@stream-io/node-sdk 0.4.25 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/index.cjs.js +6265 -3834
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.es.mjs +6263 -3835
  5. package/dist/index.es.mjs.map +1 -1
  6. package/dist/src/ApiClient.d.ts +15 -0
  7. package/dist/src/StreamCall.d.ts +2 -2
  8. package/dist/src/StreamClient.d.ts +10 -1
  9. package/dist/src/StreamFeed.d.ts +4 -0
  10. package/dist/src/StreamFeedsClient.d.ts +5 -0
  11. package/dist/src/StreamVideoClient.d.ts +3 -2
  12. package/dist/src/gen/chat/ChannelApi.d.ts +29 -30
  13. package/dist/src/gen/chat/ChatApi.d.ts +145 -180
  14. package/dist/src/gen/common/CommonApi.d.ts +122 -79
  15. package/dist/src/gen/feeds/FeedApi.d.ts +25 -0
  16. package/dist/src/gen/feeds/FeedsApi.d.ts +195 -0
  17. package/dist/src/gen/models/index.d.ts +1750 -47
  18. package/dist/src/gen/moderation/ModerationApi.d.ts +28 -27
  19. package/dist/src/gen/video/CallApi.d.ts +42 -43
  20. package/dist/src/gen/video/VideoApi.d.ts +91 -89
  21. package/dist/src/gen-imports.d.ts +5 -0
  22. package/index.ts +3 -1
  23. package/package.json +1 -1
  24. package/src/{BaseApi.ts → ApiClient.ts} +25 -6
  25. package/src/StreamCall.ts +2 -2
  26. package/src/StreamClient.ts +51 -14
  27. package/src/StreamFeed.ts +7 -0
  28. package/src/StreamFeedsClient.ts +8 -0
  29. package/src/StreamVideoClient.ts +9 -6
  30. package/src/gen/chat/ChannelApi.ts +74 -64
  31. package/src/gen/chat/ChatApi.ts +550 -681
  32. package/src/gen/common/CommonApi.ts +712 -262
  33. package/src/gen/feeds/FeedApi.ts +130 -0
  34. package/src/gen/feeds/FeedsApi.ts +1801 -0
  35. package/src/gen/model-decoders/{index.ts → decoders.ts} +2248 -336
  36. package/src/gen/models/index.ts +4668 -2088
  37. package/src/gen/moderation/ModerationApi.ts +159 -98
  38. package/src/gen/video/CallApi.ts +97 -108
  39. package/src/gen/video/VideoApi.ts +303 -203
  40. package/src/gen-imports.ts +5 -0
  41. package/dist/src/BaseApi.d.ts +0 -11
  42. /package/dist/src/gen/model-decoders/{index.d.ts → decoders.d.ts} +0 -0
@@ -4,8 +4,16 @@ import { StreamVideoClient } from './StreamVideoClient';
4
4
  import crypto from 'crypto';
5
5
  import { StreamChatClient } from './StreamChatClient';
6
6
  import { CallTokenPayload, UserTokenPayload } from './types';
7
- import { QueryBannedUsersPayload, UserRequest } from './gen/models';
7
+ import {
8
+ FileUploadRequest,
9
+ ImageUploadRequest,
10
+ QueryBannedUsersPayload,
11
+ UserRequest,
12
+ } from './gen/models';
8
13
  import { StreamModerationClient } from './StreamModerationClient';
14
+ import { ApiClient } from './ApiClient';
15
+ import { StreamFeedsClient } from './StreamFeedsClient';
16
+ import { File } from 'buffer';
9
17
 
