@sharadox/account-web-library 0.1.0-development.9 → 0.1.0-new-browser-notice.32

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 (342) hide show
  1. package/README.md +207 -17
  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-ban/index.d.ts +67 -0
  10. package/distribution/account-ban/index.d.ts.map +1 -0
  11. package/distribution/account-ban/index.js +233 -0
  12. package/distribution/account-ban/index.js.map +1 -0
  13. package/distribution/account-ban/type.d.ts +44 -0
  14. package/distribution/account-ban/type.d.ts.map +1 -0
  15. package/distribution/{username-change → account-ban}/type.js.map +1 -1
  16. package/distribution/account-database/type.d.ts +195 -4
  17. package/distribution/account-database/type.d.ts.map +1 -1
  18. package/distribution/account-deletion/index.d.ts +21 -0
  19. package/distribution/account-deletion/index.d.ts.map +1 -0
  20. package/distribution/account-deletion/index.js +66 -0
  21. package/distribution/account-deletion/index.js.map +1 -0
  22. package/distribution/account-export/index.d.ts +17 -0
  23. package/distribution/account-export/index.d.ts.map +1 -0
  24. package/distribution/account-export/index.js +87 -0
  25. package/distribution/account-export/index.js.map +1 -0
  26. package/distribution/account-export/type.d.ts +40 -0
  27. package/distribution/account-export/type.d.ts.map +1 -0
  28. package/distribution/account-export/type.js +2 -0
  29. package/distribution/account-export/type.js.map +1 -0
  30. package/distribution/account-inactivity/index.d.ts +25 -0
  31. package/distribution/account-inactivity/index.d.ts.map +1 -0
  32. package/distribution/account-inactivity/index.js +100 -0
  33. package/distribution/account-inactivity/index.js.map +1 -0
  34. package/distribution/account-migration/index.d.ts.map +1 -1
  35. package/distribution/account-migration/index.js +254 -0
  36. package/distribution/account-migration/index.js.map +1 -1
  37. package/distribution/account-name/index.d.ts +13 -0
  38. package/distribution/account-name/index.d.ts.map +1 -0
  39. package/distribution/account-name/index.js +22 -0
  40. package/distribution/account-name/index.js.map +1 -0
  41. package/distribution/account-name/type.d.ts +9 -0
  42. package/distribution/account-name/type.d.ts.map +1 -0
  43. package/distribution/account-name/type.js +2 -0
  44. package/distribution/account-name/type.js.map +1 -0
  45. package/distribution/account-name-change/index.d.ts +15 -0
  46. package/distribution/account-name-change/index.d.ts.map +1 -0
  47. package/distribution/account-name-change/index.js +26 -0
  48. package/distribution/account-name-change/index.js.map +1 -0
  49. package/distribution/account-name-change/type.d.ts +7 -0
  50. package/distribution/account-name-change/type.d.ts.map +1 -0
  51. package/distribution/account-name-change/type.js +2 -0
  52. package/distribution/account-name-change/type.js.map +1 -0
  53. package/distribution/account-notice/index.d.ts +15 -0
  54. package/distribution/account-notice/index.d.ts.map +1 -0
  55. package/distribution/account-notice/index.js +41 -0
  56. package/distribution/account-notice/index.js.map +1 -0
  57. package/distribution/account-permission/index.d.ts +14 -0
  58. package/distribution/account-permission/index.d.ts.map +1 -0
  59. package/distribution/account-permission/index.js +91 -0
  60. package/distribution/account-permission/index.js.map +1 -0
  61. package/distribution/account-permission/type.d.ts +12 -0
  62. package/distribution/account-permission/type.d.ts.map +1 -0
  63. package/distribution/account-permission/type.js +2 -0
  64. package/distribution/account-permission/type.js.map +1 -0
  65. package/distribution/account-picture-change/index.d.ts +30 -0
  66. package/distribution/account-picture-change/index.d.ts.map +1 -0
  67. package/distribution/account-picture-change/index.js +70 -0
  68. package/distribution/account-picture-change/index.js.map +1 -0
  69. package/distribution/account-picture-change/type.d.ts +11 -0
  70. package/distribution/account-picture-change/type.d.ts.map +1 -0
  71. package/distribution/account-picture-change/type.js +2 -0
  72. package/distribution/account-picture-change/type.js.map +1 -0
  73. package/distribution/account-server/index.d.ts +25 -0
  74. package/distribution/account-server/index.d.ts.map +1 -0
  75. package/distribution/account-server/index.js +34 -0
  76. package/distribution/account-server/index.js.map +1 -0
  77. package/distribution/account-server/type.d.ts +30 -0
  78. package/distribution/account-server/type.d.ts.map +1 -0
  79. package/distribution/account-server/type.js +2 -0
  80. package/distribution/account-server/type.js.map +1 -0
  81. package/distribution/account-session-end/index.d.ts +15 -0
  82. package/distribution/account-session-end/index.d.ts.map +1 -0
  83. package/distribution/account-session-end/index.js +21 -0
  84. package/distribution/account-session-end/index.js.map +1 -0
  85. package/distribution/account-session-list/index.d.ts +16 -0
  86. package/distribution/account-session-list/index.d.ts.map +1 -0
  87. package/distribution/account-session-list/index.js +33 -0
  88. package/distribution/account-session-list/index.js.map +1 -0
  89. package/distribution/account-session-list/type.d.ts +13 -0
  90. package/distribution/account-session-list/type.d.ts.map +1 -0
  91. package/distribution/account-session-list/type.js +2 -0
  92. package/distribution/account-session-list/type.js.map +1 -0
  93. package/distribution/account-session-revocation/index.d.ts +14 -0
  94. package/distribution/account-session-revocation/index.d.ts.map +1 -0
  95. package/distribution/account-session-revocation/index.js +25 -0
  96. package/distribution/account-session-revocation/index.js.map +1 -0
  97. package/distribution/account-sign-in/index.d.ts +15 -0
  98. package/distribution/account-sign-in/index.d.ts.map +1 -0
  99. package/distribution/account-sign-in/index.js +78 -0
  100. package/distribution/account-sign-in/index.js.map +1 -0
  101. package/distribution/account-sign-in/type.d.ts +24 -0
  102. package/distribution/account-sign-in/type.d.ts.map +1 -0
  103. package/distribution/account-sign-in/type.js +2 -0
  104. package/distribution/account-sign-in/type.js.map +1 -0
  105. package/distribution/account-sign-out/index.d.ts +16 -0
  106. package/distribution/account-sign-out/index.d.ts.map +1 -0
  107. package/distribution/account-sign-out/index.js +34 -0
  108. package/distribution/account-sign-out/index.js.map +1 -0
  109. package/distribution/application-sync/index.d.ts +14 -0
  110. package/distribution/application-sync/index.d.ts.map +1 -0
  111. package/distribution/application-sync/index.js +96 -0
  112. package/distribution/application-sync/index.js.map +1 -0
  113. package/distribution/application-sync/type.d.ts +29 -0
  114. package/distribution/application-sync/type.d.ts.map +1 -0
  115. package/distribution/application-sync/type.js +2 -0
  116. package/distribution/application-sync/type.js.map +1 -0
  117. package/distribution/audit-event/index.d.ts.map +1 -1
  118. package/distribution/audit-event/index.js +12 -1
  119. package/distribution/audit-event/index.js.map +1 -1
  120. package/distribution/audit-event/type.d.ts +1 -0
  121. package/distribution/audit-event/type.d.ts.map +1 -1
  122. package/distribution/banned-contact/index.d.ts +34 -0
  123. package/distribution/banned-contact/index.d.ts.map +1 -0
  124. package/distribution/banned-contact/index.js +52 -0
  125. package/distribution/banned-contact/index.js.map +1 -0
  126. package/distribution/browser-session-read/index.d.ts +17 -0
  127. package/distribution/browser-session-read/index.d.ts.map +1 -0
  128. package/distribution/browser-session-read/index.js +52 -0
  129. package/distribution/browser-session-read/index.js.map +1 -0
  130. package/distribution/browser-session-read/type.d.ts +18 -0
  131. package/distribution/browser-session-read/type.d.ts.map +1 -0
  132. package/distribution/browser-session-read/type.js +2 -0
  133. package/distribution/browser-session-read/type.js.map +1 -0
  134. package/distribution/challenge-issue/index.d.ts +13 -0
  135. package/distribution/challenge-issue/index.d.ts.map +1 -0
  136. package/distribution/challenge-issue/index.js +18 -0
  137. package/distribution/challenge-issue/index.js.map +1 -0
  138. package/distribution/code-request/index.js +1 -1
  139. package/distribution/code-request/type.d.ts +1 -1
  140. package/distribution/code-sending/index.d.ts +14 -0
  141. package/distribution/code-sending/index.d.ts.map +1 -0
  142. package/distribution/code-sending/index.js +65 -0
  143. package/distribution/code-sending/index.js.map +1 -0
  144. package/distribution/code-sending/type.d.ts +31 -0
  145. package/distribution/code-sending/type.d.ts.map +1 -0
  146. package/distribution/code-sending/type.js +2 -0
  147. package/distribution/code-sending/type.js.map +1 -0
  148. package/distribution/contact-addition-flow/index.d.ts +32 -0
  149. package/distribution/contact-addition-flow/index.d.ts.map +1 -0
  150. package/distribution/contact-addition-flow/index.js +96 -0
  151. package/distribution/contact-addition-flow/index.js.map +1 -0
  152. package/distribution/contact-addition-flow/type.d.ts +25 -0
  153. package/distribution/contact-addition-flow/type.d.ts.map +1 -0
  154. package/distribution/contact-addition-flow/type.js +2 -0
  155. package/distribution/contact-addition-flow/type.js.map +1 -0
  156. package/distribution/contact-channel/type.d.ts +49 -0
  157. package/distribution/contact-channel/type.d.ts.map +1 -0
  158. package/distribution/contact-channel/type.js +2 -0
  159. package/distribution/contact-channel/type.js.map +1 -0
  160. package/distribution/database-error/index.d.ts +1 -1
  161. package/distribution/database-error/index.js +1 -1
  162. package/distribution/email-channel/index.d.ts +13 -0
  163. package/distribution/email-channel/index.d.ts.map +1 -0
  164. package/distribution/email-channel/index.js +185 -0
  165. package/distribution/email-channel/index.js.map +1 -0
  166. package/distribution/email-channel/type.d.ts +17 -0
  167. package/distribution/email-channel/type.d.ts.map +1 -0
  168. package/distribution/email-channel/type.js +2 -0
  169. package/distribution/email-channel/type.js.map +1 -0
  170. package/distribution/identifier/index.d.ts +23 -0
  171. package/distribution/identifier/index.d.ts.map +1 -0
  172. package/distribution/identifier/index.js +32 -0
  173. package/distribution/identifier/index.js.map +1 -0
  174. package/distribution/identifier/type.d.ts +10 -0
  175. package/distribution/identifier/type.d.ts.map +1 -0
  176. package/distribution/identifier/type.js +2 -0
  177. package/distribution/identifier/type.js.map +1 -0
  178. package/distribution/identifier-availability/index.d.ts +11 -0
  179. package/distribution/identifier-availability/index.d.ts.map +1 -0
  180. package/distribution/identifier-availability/index.js +21 -0
  181. package/distribution/identifier-availability/index.js.map +1 -0
  182. package/distribution/identifier-change/index.d.ts +15 -0
  183. package/distribution/identifier-change/index.d.ts.map +1 -0
  184. package/distribution/identifier-change/index.js +43 -0
  185. package/distribution/identifier-change/index.js.map +1 -0
  186. package/distribution/identifier-change/type.d.ts +7 -0
  187. package/distribution/identifier-change/type.d.ts.map +1 -0
  188. package/distribution/identifier-change/type.js +2 -0
  189. package/distribution/identifier-change/type.js.map +1 -0
  190. package/distribution/memory-picture-storage/index.d.ts +15 -0
  191. package/distribution/memory-picture-storage/index.d.ts.map +1 -0
  192. package/distribution/memory-picture-storage/index.js +16 -0
  193. package/distribution/memory-picture-storage/index.js.map +1 -0
  194. package/distribution/one-time-code/index.d.ts +2 -2
  195. package/distribution/one-time-code/index.js +3 -3
  196. package/distribution/person-account/index.d.ts +7 -3
  197. package/distribution/person-account/index.d.ts.map +1 -1
  198. package/distribution/person-account/index.js +29 -9
  199. package/distribution/person-account/index.js.map +1 -1
  200. package/distribution/person-account/type.d.ts +7 -2
  201. package/distribution/person-account/type.d.ts.map +1 -1
  202. package/distribution/picture-key/index.d.ts +8 -0
  203. package/distribution/picture-key/index.d.ts.map +1 -0
  204. package/distribution/picture-key/index.js +10 -0
  205. package/distribution/picture-key/index.js.map +1 -0
  206. package/distribution/picture-preparation/index.d.ts +18 -0
  207. package/distribution/picture-preparation/index.d.ts.map +1 -0
  208. package/distribution/picture-preparation/index.js +86 -0
  209. package/distribution/picture-preparation/index.js.map +1 -0
  210. package/distribution/picture-preparation/type.d.ts +18 -0
  211. package/distribution/picture-preparation/type.d.ts.map +1 -0
  212. package/distribution/picture-preparation/type.js +2 -0
  213. package/distribution/picture-preparation/type.js.map +1 -0
  214. package/distribution/picture-storage/type.d.ts +11 -0
  215. package/distribution/picture-storage/type.d.ts.map +1 -0
  216. package/distribution/picture-storage/type.js +2 -0
  217. package/distribution/picture-storage/type.js.map +1 -0
  218. package/distribution/recovery-code-regeneration/index.d.ts +19 -0
  219. package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
  220. package/distribution/recovery-code-regeneration/index.js +34 -0
  221. package/distribution/recovery-code-regeneration/index.js.map +1 -0
  222. package/distribution/recovery-code-store/index.d.ts +25 -0
  223. package/distribution/recovery-code-store/index.d.ts.map +1 -0
  224. package/distribution/recovery-code-store/index.js +34 -0
  225. package/distribution/recovery-code-store/index.js.map +1 -0
  226. package/distribution/role-grant/index.d.ts +38 -0
  227. package/distribution/role-grant/index.d.ts.map +1 -0
  228. package/distribution/role-grant/index.js +142 -0
  229. package/distribution/role-grant/index.js.map +1 -0
  230. package/distribution/role-grant/type.d.ts +40 -0
  231. package/distribution/role-grant/type.d.ts.map +1 -0
  232. package/distribution/role-grant/type.js +2 -0
  233. package/distribution/role-grant/type.js.map +1 -0
  234. package/distribution/rule-sync/index.d.ts +28 -0
  235. package/distribution/rule-sync/index.d.ts.map +1 -0
  236. package/distribution/rule-sync/index.js +80 -0
  237. package/distribution/rule-sync/index.js.map +1 -0
  238. package/distribution/rule-sync/type.d.ts +17 -0
  239. package/distribution/rule-sync/type.d.ts.map +1 -0
  240. package/distribution/rule-sync/type.js +2 -0
  241. package/distribution/rule-sync/type.js.map +1 -0
  242. package/distribution/second-factor-finish/index.d.ts +13 -0
  243. package/distribution/second-factor-finish/index.d.ts.map +1 -0
  244. package/distribution/second-factor-finish/index.js +90 -0
  245. package/distribution/second-factor-finish/index.js.map +1 -0
  246. package/distribution/second-factor-finish/type.d.ts +30 -0
  247. package/distribution/second-factor-finish/type.d.ts.map +1 -0
  248. package/distribution/second-factor-finish/type.js +2 -0
  249. package/distribution/second-factor-finish/type.js.map +1 -0
  250. package/distribution/secret-derivation/index.d.ts +10 -0
  251. package/distribution/secret-derivation/index.d.ts.map +1 -0
  252. package/distribution/secret-derivation/index.js +15 -0
  253. package/distribution/secret-derivation/index.js.map +1 -0
  254. package/distribution/secret-encryption/index.d.ts +17 -0
  255. package/distribution/secret-encryption/index.d.ts.map +1 -0
  256. package/distribution/secret-encryption/index.js +37 -0
  257. package/distribution/secret-encryption/index.js.map +1 -0
  258. package/distribution/session-prune/index.d.ts +17 -0
  259. package/distribution/session-prune/index.d.ts.map +1 -0
  260. package/distribution/session-prune/index.js +30 -0
  261. package/distribution/session-prune/index.js.map +1 -0
  262. package/distribution/session-token/index.d.ts +19 -0
  263. package/distribution/session-token/index.d.ts.map +1 -0
  264. package/distribution/session-token/index.js +22 -0
  265. package/distribution/session-token/index.js.map +1 -0
  266. package/distribution/sign-in-finish/index.d.ts +13 -0
  267. package/distribution/sign-in-finish/index.d.ts.map +1 -0
  268. package/distribution/sign-in-finish/index.js +69 -0
  269. package/distribution/sign-in-finish/index.js.map +1 -0
  270. package/distribution/sign-in-finish/type.d.ts +44 -0
  271. package/distribution/sign-in-finish/type.d.ts.map +1 -0
  272. package/distribution/sign-in-finish/type.js +2 -0
  273. package/distribution/sign-in-finish/type.js.map +1 -0
  274. package/distribution/sign-in-start/index.d.ts +17 -0
  275. package/distribution/sign-in-start/index.d.ts.map +1 -0
  276. package/distribution/sign-in-start/index.js +45 -0
  277. package/distribution/sign-in-start/index.js.map +1 -0
  278. package/distribution/sign-in-start/type.d.ts +34 -0
  279. package/distribution/sign-in-start/type.d.ts.map +1 -0
  280. package/distribution/sign-in-start/type.js +2 -0
  281. package/distribution/sign-in-start/type.js.map +1 -0
  282. package/distribution/sign-up-finish/index.d.ts +13 -0
  283. package/distribution/sign-up-finish/index.d.ts.map +1 -0
  284. package/distribution/sign-up-finish/index.js +38 -0
  285. package/distribution/sign-up-finish/index.js.map +1 -0
  286. package/distribution/sign-up-finish/type.d.ts +28 -0
  287. package/distribution/sign-up-finish/type.d.ts.map +1 -0
  288. package/distribution/sign-up-finish/type.js +2 -0
  289. package/distribution/sign-up-finish/type.js.map +1 -0
  290. package/distribution/signed-ticket/index.d.ts +19 -0
  291. package/distribution/signed-ticket/index.d.ts.map +1 -0
  292. package/distribution/signed-ticket/index.js +35 -0
  293. package/distribution/signed-ticket/index.js.map +1 -0
  294. package/distribution/signed-ticket/type.d.ts +16 -0
  295. package/distribution/signed-ticket/type.d.ts.map +1 -0
  296. package/distribution/signed-ticket/type.js +2 -0
  297. package/distribution/signed-ticket/type.js.map +1 -0
  298. package/distribution/step-up/index.d.ts +48 -0
  299. package/distribution/step-up/index.d.ts.map +1 -0
  300. package/distribution/step-up/index.js +83 -0
  301. package/distribution/step-up/index.js.map +1 -0
  302. package/distribution/step-up/type.d.ts +15 -0
  303. package/distribution/step-up/type.d.ts.map +1 -0
  304. package/distribution/step-up/type.js +2 -0
  305. package/distribution/{username → step-up}/type.js.map +1 -1
  306. package/distribution/test-person/index.d.ts +14 -0
  307. package/distribution/test-person/index.d.ts.map +1 -0
  308. package/distribution/test-person/index.js +20 -0
  309. package/distribution/test-person/index.js.map +1 -0
  310. package/distribution/test-server/index.d.ts +10 -0
  311. package/distribution/test-server/index.d.ts.map +1 -0
  312. package/distribution/test-server/index.js +16 -0
  313. package/distribution/test-server/index.js.map +1 -0
  314. package/distribution/totp/type.d.ts +1 -1
  315. package/distribution/totp/type.d.ts.map +1 -1
  316. package/distribution/totp-setup/index.d.ts +50 -0
  317. package/distribution/totp-setup/index.d.ts.map +1 -0
  318. package/distribution/totp-setup/index.js +136 -0
  319. package/distribution/totp-setup/index.js.map +1 -0
  320. package/distribution/totp-setup/type.d.ts +24 -0
  321. package/distribution/totp-setup/type.d.ts.map +1 -0
  322. package/distribution/totp-setup/type.js +2 -0
  323. package/distribution/totp-setup/type.js.map +1 -0
  324. package/package.json +7 -3
  325. package/distribution/username/index.d.ts +0 -23
  326. package/distribution/username/index.d.ts.map +0 -1
  327. package/distribution/username/index.js +0 -32
  328. package/distribution/username/index.js.map +0 -1
  329. package/distribution/username/type.d.ts +0 -10
  330. package/distribution/username/type.d.ts.map +0 -1
  331. package/distribution/username-availability/index.d.ts +0 -11
  332. package/distribution/username-availability/index.d.ts.map +0 -1
  333. package/distribution/username-availability/index.js +0 -21
  334. package/distribution/username-availability/index.js.map +0 -1
  335. package/distribution/username-change/index.d.ts +0 -15
  336. package/distribution/username-change/index.d.ts.map +0 -1
  337. package/distribution/username-change/index.js +0 -39
  338. package/distribution/username-change/index.js.map +0 -1
  339. package/distribution/username-change/type.d.ts +0 -7
  340. package/distribution/username-change/type.d.ts.map +0 -1
  341. /package/distribution/{username-change → account-activity}/type.js +0 -0
  342. /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.** 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
 
