@yielded/auth-persistence-drizzle 0.1.0-beta.24 → 0.1.0-beta.26
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 +4 -2
- package/dist/D1.d.mts +495 -1151
- package/dist/D1.mjs +41 -19
- package/dist/D1.mjs.map +1 -1
- package/dist/Libsql.d.mts +385 -1996
- package/dist/Libsql.mjs +43 -47
- package/dist/Libsql.mjs.map +1 -1
- package/dist/Mysql2.d.mts +397 -1743
- package/dist/Mysql2.mjs +35 -41
- package/dist/Mysql2.mjs.map +1 -1
- package/dist/Pglite.d.mts +397 -1743
- package/dist/Pglite.mjs +42 -31
- package/dist/Pglite.mjs.map +1 -1
- package/dist/Postgres.d.mts +397 -1743
- package/dist/Postgres.mjs +42 -31
- package/dist/Postgres.mjs.map +1 -1
- package/dist/SqliteBun.d.mts +385 -1992
- package/dist/SqliteBun.mjs +43 -43
- package/dist/SqliteBun.mjs.map +1 -1
- package/dist/SqliteDo.d.mts +385 -1991
- package/dist/SqliteDo.mjs +42 -41
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +385 -1992
- package/dist/SqliteNode.mjs +43 -43
- package/dist/SqliteNode.mjs.map +1 -1
- package/dist/SqliteWasm.d.mts +385 -1992
- package/dist/SqliteWasm.mjs +43 -43
- package/dist/SqliteWasm.mjs.map +1 -1
- package/dist/drizzle/d1-identity.mjs +2 -2
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/driver-types.d.mts +15 -0
- package/dist/drizzle/email-drivers.mjs +32 -0
- package/dist/drizzle/email-drivers.mjs.map +1 -0
- package/dist/drizzle/email-model.d.mts +9 -13
- package/dist/drizzle/email-target.d.mts +10 -11
- package/dist/drizzle/email-target.mjs +33 -70
- package/dist/drizzle/email-target.mjs.map +1 -1
- package/dist/drizzle/model.d.mts +1 -10
- package/dist/drizzle/model.mjs +1 -2
- package/dist/drizzle/model.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +3 -6
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/native-clock.d.mts +9 -0
- package/dist/drizzle/native-clock.mjs +18 -0
- package/dist/drizzle/native-clock.mjs.map +1 -0
- package/dist/drizzle/native-database.d.mts +46 -0
- package/dist/drizzle/native-database.mjs +6 -5
- package/dist/drizzle/native-database.mjs.map +1 -1
- package/dist/drizzle/native-sql-table.mjs +13 -5
- package/dist/drizzle/native-sql-table.mjs.map +1 -1
- package/dist/drizzle/native-target.d.mts +6 -0
- package/dist/drizzle/native-target.mjs +44 -0
- package/dist/drizzle/native-target.mjs.map +1 -0
- package/dist/drizzle/oauth-connected-drivers.mjs +4 -56
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-model.d.mts +5 -22
- package/dist/drizzle/oauth-connected-model.mjs +1 -7
- package/dist/drizzle/oauth-connected-reference.d.mts +5 -7
- package/dist/drizzle/oauth-connected-reference.mjs +11 -3
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs +1 -2
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-model.d.mts +11 -37
- package/dist/drizzle/oauth-model.mjs +3 -4
- package/dist/drizzle/oauth-model.mjs.map +1 -1
- package/dist/drizzle/oauth-proxy.d.mts +1 -1
- package/dist/drizzle/oauth-proxy.mjs +1 -1
- package/dist/drizzle/oauth-target.d.mts +9 -6
- package/dist/drizzle/oauth-target.mjs +47 -15
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey/target.d.mts +14 -0
- package/dist/drizzle/passkey/target.mjs +52 -0
- package/dist/drizzle/passkey/target.mjs.map +1 -0
- package/dist/drizzle/passkey/write-target.d.mts +11 -0
- package/dist/drizzle/passkey/write-target.mjs +28 -0
- package/dist/drizzle/passkey/write-target.mjs.map +1 -0
- package/dist/drizzle/passkey-drivers.mjs +2 -4
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-model.d.mts +5 -26
- package/dist/drizzle/passkey-model.mjs +2 -8
- package/dist/drizzle/passkey-registration-ceremony-model.d.mts +3 -6
- package/dist/drizzle/passkey-write-drivers.mjs +2 -3
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-model.d.mts +7 -9
- package/dist/drizzle/passkey-write-model.mjs +1 -3
- package/dist/drizzle/passkey-write-model.mjs.map +1 -1
- package/dist/drizzle/password-drivers.mjs +31 -0
- package/dist/drizzle/password-drivers.mjs.map +1 -0
- package/dist/drizzle/password-model.d.mts +7 -10
- package/dist/drizzle/password-target.d.mts +7 -8
- package/dist/drizzle/password-target.mjs +23 -68
- package/dist/drizzle/password-target.mjs.map +1 -1
- package/dist/drizzle/pg-identity.mjs +3 -6
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/phone-drivers.mjs +24 -0
- package/dist/drizzle/phone-drivers.mjs.map +1 -0
- package/dist/drizzle/phone-model.d.mts +13 -104
- package/dist/drizzle/phone-model.mjs +5 -33
- package/dist/drizzle/phone-model.mjs.map +1 -1
- package/dist/drizzle/phone-target.mjs +22 -171
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/proof-drivers.mjs +24 -0
- package/dist/drizzle/proof-drivers.mjs.map +1 -0
- package/dist/drizzle/proof-model.d.mts +7 -15
- package/dist/drizzle/proof-target.d.mts +5 -5
- package/dist/drizzle/proof-target.mjs +14 -28
- package/dist/drizzle/proof-target.mjs.map +1 -1
- package/dist/drizzle/session-drivers.mjs +97 -0
- package/dist/drizzle/session-drivers.mjs.map +1 -0
- package/dist/drizzle/session-model.d.mts +11 -22
- package/dist/drizzle/sqlite-do-database.d.mts +3 -3
- package/dist/drizzle/sqlite-do-database.mjs +6 -1
- package/dist/drizzle/sqlite-do-database.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +3 -5
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/step-up-model.d.mts +2 -5
- package/dist/drizzle/storage-validation.mjs +2 -1
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-model.d.mts +7 -74
- package/dist/drizzle/totp-model.mjs +1 -5
- package/dist/drizzle/totp-model.mjs.map +1 -1
- package/dist/drizzle/totp-target.mjs +39 -75
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/dist/drizzle/transaction-handle.mjs +13 -0
- package/dist/drizzle/transaction-handle.mjs.map +1 -0
- package/dist/drizzle/transaction-mysql.mjs +43 -12
- package/dist/drizzle/transaction-mysql.mjs.map +1 -1
- package/dist/index.d.mts +17 -22
- package/dist/index.mjs +10 -16
- package/dist/internal/drizzle-postgres.mjs +4 -6
- package/dist/internal/drizzle-postgres.mjs.map +1 -1
- package/dist/internal/drizzle-sqlite.mjs +4 -6
- package/dist/internal/drizzle-sqlite.mjs.map +1 -1
- package/package.json +1 -1
- package/src/D1.ts +77 -74
- package/src/Libsql.ts +65 -105
- package/src/Mysql2.ts +52 -87
- package/src/Pglite.ts +74 -81
- package/src/Postgres.ts +74 -81
- package/src/SqliteBun.ts +65 -113
- package/src/SqliteDo.ts +58 -106
- package/src/SqliteNode.ts +65 -113
- package/src/SqliteWasm.ts +65 -113
- package/src/drizzle/d1-identity.ts +2 -2
- package/src/drizzle/driver-types.ts +26 -0
- package/src/drizzle/email-drivers.ts +320 -0
- package/src/drizzle/email-model.ts +24 -78
- package/src/drizzle/email-target.ts +118 -211
- package/src/drizzle/model.ts +0 -2
- package/src/drizzle/mysql-identity.ts +4 -24
- package/src/drizzle/native-clock.ts +21 -0
- package/src/drizzle/native-database.ts +59 -18
- package/src/drizzle/native-sql-table.ts +104 -87
- package/src/drizzle/native-target.ts +120 -0
- package/src/drizzle/oauth-connected-drivers.ts +24 -233
- package/src/drizzle/oauth-connected-model.ts +3 -93
- package/src/drizzle/oauth-connected-reference.ts +16 -25
- package/src/drizzle/oauth-drivers.ts +58 -99
- package/src/drizzle/oauth-model.ts +27 -132
- package/src/drizzle/oauth-target.ts +250 -33
- package/src/drizzle/passkey/target.ts +205 -0
- package/src/drizzle/passkey/write-target.ts +91 -0
- package/src/drizzle/passkey-drivers.ts +35 -133
- package/src/drizzle/passkey-model.ts +3 -81
- package/src/drizzle/passkey-registration-ceremony-model.ts +5 -25
- package/src/drizzle/passkey-write-drivers.ts +32 -102
- package/src/drizzle/passkey-write-model.ts +10 -44
- package/src/drizzle/password-drivers.ts +286 -0
- package/src/drizzle/password-model.ts +10 -44
- package/src/drizzle/password-target.ts +85 -239
- package/src/drizzle/pg-identity.ts +4 -19
- package/src/drizzle/phone-drivers.ts +142 -0
- package/src/drizzle/phone-model.ts +22 -162
- package/src/drizzle/phone-target.ts +51 -493
- package/src/drizzle/proof-drivers.ts +123 -0
- package/src/drizzle/proof-model.ts +12 -123
- package/src/drizzle/proof-target.ts +38 -102
- package/src/drizzle/session-drivers.ts +696 -0
- package/src/drizzle/session-model.ts +54 -118
- package/src/drizzle/sqlite-do-database.ts +8 -0
- package/src/drizzle/sqlite-identity.ts +4 -22
- package/src/drizzle/step-up-model.ts +13 -37
- package/src/drizzle/storage-validation.ts +2 -1
- package/src/drizzle/totp-model.ts +20 -77
- package/src/drizzle/totp-target.ts +121 -261
- package/src/drizzle/transaction-handle.ts +41 -0
- package/src/drizzle/transaction-mysql.ts +90 -25
- package/src/index.ts +7 -122
- package/src/internal/drizzle-postgres.ts +4 -7
- package/src/internal/drizzle-sqlite.ts +4 -7
- package/dist/drizzle/crypto.mjs +0 -11
- package/dist/drizzle/crypto.mjs.map +0 -1
- package/dist/drizzle/d1-emails.d.mts +0 -62
- package/dist/drizzle/d1-emails.mjs +0 -626
- package/dist/drizzle/d1-emails.mjs.map +0 -1
- package/dist/drizzle/d1-generated-statement.mjs +0 -79
- package/dist/drizzle/d1-generated-statement.mjs.map +0 -1
- package/dist/drizzle/d1-oauth.d.mts +0 -331
- package/dist/drizzle/d1-oauth.mjs +0 -79
- package/dist/drizzle/d1-oauth.mjs.map +0 -1
- package/dist/drizzle/d1-passkey.d.mts +0 -37
- package/dist/drizzle/d1-passkey.mjs +0 -98
- package/dist/drizzle/d1-passkey.mjs.map +0 -1
- package/dist/drizzle/d1-password-prepared.d.mts +0 -25
- package/dist/drizzle/d1-password-prepared.mjs +0 -473
- package/dist/drizzle/d1-password-prepared.mjs.map +0 -1
- package/dist/drizzle/d1-passwords.d.mts +0 -70
- package/dist/drizzle/d1-passwords.mjs +0 -808
- package/dist/drizzle/d1-passwords.mjs.map +0 -1
- package/dist/drizzle/d1-phone.d.mts +0 -23
- package/dist/drizzle/d1-phone.mjs +0 -33
- package/dist/drizzle/d1-phone.mjs.map +0 -1
- package/dist/drizzle/d1-planning.d.mts +0 -11
- package/dist/drizzle/d1-planning.mjs +0 -43
- package/dist/drizzle/d1-planning.mjs.map +0 -1
- package/dist/drizzle/d1-proofs.d.mts +0 -80
- package/dist/drizzle/d1-proofs.mjs +0 -842
- package/dist/drizzle/d1-proofs.mjs.map +0 -1
- package/dist/drizzle/d1-sessions.d.mts +0 -68
- package/dist/drizzle/d1-sessions.mjs +0 -987
- package/dist/drizzle/d1-sessions.mjs.map +0 -1
- package/dist/drizzle/d1-totp.d.mts +0 -23
- package/dist/drizzle/d1-totp.mjs +0 -30
- package/dist/drizzle/d1-totp.mjs.map +0 -1
- package/dist/drizzle/email-registration.d.mts +0 -33
- package/dist/drizzle/email-registration.mjs +0 -281
- package/dist/drizzle/email-registration.mjs.map +0 -1
- package/dist/drizzle/email-sql.d.mts +0 -1
- package/dist/drizzle/email-sql.mjs +0 -9
- package/dist/drizzle/email-sql.mjs.map +0 -1
- package/dist/drizzle/mysql-emails.d.mts +0 -71
- package/dist/drizzle/mysql-emails.mjs +0 -43
- package/dist/drizzle/mysql-emails.mjs.map +0 -1
- package/dist/drizzle/mysql-password-prepared.d.mts +0 -30
- package/dist/drizzle/mysql-password-prepared.mjs +0 -21
- package/dist/drizzle/mysql-password-prepared.mjs.map +0 -1
- package/dist/drizzle/mysql-passwords.d.mts +0 -71
- package/dist/drizzle/mysql-passwords.mjs +0 -43
- package/dist/drizzle/mysql-passwords.mjs.map +0 -1
- package/dist/drizzle/mysql-proofs.d.mts +0 -75
- package/dist/drizzle/mysql-proofs.mjs +0 -28
- package/dist/drizzle/mysql-proofs.mjs.map +0 -1
- package/dist/drizzle/mysql-sessions.d.mts +0 -92
- package/dist/drizzle/mysql-sessions.mjs +0 -58
- package/dist/drizzle/mysql-sessions.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-model.mjs.map +0 -1
- package/dist/drizzle/oauth-connected-target.d.mts +0 -6
- package/dist/drizzle/oauth-connected-target.mjs +0 -12
- package/dist/drizzle/oauth-connected-target.mjs.map +0 -1
- package/dist/drizzle/oauth-kernel.mjs +0 -11
- package/dist/drizzle/oauth-kernel.mjs.map +0 -1
- package/dist/drizzle/oauth-mysql.mjs +0 -8
- package/dist/drizzle/oauth-mysql.mjs.map +0 -1
- package/dist/drizzle/passkey-kernel.mjs +0 -8
- package/dist/drizzle/passkey-kernel.mjs.map +0 -1
- package/dist/drizzle/passkey-model.mjs.map +0 -1
- package/dist/drizzle/passkey-registration-ceremony-model.mjs +0 -2
- package/dist/drizzle/passkey-state.mjs +0 -7
- package/dist/drizzle/passkey-state.mjs.map +0 -1
- package/dist/drizzle/passkey-target.d.mts +0 -2
- package/dist/drizzle/passkey-target.mjs +0 -7
- package/dist/drizzle/passkey-target.mjs.map +0 -1
- package/dist/drizzle/passkey-write-target.d.mts +0 -5
- package/dist/drizzle/passkey-write-target.mjs +0 -7
- package/dist/drizzle/passkey-write-target.mjs.map +0 -1
- package/dist/drizzle/password-prepared-model.d.mts +0 -92
- package/dist/drizzle/password-prepared-model.mjs +0 -11
- package/dist/drizzle/password-prepared-model.mjs.map +0 -1
- package/dist/drizzle/password-prepared-sql.mjs +0 -395
- package/dist/drizzle/password-prepared-sql.mjs.map +0 -1
- package/dist/drizzle/password-prepared-state.mjs +0 -104
- package/dist/drizzle/password-prepared-state.mjs.map +0 -1
- package/dist/drizzle/password-prepared-target.d.mts +0 -13
- package/dist/drizzle/password-prepared-target.mjs +0 -62
- package/dist/drizzle/password-prepared-target.mjs.map +0 -1
- package/dist/drizzle/password-registration.d.mts +0 -7
- package/dist/drizzle/password-registration.mjs +0 -137
- package/dist/drizzle/password-registration.mjs.map +0 -1
- package/dist/drizzle/password-sql.d.mts +0 -1
- package/dist/drizzle/password-sql.mjs +0 -10
- package/dist/drizzle/password-sql.mjs.map +0 -1
- package/dist/drizzle/pg-emails.d.mts +0 -72
- package/dist/drizzle/pg-emails.mjs +0 -43
- package/dist/drizzle/pg-emails.mjs.map +0 -1
- package/dist/drizzle/pg-password-prepared.d.mts +0 -31
- package/dist/drizzle/pg-password-prepared.mjs +0 -21
- package/dist/drizzle/pg-password-prepared.mjs.map +0 -1
- package/dist/drizzle/pg-passwords.d.mts +0 -72
- package/dist/drizzle/pg-passwords.mjs +0 -43
- package/dist/drizzle/pg-passwords.mjs.map +0 -1
- package/dist/drizzle/pg-proofs.d.mts +0 -76
- package/dist/drizzle/pg-proofs.mjs +0 -27
- package/dist/drizzle/pg-proofs.mjs.map +0 -1
- package/dist/drizzle/pg-sessions.d.mts +0 -93
- package/dist/drizzle/pg-sessions.mjs +0 -58
- package/dist/drizzle/pg-sessions.mjs.map +0 -1
- package/dist/drizzle/phone-state.mjs +0 -14
- package/dist/drizzle/phone-state.mjs.map +0 -1
- package/dist/drizzle/phone-target.d.mts +0 -15
- package/dist/drizzle/proof-sql.d.mts +0 -1
- package/dist/drizzle/proof-sql.mjs +0 -8
- package/dist/drizzle/proof-sql.mjs.map +0 -1
- package/dist/drizzle/query-operations.mjs +0 -31
- package/dist/drizzle/query-operations.mjs.map +0 -1
- package/dist/drizzle/session-sql.d.mts +0 -1
- package/dist/drizzle/session-sql.mjs +0 -9
- package/dist/drizzle/session-sql.mjs.map +0 -1
- package/dist/drizzle/session-target.d.mts +0 -30
- package/dist/drizzle/session-target.mjs +0 -49
- package/dist/drizzle/session-target.mjs.map +0 -1
- package/dist/drizzle/sqlite-emails.mjs +0 -50
- package/dist/drizzle/sqlite-emails.mjs.map +0 -1
- package/dist/drizzle/sqlite-password-prepared.mjs +0 -26
- package/dist/drizzle/sqlite-password-prepared.mjs.map +0 -1
- package/dist/drizzle/sqlite-passwords.mjs +0 -54
- package/dist/drizzle/sqlite-passwords.mjs.map +0 -1
- package/dist/drizzle/sqlite-proofs.mjs +0 -34
- package/dist/drizzle/sqlite-proofs.mjs.map +0 -1
- package/dist/drizzle/sqlite-sessions.mjs +0 -79
- package/dist/drizzle/sqlite-sessions.mjs.map +0 -1
- package/dist/drizzle/standalone-guard.d.mts +0 -2
- package/dist/drizzle/standalone-guard.mjs +0 -21
- package/dist/drizzle/standalone-guard.mjs.map +0 -1
- package/dist/drizzle/totp-state.d.mts +0 -37
- package/dist/drizzle/totp-state.mjs +0 -287
- package/dist/drizzle/totp-state.mjs.map +0 -1
- package/dist/drizzle/totp-target.d.mts +0 -15
- package/dist/drizzle/transaction-execution.d.mts +0 -2
- package/dist/drizzle/transaction-execution.mjs +0 -11
- package/dist/drizzle/transaction-execution.mjs.map +0 -1
- package/dist/drizzle/transaction-owner.d.mts +0 -1
- package/dist/drizzle/transaction-owner.mjs +0 -8
- package/dist/drizzle/transaction-owner.mjs.map +0 -1
- package/src/drizzle/crypto.ts +0 -14
- package/src/drizzle/d1-emails.ts +0 -1945
- package/src/drizzle/d1-generated-statement.ts +0 -129
- package/src/drizzle/d1-oauth.ts +0 -360
- package/src/drizzle/d1-passkey.ts +0 -383
- package/src/drizzle/d1-password-prepared.ts +0 -1265
- package/src/drizzle/d1-passwords.ts +0 -2060
- package/src/drizzle/d1-phone.ts +0 -103
- package/src/drizzle/d1-planning.ts +0 -104
- package/src/drizzle/d1-proofs.ts +0 -2354
- package/src/drizzle/d1-sessions.ts +0 -2940
- package/src/drizzle/d1-totp.ts +0 -88
- package/src/drizzle/email-registration.ts +0 -850
- package/src/drizzle/email-sql.ts +0 -25
- package/src/drizzle/mysql-emails.ts +0 -343
- package/src/drizzle/mysql-password-prepared.ts +0 -198
- package/src/drizzle/mysql-passwords.ts +0 -343
- package/src/drizzle/mysql-proofs.ts +0 -196
- package/src/drizzle/mysql-sessions.ts +0 -780
- package/src/drizzle/oauth-connected-target.ts +0 -21
- package/src/drizzle/oauth-kernel.ts +0 -10
- package/src/drizzle/oauth-mysql.ts +0 -10
- package/src/drizzle/passkey-kernel.ts +0 -4
- package/src/drizzle/passkey-state.ts +0 -3
- package/src/drizzle/passkey-target.ts +0 -23
- package/src/drizzle/passkey-write-target.ts +0 -9
- package/src/drizzle/password-prepared-model.ts +0 -241
- package/src/drizzle/password-prepared-sql.ts +0 -1201
- package/src/drizzle/password-prepared-state.ts +0 -231
- package/src/drizzle/password-prepared-target.ts +0 -169
- package/src/drizzle/password-registration.ts +0 -369
- package/src/drizzle/password-sql.ts +0 -16
- package/src/drizzle/pg-emails.ts +0 -343
- package/src/drizzle/pg-password-prepared.ts +0 -199
- package/src/drizzle/pg-passwords.ts +0 -342
- package/src/drizzle/pg-proofs.ts +0 -206
- package/src/drizzle/pg-sessions.ts +0 -789
- package/src/drizzle/phone-state.ts +0 -21
- package/src/drizzle/proof-sql.ts +0 -10
- package/src/drizzle/query-operations.ts +0 -49
- package/src/drizzle/session-sql.ts +0 -15
- package/src/drizzle/session-target.ts +0 -337
- package/src/drizzle/sqlite-emails.ts +0 -393
- package/src/drizzle/sqlite-password-prepared.ts +0 -230
- package/src/drizzle/sqlite-passwords.ts +0 -497
- package/src/drizzle/sqlite-proofs.ts +0 -229
- package/src/drizzle/sqlite-sessions.ts +0 -1013
- package/src/drizzle/totp-state.ts +0 -525
- package/src/drizzle/transaction-execution.ts +0 -13
- package/src/drizzle/transaction-owner.ts +0 -11
|
@@ -1,850 +0,0 @@
|
|
|
1
|
-
import type { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
2
|
-
import {
|
|
3
|
-
type PrepareEmailCommit,
|
|
4
|
-
type EmailCommandId,
|
|
5
|
-
type EmailRegistrationDecision,
|
|
6
|
-
EmailUnavailable,
|
|
7
|
-
} from "@yielded/auth/Email";
|
|
8
|
-
import {
|
|
9
|
-
coordinateCommit,
|
|
10
|
-
CurrentCommitJournal,
|
|
11
|
-
hasCommitScope,
|
|
12
|
-
type PreparedCommit,
|
|
13
|
-
LifecycleHooks,
|
|
14
|
-
HookConfigurationError,
|
|
15
|
-
} from "@yielded/auth/Hooks";
|
|
16
|
-
import type { LoginIdentifier } from "@yielded/auth/Identity";
|
|
17
|
-
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
18
|
-
import { type ProofCompletionPlan, ProofUnavailable } from "@yielded/auth/Proofs";
|
|
19
|
-
import type { TokenDigest } from "@yielded/auth/Schema";
|
|
20
|
-
import { SecurityRevision } from "@yielded/auth/Sessions";
|
|
21
|
-
/* oxlint-disable no-explicit-any -- registration plans bridge consumer-owned Drizzle rows. */
|
|
22
|
-
import { and, eq, isNull } from "drizzle-orm";
|
|
23
|
-
import { Cause, DateTime, Effect, Schema } from "effect";
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
type AnyEmailRegistrationMapping,
|
|
27
|
-
requiredEmailRegistrationConstraints,
|
|
28
|
-
} from "./email-model";
|
|
29
|
-
import { CurrentEmailSql, type EmailSqlDatabase, type EmailSqlQuery } from "./email-sql";
|
|
30
|
-
import { column, isMappedConstraintConflict, PersistenceMappingError, updateValues } from "./model";
|
|
31
|
-
import {
|
|
32
|
-
CurrentProofSql,
|
|
33
|
-
completeProofPlanIn,
|
|
34
|
-
type ProofSqlConfiguration,
|
|
35
|
-
type ProofSqlDatabase,
|
|
36
|
-
} from "./proof-sql";
|
|
37
|
-
import { validateDrizzleStorage } from "./storage-validation";
|
|
38
|
-
|
|
39
|
-
type Mapping<Registration> = AnyEmailRegistrationMapping<Registration>;
|
|
40
|
-
const unavailable = () => EmailUnavailable.make({});
|
|
41
|
-
|
|
42
|
-
const translateFailure = <A, E, R>(
|
|
43
|
-
effect: Effect.Effect<A, E, R>,
|
|
44
|
-
): Effect.Effect<A, EmailUnavailable, R> =>
|
|
45
|
-
reportPersistenceFailure(
|
|
46
|
-
effect,
|
|
47
|
-
(error) =>
|
|
48
|
-
Schema.is(EmailUnavailable)(error) ||
|
|
49
|
-
Schema.is(ProofUnavailable)(error) ||
|
|
50
|
-
Schema.is(HookConfigurationError)(error),
|
|
51
|
-
).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
52
|
-
|
|
53
|
-
const nowMillis = Effect.map(DateTime.now, DateTime.toEpochMillis);
|
|
54
|
-
|
|
55
|
-
export interface EmailRegistrationAuthority<Registration> {
|
|
56
|
-
readonly inspect: (input: {
|
|
57
|
-
readonly identifier: LoginIdentifier;
|
|
58
|
-
readonly registration: Registration;
|
|
59
|
-
}) => Effect.Effect<
|
|
60
|
-
{ readonly fingerprint: TokenDigest; readonly eligible: boolean },
|
|
61
|
-
EmailUnavailable
|
|
62
|
-
>;
|
|
63
|
-
readonly registerWithProof: <A>(
|
|
64
|
-
input: {
|
|
65
|
-
readonly moduleId: string;
|
|
66
|
-
readonly commandId: EmailCommandId;
|
|
67
|
-
readonly identifier: LoginIdentifier;
|
|
68
|
-
readonly registration: Registration;
|
|
69
|
-
readonly fingerprint: TokenDigest;
|
|
70
|
-
readonly completion: ProofCompletionPlan;
|
|
71
|
-
},
|
|
72
|
-
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
73
|
-
) => Effect.Effect<PreparedCommit<A>, EmailUnavailable>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface EmailRegistrationConfiguration {
|
|
77
|
-
readonly mode: "interactive" | "synchronous";
|
|
78
|
-
readonly locking: boolean;
|
|
79
|
-
readonly standaloneGuard: Effect.Effect<void, EmailUnavailable>;
|
|
80
|
-
readonly coordinated?: boolean;
|
|
81
|
-
readonly generatedSubjectRows: (query: EmailSqlQuery) => EmailSqlQuery;
|
|
82
|
-
readonly proof: {
|
|
83
|
-
readonly mapping: any;
|
|
84
|
-
readonly configuration: ProofSqlConfiguration;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const selectRows = (query: EmailSqlQuery, locking: boolean) =>
|
|
89
|
-
locking && typeof query.for === "function" ? query.for("update") : query;
|
|
90
|
-
|
|
91
|
-
const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>
|
|
92
|
-
left.namespace === right.namespace && left.value === right.value;
|
|
93
|
-
|
|
94
|
-
const validConstraints = <Registration>(mapping: Mapping<Registration>) => {
|
|
95
|
-
if (
|
|
96
|
-
mapping.constraints.request !== requiredEmailRegistrationConstraints.request ||
|
|
97
|
-
mapping.constraints.pendingReference !== requiredEmailRegistrationConstraints.pendingReference
|
|
98
|
-
)
|
|
99
|
-
return false;
|
|
100
|
-
if (mapping.mode === "pending") return true;
|
|
101
|
-
|
|
102
|
-
return Object.entries(requiredEmailRegistrationConstraints).every(
|
|
103
|
-
([key, value]) =>
|
|
104
|
-
mapping.constraints[key as keyof typeof requiredEmailRegistrationConstraints] === value,
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const allocate = <A>(
|
|
109
|
-
mode: EmailRegistrationConfiguration["mode"],
|
|
110
|
-
asynchronous: Effect.Effect<A, PersistenceMappingError> | undefined,
|
|
111
|
-
synchronous: (() => A) | undefined,
|
|
112
|
-
) => {
|
|
113
|
-
if (mode === "synchronous")
|
|
114
|
-
return synchronous === undefined
|
|
115
|
-
? Effect.fail(unavailable())
|
|
116
|
-
: Effect.try({
|
|
117
|
-
try: synchronous,
|
|
118
|
-
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
119
|
-
});
|
|
120
|
-
if (asynchronous !== undefined) return asynchronous;
|
|
121
|
-
|
|
122
|
-
return synchronous === undefined
|
|
123
|
-
? Effect.fail(unavailable())
|
|
124
|
-
: Effect.try({
|
|
125
|
-
try: synchronous,
|
|
126
|
-
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const registrationRows = Effect.fn("Drizzle.registrationRows")(function* <Registration>(
|
|
131
|
-
mapping: Mapping<Registration>,
|
|
132
|
-
moduleId: string,
|
|
133
|
-
commandId: string,
|
|
134
|
-
locking: boolean,
|
|
135
|
-
) {
|
|
136
|
-
const database = yield* CurrentEmailSql;
|
|
137
|
-
|
|
138
|
-
const module = column(mapping.registration.table, mapping.registration.moduleId);
|
|
139
|
-
const command = column(mapping.registration.table, mapping.registration.commandId);
|
|
140
|
-
|
|
141
|
-
return yield* selectRows(
|
|
142
|
-
database
|
|
143
|
-
.select()
|
|
144
|
-
.from(mapping.registration.table)
|
|
145
|
-
.where(and(eq(module, moduleId), eq(command, commandId)))
|
|
146
|
-
.limit(1),
|
|
147
|
-
locking,
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
/** Discover before locking, then lock subject before identifier like the other
|
|
152
|
-
* identity owners. A changed discovery is rejected rather than locking a second
|
|
153
|
-
* subject in the opposite order. Proof authority separately enforces the host's
|
|
154
|
-
* active/unverified eligibility policy in the same physical owner. */
|
|
155
|
-
export const readEmailRegistrationTarget = Effect.fnUntraced(function* <Registration>(
|
|
156
|
-
mapping: Extract<Mapping<Registration>, { readonly mode: "atomic" }>,
|
|
157
|
-
identifier: LoginIdentifier,
|
|
158
|
-
locking: boolean,
|
|
159
|
-
) {
|
|
160
|
-
const database = yield* CurrentEmailSql;
|
|
161
|
-
const i = mapping.identifier;
|
|
162
|
-
const s = mapping.subject;
|
|
163
|
-
|
|
164
|
-
const lookup = () =>
|
|
165
|
-
database
|
|
166
|
-
.select()
|
|
167
|
-
.from(i.table)
|
|
168
|
-
.where(
|
|
169
|
-
and(
|
|
170
|
-
eq(column(i.table, i.namespace), identifier.namespace),
|
|
171
|
-
eq(column(i.table, i.value), identifier.value),
|
|
172
|
-
),
|
|
173
|
-
)
|
|
174
|
-
.limit(1);
|
|
175
|
-
|
|
176
|
-
const discovered = (yield* lookup())[0];
|
|
177
|
-
|
|
178
|
-
if (discovered === undefined) return { _tag: "Absent" } as const;
|
|
179
|
-
if (discovered[i.verifiedAt] !== null) return { _tag: "Rejected" } as const;
|
|
180
|
-
const nativeSubjectId = discovered[i.subjectId];
|
|
181
|
-
|
|
182
|
-
const subject = (yield* selectRows(
|
|
183
|
-
database
|
|
184
|
-
.select()
|
|
185
|
-
.from(s.table)
|
|
186
|
-
.where(eq(column(s.table, s.id), nativeSubjectId))
|
|
187
|
-
.limit(1),
|
|
188
|
-
locking,
|
|
189
|
-
))[0];
|
|
190
|
-
|
|
191
|
-
const current = (yield* selectRows(lookup(), locking))[0];
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
subject === undefined ||
|
|
195
|
-
current === undefined ||
|
|
196
|
-
current[i.verifiedAt] !== null ||
|
|
197
|
-
!mapping.subjectId.equals(current[i.subjectId], nativeSubjectId) ||
|
|
198
|
-
current[i.bindingRevision] !== discovered[i.bindingRevision]
|
|
199
|
-
)
|
|
200
|
-
return { _tag: "Rejected" } as const;
|
|
201
|
-
|
|
202
|
-
return {
|
|
203
|
-
_tag: "Reserved" as const,
|
|
204
|
-
nativeSubjectId,
|
|
205
|
-
bindingRevision: yield* Schema.decodeUnknownEffect(SecurityRevision)(
|
|
206
|
-
current[i.bindingRevision],
|
|
207
|
-
),
|
|
208
|
-
securityRevision: yield* Schema.decodeUnknownEffect(SecurityRevision)(
|
|
209
|
-
subject[s.securityRevision],
|
|
210
|
-
),
|
|
211
|
-
};
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const owned = <A, E, R>(
|
|
215
|
-
database: EmailSqlDatabase,
|
|
216
|
-
configuration: EmailRegistrationConfiguration,
|
|
217
|
-
body: Effect.Effect<A, E, R>,
|
|
218
|
-
) => {
|
|
219
|
-
const run = coordinateCommit(
|
|
220
|
-
() =>
|
|
221
|
-
database.transaction((transaction) =>
|
|
222
|
-
body.pipe(
|
|
223
|
-
Effect.provideService(CurrentEmailSql, transaction),
|
|
224
|
-
Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),
|
|
225
|
-
),
|
|
226
|
-
),
|
|
227
|
-
{ mode: configuration.mode },
|
|
228
|
-
).pipe(Effect.map((result) => result.value));
|
|
229
|
-
|
|
230
|
-
return configuration.coordinated !== true
|
|
231
|
-
? Effect.gen(function* () {
|
|
232
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
233
|
-
yield* configuration.standaloneGuard;
|
|
234
|
-
|
|
235
|
-
return yield* run;
|
|
236
|
-
})
|
|
237
|
-
: run;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
const completionMatches = <Registration>(
|
|
241
|
-
mapping: Mapping<Registration>,
|
|
242
|
-
input: {
|
|
243
|
-
readonly moduleId: string;
|
|
244
|
-
readonly identifier: LoginIdentifier;
|
|
245
|
-
readonly completion: ProofCompletionPlan;
|
|
246
|
-
},
|
|
247
|
-
) => {
|
|
248
|
-
const completion = input.completion.input;
|
|
249
|
-
|
|
250
|
-
return (
|
|
251
|
-
completion.moduleId === `${input.moduleId}/registration` &&
|
|
252
|
-
completion.purpose === "email-code-registration" &&
|
|
253
|
-
completion.binding._tag === "Identifier" &&
|
|
254
|
-
sameIdentifier(completion.binding.identifier, input.identifier) &&
|
|
255
|
-
validConstraints(mapping)
|
|
256
|
-
);
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const prepareReplay = Effect.fn("DrizzleEmailRegistration.prepareReplay")(function* <
|
|
260
|
-
Registration,
|
|
261
|
-
A,
|
|
262
|
-
>(
|
|
263
|
-
mapping: Mapping<Registration>,
|
|
264
|
-
row: any,
|
|
265
|
-
fingerprint: TokenDigest,
|
|
266
|
-
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
267
|
-
) {
|
|
268
|
-
const journal = yield* CurrentCommitJournal;
|
|
269
|
-
|
|
270
|
-
if (row[mapping.registration.fingerprint] !== fingerprint)
|
|
271
|
-
return prepare({ _tag: "Rejected" }, journal);
|
|
272
|
-
|
|
273
|
-
return prepare(yield* mapping.registration.decodeReplay(row), journal);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
const registerIn = Effect.fn("DrizzleEmailRegistration.registerIn")(function* <Registration, A>(
|
|
277
|
-
mapping: Mapping<Registration>,
|
|
278
|
-
configuration: EmailRegistrationConfiguration,
|
|
279
|
-
input: {
|
|
280
|
-
readonly moduleId: string;
|
|
281
|
-
readonly commandId: string;
|
|
282
|
-
readonly identifier: LoginIdentifier;
|
|
283
|
-
readonly registration: Registration;
|
|
284
|
-
readonly fingerprint: TokenDigest;
|
|
285
|
-
readonly completion: ProofCompletionPlan;
|
|
286
|
-
},
|
|
287
|
-
inspected: { readonly fingerprint: TokenDigest; readonly eligible: boolean },
|
|
288
|
-
allocated: {
|
|
289
|
-
readonly credentialId?: string;
|
|
290
|
-
readonly securityRevision?: SecurityRevision;
|
|
291
|
-
readonly displacedSecurityRevision?: SecurityRevision;
|
|
292
|
-
readonly identifierRevision?: SecurityRevision;
|
|
293
|
-
readonly credentialRevision?: SecurityRevision;
|
|
294
|
-
readonly nativeSubjectId?: unknown;
|
|
295
|
-
readonly pendingReference?: string;
|
|
296
|
-
},
|
|
297
|
-
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
298
|
-
) {
|
|
299
|
-
const journal = yield* CurrentCommitJournal;
|
|
300
|
-
|
|
301
|
-
const existing = (yield* registrationRows(
|
|
302
|
-
mapping,
|
|
303
|
-
input.moduleId,
|
|
304
|
-
input.commandId,
|
|
305
|
-
configuration.locking,
|
|
306
|
-
))[0];
|
|
307
|
-
|
|
308
|
-
if (existing !== undefined)
|
|
309
|
-
return yield* prepareReplay(mapping, existing, input.fingerprint, prepare);
|
|
310
|
-
if (!completionMatches(mapping, input)) return prepare({ _tag: "Rejected" }, journal);
|
|
311
|
-
if (!inspected.eligible || inspected.fingerprint !== input.fingerprint)
|
|
312
|
-
return prepare({ _tag: "Rejected" }, journal);
|
|
313
|
-
|
|
314
|
-
const target =
|
|
315
|
-
mapping.mode === "atomic"
|
|
316
|
-
? yield* readEmailRegistrationTarget(mapping, input.identifier, configuration.locking)
|
|
317
|
-
: undefined;
|
|
318
|
-
|
|
319
|
-
if (target?._tag === "Rejected") return prepare({ _tag: "Rejected" }, journal);
|
|
320
|
-
if (
|
|
321
|
-
target?._tag === "Reserved" &&
|
|
322
|
-
(allocated.displacedSecurityRevision === undefined ||
|
|
323
|
-
allocated.displacedSecurityRevision === target.securityRevision ||
|
|
324
|
-
allocated.identifierRevision === target.bindingRevision)
|
|
325
|
-
)
|
|
326
|
-
return yield* unavailable();
|
|
327
|
-
const now = yield* nowMillis;
|
|
328
|
-
|
|
329
|
-
const intent = {
|
|
330
|
-
moduleId: input.moduleId,
|
|
331
|
-
commandId: input.commandId,
|
|
332
|
-
identifier: Object.freeze({ ...input.identifier }),
|
|
333
|
-
registration: input.registration,
|
|
334
|
-
fingerprint: input.fingerprint,
|
|
335
|
-
completion: Object.freeze({
|
|
336
|
-
moduleId: input.completion.input.moduleId,
|
|
337
|
-
purpose: input.completion.input.purpose,
|
|
338
|
-
continuationId: input.completion.input.continuationId,
|
|
339
|
-
binding: input.completion.input.binding,
|
|
340
|
-
}),
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
let decision: EmailRegistrationDecision | undefined;
|
|
344
|
-
let nativeSubjectId = allocated.nativeSubjectId;
|
|
345
|
-
|
|
346
|
-
const protectedMutation = Effect.gen(function* () {
|
|
347
|
-
const transaction = yield* CurrentEmailSql;
|
|
348
|
-
|
|
349
|
-
if (mapping.mode === "pending") {
|
|
350
|
-
if (allocated.pendingReference === undefined) return false;
|
|
351
|
-
decision = { _tag: "ProvisioningPending", reference: allocated.pendingReference };
|
|
352
|
-
yield* transaction.insert(mapping.registration.table).values(
|
|
353
|
-
mapping.registration.encodeInsert(intent, {
|
|
354
|
-
state: "pending",
|
|
355
|
-
pendingReference: allocated.pendingReference,
|
|
356
|
-
retentionUntilMillis: now + mapping.retentionMillis,
|
|
357
|
-
}),
|
|
358
|
-
);
|
|
359
|
-
} else {
|
|
360
|
-
if (
|
|
361
|
-
allocated.credentialId === undefined ||
|
|
362
|
-
allocated.securityRevision === undefined ||
|
|
363
|
-
allocated.identifierRevision === undefined ||
|
|
364
|
-
allocated.credentialRevision === undefined
|
|
365
|
-
)
|
|
366
|
-
return false;
|
|
367
|
-
|
|
368
|
-
const subjectInsert = transaction.insert(mapping.subject.table).values(
|
|
369
|
-
mapping.provisioning.encodeSubjectInsert(intent, {
|
|
370
|
-
nativeSubjectId,
|
|
371
|
-
securityRevision: allocated.securityRevision,
|
|
372
|
-
}),
|
|
373
|
-
);
|
|
374
|
-
|
|
375
|
-
if (mapping.provisioning.idMode === "generated") {
|
|
376
|
-
const rows = yield* configuration.generatedSubjectRows(subjectInsert);
|
|
377
|
-
|
|
378
|
-
nativeSubjectId = yield* mapping.provisioning.decodeGeneratedId(rows);
|
|
379
|
-
} else yield* subjectInsert;
|
|
380
|
-
if (nativeSubjectId === undefined) return false;
|
|
381
|
-
if (target?._tag === "Reserved") {
|
|
382
|
-
const i = mapping.identifier;
|
|
383
|
-
const s = mapping.subject;
|
|
384
|
-
|
|
385
|
-
// Change only mapped ownership columns. Never delete a consumer-owned
|
|
386
|
-
// identifier row or copy insertion defaults over unrelated columns.
|
|
387
|
-
yield* transaction
|
|
388
|
-
.update(i.table)
|
|
389
|
-
.set(
|
|
390
|
-
updateValues([
|
|
391
|
-
[i.subjectId, nativeSubjectId],
|
|
392
|
-
[i.verifiedAt, mapping.encodeInstant(now)],
|
|
393
|
-
[i.bindingRevision, allocated.identifierRevision],
|
|
394
|
-
]),
|
|
395
|
-
)
|
|
396
|
-
.where(
|
|
397
|
-
and(
|
|
398
|
-
eq(column(i.table, i.namespace), input.identifier.namespace),
|
|
399
|
-
eq(column(i.table, i.value), input.identifier.value),
|
|
400
|
-
eq(column(i.table, i.subjectId), target.nativeSubjectId),
|
|
401
|
-
eq(column(i.table, i.bindingRevision), target.bindingRevision),
|
|
402
|
-
isNull(column(i.table, i.verifiedAt)),
|
|
403
|
-
),
|
|
404
|
-
);
|
|
405
|
-
yield* transaction
|
|
406
|
-
.update(s.table)
|
|
407
|
-
.set(updateValues([[s.securityRevision, allocated.displacedSecurityRevision]]))
|
|
408
|
-
.where(
|
|
409
|
-
and(
|
|
410
|
-
eq(column(s.table, s.id), target.nativeSubjectId),
|
|
411
|
-
eq(column(s.table, s.securityRevision), target.securityRevision),
|
|
412
|
-
),
|
|
413
|
-
);
|
|
414
|
-
} else {
|
|
415
|
-
yield* transaction.insert(mapping.identifier.table).values(
|
|
416
|
-
mapping.identifier.encodeVerifiedInsert({
|
|
417
|
-
identifier: input.identifier,
|
|
418
|
-
subjectId: nativeSubjectId,
|
|
419
|
-
verifiedAtMillis: now,
|
|
420
|
-
bindingRevision: allocated.identifierRevision,
|
|
421
|
-
}),
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
yield* transaction.insert(mapping.credential.table).values(
|
|
425
|
-
mapping.credential.encodeVerifiedInsert({
|
|
426
|
-
moduleId: input.moduleId,
|
|
427
|
-
subjectId: nativeSubjectId,
|
|
428
|
-
credentialId: allocated.credentialId,
|
|
429
|
-
identifier: input.identifier,
|
|
430
|
-
credentialRevision: allocated.credentialRevision,
|
|
431
|
-
}),
|
|
432
|
-
);
|
|
433
|
-
yield* transaction.insert(mapping.authorityCredential.table).values(
|
|
434
|
-
mapping.authorityCredential.encodeInsert({
|
|
435
|
-
subjectId: nativeSubjectId,
|
|
436
|
-
credentialId: allocated.credentialId,
|
|
437
|
-
revision: allocated.credentialRevision,
|
|
438
|
-
}),
|
|
439
|
-
);
|
|
440
|
-
yield* transaction.insert(mapping.registration.table).values(
|
|
441
|
-
mapping.registration.encodeInsert(intent, {
|
|
442
|
-
state: "registered",
|
|
443
|
-
nativeSubjectId,
|
|
444
|
-
retentionUntilMillis: now + mapping.retentionMillis,
|
|
445
|
-
}),
|
|
446
|
-
);
|
|
447
|
-
decision = { _tag: "Registered" };
|
|
448
|
-
}
|
|
449
|
-
const stored = (yield* registrationRows(mapping, input.moduleId, input.commandId, false))[0];
|
|
450
|
-
const registrationModule = column(mapping.registration.table, mapping.registration.moduleId);
|
|
451
|
-
const registrationCommand = column(mapping.registration.table, mapping.registration.commandId);
|
|
452
|
-
|
|
453
|
-
const registrationFingerprint = column(
|
|
454
|
-
mapping.registration.table,
|
|
455
|
-
mapping.registration.fingerprint,
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
const registrationState = column(mapping.registration.table, mapping.registration.state);
|
|
459
|
-
const registrationSubject = column(mapping.registration.table, mapping.registration.subjectId);
|
|
460
|
-
|
|
461
|
-
const registrationReference = column(
|
|
462
|
-
mapping.registration.table,
|
|
463
|
-
mapping.registration.pendingReference,
|
|
464
|
-
);
|
|
465
|
-
|
|
466
|
-
const registrationRetention = column(
|
|
467
|
-
mapping.registration.table,
|
|
468
|
-
mapping.registration.retentionUntil,
|
|
469
|
-
);
|
|
470
|
-
|
|
471
|
-
const exactRegistration = yield* selectRows(
|
|
472
|
-
transaction
|
|
473
|
-
.select()
|
|
474
|
-
.from(mapping.registration.table)
|
|
475
|
-
.where(
|
|
476
|
-
and(
|
|
477
|
-
eq(registrationModule, input.moduleId),
|
|
478
|
-
eq(registrationCommand, input.commandId),
|
|
479
|
-
eq(registrationFingerprint, input.fingerprint),
|
|
480
|
-
eq(registrationState, mapping.mode === "pending" ? "pending" : "registered"),
|
|
481
|
-
eq(registrationRetention, mapping.encodeInstant(now + mapping.retentionMillis)),
|
|
482
|
-
mapping.mode === "pending"
|
|
483
|
-
? and(
|
|
484
|
-
eq(registrationReference, allocated.pendingReference!),
|
|
485
|
-
isNull(registrationSubject),
|
|
486
|
-
)
|
|
487
|
-
: and(eq(registrationSubject, nativeSubjectId), isNull(registrationReference)),
|
|
488
|
-
),
|
|
489
|
-
)
|
|
490
|
-
.limit(1),
|
|
491
|
-
false,
|
|
492
|
-
);
|
|
493
|
-
|
|
494
|
-
if (mapping.mode === "atomic" && nativeSubjectId !== undefined) {
|
|
495
|
-
const subjectId = column(mapping.subject.table, mapping.subject.id);
|
|
496
|
-
const identifierNamespace = column(mapping.identifier.table, mapping.identifier.namespace);
|
|
497
|
-
const identifierValue = column(mapping.identifier.table, mapping.identifier.value);
|
|
498
|
-
const identifierSubject = column(mapping.identifier.table, mapping.identifier.subjectId);
|
|
499
|
-
const identifierVerifiedAt = column(mapping.identifier.table, mapping.identifier.verifiedAt);
|
|
500
|
-
const credentialModule = column(mapping.credential.table, mapping.credential.moduleId);
|
|
501
|
-
const credentialId = column(mapping.credential.table, mapping.credential.credentialId);
|
|
502
|
-
const credentialSubject = column(mapping.credential.table, mapping.credential.subjectId);
|
|
503
|
-
|
|
504
|
-
const credentialNamespace = column(
|
|
505
|
-
mapping.credential.table,
|
|
506
|
-
mapping.credential.identifierNamespace,
|
|
507
|
-
);
|
|
508
|
-
|
|
509
|
-
const credentialValue = column(mapping.credential.table, mapping.credential.identifierValue);
|
|
510
|
-
|
|
511
|
-
const authoritySubject = column(
|
|
512
|
-
mapping.authorityCredential.table,
|
|
513
|
-
mapping.authorityCredential.subjectId,
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
const authorityId = column(
|
|
517
|
-
mapping.authorityCredential.table,
|
|
518
|
-
mapping.authorityCredential.credentialId,
|
|
519
|
-
);
|
|
520
|
-
|
|
521
|
-
const subject = (yield* selectRows(
|
|
522
|
-
transaction
|
|
523
|
-
.select()
|
|
524
|
-
.from(mapping.subject.table)
|
|
525
|
-
.where(eq(subjectId, nativeSubjectId))
|
|
526
|
-
.limit(1),
|
|
527
|
-
false,
|
|
528
|
-
))[0];
|
|
529
|
-
|
|
530
|
-
const identifier = (yield* selectRows(
|
|
531
|
-
transaction
|
|
532
|
-
.select()
|
|
533
|
-
.from(mapping.identifier.table)
|
|
534
|
-
.where(
|
|
535
|
-
and(
|
|
536
|
-
eq(identifierNamespace, input.identifier.namespace),
|
|
537
|
-
eq(identifierValue, input.identifier.value),
|
|
538
|
-
eq(identifierSubject, nativeSubjectId),
|
|
539
|
-
eq(identifierVerifiedAt, mapping.encodeInstant(now)),
|
|
540
|
-
),
|
|
541
|
-
)
|
|
542
|
-
.limit(1),
|
|
543
|
-
false,
|
|
544
|
-
))[0];
|
|
545
|
-
|
|
546
|
-
const credential = (yield* selectRows(
|
|
547
|
-
transaction
|
|
548
|
-
.select()
|
|
549
|
-
.from(mapping.credential.table)
|
|
550
|
-
.where(
|
|
551
|
-
and(
|
|
552
|
-
eq(credentialModule, input.moduleId),
|
|
553
|
-
eq(credentialId, allocated.credentialId!),
|
|
554
|
-
eq(credentialSubject, nativeSubjectId),
|
|
555
|
-
eq(credentialNamespace, input.identifier.namespace),
|
|
556
|
-
eq(credentialValue, input.identifier.value),
|
|
557
|
-
),
|
|
558
|
-
)
|
|
559
|
-
.limit(1),
|
|
560
|
-
false,
|
|
561
|
-
))[0];
|
|
562
|
-
|
|
563
|
-
const authority = (yield* selectRows(
|
|
564
|
-
transaction
|
|
565
|
-
.select()
|
|
566
|
-
.from(mapping.authorityCredential.table)
|
|
567
|
-
.where(
|
|
568
|
-
and(eq(authoritySubject, nativeSubjectId), eq(authorityId, allocated.credentialId!)),
|
|
569
|
-
)
|
|
570
|
-
.limit(1),
|
|
571
|
-
false,
|
|
572
|
-
))[0];
|
|
573
|
-
|
|
574
|
-
const displaced =
|
|
575
|
-
target?._tag === "Reserved"
|
|
576
|
-
? (yield* transaction
|
|
577
|
-
.select()
|
|
578
|
-
.from(mapping.subject.table)
|
|
579
|
-
.where(
|
|
580
|
-
and(
|
|
581
|
-
eq(subjectId, target.nativeSubjectId),
|
|
582
|
-
eq(
|
|
583
|
-
column(mapping.subject.table, mapping.subject.securityRevision),
|
|
584
|
-
allocated.displacedSecurityRevision,
|
|
585
|
-
),
|
|
586
|
-
),
|
|
587
|
-
)
|
|
588
|
-
.limit(1))[0]
|
|
589
|
-
: undefined;
|
|
590
|
-
|
|
591
|
-
if (
|
|
592
|
-
(target?._tag === "Reserved" && displaced === undefined) ||
|
|
593
|
-
subject === undefined ||
|
|
594
|
-
!mapping.subject.isActiveStatus(subject[mapping.subject.status]) ||
|
|
595
|
-
subject[mapping.subject.securityRevision] !== allocated.securityRevision ||
|
|
596
|
-
identifier === undefined ||
|
|
597
|
-
identifier[mapping.identifier.bindingRevision] !== allocated.identifierRevision ||
|
|
598
|
-
!mapping.identifier.isCurrent(identifier) ||
|
|
599
|
-
credential === undefined ||
|
|
600
|
-
credential[mapping.credential.credentialRevision] !== allocated.credentialRevision ||
|
|
601
|
-
!mapping.credential.isActiveStatus(credential[mapping.credential.status]) ||
|
|
602
|
-
authority === undefined ||
|
|
603
|
-
authority[mapping.authorityCredential.revision] !== allocated.credentialRevision ||
|
|
604
|
-
!mapping.authorityCredential.isActiveStatus(authority[mapping.authorityCredential.status])
|
|
605
|
-
)
|
|
606
|
-
return false;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
return (
|
|
610
|
-
stored !== undefined &&
|
|
611
|
-
exactRegistration.length === 1 &&
|
|
612
|
-
stored[mapping.registration.fingerprint] === input.fingerprint &&
|
|
613
|
-
(mapping.mode === "pending" ||
|
|
614
|
-
(nativeSubjectId !== undefined &&
|
|
615
|
-
stored[mapping.registration.subjectId] !== null &&
|
|
616
|
-
mapping.subjectId.equals(stored[mapping.registration.subjectId], nativeSubjectId)))
|
|
617
|
-
);
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
let receipt: PreparedCommit<A> | undefined;
|
|
621
|
-
|
|
622
|
-
yield* completeProofPlanIn(
|
|
623
|
-
configuration.proof.mapping,
|
|
624
|
-
configuration.proof.configuration,
|
|
625
|
-
input.completion,
|
|
626
|
-
protectedMutation,
|
|
627
|
-
(completionDecision) => {
|
|
628
|
-
receipt = prepare(
|
|
629
|
-
completionDecision === "completed" && decision !== undefined
|
|
630
|
-
? decision
|
|
631
|
-
: { _tag: "Rejected" },
|
|
632
|
-
journal,
|
|
633
|
-
);
|
|
634
|
-
|
|
635
|
-
return completionDecision;
|
|
636
|
-
},
|
|
637
|
-
);
|
|
638
|
-
|
|
639
|
-
return receipt ?? prepare({ _tag: "Rejected" }, journal);
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
const prepareConflict = Effect.fn("Drizzle.prepareConflict")(function* <Registration, A>(
|
|
643
|
-
mapping: Mapping<Registration>,
|
|
644
|
-
configuration: EmailRegistrationConfiguration,
|
|
645
|
-
input: {
|
|
646
|
-
readonly moduleId: string;
|
|
647
|
-
readonly commandId: string;
|
|
648
|
-
readonly fingerprint: TokenDigest;
|
|
649
|
-
},
|
|
650
|
-
prepare: PrepareEmailCommit<EmailRegistrationDecision, A>,
|
|
651
|
-
) {
|
|
652
|
-
const database = yield* CurrentEmailSql;
|
|
653
|
-
|
|
654
|
-
return yield* owned(
|
|
655
|
-
database,
|
|
656
|
-
configuration,
|
|
657
|
-
Effect.gen(function* () {
|
|
658
|
-
const journal = yield* CurrentCommitJournal;
|
|
659
|
-
|
|
660
|
-
const row = (yield* registrationRows(
|
|
661
|
-
mapping,
|
|
662
|
-
input.moduleId,
|
|
663
|
-
input.commandId,
|
|
664
|
-
configuration.locking,
|
|
665
|
-
))[0];
|
|
666
|
-
|
|
667
|
-
return row === undefined
|
|
668
|
-
? prepare({ _tag: "Rejected" }, journal)
|
|
669
|
-
: yield* prepareReplay(mapping, row, input.fingerprint, prepare);
|
|
670
|
-
}),
|
|
671
|
-
);
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
export const makeSqlEmailRegistrationAuthority = Effect.fn("makeSqlEmailRegistrationAuthority")(
|
|
675
|
-
function* <Registration>(
|
|
676
|
-
mapping: Mapping<Registration>,
|
|
677
|
-
configuration: EmailRegistrationConfiguration,
|
|
678
|
-
): Effect.fn.Return<
|
|
679
|
-
EmailRegistrationAuthority<Registration>,
|
|
680
|
-
EmailUnavailable,
|
|
681
|
-
LifecycleHooks | CurrentEmailSql | NativeDatabase
|
|
682
|
-
> {
|
|
683
|
-
const database = yield* CurrentEmailSql;
|
|
684
|
-
|
|
685
|
-
if (!configuration.coordinated)
|
|
686
|
-
yield* validateDrizzleStorage({
|
|
687
|
-
...mapping,
|
|
688
|
-
proof: configuration.proof.mapping,
|
|
689
|
-
}).pipe(Effect.mapError(unavailable));
|
|
690
|
-
const hooks = yield* LifecycleHooks;
|
|
691
|
-
|
|
692
|
-
return {
|
|
693
|
-
inspect: (input) =>
|
|
694
|
-
mapping
|
|
695
|
-
.inspect(input)
|
|
696
|
-
.pipe(
|
|
697
|
-
Effect.provideService(CurrentEmailSql, database),
|
|
698
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
699
|
-
translateFailure,
|
|
700
|
-
),
|
|
701
|
-
registerWithProof: (input, prepare) =>
|
|
702
|
-
Effect.gen(function* () {
|
|
703
|
-
if (!validConstraints(mapping)) return yield* unavailable();
|
|
704
|
-
|
|
705
|
-
const snapshot = (registration: Registration) =>
|
|
706
|
-
configuration.mode === "synchronous" && configuration.coordinated === true
|
|
707
|
-
? mapping.snapshotRegistrationSync === undefined
|
|
708
|
-
? Effect.fail(unavailable())
|
|
709
|
-
: Effect.try({
|
|
710
|
-
try: () => mapping.snapshotRegistrationSync!(registration),
|
|
711
|
-
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
712
|
-
})
|
|
713
|
-
: mapping.snapshotRegistration(registration);
|
|
714
|
-
|
|
715
|
-
const storedRegistration = yield* snapshot(input.registration);
|
|
716
|
-
const inspectionRegistration = yield* snapshot(input.registration);
|
|
717
|
-
|
|
718
|
-
const capturedInput = Object.freeze({
|
|
719
|
-
...input,
|
|
720
|
-
identifier: Object.freeze({ ...input.identifier }),
|
|
721
|
-
registration: storedRegistration,
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
// Registration decoding and fingerprinting may suspend (for example while
|
|
725
|
-
// hashing a detached Registration value). Finish that work before a
|
|
726
|
-
// synchronous Durable Object transaction owner is entered.
|
|
727
|
-
const inspectInput = {
|
|
728
|
-
identifier: capturedInput.identifier,
|
|
729
|
-
registration: inspectionRegistration,
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
const inspected =
|
|
733
|
-
configuration.mode === "synchronous" && configuration.coordinated === true
|
|
734
|
-
? mapping.inspectSync === undefined
|
|
735
|
-
? yield* unavailable()
|
|
736
|
-
: yield* Effect.try({
|
|
737
|
-
try: () => mapping.inspectSync!(inspectInput),
|
|
738
|
-
catch: (cause) => new PersistenceMappingError({ operation: "mapping", cause }),
|
|
739
|
-
})
|
|
740
|
-
: yield* mapping.inspect(inspectInput);
|
|
741
|
-
|
|
742
|
-
const atomic = mapping.mode === "atomic";
|
|
743
|
-
|
|
744
|
-
const credentialId = atomic
|
|
745
|
-
? yield* allocate(
|
|
746
|
-
configuration.mode,
|
|
747
|
-
mapping.allocateCredentialId,
|
|
748
|
-
mapping.allocateCredentialIdSync,
|
|
749
|
-
)
|
|
750
|
-
: undefined;
|
|
751
|
-
|
|
752
|
-
const securityRevision = atomic
|
|
753
|
-
? yield* allocate(
|
|
754
|
-
configuration.mode,
|
|
755
|
-
mapping.allocateRevision,
|
|
756
|
-
mapping.allocateRevisionSync,
|
|
757
|
-
)
|
|
758
|
-
: undefined;
|
|
759
|
-
|
|
760
|
-
const displacedSecurityRevision = atomic
|
|
761
|
-
? yield* allocate(
|
|
762
|
-
configuration.mode,
|
|
763
|
-
mapping.allocateRevision,
|
|
764
|
-
mapping.allocateRevisionSync,
|
|
765
|
-
)
|
|
766
|
-
: undefined;
|
|
767
|
-
|
|
768
|
-
const identifierRevision = atomic
|
|
769
|
-
? yield* allocate(
|
|
770
|
-
configuration.mode,
|
|
771
|
-
mapping.allocateRevision,
|
|
772
|
-
mapping.allocateRevisionSync,
|
|
773
|
-
)
|
|
774
|
-
: undefined;
|
|
775
|
-
|
|
776
|
-
const credentialRevision = atomic
|
|
777
|
-
? yield* allocate(
|
|
778
|
-
configuration.mode,
|
|
779
|
-
mapping.allocateRevision,
|
|
780
|
-
mapping.allocateRevisionSync,
|
|
781
|
-
)
|
|
782
|
-
: undefined;
|
|
783
|
-
|
|
784
|
-
const nativeSubjectId =
|
|
785
|
-
atomic && mapping.provisioning.idMode !== "generated"
|
|
786
|
-
? yield* allocate(
|
|
787
|
-
configuration.mode,
|
|
788
|
-
mapping.provisioning.allocateSubjectId,
|
|
789
|
-
mapping.provisioning.allocateSubjectIdSync,
|
|
790
|
-
)
|
|
791
|
-
: undefined;
|
|
792
|
-
|
|
793
|
-
const pendingReference =
|
|
794
|
-
mapping.mode === "pending"
|
|
795
|
-
? yield* allocate(
|
|
796
|
-
configuration.mode,
|
|
797
|
-
mapping.allocatePendingReference,
|
|
798
|
-
mapping.allocatePendingReferenceSync,
|
|
799
|
-
)
|
|
800
|
-
: undefined;
|
|
801
|
-
|
|
802
|
-
const run = owned(
|
|
803
|
-
database,
|
|
804
|
-
configuration,
|
|
805
|
-
Effect.gen(function* () {
|
|
806
|
-
return yield* registerIn(
|
|
807
|
-
mapping,
|
|
808
|
-
configuration,
|
|
809
|
-
capturedInput,
|
|
810
|
-
inspected,
|
|
811
|
-
{
|
|
812
|
-
...(credentialId === undefined ? {} : { credentialId }),
|
|
813
|
-
...(securityRevision === undefined ? {} : { securityRevision }),
|
|
814
|
-
...(displacedSecurityRevision === undefined ? {} : { displacedSecurityRevision }),
|
|
815
|
-
...(identifierRevision === undefined ? {} : { identifierRevision }),
|
|
816
|
-
...(credentialRevision === undefined ? {} : { credentialRevision }),
|
|
817
|
-
...(nativeSubjectId === undefined ? {} : { nativeSubjectId }),
|
|
818
|
-
...(pendingReference === undefined ? {} : { pendingReference }),
|
|
819
|
-
},
|
|
820
|
-
prepare,
|
|
821
|
-
);
|
|
822
|
-
}),
|
|
823
|
-
);
|
|
824
|
-
|
|
825
|
-
return yield* run.pipe(
|
|
826
|
-
Effect.catchCause((cause) => {
|
|
827
|
-
const request =
|
|
828
|
-
cause.reasons.every(Cause.isFailReason) &&
|
|
829
|
-
isMappedConstraintConflict(mapping.isRequestConflict, cause);
|
|
830
|
-
|
|
831
|
-
const conflict =
|
|
832
|
-
mapping.mode === "atomic" &&
|
|
833
|
-
((cause.reasons.every(Cause.isFailReason) &&
|
|
834
|
-
isMappedConstraintConflict(mapping.isIdentifierConflict, cause)) ||
|
|
835
|
-
(cause.reasons.every(Cause.isFailReason) &&
|
|
836
|
-
isMappedConstraintConflict(mapping.isCredentialConflict, cause)));
|
|
837
|
-
|
|
838
|
-
return request || conflict
|
|
839
|
-
? prepareConflict(mapping, configuration, capturedInput, prepare)
|
|
840
|
-
: Effect.failCause(cause);
|
|
841
|
-
}),
|
|
842
|
-
);
|
|
843
|
-
}).pipe(
|
|
844
|
-
Effect.provideService(CurrentEmailSql, database),
|
|
845
|
-
Effect.provideService(LifecycleHooks, hooks),
|
|
846
|
-
translateFailure,
|
|
847
|
-
),
|
|
848
|
-
};
|
|
849
|
-
},
|
|
850
|
-
);
|