@composio/core 0.31.0 → 0.33.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 (92) hide show
  1. package/dist/{CustomTool-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
  2. package/dist/{CustomTool-Ds5aLDth.d.mts → CustomTool-C2kvAvzk.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
  4. package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
  5. package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-CcCuFVUb.mjs} +2 -2
  6. package/dist/composio-BqE615oV.d.mts +20365 -0
  7. package/dist/{customTool.types-DHxXBU6E.d.mts → customTool.types-DnyEZmlx.d.mts} +510 -33
  8. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +20 -12
  9. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
  10. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +96 -40
  11. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
  12. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
  13. package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
  14. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
  15. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
  16. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +53 -42
  17. package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
  18. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
  19. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
  20. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
  21. package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
  22. package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
  23. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
  24. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
  25. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +16 -18
  26. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
  27. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
  28. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
  29. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
  30. package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
  31. package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
  32. package/dist/experimental/index.d.mts +2 -2
  33. package/dist/experimental/index.mjs +1 -1
  34. package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-DPMtE0ER.mjs} +7 -71
  35. package/dist/index.d.mts +7 -245
  36. package/dist/index.mjs +573 -251
  37. package/dist/jsonSchema-CDHLYm7d.d.mts +237 -0
  38. package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-CfZwBS13.mjs} +7 -3
  39. package/dist/models/Files.node.mjs +3 -3
  40. package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-6NcnFSyX.mjs} +82 -85
  41. package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
  42. package/dist/{types-DcdZy5Nc.d.mts → types-Cwr_Makk.d.mts} +2 -2
  43. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  44. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  45. package/dist/utils/json-schema.d.mts +2 -1
  46. package/dist/utils/json-schema.mjs +2 -1
  47. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  48. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
  49. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  50. package/dist/utils/ssrfGuard.node.mjs +1 -1
  51. package/dist/utils/ssrfGuard.workerd.mjs +1 -1
  52. package/package.json +6 -6
  53. package/src/composio.ts +26 -7
  54. package/src/errors/ComposioError.ts +3 -2
  55. package/src/index.ts +19 -0
  56. package/src/lib/toolRouterParams.ts +38 -14
  57. package/src/models/AuthConfigs.ts +10 -3
  58. package/src/models/ConnectedAccounts.ts +101 -28
  59. package/src/models/CustomTool.ts +0 -10
  60. package/src/models/Keyring.ts +2 -1
  61. package/src/models/MCP.ts +43 -35
  62. package/src/models/SessionWebhooks.ts +136 -0
  63. package/src/models/ToolRouter.ts +39 -4
  64. package/src/models/ToolRouterSession.ts +2 -2
  65. package/src/models/ToolRouterSessionFileMount.ts +3 -1
  66. package/src/models/Toolkits.ts +1 -0
  67. package/src/models/Tools.ts +4 -8
  68. package/src/models/Triggers.ts +48 -213
  69. package/src/models/Webhooks.ts +2 -0
  70. package/src/provider/ComposioProvider.ts +0 -1
  71. package/src/telemetry/BatchProcessor.ts +1 -1
  72. package/src/telemetry/Telemetry.ts +1 -1
  73. package/src/types/connectedAccountAuthStates.types.ts +0 -1
  74. package/src/types/connectedAccounts.types.ts +59 -1
  75. package/src/types/provider.types.ts +0 -1
  76. package/src/types/sessionWebhooks.types.ts +292 -0
  77. package/src/types/toolRouter.types.ts +35 -5
  78. package/src/types/triggers.types.ts +4 -0
  79. package/src/utils/crypto.ts +6 -5
  80. package/src/utils/env.ts +2 -5
  81. package/src/utils/fileUtils.node.ts +5 -86
  82. package/src/utils/json-schema.ts +6 -0
  83. package/src/utils/jsonSchema.ts +17 -4
  84. package/src/utils/logger.ts +19 -9
  85. package/src/utils/mime.ts +25 -385
  86. package/src/utils/mimeTables.generated.ts +356 -0
  87. package/src/utils/pusher.ts +5 -2
  88. package/src/utils/readResponseBody.ts +30 -17
  89. package/src/utils/transformers/authConfigs.ts +0 -1
  90. package/src/utils/userCallback.ts +3 -1
  91. package/src/utils/webhookVerification.ts +211 -0
  92. package/dist/composio-Ba89XGHL.d.mts +0 -9736
