Skip to content

Commit b58079c

Browse files
committed
feat: update to latest API spec, deprecate followBatch and unfollowBatch
1 parent 921faf7 commit b58079c

File tree

5 files changed

+344
-11
lines changed

5 files changed

+344
-11
lines changed

src/StreamClient.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { StreamChatClient } from './StreamChatClient';
66
import { CallTokenPayload, UserTokenPayload } from './types';
77
import {
88
FileUploadRequest,
9+
FollowBatchRequest,
910
ImageUploadRequest,
1011
QueryBannedUsersPayload,
12+
UnfollowBatchRequest,
1113
UserRequest,
1214
} from './gen/models';
1315
import { StreamModerationClient } from './StreamModerationClient';
@@ -240,6 +242,20 @@ export class StreamClient extends CommonApi {
240242
return JWTUserToken(this.secret, payload);
241243
};
242244

245+
/**
246+
* @deprecated use `getOrCreateFollows` instead
247+
*/
248+
followBatch(request: FollowBatchRequest) {
249+
return this.feeds.followBatch(request);
250+
}
251+
252+
/**
253+
* @deprecated use `getOrCreateUnfollows` instead
254+
*/
255+
followUnbatch(request: UnfollowBatchRequest) {
256+
return this.feeds.unfollowBatch(request);
257+
}
258+
243259
verifyWebhook = (requestBody: string | Buffer, xSignature: string) => {
244260
const key = Buffer.from(this.secret, 'utf8');
245261
const hash = crypto

src/gen/feeds/FeedsApi.ts

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {
4343
DeleteFeedUserDataRequest,
4444
DeleteFeedUserDataResponse,
4545
DeleteFeedViewResponse,
46+
DeleteFeedsBatchRequest,
47+
DeleteFeedsBatchResponse,
4648
ExportFeedUserDataResponse,
4749
FollowBatchRequest,
4850
FollowBatchResponse,
@@ -66,8 +68,8 @@ import {
6668
ListFeedViewsResponse,
6769
ListFeedVisibilitiesResponse,
6870
MarkActivityRequest,
69-
OwnCapabilitiesBatchRequest,
70-
OwnCapabilitiesBatchResponse,
71+
OwnBatchRequest,
72+
OwnBatchResponse,
7173
PinActivityRequest,
7274
PinActivityResponse,
7375
PollVoteResponse,
@@ -1237,6 +1239,7 @@ export class FeedsApi {
12371239
view: request?.view,
12381240
watch: request?.watch,
12391241
data: request?.data,
1242+
enrichment_options: request?.enrichment_options,
12401243
external_ranking: request?.external_ranking,
12411244
filter: request?.filter,
12421245
followers_pagination: request?.followers_pagination,
@@ -1849,27 +1852,52 @@ export class FeedsApi {
18491852
return { ...response.body, metadata: response.metadata };
18501853
}
18511854

1852-
async ownCapabilitiesBatch(
1853-
request: OwnCapabilitiesBatchRequest,
1854-
): Promise<StreamResponse<OwnCapabilitiesBatchResponse>> {
1855+
async deleteFeedsBatch(
1856+
request: DeleteFeedsBatchRequest,
1857+
): Promise<StreamResponse<DeleteFeedsBatchResponse>> {
1858+
const body = {
1859+
feeds: request?.feeds,
1860+
hard_delete: request?.hard_delete,
1861+
};
1862+
1863+
const response = await this.apiClient.sendRequest<
1864+
StreamResponse<DeleteFeedsBatchResponse>
1865+
>(
1866+
'POST',
1867+
'/api/v2/feeds/feeds/delete',
1868+
undefined,
1869+
undefined,
1870+
body,
1871+
'application/json',
1872+
);
1873+
1874+
decoders.DeleteFeedsBatchResponse?.(response.body);
1875+
1876+
return { ...response.body, metadata: response.metadata };
1877+
}
1878+
1879+
async ownBatch(
1880+
request: OwnBatchRequest,
1881+
): Promise<StreamResponse<OwnBatchResponse>> {
18551882
const body = {
18561883
feeds: request?.feeds,
18571884
user_id: request?.user_id,
1885+
fields: request?.fields,
18581886
user: request?.user,
18591887
};
18601888

18611889
const response = await this.apiClient.sendRequest<
1862-
StreamResponse<OwnCapabilitiesBatchResponse>
1890+
StreamResponse<OwnBatchResponse>
18631891
>(
18641892
'POST',
1865-
'/api/v2/feeds/feeds/own_capabilities/batch',
1893+
'/api/v2/feeds/feeds/own/batch',
18661894
undefined,
18671895
undefined,
18681896
body,
18691897
'application/json',
18701898
);
18711899

1872-
decoders.OwnCapabilitiesBatchResponse?.(response.body);
1900+
decoders.OwnBatchResponse?.(response.body);
18731901

18741902
return { ...response.body, metadata: response.metadata };
18751903
}
@@ -2031,6 +2059,29 @@ export class FeedsApi {
20312059
return { ...response.body, metadata: response.metadata };
20322060
}
20332061

2062+
async getOrCreateFollows(
2063+
request: FollowBatchRequest,
2064+
): Promise<StreamResponse<FollowBatchResponse>> {
2065+
const body = {
2066+
follows: request?.follows,
2067+
};
2068+
2069+
const response = await this.apiClient.sendRequest<
2070+
StreamResponse<FollowBatchResponse>
2071+
>(
2072+
'POST',
2073+
'/api/v2/feeds/follows/batch/upsert',
2074+
undefined,
2075+
undefined,
2076+
body,
2077+
'application/json',
2078+
);
2079+
2080+
decoders.FollowBatchResponse?.(response.body);
2081+
2082+
return { ...response.body, metadata: response.metadata };
2083+
}
2084+
20342085
async queryFollows(
20352086
request?: QueryFollowsRequest,
20362087
): Promise<StreamResponse<QueryFollowsResponse>> {
@@ -2256,6 +2307,29 @@ export class FeedsApi {
22562307
return { ...response.body, metadata: response.metadata };
22572308
}
22582309

2310+
async getOrCreateUnfollows(
2311+
request: UnfollowBatchRequest,
2312+
): Promise<StreamResponse<UnfollowBatchResponse>> {
2313+
const body = {
2314+
follows: request?.follows,
2315+
};
2316+
2317+
const response = await this.apiClient.sendRequest<
2318+
StreamResponse<UnfollowBatchResponse>
2319+
>(
2320+
'POST',
2321+
'/api/v2/feeds/unfollow/batch/upsert',
2322+
undefined,
2323+
undefined,
2324+
body,
2325+
'application/json',
2326+
);
2327+
2328+
decoders.UnfollowBatchResponse?.(response.body);
2329+
2330+
return { ...response.body, metadata: response.metadata };
2331+
}
2332+
22592333
async deleteFeedUserData(
22602334
request: DeleteFeedUserDataRequest & { user_id: string },
22612335
): Promise<StreamResponse<DeleteFeedUserDataResponse>> {

src/gen/model-decoders/decoders.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,15 @@ decoders.FeedMemberUpdatedEvent = (input?: Record<string, any>) => {
20942094
return decode(typeMappings, input);
20952095
};
20962096

2097+
decoders.FeedOwnData = (input?: Record<string, any>) => {
2098+
const typeMappings: TypeMapping = {
2099+
own_follows: { type: 'FollowResponse', isSingle: false },
2100+
2101+
own_membership: { type: 'FeedMemberResponse', isSingle: true },
2102+
};
2103+
return decode(typeMappings, input);
2104+
};
2105+
20972106
decoders.FeedResponse = (input?: Record<string, any>) => {
20982107
const typeMappings: TypeMapping = {
20992108
created_at: { type: 'DatetimeType', isSingle: true },
@@ -2195,6 +2204,8 @@ decoders.FlagUpdatedEvent = (input?: Record<string, any>) => {
21952204

21962205
decoders.FollowBatchResponse = (input?: Record<string, any>) => {
21972206
const typeMappings: TypeMapping = {
2207+
created: { type: 'FollowResponse', isSingle: false },
2208+
21982209
follows: { type: 'FollowResponse', isSingle: false },
21992210
};
22002211
return decode(typeMappings, input);
@@ -3164,6 +3175,13 @@ decoders.NotificationStatusResponse = (input?: Record<string, any>) => {
31643175
return decode(typeMappings, input);
31653176
};
31663177

3178+
decoders.OwnBatchResponse = (input?: Record<string, any>) => {
3179+
const typeMappings: TypeMapping = {
3180+
data: { type: 'FeedOwnData', isSingle: false },
3181+
};
3182+
return decode(typeMappings, input);
3183+
};
3184+
31673185
decoders.OwnUser = (input?: Record<string, any>) => {
31683186
const typeMappings: TypeMapping = {
31693187
created_at: { type: 'DatetimeType', isSingle: true },
@@ -3490,6 +3508,21 @@ decoders.QueryCallSessionParticipantStatsTimelineResponse = (
34903508
return decode(typeMappings, input);
34913509
};
34923510

3511+
decoders.QueryCallStatsMapResponse = (input?: Record<string, any>) => {
3512+
const typeMappings: TypeMapping = {
3513+
call_ended_at: { type: 'DatetimeType', isSingle: true },
3514+
3515+
call_started_at: { type: 'DatetimeType', isSingle: true },
3516+
3517+
end_time: { type: 'DatetimeType', isSingle: true },
3518+
3519+
generated_at: { type: 'DatetimeType', isSingle: true },
3520+
3521+
start_time: { type: 'DatetimeType', isSingle: true },
3522+
};
3523+
return decode(typeMappings, input);
3524+
};
3525+
34933526
decoders.QueryCallStatsResponse = (input?: Record<string, any>) => {
34943527
const typeMappings: TypeMapping = {
34953528
reports: { type: 'CallStatsReportSummaryResponse', isSingle: false },

0 commit comments

Comments
 (0)