@digilogiclabs/platform-core 1.20.3 → 1.23.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 (38) hide show
  1. package/dist/{ConsoleEmail-CO0OM4UT.d.ts → ConsoleEmail-CgSIvRdj.d.mts} +5 -46
  2. package/dist/{ConsoleEmail-DDB28vyS.d.mts → ConsoleEmail-iJO7Cb_v.d.ts} +5 -46
  3. package/dist/{IAI-D8wA_i8N.d.mts → IAI-B7pp322X.d.mts} +1 -170
  4. package/dist/{IAI-D8wA_i8N.d.ts → IAI-B7pp322X.d.ts} +1 -170
  5. package/dist/ICache-BWSuTuhz.d.mts +66 -0
  6. package/dist/ICache-BWSuTuhz.d.ts +66 -0
  7. package/dist/IEmail-CsOcaQcb.d.mts +45 -0
  8. package/dist/IEmail-CsOcaQcb.d.ts +45 -0
  9. package/dist/ILogger-DLDBZaH4.d.mts +105 -0
  10. package/dist/ILogger-DLDBZaH4.d.ts +105 -0
  11. package/dist/{agents-DGciJI27.d.mts → agents-C7FPA8y9.d.mts} +3 -1
  12. package/dist/{agents-Cc65YUoW.d.ts → agents-qyQ3BtXy.d.ts} +3 -1
  13. package/dist/agents.d.mts +4 -2
  14. package/dist/agents.d.ts +4 -2
  15. package/dist/auth.d.mts +386 -1
  16. package/dist/auth.d.ts +386 -1
  17. package/dist/auth.js +451 -0
  18. package/dist/auth.js.map +1 -1
  19. package/dist/auth.mjs +434 -0
  20. package/dist/auth.mjs.map +1 -1
  21. package/dist/circuit-breaker-CP6kw0P5.d.ts +351 -0
  22. package/dist/circuit-breaker-CsQivd57.d.mts +351 -0
  23. package/dist/email-templates.d.mts +106 -1
  24. package/dist/email-templates.d.ts +106 -1
  25. package/dist/email-templates.js +608 -0
  26. package/dist/email-templates.js.map +1 -1
  27. package/dist/email-templates.mjs +596 -0
  28. package/dist/email-templates.mjs.map +1 -1
  29. package/dist/index.d.mts +14 -355
  30. package/dist/index.d.ts +14 -355
  31. package/dist/index.js +10 -7
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +10 -7
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/migrate.js +0 -0
  36. package/dist/testing.d.mts +6 -3
  37. package/dist/testing.d.ts +6 -3
  38. package/package.json +11 -11