@@ -19,6 +19,57 @@ 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
+ A sign-in on a browser new to the account system answers with `notify`: call it after answering, to tell every
54
+ email (`new-sign-in`).
55
+
56
+ Pass `token` (the cookie) to `startSignIn` too: a contact of an account already signed in on that browser gets
57
+ `{ status: "signed-in", accountId }` and no code. Codes are 6 digits, shown in emails as `123 456`. Identifiers are
58
+ always stored and passed without the `@` that the interface shows in front of them.
59
+
60
+ `DEFAULT_SIGN_IN_LIMITS` (`account-server`):
61
+
62
+ | Limit | Default |
63
+ | ------------------------- | --------------------------------- |
64
+ | `perContact` | 3 codes, then 1 every 5 minutes |
65
+ | `perAddress` | 10, then 1 a minute |
66
+ | `global` | 200, then 1 a second |
67
+ | `verificationsPerAddress` | 20 typed codes, then 1 every 30 s |
68
+ | `dailySendsPerChannel` | 2,000 |
69
+ | `difficulty` | 14 bits |
70
+
71
+ `createTicket` and `readTicket` (`signed-ticket`) carry signed, short-lived data between steps.
72
+
22
73
  ## Storage
23
74
 
24
75
  Postgres through Kysely (`@sharadox/database-web-library`). Run `migrateAccount(database)` when the application
