zapier-platform-core 15.6.2 → 15.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zapier-platform-core",
3
- "version": "15.6.2",
3
+ "version": "15.7.0",
4
4
  "description": "The core SDK for CLI apps in the Zapier Developer Platform.",
5
5
  "repository": "zapier/zapier-platform",
6
6
  "homepage": "https://platform.zapier.com/",
@@ -52,7 +52,7 @@
52
52
  "node-fetch": "2.6.7",
53
53
  "oauth-sign": "0.9.0",
54
54
  "semver": "7.5.2",
55
- "zapier-platform-schema": "15.6.2"
55
+ "zapier-platform-schema": "15.7.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/node-fetch": "^2.6.11",
package/src/constants.js CHANGED
@@ -11,6 +11,9 @@ const KILL_MAX_LIMIT = 450 * 1000 * 1000;
11
11
 
12
12
  const RESPONSE_SIZE_LIMIT = 6291456;
13
13
 
14
+ const UPLOAD_MAX_SIZE = 1000 * 1000 * 1000 * 1; // 1GB, in zapier backend too
15
+ const NON_STREAM_UPLOAD_MAX_SIZE = 1000 * 1000 * 150;
16
+
14
17
  const HYDRATE_DIRECTIVE_HOIST = '$HOIST$';
15
18
 
16
19
  const RENDER_ONLY_METHODS = [
@@ -66,4 +69,6 @@ module.exports = {
66
69
  RESPONSE_SIZE_LIMIT,
67
70
  SAFE_LOG_KEYS,
68
71
  STATUSES,
72
+ UPLOAD_MAX_SIZE,
73
+ NON_STREAM_UPLOAD_MAX_SIZE,
69
74
  };
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
- const { pipeline } = require('stream');
6
+ const { pipeline, Readable } = require('stream');
7
7
  const { promisify } = require('util');
8
8
  const { randomBytes } = require('crypto');
9
9
 
@@ -13,8 +13,7 @@ const FormData = require('form-data');
13
13
  const mime = require('mime-types');
14
14
 
15
15
  const request = require('./request-client-internal');
16
-
17
- const UPLOAD_MAX_SIZE = 1000 * 1000 * 150; // 150mb, in zapier backend too
16
+ const { UPLOAD_MAX_SIZE, NON_STREAM_UPLOAD_MAX_SIZE } = require('../constants');
18
17
 
19
18
  const LENGTH_ERR_MESSAGE =
20
19
  'We could not calculate the length of your file - please ' +
@@ -183,9 +182,6 @@ const uploader = async (
183
182
  filename,
184
183
  contentType
185
184
  ) => {
186
- if (knownLength && knownLength > UPLOAD_MAX_SIZE) {
187
- throw new Error(`${knownLength} is too big, ${UPLOAD_MAX_SIZE} is the max`);
188
- }
189
185
  filename = path.basename(filename).replace('"', '');
190
186
 
191
187
  const fields = {
@@ -237,6 +233,19 @@ const uploader = async (
237
233
  throw new Error(`Got ${response.status} - ${response.content}`);
238
234
  };
239
235
 
236
+ const ensureUploadMaxSizeNotExceeded = (streamOrData, length) => {
237
+ let uploadMaxSize = NON_STREAM_UPLOAD_MAX_SIZE;
238
+ let uploadMethod = 'non-streaming';
239
+ if (streamOrData instanceof Readable) {
240
+ uploadMaxSize = UPLOAD_MAX_SIZE;
241
+ uploadMethod = 'streaming';
242
+ }
243
+
244
+ if (length && length > uploadMaxSize) {
245
+ throw new Error(`${length} bytes is too big, ${uploadMaxSize} is the max for ${uploadMethod} data.`);
246
+ }
247
+ };
248
+
240
249
  // Designed to be some user provided function/api.
241
250
  const createFileStasher = (input) => {
242
251
  const rpc = _.get(input, '_zapier.rpc');
@@ -295,10 +304,13 @@ const createFileStasher = (input) => {
295
304
  filename: _filename,
296
305
  } = await resolveToBufferStringStream(responseOrData);
297
306
 
307
+ const finalLength = knownLength || length;
308
+ ensureUploadMaxSizeNotExceeded(streamOrData, finalLength);
309
+
298
310
  return uploader(
299
311
  signedPostData,
300
312
  streamOrData,
301
- knownLength || length,
313
+ finalLength,
302
314
  filename || _filename,
303
315
  contentType || _contentType
304
316
  );