@stream-io/node-sdk 0.1.7 → 0.1.8

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 (86) hide show
  1. package/README.md +8 -2
  2. package/dist/index.cjs.js +170 -515
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.d.ts +6 -6
  5. package/dist/index.es.js +170 -515
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/src/StreamCall.d.ts +7 -10
  8. package/dist/src/StreamChannel.d.ts +4 -4
  9. package/dist/src/StreamChatClient.d.ts +8 -8
  10. package/dist/src/StreamClient.d.ts +11 -11
  11. package/dist/src/StreamVideoClient.d.ts +4 -4
  12. package/dist/src/gen/chat/apis/ChannelTypesApi.d.ts +1 -1
  13. package/dist/src/gen/chat/apis/ChannelsApi.d.ts +12 -40
  14. package/dist/src/gen/chat/apis/CustomCommandsApi.d.ts +1 -1
  15. package/dist/src/gen/chat/apis/DefaultApi.d.ts +1 -1
  16. package/dist/src/gen/chat/apis/DevicesApi.d.ts +1 -1
  17. package/dist/src/gen/chat/apis/EventsApi.d.ts +2 -19
  18. package/dist/src/gen/chat/apis/FilesApi.d.ts +1 -1
  19. package/dist/src/gen/chat/apis/GDPRApi.d.ts +1 -1
  20. package/dist/src/gen/chat/apis/ImportsApi.d.ts +1 -1
  21. package/dist/src/gen/chat/apis/MessagesApi.d.ts +2 -2
  22. package/dist/src/gen/chat/apis/ModerationApi.d.ts +1 -1
  23. package/dist/src/gen/chat/apis/PermissionsV2Api.d.ts +1 -1
  24. package/dist/src/gen/chat/apis/PushApi.d.ts +1 -1
  25. package/dist/src/gen/chat/apis/ReactionsApi.d.ts +1 -1
  26. package/dist/src/gen/chat/apis/ServerSideApi.d.ts +1 -1
  27. package/dist/src/gen/chat/apis/SettingsApi.d.ts +1 -1
  28. package/dist/src/gen/chat/apis/TasksApi.d.ts +1 -1
  29. package/dist/src/gen/chat/apis/TestingApi.d.ts +1 -1
  30. package/dist/src/gen/chat/apis/UsersApi.d.ts +1 -1
  31. package/dist/src/gen/chat/models/index.d.ts +141 -160
  32. package/dist/src/gen/chat/runtime.d.ts +1 -1
  33. package/dist/src/gen/video/apis/DefaultApi.d.ts +2 -76
  34. package/dist/src/gen/video/apis/ServerSideApi.d.ts +1 -1
  35. package/dist/src/gen/video/models/index.d.ts +0 -271
  36. package/dist/src/gen/video/runtime.d.ts +1 -1
  37. package/dist/src/utils/create-token.d.ts +1 -1
  38. package/index.ts +6 -6
  39. package/package.json +26 -6
  40. package/src/StreamCall.ts +15 -19
  41. package/src/StreamChannel.ts +177 -75
  42. package/src/StreamChatClient.ts +82 -45
  43. package/src/StreamClient.ts +78 -75
  44. package/src/StreamVideoClient.ts +8 -8
  45. package/src/gen/chat/apis/ChannelTypesApi.ts +1 -1
  46. package/src/gen/chat/apis/ChannelsApi.ts +35 -160
  47. package/src/gen/chat/apis/CustomCommandsApi.ts +1 -1
  48. package/src/gen/chat/apis/DefaultApi.ts +1 -1
  49. package/src/gen/chat/apis/DevicesApi.ts +1 -1
  50. package/src/gen/chat/apis/EventsApi.ts +1 -74
  51. package/src/gen/chat/apis/FilesApi.ts +13 -13
  52. package/src/gen/chat/apis/GDPRApi.ts +1 -1
  53. package/src/gen/chat/apis/ImportsApi.ts +1 -1
  54. package/src/gen/chat/apis/MessagesApi.ts +56 -56
  55. package/src/gen/chat/apis/ModerationApi.ts +1 -1
  56. package/src/gen/chat/apis/PermissionsV2Api.ts +1 -1
  57. package/src/gen/chat/apis/PushApi.ts +1 -1
  58. package/src/gen/chat/apis/ReactionsApi.ts +1 -1
  59. package/src/gen/chat/apis/ServerSideApi.ts +1 -1
  60. package/src/gen/chat/apis/SettingsApi.ts +1 -1
  61. package/src/gen/chat/apis/TasksApi.ts +1 -1
  62. package/src/gen/chat/apis/TestingApi.ts +1 -1
  63. package/src/gen/chat/apis/UsersApi.ts +1 -1
  64. package/src/gen/chat/apis/index.ts +8 -9
  65. package/src/gen/chat/models/index.ts +141 -160
  66. package/src/gen/chat/runtime.ts +1 -1
  67. package/src/gen/video/apis/DefaultApi.ts +1 -303
  68. package/src/gen/video/apis/ServerSideApi.ts +1 -1
  69. package/src/gen/video/models/index.ts +0 -269
  70. package/src/gen/video/runtime.ts +1 -1
  71. package/src/types.ts +1 -1
  72. package/src/utils/create-token.ts +1 -1
  73. package/dist/__tests__/block-lists.test.d.ts +0 -1
  74. package/dist/__tests__/call-members.test.d.ts +0 -1
  75. package/dist/__tests__/call-types.test.d.ts +0 -1
  76. package/dist/__tests__/call.test.d.ts +0 -1
  77. package/dist/__tests__/channel-types.test.d.ts +0 -1
  78. package/dist/__tests__/channel.test.d.ts +0 -1
  79. package/dist/__tests__/command.test.d.ts +0 -1
  80. package/dist/__tests__/create-test-client.d.ts +0 -3
  81. package/dist/__tests__/create-token.test.d.ts +0 -1
  82. package/dist/__tests__/devices-push.test.d.ts +0 -1
  83. package/dist/__tests__/messages.test.d.ts +0 -1
  84. package/dist/__tests__/permissions-app-settings.test.d.ts +0 -1
  85. package/dist/__tests__/user-compat.test.d.ts +0 -1
  86. package/dist/__tests__/users.test.d.ts +0 -1
