@effect-auth/core 0.1.0-alpha.16 → 0.1.0-alpha.18
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 +308 -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/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/DrizzleDurableObjectSqliteStorage.d.ts +19 -0
- package/dist/DrizzleDurableObjectSqliteStorage.d.ts.map +1 -0
- package/dist/DrizzleDurableObjectSqliteStorage.js +14 -0
- package/dist/DrizzleDurableObjectSqliteStorage.js.map +1 -0
- 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/DrizzleWasmSqliteStorage.d.ts +23 -0
- package/dist/DrizzleWasmSqliteStorage.d.ts.map +1 -0
- package/dist/DrizzleWasmSqliteStorage.js +15 -0
- package/dist/DrizzleWasmSqliteStorage.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 +171 -0
- package/dist/EffectQbPostgresStorage.d.ts.map +1 -0
- package/dist/EffectQbPostgresStorage.js +4280 -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 +181 -23
- package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
- package/dist/EffectQbSqliteStorage.js +1728 -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 +879 -877
- package/dist/HttpApi/Api.d.ts.map +1 -1
- package/dist/HttpApi/Api.js +2160 -896
- 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 +629 -301
- package/dist/HttpApi/Endpoints.d.ts.map +1 -1
- package/dist/HttpApi/Endpoints.js +178 -120
- package/dist/HttpApi/Endpoints.js.map +1 -1
- package/dist/HttpApi/Errors.d.ts +26 -7
- package/dist/HttpApi/Errors.d.ts.map +1 -1
- package/dist/HttpApi/Errors.js +26 -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 +14 -0
- package/dist/HttpApi/Middleware.d.ts.map +1 -0
- package/dist/HttpApi/Middleware.js +5 -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/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/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 +16 -0
- package/dist/HttpApi/Operations/OAuthToken.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthToken.js +5 -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 +27 -0
- package/dist/HttpApi/Operations/index.d.ts.map +1 -0
- package/dist/HttpApi/Operations/index.js +27 -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 +361 -84
- package/dist/HttpApi/Schemas.d.ts.map +1 -1
- package/dist/HttpApi/Schemas.js +190 -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 +9 -3
- package/dist/HttpApi/index.d.ts.map +1 -1
- package/dist/HttpApi/index.js +8 -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 +93 -96
- package/dist/OAuth.d.ts.map +1 -1
- package/dist/OAuth.js +404 -217
- package/dist/OAuth.js.map +1 -1
- 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 +15 -0
- package/dist/PostgresStorageMigrations.d.ts.map +1 -0
- package/dist/PostgresStorageMigrations.js +620 -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/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/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 +6 -1
- package/dist/StorageMigrations.d.ts.map +1 -1
- package/dist/StorageMigrations.js +224 -0
- package/dist/StorageMigrations.js.map +1 -1
- package/dist/StorageSchemaGenerator.d.ts +486 -0
- package/dist/StorageSchemaGenerator.d.ts.map +1 -0
- package/dist/StorageSchemaGenerator.js +1022 -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/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/delegated-access/0001_auth_delegated_access.sql +112 -0
- package/package.json +301 -2
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
// oxlint-disable typescript/no-explicit-any, promise/prefer-await-to-then, unicorn/no-array-sort
|
|
2
|
+
import { Effect, Layer, Option, Schema } from "effect";
|
|
3
|
+
import { Column, Query, Scalar, Table } from "effect-qb";
|
|
4
|
+
import { Query as SqliteQuery } from "effect-qb/sqlite";
|
|
5
|
+
import { AccessGrantRecordSchema, AccessGrantStore, AccessGrantStoreError, isAccessGrantRecord, } from "./AccessGrant.js";
|
|
6
|
+
import { AtomicPlanError } from "./AtomicPlanExecutor.js";
|
|
7
|
+
import { makeD1EffectQbSqliteAtomicPlanExecutor, makeD1EffectQbSqliteExecutor, makeEffectQbSqliteStorage, } from "./EffectQbSqliteStorage.js";
|
|
8
|
+
import { getInvitationStatus, InvitationRecordSchema, InvitationStore, InvitationStoreError, isInvitationRecord, } from "./Invitation.js";
|
|
9
|
+
const delegatedAccessSqliteTablesTypeId = Symbol.for("@effect-auth/core/EffectQbSqliteDelegatedAccessStorage/DelegatedAccessSqliteTables");
|
|
10
|
+
const makeAuthInvitationTable = (name) => Table.make(name, {
|
|
11
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
12
|
+
kind: Column.text(),
|
|
13
|
+
target_type: Column.text(),
|
|
14
|
+
target_id: Column.text(),
|
|
15
|
+
intent_type: Column.text(),
|
|
16
|
+
intent_version: Column.int(),
|
|
17
|
+
intent_payload: Column.text(),
|
|
18
|
+
recipient_type: Column.text().pipe(Column.nullable),
|
|
19
|
+
recipient_reference: Column.text().pipe(Column.nullable),
|
|
20
|
+
issued_by_type: Column.text().pipe(Column.nullable),
|
|
21
|
+
issued_by_id: Column.text().pipe(Column.nullable),
|
|
22
|
+
created_at: Column.int(),
|
|
23
|
+
expires_at: Column.int(),
|
|
24
|
+
token_hash: Column.text(),
|
|
25
|
+
accepted_at: Column.int().pipe(Column.nullable),
|
|
26
|
+
accepted_by_type: Column.text().pipe(Column.nullable),
|
|
27
|
+
accepted_by_id: Column.text().pipe(Column.nullable),
|
|
28
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
29
|
+
superseded_at: Column.int().pipe(Column.nullable),
|
|
30
|
+
superseded_by_id: Column.text().pipe(Column.nullable),
|
|
31
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
32
|
+
});
|
|
33
|
+
const makeAuthAccessGrantTable = (name) => Table.make(name, {
|
|
34
|
+
id: Column.text().pipe(Column.primaryKey),
|
|
35
|
+
target_type: Column.text(),
|
|
36
|
+
target_id: Column.text(),
|
|
37
|
+
capabilities: Column.text(),
|
|
38
|
+
binding_type: Column.text(),
|
|
39
|
+
binding_subject_type: Column.text().pipe(Column.nullable),
|
|
40
|
+
binding_subject_id: Column.text().pipe(Column.nullable),
|
|
41
|
+
issuer_type: Column.text().pipe(Column.nullable),
|
|
42
|
+
issuer_id: Column.text().pipe(Column.nullable),
|
|
43
|
+
created_at: Column.int(),
|
|
44
|
+
expires_at: Column.int().pipe(Column.nullable),
|
|
45
|
+
token_hash: Column.text().pipe(Column.nullable),
|
|
46
|
+
revoked_at: Column.int().pipe(Column.nullable),
|
|
47
|
+
superseded_at: Column.int().pipe(Column.nullable),
|
|
48
|
+
superseded_by_id: Column.text().pipe(Column.nullable),
|
|
49
|
+
metadata: Column.text().pipe(Column.nullable),
|
|
50
|
+
});
|
|
51
|
+
const canonicalJsonValue = (value) => {
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return value.map(canonicalJsonValue);
|
|
54
|
+
}
|
|
55
|
+
if (typeof value !== "object" || value === null) {
|
|
56
|
+
return Object.is(value, -0) ? 0 : value;
|
|
57
|
+
}
|
|
58
|
+
return Object.fromEntries(Object.keys(value)
|
|
59
|
+
.sort()
|
|
60
|
+
.map((key) => [
|
|
61
|
+
key,
|
|
62
|
+
canonicalJsonValue(value[key]),
|
|
63
|
+
]));
|
|
64
|
+
};
|
|
65
|
+
const canonicalJson = (value) => {
|
|
66
|
+
const encoded = JSON.stringify(canonicalJsonValue(value));
|
|
67
|
+
if (encoded === undefined) {
|
|
68
|
+
throw new TypeError("Value is not JSON-serializable");
|
|
69
|
+
}
|
|
70
|
+
return encoded;
|
|
71
|
+
};
|
|
72
|
+
const invitationInsertValues = (record) => ({
|
|
73
|
+
id: record.id,
|
|
74
|
+
kind: record.kind,
|
|
75
|
+
target_type: record.target.type,
|
|
76
|
+
target_id: record.target.id,
|
|
77
|
+
intent_type: record.intent.type,
|
|
78
|
+
intent_version: record.intent.version,
|
|
79
|
+
intent_payload: canonicalJson(record.intent.payload),
|
|
80
|
+
recipient_type: record.recipient?.type ?? null,
|
|
81
|
+
recipient_reference: record.recipient?.reference ?? null,
|
|
82
|
+
issued_by_type: record.issuedBy?.type ?? null,
|
|
83
|
+
issued_by_id: record.issuedBy?.id ?? null,
|
|
84
|
+
created_at: Number(record.createdAt),
|
|
85
|
+
expires_at: Number(record.expiresAt),
|
|
86
|
+
token_hash: record.tokenHash,
|
|
87
|
+
accepted_at: record.acceptedAt === undefined ? null : Number(record.acceptedAt),
|
|
88
|
+
accepted_by_type: record.acceptedBy?.type ?? null,
|
|
89
|
+
accepted_by_id: record.acceptedBy?.id ?? null,
|
|
90
|
+
revoked_at: record.revokedAt === undefined ? null : Number(record.revokedAt),
|
|
91
|
+
superseded_at: record.supersededAt === undefined ? null : Number(record.supersededAt),
|
|
92
|
+
superseded_by_id: record.supersededById ?? null,
|
|
93
|
+
metadata: record.metadata === undefined ? null : canonicalJson(record.metadata),
|
|
94
|
+
});
|
|
95
|
+
const accessGrantInsertValues = (record) => {
|
|
96
|
+
const subject = record.binding.type === "bearer" ? undefined : record.binding.subject;
|
|
97
|
+
const tokenHash = "tokenHash" in record ? (record.tokenHash ?? null) : null;
|
|
98
|
+
return {
|
|
99
|
+
id: record.id,
|
|
100
|
+
target_type: record.target.type,
|
|
101
|
+
target_id: record.target.id,
|
|
102
|
+
capabilities: canonicalJson(record.capabilities),
|
|
103
|
+
binding_type: record.binding.type,
|
|
104
|
+
binding_subject_type: subject?.type ?? null,
|
|
105
|
+
binding_subject_id: subject?.id ?? null,
|
|
106
|
+
issuer_type: record.issuer?.type ?? null,
|
|
107
|
+
issuer_id: record.issuer?.id ?? null,
|
|
108
|
+
created_at: Number(record.createdAt),
|
|
109
|
+
expires_at: record.expiresAt === undefined ? null : Number(record.expiresAt),
|
|
110
|
+
token_hash: tokenHash,
|
|
111
|
+
revoked_at: record.revokedAt === undefined ? null : Number(record.revokedAt),
|
|
112
|
+
superseded_at: record.supersededAt === undefined ? null : Number(record.supersededAt),
|
|
113
|
+
superseded_by_id: record.supersededById ?? null,
|
|
114
|
+
metadata: record.metadata === undefined ? null : canonicalJson(record.metadata),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const makeInternalDelegatedAccessSqliteTables = (names) => {
|
|
118
|
+
const invitation = makeAuthInvitationTable(names.invitation ?? "auth_invitation");
|
|
119
|
+
const accessGrant = makeAuthAccessGrantTable(names.accessGrant ?? "auth_access_grant");
|
|
120
|
+
return {
|
|
121
|
+
invitation: {
|
|
122
|
+
table: invitation,
|
|
123
|
+
select: {
|
|
124
|
+
id: invitation.id,
|
|
125
|
+
kind: invitation.kind,
|
|
126
|
+
targetType: invitation.target_type,
|
|
127
|
+
targetId: invitation.target_id,
|
|
128
|
+
intentType: invitation.intent_type,
|
|
129
|
+
intentVersion: invitation.intent_version,
|
|
130
|
+
intentPayload: invitation.intent_payload,
|
|
131
|
+
recipientType: invitation.recipient_type,
|
|
132
|
+
recipientReference: invitation.recipient_reference,
|
|
133
|
+
issuedByType: invitation.issued_by_type,
|
|
134
|
+
issuedById: invitation.issued_by_id,
|
|
135
|
+
createdAt: invitation.created_at,
|
|
136
|
+
expiresAt: invitation.expires_at,
|
|
137
|
+
tokenHash: invitation.token_hash,
|
|
138
|
+
acceptedAt: invitation.accepted_at,
|
|
139
|
+
acceptedByType: invitation.accepted_by_type,
|
|
140
|
+
acceptedById: invitation.accepted_by_id,
|
|
141
|
+
revokedAt: invitation.revoked_at,
|
|
142
|
+
supersededAt: invitation.superseded_at,
|
|
143
|
+
supersededById: invitation.superseded_by_id,
|
|
144
|
+
metadata: invitation.metadata,
|
|
145
|
+
},
|
|
146
|
+
insert: invitationInsertValues,
|
|
147
|
+
revoke: (input) => ({ revoked_at: Number(input.revokedAt) }),
|
|
148
|
+
supersede: (input) => ({
|
|
149
|
+
superseded_at: Number(input.supersededAt),
|
|
150
|
+
superseded_by_id: input.replacement.id,
|
|
151
|
+
}),
|
|
152
|
+
},
|
|
153
|
+
accessGrant: {
|
|
154
|
+
table: accessGrant,
|
|
155
|
+
conflictTarget: "id",
|
|
156
|
+
select: {
|
|
157
|
+
id: accessGrant.id,
|
|
158
|
+
targetType: accessGrant.target_type,
|
|
159
|
+
targetId: accessGrant.target_id,
|
|
160
|
+
capabilities: accessGrant.capabilities,
|
|
161
|
+
bindingType: accessGrant.binding_type,
|
|
162
|
+
bindingSubjectType: accessGrant.binding_subject_type,
|
|
163
|
+
bindingSubjectId: accessGrant.binding_subject_id,
|
|
164
|
+
issuerType: accessGrant.issuer_type,
|
|
165
|
+
issuerId: accessGrant.issuer_id,
|
|
166
|
+
createdAt: accessGrant.created_at,
|
|
167
|
+
expiresAt: accessGrant.expires_at,
|
|
168
|
+
tokenHash: accessGrant.token_hash,
|
|
169
|
+
revokedAt: accessGrant.revoked_at,
|
|
170
|
+
supersededAt: accessGrant.superseded_at,
|
|
171
|
+
supersededById: accessGrant.superseded_by_id,
|
|
172
|
+
metadata: accessGrant.metadata,
|
|
173
|
+
},
|
|
174
|
+
insert: accessGrantInsertValues,
|
|
175
|
+
revoke: (input) => ({ revoked_at: Number(input.revokedAt) }),
|
|
176
|
+
supersede: (input) => ({
|
|
177
|
+
superseded_at: Number(input.supersededAt),
|
|
178
|
+
superseded_by_id: input.replacement.id,
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const asDelegatedAccessSqliteTables = (tables) => tables;
|
|
184
|
+
export const defineEffectQbDelegatedAccessTables = (tables) => asDelegatedAccessSqliteTables(tables);
|
|
185
|
+
export const makeDelegatedAccessSqliteTables = (names = {}) => asDelegatedAccessSqliteTables(makeInternalDelegatedAccessSqliteTables(names));
|
|
186
|
+
export const delegatedAccessSqliteTables = makeDelegatedAccessSqliteTables();
|
|
187
|
+
const mutationValues = (value) => value;
|
|
188
|
+
const queryInsert = (table, values) => Query.insert(table, values);
|
|
189
|
+
const queryUpdate = (table, values) => Query.update(table, values);
|
|
190
|
+
const queryEq = (left, right) => Query.eq(left, right);
|
|
191
|
+
const queryGt = (left, right) => Query.gt(left, right);
|
|
192
|
+
const queryLte = (left, right) => Query.lte(left, right);
|
|
193
|
+
const queryIsNull = (value) => Query.isNull(value);
|
|
194
|
+
const queryIsNotNull = (value) => Query.isNotNull(value);
|
|
195
|
+
const queryAnd = (...values) => Query.and(...values);
|
|
196
|
+
const queryOr = (...values) => Query.or(...values);
|
|
197
|
+
const queryChangedOne = () => queryEq(Query.call("changes"), 1);
|
|
198
|
+
const queryAstTypeId = Symbol.for("effect-qb/QueryAst");
|
|
199
|
+
const targetMutationExpression = (table, columnName, value) => {
|
|
200
|
+
if (value === null) {
|
|
201
|
+
return Query.literal(null);
|
|
202
|
+
}
|
|
203
|
+
const plan = queryUpdate(table, { [columnName]: value });
|
|
204
|
+
const ast = plan[queryAstTypeId];
|
|
205
|
+
const assignment = ast?.set?.find((candidate) => candidate.columnName === columnName);
|
|
206
|
+
if (assignment === undefined) {
|
|
207
|
+
throw new TypeError(`Invalid SQLite mutation column: ${columnName}`);
|
|
208
|
+
}
|
|
209
|
+
return assignment.value;
|
|
210
|
+
};
|
|
211
|
+
const queryInsertWhere = (table, values, predicate) => {
|
|
212
|
+
const selection = Object.fromEntries(Object.entries(values).map(([key, value]) => [
|
|
213
|
+
key,
|
|
214
|
+
targetMutationExpression(table, key, value),
|
|
215
|
+
]));
|
|
216
|
+
const select = Query.where(predicate)(Query.select(selection));
|
|
217
|
+
return Query.from(select)(Query.insert(table));
|
|
218
|
+
};
|
|
219
|
+
const executePlan = (executor, plan) => executor.execute(plan);
|
|
220
|
+
const isNullish = (value) => value === null || value === undefined;
|
|
221
|
+
const jsonText = (value, field) => {
|
|
222
|
+
if (typeof value !== "string") {
|
|
223
|
+
throw new TypeError(`${field} must be JSON text`);
|
|
224
|
+
}
|
|
225
|
+
return JSON.parse(value);
|
|
226
|
+
};
|
|
227
|
+
const optionalJsonText = (value, field) => isNullish(value) ? undefined : jsonText(value, field);
|
|
228
|
+
const decodeInvitationRecordUnknown = Schema.decodeUnknownSync(InvitationRecordSchema);
|
|
229
|
+
const decodeAccessGrantRecordUnknown = Schema.decodeUnknownSync(AccessGrantRecordSchema);
|
|
230
|
+
const decodeDefaultInvitationRecord = (row) => decodeInvitationRecordUnknown({
|
|
231
|
+
id: row.id,
|
|
232
|
+
kind: row.kind,
|
|
233
|
+
target: { type: row.targetType, id: row.targetId },
|
|
234
|
+
intent: {
|
|
235
|
+
type: row.intentType,
|
|
236
|
+
version: Number(row.intentVersion),
|
|
237
|
+
payload: jsonText(row.intentPayload, "Invitation intent payload"),
|
|
238
|
+
},
|
|
239
|
+
...(isNullish(row.recipientType) && isNullish(row.recipientReference)
|
|
240
|
+
? {}
|
|
241
|
+
: {
|
|
242
|
+
recipient: {
|
|
243
|
+
type: row.recipientType,
|
|
244
|
+
reference: row.recipientReference,
|
|
245
|
+
},
|
|
246
|
+
}),
|
|
247
|
+
...(isNullish(row.issuedByType) && isNullish(row.issuedById)
|
|
248
|
+
? {}
|
|
249
|
+
: { issuedBy: { type: row.issuedByType, id: row.issuedById } }),
|
|
250
|
+
createdAt: Number(row.createdAt),
|
|
251
|
+
expiresAt: Number(row.expiresAt),
|
|
252
|
+
tokenHash: row.tokenHash,
|
|
253
|
+
...(isNullish(row.acceptedAt)
|
|
254
|
+
? {}
|
|
255
|
+
: { acceptedAt: Number(row.acceptedAt) }),
|
|
256
|
+
...(isNullish(row.acceptedByType) && isNullish(row.acceptedById)
|
|
257
|
+
? {}
|
|
258
|
+
: {
|
|
259
|
+
acceptedBy: {
|
|
260
|
+
type: row.acceptedByType,
|
|
261
|
+
id: row.acceptedById,
|
|
262
|
+
},
|
|
263
|
+
}),
|
|
264
|
+
...(isNullish(row.revokedAt) ? {} : { revokedAt: Number(row.revokedAt) }),
|
|
265
|
+
...(isNullish(row.supersededAt)
|
|
266
|
+
? {}
|
|
267
|
+
: { supersededAt: Number(row.supersededAt) }),
|
|
268
|
+
...(isNullish(row.supersededById)
|
|
269
|
+
? {}
|
|
270
|
+
: { supersededById: row.supersededById }),
|
|
271
|
+
...(isNullish(row.metadata)
|
|
272
|
+
? {}
|
|
273
|
+
: { metadata: optionalJsonText(row.metadata, "Invitation metadata") }),
|
|
274
|
+
});
|
|
275
|
+
const decodeDefaultAccessGrantRecord = (row) => {
|
|
276
|
+
const binding = row.bindingType === "bearer"
|
|
277
|
+
? { type: row.bindingType }
|
|
278
|
+
: {
|
|
279
|
+
type: row.bindingType,
|
|
280
|
+
subject: {
|
|
281
|
+
type: row.bindingSubjectType,
|
|
282
|
+
id: row.bindingSubjectId,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
return decodeAccessGrantRecordUnknown({
|
|
286
|
+
id: row.id,
|
|
287
|
+
target: { type: row.targetType, id: row.targetId },
|
|
288
|
+
capabilities: jsonText(row.capabilities, "Access grant capabilities"),
|
|
289
|
+
binding,
|
|
290
|
+
...(isNullish(row.issuerType) && isNullish(row.issuerId)
|
|
291
|
+
? {}
|
|
292
|
+
: { issuer: { type: row.issuerType, id: row.issuerId } }),
|
|
293
|
+
createdAt: Number(row.createdAt),
|
|
294
|
+
...(isNullish(row.expiresAt) ? {} : { expiresAt: Number(row.expiresAt) }),
|
|
295
|
+
...(isNullish(row.tokenHash) ? {} : { tokenHash: row.tokenHash }),
|
|
296
|
+
...(isNullish(row.revokedAt) ? {} : { revokedAt: Number(row.revokedAt) }),
|
|
297
|
+
...(isNullish(row.supersededAt)
|
|
298
|
+
? {}
|
|
299
|
+
: { supersededAt: Number(row.supersededAt) }),
|
|
300
|
+
...(isNullish(row.supersededById)
|
|
301
|
+
? {}
|
|
302
|
+
: { supersededById: row.supersededById }),
|
|
303
|
+
...(isNullish(row.metadata)
|
|
304
|
+
? {}
|
|
305
|
+
: { metadata: optionalJsonText(row.metadata, "Access grant metadata") }),
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
const decodeInvitationRecord = (tables, row) => decodeInvitationRecordUnknown(tables.invitation.decode === undefined
|
|
309
|
+
? decodeDefaultInvitationRecord(row)
|
|
310
|
+
: tables.invitation.decode(row));
|
|
311
|
+
const decodeAccessGrantRecord = (tables, row) => decodeAccessGrantRecordUnknown(tables.accessGrant.decode === undefined
|
|
312
|
+
? decodeDefaultAccessGrantRecord(row)
|
|
313
|
+
: tables.accessGrant.decode(row));
|
|
314
|
+
const invitationStoreError = (operation, message, cause) => new InvitationStoreError({
|
|
315
|
+
operation,
|
|
316
|
+
message,
|
|
317
|
+
...(cause === undefined ? {} : { cause }),
|
|
318
|
+
});
|
|
319
|
+
const accessGrantStoreError = (operation, message, cause) => new AccessGrantStoreError({
|
|
320
|
+
operation,
|
|
321
|
+
message,
|
|
322
|
+
...(cause === undefined ? {} : { cause }),
|
|
323
|
+
});
|
|
324
|
+
const validateInvitationRecord = (record, operation, message) => Effect.try({
|
|
325
|
+
try: () => decodeInvitationRecordUnknown(record),
|
|
326
|
+
catch: (cause) => invitationStoreError(operation, message, cause),
|
|
327
|
+
});
|
|
328
|
+
const validateAccessGrantRecord = (record, operation, message) => Effect.try({
|
|
329
|
+
try: () => decodeAccessGrantRecordUnknown(record),
|
|
330
|
+
catch: (cause) => accessGrantStoreError(operation, message, cause),
|
|
331
|
+
});
|
|
332
|
+
const isSqliteUniqueViolation = (cause) => {
|
|
333
|
+
const pending = [cause];
|
|
334
|
+
const seen = new Set();
|
|
335
|
+
while (pending.length > 0) {
|
|
336
|
+
const current = pending.pop();
|
|
337
|
+
if (isNullish(current) || seen.has(current)) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
seen.add(current);
|
|
341
|
+
if (typeof current === "string") {
|
|
342
|
+
if (current === "UniqueViolation" ||
|
|
343
|
+
/\bUNIQUE constraint failed\b/i.test(current) ||
|
|
344
|
+
/\bPRIMARY KEY constraint failed\b/i.test(current)) {
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
if (typeof current !== "object") {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const record = current;
|
|
353
|
+
const { code, errno, message, name, _tag } = record;
|
|
354
|
+
if (_tag === "UniqueViolation" || name === "UniqueViolation") {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
if (code === "SQLITE_CONSTRAINT_UNIQUE" ||
|
|
358
|
+
code === "SQLITE_CONSTRAINT_PRIMARYKEY" ||
|
|
359
|
+
errno === 2067 ||
|
|
360
|
+
errno === 1555) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
if (typeof message === "string" &&
|
|
364
|
+
(/\bUNIQUE constraint failed\b/i.test(message) ||
|
|
365
|
+
/\bPRIMARY KEY constraint failed\b/i.test(message))) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
pending.push(record.cause, record.reason, record.error, record.raw);
|
|
369
|
+
if (Array.isArray(record.failures)) {
|
|
370
|
+
pending.push(...record.failures);
|
|
371
|
+
}
|
|
372
|
+
if (Array.isArray(record.reasons)) {
|
|
373
|
+
pending.push(...record.reasons);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return false;
|
|
377
|
+
};
|
|
378
|
+
const isAtomicUniqueViolation = (cause) => cause instanceof AtomicPlanError &&
|
|
379
|
+
cause.phase === "execute" &&
|
|
380
|
+
(cause.statement === undefined || cause.statement === 1) &&
|
|
381
|
+
isSqliteUniqueViolation(cause.cause);
|
|
382
|
+
const decodeInvitationRows = (tables, rows, operation) => Effect.try({
|
|
383
|
+
try: () => rows.map((row) => decodeInvitationRecord(tables, row)),
|
|
384
|
+
catch: (cause) => invitationStoreError(operation, "Stored invitation record is invalid", cause),
|
|
385
|
+
});
|
|
386
|
+
const decodeAccessGrantRows = (tables, rows, operation) => Effect.try({
|
|
387
|
+
try: () => rows.map((row) => decodeAccessGrantRecord(tables, row)),
|
|
388
|
+
catch: (cause) => accessGrantStoreError(operation, "Stored access grant record is invalid", cause),
|
|
389
|
+
});
|
|
390
|
+
const invitationPendingPredicates = (tables, id, now) => [
|
|
391
|
+
queryEq(tables.invitation.select.id, id),
|
|
392
|
+
queryIsNull(tables.invitation.select.acceptedAt),
|
|
393
|
+
queryIsNull(tables.invitation.select.acceptedByType),
|
|
394
|
+
queryIsNull(tables.invitation.select.acceptedById),
|
|
395
|
+
queryIsNull(tables.invitation.select.revokedAt),
|
|
396
|
+
queryIsNull(tables.invitation.select.supersededAt),
|
|
397
|
+
queryIsNull(tables.invitation.select.supersededById),
|
|
398
|
+
queryGt(tables.invitation.select.expiresAt, now),
|
|
399
|
+
];
|
|
400
|
+
const accessGrantActivePredicates = (tables, id, now) => [
|
|
401
|
+
queryEq(tables.accessGrant.select.id, id),
|
|
402
|
+
queryIsNull(tables.accessGrant.select.revokedAt),
|
|
403
|
+
queryIsNull(tables.accessGrant.select.supersededAt),
|
|
404
|
+
queryIsNull(tables.accessGrant.select.supersededById),
|
|
405
|
+
queryOr(queryIsNull(tables.accessGrant.select.expiresAt), queryGt(tables.accessGrant.select.expiresAt, now)),
|
|
406
|
+
];
|
|
407
|
+
const invitationTerminalClearPredicate = (tables) => queryAnd(queryIsNull(tables.invitation.select.acceptedAt), queryIsNull(tables.invitation.select.acceptedByType), queryIsNull(tables.invitation.select.acceptedById), queryIsNull(tables.invitation.select.revokedAt), queryIsNull(tables.invitation.select.supersededAt), queryIsNull(tables.invitation.select.supersededById));
|
|
408
|
+
const invitationStatusPredicate = (tables, status, now) => {
|
|
409
|
+
switch (status) {
|
|
410
|
+
case "accepted": {
|
|
411
|
+
return queryAnd(queryIsNotNull(tables.invitation.select.acceptedAt), queryIsNotNull(tables.invitation.select.acceptedByType), queryIsNotNull(tables.invitation.select.acceptedById), queryIsNull(tables.invitation.select.revokedAt), queryIsNull(tables.invitation.select.supersededAt), queryIsNull(tables.invitation.select.supersededById));
|
|
412
|
+
}
|
|
413
|
+
case "revoked": {
|
|
414
|
+
return queryAnd(queryIsNull(tables.invitation.select.acceptedAt), queryIsNull(tables.invitation.select.acceptedByType), queryIsNull(tables.invitation.select.acceptedById), queryIsNotNull(tables.invitation.select.revokedAt), queryIsNull(tables.invitation.select.supersededAt), queryIsNull(tables.invitation.select.supersededById));
|
|
415
|
+
}
|
|
416
|
+
case "superseded": {
|
|
417
|
+
return queryAnd(queryIsNull(tables.invitation.select.acceptedAt), queryIsNull(tables.invitation.select.acceptedByType), queryIsNull(tables.invitation.select.acceptedById), queryIsNull(tables.invitation.select.revokedAt), queryIsNotNull(tables.invitation.select.supersededAt), queryIsNotNull(tables.invitation.select.supersededById));
|
|
418
|
+
}
|
|
419
|
+
case "pending": {
|
|
420
|
+
return queryAnd(invitationTerminalClearPredicate(tables), queryGt(tables.invitation.select.expiresAt, now));
|
|
421
|
+
}
|
|
422
|
+
case "expired": {
|
|
423
|
+
return queryAnd(invitationTerminalClearPredicate(tables), queryLte(tables.invitation.select.expiresAt, now));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
const isAccessGrantActive = (record, now) => record.revokedAt === undefined &&
|
|
428
|
+
record.supersededAt === undefined &&
|
|
429
|
+
(record.expiresAt === undefined || now < Number(record.expiresAt));
|
|
430
|
+
const whereAll = (plan, predicates) => {
|
|
431
|
+
let current = plan;
|
|
432
|
+
for (const predicate of predicates) {
|
|
433
|
+
current = current.pipe(Query.where(predicate));
|
|
434
|
+
}
|
|
435
|
+
return current;
|
|
436
|
+
};
|
|
437
|
+
export const makeEffectQbSqliteInvitationStore = (executor, atomic, options = {}) => {
|
|
438
|
+
const tables = options.tables ?? delegatedAccessSqliteTables;
|
|
439
|
+
const findById = (id, operation = "find") => executePlan(executor, Query.select(tables.invitation.select).pipe(Query.from(tables.invitation.table), Query.where(queryEq(tables.invitation.select.id, id)))).pipe(Effect.mapError((cause) => invitationStoreError(operation, "Failed to load invitation", cause)), Effect.flatMap((rows) => decodeInvitationRows(tables, rows, operation)), Effect.map((rows) => rows[0] === undefined ? Option.none() : Option.some(rows[0])));
|
|
440
|
+
return InvitationStore.of({
|
|
441
|
+
insert: (record) => {
|
|
442
|
+
if (!isInvitationRecord(record)) {
|
|
443
|
+
return Effect.fail(invitationStoreError("insert", "Invitation record is invalid"));
|
|
444
|
+
}
|
|
445
|
+
return executePlan(executor, queryInsert(tables.invitation.table, mutationValues(tables.invitation.insert(record)))).pipe(Effect.mapError((cause) => invitationStoreError("insert", "Failed to insert invitation", cause)), Effect.asVoid);
|
|
446
|
+
},
|
|
447
|
+
findById,
|
|
448
|
+
list: (input) => {
|
|
449
|
+
const recognizedStatuses = input.statuses === undefined
|
|
450
|
+
? undefined
|
|
451
|
+
: [...new Set(input.statuses)].filter((status) => status !== "invalid");
|
|
452
|
+
if (input.statuses !== undefined &&
|
|
453
|
+
(input.statuses.length === 0 || recognizedStatuses?.length === 0)) {
|
|
454
|
+
return Effect.succeed([]);
|
|
455
|
+
}
|
|
456
|
+
let plan = Query.select(tables.invitation.select).pipe(Query.from(tables.invitation.table));
|
|
457
|
+
if (input.kind !== undefined) {
|
|
458
|
+
plan = plan.pipe(Query.where(queryEq(tables.invitation.select.kind, input.kind)));
|
|
459
|
+
}
|
|
460
|
+
if (input.target !== undefined) {
|
|
461
|
+
plan = plan.pipe(Query.where(queryAnd(queryEq(tables.invitation.select.targetType, input.target.type), queryEq(tables.invitation.select.targetId, input.target.id))));
|
|
462
|
+
}
|
|
463
|
+
if (input.recipient !== undefined) {
|
|
464
|
+
plan = plan.pipe(Query.where(queryAnd(queryEq(tables.invitation.select.recipientType, input.recipient.type), queryEq(tables.invitation.select.recipientReference, input.recipient.reference))));
|
|
465
|
+
}
|
|
466
|
+
if (input.issuedBy !== undefined) {
|
|
467
|
+
plan = plan.pipe(Query.where(queryAnd(queryEq(tables.invitation.select.issuedByType, input.issuedBy.type), queryEq(tables.invitation.select.issuedById, input.issuedBy.id))));
|
|
468
|
+
}
|
|
469
|
+
if (recognizedStatuses !== undefined) {
|
|
470
|
+
const predicates = recognizedStatuses.map((status) => invitationStatusPredicate(tables, status, Number(input.now)));
|
|
471
|
+
plan = plan.pipe(Query.where(predicates.length === 1
|
|
472
|
+
? predicates[0]
|
|
473
|
+
: queryOr(...predicates)));
|
|
474
|
+
}
|
|
475
|
+
plan = plan.pipe(Query.orderBy(tables.invitation.select.createdAt, "asc"), Query.orderBy(tables.invitation.select.id, "asc"));
|
|
476
|
+
return executePlan(executor, plan).pipe(Effect.mapError((cause) => invitationStoreError("list", "Failed to list invitations", cause)), Effect.flatMap((rows) => decodeInvitationRows(tables, rows, "list")));
|
|
477
|
+
},
|
|
478
|
+
revokePending: (input) => findById(input.id, "revoke").pipe(Effect.flatMap((current) => {
|
|
479
|
+
if (Option.isNone(current) ||
|
|
480
|
+
getInvitationStatus(current.value, input.revokedAt) !== "pending") {
|
|
481
|
+
return Effect.succeed(Option.none());
|
|
482
|
+
}
|
|
483
|
+
const candidate = {
|
|
484
|
+
...current.value,
|
|
485
|
+
revokedAt: input.revokedAt,
|
|
486
|
+
};
|
|
487
|
+
return validateInvitationRecord(candidate, "revoke", "Revoked invitation record is invalid").pipe(Effect.flatMap((revoked) => {
|
|
488
|
+
const plan = whereAll(queryUpdate(tables.invitation.table, mutationValues(tables.invitation.revoke(input))), invitationPendingPredicates(tables, input.id, Number(input.revokedAt))).pipe(Query.returning({ changed: Query.literal(1) }));
|
|
489
|
+
const executed = atomic.execute([plan]);
|
|
490
|
+
return executed.pipe(Effect.mapError((cause) => invitationStoreError("revoke", "Failed to revoke invitation", cause)), Effect.map(([rows]) => rows.length === 1 ? Option.some(revoked) : Option.none()));
|
|
491
|
+
}));
|
|
492
|
+
})),
|
|
493
|
+
supersedePending: (input) => validateInvitationRecord(input.replacement, "supersede", "Replacement invitation record is invalid").pipe(Effect.flatMap((replacement) => findById(input.id, "supersede").pipe(Effect.flatMap((current) => {
|
|
494
|
+
if (Option.isNone(current) ||
|
|
495
|
+
getInvitationStatus(current.value, input.supersededAt) !==
|
|
496
|
+
"pending") {
|
|
497
|
+
return Effect.succeed(Option.none());
|
|
498
|
+
}
|
|
499
|
+
const candidate = {
|
|
500
|
+
...current.value,
|
|
501
|
+
supersededAt: input.supersededAt,
|
|
502
|
+
supersededById: replacement.id,
|
|
503
|
+
};
|
|
504
|
+
return validateInvitationRecord(candidate, "supersede", "Superseded invitation record is invalid").pipe(Effect.flatMap((superseded) => {
|
|
505
|
+
const transition = { ...input, replacement };
|
|
506
|
+
const updatePlan = whereAll(queryUpdate(tables.invitation.table, mutationValues(tables.invitation.supersede(transition))), invitationPendingPredicates(tables, input.id, Number(input.supersededAt))).pipe(Query.returning({ changed: Query.literal(1) }));
|
|
507
|
+
const insertPlan = queryInsertWhere(tables.invitation.table, mutationValues(tables.invitation.insert(replacement)), queryChangedOne()).pipe(Query.returning({ changed: Query.literal(1) }));
|
|
508
|
+
const executed = atomic.execute([
|
|
509
|
+
updatePlan,
|
|
510
|
+
insertPlan,
|
|
511
|
+
]);
|
|
512
|
+
return executed.pipe(Effect.mapError((cause) => invitationStoreError("supersede", "Failed to supersede invitation", cause)), Effect.map(([updated, inserted]) => updated.length === 1 && inserted.length === 1
|
|
513
|
+
? Option.some({ superseded, replacement })
|
|
514
|
+
: Option.none()));
|
|
515
|
+
}));
|
|
516
|
+
})))),
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
export const makeEffectQbSqliteAccessGrantStore = (executor, atomic, options = {}) => {
|
|
520
|
+
const tables = options.tables ?? delegatedAccessSqliteTables;
|
|
521
|
+
const findById = (id, operation = "find") => executePlan(executor, Query.select(tables.accessGrant.select).pipe(Query.from(tables.accessGrant.table), Query.where(queryEq(tables.accessGrant.select.id, id)))).pipe(Effect.mapError((cause) => accessGrantStoreError(operation, "Failed to load access grant", cause)), Effect.flatMap((rows) => decodeAccessGrantRows(tables, rows, operation)), Effect.map((rows) => rows[0] === undefined ? Option.none() : Option.some(rows[0])));
|
|
522
|
+
return AccessGrantStore.of({
|
|
523
|
+
insert: (record) => {
|
|
524
|
+
if (!isAccessGrantRecord(record)) {
|
|
525
|
+
return Effect.fail(accessGrantStoreError("insert", "Access grant record is invalid"));
|
|
526
|
+
}
|
|
527
|
+
const onConflict = SqliteQuery.onConflict(tables.accessGrant.conflictTarget);
|
|
528
|
+
return executePlan(executor, queryInsert(tables.accessGrant.table, mutationValues(tables.accessGrant.insert(record))).pipe(onConflict, Query.returning({ id: tables.accessGrant.select.id }))).pipe(Effect.mapError((cause) => accessGrantStoreError("insert", "Failed to insert access grant", cause)), Effect.map((rows) => rows.length === 1));
|
|
529
|
+
},
|
|
530
|
+
findById,
|
|
531
|
+
list: (input = {}) => {
|
|
532
|
+
let plan = Query.select(tables.accessGrant.select).pipe(Query.from(tables.accessGrant.table));
|
|
533
|
+
if (input.target !== undefined) {
|
|
534
|
+
plan = plan.pipe(Query.where(queryAnd(queryEq(tables.accessGrant.select.targetType, input.target.type), queryEq(tables.accessGrant.select.targetId, input.target.id))));
|
|
535
|
+
}
|
|
536
|
+
if (input.issuer !== undefined) {
|
|
537
|
+
plan = plan.pipe(Query.where(queryAnd(queryEq(tables.accessGrant.select.issuerType, input.issuer.type), queryEq(tables.accessGrant.select.issuerId, input.issuer.id))));
|
|
538
|
+
}
|
|
539
|
+
if (input.subject !== undefined) {
|
|
540
|
+
plan = plan.pipe(Query.where(queryAnd(queryEq(tables.accessGrant.select.bindingSubjectType, input.subject.type), queryEq(tables.accessGrant.select.bindingSubjectId, input.subject.id))));
|
|
541
|
+
}
|
|
542
|
+
plan = plan.pipe(Query.orderBy(tables.accessGrant.select.createdAt, "asc"), Query.orderBy(tables.accessGrant.select.id, "asc"));
|
|
543
|
+
return executePlan(executor, plan).pipe(Effect.mapError((cause) => accessGrantStoreError("list", "Failed to list access grants", cause)), Effect.flatMap((rows) => decodeAccessGrantRows(tables, rows, "list")));
|
|
544
|
+
},
|
|
545
|
+
revoke: (input) => findById(input.id, "revoke").pipe(Effect.flatMap((current) => {
|
|
546
|
+
if (Option.isNone(current) ||
|
|
547
|
+
!isAccessGrantActive(current.value, Number(input.revokedAt))) {
|
|
548
|
+
return Effect.succeed(Option.none());
|
|
549
|
+
}
|
|
550
|
+
const candidate = {
|
|
551
|
+
...current.value,
|
|
552
|
+
revokedAt: input.revokedAt,
|
|
553
|
+
};
|
|
554
|
+
return validateAccessGrantRecord(candidate, "revoke", "Revoked access grant record is invalid").pipe(Effect.flatMap((revoked) => {
|
|
555
|
+
const plan = whereAll(queryUpdate(tables.accessGrant.table, mutationValues(tables.accessGrant.revoke(input))), accessGrantActivePredicates(tables, input.id, Number(input.revokedAt))).pipe(Query.returning({ changed: Query.literal(1) }));
|
|
556
|
+
const executed = atomic.execute([plan]);
|
|
557
|
+
return executed.pipe(Effect.mapError((cause) => accessGrantStoreError("revoke", "Failed to revoke access grant", cause)), Effect.map(([rows]) => rows.length === 1 ? Option.some(revoked) : Option.none()));
|
|
558
|
+
}));
|
|
559
|
+
})),
|
|
560
|
+
supersede: (input) => validateAccessGrantRecord(input.replacement, "supersede", "Replacement access grant record is invalid").pipe(Effect.flatMap((replacement) => findById(input.id, "supersede").pipe(Effect.flatMap((current) => {
|
|
561
|
+
if (Option.isNone(current) ||
|
|
562
|
+
!isAccessGrantActive(current.value, Number(input.supersededAt))) {
|
|
563
|
+
return Effect.succeed(Option.none());
|
|
564
|
+
}
|
|
565
|
+
const candidate = {
|
|
566
|
+
...current.value,
|
|
567
|
+
supersededAt: input.supersededAt,
|
|
568
|
+
supersededById: replacement.id,
|
|
569
|
+
};
|
|
570
|
+
return validateAccessGrantRecord(candidate, "supersede", "Superseded access grant record is invalid").pipe(Effect.flatMap((previous) => {
|
|
571
|
+
const transition = { ...input, replacement };
|
|
572
|
+
const updatePlan = whereAll(queryUpdate(tables.accessGrant.table, mutationValues(tables.accessGrant.supersede(transition))), accessGrantActivePredicates(tables, input.id, Number(input.supersededAt))).pipe(Query.returning({ changed: Query.literal(1) }));
|
|
573
|
+
const insertPlan = queryInsertWhere(tables.accessGrant.table, mutationValues(tables.accessGrant.insert(replacement)), queryChangedOne()).pipe(Query.returning({ changed: Query.literal(1) }));
|
|
574
|
+
const executed = atomic.execute([
|
|
575
|
+
updatePlan,
|
|
576
|
+
insertPlan,
|
|
577
|
+
]);
|
|
578
|
+
return executed.pipe(Effect.catch((error) => isAtomicUniqueViolation(error)
|
|
579
|
+
? Effect.succeed(undefined)
|
|
580
|
+
: Effect.fail(accessGrantStoreError("supersede", "Failed to supersede access grant", error))), Effect.map((results) => results !== undefined &&
|
|
581
|
+
results[0].length === 1 &&
|
|
582
|
+
results[1].length === 1
|
|
583
|
+
? Option.some({ previous, replacement })
|
|
584
|
+
: Option.none()));
|
|
585
|
+
}));
|
|
586
|
+
})))),
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
export const makeEffectQbSqliteDelegatedAccessStorage = (executor, atomic, options = {}) => ({
|
|
590
|
+
invitationStore: makeEffectQbSqliteInvitationStore(executor, atomic, options),
|
|
591
|
+
accessGrantStore: makeEffectQbSqliteAccessGrantStore(executor, atomic, options),
|
|
592
|
+
});
|
|
593
|
+
export const EffectQbSqliteDelegatedAccessStorageLive = (executor, atomic, options = {}) => Layer.merge(Layer.succeed(InvitationStore)(makeEffectQbSqliteInvitationStore(executor, atomic, options)), Layer.succeed(AccessGrantStore)(makeEffectQbSqliteAccessGrantStore(executor, atomic, options)));
|
|
594
|
+
export const EffectQbSqliteInvitationStoreLive = (executor, atomic, options = {}) => Layer.succeed(InvitationStore)(makeEffectQbSqliteInvitationStore(executor, atomic, options));
|
|
595
|
+
export const EffectQbSqliteAccessGrantStoreLive = (executor, atomic, options = {}) => Layer.succeed(AccessGrantStore)(makeEffectQbSqliteAccessGrantStore(executor, atomic, options));
|
|
596
|
+
export const makeEffectQbSqliteDelegatedAccessStores = makeEffectQbSqliteDelegatedAccessStorage;
|
|
597
|
+
export const EffectQbSqliteDelegatedAccessStoresLive = EffectQbSqliteDelegatedAccessStorageLive;
|
|
598
|
+
export const makeD1EffectQbSqliteDelegatedAccessStorage = (database, options = {}) => makeEffectQbSqliteDelegatedAccessStorage(makeD1EffectQbSqliteExecutor(database), makeD1EffectQbSqliteAtomicPlanExecutor(database), options);
|
|
599
|
+
export const D1EffectQbSqliteDelegatedAccessStorageLive = (database, options = {}) => EffectQbSqliteDelegatedAccessStorageLive(makeD1EffectQbSqliteExecutor(database), makeD1EffectQbSqliteAtomicPlanExecutor(database), options);
|
|
600
|
+
export const makeD1EffectQbSqliteDelegatedAccessStores = makeD1EffectQbSqliteDelegatedAccessStorage;
|
|
601
|
+
export const D1EffectQbSqliteDelegatedAccessStoresLive = D1EffectQbSqliteDelegatedAccessStorageLive;
|
|
602
|
+
//# sourceMappingURL=EffectQbSqliteDelegatedAccessStorage.js.map
|