package/dist/auth.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/auth/index.ts
@@ -22,6 +32,7 @@ var auth_exports = {};
22
32
  __export(auth_exports, {
23
33
  ApiError: () => ApiError,
24
34
  ApiErrorCode: () => ApiErrorCode,
35
+ CacheTTL: () => CacheTTL,
25
36
  CommonApiErrors: () => CommonApiErrors,
26
37
  CommonRateLimits: () => CommonRateLimits,
27
38
  DateRangeSchema: () => DateRangeSchema,
@@ -56,11 +67,13 @@ __export(auth_exports, {
56
67
  constantTimeEqual: () => constantTimeEqual,
57
68
  containsHtml: () => containsHtml,
58
69
  containsUrls: () => containsUrls,
70
+ createAppCache: () => createAppCache,
59
71
  createAuditActor: () => createAuditActor,
60
72
  createAuditLogger: () => createAuditLogger,
61
73
  createBetaClient: () => createBetaClient,
62
74
  createEnsureUser: () => createEnsureUser,
63
75
  createFeatureFlags: () => createFeatureFlags,
76
+ createHealthRoute: () => createHealthRoute,
64
77
  createLazyRateLimitStore: () => createLazyRateLimitStore,
65
78
  createMemoryRateLimitStore: () => createMemoryRateLimitStore,
66
79
  createRedisRateLimitStore: () => createRedisRateLimitStore,
@@ -92,6 +105,7 @@ __export(auth_exports, {
92
105
  hasRole: () => hasRole,
93
106
  isAllowlisted: () => isAllowlisted,
94
107
  isApiError: () => isApiError,
108
+ isHoneypotFilled: () => isHoneypotFilled,
95
109
  isTokenExpired: () => isTokenExpired,
96
110
  isValidBearerToken: () => isValidBearerToken,
97
111
  parseKeycloakRoles: () => parseKeycloakRoles,
@@ -100,8 +114,10 @@ __export(auth_exports, {
100
114
  resetRateLimitForKey: () => resetRateLimitForKey,
101
115
  resolveIdentifier: () => resolveIdentifier,
102
116
  resolveRateLimitIdentifier: () => resolveRateLimitIdentifier,
117
+ safeRedirect: () => safeRedirect,
103
118
  safeValidate: () => safeValidate,
104
119
  sanitizeApiError: () => sanitizeApiError,
120
+ signToken: () => signToken,
105
121
  storeBetaCode: () => storeBetaCode,
106
122
  stripHtml: () => stripHtml,
107
123
  stripNullBytes: () => stripNullBytes,
@@ -109,6 +125,7 @@ __export(auth_exports, {
109
125
  validateBetaCode: () => validateBetaCode,
110
126
  validateEnvVars: () => validateEnvVars,
111
127
  verifyCronAuth: () => verifyCronAuth,
128
+ verifyToken: () => verifyToken,
112
129
  zodErrorResponse: () => zodErrorResponse
113
130
  });
114
131
  module.exports = __toCommonJS(auth_exports);
@@ -1656,6 +1673,24 @@ function createSecureHandlerFactory(factoryConfig) {
1656
1673
  const resolvedAuditAction = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.action : auditCfg;
1657
1674
  const resolvedAuditResource = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.resource : routeConfig.auditResource;
1658
1675
  const resolvedGetResourceId = typeof auditCfg === "object" && auditCfg !== null ? auditCfg.getResourceId : routeConfig.getResourceId;
1676
+ const emitBlockedAudit = async (reason) => {
1677
+ if (!factoryConfig.auditOnBlocked || !factoryConfig.auditLog) return;
1678
+ const action = factoryConfig.blockedAuditAction ?? "unauthorized_access";
1679
+ try {
1680
+ await factoryConfig.auditLog({
1681
+ actor: session?.user ? {
1682
+ id: session.user.id ?? "unknown",
1683
+ type: isLegacyToken ? "admin" : "user",
1684
+ email: session.user.email ?? void 0
1685
+ } : { id: "anonymous", type: "anonymous" },
1686
+ action,
1687
+ resource: resolvedAuditResource ? { type: resolvedAuditResource, id: "unknown" } : void 0,
1688
+ outcome: "blocked",
1689
+ reason
1690
+ });
1691
+ } catch {
1692
+ }
1693
+ };
1659
1694
  try {
1660
1695
  if (routeConfig.requireAuth || routeConfig.requireAdmin || routeConfig.requireRoles?.length) {
1661
1696
  session = await factoryConfig.getSession();
@@ -1666,6 +1701,7 @@ function createSecureHandlerFactory(factoryConfig) {
1666
1701
  isAdmin = true;
1667
1702
  } else {
1668
1703
  log.warn("Unauthorized access attempt");
1704
+ await emitBlockedAudit("No authenticated session or valid token");
1669
1705
  return Response.json(
1670
1706
  { error: "Unauthorized" },
1671
1707
  { status: 401, headers: { "X-Request-ID": requestId } }
@@ -1674,6 +1710,7 @@ function createSecureHandlerFactory(factoryConfig) {
1674
1710
  }
1675
1711
  if (routeConfig.requireAdmin && !isLegacyToken && !isAdmin) {
1676
1712
  log.warn("Admin access denied");
1713
+ await emitBlockedAudit("Missing admin role");
1677
1714
  return Response.json(
1678
1715
  { error: "Forbidden: Admin access required" },
1679
1716
  { status: 403, headers: { "X-Request-ID": requestId } }
@@ -1685,6 +1722,9 @@ function createSecureHandlerFactory(factoryConfig) {
1685
1722
  );
1686
1723
  if (!hasRole2) {
1687
1724
  log.warn("Role-based access denied");
1725
+ await emitBlockedAudit(
1726
+ `Missing required roles: ${routeConfig.requireRoles.join(", ")}`
1727
+ );
1688
1728
  return Response.json(
1689
1729
  { error: "Forbidden: Insufficient permissions" },
1690
1730
  { status: 403, headers: { "X-Request-ID": requestId } }
@@ -1843,6 +1883,43 @@ function createSecureHandlerFactory(factoryConfig) {
1843
1883
  handler
1844
1884
  );
1845
1885
  }
1886
+ function withRoleBasedApi(roles, config, handler) {
1887
+ return createSecureHandler(
1888
+ {
1889
+ rateLimit: factoryConfig.rateLimiter?.authDefault,
1890
+ ...config,
1891
+ requireAuth: true,
1892
+ requireRoles: roles
1893
+ },
1894
+ handler
1895
+ );
1896
+ }
1897
+ function withDebugApi(config, handler) {
1898
+ const { allowInProduction = false, ...routeConfig } = config;
1899
+ const inner = createSecureHandler(
1900
+ {
1901
+ rateLimit: factoryConfig.rateLimiter?.adminDefault,
1902
+ ...routeConfig,
1903
+ requireAuth: true,
1904
+ requireAdmin: true
1905
+ },
1906
+ handler
1907
+ );
1908
+ return async (request, routeContext) => {
1909
+ const isProduction = isDev === false;
1910
+ if (isProduction && !allowInProduction) {
1911
+ const requestId = getRequestId(request);
1912
+ return Response.json(
1913
+ {
1914
+ error: "Debug endpoints are disabled in production",
1915
+ code: "DEBUG_DISABLED"
1916
+ },
1917
+ { status: 403, headers: { "X-Request-ID": requestId } }
1918
+ );
1919
+ }
1920
+ return inner(request, routeContext);
1921
+ };
1922
+ }
1846
1923
  function withLegacyAdminApi(config, handler) {
1847
1924
  return createSecureHandler(
1848
1925
  {
@@ -1855,11 +1932,91 @@ function createSecureHandlerFactory(factoryConfig) {
1855
1932
  handler
1856
1933
  );
1857
1934
  }
1935
+ function withAiApi(config, handler) {
1936
+ return createSecureHandler(
1937
+ {
1938
+ rateLimit: factoryConfig.rateLimiter?.aiDefault,
1939
+ ...config,
1940
+ requireAuth: true
1941
+ },
1942
+ handler
1943
+ );
1944
+ }
1945
+ function withCronApi(config, handler) {
1946
+ const { allowVercelCron = true, ...routeConfig } = config;
1947
+ return async (request, routeContext) => {
1948
+ const requestId = getRequestId(request);
1949
+ const operation = routeConfig.operation || `CRON ${new URL(request.url).pathname}`;
1950
+ const log = makeLogger(request, operation);
1951
+ const userAgent = request.headers.get("user-agent") || "";
1952
+ const isVercelCron = allowVercelCron && userAgent.toLowerCase().includes("vercel");
1953
+ const isAdminToken = checkLegacyToken(request);
1954
+ let isCronSecret = false;
1955
+ if (factoryConfig.cronSecret) {
1956
+ try {
1957
+ const contentType = request.headers.get("content-type");
1958
+ if (contentType?.includes("application/json")) {
1959
+ const body = await request.clone().json();
1960
+ if (typeof body.cronSecret === "string" && constantTimeEqual(body.cronSecret, factoryConfig.cronSecret)) {
1961
+ isCronSecret = true;
1962
+ }
1963
+ }
1964
+ } catch {
1965
+ }
1966
+ if (!isCronSecret) {
1967
+ const qs = new URL(request.url).searchParams.get("cronSecret") || "";
1968
+ if (qs && constantTimeEqual(qs, factoryConfig.cronSecret)) {
1969
+ isCronSecret = true;
1970
+ }
1971
+ }
1972
+ }
1973
+ if (!isVercelCron && !isAdminToken && !isCronSecret) {
1974
+ log.warn("Unauthorized cron access attempt");
1975
+ return Response.json(
1976
+ { error: "Unauthorized" },
1977
+ { status: 401, headers: { "X-Request-ID": requestId } }
1978
+ );
1979
+ }
1980
+ log.info("Cron job authorized", {
1981
+ method: isVercelCron ? "vercel_cron" : isAdminToken ? "admin_token" : "cron_secret"
1982
+ });
1983
+ const params = await routeContext.params;
1984
+ const ctx = {
1985
+ session: null,
1986
+ isLegacyToken: isAdminToken,
1987
+ authMethod: isAdminToken ? "legacy_token" : "none",
1988
+ isAdmin: true,
1989
+ // cron implicitly trusted
1990
+ validated: {},
1991
+ logger: log,
1992
+ requestId,
1993
+ params
1994
+ };
1995
+ try {
1996
+ const response = await handler(request, ctx);
1997
+ response.headers.set("X-Request-ID", requestId);
1998
+ return response;
1999
+ } catch (error) {
2000
+ log.error("Cron handler error", {
2001
+ error: error instanceof Error ? error.message : String(error)
2002
+ });
2003
+ const { status, body } = classify(error, isDev);
2004
+ return Response.json(
2005
+ { error: body.error, code: body.code },
2006
+ { status, headers: { "X-Request-ID": requestId } }
2007
+ );
2008
+ }
2009
+ };
2010
+ }
1858
2011
  return {
1859
2012
  createSecureHandler,
1860
2013
  withPublicApi,
1861
2014
  withAuthenticatedApi,
1862
2015
  withAdminApi,
2016
+ withRoleBasedApi,
2017
+ withDebugApi,
2018
+ withAiApi,
2019
+ withCronApi,
1863
2020
  withLegacyAdminApi
1864
2021
  };
1865
2022
  }
@@ -1941,6 +2098,293 @@ function computeClaimDelta(current, newEmail, newName) {
1941
2098
  return changed ? delta : null;
1942
2099
  }
1943
2100
 
2101
+ // src/auth/tokens.ts
2102
+ var import_node_crypto = __toESM(require("crypto"));
2103
+ var HMAC_HEX_CHARS = 16;
2104
+ function validateSecret(secret) {
2105
+ if (typeof secret !== "string" || secret.length < 16) {
2106
+ throw new Error(
2107
+ "signToken/verifyToken require a secret of at least 16 characters"
2108
+ );
2109
+ }
2110
+ }
2111
+ function computeHmac(secret, signedPart) {
2112
+ return import_node_crypto.default.createHmac("sha256", secret).update(signedPart).digest("hex").slice(0, HMAC_HEX_CHARS);
2113
+ }
2114
+ function signToken(opts) {
2115
+ validateSecret(opts.secret);
2116
+ if (typeof opts.payload !== "string" || opts.payload.length === 0) {
2117
+ throw new Error("signToken requires a non-empty payload string");
2118
+ }
2119
+ const signedPart = opts.ttlSeconds !== void 0 ? `${opts.payload}.${Math.floor(Date.now() / 1e3)}` : opts.payload;
2120
+ const encoded = Buffer.from(signedPart, "utf-8").toString("base64url");
2121
+ const hmac = computeHmac(opts.secret, signedPart);
2122
+ return `${encoded}.${hmac}`;
2123
+ }
2124
+ function verifyToken(token, opts) {
2125
+ validateSecret(opts.secret);
2126
+ if (typeof token !== "string" || token.length === 0) {
2127
+ return { valid: false, reason: "malformed" };
2128
+ }
2129
+ const lastDot = token.lastIndexOf(".");
2130
+ if (lastDot <= 0 || lastDot === token.length - 1) {
2131
+ return { valid: false, reason: "malformed" };
2132
+ }
2133
+ const encoded = token.slice(0, lastDot);
2134
+ const providedHmac = token.slice(lastDot + 1);
2135
+ let signedPart;
2136
+ try {
2137
+ signedPart = Buffer.from(encoded, "base64url").toString("utf-8");
2138
+ } catch {
2139
+ return { valid: false, reason: "malformed" };
2140
+ }
2141
+ if (signedPart.length === 0) {
2142
+ return { valid: false, reason: "malformed" };
2143
+ }
2144
+ const expectedHmac = computeHmac(opts.secret, signedPart);
2145
+ if (providedHmac.length !== expectedHmac.length || !import_node_crypto.default.timingSafeEqual(
2146
+ Buffer.from(providedHmac, "utf-8"),
2147
+ Buffer.from(expectedHmac, "utf-8")
2148
+ )) {
2149
+ return { valid: false, reason: "bad_signature" };
2150
+ }
2151
+ const tsDot = signedPart.lastIndexOf(".");
2152
+ let payload = signedPart;
2153
+ let issuedAt;
2154
+ if (tsDot > 0) {
2155
+ const tsCandidate = signedPart.slice(tsDot + 1);
2156
+ const tsNum = Number(tsCandidate);
2157
+ if (Number.isFinite(tsNum) && /^\d+$/.test(tsCandidate)) {
2158
+ payload = signedPart.slice(0, tsDot);
2159
+ issuedAt = tsNum;
2160
+ }
2161
+ }
2162
+ if (opts.maxAgeSeconds !== void 0 && issuedAt !== void 0) {
2163
+ const ageSeconds = Math.floor(Date.now() / 1e3) - issuedAt;
2164
+ if (ageSeconds > opts.maxAgeSeconds) {
2165
+ return { valid: false, reason: "expired" };
2166
+ }
2167
+ }
2168
+ return issuedAt !== void 0 ? { valid: true, payload, issuedAt } : { valid: true, payload };
2169
+ }
2170
+
2171
+ // src/auth/redirect.ts
2172
+ var DANGEROUS_PROTOCOLS = /* @__PURE__ */ new Set([
2173
+ "javascript:",
2174
+ "data:",
2175
+ "vbscript:",
2176
+ "file:"
2177
+ ]);
2178
+ function safeRedirect(candidate, opts) {
2179
+ if (typeof candidate !== "string" || candidate.length === 0) {
2180
+ return opts.fallback;
2181
+ }
2182
+ const trimmed = candidate.trim();
2183
+ if (trimmed.length === 0) {
2184
+ return opts.fallback;
2185
+ }
2186
+ if (trimmed.startsWith("//")) {
2187
+ return opts.fallback;
2188
+ }
2189
+ if (trimmed.startsWith("/")) {
2190
+ return trimmed;
2191
+ }
2192
+ let url;
2193
+ try {
2194
+ url = new URL(trimmed);
2195
+ } catch {
2196
+ return opts.fallback;
2197
+ }
2198
+ if (DANGEROUS_PROTOCOLS.has(url.protocol.toLowerCase())) {
2199
+ return opts.fallback;
2200
+ }
2201
+ const candidateOrigin = url.origin.toLowerCase();
2202
+ const allowed = opts.allowedOrigins.some(
2203
+ (o) => o.toLowerCase() === candidateOrigin
2204
+ );
2205
+ if (!allowed) {
2206
+ return opts.fallback;
2207
+ }
2208
+ return url.toString();
2209
+ }
2210
+
2211
+ // src/auth/honeypot.ts
2212
+ var DEFAULT_FIELD_NAME = "_hp";
2213
+ function isHoneypotFilled(body, fieldName = DEFAULT_FIELD_NAME) {
2214
+ if (body == null) return false;
2215
+ if (typeof FormData !== "undefined" && body instanceof FormData) {
2216
+ const value2 = body.get(fieldName);
2217
+ return typeof value2 === "string" && value2.trim().length > 0;
2218
+ }
2219
+ if (typeof body !== "object") return false;
2220
+ const value = body[fieldName];
2221
+ return typeof value === "string" && value.trim().length > 0;
2222
+ }
2223
+
2224
+ // src/auth/health-route.ts
2225
+ var DEFAULT_TIMEOUT_MS = 2e3;
2226
+ async function withTimeoutOrError(probe, timeoutMs) {
2227
+ try {
2228
+ const result = await Promise.race([
2229
+ probe(),
2230
+ new Promise(
2231
+ (_, reject) => setTimeout(() => reject(new Error("probe timed out")), timeoutMs)
2232
+ )
2233
+ ]);
2234
+ return result;
2235
+ } catch {
2236
+ return { status: "error" };
2237
+ }
2238
+ }
2239
+ function createHealthRoute(opts) {
2240
+ const names = Object.keys(opts.checks);
2241
+ return async function GET() {
2242
+ const probeResults = await Promise.all(
2243
+ names.map(async (name) => {
2244
+ const check = opts.checks[name];
2245
+ const result = await withTimeoutOrError(
2246
+ check.probe,
2247
+ check.timeoutMs ?? DEFAULT_TIMEOUT_MS
2248
+ );
2249
+ return [name, result];
2250
+ })
2251
+ );
2252
+ const services = {};
2253
+ let degraded = false;
2254
+ for (const [name, result] of probeResults) {
2255
+ services[name] = result;
2256
+ const check = opts.checks[name];
2257
+ if (check.gating && result.status === "error") {
2258
+ degraded = true;
2259
+ }
2260
+ }
2261
+ const body = {
2262
+ status: degraded ? "degraded" : "healthy",
2263
+ services
2264
+ };
2265
+ if (opts.extraBody) {
2266
+ try {
2267
+ const extra = await opts.extraBody();
2268
+ Object.assign(body, extra);
2269
+ } catch {
2270
+ }
2271
+ }
2272
+ return new Response(JSON.stringify(body), {
2273
+ status: degraded ? 503 : 200,
2274
+ headers: { "content-type": "application/json" }
2275
+ });
2276
+ };
2277
+ }
2278
+
2279
+ // src/interfaces/ILogger.ts
2280
+ var NoopLogger = class {
2281
+ debug() {
2282
+ }
2283
+ info() {
2284
+ }
2285
+ warn() {
2286
+ }
2287
+ error() {
2288
+ }
2289
+ child() {
2290
+ return this;
2291
+ }
2292
+ };
2293
+
2294
+ // src/auth/cache-helpers.ts
2295
+ var CacheTTL = {
2296
+ /** 5 minutes — query results, dropdown options. */
2297
+ SHORT: 300,
2298
+ /** 1 hour — semi-static reference data, per-user state. */
2299
+ MEDIUM: 3600,
2300
+ /** 6 hours — heavy aggregates, derived state. */
2301
+ LONG: 21600,
2302
+ /** 24 hours — positive AI cache, immutable enrichments. */
2303
+ DAY: 86400,
2304
+ /** 7 days — long-term derived data, hashed content. */
2305
+ WEEK: 604800
2306
+ };
2307
+ function createAppCache(cache, options = {}) {
2308
+ const logger = options.logger ?? new NoopLogger();
2309
+ return {
2310
+ async get(key) {
2311
+ try {
2312
+ return await cache.get(key);
2313
+ } catch (err) {
2314
+ logger.debug("cache.get failed", { key, err: String(err) });
2315
+ return null;
2316
+ }
2317
+ },
2318
+ async set(key, value, ttlSeconds) {
2319
+ try {
2320
+ await cache.set(key, value, ttlSeconds);
2321
+ } catch (err) {
2322
+ logger.debug("cache.set failed", { key, err: String(err) });
2323
+ }
2324
+ },
2325
+ async delete(key) {
2326
+ try {
2327
+ await cache.delete(key);
2328
+ } catch (err) {
2329
+ logger.debug("cache.delete failed", { key, err: String(err) });
2330
+ }
2331
+ },
2332
+ async exists(key) {
2333
+ try {
2334
+ return await cache.exists(key);
2335
+ } catch {
2336
+ return false;
2337
+ }
2338
+ },
2339
+ async getCachedOrFetch(key, fetchFn, ttlSeconds) {
2340
+ try {
2341
+ const cached = await cache.get(key);
2342
+ if (cached !== null) return cached;
2343
+ } catch (err) {
2344
+ logger.debug("getCachedOrFetch read failed; falling through", {
2345
+ key,
2346
+ err: String(err)
2347
+ });
2348
+ }
2349
+ const fresh = await fetchFn();
2350
+ try {
2351
+ await cache.set(key, fresh, ttlSeconds);
2352
+ } catch (err) {
2353
+ logger.debug("getCachedOrFetch write-back failed", {
2354
+ key,
2355
+ err: String(err)
2356
+ });
2357
+ }
2358
+ return fresh;
2359
+ },
2360
+ async invalidate(keys) {
2361
+ const list = Array.isArray(keys) ? keys : [keys];
2362
+ let total = 0;
2363
+ for (const key of list) {
2364
+ try {
2365
+ if (key.includes("*")) {
2366
+ total += await cache.deletePattern(key);
2367
+ } else {
2368
+ await cache.delete(key);
2369
+ total += 1;
2370
+ }
2371
+ } catch (err) {
2372
+ logger.debug("invalidate failed for key", { key, err: String(err) });
2373
+ }
2374
+ }
2375
+ return total;
2376
+ },
2377
+ async warm(key, fetchFn, ttlSeconds) {
2378
+ try {
2379
+ const value = await fetchFn();
2380
+ await cache.set(key, value, ttlSeconds);
2381
+ } catch (err) {
2382
+ logger.debug("warm failed", { key, err: String(err) });
2383
+ }
2384
+ }
2385
+ };
2386
+ }
2387
+
1944
2388
  // src/env.ts
1945
2389
  function getRequiredEnv(key) {
1946
2390
  const value = process.env[key];
@@ -2035,6 +2479,7 @@ function getEnvSummary(keys) {
2035
2479
  0 && (module.exports = {
2036
2480
  ApiError,
2037
2481
  ApiErrorCode,
2482
+ CacheTTL,
2038
2483
  CommonApiErrors,
2039
2484
  CommonRateLimits,
2040
2485
  DateRangeSchema,
@@ -2069,11 +2514,13 @@ function getEnvSummary(keys) {
2069
2514
  constantTimeEqual,
2070
2515
  containsHtml,
2071
2516
  containsUrls,
2517
+ createAppCache,
2072
2518
  createAuditActor,
2073
2519
  createAuditLogger,
2074
2520
  createBetaClient,
2075
2521
  createEnsureUser,
2076
2522
  createFeatureFlags,
2523
+ createHealthRoute,
2077
2524
  createLazyRateLimitStore,
2078
2525
  createMemoryRateLimitStore,
2079
2526
  createRedisRateLimitStore,
@@ -2105,6 +2552,7 @@ function getEnvSummary(keys) {
2105
2552
  hasRole,
2106
2553
  isAllowlisted,
2107
2554
  isApiError,
2555
+ isHoneypotFilled,
2108
2556
  isTokenExpired,
2109
2557
  isValidBearerToken,
2110
2558
  parseKeycloakRoles,
@@ -2113,8 +2561,10 @@ function getEnvSummary(keys) {
2113
2561
  resetRateLimitForKey,
2114
2562
  resolveIdentifier,
2115
2563
  resolveRateLimitIdentifier,
2564
+ safeRedirect,
2116
2565
  safeValidate,
2117
2566
  sanitizeApiError,
2567
+ signToken,
2118
2568
  storeBetaCode,
2119
2569
  stripHtml,
2120
2570
  stripNullBytes,
@@ -2122,6 +2572,7 @@ function getEnvSummary(keys) {
2122
2572
  validateBetaCode,
2123
2573
  validateEnvVars,
2124
2574
  verifyCronAuth,
2575
+ verifyToken,
2125
2576
  zodErrorResponse
2126
2577
  });
2127
2578
  //# sourceMappingURL=auth.js.map