@sharadox/account-web-library 0.1.0-development.21 → 0.1.0-development.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +97 -21
  2. package/distribution/account-activity/index.d.ts +16 -0
  3. package/distribution/account-activity/index.d.ts.map +1 -0
  4. package/distribution/account-activity/index.js +18 -0
  5. package/distribution/account-activity/index.js.map +1 -0
  6. package/distribution/account-activity/type.d.ts +15 -0
  7. package/distribution/account-activity/type.d.ts.map +1 -0
  8. package/distribution/account-activity/type.js.map +1 -0
  9. package/distribution/account-database/type.d.ts +57 -4
  10. package/distribution/account-database/type.d.ts.map +1 -1
  11. package/distribution/account-deletion/index.d.ts +18 -0
  12. package/distribution/account-deletion/index.d.ts.map +1 -0
  13. package/distribution/account-deletion/index.js +28 -0
  14. package/distribution/account-deletion/index.js.map +1 -0
  15. package/distribution/account-export/index.d.ts +17 -0
  16. package/distribution/account-export/index.d.ts.map +1 -0
  17. package/distribution/account-export/index.js +87 -0
  18. package/distribution/account-export/index.js.map +1 -0
  19. package/distribution/account-export/type.d.ts +40 -0
  20. package/distribution/account-export/type.d.ts.map +1 -0
  21. package/distribution/{username-change → account-export}/type.js.map +1 -1
  22. package/distribution/account-migration/index.d.ts.map +1 -1
  23. package/distribution/account-migration/index.js +110 -0
  24. package/distribution/account-migration/index.js.map +1 -1
  25. package/distribution/account-name/index.d.ts +13 -0
  26. package/distribution/account-name/index.d.ts.map +1 -0
  27. package/distribution/account-name/index.js +22 -0
  28. package/distribution/account-name/index.js.map +1 -0
  29. package/distribution/account-name/type.d.ts +9 -0
  30. package/distribution/account-name/type.d.ts.map +1 -0
  31. package/distribution/account-name/type.js +2 -0
  32. package/distribution/account-name/type.js.map +1 -0
  33. package/distribution/account-name-change/index.d.ts +15 -0
  34. package/distribution/account-name-change/index.d.ts.map +1 -0
  35. package/distribution/account-name-change/index.js +26 -0
  36. package/distribution/account-name-change/index.js.map +1 -0
  37. package/distribution/account-name-change/type.d.ts +7 -0
  38. package/distribution/account-name-change/type.d.ts.map +1 -0
  39. package/distribution/account-name-change/type.js +2 -0
  40. package/distribution/account-name-change/type.js.map +1 -0
  41. package/distribution/account-picture-change/index.d.ts +30 -0
  42. package/distribution/account-picture-change/index.d.ts.map +1 -0
  43. package/distribution/account-picture-change/index.js +70 -0
  44. package/distribution/account-picture-change/index.js.map +1 -0
  45. package/distribution/account-picture-change/type.d.ts +11 -0
  46. package/distribution/account-picture-change/type.d.ts.map +1 -0
  47. package/distribution/account-picture-change/type.js +2 -0
  48. package/distribution/account-picture-change/type.js.map +1 -0
  49. package/distribution/account-server/index.d.ts +11 -1
  50. package/distribution/account-server/index.d.ts.map +1 -1
  51. package/distribution/account-server/index.js +12 -1
  52. package/distribution/account-server/index.js.map +1 -1
  53. package/distribution/account-server/type.d.ts +2 -0
  54. package/distribution/account-server/type.d.ts.map +1 -1
  55. package/distribution/account-session-end/index.d.ts +15 -0
  56. package/distribution/account-session-end/index.d.ts.map +1 -0
  57. package/distribution/account-session-end/index.js +21 -0
  58. package/distribution/account-session-end/index.js.map +1 -0
  59. package/distribution/account-session-list/index.d.ts +16 -0
  60. package/distribution/account-session-list/index.d.ts.map +1 -0
  61. package/distribution/account-session-list/index.js +33 -0
  62. package/distribution/account-session-list/index.js.map +1 -0
  63. package/distribution/account-session-list/type.d.ts +13 -0
  64. package/distribution/account-session-list/type.d.ts.map +1 -0
  65. package/distribution/account-session-list/type.js +2 -0
  66. package/distribution/account-session-list/type.js.map +1 -0
  67. package/distribution/account-sign-in/index.d.ts +1 -1
  68. package/distribution/account-sign-in/index.d.ts.map +1 -1
  69. package/distribution/account-sign-in/index.js +4 -2
  70. package/distribution/account-sign-in/index.js.map +1 -1
  71. package/distribution/account-sign-in/type.d.ts +2 -0
  72. package/distribution/account-sign-in/type.d.ts.map +1 -1
  73. package/distribution/audit-event/index.d.ts.map +1 -1
  74. package/distribution/audit-event/index.js +12 -1
  75. package/distribution/audit-event/index.js.map +1 -1
  76. package/distribution/audit-event/type.d.ts +1 -0
  77. package/distribution/audit-event/type.d.ts.map +1 -1
  78. package/distribution/browser-session-read/index.d.ts.map +1 -1
  79. package/distribution/browser-session-read/index.js +5 -1
  80. package/distribution/browser-session-read/index.js.map +1 -1
  81. package/distribution/browser-session-read/type.d.ts +5 -1
  82. package/distribution/browser-session-read/type.d.ts.map +1 -1
  83. package/distribution/code-request/index.js +1 -1
  84. package/distribution/code-request/type.d.ts +1 -1
  85. package/distribution/code-sending/index.d.ts +14 -0
  86. package/distribution/code-sending/index.d.ts.map +1 -0
  87. package/distribution/code-sending/index.js +65 -0
  88. package/distribution/code-sending/index.js.map +1 -0
  89. package/distribution/code-sending/type.d.ts +31 -0
  90. package/distribution/code-sending/type.d.ts.map +1 -0
  91. package/distribution/code-sending/type.js +2 -0
  92. package/distribution/code-sending/type.js.map +1 -0
  93. package/distribution/contact-addition-flow/index.d.ts +31 -0
  94. package/distribution/contact-addition-flow/index.d.ts.map +1 -0
  95. package/distribution/contact-addition-flow/index.js +85 -0
  96. package/distribution/contact-addition-flow/index.js.map +1 -0
  97. package/distribution/contact-addition-flow/type.d.ts +22 -0
  98. package/distribution/contact-addition-flow/type.d.ts.map +1 -0
  99. package/distribution/contact-addition-flow/type.js +2 -0
  100. package/distribution/contact-addition-flow/type.js.map +1 -0
  101. package/distribution/database-error/index.d.ts +1 -1
  102. package/distribution/database-error/index.js +1 -1
  103. package/distribution/email-channel/index.js +1 -1
  104. package/distribution/identifier/index.d.ts +23 -0
  105. package/distribution/identifier/index.d.ts.map +1 -0
  106. package/distribution/identifier/index.js +32 -0
  107. package/distribution/identifier/index.js.map +1 -0
  108. package/distribution/identifier/type.d.ts +10 -0
  109. package/distribution/identifier/type.d.ts.map +1 -0
  110. package/distribution/identifier/type.js +2 -0
  111. package/distribution/identifier/type.js.map +1 -0
  112. package/distribution/identifier-availability/index.d.ts +11 -0
  113. package/distribution/identifier-availability/index.d.ts.map +1 -0
  114. package/distribution/identifier-availability/index.js +21 -0
  115. package/distribution/identifier-availability/index.js.map +1 -0
  116. package/distribution/identifier-change/index.d.ts +15 -0
  117. package/distribution/identifier-change/index.d.ts.map +1 -0
  118. package/distribution/identifier-change/index.js +43 -0
  119. package/distribution/identifier-change/index.js.map +1 -0
  120. package/distribution/identifier-change/type.d.ts +7 -0
  121. package/distribution/identifier-change/type.d.ts.map +1 -0
  122. package/distribution/identifier-change/type.js +2 -0
  123. package/distribution/identifier-change/type.js.map +1 -0
  124. package/distribution/memory-picture-storage/index.d.ts +15 -0
  125. package/distribution/memory-picture-storage/index.d.ts.map +1 -0
  126. package/distribution/memory-picture-storage/index.js +16 -0
  127. package/distribution/memory-picture-storage/index.js.map +1 -0
  128. package/distribution/one-time-code/index.d.ts +2 -2
  129. package/distribution/one-time-code/index.js +3 -3
  130. package/distribution/person-account/index.d.ts +7 -3
  131. package/distribution/person-account/index.d.ts.map +1 -1
  132. package/distribution/person-account/index.js +21 -9
  133. package/distribution/person-account/index.js.map +1 -1
  134. package/distribution/person-account/type.d.ts +5 -2
  135. package/distribution/person-account/type.d.ts.map +1 -1
  136. package/distribution/picture-key/index.d.ts +8 -0
  137. package/distribution/picture-key/index.d.ts.map +1 -0
  138. package/distribution/picture-key/index.js +10 -0
  139. package/distribution/picture-key/index.js.map +1 -0
  140. package/distribution/picture-preparation/index.d.ts +18 -0
  141. package/distribution/picture-preparation/index.d.ts.map +1 -0
  142. package/distribution/picture-preparation/index.js +86 -0
  143. package/distribution/picture-preparation/index.js.map +1 -0
  144. package/distribution/picture-preparation/type.d.ts +18 -0
  145. package/distribution/picture-preparation/type.d.ts.map +1 -0
  146. package/distribution/picture-preparation/type.js +2 -0
  147. package/distribution/picture-preparation/type.js.map +1 -0
  148. package/distribution/picture-storage/type.d.ts +11 -0
  149. package/distribution/picture-storage/type.d.ts.map +1 -0
  150. package/distribution/picture-storage/type.js +2 -0
  151. package/distribution/picture-storage/type.js.map +1 -0
  152. package/distribution/recovery-code-regeneration/index.d.ts +19 -0
  153. package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
  154. package/distribution/recovery-code-regeneration/index.js +34 -0
  155. package/distribution/recovery-code-regeneration/index.js.map +1 -0
  156. package/distribution/recovery-code-store/index.d.ts +25 -0
  157. package/distribution/recovery-code-store/index.d.ts.map +1 -0
  158. package/distribution/recovery-code-store/index.js +34 -0
  159. package/distribution/recovery-code-store/index.js.map +1 -0
  160. package/distribution/second-factor-finish/index.d.ts +12 -0
  161. package/distribution/second-factor-finish/index.d.ts.map +1 -0
  162. package/distribution/second-factor-finish/index.js +78 -0
  163. package/distribution/second-factor-finish/index.js.map +1 -0
  164. package/distribution/second-factor-finish/type.d.ts +27 -0
  165. package/distribution/second-factor-finish/type.d.ts.map +1 -0
  166. package/distribution/second-factor-finish/type.js +2 -0
  167. package/distribution/second-factor-finish/type.js.map +1 -0
  168. package/distribution/secret-encryption/index.d.ts +17 -0
  169. package/distribution/secret-encryption/index.d.ts.map +1 -0
  170. package/distribution/secret-encryption/index.js +37 -0
  171. package/distribution/secret-encryption/index.js.map +1 -0
  172. package/distribution/sign-in-finish/index.d.ts +3 -3
  173. package/distribution/sign-in-finish/index.d.ts.map +1 -1
  174. package/distribution/sign-in-finish/index.js +22 -5
  175. package/distribution/sign-in-finish/index.js.map +1 -1
  176. package/distribution/sign-in-finish/type.d.ts +8 -1
  177. package/distribution/sign-in-finish/type.d.ts.map +1 -1
  178. package/distribution/sign-in-start/index.d.ts +4 -6
  179. package/distribution/sign-in-start/index.d.ts.map +1 -1
  180. package/distribution/sign-in-start/index.js +14 -58
  181. package/distribution/sign-in-start/index.js.map +1 -1
  182. package/distribution/sign-in-start/type.d.ts +7 -0
  183. package/distribution/sign-in-start/type.d.ts.map +1 -1
  184. package/distribution/sign-up-finish/index.d.ts +4 -4
  185. package/distribution/sign-up-finish/index.d.ts.map +1 -1
  186. package/distribution/sign-up-finish/index.js +11 -6
  187. package/distribution/sign-up-finish/index.js.map +1 -1
  188. package/distribution/sign-up-finish/type.d.ts +6 -1
  189. package/distribution/sign-up-finish/type.d.ts.map +1 -1
  190. package/distribution/signed-ticket/index.d.ts +1 -1
  191. package/distribution/signed-ticket/index.js +1 -1
  192. package/distribution/step-up/index.d.ts +48 -0
  193. package/distribution/step-up/index.d.ts.map +1 -0
  194. package/distribution/step-up/index.js +83 -0
  195. package/distribution/step-up/index.js.map +1 -0
  196. package/distribution/step-up/type.d.ts +15 -0
  197. package/distribution/step-up/type.d.ts.map +1 -0
  198. package/distribution/step-up/type.js +2 -0
  199. package/distribution/{username → step-up}/type.js.map +1 -1
  200. package/distribution/test-person/index.d.ts +14 -0
  201. package/distribution/test-person/index.d.ts.map +1 -0
  202. package/distribution/test-person/index.js +20 -0
  203. package/distribution/test-person/index.js.map +1 -0
  204. package/distribution/totp/type.d.ts +1 -1
  205. package/distribution/totp/type.d.ts.map +1 -1
  206. package/distribution/totp-setup/index.d.ts +50 -0
  207. package/distribution/totp-setup/index.d.ts.map +1 -0
  208. package/distribution/totp-setup/index.js +136 -0
  209. package/distribution/totp-setup/index.js.map +1 -0
  210. package/distribution/totp-setup/type.d.ts +24 -0
  211. package/distribution/totp-setup/type.d.ts.map +1 -0
  212. package/distribution/totp-setup/type.js +2 -0
  213. package/distribution/totp-setup/type.js.map +1 -0
  214. package/package.json +4 -3
  215. package/distribution/username/index.d.ts +0 -23
  216. package/distribution/username/index.d.ts.map +0 -1
  217. package/distribution/username/index.js +0 -32
  218. package/distribution/username/index.js.map +0 -1
  219. package/distribution/username/type.d.ts +0 -10
  220. package/distribution/username/type.d.ts.map +0 -1
  221. package/distribution/username-availability/index.d.ts +0 -11
  222. package/distribution/username-availability/index.d.ts.map +0 -1
  223. package/distribution/username-availability/index.js +0 -21
  224. package/distribution/username-availability/index.js.map +0 -1
  225. package/distribution/username-change/index.d.ts +0 -15
  226. package/distribution/username-change/index.d.ts.map +0 -1
  227. package/distribution/username-change/index.js +0 -39
  228. package/distribution/username-change/index.js.map +0 -1
  229. package/distribution/username-change/type.d.ts +0 -7
  230. package/distribution/username-change/type.d.ts.map +0 -1
  231. /package/distribution/{username-change → account-activity}/type.js +0 -0
  232. /package/distribution/{username → account-export}/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.** Building blocks (usernames, one-time codes, TOTP, recovery codes, email contacts,
13
- effective permissions, ban lengths) and account storage in Postgres (accounts, usernames, contacts, audit log).
14
- Sign-in codes, sessions and the OpenID Connect server come next (see `CHANGELOG.md`).
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
 
