@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.
- package/LICENSE +21 -0
- package/README.md +307 -133
- package/dist/AbuseProtection.d.ts +100 -0
- package/dist/AbuseProtection.d.ts.map +1 -0
- package/dist/AbuseProtection.js +71 -0
- package/dist/AbuseProtection.js.map +1 -0
- package/dist/AccessGrant.d.ts +344 -0
- package/dist/AccessGrant.d.ts.map +1 -0
- package/dist/AccessGrant.js +687 -0
- package/dist/AccessGrant.js.map +1 -0
- package/dist/ApiKey.d.ts +0 -12
- package/dist/ApiKey.d.ts.map +1 -1
- package/dist/ApiKey.js +36 -27
- package/dist/ApiKey.js.map +1 -1
- package/dist/Assurance.d.ts +415 -0
- package/dist/Assurance.d.ts.map +1 -0
- package/dist/Assurance.js +764 -0
- package/dist/Assurance.js.map +1 -0
- package/dist/AtomicPlanExecutor.d.ts +28 -0
- package/dist/AtomicPlanExecutor.d.ts.map +1 -0
- package/dist/AtomicPlanExecutor.js +5 -0
- package/dist/AtomicPlanExecutor.js.map +1 -0
- package/dist/AuditLog.d.ts +2314 -52
- package/dist/AuditLog.d.ts.map +1 -1
- package/dist/AuditLog.js +511 -33
- package/dist/AuditLog.js.map +1 -1
- package/dist/AuthFlow.d.ts +128 -38
- package/dist/AuthFlow.d.ts.map +1 -1
- package/dist/AuthFlow.js +611 -263
- package/dist/AuthFlow.js.map +1 -1
- package/dist/AuthRateLimit.d.ts +96 -0
- package/dist/AuthRateLimit.d.ts.map +1 -0
- package/dist/AuthRateLimit.js +212 -0
- package/dist/AuthRateLimit.js.map +1 -0
- package/dist/Challenge.d.ts +0 -3
- package/dist/Challenge.d.ts.map +1 -1
- package/dist/Challenge.js +1 -4
- package/dist/Challenge.js.map +1 -1
- package/dist/Client.d.ts +205 -10
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +397 -16
- package/dist/Client.js.map +1 -1
- package/dist/CloudflareTurnstile.d.ts +28 -0
- package/dist/CloudflareTurnstile.d.ts.map +1 -0
- package/dist/CloudflareTurnstile.js +205 -0
- package/dist/CloudflareTurnstile.js.map +1 -0
- package/dist/Crypto.d.ts +0 -3
- package/dist/Crypto.d.ts.map +1 -1
- package/dist/Crypto.js +1 -4
- package/dist/Crypto.js.map +1 -1
- package/dist/DelegatedAccessStorageMigrations.d.ts +7 -0
- package/dist/DelegatedAccessStorageMigrations.d.ts.map +1 -0
- package/dist/DelegatedAccessStorageMigrations.js +159 -0
- package/dist/DelegatedAccessStorageMigrations.js.map +1 -0
- package/dist/DevEmail.d.ts +44 -0
- package/dist/DevEmail.d.ts.map +1 -0
- package/dist/DevEmail.js +115 -0
- package/dist/DevEmail.js.map +1 -0
- package/dist/DevelopmentSeed.d.ts +47 -0
- package/dist/DevelopmentSeed.d.ts.map +1 -0
- package/dist/DevelopmentSeed.js +337 -0
- package/dist/DevelopmentSeed.js.map +1 -0
- package/dist/DisposableEmailDomains.d.ts +19 -0
- package/dist/DisposableEmailDomains.d.ts.map +1 -0
- package/dist/DisposableEmailDomains.js +85 -0
- package/dist/DisposableEmailDomains.js.map +1 -0
- package/dist/DomainVerification.d.ts +0 -9
- package/dist/DomainVerification.d.ts.map +1 -1
- package/dist/DomainVerification.js +36 -22
- package/dist/DomainVerification.js.map +1 -1
- package/dist/DrizzleBunSqliteStorage.d.ts +18 -0
- package/dist/DrizzleBunSqliteStorage.d.ts.map +1 -0
- package/dist/DrizzleBunSqliteStorage.js +11 -0
- package/dist/DrizzleBunSqliteStorage.js.map +1 -0
- package/dist/DrizzleD1SqliteStorage.d.ts +4 -4
- package/dist/DrizzleD1SqliteStorage.d.ts.map +1 -1
- package/dist/DrizzleD1SqliteStorage.js +5 -5
- package/dist/DrizzleD1SqliteStorage.js.map +1 -1
- package/dist/DrizzleEffectSqliteStorage.d.ts +13 -4
- package/dist/DrizzleEffectSqliteStorage.d.ts.map +1 -1
- package/dist/DrizzleEffectSqliteStorage.js +71 -4
- package/dist/DrizzleEffectSqliteStorage.js.map +1 -1
- package/dist/DrizzleNodeSqliteStorage.d.ts +18 -0
- package/dist/DrizzleNodeSqliteStorage.d.ts.map +1 -0
- package/dist/DrizzleNodeSqliteStorage.js +11 -0
- package/dist/DrizzleNodeSqliteStorage.js.map +1 -0
- package/dist/DrizzlePostgresStorage.d.ts +26 -0
- package/dist/DrizzlePostgresStorage.d.ts.map +1 -0
- package/dist/DrizzlePostgresStorage.js +14 -0
- package/dist/DrizzlePostgresStorage.js.map +1 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts +34 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts.map +1 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.js +499 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.js.map +1 -0
- package/dist/EffectQbPostgresStorage.d.ts +178 -0
- package/dist/EffectQbPostgresStorage.d.ts.map +1 -0
- package/dist/EffectQbPostgresStorage.js +4637 -0
- package/dist/EffectQbPostgresStorage.js.map +1 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts +112 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts.map +1 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.js +602 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.js.map +1 -0
- package/dist/EffectQbSqliteStorage.d.ts +221 -23
- package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
- package/dist/EffectQbSqliteStorage.js +2064 -135
- package/dist/EffectQbSqliteStorage.js.map +1 -1
- package/dist/EmailAuth.d.ts +65 -0
- package/dist/EmailAuth.d.ts.map +1 -0
- package/dist/EmailAuth.js +171 -0
- package/dist/EmailAuth.js.map +1 -0
- package/dist/EmailIdentityAuth.d.ts +30 -0
- package/dist/EmailIdentityAuth.d.ts.map +1 -0
- package/dist/EmailIdentityAuth.js +142 -0
- package/dist/EmailIdentityAuth.js.map +1 -0
- package/dist/EmailOtp.d.ts +10 -11
- package/dist/EmailOtp.d.ts.map +1 -1
- package/dist/EmailOtp.js +44 -81
- package/dist/EmailOtp.js.map +1 -1
- package/dist/EmailRisk.d.ts +48 -0
- package/dist/EmailRisk.d.ts.map +1 -0
- package/dist/EmailRisk.js +33 -0
- package/dist/EmailRisk.js.map +1 -0
- package/dist/EmailVerification.d.ts +10 -16
- package/dist/EmailVerification.d.ts.map +1 -1
- package/dist/EmailVerification.js +85 -42
- package/dist/EmailVerification.js.map +1 -1
- package/dist/Guard.d.ts +11 -0
- package/dist/Guard.d.ts.map +1 -0
- package/dist/Guard.js +11 -0
- package/dist/Guard.js.map +1 -0
- package/dist/HibpPwnedPasswords.d.ts +56 -0
- package/dist/HibpPwnedPasswords.d.ts.map +1 -0
- package/dist/HibpPwnedPasswords.js +232 -0
- package/dist/HibpPwnedPasswords.js.map +1 -0
- package/dist/HttpApi/AdminPermissionDefinition.d.ts +4 -0
- package/dist/HttpApi/AdminPermissionDefinition.d.ts.map +1 -0
- package/dist/HttpApi/AdminPermissionDefinition.js +4 -0
- package/dist/HttpApi/AdminPermissionDefinition.js.map +1 -0
- package/dist/HttpApi/AdminSecurityTimeline.d.ts +4 -0
- package/dist/HttpApi/AdminSecurityTimeline.d.ts.map +1 -0
- package/dist/HttpApi/AdminSecurityTimeline.js +4 -0
- package/dist/HttpApi/AdminSecurityTimeline.js.map +1 -0
- package/dist/HttpApi/AdminSession.d.ts +4 -0
- package/dist/HttpApi/AdminSession.d.ts.map +1 -0
- package/dist/HttpApi/AdminSession.js +4 -0
- package/dist/HttpApi/AdminSession.js.map +1 -0
- package/dist/HttpApi/AdminTrustedDevice.d.ts +4 -0
- package/dist/HttpApi/AdminTrustedDevice.d.ts.map +1 -0
- package/dist/HttpApi/AdminTrustedDevice.js +4 -0
- package/dist/HttpApi/AdminTrustedDevice.js.map +1 -0
- package/dist/HttpApi/Api.d.ts +939 -884
- package/dist/HttpApi/Api.d.ts.map +1 -1
- package/dist/HttpApi/Api.js +2254 -940
- package/dist/HttpApi/Api.js.map +1 -1
- package/dist/HttpApi/ApiKey.d.ts +4 -0
- package/dist/HttpApi/ApiKey.d.ts.map +1 -0
- package/dist/HttpApi/ApiKey.js +4 -0
- package/dist/HttpApi/ApiKey.js.map +1 -0
- package/dist/HttpApi/Audit.d.ts +6 -0
- package/dist/HttpApi/Audit.d.ts.map +1 -0
- package/dist/HttpApi/Audit.js +10 -0
- package/dist/HttpApi/Audit.js.map +1 -0
- package/dist/HttpApi/ClientApi.d.ts +917 -0
- package/dist/HttpApi/ClientApi.d.ts.map +1 -0
- package/dist/HttpApi/ClientApi.js +101 -0
- package/dist/HttpApi/ClientApi.js.map +1 -0
- package/dist/HttpApi/EmailAuth.d.ts +6 -0
- package/dist/HttpApi/EmailAuth.d.ts.map +1 -0
- package/dist/HttpApi/EmailAuth.js +6 -0
- package/dist/HttpApi/EmailAuth.js.map +1 -0
- package/dist/HttpApi/EmailGuards.d.ts +115 -0
- package/dist/HttpApi/EmailGuards.d.ts.map +1 -0
- package/dist/HttpApi/EmailGuards.js +191 -0
- package/dist/HttpApi/EmailGuards.js.map +1 -0
- package/dist/HttpApi/EmailOtp.d.ts +6 -0
- package/dist/HttpApi/EmailOtp.d.ts.map +1 -0
- package/dist/HttpApi/EmailOtp.js +6 -0
- package/dist/HttpApi/EmailOtp.js.map +1 -0
- package/dist/HttpApi/EmailVerification.d.ts +6 -0
- package/dist/HttpApi/EmailVerification.d.ts.map +1 -0
- package/dist/HttpApi/EmailVerification.js +6 -0
- package/dist/HttpApi/EmailVerification.js.map +1 -0
- package/dist/HttpApi/Endpoints.d.ts +661 -301
- package/dist/HttpApi/Endpoints.d.ts.map +1 -1
- package/dist/HttpApi/Endpoints.js +207 -120
- package/dist/HttpApi/Endpoints.js.map +1 -1
- package/dist/HttpApi/Errors.d.ts +37 -10
- package/dist/HttpApi/Errors.d.ts.map +1 -1
- package/dist/HttpApi/Errors.js +42 -4
- package/dist/HttpApi/Errors.js.map +1 -1
- package/dist/HttpApi/Identity.d.ts +6 -0
- package/dist/HttpApi/Identity.d.ts.map +1 -0
- package/dist/HttpApi/Identity.js +6 -0
- package/dist/HttpApi/Identity.js.map +1 -0
- package/dist/HttpApi/IdentityGuards.d.ts +31 -0
- package/dist/HttpApi/IdentityGuards.d.ts.map +1 -0
- package/dist/HttpApi/IdentityGuards.js +33 -0
- package/dist/HttpApi/IdentityGuards.js.map +1 -0
- package/dist/HttpApi/Jwt.d.ts +4 -0
- package/dist/HttpApi/Jwt.d.ts.map +1 -0
- package/dist/HttpApi/Jwt.js +4 -0
- package/dist/HttpApi/Jwt.js.map +1 -0
- package/dist/HttpApi/JwtDiscovery.d.ts +4 -0
- package/dist/HttpApi/JwtDiscovery.d.ts.map +1 -0
- package/dist/HttpApi/JwtDiscovery.js +4 -0
- package/dist/HttpApi/JwtDiscovery.js.map +1 -0
- package/dist/HttpApi/LoginApproval.d.ts +5 -0
- package/dist/HttpApi/LoginApproval.d.ts.map +1 -0
- package/dist/HttpApi/LoginApproval.js +5 -0
- package/dist/HttpApi/LoginApproval.js.map +1 -0
- package/dist/HttpApi/LoginNotification.d.ts +5 -0
- package/dist/HttpApi/LoginNotification.d.ts.map +1 -0
- package/dist/HttpApi/LoginNotification.js +5 -0
- package/dist/HttpApi/LoginNotification.js.map +1 -0
- package/dist/HttpApi/MagicLink.d.ts +6 -0
- package/dist/HttpApi/MagicLink.d.ts.map +1 -0
- package/dist/HttpApi/MagicLink.js +6 -0
- package/dist/HttpApi/MagicLink.js.map +1 -0
- package/dist/HttpApi/Mfa.d.ts +5 -0
- package/dist/HttpApi/Mfa.d.ts.map +1 -0
- package/dist/HttpApi/Mfa.js +5 -0
- package/dist/HttpApi/Mfa.js.map +1 -0
- package/dist/HttpApi/Middleware.d.ts +26 -0
- package/dist/HttpApi/Middleware.d.ts.map +1 -0
- package/dist/HttpApi/Middleware.js +13 -0
- package/dist/HttpApi/Middleware.js.map +1 -0
- package/dist/HttpApi/OAuth.d.ts +4 -0
- package/dist/HttpApi/OAuth.d.ts.map +1 -0
- package/dist/HttpApi/OAuth.js +4 -0
- package/dist/HttpApi/OAuth.js.map +1 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.d.ts +106 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.js +415 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.js.map +1 -0
- package/dist/HttpApi/OAuthProviderAuthorization.d.ts +4 -0
- package/dist/HttpApi/OAuthProviderAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/OAuthProviderAuthorization.js +4 -0
- package/dist/HttpApi/OAuthProviderAuthorization.js.map +1 -0
- package/dist/HttpApi/OAuthToken.d.ts +4 -0
- package/dist/HttpApi/OAuthToken.d.ts.map +1 -0
- package/dist/HttpApi/OAuthToken.js +4 -0
- package/dist/HttpApi/OAuthToken.js.map +1 -0
- package/dist/HttpApi/OidcDiscovery.d.ts +4 -0
- package/dist/HttpApi/OidcDiscovery.d.ts.map +1 -0
- package/dist/HttpApi/OidcDiscovery.js +4 -0
- package/dist/HttpApi/OidcDiscovery.js.map +1 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts +28 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts.map +1 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.js +5 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.js.map +1 -0
- package/dist/HttpApi/Operations/AdminSession.d.ts +16 -0
- package/dist/HttpApi/Operations/AdminSession.d.ts.map +1 -0
- package/dist/HttpApi/Operations/AdminSession.js +5 -0
- package/dist/HttpApi/Operations/AdminSession.js.map +1 -0
- package/dist/HttpApi/Operations/ApiKey.d.ts +16 -0
- package/dist/HttpApi/Operations/ApiKey.d.ts.map +1 -0
- package/dist/HttpApi/Operations/ApiKey.js +5 -0
- package/dist/HttpApi/Operations/ApiKey.js.map +1 -0
- package/dist/HttpApi/Operations/Discovery.d.ts +19 -0
- package/dist/HttpApi/Operations/Discovery.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Discovery.js +7 -0
- package/dist/HttpApi/Operations/Discovery.js.map +1 -0
- package/dist/HttpApi/Operations/EmailAuth.d.ts +12 -0
- package/dist/HttpApi/Operations/EmailAuth.d.ts.map +1 -0
- package/dist/HttpApi/Operations/EmailAuth.js +5 -0
- package/dist/HttpApi/Operations/EmailAuth.js.map +1 -0
- package/dist/HttpApi/Operations/EmailOtp.d.ts +14 -0
- package/dist/HttpApi/Operations/EmailOtp.d.ts.map +1 -0
- package/dist/HttpApi/Operations/EmailOtp.js +5 -0
- package/dist/HttpApi/Operations/EmailOtp.js.map +1 -0
- package/dist/HttpApi/Operations/EmailVerification.d.ts +14 -0
- package/dist/HttpApi/Operations/EmailVerification.d.ts.map +1 -0
- package/dist/HttpApi/Operations/EmailVerification.js +5 -0
- package/dist/HttpApi/Operations/EmailVerification.js.map +1 -0
- package/dist/HttpApi/Operations/HttpOperation.d.ts +4 -0
- package/dist/HttpApi/Operations/HttpOperation.d.ts.map +1 -0
- package/dist/HttpApi/Operations/HttpOperation.js +2 -0
- package/dist/HttpApi/Operations/HttpOperation.js.map +1 -0
- package/dist/HttpApi/Operations/Identity.d.ts +22 -0
- package/dist/HttpApi/Operations/Identity.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Identity.js +5 -0
- package/dist/HttpApi/Operations/Identity.js.map +1 -0
- package/dist/HttpApi/Operations/Jwt.d.ts +14 -0
- package/dist/HttpApi/Operations/Jwt.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Jwt.js +5 -0
- package/dist/HttpApi/Operations/Jwt.js.map +1 -0
- package/dist/HttpApi/Operations/LoginApproval.d.ts +16 -0
- package/dist/HttpApi/Operations/LoginApproval.d.ts.map +1 -0
- package/dist/HttpApi/Operations/LoginApproval.js +5 -0
- package/dist/HttpApi/Operations/LoginApproval.js.map +1 -0
- package/dist/HttpApi/Operations/MagicLink.d.ts +14 -0
- package/dist/HttpApi/Operations/MagicLink.d.ts.map +1 -0
- package/dist/HttpApi/Operations/MagicLink.js +5 -0
- package/dist/HttpApi/Operations/MagicLink.js.map +1 -0
- package/dist/HttpApi/Operations/Mfa.d.ts +24 -0
- package/dist/HttpApi/Operations/Mfa.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Mfa.js +5 -0
- package/dist/HttpApi/Operations/Mfa.js.map +1 -0
- package/dist/HttpApi/Operations/OAuth.d.ts +20 -0
- package/dist/HttpApi/Operations/OAuth.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuth.js +5 -0
- package/dist/HttpApi/Operations/OAuth.js.map +1 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts +23 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js +7 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js.map +1 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts +12 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.js +5 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.js.map +1 -0
- package/dist/HttpApi/Operations/OAuthToken.d.ts +26 -0
- package/dist/HttpApi/Operations/OAuthToken.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthToken.js +9 -0
- package/dist/HttpApi/Operations/OAuthToken.js.map +1 -0
- package/dist/HttpApi/Operations/Passkey.d.ts +22 -0
- package/dist/HttpApi/Operations/Passkey.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Passkey.js +5 -0
- package/dist/HttpApi/Operations/Passkey.js.map +1 -0
- package/dist/HttpApi/Operations/Password.d.ts +22 -0
- package/dist/HttpApi/Operations/Password.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Password.js +5 -0
- package/dist/HttpApi/Operations/Password.js.map +1 -0
- package/dist/HttpApi/Operations/RecoveryCodes.d.ts +20 -0
- package/dist/HttpApi/Operations/RecoveryCodes.d.ts.map +1 -0
- package/dist/HttpApi/Operations/RecoveryCodes.js +5 -0
- package/dist/HttpApi/Operations/RecoveryCodes.js.map +1 -0
- package/dist/HttpApi/Operations/RefreshToken.d.ts +12 -0
- package/dist/HttpApi/Operations/RefreshToken.d.ts.map +1 -0
- package/dist/HttpApi/Operations/RefreshToken.js +5 -0
- package/dist/HttpApi/Operations/RefreshToken.js.map +1 -0
- package/dist/HttpApi/Operations/Security.d.ts +12 -0
- package/dist/HttpApi/Operations/Security.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Security.js +5 -0
- package/dist/HttpApi/Operations/Security.js.map +1 -0
- package/dist/HttpApi/Operations/SecurityTimeline.d.ts +19 -0
- package/dist/HttpApi/Operations/SecurityTimeline.d.ts.map +1 -0
- package/dist/HttpApi/Operations/SecurityTimeline.js +7 -0
- package/dist/HttpApi/Operations/SecurityTimeline.js.map +1 -0
- package/dist/HttpApi/Operations/Session.d.ts +22 -0
- package/dist/HttpApi/Operations/Session.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Session.js +5 -0
- package/dist/HttpApi/Operations/Session.js.map +1 -0
- package/dist/HttpApi/Operations/StepUp.d.ts +22 -0
- package/dist/HttpApi/Operations/StepUp.d.ts.map +1 -0
- package/dist/HttpApi/Operations/StepUp.js +5 -0
- package/dist/HttpApi/Operations/StepUp.js.map +1 -0
- package/dist/HttpApi/Operations/Totp.d.ts +20 -0
- package/dist/HttpApi/Operations/Totp.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Totp.js +5 -0
- package/dist/HttpApi/Operations/Totp.js.map +1 -0
- package/dist/HttpApi/Operations/TrustedDevice.d.ts +23 -0
- package/dist/HttpApi/Operations/TrustedDevice.d.ts.map +1 -0
- package/dist/HttpApi/Operations/TrustedDevice.js +7 -0
- package/dist/HttpApi/Operations/TrustedDevice.js.map +1 -0
- package/dist/HttpApi/Operations/index.d.ts +28 -0
- package/dist/HttpApi/Operations/index.d.ts.map +1 -0
- package/dist/HttpApi/Operations/index.js +28 -0
- package/dist/HttpApi/Operations/index.js.map +1 -0
- package/dist/HttpApi/Passkey.d.ts +5 -0
- package/dist/HttpApi/Passkey.d.ts.map +1 -0
- package/dist/HttpApi/Passkey.js +5 -0
- package/dist/HttpApi/Passkey.js.map +1 -0
- package/dist/HttpApi/Password.d.ts +220 -0
- package/dist/HttpApi/Password.d.ts.map +1 -0
- package/dist/HttpApi/Password.js +237 -0
- package/dist/HttpApi/Password.js.map +1 -0
- package/dist/HttpApi/PasswordContract.d.ts +307 -0
- package/dist/HttpApi/PasswordContract.d.ts.map +1 -0
- package/dist/HttpApi/PasswordContract.js +63 -0
- package/dist/HttpApi/PasswordContract.js.map +1 -0
- package/dist/HttpApi/PasswordGuards.d.ts +82 -0
- package/dist/HttpApi/PasswordGuards.d.ts.map +1 -0
- package/dist/HttpApi/PasswordGuards.js +179 -0
- package/dist/HttpApi/PasswordGuards.js.map +1 -0
- package/dist/HttpApi/RecoveryCodes.d.ts +5 -0
- package/dist/HttpApi/RecoveryCodes.d.ts.map +1 -0
- package/dist/HttpApi/RecoveryCodes.js +5 -0
- package/dist/HttpApi/RecoveryCodes.js.map +1 -0
- package/dist/HttpApi/RefreshToken.d.ts +4 -0
- package/dist/HttpApi/RefreshToken.d.ts.map +1 -0
- package/dist/HttpApi/RefreshToken.js +4 -0
- package/dist/HttpApi/RefreshToken.js.map +1 -0
- package/dist/HttpApi/RequestGuards.d.ts +42 -0
- package/dist/HttpApi/RequestGuards.d.ts.map +1 -0
- package/dist/HttpApi/RequestGuards.js +194 -0
- package/dist/HttpApi/RequestGuards.js.map +1 -0
- package/dist/HttpApi/Schemas.d.ts +399 -84
- package/dist/HttpApi/Schemas.d.ts.map +1 -1
- package/dist/HttpApi/Schemas.js +225 -27
- package/dist/HttpApi/Schemas.js.map +1 -1
- package/dist/HttpApi/Security.d.ts +12 -93
- package/dist/HttpApi/Security.d.ts.map +1 -1
- package/dist/HttpApi/Security.js +65 -356
- package/dist/HttpApi/Security.js.map +1 -1
- package/dist/HttpApi/SecurityTimeline.d.ts +4 -0
- package/dist/HttpApi/SecurityTimeline.d.ts.map +1 -0
- package/dist/HttpApi/SecurityTimeline.js +4 -0
- package/dist/HttpApi/SecurityTimeline.js.map +1 -0
- package/dist/HttpApi/Session.d.ts +5 -0
- package/dist/HttpApi/Session.d.ts.map +1 -0
- package/dist/HttpApi/Session.js +5 -0
- package/dist/HttpApi/Session.js.map +1 -0
- package/dist/HttpApi/SessionGuards.d.ts +15 -0
- package/dist/HttpApi/SessionGuards.d.ts.map +1 -0
- package/dist/HttpApi/SessionGuards.js +37 -0
- package/dist/HttpApi/SessionGuards.js.map +1 -0
- package/dist/HttpApi/StepUp.d.ts +5 -0
- package/dist/HttpApi/StepUp.d.ts.map +1 -0
- package/dist/HttpApi/StepUp.js +5 -0
- package/dist/HttpApi/StepUp.js.map +1 -0
- package/dist/HttpApi/Totp.d.ts +5 -0
- package/dist/HttpApi/Totp.d.ts.map +1 -0
- package/dist/HttpApi/Totp.js +5 -0
- package/dist/HttpApi/Totp.js.map +1 -0
- package/dist/HttpApi/Transport.d.ts +4 -6
- package/dist/HttpApi/Transport.d.ts.map +1 -1
- package/dist/HttpApi/Transport.js +62 -36
- package/dist/HttpApi/Transport.js.map +1 -1
- package/dist/HttpApi/TrustedDevice.d.ts +4 -0
- package/dist/HttpApi/TrustedDevice.d.ts.map +1 -0
- package/dist/HttpApi/TrustedDevice.js +4 -0
- package/dist/HttpApi/TrustedDevice.js.map +1 -0
- package/dist/HttpApi/index.d.ts +11 -3
- package/dist/HttpApi/index.d.ts.map +1 -1
- package/dist/HttpApi/index.js +10 -2
- package/dist/HttpApi/index.js.map +1 -1
- package/dist/Identity.d.ts +138 -0
- package/dist/Identity.d.ts.map +1 -0
- package/dist/Identity.js +105 -0
- package/dist/Identity.js.map +1 -0
- package/dist/IdentityManagement.d.ts +189 -0
- package/dist/IdentityManagement.d.ts.map +1 -0
- package/dist/IdentityManagement.js +317 -0
- package/dist/IdentityManagement.js.map +1 -0
- package/dist/IncidentAction.d.ts +1 -4
- package/dist/IncidentAction.d.ts.map +1 -1
- package/dist/IncidentAction.js +15 -9
- package/dist/IncidentAction.js.map +1 -1
- package/dist/Internal.d.ts +2 -0
- package/dist/Internal.d.ts.map +1 -1
- package/dist/Internal.js +30 -0
- package/dist/Internal.js.map +1 -1
- package/dist/Invitation.d.ts +362 -0
- package/dist/Invitation.d.ts.map +1 -0
- package/dist/Invitation.js +633 -0
- package/dist/Invitation.js.map +1 -0
- package/dist/IpQualityScore.d.ts +38 -0
- package/dist/IpQualityScore.d.ts.map +1 -0
- package/dist/IpQualityScore.js +215 -0
- package/dist/IpQualityScore.js.map +1 -0
- package/dist/Jwt.d.ts +8 -29
- package/dist/Jwt.d.ts.map +1 -1
- package/dist/Jwt.js +67 -56
- package/dist/Jwt.js.map +1 -1
- package/dist/LoginApproval.d.ts +15 -30
- package/dist/LoginApproval.d.ts.map +1 -1
- package/dist/LoginApproval.js +47 -41
- package/dist/LoginApproval.js.map +1 -1
- package/dist/LoginNotification.d.ts +7 -11
- package/dist/LoginNotification.d.ts.map +1 -1
- package/dist/LoginNotification.js +30 -17
- package/dist/LoginNotification.js.map +1 -1
- package/dist/LoginRisk.d.ts +11 -13
- package/dist/LoginRisk.d.ts.map +1 -1
- package/dist/LoginRisk.js +66 -26
- package/dist/LoginRisk.js.map +1 -1
- package/dist/LoginRiskEnrichment.d.ts +145 -0
- package/dist/LoginRiskEnrichment.d.ts.map +1 -0
- package/dist/LoginRiskEnrichment.js +220 -0
- package/dist/LoginRiskEnrichment.js.map +1 -0
- package/dist/MagicLink.d.ts +9 -8
- package/dist/MagicLink.d.ts.map +1 -1
- package/dist/MagicLink.js +40 -73
- package/dist/MagicLink.js.map +1 -1
- package/dist/Mailer.d.ts +19 -12
- package/dist/Mailer.d.ts.map +1 -1
- package/dist/Mailer.js +10 -12
- package/dist/Mailer.js.map +1 -1
- package/dist/OAuth.d.ts +138 -96
- package/dist/OAuth.d.ts.map +1 -1
- package/dist/OAuth.js +522 -221
- package/dist/OAuth.js.map +1 -1
- package/dist/OAuthDeviceAuthorization.d.ts +378 -0
- package/dist/OAuthDeviceAuthorization.d.ts.map +1 -0
- package/dist/OAuthDeviceAuthorization.js +860 -0
- package/dist/OAuthDeviceAuthorization.js.map +1 -0
- package/dist/OAuthDeviceClient.d.ts +76 -0
- package/dist/OAuthDeviceClient.d.ts.map +1 -0
- package/dist/OAuthDeviceClient.js +362 -0
- package/dist/OAuthDeviceClient.js.map +1 -0
- package/dist/Passkey.d.ts +15 -17
- package/dist/Passkey.d.ts.map +1 -1
- package/dist/Passkey.js +86 -39
- package/dist/Passkey.js.map +1 -1
- package/dist/PasskeyBrowser.d.ts +39 -0
- package/dist/PasskeyBrowser.d.ts.map +1 -0
- package/dist/PasskeyBrowser.js +206 -0
- package/dist/PasskeyBrowser.js.map +1 -0
- package/dist/PasskeySimpleWebAuthn.d.ts.map +1 -1
- package/dist/PasskeySimpleWebAuthn.js +19 -7
- package/dist/PasskeySimpleWebAuthn.js.map +1 -1
- package/dist/Password.d.ts +71 -37
- package/dist/Password.d.ts.map +1 -1
- package/dist/Password.js +295 -81
- package/dist/Password.js.map +1 -1
- package/dist/PasswordRisk.d.ts +63 -0
- package/dist/PasswordRisk.d.ts.map +1 -0
- package/dist/PasswordRisk.js +37 -0
- package/dist/PasswordRisk.js.map +1 -0
- package/dist/Permission.d.ts +308 -0
- package/dist/Permission.d.ts.map +1 -0
- package/dist/Permission.js +827 -0
- package/dist/Permission.js.map +1 -0
- package/dist/Policy.d.ts +31 -18
- package/dist/Policy.d.ts.map +1 -1
- package/dist/Policy.js +58 -14
- package/dist/Policy.js.map +1 -1
- package/dist/PostgresDelegatedAccessStorageMigrations.d.ts +7 -0
- package/dist/PostgresDelegatedAccessStorageMigrations.d.ts.map +1 -0
- package/dist/PostgresDelegatedAccessStorageMigrations.js +119 -0
- package/dist/PostgresDelegatedAccessStorageMigrations.js.map +1 -0
- package/dist/PostgresStorageMigrations.d.ts +16 -0
- package/dist/PostgresStorageMigrations.d.ts.map +1 -0
- package/dist/PostgresStorageMigrations.js +674 -0
- package/dist/PostgresStorageMigrations.js.map +1 -0
- package/dist/Privacy.d.ts +0 -3
- package/dist/Privacy.d.ts.map +1 -1
- package/dist/Privacy.js +2 -5
- package/dist/Privacy.js.map +1 -1
- package/dist/RateLimiter.d.ts +0 -3
- package/dist/RateLimiter.d.ts.map +1 -1
- package/dist/RateLimiter.js +1 -4
- package/dist/RateLimiter.js.map +1 -1
- package/dist/RecoveryCode.d.ts +83 -11
- package/dist/RecoveryCode.d.ts.map +1 -1
- package/dist/RecoveryCode.js +273 -75
- package/dist/RecoveryCode.js.map +1 -1
- package/dist/RecoveryPolicy.d.ts +81 -0
- package/dist/RecoveryPolicy.d.ts.map +1 -0
- package/dist/RecoveryPolicy.js +119 -0
- package/dist/RecoveryPolicy.js.map +1 -0
- package/dist/RefreshToken.d.ts +0 -9
- package/dist/RefreshToken.d.ts.map +1 -1
- package/dist/RefreshToken.js +31 -22
- package/dist/RefreshToken.js.map +1 -1
- package/dist/Retention.d.ts +6 -1
- package/dist/Retention.d.ts.map +1 -1
- package/dist/Retention.js +49 -12
- package/dist/Retention.js.map +1 -1
- package/dist/SecurityTimeline.d.ts +1 -4
- package/dist/SecurityTimeline.d.ts.map +1 -1
- package/dist/SecurityTimeline.js +110 -17
- package/dist/SecurityTimeline.js.map +1 -1
- package/dist/Sessions.d.ts +124 -29
- package/dist/Sessions.d.ts.map +1 -1
- package/dist/Sessions.js +626 -94
- package/dist/Sessions.js.map +1 -1
- package/dist/SqliteStorageSchemaData.d.ts +2 -0
- package/dist/SqliteStorageSchemaData.d.ts.map +1 -0
- package/dist/SqliteStorageSchemaData.js +508 -0
- package/dist/SqliteStorageSchemaData.js.map +1 -0
- package/dist/StepUp.d.ts +132 -11
- package/dist/StepUp.d.ts.map +1 -1
- package/dist/StepUp.js +387 -19
- package/dist/StepUp.js.map +1 -1
- package/dist/Storage.d.ts +89 -23
- package/dist/Storage.d.ts.map +1 -1
- package/dist/Storage.js +10 -12
- package/dist/Storage.js.map +1 -1
- package/dist/StorageMigrations.d.ts +7 -1
- package/dist/StorageMigrations.d.ts.map +1 -1
- package/dist/StorageMigrations.js +256 -0
- package/dist/StorageMigrations.js.map +1 -1
- package/dist/StorageSchemaGenerator.d.ts +544 -0
- package/dist/StorageSchemaGenerator.d.ts.map +1 -0
- package/dist/StorageSchemaGenerator.js +1418 -0
- package/dist/StorageSchemaGenerator.js.map +1 -0
- package/dist/StrongFactor.d.ts +64 -0
- package/dist/StrongFactor.d.ts.map +1 -0
- package/dist/StrongFactor.js +100 -0
- package/dist/StrongFactor.js.map +1 -0
- package/dist/Testing.js +2 -2
- package/dist/Testing.js.map +1 -1
- package/dist/Totp.d.ts +88 -13
- package/dist/Totp.d.ts.map +1 -1
- package/dist/Totp.js +192 -34
- package/dist/Totp.js.map +1 -1
- package/dist/TrustedDevice.d.ts +0 -9
- package/dist/TrustedDevice.d.ts.map +1 -1
- package/dist/TrustedDevice.js +15 -17
- package/dist/TrustedDevice.js.map +1 -1
- package/dist/WaitUntil.d.ts +0 -3
- package/dist/WaitUntil.d.ts.map +1 -1
- package/dist/WaitUntil.js +1 -4
- package/dist/WaitUntil.js.map +1 -1
- package/dist/Webhook.d.ts +42 -12
- package/dist/Webhook.d.ts.map +1 -1
- package/dist/Webhook.js +165 -26
- package/dist/Webhook.js.map +1 -1
- package/dist/alchemy/cloudflare/Email.d.ts.map +1 -1
- package/dist/alchemy/cloudflare/Email.js +9 -4
- package/dist/alchemy/cloudflare/Email.js.map +1 -1
- package/dist/cloudflare/Email.js +1 -1
- package/dist/cloudflare/Email.js.map +1 -1
- package/dist/cloudflare/RequestMetadata.d.ts +49 -0
- package/dist/cloudflare/RequestMetadata.d.ts.map +1 -0
- package/dist/cloudflare/RequestMetadata.js +71 -0
- package/dist/cloudflare/RequestMetadata.js.map +1 -0
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -35
- package/dist/index.js.map +1 -1
- package/dist/internal/AuthFlowFinalizer.d.ts +31 -0
- package/dist/internal/AuthFlowFinalizer.d.ts.map +1 -0
- package/dist/internal/AuthFlowFinalizer.js +182 -0
- package/dist/internal/AuthFlowFinalizer.js.map +1 -0
- package/migrations/0001_auth_storage.sql +1 -0
- package/migrations/0006_auth_totp_factor.sql +1 -0
- package/migrations/0024_auth_permission.sql +39 -0
- package/migrations/0025_auth_permission_definition.sql +19 -0
- package/migrations/0026_auth_user_identity.sql +59 -0
- package/migrations/0027_auth_audit_log_storage_order.sql +46 -0
- package/migrations/0028_auth_oauth_client_secret_key.sql +39 -0
- package/migrations/0029_auth_oauth_device_authorization.sql +28 -0
- package/migrations/delegated-access/0001_auth_delegated_access.sql +152 -0
- package/migrations/postgres/0001_auth_core.sql +77 -0
- package/migrations/postgres/0002_auth_security_oauth.sql +65 -0
- package/migrations/postgres/0003_auth_credentials_tokens.sql +43 -0
- package/migrations/postgres/0004_auth_security_history.sql +103 -0
- package/migrations/postgres/0005_auth_webhooks.sql +29 -0
- package/migrations/postgres/0006_auth_domain_timeline.sql +50 -0
- package/migrations/postgres/0007_auth_oauth_clients.sql +85 -0
- package/migrations/postgres/0008_auth_oauth_tokens.sql +63 -0
- package/migrations/postgres/0009_auth_permissions.sql +66 -0
- package/migrations/postgres/0010_auth_oauth_device_authorization.sql +50 -0
- package/migrations/postgres/delegated-access/0001_auth_delegated_access.sql +112 -0
- 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
|