@yielded/auth-persistence 0.1.0-beta.7

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 (526) hide show
  1. package/README.md +21 -0
  2. package/dist/Drizzle.d.mts +28 -0
  3. package/dist/Drizzle.mjs +28 -0
  4. package/dist/DrizzleD1.d.mts +963 -0
  5. package/dist/DrizzleD1.mjs +29 -0
  6. package/dist/DrizzleD1.mjs.map +1 -0
  7. package/dist/DrizzleLibsql.d.mts +2284 -0
  8. package/dist/DrizzleLibsql.mjs +92 -0
  9. package/dist/DrizzleLibsql.mjs.map +1 -0
  10. package/dist/DrizzleMysql2.d.mts +1820 -0
  11. package/dist/DrizzleMysql2.mjs +55 -0
  12. package/dist/DrizzleMysql2.mjs.map +1 -0
  13. package/dist/DrizzlePglite.d.mts +1826 -0
  14. package/dist/DrizzlePglite.mjs +53 -0
  15. package/dist/DrizzlePglite.mjs.map +1 -0
  16. package/dist/DrizzlePostgres.d.mts +1826 -0
  17. package/dist/DrizzlePostgres.mjs +53 -0
  18. package/dist/DrizzlePostgres.mjs.map +1 -0
  19. package/dist/DrizzleSqliteBun.d.mts +2279 -0
  20. package/dist/DrizzleSqliteBun.mjs +70 -0
  21. package/dist/DrizzleSqliteBun.mjs.map +1 -0
  22. package/dist/DrizzleSqliteDo.d.mts +2329 -0
  23. package/dist/DrizzleSqliteDo.mjs +105 -0
  24. package/dist/DrizzleSqliteDo.mjs.map +1 -0
  25. package/dist/DrizzleSqliteNode.d.mts +2279 -0
  26. package/dist/DrizzleSqliteNode.mjs +70 -0
  27. package/dist/DrizzleSqliteNode.mjs.map +1 -0
  28. package/dist/DrizzleSqliteWasm.d.mts +2282 -0
  29. package/dist/DrizzleSqliteWasm.mjs +70 -0
  30. package/dist/DrizzleSqliteWasm.mjs.map +1 -0
  31. package/dist/drizzle/D1BatchStatements.d.mts +11 -0
  32. package/dist/drizzle/D1BatchStatements.mjs +8 -0
  33. package/dist/drizzle/D1BatchStatements.mjs.map +1 -0
  34. package/dist/drizzle/PasswordPreparedPostconditions.mjs +12 -0
  35. package/dist/drizzle/PasswordPreparedPostconditions.mjs.map +1 -0
  36. package/dist/drizzle/SuppliedService.d.mts +10 -0
  37. package/dist/drizzle/d1-emails.d.mts +62 -0
  38. package/dist/drizzle/d1-emails.mjs +580 -0
  39. package/dist/drizzle/d1-emails.mjs.map +1 -0
  40. package/dist/drizzle/d1-generated-statement.d.mts +2 -0
  41. package/dist/drizzle/d1-generated-statement.mjs +79 -0
  42. package/dist/drizzle/d1-generated-statement.mjs.map +1 -0
  43. package/dist/drizzle/d1-identity.d.mts +31 -0
  44. package/dist/drizzle/d1-identity.mjs +119 -0
  45. package/dist/drizzle/d1-identity.mjs.map +1 -0
  46. package/dist/drizzle/d1-oauth.d.mts +301 -0
  47. package/dist/drizzle/d1-oauth.mjs +76 -0
  48. package/dist/drizzle/d1-oauth.mjs.map +1 -0
  49. package/dist/drizzle/d1-passkey.d.mts +51 -0
  50. package/dist/drizzle/d1-passkey.mjs +95 -0
  51. package/dist/drizzle/d1-passkey.mjs.map +1 -0
  52. package/dist/drizzle/d1-password-prepared.d.mts +25 -0
  53. package/dist/drizzle/d1-password-prepared.mjs +461 -0
  54. package/dist/drizzle/d1-password-prepared.mjs.map +1 -0
  55. package/dist/drizzle/d1-passwords.d.mts +87 -0
  56. package/dist/drizzle/d1-passwords.mjs +1004 -0
  57. package/dist/drizzle/d1-passwords.mjs.map +1 -0
  58. package/dist/drizzle/d1-phone.d.mts +26 -0
  59. package/dist/drizzle/d1-phone.mjs +30 -0
  60. package/dist/drizzle/d1-phone.mjs.map +1 -0
  61. package/dist/drizzle/d1-planning.d.mts +12 -0
  62. package/dist/drizzle/d1-planning.mjs +43 -0
  63. package/dist/drizzle/d1-planning.mjs.map +1 -0
  64. package/dist/drizzle/d1-proofs.d.mts +80 -0
  65. package/dist/drizzle/d1-proofs.mjs +830 -0
  66. package/dist/drizzle/d1-proofs.mjs.map +1 -0
  67. package/dist/drizzle/d1-sessions.d.mts +67 -0
  68. package/dist/drizzle/d1-sessions.mjs +966 -0
  69. package/dist/drizzle/d1-sessions.mjs.map +1 -0
  70. package/dist/drizzle/d1-totp.d.mts +26 -0
  71. package/dist/drizzle/d1-totp.mjs +27 -0
  72. package/dist/drizzle/d1-totp.mjs.map +1 -0
  73. package/dist/drizzle/email-model.d.mts +354 -0
  74. package/dist/drizzle/email-model.mjs +21 -0
  75. package/dist/drizzle/email-model.mjs.map +1 -0
  76. package/dist/drizzle/email-registration.d.mts +30 -0
  77. package/dist/drizzle/email-registration.mjs +238 -0
  78. package/dist/drizzle/email-registration.mjs.map +1 -0
  79. package/dist/drizzle/email-sql.d.mts +4 -0
  80. package/dist/drizzle/email-sql.mjs +9 -0
  81. package/dist/drizzle/email-sql.mjs.map +1 -0
  82. package/dist/drizzle/email-target.d.mts +20 -0
  83. package/dist/drizzle/email-target.mjs +72 -0
  84. package/dist/drizzle/email-target.mjs.map +1 -0
  85. package/dist/drizzle/model.d.mts +250 -0
  86. package/dist/drizzle/model.mjs +58 -0
  87. package/dist/drizzle/model.mjs.map +1 -0
  88. package/dist/drizzle/mysql-emails.d.mts +71 -0
  89. package/dist/drizzle/mysql-emails.mjs +38 -0
  90. package/dist/drizzle/mysql-emails.mjs.map +1 -0
  91. package/dist/drizzle/mysql-identity.d.mts +22 -0
  92. package/dist/drizzle/mysql-identity.mjs +94 -0
  93. package/dist/drizzle/mysql-identity.mjs.map +1 -0
  94. package/dist/drizzle/mysql-password-prepared.d.mts +30 -0
  95. package/dist/drizzle/mysql-password-prepared.mjs +16 -0
  96. package/dist/drizzle/mysql-password-prepared.mjs.map +1 -0
  97. package/dist/drizzle/mysql-passwords.d.mts +86 -0
  98. package/dist/drizzle/mysql-passwords.mjs +38 -0
  99. package/dist/drizzle/mysql-passwords.mjs.map +1 -0
  100. package/dist/drizzle/mysql-proofs.d.mts +75 -0
  101. package/dist/drizzle/mysql-proofs.mjs +23 -0
  102. package/dist/drizzle/mysql-proofs.mjs.map +1 -0
  103. package/dist/drizzle/mysql-sessions.d.mts +237 -0
  104. package/dist/drizzle/mysql-sessions.mjs +53 -0
  105. package/dist/drizzle/mysql-sessions.mjs.map +1 -0
  106. package/dist/drizzle/mysql.d.mts +70 -0
  107. package/dist/drizzle/mysql.mjs +218 -0
  108. package/dist/drizzle/mysql.mjs.map +1 -0
  109. package/dist/drizzle/oauth-accounts.mjs +358 -0
  110. package/dist/drizzle/oauth-accounts.mjs.map +1 -0
  111. package/dist/drizzle/oauth-connected-access.mjs +210 -0
  112. package/dist/drizzle/oauth-connected-access.mjs.map +1 -0
  113. package/dist/drizzle/oauth-connected-collection.mjs +202 -0
  114. package/dist/drizzle/oauth-connected-collection.mjs.map +1 -0
  115. package/dist/drizzle/oauth-connected-custody.mjs +146 -0
  116. package/dist/drizzle/oauth-connected-custody.mjs.map +1 -0
  117. package/dist/drizzle/oauth-connected-drivers.mjs +76 -0
  118. package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -0
  119. package/dist/drizzle/oauth-connected-flow.mjs +247 -0
  120. package/dist/drizzle/oauth-connected-flow.mjs.map +1 -0
  121. package/dist/drizzle/oauth-connected-input.mjs +103 -0
  122. package/dist/drizzle/oauth-connected-input.mjs.map +1 -0
  123. package/dist/drizzle/oauth-connected-maintenance.mjs +214 -0
  124. package/dist/drizzle/oauth-connected-maintenance.mjs.map +1 -0
  125. package/dist/drizzle/oauth-connected-management.mjs +228 -0
  126. package/dist/drizzle/oauth-connected-management.mjs.map +1 -0
  127. package/dist/drizzle/oauth-connected-model.d.mts +278 -0
  128. package/dist/drizzle/oauth-connected-model.mjs +22 -0
  129. package/dist/drizzle/oauth-connected-model.mjs.map +1 -0
  130. package/dist/drizzle/oauth-connected-reference.d.mts +17 -0
  131. package/dist/drizzle/oauth-connected-reference.mjs +53 -0
  132. package/dist/drizzle/oauth-connected-reference.mjs.map +1 -0
  133. package/dist/drizzle/oauth-connected-settlement.mjs +117 -0
  134. package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -0
  135. package/dist/drizzle/oauth-connected-state.d.mts +14 -0
  136. package/dist/drizzle/oauth-connected-state.mjs +422 -0
  137. package/dist/drizzle/oauth-connected-state.mjs.map +1 -0
  138. package/dist/drizzle/oauth-connected-target.d.mts +753 -0
  139. package/dist/drizzle/oauth-connected-target.mjs +91 -0
  140. package/dist/drizzle/oauth-connected-target.mjs.map +1 -0
  141. package/dist/drizzle/oauth-drivers.mjs +51 -0
  142. package/dist/drizzle/oauth-drivers.mjs.map +1 -0
  143. package/dist/drizzle/oauth-flow.d.mts +5 -0
  144. package/dist/drizzle/oauth-flow.mjs +253 -0
  145. package/dist/drizzle/oauth-flow.mjs.map +1 -0
  146. package/dist/drizzle/oauth-input.mjs +127 -0
  147. package/dist/drizzle/oauth-input.mjs.map +1 -0
  148. package/dist/drizzle/oauth-model.d.mts +463 -0
  149. package/dist/drizzle/oauth-model.mjs +49 -0
  150. package/dist/drizzle/oauth-model.mjs.map +1 -0
  151. package/dist/drizzle/oauth-mysql.mjs +8 -0
  152. package/dist/drizzle/oauth-mysql.mjs.map +1 -0
  153. package/dist/drizzle/oauth-owner.d.mts +4 -0
  154. package/dist/drizzle/oauth-owner.mjs +10 -0
  155. package/dist/drizzle/oauth-owner.mjs.map +1 -0
  156. package/dist/drizzle/oauth-registration.d.mts +6 -0
  157. package/dist/drizzle/oauth-registration.mjs +374 -0
  158. package/dist/drizzle/oauth-registration.mjs.map +1 -0
  159. package/dist/drizzle/oauth-state.mjs +107 -0
  160. package/dist/drizzle/oauth-state.mjs.map +1 -0
  161. package/dist/drizzle/oauth-target.d.mts +111 -0
  162. package/dist/drizzle/oauth-target.mjs +246 -0
  163. package/dist/drizzle/oauth-target.mjs.map +1 -0
  164. package/dist/drizzle/passkey-drivers.mjs +34 -0
  165. package/dist/drizzle/passkey-drivers.mjs.map +1 -0
  166. package/dist/drizzle/passkey-kernel.mjs +8 -0
  167. package/dist/drizzle/passkey-kernel.mjs.map +1 -0
  168. package/dist/drizzle/passkey-model.d.mts +272 -0
  169. package/dist/drizzle/passkey-model.mjs +34 -0
  170. package/dist/drizzle/passkey-model.mjs.map +1 -0
  171. package/dist/drizzle/passkey-registration-ceremony-model.d.mts +50 -0
  172. package/dist/drizzle/passkey-registration-ceremony-model.mjs +18 -0
  173. package/dist/drizzle/passkey-registration-ceremony-model.mjs.map +1 -0
  174. package/dist/drizzle/passkey-state.mjs +7 -0
  175. package/dist/drizzle/passkey-state.mjs.map +1 -0
  176. package/dist/drizzle/passkey-target.d.mts +9 -0
  177. package/dist/drizzle/passkey-target.mjs +7 -0
  178. package/dist/drizzle/passkey-target.mjs.map +1 -0
  179. package/dist/drizzle/passkey-write-drivers.mjs +32 -0
  180. package/dist/drizzle/passkey-write-drivers.mjs.map +1 -0
  181. package/dist/drizzle/passkey-write-model.d.mts +190 -0
  182. package/dist/drizzle/passkey-write-model.mjs +13 -0
  183. package/dist/drizzle/passkey-write-model.mjs.map +1 -0
  184. package/dist/drizzle/passkey-write-target.d.mts +11 -0
  185. package/dist/drizzle/passkey-write-target.mjs +7 -0
  186. package/dist/drizzle/passkey-write-target.mjs.map +1 -0
  187. package/dist/drizzle/password-model.d.mts +329 -0
  188. package/dist/drizzle/password-model.mjs +23 -0
  189. package/dist/drizzle/password-model.mjs.map +1 -0
  190. package/dist/drizzle/password-prepared-model.d.mts +94 -0
  191. package/dist/drizzle/password-prepared-model.mjs +11 -0
  192. package/dist/drizzle/password-prepared-model.mjs.map +1 -0
  193. package/dist/drizzle/password-prepared-sql.mjs +390 -0
  194. package/dist/drizzle/password-prepared-sql.mjs.map +1 -0
  195. package/dist/drizzle/password-prepared-state.mjs +104 -0
  196. package/dist/drizzle/password-prepared-state.mjs.map +1 -0
  197. package/dist/drizzle/password-prepared-target.d.mts +12 -0
  198. package/dist/drizzle/password-prepared-target.mjs +56 -0
  199. package/dist/drizzle/password-prepared-target.mjs.map +1 -0
  200. package/dist/drizzle/password-registration.d.mts +19 -0
  201. package/dist/drizzle/password-registration.mjs +135 -0
  202. package/dist/drizzle/password-registration.mjs.map +1 -0
  203. package/dist/drizzle/password-sql.d.mts +5 -0
  204. package/dist/drizzle/password-sql.mjs +9 -0
  205. package/dist/drizzle/password-sql.mjs.map +1 -0
  206. package/dist/drizzle/password-target.d.mts +17 -0
  207. package/dist/drizzle/password-target.mjs +61 -0
  208. package/dist/drizzle/password-target.mjs.map +1 -0
  209. package/dist/drizzle/pg-emails.d.mts +72 -0
  210. package/dist/drizzle/pg-emails.mjs +38 -0
  211. package/dist/drizzle/pg-emails.mjs.map +1 -0
  212. package/dist/drizzle/pg-password-prepared.d.mts +31 -0
  213. package/dist/drizzle/pg-password-prepared.mjs +16 -0
  214. package/dist/drizzle/pg-password-prepared.mjs.map +1 -0
  215. package/dist/drizzle/pg-passwords.d.mts +87 -0
  216. package/dist/drizzle/pg-passwords.mjs +38 -0
  217. package/dist/drizzle/pg-passwords.mjs.map +1 -0
  218. package/dist/drizzle/pg-proofs.d.mts +76 -0
  219. package/dist/drizzle/pg-proofs.mjs +22 -0
  220. package/dist/drizzle/pg-proofs.mjs.map +1 -0
  221. package/dist/drizzle/pg-sessions.d.mts +238 -0
  222. package/dist/drizzle/pg-sessions.mjs +53 -0
  223. package/dist/drizzle/pg-sessions.mjs.map +1 -0
  224. package/dist/drizzle/pg.d.mts +81 -0
  225. package/dist/drizzle/pg.mjs +290 -0
  226. package/dist/drizzle/pg.mjs.map +1 -0
  227. package/dist/drizzle/phone-model.d.mts +115 -0
  228. package/dist/drizzle/phone-model.mjs +39 -0
  229. package/dist/drizzle/phone-model.mjs.map +1 -0
  230. package/dist/drizzle/phone-state.mjs +16 -0
  231. package/dist/drizzle/phone-state.mjs.map +1 -0
  232. package/dist/drizzle/phone-target.d.mts +17 -0
  233. package/dist/drizzle/phone-target.mjs +170 -0
  234. package/dist/drizzle/phone-target.mjs.map +1 -0
  235. package/dist/drizzle/proof-model.d.mts +286 -0
  236. package/dist/drizzle/proof-model.mjs +17 -0
  237. package/dist/drizzle/proof-model.mjs.map +1 -0
  238. package/dist/drizzle/proof-sql.d.mts +4 -0
  239. package/dist/drizzle/proof-sql.mjs +8 -0
  240. package/dist/drizzle/proof-sql.mjs.map +1 -0
  241. package/dist/drizzle/proof-target.d.mts +12 -0
  242. package/dist/drizzle/proof-target.mjs +36 -0
  243. package/dist/drizzle/proof-target.mjs.map +1 -0
  244. package/dist/drizzle/query-operations.mjs +26 -0
  245. package/dist/drizzle/query-operations.mjs.map +1 -0
  246. package/dist/drizzle/session-model.d.mts +200 -0
  247. package/dist/drizzle/session-model.mjs +20 -0
  248. package/dist/drizzle/session-model.mjs.map +1 -0
  249. package/dist/drizzle/session-sql.mjs +8 -0
  250. package/dist/drizzle/session-sql.mjs.map +1 -0
  251. package/dist/drizzle/session-target.d.mts +28 -0
  252. package/dist/drizzle/session-target.mjs +47 -0
  253. package/dist/drizzle/session-target.mjs.map +1 -0
  254. package/dist/drizzle/sqlite-emails.mjs +45 -0
  255. package/dist/drizzle/sqlite-emails.mjs.map +1 -0
  256. package/dist/drizzle/sqlite-identity.mjs +91 -0
  257. package/dist/drizzle/sqlite-identity.mjs.map +1 -0
  258. package/dist/drizzle/sqlite-password-prepared.mjs +21 -0
  259. package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -0
  260. package/dist/drizzle/sqlite-passwords.mjs +49 -0
  261. package/dist/drizzle/sqlite-passwords.mjs.map +1 -0
  262. package/dist/drizzle/sqlite-proofs.mjs +29 -0
  263. package/dist/drizzle/sqlite-proofs.mjs.map +1 -0
  264. package/dist/drizzle/sqlite-sessions.mjs +74 -0
  265. package/dist/drizzle/sqlite-sessions.mjs.map +1 -0
  266. package/dist/drizzle/sqlite.d.mts +78 -0
  267. package/dist/drizzle/sqlite.mjs +217 -0
  268. package/dist/drizzle/sqlite.mjs.map +1 -0
  269. package/dist/drizzle/standalone-guard.mjs +19 -0
  270. package/dist/drizzle/standalone-guard.mjs.map +1 -0
  271. package/dist/drizzle/step-up-model.d.mts +65 -0
  272. package/dist/drizzle/step-up-model.mjs +9 -0
  273. package/dist/drizzle/step-up-model.mjs.map +1 -0
  274. package/dist/drizzle/step-up-state.mjs +32 -0
  275. package/dist/drizzle/step-up-state.mjs.map +1 -0
  276. package/dist/drizzle/totp-model.d.mts +84 -0
  277. package/dist/drizzle/totp-model.mjs +13 -0
  278. package/dist/drizzle/totp-model.mjs.map +1 -0
  279. package/dist/drizzle/totp-state.d.mts +38 -0
  280. package/dist/drizzle/totp-state.mjs +287 -0
  281. package/dist/drizzle/totp-state.mjs.map +1 -0
  282. package/dist/drizzle/totp-target.d.mts +17 -0
  283. package/dist/drizzle/totp-target.mjs +81 -0
  284. package/dist/drizzle/totp-target.mjs.map +1 -0
  285. package/dist/drizzle/transaction-execution.d.mts +4 -0
  286. package/dist/drizzle/transaction-execution.mjs +11 -0
  287. package/dist/drizzle/transaction-execution.mjs.map +1 -0
  288. package/dist/drizzle/transaction-mysql.mjs +46 -0
  289. package/dist/drizzle/transaction-mysql.mjs.map +1 -0
  290. package/dist/drizzle/transaction-owner.d.mts +2 -0
  291. package/dist/drizzle/transaction-owner.mjs +8 -0
  292. package/dist/drizzle/transaction-owner.mjs.map +1 -0
  293. package/dist/index.d.mts +5 -0
  294. package/dist/index.mjs +5 -0
  295. package/dist/internal/configuration.d.mts +174 -0
  296. package/dist/internal/configuration.mjs +7 -0
  297. package/dist/internal/configuration.mjs.map +1 -0
  298. package/dist/internal/drizzle-migrations.mjs +19 -0
  299. package/dist/internal/drizzle-migrations.mjs.map +1 -0
  300. package/dist/internal/drizzle-postgres.mjs +39 -0
  301. package/dist/internal/drizzle-postgres.mjs.map +1 -0
  302. package/dist/internal/drizzle-sqlite.mjs +37 -0
  303. package/dist/internal/drizzle-sqlite.mjs.map +1 -0
  304. package/dist/internal/email-kernel.d.mts +13 -0
  305. package/dist/internal/email-kernel.mjs +487 -0
  306. package/dist/internal/email-kernel.mjs.map +1 -0
  307. package/dist/internal/mapping-error.d.mts +11 -0
  308. package/dist/internal/mapping-error.mjs +30 -0
  309. package/dist/internal/mapping-error.mjs.map +1 -0
  310. package/dist/internal/passkey/admission.d.mts +7 -0
  311. package/dist/internal/passkey/admission.mjs +216 -0
  312. package/dist/internal/passkey/admission.mjs.map +1 -0
  313. package/dist/internal/passkey/credentials.d.mts +6 -0
  314. package/dist/internal/passkey/credentials.mjs +249 -0
  315. package/dist/internal/passkey/credentials.mjs.map +1 -0
  316. package/dist/internal/passkey/enrollment.mjs +138 -0
  317. package/dist/internal/passkey/enrollment.mjs.map +1 -0
  318. package/dist/internal/passkey/flow.d.mts +10 -0
  319. package/dist/internal/passkey/flow.mjs +452 -0
  320. package/dist/internal/passkey/flow.mjs.map +1 -0
  321. package/dist/internal/passkey/management.mjs +231 -0
  322. package/dist/internal/passkey/management.mjs.map +1 -0
  323. package/dist/internal/passkey/registration-ceremony.d.mts +9 -0
  324. package/dist/internal/passkey/registration-ceremony.mjs +129 -0
  325. package/dist/internal/passkey/registration-ceremony.mjs.map +1 -0
  326. package/dist/internal/passkey/registration-custody.d.mts +2 -0
  327. package/dist/internal/passkey/registration-custody.mjs +52 -0
  328. package/dist/internal/passkey/registration-custody.mjs.map +1 -0
  329. package/dist/internal/passkey/registration-write.mjs +211 -0
  330. package/dist/internal/passkey/registration-write.mjs.map +1 -0
  331. package/dist/internal/passkey/state.d.mts +5 -0
  332. package/dist/internal/passkey/state.mjs +234 -0
  333. package/dist/internal/passkey/state.mjs.map +1 -0
  334. package/dist/internal/passkey/target.d.mts +19 -0
  335. package/dist/internal/passkey/target.mjs +190 -0
  336. package/dist/internal/passkey/target.mjs.map +1 -0
  337. package/dist/internal/passkey/write-state.mjs +345 -0
  338. package/dist/internal/passkey/write-state.mjs.map +1 -0
  339. package/dist/internal/passkey/write-target.mjs +192 -0
  340. package/dist/internal/passkey/write-target.mjs.map +1 -0
  341. package/dist/internal/passkey-kernel.mjs +49 -0
  342. package/dist/internal/passkey-kernel.mjs.map +1 -0
  343. package/dist/internal/passkeys.mjs +367 -0
  344. package/dist/internal/passkeys.mjs.map +1 -0
  345. package/dist/internal/password-kernel.d.mts +13 -0
  346. package/dist/internal/password-kernel.mjs +704 -0
  347. package/dist/internal/password-kernel.mjs.map +1 -0
  348. package/dist/internal/persistence.mjs +289 -0
  349. package/dist/internal/persistence.mjs.map +1 -0
  350. package/dist/internal/phone-kernel.mjs +434 -0
  351. package/dist/internal/phone-kernel.mjs.map +1 -0
  352. package/dist/internal/proof-kernel.d.mts +9 -0
  353. package/dist/internal/proof-kernel.mjs +619 -0
  354. package/dist/internal/proof-kernel.mjs.map +1 -0
  355. package/dist/internal/query-operations.d.mts +3 -0
  356. package/dist/internal/registration.mjs +65 -0
  357. package/dist/internal/registration.mjs.map +1 -0
  358. package/dist/internal/session-kernel.mjs +737 -0
  359. package/dist/internal/session-kernel.mjs.map +1 -0
  360. package/dist/internal/sql-persistence.d.mts +11 -0
  361. package/dist/internal/sql-persistence.mjs +37 -0
  362. package/dist/internal/sql-persistence.mjs.map +1 -0
  363. package/dist/internal/sql-query.mjs +207 -0
  364. package/dist/internal/sql-query.mjs.map +1 -0
  365. package/dist/internal/sql-table.d.mts +37 -0
  366. package/dist/internal/sql-table.mjs +71 -0
  367. package/dist/internal/sql-table.mjs.map +1 -0
  368. package/dist/internal/storage-mapping.mjs +687 -0
  369. package/dist/internal/storage-mapping.mjs.map +1 -0
  370. package/dist/internal/storage-tables.d.mts +914 -0
  371. package/dist/internal/storage-tables.mjs +387 -0
  372. package/dist/internal/storage-tables.mjs.map +1 -0
  373. package/dist/internal/storage-validation.mjs +58 -0
  374. package/dist/internal/storage-validation.mjs.map +1 -0
  375. package/dist/internal/transaction-execution-kernel.d.mts +18 -0
  376. package/dist/internal/transaction-execution-kernel.mjs +118 -0
  377. package/dist/internal/transaction-execution-kernel.mjs.map +1 -0
  378. package/dist/internal/transaction-kernel.d.mts +7 -0
  379. package/dist/internal/transaction-kernel.mjs +260 -0
  380. package/dist/internal/transaction-kernel.mjs.map +1 -0
  381. package/package.json +1 -0
  382. package/src/Drizzle.ts +378 -0
  383. package/src/DrizzleD1.ts +136 -0
  384. package/src/DrizzleLibsql.ts +301 -0
  385. package/src/DrizzleMysql2.ts +184 -0
  386. package/src/DrizzlePglite.ts +174 -0
  387. package/src/DrizzlePostgres.ts +174 -0
  388. package/src/DrizzleSqliteBun.ts +258 -0
  389. package/src/DrizzleSqliteDo.ts +473 -0
  390. package/src/DrizzleSqliteNode.ts +259 -0
  391. package/src/DrizzleSqliteWasm.ts +263 -0
  392. package/src/drizzle/D1BatchStatements.ts +10 -0
  393. package/src/drizzle/PasswordPreparedPostconditions.ts +30 -0
  394. package/src/drizzle/SuppliedService.ts +10 -0
  395. package/src/drizzle/d1-emails.ts +1829 -0
  396. package/src/drizzle/d1-generated-statement.ts +129 -0
  397. package/src/drizzle/d1-identity.ts +375 -0
  398. package/src/drizzle/d1-oauth.ts +340 -0
  399. package/src/drizzle/d1-passkey.ts +373 -0
  400. package/src/drizzle/d1-password-prepared.ts +1270 -0
  401. package/src/drizzle/d1-passwords.ts +2656 -0
  402. package/src/drizzle/d1-phone.ts +96 -0
  403. package/src/drizzle/d1-planning.ts +104 -0
  404. package/src/drizzle/d1-proofs.ts +2305 -0
  405. package/src/drizzle/d1-sessions.ts +2857 -0
  406. package/src/drizzle/d1-totp.ts +78 -0
  407. package/src/drizzle/email-model.ts +516 -0
  408. package/src/drizzle/email-registration.ts +698 -0
  409. package/src/drizzle/email-sql.ts +24 -0
  410. package/src/drizzle/email-target.ts +243 -0
  411. package/src/drizzle/model.ts +463 -0
  412. package/src/drizzle/mysql-emails.ts +321 -0
  413. package/src/drizzle/mysql-identity.ts +324 -0
  414. package/src/drizzle/mysql-password-prepared.ts +204 -0
  415. package/src/drizzle/mysql-passwords.ts +339 -0
  416. package/src/drizzle/mysql-proofs.ts +181 -0
  417. package/src/drizzle/mysql-sessions.ts +741 -0
  418. package/src/drizzle/mysql.ts +687 -0
  419. package/src/drizzle/oauth-accounts.ts +804 -0
  420. package/src/drizzle/oauth-connected-access.ts +354 -0
  421. package/src/drizzle/oauth-connected-collection.ts +324 -0
  422. package/src/drizzle/oauth-connected-custody.ts +277 -0
  423. package/src/drizzle/oauth-connected-drivers.ts +465 -0
  424. package/src/drizzle/oauth-connected-flow.ts +441 -0
  425. package/src/drizzle/oauth-connected-input.ts +127 -0
  426. package/src/drizzle/oauth-connected-maintenance.ts +345 -0
  427. package/src/drizzle/oauth-connected-management.ts +365 -0
  428. package/src/drizzle/oauth-connected-model.ts +347 -0
  429. package/src/drizzle/oauth-connected-reference.ts +112 -0
  430. package/src/drizzle/oauth-connected-settlement.ts +226 -0
  431. package/src/drizzle/oauth-connected-state.ts +845 -0
  432. package/src/drizzle/oauth-connected-target.ts +264 -0
  433. package/src/drizzle/oauth-drivers.ts +569 -0
  434. package/src/drizzle/oauth-flow.ts +462 -0
  435. package/src/drizzle/oauth-input.ts +201 -0
  436. package/src/drizzle/oauth-model.ts +617 -0
  437. package/src/drizzle/oauth-mysql.ts +10 -0
  438. package/src/drizzle/oauth-owner.ts +29 -0
  439. package/src/drizzle/oauth-registration.ts +640 -0
  440. package/src/drizzle/oauth-state.ts +215 -0
  441. package/src/drizzle/oauth-target.ts +750 -0
  442. package/src/drizzle/passkey-drivers.ts +385 -0
  443. package/src/drizzle/passkey-kernel.ts +3 -0
  444. package/src/drizzle/passkey-model.ts +353 -0
  445. package/src/drizzle/passkey-registration-ceremony-model.ts +69 -0
  446. package/src/drizzle/passkey-state.ts +3 -0
  447. package/src/drizzle/passkey-target.ts +23 -0
  448. package/src/drizzle/passkey-write-drivers.ts +395 -0
  449. package/src/drizzle/passkey-write-model.ts +271 -0
  450. package/src/drizzle/passkey-write-target.ts +9 -0
  451. package/src/drizzle/password-model.ts +491 -0
  452. package/src/drizzle/password-prepared-model.ts +259 -0
  453. package/src/drizzle/password-prepared-sql.ts +1191 -0
  454. package/src/drizzle/password-prepared-state.ts +231 -0
  455. package/src/drizzle/password-prepared-target.ts +160 -0
  456. package/src/drizzle/password-registration.ts +374 -0
  457. package/src/drizzle/password-sql.ts +12 -0
  458. package/src/drizzle/password-target.ts +224 -0
  459. package/src/drizzle/pg-emails.ts +321 -0
  460. package/src/drizzle/pg-password-prepared.ts +205 -0
  461. package/src/drizzle/pg-passwords.ts +338 -0
  462. package/src/drizzle/pg-proofs.ts +191 -0
  463. package/src/drizzle/pg-sessions.ts +750 -0
  464. package/src/drizzle/pg.ts +984 -0
  465. package/src/drizzle/phone-model.ts +190 -0
  466. package/src/drizzle/phone-state.ts +21 -0
  467. package/src/drizzle/phone-target.ts +472 -0
  468. package/src/drizzle/proof-model.ts +398 -0
  469. package/src/drizzle/proof-sql.ts +9 -0
  470. package/src/drizzle/proof-target.ts +122 -0
  471. package/src/drizzle/query-operations.ts +37 -0
  472. package/src/drizzle/session-model.ts +370 -0
  473. package/src/drizzle/session-sql.ts +13 -0
  474. package/src/drizzle/session-target.ts +338 -0
  475. package/src/drizzle/sqlite-emails.ts +366 -0
  476. package/src/drizzle/sqlite-identity.ts +344 -0
  477. package/src/drizzle/sqlite-password-prepared.ts +260 -0
  478. package/src/drizzle/sqlite-passwords.ts +497 -0
  479. package/src/drizzle/sqlite-proofs.ts +202 -0
  480. package/src/drizzle/sqlite-sessions.ts +971 -0
  481. package/src/drizzle/sqlite.ts +705 -0
  482. package/src/drizzle/standalone-guard.ts +38 -0
  483. package/src/drizzle/step-up-model.ts +128 -0
  484. package/src/drizzle/step-up-state.ts +139 -0
  485. package/src/drizzle/totp-model.ts +92 -0
  486. package/src/drizzle/totp-state.ts +525 -0
  487. package/src/drizzle/totp-target.ts +308 -0
  488. package/src/drizzle/transaction-execution.ts +12 -0
  489. package/src/drizzle/transaction-mysql.ts +104 -0
  490. package/src/drizzle/transaction-owner.ts +10 -0
  491. package/src/index.ts +4 -0
  492. package/src/internal/configuration.ts +282 -0
  493. package/src/internal/drizzle-migrations.ts +30 -0
  494. package/src/internal/drizzle-postgres.ts +81 -0
  495. package/src/internal/drizzle-sqlite.ts +79 -0
  496. package/src/internal/email-kernel.ts +1532 -0
  497. package/src/internal/mapping-error.ts +36 -0
  498. package/src/internal/passkey/admission.ts +362 -0
  499. package/src/internal/passkey/credentials.ts +511 -0
  500. package/src/internal/passkey/enrollment.ts +326 -0
  501. package/src/internal/passkey/flow.ts +1062 -0
  502. package/src/internal/passkey/management.ts +422 -0
  503. package/src/internal/passkey/registration-ceremony.ts +283 -0
  504. package/src/internal/passkey/registration-custody.ts +91 -0
  505. package/src/internal/passkey/registration-write.ts +426 -0
  506. package/src/internal/passkey/state.ts +354 -0
  507. package/src/internal/passkey/target.ts +586 -0
  508. package/src/internal/passkey/write-state.ts +681 -0
  509. package/src/internal/passkey/write-target.ts +452 -0
  510. package/src/internal/passkey-kernel.ts +102 -0
  511. package/src/internal/passkeys.ts +597 -0
  512. package/src/internal/password-kernel.ts +2122 -0
  513. package/src/internal/persistence.ts +590 -0
  514. package/src/internal/phone-kernel.ts +843 -0
  515. package/src/internal/proof-kernel.ts +1949 -0
  516. package/src/internal/query-operations.ts +26 -0
  517. package/src/internal/registration.ts +160 -0
  518. package/src/internal/session-kernel.ts +2210 -0
  519. package/src/internal/sql-persistence.ts +45 -0
  520. package/src/internal/sql-query.ts +298 -0
  521. package/src/internal/sql-table.ts +89 -0
  522. package/src/internal/storage-mapping.ts +706 -0
  523. package/src/internal/storage-tables.ts +408 -0
  524. package/src/internal/storage-validation.ts +117 -0
  525. package/src/internal/transaction-execution-kernel.ts +317 -0
  526. package/src/internal/transaction-kernel.ts +582 -0
