@effect-auth/core 0.1.0-alpha.16 → 0.1.0-alpha.19

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 (637) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +307 -133
  3. package/dist/AbuseProtection.d.ts +100 -0
  4. package/dist/AbuseProtection.d.ts.map +1 -0
  5. package/dist/AbuseProtection.js +71 -0
  6. package/dist/AbuseProtection.js.map +1 -0
  7. package/dist/AccessGrant.d.ts +344 -0
  8. package/dist/AccessGrant.d.ts.map +1 -0
  9. package/dist/AccessGrant.js +687 -0
  10. package/dist/AccessGrant.js.map +1 -0
  11. package/dist/ApiKey.d.ts +0 -12
  12. package/dist/ApiKey.d.ts.map +1 -1
  13. package/dist/ApiKey.js +36 -27
  14. package/dist/ApiKey.js.map +1 -1
  15. package/dist/Assurance.d.ts +415 -0
  16. package/dist/Assurance.d.ts.map +1 -0
  17. package/dist/Assurance.js +764 -0
  18. package/dist/Assurance.js.map +1 -0
  19. package/dist/AtomicPlanExecutor.d.ts +28 -0
  20. package/dist/AtomicPlanExecutor.d.ts.map +1 -0
  21. package/dist/AtomicPlanExecutor.js +5 -0
  22. package/dist/AtomicPlanExecutor.js.map +1 -0
  23. package/dist/AuditLog.d.ts +2314 -52
  24. package/dist/AuditLog.d.ts.map +1 -1
  25. package/dist/AuditLog.js +511 -33
  26. package/dist/AuditLog.js.map +1 -1
  27. package/dist/AuthFlow.d.ts +128 -38
  28. package/dist/AuthFlow.d.ts.map +1 -1
  29. package/dist/AuthFlow.js +611 -263
  30. package/dist/AuthFlow.js.map +1 -1
  31. package/dist/AuthRateLimit.d.ts +96 -0
  32. package/dist/AuthRateLimit.d.ts.map +1 -0
  33. package/dist/AuthRateLimit.js +212 -0
  34. package/dist/AuthRateLimit.js.map +1 -0
  35. package/dist/Challenge.d.ts +0 -3
  36. package/dist/Challenge.d.ts.map +1 -1
  37. package/dist/Challenge.js +1 -4
  38. package/dist/Challenge.js.map +1 -1
  39. package/dist/Client.d.ts +205 -10
  40. package/dist/Client.d.ts.map +1 -1
  41. package/dist/Client.js +397 -16
  42. package/dist/Client.js.map +1 -1
  43. package/dist/CloudflareTurnstile.d.ts +28 -0
  44. package/dist/CloudflareTurnstile.d.ts.map +1 -0
  45. package/dist/CloudflareTurnstile.js +205 -0
  46. package/dist/CloudflareTurnstile.js.map +1 -0
  47. package/dist/Crypto.d.ts +0 -3
  48. package/dist/Crypto.d.ts.map +1 -1
  49. package/dist/Crypto.js +1 -4
  50. package/dist/Crypto.js.map +1 -1
  51. package/dist/DelegatedAccessStorageMigrations.d.ts +7 -0
  52. package/dist/DelegatedAccessStorageMigrations.d.ts.map +1 -0
  53. package/dist/DelegatedAccessStorageMigrations.js +159 -0
  54. package/dist/DelegatedAccessStorageMigrations.js.map +1 -0
  55. package/dist/DevEmail.d.ts +44 -0
  56. package/dist/DevEmail.d.ts.map +1 -0
  57. package/dist/DevEmail.js +115 -0
  58. package/dist/DevEmail.js.map +1 -0
  59. package/dist/DevelopmentSeed.d.ts +47 -0
  60. package/dist/DevelopmentSeed.d.ts.map +1 -0
  61. package/dist/DevelopmentSeed.js +337 -0
  62. package/dist/DevelopmentSeed.js.map +1 -0
  63. package/dist/DisposableEmailDomains.d.ts +19 -0
  64. package/dist/DisposableEmailDomains.d.ts.map +1 -0
  65. package/dist/DisposableEmailDomains.js +85 -0
  66. package/dist/DisposableEmailDomains.js.map +1 -0
  67. package/dist/DomainVerification.d.ts +0 -9
  68. package/dist/DomainVerification.d.ts.map +1 -1
  69. package/dist/DomainVerification.js +36 -22
  70. package/dist/DomainVerification.js.map +1 -1
  71. package/dist/DrizzleBunSqliteStorage.d.ts +18 -0
  72. package/dist/DrizzleBunSqliteStorage.d.ts.map +1 -0
  73. package/dist/DrizzleBunSqliteStorage.js +11 -0
  74. package/dist/DrizzleBunSqliteStorage.js.map +1 -0
  75. package/dist/DrizzleD1SqliteStorage.d.ts +4 -4
  76. package/dist/DrizzleD1SqliteStorage.d.ts.map +1 -1
  77. package/dist/DrizzleD1SqliteStorage.js +5 -5
  78. package/dist/DrizzleD1SqliteStorage.js.map +1 -1
  79. package/dist/DrizzleEffectSqliteStorage.d.ts +13 -4
  80. package/dist/DrizzleEffectSqliteStorage.d.ts.map +1 -1
  81. package/dist/DrizzleEffectSqliteStorage.js +71 -4
  82. package/dist/DrizzleEffectSqliteStorage.js.map +1 -1
  83. package/dist/DrizzleNodeSqliteStorage.d.ts +18 -0
  84. package/dist/DrizzleNodeSqliteStorage.d.ts.map +1 -0
  85. package/dist/DrizzleNodeSqliteStorage.js +11 -0
  86. package/dist/DrizzleNodeSqliteStorage.js.map +1 -0
  87. package/dist/DrizzlePostgresStorage.d.ts +26 -0
  88. package/dist/DrizzlePostgresStorage.d.ts.map +1 -0
  89. package/dist/DrizzlePostgresStorage.js +14 -0
  90. package/dist/DrizzlePostgresStorage.js.map +1 -0
  91. package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts +34 -0
  92. package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts.map +1 -0
  93. package/dist/EffectQbPostgresDelegatedAccessStorage.js +499 -0
  94. package/dist/EffectQbPostgresDelegatedAccessStorage.js.map +1 -0
  95. package/dist/EffectQbPostgresStorage.d.ts +178 -0
  96. package/dist/EffectQbPostgresStorage.d.ts.map +1 -0
  97. package/dist/EffectQbPostgresStorage.js +4637 -0
  98. package/dist/EffectQbPostgresStorage.js.map +1 -0
  99. package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts +112 -0
  100. package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts.map +1 -0
  101. package/dist/EffectQbSqliteDelegatedAccessStorage.js +602 -0
  102. package/dist/EffectQbSqliteDelegatedAccessStorage.js.map +1 -0
  103. package/dist/EffectQbSqliteStorage.d.ts +221 -23
  104. package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
  105. package/dist/EffectQbSqliteStorage.js +2064 -135
  106. package/dist/EffectQbSqliteStorage.js.map +1 -1
  107. package/dist/EmailAuth.d.ts +65 -0
  108. package/dist/EmailAuth.d.ts.map +1 -0
  109. package/dist/EmailAuth.js +171 -0
  110. package/dist/EmailAuth.js.map +1 -0
  111. package/dist/EmailIdentityAuth.d.ts +30 -0
  112. package/dist/EmailIdentityAuth.d.ts.map +1 -0
  113. package/dist/EmailIdentityAuth.js +142 -0
  114. package/dist/EmailIdentityAuth.js.map +1 -0
  115. package/dist/EmailOtp.d.ts +10 -11
  116. package/dist/EmailOtp.d.ts.map +1 -1
  117. package/dist/EmailOtp.js +44 -81
  118. package/dist/EmailOtp.js.map +1 -1
  119. package/dist/EmailRisk.d.ts +48 -0
  120. package/dist/EmailRisk.d.ts.map +1 -0
  121. package/dist/EmailRisk.js +33 -0
  122. package/dist/EmailRisk.js.map +1 -0
  123. package/dist/EmailVerification.d.ts +10 -16
  124. package/dist/EmailVerification.d.ts.map +1 -1
  125. package/dist/EmailVerification.js +85 -42
  126. package/dist/EmailVerification.js.map +1 -1
  127. package/dist/Guard.d.ts +11 -0
  128. package/dist/Guard.d.ts.map +1 -0
  129. package/dist/Guard.js +11 -0
  130. package/dist/Guard.js.map +1 -0
  131. package/dist/HibpPwnedPasswords.d.ts +56 -0
  132. package/dist/HibpPwnedPasswords.d.ts.map +1 -0
  133. package/dist/HibpPwnedPasswords.js +232 -0
  134. package/dist/HibpPwnedPasswords.js.map +1 -0
  135. package/dist/HttpApi/AdminPermissionDefinition.d.ts +4 -0
  136. package/dist/HttpApi/AdminPermissionDefinition.d.ts.map +1 -0
  137. package/dist/HttpApi/AdminPermissionDefinition.js +4 -0
  138. package/dist/HttpApi/AdminPermissionDefinition.js.map +1 -0
  139. package/dist/HttpApi/AdminSecurityTimeline.d.ts +4 -0
  140. package/dist/HttpApi/AdminSecurityTimeline.d.ts.map +1 -0
  141. package/dist/HttpApi/AdminSecurityTimeline.js +4 -0
  142. package/dist/HttpApi/AdminSecurityTimeline.js.map +1 -0
  143. package/dist/HttpApi/AdminSession.d.ts +4 -0
  144. package/dist/HttpApi/AdminSession.d.ts.map +1 -0
  145. package/dist/HttpApi/AdminSession.js +4 -0
  146. package/dist/HttpApi/AdminSession.js.map +1 -0
  147. package/dist/HttpApi/AdminTrustedDevice.d.ts +4 -0
  148. package/dist/HttpApi/AdminTrustedDevice.d.ts.map +1 -0
  149. package/dist/HttpApi/AdminTrustedDevice.js +4 -0
  150. package/dist/HttpApi/AdminTrustedDevice.js.map +1 -0
  151. package/dist/HttpApi/Api.d.ts +939 -884
  152. package/dist/HttpApi/Api.d.ts.map +1 -1
  153. package/dist/HttpApi/Api.js +2254 -940
  154. package/dist/HttpApi/Api.js.map +1 -1
  155. package/dist/HttpApi/ApiKey.d.ts +4 -0
  156. package/dist/HttpApi/ApiKey.d.ts.map +1 -0
  157. package/dist/HttpApi/ApiKey.js +4 -0
  158. package/dist/HttpApi/ApiKey.js.map +1 -0
  159. package/dist/HttpApi/Audit.d.ts +6 -0
  160. package/dist/HttpApi/Audit.d.ts.map +1 -0
  161. package/dist/HttpApi/Audit.js +10 -0
  162. package/dist/HttpApi/Audit.js.map +1 -0
  163. package/dist/HttpApi/ClientApi.d.ts +917 -0
  164. package/dist/HttpApi/ClientApi.d.ts.map +1 -0
  165. package/dist/HttpApi/ClientApi.js +101 -0
  166. package/dist/HttpApi/ClientApi.js.map +1 -0
  167. package/dist/HttpApi/EmailAuth.d.ts +6 -0
  168. package/dist/HttpApi/EmailAuth.d.ts.map +1 -0
  169. package/dist/HttpApi/EmailAuth.js +6 -0
  170. package/dist/HttpApi/EmailAuth.js.map +1 -0
  171. package/dist/HttpApi/EmailGuards.d.ts +115 -0
  172. package/dist/HttpApi/EmailGuards.d.ts.map +1 -0
  173. package/dist/HttpApi/EmailGuards.js +191 -0
  174. package/dist/HttpApi/EmailGuards.js.map +1 -0
  175. package/dist/HttpApi/EmailOtp.d.ts +6 -0
  176. package/dist/HttpApi/EmailOtp.d.ts.map +1 -0
  177. package/dist/HttpApi/EmailOtp.js +6 -0
  178. package/dist/HttpApi/EmailOtp.js.map +1 -0
  179. package/dist/HttpApi/EmailVerification.d.ts +6 -0
  180. package/dist/HttpApi/EmailVerification.d.ts.map +1 -0
  181. package/dist/HttpApi/EmailVerification.js +6 -0
  182. package/dist/HttpApi/EmailVerification.js.map +1 -0
  183. package/dist/HttpApi/Endpoints.d.ts +661 -301
  184. package/dist/HttpApi/Endpoints.d.ts.map +1 -1
  185. package/dist/HttpApi/Endpoints.js +207 -120
  186. package/dist/HttpApi/Endpoints.js.map +1 -1
  187. package/dist/HttpApi/Errors.d.ts +37 -10
  188. package/dist/HttpApi/Errors.d.ts.map +1 -1
  189. package/dist/HttpApi/Errors.js +42 -4
  190. package/dist/HttpApi/Errors.js.map +1 -1
  191. package/dist/HttpApi/Identity.d.ts +6 -0
  192. package/dist/HttpApi/Identity.d.ts.map +1 -0
  193. package/dist/HttpApi/Identity.js +6 -0
  194. package/dist/HttpApi/Identity.js.map +1 -0
  195. package/dist/HttpApi/IdentityGuards.d.ts +31 -0
  196. package/dist/HttpApi/IdentityGuards.d.ts.map +1 -0
  197. package/dist/HttpApi/IdentityGuards.js +33 -0
  198. package/dist/HttpApi/IdentityGuards.js.map +1 -0
  199. package/dist/HttpApi/Jwt.d.ts +4 -0
  200. package/dist/HttpApi/Jwt.d.ts.map +1 -0
  201. package/dist/HttpApi/Jwt.js +4 -0
  202. package/dist/HttpApi/Jwt.js.map +1 -0
  203. package/dist/HttpApi/JwtDiscovery.d.ts +4 -0
  204. package/dist/HttpApi/JwtDiscovery.d.ts.map +1 -0
  205. package/dist/HttpApi/JwtDiscovery.js +4 -0
  206. package/dist/HttpApi/JwtDiscovery.js.map +1 -0
  207. package/dist/HttpApi/LoginApproval.d.ts +5 -0
  208. package/dist/HttpApi/LoginApproval.d.ts.map +1 -0
  209. package/dist/HttpApi/LoginApproval.js +5 -0
  210. package/dist/HttpApi/LoginApproval.js.map +1 -0
  211. package/dist/HttpApi/LoginNotification.d.ts +5 -0
  212. package/dist/HttpApi/LoginNotification.d.ts.map +1 -0
  213. package/dist/HttpApi/LoginNotification.js +5 -0
  214. package/dist/HttpApi/LoginNotification.js.map +1 -0
  215. package/dist/HttpApi/MagicLink.d.ts +6 -0
  216. package/dist/HttpApi/MagicLink.d.ts.map +1 -0
  217. package/dist/HttpApi/MagicLink.js +6 -0
  218. package/dist/HttpApi/MagicLink.js.map +1 -0
  219. package/dist/HttpApi/Mfa.d.ts +5 -0
  220. package/dist/HttpApi/Mfa.d.ts.map +1 -0
  221. package/dist/HttpApi/Mfa.js +5 -0
  222. package/dist/HttpApi/Mfa.js.map +1 -0
  223. package/dist/HttpApi/Middleware.d.ts +26 -0
  224. package/dist/HttpApi/Middleware.d.ts.map +1 -0
  225. package/dist/HttpApi/Middleware.js +13 -0
  226. package/dist/HttpApi/Middleware.js.map +1 -0
  227. package/dist/HttpApi/OAuth.d.ts +4 -0
  228. package/dist/HttpApi/OAuth.d.ts.map +1 -0
  229. package/dist/HttpApi/OAuth.js +4 -0
  230. package/dist/HttpApi/OAuth.js.map +1 -0
  231. package/dist/HttpApi/OAuthDeviceAuthorization.d.ts +106 -0
  232. package/dist/HttpApi/OAuthDeviceAuthorization.d.ts.map +1 -0
  233. package/dist/HttpApi/OAuthDeviceAuthorization.js +415 -0
  234. package/dist/HttpApi/OAuthDeviceAuthorization.js.map +1 -0
  235. package/dist/HttpApi/OAuthProviderAuthorization.d.ts +4 -0
  236. package/dist/HttpApi/OAuthProviderAuthorization.d.ts.map +1 -0
  237. package/dist/HttpApi/OAuthProviderAuthorization.js +4 -0
  238. package/dist/HttpApi/OAuthProviderAuthorization.js.map +1 -0
  239. package/dist/HttpApi/OAuthToken.d.ts +4 -0
  240. package/dist/HttpApi/OAuthToken.d.ts.map +1 -0
  241. package/dist/HttpApi/OAuthToken.js +4 -0
  242. package/dist/HttpApi/OAuthToken.js.map +1 -0
  243. package/dist/HttpApi/OidcDiscovery.d.ts +4 -0
  244. package/dist/HttpApi/OidcDiscovery.d.ts.map +1 -0
  245. package/dist/HttpApi/OidcDiscovery.js +4 -0
  246. package/dist/HttpApi/OidcDiscovery.js.map +1 -0
  247. package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts +28 -0
  248. package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts.map +1 -0
  249. package/dist/HttpApi/Operations/AdminPermissionDefinition.js +5 -0
  250. package/dist/HttpApi/Operations/AdminPermissionDefinition.js.map +1 -0
  251. package/dist/HttpApi/Operations/AdminSession.d.ts +16 -0
  252. package/dist/HttpApi/Operations/AdminSession.d.ts.map +1 -0
  253. package/dist/HttpApi/Operations/AdminSession.js +5 -0
  254. package/dist/HttpApi/Operations/AdminSession.js.map +1 -0
  255. package/dist/HttpApi/Operations/ApiKey.d.ts +16 -0
  256. package/dist/HttpApi/Operations/ApiKey.d.ts.map +1 -0
  257. package/dist/HttpApi/Operations/ApiKey.js +5 -0
  258. package/dist/HttpApi/Operations/ApiKey.js.map +1 -0
  259. package/dist/HttpApi/Operations/Discovery.d.ts +19 -0
  260. package/dist/HttpApi/Operations/Discovery.d.ts.map +1 -0
  261. package/dist/HttpApi/Operations/Discovery.js +7 -0
  262. package/dist/HttpApi/Operations/Discovery.js.map +1 -0
  263. package/dist/HttpApi/Operations/EmailAuth.d.ts +12 -0
  264. package/dist/HttpApi/Operations/EmailAuth.d.ts.map +1 -0
  265. package/dist/HttpApi/Operations/EmailAuth.js +5 -0
  266. package/dist/HttpApi/Operations/EmailAuth.js.map +1 -0
  267. package/dist/HttpApi/Operations/EmailOtp.d.ts +14 -0
  268. package/dist/HttpApi/Operations/EmailOtp.d.ts.map +1 -0
  269. package/dist/HttpApi/Operations/EmailOtp.js +5 -0
  270. package/dist/HttpApi/Operations/EmailOtp.js.map +1 -0
  271. package/dist/HttpApi/Operations/EmailVerification.d.ts +14 -0
  272. package/dist/HttpApi/Operations/EmailVerification.d.ts.map +1 -0
  273. package/dist/HttpApi/Operations/EmailVerification.js +5 -0
  274. package/dist/HttpApi/Operations/EmailVerification.js.map +1 -0
  275. package/dist/HttpApi/Operations/HttpOperation.d.ts +4 -0
  276. package/dist/HttpApi/Operations/HttpOperation.d.ts.map +1 -0
  277. package/dist/HttpApi/Operations/HttpOperation.js +2 -0
  278. package/dist/HttpApi/Operations/HttpOperation.js.map +1 -0
  279. package/dist/HttpApi/Operations/Identity.d.ts +22 -0
  280. package/dist/HttpApi/Operations/Identity.d.ts.map +1 -0
  281. package/dist/HttpApi/Operations/Identity.js +5 -0
  282. package/dist/HttpApi/Operations/Identity.js.map +1 -0
  283. package/dist/HttpApi/Operations/Jwt.d.ts +14 -0
  284. package/dist/HttpApi/Operations/Jwt.d.ts.map +1 -0
  285. package/dist/HttpApi/Operations/Jwt.js +5 -0
  286. package/dist/HttpApi/Operations/Jwt.js.map +1 -0
  287. package/dist/HttpApi/Operations/LoginApproval.d.ts +16 -0
  288. package/dist/HttpApi/Operations/LoginApproval.d.ts.map +1 -0
  289. package/dist/HttpApi/Operations/LoginApproval.js +5 -0
  290. package/dist/HttpApi/Operations/LoginApproval.js.map +1 -0
  291. package/dist/HttpApi/Operations/MagicLink.d.ts +14 -0
  292. package/dist/HttpApi/Operations/MagicLink.d.ts.map +1 -0
  293. package/dist/HttpApi/Operations/MagicLink.js +5 -0
  294. package/dist/HttpApi/Operations/MagicLink.js.map +1 -0
  295. package/dist/HttpApi/Operations/Mfa.d.ts +24 -0
  296. package/dist/HttpApi/Operations/Mfa.d.ts.map +1 -0
  297. package/dist/HttpApi/Operations/Mfa.js +5 -0
  298. package/dist/HttpApi/Operations/Mfa.js.map +1 -0
  299. package/dist/HttpApi/Operations/OAuth.d.ts +20 -0
  300. package/dist/HttpApi/Operations/OAuth.d.ts.map +1 -0
  301. package/dist/HttpApi/Operations/OAuth.js +5 -0
  302. package/dist/HttpApi/Operations/OAuth.js.map +1 -0
  303. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts +23 -0
  304. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts.map +1 -0
  305. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js +7 -0
  306. package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js.map +1 -0
  307. package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts +12 -0
  308. package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts.map +1 -0
  309. package/dist/HttpApi/Operations/OAuthProviderAuthorization.js +5 -0
  310. package/dist/HttpApi/Operations/OAuthProviderAuthorization.js.map +1 -0
  311. package/dist/HttpApi/Operations/OAuthToken.d.ts +26 -0
  312. package/dist/HttpApi/Operations/OAuthToken.d.ts.map +1 -0
  313. package/dist/HttpApi/Operations/OAuthToken.js +9 -0
  314. package/dist/HttpApi/Operations/OAuthToken.js.map +1 -0
  315. package/dist/HttpApi/Operations/Passkey.d.ts +22 -0
  316. package/dist/HttpApi/Operations/Passkey.d.ts.map +1 -0
  317. package/dist/HttpApi/Operations/Passkey.js +5 -0
  318. package/dist/HttpApi/Operations/Passkey.js.map +1 -0
  319. package/dist/HttpApi/Operations/Password.d.ts +22 -0
  320. package/dist/HttpApi/Operations/Password.d.ts.map +1 -0
  321. package/dist/HttpApi/Operations/Password.js +5 -0
  322. package/dist/HttpApi/Operations/Password.js.map +1 -0
  323. package/dist/HttpApi/Operations/RecoveryCodes.d.ts +20 -0
  324. package/dist/HttpApi/Operations/RecoveryCodes.d.ts.map +1 -0
  325. package/dist/HttpApi/Operations/RecoveryCodes.js +5 -0
  326. package/dist/HttpApi/Operations/RecoveryCodes.js.map +1 -0
  327. package/dist/HttpApi/Operations/RefreshToken.d.ts +12 -0
  328. package/dist/HttpApi/Operations/RefreshToken.d.ts.map +1 -0
  329. package/dist/HttpApi/Operations/RefreshToken.js +5 -0
  330. package/dist/HttpApi/Operations/RefreshToken.js.map +1 -0
  331. package/dist/HttpApi/Operations/Security.d.ts +12 -0
  332. package/dist/HttpApi/Operations/Security.d.ts.map +1 -0
  333. package/dist/HttpApi/Operations/Security.js +5 -0
  334. package/dist/HttpApi/Operations/Security.js.map +1 -0
  335. package/dist/HttpApi/Operations/SecurityTimeline.d.ts +19 -0
  336. package/dist/HttpApi/Operations/SecurityTimeline.d.ts.map +1 -0
  337. package/dist/HttpApi/Operations/SecurityTimeline.js +7 -0
  338. package/dist/HttpApi/Operations/SecurityTimeline.js.map +1 -0
  339. package/dist/HttpApi/Operations/Session.d.ts +22 -0
  340. package/dist/HttpApi/Operations/Session.d.ts.map +1 -0
  341. package/dist/HttpApi/Operations/Session.js +5 -0
  342. package/dist/HttpApi/Operations/Session.js.map +1 -0
  343. package/dist/HttpApi/Operations/StepUp.d.ts +22 -0
  344. package/dist/HttpApi/Operations/StepUp.d.ts.map +1 -0
  345. package/dist/HttpApi/Operations/StepUp.js +5 -0
  346. package/dist/HttpApi/Operations/StepUp.js.map +1 -0
  347. package/dist/HttpApi/Operations/Totp.d.ts +20 -0
  348. package/dist/HttpApi/Operations/Totp.d.ts.map +1 -0
  349. package/dist/HttpApi/Operations/Totp.js +5 -0
  350. package/dist/HttpApi/Operations/Totp.js.map +1 -0
  351. package/dist/HttpApi/Operations/TrustedDevice.d.ts +23 -0
  352. package/dist/HttpApi/Operations/TrustedDevice.d.ts.map +1 -0
  353. package/dist/HttpApi/Operations/TrustedDevice.js +7 -0
  354. package/dist/HttpApi/Operations/TrustedDevice.js.map +1 -0
  355. package/dist/HttpApi/Operations/index.d.ts +28 -0
  356. package/dist/HttpApi/Operations/index.d.ts.map +1 -0
  357. package/dist/HttpApi/Operations/index.js +28 -0
  358. package/dist/HttpApi/Operations/index.js.map +1 -0
  359. package/dist/HttpApi/Passkey.d.ts +5 -0
  360. package/dist/HttpApi/Passkey.d.ts.map +1 -0
  361. package/dist/HttpApi/Passkey.js +5 -0
  362. package/dist/HttpApi/Passkey.js.map +1 -0
  363. package/dist/HttpApi/Password.d.ts +220 -0
  364. package/dist/HttpApi/Password.d.ts.map +1 -0
  365. package/dist/HttpApi/Password.js +237 -0
  366. package/dist/HttpApi/Password.js.map +1 -0
  367. package/dist/HttpApi/PasswordContract.d.ts +307 -0
  368. package/dist/HttpApi/PasswordContract.d.ts.map +1 -0
  369. package/dist/HttpApi/PasswordContract.js +63 -0
  370. package/dist/HttpApi/PasswordContract.js.map +1 -0
  371. package/dist/HttpApi/PasswordGuards.d.ts +82 -0
  372. package/dist/HttpApi/PasswordGuards.d.ts.map +1 -0
  373. package/dist/HttpApi/PasswordGuards.js +179 -0
  374. package/dist/HttpApi/PasswordGuards.js.map +1 -0
  375. package/dist/HttpApi/RecoveryCodes.d.ts +5 -0
  376. package/dist/HttpApi/RecoveryCodes.d.ts.map +1 -0
  377. package/dist/HttpApi/RecoveryCodes.js +5 -0
  378. package/dist/HttpApi/RecoveryCodes.js.map +1 -0
  379. package/dist/HttpApi/RefreshToken.d.ts +4 -0
  380. package/dist/HttpApi/RefreshToken.d.ts.map +1 -0
  381. package/dist/HttpApi/RefreshToken.js +4 -0
  382. package/dist/HttpApi/RefreshToken.js.map +1 -0
  383. package/dist/HttpApi/RequestGuards.d.ts +42 -0
  384. package/dist/HttpApi/RequestGuards.d.ts.map +1 -0
  385. package/dist/HttpApi/RequestGuards.js +194 -0
  386. package/dist/HttpApi/RequestGuards.js.map +1 -0
  387. package/dist/HttpApi/Schemas.d.ts +399 -84
  388. package/dist/HttpApi/Schemas.d.ts.map +1 -1
  389. package/dist/HttpApi/Schemas.js +225 -27
  390. package/dist/HttpApi/Schemas.js.map +1 -1
  391. package/dist/HttpApi/Security.d.ts +12 -93
  392. package/dist/HttpApi/Security.d.ts.map +1 -1
  393. package/dist/HttpApi/Security.js +65 -356
  394. package/dist/HttpApi/Security.js.map +1 -1
  395. package/dist/HttpApi/SecurityTimeline.d.ts +4 -0
  396. package/dist/HttpApi/SecurityTimeline.d.ts.map +1 -0
  397. package/dist/HttpApi/SecurityTimeline.js +4 -0
  398. package/dist/HttpApi/SecurityTimeline.js.map +1 -0
  399. package/dist/HttpApi/Session.d.ts +5 -0
  400. package/dist/HttpApi/Session.d.ts.map +1 -0
  401. package/dist/HttpApi/Session.js +5 -0
  402. package/dist/HttpApi/Session.js.map +1 -0
  403. package/dist/HttpApi/SessionGuards.d.ts +15 -0
  404. package/dist/HttpApi/SessionGuards.d.ts.map +1 -0
  405. package/dist/HttpApi/SessionGuards.js +37 -0
  406. package/dist/HttpApi/SessionGuards.js.map +1 -0
  407. package/dist/HttpApi/StepUp.d.ts +5 -0
  408. package/dist/HttpApi/StepUp.d.ts.map +1 -0
  409. package/dist/HttpApi/StepUp.js +5 -0
  410. package/dist/HttpApi/StepUp.js.map +1 -0
  411. package/dist/HttpApi/Totp.d.ts +5 -0
  412. package/dist/HttpApi/Totp.d.ts.map +1 -0
  413. package/dist/HttpApi/Totp.js +5 -0
  414. package/dist/HttpApi/Totp.js.map +1 -0
  415. package/dist/HttpApi/Transport.d.ts +4 -6
  416. package/dist/HttpApi/Transport.d.ts.map +1 -1
  417. package/dist/HttpApi/Transport.js +62 -36
  418. package/dist/HttpApi/Transport.js.map +1 -1
  419. package/dist/HttpApi/TrustedDevice.d.ts +4 -0
  420. package/dist/HttpApi/TrustedDevice.d.ts.map +1 -0
  421. package/dist/HttpApi/TrustedDevice.js +4 -0
  422. package/dist/HttpApi/TrustedDevice.js.map +1 -0
  423. package/dist/HttpApi/index.d.ts +11 -3
  424. package/dist/HttpApi/index.d.ts.map +1 -1
  425. package/dist/HttpApi/index.js +10 -2
  426. package/dist/HttpApi/index.js.map +1 -1
  427. package/dist/Identity.d.ts +138 -0
  428. package/dist/Identity.d.ts.map +1 -0
  429. package/dist/Identity.js +105 -0
  430. package/dist/Identity.js.map +1 -0
  431. package/dist/IdentityManagement.d.ts +189 -0
  432. package/dist/IdentityManagement.d.ts.map +1 -0
  433. package/dist/IdentityManagement.js +317 -0
  434. package/dist/IdentityManagement.js.map +1 -0
  435. package/dist/IncidentAction.d.ts +1 -4
  436. package/dist/IncidentAction.d.ts.map +1 -1
  437. package/dist/IncidentAction.js +15 -9
  438. package/dist/IncidentAction.js.map +1 -1
  439. package/dist/Internal.d.ts +2 -0
  440. package/dist/Internal.d.ts.map +1 -1
  441. package/dist/Internal.js +30 -0
  442. package/dist/Internal.js.map +1 -1
  443. package/dist/Invitation.d.ts +362 -0
  444. package/dist/Invitation.d.ts.map +1 -0
  445. package/dist/Invitation.js +633 -0
  446. package/dist/Invitation.js.map +1 -0
  447. package/dist/IpQualityScore.d.ts +38 -0
  448. package/dist/IpQualityScore.d.ts.map +1 -0
  449. package/dist/IpQualityScore.js +215 -0
  450. package/dist/IpQualityScore.js.map +1 -0
  451. package/dist/Jwt.d.ts +8 -29
  452. package/dist/Jwt.d.ts.map +1 -1
  453. package/dist/Jwt.js +67 -56
  454. package/dist/Jwt.js.map +1 -1
  455. package/dist/LoginApproval.d.ts +15 -30
  456. package/dist/LoginApproval.d.ts.map +1 -1
  457. package/dist/LoginApproval.js +47 -41
  458. package/dist/LoginApproval.js.map +1 -1
  459. package/dist/LoginNotification.d.ts +7 -11
  460. package/dist/LoginNotification.d.ts.map +1 -1
  461. package/dist/LoginNotification.js +30 -17
  462. package/dist/LoginNotification.js.map +1 -1
  463. package/dist/LoginRisk.d.ts +11 -13
  464. package/dist/LoginRisk.d.ts.map +1 -1
  465. package/dist/LoginRisk.js +66 -26
  466. package/dist/LoginRisk.js.map +1 -1
  467. package/dist/LoginRiskEnrichment.d.ts +145 -0
  468. package/dist/LoginRiskEnrichment.d.ts.map +1 -0
  469. package/dist/LoginRiskEnrichment.js +220 -0
  470. package/dist/LoginRiskEnrichment.js.map +1 -0
  471. package/dist/MagicLink.d.ts +9 -8
  472. package/dist/MagicLink.d.ts.map +1 -1
  473. package/dist/MagicLink.js +40 -73
  474. package/dist/MagicLink.js.map +1 -1
  475. package/dist/Mailer.d.ts +19 -12
  476. package/dist/Mailer.d.ts.map +1 -1
  477. package/dist/Mailer.js +10 -12
  478. package/dist/Mailer.js.map +1 -1
  479. package/dist/OAuth.d.ts +138 -96
  480. package/dist/OAuth.d.ts.map +1 -1
  481. package/dist/OAuth.js +522 -221
  482. package/dist/OAuth.js.map +1 -1
  483. package/dist/OAuthDeviceAuthorization.d.ts +378 -0
  484. package/dist/OAuthDeviceAuthorization.d.ts.map +1 -0
  485. package/dist/OAuthDeviceAuthorization.js +860 -0
  486. package/dist/OAuthDeviceAuthorization.js.map +1 -0
  487. package/dist/OAuthDeviceClient.d.ts +76 -0
  488. package/dist/OAuthDeviceClient.d.ts.map +1 -0
  489. package/dist/OAuthDeviceClient.js +362 -0
  490. package/dist/OAuthDeviceClient.js.map +1 -0
  491. package/dist/Passkey.d.ts +15 -17
  492. package/dist/Passkey.d.ts.map +1 -1
  493. package/dist/Passkey.js +86 -39
  494. package/dist/Passkey.js.map +1 -1
  495. package/dist/PasskeyBrowser.d.ts +39 -0
  496. package/dist/PasskeyBrowser.d.ts.map +1 -0
  497. package/dist/PasskeyBrowser.js +206 -0
  498. package/dist/PasskeyBrowser.js.map +1 -0
  499. package/dist/PasskeySimpleWebAuthn.d.ts.map +1 -1
  500. package/dist/PasskeySimpleWebAuthn.js +19 -7
  501. package/dist/PasskeySimpleWebAuthn.js.map +1 -1
  502. package/dist/Password.d.ts +71 -37
  503. package/dist/Password.d.ts.map +1 -1
  504. package/dist/Password.js +295 -81
  505. package/dist/Password.js.map +1 -1
  506. package/dist/PasswordRisk.d.ts +63 -0
  507. package/dist/PasswordRisk.d.ts.map +1 -0
  508. package/dist/PasswordRisk.js +37 -0
  509. package/dist/PasswordRisk.js.map +1 -0
  510. package/dist/Permission.d.ts +308 -0
  511. package/dist/Permission.d.ts.map +1 -0
  512. package/dist/Permission.js +827 -0
  513. package/dist/Permission.js.map +1 -0
  514. package/dist/Policy.d.ts +31 -18
  515. package/dist/Policy.d.ts.map +1 -1
  516. package/dist/Policy.js +58 -14
  517. package/dist/Policy.js.map +1 -1
  518. package/dist/PostgresDelegatedAccessStorageMigrations.d.ts +7 -0
  519. package/dist/PostgresDelegatedAccessStorageMigrations.d.ts.map +1 -0
  520. package/dist/PostgresDelegatedAccessStorageMigrations.js +119 -0
  521. package/dist/PostgresDelegatedAccessStorageMigrations.js.map +1 -0
  522. package/dist/PostgresStorageMigrations.d.ts +16 -0
  523. package/dist/PostgresStorageMigrations.d.ts.map +1 -0
  524. package/dist/PostgresStorageMigrations.js +674 -0
  525. package/dist/PostgresStorageMigrations.js.map +1 -0
  526. package/dist/Privacy.d.ts +0 -3
  527. package/dist/Privacy.d.ts.map +1 -1
  528. package/dist/Privacy.js +2 -5
  529. package/dist/Privacy.js.map +1 -1
  530. package/dist/RateLimiter.d.ts +0 -3
  531. package/dist/RateLimiter.d.ts.map +1 -1
  532. package/dist/RateLimiter.js +1 -4
  533. package/dist/RateLimiter.js.map +1 -1
  534. package/dist/RecoveryCode.d.ts +83 -11
  535. package/dist/RecoveryCode.d.ts.map +1 -1
  536. package/dist/RecoveryCode.js +273 -75
  537. package/dist/RecoveryCode.js.map +1 -1
  538. package/dist/RecoveryPolicy.d.ts +81 -0
  539. package/dist/RecoveryPolicy.d.ts.map +1 -0
  540. package/dist/RecoveryPolicy.js +119 -0
  541. package/dist/RecoveryPolicy.js.map +1 -0
  542. package/dist/RefreshToken.d.ts +0 -9
  543. package/dist/RefreshToken.d.ts.map +1 -1
  544. package/dist/RefreshToken.js +31 -22
  545. package/dist/RefreshToken.js.map +1 -1
  546. package/dist/Retention.d.ts +6 -1
  547. package/dist/Retention.d.ts.map +1 -1
  548. package/dist/Retention.js +49 -12
  549. package/dist/Retention.js.map +1 -1
  550. package/dist/SecurityTimeline.d.ts +1 -4
  551. package/dist/SecurityTimeline.d.ts.map +1 -1
  552. package/dist/SecurityTimeline.js +110 -17
  553. package/dist/SecurityTimeline.js.map +1 -1
  554. package/dist/Sessions.d.ts +124 -29
  555. package/dist/Sessions.d.ts.map +1 -1
  556. package/dist/Sessions.js +626 -94
  557. package/dist/Sessions.js.map +1 -1
  558. package/dist/SqliteStorageSchemaData.d.ts +2 -0
  559. package/dist/SqliteStorageSchemaData.d.ts.map +1 -0
  560. package/dist/SqliteStorageSchemaData.js +508 -0
  561. package/dist/SqliteStorageSchemaData.js.map +1 -0
  562. package/dist/StepUp.d.ts +132 -11
  563. package/dist/StepUp.d.ts.map +1 -1
  564. package/dist/StepUp.js +387 -19
  565. package/dist/StepUp.js.map +1 -1
  566. package/dist/Storage.d.ts +89 -23
  567. package/dist/Storage.d.ts.map +1 -1
  568. package/dist/Storage.js +10 -12
  569. package/dist/Storage.js.map +1 -1
  570. package/dist/StorageMigrations.d.ts +7 -1
  571. package/dist/StorageMigrations.d.ts.map +1 -1
  572. package/dist/StorageMigrations.js +256 -0
  573. package/dist/StorageMigrations.js.map +1 -1
  574. package/dist/StorageSchemaGenerator.d.ts +544 -0
  575. package/dist/StorageSchemaGenerator.d.ts.map +1 -0
  576. package/dist/StorageSchemaGenerator.js +1418 -0
  577. package/dist/StorageSchemaGenerator.js.map +1 -0
  578. package/dist/StrongFactor.d.ts +64 -0
  579. package/dist/StrongFactor.d.ts.map +1 -0
  580. package/dist/StrongFactor.js +100 -0
  581. package/dist/StrongFactor.js.map +1 -0
  582. package/dist/Testing.js +2 -2
  583. package/dist/Testing.js.map +1 -1
  584. package/dist/Totp.d.ts +88 -13
  585. package/dist/Totp.d.ts.map +1 -1
  586. package/dist/Totp.js +192 -34
  587. package/dist/Totp.js.map +1 -1
  588. package/dist/TrustedDevice.d.ts +0 -9
  589. package/dist/TrustedDevice.d.ts.map +1 -1
  590. package/dist/TrustedDevice.js +15 -17
  591. package/dist/TrustedDevice.js.map +1 -1
  592. package/dist/WaitUntil.d.ts +0 -3
  593. package/dist/WaitUntil.d.ts.map +1 -1
  594. package/dist/WaitUntil.js +1 -4
  595. package/dist/WaitUntil.js.map +1 -1
  596. package/dist/Webhook.d.ts +42 -12
  597. package/dist/Webhook.d.ts.map +1 -1
  598. package/dist/Webhook.js +165 -26
  599. package/dist/Webhook.js.map +1 -1
  600. package/dist/alchemy/cloudflare/Email.d.ts.map +1 -1
  601. package/dist/alchemy/cloudflare/Email.js +9 -4
  602. package/dist/alchemy/cloudflare/Email.js.map +1 -1
  603. package/dist/cloudflare/Email.js +1 -1
  604. package/dist/cloudflare/Email.js.map +1 -1
  605. package/dist/cloudflare/RequestMetadata.d.ts +49 -0
  606. package/dist/cloudflare/RequestMetadata.d.ts.map +1 -0
  607. package/dist/cloudflare/RequestMetadata.js +71 -0
  608. package/dist/cloudflare/RequestMetadata.js.map +1 -0
  609. package/dist/index.d.ts +0 -35
  610. package/dist/index.d.ts.map +1 -1
  611. package/dist/index.js +0 -35
  612. package/dist/index.js.map +1 -1
  613. package/dist/internal/AuthFlowFinalizer.d.ts +31 -0
  614. package/dist/internal/AuthFlowFinalizer.d.ts.map +1 -0
  615. package/dist/internal/AuthFlowFinalizer.js +182 -0
  616. package/dist/internal/AuthFlowFinalizer.js.map +1 -0
  617. package/migrations/0001_auth_storage.sql +1 -0
  618. package/migrations/0006_auth_totp_factor.sql +1 -0
  619. package/migrations/0024_auth_permission.sql +39 -0
  620. package/migrations/0025_auth_permission_definition.sql +19 -0
  621. package/migrations/0026_auth_user_identity.sql +59 -0
  622. package/migrations/0027_auth_audit_log_storage_order.sql +46 -0
  623. package/migrations/0028_auth_oauth_client_secret_key.sql +39 -0
  624. package/migrations/0029_auth_oauth_device_authorization.sql +28 -0
  625. package/migrations/delegated-access/0001_auth_delegated_access.sql +152 -0
  626. package/migrations/postgres/0001_auth_core.sql +77 -0
  627. package/migrations/postgres/0002_auth_security_oauth.sql +65 -0
  628. package/migrations/postgres/0003_auth_credentials_tokens.sql +43 -0
  629. package/migrations/postgres/0004_auth_security_history.sql +103 -0
  630. package/migrations/postgres/0005_auth_webhooks.sql +29 -0
  631. package/migrations/postgres/0006_auth_domain_timeline.sql +50 -0
  632. package/migrations/postgres/0007_auth_oauth_clients.sql +85 -0
  633. package/migrations/postgres/0008_auth_oauth_tokens.sql +63 -0
  634. package/migrations/postgres/0009_auth_permissions.sql +66 -0
  635. package/migrations/postgres/0010_auth_oauth_device_authorization.sql +50 -0
  636. package/migrations/postgres/delegated-access/0001_auth_delegated_access.sql +112 -0
  637. package/package.json +309 -2