@@ -0,0 +1,356 @@
1
+ // Generated from test/fixtures/mime/contract.json. Do not edit: change the contract and run
2
+ // `node test/fixtures/mime/generate-mime-tables.mjs`.
3
+
4
+ export const DEFAULT_MIME_TYPE = 'application/octet-stream';
5
+
6
+ export const EXTENSION_BY_MIME_TYPE: Readonly<Record<string, string>> = {
7
+ 'text/plain': 'txt',
8
+ 'text/html': 'html',
9
+ 'text/css': 'css',
10
+ 'text/csv': 'csv',
11
+ 'text/javascript': 'js',
12
+ 'application/json': 'json',
13
+ 'application/xml': 'xml',
14
+ 'application/pdf': 'pdf',
15
+ 'application/zip': 'zip',
16
+ 'application/x-zip-compressed': 'zip',
17
+ 'application/gzip': 'gz',
18
+ 'application/octet-stream': 'bin',
19
+ 'application/x-tar': 'tar',
20
+ 'application/msword': 'doc',
21
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
22
+ 'application/vnd.ms-excel': 'xls',
23
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
24
+ 'application/vnd.ms-powerpoint': 'ppt',
25
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
26
+ 'image/jpeg': 'jpg',
27
+ 'image/jpg': 'jpg',
28
+ 'image/png': 'png',
29
+ 'image/gif': 'gif',
30
+ 'image/svg+xml': 'svg',
31
+ 'image/webp': 'webp',
32
+ 'image/bmp': 'bmp',
33
+ 'image/tiff': 'tiff',
34
+ 'audio/mpeg': 'mp3',
35
+ 'audio/wav': 'wav',
36
+ 'audio/ogg': 'ogg',
37
+ 'video/mp4': 'mp4',
38
+ 'video/mpeg': 'mpeg',
39
+ 'video/quicktime': 'mov',
40
+ 'video/x-msvideo': 'avi',
41
+ 'video/webm': 'webm',
42
+ };
43
+
44
+ export const MIME_TYPES_BY_EXTENSION: Readonly<Record<string, string>> = {
45
+ '3g2': 'video/3gpp2',
46
+ '3gp': 'video/3gpp',
47
+ '3gpp': 'video/3gpp',
48
+ '7z': 'application/x-7z-compressed',
49
+ aab: 'application/x-authorware-bin',
50
+ aac: 'audio/aac',
51
+ aam: 'application/x-authorware-map',
52
+ aas: 'application/x-authorware-seg',
53
+ adts: 'audio/aac',
54
+ ai: 'application/postscript',
55
+ aif: 'audio/x-aiff',
56
+ aifc: 'audio/x-aiff',
57
+ aiff: 'audio/x-aiff',
58
+ arc: 'application/x-freearc',
59
+ arj: 'application/x-arj',
60
+ asf: 'video/x-ms-asf',
61
+ asm: 'text/x-asm',
62
+ asx: 'video/x-ms-asf',
63
+ au: 'audio/basic',
64
+ avi: 'video/x-msvideo',
65
+ avif: 'image/avif',
66
+ bat: 'application/x-msdownload',
67
+ bcpio: 'application/x-bcpio',
68
+ bmp: 'image/bmp',
69
+ book: 'application/vnd.framemaker',
70
+ boz: 'application/x-bzip2',
71
+ bz: 'application/x-bzip',
72
+ bz2: 'application/x-bzip2',
73
+ c: 'text/x-c',
74
+ cat: 'application/vnd.ms-pki.seccat',
75
+ cc: 'text/x-c',
76
+ cco: 'application/x-cocoa',
77
+ cdf: 'application/x-netcdf',
78
+ cer: 'application/pkix-cert',
79
+ chat: 'application/x-chat',
80
+ class: 'application/java-vm',
81
+ com: 'application/x-msdownload',
82
+ conf: 'text/plain',
83
+ cpio: 'application/x-cpio',
84
+ cpp: 'text/x-c',
85
+ cpt: 'application/mac-compactpro',
86
+ crl: 'application/pkix-crl',
87
+ crt: 'application/x-x509-ca-cert',
88
+ csh: 'application/x-csh',
89
+ css: 'text/css',
90
+ csv: 'text/csv',
91
+ cxx: 'text/x-c',
92
+ dcr: 'application/x-director',
93
+ def: 'text/plain',
94
+ der: 'application/x-x509-ca-cert',
95
+ dir: 'application/x-director',
96
+ doc: 'application/msword',
97
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
98
+ dot: 'application/msword',
99
+ dp: 'application/vnd.osgi.dp',
100
+ dvi: 'application/x-dvi',
101
+ dwf: 'model/vnd.dwf',
102
+ dwg: 'image/vnd.dwg',
103
+ dxf: 'image/vnd.dxf',
104
+ dxr: 'application/x-director',
105
+ eml: 'message/rfc822',
106
+ eot: 'application/vnd.ms-fontobject',
107
+ eps: 'application/postscript',
108
+ epub: 'application/epub+zip',
109
+ etx: 'text/x-setext',
110
+ evy: 'application/x-envoy',
111
+ f: 'text/x-fortran',
112
+ f77: 'text/x-fortran',
113
+ f90: 'text/x-fortran',
114
+ fdf: 'application/fdf',
115
+ flac: 'audio/x-flac',
116
+ fli: 'video/x-fli',
117
+ flo: 'application/vnd.micrografx.flo',
118
+ flx: 'text/vnd.fmi.flexstor',
119
+ for: 'text/x-fortran',
120
+ fpx: 'image/vnd.fpx',
121
+ g3: 'image/g3fax',
122
+ gif: 'image/gif',
123
+ gtar: 'application/x-gtar',
124
+ gz: 'application/gzip',
125
+ h: 'text/x-c',
126
+ hdf: 'application/x-hdf',
127
+ heic: 'image/heic',
128
+ heif: 'image/heif',
129
+ hh: 'text/x-c',
130
+ hlp: 'application/winhlp',
131
+ hpgl: 'application/vnd.hp-hpgl',
132
+ hqx: 'application/mac-binhex40',
133
+ htc: 'text/x-component',
134
+ htm: 'text/html',
135
+ html: 'text/html',
136
+ ice: 'x-conference/x-cooltalk',
137
+ ico: 'image/vnd.microsoft.icon',
138
+ ics: 'text/calendar',
139
+ ief: 'image/ief',
140
+ iges: 'model/iges',
141
+ igs: 'model/iges',
142
+ jam: 'application/vnd.jam',
143
+ java: 'text/x-java-source',
144
+ jfif: 'image/pjpeg',
145
+ jpe: 'image/jpeg',
146
+ jpeg: 'image/jpeg',
147
+ jpg: 'image/jpeg',
148
+ js: 'text/javascript',
149
+ json: 'application/json',
150
+ kar: 'audio/midi',
151
+ key: 'application/vnd.apple.keynote',
152
+ latex: 'application/x-latex',
153
+ lha: 'application/x-lzh-compressed',
154
+ list: 'text/plain',
155
+ log: 'text/plain',
156
+ lzh: 'application/x-lzh-compressed',
157
+ m1v: 'video/mpeg',
158
+ m2a: 'audio/mpeg',
159
+ m2v: 'video/mpeg',
160
+ m3u: 'audio/x-mpegurl',
161
+ m3u8: 'application/vnd.apple.mpegurl',
162
+ m4a: 'audio/mp4',
163
+ man: 'text/troff',
164
+ map: 'application/json',
165
+ mcd: 'application/vnd.mcd',
166
+ md: 'text/markdown',
167
+ me: 'text/troff',
168
+ mht: 'message/rfc822',
169
+ mhtml: 'message/rfc822',
170
+ mid: 'audio/midi',
171
+ midi: 'audio/midi',
172
+ mif: 'application/vnd.mif',
173
+ mime: 'message/rfc822',
174
+ mjs: 'text/javascript',
175
+ mka: 'audio/x-matroska',
176
+ mkv: 'video/x-matroska',
177
+ mov: 'video/quicktime',
178
+ movie: 'video/x-sgi-movie',
179
+ mp2: 'audio/mpeg',
180
+ mp3: 'audio/mpeg',
181
+ mp4: 'video/mp4',
182
+ mpc: 'application/vnd.mophun.certificate',
183
+ mpe: 'video/mpeg',
184
+ mpeg: 'video/mpeg',
185
+ mpg: 'video/mpeg',
186
+ mpga: 'audio/mpeg',
187
+ mpp: 'application/dash-patch+xml',
188
+ mpt: 'application/vnd.ms-project',
189
+ mrc: 'application/marc',
190
+ ms: 'text/troff',
191
+ nc: 'application/x-netcdf',
192
+ nsc: 'application/x-conference',
193
+ numbers: 'application/vnd.apple.numbers',
194
+ obj: 'model/obj',
195
+ oda: 'application/oda',
196
+ odg: 'application/vnd.oasis.opendocument.graphics',
197
+ odp: 'application/vnd.oasis.opendocument.presentation',
198
+ ods: 'application/vnd.oasis.opendocument.spreadsheet',
199
+ odt: 'application/vnd.oasis.opendocument.text',
200
+ ogg: 'audio/ogg',
201
+ opus: 'audio/ogg',
202
+ otf: 'font/otf',
203
+ p: 'text/x-pascal',
204
+ p10: 'application/pkcs10',
205
+ p12: 'application/x-pkcs12',
206
+ p7c: 'application/pkcs7-mime',
207
+ p7m: 'application/pkcs7-mime',
208
+ p7r: 'application/x-pkcs7-certreqresp',
209
+ p7s: 'application/pkcs7-signature',
210
+ pages: 'application/vnd.apple.pages',
211
+ pas: 'text/x-pascal',
212
+ pbm: 'image/x-portable-bitmap',
213
+ pcl: 'application/vnd.hp-pcl',
214
+ pct: 'image/x-pict',
215
+ pcx: 'image/vnd.zbrush.pcx',
216
+ pdb: 'application/vnd.palm',
217
+ pdf: 'application/pdf',
218
+ pfx: 'application/x-pkcs12',
219
+ pgm: 'image/x-portable-graymap',
220
+ pic: 'image/x-pict',
221
+ pl: 'application/x-perl',
222
+ pm: 'application/x-perl',
223
+ png: 'image/png',
224
+ pnm: 'image/x-portable-anymap',
225
+ pot: 'application/vnd.ms-powerpoint',
226
+ ppm: 'image/x-portable-pixmap',
227
+ pps: 'application/vnd.ms-powerpoint',
228
+ ppt: 'application/vnd.ms-powerpoint',
229
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
230
+ pre: 'application/vnd.lotus-freelance',
231
+ ps: 'application/postscript',
232
+ psd: 'image/vnd.adobe.photoshop',
233
+ pyo: 'model/vnd.pytha.pyox',
234
+ qt: 'video/quicktime',
235
+ ra: 'audio/x-pn-realaudio',
236
+ ram: 'audio/x-pn-realaudio',
237
+ rar: 'application/vnd.rar',
238
+ ras: 'image/x-cmu-raster',
239
+ rdf: 'application/rdf+xml',
240
+ rgb: 'image/x-rgb',
241
+ rm: 'application/vnd.rn-realmedia',
242
+ rmi: 'audio/midi',
243
+ rmp: 'audio/x-pn-realaudio-plugin',
244
+ rng: 'application/xml',
245
+ roff: 'text/troff',
246
+ rpm: 'application/x-redhat-package-manager',
247
+ rtf: 'application/rtf',
248
+ rtx: 'text/richtext',
249
+ s: 'text/x-asm',
250
+ s3m: 'audio/s3m',
251
+ scm: 'application/vnd.lotus-screencam',
252
+ sdp: 'application/sdp',
253
+ sea: 'application/x-sea',
254
+ sgm: 'text/sgml',
255
+ sgml: 'text/sgml',
256
+ sh: 'application/x-sh',
257
+ shar: 'application/x-shar',
258
+ shtml: 'text/html',
259
+ sid: 'image/x-mrsid-image',
260
+ sit: 'application/x-stuffit',
261
+ skd: 'application/vnd.koan',
262
+ skm: 'application/vnd.koan',
263
+ skp: 'application/vnd.koan',
264
+ skt: 'application/vnd.koan',
265
+ smi: 'application/smil+xml',
266
+ smil: 'application/smil+xml',
267
+ snd: 'audio/basic',
268
+ spc: 'application/x-pkcs7-certificates',
269
+ spl: 'application/x-futuresplash',
270
+ src: 'application/x-wais-source',
271
+ step: 'model/step',
272
+ stl: 'model/stl',
273
+ stp: 'model/step',
274
+ sv4cpio: 'application/x-sv4cpio',
275
+ sv4crc: 'application/x-sv4crc',
276
+ svg: 'image/svg+xml',
277
+ swf: 'application/x-shockwave-flash',
278
+ t: 'text/troff',
279
+ tar: 'application/x-tar',
280
+ tcl: 'application/x-tcl',
281
+ tex: 'application/x-tex',
282
+ texi: 'application/x-texinfo',
283
+ texinfo: 'application/x-texinfo',
284
+ text: 'text/plain',
285
+ tif: 'image/tiff',
286
+ tiff: 'image/tiff',
287
+ tr: 'text/troff',
288
+ ts: 'video/mp2t',
289
+ tsv: 'text/tab-separated-values',
290
+ txt: 'text/plain',
291
+ uri: 'text/uri-list',
292
+ uris: 'text/uri-list',
293
+ ustar: 'application/x-ustar',
294
+ uu: 'text/x-uuencode',
295
+ vcd: 'application/x-cdlink',
296
+ vcf: 'text/x-vcard',
297
+ vcs: 'text/x-vcalendar',
298
+ viv: 'video/vnd.vivo',
299
+ vox: 'application/x-authorware-bin',
300
+ vrml: 'model/vrml',
301
+ vsd: 'application/vnd.visio',
302
+ vst: 'application/vnd.visio',
303
+ vsw: 'application/vnd.visio',
304
+ wasm: 'application/wasm',
305
+ wav: 'audio/wav',
306
+ wbmp: 'image/vnd.wap.wbmp',
307
+ webm: 'video/webm',
308
+ webmanifest: 'application/manifest+json',
309
+ webp: 'image/webp',
310
+ wmf: 'image/wmf',
311
+ wml: 'text/vnd.wap.wml',
312
+ wmlc: 'application/vnd.wap.wmlc',
313
+ wmls: 'text/vnd.wap.wmlscript',
314
+ wmlsc: 'application/vnd.wap.wmlscriptc',
315
+ woff: 'font/woff',
316
+ woff2: 'font/woff2',
317
+ wpd: 'application/vnd.wordperfect',
318
+ wri: 'application/x-mswrite',
319
+ wrl: 'model/vrml',
320
+ wsc: 'message/vnd.wfa.wsc',
321
+ wsdl: 'application/wsdl+xml',
322
+ xbm: 'image/x-xbitmap',
323
+ xif: 'image/vnd.xiff',
324
+ xla: 'application/vnd.ms-excel',
325
+ xlc: 'application/vnd.ms-excel',
326
+ xlm: 'application/vnd.ms-excel',
327
+ xls: 'application/vnd.ms-excel',
328
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
329
+ xlt: 'application/vnd.ms-excel',
330
+ xlw: 'application/vnd.ms-excel',
331
+ xm: 'audio/xm',
332
+ xml: 'application/xml',
333
+ xpm: 'image/x-xpixmap',
334
+ xsl: 'application/xml',
335
+ xul: 'application/vnd.mozilla.xul+xml',
336
+ xwd: 'image/x-xwindowdump',
337
+ xyz: 'chemical/x-xyz',
338
+ yaml: 'text/yaml',
339
+ yml: 'text/yaml',
340
+ zip: 'application/zip',
341
+ '3gpp2': 'audio/3gpp2',
342
+ ass: 'audio/aac',
343
+ h5: 'application/x-hdf5',
344
+ ksh: 'text/plain',
345
+ loas: 'audio/aac',
346
+ mpa: 'video/mpeg',
347
+ nws: 'message/rfc822',
348
+ ppa: 'application/vnd.ms-powerpoint',
349
+ pwz: 'application/vnd.ms-powerpoint',
350
+ py: 'text/x-python',
351
+ pyc: 'application/x-python-code',
352
+ tgz: 'application/gzip',
353
+ wiz: 'application/msword',
354
+ xlb: 'application/vnd.ms-excel',
355
+ xpdl: 'application/xml',
356
+ };
@@ -1,6 +1,7 @@
1
1
  import { PusherSubscriptionError } from '../errors/PusherErrors';
