@stream-io/node-sdk 0.4.19 → 0.4.20

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.
package/dist/index.es.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import jwt from 'jsonwebtoken';
2
2
  import { v4 } from 'uuid';
3
3
  import crypto from 'crypto';
4
+ import { Agent } from 'undici';
4
5
 
5
6
  const ChannelOwnCapability = {
6
7
  BAN_CHANNEL_MEMBERS: 'ban-channel-members',
@@ -138,7 +139,7 @@ class BaseApi {
138
139
  Authorization: this.apiConfig.token,
139
140
  'stream-auth-type': 'jwt',
140
141
  'Content-Type': 'application/json',
141
- 'X-Stream-Client': 'stream-node-' + "0.4.19",
142
+ 'X-Stream-Client': 'stream-node-' + "0.4.20",
142
143
  'Accept-Encoding': 'gzip',
143
144
  'x-client-request-id': clientRequestId,
144
145
  };
@@ -149,6 +150,8 @@ class BaseApi {
149
150
  method,
150
151
  body: JSON.stringify(body),
151
152
  headers,
153
+ /** @ts-expect-error we get types from DOM here, but we should use node types */
154
+ dispatcher: this.dispatcher,
152
155
  });
153
156
  const responseHeaders = response.headers;
154
157
  const metadata = {
@@ -209,6 +212,7 @@ class BaseApi {
209
212
  }
210
213
  return newParams.join('&');
211
214
  };
215
+ this.dispatcher = this.apiConfig.agent;
212
216
  }
213
217
  }
214
218
 
@@ -512,6 +516,7 @@ decoders.ChannelStateResponse = (input) => {
512
516
  read: { type: 'ReadStateResponse', isSingle: false },
513
517
  watchers: { type: 'UserResponse', isSingle: false },
514
518
  channel: { type: 'ChannelResponse', isSingle: true },
519
+ draft: { type: 'DraftResponse', isSingle: true },
515
520
  membership: { type: 'ChannelMember', isSingle: true },
516
521
  push_preferences: { type: 'ChannelPushPreferences', isSingle: true },
517
522
  };
@@ -528,6 +533,7 @@ decoders.ChannelStateResponseFields = (input) => {
528
533
  read: { type: 'ReadStateResponse', isSingle: false },
529
534
  watchers: { type: 'UserResponse', isSingle: false },
530
535
  channel: { type: 'ChannelResponse', isSingle: true },
536
+ draft: { type: 'DraftResponse', isSingle: true },
531
537
  membership: { type: 'ChannelMember', isSingle: true },
532
538
  push_preferences: { type: 'ChannelPushPreferences', isSingle: true },
533
539
  };
@@ -654,6 +660,22 @@ decoders.DeviceResponse = (input) => {
654
660
  };
655
661
  return decode(typeMappings, input);
656
662
  };
