@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed-account.js","sourceRoot":"","sources":["../../src/scripts/seed-account.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,oGAAoG;AACpG,mGAAmG;AACnG,EAAE;AACF,uDAAuD;AACvD,+DAA+D;AAC/D,4CAA4C;AAC5C,yDAAyD;AACzD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAkC,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAE,mBAAmB,EAAiB,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,YAAY,EAA0B,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAoB,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,IAAI,GAAG,cAAc,CAAC;AAC5B,sEAAsE;AACtE,MAAM,eAAe,GAAG,aAAa,CAAC;AAatC,MAAM,QAAQ,GAA6E;IACzF,0BAA0B,EAAE,8DAA8D;IAC1F,oBAAoB,EAAE,iCAAiC;IACvD,yBAAyB,EAAE,kDAAkD;IAC7E,wBAAwB,EAAE,iDAAiD;IAC3E,uBAAuB,EAAE,+BAA+B;CACzD,CAAC;AAEF,MAAM,aAAa,GAAc;IAC/B,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;IAChC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,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EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,gEAAgE,EAAE,CAAC;IACtI,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9E,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,gCAAgC,eAAe,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;IAC1F,CAAC;AACH,CAAC;AAED,mHAAmH;AACnH,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,KAAK,sBAAsB;QAAE,OAAO,mBAAmB,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC;IACzG,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export { changePassword, type ChangePasswordErrorCode, type ChangePasswordInput, type ChangePasswordResult } from "./change-password.js";
2
2
  export { loginUser, type LoginInput, type LoginResult } from "./login.js";
3
+ export { resolveOnlyAccount, type OnlyAccountError, type OnlyAccountErrorCode, type OnlyAccountResult, type ResolveOnlyAccountOptions, } from "./only-account.js";
3
4
  export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
4
5
  export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
5
6
  export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, type PasswordResetRequestInput, type PasswordResetRequestResult, type ResetPasswordErrorCode, type ResetPasswordInput, type ResetPasswordResult, } from "./password-reset.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAClJ,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,KAAK,i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AO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -2,6 +2,7 @@
2
2
  // (`{ db, clock, config }`) and never reads request scope; tokens and client keys come in as values.
3
3
  export { changePassword } from "./change-password.js";
4
4
  export { loginUser } from "./login.js";
5
+ export { resolveOnlyAccount, } from "./only-account.js";
5
6
  export { getAuthOptions, getAuthRoutes } from "./options.js";
6
7
  export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword } from "./password.js";
7
8
  export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, } from "./password-reset.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAqF,MAAM,sBAAsB,CA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C9E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;AAClJ,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAmE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,GAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAiC,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type Err, type Ok } from "@softure-ai/core";
