@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,376 @@
|
|
|
1
|
+
import { migrate } from "@sharadox/database-web-library/migration";
|
|
2
|
+
/** The table that records which account migrations a database has applied (apart from the application's own). */
|
|
3
|
+
export const ACCOUNT_MIGRATION_TABLE = "account_migration";
|
|
4
|
+
/**
|
|
5
|
+
* The account tables, forward only. The database enforces the rules itself, as the last line behind the code:
|
|
6
|
+
* UUIDv7 ids, username rules and case-insensitive uniqueness, one account per verified contact, agents owned by a
|
|
7
|
+
* person, every person keeping a verified sign-in contact (checked at commit), and an audit log that is never changed.
|
|
8
|
+
*/
|
|
9
|
+
export const accountMigrations = [
|
|
10
|
+
{
|
|
11
|
+
name: "0001-application-account-contact-audit",
|
|
12
|
+
sql: `
|
|
13
|
+
create table application (
|
|
14
|
+
id text primary key check (id ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$' and length(id) <= 50),
|
|
15
|
+
name text not null,
|
|
16
|
+
created_at timestamptz not null default now()
|
|
17
|
+
);
|
|
18
|
+
insert into application (id, name) values ('account', 'Account');
|
|
19
|
+
|
|
20
|
+
create table account (
|
|
21
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
22
|
+
kind text not null check (kind in ('person', 'agent')),
|
|
23
|
+
username text not null
|
|
24
|
+
check (length(username) between 1 and 50 and username ~ '^[A-Za-z0-9]+([-_.][A-Za-z0-9]+)*$'),
|
|
25
|
+
owner_id uuid references account (id) on delete cascade,
|
|
26
|
+
created_at timestamptz not null default now(),
|
|
27
|
+
last_active_at timestamptz not null default now(),
|
|
28
|
+
constraint account_owner_check check ((kind = 'agent') = (owner_id is not null))
|
|
29
|
+
);
|
|
30
|
+
create unique index account_username_key on account (lower(username));
|
|
31
|
+
create index account_owner on account (owner_id) where owner_id is not null;
|
|
32
|
+
create index account_last_active_at on account (last_active_at);
|
|
33
|
+
|
|
34
|
+
create table contact (
|
|
35
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
36
|
+
account_id uuid not null references account (id) on delete cascade,
|
|
37
|
+
kind text not null check (kind ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'),
|
|
38
|
+
value text not null check (length(value) between 1 and 320),
|
|
39
|
+
verified_at timestamptz,
|
|
40
|
+
sign_in boolean not null default true,
|
|
41
|
+
created_at timestamptz not null default now()
|
|
42
|
+
);
|
|
43
|
+
create unique index contact_verified on contact (kind, value) where verified_at is not null;
|
|
44
|
+
create unique index contact_per_account on contact (account_id, kind, value);
|
|
45
|
+
|
|
46
|
+
create function account_require_sign_in_contact(target uuid) returns void
|
|
47
|
+
language plpgsql set search_path = public as $$
|
|
48
|
+
begin
|
|
49
|
+
if exists (select 1 from account where id = target and kind = 'person')
|
|
50
|
+
and not exists (
|
|
51
|
+
select 1 from contact where account_id = target and verified_at is not null and sign_in
|
|
52
|
+
) then
|
|
53
|
+
raise exception 'a person account needs at least one verified sign-in contact' using errcode = '23514';
|
|
54
|
+
end if;
|
|
55
|
+
end $$;
|
|
56
|
+
create function account_after_insert() returns trigger
|
|
57
|
+
language plpgsql set search_path = public as $$
|
|
58
|
+
begin
|
|
59
|
+
perform account_require_sign_in_contact(new.id);
|
|
60
|
+
return null;
|
|
61
|
+
end $$;
|
|
62
|
+
create function contact_after_change() returns trigger
|
|
63
|
+
language plpgsql set search_path = public as $$
|
|
64
|
+
begin
|
|
65
|
+
perform account_require_sign_in_contact(old.account_id);
|
|
66
|
+
return null;
|
|
67
|
+
end $$;
|
|
68
|
+
create constraint trigger account_sign_in_contact after insert on account
|
|
69
|
+
deferrable initially deferred for each row execute function account_after_insert();
|
|
70
|
+
create constraint trigger contact_sign_in_contact after update or delete on contact
|
|
71
|
+
deferrable initially deferred for each row execute function contact_after_change();
|
|
72
|
+
|
|
73
|
+
create table audit_event (
|
|
74
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
75
|
+
at timestamptz not null default now(),
|
|
76
|
+
account_id uuid,
|
|
77
|
+
actor_account_id uuid,
|
|
78
|
+
application text,
|
|
79
|
+
action text not null check (length(action) between 1 and 100),
|
|
80
|
+
detail jsonb not null default '{}'
|
|
81
|
+
);
|
|
82
|
+
create index audit_event_account on audit_event (account_id, at);
|
|
83
|
+
create function audit_event_unchangeable() returns trigger
|
|
84
|
+
language plpgsql as $$
|
|
85
|
+
begin
|
|
86
|
+
raise exception 'audit events are never changed';
|
|
87
|
+
end $$;
|
|
88
|
+
create trigger audit_event_unchangeable before update on audit_event
|
|
89
|
+
for each row execute function audit_event_unchangeable();
|
|
90
|
+
`,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "0002-code-request",
|
|
94
|
+
sql: `
|
|
95
|
+
create table code_request (
|
|
96
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
97
|
+
purpose text not null check (purpose in ('sign-in', 'contact-verification', 'step-up')),
|
|
98
|
+
account_id uuid,
|
|
99
|
+
kind text not null,
|
|
100
|
+
value text not null,
|
|
101
|
+
code_hash text not null,
|
|
102
|
+
created_at timestamptz not null,
|
|
103
|
+
expires_at timestamptz not null,
|
|
104
|
+
attempts integer not null default 0 check (attempts >= 0),
|
|
105
|
+
used_at timestamptz,
|
|
106
|
+
voided_at timestamptz
|
|
107
|
+
);
|
|
108
|
+
create index code_request_open on code_request (kind, value, purpose) where used_at is null and voided_at is null;
|
|
109
|
+
create index code_request_expires_at on code_request (expires_at);
|
|
110
|
+
`,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "0003-session",
|
|
114
|
+
sql: `
|
|
115
|
+
create table browser_session (
|
|
116
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
117
|
+
token_hash text not null unique,
|
|
118
|
+
created_at timestamptz not null,
|
|
119
|
+
last_seen_at timestamptz not null,
|
|
120
|
+
expires_at timestamptz not null
|
|
121
|
+
);
|
|
122
|
+
create index browser_session_expires_at on browser_session (expires_at);
|
|
123
|
+
create table account_session (
|
|
124
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
125
|
+
browser_session_id uuid not null references browser_session (id) on delete cascade,
|
|
126
|
+
account_id uuid not null references account (id) on delete cascade,
|
|
127
|
+
created_at timestamptz not null,
|
|
128
|
+
last_seen_at timestamptz not null,
|
|
129
|
+
expires_at timestamptz not null,
|
|
130
|
+
second_factor_at timestamptz,
|
|
131
|
+
unique (browser_session_id, account_id)
|
|
132
|
+
);
|
|
133
|
+
create index account_session_account on account_session (account_id);
|
|
134
|
+
`,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "0004-identifier-name-picture-second-factor",
|
|
138
|
+
sql: `
|
|
139
|
+
alter table application rename constraint application_id_check to application_key_check;
|
|
140
|
+
alter table application rename column id to key;
|
|
141
|
+
alter table application drop constraint application_pkey;
|
|
142
|
+
alter table application add constraint application_key_key unique (key);
|
|
143
|
+
alter table application
|
|
144
|
+
add column id uuid primary key default uuidv7() check (uuid_extract_version(id) = 7);
|
|
145
|
+
|
|
146
|
+
alter table audit_event add column application_id uuid
|
|
147
|
+
references application (id) on update cascade on delete restrict;
|
|
148
|
+
alter table audit_event disable trigger audit_event_unchangeable;
|
|
149
|
+
update audit_event set application_id = application.id from application
|
|
150
|
+
where audit_event.application = application.key;
|
|
151
|
+
alter table audit_event enable trigger audit_event_unchangeable;
|
|
152
|
+
alter table audit_event drop column application;
|
|
153
|
+
|
|
154
|
+
create table identifier (
|
|
155
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
156
|
+
value text not null
|
|
157
|
+
check (length(value) between 1 and 50 and value ~ '^[A-Za-z0-9]+([-_.][A-Za-z0-9]+)*$'),
|
|
158
|
+
account_id uuid unique references account (id) on update cascade on delete cascade,
|
|
159
|
+
created_at timestamptz not null default now(),
|
|
160
|
+
constraint identifier_owner_check check (num_nonnulls(account_id) = 1)
|
|
161
|
+
);
|
|
162
|
+
create unique index identifier_value_key on identifier (lower(value));
|
|
163
|
+
insert into identifier (id, value, account_id) select uuidv7(), username, id from account;
|
|
164
|
+
|
|
165
|
+
alter table account add column name text
|
|
166
|
+
check (length(name) between 1 and 50 and name = btrim(name) and name !~ '[[:cntrl:]]');
|
|
167
|
+
update account set name = username;
|
|
168
|
+
alter table account alter column name set not null;
|
|
169
|
+
alter table account drop column username;
|
|
170
|
+
|
|
171
|
+
create function account_require_identifier(target uuid) returns void
|
|
172
|
+
language plpgsql set search_path = public as $$
|
|
173
|
+
begin
|
|
174
|
+
if exists (select 1 from account where id = target)
|
|
175
|
+
and not exists (select 1 from identifier where account_id = target) then
|
|
176
|
+
raise exception 'an account needs an identifier' using errcode = '23514';
|
|
177
|
+
end if;
|
|
178
|
+
end $$;
|
|
179
|
+
create function account_identifier_after_insert() returns trigger
|
|
180
|
+
language plpgsql set search_path = public as $$
|
|
181
|
+
begin
|
|
182
|
+
perform account_require_identifier(new.id);
|
|
183
|
+
return null;
|
|
184
|
+
end $$;
|
|
185
|
+
create function identifier_after_change() returns trigger
|
|
186
|
+
language plpgsql set search_path = public as $$
|
|
187
|
+
begin
|
|
188
|
+
if old.account_id is not null then
|
|
189
|
+
perform account_require_identifier(old.account_id);
|
|
190
|
+
end if;
|
|
191
|
+
return null;
|
|
192
|
+
end $$;
|
|
193
|
+
create constraint trigger account_identifier after insert on account
|
|
194
|
+
deferrable initially deferred for each row execute function account_identifier_after_insert();
|
|
195
|
+
create constraint trigger identifier_owner after update or delete on identifier
|
|
196
|
+
deferrable initially deferred for each row execute function identifier_after_change();
|
|
197
|
+
|
|
198
|
+
alter table account drop constraint account_owner_id_fkey, add constraint account_owner_id_fkey
|
|
199
|
+
foreign key (owner_id) references account (id) on update cascade on delete cascade;
|
|
200
|
+
alter table contact drop constraint contact_account_id_fkey, add constraint contact_account_id_fkey
|
|
201
|
+
foreign key (account_id) references account (id) on update cascade on delete cascade;
|
|
202
|
+
alter table account_session drop constraint account_session_browser_session_id_fkey,
|
|
203
|
+
add constraint account_session_browser_session_id_fkey foreign key (browser_session_id)
|
|
204
|
+
references browser_session (id) on update cascade on delete cascade;
|
|
205
|
+
alter table account_session drop constraint account_session_account_id_fkey,
|
|
206
|
+
add constraint account_session_account_id_fkey
|
|
207
|
+
foreign key (account_id) references account (id) on update cascade on delete cascade;
|
|
208
|
+
delete from code_request where account_id is not null
|
|
209
|
+
and not exists (select 1 from account where account.id = code_request.account_id);
|
|
210
|
+
alter table code_request add constraint code_request_account_id_fkey
|
|
211
|
+
foreign key (account_id) references account (id) on update cascade on delete cascade;
|
|
212
|
+
|
|
213
|
+
create table account_picture (
|
|
214
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
215
|
+
account_id uuid not null unique references account (id) on update cascade on delete cascade,
|
|
216
|
+
content_type text not null check (content_type in
|
|
217
|
+
('image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/svg+xml')),
|
|
218
|
+
byte_size integer not null check (byte_size between 1 and 5242880),
|
|
219
|
+
width integer not null check (width between 1 and 4096),
|
|
220
|
+
height integer not null check (height between 1 and 4096),
|
|
221
|
+
created_at timestamptz not null default now()
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
create table totp_credential (
|
|
225
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
226
|
+
account_id uuid not null unique references account (id) on update cascade on delete cascade,
|
|
227
|
+
secret_ciphertext text not null,
|
|
228
|
+
last_used_step bigint,
|
|
229
|
+
created_at timestamptz not null default now(),
|
|
230
|
+
confirmed_at timestamptz
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
create table recovery_code (
|
|
234
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
235
|
+
account_id uuid not null references account (id) on update cascade on delete cascade,
|
|
236
|
+
code_hash text not null,
|
|
237
|
+
created_at timestamptz not null default now(),
|
|
238
|
+
used_at timestamptz,
|
|
239
|
+
unique (account_id, code_hash)
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
alter table browser_session add column user_agent text check (length(user_agent) <= 500);
|
|
243
|
+
alter table account_session add column step_up_at timestamptz;
|
|
244
|
+
`,
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "0005-role",
|
|
248
|
+
sql: `
|
|
249
|
+
create table permission (
|
|
250
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
251
|
+
application_id uuid not null references application (id) on update cascade on delete cascade,
|
|
252
|
+
key text not null unique
|
|
253
|
+
check (length(key) <= 100 and key ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*(\\.[a-z][a-z0-9]*(-[a-z0-9]+)*)+$'),
|
|
254
|
+
description text not null default '' check (length(description) <= 500),
|
|
255
|
+
created_at timestamptz not null default now()
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
create table role (
|
|
259
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
260
|
+
application_id uuid references application (id) on update cascade on delete cascade,
|
|
261
|
+
key text not null check (length(key) <= 50 and key ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'),
|
|
262
|
+
name text not null check (length(name) between 1 and 100),
|
|
263
|
+
exclusive boolean not null default false,
|
|
264
|
+
is_default boolean not null default false,
|
|
265
|
+
created_at timestamptz not null default now(),
|
|
266
|
+
constraint role_default_check check (not (is_default and (exclusive or application_id is null)))
|
|
267
|
+
);
|
|
268
|
+
create unique index role_key on role (coalesce(application_id::text, ''), key);
|
|
269
|
+
create unique index role_default on role (application_id) where is_default;
|
|
270
|
+
|
|
271
|
+
create table role_permission (
|
|
272
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
273
|
+
role_id uuid not null references role (id) on update cascade on delete cascade,
|
|
274
|
+
permission_id uuid not null references permission (id) on update cascade on delete cascade,
|
|
275
|
+
unique (role_id, permission_id)
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
create table role_grant (
|
|
279
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
280
|
+
account_id uuid not null references account (id) on update cascade on delete cascade,
|
|
281
|
+
role_id uuid not null references role (id) on update cascade on delete restrict,
|
|
282
|
+
resource text check (length(resource) <= 200),
|
|
283
|
+
starts_at timestamptz not null default now(),
|
|
284
|
+
ends_at timestamptz,
|
|
285
|
+
source text not null check (source in ('manual', 'membership', 'ban', 'system')),
|
|
286
|
+
granted_by uuid references account (id) on update cascade on delete set null,
|
|
287
|
+
reason text check (length(reason) <= 1000),
|
|
288
|
+
created_at timestamptz not null default now(),
|
|
289
|
+
constraint role_grant_check check (ends_at is null or ends_at > starts_at)
|
|
290
|
+
);
|
|
291
|
+
create index role_grant_account on role_grant (account_id);
|
|
292
|
+
create index role_grant_role on role_grant (role_id);
|
|
293
|
+
`,
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
name: "0006-rule-ban",
|
|
297
|
+
sql: `
|
|
298
|
+
create table rule (
|
|
299
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
300
|
+
application_id uuid references application (id) on update cascade on delete cascade,
|
|
301
|
+
code text not null check (length(code) <= 50 and code ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'),
|
|
302
|
+
version integer not null check (version >= 1),
|
|
303
|
+
title jsonb not null,
|
|
304
|
+
description jsonb not null,
|
|
305
|
+
schedule jsonb not null check (jsonb_typeof(schedule) = 'array' and jsonb_array_length(schedule) >= 1),
|
|
306
|
+
created_at timestamptz not null default now()
|
|
307
|
+
);
|
|
308
|
+
create unique index rule_version_key on rule (coalesce(application_id::text, ''), code, version);
|
|
309
|
+
|
|
310
|
+
create table ban (
|
|
311
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
312
|
+
grant_id uuid not null unique references role_grant (id) on update cascade on delete cascade,
|
|
313
|
+
account_id uuid not null references account (id) on update cascade on delete cascade,
|
|
314
|
+
statement text not null check (length(statement) between 1 and 2000),
|
|
315
|
+
evidence text check (length(evidence) <= 5000),
|
|
316
|
+
penalty text not null check (penalty = 'permanent' or penalty ~ '^[0-9]+$'),
|
|
317
|
+
created_by uuid references account (id) on update cascade on delete set null,
|
|
318
|
+
created_at timestamptz not null default now()
|
|
319
|
+
);
|
|
320
|
+
create index ban_account on ban (account_id);
|
|
321
|
+
|
|
322
|
+
create table ban_rule (
|
|
323
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
324
|
+
ban_id uuid not null references ban (id) on update cascade on delete cascade,
|
|
325
|
+
rule_id uuid not null references rule (id) on update cascade on delete restrict,
|
|
326
|
+
unique (ban_id, rule_id)
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
create table appeal (
|
|
330
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
331
|
+
ban_id uuid not null unique references ban (id) on update cascade on delete cascade,
|
|
332
|
+
text text not null check (length(text) between 1 and 5000),
|
|
333
|
+
created_at timestamptz not null default now(),
|
|
334
|
+
decision text check (decision in ('upheld', 'shortened', 'lifted')),
|
|
335
|
+
reasons text check (length(reasons) <= 5000),
|
|
336
|
+
decided_by uuid references account (id) on update cascade on delete set null,
|
|
337
|
+
decided_at timestamptz
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
create table banned_contact (
|
|
341
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
342
|
+
contact_hash text not null,
|
|
343
|
+
application_id uuid references application (id) on update cascade on delete cascade,
|
|
344
|
+
ends_at timestamptz,
|
|
345
|
+
rule_codes text[] not null,
|
|
346
|
+
created_at timestamptz not null default now()
|
|
347
|
+
);
|
|
348
|
+
create index banned_contact_hash on banned_contact (contact_hash);
|
|
349
|
+
`,
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
name: "0007-language-inactivity",
|
|
353
|
+
sql: `
|
|
354
|
+
alter table account add column language text check (length(language) <= 20);
|
|
355
|
+
|
|
356
|
+
create table inactivity_warning (
|
|
357
|
+
id uuid primary key check (uuid_extract_version(id) = 7),
|
|
358
|
+
account_id uuid not null references account (id) on update cascade on delete cascade,
|
|
359
|
+
stage text not null check (stage in ('6-months', '3-months', '1-month', '1-week', '1-day')),
|
|
360
|
+
active_at timestamptz not null,
|
|
361
|
+
sent_at timestamptz not null default now(),
|
|
362
|
+
unique (account_id, stage, active_at)
|
|
363
|
+
);
|
|
364
|
+
`,
|
|
365
|
+
},
|
|
366
|
+
];
|
|
367
|
+
/**
|
|
368
|
+
* Creates or updates the account tables, tracked in their own migration table. Returns the names applied.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* await migrateAccount(database);
|
|
372
|
+
*/
|
|
373
|
+
export function migrateAccount(database) {
|
|
374
|
+
return migrate(database, accountMigrations, { table: ACCOUNT_MIGRATION_TABLE });
|
|
375
|
+
}
|
|
376
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-migration/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0CAA0C,CAAC;AAGnE,iHAAiH;AACjH,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAgB;IAC5C;QACE,IAAI,EAAE,wCAAwC;QAC9C,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8EJ;KACF;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,GAAG,EAAE;;;;;;;;;;;;;;;;KAgBJ;KACF;IACD;QACE,IAAI,EAAE,cAAc;QACpB,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;KAoBJ;KACF;IACD;QACE,IAAI,EAAE,4CAA4C;QAClD,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0GJ;KACF;IACD;QACE,IAAI,EAAE,WAAW;QACjB,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6CJ;KACF;IACD;QACE,IAAI,EAAE,eAAe;QACrB,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoDJ;KACF;IACD;QACE,IAAI,EAAE,0BAA0B;QAChC,GAAG,EAAE;;;;;;;;;;;KAWJ;KACF;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAS,QAAwB;IAC7D,OAAO,OAAO,CAAC,QAAQ,EAAE,iBAAiB,EAAE,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AccountNameCheck } from "@sharadox/account-web-library/account-name/type";
|
|
2
|
+
/** The longest name, in characters (an emoji counts once). */
|
|
3
|
+
export declare const ACCOUNT_NAME_MAXIMUM_LENGTH = 50;
|
|
4
|
+
/**
|
|
5
|
+
* Checks the name an account shows (`Luis Pires`): any letters and symbols, 1 to 50 characters once trimmed and with
|
|
6
|
+
* runs of spaces made single, and no control characters (new lines, tabs, nulls).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* checkAccountName(" Luís Pires "); // { valid: true, name: "Luís Pires" }
|
|
10
|
+
* checkAccountName(""); // { valid: false, reason: "length" }
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkAccountName(name: string): AccountNameCheck;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-name/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iDAAiD,CAAC;AAExF,8DAA8D;AAC9D,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAK9C;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAM/D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The longest name, in characters (an emoji counts once). */
|
|
2
|
+
export const ACCOUNT_NAME_MAXIMUM_LENGTH = 50;
|
|
3
|
+
// eslint-disable-next-line no-control-regex
|
|
4
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
5
|
+
/**
|
|
6
|
+
* Checks the name an account shows (`Luis Pires`): any letters and symbols, 1 to 50 characters once trimmed and with
|
|
7
|
+
* runs of spaces made single, and no control characters (new lines, tabs, nulls).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* checkAccountName(" Luís Pires "); // { valid: true, name: "Luís Pires" }
|
|
11
|
+
* checkAccountName(""); // { valid: false, reason: "length" }
|
|
12
|
+
*/
|
|
13
|
+
export function checkAccountName(name) {
|
|
14
|
+
if (CONTROL.test(name))
|
|
15
|
+
return { valid: false, reason: "characters" };
|
|
16
|
+
const tidy = name.trim().replace(/ {2,}/g, " ");
|
|
17
|
+
const length = [...tidy].length;
|
|
18
|
+
if (length < 1 || length > ACCOUNT_NAME_MAXIMUM_LENGTH)
|
|
19
|
+
return { valid: false, reason: "length" };
|
|
20
|
+
return { valid: true, name: tidy };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-name/index.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AAE9C,4CAA4C;AAC5C,MAAM,OAAO,GAAG,+BAA+B,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IACtE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC;IAChC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,2BAA2B;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAClG,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-name/type.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,YAAY,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-name/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { AccountNameChangeResult } from "@sharadox/account-web-library/account-name-change/type";
|
|
4
|
+
/**
|
|
5
|
+
* Changes the name an account shows (tidied by `checkAccountName`). The audit log records that it changed, not the
|
|
6
|
+
* names, which are personal data.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* await changeAccountName(database, { accountId, name: "Luis Pires" }); // { changed: true }
|
|
10
|
+
*/
|
|
11
|
+
export declare function changeAccountName(database: Kysely<AccountDatabase>, { accountId, name }: {
|
|
12
|
+
accountId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}): Promise<AccountNameChangeResult>;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-name-change/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AAGtG;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,uBAAuB,CAAC,CAalC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { checkAccountName } from "@sharadox/account-web-library/account-name";
|
|
2
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
3
|
+
/**
|
|
4
|
+
* Changes the name an account shows (tidied by `checkAccountName`). The audit log records that it changed, not the
|
|
5
|
+
* names, which are personal data.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* await changeAccountName(database, { accountId, name: "Luis Pires" }); // { changed: true }
|
|
9
|
+
*/
|
|
10
|
+
export async function changeAccountName(database, { accountId, name }) {
|
|
11
|
+
const check = checkAccountName(name);
|
|
12
|
+
if (!check.valid)
|
|
13
|
+
return { changed: false, reason: "name-invalid" };
|
|
14
|
+
return database.transaction().execute(async (transaction) => {
|
|
15
|
+
const updated = await transaction
|
|
16
|
+
.updateTable("account")
|
|
17
|
+
.set({ name: check.name })
|
|
18
|
+
.where("id", "=", accountId)
|
|
19
|
+
.executeTakeFirst();
|
|
20
|
+
if (updated.numUpdatedRows === 0n)
|
|
21
|
+
return { changed: false, reason: "no-account" };
|
|
22
|
+
await recordAuditEvent(transaction, { accountId, action: "account.name-changed" });
|
|
23
|
+
return { changed: true };
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-name-change/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAiC,EACjC,EAAE,SAAS,EAAE,IAAI,EAAuC;IAExD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IACpE,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAoC,EAAE;QAC5F,MAAM,OAAO,GAAG,MAAM,WAAW;aAC9B,WAAW,CAAC,SAAS,CAAC;aACtB,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;aACzB,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;aAC3B,gBAAgB,EAAE,CAAC;QACtB,IAAI,OAAO,CAAC,cAAc,KAAK,EAAE;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;QACnF,MAAM,gBAAgB,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC,CAAC;QACnF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-name-change/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-name-change/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AccountServer } from "@sharadox/account-web-library/account-server/type";
|
|
2
|
+
import type { Notice } from "@sharadox/account-web-library/contact-channel/type";
|
|
3
|
+
/**
|
|
4
|
+
* Tells an account's owner something they must know (a new email, a recovery code used, a coming deletion), at every
|
|
5
|
+
* verified contact but `except`, in the account's language. A failed send is recorded and doesn't stop the others.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* after(() => notifyAccount(server, { accountId, notice: { kind: "recovery-code-used" } }));
|
|
9
|
+
*/
|
|
10
|
+
export declare function notifyAccount(server: AccountServer, { accountId, notice, except }: {
|
|
11
|
+
accountId: string;
|
|
12
|
+
notice: Notice;
|
|
13
|
+
except?: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-notice/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAEvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oDAAoD,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,aAAa,EACrB,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACpF,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
2
|
+
/**
|
|
3
|
+
* Tells an account's owner something they must know (a new email, a recovery code used, a coming deletion), at every
|
|
4
|
+
* verified contact but `except`, in the account's language. A failed send is recorded and doesn't stop the others.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* after(() => notifyAccount(server, { accountId, notice: { kind: "recovery-code-used" } }));
|
|
8
|
+
*/
|
|
9
|
+
export async function notifyAccount(server, { accountId, notice, except }) {
|
|
10
|
+
const account = await server.database
|
|
11
|
+
.selectFrom("account")
|
|
12
|
+
.select("language")
|
|
13
|
+
.where("id", "=", accountId)
|
|
14
|
+
.executeTakeFirst();
|
|
15
|
+
let contacts = server.database
|
|
16
|
+
.selectFrom("contact")
|
|
17
|
+
.select(["id", "kind", "value"])
|
|
18
|
+
.where("account_id", "=", accountId)
|
|
19
|
+
.where("verified_at", "is not", null);
|
|
20
|
+
if (except)
|
|
21
|
+
contacts = contacts.where("id", "!=", except);
|
|
22
|
+
for (const contact of await contacts.orderBy("id").execute()) {
|
|
23
|
+
const channel = server.channels.find(({ kind }) => kind === contact.kind);
|
|
24
|
+
try {
|
|
25
|
+
await channel?.notify?.({
|
|
26
|
+
contact: { kind: contact.kind, value: contact.value },
|
|
27
|
+
language: account?.language ?? "en",
|
|
28
|
+
notice,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const { name, message } = error;
|
|
33
|
+
await recordAuditEvent(server.database, {
|
|
34
|
+
accountId,
|
|
35
|
+
action: "notice.delivery-failed",
|
|
36
|
+
detail: { kind: notice.kind, error: `${name}: ${message}`.slice(0, 500) },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-notice/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAG7E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAqB,EACrB,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAA0D;IAErF,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ;SAClC,UAAU,CAAC,SAAS,CAAC;SACrB,MAAM,CAAC,UAAU,CAAC;SAClB,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;SAC3B,gBAAgB,EAAE,CAAC;IACtB,IAAI,QAAQ,GAAG,MAAM,CAAC,QAAQ;SAC3B,UAAU,CAAC,SAAS,CAAC;SACrB,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;SAC/B,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC;SACnC,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IACxC,IAAI,MAAM;QAAE,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1D,KAAK,MAAM,OAAO,IAAI,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7D,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1E,IAAI,CAAC;YACH,MAAM,OAAO,EAAE,MAAM,EAAE,CAAC;gBACtB,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE;gBACrD,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,IAAI;gBACnC,MAAM;aACP,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAc,CAAC;YACzC,MAAM,gBAAgB,CAAC,MAAM,CAAC,QAAQ,EAAE;gBACtC,SAAS;gBACT,MAAM,EAAE,wBAAwB;gBAChC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;aAC1E,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -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 { AccountPermissionQuestion } from "@sharadox/account-web-library/account-permission/type";
|
|
4
|
+
/**
|
|
5
|
+
* What an account may do in one application now, from the database: the application's default role, the account's
|
|
6
|
+
* active grants (an active exclusive one, a ban, leaving only its own permissions), limited to `scope`, and for an
|
|
7
|
+
* agent to what its owner may do right now. An unknown application gives nothing.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const permissions = await accountPermissions(database, { accountId, application: "platform" });
|
|
11
|
+
* if (!permissions.has("platform.job.create")) return forbidden();
|
|
12
|
+
*/
|
|
13
|
+
export declare function accountPermissions(database: Kysely<AccountDatabase>, { accountId, application, resource, scope, now }: AccountPermissionQuestion): Promise<Set<string>>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-permission/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,yBAAyB,EAAE,MAAM,uDAAuD,CAAC;AAIvG;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAgB,EAAE,EAAE,yBAAyB,GACvF,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CA+EtB"}
|