@classytic/arc 2.6.3 → 2.7.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.
Files changed (143) hide show
  1. package/README.md +98 -3
  2. package/dist/{BaseController-DzRtluEF.mjs → BaseController-CpMfCXdn.mjs} +134 -16
  3. package/dist/adapters/index.d.mts +2 -2
  4. package/dist/adapters/index.mjs +1 -1
  5. package/dist/{adapters-gM-WYjNe.mjs → adapters-BxGgSHjj.mjs} +1 -9
  6. package/dist/applyPermissionResult-D6GPMsvh.mjs +37 -0
  7. package/dist/audit/index.d.mts +1 -1
  8. package/dist/audit/index.mjs +1 -1
  9. package/dist/audit/mongodb.d.mts +1 -1
  10. package/dist/audit/mongodb.mjs +1 -1
  11. package/dist/auth/index.d.mts +4 -4
  12. package/dist/auth/index.mjs +7 -6
  13. package/dist/auth/mongoose.d.mts +191 -0
  14. package/dist/auth/mongoose.mjs +73 -0
  15. package/dist/auth/redis-session.d.mts +1 -1
  16. package/dist/{betterAuthOpenApi-lz0IRbXJ.mjs → betterAuthOpenApi-CCw3YX0g.mjs} +1 -1
  17. package/dist/cache/index.d.mts +2 -2
  18. package/dist/cache/index.mjs +2 -2
  19. package/dist/cli/commands/docs.mjs +2 -2
  20. package/dist/cli/commands/generate.mjs +1 -1
  21. package/dist/cli/commands/init.mjs +7 -5
  22. package/dist/cli/commands/introspect.mjs +1 -1
  23. package/dist/core/index.d.mts +3 -3
  24. package/dist/core/index.mjs +4 -4
  25. package/dist/{core-C1XCMtqM.mjs → core-BWekSEju.mjs} +41 -13
  26. package/dist/{createApp-D2w0LdYJ.mjs → createApp-D7e77m8C.mjs} +25 -14
  27. package/dist/{defineResource-wWMBB4GP.mjs → defineResource-DZzyl4a4.mjs} +42 -37
  28. package/dist/docs/index.d.mts +2 -2
  29. package/dist/docs/index.mjs +1 -1
  30. package/dist/dynamic/index.d.mts +2 -2
  31. package/dist/dynamic/index.mjs +2 -2
  32. package/dist/{elevation-BEdACOLB.mjs → elevation-By_p2lnn.mjs} +1 -1
  33. package/dist/elevation-D7WK0RXq.d.mts +23 -0
  34. package/dist/{errorHandler-r2595m8T.mjs → errorHandler-CH8wk1eD.mjs} +17 -2
  35. package/dist/{errorHandler-Do4vVQ1f.d.mts → errorHandler-pCpEtNd7.d.mts} +46 -2
  36. package/dist/{eventPlugin-Ba00swHF.mjs → eventPlugin-B6U_nCFU.mjs} +4 -3
  37. package/dist/{eventPlugin-DW45v4V5.d.mts → eventPlugin-CdvUoUna.d.mts} +1 -1
  38. package/dist/events/index.d.mts +3 -3
  39. package/dist/events/index.mjs +1 -1
  40. package/dist/events/transports/redis-stream-entry.d.mts +1 -1
  41. package/dist/events/transports/redis.d.mts +1 -1
  42. package/dist/factory/index.d.mts +1 -1
  43. package/dist/factory/index.mjs +1 -1
  44. package/dist/hooks/index.d.mts +1 -1
  45. package/dist/hooks/index.mjs +1 -1
  46. package/dist/idempotency/index.d.mts +3 -3
  47. package/dist/idempotency/mongodb.d.mts +1 -1
  48. package/dist/idempotency/redis.d.mts +1 -1
  49. package/dist/index-B0extFr4.d.mts +640 -0
  50. package/dist/{index-gz6iuzCp.d.mts → index-BjShrzoj.d.mts} +47 -4
  51. package/dist/{index-CHeJa4Zd.d.mts → index-C9eYNjGR.d.mts} +1 -1
  52. package/dist/index.d.mts +9 -8
  53. package/dist/index.mjs +10 -9
  54. package/dist/integrations/event-gateway.d.mts +1 -1
  55. package/dist/integrations/event-gateway.mjs +1 -1
  56. package/dist/integrations/index.d.mts +1 -1
  57. package/dist/integrations/mcp/index.d.mts +2 -2
  58. package/dist/integrations/mcp/index.mjs +8 -5
  59. package/dist/integrations/mcp/testing.d.mts +1 -1
  60. package/dist/integrations/mcp/testing.mjs +1 -1
  61. package/dist/integrations/webhooks.d.mts +58 -1
  62. package/dist/integrations/webhooks.mjs +78 -7
  63. package/dist/integrations/websocket.d.mts +7 -1
  64. package/dist/integrations/websocket.mjs +7 -1
  65. package/dist/{interface-DYH8AXGe.d.mts → interface-B91alUzq.d.mts} +151 -15
  66. package/dist/{mongodb-pMvOlR5_.d.mts → mongodb-B7zupyck.d.mts} +1 -1
  67. package/dist/{mongodb-kltrBPa1.d.mts → mongodb-Cgu9F1Nd.d.mts} +1 -1
  68. package/dist/{openapi-CBmZ6EQN.mjs → openapi-BBSTVcMm.mjs} +1 -1
  69. package/dist/org/index.d.mts +2 -2
  70. package/dist/org/index.mjs +1 -1
  71. package/dist/permissions/index.d.mts +4 -4
  72. package/dist/permissions/index.mjs +3 -2
  73. package/dist/{permissions-C8ImI8gC.mjs → permissions-CH4cNwJi.mjs} +358 -64
  74. package/dist/plugins/index.d.mts +52 -5
  75. package/dist/plugins/index.mjs +12 -11
  76. package/dist/plugins/response-cache.mjs +1 -1
  77. package/dist/plugins/tracing-entry.d.mts +1 -1
  78. package/dist/plugins/tracing-entry.mjs +1 -1
  79. package/dist/policies/index.d.mts +1 -1
  80. package/dist/presets/index.d.mts +3 -3
  81. package/dist/presets/index.mjs +1 -1
  82. package/dist/presets/multiTenant.d.mts +53 -3
  83. package/dist/presets/multiTenant.mjs +89 -47
  84. package/dist/{presets-BMfdy34e.mjs → presets-BFrGvvjL.mjs} +2 -2
  85. package/dist/{queryCachePlugin-DcmETvcB.d.mts → queryCachePlugin-Ckl71mkc.d.mts} +1 -1
  86. package/dist/{queryCachePlugin-XtFplYO9.mjs → queryCachePlugin-CwTpR04-.mjs} +2 -2
  87. package/dist/{redis-D0Qc-9EW.d.mts → redis-3TQxm2VZ.d.mts} +1 -1
  88. package/dist/{redis-stream-BW9UKLZM.d.mts → redis-stream-Dag5LFa9.d.mts} +1 -1
  89. package/dist/registry/index.d.mts +1 -1
  90. package/dist/registry/index.mjs +2 -2
  91. package/dist/replyHelpers-uDUIYh7u.mjs +40 -0
  92. package/dist/{resourceToTools-nCJWnG1r.mjs → resourceToTools-BJkoQoUP.mjs} +74 -25
  93. package/dist/rpc/index.d.mts +1 -1
  94. package/dist/rpc/index.mjs +1 -1
  95. package/dist/scope/index.d.mts +3 -2
  96. package/dist/scope/index.mjs +4 -3
  97. package/dist/{sse-BF7GR7IB.mjs → sse-6W0hjVS_.mjs} +2 -2
  98. package/dist/testing/index.d.mts +2 -2
  99. package/dist/testing/index.mjs +1 -1
  100. package/dist/types/index.d.mts +4 -3
  101. package/dist/types/index.mjs +1 -1
  102. package/dist/types--D3vvfdt.d.mts +286 -0
  103. package/dist/{types-By-5mIfn.d.mts → types-2FlNl0mL.d.mts} +44 -9
  104. package/dist/types-AOD8fxIw.mjs +229 -0
  105. package/dist/types-B4BNthET.d.mts +178 -0
  106. package/dist/{types-B4_TDdPe.d.mts → types-C5g2oRC7.d.mts} +18 -2
  107. package/dist/utils/index.d.mts +3 -3
  108. package/dist/utils/index.mjs +5 -5
  109. package/package.json +21 -6
  110. package/skills/arc/SKILL.md +314 -6
  111. package/skills/arc/references/integrations.md +32 -7
  112. package/skills/arc/references/mcp.md +31 -7
  113. package/skills/arc/references/multi-tenancy.md +208 -0
  114. package/skills/arc/references/production.md +69 -0
  115. package/dist/elevation-C_taLQrM.d.mts +0 -147
  116. package/dist/index-NGZksqM5.d.mts +0 -398
  117. package/dist/types-BNUccdcf.d.mts +0 -101
  118. package/dist/types-BhtYdxZU.mjs +0 -91
  119. /package/dist/{EventTransport-wc5hSLik.d.mts → EventTransport-C4VheKeC.d.mts} +0 -0
  120. /package/dist/{HookSystem-COkyWztM.mjs → HookSystem-D7lfx--K.mjs} +0 -0
  121. /package/dist/{ResourceRegistry-C6ngvOnn.mjs → ResourceRegistry-DsHiG9cL.mjs} +0 -0
  122. /package/dist/{caching-BSXB-Xr7.mjs → caching-5DtLwIqb.mjs} +0 -0
  123. /package/dist/{circuitBreaker-JP2GdJ4b.d.mts → circuitBreaker-BBPDt-J_.d.mts} +0 -0
  124. /package/dist/{circuitBreaker-BOBOpN2w.mjs → circuitBreaker-l18oRgL5.mjs} +0 -0
  125. /package/dist/{errors-CcVbl1-T.d.mts → errors-BS6lZvWy.d.mts} +0 -0
  126. /package/dist/{errors-NoQKsbAT.mjs → errors-Cg58SLNi.mjs} +0 -0
  127. /package/dist/{externalPaths-DpO-s7r8.d.mts → externalPaths-iba7jD3d.d.mts} +0 -0
  128. /package/dist/{fields-DFwdaWCq.d.mts → fields-D4nMDqnK.d.mts} +0 -0
  129. /package/dist/{interface-D_BWALyZ.d.mts → interface-CG7oRZjX.d.mts} +0 -0
  130. /package/dist/{interface-gr-7qo9j.d.mts → interface-CSbZdv_3.d.mts} +0 -0
  131. /package/dist/{logger-Dz3j1ItV.mjs → logger-DLg8-Ueg.mjs} +0 -0
  132. /package/dist/{memory-BFAYkf8H.mjs → memory-Cp7_cAko.mjs} +0 -0
  133. /package/dist/{metrics-Csh4nsvv.mjs → metrics-Qnvwc-LQ.mjs} +0 -0
  134. /package/dist/{mongodb-BuQ7fNTg.mjs → mongodb-B7X7P1P8.mjs} +0 -0
  135. /package/dist/{pluralize-CcT6qF0a.mjs → pluralize-Dckfq6US.mjs} +0 -0
  136. /package/dist/{registry-I-ogLgL9.mjs → registry-B3lRFBWo.mjs} +0 -0
  137. /package/dist/{requestContext-DYtmNpm5.mjs → requestContext-xHIKedG6.mjs} +0 -0
  138. /package/dist/{schemaConverter-DjzHpFam.mjs → schemaConverter-0TyONAwM.mjs} +0 -0
  139. /package/dist/{sessionManager-wbkYj2HL.d.mts → sessionManager-CEo9jwPI.d.mts} +0 -0
  140. /package/dist/{tracing-bz_U4EM1.d.mts → tracing-DEqdGkr-.d.mts} +0 -0
  141. /package/dist/{typeGuards-Cj5Rgvlg.mjs → typeGuards-CcFZXgU7.mjs} +0 -0
  142. /package/dist/{utils-Dc0WhlIl.mjs → utils-B-l6410F.mjs} +0 -0
  143. /package/dist/{versioning-BzfeHmhj.mjs → versioning-CdBbFefk.mjs} +0 -0
