@classytic/arc 2.23.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/{BaseController-BQ8KNvWC.mjs → BaseController--M8EMzt0.mjs} +90 -21
  2. package/dist/QueryCache-DOMT_iq7.d.mts +72 -0
  3. package/dist/actionPermissions-CAphcmUG.mjs +24 -0
  4. package/dist/audit/index.d.mts +32 -3
  5. package/dist/audit/index.mjs +7 -4
  6. package/dist/auth/index.d.mts +2 -2
  7. package/dist/auth/index.mjs +263 -259
  8. package/dist/{buildHandler-D_2ULWxZ.mjs → buildHandler-Dtwd8fdz.mjs} +1 -1
  9. package/dist/cache/index.d.mts +41 -3
  10. package/dist/cache/index.mjs +33 -4
  11. package/dist/cli/commands/describe.d.mts +1 -1
  12. package/dist/cli/commands/docs.mjs +1 -1
  13. package/dist/cli/commands/generate.mjs +1 -1
  14. package/dist/cli/commands/init.mjs +1 -1
  15. package/dist/cli/index.mjs +2 -2
  16. package/dist/context/index.mjs +2 -64
  17. package/dist/core/index.d.mts +3 -3
  18. package/dist/core/index.mjs +4 -4
  19. package/dist/{core-DQ6rDTyH.mjs → core-EUNu0u07.mjs} +296 -11
  20. package/dist/{createActionRouter-BuOv-m4Y.mjs → createActionRouter-B6GvAuAX.mjs} +3 -2
  21. package/dist/{createAggregationRouter-CgJv_BU_.mjs → createAggregationRouter-wzwFa_dW.mjs} +3 -3
  22. package/dist/docs/index.d.mts +1 -1
  23. package/dist/docs/index.mjs +2 -2
  24. package/dist/{elevation-COpYKt2h.mjs → elevation-CIz1GjGm.mjs} +4 -3
  25. package/dist/{eventPlugin-A6EbthXR.d.mts → eventPlugin-Bg3cP2_u.d.mts} +38 -3
  26. package/dist/{eventPlugin-DJG2D7sy.mjs → eventPlugin-DrQ_FesK.mjs} +22 -4
  27. package/dist/events/index.d.mts +57 -314
  28. package/dist/events/index.mjs +163 -91
  29. package/dist/events/transports/redis-stream-entry.d.mts +1 -1
  30. package/dist/events/transports/redis-stream-entry.mjs +24 -2
  31. package/dist/factory/index.d.mts +4 -5
  32. package/dist/factory/index.mjs +28 -8
  33. package/dist/{fastify-augmentation-g_f9omSc.d.mts → fastify-augmentation-dPNBVeIj.d.mts} +25 -2
  34. package/dist/{generate-usRSdQmP.mjs → generate-D0wZupBg.mjs} +1 -1
  35. package/dist/headers-BvlQSDMB.mjs +45 -0
  36. package/dist/health-CB_m4S32.mjs +377 -0
  37. package/dist/hooks/index.d.mts +1 -1
  38. package/dist/idempotency/index.mjs +27 -3
  39. package/dist/{index-wMoWBLkn.d.mts → index-BMnbzvtO.d.mts} +3 -3
  40. package/dist/{integrations/jobs.d.mts → index-CG4yqMDB.d.mts} +82 -2
  41. package/dist/{index-BBsvQt7U.d.mts → index-DPRH0Cme.d.mts} +36 -106
  42. package/dist/{module-B4u10iOJ.d.mts → index-KUoxjIq1.d.mts} +263 -23
  43. package/dist/{index-CC5ruDGh.d.mts → index-f4PTrk3B.d.mts} +37 -5
  44. package/dist/index.d.mts +6 -6
  45. package/dist/index.mjs +5 -5
  46. package/dist/{init-CjO4p_q1.mjs → init-tlRSt667.mjs} +206 -208
  47. package/dist/integrations/event-gateway.d.mts +1 -1
  48. package/dist/integrations/event-gateway.mjs +1 -1
  49. package/dist/integrations/index.d.mts +3 -3
  50. package/dist/integrations/jobs/index.d.mts +2 -0
  51. package/dist/integrations/{jobs.mjs → jobs/index.mjs} +110 -67
  52. package/dist/integrations/mcp/index.d.mts +4 -4
  53. package/dist/integrations/mcp/index.mjs +2 -2
  54. package/dist/integrations/mcp/testing.d.mts +1 -1
  55. package/dist/integrations/mcp/testing.mjs +1 -1
  56. package/dist/integrations/webhooks.d.mts +37 -30
  57. package/dist/integrations/webhooks.mjs +51 -62
  58. package/dist/integrations/websocket-redis.d.mts +1 -1
  59. package/dist/integrations/websocket.d.mts +1 -1
  60. package/dist/integrations/websocket.mjs +41 -14
  61. package/dist/{interface-C1_WLTMK.d.mts → interface-BGZCzOGL.d.mts} +24 -31
  62. package/dist/{mcpPlugin-BtzIL_kM.mjs → mcpPlugin-Cb7olw0j.mjs} +11 -9
  63. package/dist/{memory-CLXA2VeJ.mjs → memory-CmnzXE5Z.mjs} +29 -0
  64. package/dist/middleware/index.d.mts +17 -1
  65. package/dist/middleware/index.mjs +1 -1
  66. package/dist/migrations/index.d.mts +94 -44
  67. package/dist/migrations/index.mjs +196 -44
  68. package/dist/{multipartBody-CHEQSZ6G.mjs → multipartBody-D0eBvkeq.mjs} +17 -0
  69. package/dist/{openapi-jSDx-VDv.mjs → openapi-DrLtog_B.mjs} +3 -3
  70. package/dist/permissions/index.d.mts +2 -2
  71. package/dist/permissions/index.mjs +2 -2
  72. package/dist/{permissions-tbxFHxjZ.mjs → permissions-BrtiBKGs.mjs} +229 -229
  73. package/dist/pipeline/index.d.mts +1 -1
  74. package/dist/{actionPermissions-lszoJle1.mjs → pipeline-BN5G05rd.mjs} +3 -26
  75. package/dist/plugins/index.d.mts +6 -77
  76. package/dist/plugins/index.mjs +11 -95
  77. package/dist/plugins/response-cache.mjs +1 -0
  78. package/dist/plugins/tracing-entry.mjs +1 -1
  79. package/dist/{index-Ba10fdKp.d.mts → preloadResources-0oe-JSSS.d.mts} +50 -50
  80. package/dist/{createApp-CjOeWJ9_.mjs → preloadResources-DfyngIN9.mjs} +233 -70
  81. package/dist/presets/filesUpload.d.mts +3 -3
  82. package/dist/presets/filesUpload.mjs +3 -3
  83. package/dist/presets/index.d.mts +2 -1
  84. package/dist/presets/index.mjs +1 -1
  85. package/dist/presets/multiTenant.d.mts +1 -1
  86. package/dist/presets/multiTenant.mjs +1 -1
  87. package/dist/presets/search.d.mts +2 -2
  88. package/dist/presets/search.mjs +1 -1
  89. package/dist/{presets-BOe4Ugkl.mjs → presets-DwFDVKP0.mjs} +2 -2
  90. package/dist/{queryCachePlugin-DzqLN904.mjs → queryCachePlugin-DSGuSVLW.mjs} +39 -8
  91. package/dist/{queryCachePlugin-CfYWq-Ak.d.mts → queryCachePlugin-br4otiqF.d.mts} +2 -2
  92. package/dist/{registerRoute-CWO6mdYe.mjs → rateLimit-DrED-C4v.mjs} +2 -109
  93. package/dist/{realtime-I8OrfnMR.mjs → realtime-Cuw_deA-.mjs} +2 -2
  94. package/dist/{redis-stream-iVR2l7aS.d.mts → redis-stream-uIaauNpZ.d.mts} +22 -0
  95. package/dist/registerRoute-v0Wb6Plt.mjs +108 -0
  96. package/dist/registry/index.d.mts +2 -2
  97. package/dist/renewingLease-3cuQH7h8.mjs +44 -0
  98. package/dist/{requestContext-BZKOr13H.mjs → requestContext-MrlJwECf.mjs} +2 -2
  99. package/dist/schedules-CjOd2MG9.mjs +113 -0
  100. package/dist/schemas/index.d.mts +67 -67
  101. package/dist/schemas/index.mjs +2 -3
  102. package/dist/scim/index.mjs +1 -2
  103. package/dist/scope/index.d.mts +2 -2
  104. package/dist/scope/index.mjs +4 -4
  105. package/dist/{scope-LONQ3mfZ.mjs → scope-DfaPntpo.mjs} +4 -5
  106. package/dist/{sse-0u4P4-OI.mjs → sse-BQ1w0dfl.mjs} +1 -1
  107. package/dist/testing/index.d.mts +4 -3
  108. package/dist/testing/index.mjs +2 -2
  109. package/dist/transactionContext-PNdoyLLm.mjs +64 -0
  110. package/dist/types/index.d.mts +4 -4
  111. package/dist/{types-bHblZ9YN.mjs → types-CSyCxl2V.mjs} +38 -7
  112. package/dist/{types-DH0GupI7.d.mts → types-DjC-KUCz.d.mts} +118 -20
  113. package/dist/{types-Csxga7d3.d.mts → types-Dmw-6Qeo.d.mts} +96 -4
  114. package/dist/{types-5OuqeTDX.d.mts → types-QFGc3Cjv.d.mts} +1 -1
  115. package/dist/usage/index.d.mts +3 -52
  116. package/dist/usage/index.mjs +0 -0
  117. package/dist/userHelpers-Cg_y3fBz.mjs +29 -0
  118. package/dist/utils/index.d.mts +58 -85
  119. package/dist/utils/index.mjs +4 -2
  120. package/dist/{utils-CZyeRXTh.mjs → utils-taUVD4p3.mjs} +47 -337
  121. package/dist/{validate-C2mGgSXg.mjs → validate-Bk44F2yT.mjs} +1 -1
  122. package/dist/{versioning-D6PvCwpq.d.mts → versioning-DXgY5BUm.d.mts} +11 -29
  123. package/dist/{versioning-Dk-71iIz.mjs → versioning-gKWyryT3.mjs} +8 -1
  124. package/dist/{websocket-uuWqM6UY.d.mts → websocket-_Pd0CgR0.d.mts} +15 -1
  125. package/package.json +526 -513
  126. package/skills/arc/references/api-reference.md +3 -1
  127. package/skills/arc/references/integrations.md +20 -11
  128. package/dist/QueryCache-Z1B38koh.d.mts +0 -40
  129. package/dist/betterAuthOpenApi-CV1lxpRX.mjs +0 -2
  130. package/dist/health-ScyjIVo5.mjs +0 -202
  131. package/dist/requestId-5BhTVzBv.mjs +0 -113
  132. package/dist/types-XTApa8b6.mjs +0 -24
