From fd594f3ebfd633ea661751cef0f6a68abf337aa3 Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Tue, 28 Jan 2025 08:09:24 -0500 Subject: [PATCH 01/60] first attempt: split FieldSchema --- packages/schema/lib/schemas/AppSchema.js | 19 ++ .../schema/lib/schemas/AuthFieldSchema.js | 47 ++++ .../schema/lib/schemas/AuthFieldsSchema.js | 17 ++ .../schema/lib/schemas/BaseFieldSchema.js | 210 ++++++++++++++++++ .../schema/lib/schemas/InputFieldSchema.js | 52 +++++ .../schema/lib/schemas/InputFieldsSchema.js | 17 ++ .../schema/lib/schemas/OutputFieldSchema.js | 29 +++ .../schema/lib/schemas/OutputFieldsSchema.js | 17 ++ 8 files changed, 408 insertions(+) create mode 100644 packages/schema/lib/schemas/AuthFieldSchema.js create mode 100644 packages/schema/lib/schemas/AuthFieldsSchema.js create mode 100644 packages/schema/lib/schemas/BaseFieldSchema.js create mode 100644 packages/schema/lib/schemas/InputFieldSchema.js create mode 100644 packages/schema/lib/schemas/InputFieldsSchema.js create mode 100644 packages/schema/lib/schemas/OutputFieldSchema.js create mode 100644 packages/schema/lib/schemas/OutputFieldsSchema.js diff --git a/packages/schema/lib/schemas/AppSchema.js b/packages/schema/lib/schemas/AppSchema.js index ffb55c13f..e323ff6e9 100644 --- a/packages/schema/lib/schemas/AppSchema.js +++ b/packages/schema/lib/schemas/AppSchema.js @@ -106,6 +106,21 @@ module.exports = makeSchema( description: 'Top-level app options', $ref: AppFlagsSchema.id, }, + // inputFields: { + // description: + // 'An array or collection of input fields.', + // $ref: InputFieldsSchema.id, + // }, + // outputFields: { + // description: + // 'An array or collection of output fields.', + // $ref: OutputFieldsSchema.id, + // }, + // authFields: { + // description: + // 'An array or collection of auth input fields.', + // $ref: AuthFieldsSchema.id, + // }, throttle: { description: `Zapier uses this configuration to apply throttling when the limit for the window is exceeded. When set here, it is the default throttle configuration used on each action of the integration. And when set in an action's operation object, it gets overwritten for that action only.`, $ref: ThrottleObjectSchema.id, @@ -143,6 +158,10 @@ module.exports = makeSchema( [ AuthenticationSchema, FlatObjectSchema, + // OutputFieldsSchema, + // InputFieldsSchema, + // AuthFieldsSchema, + // BaseFieldSchema, ResourcesSchema, ReadBulksSchema, TriggersSchema, diff --git a/packages/schema/lib/schemas/AuthFieldSchema.js b/packages/schema/lib/schemas/AuthFieldSchema.js new file mode 100644 index 000000000..adfd6c11a --- /dev/null +++ b/packages/schema/lib/schemas/AuthFieldSchema.js @@ -0,0 +1,47 @@ +'use strict'; + +const makeSchema = require('../utils/makeSchema'); +const BaseFieldSchema = require('./BaseFieldSchema'); +const schema = makeSchema( + { + id: '/AuthFieldSchema', + description: 'Field schema specialized for auth fields (e.g., OAuth).', + type: 'object', + allOf: [ + { $ref: BaseFieldSchema.id }, + { + type: 'object', + properties: { + // New property + isSafe: { + description: 'Indicates if this auth field is safe (not secret).', + type: 'boolean', + }, + }, + additionalProperties: false, + }, + // Forbid certain keys from having isSafe = true + { + not: { + properties: { + key: { + enum: [ + 'access_token', + 'refresh_token', + 'api_key', + 'password', + 'secret', + ], + }, + isSafe: { const: true }, + }, + required: ['key', 'isSafe'], + }, + }, + ], + }, + [BaseFieldSchema], +); + +schema.dependencies = [BaseFieldSchema]; +module.exports = schema; diff --git a/packages/schema/lib/schemas/AuthFieldsSchema.js b/packages/schema/lib/schemas/AuthFieldsSchema.js new file mode 100644 index 000000000..ef05cd6d3 --- /dev/null +++ b/packages/schema/lib/schemas/AuthFieldsSchema.js @@ -0,0 +1,17 @@ +'use strict'; + +const makeSchema = require('../utils/makeSchema'); + +const AuthFieldSchema = require('./AuthFieldSchema'); + +module.exports = makeSchema( + { + id: '/AuthFieldsSchema', + description: 'An array or collection of auth input fields.', + type: 'array', + items: { $ref: AuthFieldSchema.id }, + examples: [[{ key: 'abc' }]], + antiExamples: [{ example: {}, reason: 'Must be an array' }], + }, + [AuthFieldSchema], +); diff --git a/packages/schema/lib/schemas/BaseFieldSchema.js b/packages/schema/lib/schemas/BaseFieldSchema.js new file mode 100644 index 000000000..5fe0ebd91 --- /dev/null +++ b/packages/schema/lib/schemas/BaseFieldSchema.js @@ -0,0 +1,210 @@ +'use strict'; + +const makeSchema = require('../utils/makeSchema'); + +const RefResourceSchema = require('./RefResourceSchema'); + +const FieldChoicesSchema = require('./FieldChoicesSchema'); + +const FieldMetaSchema = require('./FieldMetaSchema'); + +const { INCOMPATIBLE_FIELD_SCHEMA_KEYS } = require('../constants'); + +// the following takes an array of string arrays (string[][]) and returns the follwing string: +// * `a` & `b` +// * `c` & `d` +// ... etc +const wrapInBackticks = (s) => `\`${s}\``; +const formatBullet = (f) => `* ${f.map(wrapInBackticks).join(' & ')}`; +const incompatibleFieldsList = + INCOMPATIBLE_FIELD_SCHEMA_KEYS.map(formatBullet).join('\n'); + +module.exports = makeSchema( + { + id: '/BaseFieldSchema', + description: `Defines a field an app either needs as input, or gives as output. In addition to the requirements below, the following keys are mutually exclusive:\n\n${incompatibleFieldsList}`, + type: 'object', + required: ['key'], + properties: { + key: { + description: + 'A unique machine readable key for this value (IE: "fname").', + type: 'string', + minLength: 1, + }, + label: { + description: + 'A human readable label for this value (IE: "First Name").', + type: 'string', + minLength: 1, + }, + helpText: { + description: + 'A human readable description of this value (IE: "The first part of a full name."). You can use Markdown.', + type: 'string', + minLength: 1, + maxLength: 1000, + }, + type: { + description: + 'The type of this value. Use `string` for basic text input, `text` for a large, `