zapier-platform-core 15.17.0 → 15.18.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/CHANGELOG.md +1 -3
- package/README.md +9 -3
- package/package.json +2 -2
- package/src/tools/create-cache.js +9 -4
- package/src/tools/create-lambda-handler.js +2 -1
- package/src/tools/memory-checker.js +19 -10
- package/types/index.test-d.ts +35 -1
- package/types/zapier.custom.d.ts +20 -15
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Zapier Platform Core
|
|
2
2
|
|
|
3
|
-
This is the
|
|
3
|
+
This is the SDK used in Zapier integrations.
|
|
4
4
|
|
|
5
5
|
## Development
|
|
6
6
|
|
|
7
|
+
See [CONTRIBUTING.md](https://github.com/zapier/zapier-platform/blob/main/CONTRIBUTING.md) and [ARCHITECTURE.md](https://github.com/zapier/zapier-platform/blob/main/packages/core/ARCHITECTURE.md) of this package in particular.
|
|
8
|
+
|
|
9
|
+
Useful commands:
|
|
10
|
+
|
|
7
11
|
* `npm install` for getting started
|
|
8
12
|
* `npm test` for running unit tests
|
|
9
13
|
* `npm run local-integration-test` for running integration tests locally
|
|
@@ -16,6 +20,8 @@ Make sure your AWS access key have permission to update and run Lambda functions
|
|
|
16
20
|
* `npm run deploy-integration-test` builds and deploys a zip to a function named `integration-test-cli` on Lambda
|
|
17
21
|
* `npm run lambda-integration-test` runs the integration test using the live Lambda function `integration-test-cli`
|
|
18
22
|
|
|
19
|
-
## Publishing
|
|
23
|
+
## Publishing
|
|
24
|
+
|
|
25
|
+
Only do this after merging your PR to `main`.
|
|
20
26
|
|
|
21
27
|
* `npm version [patch|minor|major]` will pull, test, update schema version in dependencies for this package, update docs, increment version in package.json, and push tags, which then will tell Travis to publish to npm
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zapier-platform-core",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.18.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/",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"node-fetch": "2.6.7",
|
|
54
54
|
"oauth-sign": "0.9.0",
|
|
55
55
|
"semver": "7.5.2",
|
|
56
|
-
"zapier-platform-schema": "15.
|
|
56
|
+
"zapier-platform-schema": "15.18.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node-fetch": "^2.6.11",
|
|
@@ -12,7 +12,8 @@ const createCache = (input) => {
|
|
|
12
12
|
key,
|
|
13
13
|
value = null,
|
|
14
14
|
ttl = null,
|
|
15
|
-
scope = null
|
|
15
|
+
scope = null,
|
|
16
|
+
nx = null
|
|
16
17
|
) => {
|
|
17
18
|
if (!rpc) {
|
|
18
19
|
throw new Error('rpc is not available');
|
|
@@ -36,6 +37,10 @@ const createCache = (input) => {
|
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
if (nx !== null && !_.isBoolean(nx)) {
|
|
41
|
+
throw new TypeError('nx must be a boolean');
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
ensureJSONEncodable(value);
|
|
40
45
|
};
|
|
41
46
|
|
|
@@ -46,10 +51,10 @@ const createCache = (input) => {
|
|
|
46
51
|
const result = await rpc('zcache_get', key, scope);
|
|
47
52
|
return result ? JSON.parse(result) : null;
|
|
48
53
|
},
|
|
49
|
-
set: async (key, value, ttl = null, scope = null) => {
|
|
50
|
-
runValidationChecks(rpc, key, value, ttl, scope);
|
|
54
|
+
set: async (key, value, ttl = null, scope = null, nx = null) => {
|
|
55
|
+
runValidationChecks(rpc, key, value, ttl, scope, nx);
|
|
51
56
|
|
|
52
|
-
return await rpc('zcache_set', key, JSON.stringify(value), ttl, scope);
|
|
57
|
+
return await rpc('zcache_set', key, JSON.stringify(value), ttl, scope, nx);
|
|
53
58
|
},
|
|
54
59
|
delete: async (key, scope = null) => {
|
|
55
60
|
runValidationChecks(rpc, key, scope);
|
|
@@ -196,7 +196,8 @@ const createLambdaHandler = (appRawOrPath) => {
|
|
|
196
196
|
ZapierPromise.patchGlobal();
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
// If we're running out of memory, exit the process.
|
|
199
|
+
// If we're running out of memory or file descriptors, force exit the process.
|
|
200
|
+
// The backend will try again via @retry(ProcessExitedException).
|
|
200
201
|
checkMemory(event);
|
|
201
202
|
|
|
202
203
|
environmentTools.cleanEnvironment();
|
|
@@ -8,22 +8,31 @@ let zrun = 0;
|
|
|
8
8
|
const checkMemory = (event) => {
|
|
9
9
|
event = event || {};
|
|
10
10
|
|
|
11
|
+
let memUsage;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
memUsage = process.memoryUsage();
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (err.code === 'EMFILE') {
|
|
17
|
+
console.error(
|
|
18
|
+
'Force killing process by Zapier for too many open file descriptors'
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/* eslint no-process-exit: 0 */
|
|
22
|
+
process.exit(1);
|
|
23
|
+
} else {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
11
28
|
zrun += 1;
|
|
12
29
|
if (!constants.IS_TESTING && !event.calledFromCli) {
|
|
13
|
-
console.log(
|
|
14
|
-
'ZID:',
|
|
15
|
-
zid,
|
|
16
|
-
'pid',
|
|
17
|
-
'ZRUN:',
|
|
18
|
-
zrun,
|
|
19
|
-
'RSSMEM:',
|
|
20
|
-
process.memoryUsage()
|
|
21
|
-
);
|
|
30
|
+
console.log('ZID:', zid, 'pid', 'ZRUN:', zrun, 'RSSMEM:', memUsage);
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
if (
|
|
25
34
|
zrun > constants.KILL_MIN_LIMIT &&
|
|
26
|
-
|
|
35
|
+
memUsage.rss > constants.KILL_MAX_LIMIT
|
|
27
36
|
) {
|
|
28
37
|
// should throw "Process exited before completing request"
|
|
29
38
|
// and a @retry in our stack will attempt again - and this
|
package/types/index.test-d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
Trigger,
|
|
19
19
|
} from './zapier.generated';
|
|
20
20
|
|
|
21
|
-
import { expectType } from 'tsd';
|
|
21
|
+
import { expectType, expectDeprecated } from 'tsd';
|
|
22
22
|
|
|
23
23
|
const basicDisplay: BasicDisplay = {
|
|
24
24
|
label: 'some-label',
|
|
@@ -166,3 +166,37 @@ const app: App = {
|
|
|
166
166
|
searches: { [search.key]: search },
|
|
167
167
|
};
|
|
168
168
|
expectType<App>(app);
|
|
169
|
+
|
|
170
|
+
// Return types from z.request
|
|
171
|
+
async (z: ZObject) => {
|
|
172
|
+
const resp = await z.request<{ id: number; name: string }>(
|
|
173
|
+
'https://example.com'
|
|
174
|
+
);
|
|
175
|
+
expectType<{ id: number; name: string }>(resp.data);
|
|
176
|
+
expectDeprecated(resp.json);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
async (z: ZObject) => {
|
|
180
|
+
const resp = await z.request<{ id: number; name: string }>({
|
|
181
|
+
url: 'https://example.com',
|
|
182
|
+
});
|
|
183
|
+
expectType<{ id: number; name: string }>(resp.data);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Return types from z.request (raw)
|
|
187
|
+
async (z: ZObject) => {
|
|
188
|
+
const resp = await z.request<{ id: number; name: string }>(
|
|
189
|
+
'https://example.com',
|
|
190
|
+
{ raw: true }
|
|
191
|
+
);
|
|
192
|
+
const result = await resp.json();
|
|
193
|
+
expectType<{ id: number; name: string }>(result);
|
|
194
|
+
};
|
|
195
|
+
async (z: ZObject) => {
|
|
196
|
+
const resp = await z.request<{ id: number; name: string }>({
|
|
197
|
+
raw: true,
|
|
198
|
+
url: 'https://example.com',
|
|
199
|
+
});
|
|
200
|
+
const result = await resp.json();
|
|
201
|
+
expectType<{ id: number; name: string }>(result);
|
|
202
|
+
};
|
package/types/zapier.custom.d.ts
CHANGED
|
@@ -117,16 +117,17 @@ interface BaseHttpResponse {
|
|
|
117
117
|
request: HttpRequestOptions;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export interface HttpResponse extends BaseHttpResponse {
|
|
120
|
+
export interface HttpResponse<T = any> extends BaseHttpResponse {
|
|
121
121
|
content: string;
|
|
122
|
-
data
|
|
123
|
-
|
|
122
|
+
data: T;
|
|
123
|
+
/** @deprecated Since v10.0.0. Use `data` instead. */
|
|
124
|
+
json?: T;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
export interface RawHttpResponse extends BaseHttpResponse {
|
|
127
|
+
export interface RawHttpResponse<T = any> extends BaseHttpResponse {
|
|
127
128
|
body: NodeJS.ReadableStream;
|
|
128
129
|
buffer(): Promise<Buffer>;
|
|
129
|
-
json(): Promise<
|
|
130
|
+
json(): Promise<T>;
|
|
130
131
|
text(): Promise<string>;
|
|
131
132
|
}
|
|
132
133
|
|
|
@@ -138,16 +139,20 @@ type DehydrateFunc = <T>(
|
|
|
138
139
|
export interface ZObject {
|
|
139
140
|
request: {
|
|
140
141
|
// most specific overloads go first
|
|
141
|
-
(
|
|
142
|
+
<T = any>(
|
|
142
143
|
url: string,
|
|
143
144
|
options: HttpRequestOptions & { raw: true }
|
|
144
|
-
): Promise<RawHttpResponse
|
|
145
|
-
(
|
|
145
|
+
): Promise<RawHttpResponse<T>>;
|
|
146
|
+
<T = any>(
|
|
146
147
|
options: HttpRequestOptions & { raw: true; url: string }
|
|
147
|
-
): Promise<RawHttpResponse
|
|
148
|
-
|
|
149
|
-
(url: string, options?: HttpRequestOptions): Promise<
|
|
150
|
-
|
|
148
|
+
): Promise<RawHttpResponse<T>>;
|
|
149
|
+
|
|
150
|
+
<T = any>(url: string, options?: HttpRequestOptions): Promise<
|
|
151
|
+
HttpResponse<T>
|
|
152
|
+
>;
|
|
153
|
+
<T = any>(options: HttpRequestOptions & { url: string }): Promise<
|
|
154
|
+
HttpResponse<T>
|
|
155
|
+
>;
|
|
151
156
|
};
|
|
152
157
|
|
|
153
158
|
console: Console;
|
|
@@ -226,14 +231,14 @@ export type PerformFunction<BI = Record<string, any>, R = any> = (
|
|
|
226
231
|
|
|
227
232
|
export type BeforeRequestMiddleware = (
|
|
228
233
|
request: HttpRequestOptions,
|
|
229
|
-
z
|
|
230
|
-
bundle
|
|
234
|
+
z: ZObject,
|
|
235
|
+
bundle: Bundle
|
|
231
236
|
) => HttpRequestOptions | Promise<HttpRequestOptions>;
|
|
232
237
|
|
|
233
238
|
export type AfterResponseMiddleware = (
|
|
234
239
|
response: HttpResponse,
|
|
235
240
|
z: ZObject,
|
|
236
|
-
bundle
|
|
241
|
+
bundle: Bundle
|
|
237
242
|
) => HttpResponse | Promise<HttpResponse>;
|
|
238
243
|
|
|
239
244
|
export interface BufferedItem<InputData = { [x: string]: any }> {
|