@jini-ai/user-management 0.7.3-next.2 → 0.7.4

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 (380) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +55 -2
  3. package/dist/admin/adapters/memory.js +4 -4
  4. package/dist/admin-http/auth/auth-request.d.ts +112 -0
  5. package/dist/admin-http/auth/auth-request.js +32 -0
  6. package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
  7. package/dist/admin-http/auth/boot-redemption.js +17 -0
  8. package/dist/admin-http/auth/boot-session.d.ts +30 -0
  9. package/dist/admin-http/auth/boot-session.js +40 -0
  10. package/dist/admin-http/auth/current-user.d.ts +28 -0
  11. package/dist/admin-http/auth/current-user.js +34 -0
  12. package/dist/admin-http/auth/index.d.ts +17 -0
  13. package/dist/admin-http/auth/index.js +9 -0
  14. package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
  15. package/dist/admin-http/auth/local-boot-session.js +30 -0
  16. package/dist/admin-http/auth/logout.d.ts +10 -0
  17. package/dist/admin-http/auth/logout.js +17 -0
  18. package/dist/admin-http/auth/mfa-login.d.ts +30 -0
  19. package/dist/admin-http/auth/mfa-login.js +43 -0
  20. package/dist/admin-http/auth/password-login.d.ts +35 -0
  21. package/dist/admin-http/auth/password-login.js +52 -0
  22. package/dist/admin-http/auth/password-status.d.ts +34 -0
  23. package/dist/admin-http/auth/password-status.js +42 -0
  24. package/dist/admin-http/http/api-keys.d.ts +45 -0
  25. package/dist/admin-http/http/api-keys.js +28 -0
  26. package/dist/admin-http/http/users.d.ts +71 -0
  27. package/dist/admin-http/http/users.js +42 -0
  28. package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
  29. package/dist/admin-http/owner/mfa-deps.js +26 -0
  30. package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
  31. package/dist/admin-http/owner/mfa-routes.js +105 -0
  32. package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
  33. package/dist/admin-http/owner/passkey-admission.js +23 -0
  34. package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
  35. package/dist/admin-http/owner/passkey-route-deps.js +33 -0
  36. package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
  37. package/dist/admin-http/owner/passkey-routes.js +98 -0
  38. package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
  39. package/dist/admin-http/owner/recovery-routes.js +112 -0
  40. package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
  41. package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
  42. package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
  43. package/dist/admin-http/routes/api-keys/issue.js +38 -0
  44. package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
  45. package/dist/admin-http/routes/api-keys/revoke.js +31 -0
  46. package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
  47. package/dist/admin-http/routes/api-keys/shared.js +38 -0
  48. package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
  49. package/dist/admin-http/routes/users/access-shared.js +85 -0
  50. package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
  51. package/dist/admin-http/routes/users/assign-role.js +30 -0
  52. package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
  53. package/dist/admin-http/routes/users/attach-policy.js +31 -0
  54. package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
  55. package/dist/admin-http/routes/users/create-policy.js +28 -0
  56. package/dist/admin-http/routes/users/create-role.d.ts +15 -0
  57. package/dist/admin-http/routes/users/create-role.js +21 -0
  58. package/dist/admin-http/routes/users/create.d.ts +32 -0
  59. package/dist/admin-http/routes/users/create.js +67 -0
  60. package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
  61. package/dist/admin-http/routes/users/delete-policy.js +24 -0
  62. package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
  63. package/dist/admin-http/routes/users/delete-role.js +24 -0
  64. package/dist/admin-http/routes/users/delete.d.ts +35 -0
  65. package/dist/admin-http/routes/users/delete.js +35 -0
  66. package/dist/admin-http/routes/users/disable.d.ts +31 -0
  67. package/dist/admin-http/routes/users/disable.js +38 -0
  68. package/dist/admin-http/routes/users/enable.d.ts +32 -0
  69. package/dist/admin-http/routes/users/enable.js +45 -0
  70. package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
  71. package/dist/admin-http/routes/users/list-policies.js +20 -0
  72. package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
  73. package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
  74. package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
  75. package/dist/admin-http/routes/users/list-roles.js +20 -0
  76. package/dist/admin-http/routes/users/list.d.ts +40 -0
  77. package/dist/admin-http/routes/users/list.js +82 -0
  78. package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
  79. package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
  80. package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
  81. package/dist/admin-http/routes/users/reset-password.js +52 -0
  82. package/dist/admin-http/routes/users/shared.d.ts +124 -0
  83. package/dist/admin-http/routes/users/shared.js +93 -0
  84. package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
  85. package/dist/admin-http/routes/users/update-policy.js +30 -0
  86. package/dist/admin-http/routes/users/update-role.d.ts +23 -0
  87. package/dist/admin-http/routes/users/update-role.js +29 -0
  88. package/dist/admin-http/routes/users/update.d.ts +35 -0
  89. package/dist/admin-http/routes/users/update.js +78 -0
  90. package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
  91. package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
  92. package/dist/core/ports.d.ts +22 -3
  93. package/dist/core/types.d.ts +17 -5
  94. package/dist/core/types.js +12 -0
  95. package/dist/identity/api-key-secret.d.ts +68 -0
  96. package/dist/identity/api-key-secret.js +229 -0
  97. package/dist/identity/api-key-service.d.ts +144 -0
  98. package/dist/identity/api-key-service.js +389 -0
  99. package/dist/identity/api-key-types.d.ts +79 -0
  100. package/dist/identity/api-key-types.js +2 -0
  101. package/dist/identity/boot-session-token.d.ts +18 -0
  102. package/dist/identity/boot-session-token.js +92 -0
  103. package/dist/identity/builtin-role-grants.d.ts +120 -0
  104. package/dist/identity/builtin-role-grants.js +88 -0
  105. package/dist/identity/delete-user-service.d.ts +195 -0
  106. package/dist/identity/delete-user-service.js +275 -0
  107. package/dist/identity/owner-reset-env.d.ts +37 -0
  108. package/dist/identity/owner-reset-env.js +38 -0
  109. package/dist/identity/permission-grants.d.ts +31 -0
  110. package/dist/identity/permission-grants.js +12 -0
  111. package/dist/identity/permission-list-tool.d.ts +35 -0
  112. package/dist/identity/permission-list-tool.js +47 -0
  113. package/dist/identity/repo.authentication.d.ts +57 -0
  114. package/dist/identity/repo.authentication.js +153 -0
  115. package/dist/identity/repo.authorization.d.ts +82 -0
  116. package/dist/identity/repo.authorization.js +203 -0
  117. package/dist/identity/repo.d.ts +87 -0
  118. package/dist/identity/repo.js +167 -0
  119. package/dist/identity/repo.memory.d.ts +31 -0
  120. package/dist/identity/repo.memory.js +37 -0
  121. package/dist/identity/role-manage-permission.d.ts +34 -0
  122. package/dist/identity/role-manage-permission.js +39 -0
  123. package/dist/identity/site-key-permission.d.ts +66 -0
  124. package/dist/identity/site-key-permission.js +92 -0
  125. package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
  126. package/dist/identity/sql/kernel-user-purge.js +34 -0
  127. package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
  128. package/dist/identity/sql/kernel-user-trash-store.js +41 -0
  129. package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
  130. package/dist/identity/sql/user-trash-adapter.js +124 -0
  131. package/dist/identity/tool-registrations.d.ts +100 -0
  132. package/dist/identity/tool-registrations.js +257 -0
  133. package/dist/identity/user-manage-permission.d.ts +8 -0
  134. package/dist/identity/user-manage-permission.js +8 -0
  135. package/dist/identity/user-purge-types.d.ts +85 -0
  136. package/dist/identity/user-purge-types.js +17 -0
  137. package/dist/identity/user-purge.d.ts +69 -0
  138. package/dist/identity/user-purge.js +46 -0
  139. package/dist/identity/username-change-ports.d.ts +15 -0
  140. package/dist/identity/username-change-ports.js +22 -0
  141. package/dist/mail/site/capture-clear.d.ts +58 -0
  142. package/dist/mail/site/capture-clear.js +21 -0
  143. package/dist/mail/status/agent-tools.d.ts +65 -0
  144. package/dist/mail/status/agent-tools.js +22 -0
  145. package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
  146. package/dist/mail/status/delivery-agent-tools.js +63 -0
  147. package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
  148. package/dist/mail/status/delivery-tool-registrations.js +110 -0
  149. package/dist/mail/status/domain-deps.d.ts +25 -0
  150. package/dist/mail/status/domain-deps.js +23 -0
  151. package/dist/mail/status/permissions.d.ts +43 -0
  152. package/dist/mail/status/permissions.js +45 -0
  153. package/dist/mail/status/provider-agent-tools.d.ts +38 -0
  154. package/dist/mail/status/provider-agent-tools.js +17 -0
  155. package/dist/mail/status/provider-operations.d.ts +166 -0
  156. package/dist/mail/status/provider-operations.js +121 -0
  157. package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
  158. package/dist/mail/status/provider-tool-registrations.js +106 -0
  159. package/dist/mail/status/tool-registrations.d.ts +152 -0
  160. package/dist/mail/status/tool-registrations.js +112 -0
  161. package/dist/member-login/credentials.d.ts +40 -0
  162. package/dist/member-login/credentials.js +26 -0
  163. package/dist/member-login/link-service.d.ts +66 -0
  164. package/dist/member-login/link-service.js +141 -0
  165. package/dist/member-login/oidc-login.d.ts +132 -0
  166. package/dist/member-login/oidc-login.js +206 -0
  167. package/dist/member-login/oidc-request.d.ts +80 -0
  168. package/dist/member-login/oidc-request.js +86 -0
  169. package/dist/member-login/providers.d.ts +79 -0
  170. package/dist/member-login/providers.js +41 -0
  171. package/dist/member-login/ready-providers.d.ts +17 -0
  172. package/dist/member-login/ready-providers.js +11 -0
  173. package/dist/member-login/unlink-identity.d.ts +26 -0
  174. package/dist/member-login/unlink-identity.js +59 -0
  175. package/dist/members/access-resolver.d.ts +107 -0
  176. package/dist/members/access-resolver.js +231 -0
  177. package/dist/members/agent-tools.d.ts +14 -0
  178. package/dist/members/agent-tools.js +139 -0
  179. package/dist/members/auth-mail.d.ts +27 -0
  180. package/dist/members/auth-mail.js +21 -0
  181. package/dist/members/capability-card.d.ts +18 -0
  182. package/dist/members/capability-card.js +27 -0
  183. package/dist/members/consent-service.d.ts +115 -0
  184. package/dist/members/consent-service.js +179 -0
  185. package/dist/members/member-admin-writes.d.ts +73 -0
  186. package/dist/members/member-admin-writes.js +149 -0
  187. package/dist/members/member-challenge-request.d.ts +59 -0
  188. package/dist/members/member-challenge-request.js +145 -0
  189. package/dist/members/member-challenge.d.ts +37 -0
  190. package/dist/members/member-challenge.js +84 -0
  191. package/dist/members/member-credentials.d.ts +35 -0
  192. package/dist/members/member-credentials.js +57 -0
  193. package/dist/members/member-sign-in.d.ts +44 -0
  194. package/dist/members/member-sign-in.js +130 -0
  195. package/dist/members/member-validation.d.ts +5 -0
  196. package/dist/members/member-validation.js +13 -0
  197. package/dist/members/password-auth.d.ts +55 -0
  198. package/dist/members/password-auth.js +177 -0
  199. package/dist/members/ports.d.ts +455 -0
  200. package/dist/members/ports.js +21 -0
  201. package/dist/members/public-member-auth-response.d.ts +68 -0
  202. package/dist/members/public-member-auth-response.js +45 -0
  203. package/dist/members/public-member-response.d.ts +25 -0
  204. package/dist/members/public-member-response.js +15 -0
  205. package/dist/members/repo.d.ts +199 -0
  206. package/dist/members/repo.js +324 -0
  207. package/dist/members/repo.memory.d.ts +276 -0
  208. package/dist/members/repo.memory.js +395 -0
  209. package/dist/members/repo.rows.d.ts +153 -0
  210. package/dist/members/repo.rows.js +250 -0
  211. package/dist/members/repo.sessions.d.ts +80 -0
  212. package/dist/members/repo.sessions.js +166 -0
  213. package/dist/members/repo.sql.d.ts +9 -0
  214. package/dist/members/repo.sql.js +11 -0
  215. package/dist/members/subscriber-directory.d.ts +85 -0
  216. package/dist/members/subscriber-directory.js +70 -0
  217. package/dist/members/tool-registrations.d.ts +143 -0
  218. package/dist/members/tool-registrations.js +247 -0
  219. package/dist/members/trash-member.d.ts +24 -0
  220. package/dist/members/trash-member.js +24 -0
  221. package/dist/members/types.d.ts +321 -0
  222. package/dist/members/types.js +34 -0
  223. package/dist/members/write-service.d.ts +17 -0
  224. package/dist/members/write-service.js +15 -0
  225. package/dist/newsletter/agent-tools.d.ts +20 -0
  226. package/dist/newsletter/agent-tools.js +236 -0
  227. package/dist/newsletter/campaign-write-service.d.ts +92 -0
  228. package/dist/newsletter/campaign-write-service.js +190 -0
  229. package/dist/newsletter/campaign.d.ts +53 -0
  230. package/dist/newsletter/campaign.js +95 -0
  231. package/dist/newsletter/confirmation.d.ts +75 -0
  232. package/dist/newsletter/confirmation.js +142 -0
  233. package/dist/newsletter/data-module-manifest.d.ts +68 -0
  234. package/dist/newsletter/data-module-manifest.js +126 -0
  235. package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
  236. package/dist/newsletter/delivery/tool-registrations.js +229 -0
  237. package/dist/newsletter/errors.d.ts +93 -0
  238. package/dist/newsletter/errors.js +93 -0
  239. package/dist/newsletter/hooks.d.ts +59 -0
  240. package/dist/newsletter/hooks.js +49 -0
  241. package/dist/newsletter/http-error-responses.d.ts +17 -0
  242. package/dist/newsletter/http-error-responses.js +96 -0
  243. package/dist/newsletter/launch-gate.d.ts +62 -0
  244. package/dist/newsletter/launch-gate.js +29 -0
  245. package/dist/newsletter/lists.d.ts +60 -0
  246. package/dist/newsletter/lists.js +83 -0
  247. package/dist/newsletter/ports.d.ts +283 -0
  248. package/dist/newsletter/ports.js +2 -0
  249. package/dist/newsletter/repo-sends.d.ts +82 -0
  250. package/dist/newsletter/repo-sends.js +178 -0
  251. package/dist/newsletter/repo-subscribers.d.ts +83 -0
  252. package/dist/newsletter/repo-subscribers.js +215 -0
  253. package/dist/newsletter/repo.d.ts +61 -0
  254. package/dist/newsletter/repo.js +147 -0
  255. package/dist/newsletter/repo.memory.d.ts +202 -0
  256. package/dist/newsletter/repo.memory.js +260 -0
  257. package/dist/newsletter/repo.rows.d.ts +221 -0
  258. package/dist/newsletter/repo.rows.js +260 -0
  259. package/dist/newsletter/save-guard.d.ts +32 -0
  260. package/dist/newsletter/save-guard.js +27 -0
  261. package/dist/newsletter/send-pipeline.d.ts +240 -0
  262. package/dist/newsletter/send-pipeline.js +514 -0
  263. package/dist/newsletter/subscriptions.d.ts +87 -0
  264. package/dist/newsletter/subscriptions.js +119 -0
  265. package/dist/newsletter/tool-registrations.d.ts +89 -0
  266. package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
  267. package/dist/newsletter/tool-registrations.deps.js +9 -0
  268. package/dist/newsletter/tool-registrations.js +133 -0
  269. package/dist/newsletter/tool-registrations.read.d.ts +76 -0
  270. package/dist/newsletter/tool-registrations.read.js +140 -0
  271. package/dist/newsletter/tool-registrations.write.d.ts +54 -0
  272. package/dist/newsletter/tool-registrations.write.js +229 -0
  273. package/dist/newsletter/types.d.ts +279 -0
  274. package/dist/newsletter/types.js +23 -0
  275. package/dist/newsletter/unsubscribe.d.ts +41 -0
  276. package/dist/newsletter/unsubscribe.js +100 -0
  277. package/dist/project-keys/attached-vault.d.ts +23 -0
  278. package/dist/project-keys/attached-vault.js +65 -0
  279. package/dist/project-keys/create-vault.d.ts +17 -0
  280. package/dist/project-keys/create-vault.js +29 -0
  281. package/dist/project-keys/service.d.ts +133 -0
  282. package/dist/project-keys/service.js +128 -0
  283. package/dist/project-keys/site-references.d.ts +30 -0
  284. package/dist/project-keys/site-references.js +63 -0
  285. package/dist/project-keys/site-sealer.d.ts +28 -0
  286. package/dist/project-keys/site-sealer.js +64 -0
  287. package/dist/project-keys/sql/attachments.d.ts +33 -0
  288. package/dist/project-keys/sql/attachments.js +55 -0
  289. package/dist/project-keys/tools.d.ts +86 -0
  290. package/dist/project-keys/tools.js +66 -0
  291. package/dist/public-http/routes/mail/feedback.d.ts +44 -0
  292. package/dist/public-http/routes/mail/feedback.js +17 -0
  293. package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
  294. package/dist/public-http/routes/newsletter/confirm.js +33 -0
  295. package/dist/public-http/routes/newsletter/page.d.ts +29 -0
  296. package/dist/public-http/routes/newsletter/page.js +34 -0
  297. package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
  298. package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
  299. package/dist/react/auth/Passkeys.d.ts +2 -34
  300. package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
  301. package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
  302. package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
  303. package/dist/react/auth/RecoveryCodesCard.js +56 -0
  304. package/dist/react/auth/TotpSettings.d.ts +2 -23
  305. package/dist/react/auth/local-owner-signin.d.ts +40 -0
  306. package/dist/react/auth/local-owner-signin.js +25 -0
  307. package/dist/react/auth/owner-mfa-api.d.ts +10 -0
  308. package/dist/react/auth/owner-mfa-api.js +17 -0
  309. package/dist/react/auth/owner-passkey-api.d.ts +11 -0
  310. package/dist/react/auth/owner-passkey-api.js +17 -0
  311. package/dist/react/auth/owner-recovery-api.d.ts +51 -0
  312. package/dist/react/auth/owner-recovery-api.js +29 -0
  313. package/dist/react/auth/owner-request.d.ts +7 -0
  314. package/dist/react/auth/owner-request.js +2 -0
  315. package/dist/react/index.d.ts +10 -0
  316. package/dist/react/index.js +6 -0
  317. package/dist/react/mail/Email.d.ts +20 -0
  318. package/dist/react/mail/Email.js +143 -0
  319. package/dist/react/mail/EmailProviderTab.d.ts +34 -0
  320. package/dist/react/mail/EmailProviderTab.js +132 -0
  321. package/dist/react/mail/EmailSegments.d.ts +24 -0
  322. package/dist/react/mail/EmailSegments.js +15 -0
  323. package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
  324. package/dist/react/mail/EmailTemplateEditor.js +116 -0
  325. package/dist/react/mail/email-view.types.d.ts +236 -0
  326. package/dist/react/mail/email-view.types.js +2 -0
  327. package/dist/react/members/Members.d.ts +5 -3
  328. package/dist/react/members/Members.js +3 -3
  329. package/dist/react/members/api/members-api.d.ts +37 -0
  330. package/dist/react/members/api/members-api.js +16 -0
  331. package/dist/react/members/hooks/use-members.hooks.js +2 -1
  332. package/dist/react/members/members-i18n.d.ts +23 -0
  333. package/dist/react/members/members-i18n.js +25 -0
  334. package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
  335. package/dist/react/members/members-i18n.locales-a.js +294 -0
  336. package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
  337. package/dist/react/members/members-i18n.locales-b.js +265 -0
  338. package/dist/react/models.d.ts +1 -49
  339. package/dist/react/ports.d.ts +3 -143
  340. package/dist/react/roles/api/roles-api.d.ts +74 -0
  341. package/dist/react/roles/api/roles-api.js +22 -0
  342. package/dist/react/testing.js +18 -9
  343. package/dist/react/users/UsersPanel.d.ts +30 -0
  344. package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
  345. package/dist/react/users/UsersPanel.hooks.js +9 -0
  346. package/dist/react/users/UsersPanel.js +9 -0
  347. package/dist/react/users/api/users-api.d.ts +65 -0
  348. package/dist/react/users/api/users-api.js +46 -0
  349. package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
  350. package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
  351. package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
  352. package/dist/react/users/password-reset-notice.d.ts +8 -0
  353. package/dist/react/users/password-reset-notice.js +36 -0
  354. package/dist/server/admin-crud-service.d.ts +4 -10
  355. package/dist/server/admin-crud-service.js +20 -6
  356. package/dist/server/agent-tool-registrations.js +26 -7
  357. package/dist/server/agent-tools.js +22 -7
  358. package/dist/server/auth-challenge.d.ts +1 -1
  359. package/dist/server/auth-service.js +2 -1
  360. package/dist/server/grant-service.d.ts +1 -0
  361. package/dist/server/grant-service.js +7 -4
  362. package/dist/server/mfa/passkey-service.d.ts +2 -2
  363. package/dist/server/mfa/passkey-service.js +1 -1
  364. package/dist/server/mfa/service.js +6 -4
  365. package/dist/server/repo.memory.d.ts +30 -2
  366. package/dist/server/repo.memory.js +58 -4
  367. package/dist/server/seed.js +3 -3
  368. package/dist/server/sql/assignments.d.ts +90 -0
  369. package/dist/server/sql/assignments.js +128 -0
  370. package/dist/server/sql/index.d.ts +6 -0
  371. package/dist/server/sql/index.js +5 -0
  372. package/dist/server/sql/kernel.d.ts +9 -0
  373. package/dist/server/sql/kernel.js +2 -0
  374. package/dist/server/sql/mfa.d.ts +36 -0
  375. package/dist/server/sql/mfa.js +51 -0
  376. package/dist/server/sql/passkeys.d.ts +25 -0
  377. package/dist/server/sql/passkeys.js +33 -0
  378. package/dist/server/sql/recovery-codes.d.ts +22 -0
  379. package/dist/server/sql/recovery-codes.js +32 -0
  380. package/package.json +909 -11
