@sharadox/account-web-library 0.1.0-development.3 → 0.1.0-development.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/README.md +270 -8
  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/account-ban/type.js +2 -0
  16. package/distribution/account-ban/type.js.map +1 -0
  17. package/distribution/account-database/type.d.ts +264 -0
  18. package/distribution/account-database/type.d.ts.map +1 -0
  19. package/distribution/account-database/type.js +2 -0
  20. package/distribution/account-database/type.js.map +1 -0
  21. package/distribution/account-deletion/index.d.ts +21 -0
  22. package/distribution/account-deletion/index.d.ts.map +1 -0
  23. package/distribution/account-deletion/index.js +66 -0
  24. package/distribution/account-deletion/index.js.map +1 -0
  25. package/distribution/account-export/index.d.ts +17 -0
  26. package/distribution/account-export/index.d.ts.map +1 -0
  27. package/distribution/account-export/index.js +87 -0
  28. package/distribution/account-export/index.js.map +1 -0
  29. package/distribution/account-export/type.d.ts +40 -0
  30. package/distribution/account-export/type.d.ts.map +1 -0
  31. package/distribution/account-export/type.js +2 -0
  32. package/distribution/account-export/type.js.map +1 -0
  33. package/distribution/account-inactivity/index.d.ts +25 -0
  34. package/distribution/account-inactivity/index.d.ts.map +1 -0
  35. package/distribution/account-inactivity/index.js +100 -0
  36. package/distribution/account-inactivity/index.js.map +1 -0
  37. package/distribution/account-migration/index.d.ts +18 -0
  38. package/distribution/account-migration/index.d.ts.map +1 -0
  39. package/distribution/account-migration/index.js +376 -0
  40. package/distribution/account-migration/index.js.map +1 -0
  41. package/distribution/account-name/index.d.ts +13 -0
  42. package/distribution/account-name/index.d.ts.map +1 -0
  43. package/distribution/account-name/index.js +22 -0
  44. package/distribution/account-name/index.js.map +1 -0
  45. package/distribution/account-name/type.d.ts +9 -0
  46. package/distribution/account-name/type.d.ts.map +1 -0
  47. package/distribution/account-name/type.js +2 -0
  48. package/distribution/account-name/type.js.map +1 -0
  49. package/distribution/account-name-change/index.d.ts +15 -0
  50. package/distribution/account-name-change/index.d.ts.map +1 -0
  51. package/distribution/account-name-change/index.js +26 -0
  52. package/distribution/account-name-change/index.js.map +1 -0
  53. package/distribution/account-name-change/type.d.ts +7 -0
  54. package/distribution/account-name-change/type.d.ts.map +1 -0
  55. package/distribution/account-name-change/type.js +2 -0
  56. package/distribution/account-name-change/type.js.map +1 -0
  57. package/distribution/account-notice/index.d.ts +15 -0
  58. package/distribution/account-notice/index.d.ts.map +1 -0
  59. package/distribution/account-notice/index.js +41 -0
  60. package/distribution/account-notice/index.js.map +1 -0
  61. package/distribution/account-permission/index.d.ts +14 -0
  62. package/distribution/account-permission/index.d.ts.map +1 -0
  63. package/distribution/account-permission/index.js +91 -0
  64. package/distribution/account-permission/index.js.map +1 -0
  65. package/distribution/account-permission/type.d.ts +12 -0
  66. package/distribution/account-permission/type.d.ts.map +1 -0
  67. package/distribution/account-permission/type.js +2 -0
  68. package/distribution/account-permission/type.js.map +1 -0
  69. package/distribution/account-picture-change/index.d.ts +30 -0
  70. package/distribution/account-picture-change/index.d.ts.map +1 -0
  71. package/distribution/account-picture-change/index.js +70 -0
  72. package/distribution/account-picture-change/index.js.map +1 -0
  73. package/distribution/account-picture-change/type.d.ts +11 -0
  74. package/distribution/account-picture-change/type.d.ts.map +1 -0
  75. package/distribution/account-picture-change/type.js +2 -0
  76. package/distribution/account-picture-change/type.js.map +1 -0
  77. package/distribution/account-server/index.d.ts +25 -0
  78. package/distribution/account-server/index.d.ts.map +1 -0
  79. package/distribution/account-server/index.js +34 -0
  80. package/distribution/account-server/index.js.map +1 -0
  81. package/distribution/account-server/type.d.ts +30 -0
  82. package/distribution/account-server/type.d.ts.map +1 -0
  83. package/distribution/account-server/type.js +2 -0
  84. package/distribution/account-server/type.js.map +1 -0
  85. package/distribution/account-session-end/index.d.ts +15 -0
  86. package/distribution/account-session-end/index.d.ts.map +1 -0
  87. package/distribution/account-session-end/index.js +21 -0
  88. package/distribution/account-session-end/index.js.map +1 -0
  89. package/distribution/account-session-list/index.d.ts +16 -0
  90. package/distribution/account-session-list/index.d.ts.map +1 -0
  91. package/distribution/account-session-list/index.js +33 -0
  92. package/distribution/account-session-list/index.js.map +1 -0
  93. package/distribution/account-session-list/type.d.ts +13 -0
  94. package/distribution/account-session-list/type.d.ts.map +1 -0
  95. package/distribution/account-session-list/type.js +2 -0
  96. package/distribution/account-session-list/type.js.map +1 -0
  97. package/distribution/account-session-revocation/index.d.ts +14 -0
  98. package/distribution/account-session-revocation/index.d.ts.map +1 -0
  99. package/distribution/account-session-revocation/index.js +25 -0
  100. package/distribution/account-session-revocation/index.js.map +1 -0
  101. package/distribution/account-sign-in/index.d.ts +15 -0
  102. package/distribution/account-sign-in/index.d.ts.map +1 -0
  103. package/distribution/account-sign-in/index.js +78 -0
  104. package/distribution/account-sign-in/index.js.map +1 -0
  105. package/distribution/account-sign-in/type.d.ts +24 -0
  106. package/distribution/account-sign-in/type.d.ts.map +1 -0
  107. package/distribution/account-sign-in/type.js +2 -0
  108. package/distribution/account-sign-in/type.js.map +1 -0
  109. package/distribution/account-sign-out/index.d.ts +16 -0
  110. package/distribution/account-sign-out/index.d.ts.map +1 -0
  111. package/distribution/account-sign-out/index.js +34 -0
  112. package/distribution/account-sign-out/index.js.map +1 -0
  113. package/distribution/application-sync/index.d.ts +14 -0
  114. package/distribution/application-sync/index.d.ts.map +1 -0
  115. package/distribution/application-sync/index.js +96 -0
  116. package/distribution/application-sync/index.js.map +1 -0
  117. package/distribution/application-sync/type.d.ts +29 -0
  118. package/distribution/application-sync/type.d.ts.map +1 -0
  119. package/distribution/application-sync/type.js +2 -0
  120. package/distribution/application-sync/type.js.map +1 -0
  121. package/distribution/audit-event/index.d.ts +12 -0
  122. package/distribution/audit-event/index.d.ts.map +1 -0
  123. package/distribution/audit-event/index.js +36 -0
  124. package/distribution/audit-event/index.js.map +1 -0
  125. package/distribution/audit-event/type.d.ts +16 -0
  126. package/distribution/audit-event/type.d.ts.map +1 -0
  127. package/distribution/audit-event/type.js +2 -0
  128. package/distribution/audit-event/type.js.map +1 -0
  129. package/distribution/banned-contact/index.d.ts +34 -0
  130. package/distribution/banned-contact/index.d.ts.map +1 -0
  131. package/distribution/banned-contact/index.js +52 -0
  132. package/distribution/banned-contact/index.js.map +1 -0
  133. package/distribution/browser-session-read/index.d.ts +17 -0
  134. package/distribution/browser-session-read/index.d.ts.map +1 -0
  135. package/distribution/browser-session-read/index.js +52 -0
  136. package/distribution/browser-session-read/index.js.map +1 -0
  137. package/distribution/browser-session-read/type.d.ts +18 -0
  138. package/distribution/browser-session-read/type.d.ts.map +1 -0
  139. package/distribution/browser-session-read/type.js +2 -0
  140. package/distribution/browser-session-read/type.js.map +1 -0
  141. package/distribution/challenge-issue/index.d.ts +13 -0
  142. package/distribution/challenge-issue/index.d.ts.map +1 -0
  143. package/distribution/challenge-issue/index.js +18 -0
  144. package/distribution/challenge-issue/index.js.map +1 -0
  145. package/distribution/code-request/index.d.ts +16 -0
  146. package/distribution/code-request/index.d.ts.map +1 -0
  147. package/distribution/code-request/index.js +52 -0
  148. package/distribution/code-request/index.js.map +1 -0
  149. package/distribution/code-request/type.d.ts +25 -0
  150. package/distribution/code-request/type.d.ts.map +1 -0
  151. package/distribution/code-request/type.js +2 -0
  152. package/distribution/code-request/type.js.map +1 -0
  153. package/distribution/code-request-prune/index.d.ts +13 -0
  154. package/distribution/code-request-prune/index.d.ts.map +1 -0
  155. package/distribution/code-request-prune/index.js +12 -0
  156. package/distribution/code-request-prune/index.js.map +1 -0
  157. package/distribution/code-sending/index.d.ts +14 -0
  158. package/distribution/code-sending/index.d.ts.map +1 -0
  159. package/distribution/code-sending/index.js +65 -0
  160. package/distribution/code-sending/index.js.map +1 -0
  161. package/distribution/code-sending/type.d.ts +31 -0
  162. package/distribution/code-sending/type.d.ts.map +1 -0
  163. package/distribution/code-sending/type.js +2 -0
  164. package/distribution/code-sending/type.js.map +1 -0
  165. package/distribution/code-verification/index.d.ts +14 -0
  166. package/distribution/code-verification/index.d.ts.map +1 -0
  167. package/distribution/code-verification/index.js +43 -0
  168. package/distribution/code-verification/index.js.map +1 -0
  169. package/distribution/code-verification/type.d.ts +22 -0
  170. package/distribution/code-verification/type.d.ts.map +1 -0
  171. package/distribution/code-verification/type.js +2 -0
  172. package/distribution/code-verification/type.js.map +1 -0
  173. package/distribution/contact-addition/index.d.ts +13 -0
  174. package/distribution/contact-addition/index.d.ts.map +1 -0
  175. package/distribution/contact-addition/index.js +48 -0
  176. package/distribution/contact-addition/index.js.map +1 -0
  177. package/distribution/contact-addition/type.d.ts +15 -0
  178. package/distribution/contact-addition/type.d.ts.map +1 -0
  179. package/distribution/contact-addition/type.js +2 -0
  180. package/distribution/contact-addition/type.js.map +1 -0
  181. package/distribution/contact-addition-flow/index.d.ts +32 -0
  182. package/distribution/contact-addition-flow/index.d.ts.map +1 -0
  183. package/distribution/contact-addition-flow/index.js +96 -0
  184. package/distribution/contact-addition-flow/index.js.map +1 -0
  185. package/distribution/contact-addition-flow/type.d.ts +25 -0
  186. package/distribution/contact-addition-flow/type.d.ts.map +1 -0
  187. package/distribution/contact-addition-flow/type.js +2 -0
  188. package/distribution/contact-addition-flow/type.js.map +1 -0
  189. package/distribution/contact-channel/type.d.ts +49 -0
  190. package/distribution/contact-channel/type.d.ts.map +1 -0
  191. package/distribution/contact-channel/type.js +2 -0
  192. package/distribution/contact-channel/type.js.map +1 -0
  193. package/distribution/contact-kind/index.d.ts +12 -0
  194. package/distribution/contact-kind/index.d.ts.map +1 -0
  195. package/distribution/contact-kind/index.js +18 -0
  196. package/distribution/contact-kind/index.js.map +1 -0
  197. package/distribution/contact-kind/type.d.ts +6 -0
  198. package/distribution/contact-kind/type.d.ts.map +1 -0
  199. package/distribution/contact-kind/type.js +2 -0
  200. package/distribution/contact-kind/type.js.map +1 -0
  201. package/distribution/contact-lookup/index.d.ts +16 -0
  202. package/distribution/contact-lookup/index.d.ts.map +1 -0
  203. package/distribution/contact-lookup/index.js +20 -0
  204. package/distribution/contact-lookup/index.js.map +1 -0
  205. package/distribution/contact-removal/index.d.ts +19 -0
  206. package/distribution/contact-removal/index.d.ts.map +1 -0
  207. package/distribution/contact-removal/index.js +35 -0
  208. package/distribution/contact-removal/index.js.map +1 -0
  209. package/distribution/contact-verification/index.d.ts +20 -0
  210. package/distribution/contact-verification/index.d.ts.map +1 -0
  211. package/distribution/contact-verification/index.js +37 -0
  212. package/distribution/contact-verification/index.js.map +1 -0
  213. package/distribution/database-error/index.d.ts +12 -0
  214. package/distribution/database-error/index.d.ts.map +1 -0
  215. package/distribution/database-error/index.js +14 -0
  216. package/distribution/database-error/index.js.map +1 -0
  217. package/distribution/email-channel/index.d.ts +13 -0
  218. package/distribution/email-channel/index.d.ts.map +1 -0
  219. package/distribution/email-channel/index.js +185 -0
  220. package/distribution/email-channel/index.js.map +1 -0
  221. package/distribution/email-channel/type.d.ts +17 -0
  222. package/distribution/email-channel/type.d.ts.map +1 -0
  223. package/distribution/email-channel/type.js +2 -0
  224. package/distribution/email-channel/type.js.map +1 -0
  225. package/distribution/identifier/index.d.ts +23 -0
  226. package/distribution/identifier/index.d.ts.map +1 -0
  227. package/distribution/identifier/index.js +32 -0
  228. package/distribution/identifier/index.js.map +1 -0
  229. package/distribution/identifier/type.d.ts +10 -0
  230. package/distribution/identifier/type.d.ts.map +1 -0
  231. package/distribution/identifier/type.js +2 -0
  232. package/distribution/identifier/type.js.map +1 -0
  233. package/distribution/identifier-availability/index.d.ts +11 -0
  234. package/distribution/identifier-availability/index.d.ts.map +1 -0
  235. package/distribution/identifier-availability/index.js +21 -0
  236. package/distribution/identifier-availability/index.js.map +1 -0
  237. package/distribution/identifier-change/index.d.ts +15 -0
  238. package/distribution/identifier-change/index.d.ts.map +1 -0
  239. package/distribution/identifier-change/index.js +43 -0
  240. package/distribution/identifier-change/index.js.map +1 -0
  241. package/distribution/identifier-change/type.d.ts +7 -0
  242. package/distribution/identifier-change/type.d.ts.map +1 -0
  243. package/distribution/identifier-change/type.js +2 -0
  244. package/distribution/identifier-change/type.js.map +1 -0
  245. package/distribution/memory-picture-storage/index.d.ts +15 -0
  246. package/distribution/memory-picture-storage/index.d.ts.map +1 -0
  247. package/distribution/memory-picture-storage/index.js +16 -0
  248. package/distribution/memory-picture-storage/index.js.map +1 -0
  249. package/distribution/one-time-code/index.d.ts +2 -2
  250. package/distribution/one-time-code/index.js +3 -3
  251. package/distribution/person-account/index.d.ts +18 -0
  252. package/distribution/person-account/index.d.ts.map +1 -0
  253. package/distribution/person-account/index.js +65 -0
  254. package/distribution/person-account/index.js.map +1 -0
  255. package/distribution/person-account/type.d.ts +22 -0
  256. package/distribution/person-account/type.d.ts.map +1 -0
  257. package/distribution/person-account/type.js +2 -0
  258. package/distribution/person-account/type.js.map +1 -0
  259. package/distribution/picture-key/index.d.ts +8 -0
  260. package/distribution/picture-key/index.d.ts.map +1 -0
  261. package/distribution/picture-key/index.js +10 -0
  262. package/distribution/picture-key/index.js.map +1 -0
  263. package/distribution/picture-preparation/index.d.ts +18 -0
  264. package/distribution/picture-preparation/index.d.ts.map +1 -0
  265. package/distribution/picture-preparation/index.js +86 -0
  266. package/distribution/picture-preparation/index.js.map +1 -0
  267. package/distribution/picture-preparation/type.d.ts +18 -0
  268. package/distribution/picture-preparation/type.d.ts.map +1 -0
  269. package/distribution/picture-preparation/type.js +2 -0
  270. package/distribution/picture-preparation/type.js.map +1 -0
  271. package/distribution/picture-storage/type.d.ts +11 -0
  272. package/distribution/picture-storage/type.d.ts.map +1 -0
  273. package/distribution/picture-storage/type.js +2 -0
  274. package/distribution/picture-storage/type.js.map +1 -0
  275. package/distribution/recovery-code-regeneration/index.d.ts +19 -0
  276. package/distribution/recovery-code-regeneration/index.d.ts.map +1 -0
  277. package/distribution/recovery-code-regeneration/index.js +34 -0
  278. package/distribution/recovery-code-regeneration/index.js.map +1 -0
  279. package/distribution/recovery-code-store/index.d.ts +25 -0
  280. package/distribution/recovery-code-store/index.d.ts.map +1 -0
  281. package/distribution/recovery-code-store/index.js +34 -0
  282. package/distribution/recovery-code-store/index.js.map +1 -0
  283. package/distribution/role-grant/index.d.ts +38 -0
  284. package/distribution/role-grant/index.d.ts.map +1 -0
  285. package/distribution/role-grant/index.js +142 -0
  286. package/distribution/role-grant/index.js.map +1 -0
  287. package/distribution/role-grant/type.d.ts +40 -0
  288. package/distribution/role-grant/type.d.ts.map +1 -0
  289. package/distribution/role-grant/type.js +2 -0
  290. package/distribution/role-grant/type.js.map +1 -0
  291. package/distribution/rule-sync/index.d.ts +28 -0
  292. package/distribution/rule-sync/index.d.ts.map +1 -0
  293. package/distribution/rule-sync/index.js +80 -0
  294. package/distribution/rule-sync/index.js.map +1 -0
  295. package/distribution/rule-sync/type.d.ts +17 -0
  296. package/distribution/rule-sync/type.d.ts.map +1 -0
  297. package/distribution/rule-sync/type.js +2 -0
  298. package/distribution/rule-sync/type.js.map +1 -0
  299. package/distribution/second-factor-finish/index.d.ts +13 -0
  300. package/distribution/second-factor-finish/index.d.ts.map +1 -0
  301. package/distribution/second-factor-finish/index.js +90 -0
  302. package/distribution/second-factor-finish/index.js.map +1 -0
  303. package/distribution/second-factor-finish/type.d.ts +30 -0
  304. package/distribution/second-factor-finish/type.d.ts.map +1 -0
  305. package/distribution/second-factor-finish/type.js +2 -0
  306. package/distribution/second-factor-finish/type.js.map +1 -0
  307. package/distribution/secret-derivation/index.d.ts +10 -0
  308. package/distribution/secret-derivation/index.d.ts.map +1 -0
  309. package/distribution/secret-derivation/index.js +15 -0
  310. package/distribution/secret-derivation/index.js.map +1 -0
  311. package/distribution/secret-encryption/index.d.ts +17 -0
  312. package/distribution/secret-encryption/index.d.ts.map +1 -0
  313. package/distribution/secret-encryption/index.js +37 -0
  314. package/distribution/secret-encryption/index.js.map +1 -0
  315. package/distribution/session-prune/index.d.ts +17 -0
  316. package/distribution/session-prune/index.d.ts.map +1 -0
  317. package/distribution/session-prune/index.js +30 -0
  318. package/distribution/session-prune/index.js.map +1 -0
  319. package/distribution/session-token/index.d.ts +19 -0
  320. package/distribution/session-token/index.d.ts.map +1 -0
  321. package/distribution/session-token/index.js +22 -0
  322. package/distribution/session-token/index.js.map +1 -0
  323. package/distribution/sign-in-finish/index.d.ts +13 -0
  324. package/distribution/sign-in-finish/index.d.ts.map +1 -0
  325. package/distribution/sign-in-finish/index.js +69 -0
  326. package/distribution/sign-in-finish/index.js.map +1 -0
  327. package/distribution/sign-in-finish/type.d.ts +44 -0
  328. package/distribution/sign-in-finish/type.d.ts.map +1 -0
  329. package/distribution/sign-in-finish/type.js +2 -0
  330. package/distribution/sign-in-finish/type.js.map +1 -0
  331. package/distribution/sign-in-start/index.d.ts +17 -0
  332. package/distribution/sign-in-start/index.d.ts.map +1 -0
  333. package/distribution/sign-in-start/index.js +45 -0
  334. package/distribution/sign-in-start/index.js.map +1 -0
  335. package/distribution/sign-in-start/type.d.ts +34 -0
  336. package/distribution/sign-in-start/type.d.ts.map +1 -0
  337. package/distribution/sign-in-start/type.js +2 -0
  338. package/distribution/sign-in-start/type.js.map +1 -0
  339. package/distribution/sign-up-finish/index.d.ts +13 -0
  340. package/distribution/sign-up-finish/index.d.ts.map +1 -0
  341. package/distribution/sign-up-finish/index.js +38 -0
  342. package/distribution/sign-up-finish/index.js.map +1 -0
  343. package/distribution/sign-up-finish/type.d.ts +28 -0
  344. package/distribution/sign-up-finish/type.d.ts.map +1 -0
  345. package/distribution/sign-up-finish/type.js +2 -0
  346. package/distribution/sign-up-finish/type.js.map +1 -0
  347. package/distribution/signed-ticket/index.d.ts +19 -0
  348. package/distribution/signed-ticket/index.d.ts.map +1 -0
  349. package/distribution/signed-ticket/index.js +35 -0
  350. package/distribution/signed-ticket/index.js.map +1 -0
  351. package/distribution/signed-ticket/type.d.ts +16 -0
  352. package/distribution/signed-ticket/type.d.ts.map +1 -0
  353. package/distribution/signed-ticket/type.js +2 -0
  354. package/distribution/signed-ticket/type.js.map +1 -0
  355. package/distribution/step-up/index.d.ts +48 -0
  356. package/distribution/step-up/index.d.ts.map +1 -0
  357. package/distribution/step-up/index.js +83 -0
  358. package/distribution/step-up/index.js.map +1 -0
  359. package/distribution/step-up/type.d.ts +15 -0
  360. package/distribution/step-up/type.d.ts.map +1 -0
  361. package/distribution/step-up/type.js +2 -0
  362. package/distribution/{username → step-up}/type.js.map +1 -1
  363. package/distribution/test-database/index.d.ts +13 -0
  364. package/distribution/test-database/index.d.ts.map +1 -0
  365. package/distribution/test-database/index.js +17 -0
  366. package/distribution/test-database/index.js.map +1 -0
  367. package/distribution/test-person/index.d.ts +14 -0
  368. package/distribution/test-person/index.d.ts.map +1 -0
  369. package/distribution/test-person/index.js +20 -0
  370. package/distribution/test-person/index.js.map +1 -0
  371. package/distribution/test-server/index.d.ts +10 -0
  372. package/distribution/test-server/index.d.ts.map +1 -0
  373. package/distribution/test-server/index.js +16 -0
  374. package/distribution/test-server/index.js.map +1 -0
  375. package/distribution/totp/type.d.ts +1 -1
  376. package/distribution/totp/type.d.ts.map +1 -1
  377. package/distribution/totp-setup/index.d.ts +50 -0
  378. package/distribution/totp-setup/index.d.ts.map +1 -0
  379. package/distribution/totp-setup/index.js +136 -0
  380. package/distribution/totp-setup/index.js.map +1 -0
  381. package/distribution/totp-setup/type.d.ts +24 -0
  382. package/distribution/totp-setup/type.d.ts.map +1 -0
  383. package/distribution/totp-setup/type.js +2 -0
  384. package/distribution/totp-setup/type.js.map +1 -0
  385. package/package.json +9 -2
  386. package/distribution/username/index.d.ts +0 -23
  387. package/distribution/username/index.d.ts.map +0 -1
  388. package/distribution/username/index.js +0 -32
  389. package/distribution/username/index.js.map +0 -1
  390. package/distribution/username/type.d.ts +0 -10
  391. package/distribution/username/type.d.ts.map +0 -1
  392. /package/distribution/{username → account-activity}/type.js +0 -0
