@rexezuge/identity 1.9.0 → 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.
- package/dist/UserDAO.d.ts +8 -0
- package/dist/UserDAO.d.ts.map +1 -1
- package/dist/UserDAO.js +1 -1
- package/dist/UserDAO.js.map +2 -2
- package/package.json +4 -4
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;I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K,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.9.
|
|
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/d1": "1.9.
|
|
29
|
-
"@rexezuge/errors": "1.9.
|
|
30
|
-
"@rexezuge/shared": "1.9.
|
|
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",
|