@yielded/auth 0.1.0-beta.1
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 +18 -0
- package/dist/Atom.d.mts +5 -0
- package/dist/Atom.mjs +5 -0
- package/dist/Auth.d.mts +9 -0
- package/dist/Auth.mjs +7 -0
- package/dist/AuthContract.d.mts +4 -0
- package/dist/AuthContract.mjs +4 -0
- package/dist/AuthSession.d.mts +82 -0
- package/dist/AuthSession.mjs +138 -0
- package/dist/AuthSession.mjs.map +1 -0
- package/dist/AuthStore.d.mts +68 -0
- package/dist/AuthStore.mjs +194 -0
- package/dist/AuthStore.mjs.map +1 -0
- package/dist/AuthTokenCodec.d.mts +40 -0
- package/dist/AuthTokenCodec.mjs +104 -0
- package/dist/AuthTokenCodec.mjs.map +1 -0
- package/dist/Client.d.mts +2 -0
- package/dist/Client.mjs +2 -0
- package/dist/Cloudflare.d.mts +89 -0
- package/dist/Cloudflare.mjs +166 -0
- package/dist/Cloudflare.mjs.map +1 -0
- package/dist/Drizzle.d.mts +28 -0
- package/dist/Drizzle.mjs +27 -0
- package/dist/DrizzleD1.d.mts +935 -0
- package/dist/DrizzleD1.mjs +29 -0
- package/dist/DrizzleD1.mjs.map +1 -0
- package/dist/DrizzleLibsql.d.mts +2288 -0
- package/dist/DrizzleLibsql.mjs +85 -0
- package/dist/DrizzleLibsql.mjs.map +1 -0
- package/dist/DrizzleMysql2.d.mts +1809 -0
- package/dist/DrizzleMysql2.mjs +55 -0
- package/dist/DrizzleMysql2.mjs.map +1 -0
- package/dist/DrizzlePglite.d.mts +1808 -0
- package/dist/DrizzlePglite.mjs +45 -0
- package/dist/DrizzlePglite.mjs.map +1 -0
- package/dist/DrizzlePostgres.d.mts +1808 -0
- package/dist/DrizzlePostgres.mjs +45 -0
- package/dist/DrizzlePostgres.mjs.map +1 -0
- package/dist/DrizzleSqliteBun.d.mts +2287 -0
- package/dist/DrizzleSqliteBun.mjs +62 -0
- package/dist/DrizzleSqliteBun.mjs.map +1 -0
- package/dist/DrizzleSqliteDo.d.mts +2343 -0
- package/dist/DrizzleSqliteDo.mjs +105 -0
- package/dist/DrizzleSqliteDo.mjs.map +1 -0
- package/dist/DrizzleSqliteNode.d.mts +2287 -0
- package/dist/DrizzleSqliteNode.mjs +62 -0
- package/dist/DrizzleSqliteNode.mjs.map +1 -0
- package/dist/DrizzleSqliteWasm.d.mts +2287 -0
- package/dist/DrizzleSqliteWasm.mjs +62 -0
- package/dist/DrizzleSqliteWasm.mjs.map +1 -0
- package/dist/Email.d.mts +12 -0
- package/dist/Email.mjs +11 -0
- package/dist/EmailOtp.d.mts +42 -0
- package/dist/EmailOtp.mjs +120 -0
- package/dist/EmailOtp.mjs.map +1 -0
- package/dist/EmailOtpSender.d.mts +22 -0
- package/dist/EmailOtpSender.mjs +18 -0
- package/dist/EmailOtpSender.mjs.map +1 -0
- package/dist/Errors.d.mts +55 -0
- package/dist/Errors.mjs +31 -0
- package/dist/Errors.mjs.map +1 -0
- package/dist/GitHub.d.mts +5 -0
- package/dist/GitHub.mjs +4 -0
- package/dist/Hooks.d.mts +6 -0
- package/dist/Hooks.mjs +6 -0
- package/dist/Http.d.mts +12 -0
- package/dist/Http.mjs +12 -0
- package/dist/HttpServer.d.mts +103 -0
- package/dist/HttpServer.mjs +326 -0
- package/dist/HttpServer.mjs.map +1 -0
- package/dist/Identity.d.mts +9 -0
- package/dist/Identity.mjs +9 -0
- package/dist/IdentityResolver.d.mts +16 -0
- package/dist/IdentityResolver.mjs +12 -0
- package/dist/IdentityResolver.mjs.map +1 -0
- package/dist/OAuth.d.mts +36 -0
- package/dist/OAuth.mjs +35 -0
- package/dist/OpenIdClient.d.mts +3 -0
- package/dist/OpenIdClient.mjs +3 -0
- package/dist/OpenIdClientConnected.d.mts +4 -0
- package/dist/OpenIdClientConnected.mjs +3 -0
- package/dist/OperationHttp.d.mts +3 -0
- package/dist/OperationHttp.mjs +3 -0
- package/dist/OperationHttpClient.d.mts +2 -0
- package/dist/OperationHttpClient.mjs +2 -0
- package/dist/OperationHttpServer.d.mts +5 -0
- package/dist/OperationHttpServer.mjs +4 -0
- package/dist/Operations.d.mts +8 -0
- package/dist/Operations.mjs +8 -0
- package/dist/Passkey.d.mts +12 -0
- package/dist/Passkey.mjs +12 -0
- package/dist/PasskeyBrowser.d.mts +4 -0
- package/dist/PasskeyBrowser.mjs +4 -0
- package/dist/PasskeyContract.d.mts +641 -0
- package/dist/PasskeyContract.mjs +174 -0
- package/dist/PasskeyContract.mjs.map +1 -0
- package/dist/PasskeyPassword.d.mts +412 -0
- package/dist/PasskeyPassword.mjs +174 -0
- package/dist/PasskeyPassword.mjs.map +1 -0
- package/dist/PasskeySimpleWebAuthn.d.mts +3 -0
- package/dist/PasskeySimpleWebAuthn.mjs +3 -0
- package/dist/Password.d.mts +19 -0
- package/dist/Password.mjs +17 -0
- package/dist/PasswordAuth.d.mts +45 -0
- package/dist/PasswordAuth.mjs +79 -0
- package/dist/PasswordAuth.mjs.map +1 -0
- package/dist/PasswordCredentialStore.d.mts +46 -0
- package/dist/PasswordCredentialStore.mjs +62 -0
- package/dist/PasswordCredentialStore.mjs.map +1 -0
- package/dist/PasswordHasher.d.mts +31 -0
- package/dist/PasswordHasher.mjs +76 -0
- package/dist/PasswordHasher.mjs.map +1 -0
- package/dist/PhoneOtp.d.mts +11 -0
- package/dist/PhoneOtp.mjs +11 -0
- package/dist/Policy.d.mts +52 -0
- package/dist/Policy.mjs +36 -0
- package/dist/Policy.mjs.map +1 -0
- package/dist/Proofs.d.mts +14 -0
- package/dist/Proofs.mjs +13 -0
- package/dist/Rpc.d.mts +12 -0
- package/dist/Rpc.mjs +11 -0
- package/dist/Rpc.mjs.map +1 -0
- package/dist/Schema.d.mts +160 -0
- package/dist/Schema.mjs +141 -0
- package/dist/Schema.mjs.map +1 -0
- package/dist/SessionContract.d.mts +3 -0
- package/dist/SessionContract.mjs +3 -0
- package/dist/Sessions.d.mts +14 -0
- package/dist/Sessions.mjs +12 -0
- package/dist/Testing.d.mts +7 -0
- package/dist/Testing.mjs +7 -0
- package/dist/Totp.d.mts +8 -0
- package/dist/Totp.mjs +8 -0
- package/dist/TotpContract.d.mts +318 -0
- package/dist/TotpContract.mjs +119 -0
- package/dist/TotpContract.mjs.map +1 -0
- package/dist/WebCrypto.d.mts +28 -0
- package/dist/WebCrypto.mjs +42 -0
- package/dist/WebCrypto.mjs.map +1 -0
- package/dist/Workflows.d.mts +16 -0
- package/dist/Workflows.mjs +11 -0
- package/dist/Workflows.mjs.map +1 -0
- package/dist/atom/AuthAtomLifetime.d.mts +35 -0
- package/dist/atom/AuthAtomLifetime.mjs +50 -0
- package/dist/atom/AuthAtomLifetime.mjs.map +1 -0
- package/dist/atom/AuthAtomWorkflow.d.mts +17 -0
- package/dist/atom/AuthAtomWorkflow.mjs +9 -0
- package/dist/atom/AuthAtomWorkflow.mjs.map +1 -0
- package/dist/atom/client.d.mts +43 -0
- package/dist/atom/client.mjs +168 -0
- package/dist/atom/client.mjs.map +1 -0
- package/dist/atom/operations.d.mts +35 -0
- package/dist/atom/operations.mjs +58 -0
- package/dist/atom/operations.mjs.map +1 -0
- package/dist/atom/scoped-runtime.mjs +151 -0
- package/dist/atom/scoped-runtime.mjs.map +1 -0
- package/dist/auth/Auth.d.mts +7806 -0
- package/dist/auth/Auth.mjs +141 -0
- package/dist/auth/Auth.mjs.map +1 -0
- package/dist/auth/AuthConfigurationError.d.mts +10 -0
- package/dist/auth/AuthConfigurationError.mjs +14 -0
- package/dist/auth/AuthConfigurationError.mjs.map +1 -0
- package/dist/auth/AuthRequest.d.mts +21 -0
- package/dist/auth/AuthRequest.mjs +10 -0
- package/dist/auth/AuthRequest.mjs.map +1 -0
- package/dist/auth/AuthStrategy.d.mts +23 -0
- package/dist/auth/AuthStrategy.mjs +33 -0
- package/dist/auth/AuthStrategy.mjs.map +1 -0
- package/dist/auth/ConsumeDecision.d.mts +11 -0
- package/dist/auth/actions.d.mts +18 -0
- package/dist/auth/actions.mjs +70 -0
- package/dist/auth/actions.mjs.map +1 -0
- package/dist/auth/defaults.mjs +12 -0
- package/dist/auth/defaults.mjs.map +1 -0
- package/dist/auth/definition.d.mts +46 -0
- package/dist/auth/session.d.mts +27 -0
- package/dist/auth/session.mjs +56 -0
- package/dist/auth/session.mjs.map +1 -0
- package/dist/drizzle/D1BatchStatements.d.mts +11 -0
- package/dist/drizzle/D1BatchStatements.mjs +8 -0
- package/dist/drizzle/D1BatchStatements.mjs.map +1 -0
- package/dist/drizzle/PasswordPreparedPostconditions.mjs +12 -0
- package/dist/drizzle/PasswordPreparedPostconditions.mjs.map +1 -0
- package/dist/drizzle/SuppliedService.d.mts +10 -0
- package/dist/drizzle/d1-emails.d.mts +68 -0
- package/dist/drizzle/d1-emails.mjs +580 -0
- package/dist/drizzle/d1-emails.mjs.map +1 -0
- package/dist/drizzle/d1-generated-statement.mjs +79 -0
- package/dist/drizzle/d1-generated-statement.mjs.map +1 -0
- package/dist/drizzle/d1-identity.d.mts +33 -0
- package/dist/drizzle/d1-identity.mjs +120 -0
- package/dist/drizzle/d1-identity.mjs.map +1 -0
- package/dist/drizzle/d1-oauth.d.mts +316 -0
- package/dist/drizzle/d1-oauth.mjs +79 -0
- package/dist/drizzle/d1-oauth.mjs.map +1 -0
- package/dist/drizzle/d1-passkey.d.mts +52 -0
- package/dist/drizzle/d1-passkey.mjs +97 -0
- package/dist/drizzle/d1-passkey.mjs.map +1 -0
- package/dist/drizzle/d1-password-prepared.d.mts +27 -0
- package/dist/drizzle/d1-password-prepared.mjs +464 -0
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -0
- package/dist/drizzle/d1-passwords.d.mts +96 -0
- package/dist/drizzle/d1-passwords.mjs +1008 -0
- package/dist/drizzle/d1-passwords.mjs.map +1 -0
- package/dist/drizzle/d1-phone.d.mts +29 -0
- package/dist/drizzle/d1-phone.mjs +33 -0
- package/dist/drizzle/d1-phone.mjs.map +1 -0
- package/dist/drizzle/d1-planning.d.mts +12 -0
- package/dist/drizzle/d1-planning.mjs +43 -0
- package/dist/drizzle/d1-planning.mjs.map +1 -0
- package/dist/drizzle/d1-proofs.d.mts +88 -0
- package/dist/drizzle/d1-proofs.mjs +833 -0
- package/dist/drizzle/d1-proofs.mjs.map +1 -0
- package/dist/drizzle/d1-sessions.d.mts +77 -0
- package/dist/drizzle/d1-sessions.mjs +970 -0
- package/dist/drizzle/d1-sessions.mjs.map +1 -0
- package/dist/drizzle/d1-totp.d.mts +27 -0
- package/dist/drizzle/d1-totp.mjs +28 -0
- package/dist/drizzle/d1-totp.mjs.map +1 -0
- package/dist/drizzle/email-model.d.mts +352 -0
- package/dist/drizzle/email-model.mjs +21 -0
- package/dist/drizzle/email-model.mjs.map +1 -0
- package/dist/drizzle/email-registration.d.mts +33 -0
- package/dist/drizzle/email-registration.mjs +238 -0
- package/dist/drizzle/email-registration.mjs.map +1 -0
- package/dist/drizzle/email-sql.d.mts +18 -0
- package/dist/drizzle/email-sql.mjs +473 -0
- package/dist/drizzle/email-sql.mjs.map +1 -0
- package/dist/drizzle/email-target.d.mts +28 -0
- package/dist/drizzle/email-target.mjs +75 -0
- package/dist/drizzle/email-target.mjs.map +1 -0
- package/dist/drizzle/model.d.mts +259 -0
- package/dist/drizzle/model.mjs +81 -0
- package/dist/drizzle/model.mjs.map +1 -0
- package/dist/drizzle/mysql-emails.d.mts +82 -0
- package/dist/drizzle/mysql-emails.mjs +38 -0
- package/dist/drizzle/mysql-emails.mjs.map +1 -0
- package/dist/drizzle/mysql-identity.d.mts +24 -0
- package/dist/drizzle/mysql-identity.mjs +95 -0
- package/dist/drizzle/mysql-identity.mjs.map +1 -0
- package/dist/drizzle/mysql-password-prepared.d.mts +32 -0
- package/dist/drizzle/mysql-password-prepared.mjs +16 -0
- package/dist/drizzle/mysql-password-prepared.mjs.map +1 -0
- package/dist/drizzle/mysql-passwords.d.mts +102 -0
- package/dist/drizzle/mysql-passwords.mjs +38 -0
- package/dist/drizzle/mysql-passwords.mjs.map +1 -0
- package/dist/drizzle/mysql-proofs.d.mts +83 -0
- package/dist/drizzle/mysql-proofs.mjs +23 -0
- package/dist/drizzle/mysql-proofs.mjs.map +1 -0
- package/dist/drizzle/mysql-sessions.d.mts +250 -0
- package/dist/drizzle/mysql-sessions.mjs +53 -0
- package/dist/drizzle/mysql-sessions.mjs.map +1 -0
- package/dist/drizzle/mysql.d.mts +73 -0
- package/dist/drizzle/mysql.mjs +221 -0
- package/dist/drizzle/mysql.mjs.map +1 -0
- package/dist/drizzle/oauth-accounts.mjs +361 -0
- package/dist/drizzle/oauth-accounts.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-access.mjs +210 -0
- package/dist/drizzle/oauth-connected-access.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-collection.mjs +202 -0
- package/dist/drizzle/oauth-connected-collection.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-custody.mjs +146 -0
- package/dist/drizzle/oauth-connected-custody.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-drivers.mjs +78 -0
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-flow.mjs +248 -0
- package/dist/drizzle/oauth-connected-flow.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-input.mjs +105 -0
- package/dist/drizzle/oauth-connected-input.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-maintenance.mjs +215 -0
- package/dist/drizzle/oauth-connected-maintenance.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-management.mjs +228 -0
- package/dist/drizzle/oauth-connected-management.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-model.d.mts +278 -0
- package/dist/drizzle/oauth-connected-model.mjs +22 -0
- package/dist/drizzle/oauth-connected-model.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-reference.d.mts +17 -0
- package/dist/drizzle/oauth-connected-reference.mjs +53 -0
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-settlement.mjs +117 -0
- package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-state.d.mts +16 -0
- package/dist/drizzle/oauth-connected-state.mjs +422 -0
- package/dist/drizzle/oauth-connected-state.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-target.d.mts +114 -0
- package/dist/drizzle/oauth-connected-target.mjs +94 -0
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -0
- package/dist/drizzle/oauth-drivers.mjs +53 -0
- package/dist/drizzle/oauth-drivers.mjs.map +1 -0
- package/dist/drizzle/oauth-flow.d.mts +7 -0
- package/dist/drizzle/oauth-flow.mjs +255 -0
- package/dist/drizzle/oauth-flow.mjs.map +1 -0
- package/dist/drizzle/oauth-input.mjs +130 -0
- package/dist/drizzle/oauth-input.mjs.map +1 -0
- package/dist/drizzle/oauth-model.d.mts +468 -0
- package/dist/drizzle/oauth-model.mjs +49 -0
- package/dist/drizzle/oauth-model.mjs.map +1 -0
- package/dist/drizzle/oauth-mysql.mjs +8 -0
- package/dist/drizzle/oauth-mysql.mjs.map +1 -0
- package/dist/drizzle/oauth-owner.d.mts +4 -0
- package/dist/drizzle/oauth-owner.mjs +10 -0
- package/dist/drizzle/oauth-owner.mjs.map +1 -0
- package/dist/drizzle/oauth-registration.d.mts +8 -0
- package/dist/drizzle/oauth-registration.mjs +375 -0
- package/dist/drizzle/oauth-registration.mjs.map +1 -0
- package/dist/drizzle/oauth-state.mjs +109 -0
- package/dist/drizzle/oauth-state.mjs.map +1 -0
- package/dist/drizzle/oauth-target.d.mts +125 -0
- package/dist/drizzle/oauth-target.mjs +252 -0
- package/dist/drizzle/oauth-target.mjs.map +1 -0
- package/dist/drizzle/passkey-admission.mjs +203 -0
- package/dist/drizzle/passkey-admission.mjs.map +1 -0
- package/dist/drizzle/passkey-credentials.mjs +239 -0
- package/dist/drizzle/passkey-credentials.mjs.map +1 -0
- package/dist/drizzle/passkey-drivers.mjs +34 -0
- package/dist/drizzle/passkey-drivers.mjs.map +1 -0
- package/dist/drizzle/passkey-enrollment.mjs +132 -0
- package/dist/drizzle/passkey-enrollment.mjs.map +1 -0
- package/dist/drizzle/passkey-flow.mjs +436 -0
- package/dist/drizzle/passkey-flow.mjs.map +1 -0
- package/dist/drizzle/passkey-management.mjs +225 -0
- package/dist/drizzle/passkey-management.mjs.map +1 -0
- package/dist/drizzle/passkey-model.d.mts +275 -0
- package/dist/drizzle/passkey-model.mjs +36 -0
- package/dist/drizzle/passkey-model.mjs.map +1 -0
- package/dist/drizzle/passkey-registration-ceremony-model.d.mts +50 -0
- package/dist/drizzle/passkey-registration-ceremony-model.mjs +18 -0
- package/dist/drizzle/passkey-registration-ceremony-model.mjs.map +1 -0
- package/dist/drizzle/passkey-registration-ceremony.mjs +124 -0
- package/dist/drizzle/passkey-registration-ceremony.mjs.map +1 -0
- package/dist/drizzle/passkey-registration-custody.mjs +51 -0
- package/dist/drizzle/passkey-registration-custody.mjs.map +1 -0
- package/dist/drizzle/passkey-registration-write.mjs +205 -0
- package/dist/drizzle/passkey-registration-write.mjs.map +1 -0
- package/dist/drizzle/passkey-state.d.mts +5 -0
- package/dist/drizzle/passkey-state.mjs +207 -0
- package/dist/drizzle/passkey-state.mjs.map +1 -0
- package/dist/drizzle/passkey-target.d.mts +16 -0
- package/dist/drizzle/passkey-target.mjs +174 -0
- package/dist/drizzle/passkey-target.mjs.map +1 -0
- package/dist/drizzle/passkey-write-drivers.mjs +33 -0
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -0
- package/dist/drizzle/passkey-write-model.d.mts +192 -0
- package/dist/drizzle/passkey-write-model.mjs +13 -0
- package/dist/drizzle/passkey-write-model.mjs.map +1 -0
- package/dist/drizzle/passkey-write-state.mjs +326 -0
- package/dist/drizzle/passkey-write-state.mjs.map +1 -0
- package/dist/drizzle/passkey-write-target.d.mts +14 -0
- package/dist/drizzle/passkey-write-target.mjs +185 -0
- package/dist/drizzle/passkey-write-target.mjs.map +1 -0
- package/dist/drizzle/password-model.d.mts +330 -0
- package/dist/drizzle/password-model.mjs +22 -0
- package/dist/drizzle/password-model.mjs.map +1 -0
- package/dist/drizzle/password-prepared-model.d.mts +93 -0
- package/dist/drizzle/password-prepared-model.mjs +11 -0
- package/dist/drizzle/password-prepared-model.mjs.map +1 -0
- package/dist/drizzle/password-prepared-sql.mjs +394 -0
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -0
- package/dist/drizzle/password-prepared-state.mjs +107 -0
- package/dist/drizzle/password-prepared-state.mjs.map +1 -0
- package/dist/drizzle/password-prepared-target.d.mts +12 -0
- package/dist/drizzle/password-prepared-target.mjs +57 -0
- package/dist/drizzle/password-prepared-target.mjs.map +1 -0
- package/dist/drizzle/password-registration.d.mts +23 -0
- package/dist/drizzle/password-registration.mjs +136 -0
- package/dist/drizzle/password-registration.mjs.map +1 -0
- package/dist/drizzle/password-sql.d.mts +20 -0
- package/dist/drizzle/password-sql.mjs +702 -0
- package/dist/drizzle/password-sql.mjs.map +1 -0
- package/dist/drizzle/password-target.d.mts +25 -0
- package/dist/drizzle/password-target.mjs +63 -0
- package/dist/drizzle/password-target.mjs.map +1 -0
- package/dist/drizzle/pg-emails.d.mts +83 -0
- package/dist/drizzle/pg-emails.mjs +38 -0
- package/dist/drizzle/pg-emails.mjs.map +1 -0
- package/dist/drizzle/pg-password-prepared.d.mts +33 -0
- package/dist/drizzle/pg-password-prepared.mjs +16 -0
- package/dist/drizzle/pg-password-prepared.mjs.map +1 -0
- package/dist/drizzle/pg-passwords.d.mts +103 -0
- package/dist/drizzle/pg-passwords.mjs +38 -0
- package/dist/drizzle/pg-passwords.mjs.map +1 -0
- package/dist/drizzle/pg-proofs.d.mts +84 -0
- package/dist/drizzle/pg-proofs.mjs +22 -0
- package/dist/drizzle/pg-proofs.mjs.map +1 -0
- package/dist/drizzle/pg-sessions.d.mts +251 -0
- package/dist/drizzle/pg-sessions.mjs +53 -0
- package/dist/drizzle/pg-sessions.mjs.map +1 -0
- package/dist/drizzle/pg.d.mts +88 -0
- package/dist/drizzle/pg.mjs +294 -0
- package/dist/drizzle/pg.mjs.map +1 -0
- package/dist/drizzle/phone-model.d.mts +117 -0
- package/dist/drizzle/phone-model.mjs +39 -0
- package/dist/drizzle/phone-model.mjs.map +1 -0
- package/dist/drizzle/phone-state.mjs +426 -0
- package/dist/drizzle/phone-state.mjs.map +1 -0
- package/dist/drizzle/phone-target.d.mts +19 -0
- package/dist/drizzle/phone-target.mjs +171 -0
- package/dist/drizzle/phone-target.mjs.map +1 -0
- package/dist/drizzle/proof-model.d.mts +287 -0
- package/dist/drizzle/proof-model.mjs +17 -0
- package/dist/drizzle/proof-model.mjs.map +1 -0
- package/dist/drizzle/proof-sql.d.mts +16 -0
- package/dist/drizzle/proof-sql.mjs +618 -0
- package/dist/drizzle/proof-sql.mjs.map +1 -0
- package/dist/drizzle/proof-target.d.mts +17 -0
- package/dist/drizzle/proof-target.mjs +38 -0
- package/dist/drizzle/proof-target.mjs.map +1 -0
- package/dist/drizzle/session-model.d.mts +201 -0
- package/dist/drizzle/session-model.mjs +19 -0
- package/dist/drizzle/session-model.mjs.map +1 -0
- package/dist/drizzle/session-sql.mjs +732 -0
- package/dist/drizzle/session-sql.mjs.map +1 -0
- package/dist/drizzle/session-target.d.mts +37 -0
- package/dist/drizzle/session-target.mjs +47 -0
- package/dist/drizzle/session-target.mjs.map +1 -0
- package/dist/drizzle/sqlite-emails.mjs +45 -0
- package/dist/drizzle/sqlite-emails.mjs.map +1 -0
- package/dist/drizzle/sqlite-identity.mjs +92 -0
- package/dist/drizzle/sqlite-identity.mjs.map +1 -0
- package/dist/drizzle/sqlite-password-prepared.mjs +21 -0
- package/dist/drizzle/sqlite-password-prepared.mjs.map +1 -0
- package/dist/drizzle/sqlite-passwords.mjs +49 -0
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -0
- package/dist/drizzle/sqlite-proofs.mjs +29 -0
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -0
- package/dist/drizzle/sqlite-sessions.mjs +74 -0
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -0
- package/dist/drizzle/sqlite.d.mts +81 -0
- package/dist/drizzle/sqlite.mjs +220 -0
- package/dist/drizzle/sqlite.mjs.map +1 -0
- package/dist/drizzle/standalone-guard.mjs +19 -0
- package/dist/drizzle/standalone-guard.mjs.map +1 -0
- package/dist/drizzle/step-up-model.d.mts +65 -0
- package/dist/drizzle/step-up-model.mjs +9 -0
- package/dist/drizzle/step-up-model.mjs.map +1 -0
- package/dist/drizzle/step-up-state.mjs +34 -0
- package/dist/drizzle/step-up-state.mjs.map +1 -0
- package/dist/drizzle/totp-model.d.mts +85 -0
- package/dist/drizzle/totp-model.mjs +13 -0
- package/dist/drizzle/totp-model.mjs.map +1 -0
- package/dist/drizzle/totp-state.d.mts +39 -0
- package/dist/drizzle/totp-state.mjs +288 -0
- package/dist/drizzle/totp-state.mjs.map +1 -0
- package/dist/drizzle/totp-target.d.mts +16 -0
- package/dist/drizzle/totp-target.mjs +83 -0
- package/dist/drizzle/totp-target.mjs.map +1 -0
- package/dist/drizzle/transaction-execution.d.mts +20 -0
- package/dist/drizzle/transaction-execution.mjs +111 -0
- package/dist/drizzle/transaction-execution.mjs.map +1 -0
- package/dist/drizzle/transaction-mysql.mjs +46 -0
- package/dist/drizzle/transaction-mysql.mjs.map +1 -0
- package/dist/drizzle/transaction-owner.d.mts +6 -0
- package/dist/drizzle/transaction-owner.mjs +252 -0
- package/dist/drizzle/transaction-owner.mjs.map +1 -0
- package/dist/email/EmailActionEvidence.d.mts +33 -0
- package/dist/email/EmailActionEvidence.mjs +15 -0
- package/dist/email/EmailActionEvidence.mjs.map +1 -0
- package/dist/email/EmailAddressPersistence.d.mts +63 -0
- package/dist/email/EmailAddressPersistence.mjs +19 -0
- package/dist/email/EmailAddressPersistence.mjs.map +1 -0
- package/dist/email/EmailIdentifierNotifier.d.mts +30 -0
- package/dist/email/EmailIdentifierNotifier.mjs +31 -0
- package/dist/email/EmailIdentifierNotifier.mjs.map +1 -0
- package/dist/email/EmailReturnTargets.d.mts +19 -0
- package/dist/email/EmailReturnTargets.mjs +29 -0
- package/dist/email/EmailReturnTargets.mjs.map +1 -0
- package/dist/email/EmailSignInTargets.d.mts +20 -0
- package/dist/email/EmailSignInTargets.mjs +12 -0
- package/dist/email/EmailSignInTargets.mjs.map +1 -0
- package/dist/email/addresses.d.mts +33 -0
- package/dist/email/addresses.mjs +404 -0
- package/dist/email/addresses.mjs.map +1 -0
- package/dist/email/definition.d.mts +10153 -0
- package/dist/email/definition.mjs +111 -0
- package/dist/email/definition.mjs.map +1 -0
- package/dist/email/errors.d.mts +15 -0
- package/dist/email/errors.mjs +11 -0
- package/dist/email/errors.mjs.map +1 -0
- package/dist/email/magicLink.d.mts +33 -0
- package/dist/email/magicLink.mjs +58 -0
- package/dist/email/magicLink.mjs.map +1 -0
- package/dist/email/models.d.mts +56 -0
- package/dist/email/models.mjs +31 -0
- package/dist/email/models.mjs.map +1 -0
- package/dist/email/module.d.mts +22296 -0
- package/dist/email/module.mjs +415 -0
- package/dist/email/module.mjs.map +1 -0
- package/dist/email/registration.d.mts +28 -0
- package/dist/email/registration.mjs +243 -0
- package/dist/email/registration.mjs.map +1 -0
- package/dist/email/snapshot.mjs +37 -0
- package/dist/email/snapshot.mjs.map +1 -0
- package/dist/hooks/LifecycleHooks.d.mts +34 -0
- package/dist/hooks/LifecycleHooks.mjs +74 -0
- package/dist/hooks/LifecycleHooks.mjs.map +1 -0
- package/dist/hooks/commit.d.mts +66 -0
- package/dist/hooks/commit.mjs +136 -0
- package/dist/hooks/commit.mjs.map +1 -0
- package/dist/hooks/models.d.mts +51 -0
- package/dist/hooks/models.mjs +87 -0
- package/dist/hooks/models.mjs.map +1 -0
- package/dist/hooks/plugins.d.mts +36 -0
- package/dist/hooks/plugins.mjs +60 -0
- package/dist/hooks/plugins.mjs.map +1 -0
- package/dist/hooks/transactions.d.mts +31 -0
- package/dist/hooks/transactions.mjs +38 -0
- package/dist/hooks/transactions.mjs.map +1 -0
- package/dist/http/auth-api.d.mts +9 -0
- package/dist/http/auth-api.mjs +13 -0
- package/dist/http/auth-api.mjs.map +1 -0
- package/dist/http/auth-contract.d.mts +84 -0
- package/dist/http/auth-contract.mjs +75 -0
- package/dist/http/auth-contract.mjs.map +1 -0
- package/dist/http/auth-http.d.mts +216 -0
- package/dist/http/auth-http.mjs +184 -0
- package/dist/http/auth-http.mjs.map +1 -0
- package/dist/http/endpoints/get-session.d.mts +8 -0
- package/dist/http/endpoints/get-session.mjs +12 -0
- package/dist/http/endpoints/get-session.mjs.map +1 -0
- package/dist/http/endpoints/password-sign-in.d.mts +8 -0
- package/dist/http/endpoints/password-sign-in.mjs +18 -0
- package/dist/http/endpoints/password-sign-in.mjs.map +1 -0
- package/dist/http/endpoints/request-email-otp.d.mts +8 -0
- package/dist/http/endpoints/request-email-otp.mjs +17 -0
- package/dist/http/endpoints/request-email-otp.mjs.map +1 -0
- package/dist/http/endpoints/set-password.d.mts +9 -0
- package/dist/http/endpoints/set-password.mjs +19 -0
- package/dist/http/endpoints/set-password.mjs.map +1 -0
- package/dist/http/endpoints/sign-out.d.mts +6 -0
- package/dist/http/endpoints/sign-out.mjs +7 -0
- package/dist/http/endpoints/sign-out.mjs.map +1 -0
- package/dist/http/endpoints/verify-email-otp.d.mts +9 -0
- package/dist/http/endpoints/verify-email-otp.mjs +18 -0
- package/dist/http/endpoints/verify-email-otp.mjs.map +1 -0
- package/dist/http/models.d.mts +49 -0
- package/dist/http/models.mjs +35 -0
- package/dist/http/models.mjs.map +1 -0
- package/dist/http/security.d.mts +91 -0
- package/dist/http/security.mjs +77 -0
- package/dist/http/security.mjs.map +1 -0
- package/dist/http/session-contract.d.mts +303 -0
- package/dist/http/session-contract.mjs +38 -0
- package/dist/http/session-contract.mjs.map +1 -0
- package/dist/http-operation/OperationHttpInvocation.d.mts +16 -0
- package/dist/http-operation/OperationHttpInvocation.mjs +11 -0
- package/dist/http-operation/OperationHttpInvocation.mjs.map +1 -0
- package/dist/http-operation/OperationHttpServerConfig.d.mts +18 -0
- package/dist/http-operation/OperationHttpServerConfig.mjs +72 -0
- package/dist/http-operation/OperationHttpServerConfig.mjs.map +1 -0
- package/dist/http-operation/auth-client.d.mts +75 -0
- package/dist/http-operation/auth-client.mjs +116 -0
- package/dist/http-operation/auth-client.mjs.map +1 -0
- package/dist/http-operation/client.d.mts +50 -0
- package/dist/http-operation/client.mjs +188 -0
- package/dist/http-operation/client.mjs.map +1 -0
- package/dist/http-operation/configuration-schema.mjs +19 -0
- package/dist/http-operation/configuration-schema.mjs.map +1 -0
- package/dist/http-operation/contract.d.mts +40 -0
- package/dist/http-operation/contract.mjs +37 -0
- package/dist/http-operation/contract.mjs.map +1 -0
- package/dist/http-operation/errors.d.mts +13 -0
- package/dist/http-operation/errors.mjs +31 -0
- package/dist/http-operation/errors.mjs.map +1 -0
- package/dist/http-operation/models.d.mts +32 -0
- package/dist/http-operation/models.mjs +14 -0
- package/dist/http-operation/models.mjs.map +1 -0
- package/dist/http-operation/private.mjs +35 -0
- package/dist/http-operation/private.mjs.map +1 -0
- package/dist/http-operation/security.mjs +58 -0
- package/dist/http-operation/security.mjs.map +1 -0
- package/dist/http-operation/server.d.mts +33 -0
- package/dist/http-operation/server.mjs +268 -0
- package/dist/http-operation/server.mjs.map +1 -0
- package/dist/identity/ExternalIdentityMutation.d.mts +15 -0
- package/dist/identity/ExternalIdentityMutation.mjs +11 -0
- package/dist/identity/ExternalIdentityMutation.mjs.map +1 -0
- package/dist/identity/IdentityMutation.d.mts +22 -0
- package/dist/identity/IdentityMutation.mjs +17 -0
- package/dist/identity/IdentityMutation.mjs.map +1 -0
- package/dist/identity/IdentityRepository.d.mts +20 -0
- package/dist/identity/IdentityRepository.mjs +11 -0
- package/dist/identity/IdentityRepository.mjs.map +1 -0
- package/dist/identity/SubjectLifecycle.d.mts +58 -0
- package/dist/identity/SubjectLifecycle.mjs +43 -0
- package/dist/identity/SubjectLifecycle.mjs.map +1 -0
- package/dist/identity/SubjectProvisioner.d.mts +37 -0
- package/dist/identity/SubjectProvisioner.mjs +20 -0
- package/dist/identity/SubjectProvisioner.mjs.map +1 -0
- package/dist/identity/codecs.d.mts +34 -0
- package/dist/identity/codecs.mjs +40 -0
- package/dist/identity/codecs.mjs.map +1 -0
- package/dist/identity/models.d.mts +62 -0
- package/dist/identity/models.mjs +51 -0
- package/dist/identity/models.mjs.map +1 -0
- package/dist/identity/operations.d.mts +118 -0
- package/dist/identity/operations.mjs +124 -0
- package/dist/identity/operations.mjs.map +1 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.mjs +23 -0
- package/dist/internal/AuthStoreDecisions.d.mts +22 -0
- package/dist/internal/AuthStoreDecisions.mjs +8 -0
- package/dist/internal/AuthStoreDecisions.mjs.map +1 -0
- package/dist/internal/CurrentSession.d.mts +9 -0
- package/dist/internal/CurrentSession.mjs +8 -0
- package/dist/internal/CurrentSession.mjs.map +1 -0
- package/dist/internal/diagnostics.mjs +23 -0
- package/dist/internal/diagnostics.mjs.map +1 -0
- package/dist/oauth/GithubOAuthProvider.d.mts +43 -0
- package/dist/oauth/GithubOAuthProvider.mjs +66 -0
- package/dist/oauth/GithubOAuthProvider.mjs.map +1 -0
- package/dist/oauth/OAuth.d.mts +73 -0
- package/dist/oauth/OAuth.mjs +180 -0
- package/dist/oauth/OAuth.mjs.map +1 -0
- package/dist/oauth/OAuthAccountsPersistence.d.mts +109 -0
- package/dist/oauth/OAuthAccountsPersistence.mjs +12 -0
- package/dist/oauth/OAuthAccountsPersistence.mjs.map +1 -0
- package/dist/oauth/OAuthActionEvidence.d.mts +28 -0
- package/dist/oauth/OAuthActionEvidence.mjs +15 -0
- package/dist/oauth/OAuthActionEvidence.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedActionEvidence.d.mts +22 -0
- package/dist/oauth/OAuthConnectedActionEvidence.mjs +9 -0
- package/dist/oauth/OAuthConnectedActionEvidence.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedPersistence.d.mts +129 -0
- package/dist/oauth/OAuthConnectedPersistence.mjs +12 -0
- package/dist/oauth/OAuthConnectedPersistence.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedProtocol.d.mts +41 -0
- package/dist/oauth/OAuthConnectedProtocol.mjs +13 -0
- package/dist/oauth/OAuthConnectedProtocol.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedRevocations.d.mts +167 -0
- package/dist/oauth/OAuthConnectedRevocations.mjs +21 -0
- package/dist/oauth/OAuthConnectedRevocations.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedTokenProtector.d.mts +24 -0
- package/dist/oauth/OAuthConnectedTokenProtector.mjs +153 -0
- package/dist/oauth/OAuthConnectedTokenProtector.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedTransactionProtector.d.mts +23 -0
- package/dist/oauth/OAuthConnectedTransactionProtector.mjs +37 -0
- package/dist/oauth/OAuthConnectedTransactionProtector.mjs.map +1 -0
- package/dist/oauth/OAuthConnectedUseAuthority.d.mts +22 -0
- package/dist/oauth/OAuthConnectedUseAuthority.mjs +10 -0
- package/dist/oauth/OAuthConnectedUseAuthority.mjs.map +1 -0
- package/dist/oauth/OAuthConnectionStore.d.mts +33 -0
- package/dist/oauth/OAuthConnectionStore.mjs +38 -0
- package/dist/oauth/OAuthConnectionStore.mjs.map +1 -0
- package/dist/oauth/OAuthLinkTransactionProtector.d.mts +25 -0
- package/dist/oauth/OAuthLinkTransactionProtector.mjs +39 -0
- package/dist/oauth/OAuthLinkTransactionProtector.mjs.map +1 -0
- package/dist/oauth/OAuthProtocol.d.mts +33 -0
- package/dist/oauth/OAuthProtocol.mjs +16 -0
- package/dist/oauth/OAuthProtocol.mjs.map +1 -0
- package/dist/oauth/OAuthProvider.d.mts +70 -0
- package/dist/oauth/OAuthProvider.mjs +39 -0
- package/dist/oauth/OAuthProvider.mjs.map +1 -0
- package/dist/oauth/OAuthProviders.d.mts +27 -0
- package/dist/oauth/OAuthProviders.mjs +33 -0
- package/dist/oauth/OAuthProviders.mjs.map +1 -0
- package/dist/oauth/OAuthRegistrationIntents.d.mts +87 -0
- package/dist/oauth/OAuthRegistrationIntents.mjs +19 -0
- package/dist/oauth/OAuthRegistrationIntents.mjs.map +1 -0
- package/dist/oauth/OAuthReturnTargets.d.mts +15 -0
- package/dist/oauth/OAuthReturnTargets.mjs +24 -0
- package/dist/oauth/OAuthReturnTargets.mjs.map +1 -0
- package/dist/oauth/OAuthSignInPersistence.d.mts +68 -0
- package/dist/oauth/OAuthSignInPersistence.mjs +12 -0
- package/dist/oauth/OAuthSignInPersistence.mjs.map +1 -0
- package/dist/oauth/OAuthStateDecisions.d.mts +14 -0
- package/dist/oauth/OAuthStateDecisions.mjs +8 -0
- package/dist/oauth/OAuthStateDecisions.mjs.map +1 -0
- package/dist/oauth/OAuthStateStore.d.mts +35 -0
- package/dist/oauth/OAuthStateStore.mjs +64 -0
- package/dist/oauth/OAuthStateStore.mjs.map +1 -0
- package/dist/oauth/OAuthTransactionProtector.d.mts +26 -0
- package/dist/oauth/OAuthTransactionProtector.mjs +78 -0
- package/dist/oauth/OAuthTransactionProtector.mjs.map +1 -0
- package/dist/oauth/accounts.d.mts +29 -0
- package/dist/oauth/accounts.mjs +515 -0
- package/dist/oauth/accounts.mjs.map +1 -0
- package/dist/oauth/accountsModels.d.mts +463 -0
- package/dist/oauth/accountsModels.mjs +155 -0
- package/dist/oauth/accountsModels.mjs.map +1 -0
- package/dist/oauth/connected.d.mts +442 -0
- package/dist/oauth/connected.mjs +526 -0
- package/dist/oauth/connected.mjs.map +1 -0
- package/dist/oauth/connectedAccess.d.mts +20 -0
- package/dist/oauth/connectedAccess.mjs +279 -0
- package/dist/oauth/connectedAccess.mjs.map +1 -0
- package/dist/oauth/connectedMaintenance.d.mts +19 -0
- package/dist/oauth/connectedMaintenance.mjs +133 -0
- package/dist/oauth/connectedMaintenance.mjs.map +1 -0
- package/dist/oauth/connectedModels.d.mts +2023 -0
- package/dist/oauth/connectedModels.mjs +375 -0
- package/dist/oauth/connectedModels.mjs.map +1 -0
- package/dist/oauth/definition.d.mts +4396 -0
- package/dist/oauth/definition.mjs +120 -0
- package/dist/oauth/definition.mjs.map +1 -0
- package/dist/oauth/errors.d.mts +49 -0
- package/dist/oauth/errors.mjs +42 -0
- package/dist/oauth/errors.mjs.map +1 -0
- package/dist/oauth/github/identity.d.mts +8 -0
- package/dist/oauth/github/identity.mjs +24 -0
- package/dist/oauth/github/identity.mjs.map +1 -0
- package/dist/oauth/github/models.d.mts +34 -0
- package/dist/oauth/github/protocol.d.mts +54 -0
- package/dist/oauth/github/protocol.mjs +204 -0
- package/dist/oauth/github/protocol.mjs.map +1 -0
- package/dist/oauth/openid-client/ProviderRevocation.d.mts +4 -0
- package/dist/oauth/openid-client/ProviderRevocation.mjs +11 -0
- package/dist/oauth/openid-client/ProviderRevocation.mjs.map +1 -0
- package/dist/oauth/openid-client/compatibility.d.mts +1 -0
- package/dist/oauth/openid-client/compatibility.mjs +6 -0
- package/dist/oauth/openid-client/compatibility.mjs.map +1 -0
- package/dist/oauth/openid-client/configuration.mjs +305 -0
- package/dist/oauth/openid-client/configuration.mjs.map +1 -0
- package/dist/oauth/openid-client/connected/configuration.mjs +338 -0
- package/dist/oauth/openid-client/connected/configuration.mjs.map +1 -0
- package/dist/oauth/openid-client/connected/models.d.mts +42 -0
- package/dist/oauth/openid-client/connected/protocol.d.mts +16 -0
- package/dist/oauth/openid-client/connected/protocol.mjs +402 -0
- package/dist/oauth/openid-client/connected/protocol.mjs.map +1 -0
- package/dist/oauth/openid-client/models.d.mts +67 -0
- package/dist/oauth/openid-client/models.mjs +16 -0
- package/dist/oauth/openid-client/models.mjs.map +1 -0
- package/dist/oauth/openid-client/protocol.d.mts +27 -0
- package/dist/oauth/openid-client/protocol.mjs +218 -0
- package/dist/oauth/openid-client/protocol.mjs.map +1 -0
- package/dist/oauth/openid-client/transport.mjs +59 -0
- package/dist/oauth/openid-client/transport.mjs.map +1 -0
- package/dist/oauth/policy.d.mts +18 -0
- package/dist/oauth/policy.mjs +16 -0
- package/dist/oauth/policy.mjs.map +1 -0
- package/dist/oauth/registration.d.mts +24 -0
- package/dist/oauth/registration.mjs +177 -0
- package/dist/oauth/registration.mjs.map +1 -0
- package/dist/oauth/registrationModels.d.mts +152 -0
- package/dist/oauth/registrationModels.mjs +93 -0
- package/dist/oauth/registrationModels.mjs.map +1 -0
- package/dist/oauth/registrationSecrets.mjs +70 -0
- package/dist/oauth/registrationSecrets.mjs.map +1 -0
- package/dist/oauth/schema.d.mts +86 -0
- package/dist/oauth/schema.mjs +81 -0
- package/dist/oauth/schema.mjs.map +1 -0
- package/dist/oauth/signInErrors.d.mts +17 -0
- package/dist/oauth/signInErrors.mjs +16 -0
- package/dist/oauth/signInErrors.mjs.map +1 -0
- package/dist/oauth/signInModels.d.mts +343 -0
- package/dist/oauth/signInModels.mjs +181 -0
- package/dist/oauth/signInModels.mjs.map +1 -0
- package/dist/oauth/signInModule.d.mts +1546 -0
- package/dist/oauth/signInModule.mjs +430 -0
- package/dist/oauth/signInModule.mjs.map +1 -0
- package/dist/oauth/signInSnapshot.mjs +29 -0
- package/dist/oauth/signInSnapshot.mjs.map +1 -0
- package/dist/oauth/transactionEncryption.d.mts +14 -0
- package/dist/oauth/transactionEncryption.mjs +129 -0
- package/dist/oauth/transactionEncryption.mjs.map +1 -0
- package/dist/operations/RequestBindingConfig.d.mts +11 -0
- package/dist/operations/RequestBindingConfig.mjs +10 -0
- package/dist/operations/RequestBindingConfig.mjs.map +1 -0
- package/dist/operations/actions.d.mts +947 -0
- package/dist/operations/actions.mjs +148 -0
- package/dist/operations/actions.mjs.map +1 -0
- package/dist/operations/context.d.mts +63 -0
- package/dist/operations/context.mjs +55 -0
- package/dist/operations/context.mjs.map +1 -0
- package/dist/operations/credentials.d.mts +39 -0
- package/dist/operations/credentials.mjs +60 -0
- package/dist/operations/credentials.mjs.map +1 -0
- package/dist/operations/errors.d.mts +24 -0
- package/dist/operations/errors.mjs +31 -0
- package/dist/operations/errors.mjs.map +1 -0
- package/dist/operations/operation.d.mts +124 -0
- package/dist/operations/operation.mjs +220 -0
- package/dist/operations/operation.mjs.map +1 -0
- package/dist/operations/requestBinding.d.mts +46 -0
- package/dist/operations/requestBinding.mjs +130 -0
- package/dist/operations/requestBinding.mjs.map +1 -0
- package/dist/operations/requestBindingModels.d.mts +13 -0
- package/dist/operations/requestBindingModels.mjs +12 -0
- package/dist/operations/requestBindingModels.mjs.map +1 -0
- package/dist/operations/reveals.d.mts +28 -0
- package/dist/operations/reveals.mjs +88 -0
- package/dist/operations/reveals.mjs.map +1 -0
- package/dist/passkey/PasskeyActionEvidence.d.mts +22 -0
- package/dist/passkey/PasskeyActionEvidence.mjs +9 -0
- package/dist/passkey/PasskeyActionEvidence.mjs.map +1 -0
- package/dist/passkey/PasskeyCredentials.d.mts +16 -0
- package/dist/passkey/PasskeyCredentials.mjs +9 -0
- package/dist/passkey/PasskeyCredentials.mjs.map +1 -0
- package/dist/passkey/PasskeyEnrollmentContext.d.mts +22 -0
- package/dist/passkey/PasskeyEnrollmentContext.mjs +9 -0
- package/dist/passkey/PasskeyEnrollmentContext.mjs.map +1 -0
- package/dist/passkey/PasskeyManagementPersistence.d.mts +106 -0
- package/dist/passkey/PasskeyManagementPersistence.mjs +9 -0
- package/dist/passkey/PasskeyManagementPersistence.mjs.map +1 -0
- package/dist/passkey/PasskeyPersistence.d.mts +63 -0
- package/dist/passkey/PasskeyPersistence.mjs +10 -0
- package/dist/passkey/PasskeyPersistence.mjs.map +1 -0
- package/dist/passkey/PasskeyProtocol.d.mts +38 -0
- package/dist/passkey/PasskeyProtocol.mjs +11 -0
- package/dist/passkey/PasskeyProtocol.mjs.map +1 -0
- package/dist/passkey/actions.d.mts +50 -0
- package/dist/passkey/actions.mjs +376 -0
- package/dist/passkey/actions.mjs.map +1 -0
- package/dist/passkey/browser/PasskeyBrowser.d.mts +18 -0
- package/dist/passkey/browser/PasskeyBrowser.mjs +9 -0
- package/dist/passkey/browser/PasskeyBrowser.mjs.map +1 -0
- package/dist/passkey/browser/models.d.mts +38 -0
- package/dist/passkey/browser/models.mjs +41 -0
- package/dist/passkey/browser/models.mjs.map +1 -0
- package/dist/passkey/browser/simplewebauthn.d.mts +17 -0
- package/dist/passkey/browser/simplewebauthn.mjs +411 -0
- package/dist/passkey/browser/simplewebauthn.mjs.map +1 -0
- package/dist/passkey/definition.d.mts +5626 -0
- package/dist/passkey/definition.mjs +114 -0
- package/dist/passkey/definition.mjs.map +1 -0
- package/dist/passkey/errors.d.mts +20 -0
- package/dist/passkey/errors.mjs +20 -0
- package/dist/passkey/errors.mjs.map +1 -0
- package/dist/passkey/management.mjs +276 -0
- package/dist/passkey/management.mjs.map +1 -0
- package/dist/passkey/models.d.mts +1245 -0
- package/dist/passkey/models.mjs +301 -0
- package/dist/passkey/models.mjs.map +1 -0
- package/dist/passkey/module.d.mts +2132 -0
- package/dist/passkey/module.mjs +174 -0
- package/dist/passkey/module.mjs.map +1 -0
- package/dist/passkey/pending.mjs +99 -0
- package/dist/passkey/pending.mjs.map +1 -0
- package/dist/passkey/policy.d.mts +48 -0
- package/dist/passkey/policy.mjs +77 -0
- package/dist/passkey/policy.mjs.map +1 -0
- package/dist/passkey/registration.mjs +107 -0
- package/dist/passkey/registration.mjs.map +1 -0
- package/dist/passkey/simplewebauthn/configuration.mjs +45 -0
- package/dist/passkey/simplewebauthn/configuration.mjs.map +1 -0
- package/dist/passkey/simplewebauthn/models.d.mts +21 -0
- package/dist/passkey/simplewebauthn/models.mjs +8 -0
- package/dist/passkey/simplewebauthn/models.mjs.map +1 -0
- package/dist/passkey/simplewebauthn/protocol.d.mts +62 -0
- package/dist/passkey/simplewebauthn/protocol.mjs +402 -0
- package/dist/passkey/simplewebauthn/protocol.mjs.map +1 -0
- package/dist/passkey/snapshot.mjs +31 -0
- package/dist/passkey/snapshot.mjs.map +1 -0
- package/dist/passkey/stepUp.mjs +101 -0
- package/dist/passkey/stepUp.mjs.map +1 -0
- package/dist/password/CompromisedPasswords.d.mts +26 -0
- package/dist/password/CompromisedPasswords.mjs +23 -0
- package/dist/password/CompromisedPasswords.mjs.map +1 -0
- package/dist/password/NewPasswordCheck.d.mts +21 -0
- package/dist/password/NewPasswordCheck.mjs +39 -0
- package/dist/password/NewPasswordCheck.mjs.map +1 -0
- package/dist/password/PasswordHashing.d.mts +24 -0
- package/dist/password/PasswordHashing.mjs +96 -0
- package/dist/password/PasswordHashing.mjs.map +1 -0
- package/dist/password/PasswordKdfAdmission.d.mts +19 -0
- package/dist/password/PasswordKdfAdmission.mjs +25 -0
- package/dist/password/PasswordKdfAdmission.mjs.map +1 -0
- package/dist/password/configuration.d.mts +43 -0
- package/dist/password/configuration.mjs +64 -0
- package/dist/password/configuration.mjs.map +1 -0
- package/dist/password/defaults.mjs +13 -0
- package/dist/password/defaults.mjs.map +1 -0
- package/dist/password/encoding.mjs +64 -0
- package/dist/password/encoding.mjs.map +1 -0
- package/dist/password/errors.d.mts +28 -0
- package/dist/password/errors.mjs +25 -0
- package/dist/password/errors.mjs.map +1 -0
- package/dist/password/methods/PasswordActionEvidence.d.mts +38 -0
- package/dist/password/methods/PasswordActionEvidence.mjs +22 -0
- package/dist/password/methods/PasswordActionEvidence.mjs.map +1 -0
- package/dist/password/methods/PasswordPersistence.d.mts +102 -0
- package/dist/password/methods/PasswordPersistence.mjs +13 -0
- package/dist/password/methods/PasswordPersistence.mjs.map +1 -0
- package/dist/password/methods/PasswordPreparedPersistence.d.mts +111 -0
- package/dist/password/methods/contracts.d.mts +43 -0
- package/dist/password/methods/contracts.mjs +33 -0
- package/dist/password/methods/contracts.mjs.map +1 -0
- package/dist/password/methods/definition.d.mts +3813 -0
- package/dist/password/methods/definition.mjs +56 -0
- package/dist/password/methods/definition.mjs.map +1 -0
- package/dist/password/methods/errors.d.mts +15 -0
- package/dist/password/methods/errors.mjs +11 -0
- package/dist/password/methods/errors.mjs.map +1 -0
- package/dist/password/methods/models.d.mts +70 -0
- package/dist/password/methods/models.mjs +44 -0
- package/dist/password/methods/models.mjs.map +1 -0
- package/dist/password/methods/module.d.mts +3567 -0
- package/dist/password/methods/module.mjs +553 -0
- package/dist/password/methods/module.mjs.map +1 -0
- package/dist/password/methods/policy.d.mts +84 -0
- package/dist/password/methods/policy.mjs +80 -0
- package/dist/password/methods/policy.mjs.map +1 -0
- package/dist/password/methods/preparation.mjs +54 -0
- package/dist/password/methods/preparation.mjs.map +1 -0
- package/dist/password/methods/prepared.d.mts +53 -0
- package/dist/password/methods/prepared.mjs +610 -0
- package/dist/password/methods/prepared.mjs.map +1 -0
- package/dist/password/methods/preparedModels.d.mts +1295 -0
- package/dist/password/methods/preparedModels.mjs +278 -0
- package/dist/password/methods/preparedModels.mjs.map +1 -0
- package/dist/password/methods/signIn.d.mts +180 -0
- package/dist/password/methods/signIn.mjs +73 -0
- package/dist/password/methods/signIn.mjs.map +1 -0
- package/dist/password/methods/snapshot.mjs +38 -0
- package/dist/password/methods/snapshot.mjs.map +1 -0
- package/dist/password/methods/verification.mjs +138 -0
- package/dist/password/methods/verification.mjs.map +1 -0
- package/dist/password/models.d.mts +13 -0
- package/dist/password/models.mjs +12 -0
- package/dist/password/models.mjs.map +1 -0
- package/dist/password/policy.d.mts +33 -0
- package/dist/password/policy.mjs +37 -0
- package/dist/password/policy.mjs.map +1 -0
- package/dist/phone/PhoneActionEvidence.d.mts +23 -0
- package/dist/phone/PhoneActionEvidence.mjs +10 -0
- package/dist/phone/PhoneActionEvidence.mjs.map +1 -0
- package/dist/phone/PhoneAdmission.d.mts +29 -0
- package/dist/phone/PhoneAdmission.mjs +10 -0
- package/dist/phone/PhoneAdmission.mjs.map +1 -0
- package/dist/phone/PhoneDeliveryEligibility.d.mts +11 -0
- package/dist/phone/PhoneDeliveryEligibility.mjs +8 -0
- package/dist/phone/PhoneDeliveryEligibility.mjs.map +1 -0
- package/dist/phone/PhonePersistence.d.mts +33 -0
- package/dist/phone/PhonePersistence.mjs +10 -0
- package/dist/phone/PhonePersistence.mjs.map +1 -0
- package/dist/phone/PhoneRequestContext.d.mts +10 -0
- package/dist/phone/PhoneRequestContext.mjs +8 -0
- package/dist/phone/PhoneRequestContext.mjs.map +1 -0
- package/dist/phone/PhoneSignInTargets.d.mts +19 -0
- package/dist/phone/PhoneSignInTargets.mjs +13 -0
- package/dist/phone/PhoneSignInTargets.mjs.map +1 -0
- package/dist/phone/definition.d.mts +7190 -0
- package/dist/phone/definition.mjs +28 -0
- package/dist/phone/definition.mjs.map +1 -0
- package/dist/phone/failure.mjs +23 -0
- package/dist/phone/failure.mjs.map +1 -0
- package/dist/phone/lifecycle.mjs +427 -0
- package/dist/phone/lifecycle.mjs.map +1 -0
- package/dist/phone/lifecycleModels.d.mts +164 -0
- package/dist/phone/lifecycleModels.mjs +91 -0
- package/dist/phone/lifecycleModels.mjs.map +1 -0
- package/dist/phone/models.d.mts +41 -0
- package/dist/phone/models.mjs +29 -0
- package/dist/phone/models.mjs.map +1 -0
- package/dist/phone/module.d.mts +6027 -0
- package/dist/phone/module.mjs +293 -0
- package/dist/phone/module.mjs.map +1 -0
- package/dist/proofs/EmailProofDelivery.d.mts +13 -0
- package/dist/proofs/EmailProofDelivery.mjs +11 -0
- package/dist/proofs/EmailProofDelivery.mjs.map +1 -0
- package/dist/proofs/HostIngressLimiter.d.mts +20 -0
- package/dist/proofs/HostIngressLimiter.mjs +13 -0
- package/dist/proofs/HostIngressLimiter.mjs.map +1 -0
- package/dist/proofs/ProofPersistence.d.mts +140 -0
- package/dist/proofs/ProofPersistence.mjs +13 -0
- package/dist/proofs/ProofPersistence.mjs.map +1 -0
- package/dist/proofs/SmsProofDelivery.d.mts +13 -0
- package/dist/proofs/SmsProofDelivery.mjs +11 -0
- package/dist/proofs/SmsProofDelivery.mjs.map +1 -0
- package/dist/proofs/abuse.d.mts +15 -0
- package/dist/proofs/abuse.mjs +12 -0
- package/dist/proofs/abuse.mjs.map +1 -0
- package/dist/proofs/completion.d.mts +22 -0
- package/dist/proofs/crypto.d.mts +196 -0
- package/dist/proofs/crypto.mjs +189 -0
- package/dist/proofs/crypto.mjs.map +1 -0
- package/dist/proofs/definition.d.mts +335 -0
- package/dist/proofs/definition.mjs +10 -0
- package/dist/proofs/definition.mjs.map +1 -0
- package/dist/proofs/delivery.d.mts +30 -0
- package/dist/proofs/delivery.mjs +26 -0
- package/dist/proofs/delivery.mjs.map +1 -0
- package/dist/proofs/dispatch.d.mts +20 -0
- package/dist/proofs/dispatch.mjs +54 -0
- package/dist/proofs/dispatch.mjs.map +1 -0
- package/dist/proofs/errors.d.mts +21 -0
- package/dist/proofs/errors.mjs +25 -0
- package/dist/proofs/errors.mjs.map +1 -0
- package/dist/proofs/models.d.mts +141 -0
- package/dist/proofs/models.mjs +93 -0
- package/dist/proofs/models.mjs.map +1 -0
- package/dist/proofs/module.d.mts +344 -0
- package/dist/proofs/module.mjs +350 -0
- package/dist/proofs/module.mjs.map +1 -0
- package/dist/proofs/policy.d.mts +152 -0
- package/dist/proofs/policy.mjs +51 -0
- package/dist/proofs/policy.mjs.map +1 -0
- package/dist/sessions/AuthenticationAuthority.d.mts +31 -0
- package/dist/sessions/AuthenticationAuthority.mjs +8 -0
- package/dist/sessions/AuthenticationAuthority.mjs.map +1 -0
- package/dist/sessions/PendingAuthentication.d.mts +108 -0
- package/dist/sessions/PendingAuthentication.mjs +40 -0
- package/dist/sessions/PendingAuthentication.mjs.map +1 -0
- package/dist/sessions/SessionStepUpPersistence.d.mts +152 -0
- package/dist/sessions/SessionStepUpPersistence.mjs +63 -0
- package/dist/sessions/SessionStepUpPersistence.mjs.map +1 -0
- package/dist/sessions/assurance.d.mts +163 -0
- package/dist/sessions/assurance.mjs +95 -0
- package/dist/sessions/assurance.mjs.map +1 -0
- package/dist/sessions/commit.d.mts +13 -0
- package/dist/sessions/configuration.d.mts +46 -0
- package/dist/sessions/configuration.mjs +55 -0
- package/dist/sessions/configuration.mjs.map +1 -0
- package/dist/sessions/contract.d.mts +663 -0
- package/dist/sessions/contract.mjs +174 -0
- package/dist/sessions/contract.mjs.map +1 -0
- package/dist/sessions/crypto.d.mts +24 -0
- package/dist/sessions/crypto.mjs +106 -0
- package/dist/sessions/crypto.mjs.map +1 -0
- package/dist/sessions/definition.d.mts +11 -0
- package/dist/sessions/definition.mjs +10 -0
- package/dist/sessions/definition.mjs.map +1 -0
- package/dist/sessions/errors.d.mts +35 -0
- package/dist/sessions/errors.mjs +34 -0
- package/dist/sessions/errors.mjs.map +1 -0
- package/dist/sessions/invalidation.d.mts +23 -0
- package/dist/sessions/invalidation.mjs +33 -0
- package/dist/sessions/invalidation.mjs.map +1 -0
- package/dist/sessions/models.d.mts +143 -0
- package/dist/sessions/models.mjs +94 -0
- package/dist/sessions/models.mjs.map +1 -0
- package/dist/sessions/module.d.mts +1091 -0
- package/dist/sessions/module.mjs +943 -0
- package/dist/sessions/module.mjs.map +1 -0
- package/dist/sessions/persistence.d.mts +93 -0
- package/dist/sessions/policy.d.mts +80 -0
- package/dist/sessions/policy.mjs +66 -0
- package/dist/sessions/policy.mjs.map +1 -0
- package/dist/testing/conformance/AuthStore.d.mts +11 -0
- package/dist/testing/conformance/AuthStore.mjs +173 -0
- package/dist/testing/conformance/AuthStore.mjs.map +1 -0
- package/dist/testing/conformance/OAuthConnectionStore.d.mts +11 -0
- package/dist/testing/conformance/OAuthConnectionStore.mjs +102 -0
- package/dist/testing/conformance/OAuthConnectionStore.mjs.map +1 -0
- package/dist/testing/conformance/OAuthStateStore.d.mts +11 -0
- package/dist/testing/conformance/OAuthStateStore.mjs +45 -0
- package/dist/testing/conformance/OAuthStateStore.mjs.map +1 -0
- package/dist/testing/conformance/PasswordCredentialStore.d.mts +20 -0
- package/dist/testing/conformance/PasswordCredentialStore.mjs +103 -0
- package/dist/testing/conformance/PasswordCredentialStore.mjs.map +1 -0
- package/dist/testing/conformance/support.mjs +17 -0
- package/dist/testing/conformance/support.mjs.map +1 -0
- package/dist/testing/crypto.d.mts +11 -0
- package/dist/testing/crypto.mjs +41 -0
- package/dist/testing/crypto.mjs.map +1 -0
- package/dist/testing/keyring.d.mts +9 -0
- package/dist/testing/keyring.mjs +17 -0
- package/dist/testing/keyring.mjs.map +1 -0
- package/dist/totp/TotpActionEvidence.d.mts +18 -0
- package/dist/totp/TotpActionEvidence.mjs +8 -0
- package/dist/totp/TotpActionEvidence.mjs.map +1 -0
- package/dist/totp/TotpPersistence.d.mts +19 -0
- package/dist/totp/TotpPersistence.mjs +8 -0
- package/dist/totp/TotpPersistence.mjs.map +1 -0
- package/dist/totp/TotpSecretKeys.d.mts +15 -0
- package/dist/totp/TotpSecretKeys.mjs +8 -0
- package/dist/totp/TotpSecretKeys.mjs.map +1 -0
- package/dist/totp/crypto.mjs +96 -0
- package/dist/totp/crypto.mjs.map +1 -0
- package/dist/totp/definition.d.mts +764 -0
- package/dist/totp/definition.mjs +24 -0
- package/dist/totp/definition.mjs.map +1 -0
- package/dist/totp/errors.d.mts +16 -0
- package/dist/totp/errors.mjs +18 -0
- package/dist/totp/errors.mjs.map +1 -0
- package/dist/totp/models.d.mts +377 -0
- package/dist/totp/models.mjs +137 -0
- package/dist/totp/models.mjs.map +1 -0
- package/dist/totp/module.d.mts +737 -0
- package/dist/totp/module.mjs +355 -0
- package/dist/totp/module.mjs.map +1 -0
- package/package.json +1 -0
- package/src/Atom.ts +4 -0
- package/src/Auth.ts +16 -0
- package/src/AuthContract.ts +17 -0
- package/src/AuthSession.ts +298 -0
- package/src/AuthStore.ts +367 -0
- package/src/AuthTokenCodec.ts +226 -0
- package/src/Client.ts +9 -0
- package/src/Cloudflare.ts +345 -0
- package/src/Drizzle.ts +378 -0
- package/src/DrizzleD1.ts +136 -0
- package/src/DrizzleLibsql.ts +288 -0
- package/src/DrizzleMysql2.ts +184 -0
- package/src/DrizzlePglite.ts +160 -0
- package/src/DrizzlePostgres.ts +160 -0
- package/src/DrizzleSqliteBun.ts +244 -0
- package/src/DrizzleSqliteDo.ts +473 -0
- package/src/DrizzleSqliteNode.ts +245 -0
- package/src/DrizzleSqliteWasm.ts +245 -0
- package/src/Email.ts +55 -0
- package/src/EmailOtp.ts +250 -0
- package/src/EmailOtpSender.ts +28 -0
- package/src/Errors.ts +103 -0
- package/src/GitHub.ts +16 -0
- package/src/Hooks.ts +50 -0
- package/src/Http.ts +47 -0
- package/src/HttpServer.ts +742 -0
- package/src/Identity.ts +53 -0
- package/src/IdentityResolver.ts +18 -0
- package/src/OAuth.ts +242 -0
- package/src/OpenIdClient.ts +13 -0
- package/src/OpenIdClientConnected.ts +18 -0
- package/src/OperationHttp.ts +14 -0
- package/src/OperationHttpClient.ts +6 -0
- package/src/OperationHttpServer.ts +15 -0
- package/src/Operations.ts +69 -0
- package/src/Passkey.ts +81 -0
- package/src/PasskeyBrowser.ts +19 -0
- package/src/PasskeyContract.ts +212 -0
- package/src/PasskeyPassword.ts +319 -0
- package/src/PasskeySimpleWebAuthn.ts +6 -0
- package/src/Password.ts +113 -0
- package/src/PasswordAuth.ts +197 -0
- package/src/PasswordCredentialStore.ts +140 -0
- package/src/PasswordHasher.ts +147 -0
- package/src/PhoneOtp.ts +32 -0
- package/src/Policy.ts +95 -0
- package/src/Proofs.ts +71 -0
- package/src/Rpc.ts +15 -0
- package/src/Schema.ts +235 -0
- package/src/SessionContract.ts +2 -0
- package/src/Sessions.ts +105 -0
- package/src/Testing.ts +24 -0
- package/src/Totp.ts +28 -0
- package/src/TotpContract.ts +147 -0
- package/src/WebCrypto.ts +61 -0
- package/src/Workflows.ts +12 -0
- package/src/atom/AuthAtomLifetime.ts +87 -0
- package/src/atom/AuthAtomWorkflow.ts +27 -0
- package/src/atom/client.ts +364 -0
- package/src/atom/operations.ts +183 -0
- package/src/atom/scoped-runtime.ts +249 -0
- package/src/auth/Auth.ts +482 -0
- package/src/auth/AuthConfigurationError.ts +9 -0
- package/src/auth/AuthRequest.ts +21 -0
- package/src/auth/AuthStrategy.ts +116 -0
- package/src/auth/ConsumeDecision.ts +4 -0
- package/src/auth/actions.ts +220 -0
- package/src/auth/defaults.ts +23 -0
- package/src/auth/definition.ts +88 -0
- package/src/auth/session.ts +146 -0
- package/src/drizzle/D1BatchStatements.ts +10 -0
- package/src/drizzle/PasswordPreparedPostconditions.ts +30 -0
- package/src/drizzle/SuppliedService.ts +10 -0
- package/src/drizzle/d1-emails.ts +1808 -0
- package/src/drizzle/d1-generated-statement.ts +129 -0
- package/src/drizzle/d1-identity.ts +374 -0
- package/src/drizzle/d1-oauth.ts +338 -0
- package/src/drizzle/d1-passkey.ts +371 -0
- package/src/drizzle/d1-password-prepared.ts +1273 -0
- package/src/drizzle/d1-passwords.ts +2661 -0
- package/src/drizzle/d1-phone.ts +94 -0
- package/src/drizzle/d1-planning.ts +105 -0
- package/src/drizzle/d1-proofs.ts +2305 -0
- package/src/drizzle/d1-sessions.ts +2867 -0
- package/src/drizzle/d1-totp.ts +79 -0
- package/src/drizzle/email-model.ts +512 -0
- package/src/drizzle/email-registration.ts +696 -0
- package/src/drizzle/email-sql.ts +1468 -0
- package/src/drizzle/email-target.ts +243 -0
- package/src/drizzle/model.ts +492 -0
- package/src/drizzle/mysql-emails.ts +323 -0
- package/src/drizzle/mysql-identity.ts +323 -0
- package/src/drizzle/mysql-password-prepared.ts +206 -0
- package/src/drizzle/mysql-passwords.ts +341 -0
- package/src/drizzle/mysql-proofs.ts +183 -0
- package/src/drizzle/mysql-sessions.ts +742 -0
- package/src/drizzle/mysql.ts +686 -0
- package/src/drizzle/oauth-accounts.ts +801 -0
- package/src/drizzle/oauth-connected-access.ts +354 -0
- package/src/drizzle/oauth-connected-collection.ts +324 -0
- package/src/drizzle/oauth-connected-custody.ts +277 -0
- package/src/drizzle/oauth-connected-drivers.ts +463 -0
- package/src/drizzle/oauth-connected-flow.ts +439 -0
- package/src/drizzle/oauth-connected-input.ts +128 -0
- package/src/drizzle/oauth-connected-maintenance.ts +345 -0
- package/src/drizzle/oauth-connected-management.ts +365 -0
- package/src/drizzle/oauth-connected-model.ts +347 -0
- package/src/drizzle/oauth-connected-reference.ts +112 -0
- package/src/drizzle/oauth-connected-settlement.ts +226 -0
- package/src/drizzle/oauth-connected-state.ts +846 -0
- package/src/drizzle/oauth-connected-target.ts +264 -0
- package/src/drizzle/oauth-drivers.ts +567 -0
- package/src/drizzle/oauth-flow.ts +461 -0
- package/src/drizzle/oauth-input.ts +205 -0
- package/src/drizzle/oauth-model.ts +610 -0
- package/src/drizzle/oauth-mysql.ts +10 -0
- package/src/drizzle/oauth-owner.ts +29 -0
- package/src/drizzle/oauth-registration.ts +638 -0
- package/src/drizzle/oauth-state.ts +213 -0
- package/src/drizzle/oauth-target.ts +751 -0
- package/src/drizzle/passkey-admission.ts +333 -0
- package/src/drizzle/passkey-credentials.ts +465 -0
- package/src/drizzle/passkey-drivers.ts +385 -0
- package/src/drizzle/passkey-enrollment.ts +280 -0
- package/src/drizzle/passkey-flow.ts +983 -0
- package/src/drizzle/passkey-management.ts +369 -0
- package/src/drizzle/passkey-model.ts +350 -0
- package/src/drizzle/passkey-registration-ceremony-model.ts +69 -0
- package/src/drizzle/passkey-registration-ceremony.ts +254 -0
- package/src/drizzle/passkey-registration-custody.ts +82 -0
- package/src/drizzle/passkey-registration-write.ts +378 -0
- package/src/drizzle/passkey-state.ts +307 -0
- package/src/drizzle/passkey-target.ts +528 -0
- package/src/drizzle/passkey-write-drivers.ts +396 -0
- package/src/drizzle/passkey-write-model.ts +265 -0
- package/src/drizzle/passkey-write-state.ts +627 -0
- package/src/drizzle/passkey-write-target.ts +406 -0
- package/src/drizzle/password-model.ts +491 -0
- package/src/drizzle/password-prepared-model.ts +259 -0
- package/src/drizzle/password-prepared-sql.ts +1198 -0
- package/src/drizzle/password-prepared-state.ts +232 -0
- package/src/drizzle/password-prepared-target.ts +158 -0
- package/src/drizzle/password-registration.ts +372 -0
- package/src/drizzle/password-sql.ts +2082 -0
- package/src/drizzle/password-target.ts +223 -0
- package/src/drizzle/pg-emails.ts +323 -0
- package/src/drizzle/pg-password-prepared.ts +207 -0
- package/src/drizzle/pg-passwords.ts +340 -0
- package/src/drizzle/pg-proofs.ts +193 -0
- package/src/drizzle/pg-sessions.ts +751 -0
- package/src/drizzle/pg.ts +982 -0
- package/src/drizzle/phone-model.ts +185 -0
- package/src/drizzle/phone-state.ts +802 -0
- package/src/drizzle/phone-target.ts +471 -0
- package/src/drizzle/proof-model.ts +398 -0
- package/src/drizzle/proof-sql.ts +1912 -0
- package/src/drizzle/proof-target.ts +120 -0
- package/src/drizzle/session-model.ts +368 -0
- package/src/drizzle/session-sql.ts +2152 -0
- package/src/drizzle/session-target.ts +335 -0
- package/src/drizzle/sqlite-emails.ts +368 -0
- package/src/drizzle/sqlite-identity.ts +343 -0
- package/src/drizzle/sqlite-password-prepared.ts +262 -0
- package/src/drizzle/sqlite-passwords.ts +499 -0
- package/src/drizzle/sqlite-proofs.ts +204 -0
- package/src/drizzle/sqlite-sessions.ts +972 -0
- package/src/drizzle/sqlite.ts +704 -0
- package/src/drizzle/standalone-guard.ts +38 -0
- package/src/drizzle/step-up-model.ts +129 -0
- package/src/drizzle/step-up-state.ts +141 -0
- package/src/drizzle/totp-model.ts +91 -0
- package/src/drizzle/totp-state.ts +520 -0
- package/src/drizzle/totp-target.ts +304 -0
- package/src/drizzle/transaction-execution.ts +290 -0
- package/src/drizzle/transaction-mysql.ts +104 -0
- package/src/drizzle/transaction-owner.ts +570 -0
- package/src/email/EmailActionEvidence.ts +37 -0
- package/src/email/EmailAddressPersistence.ts +71 -0
- package/src/email/EmailIdentifierNotifier.ts +48 -0
- package/src/email/EmailReturnTargets.ts +50 -0
- package/src/email/EmailSignInTargets.ts +20 -0
- package/src/email/addresses.ts +630 -0
- package/src/email/definition.ts +309 -0
- package/src/email/errors.ts +23 -0
- package/src/email/magicLink.ts +84 -0
- package/src/email/models.ts +50 -0
- package/src/email/module.ts +664 -0
- package/src/email/registration.ts +415 -0
- package/src/email/snapshot.ts +51 -0
- package/src/hooks/LifecycleHooks.ts +136 -0
- package/src/hooks/commit.ts +271 -0
- package/src/hooks/models.ts +111 -0
- package/src/hooks/plugins.ts +87 -0
- package/src/hooks/transactions.ts +51 -0
- package/src/http/auth-api.ts +17 -0
- package/src/http/auth-contract.ts +148 -0
- package/src/http/auth-http.ts +467 -0
- package/src/http/endpoints/get-session.ts +9 -0
- package/src/http/endpoints/password-sign-in.ts +19 -0
- package/src/http/endpoints/request-email-otp.ts +10 -0
- package/src/http/endpoints/set-password.ts +18 -0
- package/src/http/endpoints/sign-out.ts +5 -0
- package/src/http/endpoints/verify-email-otp.ts +15 -0
- package/src/http/models.ts +80 -0
- package/src/http/security.ts +102 -0
- package/src/http/session-contract.ts +92 -0
- package/src/http-operation/OperationHttpInvocation.ts +39 -0
- package/src/http-operation/OperationHttpServerConfig.ts +124 -0
- package/src/http-operation/auth-client.ts +273 -0
- package/src/http-operation/client.ts +453 -0
- package/src/http-operation/configuration-schema.ts +19 -0
- package/src/http-operation/contract.ts +116 -0
- package/src/http-operation/errors.ts +38 -0
- package/src/http-operation/models.ts +42 -0
- package/src/http-operation/private.ts +50 -0
- package/src/http-operation/security.ts +93 -0
- package/src/http-operation/server.ts +544 -0
- package/src/identity/ExternalIdentityMutation.ts +18 -0
- package/src/identity/IdentityMutation.ts +41 -0
- package/src/identity/IdentityRepository.ts +37 -0
- package/src/identity/SubjectLifecycle.ts +80 -0
- package/src/identity/SubjectProvisioner.ts +40 -0
- package/src/identity/codecs.ts +54 -0
- package/src/identity/models.ts +82 -0
- package/src/identity/operations.ts +182 -0
- package/src/index.ts +23 -0
- package/src/internal/AuthStoreDecisions.ts +23 -0
- package/src/internal/CurrentSession.ts +8 -0
- package/src/internal/diagnostics.ts +71 -0
- package/src/oauth/GithubOAuthProvider.ts +106 -0
- package/src/oauth/OAuth.ts +436 -0
- package/src/oauth/OAuthAccountsPersistence.ts +142 -0
- package/src/oauth/OAuthActionEvidence.ts +31 -0
- package/src/oauth/OAuthConnectedActionEvidence.ts +28 -0
- package/src/oauth/OAuthConnectedPersistence.ts +163 -0
- package/src/oauth/OAuthConnectedProtocol.ts +54 -0
- package/src/oauth/OAuthConnectedRevocations.ts +48 -0
- package/src/oauth/OAuthConnectedTokenProtector.ts +240 -0
- package/src/oauth/OAuthConnectedTransactionProtector.ts +56 -0
- package/src/oauth/OAuthConnectedUseAuthority.ts +26 -0
- package/src/oauth/OAuthConnectionStore.ts +59 -0
- package/src/oauth/OAuthLinkTransactionProtector.ts +58 -0
- package/src/oauth/OAuthProtocol.ts +39 -0
- package/src/oauth/OAuthProvider.ts +126 -0
- package/src/oauth/OAuthProviders.ts +53 -0
- package/src/oauth/OAuthRegistrationIntents.ts +42 -0
- package/src/oauth/OAuthReturnTargets.ts +44 -0
- package/src/oauth/OAuthSignInPersistence.ts +91 -0
- package/src/oauth/OAuthStateDecisions.ts +16 -0
- package/src/oauth/OAuthStateStore.ts +102 -0
- package/src/oauth/OAuthTransactionProtector.ts +103 -0
- package/src/oauth/accounts.ts +987 -0
- package/src/oauth/accountsModels.ts +214 -0
- package/src/oauth/connected.ts +995 -0
- package/src/oauth/connectedAccess.ts +644 -0
- package/src/oauth/connectedMaintenance.ts +248 -0
- package/src/oauth/connectedModels.ts +495 -0
- package/src/oauth/definition.ts +414 -0
- package/src/oauth/errors.ts +78 -0
- package/src/oauth/github/identity.ts +26 -0
- package/src/oauth/github/models.ts +37 -0
- package/src/oauth/github/protocol.ts +329 -0
- package/src/oauth/openid-client/ProviderRevocation.ts +22 -0
- package/src/oauth/openid-client/compatibility.ts +47 -0
- package/src/oauth/openid-client/configuration.ts +472 -0
- package/src/oauth/openid-client/connected/configuration.ts +565 -0
- package/src/oauth/openid-client/connected/models.ts +58 -0
- package/src/oauth/openid-client/connected/protocol.ts +866 -0
- package/src/oauth/openid-client/models.ts +78 -0
- package/src/oauth/openid-client/protocol.ts +437 -0
- package/src/oauth/openid-client/transport.ts +67 -0
- package/src/oauth/policy.ts +26 -0
- package/src/oauth/registration.ts +410 -0
- package/src/oauth/registrationModels.ts +115 -0
- package/src/oauth/registrationSecrets.ts +127 -0
- package/src/oauth/schema.ts +102 -0
- package/src/oauth/signInErrors.ts +23 -0
- package/src/oauth/signInModels.ts +266 -0
- package/src/oauth/signInModule.ts +875 -0
- package/src/oauth/signInSnapshot.ts +37 -0
- package/src/oauth/transactionEncryption.ts +198 -0
- package/src/operations/RequestBindingConfig.ts +12 -0
- package/src/operations/actions.ts +342 -0
- package/src/operations/context.ts +130 -0
- package/src/operations/credentials.ts +121 -0
- package/src/operations/errors.ts +53 -0
- package/src/operations/operation.ts +740 -0
- package/src/operations/requestBinding.ts +237 -0
- package/src/operations/requestBindingModels.ts +18 -0
- package/src/operations/reveals.ts +147 -0
- package/src/passkey/PasskeyActionEvidence.ts +25 -0
- package/src/passkey/PasskeyCredentials.ts +16 -0
- package/src/passkey/PasskeyEnrollmentContext.ts +26 -0
- package/src/passkey/PasskeyManagementPersistence.ts +124 -0
- package/src/passkey/PasskeyPersistence.ts +85 -0
- package/src/passkey/PasskeyProtocol.ts +48 -0
- package/src/passkey/actions.ts +905 -0
- package/src/passkey/browser/PasskeyBrowser.ts +26 -0
- package/src/passkey/browser/models.ts +67 -0
- package/src/passkey/browser/simplewebauthn.ts +621 -0
- package/src/passkey/definition.ts +386 -0
- package/src/passkey/errors.ts +39 -0
- package/src/passkey/management.ts +552 -0
- package/src/passkey/models.ts +414 -0
- package/src/passkey/module.ts +367 -0
- package/src/passkey/pending.ts +203 -0
- package/src/passkey/policy.ts +88 -0
- package/src/passkey/registration.ts +251 -0
- package/src/passkey/simplewebauthn/configuration.ts +97 -0
- package/src/passkey/simplewebauthn/models.ts +9 -0
- package/src/passkey/simplewebauthn/protocol.ts +729 -0
- package/src/passkey/snapshot.ts +48 -0
- package/src/passkey/stepUp.ts +212 -0
- package/src/password/CompromisedPasswords.ts +36 -0
- package/src/password/NewPasswordCheck.ts +89 -0
- package/src/password/PasswordHashing.ts +209 -0
- package/src/password/PasswordKdfAdmission.ts +44 -0
- package/src/password/configuration.ts +52 -0
- package/src/password/defaults.ts +15 -0
- package/src/password/encoding.ts +137 -0
- package/src/password/errors.ts +43 -0
- package/src/password/methods/PasswordActionEvidence.ts +41 -0
- package/src/password/methods/PasswordPersistence.ts +128 -0
- package/src/password/methods/PasswordPreparedPersistence.ts +123 -0
- package/src/password/methods/contracts.ts +47 -0
- package/src/password/methods/definition.ts +199 -0
- package/src/password/methods/errors.ts +26 -0
- package/src/password/methods/models.ts +80 -0
- package/src/password/methods/module.ts +986 -0
- package/src/password/methods/policy.ts +68 -0
- package/src/password/methods/preparation.ts +73 -0
- package/src/password/methods/prepared.ts +1199 -0
- package/src/password/methods/preparedModels.ts +496 -0
- package/src/password/methods/signIn.ts +136 -0
- package/src/password/methods/snapshot.ts +53 -0
- package/src/password/methods/verification.ts +266 -0
- package/src/password/models.ts +15 -0
- package/src/password/policy.ts +41 -0
- package/src/phone/PhoneActionEvidence.ts +26 -0
- package/src/phone/PhoneAdmission.ts +29 -0
- package/src/phone/PhoneDeliveryEligibility.ts +9 -0
- package/src/phone/PhonePersistence.ts +43 -0
- package/src/phone/PhoneRequestContext.ts +7 -0
- package/src/phone/PhoneSignInTargets.ts +19 -0
- package/src/phone/definition.ts +87 -0
- package/src/phone/failure.ts +40 -0
- package/src/phone/lifecycle.ts +662 -0
- package/src/phone/lifecycleModels.ts +108 -0
- package/src/phone/models.ts +41 -0
- package/src/phone/module.ts +433 -0
- package/src/proofs/EmailProofDelivery.ts +19 -0
- package/src/proofs/HostIngressLimiter.ts +20 -0
- package/src/proofs/ProofPersistence.ts +172 -0
- package/src/proofs/SmsProofDelivery.ts +19 -0
- package/src/proofs/abuse.ts +23 -0
- package/src/proofs/completion.ts +23 -0
- package/src/proofs/crypto.ts +326 -0
- package/src/proofs/definition.ts +39 -0
- package/src/proofs/delivery.ts +73 -0
- package/src/proofs/dispatch.ts +99 -0
- package/src/proofs/errors.ts +46 -0
- package/src/proofs/models.ts +131 -0
- package/src/proofs/module.ts +620 -0
- package/src/proofs/policy.ts +77 -0
- package/src/sessions/AuthenticationAuthority.ts +51 -0
- package/src/sessions/PendingAuthentication.ts +121 -0
- package/src/sessions/SessionStepUpPersistence.ts +164 -0
- package/src/sessions/assurance.ts +192 -0
- package/src/sessions/commit.ts +13 -0
- package/src/sessions/configuration.ts +133 -0
- package/src/sessions/contract.ts +203 -0
- package/src/sessions/crypto.ts +181 -0
- package/src/sessions/definition.ts +25 -0
- package/src/sessions/errors.ts +68 -0
- package/src/sessions/invalidation.ts +46 -0
- package/src/sessions/models.ts +138 -0
- package/src/sessions/module.ts +1991 -0
- package/src/sessions/persistence.ts +135 -0
- package/src/sessions/policy.ts +103 -0
- package/src/testing/conformance/AuthStore.ts +314 -0
- package/src/testing/conformance/OAuthConnectionStore.ts +167 -0
- package/src/testing/conformance/OAuthStateStore.ts +105 -0
- package/src/testing/conformance/PasswordCredentialStore.ts +205 -0
- package/src/testing/conformance/support.ts +38 -0
- package/src/testing/crypto.ts +55 -0
- package/src/testing/keyring.ts +17 -0
- package/src/totp/TotpActionEvidence.ts +18 -0
- package/src/totp/TotpPersistence.ts +26 -0
- package/src/totp/TotpSecretKeys.ts +15 -0
- package/src/totp/crypto.ts +160 -0
- package/src/totp/definition.ts +78 -0
- package/src/totp/errors.ts +25 -0
- package/src/totp/models.ts +164 -0
- package/src/totp/module.ts +717 -0
|
@@ -0,0 +1,2661 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any -- D1 plans bridge consumer-owned Drizzle rows and SQL statements. */
|
|
2
|
+
import type { D1Client } from "@effect/sql-d1/D1Client";
|
|
3
|
+
import {
|
|
4
|
+
and,
|
|
5
|
+
count,
|
|
6
|
+
eq,
|
|
7
|
+
gte,
|
|
8
|
+
inArray,
|
|
9
|
+
lte,
|
|
10
|
+
notExists,
|
|
11
|
+
sql,
|
|
12
|
+
type AnyRelations,
|
|
13
|
+
type SQL,
|
|
14
|
+
type Table,
|
|
15
|
+
} from "drizzle-orm";
|
|
16
|
+
import type { EffectDrizzleQueryError } from "drizzle-orm/effect-core";
|
|
17
|
+
import type { EffectSQLiteD1Database } from "drizzle-orm/effect-d1";
|
|
18
|
+
import type { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
19
|
+
import { Cause, DateTime, Effect, Option, Predicate, Redacted, Schema, Context } from "effect";
|
|
20
|
+
import type { Statement } from "effect/unstable/sql/Statement";
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
coordinateCommit,
|
|
24
|
+
CurrentCommitJournal,
|
|
25
|
+
hasCommitScope,
|
|
26
|
+
type CommitJournal,
|
|
27
|
+
type PreparedCommit,
|
|
28
|
+
} from "../hooks/commit";
|
|
29
|
+
import { LifecycleHooks } from "../hooks/LifecycleHooks";
|
|
30
|
+
import { HookConfigurationError } from "../hooks/models";
|
|
31
|
+
import type { LoginIdentifier } from "../identity/models";
|
|
32
|
+
import { reportPersistenceFailure } from "../internal/diagnostics";
|
|
33
|
+
import { PasswordUnavailable } from "../password/methods/errors";
|
|
34
|
+
import type {
|
|
35
|
+
PasswordAction,
|
|
36
|
+
PasswordAttemptDecision,
|
|
37
|
+
PasswordCredentialSnapshot,
|
|
38
|
+
PasswordMutationDecision,
|
|
39
|
+
} from "../password/methods/models";
|
|
40
|
+
import {
|
|
41
|
+
PasswordPersistence,
|
|
42
|
+
type PasswordMutationInput,
|
|
43
|
+
type PreparePasswordCommit,
|
|
44
|
+
} from "../password/methods/PasswordPersistence";
|
|
45
|
+
import type { PasswordAttemptPolicy } from "../password/methods/policy";
|
|
46
|
+
import {
|
|
47
|
+
snapshotPasswordCredential,
|
|
48
|
+
snapshotPasswordRequirement,
|
|
49
|
+
snapshotPasswordRevision,
|
|
50
|
+
} from "../password/methods/snapshot";
|
|
51
|
+
import type { ProofCompletionPlan } from "../proofs/completion";
|
|
52
|
+
import { ProofUnavailable } from "../proofs/errors";
|
|
53
|
+
import type { ProofCompletionDecision } from "../proofs/models";
|
|
54
|
+
import type { ProofCompletionInput } from "../proofs/ProofPersistence";
|
|
55
|
+
import { snapshotAuthenticationEvidence } from "../sessions/assurance";
|
|
56
|
+
import {
|
|
57
|
+
AuthenticationEvidence,
|
|
58
|
+
AuthenticationRequirement,
|
|
59
|
+
type SecurityRevision,
|
|
60
|
+
} from "../sessions/models";
|
|
61
|
+
import { balancedD1And } from "./d1-generated-statement";
|
|
62
|
+
import { CurrentD1PlanningDatabase, makeD1Owner } from "./d1-planning";
|
|
63
|
+
import { compileD1ProofCompletionPlan, type D1ProtectedProofMutation } from "./d1-proofs";
|
|
64
|
+
import { D1BatchStatements } from "./D1BatchStatements";
|
|
65
|
+
import { column, isMappedConstraintConflict, DrizzleMappingError, updateValues } from "./model";
|
|
66
|
+
import {
|
|
67
|
+
type AnyPasswordRegistrationMapping,
|
|
68
|
+
type D1PasswordPersistenceMapping,
|
|
69
|
+
type PasswordAttemptRecord,
|
|
70
|
+
type PasswordRateScopeKind,
|
|
71
|
+
type PasswordRegistrationMapping,
|
|
72
|
+
type PasswordScopeKeys,
|
|
73
|
+
requiredPasswordConstraints,
|
|
74
|
+
requiredPasswordRegistrationConstraints,
|
|
75
|
+
} from "./password-model";
|
|
76
|
+
import type { PasswordRegistrationAuthority } from "./password-registration";
|
|
77
|
+
import type { D1ProofPersistenceMapping } from "./proof-model";
|
|
78
|
+
import type { SuppliedService } from "./SuppliedService";
|
|
79
|
+
|
|
80
|
+
type PlanPrepare<Method extends (...args: any[]) => any, A> = (
|
|
81
|
+
value: Parameters<Parameters<Method>[1]>[0],
|
|
82
|
+
journal: CommitJournal,
|
|
83
|
+
) => PreparedCommit<A>;
|
|
84
|
+
|
|
85
|
+
type Database = EffectSQLiteD1Database<AnyRelations> & { readonly $client: D1Client };
|
|
86
|
+
type Mapping = D1PasswordPersistenceMapping<
|
|
87
|
+
Table,
|
|
88
|
+
Table,
|
|
89
|
+
Table,
|
|
90
|
+
Table,
|
|
91
|
+
Table,
|
|
92
|
+
Table,
|
|
93
|
+
Table,
|
|
94
|
+
Table,
|
|
95
|
+
unknown
|
|
96
|
+
>;
|
|
97
|
+
type RegistrationMapping<Registration> = AnyPasswordRegistrationMapping<Registration>;
|
|
98
|
+
type AdapterFailure = DrizzleMappingError | EffectDrizzleQueryError;
|
|
99
|
+
const mapAdapter = <A>(effect: Effect.Effect<A, AdapterFailure>) => effect;
|
|
100
|
+
|
|
101
|
+
interface Planned<A> {
|
|
102
|
+
readonly receipt: A;
|
|
103
|
+
readonly statements: ReadonlyArray<Statement<any>>;
|
|
104
|
+
readonly retryable?: (cause: unknown) => boolean;
|
|
105
|
+
readonly journalGuard?: PreparedCommit<void>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const unavailable = () => PasswordUnavailable.make({});
|
|
109
|
+
|
|
110
|
+
const everyFailureMatches = (
|
|
111
|
+
cause: Cause.Cause<unknown>,
|
|
112
|
+
classify: ((cause: unknown) => boolean) | undefined,
|
|
113
|
+
): boolean =>
|
|
114
|
+
classify !== undefined &&
|
|
115
|
+
cause.reasons.length > 0 &&
|
|
116
|
+
cause.reasons.every((reason) => Cause.isFailReason(reason) && classify(Cause.fail(reason.error)));
|
|
117
|
+
|
|
118
|
+
const validConstraints = (mapping: Mapping) =>
|
|
119
|
+
Object.entries(requiredPasswordConstraints).every(
|
|
120
|
+
([key, value]) =>
|
|
121
|
+
mapping.constraints[key as keyof typeof requiredPasswordConstraints] === value,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const validRegistrationConstraints = <Registration>(mapping: RegistrationMapping<Registration>) =>
|
|
125
|
+
Object.entries(requiredPasswordRegistrationConstraints).every(
|
|
126
|
+
([key, value]) =>
|
|
127
|
+
mapping.constraints[key as keyof typeof requiredPasswordRegistrationConstraints] === value,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const containsFailure = (failure: unknown, predicate: (value: unknown) => boolean): boolean => {
|
|
131
|
+
const seen = new Set<unknown>();
|
|
132
|
+
const pending: Array<unknown> = [failure];
|
|
133
|
+
|
|
134
|
+
for (let inspected = 0; inspected < 32 && pending.length > 0; inspected++) {
|
|
135
|
+
const current = pending.shift();
|
|
136
|
+
|
|
137
|
+
if (current === undefined || current === null || seen.has(current)) continue;
|
|
138
|
+
seen.add(current);
|
|
139
|
+
if (predicate(current)) return true;
|
|
140
|
+
if (Cause.isCause(current)) {
|
|
141
|
+
for (const reason of current.reasons) {
|
|
142
|
+
if (Cause.isFailReason(reason)) pending.push(reason.error);
|
|
143
|
+
else if (Cause.isDieReason(reason)) pending.push(reason.defect);
|
|
144
|
+
}
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (typeof current !== "object") continue;
|
|
148
|
+
|
|
149
|
+
const wrapped = current as {
|
|
150
|
+
readonly cause?: unknown;
|
|
151
|
+
readonly reason?: unknown;
|
|
152
|
+
readonly message?: unknown;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
if (wrapped.cause !== undefined) pending.push(wrapped.cause);
|
|
156
|
+
if (wrapped.reason !== undefined) pending.push(wrapped.reason);
|
|
157
|
+
if (wrapped.message !== undefined) pending.push(wrapped.message);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return false;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Match only workerd's native SQLite diagnostic. A wrapper that merely echoes
|
|
164
|
+
// the bound marker is not evidence that the guard ran and rolled back the batch.
|
|
165
|
+
const isGuardFailure = (cause: unknown, marker: string) => {
|
|
166
|
+
const path = `$[${marker.replaceAll("'", "''")}]`;
|
|
167
|
+
const native = `bad JSON path: '${path}': SQLITE_ERROR`;
|
|
168
|
+
|
|
169
|
+
return containsFailure(cause, (value) => value === native || value === `D1_ERROR: ${native}`);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const statement = Effect.fn(function* (query: {
|
|
173
|
+
readonly toSQL: () => { readonly sql: string; readonly params: unknown[] };
|
|
174
|
+
}) {
|
|
175
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
176
|
+
const rendered = query.toSQL();
|
|
177
|
+
|
|
178
|
+
return database.$client.unsafe(rendered.sql, rendered.params);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const assertion = Effect.fn(function* (condition: SQL, marker: string) {
|
|
182
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
183
|
+
|
|
184
|
+
return yield* statement(
|
|
185
|
+
database
|
|
186
|
+
.select({
|
|
187
|
+
ok: sql`case when ${condition} then 1 else json_extract('[]', ${`$[${marker}]`}) end`.as(
|
|
188
|
+
"ok",
|
|
189
|
+
),
|
|
190
|
+
})
|
|
191
|
+
.from(sql`(select 1)`),
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const readEngineNowMillis = Effect.fn("Drizzle.readEngineNowMillis")(function* (mapping: Mapping) {
|
|
196
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
197
|
+
|
|
198
|
+
return yield* database
|
|
199
|
+
.select({ value: mapping.d1.engineNowMillis.as("engine_now_millis") })
|
|
200
|
+
.from(sql`(select 1)`)
|
|
201
|
+
.pipe(
|
|
202
|
+
Effect.flatMap((rows) => {
|
|
203
|
+
const value = Number(rows[0]?.value);
|
|
204
|
+
|
|
205
|
+
return Number.isFinite(value) ? Effect.succeed(value) : Effect.fail(unavailable());
|
|
206
|
+
}),
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const driverValues = (values: object, entries: ReadonlyArray<readonly [string, unknown]>) => ({
|
|
211
|
+
...values,
|
|
212
|
+
...Object.fromEntries(entries),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const allocate = <A>(
|
|
216
|
+
asyncValue: Effect.Effect<A, DrizzleMappingError> | undefined,
|
|
217
|
+
syncValue: (() => A) | undefined,
|
|
218
|
+
) =>
|
|
219
|
+
asyncValue !== undefined
|
|
220
|
+
? asyncValue
|
|
221
|
+
: syncValue === undefined
|
|
222
|
+
? Effect.fail(unavailable())
|
|
223
|
+
: Effect.try({
|
|
224
|
+
try: syncValue,
|
|
225
|
+
catch: (cause) => new DrizzleMappingError({ operation: "mapping", cause }),
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const allocateNextSecurityRevision = (mapping: Mapping, current: SecurityRevision) =>
|
|
229
|
+
allocate(
|
|
230
|
+
mapping.subject.nextSecurityRevision?.(current) ?? mapping.allocateRevision,
|
|
231
|
+
mapping.subject.nextSecurityRevisionSync === undefined
|
|
232
|
+
? mapping.allocateRevisionSync
|
|
233
|
+
: () => mapping.subject.nextSecurityRevisionSync!(current),
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const subjectColumns = (mapping: Mapping) => ({
|
|
237
|
+
id: column(mapping.subject.table, mapping.subject.id),
|
|
238
|
+
status: column(mapping.subject.table, mapping.subject.status),
|
|
239
|
+
securityRevision: column(mapping.subject.table, mapping.subject.securityRevision),
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const identifierColumns = (mapping: Mapping) => ({
|
|
243
|
+
namespace: column(mapping.identifier.table, mapping.identifier.namespace),
|
|
244
|
+
value: column(mapping.identifier.table, mapping.identifier.value),
|
|
245
|
+
subjectId: column(mapping.identifier.table, mapping.identifier.subjectId),
|
|
246
|
+
verifiedAt: column(mapping.identifier.table, mapping.identifier.verifiedAt),
|
|
247
|
+
bindingRevision: column(mapping.identifier.table, mapping.identifier.bindingRevision),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const credentialColumns = (mapping: Mapping) => ({
|
|
251
|
+
moduleId: column(mapping.credential.table, mapping.credential.moduleId),
|
|
252
|
+
subjectId: column(mapping.credential.table, mapping.credential.subjectId),
|
|
253
|
+
credentialId: column(mapping.credential.table, mapping.credential.credentialId),
|
|
254
|
+
credentialRevision: column(mapping.credential.table, mapping.credential.credentialRevision),
|
|
255
|
+
verifierVersion: column(mapping.credential.table, mapping.credential.verifierVersion),
|
|
256
|
+
verifier: column(mapping.credential.table, mapping.credential.verifier),
|
|
257
|
+
normalization: column(mapping.credential.table, mapping.credential.normalization),
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const authorityColumns = (mapping: Mapping) => ({
|
|
261
|
+
subjectId: column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId),
|
|
262
|
+
credentialId: column(mapping.authorityCredential.table, mapping.authorityCredential.credentialId),
|
|
263
|
+
revision: column(mapping.authorityCredential.table, mapping.authorityCredential.revision),
|
|
264
|
+
status:
|
|
265
|
+
mapping.authorityCredential.status === undefined
|
|
266
|
+
? undefined
|
|
267
|
+
: column(mapping.authorityCredential.table, mapping.authorityCredential.status),
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const attemptColumns = (mapping: Mapping) => ({
|
|
271
|
+
moduleId: column(mapping.attempt.table, mapping.attempt.moduleId),
|
|
272
|
+
action: column(mapping.attempt.table, mapping.attempt.action),
|
|
273
|
+
attemptId: column(mapping.attempt.table, mapping.attempt.attemptId),
|
|
274
|
+
identifierNamespace: column(mapping.attempt.table, mapping.attempt.identifierNamespace),
|
|
275
|
+
identifierValue: column(mapping.attempt.table, mapping.attempt.identifierValue),
|
|
276
|
+
subjectId: column(mapping.attempt.table, mapping.attempt.subjectId),
|
|
277
|
+
credentialId: column(mapping.attempt.table, mapping.attempt.credentialId),
|
|
278
|
+
securityRevision: column(mapping.attempt.table, mapping.attempt.securityRevision),
|
|
279
|
+
credentialRevision: column(mapping.attempt.table, mapping.attempt.credentialRevision),
|
|
280
|
+
verifierVersion: column(mapping.attempt.table, mapping.attempt.verifierVersion),
|
|
281
|
+
identifierBindingRevision: column(
|
|
282
|
+
mapping.attempt.table,
|
|
283
|
+
mapping.attempt.identifierBindingRevision,
|
|
284
|
+
),
|
|
285
|
+
admittedAt: column(mapping.attempt.table, mapping.attempt.admittedAt),
|
|
286
|
+
deadline: column(mapping.attempt.table, mapping.attempt.deadline),
|
|
287
|
+
retentionUntil: column(mapping.attempt.table, mapping.attempt.retentionUntil),
|
|
288
|
+
state: column(mapping.attempt.table, mapping.attempt.state),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const scopeColumns = (mapping: Mapping) => ({
|
|
292
|
+
moduleId: column(mapping.rateScope.table, mapping.rateScope.moduleId),
|
|
293
|
+
action: column(mapping.rateScope.table, mapping.rateScope.action),
|
|
294
|
+
scopeKind: column(mapping.rateScope.table, mapping.rateScope.scopeKind),
|
|
295
|
+
scopeKey: column(mapping.rateScope.table, mapping.rateScope.scopeKey),
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const chargeColumns = (mapping: Mapping) => ({
|
|
299
|
+
moduleId: column(mapping.charge.table, mapping.charge.moduleId),
|
|
300
|
+
action: column(mapping.charge.table, mapping.charge.action),
|
|
301
|
+
scopeKind: column(mapping.charge.table, mapping.charge.scopeKind),
|
|
302
|
+
scopeKey: column(mapping.charge.table, mapping.charge.scopeKey),
|
|
303
|
+
attemptId: column(mapping.charge.table, mapping.charge.attemptId),
|
|
304
|
+
occurredAt: column(mapping.charge.table, mapping.charge.occurredAt),
|
|
305
|
+
retentionUntil: column(mapping.charge.table, mapping.charge.retentionUntil),
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const commandColumns = (mapping: Mapping) => ({
|
|
309
|
+
moduleId: column(mapping.command.table, mapping.command.moduleId),
|
|
310
|
+
commandId: column(mapping.command.table, mapping.command.commandId),
|
|
311
|
+
action: column(mapping.command.table, mapping.command.action),
|
|
312
|
+
bindingDigest: column(mapping.command.table, mapping.command.bindingDigest),
|
|
313
|
+
decision: column(mapping.command.table, mapping.command.decision),
|
|
314
|
+
retentionUntil: column(mapping.command.table, mapping.command.retentionUntil),
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const readIdentifier = Effect.fn("Drizzle.readIdentifier")(function* (
|
|
318
|
+
mapping: Mapping,
|
|
319
|
+
identifier: LoginIdentifier,
|
|
320
|
+
) {
|
|
321
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
322
|
+
|
|
323
|
+
const c = identifierColumns(mapping);
|
|
324
|
+
|
|
325
|
+
return yield* database
|
|
326
|
+
.select()
|
|
327
|
+
.from(mapping.identifier.table)
|
|
328
|
+
.where(and(eq(c.namespace, identifier.namespace), eq(c.value, identifier.value)))
|
|
329
|
+
.limit(1);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const readSubjectNative = Effect.fn("Drizzle.readSubjectNative")(function* (
|
|
333
|
+
mapping: Mapping,
|
|
334
|
+
nativeSubjectId: unknown,
|
|
335
|
+
) {
|
|
336
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
337
|
+
|
|
338
|
+
return yield* database
|
|
339
|
+
.select()
|
|
340
|
+
.from(mapping.subject.table)
|
|
341
|
+
.where(eq(subjectColumns(mapping).id, nativeSubjectId))
|
|
342
|
+
.limit(1);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const readCredentialNative = Effect.fn("Drizzle.readCredentialNative")(function* (
|
|
346
|
+
mapping: Mapping,
|
|
347
|
+
moduleId: string,
|
|
348
|
+
nativeSubjectId: unknown,
|
|
349
|
+
) {
|
|
350
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
351
|
+
|
|
352
|
+
const c = credentialColumns(mapping);
|
|
353
|
+
|
|
354
|
+
return yield* database
|
|
355
|
+
.select()
|
|
356
|
+
.from(mapping.credential.table)
|
|
357
|
+
.where(and(eq(c.moduleId, moduleId), eq(c.subjectId, nativeSubjectId)))
|
|
358
|
+
.limit(1);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
interface Resolved {
|
|
362
|
+
readonly nativeSubjectId: unknown;
|
|
363
|
+
readonly subject: any;
|
|
364
|
+
readonly identifier: any;
|
|
365
|
+
readonly credential?: any;
|
|
366
|
+
readonly snapshot?: PasswordCredentialSnapshot;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const resolveCredential = Effect.fn("DrizzleD1Password.resolveCredential")(function* (
|
|
370
|
+
mapping: Mapping,
|
|
371
|
+
moduleId: string,
|
|
372
|
+
identifier: LoginIdentifier,
|
|
373
|
+
requestedSubjectId?: string,
|
|
374
|
+
) {
|
|
375
|
+
const identifierRow = (yield* readIdentifier(mapping, identifier))[0];
|
|
376
|
+
|
|
377
|
+
if (identifierRow === undefined || !mapping.identifier.isCurrent(identifierRow)) return undefined;
|
|
378
|
+
const nativeSubjectId = identifierRow[mapping.identifier.subjectId];
|
|
379
|
+
const subject = (yield* readSubjectNative(mapping, nativeSubjectId))[0];
|
|
380
|
+
|
|
381
|
+
if (subject === undefined || !mapping.subject.isActiveStatus(subject[mapping.subject.status]))
|
|
382
|
+
return undefined;
|
|
383
|
+
const subjectId = yield* mapping.subjectId.toSubject(nativeSubjectId);
|
|
384
|
+
|
|
385
|
+
if (requestedSubjectId !== undefined && subjectId !== requestedSubjectId) return undefined;
|
|
386
|
+
const credential = (yield* readCredentialNative(mapping, moduleId, nativeSubjectId))[0];
|
|
387
|
+
|
|
388
|
+
if (credential === undefined) return { nativeSubjectId, subject, identifier: identifierRow };
|
|
389
|
+
|
|
390
|
+
const snapshot = yield* mapping.credential
|
|
391
|
+
.decode({ moduleId, subject, identifier: identifierRow, credential })
|
|
392
|
+
.pipe(Effect.flatMap(snapshotPasswordCredential));
|
|
393
|
+
|
|
394
|
+
return { nativeSubjectId, subject, identifier: identifierRow, credential, snapshot };
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
interface ScopeEntry {
|
|
398
|
+
readonly kind: PasswordRateScopeKind;
|
|
399
|
+
readonly key: string;
|
|
400
|
+
readonly limit: number;
|
|
401
|
+
readonly windowMillis: number;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const scopeEntries = (keys: PasswordScopeKeys, policy: PasswordAttemptPolicy) => {
|
|
405
|
+
const entries: ScopeEntry[] = [
|
|
406
|
+
{ kind: "action", key: keys.action, ...policy.action },
|
|
407
|
+
{ kind: "identifier", key: keys.identifier, ...policy.identifier },
|
|
408
|
+
];
|
|
409
|
+
|
|
410
|
+
if (keys.subject !== undefined)
|
|
411
|
+
entries.push({ kind: "subject", key: keys.subject, ...policy.subject });
|
|
412
|
+
|
|
413
|
+
return entries;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const scopeAdmissionCondition = (
|
|
417
|
+
mapping: Mapping,
|
|
418
|
+
moduleId: string,
|
|
419
|
+
action: "sign-in" | "change",
|
|
420
|
+
entry: ScopeEntry,
|
|
421
|
+
policy: PasswordAttemptPolicy,
|
|
422
|
+
identifier: LoginIdentifier,
|
|
423
|
+
nativeSubjectId: unknown | undefined,
|
|
424
|
+
) => {
|
|
425
|
+
const c = chargeColumns(mapping);
|
|
426
|
+
const a = attemptColumns(mapping);
|
|
427
|
+
|
|
428
|
+
const pending =
|
|
429
|
+
entry.kind === "action"
|
|
430
|
+
? and(eq(a.moduleId, moduleId), eq(a.action, action), eq(a.state, "pending"))
|
|
431
|
+
: entry.kind === "identifier"
|
|
432
|
+
? and(
|
|
433
|
+
eq(a.moduleId, moduleId),
|
|
434
|
+
eq(a.action, action),
|
|
435
|
+
eq(a.identifierNamespace, identifier.namespace),
|
|
436
|
+
eq(a.identifierValue, identifier.value),
|
|
437
|
+
eq(a.state, "pending"),
|
|
438
|
+
)
|
|
439
|
+
: and(
|
|
440
|
+
eq(a.moduleId, moduleId),
|
|
441
|
+
eq(a.action, action),
|
|
442
|
+
eq(a.subjectId, nativeSubjectId),
|
|
443
|
+
eq(a.state, "pending"),
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
return sql`(select count(*) from ${mapping.charge.table} where ${c.moduleId} = ${sql.param(moduleId, c.moduleId)} and ${c.action} = ${sql.param(action, c.action)} and ${c.scopeKind} = ${sql.param(entry.kind, c.scopeKind)} and ${c.scopeKey} = ${sql.param(entry.key, c.scopeKey)} and ${c.occurredAt} >= ${mapping.d1.engineInstantMinus(entry.windowMillis)}) < ${entry.limit} and (select count(*) from ${mapping.attempt.table} where ${pending}) < ${policy.maximumPending}`;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const readScopeAdmission = Effect.fn("DrizzleD1Password.readScopeAdmission")(function* (
|
|
450
|
+
mapping: Mapping,
|
|
451
|
+
moduleId: string,
|
|
452
|
+
action: "sign-in" | "change",
|
|
453
|
+
entries: ReadonlyArray<ScopeEntry>,
|
|
454
|
+
policy: PasswordAttemptPolicy,
|
|
455
|
+
identifier: LoginIdentifier,
|
|
456
|
+
nativeSubjectId: unknown | undefined,
|
|
457
|
+
now: number,
|
|
458
|
+
) {
|
|
459
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
460
|
+
|
|
461
|
+
const c = chargeColumns(mapping);
|
|
462
|
+
const a = attemptColumns(mapping);
|
|
463
|
+
const admitted: ScopeEntry[] = [];
|
|
464
|
+
|
|
465
|
+
for (let index = 0; index < entries.length; index++) {
|
|
466
|
+
const entry = entries[index]!;
|
|
467
|
+
|
|
468
|
+
const chargeRows = yield* mapAdapter(
|
|
469
|
+
database
|
|
470
|
+
.select({ total: count() })
|
|
471
|
+
.from(mapping.charge.table)
|
|
472
|
+
.where(
|
|
473
|
+
and(
|
|
474
|
+
eq(c.moduleId, moduleId),
|
|
475
|
+
eq(c.action, action),
|
|
476
|
+
eq(c.scopeKind, entry.kind),
|
|
477
|
+
eq(c.scopeKey, entry.key),
|
|
478
|
+
gte(c.occurredAt, mapping.encodeInstant(now - entry.windowMillis)),
|
|
479
|
+
),
|
|
480
|
+
),
|
|
481
|
+
);
|
|
482
|
+
|
|
483
|
+
const pendingWhere =
|
|
484
|
+
entry.kind === "action"
|
|
485
|
+
? and(eq(a.moduleId, moduleId), eq(a.action, action), eq(a.state, "pending"))
|
|
486
|
+
: entry.kind === "identifier"
|
|
487
|
+
? and(
|
|
488
|
+
eq(a.moduleId, moduleId),
|
|
489
|
+
eq(a.action, action),
|
|
490
|
+
eq(a.identifierNamespace, identifier.namespace),
|
|
491
|
+
eq(a.identifierValue, identifier.value),
|
|
492
|
+
eq(a.state, "pending"),
|
|
493
|
+
)
|
|
494
|
+
: and(
|
|
495
|
+
eq(a.moduleId, moduleId),
|
|
496
|
+
eq(a.action, action),
|
|
497
|
+
eq(a.subjectId, nativeSubjectId),
|
|
498
|
+
eq(a.state, "pending"),
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
const pendingRows = yield* mapAdapter(
|
|
502
|
+
database.select({ total: count() }).from(mapping.attempt.table).where(pendingWhere),
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
const admittedHere =
|
|
506
|
+
Number(chargeRows[0]?.total ?? 0) < entry.limit &&
|
|
507
|
+
Number(pendingRows[0]?.total ?? 0) < policy.maximumPending;
|
|
508
|
+
|
|
509
|
+
if (admittedHere) admitted.push(entry);
|
|
510
|
+
else if (index === 0) break;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return admitted;
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
const evidenceProofsJson = Schema.encodeSync(
|
|
517
|
+
Schema.fromJsonString(AuthenticationEvidence.fields.proofs),
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
const alternativesJson = Schema.encodeSync(
|
|
521
|
+
Schema.fromJsonString(AuthenticationRequirement.fields.alternatives),
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
const assuranceCondition = (
|
|
525
|
+
mapping: Mapping,
|
|
526
|
+
evidence: PasswordMutationInput["authorization"]["evidence"],
|
|
527
|
+
requirement: PasswordMutationInput["authorization"]["requirement"],
|
|
528
|
+
) => {
|
|
529
|
+
const proofs = evidenceProofsJson(evidence.proofs);
|
|
530
|
+
const fresh = sql`json_extract(proof.value, '$.verifiedAt') <= ${mapping.d1.engineNowMillis} and ${mapping.d1.engineNowMillis} - json_extract(proof.value, '$.verifiedAt') < ${requirement.maximumAgeMillis}`;
|
|
531
|
+
|
|
532
|
+
return sql`exists(
|
|
533
|
+
select 1 from json_each(${alternativesJson(requirement.alternatives)}) as alternative
|
|
534
|
+
where not exists(select 1 from json_each(${proofs}) as proof where json_extract(proof.value, '$.verifiedAt') > ${mapping.d1.engineNowMillis})
|
|
535
|
+
and not exists(select 1 from json_each(alternative.value, '$.factors') as factor where not exists(select 1 from json_each(${proofs}) as proof, json_each(proof.value, '$.factors') as held where ${fresh} and held.value = factor.value))
|
|
536
|
+
and (select count(distinct json_extract(proof.value, '$.credentialId')) from json_each(${proofs}) as proof where ${fresh}) >= json_extract(alternative.value, '$.minimumCredentials')
|
|
537
|
+
and exists(select 1 from json_each(${proofs}) as proof where ${fresh} and (json_extract(alternative.value, '$.userVerified') = 0 or json_extract(proof.value, '$.userVerified') = 1) and (json_extract(alternative.value, '$.phishingResistant') = 0 or json_extract(proof.value, '$.phishingResistant') = 1))
|
|
538
|
+
)`;
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>
|
|
542
|
+
left.namespace === right.namespace && left.value === right.value;
|
|
543
|
+
|
|
544
|
+
const sameSnapshot = (left: PasswordCredentialSnapshot, right: PasswordCredentialSnapshot) =>
|
|
545
|
+
left.moduleId === right.moduleId &&
|
|
546
|
+
left.revision.subjectId === right.revision.subjectId &&
|
|
547
|
+
left.revision.securityRevision === right.revision.securityRevision &&
|
|
548
|
+
left.credentialId === right.credentialId &&
|
|
549
|
+
left.credentialRevision === right.credentialRevision &&
|
|
550
|
+
left.verifierVersion === right.verifierVersion &&
|
|
551
|
+
left.normalization === right.normalization &&
|
|
552
|
+
left.identifierVerifiedAtMillis === right.identifierVerifiedAtMillis &&
|
|
553
|
+
left.revision.credentials.length === right.revision.credentials.length &&
|
|
554
|
+
left.revision.credentials.every((entry) =>
|
|
555
|
+
right.revision.credentials.some(
|
|
556
|
+
(other) => other.credentialId === entry.credentialId && other.revision === entry.revision,
|
|
557
|
+
),
|
|
558
|
+
) &&
|
|
559
|
+
left.identifierBindingRevision === right.identifierBindingRevision &&
|
|
560
|
+
sameIdentifier(left.identifier, right.identifier) &&
|
|
561
|
+
Redacted.value(left.verifier) === Redacted.value(right.verifier);
|
|
562
|
+
|
|
563
|
+
const evidenceSatisfiedAt = (
|
|
564
|
+
evidence: PasswordMutationInput["authorization"]["evidence"],
|
|
565
|
+
requirement: PasswordMutationInput["authorization"]["requirement"],
|
|
566
|
+
now: number,
|
|
567
|
+
) => {
|
|
568
|
+
if (evidence.proofs.length > 64 || evidence.revision.credentials.length > 64) return false;
|
|
569
|
+
const revisions = new Map<string, string>();
|
|
570
|
+
|
|
571
|
+
for (const revision of evidence.revision.credentials) {
|
|
572
|
+
if (revisions.has(revision.credentialId)) return false;
|
|
573
|
+
revisions.set(revision.credentialId, revision.revision);
|
|
574
|
+
}
|
|
575
|
+
if (evidence.proofs.some((proof) => !revisions.has(proof.credentialId))) return false;
|
|
576
|
+
if (evidence.proofs.some((proof) => now < DateTime.toEpochMillis(proof.verifiedAt))) return false;
|
|
577
|
+
|
|
578
|
+
const fresh = evidence.proofs.filter(
|
|
579
|
+
(proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < requirement.maximumAgeMillis,
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
const factors = new Set(fresh.flatMap((proof) => proof.factors));
|
|
583
|
+
const credentials = new Set(fresh.map((proof) => proof.credentialId));
|
|
584
|
+
|
|
585
|
+
return requirement.alternatives.some(
|
|
586
|
+
(alternative) =>
|
|
587
|
+
alternative.factors.every((factor) => factors.has(factor)) &&
|
|
588
|
+
credentials.size >= alternative.minimumCredentials &&
|
|
589
|
+
fresh.some(
|
|
590
|
+
(proof) =>
|
|
591
|
+
(!alternative.userVerified || proof.userVerified) &&
|
|
592
|
+
(!alternative.phishingResistant || proof.phishingResistant),
|
|
593
|
+
),
|
|
594
|
+
);
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
const snapshotMutationInput = Effect.fn("DrizzleD1Password.snapshotMutationInput")(function* (
|
|
598
|
+
input: PasswordMutationInput,
|
|
599
|
+
) {
|
|
600
|
+
const expectedRevision = snapshotPasswordRevision(input.expectedRevision);
|
|
601
|
+
|
|
602
|
+
const evidence = yield* snapshotAuthenticationEvidence(input.authorization.evidence).pipe(
|
|
603
|
+
Effect.mapError(unavailable),
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
const requirement = yield* snapshotPasswordRequirement(input.authorization.requirement);
|
|
607
|
+
|
|
608
|
+
const credential =
|
|
609
|
+
input.credential === undefined
|
|
610
|
+
? undefined
|
|
611
|
+
: yield* snapshotPasswordCredential(input.credential);
|
|
612
|
+
|
|
613
|
+
return Object.freeze({
|
|
614
|
+
...input,
|
|
615
|
+
expectedRevision,
|
|
616
|
+
replacement: Object.freeze({
|
|
617
|
+
verifier: Redacted.make(Redacted.value(input.replacement.verifier)),
|
|
618
|
+
normalization: input.replacement.normalization,
|
|
619
|
+
}),
|
|
620
|
+
invalidation: Object.freeze({ ...input.invalidation }),
|
|
621
|
+
...(credential === undefined ? {} : { credential }),
|
|
622
|
+
authorization: Object.freeze({
|
|
623
|
+
challenge: Object.freeze({
|
|
624
|
+
...input.authorization.challenge,
|
|
625
|
+
revision: snapshotPasswordRevision(input.authorization.challenge.revision),
|
|
626
|
+
}),
|
|
627
|
+
evidence,
|
|
628
|
+
requirement,
|
|
629
|
+
}),
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
const completionMatchesPassword = (
|
|
634
|
+
input: PasswordMutationInput & { readonly completion: ProofCompletionPlan },
|
|
635
|
+
) => {
|
|
636
|
+
const completion = input.completion.input;
|
|
637
|
+
const binding = completion.binding;
|
|
638
|
+
|
|
639
|
+
if (
|
|
640
|
+
completion.moduleId !== `${input.moduleId}/reset` ||
|
|
641
|
+
completion.purpose !== "password-reset" ||
|
|
642
|
+
binding._tag !== "Subject" ||
|
|
643
|
+
input.credential === undefined ||
|
|
644
|
+
binding.revision.subjectId !== input.expectedRevision.subjectId ||
|
|
645
|
+
binding.revision.securityRevision !== input.expectedRevision.securityRevision ||
|
|
646
|
+
!sameIdentifier(binding.identifier, input.credential.identifier)
|
|
647
|
+
)
|
|
648
|
+
return false;
|
|
649
|
+
|
|
650
|
+
const expected = [...input.expectedRevision.credentials].sort((left, right) =>
|
|
651
|
+
left.credentialId.localeCompare(right.credentialId),
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
const actual = [...binding.revision.credentials].sort((left, right) =>
|
|
655
|
+
left.credentialId.localeCompare(right.credentialId),
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
return (
|
|
659
|
+
expected.length === actual.length &&
|
|
660
|
+
expected.every(
|
|
661
|
+
(item, index) =>
|
|
662
|
+
item.credentialId === actual[index]!.credentialId &&
|
|
663
|
+
item.revision === actual[index]!.revision,
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const probeProofCompletion = Effect.fn("DrizzleD1.probeProofCompletion")(function* (
|
|
669
|
+
mapping: D1ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>,
|
|
670
|
+
input: ProofCompletionInput,
|
|
671
|
+
) {
|
|
672
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
673
|
+
|
|
674
|
+
const plan: ProofCompletionPlan = {
|
|
675
|
+
input,
|
|
676
|
+
prepare: (decision, journal, project) => journal.prepare(project(decision)),
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
const marker = `effect-auth-proof-guard:protected:${input.continuationId}`;
|
|
680
|
+
|
|
681
|
+
const once = coordinateCommit(
|
|
682
|
+
() =>
|
|
683
|
+
Effect.gen(function* () {
|
|
684
|
+
const compiled = yield* compileD1ProofCompletionPlan(
|
|
685
|
+
mapping,
|
|
686
|
+
plan,
|
|
687
|
+
{ statements: [], appliedCondition: sql`false` },
|
|
688
|
+
() => false,
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
if (compiled.statements.length === 0) return false;
|
|
692
|
+
yield* database.$client.batch(compiled.statements);
|
|
693
|
+
|
|
694
|
+
return false;
|
|
695
|
+
}),
|
|
696
|
+
{ mode: "batch" },
|
|
697
|
+
);
|
|
698
|
+
|
|
699
|
+
return yield* once.pipe(
|
|
700
|
+
Effect.as(false),
|
|
701
|
+
Effect.catchCause((cause) =>
|
|
702
|
+
isGuardFailure(cause, marker) ? Effect.succeed(true) : Effect.failCause(cause),
|
|
703
|
+
),
|
|
704
|
+
);
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
const identifierCurrentCondition = (
|
|
708
|
+
mapping: Mapping,
|
|
709
|
+
input: PasswordMutationInput,
|
|
710
|
+
nativeSubjectId: unknown,
|
|
711
|
+
nativeVerifiedAt: unknown,
|
|
712
|
+
) => {
|
|
713
|
+
if (input.credential === undefined) return sql`true`;
|
|
714
|
+
|
|
715
|
+
const ic = identifierColumns(mapping),
|
|
716
|
+
snapshot = input.credential;
|
|
717
|
+
|
|
718
|
+
return and(
|
|
719
|
+
mapping.identifier.d1CurrentCondition({ identifier: snapshot.identifier, nativeSubjectId }),
|
|
720
|
+
sql`exists(select 1 from ${mapping.identifier.table} where ${ic.namespace} = ${sql.param(snapshot.identifier.namespace, ic.namespace)} and ${ic.value} = ${sql.param(snapshot.identifier.value, ic.value)} and ${ic.subjectId} = ${sql.param(nativeSubjectId, ic.subjectId)} and ${ic.bindingRevision} = ${sql.param(snapshot.identifierBindingRevision, ic.bindingRevision)} and ${Predicate.isNullish(nativeVerifiedAt) ? sql`${ic.verifiedAt} is null` : sql`${ic.verifiedAt} = ${sql.param(nativeVerifiedAt, ic.verifiedAt)}`})`,
|
|
721
|
+
)!;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
const readAuthority = Effect.fn("DrizzleD1Password.readAuthority")(function* (
|
|
725
|
+
mapping: Mapping,
|
|
726
|
+
input: PasswordMutationInput,
|
|
727
|
+
action: PasswordAction,
|
|
728
|
+
) {
|
|
729
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
730
|
+
|
|
731
|
+
if (
|
|
732
|
+
input.authorization.evidence.proofs.length > 64 ||
|
|
733
|
+
input.authorization.evidence.revision.credentials.length > 64
|
|
734
|
+
)
|
|
735
|
+
return undefined;
|
|
736
|
+
|
|
737
|
+
const revisionIds = new Set(
|
|
738
|
+
input.authorization.evidence.revision.credentials.map((item) => item.credentialId),
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
if (
|
|
742
|
+
revisionIds.size !== input.authorization.evidence.revision.credentials.length ||
|
|
743
|
+
input.authorization.evidence.proofs.some((proof) => !revisionIds.has(proof.credentialId))
|
|
744
|
+
)
|
|
745
|
+
return undefined;
|
|
746
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.expectedRevision.subjectId);
|
|
747
|
+
const subject = (yield* readSubjectNative(mapping, nativeSubjectId))[0];
|
|
748
|
+
|
|
749
|
+
if (
|
|
750
|
+
subject === undefined ||
|
|
751
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
752
|
+
subject[mapping.subject.securityRevision] !== input.expectedRevision.securityRevision ||
|
|
753
|
+
input.authorization.challenge.moduleId !== input.moduleId ||
|
|
754
|
+
input.authorization.challenge.action !== action ||
|
|
755
|
+
input.authorization.challenge.commandId !== input.commandId ||
|
|
756
|
+
input.authorization.challenge.revision.subjectId !== input.expectedRevision.subjectId ||
|
|
757
|
+
input.authorization.challenge.revision.securityRevision !==
|
|
758
|
+
input.expectedRevision.securityRevision ||
|
|
759
|
+
input.authorization.evidence.revision.subjectId !== input.expectedRevision.subjectId ||
|
|
760
|
+
input.authorization.evidence.revision.securityRevision !==
|
|
761
|
+
input.expectedRevision.securityRevision ||
|
|
762
|
+
(input.authorization.evidence.flowId as string) !== (input.commandId as string) ||
|
|
763
|
+
input.authorization.evidence.bindingDigest !== input.authorization.challenge.bindingDigest ||
|
|
764
|
+
(action === "add-password" &&
|
|
765
|
+
(input.credential !== undefined ||
|
|
766
|
+
input.authorization.challenge.targetCredentialId !== undefined)) ||
|
|
767
|
+
input.expectedRevision.credentials.some(
|
|
768
|
+
(expected) =>
|
|
769
|
+
!input.authorization.evidence.revision.credentials.some(
|
|
770
|
+
(actual) =>
|
|
771
|
+
actual.credentialId === expected.credentialId && actual.revision === expected.revision,
|
|
772
|
+
),
|
|
773
|
+
)
|
|
774
|
+
)
|
|
775
|
+
return undefined;
|
|
776
|
+
let identifierCondition: SQL = sql`true`;
|
|
777
|
+
|
|
778
|
+
if (input.credential !== undefined) {
|
|
779
|
+
const identifier = (yield* readIdentifier(mapping, input.credential.identifier))[0];
|
|
780
|
+
|
|
781
|
+
if (
|
|
782
|
+
identifier === undefined ||
|
|
783
|
+
input.authorization.challenge.targetCredentialId !== input.credential.credentialId ||
|
|
784
|
+
!mapping.identifier.isCurrent(identifier) ||
|
|
785
|
+
!mapping.subjectId.equals(identifier[mapping.identifier.subjectId], nativeSubjectId) ||
|
|
786
|
+
identifier[mapping.identifier.bindingRevision] !== input.credential.identifierBindingRevision
|
|
787
|
+
)
|
|
788
|
+
return undefined;
|
|
789
|
+
const credential = (yield* readCredentialNative(mapping, input.moduleId, nativeSubjectId))[0];
|
|
790
|
+
|
|
791
|
+
if (credential === undefined) return undefined;
|
|
792
|
+
|
|
793
|
+
const snapshot = yield* mapping.credential.decode({
|
|
794
|
+
moduleId: input.moduleId,
|
|
795
|
+
subject,
|
|
796
|
+
identifier,
|
|
797
|
+
credential,
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
if (!sameSnapshot(snapshot, input.credential)) return undefined;
|
|
801
|
+
identifierCondition = identifierCurrentCondition(
|
|
802
|
+
mapping,
|
|
803
|
+
input,
|
|
804
|
+
nativeSubjectId,
|
|
805
|
+
identifier[mapping.identifier.verifiedAt],
|
|
806
|
+
);
|
|
807
|
+
const ic = identifierColumns(mapping);
|
|
808
|
+
|
|
809
|
+
identifierCondition = and(
|
|
810
|
+
identifierCondition,
|
|
811
|
+
sql`exists(select 1 from ${mapping.identifier.table} where ${ic.namespace} = ${sql.param(input.credential.identifier.namespace, ic.namespace)} and ${ic.value} = ${sql.param(input.credential.identifier.value, ic.value)} and ${ic.subjectId} = ${sql.param(nativeSubjectId, ic.subjectId)} and ${ic.bindingRevision} = ${sql.param(input.credential.identifierBindingRevision, ic.bindingRevision)})`,
|
|
812
|
+
)!;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
const expected = [
|
|
816
|
+
...new Map(
|
|
817
|
+
[
|
|
818
|
+
...input.expectedRevision.credentials,
|
|
819
|
+
...input.authorization.evidence.revision.credentials,
|
|
820
|
+
].map((item) => [item.credentialId, item]),
|
|
821
|
+
).values(),
|
|
822
|
+
].sort((left, right) => left.credentialId.localeCompare(right.credentialId));
|
|
823
|
+
|
|
824
|
+
const ac = authorityColumns(mapping);
|
|
825
|
+
|
|
826
|
+
const rows =
|
|
827
|
+
expected.length === 0
|
|
828
|
+
? []
|
|
829
|
+
: yield* database
|
|
830
|
+
.select()
|
|
831
|
+
.from(mapping.authorityCredential.table)
|
|
832
|
+
.where(
|
|
833
|
+
and(
|
|
834
|
+
eq(ac.subjectId, nativeSubjectId),
|
|
835
|
+
inArray(
|
|
836
|
+
ac.credentialId,
|
|
837
|
+
expected.map((item) => item.credentialId),
|
|
838
|
+
),
|
|
839
|
+
),
|
|
840
|
+
);
|
|
841
|
+
|
|
842
|
+
const sortedRows = [...rows].sort((left: any, right: any) =>
|
|
843
|
+
String(left[mapping.authorityCredential.credentialId]).localeCompare(
|
|
844
|
+
String(right[mapping.authorityCredential.credentialId]),
|
|
845
|
+
),
|
|
846
|
+
);
|
|
847
|
+
|
|
848
|
+
if (
|
|
849
|
+
sortedRows.length !== expected.length ||
|
|
850
|
+
sortedRows.some(
|
|
851
|
+
(row: any, index) =>
|
|
852
|
+
row[mapping.authorityCredential.credentialId] !== expected[index]!.credentialId ||
|
|
853
|
+
row[mapping.authorityCredential.revision] !== expected[index]!.revision ||
|
|
854
|
+
(mapping.authorityCredential.status !== undefined &&
|
|
855
|
+
mapping.authorityCredential.isActiveStatus?.(row[mapping.authorityCredential.status]) !==
|
|
856
|
+
true),
|
|
857
|
+
)
|
|
858
|
+
)
|
|
859
|
+
return undefined;
|
|
860
|
+
const requirement = yield* mapping.subject.decodeActionRequirement(subject, action);
|
|
861
|
+
const engineNow = yield* readEngineNowMillis(mapping);
|
|
862
|
+
|
|
863
|
+
if (
|
|
864
|
+
!evidenceSatisfiedAt(
|
|
865
|
+
input.authorization.evidence,
|
|
866
|
+
input.authorization.requirement,
|
|
867
|
+
engineNow,
|
|
868
|
+
) ||
|
|
869
|
+
!evidenceSatisfiedAt(input.authorization.evidence, requirement, engineNow)
|
|
870
|
+
)
|
|
871
|
+
return undefined;
|
|
872
|
+
if (
|
|
873
|
+
input.invalidation.existingSessions === "immediate" &&
|
|
874
|
+
mapping.sessionInvalidation !== "same-authority-immediate"
|
|
875
|
+
)
|
|
876
|
+
return undefined;
|
|
877
|
+
const s = subjectColumns(mapping);
|
|
878
|
+
|
|
879
|
+
const credentialConditions = expected.map(
|
|
880
|
+
(item) =>
|
|
881
|
+
sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(item.credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(item.revision, ac.revision)}${ac.status === undefined ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`,
|
|
882
|
+
);
|
|
883
|
+
|
|
884
|
+
return {
|
|
885
|
+
nativeSubjectId,
|
|
886
|
+
subject,
|
|
887
|
+
requirement,
|
|
888
|
+
identifierCondition,
|
|
889
|
+
condition: balancedD1And(
|
|
890
|
+
sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(nativeSubjectId, s.id)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)} and ${s.securityRevision} = ${sql.param(input.expectedRevision.securityRevision, s.securityRevision)})`,
|
|
891
|
+
identifierCondition,
|
|
892
|
+
...credentialConditions,
|
|
893
|
+
assuranceCondition(mapping, input.authorization.evidence, input.authorization.requirement),
|
|
894
|
+
assuranceCondition(mapping, input.authorization.evidence, requirement),
|
|
895
|
+
)!,
|
|
896
|
+
};
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
const commandAbsentCondition = (mapping: Mapping, moduleId: string, commandId: string) => {
|
|
900
|
+
const c = commandColumns(mapping);
|
|
901
|
+
|
|
902
|
+
return sql`not exists(select 1 from ${mapping.command.table} where ${c.moduleId} = ${sql.param(moduleId, c.moduleId)} and ${c.commandId} = ${sql.param(commandId, c.commandId)})`;
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
const credentialCurrentCondition = (
|
|
906
|
+
mapping: Mapping,
|
|
907
|
+
input: PasswordMutationInput,
|
|
908
|
+
nativeSubjectId: unknown,
|
|
909
|
+
) => {
|
|
910
|
+
const c = credentialColumns(mapping);
|
|
911
|
+
|
|
912
|
+
return input.credential === undefined
|
|
913
|
+
? sql`false`
|
|
914
|
+
: sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(input.credential.credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(input.credential.credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(input.credential.verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.credential.verifier), c.verifier)} and ${c.normalization} = ${sql.param(input.credential.normalization, c.normalization)})`;
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
const admittedSnapshotCondition = (
|
|
918
|
+
mapping: Mapping,
|
|
919
|
+
resolved: Resolved | undefined,
|
|
920
|
+
moduleId: string,
|
|
921
|
+
) => {
|
|
922
|
+
const snapshot = resolved?.snapshot;
|
|
923
|
+
|
|
924
|
+
if (snapshot === undefined || resolved === undefined) return sql`true`;
|
|
925
|
+
const s = subjectColumns(mapping);
|
|
926
|
+
const i = identifierColumns(mapping);
|
|
927
|
+
const c = credentialColumns(mapping);
|
|
928
|
+
const ac = authorityColumns(mapping);
|
|
929
|
+
|
|
930
|
+
return and(
|
|
931
|
+
sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(resolved.nativeSubjectId, s.id)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)} and ${s.securityRevision} = ${sql.param(snapshot.revision.securityRevision, s.securityRevision)})`,
|
|
932
|
+
mapping.identifier.d1CurrentCondition({
|
|
933
|
+
identifier: snapshot.identifier,
|
|
934
|
+
nativeSubjectId: resolved.nativeSubjectId,
|
|
935
|
+
}),
|
|
936
|
+
sql`exists(select 1 from ${mapping.identifier.table} where ${i.namespace} = ${sql.param(snapshot.identifier.namespace, i.namespace)} and ${i.value} = ${sql.param(snapshot.identifier.value, i.value)} and ${i.subjectId} = ${sql.param(resolved.nativeSubjectId, i.subjectId)} and ${i.bindingRevision} = ${sql.param(snapshot.identifierBindingRevision, i.bindingRevision)})`,
|
|
937
|
+
sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(resolved.nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(snapshot.credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(snapshot.credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(snapshot.verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(snapshot.verifier), c.verifier)} and ${c.normalization} = ${sql.param(snapshot.normalization, c.normalization)})`,
|
|
938
|
+
...snapshot.revision.credentials.map(
|
|
939
|
+
(item) =>
|
|
940
|
+
sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(resolved.nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(item.credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(item.revision, ac.revision)}${ac.status === undefined ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`,
|
|
941
|
+
),
|
|
942
|
+
)!;
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
const mutationStatements = Effect.fn(function* (
|
|
946
|
+
mapping: Mapping,
|
|
947
|
+
input: PasswordMutationInput,
|
|
948
|
+
nativeSubjectId: unknown,
|
|
949
|
+
revisions: {
|
|
950
|
+
readonly credentialRevision: SecurityRevision;
|
|
951
|
+
readonly verifierVersion: SecurityRevision;
|
|
952
|
+
readonly nextSecurityRevision: SecurityRevision;
|
|
953
|
+
},
|
|
954
|
+
now: number,
|
|
955
|
+
) {
|
|
956
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
957
|
+
const c = credentialColumns(mapping);
|
|
958
|
+
const s = subjectColumns(mapping);
|
|
959
|
+
const ac = authorityColumns(mapping);
|
|
960
|
+
|
|
961
|
+
return [
|
|
962
|
+
yield* statement(
|
|
963
|
+
database
|
|
964
|
+
.update(mapping.credential.table)
|
|
965
|
+
.set(
|
|
966
|
+
mapping.credential.encodeReplacement({
|
|
967
|
+
replacement: input.replacement,
|
|
968
|
+
credentialRevision: revisions.credentialRevision,
|
|
969
|
+
verifierVersion: revisions.verifierVersion,
|
|
970
|
+
}),
|
|
971
|
+
)
|
|
972
|
+
.where(
|
|
973
|
+
and(
|
|
974
|
+
eq(c.moduleId, input.moduleId),
|
|
975
|
+
eq(c.subjectId, nativeSubjectId),
|
|
976
|
+
eq(c.credentialId, input.credential!.credentialId),
|
|
977
|
+
eq(c.credentialRevision, input.credential!.credentialRevision),
|
|
978
|
+
eq(c.verifierVersion, input.credential!.verifierVersion),
|
|
979
|
+
eq(c.verifier, Redacted.value(input.credential!.verifier)),
|
|
980
|
+
eq(c.normalization, input.credential!.normalization),
|
|
981
|
+
),
|
|
982
|
+
),
|
|
983
|
+
),
|
|
984
|
+
yield* statement(
|
|
985
|
+
database
|
|
986
|
+
.update(mapping.subject.table)
|
|
987
|
+
.set(updateValues([[mapping.subject.securityRevision, revisions.nextSecurityRevision]]))
|
|
988
|
+
.where(
|
|
989
|
+
and(
|
|
990
|
+
eq(s.id, nativeSubjectId),
|
|
991
|
+
eq(s.securityRevision, input.expectedRevision.securityRevision),
|
|
992
|
+
),
|
|
993
|
+
),
|
|
994
|
+
),
|
|
995
|
+
yield* statement(
|
|
996
|
+
database
|
|
997
|
+
.update(mapping.authorityCredential.table)
|
|
998
|
+
.set(mapping.authorityCredential.encodeRevision(revisions.credentialRevision))
|
|
999
|
+
.where(
|
|
1000
|
+
and(
|
|
1001
|
+
eq(ac.subjectId, nativeSubjectId),
|
|
1002
|
+
eq(ac.credentialId, input.credential!.credentialId),
|
|
1003
|
+
eq(ac.revision, input.credential!.credentialRevision),
|
|
1004
|
+
),
|
|
1005
|
+
),
|
|
1006
|
+
),
|
|
1007
|
+
yield* statement(
|
|
1008
|
+
database.insert(mapping.command.table).values(
|
|
1009
|
+
mapping.command.encodeInsert({
|
|
1010
|
+
moduleId: input.moduleId,
|
|
1011
|
+
commandId: input.commandId,
|
|
1012
|
+
action: input.authorization.challenge.action,
|
|
1013
|
+
bindingDigest: input.authorization.challenge.bindingDigest,
|
|
1014
|
+
decision: "changed",
|
|
1015
|
+
retentionUntilMillis: now + mapping.commandRetentionMillis,
|
|
1016
|
+
}),
|
|
1017
|
+
),
|
|
1018
|
+
),
|
|
1019
|
+
];
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
const replacementApplied = (
|
|
1023
|
+
mapping: Mapping,
|
|
1024
|
+
input: PasswordMutationInput,
|
|
1025
|
+
nativeSubjectId: unknown,
|
|
1026
|
+
revisions: {
|
|
1027
|
+
readonly credentialRevision: SecurityRevision;
|
|
1028
|
+
readonly verifierVersion: SecurityRevision;
|
|
1029
|
+
readonly nextSecurityRevision: SecurityRevision;
|
|
1030
|
+
},
|
|
1031
|
+
now: number,
|
|
1032
|
+
identifierCondition: SQL,
|
|
1033
|
+
) => {
|
|
1034
|
+
const c = credentialColumns(mapping);
|
|
1035
|
+
const s = subjectColumns(mapping);
|
|
1036
|
+
const ac = authorityColumns(mapping);
|
|
1037
|
+
const mc = commandColumns(mapping);
|
|
1038
|
+
|
|
1039
|
+
return and(
|
|
1040
|
+
sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(input.credential!.credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(revisions.credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(revisions.verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.replacement.verifier), c.verifier)} and ${c.normalization} = ${sql.param(input.replacement.normalization, c.normalization)})`,
|
|
1041
|
+
sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(nativeSubjectId, s.id)} and ${s.securityRevision} = ${sql.param(revisions.nextSecurityRevision, s.securityRevision)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)})`,
|
|
1042
|
+
sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(input.credential!.credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(revisions.credentialRevision, ac.revision)}${ac.status === undefined ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`,
|
|
1043
|
+
sql`exists(select 1 from ${mapping.command.table} where ${mc.moduleId} = ${sql.param(input.moduleId, mc.moduleId)} and ${mc.commandId} = ${sql.param(input.commandId, mc.commandId)} and ${mc.bindingDigest} = ${sql.param(input.authorization.challenge.bindingDigest, mc.bindingDigest)} and ${mc.action} = ${sql.param(input.authorization.challenge.action, mc.action)} and ${mc.decision} = ${sql.param("changed", mc.decision)} and ${mc.retentionUntil} = ${sql.param(mapping.encodeInstant(now + mapping.commandRetentionMillis), mc.retentionUntil)})`,
|
|
1044
|
+
identifierCondition,
|
|
1045
|
+
sql`true`,
|
|
1046
|
+
)!;
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
const compileAddMutation = Effect.fn("DrizzleD1Password.compileAddMutation")(function* (
|
|
1050
|
+
mapping: Mapping,
|
|
1051
|
+
input: PasswordMutationInput,
|
|
1052
|
+
revisions: {
|
|
1053
|
+
readonly credentialId: string;
|
|
1054
|
+
readonly credentialRevision: SecurityRevision;
|
|
1055
|
+
readonly verifierVersion: SecurityRevision;
|
|
1056
|
+
readonly nextSecurityRevision: SecurityRevision;
|
|
1057
|
+
},
|
|
1058
|
+
) {
|
|
1059
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
1060
|
+
|
|
1061
|
+
const { credentialId, credentialRevision, verifierVersion, nextSecurityRevision } = revisions;
|
|
1062
|
+
|
|
1063
|
+
const authority = yield* readAuthority(mapping, input, "add-password");
|
|
1064
|
+
|
|
1065
|
+
if (authority === undefined) return undefined;
|
|
1066
|
+
const now = yield* readEngineNowMillis(mapping);
|
|
1067
|
+
const c = credentialColumns(mapping);
|
|
1068
|
+
const s = subjectColumns(mapping);
|
|
1069
|
+
const ac = authorityColumns(mapping);
|
|
1070
|
+
const mc = commandColumns(mapping);
|
|
1071
|
+
const marker = `effect-auth-password-guard:add:${input.commandId}`;
|
|
1072
|
+
const absent = sql`not exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(authority.nativeSubjectId, c.subjectId)})`;
|
|
1073
|
+
|
|
1074
|
+
const guard = and(
|
|
1075
|
+
authority.condition,
|
|
1076
|
+
absent,
|
|
1077
|
+
commandAbsentCondition(mapping, input.moduleId, input.commandId),
|
|
1078
|
+
)!;
|
|
1079
|
+
|
|
1080
|
+
const appliedCondition = and(
|
|
1081
|
+
sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(authority.nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.replacement.verifier), c.verifier)} and ${c.normalization} = ${sql.param(input.replacement.normalization, c.normalization)})`,
|
|
1082
|
+
sql`exists(select 1 from ${mapping.authorityCredential.table} where ${ac.subjectId} = ${sql.param(authority.nativeSubjectId, ac.subjectId)} and ${ac.credentialId} = ${sql.param(credentialId, ac.credentialId)} and ${ac.revision} = ${sql.param(credentialRevision, ac.revision)}${ac.status === undefined ? sql`` : sql` and ${ac.status} = ${sql.param(mapping.authorityCredential.d1ActiveStatusValue, ac.status)}`})`,
|
|
1083
|
+
sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(authority.nativeSubjectId, s.id)} and ${s.securityRevision} = ${sql.param(nextSecurityRevision, s.securityRevision)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)})`,
|
|
1084
|
+
sql`exists(select 1 from ${mapping.command.table} where ${mc.moduleId} = ${sql.param(input.moduleId, mc.moduleId)} and ${mc.commandId} = ${sql.param(input.commandId, mc.commandId)} and ${mc.bindingDigest} = ${sql.param(input.authorization.challenge.bindingDigest, mc.bindingDigest)} and ${mc.action} = ${sql.param("add-password", mc.action)} and ${mc.decision} = ${sql.param("changed", mc.decision)} and ${mc.retentionUntil} = ${sql.param(mapping.encodeInstant(now + mapping.commandRetentionMillis), mc.retentionUntil)})`,
|
|
1085
|
+
)!;
|
|
1086
|
+
|
|
1087
|
+
const statements: Statement<any>[] = [
|
|
1088
|
+
yield* assertion(guard, marker),
|
|
1089
|
+
yield* statement(
|
|
1090
|
+
database.insert(mapping.credential.table).values(
|
|
1091
|
+
mapping.credential.encodeInsert({
|
|
1092
|
+
moduleId: input.moduleId,
|
|
1093
|
+
subjectId: authority.nativeSubjectId,
|
|
1094
|
+
credentialId,
|
|
1095
|
+
credentialRevision,
|
|
1096
|
+
verifierVersion,
|
|
1097
|
+
replacement: input.replacement,
|
|
1098
|
+
}),
|
|
1099
|
+
),
|
|
1100
|
+
),
|
|
1101
|
+
yield* statement(
|
|
1102
|
+
database.insert(mapping.authorityCredential.table).values(
|
|
1103
|
+
mapping.authorityCredential.encodeInsert({
|
|
1104
|
+
subjectId: authority.nativeSubjectId,
|
|
1105
|
+
credentialId,
|
|
1106
|
+
revision: credentialRevision,
|
|
1107
|
+
}),
|
|
1108
|
+
),
|
|
1109
|
+
),
|
|
1110
|
+
yield* statement(
|
|
1111
|
+
database
|
|
1112
|
+
.update(mapping.subject.table)
|
|
1113
|
+
.set(updateValues([[mapping.subject.securityRevision, nextSecurityRevision]]))
|
|
1114
|
+
.where(
|
|
1115
|
+
and(
|
|
1116
|
+
eq(s.id, authority.nativeSubjectId),
|
|
1117
|
+
eq(s.securityRevision, input.expectedRevision.securityRevision),
|
|
1118
|
+
),
|
|
1119
|
+
),
|
|
1120
|
+
),
|
|
1121
|
+
yield* statement(
|
|
1122
|
+
database.insert(mapping.command.table).values(
|
|
1123
|
+
mapping.command.encodeInsert({
|
|
1124
|
+
moduleId: input.moduleId,
|
|
1125
|
+
commandId: input.commandId,
|
|
1126
|
+
action: "add-password",
|
|
1127
|
+
bindingDigest: input.authorization.challenge.bindingDigest,
|
|
1128
|
+
decision: "changed",
|
|
1129
|
+
retentionUntilMillis: now + mapping.commandRetentionMillis,
|
|
1130
|
+
}),
|
|
1131
|
+
),
|
|
1132
|
+
),
|
|
1133
|
+
yield* assertion(appliedCondition, marker),
|
|
1134
|
+
];
|
|
1135
|
+
|
|
1136
|
+
return {
|
|
1137
|
+
statements,
|
|
1138
|
+
appliedCondition,
|
|
1139
|
+
retryable: (cause: unknown) => isGuardFailure(cause, marker),
|
|
1140
|
+
};
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
const makePasswordPlans = (
|
|
1144
|
+
mapping: Mapping,
|
|
1145
|
+
proofMapping?: D1ProofPersistenceMapping<
|
|
1146
|
+
any,
|
|
1147
|
+
any,
|
|
1148
|
+
any,
|
|
1149
|
+
any,
|
|
1150
|
+
any,
|
|
1151
|
+
any,
|
|
1152
|
+
any,
|
|
1153
|
+
any,
|
|
1154
|
+
any,
|
|
1155
|
+
any,
|
|
1156
|
+
any,
|
|
1157
|
+
any
|
|
1158
|
+
>,
|
|
1159
|
+
) => {
|
|
1160
|
+
const run = <A, E, R>(plan: Effect.Effect<Planned<A>, E, R>) =>
|
|
1161
|
+
Effect.gen(function* () {
|
|
1162
|
+
if (!validConstraints(mapping)) return yield* unavailable();
|
|
1163
|
+
|
|
1164
|
+
return yield* plan;
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
return {
|
|
1168
|
+
admitAttempt: <A>(
|
|
1169
|
+
input: Parameters<PasswordPersistence["Service"]["admitAttempt"]>[0],
|
|
1170
|
+
prepare: PlanPrepare<PasswordPersistence["Service"]["admitAttempt"], A>,
|
|
1171
|
+
) =>
|
|
1172
|
+
Effect.gen(function* () {
|
|
1173
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
1174
|
+
|
|
1175
|
+
const attemptId = yield* allocate(mapping.allocateAttemptId, mapping.allocateAttemptIdSync);
|
|
1176
|
+
|
|
1177
|
+
return yield* run(
|
|
1178
|
+
Effect.gen(function* () {
|
|
1179
|
+
const journal = yield* CurrentCommitJournal;
|
|
1180
|
+
|
|
1181
|
+
const now = yield* readEngineNowMillis(mapping);
|
|
1182
|
+
|
|
1183
|
+
const resolved = yield* resolveCredential(
|
|
1184
|
+
mapping,
|
|
1185
|
+
input.moduleId,
|
|
1186
|
+
input.identifier,
|
|
1187
|
+
input.subjectId,
|
|
1188
|
+
);
|
|
1189
|
+
|
|
1190
|
+
const keys = mapping.scopeKeys({
|
|
1191
|
+
moduleId: input.moduleId,
|
|
1192
|
+
action: input.action,
|
|
1193
|
+
identifier: input.identifier,
|
|
1194
|
+
...(resolved?.snapshot === undefined
|
|
1195
|
+
? {}
|
|
1196
|
+
: { subjectId: resolved.snapshot.revision.subjectId }),
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
const scopes = scopeEntries(keys, input.policy);
|
|
1200
|
+
|
|
1201
|
+
const admitted = yield* readScopeAdmission(
|
|
1202
|
+
mapping,
|
|
1203
|
+
input.moduleId,
|
|
1204
|
+
input.action,
|
|
1205
|
+
scopes,
|
|
1206
|
+
input.policy,
|
|
1207
|
+
input.identifier,
|
|
1208
|
+
resolved?.nativeSubjectId,
|
|
1209
|
+
now,
|
|
1210
|
+
);
|
|
1211
|
+
|
|
1212
|
+
const allAdmitted = admitted.length === scopes.length;
|
|
1213
|
+
const considered = admitted.length === 0 ? scopes.slice(0, 1) : scopes;
|
|
1214
|
+
|
|
1215
|
+
const receipt = prepare(
|
|
1216
|
+
allAdmitted
|
|
1217
|
+
? {
|
|
1218
|
+
_tag: "Admitted" as const,
|
|
1219
|
+
attemptId,
|
|
1220
|
+
...(resolved?.snapshot === undefined ? {} : { credential: resolved.snapshot }),
|
|
1221
|
+
}
|
|
1222
|
+
: { _tag: "Denied" as const },
|
|
1223
|
+
journal,
|
|
1224
|
+
);
|
|
1225
|
+
|
|
1226
|
+
const marker = `effect-auth-password-guard:admit:${attemptId}`;
|
|
1227
|
+
const statements: Statement<any>[] = [];
|
|
1228
|
+
|
|
1229
|
+
for (const entry of considered) {
|
|
1230
|
+
statements.push(
|
|
1231
|
+
yield* statement(
|
|
1232
|
+
database
|
|
1233
|
+
.insert(mapping.rateScope.table)
|
|
1234
|
+
.values(
|
|
1235
|
+
mapping.rateScope.encodeInsert({
|
|
1236
|
+
moduleId: input.moduleId,
|
|
1237
|
+
action: input.action,
|
|
1238
|
+
scopeKind: entry.kind,
|
|
1239
|
+
scopeKey: entry.key,
|
|
1240
|
+
}),
|
|
1241
|
+
)
|
|
1242
|
+
.onConflictDoNothing(),
|
|
1243
|
+
),
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
const conditions = considered.map((entry) => {
|
|
1248
|
+
const condition = scopeAdmissionCondition(
|
|
1249
|
+
mapping,
|
|
1250
|
+
input.moduleId,
|
|
1251
|
+
input.action,
|
|
1252
|
+
entry,
|
|
1253
|
+
input.policy,
|
|
1254
|
+
input.identifier,
|
|
1255
|
+
resolved?.nativeSubjectId,
|
|
1256
|
+
);
|
|
1257
|
+
|
|
1258
|
+
return admitted.includes(entry) ? condition : sql`not (${condition})`;
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
statements.push(
|
|
1262
|
+
yield* assertion(
|
|
1263
|
+
and(
|
|
1264
|
+
...conditions,
|
|
1265
|
+
...(allAdmitted
|
|
1266
|
+
? [admittedSnapshotCondition(mapping, resolved, input.moduleId)]
|
|
1267
|
+
: []),
|
|
1268
|
+
)!,
|
|
1269
|
+
marker,
|
|
1270
|
+
),
|
|
1271
|
+
);
|
|
1272
|
+
for (const entry of admitted)
|
|
1273
|
+
statements.push(
|
|
1274
|
+
yield* statement(
|
|
1275
|
+
database.insert(mapping.charge.table).values(
|
|
1276
|
+
driverValues(
|
|
1277
|
+
mapping.charge.encodeInsert({
|
|
1278
|
+
moduleId: input.moduleId,
|
|
1279
|
+
action: input.action,
|
|
1280
|
+
scopeKind: entry.kind,
|
|
1281
|
+
scopeKey: entry.key,
|
|
1282
|
+
attemptId,
|
|
1283
|
+
occurredAtMillis: now,
|
|
1284
|
+
retentionUntilMillis: now + entry.windowMillis,
|
|
1285
|
+
}),
|
|
1286
|
+
[
|
|
1287
|
+
[mapping.charge.occurredAt, mapping.d1.engineNow],
|
|
1288
|
+
[
|
|
1289
|
+
mapping.charge.retentionUntil,
|
|
1290
|
+
mapping.d1.engineInstantPlus(entry.windowMillis),
|
|
1291
|
+
],
|
|
1292
|
+
],
|
|
1293
|
+
),
|
|
1294
|
+
),
|
|
1295
|
+
),
|
|
1296
|
+
);
|
|
1297
|
+
if (allAdmitted) {
|
|
1298
|
+
const snapshot = resolved?.snapshot;
|
|
1299
|
+
|
|
1300
|
+
const record: PasswordAttemptRecord = {
|
|
1301
|
+
moduleId: input.moduleId,
|
|
1302
|
+
action: input.action,
|
|
1303
|
+
attemptId,
|
|
1304
|
+
identifier: input.identifier,
|
|
1305
|
+
...(snapshot === undefined
|
|
1306
|
+
? {}
|
|
1307
|
+
: {
|
|
1308
|
+
subjectId: snapshot.revision.subjectId,
|
|
1309
|
+
credentialId: snapshot.credentialId,
|
|
1310
|
+
securityRevision: snapshot.revision.securityRevision,
|
|
1311
|
+
credentialRevision: snapshot.credentialRevision,
|
|
1312
|
+
verifierVersion: snapshot.verifierVersion,
|
|
1313
|
+
identifierBindingRevision: snapshot.identifierBindingRevision,
|
|
1314
|
+
}),
|
|
1315
|
+
admittedAtMillis: now,
|
|
1316
|
+
deadlineMillis: now + input.policy.attemptLifetimeMillis,
|
|
1317
|
+
retentionUntilMillis: Math.max(
|
|
1318
|
+
now + input.policy.attemptLifetimeMillis,
|
|
1319
|
+
...scopes.map((entry) => now + entry.windowMillis),
|
|
1320
|
+
),
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
statements.push(
|
|
1324
|
+
yield* statement(
|
|
1325
|
+
database.insert(mapping.attempt.table).values(
|
|
1326
|
+
driverValues(
|
|
1327
|
+
mapping.attempt.encodeInsert(record, {
|
|
1328
|
+
...(resolved?.nativeSubjectId === undefined
|
|
1329
|
+
? {}
|
|
1330
|
+
: { nativeSubjectId: resolved.nativeSubjectId }),
|
|
1331
|
+
state: "pending",
|
|
1332
|
+
}),
|
|
1333
|
+
[
|
|
1334
|
+
[mapping.attempt.admittedAt, mapping.d1.engineNow],
|
|
1335
|
+
[
|
|
1336
|
+
mapping.attempt.deadline,
|
|
1337
|
+
mapping.d1.engineInstantPlus(input.policy.attemptLifetimeMillis),
|
|
1338
|
+
],
|
|
1339
|
+
[
|
|
1340
|
+
mapping.attempt.retentionUntil,
|
|
1341
|
+
mapping.d1.engineInstantPlus(
|
|
1342
|
+
Math.max(
|
|
1343
|
+
input.policy.attemptLifetimeMillis,
|
|
1344
|
+
...scopes.map((entry) => entry.windowMillis),
|
|
1345
|
+
),
|
|
1346
|
+
),
|
|
1347
|
+
],
|
|
1348
|
+
],
|
|
1349
|
+
),
|
|
1350
|
+
),
|
|
1351
|
+
),
|
|
1352
|
+
);
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
return {
|
|
1356
|
+
receipt,
|
|
1357
|
+
statements,
|
|
1358
|
+
retryable: (cause: unknown) => isGuardFailure(cause, marker),
|
|
1359
|
+
};
|
|
1360
|
+
}),
|
|
1361
|
+
);
|
|
1362
|
+
}),
|
|
1363
|
+
settleAttempt: <A>(
|
|
1364
|
+
uncaptured: Parameters<PasswordPersistence["Service"]["settleAttempt"]>[0],
|
|
1365
|
+
prepare: PlanPrepare<PasswordPersistence["Service"]["settleAttempt"], A>,
|
|
1366
|
+
) =>
|
|
1367
|
+
Effect.gen(function* () {
|
|
1368
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
1369
|
+
|
|
1370
|
+
const captured =
|
|
1371
|
+
uncaptured.captured === undefined
|
|
1372
|
+
? undefined
|
|
1373
|
+
: yield* snapshotPasswordCredential(uncaptured.captured);
|
|
1374
|
+
|
|
1375
|
+
const input = { ...uncaptured, ...(captured === undefined ? {} : { captured }) };
|
|
1376
|
+
|
|
1377
|
+
return yield* run(
|
|
1378
|
+
Effect.gen(function* () {
|
|
1379
|
+
const journal = yield* CurrentCommitJournal;
|
|
1380
|
+
|
|
1381
|
+
const a = attemptColumns(mapping);
|
|
1382
|
+
|
|
1383
|
+
const rows = yield* database
|
|
1384
|
+
.select()
|
|
1385
|
+
.from(mapping.attempt.table)
|
|
1386
|
+
.where(and(eq(a.moduleId, input.moduleId), eq(a.attemptId, input.attemptId)))
|
|
1387
|
+
.limit(1);
|
|
1388
|
+
|
|
1389
|
+
const row = rows[0];
|
|
1390
|
+
const engineNow = yield* readEngineNowMillis(mapping);
|
|
1391
|
+
|
|
1392
|
+
const deadline =
|
|
1393
|
+
row === undefined
|
|
1394
|
+
? undefined
|
|
1395
|
+
: yield* mapping.decodeInstant(row[mapping.attempt.deadline]);
|
|
1396
|
+
|
|
1397
|
+
let resolved: Resolved | undefined;
|
|
1398
|
+
let verified = false;
|
|
1399
|
+
|
|
1400
|
+
if (
|
|
1401
|
+
row !== undefined &&
|
|
1402
|
+
row[mapping.attempt.state] === "pending" &&
|
|
1403
|
+
input.outcome === "verified" &&
|
|
1404
|
+
input.captured !== undefined &&
|
|
1405
|
+
deadline !== undefined &&
|
|
1406
|
+
deadline > engineNow
|
|
1407
|
+
) {
|
|
1408
|
+
resolved = yield* resolveCredential(
|
|
1409
|
+
mapping,
|
|
1410
|
+
input.moduleId,
|
|
1411
|
+
input.captured.identifier,
|
|
1412
|
+
input.captured.revision.subjectId,
|
|
1413
|
+
);
|
|
1414
|
+
verified =
|
|
1415
|
+
input.captured.moduleId === input.moduleId &&
|
|
1416
|
+
resolved?.snapshot !== undefined &&
|
|
1417
|
+
sameSnapshot(resolved.snapshot, input.captured) &&
|
|
1418
|
+
mapping.subjectId.equals(
|
|
1419
|
+
row[mapping.attempt.subjectId],
|
|
1420
|
+
resolved.nativeSubjectId,
|
|
1421
|
+
) &&
|
|
1422
|
+
row[mapping.attempt.identifierNamespace] === input.captured.identifier.namespace &&
|
|
1423
|
+
row[mapping.attempt.identifierValue] === input.captured.identifier.value &&
|
|
1424
|
+
row[mapping.attempt.credentialId] === input.captured.credentialId &&
|
|
1425
|
+
row[mapping.attempt.securityRevision] ===
|
|
1426
|
+
input.captured.revision.securityRevision &&
|
|
1427
|
+
row[mapping.attempt.credentialRevision] === input.captured.credentialRevision &&
|
|
1428
|
+
row[mapping.attempt.verifierVersion] === input.captured.verifierVersion &&
|
|
1429
|
+
row[mapping.attempt.identifierBindingRevision] ===
|
|
1430
|
+
input.captured.identifierBindingRevision;
|
|
1431
|
+
}
|
|
1432
|
+
const decision: PasswordAttemptDecision = verified ? "verified" : "rejected";
|
|
1433
|
+
const receipt = prepare(decision, journal);
|
|
1434
|
+
|
|
1435
|
+
if (row === undefined || row[mapping.attempt.state] !== "pending")
|
|
1436
|
+
return { receipt, statements: [] };
|
|
1437
|
+
const marker = `effect-auth-password-guard:settle:${input.attemptId}`;
|
|
1438
|
+
|
|
1439
|
+
const base = and(
|
|
1440
|
+
eq(a.moduleId, input.moduleId),
|
|
1441
|
+
eq(a.attemptId, input.attemptId),
|
|
1442
|
+
eq(a.state, "pending"),
|
|
1443
|
+
)!;
|
|
1444
|
+
|
|
1445
|
+
const condition = verified
|
|
1446
|
+
? and(base, sql`${a.deadline} > ${mapping.d1.engineNow}`)!
|
|
1447
|
+
: base;
|
|
1448
|
+
|
|
1449
|
+
const statements: Statement<any>[] = [
|
|
1450
|
+
yield* assertion(
|
|
1451
|
+
sql`exists(select 1 from ${mapping.attempt.table} where ${condition})`,
|
|
1452
|
+
marker,
|
|
1453
|
+
),
|
|
1454
|
+
yield* statement(
|
|
1455
|
+
database
|
|
1456
|
+
.update(mapping.attempt.table)
|
|
1457
|
+
.set(updateValues([[mapping.attempt.state, decision]]))
|
|
1458
|
+
.where(condition),
|
|
1459
|
+
),
|
|
1460
|
+
];
|
|
1461
|
+
|
|
1462
|
+
if (verified && resolved?.snapshot !== undefined) {
|
|
1463
|
+
const captured = input.captured!;
|
|
1464
|
+
const s = subjectColumns(mapping);
|
|
1465
|
+
const i = identifierColumns(mapping);
|
|
1466
|
+
const c = credentialColumns(mapping);
|
|
1467
|
+
|
|
1468
|
+
const authority = and(
|
|
1469
|
+
sql`exists(select 1 from ${mapping.subject.table} where ${s.id} = ${sql.param(resolved.nativeSubjectId, s.id)} and ${s.status} = ${sql.param(mapping.subject.d1ActiveStatusValue, s.status)} and ${s.securityRevision} = ${sql.param(input.captured!.revision.securityRevision, s.securityRevision)})`,
|
|
1470
|
+
mapping.identifier.d1CurrentCondition({
|
|
1471
|
+
identifier: input.captured!.identifier,
|
|
1472
|
+
nativeSubjectId: resolved.nativeSubjectId,
|
|
1473
|
+
}),
|
|
1474
|
+
sql`exists(select 1 from ${mapping.credential.table} where ${c.moduleId} = ${sql.param(input.moduleId, c.moduleId)} and ${c.subjectId} = ${sql.param(resolved.nativeSubjectId, c.subjectId)} and ${c.credentialId} = ${sql.param(input.captured!.credentialId, c.credentialId)} and ${c.credentialRevision} = ${sql.param(input.captured!.credentialRevision, c.credentialRevision)} and ${c.verifierVersion} = ${sql.param(input.captured!.verifierVersion, c.verifierVersion)} and ${c.verifier} = ${sql.param(Redacted.value(input.captured!.verifier), c.verifier)})`,
|
|
1475
|
+
sql`exists(select 1 from ${mapping.identifier.table} where ${i.namespace} = ${sql.param(input.captured!.identifier.namespace, i.namespace)} and ${i.value} = ${sql.param(input.captured!.identifier.value, i.value)} and ${i.subjectId} = ${sql.param(resolved.nativeSubjectId, i.subjectId)} and ${i.bindingRevision} = ${sql.param(input.captured!.identifierBindingRevision, i.bindingRevision)})`,
|
|
1476
|
+
)!;
|
|
1477
|
+
|
|
1478
|
+
statements.splice(1, 0, yield* assertion(authority, marker));
|
|
1479
|
+
if (
|
|
1480
|
+
input.rehash !== undefined &&
|
|
1481
|
+
input.rehash.expectedVersion === captured.verifierVersion &&
|
|
1482
|
+
Redacted.value(input.rehash.expectedVerifier) === Redacted.value(captured.verifier)
|
|
1483
|
+
) {
|
|
1484
|
+
const nextVersion = yield* allocate(
|
|
1485
|
+
mapping.allocateRevision,
|
|
1486
|
+
mapping.allocateRevisionSync,
|
|
1487
|
+
);
|
|
1488
|
+
|
|
1489
|
+
statements.push(
|
|
1490
|
+
yield* statement(
|
|
1491
|
+
database
|
|
1492
|
+
.update(mapping.credential.table)
|
|
1493
|
+
.set(
|
|
1494
|
+
mapping.credential.encodeVerifier(input.rehash.nextVerifier, nextVersion),
|
|
1495
|
+
)
|
|
1496
|
+
.where(
|
|
1497
|
+
and(
|
|
1498
|
+
eq(c.moduleId, input.moduleId),
|
|
1499
|
+
eq(c.subjectId, resolved.nativeSubjectId),
|
|
1500
|
+
eq(c.credentialId, captured.credentialId),
|
|
1501
|
+
eq(c.credentialRevision, captured.credentialRevision),
|
|
1502
|
+
eq(c.verifierVersion, input.rehash.expectedVersion),
|
|
1503
|
+
eq(c.verifier, Redacted.value(input.rehash.expectedVerifier)),
|
|
1504
|
+
),
|
|
1505
|
+
),
|
|
1506
|
+
),
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
return {
|
|
1512
|
+
receipt,
|
|
1513
|
+
statements,
|
|
1514
|
+
retryable: (cause: unknown) => isGuardFailure(cause, marker),
|
|
1515
|
+
};
|
|
1516
|
+
}),
|
|
1517
|
+
);
|
|
1518
|
+
}),
|
|
1519
|
+
readForSubject: (input: Parameters<PasswordPersistence["Service"]["readForSubject"]>[0]) =>
|
|
1520
|
+
Effect.gen(function* () {
|
|
1521
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
1522
|
+
|
|
1523
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
1524
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
1525
|
+
const subject = (yield* readSubjectNative(mapping, nativeSubjectId))[0];
|
|
1526
|
+
|
|
1527
|
+
if (
|
|
1528
|
+
subject === undefined ||
|
|
1529
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status])
|
|
1530
|
+
)
|
|
1531
|
+
return Option.none();
|
|
1532
|
+
|
|
1533
|
+
const credential = (yield* readCredentialNative(
|
|
1534
|
+
mapping,
|
|
1535
|
+
input.moduleId,
|
|
1536
|
+
nativeSubjectId,
|
|
1537
|
+
))[0];
|
|
1538
|
+
|
|
1539
|
+
if (credential === undefined) return Option.none();
|
|
1540
|
+
const ic = identifierColumns(mapping);
|
|
1541
|
+
|
|
1542
|
+
const identifiers = yield* database
|
|
1543
|
+
.select()
|
|
1544
|
+
.from(mapping.identifier.table)
|
|
1545
|
+
.where(eq(ic.subjectId, nativeSubjectId));
|
|
1546
|
+
|
|
1547
|
+
const identifier = identifiers.find((row: any) => mapping.identifier.isCurrent(row));
|
|
1548
|
+
|
|
1549
|
+
if (identifier === undefined) return Option.none();
|
|
1550
|
+
|
|
1551
|
+
return Option.some(
|
|
1552
|
+
yield* mapping.credential
|
|
1553
|
+
.decode({ moduleId: input.moduleId, subject, identifier, credential })
|
|
1554
|
+
.pipe(Effect.flatMap(snapshotPasswordCredential)),
|
|
1555
|
+
);
|
|
1556
|
+
}),
|
|
1557
|
+
recoveryTarget: (input: Parameters<PasswordPersistence["Service"]["recoveryTarget"]>[0]) =>
|
|
1558
|
+
Effect.gen(function* () {
|
|
1559
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
1560
|
+
const resolved = yield* resolveCredential(mapping, input.moduleId, input.identifier);
|
|
1561
|
+
|
|
1562
|
+
return resolved?.snapshot === undefined ||
|
|
1563
|
+
resolved.snapshot.identifierVerifiedAtMillis === undefined
|
|
1564
|
+
? Option.none()
|
|
1565
|
+
: Option.some(resolved.snapshot);
|
|
1566
|
+
}),
|
|
1567
|
+
addIfAbsent: <A>(
|
|
1568
|
+
uncaptured: Parameters<PasswordPersistence["Service"]["addIfAbsent"]>[0],
|
|
1569
|
+
prepare: PlanPrepare<PasswordPersistence["Service"]["addIfAbsent"], A>,
|
|
1570
|
+
) =>
|
|
1571
|
+
Effect.gen(function* () {
|
|
1572
|
+
const input = yield* snapshotMutationInput(uncaptured);
|
|
1573
|
+
|
|
1574
|
+
const credentialId = yield* allocate(
|
|
1575
|
+
mapping.allocateCredentialId,
|
|
1576
|
+
mapping.allocateCredentialIdSync,
|
|
1577
|
+
);
|
|
1578
|
+
|
|
1579
|
+
const credentialRevision = yield* allocate(
|
|
1580
|
+
mapping.allocateRevision,
|
|
1581
|
+
mapping.allocateRevisionSync,
|
|
1582
|
+
);
|
|
1583
|
+
|
|
1584
|
+
const verifierVersion = yield* allocate(
|
|
1585
|
+
mapping.allocateRevision,
|
|
1586
|
+
mapping.allocateRevisionSync,
|
|
1587
|
+
);
|
|
1588
|
+
|
|
1589
|
+
const nextSecurityRevision = yield* allocateNextSecurityRevision(
|
|
1590
|
+
mapping,
|
|
1591
|
+
input.expectedRevision.securityRevision,
|
|
1592
|
+
);
|
|
1593
|
+
|
|
1594
|
+
if (nextSecurityRevision === input.expectedRevision.securityRevision)
|
|
1595
|
+
return yield* unavailable();
|
|
1596
|
+
|
|
1597
|
+
return yield* run(
|
|
1598
|
+
Effect.gen(function* () {
|
|
1599
|
+
const journal = yield* CurrentCommitJournal;
|
|
1600
|
+
|
|
1601
|
+
const compiled = yield* compileAddMutation(mapping, input, {
|
|
1602
|
+
credentialId,
|
|
1603
|
+
credentialRevision,
|
|
1604
|
+
verifierVersion,
|
|
1605
|
+
nextSecurityRevision,
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
return {
|
|
1609
|
+
receipt: prepare(compiled === undefined ? "rejected" : "changed", journal),
|
|
1610
|
+
statements: compiled?.statements ?? [],
|
|
1611
|
+
retryable: compiled?.retryable,
|
|
1612
|
+
};
|
|
1613
|
+
}),
|
|
1614
|
+
);
|
|
1615
|
+
}),
|
|
1616
|
+
replaceIfCurrent: <A>(
|
|
1617
|
+
uncaptured: Parameters<PasswordPersistence["Service"]["replaceIfCurrent"]>[0],
|
|
1618
|
+
prepare: PlanPrepare<PasswordPersistence["Service"]["replaceIfCurrent"], A>,
|
|
1619
|
+
) =>
|
|
1620
|
+
Effect.flatMap(snapshotMutationInput(uncaptured), (input) =>
|
|
1621
|
+
replacementPlan(mapping, proofMapping, input, prepare, "change-password"),
|
|
1622
|
+
),
|
|
1623
|
+
checkReset: (input: Parameters<PasswordPersistence["Service"]["checkReset"]>[0]) =>
|
|
1624
|
+
proofMapping === undefined
|
|
1625
|
+
? Effect.fail(unavailable())
|
|
1626
|
+
: Effect.gen(function* () {
|
|
1627
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
1628
|
+
if (
|
|
1629
|
+
input.moduleId.length <= "/reset".length ||
|
|
1630
|
+
!input.moduleId.endsWith("/reset") ||
|
|
1631
|
+
input.purpose !== "password-reset" ||
|
|
1632
|
+
input.binding._tag !== "Subject"
|
|
1633
|
+
)
|
|
1634
|
+
return false;
|
|
1635
|
+
const binding = input.binding;
|
|
1636
|
+
|
|
1637
|
+
const resolved = yield* resolveCredential(
|
|
1638
|
+
mapping,
|
|
1639
|
+
input.moduleId.slice(0, -"/reset".length),
|
|
1640
|
+
binding.identifier,
|
|
1641
|
+
binding.revision.subjectId,
|
|
1642
|
+
);
|
|
1643
|
+
|
|
1644
|
+
const current =
|
|
1645
|
+
resolved?.snapshot !== undefined &&
|
|
1646
|
+
resolved.snapshot.revision.securityRevision === binding.revision.securityRevision &&
|
|
1647
|
+
binding.revision.credentials.every((item) =>
|
|
1648
|
+
resolved.snapshot!.revision.credentials.some(
|
|
1649
|
+
(current) =>
|
|
1650
|
+
current.credentialId === item.credentialId &&
|
|
1651
|
+
current.revision === item.revision,
|
|
1652
|
+
),
|
|
1653
|
+
);
|
|
1654
|
+
|
|
1655
|
+
return current ? yield* probeProofCompletion(proofMapping, input) : false;
|
|
1656
|
+
}),
|
|
1657
|
+
resetWithProof: <A>(
|
|
1658
|
+
uncaptured: Parameters<PasswordPersistence["Service"]["resetWithProof"]>[0],
|
|
1659
|
+
prepare: PlanPrepare<PasswordPersistence["Service"]["resetWithProof"], A>,
|
|
1660
|
+
) =>
|
|
1661
|
+
proofMapping === undefined
|
|
1662
|
+
? Effect.fail(unavailable())
|
|
1663
|
+
: Effect.flatMap(snapshotMutationInput(uncaptured), (captured) =>
|
|
1664
|
+
replacementPlan(
|
|
1665
|
+
mapping,
|
|
1666
|
+
proofMapping,
|
|
1667
|
+
Object.freeze({ ...captured, completion: uncaptured.completion }),
|
|
1668
|
+
prepare,
|
|
1669
|
+
"reset-password",
|
|
1670
|
+
),
|
|
1671
|
+
),
|
|
1672
|
+
cleanupAttempts: <A>(
|
|
1673
|
+
input: Parameters<PasswordPersistence["Service"]["cleanupAttempts"]>[0],
|
|
1674
|
+
prepare: PlanPrepare<PasswordPersistence["Service"]["cleanupAttempts"], A>,
|
|
1675
|
+
) =>
|
|
1676
|
+
run(
|
|
1677
|
+
Effect.gen(function* () {
|
|
1678
|
+
return yield* cleanupPlan(mapping, input, prepare);
|
|
1679
|
+
}),
|
|
1680
|
+
),
|
|
1681
|
+
};
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1684
|
+
const compileReplacementMutation = Effect.fn("DrizzleD1Password.compileReplacementMutation")(
|
|
1685
|
+
function* (
|
|
1686
|
+
mapping: Mapping,
|
|
1687
|
+
input: PasswordMutationInput,
|
|
1688
|
+
action: "change-password" | "reset-password",
|
|
1689
|
+
revisions: {
|
|
1690
|
+
readonly credentialRevision: SecurityRevision;
|
|
1691
|
+
readonly verifierVersion: SecurityRevision;
|
|
1692
|
+
readonly nextSecurityRevision: SecurityRevision;
|
|
1693
|
+
},
|
|
1694
|
+
) {
|
|
1695
|
+
const { credentialRevision, verifierVersion, nextSecurityRevision } = revisions;
|
|
1696
|
+
const authority = yield* readAuthority(mapping, input, action);
|
|
1697
|
+
|
|
1698
|
+
const current =
|
|
1699
|
+
authority === undefined || input.credential === undefined
|
|
1700
|
+
? undefined
|
|
1701
|
+
: (yield* readCredentialNative(mapping, input.moduleId, authority.nativeSubjectId))[0];
|
|
1702
|
+
|
|
1703
|
+
const currentMatches =
|
|
1704
|
+
current !== undefined &&
|
|
1705
|
+
current[mapping.credential.credentialId] === input.credential!.credentialId &&
|
|
1706
|
+
current[mapping.credential.credentialRevision] === input.credential!.credentialRevision &&
|
|
1707
|
+
current[mapping.credential.verifierVersion] === input.credential!.verifierVersion &&
|
|
1708
|
+
current[mapping.credential.verifier] === Redacted.value(input.credential!.verifier) &&
|
|
1709
|
+
current[mapping.credential.normalization] === input.credential!.normalization;
|
|
1710
|
+
|
|
1711
|
+
if (authority === undefined || !currentMatches) return undefined;
|
|
1712
|
+
const now = yield* readEngineNowMillis(mapping);
|
|
1713
|
+
|
|
1714
|
+
const guard = and(
|
|
1715
|
+
authority.condition,
|
|
1716
|
+
credentialCurrentCondition(mapping, input, authority.nativeSubjectId),
|
|
1717
|
+
commandAbsentCondition(mapping, input.moduleId, input.commandId),
|
|
1718
|
+
)!;
|
|
1719
|
+
|
|
1720
|
+
const marker = `effect-auth-password-guard:${action}:${input.commandId}`;
|
|
1721
|
+
|
|
1722
|
+
const protectedMutation: D1ProtectedProofMutation = {
|
|
1723
|
+
statements: [
|
|
1724
|
+
yield* assertion(guard, marker),
|
|
1725
|
+
...(yield* mutationStatements(
|
|
1726
|
+
mapping,
|
|
1727
|
+
input,
|
|
1728
|
+
authority.nativeSubjectId,
|
|
1729
|
+
{ credentialRevision, verifierVersion, nextSecurityRevision },
|
|
1730
|
+
now,
|
|
1731
|
+
)),
|
|
1732
|
+
],
|
|
1733
|
+
appliedCondition: replacementApplied(
|
|
1734
|
+
mapping,
|
|
1735
|
+
input,
|
|
1736
|
+
authority.nativeSubjectId,
|
|
1737
|
+
{
|
|
1738
|
+
credentialRevision,
|
|
1739
|
+
verifierVersion,
|
|
1740
|
+
nextSecurityRevision,
|
|
1741
|
+
},
|
|
1742
|
+
now,
|
|
1743
|
+
authority.identifierCondition,
|
|
1744
|
+
),
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1747
|
+
return { protectedMutation, marker };
|
|
1748
|
+
},
|
|
1749
|
+
);
|
|
1750
|
+
|
|
1751
|
+
const replacementPlan = Effect.fn("Drizzle.replacementPlan")(function* <A>(
|
|
1752
|
+
mapping: Mapping,
|
|
1753
|
+
proofMapping:
|
|
1754
|
+
| D1ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
1755
|
+
| undefined,
|
|
1756
|
+
input: PasswordMutationInput & { readonly completion?: any },
|
|
1757
|
+
prepare: PreparePasswordCommit<PasswordMutationDecision, A>,
|
|
1758
|
+
action: "change-password" | "reset-password",
|
|
1759
|
+
) {
|
|
1760
|
+
const credentialRevision = yield* allocate(
|
|
1761
|
+
mapping.allocateRevision,
|
|
1762
|
+
mapping.allocateRevisionSync,
|
|
1763
|
+
);
|
|
1764
|
+
|
|
1765
|
+
const verifierVersion = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
1766
|
+
|
|
1767
|
+
const nextSecurityRevision = yield* allocateNextSecurityRevision(
|
|
1768
|
+
mapping,
|
|
1769
|
+
input.expectedRevision.securityRevision,
|
|
1770
|
+
);
|
|
1771
|
+
|
|
1772
|
+
if (
|
|
1773
|
+
nextSecurityRevision === input.expectedRevision.securityRevision ||
|
|
1774
|
+
(input.credential !== undefined && credentialRevision === input.credential.credentialRevision)
|
|
1775
|
+
)
|
|
1776
|
+
return yield* unavailable();
|
|
1777
|
+
|
|
1778
|
+
const journal = yield* CurrentCommitJournal;
|
|
1779
|
+
|
|
1780
|
+
const compiledMutation = yield* compileReplacementMutation(mapping, input, action, {
|
|
1781
|
+
credentialRevision,
|
|
1782
|
+
verifierVersion,
|
|
1783
|
+
nextSecurityRevision,
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1786
|
+
if (compiledMutation === undefined)
|
|
1787
|
+
return { receipt: prepare("rejected", journal), statements: [] };
|
|
1788
|
+
const { protectedMutation, marker } = compiledMutation;
|
|
1789
|
+
|
|
1790
|
+
if (action === "reset-password") {
|
|
1791
|
+
if (
|
|
1792
|
+
proofMapping === undefined ||
|
|
1793
|
+
input.completion === undefined ||
|
|
1794
|
+
!completionMatchesPassword(
|
|
1795
|
+
input as PasswordMutationInput & { readonly completion: ProofCompletionPlan },
|
|
1796
|
+
)
|
|
1797
|
+
)
|
|
1798
|
+
return { receipt: prepare("rejected", journal), statements: [] };
|
|
1799
|
+
let passwordReceipt: PreparedCommit<A> | undefined;
|
|
1800
|
+
|
|
1801
|
+
const compiled = yield* compileD1ProofCompletionPlan(
|
|
1802
|
+
proofMapping,
|
|
1803
|
+
input.completion,
|
|
1804
|
+
protectedMutation,
|
|
1805
|
+
(decision: ProofCompletionDecision) => {
|
|
1806
|
+
passwordReceipt = prepare(decision === "completed" ? "changed" : "rejected", journal);
|
|
1807
|
+
|
|
1808
|
+
return decision;
|
|
1809
|
+
},
|
|
1810
|
+
);
|
|
1811
|
+
|
|
1812
|
+
return {
|
|
1813
|
+
receipt: passwordReceipt ?? prepare("rejected", journal),
|
|
1814
|
+
statements: compiled.statements,
|
|
1815
|
+
retryable: (cause: unknown) =>
|
|
1816
|
+
isGuardFailure(cause, marker) ||
|
|
1817
|
+
isGuardFailure(
|
|
1818
|
+
cause,
|
|
1819
|
+
`effect-auth-proof-guard:complete:${input.completion.input.continuationId}`,
|
|
1820
|
+
) ||
|
|
1821
|
+
isGuardFailure(
|
|
1822
|
+
cause,
|
|
1823
|
+
`effect-auth-proof-guard:protected:${input.completion.input.continuationId}`,
|
|
1824
|
+
),
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
return {
|
|
1829
|
+
receipt: prepare("changed", journal),
|
|
1830
|
+
statements: [
|
|
1831
|
+
...protectedMutation.statements,
|
|
1832
|
+
yield* assertion(protectedMutation.appliedCondition, marker),
|
|
1833
|
+
],
|
|
1834
|
+
retryable: (cause: unknown) => isGuardFailure(cause, marker),
|
|
1835
|
+
};
|
|
1836
|
+
});
|
|
1837
|
+
|
|
1838
|
+
const cleanupPlan = Effect.fn("Drizzle.cleanupPlan")(function* <A>(
|
|
1839
|
+
mapping: Mapping,
|
|
1840
|
+
input: { readonly moduleId: string; readonly limit: number },
|
|
1841
|
+
prepare: PreparePasswordCommit<{ readonly removed: number; readonly hasMore: boolean }, A>,
|
|
1842
|
+
) {
|
|
1843
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
1844
|
+
const journal = yield* CurrentCommitJournal;
|
|
1845
|
+
|
|
1846
|
+
const now = yield* readEngineNowMillis(mapping);
|
|
1847
|
+
const nativeNow = mapping.encodeInstant(now);
|
|
1848
|
+
const a = attemptColumns(mapping);
|
|
1849
|
+
const c = chargeColumns(mapping);
|
|
1850
|
+
const sc = scopeColumns(mapping);
|
|
1851
|
+
let remaining = input.limit;
|
|
1852
|
+
let hasMore = false;
|
|
1853
|
+
|
|
1854
|
+
const attempts = yield* database
|
|
1855
|
+
.select({ attemptId: a.attemptId })
|
|
1856
|
+
.from(mapping.attempt.table)
|
|
1857
|
+
.where(and(eq(a.moduleId, input.moduleId), lte(a.retentionUntil, nativeNow)))
|
|
1858
|
+
.limit(remaining + 1);
|
|
1859
|
+
|
|
1860
|
+
if (attempts.length > remaining) hasMore = true;
|
|
1861
|
+
const selectedAttempts = attempts.slice(0, remaining);
|
|
1862
|
+
|
|
1863
|
+
remaining -= selectedAttempts.length;
|
|
1864
|
+
|
|
1865
|
+
const charges = yield* database
|
|
1866
|
+
.select({
|
|
1867
|
+
action: c.action,
|
|
1868
|
+
scopeKind: c.scopeKind,
|
|
1869
|
+
scopeKey: c.scopeKey,
|
|
1870
|
+
attemptId: c.attemptId,
|
|
1871
|
+
})
|
|
1872
|
+
.from(mapping.charge.table)
|
|
1873
|
+
.where(and(eq(c.moduleId, input.moduleId), lte(c.retentionUntil, nativeNow)))
|
|
1874
|
+
.limit(remaining + 1);
|
|
1875
|
+
|
|
1876
|
+
if (charges.length > remaining) hasMore = true;
|
|
1877
|
+
const selectedCharges = charges.slice(0, remaining);
|
|
1878
|
+
|
|
1879
|
+
remaining -= selectedCharges.length;
|
|
1880
|
+
|
|
1881
|
+
const scopes = yield* database
|
|
1882
|
+
.select({ action: sc.action, scopeKind: sc.scopeKind, scopeKey: sc.scopeKey })
|
|
1883
|
+
.from(mapping.rateScope.table)
|
|
1884
|
+
.where(
|
|
1885
|
+
and(
|
|
1886
|
+
eq(sc.moduleId, input.moduleId),
|
|
1887
|
+
notExists(
|
|
1888
|
+
database
|
|
1889
|
+
.select({ one: sql`1` })
|
|
1890
|
+
.from(mapping.charge.table)
|
|
1891
|
+
.where(
|
|
1892
|
+
and(
|
|
1893
|
+
eq(c.moduleId, sc.moduleId),
|
|
1894
|
+
eq(c.action, sc.action),
|
|
1895
|
+
eq(c.scopeKind, sc.scopeKind),
|
|
1896
|
+
eq(c.scopeKey, sc.scopeKey),
|
|
1897
|
+
),
|
|
1898
|
+
),
|
|
1899
|
+
),
|
|
1900
|
+
),
|
|
1901
|
+
)
|
|
1902
|
+
.limit(remaining + 1);
|
|
1903
|
+
|
|
1904
|
+
if (scopes.length > remaining) hasMore = true;
|
|
1905
|
+
const selectedScopes = scopes.slice(0, remaining);
|
|
1906
|
+
const marker = `effect-auth-password-guard:cleanup:${input.moduleId}:${now}`;
|
|
1907
|
+
const statements: Statement<any>[] = [];
|
|
1908
|
+
|
|
1909
|
+
for (const row of selectedAttempts) {
|
|
1910
|
+
const condition = and(
|
|
1911
|
+
eq(a.moduleId, input.moduleId),
|
|
1912
|
+
eq(a.attemptId, row.attemptId),
|
|
1913
|
+
lte(a.retentionUntil, mapping.d1.engineNow),
|
|
1914
|
+
)!;
|
|
1915
|
+
|
|
1916
|
+
statements.push(
|
|
1917
|
+
yield* assertion(
|
|
1918
|
+
sql`exists(select 1 from ${mapping.attempt.table} where ${condition})`,
|
|
1919
|
+
marker,
|
|
1920
|
+
),
|
|
1921
|
+
yield* statement(database.delete(mapping.attempt.table).where(condition)),
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1924
|
+
for (const row of selectedCharges) {
|
|
1925
|
+
const condition = and(
|
|
1926
|
+
eq(c.moduleId, input.moduleId),
|
|
1927
|
+
eq(c.action, row.action),
|
|
1928
|
+
eq(c.scopeKind, row.scopeKind),
|
|
1929
|
+
eq(c.scopeKey, row.scopeKey),
|
|
1930
|
+
eq(c.attemptId, row.attemptId),
|
|
1931
|
+
lte(c.retentionUntil, mapping.d1.engineNow),
|
|
1932
|
+
)!;
|
|
1933
|
+
|
|
1934
|
+
statements.push(
|
|
1935
|
+
yield* assertion(
|
|
1936
|
+
sql`exists(select 1 from ${mapping.charge.table} where ${condition})`,
|
|
1937
|
+
marker,
|
|
1938
|
+
),
|
|
1939
|
+
yield* statement(database.delete(mapping.charge.table).where(condition)),
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
for (const row of selectedScopes) {
|
|
1943
|
+
const condition = and(
|
|
1944
|
+
eq(sc.moduleId, input.moduleId),
|
|
1945
|
+
eq(sc.action, row.action),
|
|
1946
|
+
eq(sc.scopeKind, row.scopeKind),
|
|
1947
|
+
eq(sc.scopeKey, row.scopeKey),
|
|
1948
|
+
notExists(
|
|
1949
|
+
database
|
|
1950
|
+
.select({ one: sql`1` })
|
|
1951
|
+
.from(mapping.charge.table)
|
|
1952
|
+
.where(
|
|
1953
|
+
and(
|
|
1954
|
+
eq(c.moduleId, sc.moduleId),
|
|
1955
|
+
eq(c.action, sc.action),
|
|
1956
|
+
eq(c.scopeKind, sc.scopeKind),
|
|
1957
|
+
eq(c.scopeKey, sc.scopeKey),
|
|
1958
|
+
),
|
|
1959
|
+
),
|
|
1960
|
+
),
|
|
1961
|
+
)!;
|
|
1962
|
+
|
|
1963
|
+
statements.push(
|
|
1964
|
+
yield* assertion(
|
|
1965
|
+
sql`exists(select 1 from ${mapping.rateScope.table} where ${condition})`,
|
|
1966
|
+
marker,
|
|
1967
|
+
),
|
|
1968
|
+
yield* statement(database.delete(mapping.rateScope.table).where(condition)),
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
return {
|
|
1973
|
+
receipt: prepare(
|
|
1974
|
+
{
|
|
1975
|
+
removed: selectedAttempts.length + selectedCharges.length + selectedScopes.length,
|
|
1976
|
+
hasMore,
|
|
1977
|
+
},
|
|
1978
|
+
journal,
|
|
1979
|
+
),
|
|
1980
|
+
statements,
|
|
1981
|
+
retryable: (cause: unknown) => isGuardFailure(cause, marker),
|
|
1982
|
+
};
|
|
1983
|
+
});
|
|
1984
|
+
|
|
1985
|
+
export const makeD1PasswordPersistenceServices = <
|
|
1986
|
+
S extends AnySQLiteTable,
|
|
1987
|
+
I extends AnySQLiteTable,
|
|
1988
|
+
C extends AnySQLiteTable,
|
|
1989
|
+
AC extends AnySQLiteTable,
|
|
1990
|
+
A extends AnySQLiteTable,
|
|
1991
|
+
RS extends AnySQLiteTable,
|
|
1992
|
+
CE extends AnySQLiteTable,
|
|
1993
|
+
M extends AnySQLiteTable,
|
|
1994
|
+
NativeId,
|
|
1995
|
+
>(
|
|
1996
|
+
database: Database,
|
|
1997
|
+
mapping: D1PasswordPersistenceMapping<S, I, C, AC, A, RS, CE, M, NativeId>,
|
|
1998
|
+
proofMapping?: D1ProofPersistenceMapping<
|
|
1999
|
+
any,
|
|
2000
|
+
any,
|
|
2001
|
+
any,
|
|
2002
|
+
any,
|
|
2003
|
+
any,
|
|
2004
|
+
any,
|
|
2005
|
+
any,
|
|
2006
|
+
any,
|
|
2007
|
+
any,
|
|
2008
|
+
any,
|
|
2009
|
+
any,
|
|
2010
|
+
any
|
|
2011
|
+
>,
|
|
2012
|
+
) =>
|
|
2013
|
+
Effect.gen(function* () {
|
|
2014
|
+
const hooks = yield* LifecycleHooks;
|
|
2015
|
+
const plans = makePasswordPlans(mapping as unknown as Mapping, proofMapping);
|
|
2016
|
+
|
|
2017
|
+
const run = <Out, Err, Env>(plan: Effect.Effect<Planned<Out>, Err, Env>) =>
|
|
2018
|
+
Effect.gen(function* () {
|
|
2019
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
2020
|
+
|
|
2021
|
+
return yield* executeStandalone(plan, 2);
|
|
2022
|
+
}).pipe(
|
|
2023
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2024
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2025
|
+
);
|
|
2026
|
+
|
|
2027
|
+
const service: PasswordPersistence["Service"] = {
|
|
2028
|
+
admitAttempt: (input, prepare) =>
|
|
2029
|
+
run(plans.admitAttempt(input, prepare)).pipe(translateFailure),
|
|
2030
|
+
settleAttempt: (input, prepare) =>
|
|
2031
|
+
run(plans.settleAttempt(input, prepare)).pipe(translateFailure),
|
|
2032
|
+
readForSubject: (input) =>
|
|
2033
|
+
plans
|
|
2034
|
+
.readForSubject(input)
|
|
2035
|
+
.pipe(
|
|
2036
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2037
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2038
|
+
translateFailure,
|
|
2039
|
+
),
|
|
2040
|
+
recoveryTarget: (input) =>
|
|
2041
|
+
plans
|
|
2042
|
+
.recoveryTarget(input)
|
|
2043
|
+
.pipe(
|
|
2044
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2045
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2046
|
+
translateFailure,
|
|
2047
|
+
),
|
|
2048
|
+
addIfAbsent: (input, prepare) =>
|
|
2049
|
+
run(plans.addIfAbsent(input, prepare)).pipe(translateFailure),
|
|
2050
|
+
replaceIfCurrent: (input, prepare) =>
|
|
2051
|
+
run(plans.replaceIfCurrent(input, prepare)).pipe(translateFailure),
|
|
2052
|
+
checkReset: (input) =>
|
|
2053
|
+
plans
|
|
2054
|
+
.checkReset(input)
|
|
2055
|
+
.pipe(
|
|
2056
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2057
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2058
|
+
translateFailure,
|
|
2059
|
+
),
|
|
2060
|
+
resetWithProof: (input, prepare) =>
|
|
2061
|
+
run(plans.resetWithProof(input, prepare)).pipe(translateFailure),
|
|
2062
|
+
cleanupAttempts: (input, prepare) =>
|
|
2063
|
+
run(plans.cleanupAttempts(input, prepare)).pipe(translateFailure),
|
|
2064
|
+
};
|
|
2065
|
+
|
|
2066
|
+
return { passwordPersistence: service };
|
|
2067
|
+
});
|
|
2068
|
+
|
|
2069
|
+
type CoordinatorError<E> = E | PasswordUnavailable | HookConfigurationError;
|
|
2070
|
+
|
|
2071
|
+
/**
|
|
2072
|
+
* Owns one password transition plus application statements in one D1 batch.
|
|
2073
|
+
* The owner Effect is invoked once and is never replayed after an ambiguous or
|
|
2074
|
+
* guarded batch failure. Standalone adapter-owned commands may replan boundedly.
|
|
2075
|
+
*/
|
|
2076
|
+
export function coordinateD1PasswordPersistence<
|
|
2077
|
+
S extends AnySQLiteTable,
|
|
2078
|
+
I extends AnySQLiteTable,
|
|
2079
|
+
C extends AnySQLiteTable,
|
|
2080
|
+
AC extends AnySQLiteTable,
|
|
2081
|
+
At extends AnySQLiteTable,
|
|
2082
|
+
RS extends AnySQLiteTable,
|
|
2083
|
+
CE extends AnySQLiteTable,
|
|
2084
|
+
M extends AnySQLiteTable,
|
|
2085
|
+
NativeId,
|
|
2086
|
+
A,
|
|
2087
|
+
E,
|
|
2088
|
+
R,
|
|
2089
|
+
DatabaseError,
|
|
2090
|
+
DatabaseRequirements,
|
|
2091
|
+
>(
|
|
2092
|
+
acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,
|
|
2093
|
+
options: {
|
|
2094
|
+
readonly mapping: D1PasswordPersistenceMapping<S, I, C, AC, At, RS, CE, M, NativeId>;
|
|
2095
|
+
readonly proofMapping?:
|
|
2096
|
+
| D1ProofPersistenceMapping<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
2097
|
+
| undefined;
|
|
2098
|
+
},
|
|
2099
|
+
body: Effect.Effect<A, E, R>,
|
|
2100
|
+
): Effect.Effect<
|
|
2101
|
+
A,
|
|
2102
|
+
CoordinatorError<E> | DatabaseError,
|
|
2103
|
+
Exclude<R, PasswordPersistence | D1BatchStatements> | LifecycleHooks | DatabaseRequirements
|
|
2104
|
+
> {
|
|
2105
|
+
return Effect.flatMap(acquire, (database) =>
|
|
2106
|
+
Effect.gen(function* () {
|
|
2107
|
+
const hooks = yield* LifecycleHooks;
|
|
2108
|
+
|
|
2109
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
2110
|
+
|
|
2111
|
+
const result = yield* coordinateCommit(
|
|
2112
|
+
() =>
|
|
2113
|
+
Effect.gen(function* () {
|
|
2114
|
+
const statements: Statement<any>[] = [];
|
|
2115
|
+
let mutation: Planned<any> | undefined;
|
|
2116
|
+
|
|
2117
|
+
const nativeCollector = D1BatchStatements.of({
|
|
2118
|
+
append: (statement) => Effect.sync(() => statements.push(statement)),
|
|
2119
|
+
});
|
|
2120
|
+
|
|
2121
|
+
const owner = yield* makeD1Owner(unavailable()).pipe(
|
|
2122
|
+
Effect.provideService(D1BatchStatements, nativeCollector),
|
|
2123
|
+
);
|
|
2124
|
+
|
|
2125
|
+
const plans = makePasswordPlans(
|
|
2126
|
+
options.mapping as unknown as Mapping,
|
|
2127
|
+
options.proofMapping,
|
|
2128
|
+
);
|
|
2129
|
+
|
|
2130
|
+
const run = <Out, Err, Env>(plan: Effect.Effect<Planned<Out>, Err, Env>) =>
|
|
2131
|
+
coordinateCommit(
|
|
2132
|
+
() =>
|
|
2133
|
+
Effect.gen(function* () {
|
|
2134
|
+
const journal = yield* CurrentCommitJournal;
|
|
2135
|
+
const planned = yield* plan;
|
|
2136
|
+
|
|
2137
|
+
yield* owner.check;
|
|
2138
|
+
if (mutation !== undefined) return yield* unavailable();
|
|
2139
|
+
const guarded = { ...planned, journalGuard: journal.prepare(undefined) };
|
|
2140
|
+
|
|
2141
|
+
mutation = guarded;
|
|
2142
|
+
statements.push(...guarded.statements);
|
|
2143
|
+
|
|
2144
|
+
return guarded.receipt;
|
|
2145
|
+
}),
|
|
2146
|
+
{ mode: "batch" },
|
|
2147
|
+
).pipe(
|
|
2148
|
+
Effect.map((result) => result.value),
|
|
2149
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2150
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2151
|
+
);
|
|
2152
|
+
|
|
2153
|
+
const service: PasswordPersistence["Service"] = {
|
|
2154
|
+
admitAttempt: (input, prepare) =>
|
|
2155
|
+
owner.run(run(plans.admitAttempt(input, prepare)).pipe(translateFailure)),
|
|
2156
|
+
settleAttempt: (input, prepare) =>
|
|
2157
|
+
owner.run(run(plans.settleAttempt(input, prepare)).pipe(translateFailure)),
|
|
2158
|
+
readForSubject: (input) =>
|
|
2159
|
+
owner.run(
|
|
2160
|
+
plans
|
|
2161
|
+
.readForSubject(input)
|
|
2162
|
+
.pipe(
|
|
2163
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2164
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2165
|
+
translateFailure,
|
|
2166
|
+
),
|
|
2167
|
+
),
|
|
2168
|
+
recoveryTarget: (input) =>
|
|
2169
|
+
owner.run(
|
|
2170
|
+
plans
|
|
2171
|
+
.recoveryTarget(input)
|
|
2172
|
+
.pipe(
|
|
2173
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2174
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2175
|
+
translateFailure,
|
|
2176
|
+
),
|
|
2177
|
+
),
|
|
2178
|
+
addIfAbsent: (input, prepare) =>
|
|
2179
|
+
owner.run(run(plans.addIfAbsent(input, prepare)).pipe(translateFailure)),
|
|
2180
|
+
replaceIfCurrent: (input, prepare) =>
|
|
2181
|
+
owner.run(run(plans.replaceIfCurrent(input, prepare)).pipe(translateFailure)),
|
|
2182
|
+
checkReset: (input) =>
|
|
2183
|
+
owner.run(
|
|
2184
|
+
plans
|
|
2185
|
+
.checkReset(input)
|
|
2186
|
+
.pipe(
|
|
2187
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2188
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2189
|
+
translateFailure,
|
|
2190
|
+
),
|
|
2191
|
+
),
|
|
2192
|
+
resetWithProof: (input, prepare) =>
|
|
2193
|
+
owner.run(run(plans.resetWithProof(input, prepare)).pipe(translateFailure)),
|
|
2194
|
+
cleanupAttempts: (input, prepare) =>
|
|
2195
|
+
owner.run(run(plans.cleanupAttempts(input, prepare)).pipe(translateFailure)),
|
|
2196
|
+
};
|
|
2197
|
+
|
|
2198
|
+
const provided = Context.make(PasswordPersistence, service).pipe(
|
|
2199
|
+
Context.add(D1BatchStatements, owner.collector),
|
|
2200
|
+
);
|
|
2201
|
+
|
|
2202
|
+
const value = yield* owner.close(Effect.provideContext(body, provided));
|
|
2203
|
+
|
|
2204
|
+
if (mutation?.journalGuard !== undefined) {
|
|
2205
|
+
const status = yield* Effect.result(mutation.journalGuard.read);
|
|
2206
|
+
|
|
2207
|
+
if (status._tag === "Success" || status.failure._tag !== "CommitPending")
|
|
2208
|
+
return yield* unavailable();
|
|
2209
|
+
}
|
|
2210
|
+
yield* database.$client.batch(statements).pipe(
|
|
2211
|
+
Effect.catchCause((cause) =>
|
|
2212
|
+
Effect.failCause(
|
|
2213
|
+
Cause.map(cause, (error) =>
|
|
2214
|
+
everyFailureMatches(cause, mutation?.retryable) ? unavailable() : error,
|
|
2215
|
+
),
|
|
2216
|
+
),
|
|
2217
|
+
),
|
|
2218
|
+
translateFailure,
|
|
2219
|
+
);
|
|
2220
|
+
|
|
2221
|
+
return value;
|
|
2222
|
+
}),
|
|
2223
|
+
{ mode: "batch" },
|
|
2224
|
+
).pipe(Effect.provideService(LifecycleHooks, hooks));
|
|
2225
|
+
|
|
2226
|
+
return result.value;
|
|
2227
|
+
}),
|
|
2228
|
+
);
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
const registrationRows = Effect.fn("Drizzle.registrationRows")(function* <Registration>(
|
|
2232
|
+
mapping: RegistrationMapping<Registration>,
|
|
2233
|
+
moduleId: string,
|
|
2234
|
+
requestId: string,
|
|
2235
|
+
) {
|
|
2236
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
2237
|
+
|
|
2238
|
+
const module = column(mapping.registration.table, mapping.registration.moduleId);
|
|
2239
|
+
const request = column(mapping.registration.table, mapping.registration.requestId);
|
|
2240
|
+
|
|
2241
|
+
return yield* database
|
|
2242
|
+
.select()
|
|
2243
|
+
.from(mapping.registration.table)
|
|
2244
|
+
.where(and(eq(module, moduleId), eq(request, requestId)))
|
|
2245
|
+
.limit(1);
|
|
2246
|
+
});
|
|
2247
|
+
|
|
2248
|
+
const registrationIdentifierRows = Effect.fn("Drizzle.registrationIdentifierRows")(function* <
|
|
2249
|
+
Registration,
|
|
2250
|
+
>(mapping: RegistrationMapping<Registration>, identifier: LoginIdentifier) {
|
|
2251
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
2252
|
+
|
|
2253
|
+
const namespace = column(mapping.identifier.table, mapping.identifier.namespace);
|
|
2254
|
+
const value = column(mapping.identifier.table, mapping.identifier.value);
|
|
2255
|
+
|
|
2256
|
+
return yield* database
|
|
2257
|
+
.select()
|
|
2258
|
+
.from(mapping.identifier.table)
|
|
2259
|
+
.where(and(eq(namespace, identifier.namespace), eq(value, identifier.value)))
|
|
2260
|
+
.limit(1);
|
|
2261
|
+
});
|
|
2262
|
+
|
|
2263
|
+
const planRegistration = Effect.fn("Drizzle.planRegistration")(function* <Registration, A>(
|
|
2264
|
+
mapping: RegistrationMapping<Registration>,
|
|
2265
|
+
input: {
|
|
2266
|
+
readonly moduleId: string;
|
|
2267
|
+
readonly requestId: string;
|
|
2268
|
+
readonly identifier: LoginIdentifier;
|
|
2269
|
+
readonly registration: Registration;
|
|
2270
|
+
readonly replacement: PasswordMutationInput["replacement"];
|
|
2271
|
+
},
|
|
2272
|
+
allocated: {
|
|
2273
|
+
readonly credentialId: string;
|
|
2274
|
+
readonly securityRevision: SecurityRevision;
|
|
2275
|
+
readonly identifierRevision: SecurityRevision;
|
|
2276
|
+
readonly credentialRevision: SecurityRevision;
|
|
2277
|
+
readonly verifierVersion: SecurityRevision;
|
|
2278
|
+
readonly nativeSubjectId?: unknown;
|
|
2279
|
+
readonly recoveryReference?: any;
|
|
2280
|
+
},
|
|
2281
|
+
prepare: PreparePasswordCommit<
|
|
2282
|
+
import("../password/methods/module").PasswordRegistrationDecision,
|
|
2283
|
+
A
|
|
2284
|
+
>,
|
|
2285
|
+
) {
|
|
2286
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
2287
|
+
const journal = yield* CurrentCommitJournal;
|
|
2288
|
+
|
|
2289
|
+
const existing = (yield* registrationRows(mapping, input.moduleId, input.requestId))[0];
|
|
2290
|
+
|
|
2291
|
+
if (existing !== undefined)
|
|
2292
|
+
return {
|
|
2293
|
+
receipt: prepare(yield* mapping.registration.decodeReplay(existing), journal),
|
|
2294
|
+
statements: [],
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
const intent = {
|
|
2298
|
+
moduleId: input.moduleId,
|
|
2299
|
+
requestId: input.requestId,
|
|
2300
|
+
identifier: input.identifier,
|
|
2301
|
+
registration: input.registration,
|
|
2302
|
+
replacement: input.replacement,
|
|
2303
|
+
};
|
|
2304
|
+
|
|
2305
|
+
if (mapping.mode === "pending") {
|
|
2306
|
+
if (allocated.recoveryReference === undefined) return yield* unavailable();
|
|
2307
|
+
|
|
2308
|
+
return {
|
|
2309
|
+
receipt: prepare({ _tag: "Pending", reference: allocated.recoveryReference }, journal),
|
|
2310
|
+
statements: [
|
|
2311
|
+
yield* statement(
|
|
2312
|
+
database.insert(mapping.registration.table).values(
|
|
2313
|
+
mapping.registration.encodeInsert(intent, {
|
|
2314
|
+
state: "pending",
|
|
2315
|
+
recoveryReference: allocated.recoveryReference,
|
|
2316
|
+
}),
|
|
2317
|
+
),
|
|
2318
|
+
),
|
|
2319
|
+
],
|
|
2320
|
+
retryable: (cause: unknown) => isMappedConstraintConflict(mapping.isRequestConflict, cause),
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
if (mapping.provisioning.idMode === "generated" || allocated.nativeSubjectId === undefined)
|
|
2324
|
+
return yield* unavailable();
|
|
2325
|
+
if ((yield* registrationIdentifierRows(mapping, input.identifier)).length > 0)
|
|
2326
|
+
return { receipt: prepare({ _tag: "Suppressed" }, journal), statements: [] };
|
|
2327
|
+
const nativeSubjectId = allocated.nativeSubjectId;
|
|
2328
|
+
const subjectId = yield* mapping.subjectId.toSubject(nativeSubjectId);
|
|
2329
|
+
|
|
2330
|
+
return {
|
|
2331
|
+
receipt: prepare({ _tag: "Created", subjectId }, journal),
|
|
2332
|
+
statements: [
|
|
2333
|
+
yield* statement(
|
|
2334
|
+
database.insert(mapping.subject.table).values(
|
|
2335
|
+
mapping.provisioning.encodeSubjectInsert(intent, {
|
|
2336
|
+
nativeSubjectId,
|
|
2337
|
+
securityRevision: allocated.securityRevision,
|
|
2338
|
+
}),
|
|
2339
|
+
),
|
|
2340
|
+
),
|
|
2341
|
+
yield* statement(
|
|
2342
|
+
database
|
|
2343
|
+
.insert(mapping.identifier.table)
|
|
2344
|
+
.values(
|
|
2345
|
+
mapping.identifier.encodeInitialInsert(
|
|
2346
|
+
input.identifier,
|
|
2347
|
+
nativeSubjectId,
|
|
2348
|
+
allocated.identifierRevision,
|
|
2349
|
+
),
|
|
2350
|
+
),
|
|
2351
|
+
),
|
|
2352
|
+
yield* statement(
|
|
2353
|
+
database.insert(mapping.credential.table).values(
|
|
2354
|
+
mapping.credential.encodeInsert({
|
|
2355
|
+
moduleId: input.moduleId,
|
|
2356
|
+
subjectId: nativeSubjectId,
|
|
2357
|
+
credentialId: allocated.credentialId,
|
|
2358
|
+
credentialRevision: allocated.credentialRevision,
|
|
2359
|
+
verifierVersion: allocated.verifierVersion,
|
|
2360
|
+
replacement: input.replacement,
|
|
2361
|
+
}),
|
|
2362
|
+
),
|
|
2363
|
+
),
|
|
2364
|
+
yield* statement(
|
|
2365
|
+
database.insert(mapping.authorityCredential.table).values(
|
|
2366
|
+
mapping.authorityCredential.encodeInsert({
|
|
2367
|
+
subjectId: nativeSubjectId,
|
|
2368
|
+
credentialId: allocated.credentialId,
|
|
2369
|
+
revision: allocated.credentialRevision,
|
|
2370
|
+
}),
|
|
2371
|
+
),
|
|
2372
|
+
),
|
|
2373
|
+
yield* statement(
|
|
2374
|
+
database.insert(mapping.registration.table).values(
|
|
2375
|
+
mapping.registration.encodeInsert(intent, {
|
|
2376
|
+
state: "created",
|
|
2377
|
+
nativeSubjectId,
|
|
2378
|
+
}),
|
|
2379
|
+
),
|
|
2380
|
+
),
|
|
2381
|
+
],
|
|
2382
|
+
retryable: (cause: unknown) =>
|
|
2383
|
+
isMappedConstraintConflict(mapping.isRequestConflict, cause) ||
|
|
2384
|
+
isMappedConstraintConflict(mapping.isIdentifierConflict, cause),
|
|
2385
|
+
};
|
|
2386
|
+
});
|
|
2387
|
+
|
|
2388
|
+
const allocateRegistration = <Registration>(mapping: RegistrationMapping<Registration>) =>
|
|
2389
|
+
Effect.gen(function* () {
|
|
2390
|
+
const credentialId = yield* allocate(
|
|
2391
|
+
mapping.allocateCredentialId,
|
|
2392
|
+
mapping.allocateCredentialIdSync,
|
|
2393
|
+
);
|
|
2394
|
+
|
|
2395
|
+
const securityRevision = yield* allocate(
|
|
2396
|
+
mapping.allocateRevision,
|
|
2397
|
+
mapping.allocateRevisionSync,
|
|
2398
|
+
);
|
|
2399
|
+
|
|
2400
|
+
const identifierRevision = yield* allocate(
|
|
2401
|
+
mapping.allocateRevision,
|
|
2402
|
+
mapping.allocateRevisionSync,
|
|
2403
|
+
);
|
|
2404
|
+
|
|
2405
|
+
const credentialRevision = yield* allocate(
|
|
2406
|
+
mapping.allocateRevision,
|
|
2407
|
+
mapping.allocateRevisionSync,
|
|
2408
|
+
);
|
|
2409
|
+
|
|
2410
|
+
const verifierVersion = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
2411
|
+
|
|
2412
|
+
const nativeSubjectId =
|
|
2413
|
+
mapping.mode !== "atomic" || mapping.provisioning.idMode === "generated"
|
|
2414
|
+
? undefined
|
|
2415
|
+
: yield* allocate(
|
|
2416
|
+
mapping.provisioning.allocateSubjectId,
|
|
2417
|
+
mapping.provisioning.allocateSubjectIdSync,
|
|
2418
|
+
);
|
|
2419
|
+
|
|
2420
|
+
const recoveryReference =
|
|
2421
|
+
mapping.mode === "pending"
|
|
2422
|
+
? yield* allocate(mapping.allocateRecoveryReference, mapping.allocateRecoveryReferenceSync)
|
|
2423
|
+
: undefined;
|
|
2424
|
+
|
|
2425
|
+
return {
|
|
2426
|
+
credentialId,
|
|
2427
|
+
securityRevision,
|
|
2428
|
+
identifierRevision,
|
|
2429
|
+
credentialRevision,
|
|
2430
|
+
verifierVersion,
|
|
2431
|
+
...(nativeSubjectId === undefined ? {} : { nativeSubjectId }),
|
|
2432
|
+
...(recoveryReference === undefined ? {} : { recoveryReference }),
|
|
2433
|
+
};
|
|
2434
|
+
});
|
|
2435
|
+
|
|
2436
|
+
const makeRegistrationPlans = <Registration>(mapping: RegistrationMapping<Registration>) => ({
|
|
2437
|
+
register: <A>(
|
|
2438
|
+
input: Parameters<PasswordRegistrationAuthority<Registration>["register"]>[0],
|
|
2439
|
+
prepare: PlanPrepare<PasswordRegistrationAuthority<Registration>["register"], A>,
|
|
2440
|
+
) =>
|
|
2441
|
+
Effect.gen(function* () {
|
|
2442
|
+
if (!validRegistrationConstraints(mapping)) return yield* unavailable();
|
|
2443
|
+
if (mapping.mode === "atomic" && mapping.provisioning.idMode === "generated")
|
|
2444
|
+
return yield* unavailable();
|
|
2445
|
+
const allocated = yield* allocateRegistration(mapping);
|
|
2446
|
+
|
|
2447
|
+
return yield* planRegistration(mapping, input, allocated, prepare);
|
|
2448
|
+
}),
|
|
2449
|
+
});
|
|
2450
|
+
|
|
2451
|
+
export const makeD1PasswordRegistrationServices = <
|
|
2452
|
+
Registration,
|
|
2453
|
+
S extends AnySQLiteTable,
|
|
2454
|
+
I extends AnySQLiteTable,
|
|
2455
|
+
C extends AnySQLiteTable,
|
|
2456
|
+
AC extends AnySQLiteTable,
|
|
2457
|
+
Rq extends AnySQLiteTable,
|
|
2458
|
+
NativeId,
|
|
2459
|
+
>(
|
|
2460
|
+
database: Database,
|
|
2461
|
+
mapping: PasswordRegistrationMapping<Registration, S, I, C, AC, Rq, NativeId>,
|
|
2462
|
+
) =>
|
|
2463
|
+
Effect.gen(function* () {
|
|
2464
|
+
const hooks = yield* LifecycleHooks;
|
|
2465
|
+
const plans = makeRegistrationPlans(mapping as unknown as RegistrationMapping<Registration>);
|
|
2466
|
+
|
|
2467
|
+
const run = <Out, Err, Env>(plan: Effect.Effect<Planned<Out>, Err, Env>) =>
|
|
2468
|
+
Effect.gen(function* () {
|
|
2469
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
2470
|
+
|
|
2471
|
+
return yield* executeStandalone(plan, 2);
|
|
2472
|
+
}).pipe(
|
|
2473
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2474
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2475
|
+
);
|
|
2476
|
+
|
|
2477
|
+
const service: PasswordRegistrationAuthority<Registration> = {
|
|
2478
|
+
register: (input, prepare) => run(plans.register(input, prepare)).pipe(translateFailure),
|
|
2479
|
+
};
|
|
2480
|
+
|
|
2481
|
+
return { registrationAuthority: service };
|
|
2482
|
+
});
|
|
2483
|
+
|
|
2484
|
+
export function coordinateD1PasswordRegistration<
|
|
2485
|
+
TargetId,
|
|
2486
|
+
Registration,
|
|
2487
|
+
S extends AnySQLiteTable,
|
|
2488
|
+
I extends AnySQLiteTable,
|
|
2489
|
+
C extends AnySQLiteTable,
|
|
2490
|
+
AC extends AnySQLiteTable,
|
|
2491
|
+
Rq extends AnySQLiteTable,
|
|
2492
|
+
NativeId,
|
|
2493
|
+
A,
|
|
2494
|
+
E,
|
|
2495
|
+
R,
|
|
2496
|
+
DatabaseError,
|
|
2497
|
+
DatabaseRequirements,
|
|
2498
|
+
>(
|
|
2499
|
+
acquire: Effect.Effect<Database, DatabaseError, DatabaseRequirements>,
|
|
2500
|
+
options: {
|
|
2501
|
+
readonly mapping: PasswordRegistrationMapping<NoInfer<Registration>, S, I, C, AC, Rq, NativeId>;
|
|
2502
|
+
readonly target: SuppliedService<TargetId, PasswordRegistrationAuthority<Registration>>;
|
|
2503
|
+
},
|
|
2504
|
+
body: Effect.Effect<A, E, R>,
|
|
2505
|
+
): Effect.Effect<
|
|
2506
|
+
A,
|
|
2507
|
+
CoordinatorError<E> | DatabaseError,
|
|
2508
|
+
Exclude<R, TargetId | D1BatchStatements> | LifecycleHooks | DatabaseRequirements
|
|
2509
|
+
> {
|
|
2510
|
+
return Effect.flatMap(acquire, (database) =>
|
|
2511
|
+
Effect.gen(function* () {
|
|
2512
|
+
const hooks = yield* LifecycleHooks;
|
|
2513
|
+
|
|
2514
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
2515
|
+
|
|
2516
|
+
const result = yield* coordinateCommit(
|
|
2517
|
+
() =>
|
|
2518
|
+
Effect.gen(function* () {
|
|
2519
|
+
const statements: Statement<any>[] = [];
|
|
2520
|
+
let mutation: Planned<any> | undefined;
|
|
2521
|
+
|
|
2522
|
+
const nativeCollector = D1BatchStatements.of({
|
|
2523
|
+
append: (statement) => Effect.sync(() => statements.push(statement)),
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
const owner = yield* makeD1Owner(unavailable()).pipe(
|
|
2527
|
+
Effect.provideService(D1BatchStatements, nativeCollector),
|
|
2528
|
+
);
|
|
2529
|
+
|
|
2530
|
+
const plans = makeRegistrationPlans(
|
|
2531
|
+
options.mapping as unknown as RegistrationMapping<Registration>,
|
|
2532
|
+
);
|
|
2533
|
+
|
|
2534
|
+
const run = <Out, Err, Env>(plan: Effect.Effect<Planned<Out>, Err, Env>) =>
|
|
2535
|
+
coordinateCommit(
|
|
2536
|
+
() =>
|
|
2537
|
+
Effect.gen(function* () {
|
|
2538
|
+
const journal = yield* CurrentCommitJournal;
|
|
2539
|
+
const planned = yield* plan;
|
|
2540
|
+
|
|
2541
|
+
yield* owner.check;
|
|
2542
|
+
if (mutation !== undefined) return yield* unavailable();
|
|
2543
|
+
const guarded = { ...planned, journalGuard: journal.prepare(undefined) };
|
|
2544
|
+
|
|
2545
|
+
mutation = guarded;
|
|
2546
|
+
statements.push(...guarded.statements);
|
|
2547
|
+
|
|
2548
|
+
return guarded.receipt;
|
|
2549
|
+
}),
|
|
2550
|
+
{ mode: "batch" },
|
|
2551
|
+
).pipe(
|
|
2552
|
+
Effect.map((result) => result.value),
|
|
2553
|
+
Effect.provideService(CurrentD1PlanningDatabase, database),
|
|
2554
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
2555
|
+
);
|
|
2556
|
+
|
|
2557
|
+
const service: PasswordRegistrationAuthority<Registration> = {
|
|
2558
|
+
register: (input, prepare) =>
|
|
2559
|
+
owner.run(run(plans.register(input, prepare)).pipe(translateFailure)),
|
|
2560
|
+
};
|
|
2561
|
+
|
|
2562
|
+
const provided = Context.make(options.target, service).pipe(
|
|
2563
|
+
Context.add(D1BatchStatements, owner.collector),
|
|
2564
|
+
);
|
|
2565
|
+
|
|
2566
|
+
const value = yield* owner.close(Effect.provideContext(body, provided));
|
|
2567
|
+
|
|
2568
|
+
if (mutation?.journalGuard !== undefined) {
|
|
2569
|
+
const status = yield* Effect.result(mutation.journalGuard.read);
|
|
2570
|
+
|
|
2571
|
+
if (status._tag === "Success" || status.failure._tag !== "CommitPending")
|
|
2572
|
+
return yield* unavailable();
|
|
2573
|
+
}
|
|
2574
|
+
yield* database.$client.batch(statements).pipe(
|
|
2575
|
+
Effect.catchCause((cause) =>
|
|
2576
|
+
Effect.failCause(
|
|
2577
|
+
Cause.map(cause, (error) =>
|
|
2578
|
+
everyFailureMatches(cause, mutation?.retryable) ? unavailable() : error,
|
|
2579
|
+
),
|
|
2580
|
+
),
|
|
2581
|
+
),
|
|
2582
|
+
translateFailure,
|
|
2583
|
+
);
|
|
2584
|
+
|
|
2585
|
+
return value;
|
|
2586
|
+
}),
|
|
2587
|
+
{ mode: "batch" },
|
|
2588
|
+
).pipe(Effect.provideService(LifecycleHooks, hooks));
|
|
2589
|
+
|
|
2590
|
+
return result.value;
|
|
2591
|
+
}),
|
|
2592
|
+
);
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
/** Private prepared compiler seam: it never replays a caller or prepared callback. */
|
|
2596
|
+
export const passwordD1Kernel = {
|
|
2597
|
+
statement,
|
|
2598
|
+
assertion,
|
|
2599
|
+
readEngineNowMillis,
|
|
2600
|
+
allocate,
|
|
2601
|
+
allocateNextSecurityRevision,
|
|
2602
|
+
subjectColumns,
|
|
2603
|
+
identifierColumns,
|
|
2604
|
+
credentialColumns,
|
|
2605
|
+
authorityColumns,
|
|
2606
|
+
readAuthority,
|
|
2607
|
+
assuranceCondition,
|
|
2608
|
+
credentialCurrentCondition,
|
|
2609
|
+
commandAbsentCondition,
|
|
2610
|
+
compileAddMutation,
|
|
2611
|
+
compileReplacementMutation,
|
|
2612
|
+
completionMatchesPassword,
|
|
2613
|
+
isGuardFailure,
|
|
2614
|
+
};
|
|
2615
|
+
|
|
2616
|
+
const translateFailure = <A, E, R>(
|
|
2617
|
+
effect: Effect.Effect<A, E, R>,
|
|
2618
|
+
): Effect.Effect<A, PasswordUnavailable, R> =>
|
|
2619
|
+
reportPersistenceFailure(
|
|
2620
|
+
effect,
|
|
2621
|
+
(error) =>
|
|
2622
|
+
Schema.is(PasswordUnavailable)(error) ||
|
|
2623
|
+
Schema.is(ProofUnavailable)(error) ||
|
|
2624
|
+
Schema.is(HookConfigurationError)(error),
|
|
2625
|
+
).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
2626
|
+
|
|
2627
|
+
const executeStandalone = <A, E, R>(
|
|
2628
|
+
plan: Effect.Effect<Planned<A>, E, R>,
|
|
2629
|
+
retries = 2,
|
|
2630
|
+
): Effect.Effect<
|
|
2631
|
+
A,
|
|
2632
|
+
| E
|
|
2633
|
+
| import("../hooks/models").HookConfigurationError
|
|
2634
|
+
| import("effect/unstable/sql/SqlError").SqlError,
|
|
2635
|
+
Exclude<R, CurrentCommitJournal> | CurrentD1PlanningDatabase | LifecycleHooks
|
|
2636
|
+
> =>
|
|
2637
|
+
Effect.suspend(() => {
|
|
2638
|
+
let retryable: ((cause: unknown) => boolean) | undefined;
|
|
2639
|
+
|
|
2640
|
+
const once = coordinateCommit(
|
|
2641
|
+
() =>
|
|
2642
|
+
Effect.gen(function* () {
|
|
2643
|
+
const database = yield* CurrentD1PlanningDatabase;
|
|
2644
|
+
const planned = yield* plan;
|
|
2645
|
+
|
|
2646
|
+
retryable = planned.retryable;
|
|
2647
|
+
yield* database.$client.batch(planned.statements);
|
|
2648
|
+
|
|
2649
|
+
return planned.receipt;
|
|
2650
|
+
}),
|
|
2651
|
+
{ mode: "batch" },
|
|
2652
|
+
).pipe(Effect.map((result) => result.value));
|
|
2653
|
+
|
|
2654
|
+
return once.pipe(
|
|
2655
|
+
Effect.catchCause((cause) =>
|
|
2656
|
+
retries > 0 && everyFailureMatches(cause, retryable)
|
|
2657
|
+
? executeStandalone(plan, retries - 1)
|
|
2658
|
+
: Effect.failCause(cause),
|
|
2659
|
+
),
|
|
2660
|
+
);
|
|
2661
|
+
});
|