Skip to content

Commit f9dca65

Browse files
authored
feat: use new ownBatch endpoint (this is an internal endpoint) (#181)
🎫 Ticket: https://linear.app/stream/issue/REACT-681/migrate-to-new-batch-endpoint πŸ“‘ Docs: N/A internal endpoint ### πŸ’‘ Overview - `ownCapabilitiesBatch` is replaced with `ownBatch` - The new endpoint is capable of backfilling all `own_` fields of `FeedResponse` not just `own_capabilities` ### πŸ“ Implementation notes - The SDK only backfills `own_capabilities` for now (JS can't easily backfill all `own_` fields, so there is a follow up issue for that)
1 parent 0df5bf0 commit f9dca65

File tree

5 files changed

+129
-106
lines changed

5 files changed

+129
-106
lines changed

β€Žpackages/feeds-client/__integration-tests__/deferred-own-capabilities-hydration.test.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe('Deferred own_capabilities hydration', () => {
249249

250250
it('should throttle new capabilities hydration', async () => {
251251
const client = createTestClient();
252-
const getCapabilitiesSpy = vi.spyOn(client as any, 'ownCapabilitiesBatch');
252+
const getCapabilitiesSpy = vi.spyOn(client as any, 'ownBatch');
253253
await client.connectUser(ownUser, createTestTokenGenerator(ownUser));
254254
const ownFeed = client.feed(feedGroup, feedId);
255255

β€Žpackages/feeds-client/src/feeds-client/feeds-client.tsβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
FollowRequest,
1717
GetOrCreateFeedRequest,
1818
ImageUploadRequest,
19-
OwnCapabilitiesBatchRequest,
19+
OwnBatchRequest,
2020
PollResponse,
2121
PollVotesResponse,
2222
QueryFeedsRequest,
@@ -286,7 +286,7 @@ export class FeedsClient extends FeedsApi {
286286
cancelTimer: cancel,
287287
} = throttle<GetBatchedOwnCapabilitiesThrottledCallback>(
288288
(feeds, callback) => {
289-
this.ownCapabilitiesBatch({
289+
this.ownBatch({
290290
feeds,
291291
}).catch((error) => {
292292
this.eventDispatcher.dispatch({
@@ -745,12 +745,12 @@ export class FeedsClient extends FeedsApi {
745745
};
746746
}
747747

748-
async ownCapabilitiesBatch(request: OwnCapabilitiesBatchRequest) {
749-
const response = await super.ownCapabilitiesBatch(request);
750-
const feedResponses = Object.entries(response.capabilities).map(
751-
([feed, own_capabilities]) => ({
748+
async ownBatch(request: OwnBatchRequest) {
749+
const response = await super.ownBatch(request);
750+
const feedResponses = Object.entries(response.data).map(
751+
([feed, ownFields]) => ({
752752
feed,
753-
own_capabilities,
753+
own_capabilities: ownFields.own_capabilities,
754754
}),
755755
);
756756
this.hydrateCapabilitiesCache(feedResponses);

β€Žpackages/feeds-client/src/gen/feeds/FeedsApi.tsβ€Ž

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ import type {
6262
ListBlockListResponse,
6363
ListDevicesResponse,
6464
MarkActivityRequest,
65-
OwnCapabilitiesBatchRequest,
66-
OwnCapabilitiesBatchResponse,
65+
OwnBatchRequest,
66+
OwnBatchResponse,
6767
PinActivityRequest,
6868
PinActivityResponse,
6969
PollOptionResponse,
@@ -104,6 +104,8 @@ import type {
104104
SingleFollowResponse,
105105
UnblockUsersRequest,
106106
UnblockUsersResponse,
107+
UnfollowBatchRequest,
108+
UnfollowBatchResponse,
107109
UnfollowResponse,
108110
UnpinActivityResponse,
109111
UpdateActivityPartialRequest,
@@ -979,14 +981,14 @@ export class FeedsApi {
979981
}
980982

981983
async addComment(
982-
request: AddCommentRequest,
984+
request?: AddCommentRequest,
983985
): Promise<StreamResponse<AddCommentResponse>> {
984986
const body = {
985-
object_id: request?.object_id,
986-
object_type: request?.object_type,
987987
comment: request?.comment,
988988
create_notification_activity: request?.create_notification_activity,
989989
id: request?.id,
990+
object_id: request?.object_id,
991+
object_type: request?.object_type,
990992
parent_id: request?.parent_id,
991993
skip_enrich_url: request?.skip_enrich_url,
992994
skip_push: request?.skip_push,
@@ -1621,28 +1623,29 @@ export class FeedsApi {
16211623
return { ...response.body, metadata: response.metadata };
16221624
}
16231625

1624-
async ownCapabilitiesBatch(
1625-
request: OwnCapabilitiesBatchRequest & { connection_id?: string },
1626-
): Promise<StreamResponse<OwnCapabilitiesBatchResponse>> {
1626+
async ownBatch(
1627+
request: OwnBatchRequest & { connection_id?: string },
1628+
): Promise<StreamResponse<OwnBatchResponse>> {
16271629
const queryParams = {
16281630
connection_id: request?.connection_id,
16291631
};
16301632
const body = {
16311633
feeds: request?.feeds,
1634+
fields: request?.fields,
16321635
};
16331636

16341637
const response = await this.apiClient.sendRequest<
1635-
StreamResponse<OwnCapabilitiesBatchResponse>
1638+
StreamResponse<OwnBatchResponse>
16361639
>(
16371640
'POST',
1638-
'/api/v2/feeds/feeds/own_capabilities/batch',
1641+
'/api/v2/feeds/feeds/own/batch',
16391642
undefined,
16401643
queryParams,
16411644
body,
16421645
'application/json',
16431646
);
16441647

1645-
decoders.OwnCapabilitiesBatchResponse?.(response.body);
1648+
decoders.OwnBatchResponse?.(response.body);
16461649

16471650
return { ...response.body, metadata: response.metadata };
16481651
}
@@ -1783,6 +1786,29 @@ export class FeedsApi {
17831786
return { ...response.body, metadata: response.metadata };
17841787
}
17851788

1789+
async getOrCreateFollows(
1790+
request: FollowBatchRequest,
1791+
): Promise<StreamResponse<FollowBatchResponse>> {
1792+
const body = {
1793+
follows: request?.follows,
1794+
};
1795+
1796+
const response = await this.apiClient.sendRequest<
1797+
StreamResponse<FollowBatchResponse>
1798+
>(
1799+
'POST',
1800+
'/api/v2/feeds/follows/batch/upsert',
1801+
undefined,
1802+
undefined,
1803+
body,
1804+
'application/json',
1805+
);
1806+
1807+
decoders.FollowBatchResponse?.(response.body);
1808+
1809+
return { ...response.body, metadata: response.metadata };
1810+
}
1811+
17861812
async queryFollows(
17871813
request?: QueryFollowsRequest,
17881814
): Promise<StreamResponse<QueryFollowsResponse>> {
@@ -1857,6 +1883,29 @@ export class FeedsApi {
18571883
return { ...response.body, metadata: response.metadata };
18581884
}
18591885

1886+
async getOrCreateUnfollows(
1887+
request: UnfollowBatchRequest,
1888+
): Promise<StreamResponse<UnfollowBatchResponse>> {
1889+
const body = {
1890+
follows: request?.follows,
1891+
};
1892+
1893+
const response = await this.apiClient.sendRequest<
1894+
StreamResponse<UnfollowBatchResponse>
1895+
>(
1896+
'POST',
1897+
'/api/v2/feeds/unfollow/batch/upsert',
1898+
undefined,
1899+
undefined,
1900+
body,
1901+
'application/json',
1902+
);
1903+
1904+
decoders.UnfollowBatchResponse?.(response.body);
1905+
1906+
return { ...response.body, metadata: response.metadata };
1907+
}
1908+
18601909
async createGuest(
18611910
request: CreateGuestRequest,
18621911
): Promise<StreamResponse<CreateGuestResponse>> {

0 commit comments

Comments
Β (0)