@@ -26,7 +77,11 @@ migrates: the tables are tracked in their own table (`account_migration`). Type
26
77
  (`account-database/type`). The database enforces the rules itself, as the last line behind the code:
27
78
 
28
79
  - ids are UUIDv7;
29
- - usernames follow the rules and are unique without regard to case;
80
+ - every row's id is a UUIDv7, and foreign keys cascade updates and deletes (an application with audit events
81
+ can't be deleted);
82
+ - identifiers live in one table for everything that has one (accounts now, organizations later), follow the rules,
83
+ and are unique without regard to case; every account keeps exactly one;
84
+ - names have 1 to 50 characters, trimmed, with no control characters;
30
85
  - a verified contact belongs to one account only;
31
86
  - every person keeps at least one verified sign-in contact, checked when a change commits;
32
87
  - agents have an owner (and go with them);
@@ -39,22 +94,27 @@ dependency).
39
94
 
40
95
  Each export has its own entry point (`@sharadox/account-web-library/<name>`).
41
96
 
42
- ### `username`: `checkUsername(name)`, `usernameKey(name)`, `USERNAME_MAXIMUM_LENGTH`
97
+ ### `account-name`: `checkAccountName(name)`, `ACCOUNT_NAME_MAXIMUM_LENGTH`
98
+
99
+ The name an account shows: any letters and symbols, 1 to 50 characters once trimmed and with runs of spaces made
100
+ single, and no control characters. `checkAccountName(" Luís Pires ")` → `{ valid: true, name: "Luís Pires" }`.
101
+
102
+ ### `identifier`: `checkIdentifier(name)`, `identifierKey(name)`, `IDENTIFIER_MAXIMUM_LENGTH`
43
103
 
