@rexezuge/identity 1.8.2 → 1.9.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResolvedAccount.d.ts","sourceRoot":"","sources":["../src/ResolvedAccount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ResolvedAccount.d.ts","sourceRoot":"","sources":["../src/ResolvedAccount.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;EAEE;AACF,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,GAAG,eAAe,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC;AAE9F;;EAEE;AACF,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,GAAG,eAAe,GAAG,IAAI,CAIlE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
|
package/dist/ResolvedAccount.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=Object.defineProperty;var n=(e,a)=>l(e,"name",{value:a,configurable:!0});const r=n(()=>crypto.randomUUID(),"randomUUID");function i(e){return e?.id?{id:e.id,email:(e.current_email??e.email).toLowerCase(),anchorEmail:e.email,username:e.username??null}:null}n(i,"summarize");function t(){return`usr_${r().replaceAll("-","")}`}n(t,"newAccountId");function c(){return`anchor-${r().replaceAll("-","")}@users.invalid`}n(c,"newAnchor");export{t as newAccountId,c as newAnchor,i as summarize};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/ResolvedAccount.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "+EAAA,
|
|
6
|
-
"names": ["randomUUID", "
|
|
4
|
+
"sourcesContent": ["/**\n * A v4 UUID.\n *\n * The global `crypto`, not `node:crypto`. Both APIs produce the same value, but\n * only one of them resolves everywhere this kit runs: `node:crypto`'s\n * *specifier* is a Node builtin, so a Worker needs either a compatibility date\n * of 2026-08-04 or later, or an explicit `nodejs_compat` flag, before the\n * module resolves at all. `globalThis.crypto.randomUUID` is a Web Crypto method,\n * natively implemented in the Workers runtime and in Node 19+, and needs\n * neither.\n *\n * This mattered because a consumer that adopted `@rexezuge/identity` without\n * knowing it inherited a `nodejs_compat` requirement. That failure is invisible\n * at build time and surfaces only on the account-creation path at runtime, in a\n * Worker deployed with `compatibility_flags: []` — which is exactly how two of\n * the family repos are configured.\n */\nconst randomUUID = (): string => crypto.randomUUID();\n\n/**\n * `users` rows — the stored form of an account.\n *\n * Converged from `backend-data/src/dao/UserDAO.ts` + its `UserRow` (identical in\n * six of the seven identity-carrying repos; AWS and ChordDHT keep only the\n * id/email core).\n *\n * `id` is the stable account key. `email` is the *anchor*: an immutable value\n * that legacy `*_email` foreign keys resolve against, so history stays\n * resolvable across an address change. `current_email` is the address the\n * account signs in with and the one APIs report.\n */\nexport interface UserRow {\n id?: string | null;\n /**\n * The frozen anchor address. Never updated — it is the foreign-key target\n * every legacy `*_email` value resolves against, and rewriting it would\n * cascade the rows that reference it. Read `current_email` for sign-in.\n */\n email: string;\n /**\n * Mutable sign-in address. Absent on a pre-identity database, where `email`\n * *is* the sign-in address; read it as `current_email ?? email`.\n */\n current_email?: string | null;\n created_at: number;\n username: string | null;\n updated_at: number | null;\n}\n\n/**\n * A resolved account.\n *\n * `id` is the only value that should be used as an identity. `email` is the\n * address the account currently signs in with; `anchorEmail` is the immutable\n * value legacy columns store, and is what a pre-identity row can still be\n * matched on.\n */\nexport interface ResolvedAccount {\n id: string;\n email: string;\n anchorEmail: string;\n username: string | null;\n}\n\n/**\nThe denormalized subset routes and the permission path use.\n*/\nexport type AccountSummary = Pick<ResolvedAccount, 'id' | 'email' | 'username'>;\n\n/**\n * Shape every `users` read has, whether or not the identity migration has run.\n *\n * `| null` for the absent row because that is what `UserDAO` returns now — the\n * DAO layer answers `null` for \"no row\", matching D1 and KV. The union is\n * widened into `summarize` rather than normalised there, so `summarize` accepts\n * either a row or the absence of one without a caller rewriting it first.\n */\nexport type UserRowLike = Pick<UserRow, 'id' | 'email' | 'current_email' | 'username'> | null;\n\n/**\nProject a `users` row onto a `ResolvedAccount`.\n*/\nexport function summarize(row: UserRowLike): ResolvedAccount | null {\n return row?.id\n ? { id: row.id, email: (row.current_email ?? row.email).toLowerCase(), anchorEmail: row.email, username: row.username ?? null }\n : null;\n}\n\n/**\n * The opaque account id.\n *\n * Prefixed so an id is never mistaken for an address in a log line or a URL,\n * and random at 128 bits so accounts are not enumerable.\n */\nexport function newAccountId(): string {\n return `usr_${randomUUID().replaceAll('-', '')}`;\n}\n\n/**\n * Opaque anchor for an account whose login address is already held as another\n * account's anchor.\n *\n * It must be globally unique and must never be a real address: `email` is the\n * anchor every legacy `*_email` foreign key resolves against, so an address\n * parked here could never be re-registered by a different person after its\n * original account moved off it. `.invalid` is reserved by RFC 2606 and can\n * never be delivered to, so it can never authenticate either.\n */\nexport function newAnchor(): string {\n return `anchor-${randomUUID().replaceAll('-', '')}@users.invalid`;\n}\n"],
|
|
5
|
+
"mappings": "+EAiBA,MAAMA,EAAaC,EAAA,IAAc,OAAO,WAAU,EAA/B,cAiEb,SAAUC,EAAUC,EAAgB,CACxC,OAAOA,GAAK,GACR,CAAE,GAAIA,EAAI,GAAI,OAAQA,EAAI,eAAiBA,EAAI,OAAO,YAAW,EAAI,YAAaA,EAAI,MAAO,SAAUA,EAAI,UAAY,IAAI,EAC3H,IACN,CAJgBF,EAAAC,EAAA,aAYV,SAAUE,GAAY,CAC1B,MAAO,OAAOJ,EAAU,EAAG,WAAW,IAAK,EAAE,CAAC,EAChD,CAFgBC,EAAAG,EAAA,gBAcV,SAAUC,GAAS,CACvB,MAAO,UAAUL,EAAU,EAAG,WAAW,IAAK,EAAE,CAAC,gBACnD,CAFgBC,EAAAI,EAAA",
|
|
6
|
+
"names": ["randomUUID", "__name", "summarize", "row", "newAccountId", "newAnchor"]
|
|
7
7
|
}
|
package/dist/UserDAO.d.ts
CHANGED
|
@@ -44,6 +44,14 @@ export declare class UserDAO extends BaseDAO {
|
|
|
44
44
|
* then resolves to nothing, and the opaque-anchor retry fails the same way.
|
|
45
45
|
* Making the no-op detectable here is what keeps registration from stranding
|
|
46
46
|
* an address forever.
|
|
47
|
+
*
|
|
48
|
+
* The row is stamped `updated_at = now` as well as `created_at`. The canonical
|
|
49
|
+
* schema types `updated_at` nullable, so this is additive there — but a
|
|
50
|
+
* consumer whose `updated_at` is `NOT NULL` cannot relax that through `ALTER`,
|
|
51
|
+
* and D1 forbids the table rebuild that could, so omitting the column left
|
|
52
|
+
* `createUser` — and with it the whole identity package — unusable on such a
|
|
53
|
+
* schema. A created account is a touched account: there is no window in which
|
|
54
|
+
* the row exists with no update timestamp.
|
|
47
55
|
*/
|
|
48
56
|
createUser(input: {
|
|
49
57
|
anchor: string;
|
package/dist/UserDAO.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserDAO.d.ts","sourceRoot":"","sources":["../src/UserDAO.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;GASG;AACH,qBAAa,OAAQ,SAAQ,OAAO;gBACf,QAAQ,EAAE,WAAW;IAIxC
|
|
1
|
+
{"version":3,"file":"UserDAO.d.ts","sourceRoot":"","sources":["../src/UserDAO.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;GASG;AACH,qBAAa,OAAQ,SAAQ,OAAO;gBACf,QAAQ,EAAE,WAAW;IAIxC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACU,UAAU,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAe3G;;;;;OAKG;IACU,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5F;;MAEE;IACW,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASzF;;;;;;OAMG;IACU,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAI/D;;MAEE;IACW,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAIzD;;MAEE;IACW,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAItE;;;;;;;OAOG;IACU,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInF;;MAEE;IACW,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAG1E;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAE7B,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/UserDAO.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var n=(t,e)=>E(t,"name",{value:e,configurable:!0});import{BaseDAO as o}from"@rexezuge/d1";import{newAccountId as u}from"./ResolvedAccount.js";function i(t){return t.trim().toLowerCase()}n(i,"normalizeUsername");class
|
|
1
|
+
var E=Object.defineProperty;var n=(t,e)=>E(t,"name",{value:e,configurable:!0});import{BaseDAO as o}from"@rexezuge/d1";import{newAccountId as u}from"./ResolvedAccount.js";function i(t){return t.trim().toLowerCase()}n(i,"normalizeUsername");class L extends o{static{n(this,"UserDAO")}constructor(e){super(e)}async createUser(e){const r=e.anchor.toLowerCase(),s=e.loginEmail.toLowerCase(),a=u();return await this.run("INSERT INTO users (email, created_at, id, current_email, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT DO NOTHING",[r,e.now,a,s,e.now]),(await this.getByEmail(r))?.id===a?a:null}async ensureUsername(e,r,s){await this.run("UPDATE users SET username = COALESCE(username, ?), updated_at = COALESCE(updated_at, ?) WHERE id = ? OR email = ?",[i(r),s,e,e])}async setUsername(e,r,s){await this.run("UPDATE users SET username = ?, updated_at = ? WHERE id = ? OR email = ?",[i(r),s,e,e])}async getByEmail(e){return this.first("SELECT * FROM users WHERE email = ? LIMIT 1",[e.toLowerCase()])}async getById(e){return this.first("SELECT * FROM users WHERE id = ? LIMIT 1",[e])}async getByCurrentEmail(e){return this.first("SELECT * FROM users WHERE current_email = ? LIMIT 1",[e.toLowerCase()])}async setCurrentEmail(e,r,s){await this.run("UPDATE users SET current_email = ?, updated_at = ? WHERE id = ?",[r.toLowerCase(),s,e])}async getByUsernameCi(e){return this.first("SELECT * FROM users WHERE username = ? LIMIT 1",[e.toLowerCase()])}}export{L as UserDAO,i as normalizeUsername};
|
package/dist/UserDAO.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/UserDAO.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseDAO } from '@rexezuge/d1';\nimport type { D1Queryable } from '@rexezuge/d1';\nimport { newAccountId } from './ResolvedAccount.ts';\nimport type { UserRow } from './ResolvedAccount.ts';\n\n/**\n * The stored form of a handle: lowercase.\n *\n * Every username read and every username write goes through this, so the two\n * can never disagree about case. That agreement is not cosmetic: `username` has\n * no `COLLATE NOCASE` (SQLite defaults to BINARY), so a stored `Alice2` is a\n * *different value* from `alice2` and a lookup that lowercased its parameter\n * would never find it. Normalising at the write points rather than relying on\n * each caller means a future caller cannot reintroduce an unfindable handle by\n * forgetting.\n */\nfunction normalizeUsername(username: string): string {\n return username.trim().toLowerCase();\n}\n\n/**\n * `users` rows. Converged from `backend-data/src/dao/UserDAO.ts` (identical in\n * Durable-DAV, Durable-DAV-Router, Edge-Git, Mail-Otter, Mail-Meow; AWS keeps\n * the id/email core without the username methods).\n *\n * Case rule everywhere in this DAO: lowercase the *parameter*, never the\n * column — `lower(col)` makes the index or primary key unusable. It is only\n * sound because every writer stores lowercase through this DAO's own\n * normalisers.\n */\nexport class UserDAO extends BaseDAO {\n public constructor(database: D1Queryable) {\n super(database);\n }\n\n /**\n * Create an account, stamped with the identity columns.\n *\n * `INSERT ... ON CONFLICT DO NOTHING` with **no conflict target**, deliberately.\n * `users` carries two unique constraints — the anchor primary key and the\n * unique index on `current_email` — and SQLite applies `DO NOTHING` only to\n * the constraints a named target covers. Naming the anchor therefore left a\n * `current_email` collision as a raised error, which callers cannot tell from\n * a transient D1 failure: it propagated instead of returning `null`, so the\n * opaque-anchor retry never ran and every login request answered 500.\n *\n * Returns the new account's id, or `null` when the insert was a silent no-op —\n * which this DAO establishes by reading the anchor row back and requiring its\n * own generated id to be the one there. The read-back lives here rather than\n * in the caller because a caller that trusted the generated id on a taken\n * anchor would point the address registry at a *phantom* account: the address\n * then resolves to nothing, and the opaque-anchor retry fails the same way.\n * Making the no-op detectable here is what keeps registration from stranding\n * an address forever.\n */\n public async createUser(input: { anchor: string; loginEmail: string; now: number }): Promise<string | null> {\n const anchor = input.anchor.toLowerCase();\n const loginEmail = input.loginEmail.toLowerCase();\n const id = newAccountId();\n await this.run('INSERT INTO users (email, created_at, id, current_email) VALUES (?, ?, ?, ?) ON CONFLICT DO NOTHING', [\n anchor,\n input.now,\n id,\n loginEmail,\n ]);\n const row = await this.getByEmail(anchor);\n return row?.id === id ? id : null;\n }\n\n /**\n * @param idOrEmail The stable account key, or an anchor address as the\n * pre-identity fallback. `WHERE id = ? OR email = ?` cannot use either index\n * as a seek, so this stays off the hot path; login resolves through\n * `UserIdentityService` instead.\n */\n public async ensureUsername(idOrEmail: string, username: string, now: number): Promise<void> {\n await this.run('UPDATE users SET username = COALESCE(username, ?), updated_at = COALESCE(updated_at, ?) WHERE id = ? OR email = ?', [\n normalizeUsername(username),\n now,\n idOrEmail,\n idOrEmail,\n ]);\n }\n\n /**\n @param idOrEmail The stable account key, or an anchor address.\n */\n public async setUsername(idOrEmail: string, username: string, now: number): Promise<void> {\n await this.run('UPDATE users SET username = ?, updated_at = ? WHERE id = ? OR email = ?', [\n normalizeUsername(username),\n now,\n idOrEmail,\n idOrEmail,\n ]);\n }\n\n /**\n * Anchor lookup — used for legacy `*_email` values and cascade resolution.\n *\n * This is *not* a login lookup: an account that has changed its address is not\n * findable here by its new one. It is the pre-identity floor and the\n * attribution read.\n */\n public async getByEmail(email: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE email = ? LIMIT 1', [email.toLowerCase()]);\n }\n\n /**\n The account behind a stable key. Null on a pre-identity database.\n */\n public async getById(id: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE id = ? LIMIT 1', [id]);\n }\n\n /**\n The account currently signing in with this address. Identity-era only.\n */\n public async getByCurrentEmail(email: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE current_email = ? LIMIT 1', [email.toLowerCase()]);\n }\n\n /**\n * Move an account's sign-in address.\n *\n * The anchor `email` is deliberately untouched: it is what every legacy\n * `*_email` column and foreign key resolves against. Ordering matters — the\n * caller claims the new address first and revokes the old one third, so a\n * failure between steps never leaves the account without a way to sign in.\n */\n public async setCurrentEmail(id: string, email: string, now: number): Promise<void> {\n await this.run('UPDATE users SET current_email = ?, updated_at = ? WHERE id = ?', [email.toLowerCase(), now, id]);\n }\n\n /**\n Lookup by handle.\n */\n public async getByUsernameCi(usernameCi: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE username = ? LIMIT 1', [usernameCi.toLowerCase()]);\n }\n}\n\nexport { normalizeUsername };\n\nexport { type UserRow } from './ResolvedAccount.ts';\n"],
|
|
5
|
-
"mappings": "+EAAA,OAAS,WAAAA,MAAe,eAExB,OAAS,gBAAAC,MAAoB,uBAc7B,SAASC,EAAkBC,EAAgB,CACzC,OAAOA,EAAS,KAAI,EAAG,YAAW,CACpC,CAFSC,EAAAF,EAAA,qBAcH,MAAOG,UAAgBL,CAAO,CA9BpC,MA8BoC,CAAAI,EAAA,gBAClC,YAAmBE,EAAqB,CACtC,MAAMA,CAAQ,CAChB,
|
|
4
|
+
"sourcesContent": ["import { BaseDAO } from '@rexezuge/d1';\nimport type { D1Queryable } from '@rexezuge/d1';\nimport { newAccountId } from './ResolvedAccount.ts';\nimport type { UserRow } from './ResolvedAccount.ts';\n\n/**\n * The stored form of a handle: lowercase.\n *\n * Every username read and every username write goes through this, so the two\n * can never disagree about case. That agreement is not cosmetic: `username` has\n * no `COLLATE NOCASE` (SQLite defaults to BINARY), so a stored `Alice2` is a\n * *different value* from `alice2` and a lookup that lowercased its parameter\n * would never find it. Normalising at the write points rather than relying on\n * each caller means a future caller cannot reintroduce an unfindable handle by\n * forgetting.\n */\nfunction normalizeUsername(username: string): string {\n return username.trim().toLowerCase();\n}\n\n/**\n * `users` rows. Converged from `backend-data/src/dao/UserDAO.ts` (identical in\n * Durable-DAV, Durable-DAV-Router, Edge-Git, Mail-Otter, Mail-Meow; AWS keeps\n * the id/email core without the username methods).\n *\n * Case rule everywhere in this DAO: lowercase the *parameter*, never the\n * column — `lower(col)` makes the index or primary key unusable. It is only\n * sound because every writer stores lowercase through this DAO's own\n * normalisers.\n */\nexport class UserDAO extends BaseDAO {\n public constructor(database: D1Queryable) {\n super(database);\n }\n\n /**\n * Create an account, stamped with the identity columns.\n *\n * `INSERT ... ON CONFLICT DO NOTHING` with **no conflict target**, deliberately.\n * `users` carries two unique constraints — the anchor primary key and the\n * unique index on `current_email` — and SQLite applies `DO NOTHING` only to\n * the constraints a named target covers. Naming the anchor therefore left a\n * `current_email` collision as a raised error, which callers cannot tell from\n * a transient D1 failure: it propagated instead of returning `null`, so the\n * opaque-anchor retry never ran and every login request answered 500.\n *\n * Returns the new account's id, or `null` when the insert was a silent no-op —\n * which this DAO establishes by reading the anchor row back and requiring its\n * own generated id to be the one there. The read-back lives here rather than\n * in the caller because a caller that trusted the generated id on a taken\n * anchor would point the address registry at a *phantom* account: the address\n * then resolves to nothing, and the opaque-anchor retry fails the same way.\n * Making the no-op detectable here is what keeps registration from stranding\n * an address forever.\n *\n * The row is stamped `updated_at = now` as well as `created_at`. The canonical\n * schema types `updated_at` nullable, so this is additive there — but a\n * consumer whose `updated_at` is `NOT NULL` cannot relax that through `ALTER`,\n * and D1 forbids the table rebuild that could, so omitting the column left\n * `createUser` — and with it the whole identity package — unusable on such a\n * schema. A created account is a touched account: there is no window in which\n * the row exists with no update timestamp.\n */\n public async createUser(input: { anchor: string; loginEmail: string; now: number }): Promise<string | null> {\n const anchor = input.anchor.toLowerCase();\n const loginEmail = input.loginEmail.toLowerCase();\n const id = newAccountId();\n await this.run('INSERT INTO users (email, created_at, id, current_email, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT DO NOTHING', [\n anchor,\n input.now,\n id,\n loginEmail,\n input.now,\n ]);\n const row = await this.getByEmail(anchor);\n return row?.id === id ? id : null;\n }\n\n /**\n * @param idOrEmail The stable account key, or an anchor address as the\n * pre-identity fallback. `WHERE id = ? OR email = ?` cannot use either index\n * as a seek, so this stays off the hot path; login resolves through\n * `UserIdentityService` instead.\n */\n public async ensureUsername(idOrEmail: string, username: string, now: number): Promise<void> {\n await this.run('UPDATE users SET username = COALESCE(username, ?), updated_at = COALESCE(updated_at, ?) WHERE id = ? OR email = ?', [\n normalizeUsername(username),\n now,\n idOrEmail,\n idOrEmail,\n ]);\n }\n\n /**\n @param idOrEmail The stable account key, or an anchor address.\n */\n public async setUsername(idOrEmail: string, username: string, now: number): Promise<void> {\n await this.run('UPDATE users SET username = ?, updated_at = ? WHERE id = ? OR email = ?', [\n normalizeUsername(username),\n now,\n idOrEmail,\n idOrEmail,\n ]);\n }\n\n /**\n * Anchor lookup — used for legacy `*_email` values and cascade resolution.\n *\n * This is *not* a login lookup: an account that has changed its address is not\n * findable here by its new one. It is the pre-identity floor and the\n * attribution read.\n */\n public async getByEmail(email: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE email = ? LIMIT 1', [email.toLowerCase()]);\n }\n\n /**\n The account behind a stable key. Null on a pre-identity database.\n */\n public async getById(id: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE id = ? LIMIT 1', [id]);\n }\n\n /**\n The account currently signing in with this address. Identity-era only.\n */\n public async getByCurrentEmail(email: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE current_email = ? LIMIT 1', [email.toLowerCase()]);\n }\n\n /**\n * Move an account's sign-in address.\n *\n * The anchor `email` is deliberately untouched: it is what every legacy\n * `*_email` column and foreign key resolves against. Ordering matters — the\n * caller claims the new address first and revokes the old one third, so a\n * failure between steps never leaves the account without a way to sign in.\n */\n public async setCurrentEmail(id: string, email: string, now: number): Promise<void> {\n await this.run('UPDATE users SET current_email = ?, updated_at = ? WHERE id = ?', [email.toLowerCase(), now, id]);\n }\n\n /**\n Lookup by handle.\n */\n public async getByUsernameCi(usernameCi: string): Promise<UserRow | null> {\n return this.first<UserRow>('SELECT * FROM users WHERE username = ? LIMIT 1', [usernameCi.toLowerCase()]);\n }\n}\n\nexport { normalizeUsername };\n\nexport { type UserRow } from './ResolvedAccount.ts';\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,WAAAA,MAAe,eAExB,OAAS,gBAAAC,MAAoB,uBAc7B,SAASC,EAAkBC,EAAgB,CACzC,OAAOA,EAAS,KAAI,EAAG,YAAW,CACpC,CAFSC,EAAAF,EAAA,qBAcH,MAAOG,UAAgBL,CAAO,CA9BpC,MA8BoC,CAAAI,EAAA,gBAClC,YAAmBE,EAAqB,CACtC,MAAMA,CAAQ,CAChB,CA8BO,MAAM,WAAWC,EAA0D,CAChF,MAAMC,EAASD,EAAM,OAAO,YAAW,EACjCE,EAAaF,EAAM,WAAW,YAAW,EACzCG,EAAKT,EAAY,EACvB,aAAM,KAAK,IAAI,qHAAsH,CACnIO,EACAD,EAAM,IACNG,EACAD,EACAF,EAAM,IACP,GACW,MAAM,KAAK,WAAWC,CAAM,IAC5B,KAAOE,EAAKA,EAAK,IAC/B,CAQO,MAAM,eAAeC,EAAmBR,EAAkBS,EAAW,CAC1E,MAAM,KAAK,IAAI,oHAAqH,CAClIV,EAAkBC,CAAQ,EAC1BS,EACAD,EACAA,EACD,CACH,CAKO,MAAM,YAAYA,EAAmBR,EAAkBS,EAAW,CACvE,MAAM,KAAK,IAAI,0EAA2E,CACxFV,EAAkBC,CAAQ,EAC1BS,EACAD,EACAA,EACD,CACH,CASO,MAAM,WAAWE,EAAa,CACnC,OAAO,KAAK,MAAe,8CAA+C,CAACA,EAAM,YAAW,CAAE,CAAC,CACjG,CAKO,MAAM,QAAQH,EAAU,CAC7B,OAAO,KAAK,MAAe,2CAA4C,CAACA,CAAE,CAAC,CAC7E,CAKO,MAAM,kBAAkBG,EAAa,CAC1C,OAAO,KAAK,MAAe,sDAAuD,CAACA,EAAM,YAAW,CAAE,CAAC,CACzG,CAUO,MAAM,gBAAgBH,EAAYG,EAAeD,EAAW,CACjE,MAAM,KAAK,IAAI,kEAAmE,CAACC,EAAM,YAAW,EAAID,EAAKF,CAAE,CAAC,CAClH,CAKO,MAAM,gBAAgBI,EAAkB,CAC7C,OAAO,KAAK,MAAe,iDAAkD,CAACA,EAAW,YAAW,CAAE,CAAC,CACzG",
|
|
6
6
|
"names": ["BaseDAO", "newAccountId", "normalizeUsername", "username", "__name", "UserDAO", "database", "input", "anchor", "loginEmail", "id", "idOrEmail", "now", "email", "usernameCi"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/identity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@rexezuge/
|
|
29
|
-
"@rexezuge/
|
|
30
|
-
"@rexezuge/shared": "1.
|
|
28
|
+
"@rexezuge/d1": "1.9.1",
|
|
29
|
+
"@rexezuge/errors": "1.9.1",
|
|
30
|
+
"@rexezuge/shared": "1.9.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "26.6.4",
|