Skip to content

Commit

Permalink
Split FieldSchema into AuthFieldSchema, InputFieldSchema, OutputField…
Browse files Browse the repository at this point in the history
…Schema
  • Loading branch information
Natay committed Feb 4, 2025
1 parent ca8c94f commit 58ceac2
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 128 deletions.
67 changes: 50 additions & 17 deletions packages/core/types/zapier.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export type FieldChoices =
| (string | FieldChoiceWithLabel)[];

/**
* 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:
*
Expand Down Expand Up @@ -314,7 +313,19 @@ export interface Field {
}

/**
* Field schema specialized for authentication fields.
* Field schema specialized for authentication fields. In addition
* to the requirements below, the following keys are mutually
* exclusive:
*
* * `children` & `list`
* * `children` & `dict`
* * `children` & `type`
* * `children` & `placeholder`
* * `children` & `helpText`
* * `children` & `default`
* * `dict` & `list`
* * `dynamic` & `dict`
* * `dynamic` & `choices`
*
* [Docs: AuthFieldSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#AuthFieldSchema)
*/
Expand All @@ -328,7 +339,7 @@ export interface AuthField {
/** The type of this value used to be. */
type?: 'string' | 'number' | 'boolean' | 'datetime' | 'password';

/** If this value is required or not. */
/** If this value is required or not. This defaults to `true`. */
required?: boolean;

/**
Expand Down Expand Up @@ -356,10 +367,13 @@ export interface AuthField {
dict?: boolean;

/**
* Indicates if this authentication field is safe to e.g. be stored
* without encryption or displayed (not a secret).
* A human readable description of this value (IE: "The first part
* of a full name."). You can use Markdown.
*/
isNoSecret?: boolean;
helpText?: string;

/** An example value that is not saved. */
placeholder?: string;

/**
* An object of machine keys and human values to populate a static
Expand All @@ -373,21 +387,18 @@ export interface AuthField {
*/
computed?: boolean;

/**
* A human readable description of this value (IE: "The first part
* of a full name."). You can use Markdown.
*/
helpText?: string;

/** An example value that is not saved. */
placeholder?: string;

/**
* Useful when you expect the input to be part of a longer string.
* Put "{{input}}" in place of the user's input (IE:
* "https://{{input}}.yourdomain.com").
*/
inputFormat?: string;

/**
* Indicates if this authentication field is safe to e.g. be stored
* without encryption or displayed (not a secret).
*/
isNoSecret?: boolean;
[k: string]: unknown;
}

Expand Down Expand Up @@ -628,7 +639,18 @@ export interface FieldMeta {
}

/**
* Field schema specialized for input fields.
* Field schema specialized for input fields. In addition to the
* requirements below, the following keys are mutually exclusive:
*
* * `children` & `list`
* * `children` & `dict`
* * `children` & `type`
* * `children` & `placeholder`
* * `children` & `helpText`
* * `children` & `default`
* * `dict` & `list`
* * `dynamic` & `dict`
* * `dynamic` & `choices`
*
* [Docs: InputFieldSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#InputFieldSchema)
*/
Expand Down Expand Up @@ -733,7 +755,18 @@ export interface InputField {
}

/**
* Field schema specialized for output fields.
* Field schema specialized for output fields. In addition to the
* requirements below, the following keys are mutually exclusive:
*
* * `children` & `list`
* * `children` & `dict`
* * `children` & `type`
* * `children` & `placeholder`
* * `children` & `helpText`
* * `children` & `default`
* * `dict` & `list`
* * `dynamic` & `dict`
* * `dynamic` & `choices`
*
* [Docs: OutputFieldSchema](https://github.com/zapier/zapier-platform/blob/main/packages/schema/docs/build/schema.md#OutputFieldSchema)
*/
Expand Down
48 changes: 39 additions & 9 deletions packages/schema/docs/build/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ Key | Required | Type | Description

## /AuthFieldSchema

Field schema specialized for authentication fields.
Field schema specialized for authentication fields. In addition to the requirements below, the following keys are mutually exclusive:

* `children` & `list`
* `children` & `dict`
* `children` & `type`
* `children` & `placeholder`
* `children` & `helpText`
* `children` & `default`
* `dict` & `list`
* `dynamic` & `dict`
* `dynamic` & `choices`

#### Details

