@stream-io/node-sdk 0.4.20 → 0.4.21
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/index.cjs.js +11 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.mjs +11 -14
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/BaseApi.d.ts +1 -1
- package/dist/src/StreamClient.d.ts +1 -5
- package/dist/src/types.d.ts +2 -2
- package/dist/src/utils/rate-limit.d.ts +1 -0
- package/package.json +2 -3
- package/src/BaseApi.ts +1 -3
- package/src/StreamClient.ts +12 -17
- package/src/types.ts +1 -3
package/dist/src/BaseApi.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiConfig, RequestMetadata } from './types';
|
|
2
2
|
export declare class BaseApi {
|
|
3
3
|
protected readonly apiConfig: ApiConfig;
|
|
4
|
-
private readonly dispatcher
|
|
4
|
+
private readonly dispatcher?;
|
|
5
5
|
constructor(apiConfig: ApiConfig);
|
|
6
6
|
protected sendRequest: <T>(method: string, url: string, pathParams?: Record<string, string>, queryParams?: Record<string, any>, body?: any) => Promise<{
|
|
7
7
|
body: T;
|
|
@@ -5,14 +5,11 @@ import { StreamVideoClient } from './StreamVideoClient';
|
|
|
5
5
|
import { StreamChatClient } from './StreamChatClient';
|
|
6
6
|
import { QueryBannedUsersPayload, UserRequest } from './gen/models';
|
|
7
7
|
import { StreamModerationClient } from './StreamModerationClient';
|
|
8
|
-
import { Agent } from 'undici';
|
|
9
8
|
export interface StreamClientOptions {
|
|
10
9
|
timeout?: number;
|
|
11
10
|
basePath?: string;
|
|
12
|
-
/** The max number of clients to create. `null` if no limit. Default is 100. Has no effect if `agent` is provided. */
|
|
13
|
-
maxConnections?: number | null;
|
|
14
11
|
/** The [HTTP Agent](https://undici.nodejs.org/#/docs/api/Agent.md) to use. */
|
|
15
|
-
agent?:
|
|
12
|
+
agent?: unknown;
|
|
16
13
|
}
|
|
17
14
|
export declare class StreamClient extends CommonApi {
|
|
18
15
|
readonly apiKey: string;
|
|
@@ -23,7 +20,6 @@ export declare class StreamClient extends CommonApi {
|
|
|
23
20
|
readonly moderation: StreamModerationClient;
|
|
24
21
|
readonly options: StreamClientOptions;
|
|
25
22
|
private static readonly DEFAULT_TIMEOUT;
|
|
26
|
-
private static readonly MAX_CONNECTIONS;
|
|
27
23
|
/**
|
|
28
24
|
*
|
|
29
25
|
* @param apiKey
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
2
|
export type OmitTypeId<T> = Omit<T, 'type' | 'id' | 'connection_id'>;
|
|
3
3
|
export interface ApiConfig {
|
|
4
4
|
apiKey: string;
|
|
@@ -6,7 +6,7 @@ export interface ApiConfig {
|
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
/** The timeout for requests in milliseconds. The default is 3000. */
|
|
8
8
|
timeout: number;
|
|
9
|
-
agent
|
|
9
|
+
agent?: RequestInit['dispatcher'];
|
|
10
10
|
}
|
|
11
11
|
export interface RequestMetadata {
|
|
12
12
|
responseHeaders: Headers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/node-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -71,9 +71,8 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@types/jsonwebtoken": "^9.0.3",
|
|
74
|
-
"@types/node": "^
|
|
74
|
+
"@types/node": "^18.3.0",
|
|
75
75
|
"jsonwebtoken": "^9.0.2",
|
|
76
|
-
"undici": "^5.29.0",
|
|
77
76
|
"uuid": "^9.0.1"
|
|
78
77
|
},
|
|
79
78
|
"peerDependencies": {
|
package/src/BaseApi.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
2
2
|
import { ApiConfig, RequestMetadata, StreamError } from './types';
|
|
3
3
|
import { APIError } from './gen/models';
|
|
4
4
|
import { getRateLimitFromResponseHeader } from './utils/rate-limit';
|
|
5
|
-
import { Agent } from 'undici';
|
|
6
5
|
|
|
7
6
|
export class BaseApi {
|
|
8
|
-
private readonly dispatcher
|
|
7
|
+
private readonly dispatcher?: RequestInit['dispatcher'];
|
|
9
8
|
|
|
10
9
|
constructor(protected readonly apiConfig: ApiConfig) {
|
|
11
10
|
this.dispatcher = this.apiConfig.agent;
|
|
@@ -46,7 +45,6 @@ export class BaseApi {
|
|
|
46
45
|
method,
|
|
47
46
|
body: JSON.stringify(body),
|
|
48
47
|
headers,
|
|
49
|
-
/** @ts-expect-error we get types from DOM here, but we should use node types */
|
|
50
48
|
dispatcher: this.dispatcher,
|
|
51
49
|
});
|
|
52
50
|
|
package/src/StreamClient.ts
CHANGED
|
@@ -6,15 +6,13 @@ import { StreamChatClient } from './StreamChatClient';
|
|
|
6
6
|
import { CallTokenPayload, UserTokenPayload } from './types';
|
|
7
7
|
import { QueryBannedUsersPayload, UserRequest } from './gen/models';
|
|
8
8
|
import { StreamModerationClient } from './StreamModerationClient';
|
|
9
|
-
import { Agent } from 'undici';
|
|
10
9
|
|
|
11
10
|
export interface StreamClientOptions {
|
|
12
11
|
timeout?: number;
|
|
13
12
|
basePath?: string;
|
|
14
|
-
|
|
15
|
-
maxConnections?: number | null;
|
|
13
|
+
// We use unknown here because RequestInit['dispatcher'] is different between Node versions
|
|
16
14
|
/** The [HTTP Agent](https://undici.nodejs.org/#/docs/api/Agent.md) to use. */
|
|
17
|
-
agent?:
|
|
15
|
+
agent?: unknown;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
export class StreamClient extends CommonApi {
|
|
@@ -24,7 +22,6 @@ export class StreamClient extends CommonApi {
|
|
|
24
22
|
public readonly options: StreamClientOptions = {};
|
|
25
23
|
|
|
26
24
|
private static readonly DEFAULT_TIMEOUT = 3000;
|
|
27
|
-
private static readonly MAX_CONNECTIONS = 100;
|
|
28
25
|
|
|
29
26
|
/**
|
|
30
27
|
*
|
|
@@ -39,17 +36,15 @@ export class StreamClient extends CommonApi {
|
|
|
39
36
|
) {
|
|
40
37
|
const token = JWTServerToken(secret);
|
|
41
38
|
const timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT;
|
|
42
|
-
const agent =
|
|
43
|
-
config?.agent ??
|
|
44
|
-
new Agent({
|
|
45
|
-
connections:
|
|
46
|
-
config?.maxConnections === undefined
|
|
47
|
-
? StreamClient.MAX_CONNECTIONS
|
|
48
|
-
: config.maxConnections,
|
|
49
|
-
});
|
|
50
39
|
const chatBaseUrl = config?.basePath ?? 'https://chat.stream-io-api.com';
|
|
51
40
|
const videoBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com';
|
|
52
|
-
super({
|
|
41
|
+
super({
|
|
42
|
+
apiKey,
|
|
43
|
+
token,
|
|
44
|
+
timeout,
|
|
45
|
+
baseUrl: chatBaseUrl,
|
|
46
|
+
agent: config?.agent as RequestInit['dispatcher'],
|
|
47
|
+
});
|
|
53
48
|
|
|
54
49
|
this.video = new StreamVideoClient({
|
|
55
50
|
streamClient: this,
|
|
@@ -57,21 +52,21 @@ export class StreamClient extends CommonApi {
|
|
|
57
52
|
token,
|
|
58
53
|
timeout,
|
|
59
54
|
baseUrl: videoBaseUrl,
|
|
60
|
-
agent,
|
|
55
|
+
agent: config?.agent as RequestInit['dispatcher'],
|
|
61
56
|
});
|
|
62
57
|
this.chat = new StreamChatClient({
|
|
63
58
|
apiKey,
|
|
64
59
|
token,
|
|
65
60
|
timeout,
|
|
66
61
|
baseUrl: chatBaseUrl,
|
|
67
|
-
agent,
|
|
62
|
+
agent: config?.agent as RequestInit['dispatcher'],
|
|
68
63
|
});
|
|
69
64
|
this.moderation = new StreamModerationClient({
|
|
70
65
|
apiKey,
|
|
71
66
|
token,
|
|
72
67
|
timeout,
|
|
73
68
|
baseUrl: chatBaseUrl,
|
|
74
|
-
agent,
|
|
69
|
+
agent: config?.agent as RequestInit['dispatcher'],
|
|
75
70
|
});
|
|
76
71
|
}
|
|
77
72
|
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Agent } from 'undici';
|
|
2
|
-
|
|
3
1
|
export type OmitTypeId<T> = Omit<T, 'type' | 'id' | 'connection_id'>;
|
|
4
2
|
|
|
5
3
|
export interface ApiConfig {
|
|
@@ -8,7 +6,7 @@ export interface ApiConfig {
|
|
|
8
6
|
baseUrl: string;
|
|
9
7
|
/** The timeout for requests in milliseconds. The default is 3000. */
|
|
10
8
|
timeout: number;
|
|
11
|
-
agent
|
|
9
|
+
agent?: RequestInit['dispatcher'];
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
export interface RequestMetadata {
|