@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.
@@ -1,8 +1,20 @@
1
- import { GetOrCreateCallRequest, QueryCallMembersRequest } from './gen/models';
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?: ActivitySelectorConfig[];
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?: ActivitySelectorConfig[];
3143
+ activity_selectors?: ActivitySelectorConfigResponse[];
3137
3144
  aggregation?: AggregationConfig;
3138
3145
  ranking?: RankingConfig;
3139
3146
  }
@@ -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: number;
33
+ exp?: number;
33
34
  iat: number;
34
35
  call_cids?: string[];
35
36
  }
@@ -1,7 +1,7 @@
1
1
  import { Secret, SignOptions } from 'jsonwebtoken';
2
2
  export declare function JWTUserToken(apiSecret: Secret, payload: {
3
3
  user_id: string;
4
- exp: number;
4
+ exp?: number;
5
5
  iat: number;
6
6
  call_cids?: string[];
7
7
  } & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/node-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
package/src/StreamCall.ts CHANGED
@@ -1,8 +1,25 @@
1
- import { GetOrCreateCallRequest, QueryCallMembersRequest } from './gen/models';
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
  }
@@ -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
@@ -25,7 +25,7 @@ export class StreamVideoClient extends VideoApi {
25
25
  }
26
26
 
27
27
  call = (type: string, id: string) => {
28
- return new StreamCall(this, type, id);
28
+ return new StreamCall(this, type, id, this.streamClient);
29
29
  };
30
30
 
31
31
  connectOpenAi = async (options: {
@@ -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: { type: 'ActivitySelectorConfig', isSingle: false },
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: { type: 'ActivitySelectorConfig', isSingle: false },
2009
+ activity_selectors: {
2010
+ type: 'ActivitySelectorConfigResponse',
2011
+ isSingle: false,
2012
+ },
2000
2013
  };
2001
2014
  return decode(typeMappings, input);
2002
2015
  };
@@ -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?: ActivitySelectorConfig[];
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?: ActivitySelectorConfig[];
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: number;
43
+ exp?: number;
43
44
  iat: number;
44
45
  call_cids?: string[];
45
46
  }
@@ -4,7 +4,7 @@ export function JWTUserToken(
4
4
  apiSecret: Secret,
5
5
  payload: {
6
6
  user_id: string;
7
- exp: number;
7
+ exp?: number;
8
8
  iat: number;
9
9
  call_cids?: string[];
10
10
  } & { [key: string]: any },