@@ -1,14 +1,15 @@
1
1
  import { s as DEFAULT_UPDATE_METHOD, t as CRUD_OPERATIONS } from "./constants-Cxde4rpC.mjs";
2
- import { d as isElevated, f as isMember, n as PUBLIC_SCOPE } from "./types-BhtYdxZU.mjs";
3
- import { t as BaseController } from "./BaseController-DzRtluEF.mjs";
2
+ import { _ as isElevated, n as PUBLIC_SCOPE, v as isMember } from "./types-AOD8fxIw.mjs";
3
+ import { t as BaseController } from "./BaseController-CpMfCXdn.mjs";
4
4
  import { i as resolveEffectiveRoles, t as applyFieldReadPermissions } from "./fields-ipsbIRPK.mjs";
5
5
  import { t as getUserRoles } from "./types-ZUu_h0jp.mjs";
6
- import { t as requestContext } from "./requestContext-DYtmNpm5.mjs";
7
- import { i as getDefaultCrudSchemas } from "./utils-Dc0WhlIl.mjs";
8
- import { r as ForbiddenError } from "./errors-NoQKsbAT.mjs";
9
- import { n as convertRouteSchema, t as convertOpenApiSchemas } from "./schemaConverter-DjzHpFam.mjs";
10
- import { t as hasEvents } from "./typeGuards-Cj5Rgvlg.mjs";
11
- import { r as getAvailablePresets, t as applyPresets } from "./presets-BMfdy34e.mjs";
6
+ import { n as normalizePermissionResult, t as applyPermissionResult } from "./applyPermissionResult-D6GPMsvh.mjs";
7
+ import { t as requestContext } from "./requestContext-xHIKedG6.mjs";
8
+ import { i as getDefaultCrudSchemas } from "./utils-B-l6410F.mjs";
9
+ import { r as ForbiddenError } from "./errors-Cg58SLNi.mjs";
10
+ import { n as convertRouteSchema, t as convertOpenApiSchemas } from "./schemaConverter-0TyONAwM.mjs";
11
+ import { t as hasEvents } from "./typeGuards-CcFZXgU7.mjs";
12
+ import { r as getAvailablePresets, t as applyPresets } from "./presets-BFrGvvjL.mjs";
12
13
  //#region src/pipeline/pipe.ts
