@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,633 @@
|
|
|
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
|
+
export const InvitationId = Brand.nominal();
|
|
6
|
+
export const InvitationIdSchema = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{22}$/)).pipe(Schema.brand("auth/InvitationId"));
|
|
7
|
+
export const InvitationToken = Brand.nominal();
|
|
8
|
+
export const InvitationTokenHash = Brand.nominal();
|
|
9
|
+
export const InvitationTokenHashSchema = Schema.String.check(Schema.isPattern(/^sha256:.+$/)).pipe(Schema.brand("auth/InvitationTokenHash"));
|
|
10
|
+
export const invitationTokenVersion = "inv1";
|
|
11
|
+
export const invitationIdBytes = 16;
|
|
12
|
+
export const invitationSecretBytes = 32;
|
|
13
|
+
export class InvitationTokenError extends Data.TaggedError("InvitationTokenError") {
|
|
14
|
+
}
|
|
15
|
+
const textEncoder = new TextEncoder();
|
|
16
|
+
const invitationHashDomain = "effect-auth:invitation-token:v1\u0000";
|
|
17
|
+
const invitationIdEncodedLength = Math.ceil((invitationIdBytes * 4) / 3);
|
|
18
|
+
const invitationSecretEncodedLength = Math.ceil((invitationSecretBytes * 4) / 3);
|
|
19
|
+
const invitationTokenLength = invitationTokenVersion.length +
|
|
20
|
+
invitationIdEncodedLength +
|
|
21
|
+
invitationSecretEncodedLength +
|
|
22
|
+
2;
|
|
23
|
+
const invitationTokenError = (operation, message, cause) => new InvitationTokenError({
|
|
24
|
+
operation,
|
|
25
|
+
message,
|
|
26
|
+
...(cause === undefined ? {} : { cause }),
|
|
27
|
+
});
|
|
28
|
+
const decodeCanonicalTokenPart = (value, expectedBytes, expectedEncodedLength) => {
|
|
29
|
+
if (value.length !== expectedEncodedLength ||
|
|
30
|
+
!/^[A-Za-z0-9_-]+$/.test(value)) {
|
|
31
|
+
return Option.none();
|
|
32
|
+
}
|
|
33
|
+
const decoded = Encoding.decodeBase64Url(value);
|
|
34
|
+
if (Result.isFailure(decoded) ||
|
|
35
|
+
decoded.success.length !== expectedBytes ||
|
|
36
|
+
Encoding.encodeBase64Url(decoded.success) !== value) {
|
|
37
|
+
return Option.none();
|
|
38
|
+
}
|
|
39
|
+
return Option.some(decoded.success);
|
|
40
|
+
};
|
|
41
|
+
const parseInvitationTokenValue = (value, operation) => {
|
|
42
|
+
if (value.length !== invitationTokenLength) {
|
|
43
|
+
return Effect.fail(invitationTokenError(operation, "Invitation token is malformed"));
|
|
44
|
+
}
|
|
45
|
+
const parts = value.split(".");
|
|
46
|
+
if (parts.length !== 3 || parts[0] !== invitationTokenVersion) {
|
|
47
|
+
return Effect.fail(invitationTokenError(operation, "Invitation token is malformed"));
|
|
48
|
+
}
|
|
49
|
+
const [, idPart, secretPart] = parts;
|
|
50
|
+
if (idPart === undefined ||
|
|
51
|
+
secretPart === undefined ||
|
|
52
|
+
Option.isNone(decodeCanonicalTokenPart(idPart, invitationIdBytes, invitationIdEncodedLength)) ||
|
|
53
|
+
Option.isNone(decodeCanonicalTokenPart(secretPart, invitationSecretBytes, invitationSecretEncodedLength))) {
|
|
54
|
+
return Effect.fail(invitationTokenError(operation, "Invitation token is malformed"));
|
|
55
|
+
}
|
|
56
|
+
return Effect.succeed({ id: InvitationId(idPart) });
|
|
57
|
+
};
|
|
58
|
+
const hashInvitationTokenValue = (crypto, value, operation) => crypto.digestSha256({ data: `${invitationHashDomain}${value}` }).pipe(Effect.map((hash) => InvitationTokenHash(`sha256:${hash}`)), Effect.mapError((cause) => invitationTokenError(operation, "Failed to hash invitation token", cause)));
|
|
59
|
+
const invitationTokensService = Effect.gen(function* () {
|
|
60
|
+
const crypto = yield* Crypto;
|
|
61
|
+
return {
|
|
62
|
+
generate: Effect.fn("auth.invitation.tokens.generate")(function* () {
|
|
63
|
+
const idBytes = yield* crypto
|
|
64
|
+
.randomBytes(invitationIdBytes)
|
|
65
|
+
.pipe(Effect.mapError((cause) => invitationTokenError("generate", "Failed to generate invitation id", cause)));
|
|
66
|
+
const secretBytes = yield* crypto
|
|
67
|
+
.randomBytes(invitationSecretBytes)
|
|
68
|
+
.pipe(Effect.mapError((cause) => invitationTokenError("generate", "Failed to generate invitation secret", cause)));
|
|
69
|
+
if (idBytes.length !== invitationIdBytes ||
|
|
70
|
+
secretBytes.length !== invitationSecretBytes) {
|
|
71
|
+
return yield* Effect.fail(invitationTokenError("generate", "Crypto returned an unexpected invitation token byte length"));
|
|
72
|
+
}
|
|
73
|
+
const id = InvitationId(Encoding.encodeBase64Url(idBytes));
|
|
74
|
+
const token = InvitationToken(`${invitationTokenVersion}.${id}.${Encoding.encodeBase64Url(secretBytes)}`);
|
|
75
|
+
return { id, token: Redacted.make(token) };
|
|
76
|
+
}),
|
|
77
|
+
parse: Effect.fn("auth.invitation.tokens.parse")(function* (token) {
|
|
78
|
+
return yield* parseInvitationTokenValue(Redacted.value(token), "parse");
|
|
79
|
+
}),
|
|
80
|
+
hash: Effect.fn("auth.invitation.tokens.hash")(function* (input) {
|
|
81
|
+
const value = Redacted.value(input.token);
|
|
82
|
+
yield* parseInvitationTokenValue(value, "hash");
|
|
83
|
+
return yield* hashInvitationTokenValue(crypto, value, "hash");
|
|
84
|
+
}),
|
|
85
|
+
verify: Effect.fn("auth.invitation.tokens.verify")(function* (input) {
|
|
86
|
+
const value = Redacted.value(input.token);
|
|
87
|
+
const parsed = yield* parseInvitationTokenValue(value, "verify").pipe(Effect.option);
|
|
88
|
+
if (Option.isNone(parsed)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const candidate = yield* hashInvitationTokenValue(crypto, value, "verify");
|
|
92
|
+
return yield* crypto
|
|
93
|
+
.timingSafeEqual({
|
|
94
|
+
left: textEncoder.encode(candidate),
|
|
95
|
+
right: textEncoder.encode(input.tokenHash),
|
|
96
|
+
})
|
|
97
|
+
.pipe(Effect.mapError((cause) => invitationTokenError("verify", "Failed to compare invitation token hashes", cause)));
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
export class InvitationTokens extends Context.Service()("auth/InvitationTokens", {
|
|
102
|
+
make: invitationTokensService,
|
|
103
|
+
}) {
|
|
104
|
+
}
|
|
105
|
+
export const InvitationTokensSha256Live = Layer.effect(InvitationTokens)(InvitationTokens.make);
|
|
106
|
+
const hasConsistentInvitationLifecycle = (record) => {
|
|
107
|
+
const accepted = record.acceptedAt !== undefined;
|
|
108
|
+
const revoked = record.revokedAt !== undefined;
|
|
109
|
+
const superseded = record.supersededAt !== undefined;
|
|
110
|
+
return (accepted === (record.acceptedBy !== undefined) &&
|
|
111
|
+
superseded === (record.supersededById !== undefined) &&
|
|
112
|
+
Number(accepted) + Number(revoked) + Number(superseded) <= 1);
|
|
113
|
+
};
|
|
114
|
+
export const getInvitationStatus = (record, now) => {
|
|
115
|
+
if (!hasConsistentInvitationLifecycle(record)) {
|
|
116
|
+
return "invalid";
|
|
117
|
+
}
|
|
118
|
+
if (record.acceptedAt !== undefined) {
|
|
119
|
+
return "accepted";
|
|
120
|
+
}
|
|
121
|
+
if (record.revokedAt !== undefined) {
|
|
122
|
+
return "revoked";
|
|
123
|
+
}
|
|
124
|
+
if (record.supersededAt !== undefined) {
|
|
125
|
+
return "superseded";
|
|
126
|
+
}
|
|
127
|
+
if (Number(now) >= Number(record.expiresAt)) {
|
|
128
|
+
return "expired";
|
|
129
|
+
}
|
|
130
|
+
return "pending";
|
|
131
|
+
};
|
|
132
|
+
const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1));
|
|
133
|
+
const DelegatedUnixMillisSchema = UnixMillisSchema.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0));
|
|
134
|
+
const PermissionSubjectSchema = Schema.Struct({
|
|
135
|
+
type: NonEmptyStringSchema,
|
|
136
|
+
id: NonEmptyStringSchema,
|
|
137
|
+
});
|
|
138
|
+
export const InvitationJsonObjectSchema = Schema.Record(Schema.String, Schema.Json);
|
|
139
|
+
export const InvitationTargetSchema = Schema.Struct({
|
|
140
|
+
type: NonEmptyStringSchema,
|
|
141
|
+
id: NonEmptyStringSchema,
|
|
142
|
+
});
|
|
143
|
+
export const InvitationRecipientSchema = Schema.Struct({
|
|
144
|
+
type: NonEmptyStringSchema,
|
|
145
|
+
reference: NonEmptyStringSchema,
|
|
146
|
+
});
|
|
147
|
+
export const InvitationIntentSchema = Schema.Struct({
|
|
148
|
+
type: NonEmptyStringSchema,
|
|
149
|
+
version: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
150
|
+
payload: InvitationJsonObjectSchema,
|
|
151
|
+
});
|
|
152
|
+
export const InvitationRecordSchema = Schema.Struct({
|
|
153
|
+
id: InvitationIdSchema,
|
|
154
|
+
kind: NonEmptyStringSchema,
|
|
155
|
+
target: InvitationTargetSchema,
|
|
156
|
+
intent: InvitationIntentSchema,
|
|
157
|
+
recipient: Schema.optional(InvitationRecipientSchema),
|
|
158
|
+
issuedBy: Schema.optional(PermissionSubjectSchema),
|
|
159
|
+
createdAt: DelegatedUnixMillisSchema,
|
|
160
|
+
expiresAt: DelegatedUnixMillisSchema,
|
|
161
|
+
tokenHash: InvitationTokenHashSchema,
|
|
162
|
+
acceptedAt: Schema.optional(DelegatedUnixMillisSchema),
|
|
163
|
+
acceptedBy: Schema.optional(PermissionSubjectSchema),
|
|
164
|
+
revokedAt: Schema.optional(DelegatedUnixMillisSchema),
|
|
165
|
+
supersededAt: Schema.optional(DelegatedUnixMillisSchema),
|
|
166
|
+
supersededById: Schema.optional(InvitationIdSchema),
|
|
167
|
+
metadata: Schema.optional(InvitationJsonObjectSchema),
|
|
168
|
+
}).check(Schema.makeFilter((record) => {
|
|
169
|
+
if (!hasConsistentInvitationLifecycle(record)) {
|
|
170
|
+
return "Invitation terminal state is inconsistent";
|
|
171
|
+
}
|
|
172
|
+
if (Number(record.expiresAt) <= Number(record.createdAt)) {
|
|
173
|
+
return "Invitation expiry must be later than creation";
|
|
174
|
+
}
|
|
175
|
+
for (const terminalAt of [
|
|
176
|
+
record.acceptedAt,
|
|
177
|
+
record.revokedAt,
|
|
178
|
+
record.supersededAt,
|
|
179
|
+
]) {
|
|
180
|
+
if (terminalAt !== undefined &&
|
|
181
|
+
Number(terminalAt) < Number(record.createdAt)) {
|
|
182
|
+
return "Invitation terminal time must not precede creation";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}));
|
|
187
|
+
export const isInvitationRecord = Schema.is(InvitationRecordSchema);
|
|
188
|
+
const isInvitationJsonObject = Schema.is(InvitationJsonObjectSchema);
|
|
189
|
+
export class InvitationStoreError extends Data.TaggedError("InvitationStoreError") {
|
|
190
|
+
}
|
|
191
|
+
export class InvitationStore extends Context.Service()("auth/InvitationStore") {
|
|
192
|
+
}
|
|
193
|
+
const invitationStoreError = (operation, message, cause) => new InvitationStoreError({
|
|
194
|
+
operation,
|
|
195
|
+
message,
|
|
196
|
+
...(cause === undefined ? {} : { cause }),
|
|
197
|
+
});
|
|
198
|
+
const cloneMetadata = (metadata) => metadata === undefined ? undefined : structuredClone(metadata);
|
|
199
|
+
const clonePermissionSubject = (subject) => subject === undefined ? undefined : { type: subject.type, id: subject.id };
|
|
200
|
+
const cloneInvitationRecord = (record) => ({
|
|
201
|
+
id: record.id,
|
|
202
|
+
kind: record.kind,
|
|
203
|
+
target: { type: record.target.type, id: record.target.id },
|
|
204
|
+
intent: {
|
|
205
|
+
type: record.intent.type,
|
|
206
|
+
version: record.intent.version,
|
|
207
|
+
payload: structuredClone(record.intent.payload),
|
|
208
|
+
},
|
|
209
|
+
...(record.recipient === undefined
|
|
210
|
+
? {}
|
|
211
|
+
: {
|
|
212
|
+
recipient: {
|
|
213
|
+
type: record.recipient.type,
|
|
214
|
+
reference: record.recipient.reference,
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
...(record.issuedBy === undefined
|
|
218
|
+
? {}
|
|
219
|
+
: { issuedBy: clonePermissionSubject(record.issuedBy) }),
|
|
220
|
+
createdAt: record.createdAt,
|
|
221
|
+
expiresAt: record.expiresAt,
|
|
222
|
+
tokenHash: record.tokenHash,
|
|
223
|
+
...(record.acceptedAt === undefined ? {} : { acceptedAt: record.acceptedAt }),
|
|
224
|
+
...(record.acceptedBy === undefined
|
|
225
|
+
? {}
|
|
226
|
+
: { acceptedBy: clonePermissionSubject(record.acceptedBy) }),
|
|
227
|
+
...(record.revokedAt === undefined ? {} : { revokedAt: record.revokedAt }),
|
|
228
|
+
...(record.supersededAt === undefined
|
|
229
|
+
? {}
|
|
230
|
+
: { supersededAt: record.supersededAt }),
|
|
231
|
+
...(record.supersededById === undefined
|
|
232
|
+
? {}
|
|
233
|
+
: { supersededById: record.supersededById }),
|
|
234
|
+
...(record.metadata === undefined
|
|
235
|
+
? {}
|
|
236
|
+
: { metadata: cloneMetadata(record.metadata) }),
|
|
237
|
+
});
|
|
238
|
+
const subjectsEqual = (left, right) => left === undefined
|
|
239
|
+
? right === undefined
|
|
240
|
+
: right !== undefined && left.type === right.type && left.id === right.id;
|
|
241
|
+
const targetsEqual = (left, right) => left.type === right.type && left.id === right.id;
|
|
242
|
+
const recipientsEqual = (left, right) => left === undefined
|
|
243
|
+
? right === undefined
|
|
244
|
+
: right !== undefined &&
|
|
245
|
+
left.type === right.type &&
|
|
246
|
+
left.reference === right.reference;
|
|
247
|
+
const matchesInvitationList = (record, input) => (input.kind === undefined || record.kind === input.kind) &&
|
|
248
|
+
(input.target === undefined || targetsEqual(record.target, input.target)) &&
|
|
249
|
+
(input.recipient === undefined ||
|
|
250
|
+
recipientsEqual(record.recipient, input.recipient)) &&
|
|
251
|
+
(input.issuedBy === undefined ||
|
|
252
|
+
subjectsEqual(record.issuedBy, input.issuedBy)) &&
|
|
253
|
+
(input.statuses === undefined ||
|
|
254
|
+
input.statuses.includes(getInvitationStatus(record, input.now)));
|
|
255
|
+
const compareInvitationRecords = (left, right) => {
|
|
256
|
+
const createdAt = Number(left.createdAt) - Number(right.createdAt);
|
|
257
|
+
if (createdAt !== 0) {
|
|
258
|
+
return createdAt < 0 ? -1 : 1;
|
|
259
|
+
}
|
|
260
|
+
return String(left.id) < String(right.id)
|
|
261
|
+
? -1
|
|
262
|
+
: String(left.id) > String(right.id)
|
|
263
|
+
? 1
|
|
264
|
+
: 0;
|
|
265
|
+
};
|
|
266
|
+
const InvitationRecordOrder = Order.make(compareInvitationRecords);
|
|
267
|
+
const invitationStoreMemory = () => {
|
|
268
|
+
const records = new Map();
|
|
269
|
+
return InvitationStore.of({
|
|
270
|
+
insert: Effect.fn("auth.invitation.store.memory.insert")(function* (record) {
|
|
271
|
+
if (!isInvitationRecord(record)) {
|
|
272
|
+
return yield* Effect.fail(invitationStoreError("insert", "Invitation record is invalid"));
|
|
273
|
+
}
|
|
274
|
+
if (records.has(record.id)) {
|
|
275
|
+
return yield* Effect.fail(invitationStoreError("insert", "Invitation id already exists"));
|
|
276
|
+
}
|
|
277
|
+
records.set(record.id, cloneInvitationRecord(record));
|
|
278
|
+
}),
|
|
279
|
+
findById: Effect.fn("auth.invitation.store.memory.find_by_id")((id) => Effect.sync(() => {
|
|
280
|
+
const record = records.get(id);
|
|
281
|
+
return record === undefined
|
|
282
|
+
? Option.none()
|
|
283
|
+
: Option.some(cloneInvitationRecord(record));
|
|
284
|
+
})),
|
|
285
|
+
list: Effect.fn("auth.invitation.store.memory.list")((input) => Effect.sync(() => EffectArray.sort([...records.values()].filter((record) => matchesInvitationList(record, input)), InvitationRecordOrder).map(cloneInvitationRecord))),
|
|
286
|
+
revokePending: Effect.fn("auth.invitation.store.memory.revoke_pending")(function* (input) {
|
|
287
|
+
const record = records.get(input.id);
|
|
288
|
+
if (record === undefined ||
|
|
289
|
+
getInvitationStatus(record, input.revokedAt) !== "pending") {
|
|
290
|
+
return Option.none();
|
|
291
|
+
}
|
|
292
|
+
const revoked = {
|
|
293
|
+
...record,
|
|
294
|
+
revokedAt: input.revokedAt,
|
|
295
|
+
};
|
|
296
|
+
if (!isInvitationRecord(revoked)) {
|
|
297
|
+
return yield* Effect.fail(invitationStoreError("revoke", "Revoked invitation record is invalid"));
|
|
298
|
+
}
|
|
299
|
+
records.set(record.id, revoked);
|
|
300
|
+
return Option.some(cloneInvitationRecord(revoked));
|
|
301
|
+
}),
|
|
302
|
+
supersedePending: Effect.fn("auth.invitation.store.memory.supersede_pending")(function* (input) {
|
|
303
|
+
if (!isInvitationRecord(input.replacement)) {
|
|
304
|
+
return yield* Effect.fail(invitationStoreError("supersede", "Replacement invitation record is invalid"));
|
|
305
|
+
}
|
|
306
|
+
const record = records.get(input.id);
|
|
307
|
+
if (record === undefined ||
|
|
308
|
+
getInvitationStatus(record, input.supersededAt) !== "pending") {
|
|
309
|
+
return Option.none();
|
|
310
|
+
}
|
|
311
|
+
if (records.has(input.replacement.id)) {
|
|
312
|
+
return yield* Effect.fail(invitationStoreError("supersede", "Replacement invitation id already exists"));
|
|
313
|
+
}
|
|
314
|
+
const superseded = {
|
|
315
|
+
...record,
|
|
316
|
+
supersededAt: input.supersededAt,
|
|
317
|
+
supersededById: input.replacement.id,
|
|
318
|
+
};
|
|
319
|
+
if (!isInvitationRecord(superseded)) {
|
|
320
|
+
return yield* Effect.fail(invitationStoreError("supersede", "Superseded invitation record is invalid"));
|
|
321
|
+
}
|
|
322
|
+
const replacement = cloneInvitationRecord(input.replacement);
|
|
323
|
+
records.set(record.id, superseded);
|
|
324
|
+
records.set(replacement.id, replacement);
|
|
325
|
+
return Option.some({
|
|
326
|
+
superseded: cloneInvitationRecord(superseded),
|
|
327
|
+
replacement: cloneInvitationRecord(replacement),
|
|
328
|
+
});
|
|
329
|
+
}),
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
export const InvitationStoreMemoryLive = Layer.sync(InvitationStore)(invitationStoreMemory);
|
|
333
|
+
export class InvitationManagementError extends Data.TaggedError("InvitationManagementError") {
|
|
334
|
+
}
|
|
335
|
+
const invitationManagementError = (operation, message, cause) => new InvitationManagementError({
|
|
336
|
+
operation,
|
|
337
|
+
message,
|
|
338
|
+
...(cause === undefined ? {} : { cause }),
|
|
339
|
+
});
|
|
340
|
+
const validateInvitationText = (value, label, operation) => value.trim().length === 0
|
|
341
|
+
? Effect.fail(invitationManagementError(operation, `${label} must not be empty`))
|
|
342
|
+
: Effect.void;
|
|
343
|
+
const validateNewInvitation = (input, now, operation) => Effect.gen(function* () {
|
|
344
|
+
yield* validateInvitationText(input.kind, "Invitation kind", operation);
|
|
345
|
+
yield* validateInvitationText(input.target.type, "Invitation target type", operation);
|
|
346
|
+
yield* validateInvitationText(input.target.id, "Invitation target id", operation);
|
|
347
|
+
yield* validateInvitationText(input.intent.type, "Invitation intent type", operation);
|
|
348
|
+
if (!Number.isSafeInteger(input.intent.version) ||
|
|
349
|
+
input.intent.version < 1) {
|
|
350
|
+
return yield* Effect.fail(invitationManagementError(operation, "Invitation intent version must be a positive integer"));
|
|
351
|
+
}
|
|
352
|
+
if (!isInvitationJsonObject(input.intent.payload)) {
|
|
353
|
+
return yield* Effect.fail(invitationManagementError(operation, "Invitation intent payload must be JSON-compatible"));
|
|
354
|
+
}
|
|
355
|
+
if (input.metadata !== undefined &&
|
|
356
|
+
!isInvitationJsonObject(input.metadata)) {
|
|
357
|
+
return yield* Effect.fail(invitationManagementError(operation, "Invitation metadata must be JSON-compatible"));
|
|
358
|
+
}
|
|
359
|
+
if (input.recipient !== undefined) {
|
|
360
|
+
yield* validateInvitationText(input.recipient.type, "Invitation recipient type", operation);
|
|
361
|
+
yield* validateInvitationText(input.recipient.reference, "Invitation recipient reference", operation);
|
|
362
|
+
}
|
|
363
|
+
if (input.issuedBy !== undefined) {
|
|
364
|
+
yield* validateInvitationText(input.issuedBy.type, "Invitation issuer type", operation);
|
|
365
|
+
yield* validateInvitationText(input.issuedBy.id, "Invitation issuer id", operation);
|
|
366
|
+
}
|
|
367
|
+
if (!Number.isFinite(Number(input.expiresAt)) ||
|
|
368
|
+
Number(input.expiresAt) <= Number(now)) {
|
|
369
|
+
return yield* Effect.fail(invitationManagementError(operation, "Invitation expiry must be in the future"));
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
const invitationInfo = (record, now) => ({
|
|
373
|
+
id: record.id,
|
|
374
|
+
kind: record.kind,
|
|
375
|
+
target: { type: record.target.type, id: record.target.id },
|
|
376
|
+
intent: {
|
|
377
|
+
type: record.intent.type,
|
|
378
|
+
version: record.intent.version,
|
|
379
|
+
payload: structuredClone(record.intent.payload),
|
|
380
|
+
},
|
|
381
|
+
...(record.recipient === undefined
|
|
382
|
+
? {}
|
|
383
|
+
: {
|
|
384
|
+
recipient: {
|
|
385
|
+
type: record.recipient.type,
|
|
386
|
+
reference: record.recipient.reference,
|
|
387
|
+
},
|
|
388
|
+
}),
|
|
389
|
+
...(record.issuedBy === undefined
|
|
390
|
+
? {}
|
|
391
|
+
: { issuedBy: clonePermissionSubject(record.issuedBy) }),
|
|
392
|
+
createdAt: record.createdAt,
|
|
393
|
+
expiresAt: record.expiresAt,
|
|
394
|
+
status: getInvitationStatus(record, now),
|
|
395
|
+
...(record.acceptedAt === undefined ? {} : { acceptedAt: record.acceptedAt }),
|
|
396
|
+
...(record.acceptedBy === undefined
|
|
397
|
+
? {}
|
|
398
|
+
: { acceptedBy: clonePermissionSubject(record.acceptedBy) }),
|
|
399
|
+
...(record.revokedAt === undefined ? {} : { revokedAt: record.revokedAt }),
|
|
400
|
+
...(record.supersededAt === undefined
|
|
401
|
+
? {}
|
|
402
|
+
: { supersededAt: record.supersededAt }),
|
|
403
|
+
...(record.supersededById === undefined
|
|
404
|
+
? {}
|
|
405
|
+
: { supersededById: record.supersededById }),
|
|
406
|
+
...(record.metadata === undefined
|
|
407
|
+
? {}
|
|
408
|
+
: { metadata: cloneMetadata(record.metadata) }),
|
|
409
|
+
});
|
|
410
|
+
const invitationInspection = (record, now) => {
|
|
411
|
+
const { recipient, ...info } = invitationInfo(record, now);
|
|
412
|
+
return {
|
|
413
|
+
...info,
|
|
414
|
+
...(recipient === undefined ? {} : { recipientType: recipient.type }),
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
const prepareInvitation = (tokens, input, now, operation) => Effect.gen(function* () {
|
|
418
|
+
yield* validateNewInvitation(input, now, operation);
|
|
419
|
+
const generated = yield* tokens
|
|
420
|
+
.generate()
|
|
421
|
+
.pipe(Effect.mapError((cause) => invitationManagementError(operation, "Failed to generate invitation token", cause)));
|
|
422
|
+
const tokenHash = yield* tokens
|
|
423
|
+
.hash({ token: generated.token })
|
|
424
|
+
.pipe(Effect.mapError((cause) => invitationManagementError(operation, "Failed to hash invitation token", cause)));
|
|
425
|
+
const record = {
|
|
426
|
+
id: generated.id,
|
|
427
|
+
kind: input.kind,
|
|
428
|
+
target: { type: input.target.type, id: input.target.id },
|
|
429
|
+
intent: {
|
|
430
|
+
type: input.intent.type,
|
|
431
|
+
version: input.intent.version,
|
|
432
|
+
payload: structuredClone(input.intent.payload),
|
|
433
|
+
},
|
|
434
|
+
...(input.recipient === undefined
|
|
435
|
+
? {}
|
|
436
|
+
: {
|
|
437
|
+
recipient: {
|
|
438
|
+
type: input.recipient.type,
|
|
439
|
+
reference: input.recipient.reference,
|
|
440
|
+
},
|
|
441
|
+
}),
|
|
442
|
+
...(input.issuedBy === undefined
|
|
443
|
+
? {}
|
|
444
|
+
: { issuedBy: clonePermissionSubject(input.issuedBy) }),
|
|
445
|
+
createdAt: now,
|
|
446
|
+
expiresAt: input.expiresAt,
|
|
447
|
+
tokenHash,
|
|
448
|
+
...(input.metadata === undefined
|
|
449
|
+
? {}
|
|
450
|
+
: { metadata: cloneMetadata(input.metadata) }),
|
|
451
|
+
};
|
|
452
|
+
return { record, token: generated.token };
|
|
453
|
+
});
|
|
454
|
+
const invitationManagementService = Effect.gen(function* () {
|
|
455
|
+
const tokens = yield* InvitationTokens;
|
|
456
|
+
const store = yield* InvitationStore;
|
|
457
|
+
return {
|
|
458
|
+
issue: Effect.fn("auth.invitation.management.issue")(function* (input) {
|
|
459
|
+
const now = yield* currentUnixMillis;
|
|
460
|
+
const prepared = yield* prepareInvitation(tokens, input, now, "issue");
|
|
461
|
+
yield* store
|
|
462
|
+
.insert(prepared.record)
|
|
463
|
+
.pipe(Effect.mapError((cause) => invitationManagementError("issue", "Failed to store invitation", cause)));
|
|
464
|
+
return {
|
|
465
|
+
invitation: invitationInfo(prepared.record, now),
|
|
466
|
+
token: prepared.token,
|
|
467
|
+
};
|
|
468
|
+
}),
|
|
469
|
+
get: Effect.fn("auth.invitation.management.get")(function* (input) {
|
|
470
|
+
const now = yield* currentUnixMillis;
|
|
471
|
+
const record = yield* store
|
|
472
|
+
.findById(input.id)
|
|
473
|
+
.pipe(Effect.mapError((cause) => invitationManagementError("get", "Failed to load invitation", cause)));
|
|
474
|
+
if (Option.isNone(record)) {
|
|
475
|
+
return yield* Effect.fail(invitationManagementError("get", "Invitation not found"));
|
|
476
|
+
}
|
|
477
|
+
return invitationInfo(record.value, now);
|
|
478
|
+
}),
|
|
479
|
+
list: Effect.fn("auth.invitation.management.list")(function* (input = {}) {
|
|
480
|
+
const now = yield* currentUnixMillis;
|
|
481
|
+
const records = yield* store
|
|
482
|
+
.list({
|
|
483
|
+
now,
|
|
484
|
+
...(input.kind === undefined ? {} : { kind: input.kind }),
|
|
485
|
+
...(input.target === undefined ? {} : { target: input.target }),
|
|
486
|
+
...(input.recipient === undefined
|
|
487
|
+
? {}
|
|
488
|
+
: { recipient: input.recipient }),
|
|
489
|
+
...(input.issuedBy === undefined ? {} : { issuedBy: input.issuedBy }),
|
|
490
|
+
...(input.statuses === undefined ? {} : { statuses: input.statuses }),
|
|
491
|
+
})
|
|
492
|
+
.pipe(Effect.mapError((cause) => invitationManagementError("list", "Failed to list invitations", cause)));
|
|
493
|
+
return records.map((record) => invitationInfo(record, now));
|
|
494
|
+
}),
|
|
495
|
+
revoke: Effect.fn("auth.invitation.management.revoke")(function* (input) {
|
|
496
|
+
const now = yield* currentUnixMillis;
|
|
497
|
+
const revoked = yield* store
|
|
498
|
+
.revokePending({ id: input.id, revokedAt: now })
|
|
499
|
+
.pipe(Effect.mapError((cause) => invitationManagementError("revoke", "Failed to revoke invitation", cause)));
|
|
500
|
+
if (Option.isNone(revoked)) {
|
|
501
|
+
return yield* Effect.fail(invitationManagementError("revoke", "Invitation not found or not pending"));
|
|
502
|
+
}
|
|
503
|
+
return invitationInfo(revoked.value, now);
|
|
504
|
+
}),
|
|
505
|
+
supersede: Effect.fn("auth.invitation.management.supersede")(function* (input) {
|
|
506
|
+
const now = yield* currentUnixMillis;
|
|
507
|
+
const prepared = yield* prepareInvitation(tokens, input, now, "supersede");
|
|
508
|
+
const result = yield* store
|
|
509
|
+
.supersedePending({
|
|
510
|
+
id: input.id,
|
|
511
|
+
supersededAt: now,
|
|
512
|
+
replacement: prepared.record,
|
|
513
|
+
})
|
|
514
|
+
.pipe(Effect.mapError((cause) => invitationManagementError("supersede", "Failed to supersede invitation", cause)));
|
|
515
|
+
if (Option.isNone(result)) {
|
|
516
|
+
return yield* Effect.fail(invitationManagementError("supersede", "Invitation not found or not pending"));
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
superseded: invitationInfo(result.value.superseded, now),
|
|
520
|
+
invitation: invitationInfo(result.value.replacement, now),
|
|
521
|
+
token: prepared.token,
|
|
522
|
+
};
|
|
523
|
+
}),
|
|
524
|
+
};
|
|
525
|
+
});
|
|
526
|
+
export class InvitationManagement extends Context.Service()("auth/InvitationManagement", {
|
|
527
|
+
make: invitationManagementService,
|
|
528
|
+
}) {
|
|
529
|
+
}
|
|
530
|
+
export const InvitationManagementLive = Layer.effect(InvitationManagement)(InvitationManagement.make);
|
|
531
|
+
export class InvitationVerificationError extends Data.TaggedError("InvitationVerificationError") {
|
|
532
|
+
}
|
|
533
|
+
const invalidInvitationCredential = () => new InvitationVerificationError({
|
|
534
|
+
operation: "inspect",
|
|
535
|
+
message: "Invalid invitation credential",
|
|
536
|
+
});
|
|
537
|
+
const invitationVerificationService = Effect.gen(function* () {
|
|
538
|
+
const tokens = yield* InvitationTokens;
|
|
539
|
+
const store = yield* InvitationStore;
|
|
540
|
+
return {
|
|
541
|
+
inspect: Effect.fn("auth.invitation.verification.inspect")(function* (input) {
|
|
542
|
+
const parsed = yield* tokens
|
|
543
|
+
.parse(input.token)
|
|
544
|
+
.pipe(Effect.mapError(invalidInvitationCredential));
|
|
545
|
+
const record = yield* store.findById(parsed.id).pipe(Effect.mapError((cause) => new InvitationVerificationError({
|
|
546
|
+
operation: "inspect",
|
|
547
|
+
message: "Failed to inspect invitation",
|
|
548
|
+
cause,
|
|
549
|
+
})));
|
|
550
|
+
if (Option.isNone(record)) {
|
|
551
|
+
return yield* Effect.fail(invalidInvitationCredential());
|
|
552
|
+
}
|
|
553
|
+
if (!isInvitationRecord(record.value)) {
|
|
554
|
+
return yield* Effect.fail(invalidInvitationCredential());
|
|
555
|
+
}
|
|
556
|
+
const matches = yield* tokens
|
|
557
|
+
.verify({ token: input.token, tokenHash: record.value.tokenHash })
|
|
558
|
+
.pipe(Effect.mapError((cause) => new InvitationVerificationError({
|
|
559
|
+
operation: "inspect",
|
|
560
|
+
message: "Failed to inspect invitation",
|
|
561
|
+
cause,
|
|
562
|
+
})));
|
|
563
|
+
if (!matches) {
|
|
564
|
+
return yield* Effect.fail(invalidInvitationCredential());
|
|
565
|
+
}
|
|
566
|
+
const now = yield* currentUnixMillis;
|
|
567
|
+
if (getInvitationStatus(record.value, now) !== "pending") {
|
|
568
|
+
return yield* Effect.fail(invalidInvitationCredential());
|
|
569
|
+
}
|
|
570
|
+
return invitationInspection(record.value, now);
|
|
571
|
+
}),
|
|
572
|
+
};
|
|
573
|
+
});
|
|
574
|
+
export class InvitationVerification extends Context.Service()("auth/InvitationVerification", {
|
|
575
|
+
make: invitationVerificationService,
|
|
576
|
+
}) {
|
|
577
|
+
}
|
|
578
|
+
export const InvitationVerificationLive = Layer.effect(InvitationVerification)(InvitationVerification.make);
|
|
579
|
+
export class InvitationAcceptanceCommitError extends Data.TaggedError("InvitationAcceptanceCommitError") {
|
|
580
|
+
}
|
|
581
|
+
/** Atomically validates token/state and authoritative recipient eligibility, writes app state, and marks accepted. */
|
|
582
|
+
export class InvitationAcceptanceCommit extends Context.Service()("auth/InvitationAcceptanceCommit") {
|
|
583
|
+
}
|
|
584
|
+
export class InvitationAcceptanceError extends Data.TaggedError("InvitationAcceptanceError") {
|
|
585
|
+
}
|
|
586
|
+
const invitationAcceptanceService = Effect.gen(function* () {
|
|
587
|
+
const tokens = yield* InvitationTokens;
|
|
588
|
+
const acceptanceCommit = yield* InvitationAcceptanceCommit;
|
|
589
|
+
return {
|
|
590
|
+
accept: Effect.fn("auth.invitation.acceptance.accept")(function* (input) {
|
|
591
|
+
const parsed = yield* tokens.parse(input.token).pipe(Effect.mapError(() => new InvitationAcceptanceError({
|
|
592
|
+
operation: "accept",
|
|
593
|
+
message: "Invitation could not be accepted",
|
|
594
|
+
})));
|
|
595
|
+
const candidateTokenHash = yield* tokens
|
|
596
|
+
.hash({ token: input.token })
|
|
597
|
+
.pipe(Effect.mapError((cause) => new InvitationAcceptanceError({
|
|
598
|
+
operation: "accept",
|
|
599
|
+
message: "Failed to prepare invitation acceptance",
|
|
600
|
+
cause,
|
|
601
|
+
})));
|
|
602
|
+
const now = yield* currentUnixMillis;
|
|
603
|
+
const result = yield* acceptanceCommit
|
|
604
|
+
.commit({
|
|
605
|
+
id: parsed.id,
|
|
606
|
+
candidateTokenHash,
|
|
607
|
+
acceptingSubject: input.acceptingSubject,
|
|
608
|
+
commandId: input.commandId,
|
|
609
|
+
now,
|
|
610
|
+
})
|
|
611
|
+
.pipe(Effect.mapError(() => new InvitationAcceptanceError({
|
|
612
|
+
operation: "accept",
|
|
613
|
+
message: "Invitation could not be accepted",
|
|
614
|
+
})));
|
|
615
|
+
if (result.receipt.invitationId !== parsed.id ||
|
|
616
|
+
result.receipt.commandId !== input.commandId ||
|
|
617
|
+
result.receipt.credentialHash !== candidateTokenHash ||
|
|
618
|
+
!subjectsEqual(result.receipt.acceptedBy, input.acceptingSubject)) {
|
|
619
|
+
return yield* new InvitationAcceptanceError({
|
|
620
|
+
operation: "accept",
|
|
621
|
+
message: "Invitation could not be accepted",
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
return result;
|
|
625
|
+
}),
|
|
626
|
+
};
|
|
627
|
+
});
|
|
628
|
+
export class InvitationAcceptance extends Context.Service()("auth/InvitationAcceptance", {
|
|
629
|
+
make: invitationAcceptanceService,
|
|
630
|
+
}) {
|
|
631
|
+
}
|
|
632
|
+
export const InvitationAcceptanceLive = Layer.effect(InvitationAcceptance)(InvitationAcceptance.make);
|
|
633
|
+
//# sourceMappingURL=Invitation.js.map
|