@softure-ai/auth 0.2.1 → 0.2.3

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 (57) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +65 -4
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/jobs/index.d.ts +1 -0
  8. package/dist/jobs/index.d.ts.map +1 -1
  9. package/dist/jobs/index.js +3 -2
  10. package/dist/jobs/index.js.map +1 -1
  11. package/dist/jobs/password-reset-job.d.ts +19 -0
  12. package/dist/jobs/password-reset-job.d.ts.map +1 -0
  13. package/dist/jobs/password-reset-job.js +41 -0
  14. package/dist/jobs/password-reset-job.js.map +1 -0
  15. package/dist/options.d.ts +2 -1
  16. package/dist/options.d.ts.map +1 -1
  17. package/dist/options.js +8 -0
  18. package/dist/options.js.map +1 -1
  19. package/dist/password-reset-sender.d.ts +8 -1
  20. package/dist/password-reset-sender.d.ts.map +1 -1
  21. package/dist/password-reset-sender.js.map +1 -1
  22. package/dist/scripts/create-account.d.ts +18 -0
  23. package/dist/scripts/create-account.d.ts.map +1 -0
  24. package/dist/scripts/create-account.js +56 -0
  25. package/dist/scripts/create-account.js.map +1 -0
  26. package/dist/scripts/index.d.ts +1 -0
  27. package/dist/scripts/index.d.ts.map +1 -1
  28. package/dist/scripts/index.js +4 -3
  29. package/dist/scripts/index.js.map +1 -1
  30. package/dist/scripts/password-choice.d.ts +22 -0
  31. package/dist/scripts/password-choice.d.ts.map +1 -0
  32. package/dist/scripts/password-choice.js +23 -0
  33. package/dist/scripts/password-choice.js.map +1 -0
  34. package/dist/scripts/temporary-password.d.ts.map +1 -1
  35. package/dist/scripts/temporary-password.js +4 -19
  36. package/dist/scripts/temporary-password.js.map +1 -1
  37. package/dist/server/index.d.ts +1 -1
  38. package/dist/server/index.d.ts.map +1 -1
  39. package/dist/server/index.js +1 -1
  40. package/dist/server/index.js.map +1 -1
  41. package/dist/server/password-reset.d.ts +10 -2
  42. package/dist/server/password-reset.d.ts.map +1 -1
  43. package/dist/server/password-reset.js +32 -10
  44. package/dist/server/password-reset.js.map +1 -1
  45. package/module.json +1 -1
  46. package/package.json +2 -2
  47. package/src/index.ts +8 -3
  48. package/src/jobs/index.ts +4 -2
  49. package/src/jobs/password-reset-job.ts +43 -0
  50. package/src/options.ts +9 -1
  51. package/src/password-reset-sender.ts +9 -1
  52. package/src/scripts/create-account.ts +71 -0
  53. package/src/scripts/index.ts +4 -3
  54. package/src/scripts/password-choice.ts +33 -0
  55. package/src/scripts/temporary-password.ts +4 -22
  56. package/src/server/index.ts +1 -0
  57. package/src/server/password-reset.ts +35 -11
package/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ 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.2.3
8
+
9
+ - `createCreateAccountScript(config, { maxAccounts?, alphabet?, clock? })` in `@softure-ai/auth/scripts` (#521): the
10
+ `create-account` ops script creates an account while registration is closed, with a drawn temporary password or a
11
+ given `--password-hash`, dry run by default. It refuses an existing or invalid email and, with `maxAccounts`, a
12
+ table that already holds that many accounts (the table is locked for the run). Migrate (optional): an app that
13
+ inserted its first account into `auth.users` itself, or added its own index to hold one account, uses the script
14
+ with `maxAccounts: 1` instead.
15
+
16
+ ## 0.2.2
17
+
18
+ - Password reset mails can leave from a background job with retry (#494): `auth({ passwordReset: { send, enqueue:
19
+ enqueuePasswordReset } })` from the new entry `@softure-ai/auth/jobs`, with `@softure-ai/jobs` as an optional peer
20
+ dependency (`^0.1.1`). The request then only enqueues `{ userId }` on the `auth.password-reset` queue; the handler
21
+ issues the link when it runs (valid for `ttlMinutes` from the send) and calls the sender, retrying a failure with the
22
+ queue's backoff. `deliverPasswordReset` returns `"queued"` in that mode; `sendPasswordReset(ctx, userId)` is the
23
+ handler's work for an app's own worker. Without `enqueue` nothing changes. Migrate (optional): install
24
+ `@softure-ai/jobs`, add `jobs({ queues: { "auth.password-reset": {} } })` to `softure.config.ts`, pass
25
+ `enqueue: enqueuePasswordReset`, and spread `passwordResetJobHandlers` into the worker's `handlers`.
26
+
7
27
  ## 0.2.1
8
28
 
9
29
  - `@softure-ai/auth/jobs` (#491): `authJobHandlers` and `authJobSchedules` run `pruneSessions` (hourly) and
package/README.md CHANGED
@@ -12,10 +12,11 @@ Users and sessions in the `auth` schema, scrypt password hashes, opaque session
12
12
  login, logout, password change and password reset as server actions and pages, `getCurrentUser` / `requireUser`
13
13
  for server code, roles (`requireRole`, `authorizeRole`, `hasRole`, and `grant-role` /
14
14
  `revoke-role` scripts), account recovery (`revokeUserSessions` and a `set-temporary-password`
15
- script), `createAuthGuard` for the app's `proxy.ts`, and a health check that
15
+ script), a `create-account` script for the first account of an app with registration closed, `createAuthGuard` for the app's `proxy.ts`, and a health check that
16
16
  `GET /api/health` of `@softure-ai/ops` runs (every auth table answers, no rows read).
17
17
  `@softure-ai/auth/mailing` sends password reset mails through `@softure-ai/mailing`
18
- (`mailingResetSender()`). `@softure-ai/auth/testing` creates accounts directly in the database for
18
+ (`mailingResetSender()`); `@softure-ai/auth/jobs` sends them from a background job of `@softure-ai/jobs` with
19
+ retry (`enqueuePasswordReset`, `passwordResetJobHandlers`). `@softure-ai/auth/testing` creates accounts directly in the database for
19
20
  tests (`createTestAccount`, section 4, "Tests").
20
21
 
21
22
  ## 2. Installation
@@ -91,6 +92,7 @@ export default config;
91
92
  | `onRegistered` | `(event, ctx) => Promise<void>` | none | Called after the account is created, inside the same transaction. |
92
93
  | `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
