hazo_auth 10.32.1 → 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.
@@ -65,6 +65,23 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
65
65
 
66
66
  // Honor test injection or cached fallback first
67
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
+
68
85
  // Use the new singleton API from hazo_connect
69
86
  // This automatically handles:
70
87
  // - Instance reuse
@@ -72,8 +89,6 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
72
89
  // - Thread-safety for Next.js serverless
73
90
  // - Configuration from hazo_auth_config.ini (via hazo_config) or environment variables
74
91
  try {
75
- // Get configuration from hazo_auth_config.ini (falls back to environment variables)
76
- const config_options = get_hazo_connect_config_options();
77
92
  const logger = create_app_logger();
78
93
  logger.debug("hazo_connect_singleton_attempt", {
79
94
  filename: "hazo_connect_instance.server.ts",
@@ -81,7 +96,13 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
81
96
  config_options,
82
97
  note: "Attempting to get singleton with these options",
83
98
  });
84
- 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);
85
106
  } catch (error) {
86
107
  const logger = create_app_logger();
87
108
  const error_message = error instanceof Error ? error.message : "Unknown error";
@@ -96,8 +117,7 @@ export function get_hazo_connect_instance(): HazoConnectAdapter {
96
117
  // Fallback: Manual singleton implementation if new API fails
97
118
  // This should not happen with the updated package, but kept for safety
98
119
  if (!state.instance) {
99
- // Get config options to determine database type
100
- const config_options = get_hazo_connect_config_options();
120
+ // db_type already known from config_options fetched above
101
121
  const db_type = config_options.type;
102
122
 
103
123
  // Only initialize SQLite admin service for SQLite databases
@@ -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
  }
@@ -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;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"}
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"}
@@ -52,6 +52,20 @@ export function get_hazo_connect_instance() {
52
52
  // Honor test injection or cached fallback first
53
53
  if (state.instance)
54
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
+ }
55
69
  // Use the new singleton API from hazo_connect
56
70
  // This automatically handles:
57
71
  // - Instance reuse
@@ -59,8 +73,6 @@ export function get_hazo_connect_instance() {
59
73
  // - Thread-safety for Next.js serverless
60
74
  // - Configuration from hazo_auth_config.ini (via hazo_config) or environment variables
61
75
  try {
62
- // Get configuration from hazo_auth_config.ini (falls back to environment variables)
63
- const config_options = get_hazo_connect_config_options();
64
76
  const logger = create_app_logger();
65
77
  logger.debug("hazo_connect_singleton_attempt", {
66
78
  filename: "hazo_connect_instance.server.ts",
@@ -68,7 +80,13 @@ export function get_hazo_connect_instance() {
68
80
  config_options,
69
81
  note: "Attempting to get singleton with these options",
70
82
  });
71
- 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);
72
90
  }
73
91
  catch (error) {
74
92
  const logger = create_app_logger();
@@ -83,8 +101,7 @@ export function get_hazo_connect_instance() {
83
101
  // Fallback: Manual singleton implementation if new API fails
84
102
  // This should not happen with the updated package, but kept for safety
85
103
  if (!state.instance) {
86
- // Get config options to determine database type
87
- const config_options = get_hazo_connect_config_options();
104
+ // db_type already known from config_options fetched above
88
105
  const db_type = config_options.type;
89
106
  // Only initialize SQLite admin service for SQLite databases
90
107
  if (db_type === "sqlite" && !state.isInitialized) {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_auth",
3
- "version": "10.32.1",
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",