2
2
  import { CLIENT_PUSHER_KEY } from './constants';
3
3
  import logger from './logger';
4
+ import { describeThrown } from './userCallback';
4
5
 
5
6
  const PUSHER_KEY = CLIENT_PUSHER_KEY || 'ff9f18c208855d77a152';
6
7
  const PUSHER_CLUSTER = 'mt1';
@@ -124,7 +125,9 @@ export class PusherUtils {
124
125
  try {
125
126
  await PusherUtils.pusherClient.subscribe(channelName).bind(event, fn);
126
127
  } catch (error) {
127
- logger.error(`Error subscribing to ${channelName} with event ${event}: ${error}`);
128
+ logger.error(
129
+ `Error subscribing to ${channelName} with event ${event}: ${describeThrown(error)}`
130
+ );
128
131
  }
129
132
  }
130
133
 
@@ -239,7 +242,7 @@ export class PusherUtils {
239
242
 
240
243
  // Add subscription error handling
241
244
  channel.bind('pusher:subscription_error', (data: Record<string, unknown>) => {
242
- const error = data.error ? String(data.error) : 'Unknown subscription error';
245
+ const error = data.error ? describeThrown(data.error) : 'Unknown subscription error';
243
246
  throw new PusherSubscriptionError(`Trigger subscription error`, {
244
247
  cause: error,
245
248
  });
@@ -4,35 +4,40 @@ export const MAX_URL_UPLOAD_SIZE_BYTES = 100 * 1024 * 1024;
4
4
  const sizeLimitError = (actualSize: number, maxBytes: number): Error =>
5
5
  new Error(`File size (${actualSize} bytes) exceeds maximum allowed size (${maxBytes} bytes)`);
6
6
 
7
+ export const assertValidBodyLimit = (maxBytes: number): void => {
8
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) {
9
+ throw new RangeError('maxBytes must be a non-negative safe integer');
10
+ }
11
+ };
12
+
7
13
  /**
8
- * Read a fetch response without allowing an untrusted server to exhaust memory.
14
+ * Read a Fetch request or response within a byte limit.
9
15
  *
10
16
  * `Content-Length` is checked as an early rejection, but the streamed byte
11
17
  * count is authoritative because the header can be absent or dishonest.
12
18
  */
13
- export const readResponseBodyWithLimit = async (
14
- response: Response,
15
- maxBytes: number = MAX_URL_UPLOAD_SIZE_BYTES
19
+ export const readBodyWithLimit = async (
20
+ { body, headers }: Pick<Response, 'body' | 'headers'>,
21
+ maxBytes: number,
22
+ makeSizeLimitError: (actualSize: number, maxBytes: number) => Error
16
23
  ): Promise<Uint8Array> => {
17
- if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) {
18
- throw new RangeError('maxBytes must be a non-negative safe integer');
19
- }
24
+ assertValidBodyLimit(maxBytes);
20
25
 
21
- const contentLength = response.headers.get('content-length')?.trim();
26
+ const contentLength = headers.get('content-length')?.trim();
22
27
  if (contentLength && /^\d+$/.test(contentLength)) {
23
28
  const declaredSize = Number(contentLength);
24
29
  if (!Number.isSafeInteger(declaredSize) || declaredSize > maxBytes) {
25
- const error = sizeLimitError(declaredSize, maxBytes);
26
- await response.body?.cancel(error).catch(() => undefined);
30
+ const error = makeSizeLimitError(declaredSize, maxBytes);
31
+ void body?.cancel(error).catch(() => undefined);
27
32
  throw error;
28
33
  }
29
34
  }
30
35
 
31
- if (!response.body) {
36
+ if (!body) {
32
37
  return new Uint8Array();
33
38
  }
34
39
 
35
- const reader = response.body.getReader();
40
+ const reader = body.getReader();
36
41
  const chunks: Uint8Array[] = [];
37
42
  let totalBytes = 0;
38
43
 
@@ -44,8 +49,10 @@ export const readResponseBodyWithLimit = async (
44
49
 
45
50
  totalBytes += value.byteLength;
46
51
  if (totalBytes > maxBytes) {
47
- await reader.cancel(sizeLimitError(totalBytes, maxBytes));
48
- throw sizeLimitError(totalBytes, maxBytes);
52
+ const error = makeSizeLimitError(totalBytes, maxBytes);
53
+ // A cloned request can keep the cancellation pending on its other branch.
54
+ void reader.cancel(error).catch(() => undefined);
55
+ throw error;
49
56
  }
50
57
  chunks.push(value);
51
58
  }
@@ -53,11 +60,17 @@ export const readResponseBodyWithLimit = async (
53
60
  reader.releaseLock();
54
61
  }
55
62
 
56
- const body = new Uint8Array(totalBytes);
63
+ const bytes = new Uint8Array(totalBytes);
57
64
  let offset = 0;
58
65
  for (const chunk of chunks) {
59
- body.set(chunk, offset);
66
+ bytes.set(chunk, offset);
60
67
  offset += chunk.byteLength;
61
68
  }
62
- return body;
69
+ return bytes;
63
70
  };
71
+
72
+ /** Read a Fetch response within the file size limit. */
73
+ export const readResponseBodyWithLimit = (
74
+ response: Response,
75
+ maxBytes: number = MAX_URL_UPLOAD_SIZE_BYTES
76
+ ): Promise<Uint8Array> => readBodyWithLimit(response, maxBytes, sizeLimitError);
@@ -1,4 +1,3 @@
1
- import { logger } from '../..';
2
1
  import {
3
2
  AuthConfigRetrieveResponse,
4
3
  AuthConfigRetrieveResponseSchema,
@@ -11,7 +11,9 @@ import logger from './logger';
11
11
  export function describeThrown(value: unknown): string {
12
12
  try {
13
13
  if (value instanceof Error) return value.message;
14
- if (typeof value === 'object' && value !== null) return JSON.stringify(value) ?? String(value);
14
+ if (typeof value === 'object' && value !== null) {
15
+ return JSON.stringify(value) ?? Object.prototype.toString.call(value);
16
+ }
15
17
  return String(value);
16
18
  } catch {
17
19
  try {