@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,698 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PrepareEmailCommit,
|
|
3
|
+
type EmailCommandId,
|
|
4
|
+
type EmailRegistrationDecision,
|
|
5
|
+
EmailUnavailable,
|
|
6
|
+
} from "@yielded/auth/Email";
|
|
7
|
+
import {
|
|
8
|
+
coordinateCommit,
|
|
9
|
+
CurrentCommitJournal,
|
|
10
|
+
hasCommitScope,
|
|
11
|
+
type PreparedCommit,
|
|
12
|
+
LifecycleHooks,
|
|
13
|
+
HookConfigurationError,
|
|
14
|
+
} from "@yielded/auth/Hooks";
|
|
15
|
+
import type { LoginIdentifier } from "@yielded/auth/Identity";
|
|
16
|
+
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
17
|
+
import { type ProofCompletionPlan, ProofUnavailable } from "@yielded/auth/Proofs";
|
|
18
|
+
import type { TokenDigest } from "@yielded/auth/Schema";
|
|
19
|
+
import type { SecurityRevision } from "@yielded/auth/Sessions";
|
|
20
|
+
/* oxlint-disable no-explicit-any -- registration plans bridge consumer-owned Drizzle rows. */
|
|
21
|
+
import { and, eq, isNull } from "drizzle-orm";
|
|
22
|
+
import { Cause, DateTime, Effect, Schema } from "effect";
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
type AnyEmailRegistrationMapping,
|
|
26
|
+
requiredEmailRegistrationConstraints,
|
|
27
|
+
} from "./email-model";
|
|
28
|
+
import { CurrentEmailSql, type EmailSqlDatabase, type EmailSqlQuery } from "./email-sql";
|
|
29
|
+
import { column, isMappedConstraintConflict, PersistenceMappingError } from "./model";
|
|
30
|
+
import {
|
|
31
|
+
CurrentProofSql,
|
|
32
|
+
completeProofPlanIn,
|
|
33
|
+
type ProofSqlConfiguration,
|
|
34
|
+
type ProofSqlDatabase,
|
|
35
|
+
} from "./proof-sql";
|
|
36
|
+
|
|
37
|
+
type Mapping<Registration> = AnyEmailRegistrationMapping<Registration>;
|
|
38
|
+
const unavailable = () => EmailUnavailable.make({});
|
|
39
|
+
|
|
40
|
+
const translateFailure = <A, E, R>(
|
|
41
|
+
effect: Effect.Effect<A, E, R>,
|
|
42
|
+
): Effect.Effect<A, EmailUnavailable, R> =>
|
|
43
|
+
reportPersistenceFailure(
|
|
44
|
+
effect,
|
|
45
|
+
(error) =>
|
|
46
|
+
Schema.is(EmailUnavailable)(error) ||
|
|
47
|
+
Schema.is(ProofUnavailable)(error) ||
|
|
48
|
+
Schema.is(HookConfigurationError)(error),
|
|
49
|
+
).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
50
|
+
|
|
51
|
+
const nowMillis = Effect.map(DateTime.now, DateTime.toEpochMillis);
|
|
52
|
+
|
|
53
|
+
export interface EmailRegistrationAuthority<Registration> {
|
|
54
|
+
readonly inspect: (input: {
|
|
55
|
+
readonly identifier: LoginIdentifier;
|
|
56
|
+
readonly registration: Registration;
|
|
57
|
+
}) => Effect.Effect<
|
|
58
|
+
{ readonly fingerprint: TokenDigest; readonly eligible: boolean },
|
|
59
|
+
EmailUnavailable
|
|
60
|
+
>;
|
|
61
|
+
readonly registerWithProof: <A>(
|
|
62
|
+
input: {
|
|
63
|
+
readonly moduleId: string;
|
|
64
|
+
readonly commandId: EmailCommandId;
|
|
65
|
+
readonly identifier: LoginIdentifier;
|
|
66
|
+
readonly registration: Registration;
|
|
67
|
+
readonly fingerprint: TokenDigest;
|
|
68
|
+
readonly completion: ProofCompletionPlan;
|
|
69
|
+
},
|
|
70
|
+
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
71
|
+
) => Effect.Effect<PreparedCommit<A>, EmailUnavailable>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface EmailRegistrationConfiguration {
|
|
75
|
+
readonly mode: "interactive" | "synchronous";
|
|
76
|
+
readonly locking: boolean;
|
|
77
|
+
readonly standaloneGuard: Effect.Effect<void, EmailUnavailable>;
|
|
78
|
+
readonly coordinated?: boolean;
|
|
79
|
+
readonly generatedSubjectRows: (query: EmailSqlQuery) => EmailSqlQuery;
|
|
80
|
+
readonly proof: {
|
|
81
|
+
readonly mapping: any;
|
|
82
|
+
readonly configuration: ProofSqlConfiguration;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const selectRows = (query: EmailSqlQuery, locking: boolean) =>
|
|
87
|
+
locking && typeof query.for === "function" ? query.for("update") : query;
|
|
88
|
+
|
|
89
|
+
const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>
|
|
90
|
+
left.namespace === right.namespace && left.value === right.value;
|
|
91
|
+
|
|
92
|
+
const validConstraints = <Registration>(mapping: Mapping<Registration>) => {
|
|
93
|
+
if (
|
|
94
|
+
mapping.constraints.request !== requiredEmailRegistrationConstraints.request ||
|
|
95
|
+
mapping.constraints.pendingReference !== requiredEmailRegistrationConstraints.pendingReference
|
|
96
|
+
)
|
|
97
|
+
return false;
|
|
98
|
+
if (mapping.mode === "pending") return true;
|
|
99
|
+
|
|
100
|
+
return Object.entries(requiredEmailRegistrationConstraints).every(
|
|
101
|
+
([key, value]) =>
|
|
102
|
+
mapping.constraints[key as keyof typeof requiredEmailRegistrationConstraints] === value,
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const allocate = <A>(
|
|
107
|
+
mode: EmailRegistrationConfiguration["mode"],
|
|
108
|
+
asynchronous: Effect.Effect<A, PersistenceMappingError> | undefined,
|
|
109
|
+
synchronous: (() => A) | undefined,
|
|
110
|
+
) => {
|
|
111
|
+
if (mode === "synchronous")
|
|
112
|
+
return synchronous === undefined
|
|
113
|
+
? Effect.fail(unavailable())
|
|
114
|
+
: Effect.try({
|
|
115
|
+
try: synchronous,
|
|
116
|
+
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
117
|
+
});
|
|
118
|
+
if (asynchronous !== undefined) return asynchronous;
|
|
119
|
+
|
|
120
|
+
return synchronous === undefined
|
|
121
|
+
? Effect.fail(unavailable())
|
|
122
|
+
: Effect.try({
|
|
123
|
+
try: synchronous,
|
|
124
|
+
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const registrationRows = Effect.fn("Drizzle.registrationRows")(function* <Registration>(
|
|
129
|
+
mapping: Mapping<Registration>,
|
|
130
|
+
moduleId: string,
|
|
131
|
+
commandId: string,
|
|
132
|
+
locking: boolean,
|
|
133
|
+
) {
|
|
134
|
+
const database = yield* CurrentEmailSql;
|
|
135
|
+
|
|
136
|
+
const module = column(mapping.registration.table, mapping.registration.moduleId);
|
|
137
|
+
const command = column(mapping.registration.table, mapping.registration.commandId);
|
|
138
|
+
|
|
139
|
+
return yield* selectRows(
|
|
140
|
+
database
|
|
141
|
+
.select()
|
|
142
|
+
.from(mapping.registration.table)
|
|
143
|
+
.where(and(eq(module, moduleId), eq(command, commandId)))
|
|
144
|
+
.limit(1),
|
|
145
|
+
locking,
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const owned = <A, E, R>(
|
|
150
|
+
database: EmailSqlDatabase,
|
|
151
|
+
configuration: EmailRegistrationConfiguration,
|
|
152
|
+
body: Effect.Effect<A, E, R>,
|
|
153
|
+
) => {
|
|
154
|
+
const run = coordinateCommit(
|
|
155
|
+
() =>
|
|
156
|
+
database.transaction((transaction) =>
|
|
157
|
+
body.pipe(
|
|
158
|
+
Effect.provideService(CurrentEmailSql, transaction),
|
|
159
|
+
Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
{ mode: configuration.mode },
|
|
163
|
+
).pipe(Effect.map((result) => result.value));
|
|
164
|
+
|
|
165
|
+
return configuration.coordinated !== true
|
|
166
|
+
? Effect.gen(function* () {
|
|
167
|
+
if (yield* hasCommitScope) return yield* unavailable();
|
|
168
|
+
yield* configuration.standaloneGuard;
|
|
169
|
+
|
|
170
|
+
return yield* run;
|
|
171
|
+
})
|
|
172
|
+
: run;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const completionMatches = <Registration>(
|
|
176
|
+
mapping: Mapping<Registration>,
|
|
177
|
+
input: {
|
|
178
|
+
readonly moduleId: string;
|
|
179
|
+
readonly identifier: LoginIdentifier;
|
|
180
|
+
readonly completion: ProofCompletionPlan;
|
|
181
|
+
},
|
|
182
|
+
) => {
|
|
183
|
+
const completion = input.completion.input;
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
completion.moduleId === `${input.moduleId}/registration` &&
|
|
187
|
+
completion.purpose === "email-code-registration" &&
|
|
188
|
+
completion.binding._tag === "Identifier" &&
|
|
189
|
+
sameIdentifier(completion.binding.identifier, input.identifier) &&
|
|
190
|
+
validConstraints(mapping)
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const prepareReplay = Effect.fn("DrizzleEmailRegistration.prepareReplay")(function* <
|
|
195
|
+
Registration,
|
|
196
|
+
A,
|
|
197
|
+
>(
|
|
198
|
+
mapping: Mapping<Registration>,
|
|
199
|
+
row: any,
|
|
200
|
+
fingerprint: TokenDigest,
|
|
201
|
+
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
202
|
+
) {
|
|
203
|
+
const journal = yield* CurrentCommitJournal;
|
|
204
|
+
|
|
205
|
+
if (row[mapping.registration.fingerprint] !== fingerprint)
|
|
206
|
+
return prepare({ _tag: "Rejected" }, journal);
|
|
207
|
+
|
|
208
|
+
return prepare(yield* mapping.registration.decodeReplay(row), journal);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const registerIn = Effect.fn("DrizzleEmailRegistration.registerIn")(function* <Registration, A>(
|
|
212
|
+
mapping: Mapping<Registration>,
|
|
213
|
+
configuration: EmailRegistrationConfiguration,
|
|
214
|
+
input: {
|
|
215
|
+
readonly moduleId: string;
|
|
216
|
+
readonly commandId: string;
|
|
217
|
+
readonly identifier: LoginIdentifier;
|
|
218
|
+
readonly registration: Registration;
|
|
219
|
+
readonly fingerprint: TokenDigest;
|
|
220
|
+
readonly completion: ProofCompletionPlan;
|
|
221
|
+
},
|
|
222
|
+
inspected: { readonly fingerprint: TokenDigest; readonly eligible: boolean },
|
|
223
|
+
allocated: {
|
|
224
|
+
readonly credentialId?: string;
|
|
225
|
+
readonly securityRevision?: SecurityRevision;
|
|
226
|
+
readonly identifierRevision?: SecurityRevision;
|
|
227
|
+
readonly credentialRevision?: SecurityRevision;
|
|
228
|
+
readonly nativeSubjectId?: unknown;
|
|
229
|
+
readonly pendingReference?: string;
|
|
230
|
+
},
|
|
231
|
+
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
232
|
+
) {
|
|
233
|
+
const journal = yield* CurrentCommitJournal;
|
|
234
|
+
|
|
235
|
+
const existing = (yield* registrationRows(
|
|
236
|
+
mapping,
|
|
237
|
+
input.moduleId,
|
|
238
|
+
input.commandId,
|
|
239
|
+
configuration.locking,
|
|
240
|
+
))[0];
|
|
241
|
+
|
|
242
|
+
if (existing !== undefined)
|
|
243
|
+
return yield* prepareReplay(mapping, existing, input.fingerprint, prepare);
|
|
244
|
+
if (!completionMatches(mapping, input)) return prepare({ _tag: "Rejected" }, journal);
|
|
245
|
+
if (!inspected.eligible || inspected.fingerprint !== input.fingerprint)
|
|
246
|
+
return prepare({ _tag: "Rejected" }, journal);
|
|
247
|
+
const now = yield* nowMillis;
|
|
248
|
+
|
|
249
|
+
const intent = {
|
|
250
|
+
moduleId: input.moduleId,
|
|
251
|
+
commandId: input.commandId,
|
|
252
|
+
identifier: Object.freeze({ ...input.identifier }),
|
|
253
|
+
registration: input.registration,
|
|
254
|
+
fingerprint: input.fingerprint,
|
|
255
|
+
completion: Object.freeze({
|
|
256
|
+
moduleId: input.completion.input.moduleId,
|
|
257
|
+
purpose: input.completion.input.purpose,
|
|
258
|
+
continuationId: input.completion.input.continuationId,
|
|
259
|
+
binding: input.completion.input.binding,
|
|
260
|
+
}),
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
let decision: EmailRegistrationDecision | undefined;
|
|
264
|
+
let nativeSubjectId = allocated.nativeSubjectId;
|
|
265
|
+
|
|
266
|
+
const protectedMutation = Effect.gen(function* () {
|
|
267
|
+
const transaction = yield* CurrentEmailSql;
|
|
268
|
+
|
|
269
|
+
if (mapping.mode === "pending") {
|
|
270
|
+
if (allocated.pendingReference === undefined) return false;
|
|
271
|
+
decision = { _tag: "ProvisioningPending", reference: allocated.pendingReference };
|
|
272
|
+
yield* transaction.insert(mapping.registration.table).values(
|
|
273
|
+
mapping.registration.encodeInsert(intent, {
|
|
274
|
+
state: "pending",
|
|
275
|
+
pendingReference: allocated.pendingReference,
|
|
276
|
+
retentionUntilMillis: now + mapping.retentionMillis,
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
} else {
|
|
280
|
+
if (
|
|
281
|
+
allocated.credentialId === undefined ||
|
|
282
|
+
allocated.securityRevision === undefined ||
|
|
283
|
+
allocated.identifierRevision === undefined ||
|
|
284
|
+
allocated.credentialRevision === undefined
|
|
285
|
+
)
|
|
286
|
+
return false;
|
|
287
|
+
|
|
288
|
+
const subjectInsert = transaction.insert(mapping.subject.table).values(
|
|
289
|
+
mapping.provisioning.encodeSubjectInsert(intent, {
|
|
290
|
+
nativeSubjectId,
|
|
291
|
+
securityRevision: allocated.securityRevision,
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
if (mapping.provisioning.idMode === "generated") {
|
|
296
|
+
const rows = yield* configuration.generatedSubjectRows(subjectInsert);
|
|
297
|
+
|
|
298
|
+
nativeSubjectId = yield* mapping.provisioning.decodeGeneratedId(rows);
|
|
299
|
+
} else yield* subjectInsert;
|
|
300
|
+
if (nativeSubjectId === undefined) return false;
|
|
301
|
+
yield* transaction.insert(mapping.identifier.table).values(
|
|
302
|
+
mapping.identifier.encodeVerifiedInsert({
|
|
303
|
+
identifier: input.identifier,
|
|
304
|
+
subjectId: nativeSubjectId,
|
|
305
|
+
verifiedAtMillis: now,
|
|
306
|
+
bindingRevision: allocated.identifierRevision,
|
|
307
|
+
}),
|
|
308
|
+
);
|
|
309
|
+
yield* transaction.insert(mapping.credential.table).values(
|
|
310
|
+
mapping.credential.encodeVerifiedInsert({
|
|
311
|
+
moduleId: input.moduleId,
|
|
312
|
+
subjectId: nativeSubjectId,
|
|
313
|
+
credentialId: allocated.credentialId,
|
|
314
|
+
identifier: input.identifier,
|
|
315
|
+
credentialRevision: allocated.credentialRevision,
|
|
316
|
+
}),
|
|
317
|
+
);
|
|
318
|
+
yield* transaction.insert(mapping.authorityCredential.table).values(
|
|
319
|
+
mapping.authorityCredential.encodeInsert({
|
|
320
|
+
subjectId: nativeSubjectId,
|
|
321
|
+
credentialId: allocated.credentialId,
|
|
322
|
+
revision: allocated.credentialRevision,
|
|
323
|
+
}),
|
|
324
|
+
);
|
|
325
|
+
yield* transaction.insert(mapping.registration.table).values(
|
|
326
|
+
mapping.registration.encodeInsert(intent, {
|
|
327
|
+
state: "registered",
|
|
328
|
+
nativeSubjectId,
|
|
329
|
+
retentionUntilMillis: now + mapping.retentionMillis,
|
|
330
|
+
}),
|
|
331
|
+
);
|
|
332
|
+
decision = { _tag: "Registered" };
|
|
333
|
+
}
|
|
334
|
+
const stored = (yield* registrationRows(mapping, input.moduleId, input.commandId, false))[0];
|
|
335
|
+
const registrationModule = column(mapping.registration.table, mapping.registration.moduleId);
|
|
336
|
+
const registrationCommand = column(mapping.registration.table, mapping.registration.commandId);
|
|
337
|
+
|
|
338
|
+
const registrationFingerprint = column(
|
|
339
|
+
mapping.registration.table,
|
|
340
|
+
mapping.registration.fingerprint,
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
const registrationState = column(mapping.registration.table, mapping.registration.state);
|
|
344
|
+
const registrationSubject = column(mapping.registration.table, mapping.registration.subjectId);
|
|
345
|
+
|
|
346
|
+
const registrationReference = column(
|
|
347
|
+
mapping.registration.table,
|
|
348
|
+
mapping.registration.pendingReference,
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const registrationRetention = column(
|
|
352
|
+
mapping.registration.table,
|
|
353
|
+
mapping.registration.retentionUntil,
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const exactRegistration = yield* selectRows(
|
|
357
|
+
transaction
|
|
358
|
+
.select()
|
|
359
|
+
.from(mapping.registration.table)
|
|
360
|
+
.where(
|
|
361
|
+
and(
|
|
362
|
+
eq(registrationModule, input.moduleId),
|
|
363
|
+
eq(registrationCommand, input.commandId),
|
|
364
|
+
eq(registrationFingerprint, input.fingerprint),
|
|
365
|
+
eq(registrationState, mapping.mode === "pending" ? "pending" : "registered"),
|
|
366
|
+
eq(registrationRetention, mapping.encodeInstant(now + mapping.retentionMillis)),
|
|
367
|
+
mapping.mode === "pending"
|
|
368
|
+
? and(
|
|
369
|
+
eq(registrationReference, allocated.pendingReference!),
|
|
370
|
+
isNull(registrationSubject),
|
|
371
|
+
)
|
|
372
|
+
: and(eq(registrationSubject, nativeSubjectId), isNull(registrationReference)),
|
|
373
|
+
),
|
|
374
|
+
)
|
|
375
|
+
.limit(1),
|
|
376
|
+
false,
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
if (mapping.mode === "atomic" && nativeSubjectId !== undefined) {
|
|
380
|
+
const subjectId = column(mapping.subject.table, mapping.subject.id);
|
|
381
|
+
const identifierNamespace = column(mapping.identifier.table, mapping.identifier.namespace);
|
|
382
|
+
const identifierValue = column(mapping.identifier.table, mapping.identifier.value);
|
|
383
|
+
const identifierSubject = column(mapping.identifier.table, mapping.identifier.subjectId);
|
|
384
|
+
const identifierVerifiedAt = column(mapping.identifier.table, mapping.identifier.verifiedAt);
|
|
385
|
+
const credentialModule = column(mapping.credential.table, mapping.credential.moduleId);
|
|
386
|
+
const credentialId = column(mapping.credential.table, mapping.credential.credentialId);
|
|
387
|
+
const credentialSubject = column(mapping.credential.table, mapping.credential.subjectId);
|
|
388
|
+
|
|
389
|
+
const credentialNamespace = column(
|
|
390
|
+
mapping.credential.table,
|
|
391
|
+
mapping.credential.identifierNamespace,
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
const credentialValue = column(mapping.credential.table, mapping.credential.identifierValue);
|
|
395
|
+
|
|
396
|
+
const authoritySubject = column(
|
|
397
|
+
mapping.authorityCredential.table,
|
|
398
|
+
mapping.authorityCredential.subjectId,
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
const authorityId = column(
|
|
402
|
+
mapping.authorityCredential.table,
|
|
403
|
+
mapping.authorityCredential.credentialId,
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
const subject = (yield* selectRows(
|
|
407
|
+
transaction
|
|
408
|
+
.select()
|
|
409
|
+
.from(mapping.subject.table)
|
|
410
|
+
.where(eq(subjectId, nativeSubjectId))
|
|
411
|
+
.limit(1),
|
|
412
|
+
false,
|
|
413
|
+
))[0];
|
|
414
|
+
|
|
415
|
+
const identifier = (yield* selectRows(
|
|
416
|
+
transaction
|
|
417
|
+
.select()
|
|
418
|
+
.from(mapping.identifier.table)
|
|
419
|
+
.where(
|
|
420
|
+
and(
|
|
421
|
+
eq(identifierNamespace, input.identifier.namespace),
|
|
422
|
+
eq(identifierValue, input.identifier.value),
|
|
423
|
+
eq(identifierSubject, nativeSubjectId),
|
|
424
|
+
eq(identifierVerifiedAt, mapping.encodeInstant(now)),
|
|
425
|
+
),
|
|
426
|
+
)
|
|
427
|
+
.limit(1),
|
|
428
|
+
false,
|
|
429
|
+
))[0];
|
|
430
|
+
|
|
431
|
+
const credential = (yield* selectRows(
|
|
432
|
+
transaction
|
|
433
|
+
.select()
|
|
434
|
+
.from(mapping.credential.table)
|
|
435
|
+
.where(
|
|
436
|
+
and(
|
|
437
|
+
eq(credentialModule, input.moduleId),
|
|
438
|
+
eq(credentialId, allocated.credentialId!),
|
|
439
|
+
eq(credentialSubject, nativeSubjectId),
|
|
440
|
+
eq(credentialNamespace, input.identifier.namespace),
|
|
441
|
+
eq(credentialValue, input.identifier.value),
|
|
442
|
+
),
|
|
443
|
+
)
|
|
444
|
+
.limit(1),
|
|
445
|
+
false,
|
|
446
|
+
))[0];
|
|
447
|
+
|
|
448
|
+
const authority = (yield* selectRows(
|
|
449
|
+
transaction
|
|
450
|
+
.select()
|
|
451
|
+
.from(mapping.authorityCredential.table)
|
|
452
|
+
.where(
|
|
453
|
+
and(eq(authoritySubject, nativeSubjectId), eq(authorityId, allocated.credentialId!)),
|
|
454
|
+
)
|
|
455
|
+
.limit(1),
|
|
456
|
+
false,
|
|
457
|
+
))[0];
|
|
458
|
+
|
|
459
|
+
if (
|
|
460
|
+
subject === undefined ||
|
|
461
|
+
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
462
|
+
subject[mapping.subject.securityRevision] !== allocated.securityRevision ||
|
|
463
|
+
identifier === undefined ||
|
|
464
|
+
identifier[mapping.identifier.bindingRevision] !== allocated.identifierRevision ||
|
|
465
|
+
!mapping.identifier.isCurrent(identifier) ||
|
|
466
|
+
credential === undefined ||
|
|
467
|
+
credential[mapping.credential.credentialRevision] !== allocated.credentialRevision ||
|
|
468
|
+
!mapping.credential.isActiveStatus(credential[mapping.credential.status]) ||
|
|
469
|
+
authority === undefined ||
|
|
470
|
+
authority[mapping.authorityCredential.revision] !== allocated.credentialRevision ||
|
|
471
|
+
!mapping.authorityCredential.isActiveStatus(authority[mapping.authorityCredential.status])
|
|
472
|
+
)
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return (
|
|
477
|
+
stored !== undefined &&
|
|
478
|
+
exactRegistration.length === 1 &&
|
|
479
|
+
stored[mapping.registration.fingerprint] === input.fingerprint &&
|
|
480
|
+
(mapping.mode === "pending" ||
|
|
481
|
+
(nativeSubjectId !== undefined &&
|
|
482
|
+
stored[mapping.registration.subjectId] !== null &&
|
|
483
|
+
mapping.subjectId.equals(stored[mapping.registration.subjectId], nativeSubjectId)))
|
|
484
|
+
);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
let receipt: PreparedCommit<A> | undefined;
|
|
488
|
+
|
|
489
|
+
yield* completeProofPlanIn(
|
|
490
|
+
configuration.proof.mapping,
|
|
491
|
+
configuration.proof.configuration,
|
|
492
|
+
input.completion,
|
|
493
|
+
protectedMutation,
|
|
494
|
+
(completionDecision) => {
|
|
495
|
+
receipt = prepare(
|
|
496
|
+
completionDecision === "completed" && decision !== undefined
|
|
497
|
+
? decision
|
|
498
|
+
: { _tag: "Rejected" },
|
|
499
|
+
journal,
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
return completionDecision;
|
|
503
|
+
},
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
return receipt ?? prepare({ _tag: "Rejected" }, journal);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const prepareConflict = Effect.fn("Drizzle.prepareConflict")(function* <Registration, A>(
|
|
510
|
+
mapping: Mapping<Registration>,
|
|
511
|
+
configuration: EmailRegistrationConfiguration,
|
|
512
|
+
input: {
|
|
513
|
+
readonly moduleId: string;
|
|
514
|
+
readonly commandId: string;
|
|
515
|
+
readonly fingerprint: TokenDigest;
|
|
516
|
+
},
|
|
517
|
+
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
518
|
+
) {
|
|
519
|
+
const database = yield* CurrentEmailSql;
|
|
520
|
+
|
|
521
|
+
return yield* owned(
|
|
522
|
+
database,
|
|
523
|
+
configuration,
|
|
524
|
+
Effect.gen(function* () {
|
|
525
|
+
const journal = yield* CurrentCommitJournal;
|
|
526
|
+
|
|
527
|
+
const row = (yield* registrationRows(
|
|
528
|
+
mapping,
|
|
529
|
+
input.moduleId,
|
|
530
|
+
input.commandId,
|
|
531
|
+
configuration.locking,
|
|
532
|
+
))[0];
|
|
533
|
+
|
|
534
|
+
return row === undefined
|
|
535
|
+
? prepare({ _tag: "Rejected" }, journal)
|
|
536
|
+
: yield* prepareReplay(mapping, row, input.fingerprint, prepare);
|
|
537
|
+
}),
|
|
538
|
+
);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
export const makeSqlEmailRegistrationAuthority = Effect.fn("makeSqlEmailRegistrationAuthority")(
|
|
542
|
+
function* <Registration>(
|
|
543
|
+
database: EmailSqlDatabase,
|
|
544
|
+
mapping: Mapping<Registration>,
|
|
545
|
+
configuration: EmailRegistrationConfiguration,
|
|
546
|
+
): Effect.fn.Return<EmailRegistrationAuthority<Registration>, never, LifecycleHooks> {
|
|
547
|
+
const hooks = yield* LifecycleHooks;
|
|
548
|
+
|
|
549
|
+
return {
|
|
550
|
+
inspect: (input) =>
|
|
551
|
+
mapping
|
|
552
|
+
.inspect(input)
|
|
553
|
+
.pipe(
|
|
554
|
+
Effect.provideService(CurrentEmailSql, database),
|
|
555
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
556
|
+
translateFailure,
|
|
557
|
+
),
|
|
558
|
+
registerWithProof: (input, prepare) =>
|
|
559
|
+
Effect.gen(function* () {
|
|
560
|
+
if (!validConstraints(mapping)) return yield* unavailable();
|
|
561
|
+
|
|
562
|
+
const snapshot = (registration: Registration) =>
|
|
563
|
+
configuration.mode === "synchronous" && configuration.coordinated === true
|
|
564
|
+
? mapping.snapshotRegistrationSync === undefined
|
|
565
|
+
? Effect.fail(unavailable())
|
|
566
|
+
: Effect.try({
|
|
567
|
+
try: () => mapping.snapshotRegistrationSync!(registration),
|
|
568
|
+
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
569
|
+
})
|
|
570
|
+
: mapping.snapshotRegistration(registration);
|
|
571
|
+
|
|
572
|
+
const storedRegistration = yield* snapshot(input.registration);
|
|
573
|
+
const inspectionRegistration = yield* snapshot(input.registration);
|
|
574
|
+
|
|
575
|
+
const capturedInput = Object.freeze({
|
|
576
|
+
...input,
|
|
577
|
+
identifier: Object.freeze({ ...input.identifier }),
|
|
578
|
+
registration: storedRegistration,
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// Registration decoding and fingerprinting may suspend (for example while
|
|
582
|
+
// hashing a detached Registration value). Finish that work before a
|
|
583
|
+
// synchronous Durable Object transaction owner is entered.
|
|
584
|
+
const inspectInput = {
|
|
585
|
+
identifier: capturedInput.identifier,
|
|
586
|
+
registration: inspectionRegistration,
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
const inspected =
|
|
590
|
+
configuration.mode === "synchronous" && configuration.coordinated === true
|
|
591
|
+
? mapping.inspectSync === undefined
|
|
592
|
+
? yield* unavailable()
|
|
593
|
+
: yield* Effect.try({
|
|
594
|
+
try: () => mapping.inspectSync!(inspectInput),
|
|
595
|
+
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
596
|
+
})
|
|
597
|
+
: yield* mapping.inspect(inspectInput);
|
|
598
|
+
|
|
599
|
+
const atomic = mapping.mode === "atomic";
|
|
600
|
+
|
|
601
|
+
const credentialId = atomic
|
|
602
|
+
? yield* allocate(
|
|
603
|
+
configuration.mode,
|
|
604
|
+
mapping.allocateCredentialId,
|
|
605
|
+
mapping.allocateCredentialIdSync,
|
|
606
|
+
)
|
|
607
|
+
: undefined;
|
|
608
|
+
|
|
609
|
+
const securityRevision = atomic
|
|
610
|
+
? yield* allocate(
|
|
611
|
+
configuration.mode,
|
|
612
|
+
mapping.allocateRevision,
|
|
613
|
+
mapping.allocateRevisionSync,
|
|
614
|
+
)
|
|
615
|
+
: undefined;
|
|
616
|
+
|
|
617
|
+
const identifierRevision = atomic
|
|
618
|
+
? yield* allocate(
|
|
619
|
+
configuration.mode,
|
|
620
|
+
mapping.allocateRevision,
|
|
621
|
+
mapping.allocateRevisionSync,
|
|
622
|
+
)
|
|
623
|
+
: undefined;
|
|
624
|
+
|
|
625
|
+
const credentialRevision = atomic
|
|
626
|
+
? yield* allocate(
|
|
627
|
+
configuration.mode,
|
|
628
|
+
mapping.allocateRevision,
|
|
629
|
+
mapping.allocateRevisionSync,
|
|
630
|
+
)
|
|
631
|
+
: undefined;
|
|
632
|
+
|
|
633
|
+
const nativeSubjectId =
|
|
634
|
+
atomic && mapping.provisioning.idMode !== "generated"
|
|
635
|
+
? yield* allocate(
|
|
636
|
+
configuration.mode,
|
|
637
|
+
mapping.provisioning.allocateSubjectId,
|
|
638
|
+
mapping.provisioning.allocateSubjectIdSync,
|
|
639
|
+
)
|
|
640
|
+
: undefined;
|
|
641
|
+
|
|
642
|
+
const pendingReference =
|
|
643
|
+
mapping.mode === "pending"
|
|
644
|
+
? yield* allocate(
|
|
645
|
+
configuration.mode,
|
|
646
|
+
mapping.allocatePendingReference,
|
|
647
|
+
mapping.allocatePendingReferenceSync,
|
|
648
|
+
)
|
|
649
|
+
: undefined;
|
|
650
|
+
|
|
651
|
+
const run = owned(
|
|
652
|
+
database,
|
|
653
|
+
configuration,
|
|
654
|
+
Effect.gen(function* () {
|
|
655
|
+
return yield* registerIn(
|
|
656
|
+
mapping,
|
|
657
|
+
configuration,
|
|
658
|
+
capturedInput,
|
|
659
|
+
inspected,
|
|
660
|
+
{
|
|
661
|
+
...(credentialId === undefined ? {} : { credentialId }),
|
|
662
|
+
...(securityRevision === undefined ? {} : { securityRevision }),
|
|
663
|
+
...(identifierRevision === undefined ? {} : { identifierRevision }),
|
|
664
|
+
...(credentialRevision === undefined ? {} : { credentialRevision }),
|
|
665
|
+
...(nativeSubjectId === undefined ? {} : { nativeSubjectId }),
|
|
666
|
+
...(pendingReference === undefined ? {} : { pendingReference }),
|
|
667
|
+
},
|
|
668
|
+
prepare,
|
|
669
|
+
);
|
|
670
|
+
}),
|
|
671
|
+
);
|
|
672
|
+
|
|
673
|
+
return yield* run.pipe(
|
|
674
|
+
Effect.catchCause((cause) => {
|
|
675
|
+
const request =
|
|
676
|
+
cause.reasons.every(Cause.isFailReason) &&
|
|
677
|
+
isMappedConstraintConflict(mapping.isRequestConflict, cause);
|
|
678
|
+
|
|
679
|
+
const conflict =
|
|
680
|
+
mapping.mode === "atomic" &&
|
|
681
|
+
((cause.reasons.every(Cause.isFailReason) &&
|
|
682
|
+
isMappedConstraintConflict(mapping.isIdentifierConflict, cause)) ||
|
|
683
|
+
(cause.reasons.every(Cause.isFailReason) &&
|
|
684
|
+
isMappedConstraintConflict(mapping.isCredentialConflict, cause)));
|
|
685
|
+
|
|
686
|
+
return request || conflict
|
|
687
|
+
? prepareConflict(mapping, configuration, capturedInput, prepare)
|
|
688
|
+
: Effect.failCause(cause);
|
|
689
|
+
}),
|
|
690
|
+
);
|
|
691
|
+
}).pipe(
|
|
692
|
+
Effect.provideService(CurrentEmailSql, database),
|
|
693
|
+
Effect.provideService(LifecycleHooks, hooks),
|
|
694
|
+
translateFailure,
|
|
695
|
+
),
|
|
696
|
+
};
|
|
697
|
+
},
|
|
698
|
+
);
|