@@ -1,5 +1,5 @@
1
- import { StreamChatClient } from "./StreamChatClient";
2
- import { StreamVideoClient } from "./StreamVideoClient";
1
+ import { StreamChatClient } from './StreamChatClient';
2
+ import { StreamVideoClient } from './StreamVideoClient';
3
3
  import {
4
4
  APIError,
5
5
  BanRequest,
@@ -45,7 +45,7 @@ import {
45
45
  UserObjectRequest,
46
46
  UserResponse,
47
47
  UsersApi,
48
- } from "./gen/chat";
48
+ } from './gen/chat';
49
49
  import {
50
50
  Configuration,
51
51
  ErrorContext,
@@ -54,14 +54,14 @@ import {
54
54
  JSONApiResponse,
55
55
  RequestContext,
56
56
  ResponseContext,
57
- } from "./gen/video";
58
- import { v4 as uuidv4 } from "uuid";
59
- import { JWTServerToken, JWTUserToken } from "./utils/create-token";
57
+ } from './gen/video';
58
+ import { v4 as uuidv4 } from 'uuid';
59
+ import { JWTServerToken, JWTUserToken } from './utils/create-token';
60
60
 
61
- export type StreamClientOptions = {
61
+ export interface StreamClientOptions {
62
62
  timeout?: number;
63
63
  basePath?: string;
64
- };
64
+ }
65
65
 
