@stream-io/node-sdk 0.3.0 → 0.4.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 (70) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs.js +4140 -9282
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.es.js +4140 -9206
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/src/BaseApi.d.ts +10 -0
  8. package/dist/src/StreamCall.d.ts +5 -37
  9. package/dist/src/StreamChannel.d.ts +7 -34
  10. package/dist/src/StreamChatClient.d.ts +2 -25
  11. package/dist/src/StreamClient.d.ts +51 -59
  12. package/dist/src/StreamModerationClient.d.ts +3 -0
  13. package/dist/src/StreamVideoClient.d.ts +2 -18
  14. package/dist/src/gen/chat/ChannelApi.d.ts +33 -0
  15. package/dist/src/gen/chat/ChatApi.d.ts +241 -0
  16. package/dist/src/gen/common/CommonApi.d.ts +99 -0
  17. package/dist/src/gen/model-decoders/index.d.ts +3 -0
  18. package/dist/src/gen/models/index.d.ts +3878 -0
  19. package/dist/src/gen/moderation/ModerationApi.d.ts +38 -0
  20. package/dist/src/gen/video/CallApi.d.ts +56 -0
  21. package/dist/src/gen/video/VideoApi.d.ts +151 -0
  22. package/dist/src/types.d.ts +25 -0
  23. package/dist/src/utils/create-token.d.ts +2 -0
  24. package/dist/src/utils/rate-limit.d.ts +2 -0
  25. package/index.ts +2 -3
  26. package/package.json +12 -4
  27. package/src/BaseApi.ts +115 -0
  28. package/src/StreamCall.ts +9 -199
  29. package/src/StreamChannel.ts +23 -246
  30. package/src/StreamChatClient.ts +3 -122
  31. package/src/StreamClient.ts +101 -345
  32. package/src/StreamModerationClient.ts +3 -0
  33. package/src/StreamVideoClient.ts +3 -95
  34. package/src/gen/chat/ChannelApi.ts +270 -0
  35. package/src/gen/chat/ChatApi.ts +1857 -0
  36. package/src/gen/common/CommonApi.ts +1004 -0
  37. package/src/gen/model-decoders/index.ts +1897 -0
  38. package/src/gen/models/index.ts +6790 -0
  39. package/src/gen/moderation/ModerationApi.ts +476 -0
  40. package/src/gen/video/CallApi.ts +309 -0
  41. package/src/gen/video/VideoApi.ts +1011 -0
  42. package/src/types.ts +35 -0
  43. package/src/utils/create-token.ts +6 -1
  44. package/src/utils/rate-limit.ts +21 -0
  45. package/dist/src/gen/chat/apis/ProductchatApi.d.ts +0 -1750
  46. package/dist/src/gen/chat/apis/index.d.ts +0 -1
  47. package/dist/src/gen/chat/index.d.ts +0 -3
  48. package/dist/src/gen/chat/models/index.d.ts +0 -14865
  49. package/dist/src/gen/chat/runtime.d.ts +0 -180
  50. package/dist/src/gen/video/apis/ProductvideoApi.d.ts +0 -648
  51. package/dist/src/gen/video/apis/index.d.ts +0 -1
  52. package/dist/src/gen/video/index.d.ts +0 -3
  53. package/dist/src/gen/video/models/index.d.ts +0 -5011
  54. package/dist/src/gen/video/runtime.d.ts +0 -180
  55. package/src/gen/chat/.openapi-generator/FILES +0 -6
  56. package/src/gen/chat/.openapi-generator/VERSION +0 -1
  57. package/src/gen/chat/.openapi-generator-ignore +0 -23
  58. package/src/gen/chat/apis/ProductchatApi.ts +0 -7007
  59. package/src/gen/chat/apis/index.ts +0 -3
  60. package/src/gen/chat/index.ts +0 -5
  61. package/src/gen/chat/models/index.ts +0 -14766
  62. package/src/gen/chat/runtime.ts +0 -415
  63. package/src/gen/video/.openapi-generator/FILES +0 -6
  64. package/src/gen/video/.openapi-generator/VERSION +0 -1
  65. package/src/gen/video/.openapi-generator-ignore +0 -23
  66. package/src/gen/video/apis/ProductvideoApi.ts +0 -2575
  67. package/src/gen/video/apis/index.ts +0 -3
  68. package/src/gen/video/index.ts +0 -5
  69. package/src/gen/video/models/index.ts +0 -5000
  70. package/src/gen/video/runtime.ts +0 -415
