@krizaka/auth 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,8 +23,10 @@ function memoryIdentityProvider() {
23
23
  let counter = 0;
24
24
  return {
25
25
  async start(provider, returnTo) {
26
- if (!isFederatedProvider(provider)) throw new FederationError(FEDERATION_CODE.unknownProvider, `Unknown provider ${String(provider)}`);
27
- if (!isLocalReturn(returnTo)) throw new FederationError(FEDERATION_CODE.badReturn, "That return address is not allowed");
26
+ if (!isFederatedProvider(provider))
27
+ throw new FederationError(FEDERATION_CODE.unknownProvider, `Unknown provider ${String(provider)}`);
28
+ if (!isLocalReturn(returnTo))
29
+ throw new FederationError(FEDERATION_CODE.badReturn, "That return address is not allowed");
28
30
  counter += 1;
29
31
  const state = `state-${counter}`;
30
32
  return { url: `https://auth.test/${provider}/start?state=${state}`, state };
@@ -33,7 +35,8 @@ function memoryIdentityProvider() {
33
35
  const entry = pending.get(code);
34
36
  pending.delete(code);
35
37
  if (!entry) throw new FederationError(FEDERATION_CODE.invalidCode, "That code is not valid");
36
- if (entry.challenge !== null && (!options.codeVerifier || pkceChallenge(options.codeVerifier) !== entry.challenge)) throw new FederationError(FEDERATION_CODE.invalidCode, "That code is not valid");
38
+ if (entry.challenge !== null && (!options.codeVerifier || pkceChallenge(options.codeVerifier) !== entry.challenge))
39
+ throw new FederationError(FEDERATION_CODE.invalidCode, "That code is not valid");
37
40
  return entry.identity;
38
41
  },
39
42
  issue(identity, challenge) {
@@ -212,7 +215,10 @@ function identityLinksMigration() {
212
215
  function dbIdentityLinks(query) {
213
216
  return {
214
217
  async find(issuer, subject) {
215
- const [row] = await query("SELECT account_id FROM external_identities WHERE issuer = $1 AND subject = $2", [issuer, subject]);
218
+ const [row] = await query(
219
+ "SELECT account_id FROM external_identities WHERE issuer = $1 AND subject = $2",
220
+ [issuer, subject]
221
+ );
216
222
  return row?.account_id ?? null;
217
223
  },
218
224
  async link(accountId, issuer, subject, now) {
@@ -225,11 +231,17 @@ function dbIdentityLinks(query) {
225
231
  if (rows.length === 0) throw new IdentityLinkError();
226
232
  },
227
233
  async unlink(accountId, issuer, subject) {
228
- const rows = await query("DELETE FROM external_identities WHERE issuer = $1 AND subject = $2 AND account_id = $3 RETURNING 1", [issuer, subject, accountId]);
234
+ const rows = await query(
235
+ "DELETE FROM external_identities WHERE issuer = $1 AND subject = $2 AND account_id = $3 RETURNING 1",
236
+ [issuer, subject, accountId]
237
+ );
229
238
  return rows.length > 0;
230
239
  },
231
240
  async list(accountId) {
232
- const rows = await query("SELECT issuer, subject, linked_at FROM external_identities WHERE account_id = $1 ORDER BY linked_at, issuer, subject", [accountId]);
241
+ const rows = await query(
242
+ "SELECT issuer, subject, linked_at FROM external_identities WHERE account_id = $1 ORDER BY linked_at, issuer, subject",
243
+ [accountId]
244
+ );
233
245
  return rows.map((r) => ({ issuer: r.issuer, subject: r.subject, linkedAt: r.linked_at }));
234
246
  }
235
247
  };
@@ -252,4 +264,4 @@ export {
252
264
  identityLinksMigration,
253
265
  dbIdentityLinks
254
266
  };
255
- //# sourceMappingURL=chunk-5CFOMWBN.js.map
267
+ //# sourceMappingURL=chunk-2QUHBEBL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/federation.ts","../src/schema.ts","../src/identity-links.ts"],"sourcesContent":["import crypto from \"node:crypto\";\n\n/**\n * Federated sign-in (Google, Apple, Facebook, a native app's PKCE) delegated to krizaka-users, behind a PORT. The product keeps its\n * own accounts (`postgresAccounts`); this port only answers « who is this person, according to the provider ». An external\n * identity is never a second user table: it is a link to an account the product already has.\n */\nexport type FederatedProvider = \"google\" | \"apple\" | \"facebook\";\n\n/** The providers the port knows; anything else is refused before it reaches the adapter. */\nexport const FEDERATED_PROVIDERS: readonly FederatedProvider[] = [\"google\", \"apple\", \"facebook\"];\n\nexport const isFederatedProvider = (value: unknown): value is FederatedProvider =>\n FEDERATED_PROVIDERS.includes(value as FederatedProvider);\n\n/** Who the provider says the person is. `issuer` + `subject` identify them for good; the address can change. */\nexport interface ExternalIdentity {\n /** The authority that vouches (`https://accounts.google.com`, `https://appleid.apple.com`…). */\n issuer: string;\n /** The person's stable id at that authority. */\n subject: string;\n email: string | null;\n /** The provider checked the address (a Facebook address, for one, may not be). */\n emailVerified: boolean;\n name: string | null;\n}\n\n/** What a sign-in is started with: a native app sends the PKCE challenge, a browser flow does not. */\nexport interface StartOptions {\n /** The S256 challenge of a PKCE flow (a native app); the matching verifier goes to `complete`. */\n codeChallenge?: string;\n}\n\nexport interface StartedSignIn {\n /** Where to send the person: the provider's consent page, through krizaka-users. */\n url: string;\n /** Echoed back with the code: the product checks it against the one it kept for this browser. */\n state: string;\n}\n\nexport interface CompleteOptions {\n /** The PKCE verifier of the challenge given to `start`. */\n codeVerifier?: string;\n}\n\nexport interface IdentityProvider {\n /** Starts a sign-in with `provider`; the person comes back to `returnTo` (a path or an address the adapter allows) with a one-time code. */\n start(provider: FederatedProvider, returnTo: string, options?: StartOptions): Promise<StartedSignIn>;\n /** Exchanges the one-time code (single use) for the verified identity. Throws `FederationError(\"INVALID_CODE\")` for a code that is unknown, used or expired. */\n complete(code: string, options?: CompleteOptions): Promise<ExternalIdentity>;\n}\n\nexport const FEDERATION_CODE = {\n invalidCode: \"INVALID_CODE\",\n unknownProvider: \"UNKNOWN_PROVIDER\",\n badReturn: \"BAD_RETURN_TO\",\n unavailable: \"UNAVAILABLE\",\n} as const;\nexport type FederationCode = (typeof FEDERATION_CODE)[keyof typeof FEDERATION_CODE];\n\nexport class FederationError extends Error {\n constructor(\n readonly code: FederationCode,\n message: string,\n ) {\n super(message);\n this.name = \"FederationError\";\n }\n}\n\n/** The S256 challenge of a PKCE verifier: base64url(SHA-256(verifier)). A native app computes it; the adapter and the in-memory provider check it. */\nexport const pkceChallenge = (verifier: string): string =>\n crypto.createHash(\"sha256\").update(verifier).digest(\"base64url\");\n\n/** A return address stays on the product: a path (`/fr/account`), never `//host` or a scheme. */\nexport const isLocalReturn = (returnTo: string): boolean =>\n returnTo.startsWith(\"/\") &&\n !returnTo.startsWith(\"//\") &&\n !returnTo.includes(\"\\\\\") &&\n [...returnTo].every((c) => c.charCodeAt(0) > 31);\n\n/** An in-memory provider: the tests' adapter, and the reference the contract is written against. */\nexport function memoryIdentityProvider(): IdentityProvider & {\n /** Test seam: the one-time code the provider would hand back for this identity (with the PKCE challenge it was started with, if any). */\n issue(identity: ExternalIdentity, challenge?: string): string;\n} {\n const pending = new Map<string, { identity: ExternalIdentity; challenge: string | null }>();\n let counter = 0;\n return {\n async start(provider, returnTo) {\n if (!isFederatedProvider(provider))\n throw new FederationError(FEDERATION_CODE.unknownProvider, `Unknown provider ${String(provider)}`);\n if (!isLocalReturn(returnTo))\n throw new FederationError(FEDERATION_CODE.badReturn, \"That return address is not allowed\");\n counter += 1;\n const state = `state-${counter}`;\n return { url: `https://auth.test/${provider}/start?state=${state}`, state };\n },\n async complete(code, options = {}) {\n const entry = pending.get(code);\n pending.delete(code); // single use, whatever happens next\n if (!entry) throw new FederationError(FEDERATION_CODE.invalidCode, \"That code is not valid\");\n if (\n entry.challenge !== null &&\n (!options.codeVerifier || pkceChallenge(options.codeVerifier) !== entry.challenge)\n )\n throw new FederationError(FEDERATION_CODE.invalidCode, \"That code is not valid\");\n return entry.identity;\n },\n issue(identity, challenge) {\n counter += 1;\n pending.set(`code-${counter}`, { identity, challenge: challenge ?? null });\n return `code-${counter}`;\n },\n };\n}\n","import { defineModule, type ModuleSchema } from \"@krizaka/db\";\n\n/**\n * The tables of « auth », declared as modules (ADR-001 §3). They are added to a product's own `accounts` and `sessions` tables, which\n * existed before the module schemas: they stay in `public`, un-qualified, and a product that has them adopts version 1\n * (`adoptMigration`, markers only) while one that does not emits it (`emitMigration`). Version 1 of each is frozen once released:\n * a change is version 2. The one product table every one of them references is declared by the product (`accounts`, `owner`).\n */\n\n/**\n * What the account adapter needs from a product's database, safe to run on a database that already has `accounts` and `sessions`:\n * a display name, a theme, an avatar seed, the verified-address flag, and the table of e-mail changes (a link mailed to the NEW\n * address) and the table of password resets (a link mailed to the account's address). `accounts` needs `id`, `email`, `locale`, `password_hash`;\n * `sessions` needs `account_id`, `created_at`, `expires_at`, `ip`, `user_agent`.\n * @param options `backfillVerified`: for accounts that exist already, treat the address as verified (invitation-only products)\n */\nexport function accountsSchema(options: { backfillVerified?: boolean } = {}): ModuleSchema {\n return defineModule({\n module: \"auth\",\n schema: \"public\",\n tables: [\"accounts\"],\n migrations: [\n {\n version: 1,\n name: \"accounts profile, e-mail changes, password resets\",\n sql: (c) => `\nALTER TABLE ${c.tables.accounts} ADD COLUMN IF NOT EXISTS name text CHECK (name IS NULL OR char_length(name) <= 80);\nALTER TABLE ${c.tables.accounts} ADD COLUMN IF NOT EXISTS avatar_seed text CHECK (avatar_seed IS NULL OR avatar_seed ~ '^[a-z0-9-]{1,40}$');\nALTER TABLE ${c.tables.accounts} ADD COLUMN IF NOT EXISTS theme text CHECK (theme IS NULL OR theme IN ('light', 'dark', 'system'));\nALTER TABLE ${c.tables.accounts} ADD COLUMN IF NOT EXISTS email_verified_at timestamptz;\n${options.backfillVerified ? `UPDATE ${c.tables.accounts} SET email_verified_at = created_at WHERE email_verified_at IS NULL;\\n` : \"\"}CREATE TABLE IF NOT EXISTS email_changes (\n id uuid PRIMARY KEY DEFAULT gen_random_uuid(),\n account_id uuid NOT NULL REFERENCES ${c.tables.accounts}(id) ON DELETE CASCADE,\n new_email text NOT NULL CHECK (new_email = lower(new_email)),\n token_hash text NOT NULL UNIQUE,\n created_at timestamptz NOT NULL DEFAULT now(),\n expires_at timestamptz NOT NULL,\n used_at timestamptz\n);\nCREATE TABLE IF NOT EXISTS password_resets (\n id uuid PRIMARY KEY DEFAULT gen_random_uuid(),\n account_id uuid NOT NULL REFERENCES ${c.tables.accounts}(id) ON DELETE CASCADE,\n token_hash text NOT NULL UNIQUE,\n created_at timestamptz NOT NULL DEFAULT now(),\n expires_at timestamptz NOT NULL,\n used_at timestamptz\n);\n`,\n },\n ],\n });\n}\n\nconst IDENT = /^[a-z_][a-z0-9_]{0,62}$/;\nconst ident = (name: string) => {\n if (!IDENT.test(name)) throw new Error(`not a safe SQL identifier: ${name}`);\n return name;\n};\n\n/**\n * Memberships (who has which role in which scope) and invitations (an e-mail address invited with a role, by a link used once), from the\n * product's role model. Declares the account table (`owner`) and, when the roles are scoped, the scope table (`scope`: shops, workspaces):\n * a membership and an invitation then point at it. Idempotent.\n * @param roles the role names of the model: each becomes a value of the `role` check, so each must be a safe identifier\n * @param options `scoped`: true when the product declares a `scope` table\n * @throws Error for a role that is not a safe SQL identifier\n */\nexport function rolesSchema(roles: readonly string[], options: { scoped?: boolean } = {}): ModuleSchema {\n const list = roles.map((r) => `'${ident(r)}'`).join(\", \");\n return defineModule({\n module: \"auth_roles\",\n schema: \"public\",\n tables: options.scoped ? [\"owner\", \"scope\"] : [\"owner\"],\n migrations: [\n {\n version: 1,\n name: \"memberships and invitations\",\n sql: (c) => {\n const scope = options.scoped ? ` REFERENCES ${c.tables.scope}(id) ON DELETE CASCADE` : \"\";\n return `\nCREATE TABLE IF NOT EXISTS memberships (\n scope_id uuid NOT NULL${scope},\n account_id uuid NOT NULL REFERENCES ${c.tables.owner}(id) ON DELETE CASCADE,\n role text NOT NULL CHECK (role IN (${list})),\n invited_by uuid REFERENCES ${c.tables.owner}(id) ON DELETE SET NULL,\n created_at timestamptz NOT NULL,\n PRIMARY KEY (scope_id, account_id)\n);\nCREATE INDEX IF NOT EXISTS memberships_account ON memberships(account_id);\nCREATE TABLE IF NOT EXISTS invitations (\n id uuid PRIMARY KEY,\n scope_id uuid NOT NULL${scope},\n email text NOT NULL CHECK (email = lower(email)),\n role text NOT NULL CHECK (role IN (${list})),\n token_hash text NOT NULL UNIQUE,\n invited_by uuid REFERENCES ${c.tables.owner}(id) ON DELETE SET NULL,\n created_at timestamptz NOT NULL,\n expires_at timestamptz NOT NULL,\n used_at timestamptz\n);\nCREATE INDEX IF NOT EXISTS invitations_scope ON invitations(scope_id) WHERE used_at IS NULL;\n`;\n },\n },\n ],\n });\n}\n\n/** Which external identity belongs to which account (federated sign-in): `(issuer, subject) → account`, never a second user table. Idempotent. */\nexport const identityLinksSchema = defineModule({\n module: \"auth_identity_links\",\n schema: \"public\",\n tables: [\"accounts\"],\n migrations: [\n {\n version: 1,\n name: \"external identities\",\n sql: (c) => `\nCREATE TABLE IF NOT EXISTS external_identities (\n issuer text NOT NULL CHECK (char_length(issuer) BETWEEN 1 AND 200),\n subject text NOT NULL CHECK (char_length(subject) BETWEEN 1 AND 200),\n account_id uuid NOT NULL REFERENCES ${c.tables.accounts}(id) ON DELETE CASCADE,\n linked_at timestamptz NOT NULL,\n PRIMARY KEY (issuer, subject)\n);\nCREATE INDEX IF NOT EXISTS external_identities_account ON external_identities(account_id, linked_at);\n`,\n },\n ],\n});\n\n/**\n * The table of web sessions: the cookie holds a random token, the table its keyed hash (a leaked table opens nothing). The shape the\n * products' own `sessions` table has, so a product that has it adopts version 1 (`adoptMigration`) and one that does not emits it.\n * Idempotent.\n */\nexport const sessionsSchema = defineModule({\n module: \"auth_sessions\",\n schema: \"public\",\n tables: [\"accounts\"],\n migrations: [\n {\n version: 1,\n name: \"sessions\",\n sql: (c) => `\nCREATE TABLE IF NOT EXISTS sessions (\n id uuid PRIMARY KEY DEFAULT gen_random_uuid(),\n account_id uuid NOT NULL REFERENCES ${c.tables.accounts}(id) ON DELETE CASCADE,\n token_hash text NOT NULL UNIQUE,\n created_at timestamptz NOT NULL DEFAULT now(),\n expires_at timestamptz NOT NULL,\n ip text,\n user_agent text\n);\nCREATE INDEX IF NOT EXISTS sessions_account ON sessions(account_id);\n`,\n },\n ],\n});\n","import { compareAsc } from \"date-fns\";\n\nimport type { Query } from \"./accounts\";\nimport { identityLinksSchema } from \"./schema\";\n\n/**\n * Which external identity belongs to which account. Never a second user table: a row is only `(issuer, subject) → account`.\n * The product's `accounts` stays the one place a person lives.\n */\nexport interface IdentityLinkStore {\n /** The account this external identity is linked to, or null. */\n find(issuer: string, subject: string): Promise<string | null>;\n /** Links it. Idempotent for the same account; throws when the identity is already linked to another one. */\n link(accountId: string, issuer: string, subject: string, now: Date): Promise<void>;\n /** Removes the link (the person unlinks Google); true when there was one. */\n unlink(accountId: string, issuer: string, subject: string): Promise<boolean>;\n /** The identities linked to an account, oldest first. */\n list(accountId: string): Promise<{ issuer: string; subject: string; linkedAt: Date }[]>;\n}\n\nexport class IdentityLinkError extends Error {\n readonly code = \"ALREADY_LINKED\";\n constructor() {\n super(\"That external identity is already linked to another account\");\n this.name = \"IdentityLinkError\";\n }\n}\n\n/** An in-memory store: the tests' adapter, and the reference the contract is written against. */\nexport function memoryIdentityLinks(): IdentityLinkStore {\n const rows = new Map<string, { accountId: string; issuer: string; subject: string; linkedAt: Date }>();\n const key = (issuer: string, subject: string) => `${issuer}\\n${subject}`;\n return {\n async find(issuer, subject) {\n return rows.get(key(issuer, subject))?.accountId ?? null;\n },\n async link(accountId, issuer, subject, now) {\n const existing = rows.get(key(issuer, subject));\n if (existing && existing.accountId !== accountId) throw new IdentityLinkError();\n if (!existing) rows.set(key(issuer, subject), { accountId, issuer, subject, linkedAt: now });\n },\n async unlink(accountId, issuer, subject) {\n const existing = rows.get(key(issuer, subject));\n if (existing?.accountId !== accountId) return false;\n rows.delete(key(issuer, subject));\n return true;\n },\n async list(accountId) {\n return [...rows.values()]\n .filter((r) => r.accountId === accountId)\n .sort((a, b) => compareAsc(a.linkedAt, b.linkedAt))\n .map(({ issuer, subject, linkedAt }) => ({ issuer, subject, linkedAt }));\n },\n };\n}\n\n/**\n * The table of links (idempotent). `accounts` is the product's account table.\n * @deprecated Use `identityLinksSchema` with `emitMigration` or `adoptMigration` from `@krizaka/db`. Removed in the next major.\n */\nexport function identityLinksMigration(): string {\n return identityLinksSchema.migrations[0]!.sql({ schema: \"public\", tables: { accounts: \"accounts\" } });\n}\n\n/** The store over the product's own database (`external_identities`; see `identityLinksMigration`). */\nexport function dbIdentityLinks(query: Query): IdentityLinkStore {\n return {\n async find(issuer, subject) {\n const [row] = await query<{ account_id: string }>(\n \"SELECT account_id FROM external_identities WHERE issuer = $1 AND subject = $2\",\n [issuer, subject],\n );\n return row?.account_id ?? null;\n },\n async link(accountId, issuer, subject, now) {\n // One statement: the primary key decides a race; the same account is a no-op, another account is refused.\n const rows = await query<{ account_id: string }>(\n `INSERT INTO external_identities (issuer, subject, account_id, linked_at) VALUES ($1, $2, $3, $4)\n ON CONFLICT (issuer, subject) DO UPDATE SET issuer = excluded.issuer WHERE external_identities.account_id = excluded.account_id\n RETURNING account_id`,\n [issuer, subject, accountId, now],\n );\n if (rows.length === 0) throw new IdentityLinkError();\n },\n async unlink(accountId, issuer, subject) {\n const rows = await query(\n \"DELETE FROM external_identities WHERE issuer = $1 AND subject = $2 AND account_id = $3 RETURNING 1\",\n [issuer, subject, accountId],\n );\n return rows.length > 0;\n },\n async list(accountId) {\n const rows = await query<{ issuer: string; subject: string; linked_at: Date }>(\n \"SELECT issuer, subject, linked_at FROM external_identities WHERE account_id = $1 ORDER BY linked_at, issuer, subject\",\n [accountId],\n );\n return rows.map((r) => ({ issuer: r.issuer, subject: r.subject, linkedAt: r.linked_at }));\n },\n };\n}\n"],"mappings":";AAAA,OAAO,YAAY;AAUZ,IAAM,sBAAoD,CAAC,UAAU,SAAS,UAAU;AAExF,IAAM,sBAAsB,CAAC,UAClC,oBAAoB,SAAS,KAA0B;AAuClD,IAAM,kBAAkB;AAAA,EAC7B,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,aAAa;AACf;AAGO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACW,MACT,SACA;AACA,UAAM,OAAO;AAHJ;AAIT,SAAK,OAAO;AAAA,EACd;AAAA,EALW;AAMb;AAGO,IAAM,gBAAgB,CAAC,aAC5B,OAAO,WAAW,QAAQ,EAAE,OAAO,QAAQ,EAAE,OAAO,WAAW;AAG1D,IAAM,gBAAgB,CAA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KAAK,WAAW,EAAG,OAAM,IAAI,kBAAkB;AAAA,IACrD;AAAA,IACA,MAAM,OAAO,WAAW,QAAQ,SAAS;AACvC,YAAM,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,CAAC,QAAQ,SAAS,SAAS;AAAA,MAC7B;AACA,aAAO,KAAK,SAAS;AAAA,IACvB;AAAA,IACA,MAAM,KAAK,WAAW;AACpB,YAAM,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,CAAC,SAAS;AAAA,MACZ;AACA,aAAO,KAAK,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,SAAS,EAAE,SAAS,UAAU,EAAE,UAAU,EAAE;AAAA,IAC1F;AAAA,EACF;AACF;","names":[]}
@@ -19,7 +19,9 @@ var PASSWORD_RESET_MIN_MINUTES = 5;
19
19
  var PASSWORD_RESET_MAX_MINUTES = 1440;
20
20
  var checkResetTtl = (minutes) => {
21
21
  if (!Number.isInteger(minutes) || minutes < PASSWORD_RESET_MIN_MINUTES || minutes > PASSWORD_RESET_MAX_MINUTES) {
22
- throw new RangeError(`passwordResetTtlMinutes must be a whole number from ${PASSWORD_RESET_MIN_MINUTES} to ${PASSWORD_RESET_MAX_MINUTES}, got ${minutes}`);
22
+ throw new RangeError(
23
+ `passwordResetTtlMinutes must be a whole number from ${PASSWORD_RESET_MIN_MINUTES} to ${PASSWORD_RESET_MAX_MINUTES}, got ${minutes}`
24
+ );
23
25
  }
24
26
  return minutes;
25
27
  };
@@ -33,34 +35,46 @@ var emailChangeToken = linkToken;
33
35
  var isEmailChangeToken = isLinkToken;
34
36
  function passwordResetMail(product, locale, url, ttlMinutes = PASSWORD_RESET_TTL_MINUTES) {
35
37
  checkResetTtl(ttlMinutes);
36
- return locale === "fr" ? { subject: `R\xE9initialisez votre mot de passe \u2014 ${product}`, text: `Bonjour,
38
+ return locale === "fr" ? {
39
+ subject: `R\xE9initialisez votre mot de passe \u2014 ${product}`,
40
+ text: `Bonjour,
37
41
 
38
42
  Pour choisir un nouveau mot de passe pour votre compte ${product}, ouvrez ce lien (valide ${ttlMinutes} min, une seule fois) :
39
43
  ${url}
40
44
 
41
45
  Si vous n'avez rien demand\xE9, ignorez ce message : votre mot de passe ne change pas.
42
- ` } : { subject: `Reset your password \u2014 ${product}`, text: `Hello,
46
+ `
47
+ } : {
48
+ subject: `Reset your password \u2014 ${product}`,
49
+ text: `Hello,
43
50
 
44
51
  To choose a new password for your ${product} account, open this link (valid ${ttlMinutes} min, once):
45
52
  ${url}
46
53
 
47
54
  If you did not ask for this, ignore this message: your password does not change.
48
- ` };
55
+ `
56
+ };
49
57
  }
50
58
  function emailChangeMail(product, locale, url) {
51
- return locale === "fr" ? { subject: `Confirmez votre nouvelle adresse \u2014 ${product}`, text: `Bonjour,
59
+ return locale === "fr" ? {
60
+ subject: `Confirmez votre nouvelle adresse \u2014 ${product}`,
61
+ text: `Bonjour,
52
62
 
53
63
  Pour utiliser cette adresse avec votre compte ${product}, confirmez-la en ouvrant ce lien (valide ${EMAIL_CHANGE_TTL_HOURS} h) :
54
64
  ${url}
55
65
 
56
66
  Si vous n'avez rien demand\xE9, ignorez ce message : rien ne change.
57
- ` } : { subject: `Confirm your new address \u2014 ${product}`, text: `Hello,
67
+ `
68
+ } : {
69
+ subject: `Confirm your new address \u2014 ${product}`,
70
+ text: `Hello,
58
71
 
59
72
  To use this address with your ${product} account, confirm it by opening this link (valid ${EMAIL_CHANGE_TTL_HOURS} h):
60
73
  ${url}
61
74
 
62
75
  If you did not ask for this, ignore this message: nothing changes.
63
- ` };
76
+ `
77
+ };
64
78
  }
65
79
  var looksLikeEmail = (address) => {
66
80
  if (address.length > 320 || /\s/.test(address)) return false;
@@ -88,22 +102,44 @@ function dbAccounts(deps) {
88
102
  [id]
89
103
  );
90
104
  if (!row) throw new AccountError(404, "NOT_FOUND", "No such account");
91
- return { id: row.id, email: row.email, name: row.name, locale: row.locale, theme: row.theme, avatarSeed: row.avatar_seed, emailVerified: !!row.email_verified_at, pendingEmail: row.pending };
105
+ return {
106
+ id: row.id,
107
+ email: row.email,
108
+ name: row.name,
109
+ locale: row.locale,
110
+ theme: row.theme,
111
+ avatarSeed: row.avatar_seed,
112
+ emailVerified: !!row.email_verified_at,
113
+ pendingEmail: row.pending
114
+ };
92
115
  }
93
116
  async function confirmPassword(id, password) {
94
- const [row] = await query("SELECT password_hash FROM accounts WHERE id = $1", [id]);
95
- if (!row?.password_hash || password.length > PASSWORD_MAX || !await deps.passwords.verify(password, row.password_hash)) throw wrong();
117
+ const [row] = await query("SELECT password_hash FROM accounts WHERE id = $1", [
118
+ id
119
+ ]);
120
+ if (!row?.password_hash || password.length > PASSWORD_MAX || !await deps.passwords.verify(password, row.password_hash))
121
+ throw wrong();
96
122
  }
97
123
  return {
98
124
  profile: profileOf,
99
125
  async updateProfile(id, patch) {
100
126
  const name = patch.name === void 0 ? void 0 : patch.name === null ? null : cleanName(patch.name);
101
- if (patch.avatarSeed && !/^[a-z0-9-]{1,40}$/.test(patch.avatarSeed)) throw new AccountError(400, "BAD_REQUEST", "Not an avatar");
127
+ if (patch.avatarSeed && !/^[a-z0-9-]{1,40}$/.test(patch.avatarSeed))
128
+ throw new AccountError(400, "BAD_REQUEST", "Not an avatar");
102
129
  if (patch.theme && !THEMES.includes(patch.theme)) throw new AccountError(400, "BAD_REQUEST", "Not a theme");
103
130
  await query(
104
131
  `UPDATE accounts SET name = CASE WHEN $2::boolean THEN $3 ELSE name END, locale = COALESCE($4, locale),
105
132
  avatar_seed = CASE WHEN $5::boolean THEN $6 ELSE avatar_seed END, theme = CASE WHEN $7::boolean THEN $8 ELSE theme END WHERE id = $1`,
106
- [id, name !== void 0, name === "" ? null : name ?? null, patch.locale ?? null, patch.avatarSeed !== void 0, patch.avatarSeed ?? null, patch.theme !== void 0, patch.theme ?? null]
133
+ [
134
+ id,
135
+ name !== void 0,
136
+ name === "" ? null : name ?? null,
137
+ patch.locale ?? null,
138
+ patch.avatarSeed !== void 0,
139
+ patch.avatarSeed ?? null,
140
+ patch.theme !== void 0,
141
+ patch.theme ?? null
142
+ ]
107
143
  );
108
144
  return profileOf(id);
109
145
  },
@@ -116,16 +152,33 @@ function dbAccounts(deps) {
116
152
  const profile = await profileOf(id);
117
153
  await query("UPDATE email_changes SET used_at = $2 WHERE account_id = $1 AND used_at IS NULL", [id, now]);
118
154
  const token = (deps.token ?? (() => emailChangeToken(deps.tokenPrefix)))();
119
- await query("INSERT INTO email_changes (account_id, new_email, token_hash, expires_at) VALUES ($1, $2, $3, $4)", [id, address, deps.tokenHash(token), addHours(now, EMAIL_CHANGE_TTL_HOURS)]);
155
+ await query("INSERT INTO email_changes (account_id, new_email, token_hash, expires_at) VALUES ($1, $2, $3, $4)", [
156
+ id,
157
+ address,
158
+ deps.tokenHash(token),
159
+ addHours(now, EMAIL_CHANGE_TTL_HOURS)
160
+ ]);
120
161
  const url = `${deps.baseUrl.replace(/\/$/, "")}/${profile.locale}/confirm-email?token=${encodeURIComponent(token)}`;
121
- await deps.mail({ to: address, locale: profile.locale, ...emailChangeMail(deps.product, profile.locale, url), link: { kind: "emailChange", url, hours: EMAIL_CHANGE_TTL_HOURS } });
162
+ await deps.mail({
163
+ to: address,
164
+ locale: profile.locale,
165
+ ...emailChangeMail(deps.product, profile.locale, url),
166
+ link: { kind: "emailChange", url, hours: EMAIL_CHANGE_TTL_HOURS }
167
+ });
122
168
  },
123
169
  async confirmEmailChange(token, now) {
124
170
  if (!isEmailChangeToken(deps.tokenPrefix, token)) return "INVALID";
125
- const [row] = await query("UPDATE email_changes SET used_at = $2 WHERE token_hash = $1 AND used_at IS NULL AND expires_at > $2 RETURNING account_id, new_email", [deps.tokenHash(token), now]);
171
+ const [row] = await query(
172
+ "UPDATE email_changes SET used_at = $2 WHERE token_hash = $1 AND used_at IS NULL AND expires_at > $2 RETURNING account_id, new_email",
173
+ [deps.tokenHash(token), now]
174
+ );
126
175
  if (!row) return "INVALID";
127
176
  try {
128
- await query("UPDATE accounts SET email = $2, email_verified_at = $3 WHERE id = $1", [row.account_id, row.new_email, now]);
177
+ await query("UPDATE accounts SET email = $2, email_verified_at = $3 WHERE id = $1", [
178
+ row.account_id,
179
+ row.new_email,
180
+ now
181
+ ]);
129
182
  } catch {
130
183
  return "INVALID";
131
184
  }
@@ -133,42 +186,77 @@ function dbAccounts(deps) {
133
186
  },
134
187
  async changePassword(id, input, keepSessionId) {
135
188
  await confirmPassword(id, input.current);
136
- if (input.next.length < PASSWORD_MIN) throw new AccountError(400, "PASSWORD_TOO_SHORT", `At least ${PASSWORD_MIN} characters`);
137
- if (input.next.length > PASSWORD_MAX) throw new AccountError(400, "PASSWORD_TOO_LONG", `At most ${PASSWORD_MAX} characters`);
189
+ if (input.next.length < PASSWORD_MIN)
190
+ throw new AccountError(400, "PASSWORD_TOO_SHORT", `At least ${PASSWORD_MIN} characters`);
191
+ if (input.next.length > PASSWORD_MAX)
192
+ throw new AccountError(400, "PASSWORD_TOO_LONG", `At most ${PASSWORD_MAX} characters`);
138
193
  await query("UPDATE accounts SET password_hash = $2 WHERE id = $1", [id, await deps.passwords.hash(input.next)]);
139
- await query("DELETE FROM sessions WHERE account_id = $1 AND ($2::uuid IS NULL OR id <> $2::uuid)", [id, keepSessionId ?? null]);
194
+ await query("DELETE FROM sessions WHERE account_id = $1 AND ($2::uuid IS NULL OR id <> $2::uuid)", [
195
+ id,
196
+ keepSessionId ?? null
197
+ ]);
140
198
  },
141
199
  confirmPassword,
142
200
  async requestPasswordReset(email, now) {
143
201
  const address = email.trim().toLowerCase();
144
202
  if (!looksLikeEmail(address)) return;
145
203
  const issued = await transaction(async (q) => {
146
- const [row] = await q("SELECT id, locale FROM accounts WHERE email = $1 AND password_hash IS NOT NULL FOR UPDATE", [address]);
204
+ const [row] = await q(
205
+ "SELECT id, locale FROM accounts WHERE email = $1 AND password_hash IS NOT NULL FOR UPDATE",
206
+ [address]
207
+ );
147
208
  if (!row) return null;
148
209
  await q("UPDATE password_resets SET used_at = $2 WHERE account_id = $1 AND used_at IS NULL", [row.id, now]);
149
210
  const token = (deps.token ?? (() => linkToken(deps.tokenPrefix)))();
150
- await q("INSERT INTO password_resets (account_id, token_hash, expires_at) VALUES ($1, $2, $3)", [row.id, deps.tokenHash(token), addMinutes(now, resetTtlMinutes)]);
211
+ await q("INSERT INTO password_resets (account_id, token_hash, expires_at) VALUES ($1, $2, $3)", [
212
+ row.id,
213
+ deps.tokenHash(token),
214
+ addMinutes(now, resetTtlMinutes)
215
+ ]);
151
216
  return { token, locale: row.locale };
152
217
  });
153
218
  if (!issued) return;
154
219
  const url = `${deps.baseUrl.replace(/\/$/, "")}/${issued.locale}/reset-password?token=${encodeURIComponent(issued.token)}`;
155
- await deps.mail({ to: address, locale: issued.locale, ...passwordResetMail(deps.product, issued.locale, url, resetTtlMinutes), link: { kind: "passwordReset", url, minutes: resetTtlMinutes } });
220
+ await deps.mail({
221
+ to: address,
222
+ locale: issued.locale,
223
+ ...passwordResetMail(deps.product, issued.locale, url, resetTtlMinutes),
224
+ link: { kind: "passwordReset", url, minutes: resetTtlMinutes }
225
+ });
156
226
  },
157
227
  async resetPassword(token, next, now) {
158
- if (next.length < PASSWORD_MIN) throw new AccountError(400, "PASSWORD_TOO_SHORT", `At least ${PASSWORD_MIN} characters`);
159
- if (next.length > PASSWORD_MAX) throw new AccountError(400, "PASSWORD_TOO_LONG", `At most ${PASSWORD_MAX} characters`);
228
+ if (next.length < PASSWORD_MIN)
229
+ throw new AccountError(400, "PASSWORD_TOO_SHORT", `At least ${PASSWORD_MIN} characters`);
230
+ if (next.length > PASSWORD_MAX)
231
+ throw new AccountError(400, "PASSWORD_TOO_LONG", `At most ${PASSWORD_MAX} characters`);
160
232
  if (!isLinkToken(deps.tokenPrefix, token)) return "INVALID";
161
233
  return transaction(async (q) => {
162
- const [row] = await q("UPDATE password_resets SET used_at = $2 WHERE token_hash = $1 AND used_at IS NULL AND expires_at > $2 RETURNING account_id", [deps.tokenHash(token), now]);
234
+ const [row] = await q(
235
+ "UPDATE password_resets SET used_at = $2 WHERE token_hash = $1 AND used_at IS NULL AND expires_at > $2 RETURNING account_id",
236
+ [deps.tokenHash(token), now]
237
+ );
163
238
  if (!row) return "INVALID";
164
- await q("UPDATE accounts SET password_hash = $2 WHERE id = $1", [row.account_id, await deps.passwords.hash(next)]);
239
+ await q("UPDATE accounts SET password_hash = $2 WHERE id = $1", [
240
+ row.account_id,
241
+ await deps.passwords.hash(next)
242
+ ]);
165
243
  await q("DELETE FROM sessions WHERE account_id = $1", [row.account_id]);
166
244
  return "CHANGED";
167
245
  });
168
246
  },
169
247
  async sessions(id, now, currentSessionId) {
170
- const rows = await query("SELECT id, created_at, expires_at, ip, user_agent FROM sessions WHERE account_id = $1 AND expires_at > $2 ORDER BY created_at DESC", [id, now]);
171
- return rows.map((r) => ({ id: r.id, createdAt: r.created_at, expiresAt: r.expires_at, ip: r.ip, userAgent: r.user_agent, current: r.id === currentSessionId }));
248
+ const rows = await query(
249
+ "SELECT id, created_at, expires_at, ip, user_agent FROM sessions WHERE account_id = $1 AND expires_at > $2 ORDER BY created_at DESC",
250
+ [id, now]
251
+ );
252
+ return rows.map((r) => ({
253
+ id: r.id,
254
+ createdAt: r.created_at,
255
+ expiresAt: r.expires_at,
256
+ ip: r.ip,
257
+ userAgent: r.user_agent,
258
+ current: r.id === currentSessionId
259
+ }));
172
260
  },
173
261
  async signOutOthers(id, keepSessionId) {
174
262
  return (await query("DELETE FROM sessions WHERE account_id = $1 AND id <> $2::uuid RETURNING id", [id, keepSessionId])).length;
@@ -176,7 +264,12 @@ function dbAccounts(deps) {
176
264
  async exportAccount(id, now, extra) {
177
265
  const profile = await profileOf(id);
178
266
  const live = await this.sessions(id, now);
179
- return { exportedAt: now.toISOString(), account: profile, sessions: live.map(({ current: _current, ...s }) => s), ...extra ? await extra() : {} };
267
+ return {
268
+ exportedAt: now.toISOString(),
269
+ account: profile,
270
+ sessions: live.map(({ current: _current, ...s }) => s),
271
+ ...extra ? await extra() : {}
272
+ };
180
273
  },
181
274
  async deleteAccount(id) {
182
275
  const rows = await query("DELETE FROM accounts WHERE id = $1 RETURNING id", [id]);
@@ -201,4 +294,4 @@ export {
201
294
  dbAccounts,
202
295
  postgresAccounts
203
296
  };
204
- //# sourceMappingURL=chunk-3CLSDLXB.js.map
297
+ //# sourceMappingURL=chunk-34CFR7EE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/port.ts","../src/accounts.ts"],"sourcesContent":["/**\n * The account PORT (ADR-0008 of Yomizaka, now shared). A product's account — name, language, theme, avatar, e-mail change with\n * verification, password (changed when signed in, or reset by a mailed link), sessions, export, deletion — behind one interface. Every product keeps its OWN accounts: no central\n * service, no runtime dependency between products.\n */\nexport type Theme = \"light\" | \"dark\" | \"system\";\n\nexport interface AccountProfile {\n id: string;\n email: string;\n name: string | null;\n locale: \"en\" | \"fr\";\n /** The theme the person chose; null = follow the device. */\n theme: Theme | null;\n /** A seed of the default avatars (the UI draws it); null = derived from the e-mail address. */\n avatarSeed: string | null;\n emailVerified: boolean;\n /** An address awaiting its verification link, if the person asked to change it. */\n pendingEmail: string | null;\n}\n\nexport interface ProfilePatch {\n name?: string | null;\n locale?: \"en\" | \"fr\";\n theme?: Theme | null;\n avatarSeed?: string | null;\n}\n\n/** A sign-in of the person: where from and when. Never the token. */\nexport interface SessionSummary {\n id: string;\n createdAt: Date;\n expiresAt: Date;\n ip: string | null;\n userAgent: string | null;\n current: boolean;\n}\n\nexport interface AccountService {\n profile(accountId: string): Promise<AccountProfile>;\n updateProfile(accountId: string, patch: ProfilePatch): Promise<AccountProfile>;\n /** Asks to change the address: the password is checked, a link is mailed to the NEW address. Answers the same whether or not it is already taken (no enumeration). */\n requestEmailChange(accountId: string, input: { newEmail: string; password: string }, now: Date): Promise<void>;\n /** Applies the change from the mailed link (single use, expires); the new address is verified by that very act. */\n confirmEmailChange(token: string, now: Date): Promise<\"CHANGED\" | \"INVALID\">;\n /** Changes the password (the current one is checked) and signs every other session out; `keepSessionId` stays. */\n changePassword(accountId: string, input: { current: string; next: string }, keepSessionId?: string): Promise<void>;\n /** Asks for a reset link, mailed (in the person's language) when an account with a password has this address; answers the same either way (no enumeration). */\n requestPasswordReset(email: string, now: Date): Promise<void>;\n /** Sets a new password from the mailed link — single use, expires — and signs every session out. The new password is checked before the link is used up. */\n resetPassword(token: string, next: string, now: Date): Promise<\"CHANGED\" | \"INVALID\">;\n /** Checks the password. Throws `AccountError(403, \"WRONG_PASSWORD\")`. */\n confirmPassword(accountId: string, password: string): Promise<void>;\n /** The person's live sign-ins, newest first; `currentSessionId` is flagged. */\n sessions(accountId: string, now: Date, currentSessionId?: string): Promise<SessionSummary[]>;\n /** Signs every other session out (and returns how many); `keepSessionId` stays. */\n signOutOthers(accountId: string, keepSessionId: string): Promise<number>;\n /** What the product keeps about the person, as one JSON-able document: the profile, the live sign-ins, and what `extra` adds. */\n exportAccount(\n accountId: string,\n now: Date,\n extra?: () => Promise<Record<string, unknown>>,\n ): Promise<Record<string, unknown>>;\n /** Deletes the identity: the account, its sessions and everything that hangs on it (the product erases its own data first). */\n deleteAccount(accountId: string): Promise<void>;\n}\n\nexport class AccountError extends Error {\n constructor(\n readonly status: number,\n readonly code: string,\n message: string,\n ) {\n super(message);\n this.name = \"AccountError\";\n }\n}\n","import crypto from \"node:crypto\";\n\nimport type { Query } from \"@krizaka/db\";\nimport { addHours, addMinutes } from \"date-fns\";\n\nimport {\n AccountError,\n type AccountProfile,\n type AccountService,\n type ProfilePatch,\n type SessionSummary,\n type Theme,\n} from \"./port\";\n\n/** A SQL executor: `@krizaka/db`'s `Query`, which the product passes (its pool, or its transaction's client). */\nexport type { Query };\n\nexport interface Mail {\n to: string;\n /** The language of the mail (the person's). */\n locale: \"en\" | \"fr\";\n subject: string;\n text: string;\n /**\n * The link this mail carries, as data: a product that sends branded HTML (`@krizaka/email`: `passwordReset`, `emailChange`)\n * renders it from this instead of from `text`. Absent on a mail that is not a link.\n */\n link?: MailLink;\n}\n\n/** A mailed link: what it is for, where it goes, and how long it lives. */\nexport interface MailLink {\n kind: \"passwordReset\" | \"emailChange\";\n url: string;\n /** `passwordReset`: the lifetime in minutes. */\n minutes?: number;\n /** `emailChange`: the lifetime in hours. */\n hours?: number;\n}\n\nexport interface AccountDeps {\n query: Query;\n /**\n * Runs `work` in one transaction on one connection (BEGIN … COMMIT, rolled back when `work` throws) — the product's pool\n * knows how. The password reset runs under it: the account row is locked, the links retired and issued, the token claimed,\n * the password set and the sessions ended as one. Without it, the statements run one by one on `query` (one process, no\n * concurrent requests): give it in production.\n */\n transaction?: <T>(work: (query: Query) => Promise<T>) => Promise<T>;\n mail: (mail: Mail) => Promise<void>;\n /** `https://www.akinaza.com`: the e-mail change link is `<baseUrl>/<locale>/confirm-email?token=…`, the reset link `<baseUrl>/<locale>/reset-password?token=…`. */\n baseUrl: string;\n /** The product's name, in the words of the mail (« Akinaza »). */\n product: string;\n /** The product's token prefix, two or three letters (`ye1.` for Yomizaka: `ye`). The tokens are `<prefix>1.<43 base64url>`. */\n tokenPrefix: string;\n passwords: {\n hash: (password: string) => Promise<string>;\n verify: (password: string, stored: string) => Promise<boolean>;\n };\n /** How a token is kept: the product's own keyed hash, the one its sessions use. */\n tokenHash: (token: string) => string;\n /**\n * How long a password reset link lives, in minutes: a whole number from 5 to 1440 (`PASSWORD_RESET_MIN_MINUTES`–`PASSWORD_RESET_MAX_MINUTES`),\n * default `PASSWORD_RESET_TTL_MINUTES` (30). The product reads it from its settings; the expiry and the mailed text both use it.\n * Out of range, `dbAccounts` throws.\n */\n passwordResetTtlMinutes?: number;\n /** Test seam: the token to issue. */\n token?: () => string;\n}\n\n// @fixed: the lifetime of an e-mail change link, a security parameter\nexport const EMAIL_CHANGE_TTL_HOURS = 24;\n/** The default lifetime of a password reset link, in minutes (`AccountDeps.passwordResetTtlMinutes` changes it). */\n// @fixed: the default lifetime of a password reset link, a security parameter\nexport const PASSWORD_RESET_TTL_MINUTES = 30;\n// @fixed: the shortest lifetime a product may set: a person must have time to open the mail\nexport const PASSWORD_RESET_MIN_MINUTES = 5;\n// @fixed: the longest lifetime a product may set: a day\nexport const PASSWORD_RESET_MAX_MINUTES = 1440;\n\nconst checkResetTtl = (minutes: number): number => {\n if (!Number.isInteger(minutes) || minutes < PASSWORD_RESET_MIN_MINUTES || minutes > PASSWORD_RESET_MAX_MINUTES) {\n throw new RangeError(\n `passwordResetTtlMinutes must be a whole number from ${PASSWORD_RESET_MIN_MINUTES} to ${PASSWORD_RESET_MAX_MINUTES}, got ${minutes}`,\n );\n }\n return minutes;\n};\nconst NAME_MAX = 80;\nconst PASSWORD_MIN = 12;\nconst PASSWORD_MAX = 256;\nconst THEMES: readonly Theme[] = [\"light\", \"dark\", \"system\"];\n\n/** One format for every mailed link (an e-mail change, a password reset): the product's prefix, a version, 256 random bits. */\nexport const linkToken = (prefix: string) => `${prefix}1.${crypto.randomBytes(32).toString(\"base64url\")}`;\nexport const isLinkToken = (prefix: string, value: string | undefined | null): value is string =>\n !!value && new RegExp(`^${prefix}1\\\\.[A-Za-z0-9_-]{43}$`).test(value);\nexport const emailChangeToken = linkToken;\nexport const isEmailChangeToken = isLinkToken;\n\nexport function passwordResetMail(\n product: string,\n locale: \"en\" | \"fr\",\n url: string,\n ttlMinutes: number = PASSWORD_RESET_TTL_MINUTES,\n) {\n checkResetTtl(ttlMinutes);\n return locale === \"fr\"\n ? {\n subject: `Réinitialisez votre mot de passe — ${product}`,\n text: `Bonjour,\\n\\nPour choisir un nouveau mot de passe pour votre compte ${product}, ouvrez ce lien (valide ${ttlMinutes} min, une seule fois) :\\n${url}\\n\\nSi vous n'avez rien demandé, ignorez ce message : votre mot de passe ne change pas.\\n`,\n }\n : {\n subject: `Reset your password — ${product}`,\n text: `Hello,\\n\\nTo choose a new password for your ${product} account, open this link (valid ${ttlMinutes} min, once):\\n${url}\\n\\nIf you did not ask for this, ignore this message: your password does not change.\\n`,\n };\n}\n\nexport function emailChangeMail(product: string, locale: \"en\" | \"fr\", url: string) {\n return locale === \"fr\"\n ? {\n subject: `Confirmez votre nouvelle adresse — ${product}`,\n text: `Bonjour,\\n\\nPour utiliser cette adresse avec votre compte ${product}, confirmez-la en ouvrant ce lien (valide ${EMAIL_CHANGE_TTL_HOURS} h) :\\n${url}\\n\\nSi vous n'avez rien demandé, ignorez ce message : rien ne change.\\n`,\n }\n : {\n subject: `Confirm your new address — ${product}`,\n text: `Hello,\\n\\nTo use this address with your ${product} account, confirm it by opening this link (valid ${EMAIL_CHANGE_TTL_HOURS} h):\\n${url}\\n\\nIf you did not ask for this, ignore this message: nothing changes.\\n`,\n };\n}\n\n/** One « @ », something on each side, a dot inside the domain, no space — checked without a backtracking pattern. */\nconst looksLikeEmail = (address: string): boolean => {\n if (address.length > 320 || /\\s/.test(address)) return false;\n const at = address.indexOf(\"@\");\n if (at < 1 || at !== address.lastIndexOf(\"@\")) return false;\n const domain = address.slice(at + 1);\n const dot = domain.lastIndexOf(\".\");\n return dot > 0 && dot < domain.length - 1;\n};\n\nconst cleanName = (raw: string): string => {\n const name = raw.replace(/\\s+/g, \" \").trim();\n if (name.length > NAME_MAX) throw new AccountError(400, \"BAD_REQUEST\", `A name is at most ${NAME_MAX} characters`);\n return name;\n};\n\ninterface ProfileRow {\n id: string;\n email: string;\n name: string | null;\n locale: \"en\" | \"fr\";\n theme: Theme | null;\n avatar_seed: string | null;\n email_verified_at: Date | null;\n pending: string | null;\n}\n\n/** The adapter over the product's own PostgreSQL (`accounts`, `sessions`, `email_changes`, `password_resets`; see `accountsMigration`). */\nexport function dbAccounts(deps: AccountDeps): AccountService {\n const { query } = deps;\n const resetTtlMinutes = checkResetTtl(deps.passwordResetTtlMinutes ?? PASSWORD_RESET_TTL_MINUTES);\n const transaction = deps.transaction ?? (<T>(work: (q: Query) => Promise<T>) => work(query));\n const wrong = () => new AccountError(403, \"WRONG_PASSWORD\", \"The password is not right\");\n\n async function profileOf(id: string): Promise<AccountProfile> {\n const [row] = await query<ProfileRow>(\n `SELECT a.id, a.email, a.name, a.locale, a.theme, a.avatar_seed, a.email_verified_at,\n (SELECT c.new_email FROM email_changes c WHERE c.account_id = a.id AND c.used_at IS NULL AND c.expires_at > now() ORDER BY c.created_at DESC LIMIT 1) AS pending\n FROM accounts a WHERE a.id = $1`,\n [id],\n );\n if (!row) throw new AccountError(404, \"NOT_FOUND\", \"No such account\");\n return {\n id: row.id,\n email: row.email,\n name: row.name,\n locale: row.locale,\n theme: row.theme,\n avatarSeed: row.avatar_seed,\n emailVerified: !!row.email_verified_at,\n pendingEmail: row.pending,\n };\n }\n\n async function confirmPassword(id: string, password: string): Promise<void> {\n const [row] = await query<{ password_hash: string | null }>(\"SELECT password_hash FROM accounts WHERE id = $1\", [\n id,\n ]);\n if (\n !row?.password_hash ||\n password.length > PASSWORD_MAX ||\n !(await deps.passwords.verify(password, row.password_hash))\n )\n throw wrong();\n }\n\n return {\n profile: profileOf,\n\n async updateProfile(id, patch: ProfilePatch) {\n const name = patch.name === undefined ? undefined : patch.name === null ? null : cleanName(patch.name);\n if (patch.avatarSeed && !/^[a-z0-9-]{1,40}$/.test(patch.avatarSeed))\n throw new AccountError(400, \"BAD_REQUEST\", \"Not an avatar\");\n if (patch.theme && !THEMES.includes(patch.theme)) throw new AccountError(400, \"BAD_REQUEST\", \"Not a theme\");\n await query(\n `UPDATE accounts SET name = CASE WHEN $2::boolean THEN $3 ELSE name END, locale = COALESCE($4, locale),\n avatar_seed = CASE WHEN $5::boolean THEN $6 ELSE avatar_seed END, theme = CASE WHEN $7::boolean THEN $8 ELSE theme END WHERE id = $1`,\n [\n id,\n name !== undefined,\n name === \"\" ? null : (name ?? null),\n patch.locale ?? null,\n patch.avatarSeed !== undefined,\n patch.avatarSeed ?? null,\n patch.theme !== undefined,\n patch.theme ?? null,\n ],\n );\n return profileOf(id);\n },\n\n async requestEmailChange(id, input, now) {\n await confirmPassword(id, input.password);\n const address = input.newEmail.trim().toLowerCase();\n if (!looksLikeEmail(address)) throw new AccountError(400, \"BAD_REQUEST\", \"Not an e-mail address\");\n const [taken] = await query(\"SELECT 1 FROM accounts WHERE email = $1\", [address]);\n if (taken) return; // the same answer, no mail: the address is not disclosed\n const profile = await profileOf(id);\n await query(\"UPDATE email_changes SET used_at = $2 WHERE account_id = $1 AND used_at IS NULL\", [id, now]);\n const token = (deps.token ?? (() => emailChangeToken(deps.tokenPrefix)))();\n await query(\"INSERT INTO email_changes (account_id, new_email, token_hash, expires_at) VALUES ($1, $2, $3, $4)\", [\n id,\n address,\n deps.tokenHash(token),\n addHours(now, EMAIL_CHANGE_TTL_HOURS),\n ]);\n const url = `${deps.baseUrl.replace(/\\/$/, \"\")}/${profile.locale}/confirm-email?token=${encodeURIComponent(token)}`;\n await deps.mail({\n to: address,\n locale: profile.locale,\n ...emailChangeMail(deps.product, profile.locale, url),\n link: { kind: \"emailChange\", url, hours: EMAIL_CHANGE_TTL_HOURS },\n });\n },\n\n async confirmEmailChange(token, now) {\n if (!isEmailChangeToken(deps.tokenPrefix, token)) return \"INVALID\";\n const [row] = await query<{ account_id: string; new_email: string }>(\n \"UPDATE email_changes SET used_at = $2 WHERE token_hash = $1 AND used_at IS NULL AND expires_at > $2 RETURNING account_id, new_email\",\n [deps.tokenHash(token), now],\n );\n if (!row) return \"INVALID\";\n try {\n await query(\"UPDATE accounts SET email = $2, email_verified_at = $3 WHERE id = $1\", [\n row.account_id,\n row.new_email,\n now,\n ]);\n } catch {\n return \"INVALID\"; // taken in the meantime\n }\n return \"CHANGED\";\n },\n\n async changePassword(id, input, keepSessionId) {\n await confirmPassword(id, input.current);\n if (input.next.length < PASSWORD_MIN)\n throw new AccountError(400, \"PASSWORD_TOO_SHORT\", `At least ${PASSWORD_MIN} characters`);\n if (input.next.length > PASSWORD_MAX)\n throw new AccountError(400, \"PASSWORD_TOO_LONG\", `At most ${PASSWORD_MAX} characters`);\n await query(\"UPDATE accounts SET password_hash = $2 WHERE id = $1\", [id, await deps.passwords.hash(input.next)]);\n await query(\"DELETE FROM sessions WHERE account_id = $1 AND ($2::uuid IS NULL OR id <> $2::uuid)\", [\n id,\n keepSessionId ?? null,\n ]);\n },\n\n confirmPassword,\n\n async requestPasswordReset(email, now) {\n const address = email.trim().toLowerCase();\n if (!looksLikeEmail(address)) return; // the same answer: nothing is disclosed\n // One transaction, the account row locked: two requests at once leave one valid link — the later one. The mail goes after the commit.\n const issued = await transaction(async (q) => {\n const [row] = await q<{ id: string; locale: \"en\" | \"fr\" }>(\n \"SELECT id, locale FROM accounts WHERE email = $1 AND password_hash IS NOT NULL FOR UPDATE\",\n [address],\n );\n if (!row) return null;\n await q(\"UPDATE password_resets SET used_at = $2 WHERE account_id = $1 AND used_at IS NULL\", [row.id, now]);\n const token = (deps.token ?? (() => linkToken(deps.tokenPrefix)))();\n await q(\"INSERT INTO password_resets (account_id, token_hash, expires_at) VALUES ($1, $2, $3)\", [\n row.id,\n deps.tokenHash(token),\n addMinutes(now, resetTtlMinutes),\n ]);\n return { token, locale: row.locale };\n });\n if (!issued) return;\n const url = `${deps.baseUrl.replace(/\\/$/, \"\")}/${issued.locale}/reset-password?token=${encodeURIComponent(issued.token)}`;\n await deps.mail({\n to: address,\n locale: issued.locale,\n ...passwordResetMail(deps.product, issued.locale, url, resetTtlMinutes),\n link: { kind: \"passwordReset\", url, minutes: resetTtlMinutes },\n });\n },\n\n async resetPassword(token, next, now) {\n if (next.length < PASSWORD_MIN)\n throw new AccountError(400, \"PASSWORD_TOO_SHORT\", `At least ${PASSWORD_MIN} characters`);\n if (next.length > PASSWORD_MAX)\n throw new AccountError(400, \"PASSWORD_TOO_LONG\", `At most ${PASSWORD_MAX} characters`);\n if (!isLinkToken(deps.tokenPrefix, token)) return \"INVALID\";\n // One transaction: the link is claimed, the password set and every session ended as one — a failure leaves the link usable.\n return transaction(async (q) => {\n const [row] = await q<{ account_id: string }>(\n \"UPDATE password_resets SET used_at = $2 WHERE token_hash = $1 AND used_at IS NULL AND expires_at > $2 RETURNING account_id\",\n [deps.tokenHash(token), now],\n );\n if (!row) return \"INVALID\" as const;\n await q(\"UPDATE accounts SET password_hash = $2 WHERE id = $1\", [\n row.account_id,\n await deps.passwords.hash(next),\n ]);\n await q(\"DELETE FROM sessions WHERE account_id = $1\", [row.account_id]);\n return \"CHANGED\" as const;\n });\n },\n\n async sessions(id, now, currentSessionId) {\n const rows = await query<{\n id: string;\n created_at: Date;\n expires_at: Date;\n ip: string | null;\n user_agent: string | null;\n }>(\n \"SELECT id, created_at, expires_at, ip, user_agent FROM sessions WHERE account_id = $1 AND expires_at > $2 ORDER BY created_at DESC\",\n [id, now],\n );\n return rows.map((r): SessionSummary => ({\n id: r.id,\n createdAt: r.created_at,\n expiresAt: r.expires_at,\n ip: r.ip,\n userAgent: r.user_agent,\n current: r.id === currentSessionId,\n }));\n },\n\n async signOutOthers(id, keepSessionId) {\n return (\n await query(\"DELETE FROM sessions WHERE account_id = $1 AND id <> $2::uuid RETURNING id\", [id, keepSessionId])\n ).length;\n },\n\n async exportAccount(id, now, extra) {\n const profile = await profileOf(id);\n const live = await this.sessions(id, now);\n return {\n exportedAt: now.toISOString(),\n account: profile,\n sessions: live.map(({ current: _current, ...s }) => s),\n ...(extra ? await extra() : {}),\n };\n },\n\n async deleteAccount(id) {\n const rows = await query(\"DELETE FROM accounts WHERE id = $1 RETURNING id\", [id]);\n if (!rows.length) throw new AccountError(404, \"NOT_FOUND\", \"No such account\");\n },\n };\n}\n\n/** @deprecated The old name of `dbAccounts` (a name says what a thing does, not the technology). Removed in the next major. */\nexport const postgresAccounts = dbAccounts;\n"],"mappings":";AAmEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACW,QACA,MACT,SACA;AACA,UAAM,OAAO;AAJJ;AACA;AAIT,SAAK,OAAO;AAAA,EACd;AAAA,EANW;AAAA,EACA;AAMb;;;AC5EA,OAAO,YAAY;AAGnB,SAAS,UAAU,kBAAkB;AAsE9B,IAAM,yBAAyB;AAG/B,IAAM,6BAA6B;AAEnC,IAAM,6BAA6B;AAEnC,IAAM,6BAA6B;AAE1C,IAAM,gBAAgB,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Ac,IAAI;AACtB,YAAM,OAAO,MAAM,MAAM,mDAAmD,CAAC,EAAE,CAAC;AAChF,UAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,aAAa,KAAK,aAAa,iBAAiB;AAAA,IAC9E;AAAA,EACF;AACF;AAGO,IAAM,mBAAmB;","names":[]}
@@ -14,7 +14,11 @@ var meSchema = z.object({
14
14
  }).refine((me) => me.signedIn === (me.account !== void 0), { message: "account is present exactly when signedIn" });
15
15
  var ME_HEADERS = { "Cache-Control": "private, no-store", Vary: "Cookie" };
16
16
  function meResponse(input) {
17
- const body = meSchema.parse({ signedIn: !!input.account, signupOpen: input.signupOpen, ...input.account ? { account: input.account } : {} });
17
+ const body = meSchema.parse({
18
+ signedIn: !!input.account,
19
+ signupOpen: input.signupOpen,
20
+ ...input.account ? { account: input.account } : {}
21
+ });
18
22
  return Response.json(body, { headers: ME_HEADERS });
19
23
  }
20
24
 
@@ -25,4 +29,4 @@ export {
25
29
  ME_HEADERS,
26
30
  meResponse
27
31
  };
28
- //# sourceMappingURL=chunk-G46LWJPQ.js.map
32
+ //# sourceMappingURL=chunk-3MIBOYLS.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/contract.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * « Who is here »: the one contract of `GET /api/me` for every product (krizaka-ui#551). Browser-safe: zod and the web-standard\n * `Response` only, so the product's route and the bar island of `@krizaka/ui` import the same file.\n *\n * A public page asking who is there is not an error: signed out is 200 with `signedIn: false`, never a 401. The answer is a hint for the\n * bar; it authorises nothing, and every page and route checks the session itself.\n */\n\n/** The path every product serves. */\nexport const ME_PATH = \"/api/me\";\n\n/** What the bar shows of the signed-in person. */\nexport const meAccountSchema = z.object({\n id: z.string().min(1),\n name: z.string().nullable(),\n email: z.string().min(1),\n avatarSeed: z.string().nullable(),\n});\n\nexport const meSchema = z\n .object({\n signedIn: z.boolean(),\n signupOpen: z.boolean(),\n account: meAccountSchema.optional(),\n })\n .refine((me) => me.signedIn === (me.account !== undefined), { message: \"account is present exactly when signedIn\" });\n\nexport type MeAccount = z.infer<typeof meAccountSchema>;\nexport type Me = z.infer<typeof meSchema>;\n\n/** Never cached, never shared: the answer depends on the cookie. */\nexport const ME_HEADERS = { \"Cache-Control\": \"private, no-store\", Vary: \"Cookie\" } as const;\n\n/**\n * The answer of `GET /api/me`: 200, the body checked against the contract, `Cache-Control: private, no-store` and `Vary: Cookie`.\n * @param input whether sign-up is open, and the signed-in account when there is one\n * @throws ZodError when the body breaks the contract (a signed-in answer without an account)\n */\nexport function meResponse(input: { signupOpen: boolean; account?: MeAccount | null | undefined }): Response {\n const body: Me = meSchema.parse({ signedIn: !!input.account, signupOpen: input.signupOpen, ...(input.account ? { account: input.account } : {}) });\n return Response.json(body, { headers: ME_HEADERS });\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAWX,IAAM,UAAU;AAGhB,IAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACpB,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACvB,YAAY,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAEM,IAAM,WAAW,EACrB,OAAO;AAAA,EACN,UAAU,EAAE,QAAQ;AAAA,EACpB,YAAY,EAAE,QAAQ;AAAA,EACtB,SAAS,gBAAgB,SAAS;AACpC,CAAC,EACA,OAAO,CAAC,OAAO,GAAG,cAAc,GAAG,YAAY,SAAY,EAAE,SAAS,2CAA2C,CAAC;AAM9G,IAAM,aAAa,EAAE,iBAAiB,qBAAqB,MAAM,SAAS;AAO1E,SAAS,WAAW,OAAkF;AAC3G,QAAM,OAAW,SAAS,MAAM,EAAE,UAAU,CAAC,CAAC,MAAM,SAAS,YAAY,MAAM,YAAY,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC,EAAG,CAAC;AACjJ,SAAO,SAAS,KAAK,MAAM,EAAE,SAAS,WAAW,CAAC;AACpD;","names":[]}
1
+ {"version":3,"sources":["../src/contract.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * « Who is here »: the one contract of `GET /api/me` for every product (krizaka-ui#551). Browser-safe: zod and the web-standard\n * `Response` only, so the product's route and the bar island of `@krizaka/ui` import the same file.\n *\n * A public page asking who is there is not an error: signed out is 200 with `signedIn: false`, never a 401. The answer is a hint for the\n * bar; it authorises nothing, and every page and route checks the session itself.\n */\n\n/** The path every product serves. */\nexport const ME_PATH = \"/api/me\";\n\n/** What the bar shows of the signed-in person. */\nexport const meAccountSchema = z.object({\n id: z.string().min(1),\n name: z.string().nullable(),\n email: z.string().min(1),\n avatarSeed: z.string().nullable(),\n});\n\nexport const meSchema = z\n .object({\n signedIn: z.boolean(),\n signupOpen: z.boolean(),\n account: meAccountSchema.optional(),\n })\n .refine((me) => me.signedIn === (me.account !== undefined), { message: \"account is present exactly when signedIn\" });\n\nexport type MeAccount = z.infer<typeof meAccountSchema>;\nexport type Me = z.infer<typeof meSchema>;\n\n/** Never cached, never shared: the answer depends on the cookie. */\nexport const ME_HEADERS = { \"Cache-Control\": \"private, no-store\", Vary: \"Cookie\" } as const;\n\n/**\n * The answer of `GET /api/me`: 200, the body checked against the contract, `Cache-Control: private, no-store` and `Vary: Cookie`.\n * @param input whether sign-up is open, and the signed-in account when there is one\n * @throws ZodError when the body breaks the contract (a signed-in answer without an account)\n */\nexport function meResponse(input: { signupOpen: boolean; account?: MeAccount | null | undefined }): Response {\n const body: Me = meSchema.parse({\n signedIn: !!input.account,\n signupOpen: input.signupOpen,\n ...(input.account ? { account: input.account } : {}),\n });\n return Response.json(body, { headers: ME_HEADERS });\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAWX,IAAM,UAAU;AAGhB,IAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACpB,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACvB,YAAY,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAEM,IAAM,WAAW,EACrB,OAAO;AAAA,EACN,UAAU,EAAE,QAAQ;AAAA,EACpB,YAAY,EAAE,QAAQ;AAAA,EACtB,SAAS,gBAAgB,SAAS;AACpC,CAAC,EACA,OAAO,CAAC,OAAO,GAAG,cAAc,GAAG,YAAY,SAAY,EAAE,SAAS,2CAA2C,CAAC;AAM9G,IAAM,aAAa,EAAE,iBAAiB,qBAAqB,MAAM,SAAS;AAO1E,SAAS,WAAW,OAAkF;AAC3G,QAAM,OAAW,SAAS,MAAM;AAAA,IAC9B,UAAU,CAAC,CAAC,MAAM;AAAA,IAClB,YAAY,MAAM;AAAA,IAClB,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,EACpD,CAAC;AACD,SAAO,SAAS,KAAK,MAAM,EAAE,SAAS,WAAW,CAAC;AACpD;","names":[]}
@@ -10,7 +10,15 @@ var ROLES_CODE = {
10
10
  inviteInvalid: "INVITE_INVALID",
11
11
  inviteWrongAccount: "INVITE_WRONG_ACCOUNT"
12
12
  };
13
- var STATUS = { FORBIDDEN: 403, NOT_A_MEMBER: 404, UNKNOWN_ROLE: 400, LAST_OWNER: 409, ROLE_NOT_ALLOWED: 403, INVITE_INVALID: 400, INVITE_WRONG_ACCOUNT: 403 };
13
+ var STATUS = {
14
+ FORBIDDEN: 403,
15
+ NOT_A_MEMBER: 404,
16
+ UNKNOWN_ROLE: 400,
17
+ LAST_OWNER: 409,
18
+ ROLE_NOT_ALLOWED: 403,
19
+ INVITE_INVALID: 400,
20
+ INVITE_WRONG_ACCOUNT: 403
21
+ };
14
22
  var RolesError = class extends Error {
15
23
  constructor(code) {
16
24
  super(code);
@@ -28,4 +36,4 @@ export {
28
36
  ROLES_CODE,
29
37
  RolesError
30
38
  };
31
- //# sourceMappingURL=chunk-2PWX2B4I.js.map
39
+ //# sourceMappingURL=chunk-RWKBQE6N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/roles-model.ts"],"sourcesContent":["// The browser-safe half of the roles: the model as data, `can` and the error codes. No `node:*` import, no database: a client component imports it from `@krizaka/auth/client`.\n\n/**\n * Roles per scope (a shop, a workspace), as DATA: a model says which roles exist, which permissions each holds and who may hand which\n * role to whom. The code asks `can(role, \"invoices:write\")`, never `if (role === \"owner\")`. One person may belong to several scopes, with\n * a role in each. Membership and invitations live in the product's PostgreSQL (see `rolesMigration`).\n */\nexport interface RoleModel<Role extends string = string, Permission extends string = string> {\n roles: readonly Role[];\n permissions: Record<Role, readonly Permission[]>;\n /** For each role, the roles it may invite, change and remove (the owner's, typically, is every role). */\n manages: Record<Role, readonly Role[]>;\n}\n\nexport const defineRoles = <const Role extends string, const Permission extends string>(\n model: RoleModel<Role, Permission>,\n): RoleModel<Role, Permission> => model;\n\nexport const can = <Role extends string, Permission extends string>(\n model: RoleModel<Role, Permission>,\n role: Role | null | undefined,\n permission: Permission,\n): boolean => !!role && model.permissions[role].includes(permission);\n\nexport const ROLES_CODE = {\n forbidden: \"FORBIDDEN\",\n notMember: \"NOT_A_MEMBER\",\n unknownRole: \"UNKNOWN_ROLE\",\n lastOwner: \"LAST_OWNER\",\n notAllowed: \"ROLE_NOT_ALLOWED\",\n inviteInvalid: \"INVITE_INVALID\",\n inviteWrongAccount: \"INVITE_WRONG_ACCOUNT\",\n} as const;\nexport type RolesCode = (typeof ROLES_CODE)[keyof typeof ROLES_CODE];\nconst STATUS: Record<RolesCode, number> = {\n FORBIDDEN: 403,\n NOT_A_MEMBER: 404,\n UNKNOWN_ROLE: 400,\n LAST_OWNER: 409,\n ROLE_NOT_ALLOWED: 403,\n INVITE_INVALID: 400,\n INVITE_WRONG_ACCOUNT: 403,\n};\n\nexport class RolesError extends Error {\n readonly status: number;\n constructor(readonly code: RolesCode) {\n super(code);\n this.name = \"RolesError\";\n this.status = STATUS[code];\n }\n}\n"],"mappings":";AAcO,IAAM,cAAc,CACzB,UACgC;AAE3B,IAAM,MAAM,CACjB,OACA,MACA,eACY,CAAC,CAAC,QAAQ,MAAM,YAAY,IAAI,EAAE,SAAS,UAAU;AAE5D,IAAM,aAAa;AAAA,EACxB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,oBAAoB;AACtB;AAEA,IAAM,SAAoC;AAAA,EACxC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,sBAAsB;AACxB;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAEpC,YAAqB,MAAiB;AACpC,UAAM,IAAI;AADS;AAEnB,SAAK,OAAO;AACZ,SAAK,SAAS,OAAO,IAAI;AAAA,EAC3B;AAAA,EAJqB;AAAA,EADZ;AAMX;","names":[]}
package/dist/client.js CHANGED
@@ -3,14 +3,14 @@ import {
3
3
  RolesError,
4
4
  can,
5
5
  defineRoles
6
- } from "./chunk-2PWX2B4I.js";
6
+ } from "./chunk-RWKBQE6N.js";
7
7
  import {
8
8
  ME_HEADERS,
9
9
  ME_PATH,
10
10
  meAccountSchema,
11
11
  meResponse,
12
12
  meSchema
13
- } from "./chunk-G46LWJPQ.js";
13
+ } from "./chunk-3MIBOYLS.js";
14
14
  export {
15
15
  ME_HEADERS,
16
16
  ME_PATH,
package/dist/contract.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  meAccountSchema,
5
5
  meResponse,
6
6
  meSchema
7
- } from "./chunk-G46LWJPQ.js";
7
+ } from "./chunk-3MIBOYLS.js";
8
8
  export {
9
9
  ME_HEADERS,
10
10
  ME_PATH,