66
66
  export class StreamClient {
67
67
  public readonly video: StreamVideoClient;
@@ -76,7 +76,7 @@ export class StreamClient {
76
76
  private readonly settingsApi: SettingsApi;
77
77
  private readonly eventsApi: EventsApi;
78
78
  private readonly tasksApi: TasksApi;
79
- private token: string;
79
+ private readonly token: string;
80
80
  private static readonly DEFAULT_TIMEOUT = 3000;
81
81
 
82
82
  /**
@@ -86,39 +86,39 @@ export class StreamClient {
86
86
  * @param config can be a string, which will be interpreted as base path (deprecated), or a config object
87
87
  */
88
88
  constructor(
89
- private apiKey: string,
90
- private secret: string,
91
- readonly config?: string | StreamClientOptions
89
+ private readonly apiKey: string,
90
+ private readonly secret: string,
91
+ readonly config?: string | StreamClientOptions,
92
92
  ) {
93
93
  this.token = JWTServerToken(this.secret);
94
94
  this.video = new StreamVideoClient(this);
95
95
  this.chat = new StreamChatClient(this);
96
96
 
97
- if (typeof config === "string") {
97
+ if (typeof config === 'string') {
98
98
  this.options.basePath = config;
99
99
  this.options.timeout = StreamClient.DEFAULT_TIMEOUT;
100
100
  } else {
101
- this.options.timeout = config?.timeout || StreamClient.DEFAULT_TIMEOUT;
101
+ this.options.timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT;
102
102
  }
103
103
 
104
104
  const chatConfiguration = this.getConfiguration();
105
- //@ts-expect-error typing problem
105
+ // @ts-expect-error typing problem
106
106
  this.usersApi = new UsersApi(chatConfiguration);
107
- //@ts-expect-error typing problem
107
+ // @ts-expect-error typing problem
108
108
  this.devicesApi = new DevicesApi(chatConfiguration);
109
- //@ts-expect-error typing problem
109
+ // @ts-expect-error typing problem
110
110
  this.pushApi = new PushApi(chatConfiguration);
111
- //@ts-expect-error typing problem
111
+ // @ts-expect-error typing problem
112
112
  this.serversideApi = new ServerSideApi(chatConfiguration);
113
- //@ts-expect-error typing problem
113
+ // @ts-expect-error typing problem
114
114
  this.testingApi = new TestingApi(chatConfiguration);
115
- //@ts-expect-error typing problem
115
+ // @ts-expect-error typing problem
116
116
  this.permissionsApi = new PermissionsV2Api(chatConfiguration);
117
- //@ts-expect-error typing problem
117
+ // @ts-expect-error typing problem
118
118
  this.settingsApi = new SettingsApi(chatConfiguration);
119
- //@ts-expect-error typing problem
119
+ // @ts-expect-error typing problem
120
120
  this.eventsApi = new EventsApi(chatConfiguration);
121
- //@ts-expect-error typing problem
121
+ // @ts-expect-error typing problem
122
122
  this.tasksApi = new TasksApi(chatConfiguration);
123
123
  }
124
124
 
@@ -134,7 +134,7 @@ export class StreamClient {
134
134
  userID: string,
135
135
  exp = Math.round(new Date().getTime() / 1000) + 60 * 60,
136
136
  iat = Math.round(Date.now() / 1000),
137
- call_cids?: string[]
137
+ call_cids?: string[],
138
138
  ) {
139
139
  const extra: { exp?: number; iat?: number; call_cids?: string[] } = {};
140
140
 
@@ -148,7 +148,7 @@ export class StreamClient {
148
148
 
149
149
  if (call_cids) {
150
150
  console.warn(
151
- `Use createCallToken method for creating call tokens, the "call_cids" param will be removed from the createToken method with version 0.2.0`
151
+ `Use createCallToken method for creating call tokens, the "call_cids" param will be removed from the createToken method with version 0.2.0`,
152
152
  );
153
153
  extra.call_cids = call_cids;
154
154
  }
@@ -168,7 +168,7 @@ export class StreamClient {
168
168
  userID: string,
169
169
  call_cids: string[],
170
170
  exp = Math.round(new Date().getTime() / 1000) + 60 * 60,
171
- iat = Math.round(Date.now() / 1000)
171
+ iat = Math.round(Date.now() / 1000),
172
172
  ) {
173
173
  const extra: { exp?: number; iat?: number; call_cids?: string[] } = {};
174
174
 
@@ -188,9 +188,11 @@ export class StreamClient {
188
188
  createDevice = (createDeviceRequest: CreateDeviceRequest) => {
189
189
  return this.devicesApi.createDevice({ createDeviceRequest });
190
190
  };
191
+
191
192
  deleteDevice = (requestParameters: DeleteDeviceRequest) => {
192
193
  return this.devicesApi.deleteDevice(requestParameters);
193
194
  };
195
+
194
196
  listDevices = (requestParameters: ListDevicesRequest) => {
195
197
  return this.devicesApi.listDevices(requestParameters);
196
198
  };
@@ -289,9 +291,9 @@ export class StreamClient {
289
291
  queryUsers = async (payload: QueryUsersRequest) => {
290
292
  payload.user = this.mapCustomDataBeforeSend(payload.user);
291
293
  const response = await this.usersApi.queryUsers({ payload });
292
- // @ts-expect-error
293
- response.users = response.users.map(
294
- (u) => this.mapCustomDataAfterReceive(u)!
294
+ // @ts-expect-error typing problem
295
+ response.users = response.users.map((u) =>
296
+ this.mapCustomDataAfterReceive(u),
295
297
  );
296
298
 
297
299
  return response;
@@ -329,13 +331,13 @@ export class StreamClient {
329
331
  upsertUsers = async (updateUsersRequest: UpdateUsersRequest) => {
330
332
  Object.keys(updateUsersRequest.users).forEach((key) => {
331
333
  updateUsersRequest.users[key] = this.mapCustomDataBeforeSend(
332
- updateUsersRequest.users[key]
334
+ updateUsersRequest.users[key],
333
335
  );
334
336
  });
335
337
  const response = await this.usersApi.updateUsers({ updateUsersRequest });
336
338
  Object.keys(response.users).forEach((key) => {
337
339
  response.users[key] = this.mapCustomDataAfterReceive(
338
- response.users[key]
340
+ response.users[key],
339
341
  )!;
340
342
  });
341
343
 
@@ -351,7 +353,7 @@ export class StreamClient {
351
353
  });
352
354
  Object.keys(response.users).forEach((key) => {
353
355
  response.users[key] = this.mapCustomDataAfterReceive(
354
- response.users[key]
356
+ response.users[key],
355
357
  )!;
356
358
  });
357
359
 
@@ -378,7 +380,7 @@ export class StreamClient {
378
380
 
379
381
  unmuteUser = (unmuteUserRequest: UnmuteUserRequest) => {
380
382
  unmuteUserRequest.user = this.mapCustomDataBeforeSend(
381
- unmuteUserRequest.user
383
+ unmuteUserRequest.user,
382
384
  );
383
385
  return this.usersApi.unmuteUser({ unmuteUserRequest });
384
386
  };
@@ -429,25 +431,25 @@ export class StreamClient {
429
431
  getConfiguration = (options?: { basePath?: string }) => {
430
432
  return new Configuration({
431
433
  apiKey: (name: string) => {
432
- const mapping: { [key: string]: string } = {
433
- "Stream-Auth-Type": "jwt",
434
+ const mapping: Record<string, string> = {
435
+ 'Stream-Auth-Type': 'jwt',
434
436
  api_key: this.apiKey,
435
437
  Authorization: this.token,
436
438
  };
437
439
 
438
440
  return mapping[name];
439
441
  },
440
- basePath: options?.basePath || this.options.basePath,
442
+ basePath: options?.basePath ?? this.options.basePath,
441
443
  headers: {
442
- "X-Stream-Client": "stream-node-" + process.env.PKG_VERSION,
444
+ 'X-Stream-Client': 'stream-node-' + process.env.PKG_VERSION,
443
445
  },
444
446
  middleware: [
445
447
  {
446
448
  pre: (context: RequestContext) => {
447
449
  context.init.headers = {
448
450
  ...context.init.headers,
449
- "x-client-request-id": uuidv4(),
450
- "Accept-Encoding": "gzip",
451
+ 'x-client-request-id': uuidv4(),
452
+ 'Accept-Encoding': 'gzip',
451
453
  };
452
454
 
453
455
  return Promise.resolve(context);
@@ -464,7 +466,7 @@ export class StreamClient {
464
466
  const response = new JSONApiResponse(context.response);
465
467
  const value = (await response.value()) as APIError;
466
468
  throw new Error(
467
- `Stream error code ${value.code}: ${value.message}`
469
+ `Stream error code ${value.code}: ${value.message}`,
468
470
  );
469
471
  }
470
472
  },
@@ -477,10 +479,10 @@ export class StreamClient {
477
479
  },
478
480
  onError: (context: ErrorContext) => {
479
481
  const error = context.error as DOMException;
480
- if (error.name === "AbortError" || error.name === "TimeoutError") {
482
+ if (error.name === 'AbortError' || error.name === 'TimeoutError') {
481
483
  throw new FetchError(
482
484
  error,
483
- `The request was aborted due to to the ${this.options.timeout}ms timeout, you can set the timeout in the StreamClient constructor`
485
+ `The request was aborted due to to the ${this.options.timeout}ms timeout, you can set the timeout in the StreamClient constructor`,
484
486
  );
485
487
  }
486
488
 
@@ -492,49 +494,50 @@ export class StreamClient {
492
494
  queryParamsStringify: (params: HTTPQuery) => {
493
495
  const newParams = [];
494
496
  for (const k in params) {
495
- if (Array.isArray(params[k]) || typeof params[k] === "object") {
497
+ if (Array.isArray(params[k]) || typeof params[k] === 'object') {
496
498
  newParams.push(
497
- `${k}=${encodeURIComponent(JSON.stringify(params[k]))}`
499
+ `${k}=${encodeURIComponent(JSON.stringify(params[k]))}`,
498
500
  );
499
501
  } else {
500
502
  const value = params[k];
501
503
  if (
502
- typeof value === "string" ||
503
- typeof value === "number" ||
504
- typeof value === "boolean"
504
+ typeof value === 'string' ||
505
+ typeof value === 'number' ||
506
+ typeof value === 'boolean'
505
507
  ) {
506
508
  newParams.push(`${k}=${encodeURIComponent(value)}`);
507
509
  }
508
510
  }
509
511
  }
510
512
 
511
- return newParams.join("&");
513
+ return newParams.join('&');
512
514
  },
513
515
  });
514
516
  };
515
517
 
516
- private reservedKeywords = [
517
- "ban_expires",
518
- "banned",
519
- "id",
520
- "invisible",
521
- "language",
522
- "push_notifications",
523
- "revoke_tokens_issued_before",
524
- "role",
525
- "teams",
526
- "created_at",
527
- "deactivated_at",
528
- "deleted_at",
529
- "last_active",
530
- "online",
531
- "updated_at",
532
- "shadow_banned",
533
- "name",
534
- "image",
518
+ private readonly reservedKeywords = [
519
+ 'ban_expires',
520
+ 'banned',
521
+ 'id',
522
+ 'invisible',
523
+ 'language',
524
+ 'push_notifications',
525
+ 'revoke_tokens_issued_before',
526
+ 'role',
527
+ 'teams',
528
+ 'created_at',
529
+ 'deactivated_at',
530
+ 'deleted_at',
531
+ 'last_active',
532
+ 'online',
533
+ 'updated_at',
534
+ 'shadow_banned',
535
+ 'name',
536
+ 'image',
535
537
  ];
536
- private mapCustomDataBeforeSend = (
537
- user: UserObject | UserObjectRequest | UserResponse | undefined
538
+
539
+ private readonly mapCustomDataBeforeSend = (
540
+ user: UserObject | UserObjectRequest | UserResponse | undefined,
538
541
  ) => {
539
542
  if (!user) {
540
543
  return undefined;
@@ -544,14 +547,14 @@ export class StreamClient {
544
547
  return { ...copy, ...user.custom };
545
548
  };
546
549
 
547
- private mapCustomDataAfterReceive = (
548
- user: UserObject | UserResponse | undefined
549
- ) => {
550
+ private mapCustomDataAfterReceive<T = UserObject | UserResponse | undefined>(
551
+ user: T,
552
+ ) {
550
553
  if (!user) {
551
554
  return undefined;
552
555
  }
553
- // @ts-expect-error
554
- let result: UserObject | UserResponse = {};
556
+ // @ts-expect-error typing problem
557
+ const result: UserObject | UserResponse = {};
555
558
  Object.keys(user).forEach((key) => {
556
559
  if (!this.reservedKeywords.includes(key)) {
557
560
  if (!result.custom) {
@@ -564,5 +567,5 @@ export class StreamClient {
564
567
  });
565
568
 
566
569
  return result;
567
- };
570
+ }
568
571
  }
@@ -1,5 +1,5 @@
1
- import { StreamCall } from "./StreamCall";
2
- import { StreamClient } from "./StreamClient";
1
+ import { StreamCall } from './StreamCall';
2
+ import { StreamClient } from './StreamClient';
3
3
  import {
4
4
  DefaultApi,
5
5
  DeleteCallTypeRequest,
@@ -8,17 +8,17 @@ import {
8
8
  VideoCreateCallTypeRequest,
9
9
  VideoQueryCallsRequest,
10
10
  VideoUpdateCallTypeRequest,
11
- } from "./gen/video";
11
+ } from './gen/video';
12
12
 
13
13
  export class StreamVideoClient {
14
14
  private readonly apiClient: DefaultApi;
15
15
  private readonly videoServerSideApiClient: ServerSideApi;
16
16
 
17
- constructor(private streamClient: StreamClient) {
17
+ constructor(private readonly streamClient: StreamClient) {
18
18
  const configuration = this.streamClient.getConfiguration({
19
19
  basePath:
20
- this.streamClient.options.basePath ||
21
- "https://video.stream-io-api.com/video",
20
+ this.streamClient.options.basePath ??
21
+ 'https://video.stream-io-api.com/video',
22
22
  });
23
23
  this.apiClient = new DefaultApi(configuration);
24
24
  this.videoServerSideApiClient = new ServerSideApi(configuration);
@@ -30,7 +30,7 @@ export class StreamVideoClient {
30
30
 
31
31
  queryCalls = (request?: VideoQueryCallsRequest) => {
32
32
  return this.apiClient.queryCalls({
33
- videoQueryCallsRequest: request || {},
33
+ videoQueryCallsRequest: request ?? {},
34
34
  });
35
35
  };
36
36
 
@@ -54,7 +54,7 @@ export class StreamVideoClient {
54
54
 
55
55
  updateCallType = (
56
56
  name: string,
57
- videoUpdateCallTypeRequest: VideoUpdateCallTypeRequest
57
+ videoUpdateCallTypeRequest: VideoUpdateCallTypeRequest,
58
58
  ) => {
59
59
  return this.videoServerSideApiClient.updateCallType({
60
60
  name,
@@ -4,7 +4,7 @@
4
4
  * Stream Chat API
5
5
  * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
6
  *
7
- * The version of the OpenAPI document: v89.9.2
7
+ * The version of the OpenAPI document: v92.5.0
8
8
  *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).