@stream-io/node-sdk 0.1.3 → 0.1.5
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/__tests__/block-lists.test.d.ts +1 -1
- package/dist/__tests__/call-members.test.d.ts +1 -1
- package/dist/__tests__/call-types.test.d.ts +1 -1
- package/dist/__tests__/call.test.d.ts +1 -1
- package/dist/__tests__/channel-types.test.d.ts +1 -1
- package/dist/__tests__/channel.test.d.ts +1 -1
- package/dist/__tests__/command.test.d.ts +1 -1
- package/dist/__tests__/create-test-client.d.ts +3 -0
- package/dist/__tests__/devices-push.test.d.ts +1 -1
- package/dist/__tests__/permissions-app-settings.test.d.ts +1 -1
- package/dist/__tests__/user-compat.test.d.ts +1 -1
- package/dist/__tests__/users.test.d.ts +1 -1
- package/dist/index.cjs.js +53 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +53 -10
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamClient.d.ts +28 -3
- package/package.json +1 -1
- package/src/StreamCall.ts +14 -5
- package/src/StreamClient.ts +47 -8
- package/src/StreamVideoClient.ts +2 -1
|
@@ -2,12 +2,17 @@ import { StreamChatClient } from "./StreamChatClient";
|
|
|
2
2
|
import { StreamVideoClient } from "./StreamVideoClient";
|
|
3
3
|
import { BanRequest, CheckPushRequest, CreateDeviceRequest, CreateRoleRequest, DeactivateUserRequest, DeactivateUsersRequest, DeleteDeviceRequest, DeletePushProviderRequest, DeleteRoleRequest, DeleteUserRequest, DeleteUsersRequest, ExportUserRequest, ExportUsersRequest, FlagRequest, GetPermissionRequest, GetTaskRequest, GuestRequest, ListDevicesRequest, MuteUserRequest, PushProviderRequest, QueryBannedUsersRequest, QueryUsersRequest, ReactivateUserRequest, ReactivateUsersRequest, RestoreUsersRequest, UnbanRequest, UnmuteUserRequest, UpdateAppRequest, UpdateUserPartialRequest, UpdateUsersRequest, UserCustomEventRequest } from "./gen/chat";
|
|
4
4
|
import { Configuration } from "./gen/video";
|
|
5
|
+
export type StreamClientOptions = {
|
|
6
|
+
timeout?: number;
|
|
7
|
+
basePath?: string;
|
|
8
|
+
};
|
|
5
9
|
export declare class StreamClient {
|
|
6
10
|
private apiKey;
|
|
7
11
|
private secret;
|
|
8
|
-
readonly
|
|
12
|
+
readonly config?: string | StreamClientOptions | undefined;
|
|
9
13
|
readonly video: StreamVideoClient;
|
|
10
14
|
readonly chat: StreamChatClient;
|
|
15
|
+
readonly options: StreamClientOptions;
|
|
11
16
|
private readonly usersApi;
|
|
12
17
|
private readonly devicesApi;
|
|
13
18
|
private readonly pushApi;
|
|
@@ -18,16 +23,31 @@ export declare class StreamClient {
|
|
|
18
23
|
private readonly eventsApi;
|
|
19
24
|
private readonly tasksApi;
|
|
20
25
|
private token;
|
|
21
|
-
|
|
26
|
+
private static readonly DEFAULT_TIMEOUT;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param apiKey
|
|
30
|
+
* @param secret
|
|
31
|
+
* @param config can be a string, which will be interpreted as base path (deprecated), or a config object
|
|
32
|
+
*/
|
|
33
|
+
constructor(apiKey: string, secret: string, config?: string | StreamClientOptions | undefined);
|
|
22
34
|
/**
|
|
23
35
|
*
|
|
24
36
|
* @param userID
|
|
25
37
|
* @param exp
|
|
26
|
-
* @param iat
|
|
38
|
+
* @param iat deprecated, the default date will be set internally
|
|
27
39
|
* @param call_cids this parameter is deprecated use `createCallToken` for call tokens
|
|
28
40
|
* @returns
|
|
29
41
|
*/
|
|
30
42
|
createToken(userID: string, exp?: number, iat?: number, call_cids?: string[]): string;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param userID
|
|
46
|
+
* @param call_cids
|
|
47
|
+
* @param exp
|
|
48
|
+
* @param iat this is deprecated, the current date will be set internally
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
31
51
|
createCallToken(userID: string, call_cids: string[], exp?: number, iat?: number): string;
|
|
32
52
|
createDevice: (createDeviceRequest: CreateDeviceRequest) => Promise<void>;
|
|
33
53
|
deleteDevice: (requestParameters: DeleteDeviceRequest) => Promise<import("./gen/chat").Response>;
|
|
@@ -40,6 +60,11 @@ export declare class StreamClient {
|
|
|
40
60
|
banUser: (banRequest: BanRequest) => Promise<import("./gen/chat").Response>;
|
|
41
61
|
deactivateUser: (deactivateUserRequest: DeactivateUserRequest) => Promise<import("./gen/chat").DeactivateUserResponse>;
|
|
42
62
|
deactivateUsers: (deactivateUsersRequest: DeactivateUsersRequest) => Promise<import("./gen/chat").DeactivateUsersResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated use `deleteUsers` instead
|
|
65
|
+
* @param deleteUsersRequest
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
43
68
|
deleteUser: (request: DeleteUserRequest) => Promise<import("./gen/chat").DeleteUserResponse>;
|
|
44
69
|
deleteUsers: (deleteUsersRequest: DeleteUsersRequest) => Promise<import("./gen/chat").DeleteUsersResponse>;
|
|
45
70
|
exportUser: (request: ExportUserRequest) => Promise<import("./gen/chat").ExportUserResponse>;
|
package/package.json
CHANGED
package/src/StreamCall.ts
CHANGED
|
@@ -28,7 +28,8 @@ export class StreamCall {
|
|
|
28
28
|
this.baseRequest = { id: this.id, type: this.type };
|
|
29
29
|
const configuration = this.streamClient.getConfiguration({
|
|
30
30
|
basePath:
|
|
31
|
-
this.streamClient.basePath ||
|
|
31
|
+
this.streamClient.options.basePath ||
|
|
32
|
+
"https://video.stream-io-api.com/video",
|
|
32
33
|
});
|
|
33
34
|
this.apiClient = new DefaultApi(configuration);
|
|
34
35
|
}
|
|
@@ -66,7 +67,7 @@ export class StreamCall {
|
|
|
66
67
|
goLive = (videoGoLiveRequest?: VideoGoLiveRequest) => {
|
|
67
68
|
return this.apiClient.goLive({
|
|
68
69
|
...this.baseRequest,
|
|
69
|
-
videoGoLiveRequest: videoGoLiveRequest ||
|
|
70
|
+
videoGoLiveRequest: videoGoLiveRequest || {},
|
|
70
71
|
});
|
|
71
72
|
};
|
|
72
73
|
|
|
@@ -77,7 +78,10 @@ export class StreamCall {
|
|
|
77
78
|
};
|
|
78
79
|
|
|
79
80
|
muteUsers = (videoMuteUsersRequest: VideoMuteUsersRequest) => {
|
|
80
|
-
return this.apiClient.muteUsers({
|
|
81
|
+
return this.apiClient.muteUsers({
|
|
82
|
+
...this.baseRequest,
|
|
83
|
+
videoMuteUsersRequest,
|
|
84
|
+
});
|
|
81
85
|
};
|
|
82
86
|
|
|
83
87
|
queryMembers = (request?: OmitTypeId<VideoQueryMembersRequest>) => {
|
|
@@ -135,7 +139,9 @@ export class StreamCall {
|
|
|
135
139
|
});
|
|
136
140
|
};
|
|
137
141
|
|
|
138
|
-
updateCallMembers = (
|
|
142
|
+
updateCallMembers = (
|
|
143
|
+
videoUpdateCallMembersRequest: VideoUpdateCallMembersRequest
|
|
144
|
+
) => {
|
|
139
145
|
return this.apiClient.updateCallMembers({
|
|
140
146
|
videoUpdateCallMembersRequest,
|
|
141
147
|
...this.baseRequest,
|
|
@@ -156,6 +162,9 @@ export class StreamCall {
|
|
|
156
162
|
};
|
|
157
163
|
|
|
158
164
|
unpinVideo = (videoUnpinRequest: VideoUnpinRequest) => {
|
|
159
|
-
return this.apiClient.videoUnpin({
|
|
165
|
+
return this.apiClient.videoUnpin({
|
|
166
|
+
videoUnpinRequest,
|
|
167
|
+
...this.baseRequest,
|
|
168
|
+
});
|
|
160
169
|
};
|
|
161
170
|
}
|
package/src/StreamClient.ts
CHANGED
|
@@ -48,6 +48,8 @@ import {
|
|
|
48
48
|
} from "./gen/chat";
|
|
49
49
|
import {
|
|
50
50
|
Configuration,
|
|
51
|
+
ErrorContext,
|
|
52
|
+
FetchError,
|
|
51
53
|
HTTPQuery,
|
|
52
54
|
JSONApiResponse,
|
|
53
55
|
RequestContext,
|
|
@@ -56,9 +58,15 @@ import {
|
|
|
56
58
|
import { v4 as uuidv4 } from "uuid";
|
|
57
59
|
import { JWTServerToken, JWTUserToken } from "./utils/create-token";
|
|
58
60
|
|
|
61
|
+
export type StreamClientOptions = {
|
|
62
|
+
timeout?: number;
|
|
63
|
+
basePath?: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
59
66
|
export class StreamClient {
|
|
60
67
|
public readonly video: StreamVideoClient;
|
|
61
68
|
public readonly chat: StreamChatClient;
|
|
69
|
+
public readonly options: StreamClientOptions = {};
|
|
62
70
|
private readonly usersApi: UsersApi;
|
|
63
71
|
private readonly devicesApi: DevicesApi;
|
|
64
72
|
private readonly pushApi: PushApi;
|
|
@@ -69,16 +77,30 @@ export class StreamClient {
|
|
|
69
77
|
private readonly eventsApi: EventsApi;
|
|
70
78
|
private readonly tasksApi: TasksApi;
|
|
71
79
|
private token: string;
|
|
80
|
+
private static readonly DEFAULT_TIMEOUT = 3000;
|
|
72
81
|
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param apiKey
|
|
85
|
+
* @param secret
|
|
86
|
+
* @param config can be a string, which will be interpreted as base path (deprecated), or a config object
|
|
87
|
+
*/
|
|
73
88
|
constructor(
|
|
74
89
|
private apiKey: string,
|
|
75
90
|
private secret: string,
|
|
76
|
-
|
|
91
|
+
readonly config?: string | StreamClientOptions
|
|
77
92
|
) {
|
|
78
93
|
this.token = JWTServerToken(this.secret);
|
|
79
94
|
this.video = new StreamVideoClient(this);
|
|
80
95
|
this.chat = new StreamChatClient(this);
|
|
81
96
|
|
|
97
|
+
if (typeof config === "string") {
|
|
98
|
+
this.options.basePath = config;
|
|
99
|
+
this.options.timeout = StreamClient.DEFAULT_TIMEOUT;
|
|
100
|
+
} else {
|
|
101
|
+
this.options.timeout = config?.timeout || StreamClient.DEFAULT_TIMEOUT;
|
|
102
|
+
}
|
|
103
|
+
|
|
82
104
|
const chatConfiguration = this.getConfiguration();
|
|
83
105
|
//@ts-expect-error typing problem
|
|
84
106
|
this.usersApi = new UsersApi(chatConfiguration);
|
|
@@ -121,9 +143,6 @@ export class StreamClient {
|
|
|
121
143
|
}
|
|
122
144
|
|
|
123
145
|
if (iat) {
|
|
124
|
-
console.warn(
|
|
125
|
-
`This parameter is deprecated, and will be removed method with version 0.2.0, the client will set this to the current date by deault`
|
|
126
|
-
);
|
|
127
146
|
extra.iat = iat;
|
|
128
147
|
}
|
|
129
148
|
|
|
@@ -158,9 +177,6 @@ export class StreamClient {
|
|
|
158
177
|
}
|
|
159
178
|
|
|
160
179
|
if (iat) {
|
|
161
|
-
console.warn(
|
|
162
|
-
`This parameter is deprecated, and will be removed method with version 0.2.0, the client will set this to the current date by deault`
|
|
163
|
-
);
|
|
164
180
|
extra.iat = iat;
|
|
165
181
|
}
|
|
166
182
|
|
|
@@ -225,6 +241,11 @@ export class StreamClient {
|
|
|
225
241
|
return this.usersApi.deactivateUsers({ deactivateUsersRequest });
|
|
226
242
|
};
|
|
227
243
|
|
|
244
|
+
/**
|
|
245
|
+
* @deprecated use `deleteUsers` instead
|
|
246
|
+
* @param deleteUsersRequest
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
228
249
|
deleteUser = async (request: DeleteUserRequest) => {
|
|
229
250
|
const response = await this.usersApi.deleteUser(request);
|
|
230
251
|
response.user = this.mapCustomDataAfterReceive(response.user);
|
|
@@ -416,7 +437,7 @@ export class StreamClient {
|
|
|
416
437
|
|
|
417
438
|
return mapping[name];
|
|
418
439
|
},
|
|
419
|
-
basePath: options?.basePath || this.basePath,
|
|
440
|
+
basePath: options?.basePath || this.options.basePath,
|
|
420
441
|
headers: {
|
|
421
442
|
"X-Stream-Client": "stream-node-" + process.env.PKG_VERSION,
|
|
422
443
|
},
|
|
@@ -447,6 +468,24 @@ export class StreamClient {
|
|
|
447
468
|
}
|
|
448
469
|
},
|
|
449
470
|
},
|
|
471
|
+
{
|
|
472
|
+
pre: (context: RequestContext) => {
|
|
473
|
+
context.init.signal = AbortSignal.timeout(this.options.timeout!);
|
|
474
|
+
|
|
475
|
+
return Promise.resolve(context);
|
|
476
|
+
},
|
|
477
|
+
onError: (context: ErrorContext) => {
|
|
478
|
+
const error = context.error as DOMException;
|
|
479
|
+
if (error.name === "AbortError" || error.name === "TimeoutError") {
|
|
480
|
+
throw new FetchError(
|
|
481
|
+
error,
|
|
482
|
+
`The request was aborted due to to the ${this.options.timeout}ms timeout, you can set the timeout in the StreamClient constructor`
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return Promise.resolve(context.response);
|
|
487
|
+
},
|
|
488
|
+
},
|
|
450
489
|
],
|
|
451
490
|
// https://github.com/OpenAPITools/openapi-generator/issues/13222
|
|
452
491
|
queryParamsStringify: (params: HTTPQuery) => {
|
package/src/StreamVideoClient.ts
CHANGED
|
@@ -17,7 +17,8 @@ export class StreamVideoClient {
|
|
|
17
17
|
constructor(private streamClient: StreamClient) {
|
|
18
18
|
const configuration = this.streamClient.getConfiguration({
|
|
19
19
|
basePath:
|
|
20
|
-
this.streamClient.basePath ||
|
|
20
|
+
this.streamClient.options.basePath ||
|
|
21
|
+
"https://video.stream-io-api.com/video",
|
|
21
22
|
});
|
|
22
23
|
this.apiClient = new DefaultApi(configuration);
|
|
23
24
|
this.videoServerSideApiClient = new ServerSideApi(configuration);
|