@stream-io/node-sdk 0.2.1 → 0.2.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.
package/dist/index.cjs.js CHANGED
@@ -8490,16 +8490,15 @@ class StreamVideoClient {
8490
8490
  }
8491
8491
  }
8492
8492
 
8493
- function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
8494
- if (typeof userId !== 'string') {
8495
- throw new TypeError('userId should be a string');
8496
- }
8497
- const payload = Object.assign({ user_id: userId }, extraData);
8493
+ function JWTUserToken(apiSecret, payload) {
8498
8494
  // make sure we return a clear error when jwt is shimmed (ie. browser build)
8499
8495
  if (jwt == null || jwt.sign == null) {
8500
8496
  throw Error(`Unable to find jwt crypto, if you are getting this error is probably because you are trying to generate tokens on browser or React Native (or other environment where crypto functions are not available). Please Note: token should only be generated server-side.`);
8501
8497
  }
8502
- const opts = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
8498
+ const opts = Object.assign({
8499
+ algorithm: 'HS256',
8500
+ noTimestamp: true,
8501
+ });
8503
8502
  if (payload.iat) {
8504
8503
  opts.noTimestamp = false;
8505
8504
  }
@@ -8738,7 +8737,7 @@ class StreamClient {
8738
8737
  ? 'https://chat.stream-io-api.com'
8739
8738
  : 'https://video.stream-io-api.com'),
8740
8739
  headers: {
8741
- 'X-Stream-Client': 'stream-node-' + "0.2.1",
8740
+ 'X-Stream-Client': 'stream-node-' + "0.2.2",
8742
8741
  },
8743
8742
  middleware: [
8744
8743
  {
@@ -8866,18 +8865,16 @@ class StreamClient {
8866
8865
  * @returns
8867
8866
  */
8868
8867
  createToken(userID, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000), call_cids) {
8869
- const extra = {};
8870
- if (exp) {
8871
- extra.exp = exp;
8872
- }
8873
- if (iat) {
8874
- extra.iat = iat;
8875
- }
8868
+ const payload = {
8869
+ user_id: userID,
8870
+ exp,
8871
+ iat,
8872
+ };
8876
8873
  if (call_cids) {
8877
8874
  console.warn(`Use createCallToken method for creating call tokens, the "call_cids" param will be removed from the createToken method with version 0.2.0`);
8878
- extra.call_cids = call_cids;
8875
+ payload.call_cids = call_cids;
8879
8876
  }
8880
- return JWTUserToken(this.secret, userID, extra);
8877
+ return JWTUserToken(this.secret, payload);
8881
8878
  }
8882
8879
  /**
8883
8880
  *
@@ -8887,16 +8884,19 @@ class StreamClient {
8887
8884
  * @param iat this is deprecated, the current date will be set internally
8888
8885
  * @returns
8889
8886
  */
8890
- createCallToken(userID, call_cids, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000)) {
8891
- const extra = {};
8892
- if (exp) {
8893
- extra.exp = exp;
8894
- }
8895
- if (iat) {
8896
- extra.iat = iat;
8887
+ createCallToken(userIdOrObject, call_cids, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000)) {
8888
+ const payload = {
8889
+ exp,
8890
+ iat,
8891
+ call_cids,
8892
+ user_id: typeof userIdOrObject === 'string'
8893
+ ? userIdOrObject
8894
+ : userIdOrObject.user_id,
8895
+ };
8896
+ if (typeof userIdOrObject === 'object' && userIdOrObject.role) {
8897
+ payload.role = userIdOrObject.role;
8897
8898
  }
8898
- extra.call_cids = call_cids;
8899
- return JWTUserToken(this.secret, userID, extra);
8899
+ return JWTUserToken(this.secret, payload);
8900
8900
  }
8901
8901
  mapCustomDataAfterReceive(user) {
8902
8902
  if (!user) {