@sharadox/account-web-library 0.1.0-development.3 → 0.1.0-development.33
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 +270 -8
- 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-ban/index.d.ts +67 -0
- package/distribution/account-ban/index.d.ts.map +1 -0
- package/distribution/account-ban/index.js +233 -0
- package/distribution/account-ban/index.js.map +1 -0
- package/distribution/account-ban/type.d.ts +44 -0
- package/distribution/account-ban/type.d.ts.map +1 -0
- package/distribution/account-ban/type.js +2 -0
- package/distribution/account-ban/type.js.map +1 -0
- package/distribution/account-database/type.d.ts +264 -0
- package/distribution/account-database/type.d.ts.map +1 -0
- package/distribution/account-database/type.js +2 -0
- package/distribution/account-database/type.js.map +1 -0
- package/distribution/account-deletion/index.d.ts +21 -0
- package/distribution/account-deletion/index.d.ts.map +1 -0
- package/distribution/account-deletion/index.js +66 -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/account-export/type.js +2 -0
- package/distribution/account-export/type.js.map +1 -0
- package/distribution/account-inactivity/index.d.ts +25 -0
- package/distribution/account-inactivity/index.d.ts.map +1 -0
- package/distribution/account-inactivity/index.js +100 -0
- package/distribution/account-inactivity/index.js.map +1 -0
- package/distribution/account-migration/index.d.ts +18 -0
- package/distribution/account-migration/index.d.ts.map +1 -0
- package/distribution/account-migration/index.js +376 -0
- package/distribution/account-migration/index.js.map +1 -0
- 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-notice/index.d.ts +15 -0
- package/distribution/account-notice/index.d.ts.map +1 -0
- package/distribution/account-notice/index.js +41 -0
- package/distribution/account-notice/index.js.map +1 -0
- package/distribution/account-permission/index.d.ts +14 -0
- package/distribution/account-permission/index.d.ts.map +1 -0
- package/distribution/account-permission/index.js +91 -0
- package/distribution/account-permission/index.js.map +1 -0
- package/distribution/account-permission/type.d.ts +12 -0
- package/distribution/account-permission/type.d.ts.map +1 -0
- package/distribution/account-permission/type.js +2 -0
- package/distribution/account-permission/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 +25 -0
- package/distribution/account-server/index.d.ts.map +1 -0
- package/distribution/account-server/index.js +34 -0
- package/distribution/account-server/index.js.map +1 -0
- package/distribution/account-server/type.d.ts +30 -0
- package/distribution/account-server/type.d.ts.map +1 -0
- package/distribution/account-server/type.js +2 -0
- package/distribution/account-server/type.js.map +1 -0
- 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-session-revocation/index.d.ts +14 -0
- package/distribution/account-session-revocation/index.d.ts.map +1 -0
- package/distribution/account-session-revocation/index.js +25 -0
- package/distribution/account-session-revocation/index.js.map +1 -0
- package/distribution/account-sign-in/index.d.ts +15 -0
- package/distribution/account-sign-in/index.d.ts.map +1 -0
- package/distribution/account-sign-in/index.js +78 -0
- package/distribution/account-sign-in/index.js.map +1 -0
- package/distribution/account-sign-in/type.d.ts +24 -0
- package/distribution/account-sign-in/type.d.ts.map +1 -0
- package/distribution/account-sign-in/type.js +2 -0
- package/distribution/account-sign-in/type.js.map +1 -0
- package/distribution/account-sign-out/index.d.ts +16 -0
- package/distribution/account-sign-out/index.d.ts.map +1 -0
- package/distribution/account-sign-out/index.js +34 -0
- package/distribution/account-sign-out/index.js.map +1 -0
- package/distribution/application-sync/index.d.ts +14 -0
- package/distribution/application-sync/index.d.ts.map +1 -0
- package/distribution/application-sync/index.js +96 -0
- package/distribution/application-sync/index.js.map +1 -0
- package/distribution/application-sync/type.d.ts +29 -0
- package/distribution/application-sync/type.d.ts.map +1 -0
- package/distribution/application-sync/type.js +2 -0
- package/distribution/application-sync/type.js.map +1 -0
- package/distribution/audit-event/index.d.ts +12 -0
- package/distribution/audit-event/index.d.ts.map +1 -0
- package/distribution/audit-event/index.js +36 -0
- package/distribution/audit-event/index.js.map +1 -0
- package/distribution/audit-event/type.d.ts +16 -0
- package/distribution/audit-event/type.d.ts.map +1 -0
- package/distribution/audit-event/type.js +2 -0
- package/distribution/audit-event/type.js.map +1 -0
- package/distribution/banned-contact/index.d.ts +34 -0
- package/distribution/banned-contact/index.d.ts.map +1 -0
- package/distribution/banned-contact/index.js +52 -0
- package/distribution/banned-contact/index.js.map +1 -0
- package/distribution/browser-session-read/index.d.ts +17 -0
- package/distribution/browser-session-read/index.d.ts.map +1 -0
- package/distribution/browser-session-read/index.js +52 -0
- package/distribution/browser-session-read/index.js.map +1 -0
- package/distribution/browser-session-read/type.d.ts +18 -0
- package/distribution/browser-session-read/type.d.ts.map +1 -0
- package/distribution/browser-session-read/type.js +2 -0
- package/distribution/browser-session-read/type.js.map +1 -0
- package/distribution/challenge-issue/index.d.ts +13 -0
- package/distribution/challenge-issue/index.d.ts.map +1 -0
- package/distribution/challenge-issue/index.js +18 -0
- package/distribution/challenge-issue/index.js.map +1 -0
- package/distribution/code-request/index.d.ts +16 -0
- package/distribution/code-request/index.d.ts.map +1 -0
- package/distribution/code-request/index.js +52 -0
- package/distribution/code-request/index.js.map +1 -0
- package/distribution/code-request/type.d.ts +25 -0
- package/distribution/code-request/type.d.ts.map +1 -0
- package/distribution/code-request/type.js +2 -0
- package/distribution/code-request/type.js.map +1 -0
- package/distribution/code-request-prune/index.d.ts +13 -0
- package/distribution/code-request-prune/index.d.ts.map +1 -0
- package/distribution/code-request-prune/index.js +12 -0
- package/distribution/code-request-prune/index.js.map +1 -0
- 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/code-verification/index.d.ts +14 -0
- package/distribution/code-verification/index.d.ts.map +1 -0
- package/distribution/code-verification/index.js +43 -0
- package/distribution/code-verification/index.js.map +1 -0
- package/distribution/code-verification/type.d.ts +22 -0
- package/distribution/code-verification/type.d.ts.map +1 -0
- package/distribution/code-verification/type.js +2 -0
- package/distribution/code-verification/type.js.map +1 -0
- package/distribution/contact-addition/index.d.ts +13 -0
- package/distribution/contact-addition/index.d.ts.map +1 -0
- package/distribution/contact-addition/index.js +48 -0
- package/distribution/contact-addition/index.js.map +1 -0
- package/distribution/contact-addition/type.d.ts +15 -0
- package/distribution/contact-addition/type.d.ts.map +1 -0
- package/distribution/contact-addition/type.js +2 -0
- package/distribution/contact-addition/type.js.map +1 -0
- package/distribution/contact-addition-flow/index.d.ts +32 -0
- package/distribution/contact-addition-flow/index.d.ts.map +1 -0
- package/distribution/contact-addition-flow/index.js +96 -0
- package/distribution/contact-addition-flow/index.js.map +1 -0
- package/distribution/contact-addition-flow/type.d.ts +25 -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/contact-channel/type.d.ts +49 -0
- package/distribution/contact-channel/type.d.ts.map +1 -0
- package/distribution/contact-channel/type.js +2 -0
- package/distribution/contact-channel/type.js.map +1 -0
- package/distribution/contact-kind/index.d.ts +12 -0
- package/distribution/contact-kind/index.d.ts.map +1 -0
- package/distribution/contact-kind/index.js +18 -0
- package/distribution/contact-kind/index.js.map +1 -0
- package/distribution/contact-kind/type.d.ts +6 -0
- package/distribution/contact-kind/type.d.ts.map +1 -0
- package/distribution/contact-kind/type.js +2 -0
- package/distribution/contact-kind/type.js.map +1 -0
- package/distribution/contact-lookup/index.d.ts +16 -0
- package/distribution/contact-lookup/index.d.ts.map +1 -0
- package/distribution/contact-lookup/index.js +20 -0
- package/distribution/contact-lookup/index.js.map +1 -0
- package/distribution/contact-removal/index.d.ts +19 -0
- package/distribution/contact-removal/index.d.ts.map +1 -0
- package/distribution/contact-removal/index.js +35 -0
- package/distribution/contact-removal/index.js.map +1 -0
- package/distribution/contact-verification/index.d.ts +20 -0
- package/distribution/contact-verification/index.d.ts.map +1 -0
- package/distribution/contact-verification/index.js +37 -0
- package/distribution/contact-verification/index.js.map +1 -0
- package/distribution/database-error/index.d.ts +12 -0
- package/distribution/database-error/index.d.ts.map +1 -0
- package/distribution/database-error/index.js +14 -0
- package/distribution/database-error/index.js.map +1 -0
- package/distribution/email-channel/index.d.ts +13 -0
- package/distribution/email-channel/index.d.ts.map +1 -0
- package/distribution/email-channel/index.js +185 -0
- package/distribution/email-channel/index.js.map +1 -0
- package/distribution/email-channel/type.d.ts +17 -0
- package/distribution/email-channel/type.d.ts.map +1 -0
- package/distribution/email-channel/type.js +2 -0
- package/distribution/email-channel/type.js.map +1 -0
- 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 +18 -0
- package/distribution/person-account/index.d.ts.map +1 -0
- package/distribution/person-account/index.js +65 -0
- package/distribution/person-account/index.js.map +1 -0
- package/distribution/person-account/type.d.ts +22 -0
- package/distribution/person-account/type.d.ts.map +1 -0
- package/distribution/person-account/type.js +2 -0
- package/distribution/person-account/type.js.map +1 -0
- 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/role-grant/index.d.ts +38 -0
- package/distribution/role-grant/index.d.ts.map +1 -0
- package/distribution/role-grant/index.js +142 -0
- package/distribution/role-grant/index.js.map +1 -0
- package/distribution/role-grant/type.d.ts +40 -0
- package/distribution/role-grant/type.d.ts.map +1 -0
- package/distribution/role-grant/type.js +2 -0
- package/distribution/role-grant/type.js.map +1 -0
- package/distribution/rule-sync/index.d.ts +28 -0
- package/distribution/rule-sync/index.d.ts.map +1 -0
- package/distribution/rule-sync/index.js +80 -0
- package/distribution/rule-sync/index.js.map +1 -0
- package/distribution/rule-sync/type.d.ts +17 -0
- package/distribution/rule-sync/type.d.ts.map +1 -0
- package/distribution/rule-sync/type.js +2 -0
- package/distribution/rule-sync/type.js.map +1 -0
- package/distribution/second-factor-finish/index.d.ts +13 -0
- package/distribution/second-factor-finish/index.d.ts.map +1 -0
- package/distribution/second-factor-finish/index.js +90 -0
- package/distribution/second-factor-finish/index.js.map +1 -0
- package/distribution/second-factor-finish/type.d.ts +30 -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-derivation/index.d.ts +10 -0
- package/distribution/secret-derivation/index.d.ts.map +1 -0
- package/distribution/secret-derivation/index.js +15 -0
- package/distribution/secret-derivation/index.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/session-prune/index.d.ts +17 -0
- package/distribution/session-prune/index.d.ts.map +1 -0
- package/distribution/session-prune/index.js +30 -0
- package/distribution/session-prune/index.js.map +1 -0
- package/distribution/session-token/index.d.ts +19 -0
- package/distribution/session-token/index.d.ts.map +1 -0
- package/distribution/session-token/index.js +22 -0
- package/distribution/session-token/index.js.map +1 -0
- package/distribution/sign-in-finish/index.d.ts +13 -0
- package/distribution/sign-in-finish/index.d.ts.map +1 -0
- package/distribution/sign-in-finish/index.js +69 -0
- package/distribution/sign-in-finish/index.js.map +1 -0
- package/distribution/sign-in-finish/type.d.ts +44 -0
- package/distribution/sign-in-finish/type.d.ts.map +1 -0
- package/distribution/sign-in-finish/type.js +2 -0
- package/distribution/sign-in-finish/type.js.map +1 -0
- package/distribution/sign-in-start/index.d.ts +17 -0
- package/distribution/sign-in-start/index.d.ts.map +1 -0
- package/distribution/sign-in-start/index.js +45 -0
- package/distribution/sign-in-start/index.js.map +1 -0
- package/distribution/sign-in-start/type.d.ts +34 -0
- package/distribution/sign-in-start/type.d.ts.map +1 -0
- package/distribution/sign-in-start/type.js +2 -0
- package/distribution/sign-in-start/type.js.map +1 -0
- package/distribution/sign-up-finish/index.d.ts +13 -0
- package/distribution/sign-up-finish/index.d.ts.map +1 -0
- package/distribution/sign-up-finish/index.js +38 -0
- package/distribution/sign-up-finish/index.js.map +1 -0
- package/distribution/sign-up-finish/type.d.ts +28 -0
- package/distribution/sign-up-finish/type.d.ts.map +1 -0
- package/distribution/sign-up-finish/type.js +2 -0
- package/distribution/sign-up-finish/type.js.map +1 -0
- package/distribution/signed-ticket/index.d.ts +19 -0
- package/distribution/signed-ticket/index.d.ts.map +1 -0
- package/distribution/signed-ticket/index.js +35 -0
- package/distribution/signed-ticket/index.js.map +1 -0
- package/distribution/signed-ticket/type.d.ts +16 -0
- package/distribution/signed-ticket/type.d.ts.map +1 -0
- package/distribution/signed-ticket/type.js +2 -0
- package/distribution/signed-ticket/type.js.map +1 -0
- 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-database/index.d.ts +13 -0
- package/distribution/test-database/index.d.ts.map +1 -0
- package/distribution/test-database/index.js +17 -0
- package/distribution/test-database/index.js.map +1 -0
- 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/test-server/index.d.ts +10 -0
- package/distribution/test-server/index.d.ts.map +1 -0
- package/distribution/test-server/index.js +16 -0
- package/distribution/test-server/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 +9 -2
- 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 → account-activity}/type.js +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** An account signed in on the browser, as the account selector shows it. */
|
|
2
|
+
export interface SignedInAccount {
|
|
3
|
+
accountSessionId: string;
|
|
4
|
+
accountId: string;
|
|
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;
|
|
10
|
+
signedInAt: Date;
|
|
11
|
+
secondFactorAt: Date | null;
|
|
12
|
+
}
|
|
13
|
+
export interface BrowserSession {
|
|
14
|
+
browserSessionId: string;
|
|
15
|
+
/** In the order they signed in. */
|
|
16
|
+
accounts: SignedInAccount[];
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/browser-session-read/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Challenge } from "@sharadox/protection-web-library/proof-of-work/type";
|
|
2
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
3
|
+
/**
|
|
4
|
+
* A proof-of-work challenge for the sign-in form, at the server's difficulty: the browser solves it in the
|
|
5
|
+
* background (protection-web-library's `solveChallenge`) and sends the solution with the contact.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const challenge = issueChallenge(server); // give it to the page
|
|
9
|
+
*/
|
|
10
|
+
export declare function issueChallenge(server: AccountServer, { now }?: {
|
|
11
|
+
now?: number;
|
|
12
|
+
}): Challenge;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/challenge-issue/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qDAAqD,CAAC;AAErF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAGvF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,GAAgB,EAAE,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,CAM5G"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createChallenge } from "@sharadox/protection-web-library/proof-of-work";
|
|
2
|
+
import { signInLimits } from "@sharadox/account-web-library/account-server";
|
|
3
|
+
import { deriveSecret } from "@sharadox/account-web-library/secret-derivation";
|
|
4
|
+
/**
|
|
5
|
+
* A proof-of-work challenge for the sign-in form, at the server's difficulty: the browser solves it in the
|
|
6
|
+
* background (protection-web-library's `solveChallenge`) and sends the solution with the contact.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const challenge = issueChallenge(server); // give it to the page
|
|
10
|
+
*/
|
|
11
|
+
export function issueChallenge(server, { now = Date.now() } = {}) {
|
|
12
|
+
return createChallenge({
|
|
13
|
+
secret: deriveSecret(server.secret, "proof-of-work"),
|
|
14
|
+
difficulty: signInLimits(server).difficulty,
|
|
15
|
+
now,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/challenge-issue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAqB,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,KAAuB,EAAE;IAC/F,OAAO,eAAe,CAAC;QACrB,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;QACpD,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,UAAU;QAC3C,GAAG;KACJ,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { CodePurpose, CodeRequest, CodeRequestOptions } from "@sharadox/account-web-library/code-request/type";
|
|
4
|
+
/** The purposes a code can have. */
|
|
5
|
+
export declare const CODE_PURPOSES: readonly CodePurpose[];
|
|
6
|
+
/**
|
|
7
|
+
* Starts a one-time code for a contact: a new code (8 digits, 10 minutes by default), stored only as an HMAC bound
|
|
8
|
+
* to its purpose and request, replacing any open request for the same contact and purpose. Returns the code to send
|
|
9
|
+
* through the contact's channel. Rate limit and cap the sends before calling it (protection-web-library).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const { requestId, code } = await requestCode(database, { purpose: "sign-in", contact, pepper });
|
|
13
|
+
* await channel.send(contact, code); // after answering the request, so timing reveals nothing
|
|
14
|
+
*/
|
|
15
|
+
export declare function requestCode(database: Kysely<AccountDatabase>, { purpose, contact, accountId, pepper, length, lifetimeSeconds, now }: CodeRequestOptions): Promise<CodeRequest>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/code-request/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,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAC;AAIpH,oCAAoC;AACpC,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAAmD,CAAC;AAEpG;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAU,EAAE,eAAqB,EAAE,GAAgB,EAAE,EAAE,kBAAkB,GAC/G,OAAO,CAAC,WAAW,CAAC,CAmCtB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
|
|
3
|
+
import { createOneTimeCode, hashOneTimeCode } from "@sharadox/account-web-library/one-time-code";
|
|
4
|
+
/** The purposes a code can have. */
|
|
5
|
+
export const CODE_PURPOSES = ["sign-in", "contact-verification", "step-up"];
|
|
6
|
+
/**
|
|
7
|
+
* Starts a one-time code for a contact: a new code (8 digits, 10 minutes by default), stored only as an HMAC bound
|
|
8
|
+
* to its purpose and request, replacing any open request for the same contact and purpose. Returns the code to send
|
|
9
|
+
* through the contact's channel. Rate limit and cap the sends before calling it (protection-web-library).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const { requestId, code } = await requestCode(database, { purpose: "sign-in", contact, pepper });
|
|
13
|
+
* await channel.send(contact, code); // after answering the request, so timing reveals nothing
|
|
14
|
+
*/
|
|
15
|
+
export async function requestCode(database, { purpose, contact, accountId, pepper, length = 6, lifetimeSeconds = 600, now = Date.now() }) {
|
|
16
|
+
if (!CODE_PURPOSES.includes(purpose))
|
|
17
|
+
throw new Error(`unknown code purpose "${purpose}"`);
|
|
18
|
+
const { kind, value } = normalizeContact(contact);
|
|
19
|
+
const requestId = uuidVersion7({ now });
|
|
20
|
+
const code = createOneTimeCode(length);
|
|
21
|
+
const codeHash = hashOneTimeCode(code, { pepper, purpose: `${purpose}:${requestId}` });
|
|
22
|
+
const createdAt = new Date(now);
|
|
23
|
+
const expiresAt = new Date(now + lifetimeSeconds * 1000);
|
|
24
|
+
await database.transaction().execute(async (transaction) => {
|
|
25
|
+
await transaction
|
|
26
|
+
.updateTable("code_request")
|
|
27
|
+
.set({ voided_at: createdAt })
|
|
28
|
+
.where("kind", "=", kind)
|
|
29
|
+
.where("value", "=", value)
|
|
30
|
+
.where("purpose", "=", purpose)
|
|
31
|
+
.where("used_at", "is", null)
|
|
32
|
+
.where("voided_at", "is", null)
|
|
33
|
+
.execute();
|
|
34
|
+
await transaction
|
|
35
|
+
.insertInto("code_request")
|
|
36
|
+
.values({
|
|
37
|
+
id: requestId,
|
|
38
|
+
purpose,
|
|
39
|
+
account_id: accountId ?? null,
|
|
40
|
+
kind,
|
|
41
|
+
value,
|
|
42
|
+
code_hash: codeHash,
|
|
43
|
+
created_at: createdAt,
|
|
44
|
+
expires_at: expiresAt,
|
|
45
|
+
used_at: null,
|
|
46
|
+
voided_at: null,
|
|
47
|
+
})
|
|
48
|
+
.execute();
|
|
49
|
+
});
|
|
50
|
+
return { requestId, code, contact: { kind, value }, expiresAt };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/code-request/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAEjG,oCAAoC;AACpC,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,SAAS,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAC;AAEpG;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,QAAiC,EACjC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,eAAe,GAAG,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAsB;IAEhH,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,GAAG,CAAC,CAAC;IAC3F,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,OAAO,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ACH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
|
|
2
|
+
/** What a one-time code is for; a code works only for its own purpose and request. */
|
|
3
|
+
export type CodePurpose = "sign-in" | "contact-verification" | "step-up";
|
|
4
|
+
export interface CodeRequestOptions {
|
|
5
|
+
purpose: CodePurpose;
|
|
6
|
+
contact: Contact;
|
|
7
|
+
/** The account asking (step-up, contact verification). */
|
|
8
|
+
accountId?: string;
|
|
9
|
+
/** At least 32 characters, kept outside the database. */
|
|
10
|
+
pepper: string;
|
|
11
|
+
/** Digits (6 by default). */
|
|
12
|
+
length?: number;
|
|
13
|
+
/** 600 (10 minutes) by default. */
|
|
14
|
+
lifetimeSeconds?: number;
|
|
15
|
+
/** Milliseconds since 1970 (now by default). */
|
|
16
|
+
now?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CodeRequest {
|
|
19
|
+
requestId: string;
|
|
20
|
+
/** Send it, then forget it: only its hash is stored. */
|
|
21
|
+
code: string;
|
|
22
|
+
contact: Contact;
|
|
23
|
+
expiresAt: Date;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/code-request/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,sFAAsF;AACtF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,sBAAsB,GAAG,SAAS,CAAC;AAEzE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/code-request/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
/**
|
|
4
|
+
* Deletes code requests that expired before `before`, with the contacts they hold, from a daily job. Returns how
|
|
5
|
+
* many were deleted.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* await pruneCodeRequests(database, { before: new Date(Date.now() - 86_400_000) });
|
|
9
|
+
*/
|
|
10
|
+
export declare function pruneCodeRequests(database: Kysely<AccountDatabase>, { before }: {
|
|
11
|
+
before: Date;
|
|
12
|
+
}): Promise<number>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/code-request-prune/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,GAC3B,OAAO,CAAC,MAAM,CAAC,CAGjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes code requests that expired before `before`, with the contacts they hold, from a daily job. Returns how
|
|
3
|
+
* many were deleted.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* await pruneCodeRequests(database, { before: new Date(Date.now() - 86_400_000) });
|
|
7
|
+
*/
|
|
8
|
+
export async function pruneCodeRequests(database, { before }) {
|
|
9
|
+
const result = await database.deleteFrom("code_request").where("expires_at", "<", before).executeTakeFirst();
|
|
10
|
+
return Number(result.numDeletedRows);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/code-request-prune/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAiC,EACjC,EAAE,MAAM,EAAoB;IAE5B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAC7G,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -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
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/code-sending/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAqB,EACrB,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,GAAG,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAe;IAEjG,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,SAAS,CAC1B,MAAM,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,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;IACrF,OAAO;QACL,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,IAAI,CAAC;oBACjB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO;oBACP,QAAQ;oBACR,SAAS,EAAE,OAAO,CAAC,SAAS;iBAC7B,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;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,14 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { CodeVerificationOptions, CodeVerificationResult } from "@sharadox/account-web-library/code-verification/type";
|
|
4
|
+
/**
|
|
5
|
+
* Checks a typed one-time code against its request, with the row locked so concurrent guesses can't pass the
|
|
6
|
+
* attempt limit. The right code works once, before it expires, unless a newer request replaced it or 5 wrong codes
|
|
7
|
+
* came first. Returns the proved contact and the account that asked (null for sign-in).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = await verifyCode(database, { requestId, code: typed, purpose: "sign-in", pepper });
|
|
11
|
+
* if (result.valid) signIn(await findAccountByContact(database, result.contact));
|
|
12
|
+
*/
|
|
13
|
+
export declare function verifyCode(database: Kysely<AccountDatabase>, { requestId, code, purpose, pepper, maximumAttempts, now }: CodeVerificationOptions): Promise<CodeVerificationResult>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/code-verification/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,EACV,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,sDAAsD,CAAC;AAK9D;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,eAAmB,EAAE,GAAgB,EAAE,EAAE,uBAAuB,GACnG,OAAO,CAAC,sBAAsB,CAAC,CAwBjC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { matchesOneTimeCode } from "@sharadox/account-web-library/one-time-code";
|
|
2
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
/**
|
|
4
|
+
* Checks a typed one-time code against its request, with the row locked so concurrent guesses can't pass the
|
|
5
|
+
* attempt limit. The right code works once, before it expires, unless a newer request replaced it or 5 wrong codes
|
|
6
|
+
* came first. Returns the proved contact and the account that asked (null for sign-in).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result = await verifyCode(database, { requestId, code: typed, purpose: "sign-in", pepper });
|
|
10
|
+
* if (result.valid) signIn(await findAccountByContact(database, result.contact));
|
|
11
|
+
*/
|
|
12
|
+
export async function verifyCode(database, { requestId, code, purpose, pepper, maximumAttempts = 5, now = Date.now() }) {
|
|
13
|
+
if (!UUID.test(requestId))
|
|
14
|
+
return { valid: false, reason: "unknown" };
|
|
15
|
+
return database.transaction().execute(async (transaction) => {
|
|
16
|
+
const request = await transaction
|
|
17
|
+
.selectFrom("code_request")
|
|
18
|
+
.selectAll()
|
|
19
|
+
.where("id", "=", requestId)
|
|
20
|
+
.where("purpose", "=", purpose)
|
|
21
|
+
.forUpdate()
|
|
22
|
+
.executeTakeFirst();
|
|
23
|
+
if (!request)
|
|
24
|
+
return { valid: false, reason: "unknown" };
|
|
25
|
+
if (request.used_at)
|
|
26
|
+
return { valid: false, reason: "used" };
|
|
27
|
+
if (request.voided_at)
|
|
28
|
+
return { valid: false, reason: "replaced" };
|
|
29
|
+
if (request.expires_at.getTime() <= now)
|
|
30
|
+
return { valid: false, reason: "expired" };
|
|
31
|
+
if (request.attempts >= maximumAttempts)
|
|
32
|
+
return { valid: false, reason: "attempts" };
|
|
33
|
+
const at = transaction.updateTable("code_request").where("id", "=", requestId);
|
|
34
|
+
if (matchesOneTimeCode(code, request.code_hash, { pepper, purpose: `${purpose}:${requestId}` })) {
|
|
35
|
+
await at.set({ used_at: new Date(now) }).execute();
|
|
36
|
+
return { valid: true, contact: { kind: request.kind, value: request.value }, accountId: request.account_id };
|
|
37
|
+
}
|
|
38
|
+
const attempts = request.attempts + 1;
|
|
39
|
+
await at.set({ attempts }).execute();
|
|
40
|
+
return { valid: false, reason: attempts >= maximumAttempts ? "attempts" : "wrong" };
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/code-verification/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAEjF,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAE/E;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,QAAiC,EACjC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAA2B;IAEpG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACtE,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,K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,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;QAC/G,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACtC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACtF,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CodePurpose } from "@sharadox/account-web-library/code-request/type";
|
|
2
|
+
import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
|
|
3
|
+
export interface CodeVerificationOptions {
|
|
4
|
+
requestId: string;
|
|
5
|
+
/** As typed: spaces are ignored. */
|
|
6
|
+
code: string;
|
|
7
|
+
purpose: CodePurpose;
|
|
8
|
+
pepper: string;
|
|
9
|
+
/** Wrong codes allowed before the request is dead (5 by default). */
|
|
10
|
+
maximumAttempts?: number;
|
|
11
|
+
/** Milliseconds since 1970 (now by default). */
|
|
12
|
+
now?: number;
|
|
13
|
+
}
|
|
14
|
+
export type CodeVerificationResult = {
|
|
15
|
+
valid: true;
|
|
16
|
+
contact: Contact;
|
|
17
|
+
accountId: string | null;
|
|
18
|
+
} | {
|
|
19
|
+
valid: false;
|
|
20
|
+
reason: "unknown" | "used" | "replaced" | "expired" | "attempts" | "wrong";
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/code-verification/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AACnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,sBAAsB,GAC9B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC3D;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/code-verification/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { ContactAdditionRequest, ContactAdditionResult } from "@sharadox/account-web-library/contact-addition/type";
|
|
4
|
+
/**
|
|
5
|
+
* Adds a contact to an account, unverified until a one-time code sent to it comes back (`verifyContact`). Refuses
|
|
6
|
+
* one the account already has, or one another account has verified. Ask for a fresh code first (step-up) and tell
|
|
7
|
+
* the other contacts.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = await addContact(database, { accountId, contact: { kind: "email", value } });
|
|
11
|
+
*/
|
|
12
|
+
export declare function addContact(database: Kysely<AccountDatabase>, { accountId, contact, now }: ContactAdditionRequest): Promise<ContactAdditionResult>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/contact-addition/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,qDAAqD,CAAC;AAI7D;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,OAAO,EAAE,GAAgB,EAAE,EAAE,sBAAsB,GAC/D,OAAO,CAAC,qBAAqB,CAAC,CA8BhC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
3
|
+
import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
|
|
4
|
+
import { databaseError } from "@sharadox/account-web-library/database-error";
|
|
5
|
+
/**
|
|
6
|
+
* Adds a contact to an account, unverified until a one-time code sent to it comes back (`verifyContact`). Refuses
|
|
7
|
+
* one the account already has, or one another account has verified. Ask for a fresh code first (step-up) and tell
|
|
8
|
+
* the other contacts.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const result = await addContact(database, { accountId, contact: { kind: "email", value } });
|
|
12
|
+
*/
|
|
13
|
+
export async function addContact(database, { accountId, contact, now = Date.now() }) {
|
|
14
|
+
const { kind, value } = normalizeContact(contact);
|
|
15
|
+
const contactId = uuidVersion7({ now });
|
|
16
|
+
try {
|
|
17
|
+
return await database.transaction().execute(async (transaction) => {
|
|
18
|
+
const account = await transaction
|
|
19
|
+
.selectFrom("account")
|
|
20
|
+
.select("id")
|
|
21
|
+
.where("id", "=", accountId)
|
|
22
|
+
.executeTakeFirst();
|
|
23
|
+
if (!account)
|
|
24
|
+
return { added: false, reason: "no-account" };
|
|
25
|
+
const owner = await transaction
|
|
26
|
+
.selectFrom("contact")
|
|
27
|
+
.select("account_id")
|
|
28
|
+
.where("kind", "=", kind)
|
|
29
|
+
.where("value", "=", value)
|
|
30
|
+
.where("verified_at", "is not", null)
|
|
31
|
+
.executeTakeFirst();
|
|
32
|
+
if (owner && owner.account_id !== accountId)
|
|
33
|
+
return { added: false, reason: "contact-taken" };
|
|
34
|
+
await transaction
|
|
35
|
+
.insertInto("contact")
|
|
36
|
+
.values({ id: contactId, account_id: accountId, kind, value, verified_at: null, created_at: new Date(now) })
|
|
37
|
+
.execute();
|
|
38
|
+
await recordAuditEvent(transaction, { accountId, action: "contact.added", detail: { contactId, kind }, now });
|
|
39
|
+
return { added: true, contactId };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (databaseError(error)?.constraint === "contact_per_account")
|
|
44
|
+
return { added: false, reason: "already-added" };
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/contact-addition/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,QAAiC,EACjC,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC,G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;YACb,MAAM,gBAAgB,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YAC9G,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,qBAAqB;YAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;QACjH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
|
|
2
|
+
export interface ContactAdditionRequest {
|
|
3
|
+
accountId: string;
|
|
4
|
+
contact: Contact;
|
|
5
|
+
/** Milliseconds since 1970 (now by default). */
|
|
6
|
+
now?: number;
|
|
7
|
+
}
|
|
8
|
+
export type ContactAdditionResult = {
|
|
9
|
+
added: true;
|
|
10
|
+
contactId: string;
|
|
11
|
+
} | {
|
|
12
|
+
added: false;
|
|
13
|
+
reason: "already-added" | "contact-taken" | "no-account";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/contact-addition/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE/E,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,qBAAqB,GAC/B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,GAAG,eAAe,GAAG,YAAY,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/contact-addition/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
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. Call `notify` after
|
|
21
|
+
* answering, to tell the account's other contacts.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const result = await finishContactAddition(server, { accountId, requestId, code });
|
|
25
|
+
*/
|
|
26
|
+
export declare function finishContactAddition(server: AccountServer, { accountId, requestId, code, now, }: {
|
|
27
|
+
accountId: string;
|
|
28
|
+
requestId: string;
|
|
29
|
+
code: string;
|
|
30
|
+
now?: number;
|
|
31
|
+
}): Promise<ContactAdditionFinish>;
|
|
32
|
+
//# 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":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF,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,CAoC/B;AAED;;;;;;GAMG;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,CA2BhC"}
|