@yielded/auth-persistence 0.1.0-beta.7
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/README.md +21 -0
- package/dist/Drizzle.d.mts +28 -0
- package/dist/Drizzle.mjs +28 -0
- package/dist/DrizzleD1.d.mts +963 -0
- package/dist/DrizzleD1.mjs +29 -0
- package/dist/DrizzleD1.mjs.map +1 -0
- package/dist/DrizzleLibsql.d.mts +2284 -0
- package/dist/DrizzleLibsql.mjs +92 -0
- package/dist/DrizzleLibsql.mjs.map +1 -0
- package/dist/DrizzleMysql2.d.mts +1820 -0
- package/dist/DrizzleMysql2.mjs +55 -0
- package/dist/DrizzleMysql2.mjs.map +1 -0
- package/dist/DrizzlePglite.d.mts +1826 -0
- package/dist/DrizzlePglite.mjs +53 -0
- package/dist/DrizzlePglite.mjs.map +1 -0
- package/dist/DrizzlePostgres.d.mts +1826 -0
- package/dist/DrizzlePostgres.mjs +53 -0
- package/dist/DrizzlePostgres.mjs.map +1 -0
- package/dist/DrizzleSqliteBun.d.mts +2279 -0
- package/dist/DrizzleSqliteBun.mjs +70 -0
- package/dist/DrizzleSqliteBun.mjs.map +1 -0
- package/dist/DrizzleSqliteDo.d.mts +2329 -0
- package/dist/DrizzleSqliteDo.mjs +105 -0
- package/dist/DrizzleSqliteDo.mjs.map +1 -0
- package/dist/DrizzleSqliteNode.d.mts +2279 -0
- package/dist/DrizzleSqliteNode.mjs +70 -0
- package/dist/DrizzleSqliteNode.mjs.map +1 -0
- package/dist/DrizzleSqliteWasm.d.mts +2282 -0
- package/dist/DrizzleSqliteWasm.mjs +70 -0
- package/dist/DrizzleSqliteWasm.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 +62 -0
- package/dist/drizzle/d1-emails.mjs +580 -0
- package/dist/drizzle/d1-emails.mjs.map +1 -0
- package/dist/drizzle/d1-generated-statement.d.mts +2 -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 +31 -0
- package/dist/drizzle/d1-identity.mjs +119 -0
- package/dist/drizzle/d1-identity.mjs.map +1 -0
- package/dist/drizzle/d1-oauth.d.mts +301 -0
- package/dist/drizzle/d1-oauth.mjs +76 -0
- package/dist/drizzle/d1-oauth.mjs.map +1 -0
- package/dist/drizzle/d1-passkey.d.mts +51 -0
- package/dist/drizzle/d1-passkey.mjs +95 -0
- package/dist/drizzle/d1-passkey.mjs.map +1 -0
- package/dist/drizzle/d1-password-prepared.d.mts +25 -0
- package/dist/drizzle/d1-password-prepared.mjs +461 -0
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -0
- package/dist/drizzle/d1-passwords.d.mts +87 -0
- package/dist/drizzle/d1-passwords.mjs +1004 -0
- package/dist/drizzle/d1-passwords.mjs.map +1 -0
- package/dist/drizzle/d1-phone.d.mts +26 -0
- package/dist/drizzle/d1-phone.mjs +30 -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 +80 -0
- package/dist/drizzle/d1-proofs.mjs +830 -0
- package/dist/drizzle/d1-proofs.mjs.map +1 -0
- package/dist/drizzle/d1-sessions.d.mts +67 -0
- package/dist/drizzle/d1-sessions.mjs +966 -0
- package/dist/drizzle/d1-sessions.mjs.map +1 -0
- package/dist/drizzle/d1-totp.d.mts +26 -0
- package/dist/drizzle/d1-totp.mjs +27 -0
- package/dist/drizzle/d1-totp.mjs.map +1 -0
- package/dist/drizzle/email-model.d.mts +354 -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 +30 -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 +4 -0
- package/dist/drizzle/email-sql.mjs +9 -0
- package/dist/drizzle/email-sql.mjs.map +1 -0
- package/dist/drizzle/email-target.d.mts +20 -0
- package/dist/drizzle/email-target.mjs +72 -0
- package/dist/drizzle/email-target.mjs.map +1 -0
- package/dist/drizzle/model.d.mts +250 -0
- package/dist/drizzle/model.mjs +58 -0
- package/dist/drizzle/model.mjs.map +1 -0
- package/dist/drizzle/mysql-emails.d.mts +71 -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 +22 -0
- package/dist/drizzle/mysql-identity.mjs +94 -0
- package/dist/drizzle/mysql-identity.mjs.map +1 -0
- package/dist/drizzle/mysql-password-prepared.d.mts +30 -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 +86 -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 +75 -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 +237 -0
- package/dist/drizzle/mysql-sessions.mjs +53 -0
- package/dist/drizzle/mysql-sessions.mjs.map +1 -0
- package/dist/drizzle/mysql.d.mts +70 -0
- package/dist/drizzle/mysql.mjs +218 -0
- package/dist/drizzle/mysql.mjs.map +1 -0
- package/dist/drizzle/oauth-accounts.mjs +358 -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 +76 -0
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-flow.mjs +247 -0
- package/dist/drizzle/oauth-connected-flow.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-input.mjs +103 -0
- package/dist/drizzle/oauth-connected-input.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-maintenance.mjs +214 -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 +14 -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 +753 -0
- package/dist/drizzle/oauth-connected-target.mjs +91 -0
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -0
- package/dist/drizzle/oauth-drivers.mjs +51 -0
- package/dist/drizzle/oauth-drivers.mjs.map +1 -0
- package/dist/drizzle/oauth-flow.d.mts +5 -0
- package/dist/drizzle/oauth-flow.mjs +253 -0
- package/dist/drizzle/oauth-flow.mjs.map +1 -0
- package/dist/drizzle/oauth-input.mjs +127 -0
- package/dist/drizzle/oauth-input.mjs.map +1 -0
- package/dist/drizzle/oauth-model.d.mts +463 -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 +6 -0
- package/dist/drizzle/oauth-registration.mjs +374 -0
- package/dist/drizzle/oauth-registration.mjs.map +1 -0
- package/dist/drizzle/oauth-state.mjs +107 -0
- package/dist/drizzle/oauth-state.mjs.map +1 -0
- package/dist/drizzle/oauth-target.d.mts +111 -0
- package/dist/drizzle/oauth-target.mjs +246 -0
- package/dist/drizzle/oauth-target.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-kernel.mjs +8 -0
- package/dist/drizzle/passkey-kernel.mjs.map +1 -0
- package/dist/drizzle/passkey-model.d.mts +272 -0
- package/dist/drizzle/passkey-model.mjs +34 -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-state.mjs +7 -0
- package/dist/drizzle/passkey-state.mjs.map +1 -0
- package/dist/drizzle/passkey-target.d.mts +9 -0
- package/dist/drizzle/passkey-target.mjs +7 -0
- package/dist/drizzle/passkey-target.mjs.map +1 -0
- package/dist/drizzle/passkey-write-drivers.mjs +32 -0
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -0
- package/dist/drizzle/passkey-write-model.d.mts +190 -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-target.d.mts +11 -0
- package/dist/drizzle/passkey-write-target.mjs +7 -0
- package/dist/drizzle/passkey-write-target.mjs.map +1 -0
- package/dist/drizzle/password-model.d.mts +329 -0
- package/dist/drizzle/password-model.mjs +23 -0
- package/dist/drizzle/password-model.mjs.map +1 -0
- package/dist/drizzle/password-prepared-model.d.mts +94 -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 +390 -0
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -0
- package/dist/drizzle/password-prepared-state.mjs +104 -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 +56 -0
- package/dist/drizzle/password-prepared-target.mjs.map +1 -0
- package/dist/drizzle/password-registration.d.mts +19 -0
- package/dist/drizzle/password-registration.mjs +135 -0
- package/dist/drizzle/password-registration.mjs.map +1 -0
- package/dist/drizzle/password-sql.d.mts +5 -0
- package/dist/drizzle/password-sql.mjs +9 -0
- package/dist/drizzle/password-sql.mjs.map +1 -0
- package/dist/drizzle/password-target.d.mts +17 -0
- package/dist/drizzle/password-target.mjs +61 -0
- package/dist/drizzle/password-target.mjs.map +1 -0
- package/dist/drizzle/pg-emails.d.mts +72 -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 +31 -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 +87 -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 +76 -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 +238 -0
- package/dist/drizzle/pg-sessions.mjs +53 -0
- package/dist/drizzle/pg-sessions.mjs.map +1 -0
- package/dist/drizzle/pg.d.mts +81 -0
- package/dist/drizzle/pg.mjs +290 -0
- package/dist/drizzle/pg.mjs.map +1 -0
- package/dist/drizzle/phone-model.d.mts +115 -0
- package/dist/drizzle/phone-model.mjs +39 -0
- package/dist/drizzle/phone-model.mjs.map +1 -0
- package/dist/drizzle/phone-state.mjs +16 -0
- package/dist/drizzle/phone-state.mjs.map +1 -0
- package/dist/drizzle/phone-target.d.mts +17 -0
- package/dist/drizzle/phone-target.mjs +170 -0
- package/dist/drizzle/phone-target.mjs.map +1 -0
- package/dist/drizzle/proof-model.d.mts +286 -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 +4 -0
- package/dist/drizzle/proof-sql.mjs +8 -0
- package/dist/drizzle/proof-sql.mjs.map +1 -0
- package/dist/drizzle/proof-target.d.mts +12 -0
- package/dist/drizzle/proof-target.mjs +36 -0
- package/dist/drizzle/proof-target.mjs.map +1 -0
- package/dist/drizzle/query-operations.mjs +26 -0
- package/dist/drizzle/query-operations.mjs.map +1 -0
- package/dist/drizzle/session-model.d.mts +200 -0
- package/dist/drizzle/session-model.mjs +20 -0
- package/dist/drizzle/session-model.mjs.map +1 -0
- package/dist/drizzle/session-sql.mjs +8 -0
- package/dist/drizzle/session-sql.mjs.map +1 -0
- package/dist/drizzle/session-target.d.mts +28 -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 +91 -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 +78 -0
- package/dist/drizzle/sqlite.mjs +217 -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 +32 -0
- package/dist/drizzle/step-up-state.mjs.map +1 -0
- package/dist/drizzle/totp-model.d.mts +84 -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 +38 -0
- package/dist/drizzle/totp-state.mjs +287 -0
- package/dist/drizzle/totp-state.mjs.map +1 -0
- package/dist/drizzle/totp-target.d.mts +17 -0
- package/dist/drizzle/totp-target.mjs +81 -0
- package/dist/drizzle/totp-target.mjs.map +1 -0
- package/dist/drizzle/transaction-execution.d.mts +4 -0
- package/dist/drizzle/transaction-execution.mjs +11 -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 +2 -0
- package/dist/drizzle/transaction-owner.mjs +8 -0
- package/dist/drizzle/transaction-owner.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/internal/configuration.d.mts +174 -0
- package/dist/internal/configuration.mjs +7 -0
- package/dist/internal/configuration.mjs.map +1 -0
- package/dist/internal/drizzle-migrations.mjs +19 -0
- package/dist/internal/drizzle-migrations.mjs.map +1 -0
- package/dist/internal/drizzle-postgres.mjs +39 -0
- package/dist/internal/drizzle-postgres.mjs.map +1 -0
- package/dist/internal/drizzle-sqlite.mjs +37 -0
- package/dist/internal/drizzle-sqlite.mjs.map +1 -0
- package/dist/internal/email-kernel.d.mts +13 -0
- package/dist/internal/email-kernel.mjs +487 -0
- package/dist/internal/email-kernel.mjs.map +1 -0
- package/dist/internal/mapping-error.d.mts +11 -0
- package/dist/internal/mapping-error.mjs +30 -0
- package/dist/internal/mapping-error.mjs.map +1 -0
- package/dist/internal/passkey/admission.d.mts +7 -0
- package/dist/internal/passkey/admission.mjs +216 -0
- package/dist/internal/passkey/admission.mjs.map +1 -0
- package/dist/internal/passkey/credentials.d.mts +6 -0
- package/dist/internal/passkey/credentials.mjs +249 -0
- package/dist/internal/passkey/credentials.mjs.map +1 -0
- package/dist/internal/passkey/enrollment.mjs +138 -0
- package/dist/internal/passkey/enrollment.mjs.map +1 -0
- package/dist/internal/passkey/flow.d.mts +10 -0
- package/dist/internal/passkey/flow.mjs +452 -0
- package/dist/internal/passkey/flow.mjs.map +1 -0
- package/dist/internal/passkey/management.mjs +231 -0
- package/dist/internal/passkey/management.mjs.map +1 -0
- package/dist/internal/passkey/registration-ceremony.d.mts +9 -0
- package/dist/internal/passkey/registration-ceremony.mjs +129 -0
- package/dist/internal/passkey/registration-ceremony.mjs.map +1 -0
- package/dist/internal/passkey/registration-custody.d.mts +2 -0
- package/dist/internal/passkey/registration-custody.mjs +52 -0
- package/dist/internal/passkey/registration-custody.mjs.map +1 -0
- package/dist/internal/passkey/registration-write.mjs +211 -0
- package/dist/internal/passkey/registration-write.mjs.map +1 -0
- package/dist/internal/passkey/state.d.mts +5 -0
- package/dist/internal/passkey/state.mjs +234 -0
- package/dist/internal/passkey/state.mjs.map +1 -0
- package/dist/internal/passkey/target.d.mts +19 -0
- package/dist/internal/passkey/target.mjs +190 -0
- package/dist/internal/passkey/target.mjs.map +1 -0
- package/dist/internal/passkey/write-state.mjs +345 -0
- package/dist/internal/passkey/write-state.mjs.map +1 -0
- package/dist/internal/passkey/write-target.mjs +192 -0
- package/dist/internal/passkey/write-target.mjs.map +1 -0
- package/dist/internal/passkey-kernel.mjs +49 -0
- package/dist/internal/passkey-kernel.mjs.map +1 -0
- package/dist/internal/passkeys.mjs +367 -0
- package/dist/internal/passkeys.mjs.map +1 -0
- package/dist/internal/password-kernel.d.mts +13 -0
- package/dist/internal/password-kernel.mjs +704 -0
- package/dist/internal/password-kernel.mjs.map +1 -0
- package/dist/internal/persistence.mjs +289 -0
- package/dist/internal/persistence.mjs.map +1 -0
- package/dist/internal/phone-kernel.mjs +434 -0
- package/dist/internal/phone-kernel.mjs.map +1 -0
- package/dist/internal/proof-kernel.d.mts +9 -0
- package/dist/internal/proof-kernel.mjs +619 -0
- package/dist/internal/proof-kernel.mjs.map +1 -0
- package/dist/internal/query-operations.d.mts +3 -0
- package/dist/internal/registration.mjs +65 -0
- package/dist/internal/registration.mjs.map +1 -0
- package/dist/internal/session-kernel.mjs +737 -0
- package/dist/internal/session-kernel.mjs.map +1 -0
- package/dist/internal/sql-persistence.d.mts +11 -0
- package/dist/internal/sql-persistence.mjs +37 -0
- package/dist/internal/sql-persistence.mjs.map +1 -0
- package/dist/internal/sql-query.mjs +207 -0
- package/dist/internal/sql-query.mjs.map +1 -0
- package/dist/internal/sql-table.d.mts +37 -0
- package/dist/internal/sql-table.mjs +71 -0
- package/dist/internal/sql-table.mjs.map +1 -0
- package/dist/internal/storage-mapping.mjs +687 -0
- package/dist/internal/storage-mapping.mjs.map +1 -0
- package/dist/internal/storage-tables.d.mts +914 -0
- package/dist/internal/storage-tables.mjs +387 -0
- package/dist/internal/storage-tables.mjs.map +1 -0
- package/dist/internal/storage-validation.mjs +58 -0
- package/dist/internal/storage-validation.mjs.map +1 -0
- package/dist/internal/transaction-execution-kernel.d.mts +18 -0
- package/dist/internal/transaction-execution-kernel.mjs +118 -0
- package/dist/internal/transaction-execution-kernel.mjs.map +1 -0
- package/dist/internal/transaction-kernel.d.mts +7 -0
- package/dist/internal/transaction-kernel.mjs +260 -0
- package/dist/internal/transaction-kernel.mjs.map +1 -0
- package/package.json +1 -0
- package/src/Drizzle.ts +378 -0
- package/src/DrizzleD1.ts +136 -0
- package/src/DrizzleLibsql.ts +301 -0
- package/src/DrizzleMysql2.ts +184 -0
- package/src/DrizzlePglite.ts +174 -0
- package/src/DrizzlePostgres.ts +174 -0
- package/src/DrizzleSqliteBun.ts +258 -0
- package/src/DrizzleSqliteDo.ts +473 -0
- package/src/DrizzleSqliteNode.ts +259 -0
- package/src/DrizzleSqliteWasm.ts +263 -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 +1829 -0
- package/src/drizzle/d1-generated-statement.ts +129 -0
- package/src/drizzle/d1-identity.ts +375 -0
- package/src/drizzle/d1-oauth.ts +340 -0
- package/src/drizzle/d1-passkey.ts +373 -0
- package/src/drizzle/d1-password-prepared.ts +1270 -0
- package/src/drizzle/d1-passwords.ts +2656 -0
- package/src/drizzle/d1-phone.ts +96 -0
- package/src/drizzle/d1-planning.ts +104 -0
- package/src/drizzle/d1-proofs.ts +2305 -0
- package/src/drizzle/d1-sessions.ts +2857 -0
- package/src/drizzle/d1-totp.ts +78 -0
- package/src/drizzle/email-model.ts +516 -0
- package/src/drizzle/email-registration.ts +698 -0
- package/src/drizzle/email-sql.ts +24 -0
- package/src/drizzle/email-target.ts +243 -0
- package/src/drizzle/model.ts +463 -0
- package/src/drizzle/mysql-emails.ts +321 -0
- package/src/drizzle/mysql-identity.ts +324 -0
- package/src/drizzle/mysql-password-prepared.ts +204 -0
- package/src/drizzle/mysql-passwords.ts +339 -0
- package/src/drizzle/mysql-proofs.ts +181 -0
- package/src/drizzle/mysql-sessions.ts +741 -0
- package/src/drizzle/mysql.ts +687 -0
- package/src/drizzle/oauth-accounts.ts +804 -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 +465 -0
- package/src/drizzle/oauth-connected-flow.ts +441 -0
- package/src/drizzle/oauth-connected-input.ts +127 -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 +845 -0
- package/src/drizzle/oauth-connected-target.ts +264 -0
- package/src/drizzle/oauth-drivers.ts +569 -0
- package/src/drizzle/oauth-flow.ts +462 -0
- package/src/drizzle/oauth-input.ts +201 -0
- package/src/drizzle/oauth-model.ts +617 -0
- package/src/drizzle/oauth-mysql.ts +10 -0
- package/src/drizzle/oauth-owner.ts +29 -0
- package/src/drizzle/oauth-registration.ts +640 -0
- package/src/drizzle/oauth-state.ts +215 -0
- package/src/drizzle/oauth-target.ts +750 -0
- package/src/drizzle/passkey-drivers.ts +385 -0
- package/src/drizzle/passkey-kernel.ts +3 -0
- package/src/drizzle/passkey-model.ts +353 -0
- package/src/drizzle/passkey-registration-ceremony-model.ts +69 -0
- package/src/drizzle/passkey-state.ts +3 -0
- package/src/drizzle/passkey-target.ts +23 -0
- package/src/drizzle/passkey-write-drivers.ts +395 -0
- package/src/drizzle/passkey-write-model.ts +271 -0
- package/src/drizzle/passkey-write-target.ts +9 -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 +1191 -0
- package/src/drizzle/password-prepared-state.ts +231 -0
- package/src/drizzle/password-prepared-target.ts +160 -0
- package/src/drizzle/password-registration.ts +374 -0
- package/src/drizzle/password-sql.ts +12 -0
- package/src/drizzle/password-target.ts +224 -0
- package/src/drizzle/pg-emails.ts +321 -0
- package/src/drizzle/pg-password-prepared.ts +205 -0
- package/src/drizzle/pg-passwords.ts +338 -0
- package/src/drizzle/pg-proofs.ts +191 -0
- package/src/drizzle/pg-sessions.ts +750 -0
- package/src/drizzle/pg.ts +984 -0
- package/src/drizzle/phone-model.ts +190 -0
- package/src/drizzle/phone-state.ts +21 -0
- package/src/drizzle/phone-target.ts +472 -0
- package/src/drizzle/proof-model.ts +398 -0
- package/src/drizzle/proof-sql.ts +9 -0
- package/src/drizzle/proof-target.ts +122 -0
- package/src/drizzle/query-operations.ts +37 -0
- package/src/drizzle/session-model.ts +370 -0
- package/src/drizzle/session-sql.ts +13 -0
- package/src/drizzle/session-target.ts +338 -0
- package/src/drizzle/sqlite-emails.ts +366 -0
- package/src/drizzle/sqlite-identity.ts +344 -0
- package/src/drizzle/sqlite-password-prepared.ts +260 -0
- package/src/drizzle/sqlite-passwords.ts +497 -0
- package/src/drizzle/sqlite-proofs.ts +202 -0
- package/src/drizzle/sqlite-sessions.ts +971 -0
- package/src/drizzle/sqlite.ts +705 -0
- package/src/drizzle/standalone-guard.ts +38 -0
- package/src/drizzle/step-up-model.ts +128 -0
- package/src/drizzle/step-up-state.ts +139 -0
- package/src/drizzle/totp-model.ts +92 -0
- package/src/drizzle/totp-state.ts +525 -0
- package/src/drizzle/totp-target.ts +308 -0
- package/src/drizzle/transaction-execution.ts +12 -0
- package/src/drizzle/transaction-mysql.ts +104 -0
- package/src/drizzle/transaction-owner.ts +10 -0
- package/src/index.ts +4 -0
- package/src/internal/configuration.ts +282 -0
- package/src/internal/drizzle-migrations.ts +30 -0
- package/src/internal/drizzle-postgres.ts +81 -0
- package/src/internal/drizzle-sqlite.ts +79 -0
- package/src/internal/email-kernel.ts +1532 -0
- package/src/internal/mapping-error.ts +36 -0
- package/src/internal/passkey/admission.ts +362 -0
- package/src/internal/passkey/credentials.ts +511 -0
- package/src/internal/passkey/enrollment.ts +326 -0
- package/src/internal/passkey/flow.ts +1062 -0
- package/src/internal/passkey/management.ts +422 -0
- package/src/internal/passkey/registration-ceremony.ts +283 -0
- package/src/internal/passkey/registration-custody.ts +91 -0
- package/src/internal/passkey/registration-write.ts +426 -0
- package/src/internal/passkey/state.ts +354 -0
- package/src/internal/passkey/target.ts +586 -0
- package/src/internal/passkey/write-state.ts +681 -0
- package/src/internal/passkey/write-target.ts +452 -0
- package/src/internal/passkey-kernel.ts +102 -0
- package/src/internal/passkeys.ts +597 -0
- package/src/internal/password-kernel.ts +2122 -0
- package/src/internal/persistence.ts +590 -0
- package/src/internal/phone-kernel.ts +843 -0
- package/src/internal/proof-kernel.ts +1949 -0
- package/src/internal/query-operations.ts +26 -0
- package/src/internal/registration.ts +160 -0
- package/src/internal/session-kernel.ts +2210 -0
- package/src/internal/sql-persistence.ts +45 -0
- package/src/internal/sql-query.ts +298 -0
- package/src/internal/sql-table.ts +89 -0
- package/src/internal/storage-mapping.ts +706 -0
- package/src/internal/storage-tables.ts +408 -0
- package/src/internal/storage-validation.ts +117 -0
- package/src/internal/transaction-execution-kernel.ts +317 -0
- package/src/internal/transaction-kernel.ts +582 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { column, requireStandaloneConsume, updateValues } from "./model.mjs";
|
|
2
|
+
import { Cause, Context, DateTime, Duration, Effect, Schema } from "effect";
|
|
3
|
+
import { AuthStoreDecisions, reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
4
|
+
import { VerifiedEmail, timingSafeStringEqual } from "@yielded/auth/Schema";
|
|
5
|
+
import { AuthStore, EmailOtpRejected } from "@yielded/auth/AuthStore";
|
|
6
|
+
import { AuthRateLimited, AuthStoreError, InvalidRegistration } from "@yielded/auth/Errors";
|
|
7
|
+
import { InvalidOAuthState, OAuthStateDecisions, OAuthStateStore } from "@yielded/auth/OAuth";
|
|
8
|
+
import { and, eq, gt, sql } from "drizzle-orm";
|
|
9
|
+
//#region src/drizzle/mysql.ts
|
|
10
|
+
const selected = (row) => row;
|
|
11
|
+
const readError = () => AuthStoreError.make({ message: "Auth store read failed" });
|
|
12
|
+
const writeError = () => AuthStoreError.make({ message: "Auth store write failed" });
|
|
13
|
+
const isStoreFailure = Schema.is(AuthStoreError);
|
|
14
|
+
const mapStoreFailure = (failure) => (effect) => reportPersistenceFailure(effect, isStoreFailure).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, failure))));
|
|
15
|
+
const mapStoreReadFailure = mapStoreFailure(readError);
|
|
16
|
+
const mapStoreWriteFailure = mapStoreFailure(writeError);
|
|
17
|
+
/** MySQL/InnoDB implementation. Multi-step decisions stay values until commit. */
|
|
18
|
+
const makeMysqlAuthStoreServices = (database, mapping) => {
|
|
19
|
+
const db = database;
|
|
20
|
+
const challengeTable = mapping.challenge.table;
|
|
21
|
+
const ck = mapping.challenge.columns;
|
|
22
|
+
const c = Object.fromEntries(Object.entries(ck).map(([name, key]) => [name, column(challengeTable, key)]));
|
|
23
|
+
const registrationTable = mapping.registration.table;
|
|
24
|
+
const rk = mapping.registration.columns;
|
|
25
|
+
const r = Object.fromEntries(Object.entries(rk).map(([name, key]) => [name, column(registrationTable, key)]));
|
|
26
|
+
const issueChallenge = Effect.fn("DrizzleMysqlAuthStore.issueChallenge")(function* (input) {
|
|
27
|
+
const result = yield* Effect.suspend(() => db.transaction((tx) => Effect.gen(function* () {
|
|
28
|
+
yield* tx.insert(challengeTable).values(mapping.challenge.encodeInsert(input, {
|
|
29
|
+
namespace: mapping.challenge.identifierNamespace,
|
|
30
|
+
failedAttempts: 0,
|
|
31
|
+
consumed: false
|
|
32
|
+
})).onDuplicateKeyUpdate({ set: updateValues([[ck.challengeId, c.challengeId]]) });
|
|
33
|
+
const rows = yield* tx.select().from(challengeTable).where(and(eq(c.namespace, mapping.challenge.identifierNamespace), eq(c.value, input.email), eq(c.purpose, input.purpose))).for("update").limit(1);
|
|
34
|
+
if (rows[0] === void 0) return yield* AuthStoreError.make({ message: "Challenge digest conflict" });
|
|
35
|
+
const existing = yield* mapping.challenge.decode(selected(rows[0]));
|
|
36
|
+
const now = yield* DateTime.now;
|
|
37
|
+
const exactReplay = existing.challenge.challengeId === input.challengeId && timingSafeStringEqual(existing.challenge.tokenDigest, input.tokenDigest) && existing.challenge.email === input.email && existing.challenge.purpose === input.purpose && existing.challenge.otpKeyId === input.otpKeyId && timingSafeStringEqual(existing.challenge.otpDigest, input.otpDigest) && DateTime.toEpochMillis(existing.challenge.issuedAt) === DateTime.toEpochMillis(input.issuedAt) && DateTime.toEpochMillis(existing.challenge.expiresAt) === DateTime.toEpochMillis(input.expiresAt) && existing.challenge.attemptLimit === input.attemptLimit && Duration.toMillis(existing.challenge.resendCooldown) === Duration.toMillis(input.resendCooldown);
|
|
38
|
+
if (exactReplay && !existing.consumed && DateTime.toEpochMillis(existing.challenge.expiresAt) > DateTime.toEpochMillis(now)) return { _tag: "issued" };
|
|
39
|
+
if (exactReplay) return {
|
|
40
|
+
_tag: "limited",
|
|
41
|
+
retryAfterSeconds: 1
|
|
42
|
+
};
|
|
43
|
+
if (existing.challenge.challengeId === input.challengeId || DateTime.toEpochMillis(input.issuedAt) <= DateTime.toEpochMillis(existing.challenge.issuedAt)) return {
|
|
44
|
+
_tag: "limited",
|
|
45
|
+
retryAfterSeconds: 1
|
|
46
|
+
};
|
|
47
|
+
const eligibleAt = DateTime.toEpochMillis(existing.challenge.issuedAt) + Duration.toMillis(input.resendCooldown);
|
|
48
|
+
if (!existing.consumed && DateTime.toEpochMillis(now) < eligibleAt) return {
|
|
49
|
+
_tag: "limited",
|
|
50
|
+
retryAfterSeconds: Math.max(1, Math.ceil((eligibleAt - DateTime.toEpochMillis(now)) / 1e3))
|
|
51
|
+
};
|
|
52
|
+
const failedAttempts = DateTime.toEpochMillis(existing.challenge.expiresAt) > DateTime.toEpochMillis(now) ? existing.failedAttempts : 0;
|
|
53
|
+
yield* tx.update(challengeTable).set(mapping.challenge.encodeUpdate(input, {
|
|
54
|
+
namespace: mapping.challenge.identifierNamespace,
|
|
55
|
+
failedAttempts,
|
|
56
|
+
consumed: false
|
|
57
|
+
})).where(and(eq(c.namespace, mapping.challenge.identifierNamespace), eq(c.value, input.email), eq(c.purpose, input.purpose)));
|
|
58
|
+
return { _tag: "issued" };
|
|
59
|
+
}))).pipe(mapStoreWriteFailure);
|
|
60
|
+
if (result._tag === "limited") return yield* AuthRateLimited.make({ retryAfterSeconds: result.retryAfterSeconds });
|
|
61
|
+
});
|
|
62
|
+
const consumeChallengeDecision = Effect.fn("DrizzleMysqlAuthStore.consumeChallengeDecision")(function* (input) {
|
|
63
|
+
return yield* Effect.suspend(() => db.transaction((tx) => Effect.gen(function* () {
|
|
64
|
+
const rows = yield* tx.select().from(challengeTable).where(eq(c.tokenDigest, input.tokenDigest)).for("update").limit(1);
|
|
65
|
+
if (rows[0] === void 0) return {
|
|
66
|
+
_tag: "rejected",
|
|
67
|
+
reason: "missing_challenge"
|
|
68
|
+
};
|
|
69
|
+
const row = yield* mapping.challenge.decode(selected(rows[0]));
|
|
70
|
+
const now = yield* DateTime.now;
|
|
71
|
+
if (row.consumed) return {
|
|
72
|
+
_tag: "rejected",
|
|
73
|
+
reason: "consumed_challenge"
|
|
74
|
+
};
|
|
75
|
+
if (DateTime.toEpochMillis(row.challenge.expiresAt) <= DateTime.toEpochMillis(now)) return {
|
|
76
|
+
_tag: "rejected",
|
|
77
|
+
reason: "expired_challenge"
|
|
78
|
+
};
|
|
79
|
+
if (row.failedAttempts >= row.challenge.attemptLimit) return {
|
|
80
|
+
_tag: "rejected",
|
|
81
|
+
reason: "attempts_exhausted"
|
|
82
|
+
};
|
|
83
|
+
const candidate = input.otpDigests[row.challenge.otpKeyId];
|
|
84
|
+
const matches = candidate !== void 0 && timingSafeStringEqual(candidate, row.challenge.otpDigest);
|
|
85
|
+
yield* tx.update(challengeTable).set(updateValues(matches ? [[ck.consumed, true]] : [[ck.failedAttempts, sql`${c.failedAttempts} + 1`]])).where(eq(c.tokenDigest, input.tokenDigest));
|
|
86
|
+
return matches ? {
|
|
87
|
+
_tag: "accepted",
|
|
88
|
+
value: VerifiedEmail.make({
|
|
89
|
+
email: row.challenge.email,
|
|
90
|
+
purpose: row.challenge.purpose
|
|
91
|
+
})
|
|
92
|
+
} : {
|
|
93
|
+
_tag: "rejected",
|
|
94
|
+
reason: "bad_code"
|
|
95
|
+
};
|
|
96
|
+
}))).pipe(mapStoreWriteFailure);
|
|
97
|
+
});
|
|
98
|
+
const consumeChallenge = Effect.fn("DrizzleMysqlAuthStore.consumeChallenge")(function* (input) {
|
|
99
|
+
yield* requireStandaloneConsume(db);
|
|
100
|
+
const decision = yield* consumeChallengeDecision(input);
|
|
101
|
+
return decision._tag === "accepted" ? decision.value : yield* EmailOtpRejected.make({ reason: decision.reason });
|
|
102
|
+
});
|
|
103
|
+
const issueRegistration = Effect.fn("DrizzleMysqlAuthStore.issueRegistration")(function* (input) {
|
|
104
|
+
yield* Effect.suspend(() => db.insert(registrationTable).values(mapping.registration.encodeInsert(input, false))).pipe(mapStoreWriteFailure);
|
|
105
|
+
});
|
|
106
|
+
const inspectRegistration = Effect.fn("DrizzleMysqlAuthStore.inspectRegistration")(function* (digest) {
|
|
107
|
+
const now = yield* DateTime.now;
|
|
108
|
+
const rows = yield* Effect.suspend(() => db.select().from(registrationTable).where(and(eq(r.tokenDigest, digest), eq(r.consumed, false), gt(r.expiresAt, mapping.registration.encodeInstant(now)))).limit(1)).pipe(mapStoreReadFailure);
|
|
109
|
+
if (rows[0] === void 0) return yield* InvalidRegistration.make();
|
|
110
|
+
return (yield* Effect.suspend(() => mapping.registration.decode(selected(rows[0]))).pipe(mapStoreReadFailure)).registration;
|
|
111
|
+
});
|
|
112
|
+
const consumeRegistrationDecision = Effect.fn("DrizzleMysqlAuthStore.consumeRegistrationDecision")(function* (input) {
|
|
113
|
+
return yield* Effect.suspend(() => db.transaction((tx) => Effect.gen(function* () {
|
|
114
|
+
const rows = yield* tx.select().from(registrationTable).where(eq(r.tokenDigest, input.tokenDigest)).for("update").limit(1);
|
|
115
|
+
if (rows[0] === void 0) return { _tag: "rejected" };
|
|
116
|
+
const row = yield* mapping.registration.decode(selected(rows[0]));
|
|
117
|
+
const now = yield* DateTime.now;
|
|
118
|
+
if (row.consumed || DateTime.toEpochMillis(row.registration.expiresAt) <= DateTime.toEpochMillis(now)) return { _tag: "rejected" };
|
|
119
|
+
yield* tx.update(registrationTable).set(updateValues([[rk.consumed, true]])).where(eq(r.tokenDigest, input.tokenDigest));
|
|
120
|
+
return {
|
|
121
|
+
_tag: "accepted",
|
|
122
|
+
value: void 0
|
|
123
|
+
};
|
|
124
|
+
}))).pipe(mapStoreWriteFailure);
|
|
125
|
+
});
|
|
126
|
+
const consumeRegistration = Effect.fn("DrizzleMysqlAuthStore.consumeRegistration")(function* (input) {
|
|
127
|
+
yield* requireStandaloneConsume(db);
|
|
128
|
+
if ((yield* consumeRegistrationDecision(input))._tag === "rejected") return yield* InvalidRegistration.make();
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
authStore: AuthStore.of({
|
|
132
|
+
issueChallenge,
|
|
133
|
+
consumeChallenge,
|
|
134
|
+
issueRegistration,
|
|
135
|
+
inspectRegistration,
|
|
136
|
+
consumeRegistration
|
|
137
|
+
}),
|
|
138
|
+
decisions: {
|
|
139
|
+
consumeChallenge: consumeChallengeDecision,
|
|
140
|
+
consumeRegistration: consumeRegistrationDecision
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const makeMysqlOAuthStateServices = (database, mapping) => {
|
|
145
|
+
const db = database;
|
|
146
|
+
const stateTable = mapping.oauthState.table;
|
|
147
|
+
const sk = mapping.oauthState.columns;
|
|
148
|
+
const s = Object.fromEntries(Object.entries(sk).map(([name, key]) => [name, column(stateTable, key)]));
|
|
149
|
+
const issue = Effect.fn("DrizzleMysqlOAuthStateStore.issue")(function* (input) {
|
|
150
|
+
yield* Effect.suspend(() => db.insert(stateTable).values(mapping.oauthState.encodeInsert(input, false))).pipe(mapStoreWriteFailure);
|
|
151
|
+
});
|
|
152
|
+
const consumeDecision = Effect.fn("DrizzleMysqlOAuthStateStore.consumeDecision")(function* (digest) {
|
|
153
|
+
return yield* Effect.suspend(() => db.transaction((tx) => Effect.gen(function* () {
|
|
154
|
+
const rows = yield* tx.select().from(stateTable).where(eq(s.stateDigest, digest)).for("update").limit(1);
|
|
155
|
+
if (rows[0] === void 0) return { _tag: "rejected" };
|
|
156
|
+
const row = yield* mapping.oauthState.decode(selected(rows[0]));
|
|
157
|
+
const now = yield* DateTime.now;
|
|
158
|
+
if (row.consumed || DateTime.toEpochMillis(row.state.expiresAt) <= DateTime.toEpochMillis(now)) return { _tag: "rejected" };
|
|
159
|
+
yield* tx.update(stateTable).set(updateValues([[sk.consumed, true]])).where(eq(s.stateDigest, digest));
|
|
160
|
+
return {
|
|
161
|
+
_tag: "accepted",
|
|
162
|
+
value: row.state
|
|
163
|
+
};
|
|
164
|
+
}))).pipe(mapStoreWriteFailure);
|
|
165
|
+
});
|
|
166
|
+
const consume = Effect.fn("DrizzleMysqlOAuthStateStore.consume")(function* (digest) {
|
|
167
|
+
yield* requireStandaloneConsume(db);
|
|
168
|
+
const decision = yield* consumeDecision(digest);
|
|
169
|
+
return decision._tag === "accepted" ? decision.value : yield* InvalidOAuthState.make();
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
oauthStateStore: OAuthStateStore.of({
|
|
173
|
+
issue,
|
|
174
|
+
consume
|
|
175
|
+
}),
|
|
176
|
+
decisions: { consumeOAuthState: consumeDecision }
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const makeMysqlAuthServices = (database, mapping) => {
|
|
180
|
+
const auth = makeMysqlAuthStoreServices(database, mapping);
|
|
181
|
+
const oauth = makeMysqlOAuthStateServices(database, mapping);
|
|
182
|
+
return {
|
|
183
|
+
...auth,
|
|
184
|
+
...oauth,
|
|
185
|
+
decisions: {
|
|
186
|
+
...auth.decisions,
|
|
187
|
+
...oauth.decisions
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
function coordinateMysqlAuthStoreTransaction(acquire, options, body) {
|
|
192
|
+
return Effect.flatMap(acquire, (database) => database.transaction((transaction) => {
|
|
193
|
+
const decisions = makeMysqlAuthStoreServices(transaction, options.mapping).decisions;
|
|
194
|
+
const provided = Context.make(AuthStoreDecisions, decisions);
|
|
195
|
+
const work = Effect.provideContext(body, provided);
|
|
196
|
+
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
function coordinateMysqlOAuthStateTransaction(acquire, options, body) {
|
|
200
|
+
return Effect.flatMap(acquire, (database) => database.transaction((transaction) => {
|
|
201
|
+
const decisions = makeMysqlOAuthStateServices(transaction, options.mapping).decisions;
|
|
202
|
+
const provided = Context.make(OAuthStateDecisions, decisions);
|
|
203
|
+
const work = Effect.provideContext(body, provided);
|
|
204
|
+
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
function coordinateMysqlAuthTransaction(acquire, options, body) {
|
|
208
|
+
return Effect.flatMap(acquire, (database) => database.transaction((transaction) => {
|
|
209
|
+
const decisions = makeMysqlAuthServices(transaction, options.mapping).decisions;
|
|
210
|
+
const provided = Context.make(AuthStoreDecisions, decisions).pipe(Context.add(OAuthStateDecisions, decisions));
|
|
211
|
+
const work = Effect.provideContext(body, provided);
|
|
212
|
+
return options.transaction === void 0 ? work : Effect.provideService(work, options.transaction, options.transaction.of(transaction));
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { coordinateMysqlAuthStoreTransaction, coordinateMysqlAuthTransaction, coordinateMysqlOAuthStateTransaction, makeMysqlAuthServices, makeMysqlAuthStoreServices, makeMysqlOAuthStateServices };
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=mysql.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.mjs","names":[],"sources":["../../src/drizzle/mysql.ts"],"sourcesContent":["import { AuthStore, EmailOtpRejected } from \"@yielded/auth/AuthStore\";\nimport { AuthRateLimited, AuthStoreError, InvalidRegistration } from \"@yielded/auth/Errors\";\nimport {\n InvalidOAuthState,\n OAuthStateDecisions,\n OAuthStateStore,\n type OAuthState,\n} from \"@yielded/auth/OAuth\";\nimport { AuthStoreDecisions, reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport {\n timingSafeStringEqual,\n VerifiedEmail,\n type ConsumeChallenge,\n type ConsumeRegistration,\n type NewChallenge,\n type NewRegistration,\n type TokenDigest,\n} from \"@yielded/auth/Schema\";\n/* oxlint-disable no-explicit-any -- Drizzle's generic query builders lose the concrete consumer table through a runtime column map. Assertions stay in this adapter. */\nimport { and, eq, gt, sql, type AnyRelations, type InferSelectModel } from \"drizzle-orm\";\nimport type { EffectMysql2Database } from \"drizzle-orm/effect-mysql2\";\nimport type { AnyMySqlTable, MySqlColumn } from \"drizzle-orm/mysql-core\";\nimport { Cause, Context, DateTime, Duration, Effect, Schema } from \"effect\";\nimport type { SqlError } from \"effect/unstable/sql/SqlError\";\n\nimport {\n column,\n requireStandaloneConsume,\n updateValues,\n type AuthTables,\n type AuthStoreTables,\n type ChallengeConsumeDecision,\n type ConsumeDecision,\n type OAuthStateTables,\n} from \"./model\";\nimport type { SuppliedService } from \"./SuppliedService\";\n\ntype Database = EffectMysql2Database<AnyRelations>;\ntype RuntimeDatabase = EffectMysql2Database<any> & Parameters<typeof requireStandaloneConsume>[0];\ntype TransactionOf<D extends Database> = Parameters<Parameters<D[\"transaction\"]>[0]>[0];\n\nconst selected = <T extends AnyMySqlTable>(row: unknown): InferSelectModel<T> =>\n row as InferSelectModel<T>;\n\nconst readError = () => AuthStoreError.make({ message: \"Auth store read failed\" });\nconst writeError = () => AuthStoreError.make({ message: \"Auth store write failed\" });\nconst isStoreFailure = Schema.is(AuthStoreError);\n\nconst mapStoreFailure =\n (failure: () => AuthStoreError) =>\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, AuthStoreError, R> =>\n reportPersistenceFailure(effect, isStoreFailure).pipe(\n Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, failure))),\n );\n\nconst mapStoreReadFailure = mapStoreFailure(readError);\nconst mapStoreWriteFailure = mapStoreFailure(writeError);\n\n/** MySQL/InnoDB implementation. Multi-step decisions stay values until commit. */\nexport const makeMysqlAuthStoreServices = <C extends AnyMySqlTable, R extends AnyMySqlTable>(\n database: Database,\n mapping: AuthStoreTables<C, R>,\n) => {\n const db = database as RuntimeDatabase;\n const challengeTable = mapping.challenge.table;\n const ck = mapping.challenge.columns;\n\n const c = Object.fromEntries(\n Object.entries(ck).map(([name, key]) => [name, column(challengeTable, key)]),\n ) as Record<keyof typeof ck, MySqlColumn>;\n\n const registrationTable = mapping.registration.table;\n const rk = mapping.registration.columns;\n\n const r = Object.fromEntries(\n Object.entries(rk).map(([name, key]) => [name, column(registrationTable, key)]),\n ) as Record<keyof typeof rk, MySqlColumn>;\n\n const issueChallenge = Effect.fn(\"DrizzleMysqlAuthStore.issueChallenge\")(function* (\n input: NewChallenge,\n ) {\n const result = yield* Effect.suspend(() =>\n db.transaction((tx) =>\n Effect.gen(function* () {\n // A locking read of a missing InnoDB key takes a gap lock. Concurrent\n // first issuances would then deadlock when each transaction inserts.\n // The no-op upsert serializes on the declared series/digest unique\n // indexes before the row is read and evaluated below.\n yield* tx\n .insert(challengeTable as any)\n .values(\n mapping.challenge.encodeInsert(input, {\n namespace: mapping.challenge.identifierNamespace,\n failedAttempts: 0,\n consumed: false,\n }) as any,\n )\n .onDuplicateKeyUpdate({\n set: updateValues<C>([[ck.challengeId, c.challengeId]]) as any,\n });\n\n const rows = yield* tx\n .select()\n .from(challengeTable as any)\n .where(\n and(\n eq(c.namespace, mapping.challenge.identifierNamespace),\n eq(c.value, input.email),\n eq(c.purpose, input.purpose),\n ),\n )\n .for(\"update\")\n .limit(1);\n\n // A digest collision against another series is not a replay and must\n // never overwrite that row.\n if (rows[0] === undefined)\n return yield* AuthStoreError.make({ message: \"Challenge digest conflict\" });\n const existing = yield* mapping.challenge.decode(selected<C>(rows[0]));\n const now = yield* DateTime.now;\n\n const exactReplay =\n existing.challenge.challengeId === input.challengeId &&\n timingSafeStringEqual(existing.challenge.tokenDigest, input.tokenDigest) &&\n existing.challenge.email === input.email &&\n existing.challenge.purpose === input.purpose &&\n existing.challenge.otpKeyId === input.otpKeyId &&\n timingSafeStringEqual(existing.challenge.otpDigest, input.otpDigest) &&\n DateTime.toEpochMillis(existing.challenge.issuedAt) ===\n DateTime.toEpochMillis(input.issuedAt) &&\n DateTime.toEpochMillis(existing.challenge.expiresAt) ===\n DateTime.toEpochMillis(input.expiresAt) &&\n existing.challenge.attemptLimit === input.attemptLimit &&\n Duration.toMillis(existing.challenge.resendCooldown) ===\n Duration.toMillis(input.resendCooldown);\n\n // Retrying an identical still-live request is idempotent. In\n // particular, it does not reset the persisted wrong-attempt budget.\n if (\n exactReplay &&\n !existing.consumed &&\n DateTime.toEpochMillis(existing.challenge.expiresAt) > DateTime.toEpochMillis(now)\n )\n return { _tag: \"issued\" } as const;\n if (exactReplay) return { _tag: \"limited\", retryAfterSeconds: 1 } as const;\n if (\n existing.challenge.challengeId === input.challengeId ||\n DateTime.toEpochMillis(input.issuedAt) <=\n DateTime.toEpochMillis(existing.challenge.issuedAt)\n )\n return { _tag: \"limited\", retryAfterSeconds: 1 } as const;\n\n const eligibleAt =\n DateTime.toEpochMillis(existing.challenge.issuedAt) +\n Duration.toMillis(input.resendCooldown);\n\n if (!existing.consumed && DateTime.toEpochMillis(now) < eligibleAt) {\n return {\n _tag: \"limited\",\n retryAfterSeconds: Math.max(\n 1,\n Math.ceil((eligibleAt - DateTime.toEpochMillis(now)) / 1000),\n ),\n } as const;\n }\n\n const failedAttempts =\n DateTime.toEpochMillis(existing.challenge.expiresAt) > DateTime.toEpochMillis(now)\n ? existing.failedAttempts\n : 0;\n\n yield* tx\n .update(challengeTable as any)\n .set(\n mapping.challenge.encodeUpdate(input, {\n namespace: mapping.challenge.identifierNamespace,\n failedAttempts,\n consumed: false,\n }) as any,\n )\n .where(\n and(\n eq(c.namespace, mapping.challenge.identifierNamespace),\n eq(c.value, input.email),\n eq(c.purpose, input.purpose),\n ),\n );\n\n return { _tag: \"issued\" } as const;\n }),\n ),\n ).pipe(mapStoreWriteFailure);\n\n if (result._tag === \"limited\")\n return yield* AuthRateLimited.make({ retryAfterSeconds: result.retryAfterSeconds });\n });\n\n const consumeChallengeDecision = Effect.fn(\"DrizzleMysqlAuthStore.consumeChallengeDecision\")(\n function* (\n input: ConsumeChallenge,\n ): Effect.fn.Return<ChallengeConsumeDecision, AuthStoreError> {\n return yield* Effect.suspend(() =>\n db.transaction((tx) =>\n Effect.gen(function* () {\n const rows = yield* tx\n .select()\n .from(challengeTable as any)\n .where(eq(c.tokenDigest, input.tokenDigest))\n .for(\"update\")\n .limit(1);\n\n if (rows[0] === undefined)\n return { _tag: \"rejected\", reason: \"missing_challenge\" } as const;\n const row = yield* mapping.challenge.decode(selected<C>(rows[0]));\n const now = yield* DateTime.now;\n\n if (row.consumed) return { _tag: \"rejected\", reason: \"consumed_challenge\" } as const;\n if (DateTime.toEpochMillis(row.challenge.expiresAt) <= DateTime.toEpochMillis(now))\n return { _tag: \"rejected\", reason: \"expired_challenge\" } as const;\n if (row.failedAttempts >= row.challenge.attemptLimit)\n return { _tag: \"rejected\", reason: \"attempts_exhausted\" } as const;\n const candidate = input.otpDigests[row.challenge.otpKeyId];\n\n const matches =\n candidate !== undefined && timingSafeStringEqual(candidate, row.challenge.otpDigest);\n\n yield* tx\n .update(challengeTable as any)\n .set(\n updateValues<C>(\n matches\n ? [[ck.consumed, true]]\n : [[ck.failedAttempts, sql`${c.failedAttempts} + 1`]],\n ) as any,\n )\n .where(eq(c.tokenDigest, input.tokenDigest));\n\n return matches\n ? ({\n _tag: \"accepted\",\n value: VerifiedEmail.make({\n email: row.challenge.email,\n purpose: row.challenge.purpose,\n }),\n } as const)\n : ({ _tag: \"rejected\", reason: \"bad_code\" } as const);\n }),\n ),\n ).pipe(mapStoreWriteFailure);\n },\n );\n\n const consumeChallenge = Effect.fn(\"DrizzleMysqlAuthStore.consumeChallenge\")(function* (\n input: ConsumeChallenge,\n ) {\n yield* requireStandaloneConsume(db);\n const decision = yield* consumeChallengeDecision(input);\n\n return decision._tag === \"accepted\"\n ? decision.value\n : yield* EmailOtpRejected.make({ reason: decision.reason });\n });\n\n const issueRegistration = Effect.fn(\"DrizzleMysqlAuthStore.issueRegistration\")(function* (\n input: NewRegistration,\n ) {\n yield* Effect.suspend(() =>\n db\n .insert(registrationTable as any)\n .values(mapping.registration.encodeInsert(input, false) as any),\n ).pipe(mapStoreWriteFailure);\n });\n\n const inspectRegistration = Effect.fn(\"DrizzleMysqlAuthStore.inspectRegistration\")(function* (\n digest: TokenDigest,\n ) {\n const now = yield* DateTime.now;\n\n const rows = yield* Effect.suspend(() =>\n db\n .select()\n .from(registrationTable as any)\n .where(\n and(\n eq(r.tokenDigest, digest),\n eq(r.consumed, false),\n gt(r.expiresAt, mapping.registration.encodeInstant(now)),\n ),\n )\n .limit(1),\n ).pipe(mapStoreReadFailure);\n\n if (rows[0] === undefined) return yield* InvalidRegistration.make();\n\n return (yield* Effect.suspend(() => mapping.registration.decode(selected<R>(rows[0]))).pipe(\n mapStoreReadFailure,\n )).registration;\n });\n\n const consumeRegistrationDecision = Effect.fn(\n \"DrizzleMysqlAuthStore.consumeRegistrationDecision\",\n )(function* (\n input: ConsumeRegistration,\n ): Effect.fn.Return<ConsumeDecision<void>, AuthStoreError> {\n return yield* Effect.suspend(() =>\n db.transaction((tx) =>\n Effect.gen(function* () {\n const rows = yield* tx\n .select()\n .from(registrationTable as any)\n .where(eq(r.tokenDigest, input.tokenDigest))\n .for(\"update\")\n .limit(1);\n\n if (rows[0] === undefined) return { _tag: \"rejected\" } as const;\n const row = yield* mapping.registration.decode(selected<R>(rows[0]));\n const now = yield* DateTime.now;\n\n if (\n row.consumed ||\n DateTime.toEpochMillis(row.registration.expiresAt) <= DateTime.toEpochMillis(now)\n )\n return { _tag: \"rejected\" } as const;\n yield* tx\n .update(registrationTable as any)\n .set(updateValues<R>([[rk.consumed, true]]) as any)\n .where(eq(r.tokenDigest, input.tokenDigest));\n\n return { _tag: \"accepted\", value: undefined } as const;\n }),\n ),\n ).pipe(mapStoreWriteFailure);\n });\n\n const consumeRegistration = Effect.fn(\"DrizzleMysqlAuthStore.consumeRegistration\")(function* (\n input: ConsumeRegistration,\n ) {\n yield* requireStandaloneConsume(db);\n const decision = yield* consumeRegistrationDecision(input);\n\n if (decision._tag === \"rejected\") return yield* InvalidRegistration.make();\n });\n\n return {\n authStore: AuthStore.of({\n issueChallenge,\n consumeChallenge,\n issueRegistration,\n inspectRegistration,\n consumeRegistration,\n }),\n decisions: {\n consumeChallenge: consumeChallengeDecision,\n consumeRegistration: consumeRegistrationDecision,\n },\n } as const;\n};\n\nexport const makeMysqlOAuthStateServices = <S extends AnyMySqlTable>(\n database: Database,\n mapping: OAuthStateTables<S>,\n) => {\n const db = database as RuntimeDatabase;\n const stateTable = mapping.oauthState.table;\n const sk = mapping.oauthState.columns;\n\n const s = Object.fromEntries(\n Object.entries(sk).map(([name, key]) => [name, column(stateTable, key)]),\n ) as Record<keyof typeof sk, MySqlColumn>;\n\n const issue = Effect.fn(\"DrizzleMysqlOAuthStateStore.issue\")(function* (input: OAuthState) {\n yield* Effect.suspend(() =>\n db.insert(stateTable as any).values(mapping.oauthState.encodeInsert(input, false) as any),\n ).pipe(mapStoreWriteFailure);\n });\n\n const consumeDecision = Effect.fn(\"DrizzleMysqlOAuthStateStore.consumeDecision\")(function* (\n digest: TokenDigest,\n ): Effect.fn.Return<ConsumeDecision<OAuthState>, AuthStoreError> {\n return yield* Effect.suspend(() =>\n db.transaction((tx) =>\n Effect.gen(function* () {\n const rows = yield* tx\n .select()\n .from(stateTable as any)\n .where(eq(s.stateDigest, digest))\n .for(\"update\")\n .limit(1);\n\n if (rows[0] === undefined) return { _tag: \"rejected\" } as const;\n const row = yield* mapping.oauthState.decode(selected<S>(rows[0]));\n const now = yield* DateTime.now;\n\n if (\n row.consumed ||\n DateTime.toEpochMillis(row.state.expiresAt) <= DateTime.toEpochMillis(now)\n )\n return { _tag: \"rejected\" } as const;\n yield* tx\n .update(stateTable as any)\n .set(updateValues<S>([[sk.consumed, true]]) as any)\n .where(eq(s.stateDigest, digest));\n\n return { _tag: \"accepted\", value: row.state } as const;\n }),\n ),\n ).pipe(mapStoreWriteFailure);\n });\n\n const consume = Effect.fn(\"DrizzleMysqlOAuthStateStore.consume\")(function* (digest: TokenDigest) {\n yield* requireStandaloneConsume(db);\n const decision = yield* consumeDecision(digest);\n\n return decision._tag === \"accepted\" ? decision.value : yield* InvalidOAuthState.make();\n });\n\n return {\n oauthStateStore: OAuthStateStore.of({ issue, consume }),\n decisions: { consumeOAuthState: consumeDecision },\n } as const;\n};\n\nexport const makeMysqlAuthServices = <\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n S extends AnyMySqlTable,\n>(\n database: Database,\n mapping: AuthTables<C, R, S>,\n) => {\n const auth = makeMysqlAuthStoreServices(database, mapping);\n const oauth = makeMysqlOAuthStateServices(database, mapping);\n\n return { ...auth, ...oauth, decisions: { ...auth.decisions, ...oauth.decisions } } as const;\n};\n\n/**\n * Owns the native outer commit. Keep rejection as a decision value inside the\n * owner; interruption before commit rolls back. This adapter never retries a\n * deadlock inside the caller's transaction.\n */\nexport function coordinateMysqlAuthStoreTransaction<\n D extends Database,\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: { readonly mapping: AuthStoreTables<C, R>; readonly transaction?: never },\n body: Effect.Effect<A, E, Requirements>,\n): Effect.Effect<\n A,\n E | DatabaseError | SqlError,\n Exclude<Requirements, AuthStoreDecisions> | DatabaseRequirements\n>;\n\nexport function coordinateMysqlAuthStoreTransaction<\n D extends Database,\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthStoreTables<C, R>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, Requirements>,\n): Effect.Effect<\n A,\n E | DatabaseError | SqlError,\n Exclude<Requirements, AuthStoreDecisions | TxId> | DatabaseRequirements\n>;\n\nexport function coordinateMysqlAuthStoreTransaction<\n D extends Database,\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthStoreTables<C, R>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, Requirements>,\n) {\n return Effect.flatMap(acquire, (database) =>\n database.transaction<A, E, Exclude<Requirements, AuthStoreDecisions>>((transaction) => {\n const decisions = makeMysqlAuthStoreServices(transaction as never, options.mapping).decisions;\n const provided = Context.make(AuthStoreDecisions, decisions);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(\n work,\n options.transaction,\n options.transaction.of(transaction as TransactionOf<D>),\n );\n }),\n );\n}\n\nexport function coordinateMysqlOAuthStateTransaction<\n D extends Database,\n S extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: { readonly mapping: OAuthStateTables<S>; readonly transaction?: never },\n body: Effect.Effect<A, E, Requirements>,\n): Effect.Effect<\n A,\n E | DatabaseError | SqlError,\n Exclude<Requirements, OAuthStateDecisions> | DatabaseRequirements\n>;\n\nexport function coordinateMysqlOAuthStateTransaction<\n D extends Database,\n S extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: OAuthStateTables<S>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, Requirements>,\n): Effect.Effect<\n A,\n E | DatabaseError | SqlError,\n Exclude<Requirements, OAuthStateDecisions | TxId> | DatabaseRequirements\n>;\n\nexport function coordinateMysqlOAuthStateTransaction<\n D extends Database,\n S extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: OAuthStateTables<S>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, Requirements>,\n) {\n return Effect.flatMap(acquire, (database) =>\n database.transaction<A, E, Exclude<Requirements, OAuthStateDecisions>>((transaction) => {\n const decisions = makeMysqlOAuthStateServices(\n transaction as never,\n options.mapping,\n ).decisions;\n\n const provided = Context.make(OAuthStateDecisions, decisions);\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(\n work,\n options.transaction,\n options.transaction.of(transaction as TransactionOf<D>),\n );\n }),\n );\n}\n\nexport function coordinateMysqlAuthTransaction<\n D extends Database,\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n S extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: { readonly mapping: AuthTables<C, R, S>; readonly transaction?: never },\n body: Effect.Effect<A, E, Requirements>,\n): Effect.Effect<\n A,\n E | DatabaseError | SqlError,\n Exclude<Requirements, AuthStoreDecisions | OAuthStateDecisions> | DatabaseRequirements\n>;\n\nexport function coordinateMysqlAuthTransaction<\n D extends Database,\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n S extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthTables<C, R, S>;\n readonly transaction: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, Requirements>,\n): Effect.Effect<\n A,\n E | DatabaseError | SqlError,\n Exclude<Requirements, AuthStoreDecisions | OAuthStateDecisions | TxId> | DatabaseRequirements\n>;\n\nexport function coordinateMysqlAuthTransaction<\n D extends Database,\n C extends AnyMySqlTable,\n R extends AnyMySqlTable,\n S extends AnyMySqlTable,\n A,\n E,\n Requirements,\n DatabaseError,\n DatabaseRequirements,\n TxId,\n TxShape,\n>(\n acquire: Effect.Effect<D, DatabaseError, DatabaseRequirements>,\n options: {\n readonly mapping: AuthTables<C, R, S>;\n readonly transaction?: SuppliedService<TxId, NoInfer<TransactionOf<D>>, TxShape>;\n },\n body: Effect.Effect<A, E, Requirements>,\n) {\n return Effect.flatMap(acquire, (database) =>\n database.transaction<A, E, Exclude<Requirements, AuthStoreDecisions | OAuthStateDecisions>>(\n (transaction) => {\n const decisions = makeMysqlAuthServices(transaction as never, options.mapping).decisions;\n\n const provided = Context.make(AuthStoreDecisions, decisions).pipe(\n Context.add(OAuthStateDecisions, decisions),\n );\n\n const work = Effect.provideContext(body, provided);\n\n return options.transaction === undefined\n ? work\n : Effect.provideService(\n work,\n options.transaction,\n options.transaction.of(transaction as TransactionOf<D>),\n );\n },\n ),\n );\n}\n"],"mappings":";;;;;;;;;AAyCA,MAAM,YAAqC,QACzC;AAEF,MAAM,kBAAkB,eAAe,KAAK,EAAE,SAAS,yBAAyB,CAAC;AACjF,MAAM,mBAAmB,eAAe,KAAK,EAAE,SAAS,0BAA0B,CAAC;AACnF,MAAM,iBAAiB,OAAO,GAAG,cAAc;AAE/C,MAAM,mBACH,aACS,WACR,yBAAyB,QAAQ,cAAc,CAAC,CAAC,KAC/C,OAAO,YAAY,UAAU,OAAO,UAAU,MAAM,IAAI,OAAO,OAAO,CAAC,CAAC,CAC1E;AAEJ,MAAM,sBAAsB,gBAAgB,SAAS;AACrD,MAAM,uBAAuB,gBAAgB,UAAU;;AAGvD,MAAa,8BACX,UACA,YACG;CACH,MAAM,KAAK;CACX,MAAM,iBAAiB,QAAQ,UAAU;CACzC,MAAM,KAAK,QAAQ,UAAU;CAE7B,MAAM,IAAI,OAAO,YACf,OAAO,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,MAAM,OAAO,gBAAgB,GAAG,CAAC,CAAC,CAC7E;CAEA,MAAM,oBAAoB,QAAQ,aAAa;CAC/C,MAAM,KAAK,QAAQ,aAAa;CAEhC,MAAM,IAAI,OAAO,YACf,OAAO,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,MAAM,OAAO,mBAAmB,GAAG,CAAC,CAAC,CAChF;CAEA,MAAM,iBAAiB,OAAO,GAAG,sCAAsC,CAAC,CAAC,WACvE,OACA;EACA,MAAM,SAAS,OAAO,OAAO,cAC3B,GAAG,aAAa,OACd,OAAO,IAAI,aAAa;GAKtB,OAAO,GACJ,OAAO,cAAqB,CAAC,CAC7B,OACC,QAAQ,UAAU,aAAa,OAAO;IACpC,WA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authIdentityKey, sameRevision, satisfies, storage, validAction } from "./oauth-state.mjs";
|
|
2
|
+
import { both } from "./transaction-owner.mjs";
|
|
3
|
+
import { CurrentOAuthTransaction, col, copiedRow, equal } from "./oauth-owner.mjs";
|
|
4
|
+
import { claimFlow, credentialStorage, currentSubject, exactClaim, issueFlow, linkStorage, matchesAccess, readFlow, terminalFlow } from "./oauth-flow.mjs";
|
|
5
|
+
import { acquireTuple, readTuple } from "./oauth-registration.mjs";
|
|
6
|
+
import { DateTime, Effect } from "effect";
|
|
7
|
+
import { AuthenticationRequirement, SecurityRevision, SessionInvalidationWindow } from "@yielded/auth/Sessions";
|
|
8
|
+
import { OAuthAccountRevision, OAuthActionAuthorization, OAuthCredentialSnapshot, OAuthLinkAccess, OAuthLinkClaim, OAuthLinkPendingFlow, OAuthLinkTransactionContext, OAuthUnlinked, snapshotOAuthSync } from "@yielded/auth/OAuth";
|
|
9
|
+
import { eq, sql } from "drizzle-orm";
|
|
10
|
+
//#region src/drizzle/oauth-accounts.ts
|
|
11
|
+
const contextStorage = storage(OAuthLinkTransactionContext);
|
|
12
|
+
const unlinkedStorage = storage(OAuthUnlinked);
|
|
13
|
+
const accountCurrent = (mapping, subjectId) => Effect.gen(function* () {
|
|
14
|
+
const native = yield* mapping.subjectId.toNative(subjectId);
|
|
15
|
+
return yield* currentSubject(mapping, native);
|
|
16
|
+
});
|
|
17
|
+
const authorization = (mapping, current, auth, action, flowId, commandId, intent, maximumAge) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
18
|
+
const now = yield* owner.now(mapping.clock);
|
|
19
|
+
const currentRequirement = snapshotOAuthSync(AuthenticationRequirement, mapping.subject.decodeActionRequirement(copiedRow(current.row), action));
|
|
20
|
+
if (!validAction(auth, {
|
|
21
|
+
moduleId: auth.challenge.moduleId,
|
|
22
|
+
action,
|
|
23
|
+
flowId,
|
|
24
|
+
commandId,
|
|
25
|
+
revision: current.revision,
|
|
26
|
+
intent
|
|
27
|
+
}, currentRequirement, now, maximumAge)) return false;
|
|
28
|
+
const age = Math.min(maximumAge, auth.requirement.maximumAgeMillis, currentRequirement.maximumAgeMillis);
|
|
29
|
+
const fresh = auth.evidence.proofs.filter((proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < age);
|
|
30
|
+
invariant(fresh.length > 0);
|
|
31
|
+
const deadline = Math.min(...fresh.map((proof) => DateTime.toEpochMillis(proof.verifiedAt) + age));
|
|
32
|
+
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${deadline}`);
|
|
33
|
+
return true;
|
|
34
|
+
}));
|
|
35
|
+
const currentLink = (mapping, flow) => Effect.gen(function* () {
|
|
36
|
+
const current = yield* accountCurrent(mapping, flow.context.revision.subjectId);
|
|
37
|
+
return current !== void 0 && sameRevision(current.revision, flow.context.revision) ? current : void 0;
|
|
38
|
+
});
|
|
39
|
+
const issueLink = (mapping, input) => Effect.gen(function* () {
|
|
40
|
+
const flow = snapshotOAuthSync(OAuthLinkPendingFlow, input.flow), c = flow.context;
|
|
41
|
+
const current = yield* currentLink(mapping, flow);
|
|
42
|
+
const auth = snapshotOAuthSync(OAuthActionAuthorization, input.authorization);
|
|
43
|
+
if (current === void 0 || auth.challenge.moduleId !== c.moduleId || !(yield* authorization(mapping, current, auth, "link-begin", c.flowId, c.commandId, contextStorage.encode(c), c.maximumEvidenceAgeMillis))) return { _tag: "Rejected" };
|
|
44
|
+
return yield* issueFlow(mapping, flow, "link");
|
|
45
|
+
});
|
|
46
|
+
const preflightLink = (mapping, original) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
47
|
+
const input = snapshotOAuthSync(OAuthLinkAccess, original);
|
|
48
|
+
const current = yield* accountCurrent(mapping, input.subjectId);
|
|
49
|
+
const found = yield* readFlow(mapping, input, "link");
|
|
50
|
+
const now = yield* owner.now(mapping.clock);
|
|
51
|
+
if (current === void 0 || found.flow === void 0 || found.row?.[mapping.flow.state] !== "Pending" || !matchesAccess(found.flow, input)) return void 0;
|
|
52
|
+
const flow = snapshotOAuthSync(OAuthLinkPendingFlow, found.flow), c = flow.context;
|
|
53
|
+
if (c.revision.subjectId !== input.subjectId || !sameRevision(current.revision, c.revision) || now < c.issuedAtMillis || now >= c.expiresAtMillis) return void 0;
|
|
54
|
+
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${c.issuedAtMillis} and ${mapping.clock.engineNowMillis} < ${c.expiresAtMillis}`);
|
|
55
|
+
return {
|
|
56
|
+
current,
|
|
57
|
+
flow,
|
|
58
|
+
row: found.row
|
|
59
|
+
};
|
|
60
|
+
}));
|
|
61
|
+
const claimLink = (mapping, input) => Effect.gen(function* () {
|
|
62
|
+
const found = yield* preflightLink(mapping, input.access);
|
|
63
|
+
const flow = snapshotOAuthSync(OAuthLinkPendingFlow, input.flow);
|
|
64
|
+
const auth = snapshotOAuthSync(OAuthActionAuthorization, input.authorization), c = flow.context;
|
|
65
|
+
if (found === void 0 || linkStorage.encode(found.flow) !== linkStorage.encode(flow) || auth.challenge.moduleId !== c.moduleId || !(yield* authorization(mapping, found.current, auth, "link-complete", c.flowId, c.commandId, contextStorage.encode(c), c.maximumEvidenceAgeMillis))) return { _tag: "Rejected" };
|
|
66
|
+
const claim = yield* claimFlow(mapping, {
|
|
67
|
+
row: found.row,
|
|
68
|
+
flow
|
|
69
|
+
}, input.claimId);
|
|
70
|
+
return claim === void 0 ? { _tag: "Rejected" } : {
|
|
71
|
+
_tag: "Claimed",
|
|
72
|
+
claim
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
const checkInvalidation = (mapping, original) => {
|
|
76
|
+
const value = snapshotOAuthSync(SessionInvalidationWindow, original);
|
|
77
|
+
invariant(value.trigger === "credential-change" && value.oldAuthenticationEvidence === "rejected" && (mapping.sessionInvalidation === "same-authority-immediate" ? value.existingSessions === "immediate" && value.maximumExposureMillis === 0 : value.existingSessions === "original-absolute-expiry"));
|
|
78
|
+
return value;
|
|
79
|
+
};
|
|
80
|
+
const advance = (mapping, current, removed) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
81
|
+
const revision = mapping.subject.nextSecurityRevision(current.revision.securityRevision);
|
|
82
|
+
invariant(typeof revision === "string" && revision.length > 0 && revision.length <= 256 && revision !== current.revision.securityRevision);
|
|
83
|
+
const subject = mapping.subject;
|
|
84
|
+
yield* owner.update(subject.table, { [subject.id]: current.nativeId }, { [subject.securityRevision]: revision });
|
|
85
|
+
for (const cleanup of mapping.cleanup) {
|
|
86
|
+
const condition = both(eq(col(cleanup.table, cleanup.subjectId), current.nativeId), cleanup.condition({
|
|
87
|
+
subjectId: current.nativeId,
|
|
88
|
+
revision: snapshotOAuthSync(OAuthAccountRevision, current.revision),
|
|
89
|
+
...removed === void 0 ? {} : { removedCredentialId: removed }
|
|
90
|
+
}));
|
|
91
|
+
yield* owner.write(owner.database.delete(cleanup.table).where(condition));
|
|
92
|
+
owner.postconditions.push(sql`not exists(select 1 from ${cleanup.table} where ${condition})`);
|
|
93
|
+
}
|
|
94
|
+
return SecurityRevision.make(revision);
|
|
95
|
+
}));
|
|
96
|
+
const settleLink = (mapping, input, allocated) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
97
|
+
const claim = snapshotOAuthSync(OAuthLinkClaim, input.claim), flow = claim.flow, c = flow.context;
|
|
98
|
+
const current = yield* currentLink(mapping, flow);
|
|
99
|
+
const identity = input.outcome._tag === "Verified" ? input.outcome.identity.identity : void 0;
|
|
100
|
+
if (identity !== void 0) invariant(identity.provider === c.provider && identity.issuer === c.issuer);
|
|
101
|
+
const tuple = identity !== void 0 && current !== void 0 ? yield* readTuple(mapping.ownership, identity) : void 0;
|
|
102
|
+
if ((yield* exactClaim(mapping, claim, "link")) === void 0) return { _tag: "Rejected" };
|
|
103
|
+
let decision = { _tag: input.outcome._tag };
|
|
104
|
+
if (input.outcome._tag === "Verified") {
|
|
105
|
+
decision = { _tag: "Rejected" };
|
|
106
|
+
const auth = snapshotOAuthSync(OAuthActionAuthorization, input.authorization);
|
|
107
|
+
if (current !== void 0 && tuple !== void 0 && auth.challenge.moduleId === c.moduleId && (yield* authorization(mapping, current, auth, "link-complete", c.flowId, c.commandId, contextStorage.encode(c), c.maximumEvidenceAgeMillis))) {
|
|
108
|
+
const t = mapping.ownership.tuple, cr = mapping.credential, a = mapping.authority;
|
|
109
|
+
const login = yield* owner.read(cr.table, eq(col(cr.table, cr.identityKey), tuple.key), { limit: 1 });
|
|
110
|
+
const previous = login.rows[0];
|
|
111
|
+
if (tuple.row[t.state] === "Reserved" || tuple.row[t.state] === "Owned" && !mapping.subjectId.equals(tuple.row[t.subjectId], current.nativeId) || previous !== void 0 && (previous[cr.moduleId] !== c.moduleId || !mapping.subjectId.equals(previous[cr.subjectId], current.nativeId) || !cr.isActiveStatus(previous[cr.status]))) decision = { _tag: "Conflict" };
|
|
112
|
+
else if (previous !== void 0) {
|
|
113
|
+
const shared = current.revision.credentials.find((item) => item.credentialId === previous[cr.credentialId]);
|
|
114
|
+
if (tuple.row[t.state] !== "Owned" || shared?.revision !== previous[cr.credentialRevision] || !(yield* owner.check(sql`exists(select 1 from ${cr.table} where ${both(eq(col(cr.table, cr.identityKey), tuple.key), cr.activeCondition)})`))) decision = { _tag: "Conflict" };
|
|
115
|
+
else decision = {
|
|
116
|
+
_tag: "Linked",
|
|
117
|
+
changed: false,
|
|
118
|
+
credential: snapshotOAuthSync(OAuthCredentialSnapshot, {
|
|
119
|
+
moduleId: c.moduleId,
|
|
120
|
+
identity,
|
|
121
|
+
credentialId: previous[cr.credentialId],
|
|
122
|
+
credentialRevision: previous[cr.credentialRevision],
|
|
123
|
+
revision: current.revision
|
|
124
|
+
})
|
|
125
|
+
};
|
|
126
|
+
} else {
|
|
127
|
+
checkInvalidation(mapping, input.invalidation);
|
|
128
|
+
const values = {
|
|
129
|
+
...cr.encodeInsert({
|
|
130
|
+
moduleId: c.moduleId,
|
|
131
|
+
subjectId: current.nativeId,
|
|
132
|
+
identityKey: tuple.key,
|
|
133
|
+
credentialId: allocated.credentialId,
|
|
134
|
+
credentialRevision: allocated.revision
|
|
135
|
+
}),
|
|
136
|
+
[cr.moduleId]: c.moduleId,
|
|
137
|
+
[cr.subjectId]: current.nativeId,
|
|
138
|
+
[cr.identityKey]: tuple.key,
|
|
139
|
+
[cr.credentialId]: allocated.credentialId,
|
|
140
|
+
[cr.credentialRevision]: allocated.revision
|
|
141
|
+
};
|
|
142
|
+
invariant(cr.isActiveStatus(values[cr.status]));
|
|
143
|
+
login.rows = (yield* owner.insert(cr.table, values, { [cr.credentialId]: allocated.credentialId })).rows;
|
|
144
|
+
const sharedValues = {
|
|
145
|
+
...a.encodeInsert({
|
|
146
|
+
subjectId: current.nativeId,
|
|
147
|
+
credentialId: allocated.credentialId,
|
|
148
|
+
revision: allocated.revision
|
|
149
|
+
}),
|
|
150
|
+
[a.subjectId]: current.nativeId,
|
|
151
|
+
[a.credentialId]: allocated.credentialId,
|
|
152
|
+
[a.revision]: allocated.revision
|
|
153
|
+
};
|
|
154
|
+
invariant(a.isActiveStatus(sharedValues[a.status]));
|
|
155
|
+
const shared = yield* owner.insert(a.table, sharedValues, {
|
|
156
|
+
[a.subjectId]: current.nativeId,
|
|
157
|
+
[a.credentialId]: allocated.credentialId
|
|
158
|
+
});
|
|
159
|
+
current.authorities.rows = [...current.authorities.rows, ...shared.rows];
|
|
160
|
+
owner.postconditions.push(sql`exists(select 1 from ${cr.table} where ${both(eq(col(cr.table, cr.credentialId), allocated.credentialId), cr.activeCondition)})`, sql`exists(select 1 from ${a.table} where ${both(eq(col(a.table, a.subjectId), current.nativeId), eq(col(a.table, a.credentialId), allocated.credentialId), a.activeCondition)})`);
|
|
161
|
+
if (tuple.row[t.state] === "Unowned") yield* acquireTuple(mapping.ownership, identity, tuple.key, current.nativeId);
|
|
162
|
+
const next = yield* advance(mapping, current);
|
|
163
|
+
const revision = snapshotOAuthSync(OAuthAccountRevision, {
|
|
164
|
+
...current.revision,
|
|
165
|
+
securityRevision: next,
|
|
166
|
+
credentials: [...current.revision.credentials, {
|
|
167
|
+
credentialId: allocated.credentialId,
|
|
168
|
+
revision: allocated.revision
|
|
169
|
+
}]
|
|
170
|
+
});
|
|
171
|
+
decision = {
|
|
172
|
+
_tag: "Linked",
|
|
173
|
+
changed: true,
|
|
174
|
+
credential: snapshotOAuthSync(OAuthCredentialSnapshot, {
|
|
175
|
+
moduleId: c.moduleId,
|
|
176
|
+
identity,
|
|
177
|
+
credentialId: allocated.credentialId,
|
|
178
|
+
credentialRevision: allocated.revision,
|
|
179
|
+
revision
|
|
180
|
+
})
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
yield* terminalFlow(mapping, flow, decision._tag);
|
|
186
|
+
return decision;
|
|
187
|
+
}));
|
|
188
|
+
const targetCredential = (mapping, moduleId, credentialId, current) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
189
|
+
const cr = mapping.credential;
|
|
190
|
+
const row = (yield* owner.read(cr.table, eq(col(cr.table, cr.credentialId), credentialId), { limit: 1 })).rows[0];
|
|
191
|
+
if (row === void 0 || row[cr.moduleId] !== moduleId || !mapping.subjectId.equals(row[cr.subjectId], current.nativeId) || !cr.isActiveStatus(row[cr.status])) return void 0;
|
|
192
|
+
const t = mapping.ownership.tuple;
|
|
193
|
+
const ownership = (yield* owner.read(t.table, eq(col(t.table, t.identityKey), row[cr.identityKey]), { limit: 1 })).rows[0];
|
|
194
|
+
if (ownership === void 0 || ownership[t.state] !== "Owned" || !mapping.subjectId.equals(ownership[t.subjectId], current.nativeId)) return void 0;
|
|
195
|
+
const identity = {
|
|
196
|
+
provider: ownership[t.provider],
|
|
197
|
+
issuer: ownership[t.issuer],
|
|
198
|
+
subject: ownership[t.externalSubject]
|
|
199
|
+
};
|
|
200
|
+
invariant(oauthIdentityKey(identity) === row[cr.identityKey]);
|
|
201
|
+
if (current.revision.credentials.find((item) => item.credentialId === credentialId)?.revision !== row[cr.credentialRevision] || !(yield* owner.check(sql`exists(select 1 from ${cr.table} where ${both(eq(col(cr.table, cr.credentialId), credentialId), cr.activeCondition)})`))) return void 0;
|
|
202
|
+
return snapshotOAuthSync(OAuthCredentialSnapshot, {
|
|
203
|
+
moduleId,
|
|
204
|
+
identity,
|
|
205
|
+
credentialId,
|
|
206
|
+
credentialRevision: row[cr.credentialRevision],
|
|
207
|
+
revision: current.revision
|
|
208
|
+
});
|
|
209
|
+
}));
|
|
210
|
+
const unlinkCommand = (mapping, moduleId, commandId) => Effect.flatMap(CurrentOAuthTransaction, (owner) => owner.read(mapping.command.table, equal(mapping.command.table, {
|
|
211
|
+
[mapping.command.moduleId]: moduleId,
|
|
212
|
+
[mapping.command.commandId]: commandId
|
|
213
|
+
}), { limit: 1 }));
|
|
214
|
+
const inspectUnlink = (mapping, input) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
215
|
+
const current = yield* accountCurrent(mapping, input.subjectId);
|
|
216
|
+
if (current === void 0) return { _tag: "Rejected" };
|
|
217
|
+
const command = yield* unlinkCommand(mapping, input.moduleId, input.commandId), r = mapping.command;
|
|
218
|
+
const old = command.rows[0];
|
|
219
|
+
if (old !== void 0) {
|
|
220
|
+
const intent = credentialStorage.decode(old[r.intentSnapshot]);
|
|
221
|
+
if (intent.moduleId !== input.moduleId || intent.revision.subjectId !== input.subjectId || intent.credentialId !== input.credentialId || !mapping.subjectId.equals(old[r.subjectId], current.nativeId) || old[r.credentialId] !== input.credentialId) return { _tag: "Conflict" };
|
|
222
|
+
const metadata = mapping.metadata.condition(current.nativeId);
|
|
223
|
+
if (!(yield* owner.check(metadata))) return { _tag: "Rejected" };
|
|
224
|
+
owner.postconditions.push(metadata);
|
|
225
|
+
return {
|
|
226
|
+
_tag: "Replay",
|
|
227
|
+
result: unlinkedStorage.decode(old[r.decision])
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const credential = yield* targetCredential(mapping, input.moduleId, input.credentialId, current);
|
|
231
|
+
return credential === void 0 ? { _tag: "Rejected" } : {
|
|
232
|
+
_tag: "Target",
|
|
233
|
+
credential
|
|
234
|
+
};
|
|
235
|
+
}));
|
|
236
|
+
const remainingEligibility = (mapping, current, removed) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
237
|
+
invariant(mapping.eligibility.length > 0 && mapping.eligibility.length <= 32);
|
|
238
|
+
const facts = /* @__PURE__ */ new Map();
|
|
239
|
+
const revisions = new Map(current.revision.credentials.map((item) => [item.credentialId, item.revision]));
|
|
240
|
+
for (const descriptor of mapping.eligibility) {
|
|
241
|
+
const observed = yield* owner.read(descriptor.table, both(eq(col(descriptor.table, descriptor.subjectId), current.nativeId), descriptor.condition(current.nativeId)), { orderBy: col(descriptor.table, descriptor.credentialId) });
|
|
242
|
+
for (const row of observed.rows) {
|
|
243
|
+
const fact = descriptor.decode(copiedRow(row));
|
|
244
|
+
if (fact === void 0 || fact.credentialId === removed) continue;
|
|
245
|
+
invariant(fact.credentialId === row[descriptor.credentialId] && fact.revision === row[descriptor.revision] && revisions.get(fact.credentialId) === fact.revision && fact.factors.length <= 8 && fact.factors.every((factor) => [
|
|
246
|
+
"knowledge",
|
|
247
|
+
"possession",
|
|
248
|
+
"inherence"
|
|
249
|
+
].includes(factor)));
|
|
250
|
+
invariant(typeof fact.usablePrimary === "boolean" && typeof fact.userVerified === "boolean" && typeof fact.phishingResistant === "boolean");
|
|
251
|
+
const normalized = {
|
|
252
|
+
credentialId: fact.credentialId,
|
|
253
|
+
revision: fact.revision,
|
|
254
|
+
usablePrimary: fact.usablePrimary,
|
|
255
|
+
factors: [...new Set(fact.factors)].sort(),
|
|
256
|
+
userVerified: fact.userVerified,
|
|
257
|
+
phishingResistant: fact.phishingResistant
|
|
258
|
+
};
|
|
259
|
+
const prior = facts.get(fact.credentialId);
|
|
260
|
+
invariant(prior === void 0 || JSON.stringify(prior) === JSON.stringify(normalized));
|
|
261
|
+
facts.set(fact.credentialId, normalized);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const available = [...facts.values()];
|
|
265
|
+
const requirement = snapshotOAuthSync(AuthenticationRequirement, mapping.subject.decodeAuthenticationRequirement(copiedRow(current.row)));
|
|
266
|
+
return available.some((fact) => fact.usablePrimary) && satisfies(available, requirement);
|
|
267
|
+
}));
|
|
268
|
+
const unlink = (mapping, input) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
269
|
+
const expected = snapshotOAuthSync(OAuthCredentialSnapshot, input.credential);
|
|
270
|
+
invariant(expected.moduleId === input.moduleId);
|
|
271
|
+
const current = yield* accountCurrent(mapping, expected.revision.subjectId);
|
|
272
|
+
if (current === void 0) return { _tag: "Rejected" };
|
|
273
|
+
const guards = mapping.connectedReferenceGuards ?? [];
|
|
274
|
+
invariant(guards.length <= 32);
|
|
275
|
+
let referencesGuarded = mapping.connectedReference !== void 0 && guards.length > 0;
|
|
276
|
+
if (mapping.connectedReference !== void 0) {
|
|
277
|
+
for (const guard of guards) if ((yield* owner.read(guard.table, guard.condition({
|
|
278
|
+
identity: snapshotOAuthSync(OAuthCredentialSnapshot.fields.identity, expected.identity),
|
|
279
|
+
identityKey: oauthIdentityKey(expected.identity),
|
|
280
|
+
subjectId: copiedRow({ value: current.nativeId }).value
|
|
281
|
+
}), { orderBy: col(guard.table, guard.orderBy) })).rows.length === 0) referencesGuarded = false;
|
|
282
|
+
}
|
|
283
|
+
const command = yield* unlinkCommand(mapping, input.moduleId, input.commandId), r = mapping.command;
|
|
284
|
+
const previous = command.rows[0];
|
|
285
|
+
if (previous !== void 0) {
|
|
286
|
+
if (previous[r.intentSnapshot] !== credentialStorage.encode(expected) || previous[r.credentialId] !== expected.credentialId || !mapping.subjectId.equals(previous[r.subjectId], current.nativeId)) return { _tag: "Conflict" };
|
|
287
|
+
const metadata = mapping.metadata.condition(current.nativeId);
|
|
288
|
+
if (!(yield* owner.check(metadata))) return { _tag: "Rejected" };
|
|
289
|
+
owner.postconditions.push(metadata);
|
|
290
|
+
return {
|
|
291
|
+
_tag: "Unlinked",
|
|
292
|
+
replayed: true,
|
|
293
|
+
result: unlinkedStorage.decode(previous[r.decision])
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const actual = yield* targetCredential(mapping, input.moduleId, expected.credentialId, current);
|
|
297
|
+
if (actual === void 0 || credentialStorage.encode(actual) !== credentialStorage.encode(expected)) return { _tag: "Rejected" };
|
|
298
|
+
const auth = snapshotOAuthSync(OAuthActionAuthorization, input.authorization);
|
|
299
|
+
if (auth.challenge.moduleId !== input.moduleId || !(yield* authorization(mapping, current, auth, "unlink", input.commandId, input.commandId, credentialStorage.encode(expected), auth.requirement.maximumAgeMillis))) return { _tag: "Rejected" };
|
|
300
|
+
if (!(yield* remainingEligibility(mapping, current, expected.credentialId))) return { _tag: "LastSignInMethod" };
|
|
301
|
+
const invalidation = checkInvalidation(mapping, input.invalidation), cr = mapping.credential, a = mapping.authority;
|
|
302
|
+
const key = oauthIdentityKey(expected.identity), t = mapping.ownership.tuple;
|
|
303
|
+
const connected = mapping.connectedReference?.({
|
|
304
|
+
identityKey: key,
|
|
305
|
+
subjectId: copiedRow({ value: current.nativeId }).value
|
|
306
|
+
});
|
|
307
|
+
const retain = connected !== void 0 && (!referencesGuarded || (yield* owner.check(connected)));
|
|
308
|
+
if (connected !== void 0 && referencesGuarded) owner.postconditions.push(retain ? connected : sql`not (${connected})`);
|
|
309
|
+
yield* owner.remove(cr.table, { [cr.credentialId]: expected.credentialId });
|
|
310
|
+
yield* owner.remove(a.table, {
|
|
311
|
+
[a.subjectId]: current.nativeId,
|
|
312
|
+
[a.credentialId]: expected.credentialId
|
|
313
|
+
});
|
|
314
|
+
if (!retain) {
|
|
315
|
+
yield* owner.update(t.table, { [t.identityKey]: key }, {
|
|
316
|
+
[t.state]: "Unowned",
|
|
317
|
+
[t.subjectId]: null,
|
|
318
|
+
[t.reservation]: null,
|
|
319
|
+
[t.version]: owner.marker
|
|
320
|
+
});
|
|
321
|
+
if (mapping.ownership.mode === "separate") yield* owner.remove(mapping.ownership.external.table, { [mapping.ownership.external.identityKey]: key });
|
|
322
|
+
}
|
|
323
|
+
yield* advance(mapping, current, expected.credentialId);
|
|
324
|
+
const result = snapshotOAuthSync(OAuthUnlinked, {
|
|
325
|
+
_tag: "Unlinked",
|
|
326
|
+
credentialId: expected.credentialId,
|
|
327
|
+
invalidation
|
|
328
|
+
});
|
|
329
|
+
const now = yield* owner.now(mapping.clock);
|
|
330
|
+
invariant(Number.isSafeInteger(input.retentionUntilMillis) && input.retentionUntilMillis > now && input.retentionUntilMillis >= input.nowMillis + 12e4);
|
|
331
|
+
const commandKey = {
|
|
332
|
+
[r.moduleId]: input.moduleId,
|
|
333
|
+
[r.commandId]: input.commandId
|
|
334
|
+
};
|
|
335
|
+
const values = {
|
|
336
|
+
...r.encodeInsert({
|
|
337
|
+
moduleId: input.moduleId,
|
|
338
|
+
commandId: input.commandId,
|
|
339
|
+
credential: snapshotOAuthSync(OAuthCredentialSnapshot, expected)
|
|
340
|
+
}),
|
|
341
|
+
...commandKey,
|
|
342
|
+
[r.subjectId]: current.nativeId,
|
|
343
|
+
[r.credentialId]: expected.credentialId,
|
|
344
|
+
[r.intentSnapshot]: credentialStorage.encode(expected),
|
|
345
|
+
[r.decision]: unlinkedStorage.encode(result),
|
|
346
|
+
[r.retentionUntil]: mapping.clock.encodeInstant(input.retentionUntilMillis)
|
|
347
|
+
};
|
|
348
|
+
command.rows = (yield* owner.insert(r.table, values, commandKey)).rows;
|
|
349
|
+
return {
|
|
350
|
+
_tag: "Unlinked",
|
|
351
|
+
result,
|
|
352
|
+
replayed: false
|
|
353
|
+
};
|
|
354
|
+
}));
|
|
355
|
+
//#endregion
|
|
356
|
+
export { accountCurrent, claimLink, inspectUnlink, issueLink, preflightLink, settleLink, unlink };
|
|
357
|
+
|
|
358
|
+
//# sourceMappingURL=oauth-accounts.mjs.map
|