Skip to main content

Processing Quotas

Quotas are managed using ductape.processor.quota.run(data) within the Ductape system. This processor allows you to enforce, check, and update usage quotas for products or features.

await ductape.processor.quota.run(data: IQuotaProcessorInput)

This processes a quota event in the specified environment and application context, handling quota checks, increments, or resets.

Parameters

IQuotaProcessorInput

FieldTypeRequiredDescription
envstringYesEnvironment slug (e.g., "dev", "prd").
product_tagstringYesUnique identifier for the product.
quota_tagstringYesTag of the quota to check or update.
actionstringYesAction to perform: "check", "increment", or "reset".
amountnumberNoAmount to increment (for increment action).
sessionISessionNoAttach user session context to the request.
cachestringNoCache tag to cache this request, if applicable.

Note: Optional fields can be omitted or passed as empty {}.

ISession Schema

The session field enables optional session tracking for any quota operation.

interface ISession {
tag: string; // session tag
token: string; // session token (e.g. signed JWT)
}
FieldTypeRequiredDescription
tagstringYesTag identifying the session type.
tokenstringYesToken generated when the session was created.

Returns

Returns a Promise<unknown> resolving with the result of the quota operation. The exact structure depends on the specific quota action.

Example

const data = {
env: "prd",
product_tag: "my-product",
quota_tag: "api-requests",
action: "increment",
amount: 1,
session: {
tag: "user-session",
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
},
cache: "quota-api-requests"
};

const res = await ductape.processor.quota.run(data);

See Also