@@ -0,0 +1,78 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
3
+ import { createSessionToken, hashSessionToken } from "@sharadox/account-web-library/session-token";
4
+ const DAY = 86_400;
5
+ /**
6
+ * Signs an account in on a browser, after its code (and two-factor, when it has it) passed: the account joins the
7
+ * accounts already signed in there (the account selector has no limit), or a new browser session starts. The browser
8
+ * gets a new token every time, so a token planted before sign-in is worthless. Signing in again with the same account
9
+ * replaces its session there.
10
+ *
11
+ * @example
12
+ * const { token } = await signIn(database, { accountId, token: cookies.get("__Host-account")?.value });
13
+ * cookies.set("__Host-account", token, { httpOnly: true, secure: true, sameSite: "lax", path: "/" });
14
+ */
15
+ export async function signIn(database, { accountId, token, secondFactor = false, userAgent = null, accountSessionSeconds = 30 * DAY, browserSessionSeconds = 400 * DAY, now = Date.now(), }) {
16
+ const at = new Date(now);
17
+ const fresh = createSessionToken();
18
+ const device = userAgent?.slice(0, 500) ?? null;
19
+ return database.transaction().execute(async (transaction) => {
20
+ const browser = token
21
+ ? await transaction
22
+ .selectFrom("browser_session")
23
+ .select("id")
24
+ .where("token_hash", "=", hashSessionToken(token))
25
+ .where("expires_at", ">", at)
26
+ .forUpdate()
27
+ .executeTakeFirst()
28
+ : undefined;
29
+ const browserSessionId = browser?.id ?? uuidVersion7({ now });
30
+ if (browser) {
31
+ await transaction
32
+ .updateTable("browser_session")
33
+ .set({ token_hash: fresh.hash, last_seen_at: at, user_agent: device })
34
+ .where("id", "=", browserSessionId)
35
+ .execute();
36
+ }
37
+ else {
38
+ await transaction
39
+ .insertInto("browser_session")
40
+ .values({
41
+ id: browserSessionId,
42
+ token_hash: fresh.hash,
43
+ created_at: at,
44
+ last_seen_at: at,
45
+ expires_at: new Date(now + browserSessionSeconds * 1000),
46
+ user_agent: device,
47
+ })
48
+ .execute();
49
+ }
50
+ await transaction
51
+ .deleteFrom("account_session")
52
+ .where("browser_session_id", "=", browserSessionId)
53
+ .where("account_id", "=", accountId)
54
+ .execute();
55
+ const accountSessionId = uuidVersion7({ now });
56
+ await transaction
57
+ .insertInto("account_session")
58
+ .values({
59
+ id: accountSessionId,
60
+ browser_session_id: browserSessionId,
61
+ account_id: accountId,
62
+ created_at: at,
63
+ last_seen_at: at,
64
+ expires_at: new Date(now + accountSessionSeconds * 1000),
65
+ second_factor_at: secondFactor ? at : null,
66
+ })
67
+ .execute();
68
+ await transaction.updateTable("account").set({ last_active_at: at }).where("id", "=", accountId).execute();
69
+ await recordAuditEvent(transaction, {
70
+ accountId,
71
+ action: "session.signed-in",
72
+ detail: { accountSessionId, secondFactor },
73
+ now,
74
+ });
75
+ return { token: fresh.token, browserSessionId, accountSessionId, newBrowser: !browser };
76
+ });
77
+ }
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-sign-in/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAEnG,MAAM,GAAG,GAAG,MAAM,CAAC;AAEnB;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,QAAiC,EACjC,EACE,SAAS,EACT,KAAK,EACL,YAAY,GAAG,KAAK,EACpB,SAAS,GAAG,IAAI,EAChB,qBAAqB,GAAG,EAAE,GAAG,GAAG,EAChC,qBAAqB,GAAG,GAAG,GAAG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OAAO,EAAE,CAAC;IAC1F,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,24 @@
1
+ export interface SignInOptions {
2
+ accountId: string;
3
+ /** The browser's current token (its cookie), if it has one: the account joins that browser's accounts. */
4
+ token?: string;
5
+ /** Whether two-factor was passed for this sign-in. */
6
+ secondFactor?: boolean;
7
+ /** The browser's User-Agent, shown in the list of devices (kept to 500 characters). */
8
+ userAgent?: string | null;
9
+ /** 30 days by default. */
10
+ accountSessionSeconds?: number;
11
+ /** 400 days by default (the longest a browser keeps a cookie). */
12
+ browserSessionSeconds?: number;
13
+ /** Milliseconds since 1970 (now by default). */
14
+ now?: number;
15
+ }
16
+ export interface SignInResult {
17
+ /** The browser's new token: set it as the cookie (it replaces the old one at every sign-in). */
18
+ token: string;
19
+ browserSessionId: string;
20
+ accountSessionId: string;
21
+ /** Whether the browser had no session before (tell the account's emails: someone signed in somewhere new). */
22
+ newBrowser: boolean;
23
+ }
24
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/account-sign-in/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,0BAA0B;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kEAAkE;IAClE,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,gGAAgG;IAChG,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,8GAA8G;IAC9G,UAAU,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/account-sign-in/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Signs one account out of a browser (`accountId`), or every account and the browser session with it. Returns the
5
+ * accounts signed out; tell their applications (back-channel logout) so they end their own sessions too.
6
+ *
7
+ * @example
8
+ * await signOut(database, { token: cookies.get("__Host-account")?.value, accountId });
9
+ */
10
+ export declare function signOut(database: Kysely<AccountDatabase>, { token, accountId }: {
11
+ token: string | undefined;
12
+ accountId?: string;
13
+ }): Promise<{
14
+ signedOut: string[];
15
+ }>;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/account-sign-out/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACtE,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAmBlC"}
@@ -0,0 +1,34 @@
1
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
2
+ import { hashSessionToken } from "@sharadox/account-web-library/session-token";
3
+ /**
4
+ * Signs one account out of a browser (`accountId`), or every account and the browser session with it. Returns the
5
+ * accounts signed out; tell their applications (back-channel logout) so they end their own sessions too.
6
+ *
7
+ * @example
8
+ * await signOut(database, { token: cookies.get("__Host-account")?.value, accountId });
9
+ */
10
+ export async function signOut(database, { token, accountId }) {
11
+ if (!token)
12
+ return { signedOut: [] };
13
+ return database.transaction().execute(async (transaction) => {
14
+ const browser = await transaction
15
+ .selectFrom("browser_session")
16
+ .select("id")
17
+ .where("token_hash", "=", hashSessionToken(token))
18
+ .forUpdate()
19
+ .executeTakeFirst();
20
+ if (!browser)
21
+ return { signedOut: [] };
22
+ let removal = transaction.deleteFrom("account_session").where("browser_session_id", "=", browser.id);
23
+ if (accountId)
24
+ removal = removal.where("account_id", "=", accountId);
25
+ const removed = await removal.returning("account_id").execute();
26
+ if (!accountId)
27
+ await transaction.deleteFrom("browser_session").where("id", "=", browser.id).execute();
28
+ for (const { account_id } of removed) {
29
+ await recordAuditEvent(transaction, { accountId: account_id, action: "session.signed-out" });
30
+ }
31
+ return { signedOut: removed.map(({ account_id }) => account_id) };
32
+ });
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/account-sign-out/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,QAAiC,EACjC,EAAE,KAAK,EAAE,SAAS,EAAqD;IAEvE,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACrC,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC1D,MAAM,OAAO,GAAG,MAAM,WAAW;aAC9B,UAAU,CAAC,iBAAiB,CAAC;aAC7B,MAAM,CAAC,IAAI,CAAC;aACZ,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;aACjD,SAAS,EAAE;aACX,gBAAgB,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QACvC,IAAI,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,oBAAoB,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACrG,IAAI,SAAS;YAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;QAChE,IAAI,CAAC,SAAS;YAAE,MAAM,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACvG,KAAK,MAAM,EAAE,UAAU,EAAE,IAAI,OAAO,EAAE,CAAC;YACrC,MAAM,gBAAgB,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAC/F,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { ApplicationDeclaration, ApplicationSyncResult } from "@sharadox/account-web-library/application-sync/type";
4
+ /**
5
+ * Makes the database follow what an application declares in its code, all or nothing: the application, its
6
+ * permissions (only its own: each starts with `<key>.`), and its roles with their permissions, the default one
7
+ * (held by every account) and exclusive ones (bans). Permissions and roles no longer declared go, except a role
8
+ * still granted, which stays until its grants end. Run it at every deploy.
9
+ *
10
+ * @example
11
+ * await syncApplication(database, { key: "platform", name: "Platform", permissions, roles });
12
+ */
13
+ export declare function syncApplication(database: Kysely<AccountDatabase>, { key, name, permissions, roles }: ApplicationDeclaration): Promise<ApplicationSyncResult>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/application-sync/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,EACV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,qDAAqD,CAAC;AAG7D;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,sBAAsB,GACxD,OAAO,CAAC,qBAAqB,CAAC,CA0FhC"}
@@ -0,0 +1,96 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
3
+ /**
4
+ * Makes the database follow what an application declares in its code, all or nothing: the application, its
5
+ * permissions (only its own: each starts with `<key>.`), and its roles with their permissions, the default one
6
+ * (held by every account) and exclusive ones (bans). Permissions and roles no longer declared go, except a role
7
+ * still granted, which stays until its grants end. Run it at every deploy.
8
+ *
9
+ * @example
10
+ * await syncApplication(database, { key: "platform", name: "Platform", permissions, roles });
11
+ */
12
+ export async function syncApplication(database, { key, name, permissions, roles }) {
13
+ const foreign = permissions.find((permission) => !permission.key.startsWith(`${key}.`));
14
+ if (foreign)
15
+ return { synced: false, reason: "foreign-permission", detail: foreign.key };
16
+ const declared = new Set(permissions.map((permission) => permission.key));
17
+ const unknown = roles.flatMap((role) => role.permissions).find((permission) => !declared.has(permission));
18
+ if (unknown)
19
+ return { synced: false, reason: "unknown-permission", detail: unknown };
20
+ const defaults = roles.filter((role) => role.default).map((role) => role.key);
21
+ if (defaults.length > 1)
22
+ return { synced: false, reason: "defaults", detail: defaults.join(", ") };
23
+ await database.transaction().execute(async (transaction) => {
24
+ const application = await transaction
25
+ .insertInto("application")
26
+ .values({ key, name })
27
+ .onConflict((conflict) => conflict.column("key").doUpdateSet({ name }))
28
+ .returning("id")
29
+ .executeTakeFirstOrThrow();
30
+ for (const permission of permissions)
31
+ await transaction
32
+ .insertInto("permission")
33
+ .values({ id: uuidVersion7(), application_id: application.id, ...permission })
34
+ .onConflict((conflict) => conflict.column("key").doUpdateSet({ description: permission.description }))
35
+ .execute();
36
+ let gone = transaction.deleteFrom("permission").where("application_id", "=", application.id);
37
+ if (declared.size > 0)
38
+ gone = gone.where("key", "not in", [...declared]);
39
+ await gone.execute();
40
+ const permissionIds = new Map((await transaction
41
+ .selectFrom("permission")
42
+ .select(["id", "key"])
43
+ .where("application_id", "=", application.id)
44
+ .execute()).map(({ id, key: permissionKey }) => [permissionKey, id]));
45
+ // The default moves only once every role is in place (one default per application at any moment).
46
+ await transaction
47
+ .updateTable("role")
48
+ .set({ is_default: false })
49
+ .where("application_id", "=", application.id)
50
+ .execute();
51
+ for (const role of roles) {
52
+ const existing = await transaction
53
+ .selectFrom("role")
54
+ .select("id")
55
+ .where("application_id", "=", application.id)
56
+ .where("key", "=", role.key)
57
+ .executeTakeFirst();
58
+ const roleId = existing?.id ?? uuidVersion7();
59
+ const values = { name: role.name, exclusive: role.exclusive ?? false };
60
+ if (existing)
61
+ await transaction.updateTable("role").set(values).where("id", "=", roleId).execute();
62
+ else
63
+ await transaction
64
+ .insertInto("role")
65
+ .values({ id: roleId, application_id: application.id, key: role.key, ...values })
66
+ .execute();
67
+ await transaction.deleteFrom("role_permission").where("role_id", "=", roleId).execute();
68
+ if (role.permissions.length > 0)
69
+ await transaction
70
+ .insertInto("role_permission")
71
+ .values(role.permissions.map((permission) => ({
72
+ id: uuidVersion7(),
73
+ role_id: roleId,
74
+ permission_id: permissionIds.get(permission),
75
+ })))
76
+ .execute();
77
+ }
78
+ if (defaults.length === 1)
79
+ await transaction
80
+ .updateTable("role")
81
+ .set({ is_default: true })
82
+ .where("application_id", "=", application.id)
83
+ .where("key", "=", defaults[0])
84
+ .execute();
85
+ let undeclared = transaction
86
+ .deleteFrom("role")
87
+ .where("application_id", "=", application.id)
88
+ .where(({ not, exists, selectFrom }) => not(exists(selectFrom("role_grant").select("role_grant.id").whereRef("role_grant.role_id", "=", "role.id"))));
89
+ if (roles.length > 0)
90
+ undeclared = undeclared.where("key", "not in", roles.map((role) => role.key));
91
+ await undeclared.execute();
92
+ await recordAuditEvent(transaction, { application: key, action: "application.synced" });
93
+ });
94
+ return { synced: true };
95
+ }
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/application-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAM/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAE7E;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAAiC,EACjC,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAA0B;IAEzD,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;IACxF,IAAI,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,OAAO,CAAC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M,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,29 @@
1
+ /** What an application declares in its code, synced at each deploy. */
2
+ export interface ApplicationDeclaration {
3
+ /** Its permanent short name, the prefix of its permissions (`platform`). */
4
+ key: string;
5
+ name: string;
6
+ /** Each starts with `<key>.`. */
7
+ permissions: {
8
+ key: string;
9
+ description: string;
10
+ }[];
11
+ roles: {
12
+ key: string;
13
+ name: string;
14
+ /** Keys from `permissions`. */
15
+ permissions: string[];
16
+ /** The role every account holds without a grant (one at most). */
17
+ default?: boolean;
18
+ /** While granted, only this role's permissions count (a ban). */
19
+ exclusive?: boolean;
20
+ }[];
21
+ }
22
+ export type ApplicationSyncResult = {
23
+ synced: true;
24
+ } | {
25
+ synced: false;
26
+ reason: "foreign-permission" | "unknown-permission" | "defaults";
27
+ detail: string;
28
+ };
29
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/application-sync/type.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,WAAW,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACpD,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,+BAA+B;QAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,kEAAkE;QAClE,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,iEAAiE;QACjE,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,EAAE,CAAC;CACL;AAED,MAAM,MAAM,qBAAqB,GAC7B;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,GAChB;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,GAAG,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/application-sync/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { AuditEvent } from "@sharadox/account-web-library/audit-event/type";
4
+ /**
5
+ * Adds a line to the append-only audit log (the database refuses changes to it). Pass a transaction to record it
6
+ * together with the change it describes. Returns the event's UUIDv7.
7
+ *
8
+ * @example
9
+ * await recordAuditEvent(transaction, { accountId, action: "contact.removed", detail: { contactId } });
10
+ */
11
+ export declare function recordAuditEvent(database: Kysely<AccountDatabase>, { accountId, actorAccountId, application, action, detail, now }: AuditEvent): Promise<string>;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/audit-event/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,MAAM,gDAAgD,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAgB,EAAE,cAAqB,EAAE,WAAkB,EAAE,MAAM,EAAE,MAAW,EAAE,GAAgB,EAAE,EAAE,UAAU,GACjH,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
@@ -0,0 +1,36 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ /**
3
+ * Adds a line to the append-only audit log (the database refuses changes to it). Pass a transaction to record it
4
+ * together with the change it describes. Returns the event's UUIDv7.
5
+ *
6
+ * @example
7
+ * await recordAuditEvent(transaction, { accountId, action: "contact.removed", detail: { contactId } });
8
+ */
9
+ export async function recordAuditEvent(database, { accountId = null, actorAccountId = null, application = null, action, detail = {}, now = Date.now() }) {
10
+ const id = uuidVersion7({ now });
11
+ let applicationId = null;
12
+ if (application !== null) {
13
+ const found = await database
14
+ .selectFrom("application")
15
+ .select("id")
16
+ .where("key", "=", application)
17
+ .executeTakeFirst();
18
+ if (!found)
19
+ throw new Error(`no application "${application}"`);
20
+ applicationId = found.id;
21
+ }
22
+ await database
23
+ .insertInto("audit_event")
24
+ .values({
25
+ id,
26
+ at: new Date(now),
27
+ account_id: accountId,
28
+ actor_account_id: actorAccountId,
29
+ application_id: applicationId,
30
+ action,
31
+ detail,
32
+ })
33
+ .execute();
34
+ return id;
35
+ }
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/audit-event/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAI/E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAiC,EACjC,EAAE,SAAS,GAAG,IAAI,EAAE,cAAc,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAc;IAElH,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACjC,IAAI,aAAa,GAAkB,IAAI,CAAC;IACxC,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,QAAQ;aACzB,UAAU,CAAC,aAAa,CAAC;aACzB,MAAM,CAAC,IAAI,CAAC;aACZ,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,CAAC;aAC9B,gBAAgB,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,WAAW,GAAG,CAAC,CAAC;QAC/D,aAAa,GAAG,KAAK,CAAC,EAAE,CAAC;IAC3B,CAAC;IACD,MAAM,QAAQ;SACX,UAAU,CAAC,aAAa,CAAC;SACzB,MAAM,CAAC;QACN,EAAE;QACF,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC;QACjB,UAAU,EAAE,SAAS;QACrB,gBAAgB,EAAE,cAAc;QAChC,cAAc,EAAE,aAAa;QAC7B,MAAM;QACN,MAAM;KACP,CAAC;SACD,OAAO,EAAE,CAAC;IACb,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** What happened, to which account, done by whom, in which application. */
2
+ export interface AuditEvent {
3
+ /** The account it is about. */
4
+ accountId?: string | null;
5
+ /** Who did it, when not the account itself. */
6
+ actorAccountId?: string | null;
7
+ /** The application's key (`platform`), stored as its id; it must exist. */
8
+ application?: string | null;
9
+ /** `<subject>.<verb>`: `account.created`, `contact.removed`, `role.granted`… */
10
+ action: string;
11
+ /** Ids and kinds, never contact values or secrets. */
12
+ detail?: Record<string, unknown>;
13
+ /** Milliseconds since 1970 (now by default). */
14
+ now?: number;
15
+ }
16
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/audit-event/type.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/audit-event/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
4
+ /**
5
+ * The form a contact is kept in the banned-contact ledger: an HMAC under a pepper kept outside the database, of the
6
+ * contact normalized and, for an email, without its `+tag` (so `ana+new@` is still `ana@`). Never the contact.
7
+ *
8
+ * @example
9
+ * bannedContactHash({ kind: "email", value: "Ana+x@example.com" }, pepper);
10
+ */
11
+ export declare function bannedContactHash(contact: Contact, pepper: string): string;
12
+ /**
13
+ * Whether a contact belongs to a deleted account banned in this application (or everywhere), while the ban lasts:
14
+ * checked before signing up and adding a contact. An invalid contact is not banned.
15
+ *
16
+ * @example
17
+ * if (await contactBanned(database, { contact, pepper, application: "account" })) return refuse();
18
+ */
19
+ export declare function contactBanned(database: Kysely<AccountDatabase>, { contact, pepper, application, now, }: {
20
+ contact: Contact;
21
+ pepper: string;
22
+ application: string;
23
+ now?: number;
24
+ }): Promise<boolean>;
25
+ /**
26
+ * Forgets ledger rows whose ban has ended, for a daily job. Returns how many went.
27
+ *
28
+ * @example
29
+ * await pruneBannedContacts(database);
30
+ */
31
+ export declare function pruneBannedContacts(database: Kysely<AccountDatabase>, { now }?: {
32
+ now?: number;
33
+ }): Promise<number>;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/banned-contact/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAE3F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAG/E;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,OAAO,EACP,MAAM,EACN,WAAW,EACX,GAAgB,GACjB,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACzE,OAAO,CAAC,OAAO,CAAC,CAkBlB;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,GAAgB,EAAE,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1C,OAAO,CAAC,MAAM,CAAC,CAGjB"}
@@ -0,0 +1,52 @@
1
+ import { createHmac } from "node:crypto";
2
+ import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
3
+ import { emailLedgerForm } from "@sharadox/account-web-library/email-contact";
4
+ /**
5
+ * The form a contact is kept in the banned-contact ledger: an HMAC under a pepper kept outside the database, of the
6
+ * contact normalized and, for an email, without its `+tag` (so `ana+new@` is still `ana@`). Never the contact.
7
+ *
8
+ * @example
9
+ * bannedContactHash({ kind: "email", value: "Ana+x@example.com" }, pepper);
10
+ */
11
+ export function bannedContactHash(contact, pepper) {
12
+ const { kind, value } = normalizeContact(contact);
13
+ // Email is the only kind of contact so far (normalizeContact refuses others); a new kind brings its own form.
14
+ const form = emailLedgerForm(value);
15
+ return createHmac("sha256", pepper).update(`${kind}\n${form}`).digest("base64url");
16
+ }
17
+ /**
18
+ * Whether a contact belongs to a deleted account banned in this application (or everywhere), while the ban lasts:
19
+ * checked before signing up and adding a contact. An invalid contact is not banned.
20
+ *
21
+ * @example
22
+ * if (await contactBanned(database, { contact, pepper, application: "account" })) return refuse();
23
+ */
24
+ export async function contactBanned(database, { contact, pepper, application, now = Date.now(), }) {
25
+ let hash;
26
+ try {
27
+ hash = bannedContactHash(contact, pepper);
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ const found = await database
33
+ .selectFrom("banned_contact")
34
+ .leftJoin("application", "application.id", "banned_contact.application_id")
35
+ .select("banned_contact.id")
36
+ .where("contact_hash", "=", hash)
37
+ .where((where) => where.or([where("banned_contact.application_id", "is", null), where("application.key", "=", application)]))
38
+ .where((where) => where.or([where("ends_at", "is", null), where("ends_at", ">", new Date(now))]))
39
+ .executeTakeFirst();
40
+ return found !== undefined;
41
+ }
42
+ /**
43
+ * Forgets ledger rows whose ban has ended, for a daily job. Returns how many went.
44
+ *
45
+ * @example
46
+ * await pruneBannedContacts(database);
47
+ */
48
+ export async function pruneBannedContacts(database, { now = Date.now() } = {}) {
49
+ const result = await database.deleteFrom("banned_contact").where("ends_at", "<=", new Date(now)).executeTakeFirst();
50
+ return Number(result.numDeletedRows);
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/banned-contact/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAA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CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAChG,gBAAgB,EAAE,CAAC;IACtB,OAAO,KAAK,KAAK,SAAS,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAiC,EACjC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,KAAuB,EAAE;IAE3C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpH,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AACvC,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 { BrowserSession } from "@sharadox/account-web-library/browser-session-read/type";
4
+ /**
5
+ * The accounts signed in on a browser, from its cookie's token, leaving out sessions past their end or idle longer
6
+ * than `idleSeconds` (7 days by default); marks the browser and those sessions as seen now. Undefined for a missing,
7
+ * unknown or expired token.
8
+ *
9
+ * @example
10
+ * const session = await readBrowserSession(database, { token: cookies.get("__Host-account")?.value });
11
+ */
12
+ export declare function readBrowserSession(database: Kysely<AccountDatabase>, { token, idleSeconds, now, }: {
13
+ token: string | undefined;
14
+ idleSeconds?: number;
15
+ now?: number;
16
+ }): Promise<BrowserSession | undefined>;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/browser-session-read/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,cAAc,EAAE,MAAM,yDAAyD,CAAC;AAG9F;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EACE,KAAK,EACL,WAAwB,EACxB,GAAgB,GACjB,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnE,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CA2CrC"}
@@ -0,0 +1,52 @@
1
+ import { hashSessionToken } from "@sharadox/account-web-library/session-token";
2
+ /**
3
+ * The accounts signed in on a browser, from its cookie's token, leaving out sessions past their end or idle longer
4
+ * than `idleSeconds` (7 days by default); marks the browser and those sessions as seen now. Undefined for a missing,
5
+ * unknown or expired token.
6
+ *
7
+ * @example
8
+ * const session = await readBrowserSession(database, { token: cookies.get("__Host-account")?.value });
9
+ */
10
+ export async function readBrowserSession(database, { token, idleSeconds = 7 * 86_400, now = Date.now(), }) {
11
+ if (!token)
12
+ return undefined;
13
+ const at = new Date(now);
14
+ const browser = await database
15
+ .selectFrom("browser_session")
16
+ .select("id")
17
+ .where("token_hash", "=", hashSessionToken(token))
18
+ .where("expires_at", ">", at)
19
+ .executeTakeFirst();
20
+ if (!browser)
21
+ return undefined;
22
+ const rows = await database
23
+ .selectFrom("account_session")
24
+ .innerJoin("account", "account.id", "account_session.account_id")
25
+ .innerJoin("identifier", "identifier.account_id", "account.id")
26
+ .leftJoin("account_picture", "account_picture.account_id", "account.id")
27
+ .select([
28
+ "account_session.id as accountSessionId",
29
+ "account.id as accountId",
30
+ "identifier.value as identifier",
31
+ "account.name as name",
32
+ "account_picture.id as pictureId",
33
+ "account_session.created_at as signedInAt",
34
+ "account_session.second_factor_at as secondFactorAt",
35
+ ])
36
+ .where("account_session.browser_session_id", "=", browser.id)
37
+ .where("account_session.expires_at", ">", at)
38
+ .where("account_session.last_seen_at", ">", new Date(now - idleSeconds * 1000))
39
+ .orderBy("account_session.created_at")
40
+ .orderBy("account_session.id")
41
+ .execute();
42
+ await database.updateTable("browser_session").set({ last_seen_at: at }).where("id", "=", browser.id).execute();
43
+ if (rows.length > 0) {
44
+ await database
45
+ .updateTable("account_session")
46
+ .set({ last_seen_at: at })
47
+ .where("id", "in", rows.map(({ accountSessionId }) => accountSessionId))
48
+ .execute();
49
+ }
50
+ return { browserSessionId: browser.id, accounts: rows };
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/browser-session-read/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAiC,EACjC,EACE,KAAK,EACL,WAAW,GAAG,CAAC,GAAG,MAAM,EACxB,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GACkD;IAEpE,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,OAAO,GAAG,MAAM,QAAQ;SAC3B,UAAU,CAAC,iBAAiB,CAAC;SAC7B,MAAM,CAAC,IAAI,CAAC;SACZ,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;SACjD,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,EAAE,CAAC;SAC5B,gBAAgB,EAAE,CAAC;IACtB,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,IAAI,GAAG,MAAM,QAAQ;SACxB,UAAU,CAAC,iBAAiB,CAAC;SAC7B,SAAS,CAAC,SAAS,EAAE,YAAY,EAAE,4BAA4B,CAAC;SAChE,SAAS,CAAC,YAAY,EAAE,uBAAuB,EAAE,YAAY,CAAC;SAC9D,QA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