@@ -0,0 +1,687 @@
1
+ import { Array as EffectArray, Brand, Context, Data, Effect, Encoding, Layer, Option, Order, Redacted, Result, Schema, } from "effect";
2
+ import { Crypto } from "./Crypto.js";
3
+ import { UnixMillisSchema } from "./Identifiers.js";
4
+ import { currentUnixMillis } from "./Internal.js";
5
+ import { CurrentPrincipal, PermissionSubject } from "./Permission.js";
6
+ export const AccessGrantId = Brand.nominal();
7
+ export const AccessGrantIdSchema = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{22}$/)).pipe(Schema.brand("auth/AccessGrantId"));
8
+ export const AccessGrantToken = Brand.nominal();
9
+ export const AccessGrantTokenHash = Brand.nominal();
10
+ export const AccessGrantTokenHashSchema = Schema.String.check(Schema.isPattern(/^sha256:.+$/)).pipe(Schema.brand("auth/AccessGrantTokenHash"));
11
+ export const accessGrantTokenVersion = "agr1";
12
+ export const accessGrantIdBytes = 16;
13
+ export const accessGrantSecretBytes = 32;
14
+ const accessGrantIdEncodedLength = Math.ceil((accessGrantIdBytes * 4) / 3);
15
+ const accessGrantSecretEncodedLength = Math.ceil((accessGrantSecretBytes * 4) / 3);
16
+ const accessGrantTokenLength = accessGrantTokenVersion.length +
17
+ accessGrantIdEncodedLength +
18
+ accessGrantSecretEncodedLength +
19
+ 2;
20
+ const accessGrantHashDomain = "effect-auth:access-grant-token:v1\u0000";
21
+ const textEncoder = new TextEncoder();
22
+ export class AccessGrantTokenError extends Data.TaggedError("AccessGrantTokenError") {
23
+ }
24
+ const accessGrantTokenError = (operation, message, cause) => new AccessGrantTokenError({
25
+ operation,
26
+ message,
27
+ ...(cause === undefined ? {} : { cause }),
28
+ });
29
+ const parseTokenSegment = (segment, expectedBytes, expectedEncodedLength, label, operation) => {
30
+ if (segment.length !== expectedEncodedLength ||
31
+ !/^[A-Za-z0-9_-]+$/.test(segment)) {
32
+ return Effect.fail(accessGrantTokenError(operation, `Access grant ${label} is malformed`));
33
+ }
34
+ const decoded = Encoding.decodeBase64Url(segment);
35
+ if (Result.isFailure(decoded) ||
36
+ Encoding.encodeBase64Url(decoded.success) !== segment ||
37
+ decoded.success.length !== expectedBytes) {
38
+ return Effect.fail(accessGrantTokenError(operation, `Access grant ${label} is malformed`));
39
+ }
40
+ return Effect.succeed(decoded.success);
41
+ };
42
+ const parseAccessGrantTokenValue = (value, operation) => Effect.gen(function* () {
43
+ if (value.length !== accessGrantTokenLength) {
44
+ return yield* accessGrantTokenError(operation, "Access grant token is malformed");
45
+ }
46
+ const parts = value.split(".");
47
+ if (parts.length !== 3 || parts[0] !== accessGrantTokenVersion) {
48
+ return yield* accessGrantTokenError(operation, "Access grant token is malformed");
49
+ }
50
+ const id = parts[1] ?? "";
51
+ const secret = parts[2] ?? "";
52
+ yield* parseTokenSegment(id, accessGrantIdBytes, accessGrantIdEncodedLength, "id", operation);
53
+ yield* parseTokenSegment(secret, accessGrantSecretBytes, accessGrantSecretEncodedLength, "secret", operation);
54
+ return { id: AccessGrantId(id) };
55
+ });
56
+ const hashAccessGrantTokenValue = (crypto, value, operation) => crypto.digestSha256({ data: `${accessGrantHashDomain}${value}` }).pipe(Effect.map((hash) => AccessGrantTokenHash(`sha256:${hash}`)), Effect.mapError((cause) => accessGrantTokenError(operation, "Failed to hash access grant token", cause)));
57
+ export class AccessGrantTokens extends Context.Service()("auth/AccessGrantTokens", {
58
+ make: Effect.gen(function* () {
59
+ const crypto = yield* Crypto;
60
+ const randomSegment = (byteLength) => Effect.gen(function* () {
61
+ const bytes = yield* crypto
62
+ .randomBytes(byteLength)
63
+ .pipe(Effect.mapError((cause) => accessGrantTokenError("generate", "Failed to generate access grant token", cause)));
64
+ if (bytes.length !== byteLength) {
65
+ return yield* accessGrantTokenError("generate", "Crypto returned an unexpected access grant token byte length");
66
+ }
67
+ return Encoding.encodeBase64Url(bytes);
68
+ });
69
+ const generateId = Effect.fn("auth.access_grant.tokens.generate_id")(function* () {
70
+ return AccessGrantId(yield* randomSegment(accessGrantIdBytes));
71
+ });
72
+ return {
73
+ generateId,
74
+ generate: Effect.fn("auth.access_grant.tokens.generate")(function* () {
75
+ const id = yield* generateId();
76
+ const secret = yield* randomSegment(accessGrantSecretBytes);
77
+ const token = AccessGrantToken(`${accessGrantTokenVersion}.${id}.${secret}`);
78
+ return { id, token: Redacted.make(token) };
79
+ }),
80
+ parse: Effect.fn("auth.access_grant.tokens.parse")(function* (token) {
81
+ return yield* parseAccessGrantTokenValue(Redacted.value(token), "parse");
82
+ }),
83
+ hash: Effect.fn("auth.access_grant.tokens.hash")(function* (input) {
84
+ const value = Redacted.value(input.token);
85
+ yield* parseAccessGrantTokenValue(value, "hash");
86
+ return yield* hashAccessGrantTokenValue(crypto, value, "hash");
87
+ }),
88
+ verify: Effect.fn("auth.access_grant.tokens.verify")(function* (input) {
89
+ const value = Redacted.value(input.token);
90
+ const parsed = yield* parseAccessGrantTokenValue(value, "verify").pipe(Effect.catchTag("AccessGrantTokenError", () => Effect.succeed(undefined)));
91
+ if (parsed === undefined) {
92
+ return false;
93
+ }
94
+ const hash = yield* hashAccessGrantTokenValue(crypto, value, "verify");
95
+ return yield* crypto
96
+ .timingSafeEqual({
97
+ left: textEncoder.encode(hash),
98
+ right: textEncoder.encode(input.tokenHash),
99
+ })
100
+ .pipe(Effect.mapError((cause) => accessGrantTokenError("verify", "Failed to compare access grant token hashes", cause)));
101
+ }),
102
+ };
103
+ }),
104
+ }) {
105
+ }
106
+ export const AccessGrantTokensSha256Live = Layer.effect(AccessGrantTokens)(AccessGrantTokens.make);
107
+ export const AccessGrantTarget = {
108
+ make: (type, id) => ({ type, id }),
109
+ };
110
+ export const AccessGrantBinding = {
111
+ bearer: () => ({ type: "bearer" }),
112
+ subject: (subject) => ({
113
+ type: "subject",
114
+ subject,
115
+ }),
116
+ subjectAndBearer: (subject) => ({
117
+ type: "subject-and-bearer",
118
+ subject,
119
+ }),
120
+ };
121
+ const hasConsistentAccessGrantLifecycle = (record) => (record.supersededAt !== undefined) ===
122
+ (record.supersededById !== undefined) &&
123
+ Number(record.revokedAt !== undefined) +
124
+ Number(record.supersededAt !== undefined) <=
125
+ 1;
126
+ const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1));
127
+ const DelegatedUnixMillisSchema = UnixMillisSchema.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0));
128
+ const PermissionSubjectSchema = Schema.Struct({
129
+ type: NonEmptyStringSchema,
130
+ id: NonEmptyStringSchema,
131
+ });
132
+ export const AccessGrantJsonObjectSchema = Schema.Record(Schema.String, Schema.Json);
133
+ export const AccessGrantTargetSchema = Schema.Struct({
134
+ type: NonEmptyStringSchema,
135
+ id: NonEmptyStringSchema,
136
+ });
137
+ export const AccessGrantBindingSchema = Schema.Union([
138
+ Schema.Struct({ type: Schema.Literal("bearer") }),
139
+ Schema.Struct({
140
+ type: Schema.Literal("subject"),
141
+ subject: PermissionSubjectSchema,
142
+ }),
143
+ Schema.Struct({
144
+ type: Schema.Literal("subject-and-bearer"),
145
+ subject: PermissionSubjectSchema,
146
+ }),
147
+ ]);
148
+ const AccessGrantCapabilitiesSchema = Schema.Array(NonEmptyStringSchema).check(Schema.isMinLength(1), Schema.makeFilter((capabilities) => new Set(capabilities).size === capabilities.length
149
+ ? undefined
150
+ : "Access grant capabilities must be unique"));
151
+ export const AccessGrantRecordSchema = Schema.Struct({
152
+ id: AccessGrantIdSchema,
153
+ target: AccessGrantTargetSchema,
154
+ capabilities: AccessGrantCapabilitiesSchema,
155
+ binding: AccessGrantBindingSchema,
156
+ issuer: Schema.optional(PermissionSubjectSchema),
157
+ createdAt: DelegatedUnixMillisSchema,
158
+ expiresAt: Schema.optional(DelegatedUnixMillisSchema),
159
+ tokenHash: Schema.optional(AccessGrantTokenHashSchema),
160
+ revokedAt: Schema.optional(DelegatedUnixMillisSchema),
161
+ supersededAt: Schema.optional(DelegatedUnixMillisSchema),
162
+ supersededById: Schema.optional(AccessGrantIdSchema),
163
+ metadata: Schema.optional(AccessGrantJsonObjectSchema),
164
+ }).check(Schema.makeFilter((record) => {
165
+ if (!hasConsistentAccessGrantLifecycle(record)) {
166
+ return "Access grant terminal state is inconsistent";
167
+ }
168
+ if ((record.binding.type === "subject") ===
169
+ (record.tokenHash !== undefined)) {
170
+ return "Access grant credential shape does not match its binding";
171
+ }
172
+ if (record.expiresAt !== undefined &&
173
+ Number(record.expiresAt) <= Number(record.createdAt)) {
174
+ return "Access grant expiry must be later than creation";
175
+ }
176
+ for (const terminalAt of [record.revokedAt, record.supersededAt]) {
177
+ if (terminalAt !== undefined &&
178
+ Number(terminalAt) < Number(record.createdAt)) {
179
+ return "Access grant terminal time must not precede creation";
180
+ }
181
+ }
182
+ return undefined;
183
+ }));
184
+ export const isAccessGrantRecord = Schema.is(AccessGrantRecordSchema);
185
+ const isAccessGrantJsonObject = Schema.is(AccessGrantJsonObjectSchema);
186
+ const cloneMetadata = (metadata) => metadata === undefined ? undefined : structuredClone(metadata);
187
+ const cloneSubject = (subject) => ({
188
+ type: subject.type,
189
+ id: subject.id,
190
+ });
191
+ const cloneTarget = (target) => ({
192
+ type: target.type,
193
+ id: target.id,
194
+ });
195
+ const cloneBinding = (binding) => {
196
+ switch (binding.type) {
197
+ case "bearer": {
198
+ return AccessGrantBinding.bearer();
199
+ }
200
+ case "subject": {
201
+ return AccessGrantBinding.subject(cloneSubject(binding.subject));
202
+ }
203
+ case "subject-and-bearer": {
204
+ return AccessGrantBinding.subjectAndBearer(cloneSubject(binding.subject));
205
+ }
206
+ }
207
+ };
208
+ const cloneAccessGrantBase = (grant) => ({
209
+ id: grant.id,
210
+ target: cloneTarget(grant.target),
211
+ capabilities: [...grant.capabilities],
212
+ ...(grant.issuer === undefined ? {} : { issuer: cloneSubject(grant.issuer) }),
213
+ createdAt: grant.createdAt,
214
+ ...(grant.expiresAt === undefined ? {} : { expiresAt: grant.expiresAt }),
215
+ ...(grant.revokedAt === undefined ? {} : { revokedAt: grant.revokedAt }),
216
+ ...(grant.supersededAt === undefined
217
+ ? {}
218
+ : { supersededAt: grant.supersededAt }),
219
+ ...(grant.supersededById === undefined
220
+ ? {}
221
+ : { supersededById: grant.supersededById }),
222
+ ...(grant.metadata === undefined
223
+ ? {}
224
+ : { metadata: cloneMetadata(grant.metadata) }),
225
+ });
226
+ const cloneAccessGrantRecord = (record) => {
227
+ const base = cloneAccessGrantBase(record);
228
+ if (record.binding.type === "subject") {
229
+ return {
230
+ ...base,
231
+ binding: cloneBinding(record.binding),
232
+ };
233
+ }
234
+ return {
235
+ ...base,
236
+ binding: cloneBinding(record.binding),
237
+ tokenHash: record.tokenHash,
238
+ };
239
+ };
240
+ const safeAccessGrant = (record) => {
241
+ const base = cloneAccessGrantBase(record);
242
+ if (record.binding.type === "subject") {
243
+ return {
244
+ ...base,
245
+ binding: cloneBinding(record.binding),
246
+ };
247
+ }
248
+ return {
249
+ ...base,
250
+ binding: cloneBinding(record.binding),
251
+ };
252
+ };
253
+ const subjectsMatch = (left, right) => left.type === right.type && left.id === right.id;
254
+ const targetsMatch = (left, right) => left.type === right.type && left.id === right.id;
255
+ const boundSubject = (binding) => binding.type === "bearer" ? undefined : binding.subject;
256
+ const isAccessGrantActive = (record, now) => hasConsistentAccessGrantLifecycle(record) &&
257
+ record.revokedAt === undefined &&
258
+ record.supersededAt === undefined &&
259
+ (record.expiresAt === undefined || Number(now) < Number(record.expiresAt));
260
+ export class AccessGrantStoreError extends Data.TaggedError("AccessGrantStoreError") {
261
+ }
262
+ export class AccessGrantStore extends Context.Service()("auth/AccessGrantStore") {
263
+ }
264
+ const compareAccessGrantRecords = (left, right) => {
265
+ const createdAt = Number(left.createdAt) - Number(right.createdAt);
266
+ if (createdAt !== 0) {
267
+ return createdAt < 0 ? -1 : 1;
268
+ }
269
+ return String(left.id) < String(right.id)
270
+ ? -1
271
+ : String(left.id) > String(right.id)
272
+ ? 1
273
+ : 0;
274
+ };
275
+ const AccessGrantRecordOrder = Order.make(compareAccessGrantRecords);
276
+ const accessGrantStoreMemory = Effect.sync(() => {
277
+ const grants = new Map();
278
+ return {
279
+ insert: Effect.fn("auth.access_grant.store.insert")(function* (record) {
280
+ if (!isAccessGrantRecord(record)) {
281
+ return yield* new AccessGrantStoreError({
282
+ operation: "insert",
283
+ message: "Access grant record is invalid",
284
+ });
285
+ }
286
+ if (grants.has(record.id)) {
287
+ return false;
288
+ }
289
+ grants.set(record.id, cloneAccessGrantRecord(record));
290
+ return true;
291
+ }),
292
+ findById: Effect.fn("auth.access_grant.store.find_by_id")((id) => Effect.sync(() => {
293
+ const record = grants.get(id);
294
+ return record === undefined
295
+ ? Option.none()
296
+ : Option.some(cloneAccessGrantRecord(record));
297
+ })),
298
+ list: Effect.fn("auth.access_grant.store.list")((input) => Effect.sync(() => EffectArray.sort([...grants.values()].filter((record) => (input?.target === undefined ||
299
+ targetsMatch(record.target, input.target)) &&
300
+ (input?.issuer === undefined ||
301
+ (record.issuer !== undefined &&
302
+ subjectsMatch(record.issuer, input.issuer))) &&
303
+ (input?.subject === undefined ||
304
+ (boundSubject(record.binding) !== undefined &&
305
+ subjectsMatch(boundSubject(record.binding), input.subject)))), AccessGrantRecordOrder).map(cloneAccessGrantRecord))),
306
+ revoke: Effect.fn("auth.access_grant.store.revoke")(function* (input) {
307
+ const current = grants.get(input.id);
308
+ if (current === undefined ||
309
+ !isAccessGrantActive(current, input.revokedAt)) {
310
+ return Option.none();
311
+ }
312
+ const revoked = {
313
+ ...current,
314
+ revokedAt: input.revokedAt,
315
+ };
316
+ if (!isAccessGrantRecord(revoked)) {
317
+ return yield* new AccessGrantStoreError({
318
+ operation: "revoke",
319
+ message: "Revoked access grant record is invalid",
320
+ });
321
+ }
322
+ grants.set(input.id, revoked);
323
+ return Option.some(cloneAccessGrantRecord(revoked));
324
+ }),
325
+ supersede: Effect.fn("auth.access_grant.store.supersede")(function* (input) {
326
+ if (!isAccessGrantRecord(input.replacement)) {
327
+ return yield* new AccessGrantStoreError({
328
+ operation: "supersede",
329
+ message: "Replacement access grant record is invalid",
330
+ });
331
+ }
332
+ const current = grants.get(input.id);
333
+ if (current === undefined ||
334
+ grants.has(input.replacement.id) ||
335
+ !isAccessGrantActive(current, input.supersededAt)) {
336
+ return Option.none();
337
+ }
338
+ const previous = {
339
+ ...current,
340
+ supersededAt: input.supersededAt,
341
+ supersededById: input.replacement.id,
342
+ };
343
+ if (!isAccessGrantRecord(previous)) {
344
+ return yield* new AccessGrantStoreError({
345
+ operation: "supersede",
346
+ message: "Superseded access grant record is invalid",
347
+ });
348
+ }
349
+ const replacement = cloneAccessGrantRecord(input.replacement);
350
+ grants.set(previous.id, previous);
351
+ grants.set(replacement.id, replacement);
352
+ return Option.some({
353
+ previous: cloneAccessGrantRecord(previous),
354
+ replacement: cloneAccessGrantRecord(replacement),
355
+ });
356
+ }),
357
+ };
358
+ });
359
+ export const AccessGrantStoreMemoryLive = Layer.effect(AccessGrantStore)(accessGrantStoreMemory);
360
+ export class AccessGrantManagementError extends Data.TaggedError("AccessGrantManagementError") {
361
+ }
362
+ const managementError = (operation, reason, message, cause) => new AccessGrantManagementError({
363
+ operation,
364
+ reason,
365
+ message,
366
+ ...(cause === undefined ? {} : { cause }),
367
+ });
368
+ const validateText = (value, label, operation) => value.trim().length > 0
369
+ ? Effect.void
370
+ : Effect.fail(managementError(operation, "invalid_input", `${label} must not be empty`));
371
+ const validateTarget = (target, operation) => Effect.gen(function* () {
372
+ yield* validateText(target.type, "Access grant target type", operation);
373
+ yield* validateText(target.id, "Access grant target id", operation);
374
+ });
375
+ const validateSubject = (subject, label, operation) => Effect.gen(function* () {
376
+ yield* validateText(subject.type, `${label} type`, operation);
377
+ yield* validateText(subject.id, `${label} id`, operation);
378
+ });
379
+ const validateCapabilities = (capabilities, operation) => Effect.gen(function* () {
380
+ if (capabilities.length === 0) {
381
+ return yield* managementError(operation, "invalid_input", "Access grant capabilities must not be empty");
382
+ }
383
+ const seen = new Set();
384
+ for (const capability of capabilities) {
385
+ if (capability.trim().length === 0) {
386
+ return yield* managementError(operation, "invalid_input", "Access grant capability must not be empty");
387
+ }
388
+ if (seen.has(capability)) {
389
+ return yield* managementError(operation, "invalid_input", "Access grant capabilities must not contain duplicates");
390
+ }
391
+ seen.add(capability);
392
+ }
393
+ return [...capabilities];
394
+ });
395
+ const validateExpiry = (expiresAt, now, operation) => {
396
+ if (expiresAt === undefined) {
397
+ return Effect.void;
398
+ }
399
+ const value = Number(expiresAt);
400
+ return Number.isSafeInteger(value) && value > Number(now)
401
+ ? Effect.void
402
+ : Effect.fail(managementError(operation, "invalid_input", "Access grant expiry must be later than the current time"));
403
+ };
404
+ const validateMetadata = (metadata, operation) => metadata === undefined || isAccessGrantJsonObject(metadata)
405
+ ? Effect.void
406
+ : Effect.fail(managementError(operation, "invalid_input", "Access grant metadata must be JSON-compatible"));
407
+ const prepareAccessGrantCredential = (tokens, binding, operation) => Effect.gen(function* () {
408
+ if (binding.type === "subject") {
409
+ const id = yield* tokens
410
+ .generateId()
411
+ .pipe(Effect.mapError((cause) => managementError(operation, "token", "Failed to generate access grant id", cause)));
412
+ return { type: "subject", id };
413
+ }
414
+ const generated = yield* tokens
415
+ .generate()
416
+ .pipe(Effect.mapError((cause) => managementError(operation, "token", "Failed to generate access grant token", cause)));
417
+ const tokenHash = yield* tokens
418
+ .hash({ token: generated.token })
419
+ .pipe(Effect.mapError((cause) => managementError(operation, "token", "Failed to hash access grant token", cause)));
420
+ return {
421
+ type: "bearer",
422
+ id: generated.id,
423
+ token: generated.token,
424
+ tokenHash,
425
+ };
426
+ });
427
+ const preparedAccessGrantRecord = (base, credential) => {
428
+ if (credential.type === "subject") {
429
+ return {
430
+ ...base,
431
+ id: credential.id,
432
+ target: cloneTarget(base.target),
433
+ capabilities: [...base.capabilities],
434
+ binding: cloneBinding(base.binding),
435
+ };
436
+ }
437
+ return {
438
+ ...base,
439
+ id: credential.id,
440
+ target: cloneTarget(base.target),
441
+ capabilities: [...base.capabilities],
442
+ binding: cloneBinding(base.binding),
443
+ tokenHash: credential.tokenHash,
444
+ };
445
+ };
446
+ const issuedAccessGrant = (record, credential) => {
447
+ const grant = safeAccessGrant(record);
448
+ return credential.type === "subject"
449
+ ? {
450
+ grant: grant,
451
+ }
452
+ : {
453
+ grant: grant,
454
+ token: credential.token,
455
+ };
456
+ };
457
+ const accessGrantLifecycleReason = (record, now) => !hasConsistentAccessGrantLifecycle(record)
458
+ ? "invalid-record"
459
+ : record.revokedAt !== undefined
460
+ ? "revoked"
461
+ : record.supersededAt !== undefined
462
+ ? "superseded"
463
+ : record.expiresAt !== undefined &&
464
+ Number(now) >= Number(record.expiresAt)
465
+ ? "expired"
466
+ : undefined;
467
+ export class AccessGrantManagement extends Context.Service()("auth/AccessGrantManagement", {
468
+ make: Effect.gen(function* () {
469
+ const tokens = yield* AccessGrantTokens;
470
+ const store = yield* AccessGrantStore;
471
+ const storeError = (operation, message, effect) => effect.pipe(Effect.mapError((cause) => managementError(operation, "storage", message, cause)));
472
+ return {
473
+ issue: Effect.fn("auth.access_grant.management.issue")(function* (input) {
474
+ const now = yield* currentUnixMillis;
475
+ yield* validateTarget(input.target, "issue");
476
+ const capabilities = yield* validateCapabilities(input.capabilities, "issue");
477
+ if (input.binding.type !== "bearer") {
478
+ yield* validateSubject(input.binding.subject, "Access grant binding subject", "issue");
479
+ }
480
+ if (input.issuer !== undefined) {
481
+ yield* validateSubject(input.issuer, "Access grant issuer", "issue");
482
+ }
483
+ yield* validateExpiry(input.expiresAt, now, "issue");
484
+ yield* validateMetadata(input.metadata, "issue");
485
+ const credential = yield* prepareAccessGrantCredential(tokens, input.binding, "issue");
486
+ const record = preparedAccessGrantRecord({
487
+ target: input.target,
488
+ capabilities,
489
+ binding: input.binding,
490
+ ...(input.issuer === undefined ? {} : { issuer: input.issuer }),
491
+ createdAt: now,
492
+ ...(input.expiresAt === undefined
493
+ ? {}
494
+ : { expiresAt: input.expiresAt }),
495
+ ...(input.metadata === undefined
496
+ ? {}
497
+ : { metadata: input.metadata }),
498
+ }, credential);
499
+ const inserted = yield* storeError("issue", "Failed to store access grant", store.insert(record));
500
+ if (!inserted) {
501
+ return yield* managementError("issue", "conflict", "Access grant id already exists");
502
+ }
503
+ return issuedAccessGrant(record, credential);
504
+ }),
505
+ list: Effect.fn("auth.access_grant.management.list")(function* (input) {
506
+ const records = yield* storeError("list", "Failed to list access grants", store.list(input));
507
+ const activity = input?.activity ?? "active";
508
+ if (activity === "all") {
509
+ return records.map(safeAccessGrant);
510
+ }
511
+ const now = yield* currentUnixMillis;
512
+ return records
513
+ .filter((record) => (accessGrantLifecycleReason(record, now) === undefined) ===
514
+ (activity === "active"))
515
+ .map(safeAccessGrant);
516
+ }),
517
+ get: Effect.fn("auth.access_grant.management.get")(function* (id) {
518
+ const record = yield* storeError("get", "Failed to load access grant", store.findById(id));
519
+ return Option.map(record, safeAccessGrant);
520
+ }),
521
+ revoke: Effect.fn("auth.access_grant.management.revoke")(function* (input) {
522
+ const revokedAt = yield* currentUnixMillis;
523
+ const revoked = yield* storeError("revoke", "Failed to revoke access grant", store.revoke({ id: input.id, revokedAt }));
524
+ if (Option.isSome(revoked)) {
525
+ return safeAccessGrant(revoked.value);
526
+ }
527
+ const current = yield* storeError("revoke", "Failed to reload access grant", store.findById(input.id));
528
+ return yield* managementError("revoke", Option.isNone(current) ? "not_found" : "inactive", Option.isNone(current)
529
+ ? "Access grant was not found"
530
+ : "Access grant is not active");
531
+ }),
532
+ supersede: Effect.fn("auth.access_grant.management.supersede")(function* (input) {
533
+ const now = yield* currentUnixMillis;
534
+ const currentOption = yield* storeError("supersede", "Failed to load access grant", store.findById(input.id));
535
+ if (Option.isNone(currentOption)) {
536
+ return yield* managementError("supersede", "not_found", "Access grant was not found");
537
+ }
538
+ const current = currentOption.value;
539
+ if (accessGrantLifecycleReason(current, now) !== undefined) {
540
+ return yield* managementError("supersede", "inactive", "Access grant is not active");
541
+ }
542
+ const expiresAt = input.expiresAt ?? current.expiresAt;
543
+ yield* validateExpiry(expiresAt, now, "supersede");
544
+ yield* validateMetadata(input.metadata, "supersede");
545
+ const credential = yield* prepareAccessGrantCredential(tokens, current.binding, "supersede");
546
+ const replacement = preparedAccessGrantRecord({
547
+ target: current.target,
548
+ capabilities: current.capabilities,
549
+ binding: current.binding,
550
+ ...(current.issuer === undefined
551
+ ? {}
552
+ : { issuer: current.issuer }),
553
+ createdAt: now,
554
+ ...(expiresAt === undefined ? {} : { expiresAt }),
555
+ metadata: input.metadata ?? current.metadata,
556
+ }, credential);
557
+ const superseded = yield* storeError("supersede", "Failed to supersede access grant", store.supersede({
558
+ id: current.id,
559
+ supersededAt: now,
560
+ replacement,
561
+ }));
562
+ if (Option.isNone(superseded)) {
563
+ return yield* managementError("supersede", "conflict", "Access grant changed while it was being superseded");
564
+ }
565
+ const issued = issuedAccessGrant(superseded.value.replacement, credential);
566
+ return {
567
+ ...issued,
568
+ previous: safeAccessGrant(superseded.value.previous),
569
+ };
570
+ }),
571
+ };
572
+ }),
573
+ }) {
574
+ }
575
+ export const AccessGrantManagementLive = Layer.effect(AccessGrantManagement)(AccessGrantManagement.make);
576
+ export class AccessGrantAuthorizationError extends Data.TaggedError("AccessGrantAuthorizationError") {
577
+ }
578
+ /** Expected authorization denials from `require`; operational failures stay separate. */
579
+ export class AccessGrantDeniedError extends Data.TaggedError("AccessGrantDeniedError") {
580
+ }
581
+ const denied = (reason, grantId) => ({
582
+ type: "denied",
583
+ reason,
584
+ ...(grantId === undefined ? {} : { grantId }),
585
+ });
586
+ const authorizationError = (kind, message, cause) => new AccessGrantAuthorizationError({
587
+ operation: "check",
588
+ kind,
589
+ message,
590
+ cause,
591
+ });
592
+ const resolveAccessGrantReference = (tokens, input) => Effect.gen(function* () {
593
+ if (input.bearerToken === undefined) {
594
+ return input.grantId ?? denied("grant-id-required");
595
+ }
596
+ const parsed = yield* tokens.parse(input.bearerToken).pipe(Effect.option);
597
+ if (Option.isNone(parsed)) {
598
+ return denied("malformed-token", input.grantId);
599
+ }
600
+ if (input.grantId !== undefined && input.grantId !== parsed.value.id) {
601
+ return denied("grant-reference-mismatch", input.grantId);
602
+ }
603
+ return input.grantId ?? parsed.value.id;
604
+ });
605
+ export class AccessGrants extends Context.Service()("auth/AccessGrants", {
606
+ make: Effect.gen(function* () {
607
+ const tokens = yield* AccessGrantTokens;
608
+ const store = yield* AccessGrantStore;
609
+ const check = Effect.fn("auth.access_grant.check")(function* (input) {
610
+ const reference = yield* resolveAccessGrantReference(tokens, input);
611
+ if (typeof reference !== "string") {
612
+ return reference;
613
+ }
614
+ const grantId = reference;
615
+ const recordOption = yield* store
616
+ .findById(grantId)
617
+ .pipe(Effect.mapError((cause) => authorizationError("store", "Failed to load access grant", cause)));
618
+ if (Option.isNone(recordOption)) {
619
+ return denied("grant-not-found", grantId);
620
+ }
621
+ const record = recordOption.value;
622
+ if (!isAccessGrantRecord(record)) {
623
+ return denied("invalid-record", grantId);
624
+ }
625
+ if (record.binding.type === "subject" && input.grantId === undefined) {
626
+ return denied("grant-id-required");
627
+ }
628
+ if (record.binding.type !== "subject") {
629
+ if (input.bearerToken === undefined) {
630
+ return denied("bearer-required", grantId);
631
+ }
632
+ const valid = yield* tokens
633
+ .verify({
634
+ token: input.bearerToken,
635
+ tokenHash: record.tokenHash,
636
+ })
637
+ .pipe(Effect.mapError((cause) => authorizationError("token", "Failed to verify access grant token", cause)));
638
+ if (!valid) {
639
+ return denied("invalid-bearer", grantId);
640
+ }
641
+ }
642
+ if (record.binding.type !== "bearer") {
643
+ const principal = yield* Effect.serviceOption(CurrentPrincipal);
644
+ if (Option.isNone(principal)) {
645
+ return denied("subject-required", grantId);
646
+ }
647
+ if (!subjectsMatch(record.binding.subject, principal.value)) {
648
+ return denied("subject-mismatch", grantId);
649
+ }
650
+ }
651
+ const now = yield* currentUnixMillis;
652
+ const lifecycleReason = accessGrantLifecycleReason(record, now);
653
+ if (lifecycleReason !== undefined) {
654
+ return denied(lifecycleReason, grantId);
655
+ }
656
+ if (!targetsMatch(record.target, input.target)) {
657
+ return denied("target-mismatch", grantId);
658
+ }
659
+ if (!record.capabilities.includes(input.action)) {
660
+ return denied("capability-missing", grantId);
661
+ }
662
+ return {
663
+ type: "allowed",
664
+ grant: safeAccessGrant(record),
665
+ principal: PermissionSubject.make("access-grant", record.id),
666
+ };
667
+ });
668
+ return {
669
+ check,
670
+ require: Effect.fn("auth.access_grant.require")(function* (input) {
671
+ const decision = yield* check(input);
672
+ if (decision.type === "denied") {
673
+ return yield* new AccessGrantDeniedError({
674
+ reason: decision.reason,
675
+ ...(decision.grantId === undefined
676
+ ? {}
677
+ : { grantId: decision.grantId }),
678
+ });
679
+ }
680
+ return decision;
681
+ }),
682
+ };
683
+ }),
684
+ }) {
685
+ }
686
+ export const AccessGrantsLive = Layer.effect(AccessGrants)(AccessGrants.make);
687
+ //# sourceMappingURL=AccessGrant.js.map