Expand All @@ -163,17 +173,17 @@ Key | Required | Type | Description
`key` | **yes** | `string` | A unique machine readable key for this value (IE: "fname").
`label` | no | `string` | A human readable label for this value (IE: "First Name").
`type` | no | `string` in (`'string'`, `'number'`, `'boolean'`, `'datetime'`, `'password'`) | The type of this value used to be.
`required` | no | `boolean` | If this value is required or not.
`required` | no | `boolean` | If this value is required or not. This defaults to `true`.
`default` | no | `string` | A default value that is saved the first time a Zap is created.
`list` | no | `boolean` | Acts differently when used in inputFields vs. when used in outputFields. In inputFields: Can a user provide multiples of this field? In outputFields: Does this field return an array of items of type `type`?
`children` | no | `array`[undefined] | An array of child fields that define the structure of a sub-object for this field. Usually used for line items.
`dict` | no | `boolean` | Is this field a key/value input?
`isNoSecret` | no | `boolean` | Indicates if this authentication field is safe to e.g. be stored without encryption or displayed (not a secret).
`choices` | no | [/FieldChoicesSchema](#fieldchoicesschema) | An object of machine keys and human values to populate a static dropdown.
`computed` | no | `boolean` | Is this field automatically populated (and hidden from the user)? Note: Only OAuth and Session Auth support fields with this key.
`helpText` | no | `string` | A human readable description of this value (IE: "The first part of a full name."). You can use Markdown.
`placeholder` | no | `string` | An example value that is not saved.
`choices` | no | [/FieldChoicesSchema](#fieldchoicesschema) | An object of machine keys and human values to populate a static dropdown.
`computed` | no | `boolean` | Is this field automatically populated (and hidden from the user)? Note: Only OAuth and Session Auth support fields with this key.
`inputFormat` | no | `string` | Useful when you expect the input to be part of a longer string. Put "{{input}}" in place of the user's input (IE: "https://{{input}}.yourdomain.com").
`isNoSecret` | no | `boolean` | Indicates if this authentication field is safe to e.g. be stored without encryption or displayed (not a secret).

#### Examples

Expand All @@ -183,8 +193,8 @@ Key | Required | Type | Description

#### Anti-Examples

* `{ key: 'password', type: 'password', isNoSecret: true, required: true }` - _A "password" field cannot have isSafe = true._
* `{ key: 'api_key', isNoSecret: true }` - _"api_key" is a sensitive field and cannot have isSafe set as true._
* `{ key: 'password', type: 'password', isNoSecret: true, required: true }` - _"password" is a sensitive field and cannot have isNoSecret set as true._
* `{ key: 'api_key', isNoSecret: true }` - _"api_key" is a sensitive field and cannot have isNoSecret set as true._
* `{ type: 'string', isNoSecret: false }` - _Missing required key: key_

-----
Expand Down Expand Up @@ -1192,7 +1202,17 @@ Key | Required | Type | Description

## /InputFieldSchema

Field schema specialized for input fields.
Field schema specialized for input fields. In addition to the requirements below, the following keys are mutually exclusive:

* `children` & `list`
* `children` & `dict`
* `children` & `type`
* `children` & `placeholder`
* `children` & `helpText`
* `children` & `default`
* `dict` & `list`
* `dynamic` & `dict`
* `dynamic` & `choices`

#### Details

Expand Down Expand Up @@ -1328,7 +1348,17 @@ List of before or after middlewares. Can be an array of functions or a single fu

## /OutputFieldSchema

Field schema specialized for output fields.
Field schema specialized for output fields. In addition to the requirements below, the following keys are mutually exclusive:

* `children` & `list`
* `children` & `dict`
* `children` & `type`
* `children` & `placeholder`
* `children` & `helpText`
* `children` & `default`
* `dict` & `list`
* `dynamic` & `dict`
* `dynamic` & `choices`

#### Details

Expand Down
34 changes: 17 additions & 17 deletions packages/schema/exported-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
},
"FieldSchema": {
"id": "/FieldSchema",
"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* `children` & `list`\n* `children` & `dict`\n* `children` & `type`\n* `children` & `placeholder`\n* `children` & `helpText`\n* `children` & `default`\n* `dict` & `list`\n* `dynamic` & `dict`\n* `dynamic` & `choices`",
"description": "In addition to the requirements below, the following keys are mutually exclusive:\n\n* `children` & `list`\n* `children` & `dict`\n* `children` & `type`\n* `children` & `placeholder`\n* `children` & `helpText`\n* `children` & `default`\n* `dict` & `list`\n* `dynamic` & `dict`\n* `dynamic` & `choices`",
"type": "object",
"required": ["key"],
"docAnnotation": {
Expand Down Expand Up @@ -285,7 +285,7 @@
},
"AuthFieldSchema": {
"id": "/AuthFieldSchema",
"description": "Field schema specialized for authentication fields.",
"description": "Field schema specialized for authentication fields. In addition to the requirements below, the following keys are mutually exclusive:\n\n* `children` & `list`\n* `children` & `dict`\n* `children` & `type`\n* `children` & `placeholder`\n* `children` & `helpText`\n* `children` & `default`\n* `dict` & `list`\n* `dynamic` & `dict`\n* `dynamic` & `choices`",
"required": ["key"],
"type": "object",
"properties": {
Expand All @@ -305,7 +305,7 @@
"enum": ["string", "number", "boolean", "datetime", "password"]
},
"required": {
"description": "If this value is required or not.",
"description": "If this value is required or not. This defaults to `true`.",
"type": "boolean"
},
"default": {
Expand All @@ -329,18 +329,6 @@
"description": "Is this field a key/value input?",
"type": "boolean"
},
"isNoSecret": {
"description": "Indicates if this authentication field is safe to e.g. be stored without encryption or displayed (not a secret).",
"type": "boolean"
},
"choices": {
"description": "An object of machine keys and human values to populate a static dropdown.",
"$ref": "/FieldChoicesSchema"
},
"computed": {
"description": "Is this field automatically populated (and hidden from the user)? Note: Only OAuth and Session Auth support fields with this key.",
"type": "boolean"
},
"helpText": {
"description": "A human readable description of this value (IE: \"The first part of a full name.\"). You can use Markdown.",
"type": "string",
Expand All @@ -352,10 +340,22 @@
"type": "string",
"minLength": 1
},
"choices": {
"description": "An object of machine keys and human values to populate a static dropdown.",
"$ref": "/FieldChoicesSchema"
},
"computed": {
"description": "Is this field automatically populated (and hidden from the user)? Note: Only OAuth and Session Auth support fields with this key.",
"type": "boolean"
},
"inputFormat": {
"description": "Useful when you expect the input to be part of a longer string. Put \"{{input}}\" in place of the user's input (IE: \"https://{{input}}.yourdomain.com\").",
"type": "string",
"pattern": "^.*{{input}}.*$"
},
"isNoSecret": {
"description": "Indicates if this authentication field is safe to e.g. be stored without encryption or displayed (not a secret).",
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -663,7 +663,7 @@
}
},
"InputFieldSchema": {
"description": "Field schema specialized for input fields.",
"description": "Field schema specialized for input fields. In addition to the requirements below, the following keys are mutually exclusive:\n\n* `children` & `list`\n* `children` & `dict`\n* `children` & `type`\n* `children` & `placeholder`\n* `children` & `helpText`\n* `children` & `default`\n* `dict` & `list`\n* `dynamic` & `dict`\n* `dynamic` & `choices`",
"id": "/InputFieldSchema",
"type": "object",
"required": ["key"],
Expand Down Expand Up @@ -759,7 +759,7 @@
"additionalProperties": false
},
"OutputFieldSchema": {
"description": "Field schema specialized for output fields.",
"description": "Field schema specialized for output fields. In addition to the requirements below, the following keys are mutually exclusive:\n\n* `children` & `list`\n* `children` & `dict`\n* `children` & `type`\n* `children` & `placeholder`\n* `children` & `helpText`\n* `children` & `default`\n* `dict` & `list`\n* `dynamic` & `dict`\n* `dynamic` & `choices`",
"id": "/OutputFieldSchema",
"type": "object",
"required": ["key"],
Expand Down
10 changes: 7 additions & 3 deletions packages/schema/lib/functional-constraints/AuthFieldisSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const AUTH_FIELDS_ID = '/AuthFieldsSchema';

const FORBIDDEN_KEYS = [
'access_token',
'access-token',
'accesstoken',
'api_key',
'apikey',
'api-key',
Expand All @@ -16,16 +18,18 @@ const FORBIDDEN_KEYS = [
'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),
);
FORBIDDEN_KEYS.some((forbidden) => key.toLowerCase().includes(forbidden));

const checkAuthField = (field) => {
const errors = [];
Expand Down
Loading

0 comments on commit 58ceac2

Please sign in to comment.