@@ -1,14 +1,14 @@
1
1
  import { h as SYSTEM_FIELDS, o as DEFAULT_TENANT_FIELD } from "./constants-DNre0wRg.mjs";
2
2
  import { arcLog } from "./logger/index.mjs";
3
3
  import { d as createDomainError, f as createError, i as NotFoundError, r as ForbiddenError } from "./errors-DkO8Nk6-.mjs";
4
- import { b as isElevated, c as getOrgId, n as PUBLIC_SCOPE, x as isMember } from "./types-bHblZ9YN.mjs";
4
+ import { n as getUserRoles, t as getUserId } from "./userHelpers-Cg_y3fBz.mjs";
5
+ import { b as isElevated, c as getOrgId, n as PUBLIC_SCOPE, x as isMember } from "./types-CSyCxl2V.mjs";
5
6
  import { t as simpleEqualityMatcher } from "./simpleEqualityMatcher-Cg05HPsn.mjs";
6
7
  import { a as applyFieldWritePermissions, s as resolveEffectiveRoles } from "./applyPermissionResult-Tw4iXtlf.mjs";
7
- import { t as getUserRoles } from "./types-XTApa8b6.mjs";
8
- import { _ as ArcQueryParser, r as scheduleBackground, t as getUserId } from "./utils-CZyeRXTh.mjs";
8
+ import { g as ArcQueryParser, n as scheduleBackground } from "./utils-taUVD4p3.mjs";
9
9
  import { t as buildQueryKey } from "./keys-Cd316u_y.mjs";