44
104
  The rules:
45
105
 
46
106
  - 1 to 50 characters;
47
107
  - 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 username.
108
+ - shown as written, but unique without regard to case: `abc` and `aBc` are the same identifier.
49
109
 
50
110
  ```ts
51
- checkUsername("Luis-Pires"); // { valid: true, username: "Luis-Pires", key: "luis-pires" }
52
- checkUsername("a--b"); // { valid: false, reason: "characters" }
111
+ checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
112
+ checkIdentifier("a--b"); // { valid: false, reason: "characters" }
53
113
  ```
54
114
 
55
115
  Store `key` under a unique index.
56
116
 
57
- ### `one-time-code`: `createOneTimeCode(length = 8)`, `hashOneTimeCode(code, { pepper, purpose })`, `matchesOneTimeCode(code, hash, { pepper, purpose })`
117
+ ### `one-time-code`: `createOneTimeCode(length = 6)`, `hashOneTimeCode(code, { pepper, purpose })`, `matchesOneTimeCode(code, hash, { pepper, purpose })`
58
118
 
59
119
  - Codes are uniform random digits.
60
120
  - Only an HMAC-SHA-256 is stored, under a pepper of at least 32 characters kept outside the database, and bound to
@@ -105,20 +165,20 @@ Codes like `7KQM-W3HD-9TXA` (about 59 bits each), from characters that can't be
105
165
  - `normalizeEmail` trims and lowercases, and throws for text that isn't an email address.
