@stream-io/node-sdk 0.1.3 → 0.1.4

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.js CHANGED
@@ -8339,7 +8339,8 @@ class StreamCall {
8339
8339
  };
8340
8340
  this.baseRequest = { id: this.id, type: this.type };
8341
8341
  const configuration = this.streamClient.getConfiguration({
8342
- basePath: this.streamClient.basePath || "https://video.stream-io-api.com/video",
8342
+ basePath: this.streamClient.options.basePath ||
8343
+ "https://video.stream-io-api.com/video",
8343
8344
  });
8344
8345
  this.apiClient = new DefaultApi(configuration);
8345
8346
  }
@@ -8377,7 +8378,8 @@ class StreamVideoClient {
8377
8378
  });
8378
8379
  };
8379
8380
  const configuration = this.streamClient.getConfiguration({
8380
- basePath: this.streamClient.basePath || "https://video.stream-io-api.com/video",
8381
+ basePath: this.streamClient.options.basePath ||
8382
+ "https://video.stream-io-api.com/video",
8381
8383
  });
8382
8384
  this.apiClient = new DefaultApi(configuration);
8383
8385
  this.videoServerSideApiClient = new ServerSideApi(configuration);
@@ -8408,10 +8410,17 @@ function JWTServerToken(apiSecret, jwtOptions = {}) {
8408
8410
  }
8409
8411
 
8410
8412
  class StreamClient {
8411
- constructor(apiKey, secret, basePath) {
8413
+ /**
8414
+ *
8415
+ * @param apiKey
8416
+ * @param secret
8417
+ * @param config can be a string, which will be interpreted as base path (deprecated), or a config object
8418
+ */
8419
+ constructor(apiKey, secret, config) {
8412
8420
  this.apiKey = apiKey;
8413
8421
  this.secret = secret;
8414
- this.basePath = basePath;
8422
+ this.config = config;
8423
+ this.options = {};
8415
8424
  this.createDevice = (createDeviceRequest) => {
8416
8425
  return this.devicesApi.createDevice({ createDeviceRequest });
8417
8426
  };
@@ -8601,9 +8610,9 @@ class StreamClient {
8601
8610
  };
8602
8611
  return mapping[name];
8603
8612
  },
8604
- basePath: (options === null || options === void 0 ? void 0 : options.basePath) || this.basePath,
8613
+ basePath: (options === null || options === void 0 ? void 0 : options.basePath) || this.options.basePath,
8605
8614
  headers: {
8606
- "X-Stream-Client": "stream-node-" + "0.1.2",
8615
+ "X-Stream-Client": "stream-node-" + "0.1.3",
8607
8616
  },
8608
8617
  middleware: [
8609
8618
  {
@@ -8624,6 +8633,19 @@ class StreamClient {
8624
8633
  }
8625
8634
  }),
8626
8635
  },
8636
+ {
8637
+ pre: (context) => {
8638
+ context.init.signal = AbortSignal.timeout(this.options.timeout);
8639
+ return Promise.resolve(context);
8640
+ },
8641
+ onError: (context) => {
8642
+ const error = context.error;
8643
+ if (error.name === "AbortError" || error.name === "TimeoutError") {
8644
+ throw new FetchError(error, `The request was aborted due to to the ${this.options.timeout}ms timeout, you can set the timeout in the StreamClient constructor`);
8645
+ }
8646
+ return Promise.resolve(context.response);
8647
+ },
8648
+ },
8627
8649
  ],
8628
8650
  // https://github.com/OpenAPITools/openapi-generator/issues/13222
