@classytic/arc 2.51.0 → 2.53.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/README.md +2 -1
- package/dist/{EventTransport-K7Q9WPjm.mjs → EventTransport-B3jTKMQH.mjs} +2 -2
- package/dist/{HookSystem-DBAu9uNT.mjs → HookSystem-DNwxV463.mjs} +2 -2
- package/dist/{ResourceRegistry-BelzCRMy.mjs → ResourceRegistry-Ck7RFodL.mjs} +2 -2
- package/dist/{acquire-B0zhfGSm.mjs → acquire-DkLruwhL.mjs} +1 -1
- package/dist/audit/index.d.mts +1 -1
- package/dist/audit/index.mjs +4 -4
- package/dist/auth/audit.mjs +1 -1
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.mjs +7 -7
- package/dist/auth/redis-session.mjs +1 -1
- package/dist/auth/social/index.mjs +1 -1
- package/dist/{authorizationDecision-Dxj_cy6N.mjs → authorizationDecision-gB5-bHDp.mjs} +9 -7
- package/dist/bootError-BT3z3cvX.mjs +38 -0
- package/dist/{boundedMap-DOBai-H3.mjs → boundedMap-Ddw2yGb2.mjs} +1 -1
- package/dist/{buildHandler-Dyl8P9j0.mjs → buildHandler-B8IDGmhD.mjs} +5 -5
- package/dist/cache/index.mjs +4 -4
- package/dist/{caching-CUmaNL8Y.mjs → caching-BitJDAY0.mjs} +2 -2
- package/dist/{claimed-DJPk4VZr.mjs → claimed-CM_-lFHX.mjs} +1 -1
- package/dist/cleanup/index.d.mts +2 -2
- package/dist/cleanup/index.mjs +4 -4
- package/dist/cli/commands/describe.d.mts +18 -1
- package/dist/cli/commands/describe.mjs +39 -7
- package/dist/cli/commands/docs.mjs +3 -3
- package/dist/cli/commands/doctor.d.mts +3 -1
- package/dist/cli/commands/doctor.mjs +135 -22
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/commands/init.mjs +2 -2
- package/dist/cli/commands/introspect.mjs +2 -2
- package/dist/cli/index.mjs +3 -3
- package/dist/{constants-DH41jnNT.mjs → constants-D9EiaO5s.mjs} +1 -1
- package/dist/context/index.d.mts +5 -2
- package/dist/context/index.mjs +5 -5
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +7 -7
- package/dist/{core-DPmRWlpx.mjs → core-B_06Fcn0.mjs} +3 -3
- package/dist/{createActionRouter-B1xhER6i.mjs → createActionRouter-DtxUXOCI.mjs} +5 -5
- package/dist/{createAggregationRouter-CNntJL-z.mjs → createAggregationRouter-BMiKyDoW.mjs} +7 -7
- package/dist/{createApp-DpG26bCu.mjs → createApp-CEdGZtkP.mjs} +207 -44
- package/dist/{createMcpServer-CS2KOVP6.d.mts → createMcpServer-Bk3ls5jS.d.mts} +1 -1
- package/dist/{defineAggregation-rI3EbZUg.mjs → defineAggregation-DUsrGcsm.mjs} +1 -1
- package/dist/{defineResource-5DcG_wlI.mjs → defineResource-q8TsJpOm.mjs} +92 -36
- package/dist/deprecation-DX625dth.mjs +27 -0
- package/dist/discovery/index.mjs +1 -1
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +3 -3
- package/dist/{elevation-XFu7J3aj.mjs → elevation-NJ3908pJ.mjs} +5 -5
- package/dist/encryption/index.d.mts +26 -1
- package/dist/encryption/index.mjs +56 -6
- package/dist/{errorHandler-xDVUWOMu.mjs → errorHandler-Ke6PGvF7.mjs} +7 -4
- package/dist/{errors-KBZ3tQk5.mjs → errors-Ukhmfmmx.mjs} +1 -1
- package/dist/{eventPlugin-BY38F6yK.d.mts → eventPlugin-BeJasppx.d.mts} +7 -18
- package/dist/{eventPlugin-C4lNj2Dw.mjs → eventPlugin-DTKAgSvb.mjs} +10 -8
- package/dist/{eventTypes-DZRoUAdk.mjs → eventTypes-DpDQtyR6.mjs} +2 -2
- package/dist/events/index.d.mts +2 -2
- package/dist/events/index.mjs +8 -8
- package/dist/events/transports/redis-stream-entry.mjs +4 -4
- package/dist/events/transports/redis.mjs +2 -2
- package/dist/factory/index.d.mts +28 -5
- package/dist/factory/index.mjs +12 -7
- package/dist/{fastify-augmentation-baQc3MaO.d.mts → fastify-augmentation-DjxuSRG4.d.mts} +4 -3
- package/dist/{fieldTypes-DrXUW1jc.mjs → fieldTypes-BtFpQO6I.mjs} +2 -2
- package/dist/{fields-C5J8WTd2.mjs → fields-B7fuROWK.mjs} +1 -1
- package/dist/{filter-merge-DTjYoDrj.mjs → filter-merge-BuzZ-r9z.mjs} +1 -1
- package/dist/{generate-SA8oMlLB.mjs → generate-c4F39pk1.mjs} +4 -4
- package/dist/{headers-D5wrBLOk.mjs → headers-Ib7BDgRI.mjs} +2 -2
- package/dist/{health-BLal039H.mjs → health-22T82HAa.mjs} +1 -1
- package/dist/health-skjSwNaC.d.mts +36 -0
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.mjs +2 -2
- package/dist/http-cache/index.mjs +4 -4
- package/dist/http-cache/purgers/cloudflare.mjs +2 -2
- package/dist/http-cache/purgers/fastly.mjs +2 -2
- package/dist/http-cache/testing/index.mjs +1 -1
- package/dist/idempotency/index.d.mts +7 -1
- package/dist/idempotency/index.mjs +9 -7
- package/dist/idempotency/redis.mjs +2 -2
- package/dist/{index-CMNpMBtW.d.mts → index-BzUyno-u.d.mts} +14 -5
- package/dist/{index-Dhrks-hM.d.mts → index-CXqYFGoH.d.mts} +13 -4
- package/dist/{index-DexdFs1a.d.mts → index-CaBFPmnu.d.mts} +29 -7
- package/dist/{index-DKM2p5w5.d.mts → index-DWn0o4U7.d.mts} +2 -2
- package/dist/{index-DLCcLUQT.d.mts → index-DtHACefu.d.mts} +109 -116
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +12 -12
- package/dist/{init-DeKHaNZn.mjs → init-XY5slyuS.mjs} +3 -3
- package/dist/integrations/event-gateway.mjs +2 -2
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/index.mjs +1 -1
- package/dist/integrations/jobs/index.mjs +3 -3
- package/dist/integrations/mcp/index.d.mts +9 -4
- package/dist/integrations/mcp/index.mjs +2 -2
- package/dist/integrations/mcp/testing.d.mts +2 -2
- package/dist/integrations/mcp/testing.mjs +2 -2
- package/dist/integrations/streamline.mjs +3 -3
- package/dist/integrations/webhooks.d.mts +1 -1
- package/dist/integrations/webhooks.mjs +4 -4
- package/dist/integrations/websocket-pushref-redis.mjs +1 -1
- package/dist/integrations/websocket-redis.mjs +1 -1
- package/dist/integrations/websocket.mjs +2 -2
- package/dist/invariants-COekUeoh.mjs +120 -0
- package/dist/{jsonBody-rDPGT5A9.mjs → jsonBody-BNlcGUnb.mjs} +2 -2
- package/dist/{keys-t7i-lJ2r.mjs → keys-DwvXJwUX.mjs} +1 -1
- package/dist/{loadResources-CcupAVJH.mjs → loadResources-izEeQLO_.mjs} +3 -3
- package/dist/{loadResourcesFromEntry-BpjYlaoj.mjs → loadResourcesFromEntry-CijqjbHE.mjs} +2 -2
- package/dist/logger/index.mjs +2 -2
- package/dist/{logger-IL7Btm-N.mjs → logger-DdMS0XC_.mjs} +1 -1
- package/dist/{mcpPlugin-BsdH7Vot.mjs → mcpPlugin-D0tSZqKk.mjs} +24 -22
- package/dist/{memory-Dkp6ZD3F.mjs → memory-Ay0haw9n.mjs} +3 -3
- package/dist/{metrics-CDPqgdKr.mjs → metrics-Bpgf4UL6.mjs} +3 -3
- package/dist/middleware/index.d.mts +1 -1
- package/dist/middleware/index.mjs +3 -3
- package/dist/migrations/index.mjs +2 -2
- package/dist/{module-KFxT1Iuk.mjs → module-BLrTmMyk.mjs} +17 -2
- package/dist/{multiTenant-QtDzxx_K.d.mts → multiTenant-Cf0Ye-Wu.d.mts} +1 -1
- package/dist/{multipartBody-BHktuarE.mjs → multipartBody-L2gr96df.mjs} +1 -1
- package/dist/{observeSend-CY-sLanc.mjs → observeSend-B7FEdk_g.mjs} +1 -1
- package/dist/{openapi-DbeXiy2v.mjs → openapi-COrL_33P.mjs} +6 -6
- package/dist/outbox-admin/index.d.mts +1 -1
- package/dist/outbox-admin/index.mjs +6 -6
- package/dist/{outbox-module-BWqkTE8-.mjs → outbox-module-BY2HtnjU.mjs} +7 -7
- package/dist/{outbox-module-DzW6zwWJ.d.mts → outbox-module-C1QWMloZ.d.mts} +5 -8
- package/dist/permissions/index.d.mts +2 -2
- package/dist/permissions/index.mjs +8 -8
- package/dist/{permissions-e5YMrFbm.mjs → permissions-CEyeDHtT.mjs} +36 -17
- package/dist/{pipe-CMnKfdF4.mjs → pipe-DIAr91at.mjs} +2 -2
- package/dist/pipeline/index.d.mts +1 -1
- package/dist/pipeline/index.mjs +2 -2
- package/dist/{plan-BvLJGm3U.mjs → plan-BhKHIkFl.mjs} +75 -20
- package/dist/{plugin-DYmu8uT4.mjs → plugin-D6hrdx-j.mjs} +72 -38
- package/dist/plugins/index.d.mts +4 -3
- package/dist/plugins/index.mjs +18 -18
- package/dist/plugins/response-cache.mjs +4 -4
- package/dist/plugins/tracing-entry.mjs +177 -85
- package/dist/{pluralize-ClwfBdIx.mjs → pluralize-CJKgYkVc.mjs} +1 -1
- package/dist/presetPermission-2pcRVYRG.mjs +23 -0
- package/dist/presets/filesUpload.d.mts +4 -2
- package/dist/presets/filesUpload.mjs +11 -6
- package/dist/presets/index.d.mts +6 -4
- package/dist/presets/index.mjs +2 -2
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +5 -5
- package/dist/presets/search.d.mts +2 -2
- package/dist/presets/search.mjs +54 -38
- package/dist/{presets-DX_lPabi.mjs → presets-st11ePNn.mjs} +150 -41
- package/dist/{projection-DnZiFPPE.mjs → projection-B4rqiJTi.mjs} +2 -2
- package/dist/{purger.types-BEzTVDOU.mjs → purger.types-BcHeAhY_.mjs} +1 -1
- package/dist/{queryCachePlugin-C57-Nj-g.mjs → queryCachePlugin-BgSc2bga.mjs} +6 -6
- package/dist/rateLimitKey-DLGdeFd2.mjs +138 -0
- package/dist/{realtime-C-VIoXMg.mjs → realtime-CpYpIFsm.mjs} +11 -11
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.mjs +3 -3
- package/dist/{registry-DbQvODPH.mjs → registry-BQsdAlZ_.mjs} +2 -2
- package/dist/{relay-B61seKq1.mjs → relay-CmT3gtkP.mjs} +11 -12
- package/dist/{renewingLease-Dp7wmzNN.mjs → renewingLease-DaoP0K-e.mjs} +1 -1
- package/dist/{replyHelpers-CHii_jIO.mjs → replyHelpers-SiLr1wK4.mjs} +2 -2
- package/dist/{requestContext-C_mbAm8o.mjs → requestContext-B-TjFpWt.mjs} +8 -3
- package/dist/{health-vEo3fni4.mjs → requestId-ClcKoWLq.mjs} +154 -116
- package/dist/{requirement-C8OsWLYp.mjs → requirement-BygDzjDS.mjs} +1 -1
- package/dist/{resourceRateLimit-DhbQZjE2.mjs → resourceRateLimit-DdIYis3m.mjs} +2 -2
- package/dist/{rolldown-runtime-HTi8KV7V.mjs → rolldown-runtime-Cy6j0m8_.mjs} +1 -1
- package/dist/{routeValidator-DnQ2BGnH.mjs → routeValidator-Bn-x2gaJ.mjs} +1 -1
- package/dist/{runtimeCapabilities-G9QXHov1.mjs → runtimeCapabilities-DY20Pibh.mjs} +7 -2
- package/dist/{schedules-DAthT5O3.mjs → schedules-CwqC0Mp0.mjs} +5 -5
- package/dist/{schemaConverter-BOt_ed78.mjs → schemaConverter-XoLKVpzG.mjs} +2 -2
- package/dist/{schemaIR-MZVVj6Cw.mjs → schemaIR-DP7mMj7c.mjs} +16 -16
- package/dist/schemas/index.mjs +1 -1
- package/dist/scim/index.mjs +2 -2
- package/dist/scope/index.d.mts +6 -2
- package/dist/scope/index.mjs +5 -5
- package/dist/{scope-btg-225w.mjs → scope-B0vgM2Zw.mjs} +4 -4
- package/dist/{shutdown-Dfy8La90.mjs → shutdown-C76Hn-Th.mjs} +1 -1
- package/dist/{simpleEqualityMatcher-D5dOqbbj.mjs → simpleEqualityMatcher-Qbl-11cE.mjs} +1 -1
- package/dist/{sse-DivxX1m6.mjs → sse-eyb8lNuI.mjs} +7 -7
- package/dist/{sseStream-hQxQjvre.mjs → sseStream-BsBesrfw.mjs} +2 -2
- package/dist/{store-helpers-DfqfssAw.mjs → store-helpers-D1yIVa91.mjs} +1 -1
- package/dist/{streaming-CQiOktsh.mjs → streaming-DKziqs1Z.mjs} +1 -1
- package/dist/{subscriberIdentity-Bf8VLqA7.mjs → subscriberIdentity-DpdSQMQq.mjs} +1 -1
- package/dist/{tenancy-Btmaf1MB.mjs → tenancy-YuRYsOPr.mjs} +2 -2
- package/dist/{tenantPreparation-4e3qyb6q.mjs → tenantPreparation-Bk8ouRB3.mjs} +17 -5
- package/dist/testing/cleanupStoreContract.mjs +1 -1
- package/dist/testing/index.d.mts +4 -4
- package/dist/testing/index.mjs +11 -11
- package/dist/testing/outboxStoreContract.mjs +2 -2
- package/dist/testing/requiredPorts.d.mts +1 -1
- package/dist/testing/requiredPorts.mjs +2 -2
- package/dist/testing/storageContract.mjs +1 -1
- package/dist/{timing-DXx0IWyi.mjs → timing-BtIDIdQz.mjs} +1 -1
- package/dist/{transactionContext-DperjON1.mjs → transactionContext-BsQ5ortM.mjs} +1 -1
- package/dist/{typeGuards-eoQLIOh6.mjs → typeGuards-Cr2_zEW0.mjs} +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +1 -1
- package/dist/types/storage.mjs +1 -1
- package/dist/{types-BeEJm-DV.d.mts → types-CQhHTZXs.d.mts} +48 -35
- package/dist/{types-B4E0sc6D.d.mts → types-DWFgq8EP.d.mts} +1 -1
- package/dist/{types-CcpISJe8.mjs → types-ZvdR7MVa.mjs} +4 -4
- package/dist/usage/index.mjs +4 -4
- package/dist/{userHelpers-Cp5zqlEN.mjs → userHelpers-CwpEK36a.mjs} +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +12 -12
- package/dist/{utils-dKN-_315.mjs → utils-CnrfcYMq.mjs} +6 -6
- package/dist/{validate-BZHaAdgy.mjs → validate-BTQBh-Dr.mjs} +3 -3
- package/dist/{versioning-CPLP0VbB.mjs → versioning-DiLykI6U.mjs} +3 -3
- package/dist/{workScope-BI72KXsI.mjs → workScope-C3tPz_Gt.mjs} +2 -2
- package/package.json +34 -9
- package/skills/arc/SKILL.md +5 -5
- package/skills/arc/references/api-reference.md +1 -1
- package/skills/arc/references/boot.md +17 -2
- package/skills/arc/references/events.md +0 -1
- package/skills/arc/references/mcp-setup.md +3 -2
- package/skills/arc/references/multi-tenancy.md +1 -1
- package/skills/arc/references/production-api.md +19 -12
- package/skills/arc/references/production-audit.md +1 -1
- package/skills/arc/references/production-boot.md +3 -3
- package/skills/arc/references/production-idempotency.md +2 -2
- package/skills/arc/references/production-observability.md +14 -2
- package/skills/arc/references/production-reliability.md +1 -1
- package/skills/arc/references/querying.md +1 -2
- package/skills/arc/references/resources.md +8 -6
- package/skills/arc/references/testing.md +1 -1
- package/skills/arc-code-review/references/arc-cheatsheet.md +1 -1
- package/skills/arc-code-review/references/recipe-scope-permissions.md +1 -1
- package/skills/arc-module-publishing/references/resource-assembly.md +2 -2
- package/dist/rateLimitKey-B1RxyGt3.mjs +0 -40
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { n as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { d as createPresetControllerHandle, n as getAvailablePresets, t as applyPresets } from "./presets-st11ePNn.mjs";
|
|
3
|
+
import { t as arcLog } from "./logger-DdMS0XC_.mjs";
|
|
4
|
+
import { C as isWriteVerbCapable, S as detectOverriddenWriteSlots, f as BaseController, i as resolveOpenApiSchemas, l as autoInjectTenantFieldRules, t as buildResourcePlugin } from "./plugin-D6hrdx-j.mjs";
|
|
5
|
+
import { m as MUTATION_OPERATIONS, t as CRUD_OPERATIONS } from "./constants-D9EiaO5s.mjs";
|
|
6
|
+
import { n as warnDeprecated } from "./deprecation-DX625dth.mjs";
|
|
7
|
+
import { B as requireAuth, F as allowPublic } from "./permissions-CEyeDHtT.mjs";
|
|
8
|
+
import { n as unresolvedPresetPermission } from "./presetPermission-2pcRVYRG.mjs";
|
|
9
|
+
import { t as pluralize } from "./pluralize-CJKgYkVc.mjs";
|
|
10
|
+
import { a as isZodSchema, i as isJsonSchema } from "./schemaConverter-XoLKVpzG.mjs";
|
|
9
11
|
import { isReadOnlyRepo } from "@classytic/repo-core/repository";
|
|
10
12
|
import { readEnv } from "@classytic/primitives/environment";
|
|
11
13
|
// src/core/defineResource/writeVerbs.ts
|
|
@@ -94,7 +96,7 @@ function resolveOrAutoCreateController(resolvedConfig, adapter, repository, hasC
|
|
|
94
96
|
if (repository && isReadOnlyRepo(repository)) {
|
|
95
97
|
const disabled = new Set(resolvedConfig.disabledRoutes ?? []);
|
|
96
98
|
const enabledWrites = READ_ONLY_REFUSED_ROUTES.filter((op) => !resolvedConfig.disableDefaultRoutes && !disabled.has(op));
|
|
97
|
-
if (enabledWrites.length > 0) throw new Error(`Resource "${resolvedConfig.name}" mounts write routes (${enabledWrites.join(", ")}) over a READ-ONLY repository — its rows are owned by another component that enforces invariants generic CRUD would bypass (Better Auth hashes passwords, revokes sessions, and cascades org membership on every write it performs). Disable the write routes (\`
|
|
99
|
+
if (enabledWrites.length > 0) throw new Error(`Resource "${resolvedConfig.name}" mounts write routes (${enabledWrites.join(", ")}) over a READ-ONLY repository — its rows are owned by another component that enforces invariants generic CRUD would bypass (Better Auth hashes passwords, revokes sessions, and cascades org membership on every write it performs). Disable the write routes (\`crud: { list: true, get: true }\`), or if raw writes are genuinely required, build the repository with the kit's explicit \`unsafeWritable: true\` opt-in.`);
|
|
98
100
|
}
|
|
99
101
|
if (userController) {
|
|
100
102
|
bindControllerResourceName(userController, resolvedConfig.name);
|
|
@@ -249,6 +251,26 @@ function assertTransactionCapability(repository, resourceName) {
|
|
|
249
251
|
if (!capabilities || capabilities.transactions === true) return;
|
|
250
252
|
throw new Error(`Resource "${resourceName}" declares \`transactional: true\` but its repository reports \`capabilities.transactions: ${String(capabilities.transactions)}\` — this deployment cannot run transactions (standalone MongoDB, D1, or a topology arc could not confirm). \`withTransaction\` exists but every call would fail at BEGIN. Point at a replica set / transactional backend, or remove the flag. Checked at REGISTRATION, so a connection opened in \`beforeBoot()\` is already live by now.`);
|
|
251
253
|
}
|
|
254
|
+
// src/core/defineResource/deprecations.ts
|
|
255
|
+
/**
|
|
256
|
+
* Phase 0 side channel — warn (once per process) about deprecated config
|
|
257
|
+
* spellings. Reads the CALLER's config, never the normalised copy: Phase 0
|
|
258
|
+
* itself produces `disabledRoutes` / `disableDefaultRoutes` from `crud` and
|
|
259
|
+
* `customRoutesOnly`, so arc never triggers a warning here. Routes a preset adds
|
|
260
|
+
* are checked where presets merge (`warnDeprecatedPresetRoutes` in `presets/`).
|
|
261
|
+
*/
|
|
262
|
+
const FUNCTION_HANDLER_FIX = "Use a function `handler: (ctx) => controller.method(ctx)` (arc pipeline + MCP tool); `rawHandler` takes a function for streams, raw-body webhooks, files and redirects.";
|
|
263
|
+
function warnDeprecatedConfig(config) {
|
|
264
|
+
const name = config.name;
|
|
265
|
+
if (config.disableDefaultRoutes !== void 0) warnDeprecated("`disableDefaultRoutes`", `Use \`crud: false\` (first seen on resource '${name}').`);
|
|
266
|
+
if (config.disabledRoutes !== void 0) warnDeprecated("`disabledRoutes`", `Use the \`crud\` allow-list: \`disabledRoutes: ['delete']\` becomes \`crud: { list: true, get: true, create: true, update: true }\` (first seen on resource '${name}').`);
|
|
267
|
+
for (const route of config.routes ?? []) {
|
|
268
|
+
const where = `(first seen on ${route.method} ${route.path} of resource '${name}')`;
|
|
269
|
+
if (typeof route.handler === "string") warnDeprecated("A string route `handler`", `${FUNCTION_HANDLER_FIX} ${where}`);
|
|
270
|
+
if (route.controllerMethod !== void 0) warnDeprecated("Route `controllerMethod`", `${FUNCTION_HANDLER_FIX} ${where}`);
|
|
271
|
+
if (typeof route.rawHandler === "string") warnDeprecated("A string route `rawHandler`", "Pass the function: `rawHandler: (request, reply) => controller.method(request, reply)`. " + where);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
252
274
|
// src/core/defineResource/hooks.ts
|
|
253
275
|
/**
|
|
254
276
|
* Combined entry-point for Phase 6. Pushes preset-collected hooks
|
|
@@ -518,15 +540,17 @@ function resolveCrudAllowList(config) {
|
|
|
518
540
|
* shape — `defineResource()` only ever consults `resolvedConfig`,
|
|
519
541
|
* never the raw user input, after this phase runs.
|
|
520
542
|
*/
|
|
543
|
+
const PRESET_ROUTE_PUBLIC_BY_OMISSION = "preset-route-public-by-omission";
|
|
521
544
|
/**
|
|
522
545
|
* Run the Phase 3 pipeline: clone → apply presets → infer tenant
|
|
523
546
|
* field → auto-inject system-managed rules. Returns the resolved
|
|
524
|
-
* `InternalResourceConfig` that every later phase consumes.
|
|
547
|
+
* `InternalResourceConfig` that every later phase consumes. `controller` is the
|
|
548
|
+
* handle preset `routes(permissions, controller)` builders receive; Phase 4 binds it.
|
|
525
549
|
*/
|
|
526
|
-
function applyPresetsAndAutoInject(config) {
|
|
550
|
+
function applyPresetsAndAutoInject(config, controller) {
|
|
527
551
|
const originalPresets = (config.presets ?? []).map((p) => typeof p === "string" ? p : p.name);
|
|
528
552
|
const declaredKeys = new Set(Object.keys(config).filter((k) => config[k] !== void 0));
|
|
529
|
-
const resolvedConfig = config.presets?.length ? applyPresets(config, config.presets) : { ...config };
|
|
553
|
+
const resolvedConfig = config.presets?.length ? applyPresets(config, config.presets, controller) : { ...config };
|
|
530
554
|
resolvedConfig._appliedPresets = originalPresets;
|
|
531
555
|
resolvedConfig._declaredKeys = declaredKeys;
|
|
532
556
|
inferTenantFieldFromAdapter(resolvedConfig);
|
|
@@ -577,6 +601,32 @@ function computeHasCrudRoutes(config) {
|
|
|
577
601
|
const disabled = new Set(config.disabledRoutes ?? []);
|
|
578
602
|
return !config.disableDefaultRoutes && CRUD_OPERATIONS.some((op) => !disabled.has(op));
|
|
579
603
|
}
|
|
604
|
+
/**
|
|
605
|
+
* Preset routes whose permission resolved to nothing (no preset option, no resource
|
|
606
|
+
* permission to inherit; see `presetPermission`). The CRUD-read ladder: `error` under
|
|
607
|
+
* `strict`; otherwise `info`, and the route is mounted public (`allowPublic()`), as an
|
|
608
|
+
* ungated CRUD read is. Rewrites `config.routes` (a fresh array owned by `resolvedConfig`).
|
|
609
|
+
*/
|
|
610
|
+
function resolvePresetRoutePermissions(config, strict = false) {
|
|
611
|
+
const diagnostics = [];
|
|
612
|
+
const routes = config.routes?.map((route) => {
|
|
613
|
+
const unresolved = unresolvedPresetPermission(route.permissions);
|
|
614
|
+
if (!unresolved) return route;
|
|
615
|
+
const { preset, inherits, option } = unresolved;
|
|
616
|
+
const where = `${route.method} ${route.path}`;
|
|
617
|
+
diagnostics.push({
|
|
618
|
+
severity: strict ? "error" : "info",
|
|
619
|
+
code: PRESET_ROUTE_PUBLIC_BY_OMISSION,
|
|
620
|
+
message: `[Arc] Resource '${config.name}': preset '${preset}' route ${where} has no permission (it inherits permissions.${inherits}, which is not set).\n` + (strict ? "strictPermissions is on and an ungated READ is fatal. State intent explicitly:\n" : "It is mounted WITHOUT auth. State intent explicitly:\n") + ` permissions: { ${inherits}: allowPublic(), ... } // intentionally public\n permissions: { ${inherits}: requireAuth(), ... } // or requireRoles([...])` + (option ? `\n ${option} // this route only` : "")
|
|
621
|
+
});
|
|
622
|
+
return strict ? route : {
|
|
623
|
+
...route,
|
|
624
|
+
permissions: allowPublic()
|
|
625
|
+
};
|
|
626
|
+
});
|
|
627
|
+
if (routes && !strict && diagnostics.length > 0) config.routes = routes;
|
|
628
|
+
return diagnostics;
|
|
629
|
+
}
|
|
580
630
|
const WRITE_OPERATIONS = /* @__PURE__ */ new Set([
|
|
581
631
|
"create",
|
|
582
632
|
"update",
|
|
@@ -595,18 +645,15 @@ const WRITE_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
595
645
|
* wiring, ...) count as gates and don't false-positive.
|
|
596
646
|
*
|
|
597
647
|
* Severity ladder:
|
|
598
|
-
* - `error` when
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
* - `info` when only reads are ungated — public catalogs
|
|
605
|
-
* (`referenceData: true`) are a legitimate shape, but the host should
|
|
606
|
-
* still state intent with `permissions.fullPublic()` / `allowPublic()`.
|
|
648
|
+
* - `error` when ANY enabled op is ungated AND `strict` is on — the resource
|
|
649
|
+
* fails boot (`defineResource()` throws). An ungated read is as fatal as an
|
|
650
|
+
* ungated write: a public catalog states it with `allowPublic()`, so an
|
|
651
|
+
* accidental public read never ships.
|
|
652
|
+
* - `warn` (strict off) when an enabled WRITE op is ungated.
|
|
653
|
+
* - `info` (strict off) when only reads are ungated.
|
|
607
654
|
*
|
|
608
|
-
* `strict`
|
|
609
|
-
* `ARC_STRICT_PERMISSIONS` env
|
|
655
|
+
* The caller resolves `strict` (resource `strictPermissions`, else the
|
|
656
|
+
* `ARC_STRICT_PERMISSIONS` env, which is on unless set to false).
|
|
610
657
|
*/
|
|
611
658
|
function collectUngatedCrudDiagnostics(config, strict = false) {
|
|
612
659
|
if (config.disableDefaultRoutes) return [];
|
|
@@ -614,13 +661,15 @@ function collectUngatedCrudDiagnostics(config, strict = false) {
|
|
|
614
661
|
const permissions = config.permissions ?? {};
|
|
615
662
|
const ungated = CRUD_OPERATIONS.filter((op) => !disabled.has(op) && typeof permissions[op] !== "function");
|
|
616
663
|
if (ungated.length === 0) return [];
|
|
617
|
-
const
|
|
664
|
+
const hasUngatedWrite = ungated.some((op) => WRITE_OPERATIONS.has(op));
|
|
665
|
+
const severity = strict ? "error" : hasUngatedWrite ? "warn" : "info";
|
|
666
|
+
const ungatedReads = ungated.filter((op) => !WRITE_OPERATIONS.has(op));
|
|
618
667
|
return [{
|
|
619
668
|
severity,
|
|
620
669
|
code: "crud-public-by-omission",
|
|
621
|
-
message: `[Arc] Resource '${config.name}' mounts ${ungated.length} CRUD route(s) with no permission gate: ${ungated.join(", ")}.\n` + (severity === "error" ?
|
|
622
|
-
permissions:
|
|
623
|
-
permissions: { ${ungated[0]}: requireAuth(), ... } // per-operation` + (severity === "warn" ? "\nRecommended in production: ARC_STRICT_PERMISSIONS=true (or `strictPermissions: true` on the resource) makes an ungated WRITE fail the boot instead of shipping.
|
|
670
|
+
message: `[Arc] Resource '${config.name}' mounts ${ungated.length} CRUD route(s) with no permission gate: ${ungated.join(", ")}.\n` + (severity === "error" ? `strictPermissions is on and an ungated ${hasUngatedWrite ? "WRITE" : "READ"} is fatal. State intent explicitly:\n` : "An omitted permission mounts the route WITHOUT auth. State intent explicitly:\n") + (ungatedReads.length > 0 ? ` permissions: { ${ungatedReads.map((op) => `${op}: allowPublic()`).join(", ")}, ... } // intentionally public reads\n` : "") + ` permissions: fullPublic() // every op intentionally public
|
|
671
|
+
permissions: authenticated() // require auth on every op
|
|
672
|
+
permissions: { ${ungated[0]}: requireAuth(), ... } // per-operation` + (severity === "warn" ? "\nRecommended in production: ARC_STRICT_PERMISSIONS=true (or `strictPermissions: true` on the resource) makes an ungated WRITE fail the boot instead of shipping. Strict permissions is the default; this resource or app has switched it off." : "")
|
|
624
673
|
}];
|
|
625
674
|
}
|
|
626
675
|
// src/registry/resolveTenantPurge.ts
|
|
@@ -1072,15 +1121,15 @@ function validateResourceConfig(config, options = {}) {
|
|
|
1072
1121
|
});
|
|
1073
1122
|
if (declared.length > 0 && config.disableDefaultRoutes) errors.push({
|
|
1074
1123
|
field: "writes",
|
|
1075
|
-
message: `Resource declares write verb(s) [${declared.join(", ")}] but \`
|
|
1076
|
-
suggestion: "
|
|
1124
|
+
message: `Resource declares write verb(s) [${declared.join(", ")}] but \`crud: false\` means no CRUD slot will call them`,
|
|
1125
|
+
suggestion: "Allow the slots in `crud` so they mount, or move the command into a custom route / action and remove `writes`"
|
|
1077
1126
|
});
|
|
1078
1127
|
else if (declared.length > 0) {
|
|
1079
1128
|
const notMounted = declared.filter((op) => disabledRoutes.has(op));
|
|
1080
1129
|
if (notMounted.length > 0) errors.push({
|
|
1081
1130
|
field: "writes",
|
|
1082
1131
|
message: `Write verb(s) [${notMounted.join(", ")}] are declared but those CRUD slots are disabled, so the verbs can never run`,
|
|
1083
|
-
suggestion: `
|
|
1132
|
+
suggestion: `Allow [${notMounted.join(", ")}] in \`crud\`, or delete the matching \`writes\` entr(ies) — a command nothing calls is decoration`
|
|
1084
1133
|
});
|
|
1085
1134
|
}
|
|
1086
1135
|
}
|
|
@@ -1191,7 +1240,7 @@ function validatePresetOptions(preset, warnings) {
|
|
|
1191
1240
|
* Without this check, a custom `POST /` on the same prefix as auto-CRUD's
|
|
1192
1241
|
* `create` boots fine through `defineResource()` and only blows up at
|
|
1193
1242
|
* `app.register()` time with Fastify's opaque `FST_ERR_DUPLICATED_ROUTE`.
|
|
1194
|
-
* That error doesn't mention `
|
|
1243
|
+
* That error doesn't mention `crud` and doesn't distinguish
|
|
1195
1244
|
* "you collided with auto-CRUD" from "you collided with yourself" — so
|
|
1196
1245
|
* the consumer has to grep arc's source to discover the fix.
|
|
1197
1246
|
*
|
|
@@ -1244,7 +1293,7 @@ function validateRouteCrudCollisions(config, errors) {
|
|
|
1244
1293
|
errors.push({
|
|
1245
1294
|
field: `routes[${i}]`,
|
|
1246
1295
|
message: `Route ${route.method} ${route.path} collides with auto-CRUD "${crud.op}"`,
|
|
1247
|
-
suggestion: `
|
|
1296
|
+
suggestion: `Leave "${crud.op}" out of the \`crud\` allow-list (\`crud: { ${CRUD_OPERATIONS.filter((op) => op !== crud.op && !disabled.has(op)).map((op) => `${op}: true`).join(", ")} }\`) to suppress the auto-CRUD route, or move your custom handler to a different path. Set \`crud: false\` to disable all auto-CRUD on this resource.`
|
|
1248
1297
|
});
|
|
1249
1298
|
}
|
|
1250
1299
|
}
|
|
@@ -1278,8 +1327,8 @@ function validateRoutes(routes, errors) {
|
|
|
1278
1327
|
const routeWithRefs = route;
|
|
1279
1328
|
if (!route.handler && !route.rawHandler && typeof routeWithRefs.controllerMethod !== "function") errors.push({
|
|
1280
1329
|
field: `routes[${i}].handler`,
|
|
1281
|
-
message: "Route must declare
|
|
1282
|
-
suggestion: "
|
|
1330
|
+
message: "Route must declare a function `handler` (arc pipeline) or a function `rawHandler` (Fastify-native)",
|
|
1331
|
+
suggestion: "Call the controller from a function handler: `handler: (ctx) => controller.method(ctx)`."
|
|
1283
1332
|
});
|
|
1284
1333
|
if (route.handler && route.rawHandler) errors.push({
|
|
1285
1334
|
field: `routes[${i}].rawHandler`,
|
|
@@ -1588,22 +1637,28 @@ function validateActionsShape(config) {
|
|
|
1588
1637
|
* ```
|
|
1589
1638
|
*/
|
|
1590
1639
|
function defineResource(config) {
|
|
1640
|
+
warnDeprecatedConfig(config);
|
|
1591
1641
|
const normalisedConfig = normalizeResourceConfig(config);
|
|
1592
1642
|
let diagnostics = [];
|
|
1593
1643
|
if (!normalisedConfig.skipValidation) diagnostics = validateDefineResourceConfig(normalisedConfig);
|
|
1594
1644
|
else validateSecurityInvariants(normalisedConfig);
|
|
1595
1645
|
const repository = normalisedConfig.adapter?.repository;
|
|
1596
1646
|
const configWithId = resolveIdField(normalisedConfig, repository);
|
|
1597
|
-
const
|
|
1647
|
+
const presetController = createPresetControllerHandle(configWithId.name);
|
|
1648
|
+
const resolvedConfig = applyPresetsAndAutoInject(configWithId, presetController.controller);
|
|
1598
1649
|
const hasCrudRoutes = computeHasCrudRoutes(resolvedConfig);
|
|
1599
1650
|
const strict = resolvedConfig.strictPermissions ?? readEnv(process.env).bool("ARC_STRICT_PERMISSIONS", true);
|
|
1600
1651
|
diagnostics = diagnostics.concat(collectUngatedCrudDiagnostics(resolvedConfig, strict));
|
|
1652
|
+
diagnostics = diagnostics.concat(resolvePresetRoutePermissions(resolvedConfig, strict));
|
|
1601
1653
|
diagnostics = diagnostics.concat(collectSchemaSlotDiagnostics(resolvedConfig, resolvedConfig.strictSchemas ?? readEnv(process.env).bool("ARC_STRICT_SCHEMAS", false)));
|
|
1602
1654
|
const fatal = diagnostics.filter((d) => d.severity === "error");
|
|
1603
|
-
if (fatal.length > 0) throw new Error(fatal.map((d) => d.message).join("\n\n"));
|
|
1655
|
+
if (fatal.length > 0) throw Object.assign(new Error(fatal.map((d) => d.message).join("\n\n")), { code: fatal[0]?.code });
|
|
1604
1656
|
const narrowedConfig = resolvedConfig;
|
|
1605
1657
|
const narrowedAdapter = configWithId.adapter;
|
|
1606
1658
|
const controller = resolveOrAutoCreateController(narrowedConfig, narrowedAdapter, repository, hasCrudRoutes);
|
|
1659
|
+
presetController.bind(controller);
|
|
1660
|
+
const verifyPresetRoutes = () => presetController.verify(resolvedConfig.routes ?? []);
|
|
1661
|
+
if (!normalisedConfig.skipValidation) verifyPresetRoutes();
|
|
1607
1662
|
const resource = new ResourceDefinition({
|
|
1608
1663
|
...resolvedConfig,
|
|
1609
1664
|
adapter: configWithId.adapter,
|
|
@@ -1616,6 +1671,7 @@ function defineResource(config) {
|
|
|
1616
1671
|
if (registryMeta) resource._registryMeta = registryMeta;
|
|
1617
1672
|
}
|
|
1618
1673
|
const deferred = [];
|
|
1674
|
+
if (normalisedConfig.skipValidation) deferred.push(verifyPresetRoutes);
|
|
1619
1675
|
if (resolvedConfig.transactional === true) {
|
|
1620
1676
|
const name = resolvedConfig.name;
|
|
1621
1677
|
deferred.push(() => assertTransactionCapability(repository, name));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as arcLog } from "./logger-DdMS0XC_.mjs";
|
|
3
|
+
// src/logger/deprecation.ts
|
|
4
|
+
/**
|
|
5
|
+
* One warning per deprecated spelling per process. Keyed by the spelling, not
|
|
6
|
+
* the call site: a host with 80 string handlers needs one line naming the
|
|
7
|
+
* replacement, not 80. Goes through `arcLog`, so `ARC_SUPPRESS_WARNINGS` and
|
|
8
|
+
* the app's pino writer apply.
|
|
9
|
+
*/
|
|
10
|
+
const warned = /* @__PURE__ */ new Set();
|
|
11
|
+
function warnDeprecated(key, message) {
|
|
12
|
+
if (warned.has(key)) return;
|
|
13
|
+
warned.add(key);
|
|
14
|
+
arcLog("deprecated").warn(`${key} is deprecated and will be removed in the next minor. ${message}`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a namespace object so reading one of ITS members warns once. Probes for
|
|
18
|
+
* members it does not have (`then`, symbols) stay silent, so awaiting or
|
|
19
|
+
* tagging the object never emits a false warning.
|
|
20
|
+
*/
|
|
21
|
+
function deprecatedNamespace(target, key, message) {
|
|
22
|
+
return new Proxy(target, { get(t, property, receiver) {
|
|
23
|
+
if (typeof property === "string" && Object.hasOwn(t, property)) warnDeprecated(key, message);
|
|
24
|
+
return Reflect.get(t, property, receiver);
|
|
25
|
+
} });
|
|
26
|
+
}
|
|
27
|
+
export { warnDeprecated as n, deprecatedNamespace as t };
|
package/dist/discovery/index.mjs
CHANGED
package/dist/docs/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { t as ExternalOpenApiPaths } from "../externalPaths-BOqdq5wr.mjs";
|
|
3
|
-
import { o as RegistryEntry } from "../index-
|
|
3
|
+
import { o as RegistryEntry } from "../index-DtHACefu.mjs";
|
|
4
4
|
import { FastifyPluginAsync } from "fastify";
|
|
5
5
|
/**
|
|
6
6
|
* OpenAPI 3.0 type primitives used by arc's spec emitter.
|
package/dist/docs/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { n as openapi_default, t as buildOpenApiSpec } from "../openapi-
|
|
3
|
-
import { n as getUserRoles } from "../userHelpers-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { n as openapi_default, t as buildOpenApiSpec } from "../openapi-COrL_33P.mjs";
|
|
3
|
+
import { n as getUserRoles } from "../userHelpers-CwpEK36a.mjs";
|
|
4
4
|
import fp from "fastify-plugin";
|
|
5
5
|
// src/docs/scalar.ts
|
|
6
6
|
const scalarPlugin = async (fastify, opts = {}) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
3
|
-
import { t as arcLog } from "./logger-
|
|
4
|
-
import { n as requireSingleHeaderValue } from "./headers-
|
|
5
|
-
import { n as getUserRoles } from "./userHelpers-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-Cy6j0m8_.mjs";
|
|
3
|
+
import { t as arcLog } from "./logger-DdMS0XC_.mjs";
|
|
4
|
+
import { n as requireSingleHeaderValue } from "./headers-Ib7BDgRI.mjs";
|
|
5
|
+
import { n as getUserRoles } from "./userHelpers-CwpEK36a.mjs";
|
|
6
6
|
import { ARC_ERROR_CODES } from "@classytic/repo-core/errors";
|
|
7
7
|
import fp from "fastify-plugin";
|
|
8
8
|
// src/scope/elevation.ts
|
|
@@ -33,6 +33,31 @@ interface ParsedFieldEnvelope {
|
|
|
33
33
|
export declare function parseFieldEnvelope(token: string): ParsedFieldEnvelope | null;
|
|
34
34
|
/** Decrypt a parsed `arc.v1` envelope with the resolved key. Throws on tamper. */
|
|
35
35
|
export declare function decryptField(envelope: ParsedFieldEnvelope, key: unknown): string;
|
|
36
|
+
/**
|
|
37
|
+
* A synchronous string sealer over the `arc.v1` field envelope and a STATIC key ring, for values sealed
|
|
38
|
+
* at rest (an account number, a token). The ring's first key seals; every listed key opens (rotation).
|
|
39
|
+
* A value that does not open THROWS; it never returns its input. Pinned by tests/encryption/field-sealer.test.ts.
|
|
40
|
+
*/
|
|
41
|
+
/** Keys by `kid`, in ring order; `activeKid` (the first) seals; `label` names the source in errors. */
|
|
42
|
+
interface FieldKeyRing {
|
|
43
|
+
readonly activeKid: string;
|
|
44
|
+
readonly keys: ReadonlyMap<string, Buffer>;
|
|
45
|
+
readonly label: string;
|
|
46
|
+
}
|
|
47
|
+
interface FieldSealer {
|
|
48
|
+
readonly activeKid: string;
|
|
49
|
+
encrypt(plain: string): string;
|
|
50
|
+
/** Throws on a value that is not an envelope, names a kid the ring lacks, or fails the GCM tag. */
|
|
51
|
+
decrypt(token: string): string;
|
|
52
|
+
/** The kid a value is sealed under, or `null` when it is not an `arc.v1` envelope. */
|
|
53
|
+
kidOf(token: string): string | null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parse `kid:base64(32 bytes)` entries (e.g. an env list) into a ring. `label` names the source in every
|
|
57
|
+
* error. Empty, malformed, short or repeated entries throw.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseFieldKeyRing(entries: readonly string[], label: string): FieldKeyRing;
|
|
60
|
+
export declare function createFieldSealer(ring: FieldKeyRing): FieldSealer;
|
|
36
61
|
interface StaticKeyProviderOptions {
|
|
37
62
|
/**
|
|
38
63
|
* Active key used to ENCRYPT outbound responses. For `jwe` mode this is the
|
|
@@ -72,4 +97,4 @@ interface StaticKeyProviderOptions {
|
|
|
72
97
|
* ```
|
|
73
98
|
*/
|
|
74
99
|
export declare function createStaticKeyProvider(options: StaticKeyProviderOptions): KeyProvider;
|
|
75
|
-
export { type ActiveKey, type EncryptionDirective, type EncryptionMode, type EncryptionOptions, type JweAlg, type JweEnc, type KeyContext, type KeyMaterial, type KeyProvider, type ParsedFieldEnvelope, type StaticKeyProviderOptions, _default as default, encryptionPlugin };
|
|
100
|
+
export { type ActiveKey, type EncryptionDirective, type EncryptionMode, type EncryptionOptions, type FieldKeyRing, type FieldSealer, type JweAlg, type JweEnc, type KeyContext, type KeyMaterial, type KeyProvider, type ParsedFieldEnvelope, type StaticKeyProviderOptions, _default as default, encryptionPlugin };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as ArcError } from "../errors-
|
|
3
|
-
import { t as parseJsonBody } from "../jsonBody-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as ArcError } from "../errors-Ukhmfmmx.mjs";
|
|
3
|
+
import { t as parseJsonBody } from "../jsonBody-BNlcGUnb.mjs";
|
|
4
4
|
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
5
5
|
import fp from "fastify-plugin";
|
|
6
6
|
// src/encryption/fieldCipher.ts
|
|
@@ -23,13 +23,13 @@ import fp from "fastify-plugin";
|
|
|
23
23
|
*/
|
|
24
24
|
const ENVELOPE_PREFIX = "arc.v1";
|
|
25
25
|
const IV_BYTES = 12;
|
|
26
|
-
const KEY_BYTES = 32;
|
|
26
|
+
const KEY_BYTES$1 = 32;
|
|
27
27
|
function b64url(buf) {
|
|
28
28
|
return buf.toString("base64url");
|
|
29
29
|
}
|
|
30
30
|
function toKeyBuffer(key) {
|
|
31
31
|
if (Buffer.isBuffer(key)) {
|
|
32
|
-
if (key.length !== KEY_BYTES) throw new Error(`[arc/encryption] field-mode key must be ${KEY_BYTES} bytes (AES-256); got ${key.length}`);
|
|
32
|
+
if (key.length !== KEY_BYTES$1) throw new Error(`[arc/encryption] field-mode key must be ${KEY_BYTES$1} bytes (AES-256); got ${key.length}`);
|
|
33
33
|
return key;
|
|
34
34
|
}
|
|
35
35
|
if (key instanceof Uint8Array) return toKeyBuffer(Buffer.from(key));
|
|
@@ -236,6 +236,56 @@ var encryptionPlugin_default = fp(encryptionPlugin, {
|
|
|
236
236
|
name: "arc-encryption",
|
|
237
237
|
fastify: "5.x"
|
|
238
238
|
});
|
|
239
|
+
// src/encryption/fieldSealer.ts
|
|
240
|
+
/**
|
|
241
|
+
* A synchronous string sealer over the `arc.v1` field envelope and a STATIC key ring, for values sealed
|
|
242
|
+
* at rest (an account number, a token). The ring's first key seals; every listed key opens (rotation).
|
|
243
|
+
* A value that does not open THROWS; it never returns its input. Pinned by tests/encryption/field-sealer.test.ts.
|
|
244
|
+
*/
|
|
245
|
+
const KID = /^[A-Za-z0-9_-]{1,32}$/;
|
|
246
|
+
const KEY_BYTES = 32;
|
|
247
|
+
/**
|
|
248
|
+
* Parse `kid:base64(32 bytes)` entries (e.g. an env list) into a ring. `label` names the source in every
|
|
249
|
+
* error. Empty, malformed, short or repeated entries throw.
|
|
250
|
+
*/
|
|
251
|
+
function parseFieldKeyRing(entries, label) {
|
|
252
|
+
const trimmed = entries.map((e) => e.trim()).filter((e) => e !== "");
|
|
253
|
+
if (trimmed.length === 0) throw new Error(`${label} is not set: a field key ring needs at least one kid:base64 entry (32 random bytes)`);
|
|
254
|
+
const keys = /* @__PURE__ */ new Map();
|
|
255
|
+
let activeKid = "";
|
|
256
|
+
for (const entry of trimmed) {
|
|
257
|
+
const at = entry.indexOf(":");
|
|
258
|
+
const kid = at > 0 ? entry.slice(0, at) : "";
|
|
259
|
+
if (!KID.test(kid)) throw new Error(`${label}: each entry is kid:base64 with a kid of [A-Za-z0-9_-]{1,32}`);
|
|
260
|
+
const key = Buffer.from(entry.slice(at + 1), "base64");
|
|
261
|
+
if (key.length !== KEY_BYTES) throw new Error(`${label}: key ${kid} must be ${KEY_BYTES} bytes (AES-256), got ${key.length}`);
|
|
262
|
+
if (keys.has(kid)) throw new Error(`${label}: key id ${kid} is listed twice`);
|
|
263
|
+
keys.set(kid, key);
|
|
264
|
+
activeKid ||= kid;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
activeKid,
|
|
268
|
+
keys,
|
|
269
|
+
label
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function createFieldSealer(ring) {
|
|
273
|
+
const { label } = ring;
|
|
274
|
+
const activeKey = ring.keys.get(ring.activeKid);
|
|
275
|
+
if (!activeKey) throw new Error(`createFieldSealer: active key ${ring.activeKid} is not in ${label}`);
|
|
276
|
+
return {
|
|
277
|
+
activeKid: ring.activeKid,
|
|
278
|
+
encrypt: (plain) => encryptField(plain, ring.activeKid, activeKey),
|
|
279
|
+
decrypt(token) {
|
|
280
|
+
const envelope = parseFieldEnvelope(token);
|
|
281
|
+
if (!envelope) throw new Error("not a sealed value (expected an arc.v1 field envelope)");
|
|
282
|
+
const key = ring.keys.get(envelope.kid);
|
|
283
|
+
if (!key) throw new Error(`the value is sealed with key ${envelope.kid}, which ${label} does not hold`);
|
|
284
|
+
return decryptField(envelope, key);
|
|
285
|
+
},
|
|
286
|
+
kidOf: (token) => parseFieldEnvelope(token)?.kid ?? null
|
|
287
|
+
};
|
|
288
|
+
}
|
|
239
289
|
// src/encryption/keyProvider.ts
|
|
240
290
|
/**
|
|
241
291
|
* A static, in-memory key provider with `kid`-based rotation. Keys are held
|
|
@@ -268,4 +318,4 @@ function createStaticKeyProvider(options) {
|
|
|
268
318
|
decryptionKey: (kid) => decryptionKeys[kid]
|
|
269
319
|
};
|
|
270
320
|
}
|
|
271
|
-
export { createStaticKeyProvider, decryptField, encryptionPlugin_default as default, encryptField, encryptionPlugin, parseFieldEnvelope };
|
|
321
|
+
export { createFieldSealer, createStaticKeyProvider, decryptField, encryptionPlugin_default as default, encryptField, encryptionPlugin, parseFieldEnvelope, parseFieldKeyRing };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
3
|
-
import { m as statusToArcCode, p as isArcError } from "./errors-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-Cy6j0m8_.mjs";
|
|
3
|
+
import { m as statusToArcCode, p as isArcError } from "./errors-Ukhmfmmx.mjs";
|
|
4
4
|
import { isHttpError, toErrorContract } from "@classytic/repo-core/errors";
|
|
5
5
|
import { isProductionEnv } from "@classytic/primitives/environment";
|
|
6
6
|
import fp from "fastify-plugin";
|
|
@@ -165,7 +165,10 @@ async function errorHandlerPluginFn(fastify, options = {}) {
|
|
|
165
165
|
const deliberateUnavailable = status === 503 && wire.code !== "arc.internal_error";
|
|
166
166
|
if (status >= 500 && !deliberateUnavailable) request.log.error({
|
|
167
167
|
err: error,
|
|
168
|
-
status
|
|
168
|
+
status,
|
|
169
|
+
code: wire.code,
|
|
170
|
+
route: request.routeOptions?.url,
|
|
171
|
+
method: request.method
|
|
169
172
|
}, "Server error");
|
|
170
173
|
else if (deliberateUnavailable) request.log.warn({
|
|
171
174
|
code: wire.code,
|
|
@@ -319,7 +319,7 @@ interface EventPluginOptions {
|
|
|
319
319
|
*
|
|
320
320
|
* **Important:** With `failOpen: true` (default), a transport outage will
|
|
321
321
|
* silently drop events while requests continue succeeding. Pair with the
|
|
322
|
-
* `onPublishError` callback to monitor failures, or use
|
|
322
|
+
* `onPublishError` callback to monitor failures, or use the outbox for
|
|
323
323
|
* at-least-once delivery guarantees.
|
|
324
324
|
*
|
|
325
325
|
* Never applies to a type the `registry` declares `durability: 'durable'`: the facade
|
|
@@ -327,24 +327,13 @@ interface EventPluginOptions {
|
|
|
327
327
|
*/
|
|
328
328
|
failOpen?: boolean;
|
|
329
329
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
330
|
+
* Write-ahead hook called BEFORE the transport publish, with an optional
|
|
331
|
+
* acknowledge() AFTER a successful publish. NOT at-least-once on its own:
|
|
332
|
+
* nothing replays a saved-but-unpublished row.
|
|
332
333
|
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* For at-least-once you must EITHER:
|
|
337
|
-
*
|
|
338
|
-
* 1. Run a relay loop yourself (read unacknowledged WAL rows on boot,
|
|
339
|
-
* republish, ack on success), or
|
|
340
|
-
* 2. Use `EventOutbox` ([./outbox.ts]) — `outbox.relay()` is the
|
|
341
|
-
* production-grade at-least-once primitive with claim/lease,
|
|
342
|
-
* retry/DLQ, multi-worker safety, and `repository`-backed durable
|
|
343
|
-
* storage. New code should prefer `EventOutbox` over `wal`.
|
|
344
|
-
*
|
|
345
|
-
* The `wal` slot is kept for hosts that want to integrate with custom
|
|
346
|
-
* write-ahead infrastructure (Kafka producer transactions, S3 batch
|
|
347
|
-
* archives, debug audit logs) without arc's outbox claim/lease semantics.
|
|
334
|
+
* @deprecated Use the outbox (`createOutboxModule` / `EventOutbox`), which
|
|
335
|
+
* has claim/lease, retry/DLQ and a relay loop. Warns once per process;
|
|
336
|
+
* removed in the next minor.
|
|
348
337
|
*/
|
|
349
338
|
wal?: {
|
|
350
339
|
save: (event: DomainEvent) => Promise<void>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
3
|
-
import { n as requestContext } from "./requestContext-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { n as
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-Cy6j0m8_.mjs";
|
|
3
|
+
import { n as requestContext } from "./requestContext-B-TjFpWt.mjs";
|
|
4
|
+
import { n as warnDeprecated } from "./deprecation-DX625dth.mjs";
|
|
5
|
+
import { t as arcLog } from "./logger-DdMS0XC_.mjs";
|
|
6
|
+
import { d as createDomainError } from "./errors-Ukhmfmmx.mjs";
|
|
7
|
+
import { i as runAdmittedWork, n as isAdmittedWork, r as registerShutdownParticipant } from "./shutdown-C76Hn-Th.mjs";
|
|
8
|
+
import { n as MemoryEventTransport, r as createEvent, t as ARC_EVENT_TRANSPORT } from "./EventTransport-B3jTKMQH.mjs";
|
|
9
|
+
import { n as preserveSubscriberIdentity } from "./subscriberIdentity-DpdSQMQq.mjs";
|
|
9
10
|
import { isProductionEnv } from "@classytic/primitives/environment";
|
|
10
11
|
import fp from "fastify-plugin";
|
|
11
12
|
import { NonDurablePublishError } from "@classytic/primitives/durable-events";
|
|
@@ -162,6 +163,7 @@ const eventPlugin = async (fastify, opts = {}) => {
|
|
|
162
163
|
*/
|
|
163
164
|
const ownsTransport = opts.transport === void 0;
|
|
164
165
|
const { transport = new MemoryEventTransport(opts.memoryTransport), singleProcess = false, logEvents = false, failOpen = true, retry: retryOpts, deadLetterQueue: dlqOpts, wal, onPublish, onPublishError, registry, validateMode: rawValidateMode, warnOnDuplicate: rawWarnOnDuplicate } = opts;
|
|
166
|
+
if (wal) warnDeprecated("The eventPlugin `wal` option", "Use the outbox (`createOutboxModule` / `EventOutbox`) for at-least-once delivery.");
|
|
165
167
|
/** A host telemetry callback — isolated like an observer, so it can never change delivery. */
|
|
166
168
|
const notify = (hook, run, eventType) => {
|
|
167
169
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { r as createEvent } from "./EventTransport-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { r as createEvent } from "./EventTransport-B3jTKMQH.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { durableEventMeta } from "@classytic/primitives/durable-events";
|
|
5
5
|
// src/events/defineEvent.ts
|
package/dist/events/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
import { a as withRetry, c as EventDefinitionOutput, d as EventSchema, f as ValidationResult, i as createDeadLetterPublisher, l as EventRegistry, m as defineEvent, n as eventPlugin, o as CustomValidator, p as createEventRegistry, r as RetryOptions, s as EventDefinitionInput, t as EventPluginOptions, u as EventRegistryOptions } from "../eventPlugin-
|
|
2
|
+
import { a as withRetry, c as EventDefinitionOutput, d as EventSchema, f as ValidationResult, i as createDeadLetterPublisher, l as EventRegistry, m as defineEvent, n as eventPlugin, o as CustomValidator, p as createEventRegistry, r as RetryOptions, s as EventDefinitionInput, t as EventPluginOptions, u as EventRegistryOptions } from "../eventPlugin-BeJasppx.mjs";
|
|
3
3
|
import { i as EventLogger, n as DomainEvent, o as MemoryEventTransport, r as EventHandler, s as MemoryEventTransportOptions } from "../EventTransport-CYEoCJGe.mjs";
|
|
4
|
-
import { a as createOutboxModule, c as EventOutboxOptions, d as RelayBatchOptions, f as RelayResult, g as readOutboxHealth, h as OutboxHealthStore, i as OutboxModuleOptions, l as OutboxRelayErrorHandler, m as OutboxHealth, n as OutboxDrainResult, o as MemoryOutboxStore, p as DEFAULT_RELAY_LAG_UNHEALTHY_MS, r as OutboxModuleExports, s as EventOutbox, t as OutboxDrainRequest, u as OutboxRelayErrorKind } from "../outbox-module-
|
|
4
|
+
import { a as createOutboxModule, c as EventOutboxOptions, d as RelayBatchOptions, f as RelayResult, g as readOutboxHealth, h as OutboxHealthStore, i as OutboxModuleOptions, l as OutboxRelayErrorHandler, m as OutboxHealth, n as OutboxDrainResult, o as MemoryOutboxStore, p as DEFAULT_RELAY_LAG_UNHEALTHY_MS, r as OutboxModuleExports, s as EventOutbox, t as OutboxDrainRequest, u as OutboxRelayErrorKind } from "../outbox-module-C1QWMloZ.mjs";
|
|
5
5
|
import { RedisEventTransportOptions, RedisLike } from "./transports/redis.mjs";
|
|
6
6
|
import { r as RedisStreamTransportOptions, t as RedisStreamLike } from "../redis-stream-CS1N9dwM.mjs";
|
|
7
7
|
import { OutboxStore } from "@classytic/primitives/outbox";
|
package/dist/events/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { a as crudEventType, d as createEventRegistry, f as defineEvent, i as CRUD_EVENT_SUFFIXES, l as wrapWithBoundary, n as CACHE_EVENTS, o as subscribeWithBoundary, s as subscribeWithSchema, t as ARC_LIFECYCLE_EVENTS, u as wrapWithSchema } from "../eventTypes-
|
|
3
|
-
import { n as MemoryEventTransport } from "../EventTransport-
|
|
4
|
-
import { a as withRetry, i as createDeadLetterPublisher, n as eventPlugin } from "../eventPlugin-
|
|
5
|
-
import { r as withSubscriberId } from "../subscriberIdentity-
|
|
6
|
-
import { r as readOutboxHealth, t as DEFAULT_RELAY_LAG_UNHEALTHY_MS } from "../health-
|
|
7
|
-
import { t as createOutboxModule } from "../outbox-module-
|
|
8
|
-
import { n as repositoryAsOutboxStore, r as exponentialBackoff, t as EventOutbox } from "../relay-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { a as crudEventType, d as createEventRegistry, f as defineEvent, i as CRUD_EVENT_SUFFIXES, l as wrapWithBoundary, n as CACHE_EVENTS, o as subscribeWithBoundary, s as subscribeWithSchema, t as ARC_LIFECYCLE_EVENTS, u as wrapWithSchema } from "../eventTypes-DpDQtyR6.mjs";
|
|
3
|
+
import { n as MemoryEventTransport } from "../EventTransport-B3jTKMQH.mjs";
|
|
4
|
+
import { a as withRetry, i as createDeadLetterPublisher, n as eventPlugin } from "../eventPlugin-DTKAgSvb.mjs";
|
|
5
|
+
import { r as withSubscriberId } from "../subscriberIdentity-DpdSQMQq.mjs";
|
|
6
|
+
import { r as readOutboxHealth, t as DEFAULT_RELAY_LAG_UNHEALTHY_MS } from "../health-22T82HAa.mjs";
|
|
7
|
+
import { t as createOutboxModule } from "../outbox-module-BY2HtnjU.mjs";
|
|
8
|
+
import { n as repositoryAsOutboxStore, r as exponentialBackoff, t as EventOutbox } from "../relay-CmT3gtkP.mjs";
|
|
9
9
|
import { fingerprintRequest, runIdempotent } from "@classytic/repo-core/idempotency";
|
|
10
10
|
import { MemoryOutboxStore } from "@classytic/primitives/memory-outbox";
|
|
11
11
|
// src/events/inbox.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { n as evictToSize } from "../../boundedMap-
|
|
3
|
-
import { r as workSeedFromEvent, t as runWorkScope } from "../../workScope-
|
|
4
|
-
import { t as getSubscriberId } from "../../subscriberIdentity-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { n as evictToSize } from "../../boundedMap-Ddw2yGb2.mjs";
|
|
3
|
+
import { r as workSeedFromEvent, t as runWorkScope } from "../../workScope-C3tPz_Gt.mjs";
|
|
4
|
+
import { t as getSubscriberId } from "../../subscriberIdentity-DpdSQMQq.mjs";
|
|
5
5
|
import sjson from "secure-json-parse";
|
|
6
6
|
import { createEventRouter } from "@classytic/primitives/events";
|
|
7
7
|
// src/events/transports/redis-stream.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { r as workSeedFromEvent, t as runWorkScope } from "../../workScope-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { r as workSeedFromEvent, t as runWorkScope } from "../../workScope-C3tPz_Gt.mjs";
|
|
3
3
|
import sjson from "secure-json-parse";
|
|
4
4
|
// src/events/transports/redis.ts
|
|
5
5
|
/**
|