94
  | `passwordReset.send` | `(link, user, details) => Promise<void>` | none | Delivers reset links (section 4, "Password reset"). Without it password reset is off. |
95
+ | `passwordReset.enqueue` | `(ctx, userId) => Promise<void>` | none | Sends the link from a background job instead of the request: `enqueuePasswordReset` of `@softure-ai/auth/jobs` (section 4, "Password reset through jobs"). Needs `send`. |
94
96
  | `passwordReset.ttlMinutes` | `number` (5-1440) | `60` | How long a reset link works. |
95
97
  | `routes` | `{ login, register, changePassword, forgotPassword, resetPassword, afterLogin, afterLogout }` | `/login`, `/register`, `/account/password`, `/forgot-password`, `/reset-password`, `/`, `/login` | Where the pages are mounted and where users land. |
96
98
  | `messages` | partial dictionaries per locale (`en` built in; any other is the app's own translation) | built in | Copy overrides (section 9). |
@@ -364,6 +366,28 @@ the first login. `isPasswordHash(value)` checks the format locally, exactly: a h
364
366
  a character outside base64url or a cost scrypt refuses is not a hash `hashPassword` writes, so the script refuses it
365
367
  instead of storing a hash no password matches.
366
368
 
369
+ **First account.** An app with registration closed (`registrationClosed: true`, no `/register` page) creates its
370
+ owner's account with the `create-account` ops script. It draws a temporary password exactly like
371
+ `set-temporary-password` (or stores a `--password-hash` made locally, the same way), refuses an invalid email and an
372
+ email that already has an account, and works whether registration is open or not:
373
+
374
+ ```ts
375
+ // scripts/create-account.ts (bundled and run like grant-role)
376
+ import { createCreateAccountScript } from "@softure-ai/auth/scripts";
377
+ import { runOpsScript } from "@softure-ai/ops/scripts";
378
+ import config from "../softure.config";
379
+
380
+ process.exitCode = await runOpsScript({ script: createCreateAccountScript(config, { maxAccounts: 1 }), argv: process.argv.slice(2), config });
381
+ ```
382
+
383
+ `node create-account.mjs --email=owner@example.com` shows the account it would create and rolls back; `--commit`
384
+ writes and prints the password once (or `passwordFrom: "hash"`). The report names the user id and the number of
385
+ accounts, never the email. `maxAccounts` (a whole number of at least 1, no limit by default) makes the script refuse
386
+ once `auth.users` holds that many accounts, whoever created them; the script locks the table for its run, so two runs
387
+ cannot both pass the limit. The app's `onRegistered` hook does not run (no consent, no registration fields): an app
388
+ that keeps its own rows per account creates them in its own script. `alphabet` and `clock` work as for
389
+ `createSetTemporaryPasswordScript`.
390
+
367
391
  **Development seed.** `runSeedAccount` from `@softure-ai/auth/scripts` creates a login account for local
368
392
  development from `SEED_EMAIL` and `SEED_PASSWORD` through `registerUser`, so the app's `onRegistered` hook runs as
369
393
  for a real sign-up, and ends the session registration opens:
@@ -441,9 +465,41 @@ auth({
441
465
  link's path and query and swaps the origin in its sender, from what it knows about the user.
442
466
  - The reset page's referrer policy is `same-origin`, so the token in its URL never reaches another
443
467
  site. It still lands in your own access logs; it works once and expires.
444
- - `requestPasswordReset`, `deliverPasswordReset`, `resetPassword`, `findPasswordResetUser` and
468
+ - `requestPasswordReset`, `deliverPasswordReset`, `sendPasswordReset`, `resetPassword`, `findPasswordResetUser` and
445
469
  `prunePasswordResets` in `@softure-ai/auth/server` do the same for your own flows.
446
470
 
471
+ **Password reset through jobs.** Without it, the sender runs once after the response: a provider outage loses the mail.
472
+ With `@softure-ai/jobs` (an optional peer dependency), the request only enqueues the account's id and a worker sends
473
+ the link with retry and backoff:
474
+
475
+ ```ts
476
+ // softure.config.ts
477
+ import { auth } from "@softure-ai/auth";
478
+ import { enqueuePasswordReset, PASSWORD_RESET_QUEUE } from "@softure-ai/auth/jobs";
479
+ import { mailingResetSender } from "@softure-ai/auth/mailing";
480
+ import { jobs } from "@softure-ai/jobs";
481
+
482
+ modules: [
483
+ auth({ passwordReset: { send: mailingResetSender(), enqueue: enqueuePasswordReset } }),
484
+ jobs({ queues: { [PASSWORD_RESET_QUEUE]: { maxAttempts: 5 } } }), // "auth.password-reset"
485
+ ];
486
+
487
+ // scripts/worker.ts
488
+ import { passwordResetJobHandlers } from "@softure-ai/auth/jobs";
489
+ await runJobWorkerProcess({ config, handlers: { ...passwordResetJobHandlers, ...appHandlers } });
490
+ ```
491
+
492
+ - The request (still after the response) looks the account up and enqueues `{ userId }` on `auth.password-reset`,
493
+ deduplicated per account while a job is pending. No address and no token is ever in the payload, and no reset row
494
+ is written in the request.
495
+ - The handler (`passwordResetJobHandler`) issues the link when it runs, so the link works for `ttlMinutes` from the
496
+ send, and calls `passwordReset.send`. Only the token's hash is stored, so a retry issues a new link that replaces
497
+ the last one: a retry after a send whose outcome was not recorded (a worker crash) mails a second link, and only
498
+ the newer works. A thrown sender is logged by its label (never the link) and retried as
499
+ `auth.password_reset_send_failed`; an account deleted in the meantime ends the job without a mail.
500
+ - `mailingResetSender()` reads the registered config: the worker imports `softure.config.ts`, which registers it
501
+ (section 3).
502
+
447
503
  **Your own forms.** `@softure-ai/auth/ui` exports `LoginForm`, `RegisterForm`,
448
504
  `ChangePasswordForm`, `ForgotPasswordForm` and `ResetPasswordForm`; pass them the actions from
449
505
  `@softure-ai/auth/next`. `RegisterForm` takes `consentLabel` and `extraFields` like
@@ -596,7 +652,10 @@ failure. `@softure-ai/privacy` stores the consent through it.
596
652
 
597
653
  `passwordReset.send(link, user, details)`: after a reset request is answered, for an existing
598
654
  account only (section 4, "Password reset"). `mailingResetSender()` from `@softure-ai/auth/mailing`
599
- plugs `@softure-ai/mailing` in here.
655
+ plugs `@softure-ai/mailing` in here. With `passwordReset.enqueue`, it runs in the worker's reset job instead.
656
+
657
+ `passwordReset.enqueue(ctx, userId)`: where a reset request is answered, for an existing account, instead of the
658
+ sender. `enqueuePasswordReset` from `@softure-ai/auth/jobs` plugs `@softure-ai/jobs` in here.
600
659
 
601
660
  ## 11. GDPR
602
661
 
@@ -629,5 +688,7 @@ Rate limit rows of `security` hold only SHA-256 prefixes of the email and user i
629
688
  - A `next` path longer than 8192 characters is replaced by the default target, with a warning in
630
689
  the log that names its length.
631
690
  - A temporary password from the script is not forced to change at the next login.
691
+ - `maxAccounts` limits the `create-account` script only; registration does not count accounts. An app that must hold
692
+ at most N accounts keeps registration closed.
632
693
  - A registration attempt reveals whether an email has an account (`auth.email_taken`); the
633
694
  `register` rate limit bounds how fast anyone can ask.
package/dist/index.d.ts CHANGED
@@ -184,6 +184,7 @@ export declare const auth: import("@softure-ai/core").ModuleFactory<{
184
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>>]>>;
185
185
  passwordReset: import("zod").ZodPrefault<import("zod").ZodObject<{
186
186
  send: import("zod").ZodOptional<import("zod").ZodCustom<import("./password-reset-sender.js").PasswordResetSender, import("./password-reset-sender.js").PasswordResetSender>>;
187
+ enqueue: import("zod").ZodOptional<import("zod").ZodCustom<import("./password-reset-sender.js").PasswordResetEnqueuer, import("./password-reset-sender.js").PasswordResetEnqueuer>>;
187
188
  ttlMinutes: import("zod").ZodDefault<import("zod").ZodNumber>;
188
189
  }, import("zod/v4/core").$strict>>;
189
190
  onRegistered: import("zod").ZodOptional<import("zod").ZodCustom<import("./options.js").OnRegisteredHook, import("./options.js").OnRegisteredHook>>;
@@ -193,7 +194,7 @@ export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
193
194
  export type { AuthErrorCode, AuthFormErrorCode, AuthFormField, AuthFormState, AuthUser, NewSession, RegisteredEvent, SignedIn, } from "./contract.js";
194
195
  export { authMessages, getAuthErrorMessage, type AuthMessages } from "./messages/index.js";
195
196
  export type { AuthOptions, AuthOptionsInput, OnRegisteredHook, RewriteRedirect, RewriteRedirectContext, ScryptParams } from "./options.js";
196
- export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetSender } from "./password-reset-sender.js";
197
+ export { consolePasswordResetSender, type PasswordResetDetails, type PasswordResetEnqueuer, type PasswordResetSender, } from "./password-reset-sender.js";
197
198
  export { getSessionCookie, type SessionCookie } from "./session-cookie.js";
198
199
  export { toSafeNextPath } from "./safe-next-path.js";
199
200
  export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,2DAA2D;AAC3D,eAAO,MAAM,0BAA0B,6BAA6B,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AAEjF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQ+B,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAwCf,CAAC;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,QAAQ,EACR,UAAU,EACV,eAAe,EACf,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3F,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3I,OAAO,EAAE,0BAA0B,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC7H,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;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BAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Public API of @softure-ai/auth: the module factory for softure.config.ts, its types, messages and
2
2
  // tables, and the development reset sender. Database work is in `@softure-ai/auth/server`, the Next.js adapter in `/next`, the route
3
- // guard in `/proxy`, the forms in `/ui` and the role scripts in `/scripts`.
3
+ // guard in `/proxy`, the reset job in `/jobs`, the forms in `/ui` and the role scripts in `/scripts`.
4
4
  import { defineModule, resolveMigrationsDir } from "@softure-ai/core";
5
5
  import { authMessages } from "./messages/index.js";
6
6
  import { authOptionsSchema } from "./options.js";
@@ -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.2.1",
39
+ version: "0.2.3",
40
40
  dependsOn: { security: "^0.2.0", mailing: "^0.2.0?", ops: "^0.2.0?", jobs: "^0.1.1?" },
41
41
  dbSchema: "auth",
42
42
  tables: ["users", "sessions", "user_roles", "password_resets"],
@@ -76,7 +76,7 @@ export const auth = defineModule({
76
76
  });
77
77
  export { INITIAL_AUTH_FORM_STATE } from "./contract.js";
78
78
  export { authMessages, getAuthErrorMessage } from "./messages/index.js";
79
- export { consolePasswordResetSender } from "./password-reset-sender.js";
79
+ export { consolePasswordResetSender, } from "./password-reset-sender.js";
80
80
  export { getSessionCookie } from "./session-cookie.js";
81
81
  export { toSafeNextPath } from "./safe-next-path.js";
82
82
  export { ADMIN_ROLE, ROLE_NAME_PATTERN } from "./roles.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"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AE,GAAG,EAAE,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;IAC5E,OAAO,EAAE,sBAAsB;IAC/B,MAAM,EAAE,eAAe;CACxB,CAAC,CAAC;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAWxD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAqB,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EACL,0BAA0B,GAI3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,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"}
@@ -14,4 +14,5 @@ export declare const authJobSchedules: {
14
14
  every: string;
15
15
  };
16
16
  };
17
+ export { enqueuePasswordReset, PASSWORD_RESET_QUEUE, passwordResetJobHandler, passwordResetJobHandlers } from "./password-reset-job.js";
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAQA,mEAAmE;AACnE,eAAO,MAAM,eAAe;IAC1B,kDAAkD;;IAQlD,oEAAoE;;CAQ/C,CAAC;AAExB,wGAAwG;AACxG,eAAO,MAAM,gBAAgB;;;;;;;CAGA,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAQA,mEAAmE;AACnE,eAAO,MAAM,eAAe;IAC1B,kDAAkD;;IAQlD,oEAAoE;;CAQ/C,CAAC;AAExB,wGAAwG;AACxG,eAAO,MAAM,gBAAgB;;;;;;;CAGA,CAAC;AAE9B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -1,5 +1,5 @@
1
- // The jobs adapter of @softure-ai/auth: its prune functions as `@softure-ai/jobs` handlers and schedules (an optional
2
- // peer dependency; only apps that import this entry need it).
1
+ // The jobs adapter of @softure-ai/auth: its prune functions as `@softure-ai/jobs` handlers and schedules, and the
2
+ // password reset mail sent by a job with retry (an optional peer dependency; only apps that import this entry need it).
3
3
  import { ok } from "@softure-ai/core";
4
4
  import { defineJobHandler } from "@softure-ai/jobs";
5
5
  import { z } from "zod";
@@ -29,4 +29,5 @@ export const authJobSchedules = {
29
29
  "auth.prune-sessions": { every: "1h" },
30
30
  "auth.prune-password-resets": { every: "1d" },
31
31
  };
32
+ export { enqueuePasswordReset, PASSWORD_RESET_QUEUE, passwordResetJobHandler, passwordResetJobHandlers } from "./password-reset-job.js";
32
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,8DAA8D;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAA4C,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,mEAAmE;AACnE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,kDAAkD;IAClD,qBAAqB,EAAE,gBAAgB,CAAC;QACtC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QACrB,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YACzB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CAAC,MAAM,CAAC,EAAE,CAAC;QACrB,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC/B,OAAO,EAAE,EAAE,CAAC;QACd,CAAC;KACF,CAAC;CACmB,CAAC;AAExB,wGAAwG;AACxG,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,qBAAqB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;IACtC,4BAA4B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;CAClB,CAAC;AAE9B,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type JobHandlers } from "@softure-ai/jobs";
2
+ import type { PasswordResetEnqueuer } from "../password-reset-sender.js";
3
+ /** The queue of the reset job; define it in `jobs({ queues })`. */
4
+ export declare const PASSWORD_RESET_QUEUE = "auth.password-reset";
5
+ /**
6
+ * `auth({ passwordReset: { send, enqueue: enqueuePasswordReset } })`: enqueues `{ userId }` on
7
+ * `auth.password-reset`. While a job of the account is pending, a new request joins it.
8
+ */
9
+ export declare const enqueuePasswordReset: PasswordResetEnqueuer;
10
+ /**
11
+ * Issues the link and calls `passwordReset.send`. A gone account ends the job without a mail; a
12
+ * failing sender is logged by its label (never the link) and retried with the queue's backoff.
13
+ */
14
+ export declare const passwordResetJobHandler: import("@softure-ai/jobs").JobHandler<{
15
+ userId: string;
16
+ }>;
17
+ /** The reset job for the worker, next to the prune handlers: `handlers: { ...authJobHandlers, ...passwordResetJobHandlers }`. */
18
+ export declare const passwordResetJobHandlers: JobHandlers;
19
+ //# sourceMappingURL=password-reset-job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset-job.d.ts","sourceRoot":"","sources":["../../src/jobs/password-reset-job.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAIzE,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,wBAAwB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,qBAElC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;EAYlC,CAAC;AAEH,iIAAiI;AACjI,eAAO,MAAM,wBAAwB,EAAE,WAAiE,CAAC"}
@@ -0,0 +1,41 @@
1
+ // The password reset job: the request enqueues the account's id (never the address or a token), and
2
+ // the handler issues a fresh link and calls the app's sender. Only the token's hash is stored, so the
3
+ // link cannot be rebuilt from the database: every attempt issues a new one, which replaces the last.
4
+ // A retry after a send that was not recorded therefore mails a second link, and only the newer works.
5
+ import { err, errorLogLabel, ok } from "@softure-ai/core";
6
+ import { defineJobHandler, failJob } from "@softure-ai/jobs";
7
+ import { enqueueJob } from "@softure-ai/jobs/server";
8
+ import { z } from "zod";
9
+ import { getAuthOptions } from "../server/options.js";
10
+ import { sendPasswordReset } from "../server/password-reset.js";
11
+ /** The queue of the reset job; define it in `jobs({ queues })`. */
12
+ export const PASSWORD_RESET_QUEUE = "auth.password-reset";
13
+ /**
14
+ * `auth({ passwordReset: { send, enqueue: enqueuePasswordReset } })`: enqueues `{ userId }` on
15
+ * `auth.password-reset`. While a job of the account is pending, a new request joins it.
16
+ */
17
+ export const enqueuePasswordReset = async (ctx, userId) => {
18
+ await enqueueJob(ctx, { queue: PASSWORD_RESET_QUEUE, payload: { userId }, dedupKey: userId });
19
+ };
20
+ /**
21
+ * Issues the link and calls `passwordReset.send`. A gone account ends the job without a mail; a
22
+ * failing sender is logged by its label (never the link) and retried with the queue's backoff.
23
+ */
24
+ export const passwordResetJobHandler = defineJobHandler({
25
+ payload: z.object({ userId: z.uuid() }),
26
+ run: async ({ userId }, ctx) => {
27
+ if (getAuthOptions(ctx.config).passwordReset.send === undefined)
28
+ return failJob("auth.password_reset_unavailable");
29
+ try {
30
+ await sendPasswordReset(ctx, userId);
31
+ }
32
+ catch (error) {
33
+ console.error(`@softure-ai/auth: the password reset job failed: ${errorLogLabel(error)}`);
34
+ return err("auth.password_reset_send_failed");
35
+ }
36
+ return ok();
37
+ },
38
+ });
39
+ /** The reset job for the worker, next to the prune handlers: `handlers: { ...authJobHandlers, ...passwordResetJobHandlers }`. */
40
+ export const passwordResetJobHandlers = { [PASSWORD_RESET_QUEUE]: passwordResetJobHandler };
41
+ //# sourceMappingURL=password-reset-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-reset-job.js","sourceRoot":"","sources":["../../src/jobs/password-reset-job.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,sGAAsG;AACtG,qGAAqG;AACrG,sGAAsG;AACtG,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAoB,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;IAC/E,MAAM,UAAU,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AAChG,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,gBAAgB,CAAC;IACtD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;IACvC,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE;QAC7B,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC,iCAAiC,CAAC,CAAC;QACnH,IAAI,CAAC;YACH,MAAM,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,oDAAoD,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1F,OAAO,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;CACF,CAAC,CAAC;AAEH,iIAAiI;AACjI,MAAM,CAAC,MAAM,wBAAwB,GAAgB,EAAE,CAAC,oBAAoB,CAAC,EAAE,uBAAuB,EAAE,CAAC"}
package/dist/options.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { ModuleContext, SoftureConfig } from "@softure-ai/core";
2
2
  import type { Queryable } from "@softure-ai/db";