@@ -34,7 +34,8 @@ Every key is derived from it with `deriveSecret`.
34
34
  - the channel's daily spending cap.
35
35
 
36
36
  It answers `{ status: "sent", requestId, deliver }`, and you call `deliver` after answering (Next.js `after()`).
37
- A failed send is recorded in the audit log as `code.delivery-failed`, with the error but never the code.
37
+ Each send is recorded in the audit log as `code.sent`, or as `code.delivery-failed` with the error, never the
38
+ code.
38
39
  Otherwise it answers `refused` with `proof`, `contact`, `unavailable` (the cap is reached: sending pauses), or
39
40
  `rate-limit` with `retryAfterSeconds`. The answer never depends on whether an account exists.
40
41
 
@@ -42,8 +43,16 @@ Every key is derived from it with `deriveSecret`.
42
43
  - `signed-in`, with `{ accountId, token }`: set `token` as the cookie;
43
44
  - `sign-up`, with `{ ticket }`, for a contact with no account;
44
45
  - `refused`, with the code's reason or `rate-limit`.
45
- 4. `finishSignUp(server, { ticket, username, token, now? })` creates the account and signs it in. A refused
46
- username can be tried again with the same ticket, which lasts 15 minutes.
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.
47
56
 
48
57
  `DEFAULT_SIGN_IN_LIMITS` (`account-server`):
