@stream-io/node-sdk 0.1.0 → 0.1.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/README.md +3 -1
- package/dist/__tests__/create-token.test.d.ts +1 -1
- package/dist/index.cjs.js +60 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +60 -14
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamClient.d.ts +9 -0
- package/package.json +4 -3
- package/src/StreamClient.ts +121 -47
package/README.md
CHANGED
|
@@ -21,9 +21,11 @@ Stream is free for most side and hobby projects. To qualify, your project/compan
|
|
|
21
21
|
|
|
22
22
|
This repo contains the Node server-side SDK developed by the team and Stream community. For a feature overview please visit our [roadmap](https://github.com/GetStream/protocol/discussions/177).
|
|
23
23
|
|
|
24
|
+
Minimum supported Node version: v18.
|
|
25
|
+
|
|
24
26
|
## Contributing
|
|
25
27
|
|
|
26
28
|
- How can I submit a sample app?
|
|
27
29
|
- Apps submissions are always welcomed! 🥳 Open a pr with a proper description and we'll review it as soon as possible
|
|
28
30
|
- Spot a bug 🕷 ?
|
|
29
|
-
- We welcome code changes that improve the apps or fix a problem. Please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github.
|
|
31
|
+
- We welcome code changes that improve the apps or fix a problem. Please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "dotenv/config";
|
package/dist/index.cjs.js
CHANGED
|
@@ -8430,7 +8430,9 @@ class StreamClient {
|
|
|
8430
8430
|
return this.pushApi.deletePushProvider(request);
|
|
8431
8431
|
};
|
|
8432
8432
|
this.upsertPushProvider = (request) => {
|
|
8433
|
-
return this.serversideApi.upsertPushProvider({
|
|
8433
|
+
return this.serversideApi.upsertPushProvider({
|
|
8434
|
+
upsertPushProviderRequest: { push_provider: request },
|
|
8435
|
+
});
|
|
8434
8436
|
};
|
|
8435
8437
|
this.checkPush = (checkPushRequest) => {
|
|
8436
8438
|
return this.testingApi.checkPush({ checkPushRequest });
|
|
@@ -8483,7 +8485,7 @@ class StreamClient {
|
|
|
8483
8485
|
this.queryBannedUsers = (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
8484
8486
|
payload.user = this.mapCustomDataBeforeSend(payload.user);
|
|
8485
8487
|
const response = yield this.usersApi.queryBannedUsers({ payload });
|
|
8486
|
-
response.bans.forEach(b => {
|
|
8488
|
+
response.bans.forEach((b) => {
|
|
8487
8489
|
b.banned_by = this.mapCustomDataAfterReceive(b.banned_by);
|
|
8488
8490
|
b.user = this.mapCustomDataAfterReceive(b.user);
|
|
8489
8491
|
});
|
|
@@ -8493,7 +8495,7 @@ class StreamClient {
|
|
|
8493
8495
|
payload.user = this.mapCustomDataBeforeSend(payload.user);
|
|
8494
8496
|
const response = yield this.usersApi.queryUsers({ payload });
|
|
8495
8497
|
// @ts-expect-error
|
|
8496
|
-
response.users = response.users.map(u => this.mapCustomDataAfterReceive(u));
|
|
8498
|
+
response.users = response.users.map((u) => this.mapCustomDataAfterReceive(u));
|
|
8497
8499
|
return response;
|
|
8498
8500
|
});
|
|
8499
8501
|
this.reactivateUser = (reactivateUserRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -8521,19 +8523,21 @@ class StreamClient {
|
|
|
8521
8523
|
return response;
|
|
8522
8524
|
});
|
|
8523
8525
|
this.upsertUsers = (updateUsersRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
8524
|
-
Object.keys(updateUsersRequest.users).forEach(key => {
|
|
8526
|
+
Object.keys(updateUsersRequest.users).forEach((key) => {
|
|
8525
8527
|
updateUsersRequest.users[key] = this.mapCustomDataBeforeSend(updateUsersRequest.users[key]);
|
|
8526
8528
|
});
|
|
8527
8529
|
const response = yield this.usersApi.updateUsers({ updateUsersRequest });
|
|
8528
|
-
Object.keys(response.users).forEach(key => {
|
|
8530
|
+
Object.keys(response.users).forEach((key) => {
|
|
8529
8531
|
response.users[key] = this.mapCustomDataAfterReceive(response.users[key]);
|
|
8530
8532
|
});
|
|
8531
8533
|
return response;
|
|
8532
8534
|
});
|
|
8533
8535
|
this.updateUsersPartial = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8536
|
+
const response = yield this.usersApi.updateUsersPartial({
|
|
8537
|
+
// @ts-expect-error typing error
|
|
8538
|
+
updateUserPartialRequest: request,
|
|
8539
|
+
});
|
|
8540
|
+
Object.keys(response.users).forEach((key) => {
|
|
8537
8541
|
response.users[key] = this.mapCustomDataAfterReceive(response.users[key]);
|
|
8538
8542
|
});
|
|
8539
8543
|
return response;
|
|
@@ -8546,7 +8550,7 @@ class StreamClient {
|
|
|
8546
8550
|
response.mute.user = this.mapCustomDataAfterReceive((_e = response.mute) === null || _e === void 0 ? void 0 : _e.user);
|
|
8547
8551
|
}
|
|
8548
8552
|
if (response.mutes) {
|
|
8549
|
-
response.mutes = response.mutes.map(m => {
|
|
8553
|
+
response.mutes = response.mutes.map((m) => {
|
|
8550
8554
|
return Object.assign(Object.assign({}, m), { user: this.mapCustomDataAfterReceive(m.user) });
|
|
8551
8555
|
});
|
|
8552
8556
|
}
|
|
@@ -8557,7 +8561,10 @@ class StreamClient {
|
|
|
8557
8561
|
return this.usersApi.unmuteUser({ unmuteUserRequest });
|
|
8558
8562
|
};
|
|
8559
8563
|
this.sendCustomEventToUser = (userId, event) => {
|
|
8560
|
-
return this.eventsApi.sendUserCustomEvent({
|
|
8564
|
+
return this.eventsApi.sendUserCustomEvent({
|
|
8565
|
+
userId,
|
|
8566
|
+
sendUserCustomEventRequest: { event },
|
|
8567
|
+
});
|
|
8561
8568
|
};
|
|
8562
8569
|
this.createRole = (createRoleRequest) => {
|
|
8563
8570
|
return this.permissionsApi.createRole({ createRoleRequest });
|
|
@@ -8598,7 +8605,7 @@ class StreamClient {
|
|
|
8598
8605
|
},
|
|
8599
8606
|
basePath: (options === null || options === void 0 ? void 0 : options.basePath) || this.basePath,
|
|
8600
8607
|
headers: {
|
|
8601
|
-
"X-Stream-Client": "stream-node-" + "0.1.
|
|
8608
|
+
"X-Stream-Client": "stream-node-" + "0.1.2",
|
|
8602
8609
|
},
|
|
8603
8610
|
middleware: [
|
|
8604
8611
|
{
|
|
@@ -8640,7 +8647,26 @@ class StreamClient {
|
|
|
8640
8647
|
},
|
|
8641
8648
|
});
|
|
8642
8649
|
};
|
|
8643
|
-
this.reservedKeywords = [
|
|
8650
|
+
this.reservedKeywords = [
|
|
8651
|
+
"ban_expires",
|
|
8652
|
+
"banned",
|
|
8653
|
+
"id",
|
|
8654
|
+
"invisible",
|
|
8655
|
+
"language",
|
|
8656
|
+
"push_notifications",
|
|
8657
|
+
"revoke_tokens_issued_before",
|
|
8658
|
+
"role",
|
|
8659
|
+
"teams",
|
|
8660
|
+
"created_at",
|
|
8661
|
+
"deactivated_at",
|
|
8662
|
+
"deleted_at",
|
|
8663
|
+
"last_active",
|
|
8664
|
+
"online",
|
|
8665
|
+
"updated_at",
|
|
8666
|
+
"shadow_banned",
|
|
8667
|
+
"name",
|
|
8668
|
+
"image",
|
|
8669
|
+
];
|
|
8644
8670
|
this.mapCustomDataBeforeSend = (user) => {
|
|
8645
8671
|
if (!user) {
|
|
8646
8672
|
return undefined;
|
|
@@ -8655,7 +8681,7 @@ class StreamClient {
|
|
|
8655
8681
|
}
|
|
8656
8682
|
// @ts-expect-error
|
|
8657
8683
|
let result = {};
|
|
8658
|
-
Object.keys(user).forEach(key => {
|
|
8684
|
+
Object.keys(user).forEach((key) => {
|
|
8659
8685
|
if (!this.reservedKeywords.includes(key)) {
|
|
8660
8686
|
if (!result.custom) {
|
|
8661
8687
|
result.custom = {};
|
|
@@ -8691,7 +8717,15 @@ class StreamClient {
|
|
|
8691
8717
|
//@ts-expect-error typing problem
|
|
8692
8718
|
this.tasksApi = new TasksApi(chatConfiguration);
|
|
8693
8719
|
}
|
|
8694
|
-
|
|
8720
|
+
/**
|
|
8721
|
+
*
|
|
8722
|
+
* @param userID
|
|
8723
|
+
* @param exp
|
|
8724
|
+
* @param iat
|
|
8725
|
+
* @param call_cids this parameter is deprecated use `createCallToken` for call tokens
|
|
8726
|
+
* @returns
|
|
8727
|
+
*/
|
|
8728
|
+
createToken(userID, exp, iat = Math.round(Date.now() / 1000), call_cids) {
|
|
8695
8729
|
const extra = {};
|
|
8696
8730
|
if (exp) {
|
|
8697
8731
|
extra.exp = exp;
|
|
@@ -8700,10 +8734,22 @@ class StreamClient {
|
|
|
8700
8734
|
extra.iat = iat;
|
|
8701
8735
|
}
|
|
8702
8736
|
if (call_cids) {
|
|
8737
|
+
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`);
|
|
8703
8738
|
extra.call_cids = call_cids;
|
|
8704
8739
|
}
|
|
8705
8740
|
return JWTUserToken(this.secret, userID, extra);
|
|
8706
8741
|
}
|
|
8742
|
+
createCallToken(userID, call_cids, exp, iat = Math.round(Date.now() / 1000)) {
|
|
8743
|
+
const extra = {};
|
|
8744
|
+
if (exp) {
|
|
8745
|
+
extra.exp = exp;
|
|
8746
|
+
}
|
|
8747
|
+
if (iat) {
|
|
8748
|
+
extra.iat = iat;
|
|
8749
|
+
}
|
|
8750
|
+
extra.call_cids = call_cids;
|
|
8751
|
+
return JWTUserToken(this.secret, userID, extra);
|
|
8752
|
+
}
|
|
8707
8753
|
}
|
|
8708
8754
|
|
|
8709
8755
|
exports.APNConfigRequestAuthTypeEnum = APNConfigRequestAuthTypeEnum;
|