Skip to content

Commit

Permalink
Merge pull request #757 from zapier/IQQ-814
Browse files Browse the repository at this point in the history
feat(schema): Support "key" in throttle schema and the scope of "action"
  • Loading branch information
kola-er authored Mar 25, 2024
2 parents cd6cfe2 + 49df28b commit f003657
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
14 changes: 12 additions & 2 deletions packages/schema/docs/build/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ Key | Required | Type | Description

## /ThrottleObjectSchema

Zapier uses this configuration to apply throttling when the limit for the window is exceeded.
Zapier uses this configuration to apply throttling when the limit for the window is exceeded. **NOTE:** The final key used for the throttling is formed as a combination of all the configurations; key, window, limit, and scope. To share a limit across multiple actions in an integration, each should have the same configuration set without "action" in the scope.

#### Details

Expand All @@ -2080,14 +2080,24 @@ Key | Required | Type | Description
--- | -------- | ---- | -----------
`window` | **yes** | `integer` | The timeframe, in seconds, within which the system tracks the number of invocations for an action. The number of invocations begins at zero at the start of each window.
`limit` | **yes** | `integer` | The maximum number of invocations for an action, allowed within the timeframe window.
`scope` | no | `array`[`string` in (`'user'`, `'auth'`, `'account'`)] | The granularity to throttle by. You can set the scope to one or more of the following: 'user' - Throttles based on user ids. 'auth' - Throttles based on auth ids. 'account' - Throttles based on account ids for all users under a single account. By default, throttling is scoped to the account.
`key` | no | `string` | The key to throttle with in combination with the scope. User data provided for the input fields can be used in the key with the use of the curly braces referencing. For example, to access the user data provided for the input field "test_field", use `{{bundle.inputData.test_field}}`. Note that a required input field should be referenced to get user data always.
`scope` | no | `array`[`string` in (`'user'`, `'auth'`, `'account'`, `'action'`)] | The granularity to throttle by. You can set the scope to one or more of the following: 'user' - Throttles based on user ids. 'auth' - Throttles based on auth ids. 'account' - Throttles based on account ids for all users under a single account. 'action' - Throttles the action it is set on separately from other actions. By default, throttling is scoped to the action and account.
`overrides` | no | `array`[`object`] | EXPERIMENTAL: Overrides the original throttle configuration based on a Zapier account attribute.

#### Examples

* `{ window: 60, limit: 100 }`
* `{ window: 600, limit: 100, scope: [ 'account', 'user' ] }`
* `{ window: 3600, limit: 10, scope: [ 'auth' ] }`
* `{ window: 3600, limit: 10, key: 'random_key', scope: [] }`
* ```
{
window: 3600,
limit: 10,
key: 'random_key-{{bundle.inputData.test_field}}',
scope: [ 'action', 'auth' ]
}
```
* ```
{
window: 3600,
Expand Down
11 changes: 8 additions & 3 deletions packages/schema/exported-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@
},
"ThrottleObjectSchema": {
"id": "/ThrottleObjectSchema",
"description": "Zapier uses this configuration to apply throttling when the limit for the window is exceeded.",
"description": "Zapier uses this configuration to apply throttling when the limit for the window is exceeded. **NOTE:** The final key used for the throttling is formed as a combination of all the configurations; key, window, limit, and scope. To share a limit across multiple actions in an integration, each should have the same configuration set without \"action\" in the scope.",
"type": "object",
"required": ["window", "limit"],
"properties": {
Expand All @@ -678,11 +678,16 @@
"description": "The maximum number of invocations for an action, allowed within the timeframe window.",
"type": "integer"
},
"key": {
"description": "The key to throttle with in combination with the scope. User data provided for the input fields can be used in the key with the use of the curly braces referencing. For example, to access the user data provided for the input field \"test_field\", use `{{bundle.inputData.test_field}}`. Note that a required input field should be referenced to get user data always.",
"type": "string",
"minLength": 1
},
"scope": {
"description": "The granularity to throttle by. You can set the scope to one or more of the following: 'user' - Throttles based on user ids. 'auth' - Throttles based on auth ids. 'account' - Throttles based on account ids for all users under a single account. By default, throttling is scoped to the account.",
"description": "The granularity to throttle by. You can set the scope to one or more of the following: 'user' - Throttles based on user ids. 'auth' - Throttles based on auth ids. 'account' - Throttles based on account ids for all users under a single account. 'action' - Throttles the action it is set on separately from other actions. By default, throttling is scoped to the action and account.",
"type": "array",
"items": {
"enum": ["user", "auth", "account"],
"enum": ["user", "auth", "account", "action"],
"type": "string"
}
},
Expand Down
24 changes: 21 additions & 3 deletions packages/schema/lib/schemas/ThrottleObjectSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const makeSchema = require('../utils/makeSchema');
module.exports = makeSchema({
id: '/ThrottleObjectSchema',
description:
'Zapier uses this configuration to apply throttling when the limit for the window is exceeded.',
'Zapier uses this configuration to apply throttling when the limit for the window is exceeded. **NOTE:** The final key used for the throttling is formed as a combination of all the configurations; key, window, limit, and scope. To share a limit across multiple actions in an integration, each should have the same configuration set without "action" in the scope.',
type: 'object',
required: ['window', 'limit'],
properties: {
Expand All @@ -19,11 +19,17 @@ module.exports = makeSchema({
'The maximum number of invocations for an action, allowed within the timeframe window.',
type: 'integer',
},
key: {
description:
'The key to throttle with in combination with the scope. User data provided for the input fields can be used in the key with the use of the curly braces referencing. For example, to access the user data provided for the input field "test_field", use `{{bundle.inputData.test_field}}`. Note that a required input field should be referenced to get user data always.',
type: 'string',
minLength: 1,
},
scope: {
description: `The granularity to throttle by. You can set the scope to one or more of the following: 'user' - Throttles based on user ids. 'auth' - Throttles based on auth ids. 'account' - Throttles based on account ids for all users under a single account. By default, throttling is scoped to the account.`,
description: `The granularity to throttle by. You can set the scope to one or more of the following: 'user' - Throttles based on user ids. 'auth' - Throttles based on auth ids. 'account' - Throttles based on account ids for all users under a single account. 'action' - Throttles the action it is set on separately from other actions. By default, throttling is scoped to the action and account.`,
type: 'array',
items: {
enum: ['user', 'auth', 'account'],
enum: ['user', 'auth', 'account', 'action'],
type: 'string',
},
},
Expand Down Expand Up @@ -66,6 +72,18 @@ module.exports = makeSchema({
limit: 10,
scope: ['auth'],
},
{
window: 3600,
limit: 10,
key: 'random_key',
scope: [], // this ensures neither the default nor any of the scope options is used
},
{
window: 3600,
limit: 10,
key: 'random_key-{{bundle.inputData.test_field}}',
scope: ['action', 'auth'],
},
{
window: 3600,
limit: 10,
Expand Down

0 comments on commit f003657

Please sign in to comment.