Milestone 0: import zappier billing, Verae middleware, and Zapier research

Compose-ready workspace: packages/zappier (rate card, portal, Stripe),
packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier
(CLI app), vendor/zapier-platform, and research/zapier vendor corpus.

Gate 0 structure checks pass. Product code and research are not yet wired.
This commit is contained in:
George Lambert 2026-09-09 02:37:36 -04:00
commit b4150c8250
117 changed files with 6814366 additions and 0 deletions

View file

@ -0,0 +1,4 @@
node_modules
*.zip
*.log
coverage

View file

@ -0,0 +1 @@
v22

View file

@ -0,0 +1,24 @@
# `zapier-platform-schema` Architecture
## Purpose
- This package, released as `zapier-platform-schema` publicly on [npm](https://www.npmjs.com/package/zapier-platform-schema), dictates the full schema against which apps are validated
- It's powered by [JSONSchema](https://json-schema.org/)
- The `core`, `schema`, and `cli` packages are always released together under matching version numbers.
## Technical Organization
> `schema/...`, when used in a path to a file, is shorthand for `zapier-platform/packages/schema/...`
- Schemas are declared, one-per-file, in `schema/lib/schemas`.
- The "root" schema is `schema/lib/schemas/AppSchema.js`, but that one doesn't change much.
- There are also functional constraints in `schema/lib/schemas/functional-constraints`, which validate things that JSONSchema can't cover (such as pairs of fields needing to have the same keys).
- Docs (in `schema/docs`) are generated directly from schemas via `pnpm build-docs`.
- Each schema has a `validate` that will validate incoming JSON. This is used in `core` to execute the `validation` command (which is exposed as the `zapier validate` command in CLI). See `schema/lib/utils/makeValidator.js`
### Tests
- tests live in `schema/test`.
- Each schema has an array of `examples` and `anti-examples`.
- Basic tests take each schema and ensure that it passes each of its `examples` and fails each of its `anti-examples`.
- There are separate tests for functional constraints.

View file

@ -0,0 +1 @@
See [CHANGELOG.md](https://github.com/zapier/zapier-platform/blob/main/CHANGELOG.md).

View file

@ -0,0 +1,3 @@
Copyright (c) Zapier, Inc.
This repository is part of Zapier Platform. By downloading, installing, accessing, or using any part of the Zapier Platform, including this repository, you agree to the Zapier Platform Agreement, which can be found at: https://zapier.com/platform/tos. If you do not agree to the Zapier Platform Agreement, you may not download, install, access, or use any part of the Zapier Platform, including this repository.

View file

@ -0,0 +1,31 @@
# Zapier Platform Schema
This is the schema for Zapier integrations.
For documentation:
- [Platform Docs](https://docs.zapier.com/platform)
- [CLI Reference](https://github.com/zapier/zapier-platform/blob/main/packages/cli/docs/cli.md)
- [Schema Reference](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md)
## Development
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/schema/ARCHITECTURE.md) of this package in particular.
Useful commands:
- `pnpm` to install packages and get started
- `pnpm lint` to lint code
- `pnpm test` to run tests
- `pnpm smoke-test` to run smoke tests
- `pnpm coverage` to run tests and display test coverage
- `pnpm validate` to run tests, smoke tests, and linter
- `pnpm export` to update the exported-schema (even if only the version changes)
- `pnpm docs` to update docs (even if only the version changes)
- `pnpm build` to update docs and the exported-schema (even if only the version changes)
## Publishing
Only do this after merging your PR to `main`.
- `pnpm version --[patch|minor|major]` will pull, test, update exported-schema, update docs, increment version in package.json, push tags, and publish to npm

View file

@ -0,0 +1,10 @@
'use strict';
const fs = require('fs');
const constants = require('../lib/constants');
const AppSchema = require('../lib/schemas/AppSchema');
const buildDocs = require('../lib/utils/buildDocs');
fs.writeFileSync(`./${constants.DOCS_PATH}`, buildDocs(AppSchema));

View file

@ -0,0 +1,11 @@
'use strict';
const fs = require('fs');
const schema = require('../schema');
const exportedSchema = schema.exportSchema();
fs.writeFileSync(
'./exported-schema.json',
JSON.stringify(exportedSchema, null, ' '),
);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,472 @@
{
"version": "1.2.30",
"platformVersion": "1.2.30",
"beforeRequest": "$func$2$f$",
"afterResponse": ["$func$2$f$"],
"requestTemplate": {
"headers": {
"X-MyCustomHeader": "my header value"
}
},
"authentication": {
"type": "oauth2",
"test": {
"url": "https://fake-crm.getsandbox.com/ping",
"method": "GET"
},
"fields": [
{
"key": "access_token",
"computed": true
},
{
"key": "refresh_token",
"computed": true
}
],
"oauth2Config": {
"authorizeUrl": "$func$2$f$",
"getAccessToken": {
"url": "https://fake-crm.getsandbox.com/oauth/access_token",
"method": "POST"
},
"scope": "tags,users,contacts",
"autoRefresh": false,
"enablePkce": false
},
"connectionLabel": "{{inputData.email}}"
},
"resources": {
"tag": {
"key": "tag",
"noun": "Tag",
"sample": {
"id": 1,
"name": "test tag"
},
"get": {
"display": {
"label": "Get Tag by ID",
"description": "Grab a specific Tag by ID."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/tags/{{inputData.id}}"
},
"sample": {
"id": 385,
"name": "proactive enable ROI"
},
"inputFields": [
{
"key": "id",
"required": true
}
]
}
},
"list": {
"display": {
"label": "New Tag",
"description": "Trigger when a new Tag is created in your account."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/tags"
},
"sample": {
"id": 385,
"name": "proactive enable ROI"
}
}
},
"create": {
"display": {
"label": "Create Tag",
"description": "Create a new Tag in your account."
},
"operation": {
"perform": "$func$2$f$",
"sample": {
"id": 1,
"name": "proactive enable ROI"
}
}
}
},
"user": {
"key": "user",
"noun": "User",
"sample": {
"id": 1,
"name": "Test McTesterson",
"email": "test@mctesterson.com"
},
"get": {
"display": {
"label": "Get User by ID",
"description": "Grab a specific User by ID."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/users/{{inputData.id}}"
},
"sample": {
"id": 1,
"name": "Jalen Bode",
"email": "jalen.bode@company.com"
},
"inputFields": [
{
"key": "id",
"required": true
}
]
}
},
"list": {
"display": {
"label": "New User",
"description": "Trigger when a new User is created in your account."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/users"
},
"sample": {
"id": 49,
"name": "Veronica Kuhn",
"email": "veronica.kuhn@company.com"
}
}
}
},
"contact": {
"key": "contact",
"noun": "Contact",
"sample": {
"id": 1,
"name": "Test Contact",
"company": "Test Inc",
"email": "test@example.com.com",
"phone": "1-111-555-7000",
"address": "1234 Test Canyon",
"owner_id": 1,
"tag_ids": [1, 2, 3]
},
"get": {
"display": {
"label": "Get Contact by ID",
"description": "Grab a specific Contact by ID."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/contacts/{{inputData.id}}"
},
"sample": {
"id": 1,
"name": "Rosalee Kub",
"company": "Schmidt, O'Reilly and Moen",
"email": "Rosalee_Kub47@hotmail.com",
"phone": "412-916-6798 x3478",
"address": "73375 Jacobson Turnpike",
"owner_id": 9,
"tag_ids": [87]
},
"inputFields": [
{
"key": "id",
"required": true
}
]
}
},
"list": {
"display": {
"label": "New Contact",
"description": "Trigger when a new Contact is created in your account."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/contacts"
},
"sample": {
"id": 1,
"name": "Rosalee Kub",
"company": "Schmidt, O'Reilly and Moen",
"email": "Rosalee_Kub47@hotmail.com",
"phone": "412-916-6798 x3478",
"address": "73375 Jacobson Turnpike",
"owner_id": 9,
"tag_ids": [87]
}
}
},
"create": {
"display": {
"label": "Create Contact",
"description": "Create a new Contact in your account."
},
"operation": {
"perform": "$func$2$f$",
"sample": {
"id": 1,
"name": "Rosalee Kub",
"company": "Schmidt, O'Reilly and Moen",
"email": "Rosalee_Kub47@hotmail.com",
"phone": "412-916-6798 x3478",
"address": "73375 Jacobson Turnpike",
"owner_id": 9,
"tag_ids": [87]
},
"inputFields": [
{
"key": "email",
"label": "Email",
"type": "string",
"required": true
},
{
"key": "name",
"label": "Name",
"type": "string"
},
{
"key": "company",
"label": "Company",
"type": "string"
},
{
"key": "phone",
"label": "Phone",
"type": "string"
},
{
"key": "address",
"label": "Address",
"type": "text"
},
{
"key": "owner_id",
"label": "Owner",
"type": "integer",
"dynamic": "user.id"
},
{
"key": "tag_id",
"label": "Tag",
"type": "integer",
"dynamic": "tag.id.name",
"search": "tag.id"
}
]
}
}
}
},
"triggers": {
"contact_by_tag": {
"key": "contact_by_tag",
"noun": "Contact",
"display": {
"label": "New Tagged Contact",
"description": "Trigger when a new Contact is tagged in your account."
},
"operation": {
"resource": "contact",
"perform": {
"url": "https://fake-crm.getsandbox.com/contacts?tag_id={{inputData.tagId}}"
},
"inputFields": [
{
"key": "tagId",
"label": "Tag",
"type": "integer",
"dynamic": "tag.id"
}
],
"sample": {
"id": 1,
"name": "Test Contact",
"company": "Test Inc",
"email": "test@example.com.com",
"phone": "1-111-555-7000",
"address": "1234 Test Canyon",
"owner_id": 1,
"tag_ids": [1, 2, 3]
}
}
},
"tag_list": {
"display": {
"label": "New Tag",
"description": "Trigger when a new Tag is created in your account."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/tags"
},
"sample": {
"id": 385,
"name": "proactive enable ROI"
},
"resource": "tag",
"type": "polling"
},
"key": "tag_list",
"noun": "Tag"
},
"user_list": {
"display": {
"label": "New User",
"description": "Trigger when a new User is created in your account."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/users"
},
"sample": {
"id": 49,
"name": "Veronica Kuhn",
"email": "veronica.kuhn@company.com"
},
"resource": "user",
"type": "polling"
},
"key": "user_list",
"noun": "User"
},
"contact_list": {
"display": {
"label": "New Contact",
"description": "Trigger when a new Contact is created in your account."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/contacts"
},
"resource": "contact",
"type": "polling",
"sample": {
"id": 1,
"name": "Test Contact",
"company": "Test Inc",
"email": "test@example.com.com",
"phone": "1-111-555-7000",
"address": "1234 Test Canyon",
"owner_id": 1,
"tag_ids": [1, 2, 3]
}
},
"key": "contact_list",
"noun": "Contact"
}
},
"searches": {
"tag": {
"display": {
"label": "Find Tag",
"description": "Finds a Tag."
},
"operation": {
"perform": {
"url": "https://fake-crm.getsandbox.com/tags?name={{inputData.name}}"
},
"resource": "tag",
"inputFields": [
{
"key": "name",
"label": "Tag Name",
"type": "string"
}
],
"sample": {
"id": 1,
"name": "test tag"
}
},
"key": "tag",
"noun": "Tag"
}
},
"creates": {
"tag_create": {
"display": {
"label": "Create Tag",
"description": "Create a new Tag in your account."
},
"operation": {
"perform": "$func$2$f$",
"resource": "tag",
"sample": {
"id": 385,
"name": "proactive enable ROI"
}
},
"key": "tag_create",
"noun": "Tag"
},
"contact_create": {
"display": {
"label": "Create Contact",
"description": "Create a new Contact in your account."
},
"operation": {
"perform": "$func$2$f$",
"inputFields": [
{
"key": "email",
"label": "Email",
"type": "string",
"required": true
},
{
"key": "name",
"label": "Name",
"type": "string"
},
{
"key": "company",
"label": "Company",
"type": "string"
},
{
"key": "phone",
"label": "Phone",
"type": "string"
},
{
"key": "address",
"label": "Address",
"type": "text"
},
{
"key": "owner_id",
"label": "Owner",
"type": "integer",
"dynamic": "user.id"
},
{
"key": "tag_id",
"label": "Tag",
"type": "integer",
"dynamic": "tag.id"
}
],
"resource": "contact",
"sample": {
"id": 1,
"name": "Test Contact",
"company": "Test Inc",
"email": "test@example.com.com",
"phone": "1-111-555-7000",
"address": "1234 Test Canyon",
"owner_id": 1,
"tag_ids": [1, 2, 3]
}
},
"key": "contact_create",
"noun": "Contact"
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,21 @@
module.exports = {
ROOT_GITHUB: 'https://github.com/zapier/zapier-platform',
DOCS_PATH: 'docs/build/schema.md',
DOC_URL_TEMPLATE:
'https://github.com/zapier/zapier-platform/blob/zapier-platform-cli%40<%= version %>/packages/schema/docs/build/schema.md<%= anchor %>',
SKIP_KEY: '_skipTest',
// the following pairs of keys can't be used together in PlainFieldSchema
// they're stored here because they're used in a few places
INCOMPATIBLE_FIELD_SCHEMA_KEYS: [
['children', 'list'], // This is actually a Feature Request (https://github.com/zapier/zapier-platform-cli/issues/115)
['children', 'dict'], // dict is ignored
['children', 'type'], // type is ignored
['children', 'placeholder'], // placeholder is ignored
['children', 'helpText'], // helpText is ignored
['children', 'default'], // default is ignored
['dict', 'list'], // Use only one or the other
['dynamic', 'dict'], // dict is ignored
['dynamic', 'choices'], // choices are ignored
],
FIELD_SCHEMA_BOOLEANS: new Set(['dict', 'list']),
};

View file

@ -0,0 +1,85 @@
'use strict';
const jsonschema = require('jsonschema');
const AUTH_FIELD_ID = '/AuthFieldSchema';
const AUTH_FIELDS_ID = '/AuthFieldsSchema';
const FORBIDDEN_KEYS = [
'access_token',
'access-token',
'accesstoken',
'api_key',
'apikey',
'api-key',
'auth',
'jwt',
'passwd',
'password',
'pswd',
'refresh_token',
'refresh-token',
'refreshtoken',
'secret',
'set-cookie',
'set_cookie',
'setcookie',
'signature',
'token',
];
const isSensitiveKey = (key = '') =>
FORBIDDEN_KEYS.some((forbidden) => key.toLowerCase().includes(forbidden));
const checkAuthField = (field) => {
const errors = [];
// if the field key contains any forbidden substring (case-insensitive),
// AND 'isNoSecret' is true, throw a validation error
if (
(field.key === 'password' || isSensitiveKey(field.key)) &&
field.isNoSecret === true
) {
errors.push(
new jsonschema.ValidationError(
`cannot set isNoSecret as true for the sensitive key "${field.key}".`,
field,
'/AuthFieldSchema',
'instance.field',
'sensitive',
'field',
),
);
}
return errors;
};
module.exports = (definition, mainSchema) => {
const errors = [];
// Done to validate anti-examples declaratively defined in the schema
if ([AUTH_FIELD_ID, AUTH_FIELDS_ID].includes(mainSchema.id)) {
const definitions = Array.isArray(definition) ? definition : [definition];
definitions.forEach((field, index) => {
checkAuthField(field).forEach((err) => {
err.property = `instance[${index}]`;
err.stack = err.stack.replace('instance.field', err.property);
errors.push(err);
});
});
}
// If there's no authentication or no fields, we have nothing to check
if (!definition.authentication || !definition.authentication.fields) {
return errors;
}
definition.authentication.fields.forEach((field, index) => {
checkAuthField(field).forEach((err) => {
err.property = `instance.authentication.fields[${index}]`;
err.stack = err.stack.replace('instance.field', err.property);
errors.push(err);
});
});
return errors;
};

View file

@ -0,0 +1,102 @@
'use strict';
const _ = require('lodash');
const jsonschema = require('jsonschema');
const bufferedCreateConstraints = (definition) => {
const errors = [];
const actionType = 'creates';
if (definition[actionType]) {
_.each(definition[actionType], (actionDef) => {
if (actionDef.operation && actionDef.operation.buffer) {
if (!actionDef.operation.performBuffer) {
errors.push(
new jsonschema.ValidationError(
'must contain property "performBuffer" because property "buffer" is present.',
actionDef.operation,
'/BasicCreateOperationSchema',
`instance.${actionType}.${actionDef.key}.operation`,
'missing',
'performBuffer',
),
);
}
if (actionDef.operation.perform) {
errors.push(
new jsonschema.ValidationError(
'must not contain property "perform" because it is mutually exclusive with property "buffer".',
actionDef.operation,
'/BasicCreateOperationSchema',
`instance.${actionType}.${actionDef.key}.operation`,
'invalid',
'perform',
),
);
}
if (actionDef.operation.buffer.groupedBy) {
const requiredInputFields = [];
const inputFields = _.get(
actionDef,
['operation', 'inputFields'],
[],
);
inputFields.forEach((inputField) => {
if (inputField.required) {
requiredInputFields.push(inputField.key);
}
});
actionDef.operation.buffer.groupedBy.forEach((field, index) => {
if (!requiredInputFields.includes(field)) {
errors.push(
new jsonschema.ValidationError(
`cannot use optional or non-existent inputField "${field}".`,
actionDef.operation.buffer,
'/BufferConfigSchema',
`instance.${actionType}.${actionDef.key}.operation.buffer.groupedBy[${index}]`,
'invalid',
'groupedBy',
),
);
}
});
}
}
if (actionDef.operation && actionDef.operation.performBuffer) {
if (!actionDef.operation.buffer) {
errors.push(
new jsonschema.ValidationError(
'must contain property "buffer" because property "performBuffer" is present.',
actionDef.operation,
'/BasicCreateOperationSchema',
`instance.${actionType}.${actionDef.key}.operation`,
'missing',
'buffer',
),
);
}
if (actionDef.operation.perform) {
errors.push(
new jsonschema.ValidationError(
'must not contain property "perform" because it is mutually exclusive with property "performBuffer".',
actionDef.operation,
'/BasicCreateOperationSchema',
`instance.${actionType}.${actionDef.key}.operation`,
'invalid',
'perform',
),
);
}
}
});
}
return errors;
};
module.exports = bufferedCreateConstraints;

View file

@ -0,0 +1,68 @@
'use strict';
const _ = require('lodash');
const jsonschema = require('jsonschema');
const collectErrors = (inputFields, path) => {
const errors = [];
_.each(inputFields, (inputField, index) => {
if (inputField.children) {
if (inputField.children.length === 0) {
errors.push(
new jsonschema.ValidationError(
'must not be empty.',
inputField,
'/PlainFieldSchema',
`instance.${path}.inputFields[${index}].children`,
'empty',
'inputFields',
),
);
} else {
const hasDeeplyNestedChildren = _.some(
inputField.children,
(child) => child.children,
);
if (hasDeeplyNestedChildren) {
errors.push(
new jsonschema.ValidationError(
'must not contain deeply nested child fields. One level max.',
inputField,
'/PlainFieldSchema',
`instance.${path}.inputFields[${index}]`,
'deepNesting',
'inputFields',
),
);
}
}
}
});
return errors;
};
const validateFieldNesting = (definition) => {
let errors = [];
_.each(['triggers', 'searches', 'creates'], (typeOf) => {
if (definition[typeOf]) {
_.each(definition[typeOf], (actionDef) => {
if (actionDef.operation && actionDef.operation.inputFields) {
errors = errors.concat(
collectErrors(
actionDef.operation.inputFields,
`${typeOf}.${actionDef.key}`,
),
);
}
});
}
});
return errors;
};
module.exports = validateFieldNesting;

View file

@ -0,0 +1,41 @@
'use strict';
/* Each check below is expected to return a list of ValidationSchema errors. An error is defined by:
* new jsonschema.ValidationError(
* message, // string that explains the problem, like 'must not have a URL that points to AWS'
* instance, // the snippet of the app definition that is invalid
* schema, // name of the schema that failed, like '/TriggerSchema'
* propertyPath, // stringified path to problematic snippet, like 'instance.triggers.find_contact'
* name, // optional, the validation type that failed. Can make something up like 'invalidUrl'
* argument // optional
* );
*/
const checks = [
require('./searchOrCreateKeys'),
require('./deepNestedFields'),
require('./mutuallyExclusiveFields'),
require('./requiredSamples'),
require('./matchingKeys'),
require('./labelWhenVisible'),
require('./uniqueInputFieldKeys'),
require('./bufferedCreateConstraints'),
require('./requirePerformConditionally'),
require('./pollingThrottle'),
require('./AuthFieldisSafe'),
require('./inputFieldGroupsConstraints'),
require('./validateJsonFieldSchema'),
];
const runFunctionalConstraints = (definition, mainSchema) => {
return checks.reduce((errors, checkFunc) => {
const errorsForCheck = checkFunc(definition, mainSchema);
if (errorsForCheck) {
errors = errors.concat(errorsForCheck);
}
return errors;
}, []);
};
module.exports = {
run: runFunctionalConstraints,
};

View file

@ -0,0 +1,144 @@
'use strict';
const _ = require('lodash');
const jsonschema = require('jsonschema');
const actionTypes = ['triggers', 'searches', 'creates', 'bulkReads'];
const resourceMethods = ['get', 'list', 'hook', 'search', 'create'];
const validateInputFieldGroups = (
inputFields,
inputFieldGroups,
basePath,
schemaName,
) => {
const errors = [];
// Check for duplicate group keys in inputFieldGroups
const groupKeys = inputFieldGroups.map((group) => group.key);
const duplicateKeys = groupKeys.filter(
(key, index) => groupKeys.indexOf(key) !== index,
);
if (duplicateKeys.length > 0) {
duplicateKeys.forEach((duplicateKey) => {
const duplicateIndex = groupKeys.lastIndexOf(duplicateKey);
errors.push(
new jsonschema.ValidationError(
`Duplicate group key "${duplicateKey}" found in inputFieldGroups. Group keys must be unique.`,
inputFieldGroups[duplicateIndex],
schemaName,
`${basePath}.inputFieldGroups[${duplicateIndex}].key`,
'duplicateGroupKey',
'inputFieldGroups',
),
);
});
}
// Create a set of valid group keys
const validGroupKeys = new Set(groupKeys);
inputFields.forEach((inputField, index) => {
// Check children fields first - groups are not allowed in children
(inputField.children || []).forEach((childField, childIndex) => {
if (childField.group) {
errors.push(
new jsonschema.ValidationError(
`Group fields are not allowed in children fields. Remove the group property from this field.`,
childField.group,
'/PlainInputFieldSchema',
`${basePath}.inputFields[${index}].children[${childIndex}].group`,
'groupInChildren',
'group',
),
);
}
});
// Check if group reference is valid
if (inputField.group) {
if (!validGroupKeys.has(inputField.group)) {
const availableGroups =
Array.from(validGroupKeys).length > 0
? `[${Array.from(validGroupKeys).join(', ')}]`
: '[]';
errors.push(
new jsonschema.ValidationError(
`Group "${inputField.group}" is not defined in inputFieldGroups. Available groups: ${availableGroups}`,
inputField.group,
'/PlainInputFieldSchema',
`${basePath}.inputFields[${index}].group`,
'invalidGroupReference',
'group',
),
);
}
}
});
return errors;
};
const inputFieldGroupsConstraints = (definition) => {
const errors = [];
// Validate action types (triggers, searches, creates, bulkReads)
for (const actionType of actionTypes) {
const group = definition[actionType] || {};
_.each(group, (action, actionKey) => {
const inputFields = _.get(action, ['operation', 'inputFields'], []);
const inputFieldGroups = _.get(
action,
['operation', 'inputFieldGroups'],
[],
);
const basePath = `instance.${actionType}.${actionKey}.operation`;
const schemaName = '/BasicOperationSchema';
const actionErrors = validateInputFieldGroups(
inputFields,
inputFieldGroups,
basePath,
schemaName,
);
errors.push(...actionErrors);
});
}
// Validate resources
if (definition.resources) {
_.each(definition.resources, (resource, resourceKey) => {
resourceMethods.forEach((method) => {
if (resource[method] && resource[method].operation) {
const inputFields = _.get(
resource[method],
['operation', 'inputFields'],
[],
);
const inputFieldGroups = _.get(
resource[method],
['operation', 'inputFieldGroups'],
[],
);
const basePath = `instance.resources.${resourceKey}.${method}.operation`;
const schemaName = '/BasicOperationSchema';
const resourceErrors = validateInputFieldGroups(
inputFields,
inputFieldGroups,
basePath,
schemaName,
);
errors.push(...resourceErrors);
}
});
});
}
return errors;
};
module.exports = inputFieldGroupsConstraints;

View file

@ -0,0 +1,31 @@
const _ = require('lodash');
const jsonschema = require('jsonschema');
const actionTypes = ['triggers', 'searches', 'creates', 'bulkReads'];
const labelWhenVisible = (definition) => {
const errors = [];
for (const actionType of actionTypes) {
const group = definition[actionType] || {};
_.each(group, (action, key) => {
const { display } = action;
if (!display.hidden && !(display.label && display.description)) {
errors.push(
new jsonschema.ValidationError(
`visible actions must have a label and description`,
action,
`/BasicDisplaySchema`,
`instance.${actionType}.${key}.display`,
'invalid',
'key',
),
);
}
});
}
return errors;
};
module.exports = labelWhenVisible;

View file

@ -0,0 +1,35 @@
'use strict';
const _ = require('lodash');
const jsonschema = require('jsonschema');
const actionTypes = ['triggers', 'searches', 'creates'];
const matchingKeys = (definition) => {
const errors = [];
// verifies that x.key === x
// otherwise, we double results in the compiled app via core's compileApp
for (const actionType of actionTypes) {
const group = definition[actionType] || {};
_.each(group, (action, key) => {
if (action.key !== key) {
errors.push(
new jsonschema.ValidationError(
`must have a matching top-level key (found "${key}" and "${action.key}")`,
action,
`/${_.capitalize(actionType)}Schema`,
`instance.${key}.key`,
'invalid',
'key',
),
);
}
});
}
return errors;
};
module.exports = matchingKeys;

View file

@ -0,0 +1,70 @@
'use strict';
const _ = require('lodash');
const jsonschema = require('jsonschema');
// NOTE: While it would be possible to accomplish this with a solution like
// https://stackoverflow.com/questions/28162509/mutually-exclusive-property-groups#28172831
// it was harder to read and understand.
const {
INCOMPATIBLE_FIELD_SCHEMA_KEYS,
FIELD_SCHEMA_BOOLEANS,
} = require('../constants');
const verifyIncompatibilities = (inputFields, path) => {
const errors = [];
_.each(inputFields, (inputField, index) => {
_.each(INCOMPATIBLE_FIELD_SCHEMA_KEYS, ([firstField, secondField]) => {
if (_.has(inputField, firstField) && _.has(inputField, secondField)) {
// this could be ok if it's a boolean field and is falsy
// i'm reasonably sure that the editor handles this fine, but if it also checks
// for the existence of the property (not the truthiness), then there could be an issue
if (
(FIELD_SCHEMA_BOOLEANS.has(firstField) && !inputField[firstField]) ||
(FIELD_SCHEMA_BOOLEANS.has(secondField) && !inputField[secondField])
) {
return;
}
errors.push(
new jsonschema.ValidationError(
`must not contain ${firstField} and ${secondField}, as they're mutually exclusive.`,
inputField,
'/PlainFieldSchema',
`instance.${path}.inputFields[${index}]`,
'invalid',
'inputFields',
),
);
}
});
});
return errors;
};
const mutuallyExclusiveFields = (definition) => {
let errors = [];
_.each(['triggers', 'searches', 'creates'], (typeOf) => {
if (definition[typeOf]) {
_.each(definition[typeOf], (actionDef) => {
if (actionDef.operation && actionDef.operation.inputFields) {
errors = [
...errors,
...verifyIncompatibilities(
actionDef.operation.inputFields,
`${typeOf}.${actionDef.key}`,
),
];
}
});
}
});
return errors;
};
module.exports = mutuallyExclusiveFields;

Some files were not shown because too many files have changed in this diff Show more