@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.es.js CHANGED
@@ -8488,16 +8488,15 @@ class StreamVideoClient {
8488
8488
  }
8489
8489
  }
8490
8490
 
8491
- function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
8492
- if (typeof userId !== 'string') {
8493
- throw new TypeError('userId should be a string');
8494
- }
8495
- const payload = Object.assign({ user_id: userId }, extraData);
8491
+ function JWTUserToken(apiSecret, payload) {
8496
8492
  // make sure we return a clear error when jwt is shimmed (ie. browser build)
8497
8493
  if (jwt == null || jwt.sign == null) {
8498
8494
  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.`);
8499
8495
  }
8500
- const opts = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
8496
+ const opts = Object.assign({
8497
+ algorithm: 'HS256',
8498
+ noTimestamp: true,
8499
+ });
8501
8500
  if (payload.iat) {
8502
8501
  opts.noTimestamp = false;
8503
8502
  }
@@ -8736,7 +8735,7 @@ class StreamClient {
8736
8735
  ? 'https://chat.stream-io-api.com'
8737
8736
  : 'https://video.stream-io-api.com'),
8738
8737
  headers: {
8739
- 'X-Stream-Client': 'stream-node-' + "0.2.1",
8738
+ 'X-Stream-Client': 'stream-node-' + "0.2.2",
8740
8739
  },
8741
8740
  middleware: [
8742
8741
  {
@@ -8864,18 +8863,16 @@ class StreamClient {
8864
8863
  * @returns
8865
8864
  */
8866
8865
  createToken(userID, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000), call_cids) {
8867
- const extra = {};
8868
- if (exp) {
8869
- extra.exp = exp;
8870
- }
8871
- if (iat) {
8872
- extra.iat = iat;
8873
- }
8866
+ const payload = {
8867
+ user_id: userID,
8868
+ exp,
8869
+ iat,
8870
+ };
8874
8871
  if (call_cids) {
8875
8872
  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`);
8876
- extra.call_cids = call_cids;
8873
+ payload.call_cids = call_cids;
8877
8874
  }
8878
- return JWTUserToken(this.secret, userID, extra);
8875
+ return JWTUserToken(this.secret, payload);
8879
8876
  }
8880
8877
  /**
8881
8878
  *
@@ -8885,16 +8882,19 @@ class StreamClient {
8885
8882
  * @param iat this is deprecated, the current date will be set internally
8886
8883
  * @returns
8887
8884
  */
8888
- createCallToken(userID, call_cids, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000)) {
8889
- const extra = {};
8890
- if (exp) {
8891
- extra.exp = exp;
8892
- }
8893
- if (iat) {
8894
- extra.iat = iat;
8885
+ createCallToken(userIdOrObject, call_cids, exp = Math.round(new Date().getTime() / 1000) + 60 * 60, iat = Math.round(Date.now() / 1000)) {
8886
+ const payload = {
8887
+ exp,
8888
+ iat,
8889
+ call_cids,
8890
+ user_id: typeof userIdOrObject === 'string'
8891
+ ? userIdOrObject
8892
+ : userIdOrObject.user_id,
8893
+ };
8894
+ if (typeof userIdOrObject === 'object' && userIdOrObject.role) {
8895
+ payload.role = userIdOrObject.role;
8895
8896
  }
8896
- extra.call_cids = call_cids;
8897
- return JWTUserToken(this.secret, userID, extra);
8897
+ return JWTUserToken(this.secret, payload);
8898
8898
  }
8899
8899
  mapCustomDataAfterReceive(user) {
8900
8900
  if (!user) {