@classytic/arc 2.20.0 → 2.22.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.
Files changed (143) hide show
  1. package/dist/{BaseController-D-MHZ27_.mjs → BaseController-C6FlRWxF.mjs} +2 -2
  2. package/dist/{EventTransport-IEn7Tn-Q.d.mts → EventTransport-QmY7A258.d.mts} +0 -1
  3. package/dist/{QueryCache-TRfXau3W.d.mts → QueryCache-Z1B38koh.d.mts} +0 -1
  4. package/dist/{actionPermissions-C9RMiIpc.mjs → actionPermissions-ze70xXJi.mjs} +1 -1
  5. package/dist/audit/index.d.mts +9 -5
  6. package/dist/auth/audit.d.mts +7 -4
  7. package/dist/auth/audit.mjs +5 -0
  8. package/dist/auth/index.d.mts +35 -14
  9. package/dist/auth/index.mjs +6 -3
  10. package/dist/auth/redis-session.d.mts +1 -2
  11. package/dist/cache/index.d.mts +2 -3
  12. package/dist/cli/commands/describe.d.mts +1 -2
  13. package/dist/cli/commands/docs.mjs +1 -1
  14. package/dist/cli/commands/init.mjs +1 -1
  15. package/dist/cli/index.mjs +1 -1
  16. package/dist/context/index.d.mts +2 -2
  17. package/dist/core/index.d.mts +3 -3
  18. package/dist/core/index.mjs +4 -4
  19. package/dist/{core-CWhyGkiM.mjs → core-b6fgFgnd.mjs} +129 -17
  20. package/dist/{createActionRouter-HlQso0jO.mjs → createActionRouter-h1cEEaEX.mjs} +10 -6
  21. package/dist/{createAggregationRouter-5LzPzgw1.mjs → createAggregationRouter-B1C0kvTL.mjs} +3 -3
  22. package/dist/{createApp-D6uwzCKu.mjs → createApp-Ci7yG5gv.mjs} +390 -192
  23. package/dist/discovery/index.d.mts +0 -1
  24. package/dist/docs/index.d.mts +1 -2
  25. package/dist/docs/index.mjs +1 -1
  26. package/dist/{elevation-xGUBq6p_.d.mts → elevation-C9s5hFP_.d.mts} +0 -1
  27. package/dist/encryption/index.d.mts +2 -144
  28. package/dist/encryption/index.mjs +9 -5
  29. package/dist/{errorHandler-Dxf6P_kV.mjs → errorHandler-BTzXSwIg.mjs} +24 -3
  30. package/dist/{errorHandler-BtUUDPEa.d.mts → errorHandler-C6yv4ZTW.d.mts} +13 -1
  31. package/dist/{errors-DOHkjQlD.d.mts → errors-DHcHVAgk.d.mts} +0 -1
  32. package/dist/{eventPlugin-DbBFd3x_.d.mts → eventPlugin-A6EbthXR.d.mts} +10 -6
  33. package/dist/events/index.d.mts +9 -6
  34. package/dist/events/transports/redis-stream-entry.d.mts +1 -1
  35. package/dist/events/transports/redis.d.mts +1 -2
  36. package/dist/factory/index.d.mts +30 -9
  37. package/dist/factory/index.mjs +35 -4
  38. package/dist/{fastify-augmentation-CCQJEDgh.d.mts → fastify-augmentation-9_fuetB4.d.mts} +2 -3
  39. package/dist/fields-D3lhgzhD.d.mts +121 -0
  40. package/dist/health-ScyjIVo5.mjs +202 -0
  41. package/dist/hooks/index.d.mts +1 -1
  42. package/dist/idempotency/index.d.mts +4 -3
  43. package/dist/idempotency/index.mjs +2 -0
  44. package/dist/idempotency/redis.d.mts +1 -1
  45. package/dist/{types-BHMKlMBU.d.mts → index-BEu4wjbL.d.mts} +241 -80
  46. package/dist/{index-DUa8WHz3.d.mts → index-D8MKYGDa.d.mts} +88 -7
  47. package/dist/{index-_--GyzcO.d.mts → index-DbtgCOCj.d.mts} +1324 -1228
  48. package/dist/{index-CdFkIMEd.d.mts → index-ogIHvOjo.d.mts} +36 -7
  49. package/dist/index.d.mts +8 -7
  50. package/dist/index.mjs +6 -6
  51. package/dist/{init-YH_nslQR.mjs → init-DleK3p9f.mjs} +272 -139
  52. package/dist/integrations/event-gateway.d.mts +2 -3
  53. package/dist/integrations/index.d.mts +2 -2
  54. package/dist/integrations/jobs.d.mts +0 -1
  55. package/dist/integrations/mcp/index.d.mts +6 -7
  56. package/dist/integrations/mcp/index.mjs +1 -1
  57. package/dist/integrations/mcp/testing.d.mts +1 -2
  58. package/dist/integrations/mcp/testing.mjs +1 -1
  59. package/dist/integrations/streamline.d.mts +2 -2
  60. package/dist/integrations/webhooks.d.mts +8 -5
  61. package/dist/integrations/webhooks.mjs +9 -5
  62. package/dist/integrations/websocket-pushref-redis.d.mts +1 -2
  63. package/dist/integrations/websocket-redis.d.mts +1 -2
  64. package/dist/integrations/websocket.d.mts +2 -2
  65. package/dist/jsonBody-BlzAoGCe.mjs +43 -0
  66. package/dist/{loadResources-B8UmpITt.mjs → loadResources-DpU8pfjV.mjs} +4 -3
  67. package/dist/logger/index.d.mts +26 -1
  68. package/dist/logger/index.mjs +39 -1
  69. package/dist/{mcpPlugin-CuW6L_uD.mjs → mcpPlugin-ByA2tf6D.mjs} +8 -4
  70. package/dist/middleware/index.d.mts +1 -2
  71. package/dist/{module-JYH9V0I8.d.mts → module-B4u10iOJ.d.mts} +71 -1
  72. package/dist/{openapi-Dq6RbEGK.mjs → openapi-BRpMZD7C.mjs} +3 -3
  73. package/dist/permissions/index.d.mts +4 -3
  74. package/dist/permissions/index.mjs +2 -2
  75. package/dist/{permissions-CgbOLJZG.mjs → permissions-BJMuKMl7.mjs} +33 -1
  76. package/dist/pipeline/index.d.mts +1 -2
  77. package/dist/plugins/index.d.mts +96 -7
  78. package/dist/plugins/index.mjs +86 -268
  79. package/dist/plugins/response-cache.d.mts +5 -3
  80. package/dist/plugins/response-cache.mjs +1 -0
  81. package/dist/plugins/tracing-entry.d.mts +1 -1
  82. package/dist/plugins/tracing-entry.mjs +7 -4
  83. package/dist/presets/filesUpload.d.mts +4 -5
  84. package/dist/presets/filesUpload.mjs +1 -1
  85. package/dist/presets/index.d.mts +1 -2
  86. package/dist/presets/index.mjs +1 -1
  87. package/dist/presets/multiTenant.d.mts +1 -2
  88. package/dist/presets/search.d.mts +2 -3
  89. package/dist/presets/search.mjs +1 -1
  90. package/dist/{presets-DWsYQdbV.mjs → presets-gw0ciIUD.mjs} +1 -1
  91. package/dist/{pushref-registry-DnCqL3aa.d.mts → pushref-registry-BbcnpNTm.d.mts} +4 -2
  92. package/dist/{queryCachePlugin-xzFyKAjT.d.mts → queryCachePlugin-CfYWq-Ak.d.mts} +1 -2
  93. package/dist/rateLimitKey-BoWRH3e7.mjs +14 -0
  94. package/dist/{redis-C3W0qbz8.d.mts → redis-UDtLaNj6.d.mts} +0 -1
  95. package/dist/{redis-stream-DsP1vqZB.d.mts → redis-stream-iVR2l7aS.d.mts} +1 -2
  96. package/dist/{registerRoute-DGSREwPw.mjs → registerRoute-xHc42fwB.mjs} +38 -18
  97. package/dist/registry/index.d.mts +2 -2
  98. package/dist/requestId-5BhTVzBv.mjs +113 -0
  99. package/dist/schemaConverter-Ds5reSGs.mjs +168 -0
  100. package/dist/{schemaIR-ajetw3Fv.mjs → schemaIR-B-6SPe7g.mjs} +2 -2
  101. package/dist/schemas/index.d.mts +0 -1
  102. package/dist/scim/index.d.mts +0 -1
  103. package/dist/scim/index.mjs +6 -7
  104. package/dist/scope/index.d.mts +2 -3
  105. package/dist/scope/index.mjs +2 -76
  106. package/dist/scope-k15RXfcq.mjs +64 -0
  107. package/dist/{sessionManager-BXG-HGwG.d.mts → sessionManager-BHOM3N_0.d.mts} +10 -6
  108. package/dist/{storage-Co_PQpeQ.d.mts → storage-DLUZ04kK.d.mts} +8 -4
  109. package/dist/testing/index.d.mts +83 -4
  110. package/dist/testing/index.mjs +74 -4
  111. package/dist/testing/storageContract.d.mts +1 -2
  112. package/dist/{tracing-D8jlGXP7.d.mts → tracing-CsGKQJGg.d.mts} +0 -1
  113. package/dist/types/index.d.mts +4 -4
  114. package/dist/types/storage.d.mts +1 -1
  115. package/dist/{types-C9b2HR5W.d.mts → types-Bc42CUyk.d.mts} +1 -2
  116. package/dist/types-Cc91nXuA.d.mts +132 -0
  117. package/dist/{fields-C7ahdGYf.d.mts → types-Csxga7d3.d.mts} +2 -123
  118. package/dist/{types-LNebCoJx.d.mts → types-DH0GupI7.d.mts} +8 -4
  119. package/dist/usage/index.d.mts +142 -0
  120. package/dist/usage/index.mjs +0 -0
  121. package/dist/utils/index.d.mts +220 -144
  122. package/dist/utils/index.mjs +3 -3
  123. package/dist/{utils-ChjYQpjn.mjs → utils-FhJ88TJE.mjs} +129 -39
  124. package/dist/{versioning-D_eBCfNr.d.mts → versioning-DLwklPlG.d.mts} +1 -7
  125. package/dist/{websocket-MlYlrYq0.d.mts → websocket-uuWqM6UY.d.mts} +5 -4
  126. package/llms.txt +39 -0
  127. package/package.json +453 -447
  128. package/skills/arc/SKILL.md +14 -8
  129. package/skills/arc/references/api-reference.md +34 -0
  130. package/skills/arc/references/auth.md +21 -4
  131. package/skills/arc/references/mcp.md +1 -1
  132. package/skills/arc/references/production.md +44 -2
  133. package/skills/arc-code-review/SKILL.md +1 -1
  134. package/skills/arc-code-review/references/anti-patterns.md +71 -18
  135. package/skills/arc-code-review/references/arc-cheatsheet.md +15 -2
  136. package/skills/arc-code-review/references/migration-recipes.md +7 -7
  137. package/skills/arc-code-review/references/mongokit-migration.md +4 -3
  138. package/skills/arc-module-publishing/SKILL.md +243 -0
  139. package/skills/arc-module-publishing/references/authoring-modules.md +327 -0
  140. package/skills/arc-module-publishing/references/package-manifest.md +157 -0
  141. package/skills/arc-module-publishing/references/publishing-workflow.md +182 -0
  142. package/dist/preloadResources-CHw3_oA_.mjs +0 -45
  143. package/dist/schemaConverter-U0MnO9vd.mjs +0 -110
