hazo_auth 10.32.0 → 10.32.2

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.
@@ -1,6 +1,7 @@
1
1
  // file_description: standalone helper to return a 403 FORBIDDEN response and fire the permission-denied handler
2
2
  import 'server-only';
3
3
 
4
+ import { optional_import } from 'hazo_core';
4
5
  import {
5
6
  buildDenialPayloadFromRequest,
6
7
  buildForbiddenResponse,
@@ -86,13 +87,15 @@ export function denyPermission(input: DenyPermissionInput): Response {
86
87
  // Kick off async hazo_api enhancement but return the sync response immediately.
87
88
  // The returned Response object is the sync fallback; hazo_api is decorative for
88
89
  // middleware use cases that don't need the exact envelope.
89
- void import('hazo_api')
90
- .then((m: any) => {
91
- if (typeof m?.fail === 'function') {
92
- // No-op: we already returned — this is a fire-and-forget; nothing to do with the result.
93
- }
94
- })
95
- .catch(() => undefined);
90
+ // optional_import (not a literal `import('hazo_api')`) — hazo_api is an
91
+ // optional peer; a literal dynamic import of an uninstalled package name
92
+ // fails Next.js/Turbopack's build-time static resolution even though the
93
+ // `.catch()` would have handled it fine at runtime.
94
+ void optional_import<{ fail?: (...args: unknown[]) => Response }>('hazo_api').then((m) => {
95
+ if (typeof m?.fail === 'function') {
96
+ // No-op: we already returned — this is a fire-and-forget; nothing to do with the result.
97
+ }
98
+ });
96
99
 
97
100
  return new Response(bodyJson, {
98
101
  status: 403,
@@ -4,7 +4,7 @@ import 'server-only';
4
4
 
5
5
  // section: imports
6
6
  import { type NextRequest } from 'next/server';
7
- import { createLogger } from 'hazo_core';
7
+ import { createLogger, optional_import } from 'hazo_core';
8
8
  import { PermissionError } from './auth_types.js';
9
9
  import { hazo_get_auth } from './hazo_get_auth.server.js';
10
10
 
@@ -106,13 +106,15 @@ export function buildDenialPayloadFromRequest(
106
106
 
107
107
  /** Builds the 403 Response, using hazo_api.fail() if available, otherwise hand-built. */
108
108
  export async function buildForbiddenResponse(payload: PermissionDeniedPayload): Promise<Response> {
109
- const apiMod = (await import('hazo_api').catch(() => null)) as {
109
+ // optional_import, not a literal `import('hazo_api')` — see deny_permission.server.ts
110
+ // for why a literal dynamic import of this optional peer breaks Turbopack builds.
111
+ const apiMod = await optional_import<{
110
112
  fail?: (
111
113
  code: string,
112
114
  message: string,
113
115
  opts?: { details?: unknown; status?: number },
114
116
  ) => Response;
115
- } | null;
117
+ }>('hazo_api');
116
118
 
117
119
  if (apiMod?.fail) {
118
120
  return apiMod.fail('FORBIDDEN', payload.user_friendly_message, {
@@ -14,8 +14,36 @@ import { initializeAdminService, getSqliteAdminService } from "hazo_connect/serv
14
14
  import { create_app_logger } from "./app_logger.js";
15
15
 
16
16
  // section: singleton_state
17
- let hazoConnectInstance: HazoConnectAdapter | null = null;
18
- let isInitialized = false;
17
+ /**
18
+ * Backed by globalThis (keyed by a well-known Symbol.for), not plain
19
+ * module-level variables. A consuming Next.js app typically calls
20
+ * set_hazo_connect_instance() once from instrumentation.ts (to inject its own
21
+ * Postgres-backed hazo_connect adapter, bypassing this package's INI-based
22
+ * sqlite/postgrest config) and get_hazo_connect_instance() later from an API
23
+ * route's hazo_get_auth() call — two separate entry points that a bundler
24
+ * (Next.js/Turbopack, especially in `next dev`) can place in separate module
25
+ * graphs, each getting its own evaluation of this module. Plain `let`s would
26
+ * then be two different variables: the injected instance set in one graph
27
+ * would be invisible in the other, get_hazo_connect_instance() would fall
28
+ * through to getHazoConnectSingleton()'s INI-config path (which throws
29
+ * "hazo_connect_singleton_failed" when the app deliberately has no
30
+ * [hazo_connect] config section), and every authenticated request would fail
31
+ * with a DB lookup error even though the singleton was injected correctly.
32
+ * globalThis is the one thing shared across module graphs in the same
33
+ * process; Symbol.for interns the key so every graph's accessor resolves to
34
+ * the same backing object. Same pattern as auth_hooks.ts's hook registry.
35
+ */
36
+ const CONNECT_SINGLETON_KEY = Symbol.for('hazo_auth.hazo_connect_instance');
37
+
38
+ type ConnectSingletonState = {
39
+ instance: HazoConnectAdapter | null;
40
+ isInitialized: boolean;
41
+ };
42
+
43
+ function connect_singleton_store(): ConnectSingletonState {
44
+ const g = globalThis as unknown as Record<symbol, ConnectSingletonState>;
45
+ return (g[CONNECT_SINGLETON_KEY] ??= { instance: null, isInitialized: false });
46
+ }
19
47
 
20
48
  // section: helpers
21
49
  /**
@@ -33,8 +61,27 @@ let isInitialized = false;
33
61
  * @returns The singleton HazoConnectAdapter instance
34
62
  */
35
63
  export function get_hazo_connect_instance(): HazoConnectAdapter {
64
+ const state = connect_singleton_store();
65
+
36
66
  // Honor test injection or cached fallback first
37
- if (hazoConnectInstance) return hazoConnectInstance;
67
+ if (state.instance) return state.instance;
68
+
69
+ // Get configuration from hazo_auth_config.ini (falls back to environment variables)
70
+ const config_options = get_hazo_connect_config_options();
71
+
72
+ // "pg" (raw Postgres, e.g. a standalone CLI process talking to an app's own
73
+ // DATABASE_URL) has no generic env-based singleton in
74
+ // hazo_connect/nextjs/setup — getHazoConnectSingleton only understands
75
+ // sqlite/postgrest and would throw "Unsupported database type: pg". Build
76
+ // it directly instead of routing through that singleton's throw-and-catch
77
+ // fallback path below.
78
+ if (config_options.type === "pg") {
79
+ if (!state.instance) {
80
+ state.instance = create_sqlite_hazo_connect_server();
81
+ }
82
+ return state.instance;
83
+ }
84
+
38
85
  // Use the new singleton API from hazo_connect
39
86
  // This automatically handles:
40
87
  // - Instance reuse
@@ -42,8 +89,6 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
42
89
  // - Thread-safety for Next.js serverless
43
90
  // - Configuration from hazo_auth_config.ini (via hazo_config) or environment variables
44
91
  try {
45
- // Get configuration from hazo_auth_config.ini (falls back to environment variables)
46
- const config_options = get_hazo_connect_config_options();
47
92
  const logger = create_app_logger();
48
93
  logger.debug("hazo_connect_singleton_attempt", {
49
94
  filename: "hazo_connect_instance.server.ts",
@@ -51,7 +96,13 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
51
96
  config_options,
52
97
  note: "Attempting to get singleton with these options",
53
98
  });
54
- return getHazoConnectSingleton(config_options);
99
+ // config_options.type is runtime-guaranteed "sqlite" | "postgrest" here
100
+ // (the "pg" branch above always returns before this point) — asserted
101
+ // away as a variable, not an object literal, so passing the extra
102
+ // baseUrl/apiKey fields through (pre-existing behavior, unrelated to
103
+ // this change) doesn't trip excess-property checking.
104
+ const singleton_options = config_options as typeof config_options & { type?: "sqlite" | "postgrest" };
105
+ return getHazoConnectSingleton(singleton_options);
55
106
  } catch (error) {
56
107
  const logger = create_app_logger();
57
108
  const error_message = error instanceof Error ? error.message : "Unknown error";
@@ -62,23 +113,22 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
62
113
  error_stack: error instanceof Error ? error.stack : undefined,
63
114
  note: "Falling back to manual singleton implementation",
64
115
  });
65
-
116
+
66
117
  // Fallback: Manual singleton implementation if new API fails
67
118
  // This should not happen with the updated package, but kept for safety
68
- if (!hazoConnectInstance) {
69
- // Get config options to determine database type
70
- const config_options = get_hazo_connect_config_options();
119
+ if (!state.instance) {
120
+ // db_type already known from config_options fetched above
71
121
  const db_type = config_options.type;
72
-
122
+
73
123
  // Only initialize SQLite admin service for SQLite databases
74
- if (db_type === "sqlite" && !isInitialized) {
124
+ if (db_type === "sqlite" && !state.isInitialized) {
75
125
  initializeAdminService({ enable_admin_ui: true });
76
- isInitialized = true;
126
+ state.isInitialized = true;
77
127
  }
78
-
128
+
79
129
  // Create the adapter instance (reads from hazo_auth_config.ini)
80
130
  // Note: Despite the name, this function supports both SQLite and PostgREST
81
- hazoConnectInstance = create_sqlite_hazo_connect_server();
131
+ state.instance = create_sqlite_hazo_connect_server();
82
132
 
83
133
  // Note: Database migrations should be applied manually via SQLite Admin UI
84
134
  // or through a separate migration script. The token_service has fallback
@@ -100,21 +150,22 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
100
150
  }
101
151
  }
102
152
  }
103
-
104
- return hazoConnectInstance;
153
+
154
+ return state.instance;
105
155
  }
106
156
  }
107
157
 
108
158
  /** Inject a connect adapter for tests (mirrors set_hazo_connect_instance pattern). */
109
159
  export function set_hazo_connect_instance(adapter: HazoConnectAdapter): void {
110
- hazoConnectInstance = adapter;
160
+ connect_singleton_store().instance = adapter;
111
161
  setHazoConnectSingleton(adapter);
112
162
  }
113
163
 
114
164
  /** Reset the injected adapter (call in afterAll). */
115
165
  export function reset_hazo_connect_instance(): void {
116
- hazoConnectInstance = null;
117
- isInitialized = false;
166
+ const state = connect_singleton_store();
167
+ state.instance = null;
168
+ state.isInitialized = false;
118
169
  resetHazoConnectSingleton();
119
170
  }
120
171
 
@@ -20,13 +20,15 @@ import { read_config_section } from "./config/config_loader.server.js";
20
20
  * @returns Configuration options for hazo_connect
21
21
  */
22
22
  function get_hazo_connect_config(): {
23
- type: "sqlite" | "postgrest";
23
+ type: "sqlite" | "postgrest" | "pg";
24
24
  sqlitePath?: string;
25
25
  sqliteDriver?: "sql.js" | "better-sqlite3";
26
26
  enableAdminUi: boolean;
27
27
  readOnly?: boolean;
28
28
  postgrestUrl?: string;
29
29
  postgrestApiKey?: string;
30
+ pgConnectionString?: string;
31
+ pgSsl?: boolean;
30
32
  } {
31
33
  const default_config_path = path.resolve(process.cwd(), "hazo_auth_config.ini");
32
34
  let hazo_connect_section: Record<string, string> | undefined;
@@ -40,7 +42,7 @@ function get_hazo_connect_config(): {
40
42
  hazo_connect_section?.type ||
41
43
  process.env.HAZO_CONNECT_TYPE ||
42
44
  "sqlite"
43
- ).toLowerCase() as "sqlite" | "postgrest";
45
+ ).toLowerCase() as "sqlite" | "postgrest" | "pg";
44
46
 
45
47
  // Read enable_admin_ui (defaults to true)
46
48
  const enable_admin_ui_str =
@@ -163,10 +165,45 @@ function get_hazo_connect_config(): {
163
165
  };
164
166
  }
165
167
 
168
+ // Raw Postgres configuration — for apps whose own DB is a `pg`-dialect
169
+ // hazo_connect adapter (JSONB/TEXT[]/INT[] columns PostgREST can't model),
170
+ // which inject their own adapter at runtime via set_hazo_connect_instance()
171
+ // (see hazo_connect_instance.server.ts's own comment) but whose standalone
172
+ // CLI process (this file, used by `hazo_auth init-users` etc.) never runs
173
+ // that app's instrumentation.ts — so the CLI needs its own direct
174
+ // connection, reusing the same DATABASE_URL the app itself already has.
175
+ if (type === "pg") {
176
+ const connection_string =
177
+ hazo_connect_section?.database_url ||
178
+ process.env.HAZO_CONNECT_DATABASE_URL ||
179
+ process.env.DATABASE_URL;
180
+
181
+ if (!connection_string) {
182
+ throw new HazoConfigError({
183
+ code: 'HAZO_AUTH_CONFIG',
184
+ pkg: 'hazo_auth',
185
+ message: 'Postgres connection string is required for type "pg". Set database_url in [hazo_connect] section of hazo_auth_config.ini, or set HAZO_CONNECT_DATABASE_URL or DATABASE_URL environment variable.',
186
+ });
187
+ }
188
+
189
+ const ssl_str =
190
+ hazo_connect_section?.ssl ||
191
+ process.env.HAZO_CONNECT_PG_SSL ||
192
+ "false";
193
+ const ssl = ssl_str.toLowerCase() === "true";
194
+
195
+ return {
196
+ type: "pg",
197
+ pgConnectionString: connection_string,
198
+ pgSsl: ssl,
199
+ enableAdminUi,
200
+ };
201
+ }
202
+
166
203
  throw new HazoConfigError({
167
204
  code: 'HAZO_AUTH_CONFIG',
168
205
  pkg: 'hazo_auth',
169
- message: `Unsupported HAZO_CONNECT_TYPE: ${type}. Supported types: sqlite, postgrest`,
206
+ message: `Unsupported HAZO_CONNECT_TYPE: ${type}. Supported types: sqlite, postgrest, pg`,
170
207
  });
171
208
  }
172
209
 
@@ -193,7 +230,7 @@ export function create_sqlite_hazo_connect_server() {
193
230
  if (config.type === "postgrest") {
194
231
  // Ensure we have a value (empty string if not set, for PostgREST instances without auth)
195
232
  const apiKey = config.postgrestApiKey || "";
196
-
233
+
197
234
  return createHazoConnect({
198
235
  type: "postgrest",
199
236
  baseUrl: config.postgrestUrl!,
@@ -201,6 +238,14 @@ export function create_sqlite_hazo_connect_server() {
201
238
  });
202
239
  }
203
240
 
241
+ if (config.type === "pg") {
242
+ return createHazoConnect({
243
+ type: "pg",
244
+ connectionString: config.pgConnectionString!,
245
+ ssl: config.pgSsl ?? false,
246
+ });
247
+ }
248
+
204
249
  throw new HazoConfigError({ code: 'HAZO_AUTH_CONFIG', pkg: 'hazo_auth', message: `Unsupported database type: ${config.type}` });
205
250
  }
206
251
 
@@ -210,13 +255,15 @@ export function create_sqlite_hazo_connect_server() {
210
255
  * @returns Configuration options compatible with getHazoConnectSingleton
211
256
  */
212
257
  export function get_hazo_connect_config_options(): {
213
- type?: "sqlite" | "postgrest";
258
+ type?: "sqlite" | "postgrest" | "pg";
214
259
  sqlitePath?: string;
215
260
  sqliteDriver?: "sql.js" | "better-sqlite3";
216
261
  enableAdminUi?: boolean;
217
262
  readOnly?: boolean;
218
263
  baseUrl?: string;
219
264
  apiKey?: string;
265
+ connectionString?: string;
266
+ ssl?: boolean;
220
267
  } {
221
268
  const config = get_hazo_connect_config();
222
269
 
@@ -238,6 +285,19 @@ export function get_hazo_connect_config_options(): {
238
285
  };
239
286
  }
240
287
 
288
+ // No generic env-based singleton exists for "pg" in hazo_connect/nextjs/setup
289
+ // (getHazoConnectSingleton only understands sqlite/postgrest) — this result
290
+ // is still returned so get_hazo_connect_instance() can read `.type` to skip
291
+ // that singleton call entirely and build the pg adapter directly via
292
+ // create_sqlite_hazo_connect_server() instead.
293
+ if (config.type === "pg") {
294
+ return {
295
+ type: "pg",
296
+ connectionString: config.pgConnectionString,
297
+ ssl: config.pgSsl,
298
+ };
299
+ }
300
+
241
301
  // Fallback: return empty object to let it use environment variables
242
302
  return {};
243
303
  }
@@ -396,10 +396,25 @@ export async function send_template_email(
396
396
  const from_name = await get_email_from_name(notify_config);
397
397
  const subject = get_email_subject(template_type);
398
398
 
399
- // Dynamic import keeps hazo_notify optional at build time.
400
- const { send_template_email: notify_send_template_email } = await import(
399
+ // A bare `await import("hazo_notify/template_manager")` here would keep
400
+ // hazo_notify optional at *runtime* (ESM dynamic import, caught by this
401
+ // function's own try/catch) but not at *build time*: Turbopack/webpack
402
+ // still statically resolve a literal-string dynamic import target and
403
+ // eagerly bundle its whole module graph, which fails the build outright
404
+ // for any consumer that has hazo_notify installed (even just for one
405
+ // subpath export) without also having every one of hazo_notify's own
406
+ // `template_manager` dependencies (handlebars, hazo_i18n,
407
+ // isomorphic-dompurify, …) installed. `optional_import` (same helper
408
+ // the two `hazo_notify/adapters/email` call sites above already use)
409
+ // carries the turbopackIgnore/webpackIgnore/@vite-ignore directives
410
+ // that make the bundler treat this as truly optional.
411
+ const notify_template_manager_module = await optional_import<typeof import("hazo_notify/template_manager")>(
401
412
  "hazo_notify/template_manager"
402
413
  );
414
+ if (!notify_template_manager_module) {
415
+ throw new Error("hazo_notify is not installed");
416
+ }
417
+ const { send_template_email: notify_send_template_email } = notify_template_manager_module;
403
418
 
404
419
  const result = await notify_send_template_email(
405
420
  {
@@ -1 +1 @@
1
- {"version":3,"file":"deny_permission.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/deny_permission.server.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,CAAC;AASrB,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,IAAI,EAAE,GAAG,CAAC;IACV,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,sCAAsC;IACtC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAuDnE"}
1
+ {"version":3,"file":"deny_permission.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/deny_permission.server.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,CAAC;AAUrB,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,IAAI,EAAE,GAAG,CAAC;IACV,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,sCAAsC;IACtC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,CAyDnE"}
@@ -1,5 +1,6 @@
1
1
  // file_description: standalone helper to return a 403 FORBIDDEN response and fire the permission-denied handler
2
2
  import 'server-only';
3
+ import { optional_import } from 'hazo_core';
3
4
  import { buildDenialPayloadFromRequest, getPermissionDeniedHandler, } from './with_permission_issue_capture.server.js';
4
5
  function extractUserId(auth) {
5
6
  var _a, _b;
@@ -52,13 +53,15 @@ export function denyPermission(input) {
52
53
  // Kick off async hazo_api enhancement but return the sync response immediately.
53
54
  // The returned Response object is the sync fallback; hazo_api is decorative for
54
55
  // middleware use cases that don't need the exact envelope.
55
- void import('hazo_api')
56
- .then((m) => {
56
+ // optional_import (not a literal `import('hazo_api')`) — hazo_api is an
57
+ // optional peer; a literal dynamic import of an uninstalled package name
58
+ // fails Next.js/Turbopack's build-time static resolution even though the
59
+ // `.catch()` would have handled it fine at runtime.
60
+ void optional_import('hazo_api').then((m) => {
57
61
  if (typeof (m === null || m === void 0 ? void 0 : m.fail) === 'function') {
58
62
  // No-op: we already returned — this is a fire-and-forget; nothing to do with the result.
59
63
  }
60
- })
61
- .catch(() => undefined);
64
+ });
62
65
  return new Response(bodyJson, {
63
66
  status: 403,
64
67
  headers: { 'Content-Type': 'application/json' },
@@ -1 +1 @@
1
- {"version":3,"file":"with_permission_issue_capture.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_permission_issue_capture.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAS/C,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAUD,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC7D,IAAI,CAEN;AAED,wBAAgB,0BAA0B,eARN,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAUnF;AAID,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,uBAAuB,GAC7B,uBAAuB,CAoCzB;AAID,yFAAyF;AACzF,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsChG;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EACpD,IAAI,EAAE;IAAE,oBAAoB,EAAE,MAAM,EAAE,CAAA;CAAE,GACvC,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0D7C"}
1
+ {"version":3,"file":"with_permission_issue_capture.server.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/with_permission_issue_capture.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAGrB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAS/C,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAUD,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC7D,IAAI,CAEN;AAED,wBAAgB,0BAA0B,eARN,uBAAuB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAUnF;AAID,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,uBAAuB,GAC7B,uBAAuB,CAoCzB;AAID,yFAAyF;AACzF,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwChG;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EACpD,IAAI,EAAE;IAAE,oBAAoB,EAAE,MAAM,EAAE,CAAA;CAAE,GACvC,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0D7C"}
@@ -1,7 +1,7 @@
1
1
  // file_description: Route handler wrapper that catches PermissionError and returns a structured hazo_api fail() 403
2
2
  // section: server-only-guard
3
3
  import 'server-only';
4
- import { createLogger } from 'hazo_core';
4
+ import { createLogger, optional_import } from 'hazo_core';
5
5
  import { PermissionError } from './auth_types.js';
6
6
  import { hazo_get_auth } from './hazo_get_auth.server.js';
7
7
  const log = createLogger('hazo_auth:permission_capture');
@@ -56,7 +56,9 @@ export function buildDenialPayloadFromRequest(request, parts) {
56
56
  // section: response_helper
57
57
  /** Builds the 403 Response, using hazo_api.fail() if available, otherwise hand-built. */
58
58
  export async function buildForbiddenResponse(payload) {
59
- const apiMod = (await import('hazo_api').catch(() => null));
59
+ // optional_import, not a literal `import('hazo_api')` — see deny_permission.server.ts
60
+ // for why a literal dynamic import of this optional peer breaks Turbopack builds.
61
+ const apiMod = await optional_import('hazo_api');
60
62
  if (apiMod === null || apiMod === void 0 ? void 0 : apiMod.fail) {
61
63
  return apiMod.fail('FORBIDDEN', payload.user_friendly_message, {
62
64
  status: 403,
@@ -1 +1 @@
1
- {"version":3,"file":"hazo_connect_instance.server.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_connect_instance.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAMrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAYvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,IAAI,kBAAkB,CAuE9D;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAG3E;AAED,qDAAqD;AACrD,wBAAgB,2BAA2B,IAAI,IAAI,CAIlD"}
1
+ {"version":3,"file":"hazo_connect_instance.server.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_connect_instance.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AAMrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAwCvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,IAAI,kBAAkB,CA6F9D;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAG3E;AAED,qDAAqD;AACrD,wBAAgB,2BAA2B,IAAI,IAAI,CAKlD"}
@@ -7,8 +7,31 @@ import { create_sqlite_hazo_connect_server, get_hazo_connect_config_options } fr
7
7
  import { initializeAdminService, getSqliteAdminService } from "hazo_connect/server";
8
8
  import { create_app_logger } from "./app_logger.js";
9
9
  // section: singleton_state
10
- let hazoConnectInstance = null;
11
- let isInitialized = false;
10
+ /**
11
+ * Backed by globalThis (keyed by a well-known Symbol.for), not plain
12
+ * module-level variables. A consuming Next.js app typically calls
13
+ * set_hazo_connect_instance() once from instrumentation.ts (to inject its own
14
+ * Postgres-backed hazo_connect adapter, bypassing this package's INI-based
15
+ * sqlite/postgrest config) and get_hazo_connect_instance() later from an API
16
+ * route's hazo_get_auth() call — two separate entry points that a bundler
17
+ * (Next.js/Turbopack, especially in `next dev`) can place in separate module
18
+ * graphs, each getting its own evaluation of this module. Plain `let`s would
19
+ * then be two different variables: the injected instance set in one graph
20
+ * would be invisible in the other, get_hazo_connect_instance() would fall
21
+ * through to getHazoConnectSingleton()'s INI-config path (which throws
22
+ * "hazo_connect_singleton_failed" when the app deliberately has no
23
+ * [hazo_connect] config section), and every authenticated request would fail
24
+ * with a DB lookup error even though the singleton was injected correctly.
25
+ * globalThis is the one thing shared across module graphs in the same
26
+ * process; Symbol.for interns the key so every graph's accessor resolves to
27
+ * the same backing object. Same pattern as auth_hooks.ts's hook registry.
28
+ */
29
+ const CONNECT_SINGLETON_KEY = Symbol.for('hazo_auth.hazo_connect_instance');
30
+ function connect_singleton_store() {
31
+ var _a;
32
+ const g = globalThis;
33
+ return ((_a = g[CONNECT_SINGLETON_KEY]) !== null && _a !== void 0 ? _a : (g[CONNECT_SINGLETON_KEY] = { instance: null, isInitialized: false }));
34
+ }
12
35
  // section: helpers
13
36
  /**
14
37
  * Gets or creates the singleton hazo_connect adapter instance
@@ -25,9 +48,24 @@ let isInitialized = false;
25
48
  * @returns The singleton HazoConnectAdapter instance
26
49
  */
27
50
  export function get_hazo_connect_instance() {
51
+ const state = connect_singleton_store();
28
52
  // Honor test injection or cached fallback first
29
- if (hazoConnectInstance)
30
- return hazoConnectInstance;
53
+ if (state.instance)
54
+ return state.instance;
55
+ // Get configuration from hazo_auth_config.ini (falls back to environment variables)
56
+ const config_options = get_hazo_connect_config_options();
57
+ // "pg" (raw Postgres, e.g. a standalone CLI process talking to an app's own
58
+ // DATABASE_URL) has no generic env-based singleton in
59
+ // hazo_connect/nextjs/setup — getHazoConnectSingleton only understands
60
+ // sqlite/postgrest and would throw "Unsupported database type: pg". Build
61
+ // it directly instead of routing through that singleton's throw-and-catch
62
+ // fallback path below.
63
+ if (config_options.type === "pg") {
64
+ if (!state.instance) {
65
+ state.instance = create_sqlite_hazo_connect_server();
66
+ }
67
+ return state.instance;
68
+ }
31
69
  // Use the new singleton API from hazo_connect
32
70
  // This automatically handles:
33
71
  // - Instance reuse
@@ -35,8 +73,6 @@ export function get_hazo_connect_instance() {
35
73
  // - Thread-safety for Next.js serverless
36
74
  // - Configuration from hazo_auth_config.ini (via hazo_config) or environment variables
37
75
  try {
38
- // Get configuration from hazo_auth_config.ini (falls back to environment variables)
39
- const config_options = get_hazo_connect_config_options();
40
76
  const logger = create_app_logger();
41
77
  logger.debug("hazo_connect_singleton_attempt", {
42
78
  filename: "hazo_connect_instance.server.ts",
@@ -44,7 +80,13 @@ export function get_hazo_connect_instance() {
44
80
  config_options,
45
81
  note: "Attempting to get singleton with these options",
46
82
  });
47
- return getHazoConnectSingleton(config_options);
83
+ // config_options.type is runtime-guaranteed "sqlite" | "postgrest" here
84
+ // (the "pg" branch above always returns before this point) — asserted
85
+ // away as a variable, not an object literal, so passing the extra
86
+ // baseUrl/apiKey fields through (pre-existing behavior, unrelated to
87
+ // this change) doesn't trip excess-property checking.
88
+ const singleton_options = config_options;
89
+ return getHazoConnectSingleton(singleton_options);
48
90
  }
49
91
  catch (error) {
50
92
  const logger = create_app_logger();
@@ -58,18 +100,17 @@ export function get_hazo_connect_instance() {
58
100
  });
59
101
  // Fallback: Manual singleton implementation if new API fails
60
102
  // This should not happen with the updated package, but kept for safety
61
- if (!hazoConnectInstance) {
62
- // Get config options to determine database type
63
- const config_options = get_hazo_connect_config_options();
103
+ if (!state.instance) {
104
+ // db_type already known from config_options fetched above
64
105
  const db_type = config_options.type;
65
106
  // Only initialize SQLite admin service for SQLite databases
66
- if (db_type === "sqlite" && !isInitialized) {
107
+ if (db_type === "sqlite" && !state.isInitialized) {
67
108
  initializeAdminService({ enable_admin_ui: true });
68
- isInitialized = true;
109
+ state.isInitialized = true;
69
110
  }
70
111
  // Create the adapter instance (reads from hazo_auth_config.ini)
71
112
  // Note: Despite the name, this function supports both SQLite and PostgREST
72
- hazoConnectInstance = create_sqlite_hazo_connect_server();
113
+ state.instance = create_sqlite_hazo_connect_server();
73
114
  // Note: Database migrations should be applied manually via SQLite Admin UI
74
115
  // or through a separate migration script. The token_service has fallback
75
116
  // logic to work without the token_type column if migration hasn't been applied.
@@ -90,17 +131,18 @@ export function get_hazo_connect_instance() {
90
131
  }
91
132
  }
92
133
  }
93
- return hazoConnectInstance;
134
+ return state.instance;
94
135
  }
95
136
  }
96
137
  /** Inject a connect adapter for tests (mirrors set_hazo_connect_instance pattern). */
97
138
  export function set_hazo_connect_instance(adapter) {
98
- hazoConnectInstance = adapter;
139
+ connect_singleton_store().instance = adapter;
99
140
  setHazoConnectSingleton(adapter);
100
141
  }
101
142
  /** Reset the injected adapter (call in afterAll). */
102
143
  export function reset_hazo_connect_instance() {
103
- hazoConnectInstance = null;
104
- isInitialized = false;
144
+ const state = connect_singleton_store();
145
+ state.instance = null;
146
+ state.isInitialized = false;
105
147
  resetHazoConnectSingleton();
106
148
  }
@@ -11,12 +11,14 @@ export declare function create_sqlite_hazo_connect_server(): import("hazo_connec
11
11
  * @returns Configuration options compatible with getHazoConnectSingleton
12
12
  */
13
13
  export declare function get_hazo_connect_config_options(): {
14
- type?: "sqlite" | "postgrest";
14
+ type?: "sqlite" | "postgrest" | "pg";
15
15
  sqlitePath?: string;
16
16
  sqliteDriver?: "sql.js" | "better-sqlite3";
17
17
  enableAdminUi?: boolean;
18
18
  readOnly?: boolean;
19
19
  baseUrl?: string;
20
20
  apiKey?: string;
21
+ connectionString?: string;
22
+ ssl?: boolean;
21
23
  };
22
24
  //# sourceMappingURL=hazo_connect_setup.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hazo_connect_setup.server.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_connect_setup.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AA0KrB;;;;GAIG;AACH,wBAAgB,iCAAiC,8CA2BhD;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI;IACjD,IAAI,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,QAAQ,GAAG,gBAAgB,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAuBA"}
1
+ {"version":3,"file":"hazo_connect_setup.server.d.ts","sourceRoot":"","sources":["../../src/lib/hazo_connect_setup.server.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC;AA+MrB;;;;GAIG;AACH,wBAAgB,iCAAiC,8CAmChD;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI;IACjD,IAAI,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI,CAAC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,QAAQ,GAAG,gBAAgB,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAoCA"}
@@ -122,10 +122,39 @@ function get_hazo_connect_config() {
122
122
  enableAdminUi,
123
123
  };
124
124
  }
125
+ // Raw Postgres configuration — for apps whose own DB is a `pg`-dialect
126
+ // hazo_connect adapter (JSONB/TEXT[]/INT[] columns PostgREST can't model),
127
+ // which inject their own adapter at runtime via set_hazo_connect_instance()
128
+ // (see hazo_connect_instance.server.ts's own comment) but whose standalone
129
+ // CLI process (this file, used by `hazo_auth init-users` etc.) never runs
130
+ // that app's instrumentation.ts — so the CLI needs its own direct
131
+ // connection, reusing the same DATABASE_URL the app itself already has.
132
+ if (type === "pg") {
133
+ const connection_string = (hazo_connect_section === null || hazo_connect_section === void 0 ? void 0 : hazo_connect_section.database_url) ||
134
+ process.env.HAZO_CONNECT_DATABASE_URL ||
135
+ process.env.DATABASE_URL;
136
+ if (!connection_string) {
137
+ throw new HazoConfigError({
138
+ code: 'HAZO_AUTH_CONFIG',
139
+ pkg: 'hazo_auth',
140
+ message: 'Postgres connection string is required for type "pg". Set database_url in [hazo_connect] section of hazo_auth_config.ini, or set HAZO_CONNECT_DATABASE_URL or DATABASE_URL environment variable.',
141
+ });
142
+ }
143
+ const ssl_str = (hazo_connect_section === null || hazo_connect_section === void 0 ? void 0 : hazo_connect_section.ssl) ||
144
+ process.env.HAZO_CONNECT_PG_SSL ||
145
+ "false";
146
+ const ssl = ssl_str.toLowerCase() === "true";
147
+ return {
148
+ type: "pg",
149
+ pgConnectionString: connection_string,
150
+ pgSsl: ssl,
151
+ enableAdminUi,
152
+ };
153
+ }
125
154
  throw new HazoConfigError({
126
155
  code: 'HAZO_AUTH_CONFIG',
127
156
  pkg: 'hazo_auth',
128
- message: `Unsupported HAZO_CONNECT_TYPE: ${type}. Supported types: sqlite, postgrest`,
157
+ message: `Unsupported HAZO_CONNECT_TYPE: ${type}. Supported types: sqlite, postgrest, pg`,
129
158
  });
130
159
  }
131
160
  /**
@@ -134,6 +163,7 @@ function get_hazo_connect_config() {
134
163
  * This should only be called from server-side code (API routes, server components)
135
164
  */
136
165
  export function create_sqlite_hazo_connect_server() {
166
+ var _a;
137
167
  const config = get_hazo_connect_config();
138
168
  if (config.type === "sqlite") {
139
169
  return createHazoConnect({
@@ -155,6 +185,13 @@ export function create_sqlite_hazo_connect_server() {
155
185
  apiKey: apiKey, // Pass empty string if not set
156
186
  });
157
187
  }
188
+ if (config.type === "pg") {
189
+ return createHazoConnect({
190
+ type: "pg",
191
+ connectionString: config.pgConnectionString,
192
+ ssl: (_a = config.pgSsl) !== null && _a !== void 0 ? _a : false,
193
+ });
194
+ }
158
195
  throw new HazoConfigError({ code: 'HAZO_AUTH_CONFIG', pkg: 'hazo_auth', message: `Unsupported database type: ${config.type}` });
159
196
  }
160
197
  /**
@@ -180,6 +217,18 @@ export function get_hazo_connect_config_options() {
180
217
  apiKey: config.postgrestApiKey || "", // Corrected from postgrestApiKey and ensured string value
181
218
  };
182
219
  }
220
+ // No generic env-based singleton exists for "pg" in hazo_connect/nextjs/setup
221
+ // (getHazoConnectSingleton only understands sqlite/postgrest) — this result
222
+ // is still returned so get_hazo_connect_instance() can read `.type` to skip
223
+ // that singleton call entirely and build the pg adapter directly via
224
+ // create_sqlite_hazo_connect_server() instead.
225
+ if (config.type === "pg") {
226
+ return {
227
+ type: "pg",
228
+ connectionString: config.pgConnectionString,
229
+ ssl: config.pgSsl,
230
+ };
231
+ }
183
232
  // Fallback: return empty object to let it use environment variables
184
233
  return {};
185
234
  }
@@ -1 +1 @@
1
- {"version":3,"file":"email_service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/email_service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,4BAA4B,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,G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MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,oBAAoB,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;AAElH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC,CAAC;AAiBF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAE3E;AAmMD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA4ErG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,iBAAiB,EAChC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,iBAAiB,EACvB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA4G/C"}
@@ -328,8 +328,23 @@ export async function send_template_email(template_type, to, data, recipient_use
328
328
  const from = await get_email_from(notify_config);
329
329
  const from_name = await get_email_from_name(notify_config);
330
330
  const subject = get_email_subject(template_type);
331
- // Dynamic import keeps hazo_notify optional at build time.
332
- const { send_template_email: notify_send_template_email } = await import("hazo_notify/template_manager");
331
+ // A bare `await import("hazo_notify/template_manager")` here would keep
332
+ // hazo_notify optional at *runtime* (ESM dynamic import, caught by this
333
+ // function's own try/catch) but not at *build time*: Turbopack/webpack
334
+ // still statically resolve a literal-string dynamic import target and
335
+ // eagerly bundle its whole module graph, which fails the build outright
336
+ // for any consumer that has hazo_notify installed (even just for one
337
+ // subpath export) without also having every one of hazo_notify's own
338
+ // `template_manager` dependencies (handlebars, hazo_i18n,
339
+ // isomorphic-dompurify, …) installed. `optional_import` (same helper
340
+ // the two `hazo_notify/adapters/email` call sites above already use)
341
+ // carries the turbopackIgnore/webpackIgnore/@vite-ignore directives
342
+ // that make the bundler treat this as truly optional.
343
+ const notify_template_manager_module = await optional_import("hazo_notify/template_manager");
344
+ if (!notify_template_manager_module) {
345
+ throw new Error("hazo_notify is not installed");
346
+ }
347
+ const { send_template_email: notify_send_template_email } = notify_template_manager_module;
333
348
  const result = await notify_send_template_email(Object.assign({ template_name: template_type, to,
334
349
  variables, scope_id: null, subject,
335
350
  from,
@@ -1,5 +1,6 @@
1
1
  import "server-only";
2
2
  export * from "./lib/auth/index.js";
3
+ export { HAZO_AUTH_PERMISSIONS, ALL_ADMIN_PERMISSIONS, GLOBAL_ADMIN_PERMISSION } from "./lib/constants.js";
3
4
  export { register_auth_hooks, fire_auth_hook } from "./lib/auth_hooks.js";
4
5
  export type { AuthHooks, AuthHookContext } from "./lib/auth_hooks";
5
6
  export * from "./lib/services/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"server-lib.d.ts","sourceRoot":"","sources":["../src/server-lib.ts"],"names":[],"mappings":"AAYA,OAAO,aAAa,CAAC;AAGrB,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnE,cAAc,sBAAsB,CAAC;AACr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AE,MAAM,6CAA6C,CAAC;AAG9F,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAK7E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC1F,YAAY,EACV,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,8BAA8B,CAAC"}
@@ -12,6 +12,13 @@
12
12
  import "server-only";
13
13
  // section: auth_exports
14
14
  export * from "./lib/auth/index.js";
15
+ // section: constant_exports
16
+ // Zero-dependency string constants — exported here (not just from the root
17
+ // `hazo_auth` / `hazo_auth/client` entries) so server code that only needs
18
+ // e.g. GLOBAL_ADMIN_PERMISSION isn't forced to pull in the root entry's
19
+ // component tree (hazo_ui, @uiw/react-md-editor, its .css import) just to
20
+ // read a string.
21
+ export { HAZO_AUTH_PERMISSIONS, ALL_ADMIN_PERMISSIONS, GLOBAL_ADMIN_PERMISSION } from "./lib/constants.js";
15
22
  // section: auth_hooks_exports
16
23
  export { register_auth_hooks, fire_auth_hook } from "./lib/auth_hooks.js";
17
24
  // section: service_exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_auth",
3
- "version": "10.32.0",
3
+ "version": "10.32.2",
4
4
  "description": "Zero-config authentication UI components for Next.js with RBAC, OAuth, scope-based multi-tenancy, and invitations",
5
5
  "keywords": [
6
6
  "authentication",
@@ -106,6 +106,10 @@
106
106
  "types": "./dist/server/routes/index.d.ts",
107
107
  "import": "./dist/server/routes/index.js"
108
108
  },
109
+ "./server/routes/*": {
110
+ "types": "./dist/server/routes/*.d.ts",
111
+ "import": "./dist/server/routes/*.js"
112
+ },
109
113
  "./server/middleware": {
110
114
  "types": "./dist/server/middleware.d.ts",
111
115
  "import": "./dist/server/middleware.js"