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:
commit
b4150c8250
1364 changed files with 6814366 additions and 0 deletions
66
vendor/zapier-platform/packages/schema/lib/functional-constraints/uniqueInputFieldKeys.js
vendored
Normal file
66
vendor/zapier-platform/packages/schema/lib/functional-constraints/uniqueInputFieldKeys.js
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const jsonschema = require('jsonschema');
|
||||
|
||||
const actionTypes = ['triggers', 'searches', 'creates'];
|
||||
|
||||
const uniqueInputFieldKeys = (definition) => {
|
||||
const errors = [];
|
||||
for (const actionType of actionTypes) {
|
||||
const group = definition[actionType] || {};
|
||||
_.each(group, (action, key) => {
|
||||
const inputFields = _.get(action, ['operation', 'inputFields'], []);
|
||||
|
||||
const existingKeys = {}; // map of key to where it already lives
|
||||
|
||||
inputFields.forEach((inputField, index) => {
|
||||
// could be a string or a non-field object (`source` or `require` function obj)
|
||||
if (!inputField.key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (existingKeys[inputField.key]) {
|
||||
errors.push(
|
||||
new jsonschema.ValidationError(
|
||||
`inputField keys must be unique for each action. The key "${
|
||||
inputField.key
|
||||
}" is already in use at ${actionType}.${key}.operation.${
|
||||
existingKeys[inputField.key]
|
||||
}.key`,
|
||||
inputField.key,
|
||||
`/BasicOperationSchema`,
|
||||
`instance.${actionType}.${key}.operation.inputFields[${index}].key`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
existingKeys[inputField.key] = `inputFields[${index}]`;
|
||||
}
|
||||
|
||||
(inputField.children || []).forEach((subField, subFieldIndex) => {
|
||||
if (existingKeys[subField.key]) {
|
||||
errors.push(
|
||||
new jsonschema.ValidationError(
|
||||
`inputField keys must be unique for each action, even if they're children. The key "${
|
||||
subField.key
|
||||
}" is already in use at ${actionType}.${key}.operation.${
|
||||
existingKeys[subField.key]
|
||||
}.key`,
|
||||
subField.key,
|
||||
`/BasicOperationSchema`,
|
||||
`instance.${actionType}.${key}.operation.inputFields[${index}].children[${subFieldIndex}].key`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
existingKeys[subField.key] =
|
||||
`inputFields[${index}].children[${subFieldIndex}]`;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
module.exports = uniqueInputFieldKeys;
|
||||
Loading…
Add table
Add a link
Reference in a new issue