106
166
  - `emailLedgerForm` also drops `+tags`, for the banned-contact ledger.
107
167
 
108
- ### `person-account`: `createPersonAccount(database, { username, contact, now? })`
168
+ ### `person-account`: `createPersonAccount(database, { name, identifier, contact, now? })`
109
169
 
110
170
  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 `username-invalid`,
112
- `username-taken` or `contact-taken`.
171
+ Returns `{ created: true, accountId, contactId }`, or `{ created: false, reason }` with `name-invalid`,
172
+ `identifier-invalid`, `identifier-taken` or `contact-taken`.
113
173
 
114
- ### `username-availability`: `usernameAvailability(database, username)` → `available` | `taken` | `invalid`
174
+ ### `identifier-availability`: `identifierAvailability(database, identifier)` → `available` | `taken` | `invalid`
115
175
 
116
176
  Rate limit it: it tells whether an account exists.
117
177
 
118
- ### `username-change`: `changeUsername(database, { accountId, username })`
178
+ ### `identifier-change`: `changeIdentifier(database, { accountId, identifier })`
119
179
 
120
- Any time, and the old name is free at once; the audit log keeps `{ from, to }`. Reasons: `username-invalid`,
121
- `username-taken`, `no-account`.
180
+ Any time, and the old name is free at once; the audit log keeps `{ from, to }`. Reasons: `identifier-invalid`,
181
+ `identifier-taken`, `no-account`.
122
182
 
