export class RateLimitExceededError extends Error {
    retryAfterMs;
    constructor(retryAfterMs) {
        super("Rate limit exceeded.");
        this.retryAfterMs = retryAfterMs;
        this.name = "RateLimitExceededError";
    }
}
export class MemoryRateLimiter {
    buckets = new Map();
    consume(key, rule, now = Date.now()) {
        const bucket = this.buckets.get(key);
        if (!bucket || bucket.resetAt <= now) {
            this.buckets.set(key, { tokens: rule.limit - 1, resetAt: now + rule.windowMs });
            return;
        }
        if (bucket.tokens <= 0) {
            throw new RateLimitExceededError(bucket.resetAt - now);
        }
        bucket.tokens -= 1;
    }
}
export const STUDIO_RATE_LIMITS = {
    login: { limit: 5, windowMs: 10 * 60 * 1000 },
    changePassword: { limit: 5, windowMs: 10 * 60 * 1000 },
    createJob: { limit: 10, windowMs: 60 * 60 * 1000 },
    api: { limit: 300, windowMs: 60 * 1000 },
};
//# sourceMappingURL=rate-limit.js.map