49
58
 
@@ -65,7 +74,11 @@ migrates: the tables are tracked in their own table (`account_migration`). Type
65
74
  (`account-database/type`). The database enforces the rules itself, as the last line behind the code:
66
75
 
67
76
  - ids are UUIDv7;
68
- - usernames follow the rules and are unique without regard to case;
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;
69
82
  - a verified contact belongs to one account only;
70
83
  - every person keeps at least one verified sign-in contact, checked when a change commits;
71
84
  - agents have an owner (and go with them);
@@ -78,22 +91,27 @@ dependency).
78
91
 
79
92
  Each export has its own entry point (`@sharadox/account-web-library/<name>`).
80
93
 
81
- ### `username`: `checkUsername(name)`, `usernameKey(name)`, `USERNAME_MAXIMUM_LENGTH`
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`
82
100
 
83
101
  The rules:
84
102
 
85
103
  - 1 to 50 characters;
86
104
  - A–Z, a–z and 0–9, with `-`, `_` or `.` allowed only between letters or digits, never two in a row;
87
- - shown as written, but unique without regard to case: `abc` and `aBc` are the same username.
105
+ - shown as written, but unique without regard to case: `abc` and `aBc` are the same identifier.
88
106
 
89
107
  ```ts
90
- checkUsername("Luis-Pires"); // { valid: true, username: "Luis-Pires", key: "luis-pires" }
91
- checkUsername("a--b"); // { valid: false, reason: "characters" }
108
+ checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
109
+ checkIdentifier("a--b"); // { valid: false, reason: "characters" }
92
110
  ```
93
111
 
94
112
  Store `key` under a unique index.
95
113
 
96
- ### `one-time-code`: `createOneTimeCode(length = 8)`, `hashOneTimeCode(code, { pepper, purpose })`, `matchesOneTimeCode(code, hash, { pepper, purpose })`
114
+ ### `one-time-code`: `createOneTimeCode(length = 6)`, `hashOneTimeCode(code, { pepper, purpose })`, `matchesOneTimeCode(code, hash, { pepper, purpose })`
97
115
 
98
116
  - Codes are uniform random digits.
99
117
  - Only an HMAC-SHA-256 is stored, under a pepper of at least 32 characters kept outside the database, and bound to
@@ -144,20 +162,20 @@ Codes like `7KQM-W3HD-9TXA` (about 59 bits each), from characters that can't be
144
162
  - `normalizeEmail` trims and lowercases, and throws for text that isn't an email address.
145
163
  - `emailLedgerForm` also drops `+tags`, for the banned-contact ledger.
146
164
 
147
- ### `person-account`: `createPersonAccount(database, { username, contact, now? })`
165
+ ### `person-account`: `createPersonAccount(database, { name, identifier, contact, now? })`
148
166
 
149
167
  Creates a person with the contact their one-time code just proved, stored verified, and records `account.created`.
150
- Returns `{ created: true, accountId, contactId }`, or `{ created: false, reason }` with `username-invalid`,
151
- `username-taken` or `contact-taken`.
168
+ Returns `{ created: true, accountId, contactId }`, or `{ created: false, reason }` with `name-invalid`,
169
+ `identifier-invalid`, `identifier-taken` or `contact-taken`.
152
170
 
153
- ### `username-availability`: `usernameAvailability(database, username)` → `available` | `taken` | `invalid`
171
+ ### `identifier-availability`: `identifierAvailability(database, identifier)` → `available` | `taken` | `invalid`
154
172
 
155
173
  Rate limit it: it tells whether an account exists.
156
174
 
157
- ### `username-change`: `changeUsername(database, { accountId, username })`
175
+ ### `identifier-change`: `changeIdentifier(database, { accountId, identifier })`
158
176
 
159
- Any time, and the old name is free at once; the audit log keeps `{ from, to }`. Reasons: `username-invalid`,
160
- `username-taken`, `no-account`.
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`.
161
179
 