663
+ decoders.DraftPayloadResponse = (input) => {
664
+ const typeMappings = {
665
+ mentioned_users: { type: 'UserResponse', isSingle: false },
666
+ };
667
+ return decode(typeMappings, input);
668
+ };
669
+ decoders.DraftResponse = (input) => {
670
+ const typeMappings = {
671
+ created_at: { type: 'DatetimeType', isSingle: true },
672
+ message: { type: 'DraftPayloadResponse', isSingle: true },
673
+ channel: { type: 'ChannelResponse', isSingle: true },
674
+ parent_message: { type: 'MessageResponse', isSingle: true },
675
+ quoted_message: { type: 'MessageResponse', isSingle: true },
676
+ };
677
+ return decode(typeMappings, input);
678
+ };
657
679
  decoders.EgressRTMPResponse = (input) => {
658
680
  const typeMappings = {
659
681
  started_at: { type: 'DatetimeType', isSingle: true },
@@ -704,7 +726,7 @@ decoders.ExportUserResponse = (input) => {
704
726
  };
705
727
  return decode(typeMappings, input);
706
728
  };
707
- decoders.Flag2 = (input) => {
729
+ decoders.Flag = (input) => {
708
730
  const typeMappings = {
709
731
  created_at: { type: 'DatetimeType', isSingle: true },
710
732
  updated_at: { type: 'DatetimeType', isSingle: true },
@@ -712,14 +734,6 @@ decoders.Flag2 = (input) => {
712
734
  };
713
735
  return decode(typeMappings, input);
714
736
  };
715
- decoders.Flag2Response = (input) => {
716
- const typeMappings = {
717
- created_at: { type: 'DatetimeType', isSingle: true },
718
- updated_at: { type: 'DatetimeType', isSingle: true },
719
- user: { type: 'UserResponse', isSingle: true },
720
- };
721
- return decode(typeMappings, input);
722
- };
723
737
  decoders.FlagDetails = (input) => {
724
738
  const typeMappings = {
725
739
  automod: { type: 'AutomodDetails', isSingle: true },
@@ -779,12 +793,6 @@ decoders.GetCallTypeResponse = (input) => {
779
793
  };
780
794
  return decode(typeMappings, input);
781
795
  };
782
- decoders.GetCampaignResponse = (input) => {
783
- const typeMappings = {
784
- campaign: { type: 'CampaignResponse', isSingle: true },
785
- };
786
- return decode(typeMappings, input);
787
- };
788
796
  decoders.GetChannelTypeResponse = (input) => {
789
797
  const typeMappings = {
790
798
  created_at: { type: 'DatetimeType', isSingle: true },
@@ -806,6 +814,12 @@ decoders.GetConfigResponse = (input) => {
806
814
  };
807
815
  return decode(typeMappings, input);
808
816
  };
817
+ decoders.GetDraftResponse = (input) => {
818
+ const typeMappings = {
819
+ draft: { type: 'DraftResponse', isSingle: true },
820
+ };
821
+ return decode(typeMappings, input);
822
+ };
809
823
  decoders.GetImportResponse = (input) => {
810
824
  const typeMappings = {
811
825
  import_task: { type: 'ImportTask', isSingle: true },
@@ -869,14 +883,6 @@ decoders.GetThreadResponse = (input) => {
869
883
  };
870
884
  return decode(typeMappings, input);
871
885
  };
872
- decoders.GetUserModerationReportResponse = (input) => {
873
- const typeMappings = {
874
- user_blocks: { type: 'UserBlock', isSingle: false },
875
- user_mutes: { type: 'UserMute', isSingle: false },
876
- user: { type: 'UserResponse', isSingle: true },
877
- };
878
- return decode(typeMappings, input);
879
- };
880
886
  decoders.GoLiveResponse = (input) => {
881
887
  const typeMappings = {
882
888
  call: { type: 'CallResponse', isSingle: true },
@@ -1049,6 +1055,7 @@ decoders.MessageResponse = (input) => {
1049
1055
  pin_expires: { type: 'DatetimeType', isSingle: true },
1050
1056
  pinned_at: { type: 'DatetimeType', isSingle: true },
1051
1057
  thread_participants: { type: 'UserResponse', isSingle: false },
1058
+ draft: { type: 'DraftResponse', isSingle: true },
1052
1059
  pinned_by: { type: 'UserResponse', isSingle: true },
1053
1060
  poll: { type: 'PollResponseData', isSingle: true },
1054
1061
  quoted_message: { type: 'MessageResponse', isSingle: true },
@@ -1070,6 +1077,7 @@ decoders.MessageWithChannelResponse = (input) => {
1070
1077
  pin_expires: { type: 'DatetimeType', isSingle: true },
1071
1078
  pinned_at: { type: 'DatetimeType', isSingle: true },
1072
1079
  thread_participants: { type: 'UserResponse', isSingle: false },
1080
+ draft: { type: 'DraftResponse', isSingle: true },
1073
1081
  pinned_by: { type: 'UserResponse', isSingle: true },
1074
1082
  poll: { type: 'PollResponseData', isSingle: true },
1075
1083
  quoted_message: { type: 'MessageResponse', isSingle: true },
@@ -1077,13 +1085,6 @@ decoders.MessageWithChannelResponse = (input) => {
1077
1085
  };
1078
1086
  return decode(typeMappings, input);
1079
1087
  };
1080
- decoders.ModerationUsageStats = (input) => {
1081
- const typeMappings = {
1082
- reference_date: { type: 'DatetimeType', isSingle: true },
1083
- updated_at: { type: 'DatetimeType', isSingle: true },
1084
- };
1085
- return decode(typeMappings, input);
1086
- };
1087
1088
  decoders.MuteChannelResponse = (input) => {
1088
1089
  const typeMappings = {
1089
1090
  channel_mutes: { type: 'ChannelMute', isSingle: false },
@@ -1261,6 +1262,12 @@ decoders.QueryChannelsResponse = (input) => {
1261
1262
  };
1262
1263
  return decode(typeMappings, input);
1263
1264
  };
1265
+ decoders.QueryDraftsResponse = (input) => {
1266
+ const typeMappings = {
1267
+ drafts: { type: 'DraftResponse', isSingle: false },
1268
+ };
1269
+ return decode(typeMappings, input);
1270
+ };
1264
1271
  decoders.QueryFeedModerationTemplate = (input) => {
1265
1272
  const typeMappings = {
1266
1273
  created_at: { type: 'DatetimeType', isSingle: true },
@@ -1334,12 +1341,6 @@ decoders.QueryThreadsResponse = (input) => {
1334
1341
  };
1335
1342
  return decode(typeMappings, input);
1336
1343
  };
1337
- decoders.QueryUsageStatsResponse = (input) => {
1338
- const typeMappings = {
1339
- items: { type: 'ModerationUsageStats', isSingle: false },
1340
- };
1341
- return decode(typeMappings, input);
1342
- };
1343
1344
  decoders.QueryUsersResponse = (input) => {
1344
1345
  const typeMappings = {
1345
1346
  users: { type: 'FullUserResponse', isSingle: false },
@@ -1388,7 +1389,7 @@ decoders.ReviewQueueItem = (input) => {
1388
1389
  updated_at: { type: 'DatetimeType', isSingle: true },
1389
1390
  actions: { type: 'ActionLog', isSingle: false },
1390
1391
  bans: { type: 'Ban', isSingle: false },
1391
- flags: { type: 'Flag2', isSingle: false },
1392
+ flags: { type: 'Flag', isSingle: false },
1392
1393
  assigned_to: { type: 'User', isSingle: true },
1393
1394
  entity_creator: { type: 'EntityCreator', isSingle: true },
1394
1395
  feeds_v2_reaction: { type: 'Reaction', isSingle: true },
@@ -1403,7 +1404,6 @@ decoders.ReviewQueueItemResponse = (input) => {
1403
1404
  updated_at: { type: 'DatetimeType', isSingle: true },
1404
1405
  actions: { type: 'ActionLogResponse', isSingle: false },
1405
1406
  bans: { type: 'Ban', isSingle: false },
1406
- flags: { type: 'Flag2Response', isSingle: false },
1407
1407
  completed_at: { type: 'DatetimeType', isSingle: true },
1408
1408
  reviewed_at: { type: 'DatetimeType', isSingle: true },
1409
1409
  assigned_to: { type: 'UserResponse', isSingle: true },
@@ -1441,6 +1441,7 @@ decoders.SearchResultMessage = (input) => {
1441
1441
  pinned_at: { type: 'DatetimeType', isSingle: true },
1442
1442
  thread_participants: { type: 'UserResponse', isSingle: false },
1443
1443
  channel: { type: 'ChannelResponse', isSingle: true },
1444
+ draft: { type: 'DraftResponse', isSingle: true },
1444
1445
  pinned_by: { type: 'UserResponse', isSingle: true },
1445
1446
  poll: { type: 'PollResponseData', isSingle: true },
1446
1447
  quoted_message: { type: 'MessageResponse', isSingle: true },
@@ -1483,12 +1484,6 @@ decoders.SendReactionResponse = (input) => {
1483
1484
  };
1484
1485
  return decode(typeMappings, input);
1485
1486
  };
1486
- decoders.StartCampaignResponse = (input) => {
1487
- const typeMappings = {
1488
- campaign: { type: 'CampaignResponse', isSingle: true },
1489
- };
1490
- return decode(typeMappings, input);
1491
- };
1492
1487
  decoders.StopLiveResponse = (input) => {
1493
1488
  const typeMappings = {
1494
1489
  call: { type: 'CallResponse', isSingle: true },
@@ -1535,6 +1530,7 @@ decoders.ThreadStateResponse = (input) => {
1535
1530
  thread_participants: { type: 'ThreadParticipant', isSingle: false },
1536
1531
  channel: { type: 'ChannelResponse', isSingle: true },
1537
1532
  created_by: { type: 'UserResponse', isSingle: true },
1533
+ draft: { type: 'DraftResponse', isSingle: true },
1538
1534
  parent_message: { type: 'MessageResponse', isSingle: true },
1539
1535
  };
1540
1536
  return decode(typeMappings, input);
@@ -1693,12 +1689,6 @@ decoders.User = (input) => {
1693
1689
  };
1694
1690
  return decode(typeMappings, input);
1695
1691
  };
1696
- decoders.UserBlock = (input) => {
1697
- const typeMappings = {
1698
- created_at: { type: 'DatetimeType', isSingle: true },
1699
- };
1700
- return decode(typeMappings, input);
1701
- };
1702
1692
  decoders.UserMute = (input) => {
1703
1693
  const typeMappings = {
1704
1694
  created_at: { type: 'DatetimeType', isSingle: true },
@@ -3086,6 +3076,7 @@ class ChatApi extends BaseApi {
3086
3076
  limit: request?.limit,
3087
3077
  next: request?.next,
3088
3078
  prev: request?.prev,
3079
+ user_limit: request?.user_limit,
3089
3080
  sort: request?.sort,
3090
3081
  filter: request?.filter,
3091
3082
  };
@@ -3094,10 +3085,15 @@ class ChatApi extends BaseApi {
3094
3085
  return { ...response.body, metadata: response.metadata };
3095
3086
  };
3096
3087
  this.getCampaign = async (request) => {
3088
+ const queryParams = {
3089
+ prev: request?.prev,
3090
+ next: request?.next,
3091
+ limit: request?.limit,
3092
+ };
3097
3093
  const pathParams = {
3098
3094
  id: request?.id,
3099
3095
  };
3100
- const response = await this.sendRequest('GET', '/api/v2/chat/campaigns/{id}', pathParams, undefined);
3096
+ const response = await this.sendRequest('GET', '/api/v2/chat/campaigns/{id}', pathParams, queryParams);
3101
3097
  decoders.GetCampaignResponse?.(response.body);
3102
3098
  return { ...response.body, metadata: response.metadata };
3103
3099
  };
@@ -3227,6 +3223,32 @@ class ChatApi extends BaseApi {
3227
3223
  decoders.UpdateChannelResponse?.(response.body);
3228
3224
  return { ...response.body, metadata: response.metadata };
3229
3225
  };
3226
+ this.deleteDraft = async (request) => {
3227
+ const queryParams = {
3228
+ parent_id: request?.parent_id,
3229
+ user_id: request?.user_id,
3230
+ };
3231
+ const pathParams = {
3232
+ type: request?.type,
3233
+ id: request?.id,
3234
+ };
3235
+ const response = await this.sendRequest('DELETE', '/api/v2/chat/channels/{type}/{id}/draft', pathParams, queryParams);
3236
+ decoders.Response?.(response.body);
3237
+ return { ...response.body, metadata: response.metadata };
3238
+ };
3239
+ this.getDraft = async (request) => {
3240
+ const queryParams = {
3241
+ parent_id: request?.parent_id,
3242
+ user_id: request?.user_id,
3243
+ };
3244
+ const pathParams = {
3245
+ type: request?.type,
3246
+ id: request?.id,
3247
+ };
3248
+ const response = await this.sendRequest('GET', '/api/v2/chat/channels/{type}/{id}/draft', pathParams, queryParams);
3249
+ decoders.GetDraftResponse?.(response.body);
3250
+ return { ...response.body, metadata: response.metadata };
3251
+ };
3230
3252
  this.sendEvent = async (request) => {
3231
3253
  const pathParams = {
3232
3254
  type: request?.type,
@@ -3565,6 +3587,20 @@ class ChatApi extends BaseApi {
3565
3587
  decoders.UpdateCommandResponse?.(response.body);
3566
3588
  return { ...response.body, metadata: response.metadata };
3567
3589
  };
3590
+ this.queryDrafts = async (request) => {
3591
+ const body = {
3592
+ limit: request?.limit,
3593
+ next: request?.next,
3594
+ prev: request?.prev,
3595
+ user_id: request?.user_id,
3596
+ sort: request?.sort,
3597
+ filter: request?.filter,
3598
+ user: request?.user,
3599
+ };
3600
+ const response = await this.sendRequest('POST', '/api/v2/chat/drafts/query', undefined, undefined, body);
3601
+ decoders.QueryDraftsResponse?.(response.body);
3602
+ return { ...response.body, metadata: response.metadata };
3603
+ };
3568
3604
  this.exportChannels = async (request) => {
3569
3605
  const body = {
3570
3606
  channels: request?.channels,
@@ -4181,6 +4217,22 @@ class ChannelApi {
4181
4217
  ...request,
4182
4218
  });
4183
4219
  };
4220
+ this.deleteDraft = (request) => {
4221
+ if (!this.id) {
4222
+ throw new Error(`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`);
4223
+ }
4224
+ return this.chatApi.deleteDraft({
4225
+ id: this.id,
4226
+ type: this.type,
4227
+ ...request,
4228
+ });
4229
+ };
4230
+ this.getDraft = (request) => {
4231
+ if (!this.id) {
4232
+ throw new Error(`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`);
4233
+ }
4234
+ return this.chatApi.getDraft({ id: this.id, type: this.type, ...request });
4235
+ };
4184
4236
  this.sendEvent = (request) => {
4185
4237
  if (!this.id) {
4186
4238
  throw new Error(`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`);
@@ -4366,15 +4418,6 @@ class StreamChatClient extends ChatApi {
4366
4418
  class ModerationApi extends BaseApi {
4367
4419
  constructor() {
4368
4420
  super(...arguments);
4369
- this.getModerationAnalytics = async (request) => {
4370
- const body = {
4371
- end_date: request?.end_date,
4372
- start_date: request?.start_date,
4373
- };
4374
- const response = await this.sendRequest('POST', '/api/v2/moderation/analytics', undefined, undefined, body);
4375
- decoders.GetModerationAnalyticsResponse?.(response.body);
4376
- return { ...response.body, metadata: response.metadata };
4377
- };
4378
4421
  this.ban = async (request) => {
4379
4422
  const body = {
4380
4423
  target_user_id: request?.target_user_id,
@@ -4414,7 +4457,6 @@ class ModerationApi extends BaseApi {
4414
4457
  team: request?.team,
4415
4458
  user_id: request?.user_id,
4416
4459
  ai_image_config: request?.ai_image_config,
4417
- ai_image_lite_config: request?.ai_image_lite_config,
4418
4460
  ai_text_config: request?.ai_text_config,
4419
4461
  ai_video_config: request?.ai_video_config,
4420
4462
  automod_platform_circumvention_config: request?.automod_platform_circumvention_config,
@@ -4529,11 +4571,6 @@ class ModerationApi extends BaseApi {
4529
4571
  decoders.QueryModerationLogsResponse?.(response.body);
4530
4572
  return { ...response.body, metadata: response.metadata };
4531
4573
  };
4532
- this.getModeratorStats = async () => {
4533
- const response = await this.sendRequest('GET', '/api/v2/moderation/moderator_stats', undefined, undefined);
4534
- decoders.ModeratorStatsResponse?.(response.body);
4535
- return { ...response.body, metadata: response.metadata };
4536
- };
4537
4574
  this.mute = async (request) => {
4538
4575
  const body = {
4539
4576
  target_ids: request?.target_ids,
@@ -4545,11 +4582,6 @@ class ModerationApi extends BaseApi {
4545
4582
  decoders.MuteResponse?.(response.body);
4546
4583
  return { ...response.body, metadata: response.metadata };
4547
4584
  };
4548
- this.getQueueStats = async () => {
4549
- const response = await this.sendRequest('GET', '/api/v2/moderation/queue_stats', undefined, undefined);
4550
- decoders.QueueStatsResponse?.(response.body);
4551
- return { ...response.body, metadata: response.metadata };
4552
- };
4553
4585
  this.queryReviewQueue = async (request) => {
4554
4586
  const body = {
4555
4587
  limit: request?.limit,
@@ -4619,31 +4651,6 @@ class ModerationApi extends BaseApi {
4619
4651
  decoders.UnmuteResponse?.(response.body);
4620
4652
  return { ...response.body, metadata: response.metadata };
4621
4653
  };
4622
- this.queryUsageStats = async (request) => {
4623
- const body = {
4624
- limit: request?.limit,
4625
- next: request?.next,
4626
- prev: request?.prev,
4627
- user_id: request?.user_id,
4628
- sort: request?.sort,
4629
- filter: request?.filter,
4630
- user: request?.user,
4631
- };
4632
- const response = await this.sendRequest('POST', '/api/v2/moderation/usage_stats', undefined, undefined, body);
4633
- decoders.QueryUsageStatsResponse?.(response.body);
4634
- return { ...response.body, metadata: response.metadata };
4635
- };
4636
- this.getUserReport = async (request) => {
4637
- const queryParams = {
4638
- user_id: request?.user_id,
4639
- create_user_if_not_exists: request?.create_user_if_not_exists,
4640
- include_user_mutes: request?.include_user_mutes,
4641
- include_user_blocks: request?.include_user_blocks,
4642
- };
4643
- const response = await this.sendRequest('GET', '/api/v2/moderation/user_report', undefined, queryParams);
4644
- decoders.GetUserModerationReportResponse?.(response.body);
4645
- return { ...response.body, metadata: response.metadata };
4646
- };
4647
4654
  }
4648
4655
  }
4649
4656
 
@@ -4660,9 +4667,15 @@ class StreamClient extends CommonApi {
4660
4667
  constructor(apiKey, secret, config) {
4661
4668
  const token = JWTServerToken(secret);
4662
4669
  const timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT;
4670
+ const agent = config?.agent ??
4671
+ new Agent({
4672
+ connections: config?.maxConnections === undefined
4673
+ ? StreamClient.MAX_CONNECTIONS
4674
+ : config.maxConnections,
4675
+ });
4663
4676
  const chatBaseUrl = config?.basePath ?? 'https://chat.stream-io-api.com';
4664
4677
  const videoBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com';
4665
- super({ apiKey, token, timeout, baseUrl: chatBaseUrl });
4678
+ super({ apiKey, token, timeout, baseUrl: chatBaseUrl, agent });
4666
4679
  this.apiKey = apiKey;
4667
4680
  this.secret = secret;
4668
4681
  this.config = config;
@@ -4763,22 +4776,26 @@ class StreamClient extends CommonApi {
4763
4776
  token,
4764
4777
  timeout,
4765
4778
  baseUrl: videoBaseUrl,
4779
+ agent,
4766
4780
  });
4767
4781
  this.chat = new StreamChatClient({
4768
4782
  apiKey,
4769
4783
  token,
4770
4784
  timeout,
4771
4785
  baseUrl: chatBaseUrl,
4786
+ agent,
4772
4787
  });
4773
4788
  this.moderation = new StreamModerationClient({
4774
4789
  apiKey,
4775
4790
  token,
4776
4791
  timeout,
4777
4792
  baseUrl: chatBaseUrl,
4793
+ agent,
4778
4794
  });
4779
4795
  }
4780
4796
  }
4781
4797
  StreamClient.DEFAULT_TIMEOUT = 3000;
4798
+ StreamClient.MAX_CONNECTIONS = 100;
4782
4799
 
4783
4800
  export { ChannelOwnCapability, OwnCapability, StreamCall, StreamChannel, StreamChatClient, StreamClient, StreamVideoClient };
4784
4801
  //# sourceMappingURL=index.es.mjs.map