@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 +25 -25
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +25 -25
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamClient.d.ts +4 -1
- package/dist/src/types.d.ts +12 -0
- package/dist/src/utils/create-token.d.ts +6 -1
- package/package.json +1 -1
- package/src/StreamClient.ts +22 -23
- package/src/types.ts +14 -0
- package/src/utils/create-token.ts +5 -16
package/dist/index.cjs.js
CHANGED
|
@@ -8490,16 +8490,15 @@ class StreamVideoClient {
|
|
|
8490
8490
|
}
|
|
8491
8491
|
}
|
|
8492
8492
|
|
|
8493
|
-
function JWTUserToken(apiSecret,
|
|
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({
|
|
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.
|
|
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
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
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
|
-
|
|
8875
|
+
payload.call_cids = call_cids;
|
|
8879
8876
|
}
|
|
8880
|
-
return JWTUserToken(this.secret,
|
|
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(
|
|
8891
|
-
const
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
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
|
-
|
|
8899
|
-
return JWTUserToken(this.secret, userID, extra);
|
|
8899
|
+
return JWTUserToken(this.secret, payload);
|
|
8900
8900
|
}
|
|
8901
8901
|
mapCustomDataAfterReceive(user) {
|
|
8902
8902
|
if (!user) {
|