@stream-io/node-sdk 0.1.2 → 0.1.4
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 +47 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +47 -9
- package/dist/index.es.js.map +1 -1
- package/dist/src/StreamClient.d.ts +23 -3
- package/package.json +1 -1
- package/src/StreamCall.ts +13 -4
- package/src/StreamClient.ts +53 -5
- 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>;
|
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
|
}
|
|
@@ -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);
|
|
@@ -104,13 +126,13 @@ export class StreamClient {
|
|
|
104
126
|
*
|
|
105
127
|
* @param userID
|
|
106
128
|
* @param exp
|
|
107
|
-
* @param iat
|
|
129
|
+
* @param iat deprecated, the default date will be set internally
|
|
108
130
|
* @param call_cids this parameter is deprecated use `createCallToken` for call tokens
|
|
109
131
|
* @returns
|
|
110
132
|
*/
|
|
111
133
|
createToken(
|
|
112
134
|
userID: string,
|
|
113
|
-
exp
|
|
135
|
+
exp = Math.round(new Date().getTime() / 1000) + 60 * 60,
|
|
114
136
|
iat = Math.round(Date.now() / 1000),
|
|
115
137
|
call_cids?: string[]
|
|
116
138
|
) {
|
|
@@ -134,10 +156,18 @@ export class StreamClient {
|
|
|
134
156
|
return JWTUserToken(this.secret, userID, extra);
|
|
135
157
|
}
|
|
136
158
|
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* @param userID
|
|
162
|
+
* @param call_cids
|
|
163
|
+
* @param exp
|
|
164
|
+
* @param iat this is deprecated, the current date will be set internally
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
137
167
|
createCallToken(
|
|
138
168
|
userID: string,
|
|
139
169
|
call_cids: string[],
|
|
140
|
-
exp
|
|
170
|
+
exp = Math.round(new Date().getTime() / 1000) + 60 * 60,
|
|
141
171
|
iat = Math.round(Date.now() / 1000)
|
|
142
172
|
) {
|
|
143
173
|
const extra: { exp?: number; iat?: number; call_cids?: string[] } = {};
|
|
@@ -402,7 +432,7 @@ export class StreamClient {
|
|
|
402
432
|
|
|
403
433
|
return mapping[name];
|
|
404
434
|
},
|
|
405
|
-
basePath: options?.basePath || this.basePath,
|
|
435
|
+
basePath: options?.basePath || this.options.basePath,
|
|
406
436
|
headers: {
|
|
407
437
|
"X-Stream-Client": "stream-node-" + process.env.PKG_VERSION,
|
|
408
438
|
},
|
|
@@ -433,6 +463,24 @@ export class StreamClient {
|
|
|
433
463
|
}
|
|
434
464
|
},
|
|
435
465
|
},
|
|
466
|
+
{
|
|
467
|
+
pre: (context: RequestContext) => {
|
|
468
|
+
context.init.signal = AbortSignal.timeout(this.options.timeout!);
|
|
469
|
+
|
|
470
|
+
return Promise.resolve(context);
|
|
471
|
+
},
|
|
472
|
+
onError: (context: ErrorContext) => {
|
|
473
|
+
const error = context.error as DOMException;
|
|
474
|
+
if (error.name === "AbortError" || error.name === "TimeoutError") {
|
|
475
|
+
throw new FetchError(
|
|
476
|
+
error,
|
|
477
|
+
`The request was aborted due to to the ${this.options.timeout}ms timeout, you can set the timeout in the StreamClient constructor`
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return Promise.resolve(context.response);
|
|
482
|
+
},
|
|
483
|
+
},
|
|
436
484
|
],
|
|
437
485
|
// https://github.com/OpenAPITools/openapi-generator/issues/13222
|
|
438
486
|
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);
|