@softure-ai/auth 0.1.11 → 0.1.13

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 (48) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +65 -9
  3. package/dist/index.d.ts +8 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +8 -8
  6. package/dist/index.js.map +1 -1
  7. package/dist/options.d.ts +1 -1
  8. package/dist/options.d.ts.map +1 -1
  9. package/dist/options.js +26 -1
  10. package/dist/options.js.map +1 -1
  11. package/dist/proxy/index.d.ts +11 -0
  12. package/dist/proxy/index.d.ts.map +1 -1
  13. package/dist/proxy/index.js +11 -3
  14. package/dist/proxy/index.js.map +1 -1
  15. package/dist/scripts/index.d.ts +1 -0
  16. package/dist/scripts/index.d.ts.map +1 -1
  17. package/dist/scripts/index.js +4 -2
  18. package/dist/scripts/index.js.map +1 -1
  19. package/dist/scripts/seed-account.d.ts +19 -0
  20. package/dist/scripts/seed-account.d.ts.map +1 -0
  21. package/dist/scripts/seed-account.js +95 -0
  22. package/dist/scripts/seed-account.js.map +1 -0
  23. package/dist/server/index.d.ts +1 -0
  24. package/dist/server/index.d.ts.map +1 -1
  25. package/dist/server/index.js +1 -0
  26. package/dist/server/index.js.map +1 -1
  27. package/dist/server/only-account.d.ts +21 -0
  28. package/dist/server/only-account.d.ts.map +1 -0
  29. package/dist/server/only-account.js +34 -0
  30. package/dist/server/only-account.js.map +1 -0
  31. package/dist/testing/account.d.ts +27 -5
  32. package/dist/testing/account.d.ts.map +1 -1
  33. package/dist/testing/account.js +42 -7
  34. package/dist/testing/account.js.map +1 -1
  35. package/dist/testing/index.d.ts +1 -1
  36. package/dist/testing/index.d.ts.map +1 -1
  37. package/dist/testing/index.js.map +1 -1
  38. package/module.json +1 -1
  39. package/package.json +4 -4
  40. package/src/index.ts +10 -9
  41. package/src/options.ts +26 -1
  42. package/src/proxy/index.ts +21 -3
  43. package/src/scripts/index.ts +4 -2
  44. package/src/scripts/seed-account.ts +108 -0
  45. package/src/server/index.ts +7 -0
  46. package/src/server/only-account.ts +50 -0
  47. package/src/testing/account.ts +72 -12
  48. package/src/testing/index.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -4,12 +4,39 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done"). Versions before the first one below are described in their GitHub Releases (`auth@x.y.z`).
6
6
 
