@classytic/arc 2.8.5 → 2.10.3
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/README.md +50 -38
- package/dist/{BaseController-DAGGc5Xn.mjs → BaseController-CbKKIflT.mjs} +193 -143
- package/dist/EventTransport-CUw5NNWe.d.mts +293 -0
- package/dist/{ResourceRegistry-C6uXlWe3.mjs → ResourceRegistry-BPd6NQDm.mjs} +1 -1
- package/dist/adapters/index.d.mts +3 -3
- package/dist/adapters/index.mjs +2 -2
- package/dist/{adapters-BBqAVvPK.mjs → adapters-BXY4i-hw.mjs} +210 -41
- package/dist/audit/index.d.mts +135 -11
- package/dist/audit/index.mjs +107 -20
- package/dist/auth/index.d.mts +17 -9
- package/dist/auth/index.mjs +14 -7
- package/dist/auth/redis-session.d.mts +1 -1
- package/dist/{betterAuthOpenApi-BuUcUEJq.mjs → betterAuthOpenApi-BBRVhjQN.mjs} +1 -1
- package/dist/cache/index.d.mts +17 -15
- package/dist/cache/index.mjs +15 -14
- package/dist/{caching-IMuYVjTL.mjs → caching-CBpK_SCM.mjs} +8 -3
- package/dist/cli/commands/describe.mjs +1 -1
- package/dist/cli/commands/docs.mjs +2 -2
- package/dist/cli/commands/generate.mjs +1 -1
- package/dist/cli/commands/init.mjs +1 -1
- package/dist/cli/commands/introspect.mjs +1 -1
- package/dist/core/index.d.mts +3 -3
- package/dist/core/index.mjs +4 -6
- package/dist/{defineResource-tcgySDo1.mjs → core-CcR01lup.mjs} +58 -61
- package/dist/{createActionRouter-BORM8f17.mjs → createActionRouter-Bp_5c_2b.mjs} +3 -3
- package/dist/{createApp-B1EY8zxa.mjs → createApp-BuvPma24.mjs} +15 -14
- package/dist/docs/index.d.mts +2 -2
- package/dist/docs/index.mjs +2 -2
- package/dist/{elevation-DtFxrG0s.mjs → elevation-C7hgL_aI.mjs} +22 -8
- package/dist/{errorHandler-f869_8PQ.mjs → errorHandler-Bb49BvPD.mjs} +59 -7
- package/dist/{errorHandler-Bah5JhBd.d.mts → errorHandler-DRQ3EqfL.d.mts} +37 -2
- package/dist/{eventPlugin-D9DKB2zM.d.mts → eventPlugin-CxWgpd6K.d.mts} +14 -2
- package/dist/{eventPlugin-CDjVTM82.mjs → eventPlugin-DCUjuiQT.mjs} +83 -5
- package/dist/events/index.d.mts +150 -36
- package/dist/events/index.mjs +355 -101
- package/dist/events/transports/redis-stream-entry.d.mts +1 -1
- package/dist/events/transports/redis.d.mts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.mjs +2 -2
- package/dist/{types-DZi1aYhm.d.mts → fields-Lo1VUDpt.d.mts} +121 -1
- package/dist/{fields-ipsbIRPK.mjs → fields-bxkeltzz.mjs} +18 -5
- package/dist/{filesUpload-C7r7HIeA.mjs → filesUpload-t21LS-py.mjs} +65 -7
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/idempotency/index.d.mts +32 -5
- package/dist/idempotency/index.mjs +119 -12
- package/dist/idempotency/redis.d.mts +1 -1
- package/dist/{index-DtDzOBn8.d.mts → index-8qw4y6ff.d.mts} +4 -135
- package/dist/{index-BLXBmWud.d.mts → index-ChIw3776.d.mts} +283 -408
- package/dist/{interface-CMRutPfe.d.mts → index-Cl0uoKd5.d.mts} +1758 -2506
- package/dist/{index-C1meYuDn.d.mts → index-DStwgFUK.d.mts} +81 -7
- package/dist/index.d.mts +7 -8
- package/dist/index.mjs +11 -12
- package/dist/integrations/event-gateway.d.mts +1 -1
- package/dist/integrations/event-gateway.mjs +1 -1
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/mcp/index.d.mts +26 -8
- package/dist/integrations/mcp/index.mjs +96 -17
- package/dist/integrations/mcp/testing.d.mts +1 -1
- package/dist/integrations/mcp/testing.mjs +1 -1
- package/dist/integrations/webhooks.d.mts +5 -0
- package/dist/integrations/webhooks.mjs +6 -0
- package/dist/interface-D218ikEo.d.mts +77 -0
- package/dist/{memory-Cp7_cAko.mjs → memory-B5Amv9A1.mjs} +23 -8
- package/dist/{openapi-CbKUJY_m.mjs → openapi-B5F8AddX.mjs} +3 -3
- package/dist/org/index.d.mts +2 -2
- package/dist/permissions/index.d.mts +3 -4
- package/dist/permissions/index.mjs +5 -5
- package/dist/{permissions-CH4cNwJi.mjs → permissions-Dk6mshja.mjs} +315 -397
- package/dist/plugins/index.d.mts +7 -7
- package/dist/plugins/index.mjs +14 -16
- package/dist/plugins/response-cache.mjs +2 -2
- package/dist/plugins/tracing-entry.d.mts +1 -1
- package/dist/plugins/tracing-entry.mjs +1 -1
- package/dist/presets/filesUpload.d.mts +27 -5
- package/dist/presets/filesUpload.mjs +1 -1
- package/dist/presets/index.d.mts +3 -2
- package/dist/presets/index.mjs +4 -3
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +2 -2
- package/dist/presets/search.d.mts +178 -0
- package/dist/presets/search.mjs +150 -0
- package/dist/{presets-C2xgzW6x.mjs → presets-fLJVXdVn.mjs} +1 -1
- package/dist/{queryCachePlugin-BJJGBTlu.d.mts → queryCachePlugin-BKbWjgDG.d.mts} +1 -1
- package/dist/{queryCachePlugin-BH-fidlv.mjs → queryCachePlugin-DQCEfJis.mjs} +9 -9
- package/dist/{queryParser-CgCtsjti.mjs → queryParser-DBqBB6AC.mjs} +1 -1
- package/dist/{redis-BM00zaPB.d.mts → redis-DqyeggCa.d.mts} +1 -1
- package/dist/{redis-stream-CrsfUmPt.d.mts → redis-stream-CakIQmwR.d.mts} +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +2 -2
- package/dist/{resourceToTools-8s-EsCCe.mjs → resourceToTools-BElv3xPT.mjs} +65 -48
- package/dist/{schemaConverter-Y7nCYaLJ.mjs → schemaConverter-BxFDdtXu.mjs} +1 -1
- package/dist/scope/index.d.mts +1 -1
- package/dist/scope/index.mjs +2 -2
- package/dist/{sse-Ad7ypl9e.mjs → sse-yBCgOLGu.mjs} +1 -1
- package/dist/store-helpers-ZCSMJJAX.mjs +57 -0
- package/dist/testing/index.d.mts +9 -17
- package/dist/testing/index.mjs +27 -83
- package/dist/testing/storageContract.d.mts +1 -1
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.mjs +1 -31
- package/dist/types/storage.d.mts +1 -1
- package/dist/{types-BsbNMEDR.d.mts → types-Btdda02s.d.mts} +1 -1
- package/dist/{types-Ch9pTQbf.d.mts → types-Co8k3NyS.d.mts} +11 -9
- package/dist/types-Csi3FLfq.mjs +27 -0
- package/dist/utils/index.d.mts +208 -4
- package/dist/utils/index.mjs +5 -6
- package/dist/{utils-yYT3HDXt.mjs → utils-B2fNOD_i.mjs} +285 -2
- package/dist/{versioning-CDugduqI.mjs → versioning-C2U_bLY0.mjs} +3 -5
- package/package.json +20 -26
- package/skills/arc/SKILL.md +97 -23
- package/skills/arc/references/auth.md +94 -0
- package/skills/arc/references/events.md +200 -12
- package/skills/arc/references/mcp.md +4 -17
- package/skills/arc/references/multi-tenancy.md +43 -0
- package/skills/arc/references/production.md +34 -60
- package/dist/EventTransport-BXja8NOc.d.mts +0 -135
- package/dist/audit/mongodb.d.mts +0 -2
- package/dist/audit/mongodb.mjs +0 -2
- package/dist/circuitBreaker-cmi5XDv5.mjs +0 -284
- package/dist/circuitBreaker-dTtG-UyS.d.mts +0 -206
- package/dist/core-F0QoWBt2.mjs +0 -34
- package/dist/dynamic/index.d.mts +0 -93
- package/dist/dynamic/index.mjs +0 -122
- package/dist/fields-DpZQa_Q3.d.mts +0 -109
- package/dist/idempotency/mongodb.d.mts +0 -2
- package/dist/idempotency/mongodb.mjs +0 -123
- package/dist/interface-4y979v99.d.mts +0 -54
- package/dist/mongodb-BsP-WbhN.d.mts +0 -127
- package/dist/mongodb-CTcp0hQZ.d.mts +0 -80
- package/dist/mongodb-Utc5k_-0.mjs +0 -90
- package/dist/policies/index.d.mts +0 -432
- package/dist/policies/index.mjs +0 -318
- package/dist/rpc/index.d.mts +0 -90
- package/dist/rpc/index.mjs +0 -248
- /package/dist/{HookSystem-HprTmvVY.mjs → HookSystem-BNYKnrXF.mjs} +0 -0
- /package/dist/{applyPermissionResult-D6GPMsvh.mjs → applyPermissionResult-QhV1Pa-g.mjs} +0 -0
- /package/dist/{constants-Cxde4rpC.mjs → constants-BhY1OHoH.mjs} +0 -0
- /package/dist/{elevation-B6S5csVA.d.mts → elevation-C5SwtkAn.d.mts} +0 -0
- /package/dist/{errors-Ck2h67pm.d.mts → errors-CCSsMpXE.d.mts} +0 -0
- /package/dist/{errors-BF2bIOIS.mjs → errors-D5c-5BJL.mjs} +0 -0
- /package/dist/{externalPaths-BnkYrNzp.d.mts → externalPaths-BQ8QijNH.d.mts} +0 -0
- /package/dist/{interface-DfLGcus7.d.mts → interface-CSbZdv_3.d.mts} +0 -0
- /package/dist/{loadResources-PWd0OCpV.mjs → loadResources-BAzJItAJ.mjs} +0 -0
- /package/dist/{logger-D1YrIImS.mjs → logger-DLg8-Ueg.mjs} +0 -0
- /package/dist/{metrics-B-PU4-Yu.mjs → metrics-DuhiSEZI.mjs} +0 -0
- /package/dist/{pluralize-CWP6MB39.mjs → pluralize-A0tWEl1K.mjs} +0 -0
- /package/dist/{registry-BiTKT1Dg.mjs → registry-B3lRFBWo.mjs} +0 -0
- /package/dist/{replyHelpers-CxkYGT81.mjs → replyHelpers-CXtJDAZ0.mjs} +0 -0
- /package/dist/{requestContext-DYvHl113.mjs → requestContext-xHIKedG6.mjs} +0 -0
- /package/dist/{sessionManager-DDCmiNIo.d.mts → sessionManager-BkzVU8h2.d.mts} +0 -0
- /package/dist/{storage-Dfzt4VTl.d.mts → storage-CVk_SEn2.d.mts} +0 -0
- /package/dist/{tracing-DdN2-wHJ.d.mts → tracing-65B51Dw3.d.mts} +0 -0
- /package/dist/{typeGuards-CcFZXgU7.mjs → typeGuards-Cj5Rgvlg.mjs} +0 -0
- /package/dist/{types-ZUu_h0jp.mjs → types-DV9WDfeg.mjs} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/arc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.3",
|
|
4
4
|
"description": "Resource-oriented backend framework for Fastify — clean, minimal, powerful, tree-shakable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"types": "./dist/presets/filesUpload.d.mts",
|
|
45
45
|
"default": "./dist/presets/filesUpload.mjs"
|
|
46
46
|
},
|
|
47
|
+
"./presets/search": {
|
|
48
|
+
"types": "./dist/presets/search.d.mts",
|
|
49
|
+
"default": "./dist/presets/search.mjs"
|
|
50
|
+
},
|
|
47
51
|
"./auth": {
|
|
48
52
|
"types": "./dist/auth/index.d.mts",
|
|
49
53
|
"default": "./dist/auth/index.mjs"
|
|
@@ -84,10 +88,6 @@
|
|
|
84
88
|
"types": "./dist/audit/index.d.mts",
|
|
85
89
|
"default": "./dist/audit/index.mjs"
|
|
86
90
|
},
|
|
87
|
-
"./audit/mongodb": {
|
|
88
|
-
"types": "./dist/audit/mongodb.d.mts",
|
|
89
|
-
"default": "./dist/audit/mongodb.mjs"
|
|
90
|
-
},
|
|
91
91
|
"./docs": {
|
|
92
92
|
"types": "./dist/docs/index.d.mts",
|
|
93
93
|
"default": "./dist/docs/index.mjs"
|
|
@@ -100,10 +100,6 @@
|
|
|
100
100
|
"types": "./dist/idempotency/redis.d.mts",
|
|
101
101
|
"default": "./dist/idempotency/redis.mjs"
|
|
102
102
|
},
|
|
103
|
-
"./idempotency/mongodb": {
|
|
104
|
-
"types": "./dist/idempotency/mongodb.d.mts",
|
|
105
|
-
"default": "./dist/idempotency/mongodb.mjs"
|
|
106
|
-
},
|
|
107
103
|
"./events": {
|
|
108
104
|
"types": "./dist/events/index.d.mts",
|
|
109
105
|
"default": "./dist/events/index.mjs"
|
|
@@ -116,10 +112,6 @@
|
|
|
116
112
|
"types": "./dist/events/transports/redis-stream-entry.d.mts",
|
|
117
113
|
"default": "./dist/events/transports/redis-stream-entry.mjs"
|
|
118
114
|
},
|
|
119
|
-
"./dynamic": {
|
|
120
|
-
"types": "./dist/dynamic/index.d.mts",
|
|
121
|
-
"default": "./dist/dynamic/index.mjs"
|
|
122
|
-
},
|
|
123
115
|
"./testing": {
|
|
124
116
|
"types": "./dist/testing/index.d.mts",
|
|
125
117
|
"default": "./dist/testing/index.mjs"
|
|
@@ -128,10 +120,6 @@
|
|
|
128
120
|
"types": "./dist/testing/storageContract.d.mts",
|
|
129
121
|
"default": "./dist/testing/storageContract.mjs"
|
|
130
122
|
},
|
|
131
|
-
"./policies": {
|
|
132
|
-
"types": "./dist/policies/index.d.mts",
|
|
133
|
-
"default": "./dist/policies/index.mjs"
|
|
134
|
-
},
|
|
135
123
|
"./factory": {
|
|
136
124
|
"types": "./dist/factory/index.d.mts",
|
|
137
125
|
"default": "./dist/factory/index.mjs"
|
|
@@ -192,10 +180,6 @@
|
|
|
192
180
|
"types": "./dist/scope/index.d.mts",
|
|
193
181
|
"default": "./dist/scope/index.mjs"
|
|
194
182
|
},
|
|
195
|
-
"./rpc": {
|
|
196
|
-
"types": "./dist/rpc/index.d.mts",
|
|
197
|
-
"default": "./dist/rpc/index.mjs"
|
|
198
|
-
},
|
|
199
183
|
"./mcp": {
|
|
200
184
|
"types": "./dist/integrations/mcp/index.d.mts",
|
|
201
185
|
"default": "./dist/integrations/mcp/index.mjs"
|
|
@@ -239,7 +223,8 @@
|
|
|
239
223
|
"node": ">=22"
|
|
240
224
|
},
|
|
241
225
|
"peerDependencies": {
|
|
242
|
-
"@classytic/mongokit": ">=3.
|
|
226
|
+
"@classytic/mongokit": ">=3.10.2",
|
|
227
|
+
"@classytic/repo-core": ">=0.1.0",
|
|
243
228
|
"@classytic/streamline": ">=2.1.0",
|
|
244
229
|
"@fastify/cors": ">=11.0.0",
|
|
245
230
|
"@fastify/helmet": ">=13.0.0",
|
|
@@ -259,11 +244,11 @@
|
|
|
259
244
|
"@sinclair/typebox": ">=0.34.0",
|
|
260
245
|
"better-auth": ">=1.6.2",
|
|
261
246
|
"bullmq": ">=5.0.0",
|
|
262
|
-
"fastify": "
|
|
247
|
+
"fastify": "^5.8.5",
|
|
263
248
|
"fastify-raw-body": ">=5.0.0",
|
|
264
249
|
"ioredis": ">=5.0.0",
|
|
265
250
|
"mongodb": ">=7.0.0",
|
|
266
|
-
"mongoose": "
|
|
251
|
+
"mongoose": "^9.4.1",
|
|
267
252
|
"pino-pretty": ">=13.0.0",
|
|
268
253
|
"zod": ">=4.0.0"
|
|
269
254
|
},
|
|
@@ -271,6 +256,9 @@
|
|
|
271
256
|
"@classytic/mongokit": {
|
|
272
257
|
"optional": true
|
|
273
258
|
},
|
|
259
|
+
"@classytic/repo-core": {
|
|
260
|
+
"optional": true
|
|
261
|
+
},
|
|
274
262
|
"mongodb": {
|
|
275
263
|
"optional": true
|
|
276
264
|
},
|
|
@@ -356,9 +344,12 @@
|
|
|
356
344
|
"secure-json-parse": "^4.1.0"
|
|
357
345
|
},
|
|
358
346
|
"devDependencies": {
|
|
347
|
+
"@better-auth/drizzle-adapter": "^1.6.2",
|
|
359
348
|
"@better-auth/mongo-adapter": "^1.6.2",
|
|
360
349
|
"@biomejs/biome": "^2.4.11",
|
|
361
|
-
"@classytic/mongokit": "
|
|
350
|
+
"@classytic/mongokit": "^3.10.2",
|
|
351
|
+
"@classytic/repo-core": "^0.1.0",
|
|
352
|
+
"@classytic/sqlitekit": "^0.1.0",
|
|
362
353
|
"@classytic/streamline": "^2.1.0",
|
|
363
354
|
"@fastify/cors": "^11.2.0",
|
|
364
355
|
"@fastify/helmet": "^13.0.2",
|
|
@@ -376,15 +367,18 @@
|
|
|
376
367
|
"@vitest/coverage-v8": "^3.2.4",
|
|
377
368
|
"ajv": "^8.18.0",
|
|
378
369
|
"better-auth": "^1.6.2",
|
|
370
|
+
"better-sqlite3": "^12.9.0",
|
|
379
371
|
"bullmq": "^5.73.5",
|
|
380
372
|
"dotenv": "^17.4.2",
|
|
373
|
+
"drizzle-orm": "^0.45.2",
|
|
374
|
+
"fast-check": "^4.6.0",
|
|
381
375
|
"fastify-raw-body": "^5.0.0",
|
|
382
376
|
"ioredis": "^5.10.1",
|
|
383
377
|
"jsonwebtoken": "^9.0.0",
|
|
384
378
|
"knip": "^6.4.1",
|
|
385
379
|
"mongodb": "^7.1.0",
|
|
386
380
|
"mongodb-memory-server": "^11.0.1",
|
|
387
|
-
"mongoose": "
|
|
381
|
+
"mongoose": ">=9.4.1",
|
|
388
382
|
"tsdown": "^0.21.7",
|
|
389
383
|
"typescript": "^6.0.2",
|
|
390
384
|
"vitest": "^3.0.0",
|
package/skills/arc/SKILL.md
CHANGED
|
@@ -8,11 +8,11 @@ description: |
|
|
|
8
8
|
Triggers: arc, fastify resource, defineResource, createApp, BaseController, arc preset,
|
|
9
9
|
arc auth, arc events, arc jobs, arc websocket, arc mcp, arc plugin, arc testing, arc cli,
|
|
10
10
|
arc permissions, arc hooks, arc pipeline, arc factory, arc cache, arc QueryCache.
|
|
11
|
-
version: 2.
|
|
11
|
+
version: 2.10.3
|
|
12
12
|
license: MIT
|
|
13
13
|
metadata:
|
|
14
14
|
author: Classytic
|
|
15
|
-
version: "2.
|
|
15
|
+
version: "2.10.3"
|
|
16
16
|
tags:
|
|
17
17
|
- fastify
|
|
18
18
|
- rest-api
|
|
@@ -68,6 +68,22 @@ await app.register(productResource.toPlugin());
|
|
|
68
68
|
await app.listen({ port: 8040, host: '0.0.0.0' });
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
## v2.9 Security Defaults (breaking)
|
|
72
|
+
|
|
73
|
+
- **Field-write perms: `reject` (default)** — requests carrying non-writable fields get 403 with denied-field list. Opt into silent strip: `defineResource({ onFieldWriteDenied: 'strip' })`.
|
|
74
|
+
- **multiTenant injects org on UPDATE** — body-supplied `organizationId` overwritten with caller's scope. Closes tenant-hop vector.
|
|
75
|
+
- **Elevation always emits `arc.scope.elevated` event** — audit via `fastify.events.subscribe(...)`.
|
|
76
|
+
- **`verifySignature(body, ...)` throws on parsed body** — pass `req.rawBody`, not `req.body`.
|
|
77
|
+
- **Upload `sanitizeFilename`** — strict by default (no `/ \ .. \0 >255ch`). Pass `false` / `'*'` / custom fn to relax.
|
|
78
|
+
- **Idempotency `namespace`** option for shared-store prod+canary deployments.
|
|
79
|
+
|
|
80
|
+
## Removed in v2.9
|
|
81
|
+
|
|
82
|
+
- `createActionRouter`, `buildActionBodySchema` — use `actions` on `defineResource`
|
|
83
|
+
- `ResourceConfig.onRegister` — use `actions` or resource `hooks`
|
|
84
|
+
- `AdditionalRoute` type + `resource.additionalRoutes` field — use `RouteDefinition` and `resource.routes` (single source of truth; no normalised mirror)
|
|
85
|
+
- `wrapHandler` on route defs — derived from `!route.raw` at use-site (set `raw: true` to opt out of the arc pipeline)
|
|
86
|
+
|
|
71
87
|
## defineResource()
|
|
72
88
|
|
|
73
89
|
Single API to define a full REST resource:
|
|
@@ -109,7 +125,7 @@ const productResource = defineResource({
|
|
|
109
125
|
{ method: 'POST', path: '/webhook', handler: webhookFn, raw: true, permissions: auth() },
|
|
110
126
|
],
|
|
111
127
|
|
|
112
|
-
// Actions
|
|
128
|
+
// Actions — single POST /:id/action endpoint, discriminated on `action` body field
|
|
113
129
|
actions: {
|
|
114
130
|
approve: async (id, data, req) => service.approve(id, req.user._id),
|
|
115
131
|
cancel: {
|
|
@@ -489,6 +505,8 @@ permissions: { list: acl.canAction('product', 'read') }
|
|
|
489
505
|
| `multiTenant` | none (middleware) | — | `{ tenantField }` OR `{ tenantFields: TenantFieldSpec[] }` (2.7.1+) |
|
|
490
506
|
| `audited` | none (middleware) | — | — |
|
|
491
507
|
| `bulk` | POST/PATCH/DELETE /bulk | — | `{ operations?, maxCreateItems? }` |
|
|
508
|
+
| `filesUpload` | POST /upload, GET /:id, DELETE /:id | — (uses `Storage` adapter) | `{ storage, sanitizeFilename?, allowedMimeTypes?, maxFileSize? }` |
|
|
509
|
+
| `search` | POST /search, /search-similar, /embed (opt-in) | — | `{ repository?, search?, similar?, embed?, routes? }` |
|
|
492
510
|
|
|
493
511
|
```typescript
|
|
494
512
|
// Single-field (default, backwards compatible)
|
|
@@ -546,7 +564,7 @@ Default is `'_id'`. Override for resources keyed by a business identifier (UUID,
|
|
|
546
564
|
defineResource({
|
|
547
565
|
name: 'job',
|
|
548
566
|
adapter: createMongooseAdapter(JobModel, jobRepository),
|
|
549
|
-
idField: 'jobId', // ← one line
|
|
567
|
+
idField: 'jobId', // ← one line (or omit and auto-derive from repository.idField — see below)
|
|
550
568
|
});
|
|
551
569
|
|
|
552
570
|
// GET /jobs/job-5219f346-a4d → controller runs { jobId: 'job-5219f346-a4d' }
|
|
@@ -559,10 +577,66 @@ Changes all three layers:
|
|
|
559
577
|
- **OpenAPI docs** — `spec.paths['/jobs/{id}']` emits a plain string `id` with description
|
|
560
578
|
- **MCP tools** — auto-generated CRUD tools use `idField` transparently
|
|
561
579
|
|
|
562
|
-
|
|
580
|
+
**Auto-derive from repository** (2.7.x+). If you don't set `idField` on `defineResource` but your `adapter.repository` exposes one (e.g. `new Repository(Model, [], {}, { idField: 'slug' })`), Arc picks it up automatically. Configure in one place, not two.
|
|
581
|
+
|
|
582
|
+
**URL path segment is ALWAYS `:id` and `req.params.id` is ALWAYS named `id`** — regardless of what `idField` is set to. `idField` controls the *lookup field*, not the *URL parameter name*. This is the same convention Stripe / GitHub / most REST APIs use:
|
|
583
|
+
|
|
584
|
+
```typescript
|
|
585
|
+
// idField: 'slug'
|
|
586
|
+
// Client sends: POST /agents/sadman/action
|
|
587
|
+
// In handler: req.params.id === 'sadman' ← always keyed 'id'
|
|
588
|
+
// repo.update(id, data) ← mongokit resolves by slug via repo.idField
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
This applies to CRUD routes (`GET/PATCH/DELETE /:id`), action routes (`POST /:id/action`), and any `routes: [...]` entries that use `:id`.
|
|
592
|
+
|
|
593
|
+
**Common confusion pattern.** A 404 on `PATCH /agents/sadman` when `GET /agents/sadman` returns 200 looks like an `idField` bug but usually isn't. Check whether your **update permission** returns `filters` — arc merges those into the compound DB lookup (`{ slug: 'sadman', ...filters }`), and a filter that excludes the doc is what's returning null. Fix is in the permission, not `idField`.
|
|
594
|
+
|
|
595
|
+
User-provided `openApiSchemas.params` still overrides everything.
|
|
563
596
|
|
|
564
597
|
For custom adapters, honor the new `AdapterSchemaContext` passed to `generateSchemas(options, context?)` to emit the right `params.id` pattern from the start. Legacy adapters still work — Arc's safety net strips mismatched ObjectId patterns automatically.
|
|
565
598
|
|
|
599
|
+
## searchPreset (text + vector + embed)
|
|
600
|
+
|
|
601
|
+
Backend-agnostic routes for Elasticsearch / OpenSearch / Algolia / Typesense / Atlas `$vectorSearch` / Pinecone / Qdrant / Milvus. Opt-in per section; `mcp: false` skips per path.
|
|
602
|
+
|
|
603
|
+
```typescript
|
|
604
|
+
import { searchPreset } from '@classytic/arc/presets/search';
|
|
605
|
+
|
|
606
|
+
// A — auto-wire from a repo with search/searchSimilar/embed methods
|
|
607
|
+
// (mongokit's elasticSearchPlugin + vectorPlugin register exactly these).
|
|
608
|
+
// Each method's native calling convention is honoured:
|
|
609
|
+
// search(query, options) — positional (elasticSearchPlugin)
|
|
610
|
+
// searchSimilar(VectorSearchParams) — single object (vectorPlugin)
|
|
611
|
+
// embed(input) — single arg (vectorPlugin)
|
|
612
|
+
searchPreset({
|
|
613
|
+
repository: productRepo,
|
|
614
|
+
search: true, // POST /search → repo.search(body.query, body)
|
|
615
|
+
similar: true, // POST /search-similar → repo.searchSimilar(body)
|
|
616
|
+
// embed omitted → /embed not mounted
|
|
617
|
+
})
|
|
618
|
+
|
|
619
|
+
// B — external backends + custom path + Zod schema
|
|
620
|
+
searchPreset({
|
|
621
|
+
search: {
|
|
622
|
+
path: '/full-text',
|
|
623
|
+
schema: { body: z.object({ q: z.string().min(1) }) },
|
|
624
|
+
handler: (req) => elastic.search({ index: 'products', q: req.body.q }),
|
|
625
|
+
},
|
|
626
|
+
similar: { handler: (req) => pinecone.query({ vector: req.body.vector, topK: 10 }), mcp: false },
|
|
627
|
+
routes: [ // bespoke paths
|
|
628
|
+
{ method: 'GET', path: '/autocomplete', permissions: allowPublic(),
|
|
629
|
+
handler: (req) => algolia.suggest((req.query as { q: string }).q) },
|
|
630
|
+
],
|
|
631
|
+
})
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
**Defaults:** search/similar → POST, permissions fall back to resource `list` → `allowPublic()`. Embed → POST + `requireAuth()`. Every field (`path`, `method`, `schema`, `permissions`, `mcp`, `summary`, `tags`, `operation`) is overridable per section. Zod v4 schemas auto-convert to JSON Schema for both Fastify validation and OpenAPI.
|
|
635
|
+
|
|
636
|
+
**MCP namespacing:** tool names are `{op}_{resource}` — many resources can register their own searchPreset under one `mcpPlugin` endpoint without colliding (`product_search`, `order_search`, …).
|
|
637
|
+
|
|
638
|
+
**When to use `routes` directly instead:** one-off search endpoints, or when you want full control without the preset's defaults.
|
|
639
|
+
|
|
566
640
|
## QueryCache
|
|
567
641
|
|
|
568
642
|
TanStack Query-inspired server cache with stale-while-revalidate and auto-invalidation on mutations.
|
|
@@ -618,14 +692,11 @@ class ProductController extends BaseController<Product> {
|
|
|
618
692
|
import { createMongooseAdapter } from '@classytic/arc';
|
|
619
693
|
const adapter = createMongooseAdapter({ model: ProductModel, repository: productRepo });
|
|
620
694
|
|
|
621
|
-
// Custom adapter — implement
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
update(id: string, data): Promise<TDoc | null>;
|
|
627
|
-
delete(id: string): Promise<boolean>;
|
|
628
|
-
}
|
|
695
|
+
// Custom adapter — implement MinimalRepo from @classytic/repo-core/repository:
|
|
696
|
+
import type { MinimalRepo } from '@classytic/repo-core/repository';
|
|
697
|
+
// MinimalRepo<TDoc> = five-method floor (getAll, getById, create, update, delete)
|
|
698
|
+
// StandardRepo<TDoc> = MinimalRepo + optional batch ops, CAS, soft-delete, etc.
|
|
699
|
+
// Arc feature-detects optional methods at call sites.
|
|
629
700
|
```
|
|
630
701
|
|
|
631
702
|
## Events
|
|
@@ -652,7 +723,11 @@ CRUD events auto-emit: `{resource}.created`, `{resource}.updated`, `{resource}.d
|
|
|
652
723
|
|
|
653
724
|
**Transports:** Memory (default) | Redis Pub/Sub (fire-and-forget) | Redis Streams (durable, at-least-once, consumer groups, DLQ)
|
|
654
725
|
|
|
655
|
-
**Event Outbox** — at-least-once delivery via transactional outbox pattern.
|
|
726
|
+
**Event Outbox** — at-least-once delivery via transactional outbox pattern. Pass `repository: RepositoryLike` (mongokit / prismakit / custom) for production, or `store: MemoryOutboxStore()` for dev. Arc adapts the repo to the `OutboxStore` contract internally — `create` / `findAll` / `deleteMany` / `findOneAndUpdate` cover save, claim, ack, fail, DLQ.
|
|
727
|
+
|
|
728
|
+
**Event contract (v2.9):** `EventMeta` = `id`, `timestamp`, optional `schemaVersion`, `correlationId`, `causationId`, `partitionKey`, `source`, `idempotencyKey`, `resource`, `resourceId`, `userId`, `organizationId`, `aggregate: { type, id }`. `createChildEvent(parent, ...)` inherits correlation/causation/source/idempotencyKey; aggregate stays explicit. `DeadLetteredEvent<T>` + optional `transport.deadLetter()` for typed DLQ. `withRetry({ transport })` auto-routes exhausted events — no custom plumbing for Kafka/SQS. `@classytic/primitives` mirrors these shapes — arc is source of truth.
|
|
729
|
+
|
|
730
|
+
**Outbox (v2.9):** `EventOutbox.store()` auto-maps `meta.idempotencyKey` → `dedupeKey`. `new EventOutbox({ failurePolicy: ({ attempts }) => ({ retryAt, deadLetter }) })` centralises retry/DLQ. `outbox.getDeadLettered(limit)` returns typed `DeadLetteredEvent[]`. `RelayResult.deadLettered` for per-batch DLQ count. Durable store: `new EventOutbox({ repository: new Repository(OutboxModel), transport })` (v2.9.1) — multi-worker claim, session-threaded writes, and dedupe semantics come from the repo's backing kit.
|
|
656
731
|
|
|
657
732
|
## Factory — createApp()
|
|
658
733
|
|
|
@@ -948,7 +1023,7 @@ defineResource({ name: 'order', audit: true });
|
|
|
948
1023
|
defineResource({ name: 'payment', audit: { operations: ['delete'] } });
|
|
949
1024
|
defineResource({ name: 'product' }); // not audited
|
|
950
1025
|
|
|
951
|
-
// Manual custom() for MCP/
|
|
1026
|
+
// Manual custom() for MCP tools / custom routes / read auditing
|
|
952
1027
|
app.post('/orders/:id/refund', async (req) => {
|
|
953
1028
|
await app.audit.custom('order', req.params.id, 'refund', { reason }, { user });
|
|
954
1029
|
});
|
|
@@ -980,7 +1055,6 @@ permissions: {
|
|
|
980
1055
|
|
|
981
1056
|
```typescript
|
|
982
1057
|
// Typed request for raw routes — no more (req as any).user
|
|
983
|
-
// v2.8: `raw: true` replaces `wrapHandler: false` (wrapHandler still works but is deprecated)
|
|
984
1058
|
import type { ArcRequest } from '@classytic/arc';
|
|
985
1059
|
handler: async (req: ArcRequest, reply) => { req.user?.id; req.scope; req.signal; }
|
|
986
1060
|
|
|
@@ -996,15 +1070,16 @@ const { userId, organizationId, roles, orgRoles } = getOrgContext(request);
|
|
|
996
1070
|
import { createDomainError } from '@classytic/arc';
|
|
997
1071
|
throw createDomainError('SELF_REFERRAL', 'Cannot refer yourself', 422);
|
|
998
1072
|
|
|
999
|
-
//
|
|
1000
|
-
|
|
1001
|
-
|
|
1073
|
+
// Custom routes — always `routes: [...]` with optional `raw: true` for non-JSON
|
|
1074
|
+
defineResource({
|
|
1075
|
+
routes: [{ method: 'GET', path: '/stats', handler: 'getStats', permissions: allowPublic() }],
|
|
1076
|
+
});
|
|
1002
1077
|
|
|
1003
1078
|
// SSE auth — preAuth runs BEFORE auth middleware (EventSource can't set headers)
|
|
1004
|
-
|
|
1079
|
+
routes: [{ preAuth: [(req) => { req.headers.authorization = `Bearer ${req.query.token}`; }] }]
|
|
1005
1080
|
|
|
1006
|
-
// SSE streaming —
|
|
1007
|
-
|
|
1081
|
+
// SSE streaming — raw: true + stream the response
|
|
1082
|
+
routes: [{ method: 'GET', path: '/stream', raw: true, handler: async (req, reply) => reply.send(stream) }]
|
|
1008
1083
|
```
|
|
1009
1084
|
|
|
1010
1085
|
## DX Helpers (v2.7.3+)
|
|
@@ -1100,7 +1175,6 @@ import {
|
|
|
1100
1175
|
} from '@classytic/arc/scope';
|
|
1101
1176
|
import { createTenantKeyGenerator } from '@classytic/arc/scope';
|
|
1102
1177
|
import { createRoleHierarchy } from '@classytic/arc/permissions';
|
|
1103
|
-
import { createServiceClient } from '@classytic/arc/rpc';
|
|
1104
1178
|
import { metricsPlugin, versioningPlugin } from '@classytic/arc/plugins';
|
|
1105
1179
|
import { webhookPlugin } from '@classytic/arc/integrations/webhooks';
|
|
1106
1180
|
import { mcpPlugin, createMcpServer, defineTool, definePrompt, fieldRulesToZod, resourceToTools } from '@classytic/arc/mcp';
|
|
@@ -225,6 +225,100 @@ auth: {
|
|
|
225
225
|
}
|
|
226
226
|
```
|
|
227
227
|
|
|
228
|
+
## Service Identity (Machine Principals)
|
|
229
|
+
|
|
230
|
+
Arc distinguishes **machine callers** (API clients, spawned agents, cron workers) from **human users** via `RequestScope.service` — a first-class scope kind with `clientId` + OAuth-style `scopes`. Any auth mechanism (arc JWT, API keys, Better Auth client credentials, mTLS, gateway headers) can install it; arc does not ship a "service token" issuer — the app picks its credential flow and maps the result to scope.
|
|
231
|
+
|
|
232
|
+
Install service scope from your `authenticate` callback — arc's default JWT verify installs `member` scope by design, so custom authenticators are the extension point:
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
await createApp({
|
|
236
|
+
auth: {
|
|
237
|
+
type: 'jwt',
|
|
238
|
+
jwt: { secret: process.env.JWT_SECRET! },
|
|
239
|
+
authenticate: async (request, { jwt }) => {
|
|
240
|
+
const token = request.headers.authorization?.slice(7);
|
|
241
|
+
if (!token) return null;
|
|
242
|
+
const decoded = jwt.verify(token) as {
|
|
243
|
+
clientId?: string; userId?: string;
|
|
244
|
+
organizationId?: string; scopes?: string[];
|
|
245
|
+
};
|
|
246
|
+
// Machine principal — clientId present, no human user record.
|
|
247
|
+
if (decoded.clientId) {
|
|
248
|
+
request.scope = {
|
|
249
|
+
kind: 'service',
|
|
250
|
+
clientId: decoded.clientId,
|
|
251
|
+
organizationId: decoded.organizationId ?? '',
|
|
252
|
+
scopes: decoded.scopes ?? [],
|
|
253
|
+
};
|
|
254
|
+
return { clientId: decoded.clientId }; // returned value → request.user
|
|
255
|
+
}
|
|
256
|
+
// Human principal — fall through to user lookup.
|
|
257
|
+
return await User.findById(decoded.userId);
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Gate routes on service identity using the scope helpers + a permission builder:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { isService, getClientId, getServiceScopes } from '@classytic/arc/scope';
|
|
267
|
+
import type { PermissionCheck } from '@classytic/arc/permissions';
|
|
268
|
+
|
|
269
|
+
const requireScope = (scope: string): PermissionCheck => (ctx) => {
|
|
270
|
+
if (!isService(ctx.request.scope)) return { granted: false, reason: 'service only' };
|
|
271
|
+
const has = getServiceScopes(ctx.request.scope).includes(scope);
|
|
272
|
+
return has ? { granted: true } : { granted: false, reason: `missing scope: ${scope}` };
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
defineResource({
|
|
276
|
+
name: 'order',
|
|
277
|
+
permissions: { create: requireScope('orders:write') },
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Mixing humans and services on the same route** — compose arc's builders:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
// Humans with 'editor' role OR services with 'orders:write' scope
|
|
285
|
+
permissions: {
|
|
286
|
+
create: anyOf(requireOrgRole('editor'), requireScope('orders:write')),
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**Audit differentiation** — because `scope.kind === 'service'` carries `clientId` instead of `userId`, your audit plugin's `actor` resolver can tag machine actions distinctly:
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
auditPlugin({
|
|
294
|
+
actor: (request) =>
|
|
295
|
+
isService(request.scope)
|
|
296
|
+
? { kind: 'service', clientId: getClientId(request.scope) }
|
|
297
|
+
: { kind: 'user', userId: getUserId(request.scope) },
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**Rate-limit separation** — gate a separate bucket per `clientId` so one noisy agent can't starve humans in the same org:
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
rateLimit: {
|
|
305
|
+
keyGenerator: (req) =>
|
|
306
|
+
isService(req.scope) ? `svc:${getClientId(req.scope)}` : `org:${getOrgId(req.scope)}`,
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Credential-flow choice is the app's** — arc does not pick for you:
|
|
311
|
+
|
|
312
|
+
| Flow | Wire via `authenticate` callback |
|
|
313
|
+
|---|---|
|
|
314
|
+
| Arc JWT with `clientId` claim | example above |
|
|
315
|
+
| API key in header (DB lookup) | read `x-api-key`, look up client, set `scope` to service |
|
|
316
|
+
| Better Auth client credentials | `auth.api.getSession({ headers })`, detect client-credential grant |
|
|
317
|
+
| mTLS cert DN → client | read cert from terminator header, map DN → `clientId` |
|
|
318
|
+
| OAuth2 client-credentials | verify token via introspection endpoint |
|
|
319
|
+
|
|
320
|
+
All five produce the same downstream primitive: `RequestScope.service`. Permission builders, audit hooks, and rate-limit keys compose the same way regardless.
|
|
321
|
+
|
|
228
322
|
## Microservice Gateway Pattern
|
|
229
323
|
|
|
230
324
|
```
|