@getstrata/bootstrap 2.2.60 → 3.0.5

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 (90) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/bootstrap/app.d.ts +18 -7
  3. package/dist/bootstrap/buildModuleRoutes.d.ts +3 -5
  4. package/dist/bootstrap/buildWebModuleRoutes.d.ts +2 -3
  5. package/dist/bootstrap/cache/modelCacheTags.d.ts +3 -2
  6. package/dist/bootstrap/cachedJson.d.ts +7 -2
  7. package/dist/bootstrap/config.d.ts +1 -1
  8. package/dist/bootstrap/context.d.ts +25 -7
  9. package/dist/bootstrap/contracts.d.ts +1 -0
  10. package/dist/bootstrap/createWebRoutes.d.ts +2 -1
  11. package/dist/bootstrap/databaseReadiness.d.ts +3 -0
  12. package/dist/bootstrap/dependencies.d.ts +3 -2
  13. package/dist/bootstrap/discoverJobs.d.ts +3 -2
  14. package/dist/bootstrap/discoverListeners.d.ts +10 -7
  15. package/dist/bootstrap/discoverModels.d.ts +3 -2
  16. package/dist/bootstrap/discoverModules.d.ts +7 -6
  17. package/dist/bootstrap/health.d.ts +3 -2
  18. package/dist/bootstrap/http/securedRouteModelBinding.d.ts +1 -1
  19. package/dist/bootstrap/httpKernel.d.ts +43 -22
  20. package/dist/bootstrap/httpPersistence.d.ts +4 -0
  21. package/dist/bootstrap/inProcessCron.d.ts +5 -5
  22. package/dist/bootstrap/listeners/invalidateCacheOnModelWrite.d.ts +13 -12
  23. package/dist/bootstrap/metricsRoutes.d.ts +6 -1
  24. package/dist/bootstrap/moduleRouteMiddleware.d.ts +4 -4
  25. package/dist/bootstrap/modules.d.ts +1 -1
  26. package/dist/bootstrap/ownedHttpRoute.d.ts +23 -0
  27. package/dist/bootstrap/persistenceContracts.d.ts +70 -0
  28. package/dist/bootstrap/persistenceInvocation.d.ts +4 -0
  29. package/dist/bootstrap/providers/auth.d.ts +21 -0
  30. package/dist/bootstrap/providers/cache.d.ts +9 -3
  31. package/dist/bootstrap/providers/cacheProvider.d.ts +3 -0
  32. package/dist/bootstrap/providers/config.d.ts +6 -3
  33. package/dist/bootstrap/providers/events.d.ts +5 -2
  34. package/dist/bootstrap/providers/index.d.ts +3 -2
  35. package/dist/bootstrap/providers/listeners.d.ts +3 -3
  36. package/dist/bootstrap/providers/mail.d.ts +15 -0
  37. package/dist/bootstrap/providers/queue.d.ts +3 -2
  38. package/dist/bootstrap/providers/storage.d.ts +11 -2
  39. package/dist/bootstrap/providers/tracing.d.ts +4 -2
  40. package/dist/bootstrap/providers/view.d.ts +8 -5
  41. package/dist/bootstrap/public-api.d.ts +10 -7
  42. package/dist/bootstrap/queue/defaultJobs.d.ts +4 -2
  43. package/dist/bootstrap/rateLimit.d.ts +13 -3
  44. package/dist/bootstrap/routeCompiler.d.ts +20 -0
  45. package/dist/bootstrap/routeMetadata.d.ts +3 -3
  46. package/dist/bootstrap/routePlan.d.ts +11 -0
  47. package/dist/bootstrap/schedule.d.ts +11 -2
  48. package/dist/bootstrap/secretsGuard.d.ts +2 -3
  49. package/dist/bootstrap/web/routing.d.ts +6 -3
  50. package/dist/bootstrap/web/server.d.ts +14 -4
  51. package/dist/bootstrap/web/session.d.ts +23 -16
  52. package/dist/entries/buildModuleRoutes.js +602 -384
  53. package/dist/entries/buildWebModuleRoutes.js +596 -347
  54. package/dist/entries/cache/modelCacheTags.js +8 -186
  55. package/dist/entries/cachedJson.js +22 -0
  56. package/dist/entries/config.js +1 -3
  57. package/dist/entries/context.js +665 -700
  58. package/dist/entries/createSpaRoutes.js +194 -5
  59. package/dist/entries/createWebRoutes.js +618 -367
  60. package/dist/entries/databaseReadiness.js +267 -0
  61. package/dist/entries/dependencies.js +666 -701
  62. package/dist/entries/discoverJobs.js +18 -16
  63. package/dist/entries/discoverListeners.js +27 -38
  64. package/dist/entries/discoverModels.js +4 -3
  65. package/dist/entries/discoverModules.js +29 -67
  66. package/dist/entries/health.js +14 -34
  67. package/dist/entries/httpKernel.js +405 -89
  68. package/dist/entries/listeners/invalidateCacheOnModelWrite.js +43 -289
  69. package/dist/entries/metricsRoutes.js +9 -5
  70. package/dist/entries/persistenceContracts.js +1 -0
  71. package/dist/entries/persistenceInvocation.js +17 -0
  72. package/dist/entries/providers/auth.js +114 -0
  73. package/dist/entries/providers/cache.js +35 -0
  74. package/dist/entries/providers/events.js +55 -0
  75. package/dist/entries/providers/view.js +34 -44
  76. package/dist/entries/providers.js +392 -561
  77. package/dist/entries/queue/defaultJobs.js +9 -6
  78. package/dist/entries/routePlan.js +200 -0
  79. package/dist/entries/schedule.js +37 -37
  80. package/dist/entries/secretsGuard.js +10 -13
  81. package/dist/entries/web/routing.js +412 -96
  82. package/dist/entries/web/server.js +461 -29
  83. package/dist/entries/web/session.js +61 -73
  84. package/dist/index.js +1520 -1085
  85. package/dist/internal/ownedHttpRoute.js +66 -0
  86. package/package.json +52 -15
  87. package/dist/bootstrap/applicationRegistry.d.ts +0 -1
  88. package/dist/bootstrap/routeRegistry.d.ts +0 -10
  89. package/dist/entries/applicationRegistry.js +0 -24
  90. package/dist/entries/routeRegistry.js +0 -29
