zapier-platform-core 17.6.0 → 17.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": "17.
|
|
3
|
+
"version": "17.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/",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"node-fetch": "2.7.0",
|
|
64
64
|
"oauth-sign": "0.9.0",
|
|
65
65
|
"semver": "7.7.1",
|
|
66
|
-
"zapier-platform-schema": "17.
|
|
66
|
+
"zapier-platform-schema": "17.7.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/node-fetch": "^2.6.11",
|
package/src/checks/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
createIsObject: require('./create-is-object'),
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
searchIsArrayOrEnvelope: require('./search-is-array-or-envelope'),
|
|
5
5
|
|
|
6
6
|
triggerIsArray: require('./trigger-is-array'),
|
|
7
7
|
triggerIsObject: require('./trigger-is-object'),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const { simpleTruncate } = require('../tools/data');
|
|
5
|
+
|
|
6
|
+
const isSearch = require('./is-search');
|
|
7
|
+
|
|
8
|
+
const hasCanPaginate = (searchKey, compiledApp) => {
|
|
9
|
+
const canPaginate =
|
|
10
|
+
compiledApp?.searches?.[searchKey]?.operation?.canPaginate;
|
|
11
|
+
return canPaginate;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
Searches should return an array of objects,
|
|
16
|
+
or a response envelope like { results: [...], paging_token: '...' }
|
|
17
|
+
when canPaginate is true.
|
|
18
|
+
*/
|
|
19
|
+
const searchIsArrayOrEnvelope = {
|
|
20
|
+
name: 'searchIsArrayOrEnvelope',
|
|
21
|
+
shouldRun: isSearch,
|
|
22
|
+
run: (method, results, compiledApp) => {
|
|
23
|
+
const searchKey = method.split('.', 2)[1];
|
|
24
|
+
const truncatedResults = simpleTruncate(JSON.stringify(results), 50);
|
|
25
|
+
|
|
26
|
+
if (hasCanPaginate(searchKey, compiledApp)) {
|
|
27
|
+
// if paging is supported and results is an object (indicating pagination), it must have results and paging_token
|
|
28
|
+
if (_.isPlainObject(results)) {
|
|
29
|
+
if (!_.has(results, 'results') || !_.has(results, 'paging_token')) {
|
|
30
|
+
return [
|
|
31
|
+
`Paginated search results must be an object containing results and paging_token, got: ${truncatedResults}`,
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
if (
|
|
35
|
+
!_.isString(results.paging_token) &&
|
|
36
|
+
!_.isNull(results.paging_token)
|
|
37
|
+
) {
|
|
38
|
+
return [
|
|
39
|
+
`"paging_token" must be a string or null, got: ${typeof results.paging_token}`,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
// pass to array check below
|
|
43
|
+
results = results.results;
|
|
44
|
+
} else {
|
|
45
|
+
return [
|
|
46
|
+
`Paginated search results must be an object, got: ${typeof results}, (${truncatedResults})`,
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!_.isArray(results)) {
|
|
52
|
+
return [
|
|
53
|
+
`Search results must be an array, got: ${typeof results}, (${truncatedResults})`,
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports = searchIsArrayOrEnvelope;
|
package/types/functions.d.ts
CHANGED
|
@@ -118,9 +118,17 @@ export type CreatePerformGet<
|
|
|
118
118
|
> = (z: ZObject, bundle: Bundle<$InputData>) => $Return | Promise<$Return>;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Helper type for search results that can optionally include pagination.
|
|
122
|
+
* Returns either:
|
|
123
|
+
* - an array of objects, matching the search query.
|
|
124
|
+
* - an object with a `results` array of objects and a `paging_token` string.
|
|
122
125
|
*
|
|
123
|
-
*
|
|
126
|
+
* When `canPaginate` is true for the search, the object shape is required.
|
|
127
|
+
*/
|
|
128
|
+
type SearchResult<T> = T[] | { results: T[], paging_token: string };
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Search for objects on a partner API.
|
|
124
132
|
*
|
|
125
133
|
* @remarks
|
|
126
134
|
* This type requires a one-item array. Multiple items *can* be
|
|
@@ -130,7 +138,7 @@ export type CreatePerformGet<
|
|
|
130
138
|
export type SearchPerform<
|
|
131
139
|
$InputData extends DefaultInputData = DefaultInputData,
|
|
132
140
|
$Return extends {} = {},
|
|
133
|
-
> = (z: ZObject, bundle: Bundle<$InputData>) =>
|
|
141
|
+
> = (z: ZObject, bundle: Bundle<$InputData>) => SearchResult<$Return> | Promise<SearchResult<$Return>>;
|
|
134
142
|
|
|
135
143
|
/**
|
|
136
144
|
* Follow up a search's perform with additional data.
|
|
@@ -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.6.0
|
|
8
8
|
* schema-to-ts compiler version: 0.1.0
|
|
9
9
|
*/
|
|
10
10
|
import type {
|
|
@@ -1193,6 +1193,9 @@ export interface BasicSearchOperation<
|
|
|
1193
1193
|
*/
|
|
1194
1194
|
performGet?: Request | SearchPerformGet<InferInputData<$InputFields>>;
|
|
1195
1195
|
|
|
1196
|
+
/** Does this search support pagination? */
|
|
1197
|
+
canPaginate?: boolean;
|
|
1198
|
+
|
|
1196
1199
|
/** What should the form a user sees and configures look like? */
|
|
1197
1200
|
inputFields?: $InputFields;
|
|
1198
1201
|
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const { simpleTruncate } = require('../tools/data');
|
|
5
|
-
|
|
6
|
-
const isSearch = require('./is-search');
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
Searches should always return an array of objects.
|
|
10
|
-
*/
|
|
11
|
-
const searchIsArray = {
|
|
12
|
-
name: 'triggerIsArray',
|
|
13
|
-
shouldRun: isSearch,
|
|
14
|
-
run: (method, results) => {
|
|
15
|
-
if (!_.isArray(results)) {
|
|
16
|
-
const repr = simpleTruncate(JSON.stringify(results), 50);
|
|
17
|
-
return [`Results must be an array, got: ${typeof results}, (${repr})`];
|
|
18
|
-
}
|
|
19
|
-
return [];
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
module.exports = searchIsArray;
|