162
180
  ### `contact-lookup`: `findAccountByContact(database, contact)` → `{ accountId, contactId, signIn }` or undefined
163
181
 
@@ -173,7 +191,7 @@ Verified contacts only, normalized first.
173
191
 
174
192
  Each is recorded in the audit log. Ask for a fresh code first (step-up) and tell the other contacts.
175
193
 
176
- ### `code-request`: `requestCode(database, { purpose, contact, accountId?, pepper, length = 8, lifetimeSeconds = 600, now? })` → `{ requestId, code, contact, expiresAt }`
194
+ ### `code-request`: `requestCode(database, { purpose, contact, accountId?, pepper, length = 6, lifetimeSeconds = 600, now? })` → `{ requestId, code, contact, expiresAt }`
177
195
 
178
196
  Starts a one-time code for `sign-in`, `contact-verification` or `step-up`.
179
197
 
@@ -200,7 +218,7 @@ points to any number of account sessions, so the selector has no limit and the c
200
218
  → `{ token, browserSessionId, accountSessionId }`. Adds the account to the browser's accounts (or starts a
201
219
  browser session). The browser gets a **new token at every sign-in**: set it as the cookie.
202
220
  - `readBrowserSession(database, { token, idleSeconds = 7 days, now? })` → `{ browserSessionId, accounts }` or