@@ -0,0 +1,142 @@
1
+ import { i as RequestScope } from "../types-DH0GupI7.mjs";
2
+ import { n as PermissionContext, t as PermissionCheck } from "../types-Csxga7d3.mjs";
3
+ import { FastifyPluginAsync, FastifyRequest } from "fastify";
4
+ //#region src/usage/requireQuota.d.ts
5
+ interface QuotaOptions {
6
+ /** Counter to enforce — `ai.tokens`, `export.runs`, `api.requests`, ... */
7
+ kind: string;
8
+ /**
9
+ * Ceiling for the current period. A number, `false` (unlimited — lets
10
+ * plan tables express "enterprise: false" uniformly), or a sync/async
11
+ * resolver receiving the permission context (plan-aware quotas).
12
+ */
13
+ limit: number | false | ((ctx: PermissionContext) => number | false | Promise<number | false>);
14
+ /**
15
+ * Actor key override. Default: the meter's own chain
16
+ * (org → user → client → `ip:<addr>`), so quota buckets are the same
17
+ * buckets usage writes and rate limits read.
18
+ */
19
+ actorOf?: (ctx: PermissionContext) => string | undefined;
20
+ /**
21
+ * Counter-store failure policy. Default `'allow'` (fail-open — see
22
+ * module header). `'deny'` throws the same 429 shape with
23
+ * `code: 'quota.unavailable'` and status 503.
24
+ */
25
+ onStoreError?: "allow" | "deny";
26
+ /** Memoize summary reads per (actor, kind) for this many ms. Default 0. */
27
+ cacheTtlMs?: number;
28
+ }
29
+ declare function requireQuota(options: QuotaOptions): PermissionCheck;
30
+ //#endregion
31
+ //#region src/usage/stores/interface.d.ts
32
+ /**
33
+ * Usage store contract — period-bucketed counters per actor.
34
+ *
35
+ * CANONICAL HOME: `@classytic/repo-core/usage` (>=0.10) owns this
36
+ * contract for the ecosystem — kits implement it there without ever
37
+ * depending on arc (`@classytic/mongokit/usage`, ...). This file is a
38
+ * deliberate STRUCTURAL MIRROR of that shape — same trick as
39
+ * `ScheduleLockLike` vs repo-core's `LockAdapter` — so arc's emitted
40
+ * declarations carry no repo-core@>=0.10 subpath reference and the
41
+ * peer floor stays honest. Any conforming adapter assigns directly.
42
+ *
43
+ * The deliberately tiny surface (one increment, one read) is what makes
44
+ * every backend trivial: memory (dev/tests), Redis (`HINCRBY`), or any kit
45
+ * (Mongo `$inc` upsert) implements it in a handful of lines. Aggregation
46
+ * happens IN the store — arc never buffers counters in process memory
47
+ * beyond the built-in memory store, so multi-replica deployments stay
48
+ * correct as long as the store is shared.
49
+ *
50
+ * This is the HORIZONTAL usage layer (per-actor, per-period platform
51
+ * accounting for quotas/plans/billing). Itemized vertical records — e.g.
52
+ * `@classytic/arc-ai/usage`'s per-run AI token/cost tracking — keep their
53
+ * own richer stores and can sink into this one (`kind: 'ai.tokens'`).
54
+ */
55
+ /** One counter cell: (actor, period, kind). */
56
+ interface UsageBucket {
57
+ /** Who consumed — org / user / client id, or an IP-derived fallback. */
58
+ actor: string;
59
+ /** Aggregation period, `YYYY-MM` (see `usagePeriod()`). */
60
+ period: string;
61
+ /** Namespaced counter, dot-separated: `api.requests`, `ai.tokens`, `storage.bytes`. */
62
+ kind: string;
63
+ }
64
+ interface UsageStore {
65
+ /** Store name for diagnostics (e.g. 'memory', 'redis', 'mongo'). */
66
+ readonly name: string;
67
+ /** Add `amount` to the bucket's counter, creating it at 0 first. MUST be atomic per bucket. */
68
+ increment(bucket: UsageBucket, amount: number): Promise<void> | void;
69
+ /** Every counter for an actor in a period: `{ 'api.requests': 40231, ... }`. */
70
+ summary(actor: string, period: string): Promise<Record<string, number>>;
71
+ /** Optional cleanup hook (connections, timers). */
72
+ close?(): Promise<void>;
73
+ }
74
+ /**
75
+ * Canonical period key for a date — calendar month, UTC: `2026-07`.
76
+ * Monthly is the billing-native granularity; stores that want finer
77
+ * windows can shard internally without changing the contract.
78
+ */
79
+ declare function usagePeriod(date?: Date): string;
80
+ //#endregion
81
+ //#region src/usage/stores/memory.d.ts
82
+ declare class MemoryUsageStore implements UsageStore {
83
+ #private;
84
+ readonly name = "memory";
85
+ increment(bucket: UsageBucket, amount: number): void;
86
+ summary(actor: string, period: string): Promise<Record<string, number>>;
87
+ /** Test convenience — drop everything. */
88
+ clear(): void;
89
+ }
90
+ //#endregion
91
+ //#region src/usage/usagePlugin.d.ts
92
+ interface UsageTrackOptions {
93
+ /** Count every completed request as `api.requests` (default: true). */
94
+ requests?: boolean;
95
+ /** Sum `content-length` response bytes as `api.egress.bytes` (default: false). */
96
+ egress?: boolean;
97
+ }
98
+ interface UsagePluginOptions {
99
+ /** Master switch — `false` registers a typed no-op (config-gated environments). */
100
+ enabled?: boolean;
101
+ /** Counter backend. Default: in-memory (per-process — use a shared store in multi-replica). */
102
+ store?: UsageStore;
103
+ /** Automatic per-request accounting. Default: `{ requests: true, egress: false }`. */
104
+ track?: UsageTrackOptions;
105
+ /**
106
+ * Derive the actor key from a request. Default: org → user → client →
107
+ * `ip:<addr>` (same chain as `createTenantKeyGenerator`).
108
+ */
109
+ actorOf?: (request: FastifyRequest) => string | undefined;
110
+ /**
111
+ * Paths exempt from automatic tracking. Exact or trailing-`*` prefix.
112
+ * Default: `['/_health*', '/_metrics*']`.
113
+ */
114
+ ignorePaths?: string[];
115
+ }
116
+ /** The `fastify.usage` surface. */
117
+ interface UsageMeter {
118
+ /**
119
+ * Add to a counter. `actor` may be a raw key or a `RequestScope`
120
+ * (derived via the org → user → client chain). Fire-and-forget safe:
121
+ * awaiting is optional, errors never throw into request flow.
122
+ */
123
+ record(actor: string | RequestScope | undefined, kind: string, amount?: number): Promise<void>;
124
+ /** All counters for an actor. Period defaults to the current month. */
125
+ summary(actor: string, period?: string): Promise<Record<string, number>>;
126
+ /** Canonical period key (`YYYY-MM`) for a date. */
127
+ period(date?: Date): string;
128
+ /** The actor key automatic tracking would use for this request. */
129
+ actorOf(request: FastifyRequest): string;
130
+ /** The active store (diagnostics). */
131
+ readonly store: UsageStore;
132
+ }
133
+ declare module "fastify" {
134
+ interface FastifyInstance {
135
+ /** Per-actor usage counters — registered by `usagePlugin`. */
136
+ usage?: UsageMeter;
137
+ }
138
+ }
139
+ declare const usagePluginFn: FastifyPluginAsync<UsagePluginOptions>;
140
+ declare const _default: FastifyPluginAsync<UsagePluginOptions>;
141
+ //#endregion
142
+ export { MemoryUsageStore, type QuotaOptions, type UsageBucket, type UsageMeter, type UsagePluginOptions, type UsageStore, type UsageTrackOptions, _default as default, requireQuota, usagePeriod, usagePluginFn as usagePlugin };
Binary file