zapier-platform-schema 15.14.0 → 15.14.2

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "15.14.0",
2
+ "version": "15.14.2",
3
3
  "schemas": {
4
4
  "AppSchema": {
5
5
  "id": "/AppSchema",
@@ -1360,18 +1360,35 @@
1360
1360
  },
1361
1361
  "additionalProperties": false
1362
1362
  },
1363
+ "BufferConfigSchema": {
1364
+ "id": "/BufferConfigSchema",
1365
+ "description": "Currently an **internal-only** feature. Zapier uses this configuration for creating objects in bulk.",
1366
+ "type": "object",
1367
+ "required": ["groupedBy", "limit"],
1368
+ "properties": {
1369
+ "groupedBy": {
1370
+ "description": "The list of keys of input fields to group bulk-create with. The actual user data provided for the fields will be used during execution. Note that a required input field should be referenced to get user data always.",
1371
+ "type": "array",
1372
+ "minItems": 1
1373
+ },
1374
+ "limit": {
1375
+ "description": "The maximum number of items to call `performBuffer` with. **Note** that it is capped by the platform to prevent exceeding the [AWS Lambda's request/response payload size quota of 6 MB](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#function-configuration-deployment-and-execution). Also, the execution is time-bound; we recommend reducing it upon consistent timeout.",
1376
+ "type": "integer"
1377
+ }
1378
+ },
1379
+ "additionalProperties": false
1380
+ },
1363
1381
  "BasicCreateActionOperationSchema": {
1364
1382
  "id": "/BasicCreateActionOperationSchema",
1365
1383
  "description": "Represents the fundamental mechanics of a create.",
1366
1384
  "type": "object",
1367
- "required": ["perform"],
1368
1385
  "properties": {
1369
1386
  "resource": {
1370
1387
  "description": "Optionally reference and extends a resource. Allows Zapier to automatically tie together samples, lists and hooks, greatly improving the UX. EG: if you had another trigger reusing a resource but filtering the results.",
1371
1388
  "$ref": "/KeySchema"
1372
1389
  },
1373
1390
  "perform": {
1374
- "description": "How will Zapier get the data? This can be a function like `(z) => [{id: 123}]` or a request like `{url: 'http...'}`.",
1391
+ "description": "How will Zapier get the data? This can be a function like `(z) => [{id: 123}]` or a request like `{url: 'http...'}`. Exactly one of `perform` or `performBuffer` must be defined. If you choose to define `buffer` and `performBuffer`, you must omit `perform`.",
1375
1392
  "oneOf": [
1376
1393
  {
1377
1394
  "$ref": "/RequestSchema"
@@ -1379,7 +1396,13 @@
1379
1396
  {
1380
1397
  "$ref": "/FunctionSchema"
1381
1398
  }
1382
- ]
1399
+ ],
1400
+ "docAnnotation": {
1401
+ "required": {
1402
+ "type": "replace",
1403
+ "value": "no (with exceptions, see description)"
1404
+ }
1405
+ }
1383
1406
  },
1384
1407
  "performResume": {
1385
1408
  "description": "A function that parses data from a perform (which uses z.generateCallbackUrl()) and callback request to resume this action.",
@@ -1426,6 +1449,26 @@
1426
1449
  "shouldLock": {
1427
1450
  "description": "Should this action be performed one at a time (avoid concurrency)?",
1428
1451
  "type": "boolean"
1452
+ },
1453
+ "buffer": {
1454
+ "description": "Currently an **internal-only** feature. Zapier uses this configuration for creating objects in bulk with `performBuffer`.",
1455
+ "$ref": "/BufferConfigSchema",
1456
+ "docAnnotation": {
1457
+ "required": {
1458
+ "type": "replace",
1459
+ "value": "no (with exceptions, see description)"
1460
+ }
1461
+ }
1462
+ },
1463
+ "performBuffer": {
1464
+ "description": "Currently an **internal-only** feature. A function to create objects in bulk with. `buffer` and `performBuffer` must either both be defined or neither. Additionally, only one of `perform` or `performBuffer` can be defined. If you choose to define `perform`, you must omit `buffer` and `performBuffer`.",
1465
+ "$ref": "/FunctionSchema",
1466
+ "docAnnotation": {
1467
+ "required": {
1468
+ "type": "replace",
1469
+ "value": "no (with exceptions, see description)"
1470
+ }
1471
+ }
1429
1472
  }
1430
1473
  },
1431
1474
  "additionalProperties": false
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ const _ = require('lodash');
4
+ const jsonschema = require('jsonschema');
5
+
6
+ const bufferedCreateConstraints = (definition) => {
7
+ const errors = [];
8
+ const actionType = 'creates';
9
+
10
+ if (definition[actionType]) {
11
+ _.each(definition[actionType], (actionDef) => {
12
+ if (actionDef.operation && actionDef.operation.buffer) {
13
+ if (!actionDef.operation.performBuffer) {
14
+ errors.push(
15
+ new jsonschema.ValidationError(
16
+ 'must contain property "performBuffer" because property "buffer" is present.',
17
+ actionDef.operation,
18
+ '/BasicCreateActionOperationSchema',
19
+ `instance.${actionType}.${actionDef.key}.operation`,
20
+ 'missing',
21
+ 'performBuffer'
22
+ )
23
+ );
24
+ }
25
+
26
+ if (actionDef.operation.perform) {
27
+ errors.push(
28
+ new jsonschema.ValidationError(
29
+ 'must not contain property "perform" because it is mutually exclusive with property "buffer".',
30
+ actionDef.operation,
31
+ '/BasicCreateActionOperationSchema',
32
+ `instance.${actionType}.${actionDef.key}.operation`,
33
+ 'invalid',
34
+ 'perform'
35
+ )
36
+ );
37
+ }
38
+
39
+ if (actionDef.operation.buffer.groupedBy) {
40
+ const requiredInputFields = [];
41
+ const inputFields = _.get(
42
+ actionDef,
43
+ ['operation', 'inputFields'],
44
+ []
45
+ );
46
+ inputFields.forEach((inputField) => {
47
+ if (inputField.required) {
48
+ requiredInputFields.push(inputField.key);
49
+ }
50
+ });
51
+
52
+ actionDef.operation.buffer.groupedBy.forEach((field, index) => {
53
+ if (!requiredInputFields.includes(field)) {
54
+ errors.push(
55
+ new jsonschema.ValidationError(
56
+ `cannot use optional or non-existent inputField "${field}".`,
57
+ actionDef.operation.buffer,
58
+ '/BufferConfigSchema',
59
+ `instance.${actionType}.${actionDef.key}.operation.buffer.groupedBy[${index}]`,
60
+ 'invalid',
61
+ 'groupedBy'
62
+ )
63
+ );
64
+ }
65
+ });
66
+ }
67
+ }
68
+
69
+ if (actionDef.operation && actionDef.operation.performBuffer) {
70
+ if (!actionDef.operation.buffer) {
71
+ errors.push(
72
+ new jsonschema.ValidationError(
73
+ 'must contain property "buffer" because property "performBuffer" is present.',
74
+ actionDef.operation,
75
+ '/BasicCreateActionOperationSchema',
76
+ `instance.${actionType}.${actionDef.key}.operation`,
77
+ 'missing',
78
+ 'buffer'
79
+ )
80
+ );
81
+ }
82
+
83
+ if (actionDef.operation.perform) {
84
+ errors.push(
85
+ new jsonschema.ValidationError(
86
+ 'must not contain property "perform" because it is mutually exclusive with property "performBuffer".',
87
+ actionDef.operation,
88
+ '/BasicCreateActionOperationSchema',
89
+ `instance.${actionType}.${actionDef.key}.operation`,
90
+ 'invalid',
91
+ 'perform'
92
+ )
93
+ );
94
+ }
95
+ }
96
+ });
97
+ }
98
+
99
+ return errors;
100
+ };
101
+
102
+ module.exports = bufferedCreateConstraints;
@@ -18,6 +18,8 @@ const checks = [
18
18
  require('./matchingKeys'),
19
19
  require('./labelWhenVisible'),
20
20
  require('./uniqueInputFieldKeys'),
21
+ require('./bufferedCreateConstraints'),
22
+ require('./requirePerformConditionally'),
21
23
  require('./pollingThrottle'),
22
24
  ];
23
25
 
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ const _ = require('lodash');
4
+ const jsonschema = require('jsonschema');
5
+
6
+ const requirePerformConditionally = (definition) => {
7
+ const errors = [];
8
+ const actionType = 'creates';
9
+
10
+ if (definition[actionType]) {
11
+ _.each(definition[actionType], (actionDef) => {
12
+ if (
13
+ actionDef.operation &&
14
+ !actionDef.operation.buffer &&
15
+ !actionDef.operation.performBuffer &&
16
+ !actionDef.operation.perform
17
+ ) {
18
+ errors.push(
19
+ new jsonschema.ValidationError(
20
+ 'requires property "perform".',
21
+ actionDef.operation,
22
+ '/BasicCreateActionOperationSchema',
23
+ `instance.${actionType}.${actionDef.key}.operation`,
24
+ 'required',
25
+ 'perform'
26
+ )
27
+ );
28
+ }
29
+ });
30
+ }
31
+
32
+ return errors;
33
+ };
34
+
35
+ module.exports = requirePerformConditionally;
@@ -3,6 +3,9 @@
3
3
  const makeSchema = require('../utils/makeSchema');
4
4
 
5
5
  const BasicActionOperationSchema = require('./BasicActionOperationSchema');
6
+ const BufferConfigSchema = require('./BufferConfigSchema');
7
+ const FunctionSchema = require('./FunctionSchema');
8
+ const RequestSchema = require('./RequestSchema');
6
9
 
7
10
  // TODO: would be nice to deep merge these instead
8
11
  // or maybe use allOf which is built into json-schema
@@ -20,7 +23,45 @@ BasicCreateActionOperationSchema.properties.shouldLock = {
20
23
  type: 'boolean',
21
24
  };
22
25
 
26
+ BasicCreateActionOperationSchema.properties.perform = {
27
+ description:
28
+ "How will Zapier get the data? This can be a function like `(z) => [{id: 123}]` or a request like `{url: 'http...'}`. Exactly one of `perform` or `performBuffer` must be defined. If you choose to define `buffer` and `performBuffer`, you must omit `perform`.",
29
+ oneOf: [{ $ref: RequestSchema.id }, { $ref: FunctionSchema.id }],
30
+ docAnnotation: {
31
+ required: {
32
+ type: 'replace', // replace or append
33
+ value: 'no (with exceptions, see description)',
34
+ },
35
+ },
36
+ };
37
+
38
+ BasicCreateActionOperationSchema.properties.buffer = {
39
+ description:
40
+ 'Currently an **internal-only** feature. Zapier uses this configuration for creating objects in bulk with `performBuffer`.',
41
+ $ref: BufferConfigSchema.id,
42
+ docAnnotation: {
43
+ required: {
44
+ type: 'replace', // replace or append
45
+ value: 'no (with exceptions, see description)',
46
+ },
47
+ },
48
+ };
49
+
50
+ BasicCreateActionOperationSchema.properties.performBuffer = {
51
+ description:
52
+ 'Currently an **internal-only** feature. A function to create objects in bulk with. `buffer` and `performBuffer` must either both be defined or neither. Additionally, only one of `perform` or `performBuffer` can be defined. If you choose to define `perform`, you must omit `buffer` and `performBuffer`.',
53
+ $ref: FunctionSchema.id,
54
+ docAnnotation: {
55
+ required: {
56
+ type: 'replace', // replace or append
57
+ value: 'no (with exceptions, see description)',
58
+ },
59
+ },
60
+ };
61
+
62
+ delete BasicCreateActionOperationSchema.required;
63
+
23
64
  module.exports = makeSchema(
24
65
  BasicCreateActionOperationSchema,
25
- BasicActionOperationSchema.dependencies
66
+ BasicActionOperationSchema.dependencies.concat(BufferConfigSchema)
26
67
  );
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ const makeSchema = require('../utils/makeSchema');
4
+
5
+ module.exports = makeSchema({
6
+ id: '/BufferConfigSchema',
7
+ description:
8
+ 'Currently an **internal-only** feature. Zapier uses this configuration for creating objects in bulk.',
9
+ type: 'object',
10
+ required: ['groupedBy', 'limit'],
11
+ properties: {
12
+ groupedBy: {
13
+ description:
14
+ 'The list of keys of input fields to group bulk-create with. The actual user data provided for the fields will be used during execution. Note that a required input field should be referenced to get user data always.',
15
+ type: 'array',
16
+ minItems: 1,
17
+ },
18
+ limit: {
19
+ description:
20
+ "The maximum number of items to call `performBuffer` with. **Note** that it is capped by the platform to prevent exceeding the [AWS Lambda's request/response payload size quota of 6 MB](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#function-configuration-deployment-and-execution). Also, the execution is time-bound; we recommend reducing it upon consistent timeout.",
21
+ type: 'integer',
22
+ },
23
+ },
24
+ examples: [
25
+ {
26
+ groupedBy: ['workspace', 'sheet'],
27
+ limit: 100,
28
+ },
29
+ ],
30
+ antiExamples: [
31
+ {
32
+ example: {
33
+ groupedBy: [],
34
+ limit: 100,
35
+ },
36
+ reason: 'Empty groupedBy list provided: `[]`.',
37
+ },
38
+ {
39
+ example: { groupedBy: ['workspace'] },
40
+ reason: 'Missing required key: `limit`.',
41
+ },
42
+ {
43
+ example: { limit: 1 },
44
+ reason: 'Missing required key: `groupedBy`.',
45
+ },
46
+ ],
47
+ additionalProperties: false,
48
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zapier-platform-schema",
3
- "version": "15.14.0",
3
+ "version": "15.14.2",
4
4
  "description": "Schema definition for CLI apps in the Zapier Developer Platform.",
5
5
  "repository": "zapier/zapier-platform",
6
6
  "homepage": "https://platform.zapier.com/",