203
- undefined. `accounts` are `{ accountSessionId, accountId, username, signedInAt, secondFactorAt }`, in sign-in
221
+ undefined. `accounts` are `{ accountSessionId, accountId, identifier, name, pictureId, signedInAt, secondFactorAt }`, in sign-in
204
222
  order, without ended or idle sessions. It marks them as seen.
205
223
  - `signOut(database, { token, accountId? })` → `{ signedOut }`: one account, or all and the browser session.
206
224
  - `revokeAccountSessions(database, { accountId, actorAccountId? })` → count: signed out on every browser.
@@ -228,6 +246,64 @@ Pass the transaction of the change it describes. `detail` holds ids and kinds, n
228
246
 
229
247
  ### `database-error`: `databaseError(error)` → `{ code, constraint }` or undefined
230
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
+
231
307
  ## License
232
308
 
233
309
  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":""}
@@ -4,7 +4,10 @@ import type { ColumnType, Generated } from "kysely";
4
4
  type DefaultTime = ColumnType<Date, Date | undefined, Date>;
5
5
  /** An application the accounts sign in to (`account` itself, `platform`, `shop`…). */
6
6
  export interface ApplicationTable {
7
- id: string;
7
+ /** UUIDv7. */
8
+ id: Generated<string>;
9
+ /** Its permanent short name, the prefix of its permissions (`account`, `platform`). */
10
+ key: string;
8
11
  name: string;
9
12
  created_at: DefaultTime;
10
13
  }