@@ -178,7 +178,7 @@ async function ensureBuiltinRole(required) {
178
178
  const existing = await deps.repos.roles.findByName({ workspaceId, name });
179
179
  if (!existing) {
180
180
  const roleId = deps.idGen.newId();
181
- await deps.repos.roles.save({ id: roleId, workspaceId, name, isBuiltin: true });
181
+ await deps.repos.roles.save({ version: 1, id: roleId, workspaceId, name, isBuiltin: true });
182
182
  return roleId;
183
183
  }
184
184
  if (!existing.isBuiltin) {
@@ -194,7 +194,7 @@ async function ensureBuiltinPolicy(required) {
194
194
  const existing = await deps.repos.policies.findByName({ workspaceId, name: policyName });
195
195
  if (!existing) {
196
196
  const policyId = deps.idGen.newId();
197
- await deps.repos.policies.save({
197
+ await deps.repos.policies.save({ version: 1,
198
198
  id: policyId,
199
199
  workspaceId,
200
200
  name: policyName,
@@ -375,7 +375,7 @@ async function createOwner(required) {
375
375
  status: "active",
376
376
  createdAt: nowIso,
377
377
  });
378
- await deps.repos.users.save({
378
+ await deps.repos.users.save({ version: 1,
379
379
  principalId: ownerPrincipalId,
380
380
  workspaceId,
381
381
  username: ownerUsername,
@@ -0,0 +1,90 @@
1
+ import type { PrincipalPolicyRecord, PrincipalPolicyRepoPort, PrincipalRoleRecord, PrincipalRoleRepoPort, IdentityTransactionPort, RolePolicyRecord, RolePolicyRepoPort } from "../../core/index.js";
2
+ import type { SqlIdentityKernel } from "./kernel.js";
3
+ /**
4
+ * @file The three identity assignment join repositories (role->policy, principal->role, principal->policy) as
5
+ * one Kysely query body for every dialect. Each `save` is an upsert on `id` inside the injected identity
6
+ * transaction, so the workspace lock also covers it and a grant writer cannot insert a phantom reference
7
+ * while a guarded mutation is deciding. Table names are host-owned.
8
+ */
9
+ /** Stored column shape of the host's role->policy join table. */
10
+ export interface RolePoliciesTable {
11
+ id: string;
12
+ workspace_id: string;
13
+ role_id: string;
14
+ policy_id: string;
15
+ }
16
+ /** Stored column shape of the host's principal->role join table. */
17
+ export interface PrincipalRolesTable {
18
+ id: string;
19
+ workspace_id: string;
20
+ principal_id: string;
21
+ role_id: string;
22
+ }
23
+ /** Stored column shape of the host's principal->policy join table. */
24
+ export interface PrincipalPoliciesTable {
25
+ id: string;
26
+ workspace_id: string;
27
+ principal_id: string;
28
+ policy_id: string;
29
+ }
30
+ /** Host-owned table names. */
31
+ export interface RolePolicyTables {
32
+ rolePolicies: string;
33
+ }
34
+ export interface PrincipalRoleTables {
35
+ principalRoles: string;
36
+ }
37
+ export interface PrincipalPolicyTables {
38
+ principalPolicies: string;
39
+ }
40
+ export interface AssignmentSqlRequired<Tables> {
41
+ kernel: SqlIdentityKernel;
42
+ transactions: IdentityTransactionPort;
43
+ tables: Tables;
44
+ }
45
+ export declare class SqlRolePolicyRepo implements RolePolicyRepoPort {
46
+ protected readonly kernel: SqlIdentityKernel;
47
+ protected readonly transactions: IdentityTransactionPort;
48
+ protected readonly tables: RolePolicyTables;
49
+ constructor({ kernel, transactions, tables }: AssignmentSqlRequired<RolePolicyTables>, _optional?: Record<string, never>);
50
+ listByRoleId(required: {
51
+ workspaceId: string;
52
+ roleId: string;
53
+ }): Promise<RolePolicyRecord[]>;
54
+ listByPolicyId(required: {
55
+ workspaceId: string;
56
+ policyId: string;
57
+ }): Promise<RolePolicyRecord[]>;
58
+ save(record: RolePolicyRecord): Promise<void>;
59
+ }
60
+ export declare class SqlPrincipalRoleRepo implements PrincipalRoleRepoPort {
61
+ protected readonly kernel: SqlIdentityKernel;
62
+ protected readonly transactions: IdentityTransactionPort;
63
+ protected readonly tables: PrincipalRoleTables;
64
+ constructor({ kernel, transactions, tables }: AssignmentSqlRequired<PrincipalRoleTables>, _optional?: Record<string, never>);
65
+ listByPrincipalId(required: {
66
+ workspaceId: string;
67
+ principalId: string;
68
+ }): Promise<PrincipalRoleRecord[]>;
69
+ listByRoleId(required: {
70
+ workspaceId: string;
71
+ roleId: string;
72
+ }): Promise<PrincipalRoleRecord[]>;
73
+ save(record: PrincipalRoleRecord): Promise<void>;
74
+ }
75
+ export declare class SqlPrincipalPolicyRepo implements PrincipalPolicyRepoPort {
76
+ protected readonly kernel: SqlIdentityKernel;
77
+ protected readonly transactions: IdentityTransactionPort;
78
+ protected readonly tables: PrincipalPolicyTables;
79
+ constructor({ kernel, transactions, tables }: AssignmentSqlRequired<PrincipalPolicyTables>, _optional?: Record<string, never>);
80
+ listByPrincipalId(required: {
81
+ workspaceId: string;
82
+ principalId: string;
83
+ }): Promise<PrincipalPolicyRecord[]>;
84
+ listByPolicyId(required: {
85
+ workspaceId: string;
86
+ policyId: string;
87
+ }): Promise<PrincipalPolicyRecord[]>;
88
+ save(record: PrincipalPolicyRecord): Promise<void>;
89
+ }
90
+ //# sourceMappingURL=assignments.d.ts.map
@@ -0,0 +1,128 @@
1
+ const rolePoliciesView = (db) => db.withTables();
2
+ const principalRolesView = (db) => db.withTables();
3
+ const principalPoliciesView = (db) => db.withTables();
4
+ function toRolePolicyRecord(row) {
5
+ return { id: row.id, workspaceId: row.workspace_id, roleId: row.role_id, policyId: row.policy_id };
6
+ }
7
+ export class SqlRolePolicyRepo {
8
+ kernel;
9
+ transactions;
10
+ tables;
11
+ constructor({ kernel, transactions, tables }, _optional = {}) {
12
+ this.kernel = kernel;
13
+ this.transactions = transactions;
14
+ this.tables = tables;
15
+ }
16
+ async listByRoleId(required) {
17
+ const rows = await this.kernel.run((db) => rolePoliciesView(db)
18
+ .selectFrom(this.tables.rolePolicies)
19
+ .selectAll()
20
+ .where("workspace_id", "=", required.workspaceId)
21
+ .where("role_id", "=", required.roleId)
22
+ .execute());
23
+ return rows.map(toRolePolicyRecord);
24
+ }
25
+ async listByPolicyId(required) {
26
+ const rows = await this.kernel.run((db) => rolePoliciesView(db)
27
+ .selectFrom(this.tables.rolePolicies)
28
+ .selectAll()
29
+ .where("workspace_id", "=", required.workspaceId)
30
+ .where("policy_id", "=", required.policyId)
31
+ .execute());
32
+ return rows.map(toRolePolicyRecord);
33
+ }
34
+ async save(record) {
35
+ const row = {
36
+ id: record.id,
37
+ workspace_id: record.workspaceId,
38
+ role_id: record.roleId,
39
+ policy_id: record.policyId,
40
+ };
41
+ await this.transactions.run({ workspaceId: record.workspaceId, execute: () => this.kernel.run((db) => rolePoliciesView(db).insertInto(this.tables.rolePolicies).values(row).onConflict((oc) => oc.column("id").doUpdateSet(row)).execute()) });
42
+ }
43
+ }
44
+ function toPrincipalRoleRecord(row) {
45
+ return { id: row.id, workspaceId: row.workspace_id, principalId: row.principal_id, roleId: row.role_id };
46
+ }
47
+ export class SqlPrincipalRoleRepo {
48
+ kernel;
49
+ transactions;
50
+ tables;
51
+ constructor({ kernel, transactions, tables }, _optional = {}) {
52
+ this.kernel = kernel;
53
+ this.transactions = transactions;
54
+ this.tables = tables;
55
+ }
56
+ async listByPrincipalId(required) {
57
+ const rows = await this.kernel.run((db) => principalRolesView(db)
58
+ .selectFrom(this.tables.principalRoles)
59
+ .selectAll()
60
+ .where("workspace_id", "=", required.workspaceId)
61
+ .where("principal_id", "=", required.principalId)
62
+ .execute());
63
+ return rows.map(toPrincipalRoleRecord);
64
+ }
65
+ async listByRoleId(required) {
66
+ const rows = await this.kernel.run((db) => principalRolesView(db)
67
+ .selectFrom(this.tables.principalRoles)
68
+ .selectAll()
69
+ .where("workspace_id", "=", required.workspaceId)
70
+ .where("role_id", "=", required.roleId)
71
+ .execute());
72
+ return rows.map(toPrincipalRoleRecord);
73
+ }
74
+ async save(record) {
75
+ const row = {
76
+ id: record.id,
77
+ workspace_id: record.workspaceId,
78
+ principal_id: record.principalId,
79
+ role_id: record.roleId,
80
+ };
81
+ await this.transactions.run({ workspaceId: record.workspaceId, execute: () => this.kernel.run((db) => principalRolesView(db).insertInto(this.tables.principalRoles).values(row).onConflict((oc) => oc.column("id").doUpdateSet(row)).execute()) });
82
+ }
83
+ }
84
+ function toPrincipalPolicyRecord(row) {
85
+ return { id: row.id, workspaceId: row.workspace_id, principalId: row.principal_id, policyId: row.policy_id };
86
+ }
87
+ export class SqlPrincipalPolicyRepo {
88
+ kernel;
89
+ transactions;
90
+ tables;
91
+ constructor({ kernel, transactions, tables }, _optional = {}) {
92
+ this.kernel = kernel;
93
+ this.transactions = transactions;
94
+ this.tables = tables;
95
+ }
96
+ async listByPrincipalId(required) {
97
+ const rows = await this.kernel.run((db) => principalPoliciesView(db)
98
+ .selectFrom(this.tables.principalPolicies)
99
+ .selectAll()
100
+ .where("workspace_id", "=", required.workspaceId)
101
+ .where("principal_id", "=", required.principalId)
102
+ .execute());
103
+ return rows.map(toPrincipalPolicyRecord);
104
+ }
105
+ async listByPolicyId(required) {
106
+ const rows = await this.kernel.run((db) => principalPoliciesView(db)
107
+ .selectFrom(this.tables.principalPolicies)
108
+ .selectAll()
109
+ .where("workspace_id", "=", required.workspaceId)
110
+ .where("policy_id", "=", required.policyId)
111
+ .execute());
112
+ return rows.map(toPrincipalPolicyRecord);
113
+ }
114
+ async save(record) {
115
+ const row = {
116
+ id: record.id,
117
+ workspace_id: record.workspaceId,
118
+ principal_id: record.principalId,
119
+ policy_id: record.policyId,
120
+ };
121
+ await this.transactions.run({ workspaceId: record.workspaceId, execute: () => this.kernel.run((db) => principalPoliciesView(db)
122
+ .insertInto(this.tables.principalPolicies)
123
+ .values(row)
124
+ .onConflict((oc) => oc.column("id").doUpdateSet(row))
125
+ .execute()) });
126
+ }
127
+ }
128
+ //# sourceMappingURL=assignments.js.map
@@ -0,0 +1,6 @@
1
+ export { createSqlRecoveryCodeStore, type RecoveryCodesTable, type RecoveryCodeTables } from "./recovery-codes.js";
2
+ export type { SqlIdentityKernel } from "./kernel.js";
3
+ export { createSqlPasskeyStore, type PasskeysTable, type PasskeyTables } from "./passkeys.js";
4
+ export { createSqlMfaStore, type MfaFactorsTable, type MfaPendingTable, type MfaTables } from "./mfa.js";
5
+ export { SqlPrincipalPolicyRepo, SqlPrincipalRoleRepo, SqlRolePolicyRepo, type AssignmentSqlRequired, type PrincipalPoliciesTable, type PrincipalPolicyTables, type PrincipalRolesTable, type PrincipalRoleTables, type RolePoliciesTable, type RolePolicyTables, } from "./assignments.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export { createSqlRecoveryCodeStore } from "./recovery-codes.js";
2
+ export { createSqlPasskeyStore } from "./passkeys.js";
3
+ export { createSqlMfaStore } from "./mfa.js";
4
+ export { SqlPrincipalPolicyRepo, SqlPrincipalRoleRepo, SqlRolePolicyRepo, } from "./assignments.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ import type { StorageKernel } from "@jini-ai/core/contracts/storage";
2
+ import type { Kysely } from "kysely";
3
+ /**
4
+ * @file The kernel shape every SQL identity store takes: the host's storage kernel typed without its schema.
5
+ * A store supplies each query's table view itself (`db.withTables<…>()`), so the host's table names stay
6
+ * host-owned (see each store's `tables` argument) and no product schema is named in this package.
7
+ */
8
+ export type SqlIdentityKernel = StorageKernel<Kysely<unknown>, unknown>;
9
+ //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kernel.js.map
@@ -0,0 +1,36 @@
1
+ import type { IdentityTransactionPort } from "../../core/ports.js";
2
+ import type { MfaStore } from "../mfa/ports.js";
3
+ import type { SqlIdentityKernel } from "./kernel.js";
4
+ /** Stored column shape of the host's owner MFA factor table; the table name itself is host-owned. */
5
+ export interface MfaFactorsTable {
6
+ workspace_id: string;
7
+ principal_id: string;
8
+ sealed_secret: string;
9
+ last_step: number;
10
+ }
11
+ /** Stored column shape of the host's pending MFA proof table; the table name itself is host-owned. */
12
+ export interface MfaPendingTable {
13
+ workspace_id: string;
14
+ principal_id: string;
15
+ purpose: string;
16
+ token_hash: string;
17
+ expires_at: number;
18
+ attempts: number;
19
+ sealed_secret: string | null;
20
+ }
21
+ /** Host-owned table names. `passkeys` is cleared together with the factor by `clear`. */
22
+ export interface MfaTables {
23
+ factors: string;
24
+ pending: string;
25
+ passkeys: string;
26
+ }
27
+ /** Store sealed owner factors and bounded pending proofs in the existing identity transaction.
28
+ * Errors propagate for rollback; no plaintext factor or bearer proof is persisted.
29
+ * @complexity Each method uses a fixed number of indexed queries and O(1) result space.
30
+ */
31
+ export declare function createSqlMfaStore({ kernel, transactions, tables }: {
32
+ kernel: SqlIdentityKernel;
33
+ transactions: IdentityTransactionPort;
34
+ tables: MfaTables;
35
+ }, _options?: Record<string, never>): MfaStore;
36
+ //# sourceMappingURL=mfa.d.ts.map
@@ -0,0 +1,51 @@
1
+ const factorsView = (db) => db.withTables();
2
+ const pendingView = (db) => db.withTables();
3
+ const passkeysView = (db) => db.withTables();
4
+ /** Store sealed owner factors and bounded pending proofs in the existing identity transaction.
5
+ * Errors propagate for rollback; no plaintext factor or bearer proof is persisted.
6
+ * @complexity Each method uses a fixed number of indexed queries and O(1) result space.
7
+ */
8
+ export function createSqlMfaStore({ kernel, transactions, tables }, _options = {}) {
9
+ const clearPending = scope => transactions.run({ workspaceId: scope.workspaceId,
10
+ execute: () => kernel.run(async (db) => {
11
+ await pendingView(db).deleteFrom(tables.pending).where("workspace_id", "=", scope.workspaceId)
12
+ .where("principal_id", "=", scope.principalId).execute();
13
+ }),
14
+ });
15
+ return {
16
+ clearPending,
17
+ factor: scope => transactions.run({ workspaceId: scope.workspaceId, execute: async () => {
18
+ const row = await kernel.run(db => factorsView(db).selectFrom(tables.factors).selectAll()
19
+ .where("workspace_id", "=", scope.workspaceId).where("principal_id", "=", scope.principalId).executeTakeFirst());
20
+ return row ? { ...scope, sealedSecret: row.sealed_secret, lastStep: Number(row.last_step) } : null;
21
+ } }),
22
+ saveFactor: factor => transactions.run({ workspaceId: factor.workspaceId, execute: () => kernel.run(async (db) => {
23
+ const values = { workspace_id: factor.workspaceId, principal_id: factor.principalId,
24
+ sealed_secret: factor.sealedSecret, last_step: factor.lastStep };
25
+ await factorsView(db).insertInto(tables.factors).values(values).onConflict(conflict => conflict.columns(["workspace_id", "principal_id"]).doUpdateSet(values)).execute();
26
+ }) }),
27
+ pending: input => transactions.run({ workspaceId: input.workspaceId, execute: async () => {
28
+ const row = await kernel.run(db => pendingView(db).selectFrom(tables.pending).selectAll()
29
+ .where("workspace_id", "=", input.workspaceId).where("token_hash", "=", input.tokenHash).executeTakeFirst());
30
+ if (!row)
31
+ return null;
32
+ return { workspaceId: row.workspace_id, principalId: row.principal_id, purpose: row.purpose,
33
+ tokenHash: row.token_hash, expiresAt: Number(row.expires_at), attempts: Number(row.attempts),
34
+ ...(row.sealed_secret === null ? {} : { sealedSecret: row.sealed_secret }) };
35
+ } }),
36
+ savePending: pending => transactions.run({ workspaceId: pending.workspaceId, execute: () => kernel.run(async (db) => {
37
+ const values = { workspace_id: pending.workspaceId, principal_id: pending.principalId, purpose: pending.purpose,
38
+ token_hash: pending.tokenHash, expires_at: pending.expiresAt, attempts: pending.attempts,
39
+ sealed_secret: pending.sealedSecret ?? null };
40
+ await pendingView(db).insertInto(tables.pending).values(values).onConflict(conflict => conflict.columns(["workspace_id", "principal_id", "purpose"]).doUpdateSet(values)).execute();
41
+ }) }),
42
+ clear: scope => transactions.run({ workspaceId: scope.workspaceId, execute: async () => {
43
+ await clearPending(scope);
44
+ await kernel.run(db => passkeysView(db).deleteFrom(tables.passkeys).where("workspace_id", "=", scope.workspaceId)
45
+ .where("principal_id", "=", scope.principalId).execute());
46
+ await kernel.run(db => factorsView(db).deleteFrom(tables.factors).where("workspace_id", "=", scope.workspaceId)
47
+ .where("principal_id", "=", scope.principalId).execute());
48
+ } }),
49
+ };
50
+ }
51
+ //# sourceMappingURL=mfa.js.map
@@ -0,0 +1,25 @@
1
+ import type { IdentityTransactionPort } from "../../core/ports.js";
2
+ import type { PasskeyStore } from "../mfa/passkey-ports.js";
3
+ import type { SqlIdentityKernel } from "./kernel.js";
4
+ /** Stored column shape of the host's owner passkey table; the table name itself is host-owned. */
5
+ export interface PasskeysTable {
6
+ workspace_id: string;
7
+ principal_id: string;
8
+ credential_id: string;
9
+ public_key: string;
10
+ counter: number;
11
+ rp_id: string;
12
+ }
13
+ /** Host-owned table names. */
14
+ export interface PasskeyTables {
15
+ passkeys: string;
16
+ }
17
+ /** Public keys/counters only. Every query joins the identity lock and rollback boundary.
18
+ * @complexity One indexed query per method, list bounded to six rows (five-key cap plus overflow detection).
19
+ */
20
+ export declare function createSqlPasskeyStore({ kernel, transactions, tables }: {
21
+ kernel: SqlIdentityKernel;
22
+ transactions: IdentityTransactionPort;
23
+ tables: PasskeyTables;
24
+ }, _options?: Record<string, never>): PasskeyStore;
25
+ //# sourceMappingURL=passkeys.d.ts.map
@@ -0,0 +1,33 @@
1
+ const view = (db) => db.withTables();
2
+ /** Public keys/counters only. Every query joins the identity lock and rollback boundary.
3
+ * @complexity One indexed query per method, list bounded to six rows (five-key cap plus overflow detection).
4
+ */
5
+ export function createSqlPasskeyStore({ kernel, transactions, tables }, _options = {}) {
6
+ const qualified = (column) => `${tables.passkeys}.${column}`;
7
+ return {
8
+ list: scope => transactions.run({ workspaceId: scope.workspaceId, execute: () => kernel.run(async (db) => {
9
+ const rows = await view(db).selectFrom(tables.passkeys).selectAll().where("workspace_id", "=", scope.workspaceId)
10
+ .where("principal_id", "=", scope.principalId).orderBy("credential_id").limit(6).execute();
11
+ return rows.map(r => ({ workspaceId: r.workspace_id, principalId: r.principal_id, id: r.credential_id,
12
+ publicKey: r.public_key, counter: Number(r.counter), rpId: r.rp_id }));
13
+ }) }),
14
+ save: credential => transactions.run({ workspaceId: credential.workspaceId, execute: () => kernel.run(async (db) => {
15
+ const result = await view(db).insertInto(tables.passkeys).values({ workspace_id: credential.workspaceId,
16
+ principal_id: credential.principalId, credential_id: credential.id, public_key: credential.publicKey,
17
+ counter: credential.counter, rp_id: credential.rpId }).onConflict(c => c.columns(["workspace_id", "credential_id"])
18
+ .doUpdateSet({ counter: credential.counter }).where(qualified("principal_id"), "=", credential.principalId)
19
+ .where(qualified("public_key"), "=", credential.publicKey).where(qualified("rp_id"), "=", credential.rpId))
20
+ .executeTakeFirst();
21
+ if (result.numInsertedOrUpdatedRows === 0n)
22
+ throw new Error("Passkey credential ownership conflict");
23
+ }) }),
24
+ remove: input => transactions.run({ workspaceId: input.workspaceId, execute: () => kernel.run(async (db) => {
25
+ await view(db).deleteFrom(tables.passkeys).where("workspace_id", "=", input.workspaceId)
26
+ .where("principal_id", "=", input.principalId).where("credential_id", "=", input.id).execute();
27
+ }) }),
28
+ clear: scope => transactions.run({ workspaceId: scope.workspaceId, execute: () => kernel.run(async (db) => {
29
+ await view(db).deleteFrom(tables.passkeys).where("workspace_id", "=", scope.workspaceId).where("principal_id", "=", scope.principalId).execute();
30
+ }) }),
31
+ };
32
+ }
33
+ //# sourceMappingURL=passkeys.js.map
@@ -0,0 +1,22 @@
1
+ import type { RecoveryCodeStore } from "../recovery-codes.js";
2
+ import type { SqlIdentityKernel } from "./kernel.js";
3
+ /** Stored column shape of the host's owner recovery-code table; the table name itself is host-owned. */
4
+ export interface RecoveryCodesTable {
5
+ workspace_id: string;
6
+ principal_id: string;
7
+ code_hash: string;
8
+ }
9
+ /** Host-owned table names. */
10
+ export interface RecoveryCodeTables {
11
+ recoveryCodes: string;
12
+ }
13
+ /** Persist only digests, using the same kernel/transaction as the password and session repositories.
14
+ * @returns A workspace/owner-scoped store; errors propagate to the identity transaction for rollback.
15
+ * @complexity Each replace writes at most ten rows in one insert after one scoped delete. Contains
16
+ * is one primary-key lookup returning at most one digest; clear deletes at most ten scoped rows.
17
+ */
18
+ export declare function createSqlRecoveryCodeStore({ kernel, tables }: {
19
+ kernel: SqlIdentityKernel;
20
+ tables: RecoveryCodeTables;
21
+ }, _options?: Record<string, never>): RecoveryCodeStore;
22
+ //# sourceMappingURL=recovery-codes.d.ts.map
@@ -0,0 +1,32 @@
1
+ /** Persist only digests, using the same kernel/transaction as the password and session repositories.
2
+ * @returns A workspace/owner-scoped store; errors propagate to the identity transaction for rollback.
3
+ * @complexity Each replace writes at most ten rows in one insert after one scoped delete. Contains
4
+ * is one primary-key lookup returning at most one digest; clear deletes at most ten scoped rows.
5
+ */
6
+ export function createSqlRecoveryCodeStore({ kernel, tables }, _options = {}) {
7
+ const view = (db) => db.withTables();
8
+ const clear = scope => kernel.run(async (db) => {
9
+ await view(db).deleteFrom(tables.recoveryCodes).where("workspace_id", "=", scope.workspaceId)
10
+ .where("principal_id", "=", scope.principalId).execute();
11
+ });
12
+ return {
13
+ clear,
14
+ async replace(input) {
15
+ if (input.hashes.length > 10)
16
+ throw new RangeError("Recovery codes could not be saved. Generate a new set of ten codes. Details: recovery-code-limit");
17
+ await clear(input);
18
+ if (input.hashes.length === 0)
19
+ return;
20
+ await kernel.run(db => view(db).insertInto(tables.recoveryCodes).values(input.hashes.map(hash => ({
21
+ workspace_id: input.workspaceId, principal_id: input.principalId, code_hash: hash,
22
+ }))).execute());
23
+ },
24
+ async contains(input) {
25
+ const row = await kernel.run(db => view(db).selectFrom(tables.recoveryCodes).select("code_hash")
26
+ .where("workspace_id", "=", input.workspaceId).where("principal_id", "=", input.principalId)
27
+ .where("code_hash", "=", input.hash).limit(1).executeTakeFirst());
28
+ return row !== undefined;
29
+ },
30
+ };
31
+ }
32
+ //# sourceMappingURL=recovery-codes.js.map