10
18
  export interface StreamClientOptions {
11
19
  timeout?: number;
@@ -19,6 +27,7 @@ export class StreamClient extends CommonApi {
19
27
  public readonly video: StreamVideoClient;
20
28
  public readonly chat: StreamChatClient;
21
29
  public readonly moderation: StreamModerationClient;
30
+ public readonly feeds: StreamFeedsClient;
22
31
  public readonly options: StreamClientOptions = {};
23
32
 
24
33
  private static readonly DEFAULT_TIMEOUT = 3000;
@@ -38,36 +47,40 @@ export class StreamClient extends CommonApi {
38
47
  const timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT;
39
48
  const chatBaseUrl = config?.basePath ?? 'https://chat.stream-io-api.com';
40
49
  const videoBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com';
41
- super({
50
+ const feedsBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com';
51
+ const chatApiClient = new ApiClient({
42
52
  apiKey,
43
53
  token,
44
- timeout,
45
54
  baseUrl: chatBaseUrl,
55
+ timeout,
46
56
  agent: config?.agent as RequestInit['dispatcher'],
47
57
  });
48
58
 
49
- this.video = new StreamVideoClient({
50
- streamClient: this,
59
+ const videoApiClient = new ApiClient({
51
60
  apiKey,
52
61
  token,
53
- timeout,
54
62
  baseUrl: videoBaseUrl,
55
- agent: config?.agent as RequestInit['dispatcher'],
56
- });
57
- this.chat = new StreamChatClient({
58
- apiKey,
59
- token,
60
63
  timeout,
61
- baseUrl: chatBaseUrl,
62
64
  agent: config?.agent as RequestInit['dispatcher'],
63
65
  });
64
- this.moderation = new StreamModerationClient({
66
+
67
+ const feedsApiClient = new ApiClient({
65
68
  apiKey,
66
69
  token,
70
+ baseUrl: feedsBaseUrl,
67
71
  timeout,
68
- baseUrl: chatBaseUrl,
69
72
  agent: config?.agent as RequestInit['dispatcher'],
70
73
  });
74
+
75
+ super(chatApiClient);
76
+
77
+ this.video = new StreamVideoClient({
78
+ streamClient: this,
79
+ apiClient: videoApiClient,
80
+ });
81
+ this.chat = new StreamChatClient(this.apiClient);
82
+ this.moderation = new StreamModerationClient(chatApiClient);
83
+ this.feeds = new StreamFeedsClient(feedsApiClient);
71
84
  }
72
85
 
73
86
  upsertUsers = (users: UserRequest[]) => {
@@ -84,6 +97,30 @@ export class StreamClient extends CommonApi {
84
97
  return this.chat.queryBannedUsers(request);
85
98
  };
86
99
 
100
+ // @ts-expect-error API spec says file should be a string
101
+ uploadFile = (request: Omit<FileUploadRequest, 'file'> & { file: File }) => {
102
+ return super.uploadFile({
103
+ // @ts-expect-error API spec says file should be a string
104
+ file: request.file,
105
+ // @ts-expect-error form data will only work if this is a string
106
+ user: JSON.stringify(request.user),
107
+ });
108
+ };
109
+
110
+ // @ts-expect-error API spec says file should be a string
111
+ uploadImage = (
112
+ request: Omit<ImageUploadRequest, 'file'> & { file: File },
113
+ ) => {
114
+ return super.uploadImage({
115
+ // @ts-expect-error API spec says file should be a string
116
+ file: request.file,
117
+ // @ts-expect-error form data will only work if this is a string
118
+ user: JSON.stringify(request.user),
119
+ // @ts-expect-error form data will only work if this is a string
120
+ upload_sizes: JSON.stringify(request.upload_sizes),
121
+ });
122
+ };
123
+
87
124
  /**
88
125
  *
89
126
  * @param payload
@@ -0,0 +1,7 @@
1
+ import { FeedApi } from './gen/feeds/FeedApi';
2
+
3
+ export class StreamFeed extends FeedApi {
4
+ get fid() {
5
+ return `${this.group}:${this.id}`;
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ import { FeedsApi } from './gen/feeds/FeedsApi';
2
+ import { StreamFeed } from './StreamFeed';
3
+
4
+ export class StreamFeedsClient extends FeedsApi {
5
+ feed = (group: string, id: string) => {
6
+ return new StreamFeed(this, group, id);
7
+ };
8
+ }
@@ -1,7 +1,7 @@
1
+ import { ApiClient } from './ApiClient';
1
2
  import { VideoApi } from './gen/video/VideoApi';
2
3
  import { StreamCall } from './StreamCall';
3
4
  import type { StreamClient } from './StreamClient';
4
- import type { ApiConfig } from './types';
5
5
  // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
6
6
  /** @ts-ignore Optional dependency */
7
7
  import type {
@@ -15,9 +15,12 @@ export class StreamVideoClient extends VideoApi {
15
15
 
16
16
  constructor({
17
17
  streamClient,
18
- ...apiConfig
19
- }: ApiConfig & { streamClient: StreamClient }) {
20
- super(apiConfig);
18
+ apiClient,
19
+ }: {
20
+ streamClient: StreamClient;
21
+ apiClient: ApiClient;
22
+ }) {
23
+ super(apiClient);
21
24
  this.streamClient = streamClient;
22
25
  }
23
26
 
@@ -54,9 +57,9 @@ export class StreamVideoClient extends VideoApi {
54
57
  });
55
58
 
56
59
  const realtimeClient = doCreateRealtimeClient({
57
- baseUrl: this.apiConfig.baseUrl,
60
+ baseUrl: this.streamClient.apiClient.apiConfig.baseUrl,
58
61
  call: options.call,
59
- streamApiKey: this.apiConfig.apiKey,
62
+ streamApiKey: this.streamClient.apiClient.apiConfig.apiKey,
60
63
  streamUserToken: token,
61
64
  openAiApiKey: options.openAiApiKey,
62
65
  model: options.model,
@@ -1,5 +1,4 @@
1
- import { ChatApi } from './ChatApi';
2
- import { StreamResponse } from '../../types';
1
+ import { StreamResponse, ChatApi } from '../../gen-imports';
3
2
  import {
4
3
  ChannelGetOrCreateRequest,
5
4
  ChannelStateResponse,
@@ -36,281 +35,292 @@ export class ChannelApi {
36
35
  constructor(
37
36
  protected chatApi: ChatApi,
38
37
  public readonly type: string,
39
- public id?: string,
38
+ public id: string | undefined,
40
39
  ) {}
41
40
 
42
- delete = (request?: {
41
+ delete(request?: {
43
42
  hard_delete?: boolean;
44
- }): Promise<StreamResponse<DeleteChannelResponse>> => {
43
+ }): Promise<StreamResponse<DeleteChannelResponse>> {
45
44
  if (!this.id) {
46
45
  throw new Error(
47
46
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
48
47
  );
49
48
  }
49
+
50
50
  return this.chatApi.deleteChannel({
51
51
  id: this.id,
52
52
  type: this.type,
53
53
  ...request,
54
54
  });
55
- };
55
+ }
56
56
 
57
- updateChannelPartial = (
57
+ updateChannelPartial(
58
58
  request?: UpdateChannelPartialRequest,
59
- ): Promise<StreamResponse<UpdateChannelPartialResponse>> => {
59
+ ): Promise<StreamResponse<UpdateChannelPartialResponse>> {
60
60
  if (!this.id) {
61
61
  throw new Error(
62
62
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
63
63
  );
64
64
  }
65
+
65
66
  return this.chatApi.updateChannelPartial({
66
67
  id: this.id,
67
68
  type: this.type,
68
69
  ...request,
69
70
  });
70
- };
71
+ }
71
72
 
72
- update = (
73
+ update(
73
74
  request?: UpdateChannelRequest,
74
- ): Promise<StreamResponse<UpdateChannelResponse>> => {
75
+ ): Promise<StreamResponse<UpdateChannelResponse>> {
75
76
  if (!this.id) {
76
77
  throw new Error(
77
78
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
78
79
  );
79
80
  }
81
+
80
82
  return this.chatApi.updateChannel({
81
83
  id: this.id,
82
84
  type: this.type,
83
85
  ...request,
84
86
  });
85
- };
87
+ }
86
88
 
87
- deleteDraft = (request?: {
89
+ deleteDraft(request?: {
88
90
  parent_id?: string;
89
91
  user_id?: string;
90
- }): Promise<StreamResponse<Response>> => {
92
+ }): Promise<StreamResponse<Response>> {
91
93
  if (!this.id) {
92
94
  throw new Error(
93
95
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
94
96
  );
95
97
  }
98
+
96
99
  return this.chatApi.deleteDraft({
97
100
  id: this.id,
98
101
  type: this.type,
99
102
  ...request,
100
103
  });
101
- };
104
+ }
102
105
 
103
- getDraft = (request?: {
106
+ getDraft(request?: {
104
107
  parent_id?: string;
105
108
  user_id?: string;
106
- }): Promise<StreamResponse<GetDraftResponse>> => {
109
+ }): Promise<StreamResponse<GetDraftResponse>> {
107
110
  if (!this.id) {
108
111
  throw new Error(
109
112
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
110
113
  );
111
114
  }
115
+
112
116
  return this.chatApi.getDraft({ id: this.id, type: this.type, ...request });
113
- };
117
+ }
114
118
 
115
- sendEvent = (
116
- request: SendEventRequest,
117
- ): Promise<StreamResponse<EventResponse>> => {
119
+ sendEvent(request: SendEventRequest): Promise<StreamResponse<EventResponse>> {
118
120
  if (!this.id) {
119
121
  throw new Error(
120
122
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
121
123
  );
122
124
  }
125
+
123
126
  return this.chatApi.sendEvent({ id: this.id, type: this.type, ...request });
124
- };
127
+ }
125
128
 
126
- deleteFile = (request?: {
127
- url?: string;
128
- }): Promise<StreamResponse<Response>> => {
129
+ deleteFile(request?: { url?: string }): Promise<StreamResponse<Response>> {
129
130
  if (!this.id) {
130
131
  throw new Error(
131
132
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
132
133
  );
133
134
  }
135
+
134
136
  return this.chatApi.deleteFile({
135
137
  id: this.id,
136
138
  type: this.type,
137
139
  ...request,
138
140
  });
139
- };
141
+ }
140
142
 
141
- uploadFile = (
143
+ uploadFile(
142
144
  request?: FileUploadRequest,
143
- ): Promise<StreamResponse<FileUploadResponse>> => {
145
+ ): Promise<StreamResponse<FileUploadResponse>> {
144
146
  if (!this.id) {
145
147
  throw new Error(
146
148
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
147
149
  );
148
150
  }
151
+
149
152
  return this.chatApi.uploadFile({
150
153
  id: this.id,
151
154
  type: this.type,
152
155
  ...request,
153
156
  });
154
- };
157
+ }
155
158
 
156
- hide = (
159
+ hide(
157
160
  request?: HideChannelRequest,
158
- ): Promise<StreamResponse<HideChannelResponse>> => {
161
+ ): Promise<StreamResponse<HideChannelResponse>> {
159
162
  if (!this.id) {
160
163
  throw new Error(
161
164
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
162
165
  );
163
166
  }
167
+
164
168
  return this.chatApi.hideChannel({
165
169
  id: this.id,
166
170
  type: this.type,
167
171
  ...request,
168
172
  });
169
- };
173
+ }
170
174
 
171
- deleteImage = (request?: {
172
- url?: string;
173
- }): Promise<StreamResponse<Response>> => {
175
+ deleteImage(request?: { url?: string }): Promise<StreamResponse<Response>> {
174
176
  if (!this.id) {
175
177
  throw new Error(
176
178
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
177
179
  );
178
180
  }
181
+
179
182
  return this.chatApi.deleteImage({
180
183
  id: this.id,
181
184
  type: this.type,
182
185
  ...request,
183
186
  });
184
- };
187
+ }
185
188
 
186
- uploadImage = (
189
+ uploadImage(
187
190
  request?: ImageUploadRequest,
188
- ): Promise<StreamResponse<ImageUploadResponse>> => {
191
+ ): Promise<StreamResponse<ImageUploadResponse>> {
189
192
  if (!this.id) {
190
193
  throw new Error(
191
194
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
192
195
  );
193
196
  }
197
+
194
198
  return this.chatApi.uploadImage({
195
199
  id: this.id,
196
200
  type: this.type,
197
201
  ...request,
198
202
  });
199
- };
203
+ }
200
204
 
201
- updateMemberPartial = (
205
+ updateMemberPartial(
202
206
  request?: UpdateMemberPartialRequest & { user_id?: string },
203
- ): Promise<StreamResponse<UpdateMemberPartialResponse>> => {
207
+ ): Promise<StreamResponse<UpdateMemberPartialResponse>> {
204
208
  if (!this.id) {
205
209
  throw new Error(
206
210
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
207
211
  );
208
212
  }
213
+
209
214
  return this.chatApi.updateMemberPartial({
210
215
  id: this.id,
211
216
  type: this.type,
212
217
  ...request,
213
218
  });
214
- };
219
+ }
215
220
 
216
- sendMessage = (
221
+ sendMessage(
217
222
  request: SendMessageRequest,
218
- ): Promise<StreamResponse<SendMessageResponse>> => {
223
+ ): Promise<StreamResponse<SendMessageResponse>> {
219
224
  if (!this.id) {
220
225
  throw new Error(
221
226
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
222
227
  );
223
228
  }
229
+
224
230
  return this.chatApi.sendMessage({
225
231
  id: this.id,
226
232
  type: this.type,
227
233
  ...request,
228
234
  });
229
- };
235
+ }
230
236
 
231
- getManyMessages = (request: {
237
+ getManyMessages(request: {
232
238
  ids: string[];
233
- }): Promise<StreamResponse<GetManyMessagesResponse>> => {
239
+ }): Promise<StreamResponse<GetManyMessagesResponse>> {
234
240
  if (!this.id) {
235
241
  throw new Error(
236
242
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
237
243
  );
238
244
  }
245
+
239
246
  return this.chatApi.getManyMessages({
240
247
  id: this.id,
241
248
  type: this.type,
242
249
  ...request,
243
250
  });
244
- };
251
+ }
245
252
 
246
- getOrCreate = (
253
+ getOrCreate(
247
254
  request?: ChannelGetOrCreateRequest,
248
- ): Promise<StreamResponse<ChannelStateResponse>> => {
255
+ ): Promise<StreamResponse<ChannelStateResponse>> {
249
256
  if (!this.id) {
250
257
  throw new Error(
251
258
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
252
259
  );
253
260
  }
261
+
254
262
  return this.chatApi.getOrCreateChannel({
255
263
  id: this.id,
256
264
  type: this.type,
257
265
  ...request,
258
266
  });
259
- };
267
+ }
260
268
 
261
- markRead = (
269
+ markRead(
262
270
  request?: MarkReadRequest,
263
- ): Promise<StreamResponse<MarkReadResponse>> => {
271
+ ): Promise<StreamResponse<MarkReadResponse>> {
264
272
  if (!this.id) {
265
273
  throw new Error(
266
274
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
267
275
  );
268
276
  }
277
+
269
278
  return this.chatApi.markRead({ id: this.id, type: this.type, ...request });
270
- };
279
+ }
271
280
 
272
- show = (
281
+ show(
273
282
  request?: ShowChannelRequest,
274
- ): Promise<StreamResponse<ShowChannelResponse>> => {
283
+ ): Promise<StreamResponse<ShowChannelResponse>> {
275
284
  if (!this.id) {
276
285
  throw new Error(
277
286
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
278
287
  );
279
288
  }
289
+
280
290
  return this.chatApi.showChannel({
281
291
  id: this.id,
282
292
  type: this.type,
283
293
  ...request,
284
294
  });
285
- };
295
+ }
286
296
 
287
- truncate = (
297
+ truncate(
288
298
  request?: TruncateChannelRequest,
289
- ): Promise<StreamResponse<TruncateChannelResponse>> => {
299
+ ): Promise<StreamResponse<TruncateChannelResponse>> {
290
300
  if (!this.id) {
291
301
  throw new Error(
292
302
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
293
303
  );
294
304
  }
305
+
295
306
  return this.chatApi.truncateChannel({
296
307
  id: this.id,
297
308
  type: this.type,
298
309
  ...request,
299
310
  });
300
- };
311
+ }
301
312
 
302
- markUnread = (
303
- request?: MarkUnreadRequest,
304
- ): Promise<StreamResponse<Response>> => {
313
+ markUnread(request?: MarkUnreadRequest): Promise<StreamResponse<Response>> {
305
314
  if (!this.id) {
306
315
  throw new Error(
307
316
  `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
308
317
  );
309
318
  }
319
+
310
320
  return this.chatApi.markUnread({
311
321
  id: this.id,
312
322
  type: this.type,
313
323
  ...request,
314
324
  });
315
- };
325
+ }
316
326
  }