@@ -2,14 +2,17 @@
2
2
  // ../../src/bootstrap/queue/defaultJobs.ts
3
3
  import { ExportAuditLogsJob } from "@getstrata/core/jobs/exportAuditLogsJob";
4
4
  import { InvalidateCacheTagsJob } from "@getstrata/core/jobs/invalidateCacheTagsJob";
5
- import { jobRegistry } from "@getstrata/core/queue/jobRegistry";
6
- import { resolveApplicationCache } from "@getstrata/core/runtime/applicationRegistry";
7
- function registerDefaultJobs() {
8
- jobRegistry.register("cache.invalidate-tags", () => {
9
- return new InvalidateCacheTagsJob(resolveApplicationCache());
5
+ var SYSTEM_JOB_NAMES = Object.freeze([
6
+ InvalidateCacheTagsJob.jobName,
7
+ ExportAuditLogsJob.jobName
8
+ ]);
9
+ function registerDefaultJobs(registry) {
10
+ registry.register(InvalidateCacheTagsJob.jobName, () => {
11
+ return new InvalidateCacheTagsJob;
10
12
  });
11
- jobRegistry.register("audit.export", () => new ExportAuditLogsJob);
13
+ registry.register(ExportAuditLogsJob.jobName, () => new ExportAuditLogsJob);
12
14
  }
13
15
  export {
16
+ SYSTEM_JOB_NAMES,
14
17
  registerDefaultJobs
15
18
  };
@@ -0,0 +1,200 @@
1
+ // @bun
2
+ // ../../src/bootstrap/routeCompiler.ts
3
+ var ROUTE_METHODS = ["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
4
+ var OPENAPI_METHODS = new Set([...ROUTE_METHODS, "TRACE"]);
5
+ var inventoryKey = Symbol.for("@getstrata/owned-route-inventory");
6
+ function readRouteInventory(routes) {
7
+ return Object.getOwnPropertyDescriptor(routes, inventoryKey)?.value;
8
+ }
9
+ function immutableCopy(value, ancestors = new Set) {
10
+ if (value === null || typeof value !== "object") {
11
+ if (typeof value === "function" || typeof value === "symbol" || typeof value === "bigint" || typeof value === "number" && !Number.isFinite(value)) {
12
+ throw new Error("Route metadata must contain only JSON values");
13
+ }
14
+ return value;
15
+ }
16
+ if (ancestors.has(value))
17
+ throw new Error("Route metadata must not contain cycles");
18
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
19
+ throw new Error("Route metadata must contain only JSON objects");
20
+ }
21
+ ancestors.add(value);
22
+ const copy = Array.isArray(value) ? value.map((entry) => immutableCopy(entry, ancestors)) : Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, immutableCopy(entry, ancestors)]));
23
+ ancestors.delete(value);
24
+ return Object.freeze(copy);
25
+ }
26
+ function normalizeRoutePath(path, prefix = "") {
27
+ const normalizedPrefix = prefix.replace(/\/+$/, "");
28
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
29
+ const result = `${normalizedPrefix ? normalizedPrefix.startsWith("/") ? normalizedPrefix : `/${normalizedPrefix}` : ""}${normalizedPath}`;
30
+ if (!path || /[?#\s]/.test(result) || result.includes("//") || result.split("/").some((part) => part === "." || part === "..")) {
31
+ throw new Error(`Invalid route path: ${path}`);
32
+ }
33
+ return result;
34
+ }
35
+ function routeMethods(handler) {
36
+ if (handler === false)
37
+ return { methods: [], handler };
38
+ if (handler instanceof Response)
39
+ return {
40
+ methods: [...ROUTE_METHODS],
41
+ handler: Object.freeze(Object.fromEntries(ROUTE_METHODS.map((method) => [method, handler])))
42
+ };
43
+ if (typeof handler === "function")
44
+ return { methods: ["*"], handler };
45
+ if (handler && typeof handler === "object" && !Array.isArray(handler)) {
46
+ const entries = Object.entries(handler);
47
+ if (entries.some(([method, value]) => OPENAPI_METHODS.has(method.toUpperCase()) || typeof value === "function" || value instanceof Response)) {
48
+ const methods = {};
49
+ for (const [rawMethod, value] of entries) {
50
+ const method = rawMethod.toUpperCase();
51
+ if (!ROUTE_METHODS.includes(method)) {
52
+ throw new Error(`Unsupported route method: ${rawMethod}`);
53
+ }
54
+ if (Object.hasOwn(methods, method))
55
+ throw new Error(`Duplicate route method: ${method}`);
56
+ if (typeof value !== "function" && !(value instanceof Response)) {
57
+ throw new Error(`Invalid route handler: ${method}`);
58
+ }
59
+ methods[method] = value;
60
+ }
61
+ return { methods: Object.keys(methods), handler: Object.freeze(methods) };
62
+ }
63
+ if (Object.prototype.toString.call(handler) === "[object HTMLBundle]") {
64
+ return { methods: ["GET", "HEAD"], handler };
65
+ }
66
+ if (handler instanceof Blob && "exists" in handler && typeof handler.exists === "function") {
67
+ return { methods: ["*"], handler };
68
+ }
69
+ if (Object.getPrototypeOf(handler) === Object.prototype && "dir" in handler && typeof handler.dir === "string" && handler.dir.length > 0 && entries.every(([key, value]) => key === "dir" || key === "statCache" && typeof value === "boolean")) {
70
+ return { methods: ["*"], handler: Object.freeze({ ...handler }) };
71
+ }
72
+ throw new Error("Invalid route method map or native route declaration");
73
+ }
74
+ throw new Error("Invalid route handler");
75
+ }
76
+ function compileRoutePlan(sources, prefix = "") {
77
+ const routes = Object.create(null);
78
+ const owners = new Map;
79
+ const inventory = [];
80
+ const canonicalPaths = new Map;
81
+ const implicitHeads = new Map;
82
+ for (const source of sources) {
83
+ for (const path of Object.keys(source.metadata ?? {})) {
84
+ if (!Object.hasOwn(source.routes, path)) {
85
+ throw new Error(`OpenAPI metadata has no API route: ${source.name} ${path}`);
86
+ }
87
+ }
88
+ for (const [rawPath, rawHandler] of Object.entries(source.routes)) {
89
+ const path = normalizeRoutePath(rawPath, prefix);
90
+ const { methods, handler } = routeMethods(rawHandler);
91
+ if (handler && typeof handler === "object" && "dir" in handler && !path.endsWith("/*")) {
92
+ throw new Error(`Directory route must end in /*: ${path}`);
93
+ }
94
+ const collisionPath = path.replace(/:[^/]+/g, ":parameter");
95
+ const canonicalPath = canonicalPaths.get(collisionPath);
96
+ if (canonicalPath && canonicalPath !== path) {
97
+ throw new Error(`Ambiguous route parameter names: ${canonicalPath} and ${path}`);
98
+ }
99
+ canonicalPaths.set(collisionPath, path);
100
+ const previous = owners.get(collisionPath) ?? new Map;
101
+ for (const method of methods) {
102
+ if (previous.has(method) || previous.has("*") || method === "*" && previous.size) {
103
+ throw new Error(`Duplicate route: ${method} ${path} (${[...previous.values()][0]} and ${source.name})`);
104
+ }
105
+ }
106
+ const metadata = source.metadata?.[rawPath];
107
+ for (const method of Object.keys(metadata ?? {})) {
108
+ if (!OPENAPI_METHODS.has(method) || !methods.includes("*") && !methods.includes(method) && !(method === "HEAD" && methods.includes("GET"))) {
109
+ throw new Error(`OpenAPI metadata has no API handler: ${method} ${rawPath}`);
110
+ }
111
+ }
112
+ const inherited = readRouteInventory(source.routes)?.filter((entry) => entry.path === rawPath);
113
+ if (inherited) {
114
+ inventory.push(...inherited.filter((entry) => entry.method !== "HEAD" || !methods.includes("GET") || methods.includes("HEAD")).map((entry) => ({ ...entry, path })));
115
+ } else {
116
+ for (const method of methods) {
117
+ const openApi = metadata?.[method];
118
+ inventory.push({
119
+ method,
120
+ path,
121
+ middleware: source.middleware ?? [],
122
+ ...openApi ? { openApi } : {}
123
+ });
124
+ }
125
+ if (methods.includes("*")) {
126
+ for (const [method, openApi] of Object.entries(metadata ?? {})) {
127
+ inventory.push({
128
+ method,
129
+ path,
130
+ middleware: source.middleware ?? [],
131
+ ...openApi ? { openApi } : {}
132
+ });
133
+ }
134
+ }
135
+ }
136
+ if (methods.includes("GET") && !methods.includes("HEAD")) {
137
+ const openApi = metadata?.HEAD ?? inherited?.find((entry) => entry.method === "HEAD")?.openApi;
138
+ implicitHeads.set(path, {
139
+ method: "HEAD",
140
+ path,
141
+ middleware: inherited?.find((entry) => entry.method === "GET")?.middleware ?? source.middleware ?? [],
142
+ ...openApi ? { openApi } : {}
143
+ });
144
+ }
145
+ for (const method of methods)
146
+ previous.set(method, source.name);
147
+ owners.set(collisionPath, previous);
148
+ if (Object.hasOwn(routes, path)) {
149
+ if (routes[path] === false || handler === false || Object.prototype.toString.call(routes[path]) === "[object HTMLBundle]" || Object.prototype.toString.call(handler) === "[object HTMLBundle]") {
150
+ throw new Error(`Cannot merge native bundle route: ${path}`);
151
+ }
152
+ routes[path] = Object.freeze({ ...routes[path], ...handler });
153
+ } else {
154
+ routes[path] = handler;
155
+ }
156
+ }
157
+ }
158
+ for (const [path, head] of implicitHeads) {
159
+ if (!inventory.some((entry) => entry.path === path && entry.method === "HEAD"))
160
+ inventory.push(head);
161
+ }
162
+ const snapshot = immutableCopy(inventory.sort((left, right) => left.path.localeCompare(right.path)));
163
+ return Object.freeze({ routes: attachRouteInventory(routes, snapshot), inventory: snapshot });
164
+ }
165
+ function attachRouteInventory(routes, inventory) {
166
+ for (const value of Object.values(routes)) {
167
+ if (value && typeof value === "object" && !(value instanceof Response) && Object.keys(value).some((method) => ROUTE_METHODS.includes(method))) {
168
+ Object.freeze(value);
169
+ }
170
+ }
171
+ Object.defineProperty(routes, inventoryKey, { value: inventory, enumerable: false });
172
+ return Object.freeze(routes);
173
+ }
174
+ function getRouteInventory(routes) {
175
+ const inventory = readRouteInventory(routes);
176
+ if (!inventory)
177
+ throw new Error("Route map has not been compiled");
178
+ return inventory;
179
+ }
180
+
181
+ // ../../src/bootstrap/routePlan.ts
182
+ function compileRouteMap(routes, options = {}) {
183
+ if (options.middleware !== undefined || options.metadata !== undefined) {
184
+ try {
185
+ getRouteInventory(routes);
186
+ } catch {
187
+ return compileRoutePlan([{ name: "routes", routes, ...options }]).routes;
188
+ }
189
+ throw new Error("Cannot replace contracts or middleware on an already compiled route map");
190
+ }
191
+ return compileRoutePlan([{ name: "routes", routes }]).routes;
192
+ }
193
+ function composeRouteMaps(...maps) {
194
+ return compileRoutePlan(maps.map((routes, index) => ({ name: `routes ${index + 1}`, routes }))).routes;
195
+ }
196
+ export {
197
+ compileRouteMap,
198
+ composeRouteMaps,
199
+ getRouteInventory
200
+ };
@@ -2,44 +2,44 @@
2
2
  // ../../src/bootstrap/schedule.ts
3
3
  import { ExportAuditLogsJob } from "@getstrata/core/jobs/exportAuditLogsJob";
4
4
  import { appLogger } from "@getstrata/core/logging/logger";
5
- import { appSchedule } from "@getstrata/core/scheduler/schedule";
6
-
7
- // ../../src/config/features.ts
8
- function readFeatureFlags() {
9
- return {
10
- webhooks: (process.env.FEATURE_WEBHOOKS ?? "true") !== "false",
11
- fullTextSearch: (process.env.FEATURE_SEARCH ?? "true") !== "false",
12
- auditLog: (process.env.FEATURE_AUDIT_LOG ?? "true") !== "false",
13
- oauthLogin: (process.env.FEATURE_OAUTH ?? "true") !== "false",
14
- samlLogin: (process.env.FEATURE_SAML ?? "false") === "true",
15
- scim: (process.env.FEATURE_SCIM ?? "true") !== "false",
16
- billing: (process.env.FEATURE_BILLING ?? "true") !== "false",
17
- siemExport: (process.env.FEATURE_SIEM_EXPORT ?? "false") === "true",
18
- publicReads: (process.env.FEATURE_PUBLIC_READS ?? "false") === "true",
19
- emailVerification: (process.env.FEATURE_EMAIL_VERIFICATION ?? "false") === "true",
20
- mfa: (process.env.FEATURE_MFA ?? "false") === "true",
21
- registration: (process.env.FEATURE_REGISTRATION ?? "true") !== "false"
22
- };
5
+ import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
6
+ import { appKeyPrefix } from "@getstrata/core/runtime/appKeyPrefix";
7
+ import { Schedule } from "@getstrata/core/scheduler/schedule";
8
+ function createAppSchedule(options) {
9
+ const enabled = options.environment.FEATURE_SIEM_EXPORT === "true";
10
+ const schedule = new Schedule;
11
+ const owned = (name, work) => async (context) => options.invoke({
12
+ kind: "job",
13
+ externalId: context.occurrenceId,
14
+ signal: context.signal,
15
+ actor: { kind: "system", policy: "scheduler.task" },
16
+ metadata: { taskName: name }
17
+ }, work);
18
+ schedule.command("* * * * *", "heartbeat", owned("heartbeat", () => {
19
+ appLogger.debug("Scheduler heartbeat");
20
+ }));
21
+ schedule.command("* * * * *", "audit-export", owned("audit-export", async () => {
22
+ if (!enabled)
23
+ return;
24
+ try {
25
+ await new ExportAuditLogsJob(options.auditExport).handle({});
26
+ } catch (error) {
27
+ appLogger.error("Audit export failed.", { error: String(error) });
28
+ }
29
+ }));
30
+ return schedule;
23
31
  }
24
- var featureFlags = readFeatureFlags();
25
- function isFeatureEnabled(feature) {
26
- return readFeatureFlags()[feature];
32
+ function createScheduleRunOptions(environment) {
33
+ const coordination = environment.SCHEDULER_COORDINATION ?? (isProductionEnv(environment) ? "redis" : "single-runner");
34
+ if (coordination !== "redis" && coordination !== "single-runner")
35
+ throw new TypeError("Unsupported scheduler coordination.");
36
+ return Object.freeze({
37
+ coordination,
38
+ redisUrl: environment.REDIS_URL?.trim() ?? "",
39
+ namespace: appKeyPrefix(environment) + ":schedule"
40
+ });
27
41
  }
28
-
29
- // ../../src/bootstrap/schedule.ts
30
- appSchedule.command("* * * * *", "heartbeat", () => {
31
- appLogger.debug("Scheduler heartbeat");
32
- });
33
- appSchedule.command("* * * * *", "audit-export", async () => {
34
- if (!isFeatureEnabled("siemExport")) {
35
- return;
36
- }
37
- try {
38
- await new ExportAuditLogsJob().handle({});
39
- } catch (error) {
40
- appLogger.error("Audit export failed.", { error: String(error) });
41
- }
42
- });
43
42
  export {
44
- appSchedule
43
+ createAppSchedule,
44
+ createScheduleRunOptions
45
45
  };
@@ -1,12 +1,10 @@
1
1
  // @bun
2
2
  // ../../src/bootstrap/secretsGuard.ts
3
3
  import { resolveFieldEncryptionKeyring } from "@getstrata/core/crypto/fieldEncryption";
4
- import { getDefaultDatabasePool } from "@getstrata/core/database/defaultConnection";
5
4
  import { envFlagEnabled, isProductionEnv } from "@getstrata/core/runtime/appEnv";
6
5
  import { isViewsMode, parseFrontendMode } from "@getstrata/core/runtime/frontendMode";
7
6
  import {
8
7
  assertPostgresRoleCannotBypassRls,
9
- inspectCurrentPostgresRole,
10
8
  isPostgresUrl,
11
9
  postgresUrlUsername
12
10
  } from "@getstrata/core/tenant/enableTenantRls";
@@ -23,6 +21,7 @@ var PUBLISHED_TEST_SCIM_TOKENS = new Set([PUBLISHED_TEST_SCIM_BEARER_TOKEN]);
23
21
  var PLACEHOLDER_SECRET_PATTERN = /change-me/i;
24
22
  var SECRETS_TO_ROTATE = [
25
23
  "SESSION_SECRET",
24
+ "SIGNED_URL_SECRET",
26
25
  "TOKEN_HASH_PEPPER",
27
26
  "METRICS_TOKEN",
28
27
  "SCIM_BEARER_TOKEN",
@@ -135,10 +134,6 @@ function assertFeatureProductionSecrets(env) {
135
134
  }
136
135
  }
137
136
  var LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1", "[::1]"]);
138
- var livePostgresRoleInspector = null;
139
- function setLivePostgresRoleInspectorForTests(inspect) {
140
- livePostgresRoleInspector = inspect;
141
- }
142
137
  function rlsRuntimeDatabaseUrl(env) {
143
138
  const app = env.APP_DATABASE_URL?.trim();
144
139
  if (app) {
@@ -169,10 +164,7 @@ function assertRlsUsesAppDatabaseRole(env) {
169
164
  throw new Error(`TENANCY_DRIVER=rls startup blocked: ${runtime.name} for TENANCY_DRIVER=rls must use a NOBYPASSRLS role, not ${user}. FORCE RLS does not apply to PostgreSQL superusers.`);
170
165
  }
171
166
  }
172
- async function defaultInspectLivePostgresRole() {
173
- return await inspectCurrentPostgresRole(getDefaultDatabasePool());
174
- }
175
- async function assertRlsLiveDatabaseRole(env = process.env, inspect) {
167
+ async function assertRlsLiveDatabaseRole(env, inspect) {
176
168
  if (!isRlsTenancy(env)) {
177
169
  return;
178
170
  }
@@ -184,7 +176,13 @@ async function assertRlsLiveDatabaseRole(env = process.env, inspect) {
184
176
  assertRlsUsesAppDatabaseRole(env);
185
177
  let role;
186
178
  try {
187
- role = await (inspect ?? livePostgresRoleInspector ?? defaultInspectLivePostgresRole)();
179
+ const inspected = await inspect();
180
+ if (!inspected)
181
+ throw new TypeError("Missing live PostgreSQL role.");
182
+ const { rolname, rolsuper, rolbypassrls } = inspected;
183
+ if (typeof rolname !== "string" || !rolname.trim() || typeof rolsuper !== "boolean" || typeof rolbypassrls !== "boolean")
184
+ throw new TypeError("Malformed live PostgreSQL role.");
185
+ role = { rolname, rolsuper, rolbypassrls };
188
186
  } catch {
189
187
  throw new Error(`TENANCY_DRIVER=rls startup blocked: could not inspect the live Postgres role for ${source}.`);
190
188
  }
@@ -227,6 +225,5 @@ function assertProductionSecrets(env = process.env) {
227
225
  }
228
226
  export {
229
227
  assertProductionSecrets,
230
- assertRlsLiveDatabaseRole,
231
- setLivePostgresRoleInspectorForTests
228
+ assertRlsLiveDatabaseRole
232
229
  };