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

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 +267 -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 +22 -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 +44 -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 +168 -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 +83 -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 +12 -0
  324. package/distribution/sign-in-finish/index.d.ts.map +1 -0
  325. package/distribution/sign-in-finish/index.js +64 -0
  326. package/distribution/sign-in-finish/index.js.map +1 -0
  327. package/distribution/sign-in-finish/type.d.ts +41 -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,168 @@
1
+ import { emailLayout } from "@sharadox/email-web-library/email-layout";
2
+ const date = (language, at) => new Intl.DateTimeFormat(language, { dateStyle: "long", timeZone: "Europe/Lisbon" }).format(at);
3
+ const ENGLISH = {
4
+ language: "en",
5
+ subject: {
6
+ "sign-in": (company) => `Your ${company} sign-in code`,
7
+ "contact-verification": (company) => `Confirm your address for ${company}`,
8
+ "step-up": (company) => `Your ${company} confirmation code`,
9
+ },
10
+ eyebrow: { "sign-in": "Sign in", "contact-verification": "Confirm address", "step-up": "Confirmation" },
11
+ heading: {
12
+ "sign-in": "Your sign-in code",
13
+ "contact-verification": "Confirm this address",
14
+ "step-up": "Confirm it's you",
15
+ },
16
+ label: "Code",
17
+ lifetime: (minutes) => `It works once, for ${minutes} ${minutes === 1 ? "minute" : "minutes"}.`,
18
+ ignore: "If you didn't ask for it, you can ignore this email: without the code, nobody gets in.",
19
+ never: "We will never ask you for this code.",
20
+ closing: "Best regards,",
21
+ notice: {
22
+ "inactivity-warning": {
23
+ subject: (company) => `Your ${company} account will be deleted`,
24
+ heading: "Your account will be deleted",
25
+ body: (notice) => [
26
+ `Nobody has signed in to it for a long time, so it will be deleted on ${date("en-GB", notice.deletionAt)}, with everything in it.`,
27
+ "Sign in before then to keep it. If you don't need it any more, there is nothing to do.",
28
+ ],
29
+ },
30
+ "contact-added": {
31
+ subject: (company) => `An email was added to your ${company} account`,
32
+ heading: "An email was added",
33
+ body: (notice) => [
34
+ `${notice.contact} can now sign in to your account.`,
35
+ "If it wasn't you, sign in, remove it, and sign out of the devices you don't recognize.",
36
+ ],
37
+ },
38
+ "recovery-code-used": {
39
+ subject: (company) => `A recovery code was used for your ${company} account`,
40
+ heading: "A recovery code was used",
41
+ body: () => [
42
+ "Someone signed in to your account with one of its recovery codes.",
43
+ "If it wasn't you, sign in, make new recovery codes, and sign out of the devices you don't recognize.",
44
+ ],
45
+ },
46
+ },
47
+ };
48
+ const PORTUGUESE = {
49
+ language: "pt-PT",
50
+ subject: {
51
+ "sign-in": (company) => `O seu código para entrar em ${company}`,
52
+ "contact-verification": (company) => `Confirme o seu endereço em ${company}`,
53
+ "step-up": (company) => `O seu código de confirmação de ${company}`,
54
+ },
55
+ eyebrow: { "sign-in": "Entrar", "contact-verification": "Confirmar endereço", "step-up": "Confirmação" },
56
+ heading: {
57
+ "sign-in": "O seu código para entrar",
58
+ "contact-verification": "Confirme este endereço",
59
+ "step-up": "Confirme que é você",
60
+ },
61
+ label: "Código",
62
+ lifetime: (minutes) => `Funciona uma vez, durante ${minutes} ${minutes === 1 ? "minuto" : "minutos"}.`,
63
+ ignore: "Se não o pediu, pode ignorar este email: sem o código, ninguém entra.",
64
+ never: "Nunca lhe pediremos este código.",
65
+ closing: "Com os melhores cumprimentos,",
66
+ notice: {
67
+ "inactivity-warning": {
68
+ subject: (company) => `A sua conta ${company} vai ser eliminada`,
69
+ heading: "A sua conta vai ser eliminada",
70
+ body: (notice) => [
71
+ `Ninguém entra nela há muito tempo, por isso será eliminada a ${date("pt-PT", notice.deletionAt)}, com tudo o que contém.`,
72
+ "Entre antes disso para a manter. Se já não precisa dela, não tem de fazer nada.",
73
+ ],
74
+ },
75
+ "contact-added": {
76
+ subject: (company) => `Foi adicionado um email à sua conta ${company}`,
77
+ heading: "Foi adicionado um email",
78
+ body: (notice) => [
79
+ `${notice.contact} pode agora entrar na sua conta.`,
80
+ "Se não foi você, entre, remova-o e termine a sessão nos dispositivos que não reconhece.",
81
+ ],
82
+ },
83
+ "recovery-code-used": {
84
+ subject: (company) => `Foi usado um código de recuperação da sua conta ${company}`,
85
+ heading: "Foi usado um código de recuperação",
86
+ body: () => [
87
+ "Alguém entrou na sua conta com um dos códigos de recuperação.",
88
+ "Se não foi você, entre, crie novos códigos de recuperação e termine a sessão nos dispositivos que não reconhece.",
89
+ ],
90
+ },
91
+ },
92
+ };
93
+ /**
94
+ * Sends one-time codes by email, in the shared Sharadox email layout (email-web-library), in English or European
95
+ * Portuguese (any `pt` reader). The code is in the body only, never the subject (lock screens show subjects), with
96
+ * no link to click: nothing to imitate in a phishing email.
97
+ *
98
+ * @example
99
+ * const channel = createEmailChannel({ sender: createAmazonSesSender(configuration), from, design });
100
+ * await channel.send({ contact, code, purpose: "sign-in", language: "pt-PT", expiresAt });
101
+ */
102
+ export function createEmailChannel({ sender, from, design, logos = [], now = Date.now, }) {
103
+ const carried = { light: logos.some(({ id }) => id === "logo"), dark: logos.some(({ id }) => id === "logo-dark") };
104
+ return {
105
+ kind: "email",
106
+ async send({ contact, code, purpose, language, expiresAt }) {
107
+ if (contact.kind !== "email")
108
+ throw new Error(`the email channel can't send to a "${contact.kind}" contact`);
109
+ const words = language.toLowerCase().startsWith("pt") ? PORTUGUESE : ENGLISH;
110
+ const shown = code.replace(/(.{3})(?=.)/g, "$1 ");
111
+ const minutes = Math.max(1, Math.ceil((expiresAt.getTime() - now()) / 60_000));
112
+ const paragraphs = [words.lifetime(minutes), words.ignore, words.never];
113
+ const html = emailLayout({
114
+ language: words.language,
115
+ preview: words.heading[purpose],
116
+ eyebrow: words.eyebrow[purpose],
117
+ heading: words.heading[purpose],
118
+ rows: [{ label: words.label, value: shown }],
119
+ paragraphs,
120
+ closing: words.closing,
121
+ }, design, carried);
122
+ const text = [
123
+ words.heading[purpose],
124
+ "",
125
+ `${words.label}: ${shown}`,
126
+ "",
127
+ ...paragraphs,
128
+ "",
129
+ words.closing,
130
+ design.name,
131
+ ].join("\n");
132
+ await sender.send({
133
+ from,
134
+ to: contact.value,
135
+ subject: words.subject[purpose](design.name),
136
+ html,
137
+ text,
138
+ ...(logos.length > 0 ? { inlineImages: logos } : {}),
139
+ });
140
+ },
141
+ async notify({ contact, language, notice }) {
142
+ if (contact.kind !== "email")
143
+ throw new Error(`the email channel can't send to a "${contact.kind}" contact`);
144
+ const words = language.toLowerCase().startsWith("pt") ? PORTUGUESE : ENGLISH;
145
+ const message = words.notice[notice.kind];
146
+ const paragraphs = message.body(notice);
147
+ const html = emailLayout({
148
+ language: words.language,
149
+ preview: message.heading,
150
+ eyebrow: design.name,
151
+ heading: message.heading,
152
+ rows: [],
153
+ paragraphs,
154
+ closing: words.closing,
155
+ }, design, carried);
156
+ const text = [message.heading, "", ...paragraphs, "", words.closing, design.name].join("\n");
157
+ await sender.send({
158
+ from,
159
+ to: contact.value,
160
+ subject: message.subject(design.name),
161
+ html,
162
+ text,
163
+ ...(logos.length > 0 ? { inlineImages: logos } : {}),
164
+ });
165
+ },
166
+ };
167
+ }
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/email-channel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AA0BvE,MAAM,IAAI,GAAG,CAAC,QAAgB,EAAE,EAAQ,EAAE,EAAE,CAC1C,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEjG,MAAM,OAAO,GAAU;IACrB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE;QACP,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,OAAO,eAAe;QACtD,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,4BAA4B,OAAO,EAAE;QAC1E,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,OAAO,oBAAoB;KAC5D;IACD,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,sBAAsB,EAAE,iBAAiB,EAAE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adox/email-web-library/email-layout/type";
3
+ import type { InlineImage } from "@sharadox/email-web-library/email-message/type";
4
+ import type { EmailSender } from "@sharadox/email-web-library/email-sender/type";
5
+ export interface EmailChannelOptions {
6
+ /** From email-web-library (`createAmazonSesSender`…). */
7
+ sender: EmailSender;
8
+ /** The sending address, for example `"Luis Pires Decor" <account@web.luispiresdecor.com>`. */
9
+ from: EmailAddress;
10
+ /** The company's name, logo size and signature (email-web-library's layout). */
11
+ design: EmailDesign;
12
+ /** The inline images "logo" and "logo-dark", when the design shows a logo. */
13
+ logos?: InlineImage[];
14
+ /** The clock, for how long the code still works (Date.now by default). */
15
+ now?: () => number;
16
+ }
17
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/email-channel/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEjF,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,MAAM,EAAE,WAAW,CAAC;IACpB,8FAA8F;IAC9F,IAAI,EAAE,YAAY,CAAC;IACnB,gFAAgF;IAChF,MAAM,EAAE,WAAW,CAAC;IACpB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,0EAA0E;IAC1E,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/email-channel/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import type { IdentifierCheck } from "@sharadox/account-web-library/identifier/type";
2
+ /** The longest identifier. */
3
+ export declare const IDENTIFIER_MAXIMUM_LENGTH = 50;
4
+ /**
5
+ * Checks an identifier against the rules:
6
+ * - 1 to 50 characters;
7
+ * - only A–Z, a–z and 0–9, with `-`, `_` or `.` allowed only between letters or digits, never two in a row;
8
+ * - shown as written, unique without regard to case (see `identifierKey`).
9
+ *
10
+ * @example
11
+ * checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
12
+ * checkIdentifier("a--b"); // { valid: false, reason: "characters" }
13
+ */
14
+ export declare function checkIdentifier(identifier: string): IdentifierCheck;
15
+ /**
16
+ * The form an identifier is unique in: lowercase, so `abc` and `aBc` are the same identifier (the database's unique index
17
+ * is on this key).
18
+ *
19
+ * @example
20
+ * identifierKey("aBc"); // "abc"
21
+ */
22
+ export declare function identifierKey(identifier: string): string;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/identifier/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAKrF,8BAA8B;AAC9B,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,CAInE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAExD"}
@@ -0,0 +1,32 @@
1
+ /** Letters and digits, with single `-`, `_` or `.` only between them. */
2
+ const PATTERN = /^[A-Za-z0-9]+(?:[-_.][A-Za-z0-9]+)*$/;
3
+ /** The longest identifier. */
4
+ export const IDENTIFIER_MAXIMUM_LENGTH = 50;
5
+ /**
6
+ * Checks an identifier against the rules:
7
+ * - 1 to 50 characters;
8
+ * - only A–Z, a–z and 0–9, with `-`, `_` or `.` allowed only between letters or digits, never two in a row;
9
+ * - shown as written, unique without regard to case (see `identifierKey`).
10
+ *
11
+ * @example
12
+ * checkIdentifier("Luis-Pires"); // { valid: true, identifier: "Luis-Pires", key: "luis-pires" }
13
+ * checkIdentifier("a--b"); // { valid: false, reason: "characters" }
14
+ */
15
+ export function checkIdentifier(identifier) {
16
+ if (identifier.length < 1 || identifier.length > IDENTIFIER_MAXIMUM_LENGTH)
17
+ return { valid: false, reason: "length" };
18
+ if (!PATTERN.test(identifier))
19
+ return { valid: false, reason: "characters" };
20
+ return { valid: true, identifier, key: identifierKey(identifier) };
21
+ }
22
+ /**
23
+ * The form an identifier is unique in: lowercase, so `abc` and `aBc` are the same identifier (the database's unique index
24
+ * is on this key).
25
+ *
26
+ * @example
27
+ * identifierKey("aBc"); // "abc"
28
+ */
29
+ export function identifierKey(identifier) {
30
+ return identifier.toLowerCase();
31
+ }
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/identifier/index.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,OAAO,GAAG,sCAAsC,CAAC;AAEvD,8BAA8B;AAC9B,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,yBAAyB;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACtH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAC7E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** An identifier that follows the rules (with its `key` for uniqueness), or why not. */
2
+ export type IdentifierCheck = {
3
+ valid: true;
4
+ identifier: string;
5
+ key: string;
6
+ } | {
7
+ valid: false;
8
+ reason: "length" | "characters";
9
+ };
10
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/identifier/type.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,MAAM,eAAe,GACzB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,YAAY,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/identifier/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { type Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ /**
4
+ * Whether an identifier can be taken: `available`, `taken` (in any case: `aBc` is taken when `abc` exists) or `invalid`
5
+ * (outside the rules). Rate limit callers: it tells whether an account exists.
6
+ *
7
+ * @example
8
+ * await identifierAvailability(database, "Luis-Pires"); // "available"
9
+ */
10
+ export declare function identifierAvailability(database: Kysely<AccountDatabase>, identifier: string): Promise<"available" | "taken" | "invalid">;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/identifier-availability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAG3F;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC,CAS5C"}
@@ -0,0 +1,21 @@
1
+ import { sql } from "kysely";
2
+ import { checkIdentifier } from "@sharadox/account-web-library/identifier";
3
+ /**
4
+ * Whether an identifier can be taken: `available`, `taken` (in any case: `aBc` is taken when `abc` exists) or `invalid`
5
+ * (outside the rules). Rate limit callers: it tells whether an account exists.
6
+ *
7
+ * @example
8
+ * await identifierAvailability(database, "Luis-Pires"); // "available"
9
+ */
10
+ export async function identifierAvailability(database, identifier) {
11
+ const check = checkIdentifier(identifier);
12
+ if (!check.valid)
13
+ return "invalid";
14
+ const found = await database
15
+ .selectFrom("identifier")
16
+ .select("id")
17
+ .where(sql `lower(value)`, "=", check.key)
18
+ .executeTakeFirst();
19
+ return found ? "taken" : "available";
20
+ }
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/identifier-availability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,QAAiC,EACjC,UAAkB;IAElB,MAAM,KAAK,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,QAAQ;SACzB,UAAU,CAAC,YAAY,CAAC;SACxB,MAAM,CAAC,IAAI,CAAC;SACZ,KAAK,CAAC,GAAG,CAAQ,cAAc,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;SAChD,gBAAgB,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;AACvC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { IdentifierChangeResult } from "@sharadox/account-web-library/identifier-change/type";
4
+ /**
5
+ * Changes an account's identifier whenever its owner wants; the old one is free for anyone at once. Accounts are
6
+ * referenced by id, so nothing breaks; the audit log keeps the history. Changing only the case is allowed.
7
+ *
8
+ * @example
9
+ * await changeIdentifier(database, { accountId, identifier: "Luis-Pires" }); // { changed: true }
10
+ */
11
+ export declare function changeIdentifier(database: Kysely<AccountDatabase>, { accountId, identifier }: {
12
+ accountId: string;
13
+ identifier: string;
14
+ }): Promise<IdentifierChangeResult>;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/identifier-change/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAEnG;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACnE,OAAO,CAAC,sBAAsB,CAAC,CA4BjC"}
@@ -0,0 +1,43 @@
1
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
2
+ import { databaseError } from "@sharadox/account-web-library/database-error";
3
+ import { checkIdentifier } from "@sharadox/account-web-library/identifier";
4
+ /**
5
+ * Changes an account's identifier whenever its owner wants; the old one is free for anyone at once. Accounts are
6
+ * referenced by id, so nothing breaks; the audit log keeps the history. Changing only the case is allowed.
7
+ *
8
+ * @example
9
+ * await changeIdentifier(database, { accountId, identifier: "Luis-Pires" }); // { changed: true }
10
+ */
11
+ export async function changeIdentifier(database, { accountId, identifier }) {
12
+ if (!checkIdentifier(identifier).valid)
13
+ return { changed: false, reason: "identifier-invalid" };
14
+ try {
15
+ return await database.transaction().execute(async (transaction) => {
16
+ const current = await transaction
17
+ .selectFrom("identifier")
18
+ .select("value")
19
+ .where("account_id", "=", accountId)
20
+ .forUpdate()
21
+ .executeTakeFirst();
22
+ if (!current)
23
+ return { changed: false, reason: "no-account" };
24
+ await transaction
25
+ .updateTable("identifier")
26
+ .set({ value: identifier })
27
+ .where("account_id", "=", accountId)
28
+ .execute();
29
+ await recordAuditEvent(transaction, {
30
+ accountId,
31
+ action: "account.identifier-changed",
32
+ detail: { from: current.value, to: identifier },
33
+ });
34
+ return { changed: true };
35
+ });
36
+ }
37
+ catch (error) {
38
+ if (databaseError(error)?.constraint === "identifier_value_key")
39
+ return { changed: false, reason: "identifier-taken" };
40
+ throw error;
41
+ }
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/identifier-change/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAG3E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAiC,EACjC,EAAE,SAAS,EAAE,UAAU,EAA6C;IAEpE,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,E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account";
6
+ };
7
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/identifier-change/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAChC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,YAAY,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/identifier-change/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import type { PictureStorage } from "@sharadox/account-web-library/picture-storage/type";
2
+ /**
3
+ * Picture storage in memory, for tests and local runs: `files` shows what is stored.
4
+ *
5
+ * @example
6
+ * const storage = createMemoryPictureStorage();
7
+ * await setAccountPicture(database, storage, { accountId, bytes });
8
+ */
9
+ export declare function createMemoryPictureStorage(): PictureStorage & {
10
+ files: Map<string, {
11
+ bytes: Uint8Array;
12
+ contentType: string;
13
+ }>;
14
+ };
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/memory-picture-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAEzF;;;;;;GAMG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,GAAG;IAC7D,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,UAAU,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChE,CAOA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Picture storage in memory, for tests and local runs: `files` shows what is stored.
3
+ *
4
+ * @example
5
+ * const storage = createMemoryPictureStorage();
6
+ * await setAccountPicture(database, storage, { accountId, bytes });
7
+ */
8
+ export function createMemoryPictureStorage() {
9
+ const files = new Map();
10
+ return {
11
+ files,
12
+ put: async (key, bytes, contentType) => void files.set(key, { bytes, contentType }),
13
+ remove: async (key) => void files.delete(key),
14
+ };
15
+ }
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/memory-picture-storage/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B;IAGxC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsD,CAAC;IAC5E,OAAO;QACL,KAAK;QACL,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QACnF,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;KAC9C,CAAC;AACJ,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import type { OneTimeCodeHashOptions } from "@sharadox/account-web-library/one-time-code/type";
2
2
  /**
3
- * A new one-time code: `length` digits (8 by default, one in a hundred million), each drawn uniformly by the
3
+ * A new one-time code: `length` digits (6 by default, one in a million: rate limits and 5 attempts per code keep guessing hopeless), each drawn uniformly by the
4
4
  * operating system's secure random source. Send it to the contact; store only `hashOneTimeCode`.
5
5
  *
6
6
  * @example
7
- * const code = createOneTimeCode(); // "04718263"
7
+ * const code = createOneTimeCode(); // "047182"
8
8
  */
9
9
  export declare function createOneTimeCode(length?: number): string;
10
10
  /**
@@ -1,12 +1,12 @@
1
1
  import { createHmac, randomInt, timingSafeEqual } from "node:crypto";
2
2
  /**
3
- * A new one-time code: `length` digits (8 by default, one in a hundred million), each drawn uniformly by the
3
+ * A new one-time code: `length` digits (6 by default, one in a million: rate limits and 5 attempts per code keep guessing hopeless), each drawn uniformly by the
4
4
  * operating system's secure random source. Send it to the contact; store only `hashOneTimeCode`.
5
5
  *
6
6
  * @example
7
- * const code = createOneTimeCode(); // "04718263"
7
+ * const code = createOneTimeCode(); // "047182"
8
8
  */
9
- export function createOneTimeCode(length = 8) {
9
+ export function createOneTimeCode(length = 6) {
10
10
  return Array.from({ length }, () => randomInt(10)).join("");
11
11
  }
12
12
  /**
@@ -0,0 +1,18 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { AccountDatabase } from "@sharadox/account-web-library/account-database/type";
3
+ import type { PersonAccountRequest, PersonAccountResult } from "@sharadox/account-web-library/person-account/type";
4
+ /**
5
+ * Creates a person's account with the contact their one-time code just proved, as its verified sign-in contact, and
6
+ * records it — all or nothing. Refuses a name outside the rules (`checkAccountName`, stored tidied), an identifier outside the rules or taken in any case, and a contact another
7
+ * account has verified.
8
+ *
9
+ * @example
10
+ * const result = await createPersonAccount(database, {
11
+ * name: "Luis Pires",
12
+ * identifier: "Luis-Pires",
13
+ * contact: { kind: "email", value },
14
+ * });
15
+ * if (!result.created) return explain(result.reason);
16
+ */
17
+ export declare function createPersonAccount(database: Kysely<AccountDatabase>, { name, identifier, contact, language, now }: PersonAccountRequest): Promise<PersonAccountResult>;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/person-account/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AAI3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAInH;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAgB,EAAE,EAAE,oBAAoB,GAC9E,OAAO,CAAC,mBAAmB,CAAC,CAuC9B"}
@@ -0,0 +1,65 @@
1
+ import { uuidVersion7 } from "@sharadox/web-library/identifier/uuid-version-7";
2
+ import { recordAuditEvent } from "@sharadox/account-web-library/audit-event";
3
+ import { normalizeContact } from "@sharadox/account-web-library/contact-kind";
4
+ import { databaseError } from "@sharadox/account-web-library/database-error";
5
+ import { checkAccountName } from "@sharadox/account-web-library/account-name";
6
+ import { checkIdentifier } from "@sharadox/account-web-library/identifier";
7
+ /**
8
+ * Creates a person's account with the contact their one-time code just proved, as its verified sign-in contact, and
9
+ * records it — all or nothing. Refuses a name outside the rules (`checkAccountName`, stored tidied), an identifier outside the rules or taken in any case, and a contact another
10
+ * account has verified.
11
+ *
12
+ * @example
13
+ * const result = await createPersonAccount(database, {
14
+ * name: "Luis Pires",
15
+ * identifier: "Luis-Pires",
16
+ * contact: { kind: "email", value },
17
+ * });
18
+ * if (!result.created) return explain(result.reason);
19
+ */
20
+ export async function createPersonAccount(database, { name, identifier, contact, language, now = Date.now() }) {
21
+ const named = checkAccountName(name);
22
+ if (!named.valid)
23
+ return { created: false, reason: "name-invalid" };
24
+ if (!checkIdentifier(identifier).valid)
25
+ return { created: false, reason: "identifier-invalid" };
26
+ const { kind, value } = normalizeContact(contact);
27
+ const at = new Date(now);
28
+ const accountId = uuidVersion7({ now });
29
+ const contactId = uuidVersion7({ now });
30
+ try {
31
+ await database.transaction().execute(async (transaction) => {
32
+ await transaction
33
+ .insertInto("account")
34
+ .values({
35
+ id: accountId,
36
+ kind: "person",
37
+ name: named.name,
38
+ owner_id: null,
39
+ created_at: at,
40
+ last_active_at: at,
41
+ language: language?.slice(0, 20) ?? null,
42
+ })
43
+ .execute();
44
+ await transaction
45
+ .insertInto("identifier")
46
+ .values({ id: uuidVersion7({ now }), value: identifier, account_id: accountId, created_at: at })
47
+ .execute();
48
+ await transaction
49
+ .insertInto("contact")
50
+ .values({ id: contactId, account_id: accountId, kind, value, verified_at: at, created_at: at })
51
+ .execute();
52
+ await recordAuditEvent(transaction, { accountId, action: "account.created", detail: { contactId }, now });
53
+ });
54
+ }
55
+ catch (error) {
56
+ const constraint = databaseError(error)?.constraint;
57
+ if (constraint === "identifier_value_key")
58
+ return { created: false, reason: "identifier-taken" };
59
+ if (constraint === "contact_verified")
60
+ return { created: false, reason: "contact-taken" };
61
+ throw error;
62
+ }
63
+ return { created: true, accountId, contactId };
64
+ }
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/person-account/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAE/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAE3E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAiC,EACjC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAwB;IAE/E,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IACpE,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAChG,MAAM,EAAE,IAA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AAE,MAAM,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAC5G,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;QACpD,IAAI,UAAU,KAAK,sBAAsB;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;QACjG,IAAI,UAAU,KAAK,kBAAkB;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;QAC1F,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACjD,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Contact } from "@sharadox/account-web-library/contact-kind/type";
2
+ export interface PersonAccountRequest {
3
+ /** What the account shows (`checkAccountName`). */
4
+ name: string;
5
+ /** Without the `@` (`checkIdentifier`). */
6
+ identifier: string;
7
+ /** Already proved by a one-time code: it is stored verified. */
8
+ contact: Contact;
9
+ /** The person's language, for notices (`pt-PT`); English without it. */
10
+ language?: string;
11
+ /** Milliseconds since 1970 (now by default). */
12
+ now?: number;
13
+ }
14
+ export type PersonAccountResult = {
15
+ created: true;
16
+ accountId: string;
17
+ contactId: string;
18
+ } | {
19
+ created: false;
20
+ reason: "name-invalid" | "identifier-invalid" | "identifier-taken" | "contact-taken";
21
+ };
22
+ //# sourceMappingURL=type.d.ts.map