@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,2152 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any -- Drizzle intentionally erases consumer table types at this adapter boundary. */
|
|
2
|
+
import { and, eq, gt, lte, inArray, or, sql } from "drizzle-orm";
|
|
3
|
+
import type { EffectDrizzleQueryError } from "drizzle-orm/effect-core";
|
|
4
|
+
import { Cause, Context, DateTime, Effect, Option, Schema } from "effect";
|
|
5
|
+
import type * as SqlError from "effect/unstable/sql/SqlError";
|
|
6
|
+
|
|
7
|
+
import { coordinateCommit, CurrentCommitJournal, hasCommitScope } from "../hooks/commit";
|
|
8
|
+
import { LifecycleHooks } from "../hooks/LifecycleHooks";
|
|
9
|
+
import { reportPersistenceFailure } from "../internal/diagnostics";
|
|
10
|
+
import type { SubjectId, TokenDigest } from "../Schema";
|
|
11
|
+
import {
|
|
12
|
+
assessAuthentication,
|
|
13
|
+
snapshotSessionAuthenticationProvenance,
|
|
14
|
+
} from "../sessions/assurance";
|
|
15
|
+
import type { AuthenticationAuthority } from "../sessions/AuthenticationAuthority";
|
|
16
|
+
import type { PrepareSessionCommit } from "../sessions/commit";
|
|
17
|
+
import {
|
|
18
|
+
PendingAuthenticationInvalid,
|
|
19
|
+
SessionConflict,
|
|
20
|
+
SessionInvalid,
|
|
21
|
+
SessionStepUpInvalid,
|
|
22
|
+
SessionUnavailable,
|
|
23
|
+
StaleAuthentication,
|
|
24
|
+
} from "../sessions/errors";
|
|
25
|
+
import {
|
|
26
|
+
type AuthenticationEvidence,
|
|
27
|
+
type AuthenticationRevision,
|
|
28
|
+
type PendingConsumption,
|
|
29
|
+
type SecurityRevision,
|
|
30
|
+
type SessionInspection,
|
|
31
|
+
SessionMetadata,
|
|
32
|
+
} from "../sessions/models";
|
|
33
|
+
import {
|
|
34
|
+
pendingAuthenticationContext,
|
|
35
|
+
snapshotPendingAuthenticationContext,
|
|
36
|
+
type PendingAuthentication,
|
|
37
|
+
type PendingAuthenticationRecord,
|
|
38
|
+
type PendingAuthenticationState,
|
|
39
|
+
} from "../sessions/PendingAuthentication";
|
|
40
|
+
import type {
|
|
41
|
+
SessionRepository,
|
|
42
|
+
SignedSessionValidity,
|
|
43
|
+
StatefulSessionPersistence,
|
|
44
|
+
StatefulSessionRecord,
|
|
45
|
+
} from "../sessions/persistence";
|
|
46
|
+
import {
|
|
47
|
+
type SessionStepUpIntent,
|
|
48
|
+
type SessionStepUpPersistence,
|
|
49
|
+
} from "../sessions/SessionStepUpPersistence";
|
|
50
|
+
import { column, DrizzleMappingError, isMappedConstraintConflict, updateValues } from "./model";
|
|
51
|
+
import type {
|
|
52
|
+
AuthenticationAuthorityMapping,
|
|
53
|
+
PendingAuthenticationTables,
|
|
54
|
+
PendingAuthenticationMapping,
|
|
55
|
+
SessionAuthorityTables,
|
|
56
|
+
SessionFlowTables,
|
|
57
|
+
SessionSubjectTables,
|
|
58
|
+
SignedSessionValidityMapping,
|
|
59
|
+
StatefulSessionMapping,
|
|
60
|
+
} from "./session-model";
|
|
61
|
+
import type { SessionStepUpMapping } from "./step-up-model";
|
|
62
|
+
import {
|
|
63
|
+
decodeStepUpIntent,
|
|
64
|
+
encodeStepUpIntent,
|
|
65
|
+
sameStepUpRevision,
|
|
66
|
+
stepUpIntentLive,
|
|
67
|
+
validateStepUpPlan,
|
|
68
|
+
stepUpRotationMatches,
|
|
69
|
+
} from "./step-up-state";
|
|
70
|
+
|
|
71
|
+
type CommitMode = "interactive" | "synchronous";
|
|
72
|
+
type AnySubjectMapping = SessionSubjectTables<any, any>;
|
|
73
|
+
type AnyAuthorityMapping = SessionAuthorityTables<any, any, any>;
|
|
74
|
+
type AnyFlowMapping = SessionFlowTables<any, any>;
|
|
75
|
+
type AnyPendingMapping = AnyAuthorityMapping &
|
|
76
|
+
AnyFlowMapping &
|
|
77
|
+
PendingAuthenticationTables<any, any, any, any>;
|
|
78
|
+
type AnyStepUpMapping = SessionStepUpMapping<any, any, any, any, any, any, any, any>;
|
|
79
|
+
interface SessionSqlQuery<A = ReadonlyArray<any>> extends Effect.Effect<
|
|
80
|
+
A,
|
|
81
|
+
EffectDrizzleQueryError | SqlError.SqlError
|
|
82
|
+
> {
|
|
83
|
+
readonly from: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
84
|
+
readonly where: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
85
|
+
readonly limit: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
86
|
+
readonly orderBy: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
87
|
+
readonly for: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
88
|
+
readonly set: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
89
|
+
readonly values: (...args: ReadonlyArray<any>) => SessionSqlQuery<A>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface SessionSqlDatabase {
|
|
93
|
+
readonly select: (...args: ReadonlyArray<any>) => SessionSqlQuery;
|
|
94
|
+
readonly insert: (...args: ReadonlyArray<any>) => SessionSqlQuery;
|
|
95
|
+
readonly update: (...args: ReadonlyArray<any>) => SessionSqlQuery;
|
|
96
|
+
readonly delete: (...args: ReadonlyArray<any>) => SessionSqlQuery;
|
|
97
|
+
readonly transaction: <A, E, R>(
|
|
98
|
+
body: (transaction: SessionSqlDatabase) => Effect.Effect<A, E, R>,
|
|
99
|
+
) => Effect.Effect<A, E | SqlError.SqlError, R>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type Database = SessionSqlDatabase;
|
|
103
|
+
|
|
104
|
+
/** Native SQL authority for the current transaction or savepoint. */
|
|
105
|
+
export class CurrentSessionSql extends Context.Service<CurrentSessionSql, SessionSqlDatabase>()(
|
|
106
|
+
"effect-auth/drizzle/CurrentSessionSql",
|
|
107
|
+
) {}
|
|
108
|
+
|
|
109
|
+
type Guard = Effect.Effect<void, SessionUnavailable>;
|
|
110
|
+
|
|
111
|
+
export interface SessionSqlOptions {
|
|
112
|
+
readonly mode: CommitMode;
|
|
113
|
+
readonly locking: boolean;
|
|
114
|
+
/** Target-specific ambient transaction preflight. It runs before IDs or writes. */
|
|
115
|
+
readonly standaloneGuard: Guard;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const unavailable = () => SessionUnavailable.make({});
|
|
119
|
+
const stale = () => StaleAuthentication.make({});
|
|
120
|
+
const invalidPending = () => PendingAuthenticationInvalid.make({});
|
|
121
|
+
const invalidSession = () => SessionInvalid.make({});
|
|
122
|
+
|
|
123
|
+
const mapFailureCause = <A, E, R, E2>(
|
|
124
|
+
effect: Effect.Effect<A, E, R>,
|
|
125
|
+
map: (error: E) => E2,
|
|
126
|
+
): Effect.Effect<A, E2, R> =>
|
|
127
|
+
Effect.catchCause(effect, (cause) => Effect.failCause(Cause.map(cause, map)));
|
|
128
|
+
|
|
129
|
+
type SessionDomainError =
|
|
130
|
+
| SessionStepUpInvalid
|
|
131
|
+
| PendingAuthenticationInvalid
|
|
132
|
+
| SessionConflict
|
|
133
|
+
| SessionInvalid
|
|
134
|
+
| SessionUnavailable
|
|
135
|
+
| StaleAuthentication;
|
|
136
|
+
type AdapterFailure =
|
|
137
|
+
| EffectDrizzleQueryError
|
|
138
|
+
| DrizzleMappingError
|
|
139
|
+
| Schema.SchemaError
|
|
140
|
+
| SqlError.SqlError;
|
|
141
|
+
|
|
142
|
+
const isExpectedMutationError = (error: unknown): error is SessionDomainError => {
|
|
143
|
+
const tag = typeof error === "object" && error !== null ? Reflect.get(error, "_tag") : undefined;
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
tag === "SessionStepUpInvalid" ||
|
|
147
|
+
tag === "StaleAuthentication" ||
|
|
148
|
+
tag === "PendingAuthenticationInvalid" ||
|
|
149
|
+
tag === "SessionConflict" ||
|
|
150
|
+
tag === "SessionInvalid" ||
|
|
151
|
+
tag === "SessionUnavailable"
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const normalizeMutation =
|
|
156
|
+
(mapping: any) =>
|
|
157
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
158
|
+
effect.pipe(
|
|
159
|
+
Effect.catchCause((cause) =>
|
|
160
|
+
Effect.failCause(
|
|
161
|
+
Cause.map(cause, (error) =>
|
|
162
|
+
isMappedConstraintConflict(mapping.isConstraintConflict, error)
|
|
163
|
+
? SessionConflict.make({})
|
|
164
|
+
: error,
|
|
165
|
+
),
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
type NormalizedSessionFailure<E> = E extends SessionDomainError ? E : SessionUnavailable;
|
|
171
|
+
|
|
172
|
+
const safeTransaction = <A, E, R>(
|
|
173
|
+
effect: Effect.Effect<A, E, R>,
|
|
174
|
+
): Effect.Effect<A, NormalizedSessionFailure<E> | SessionUnavailable, R> =>
|
|
175
|
+
reportPersistenceFailure(effect, isExpectedMutationError).pipe(
|
|
176
|
+
Effect.catchCause((cause) =>
|
|
177
|
+
Effect.failCause(
|
|
178
|
+
Cause.map(
|
|
179
|
+
cause,
|
|
180
|
+
(error): NormalizedSessionFailure<E> =>
|
|
181
|
+
(isExpectedMutationError(error) ? error : unavailable()) as NormalizedSessionFailure<E>,
|
|
182
|
+
),
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const selectRows = (
|
|
188
|
+
query: SessionSqlQuery,
|
|
189
|
+
locking: boolean,
|
|
190
|
+
): Effect.Effect<ReadonlyArray<any>, AdapterFailure> =>
|
|
191
|
+
locking && typeof query.for === "function" ? query.for("update") : query;
|
|
192
|
+
|
|
193
|
+
const inTransaction = <A, E, R>(
|
|
194
|
+
database: Database,
|
|
195
|
+
effect: Effect.Effect<A, E, R | CurrentSessionSql>,
|
|
196
|
+
): Effect.Effect<A, E | SqlError.SqlError, Exclude<R, CurrentSessionSql>> =>
|
|
197
|
+
Effect.suspend(() =>
|
|
198
|
+
database.transaction((current) =>
|
|
199
|
+
effect.pipe(Effect.provideService(CurrentSessionSql, current)),
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const owned = <A, E, R>(
|
|
204
|
+
database: Database,
|
|
205
|
+
options: SessionSqlOptions,
|
|
206
|
+
isConstraintConflict: (cause: unknown) => boolean,
|
|
207
|
+
body: Effect.Effect<A, E, R | CurrentSessionSql | CurrentCommitJournal>,
|
|
208
|
+
): Effect.Effect<
|
|
209
|
+
A,
|
|
210
|
+
NormalizedSessionFailure<E> | SessionUnavailable,
|
|
211
|
+
Exclude<Exclude<R, CurrentSessionSql>, CurrentCommitJournal> | LifecycleHooks
|
|
212
|
+
> => {
|
|
213
|
+
const run = coordinateCommit(
|
|
214
|
+
() =>
|
|
215
|
+
database.transaction((current) =>
|
|
216
|
+
body.pipe(Effect.provideService(CurrentSessionSql, current)),
|
|
217
|
+
),
|
|
218
|
+
{ mode: options.mode },
|
|
219
|
+
).pipe(
|
|
220
|
+
(effect) =>
|
|
221
|
+
reportPersistenceFailure(
|
|
222
|
+
effect,
|
|
223
|
+
(error) =>
|
|
224
|
+
isExpectedMutationError(error) || isMappedConstraintConflict(isConstraintConflict, error),
|
|
225
|
+
),
|
|
226
|
+
Effect.map((result) => result.value),
|
|
227
|
+
Effect.catchCause((cause) =>
|
|
228
|
+
Effect.failCause(
|
|
229
|
+
Cause.map(cause, (error): NormalizedSessionFailure<E> | SessionUnavailable =>
|
|
230
|
+
isExpectedMutationError(error) ? (error as NormalizedSessionFailure<E>) : unavailable(),
|
|
231
|
+
),
|
|
232
|
+
),
|
|
233
|
+
),
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
return Effect.gen(function* () {
|
|
237
|
+
const current = yield* Effect.serviceOption(CurrentSessionSql);
|
|
238
|
+
const transactionBound = Option.isSome(current) && current.value === database;
|
|
239
|
+
|
|
240
|
+
if (!transactionBound) {
|
|
241
|
+
// A root service must never commit one database underneath another owner.
|
|
242
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
243
|
+
yield* options.standaloneGuard;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// A tx-bound service still owns a savepoint and child journal. If the caller
|
|
247
|
+
// catches its failure, both partial writes and prepared values are discarded.
|
|
248
|
+
return yield* run;
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const uniqueStrings = (values: ReadonlyArray<string>): ReadonlyArray<string> =>
|
|
253
|
+
[...new Set(values)].sort();
|
|
254
|
+
|
|
255
|
+
const preservesRevision = (
|
|
256
|
+
completed: AuthenticationEvidence,
|
|
257
|
+
original: AuthenticationEvidence,
|
|
258
|
+
): boolean => {
|
|
259
|
+
const current = new Map(
|
|
260
|
+
completed.revision.credentials.map((item) => [item.credentialId, item.revision]),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
completed.flowId === original.flowId &&
|
|
265
|
+
completed.bindingDigest === original.bindingDigest &&
|
|
266
|
+
completed.revision.subjectId === original.revision.subjectId &&
|
|
267
|
+
completed.revision.securityRevision === original.revision.securityRevision &&
|
|
268
|
+
original.revision.credentials.every(
|
|
269
|
+
(item) => current.get(item.credentialId) === item.revision,
|
|
270
|
+
) &&
|
|
271
|
+
original.proofs.every((expected) =>
|
|
272
|
+
completed.proofs.some(
|
|
273
|
+
(proof) =>
|
|
274
|
+
proof.method === expected.method &&
|
|
275
|
+
proof.credentialId === expected.credentialId &&
|
|
276
|
+
proof.userVerified === expected.userVerified &&
|
|
277
|
+
proof.phishingResistant === expected.phishingResistant &&
|
|
278
|
+
DateTime.toEpochMillis(proof.verifiedAt) ===
|
|
279
|
+
DateTime.toEpochMillis(expected.verifiedAt) &&
|
|
280
|
+
proof.factors.length === expected.factors.length &&
|
|
281
|
+
proof.factors.every((factor, index) => factor === expected.factors[index]),
|
|
282
|
+
),
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const authorityColumns = (mapping: any) => ({
|
|
288
|
+
subjectId: column(mapping.subject.table, mapping.subject.id),
|
|
289
|
+
subjectStatus: column(mapping.subject.table, mapping.subject.status),
|
|
290
|
+
subjectRevision: column(mapping.subject.table, mapping.subject.securityRevision),
|
|
291
|
+
credentialSubjectId: column(mapping.credential.table, mapping.credential.subjectId),
|
|
292
|
+
credentialId: column(mapping.credential.table, mapping.credential.credentialId),
|
|
293
|
+
credentialRevision: column(mapping.credential.table, mapping.credential.revision),
|
|
294
|
+
...(mapping.credential.status === undefined
|
|
295
|
+
? {}
|
|
296
|
+
: { credentialStatus: column(mapping.credential.table, mapping.credential.status) }),
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const subjectColumns = (mapping: any) => ({
|
|
300
|
+
subjectId: column(mapping.subject.table, mapping.subject.id),
|
|
301
|
+
subjectStatus: column(mapping.subject.table, mapping.subject.status),
|
|
302
|
+
subjectRevision: column(mapping.subject.table, mapping.subject.securityRevision),
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
const readSubject = Effect.fn("DrizzleSession.readSubject")(function* (
|
|
306
|
+
mapping: AnySubjectMapping,
|
|
307
|
+
nativeSubjectId: unknown,
|
|
308
|
+
locking: boolean,
|
|
309
|
+
) {
|
|
310
|
+
const database = yield* CurrentSessionSql;
|
|
311
|
+
const columns = subjectColumns(mapping);
|
|
312
|
+
|
|
313
|
+
return yield* selectRows(
|
|
314
|
+
database
|
|
315
|
+
.select()
|
|
316
|
+
.from(mapping.subject.table)
|
|
317
|
+
.where(eq(columns.subjectId, nativeSubjectId))
|
|
318
|
+
.limit(1),
|
|
319
|
+
locking,
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const captureDetailsIn = Effect.fn("DrizzleSession.captureDetails")(function* (
|
|
324
|
+
mapping: AnyAuthorityMapping,
|
|
325
|
+
subjectId: SubjectId,
|
|
326
|
+
credentialIds: ReadonlyArray<string>,
|
|
327
|
+
locking: boolean,
|
|
328
|
+
) {
|
|
329
|
+
const database = yield* CurrentSessionSql;
|
|
330
|
+
const requested = uniqueStrings(credentialIds);
|
|
331
|
+
|
|
332
|
+
if (requested.length !== credentialIds.length) return yield* stale();
|
|
333
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(subjectId);
|
|
334
|
+
const subjectRows = yield* readSubject(mapping, nativeSubjectId, locking);
|
|
335
|
+
const subject = subjectRows[0];
|
|
336
|
+
const columns = authorityColumns(mapping);
|
|
337
|
+
|
|
338
|
+
if (subject === undefined || !mapping.subject.isActiveStatus(subject[mapping.subject.status]))
|
|
339
|
+
return yield* stale();
|
|
340
|
+
|
|
341
|
+
const query = database
|
|
342
|
+
.select()
|
|
343
|
+
.from(mapping.credential.table)
|
|
344
|
+
.where(
|
|
345
|
+
and(
|
|
346
|
+
eq(columns.credentialSubjectId, nativeSubjectId),
|
|
347
|
+
requested.length === 0 ? sql<boolean>`false` : inArray(columns.credentialId, requested),
|
|
348
|
+
),
|
|
349
|
+
)
|
|
350
|
+
.orderBy(columns.credentialId);
|
|
351
|
+
|
|
352
|
+
const credentialRows = requested.length === 0 ? [] : yield* selectRows(query, locking);
|
|
353
|
+
|
|
354
|
+
if (credentialRows.length !== requested.length) return yield* stale();
|
|
355
|
+
|
|
356
|
+
const credentials = credentialRows
|
|
357
|
+
.map((row: any) => ({
|
|
358
|
+
credentialId: row[mapping.credential.credentialId] as string,
|
|
359
|
+
revision: row[mapping.credential.revision] as SecurityRevision,
|
|
360
|
+
active:
|
|
361
|
+
mapping.credential.status === undefined ||
|
|
362
|
+
mapping.credential.isActiveStatus?.(row[mapping.credential.status]) === true,
|
|
363
|
+
}))
|
|
364
|
+
.sort((left: any, right: any) => left.credentialId.localeCompare(right.credentialId));
|
|
365
|
+
|
|
366
|
+
if (credentials.some((item: any) => !item.active)) return yield* stale();
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
subject,
|
|
370
|
+
revision: {
|
|
371
|
+
subjectId,
|
|
372
|
+
securityRevision: subject[mapping.subject.securityRevision] as SecurityRevision,
|
|
373
|
+
credentials: credentials.map(({ credentialId, revision }: any) => ({
|
|
374
|
+
credentialId,
|
|
375
|
+
revision,
|
|
376
|
+
})),
|
|
377
|
+
} satisfies AuthenticationRevision,
|
|
378
|
+
};
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const captureIn = Effect.fn("DrizzleSession.capture")(function* (
|
|
382
|
+
mapping: AnyAuthorityMapping,
|
|
383
|
+
subjectId: SubjectId,
|
|
384
|
+
credentialIds: ReadonlyArray<string>,
|
|
385
|
+
locking: boolean,
|
|
386
|
+
) {
|
|
387
|
+
return (yield* captureDetailsIn(mapping, subjectId, credentialIds, locking)).revision;
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const validateEvidenceIn = Effect.fn("DrizzleSession.validateEvidence")(function* (
|
|
391
|
+
mapping: AnyAuthorityMapping,
|
|
392
|
+
evidence: AuthenticationEvidence,
|
|
393
|
+
locking: boolean,
|
|
394
|
+
) {
|
|
395
|
+
const captured = yield* captureDetailsIn(
|
|
396
|
+
mapping,
|
|
397
|
+
evidence.revision.subjectId,
|
|
398
|
+
evidence.revision.credentials.map((item) => item.credentialId),
|
|
399
|
+
locking,
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
if (
|
|
403
|
+
captured.revision.securityRevision !== evidence.revision.securityRevision ||
|
|
404
|
+
captured.revision.credentials.length !== evidence.revision.credentials.length ||
|
|
405
|
+
captured.revision.credentials.some(
|
|
406
|
+
(item: { credentialId: string; revision: SecurityRevision }, index: number) => {
|
|
407
|
+
const expected = [...evidence.revision.credentials].sort((a, b) =>
|
|
408
|
+
a.credentialId.localeCompare(b.credentialId),
|
|
409
|
+
)[index];
|
|
410
|
+
|
|
411
|
+
return (
|
|
412
|
+
expected === undefined ||
|
|
413
|
+
expected.credentialId !== item.credentialId ||
|
|
414
|
+
expected.revision !== item.revision
|
|
415
|
+
);
|
|
416
|
+
},
|
|
417
|
+
)
|
|
418
|
+
)
|
|
419
|
+
return yield* stale();
|
|
420
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(evidence.revision.subjectId);
|
|
421
|
+
const requirement = yield* mapping.subject.decodeRequirement(captured.subject);
|
|
422
|
+
|
|
423
|
+
return { nativeSubjectId, requirement };
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
const flowColumns = (mapping: any) => ({
|
|
427
|
+
flowId: column(mapping.flow.table, mapping.flow.flowId),
|
|
428
|
+
subjectId: column(mapping.flow.table, mapping.flow.subjectId),
|
|
429
|
+
state: column(mapping.flow.table, mapping.flow.state),
|
|
430
|
+
pendingDigest: column(mapping.flow.table, mapping.flow.pendingDigest),
|
|
431
|
+
dedupUntil: column(mapping.flow.table, mapping.flow.dedupUntil),
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const readFlow = Effect.fn("DrizzleSession.readFlow")(function* (
|
|
435
|
+
mapping: AnyFlowMapping,
|
|
436
|
+
flowId: string,
|
|
437
|
+
locking: boolean,
|
|
438
|
+
) {
|
|
439
|
+
const database = yield* CurrentSessionSql;
|
|
440
|
+
const columns = flowColumns(mapping);
|
|
441
|
+
|
|
442
|
+
return yield* selectRows(
|
|
443
|
+
database.select().from(mapping.flow.table).where(eq(columns.flowId, flowId)).limit(1),
|
|
444
|
+
locking,
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const ensureDirectFlowAvailable = Effect.fn("DrizzleSession.ensureFlowAvailable")(function* (
|
|
449
|
+
mapping: AnyAuthorityMapping &
|
|
450
|
+
AnyFlowMapping & {
|
|
451
|
+
readonly pending?: PendingAuthenticationTables<any, any, any, any>["pending"];
|
|
452
|
+
},
|
|
453
|
+
evidence: AuthenticationEvidence,
|
|
454
|
+
nativeSubjectId: unknown,
|
|
455
|
+
dedupUntil: DateTime.Utc,
|
|
456
|
+
) {
|
|
457
|
+
const database = yield* CurrentSessionSql;
|
|
458
|
+
const rows = yield* readFlow(mapping, evidence.flowId, true);
|
|
459
|
+
const existing = rows[0];
|
|
460
|
+
|
|
461
|
+
if (existing !== undefined) {
|
|
462
|
+
const now = yield* freshNow;
|
|
463
|
+
|
|
464
|
+
if (
|
|
465
|
+
DateTime.toEpochMillis(now) <
|
|
466
|
+
DateTime.toEpochMillis(yield* mapping.flow.decodeInstant(existing[mapping.flow.dedupUntil]))
|
|
467
|
+
)
|
|
468
|
+
return yield* SessionConflict.make({});
|
|
469
|
+
if (mapping.pending !== undefined)
|
|
470
|
+
yield* database
|
|
471
|
+
.delete(mapping.pending.table)
|
|
472
|
+
.where(eq(column(mapping.pending.table, mapping.pending.flowId), evidence.flowId));
|
|
473
|
+
yield* database
|
|
474
|
+
.delete(mapping.flow.table)
|
|
475
|
+
.where(eq(flowColumns(mapping).flowId, evidence.flowId));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return mapping.flow.encodeEstablishedInsert({ evidence, subjectId: nativeSubjectId, dedupUntil });
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const pendingColumns = (mapping: any) => ({
|
|
482
|
+
digest: column(mapping.pending.table, mapping.pending.digest),
|
|
483
|
+
version: column(mapping.pending.table, mapping.pending.version),
|
|
484
|
+
flowId: column(mapping.pending.table, mapping.pending.flowId),
|
|
485
|
+
subjectId: column(mapping.pending.table, mapping.pending.subjectId),
|
|
486
|
+
bindingDigest: column(mapping.pending.table, mapping.pending.bindingDigest),
|
|
487
|
+
expiresAt: column(mapping.pending.table, mapping.pending.expiresAt),
|
|
488
|
+
attemptLimit: column(mapping.pending.table, mapping.pending.attemptLimit),
|
|
489
|
+
failedAttempts: column(mapping.pending.table, mapping.pending.failedAttempts),
|
|
490
|
+
consumed: column(mapping.pending.table, mapping.pending.consumed),
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const readPending = Effect.fn("DrizzleSession.readPending")(function* (
|
|
494
|
+
mapping: AnyPendingMapping,
|
|
495
|
+
digest: TokenDigest,
|
|
496
|
+
locking: boolean,
|
|
497
|
+
) {
|
|
498
|
+
const database = yield* CurrentSessionSql;
|
|
499
|
+
|
|
500
|
+
return yield* selectRows(
|
|
501
|
+
database
|
|
502
|
+
.select()
|
|
503
|
+
.from(mapping.pending.table)
|
|
504
|
+
.where(eq(pendingColumns(mapping).digest, digest))
|
|
505
|
+
.limit(1),
|
|
506
|
+
locking,
|
|
507
|
+
);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
type PendingProjection = "record" | "context";
|
|
511
|
+
|
|
512
|
+
const validatePending = Effect.fn("DrizzleSession.validatePending")(function* <
|
|
513
|
+
Record extends PendingAuthenticationState = PendingAuthenticationRecord<unknown>,
|
|
514
|
+
>(mapping: AnyPendingMapping, input: PendingConsumption, projection: PendingProjection = "record") {
|
|
515
|
+
const rows = yield* readPending(mapping, input.digest, true);
|
|
516
|
+
const row = rows[0];
|
|
517
|
+
|
|
518
|
+
if (row === undefined) return yield* invalidPending();
|
|
519
|
+
|
|
520
|
+
const decode = (
|
|
521
|
+
projection === "context" ? mapping.pending.decodeContext : mapping.pending.decode
|
|
522
|
+
) as (row: any) => Effect.Effect<Record, DrizzleMappingError>;
|
|
523
|
+
|
|
524
|
+
const record = yield* decode(row);
|
|
525
|
+
const failedAttempts = Number(row[mapping.pending.failedAttempts]);
|
|
526
|
+
|
|
527
|
+
if (
|
|
528
|
+
record.version !== input.version ||
|
|
529
|
+
record.evidence.flowId !== input.flowId ||
|
|
530
|
+
record.evidence.bindingDigest !== input.bindingDigest ||
|
|
531
|
+
row[mapping.pending.consumed] !== false ||
|
|
532
|
+
failedAttempts >= record.attemptLimit
|
|
533
|
+
)
|
|
534
|
+
return yield* invalidPending();
|
|
535
|
+
const flows = yield* readFlow(mapping, input.flowId, true);
|
|
536
|
+
const flow = flows[0];
|
|
537
|
+
|
|
538
|
+
if (
|
|
539
|
+
flow === undefined ||
|
|
540
|
+
flow[mapping.flow.state] !== mapping.flow.pendingStateValue ||
|
|
541
|
+
flow[mapping.flow.pendingDigest] !== input.digest
|
|
542
|
+
)
|
|
543
|
+
return yield* invalidPending();
|
|
544
|
+
if (DateTime.toEpochMillis(yield* freshNow) >= DateTime.toEpochMillis(record.expiresAt))
|
|
545
|
+
return yield* invalidPending();
|
|
546
|
+
|
|
547
|
+
return record;
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
const consumePending = Effect.fn("DrizzleSession.consumePending")(function* (
|
|
551
|
+
mapping: AnyPendingMapping,
|
|
552
|
+
input: PendingConsumption,
|
|
553
|
+
until: DateTime.Utc,
|
|
554
|
+
) {
|
|
555
|
+
const database = yield* CurrentSessionSql;
|
|
556
|
+
|
|
557
|
+
yield* Effect.all([
|
|
558
|
+
database
|
|
559
|
+
.update(mapping.pending.table)
|
|
560
|
+
.set(updateValues<any>([[mapping.pending.consumed, true]]))
|
|
561
|
+
.where(
|
|
562
|
+
and(
|
|
563
|
+
eq(pendingColumns(mapping).digest, input.digest),
|
|
564
|
+
eq(pendingColumns(mapping).version, input.version),
|
|
565
|
+
eq(pendingColumns(mapping).consumed, false),
|
|
566
|
+
),
|
|
567
|
+
),
|
|
568
|
+
|
|
569
|
+
database
|
|
570
|
+
.update(mapping.flow.table)
|
|
571
|
+
.set(
|
|
572
|
+
updateValues<any>([
|
|
573
|
+
[mapping.flow.state, mapping.flow.establishedStateValue],
|
|
574
|
+
[mapping.flow.pendingDigest, null],
|
|
575
|
+
[mapping.flow.dedupUntil, mapping.flow.encodeInstant(until)],
|
|
576
|
+
]),
|
|
577
|
+
)
|
|
578
|
+
.where(eq(flowColumns(mapping).flowId, input.flowId)),
|
|
579
|
+
]);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
const freshNow = DateTime.now;
|
|
583
|
+
|
|
584
|
+
const allocate = <A>(
|
|
585
|
+
mode: CommitMode,
|
|
586
|
+
asynchronous: Effect.Effect<A, DrizzleMappingError> | undefined,
|
|
587
|
+
synchronous: (() => A) | undefined,
|
|
588
|
+
): Effect.Effect<A, DrizzleMappingError | SessionUnavailable> => {
|
|
589
|
+
if (mode === "synchronous")
|
|
590
|
+
return synchronous === undefined
|
|
591
|
+
? Effect.fail(unavailable())
|
|
592
|
+
: Effect.try({
|
|
593
|
+
try: synchronous,
|
|
594
|
+
catch: (cause) => DrizzleMappingError.make({ operation: "allocate", cause }),
|
|
595
|
+
});
|
|
596
|
+
if (asynchronous !== undefined) return asynchronous;
|
|
597
|
+
|
|
598
|
+
return synchronous === undefined
|
|
599
|
+
? Effect.fail(unavailable())
|
|
600
|
+
: Effect.try({
|
|
601
|
+
try: synchronous,
|
|
602
|
+
catch: (cause) => DrizzleMappingError.make({ operation: "allocate", cause }),
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
export const makeSqlAuthenticationAuthority = <Claims>(
|
|
607
|
+
database: Database,
|
|
608
|
+
mapping: AuthenticationAuthorityMapping<Claims, any, any, any, any, any>,
|
|
609
|
+
options: SessionSqlOptions,
|
|
610
|
+
) =>
|
|
611
|
+
Effect.map(LifecycleHooks, (hooks) => {
|
|
612
|
+
const service = {
|
|
613
|
+
capture: (subjectId: SubjectId, credentialIds: ReadonlyArray<string>) =>
|
|
614
|
+
safeTransaction(
|
|
615
|
+
inTransaction(database, captureIn(mapping, subjectId, credentialIds, true)),
|
|
616
|
+
),
|
|
617
|
+
requirements: (evidence: AuthenticationEvidence) =>
|
|
618
|
+
safeTransaction(
|
|
619
|
+
inTransaction(
|
|
620
|
+
database,
|
|
621
|
+
validateEvidenceIn(mapping, evidence, true).pipe(
|
|
622
|
+
Effect.map((result) => result.requirement),
|
|
623
|
+
),
|
|
624
|
+
),
|
|
625
|
+
),
|
|
626
|
+
approve: <A>(
|
|
627
|
+
input: Parameters<AuthenticationAuthority["Service"]["approve"]>[0],
|
|
628
|
+
prepare: PrepareSessionCommit<void, A>,
|
|
629
|
+
) =>
|
|
630
|
+
owned(
|
|
631
|
+
database,
|
|
632
|
+
options,
|
|
633
|
+
mapping.isConstraintConflict,
|
|
634
|
+
Effect.gen(function* () {
|
|
635
|
+
const journal = yield* CurrentCommitJournal;
|
|
636
|
+
const { requirement } = yield* validateEvidenceIn(mapping, input.evidence, true);
|
|
637
|
+
|
|
638
|
+
if (input.pending === undefined) {
|
|
639
|
+
const assessed = yield* assessAuthentication(input.evidence, requirement).pipe(
|
|
640
|
+
Effect.mapError(unavailable),
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
const now = yield* freshNow;
|
|
644
|
+
|
|
645
|
+
if (
|
|
646
|
+
!assessed.satisfied ||
|
|
647
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.expiresAt) ||
|
|
648
|
+
DateTime.toEpochMillis(input.expiresAt) >
|
|
649
|
+
DateTime.toEpochMillis(input.absoluteExpiresAt)
|
|
650
|
+
)
|
|
651
|
+
return yield* stale();
|
|
652
|
+
|
|
653
|
+
return prepare(undefined, journal);
|
|
654
|
+
}
|
|
655
|
+
if (mapping.pending === undefined) return yield* invalidPending();
|
|
656
|
+
const pendingMapping = { ...mapping, ...mapping.pending };
|
|
657
|
+
const pending = yield* validatePending(pendingMapping, input.pending);
|
|
658
|
+
|
|
659
|
+
if (!preservesRevision(input.evidence, pending.evidence))
|
|
660
|
+
return yield* invalidPending();
|
|
661
|
+
|
|
662
|
+
const assessed = yield* assessAuthentication(input.evidence, requirement).pipe(
|
|
663
|
+
Effect.mapError(unavailable),
|
|
664
|
+
);
|
|
665
|
+
|
|
666
|
+
const now = yield* freshNow;
|
|
667
|
+
|
|
668
|
+
if (
|
|
669
|
+
!assessed.satisfied ||
|
|
670
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(pending.expiresAt) ||
|
|
671
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.expiresAt) ||
|
|
672
|
+
DateTime.toEpochMillis(input.expiresAt) >
|
|
673
|
+
DateTime.toEpochMillis(input.absoluteExpiresAt)
|
|
674
|
+
)
|
|
675
|
+
return yield* stale();
|
|
676
|
+
const receipt = prepare(undefined, journal);
|
|
677
|
+
|
|
678
|
+
yield* consumePending(pendingMapping, input.pending, input.absoluteExpiresAt);
|
|
679
|
+
|
|
680
|
+
return receipt;
|
|
681
|
+
}),
|
|
682
|
+
),
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
return {
|
|
686
|
+
capture: (subjectId, credentialIds) =>
|
|
687
|
+
service
|
|
688
|
+
.capture(subjectId, credentialIds)
|
|
689
|
+
.pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
690
|
+
requirements: (evidence) =>
|
|
691
|
+
service.requirements(evidence).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
692
|
+
approve: (input, prepare) =>
|
|
693
|
+
service.approve(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
694
|
+
} satisfies AuthenticationAuthority["Service"];
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
/** The same locked security checks serve full consumption reads and the
|
|
698
|
+
* claims-free additional-factor context. No lock spans proof verification. */
|
|
699
|
+
const readAuthenticatedPending = Effect.fn("DrizzleSession.readAuthenticatedPending")(function* <
|
|
700
|
+
Record extends PendingAuthenticationState,
|
|
701
|
+
>(
|
|
702
|
+
mapping: AnyPendingMapping,
|
|
703
|
+
input: { readonly digest: TokenDigest; readonly bindingDigest?: TokenDigest },
|
|
704
|
+
projection: PendingProjection,
|
|
705
|
+
) {
|
|
706
|
+
const initial = (yield* readPending(mapping, input.digest, false))[0];
|
|
707
|
+
|
|
708
|
+
if (initial === undefined) return yield* invalidPending();
|
|
709
|
+
const initialNativeSubjectId = initial[mapping.pending.subjectId];
|
|
710
|
+
const subject = (yield* readSubject(mapping, initialNativeSubjectId, true))[0];
|
|
711
|
+
|
|
712
|
+
if (subject === undefined) return yield* invalidPending();
|
|
713
|
+
const current = (yield* readPending(mapping, input.digest, true))[0];
|
|
714
|
+
|
|
715
|
+
if (
|
|
716
|
+
current === undefined ||
|
|
717
|
+
!mapping.subjectId.equals(current[mapping.pending.subjectId], initialNativeSubjectId)
|
|
718
|
+
)
|
|
719
|
+
return yield* invalidPending();
|
|
720
|
+
|
|
721
|
+
const decode = (
|
|
722
|
+
projection === "context" ? mapping.pending.decodeContext : mapping.pending.decode
|
|
723
|
+
) as (row: any) => Effect.Effect<Record, DrizzleMappingError>;
|
|
724
|
+
|
|
725
|
+
const record = yield* decode(current);
|
|
726
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(record.evidence.revision.subjectId);
|
|
727
|
+
const failedAttempts = Number(current[mapping.pending.failedAttempts]);
|
|
728
|
+
|
|
729
|
+
if (
|
|
730
|
+
!mapping.subjectId.equals(nativeSubjectId, initialNativeSubjectId) ||
|
|
731
|
+
(input.bindingDigest !== undefined && record.evidence.bindingDigest !== input.bindingDigest) ||
|
|
732
|
+
current[mapping.pending.version] !== record.version ||
|
|
733
|
+
current[mapping.pending.flowId] !== record.evidence.flowId ||
|
|
734
|
+
current[mapping.pending.bindingDigest] !== record.evidence.bindingDigest ||
|
|
735
|
+
current[mapping.pending.consumed] !== false ||
|
|
736
|
+
failedAttempts >= record.attemptLimit
|
|
737
|
+
)
|
|
738
|
+
return yield* invalidPending();
|
|
739
|
+
const flow = (yield* readFlow(mapping, record.evidence.flowId, true))[0];
|
|
740
|
+
|
|
741
|
+
if (
|
|
742
|
+
flow === undefined ||
|
|
743
|
+
flow[mapping.flow.state] !== mapping.flow.pendingStateValue ||
|
|
744
|
+
flow[mapping.flow.pendingDigest] !== input.digest
|
|
745
|
+
)
|
|
746
|
+
return yield* invalidPending();
|
|
747
|
+
|
|
748
|
+
const { requirement } = yield* mapFailureCause(
|
|
749
|
+
validateEvidenceIn(mapping, record.evidence, true),
|
|
750
|
+
(error) => (error._tag === "StaleAuthentication" ? invalidPending() : error),
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
yield* assessAuthentication(record.evidence, requirement).pipe(
|
|
754
|
+
Effect.mapError(() => invalidPending()),
|
|
755
|
+
);
|
|
756
|
+
if (DateTime.toEpochMillis(yield* freshNow) >= DateTime.toEpochMillis(record.expiresAt))
|
|
757
|
+
return yield* invalidPending();
|
|
758
|
+
|
|
759
|
+
return record;
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
export const makeSqlPendingAuthentication = <Claims>(
|
|
763
|
+
database: Database,
|
|
764
|
+
mapping: PendingAuthenticationMapping<Claims, any, any, any, any, any>,
|
|
765
|
+
options: SessionSqlOptions,
|
|
766
|
+
) =>
|
|
767
|
+
Effect.map(LifecycleHooks, (hooks) => {
|
|
768
|
+
const service = {
|
|
769
|
+
create: <A>(
|
|
770
|
+
input: Omit<PendingAuthenticationRecord<Claims>, "version">,
|
|
771
|
+
_inputNow: DateTime.Utc,
|
|
772
|
+
prepare: PrepareSessionCommit<PendingAuthenticationRecord<Claims>, A>,
|
|
773
|
+
) =>
|
|
774
|
+
owned(
|
|
775
|
+
database,
|
|
776
|
+
options,
|
|
777
|
+
mapping.isConstraintConflict,
|
|
778
|
+
Effect.gen(function* () {
|
|
779
|
+
const transaction = yield* CurrentSessionSql;
|
|
780
|
+
const journal = yield* CurrentCommitJournal;
|
|
781
|
+
|
|
782
|
+
const { nativeSubjectId, requirement } = yield* validateEvidenceIn(
|
|
783
|
+
mapping,
|
|
784
|
+
input.evidence,
|
|
785
|
+
true,
|
|
786
|
+
);
|
|
787
|
+
|
|
788
|
+
const existing = (yield* readFlow(mapping, input.evidence.flowId, true))[0];
|
|
789
|
+
|
|
790
|
+
if (existing !== undefined) {
|
|
791
|
+
const dedupUntil = yield* mapping.flow.decodeInstant(
|
|
792
|
+
existing[mapping.flow.dedupUntil],
|
|
793
|
+
);
|
|
794
|
+
|
|
795
|
+
if (DateTime.toEpochMillis(yield* freshNow) < DateTime.toEpochMillis(dedupUntil))
|
|
796
|
+
return yield* SessionConflict.make({});
|
|
797
|
+
yield* transaction
|
|
798
|
+
.delete(mapping.pending.table)
|
|
799
|
+
.where(eq(pendingColumns(mapping).flowId, input.evidence.flowId));
|
|
800
|
+
yield* transaction
|
|
801
|
+
.delete(mapping.flow.table)
|
|
802
|
+
.where(eq(flowColumns(mapping).flowId, input.evidence.flowId));
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const version = yield* allocate(
|
|
806
|
+
options.mode,
|
|
807
|
+
mapping.pending.allocateVersion,
|
|
808
|
+
mapping.pending.allocateVersionSync,
|
|
809
|
+
);
|
|
810
|
+
|
|
811
|
+
yield* assessAuthentication(input.evidence, requirement);
|
|
812
|
+
const now = yield* freshNow;
|
|
813
|
+
|
|
814
|
+
if (DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.expiresAt))
|
|
815
|
+
return yield* stale();
|
|
816
|
+
const record = { ...input, version };
|
|
817
|
+
const receipt = prepare(record, journal);
|
|
818
|
+
|
|
819
|
+
yield* transaction.insert(mapping.flow.table).values(
|
|
820
|
+
mapping.flow.encodePendingInsert({
|
|
821
|
+
evidence: input.evidence,
|
|
822
|
+
subjectId: nativeSubjectId,
|
|
823
|
+
pendingDigest: input.digest,
|
|
824
|
+
dedupUntil: input.expiresAt,
|
|
825
|
+
}),
|
|
826
|
+
);
|
|
827
|
+
yield* transaction.insert(mapping.pending.table).values(
|
|
828
|
+
mapping.pending.encodeInsert(record, {
|
|
829
|
+
subjectId: nativeSubjectId,
|
|
830
|
+
failedAttempts: 0,
|
|
831
|
+
consumed: false,
|
|
832
|
+
}),
|
|
833
|
+
);
|
|
834
|
+
|
|
835
|
+
return receipt;
|
|
836
|
+
}).pipe(normalizeMutation(mapping)),
|
|
837
|
+
),
|
|
838
|
+
context: (input: { readonly digest: TokenDigest; readonly now: DateTime.Utc }) =>
|
|
839
|
+
safeTransaction(
|
|
840
|
+
inTransaction(
|
|
841
|
+
database,
|
|
842
|
+
readAuthenticatedPending<PendingAuthenticationState>(mapping, input, "context"),
|
|
843
|
+
),
|
|
844
|
+
).pipe(Effect.flatMap(pendingAuthenticationContext)),
|
|
845
|
+
read: (input: {
|
|
846
|
+
readonly digest: TokenDigest;
|
|
847
|
+
readonly bindingDigest: TokenDigest;
|
|
848
|
+
readonly now: DateTime.Utc;
|
|
849
|
+
}) =>
|
|
850
|
+
safeTransaction(
|
|
851
|
+
inTransaction(
|
|
852
|
+
database,
|
|
853
|
+
readAuthenticatedPending<PendingAuthenticationRecord<Claims>>(mapping, input, "record"),
|
|
854
|
+
),
|
|
855
|
+
).pipe(Effect.map((record) => record as PendingAuthenticationRecord<Claims>)),
|
|
856
|
+
reject: <A>(
|
|
857
|
+
input: Parameters<PendingAuthentication<Claims>["reject"]>[0],
|
|
858
|
+
prepare: PrepareSessionCommit<{ readonly _tag: "Rejected" }, A>,
|
|
859
|
+
) =>
|
|
860
|
+
owned(
|
|
861
|
+
database,
|
|
862
|
+
options,
|
|
863
|
+
mapping.isConstraintConflict,
|
|
864
|
+
Effect.gen(function* () {
|
|
865
|
+
const transaction = yield* CurrentSessionSql;
|
|
866
|
+
const journal = yield* CurrentCommitJournal;
|
|
867
|
+
const initial = (yield* readPending(mapping, input.digest, false))[0];
|
|
868
|
+
|
|
869
|
+
if (initial === undefined) return prepare({ _tag: "Rejected" }, journal);
|
|
870
|
+
const record = yield* mapping.pending.decodeContext(initial);
|
|
871
|
+
|
|
872
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(
|
|
873
|
+
record.evidence.revision.subjectId,
|
|
874
|
+
);
|
|
875
|
+
|
|
876
|
+
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
877
|
+
const current = (yield* readPending(mapping, input.digest, true))[0];
|
|
878
|
+
const now = yield* freshNow;
|
|
879
|
+
const receipt = prepare({ _tag: "Rejected" }, journal);
|
|
880
|
+
|
|
881
|
+
if (
|
|
882
|
+
subject !== undefined &&
|
|
883
|
+
mapping.subject.isActiveStatus(subject[mapping.subject.status]) &&
|
|
884
|
+
subject[mapping.subject.securityRevision] ===
|
|
885
|
+
record.evidence.revision.securityRevision &&
|
|
886
|
+
current !== undefined &&
|
|
887
|
+
current[mapping.pending.consumed] === false &&
|
|
888
|
+
record.evidence.bindingDigest === input.bindingDigest &&
|
|
889
|
+
DateTime.toEpochMillis(now) < DateTime.toEpochMillis(record.expiresAt)
|
|
890
|
+
) {
|
|
891
|
+
yield* transaction
|
|
892
|
+
.update(mapping.pending.table)
|
|
893
|
+
.set(
|
|
894
|
+
updateValues<any>([
|
|
895
|
+
[
|
|
896
|
+
mapping.pending.failedAttempts,
|
|
897
|
+
sql`case when ${pendingColumns(mapping).failedAttempts} < ${pendingColumns(mapping).attemptLimit} then ${pendingColumns(mapping).failedAttempts} + 1 else ${pendingColumns(mapping).failedAttempts} end`,
|
|
898
|
+
],
|
|
899
|
+
]),
|
|
900
|
+
)
|
|
901
|
+
.where(eq(pendingColumns(mapping).digest, input.digest));
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return receipt;
|
|
905
|
+
}),
|
|
906
|
+
),
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
return {
|
|
910
|
+
create: (input, now, prepare) =>
|
|
911
|
+
service.create(input, now, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
912
|
+
context: (input) => service.context(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
913
|
+
read: (input) => service.read(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
914
|
+
reject: (input, prepare) =>
|
|
915
|
+
service.reject(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
916
|
+
} satisfies PendingAuthentication<Claims>;
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
const sessionColumns = (mapping: any) => ({
|
|
920
|
+
sessionId: column(mapping.session.table, mapping.session.sessionId),
|
|
921
|
+
subjectId: column(mapping.session.table, mapping.session.subjectId),
|
|
922
|
+
digest: column(mapping.session.table, mapping.session.digest),
|
|
923
|
+
version: column(mapping.session.table, mapping.session.version),
|
|
924
|
+
securityRevision: column(mapping.session.table, mapping.session.securityRevision),
|
|
925
|
+
issuedAt: column(mapping.session.table, mapping.session.issuedAt),
|
|
926
|
+
expiresAt: column(mapping.session.table, mapping.session.expiresAt),
|
|
927
|
+
absoluteExpiresAt: column(mapping.session.table, mapping.session.absoluteExpiresAt),
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
export const makeSqlStatefulSessions = <Claims>(
|
|
931
|
+
database: Database,
|
|
932
|
+
mapping: StatefulSessionMapping<Claims, any, any, any, any, any, any, any>,
|
|
933
|
+
options: SessionSqlOptions,
|
|
934
|
+
) =>
|
|
935
|
+
Effect.map(LifecycleHooks, (hooks) => {
|
|
936
|
+
const c = sessionColumns(mapping);
|
|
937
|
+
|
|
938
|
+
const persistence = {
|
|
939
|
+
establish: <A>(
|
|
940
|
+
input: Parameters<StatefulSessionPersistence<Claims>["establish"]>[0],
|
|
941
|
+
prepare: PrepareSessionCommit<StatefulSessionRecord<Claims>, A>,
|
|
942
|
+
) =>
|
|
943
|
+
owned(
|
|
944
|
+
database,
|
|
945
|
+
options,
|
|
946
|
+
mapping.isConstraintConflict,
|
|
947
|
+
Effect.gen(function* () {
|
|
948
|
+
const transaction = yield* CurrentSessionSql;
|
|
949
|
+
const journal = yield* CurrentCommitJournal;
|
|
950
|
+
|
|
951
|
+
const { nativeSubjectId, requirement } = yield* validateEvidenceIn(
|
|
952
|
+
mapping,
|
|
953
|
+
input.evidence,
|
|
954
|
+
true,
|
|
955
|
+
);
|
|
956
|
+
|
|
957
|
+
let flowInsert: unknown | undefined;
|
|
958
|
+
let pendingExpiresAt: DateTime.Utc | undefined;
|
|
959
|
+
|
|
960
|
+
if (input.pending === undefined)
|
|
961
|
+
flowInsert = yield* ensureDirectFlowAvailable(
|
|
962
|
+
mapping,
|
|
963
|
+
input.evidence,
|
|
964
|
+
nativeSubjectId,
|
|
965
|
+
input.session.absoluteExpiresAt,
|
|
966
|
+
);
|
|
967
|
+
else {
|
|
968
|
+
if (mapping.pending === undefined) return yield* invalidPending();
|
|
969
|
+
const pending = yield* validatePending(mapping, input.pending);
|
|
970
|
+
|
|
971
|
+
if (!preservesRevision(input.evidence, pending.evidence))
|
|
972
|
+
return yield* invalidPending();
|
|
973
|
+
pendingExpiresAt = pending.expiresAt;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const nativeSessionId = yield* allocate(
|
|
977
|
+
options.mode,
|
|
978
|
+
mapping.session.allocateId,
|
|
979
|
+
mapping.session.allocateIdSync,
|
|
980
|
+
);
|
|
981
|
+
|
|
982
|
+
const sessionId = yield* mapping.sessionId.toSession(nativeSessionId);
|
|
983
|
+
|
|
984
|
+
const version = yield* allocate(
|
|
985
|
+
options.mode,
|
|
986
|
+
mapping.session.allocateVersion,
|
|
987
|
+
mapping.session.allocateVersionSync,
|
|
988
|
+
);
|
|
989
|
+
|
|
990
|
+
const assessed = yield* assessAuthentication(input.evidence, requirement);
|
|
991
|
+
const now = yield* freshNow;
|
|
992
|
+
|
|
993
|
+
if (
|
|
994
|
+
!assessed.satisfied ||
|
|
995
|
+
(pendingExpiresAt !== undefined &&
|
|
996
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(pendingExpiresAt)) ||
|
|
997
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.session.expiresAt) ||
|
|
998
|
+
DateTime.toEpochMillis(input.session.expiresAt) >
|
|
999
|
+
DateTime.toEpochMillis(input.session.absoluteExpiresAt)
|
|
1000
|
+
)
|
|
1001
|
+
return yield* stale();
|
|
1002
|
+
|
|
1003
|
+
const record = {
|
|
1004
|
+
...input.session,
|
|
1005
|
+
sessionId,
|
|
1006
|
+
version,
|
|
1007
|
+
subjectId: input.evidence.revision.subjectId,
|
|
1008
|
+
securityRevision: input.evidence.revision.securityRevision,
|
|
1009
|
+
assurance: assessed.assurance,
|
|
1010
|
+
provenance: yield* snapshotSessionAuthenticationProvenance({
|
|
1011
|
+
evidence: input.evidence,
|
|
1012
|
+
}),
|
|
1013
|
+
issuedAt: now,
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
const receipt = prepare(record, journal);
|
|
1017
|
+
|
|
1018
|
+
if (flowInsert !== undefined)
|
|
1019
|
+
yield* transaction.insert(mapping.flow.table).values(flowInsert);
|
|
1020
|
+
else
|
|
1021
|
+
yield* consumePending(
|
|
1022
|
+
{ ...mapping, pending: mapping.pending! },
|
|
1023
|
+
input.pending!,
|
|
1024
|
+
input.session.absoluteExpiresAt,
|
|
1025
|
+
);
|
|
1026
|
+
yield* transaction.insert(mapping.session.table).values(
|
|
1027
|
+
mapping.session.encodeInsert(record, {
|
|
1028
|
+
subjectId: nativeSubjectId,
|
|
1029
|
+
sessionId: nativeSessionId,
|
|
1030
|
+
}),
|
|
1031
|
+
);
|
|
1032
|
+
|
|
1033
|
+
return receipt;
|
|
1034
|
+
}).pipe(normalizeMutation(mapping)),
|
|
1035
|
+
),
|
|
1036
|
+
verify: (input: any) =>
|
|
1037
|
+
safeTransaction(
|
|
1038
|
+
inTransaction(
|
|
1039
|
+
database,
|
|
1040
|
+
Effect.gen(function* () {
|
|
1041
|
+
const read = yield* CurrentSessionSql;
|
|
1042
|
+
|
|
1043
|
+
const rows = yield* read
|
|
1044
|
+
.select()
|
|
1045
|
+
.from(mapping.session.table)
|
|
1046
|
+
.where(eq(c.digest, input.digest))
|
|
1047
|
+
.limit(1);
|
|
1048
|
+
|
|
1049
|
+
const row = rows[0];
|
|
1050
|
+
|
|
1051
|
+
if (row === undefined) return yield* invalidSession();
|
|
1052
|
+
const record = yield* mapping.session.decode(row);
|
|
1053
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(record.subjectId);
|
|
1054
|
+
const subjects = yield* readSubject(mapping, nativeSubjectId, false);
|
|
1055
|
+
const subject = subjects[0];
|
|
1056
|
+
const now = yield* freshNow;
|
|
1057
|
+
|
|
1058
|
+
if (
|
|
1059
|
+
subject === undefined ||
|
|
1060
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
1061
|
+
subject[mapping.subject.securityRevision] !== record.securityRevision ||
|
|
1062
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.expiresAt) ||
|
|
1063
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.absoluteExpiresAt)
|
|
1064
|
+
)
|
|
1065
|
+
return yield* invalidSession();
|
|
1066
|
+
|
|
1067
|
+
return record;
|
|
1068
|
+
}),
|
|
1069
|
+
),
|
|
1070
|
+
),
|
|
1071
|
+
rotate: <A>(
|
|
1072
|
+
input: Parameters<StatefulSessionPersistence<Claims>["rotate"]>[0],
|
|
1073
|
+
prepare: PrepareSessionCommit<StatefulSessionRecord<Claims>, A>,
|
|
1074
|
+
) =>
|
|
1075
|
+
owned(
|
|
1076
|
+
database,
|
|
1077
|
+
options,
|
|
1078
|
+
mapping.isConstraintConflict,
|
|
1079
|
+
Effect.gen(function* () {
|
|
1080
|
+
const transaction = yield* CurrentSessionSql;
|
|
1081
|
+
const journal = yield* CurrentCommitJournal;
|
|
1082
|
+
const nativeSessionId = yield* mapping.sessionId.toNative(input.sessionId);
|
|
1083
|
+
|
|
1084
|
+
const initial = (yield* transaction
|
|
1085
|
+
.select()
|
|
1086
|
+
.from(mapping.session.table)
|
|
1087
|
+
.where(eq(c.sessionId, nativeSessionId))
|
|
1088
|
+
.limit(1))[0];
|
|
1089
|
+
|
|
1090
|
+
if (initial === undefined) return yield* SessionConflict.make({});
|
|
1091
|
+
const initialRecord = yield* mapping.session.decode(initial);
|
|
1092
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(initialRecord.subjectId);
|
|
1093
|
+
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
1094
|
+
|
|
1095
|
+
const row = (yield* selectRows(
|
|
1096
|
+
transaction
|
|
1097
|
+
.select()
|
|
1098
|
+
.from(mapping.session.table)
|
|
1099
|
+
.where(eq(c.sessionId, nativeSessionId))
|
|
1100
|
+
.limit(1),
|
|
1101
|
+
options.locking,
|
|
1102
|
+
))[0];
|
|
1103
|
+
|
|
1104
|
+
if (row === undefined) return yield* SessionConflict.make({});
|
|
1105
|
+
const record = yield* mapping.session.decode(row);
|
|
1106
|
+
|
|
1107
|
+
const version = yield* allocate(
|
|
1108
|
+
options.mode,
|
|
1109
|
+
mapping.session.allocateVersion,
|
|
1110
|
+
mapping.session.allocateVersionSync,
|
|
1111
|
+
);
|
|
1112
|
+
|
|
1113
|
+
const now = yield* freshNow;
|
|
1114
|
+
|
|
1115
|
+
if (
|
|
1116
|
+
subject === undefined ||
|
|
1117
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
1118
|
+
subject[mapping.subject.securityRevision] !== input.expectedSecurityRevision ||
|
|
1119
|
+
record.securityRevision !== input.expectedSecurityRevision ||
|
|
1120
|
+
record.digest !== input.expectedDigest ||
|
|
1121
|
+
record.version !== input.expectedVersion ||
|
|
1122
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.expiresAt) ||
|
|
1123
|
+
DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.absoluteExpiresAt) ||
|
|
1124
|
+
DateTime.toEpochMillis(input.nextExpiresAt) >
|
|
1125
|
+
DateTime.toEpochMillis(record.absoluteExpiresAt) ||
|
|
1126
|
+
DateTime.toEpochMillis(input.nextExpiresAt) <= DateTime.toEpochMillis(now)
|
|
1127
|
+
)
|
|
1128
|
+
return yield* SessionConflict.make({});
|
|
1129
|
+
|
|
1130
|
+
const next = {
|
|
1131
|
+
...record,
|
|
1132
|
+
digest: input.nextDigest,
|
|
1133
|
+
credentialVersion: input.nextCredentialVersion,
|
|
1134
|
+
version,
|
|
1135
|
+
issuedAt: now,
|
|
1136
|
+
expiresAt: input.nextExpiresAt,
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
const receipt = prepare(next, journal);
|
|
1140
|
+
|
|
1141
|
+
yield* transaction
|
|
1142
|
+
.update(mapping.session.table)
|
|
1143
|
+
.set(mapping.session.encodeRotation(next))
|
|
1144
|
+
.where(
|
|
1145
|
+
and(
|
|
1146
|
+
eq(c.sessionId, nativeSessionId),
|
|
1147
|
+
eq(c.digest, input.expectedDigest),
|
|
1148
|
+
eq(c.version, input.expectedVersion),
|
|
1149
|
+
),
|
|
1150
|
+
);
|
|
1151
|
+
|
|
1152
|
+
return receipt;
|
|
1153
|
+
}),
|
|
1154
|
+
),
|
|
1155
|
+
revokeDigest: <A>(digest: TokenDigest, prepare: PrepareSessionCommit<boolean, A>) =>
|
|
1156
|
+
owned(
|
|
1157
|
+
database,
|
|
1158
|
+
options,
|
|
1159
|
+
mapping.isConstraintConflict,
|
|
1160
|
+
Effect.gen(function* () {
|
|
1161
|
+
const transaction = yield* CurrentSessionSql;
|
|
1162
|
+
const journal = yield* CurrentCommitJournal;
|
|
1163
|
+
|
|
1164
|
+
const initial = (yield* transaction
|
|
1165
|
+
.select()
|
|
1166
|
+
.from(mapping.session.table)
|
|
1167
|
+
.where(eq(c.digest, digest))
|
|
1168
|
+
.limit(1))[0];
|
|
1169
|
+
|
|
1170
|
+
if (initial === undefined) return prepare(false, journal);
|
|
1171
|
+
const record = yield* mapping.session.decode(initial);
|
|
1172
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(record.subjectId);
|
|
1173
|
+
|
|
1174
|
+
yield* readSubject(mapping, nativeSubjectId, true);
|
|
1175
|
+
|
|
1176
|
+
const row = (yield* selectRows(
|
|
1177
|
+
transaction.select().from(mapping.session.table).where(eq(c.digest, digest)).limit(1),
|
|
1178
|
+
options.locking,
|
|
1179
|
+
))[0];
|
|
1180
|
+
|
|
1181
|
+
const receipt = prepare(row !== undefined, journal);
|
|
1182
|
+
|
|
1183
|
+
if (row !== undefined)
|
|
1184
|
+
yield* transaction.delete(mapping.session.table).where(eq(c.digest, digest));
|
|
1185
|
+
|
|
1186
|
+
return receipt;
|
|
1187
|
+
}),
|
|
1188
|
+
),
|
|
1189
|
+
revoke: <A>(
|
|
1190
|
+
input: Parameters<StatefulSessionPersistence<Claims>["revoke"]>[0],
|
|
1191
|
+
prepare: PrepareSessionCommit<void, A>,
|
|
1192
|
+
) =>
|
|
1193
|
+
owned(
|
|
1194
|
+
database,
|
|
1195
|
+
options,
|
|
1196
|
+
mapping.isConstraintConflict,
|
|
1197
|
+
Effect.gen(function* () {
|
|
1198
|
+
const transaction = yield* CurrentSessionSql;
|
|
1199
|
+
const journal = yield* CurrentCommitJournal;
|
|
1200
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
1201
|
+
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
1202
|
+
|
|
1203
|
+
if (
|
|
1204
|
+
subject === undefined ||
|
|
1205
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
1206
|
+
subject[mapping.subject.securityRevision] !== input.expectedSecurityRevision
|
|
1207
|
+
)
|
|
1208
|
+
return yield* stale();
|
|
1209
|
+
const nativeSessionId = yield* mapping.sessionId.toNative(input.sessionId);
|
|
1210
|
+
const receipt = prepare(undefined, journal);
|
|
1211
|
+
|
|
1212
|
+
yield* transaction
|
|
1213
|
+
.delete(mapping.session.table)
|
|
1214
|
+
.where(and(eq(c.subjectId, nativeSubjectId), eq(c.sessionId, nativeSessionId)));
|
|
1215
|
+
|
|
1216
|
+
return receipt;
|
|
1217
|
+
}),
|
|
1218
|
+
),
|
|
1219
|
+
revokeAll: <A>(
|
|
1220
|
+
input: Parameters<StatefulSessionPersistence<Claims>["revokeAll"]>[0],
|
|
1221
|
+
prepare: PrepareSessionCommit<void, A>,
|
|
1222
|
+
) =>
|
|
1223
|
+
owned(
|
|
1224
|
+
database,
|
|
1225
|
+
options,
|
|
1226
|
+
mapping.isConstraintConflict,
|
|
1227
|
+
Effect.gen(function* () {
|
|
1228
|
+
const transaction = yield* CurrentSessionSql;
|
|
1229
|
+
const journal = yield* CurrentCommitJournal;
|
|
1230
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
1231
|
+
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
1232
|
+
|
|
1233
|
+
if (
|
|
1234
|
+
subject === undefined ||
|
|
1235
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
1236
|
+
subject[mapping.subject.securityRevision] !== input.expectedSecurityRevision
|
|
1237
|
+
)
|
|
1238
|
+
return yield* stale();
|
|
1239
|
+
const nextRevisionSync = mapping.subject.nextSecurityRevisionSync;
|
|
1240
|
+
|
|
1241
|
+
const next = yield* allocate(
|
|
1242
|
+
options.mode,
|
|
1243
|
+
mapping.subject.nextSecurityRevision?.(input.expectedSecurityRevision),
|
|
1244
|
+
nextRevisionSync === undefined
|
|
1245
|
+
? undefined
|
|
1246
|
+
: () => nextRevisionSync(input.expectedSecurityRevision),
|
|
1247
|
+
);
|
|
1248
|
+
|
|
1249
|
+
const receipt = prepare(undefined, journal);
|
|
1250
|
+
|
|
1251
|
+
yield* transaction
|
|
1252
|
+
.update(mapping.subject.table)
|
|
1253
|
+
.set(updateValues<any>([[mapping.subject.securityRevision, next]]))
|
|
1254
|
+
.where(
|
|
1255
|
+
and(
|
|
1256
|
+
eq(authorityColumns(mapping).subjectId, nativeSubjectId),
|
|
1257
|
+
eq(authorityColumns(mapping).subjectRevision, input.expectedSecurityRevision),
|
|
1258
|
+
),
|
|
1259
|
+
);
|
|
1260
|
+
yield* transaction
|
|
1261
|
+
.delete(mapping.session.table)
|
|
1262
|
+
.where(eq(c.subjectId, nativeSubjectId));
|
|
1263
|
+
|
|
1264
|
+
return receipt;
|
|
1265
|
+
}),
|
|
1266
|
+
),
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
const repository = {
|
|
1270
|
+
list: (input: any) =>
|
|
1271
|
+
safeTransaction(
|
|
1272
|
+
inTransaction(
|
|
1273
|
+
database,
|
|
1274
|
+
Effect.gen(function* () {
|
|
1275
|
+
const read = yield* CurrentSessionSql;
|
|
1276
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
1277
|
+
const subject = (yield* readSubject(mapping, nativeSubjectId, false))[0];
|
|
1278
|
+
|
|
1279
|
+
if (
|
|
1280
|
+
subject === undefined ||
|
|
1281
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status])
|
|
1282
|
+
)
|
|
1283
|
+
return { sessions: [] };
|
|
1284
|
+
|
|
1285
|
+
const cursor =
|
|
1286
|
+
input.cursor === undefined
|
|
1287
|
+
? undefined
|
|
1288
|
+
: yield* mapping.sessionId.toNative(input.cursor as any);
|
|
1289
|
+
|
|
1290
|
+
const now = yield* freshNow;
|
|
1291
|
+
|
|
1292
|
+
const rows = yield* read
|
|
1293
|
+
.select()
|
|
1294
|
+
.from(mapping.session.table)
|
|
1295
|
+
.where(
|
|
1296
|
+
and(
|
|
1297
|
+
eq(c.subjectId, nativeSubjectId),
|
|
1298
|
+
eq(c.securityRevision, subject[mapping.subject.securityRevision]),
|
|
1299
|
+
gt(c.expiresAt, mapping.session.encodeInstant(now)),
|
|
1300
|
+
gt(c.absoluteExpiresAt, mapping.session.encodeInstant(now)),
|
|
1301
|
+
cursor === undefined ? undefined : gt(c.sessionId, cursor),
|
|
1302
|
+
),
|
|
1303
|
+
)
|
|
1304
|
+
.orderBy(c.sessionId)
|
|
1305
|
+
.limit(input.limit + 1);
|
|
1306
|
+
|
|
1307
|
+
const decoded = yield* Effect.forEach(rows, (row: any) =>
|
|
1308
|
+
mapping.session.decode(row),
|
|
1309
|
+
);
|
|
1310
|
+
|
|
1311
|
+
const codec = Schema.toCodecJson(Schema.toType(SessionMetadata));
|
|
1312
|
+
|
|
1313
|
+
const sessions = yield* Effect.forEach(decoded.slice(0, input.limit), (record: any) =>
|
|
1314
|
+
Schema.encodeEffect(codec)(record).pipe(Effect.flatMap(Schema.decodeEffect(codec))),
|
|
1315
|
+
);
|
|
1316
|
+
|
|
1317
|
+
const extra = decoded[input.limit];
|
|
1318
|
+
|
|
1319
|
+
return {
|
|
1320
|
+
sessions,
|
|
1321
|
+
...(extra === undefined ? {} : { nextCursor: sessions.at(-1)?.sessionId }),
|
|
1322
|
+
};
|
|
1323
|
+
}),
|
|
1324
|
+
),
|
|
1325
|
+
),
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
return {
|
|
1329
|
+
statefulSessionPersistence: {
|
|
1330
|
+
establish: (input, prepare) =>
|
|
1331
|
+
persistence.establish(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1332
|
+
verify: (input) =>
|
|
1333
|
+
persistence.verify(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1334
|
+
rotate: (input, prepare) =>
|
|
1335
|
+
persistence.rotate(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1336
|
+
revokeDigest: (digest, prepare) =>
|
|
1337
|
+
persistence
|
|
1338
|
+
.revokeDigest(digest, prepare)
|
|
1339
|
+
.pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1340
|
+
revoke: (input, prepare) =>
|
|
1341
|
+
persistence.revoke(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1342
|
+
revokeAll: (input, prepare) =>
|
|
1343
|
+
persistence.revokeAll(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1344
|
+
} satisfies StatefulSessionPersistence<Claims>,
|
|
1345
|
+
sessionRepository: {
|
|
1346
|
+
list: (input) => repository.list(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1347
|
+
} satisfies SessionRepository,
|
|
1348
|
+
};
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
export const makeSqlSignedValidity = (
|
|
1352
|
+
database: Database,
|
|
1353
|
+
mapping: SignedSessionValidityMapping<any, any, any, any>,
|
|
1354
|
+
options: SessionSqlOptions,
|
|
1355
|
+
) =>
|
|
1356
|
+
Effect.map(LifecycleHooks, (hooks) => {
|
|
1357
|
+
const subject = subjectColumns(mapping);
|
|
1358
|
+
|
|
1359
|
+
const tombstone = {
|
|
1360
|
+
subjectId: column(mapping.tombstone.table, mapping.tombstone.subjectId),
|
|
1361
|
+
sessionId: column(mapping.tombstone.table, mapping.tombstone.sessionId),
|
|
1362
|
+
absoluteExpiresAt: column(mapping.tombstone.table, mapping.tombstone.absoluteExpiresAt),
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1365
|
+
const service = {
|
|
1366
|
+
verify: (session: SessionMetadata, _now: DateTime.Utc) =>
|
|
1367
|
+
safeTransaction(
|
|
1368
|
+
inTransaction(
|
|
1369
|
+
database,
|
|
1370
|
+
Effect.gen(function* () {
|
|
1371
|
+
const read = yield* CurrentSessionSql;
|
|
1372
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(session.subjectId);
|
|
1373
|
+
const nativeSessionId = yield* mapping.sessionId.toNative(session.sessionId);
|
|
1374
|
+
const subjects = yield* readSubject(mapping, nativeSubjectId, false);
|
|
1375
|
+
const row = subjects[0];
|
|
1376
|
+
|
|
1377
|
+
if (
|
|
1378
|
+
row === undefined ||
|
|
1379
|
+
!mapping.subject.isActiveStatus(row[mapping.subject.status]) ||
|
|
1380
|
+
row[mapping.subject.securityRevision] !== session.securityRevision
|
|
1381
|
+
)
|
|
1382
|
+
return yield* invalidSession();
|
|
1383
|
+
const authoritativeNow = yield* freshNow;
|
|
1384
|
+
|
|
1385
|
+
if (
|
|
1386
|
+
DateTime.toEpochMillis(authoritativeNow) >=
|
|
1387
|
+
DateTime.toEpochMillis(session.expiresAt) ||
|
|
1388
|
+
DateTime.toEpochMillis(authoritativeNow) >=
|
|
1389
|
+
DateTime.toEpochMillis(session.absoluteExpiresAt)
|
|
1390
|
+
)
|
|
1391
|
+
return yield* invalidSession();
|
|
1392
|
+
|
|
1393
|
+
const revoked = yield* read
|
|
1394
|
+
.select({ sessionId: tombstone.sessionId })
|
|
1395
|
+
.from(mapping.tombstone.table)
|
|
1396
|
+
.where(
|
|
1397
|
+
and(
|
|
1398
|
+
eq(tombstone.subjectId, nativeSubjectId),
|
|
1399
|
+
eq(tombstone.sessionId, nativeSessionId),
|
|
1400
|
+
gt(
|
|
1401
|
+
tombstone.absoluteExpiresAt,
|
|
1402
|
+
mapping.tombstone.encodeInstant(authoritativeNow),
|
|
1403
|
+
),
|
|
1404
|
+
),
|
|
1405
|
+
)
|
|
1406
|
+
.limit(1);
|
|
1407
|
+
|
|
1408
|
+
if (revoked.length > 0) return yield* invalidSession();
|
|
1409
|
+
}),
|
|
1410
|
+
),
|
|
1411
|
+
),
|
|
1412
|
+
revoke: <A>(
|
|
1413
|
+
input: Parameters<SignedSessionValidity["revoke"]>[0],
|
|
1414
|
+
prepare: PrepareSessionCommit<void, A>,
|
|
1415
|
+
) =>
|
|
1416
|
+
owned(
|
|
1417
|
+
database,
|
|
1418
|
+
options,
|
|
1419
|
+
mapping.isConstraintConflict,
|
|
1420
|
+
Effect.gen(function* () {
|
|
1421
|
+
const transaction = yield* CurrentSessionSql;
|
|
1422
|
+
const journal = yield* CurrentCommitJournal;
|
|
1423
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
1424
|
+
const row = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
1425
|
+
|
|
1426
|
+
if (
|
|
1427
|
+
row === undefined ||
|
|
1428
|
+
!mapping.subject.isActiveStatus(row[mapping.subject.status]) ||
|
|
1429
|
+
row[mapping.subject.securityRevision] !== input.expectedSecurityRevision
|
|
1430
|
+
)
|
|
1431
|
+
return yield* stale();
|
|
1432
|
+
const nativeSessionId = yield* mapping.sessionId.toNative(input.sessionId);
|
|
1433
|
+
|
|
1434
|
+
const existing = yield* transaction
|
|
1435
|
+
.select()
|
|
1436
|
+
.from(mapping.tombstone.table)
|
|
1437
|
+
.where(
|
|
1438
|
+
and(
|
|
1439
|
+
eq(tombstone.subjectId, nativeSubjectId),
|
|
1440
|
+
eq(tombstone.sessionId, nativeSessionId),
|
|
1441
|
+
),
|
|
1442
|
+
)
|
|
1443
|
+
.limit(1);
|
|
1444
|
+
|
|
1445
|
+
const receipt = prepare(undefined, journal);
|
|
1446
|
+
|
|
1447
|
+
if (existing[0] === undefined)
|
|
1448
|
+
yield* transaction.insert(mapping.tombstone.table).values(
|
|
1449
|
+
mapping.tombstone.encodeInsert({
|
|
1450
|
+
subjectId: nativeSubjectId,
|
|
1451
|
+
sessionId: nativeSessionId,
|
|
1452
|
+
absoluteExpiresAt: input.absoluteExpiresAt,
|
|
1453
|
+
}),
|
|
1454
|
+
);
|
|
1455
|
+
else {
|
|
1456
|
+
const existingExpiry = yield* mapping.tombstone.decodeInstant(
|
|
1457
|
+
existing[0][mapping.tombstone.absoluteExpiresAt],
|
|
1458
|
+
);
|
|
1459
|
+
|
|
1460
|
+
if (
|
|
1461
|
+
DateTime.toEpochMillis(input.absoluteExpiresAt) >
|
|
1462
|
+
DateTime.toEpochMillis(existingExpiry)
|
|
1463
|
+
)
|
|
1464
|
+
yield* transaction
|
|
1465
|
+
.update(mapping.tombstone.table)
|
|
1466
|
+
.set(
|
|
1467
|
+
updateValues<any>([
|
|
1468
|
+
[
|
|
1469
|
+
mapping.tombstone.absoluteExpiresAt,
|
|
1470
|
+
mapping.tombstone.encodeInstant(input.absoluteExpiresAt),
|
|
1471
|
+
],
|
|
1472
|
+
]),
|
|
1473
|
+
)
|
|
1474
|
+
.where(
|
|
1475
|
+
and(
|
|
1476
|
+
eq(tombstone.subjectId, nativeSubjectId),
|
|
1477
|
+
eq(tombstone.sessionId, nativeSessionId),
|
|
1478
|
+
),
|
|
1479
|
+
);
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
return receipt;
|
|
1483
|
+
}),
|
|
1484
|
+
),
|
|
1485
|
+
revokeAll: <A>(
|
|
1486
|
+
input: Parameters<SignedSessionValidity["revokeAll"]>[0],
|
|
1487
|
+
prepare: PrepareSessionCommit<void, A>,
|
|
1488
|
+
) =>
|
|
1489
|
+
owned(
|
|
1490
|
+
database,
|
|
1491
|
+
options,
|
|
1492
|
+
mapping.isConstraintConflict,
|
|
1493
|
+
Effect.gen(function* () {
|
|
1494
|
+
const transaction = yield* CurrentSessionSql;
|
|
1495
|
+
const journal = yield* CurrentCommitJournal;
|
|
1496
|
+
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
1497
|
+
const row = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
1498
|
+
|
|
1499
|
+
if (
|
|
1500
|
+
row === undefined ||
|
|
1501
|
+
!mapping.subject.isActiveStatus(row[mapping.subject.status]) ||
|
|
1502
|
+
row[mapping.subject.securityRevision] !== input.expectedSecurityRevision
|
|
1503
|
+
)
|
|
1504
|
+
return yield* stale();
|
|
1505
|
+
const nextRevisionSync = mapping.subject.nextSecurityRevisionSync;
|
|
1506
|
+
|
|
1507
|
+
const next = yield* allocate(
|
|
1508
|
+
options.mode,
|
|
1509
|
+
mapping.subject.nextSecurityRevision?.(input.expectedSecurityRevision),
|
|
1510
|
+
nextRevisionSync === undefined
|
|
1511
|
+
? undefined
|
|
1512
|
+
: () => nextRevisionSync(input.expectedSecurityRevision),
|
|
1513
|
+
);
|
|
1514
|
+
|
|
1515
|
+
const receipt = prepare(undefined, journal);
|
|
1516
|
+
|
|
1517
|
+
yield* transaction
|
|
1518
|
+
.update(mapping.subject.table)
|
|
1519
|
+
.set(updateValues<any>([[mapping.subject.securityRevision, next]]))
|
|
1520
|
+
.where(
|
|
1521
|
+
and(
|
|
1522
|
+
eq(subject.subjectId, nativeSubjectId),
|
|
1523
|
+
eq(subject.subjectRevision, input.expectedSecurityRevision),
|
|
1524
|
+
),
|
|
1525
|
+
);
|
|
1526
|
+
|
|
1527
|
+
return receipt;
|
|
1528
|
+
}),
|
|
1529
|
+
),
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
return {
|
|
1533
|
+
verify: (session, now) =>
|
|
1534
|
+
service.verify(session, now).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1535
|
+
revoke: (input, prepare) =>
|
|
1536
|
+
service.revoke(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1537
|
+
revokeAll: (input, prepare) =>
|
|
1538
|
+
service.revokeAll(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
1539
|
+
} satisfies SignedSessionValidity;
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
const stepUpColumns = (mapping: any) =>
|
|
1543
|
+
Object.fromEntries(
|
|
1544
|
+
[
|
|
1545
|
+
"digest",
|
|
1546
|
+
"version",
|
|
1547
|
+
"flowId",
|
|
1548
|
+
"subjectId",
|
|
1549
|
+
"bindingDigest",
|
|
1550
|
+
"snapshot",
|
|
1551
|
+
"expiresAt",
|
|
1552
|
+
"attemptLimit",
|
|
1553
|
+
"failedAttempts",
|
|
1554
|
+
"consumed",
|
|
1555
|
+
].map((key) => [key, column(mapping.intent.table, mapping.intent[key])]),
|
|
1556
|
+
);
|
|
1557
|
+
|
|
1558
|
+
const stepUpLocator = Effect.fn("DrizzleStepUp.locator")(function* (
|
|
1559
|
+
mapping: AnyStepUpMapping,
|
|
1560
|
+
digest: TokenDigest,
|
|
1561
|
+
locking: boolean,
|
|
1562
|
+
expiresAt?: DateTime.Utc,
|
|
1563
|
+
) {
|
|
1564
|
+
const database = yield* CurrentSessionSql;
|
|
1565
|
+
|
|
1566
|
+
return yield* selectRows(
|
|
1567
|
+
database
|
|
1568
|
+
.select()
|
|
1569
|
+
.from(mapping.intent.table)
|
|
1570
|
+
.where(
|
|
1571
|
+
and(
|
|
1572
|
+
eq(stepUpColumns(mapping).digest, digest),
|
|
1573
|
+
expiresAt === undefined
|
|
1574
|
+
? undefined
|
|
1575
|
+
: eq(stepUpColumns(mapping).expiresAt, mapping.intent.encodeInstant(expiresAt)),
|
|
1576
|
+
),
|
|
1577
|
+
)
|
|
1578
|
+
.limit(1),
|
|
1579
|
+
locking,
|
|
1580
|
+
).pipe(Effect.map((rows) => rows[0]));
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
const stepUpAuthority = Effect.fn("DrizzleStepUp.authority")(function* (
|
|
1584
|
+
mapping: AnyStepUpMapping,
|
|
1585
|
+
revision: AuthenticationRevision,
|
|
1586
|
+
locking: boolean,
|
|
1587
|
+
) {
|
|
1588
|
+
const current = yield* captureDetailsIn(
|
|
1589
|
+
mapping,
|
|
1590
|
+
revision.subjectId,
|
|
1591
|
+
revision.credentials.map((c) => c.credentialId),
|
|
1592
|
+
locking,
|
|
1593
|
+
);
|
|
1594
|
+
|
|
1595
|
+
if (!sameStepUpRevision(current.revision, revision)) return yield* stale();
|
|
1596
|
+
const requirement = yield* mapping.subject.decodeRequirement(current.subject);
|
|
1597
|
+
|
|
1598
|
+
return {
|
|
1599
|
+
nativeSubjectId: yield* mapping.subjectId.toNative(revision.subjectId),
|
|
1600
|
+
requirement,
|
|
1601
|
+
};
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
const stepUpSource = Effect.fn("DrizzleStepUp.source")(function* (
|
|
1605
|
+
mapping: AnyStepUpMapping,
|
|
1606
|
+
intent: SessionStepUpIntent,
|
|
1607
|
+
nativeSubjectId: unknown,
|
|
1608
|
+
now: DateTime.Utc,
|
|
1609
|
+
locking: boolean,
|
|
1610
|
+
) {
|
|
1611
|
+
const database = yield* CurrentSessionSql;
|
|
1612
|
+
|
|
1613
|
+
if (!stepUpIntentLive(intent, mapping.source.kind, now))
|
|
1614
|
+
return yield* SessionStepUpInvalid.make({});
|
|
1615
|
+
const source = mapping.source;
|
|
1616
|
+
|
|
1617
|
+
if (source.kind === "StatelessSigned") return { nativeSessionId: undefined, row: undefined };
|
|
1618
|
+
const nativeSessionId = yield* source.sessionId.toNative(intent.sourceSessionId);
|
|
1619
|
+
|
|
1620
|
+
if (source.kind === "StateAssistedSigned") {
|
|
1621
|
+
const t = source.tombstone;
|
|
1622
|
+
|
|
1623
|
+
const found = yield* selectRows(
|
|
1624
|
+
database
|
|
1625
|
+
.select()
|
|
1626
|
+
.from(t.table)
|
|
1627
|
+
.where(
|
|
1628
|
+
and(
|
|
1629
|
+
eq(column(t.table, t.subjectId), nativeSubjectId),
|
|
1630
|
+
eq(column(t.table, t.sessionId), nativeSessionId),
|
|
1631
|
+
gt(column(t.table, t.absoluteExpiresAt), t.encodeInstant(now)),
|
|
1632
|
+
),
|
|
1633
|
+
)
|
|
1634
|
+
.limit(1),
|
|
1635
|
+
locking,
|
|
1636
|
+
);
|
|
1637
|
+
|
|
1638
|
+
if (found.length > 0) return yield* SessionStepUpInvalid.make({});
|
|
1639
|
+
|
|
1640
|
+
return { nativeSessionId, row: undefined };
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
const s = source.session,
|
|
1644
|
+
c = sessionColumns(source);
|
|
1645
|
+
|
|
1646
|
+
const row = (yield* selectRows(
|
|
1647
|
+
database
|
|
1648
|
+
.select()
|
|
1649
|
+
.from(s.table)
|
|
1650
|
+
.where(
|
|
1651
|
+
and(
|
|
1652
|
+
eq(c.sessionId, nativeSessionId),
|
|
1653
|
+
eq(c.subjectId, nativeSubjectId),
|
|
1654
|
+
eq(c.securityRevision, intent.revision.securityRevision),
|
|
1655
|
+
eq(column(s.table, s.credentialVersion), intent.sourceCredentialVersion),
|
|
1656
|
+
eq(column(s.table, s.authenticatedAt), s.encodeInstant(intent.sourceAuthenticatedAt)),
|
|
1657
|
+
eq(c.expiresAt, s.encodeInstant(intent.sourceExpiresAt)),
|
|
1658
|
+
eq(c.absoluteExpiresAt, s.encodeInstant(intent.sourceAbsoluteExpiresAt)),
|
|
1659
|
+
gt(c.expiresAt, s.encodeInstant(now)),
|
|
1660
|
+
gt(c.absoluteExpiresAt, s.encodeInstant(now)),
|
|
1661
|
+
),
|
|
1662
|
+
)
|
|
1663
|
+
.limit(1),
|
|
1664
|
+
locking,
|
|
1665
|
+
))[0];
|
|
1666
|
+
|
|
1667
|
+
if (row === undefined) return yield* SessionStepUpInvalid.make({});
|
|
1668
|
+
|
|
1669
|
+
return { nativeSessionId, row };
|
|
1670
|
+
});
|
|
1671
|
+
|
|
1672
|
+
const readSqlStepUp = Effect.fn("DrizzleStepUp.read")(function* (
|
|
1673
|
+
mapping: AnyStepUpMapping,
|
|
1674
|
+
digest: TokenDigest,
|
|
1675
|
+
locking: boolean,
|
|
1676
|
+
) {
|
|
1677
|
+
const first = yield* stepUpLocator(mapping, digest, false);
|
|
1678
|
+
|
|
1679
|
+
if (first === undefined) return yield* SessionStepUpInvalid.make({});
|
|
1680
|
+
const intent = yield* decodeStepUpIntent(first[mapping.intent.snapshot]);
|
|
1681
|
+
const authority = yield* stepUpAuthority(mapping, intent.revision, locking);
|
|
1682
|
+
|
|
1683
|
+
const source = yield* stepUpSource(
|
|
1684
|
+
mapping,
|
|
1685
|
+
intent,
|
|
1686
|
+
authority.nativeSubjectId,
|
|
1687
|
+
yield* freshNow,
|
|
1688
|
+
locking,
|
|
1689
|
+
);
|
|
1690
|
+
|
|
1691
|
+
const row = yield* stepUpLocator(mapping, digest, locking, intent.expiresAt);
|
|
1692
|
+
const m = mapping.intent;
|
|
1693
|
+
|
|
1694
|
+
if (
|
|
1695
|
+
row === undefined ||
|
|
1696
|
+
row[m.snapshot] !== first[m.snapshot] ||
|
|
1697
|
+
row[m.version] !== intent.version ||
|
|
1698
|
+
row[m.digest] !== intent.digest ||
|
|
1699
|
+
digest !== intent.digest ||
|
|
1700
|
+
row[m.flowId] !== intent.flowId ||
|
|
1701
|
+
row[m.bindingDigest] !== intent.bindingDigest ||
|
|
1702
|
+
!mapping.subjectId.equals(row[m.subjectId], authority.nativeSubjectId) ||
|
|
1703
|
+
Boolean(row[m.consumed]) ||
|
|
1704
|
+
!Schema.is(Schema.Natural)(row[m.failedAttempts]) ||
|
|
1705
|
+
row[m.failedAttempts] >= row[m.attemptLimit] ||
|
|
1706
|
+
row[m.attemptLimit] !== intent.attemptLimit ||
|
|
1707
|
+
!stepUpIntentLive(intent, mapping.source.kind, yield* freshNow)
|
|
1708
|
+
)
|
|
1709
|
+
return yield* SessionStepUpInvalid.make({});
|
|
1710
|
+
|
|
1711
|
+
return { row, intent, source, ...authority };
|
|
1712
|
+
});
|
|
1713
|
+
|
|
1714
|
+
type SqlStepUpRejectAbsence = SessionStepUpInvalid | StaleAuthentication;
|
|
1715
|
+
type SqlStepUpReadFailure = AdapterFailure | SqlStepUpRejectAbsence | SessionUnavailable;
|
|
1716
|
+
|
|
1717
|
+
const isSqlStepUpRejectAbsence = (error: unknown): error is SqlStepUpRejectAbsence => {
|
|
1718
|
+
const tag = typeof error === "object" && error !== null ? Reflect.get(error, "_tag") : undefined;
|
|
1719
|
+
|
|
1720
|
+
return tag === "SessionStepUpInvalid" || tag === "StaleAuthentication";
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
const recoverSqlStepUpRejectAbsence = <A, B, R>(
|
|
1724
|
+
effect: Effect.Effect<A, SqlStepUpReadFailure, R>,
|
|
1725
|
+
rejected: B,
|
|
1726
|
+
): Effect.Effect<A | B, AdapterFailure | SessionUnavailable, R> =>
|
|
1727
|
+
effect.pipe(
|
|
1728
|
+
Effect.catchCause((cause) => {
|
|
1729
|
+
if (
|
|
1730
|
+
cause.reasons.length > 0 &&
|
|
1731
|
+
cause.reasons.every(
|
|
1732
|
+
(reason) => Cause.isFailReason(reason) && isSqlStepUpRejectAbsence(reason.error),
|
|
1733
|
+
)
|
|
1734
|
+
)
|
|
1735
|
+
return Effect.succeed(rejected);
|
|
1736
|
+
|
|
1737
|
+
return Effect.failCause(
|
|
1738
|
+
Cause.map(cause, (error) => (isSqlStepUpRejectAbsence(error) ? unavailable() : error)),
|
|
1739
|
+
);
|
|
1740
|
+
}),
|
|
1741
|
+
);
|
|
1742
|
+
|
|
1743
|
+
/** Shared implementation; public driver entrypoints restore concrete tables/IDs. */
|
|
1744
|
+
export const makeSqlSessionStepUp = <Claims>(
|
|
1745
|
+
database: Database,
|
|
1746
|
+
mapping: SessionStepUpMapping<Claims, any, any, any, any, any, any, any>,
|
|
1747
|
+
options: SessionSqlOptions,
|
|
1748
|
+
) =>
|
|
1749
|
+
Effect.map(LifecycleHooks, (hooks) => {
|
|
1750
|
+
const m = mapping.intent,
|
|
1751
|
+
c = stepUpColumns(mapping);
|
|
1752
|
+
|
|
1753
|
+
const read = (digest: TokenDigest) =>
|
|
1754
|
+
mapFailureCause(
|
|
1755
|
+
safeTransaction(inTransaction(database, readSqlStepUp(mapping, digest, options.locking))),
|
|
1756
|
+
(error) => (error._tag === "StaleAuthentication" ? SessionStepUpInvalid.make({}) : error),
|
|
1757
|
+
);
|
|
1758
|
+
|
|
1759
|
+
const service = {
|
|
1760
|
+
create: <A>(
|
|
1761
|
+
input: Omit<SessionStepUpIntent, "version">,
|
|
1762
|
+
_now: DateTime.Utc,
|
|
1763
|
+
prepare: PrepareSessionCommit<SessionStepUpIntent, A>,
|
|
1764
|
+
) =>
|
|
1765
|
+
owned(
|
|
1766
|
+
database,
|
|
1767
|
+
options,
|
|
1768
|
+
mapping.isConstraintConflict,
|
|
1769
|
+
Effect.gen(function* () {
|
|
1770
|
+
const tx = yield* CurrentSessionSql;
|
|
1771
|
+
const journal = yield* CurrentCommitJournal;
|
|
1772
|
+
const authority = yield* stepUpAuthority(mapping, input.revision, options.locking);
|
|
1773
|
+
const version = yield* allocate(options.mode, m.allocateVersion, m.allocateVersionSync);
|
|
1774
|
+
const record: SessionStepUpIntent = { ...input, version };
|
|
1775
|
+
|
|
1776
|
+
yield* stepUpSource(
|
|
1777
|
+
mapping,
|
|
1778
|
+
record,
|
|
1779
|
+
authority.nativeSubjectId,
|
|
1780
|
+
yield* freshNow,
|
|
1781
|
+
options.locking,
|
|
1782
|
+
);
|
|
1783
|
+
|
|
1784
|
+
const existing = yield* selectRows(
|
|
1785
|
+
tx
|
|
1786
|
+
.select()
|
|
1787
|
+
.from(m.table)
|
|
1788
|
+
.where(or(eq(c.digest, input.digest), eq(c.flowId, input.flowId)))
|
|
1789
|
+
.limit(1),
|
|
1790
|
+
options.locking,
|
|
1791
|
+
);
|
|
1792
|
+
|
|
1793
|
+
if (existing.length > 0) return yield* SessionConflict.make({});
|
|
1794
|
+
const snapshot = yield* encodeStepUpIntent(record);
|
|
1795
|
+
|
|
1796
|
+
const values = {
|
|
1797
|
+
...m.encodeInsert(record, { subjectId: authority.nativeSubjectId }),
|
|
1798
|
+
...updateValues<any>([
|
|
1799
|
+
[m.digest, record.digest],
|
|
1800
|
+
[m.version, version],
|
|
1801
|
+
[m.flowId, record.flowId],
|
|
1802
|
+
[m.subjectId, authority.nativeSubjectId],
|
|
1803
|
+
[m.bindingDigest, record.bindingDigest],
|
|
1804
|
+
[m.snapshot, snapshot],
|
|
1805
|
+
[m.expiresAt, m.encodeInstant(record.expiresAt)],
|
|
1806
|
+
[m.attemptLimit, record.attemptLimit],
|
|
1807
|
+
[m.failedAttempts, 0],
|
|
1808
|
+
[m.consumed, false],
|
|
1809
|
+
]),
|
|
1810
|
+
};
|
|
1811
|
+
|
|
1812
|
+
const receipt = prepare(record, journal);
|
|
1813
|
+
|
|
1814
|
+
yield* tx.insert(m.table).values(values).pipe(normalizeMutation(mapping));
|
|
1815
|
+
|
|
1816
|
+
const inserted = (yield* tx
|
|
1817
|
+
.select()
|
|
1818
|
+
.from(m.table)
|
|
1819
|
+
.where(
|
|
1820
|
+
and(
|
|
1821
|
+
eq(c.digest, record.digest),
|
|
1822
|
+
eq(c.version, version),
|
|
1823
|
+
eq(c.flowId, record.flowId),
|
|
1824
|
+
eq(c.subjectId, authority.nativeSubjectId),
|
|
1825
|
+
eq(c.bindingDigest, record.bindingDigest),
|
|
1826
|
+
eq(c.snapshot, snapshot),
|
|
1827
|
+
eq(c.expiresAt, m.encodeInstant(record.expiresAt)),
|
|
1828
|
+
eq(c.attemptLimit, record.attemptLimit),
|
|
1829
|
+
eq(c.failedAttempts, 0),
|
|
1830
|
+
eq(c.consumed, false),
|
|
1831
|
+
),
|
|
1832
|
+
)
|
|
1833
|
+
.limit(1))[0];
|
|
1834
|
+
|
|
1835
|
+
if (inserted === undefined) return yield* unavailable();
|
|
1836
|
+
|
|
1837
|
+
return receipt;
|
|
1838
|
+
}),
|
|
1839
|
+
).pipe((effect) =>
|
|
1840
|
+
mapFailureCause(effect, (error) =>
|
|
1841
|
+
error._tag === "SessionStepUpInvalid" ? stale() : error,
|
|
1842
|
+
),
|
|
1843
|
+
),
|
|
1844
|
+
context: (input: any) =>
|
|
1845
|
+
mapFailureCause(
|
|
1846
|
+
read(input.digest).pipe(
|
|
1847
|
+
Effect.flatMap(({ intent }) =>
|
|
1848
|
+
snapshotPendingAuthenticationContext({
|
|
1849
|
+
flowId: intent.flowId,
|
|
1850
|
+
bindingDigest: intent.bindingDigest,
|
|
1851
|
+
revision: intent.revision,
|
|
1852
|
+
expiresAtMillis: DateTime.toEpochMillis(intent.expiresAt),
|
|
1853
|
+
}),
|
|
1854
|
+
),
|
|
1855
|
+
),
|
|
1856
|
+
(error) => (error._tag === "PendingAuthenticationInvalid" ? unavailable() : error),
|
|
1857
|
+
),
|
|
1858
|
+
read: (input: any) =>
|
|
1859
|
+
read(input.digest).pipe(
|
|
1860
|
+
Effect.flatMap((value) =>
|
|
1861
|
+
value.intent.bindingDigest === input.bindingDigest
|
|
1862
|
+
? Effect.succeed(value.intent)
|
|
1863
|
+
: Effect.fail(SessionStepUpInvalid.make({})),
|
|
1864
|
+
),
|
|
1865
|
+
),
|
|
1866
|
+
reject: <A>(
|
|
1867
|
+
input: Parameters<SessionStepUpPersistence<Claims>["reject"]>[0],
|
|
1868
|
+
prepare: PrepareSessionCommit<{ readonly _tag: "Rejected" }, A>,
|
|
1869
|
+
) =>
|
|
1870
|
+
owned(
|
|
1871
|
+
database,
|
|
1872
|
+
options,
|
|
1873
|
+
mapping.isConstraintConflict,
|
|
1874
|
+
Effect.gen(function* () {
|
|
1875
|
+
const tx = yield* CurrentSessionSql;
|
|
1876
|
+
const journal = yield* CurrentCommitJournal;
|
|
1877
|
+
|
|
1878
|
+
const selected = yield* recoverSqlStepUpRejectAbsence(
|
|
1879
|
+
readSqlStepUp(mapping, input.digest, options.locking).pipe(
|
|
1880
|
+
Effect.map((value) => ({ _tag: "Found" as const, value })),
|
|
1881
|
+
),
|
|
1882
|
+
{ _tag: "Rejected" as const },
|
|
1883
|
+
);
|
|
1884
|
+
|
|
1885
|
+
if (selected._tag === "Rejected") return prepare({ _tag: "Rejected" }, journal);
|
|
1886
|
+
const { row, intent } = selected.value;
|
|
1887
|
+
const receipt = prepare({ _tag: "Rejected" }, journal);
|
|
1888
|
+
|
|
1889
|
+
yield* tx
|
|
1890
|
+
.update(m.table)
|
|
1891
|
+
.set(updateValues<any>([[m.failedAttempts, sql`${c.failedAttempts} + 1`]]))
|
|
1892
|
+
.where(
|
|
1893
|
+
and(
|
|
1894
|
+
eq(c.digest, input.digest),
|
|
1895
|
+
eq(c.snapshot, row[m.snapshot]),
|
|
1896
|
+
eq(c.version, intent.version),
|
|
1897
|
+
eq(c.consumed, false),
|
|
1898
|
+
sql`${c.failedAttempts} < ${c.attemptLimit}`,
|
|
1899
|
+
),
|
|
1900
|
+
);
|
|
1901
|
+
const written = yield* stepUpLocator(mapping, input.digest, false);
|
|
1902
|
+
|
|
1903
|
+
if (
|
|
1904
|
+
written === undefined ||
|
|
1905
|
+
written[m.version] !== intent.version ||
|
|
1906
|
+
written[m.snapshot] !== row[m.snapshot] ||
|
|
1907
|
+
written[m.failedAttempts] !== row[m.failedAttempts] + 1
|
|
1908
|
+
)
|
|
1909
|
+
return yield* unavailable();
|
|
1910
|
+
|
|
1911
|
+
return receipt;
|
|
1912
|
+
}),
|
|
1913
|
+
),
|
|
1914
|
+
complete: <A>(
|
|
1915
|
+
plan: Parameters<SessionStepUpPersistence<Claims>["complete"]>[0],
|
|
1916
|
+
prepare: PrepareSessionCommit<SessionInspection<Claims>, A>,
|
|
1917
|
+
) =>
|
|
1918
|
+
owned(
|
|
1919
|
+
database,
|
|
1920
|
+
options,
|
|
1921
|
+
mapping.isConstraintConflict,
|
|
1922
|
+
Effect.gen(function* () {
|
|
1923
|
+
const tx = yield* CurrentSessionSql;
|
|
1924
|
+
const journal = yield* CurrentCommitJournal;
|
|
1925
|
+
|
|
1926
|
+
yield* validateStepUpPlan(plan);
|
|
1927
|
+
|
|
1928
|
+
// Lock the entire combined vector before source/intent, including added factors.
|
|
1929
|
+
const current = yield* stepUpAuthority(
|
|
1930
|
+
mapping,
|
|
1931
|
+
plan.evidence.revision,
|
|
1932
|
+
options.locking,
|
|
1933
|
+
);
|
|
1934
|
+
|
|
1935
|
+
const stored = yield* readSqlStepUp(mapping, plan.intent.digest, options.locking);
|
|
1936
|
+
|
|
1937
|
+
if (
|
|
1938
|
+
(yield* encodeStepUpIntent(stored.intent)) !==
|
|
1939
|
+
(yield* encodeStepUpIntent(plan.intent))
|
|
1940
|
+
)
|
|
1941
|
+
return yield* SessionStepUpInvalid.make({});
|
|
1942
|
+
|
|
1943
|
+
const base = yield* assessAuthentication(plan.evidence, current.requirement).pipe(
|
|
1944
|
+
Effect.mapError(() => stale()),
|
|
1945
|
+
);
|
|
1946
|
+
|
|
1947
|
+
const profile = yield* assessAuthentication(
|
|
1948
|
+
plan.evidence,
|
|
1949
|
+
stored.intent.requirement,
|
|
1950
|
+
).pipe(Effect.mapError(() => stale()));
|
|
1951
|
+
|
|
1952
|
+
if (!base.satisfied || !profile.satisfied) return yield* stale();
|
|
1953
|
+
|
|
1954
|
+
const replacement = plan.replacement,
|
|
1955
|
+
now = yield* freshNow;
|
|
1956
|
+
|
|
1957
|
+
if (
|
|
1958
|
+
DateTime.toEpochMillis(replacement.inspection.session.expiresAt) >
|
|
1959
|
+
DateTime.toEpochMillis(stored.intent.sourceAbsoluteExpiresAt) ||
|
|
1960
|
+
DateTime.toEpochMillis(now) <
|
|
1961
|
+
DateTime.toEpochMillis(replacement.inspection.session.issuedAt) ||
|
|
1962
|
+
DateTime.toEpochMillis(now) >=
|
|
1963
|
+
Math.min(
|
|
1964
|
+
DateTime.toEpochMillis(replacement.inspection.session.expiresAt),
|
|
1965
|
+
DateTime.toEpochMillis(stored.intent.expiresAt),
|
|
1966
|
+
)
|
|
1967
|
+
)
|
|
1968
|
+
return yield* SessionStepUpInvalid.make({});
|
|
1969
|
+
let rotation: any;
|
|
1970
|
+
|
|
1971
|
+
if (replacement._tag === "Stateful") {
|
|
1972
|
+
if (mapping.source.kind !== "Stateful") return yield* SessionStepUpInvalid.make({});
|
|
1973
|
+
|
|
1974
|
+
const s = mapping.source.session,
|
|
1975
|
+
row = stored.source.row;
|
|
1976
|
+
|
|
1977
|
+
if (
|
|
1978
|
+
row[s.digest] !== replacement.expectedDigest ||
|
|
1979
|
+
row[s.version] !== replacement.expectedRowVersion
|
|
1980
|
+
)
|
|
1981
|
+
return yield* SessionConflict.make({});
|
|
1982
|
+
|
|
1983
|
+
const version = yield* allocate(
|
|
1984
|
+
options.mode,
|
|
1985
|
+
s.allocateVersion,
|
|
1986
|
+
s.allocateVersionSync,
|
|
1987
|
+
);
|
|
1988
|
+
|
|
1989
|
+
const next: StatefulSessionRecord<Claims> = {
|
|
1990
|
+
...replacement.inspection.session,
|
|
1991
|
+
provenance: replacement.inspection.provenance,
|
|
1992
|
+
credentialVersion: replacement.inspection.credentialVersion,
|
|
1993
|
+
digest: replacement.nextDigest,
|
|
1994
|
+
version,
|
|
1995
|
+
};
|
|
1996
|
+
|
|
1997
|
+
rotation = {
|
|
1998
|
+
...s.encodeRotation(next),
|
|
1999
|
+
...updateValues<any>([
|
|
2000
|
+
[s.version, version],
|
|
2001
|
+
[s.digest, next.digest],
|
|
2002
|
+
[s.credentialVersion, next.credentialVersion],
|
|
2003
|
+
[s.authenticatedAt, s.encodeInstant(next.assurance.authenticatedAt)],
|
|
2004
|
+
[s.issuedAt, s.encodeInstant(next.issuedAt)],
|
|
2005
|
+
[s.expiresAt, s.encodeInstant(next.expiresAt)],
|
|
2006
|
+
[s.absoluteExpiresAt, s.encodeInstant(next.absoluteExpiresAt)],
|
|
2007
|
+
]),
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
const completionVersion = yield* allocate(
|
|
2012
|
+
options.mode,
|
|
2013
|
+
m.allocateVersion,
|
|
2014
|
+
m.allocateVersionSync,
|
|
2015
|
+
);
|
|
2016
|
+
|
|
2017
|
+
if (completionVersion === stored.intent.version) return yield* unavailable();
|
|
2018
|
+
|
|
2019
|
+
const completionSnapshot = yield* encodeStepUpIntent({
|
|
2020
|
+
...stored.intent,
|
|
2021
|
+
version: completionVersion,
|
|
2022
|
+
});
|
|
2023
|
+
|
|
2024
|
+
const receipt = prepare(replacement.inspection, journal);
|
|
2025
|
+
|
|
2026
|
+
if (replacement._tag === "Stateful" && mapping.source.kind === "Stateful") {
|
|
2027
|
+
const s = mapping.source.session,
|
|
2028
|
+
sc = sessionColumns(mapping.source);
|
|
2029
|
+
|
|
2030
|
+
yield* tx
|
|
2031
|
+
.update(s.table)
|
|
2032
|
+
.set(rotation)
|
|
2033
|
+
.where(
|
|
2034
|
+
and(
|
|
2035
|
+
eq(sc.sessionId, stored.source.nativeSessionId),
|
|
2036
|
+
eq(sc.digest, replacement.expectedDigest),
|
|
2037
|
+
eq(sc.version, replacement.expectedRowVersion),
|
|
2038
|
+
),
|
|
2039
|
+
);
|
|
2040
|
+
|
|
2041
|
+
const written = (yield* tx
|
|
2042
|
+
.select()
|
|
2043
|
+
.from(s.table)
|
|
2044
|
+
.where(eq(sc.sessionId, stored.source.nativeSessionId))
|
|
2045
|
+
.limit(1))[0];
|
|
2046
|
+
|
|
2047
|
+
if (written === undefined || written[s.version] !== rotation[s.version])
|
|
2048
|
+
return yield* unavailable();
|
|
2049
|
+
const decoded = yield* s.decode(written);
|
|
2050
|
+
|
|
2051
|
+
if (decoded.version !== rotation[s.version] || !stepUpRotationMatches(plan, decoded))
|
|
2052
|
+
return yield* unavailable();
|
|
2053
|
+
} else if (
|
|
2054
|
+
replacement._tag === "StateAssistedSigned" &&
|
|
2055
|
+
mapping.source.kind === "StateAssistedSigned"
|
|
2056
|
+
) {
|
|
2057
|
+
const t = mapping.source.tombstone;
|
|
2058
|
+
|
|
2059
|
+
const owner = column(t.table, t.subjectId),
|
|
2060
|
+
id = column(t.table, t.sessionId),
|
|
2061
|
+
expiry = column(t.table, t.absoluteExpiresAt);
|
|
2062
|
+
|
|
2063
|
+
yield* tx
|
|
2064
|
+
.delete(t.table)
|
|
2065
|
+
.where(
|
|
2066
|
+
and(
|
|
2067
|
+
eq(owner, stored.nativeSubjectId),
|
|
2068
|
+
eq(id, stored.source.nativeSessionId),
|
|
2069
|
+
lte(expiry, t.encodeInstant(yield* freshNow)),
|
|
2070
|
+
),
|
|
2071
|
+
);
|
|
2072
|
+
|
|
2073
|
+
const values = t.encodeInsert({
|
|
2074
|
+
subjectId: stored.nativeSubjectId,
|
|
2075
|
+
sessionId: stored.source.nativeSessionId,
|
|
2076
|
+
absoluteExpiresAt: replacement.tombstoneUntil,
|
|
2077
|
+
});
|
|
2078
|
+
|
|
2079
|
+
yield* tx.insert(t.table).values(values).pipe(normalizeMutation(mapping));
|
|
2080
|
+
|
|
2081
|
+
const inserted = (yield* tx
|
|
2082
|
+
.select()
|
|
2083
|
+
.from(t.table)
|
|
2084
|
+
.where(
|
|
2085
|
+
and(
|
|
2086
|
+
eq(owner, stored.nativeSubjectId),
|
|
2087
|
+
eq(id, stored.source.nativeSessionId),
|
|
2088
|
+
eq(expiry, t.encodeInstant(replacement.tombstoneUntil)),
|
|
2089
|
+
),
|
|
2090
|
+
)
|
|
2091
|
+
.limit(1))[0];
|
|
2092
|
+
|
|
2093
|
+
if (inserted === undefined) return yield* unavailable();
|
|
2094
|
+
}
|
|
2095
|
+
yield* tx
|
|
2096
|
+
.update(m.table)
|
|
2097
|
+
.set(
|
|
2098
|
+
updateValues<any>([
|
|
2099
|
+
[m.consumed, true],
|
|
2100
|
+
[m.version, completionVersion],
|
|
2101
|
+
[m.snapshot, completionSnapshot],
|
|
2102
|
+
]),
|
|
2103
|
+
)
|
|
2104
|
+
.where(
|
|
2105
|
+
and(
|
|
2106
|
+
eq(c.digest, stored.intent.digest),
|
|
2107
|
+
eq(c.version, stored.intent.version),
|
|
2108
|
+
eq(c.snapshot, stored.row[m.snapshot]),
|
|
2109
|
+
eq(c.consumed, false),
|
|
2110
|
+
eq(c.failedAttempts, stored.row[m.failedAttempts]),
|
|
2111
|
+
),
|
|
2112
|
+
);
|
|
2113
|
+
const completed = yield* stepUpLocator(mapping, stored.intent.digest, false);
|
|
2114
|
+
|
|
2115
|
+
if (
|
|
2116
|
+
completed === undefined ||
|
|
2117
|
+
!completed[m.consumed] ||
|
|
2118
|
+
completed[m.version] !== completionVersion ||
|
|
2119
|
+
completed[m.snapshot] !== completionSnapshot
|
|
2120
|
+
)
|
|
2121
|
+
return yield* unavailable();
|
|
2122
|
+
const commitNow = yield* freshNow;
|
|
2123
|
+
|
|
2124
|
+
if (
|
|
2125
|
+
!stepUpIntentLive(stored.intent, mapping.source.kind, commitNow) ||
|
|
2126
|
+
DateTime.toEpochMillis(commitNow) >=
|
|
2127
|
+
DateTime.toEpochMillis(replacement.inspection.session.expiresAt) ||
|
|
2128
|
+
!(yield* assessAuthentication(plan.evidence, current.requirement).pipe(
|
|
2129
|
+
Effect.mapError(() => stale()),
|
|
2130
|
+
)).satisfied ||
|
|
2131
|
+
!(yield* assessAuthentication(plan.evidence, stored.intent.requirement).pipe(
|
|
2132
|
+
Effect.mapError(() => stale()),
|
|
2133
|
+
)).satisfied
|
|
2134
|
+
)
|
|
2135
|
+
return yield* stale();
|
|
2136
|
+
|
|
2137
|
+
return receipt;
|
|
2138
|
+
}),
|
|
2139
|
+
),
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
return {
|
|
2143
|
+
create: (input, now, prepare) =>
|
|
2144
|
+
service.create(input, now, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
2145
|
+
context: (input) => service.context(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
2146
|
+
read: (input) => service.read(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
2147
|
+
reject: (input, prepare) =>
|
|
2148
|
+
service.reject(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
2149
|
+
complete: (plan, prepare) =>
|
|
2150
|
+
service.complete(plan, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
2151
|
+
} satisfies SessionStepUpPersistence<Claims>;
|
|
2152
|
+
});
|