@sharadox/account-web-library 0.1.0-development.9 → 0.1.0-roles.29
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 +204 -17
- 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/{username-change → account-ban}/type.js.map +1 -1
- package/distribution/account-database/type.d.ts +195 -4
- package/distribution/account-database/type.d.ts.map +1 -1
- 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.map +1 -1
- package/distribution/account-migration/index.js +254 -0
- package/distribution/account-migration/index.js.map +1 -1
- package/distribution/account-name/index.d.ts +13 -0
- package/distribution/account-name/index.d.ts.map +1 -0
- package/distribution/account-name/index.js +22 -0
- package/distribution/account-name/index.js.map +1 -0
- package/distribution/account-name/type.d.ts +9 -0
- package/distribution/account-name/type.d.ts.map +1 -0
- package/distribution/account-name/type.js +2 -0
- package/distribution/account-name/type.js.map +1 -0
- package/distribution/account-name-change/index.d.ts +15 -0
- package/distribution/account-name-change/index.d.ts.map +1 -0
- package/distribution/account-name-change/index.js +26 -0
- package/distribution/account-name-change/index.js.map +1 -0
- package/distribution/account-name-change/type.d.ts +7 -0
- package/distribution/account-name-change/type.d.ts.map +1 -0
- package/distribution/account-name-change/type.js +2 -0
- package/distribution/account-name-change/type.js.map +1 -0
- package/distribution/account-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 +22 -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.map +1 -1
- package/distribution/audit-event/index.js +12 -1
- package/distribution/audit-event/index.js.map +1 -1
- package/distribution/audit-event/type.d.ts +1 -0
- package/distribution/audit-event/type.d.ts.map +1 -1
- package/distribution/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.js +1 -1
- package/distribution/code-request/type.d.ts +1 -1
- package/distribution/code-sending/index.d.ts +14 -0
- package/distribution/code-sending/index.d.ts.map +1 -0
- package/distribution/code-sending/index.js +65 -0
- package/distribution/code-sending/index.js.map +1 -0
- package/distribution/code-sending/type.d.ts +31 -0
- package/distribution/code-sending/type.d.ts.map +1 -0
- package/distribution/code-sending/type.js +2 -0
- package/distribution/code-sending/type.js.map +1 -0
- package/distribution/contact-addition-flow/index.d.ts +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 +44 -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/database-error/index.d.ts +1 -1
- package/distribution/database-error/index.js +1 -1
- 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 +168 -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 +7 -3
- package/distribution/person-account/index.d.ts.map +1 -1
- package/distribution/person-account/index.js +29 -9
- package/distribution/person-account/index.js.map +1 -1
- package/distribution/person-account/type.d.ts +7 -2
- package/distribution/person-account/type.d.ts.map +1 -1
- package/distribution/picture-key/index.d.ts +8 -0
- package/distribution/picture-key/index.d.ts.map +1 -0
- package/distribution/picture-key/index.js +10 -0
- package/distribution/picture-key/index.js.map +1 -0
- package/distribution/picture-preparation/index.d.ts +18 -0
- package/distribution/picture-preparation/index.d.ts.map +1 -0
- package/distribution/picture-preparation/index.js +86 -0
- package/distribution/picture-preparation/index.js.map +1 -0
- package/distribution/picture-preparation/type.d.ts +18 -0
- package/distribution/picture-preparation/type.d.ts.map +1 -0
- package/distribution/picture-preparation/type.js +2 -0
- package/distribution/picture-preparation/type.js.map +1 -0
- package/distribution/picture-storage/type.d.ts +11 -0
- package/distribution/picture-storage/type.d.ts.map +1 -0
- package/distribution/picture-storage/type.js +2 -0
- package/distribution/picture-storage/type.js.map +1 -0
- package/distribution/recovery-code-regeneration/index.d.ts +19 -0
- package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
- package/distribution/recovery-code-regeneration/index.js +34 -0
- package/distribution/recovery-code-regeneration/index.js.map +1 -0
- package/distribution/recovery-code-store/index.d.ts +25 -0
- package/distribution/recovery-code-store/index.d.ts.map +1 -0
- package/distribution/recovery-code-store/index.js +34 -0
- package/distribution/recovery-code-store/index.js.map +1 -0
- package/distribution/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 +83 -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 +12 -0
- package/distribution/sign-in-finish/index.d.ts.map +1 -0
- package/distribution/sign-in-finish/index.js +64 -0
- package/distribution/sign-in-finish/index.js.map +1 -0
- package/distribution/sign-in-finish/type.d.ts +41 -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-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 +7 -3
- package/distribution/username/index.d.ts +0 -23
- package/distribution/username/index.d.ts.map +0 -1
- package/distribution/username/index.js +0 -32
- package/distribution/username/index.js.map +0 -1
- package/distribution/username/type.d.ts +0 -10
- package/distribution/username/type.d.ts.map +0 -1
- package/distribution/username-availability/index.d.ts +0 -11
- package/distribution/username-availability/index.d.ts.map +0 -1
- package/distribution/username-availability/index.js +0 -21
- package/distribution/username-availability/index.js.map +0 -1
- package/distribution/username-change/index.d.ts +0 -15
- package/distribution/username-change/index.d.ts.map +0 -1
- package/distribution/username-change/index.js +0 -39
- package/distribution/username-change/index.js.map +0 -1
- package/distribution/username-change/type.d.ts +0 -7
- package/distribution/username-change/type.d.ts.map +0 -1
- /package/distribution/{username-change → account-activity}/type.js +0 -0
- /package/distribution/{username → account-ban}/type.js +0 -0
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@ Passwordless accounts for web applications, built on open standards, with no aut
|
|
|
9
9
|
|
|
10
10
|
One deployment per company. Everything company-specific is configuration.
|
|
11
11
|
|
|
12
|
-
**Status: 0.1.0, in progress.**
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
**Status: 0.1.0, in progress.** Sign-in by emailed code with optional two-factor (authenticator apps and recovery
|
|
13
|
+
codes), and everything an account manages for itself: name, identifier, picture, contacts, devices, activity, data
|
|
14
|
+
export and deletion. Roles, bans and the OpenID Connect server come next (see `CHANGELOG.md`).
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
@@ -19,6 +19,54 @@ Sign-in codes, sessions and the OpenID Connect server come next (see `CHANGELOG.
|
|
|
19
19
|
pnpm add @sharadox/account-web-library
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## The sign-in flow
|
|
23
|
+
|
|
24
|
+
Signing up and signing in are the same three steps, on one `AccountServer`:
|
|
25
|
+
`{ database, channels, secret, limits? }`. The database holds the account tables and protection-web-library's
|
|
26
|
+
(`migrateProtection` and `migrateAccount`). `secret` is `ACCOUNT_SECRET`: at least 32 random characters, server only.
|
|
27
|
+
Every key is derived from it with `deriveSecret`.
|
|
28
|
+
|
|
29
|
+
1. `issueChallenge(server)` gives the page a proof-of-work challenge, which the browser solves in the background.
|
|
30
|
+
2. `startSignIn(server, { contact, solution, address, language, now? })` checks, in this order:
|
|
31
|
+
- the proof of work (single use);
|
|
32
|
+
- the contact and its channel;
|
|
33
|
+
- rate limits per contact, per address group and for everyone;
|
|
34
|
+
- the channel's daily spending cap.
|
|
35
|
+
|
|
36
|
+
It answers `{ status: "sent", requestId, deliver }`, and you call `deliver` after answering (Next.js `after()`).
|
|
37
|
+
Each send is recorded in the audit log as `code.sent`, or as `code.delivery-failed` with the error, never the
|
|
38
|
+
code.
|
|
39
|
+
Otherwise it answers `refused` with `proof`, `contact`, `unavailable` (the cap is reached: sending pauses), or
|
|
40
|
+
`rate-limit` with `retryAfterSeconds`. The answer never depends on whether an account exists.
|
|
41
|
+
|
|
42
|
+
3. `finishSignIn(server, { requestId, code, address, token, now? })` limits guesses per address group. It answers:
|
|
43
|
+
- `signed-in`, with `{ accountId, token }`: set `token` as the cookie;
|
|
44
|
+
- `sign-up`, with `{ ticket }`, for a contact with no account;
|
|
45
|
+
- `refused`, with the code's reason or `rate-limit`.
|
|
46
|
+
4. `finishSignUp(server, { ticket, name, identifier, token, userAgent?, now? })` creates the account and signs it
|
|
47
|
+
in. A refused name or identifier can be tried again with the same ticket, which lasts 15 minutes.
|
|
48
|
+
5. With two-factor on, `finishSignIn` answers `second-factor` with a ticket (10 minutes) instead of signing in:
|
|
49
|
+
`finishSecondFactor(server, { ticket, code, address, token, userAgent?, now? })` takes the authenticator app's
|
|
50
|
+
code (never the same step twice) or a recovery code (single use). Guesses are limited per account and per
|
|
51
|
+
address group.
|
|
52
|
+
|
|
53
|
+
Pass `token` (the cookie) to `startSignIn` too: a contact of an account already signed in on that browser gets
|
|
54
|
+
`{ status: "signed-in", accountId }` and no code. Codes are 6 digits, shown in emails as `123 456`. Identifiers are
|
|
55
|
+
always stored and passed without the `@` that the interface shows in front of them.
|
|
56
|
+
|
|
57
|
+
`DEFAULT_SIGN_IN_LIMITS` (`account-server`):
|
|
58
|
+
|
|
59
|
+
| Limit | Default |
|
|
60
|
+
| ------------------------- | --------------------------------- |
|
|
61
|
+
| `perContact` | 3 codes, then 1 every 5 minutes |
|
|
62
|
+
| `perAddress` | 10, then 1 a minute |
|
|
63
|
+
| `global` | 200, then 1 a second |
|
|
64
|
+
| `verificationsPerAddress` | 20 typed codes, then 1 every 30 s |
|
|
65
|
+
| `dailySendsPerChannel` | 2,000 |
|
|
66
|
+
| `difficulty` | 14 bits |
|
|
67
|
+
|
|
68
|
+
`createTicket` and `readTicket` (`signed-ticket`) carry signed, short-lived data between steps.
|
|
69
|
+
|
|
22
70
|
## Storage
|
|
23
71
|
|
|
24
72
|
Postgres through Kysely (`@sharadox/database-web-library`). Run `migrateAccount(database)` when the application
|
|
@@ -26,7 +74,11 @@ migrates: the tables are tracked in their own table (`account_migration`). Type
|
|
|
26
74
|
(`account-database/type`). The database enforces the rules itself, as the last line behind the code:
|
|
27
75
|
|
|
28
76
|
- ids are UUIDv7;
|
|
29
|
-
-
|
|
77
|
+
- every row's id is a UUIDv7, and foreign keys cascade updates and deletes (an application with audit events
|
|
78
|
+
can't be deleted);
|
|
79
|
+
- identifiers live in one table for everything that has one (accounts now, organizations later), follow the rules,
|
|
80
|
+
and are unique without regard to case; every account keeps exactly one;
|
|
81
|
+
- names have 1 to 50 characters, trimmed, with no control characters;
|
|
30
82
|
- a verified contact belongs to one account only;
|
|
31
83
|
- every person keeps at least one verified sign-in contact, checked when a change commits;
|
|
32
84
|
- agents have an owner (and go with them);
|
|
@@ -39,22 +91,27 @@ dependency).
|
|
|
39
91
|
|
|
40
92
|
Each export has its own entry point (`@sharadox/account-web-library/<name>`).
|
|
41
93
|
|
|
42
|
-
### `
|
|
94
|
+
### `account-name`: `checkAccountName(name)`, `ACCOUNT_NAME_MAXIMUM_LENGTH`
|
|
95
|
+
|
|
96
|
+
The name an account shows: any letters and symbols, 1 to 50 characters once trimmed and with runs of spaces made
|
|
97
|
+
single, and no control characters. `checkAccountName(" Luís Pires ")` → `{ valid: true, name: "Luís Pires" }`.
|
|
98
|
+
|
|
99
|
+
### `identifier`: `checkIdentifier(name)`, `identifierKey(name)`, `IDENTIFIER_MAXIMUM_LENGTH`
|
|
43
100
|
|
|
44
101
|
The rules:
|
|
45
102
|
|
|
46
103
|
- 1 to 50 characters;
|
|
47
104
|
- A–Z, a–z and 0–9, with `-`, `_` or `.` allowed only between letters or digits, never two in a row;
|
|
48
|
-
- shown as written, but unique without regard to case: `abc` and `aBc` are the same
|
|
105
|
+
- shown as written, but unique without regard to case: `abc` and `aBc` are the same identifier.
|
|
49
106
|
|
|
50
107
|
```ts
|
|
51
|
-
|
|
52
|
-
|
|
108
|
+
checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
|
|
109
|
+
checkIdentifier("a--b"); // { valid: false, reason: "characters" }
|
|
53
110
|
```
|
|
54
111
|
|
|
55
112
|
Store `key` under a unique index.
|
|
56
113
|
|
|
57
|
-
### `one-time-code`: `createOneTimeCode(length =
|
|
114
|
+
### `one-time-code`: `createOneTimeCode(length = 6)`, `hashOneTimeCode(code, { pepper, purpose })`, `matchesOneTimeCode(code, hash, { pepper, purpose })`
|
|
58
115
|
|
|
59
116
|
- Codes are uniform random digits.
|
|
60
117
|
- Only an HMAC-SHA-256 is stored, under a pepper of at least 32 characters kept outside the database, and bound to
|
|
@@ -105,20 +162,20 @@ Codes like `7KQM-W3HD-9TXA` (about 59 bits each), from characters that can't be
|
|
|
105
162
|
- `normalizeEmail` trims and lowercases, and throws for text that isn't an email address.
|
|
106
163
|
- `emailLedgerForm` also drops `+tags`, for the banned-contact ledger.
|
|
107
164
|
|
|
108
|
-
### `person-account`: `createPersonAccount(database, {
|
|
165
|
+
### `person-account`: `createPersonAccount(database, { name, identifier, contact, now? })`
|
|
109
166
|
|
|
110
167
|
Creates a person with the contact their one-time code just proved, stored verified, and records `account.created`.
|
|
111
|
-
Returns `{ created: true, accountId, contactId }`, or `{ created: false, reason }` with `
|
|
112
|
-
`
|
|
168
|
+
Returns `{ created: true, accountId, contactId }`, or `{ created: false, reason }` with `name-invalid`,
|
|
169
|
+
`identifier-invalid`, `identifier-taken` or `contact-taken`.
|
|
113
170
|
|
|
114
|
-
### `
|
|
171
|
+
### `identifier-availability`: `identifierAvailability(database, identifier)` → `available` | `taken` | `invalid`
|
|
115
172
|
|
|
116
173
|
Rate limit it: it tells whether an account exists.
|
|
117
174
|
|
|
118
|
-
### `
|
|
175
|
+
### `identifier-change`: `changeIdentifier(database, { accountId, identifier })`
|
|
119
176
|
|
|
120
|
-
Any time, and the old name is free at once; the audit log keeps `{ from, to }`. Reasons: `
|
|
121
|
-
`
|
|
177
|
+
Any time, and the old name is free at once; the audit log keeps `{ from, to }`. Reasons: `identifier-invalid`,
|
|
178
|
+
`identifier-taken`, `no-account`.
|
|
122
179
|
|
|
123
180
|
### `contact-lookup`: `findAccountByContact(database, contact)` → `{ accountId, contactId, signIn }` or undefined
|
|
124
181
|
|
|
@@ -134,7 +191,7 @@ Verified contacts only, normalized first.
|
|
|
134
191
|
|
|
135
192
|
Each is recorded in the audit log. Ask for a fresh code first (step-up) and tell the other contacts.
|
|
136
193
|
|
|
137
|
-
### `code-request`: `requestCode(database, { purpose, contact, accountId?, pepper, length =
|
|
194
|
+
### `code-request`: `requestCode(database, { purpose, contact, accountId?, pepper, length = 6, lifetimeSeconds = 600, now? })` → `{ requestId, code, contact, expiresAt }`
|
|
138
195
|
|
|
139
196
|
Starts a one-time code for `sign-in`, `contact-verification` or `step-up`.
|
|
140
197
|
|
|
@@ -151,6 +208,34 @@ pass the limit; after the last attempt even the right code is refused.
|
|
|
151
208
|
|
|
152
209
|
### `code-request-prune`: `pruneCodeRequests(database, { before })` → deleted count
|
|
153
210
|
|
|
211
|
+
### Sessions and the account selector
|
|
212
|
+
|
|
213
|
+
A browser holds one cookie with an opaque token (only its SHA-256 is stored). On the server, that browser session
|
|
214
|
+
points to any number of account sessions, so the selector has no limit and the cookie never grows. Use a
|
|
215
|
+
`__Host-` cookie: HttpOnly, Secure, SameSite=Lax, path `/`.
|
|
216
|
+
|
|
217
|
+
- `signIn(database, { accountId, token?, secondFactor?, accountSessionSeconds = 30 days, browserSessionSeconds = 400 days, now? })`
|
|
218
|
+
→ `{ token, browserSessionId, accountSessionId }`. Adds the account to the browser's accounts (or starts a
|
|
219
|
+
browser session). The browser gets a **new token at every sign-in**: set it as the cookie.
|
|
220
|
+
- `readBrowserSession(database, { token, idleSeconds = 7 days, now? })` → `{ browserSessionId, accounts }` or
|
|
221
|
+
undefined. `accounts` are `{ accountSessionId, accountId, identifier, name, pictureId, signedInAt, secondFactorAt }`, in sign-in
|
|
222
|
+
order, without ended or idle sessions. It marks them as seen.
|
|
223
|
+
- `signOut(database, { token, accountId? })` → `{ signedOut }`: one account, or all and the browser session.
|
|
224
|
+
- `revokeAccountSessions(database, { accountId, actorAccountId? })` → count: signed out on every browser.
|
|
225
|
+
- `pruneSessions(database, { idleSeconds?, now? })` → `{ accountSessions, browserSessions }`, for a daily job.
|
|
226
|
+
- `createSessionToken()`, `hashSessionToken(token)` (`session-token`).
|
|
227
|
+
|
|
228
|
+
### `email-channel`: `createEmailChannel({ sender, from, design, logos?, now? })` → `ContactChannel`
|
|
229
|
+
|
|
230
|
+
Sends codes by email through email-web-library's sender, in the shared email layout.
|
|
231
|
+
|
|
232
|
+
- English, or European Portuguese for any `pt` reader.
|
|
233
|
+
- The code is in the body only, never in the subject (lock screens show subjects).
|
|
234
|
+
- No link to click: nothing for a phishing email to imitate.
|
|
235
|
+
|
|
236
|
+
A `ContactChannel` (`contact-channel/type`) is `{ kind, send({ contact, code, purpose, language, expiresAt }) }`:
|
|
237
|
+
phone, WhatsApp, Messenger and Instagram channels will have the same shape.
|
|
238
|
+
|
|
154
239
|
### `contact-kind`: `normalizeContact({ kind, value })`, `CONTACT_KINDS`
|
|
155
240
|
|
|
156
241
|
`email` in this version; unknown kinds and invalid values throw.
|
|
@@ -161,6 +246,108 @@ Pass the transaction of the change it describes. `detail` holds ids and kinds, n
|
|
|
161
246
|
|
|
162
247
|
### `database-error`: `databaseError(error)` → `{ code, constraint }` or undefined
|
|
163
248
|
|
|
249
|
+
## Managing an account
|
|
250
|
+
|
|
251
|
+
Everything a person can do with their own account. Ask for a fresh code first (step-up) before changing contacts,
|
|
252
|
+
two-factor or recovery codes, and before deleting the account.
|
|
253
|
+
|
|
254
|
+
### `step-up`: `startStepUp(server, { accountId, contactId, address, language })`, `finishStepUp(server, { accountId, requestId, code, token })`, `hasFreshStepUp(database, { accountId, token })`
|
|
255
|
+
|
|
256
|
+
A code to one of the account's own verified contacts. Once it comes back, this browser's session of the account is
|
|
257
|
+
confirmed for 10 minutes (`STEP_UP_SECONDS`): check `hasFreshStepUp` before every sensitive change.
|
|
258
|
+
|
|
259
|
+
### `code-sending`: `sendCode(server, { purpose, contact, channel, accountId?, address, language })`
|
|
260
|
+
|
|
261
|
+
What every flow above uses to send a code: rate limits per contact, per address group and for everyone, the
|
|
262
|
+
channel's daily cap, then `deliver` to call after answering, recorded as `code.sent` or `code.delivery-failed`.
|
|
263
|
+
|
|
264
|
+
### `account-name-change`: `changeAccountName(database, { accountId, name })`
|
|
265
|
+
|
|
266
|
+
Reasons: `name-invalid`, `no-account`. The audit log records that it changed, not the names.
|
|
267
|
+
|
|
268
|
+
### Pictures: `picture-preparation`, `account-picture-change`, `picture-key`, `picture-storage/type`, `memory-picture-storage`
|
|
269
|
+
|
|
270
|
+
- `preparePicture(bytes)` takes JPEG, PNG, GIF, WebP, AVIF or SVG, up to 5 MB and 4096 pixels, and gives WebP of at
|
|
271
|
+
most 1024 pixels on the longer side. Metadata (a photo's location) is dropped and its rotation applied; GIFs stay
|
|
272
|
+
animated; SVGs are drawn into an image, so nothing in them can run. It refuses (`reason`) `size`, `type`,
|
|
273
|
+
`dimensions`, `suspicious` (far more bytes than the picture needs: something is hidden in it) and `unsafe` (an SVG
|
|
274
|
+
that loads anything from outside itself, or declares entities).
|
|
275
|
+
- `setAccountPicture(database, storage, { accountId, bytes })` → `{ changed: true, pictureId }`: the new file is
|
|
276
|
+
stored first, then the old one is deleted. `removeAccountPicture(database, storage, { accountId })`.
|
|
277
|
+
- Files live in object storage under `pictureKey(pictureId)` (`account-picture/<id>.webp`). The application gives a
|
|
278
|
+
`PictureStorage` (`put(key, bytes, contentType)`, `remove(key)`); tests use `createMemoryPictureStorage()`.
|
|
279
|
+
|
|
280
|
+
### Contacts: `contact-addition-flow`
|
|
281
|
+
|
|
282
|
+
`startContactAddition(server, { accountId, contact, address, language })` adds the contact unverified and sends it a
|
|
283
|
+
code (asking again sends a new one); `finishContactAddition(server, { accountId, requestId, code })` verifies it.
|
|
284
|
+
Removing one is `removeContact` (the last sign-in contact can't go).
|
|
285
|
+
|
|
286
|
+
### Two-factor: `totp-setup`, `recovery-code-regeneration`, `second-factor-finish`, `secret-encryption`
|
|
287
|
+
|
|
288
|
+
- `startTotpSetup(server, { accountId, issuer })` → `{ status: "started", uri, secret }`: show `uri` as a QR code and
|
|
289
|
+
`secret` for typing in. The secret is stored encrypted (AES-256-GCM, key derived from `ACCOUNT_SECRET`).
|
|
290
|
+
- `confirmTotpSetup(server, { accountId, code })` turns it on with the app's first right code and returns 10 recovery
|
|
291
|
+
codes to show once (only their HMACs are stored).
|
|
292
|
+
- `removeTotp(database, { accountId })`, `totpStatus(database, { accountId })` → `{ on, recoveryCodesLeft }`,
|
|
293
|
+
`regenerateRecoveryCodes(server, { accountId })` (the old ones stop working).
|
|
294
|
+
|
|
295
|
+
### Devices, activity, export and deletion
|
|
296
|
+
|
|
297
|
+
- `listAccountSessions(database, { accountId, token })` → devices (`userAgent`, `signedInAt`, `lastSeenAt`,
|
|
298
|
+
`secondFactor`, `current`), most recently seen first; `signIn` stores each browser's User-Agent (`userAgent`).
|
|
299
|
+
- `endAccountSession(database, { accountId, accountSessionId })` signs out one device.
|
|
300
|
+
- `listAccountActivity(database, { accountId, before?, limit = 50 })` → `{ events, next }`, newest first.
|
|
301
|
+
- `exportAccount(database, { accountId })` → everything stored about the account as JSON-ready data, never secrets.
|
|
302
|
+
- `deleteAccount(database, storage, { accountId })` deletes the picture file, then the account and everything that
|
|
303
|
+
belongs to it; its identifier is free at once and the audit log keeps `account.deleted` under the bare id.
|
|
304
|
+
|
|
305
|
+
Tests: `createTestPerson(database, identifier)` (`test-person`).
|
|
306
|
+
|
|
307
|
+
## Roles and permissions
|
|
308
|
+
|
|
309
|
+
Every application declares its permissions and roles in code, and the account system answers what an account may
|
|
310
|
+
do there.
|
|
311
|
+
|
|
312
|
+
- `syncApplication(database, { key, name, permissions, roles })` (`application-sync`): run at every deploy. Each
|
|
313
|
+
permission starts with the application's key (`platform.job.read`); a role lists permissions, and may be the
|
|
314
|
+
application's `default` (every account holds it, with no grant) or `exclusive` (while granted, only its
|
|
315
|
+
permissions count: a ban). Undeclared permissions and roles go, except a role still granted. Refusals:
|
|
316
|
+
`foreign-permission`, `unknown-permission`, `defaults` (more than one).
|
|
317
|
+
- `grantRole(database, { accountId, application, role, resource?, startsAt?, endsAt?, source?, grantedBy?, reason? })`
|
|
318
|
+
(`role-grant`) → `{ granted: true, grantId }` or a reason (`no-role`, `no-account`, `not-allowed`, `escalation`).
|
|
319
|
+
Given by someone, it needs their `account.role.assign` (`ROLE_ASSIGN_PERMISSION`, in the `account` application)
|
|
320
|
+
and every permission of the role: nobody hands out more than they hold. `revokeGrant(database, { grantId,
|
|
321
|
+
revokedBy? })` ends it now (history kept); `listGrants(database, { accountId })` lists them with `active`.
|
|
322
|
+
- `accountPermissions(database, { accountId, application, resource?, scope? })` (`account-permission`) → the set of
|
|
323
|
+
permissions now: the default role plus active grants (an active exclusive one wins), limited to `scope`, and for an
|
|
324
|
+
agent to what its owner may do right now. Built on `effectivePermissions`.
|
|
325
|
+
|
|
326
|
+
In the database (migration `0005-role`): `permission`, `role`, `role_permission`, `role_grant`. A role still
|
|
327
|
+
granted can't be deleted (`RESTRICT`); a grant outlives the account that gave it (`granted_by` becomes null).
|
|
328
|
+
|
|
329
|
+
## Rules, bans and appeals
|
|
330
|
+
|
|
331
|
+
- `syncRules(database, { application, rules })` (`rule-sync`): public rules, the application's own or global
|
|
332
|
+
(`application: null`), each with its words per language and its penalty schedule (seconds or `"permanent"` for the
|
|
333
|
+
1st, 2nd… offense; the last repeats). A changed rule gets a new version; bans keep the version they cited.
|
|
334
|
+
`listRules(database, { application })` gives the newest versions, for the public rules page.
|
|
335
|
+
- `banAccount(database, { accountId, application, rules, statement, evidence?, by? })` (`account-ban`): the length
|
|
336
|
+
comes from the rules (this offense for each, per account, rule and application; the longest wins), so equal
|
|
337
|
+
offenses get equal penalties. The ban is the application's exclusive role, granted until then or for good. `by`
|
|
338
|
+
needs `account.ban.create` (`BAN_PERMISSION`). Refusals: `not-allowed`, `no-rule`, `no-ban-role`.
|
|
339
|
+
- `appealBan(database, { banId, accountId, text })`: one appeal per ban, by the banned account.
|
|
340
|
+
`decideAppeal(database, { appealId, by, decision, reasons, endsAt? })`: `upheld`, `shortened` (to `endsAt`) or
|
|
341
|
+
`lifted`, once, by someone with `account.appeal.decide` (`APPEAL_PERMISSION`). `listBans(database, { accountId })`.
|
|
342
|
+
- The banned-contact ledger (`banned-contact`): deleting a banned account (`deleteAccount` now takes
|
|
343
|
+
`ledgerPepper`, `deriveSecret(ACCOUNT_SECRET, "banned-contact")`) keeps each verified contact's HMAC (emails
|
|
344
|
+
without `+tags`) until the ban ends. `finishSignUp` and `startContactAddition` refuse such a contact
|
|
345
|
+
(`contact-banned`); `contactBanned(database, { contact, pepper, application })` asks directly;
|
|
346
|
+
`pruneBannedContacts(database)` forgets ended ones (a daily job).
|
|
347
|
+
|
|
348
|
+
In the database (migration `0006-rule-ban`): `rule`, `ban`, `ban_rule` (a cited rule version can't be deleted),
|
|
349
|
+
`appeal` (one per ban), `banned_contact` (no link to any account).
|
|
350
|
+
|
|
164
351
|
## License
|
|
165
352
|
|
|
166
353
|
Sharadox Open Source License 0.1.0 (see `LICENSE.md`).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { AccountActivityPage } from "@sharadox/account-web-library/account-activity/type";
|
|
4
|
+
/**
|
|
5
|
+
* The account's own history from the audit log, newest first, `limit` (50 by default) at a time: pass the page's
|
|
6
|
+
* `next` as `before` for older events (UUIDv7 ids sort by time).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const { events, next } = await listAccountActivity(database, { accountId });
|
|
10
|
+
*/
|
|
11
|
+
export declare function listAccountActivity(database: Kysely<AccountDatabase>, { accountId, before, limit }: {
|
|
12
|
+
accountId: string;
|
|
13
|
+
before?: string;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}): Promise<AccountActivityPage>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-activity/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,mBAAmB,EAAE,MAAM,qDAAqD,CAAC;AAE/F;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,MAAM,EAAE,KAAU,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACxF,OAAO,CAAC,mBAAmB,CAAC,CAQ9B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The account's own history from the audit log, newest first, `limit` (50 by default) at a time: pass the page's
|
|
3
|
+
* `next` as `before` for older events (UUIDv7 ids sort by time).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const { events, next } = await listAccountActivity(database, { accountId });
|
|
7
|
+
*/
|
|
8
|
+
export async function listAccountActivity(database, { accountId, before, limit = 50 }) {
|
|
9
|
+
let query = database
|
|
10
|
+
.selectFrom("audit_event")
|
|
11
|
+
.select(["id", "at", "action", "detail"])
|
|
12
|
+
.where("account_id", "=", accountId);
|
|
13
|
+
if (before)
|
|
14
|
+
query = query.where("id", "<", before);
|
|
15
|
+
const events = await query.orderBy("id", "desc").limit(limit).execute();
|
|
16
|
+
return { events, next: events.length === limit ? events.at(-1).id : null };
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-activity/index.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAiC,EACjC,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,GAAG,EAAE,EAA0D;IAEzF,IAAI,KAAK,GAAG,QAAQ;SACjB,UAAU,CAAC,aAAa,CAAC;SACzB,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;SACxC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACvC,IAAI,MAAM;QAAE,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACxE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** One thing that happened to the account, as its owner sees it. */
|
|
2
|
+
export interface AccountActivityEvent {
|
|
3
|
+
id: string;
|
|
4
|
+
at: Date;
|
|
5
|
+
/** `account.created`, `session.signed-in`, `contact.added`… */
|
|
6
|
+
action: string;
|
|
7
|
+
/** Ids and kinds, never contact values or secrets. */
|
|
8
|
+
detail: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface AccountActivityPage {
|
|
11
|
+
events: AccountActivityEvent[];
|
|
12
|
+
/** Pass as `before` for the next page; null when there are no more. */
|
|
13
|
+
next: string | null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-activity/type.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,IAAI,CAAC;IACT,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,uEAAuE;IACvE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-activity/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
|
|
3
|
+
import type { BanRequest, BanResult, BanView } from "@sharadox/account-web-library/account-ban/type";
|
|
4
|
+
/** Banning, in the account system's own application. */
|
|
5
|
+
export declare const BAN_PERMISSION = "account.ban.create";
|
|
6
|
+
/** Deciding appeals, in the account system's own application. */
|
|
7
|
+
export declare const APPEAL_PERMISSION = "account.appeal.decide";
|
|
8
|
+
/**
|
|
9
|
+
* Bans an account in an application for breaking rules: the length comes from the rules' penalty schedules (this
|
|
10
|
+
* offense for each, counted per account, rule and application; the longest wins), so equal offenses get equal
|
|
11
|
+
* penalties. The ban is the application's exclusive role, granted until then (or for good), with a record of the
|
|
12
|
+
* rule versions broken and the statement of reasons. Recorded in the audit log.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* await banAccount(database, { accountId, application: "platform", rules: ["spam"], statement, by: moderator });
|
|
16
|
+
*/
|
|
17
|
+
export declare function banAccount(database: Kysely<AccountDatabase>, { accountId, application, rules, statement, evidence, by, now }: BanRequest): Promise<BanResult>;
|
|
18
|
+
/**
|
|
19
|
+
* The one appeal a ban may have, written by the banned account.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* await appealBan(database, { banId, accountId, text });
|
|
23
|
+
*/
|
|
24
|
+
export declare function appealBan(database: Kysely<AccountDatabase>, { banId, accountId, text, now }: {
|
|
25
|
+
banId: string;
|
|
26
|
+
accountId: string;
|
|
27
|
+
text: string;
|
|
28
|
+
now?: number;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
appealed: true;
|
|
31
|
+
appealId: string;
|
|
32
|
+
} | {
|
|
33
|
+
appealed: false;
|
|
34
|
+
reason: "no-ban" | "already-appealed";
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* A moderator's decision on an appeal, with its reasons: `upheld` keeps the ban, `shortened` moves its end to
|
|
38
|
+
* `endsAt`, `lifted` ends it now. Decided once.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* await decideAppeal(database, { appealId, by: moderator, decision: "lifted", reasons });
|
|
42
|
+
*/
|
|
43
|
+
export declare function decideAppeal(database: Kysely<AccountDatabase>, { appealId, by, decision, reasons, endsAt, now, }: {
|
|
44
|
+
appealId: string;
|
|
45
|
+
by: string;
|
|
46
|
+
decision: "upheld" | "shortened" | "lifted";
|
|
47
|
+
reasons: string;
|
|
48
|
+
endsAt?: number;
|
|
49
|
+
now?: number;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
decided: true;
|
|
52
|
+
} | {
|
|
53
|
+
decided: false;
|
|
54
|
+
reason: "not-allowed" | "no-appeal" | "already-decided";
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* An account's bans, newest first: the rules cited, the statement, the penalty, when it ends, whether it is active,
|
|
58
|
+
* and its appeal.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const bans = await listBans(database, { accountId });
|
|
62
|
+
*/
|
|
63
|
+
export declare function listBans(database: Kysely<AccountDatabase>, { accountId, now }: {
|
|
64
|
+
accountId: string;
|
|
65
|
+
now?: number;
|
|
66
|
+
}): Promise<BanView[]>;
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-ban/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gDAAgD,CAAC;AAMrG,wDAAwD;AACxD,eAAO,MAAM,cAAc,uBAAuB,CAAC;AACnD,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAKzD;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAgB,EAAE,EAAE,UAAU,GACvF,OAAO,CAAC,SAAS,CAAC,CAqFpB;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,GAAgB,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7G,OAAO,CAAC;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,kBAAkB,CAAA;CAAE,CAAC,CAkB5G;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,QAAQ,EACR,EAAE,EACF,QAAQ,EACR,OAAO,EACP,MAAM,EACN,GAAgB,GACjB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GACA,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,iBAAiB,CAAA;CAAE,CAAC,CA8B1G;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,GAAgB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,OAAO,CAAC,OAAO,EAAE,CAAC,CA8CpB"}
|