Skip to content

Commit

Permalink
IQQ-814 Add support for throttling across actions and "key" field
Browse files Browse the repository at this point in the history
  • Loading branch information
kola-er committed Mar 21, 2024
1 parent a68b069 commit eb58f66
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
12 changes: 11 additions & 1 deletion packages/schema/docs/build/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. This should be unique to the operation. While actions of different integrations with the same key and scope will never share the same limit, actions of the same integration with the same key and scope will do when "action" is not in 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
9 changes: 7 additions & 2 deletions packages/schema/exported-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. This should be unique to the operation. While actions of different integrations with the same key and scope will never share the same limit, actions of the same integration with the same key and scope will do when \"action\" is not in 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
22 changes: 20 additions & 2 deletions packages/schema/lib/schemas/ThrottleObjectSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. This should be unique to the operation. While actions of different integrations with the same key and scope will never share the same limit, actions of the same integration with the same key and scope will do when "action" is not in 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 eb58f66

Please sign in to comment.