123
183
  ### `contact-lookup`: `findAccountByContact(database, contact)` → `{ accountId, contactId, signIn }` or undefined
124
184
 
@@ -134,7 +194,7 @@ Verified contacts only, normalized first.
134
194
 
135
195
  Each is recorded in the audit log. Ask for a fresh code first (step-up) and tell the other contacts.
136
196
 
137
- ### `code-request`: `requestCode(database, { purpose, contact, accountId?, pepper, length = 8, lifetimeSeconds = 600, now? })` → `{ requestId, code, contact, expiresAt }`
197
+ ### `code-request`: `requestCode(database, { purpose, contact, accountId?, pepper, length = 6, lifetimeSeconds = 600, now? })` → `{ requestId, code, contact, expiresAt }`
138
198
 
139
199
  Starts a one-time code for `sign-in`, `contact-verification` or `step-up`.
140
200
 
@@ -151,6 +211,34 @@ pass the limit; after the last attempt even the right code is refused.
151
211
 
152
212
  ### `code-request-prune`: `pruneCodeRequests(database, { before })` → deleted count
153
213
 
214
+ ### Sessions and the account selector
215
+
216
+ A browser holds one cookie with an opaque token (only its SHA-256 is stored). On the server, that browser session
217
+ points to any number of account sessions, so the selector has no limit and the cookie never grows. Use a
218
+ `__Host-` cookie: HttpOnly, Secure, SameSite=Lax, path `/`.
219
+
220
+ - `signIn(database, { accountId, token?, secondFactor?, accountSessionSeconds = 30 days, browserSessionSeconds = 400 days, now? })`
221
+ → `{ token, browserSessionId, accountSessionId }`. Adds the account to the browser's accounts (or starts a
222
+ browser session). The browser gets a **new token at every sign-in**: set it as the cookie.
223
+ - `readBrowserSession(database, { token, idleSeconds = 7 days, now? })` → `{ browserSessionId, accounts }` or
224
+ undefined. `accounts` are `{ accountSessionId, accountId, identifier, name, pictureId, signedInAt, secondFactorAt }`, in sign-in
225
+ order, without ended or idle sessions. It marks them as seen.
226
+ - `signOut(database, { token, accountId? })` → `{ signedOut }`: one account, or all and the browser session.
227
+ - `revokeAccountSessions(database, { accountId, actorAccountId? })` → count: signed out on every browser.
228
+ - `pruneSessions(database, { idleSeconds?, now? })` → `{ accountSessions, browserSessions }`, for a daily job.
229
+ - `createSessionToken()`, `hashSessionToken(token)` (`session-token`).
230
+
231
+ ### `email-channel`: `createEmailChannel({ sender, from, design, logos?, now? })` → `ContactChannel`
232
+
233
+ Sends codes by email through email-web-library's sender, in the shared email layout.
234
+
235
+ - English, or European Portuguese for any `pt` reader.
236
+ - The code is in the body only, never in the subject (lock screens show subjects).
237
+ - No link to click: nothing for a phishing email to imitate.
238
+
239
+ A `ContactChannel` (`contact-channel/type`) is `{ kind, send({ contact, code, purpose, language, expiresAt }) }`:
240
+ phone, WhatsApp, Messenger and Instagram channels will have the same shape.
241
+
154
242
  ### `contact-kind`: `normalizeContact({ kind, value })`, `CONTACT_KINDS`