2
+ import type { Queryable } from "@softure-ai/db";
3
+ export type OnlyAccountErrorCode = "auth.account_unknown" | "auth.no_account" | "auth.account_ambiguous";
4
+ /** Why there is no account to use, with a line for the person running the tool. */
5
+ export type OnlyAccountError = Err<OnlyAccountErrorCode> & {
6
+ readonly message: string;
7
+ };
8
+ export type OnlyAccountResult = Ok<string> | OnlyAccountError;
9
+ export interface ResolveOnlyAccountOptions {
10
+ readonly db: Queryable;
11
+ /** The variable that may name the account's id, e.g. `MCP_USER_ID`. */
12
+ readonly envName: string;
13
+ /** Default: `process.env`. */
14
+ readonly env?: Readonly<Record<string, string | undefined>>;
15
+ }
16
+ /**
17
+ * The id of the account `envName` names (it must exist), or, when the variable is empty or unset,
18
+ * of the only account. Refuses an unknown id, an empty database and several accounts with none named.
19
+ */
20
+ export declare function resolveOnlyAccount(options: ResolveOnlyAccountOptions): Promise<OnlyAccountResult>;
21
+ //# sourceMappingURL=only-account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"only-account.d.ts","sourceRoot":"","sources":["../../src/server/only-account.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMhD,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,GAAG,iBAAiB,GAAG,wBAAwB,CAAC;AAEzG,mFAAmF;AACnF,MAAM,MAAM,gBAAgB,GAAG,GAAG,CAAC,oBAAoB,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExF,MAAM,MAAM,iBAAiB,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC;AAE9D,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgBvG"}
@@ -0,0 +1,34 @@
1
+ // The one account a local tool acts for (a stdio MCP server, a measurement or seed script): the
2
+ // account an environment variable names, else the only account in the database. Never the first of
3
+ // several: that could be another person's data.
4
+ import { err, ok } from "@softure-ai/core";
5
+ import { eq } from "drizzle-orm";
6
+ import { users } from "../schema.js";
7
+ const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8
+ /**
9
+ * The id of the account `envName` names (it must exist), or, when the variable is empty or unset,
10
+ * of the only account. Refuses an unknown id, an empty database and several accounts with none named.
11
+ */
12
+ export async function resolveOnlyAccount(options) {
13
+ const { db, envName } = options;
14
+ const requested = (options.env ?? process.env)[envName]?.trim() ?? "";
15
+ if (requested !== "") {
16
+ const unknown = refuse("auth.account_unknown", `${envName} names no account`);
17
+ // Checked before the query: Postgres rejects a malformed uuid with an error, not an empty result.
18
+ if (!UUID_SHAPE.test(requested))
19
+ return unknown;
20
+ const [found] = await db.select({ id: users.id }).from(users).where(eq(users.id, requested)).limit(1);
21
+ return found === undefined ? unknown : ok(found.id);
22
+ }
23
+ const [only, second] = await db.select({ id: users.id }).from(users).limit(2);
24
+ if (only === undefined)
25
+ return refuse("auth.no_account", "the database has no account");
26
+ if (second !== undefined) {
27
+ return refuse("auth.account_ambiguous", `the database has several accounts; set ${envName} to the id of the one to use`);
28
+ }
29
+ return ok(only.id);
30
+ }
31
+ function refuse(code, message) {
32
+ return { ...err(code), message };
33
+ }
34
+ //# sourceMappingURL=only-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"only-account.js","sourceRoot":"","sources":["../../src/server/only-account.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,mGAAmG;AACnG,gDAAgD;AAChD,OAAO,EAAE,GAAG,EAAE,EAAE,EAAqB,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,MAAM,UAAU,GAAG,iEAAiE,CAAC;AAiBrF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAkC;IACzE,MAAM,EAAE,EAAE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ACrB,CAAC;AAED,SAAS,MAAM,CAAC,IAA0B,EAAE,OAAe;IACzD,OAAO,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC"}
@@ -1,17 +1,39 @@
1
1
  import type { Queryable } from "@softure-ai/db";
2
2
  import type { AuthUser } from "../contract.js";
3
3
  import { type ScryptParams } from "../options.js";
