docs(config): align rate limit settings

This commit is contained in:
root 2026-03-15 09:42:42 +00:00
parent e4bff5a2fe
commit d93ada4037
4 changed files with 20 additions and 1 deletions

View File

@ -14,6 +14,10 @@ COSMOS_DATABASE=lysnrai
# ── Auth (platform-service) ─────────────────────────
JWT_SECRET=change-me-prototype-jwt-secret
RATE_LIMIT_STORE_MODE=datastore
RATE_LIMIT_CONFIG_JSON=
API_KEY_RATE_LIMIT_CONFIG_JSON=
API_KEY_PRODUCT_RATE_LIMIT_CONFIG_JSON=
# ── Azure Blob Storage (platform-service) ─────────────────────
STORAGE_PROVIDER=azure

View File

@ -34,6 +34,15 @@ describe('lib/config', () => {
vi.stubEnv('NODE_ENV', 'test');
vi.stubEnv('SERVICE_NAME', 'platform-service-test');
vi.stubEnv('USAGE_WARN_THRESHOLD', '0.9');
vi.stubEnv('RATE_LIMIT_STORE_MODE', 'memory');
vi.stubEnv(
'API_KEY_RATE_LIMIT_CONFIG_JSON',
'{"jobs:read":{"maxRequests":10,"windowSeconds":60}}'
);
vi.stubEnv(
'API_KEY_PRODUCT_RATE_LIMIT_CONFIG_JSON',
'{"jobs:read":{"maxRequests":20,"windowSeconds":60}}'
);
const { config } = await import('./config.js');
@ -41,6 +50,9 @@ describe('lib/config', () => {
expect(config.NODE_ENV).toBe('test');
expect(config.SERVICE_NAME).toBe('platform-service-test');
expect(config.USAGE_WARN_THRESHOLD).toBe(0.9);
expect(config.RATE_LIMIT_STORE_MODE).toBe('memory');
expect(config.API_KEY_RATE_LIMIT_CONFIG_JSON).toContain('"jobs:read"');
expect(config.API_KEY_PRODUCT_RATE_LIMIT_CONFIG_JSON).toContain('"jobs:read"');
});
it('throws when required env vars are missing', async () => {

View File

@ -14,6 +14,9 @@ const envSchema = z.object({
AZURE_BLOB_ACCOUNT_NAME: z.string().optional(),
AZURE_BLOB_ACCOUNT_KEY: z.string().optional(),
RATE_LIMIT_CONFIG_JSON: z.string().optional(),
RATE_LIMIT_STORE_MODE: z.enum(['datastore', 'memory']).default('datastore'),
API_KEY_RATE_LIMIT_CONFIG_JSON: z.string().optional(),
API_KEY_PRODUCT_RATE_LIMIT_CONFIG_JSON: z.string().optional(),
// ── Growth (merged) ──
WEBHOOK_INVITATION_REDEEMED_URL: z.string().optional(),
WEBHOOK_REFERRAL_STATUS_URL: z.string().optional(),

View File

@ -1,7 +1,7 @@
/**
* Rate limiting types sliding window limiter with per-product config.
*
* Storage: in-memory Map (default) or Redis-backed (when REDIS_URL is set).
* Storage: datastore-backed by default, or in-memory when RATE_LIMIT_STORE_MODE=memory.
* Config: per-product rate limit rules loaded from RATE_LIMIT_CONFIG_JSON env
* or defaults to sensible values.
*/