7
+ ## 0.1.13
8
+
9
+ - `resolveOnlyAccount({ db, envName, env? })` in `@softure-ai/auth/server`: the account a local tool acts for, named by
10
+ an environment variable or the only one in the database; refuses `auth.account_unknown`, `auth.no_account` and
11
+ `auth.account_ambiguous` with a readable `message` (#411). An app drops its own copy of this lookup.
12
+ - `runSeedAccount({ config, env? })` in `@softure-ai/auth/scripts`: a development account from `SEED_EMAIL` /
13
+ `SEED_PASSWORD` through registration (the `onRegistered` hook runs), idempotent, refused under
14
+ `NODE_ENV=production`; returns the exit code (#411).
15
+ - The `@softure-ai/ui` peer range also accepts 0.2.0.
16
+
17
+ ## 0.1.12
18
+
19
+ - `createAuthGuard({ redirect: "relative" })` answers with a path-only `Location` (`/login?next=…`), so a stack on a
20
+ port or host the config cannot list keeps the browser where it is; `createAuthGuard({ excludeExact })` lets exact
21
+ paths through (`/pricing` and `/pricing/`, not `/pricing/plans`) for an app with an exact public allowlist (#314).
22
+ - `createTestAccount` builds fixture accounts (#314): `id`, `createdAt` and a ready `passwordHash` (stored as is, never
23
+ hashed); a module context (`{ db, clock, config }`) as the first argument hashes with the app's parameters and, with
24
+ `runHooks: true`, runs the app's `onRegistered` in the account's transaction (`fields` for `event.fields`). One
25
+ password with one set of parameters is hashed once per test run.
26
+ - `adminEmails` also takes the raw environment string (#314): entries split on commas and whitespace, trimmed and
27
+ lowercased; an entry that is not an email is dropped with one log line naming its position and grants nothing. A
28
+ list still refuses a bad entry at config load.
29
+
7
30
  ## 0.1.11
8
31
 
9
32
  - The guard's login redirect uses core's `resolveAppOrigin` (#311): an origin listed in the config's
10
33
  `origins.trustedOrigins` is trusted like one in the guard's `trustedOrigins` option, and `origins.trustRequestHost`
11
34
  is honoured. A non-http(s) `X-Forwarded-Proto` value now falls back to the URL's scheme instead of making the
12
35
  origin unreadable. Needs `@softure-ai/core` 0.1.8.
36
+ - `AUTH_RATE_LIMIT_BUCKETS` declares what each bucket counts by: `register`, `login`, `password-reset` and
37
+ `password-reset-confirm` `key: "ip"`; `login-account`, `change-password` and `password-reset-account`
38
+ `key: "account"`. Change one threshold with `overrideBuckets` from `@softure-ai/security` 0.1.8.
39
+ - Requires `@softure-ai/security` `^0.1.8`: earlier versions refuse the `key` field.
13
40
 
14
41
  ## 0.1.10
15
42
 
package/README.md CHANGED
@@ -50,7 +50,7 @@ same way.
50
50
  import { defineSoftureConfig } from "@softure-ai/core";
51
51
  import { registerSoftureConfig } from "@softure-ai/core/next";
52
52
  import { auth, AUTH_RATE_LIMIT_BUCKETS } from "@softure-ai/auth";
53
- import { cloudflareIp, security } from "@softure-ai/security";
53
+ import { cloudflareIp, overrideBuckets, security } from "@softure-ai/security";
54
54
 
55
55
  const config = defineSoftureConfig({
56
56
  database: { url: process.env.DATABASE_URL! },
@@ -58,8 +58,8 @@ const config = defineSoftureConfig({
58
58
  timezone: "Europe/Warsaw",
59
59
  appOrigin: process.env.APP_ORIGIN!,
60
60
  modules: [
61
- // auth counts attempts in these buckets; change the numbers, keep the names.
62
- security({ clientIp: cloudflareIp(), buckets: { ...AUTH_RATE_LIMIT_BUCKETS } }),
61
+ // auth counts attempts in these buckets; change the numbers with overrideBuckets, keep the names.
62
+ security({ clientIp: cloudflareIp(), buckets: overrideBuckets(AUTH_RATE_LIMIT_BUCKETS, { login: { limit: 100 } }) }),
63
63
  auth({
64
64
  routes: { afterLogin: "/dashboard" },
65
65
  password: { minLength: 12 },
@@ -87,7 +87,7 @@ export default config;
87
87
  | `legacySession` | `{ cookieName, tokenPattern }` | none | Sessions of the system the app took over (section 5, "Adopting existing sessions"). |
88
88
  | `registrationClosed` | `boolean` | `false` | Declared default of the `auth.registration_closed` switch. |
89
89
  | `roles` | `string[]` | `[]` | Role names the app checks besides `admin` (always declared): `a-z`, `0-9`, `_`, `-`, at most 32. |
90
- | `adminEmails` | `string[]` | `[]` | Initial admin list: while an email is listed, its account holds `admin`. Auth does not verify emails, so create these accounts before you deploy the list (section 4, "Roles"). |
90
+ | `adminEmails` | `string[] \| string` | `[]` | Initial admin list: while an email is listed, its account holds `admin`. Auth does not verify emails, so create these accounts before you deploy the list (section 4, "Roles"). A list refuses an entry that is not an email at config load. A string is the raw environment value (`adminEmails: process.env.ADMIN_EMAILS ?? ""`): entries split on commas and whitespace, trimmed and lowercased; one that is not an email is dropped with one log line naming its position and grants nothing. |
91
91
  | `onRegistered` | `(event, ctx) => Promise<void>` | none | Called after the account is created, inside the same transaction. |
92
92
  | `rewriteRedirect` | `(path, { config, searchParams? }) => string \| Promise<string>` | none | Rewrites the path of every auth redirect: the actions' (login, sign-up, password reset, logout), the login and register pages' redirect of a signed-in visitor and `requireUser`'s redirect to login, e.g. `tagRedirect` from `@softure-ai/analytics/next`, which keeps the channel tag. A page passes its own `searchParams` (`URLSearchParams`; `requireUser` hands over the ones the page gives it); an action passes none, and during a page's render the `Referer` is the page before, not the page itself. A result that is not a path on this app, or an error, leaves auth's own path. |
93
93
  | `passwordReset.send` | `(link, user, details) => Promise<void>` | none | Delivers reset links (section 4, "Password reset"). Without it password reset is off. |
@@ -108,7 +108,9 @@ that stack only.
108
108
  per client address, `login-account` 10 per email, `change-password` 10 per user,
109
109
  `password-reset` 10 (link requests) and `password-reset-confirm` 10 (new passwords) per client
110
110
  address, `password-reset-account` 3 per email (the mails one address can get), each per 15
111
- minutes. Attempts are counted before any password is hashed. A successful login forgets the
111
+ minutes. Each bucket declares what it counts by (`key: "ip"` or `"account"`, security README §3), so
112
+ `listRateLimitBuckets(config)` names the IP-keyed ones; `overrideBuckets(AUTH_RATE_LIMIT_BUCKETS, { login: { limit: 500 } })`
113
+ changes one threshold and keeps the rest. Attempts are counted before any password is hashed. A successful login forgets the
112
114
  email's failed attempts, not the address's: the per-address `login` bucket counts every login,
113
115
  successful or not, so a test suite that logs in many times from one address must raise `login`
114
116
  (or give each test its own address). `login-account` is a lockout by design: ten wrong
@@ -250,10 +252,17 @@ const guard = createAuthGuard(softureConfig, { protect: ["/"], exclude: ["/", "/
250
252
  ```
251
253
 
252
254
  In `exclude`, `"/"` is the home page only; any other entry matches whole segments like `protect`.
255
+ An app that keeps an exact allowlist instead lists the paths in `excludeExact`: `/pricing` there lets
256
+ `/pricing` and `/pricing/` through and guards `/pricing/plans`.
253
257
  Auth's own public pages (login, register, forgot and reset password) and `/api/auth/session` are
254
258
  never guarded, so `protect: ["/"]` cannot send the login page to itself. The change-password route
255
259
  stays guarded even under an excluded prefix.
256
260
 
261
+ A stack the config cannot list (an integration run on a random port, a host added at deploy time)
262
+ sets `redirect: "relative"`: the `Location` is the path only (`/login?next=%2Faccount`), so the browser
263
+ stays on the host and port it used and no request header is read. An app whose image serves hosts it
264
+ does not know in advance can instead set the config's `origins.trustRequestHost` (core README).
265
+
257
266
  **Roles.** A role is a declared name (`admin`, plus `auth({ roles: ["editor"] })`) held by an
258
267
  account: as a row in `auth.user_roles`, or, for `admin` only, through `adminEmails`. Nothing is
259
268
  granted by default: with no admin listed and no rows, every admin-only surface stays closed.
@@ -354,6 +363,35 @@ the first login. `isPasswordHash(value)` checks the format locally, exactly: a h
354
363
  a character outside base64url or a cost scrypt refuses is not a hash `hashPassword` writes, so the script refuses it
355
364
  instead of storing a hash no password matches.
356
365
 
366
+ **Development seed.** `runSeedAccount` from `@softure-ai/auth/scripts` creates a login account for local
367
+ development from `SEED_EMAIL` and `SEED_PASSWORD` through `registerUser`, so the app's `onRegistered` hook runs as
368
+ for a real sign-up, and ends the session registration opens:
369
+
370
+ ```ts
371
+ // scripts/seed.ts, run with `tsx scripts/seed.ts`
372
+ import { runSeedAccount } from "@softure-ai/auth/scripts";
373
+ import config from "../softure.config";
374
+
375
+ process.exitCode = await runSeedAccount({ config });
376
+ ```
377
+
378
+ It is idempotent: an account with that email is left as it is (its password is not reset), exit 0. A refusal names
379
+ the variable and the code (`SEED_PASSWORD is shorter than password.minLength (auth.password_too_short)`, closed
380
+ registration, an invalid email) and writes nothing; a hook that throws rolls the account back. It refuses to run with
381
+ `NODE_ENV=production`, needs the security buckets like any registration, and never prints the password.
382
+
383
+ **One account for a local tool.** `resolveOnlyAccount({ db, envName, env? })` from `@softure-ai/auth/server` gives
384
+ the account a local tool acts for (a stdio MCP server, a measurement or seed script): the id in `env[envName]`
385
+ (`process.env` by default), which must name an account, else the only account in the database. It returns
386
+ `{ ok: true, value: id }` or a refusal with a `message` for the person running the tool: `auth.account_unknown`,
387
+ `auth.no_account`, or `auth.account_ambiguous` when there are several accounts and none is named. It never picks the
388
+ first of several.
389
+
390
+ ```ts
391
+ const account = await resolveOnlyAccount({ db, envName: "MEASURE_USER_ID" });
392
+ if (!account.ok) throw new Error(account.message);
393
+ ```
394
+
357
395
  **Password reset.** Pass a sender, and the login form links to the request page. With
358
396
  `@softure-ai/mailing` enabled, `mailingResetSender()` is that sender:
359
397
 
@@ -412,9 +450,9 @@ auth({
412
450
 
413
451
  **Tests.** `createTestAccount(db, { email, password, roles?, scrypt? })` from `@softure-ai/auth/testing`
414
452
  writes an account and its role rows in one transaction, hashed as registration hashes it, and returns
415
- the `AuthUser`. It is for tests that need an account but are not about registration: no `onRegistered`
416
- hook runs (no consent row) and no session is opened, so the test signs in through the login form.
417
- Pass the app's parameters, so the first login does not rehash:
453
+ the `AuthUser`. It is for tests that need an account but are not about registration: no session is
454
+ opened, so the test signs in through the login form. One password with one set of parameters is hashed
455
+ once per test run. Pass the app's parameters, so the first login does not rehash:
418
456
 
419
457
  ```ts
420
458
  import { getAuthOptions } from "@softure-ai/auth/server";
@@ -428,7 +466,24 @@ const user = await createTestAccount(handle.db, {
428
466
  });
429
467
  ```
430
468
 
431
- An invalid or taken email throws. The entry is server-only and never imported by the module itself.
469
+ A fixture account takes more, with a module context (`{ db, clock, config }`) instead of the database:
470
+
471
+ ```ts
472
+ const user = await createTestAccount(ctx, {
473
+ id: "0b9f5a0e-3c1d-4f6e-9a2b-7c8d9e0f1a2b",
474
+ email: "ada@example.com",
475
+ passwordHash: FIXTURE_HASH, // from hashPassword, stored as is: nothing is hashed
476
+ createdAt: new Date("2025-01-02T03:04:05Z"),
477
+ runHooks: true, // the app's onRegistered runs in the account's transaction
478
+ fields: { channel: "newsletter" }, // event.fields for the hook
479
+ });
480
+ ```
481
+
482
+ With a context and no `scrypt`, a `password` is hashed with the app's parameters. `runHooks` hands the
483
+ hook a consent accepted at `createdAt` (null when `requireConsent` is off); it needs the context and
484
+ throws with a bare database. An invalid or taken email, a `passwordHash` that is not a module hash or a
485
+ hook that throws rolls everything back and throws. The entry is server-only and never imported by the
486
+ module itself.
432
487
 
433
488
  ## 5. Migrations and tables
434
489
 
@@ -476,6 +531,7 @@ its NFC form fails, then rehashes it in NFC.
476
531
  | Name | Required | Meaning |
477
532
  | --- | --- | --- |
478
533
  | `SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED` | no | `true` / `1` closes registration, `false` / `0` opens it, over the declared default. Any other value closes it and logs the variable name. When the app defines the switch in `@softure-ai/feature-switches`, that module reads this variable by its own rules (`on` / `off` too; an unreadable value gives the fail mode). |
534
+ | `SEED_EMAIL`, `SEED_PASSWORD` | for `runSeedAccount` | The development account the seed entry creates (section 4, "Development seed"). |
479
535
 
480
536
  ## 7. Switches
481
537
 
package/dist/index.d.ts CHANGED
@@ -16,30 +16,37 @@ export declare const AUTH_RATE_LIMIT_BUCKETS: {
16
16
  readonly register: {
17
17
  readonly limit: 5;
18
18
  readonly windowMinutes: 15;
19
+ readonly key: "ip";
19
20
  };
20
21
  readonly login: {
21
22
  readonly limit: 50;
22
23
  readonly windowMinutes: 15;
24
+ readonly key: "ip";
23
25
  };
24
26
  readonly "login-account": {
25
27
  readonly limit: 10;
26
28
  readonly windowMinutes: 15;
29
+ readonly key: "account";
27
30
  };
28
31
  readonly "change-password": {
29
32
  readonly limit: 10;
30
33
  readonly windowMinutes: 15;
34
+ readonly key: "account";
31
35
  };
32
36
  readonly "password-reset": {
33
37
  readonly limit: 10;
34
38
  readonly windowMinutes: 15;
39
+ readonly key: "ip";
35
40
  };
36
41
  readonly "password-reset-account": {
37
42
  readonly limit: 3;
38
43
  readonly windowMinutes: 15;
44
+ readonly key: "account";
39
45
  };
40
46
  readonly "password-reset-confirm": {
41
47
  readonly limit: 10;
42
48
  readonly windowMinutes: 15;
49
+ readonly key: "ip";
43
50
  };
44
51
  };
45
52
  /**
@@ -174,7 +181,7 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
174
181
  requireConsent: import("zod").ZodDefault<import("zod").ZodBoolean>;
175
182
  registrationClosed: import("zod").ZodDefault<import("zod").ZodBoolean>;
176
183
  roles: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
177
- adminEmails: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>>>;
184
+ adminEmails: import("zod").ZodDefault<import("zod").ZodUnion<readonly [import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>>, import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<string[], string>>]>>;
178
185
  passwordReset: import("zod").ZodPrefault<import("zod").ZodObject<{
179
186
  send: import("zod").ZodOptional<import("zod").ZodCustom<import("./password-reset-sender.js").PasswordResetSender, import("./password-reset-sender.js").PasswordResetSender>>;
180
187
  ttlMinutes: import("zod").ZodDefault<import("zod").ZodNumber>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,2DAA2D;AAC3D,eAA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OSED_ENV = "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED"
21
21
  * and `password-reset-account` per email, which bounds the mails one address can receive.
22
22
  */
23
23
  export const AUTH_RATE_LIMIT_BUCKETS = {
24
- register: { limit: 5, windowMinutes: 15 },
25
- login: { limit: 50, windowMinutes: 15 },
26
- "login-account": { limit: 10, windowMinutes: 15 },
27
- "change-password": { limit: 10, windowMinutes: 15 },
28
- "password-reset": { limit: 10, windowMinutes: 15 },
29
- "password-reset-account": { limit: 3, windowMinutes: 15 },
30
- "password-reset-confirm": { limit: 10, windowMinutes: 15 },
24
+ register: { limit: 5, windowMinutes: 15, key: "ip" },
25
+ login: { limit: 50, windowMinutes: 15, key: "ip" },
26
+ "login-account": { limit: 10, windowMinutes: 15, key: "account" },
27
+ "change-password": { limit: 10, windowMinutes: 15, key: "account" },
28
+ "password-reset": { limit: 10, windowMinutes: 15, key: "ip" },
29
+ "password-reset-account": { limit: 3, windowMinutes: 15, key: "account" },
30
+ "password-reset-confirm": { limit: 10, windowMinutes: 15, key: "ip" },
31
31
  };
32
32
  /**
33
33
  * Enables accounts in `softure.config.ts` (next to `security({ ... })`):
@@ -36,7 +36,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
36
36
  export const auth = defineModule({
37
37
  manifest: {
38
38
  id: MODULE_ID,
39
- version: "0.1.11",
39
+ version: "0.1.13",
40
40
  dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
41
41
  dbSchema: "auth",
42
42
  tables: ["users", "sessions", "user_roles", "password_resets"],
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,qIAAqI;AACrI,4EAA4E;AAC5E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAA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AAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
package/dist/options.d.ts CHANGED
@@ -57,7 +57,7 @@ export declare const authOptionsSchema: z.ZodObject<{
57
57
  requireConsent: z.ZodDefault<z.ZodBoolean>;
58
58
  registrationClosed: z.ZodDefault<z.ZodBoolean>;
59
59
  roles: z.ZodDefault<z.ZodArray<z.ZodString>>;
60
- adminEmails: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>>;
60
+ adminEmails: z.ZodDefault<z.ZodUnion<readonly [z.ZodArray<z.ZodPipe<z.ZodString, z.ZodEmail>>, z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>]>>;
61
61
  passwordReset: z.ZodPrefault<z.ZodObject<{
62
62
  send: z.ZodOptional<z.ZodCustom<PasswordResetSender, PasswordResetSender>>;
63
63
  ttlMinutes: z.ZodDefault<z.ZodNumber>;
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAU,CAAC;AAY3C,4FAA4F;AAC5F,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,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IAAI,CAAC,CAAC;AAExG,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAMtG,QAAA,MAAM,YAAY;;;;kBAahB,CAAC;AAyBH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAsF5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC7D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC"}
package/dist/options.js CHANGED
@@ -32,6 +32,29 @@ const scryptSchema = z.strictObject({
32
32
  /** p: parallelization. */
33
33
  parallelization: z.number().int().min(1).max(16).default(1),
34
34
  });
35
+ const adminEmailSchema = z.string().trim().toLowerCase().max(MAX_EMAIL_LENGTH).pipe(z.email("must be an email address"));
36
+ /**
37
+ * `adminEmails` given as the raw environment string: entries split on commas and whitespace, trimmed and
38
+ * lowercased. One bad entry must not stop the app, so entries that are not emails are dropped with one log
39
+ * line naming their positions (never their values) and grant nothing.
40
+ */
41
+ function parseAdminEmailList(raw) {
42
+ const entries = raw.split(/[\s,]+/).filter((entry) => entry !== "");
43
+ const emails = [];
44
+ const dropped = [];
45
+ entries.forEach((entry, index) => {
46
+ const parsed = adminEmailSchema.safeParse(entry);
47
+ if (parsed.success)
48
+ emails.push(parsed.data);
49
+ else
50
+ dropped.push(index + 1);
51
+ });
52
+ if (dropped.length > 0) {
53
+ const positions = dropped.join(", ");
54
+ console.warn(`@softure-ai/auth: adminEmails: ${String(dropped.length)} of ${String(entries.length)} entries are not email addresses and grant no role (positions ${positions})`);
55
+ }
56
+ return emails;
57
+ }
35
58
  export const authOptionsSchema = z.strictObject({
36
59
  password: z
37
60
  .strictObject({
@@ -92,7 +115,9 @@ export const authOptionsSchema = z.strictObject({
92
115
  * Initial admin list: while an email is listed, the account with that email holds `admin`.
93
116
  * Auth does not verify emails, so create these accounts before deploying the list.
94
117
  */
95
- adminEmails: z.array(z.string().trim().toLowerCase().max(MAX_EMAIL_LENGTH).pipe(z.email("must be an email address"))).default([]),
118
+ adminEmails: z
119
+ .union([z.array(adminEmailSchema), z.string().transform(parseAdminEmailList)], { error: "must be a list of email addresses or one string of them" })
120
+ .default([]),
96
121
  passwordReset: z
97
122
  .strictObject({
98
123
  /** Delivers reset links. Without it password reset is off: no link, and its pages are not found. */
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,CAAC;AAE3C,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAC5C,4EAA4E;AAC5E,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AACrD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAC5D,0EAA0E;AAC1E,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AACpG,MAAM,MAAM,GAAG,gGAAgG,CAAC;AAuBh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AAe,EAAE,CAAC,CAAC,MAAM,CAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,EAAE,oBAAoB,CAAC,CAAC,QAAQ,EAAE;CACpH,CAAC,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IACjC,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1F,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,OAAO,EAAE,oDAAoD,EAAE,CAAC,CAAC;IAC7I,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -7,6 +7,11 @@ export interface AuthGuardOptions {
7
7
  * public pages here). `"/"` here is the home page only. The change-password route stays guarded.
8
8
  */
9
9
  readonly exclude?: readonly string[];
10
+ /**
11
+ * Paths that never need a session, matched whole (`/pricing` and `/pricing/`, not `/pricing/plans`), for an app
12
+ * that protects everything except an exact allowlist. Compared decoded and lowercased, like the other lists.
13
+ */
14
+ readonly excludeExact?: readonly string[];
10
15
  /**
11
16
  * Origins besides `appOrigin` and the config's `origins.trustedOrigins` that the login redirect may stay on
12
17
  * (`https://example.com`). Prefer the config's block, which every module reads. The request's public origin
@@ -14,6 +19,12 @@ export interface AuthGuardOptions {
14
19
  * `appOrigin`.
15
20
  */
16
21
  readonly trustedOrigins?: readonly string[];
22
+ /**
23
+ * `"absolute"` (default): the login URL is built on the resolved origin (above). `"relative"`: the `Location` is
24
+ * the path only (`/login?next=…`), so the browser stays on whatever host and port it used; for a stack served on
25
+ * ports or hosts the config cannot list (an integration run on a random port).
26
+ */
27
+ readonly redirect?: "absolute" | "relative";
17
28
  }
18
29
  export type AuthGuard = (request: Request) => Response | null;
19
30
  /** A guard that redirects to the login page (with `?next=`) for protected paths without a session cookie. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrF,MAAM,WAAW,gBAAgB;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAKD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;AAE9D,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAgC3F"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrF,MAAM,WAAW,gBAAgB;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CAC7C;AAKD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;AAE9D,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAoC3F"}
@@ -21,10 +21,13 @@ export function createAuthGuard(config, options) {
21
21
  // Auth's own public pages: guarding them would send a visitor from the login page to itself.
22
22
  const publicPaths = [routes.login, routes.register, routes.forgotPassword, routes.resetPassword, SESSION_ROUTE].map((path) => normalizePrefix(path, "excluded"));
23
23
  const excluded = (options.exclude ?? []).map((prefix) => normalizePrefix(prefix, "excluded"));
24
+ const exactExcluded = new Set((options.excludeExact ?? []).map((path) => normalizePrefix(path, "excluded")));
24
25
  const trustedOrigins = (options.trustedOrigins ?? []).map(normalizeOrigin);
25
26
  const isGuarded = (path) => {
26
27
  if (isUnder(path, changePassword))
27
28
  return true;
29
+ if (exactExcluded.has(normalizeTrailingSlash(path)))
30
+ return false;
28
31
  if ([...publicPaths, ...excluded].some((prefix) => isExcludedBy(path, prefix)))
29
32
  return false;
30
33
  return prefixes.some((prefix) => isUnder(path, prefix));
@@ -43,15 +46,20 @@ export function createAuthGuard(config, options) {
43
46
  // the request URL carries an internal host, and request headers alone are never trusted.
44
47
  const login = new URL(routes.login, resolveAppOrigin(config, request, { trustedOrigins }));
45
48
  login.searchParams.set("next", `${url.pathname}${url.search}`);
46
- return Response.redirect(login, 307);
49
+ if (options.redirect !== "relative")
50
+ return Response.redirect(login, 307);
51
+ // A path-only Location reads no request header at all; `Response.redirect` would need an absolute URL.
52
+ return new Response(null, { status: 307, headers: { location: `${login.pathname}${login.search}` } });
47
53
  };
48
54
  }
49
55
  function normalizePrefix(prefix, kind) {
50
56
  if (!prefix.startsWith("/")) {
51
57
  throw new Error(`createAuthGuard: ${kind} path "${prefix}" must start with /`);
52
58
  }
53
- const trimmed = prefix.length > 1 && prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
54
- return trimmed.toLowerCase();
59
+ return normalizeTrailingSlash(prefix).toLowerCase();
60
+ }
61
+ function normalizeTrailingSlash(path) {
62
+ return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
55
63
  }
56
64
  /** `entry` as an origin (`https://example.com`, a trailing `/` dropped); anything else is a config error. */
57
65
  function normalizeOrigin(entry) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,gGAAgG;AAChG,mGAAmG;AACnG,sDAAsD;AACtD,EAAE;AACF,6FAA6F;AAC7F,6FAA6F;AAC7F,mGAAmG;AACnG,mGAAmG;AACnG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAsB,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAmB1E,+GAA+G;AAC/G,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAI1C,6GAA6G;AAC7G,MAAM,UAAU,eAAe,CAAC,MAAqB,EAAE,OAAyB;IAC9E,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC3I,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACvF,MAAM,cAAc,GAAG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AkB,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,6FAA6F;AAC7F,SAAS,YAAY,CAAC,QAAgB,EAAE,MAAc;IACpD,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,OAAO,CAAC,QAAgB,EAAE,MAAc;IAC/C,OAAO,MAAM,KAAK,GAAG,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AACpF,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { createGrantRoleScript, createRevokeRoleScript, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
2
2
  export { createSetTemporaryPasswordScript, type TemporaryPasswordScriptArgs, type TemporaryPasswordScriptOptions, } from "./temporary-password.js";
3
+ export { runSeedAccount, type RunSeedAccountOptions } from "./seed-account.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,GACpC,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,EAChC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,GACpC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,5 +1,7 @@
1
- // `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles and set a temporary password
2
- // (see the README, "Roles" and "Account recovery").
1
+ // `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles and set a temporary password,
2
+ // and the development seed account
3
+ // (see the README, "Roles", "Account recovery" and "Development seed").
3
4
  export { createGrantRoleScript, createRevokeRoleScript } from "./role-scripts.js";
4
5
  export { createSetTemporaryPasswordScript, } from "./temporary-password.js";
6
+ export { runSeedAccount } from "./seed-account.js";
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,oDAAoD;AACpD,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA+C,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,GAGjC,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,mCAAmC;AACnC,wEAAwE;AACxE,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA+C,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,GAGjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAA8B,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type Clock, type SoftureConfig } from "@softure-ai/core";
2
+ import { type Database } from "@softure-ai/db";
3
+ import { type CliOutput } from "@softure-ai/db/cli";
4
+ export interface RunSeedAccountOptions {
5
+ readonly config: SoftureConfig;
6
+ /** Default: `process.env`. Reads `SEED_EMAIL`, `SEED_PASSWORD` and `NODE_ENV`. */
7
+ readonly env?: Readonly<Record<string, string | undefined>>;
8
+ /** An open database to use instead of the config's (tests); it is not closed. */
9
+ readonly database?: Database;
10
+ /** Default: the console. The password is never printed. */
11
+ readonly output?: CliOutput;
12
+ readonly clock?: Clock;
13
+ }
14
+ /**
15
+ * Creates the development account and returns the exit code: 0 created or already there, 1 refused
16
+ * or failed (nothing written), 2 `SEED_EMAIL` or `SEED_PASSWORD` missing.
17
+ */
18
+ export declare function runSeedAccount(options: RunSeedAccountOptions): Promise<number>;
19
+ //# sourceMappingURL=seed-account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed-account.d.ts","sourceRoot":"","sources":["../../src/scripts/seed-account.ts"],"names":[],"mappings":"AAQA,OAAO,EAAyC,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAuB,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAStF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC5D,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AAeD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyCpF"}
@@ -0,0 +1,95 @@
1
+ // A development login account from `SEED_EMAIL` and `SEED_PASSWORD`, created through the module's
2
+ // registration, so the app's `onRegistered` hook runs as for a real sign-up. Idempotent: an account
3
+ // with that email is left as it is. Not an ops script: it refuses to run with NODE_ENV=production.
4
+ //
5
+ // // scripts/seed.ts, run with `tsx scripts/seed.ts`
6
+ // import { runSeedAccount } from "@softure-ai/auth/scripts";
7
+ // import config from "../softure.config";
8
+ // process.exitCode = await runSeedAccount({ config });
9
+ import { errorLogLabel, safeError, systemClock } from "@softure-ai/core";
10
+ import { openCommandDatabase } from "@softure-ai/db";
11
+ import { EXIT_FAILED, EXIT_OK, EXIT_USAGE } from "@softure-ai/db/cli";
12
+ import { registerUser } from "../server/register.js";
13
+ import { logoutSession } from "../server/sessions.js";
14
+ import { normalizeEmail } from "../server/validation.js";
15
+ const NAME = "seed-account";
16
+ /** The rate limit key the seed counts registration attempts under. */
17
+ const SEED_CLIENT_KEY = "script:seed";
18
+ const REFUSALS = {
19
+ "auth.registration_closed": "registration is closed by a switch; open it for the seed run",
20
+ "auth.email_invalid": "SEED_EMAIL is not a valid email",
21
+ "auth.password_too_short": "SEED_PASSWORD is shorter than password.minLength",
22
+ "auth.password_too_long": "SEED_PASSWORD is longer than the module accepts",
23
+ "auth.consent_required": "registration requires consent",
24
+ };
25
+ const consoleOutput = {
26
+ log: (line) => console.log(line),
27
+ error: (line) => console.error(line),
28
+ };
29
+ /**
30
+ * Creates the development account and returns the exit code: 0 created or already there, 1 refused
31
+ * or failed (nothing written), 2 `SEED_EMAIL` or `SEED_PASSWORD` missing.
32
+ */
33
+ export async function runSeedAccount(options) {
34
+ const env = options.env ?? process.env;
35
+ const output = options.output ?? consoleOutput;
36
+ const email = env.SEED_EMAIL?.trim() ?? "";
37
+ const password = env.SEED_PASSWORD ?? "";
38
+ if (email === "" || password.trim() === "") {
39
+ output.error(`${NAME}: set SEED_EMAIL and SEED_PASSWORD to the development account's email and password`);
40
+ return EXIT_USAGE;
41
+ }
42
+ if (env.NODE_ENV === "production") {
43
+ output.error(`${NAME}: refused: NODE_ENV is production; the seed account is for development`);
44
+ return EXIT_FAILED;
45
+ }
46
+ const opened = await openDatabase(options);
47
+ if (!opened.ok) {
48
+ output.error(`${NAME}: ${opened.message}`);
49
+ return EXIT_FAILED;
50
+ }
51
+ try {
52
+ const ctx = { db: opened.db, clock: options.clock ?? systemClock, config: options.config };
53
+ const registered = await registerUser(ctx, { email, password, hasConsented: true, clientKey: SEED_CLIENT_KEY });
54
+ if (registered.ok) {
55
+ // Registration signs the account in; the seed only wants the account.
56
+ await logoutSession(ctx, registered.value.session.token);
57
+ output.log(`${NAME}: created the account ${registered.value.user.email}`);
58
+ return EXIT_OK;
59
+ }
60
+ if (registered.error === "auth.email_taken") {
61
+ output.log(`${NAME}: ${normalizeEmail(email)} is already there; nothing changed`);
62
+ return EXIT_OK;
63
+ }
64
+ const reason = registered.error === "security.rate_limited" ? "too many registrations from the seed; wait and run it again" : REFUSALS[registered.error];
65
+ output.error(`${NAME}: refused: ${reason} (${registered.error})`);
66
+ return EXIT_FAILED;
67
+ }
68
+ catch (error) {
69
+ output.error(`${NAME}: failed: ${describeFailure(error)}`);
70
+ return EXIT_FAILED;
71
+ }
72
+ finally {
73
+ await opened.close();
74
+ }
75
+ }
76
+ async function openDatabase(options) {
77
+ if (options.database !== undefined)
78
+ return { ok: true, db: options.database, close: () => Promise.resolve() };
79
+ if (options.config.database === null)
80
+ return { ok: false, message: "the config has no database; set database.url in softure.config" };
81
+ try {
82
+ const opened = await openCommandDatabase(options.config.database, { max: 1 });
83
+ return { ok: true, db: opened.handle.db, close: opened.close };
84
+ }
85
+ catch (error) {
86
+ return { ok: false, message: `could not open the database: ${describeFailure(error)}` };
87
+ }
88
+ }
89
+ /** The error message, except for database errors, whose message may carry query parameters (the password hash). */
90
+ function describeFailure(error) {
91
+ if (safeError(error).error === "core.database_failed")
92
+ return `database error (${errorLogLabel(error)})`;
93
+ return error instanceof Error ? error.message : String(error);
94
+ }
95
+ //# sourceMappingURL=seed-account.js.map