@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,233 @@
|
|
|
1
|
+
import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
|
|
2
|
+
import { accountPermissions } from "@sharadox/account-web-library/account-permission";
|
|
3
|
+
import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
|
|
4
|
+
import { banLength } from "@sharadox/account-web-library/ban-length";
|
|
5
|
+
import { revokeGrant } from "@sharadox/account-web-library/role-grant";
|
|
6
|
+
/** Banning, in the account system's own application. */
|
|
7
|
+
export const BAN_PERMISSION = "account.ban.create";
|
|
8
|
+
/** Deciding appeals, in the account system's own application. */
|
|
9
|
+
export const APPEAL_PERMISSION = "account.appeal.decide";
|
|
10
|
+
const allowed = async (database, accountId, permission) => (await accountPermissions(database, { accountId, application: "account" })).has(permission);
|
|
11
|
+
/**
|
|
12
|
+
* Bans an account in an application for breaking rules: the length comes from the rules' penalty schedules (this
|
|
13
|
+
* offense for each, counted per account, rule and application; the longest wins), so equal offenses get equal
|
|
14
|
+
* penalties. The ban is the application's exclusive role, granted until then (or for good), with a record of the
|
|
15
|
+
* rule versions broken and the statement of reasons. Recorded in the audit log.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* await banAccount(database, { accountId, application: "platform", rules: ["spam"], statement, by: moderator });
|
|
19
|
+
*/
|
|
20
|
+
export async function banAccount(database, { accountId, application, rules, statement, evidence, by, now = Date.now() }) {
|
|
21
|
+
if (by && !(await allowed(database, by, BAN_PERMISSION)))
|
|
22
|
+
return { banned: false, reason: "not-allowed" };
|
|
23
|
+
const app = await database
|
|
24
|
+
.selectFrom("application")
|
|
25
|
+
.select("id")
|
|
26
|
+
.where("key", "=", application)
|
|
27
|
+
.executeTakeFirstOrThrow();
|
|
28
|
+
if (rules.length === 0)
|
|
29
|
+
return { banned: false, reason: "no-rule", detail: "" };
|
|
30
|
+
const cited = [];
|
|
31
|
+
for (const code of rules) {
|
|
32
|
+
const rule = await database
|
|
33
|
+
.selectFrom("rule")
|
|
34
|
+
.select(["id", "code", "schedule"])
|
|
35
|
+
.where("code", "=", code)
|
|
36
|
+
.where((where) => where.or([where("application_id", "=", app.id), where("application_id", "is", null)]))
|
|
37
|
+
.orderBy("version", "desc")
|
|
38
|
+
.executeTakeFirst();
|
|
39
|
+
if (!rule)
|
|
40
|
+
return { banned: false, reason: "no-rule", detail: code };
|
|
41
|
+
cited.push(rule);
|
|
42
|
+
}
|
|
43
|
+
const role = await database
|
|
44
|
+
.selectFrom("role")
|
|
45
|
+
.select("id")
|
|
46
|
+
.where("application_id", "=", app.id)
|
|
47
|
+
.where("exclusive", "=", true)
|
|
48
|
+
.orderBy("key")
|
|
49
|
+
.executeTakeFirst();
|
|
50
|
+
if (!role)
|
|
51
|
+
return { banned: false, reason: "no-ban-role" };
|
|
52
|
+
const broken = [];
|
|
53
|
+
for (const rule of cited) {
|
|
54
|
+
const previous = await database
|
|
55
|
+
.selectFrom("ban_rule")
|
|
56
|
+
.innerJoin("rule", "rule.id", "ban_rule.rule_id")
|
|
57
|
+
.innerJoin("ban", "ban.id", "ban_rule.ban_id")
|
|
58
|
+
.select((select) => select.fn.countAll().as("count"))
|
|
59
|
+
.where("ban.account_id", "=", accountId)
|
|
60
|
+
.where("rule.code", "=", rule.code)
|
|
61
|
+
.where("rule.application_id", "is not distinct from", app.id)
|
|
62
|
+
.executeTakeFirstOrThrow();
|
|
63
|
+
broken.push({ schedule: rule.schedule, previousOffenses: Number(previous.count) });
|
|
64
|
+
}
|
|
65
|
+
const penalty = banLength(broken);
|
|
66
|
+
const endsAt = penalty === "permanent" ? null : new Date(now + penalty * 1000);
|
|
67
|
+
const banId = uuidVersion7({ now });
|
|
68
|
+
await database.transaction().execute(async (transaction) => {
|
|
69
|
+
const grantId = uuidVersion7({ now });
|
|
70
|
+
await transaction
|
|
71
|
+
.insertInto("role_grant")
|
|
72
|
+
.values({
|
|
73
|
+
id: grantId,
|
|
74
|
+
account_id: accountId,
|
|
75
|
+
role_id: role.id,
|
|
76
|
+
starts_at: new Date(now),
|
|
77
|
+
ends_at: endsAt,
|
|
78
|
+
source: "ban",
|
|
79
|
+
granted_by: by ?? null,
|
|
80
|
+
reason: statement,
|
|
81
|
+
})
|
|
82
|
+
.execute();
|
|
83
|
+
await transaction
|
|
84
|
+
.insertInto("ban")
|
|
85
|
+
.values({
|
|
86
|
+
id: banId,
|
|
87
|
+
grant_id: grantId,
|
|
88
|
+
account_id: accountId,
|
|
89
|
+
statement,
|
|
90
|
+
evidence: evidence ?? null,
|
|
91
|
+
penalty: String(penalty),
|
|
92
|
+
created_by: by ?? null,
|
|
93
|
+
})
|
|
94
|
+
.execute();
|
|
95
|
+
await transaction
|
|
96
|
+
.insertInto("ban_rule")
|
|
97
|
+
.values(cited.map((rule) => ({ id: uuidVersion7({ now }), ban_id: banId, rule_id: rule.id })))
|
|
98
|
+
.execute();
|
|
99
|
+
await recordAuditEvent(transaction, {
|
|
100
|
+
accountId,
|
|
101
|
+
actorAccountId: by ?? null,
|
|
102
|
+
application,
|
|
103
|
+
action: "ban.created",
|
|
104
|
+
detail: { banId, rules, penalty },
|
|
105
|
+
now,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return { banned: true, banId, endsAt };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The one appeal a ban may have, written by the banned account.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* await appealBan(database, { banId, accountId, text });
|
|
115
|
+
*/
|
|
116
|
+
export async function appealBan(database, { banId, accountId, text, now = Date.now() }) {
|
|
117
|
+
const ban = await database
|
|
118
|
+
.selectFrom("ban")
|
|
119
|
+
.select("id")
|
|
120
|
+
.where("id", "=", banId)
|
|
121
|
+
.where("account_id", "=", accountId)
|
|
122
|
+
.executeTakeFirst();
|
|
123
|
+
if (!ban)
|
|
124
|
+
return { appealed: false, reason: "no-ban" };
|
|
125
|
+
const existing = await database.selectFrom("appeal").select("id").where("ban_id", "=", banId).executeTakeFirst();
|
|
126
|
+
if (existing)
|
|
127
|
+
return { appealed: false, reason: "already-appealed" };
|
|
128
|
+
// The database still refuses a second one sent at the same moment (unique ban_id).
|
|
129
|
+
const appealId = uuidVersion7({ now });
|
|
130
|
+
await database
|
|
131
|
+
.insertInto("appeal")
|
|
132
|
+
.values({ id: appealId, ban_id: banId, text, created_at: new Date(now) })
|
|
133
|
+
.execute();
|
|
134
|
+
await recordAuditEvent(database, { accountId, action: "ban.appealed", detail: { banId, appealId }, now });
|
|
135
|
+
return { appealed: true, appealId };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A moderator's decision on an appeal, with its reasons: `upheld` keeps the ban, `shortened` moves its end to
|
|
139
|
+
* `endsAt`, `lifted` ends it now. Decided once.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* await decideAppeal(database, { appealId, by: moderator, decision: "lifted", reasons });
|
|
143
|
+
*/
|
|
144
|
+
export async function decideAppeal(database, { appealId, by, decision, reasons, endsAt, now = Date.now(), }) {
|
|
145
|
+
if (!(await allowed(database, by, APPEAL_PERMISSION)))
|
|
146
|
+
return { decided: false, reason: "not-allowed" };
|
|
147
|
+
const appeal = await database
|
|
148
|
+
.selectFrom("appeal")
|
|
149
|
+
.innerJoin("ban", "ban.id", "appeal.ban_id")
|
|
150
|
+
.select(["appeal.decision", "ban.grant_id", "ban.account_id", "ban.id as banId"])
|
|
151
|
+
.where("appeal.id", "=", appealId)
|
|
152
|
+
.executeTakeFirst();
|
|
153
|
+
if (!appeal)
|
|
154
|
+
return { decided: false, reason: "no-appeal" };
|
|
155
|
+
if (appeal.decision)
|
|
156
|
+
return { decided: false, reason: "already-decided" };
|
|
157
|
+
if (decision === "lifted")
|
|
158
|
+
await revokeGrant(database, { grantId: appeal.grant_id, revokedBy: by, now });
|
|
159
|
+
if (decision === "shortened" && endsAt !== undefined)
|
|
160
|
+
await database
|
|
161
|
+
.updateTable("role_grant")
|
|
162
|
+
.set({ ends_at: new Date(endsAt) })
|
|
163
|
+
.where("id", "=", appeal.grant_id)
|
|
164
|
+
.execute();
|
|
165
|
+
await database
|
|
166
|
+
.updateTable("appeal")
|
|
167
|
+
.set({ decision, reasons, decided_by: by, decided_at: new Date(now) })
|
|
168
|
+
.where("id", "=", appealId)
|
|
169
|
+
.execute();
|
|
170
|
+
await recordAuditEvent(database, {
|
|
171
|
+
accountId: appeal.account_id,
|
|
172
|
+
actorAccountId: by,
|
|
173
|
+
action: "ban.appeal-decided",
|
|
174
|
+
detail: { banId: appeal.banId, appealId, decision },
|
|
175
|
+
now,
|
|
176
|
+
});
|
|
177
|
+
return { decided: true };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* An account's bans, newest first: the rules cited, the statement, the penalty, when it ends, whether it is active,
|
|
181
|
+
* and its appeal.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const bans = await listBans(database, { accountId });
|
|
185
|
+
*/
|
|
186
|
+
export async function listBans(database, { accountId, now = Date.now() }) {
|
|
187
|
+
const bans = await database
|
|
188
|
+
.selectFrom("ban")
|
|
189
|
+
.innerJoin("role_grant", "role_grant.id", "ban.grant_id")
|
|
190
|
+
.innerJoin("role", "role.id", "role_grant.role_id")
|
|
191
|
+
.leftJoin("application", "application.id", "role.application_id")
|
|
192
|
+
.leftJoin("appeal", "appeal.ban_id", "ban.id")
|
|
193
|
+
.select([
|
|
194
|
+
"ban.id as banId",
|
|
195
|
+
"application.key as application",
|
|
196
|
+
"ban.statement",
|
|
197
|
+
"ban.penalty",
|
|
198
|
+
"role_grant.starts_at as startsAt",
|
|
199
|
+
"role_grant.ends_at as endsAt",
|
|
200
|
+
"appeal.id as appealId",
|
|
201
|
+
"appeal.text as appealText",
|
|
202
|
+
"appeal.decision",
|
|
203
|
+
"appeal.reasons",
|
|
204
|
+
])
|
|
205
|
+
.where("ban.account_id", "=", accountId)
|
|
206
|
+
.orderBy("ban.id", "desc")
|
|
207
|
+
.execute();
|
|
208
|
+
const views = [];
|
|
209
|
+
for (const ban of bans) {
|
|
210
|
+
const rules = await database
|
|
211
|
+
.selectFrom("ban_rule")
|
|
212
|
+
.innerJoin("rule", "rule.id", "ban_rule.rule_id")
|
|
213
|
+
.select("rule.code")
|
|
214
|
+
.where("ban_rule.ban_id", "=", ban.banId)
|
|
215
|
+
.orderBy("rule.code")
|
|
216
|
+
.execute();
|
|
217
|
+
views.push({
|
|
218
|
+
banId: ban.banId,
|
|
219
|
+
application: ban.application,
|
|
220
|
+
rules: rules.map(({ code }) => code),
|
|
221
|
+
statement: ban.statement,
|
|
222
|
+
penalty: ban.penalty,
|
|
223
|
+
startsAt: ban.startsAt,
|
|
224
|
+
endsAt: ban.endsAt,
|
|
225
|
+
active: ban.startsAt.getTime() <= now && (ban.endsAt === null || now < ban.endsAt.getTime()),
|
|
226
|
+
appeal: ban.appealId
|
|
227
|
+
? { appealId: ban.appealId, text: ban.appealText, decision: ban.decision, reasons: ban.reasons }
|
|
228
|
+
: null,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return views;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-ban/index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CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface BanRequest {
|
|
2
|
+
accountId: string;
|
|
3
|
+
/** The application's key (`platform`): its exclusive role is the ban. */
|
|
4
|
+
application: string;
|
|
5
|
+
/** The codes of the rules broken (newest versions), the application's own or global. */
|
|
6
|
+
rules: string[];
|
|
7
|
+
/** The statement of reasons the account is shown. */
|
|
8
|
+
statement: string;
|
|
9
|
+
evidence?: string;
|
|
10
|
+
/** The moderator: needs `account.ban.create`. The system without it. */
|
|
11
|
+
by?: string;
|
|
12
|
+
now?: number;
|
|
13
|
+
}
|
|
14
|
+
export type BanResult = {
|
|
15
|
+
banned: true;
|
|
16
|
+
banId: string;
|
|
17
|
+
endsAt: Date | null;
|
|
18
|
+
} | {
|
|
19
|
+
banned: false;
|
|
20
|
+
reason: "not-allowed" | "no-ban-role";
|
|
21
|
+
} | {
|
|
22
|
+
banned: false;
|
|
23
|
+
reason: "no-rule";
|
|
24
|
+
detail: string;
|
|
25
|
+
};
|
|
26
|
+
/** A ban as the banned account, or a moderator, sees it. */
|
|
27
|
+
export interface BanView {
|
|
28
|
+
banId: string;
|
|
29
|
+
application: string | null;
|
|
30
|
+
rules: string[];
|
|
31
|
+
statement: string;
|
|
32
|
+
/** Seconds, or "permanent". */
|
|
33
|
+
penalty: string;
|
|
34
|
+
startsAt: Date;
|
|
35
|
+
endsAt: Date | null;
|
|
36
|
+
active: boolean;
|
|
37
|
+
appeal: {
|
|
38
|
+
appealId: string;
|
|
39
|
+
text: string;
|
|
40
|
+
decision: string | null;
|
|
41
|
+
reasons: string | null;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-ban/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,yE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1,264 @@
|
|
|
1
|
+
import type { ProtectionDatabase } from "@sharadox/protection-web-library/protection-database/type";
|
|
2
|
+
import type { ColumnType, Generated } from "kysely";
|
|
3
|
+
/** A timestamp the database fills in when not given. */
|
|
4
|
+
type DefaultTime = ColumnType<Date, Date | undefined, Date>;
|
|
5
|
+
/** An application the accounts sign in to (`account` itself, `platform`, `shop`…). */
|
|
6
|
+
export interface ApplicationTable {
|
|
7
|
+
/** UUIDv7. */
|
|
8
|
+
id: Generated<string>;
|
|
9
|
+
/** Its permanent short name, the prefix of its permissions (`account`, `platform`). */
|
|
10
|
+
key: string;
|
|
11
|
+
name: string;
|
|
12
|
+
created_at: DefaultTime;
|
|
13
|
+
}
|
|
14
|
+
/** A person, or an agent owned by a person. */
|
|
15
|
+
export interface AccountTable {
|
|
16
|
+
id: string;
|
|
17
|
+
kind: "person" | "agent";
|
|
18
|
+
/** The person's or agent's name, 1 to 50 characters. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The person who owns an agent; null for people. */
|
|
21
|
+
owner_id: string | null;
|
|
22
|
+
created_at: DefaultTime;
|
|
23
|
+
last_active_at: DefaultTime;
|
|
24
|
+
/** The language its notices are written in (`pt-PT`); English when null. */
|
|
25
|
+
language: ColumnType<string | null, string | null | undefined, string | null>;
|
|
26
|
+
}
|
|
27
|
+
/** A way to reach an account (email now; phone and messaging later). */
|
|
28
|
+
export interface ContactTable {
|
|
29
|
+
id: string;
|
|
30
|
+
account_id: string;
|
|
31
|
+
kind: string;
|
|
32
|
+
/** Normalized (see `normalizeContact`). */
|
|
33
|
+
value: string;
|
|
34
|
+
/** When a one-time code proved it; null until then. A verified contact belongs to one account only. */
|
|
35
|
+
verified_at: Date | null;
|
|
36
|
+
/** Whether codes for signing in may be sent to it. */
|
|
37
|
+
sign_in: Generated<boolean>;
|
|
38
|
+
created_at: DefaultTime;
|
|
39
|
+
}
|
|
40
|
+
/** One line of the append-only audit log. */
|
|
41
|
+
export interface AuditEventTable {
|
|
42
|
+
id: string;
|
|
43
|
+
at: DefaultTime;
|
|
44
|
+
/** The account it is about (kept after the account is deleted, as a bare id). */
|
|
45
|
+
account_id: string | null;
|
|
46
|
+
/** Who did it, when not the account itself (an administrator, an agent). */
|
|
47
|
+
actor_account_id: string | null;
|
|
48
|
+
/** The application it happened in; null for the account system as a whole. */
|
|
49
|
+
application_id: string | null;
|
|
50
|
+
action: string;
|
|
51
|
+
detail: ColumnType<Record<string, unknown>, Record<string, unknown> | undefined, never>;
|
|
52
|
+
}
|
|
53
|
+
/** A one-time code sent to a contact, stored only as an HMAC bound to its purpose and request. */
|
|
54
|
+
export interface CodeRequestTable {
|
|
55
|
+
id: string;
|
|
56
|
+
/** `sign-in`, `contact-verification` or `step-up`. */
|
|
57
|
+
purpose: string;
|
|
58
|
+
/** The account asking (step-up, contact verification); null when signing in. */
|
|
59
|
+
account_id: string | null;
|
|
60
|
+
kind: string;
|
|
61
|
+
value: string;
|
|
62
|
+
code_hash: string;
|
|
63
|
+
created_at: Date;
|
|
64
|
+
expires_at: Date;
|
|
65
|
+
attempts: Generated<number>;
|
|
66
|
+
/** When the right code came back. */
|
|
67
|
+
used_at: Date | null;
|
|
68
|
+
/** When a newer request for the same contact and purpose replaced it. */
|
|
69
|
+
voided_at: Date | null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A unique name to reference something by (`@luis-pires`): one namespace for accounts now and organizations later,
|
|
73
|
+
* unique without regard to case. Stored without the `@`.
|
|
74
|
+
*/
|
|
75
|
+
export interface IdentifierTable {
|
|
76
|
+
id: string;
|
|
77
|
+
/** Shown as written. */
|
|
78
|
+
value: string;
|
|
79
|
+
/** The account it names (exactly one owner per identifier). */
|
|
80
|
+
account_id: string | null;
|
|
81
|
+
created_at: DefaultTime;
|
|
82
|
+
}
|
|
83
|
+
/** An account's picture: the file itself is in object storage, under its id. */
|
|
84
|
+
export interface AccountPictureTable {
|
|
85
|
+
id: string;
|
|
86
|
+
account_id: string;
|
|
87
|
+
content_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp" | "image/avif" | "image/svg+xml";
|
|
88
|
+
byte_size: number;
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
created_at: DefaultTime;
|
|
92
|
+
}
|
|
93
|
+
/** An authenticator app (TOTP) for two-factor, its secret encrypted with a key outside the database. */
|
|
94
|
+
export interface TotpCredentialTable {
|
|
95
|
+
id: string;
|
|
96
|
+
account_id: string;
|
|
97
|
+
secret_ciphertext: string;
|
|
98
|
+
/** The last 30-second step accepted, so a code can't be replayed. */
|
|
99
|
+
last_used_step: ColumnType<string | null, number | string | null | undefined, number | string | null>;
|
|
100
|
+
created_at: DefaultTime;
|
|
101
|
+
/** When the first correct code turned it on; null while it is being set up. */
|
|
102
|
+
confirmed_at: Date | null;
|
|
103
|
+
}
|
|
104
|
+
/** A single-use recovery code, stored only as an HMAC. */
|
|
105
|
+
export interface RecoveryCodeTable {
|
|
106
|
+
id: string;
|
|
107
|
+
account_id: string;
|
|
108
|
+
code_hash: string;
|
|
109
|
+
created_at: DefaultTime;
|
|
110
|
+
used_at: Date | null;
|
|
111
|
+
}
|
|
112
|
+
/** One browser (the account site's cookie holds its token; only the token's hash is stored). */
|
|
113
|
+
export interface BrowserSessionTable {
|
|
114
|
+
id: string;
|
|
115
|
+
token_hash: string;
|
|
116
|
+
/** The browser's description (its User-Agent, at most 500 characters), for the list of devices. */
|
|
117
|
+
user_agent: ColumnType<string | null, string | null | undefined, string | null>;
|
|
118
|
+
created_at: Date;
|
|
119
|
+
last_seen_at: Date;
|
|
120
|
+
expires_at: Date;
|
|
121
|
+
}
|
|
122
|
+
/** One account signed in on one browser: a browser can hold any number of them (the account selector). */
|
|
123
|
+
export interface AccountSessionTable {
|
|
124
|
+
id: string;
|
|
125
|
+
browser_session_id: string;
|
|
126
|
+
account_id: string;
|
|
127
|
+
created_at: Date;
|
|
128
|
+
last_seen_at: Date;
|
|
129
|
+
expires_at: Date;
|
|
130
|
+
/** When two-factor was last passed in this session; null without it. */
|
|
131
|
+
second_factor_at: Date | null;
|
|
132
|
+
/** When a fresh code last confirmed it is really them, for sensitive changes (`step-up`). */
|
|
133
|
+
step_up_at: ColumnType<Date | null, Date | null | undefined, Date | null>;
|
|
134
|
+
}
|
|
135
|
+
/** Something an account may do in one application (`platform.job.read`); declared by the application. */
|
|
136
|
+
export interface PermissionTable {
|
|
137
|
+
id: string;
|
|
138
|
+
application_id: string;
|
|
139
|
+
/** Starts with the application's key. */
|
|
140
|
+
key: string;
|
|
141
|
+
description: Generated<string>;
|
|
142
|
+
created_at: DefaultTime;
|
|
143
|
+
}
|
|
144
|
+
/** A set of permissions in one application (or every one: `application_id` null). */
|
|
145
|
+
export interface RoleTable {
|
|
146
|
+
id: string;
|
|
147
|
+
application_id: string | null;
|
|
148
|
+
key: string;
|
|
149
|
+
name: string;
|
|
150
|
+
/** While granted, the account has only this role's permissions there (how bans work). */
|
|
151
|
+
exclusive: Generated<boolean>;
|
|
152
|
+
/** Every account holds its application's default role, without a grant. */
|
|
153
|
+
is_default: Generated<boolean>;
|
|
154
|
+
created_at: DefaultTime;
|
|
155
|
+
}
|
|
156
|
+
export interface RolePermissionTable {
|
|
157
|
+
id: string;
|
|
158
|
+
role_id: string;
|
|
159
|
+
permission_id: string;
|
|
160
|
+
}
|
|
161
|
+
/** A role given to an account, maybe for one resource, from a moment until another (or for good). */
|
|
162
|
+
export interface RoleGrantTable {
|
|
163
|
+
id: string;
|
|
164
|
+
account_id: string;
|
|
165
|
+
role_id: string;
|
|
166
|
+
/** `platform:project:42`; null for the whole application. */
|
|
167
|
+
resource: string | null;
|
|
168
|
+
starts_at: DefaultTime;
|
|
169
|
+
ends_at: Date | null;
|
|
170
|
+
source: "manual" | "membership" | "ban" | "system";
|
|
171
|
+
/** Who gave it; null for the system, or once that account is gone. */
|
|
172
|
+
granted_by: string | null;
|
|
173
|
+
reason: string | null;
|
|
174
|
+
created_at: DefaultTime;
|
|
175
|
+
}
|
|
176
|
+
/** Words in each language (`{ en, pt }`). */
|
|
177
|
+
type Words = Record<string, string>;
|
|
178
|
+
/** One version of a public rule, with its penalties for the 1st, 2nd… offense (seconds, or "permanent"). */
|
|
179
|
+
export interface RuleTable {
|
|
180
|
+
id: string;
|
|
181
|
+
/** Null for every application. */
|
|
182
|
+
application_id: string | null;
|
|
183
|
+
code: string;
|
|
184
|
+
version: number;
|
|
185
|
+
title: ColumnType<Words, Words | string, Words | string>;
|
|
186
|
+
description: ColumnType<Words, Words | string, Words | string>;
|
|
187
|
+
schedule: ColumnType<(number | "permanent")[], (number | "permanent")[] | string, (number | "permanent")[] | string>;
|
|
188
|
+
created_at: DefaultTime;
|
|
189
|
+
}
|
|
190
|
+
/** A ban: the exclusive grant it made, its statement of reasons, and how its length was reached. */
|
|
191
|
+
export interface BanTable {
|
|
192
|
+
id: string;
|
|
193
|
+
grant_id: string;
|
|
194
|
+
account_id: string;
|
|
195
|
+
statement: string;
|
|
196
|
+
evidence: string | null;
|
|
197
|
+
/** Seconds, or "permanent". */
|
|
198
|
+
penalty: string;
|
|
199
|
+
created_by: string | null;
|
|
200
|
+
created_at: DefaultTime;
|
|
201
|
+
}
|
|
202
|
+
/** A rule version a ban cites. */
|
|
203
|
+
export interface BanRuleTable {
|
|
204
|
+
id: string;
|
|
205
|
+
ban_id: string;
|
|
206
|
+
rule_id: string;
|
|
207
|
+
}
|
|
208
|
+
/** The one appeal a ban may have, and its decision. */
|
|
209
|
+
export interface AppealTable {
|
|
210
|
+
id: string;
|
|
211
|
+
ban_id: string;
|
|
212
|
+
text: string;
|
|
213
|
+
created_at: DefaultTime;
|
|
214
|
+
decision: "upheld" | "shortened" | "lifted" | null;
|
|
215
|
+
reasons: string | null;
|
|
216
|
+
decided_by: string | null;
|
|
217
|
+
decided_at: Date | null;
|
|
218
|
+
}
|
|
219
|
+
/** A banned account's contact, kept (as an HMAC only) after the account is deleted, until the ban ends. */
|
|
220
|
+
export interface BannedContactTable {
|
|
221
|
+
id: string;
|
|
222
|
+
contact_hash: string;
|
|
223
|
+
application_id: string | null;
|
|
224
|
+
ends_at: Date | null;
|
|
225
|
+
rule_codes: string[];
|
|
226
|
+
created_at: DefaultTime;
|
|
227
|
+
}
|
|
228
|
+
/** An inactivity warning sent, for one period of inactivity (from `active_at`). */
|
|
229
|
+
export interface InactivityWarningTable {
|
|
230
|
+
id: string;
|
|
231
|
+
account_id: string;
|
|
232
|
+
stage: "6-months" | "3-months" | "1-month" | "1-week" | "1-day";
|
|
233
|
+
/** The `last_active_at` it counted from: signing in starts a new period. */
|
|
234
|
+
active_at: Date;
|
|
235
|
+
sent_at: DefaultTime;
|
|
236
|
+
}
|
|
237
|
+
/** The tables `migrateAccount` creates, for typing a Kysely instance. */
|
|
238
|
+
export interface AccountDatabase {
|
|
239
|
+
application: ApplicationTable;
|
|
240
|
+
account: AccountTable;
|
|
241
|
+
contact: ContactTable;
|
|
242
|
+
audit_event: AuditEventTable;
|
|
243
|
+
code_request: CodeRequestTable;
|
|
244
|
+
browser_session: BrowserSessionTable;
|
|
245
|
+
account_session: AccountSessionTable;
|
|
246
|
+
identifier: IdentifierTable;
|
|
247
|
+
account_picture: AccountPictureTable;
|
|
248
|
+
totp_credential: TotpCredentialTable;
|
|
249
|
+
recovery_code: RecoveryCodeTable;
|
|
250
|
+
permission: PermissionTable;
|
|
251
|
+
role: RoleTable;
|
|
252
|
+
role_permission: RolePermissionTable;
|
|
253
|
+
role_grant: RoleGrantTable;
|
|
254
|
+
rule: RuleTable;
|
|
255
|
+
ban: BanTable;
|
|
256
|
+
ban_rule: BanRuleTable;
|
|
257
|
+
appeal: AppealTable;
|
|
258
|
+
banned_contact: BannedContactTable;
|
|
259
|
+
inactivity_warning: InactivityWarningTable;
|
|
260
|
+
}
|
|
261
|
+
/** The account tables and the protection tables (rate limits, spending caps, used challenges) the server needs. */
|
|
262
|
+
export type AccountServerDatabase = AccountDatabase & ProtectionDatabase;
|
|
263
|
+
export {};
|
|
264
|
+
//# sourceMappingURL=type.d.ts.map
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AY,CAAC;IACtB,WAAW,EAAE,eAAe,CAAC;IAC7B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,eAAe,EAAE,mBAAmB,CAAC;IACrC,eAAe,EAAE,mBAAmB,CAAC;IACrC,UAAU,EAAE,eAAe,CAAC;IAC5B,eAAe,EAAE,mBAAmB,CAAC;IACrC,eAAe,EAAE,mBAAmB,CAAC;IACrC,aAAa,EAAE,iBAAiB,CAAC;IACjC,UAAU,EAAE,eAAe,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,eAAe,EAAE,mBAAmB,CAAC;IACrC,UAAU,EAAE,cAAc,CAAC;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,QAAQ,CAAC;IACd,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;IACpB,cAAc,EAAE,kBAAkB,CAAC;IACnC,kBAAkB,EAAE,sBAAsB,CAAC;CAC5C;AAED,mHAAmH;AACnH,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-database/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { PictureStorage } from "@sharadox/account-web-library/picture-storage/type";
|
|
4
|
+
/**
|
|
5
|
+
* Deletes an account for good: its picture file, then the account with everything that belongs to it (identifier,
|
|
6
|
+
* contacts, sessions, two-factor, agents), in one transaction. Its identifier is free at once. The audit log keeps
|
|
7
|
+
* `account.deleted` and earlier events under the bare id, with no personal data. An account banned somewhere leaves
|
|
8
|
+
* its contacts in the banned-contact ledger (HMACs under `ledgerPepper`) until the ban ends. Ask for a fresh code
|
|
9
|
+
* first (step-up).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* await deleteAccount(database, storage, { accountId, ledgerPepper }); // { deleted: true }
|
|
13
|
+
*/
|
|
14
|
+
export declare function deleteAccount(database: Kysely<AccountDatabase>, storage: PictureStorage, { accountId, ledgerPepper, now }: {
|
|
15
|
+
accountId: string;
|
|
16
|
+
ledgerPepper: string;
|
|
17
|
+
now?: number;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
deleted: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-deletion/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAK3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAEzF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,OAAO,EAAE,cAAc,EACvB,EAAE,SAAS,EAAE,YAAY,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACvG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAoD/B"}
|