hazo_auth 10.32.0 → 10.32.1
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.
- package/cli-src/lib/auth/deny_permission.server.ts +10 -7
- package/cli-src/lib/auth/with_permission_issue_capture.server.ts +5 -3
- package/cli-src/lib/hazo_connect_instance.server.ts +46 -15
- package/cli-src/lib/services/email_service.ts +17 -2
- package/dist/lib/auth/deny_permission.server.d.ts.map +1 -1
- package/dist/lib/auth/deny_permission.server.js +7 -4
- package/dist/lib/auth/with_permission_issue_capture.server.d.ts.map +1 -1
- package/dist/lib/auth/with_permission_issue_capture.server.js +4 -2
- package/dist/lib/hazo_connect_instance.server.d.ts.map +1 -1
- package/dist/lib/hazo_connect_instance.server.js +37 -12
- package/dist/lib/services/email_service.d.ts.map +1 -1
- package/dist/lib/services/email_service.js +17 -2
- package/dist/server-lib.d.ts +1 -0
- package/dist/server-lib.d.ts.map +1 -1
- package/dist/server-lib.js +7 -0
- package/package.json +5 -1
|
@@ -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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
18
|
-
|
|
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,10 @@ 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 (
|
|
67
|
+
if (state.instance) return state.instance;
|
|
38
68
|
// Use the new singleton API from hazo_connect
|
|
39
69
|
// This automatically handles:
|
|
40
70
|
// - Instance reuse
|
|
@@ -62,23 +92,23 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
|
|
|
62
92
|
error_stack: error instanceof Error ? error.stack : undefined,
|
|
63
93
|
note: "Falling back to manual singleton implementation",
|
|
64
94
|
});
|
|
65
|
-
|
|
95
|
+
|
|
66
96
|
// Fallback: Manual singleton implementation if new API fails
|
|
67
97
|
// This should not happen with the updated package, but kept for safety
|
|
68
|
-
if (!
|
|
98
|
+
if (!state.instance) {
|
|
69
99
|
// Get config options to determine database type
|
|
70
100
|
const config_options = get_hazo_connect_config_options();
|
|
71
101
|
const db_type = config_options.type;
|
|
72
|
-
|
|
102
|
+
|
|
73
103
|
// Only initialize SQLite admin service for SQLite databases
|
|
74
|
-
if (db_type === "sqlite" && !isInitialized) {
|
|
104
|
+
if (db_type === "sqlite" && !state.isInitialized) {
|
|
75
105
|
initializeAdminService({ enable_admin_ui: true });
|
|
76
|
-
isInitialized = true;
|
|
106
|
+
state.isInitialized = true;
|
|
77
107
|
}
|
|
78
|
-
|
|
108
|
+
|
|
79
109
|
// Create the adapter instance (reads from hazo_auth_config.ini)
|
|
80
110
|
// Note: Despite the name, this function supports both SQLite and PostgREST
|
|
81
|
-
|
|
111
|
+
state.instance = create_sqlite_hazo_connect_server();
|
|
82
112
|
|
|
83
113
|
// Note: Database migrations should be applied manually via SQLite Admin UI
|
|
84
114
|
// or through a separate migration script. The token_service has fallback
|
|
@@ -100,21 +130,22 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
|
|
|
100
130
|
}
|
|
101
131
|
}
|
|
102
132
|
}
|
|
103
|
-
|
|
104
|
-
return
|
|
133
|
+
|
|
134
|
+
return state.instance;
|
|
105
135
|
}
|
|
106
136
|
}
|
|
107
137
|
|
|
108
138
|
/** Inject a connect adapter for tests (mirrors set_hazo_connect_instance pattern). */
|
|
109
139
|
export function set_hazo_connect_instance(adapter: HazoConnectAdapter): void {
|
|
110
|
-
|
|
140
|
+
connect_singleton_store().instance = adapter;
|
|
111
141
|
setHazoConnectSingleton(adapter);
|
|
112
142
|
}
|
|
113
143
|
|
|
114
144
|
/** Reset the injected adapter (call in afterAll). */
|
|
115
145
|
export function reset_hazo_connect_instance(): void {
|
|
116
|
-
|
|
117
|
-
|
|
146
|
+
const state = connect_singleton_store();
|
|
147
|
+
state.instance = null;
|
|
148
|
+
state.isInitialized = false;
|
|
118
149
|
resetHazoConnectSingleton();
|
|
119
150
|
}
|
|
120
151
|
|
|
@@ -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
|
-
//
|
|
400
|
-
|
|
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;
|
|
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
|
-
|
|
56
|
-
|
|
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,
|
|
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,E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,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
|
-
|
|
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;
|
|
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,CAyE9D;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
|
-
|
|
11
|
-
|
|
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,10 @@ 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 (
|
|
30
|
-
return
|
|
53
|
+
if (state.instance)
|
|
54
|
+
return state.instance;
|
|
31
55
|
// Use the new singleton API from hazo_connect
|
|
32
56
|
// This automatically handles:
|
|
33
57
|
// - Instance reuse
|
|
@@ -58,18 +82,18 @@ export function get_hazo_connect_instance() {
|
|
|
58
82
|
});
|
|
59
83
|
// Fallback: Manual singleton implementation if new API fails
|
|
60
84
|
// This should not happen with the updated package, but kept for safety
|
|
61
|
-
if (!
|
|
85
|
+
if (!state.instance) {
|
|
62
86
|
// Get config options to determine database type
|
|
63
87
|
const config_options = get_hazo_connect_config_options();
|
|
64
88
|
const db_type = config_options.type;
|
|
65
89
|
// Only initialize SQLite admin service for SQLite databases
|
|
66
|
-
if (db_type === "sqlite" && !isInitialized) {
|
|
90
|
+
if (db_type === "sqlite" && !state.isInitialized) {
|
|
67
91
|
initializeAdminService({ enable_admin_ui: true });
|
|
68
|
-
isInitialized = true;
|
|
92
|
+
state.isInitialized = true;
|
|
69
93
|
}
|
|
70
94
|
// Create the adapter instance (reads from hazo_auth_config.ini)
|
|
71
95
|
// Note: Despite the name, this function supports both SQLite and PostgREST
|
|
72
|
-
|
|
96
|
+
state.instance = create_sqlite_hazo_connect_server();
|
|
73
97
|
// Note: Database migrations should be applied manually via SQLite Admin UI
|
|
74
98
|
// or through a separate migration script. The token_service has fallback
|
|
75
99
|
// logic to work without the token_type column if migration hasn't been applied.
|
|
@@ -90,17 +114,18 @@ export function get_hazo_connect_instance() {
|
|
|
90
114
|
}
|
|
91
115
|
}
|
|
92
116
|
}
|
|
93
|
-
return
|
|
117
|
+
return state.instance;
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
120
|
/** Inject a connect adapter for tests (mirrors set_hazo_connect_instance pattern). */
|
|
97
121
|
export function set_hazo_connect_instance(adapter) {
|
|
98
|
-
|
|
122
|
+
connect_singleton_store().instance = adapter;
|
|
99
123
|
setHazoConnectSingleton(adapter);
|
|
100
124
|
}
|
|
101
125
|
/** Reset the injected adapter (call in afterAll). */
|
|
102
126
|
export function reset_hazo_connect_instance() {
|
|
103
|
-
|
|
104
|
-
|
|
127
|
+
const state = connect_singleton_store();
|
|
128
|
+
state.instance = null;
|
|
129
|
+
state.isInitialized = false;
|
|
105
130
|
resetHazoConnectSingleton();
|
|
106
131
|
}
|
|
@@ -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,GAAG,oBAAoB,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;AAElH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC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,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
|
-
//
|
|
332
|
-
|
|
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,
|
package/dist/server-lib.d.ts
CHANGED
|
@@ -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";
|
package/dist/server-lib.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"server-lib.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YAAY,EAAE,0BAA0B,EAAE,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"}
|
package/dist/server-lib.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "10.32.1",
|
|
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"
|