10
10
  //#region src/core/AccessControl.ts
11
- const log = arcLog("access-control");
11
+ const log$1 = arcLog("access-control");
12
12
  var AccessControl = class {
13
13
  tenantField;
14
14
  idField;
@@ -88,7 +88,7 @@ var AccessControl = class {
88
88
  _warnNoMatcher(policyFilters) {
89
89
  if (this._warnedNoMatcher) return;
90
90
  this._warnedNoMatcher = true;
91
- log.warn("`_policyFilters` contains operator-shaped entries (e.g. `$in`, `$ne`, `$regex`) but `DataAdapter.matchesFilter` is not set. Arc's flat-equality fallback cannot evaluate operators and will reject these items on non-compound fetches (`validateItemAccess`, `getBySlug`, cache revalidation). Wire up `matchesFilter` on your adapter — use `matchFilter` from `@classytic/repo-core/filter` for IR-based adapters, or your DB's native predicate engine.", { policyFilterKeys: Object.keys(policyFilters) });
91
+ log$1.warn("`_policyFilters` contains operator-shaped entries (e.g. `$in`, `$ne`, `$regex`) but `DataAdapter.matchesFilter` is not set. Arc's flat-equality fallback cannot evaluate operators and will reject these items on non-compound fetches (`validateItemAccess`, `getBySlug`, cache revalidation). Wire up `matchesFilter` on your adapter — use `matchFilter` from `@classytic/repo-core/filter` for IR-based adapters, or your DB's native predicate engine.", { policyFilterKeys: Object.keys(policyFilters) });
92
92
  }
93
93
  /**
94
94
  * Check org/tenant scope for a document — uses configurable tenantField.
@@ -618,6 +618,20 @@ const defaultParser = new ArcQueryParser();
618
618
  function getDefaultQueryParser() {
619
619
  return defaultParser;
620
620
  }
621
+ const log = arcLog("query");
622
+ /**
623
+ * Deny-by-default (2.24 flip): `populate=` / `lookup=` with NO allowlist
624
+ * configured is rejected — client-driven joins/population are an easy
625
+ * accidental N+1 / expensive-join surface, and "absent means all" made
626
+ * every resource opt into it silently. A one-shot dev log explains the
627
+ * drop the first time a request hits it.
628
+ */
629
+ let notedDeniedJoins = false;
630
+ function noteDeniedJoins(kind) {
631
+ if (notedDeniedJoins || process.env.NODE_ENV === "production") return;
632
+ notedDeniedJoins = true;
633
+ log.warn(`client requested ${kind} but no allowlist is configured — DENIED (2.24 default flip; it was allow-all). Set schemaOptions.query.allowedPopulate / allowedLookups to enable client-driven joins. (dev-only note, shown once)`);
634
+ }
621
635
  var QueryResolver = class {
622
636
  queryParser;
623
637
  maxLimit;
@@ -709,7 +723,10 @@ var QueryResolver = class {
709
723
  const allowedPopulate = schemaOptions.query?.allowedPopulate;
710
724
  const requested = typeof populate === "string" ? populate.split(",").map((p) => p.trim()) : Array.isArray(populate) ? populate.map(String) : [];
711
725
  if (requested.length === 0) return void 0;
712
- if (!allowedPopulate) return requested;
726
+ if (!allowedPopulate) {
727
+ noteDeniedJoins("populate");
728
+ return;
729
+ }
713
730
  const sanitized = requested.filter((p) => allowedPopulate.includes(p));
714
731
  return sanitized.length > 0 ? sanitized : void 0;
715
732
  }
@@ -717,25 +734,32 @@ var QueryResolver = class {
717
734
  sanitizePopulateOptions(options, schemaOptions) {
718
735
  if (!options || options.length === 0) return void 0;
719
736
  const allowedPopulate = schemaOptions.query?.allowedPopulate;
720
- if (!allowedPopulate) return options;
737
+ if (!allowedPopulate) {
738
+ noteDeniedJoins("populate");
739
+ return;
740
+ }
721
741
  const sanitized = options.filter((opt) => allowedPopulate.includes(opt.path));
722
742
  return sanitized.length > 0 ? sanitized : void 0;
723
743
  }
724
744
  /**
725
- * Sanitize lookup/join options.
726
- * If schemaOptions.query.allowedLookups is set, only those collections are allowed.
727
- * Validates lookup structure to prevent injection.
745
+ * Sanitize lookup/join options. Deny-by-default: `allowedLookups` must be
746
+ * configured for any client-driven lookup to pass; listed collections are
747
+ * then structurally validated to prevent injection.
728
748
  */
729
749
  sanitizeLookups(lookups, schemaOptions) {
730
750
  if (!lookups || lookups.length === 0) return void 0;
731
751
  const allowedLookups = schemaOptions.query?.allowedLookups;
752
+ if (!allowedLookups) {
753
+ noteDeniedJoins("lookups");
754
+ return;
755
+ }
732
756
  const validFieldName = /^[a-zA-Z_][a-zA-Z0-9_.]*$/;
733
757
  const sanitized = lookups.filter((lookup) => {
734
758
  if (!lookup.from || !lookup.localField || !lookup.foreignField) return false;
735
759
  if (!validFieldName.test(lookup.from)) return false;
736
760
  if (!validFieldName.test(lookup.localField)) return false;
737
761
  if (!validFieldName.test(lookup.foreignField)) return false;
738
- if (allowedLookups && !allowedLookups.includes(lookup.from)) return false;
762
+ if (!allowedLookups.includes(lookup.from)) return false;
739
763
  return true;
740
764
  });
741
765
  return sanitized.length > 0 ? sanitized : void 0;
@@ -1083,6 +1107,45 @@ var BaseCrudController = class {
1083
1107
  async runAfterHook(req, op, data, meta) {
1084
1108
  return executeAfterHook(this.hookOpContext(req), op, data, meta);
1085
1109
  }
1110
+ /**
1111
+ * Per-instance single-flight for cache fills — concurrent requests for
1112
+ * the SAME cache key coalesce onto one repository query instead of each
1113
+ * issuing its own (a popular entry expiring under 1,000 concurrent
1114
+ * readers must produce 1 DB query, not 1,000). Keys already encode the
1115
+ * resolved query + user/org scope + resource version, so coalescing can
1116
+ * never cross tenants, scopes, or invalidation generations. Per-process
1117
+ * by design; distributed refresh leases are a store-level concern
1118
+ * (planned with the repo-core CacheEngine façade, which ships
1119
+ * single-flight natively).
1120
+ */
1121
+ inFlightCacheFills = /* @__PURE__ */ new Map();
1122
+ cacheSingleFlight(key, fill) {
1123
+ const existing = this.inFlightCacheFills.get(key);
1124
+ if (existing) return existing;
1125
+ const flight = fill().finally(() => {
1126
+ this.inFlightCacheFills.delete(key);
1127
+ });
1128
+ this.inFlightCacheFills.set(key, flight);
1129
+ return flight;
1130
+ }
1131
+ /**
1132
+ * Register a background SWR refresh for `key` unless one is already in
1133
+ * flight. Registration is SYNCHRONOUS (before the deferred tick) so a
1134
+ * burst of stale readers arriving in the same tick schedules exactly one
1135
+ * revalidation.
1136
+ */
1137
+ scheduleCacheRefresh(key, refresh) {
1138
+ if (this.inFlightCacheFills.has(key)) return;
1139
+ const flight = new Promise((resolve) => {
1140
+ scheduleBackground(() => {
1141
+ refresh().catch(() => {}).finally(() => {
1142
+ this.inFlightCacheFills.delete(key);
1143
+ resolve();
1144
+ });
1145
+ });
1146
+ });
1147
+ this.inFlightCacheFills.set(key, flight);
1148
+ }
1086
1149
  /** Cached `list()` flow with SWR semantics. Returns null when cache is disabled. */
1087
1150
  async withListCache(req, options) {
1088
1151
  const cacheConfig = this.resolveCacheConfig("list");
@@ -1095,13 +1158,17 @@ var BaseCrudController = class {
1095
1158
  const { data, status } = await qc.get(key);
1096
1159
  if (status === "fresh") return this.cacheResponse(data, "HIT");
1097
1160
  if (status === "stale") {
1098
- scheduleBackground(() => {
1099
- this.executeListQuery(options, req).then((fresh) => qc.set(key, fresh, cacheConfig)).catch(() => {});
1161
+ this.scheduleCacheRefresh(key, async () => {
1162
+ const fresh = await this.executeListQuery(options, req);
1163
+ await qc.set(key, fresh, cacheConfig);
1100
1164
  });
1101
1165
  return this.cacheResponse(data, "STALE");
1102
1166
  }
1103
- const result = await this.executeListQuery(options, req);
1104
- await qc.set(key, result, cacheConfig);
1167
+ const result = await this.cacheSingleFlight(key, async () => {
1168
+ const fresh = await this.executeListQuery(options, req);
1169
+ await qc.set(key, fresh, cacheConfig);
1170
+ return fresh;
1171
+ });
1105
1172
  return this.cacheResponse(result, "MISS");
1106
1173
  }
1107
1174
  /** Cached `get()` flow with SWR semantics. Returns null when cache is disabled. */
@@ -1119,16 +1186,18 @@ var BaseCrudController = class {
1119
1186
  const { data, status } = await qc.get(key);
1120
1187
  if (status === "fresh") return this.cacheResponse(data, "HIT");
1121
1188
  if (status === "stale") {
1122
- scheduleBackground(() => {
1123
- this.executeGetQuery(id, options, req).then(({ doc: fresh }) => {
1124
- if (fresh) qc.set(key, fresh, cacheConfig);
1125
- }).catch(() => {});
1189
+ this.scheduleCacheRefresh(key, async () => {
1190
+ const { doc: fresh } = await this.executeGetQuery(id, options, req);
1191
+ if (fresh) await qc.set(key, fresh, cacheConfig);
1126
1192
  });
1127
1193
  return this.cacheResponse(data, "STALE");
1128
1194
  }
1129
- const { doc, reason } = await this.executeGetQuery(id, options, req);
1195
+ const { doc, reason } = await this.cacheSingleFlight(key, async () => {
1196
+ const result = await this.executeGetQuery(id, options, req);
1197
+ if (result.doc) await qc.set(key, result.doc, cacheConfig);
1198
+ return result;
1199
+ });
1130
1200
  if (!doc) this.throwNotFound(reason);
1131
- await qc.set(key, doc, cacheConfig);
1132
1201
  return this.cacheResponse(doc, "MISS");
1133
1202
  }
1134
1203
  async list(req) {
@@ -0,0 +1,72 @@
1
+ import { r as CacheStore } from "./interface-BGZCzOGL.mjs";
2
+ //#region src/cache/QueryCache.d.ts
3
+ /** Metadata wrapper stored in CacheStore */
4
+ interface CacheEnvelope<T = unknown> {
5
+ data: T;
6
+ createdAt: number;
7
+ staleAfter: number;
8
+ expiresAt: number;
9
+ tags: string[];
10
+ }
11
+ interface QueryCacheConfig {
12
+ /** Seconds data is "fresh" (no revalidation). Default: 0 */
13
+ staleTime?: number;
14
+ /** Seconds stale data stays cached (SWR window). Default: 60 */
15
+ gcTime?: number;
16
+ /** Tags for group invalidation */
17
+ tags?: string[];
18
+ /**
19
+ * Randomized freshness jitter (0–1, default 0 = off). Each write varies
20
+ * its effective `staleTime` by ±(jitter × staleTime), so entries cached
21
+ * together don't all go stale in the same instant — spreading
22
+ * revalidation load instead of synchronizing a refresh burst.
23
+ * Single-flight coalescing (BaseCrudController) handles same-key
24
+ * stampedes; jitter de-synchronizes ACROSS keys. 0.1 is a sane value.
25
+ */
26
+ jitter?: number;
27
+ }
28
+ type CacheStatus = "fresh" | "stale" | "miss";
29
+ interface CacheResult<T> {
30
+ data: T;
31
+ status: CacheStatus;
32
+ }
33
+ declare class QueryCache {
34
+ private readonly store;
35
+ constructor(store: CacheStore);
36
+ get<T>(key: string): Promise<CacheResult<T>>;
37
+ set<T>(key: string, data: T, config: QueryCacheConfig): Promise<void>;
38
+ invalidate(key: string): Promise<void>;
39
+ /** Get current version for a resource (defaults to 0 if not set) */
40
+ getResourceVersion(resource: string): Promise<number>;
41
+ /** Bump resource version — orphans all cached queries for this resource */
42
+ bumpResourceVersion(resource: string): Promise<void>;
43
+ /** Get current version for a tag */
44
+ getTagVersion(tag: string): Promise<number>;
45
+ /** Bump tag version — orphans all cached queries tagged with this tag */
46
+ bumpTagVersion(tag: string): Promise<void>;
47
+ /**
48
+ * Version-bump semantics:
49
+ *
50
+ * - `store.increment` present (Redis `INCR`) — atomic and strictly
51
+ * monotonic across replicas; concurrent bumps can never collide or
52
+ * go backwards.
53
+ * - fallback — read-modify-write with `max(now, current + 1)`: two
54
+ * bumps in the same millisecond and clock regressions still advance
55
+ * the version. Concurrent bumps from DIFFERENT replicas can lose one
56
+ * write, which is why distributed hosts should use an incrementing
57
+ * store (`runtime: 'distributed'` already requires a shared one).
58
+ *
59
+ * Version keys must outlive every derived cache entry — that invariant
60
+ * is what makes version invalidation sound (a version key expiring back
61
+ * to 0 would make entries written under the pre-reset version
62
+ * addressable again). The 1-year TTL applies with the repo-core
63
+ * TTL-ON-CREATE semantics, so a version key expires one year after its
64
+ * FIRST bump — safe, because a revived collision would need an entry to
65
+ * outlive that reset and entry TTLs are minutes-scale (staleTime +
66
+ * gcTime). The read-modify-write fallback uses plain `set`, which
67
+ * refreshes the TTL per bump — strictly longer-lived, equally safe.
68
+ */
69
+ private bumpVersion;
70
+ }
71
+ //#endregion
72
+ export { QueryCacheConfig as a, QueryCache as i, CacheResult as n, CacheStatus as r, CacheEnvelope as t };
@@ -0,0 +1,24 @@
1
+ //#region src/core/actionPermissions.ts
2
+ /**
3
+ * Return the effective `PermissionCheck` for a single action, or `undefined`
4
+ * when the resource declares no gate at any level.
5
+ *
6
+ * Callers decide what "no gate" means:
7
+ * - HTTP: boot-time throw in `normalizeActionsToRouterConfig`.
8
+ * - MCP: tool-generation throw in `resourceToTools` (mirrors HTTP — the
9
+ * two surfaces fail closed identically so MCP can't expose an
10
+ * unauthenticated mutating tool when the HTTP plugin lifecycle hasn't
11
+ * run).
12
+ * - OpenAPI: docs advertise the endpoint as unauthenticated.
13
+ */
14
+ function resolveActionPermission(input) {
15
+ const { action, resourcePermissions, resourceActionPermissions, globalAuth } = input;
16
+ const explicit = typeof action !== "function" && action.permissions ? action.permissions : void 0;
17
+ if (explicit) return explicit;
18
+ if (resourceActionPermissions) return resourceActionPermissions;
19
+ if (globalAuth) return globalAuth;
20
+ const updateFallback = resourcePermissions?.update;
21
+ if (updateFallback) return updateFallback;
22
+ }
23
+ //#endregion
24
+ export { resolveActionPermission as t };
@@ -1,5 +1,5 @@
1
- import "../index-BBsvQt7U.mjs";
2
- import { i as UserBase } from "../types-Csxga7d3.mjs";
1
+ import "../index-DPRH0Cme.mjs";
2
+ import { i as UserBase } from "../types-Dmw-6Qeo.mjs";
3
3
  import { FastifyPluginAsync } from "fastify";
4
4
  import { RepositoryLike } from "@classytic/repo-core/adapter";
5
5
  //#region src/audit/stores/interface.d.ts
@@ -131,6 +131,17 @@ interface AuditPluginOptions {
131
131
  /** Interval between purges in ms. Default 86_400_000 (24h). 0 disables the timer. */
132
132
  purgeIntervalMs?: number;
133
133
  };
134
+ /**
135
+ * Unit-of-Work session provider for the built-in `repository` store. When a
136
+ * request runs inside a `transactionContext.run(session, …)` scope, the audit
137
+ * row is written **with that session**, so it commits/rolls back atomically
138
+ * with the domain write. Defaults to `() => transactionContext.get()`, so
139
+ * atomic audit works out of the box for kits that honor a write session
140
+ * (mongokit). Outside a transaction scope the provider returns `undefined`
141
+ * and the audit write proceeds session-less (unchanged). Pass `false` (or
142
+ * `() => undefined`) to opt out.
143
+ */
144
+ sessionProvider?: (() => unknown) | false;
134
145
  /**
135
146
  * Automatically audit CRUD operations via the hook system (default: true when enabled).
136
147
  * When enabled, create/update/delete operations are auto-logged without manual calls.
@@ -207,7 +218,25 @@ declare const auditPlugin: FastifyPluginAsync<AuditPluginOptions>;
207
218
  declare const _default: FastifyPluginAsync<AuditPluginOptions>;
208
219
  //#endregion
209
220
  //#region src/audit/repository-audit-adapter.d.ts
210
- declare function repositoryAsAuditStore(repository: RepositoryLike): AuditStore;
221
+ /** Options for {@link repositoryAsAuditStore}. */
222
+ interface RepositoryAuditStoreOptions {
223
+ /**
224
+ * Unit-of-Work session provider (AsyncLocalStorage integration), mirroring
225
+ * {@link EventOutbox}'s `sessionProvider`. When set, `log()` calls it to get
226
+ * the active DB session and writes the audit row **with that session**, so
227
+ * the audit entry commits/rolls back **atomically with the domain write**
228
+ * that produced it — no unaudited successful write, and no orphan audit for a
229
+ * rolled-back write. Returns `undefined` outside a transaction scope, in
230
+ * which case the write proceeds session-less (unchanged legacy behaviour).
231
+ *
232
+ * Wire with arc's `transactionContext` (auditPlugin does this by default):
233
+ * ```ts
234
+ * repositoryAsAuditStore(repo, { sessionProvider: () => transactionContext.get() })
235
+ * ```
236
+ */
237
+ readonly sessionProvider?: () => unknown;
238
+ }
239
+ declare function repositoryAsAuditStore(repository: RepositoryLike, options?: RepositoryAuditStoreOptions): AuditStore;
211
240
  //#endregion
212
241
  //#region src/audit/stores/memory.d.ts
213
242
  interface MemoryAuditStoreOptions {
@@ -1,8 +1,10 @@
1
+ import { t as transactionContext } from "../transactionContext-PNdoyLLm.mjs";
1
2
  import fp from "fastify-plugin";
2
3
  import { and, anyOf, eq, gte, lt, lte } from "@classytic/repo-core/filter";
3
4
  //#region src/audit/repository-audit-adapter.ts
4
- function repositoryAsAuditStore(repository) {
5
+ function repositoryAsAuditStore(repository, options = {}) {
5
6
  const idField = repository.idField ?? "_id";
7
+ const { sessionProvider } = options;
6
8
  return {
7
9
  name: "repository",
8
10
  async log(entry) {
@@ -22,7 +24,8 @@ function repositoryAsAuditStore(repository) {
22
24
  metadata: entry.metadata,
23
25
  timestamp: entry.timestamp
24
26
  };
25
- await repository.create(doc);
27
+ const session = sessionProvider?.();
28
+ await repository.create(doc, session != null ? { session } : void 0);
26
29
  },
27
30
  async purgeOlderThan(cutoff) {
28
31
  if (!repository.deleteMany) return 0;
@@ -173,7 +176,7 @@ var MemoryAuditStore = class {
173
176
  //#endregion
174
177
  //#region src/audit/auditPlugin.ts
175
178
  const auditPlugin = async (fastify, opts = {}) => {
176
- const { enabled = false, repository, customStores = [] } = opts;
179
+ const { enabled = false, repository, customStores = [], sessionProvider = () => transactionContext.get() } = opts;
177
180
  if (!enabled) {
178
181
  fastify.decorate("audit", createNoopLogger());
179
182
  fastify.decorateRequest("auditContext", void 0);
@@ -181,7 +184,7 @@ const auditPlugin = async (fastify, opts = {}) => {
181
184
  return;
182
185
  }
183
186
  const stores = [];
184
- if (repository) stores.push(repositoryAsAuditStore(repository));
187
+ if (repository) stores.push(repositoryAsAuditStore(repository, { sessionProvider: sessionProvider === false ? void 0 : sessionProvider }));
185
188
  stores.push(...customStores);
186
189
  if (stores.length === 0) stores.push(new MemoryAuditStore());
187
190
  async function logToStores(entry) {
@@ -1,5 +1,5 @@
1
- import { Ht as AuthHelpers, Ut as AuthPluginOptions } from "../index-BBsvQt7U.mjs";
2
- import { t as PermissionCheck } from "../types-Csxga7d3.mjs";
1
+ import { Ht as AuthHelpers, Ut as AuthPluginOptions } from "../index-DPRH0Cme.mjs";
2
+ import { t as PermissionCheck } from "../types-Dmw-6Qeo.mjs";
3
3
  import { t as ExternalOpenApiPaths } from "../externalPaths-BE6wFpYv.mjs";
4
4
  import { a as SessionManagerOptions, c as createSessionManager, i as SessionData, n as MemorySessionStoreOptions, o as SessionManagerResult, r as SessionCookieOptions, s as SessionStore, t as MemorySessionStore } from "../sessionManager-BHOM3N_0.mjs";
5
5
  import { FastifyPluginAsync, FastifyReply as FastifyReply$1, FastifyRequest } from "fastify";