8629
8651
  queryParamsStringify: (params) => {
@@ -8695,6 +8717,13 @@ class StreamClient {
8695
8717
  this.token = JWTServerToken(this.secret);
8696
8718
  this.video = new StreamVideoClient(this);
8697
8719
  this.chat = new StreamChatClient(this);
8720
+ if (typeof config === "string") {
8721
+ this.options.basePath = config;
8722
+ this.options.timeout = StreamClient.DEFAULT_TIMEOUT;
8723
+ }
8724
+ else {
8725
+ this.options.timeout = (config === null || config === void 0 ? void 0 : config.timeout) || StreamClient.DEFAULT_TIMEOUT;
8726
+ }
8698
8727
  const chatConfiguration = this.getConfiguration();
8699
8728
  //@ts-expect-error typing problem
8700
8729
  this.usersApi = new UsersApi(chatConfiguration);
@@ -8719,11 +8748,11 @@ class StreamClient {
8719
8748
  *
8720
8749
  * @param userID
8721
8750
  * @param exp
8722
- * @param iat
8751
+ * @param iat deprecated, the default date will be set internally
8723
8752
  * @param call_cids this parameter is deprecated use `createCallToken` for call tokens
8724
8753
  * @returns
8725
8754
  */
8726
- createToken(userID, exp, iat = Math.round(Date.now() / 1000), call_cids) {
8755
+ createToken(userID, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000), call_cids) {
8727
8756
  const extra = {};
8728
8757
  if (exp) {
8729
8758
  extra.exp = exp;
@@ -8737,7 +8766,15 @@ class StreamClient {
8737
8766
  }
8738
8767
  return JWTUserToken(this.secret, userID, extra);
8739
8768
  }
8740
- createCallToken(userID, call_cids, exp, iat = Math.round(Date.now() / 1000)) {
8769
+ /**
8770
+ *
8771
+ * @param userID
8772
+ * @param call_cids
8773
+ * @param exp
8774
+ * @param iat this is deprecated, the current date will be set internally
8775
+ * @returns
8776
+ */
8777
+ createCallToken(userID, call_cids, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000)) {
8741
8778
  const extra = {};
8742
8779
  if (exp) {
8743
8780
  extra.exp = exp;
@@ -8749,6 +8786,7 @@ class StreamClient {
8749
8786
  return JWTUserToken(this.secret, userID, extra);
8750
8787
  }
8751
8788
  }
8789
+ StreamClient.DEFAULT_TIMEOUT = 3000;
8752
8790
 
8753
8791
  export { APNConfigRequestAuthTypeEnum, AppSearchBackendEnum, AsyncModerationCallbackConfigRequestModeEnum, AudioSettingsDefaultDeviceEnum, BlockListOptionsBehaviorEnum, BlockListOptionsRequestBehaviorEnum, ChannelConfigAutomodBehaviorEnum, ChannelConfigAutomodEnum, ChannelConfigBlocklistBehaviorEnum, ChannelConfigRequestBlocklistBehaviorEnum, ChannelConfigWithInfoAutomodBehaviorEnum, ChannelConfigWithInfoAutomodEnum, ChannelConfigWithInfoBlocklistBehaviorEnum, ChannelConfigWithInfoRequestAutomodBehaviorEnum, ChannelConfigWithInfoRequestAutomodEnum, ChannelConfigWithInfoRequestBlocklistBehaviorEnum, ChannelMemberRequestRoleEnum, ChannelMemberRoleEnum, ChannelTypeConfigAutomodBehaviorEnum, ChannelTypeConfigAutomodEnum, ChannelTypeConfigBlocklistBehaviorEnum, CheckPushRequestPushProviderTypeEnum, CheckSNSResponseStatusEnum, CheckSQSResponseStatusEnum, ConfigDefaultRoleEnum, ConfigRequestDefaultRoleEnum, CreateCallRequestTypeEnum, CreateChannelTypeRequestAutomodBehaviorEnum, CreateChannelTypeRequestAutomodEnum, CreateChannelTypeRequestBlocklistBehaviorEnum, CreateChannelTypeResponseAutomodBehaviorEnum, CreateChannelTypeResponseAutomodEnum, CreateChannelTypeResponseBlocklistBehaviorEnum, CreateDeviceRequestPushProviderEnum, CreateImportRequestModeEnum, DeleteUsersRequestConversationsEnum, DeleteUsersRequestMessagesEnum, DeleteUsersRequestUserEnum, DeviceFieldsPushProviderEnum, DevicePushProviderEnum, DeviceRequestPushProviderEnum, ImageSizeCropEnum, ImageSizeResizeEnum, LayoutSettingsNameEnum, MessageRequest1TypeEnum, MessageRequestTypeEnum, MessageTypeEnum, PermissionLevelEnum, PolicyRequest1ActionEnum, PolicyRequestActionEnum, PushConfigRequestVersionEnum, StreamCall, StreamChannel, StreamChatClient, StreamClient, StreamVideoClient, TranscriptionSettingsModeEnum, TranslateMessageRequestLanguageEnum, UpdateAppRequestEnforceUniqueUsernamesEnum, UpdateAppRequestPermissionVersionEnum, UpdateAppRequestVideoProviderEnum, UpdateChannelTypeRequestAutomodBehaviorEnum, UpdateChannelTypeRequestAutomodEnum, UpdateChannelTypeRequestBlocklistBehaviorEnum, UpdateChannelTypeResponseAutomodBehaviorEnum, UpdateChannelTypeResponseAutomodEnum, UpdateChannelTypeResponseBlocklistBehaviorEnum, VideoAudioSettingsDefaultDeviceEnum, VideoAudioSettingsRequestDefaultDeviceEnum, VideoCreateDeviceRequestPushProviderEnum, VideoLayoutSettingsNameEnum, VideoLayoutSettingsRequestNameEnum, VideoOwnCapability, VideoRecordSettingsRequestModeEnum, VideoRecordSettingsRequestQualityEnum, VideoSettingsCameraFacingEnum, VideoTranscriptionSettingsModeEnum, VideoTranscriptionSettingsRequestModeEnum, VideoVideoSettingsCameraFacingEnum, VideoVideoSettingsRequestCameraFacingEnum };
8754
8792
  //# sourceMappingURL=index.es.js.map