@stream-io/node-sdk 0.8.0 → 0.8.2

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.
@@ -221,7 +221,7 @@ export declare class VideoApi {
221
221
  limit?: number;
222
222
  prev?: string;
223
223
  next?: string;
224
- sort?: SortParamRequest[];
224
+ sort?: Array<SortParamRequest>;
225
225
  filter_conditions?: Record<string, any>;
226
226
  }): Promise<StreamResponse<QueryCallSessionParticipantStatsResponse>>;
227
227
  getCallSessionParticipantStatsTimeline(request: {
@@ -232,7 +232,7 @@ export declare class VideoApi {
232
232
  user_session: string;
233
233
  start_time?: string;
234
234
  end_time?: string;
235
- severity?: string[];
235
+ severity?: Array<string>;
236
236
  }): Promise<StreamResponse<QueryCallSessionParticipantStatsTimelineResponse>>;
237
237
  queryCalls(request?: QueryCallsRequest): Promise<StreamResponse<QueryCallsResponse>>;
238
238
  listCallTypes(): Promise<StreamResponse<ListCallTypeResponse>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/node-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
package/src/ApiClient.ts CHANGED
@@ -51,13 +51,8 @@ export class ApiClient {
51
51
 
52
52
  const encodedBody =
53
53
  requestContentType === 'multipart/form-data'
54
- ? new FormData()
54
+ ? this.multipartBodyStringify(body as Record<string, any>)
55
55
  : JSON.stringify(body);
56
- if (requestContentType === 'multipart/form-data') {
57
- Object.keys(body as Record<string, any>).forEach((key) => {
58
- (encodedBody as FormData).append(key, body[key]);
59
- });
60
- }
61
56
 
62
57
  try {
63
58
  const response = await fetch(`${this.apiConfig.baseUrl}${url}`, {
@@ -125,6 +120,23 @@ export class ApiClient {
125
120
  }
126
121
  };
127
122
 
123
+ protected multipartBodyStringify = (body: Record<string, any>): FormData => {
124
+ const formData = new FormData();
125
+ for (const key in body) {
126
+ const value = body[key];
127
+ if (value === null || value === undefined) continue;
128
+ if (value instanceof Blob) {
129
+ formData.append(key, value);
130
+ } else if (isScalar(value)) {
131
+ formData.append(key, String(value));
132
+ } else {
133
+ formData.append(key, JSON.stringify(value));
134
+ }
135
+ }
136
+
137
+ return formData;
138
+ };
139
+
128
140
  protected queryParamsStringify = (params: Record<string, any>) => {
129
141
  const newParams = [];
130
142
  for (const k in params) {
@@ -105,26 +105,16 @@ export class StreamClient extends CommonApi {
105
105
 
106
106
  // @ts-expect-error API spec says file should be a string
107
107
  uploadFile = (request: Omit<FileUploadRequest, 'file'> & { file: File }) => {
108
- return super.uploadFile({
109
- // @ts-expect-error API spec says file should be a string
110
- file: request.file,
111
- // @ts-expect-error form data will only work if this is a string
112
- user: JSON.stringify(request.user),
113
- });
108
+ // @ts-expect-error API spec says file should be a string
109
+ return super.uploadFile(request);
114
110
  };
115
111
 
116
112
  // @ts-expect-error API spec says file should be a string
117
113
  uploadImage = (
118
114
  request: Omit<ImageUploadRequest, 'file'> & { file: File },
119
115
  ) => {
120
- return super.uploadImage({
121
- // @ts-expect-error API spec says file should be a string
122
- file: request.file,
123
- // @ts-expect-error form data will only work if this is a string
124
- user: JSON.stringify(request.user),
125
- // @ts-expect-error form data will only work if this is a string
126
- upload_sizes: JSON.stringify(request.upload_sizes),
127
- });
116
+ // @ts-expect-error API spec says file should be a string
117
+ return super.uploadImage(request);
128
118
  };
129
119
 
130
120
  /**
@@ -6,6 +6,7 @@ import {
6
6
  EventResponse,
7
7
  GetDraftResponse,
8
8
  GetManyMessagesResponse,
9
+ GetPinnedMessagesResponse,
9
10
  HideChannelRequest,
10
11
  HideChannelResponse,
11
12
  MarkReadRequest,
@@ -17,6 +18,7 @@ import {
17
18
  SendMessageResponse,
18
19
  ShowChannelRequest,
19
20
  ShowChannelResponse,
21
+ SortParamRequest,
20
22
  TruncateChannelRequest,
21
23
  TruncateChannelResponse,
22
24
  UpdateChannelPartialRequest,
@@ -64,6 +66,7 @@ export class ChannelApi {
64
66
  messages_id_gt?: string;
65
67
  messages_id_gte?: string;
66
68
  messages_id_around?: string;
69
+ user_id?: string;
67
70
  }): Promise<StreamResponse<ChannelStateResponse>> {
68
71
  if (!this.id) {
69
72
  throw new Error(
@@ -263,8 +266,8 @@ export class ChannelApi {
263
266
  }
264
267
 
265
268
  getManyMessages(request: {
266
- ids: string[];
267
- member_custom_include?: string[];
269
+ ids: Array<string>;
270
+ member_custom_include?: Array<string>;
268
271
  }): Promise<StreamResponse<GetManyMessagesResponse>> {
269
272
  if (!this.id) {
270
273
  throw new Error(
@@ -279,6 +282,36 @@ export class ChannelApi {
279
282
  });
280
283
  }
281
284
 
285
+ getPinnedMessages(request?: {
286
+ limit?: number;
287
+ offset?: number;
288
+ id_gte?: string;
289
+ id_gt?: string;
290
+ id_lte?: string;
291
+ id_lt?: string;
292
+ pinned_at_after_or_equal?: Date;
293
+ pinned_at_after?: Date;
294
+ pinned_at_before_or_equal?: Date;
295
+ pinned_at_before?: Date;
296
+ id_around?: string;
297
+ pinned_at_around?: Date;
298
+ user_id?: string;
299
+ sort?: Array<SortParamRequest>;
300
+ member_custom_include?: Array<string>;
301
+ }): Promise<StreamResponse<GetPinnedMessagesResponse>> {
302
+ if (!this.id) {
303
+ throw new Error(
304
+ `Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
305
+ );
306
+ }
307
+
308
+ return this.chatApi.getPinnedMessages({
309
+ id: this.id,
310
+ type: this.type,
311
+ ...request,
312
+ });
313
+ }
314
+
282
315
  getOrCreate(
283
316
  request?: ChannelGetOrCreateRequest,
284
317
  ): Promise<StreamResponse<ChannelStateResponse>> {