From a6f4867cdbd0f3bd20eaa9ab95b90e2779e98642 Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Tue, 4 Feb 2025 09:05:08 -0500 Subject: [PATCH] feat(schema): PDE-5719 split FieldSchema into InputFieldSchema, OutputFieldSchema, and AuthFieldSchema (#957) * first attempt: split FieldSchema * PDE-5719 address PR comments * PDE-5719 address commented out lines * PDE-5719 address commented out lines * PDE-5719 clean up * PDE-5719 clean up * rename to AuthFieldSchema * PR suggestions: remove cleanErrors addition * PR suggestions: add examples and anti-examples * fix description * remove FieldsSchema and DynamicFieldsSchema * add unit tests * update unit test * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldsSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldsSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldsSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldsSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldsSchema.js Co-authored-by: Kola Erinoso * run yarn build * PR suggestion: move isSafe check as a functional-contsraint * update test * Update packages/schema/test/index.js Co-authored-by: Kola Erinoso * Update packages/schema/test/index.js Co-authored-by: Kola Erinoso * Update packages/schema/test/index.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/utils/makeValidator.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * update FORBIDDEN_KEYS to match secret scrubber * PR suggestions: tailor fields to not inherit from FieldSchema * run yarn build * PR suggestions: remove uneeded fields and fix tests * PR suggestion:rename to isNotSecret * PDE-5719 add helpText back to inputField * update type enums for better fit * apply PR suggestions * apply PR suggestions * remove copy from auth types * add default back to input and output schema * update docs * apply PR suggestions * apply PR suggestions * PR suggestion: use common fields and update schemas * Update packages/schema/lib/functional-constraints/AuthFieldisSafe.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/OutputFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/test/index.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/FieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso * Update packages/schema/lib/schemas/InputFieldSchema.js Co-authored-by: Kola Erinoso * Split FieldSchema into AuthFieldSchema, InputFieldSchema, OutputFieldSchema * add examples/anti-examples back for FieldSchema * Update packages/schema/lib/schemas/AuthFieldSchema.js Co-authored-by: Kola Erinoso --------- Co-authored-by: Kola Erinoso --- packages/cli/src/tests/utils/build.js | 2 +- packages/core/types/zapier.generated.d.ts | 520 +++++++++++----- packages/schema/docs/build/schema.md | 398 ++++++++----- packages/schema/exported-schema.json | 553 ++++++++++++------ .../functional-constraints/AuthFieldisSafe.js | 85 +++ .../lib/functional-constraints/index.js | 1 + .../schema/lib/schemas/AuthFieldSchema.js | 115 ++++ .../schema/lib/schemas/AuthFieldsSchema.js | 67 +++ .../lib/schemas/AuthenticationSchema.js | 6 +- .../lib/schemas/BasicOperationSchema.js | 10 +- .../schema/lib/schemas/DynamicFieldsSchema.js | 36 -- .../lib/schemas/DynamicInputFieldsSchema.js | 20 + .../lib/schemas/DynamicOutputFieldsSchema.js | 20 + .../lib/schemas/FieldOrFunctionSchema.js | 40 -- packages/schema/lib/schemas/FieldSchema.js | 322 ++++------ packages/schema/lib/schemas/FieldsSchema.js | 17 - .../schema/lib/schemas/InputFieldSchema.js | 124 ++++ .../schema/lib/schemas/OutputFieldSchema.js | 81 +++ packages/schema/lib/schemas/ResourceSchema.js | 6 +- packages/schema/test/index.js | 68 ++- 20 files changed, 1721 insertions(+), 770 deletions(-) create mode 100644 packages/schema/lib/functional-constraints/AuthFieldisSafe.js create mode 100644 packages/schema/lib/schemas/AuthFieldSchema.js create mode 100644 packages/schema/lib/schemas/AuthFieldsSchema.js delete mode 100644 packages/schema/lib/schemas/DynamicFieldsSchema.js create mode 100644 packages/schema/lib/schemas/DynamicInputFieldsSchema.js create mode 100644 packages/schema/lib/schemas/DynamicOutputFieldsSchema.js delete mode 100644 packages/schema/lib/schemas/FieldOrFunctionSchema.js delete mode 100644 packages/schema/lib/schemas/FieldsSchema.js create mode 100644 packages/schema/lib/schemas/InputFieldSchema.js create mode 100644 packages/schema/lib/schemas/OutputFieldSchema.js diff --git a/packages/cli/src/tests/utils/build.js b/packages/cli/src/tests/utils/build.js index d908cd7ac..033261551 100644 --- a/packages/cli/src/tests/utils/build.js +++ b/packages/cli/src/tests/utils/build.js @@ -59,7 +59,7 @@ describe('build (runs slowly)', function () { smartPaths.filter((p) => p.endsWith('.ts')).length.should.equal(0); smartPaths.should.not.containEql('tsconfig.json'); - smartPaths.length.should.be.within(200, 301); + smartPaths.length.should.be.within(200, 304); }); it('should list all the files', () => { diff --git a/packages/core/types/zapier.generated.d.ts b/packages/core/types/zapier.generated.d.ts index 094ff5c06..640929075 100644 --- a/packages/core/types/zapier.generated.d.ts +++ b/packages/core/types/zapier.generated.d.ts @@ -135,6 +135,68 @@ export interface App { firehoseWebhooks?: { [k: string]: unknown }; } +/** + * A path to a file that might have content like `module.exports = + * (z, bundle) => [{id: 123}];`. + * + * [Docs: FunctionRequireSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#FunctionRequireSchema) + */ +export interface FunctionRequire { + require: string; +} + +/** + * Source code like `{source: "return 1 + 2"}` which the system will + * wrap in a function for you. + * + * [Docs: FunctionSourceSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#FunctionSourceSchema) + */ +export interface FunctionSource { + /** + * JavaScript code for the function body. This must end with a + * `return` statement. + */ + source: string; + + /** + * Function signature. Defaults to `['z', 'bundle']` if not + * specified. + */ + args?: string[]; +} + +/** + * An object whose values can only be primitives + * + * [Docs: FlatObjectSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#FlatObjectSchema) + */ +export interface FlatObject { + /** + * Any key may exist in this flat object as long as its values are + * simple. + * + * This interface was referenced by `FlatObjectSchema`'s JSON-Schema + * definition + * via the `patternProperty` "[^\s]+". + */ + [k: string]: null | string | number | boolean; +} + +/** + * Internal pointer to a function from the original source or the + * source code itself. Encodes arity and if `arguments` is used in + * the body. Note - just write normal functions and the system will + * encode the pointers for you. Or, provide {source: "return 1 + 2"} + * and the system will wrap in a function for you. + * + * [Docs: FunctionSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#FunctionSchema) + */ +export type Function = + | PerformFunction + | string + | FunctionRequire + | FunctionSource; + /** * An object describing a labeled choice in a static dropdown. * Useful if the value a user picks isn't exactly what the zap uses. @@ -162,14 +224,6 @@ export interface FieldChoiceWithLabel { [k: string]: unknown; } -/** - * Reference a resource by key and the data it returns. In the - * format of: `{resource_key}.{foreign_key}(.{human_label_key})`. - * - * [Docs: RefResourceSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#RefResourceSchema) - */ -export type RefResource = string; - /** * A static dropdown of options. Which you use depends on your order * and label requirements: @@ -188,23 +242,6 @@ export type FieldChoices = | (string | FieldChoiceWithLabel)[]; /** - * Allows for additional metadata to be stored on the field. - * - * [Docs: FieldMetaSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#FieldMetaSchema) - */ -export interface FieldMeta { - /** - * Only string, integer or boolean values are allowed. - * - * This interface was referenced by `FieldMetaSchema`'s JSON-Schema - * definition - * via the `patternProperty` "[^\s]+". - */ - [k: string]: string | number | boolean; -} - -/** - * 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: * @@ -227,12 +264,6 @@ export interface Field { /** A human readable label for this value (IE: "First Name"). */ label?: string; - /** - * A human readable description of this value (IE: "The first part - * of a full name."). You can use Markdown. - */ - helpText?: string; - /** * The type of this value. Use `string` for basic text input, `text` * for a large, `