@stream-io/node-sdk 0.1.2 → 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.
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import "dotenv/config";
2
+ import { StreamClient } from "../src/StreamClient";
3
+ export declare const createTestClient: () => StreamClient;
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
package/dist/index.cjs.js CHANGED
@@ -8341,7 +8341,8 @@ class StreamCall {
8341
8341
  };
8342
8342
  this.baseRequest = { id: this.id, type: this.type };
8343
8343
  const configuration = this.streamClient.getConfiguration({
8344
- basePath: this.streamClient.basePath || "https://video.stream-io-api.com/video",
8344
+ basePath: this.streamClient.options.basePath ||
8345
+ "https://video.stream-io-api.com/video",
8345
8346
  });
8346
8347
  this.apiClient = new DefaultApi(configuration);
8347
8348
  }
@@ -8379,7 +8380,8 @@ class StreamVideoClient {
8379
8380
  });
8380
8381
  };
8381
8382
  const configuration = this.streamClient.getConfiguration({
8382
- basePath: this.streamClient.basePath || "https://video.stream-io-api.com/video",
8383
+ basePath: this.streamClient.options.basePath ||
8384
+ "https://video.stream-io-api.com/video",
8383
8385
  });
8384
8386
  this.apiClient = new DefaultApi(configuration);
8385
8387
  this.videoServerSideApiClient = new ServerSideApi(configuration);
@@ -8410,10 +8412,17 @@ function JWTServerToken(apiSecret, jwtOptions = {}) {
8410
8412
  }
8411
8413
 
8412
8414
  class StreamClient {
8413
- constructor(apiKey, secret, basePath) {
8415
+ /**
8416
+ *
8417
+ * @param apiKey
8418
+ * @param secret
8419
+ * @param config can be a string, which will be interpreted as base path (deprecated), or a config object
8420
+ */
8421
+ constructor(apiKey, secret, config) {
8414
8422
  this.apiKey = apiKey;
8415
8423
  this.secret = secret;
8416
- this.basePath = basePath;
8424
+ this.config = config;
8425
+ this.options = {};
8417
8426
  this.createDevice = (createDeviceRequest) => {
8418
8427
  return this.devicesApi.createDevice({ createDeviceRequest });
8419
8428
  };
@@ -8603,9 +8612,9 @@ class StreamClient {
8603
8612
  };
8604
8613
  return mapping[name];
8605
8614
  },
8606
- basePath: (options === null || options === void 0 ? void 0 : options.basePath) || this.basePath,
8615
+ basePath: (options === null || options === void 0 ? void 0 : options.basePath) || this.options.basePath,
8607
8616
  headers: {
8608
- "X-Stream-Client": "stream-node-" + "0.1.2",
8617
+ "X-Stream-Client": "stream-node-" + "0.1.3",
8609
8618
  },
8610
8619
  middleware: [
8611
8620
  {
@@ -8626,6 +8635,19 @@ class StreamClient {
8626
8635
  }
8627
8636
  }),
8628
8637
  },
8638
+ {
8639
+ pre: (context) => {
8640
+ context.init.signal = AbortSignal.timeout(this.options.timeout);
8641
+ return Promise.resolve(context);
8642
+ },
8643
+ onError: (context) => {
8644
+ const error = context.error;
8645
+ if (error.name === "AbortError" || error.name === "TimeoutError") {
8646
+ 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`);
8647
+ }
8648
+ return Promise.resolve(context.response);
8649
+ },
8650
+ },
8629
8651
  ],
8630
8652
  // https://github.com/OpenAPITools/openapi-generator/issues/13222
8631
8653
  queryParamsStringify: (params) => {
@@ -8697,6 +8719,13 @@ class StreamClient {
8697
8719
  this.token = JWTServerToken(this.secret);
8698
8720
  this.video = new StreamVideoClient(this);
8699
8721
  this.chat = new StreamChatClient(this);
8722
+ if (typeof config === "string") {
8723
+ this.options.basePath = config;
8724
+ this.options.timeout = StreamClient.DEFAULT_TIMEOUT;
8725
+ }
8726
+ else {
8727
+ this.options.timeout = (config === null || config === void 0 ? void 0 : config.timeout) || StreamClient.DEFAULT_TIMEOUT;
8728
+ }
8700
8729
  const chatConfiguration = this.getConfiguration();
8701
8730
  //@ts-expect-error typing problem
8702
8731
  this.usersApi = new UsersApi(chatConfiguration);
@@ -8721,11 +8750,11 @@ class StreamClient {
8721
8750
  *
8722
8751
  * @param userID
8723
8752
  * @param exp
8724
- * @param iat
8753
+ * @param iat deprecated, the default date will be set internally
8725
8754
  * @param call_cids this parameter is deprecated use `createCallToken` for call tokens
8726
8755
  * @returns
8727
8756
  */
8728
- createToken(userID, exp, iat = Math.round(Date.now() / 1000), call_cids) {
8757
+ createToken(userID, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000), call_cids) {
8729
8758
  const extra = {};
8730
8759
  if (exp) {
8731
8760
  extra.exp = exp;
@@ -8739,7 +8768,15 @@ class StreamClient {
8739
8768
  }
8740
8769
  return JWTUserToken(this.secret, userID, extra);
8741
8770
  }
8742
- createCallToken(userID, call_cids, exp, iat = Math.round(Date.now() / 1000)) {
8771
+ /**
8772
+ *
8773
+ * @param userID
8774
+ * @param call_cids
8775
+ * @param exp
8776
+ * @param iat this is deprecated, the current date will be set internally
8777
+ * @returns
8778
+ */
8779
+ createCallToken(userID, call_cids, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000)) {
8743
8780
  const extra = {};
8744
8781
  if (exp) {
8745
8782
  extra.exp = exp;
@@ -8751,6 +8788,7 @@ class StreamClient {
8751
8788
  return JWTUserToken(this.secret, userID, extra);
8752
8789
  }
8753
8790
  }
8791
+ StreamClient.DEFAULT_TIMEOUT = 3000;
8754
8792
 
8755
8793
  exports.APNConfigRequestAuthTypeEnum = APNConfigRequestAuthTypeEnum;
8756
8794
  exports.AppSearchBackendEnum = AppSearchBackendEnum;