@@ -0,0 +1,107 @@
1
+ import { DateTime, Effect, Encoding, Schema } from "effect";
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
+ import { randomBytes } from "@noble/hashes/utils.js";
4
+ import { OAuthExternalIdentity, OAuthUnavailable, snapshotOAuthSync } from "@yielded/auth/OAuth";
5
+ //#region src/drizzle/oauth-state.ts
6
+ const encoder = new TextEncoder();
7
+ const decoder = new TextDecoder("utf-8", { fatal: true });
8
+ const unavailable = () => OAuthUnavailable.make({});
9
+ const invariant = (value) => {
10
+ if (!value) throw unavailable();
11
+ };
12
+ const nonce = () => Encoding.encodeBase64Url(randomBytes(32));
13
+ const digest = (value) => Encoding.encodeBase64Url(sha256(encoder.encode(value)));
14
+ /** Capture configuration/callback references while preserving Drizzle table, SQL
15
+ * and Effect objects. Never freeze or mutate the consumer's original graph. */
16
+ const captureOAuthMapping = (input) => {
17
+ const seen = /* @__PURE__ */ new Map();
18
+ const copy = (value) => {
19
+ if (value === null || typeof value !== "object" || Effect.isEffect(value)) return value;
20
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) return value;
21
+ const prior = seen.get(value);
22
+ if (prior !== void 0) return prior;
23
+ if (Array.isArray(value)) {
24
+ const result = [];
25
+ seen.set(value, result);
26
+ result.push(...value.map(copy));
27
+ return Object.freeze(result);
28
+ }
29
+ const result = {};
30
+ seen.set(value, result);
31
+ for (const [key, child] of Object.entries(value)) result[key] = copy(child);
32
+ return Object.freeze(result);
33
+ };
34
+ return copy(input);
35
+ };
36
+ /** Versioned length-delimited UTF-8 tuple; the module is deliberately excluded.
37
+ * Reject ill-formed UTF-16 rather than letting UTF-8 replacement alias identities. */
38
+ const oauthIdentityKey = (input) => {
39
+ const identity = snapshotOAuthSync(OAuthExternalIdentity, input);
40
+ const bytes = [
41
+ "effect-auth/oauth-identity-key/v1",
42
+ identity.provider,
43
+ identity.issuer,
44
+ identity.subject
45
+ ].map((field) => {
46
+ const value = encoder.encode(field);
47
+ invariant(decoder.decode(value) === field);
48
+ return value;
49
+ });
50
+ const packed = new Uint8Array(bytes.reduce((size, value) => size + 4 + value.length, 0));
51
+ const view = new DataView(packed.buffer);
52
+ let offset = 0;
53
+ for (const value of bytes) {
54
+ view.setUint32(offset, value.length, false);
55
+ packed.set(value, offset + 4);
56
+ offset += 4 + value.length;
57
+ }
58
+ return "v1:" + Encoding.encodeBase64Url(sha256(packed));
59
+ };
60
+ const sameIdentity = (left, right) => left.provider === right.provider && left.issuer === right.issuer && left.subject === right.subject;
61
+ /** Private Type storage: opaque wrappers and DateTimes are freshly reconstructed. */
62
+ const storage = (schema) => {
63
+ const codec = Schema.fromJsonString(Schema.toCodecJson(Schema.toType(schema)));
64
+ const encode = Schema.encodeSync(codec);
65
+ const decode = Schema.decodeSync(codec);
66
+ return {
67
+ encode: (value) => encode(snapshotOAuthSync(schema, value)),
68
+ decode: (value) => snapshotOAuthSync(schema, decode(value))
69
+ };
70
+ };
71
+ const sameRevision = (left, right) => {
72
+ if (left.subjectId !== right.subjectId || left.securityRevision !== right.securityRevision || left.credentials.length !== right.credentials.length) return false;
73
+ const revisions = new Map(left.credentials.map((item) => [item.credentialId, item.revision]));
74
+ return revisions.size === left.credentials.length && new Set(right.credentials.map((item) => item.credentialId)).size === right.credentials.length && right.credentials.every((item) => revisions.get(item.credentialId) === item.revision);
75
+ };
76
+ const satisfies = (proofs, requirement) => {
77
+ const factors = new Set(proofs.flatMap((proof) => [...proof.factors]));
78
+ const count = new Set(proofs.map((proof) => proof.credentialId)).size;
79
+ return requirement.alternatives.some((alternative) => alternative.factors.every((factor) => factors.has(factor)) && count >= alternative.minimumCredentials && proofs.some((proof) => (!alternative.userVerified || proof.userVerified) && (!alternative.phishingResistant || proof.phishingResistant)));
80
+ };
81
+ const validAction = (authorization, expected, currentRequirement, now, maximumAgeMillis) => {
82
+ const challenge = authorization.challenge;
83
+ const evidence = authorization.evidence;
84
+ const intentDigest = digest(expected.intent);
85
+ const binding = digest(JSON.stringify([
86
+ "effect-auth/oauth-action/v1",
87
+ expected.moduleId,
88
+ expected.action,
89
+ expected.flowId,
90
+ expected.commandId,
91
+ intentDigest
92
+ ]));
93
+ if (challenge.moduleId !== expected.moduleId || challenge.action !== expected.action || challenge.flowId !== expected.flowId || challenge.commandId !== expected.commandId || challenge.intentDigest !== intentDigest || challenge.bindingDigest !== binding || evidence.flowId !== expected.flowId || evidence.bindingDigest !== binding || !sameRevision(challenge.revision, expected.revision) || !sameRevision(evidence.revision, expected.revision)) return false;
94
+ const revisions = new Map(expected.revision.credentials.map((item) => [item.credentialId, item.revision]));
95
+ if (evidence.proofs.some((proof) => !revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now)) return false;
96
+ return [authorization.requirement, currentRequirement].every((requirement) => {
97
+ const fresh = evidence.proofs.filter((proof) => {
98
+ const age = now - DateTime.toEpochMillis(proof.verifiedAt);
99
+ return age >= 0 && age < Math.min(maximumAgeMillis, requirement.maximumAgeMillis);
100
+ });
101
+ return satisfies(fresh, requirement);
102
+ });
103
+ };
104
+ //#endregion
105
+ export { captureOAuthMapping, digest, invariant, nonce, oauthIdentityKey, sameIdentity, sameRevision, satisfies, storage, unavailable, validAction };
106
+
107
+ //# sourceMappingURL=oauth-state.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-state.mjs","names":[],"sources":["../../src/drizzle/oauth-state.ts"],"sourcesContent":["// oxlint-disable-next-line import/extensions -- Noble exposes only its explicit .js subpath.\nimport { sha256 } from \"@noble/hashes/sha2.js\";\n// oxlint-disable-next-line import/extensions -- Noble exposes only its explicit .js subpath.\nimport { randomBytes } from \"@noble/hashes/utils.js\";\nimport {\n type OAuthActionAuthorization,\n type OAuthAccountRevision,\n OAuthUnavailable,\n OAuthExternalIdentity,\n snapshotOAuthSync,\n} from \"@yielded/auth/OAuth\";\nimport type { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\nimport { DateTime, Effect, Encoding, Schema } from \"effect\";\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\nexport const unavailable = () => OAuthUnavailable.make({});\n\nexport const invariant: (value: unknown) => asserts value = (value) => {\n if (!value) throw unavailable();\n};\n\nexport const nonce = () => Encoding.encodeBase64Url(randomBytes(32));\nexport const digest = (value: string) => Encoding.encodeBase64Url(sha256(encoder.encode(value)));\n\n/** Capture configuration/callback references while preserving Drizzle table, SQL\n * and Effect objects. Never freeze or mutate the consumer's original graph. */\nexport const captureOAuthMapping = <A>(input: A): A => {\n const seen = new Map<object, unknown>();\n\n const copy = (value: unknown): unknown => {\n if (value === null || typeof value !== \"object\" || Effect.isEffect(value)) return value;\n if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) return value;\n const prior = seen.get(value);\n\n if (prior !== undefined) return prior;\n if (Array.isArray(value)) {\n const result: unknown[] = [];\n\n seen.set(value, result);\n result.push(...value.map(copy));\n\n return Object.freeze(result);\n }\n const result: Record<string, unknown> = {};\n\n seen.set(value, result);\n for (const [key, child] of Object.entries(value)) result[key] = copy(child);\n\n return Object.freeze(result);\n };\n\n return copy(input) as A;\n};\n\n/** Versioned length-delimited UTF-8 tuple; the module is deliberately excluded.\n * Reject ill-formed UTF-16 rather than letting UTF-8 replacement alias identities. */\nexport const oauthIdentityKey = (input: typeof OAuthExternalIdentity.Type): string => {\n const identity = snapshotOAuthSync(OAuthExternalIdentity, input);\n\n const fields = [\n \"effect-auth/oauth-identity-key/v1\",\n identity.provider,\n identity.issuer,\n identity.subject,\n ];\n\n const bytes = fields.map((field) => {\n const value = encoder.encode(field);\n\n invariant(decoder.decode(value) === field);\n\n return value;\n });\n\n const packed = new Uint8Array(bytes.reduce((size, value) => size + 4 + value.length, 0));\n const view = new DataView(packed.buffer);\n let offset = 0;\n\n for (const value of bytes) {\n view.setUint32(offset, value.length, false);\n packed.set(value, offset + 4);\n offset += 4 + value.length;\n }\n\n return \"v1:\" + Encoding.encodeBase64Url(sha256(packed));\n};\n\nexport const sameIdentity = (\n left: typeof OAuthExternalIdentity.Type,\n right: typeof OAuthExternalIdentity.Type,\n) =>\n left.provider === right.provider &&\n left.issuer === right.issuer &&\n left.subject === right.subject;\n\n/** Private Type storage: opaque wrappers and DateTimes are freshly reconstructed. */\nexport const storage = <S extends Schema.Codec<unknown, unknown, never, never>>(schema: S) => {\n const codec = Schema.fromJsonString(Schema.toCodecJson(Schema.toType(schema)));\n const encode = Schema.encodeSync(codec);\n const decode = Schema.decodeSync(codec);\n\n return {\n encode: (value: S[\"Type\"]) => encode(snapshotOAuthSync(schema, value)),\n decode: (value: string) => snapshotOAuthSync(schema, decode(value)),\n };\n};\n\nexport const sameRevision = (left: OAuthAccountRevision, right: OAuthAccountRevision) => {\n if (\n left.subjectId !== right.subjectId ||\n left.securityRevision !== right.securityRevision ||\n left.credentials.length !== right.credentials.length\n )\n return false;\n const revisions = new Map(left.credentials.map((item) => [item.credentialId, item.revision]));\n\n return (\n revisions.size === left.credentials.length &&\n new Set(right.credentials.map((item) => item.credentialId)).size === right.credentials.length &&\n right.credentials.every((item) => revisions.get(item.credentialId) === item.revision)\n );\n};\n\nexport const satisfies = (\n proofs: ReadonlyArray<{\n readonly credentialId: string;\n readonly factors: ReadonlyArray<string>;\n readonly userVerified: boolean;\n readonly phishingResistant: boolean;\n }>,\n requirement: AuthenticationRequirement,\n) => {\n const factors = new Set(proofs.flatMap((proof) => [...proof.factors]));\n const count = new Set(proofs.map((proof) => proof.credentialId)).size;\n\n return requirement.alternatives.some(\n (alternative) =>\n alternative.factors.every((factor) => factors.has(factor)) &&\n count >= alternative.minimumCredentials &&\n proofs.some(\n (proof) =>\n (!alternative.userVerified || proof.userVerified) &&\n (!alternative.phishingResistant || proof.phishingResistant),\n ),\n );\n};\n\nexport const validAction = (\n authorization: OAuthActionAuthorization,\n expected: {\n readonly moduleId: string;\n readonly action: OAuthActionAuthorization[\"challenge\"][\"action\"];\n readonly flowId: string;\n readonly commandId: string;\n readonly revision: OAuthAccountRevision;\n readonly intent: string;\n },\n currentRequirement: AuthenticationRequirement,\n now: number,\n maximumAgeMillis: number,\n) => {\n const challenge = authorization.challenge;\n const evidence = authorization.evidence;\n const intentDigest = digest(expected.intent);\n\n const binding = digest(\n // oxlint-disable-next-line no-restricted-properties -- Fixed private action fingerprint format shared with the core verifier.\n JSON.stringify([\n \"effect-auth/oauth-action/v1\",\n expected.moduleId,\n expected.action,\n expected.flowId,\n expected.commandId,\n intentDigest,\n ]),\n );\n\n if (\n challenge.moduleId !== expected.moduleId ||\n challenge.action !== expected.action ||\n challenge.flowId !== expected.flowId ||\n challenge.commandId !== expected.commandId ||\n challenge.intentDigest !== intentDigest ||\n challenge.bindingDigest !== binding ||\n evidence.flowId !== expected.flowId ||\n evidence.bindingDigest !== binding ||\n !sameRevision(challenge.revision, expected.revision) ||\n !sameRevision(evidence.revision, expected.revision)\n )\n return false;\n\n const revisions = new Map(\n expected.revision.credentials.map((item) => [item.credentialId, item.revision]),\n );\n\n if (\n evidence.proofs.some(\n (proof) =>\n !revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now,\n )\n )\n return false;\n\n return [authorization.requirement, currentRequirement].every((requirement) => {\n const fresh = evidence.proofs.filter((proof) => {\n const age = now - DateTime.toEpochMillis(proof.verifiedAt);\n\n return age >= 0 && age < Math.min(maximumAgeMillis, requirement.maximumAgeMillis);\n });\n\n return satisfies(fresh, requirement);\n });\n};\n"],"mappings":";;;;;AAcA,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,UAAU,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC;AAExD,MAAa,oBAAoB,iBAAiB,KAAK,CAAC,CAAC;AAEzD,MAAa,aAAgD,UAAU;CACrE,IAAI,CAAC,OAAO,MAAM,YAAY;AAChC;AAEA,MAAa,cAAc,SAAS,gBAAgB,YAAY,EAAE,CAAC;AACnE,MAAa,UAAU,UAAkB,SAAS,gBAAgB,OAAO,QAAQ,OAAO,KAAK,CAAC,CAAC;;;AAI/F,MAAa,uBAA0B,UAAgB;CACrD,MAAM,uBAAO,IAAI,IAAqB;CAEtC,MAAM,QAAQ,UAA4B;EACxC,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO;EAClF,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,OAAO,eAAe,KAAK,MAAM,OAAO,WAAW,OAAO;EACvF,MAAM,QAAQ,KAAK,IAAI,KAAK;EAE5B,IAAI,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SAAS;EACT,SAAS;EACT,SAAS;EACT;CACF,CAAC,CACH;CAEA,IACE,UAAU,aAAa,SAAS,YAChC,UAAU,WAAW,SAAS,UAC9B,UAAU,WAAW,SAAS,UAC9B,UAAU,cAAc,SAAS,aACjC,UAAU,iBAAiB,gBAC3B,UAAU,kBAAkB,WAC5B,SAAS,WAAW,SAAS,UAC7B,SAAS,kBAAkB,WAC3B,CAAC,aAAa,UAAU,UAAU,SAAS,QAAQ,KACnD,CAAC,aAAa,SAAS,UAAU,SAAS,QAAQ,GAElD,OAAO;CAET,MAAM,YAAY,IAAI,IACpB,SAAS,SAAS,YAAY,KAAK,SAAS,CAAC,KAAK,cAAc,KAAK,QAAQ,CAAC,CAChF;CAEA,IACE,SAAS,OAAO,MACb,UACC,CAAC,UAAU,IAAI,MAAM,YAAY,KAAK,SAAS,cAAc,MAAM,UAAU,IAAI,GACrF,GAEA,OAAO;CAET,OAAO,CAAC,cAAc,aAAa,kBAAkB,CAAC,CAAC,OAAO,gBAAgB;EAC5E,MAAM,QAAQ,SAAS,OAAO,QAAQ,UAAU;GAC9C,MAAM,MAAM,MAAM,SAAS,cAAc,MAAM,UAAU;GAEzD,OAAO,OAAO,KAAK,MAAM,KAAK,IAAI,kBAAkB,YAAY,gBAAgB;EAClF,CAAC;EAED,OAAO,UAAU,OAAO,WAAW;CACrC,CAAC;AACH"}
@@ -0,0 +1,111 @@
1
+ import "./model.mjs";
2
+ import { OAuthRegistrationAuthority } from "./oauth-model.mjs";
3
+ import "./oauth-owner.mjs";
4
+ import "./oauth-registration.mjs";
5
+ import { TransactionCoordinatorError, TransactionTargetConfiguration } from "../internal/transaction-execution-kernel.mjs";
6
+ import "./transaction-execution.mjs";
7
+ import { Context, Effect, Layer } from "effect";
8
+ import { LifecycleHooks } from "@yielded/auth/Hooks";
9
+ import { OAuthAccountRevision, OAuthAccountsPersistence, OAuthClaim, OAuthClaimDecision, OAuthCleanupInput, OAuthCredentialSnapshot, OAuthIssueDecision, OAuthLinkClaimDecision, OAuthLinkDecision, OAuthLinkIssueDecision, OAuthLinkPendingFlow, OAuthPendingFlow, OAuthRegistrationIntent, OAuthRegistrationIntents, OAuthSettlementDecision, OAuthSignInPersistence, OAuthUnavailable, OAuthUnlinkDecision, OAuthUnlinkInspection, OAuthVerifiedExternalIdentity, PrepareOAuthCommit } from "@yielded/auth/OAuth";
10
+ import { Statement } from "effect/unstable/sql/Statement";
11
+ //#region src/drizzle/oauth-target.d.ts
12
+ type OAuthTargetConfiguration = TransactionTargetConfiguration<OAuthUnavailable>;
13
+ type OAuthCoordinatorError<E> = TransactionCoordinatorError<E, OAuthUnavailable>;
14
+ declare const makeTargetOAuthSignInServices: (database: any, mapping: any, configuration: OAuthTargetConfiguration) => Effect.Effect<{
15
+ oauthSignInPersistence: {
16
+ readonly issue: <A>(input: OAuthPendingFlow, prepare: PrepareOAuthCommit<OAuthIssueDecision, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
17
+ readonly claim: <A>(input: {
18
+ readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
19
+ readonly generation: number;
20
+ readonly flowId: import("@yielded/auth/Operations").RequestBindingFlowId;
21
+ readonly provider: import("@yielded/auth/OAuth").OAuthProviderKey;
22
+ readonly callbackId: string & import("effect/Brand").Brand<"effect-auth/OAuthCallbackId">;
23
+ readonly stateDigest: import("@yielded/auth/Schema").TokenDigest;
24
+ readonly requestBindingVerifier: import("@yielded/auth/Schema").TokenDigest;
25
+ readonly requestBindingExpiresAtMillis: number;
26
+ readonly responseIssuer?: string & import("effect/Brand").Brand<"effect-auth/OAuthIssuer">;
27
+ readonly claimId: string & import("effect/Brand").Brand<"effect-auth/OAuthClaimId">;
28
+ readonly nowMillis: number;
29
+ }, prepare: PrepareOAuthCommit<OAuthClaimDecision, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
30
+ readonly settle: <A>(input: {
31
+ readonly claim: OAuthClaim;
32
+ readonly outcome: {
33
+ readonly _tag: "Verified";
34
+ readonly identity: OAuthVerifiedExternalIdentity;
35
+ } | {
36
+ readonly _tag: "Cancelled" | "Rejected" | "Ambiguous";
37
+ };
38
+ readonly nowMillis: number;
39
+ }, prepare: PrepareOAuthCommit<OAuthSettlementDecision, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
40
+ readonly cleanup: <A>(input: OAuthCleanupInput, prepare: PrepareOAuthCommit<{
41
+ readonly terminalized: number;
42
+ readonly removed: number;
43
+ readonly hasMore: boolean;
44
+ }, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
45
+ };
46
+ }, never, LifecycleHooks>;
47
+ declare const makeTargetOAuthRegistrationIntentServices: (database: any, mapping: any, configuration: OAuthTargetConfiguration) => Effect.Effect<{
48
+ oauthRegistrationIntents: {
49
+ readonly settle: <A>(input: {
50
+ readonly claim: OAuthClaim;
51
+ readonly identity: OAuthVerifiedExternalIdentity;
52
+ readonly intent?: OAuthRegistrationIntent;
53
+ readonly nowMillis: number;
54
+ }, prepare: PrepareOAuthCommit<import("@yielded/auth/OAuth").OAuthRegistrationSettlement, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
55
+ };
56
+ }, never, LifecycleHooks>;
57
+ declare const makeTargetOAuthAccountsServices: (database: any, mapping: any, configuration: OAuthTargetConfiguration) => Effect.Effect<{
58
+ oauthAccountsPersistence: {
59
+ readonly capture: (input: {
60
+ readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
61
+ readonly subjectId: import("@yielded/auth/Schema").SubjectId;
62
+ }) => Effect.Effect<OAuthAccountRevision | undefined, OAuthUnavailable>;
63
+ readonly issue: <A>(input: {
64
+ readonly flow: OAuthLinkPendingFlow;
65
+ readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
66
+ }, prepare: PrepareOAuthCommit<typeof OAuthLinkIssueDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
67
+ readonly preflight: (input: import("@yielded/auth/OAuth").OAuthLinkAccess) => Effect.Effect<OAuthLinkPendingFlow | undefined, OAuthUnavailable>;
68
+ readonly claim: <A>(input: {
69
+ readonly access: import("@yielded/auth/OAuth").OAuthLinkAccess;
70
+ readonly flow: OAuthLinkPendingFlow;
71
+ readonly claimId: import("@yielded/auth/OAuth").OAuthLinkClaim["claimId"];
72
+ readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
73
+ }, prepare: PrepareOAuthCommit<typeof OAuthLinkClaimDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
74
+ readonly settle: <A>(input: {
75
+ readonly claim: import("@yielded/auth/OAuth").OAuthLinkClaim;
76
+ readonly outcome: import("@yielded/auth/OAuth").OAuthLinkOutcome;
77
+ readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
78
+ readonly invalidation: import("@yielded/auth/Sessions").SessionInvalidationWindow;
79
+ readonly nowMillis: number;
80
+ }, prepare: PrepareOAuthCommit<typeof OAuthLinkDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
81
+ readonly inspectUnlink: (input: {
82
+ readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
83
+ readonly subjectId: import("@yielded/auth/Schema").SubjectId;
84
+ readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
85
+ readonly credentialId: string;
86
+ }) => Effect.Effect<typeof OAuthUnlinkInspection.Type, OAuthUnavailable>;
87
+ readonly unlink: <A>(input: {
88
+ readonly moduleId: string & import("effect/Brand").Brand<"effect-auth/OAuthModuleId">;
89
+ readonly commandId: string & import("effect/Brand").Brand<"effect-auth/OAuthCommandId">;
90
+ readonly credential: OAuthCredentialSnapshot;
91
+ readonly authorization: import("@yielded/auth/OAuth").OAuthActionAuthorization;
92
+ readonly invalidation: import("@yielded/auth/Sessions").SessionInvalidationWindow;
93
+ readonly nowMillis: number;
94
+ readonly retentionUntilMillis: number;
95
+ }, prepare: PrepareOAuthCommit<typeof OAuthUnlinkDecision.Type, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
96
+ readonly cleanup: <A>(input: OAuthCleanupInput, prepare: PrepareOAuthCommit<{
97
+ readonly terminalized: number;
98
+ readonly removed: number;
99
+ readonly hasMore: boolean;
100
+ }, A>) => Effect.Effect<import("@yielded/auth/Hooks").PreparedCommit<A>, OAuthUnavailable>;
101
+ };
102
+ }, never, LifecycleHooks>;
103
+ declare const oauthAccountsPersistenceLayer: (services: ReturnType<typeof makeTargetOAuthAccountsServices>) => Layer.Layer<OAuthAccountsPersistence, never, LifecycleHooks>;
104
+ declare const oauthSignInPersistenceLayer: (services: ReturnType<typeof makeTargetOAuthSignInServices>) => Layer.Layer<OAuthSignInPersistence, never, LifecycleHooks>;
105
+ declare const oauthRegistrationIntentsLayer: (services: ReturnType<typeof makeTargetOAuthRegistrationIntentServices>) => Layer.Layer<OAuthRegistrationIntents, never, LifecycleHooks>;
106
+ declare const oauthRegistrationAuthorityLayer: <Id, Registration>(tag: Context.Key<Id, OAuthRegistrationAuthority<Registration>>, services: Effect.Effect<{
107
+ readonly registrationAuthority: OAuthRegistrationAuthority<Registration>;
108
+ }, never, LifecycleHooks>) => Layer.Layer<Id, never, LifecycleHooks>;
109
+ //#endregion
110
+ export { OAuthCoordinatorError, OAuthTargetConfiguration, makeTargetOAuthAccountsServices, makeTargetOAuthRegistrationIntentServices, makeTargetOAuthSignInServices, oauthAccountsPersistenceLayer, oauthRegistrationAuthorityLayer, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer };
111
+ //# sourceMappingURL=oauth-target.d.mts.map
@@ -0,0 +1,246 @@
1
+ import { captureOAuthMapping, invariant, nonce, unavailable } from "./oauth-state.mjs";
2
+ import { both } from "./transaction-owner.mjs";
3
+ import { CurrentOAuthTransaction, col, equal } from "./oauth-owner.mjs";
4
+ import { claimFlow, cleanupFlows, discoverOwned, exactClaim, issueFlow, matchesAccess, readFlow, resolveOwned, terminalFlow } from "./oauth-flow.mjs";
5
+ import { inspectIntent, register, registrationData, registrationResources, settleRegistrationIntent } from "./oauth-registration.mjs";
6
+ import { accountCurrent, claimLink, inspectUnlink, issueLink, preflightLink, settleLink, unlink } from "./oauth-accounts.mjs";
7
+ import { accountsInputs, capturedOAuthService, registrationInputs, registrationIntentInputs, signInInputs } from "./oauth-input.mjs";
8
+ import { coordinateTransactionOwner, makeTransactionExecution, sqlClientTransactionStandaloneGuard } from "./transaction-execution.mjs";
9
+ import { Effect, Layer } from "effect";
10
+ import { LifecycleHooks } from "@yielded/auth/Hooks";
11
+ import { OAuthAccountRevision, OAuthAccountsPersistence, OAuthClaim, OAuthClaimDecision, OAuthCleanupInput, OAuthCredentialSnapshot, OAuthIssueDecision, OAuthLinkClaimDecision, OAuthLinkDecision, OAuthLinkIssueDecision, OAuthLinkPendingFlow, OAuthPendingFlow, OAuthRegistrationFingerprint, OAuthRegistrationIntent, OAuthRegistrationIntents, OAuthSettlementDecision, OAuthSignInPersistence, OAuthUnlinkDecision, OAuthUnlinkInspection, OAuthVerifiedExternalIdentity, snapshotOAuthSync } from "@yielded/auth/OAuth";
12
+ import { eq, sql } from "drizzle-orm";
13
+ //#region src/drizzle/oauth-target.ts
14
+ const sqlClientOAuthStandaloneGuard = (database) => sqlClientTransactionStandaloneGuard(unavailable, database);
15
+ const makeOAuthExecution = (database, hooks, configuration) => {
16
+ const execution = makeTransactionExecution(CurrentOAuthTransaction, database, configuration, unavailable, nonce);
17
+ return {
18
+ ...execution,
19
+ run: (operation, mutation) => execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks))
20
+ };
21
+ };
22
+ const prepareValue = (value, prepare) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.sync(() => {
23
+ owner.guards.push(owner.journal.prepare(void 0));
24
+ return prepare(value, owner.journal);
25
+ }));
26
+ const makeOAuthSignIn = (mapping, execute) => capturedOAuthService({
27
+ issue: (original, prepare) => execute.run(Effect.gen(function* () {
28
+ const input = snapshotOAuthSync(OAuthPendingFlow, original);
29
+ const value = yield* issueFlow(mapping, input, "sign-in");
30
+ return yield* prepareValue(snapshotOAuthSync(OAuthIssueDecision, value), prepare);
31
+ })),
32
+ claim: (input, prepare) => execute.run(Effect.gen(function* () {
33
+ const read = yield* readFlow(mapping, input, "sign-in");
34
+ const claim = read.row !== void 0 && read.flow !== void 0 && matchesAccess(read.flow, input) ? yield* claimFlow(mapping, {
35
+ row: read.row,
36
+ flow: read.flow
37
+ }, input.claimId) : void 0;
38
+ return yield* prepareValue(snapshotOAuthSync(OAuthClaimDecision, claim === void 0 ? { _tag: "Rejected" } : {
39
+ _tag: "Claimed",
40
+ claim
41
+ }), prepare);
42
+ })),
43
+ settle: (original, prepare) => execute.run(Effect.gen(function* () {
44
+ const claim = snapshotOAuthSync(OAuthClaim, original.claim);
45
+ const outcome = original.outcome;
46
+ const identity = outcome._tag === "Verified" ? snapshotOAuthSync(OAuthVerifiedExternalIdentity, outcome.identity).identity : void 0;
47
+ if (identity !== void 0) invariant(identity.provider === claim.flow.context.provider && identity.issuer === claim.flow.context.issuer);
48
+ const found = identity === void 0 ? void 0 : yield* discoverOwned(mapping, identity);
49
+ const exact = yield* exactClaim(mapping, claim, "sign-in");
50
+ let value = { _tag: "Rejected" };
51
+ if (exact !== void 0) {
52
+ const credential = identity === void 0 ? void 0 : resolveOwned(mapping, claim.flow.context.moduleId, identity, found);
53
+ value = outcome._tag !== "Verified" ? { _tag: outcome._tag } : credential === void 0 ? { _tag: "Rejected" } : {
54
+ _tag: "Verified",
55
+ credential
56
+ };
57
+ yield* terminalFlow(mapping, claim.flow, value._tag);
58
+ }
59
+ return yield* prepareValue(snapshotOAuthSync(OAuthSettlementDecision, value), prepare);
60
+ })),
61
+ cleanup: (input, prepare) => execute.run(Effect.gen(function* () {
62
+ const value = yield* cleanupFlows(mapping, input, "sign-in");
63
+ return yield* prepareValue(value, prepare);
64
+ }))
65
+ }, signInInputs, execute.active, execute.poison);
66
+ const makeOAuthRegistrationIntents = (mapping, execute) => capturedOAuthService({ settle: (input, prepare) => execute.run(Effect.gen(function* () {
67
+ const value = yield* settleRegistrationIntent(mapping, {
68
+ claim: snapshotOAuthSync(OAuthClaim, input.claim),
69
+ identity: snapshotOAuthSync(OAuthVerifiedExternalIdentity, input.identity),
70
+ ...input.intent === void 0 ? {} : { intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent) }
71
+ });
72
+ return yield* prepareValue(value, prepare);
73
+ })) }, registrationIntentInputs, execute.active, execute.poison);
74
+ const makeOAuthRegistration = (mapping, execute, allocated) => capturedOAuthService({
75
+ read: (input) => execute.run(Effect.map(inspectIntent(mapping, input), (result) => result?.inspection), false),
76
+ inspect: (input) => Effect.gen(function* () {
77
+ yield* execute.admit;
78
+ const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent);
79
+ const stored = mapping.application.encode(input.registration);
80
+ invariant(typeof stored === "string" && new TextEncoder().encode(stored).length <= 1048576);
81
+ const detached = {
82
+ intent,
83
+ registration: mapping.application.decode(stored)
84
+ };
85
+ const checked = execute.bound ? (invariant(mapping.inspectSync !== void 0), mapping.inspectSync(detached)) : yield* mapping.inspect(detached);
86
+ invariant(typeof checked.eligible === "boolean");
87
+ return {
88
+ fingerprint: snapshotOAuthSync(OAuthRegistrationFingerprint, checked.fingerprint),
89
+ eligible: checked.eligible
90
+ };
91
+ }).pipe((effect) => execute.bound ? execute.run(effect, false) : effect, Effect.onExit((exit) => Effect.sync(() => {
92
+ if (exit._tag === "Failure") execute.poison();
93
+ })), Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable()))),
94
+ register: (input, prepare) => Effect.gen(function* () {
95
+ yield* execute.admit;
96
+ const data = yield* registrationData(mapping, input, execute.bound);
97
+ const resources = allocated ?? (yield* registrationResources(mapping));
98
+ return yield* execute.run(Effect.gen(function* () {
99
+ const value = yield* register(mapping, input, data, resources);
100
+ return yield* prepareValue(value, prepare);
101
+ }));
102
+ }).pipe(Effect.onExit((exit) => Effect.sync(() => {
103
+ if (exit._tag === "Failure") execute.poison();
104
+ })), Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable()))),
105
+ cleanup: (original, prepare) => execute.run(Effect.gen(function* () {
106
+ const owner = yield* CurrentOAuthTransaction;
107
+ const input = snapshotOAuthSync(OAuthCleanupInput, original), i = mapping.intent, r = mapping.command;
108
+ const now = yield* owner.now(mapping.clock);
109
+ const candidates = yield* owner.read(i.table, both(eq(col(i.table, i.moduleId), input.moduleId), sql`${col(i.table, i.state)} <> 'ProvisioningPending' and ${col(i.table, i.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`), {
110
+ limit: input.limit,
111
+ observe: false,
112
+ takeOnly: true
113
+ });
114
+ let removed = 0;
115
+ for (const candidate of candidates.rows) {
116
+ const row = (yield* owner.read(i.table, equal(i.table, {
117
+ [i.moduleId]: input.moduleId,
118
+ [i.reference]: candidate[i.reference]
119
+ }), { limit: 1 })).rows[0];
120
+ if (row === void 0 || row[i.state] === "ProvisioningPending") continue;
121
+ let horizon = mapping.clock.decodeInstant(row[i.retentionUntil]);
122
+ if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock))) continue;
123
+ if (row[i.commandId] !== null) {
124
+ const command = (yield* owner.read(r.table, equal(r.table, {
125
+ [r.moduleId]: input.moduleId,
126
+ [r.commandId]: row[i.commandId]
127
+ }), { limit: 1 })).rows[0];
128
+ if (command === void 0) continue;
129
+ horizon = Math.max(horizon, mapping.clock.decodeInstant(command[r.retentionUntil]));
130
+ if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock))) continue;
131
+ yield* owner.remove(r.table, {
132
+ [r.moduleId]: input.moduleId,
133
+ [r.commandId]: row[i.commandId]
134
+ });
135
+ }
136
+ yield* owner.remove(i.table, {
137
+ [i.moduleId]: input.moduleId,
138
+ [i.reference]: row[i.reference]
139
+ });
140
+ owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);
141
+ removed++;
142
+ }
143
+ return yield* prepareValue({
144
+ removed,
145
+ hasMore: candidates.rows.length === input.limit
146
+ }, prepare);
147
+ }))
148
+ }, registrationInputs(mapping.application), execute.active, execute.poison);
149
+ const makeTargetOAuthSignInServices = (database, mapping, configuration) => {
150
+ const captured = captureOAuthMapping(mapping);
151
+ return Effect.map(LifecycleHooks, (hooks) => ({ oauthSignInPersistence: makeOAuthSignIn(captured, makeOAuthExecution(database, hooks, configuration)) }));
152
+ };
153
+ const makeTargetOAuthRegistrationIntentServices = (database, mapping, configuration) => {
154
+ const captured = captureOAuthMapping(mapping);
155
+ return Effect.map(LifecycleHooks, (hooks) => ({ oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, makeOAuthExecution(database, hooks, configuration)) }));
156
+ };
157
+ const makeTargetOAuthRegistrationServices = (database, mapping, configuration) => {
158
+ const captured = captureOAuthMapping(mapping);
159
+ return Effect.map(LifecycleHooks, (hooks) => ({ registrationAuthority: makeOAuthRegistration(captured, makeOAuthExecution(database, hooks, configuration)) }));
160
+ };
161
+ const coordinateOAuthOwner = (database, mapping, configuration, allocate, services, owner) => {
162
+ const captured = captureOAuthMapping(mapping);
163
+ return Effect.flatMap(LifecycleHooks, (hooks) => coordinateTransactionOwner(database, CurrentOAuthTransaction, configuration, Effect.suspend(() => allocate(captured)), unavailable, nonce, (execution, resources) => services(captured, {
164
+ ...execution,
165
+ run: (operation, mutation) => execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks))
166
+ }, resources), owner).pipe(Effect.provideService(LifecycleHooks, hooks)));
167
+ };
168
+ const accountResources = (mapping) => Effect.gen(function* () {
169
+ return {
170
+ credentialId: snapshotOAuthSync(OAuthCredentialSnapshot.fields.credentialId, yield* mapping.allocateCredentialId),
171
+ revision: snapshotOAuthSync(OAuthCredentialSnapshot.fields.credentialRevision, yield* mapping.allocateRevision)
172
+ };
173
+ });
174
+ const coordinateTargetOAuthRegistration = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, registrationResources, (captured, execute, resources) => ({ registrationAuthority: makeOAuthRegistration(captured, execute, resources) }), owner);
175
+ const coordinateTargetOAuthSignIn = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, () => Effect.void, (captured, execute) => ({ oauthSignInPersistence: makeOAuthSignIn(captured, execute) }), owner);
176
+ const coordinateTargetOAuthRegistrationIntents = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, () => Effect.void, (captured, execute) => ({ oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execute) }), owner);
177
+ const coordinateTargetOAuthAccounts = (database, mapping, configuration, owner) => coordinateOAuthOwner(database, mapping, configuration, accountResources, (captured, execute, resources) => ({ oauthAccountsPersistence: makeOAuthAccounts(captured, execute, resources) }), owner);
178
+ const makeOAuthAccounts = (mapping, execute, resources) => capturedOAuthService({
179
+ capture: (input) => execute.run(Effect.map(accountCurrent(mapping, input.subjectId), (current) => current === void 0 ? void 0 : snapshotOAuthSync(OAuthAccountRevision, current.revision)), false),
180
+ issue: (input, prepare) => execute.run(Effect.gen(function* () {
181
+ const value = yield* issueLink(mapping, input);
182
+ return yield* prepareValue(snapshotOAuthSync(OAuthLinkIssueDecision, value), prepare);
183
+ })),
184
+ preflight: (input) => execute.run(Effect.map(preflightLink(mapping, input), (current) => current === void 0 ? void 0 : snapshotOAuthSync(OAuthLinkPendingFlow, current.flow)), false),
185
+ claim: (input, prepare) => execute.run(Effect.gen(function* () {
186
+ const value = yield* claimLink(mapping, input);
187
+ return yield* prepareValue(snapshotOAuthSync(OAuthLinkClaimDecision, value), prepare);
188
+ })),
189
+ settle: (input, prepare) => Effect.gen(function* () {
190
+ yield* execute.admit;
191
+ const allocated = resources ?? (yield* accountResources(mapping));
192
+ return yield* execute.run(Effect.gen(function* () {
193
+ const value = yield* settleLink(mapping, input, allocated);
194
+ return yield* prepareValue(snapshotOAuthSync(OAuthLinkDecision, value), prepare);
195
+ }));
196
+ }).pipe(Effect.mapError(unavailable), Effect.catchDefect(() => Effect.fail(unavailable()))),
197
+ inspectUnlink: (input) => execute.run(Effect.map(inspectUnlink(mapping, input), (value) => snapshotOAuthSync(OAuthUnlinkInspection, value)), false),
198
+ unlink: (input, prepare) => execute.run(Effect.gen(function* () {
199
+ const value = yield* unlink(mapping, input);
200
+ return yield* prepareValue(snapshotOAuthSync(OAuthUnlinkDecision, value), prepare);
201
+ })),
202
+ cleanup: (input, prepare) => execute.run(Effect.gen(function* () {
203
+ const owner = yield* CurrentOAuthTransaction;
204
+ const value = yield* cleanupFlows(mapping, input, "link");
205
+ const remaining = input.limit - value.terminalized - value.removed;
206
+ const now = yield* owner.now(mapping.clock), r = mapping.command;
207
+ let removed = 0;
208
+ if (remaining > 0) {
209
+ const rows = yield* owner.read(r.table, both(eq(col(r.table, r.moduleId), input.moduleId), sql`${col(r.table, r.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`), {
210
+ limit: remaining,
211
+ observe: false,
212
+ takeOnly: true
213
+ });
214
+ for (const row of rows.rows) {
215
+ const key = {
216
+ [r.moduleId]: input.moduleId,
217
+ [r.commandId]: row[r.commandId]
218
+ };
219
+ const current = (yield* owner.read(r.table, equal(r.table, key), { limit: 1 })).rows[0];
220
+ if (current === void 0) continue;
221
+ const horizon = mapping.clock.decodeInstant(current[r.retentionUntil]);
222
+ if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock))) continue;
223
+ yield* owner.remove(r.table, key);
224
+ owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);
225
+ removed++;
226
+ }
227
+ }
228
+ return yield* prepareValue({
229
+ ...value,
230
+ removed: value.removed + removed,
231
+ hasMore: value.hasMore || remaining === removed
232
+ }, prepare);
233
+ }))
234
+ }, accountsInputs, execute.active, execute.poison);
235
+ const makeTargetOAuthAccountsServices = (database, mapping, configuration) => {
236
+ const captured = captureOAuthMapping(mapping);
237
+ return Effect.map(LifecycleHooks, (hooks) => ({ oauthAccountsPersistence: makeOAuthAccounts(captured, makeOAuthExecution(database, hooks, configuration)) }));
238
+ };
239
+ const oauthAccountsPersistenceLayer = (services) => Layer.effect(OAuthAccountsPersistence, Effect.map(services, (value) => value.oauthAccountsPersistence));
240
+ const oauthSignInPersistenceLayer = (services) => Layer.effect(OAuthSignInPersistence, Effect.map(services, (value) => value.oauthSignInPersistence));
241
+ const oauthRegistrationIntentsLayer = (services) => Layer.effect(OAuthRegistrationIntents, Effect.map(services, (value) => value.oauthRegistrationIntents));
242
+ const oauthRegistrationAuthorityLayer = (tag, services) => Layer.effect(tag, Effect.map(services, (value) => value.registrationAuthority));
243
+ //#endregion
244
+ export { coordinateOAuthOwner, coordinateTargetOAuthAccounts, coordinateTargetOAuthRegistration, coordinateTargetOAuthRegistrationIntents, coordinateTargetOAuthSignIn, makeOAuthAccounts, makeOAuthExecution, makeOAuthRegistration, makeOAuthRegistrationIntents, makeOAuthSignIn, makeTargetOAuthAccountsServices, makeTargetOAuthRegistrationIntentServices, makeTargetOAuthRegistrationServices, makeTargetOAuthSignInServices, oauthAccountsPersistenceLayer, oauthRegistrationAuthorityLayer, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer, sqlClientOAuthStandaloneGuard };
245
+
246
+ //# sourceMappingURL=oauth-target.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-target.mjs","names":[],"sources":["../../src/drizzle/oauth-target.ts"],"sourcesContent":["import { LifecycleHooks } from \"@yielded/auth/Hooks\";\nimport {\n OAuthAccountRevision,\n OAuthLinkClaimDecision,\n OAuthLinkDecision,\n OAuthLinkIssueDecision,\n OAuthLinkPendingFlow,\n OAuthUnlinkDecision,\n OAuthUnlinkInspection,\n OAuthAccountsPersistence,\n OAuthRegistrationIntents,\n OAuthSignInPersistence,\n type PrepareOAuthCommit,\n OAuthRegistrationIntent,\n OAuthRegistrationFingerprint,\n OAuthClaim,\n OAuthClaimDecision,\n OAuthCleanupInput,\n OAuthIssueDecision,\n OAuthPendingFlow,\n OAuthSettlementDecision,\n OAuthVerifiedExternalIdentity,\n OAuthCredentialSnapshot,\n snapshotOAuthSync,\n type OAuthUnavailable,\n} from \"@yielded/auth/OAuth\";\nimport type { SecurityRevision } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- concrete driver entry points restore table/database generics. */\nimport { eq, sql } from \"drizzle-orm\";\nimport { type Context, Effect, Layer } from \"effect\";\nimport type { Statement } from \"effect/unstable/sql/Statement\";\n\nimport type { PersistenceMappingError } from \"./model\";\nimport {\n accountCurrent,\n claimLink,\n inspectUnlink,\n issueLink,\n preflightLink,\n settleLink,\n unlink,\n} from \"./oauth-accounts\";\nimport {\n claimFlow,\n cleanupFlows,\n discoverOwned,\n exactClaim,\n issueFlow,\n matchesAccess,\n readFlow,\n resolveOwned,\n terminalFlow,\n} from \"./oauth-flow\";\nimport {\n accountsInputs,\n capturedOAuthService,\n registrationInputs,\n registrationIntentInputs,\n signInInputs,\n} from \"./oauth-input\";\nimport type { OAuthRegistrationAuthority } from \"./oauth-model\";\nimport { both, col, equal, CurrentOAuthTransaction, type OAuthNativeDatabase } from \"./oauth-owner\";\nimport {\n inspectIntent,\n register,\n registrationData,\n registrationResources,\n type RegistrationCallbacks,\n settleRegistrationIntent,\n} from \"./oauth-registration\";\nimport { captureOAuthMapping, invariant, nonce, unavailable } from \"./oauth-state\";\nimport {\n coordinateTransactionOwner,\n makeTransactionExecution,\n sqlClientTransactionStandaloneGuard,\n type TransactionTargetConfiguration,\n type TransactionCoordinatorError,\n type TransactionExecution,\n} from \"./transaction-execution\";\n\nexport type OAuthTargetConfiguration = TransactionTargetConfiguration<OAuthUnavailable>;\nexport type OAuthCoordinatorError<E> = TransactionCoordinatorError<E, OAuthUnavailable>;\nexport type OAuthExecution = TransactionExecution<OAuthUnavailable, CurrentOAuthTransaction, never>;\n\nexport const sqlClientOAuthStandaloneGuard = (\n database: Parameters<typeof sqlClientTransactionStandaloneGuard>[1],\n) => sqlClientTransactionStandaloneGuard(unavailable, database);\n\nexport const makeOAuthExecution = (\n database: OAuthNativeDatabase,\n hooks: LifecycleHooks[\"Service\"],\n configuration: OAuthTargetConfiguration,\n): OAuthExecution => {\n const execution = makeTransactionExecution(\n CurrentOAuthTransaction,\n database,\n configuration,\n unavailable,\n nonce,\n );\n\n return {\n ...execution,\n run: (operation, mutation) =>\n execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks)),\n };\n};\n\nconst prepareValue = <Value, A>(value: Value, prepare: PrepareOAuthCommit<Value, A>) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.sync(() => {\n owner.guards.push(owner.journal.prepare(undefined));\n\n return prepare(value, owner.journal);\n }),\n );\n\nexport const makeOAuthSignIn = (\n mapping: any,\n execute: OAuthExecution,\n): OAuthSignInPersistence[\"Service\"] =>\n capturedOAuthService<OAuthSignInPersistence[\"Service\"]>(\n {\n issue: (original, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const input = snapshotOAuthSync(OAuthPendingFlow, original);\n const value = yield* issueFlow(mapping, input, \"sign-in\");\n\n return yield* prepareValue(\n snapshotOAuthSync(OAuthIssueDecision, value as never),\n prepare,\n );\n }),\n ),\n claim: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const read = yield* readFlow(mapping, input, \"sign-in\");\n\n const claim =\n read.row !== undefined && read.flow !== undefined && matchesAccess(read.flow, input)\n ? yield* claimFlow(mapping, { row: read.row, flow: read.flow }, input.claimId)\n : undefined;\n\n return yield* prepareValue(\n snapshotOAuthSync(\n OAuthClaimDecision,\n claim === undefined\n ? { _tag: \"Rejected\" }\n : { _tag: \"Claimed\", claim: claim as typeof OAuthClaim.Type },\n ),\n prepare,\n );\n }),\n ),\n settle: (original, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const claim = snapshotOAuthSync(OAuthClaim, original.claim);\n const outcome = original.outcome;\n\n const identity =\n outcome._tag === \"Verified\"\n ? snapshotOAuthSync(OAuthVerifiedExternalIdentity, outcome.identity).identity\n : undefined;\n\n if (identity !== undefined)\n invariant(\n identity.provider === claim.flow.context.provider &&\n identity.issuer === claim.flow.context.issuer,\n );\n\n // Discover/lock the existing subject before locking its claimed flow.\n const found =\n identity === undefined ? undefined : yield* discoverOwned(mapping, identity);\n\n const exact = yield* exactClaim(mapping, claim, \"sign-in\");\n let value: typeof OAuthSettlementDecision.Type = { _tag: \"Rejected\" };\n\n if (exact !== undefined) {\n const credential =\n identity === undefined\n ? undefined\n : resolveOwned(mapping, claim.flow.context.moduleId, identity, found);\n\n value =\n outcome._tag !== \"Verified\"\n ? { _tag: outcome._tag }\n : credential === undefined\n ? { _tag: \"Rejected\" }\n : { _tag: \"Verified\", credential };\n yield* terminalFlow(mapping, claim.flow, value._tag);\n }\n\n return yield* prepareValue(snapshotOAuthSync(OAuthSettlementDecision, value), prepare);\n }),\n ),\n cleanup: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* cleanupFlows(mapping, input, \"sign-in\");\n\n return yield* prepareValue(value, prepare);\n }),\n ),\n },\n signInInputs,\n execute.active,\n execute.poison,\n );\n\nexport const makeOAuthRegistrationIntents = (\n mapping: any,\n execute: OAuthExecution,\n): OAuthRegistrationIntents[\"Service\"] =>\n capturedOAuthService<OAuthRegistrationIntents[\"Service\"]>(\n {\n settle: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* settleRegistrationIntent(mapping, {\n claim: snapshotOAuthSync(OAuthClaim, input.claim),\n identity: snapshotOAuthSync(OAuthVerifiedExternalIdentity, input.identity),\n ...(input.intent === undefined\n ? {}\n : { intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent) }),\n });\n\n return yield* prepareValue(value, prepare);\n }),\n ),\n },\n registrationIntentInputs,\n execute.active,\n execute.poison,\n );\n\nexport const makeOAuthRegistration = <Registration>(\n mapping: any,\n execute: OAuthExecution,\n allocated?: Awaited<ReturnType<typeof registrationResources>> extends Effect.Effect<\n infer A,\n any,\n any\n >\n ? A\n : never,\n): OAuthRegistrationAuthority<Registration> =>\n capturedOAuthService<OAuthRegistrationAuthority<Registration>>(\n {\n read: (input) =>\n execute.run(\n Effect.map(inspectIntent(mapping, input), (result) => result?.inspection),\n false,\n ),\n inspect: (input) =>\n Effect.gen(function* () {\n yield* execute.admit;\n const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent);\n const stored = mapping.application.encode(input.registration);\n\n invariant(\n typeof stored === \"string\" && new TextEncoder().encode(stored).length <= 1048576,\n );\n const detached = { intent, registration: mapping.application.decode(stored) };\n\n const checked = execute.bound\n ? (invariant(mapping.inspectSync !== undefined), mapping.inspectSync(detached))\n : yield* (mapping as RegistrationCallbacks<Registration>).inspect(detached);\n\n invariant(typeof checked.eligible === \"boolean\");\n\n return {\n fingerprint: snapshotOAuthSync(OAuthRegistrationFingerprint, checked.fingerprint),\n eligible: checked.eligible,\n };\n }).pipe(\n (effect) => (execute.bound ? execute.run(effect, false) : effect),\n Effect.onExit((exit) =>\n Effect.sync(() => {\n if (exit._tag === \"Failure\") execute.poison();\n }),\n ),\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ) as never,\n register: (input, prepare) =>\n Effect.gen(function* () {\n yield* execute.admit;\n const data = yield* registrationData(mapping, input, execute.bound);\n const resources = allocated ?? (yield* registrationResources(mapping));\n\n return yield* execute.run(\n Effect.gen(function* () {\n const value = yield* register(mapping, input, data, resources);\n\n return yield* prepareValue(value, prepare);\n }),\n );\n }).pipe(\n Effect.onExit((exit) =>\n Effect.sync(() => {\n if (exit._tag === \"Failure\") execute.poison();\n }),\n ),\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ) as never,\n cleanup: (original, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const owner = yield* CurrentOAuthTransaction;\n\n const input = snapshotOAuthSync(OAuthCleanupInput, original),\n i = mapping.intent,\n r = mapping.command;\n\n const now = yield* owner.now(mapping.clock);\n\n const candidates = yield* owner.read(\n i.table,\n both(\n eq(col(i.table, i.moduleId), input.moduleId),\n sql`${col(i.table, i.state)} <> 'ProvisioningPending' and ${col(i.table, i.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`,\n ),\n { limit: input.limit, observe: false, takeOnly: true },\n );\n\n let removed = 0;\n\n for (const candidate of candidates.rows) {\n const selected = yield* owner.read(\n i.table,\n equal(i.table, {\n [i.moduleId]: input.moduleId,\n [i.reference]: candidate[i.reference],\n }),\n { limit: 1 },\n );\n\n const row = selected.rows[0];\n\n if (row === undefined || row[i.state] === \"ProvisioningPending\") continue;\n let horizon = mapping.clock.decodeInstant(row[i.retentionUntil]);\n\n if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock)))\n continue;\n if (row[i.commandId] !== null) {\n const commands = yield* owner.read(\n r.table,\n equal(r.table, {\n [r.moduleId]: input.moduleId,\n [r.commandId]: row[i.commandId],\n }),\n { limit: 1 },\n );\n\n const command = commands.rows[0];\n\n if (command === undefined) continue;\n horizon = Math.max(horizon, mapping.clock.decodeInstant(command[r.retentionUntil]));\n if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock)))\n continue;\n yield* owner.remove(r.table, {\n [r.moduleId]: input.moduleId,\n [r.commandId]: row[i.commandId],\n });\n }\n yield* owner.remove(i.table, {\n [i.moduleId]: input.moduleId,\n [i.reference]: row[i.reference],\n });\n owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);\n removed++;\n }\n\n return yield* prepareValue(\n { removed, hasMore: candidates.rows.length === input.limit },\n prepare,\n );\n }),\n ),\n },\n registrationInputs(mapping.application),\n execute.active,\n execute.poison,\n );\n\nexport const makeTargetOAuthSignInServices = (\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(LifecycleHooks, (hooks) => ({\n oauthSignInPersistence: makeOAuthSignIn(\n captured,\n makeOAuthExecution(database, hooks, configuration),\n ),\n }));\n};\n\nexport const makeTargetOAuthRegistrationIntentServices = (\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(LifecycleHooks, (hooks) => ({\n oauthRegistrationIntents: makeOAuthRegistrationIntents(\n captured,\n makeOAuthExecution(database, hooks, configuration),\n ),\n }));\n};\n\nexport const makeTargetOAuthRegistrationServices = <Registration>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(LifecycleHooks, (hooks) => ({\n registrationAuthority: makeOAuthRegistration<Registration>(\n captured,\n makeOAuthExecution(database, hooks, configuration),\n ),\n }));\n};\n\nexport const coordinateOAuthOwner = <Services, Transaction, A, E, R>(\n database: OAuthNativeDatabase,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n allocate: (mapping: any) => Effect.Effect<any, PersistenceMappingError>,\n services: (mapping: any, execution: OAuthExecution, resources: any) => Services,\n owner: (\n transaction: Transaction,\n services: Services,\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n): Effect.Effect<A, OAuthCoordinatorError<E>, R | LifecycleHooks> => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.flatMap(LifecycleHooks, (hooks) =>\n coordinateTransactionOwner(\n database,\n CurrentOAuthTransaction,\n configuration,\n Effect.suspend(() => allocate(captured)),\n unavailable,\n nonce,\n (execution, resources) =>\n services(\n captured,\n {\n ...execution,\n run: (operation, mutation) =>\n execution.run(operation, mutation).pipe(Effect.provideService(LifecycleHooks, hooks)),\n },\n resources,\n ),\n owner,\n ).pipe(Effect.provideService(LifecycleHooks, hooks)),\n );\n};\n\nconst accountResources = (mapping: any) =>\n Effect.gen(function* () {\n return {\n credentialId: snapshotOAuthSync(\n OAuthCredentialSnapshot.fields.credentialId,\n yield* mapping.allocateCredentialId as Effect.Effect<string, PersistenceMappingError>,\n ),\n revision: snapshotOAuthSync(\n OAuthCredentialSnapshot.fields.credentialRevision,\n yield* mapping.allocateRevision as Effect.Effect<SecurityRevision, PersistenceMappingError>,\n ),\n };\n });\n\nexport const coordinateTargetOAuthRegistration = <Registration, Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly registrationAuthority: OAuthRegistrationAuthority<Registration> },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n registrationResources,\n (captured, execute, resources) => ({\n registrationAuthority: makeOAuthRegistration<Registration>(captured, execute, resources),\n }),\n owner,\n );\n\nexport const coordinateTargetOAuthSignIn = <Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly oauthSignInPersistence: OAuthSignInPersistence[\"Service\"] },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n () => Effect.void,\n (captured, execute) => ({ oauthSignInPersistence: makeOAuthSignIn(captured, execute) }),\n owner,\n );\n\nexport const coordinateTargetOAuthRegistrationIntents = <Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly oauthRegistrationIntents: OAuthRegistrationIntents[\"Service\"] },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n () => Effect.void,\n (captured, execute) => ({\n oauthRegistrationIntents: makeOAuthRegistrationIntents(captured, execute),\n }),\n owner,\n );\n\nexport const coordinateTargetOAuthAccounts = <Transaction, A, E, R>(\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n owner: (\n transaction: Transaction,\n services: { readonly oauthAccountsPersistence: OAuthAccountsPersistence[\"Service\"] },\n append: (statement: Statement<any>) => void,\n ) => Effect.Effect<A, E, R>,\n) =>\n coordinateOAuthOwner(\n database,\n mapping,\n configuration,\n accountResources,\n (captured, execute, resources) => ({\n oauthAccountsPersistence: makeOAuthAccounts(captured, execute, resources),\n }),\n owner,\n );\n\nexport const makeOAuthAccounts = (\n mapping: any,\n execute: OAuthExecution,\n resources?: any,\n): OAuthAccountsPersistence[\"Service\"] =>\n capturedOAuthService<OAuthAccountsPersistence[\"Service\"]>(\n {\n capture: (input) =>\n execute.run(\n Effect.map(accountCurrent(mapping, input.subjectId), (current) =>\n current === undefined\n ? undefined\n : snapshotOAuthSync(OAuthAccountRevision, current.revision),\n ),\n false,\n ),\n issue: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* issueLink(mapping, input);\n\n return yield* prepareValue(\n snapshotOAuthSync(OAuthLinkIssueDecision, value as never),\n prepare,\n );\n }),\n ),\n preflight: (input) =>\n execute.run(\n Effect.map(preflightLink(mapping, input), (current) =>\n current === undefined\n ? undefined\n : snapshotOAuthSync(OAuthLinkPendingFlow, current.flow),\n ),\n false,\n ),\n claim: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* claimLink(mapping, input);\n\n return yield* prepareValue(\n snapshotOAuthSync(OAuthLinkClaimDecision, value as never),\n prepare,\n );\n }),\n ),\n settle: (input, prepare) =>\n Effect.gen(function* () {\n yield* execute.admit;\n const allocated = resources ?? (yield* accountResources(mapping));\n\n return yield* execute.run(\n Effect.gen(function* () {\n const value = yield* settleLink(mapping, input, allocated as never);\n\n return yield* prepareValue(snapshotOAuthSync(OAuthLinkDecision, value), prepare);\n }),\n );\n }).pipe(\n Effect.mapError(unavailable),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ) as never,\n inspectUnlink: (input) =>\n execute.run(\n Effect.map(inspectUnlink(mapping, input), (value) =>\n snapshotOAuthSync(OAuthUnlinkInspection, value),\n ),\n false,\n ),\n unlink: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const value = yield* unlink(mapping, input);\n\n return yield* prepareValue(snapshotOAuthSync(OAuthUnlinkDecision, value), prepare);\n }),\n ),\n cleanup: (input, prepare) =>\n execute.run(\n Effect.gen(function* () {\n const owner = yield* CurrentOAuthTransaction;\n const value = yield* cleanupFlows(mapping, input, \"link\");\n const remaining = input.limit - value.terminalized - value.removed;\n\n const now = yield* owner.now(mapping.clock),\n r = mapping.command;\n\n let removed = 0;\n\n if (remaining > 0) {\n const rows = yield* owner.read(\n r.table,\n both(\n eq(col(r.table, r.moduleId), input.moduleId),\n sql`${col(r.table, r.retentionUntil)} < ${mapping.clock.encodeInstant(now)}`,\n ),\n { limit: remaining, observe: false, takeOnly: true },\n );\n\n for (const row of rows.rows) {\n const key = { [r.moduleId]: input.moduleId, [r.commandId]: row[r.commandId] };\n const selected = yield* owner.read(r.table, equal(r.table, key), { limit: 1 });\n const current = selected.rows[0];\n\n if (current === undefined) continue;\n const horizon = mapping.clock.decodeInstant(current[r.retentionUntil]);\n\n if (!Number.isSafeInteger(horizon) || horizon >= (yield* owner.now(mapping.clock)))\n continue;\n yield* owner.remove(r.table, key);\n owner.postconditions.push(sql`${mapping.clock.engineNowMillis} > ${horizon}`);\n removed++;\n }\n }\n\n return yield* prepareValue(\n {\n ...value,\n removed: value.removed + removed,\n hasMore: value.hasMore || remaining === removed,\n },\n prepare,\n );\n }),\n ),\n },\n accountsInputs,\n execute.active,\n execute.poison,\n );\n\nexport const makeTargetOAuthAccountsServices = (\n database: any,\n mapping: any,\n configuration: OAuthTargetConfiguration,\n) => {\n const captured = captureOAuthMapping(mapping);\n\n return Effect.map(LifecycleHooks, (hooks) => ({\n oauthAccountsPersistence: makeOAuthAccounts(\n captured,\n makeOAuthExecution(database, hooks, configuration),\n ),\n }));\n};\n\nexport const oauthAccountsPersistenceLayer = (\n services: ReturnType<typeof makeTargetOAuthAccountsServices>,\n) =>\n Layer.effect(\n OAuthAccountsPersistence,\n Effect.map(services, (value) => value.oauthAccountsPersistence),\n );\n\nexport const oauthSignInPersistenceLayer = (\n services: ReturnType<typeof makeTargetOAuthSignInServices>,\n) =>\n Layer.effect(\n OAuthSignInPersistence,\n Effect.map(services, (value) => value.oauthSignInPersistence),\n );\n\nexport const oauthRegistrationIntentsLayer = (\n services: ReturnType<typeof makeTargetOAuthRegistrationIntentServices>,\n) =>\n Layer.effect(\n OAuthRegistrationIntents,\n Effect.map(services, (value) => value.oauthRegistrationIntents),\n );\n\nexport const oauthRegistrationAuthorityLayer = <Id, Registration>(\n tag: Context.Key<Id, OAuthRegistrationAuthority<Registration>>,\n services: Effect.Effect<\n { readonly registrationAuthority: OAuthRegistrationAuthority<Registration> },\n never,\n LifecycleHooks\n >,\n) =>\n Layer.effect(\n tag,\n Effect.map(services, (value) => value.registrationAuthority),\n );\n"],"mappings":";;;;;;;;;;;;;AAoFA,MAAa,iCACX,aACG,oCAAoC,aAAa,QAAQ;AAE9D,MAAa,sBACX,UACA,OACA,kBACmB;CACnB,MAAM,YAAY,yBAChB,yBACA,UACA,eACA,aACA,KACF;CAEA,OAAO;EACL,GAAG;EACH,MAAM,WAAW,aACf,UAAU,IAAI,WAAW,QAAQ,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,KAAK,CAAC;CACxF;AACF;AAEA,MAAM,gBAA0B,OAAc,YAC5C,OAAO,QAAQ,0BAA0B,UACvC,OAAO,WAAW;CAChB,MAAM,OAAO,KAAK,MAAM,QAAQ,QAAQ,KAAA,CAAS,CAAC;CAElD,OAAO,QAAQ,OAAO,MAAM,OAAO;AACrC,CAAC,CACH;AAEF,MAAa,mBACX,SACA,YAEA,qBACE;CACE,QAAQ,UAAU,YAChB,QAAQ,IACN,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,kBAAkB,kBAAkB,QAAQ;EAC1D,MAAM,QAAQ,OAAO,UAAU,SA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J,wBACA,OAAO,IAAI,WAAW,UAAU,MAAM,sBAAsB,CAC9D;AAEF,MAAa,iCACX,aAEA,MAAM,OACJ,0BACA,OAAO,IAAI,WAAW,UAAU,MAAM,wBAAwB,CAChE;AAEF,MAAa,mCACX,KACA,aAMA,MAAM,OACJ,KACA,OAAO,IAAI,WAAW,UAAU,MAAM,qBAAqB,CAC7D"}
@@ -0,0 +1,34 @@
1
+ import { coordinateTargetPasskey, coordinateTargetPasskeyRegistration, makeTargetPasskeyCredentials, makeTargetPasskeyEnrollmentContext, makeTargetPasskeyPersistence, makeTargetPasskeyRegistration } from "./passkey-target.mjs";
2
+ import { makePasskeyWriteTarget } from "./passkey-write-drivers.mjs";
3
+ import { Context, Effect } from "effect";
4
+ import { PasskeyPersistence } from "@yielded/auth/Passkey";
5
+ //#region src/drizzle/passkey-drivers.ts
6
+ const makePasskeyTarget = (configuration) => {
7
+ function coordinatePasskeyPersistence(acquire, options, body) {
8
+ return Effect.flatMap(acquire, (database) => coordinateTargetPasskey(database, options.mapping, configuration, (transaction, services) => {
9
+ const provided = Context.make(PasskeyPersistence, services.passkeyPersistence);
10
+ const work = Effect.provideContext(body, provided);
11
+ return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
12
+ }));
13
+ }
14
+ function coordinatePasskeyRegistrationCeremony(acquire, options, body) {
15
+ return Effect.flatMap(acquire, (database) => coordinateTargetPasskeyRegistration(database, options.mapping, configuration, (transaction, services) => {
16
+ const provided = Context.make(PasskeyPersistence, services.passkeyPersistence);
17
+ const work = Effect.provideContext(body, provided);
18
+ return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
19
+ }));
20
+ }
21
+ return {
22
+ ...makePasskeyWriteTarget(configuration),
23
+ makePasskeyCredentialServices: (database, mapping) => makeTargetPasskeyCredentials(database, mapping, configuration),
24
+ makePasskeyEnrollmentContextServices: (database, mapping) => makeTargetPasskeyEnrollmentContext(database, mapping, configuration),
25
+ makePasskeyPersistenceServices: (database, mapping) => makeTargetPasskeyPersistence(database, mapping, configuration),
26
+ makePasskeyRegistrationCeremonyServices: (database, mapping) => makeTargetPasskeyRegistration(database, mapping, configuration),
27
+ coordinatePasskeyPersistence,
28
+ coordinatePasskeyRegistrationCeremony
29
+ };
30
+ };
31
+ //#endregion
32
+ export { makePasskeyTarget };
33
+
34
+ //# sourceMappingURL=passkey-drivers.mjs.map