@stream-io/node-sdk 0.3.0 → 0.4.0

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.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs.js +4140 -9282
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.es.js +4140 -9206
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/src/BaseApi.d.ts +10 -0
  8. package/dist/src/StreamCall.d.ts +5 -37
  9. package/dist/src/StreamChannel.d.ts +7 -34
  10. package/dist/src/StreamChatClient.d.ts +2 -25
  11. package/dist/src/StreamClient.d.ts +51 -59
  12. package/dist/src/StreamModerationClient.d.ts +3 -0
  13. package/dist/src/StreamVideoClient.d.ts +2 -18
  14. package/dist/src/gen/chat/ChannelApi.d.ts +33 -0
  15. package/dist/src/gen/chat/ChatApi.d.ts +241 -0
  16. package/dist/src/gen/common/CommonApi.d.ts +99 -0
  17. package/dist/src/gen/model-decoders/index.d.ts +3 -0
  18. package/dist/src/gen/models/index.d.ts +3878 -0
  19. package/dist/src/gen/moderation/ModerationApi.d.ts +38 -0
  20. package/dist/src/gen/video/CallApi.d.ts +56 -0
  21. package/dist/src/gen/video/VideoApi.d.ts +151 -0
  22. package/dist/src/types.d.ts +25 -0
  23. package/dist/src/utils/create-token.d.ts +2 -0
  24. package/dist/src/utils/rate-limit.d.ts +2 -0
  25. package/index.ts +2 -3
  26. package/package.json +12 -4
  27. package/src/BaseApi.ts +115 -0
  28. package/src/StreamCall.ts +9 -199
  29. package/src/StreamChannel.ts +23 -246
  30. package/src/StreamChatClient.ts +3 -122
  31. package/src/StreamClient.ts +101 -345
  32. package/src/StreamModerationClient.ts +3 -0
  33. package/src/StreamVideoClient.ts +3 -95
  34. package/src/gen/chat/ChannelApi.ts +270 -0
  35. package/src/gen/chat/ChatApi.ts +1857 -0
  36. package/src/gen/common/CommonApi.ts +1004 -0
  37. package/src/gen/model-decoders/index.ts +1897 -0
  38. package/src/gen/models/index.ts +6790 -0
  39. package/src/gen/moderation/ModerationApi.ts +476 -0
  40. package/src/gen/video/CallApi.ts +309 -0
  41. package/src/gen/video/VideoApi.ts +1011 -0
  42. package/src/types.ts +35 -0
  43. package/src/utils/create-token.ts +6 -1
  44. package/src/utils/rate-limit.ts +21 -0
  45. package/dist/src/gen/chat/apis/ProductchatApi.d.ts +0 -1750
  46. package/dist/src/gen/chat/apis/index.d.ts +0 -1
  47. package/dist/src/gen/chat/index.d.ts +0 -3
  48. package/dist/src/gen/chat/models/index.d.ts +0 -14865
  49. package/dist/src/gen/chat/runtime.d.ts +0 -180
  50. package/dist/src/gen/video/apis/ProductvideoApi.d.ts +0 -648
  51. package/dist/src/gen/video/apis/index.d.ts +0 -1
  52. package/dist/src/gen/video/index.d.ts +0 -3
  53. package/dist/src/gen/video/models/index.d.ts +0 -5011
  54. package/dist/src/gen/video/runtime.d.ts +0 -180
  55. package/src/gen/chat/.openapi-generator/FILES +0 -6
  56. package/src/gen/chat/.openapi-generator/VERSION +0 -1
  57. package/src/gen/chat/.openapi-generator-ignore +0 -23
  58. package/src/gen/chat/apis/ProductchatApi.ts +0 -7007
  59. package/src/gen/chat/apis/index.ts +0 -3
  60. package/src/gen/chat/index.ts +0 -5
  61. package/src/gen/chat/models/index.ts +0 -14766
  62. package/src/gen/chat/runtime.ts +0 -415
  63. package/src/gen/video/.openapi-generator/FILES +0 -6
  64. package/src/gen/video/.openapi-generator/VERSION +0 -1
  65. package/src/gen/video/.openapi-generator-ignore +0 -23
  66. package/src/gen/video/apis/ProductvideoApi.ts +0 -2575
  67. package/src/gen/video/apis/index.ts +0 -3
  68. package/src/gen/video/index.ts +0 -5
  69. package/src/gen/video/models/index.ts +0 -5000
  70. package/src/gen/video/runtime.ts +0 -415
package/src/types.ts CHANGED
@@ -1,5 +1,40 @@
1
1
  export type OmitTypeId<T> = Omit<T, 'type' | 'id' | 'connection_id'>;
2
2
 
3
+ export interface ApiConfig {
4
+ apiKey: string;
5
+ token: string;
6
+ baseUrl: string;
7
+ timeout: number;
8
+ }
9
+
10
+ export interface RequestMetadata {
11
+ responseHeaders: Headers;
12
+ rateLimit: RateLimit;
13
+ responseCode: number;
14
+ clientRequestId: string;
15
+ }
16
+
17
+ export type StreamResponse<T> = T & {
18
+ metadata: RequestMetadata;
19
+ };
20
+
21
+ export class StreamError extends Error {
22
+ constructor(
23
+ message: string,
24
+ public metadata: Partial<RequestMetadata>,
25
+ public code?: number,
26
+ errorOptions?: ErrorOptions,
27
+ ) {
28
+ super(message, errorOptions);
29
+ }
30
+ }
31
+
32
+ export interface RateLimit {
33
+ rateLimit?: number;
34
+ rateLimitRemaining?: number;
35
+ rateLimitReset?: Date;
36
+ }
37
+
3
38
  interface BaseTokenPayload {
4
39
  user_id: string;
5
40
  exp: number;
@@ -2,7 +2,12 @@ import jwt, { Secret, SignOptions } from 'jsonwebtoken';
2
2
 
3
3
  export function JWTUserToken(
4
4
  apiSecret: Secret,
5
- payload: { user_id: string; exp: number; iat: number; call_cids?: string[] },
5
+ payload: {
6
+ user_id: string;
7
+ exp: number;
8
+ iat: number;
9
+ call_cids?: string[];
10
+ } & { [key: string]: any },
6
11
  ) {
7
12
  // make sure we return a clear error when jwt is shimmed (ie. browser build)
8
13
  if (jwt == null || jwt.sign == null) {
@@ -0,0 +1,21 @@
1
+ import { RateLimit } from '../types';
2
+
3
+ export const getRateLimitFromResponseHeader = (responseHeaders: Headers) => {
4
+ const rateLimit = responseHeaders.has('x-ratelimit-limit')
5
+ ? +responseHeaders.get('x-ratelimit-limit')!
6
+ : undefined;
7
+ const rateLimitRemaining = responseHeaders.has('x-ratelimit-remaining')
8
+ ? +responseHeaders.get('x-ratelimit-remaining')!
9
+ : undefined;
10
+ const rateLimitReset = responseHeaders.has('x-ratelimit-reset')
11
+ ? new Date(+responseHeaders.get('x-ratelimit-reset')! * 1000)
12
+ : undefined;
13
+
14
+ const result: RateLimit = {
15
+ rateLimit,
16
+ rateLimitRemaining,
17
+ rateLimitReset,
18
+ };
19
+
20
+ return result;
21
+ };