3
3
  import { z } from "zod";
4
4
  import type { RegisteredEvent } from "./contract.js";
5
- import type { PasswordResetSender } from "./password-reset-sender.js";
5
+ import type { PasswordResetEnqueuer, PasswordResetSender } from "./password-reset-sender.js";
6
6
  /**
7
7
  * OWASP's scrypt cost for passwords: N = 2^17, r = 8, p = 1. One hash takes 128 * N * r bytes
8
8
  * (128 MiB) and about 0.4 s of a core; Node runs up to four at once on its libuv pool, so a burst of
@@ -60,6 +60,7 @@ export declare const authOptionsSchema: z.ZodObject<{
60
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
+ enqueue: z.ZodOptional<z.ZodCustom<PasswordResetEnqueuer, PasswordResetEnqueuer>>;
63
64
  ttlMinutes: z.ZodDefault<z.ZodNumber>;
64
65
  }, z.core.$strict>>;
65
66
  onRegistered: z.ZodOptional<z.ZodCustom<OnRegisteredHook, OnRegisteredHook>>;
@@ -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,OAAO,CAAC,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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AahB,CAAC;AAyBH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8F5B,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
@@ -122,6 +122,11 @@ export const authOptionsSchema = z.strictObject({
122
122
  .strictObject({
123
123
  /** Delivers reset links. Without it password reset is off: no link, and its pages are not found. */
