@cosmicdrift/kumiko-samples 0.372.0 → 0.373.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-samples",
3
- "version": "0.372.0",
3
+ "version": "0.373.0",
4
4
  "description": "Source trees of the Kumiko sample recipes, sample apps and bundled features in repo layout, for tooling such as few-shot corpus builds.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-bundled-features",
3
- "version": "0.372.0",
3
+ "version": "0.373.0",
4
4
  "description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -5,8 +5,29 @@ End-to-end rate limiting: L1 global-IP + L2 auth + L3 handler opt-in.
5
5
  ## What it shows
6
6
 
7
7
  - Handler `rateLimit: { per, limit, windowSeconds }`
8
+ - Several buckets on one handler: `rateLimit: [{ per: "user", ... }, { per: "tenant+handler", ... }]`
8
9
  - How L1/L2 from `buildServer` stack with L3
9
10
 
11
+ ## Combined buckets
12
+
13
+ Pass a list to enforce several budgets on one handler, for example a per-caller and a per-tenant cap:
14
+
15
+ ```ts illustration
16
+ r.writeHandler({
17
+ // ...
18
+ rateLimit: [
19
+ { per: "user", limit: 2, windowSeconds: 3600 },
20
+ { per: "tenant+handler", limit: 3, windowSeconds: 3600 },
21
+ ],
22
+ });
23
+ ```
24
+
25
+ Each bucket applies on its own. The check is all-or-nothing: if any bucket is exhausted the call
26
+ answers 429 `rate_limited` for that bucket (the one with the longest wait when several are
27
+ exhausted) and no bucket is charged. Each `per` may appear once; an empty list fails at boot.
28
+ An anonymous handler needs every bucket to be ip-keyed, and `{ disabled: true, reason }`
29
+ stays a single declaration.
30
+
10
31
  ## Per-payload limits
11
32
 
12
33
  A public write handler that mails an address typed by the caller is also limited per
@@ -20,5 +20,18 @@ export function createRateLimitShowcaseFeature(): FeatureDefinition {
20
20
  access: { roles: ["Admin", "User"] },
21
21
  rateLimit: { per: "user", limit: 3, windowSeconds: 60 },
22
22
  });
23
+
24
+ // Combined budget: each caller gets 2 submits per hour and the tenant 3 per hour in
25
+ // total. Both buckets are checked together; a request one bucket rejects charges neither.
26
+ r.writeHandler({
27
+ name: "submit-report",
28
+ schema: z.object({}),
29
+ handler: async () => ({ isSuccess: true as const, data: {} }),
30
+ access: { roles: ["Admin", "User"] },
31
+ rateLimit: [
32
+ { per: "user", limit: 2, windowSeconds: 3600 },
33
+ { per: "tenant+handler", limit: 3, windowSeconds: 3600 },
34
+ ],
35
+ });
23
36
  });
24
37
  }