4
- export interface TestAccountInput {
4
+ import type { AuthContext } from "../server/sessions.js";
5
+ interface TestAccountBase {
5
6
  readonly email: string;
6
- readonly password: string;
7
+ /** The row's id (a uuid); the database draws one when absent. */
8
+ readonly id?: string;
9
+ /** `created_at` and `password_changed_at`; now when absent. */
10
+ readonly createdAt?: Date;
7
11
  /** Rows of `auth.user_roles`, e.g. `["admin"]`. */
8
12
  readonly roles?: readonly string[];
9
- /** The app's hash parameters (`getAuthOptions(config).password.scrypt`), so its login does not rehash. */
13
+ /** Run the app's `onRegistered` hook in the account's transaction. Needs a module context as the first argument. */
14
+ readonly runHooks?: boolean;
15
+ /** `event.fields` for the hook, as the register form would send the app's `registrationFields`. */
16
+ readonly fields?: Readonly<Record<string, string>>;
17
+ }
18
+ /** An account with a password, hashed here (once per password and parameters). */
19
+ export interface TestAccountInput extends TestAccountBase {
20
+ readonly password: string;
21
+ /** Hash parameters; the app's (`getAuthOptions(config).password.scrypt`) when a module context is given, else auth's default. */
10
22
  readonly scrypt?: ScryptParams;
23
+ readonly passwordHash?: never;
24
+ }
25
+ /** An account with a ready hash, stored as is. */
26
+ export interface TestAccountHashInput extends TestAccountBase {
27
+ /** A ready hash from `hashPassword`, stored as is: nothing is hashed. */
28
+ readonly passwordHash: string;
29
+ readonly password?: never;
30
+ readonly scrypt?: never;
11
31
  }
12
32
  /**
13
33
  * Creates an account and its roles in one transaction and returns it. The email is normalized as
14
- * registration normalizes it. An invalid or taken email throws: in test setup it is a bug of the test.
34
+ * registration normalizes it. An invalid or taken email, a malformed `passwordHash` or a hook that
35
+ * throws rolls everything back and throws: in test setup it is a bug of the test.
15
36
  */
16
- export declare function createTestAccount(db: Queryable, input: TestAccountInput): Promise<AuthUser>;
37
+ export declare function createTestAccount(target: Queryable | AuthContext, input: TestAccountInput | TestAccountHashInput): Promise<AuthUser>;
38
+ export {};
17
39
  //# sourceMappingURL=account.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/testing/account.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAQvE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,0GAA0G;IAC1G,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiBjG"}
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/testing/account.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAIvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASzD,UAAU,eAAe;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,oHAAoH;IACpH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,mGAAmG;IACnG,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACpD;AAED,kFAAkF;AAClF,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,iIAAiI;IACjI,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC;CAC/B;AAED,kDAAkD;AAClD,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,yEAAyE;IACzE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW,EAAE,KAAK,EAAE,gBAAgB,GAAG,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4B1I"}
@@ -1,23 +1,32 @@
1
1
  import { DEFAULT_SCRYPT_COST } from "../options.js";
2
2
  import { userRoles, users } from "../schema.js";
3
- import { hashPassword } from "../server/password.js";
3
+ import { getAuthOptions } from "../server/options.js";
4
+ import { hashPassword, isPasswordHash } from "../server/password.js";
4
5
  import { parseEmail } from "../server/validation.js";
5
6
  /** Auth's own hash parameters when the app sets none (`password.scrypt` in `auth({ ... })`). */
6
7
  const DEFAULT_SCRYPT = { cost: DEFAULT_SCRYPT_COST, blockSize: 8, parallelization: 1 };
8
+ /** One hash per password and parameters for the whole test run: scrypt is the slow part of a big suite's setup. */
9
+ const hashCache = new Map();
7
10
  /**
8
11
  * Creates an account and its roles in one transaction and returns it. The email is normalized as
9
- * registration normalizes it. An invalid or taken email throws: in test setup it is a bug of the test.
12
+ * registration normalizes it. An invalid or taken email, a malformed `passwordHash` or a hook that
13
+ * throws rolls everything back and throws: in test setup it is a bug of the test.
10
14
  */
11
- export async function createTestAccount(db, input) {
15
+ export async function createTestAccount(target, input) {
16
+ const ctx = isModuleContext(target) ? target : null;
17
+ const db = isModuleContext(target) ? target.db : target;
12
18
  const email = parseEmail(input.email);
13
19
  if (!email.ok)
14
20
  throw new Error(`createTestAccount: "${input.email}" is not a valid email`);
15
- const passwordHash = await hashPassword(input.password, input.scrypt ?? DEFAULT_SCRYPT);
16
- const now = new Date();
21
+ if (input.runHooks === true && ctx === null) {
22
+ throw new Error("createTestAccount: runHooks needs a module context ({ db, clock, config }) instead of a database");
23
+ }
24
+ const passwordHash = await readPasswordHash(input, email.value, ctx);
25
+ const now = input.createdAt ?? new Date();
17
26
  return db.transaction(async (tx) => {
18
27
  const [row] = await tx
19
28
  .insert(users)
20
- .values({ email: email.value, passwordHash, createdAt: now, passwordChangedAt: now })
29
+ .values({ ...(input.id === undefined ? {} : { id: input.id }), email: email.value, passwordHash, createdAt: now, passwordChangedAt: now })
21
30
  .onConflictDoNothing({ target: users.email })
22
31
  .returning();
23
32
  if (row === undefined)
@@ -25,7 +34,33 @@ export async function createTestAccount(db, input) {
25
34
  const roles = input.roles ?? [];
26
35
  if (roles.length > 0)
27
36
  await tx.insert(userRoles).values(roles.map((role) => ({ userId: row.id, role, grantedAt: now })));
28
- return { id: row.id, email: row.email, createdAt: row.createdAt };
37
+ const user = { id: row.id, email: row.email, createdAt: row.createdAt };
38
+ if (input.runHooks === true && ctx !== null) {
39
+ const options = getAuthOptions(ctx.config);
40
+ const consent = options.requireConsent ? { acceptedAt: now } : null;
41
+ await options.onRegistered?.({ user, consent, fields: input.fields ?? {} }, { ...ctx, db: tx });
42
+ }
43
+ return user;
29
44
  });
30
45
  }
46
+ async function readPasswordHash(input, email, ctx) {
47
+ if (input.passwordHash !== undefined) {
48
+ if (!isPasswordHash(input.passwordHash))
49
+ throw new Error(`createTestAccount: the passwordHash for "${email}" is not a hash from hashPassword`);
50
+ return input.passwordHash;
51
+ }
52
+ const scrypt = input.scrypt ?? (ctx === null ? DEFAULT_SCRYPT : getAuthOptions(ctx.config).password.scrypt);
53
+ const key = JSON.stringify([scrypt.cost, scrypt.blockSize, scrypt.parallelization, input.password]);
54
+ let hash = hashCache.get(key);
55
+ if (hash === undefined) {
56
+ hash = hashPassword(input.password, scrypt);
57
+ hashCache.set(key, hash);
58
+ // A failed hash is not kept, so the next call tries again.
59
+ void hash.catch(() => hashCache.delete(key));
60
+ }
61
+ return hash;
62
+ }
63
+ function isModuleContext(target) {
64
+ return "config" in target && "clock" in target && "db" in target;
65
+ }
31
66
  //# sourceMappingURL=account.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/testing/account.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAqB,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,gGAAgG;AAChG,MAAM,cAAc,GAAiB,EAAE,IAAI,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;AAWrG;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EAAa,EAAE,KAAuB;IAC5E,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI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GAAG,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC5C,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACzB,2DAA2D;QAC3D,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,MAA+B;IACtD,OAAO,QAAQ,IAAI,MAAM,IAAI,OAAO,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;AACnE,CAAC"}
@@ -1,2 +1,2 @@
1
- export { createTestAccount, type TestAccountInput } from "./account.js";
1
+ export { createTestAccount, type TestAccountHashInput, type TestAccountInput } from "./account.js";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,mGAAmG;AACnG,OAAO,EAAE,iBAAiB,EAAyB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,mGAAmG;AACnG,OAAO,EAAE,iBAAiB,EAAoD,MAAM,cAAc,CAAC"}
package/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "auth",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "dependsOn": { "security": "^0.1.0", "mailing": "^0.1.0?", "ops": "^0.1.0?" },
5
5
  "dbSchema": "auth",
6
6
  "tables": ["users", "sessions", "user_roles", "password_resets"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softure-ai/auth",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "SOFTURE AI auth module: users, scrypt passwords, database sessions, register with consent, login, logout, password change, roles, a proxy route guard, pages and forms for Next.js, and a password reset sender over @softure-ai/mailing.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -74,19 +74,19 @@
74
74
  "dependencies": {
75
75
  "@softure-ai/core": "^0.1.8",
76
76
  "@softure-ai/db": "^0.1.0",
77
- "@softure-ai/security": "^0.1.0",
77
+ "@softure-ai/security": "^0.1.8",
78
78
  "zod": "^4.6.5"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "@softure-ai/mailing": "^0.1.0",
82
82
  "@softure-ai/ops": "^0.1.0",
83
- "@softure-ai/ui": "^0.1.0",
83
+ "@softure-ai/ui": "^0.1.0 || ^0.2.0",
84
84
  "drizzle-orm": "^0.45.2",
85
85
  "next": "^16.0.0",
86
86
  "react": "^19.0.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@softure-ai/ui": "^0.1.7"
89
+ "@softure-ai/ui": "^0.1.7 || ^0.2.0"
90
90
  },
91
91
  "peerDependenciesMeta": {
92
92
  "@softure-ai/mailing": {
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@
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
3
  // guard in `/proxy`, the forms in `/ui` and the role scripts in `/scripts`.
4
4
  import { defineModule, resolveMigrationsDir } from "@softure-ai/core";
5
+ import type { RateLimitBucketInput } from "@softure-ai/security";
5
6
  import { authMessages } from "./messages/index.js";
6
7
  import { authOptionsSchema } from "./options.js";
7
8
  import { checkAuthTables } from "./server/health.js";
@@ -25,14 +26,14 @@ export const REGISTRATION_CLOSED_ENV = "SOFTURE_SWITCH_AUTH_REGISTRATION_CLOSED"
25
26
  * and `password-reset-account` per email, which bounds the mails one address can receive.
26
27
  */
27
28
  export const AUTH_RATE_LIMIT_BUCKETS = {
28
- register: { limit: 5, windowMinutes: 15 },
29
- login: { limit: 50, windowMinutes: 15 },
30
- "login-account": { limit: 10, windowMinutes: 15 },
31
- "change-password": { limit: 10, windowMinutes: 15 },
32
- "password-reset": { limit: 10, windowMinutes: 15 },
33
- "password-reset-account": { limit: 3, windowMinutes: 15 },
34
- "password-reset-confirm": { limit: 10, windowMinutes: 15 },
35
- } as const;
29
+ register: { limit: 5, windowMinutes: 15, key: "ip" },
30
+ login: { limit: 50, windowMinutes: 15, key: "ip" },
31
+ "login-account": { limit: 10, windowMinutes: 15, key: "account" },
32
+ "change-password": { limit: 10, windowMinutes: 15, key: "account" },
33
+ "password-reset": { limit: 10, windowMinutes: 15, key: "ip" },
34
+ "password-reset-account": { limit: 3, windowMinutes: 15, key: "account" },
35
+ "password-reset-confirm": { limit: 10, windowMinutes: 15, key: "ip" },
36
+ } as const satisfies Readonly<Record<string, RateLimitBucketInput>>;
36
37
 
37
38
  /**
38
39
  * Enables accounts in `softure.config.ts` (next to `security({ ... })`):
@@ -41,7 +42,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
41
42
  export const auth = defineModule({
42
43
  manifest: {
43
44
  id: MODULE_ID,
44
- version: "0.1.11",
45
+ version: "0.1.13",
45
46
  dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
46
47
  dbSchema: "auth",
47
48
  tables: ["users", "sessions", "user_roles", "password_resets"],
package/src/options.ts CHANGED
@@ -63,6 +63,29 @@ const scryptSchema = z.strictObject({
63
63
  parallelization: z.number().int().min(1).max(16).default(1),
64
64
  });
65
65
 
66
+ const adminEmailSchema = z.string().trim().toLowerCase().max(MAX_EMAIL_LENGTH).pipe(z.email("must be an email address"));
67
+
68
+ /**
69
+ * `adminEmails` given as the raw environment string: entries split on commas and whitespace, trimmed and
70
+ * lowercased. One bad entry must not stop the app, so entries that are not emails are dropped with one log
71
+ * line naming their positions (never their values) and grant nothing.
72
+ */
73
+ function parseAdminEmailList(raw: string): string[] {
74
+ const entries = raw.split(/[\s,]+/).filter((entry) => entry !== "");
75
+ const emails: string[] = [];
76
+ const dropped: number[] = [];
77
+ entries.forEach((entry, index) => {
78
+ const parsed = adminEmailSchema.safeParse(entry);
79
+ if (parsed.success) emails.push(parsed.data);
80
+ else dropped.push(index + 1);
81
+ });
82
+ if (dropped.length > 0) {
83
+ const positions = dropped.join(", ");
84
+ console.warn(`@softure-ai/auth: adminEmails: ${String(dropped.length)} of ${String(entries.length)} entries are not email addresses and grant no role (positions ${positions})`);
85
+ }
86
+ return emails;
87
+ }
88
+
66
89
  export const authOptionsSchema = z.strictObject({
67
90
  password: z
68
91
  .strictObject({
@@ -128,7 +151,9 @@ export const authOptionsSchema = z.strictObject({
128
151
  * Initial admin list: while an email is listed, the account with that email holds `admin`.
129
152
  * Auth does not verify emails, so create these accounts before deploying the list.
130
153
  */
131
- adminEmails: z.array(z.string().trim().toLowerCase().max(MAX_EMAIL_LENGTH).pipe(z.email("must be an email address"))).default([]),
154
+ adminEmails: z
155
+ .union([z.array(adminEmailSchema), z.string().transform(parseAdminEmailList)], { error: "must be a list of email addresses or one string of them" })
156
+ .default([]),
132
157
  passwordReset: z
133
158
  .strictObject({
134
159
  /** Delivers reset links. Without it password reset is off: no link, and its pages are not found. */
@@ -19,6 +19,11 @@ export interface AuthGuardOptions {
19
19
  * public pages here). `"/"` here is the home page only. The change-password route stays guarded.
20
20
  */
21
21
  readonly exclude?: readonly string[];
22
+ /**
23
+ * Paths that never need a session, matched whole (`/pricing` and `/pricing/`, not `/pricing/plans`), for an app
24
+ * that protects everything except an exact allowlist. Compared decoded and lowercased, like the other lists.
25
+ */
26
+ readonly excludeExact?: readonly string[];
22
27
  /**
23
28
  * Origins besides `appOrigin` and the config's `origins.trustedOrigins` that the login redirect may stay on
24
29
  * (`https://example.com`). Prefer the config's block, which every module reads. The request's public origin
@@ -26,6 +31,12 @@ export interface AuthGuardOptions {
26
31
  * `appOrigin`.
27
32
  */
28
33
  readonly trustedOrigins?: readonly string[];
34
+ /**
35
+ * `"absolute"` (default): the login URL is built on the resolved origin (above). `"relative"`: the `Location` is
36
+ * the path only (`/login?next=…`), so the browser stays on whatever host and port it used; for a stack served on
37
+ * ports or hosts the config cannot list (an integration run on a random port).
38
+ */
39
+ readonly redirect?: "absolute" | "relative";
29
40
  }
30
41
 
31
42
  /** Mounted at a fixed path by the module (manifest `mount`); it answers `{ user: null }` without a session. */
@@ -44,10 +55,12 @@ export function createAuthGuard(config: SoftureConfig, options: AuthGuardOptions
44
55
  normalizePrefix(path, "excluded"),
45
56
  );
46
57
  const excluded = (options.exclude ?? []).map((prefix) => normalizePrefix(prefix, "excluded"));
58
+ const exactExcluded = new Set((options.excludeExact ?? []).map((path) => normalizePrefix(path, "excluded")));
47
59
  const trustedOrigins = (options.trustedOrigins ?? []).map(normalizeOrigin);
48
60
 
49
61
  const isGuarded = (path: string): boolean => {
50
62
  if (isUnder(path, changePassword)) return true;
63
+ if (exactExcluded.has(normalizeTrailingSlash(path))) return false;
51
64
  if ([...publicPaths, ...excluded].some((prefix) => isExcludedBy(path, prefix))) return false;
52
65
  return prefixes.some((prefix) => isUnder(path, prefix));
53
66
  };
@@ -64,7 +77,9 @@ export function createAuthGuard(config: SoftureConfig, options: AuthGuardOptions
64
77
  // the request URL carries an internal host, and request headers alone are never trusted.
65
78
  const login = new URL(routes.login, resolveAppOrigin(config, request, { trustedOrigins }));
66
79
  login.searchParams.set("next", `${url.pathname}${url.search}`);
67
- return Response.redirect(login, 307);
80
+ if (options.redirect !== "relative") return Response.redirect(login, 307);
81
+ // A path-only Location reads no request header at all; `Response.redirect` would need an absolute URL.
82
+ return new Response(null, { status: 307, headers: { location: `${login.pathname}${login.search}` } });
68
83
  };
69
84
  }
70
85
 
@@ -72,8 +87,11 @@ function normalizePrefix(prefix: string, kind: "protected" | "excluded"): string
72
87
  if (!prefix.startsWith("/")) {
73
88
  throw new Error(`createAuthGuard: ${kind} path "${prefix}" must start with /`);
74
89
  }
75
- const trimmed = prefix.length > 1 && prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
76
- return trimmed.toLowerCase();
90
+ return normalizeTrailingSlash(prefix).toLowerCase();
91
+ }
92
+
93
+ function normalizeTrailingSlash(path: string): string {
94
+ return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
77
95
  }
78
96
 
79
97
  /** `entry` as an origin (`https://example.com`, a trailing `/` dropped); anything else is a config error. */
@@ -1,8 +1,10 @@
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, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
4
5
  export {
5
6
  createSetTemporaryPasswordScript,
6
7
  type TemporaryPasswordScriptArgs,
7
8
  type TemporaryPasswordScriptOptions,
8
9
  } from "./temporary-password.js";
10
+ export { runSeedAccount, type RunSeedAccountOptions } from "./seed-account.js";
@@ -0,0 +1,108 @@
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, type Clock, type SoftureConfig } from "@softure-ai/core";
10
+ import { openCommandDatabase, type Database } from "@softure-ai/db";
11
+ import { EXIT_FAILED, EXIT_OK, EXIT_USAGE, type CliOutput } from "@softure-ai/db/cli";
12
+ import { registerUser, type RegisterErrorCode } from "../server/register.js";
13
+ import { logoutSession, type AuthContext } from "../server/sessions.js";
14
+ import { normalizeEmail } from "../server/validation.js";
15
+
16
+ const NAME = "seed-account";
17
+ /** The rate limit key the seed counts registration attempts under. */
18
+ const SEED_CLIENT_KEY = "script:seed";
19
+
20
+ export interface RunSeedAccountOptions {
21
+ readonly config: SoftureConfig;
22
+ /** Default: `process.env`. Reads `SEED_EMAIL`, `SEED_PASSWORD` and `NODE_ENV`. */
23
+ readonly env?: Readonly<Record<string, string | undefined>>;
24
+ /** An open database to use instead of the config's (tests); it is not closed. */
25
+ readonly database?: Database;
26
+ /** Default: the console. The password is never printed. */
27
+ readonly output?: CliOutput;
28
+ readonly clock?: Clock;
29
+ }
30
+
31
+ const REFUSALS: Readonly<Record<Exclude<RegisterErrorCode, "auth.email_taken">, string>> = {
32
+ "auth.registration_closed": "registration is closed by a switch; open it for the seed run",
33
+ "auth.email_invalid": "SEED_EMAIL is not a valid email",
34
+ "auth.password_too_short": "SEED_PASSWORD is shorter than password.minLength",
35
+ "auth.password_too_long": "SEED_PASSWORD is longer than the module accepts",
36
+ "auth.consent_required": "registration requires consent",
37
+ };
38
+
39
+ const consoleOutput: CliOutput = {
40
+ log: (line) => console.log(line),
41
+ error: (line) => console.error(line),
42
+ };
43
+
44
+ /**
45
+ * Creates the development account and returns the exit code: 0 created or already there, 1 refused
46
+ * or failed (nothing written), 2 `SEED_EMAIL` or `SEED_PASSWORD` missing.
47
+ */
48
+ export async function runSeedAccount(options: RunSeedAccountOptions): Promise<number> {
49
+ const env = options.env ?? process.env;
50
+ const output = options.output ?? consoleOutput;
51
+ const email = env.SEED_EMAIL?.trim() ?? "";
52
+ const password = env.SEED_PASSWORD ?? "";
53
+ if (email === "" || password.trim() === "") {
54
+ output.error(`${NAME}: set SEED_EMAIL and SEED_PASSWORD to the development account's email and password`);
55
+ return EXIT_USAGE;
56
+ }
57
+ if (env.NODE_ENV === "production") {
58
+ output.error(`${NAME}: refused: NODE_ENV is production; the seed account is for development`);
59
+ return EXIT_FAILED;
60
+ }
61
+
62
+ const opened = await openDatabase(options);
63
+ if (!opened.ok) {
64
+ output.error(`${NAME}: ${opened.message}`);
65
+ return EXIT_FAILED;
66
+ }
67
+ try {
68
+ const ctx: AuthContext = { db: opened.db, clock: options.clock ?? systemClock, config: options.config };
69
+ const registered = await registerUser(ctx, { email, password, hasConsented: true, clientKey: SEED_CLIENT_KEY });
70
+ if (registered.ok) {
71
+ // Registration signs the account in; the seed only wants the account.
72
+ await logoutSession(ctx, registered.value.session.token);
73
+ output.log(`${NAME}: created the account ${registered.value.user.email}`);
74
+ return EXIT_OK;
75
+ }
76
+ if (registered.error === "auth.email_taken") {
77
+ output.log(`${NAME}: ${normalizeEmail(email)} is already there; nothing changed`);
78
+ return EXIT_OK;
79
+ }
80
+ const reason = registered.error === "security.rate_limited" ? "too many registrations from the seed; wait and run it again" : REFUSALS[registered.error];
81
+ output.error(`${NAME}: refused: ${reason} (${registered.error})`);
82
+ return EXIT_FAILED;
83
+ } catch (error) {
84
+ output.error(`${NAME}: failed: ${describeFailure(error)}`);
85
+ return EXIT_FAILED;
86
+ } finally {
87
+ await opened.close();
88
+ }
89
+ }
90
+
91
+ type OpenedDatabase = { readonly ok: true; readonly db: Database; readonly close: () => Promise<void> } | { readonly ok: false; readonly message: string };
92
+
93
+ async function openDatabase(options: RunSeedAccountOptions): Promise<OpenedDatabase> {
94
+ if (options.database !== undefined) return { ok: true, db: options.database, close: () => Promise.resolve() };
95
+ if (options.config.database === null) return { ok: false, message: "the config has no database; set database.url in softure.config" };
96
+ try {
97
+ const opened = await openCommandDatabase(options.config.database, { max: 1 });
98
+ return { ok: true, db: opened.handle.db, close: opened.close };
99
+ } catch (error) {
100
+ return { ok: false, message: `could not open the database: ${describeFailure(error)}` };
101
+ }
102
+ }
103
+
104
+ /** The error message, except for database errors, whose message may carry query parameters (the password hash). */
105
+ function describeFailure(error: unknown): string {
106
+ if (safeError(error).error === "core.database_failed") return `database error (${errorLogLabel(error)})`;
107
+ return error instanceof Error ? error.message : String(error);
108
+ }
@@ -2,6 +2,13 @@
2
2
  // (`{ db, clock, config }`) and never reads request scope; tokens and client keys come in as values.
3
3
  export { changePassword, type ChangePasswordErrorCode, type ChangePasswordInput, type ChangePasswordResult } from "./change-password.js";
4
4
  export { loginUser, type LoginInput, type LoginResult } from "./login.js";
5
+ export {
6
+ resolveOnlyAccount,
7
+ type OnlyAccountError,
8
+ type OnlyAccountErrorCode,
9
+ type OnlyAccountResult,
10
+ type ResolveOnlyAccountOptions,
11
+ } from "./only-account.js";
5
12
  export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
6
13
  export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
7
14
  export {