Rocky_Mountain_Vending/.pnpm-store/v10/files/4e/fff3ea151e03fde56ad6ccfccc6748d419b0809bcf2355c3f9243147d08187ae35a400493b8c5c2ba7da4c72203b34afc260e2b095439778199811e2b00c94
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

54 lines
1.7 KiB
Text

// src/workers/ratelimit/ratelimit.worker.ts
var RatelimitOptionKeys = ["key", "limit", "period"], RatelimitPeriodValues = [10, 60];
function validate(test, message) {
if (!test)
throw new Error(message);
}
var Ratelimit = class {
namespaceId;
limitVal;
period;
buckets;
epoch;
constructor(config) {
this.namespaceId = config.namespaceId, this.limitVal = config.limit, this.period = config.period, this.buckets = /* @__PURE__ */ new Map(), this.epoch = 0;
}
// method that counts and checks against the limit in in-memory buckets
async limit(options) {
validate(
typeof options == "object" && options !== null,
"invalid rate limit options"
);
let invalidProps = Object.keys(options ?? {}).filter(
(key2) => !RatelimitOptionKeys.includes(key2)
);
validate(
invalidProps.length == 0,
`bad rate limit options: [${invalidProps.join(",")}]`
);
let {
key = "",
limit = this.limitVal,
period = this.period
} = options;
validate(typeof key == "string", `invalid key: ${key}`), validate(typeof limit == "number", `limit must be a number: ${limit}`), validate(typeof period == "number", `period must be a number: ${period}`), validate(
RatelimitPeriodValues.includes(period),
`unsupported period: ${period}`
);
let epoch = Math.floor(Date.now() / (period * 1e3));
epoch != this.epoch && (this.epoch = epoch, this.buckets.clear());
let val = this.buckets.get(key) || 0;
return val >= limit ? {
success: !1
} : (this.buckets.set(key, val + 1), {
success: !0
});
}
};
function ratelimit_worker_default(env) {
return new Ratelimit(env);
}
export {
ratelimit_worker_default as default
};
//# sourceMappingURL=ratelimit.worker.js.map