155
243
 
156
244
  `email` in this version; unknown kinds and invalid values throw.
@@ -161,6 +249,108 @@ Pass the transaction of the change it describes. `detail` holds ids and kinds, n
161
249
 
162
250
  ### `database-error`: `databaseError(error)` → `{ code, constraint }` or undefined
163
251
 
252
+ ## Managing an account
253
+
254
+ Everything a person can do with their own account. Ask for a fresh code first (step-up) before changing contacts,
255
+ two-factor or recovery codes, and before deleting the account.
256
+
257
+ ### `step-up`: `startStepUp(server, { accountId, contactId, address, language })`, `finishStepUp(server, { accountId, requestId, code, token })`, `hasFreshStepUp(database, { accountId, token })`
258
+
259
+ A code to one of the account's own verified contacts. Once it comes back, this browser's session of the account is
260
+ confirmed for 10 minutes (`STEP_UP_SECONDS`): check `hasFreshStepUp` before every sensitive change.
261
+
262
+ ### `code-sending`: `sendCode(server, { purpose, contact, channel, accountId?, address, language })`
263
+
264
+ What every flow above uses to send a code: rate limits per contact, per address group and for everyone, the
265
+ channel's daily cap, then `deliver` to call after answering, recorded as `code.sent` or `code.delivery-failed`.
266
+
267
+ ### `account-name-change`: `changeAccountName(database, { accountId, name })`
268
+
269
+ Reasons: `name-invalid`, `no-account`. The audit log records that it changed, not the names.
270
+
271
+ ### Pictures: `picture-preparation`, `account-picture-change`, `picture-key`, `picture-storage/type`, `memory-picture-storage`
272
+
273
+ - `preparePicture(bytes)` takes JPEG, PNG, GIF, WebP, AVIF or SVG, up to 5 MB and 4096 pixels, and gives WebP of at
274
+ most 1024 pixels on the longer side. Metadata (a photo's location) is dropped and its rotation applied; GIFs stay
275
+ animated; SVGs are drawn into an image, so nothing in them can run. It refuses (`reason`) `size`, `type`,
276
+ `dimensions`, `suspicious` (far more bytes than the picture needs: something is hidden in it) and `unsafe` (an SVG
277
+ that loads anything from outside itself, or declares entities).
278
+ - `setAccountPicture(database, storage, { accountId, bytes })` → `{ changed: true, pictureId }`: the new file is
279
+ stored first, then the old one is deleted. `removeAccountPicture(database, storage, { accountId })`.
280
+ - Files live in object storage under `pictureKey(pictureId)` (`account-picture/<id>.webp`). The application gives a
281
+ `PictureStorage` (`put(key, bytes, contentType)`, `remove(key)`); tests use `createMemoryPictureStorage()`.
282
+
283
+ ### Contacts: `contact-addition-flow`
284
+
285
+ `startContactAddition(server, { accountId, contact, address, language })` adds the contact unverified and sends it a
286
+ code (asking again sends a new one); `finishContactAddition(server, { accountId, requestId, code })` verifies it.
287
+ Removing one is `removeContact` (the last sign-in contact can't go).
288
+
289
+ ### Two-factor: `totp-setup`, `recovery-code-regeneration`, `second-factor-finish`, `secret-encryption`
290
+
291
+ - `startTotpSetup(server, { accountId, issuer })` → `{ status: "started", uri, secret }`: show `uri` as a QR code and
292
+ `secret` for typing in. The secret is stored encrypted (AES-256-GCM, key derived from `ACCOUNT_SECRET`).
293
+ - `confirmTotpSetup(server, { accountId, code })` turns it on with the app's first right code and returns 10 recovery
294
+ codes to show once (only their HMACs are stored).
295
+ - `removeTotp(database, { accountId })`, `totpStatus(database, { accountId })` → `{ on, recoveryCodesLeft }`,
296
+ `regenerateRecoveryCodes(server, { accountId })` (the old ones stop working).
297
+
298
+ ### Devices, activity, export and deletion
299
+
300
+ - `listAccountSessions(database, { accountId, token })` → devices (`userAgent`, `signedInAt`, `lastSeenAt`,
301
+ `secondFactor`, `current`), most recently seen first; `signIn` stores each browser's User-Agent (`userAgent`).
302
+ - `endAccountSession(database, { accountId, accountSessionId })` signs out one device.
303
+ - `listAccountActivity(database, { accountId, before?, limit = 50 })` → `{ events, next }`, newest first.
304
+ - `exportAccount(database, { accountId })` → everything stored about the account as JSON-ready data, never secrets.
305
+ - `deleteAccount(database, storage, { accountId })` deletes the picture file, then the account and everything that
306
+ belongs to it; its identifier is free at once and the audit log keeps `account.deleted` under the bare id.
307
+
308
+ Tests: `createTestPerson(database, identifier)` (`test-person`).
309
+
310
+ ## Roles and permissions
311
+
312
+ Every application declares its permissions and roles in code, and the account system answers what an account may
313
+ do there.
314
+
315
+ - `syncApplication(database, { key, name, permissions, roles })` (`application-sync`): run at every deploy. Each
316
+ permission starts with the application's key (`platform.job.read`); a role lists permissions, and may be the
317
+ application's `default` (every account holds it, with no grant) or `exclusive` (while granted, only its
318
+ permissions count: a ban). Undeclared permissions and roles go, except a role still granted. Refusals:
319
+ `foreign-permission`, `unknown-permission`, `defaults` (more than one).
320
+ - `grantRole(database, { accountId, application, role, resource?, startsAt?, endsAt?, source?, grantedBy?, reason? })`
321
+ (`role-grant`) → `{ granted: true, grantId }` or a reason (`no-role`, `no-account`, `not-allowed`, `escalation`).
322
+ Given by someone, it needs their `account.role.assign` (`ROLE_ASSIGN_PERMISSION`, in the `account` application)
323
+ and every permission of the role: nobody hands out more than they hold. `revokeGrant(database, { grantId,
324
+ revokedBy? })` ends it now (history kept); `listGrants(database, { accountId })` lists them with `active`.
325
+ - `accountPermissions(database, { accountId, application, resource?, scope? })` (`account-permission`) → the set of
326
+ permissions now: the default role plus active grants (an active exclusive one wins), limited to `scope`, and for an
327
+ agent to what its owner may do right now. Built on `effectivePermissions`.
328
+
329
+ In the database (migration `0005-role`): `permission`, `role`, `role_permission`, `role_grant`. A role still
330
+ granted can't be deleted (`RESTRICT`); a grant outlives the account that gave it (`granted_by` becomes null).
331
+
332
+ ## Rules, bans and appeals
333
+
334
+ - `syncRules(database, { application, rules })` (`rule-sync`): public rules, the application's own or global
335
+ (`application: null`), each with its words per language and its penalty schedule (seconds or `"permanent"` for the
336
+ 1st, 2nd… offense; the last repeats). A changed rule gets a new version; bans keep the version they cited.
337
+ `listRules(database, { application })` gives the newest versions, for the public rules page.
338
+ - `banAccount(database, { accountId, application, rules, statement, evidence?, by? })` (`account-ban`): the length
339
+ comes from the rules (this offense for each, per account, rule and application; the longest wins), so equal
340
+ offenses get equal penalties. The ban is the application's exclusive role, granted until then or for good. `by`
341
+ needs `account.ban.create` (`BAN_PERMISSION`). Refusals: `not-allowed`, `no-rule`, `no-ban-role`.
342
+ - `appealBan(database, { banId, accountId, text })`: one appeal per ban, by the banned account.
343
+ `decideAppeal(database, { appealId, by, decision, reasons, endsAt? })`: `upheld`, `shortened` (to `endsAt`) or
344
+ `lifted`, once, by someone with `account.appeal.decide` (`APPEAL_PERMISSION`). `listBans(database, { accountId })`.
345
+ - The banned-contact ledger (`banned-contact`): deleting a banned account (`deleteAccount` now takes
346
+ `ledgerPepper`, `deriveSecret(ACCOUNT_SECRET, "banned-contact")`) keeps each verified contact's HMAC (emails
347
+ without `+tags`) until the ban ends. `finishSignUp` and `startContactAddition` refuse such a contact
348
+ (`contact-banned`); `contactBanned(database, { contact, pepper, application })` asks directly;
349
+ `pruneBannedContacts(database)` forgets ended ones (a daily job).
350
+
351
+ In the database (migration `0006-rule-ban`): `rule`, `ban`, `ban_rule` (a cited rule version can't be deleted),
352
+ `appeal` (one per ban), `banned_contact` (no link to any account).
353
+
164
354
  ## License
165
355
 
166
356
  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"}