@@ -12,8 +15,8 @@ export interface ApplicationTable {
12
15
  export interface AccountTable {
13
16
  id: string;
14
17
  kind: "person" | "agent";
15
- /** Shown as written; unique without regard to case. */
16
- username: string;
18
+ /** The person's or agent's name, 1 to 50 characters. */
19
+ name: string;
17
20
  /** The person who owns an agent; null for people. */
18
21
  owner_id: string | null;
19
22
  created_at: DefaultTime;
@@ -40,7 +43,8 @@ export interface AuditEventTable {
40
43
  account_id: string | null;
41
44
  /** Who did it, when not the account itself (an administrator, an agent). */
42
45
  actor_account_id: string | null;
43
- application: string | null;
46
+ /** The application it happened in; null for the account system as a whole. */
47
+ application_id: string | null;
44
48
  action: string;
45
49
  detail: ColumnType<Record<string, unknown>, Record<string, unknown> | undefined, never>;
46
50
  }
@@ -62,10 +66,53 @@ export interface CodeRequestTable {
62
66
  /** When a newer request for the same contact and purpose replaced it. */
63
67
  voided_at: Date | null;
64
68
  }
69
+ /**
70
+ * A unique name to reference something by (`@luis-pires`): one namespace for accounts now and organizations later,
71
+ * unique without regard to case. Stored without the `@`.
72
+ */
73
+ export interface IdentifierTable {
74
+ id: string;
75
+ /** Shown as written. */
76
+ value: string;
77
+ /** The account it names (exactly one owner per identifier). */
78
+ account_id: string | null;
79
+ created_at: DefaultTime;
80
+ }
81
+ /** An account's picture: the file itself is in object storage, under its id. */
82
+ export interface AccountPictureTable {
83
+ id: string;
84
+ account_id: string;
85
+ content_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp" | "image/avif" | "image/svg+xml";
86
+ byte_size: number;
87
+ width: number;
88
+ height: number;
89
+ created_at: DefaultTime;
90
+ }
91
+ /** An authenticator app (TOTP) for two-factor, its secret encrypted with a key outside the database. */
92
+ export interface TotpCredentialTable {
93
+ id: string;
94
+ account_id: string;
95
+ secret_ciphertext: string;
96
+ /** The last 30-second step accepted, so a code can't be replayed. */
97
+ last_used_step: ColumnType<string | null, number | string | null | undefined, number | string | null>;
98
+ created_at: DefaultTime;
99
+ /** When the first correct code turned it on; null while it is being set up. */
100
+ confirmed_at: Date | null;
101
+ }
102
+ /** A single-use recovery code, stored only as an HMAC. */
103
+ export interface RecoveryCodeTable {
104
+ id: string;
105
+ account_id: string;
106
+ code_hash: string;
107
+ created_at: DefaultTime;
108
+ used_at: Date | null;
109
+ }
65
110
  /** One browser (the account site's cookie holds its token; only the token's hash is stored). */
66
111
  export interface BrowserSessionTable {
67
112
  id: string;
68
113
  token_hash: string;
114
+ /** The browser's description (its User-Agent, at most 500 characters), for the list of devices. */
115
+ user_agent: ColumnType<string | null, string | null | undefined, string | null>;
69
116
  created_at: Date;
70
117
  last_seen_at: Date;
71
118
  expires_at: Date;
@@ -80,6 +127,8 @@ export interface AccountSessionTable {
80
127
  expires_at: Date;
81
128
  /** When two-factor was last passed in this session; null without it. */
82
129
  second_factor_at: Date | null;
130
+ /** When a fresh code last confirmed it is really them, for sensitive changes (`step-up`). */
131
+ step_up_at: ColumnType<Date | null, Date | null | undefined, Date | null>;
83
132
  }
84
133
  /** The tables `migrateAccount` creates, for typing a Kysely instance. */
85
134
  export interface AccountDatabase {
@@ -90,6 +139,10 @@ export interface AccountDatabase {
90
139
  code_request: CodeRequestTable;
91
140
  browser_session: BrowserSessionTable;
92
141
  account_session: AccountSessionTable;
142
+ identifier: IdentifierTable;
143
+ account_picture: AccountPictureTable;
144
+ totp_credential: TotpCredentialTable;
145
+ recovery_code: RecoveryCodeTable;
93
146
  }
94
147
  /** The account tables and the protection tables (rate limits, spending caps, used challenges) the server needs. */
95
148
  export type AccountServerDatabase = AccountDatabase & ProtectionDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-database/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEpD,wDAAwD;AACxD,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC;AAE5D,sFAAsF;AACtF,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,WAAW,CAAC;CACzB;AAED,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;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,eAAe;IAC9B,WAAW,EAAE,gBAAgB,CAAC;IAC9B,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,YAAY,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;CAClC;AAED,mHAAmH;AACnH,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,18 @@
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. Ask for a fresh code first
8
+ * (step-up).
9
+ *
10
+ * @example
11
+ * await deleteAccount(database, storage, { accountId }); // { deleted: true }
12
+ */
13
+ export declare function deleteAccount(database: Kysely<AccountDatabase>, storage: PictureStorage, { accountId }: {
14
+ accountId: string;
15
+ }): Promise<{
16
+ deleted: boolean;
17
+ }>;
18
+ //# 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;AAG3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAEzF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,OAAO,EAAE,cAAc,EACvB,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACnC,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAa/B"}
@@ -0,0 +1,28 @@
1
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
2
+ import { pictureKey } from "@sharadox/account-web-library/picture-key";
3
+ /**
4
+ * Deletes an account for good: its picture file, then the account with everything that belongs to it (identifier,
5
+ * contacts, sessions, two-factor, agents), in one transaction. Its identifier is free at once. The audit log keeps
6
+ * `account.deleted` and earlier events under the bare id, with no personal data. Ask for a fresh code first
7
+ * (step-up).
8
+ *
9
+ * @example
10
+ * await deleteAccount(database, storage, { accountId }); // { deleted: true }
11
+ */
12
+ export async function deleteAccount(database, storage, { accountId }) {
13
+ const picture = await database
14
+ .selectFrom("account_picture")
15
+ .select("id")
16
+ .where("account_id", "=", accountId)
17
+ .executeTakeFirst();
18
+ if (picture)
19
+ await storage.remove(pictureKey(picture.id));
20
+ return database.transaction().execute(async (transaction) => {
21
+ const deleted = await transaction.deleteFrom("account").where("id", "=", accountId).executeTakeFirst();
22
+ if (deleted.numDeletedRows === 0n)
23
+ return { deleted: false };
24
+ await recordAuditEvent(transaction, { accountId, action: "account.deleted" });
25
+ return { deleted: true };
26
+ });
27
+ }
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-deletion/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AAGvE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAiC,EACjC,OAAuB,EACvB,EAAE,SAAS,EAAyB;IAEpC,MAAM,OAAO,GAAG,MAAM,QAAQ;SAC3B,UAAU,CAAC,iBAAiB,CAAC;SAC7B,MAAM,CAAC,IAAI,CAAC;SACZ,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC;SACnC,gBAAgB,EAAE,CAAC;IACtB,IAAI,OAAO;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC1D,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACvG,IAAI,OAAO,CAAC,cAAc,KAAK,EAAE;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC7D,MAAM,gBAAgB,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { AccountExport } from "@sharadox/account-web-library/account-export/type";
4
+ /**
5
+ * Everything stored about an account, ready to download as JSON: the account, its identifier, contacts, picture,
6
+ * two-factor status, devices and full history. Never secrets: no token, code or key hashes, no TOTP secret.
7
+ * Undefined for an unknown account.
8
+ *
9
+ * @example
10
+ * const data = await exportAccount(database, { accountId });
11
+ * return Response.json(data, { headers: { "content-disposition": 'attachment; filename="account.json"' } });
12
+ */
13
+ export declare function exportAccount(database: Kysely<AccountDatabase>, { accountId, now }: {
14
+ accountId: string;
15
+ now?: number;
16
+ }): Promise<AccountExport | undefined>;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-export/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,aAAa,EAAE,MAAM,mDAAmD,CAAC;AAKvF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,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,aAAa,GAAG,SAAS,CAAC,CAyEpC"}
@@ -0,0 +1,87 @@
1
+ const iso = (date) => date.toISOString();
2
+ const isoOrNull = (date) => (date ? date.toISOString() : null);
3
+ /**
4
+ * Everything stored about an account, ready to download as JSON: the account, its identifier, contacts, picture,
5
+ * two-factor status, devices and full history. Never secrets: no token, code or key hashes, no TOTP secret.
6
+ * Undefined for an unknown account.
7
+ *
8
+ * @example
9
+ * const data = await exportAccount(database, { accountId });
10
+ * return Response.json(data, { headers: { "content-disposition": 'attachment; filename="account.json"' } });
11
+ */
12
+ export async function exportAccount(database, { accountId, now = Date.now() }) {
13
+ const account = await database
14
+ .selectFrom("account")
15
+ .innerJoin("identifier", "identifier.account_id", "account.id")
16
+ .select([
17
+ "account.id",
18
+ "account.kind",
19
+ "account.name",
20
+ "identifier.value as identifier",
21
+ "account.created_at",
22
+ "account.last_active_at",
23
+ ])
24
+ .where("account.id", "=", accountId)
25
+ .executeTakeFirst();
26
+ if (!account)
27
+ return undefined;
28
+ const [contacts, picture, totp, recovery, sessions, activity] = await Promise.all([
29
+ database.selectFrom("contact").selectAll().where("account_id", "=", accountId).orderBy("id").execute(),
30
+ database.selectFrom("account_picture").selectAll().where("account_id", "=", accountId).executeTakeFirst(),
31
+ database
32
+ .selectFrom("totp_credential")
33
+ .select("id")
34
+ .where("account_id", "=", accountId)
35
+ .where("confirmed_at", "is not", null)
36
+ .executeTakeFirst(),
37
+ database
38
+ .selectFrom("recovery_code")
39
+ .select("id")
40
+ .where("account_id", "=", accountId)
41
+ .where("used_at", "is", null)
42
+ .execute(),
43
+ database
44
+ .selectFrom("account_session")
45
+ .innerJoin("browser_session", "browser_session.id", "account_session.browser_session_id")
46
+ .select(["browser_session.user_agent", "account_session.created_at", "account_session.last_seen_at"])
47
+ .where("account_session.account_id", "=", accountId)
48
+ .orderBy("account_session.id")
49
+ .execute(),
50
+ database
51
+ .selectFrom("audit_event")
52
+ .select(["id", "at", "action", "detail"])
53
+ .where("account_id", "=", accountId)
54
+ .orderBy("id", "desc")
55
+ .execute(),
56
+ ]);
57
+ return {
58
+ exportedAt: iso(new Date(now)),
59
+ account: {
60
+ id: account.id,
61
+ kind: account.kind,
62
+ name: account.name,
63
+ identifier: account.identifier,
64
+ createdAt: iso(account.created_at),
65
+ lastActiveAt: iso(account.last_active_at),
66
+ },
67
+ contacts: contacts.map((contact) => ({
68
+ id: contact.id,
69
+ kind: contact.kind,
70
+ value: contact.value,
71
+ verifiedAt: isoOrNull(contact.verified_at),
72
+ signIn: contact.sign_in,
73
+ createdAt: iso(contact.created_at),
74
+ })),
75
+ picture: picture
76
+ ? { id: picture.id, width: picture.width, height: picture.height, createdAt: iso(picture.created_at) }
77
+ : null,
78
+ secondFactor: { authenticatorApp: totp !== undefined, recoveryCodesLeft: recovery.length },
79
+ sessions: sessions.map((session) => ({
80
+ userAgent: session.user_agent,
81
+ signedInAt: iso(session.created_at),
82
+ lastSeenAt: iso(session.last_seen_at),
83
+ })),
84
+ activity: activity.map((event) => ({ ...event, at: iso(event.at) })),
85
+ };
86
+ }
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.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account-activity/type";
2
+ /** Everything stored about an account, for its owner to download (GDPR Art. 15 and 20). Dates are ISO 8601 text. */
3
+ export interface AccountExport {
4
+ exportedAt: string;
5
+ account: {
6
+ id: string;
7
+ kind: string;
8
+ name: string;
9
+ identifier: string;
10
+ createdAt: string;
11
+ lastActiveAt: string;
12
+ };
13
+ contacts: {
14
+ id: string;
15
+ kind: string;
16
+ value: string;
17
+ verifiedAt: string | null;
18
+ signIn: boolean;
19
+ createdAt: string;
20
+ }[];
21
+ picture: {
22
+ id: string;
23
+ width: number;
24
+ height: number;
25
+ createdAt: string;
26
+ } | null;
27
+ secondFactor: {
28
+ authenticatorApp: boolean;
29
+ recoveryCodesLeft: number;
30
+ };
31
+ sessions: {
32
+ userAgent: string | null;
33
+ signedInAt: string;
34
+ lastSeenAt: string;
35
+ }[];
36
+ activity: (Omit<AccountActivityEvent, "at"> & {
37
+ at: string;
38
+ })[];
39
+ }
40
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-export/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAEhG,oHAAoH;AACpH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IACjH,QAAQ,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;IACJ,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACjF,YAAY,EAAE;QAAE,gBAAgB,EAAE,OAAO,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACjF,QAAQ,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;CACjE"}
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/username-change/type.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-export/type.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-migration/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAE/E,iHAAiH;AACjH,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAE3D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,EA+HxC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAElF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-migration/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAE/E,iHAAiH;AACjH,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAE3D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,EA6OxC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAElF"}