13
14
  /**
14
15
  * Compose pipeline steps into an ordered array.
@@ -372,17 +373,7 @@ function buildPermissionMiddleware(permissionCheck, resourceName, action) {
372
373
  });
373
374
  return;
374
375
  }
375
- if (typeof result === "boolean") {
376
- if (!result) {
377
- reply.code(context.user ? 403 : 401).send({
378
- success: false,
379
- error: context.user ? "Permission denied" : "Authentication required"
380
- });
381
- return;
382
- }
383
- return;
384
- }
385
- const permResult = result;
376
+ const permResult = normalizePermissionResult(result);
386
377
  if (!permResult.granted) {
387
378
  const defaultMsg = context.user ? "Permission denied" : "Authentication required";
388
379
  const reason = permResult.reason && permResult.reason.length <= 100 ? permResult.reason : defaultMsg;
@@ -392,10 +383,7 @@ function buildPermissionMiddleware(permissionCheck, resourceName, action) {
392
383
  });
393
384
  return;
394
385
  }
395
- if (permResult.filters) reqWithExtras._policyFilters = {
396
- ...reqWithExtras._policyFilters ?? {},
397
- ...permResult.filters
398
- };
386
+ applyPermissionResult(permResult, request);
399
387
  };
400
388
  }
401
389
  /**
@@ -907,6 +895,13 @@ function defineResource(config) {
907
895
  }
908
896
  }
909
897
  const repository = config.adapter?.repository;
898
+ if (config.idField === void 0 && repository) {
899
+ const repoIdField = repository.idField;
900
+ if (typeof repoIdField === "string" && repoIdField !== "_id") config = {
901
+ ...config,
902
+ idField: repoIdField
903
+ };
904
+ }
910
905
  const crudRoutes = CRUD_OPERATIONS;
911
906
  const disabledRoutes = new Set(config.disabledRoutes ?? []);
912
907
  const hasCrudRoutes = !config.disableDefaultRoutes && crudRoutes.some((route) => !disabledRoutes.has(route));
@@ -1218,22 +1213,32 @@ var ResourceDefinition = class {
1218
1213
  }
1219
1214
  const listQuerySchema = self._registryMeta?.openApiSchemas?.listQuery;
1220
1215
  if (listQuerySchema) {
1221
- const KEEP_AS_IS = new Set([
1222
- "page",
1223
- "limit",
1224
- "sort",
1225
- "search",
1226
- "select",
1227
- "after",
1228
- "populate",
1229
- "lookup",
1230
- "aggregate"
1231
- ]);
1216
+ const NORMALIZED_PROPS = {
1217
+ page: {
1218
+ type: "integer",
1219
+ minimum: 1
1220
+ },
1221
+ limit: {
1222
+ type: "integer",
1223
+ minimum: 1
1224
+ },
1225
+ sort: {},
1226
+ search: {},
1227
+ select: {},
1228
+ after: {},
1229
+ populate: {},
1230
+ lookup: {},
1231
+ aggregate: {}
1232
+ };
1232
1233
  const props = listQuerySchema.properties;
1233
1234
  const normalizedProps = props ? { ...props } : void 0;
1234
- if (normalizedProps) for (const key of Object.keys(normalizedProps)) {
1235
- if (KEEP_AS_IS.has(key)) continue;
1236
- normalizedProps[key] = {};
1235
+ if (normalizedProps) {
1236
+ const originalLimit = normalizedProps.limit;
1237
+ if (originalLimit?.maximum) NORMALIZED_PROPS.limit = {
1238
+ ...NORMALIZED_PROPS.limit,
1239
+ maximum: originalLimit.maximum
1240
+ };
1241
+ for (const key of Object.keys(normalizedProps)) normalizedProps[key] = NORMALIZED_PROPS[key] ?? {};
1237
1242
  }
1238
1243
  const normalizedSchema = {
1239
1244
  ...listQuerySchema,
@@ -1,5 +1,5 @@
1
- import { et as RegistryEntry } from "../interface-DYH8AXGe.mjs";
2
- import { t as ExternalOpenApiPaths } from "../externalPaths-DpO-s7r8.mjs";
1
+ import { et as RegistryEntry } from "../interface-B91alUzq.mjs";
2
+ import { t as ExternalOpenApiPaths } from "../externalPaths-iba7jD3d.mjs";
3
3
  import { FastifyPluginAsync } from "fastify";
4
4
 
5
5
  //#region src/docs/openapi.d.ts
@@ -1,5 +1,5 @@
1
1
  import { t as getUserRoles } from "../types-ZUu_h0jp.mjs";
2
- import { n as openApiPlugin, r as openapi_default, t as buildOpenApiSpec } from "../openapi-CBmZ6EQN.mjs";
2
+ import { n as openApiPlugin, r as openapi_default, t as buildOpenApiSpec } from "../openapi-BBSTVcMm.mjs";
3
3
  import fp from "fastify-plugin";
4
4
  //#region src/docs/scalar.ts
5
5
  const scalarPlugin = async (fastify, opts = {}) => {
@@ -1,5 +1,5 @@
1
- import { Vt as ResourceDefinition, r as DataAdapter } from "../interface-DYH8AXGe.mjs";
2
- import { t as PermissionCheck } from "../types-BNUccdcf.mjs";
1
+ import { Vt as ResourceDefinition, r as DataAdapter } from "../interface-B91alUzq.mjs";
2
+ import { t as PermissionCheck } from "../types-B4BNthET.mjs";
3
3
 
4
4
  //#region src/dynamic/ArcDynamicLoader.d.ts
5
5
  interface ArcArchitectureSchema {
@@ -1,6 +1,6 @@
1
1
  import { t as ArcQueryParser } from "../queryParser-CgCtsjti.mjs";
2
- import { n as defineResource } from "../defineResource-wWMBB4GP.mjs";
3
- import { S as readOnly, _ as fullPublic, b as publicRead, g as authenticated, h as adminOnly, v as ownerWithAdminBypass, x as publicReadAdminWrite } from "../permissions-C8ImI8gC.mjs";
2
+ import { n as defineResource } from "../defineResource-DZzyl4a4.mjs";
3
+ import { C as publicRead, T as readOnly, b as fullPublic, v as adminOnly, w as publicReadAdminWrite, x as ownerWithAdminBypass, y as authenticated } from "../permissions-CH4cNwJi.mjs";
4
4
  //#region src/dynamic/ArcDynamicLoader.ts
5
5
  const VALID_FIELD_TYPES = new Set([
6
6
  "string",
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
2
2
  import { t as getUserRoles } from "./types-ZUu_h0jp.mjs";
3
- import { t as arcLog } from "./logger-Dz3j1ItV.mjs";
3
+ import { t as arcLog } from "./logger-DLg8-Ueg.mjs";
4
4
  import fp from "fastify-plugin";
5
5
  //#region src/scope/elevation.ts
6
6
  var elevation_exports = /* @__PURE__ */ __exportAll({
@@ -0,0 +1,23 @@
1
+ import { FastifyPluginAsync, FastifyRequest } from "fastify";
2
+
3
+ //#region src/scope/elevation.d.ts
4
+ interface ElevationOptions {
5
+ /** Roles that can use elevation (default: ['superadmin']) */
6
+ platformRoles?: string[];
7
+ /** Header name for scope declaration (default: 'x-arc-scope') */
8
+ scopeHeader?: string;
9
+ /** Header name for target organization (default: 'x-organization-id') */
10
+ orgHeader?: string;
11
+ /** Called when elevation happens — use for audit logging */
12
+ onElevation?: (event: ElevationEvent) => void | Promise<void>;
13
+ }
14
+ interface ElevationEvent {
15
+ userId: string;
16
+ organizationId?: string;
17
+ request: FastifyRequest;
18
+ timestamp: Date;
19
+ }
20
+ declare const elevationPlugin: FastifyPluginAsync<ElevationOptions>;
21
+ declare const _default: FastifyPluginAsync<ElevationOptions>;
22
+ //#endregion
23
+ export { elevationPlugin as i, ElevationOptions as n, _default as r, ElevationEvent as t };
@@ -1,11 +1,11 @@
1
1
  import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
2
- import { p as isArcError } from "./errors-NoQKsbAT.mjs";
2
+ import { p as isArcError } from "./errors-Cg58SLNi.mjs";
3
3
  import fp from "fastify-plugin";
4
4
  //#region src/plugins/errorHandler.ts
5
5
  var errorHandler_exports = /* @__PURE__ */ __exportAll({ errorHandlerPlugin: () => errorHandlerPlugin });
6
6
  async function errorHandlerPluginFn(fastify, options = {}) {
7
7
  const isProduction = process.env.NODE_ENV === "production";
8
- const { includeStack = !isProduction, onError, errorMap = {} } = options;
8
+ const { includeStack = !isProduction, onError, errorMap = {}, errorMappers = [] } = options;
9
9
  fastify.setErrorHandler(async (error, request, reply) => {
10
10
  if (onError) try {
11
11
  await onError(error, request);
@@ -13,6 +13,21 @@ async function errorHandlerPluginFn(fastify, options = {}) {
13
13
  request.log.error({ err: callbackError }, "Error in onError callback");
14
14
  }
15
15
  const requestId = request.id;
16
+ if (errorMappers.length > 0) {
17
+ for (const mapper of errorMappers) if (error instanceof mapper.type) {
18
+ const mapped = mapper.toResponse(error);
19
+ const response = {
20
+ success: false,
21
+ error: mapped.message ?? error.message,
22
+ code: mapped.code ?? "DOMAIN_ERROR",
23
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
24
+ ...requestId && { requestId },
25
+ ...mapped.details && { details: mapped.details },
26
+ ...includeStack && error.stack ? { stack: error.stack } : {}
27
+ };
28
+ return reply.code(mapped.status).send(response);
29
+ }
30
+ }
16
31
  const response = {
17
32
  success: false,
18
33
  error: error.message || "Internal Server Error",
@@ -1,4 +1,4 @@
1
- import { t as DomainEvent } from "./EventTransport-wc5hSLik.mjs";
1
+ import { t as DomainEvent } from "./EventTransport-C4VheKeC.mjs";
2
2
  import { FastifyInstance, FastifyPluginAsync, FastifyRequest } from "fastify";
3
3
 
4
4
  //#region src/plugins/caching.d.ts
@@ -115,6 +115,18 @@ declare const versioningPlugin: FastifyPluginAsync<VersioningOptions>;
115
115
  declare const _default: FastifyPluginAsync<VersioningOptions>;
116
116
  //#endregion
117
117
  //#region src/plugins/errorHandler.d.ts
118
+ /** Class-based error mapper — maps thrown error instances to HTTP responses */
119
+ interface ErrorMapper<T extends Error = Error> {
120
+ /** Error class to match (uses instanceof) */
121
+ type: new (...args: unknown[]) => T;
122
+ /** Convert the error to an HTTP response shape */
123
+ toResponse: (error: T) => {
124
+ status: number;
125
+ code?: string;
126
+ message?: string;
127
+ details?: Record<string, unknown>;
128
+ };
129
+ }
118
130
  interface ErrorHandlerOptions {
119
131
  /**
120
132
  * Include stack trace in error responses (default: false in production)
@@ -125,13 +137,45 @@ interface ErrorHandlerOptions {
125
137
  */
126
138
  onError?: (error: Error, request: FastifyRequest) => void | Promise<void>;
127
139
  /**
128
- * Map specific error types to custom responses
140
+ * Map specific error types to custom responses (by error.name string)
129
141
  */
130
142
  errorMap?: Record<string, {
131
143
  statusCode: number;
132
144
  code: string;
133
145
  message?: string;
134
146
  }>;
147
+ /**
148
+ * Class-based error mappers — checked via `instanceof`, highest priority.
149
+ *
150
+ * Register your domain error classes once; Arc auto-catches and maps them
151
+ * in every handler. Handlers just `throw` — no try/catch needed.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * class AccountingError extends Error {
156
+ * constructor(message: string, public status: number, public code: string) {
157
+ * super(message);
158
+ * }
159
+ * }
160
+ *
161
+ * const app = await createApp({
162
+ * errorHandler: {
163
+ * errorMappers: [
164
+ * {
165
+ * type: AccountingError,
166
+ * toResponse: (err) => ({ status: err.status, code: err.code, message: err.message }),
167
+ * },
168
+ * ],
169
+ * },
170
+ * });
171
+ *
172
+ * // Now handlers just throw:
173
+ * handler: async (req) => {
174
+ * await ledger.post(id); // throws AccountingError → Arc maps to proper HTTP response
175
+ * }
176
+ * ```
177
+ */
178
+ errorMappers?: ErrorMapper[];
135
179
  }
136
180
  declare function errorHandlerPluginFn(fastify: FastifyInstance, options?: ErrorHandlerOptions): Promise<void>;
137
181
  declare const errorHandlerPlugin: typeof errorHandlerPluginFn;
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
2
- import { t as requestContext } from "./requestContext-DYtmNpm5.mjs";
2
+ import { t as requestContext } from "./requestContext-xHIKedG6.mjs";
3
3
  import fp from "fastify-plugin";
4
4
  //#region src/events/EventTransport.ts
5
5
  /**
@@ -165,9 +165,10 @@ const eventPlugin = async (fastify, opts = {}) => {
165
165
  }
166
166
  }
167
167
  try {
168
- if (wal) await wal.save(event);
168
+ const isInternalEvent = type.startsWith("arc.");
169
+ if (wal && !isInternalEvent) await wal.save(event);
169
170
  await transport.publish(event);
170
- if (wal?.acknowledge) await wal.acknowledge(event.meta.id);
171
+ if (wal?.acknowledge && !isInternalEvent) await wal.acknowledge(event.meta.id);
171
172
  onPublish?.(event);
172
173
  } catch (error) {
173
174
  fastify.log?.error?.({
@@ -1,4 +1,4 @@
1
- import { i as EventTransport, n as EventHandler, r as EventLogger, t as DomainEvent } from "./EventTransport-wc5hSLik.mjs";
1
+ import { i as EventTransport, n as EventHandler, r as EventLogger, t as DomainEvent } from "./EventTransport-C4VheKeC.mjs";
2
2
  import { FastifyPluginAsync } from "fastify";
3
3
 
4
4
  //#region src/events/defineEvent.d.ts
@@ -1,7 +1,7 @@
1
- import { a as MemoryEventTransport, i as EventTransport, n as EventHandler, o as MemoryEventTransportOptions, r as EventLogger, s as createEvent, t as DomainEvent } from "../EventTransport-wc5hSLik.mjs";
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-DW45v4V5.mjs";
1
+ import { a as MemoryEventTransport, i as EventTransport, n as EventHandler, o as MemoryEventTransportOptions, r as EventLogger, s as createEvent, t as DomainEvent } from "../EventTransport-C4VheKeC.mjs";
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-CdvUoUna.mjs";
3
3
  import { RedisEventTransportOptions, RedisLike } from "./transports/redis.mjs";
4
- import { r as RedisStreamTransportOptions, t as RedisStreamLike } from "../redis-stream-BW9UKLZM.mjs";
4
+ import { r as RedisStreamTransportOptions, t as RedisStreamLike } from "../redis-stream-Dag5LFa9.mjs";
5
5
 
6
6
  //#region src/events/eventTypes.d.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { a as MemoryEventTransport, i as withRetry, o as createEvent, r as createDeadLetterPublisher, t as eventPlugin } from "../eventPlugin-Ba00swHF.mjs";
1
+ import { a as MemoryEventTransport, i as withRetry, o as createEvent, r as createDeadLetterPublisher, t as eventPlugin } from "../eventPlugin-B6U_nCFU.mjs";
2
2
  //#region src/events/defineEvent.ts
3
3
  /**
4
4
  * defineEvent — Typed Event Definitions with Optional Schema Validation
@@ -1,2 +1,2 @@
1
- import { n as RedisStreamTransport, r as RedisStreamTransportOptions, t as RedisStreamLike } from "../../redis-stream-BW9UKLZM.mjs";
1
+ import { n as RedisStreamTransport, r as RedisStreamTransportOptions, t as RedisStreamLike } from "../../redis-stream-Dag5LFa9.mjs";
2
2
  export { type RedisStreamLike, RedisStreamTransport, type RedisStreamTransportOptions };
@@ -1,4 +1,4 @@
1
- import { i as EventTransport, n as EventHandler, r as EventLogger, t as DomainEvent } from "../../EventTransport-wc5hSLik.mjs";
1
+ import { i as EventTransport, n as EventHandler, r as EventLogger, t as DomainEvent } from "../../EventTransport-C4VheKeC.mjs";
2
2
 
3
3
  //#region src/events/transports/redis.d.ts
4
4
  interface RedisLike {
@@ -1,4 +1,4 @@
1
- import { a as CustomPluginAuthOption, c as RawBodyOptions, d as ResourceLike, f as loadResources, i as CustomAuthenticatorOption, l as UnderPressureOptions, n as BetterAuthOption, o as JwtAuthOption, r as CreateAppOptions, s as MultipartOptions, t as AuthOption, u as LoadResourcesOptions } from "../types-By-5mIfn.mjs";
1
+ import { a as CustomPluginAuthOption, c as RawBodyOptions, d as ResourceLike, f as loadResources, i as CustomAuthenticatorOption, l as UnderPressureOptions, n as BetterAuthOption, o as JwtAuthOption, r as CreateAppOptions, s as MultipartOptions, t as AuthOption, u as LoadResourcesOptions } from "../types-2FlNl0mL.mjs";
2
2
  import { FastifyInstance } from "fastify";
3
3
 
4
4
  //#region src/factory/createApp.d.ts
@@ -1,4 +1,4 @@
1
- import { a as edgePreset, c as testingPreset, i as developmentPreset, n as createApp, o as getPreset, s as productionPreset, t as ArcFactory } from "../createApp-D2w0LdYJ.mjs";
1
+ import { a as edgePreset, c as testingPreset, i as developmentPreset, n as createApp, o as getPreset, s as productionPreset, t as ArcFactory } from "../createApp-D7e77m8C.mjs";
2
2
  import { readdir } from "node:fs/promises";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -1,2 +1,2 @@
1
- import { _n as defineHook, an as HookOperation, cn as HookSystem, dn as afterDelete, fn as afterUpdate, gn as createHookSystem, hn as beforeUpdate, in as HookHandler, ln as HookSystemOptions, mn as beforeDelete, nn as DefineHookOptions, on as HookPhase, pn as beforeCreate, rn as HookContext, sn as HookRegistration, un as afterCreate } from "../interface-DYH8AXGe.mjs";
1
+ import { _n as defineHook, an as HookOperation, cn as HookSystem, dn as afterDelete, fn as afterUpdate, gn as createHookSystem, hn as beforeUpdate, in as HookHandler, ln as HookSystemOptions, mn as beforeDelete, nn as DefineHookOptions, on as HookPhase, pn as beforeCreate, rn as HookContext, sn as HookRegistration, un as afterCreate } from "../interface-B91alUzq.mjs";
2
2
  export { type DefineHookOptions, type HookContext, type HookHandler, type HookOperation, type HookPhase, type HookRegistration, HookSystem, type HookSystemOptions, afterCreate, afterDelete, afterUpdate, beforeCreate, beforeDelete, beforeUpdate, createHookSystem, defineHook };
@@ -1,2 +1,2 @@
1
- import { a as beforeCreate, c as createHookSystem, i as afterUpdate, l as defineHook, n as afterCreate, o as beforeDelete, r as afterDelete, s as beforeUpdate, t as HookSystem } from "../HookSystem-COkyWztM.mjs";
1
+ import { a as beforeCreate, c as createHookSystem, i as afterUpdate, l as defineHook, n as afterCreate, o as beforeDelete, r as afterDelete, s as beforeUpdate, t as HookSystem } from "../HookSystem-D7lfx--K.mjs";
2
2
  export { HookSystem, afterCreate, afterDelete, afterUpdate, beforeCreate, beforeDelete, beforeUpdate, createHookSystem, defineHook };
@@ -1,6 +1,6 @@
1
- import { i as createIdempotencyResult, n as IdempotencyResult, r as IdempotencyStore, t as IdempotencyLock } from "../interface-gr-7qo9j.mjs";
2
- import { n as MongoIdempotencyStoreOptions } from "../mongodb-pMvOlR5_.mjs";
3
- import { r as RedisIdempotencyStoreOptions, t as RedisClient } from "../redis-D0Qc-9EW.mjs";
1
+ import { i as createIdempotencyResult, n as IdempotencyResult, r as IdempotencyStore, t as IdempotencyLock } from "../interface-CSbZdv_3.mjs";
2
+ import { n as MongoIdempotencyStoreOptions } from "../mongodb-B7zupyck.mjs";
3
+ import { r as RedisIdempotencyStoreOptions, t as RedisClient } from "../redis-3TQxm2VZ.mjs";
4
4
  import { FastifyPluginAsync } from "fastify";
5
5
 
6
6
  //#region src/idempotency/idempotencyPlugin.d.ts
@@ -1,2 +1,2 @@
1
- import { n as MongoIdempotencyStoreOptions, t as MongoIdempotencyStore } from "../mongodb-pMvOlR5_.mjs";
1
+ import { n as MongoIdempotencyStoreOptions, t as MongoIdempotencyStore } from "../mongodb-B7zupyck.mjs";
2
2
  export { MongoIdempotencyStore, type MongoIdempotencyStoreOptions };
@@ -1,2 +1,2 @@
1
- import { n as RedisIdempotencyStore, r as RedisIdempotencyStoreOptions, t as RedisClient } from "../redis-D0Qc-9EW.mjs";
1
+ import { n as RedisIdempotencyStore, r as RedisIdempotencyStoreOptions, t as RedisClient } from "../redis-3TQxm2VZ.mjs";
2
2
  export { type RedisClient, RedisIdempotencyStore, type RedisIdempotencyStoreOptions };