zapier-platform-core 17.9.0 → 18.0.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 +5 -5
- package/src/http-middlewares/after/throw-for-throttling.js +33 -0
- package/src/http-middlewares/before/prepare-request.js +5 -0
- package/src/tools/create-app-request-client.js +2 -0
- package/src/tools/create-rpc-client.js +4 -0
- package/src/tools/environment.js +5 -2
- package/types/schemas.generated.d.ts +71 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zapier-platform-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.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/",
|
|
@@ -54,16 +54,16 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@zapier/secret-scrubber": "^1.1.2",
|
|
56
56
|
"content-disposition": "0.5.4",
|
|
57
|
-
"dotenv": "
|
|
57
|
+
"dotenv": "17.2.1",
|
|
58
58
|
"fernet": "^0.3.3",
|
|
59
59
|
"form-data": "4.0.4",
|
|
60
60
|
"lodash": "4.17.21",
|
|
61
|
-
"mime-types": "
|
|
61
|
+
"mime-types": "3.0.1",
|
|
62
62
|
"node-abort-controller": "3.1.1",
|
|
63
63
|
"node-fetch": "2.7.0",
|
|
64
64
|
"oauth-sign": "0.9.0",
|
|
65
|
-
"semver": "7.7.
|
|
66
|
-
"zapier-platform-schema": "
|
|
65
|
+
"semver": "7.7.2",
|
|
66
|
+
"zapier-platform-schema": "18.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/node-fetch": "^2.6.11",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { ThrottledError } = require('../../errors');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Raise a ThrottledError for 429 responses _before_ dev's afterResponse middleware,
|
|
7
|
+
* unless throwForThrottlingEarly is set to true on the request.
|
|
8
|
+
* Behaves similarly to throwForStaleAuth but for throttling.
|
|
9
|
+
*/
|
|
10
|
+
const throwForThrottling = (resp) => {
|
|
11
|
+
// throwForThrottlingEarly has to be explicitly set to false to disable this
|
|
12
|
+
// middleware. By default, when it's undefined or null, we want this
|
|
13
|
+
// middleware to run.
|
|
14
|
+
if (resp.request?.throwForThrottlingEarly === false) {
|
|
15
|
+
return resp;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (resp.status === 429) {
|
|
19
|
+
const retryAfter = resp.headers.get('retry-after');
|
|
20
|
+
let delay = retryAfter ? parseInt(retryAfter, 10) : null;
|
|
21
|
+
if (Number.isNaN(delay)) {
|
|
22
|
+
delay = null;
|
|
23
|
+
}
|
|
24
|
+
throw new ThrottledError(
|
|
25
|
+
'The server returned 429 (Too Many Requests)',
|
|
26
|
+
delay,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return resp;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = throwForThrottling;
|
|
@@ -145,6 +145,11 @@ const prepareRequest = function (req) {
|
|
|
145
145
|
['_zapier', 'app', 'flags', 'skipThrowForStatus'],
|
|
146
146
|
false,
|
|
147
147
|
),
|
|
148
|
+
throwForThrottlingEarly: _.get(
|
|
149
|
+
input,
|
|
150
|
+
['_zapier', 'app', 'flags', 'throwForThrottlingEarly'],
|
|
151
|
+
true,
|
|
152
|
+
),
|
|
148
153
|
});
|
|
149
154
|
|
|
150
155
|
req = sugarBody(req);
|
|
@@ -20,6 +20,7 @@ const sanitizeHeaders = require('../http-middlewares/before/sanatize-headers');
|
|
|
20
20
|
const { logResponse } = require('../http-middlewares/after/log-response');
|
|
21
21
|
const prepareResponse = require('../http-middlewares/after/prepare-response');
|
|
22
22
|
const throwForStaleAuth = require('../http-middlewares/after/throw-for-stale-auth');
|
|
23
|
+
const throwForThrottling = require('../http-middlewares/after/throw-for-throttling');
|
|
23
24
|
const throwForStatusMiddleware = require('../http-middlewares/after/throw-for-status');
|
|
24
25
|
const throwForDisallowedHostnameAfterRedirect = require('../http-middlewares/after/throw-for-disallowed-hostname-after-redirect');
|
|
25
26
|
|
|
@@ -69,6 +70,7 @@ const createAppRequestClient = (input, options) => {
|
|
|
69
70
|
throwForDisallowedHostnameAfterRedirect,
|
|
70
71
|
logResponse,
|
|
71
72
|
...(includeAutoRefresh ? [throwForStaleAuth] : []),
|
|
73
|
+
throwForThrottling,
|
|
72
74
|
...ensureArray(app.afterResponse),
|
|
73
75
|
throwForStatusMiddleware,
|
|
74
76
|
];
|
|
@@ -111,6 +111,10 @@ const createRpcClient = (event) => {
|
|
|
111
111
|
if (res.status >= 500) {
|
|
112
112
|
throw new Error('Unable to reach the RPC server');
|
|
113
113
|
}
|
|
114
|
+
if (res.status === 413) {
|
|
115
|
+
throw new Error('The request is too large to be processed');
|
|
116
|
+
}
|
|
117
|
+
|
|
114
118
|
if (res.content) {
|
|
115
119
|
// check if the ids match
|
|
116
120
|
if (res.content.id !== id) {
|
package/src/tools/environment.js
CHANGED
|
@@ -46,10 +46,13 @@ const injectEnvironmentFile = (filename) => {
|
|
|
46
46
|
filename = localFilepath(filename);
|
|
47
47
|
}
|
|
48
48
|
// reads ".env" if filename is falsy, needs full path otherwise
|
|
49
|
-
let result = dotenv.config({ path: filename });
|
|
49
|
+
let result = dotenv.config({ path: filename, quiet: true });
|
|
50
50
|
if (result.error) {
|
|
51
51
|
// backwards compatibility
|
|
52
|
-
result = dotenv.config({
|
|
52
|
+
result = dotenv.config({
|
|
53
|
+
path: localFilepath('.environment'),
|
|
54
|
+
quiet: true,
|
|
55
|
+
});
|
|
53
56
|
if (result.parsed && !IS_TESTING) {
|
|
54
57
|
console.log(
|
|
55
58
|
[
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* files, and/or the schema-to-ts tool and run its CLI to regenerate
|
|
5
5
|
* these typings.
|
|
6
6
|
*
|
|
7
|
-
* zapier-platform-schema version: 17.
|
|
7
|
+
* zapier-platform-schema version: 17.9.1
|
|
8
8
|
* schema-to-ts compiler version: 0.1.0
|
|
9
9
|
*/
|
|
10
10
|
import type {
|
|
@@ -292,6 +292,27 @@ export interface AppFlags {
|
|
|
292
292
|
* ignore this flag if they set `skipThrowForStatus` directly
|
|
293
293
|
*/
|
|
294
294
|
skipThrowForStatus?: boolean;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Starting in `core` version `18.0.0`, 429 (throttling) responses
|
|
298
|
+
* throw a `ThrottledError` before `afterResponse` middleware runs
|
|
299
|
+
* by default. Set this flag to `true` to preserve the old behavior
|
|
300
|
+
* where `afterResponse` middleware can see and handle 429
|
|
301
|
+
* responses. This flag can be overridden per-request by setting
|
|
302
|
+
* `throwForThrottlingEarly` directly on the request options.
|
|
303
|
+
*/
|
|
304
|
+
throwForThrottlingEarly?: boolean;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
308
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
309
|
+
* before passing it to your `perform*` function. If you want to
|
|
310
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
311
|
+
* false. This is a global flag that affects all the triggers and
|
|
312
|
+
* actions in your integration. The `cleanInputData` flag in
|
|
313
|
+
* `operation` takes precedence over this one.
|
|
314
|
+
*/
|
|
315
|
+
cleanInputData?: boolean;
|
|
295
316
|
}
|
|
296
317
|
|
|
297
318
|
/**
|
|
@@ -941,10 +962,14 @@ export interface BasicPollingOperation<
|
|
|
941
962
|
throttle?: ThrottleObject;
|
|
942
963
|
|
|
943
964
|
/**
|
|
944
|
-
*
|
|
945
|
-
* empty Arrays or objects
|
|
965
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
966
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
967
|
+
* before passing it to your `perform*` function. If you want to
|
|
968
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
969
|
+
* false. There is also a global flag with the same name in
|
|
970
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
946
971
|
*/
|
|
947
|
-
|
|
972
|
+
cleanInputData?: boolean;
|
|
948
973
|
}
|
|
949
974
|
|
|
950
975
|
/**
|
|
@@ -1036,10 +1061,14 @@ export interface BasicHookOperation<
|
|
|
1036
1061
|
sample?: Record<string, unknown>;
|
|
1037
1062
|
|
|
1038
1063
|
/**
|
|
1039
|
-
*
|
|
1040
|
-
* empty Arrays or objects
|
|
1064
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
1065
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
1066
|
+
* before passing it to your `perform*` function. If you want to
|
|
1067
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
1068
|
+
* false. There is also a global flag with the same name in
|
|
1069
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
1041
1070
|
*/
|
|
1042
|
-
|
|
1071
|
+
cleanInputData?: boolean;
|
|
1043
1072
|
}
|
|
1044
1073
|
|
|
1045
1074
|
/**
|
|
@@ -1102,10 +1131,14 @@ export interface BasicHookToPollOperation<
|
|
|
1102
1131
|
sample?: Record<string, unknown>;
|
|
1103
1132
|
|
|
1104
1133
|
/**
|
|
1105
|
-
*
|
|
1106
|
-
* empty Arrays or objects
|
|
1134
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
1135
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
1136
|
+
* before passing it to your `perform*` function. If you want to
|
|
1137
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
1138
|
+
* false. There is also a global flag with the same name in
|
|
1139
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
1107
1140
|
*/
|
|
1108
|
-
|
|
1141
|
+
cleanInputData?: boolean;
|
|
1109
1142
|
|
|
1110
1143
|
/**
|
|
1111
1144
|
* The maximum amount of time to wait between polling requests in
|
|
@@ -1180,10 +1213,14 @@ export interface BasicActionOperation {
|
|
|
1180
1213
|
throttle?: ThrottleObject;
|
|
1181
1214
|
|
|
1182
1215
|
/**
|
|
1183
|
-
*
|
|
1184
|
-
* empty Arrays or objects
|
|
1216
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
1217
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
1218
|
+
* before passing it to your `perform*` function. If you want to
|
|
1219
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
1220
|
+
* false. There is also a global flag with the same name in
|
|
1221
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
1185
1222
|
*/
|
|
1186
|
-
|
|
1223
|
+
cleanInputData?: boolean;
|
|
1187
1224
|
}
|
|
1188
1225
|
|
|
1189
1226
|
/** Represents the fundamental mechanics of a search. */
|
|
@@ -1256,10 +1293,14 @@ export interface BasicSearchOperation<
|
|
|
1256
1293
|
throttle?: ThrottleObject;
|
|
1257
1294
|
|
|
1258
1295
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
* empty Arrays or objects
|
|
1296
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
1297
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
1298
|
+
* before passing it to your `perform*` function. If you want to
|
|
1299
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
1300
|
+
* false. There is also a global flag with the same name in
|
|
1301
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
1261
1302
|
*/
|
|
1262
|
-
|
|
1303
|
+
cleanInputData?: boolean;
|
|
1263
1304
|
}
|
|
1264
1305
|
|
|
1265
1306
|
/** Represents the fundamental mechanics of a create. */
|
|
@@ -1331,10 +1372,14 @@ export interface BasicCreateOperation<
|
|
|
1331
1372
|
throttle?: ThrottleObject;
|
|
1332
1373
|
|
|
1333
1374
|
/**
|
|
1334
|
-
*
|
|
1335
|
-
* empty Arrays or objects
|
|
1375
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
1376
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
1377
|
+
* before passing it to your `perform*` function. If you want to
|
|
1378
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
1379
|
+
* false. There is also a global flag with the same name in
|
|
1380
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
1336
1381
|
*/
|
|
1337
|
-
|
|
1382
|
+
cleanInputData?: boolean;
|
|
1338
1383
|
|
|
1339
1384
|
/**
|
|
1340
1385
|
* Currently an **internal-only** feature. Zapier uses this
|
|
@@ -1421,10 +1466,14 @@ export interface BasicOperation {
|
|
|
1421
1466
|
throttle?: ThrottleObject;
|
|
1422
1467
|
|
|
1423
1468
|
/**
|
|
1424
|
-
*
|
|
1425
|
-
* empty Arrays or objects
|
|
1469
|
+
* If true, Zapier removes empty strings, `null`, `undefined`, and
|
|
1470
|
+
* empty Arrays or objects from `bundle.inputData` recursively
|
|
1471
|
+
* before passing it to your `perform*` function. If you want to
|
|
1472
|
+
* handle empty values yourself in your code, explicitly set this to
|
|
1473
|
+
* false. There is also a global flag with the same name in
|
|
1474
|
+
* `App.flags`. This one takes precedence over the global one.
|
|
1426
1475
|
*/
|
|
1427
|
-
|
|
1476
|
+
cleanInputData?: boolean;
|
|
1428
1477
|
}
|
|
1429
1478
|
|
|
1430
1479
|
/**
|