124
124
  send: z.custom((value) => typeof value === "function", "must be a function").optional(),
125
+ /**
126
+ * Sends the link from a background job instead of the request (`enqueuePasswordReset` of
127
+ * `@softure-ai/auth/jobs`): the job's handler issues the link and calls `send`, with retry.
128
+ */
129
+ enqueue: z.custom((value) => typeof value === "function", "must be a function").optional(),
125
130
  /** How long a reset link works. */
126
131
  ttlMinutes: z.number().int().min(5).max(1440).default(60),
127
132
  })
@@ -131,6 +136,9 @@ export const authOptionsSchema = z.strictObject({
131
136
  /** Rewrites the path of every auth redirect (e.g. `tagRedirect` from `@softure-ai/analytics/next`). */
132
137
  rewriteRedirect: z.custom((value) => typeof value === "function", "must be a function").optional(),
133
138
  }).superRefine((options, context) => {
139
+ if (options.passwordReset.enqueue !== undefined && options.passwordReset.send === undefined) {
140
+ context.addIssue({ code: "custom", path: ["passwordReset", "enqueue"], message: "needs passwordReset.send, which the job calls" });
141
+ }
134
142
  const legacy = options.legacySession?.cookieName;
135
143
  const base = options.cookie.name;
136
144
  if (legacy !== undefined && [base, `__Host-${base}`, `__Secure-${base}`].includes(legacy)) {
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MA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AQ,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"}
@@ -1,4 +1,5 @@
1
- import type { Locale } from "@softure-ai/core";
1
+ import type { Locale, ModuleContext } from "@softure-ai/core";
2
+ import type { Queryable } from "@softure-ai/db";
2
3
  import type { AuthUser } from "./contract.js";
3
4
  export interface PasswordResetDetails {
4
5
  /** When the link stops working. */
@@ -18,4 +19,10 @@ export type PasswordResetSender = (link: string, user: AuthUser, details: Passwo
18
19
  * production, where a reset link in the logs would be a live credential in the logs.
19
20
  */
20
21
  export declare const consolePasswordResetSender: PasswordResetSender;
22
+ /**
23
+ * Hands a reset to a background job instead of sending it in the request: `enqueuePasswordReset` of
24
+ * `@softure-ai/auth/jobs` enqueues `{ userId }` on the `auth.password-reset` queue, whose handler issues
25
+ * the link and calls the sender with retry. `ctx.db` is the request's database.
26
+ */
27
+ export type PasswordResetEnqueuer = (ctx: ModuleContext<Queryable>, userId: string) => Promise<void>;
21
28
  //# sourceMappingURL=password-reset-sender.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"password-reset-sender.d.ts","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,mBAQxC,CAAC"}
1
+ {"version":3,"file":"password-reset-sender.d.ts","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,mBAQxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"password-reset-sender.js","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IACrF,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,+HAA+H,CAAC,CAC3I,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,KAAK,iBAAiB,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACjI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC,CAAC"}
1
+ {"version":3,"file":"password-reset-sender.js","sourceRoot":"","sources":["../src/password-reset-sender.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IACrF,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,+HAA+H,CAAC,CAC3I,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,KAAK,iBAAiB,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACjI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type Clock, type SoftureConfig } from "@softure-ai/core";
2
+ import { type OpsScript } from "@softure-ai/ops/scripts";
3
+ export interface CreateAccountScriptArgs {
4
+ readonly email: string;
5
+ /** A hash from `hashPassword`, computed where the password was made; the script then draws none. */
6
+ readonly "password-hash"?: string;
7
+ }
8
+ export interface CreateAccountScriptOptions {
9
+ /** The time stored as `created_at` and `password_changed_at`; the system clock by default. */
10
+ readonly clock?: Clock;
11
+ /** The characters a drawn password uses (e.g. `READABLE_PASSWORD_ALPHABET`); base64url by default. */
12
+ readonly alphabet?: string;
13
+ /** The most accounts the app holds (e.g. 1 for a single-owner app); the script refuses beyond it. No limit by default. */
14
+ readonly maxAccounts?: number;
15
+ }
16
+ /** `create-account --email=… [--password-hash=…]`: a new account, with or without registration open. */
17
+ export declare function createCreateAccountScript(config: SoftureConfig, options?: CreateAccountScriptOptions): OpsScript<CreateAccountScriptArgs>;
18
+ //# sourceMappingURL=create-account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-account.d.ts","sourceRoot":"","sources":["../../src/scripts/create-account.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAO3F,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,oGAAoG;IACpG,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,0BAA0B;IACzC,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,0HAA0H;IAC1H,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAOD,wGAAwG;AACxG,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,0BAA+B,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAkC7I"}
@@ -0,0 +1,56 @@
1
+ // The first account of an app whose registration is closed: a safe ops script
2
+ // (`@softure-ai/ops/scripts`), dry run by default, `--commit` writes. It creates the account with a
3
+ // drawn temporary password, printed once, or with a `hashPassword` hash computed elsewhere
4
+ // (`--password-hash`, best through `--password-hash-file=-`). With `maxAccounts` it refuses once the
5
+ // table holds that many accounts; the table is locked for the run, so two runs cannot both pass.
6
+ // The app's `onRegistered` hook does not run: nobody gave consent and there are no registration
7
+ // fields. Reports carry the user id, never the email or the hash.
8
+ import { ok, systemClock } from "@softure-ai/core";
9
+ import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
10
+ import { count, sql } from "drizzle-orm";
11
+ import { z } from "zod";
12
+ import { users } from "../schema.js";
13
+ import { parseEmail } from "../server/validation.js";
14
+ import { choosePassword, describeChosenPassword, PASSWORD_HASH_KEY, PASSWORD_HASH_USAGE, passwordHashArg } from "./password-choice.js";
15
+ const scriptArgs = z.strictObject({
16
+ email: z.string().min(1, "--email=<account email> is required"),
17
+ [PASSWORD_HASH_KEY]: passwordHashArg,
18
+ });
19
+ /** `create-account --email=… [--password-hash=…]`: a new account, with or without registration open. */
20
+ export function createCreateAccountScript(config, options = {}) {
21
+ const { maxAccounts } = options;
22
+ if (maxAccounts !== undefined && !(Number.isInteger(maxAccounts) && maxAccounts >= 1)) {
23
+ throw new Error("@softure-ai/auth: createCreateAccountScript needs maxAccounts to be a whole number of at least 1");
24
+ }
25
+ const clock = options.clock ?? systemClock;
26
+ return defineOpsScript({
27
+ name: "create-account",
28
+ description: "Creates an account with the given email and a random password (or the given hash), also while registration is closed.",
29
+ usage: ["--email=<account email>", PASSWORD_HASH_USAGE],
30
+ args: scriptArgs,
31
+ secrets: [PASSWORD_HASH_KEY],
32
+ run: async (tx, args) => {
33
+ const email = parseEmail(args.email);
34
+ if (!email.ok)
35
+ return refuseOpsScript("the email is not valid");
36
+ // Conflicts with itself and with every insert, until the script's transaction ends.
37
+ await tx.execute(sql `LOCK TABLE auth.users IN SHARE ROW EXCLUSIVE MODE`);
38
+ const [counted] = await tx.select({ accounts: count() }).from(users);
39
+ const accounts = counted?.accounts ?? 0;
40
+ if (maxAccounts !== undefined && accounts >= maxAccounts) {
41
+ return refuseOpsScript(`the app already holds ${String(accounts)} account(s), its maxAccounts`);
42
+ }
43
+ const password = await choosePassword(args[PASSWORD_HASH_KEY], config, options.alphabet);
44
+ const now = clock.now();
45
+ const [created] = await tx
46
+ .insert(users)
47
+ .values({ email: email.value, passwordHash: password.hash, createdAt: now, passwordChangedAt: now })
48
+ .onConflictDoNothing({ target: users.email })
49
+ .returning({ id: users.id });
50
+ if (created === undefined)
51
+ return refuseOpsScript("an account with this email already exists");
52
+ return ok({ before: { accounts }, after: { userId: created.id, accounts: accounts + 1, ...describeChosenPassword(password) } });
53
+ },
54
+ });
55
+ }
56
+ //# sourceMappingURL=create-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-account.js","sourceRoot":"","sources":["../../src/scripts/create-account.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,oGAAoG;AACpG,2FAA2F;AAC3F,qGAAqG;AACrG,iGAAiG;AACjG,gGAAgG;AAChG,kEAAkE;AAClE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAkC,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAkB,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAiBvI,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qCAAqC,CAAC;IAC/D,CAAC,iBAAiB,CAAC,EAAE,eAAe;CACrC,CAAC,CAAC;AAEH,wGAAwG;AACxG,MAAM,UAAU,yBAAyB,CAAC,MAAqB,EAAE,UAAsC,EAAE;IACvG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,IAAI,WAAW,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CA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M,EAAE;iBACvB,MAAM,CAAC,KAAK,CAAC;iBACb,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC;iBACnG,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;iBAC5C,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/B,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,eAAe,CAAC,2CAA2C,CAAC,CAAC;YAC/F,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,sBAAsB,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;QAClI,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -1,4 +1,5 @@
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 { createCreateAccountScript, type CreateAccountScriptArgs, type CreateAccountScriptOptions } from "./create-account.js";
3
4
  export { runSeedAccount, type RunSeedAccountOptions } from "./seed-account.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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
+ {"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,yBAAyB,EAAE,KAAK,uBAAuB,EAAE,KAAK,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAC/H,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,7 +1,8 @@
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").
1
+ // `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles, set a temporary password and
2
+ // create an account, and the development seed account
3
+ // (see the README, "Roles", "Account recovery", "First account" and "Development seed").
4
4
  export { createGrantRoleScript, createRevokeRoleScript } from "./role-scripts.js";
5
5
  export { createSetTemporaryPasswordScript, } from "./temporary-password.js";
6
+ export { createCreateAccountScript } from "./create-account.js";
6
7
  export { runSeedAccount } from "./seed-account.js";
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,sDAAsD;AACtD,yFAAyF;AACzF,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA+C,MAAM,mBAAmB,CAAC;AAC/H,OAAO,EACL,gCAAgC,GAGjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAiE,MAAM,qBAAqB,CAAC;AAC/H,OAAO,EAAE,cAAc,EAA8B,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { SoftureConfig } from "@softure-ai/core";
2
+ import { z } from "zod";
3
+ export declare const PASSWORD_HASH_KEY = "password-hash";
4
+ export declare const PASSWORD_HASH_USAGE = "--password-hash=<hash> store this hashPassword() hash instead of drawing a password";
5
+ export declare const passwordHashArg: z.ZodOptional<z.ZodString>;
6
+ export type ChosenPassword = {
7
+ readonly from: "hash";
8
+ readonly hash: string;
9
+ } | {
10
+ readonly from: "drawn";
11
+ readonly hash: string;
12
+ readonly plain: string;
13
+ };
14
+ /** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
15
+ export declare function choosePassword(givenHash: string | undefined, config: SoftureConfig, alphabet: string | undefined): Promise<ChosenPassword>;
16
+ /** What a report says about the stored password: never the hash, the drawn password once. */
17
+ export declare function describeChosenPassword(password: ChosenPassword): {
18
+ passwordFrom: "hash";
19
+ } | {
20
+ temporaryPassword: string;
21
+ };
22
+ //# sourceMappingURL=password-choice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-choice.d.ts","sourceRoot":"","sources":["../../src/scripts/password-choice.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AACjD,eAAO,MAAM,mBAAmB,yFAAgG,CAAC;AAGjI,eAAO,MAAM,eAAe,4BAAmG,CAAC;AAEhI,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,6GAA6G;AAC7G,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAKhJ;AAED,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAEzH"}