@@ -1,262 +1,39 @@
1
- import { StreamClient } from './StreamClient';
2
- import {
3
- ChannelGetOrCreateRequest,
4
- DeleteChannelRequest,
5
- DeleteMessageRequest,
6
- DeleteReactionRequest,
7
- EventRequest,
8
- GetManyMessagesRequest,
9
- GetMessageRequest,
10
- GetOGRequest,
11
- GetReactionsRequest,
12
- GetRepliesRequest,
13
- HideChannelRequest,
14
- MarkReadRequest,
15
- MarkUnreadRequest,
16
- MuteChannelRequest,
17
- ProductchatApi,
18
- QueryMembersRequest,
19
- SendMessageRequest,
20
- SendReactionRequest,
21
- ShowChannelRequest,
22
- TranslateMessageRequest,
23
- TruncateChannelRequest,
24
- UnmuteChannelRequest,
25
- UpdateChannelPartialRequest,
26
- UpdateChannelRequest,
27
- UpdateMessagePartialRequest,
28
- UpdateMessageRequest,
29
- } from './gen/chat';
1
+ import { ChannelApi } from './gen/chat/ChannelApi';
2
+ import { ChannelGetOrCreateRequest, QueryMembersRequest } from './gen/models';
30
3
  import { OmitTypeId } from './types';
31
4
 
