@yielded/auth-persistence-drizzle 0.1.0-beta.25 → 0.1.0-beta.27
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 +91 -26
- 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 -1266
- package/src/drizzle/d1-passwords.ts +0 -2061
- 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 -1202
- 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,626 +0,0 @@
|
|
|
1
|
-
import { requiredEmailAddressConstraints, requiredEmailRegistrationConstraints } from "./email-model.mjs";
|
|
2
|
-
import { PersistenceMappingError as PersistenceMappingError$1, column, isMappedConstraintConflict, updateValues } from "./model.mjs";
|
|
3
|
-
import { validateDrizzleStorage } from "./storage-validation.mjs";
|
|
4
|
-
import { CurrentEmailSql, currentAddress, decodeEmailSnapshot, emailLookupQuery, sameEmailRevision, snapshotEmailMutation, validEmailSignInConstraints, validateEmailAuthority } from "./email-sql.mjs";
|
|
5
|
-
import { readEmailRegistrationTarget } from "./email-registration.mjs";
|
|
6
|
-
import { Database } from "./d1-database.mjs";
|
|
7
|
-
import { D1BatchStatements } from "./D1BatchStatements.mjs";
|
|
8
|
-
import { CurrentD1PlanningDatabase, makeD1Owner } from "./d1-planning.mjs";
|
|
9
|
-
import { nativeDatabase } from "./native-database.mjs";
|
|
10
|
-
import { compileD1ProofCompletionPlan } from "./d1-proofs.mjs";
|
|
11
|
-
import { NativeDatabase } from "@yielded/auth-persistence/Adapter";
|
|
12
|
-
import { and, eq, inArray, lte, sql } from "drizzle-orm";
|
|
13
|
-
import { Cause, Context, DateTime, Effect, Option, Schema } from "effect";
|
|
14
|
-
import { CurrentCommitJournal, HookConfigurationError, LifecycleHooks, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
15
|
-
import { assessAuthentication } from "@yielded/auth/Sessions";
|
|
16
|
-
import { EmailAddressPersistence, EmailSignInTargets, EmailUnavailable } from "@yielded/auth/Email";
|
|
17
|
-
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
18
|
-
import { ProofUnavailable } from "@yielded/auth/Proofs";
|
|
19
|
-
//#region src/drizzle/d1-emails.ts
|
|
20
|
-
const emailLookupRows = Effect.fn("DrizzleD1.emailLookupRows")(function* (mapping, moduleId, identifier) {
|
|
21
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
22
|
-
const query = emailLookupQuery(mapping, moduleId, identifier);
|
|
23
|
-
return yield* database.select(query.fields).from(query.from).innerJoin(query.subjectTable, query.subjectJoin).innerJoin(query.credentialTable, query.credentialJoin).where(query.predicate).limit(query.limit);
|
|
24
|
-
});
|
|
25
|
-
const unavailable = () => EmailUnavailable.make({});
|
|
26
|
-
const everyFailureMatches = (cause, classify) => classify !== void 0 && cause.reasons.length > 0 && cause.reasons.every((reason) => Cause.isFailReason(reason) && classify(Cause.fail(reason.error)));
|
|
27
|
-
const statement = Effect.fn(function* (query) {
|
|
28
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
29
|
-
const rendered = query.toSQL();
|
|
30
|
-
return database.$client.unsafe(rendered.sql, rendered.params);
|
|
31
|
-
});
|
|
32
|
-
const containsFailure = (failure, predicate) => {
|
|
33
|
-
const pending = [failure];
|
|
34
|
-
const seen = /* @__PURE__ */ new Set();
|
|
35
|
-
for (let index = 0; index < 32 && pending.length > 0; index++) {
|
|
36
|
-
const value = pending.shift();
|
|
37
|
-
if (value === null || value === void 0 || seen.has(value)) continue;
|
|
38
|
-
seen.add(value);
|
|
39
|
-
if (predicate(value)) return true;
|
|
40
|
-
if (Cause.isCause(value)) {
|
|
41
|
-
for (const reason of value.reasons) if (Cause.isFailReason(reason)) pending.push(reason.error);
|
|
42
|
-
else if (Cause.isDieReason(reason)) pending.push(reason.defect);
|
|
43
|
-
} else if (typeof value === "object") {
|
|
44
|
-
const wrapped = value;
|
|
45
|
-
if (wrapped.cause !== void 0) pending.push(wrapped.cause);
|
|
46
|
-
if (wrapped.reason !== void 0) pending.push(wrapped.reason);
|
|
47
|
-
if (wrapped.message !== void 0) pending.push(wrapped.message);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
};
|
|
52
|
-
const guardFailure = (cause, marker) => {
|
|
53
|
-
const native = `bad JSON path: '${`$[${marker.replaceAll("'", "''")}]`}': SQLITE_ERROR`;
|
|
54
|
-
return containsFailure(cause, (value) => value === native || value === `D1_ERROR: ${native}`);
|
|
55
|
-
};
|
|
56
|
-
const assertion = Effect.fn(function* (condition, marker) {
|
|
57
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
58
|
-
return yield* statement(database.select({ ok: sql`case when ${condition} then 1 else json_extract('[]', ${`$[${marker}]`}) end`.as("ok") }).from(sql`(select 1)`));
|
|
59
|
-
});
|
|
60
|
-
const existsSql = (query) => sql`exists(${query})`;
|
|
61
|
-
const notExistsSql = (query) => sql`not exists(${query})`;
|
|
62
|
-
const readEngineNowMillis = Effect.fn("Drizzle.readEngineNowMillis")(function* (clock) {
|
|
63
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
64
|
-
return yield* awaitRows(database.select({ value: sql`${clock.engineNowMillis}`.mapWith(Number) }).from(sql`(select 1)`)).pipe(Effect.flatMap((rows) => typeof rows[0]?.value === "number" && Number.isFinite(rows[0].value) ? Effect.succeed(rows[0].value) : Effect.fail(unavailable())));
|
|
65
|
-
});
|
|
66
|
-
const driverValues = (values, entries) => ({
|
|
67
|
-
...values,
|
|
68
|
-
...Object.fromEntries(entries)
|
|
69
|
-
});
|
|
70
|
-
const allocate = (asynchronous, synchronous) => asynchronous !== void 0 ? asynchronous : synchronous === void 0 ? Effect.fail(unavailable()) : Effect.try({
|
|
71
|
-
try: synchronous,
|
|
72
|
-
catch: (cause) => new PersistenceMappingError$1({
|
|
73
|
-
operation: "mapping",
|
|
74
|
-
cause
|
|
75
|
-
})
|
|
76
|
-
});
|
|
77
|
-
const validAddress = (mapping) => Object.entries(requiredEmailAddressConstraints).every(([key, value]) => mapping.constraints[key] === value);
|
|
78
|
-
const evidenceCondition = (mapping, evidence, requirement) => {
|
|
79
|
-
const fresh = (proof) => {
|
|
80
|
-
const verified = DateTime.toEpochMillis(proof.verifiedAt);
|
|
81
|
-
return sql`${mapping.d1.engineNowMillis} >= ${verified} and ${mapping.d1.engineNowMillis} - ${verified} < ${requirement.maximumAgeMillis}`;
|
|
82
|
-
};
|
|
83
|
-
const alternatives = requirement.alternatives.flatMap((alternative) => {
|
|
84
|
-
const byCredential = /* @__PURE__ */ new Map();
|
|
85
|
-
for (const proof of evidence.proofs) byCredential.set(proof.credentialId, [...byCredential.get(proof.credentialId) ?? [], fresh(proof)]);
|
|
86
|
-
const credentials = [...byCredential.values()].map((conditions) => sql`(${sql.join(conditions, sql` or `)})`);
|
|
87
|
-
const factors = alternative.factors.map((factor) => {
|
|
88
|
-
const matches = evidence.proofs.filter((proof) => proof.factors.includes(factor)).map(fresh);
|
|
89
|
-
return matches.length === 0 ? sql`false` : sql`(${sql.join(matches, sql` or `)})`;
|
|
90
|
-
});
|
|
91
|
-
const assurance = evidence.proofs.filter((proof) => (!alternative.userVerified || proof.userVerified) && (!alternative.phishingResistant || proof.phishingResistant)).map(fresh);
|
|
92
|
-
if (assurance.length === 0 || credentials.length < alternative.minimumCredentials) return [];
|
|
93
|
-
const minimum = alternative.minimumCredentials === 0 ? sql`true` : sql`(${sql.join(credentials.map((condition) => sql`case when ${condition} then 1 else 0 end`), sql` + `)}) >= ${alternative.minimumCredentials}`;
|
|
94
|
-
return [and(...factors, sql`(${sql.join(assurance, sql` or `)})`, minimum)];
|
|
95
|
-
});
|
|
96
|
-
const noFuture = evidence.proofs.map((proof) => sql`${mapping.d1.engineNowMillis} >= ${DateTime.toEpochMillis(proof.verifiedAt)}`);
|
|
97
|
-
return alternatives.length === 0 ? sql`false` : and(...noFuture, sql`(${sql.join(alternatives, sql` or `)})`);
|
|
98
|
-
};
|
|
99
|
-
const subjectCondition = (mapping, current, revision) => {
|
|
100
|
-
const id = column(mapping.subject.table, mapping.subject.id);
|
|
101
|
-
const status = column(mapping.subject.table, mapping.subject.status);
|
|
102
|
-
const security = column(mapping.subject.table, mapping.subject.securityRevision);
|
|
103
|
-
return existsSql(sql`select 1 from ${mapping.subject.table} where ${id}=${sql.param(current.nativeSubjectId, id)} and ${status}=${sql.param(mapping.subject.d1ActiveStatusValue, status)} and ${security}=${sql.param(revision, security)}`);
|
|
104
|
-
};
|
|
105
|
-
const authorityRevisionCondition = (mapping, current) => {
|
|
106
|
-
const a = mapping.authorityCredential;
|
|
107
|
-
const subject = column(a.table, a.subjectId);
|
|
108
|
-
const credential = column(a.table, a.credentialId);
|
|
109
|
-
const revision = column(a.table, a.revision);
|
|
110
|
-
const status = column(a.table, a.status);
|
|
111
|
-
const expected = current.revision.credentials;
|
|
112
|
-
const matches = expected.map((item) => existsSql(sql`select 1 from ${a.table} where ${subject}=${sql.param(current.nativeSubjectId, subject)} and ${credential}=${sql.param(item.credentialId, credential)} and ${revision}=${sql.param(item.revision, revision)} and ${status}=${sql.param(a.d1ActiveStatusValue, status)}`));
|
|
113
|
-
return and(...matches, sql`(select count(*) from ${a.table} where ${subject}=${sql.param(current.nativeSubjectId, subject)} and ${status}=${sql.param(a.d1ActiveStatusValue, status)})=${expected.length}`);
|
|
114
|
-
};
|
|
115
|
-
const mutationPlan = Effect.fn("Drizzle.mutationPlan")(function* (mapping, proofMapping, uncaptured, action, prepare) {
|
|
116
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
117
|
-
const journal = yield* CurrentCommitJournal;
|
|
118
|
-
if (!validAddress(mapping)) return yield* unavailable();
|
|
119
|
-
const input = yield* snapshotEmailMutation(uncaptured).pipe(Effect.mapError(unavailable));
|
|
120
|
-
const current = yield* validateEmailAuthority(mapping, {
|
|
121
|
-
mode: "interactive",
|
|
122
|
-
locking: false,
|
|
123
|
-
standaloneGuard: Effect.void
|
|
124
|
-
}, input, action);
|
|
125
|
-
if (current === void 0) return {
|
|
126
|
-
receipt: prepare("rejected", journal),
|
|
127
|
-
statements: []
|
|
128
|
-
};
|
|
129
|
-
if ((yield* awaitRows(database.select().from(mapping.command.table).where(and(eq(column(mapping.command.table, mapping.command.moduleId), input.moduleId), eq(column(mapping.command.table, mapping.command.commandId), input.commandId))).limit(1))).length > 0) return {
|
|
130
|
-
receipt: prepare("rejected", journal),
|
|
131
|
-
statements: []
|
|
132
|
-
};
|
|
133
|
-
const requirement = yield* mapping.subject.decodeActionRequirement(current.subject, action);
|
|
134
|
-
const original = yield* assessAuthentication(input.authorization.evidence, input.authorization.requirement).pipe(Effect.mapError(unavailable));
|
|
135
|
-
const configured = yield* assessAuthentication(input.authorization.evidence, requirement).pipe(Effect.mapError(unavailable));
|
|
136
|
-
if (!original.satisfied || !configured.satisfied) return {
|
|
137
|
-
receipt: prepare("rejected", journal),
|
|
138
|
-
statements: []
|
|
139
|
-
};
|
|
140
|
-
const transitionMillis = yield* readEngineNowMillis(mapping.d1);
|
|
141
|
-
const transitionInstant = mapping.encodeInstant(transitionMillis);
|
|
142
|
-
const targetCredentialId = current.targetCredential?.[mapping.credential.credentialId] ?? (yield* allocate(mapping.allocateCredentialId, mapping.allocateCredentialIdSync));
|
|
143
|
-
const targetIdentifierRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
144
|
-
const targetCredentialRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
145
|
-
const sourceIdentifierRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
146
|
-
const sourceCredentialRevision = yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync);
|
|
147
|
-
const confirmsExisting = action === "verify-address" && input.captured.targetIdentifierRevision !== void 0;
|
|
148
|
-
const nextRevision = confirmsExisting ? input.captured.revision.securityRevision : yield* allocate(mapping.subject.nextSecurityRevision?.(input.captured.revision.securityRevision) ?? mapping.allocateRevision, mapping.subject.nextSecurityRevisionSync === void 0 ? mapping.allocateRevisionSync : () => mapping.subject.nextSecurityRevisionSync(input.captured.revision.securityRevision));
|
|
149
|
-
if (!confirmsExisting && nextRevision === input.captured.revision.securityRevision || current.targetIdentifier !== void 0 && targetIdentifierRevision === current.targetIdentifier[mapping.identifier.bindingRevision] || current.targetCredential !== void 0 && targetCredentialRevision === current.targetCredential[mapping.credential.credentialRevision] || current.source !== void 0 && (sourceIdentifierRevision === current.source.snapshot.identifierRevision || sourceCredentialRevision === current.source.snapshot.credentialRevision)) return yield* unavailable();
|
|
150
|
-
const statements = [];
|
|
151
|
-
const i = mapping.identifier;
|
|
152
|
-
const c = mapping.credential;
|
|
153
|
-
const a = mapping.authorityCredential;
|
|
154
|
-
const sc = current.source;
|
|
155
|
-
const authorityMarker = `effect-auth-email-guard:authority:${input.commandId}`;
|
|
156
|
-
const targetIdentifierPrecondition = current.targetIdentifier === void 0 ? notExistsSql(sql`select 1 from ${i.table} where ${column(i.table, i.namespace)}=${sql.param(input.target.namespace, column(i.table, i.namespace))} and ${column(i.table, i.value)}=${sql.param(input.target.value, column(i.table, i.value))}`) : existsSql(sql`select 1 from ${i.table} where ${column(i.table, i.bindingRevision)}=${sql.param(current.targetIdentifier[i.bindingRevision], column(i.table, i.bindingRevision))} and ${i.d1MutableTargetCondition({
|
|
157
|
-
identifier: input.target,
|
|
158
|
-
nativeSubjectId: current.nativeSubjectId
|
|
159
|
-
})}`);
|
|
160
|
-
const targetCredentialPrecondition = current.targetCredential === void 0 ? notExistsSql(sql`select 1 from ${c.table} where ${column(c.table, c.moduleId)}=${sql.param(input.moduleId, column(c.table, c.moduleId))} and ${column(c.table, c.identifierNamespace)}=${sql.param(input.target.namespace, column(c.table, c.identifierNamespace))} and ${column(c.table, c.identifierValue)}=${sql.param(input.target.value, column(c.table, c.identifierValue))}`) : existsSql(sql`select 1 from ${c.table} where ${column(c.table, c.moduleId)}=${sql.param(input.moduleId, column(c.table, c.moduleId))} and ${column(c.table, c.credentialId)}=${sql.param(current.targetCredential[c.credentialId], column(c.table, c.credentialId))} and ${column(c.table, c.subjectId)}=${sql.param(current.nativeSubjectId, column(c.table, c.subjectId))} and ${column(c.table, c.credentialRevision)}=${sql.param(current.targetCredential[c.credentialRevision], column(c.table, c.credentialRevision))} and ${column(c.table, c.status)}<>${sql.param(c.d1ActiveStatusValue, column(c.table, c.status))}`);
|
|
161
|
-
const sourcePrecondition = action === "verify-address" ? sql`true` : and(existsSql(sql`select 1 from ${i.table} where ${i.d1CurrentCondition({
|
|
162
|
-
identifier: sc.snapshot.identifier,
|
|
163
|
-
nativeSubjectId: current.nativeSubjectId,
|
|
164
|
-
bindingRevision: sc.snapshot.identifierRevision
|
|
165
|
-
})}`), existsSql(sql`select 1 from ${c.table} where ${column(c.table, c.moduleId)}=${sql.param(input.moduleId, column(c.table, c.moduleId))} and ${column(c.table, c.credentialId)}=${sql.param(sc.snapshot.credentialId, column(c.table, c.credentialId))} and ${column(c.table, c.subjectId)}=${sql.param(current.nativeSubjectId, column(c.table, c.subjectId))} and ${column(c.table, c.credentialRevision)}=${sql.param(sc.snapshot.credentialRevision, column(c.table, c.credentialRevision))} and ${column(c.table, c.status)}=${sql.param(c.d1ActiveStatusValue, column(c.table, c.status))}`));
|
|
166
|
-
statements.push(yield* assertion(and(subjectCondition(mapping, current, input.captured.revision.securityRevision), authorityRevisionCondition(mapping, current), targetIdentifierPrecondition, targetCredentialPrecondition, sourcePrecondition, evidenceCondition(mapping, input.authorization.evidence, input.authorization.requirement), evidenceCondition(mapping, input.authorization.evidence, requirement)), authorityMarker));
|
|
167
|
-
if (action === "change-address") {
|
|
168
|
-
statements.push(yield* statement(database.update(i.table).set(i.encodeRetirement({
|
|
169
|
-
source: sc.snapshot.identifier,
|
|
170
|
-
bindingRevision: sourceIdentifierRevision
|
|
171
|
-
})).where(and(eq(column(i.table, i.namespace), sc.snapshot.identifier.namespace), eq(column(i.table, i.value), sc.snapshot.identifier.value), eq(column(i.table, i.subjectId), current.nativeSubjectId), eq(column(i.table, i.bindingRevision), sc.snapshot.identifierRevision)))));
|
|
172
|
-
statements.push(yield* statement(database.update(c.table).set(c.encodeRetirement({
|
|
173
|
-
source: sc.snapshot.identifier,
|
|
174
|
-
credentialRevision: sourceCredentialRevision
|
|
175
|
-
})).where(and(eq(column(c.table, c.moduleId), input.moduleId), eq(column(c.table, c.credentialId), sc.snapshot.credentialId), eq(column(c.table, c.subjectId), current.nativeSubjectId), eq(column(c.table, c.credentialRevision), sc.snapshot.credentialRevision)))));
|
|
176
|
-
statements.push(yield* statement(database.update(a.table).set(a.encodeRetirement(sourceCredentialRevision)).where(and(eq(column(a.table, a.subjectId), current.nativeSubjectId), eq(column(a.table, a.credentialId), sc.snapshot.credentialId), eq(column(a.table, a.revision), sc.snapshot.credentialRevision)))));
|
|
177
|
-
}
|
|
178
|
-
if (current.targetIdentifier === void 0) statements.push(yield* statement(database.insert(i.table).values(driverValues(i.encodeVerifiedInsert({
|
|
179
|
-
identifier: input.target,
|
|
180
|
-
subjectId: current.nativeSubjectId,
|
|
181
|
-
verifiedAtMillis: transitionMillis,
|
|
182
|
-
bindingRevision: targetIdentifierRevision
|
|
183
|
-
}), [[i.verifiedAt, transitionInstant]]))));
|
|
184
|
-
else statements.push(yield* statement(database.update(i.table).set(driverValues(i.encodeVerification({
|
|
185
|
-
verifiedAtMillis: transitionMillis,
|
|
186
|
-
bindingRevision: targetIdentifierRevision
|
|
187
|
-
}), [[i.verifiedAt, transitionInstant]])).where(and(eq(column(i.table, i.namespace), input.target.namespace), eq(column(i.table, i.value), input.target.value), eq(column(i.table, i.subjectId), current.nativeSubjectId), eq(column(i.table, i.bindingRevision), current.targetIdentifier[i.bindingRevision])))));
|
|
188
|
-
if (current.targetCredential === void 0) {
|
|
189
|
-
statements.push(yield* statement(database.insert(c.table).values(c.encodeVerifiedInsert({
|
|
190
|
-
moduleId: input.moduleId,
|
|
191
|
-
subjectId: current.nativeSubjectId,
|
|
192
|
-
credentialId: targetCredentialId,
|
|
193
|
-
identifier: input.target,
|
|
194
|
-
credentialRevision: targetCredentialRevision
|
|
195
|
-
}))));
|
|
196
|
-
statements.push(yield* statement(database.insert(a.table).values(a.encodeInsert({
|
|
197
|
-
subjectId: current.nativeSubjectId,
|
|
198
|
-
credentialId: targetCredentialId,
|
|
199
|
-
revision: targetCredentialRevision
|
|
200
|
-
}))));
|
|
201
|
-
} else {
|
|
202
|
-
const oldRevision = current.targetCredential[c.credentialRevision];
|
|
203
|
-
statements.push(yield* statement(database.update(c.table).set(c.encodeActivation({
|
|
204
|
-
identifier: input.target,
|
|
205
|
-
credentialRevision: targetCredentialRevision
|
|
206
|
-
})).where(and(eq(column(c.table, c.moduleId), input.moduleId), eq(column(c.table, c.credentialId), targetCredentialId), eq(column(c.table, c.subjectId), current.nativeSubjectId), eq(column(c.table, c.credentialRevision), oldRevision)))));
|
|
207
|
-
statements.push(yield* statement(database.update(a.table).set(a.encodeActivation(targetCredentialRevision)).where(and(eq(column(a.table, a.subjectId), current.nativeSubjectId), eq(column(a.table, a.credentialId), targetCredentialId), eq(column(a.table, a.revision), oldRevision)))));
|
|
208
|
-
}
|
|
209
|
-
statements.push(yield* statement(database.update(mapping.subject.table).set(updateValues([[mapping.subject.securityRevision, nextRevision]])).where(and(eq(column(mapping.subject.table, mapping.subject.id), current.nativeSubjectId), eq(column(mapping.subject.table, mapping.subject.securityRevision), input.captured.revision.securityRevision)))));
|
|
210
|
-
statements.push(yield* statement(database.insert(mapping.command.table).values(driverValues(mapping.command.encodeInsert({
|
|
211
|
-
moduleId: input.moduleId,
|
|
212
|
-
commandId: input.commandId,
|
|
213
|
-
action,
|
|
214
|
-
bindingDigest: input.authorization.challenge.bindingDigest,
|
|
215
|
-
retentionUntilMillis: transitionMillis + mapping.commandRetentionMillis
|
|
216
|
-
}), [[mapping.command.retentionUntil, mapping.encodeInstant(transitionMillis + mapping.commandRetentionMillis)]]))));
|
|
217
|
-
const targetExists = existsSql(sql`select 1 from ${i.table} where ${column(i.table, i.bindingRevision)}=${sql.param(targetIdentifierRevision, column(i.table, i.bindingRevision))} and ${column(i.table, i.verifiedAt)}=${sql.param(transitionInstant, column(i.table, i.verifiedAt))} and ${i.d1CurrentCondition({
|
|
218
|
-
identifier: input.target,
|
|
219
|
-
nativeSubjectId: current.nativeSubjectId,
|
|
220
|
-
bindingRevision: targetIdentifierRevision
|
|
221
|
-
})}`);
|
|
222
|
-
const credentialExists = existsSql(sql`select 1 from ${c.table} where ${column(c.table, c.moduleId)}=${sql.param(input.moduleId, column(c.table, c.moduleId))} and ${column(c.table, c.credentialId)}=${sql.param(targetCredentialId, column(c.table, c.credentialId))} and ${column(c.table, c.subjectId)}=${sql.param(current.nativeSubjectId, column(c.table, c.subjectId))} and ${column(c.table, c.identifierNamespace)}=${sql.param(input.target.namespace, column(c.table, c.identifierNamespace))} and ${column(c.table, c.identifierValue)}=${sql.param(input.target.value, column(c.table, c.identifierValue))} and ${column(c.table, c.credentialRevision)}=${sql.param(targetCredentialRevision, column(c.table, c.credentialRevision))} and ${column(c.table, c.status)}=${sql.param(c.d1ActiveStatusValue, column(c.table, c.status))}`);
|
|
223
|
-
const authorityExists = existsSql(sql`select 1 from ${a.table} where ${column(a.table, a.subjectId)}=${sql.param(current.nativeSubjectId, column(a.table, a.subjectId))} and ${column(a.table, a.credentialId)}=${sql.param(targetCredentialId, column(a.table, a.credentialId))} and ${column(a.table, a.revision)}=${sql.param(targetCredentialRevision, column(a.table, a.revision))} and ${column(a.table, a.status)}=${sql.param(a.d1ActiveStatusValue, column(a.table, a.status))}`);
|
|
224
|
-
const commandExists = existsSql(sql`select 1 from ${mapping.command.table} where ${column(mapping.command.table, mapping.command.moduleId)}=${sql.param(input.moduleId, column(mapping.command.table, mapping.command.moduleId))} and ${column(mapping.command.table, mapping.command.commandId)}=${sql.param(input.commandId, column(mapping.command.table, mapping.command.commandId))} and ${column(mapping.command.table, mapping.command.action)}=${sql.param(action, column(mapping.command.table, mapping.command.action))} and ${column(mapping.command.table, mapping.command.bindingDigest)}=${sql.param(input.authorization.challenge.bindingDigest, column(mapping.command.table, mapping.command.bindingDigest))} and ${column(mapping.command.table, mapping.command.retentionUntil)}=${sql.param(mapping.encodeInstant(transitionMillis + mapping.commandRetentionMillis), column(mapping.command.table, mapping.command.retentionUntil))}`);
|
|
225
|
-
const sourceRetired = action === "verify-address" ? sql`true` : and(existsSql(sql`select 1 from ${i.table} where ${column(i.table, i.namespace)}=${sql.param(sc.snapshot.identifier.namespace, column(i.table, i.namespace))} and ${column(i.table, i.value)}=${sql.param(sc.snapshot.identifier.value, column(i.table, i.value))} and ${column(i.table, i.subjectId)}=${sql.param(current.nativeSubjectId, column(i.table, i.subjectId))} and ${column(i.table, i.bindingRevision)}=${sql.param(sourceIdentifierRevision, column(i.table, i.bindingRevision))} and not (${i.d1CurrentCondition({
|
|
226
|
-
identifier: sc.snapshot.identifier,
|
|
227
|
-
nativeSubjectId: current.nativeSubjectId,
|
|
228
|
-
bindingRevision: sourceIdentifierRevision
|
|
229
|
-
})})`), existsSql(sql`select 1 from ${c.table} where ${column(c.table, c.moduleId)}=${sql.param(input.moduleId, column(c.table, c.moduleId))} and ${column(c.table, c.credentialId)}=${sql.param(sc.snapshot.credentialId, column(c.table, c.credentialId))} and ${column(c.table, c.subjectId)}=${sql.param(current.nativeSubjectId, column(c.table, c.subjectId))} and ${column(c.table, c.identifierNamespace)}=${sql.param(sc.snapshot.identifier.namespace, column(c.table, c.identifierNamespace))} and ${column(c.table, c.identifierValue)}=${sql.param(sc.snapshot.identifier.value, column(c.table, c.identifierValue))} and ${column(c.table, c.credentialRevision)}=${sql.param(sourceCredentialRevision, column(c.table, c.credentialRevision))} and ${column(c.table, c.status)}<>${sql.param(c.d1ActiveStatusValue, column(c.table, c.status))}`), existsSql(sql`select 1 from ${a.table} where ${column(a.table, a.subjectId)}=${sql.param(current.nativeSubjectId, column(a.table, a.subjectId))} and ${column(a.table, a.credentialId)}=${sql.param(sc.snapshot.credentialId, column(a.table, a.credentialId))} and ${column(a.table, a.revision)}=${sql.param(sourceCredentialRevision, column(a.table, a.revision))} and ${column(a.table, a.status)}<>${sql.param(a.d1ActiveStatusValue, column(a.table, a.status))}`));
|
|
230
|
-
const applied = and(subjectCondition(mapping, current, nextRevision), targetExists, credentialExists, authorityExists, commandExists, sourceRetired, evidenceCondition(mapping, input.authorization.evidence, input.authorization.requirement), evidenceCondition(mapping, input.authorization.evidence, requirement));
|
|
231
|
-
const compiled = yield* compileD1ProofCompletionPlan(proofMapping, input.completion, {
|
|
232
|
-
statements,
|
|
233
|
-
appliedCondition: applied
|
|
234
|
-
}, (decision) => decision);
|
|
235
|
-
const marker = `effect-auth-proof-guard:protected:${input.completion.input.continuationId}`;
|
|
236
|
-
return {
|
|
237
|
-
receipt: prepare(compiled.statements.length === 0 ? "rejected" : "changed", journal),
|
|
238
|
-
statements: compiled.statements,
|
|
239
|
-
retryable: (cause) => guardFailure(cause, marker) || guardFailure(cause, authorityMarker) || isMappedConstraintConflict(mapping.isCommandConflict, cause) || isMappedConstraintConflict(mapping.isIdentifierConflict, cause) || isMappedConstraintConflict(mapping.isCredentialConflict, cause)
|
|
240
|
-
};
|
|
241
|
-
});
|
|
242
|
-
const awaitRows = (effect) => effect;
|
|
243
|
-
const probeCompletion = Effect.fn("DrizzleD1.probeCompletion")(function* (proofMapping, input) {
|
|
244
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
245
|
-
const plan = {
|
|
246
|
-
input,
|
|
247
|
-
prepare: (decision, journal, project) => journal.prepare(project(decision))
|
|
248
|
-
};
|
|
249
|
-
const marker = `effect-auth-proof-guard:protected:${input.continuationId}`;
|
|
250
|
-
return yield* coordinateCommit(() => Effect.gen(function* () {
|
|
251
|
-
const compiled = yield* compileD1ProofCompletionPlan(proofMapping, plan, {
|
|
252
|
-
statements: [],
|
|
253
|
-
appliedCondition: sql`false`
|
|
254
|
-
}, () => false);
|
|
255
|
-
if (compiled.statements.length === 0) return false;
|
|
256
|
-
yield* database.$client.batch(compiled.statements);
|
|
257
|
-
return false;
|
|
258
|
-
}), { mode: "batch" }).pipe(Effect.as(false), Effect.catchCause((cause) => guardFailure(cause, marker) ? Effect.succeed(true) : Effect.failCause(cause)));
|
|
259
|
-
});
|
|
260
|
-
const makeAddressPlans = (mapping, proofMapping) => ({
|
|
261
|
-
target: (input) => currentAddress(mapping, input, false).pipe(Effect.flatMap((current) => current === void 0 ? Effect.fail(unavailable()) : Effect.succeed({
|
|
262
|
-
revision: current.revision,
|
|
263
|
-
eligible: current.eligible,
|
|
264
|
-
...current.targetIdentifierRevision === void 0 ? {} : { targetIdentifierRevision: current.targetIdentifierRevision },
|
|
265
|
-
...current.source === void 0 ? {} : { source: current.source.snapshot }
|
|
266
|
-
}))),
|
|
267
|
-
checkCompletion: (input) => {
|
|
268
|
-
if (input.binding._tag !== "IdentifierChange") return Effect.succeed(false);
|
|
269
|
-
const binding = input.binding;
|
|
270
|
-
const action = input.moduleId.endsWith("/verify-address") && input.purpose === "email-address-verification" ? "verify-address" : input.moduleId.endsWith("/change-address") && input.purpose === "email-address-change" ? "change-address" : void 0;
|
|
271
|
-
if (action === void 0) return Effect.succeed(false);
|
|
272
|
-
const moduleId = input.moduleId.slice(0, -`/${action}`.length);
|
|
273
|
-
return currentAddress(mapping, {
|
|
274
|
-
moduleId,
|
|
275
|
-
subjectId: binding.revision.subjectId,
|
|
276
|
-
target: binding.identifier
|
|
277
|
-
}, false).pipe(Effect.flatMap((current) => current !== void 0 && sameEmailRevision(current.revision, binding.revision) ? probeCompletion(proofMapping, input) : Effect.succeed(false)));
|
|
278
|
-
},
|
|
279
|
-
verifyWithProof: (input, prepare) => mutationPlan(mapping, proofMapping, input, "verify-address", prepare),
|
|
280
|
-
changeWithProof: (input, prepare) => mutationPlan(mapping, proofMapping, input, "change-address", prepare),
|
|
281
|
-
cleanup: (input, prepare) => Effect.gen(function* () {
|
|
282
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
283
|
-
const journal = yield* CurrentCommitJournal;
|
|
284
|
-
const module = column(mapping.command.table, mapping.command.moduleId);
|
|
285
|
-
const id = column(mapping.command.table, mapping.command.commandId);
|
|
286
|
-
const retention = column(mapping.command.table, mapping.command.retentionUntil);
|
|
287
|
-
const rows = yield* awaitRows(database.select({ commandId: id }).from(mapping.command.table).where(and(eq(module, input.moduleId), lte(retention, mapping.d1.engineNow))).limit(input.limit + 1));
|
|
288
|
-
const selected = rows.slice(0, input.limit);
|
|
289
|
-
const marker = `effect-auth-email-guard:cleanup:${input.moduleId}`;
|
|
290
|
-
const selectedIds = selected.map((row) => row.commandId);
|
|
291
|
-
const selectedWhere = and(eq(module, input.moduleId), inArray(id, selectedIds), lte(retention, mapping.d1.engineNow));
|
|
292
|
-
const statements = selected.length === 0 ? [] : [yield* assertion(sql`(select count(*) from ${mapping.command.table} where ${selectedWhere})=${selected.length}`, marker), yield* statement(database.delete(mapping.command.table).where(selectedWhere))];
|
|
293
|
-
return {
|
|
294
|
-
receipt: prepare({
|
|
295
|
-
removed: selected.length,
|
|
296
|
-
hasMore: rows.length > input.limit
|
|
297
|
-
}, journal),
|
|
298
|
-
statements,
|
|
299
|
-
retryable: (cause) => guardFailure(cause, marker)
|
|
300
|
-
};
|
|
301
|
-
})
|
|
302
|
-
});
|
|
303
|
-
const registrationRows = Effect.fn("Drizzle.registrationRows")(function* (mapping, moduleId, commandId) {
|
|
304
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
305
|
-
return yield* awaitRows(database.select().from(mapping.registration.table).where(and(eq(column(mapping.registration.table, mapping.registration.moduleId), moduleId), eq(column(mapping.registration.table, mapping.registration.commandId), commandId))).limit(1));
|
|
306
|
-
});
|
|
307
|
-
const sameIdentifier = (left, right) => left.namespace === right.namespace && left.value === right.value;
|
|
308
|
-
const registrationCompletionMatches = (mapping, input) => input.completion.input.moduleId === `${input.moduleId}/registration` && input.completion.input.purpose === "email-code-registration" && input.completion.input.binding._tag === "Identifier" && sameIdentifier(input.completion.input.binding.identifier, input.identifier) && mapping.constraints.request === requiredEmailRegistrationConstraints.request && mapping.constraints.pendingReference === requiredEmailRegistrationConstraints.pendingReference && (mapping.mode === "pending" || Object.entries(requiredEmailRegistrationConstraints).every(([key, value]) => mapping.constraints[key] === value));
|
|
309
|
-
const registrationPlan = Effect.fn("Drizzle.registrationPlan")(function* (mapping, proofMapping, input, inspected, allocated, prepare) {
|
|
310
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
311
|
-
const journal = yield* CurrentCommitJournal;
|
|
312
|
-
const existing = (yield* registrationRows(mapping, input.moduleId, input.commandId))[0];
|
|
313
|
-
if (existing !== void 0) return {
|
|
314
|
-
receipt: prepare(existing[mapping.registration.fingerprint] !== input.fingerprint ? { _tag: "Rejected" } : yield* mapping.registration.decodeReplay(existing), journal),
|
|
315
|
-
statements: []
|
|
316
|
-
};
|
|
317
|
-
if (!registrationCompletionMatches(mapping, input) || !inspected.eligible || inspected.fingerprint !== input.fingerprint || mapping.mode === "atomic" && (mapping.provisioning.idMode === "generated" || mapping.subject.d1ActiveStatusValue === void 0 || mapping.identifier.d1CurrentCondition === void 0 || mapping.credential.d1ActiveStatusValue === void 0 || mapping.authorityCredential.d1ActiveStatusValue === void 0)) return {
|
|
318
|
-
receipt: prepare({ _tag: "Rejected" }, journal),
|
|
319
|
-
statements: []
|
|
320
|
-
};
|
|
321
|
-
const target = mapping.mode === "atomic" ? yield* readEmailRegistrationTarget(mapping, input.identifier, false) : void 0;
|
|
322
|
-
if (target?._tag === "Rejected") return {
|
|
323
|
-
receipt: prepare({ _tag: "Rejected" }, journal),
|
|
324
|
-
statements: []
|
|
325
|
-
};
|
|
326
|
-
if (target?._tag === "Reserved" && (allocated.displacedSecurityRevision === void 0 || allocated.displacedSecurityRevision === target.securityRevision || allocated.identifierRevision === target.bindingRevision)) return yield* unavailable();
|
|
327
|
-
const intent = {
|
|
328
|
-
moduleId: input.moduleId,
|
|
329
|
-
commandId: input.commandId,
|
|
330
|
-
identifier: input.identifier,
|
|
331
|
-
registration: input.registration,
|
|
332
|
-
fingerprint: input.fingerprint,
|
|
333
|
-
completion: {
|
|
334
|
-
moduleId: input.completion.input.moduleId,
|
|
335
|
-
purpose: input.completion.input.purpose,
|
|
336
|
-
continuationId: input.completion.input.continuationId,
|
|
337
|
-
binding: input.completion.input.binding
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const transitionMillis = yield* readEngineNowMillis(mapping.d1);
|
|
341
|
-
const retentionInstant = mapping.encodeInstant(transitionMillis + mapping.retentionMillis);
|
|
342
|
-
const statements = [];
|
|
343
|
-
let applied;
|
|
344
|
-
let desired;
|
|
345
|
-
const registrationModule = column(mapping.registration.table, mapping.registration.moduleId);
|
|
346
|
-
const registrationCommand = column(mapping.registration.table, mapping.registration.commandId);
|
|
347
|
-
const registrationFingerprint = column(mapping.registration.table, mapping.registration.fingerprint);
|
|
348
|
-
const registrationState = column(mapping.registration.table, mapping.registration.state);
|
|
349
|
-
if (mapping.mode === "pending") {
|
|
350
|
-
if (allocated.pendingReference === void 0) return {
|
|
351
|
-
receipt: prepare({ _tag: "Rejected" }, journal),
|
|
352
|
-
statements: []
|
|
353
|
-
};
|
|
354
|
-
desired = {
|
|
355
|
-
_tag: "ProvisioningPending",
|
|
356
|
-
reference: allocated.pendingReference
|
|
357
|
-
};
|
|
358
|
-
statements.push(yield* statement(database.insert(mapping.registration.table).values(driverValues(mapping.registration.encodeInsert(intent, {
|
|
359
|
-
state: "pending",
|
|
360
|
-
pendingReference: allocated.pendingReference,
|
|
361
|
-
retentionUntilMillis: transitionMillis + mapping.retentionMillis
|
|
362
|
-
}), [[mapping.registration.retentionUntil, retentionInstant]]))));
|
|
363
|
-
applied = existsSql(sql`select 1 from ${mapping.registration.table} where ${registrationModule}=${sql.param(input.moduleId, registrationModule)} and ${registrationCommand}=${sql.param(input.commandId, registrationCommand)} and ${registrationFingerprint}=${sql.param(input.fingerprint, registrationFingerprint)} and ${registrationState}='pending' and ${column(mapping.registration.table, mapping.registration.pendingReference)}=${sql.param(allocated.pendingReference, column(mapping.registration.table, mapping.registration.pendingReference))} and ${column(mapping.registration.table, mapping.registration.subjectId)} is null and ${column(mapping.registration.table, mapping.registration.retentionUntil)}=${sql.param(retentionInstant, column(mapping.registration.table, mapping.registration.retentionUntil))}`);
|
|
364
|
-
} else {
|
|
365
|
-
if (allocated.nativeSubjectId === void 0 || allocated.credentialId === void 0 || allocated.securityRevision === void 0 || allocated.identifierRevision === void 0 || allocated.credentialRevision === void 0) return {
|
|
366
|
-
receipt: prepare({ _tag: "Rejected" }, journal),
|
|
367
|
-
statements: []
|
|
368
|
-
};
|
|
369
|
-
const nativeSubjectId = allocated.nativeSubjectId;
|
|
370
|
-
desired = { _tag: "Registered" };
|
|
371
|
-
const i = mapping.identifier;
|
|
372
|
-
const s = mapping.subject;
|
|
373
|
-
const marker = `effect-auth-proof-guard:protected:${input.completion.input.continuationId}`;
|
|
374
|
-
if (target?._tag === "Reserved") statements.push(yield* assertion(and(existsSql(sql`select 1 from ${i.table} where
|
|
375
|
-
${column(i.table, i.namespace)}=${sql.param(input.identifier.namespace, column(i.table, i.namespace))}
|
|
376
|
-
and ${column(i.table, i.value)}=${sql.param(input.identifier.value, column(i.table, i.value))}
|
|
377
|
-
and ${column(i.table, i.subjectId)}=${sql.param(target.nativeSubjectId, column(i.table, i.subjectId))}
|
|
378
|
-
and ${column(i.table, i.bindingRevision)}=${sql.param(target.bindingRevision, column(i.table, i.bindingRevision))}
|
|
379
|
-
and ${column(i.table, i.verifiedAt)} is null`), existsSql(sql`select 1 from ${s.table} where
|
|
380
|
-
${column(s.table, s.id)}=${sql.param(target.nativeSubjectId, column(s.table, s.id))}
|
|
381
|
-
and ${column(s.table, s.securityRevision)}=${sql.param(target.securityRevision, column(s.table, s.securityRevision))}`)), marker));
|
|
382
|
-
statements.push(yield* statement(database.insert(mapping.subject.table).values(mapping.provisioning.encodeSubjectInsert(intent, {
|
|
383
|
-
nativeSubjectId,
|
|
384
|
-
securityRevision: allocated.securityRevision
|
|
385
|
-
}))), ...target?._tag === "Reserved" ? [yield* statement(database.update(i.table).set(updateValues([
|
|
386
|
-
[i.subjectId, nativeSubjectId],
|
|
387
|
-
[i.verifiedAt, mapping.encodeInstant(transitionMillis)],
|
|
388
|
-
[i.bindingRevision, allocated.identifierRevision]
|
|
389
|
-
])).where(and(eq(column(i.table, i.namespace), input.identifier.namespace), eq(column(i.table, i.value), input.identifier.value), eq(column(i.table, i.subjectId), target.nativeSubjectId), eq(column(i.table, i.bindingRevision), target.bindingRevision), sql`${column(i.table, i.verifiedAt)} is null`))), yield* statement(database.update(s.table).set(updateValues([[s.securityRevision, allocated.displacedSecurityRevision]])).where(and(eq(column(s.table, s.id), target.nativeSubjectId), eq(column(s.table, s.securityRevision), target.securityRevision))))] : [yield* statement(database.insert(i.table).values(driverValues(i.encodeVerifiedInsert({
|
|
390
|
-
identifier: input.identifier,
|
|
391
|
-
subjectId: nativeSubjectId,
|
|
392
|
-
verifiedAtMillis: transitionMillis,
|
|
393
|
-
bindingRevision: allocated.identifierRevision
|
|
394
|
-
}), [[i.verifiedAt, mapping.encodeInstant(transitionMillis)]])))], yield* statement(database.insert(mapping.credential.table).values(mapping.credential.encodeVerifiedInsert({
|
|
395
|
-
moduleId: input.moduleId,
|
|
396
|
-
subjectId: nativeSubjectId,
|
|
397
|
-
credentialId: allocated.credentialId,
|
|
398
|
-
identifier: input.identifier,
|
|
399
|
-
credentialRevision: allocated.credentialRevision
|
|
400
|
-
}))), yield* statement(database.insert(mapping.authorityCredential.table).values(mapping.authorityCredential.encodeInsert({
|
|
401
|
-
subjectId: nativeSubjectId,
|
|
402
|
-
credentialId: allocated.credentialId,
|
|
403
|
-
revision: allocated.credentialRevision
|
|
404
|
-
}))), yield* statement(database.insert(mapping.registration.table).values(driverValues(mapping.registration.encodeInsert(intent, {
|
|
405
|
-
state: "registered",
|
|
406
|
-
nativeSubjectId,
|
|
407
|
-
retentionUntilMillis: transitionMillis + mapping.retentionMillis
|
|
408
|
-
}), [[mapping.registration.retentionUntil, retentionInstant]]))));
|
|
409
|
-
const sId = column(mapping.subject.table, mapping.subject.id);
|
|
410
|
-
const sStatus = column(mapping.subject.table, mapping.subject.status);
|
|
411
|
-
const sRevision = column(mapping.subject.table, mapping.subject.securityRevision);
|
|
412
|
-
const iNamespace = column(mapping.identifier.table, mapping.identifier.namespace);
|
|
413
|
-
const iValue = column(mapping.identifier.table, mapping.identifier.value);
|
|
414
|
-
const iSubject = column(mapping.identifier.table, mapping.identifier.subjectId);
|
|
415
|
-
const iVerifiedAt = column(mapping.identifier.table, mapping.identifier.verifiedAt);
|
|
416
|
-
const iRevision = column(mapping.identifier.table, mapping.identifier.bindingRevision);
|
|
417
|
-
const cModule = column(mapping.credential.table, mapping.credential.moduleId);
|
|
418
|
-
const cSubject = column(mapping.credential.table, mapping.credential.subjectId);
|
|
419
|
-
const cId = column(mapping.credential.table, mapping.credential.credentialId);
|
|
420
|
-
const cNamespace = column(mapping.credential.table, mapping.credential.identifierNamespace);
|
|
421
|
-
const cValue = column(mapping.credential.table, mapping.credential.identifierValue);
|
|
422
|
-
const cRevision = column(mapping.credential.table, mapping.credential.credentialRevision);
|
|
423
|
-
const aSubject = column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId);
|
|
424
|
-
const aId = column(mapping.authorityCredential.table, mapping.authorityCredential.credentialId);
|
|
425
|
-
const aRevision = column(mapping.authorityCredential.table, mapping.authorityCredential.revision);
|
|
426
|
-
applied = and(target?._tag === "Reserved" ? existsSql(sql`select 1 from ${s.table} where
|
|
427
|
-
${sId}=${sql.param(target.nativeSubjectId, sId)}
|
|
428
|
-
and ${sRevision}=${sql.param(allocated.displacedSecurityRevision, sRevision)}`) : sql`true`, existsSql(sql`select 1 from ${mapping.subject.table} where ${sId}=${sql.param(nativeSubjectId, sId)} and ${sStatus}=${sql.param(mapping.subject.d1ActiveStatusValue, sStatus)} and ${sRevision}=${sql.param(allocated.securityRevision, sRevision)}`), existsSql(sql`select 1 from ${mapping.identifier.table} where ${iNamespace}=${sql.param(input.identifier.namespace, iNamespace)} and ${iValue}=${sql.param(input.identifier.value, iValue)} and ${iSubject}=${sql.param(nativeSubjectId, iSubject)} and ${iVerifiedAt}=${sql.param(mapping.encodeInstant(transitionMillis), iVerifiedAt)} and ${iRevision}=${sql.param(allocated.identifierRevision, iRevision)} and ${mapping.identifier.d1CurrentCondition({
|
|
429
|
-
identifier: input.identifier,
|
|
430
|
-
nativeSubjectId,
|
|
431
|
-
bindingRevision: allocated.identifierRevision
|
|
432
|
-
})}`), existsSql(sql`select 1 from ${mapping.credential.table} where ${cModule}=${sql.param(input.moduleId, cModule)} and ${cSubject}=${sql.param(nativeSubjectId, cSubject)} and ${cId}=${sql.param(allocated.credentialId, cId)} and ${cNamespace}=${sql.param(input.identifier.namespace, cNamespace)} and ${cValue}=${sql.param(input.identifier.value, cValue)} and ${cRevision}=${sql.param(allocated.credentialRevision, cRevision)} and ${column(mapping.credential.table, mapping.credential.status)}=${sql.param(mapping.credential.d1ActiveStatusValue, column(mapping.credential.table, mapping.credential.status))}`), existsSql(sql`select 1 from ${mapping.authorityCredential.table} where ${aSubject}=${sql.param(nativeSubjectId, aSubject)} and ${aId}=${sql.param(allocated.credentialId, aId)} and ${aRevision}=${sql.param(allocated.credentialRevision, aRevision)} and ${column(mapping.authorityCredential.table, mapping.authorityCredential.status)}=${sql.param(mapping.authorityCredential.d1ActiveStatusValue, column(mapping.authorityCredential.table, mapping.authorityCredential.status))}`), existsSql(sql`select 1 from ${mapping.registration.table} where ${registrationModule}=${sql.param(input.moduleId, registrationModule)} and ${registrationCommand}=${sql.param(input.commandId, registrationCommand)} and ${registrationFingerprint}=${sql.param(input.fingerprint, registrationFingerprint)} and ${registrationState}='registered' and ${column(mapping.registration.table, mapping.registration.subjectId)}=${sql.param(nativeSubjectId, column(mapping.registration.table, mapping.registration.subjectId))} and ${column(mapping.registration.table, mapping.registration.pendingReference)} is null and ${column(mapping.registration.table, mapping.registration.retentionUntil)}=${sql.param(retentionInstant, column(mapping.registration.table, mapping.registration.retentionUntil))}`));
|
|
433
|
-
}
|
|
434
|
-
let receipt;
|
|
435
|
-
const compiled = yield* compileD1ProofCompletionPlan(proofMapping, input.completion, {
|
|
436
|
-
statements,
|
|
437
|
-
appliedCondition: applied
|
|
438
|
-
}, (completion) => {
|
|
439
|
-
receipt = prepare(completion === "completed" ? desired : { _tag: "Rejected" }, journal);
|
|
440
|
-
return completion;
|
|
441
|
-
});
|
|
442
|
-
const marker = `effect-auth-proof-guard:protected:${input.completion.input.continuationId}`;
|
|
443
|
-
return {
|
|
444
|
-
receipt: receipt ?? prepare({ _tag: "Rejected" }, journal),
|
|
445
|
-
statements: compiled.statements,
|
|
446
|
-
retryable: (cause) => guardFailure(cause, marker) || isMappedConstraintConflict(mapping.isRequestConflict, cause) || mapping.mode === "atomic" && (isMappedConstraintConflict(mapping.isIdentifierConflict, cause) || isMappedConstraintConflict(mapping.isCredentialConflict, cause))
|
|
447
|
-
};
|
|
448
|
-
});
|
|
449
|
-
const makeRegistrationPlans = (mapping, proofMapping) => ({
|
|
450
|
-
inspect: (input) => mapping.inspect(input),
|
|
451
|
-
registerWithProof: (uncaptured, prepare) => Effect.gen(function* () {
|
|
452
|
-
const registration = yield* mapping.snapshotRegistration(uncaptured.registration);
|
|
453
|
-
const inspectionRegistration = yield* mapping.snapshotRegistration(uncaptured.registration);
|
|
454
|
-
const input = Object.freeze({
|
|
455
|
-
...uncaptured,
|
|
456
|
-
identifier: Object.freeze({ ...uncaptured.identifier }),
|
|
457
|
-
registration
|
|
458
|
-
});
|
|
459
|
-
const inspected = yield* mapping.inspect({
|
|
460
|
-
identifier: input.identifier,
|
|
461
|
-
registration: inspectionRegistration
|
|
462
|
-
});
|
|
463
|
-
const atomic = mapping.mode === "atomic";
|
|
464
|
-
const credentialId = atomic ? yield* allocate(mapping.allocateCredentialId, mapping.allocateCredentialIdSync) : void 0;
|
|
465
|
-
const securityRevision = atomic ? yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync) : void 0;
|
|
466
|
-
const displacedSecurityRevision = atomic ? yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync) : void 0;
|
|
467
|
-
const identifierRevision = atomic ? yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync) : void 0;
|
|
468
|
-
const credentialRevision = atomic ? yield* allocate(mapping.allocateRevision, mapping.allocateRevisionSync) : void 0;
|
|
469
|
-
const nativeSubjectId = atomic && mapping.provisioning.idMode !== "generated" ? yield* allocate(mapping.provisioning.allocateSubjectId, mapping.provisioning.allocateSubjectIdSync) : void 0;
|
|
470
|
-
const pendingReference = mapping.mode === "pending" ? yield* allocate(mapping.allocatePendingReference, mapping.allocatePendingReferenceSync) : void 0;
|
|
471
|
-
return yield* registrationPlan(mapping, proofMapping, input, inspected, {
|
|
472
|
-
...credentialId === void 0 ? {} : { credentialId },
|
|
473
|
-
...securityRevision === void 0 ? {} : { securityRevision },
|
|
474
|
-
...displacedSecurityRevision === void 0 ? {} : { displacedSecurityRevision },
|
|
475
|
-
...identifierRevision === void 0 ? {} : { identifierRevision },
|
|
476
|
-
...credentialRevision === void 0 ? {} : { credentialRevision },
|
|
477
|
-
...nativeSubjectId === void 0 ? {} : { nativeSubjectId },
|
|
478
|
-
...pendingReference === void 0 ? {} : { pendingReference }
|
|
479
|
-
}, prepare);
|
|
480
|
-
})
|
|
481
|
-
});
|
|
482
|
-
const makeD1EmailSignInServices = (mapping) => Effect.flatMap(nativeDatabase(Database), (database) => validateDrizzleStorage(mapping).pipe(Effect.provideService(NativeDatabase, database), Effect.mapError(unavailable), Effect.as({ emailSignInTargets: EmailSignInTargets.of({ lookup: (input) => {
|
|
483
|
-
if (!validEmailSignInConstraints(mapping)) return Effect.fail(unavailable());
|
|
484
|
-
return emailLookupRows(mapping, input.moduleId, input.identifier).pipe(Effect.flatMap((rows) => {
|
|
485
|
-
const row = rows[0];
|
|
486
|
-
if (row === void 0) return Effect.succeed(Option.none());
|
|
487
|
-
return decodeEmailSnapshot(mapping, input.moduleId, input.identifier, row).pipe(Effect.map((snapshot) => snapshot === void 0 ? Option.none() : Option.some(snapshot)));
|
|
488
|
-
}), Effect.provideService(CurrentD1PlanningDatabase, database), translateFailure);
|
|
489
|
-
} }) })));
|
|
490
|
-
const makeD1EmailAddressServices = Effect.fnUntraced(function* (mapping, proofMapping) {
|
|
491
|
-
const database = yield* Database;
|
|
492
|
-
yield* validateDrizzleStorage({
|
|
493
|
-
...mapping,
|
|
494
|
-
proof: proofMapping
|
|
495
|
-
}).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(Database)), Effect.mapError(unavailable));
|
|
496
|
-
const hooks = yield* LifecycleHooks;
|
|
497
|
-
const plans = makeAddressPlans(mapping, proofMapping);
|
|
498
|
-
const run = (plan) => Effect.gen(function* () {
|
|
499
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
500
|
-
return yield* executeStandalone(plan, 2);
|
|
501
|
-
}).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks));
|
|
502
|
-
return { emailAddressPersistence: {
|
|
503
|
-
target: (input) => plans.target(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
504
|
-
checkCompletion: (input) => plans.checkCompletion(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
505
|
-
verifyWithProof: (input, prepare) => run(plans.verifyWithProof(input, prepare)).pipe(translateFailure),
|
|
506
|
-
changeWithProof: (input, prepare) => run(plans.changeWithProof(input, prepare)).pipe(translateFailure),
|
|
507
|
-
cleanup: (input, prepare) => run(plans.cleanup(input, prepare)).pipe(translateFailure)
|
|
508
|
-
} };
|
|
509
|
-
});
|
|
510
|
-
const makeD1EmailRegistrationServices = Effect.fnUntraced(function* (mapping, proofMapping) {
|
|
511
|
-
const database = yield* Database;
|
|
512
|
-
yield* validateDrizzleStorage({
|
|
513
|
-
...mapping,
|
|
514
|
-
proof: proofMapping
|
|
515
|
-
}).pipe(Effect.provideServiceEffect(NativeDatabase, nativeDatabase(Database)), Effect.mapError(unavailable));
|
|
516
|
-
const hooks = yield* LifecycleHooks;
|
|
517
|
-
const plans = makeRegistrationPlans(mapping, proofMapping);
|
|
518
|
-
const run = (plan) => Effect.gen(function* () {
|
|
519
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
520
|
-
return yield* executeStandalone(plan, 2);
|
|
521
|
-
}).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks));
|
|
522
|
-
return { registrationAuthority: {
|
|
523
|
-
inspect: (input) => plans.inspect(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure),
|
|
524
|
-
registerWithProof: (input, prepare) => run(plans.registerWithProof(input, prepare)).pipe(translateFailure)
|
|
525
|
-
} };
|
|
526
|
-
});
|
|
527
|
-
function coordinateD1EmailAddress(acquire, options, body) {
|
|
528
|
-
return Effect.flatMap(nativeDatabase(acquire), (database) => Effect.gen(function* () {
|
|
529
|
-
yield* validateDrizzleStorage({
|
|
530
|
-
...options.mapping,
|
|
531
|
-
proof: options.proofMapping
|
|
532
|
-
}).pipe(Effect.mapError(unavailable));
|
|
533
|
-
const hooks = yield* LifecycleHooks;
|
|
534
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
535
|
-
return (yield* coordinateCommit(() => Effect.gen(function* () {
|
|
536
|
-
const statements = [];
|
|
537
|
-
let mutation;
|
|
538
|
-
const nativeCollector = D1BatchStatements.of({ append: (statement) => Effect.sync(() => statements.push(statement)) });
|
|
539
|
-
const owner = yield* makeD1Owner(unavailable()).pipe(Effect.provideService(D1BatchStatements, nativeCollector));
|
|
540
|
-
const plans = makeAddressPlans(options.mapping, options.proofMapping);
|
|
541
|
-
const run = (plan) => coordinateCommit(() => Effect.gen(function* () {
|
|
542
|
-
const journal = yield* CurrentCommitJournal;
|
|
543
|
-
const planned = yield* plan;
|
|
544
|
-
yield* owner.check;
|
|
545
|
-
if (mutation !== void 0) return yield* unavailable();
|
|
546
|
-
const guarded = {
|
|
547
|
-
...planned,
|
|
548
|
-
journalGuard: journal.prepare(void 0)
|
|
549
|
-
};
|
|
550
|
-
mutation = guarded;
|
|
551
|
-
statements.push(...guarded.statements);
|
|
552
|
-
return guarded.receipt;
|
|
553
|
-
}), { mode: "batch" }).pipe(Effect.map((result) => result.value), Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks));
|
|
554
|
-
const provided = Context.make(EmailAddressPersistence, {
|
|
555
|
-
target: (input) => owner.run(plans.target(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)),
|
|
556
|
-
checkCompletion: (input) => owner.run(plans.checkCompletion(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)),
|
|
557
|
-
verifyWithProof: (input, prepare) => owner.run(run(plans.verifyWithProof(input, prepare)).pipe(translateFailure)),
|
|
558
|
-
changeWithProof: (input, prepare) => owner.run(run(plans.changeWithProof(input, prepare)).pipe(translateFailure)),
|
|
559
|
-
cleanup: (input, prepare) => owner.run(run(plans.cleanup(input, prepare)).pipe(translateFailure))
|
|
560
|
-
}).pipe(Context.add(D1BatchStatements, owner.collector));
|
|
561
|
-
const value = yield* owner.close(Effect.provideContext(body, provided));
|
|
562
|
-
if (mutation?.journalGuard !== void 0) {
|
|
563
|
-
const status = yield* Effect.result(mutation.journalGuard.read);
|
|
564
|
-
if (status._tag === "Success" || status.failure._tag !== "CommitPending") return yield* unavailable();
|
|
565
|
-
}
|
|
566
|
-
yield* database.$client.batch(statements).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => everyFailureMatches(cause, mutation?.retryable) ? unavailable() : error))), translateFailure);
|
|
567
|
-
return value;
|
|
568
|
-
}), { mode: "batch" }).pipe(Effect.provideService(LifecycleHooks, hooks))).value;
|
|
569
|
-
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
570
|
-
}
|
|
571
|
-
function coordinateD1EmailRegistration(acquire, options, body) {
|
|
572
|
-
return Effect.flatMap(nativeDatabase(acquire), (database) => Effect.gen(function* () {
|
|
573
|
-
yield* validateDrizzleStorage({
|
|
574
|
-
...options.mapping,
|
|
575
|
-
proof: options.proofMapping
|
|
576
|
-
}).pipe(Effect.mapError(unavailable));
|
|
577
|
-
const hooks = yield* LifecycleHooks;
|
|
578
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
579
|
-
return (yield* coordinateCommit(() => Effect.gen(function* () {
|
|
580
|
-
const statements = [];
|
|
581
|
-
let mutation;
|
|
582
|
-
const nativeCollector = D1BatchStatements.of({ append: (statement) => Effect.sync(() => statements.push(statement)) });
|
|
583
|
-
const owner = yield* makeD1Owner(unavailable()).pipe(Effect.provideService(D1BatchStatements, nativeCollector));
|
|
584
|
-
const plans = makeRegistrationPlans(options.mapping, options.proofMapping);
|
|
585
|
-
const run = (plan) => coordinateCommit(() => Effect.gen(function* () {
|
|
586
|
-
const journal = yield* CurrentCommitJournal;
|
|
587
|
-
const planned = yield* plan;
|
|
588
|
-
yield* owner.check;
|
|
589
|
-
if (mutation !== void 0) return yield* unavailable();
|
|
590
|
-
const guarded = {
|
|
591
|
-
...planned,
|
|
592
|
-
journalGuard: journal.prepare(void 0)
|
|
593
|
-
};
|
|
594
|
-
mutation = guarded;
|
|
595
|
-
statements.push(...guarded.statements);
|
|
596
|
-
return guarded.receipt;
|
|
597
|
-
}), { mode: "batch" }).pipe(Effect.map((result) => result.value), Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks));
|
|
598
|
-
const provided = Context.make(options.target, {
|
|
599
|
-
inspect: (input) => owner.run(plans.inspect(input).pipe(Effect.provideService(CurrentD1PlanningDatabase, database), Effect.provideService(CurrentEmailSql, database), Effect.provideService(LifecycleHooks, hooks), translateFailure)),
|
|
600
|
-
registerWithProof: (input, prepare) => owner.run(run(plans.registerWithProof(input, prepare)).pipe(translateFailure))
|
|
601
|
-
}).pipe(Context.add(D1BatchStatements, owner.collector));
|
|
602
|
-
const value = yield* owner.close(Effect.provideContext(body, provided));
|
|
603
|
-
if (mutation?.journalGuard !== void 0) {
|
|
604
|
-
const status = yield* Effect.result(mutation.journalGuard.read);
|
|
605
|
-
if (status._tag === "Success" || status.failure._tag !== "CommitPending") return yield* unavailable();
|
|
606
|
-
}
|
|
607
|
-
yield* database.$client.batch(statements).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => everyFailureMatches(cause, mutation?.retryable) ? unavailable() : error))), translateFailure);
|
|
608
|
-
return value;
|
|
609
|
-
}), { mode: "batch" }).pipe(Effect.provideService(LifecycleHooks, hooks))).value;
|
|
610
|
-
}).pipe(Effect.provideService(NativeDatabase, database)));
|
|
611
|
-
}
|
|
612
|
-
const translateFailure = (effect) => reportPersistenceFailure(effect, (error) => Schema.is(EmailUnavailable)(error) || Schema.is(ProofUnavailable)(error) || Schema.is(HookConfigurationError)(error)).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));
|
|
613
|
-
const executeStandalone = (plan, retries = 2) => Effect.suspend(() => {
|
|
614
|
-
let retryable;
|
|
615
|
-
return coordinateCommit(() => Effect.gen(function* () {
|
|
616
|
-
const database = yield* CurrentD1PlanningDatabase;
|
|
617
|
-
const planned = yield* plan;
|
|
618
|
-
retryable = planned.retryable;
|
|
619
|
-
yield* database.$client.batch(planned.statements);
|
|
620
|
-
return planned.receipt;
|
|
621
|
-
}), { mode: "batch" }).pipe(Effect.map((result) => result.value)).pipe(Effect.catchCause((cause) => retries > 0 && everyFailureMatches(cause, retryable) ? executeStandalone(plan, retries - 1) : Effect.failCause(cause)));
|
|
622
|
-
});
|
|
623
|
-
//#endregion
|
|
624
|
-
export { coordinateD1EmailAddress, coordinateD1EmailRegistration, makeD1EmailAddressServices, makeD1EmailRegistrationServices, makeD1EmailSignInServices };
|
|
625
|
-
|
|
626
|
-
//# sourceMappingURL=d1-emails.mjs.map
|