@sharadox/account-web-library 0.1.0-development.24 → 0.1.0-development.27
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/README.md +95 -20
- package/distribution/account-activity/index.d.ts +16 -0
- package/distribution/account-activity/index.d.ts.map +1 -0
- package/distribution/account-activity/index.js +18 -0
- package/distribution/account-activity/index.js.map +1 -0
- package/distribution/account-activity/type.d.ts +15 -0
- package/distribution/account-activity/type.d.ts.map +1 -0
- package/distribution/account-activity/type.js.map +1 -0
- package/distribution/account-database/type.d.ts +57 -4
- package/distribution/account-database/type.d.ts.map +1 -1
- package/distribution/account-deletion/index.d.ts +18 -0
- package/distribution/account-deletion/index.d.ts.map +1 -0
- package/distribution/account-deletion/index.js +28 -0
- package/distribution/account-deletion/index.js.map +1 -0
- package/distribution/account-export/index.d.ts +17 -0
- package/distribution/account-export/index.d.ts.map +1 -0
- package/distribution/account-export/index.js +87 -0
- package/distribution/account-export/index.js.map +1 -0
- package/distribution/account-export/type.d.ts +40 -0
- package/distribution/account-export/type.d.ts.map +1 -0
- package/distribution/{username-change → account-export}/type.js.map +1 -1
- package/distribution/account-migration/index.d.ts.map +1 -1
- package/distribution/account-migration/index.js +110 -0
- package/distribution/account-migration/index.js.map +1 -1
- package/distribution/account-name/index.d.ts +13 -0
- package/distribution/account-name/index.d.ts.map +1 -0
- package/distribution/account-name/index.js +22 -0
- package/distribution/account-name/index.js.map +1 -0
- package/distribution/account-name/type.d.ts +9 -0
- package/distribution/account-name/type.d.ts.map +1 -0
- package/distribution/account-name/type.js +2 -0
- package/distribution/account-name/type.js.map +1 -0
- package/distribution/account-name-change/index.d.ts +15 -0
- package/distribution/account-name-change/index.d.ts.map +1 -0
- package/distribution/account-name-change/index.js +26 -0
- package/distribution/account-name-change/index.js.map +1 -0
- package/distribution/account-name-change/type.d.ts +7 -0
- package/distribution/account-name-change/type.d.ts.map +1 -0
- package/distribution/account-name-change/type.js +2 -0
- package/distribution/account-name-change/type.js.map +1 -0
- package/distribution/account-picture-change/index.d.ts +30 -0
- package/distribution/account-picture-change/index.d.ts.map +1 -0
- package/distribution/account-picture-change/index.js +70 -0
- package/distribution/account-picture-change/index.js.map +1 -0
- package/distribution/account-picture-change/type.d.ts +11 -0
- package/distribution/account-picture-change/type.d.ts.map +1 -0
- package/distribution/account-picture-change/type.js +2 -0
- package/distribution/account-picture-change/type.js.map +1 -0
- package/distribution/account-server/index.d.ts +11 -1
- package/distribution/account-server/index.d.ts.map +1 -1
- package/distribution/account-server/index.js +12 -1
- package/distribution/account-server/index.js.map +1 -1
- package/distribution/account-server/type.d.ts +2 -0
- package/distribution/account-server/type.d.ts.map +1 -1
- package/distribution/account-session-end/index.d.ts +15 -0
- package/distribution/account-session-end/index.d.ts.map +1 -0
- package/distribution/account-session-end/index.js +21 -0
- package/distribution/account-session-end/index.js.map +1 -0
- package/distribution/account-session-list/index.d.ts +16 -0
- package/distribution/account-session-list/index.d.ts.map +1 -0
- package/distribution/account-session-list/index.js +33 -0
- package/distribution/account-session-list/index.js.map +1 -0
- package/distribution/account-session-list/type.d.ts +13 -0
- package/distribution/account-session-list/type.d.ts.map +1 -0
- package/distribution/account-session-list/type.js +2 -0
- package/distribution/account-session-list/type.js.map +1 -0
- package/distribution/account-sign-in/index.d.ts +1 -1
- package/distribution/account-sign-in/index.d.ts.map +1 -1
- package/distribution/account-sign-in/index.js +4 -2
- package/distribution/account-sign-in/index.js.map +1 -1
- package/distribution/account-sign-in/type.d.ts +2 -0
- package/distribution/account-sign-in/type.d.ts.map +1 -1
- package/distribution/audit-event/index.d.ts.map +1 -1
- package/distribution/audit-event/index.js +12 -1
- package/distribution/audit-event/index.js.map +1 -1
- package/distribution/audit-event/type.d.ts +1 -0
- package/distribution/audit-event/type.d.ts.map +1 -1
- package/distribution/browser-session-read/index.d.ts.map +1 -1
- package/distribution/browser-session-read/index.js +5 -1
- package/distribution/browser-session-read/index.js.map +1 -1
- package/distribution/browser-session-read/type.d.ts +5 -1
- package/distribution/browser-session-read/type.d.ts.map +1 -1
- package/distribution/code-request/index.js +1 -1
- package/distribution/code-request/type.d.ts +1 -1
- package/distribution/code-sending/index.d.ts +14 -0
- package/distribution/code-sending/index.d.ts.map +1 -0
- package/distribution/code-sending/index.js +65 -0
- package/distribution/code-sending/index.js.map +1 -0
- package/distribution/code-sending/type.d.ts +31 -0
- package/distribution/code-sending/type.d.ts.map +1 -0
- package/distribution/code-sending/type.js +2 -0
- package/distribution/code-sending/type.js.map +1 -0
- package/distribution/contact-addition-flow/index.d.ts +31 -0
- package/distribution/contact-addition-flow/index.d.ts.map +1 -0
- package/distribution/contact-addition-flow/index.js +85 -0
- package/distribution/contact-addition-flow/index.js.map +1 -0
- package/distribution/contact-addition-flow/type.d.ts +22 -0
- package/distribution/contact-addition-flow/type.d.ts.map +1 -0
- package/distribution/contact-addition-flow/type.js +2 -0
- package/distribution/contact-addition-flow/type.js.map +1 -0
- package/distribution/database-error/index.d.ts +1 -1
- package/distribution/database-error/index.js +1 -1
- package/distribution/email-channel/index.js +1 -1
- package/distribution/identifier/index.d.ts +23 -0
- package/distribution/identifier/index.d.ts.map +1 -0
- package/distribution/identifier/index.js +32 -0
- package/distribution/identifier/index.js.map +1 -0
- package/distribution/identifier/type.d.ts +10 -0
- package/distribution/identifier/type.d.ts.map +1 -0
- package/distribution/identifier/type.js +2 -0
- package/distribution/identifier/type.js.map +1 -0
- package/distribution/identifier-availability/index.d.ts +11 -0
- package/distribution/identifier-availability/index.d.ts.map +1 -0
- package/distribution/identifier-availability/index.js +21 -0
- package/distribution/identifier-availability/index.js.map +1 -0
- package/distribution/identifier-change/index.d.ts +15 -0
- package/distribution/identifier-change/index.d.ts.map +1 -0
- package/distribution/identifier-change/index.js +43 -0
- package/distribution/identifier-change/index.js.map +1 -0
- package/distribution/identifier-change/type.d.ts +7 -0
- package/distribution/identifier-change/type.d.ts.map +1 -0
- package/distribution/identifier-change/type.js +2 -0
- package/distribution/identifier-change/type.js.map +1 -0
- package/distribution/memory-picture-storage/index.d.ts +15 -0
- package/distribution/memory-picture-storage/index.d.ts.map +1 -0
- package/distribution/memory-picture-storage/index.js +16 -0
- package/distribution/memory-picture-storage/index.js.map +1 -0
- package/distribution/one-time-code/index.d.ts +2 -2
- package/distribution/one-time-code/index.js +3 -3
- package/distribution/person-account/index.d.ts +7 -3
- package/distribution/person-account/index.d.ts.map +1 -1
- package/distribution/person-account/index.js +21 -9
- package/distribution/person-account/index.js.map +1 -1
- package/distribution/person-account/type.d.ts +5 -2
- package/distribution/person-account/type.d.ts.map +1 -1
- package/distribution/picture-key/index.d.ts +8 -0
- package/distribution/picture-key/index.d.ts.map +1 -0
- package/distribution/picture-key/index.js +10 -0
- package/distribution/picture-key/index.js.map +1 -0
- package/distribution/picture-preparation/index.d.ts +18 -0
- package/distribution/picture-preparation/index.d.ts.map +1 -0
- package/distribution/picture-preparation/index.js +86 -0
- package/distribution/picture-preparation/index.js.map +1 -0
- package/distribution/picture-preparation/type.d.ts +18 -0
- package/distribution/picture-preparation/type.d.ts.map +1 -0
- package/distribution/picture-preparation/type.js +2 -0
- package/distribution/picture-preparation/type.js.map +1 -0
- package/distribution/picture-storage/type.d.ts +11 -0
- package/distribution/picture-storage/type.d.ts.map +1 -0
- package/distribution/picture-storage/type.js +2 -0
- package/distribution/picture-storage/type.js.map +1 -0
- package/distribution/recovery-code-regeneration/index.d.ts +19 -0
- package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
- package/distribution/recovery-code-regeneration/index.js +34 -0
- package/distribution/recovery-code-regeneration/index.js.map +1 -0
- package/distribution/recovery-code-store/index.d.ts +25 -0
- package/distribution/recovery-code-store/index.d.ts.map +1 -0
- package/distribution/recovery-code-store/index.js +34 -0
- package/distribution/recovery-code-store/index.js.map +1 -0
- package/distribution/second-factor-finish/index.d.ts +12 -0
- package/distribution/second-factor-finish/index.d.ts.map +1 -0
- package/distribution/second-factor-finish/index.js +78 -0
- package/distribution/second-factor-finish/index.js.map +1 -0
- package/distribution/second-factor-finish/type.d.ts +27 -0
- package/distribution/second-factor-finish/type.d.ts.map +1 -0
- package/distribution/second-factor-finish/type.js +2 -0
- package/distribution/second-factor-finish/type.js.map +1 -0
- package/distribution/secret-encryption/index.d.ts +17 -0
- package/distribution/secret-encryption/index.d.ts.map +1 -0
- package/distribution/secret-encryption/index.js +37 -0
- package/distribution/secret-encryption/index.js.map +1 -0
- package/distribution/sign-in-finish/index.d.ts +3 -3
- package/distribution/sign-in-finish/index.d.ts.map +1 -1
- package/distribution/sign-in-finish/index.js +22 -5
- package/distribution/sign-in-finish/index.js.map +1 -1
- package/distribution/sign-in-finish/type.d.ts +8 -1
- package/distribution/sign-in-finish/type.d.ts.map +1 -1
- package/distribution/sign-in-start/index.d.ts +4 -6
- package/distribution/sign-in-start/index.d.ts.map +1 -1
- package/distribution/sign-in-start/index.js +14 -62
- package/distribution/sign-in-start/index.js.map +1 -1
- package/distribution/sign-in-start/type.d.ts +7 -0
- package/distribution/sign-in-start/type.d.ts.map +1 -1
- package/distribution/sign-up-finish/index.d.ts +4 -4
- package/distribution/sign-up-finish/index.d.ts.map +1 -1
- package/distribution/sign-up-finish/index.js +11 -6
- package/distribution/sign-up-finish/index.js.map +1 -1
- package/distribution/sign-up-finish/type.d.ts +6 -1
- package/distribution/sign-up-finish/type.d.ts.map +1 -1
- package/distribution/signed-ticket/index.d.ts +1 -1
- package/distribution/signed-ticket/index.js +1 -1
- package/distribution/step-up/index.d.ts +48 -0
- package/distribution/step-up/index.d.ts.map +1 -0
- package/distribution/step-up/index.js +83 -0
- package/distribution/step-up/index.js.map +1 -0
- package/distribution/step-up/type.d.ts +15 -0
- package/distribution/step-up/type.d.ts.map +1 -0
- package/distribution/step-up/type.js +2 -0
- package/distribution/{username → step-up}/type.js.map +1 -1
- package/distribution/test-person/index.d.ts +14 -0
- package/distribution/test-person/index.d.ts.map +1 -0
- package/distribution/test-person/index.js +20 -0
- package/distribution/test-person/index.js.map +1 -0
- package/distribution/totp/type.d.ts +1 -1
- package/distribution/totp/type.d.ts.map +1 -1
- package/distribution/totp-setup/index.d.ts +50 -0
- package/distribution/totp-setup/index.d.ts.map +1 -0
- package/distribution/totp-setup/index.js +136 -0
- package/distribution/totp-setup/index.js.map +1 -0
- package/distribution/totp-setup/type.d.ts +24 -0
- package/distribution/totp-setup/type.d.ts.map +1 -0
- package/distribution/totp-setup/type.js +2 -0
- package/distribution/totp-setup/type.js.map +1 -0
- package/package.json +4 -3
- package/distribution/username/index.d.ts +0 -23
- package/distribution/username/index.d.ts.map +0 -1
- package/distribution/username/index.js +0 -32
- package/distribution/username/index.js.map +0 -1
- package/distribution/username/type.d.ts +0 -10
- package/distribution/username/type.d.ts.map +0 -1
- package/distribution/username-availability/index.d.ts +0 -11
- package/distribution/username-availability/index.d.ts.map +0 -1
- package/distribution/username-availability/index.js +0 -21
- package/distribution/username-availability/index.js.map +0 -1
- package/distribution/username-change/index.d.ts +0 -15
- package/distribution/username-change/index.d.ts.map +0 -1
- package/distribution/username-change/index.js +0 -39
- package/distribution/username-change/index.js.map +0 -1
- package/distribution/username-change/type.d.ts +0 -7
- package/distribution/username-change/type.d.ts.map +0 -1
- /package/distribution/{username-change → account-activity}/type.js +0 -0
- /package/distribution/{username → account-export}/type.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-session-list/type.ts"],"names":[],"mappings":""}
|
|
@@ -11,5 +11,5 @@ import type { SignInOptions, SignInResult } from "@sharadox/account-web-library/
|
|
|
11
11
|
* const { token } = await signIn(database, { accountId, token: cookies.get("__Host-account")?.value });
|
|
12
12
|
* cookies.set("__Host-account", token, { httpOnly: true, secure: true, sameSite: "lax", path: "/" });
|
|
13
13
|
*/
|
|
14
|
-
export declare function signIn(database: Kysely<AccountDatabase>, { accountId, token, secondFactor, accountSessionSeconds, browserSessionSeconds, now, }: SignInOptions): Promise<SignInResult>;
|
|
14
|
+
export declare function signIn(database: Kysely<AccountDatabase>, { accountId, token, secondFactor, userAgent, accountSessionSeconds, browserSessionSeconds, now, }: SignInOptions): Promise<SignInResult>;
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-sign-in/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAMtG;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,SAAS,EACT,KAAK,EACL,YAAoB,EACpB,qBAAgC,EAChC,qBAAiC,EACjC,GAAgB,GACjB,EAAE,aAAa,GACf,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-sign-in/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAC;AAMtG;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,SAAS,EACT,KAAK,EACL,YAAoB,EACpB,SAAgB,EAChB,qBAAgC,EAChC,qBAAiC,EACjC,GAAgB,GACjB,EAAE,aAAa,GACf,OAAO,CAAC,YAAY,CAAC,CA6DvB"}
|
|
@@ -12,9 +12,10 @@ const DAY = 86_400;
|
|
|
12
12
|
* const { token } = await signIn(database, { accountId, token: cookies.get("__Host-account")?.value });
|
|
13
13
|
* cookies.set("__Host-account", token, { httpOnly: true, secure: true, sameSite: "lax", path: "/" });
|
|
14
14
|
*/
|
|
15
|
-
export async function signIn(database, { accountId, token, secondFactor = false, accountSessionSeconds = 30 * DAY, browserSessionSeconds = 400 * DAY, now = Date.now(), }) {
|
|
15
|
+
export async function signIn(database, { accountId, token, secondFactor = false, userAgent = null, accountSessionSeconds = 30 * DAY, browserSessionSeconds = 400 * DAY, now = Date.now(), }) {
|
|
16
16
|
const at = new Date(now);
|
|
17
17
|
const fresh = createSessionToken();
|
|
18
|
+
const device = userAgent?.slice(0, 500) ?? null;
|
|
18
19
|
return database.transaction().execute(async (transaction) => {
|
|
19
20
|
const browser = token
|
|
20
21
|
? await transaction
|
|
@@ -29,7 +30,7 @@ export async function signIn(database, { accountId, token, secondFactor = false,
|
|
|
29
30
|
if (browser) {
|
|
30
31
|
await transaction
|
|
31
32
|
.updateTable("browser_session")
|
|
32
|
-
.set({ token_hash: fresh.hash, last_seen_at: at })
|
|
33
|
+
.set({ token_hash: fresh.hash, last_seen_at: at, user_agent: device })
|
|
33
34
|
.where("id", "=", browserSessionId)
|
|
34
35
|
.execute();
|
|
35
36
|
}
|
|
@@ -42,6 +43,7 @@ export async function signIn(database, { accountId, token, secondFactor = false,
|
|
|
42
43
|
created_at: at,
|
|
43
44
|
last_seen_at: at,
|
|
44
45
|
expires_at: new Date(now + browserSessionSeconds * 1000),
|
|
46
|
+
user_agent: device,
|
|
45
47
|
})
|
|
46
48
|
.execute();
|
|
47
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-sign-in/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAEnG,MAAM,GAAG,GAAG,MAAM,CA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AAG,EAAE,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3G,MAAM,gBAAgB,CAAC,WAAW,EAAE;YAClC,SAAS;YACT,MAAM,EAAE,mBAAmB;YAC3B,MAAM,EAAE,EAAE,gBAAgB,EAAE,YAAY,EAAE;YAC1C,GAAG;SACJ,CAAC,CAAC;QACH,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -4,6 +4,8 @@ export interface SignInOptions {
|
|
|
4
4
|
token?: string;
|
|
5
5
|
/** Whether two-factor was passed for this sign-in. */
|
|
6
6
|
secondFactor?: boolean;
|
|
7
|
+
/** The browser's User-Agent, shown in the list of devices (kept to 500 characters). */
|
|
8
|
+
userAgent?: string | null;
|
|
7
9
|
/** 30 days by default. */
|
|
8
10
|
accountSessionSeconds?: number;
|
|
9
11
|
/** 400 days by default (the longest a browser keeps a cookie). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-sign-in/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0BAA0B;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kEAAkE;IAClE,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-sign-in/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,0BAA0B;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kEAAkE;IAClE,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/audit-event/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAgB,EAAE,cAAqB,EAAE,WAAkB,EAAE,MAAM,EAAE,MAAW,EAAE,GAAgB,EAAE,EAAE,UAAU,GACjH,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/audit-event/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAgB,EAAE,cAAqB,EAAE,WAAkB,EAAE,MAAM,EAAE,MAAW,EAAE,GAAgB,EAAE,EAAE,UAAU,GACjH,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
|
|
@@ -8,6 +8,17 @@ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
|
8
8
|
*/
|
|
9
9
|
export async function recordAuditEvent(database, { accountId = null, actorAccountId = null, application = null, action, detail = {}, now = Date.now() }) {
|
|
10
10
|
const id = uuidVersion7({ now });
|
|
11
|
+
let applicationId = null;
|
|
12
|
+
if (application !== null) {
|
|
13
|
+
const found = await database
|
|
14
|
+
.selectFrom("application")
|
|
15
|
+
.select("id")
|
|
16
|
+
.where("key", "=", application)
|
|
17
|
+
.executeTakeFirst();
|
|
18
|
+
if (!found)
|
|
19
|
+
throw new Error(`no application "${application}"`);
|
|
20
|
+
applicationId = found.id;
|
|
21
|
+
}
|
|
11
22
|
await database
|
|
12
23
|
.insertInto("audit_event")
|
|
13
24
|
.values({
|
|
@@ -15,7 +26,7 @@ export async function recordAuditEvent(database, { accountId = null, actorAccoun
|
|
|
15
26
|
at: new Date(now),
|
|
16
27
|
account_id: accountId,
|
|
17
28
|
actor_account_id: actorAccountId,
|
|
18
|
-
|
|
29
|
+
application_id: applicationId,
|
|
19
30
|
action,
|
|
20
31
|
detail,
|
|
21
32
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/audit-event/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAI/E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAA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,CAAC;IACD,MAAM,QAAQ;SACX,UAAU,CAAC,aAAa,CAAC;SACzB,MAAM,CAAC;QACN,EAAE;QACF,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC;QACjB,UAAU,EAAE,SAAS;QACrB,gBAAgB,EAAE,cAAc;QAChC,cAAc,EAAE,aAAa;QAC7B,MAAM;QACN,MAAM;KACP,CAAC;SACD,OAAO,EAAE,CAAC;IACb,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -4,6 +4,7 @@ export interface AuditEvent {
|
|
|
4
4
|
accountId?: string | null;
|
|
5
5
|
/** Who did it, when not the account itself. */
|
|
6
6
|
actorAccountId?: string | null;
|
|
7
|
+
/** The application's key (`platform`), stored as its id; it must exist. */
|
|
7
8
|
application?: string | null;
|
|
8
9
|
/** `<subject>.<verb>`: `account.created`, `contact.removed`, `role.granted`… */
|
|
9
10
|
action: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/audit-event/type.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/audit-event/type.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/browser-session-read/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yDAAyD,CAAC;AAG9F;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,KAAK,EACL,WAAwB,EACxB,GAAgB,GACjB,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/browser-session-read/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yDAAyD,CAAC;AAG9F;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,KAAK,EACL,WAAwB,EACxB,GAAgB,GACjB,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CA2CrC"}
|
|
@@ -22,10 +22,14 @@ export async function readBrowserSession(database, { token, idleSeconds = 7 * 86
|
|
|
22
22
|
const rows = await database
|
|
23
23
|
.selectFrom("account_session")
|
|
24
24
|
.innerJoin("account", "account.id", "account_session.account_id")
|
|
25
|
+
.innerJoin("identifier", "identifier.account_id", "account.id")
|
|
26
|
+
.leftJoin("account_picture", "account_picture.account_id", "account.id")
|
|
25
27
|
.select([
|
|
26
28
|
"account_session.id as accountSessionId",
|
|
27
29
|
"account.id as accountId",
|
|
28
|
-
"
|
|
30
|
+
"identifier.value as identifier",
|
|
31
|
+
"account.name as name",
|
|
32
|
+
"account_picture.id as pictureId",
|
|
29
33
|
"account_session.created_at as signedInAt",
|
|
30
34
|
"account_session.second_factor_at as secondFactorAt",
|
|
31
35
|
])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/browser-session-read/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAiC,EACjC,EACE,KAAK,EACL,WAAW,GAAG,CAAC,GAAG,MAAM,EACxB,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GACkD;IAEpE,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,OAAO,GAAG,MAAM,QAAQ;SAC3B,UAAU,CAAC,iBAAiB,CAAC;SAC7B,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,7 +2,11 @@
|
|
|
2
2
|
export interface SignedInAccount {
|
|
3
3
|
accountSessionId: string;
|
|
4
4
|
accountId: string;
|
|
5
|
-
|
|
5
|
+
/** Without the `@`. */
|
|
6
|
+
identifier: string;
|
|
7
|
+
name: string;
|
|
8
|
+
/** The picture's id (its file's name in storage); null without one. */
|
|
9
|
+
pictureId: string | null;
|
|
6
10
|
signedInAt: Date;
|
|
7
11
|
secondFactorAt: Date | null;
|
|
8
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/browser-session-read/type.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/browser-session-read/type.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,IAAI,CAAC;IACjB,cAAc,EAAE,IAAI,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B"}
|
|
@@ -12,7 +12,7 @@ export const CODE_PURPOSES = ["sign-in", "contact-verification", "step-up"];
|
|
|
12
12
|
* const { requestId, code } = await requestCode(database, { purpose: "sign-in", contact, pepper });
|
|
13
13
|
* await channel.send(contact, code); // after answering the request, so timing reveals nothing
|
|
14
14
|
*/
|
|
15
|
-
export async function requestCode(database, { purpose, contact, accountId, pepper, length =
|
|
15
|
+
export async function requestCode(database, { purpose, contact, accountId, pepper, length = 6, lifetimeSeconds = 600, now = Date.now() }) {
|
|
16
16
|
if (!CODE_PURPOSES.includes(purpose))
|
|
17
17
|
throw new Error(`unknown code purpose "${purpose}"`);
|
|
18
18
|
const { kind, value } = normalizeContact(contact);
|
|
@@ -8,7 +8,7 @@ export interface CodeRequestOptions {
|
|
|
8
8
|
accountId?: string;
|
|
9
9
|
/** At least 32 characters, kept outside the database. */
|
|
10
10
|
pepper: string;
|
|
11
|
-
/** Digits (
|
|
11
|
+
/** Digits (6 by default). */
|
|
12
12
|
length?: number;
|
|
13
13
|
/** 600 (10 minutes) by default. */
|
|
14
14
|
lifetimeSeconds?: number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
2
|
+
import type { CodeSending, CodeSendingResult } from "@sharadox/account-web-library/code-sending/type";
|
|
3
|
+
/**
|
|
4
|
+
* Sends a one-time code to a contact, each check cheaper than what it protects: rate limits per contact, per
|
|
5
|
+
* address group (an IPv6 /64 is one visitor) and for everyone; then the channel's daily spending cap (past it,
|
|
6
|
+
* sending pauses: it never spends); then a new code, sent by `deliver` after answering. Each send is recorded in the
|
|
7
|
+
* audit log (`code.sent`, or `code.delivery-failed` with the error, never the code; a failure is thrown).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = await sendCode(server, { purpose: "step-up", contact, channel, accountId, address, language });
|
|
11
|
+
* if (result.status === "sent") after(result.deliver);
|
|
12
|
+
*/
|
|
13
|
+
export declare function sendCode(server: AccountServer, { purpose, contact, channel, accountId, address, language, now }: CodeSending): Promise<CodeSendingResult>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/code-sending/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAGvF,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAGtG;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAgB,EAAE,EAAE,WAAW,GAChG,OAAO,CAAC,iBAAiB,CAAC,CAmD5B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { addressGroup } from "@sharadox/protection-web-library/address-group";
|
|
2
|
+
import { limitRate } from "@sharadox/protection-web-library/rate-limit";
|
|
3
|
+
import { spendFromCap } from "@sharadox/protection-web-library/spending-cap";
|
|
4
|
+
import { signInLimits } from "@sharadox/account-web-library/account-server";
|
|
5
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
6
|
+
import { requestCode } from "@sharadox/account-web-library/code-request";
|
|
7
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
8
|
+
/**
|
|
9
|
+
* Sends a one-time code to a contact, each check cheaper than what it protects: rate limits per contact, per
|
|
10
|
+
* address group (an IPv6 /64 is one visitor) and for everyone; then the channel's daily spending cap (past it,
|
|
11
|
+
* sending pauses: it never spends); then a new code, sent by `deliver` after answering. Each send is recorded in the
|
|
12
|
+
* audit log (`code.sent`, or `code.delivery-failed` with the error, never the code; a failure is thrown).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const result = await sendCode(server, { purpose: "step-up", contact, channel, accountId, address, language });
|
|
16
|
+
* if (result.status === "sent") after(result.deliver);
|
|
17
|
+
*/
|
|
18
|
+
export async function sendCode(server, { purpose, contact, channel, accountId = null, address, language, now = Date.now() }) {
|
|
19
|
+
const limits = signInLimits(server);
|
|
20
|
+
const rate = await limitRate(server.database, [
|
|
21
|
+
{ key: `contact:${contact.kind}:${contact.value}`, rule: limits.perContact },
|
|
22
|
+
{ key: `address:${addressGroup(address)}`, rule: limits.perAddress },
|
|
23
|
+
{ key: "global:sign-in", rule: limits.global },
|
|
24
|
+
], { secret: deriveSecret(server.secret, "rate-limit"), now });
|
|
25
|
+
if (!rate.allowed)
|
|
26
|
+
return { status: "refused", reason: "rate-limit", retryAfterSeconds: rate.retryAfterSeconds };
|
|
27
|
+
const cap = await spendFromCap(server.database, { name: `${contact.kind}-send`, limit: limits.dailySendsPerChannel, period: "day" }, { now });
|
|
28
|
+
if (!cap.allowed)
|
|
29
|
+
return { status: "refused", reason: "unavailable" };
|
|
30
|
+
const request = await requestCode(server.database, {
|
|
31
|
+
purpose,
|
|
32
|
+
contact,
|
|
33
|
+
...(accountId ? { accountId } : {}),
|
|
34
|
+
pepper: deriveSecret(server.secret, "one-time-code"),
|
|
35
|
+
now,
|
|
36
|
+
});
|
|
37
|
+
const detail = { kind: request.contact.kind, purpose, requestId: request.requestId };
|
|
38
|
+
return {
|
|
39
|
+
status: "sent",
|
|
40
|
+
requestId: request.requestId,
|
|
41
|
+
deliver: async () => {
|
|
42
|
+
try {
|
|
43
|
+
await channel.send({
|
|
44
|
+
contact: request.contact,
|
|
45
|
+
code: request.code,
|
|
46
|
+
purpose,
|
|
47
|
+
language,
|
|
48
|
+
expiresAt: request.expiresAt,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// Nobody is waiting for the answer any more: the audit log is where a failed send shows (never the code).
|
|
53
|
+
const { name, message } = error;
|
|
54
|
+
await recordAuditEvent(server.database, {
|
|
55
|
+
accountId,
|
|
56
|
+
action: "code.delivery-failed",
|
|
57
|
+
detail: { ...detail, error: `${name}: ${message}`.slice(0, 500) },
|
|
58
|
+
});
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
await recordAuditEvent(server.database, { accountId, action: "code.sent", detail });
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|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AC;gBACf,0GAA0G;gBAC1G,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAc,CAAC;gBACzC,MAAM,gBAAgB,CAAC,MAAM,CAAC,QAAQ,EAAE;oBACtC,SAAS;oBACT,MAAM,EAAE,sBAAsB;oBAC9B,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;iBAClE,CAAC,CAAC;gBACH,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,gBAAgB,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CodePurpose } from "@sharadox/account-web-library/code-request/type";
|
|
2
|
+
import type { ContactChannel } from "@sharadox/account-web-library/contact-channel/type";
|
|
3
|
+
import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
|
|
4
|
+
export interface CodeSending {
|
|
5
|
+
purpose: CodePurpose;
|
|
6
|
+
/** Already normalized. */
|
|
7
|
+
contact: Contact;
|
|
8
|
+
channel: ContactChannel;
|
|
9
|
+
/** The account asking (step-up, contact verification); null when signing in. */
|
|
10
|
+
accountId?: string | null;
|
|
11
|
+
/** The client's IP address. */
|
|
12
|
+
address: string;
|
|
13
|
+
/** For the code's message. */
|
|
14
|
+
language: string;
|
|
15
|
+
/** Milliseconds since 1970 (now by default). */
|
|
16
|
+
now?: number;
|
|
17
|
+
}
|
|
18
|
+
export type CodeSendingResult = {
|
|
19
|
+
status: "sent";
|
|
20
|
+
requestId: string;
|
|
21
|
+
/** Sends the code: call it after answering (Next.js `after()`), so the answer's timing reveals nothing. */
|
|
22
|
+
deliver: () => Promise<void>;
|
|
23
|
+
} | {
|
|
24
|
+
status: "refused";
|
|
25
|
+
reason: "unavailable";
|
|
26
|
+
} | {
|
|
27
|
+
status: "refused";
|
|
28
|
+
reason: "rate-limit";
|
|
29
|
+
retryAfterSeconds: number;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/code-sending/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACzF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,WAAW,CAAC;IACrB,0BAA0B;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,cAAc,CAAC;IACxB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,iBAAiB,GACzB;IACE,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,2GAA2G;IAC3G,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,GACD;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GAC5C;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/code-sending/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
2
|
+
import type { ContactAdditionFinish, ContactAdditionStart } from "@sharadox/account-web-library/contact-addition-flow/type";
|
|
3
|
+
import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
|
|
4
|
+
/**
|
|
5
|
+
* Adds a contact to an account, unverified, and sends it a code (through `sendCode`); asking again for the same
|
|
6
|
+
* unverified contact sends a new code. Ask for a step-up first, and tell the account's other contacts.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result = await startContactAddition(server, { accountId, contact, address, language });
|
|
10
|
+
* if (result.status === "sent") after(result.deliver);
|
|
11
|
+
*/
|
|
12
|
+
export declare function startContactAddition(server: AccountServer, { accountId, contact, address, language, now, }: {
|
|
13
|
+
accountId: string;
|
|
14
|
+
contact: Contact;
|
|
15
|
+
address: string;
|
|
16
|
+
language: string;
|
|
17
|
+
now?: number;
|
|
18
|
+
}): Promise<ContactAdditionStart>;
|
|
19
|
+
/**
|
|
20
|
+
* Verifies the added contact once its code comes back: it can then be used to sign in.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const result = await finishContactAddition(server, { accountId, requestId, code });
|
|
24
|
+
*/
|
|
25
|
+
export declare function finishContactAddition(server: AccountServer, { accountId, requestId, code, now, }: {
|
|
26
|
+
accountId: string;
|
|
27
|
+
requestId: string;
|
|
28
|
+
code: string;
|
|
29
|
+
now?: number;
|
|
30
|
+
}): Promise<ContactAdditionFinish>;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-addition-flow/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAIvF,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,0DAA0D,CAAC;AAElE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAI/E;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,QAAQ,EACR,GAAgB,GACjB,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1F,OAAO,CAAC,oBAAoB,CAAC,CAiC/B;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EACE,SAAS,EACT,SAAS,EACT,IAAI,EACJ,GAAgB,GACjB,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACtE,OAAO,CAAC,qBAAqB,CAAC,CAsBhC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { sendCode } from "@sharadox/account-web-library/code-sending";
|
|
2
|
+
import { verifyCode } from "@sharadox/account-web-library/code-verification";
|
|
3
|
+
import { addContact } from "@sharadox/account-web-library/contact-addition";
|
|
4
|
+
import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
|
|
5
|
+
import { verifyContact } from "@sharadox/account-web-library/contact-verification";
|
|
6
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
7
|
+
/**
|
|
8
|
+
* Adds a contact to an account, unverified, and sends it a code (through `sendCode`); asking again for the same
|
|
9
|
+
* unverified contact sends a new code. Ask for a step-up first, and tell the account's other contacts.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = await startContactAddition(server, { accountId, contact, address, language });
|
|
13
|
+
* if (result.status === "sent") after(result.deliver);
|
|
14
|
+
*/
|
|
15
|
+
export async function startContactAddition(server, { accountId, contact, address, language, now = Date.now(), }) {
|
|
16
|
+
let normalized;
|
|
17
|
+
try {
|
|
18
|
+
normalized = normalizeContact(contact);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return { status: "refused", reason: "contact" };
|
|
22
|
+
}
|
|
23
|
+
const channel = server.channels.find(({ kind }) => kind === normalized.kind);
|
|
24
|
+
if (!channel)
|
|
25
|
+
return { status: "refused", reason: "contact" };
|
|
26
|
+
const existing = await server.database
|
|
27
|
+
.selectFrom("contact")
|
|
28
|
+
.select(["id", "verified_at"])
|
|
29
|
+
.where("account_id", "=", accountId)
|
|
30
|
+
.where("kind", "=", normalized.kind)
|
|
31
|
+
.where("value", "=", normalized.value)
|
|
32
|
+
.executeTakeFirst();
|
|
33
|
+
if (existing?.verified_at)
|
|
34
|
+
return { status: "refused", reason: "already-added" };
|
|
35
|
+
let contactId = existing?.id;
|
|
36
|
+
if (!contactId) {
|
|
37
|
+
const added = await addContact(server.database, { accountId, contact: normalized, now });
|
|
38
|
+
if (!added.added)
|
|
39
|
+
return { status: "refused", reason: added.reason };
|
|
40
|
+
contactId = added.contactId;
|
|
41
|
+
}
|
|
42
|
+
const sent = await sendCode(server, {
|
|
43
|
+
purpose: "contact-verification",
|
|
44
|
+
contact: normalized,
|
|
45
|
+
channel,
|
|
46
|
+
accountId,
|
|
47
|
+
address,
|
|
48
|
+
language,
|
|
49
|
+
now,
|
|
50
|
+
});
|
|
51
|
+
return sent.status === "sent" ? { ...sent, contactId } : sent;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Verifies the added contact once its code comes back: it can then be used to sign in.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const result = await finishContactAddition(server, { accountId, requestId, code });
|
|
58
|
+
*/
|
|
59
|
+
export async function finishContactAddition(server, { accountId, requestId, code, now = Date.now(), }) {
|
|
60
|
+
const verification = await verifyCode(server.database, {
|
|
61
|
+
requestId,
|
|
62
|
+
code,
|
|
63
|
+
purpose: "contact-verification",
|
|
64
|
+
pepper: deriveSecret(server.secret, "one-time-code"),
|
|
65
|
+
now,
|
|
66
|
+
});
|
|
67
|
+
if (!verification.valid)
|
|
68
|
+
return { status: "refused", reason: verification.reason };
|
|
69
|
+
if (verification.accountId !== accountId)
|
|
70
|
+
return { status: "refused", reason: "unknown" };
|
|
71
|
+
const contact = await server.database
|
|
72
|
+
.selectFrom("contact")
|
|
73
|
+
.select("id")
|
|
74
|
+
.where("account_id", "=", accountId)
|
|
75
|
+
.where("kind", "=", verification.contact.kind)
|
|
76
|
+
.where("value", "=", verification.contact.value)
|
|
77
|
+
.executeTakeFirst();
|
|
78
|
+
if (!contact)
|
|
79
|
+
return { status: "refused", reason: "no-contact" };
|
|
80
|
+
const verified = await verifyContact(server.database, { accountId, contactId: contact.id, now });
|
|
81
|
+
return verified.verified
|
|
82
|
+
? { status: "verified", contactId: contact.id }
|
|
83
|
+
: { status: "refused", reason: verified.reason };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-addition-flow/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iDAAiD,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAC;AAK5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAqB,EACrB,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,QAAQ,EACR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E,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;SAC7C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC;SAC/C,gBAAgB,EAAE,CAAC;IACtB,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IACjE,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACjG,OAAO,QAAQ,CAAC,QAAQ;QACtB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE;QAC/C,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CodeSendingResult } from "@sharadox/account-web-library/code-sending/type";
|
|
2
|
+
import type { CodeVerificationResult } from "@sharadox/account-web-library/code-verification/type";
|
|
3
|
+
export type ContactAdditionStart = (Extract<CodeSendingResult, {
|
|
4
|
+
status: "sent";
|
|
5
|
+
}> & {
|
|
6
|
+
contactId: string;
|
|
7
|
+
}) | Exclude<CodeSendingResult, {
|
|
8
|
+
status: "sent";
|
|
9
|
+
}> | {
|
|
10
|
+
status: "refused";
|
|
11
|
+
reason: "contact" | "already-added" | "contact-taken" | "no-account";
|
|
12
|
+
};
|
|
13
|
+
export type ContactAdditionFinish = {
|
|
14
|
+
status: "verified";
|
|
15
|
+
contactId: string;
|
|
16
|
+
} | {
|
|
17
|
+
status: "refused";
|
|
18
|
+
reason: Extract<CodeVerificationResult, {
|
|
19
|
+
valid: false;
|
|
20
|
+
}>["reason"] | "no-contact" | "contact-taken";
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-addition-flow/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAEnG,MAAM,MAAM,oBAAoB,GAC5B,CAAC,OAAO,CAAC,iBAAiB,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,GACxE,OAAO,CAAC,iBAAiB,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9C;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,eAAe,GAAG,eAAe,GAAG,YAAY,CAAA;CAAE,CAAC;AAEhG,MAAM,MAAM,qBAAqB,GAC7B;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACzC;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC,sBAAsB,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,eAAe,CAAC;CACtG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/contact-addition-flow/type.ts"],"names":[],"mappings":""}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* driver (Neon's or PGlite's); undefined for any other error.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* if (databaseError(error)?.constraint === "
|
|
6
|
+
* if (databaseError(error)?.constraint === "account_identifier_key") return { reason: "identifier-taken" };
|
|
7
7
|
*/
|
|
8
8
|
export declare function databaseError(error: unknown): {
|
|
9
9
|
code: string;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* driver (Neon's or PGlite's); undefined for any other error.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* if (databaseError(error)?.constraint === "
|
|
6
|
+
* if (databaseError(error)?.constraint === "account_identifier_key") return { reason: "identifier-taken" };
|
|
7
7
|
*/
|
|
8
8
|
export function databaseError(error) {
|
|
9
9
|
if (typeof error !== "object" || error === null || typeof error.code !== "string")
|
|
@@ -54,7 +54,7 @@ export function createEmailChannel({ sender, from, design, logos = [], now = Dat
|
|
|
54
54
|
if (contact.kind !== "email")
|
|
55
55
|
throw new Error(`the email channel can't send to a "${contact.kind}" contact`);
|
|
56
56
|
const words = language.toLowerCase().startsWith("pt") ? PORTUGUESE : ENGLISH;
|
|
57
|
-
const shown = code.replace(/(.{
|
|
57
|
+
const shown = code.replace(/(.{3})(?=.)/g, "$1 ");
|
|
58
58
|
const minutes = Math.max(1, Math.ceil((expiresAt.getTime() - now()) / 60_000));
|
|
59
59
|
const paragraphs = [words.lifetime(minutes), words.ignore, words.never];
|
|
60
60
|
const html = emailLayout({
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IdentifierCheck } from "@sharadox/account-web-library/identifier/type";
|
|
2
|
+
/** The longest identifier. */
|
|
3
|
+
export declare const IDENTIFIER_MAXIMUM_LENGTH = 50;
|
|
4
|
+
/**
|
|
5
|
+
* Checks an identifier against the rules:
|
|
6
|
+
* - 1 to 50 characters;
|
|
7
|
+
* - only A–Z, a–z and 0–9, with `-`, `_` or `.` allowed only between letters or digits, never two in a row;
|
|
8
|
+
* - shown as written, unique without regard to case (see `identifierKey`).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
|
|
12
|
+
* checkIdentifier("a--b"); // { valid: false, reason: "characters" }
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkIdentifier(identifier: string): IdentifierCheck;
|
|
15
|
+
/**
|
|
16
|
+
* The form an identifier is unique in: lowercase, so `abc` and `aBc` are the same identifier (the database's unique index
|
|
17
|
+
* is on this key).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* identifierKey("aBc"); // "abc"
|
|
21
|
+
*/
|
|
22
|
+
export declare function identifierKey(identifier: string): string;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/identifier/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAKrF,8BAA8B;AAC9B,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,CAInE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Letters and digits, with single `-`, `_` or `.` only between them. */
|
|
2
|
+
const PATTERN = /^[A-Za-z0-9]+(?:[-_.][A-Za-z0-9]+)*$/;
|
|
3
|
+
/** The longest identifier. */
|
|
4
|
+
export const IDENTIFIER_MAXIMUM_LENGTH = 50;
|
|
5
|
+
/**
|
|
6
|
+
* Checks an identifier against the rules:
|
|
7
|
+
* - 1 to 50 characters;
|
|
8
|
+
* - only A–Z, a–z and 0–9, with `-`, `_` or `.` allowed only between letters or digits, never two in a row;
|
|
9
|
+
* - shown as written, unique without regard to case (see `identifierKey`).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
|
|
13
|
+
* checkIdentifier("a--b"); // { valid: false, reason: "characters" }
|
|
14
|
+
*/
|
|
15
|
+
export function checkIdentifier(identifier) {
|
|
16
|
+
if (identifier.length < 1 || identifier.length > IDENTIFIER_MAXIMUM_LENGTH)
|
|
17
|
+
return { valid: false, reason: "length" };
|
|
18
|
+
if (!PATTERN.test(identifier))
|
|
19
|
+
return { valid: false, reason: "characters" };
|
|
20
|
+
return { valid: true, identifier, key: identifierKey(identifier) };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The form an identifier is unique in: lowercase, so `abc` and `aBc` are the same identifier (the database's unique index
|
|
24
|
+
* is on this key).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* identifierKey("aBc"); // "abc"
|
|
28
|
+
*/
|
|
29
|
+
export function identifierKey(identifier) {
|
|
30
|
+
return identifier.toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/identifier/index.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,OAAO,GAAG,sCAAsC,CAAC;AAEvD,8BAA8B;AAC9B,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,yBAAyB;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACtH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAC7E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC"}
|