32
- export class StreamChannel {
33
- private readonly chatApi: ProductchatApi;
34
-
35
- constructor(
36
- private readonly streamClient: StreamClient,
37
- public readonly type: string,
38
- public id?: string,
39
- ) {
40
- const configuration = this.streamClient.getConfiguration();
41
- /** @ts-expect-error */
42
- this.chatApi = new ProductchatApi(configuration);
43
- }
44
-
5
+ export class StreamChannel extends ChannelApi {
45
6
  get cid() {
46
- return `${this.baseRequest.type}:${this.baseRequest.id}`;
7
+ return `${this.type}:${this.id}`;
47
8
  }
48
9
 
49
- delete = (request?: OmitTypeId<DeleteChannelRequest>) => {
50
- return this.chatApi.deleteChannel({
51
- ...this.baseRequest,
52
- ...(request ?? {}),
53
- });
54
- };
55
-
56
- update = (updateChannelRequest: OmitTypeId<UpdateChannelRequest>) => {
57
- return this.chatApi.updateChannel({
58
- ...this.baseRequest,
59
- updateChannelRequest,
60
- });
61
- };
62
-
63
- updatePartial = (
64
- updateChannelPartialRequest: OmitTypeId<UpdateChannelPartialRequest>,
65
- ) => {
66
- return this.chatApi.updateChannelPartial({
67
- ...this.baseRequest,
68
- updateChannelPartialRequest,
69
- });
70
- };
71
-
72
- getOrCreate = async (
73
- channelGetOrCreateRequest?: ChannelGetOrCreateRequest,
74
- ) => {
75
- if (this.id) {
76
- return await this.chatApi.getOrCreateChannel({
77
- ...this.baseRequest,
78
- channelGetOrCreateRequest: channelGetOrCreateRequest ?? {},
79
- });
10
+ getOrCreate = (channel_get_or_create_request?: ChannelGetOrCreateRequest) => {
11
+ if (!this.id) {
12
+ return this.chatApi
13
+ .getOrCreateDistinctChannel({
14
+ type: this.type,
15
+ ...channel_get_or_create_request,
16
+ })
17
+ .then((response) => {
18
+ this.id = response.channel?.id;
19
+ return response;
20
+ });
80
21
  } else {
81
- if (!channelGetOrCreateRequest?.data?.members) {
82
- throw new Error(
83
- 'You need to provide members to create a channel without ID',
84
- );
85
- }
86
- const response = await this.chatApi.getOrCreateDistinctChannel({
22
+ return this.chatApi.getOrCreateChannel({
23
+ id: this.id,
87
24
  type: this.type,
88
- channelGetOrCreateRequest,
25
+ ...channel_get_or_create_request,
89
26
  });
90
- this.id = response.channel?.id;
91
- return response;
92
27
  }
93
28
  };
94
29
 
95
- markRead = (markReadRequest: MarkReadRequest) => {
96
- return this.chatApi.markRead({ ...this.baseRequest, markReadRequest });
97
- };
98
-
99
- markUnread = (markUnreadRequest: MarkUnreadRequest) => {
100
- return this.chatApi.markUnread({
101
- ...this.baseRequest,
102
- markUnreadRequest,
103
- });
104
- };
105
-
106
- show = (showChannelRequest: ShowChannelRequest) => {
107
- return this.chatApi.showChannel({
108
- ...this.baseRequest,
109
- showChannelRequest,
110
- });
111
- };
112
-
113
- hide = (hideChannelRequest: HideChannelRequest) => {
114
- return this.chatApi.hideChannel({
115
- ...this.baseRequest,
116
- hideChannelRequest,
117
- });
118
- };
119
-
120
- truncate = (truncateChannelRequest: TruncateChannelRequest) => {
121
- return this.chatApi.truncateChannel({
122
- ...this.baseRequest,
123
- truncateChannelRequest,
124
- });
125
- };
126
-
127
- queryMembers = (request: OmitTypeId<QueryMembersRequest>) => {
30
+ queryMembers(request?: { payload?: OmitTypeId<QueryMembersRequest> }) {
128
31
  return this.chatApi.queryMembers({
129
- payload: { ...this.baseRequest, ...request },
130
- });
131
- };
132
-
133
- mute = (muteChannelRequest: Omit<MuteChannelRequest, 'channel_cids'>) => {
134
- return this.chatApi.muteChannel({
135
- muteChannelRequest: { ...muteChannelRequest, channel_cids: [this.cid] },
136
- });
137
- };
138
-
139
- unmute = (
140
- unmuteChannelRequest: Omit<
141
- UnmuteChannelRequest,
142
- 'channel_cids' | 'channel_cid'
143
- >,
144
- ) => {
145
- return this.chatApi.unmuteChannel({
146
- unmuteChannelRequest: {
147
- ...unmuteChannelRequest,
148
- channel_cids: [this.cid],
32
+ payload: {
33
+ id: this.id,
34
+ type: this.type,
35
+ ...(request?.payload ?? { filter_conditions: {} }),
149
36
  },
150
37
  });
151
- };
152
-
153
- // TODO: there is probably an issue with the generated code here
154
- // uploadFile = (options: Omit<OmitTypeId<UploadFileRequest>, 'file'>, file: Buffer) => {
155
- // return this.chatApi.uploadFile({...options, ...this.baseRequest, file: file as any as string});
156
- // }
157
-
158
- // deleteFile = (request: OmitTypeId<DeleteFileRequest>) => {
159
- // return this.chatApi.deleteFile({...request, ...this.baseRequest});
160
- // }
161
-
162
- // uploadImage = (request: OmitTypeId<UploadImageRequest>) => {
163
- // return this.chatApi.uploadImage({...request, ...this.baseRequest});
164
- // }
165
-
166
- // deleteImage = (request: OmitTypeId<DeleteImageRequest>) => {
167
- // return this.chatApi.deleteImage({...request, ...this.baseRequest});
168
- // }
169
-
170
- sendMessage = (sendMessageRequest: SendMessageRequest) => {
171
- return this.chatApi.sendMessage({
172
- ...this.baseRequest,
173
- sendMessageRequest,
174
- });
175
- };
176
-
177
- deleteMessage = (request: DeleteMessageRequest) => {
178
- return this.chatApi.deleteMessage(request);
179
- };
180
-
181
- updateMessage = (id: string, updateMessageRequest: UpdateMessageRequest) => {
182
- return this.chatApi.updateMessage({ id, updateMessageRequest });
183
- };
184
-
185
- updateMessagePartial = (
186
- id: string,
187
- updateMessagePartialRequest: UpdateMessagePartialRequest,
188
- ) => {
189
- return this.chatApi.updateMessagePartial({
190
- id,
191
- updateMessagePartialRequest,
192
- });
193
- };
194
-
195
- getMessage = (request: GetMessageRequest) => {
196
- return this.chatApi.getMessage(request);
197
- };
198
-
199
- getManyMessages = (request: OmitTypeId<GetManyMessagesRequest>) => {
200
- return this.chatApi.getManyMessages({
201
- ...request,
202
- ...this.baseRequest,
203
- });
204
- };
205
-
206
- translateMessage = (
207
- id: string,
208
- translateMessageRequest: TranslateMessageRequest,
209
- ) => {
210
- return this.chatApi.translateMessage({ id, translateMessageRequest });
211
- };
212
-
213
- getMessagesAround = (request: GetRepliesRequest) => {
214
- return this.chatApi.getReplies(request);
215
- };
216
-
217
- getOpenGraphData = (request: GetOGRequest) => {
218
- return this.chatApi.getOG(request);
219
- };
220
-
221
- sendMessageReaction = (
222
- messageId: string,
223
- sendReactionRequest: SendReactionRequest,
224
- ) => {
225
- return this.chatApi.sendReaction({
226
- id: messageId,
227
- sendReactionRequest,
228
- });
229
- };
230
-
231
- deleteMessageReaction = (
232
- messageId: string,
233
- request: Omit<DeleteReactionRequest, 'id'>,
234
- ) => {
235
- return this.chatApi.deleteReaction({ ...request, id: messageId });
236
- };
237
-
238
- getMessageReactions = (
239
- messageId: string,
240
- request?: Omit<GetReactionsRequest, 'id'>,
241
- ) => {
242
- return this.chatApi.getReactions({ ...(request ?? {}), id: messageId });
243
- };
244
-
245
- sendCustomEvent = (event: EventRequest) => {
246
- return this.chatApi.sendEvent({
247
- ...this.baseRequest,
248
- sendEventRequest: { event },
249
- });
250
- };
251
-
252
- private get baseRequest() {
253
- if (!this.id) {
254
- throw new Error('You need to initialize the channel with `getOrCreate`');
255
- }
256
-
257
- return {
258
- id: this.id,
259
- type: this.type,
260
- };
261
38
  }
262
39
  }
@@ -1,127 +1,8 @@
1
+ import { ChatApi } from './gen/chat/ChatApi';
1
2
  import { StreamChannel } from './StreamChannel';
2
- import { StreamClient } from './StreamClient';
3
- import {
4
- CreateBlockListRequest,
5
- CreateChannelTypeRequest,
6
- CreateCommandRequest,
7
- DeleteBlockListRequest,
8
- DeleteChannelTypeRequest,
9
- DeleteCommandRequest,
10
- ExportChannelsRequest,
11
- GetBlockListRequest,
12
- GetChannelTypeRequest,
13
- GetCommandRequest,
14
- GetExportChannelsStatusRequest,
15
- ProductchatApi,
16
- QueryChannelsRequest,
17
- SearchRequest,
18
- UpdateBlockListRequest,
19
- UpdateChannelTypeRequest,
20
- UpdateCommandRequest,
21
- } from './gen/chat';
22
-
23
- export class StreamChatClient {
24
- private readonly chatApi: ProductchatApi;
25
-
26
- constructor(private readonly streamClient: StreamClient) {
27
- const configuration = this.streamClient.getConfiguration();
28
- /** @ts-expect-error */
29
- this.chatApi = new ProductchatApi(configuration);
30
- }
31
3
 
4
+ export class StreamChatClient extends ChatApi {
32
5
  channel = (type: string, id?: string) => {
33
- return new StreamChannel(this.streamClient, type, id);
34
- };
35
-
36
- createBlockList = (createBlockListRequest: CreateBlockListRequest) => {
37
- return this.chatApi.createBlockList({ createBlockListRequest });
38
- };
39
-
40
- listBlockLists = () => {
41
- return this.chatApi.listBlockLists();
42
- };
43
-
44
- getBlockList = (request: GetBlockListRequest) => {
45
- return this.chatApi.getBlockList(request);
46
- };
47
-
48
- updateBlockList = (
49
- name: string,
50
- updateBlockListRequest: UpdateBlockListRequest,
51
- ) => {
52
- return this.chatApi.updateBlockList({ name, updateBlockListRequest });
53
- };
54
-
55
- deleteBlockList = (request: DeleteBlockListRequest) => {
56
- return this.chatApi.deleteBlockList(request);
57
- };
58
-
59
- createChannelType = (createChannelTypeRequest: CreateChannelTypeRequest) => {
60
- return this.chatApi.createChannelType({ createChannelTypeRequest });
61
- };
62
-
63
- deleteChannelType = (request: DeleteChannelTypeRequest) => {
64
- return this.chatApi.deleteChannelType(request);
65
- };
66
-
67
- getChannelType = (request: GetChannelTypeRequest) => {
68
- return this.chatApi.getChannelType(request);
69
- };
70
-
71
- listChannelTypes = () => {
72
- return this.chatApi.listChannelTypes();
73
- };
74
-
75
- updateChannelType = (
76
- name: string,
77
- updateChannelTypeRequest: UpdateChannelTypeRequest,
78
- ) => {
79
- return this.chatApi.updateChannelType({
80
- name,
81
- updateChannelTypeRequest,
82
- });
83
- };
84
-
85
- queryChannels = (queryChannelsRequest?: QueryChannelsRequest) => {
86
- return this.chatApi.queryChannels({
87
- queryChannelsRequest: queryChannelsRequest ?? {},
88
- });
89
- };
90
-
91
- searchMessages = (payload?: SearchRequest) => {
92
- return this.chatApi.search({ payload });
93
- };
94
-
95
- exportChannels = (exportChannelsRequest?: ExportChannelsRequest) => {
96
- return this.chatApi.exportChannels({
97
- exportChannelsRequest: exportChannelsRequest ?? null,
98
- });
99
- };
100
-
101
- getExportStatus = (request: GetExportChannelsStatusRequest) => {
102
- return this.chatApi.getExportChannelsStatus(request);
103
- };
104
-
105
- listCommands = () => {
106
- return this.chatApi.listCommands();
107
- };
108
-
109
- createCommand = (createCommandRequest: CreateCommandRequest) => {
110
- return this.chatApi.createCommand({ createCommandRequest });
111
- };
112
-
113
- getCommand = (getCommandRequest: GetCommandRequest) => {
114
- return this.chatApi.getCommand(getCommandRequest);
115
- };
116
-
117
- updateCommand = (
118
- name: string,
119
- updateCommandRequest: UpdateCommandRequest,
120
- ) => {
121
- return this.chatApi.updateCommand({ name, updateCommandRequest });
122
- };
123
-
124
- deleteCommand = (request: DeleteCommandRequest) => {
125
- return this.chatApi.deleteCommand(request);
6
+ return new StreamChannel(this, type, id);
126
7
  };
127
8
  }