zapier-platform-core 15.13.0 → 15.14.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.13.0",
3
+ "version": "15.14.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.13.0"
56
+ "zapier-platform-schema": "15.14.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node-fetch": "^2.6.11",
@@ -7,7 +7,13 @@ const ensureJSONEncodable = require('./ensure-json-encodable');
7
7
 
8
8
  const createCache = (input) => {
9
9
  const rpc = _.get(input, '_zapier.rpc');
10
- const runValidationChecks = (rpc, key, value = null, ttl = null) => {
10
+ const runValidationChecks = (
11
+ rpc,
12
+ key,
13
+ value = null,
14
+ ttl = null,
15
+ scope = null
16
+ ) => {
11
17
  if (!rpc) {
12
18
  throw new Error('rpc is not available');
13
19
  }
@@ -20,25 +26,35 @@ const createCache = (input) => {
20
26
  throw new TypeError('ttl must be an integer');
21
27
  }
22
28
 
29
+ if (
30
+ scope !== null &&
31
+ (!Array.isArray(scope) ||
32
+ !scope.every((v) => v === 'user' || v === 'auth'))
33
+ ) {
34
+ throw new TypeError(
35
+ 'scope must be an array of strings with values "user" or "auth"'
36
+ );
37
+ }
38
+
23
39
  ensureJSONEncodable(value);
24
40
  };
25
41
 
26
42
  return {
27
- get: async (key) => {
28
- runValidationChecks(rpc, key);
43
+ get: async (key, scope = null) => {
44
+ runValidationChecks(rpc, key, scope);
29
45
 
30
- const result = await rpc('zcache_get', key);
46
+ const result = await rpc('zcache_get', key, scope);
31
47
  return result ? JSON.parse(result) : null;
32
48
  },
33
- set: async (key, value, ttl = null) => {
34
- runValidationChecks(rpc, key, value, ttl);
49
+ set: async (key, value, ttl = null, scope = null) => {
50
+ runValidationChecks(rpc, key, value, ttl, scope);
35
51
 
36
- return await rpc('zcache_set', key, JSON.stringify(value), ttl);
52
+ return await rpc('zcache_set', key, JSON.stringify(value), ttl, scope);
37
53
  },
38
- delete: async (key) => {
39
- runValidationChecks(rpc, key);
54
+ delete: async (key, scope = null) => {
55
+ runValidationChecks(rpc, key, scope);
40
56
 
41
- return await rpc('zcache_delete', key);
57
+ return await rpc('zcache_delete', key, scope);
42
58
  },
43
59
  };
44
60
  };
@@ -2,7 +2,6 @@ import type {
2
2
  AfterResponseMiddleware,
3
3
  BeforeRequestMiddleware,
4
4
  Bundle,
5
- PerformFunction,
6
5
  ZObject,
7
6
  } from './zapier.custom';
8
7
  import type {
@@ -101,7 +100,10 @@ expectType<Trigger>(hookTrigger);
101
100
 
102
101
  const searchOperation: BasicActionOperation = {
103
102
  inputFields: [{ key: 'some-input-key-1', type: 'file', required: true }],
104
- perform: async (z: ZObject, b: Bundle) => [{ data: true }],
103
+ perform: async (z: ZObject, b: Bundle) => {
104
+ z.request('https://example.com', { middlewareData: { resumable: true } });
105
+ return [{ data: true }];
106
+ },
105
107
  };
106
108
  expectType<BasicActionOperation>(searchOperation);
107
109
 
@@ -124,7 +126,12 @@ const addBearerHeader: BeforeRequestMiddleware = (request, z, bundle) => {
124
126
  };
125
127
  expectType<BeforeRequestMiddleware>(addBearerHeader);
126
128
 
127
- const asyncBeforeRequest: BeforeRequestMiddleware = async (request) => request;
129
+ const asyncBeforeRequest: BeforeRequestMiddleware = async (request) => {
130
+ if (request.middlewareData?.resumable) {
131
+ // do something async etc.
132
+ }
133
+ return request;
134
+ };
128
135
  expectType<BeforeRequestMiddleware>(asyncBeforeRequest);
129
136
 
130
137
  const checkPermissionsError: AfterResponseMiddleware = (response, z) => {
@@ -95,6 +95,14 @@ export interface HttpRequestOptions {
95
95
  timeout?: number;
96
96
  url?: string;
97
97
  skipThrowForStatus?: boolean;
98
+
99
+ /**
100
+ * This is a special field that can be used to pass data to
101
+ * middleware. It is not sent with the request, but is available in
102
+ * the `response` object that middleware receives. This is useful for
103
+ * things like `prefixErrorMessage` fields etc.
104
+ */
105
+ middlewareData?: Record<string, any>;
98
106
  }
99
107
 
100
108
  interface BaseHttpResponse {
@@ -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: 15.13.0
7
+ * zapier-platform-schema version: 15.14.0
8
8
  * schema-to-ts compiler version: 0.1.0
9
9
  */
10
10