@rexezuge/identity 1.6.1 → 1.7.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/UserEmailDAO.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseDAO } from '@rexezuge/d1';
|
|
2
2
|
import type { D1Queryable } from '@rexezuge/d1';
|
|
3
|
+
import type { SubrequestMeter } from '@rexezuge/shared';
|
|
3
4
|
/**
|
|
4
5
|
* One known address for an account.
|
|
5
6
|
*
|
|
@@ -20,7 +21,17 @@ export interface UserEmailRow {
|
|
|
20
21
|
}
|
|
21
22
|
export type EmailClaim = 'claimed' | 'already-claimed';
|
|
22
23
|
export declare class UserEmailDAO extends BaseDAO {
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* @param database The binding.
|
|
26
|
+
* @param meter The invocation's subrequest counter. Optional, and defaulted,
|
|
27
|
+
* because a consumer that meters its own DAOs must be able to meter this one
|
|
28
|
+
* too: a DAO that charges nothing does not under-report loudly, it spends a
|
|
29
|
+
* subrequest the ceiling never saw — and the failure surfaces as the platform
|
|
30
|
+
* terminating an invocation, on no request, with no error in the application.
|
|
31
|
+
* The parameter exists so adopting this class does not silently un-meter a
|
|
32
|
+
* repository whose every other statement is charged.
|
|
33
|
+
*/
|
|
34
|
+
constructor(database: D1Queryable, meter?: SubrequestMeter);
|
|
24
35
|
/**
|
|
25
36
|
* Claim an address for an account.
|
|
26
37
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserEmailDAO.d.ts","sourceRoot":"","sources":["../src/UserEmailDAO.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"UserEmailDAO.d.ts","sourceRoot":"","sources":["../src/UserEmailDAO.ts"],"names":[],"mappings":"AAAA,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s,"name",{value:e,configurable:!0});import{BaseDAO as d}from"@rexezuge/d1";class o extends d{static{a(this,"UserEmailDAO")}constructor(e){super(e)}async register(e){const i=e.email.toLowerCase(),r=await this.get(i);return r&&r.is_verified===1?"already-claimed":(await this.run(`INSERT INTO user_emails (email, user_id, is_verified, created_at)
|
|
1
|
+
var t=Object.defineProperty;var a=(s,e)=>t(s,"name",{value:e,configurable:!0});import{BaseDAO as d}from"@rexezuge/d1";class o extends d{static{a(this,"UserEmailDAO")}constructor(e,i){super(e,i)}async register(e){const i=e.email.toLowerCase(),r=await this.get(i);return r&&r.is_verified===1?"already-claimed":(await this.run(`INSERT INTO user_emails (email, user_id, is_verified, created_at)
|
|
2
2
|
VALUES (?, ?, ?, ?)
|
|
3
3
|
ON CONFLICT(email) DO UPDATE SET user_id = excluded.user_id, is_verified = excluded.is_verified`,[i,e.userId,e.isVerified?1:0,e.now]),"claimed")}async get(e){return this.first("SELECT * FROM user_emails WHERE email = ? LIMIT 1",[e.toLowerCase()])}async resolveVerified(e){return this.first("SELECT * FROM user_emails WHERE email = ? AND is_verified = 1 LIMIT 1",[e.toLowerCase()])}async listByUserId(e){return this.all("SELECT * FROM user_emails WHERE user_id = ? ORDER BY is_verified DESC, created_at ASC",[e])}async revoke(e){await this.run("UPDATE user_emails SET is_verified = 0 WHERE email = ?",[e.toLowerCase()])}async revokeAllVerified(e,i){await this.run("UPDATE user_emails SET is_verified = 0 WHERE user_id = ? AND email != ?",[e,i.toLowerCase()])}}export{o as UserEmailDAO};
|
package/dist/UserEmailDAO.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/UserEmailDAO.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseDAO } from '@rexezuge/d1';\nimport type { D1Queryable } from '@rexezuge/d1';\n\n/**\n * One known address for an account.\n *\n * `is_verified` gates login: `1` means the address may authenticate the\n * account, `0` means it was changed away from and is retained only so rows\n * written before the change still resolve. A revoked row is re-pointed (not\n * deleted) when a later account legitimately claims the address, so an address\n * is never permanently reserved.\n *\n * Converged from `backend-data/src/dao/UserEmailDAO.ts` (identical in Durable-DAV,\n * Durable-DAV-Router, Edge-Git, Mail-Otter).\n */\nexport interface UserEmailRow {\n email: string;\n user_id: string;\n is_verified: number;\n created_at: number;\n}\n\nexport type EmailClaim = 'claimed' | 'already-claimed';\n\nexport class UserEmailDAO extends BaseDAO {\n public constructor(database: D1Queryable) {\n super(database);\n }\n\n /**\n * Claim an address for an account.\n *\n * An existing verified row is left alone: the address already belongs to\n * someone, and silently re-pointing it would hand one account's identity to\n * another. Callers check `resolveVerified` first and reject on a hit.\n * An unverified (revoked) row is re-pointed, which releases the address.\n */\n public async register(input: { email: string; userId: string; isVerified: boolean; now: number }): Promise<EmailClaim> {\n const email = input.email.toLowerCase();\n const existing = await this.get(email);\n if (existing && existing.is_verified === 1) return 'already-claimed';\n await this.run(\n `INSERT INTO user_emails (email, user_id, is_verified, created_at)\n VALUES (?, ?, ?, ?)\n ON CONFLICT(email) DO UPDATE SET user_id = excluded.user_id, is_verified = excluded.is_verified`,\n [email, input.userId, input.isVerified ? 1 : 0, input.now],\n );\n return 'claimed';\n }\n\n public async get(email: string): Promise<UserEmailRow | null> {\n // Lowercase the *parameter*: the column is stored lowercased by every\n // writer, so `lower(email) = ?` matched identically while making the\n // primary key unusable.\n return this.first<UserEmailRow>('SELECT * FROM user_emails WHERE email = ? LIMIT 1', [email.toLowerCase()]);\n }\n\n /**\n Login resolution: only a verified address identifies an account.\n */\n public async resolveVerified(email: string): Promise<UserEmailRow | null> {\n return this.first<UserEmailRow>('SELECT * FROM user_emails WHERE email = ? AND is_verified = 1 LIMIT 1', [email.toLowerCase()]);\n }\n\n public async listByUserId(userId: string): Promise<UserEmailRow[]> {\n return this.all<UserEmailRow>('SELECT * FROM user_emails WHERE user_id = ? ORDER BY is_verified DESC, created_at ASC', [userId]);\n }\n\n /**\n Revoke an address for login while keeping it resolvable for attribution.\n */\n public async revoke(email: string): Promise<void> {\n await this.run('UPDATE user_emails SET is_verified = 0 WHERE email = ?', [email.toLowerCase()]);\n }\n\n /**\n * Revoke every verified address for an account. Used when an account's login\n * address changes, so only the new address can authenticate it.\n */\n public async revokeAllVerified(userId: string, exceptEmail: string): Promise<void> {\n await this.run('UPDATE user_emails SET is_verified = 0 WHERE user_id = ? AND email != ?', [userId, exceptEmail.toLowerCase()]);\n }\n}\n"],
|
|
5
|
-
"mappings": "+EAAA,OAAS,WAAAA,MAAe,
|
|
6
|
-
"names": ["BaseDAO", "UserEmailDAO", "__name", "database", "input", "email", "existing", "userId", "exceptEmail"]
|
|
4
|
+
"sourcesContent": ["import { BaseDAO } from '@rexezuge/d1';\nimport type { D1Queryable } from '@rexezuge/d1';\nimport type { SubrequestMeter } from '@rexezuge/shared';\n\n/**\n * One known address for an account.\n *\n * `is_verified` gates login: `1` means the address may authenticate the\n * account, `0` means it was changed away from and is retained only so rows\n * written before the change still resolve. A revoked row is re-pointed (not\n * deleted) when a later account legitimately claims the address, so an address\n * is never permanently reserved.\n *\n * Converged from `backend-data/src/dao/UserEmailDAO.ts` (identical in Durable-DAV,\n * Durable-DAV-Router, Edge-Git, Mail-Otter).\n */\nexport interface UserEmailRow {\n email: string;\n user_id: string;\n is_verified: number;\n created_at: number;\n}\n\nexport type EmailClaim = 'claimed' | 'already-claimed';\n\nexport class UserEmailDAO extends BaseDAO {\n /**\n * @param database The binding.\n * @param meter The invocation's subrequest counter. Optional, and defaulted,\n * because a consumer that meters its own DAOs must be able to meter this one\n * too: a DAO that charges nothing does not under-report loudly, it spends a\n * subrequest the ceiling never saw — and the failure surfaces as the platform\n * terminating an invocation, on no request, with no error in the application.\n * The parameter exists so adopting this class does not silently un-meter a\n * repository whose every other statement is charged.\n */\n public constructor(database: D1Queryable, meter?: SubrequestMeter) {\n super(database, meter);\n }\n\n /**\n * Claim an address for an account.\n *\n * An existing verified row is left alone: the address already belongs to\n * someone, and silently re-pointing it would hand one account's identity to\n * another. Callers check `resolveVerified` first and reject on a hit.\n * An unverified (revoked) row is re-pointed, which releases the address.\n */\n public async register(input: { email: string; userId: string; isVerified: boolean; now: number }): Promise<EmailClaim> {\n const email = input.email.toLowerCase();\n const existing = await this.get(email);\n if (existing && existing.is_verified === 1) return 'already-claimed';\n await this.run(\n `INSERT INTO user_emails (email, user_id, is_verified, created_at)\n VALUES (?, ?, ?, ?)\n ON CONFLICT(email) DO UPDATE SET user_id = excluded.user_id, is_verified = excluded.is_verified`,\n [email, input.userId, input.isVerified ? 1 : 0, input.now],\n );\n return 'claimed';\n }\n\n public async get(email: string): Promise<UserEmailRow | null> {\n // Lowercase the *parameter*: the column is stored lowercased by every\n // writer, so `lower(email) = ?` matched identically while making the\n // primary key unusable.\n return this.first<UserEmailRow>('SELECT * FROM user_emails WHERE email = ? LIMIT 1', [email.toLowerCase()]);\n }\n\n /**\n Login resolution: only a verified address identifies an account.\n */\n public async resolveVerified(email: string): Promise<UserEmailRow | null> {\n return this.first<UserEmailRow>('SELECT * FROM user_emails WHERE email = ? AND is_verified = 1 LIMIT 1', [email.toLowerCase()]);\n }\n\n public async listByUserId(userId: string): Promise<UserEmailRow[]> {\n return this.all<UserEmailRow>('SELECT * FROM user_emails WHERE user_id = ? ORDER BY is_verified DESC, created_at ASC', [userId]);\n }\n\n /**\n Revoke an address for login while keeping it resolvable for attribution.\n */\n public async revoke(email: string): Promise<void> {\n await this.run('UPDATE user_emails SET is_verified = 0 WHERE email = ?', [email.toLowerCase()]);\n }\n\n /**\n * Revoke every verified address for an account. Used when an account's login\n * address changes, so only the new address can authenticate it.\n */\n public async revokeAllVerified(userId: string, exceptEmail: string): Promise<void> {\n await this.run('UPDATE user_emails SET is_verified = 0 WHERE user_id = ? AND email != ?', [userId, exceptEmail.toLowerCase()]);\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,WAAAA,MAAe,eAyBlB,MAAOC,UAAqBD,CAAO,CAzBzC,MAyByC,CAAAE,EAAA,qBAWvC,YAAmBC,EAAuBC,EAAuB,CAC/D,MAAMD,EAAUC,CAAK,CACvB,CAUO,MAAM,SAASC,EAA0E,CAC9F,MAAMC,EAAQD,EAAM,MAAM,YAAW,EAC/BE,EAAW,MAAM,KAAK,IAAID,CAAK,EACrC,OAAIC,GAAYA,EAAS,cAAgB,EAAU,mBACnD,MAAM,KAAK,IACT;;wGAGA,CAACD,EAAOD,EAAM,OAAQA,EAAM,WAAa,EAAI,EAAGA,EAAM,GAAG,CAAC,EAErD,UACT,CAEO,MAAM,IAAIC,EAAa,CAI5B,OAAO,KAAK,MAAoB,oDAAqD,CAACA,EAAM,YAAW,CAAE,CAAC,CAC5G,CAKO,MAAM,gBAAgBA,EAAa,CACxC,OAAO,KAAK,MAAoB,wEAAyE,CAACA,EAAM,YAAW,CAAE,CAAC,CAChI,CAEO,MAAM,aAAaE,EAAc,CACtC,OAAO,KAAK,IAAkB,wFAAyF,CAACA,CAAM,CAAC,CACjI,CAKO,MAAM,OAAOF,EAAa,CAC/B,MAAM,KAAK,IAAI,yDAA0D,CAACA,EAAM,YAAW,CAAE,CAAC,CAChG,CAMO,MAAM,kBAAkBE,EAAgBC,EAAmB,CAChE,MAAM,KAAK,IAAI,0EAA2E,CAACD,EAAQC,EAAY,YAAW,CAAE,CAAC,CAC/H",
|
|
6
|
+
"names": ["BaseDAO", "UserEmailDAO", "__name", "database", "meter", "input", "email", "existing", "userId", "exceptEmail"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/identity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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/shared": "1.
|
|
30
|
-
"@rexezuge/
|
|
28
|
+
"@rexezuge/errors": "1.7.1",
|
|
29
|
+
"@rexezuge/shared": "1.7.1",
|
|
30
|
+
"@rexezuge/d1": "1.7.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "26.6.4",
|