quota

Configuration of the quota manager used for this component. Quotas allow you to throttle the firing of your component. This is especially useful and many times even necessary to make sure you don't go over the limits of the usage of the API that you call in your components. Quota managers are defined in the quota.js file of your service/module. Example:

{
     "quota": {
        "manager": "pipedrive",
        "resources": "requests",
        "scope": {
            "userId": "{{userId}}"
        }
    }
}

Dynamic values

The {{}} can be used in any property within the quota definition. And values from two objects - the user's metadata, and the account's profileInfo can be used there. The following example shows how to dynamically select a resource based on the value of user's metadata.tier .

{
     "quota": {
        "manager": "your-service",
        // Before the quota request is created, the system will check the user's
        // metadata.tier value. If set, it will be used as a 'resources' value.
        // If not, the value 'basic' will be used.
        "resources": "{{userMetadata.tier || 'basic'}}",
        "scope": {
            "userId": "{{userId}}"
        }
    }
}

The quota.js file with the rules for the previous example could look like this:

module.exports = {
    rules: [
        {
            name: 'basic-tier',
            limit: 10,          // 10 requests per minute
            window: 1000 * 60,  // 1 minute
            throttling: 'window-sliding',
            queueing: 'fifo',
            resource: 'basic',  // the 'basic' resource
            scope: 'userId'
        },
        {

            name: 'paid-tier',
            limit: 100,         // or 100 requests per minute
            window: 1000 * 60,  // 1 minute
            throttling: 'window-sliding',
            queueing: 'fifo',
            resource: 'paid',   // the 'paid' resource
            scope: 'userId'
        }
    ]
};

The other object that can be used here, is the profileInfo.

{
     "quota": {
        "manager": "your-service",
        // Before the quota request is created, the system will check the user's
        // account profileInfo.tier value. If set, it will be used as a 'resources' value.
        // If not, the value 'basic' will be used.
        "resources": "{{profileInfo.tier || 'basic'}}",
        "scope": {
            "userId": "{{userId}}"
        }
    }
}

quota.manager

The name of the quota module where usage limit rules are defined.

quota.resources

One or more resources that identify rules from the quota module that apply to this component. Each rule in the quota module can have the resource property. quota.resources allow you to cherry-pick rules from the list of rules in the quota module that apply to this component. quota.resources can either be a string or an array of strings.

Dynamic values. Sometimes different users have different quotas for the same service.

quota.scope

This scope instructs the quota manager to count calls either for the whole application (service) or per-user. Currently, it can either be omitted in which case the quota limits for this component apply to the whole application or it can be { "userId": "{{userId}}" } in which case the quota limits are counted per Appmixer user.

Last updated

Was this helpful?