@stream-io/node-sdk 0.3.1 → 0.4.1

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 (69) hide show
  1. package/dist/index.cjs.js +4136 -9282
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +2 -3
  4. package/dist/index.es.js +4136 -9206
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/src/BaseApi.d.ts +10 -0
  7. package/dist/src/StreamCall.d.ts +5 -37
  8. package/dist/src/StreamChannel.d.ts +7 -34
  9. package/dist/src/StreamChatClient.d.ts +2 -25
  10. package/dist/src/StreamClient.d.ts +51 -59
  11. package/dist/src/StreamModerationClient.d.ts +3 -0
  12. package/dist/src/StreamVideoClient.d.ts +2 -18
  13. package/dist/src/gen/chat/ChannelApi.d.ts +33 -0
  14. package/dist/src/gen/chat/ChatApi.d.ts +241 -0
  15. package/dist/src/gen/common/CommonApi.d.ts +99 -0
  16. package/dist/src/gen/model-decoders/index.d.ts +3 -0
  17. package/dist/src/gen/models/index.d.ts +3881 -0
  18. package/dist/src/gen/moderation/ModerationApi.d.ts +38 -0
  19. package/dist/src/gen/video/CallApi.d.ts +56 -0
  20. package/dist/src/gen/video/VideoApi.d.ts +151 -0
  21. package/dist/src/types.d.ts +25 -0
  22. package/dist/src/utils/create-token.d.ts +2 -0
  23. package/dist/src/utils/rate-limit.d.ts +2 -0
  24. package/index.ts +2 -3
  25. package/package.json +5 -4
  26. package/src/BaseApi.ts +115 -0
  27. package/src/StreamCall.ts +9 -199
  28. package/src/StreamChannel.ts +23 -246
  29. package/src/StreamChatClient.ts +3 -122
  30. package/src/StreamClient.ts +101 -345
  31. package/src/StreamModerationClient.ts +3 -0
  32. package/src/StreamVideoClient.ts +3 -95
  33. package/src/gen/chat/ChannelApi.ts +270 -0
  34. package/src/gen/chat/ChatApi.ts +1857 -0
  35. package/src/gen/common/CommonApi.ts +1004 -0
  36. package/src/gen/model-decoders/index.ts +1897 -0
  37. package/src/gen/models/index.ts +6794 -0
  38. package/src/gen/moderation/ModerationApi.ts +476 -0
  39. package/src/gen/video/CallApi.ts +309 -0
  40. package/src/gen/video/VideoApi.ts +1007 -0
  41. package/src/types.ts +35 -0
  42. package/src/utils/create-token.ts +6 -1
  43. package/src/utils/rate-limit.ts +21 -0
  44. package/dist/src/gen/chat/apis/ProductchatApi.d.ts +0 -1750
  45. package/dist/src/gen/chat/apis/index.d.ts +0 -1
  46. package/dist/src/gen/chat/index.d.ts +0 -3
  47. package/dist/src/gen/chat/models/index.d.ts +0 -14865
  48. package/dist/src/gen/chat/runtime.d.ts +0 -180
  49. package/dist/src/gen/video/apis/ProductvideoApi.d.ts +0 -648
  50. package/dist/src/gen/video/apis/index.d.ts +0 -1
  51. package/dist/src/gen/video/index.d.ts +0 -3
  52. package/dist/src/gen/video/models/index.d.ts +0 -5011
  53. package/dist/src/gen/video/runtime.d.ts +0 -180
  54. package/src/gen/chat/.openapi-generator/FILES +0 -6
  55. package/src/gen/chat/.openapi-generator/VERSION +0 -1
  56. package/src/gen/chat/.openapi-generator-ignore +0 -23
  57. package/src/gen/chat/apis/ProductchatApi.ts +0 -7007
  58. package/src/gen/chat/apis/index.ts +0 -3
  59. package/src/gen/chat/index.ts +0 -5
  60. package/src/gen/chat/models/index.ts +0 -14766
  61. package/src/gen/chat/runtime.ts +0 -415
  62. package/src/gen/video/.openapi-generator/FILES +0 -6
  63. package/src/gen/video/.openapi-generator/VERSION +0 -1
  64. package/src/gen/video/.openapi-generator-ignore +0 -23
  65. package/src/gen/video/apis/ProductvideoApi.ts +0 -2575
  66. package/src/gen/video/apis/index.ts +0 -3
  67. package/src/gen/video/index.ts +0 -5
  68. package/src/gen/video/models/index.ts +0 -5000
  69. 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
+ };