@stream-io/node-sdk 0.7.0 → 0.7.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 +1 -0
- package/dist/index.cjs.js +59 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.mjs +59 -6
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/StreamCall.d.ts +13 -1
- package/dist/src/StreamClient.d.ts +10 -0
- package/dist/src/gen/models/index.d.ts +9 -2
- package/dist/src/types.d.ts +2 -1
- package/dist/src/utils/create-token.d.ts +1 -1
- package/package.json +1 -1
- package/src/StreamCall.ts +56 -1
- package/src/StreamClient.ts +18 -0
- package/src/StreamVideoClient.ts +1 -1
- package/src/gen/model-decoders/decoders.ts +15 -2
- package/src/gen/models/index.ts +14 -2
- package/src/types.ts +2 -1
- package/src/utils/create-token.ts +1 -1
package/dist/src/StreamCall.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VideoApi } from './gen-imports';
|
|
2
|
+
import { CallResponse, GetOrCreateCallRequest, QueryCallMembersRequest } from './gen/models';
|
|
2
3
|
import { CallApi } from './gen/video/CallApi';
|
|
4
|
+
import { StreamClient } from './StreamClient';
|
|
3
5
|
import { OmitTypeId } from './types';
|
|
4
6
|
export declare class StreamCall extends CallApi {
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly id: string;
|
|
9
|
+
private readonly streamClient;
|
|
10
|
+
data?: CallResponse;
|
|
11
|
+
constructor(videoApi: VideoApi, type: string, id: string, streamClient: StreamClient);
|
|
5
12
|
get cid(): string;
|
|
6
13
|
create: (request?: GetOrCreateCallRequest) => Promise<import("./types").StreamResponse<import("./gen/models").GetOrCreateCallResponse>>;
|
|
7
14
|
queryMembers: (request?: OmitTypeId<QueryCallMembersRequest>) => Promise<import("./types").StreamResponse<import("./gen/models").QueryCallMembersResponse>>;
|
|
15
|
+
getOrCreate: (request?: GetOrCreateCallRequest) => Promise<import("./types").StreamResponse<import("./gen/models").GetOrCreateCallResponse>>;
|
|
16
|
+
get: () => Promise<import("./types").StreamResponse<import("./gen/models").GetCallResponse>>;
|
|
17
|
+
createSRTCredetials: (userID: string) => {
|
|
18
|
+
address: string;
|
|
19
|
+
};
|
|
8
20
|
}
|
|
@@ -54,6 +54,16 @@ export declare class StreamClient extends CommonApi {
|
|
|
54
54
|
exp?: number;
|
|
55
55
|
iat?: number;
|
|
56
56
|
} & Record<string, unknown>) => string;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param payload
|
|
60
|
+
* - user_id - the id of the user the token is for
|
|
61
|
+
* - iat - issued at date of the token, unix timestamp in seconds, by default it's now
|
|
62
|
+
*/
|
|
63
|
+
generatePermanentUserToken: (payload: {
|
|
64
|
+
user_id: string;
|
|
65
|
+
iat?: number;
|
|
66
|
+
} & Record<string, unknown>) => string;
|
|
57
67
|
/**
|
|
58
68
|
*
|
|
59
69
|
* @param payload
|
|
@@ -332,6 +332,13 @@ export interface ActivityResponse {
|
|
|
332
332
|
poll?: PollResponseData;
|
|
333
333
|
}
|
|
334
334
|
export interface ActivitySelectorConfig {
|
|
335
|
+
cutoff_time?: string;
|
|
336
|
+
min_popularity?: number;
|
|
337
|
+
type?: string;
|
|
338
|
+
sort?: SortParam[];
|
|
339
|
+
filter?: Record<string, any>;
|
|
340
|
+
}
|
|
341
|
+
export interface ActivitySelectorConfigResponse {
|
|
335
342
|
cutoff_time?: Date;
|
|
336
343
|
min_popularity?: number;
|
|
337
344
|
type?: string;
|
|
@@ -2991,7 +2998,7 @@ export interface FeedGroupResponse {
|
|
|
2991
2998
|
updated_at: Date;
|
|
2992
2999
|
default_visibility?: string;
|
|
2993
3000
|
activity_processors?: ActivityProcessorConfig[];
|
|
2994
|
-
activity_selectors?:
|
|
3001
|
+
activity_selectors?: ActivitySelectorConfigResponse[];
|
|
2995
3002
|
aggregation?: AggregationConfig;
|
|
2996
3003
|
custom?: Record<string, any>;
|
|
2997
3004
|
notification?: NotificationConfig;
|
|
@@ -3133,7 +3140,7 @@ export interface FeedViewResponse {
|
|
|
3133
3140
|
id: string;
|
|
3134
3141
|
last_used_at?: Date;
|
|
3135
3142
|
activity_processors?: ActivityProcessorConfig[];
|
|
3136
|
-
activity_selectors?:
|
|
3143
|
+
activity_selectors?: ActivitySelectorConfigResponse[];
|
|
3137
3144
|
aggregation?: AggregationConfig;
|
|
3138
3145
|
ranking?: RankingConfig;
|
|
3139
3146
|
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ApiConfig {
|
|
|
7
7
|
/** The timeout for requests in milliseconds. The default is 3000. */
|
|
8
8
|
timeout: number;
|
|
9
9
|
agent?: RequestInit['dispatcher'];
|
|
10
|
+
secret?: string;
|
|
10
11
|
}
|
|
11
12
|
export interface RequestMetadata {
|
|
12
13
|
responseHeaders: Headers;
|
|
@@ -29,7 +30,7 @@ export interface RateLimit {
|
|
|
29
30
|
}
|
|
30
31
|
interface BaseTokenPayload {
|
|
31
32
|
user_id: string;
|
|
32
|
-
exp
|
|
33
|
+
exp?: number;
|
|
33
34
|
iat: number;
|
|
34
35
|
call_cids?: string[];
|
|
35
36
|
}
|
package/package.json
CHANGED
package/src/StreamCall.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VideoApi } from './gen-imports';
|
|
2
|
+
import {
|
|
3
|
+
CallResponse,
|
|
4
|
+
GetOrCreateCallRequest,
|
|
5
|
+
QueryCallMembersRequest,
|
|
6
|
+
} from './gen/models';
|
|
2
7
|
import { CallApi } from './gen/video/CallApi';
|
|
8
|
+
import { StreamClient } from './StreamClient';
|
|
3
9
|
import { OmitTypeId } from './types';
|
|
4
10
|
|
|
5
11
|
export class StreamCall extends CallApi {
|
|
12
|
+
data?: CallResponse;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
videoApi: VideoApi,
|
|
16
|
+
readonly type: string,
|
|
17
|
+
readonly id: string,
|
|
18
|
+
private readonly streamClient: StreamClient,
|
|
19
|
+
) {
|
|
20
|
+
super(videoApi, type, id);
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
get cid() {
|
|
7
24
|
return `${this.type}:${this.id}`;
|
|
8
25
|
}
|
|
@@ -16,4 +33,42 @@ export class StreamCall extends CallApi {
|
|
|
16
33
|
...(request ?? {}),
|
|
17
34
|
});
|
|
18
35
|
};
|
|
36
|
+
|
|
37
|
+
getOrCreate = async (request?: GetOrCreateCallRequest) => {
|
|
38
|
+
const response = await super.getOrCreate(request);
|
|
39
|
+
this.data = response.call;
|
|
40
|
+
return response;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
get = async () => {
|
|
44
|
+
const response = await super.get();
|
|
45
|
+
this.data = response.call;
|
|
46
|
+
return response;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
createSRTCredetials = (
|
|
50
|
+
userID: string,
|
|
51
|
+
): {
|
|
52
|
+
address: string;
|
|
53
|
+
} => {
|
|
54
|
+
if (!this.data) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'Object is not initialized, call get() or getOrCreate() first',
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const token = this.streamClient.generatePermanentUserToken({
|
|
61
|
+
user_id: userID,
|
|
62
|
+
});
|
|
63
|
+
const segments = token.split('.');
|
|
64
|
+
if (segments.length !== 3) {
|
|
65
|
+
throw new Error('Invalid token format');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
address: this.data.ingress.srt.address
|
|
70
|
+
.replace('{passphrase}', segments[2])
|
|
71
|
+
.replace('{token}', token),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
19
74
|
}
|
package/src/StreamClient.ts
CHANGED
|
@@ -145,6 +145,24 @@ export class StreamClient extends CommonApi {
|
|
|
145
145
|
return JWTUserToken(this.secret, payload as UserTokenPayload);
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* @param payload
|
|
151
|
+
* - user_id - the id of the user the token is for
|
|
152
|
+
* - iat - issued at date of the token, unix timestamp in seconds, by default it's now
|
|
153
|
+
*/
|
|
154
|
+
generatePermanentUserToken = (
|
|
155
|
+
payload: {
|
|
156
|
+
user_id: string;
|
|
157
|
+
iat?: number;
|
|
158
|
+
} & Record<string, unknown>,
|
|
159
|
+
) => {
|
|
160
|
+
const defaultIat = Math.floor((Date.now() - 1000) / 1000);
|
|
161
|
+
payload.iat = payload.iat ?? defaultIat;
|
|
162
|
+
|
|
163
|
+
return JWTUserToken(this.secret, payload as UserTokenPayload);
|
|
164
|
+
};
|
|
165
|
+
|
|
148
166
|
/**
|
|
149
167
|
*
|
|
150
168
|
* @param payload
|
package/src/StreamVideoClient.ts
CHANGED
|
@@ -225,6 +225,13 @@ decoders.ActivityResponse = (input?: Record<string, any>) => {
|
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
decoders.ActivitySelectorConfig = (input?: Record<string, any>) => {
|
|
228
|
+
const typeMappings: TypeMapping = {
|
|
229
|
+
cutoff_time: { type: 'StringType', isSingle: true },
|
|
230
|
+
};
|
|
231
|
+
return decode(typeMappings, input);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
decoders.ActivitySelectorConfigResponse = (input?: Record<string, any>) => {
|
|
228
235
|
const typeMappings: TypeMapping = {
|
|
229
236
|
cutoff_time: { type: 'DatetimeType', isSingle: true },
|
|
230
237
|
};
|
|
@@ -1903,7 +1910,10 @@ decoders.FeedGroupResponse = (input?: Record<string, any>) => {
|
|
|
1903
1910
|
|
|
1904
1911
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
1905
1912
|
|
|
1906
|
-
activity_selectors: {
|
|
1913
|
+
activity_selectors: {
|
|
1914
|
+
type: 'ActivitySelectorConfigResponse',
|
|
1915
|
+
isSingle: false,
|
|
1916
|
+
},
|
|
1907
1917
|
};
|
|
1908
1918
|
return decode(typeMappings, input);
|
|
1909
1919
|
};
|
|
@@ -1996,7 +2006,10 @@ decoders.FeedViewResponse = (input?: Record<string, any>) => {
|
|
|
1996
2006
|
const typeMappings: TypeMapping = {
|
|
1997
2007
|
last_used_at: { type: 'DatetimeType', isSingle: true },
|
|
1998
2008
|
|
|
1999
|
-
activity_selectors: {
|
|
2009
|
+
activity_selectors: {
|
|
2010
|
+
type: 'ActivitySelectorConfigResponse',
|
|
2011
|
+
isSingle: false,
|
|
2012
|
+
},
|
|
2000
2013
|
};
|
|
2001
2014
|
return decode(typeMappings, input);
|
|
2002
2015
|
};
|
package/src/gen/models/index.ts
CHANGED
|
@@ -595,6 +595,18 @@ export interface ActivityResponse {
|
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
export interface ActivitySelectorConfig {
|
|
598
|
+
cutoff_time?: string;
|
|
599
|
+
|
|
600
|
+
min_popularity?: number;
|
|
601
|
+
|
|
602
|
+
type?: string;
|
|
603
|
+
|
|
604
|
+
sort?: SortParam[];
|
|
605
|
+
|
|
606
|
+
filter?: Record<string, any>;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export interface ActivitySelectorConfigResponse {
|
|
598
610
|
cutoff_time?: Date;
|
|
599
611
|
|
|
600
612
|
min_popularity?: number;
|
|
@@ -5257,7 +5269,7 @@ export interface FeedGroupResponse {
|
|
|
5257
5269
|
|
|
5258
5270
|
activity_processors?: ActivityProcessorConfig[];
|
|
5259
5271
|
|
|
5260
|
-
activity_selectors?:
|
|
5272
|
+
activity_selectors?: ActivitySelectorConfigResponse[];
|
|
5261
5273
|
|
|
5262
5274
|
aggregation?: AggregationConfig;
|
|
5263
5275
|
|
|
@@ -5493,7 +5505,7 @@ export interface FeedViewResponse {
|
|
|
5493
5505
|
|
|
5494
5506
|
activity_processors?: ActivityProcessorConfig[];
|
|
5495
5507
|
|
|
5496
|
-
activity_selectors?:
|
|
5508
|
+
activity_selectors?: ActivitySelectorConfigResponse[];
|
|
5497
5509
|
|
|
5498
5510
|
aggregation?: AggregationConfig;
|
|
5499
5511
|
|
package/src/types.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface ApiConfig {
|
|
|
7
7
|
/** The timeout for requests in milliseconds. The default is 3000. */
|
|
8
8
|
timeout: number;
|
|
9
9
|
agent?: RequestInit['dispatcher'];
|
|
10
|
+
secret?: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface RequestMetadata {
|
|
@@ -39,7 +40,7 @@ export interface RateLimit {
|
|
|
39
40
|
|
|
40
41
|
interface BaseTokenPayload {
|
|
41
42
|
user_id: string;
|
|
42
|
-
exp
|
|
43
|
+
exp?: number;
|
|
43
44
|
iat: number;
|
|
44
45
|
call_cids?: string[];
|
|
45
46
|
}
|