@yielded/auth-persistence 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 +6 -8
- package/dist/Adapter.d.mts +47 -33
- package/dist/Adapter.mjs +36 -23
- package/dist/OAuthPersistence.d.mts +35 -51
- package/dist/OAuthPersistence.mjs +60 -68
- package/dist/OAuthPersistence.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/internal/browser-login.d.mts +1 -1
- package/dist/internal/browser-login.mjs +29 -9
- package/dist/internal/browser-login.mjs.map +1 -1
- package/dist/internal/configuration.d.mts +13 -8
- package/dist/internal/configuration.mjs.map +1 -1
- package/dist/internal/crypto.d.mts +1 -0
- package/dist/internal/crypto.mjs +1 -1
- package/dist/internal/d1-planning.mjs +8 -0
- package/dist/internal/d1-planning.mjs.map +1 -0
- package/dist/internal/email-native-state.mjs +135 -0
- package/dist/internal/email-native-state.mjs.map +1 -0
- package/dist/internal/email-native.d.mts +17 -0
- package/dist/internal/email-native.mjs +245 -0
- package/dist/internal/email-native.mjs.map +1 -0
- package/dist/internal/email-policy.mjs +92 -0
- package/dist/internal/email-policy.mjs.map +1 -0
- package/dist/internal/email-registration-native.d.mts +38 -0
- package/dist/internal/email-registration-native.mjs +171 -0
- package/dist/internal/email-registration-native.mjs.map +1 -0
- package/dist/internal/models/email-model.d.mts +40 -104
- package/dist/internal/models/email-model.mjs +3 -5
- package/dist/internal/models/email-model.mjs.map +1 -1
- package/dist/internal/models/oauth-connected-model.d.mts +44 -213
- package/dist/internal/models/oauth-connected-model.mjs +6 -14
- package/dist/internal/models/oauth-connected-model.mjs.map +1 -1
- package/dist/internal/models/oauth-model.d.mts +95 -244
- package/dist/internal/models/oauth-model.mjs +28 -22
- package/dist/internal/models/oauth-model.mjs.map +1 -1
- package/dist/internal/models/passkey-model.d.mts +11 -147
- package/dist/internal/models/passkey-model.mjs +5 -24
- package/dist/internal/models/passkey-model.mjs.map +1 -1
- package/dist/internal/models/passkey-registration-ceremony-model.d.mts +5 -39
- package/dist/internal/models/passkey-write-model.d.mts +17 -75
- package/dist/internal/models/passkey-write-model.mjs +1 -7
- package/dist/internal/models/passkey-write-model.mjs.map +1 -1
- package/dist/internal/models/password-model.d.mts +16 -82
- package/dist/internal/models/password-model.mjs +1 -4
- package/dist/internal/models/password-model.mjs.map +1 -1
- package/dist/internal/models/phone-model.d.mts +86 -0
- package/dist/internal/models/phone-model.mjs +10 -0
- package/dist/internal/models/phone-model.mjs.map +1 -0
- package/dist/internal/models/proof-model.d.mts +43 -272
- package/dist/internal/models/proof-model.mjs +2 -10
- package/dist/internal/models/proof-model.mjs.map +1 -1
- package/dist/internal/models/session-model.d.mts +74 -93
- package/dist/internal/models/session-model.mjs +3 -11
- package/dist/internal/models/session-model.mjs.map +1 -1
- package/dist/internal/models/step-up-model.d.mts +12 -50
- package/dist/internal/models/step-up-model.mjs +2 -4
- package/dist/internal/models/step-up-model.mjs.map +1 -1
- package/dist/internal/models/totp-model.d.mts +76 -0
- package/dist/internal/models/totp-model.mjs +10 -0
- package/dist/internal/models/totp-model.mjs.map +1 -0
- package/dist/internal/native-sql-table.d.mts +21 -4
- package/dist/internal/native-sql-table.mjs +9 -5
- package/dist/internal/native-sql-table.mjs.map +1 -1
- package/dist/internal/oauth/native-accounts.d.mts +17 -0
- package/dist/internal/oauth/native-accounts.mjs +290 -0
- package/dist/internal/oauth/native-accounts.mjs.map +1 -0
- package/dist/internal/oauth/native-connected-state.d.mts +11 -0
- package/dist/internal/oauth/native-connected-state.mjs +146 -0
- package/dist/internal/oauth/native-connected-state.mjs.map +1 -0
- package/dist/internal/oauth/native-connected.d.mts +15 -0
- package/dist/internal/oauth/native-connected.mjs +462 -0
- package/dist/internal/oauth/native-connected.mjs.map +1 -0
- package/dist/internal/oauth/native-flow.mjs +138 -0
- package/dist/internal/oauth/native-flow.mjs.map +1 -0
- package/dist/internal/oauth/native-layers.d.mts +24 -0
- package/dist/internal/oauth/native-layers.mjs +13 -0
- package/dist/internal/oauth/native-layers.mjs.map +1 -0
- package/dist/internal/oauth/native-mutation.mjs +122 -0
- package/dist/internal/oauth/native-mutation.mjs.map +1 -0
- package/dist/internal/oauth/native-registration.d.mts +24 -0
- package/dist/internal/oauth/native-registration.mjs +328 -0
- package/dist/internal/oauth/native-registration.mjs.map +1 -0
- package/dist/internal/oauth/native-revocations.d.mts +17 -0
- package/dist/internal/oauth/native-revocations.mjs +106 -0
- package/dist/internal/oauth/native-revocations.mjs.map +1 -0
- package/dist/internal/oauth/native-sign-in.d.mts +17 -0
- package/dist/internal/oauth/native-sign-in.mjs +50 -0
- package/dist/internal/oauth/native-sign-in.mjs.map +1 -0
- package/dist/internal/oauth/native-state.d.mts +10 -0
- package/dist/internal/oauth/native-state.mjs +214 -0
- package/dist/internal/oauth/native-state.mjs.map +1 -0
- package/dist/internal/oauth/state.d.mts +10 -0
- package/dist/internal/oauth/state.mjs +3 -27
- package/dist/internal/oauth/state.mjs.map +1 -1
- package/dist/internal/passkey-actions.mjs +55 -0
- package/dist/internal/passkey-actions.mjs.map +1 -0
- package/dist/internal/passkey-inputs.mjs +73 -0
- package/dist/internal/passkey-inputs.mjs.map +1 -0
- package/dist/internal/passkey-managed.mjs +224 -0
- package/dist/internal/passkey-managed.mjs.map +1 -0
- package/dist/internal/passkey-native-ceremony.d.mts +35 -0
- package/dist/internal/passkey-native-ceremony.mjs +38 -0
- package/dist/internal/passkey-native-ceremony.mjs.map +1 -0
- package/dist/internal/passkey-native-flow.mjs +91 -0
- package/dist/internal/passkey-native-flow.mjs.map +1 -0
- package/dist/internal/passkey-native-registration.d.mts +10 -0
- package/dist/internal/passkey-native-registration.mjs +114 -0
- package/dist/internal/passkey-native-registration.mjs.map +1 -0
- package/dist/internal/passkey-native-state.d.mts +15 -0
- package/dist/internal/passkey-native-state.mjs +186 -0
- package/dist/internal/passkey-native-state.mjs.map +1 -0
- package/dist/internal/passkey-native-write.d.mts +82 -0
- package/dist/internal/passkey-native-write.mjs +330 -0
- package/dist/internal/passkey-native-write.mjs.map +1 -0
- package/dist/internal/passkey-native.d.mts +835 -0
- package/dist/internal/passkey-native.mjs +175 -0
- package/dist/internal/passkey-native.mjs.map +1 -0
- package/dist/internal/passkey-policy.mjs +115 -0
- package/dist/internal/passkey-policy.mjs.map +1 -0
- package/dist/internal/password-credentials.mjs +38 -9
- package/dist/internal/password-credentials.mjs.map +1 -1
- package/dist/internal/password-native.d.mts +14 -0
- package/dist/internal/password-native.mjs +292 -0
- package/dist/internal/password-native.mjs.map +1 -0
- package/dist/internal/password-policy.mjs +93 -0
- package/dist/internal/password-policy.mjs.map +1 -0
- package/dist/internal/password-registration-native.d.mts +22 -0
- package/dist/internal/password-registration-native.mjs +142 -0
- package/dist/internal/password-registration-native.mjs.map +1 -0
- package/dist/internal/persistence.d.mts +6 -19
- package/dist/internal/persistence.mjs +199 -166
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/phone-composed.mjs +79 -0
- package/dist/internal/phone-composed.mjs.map +1 -0
- package/dist/internal/phone-native.d.mts +15 -0
- package/dist/internal/phone-native.mjs +354 -0
- package/dist/internal/phone-native.mjs.map +1 -0
- package/dist/internal/proof-native.d.mts +15 -0
- package/dist/internal/proof-native.mjs +289 -0
- package/dist/internal/proof-native.mjs.map +1 -0
- package/dist/internal/registration.mjs +50 -60
- package/dist/internal/registration.mjs.map +1 -1
- package/dist/internal/session-native-authority.d.mts +15 -0
- package/dist/internal/session-native-authority.mjs +91 -0
- package/dist/internal/session-native-authority.mjs.map +1 -0
- package/dist/internal/session-native-cleanup.d.mts +14 -0
- package/dist/internal/session-native-cleanup.mjs +48 -0
- package/dist/internal/session-native-cleanup.mjs.map +1 -0
- package/dist/internal/session-native-login.d.mts +15 -0
- package/dist/internal/session-native-login.mjs +87 -0
- package/dist/internal/session-native-login.mjs.map +1 -0
- package/dist/internal/session-native-pending-read.mjs +42 -0
- package/dist/internal/session-native-pending-read.mjs.map +1 -0
- package/dist/internal/session-native-pending.mjs +134 -0
- package/dist/internal/session-native-pending.mjs.map +1 -0
- package/dist/internal/session-native-record.mjs +79 -0
- package/dist/internal/session-native-record.mjs.map +1 -0
- package/dist/internal/session-native-state.mjs +130 -0
- package/dist/internal/session-native-state.mjs.map +1 -0
- package/dist/internal/session-native-stateful.d.mts +16 -0
- package/dist/internal/session-native-stateful.mjs +225 -0
- package/dist/internal/session-native-stateful.mjs.map +1 -0
- package/dist/internal/session-native-step-up.d.mts +15 -0
- package/dist/internal/session-native-step-up.mjs +212 -0
- package/dist/internal/session-native-step-up.mjs.map +1 -0
- package/dist/internal/session-native-validity.d.mts +15 -0
- package/dist/internal/session-native-validity.mjs +97 -0
- package/dist/internal/session-native-validity.mjs.map +1 -0
- package/dist/internal/session-policy.mjs +29 -0
- package/dist/internal/session-policy.mjs.map +1 -0
- package/dist/internal/sql-authority.d.mts +16 -0
- package/dist/internal/sql-authority.mjs +32 -0
- package/dist/internal/sql-authority.mjs.map +1 -0
- package/dist/internal/sql-change.mjs +21 -0
- package/dist/internal/sql-change.mjs.map +1 -0
- package/dist/internal/sql-cleanup.mjs +35 -0
- package/dist/internal/sql-cleanup.mjs.map +1 -0
- package/dist/internal/sql-commit.d.mts +72 -0
- package/dist/internal/sql-commit.mjs +176 -0
- package/dist/internal/sql-commit.mjs.map +1 -0
- package/dist/internal/sql-expression.d.mts +17 -0
- package/dist/internal/sql-expression.mjs +49 -0
- package/dist/internal/sql-expression.mjs.map +1 -0
- package/dist/internal/sql-oauth-connected-model.d.mts +7 -23
- package/dist/internal/sql-oauth-model.d.mts +27 -52
- package/dist/internal/sql-oauth-model.mjs +3 -4
- package/dist/internal/sql-oauth-model.mjs.map +1 -1
- package/dist/internal/sql-persistence.mjs +5 -9
- package/dist/internal/sql-persistence.mjs.map +1 -1
- package/dist/internal/sql-storage-validation.mjs +1 -2
- package/dist/internal/sql-storage-validation.mjs.map +1 -1
- package/dist/internal/sql-table.d.mts +3 -16
- package/dist/internal/sql-table.mjs +21 -42
- package/dist/internal/sql-table.mjs.map +1 -1
- package/dist/internal/standalone.mjs +2 -3
- package/dist/internal/standalone.mjs.map +1 -1
- package/dist/internal/step-up-state.mjs +5 -8
- package/dist/internal/step-up-state.mjs.map +1 -1
- package/dist/internal/storage-clock.mjs +44 -0
- package/dist/internal/storage-clock.mjs.map +1 -0
- package/dist/internal/storage-mapping.d.mts +11 -8
- package/dist/internal/storage-mapping.mjs +88 -302
- package/dist/internal/storage-mapping.mjs.map +1 -1
- package/dist/internal/storage-plans.mjs +15 -73
- package/dist/internal/storage-plans.mjs.map +1 -1
- package/dist/internal/storage-tables.d.mts +37 -520
- package/dist/internal/storage-tables.mjs +31 -211
- package/dist/internal/storage-tables.mjs.map +1 -1
- package/dist/internal/storage-validation.d.mts +1 -6
- package/dist/internal/storage-validation.mjs +1 -42
- package/dist/internal/storage-validation.mjs.map +1 -1
- package/dist/internal/table-model.d.mts +21 -0
- package/dist/internal/totp-native.d.mts +15 -0
- package/dist/internal/totp-native.mjs +401 -0
- package/dist/internal/totp-native.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Adapter.ts +143 -199
- package/src/OAuthPersistence.ts +128 -271
- package/src/index.ts +1 -1
- package/src/internal/browser-login.ts +54 -24
- package/src/internal/configuration.ts +16 -31
- package/src/internal/d1-planning.ts +7 -0
- package/src/internal/email-native-state.ts +247 -0
- package/src/internal/email-native.ts +514 -0
- package/src/internal/email-policy.ts +235 -0
- package/src/internal/email-registration-native.ts +386 -0
- package/src/internal/models/email-model.ts +76 -214
- package/src/internal/models/oauth-connected-model.ts +50 -288
- package/src/internal/models/oauth-model.ts +147 -368
- package/src/internal/models/passkey-model.ts +11 -208
- package/src/internal/models/passkey-registration-ceremony-model.ts +6 -60
- package/src/internal/models/passkey-write-model.ts +14 -95
- package/src/internal/models/password-model.ts +28 -148
- package/src/internal/models/phone-model.ts +110 -0
- package/src/internal/models/proof-model.ts +48 -404
- package/src/internal/models/session-model.ts +102 -200
- package/src/internal/models/step-up-model.ts +17 -96
- package/src/internal/models/totp-model.ts +82 -0
- package/src/internal/native-sql-table.ts +32 -11
- package/src/internal/oauth/native-accounts.ts +576 -0
- package/src/internal/oauth/native-connected-state.ts +288 -0
- package/src/internal/oauth/native-connected.ts +888 -0
- package/src/internal/oauth/native-flow.ts +253 -0
- package/src/internal/oauth/native-layers.ts +83 -0
- package/src/internal/oauth/native-mutation.ts +222 -0
- package/src/internal/oauth/native-registration.ts +545 -0
- package/src/internal/oauth/native-revocations.ts +190 -0
- package/src/internal/oauth/native-sign-in.ts +111 -0
- package/src/internal/oauth/native-state.ts +346 -0
- package/src/internal/oauth/state.ts +2 -70
- package/src/internal/passkey-actions.ts +70 -0
- package/src/internal/passkey-inputs.ts +56 -0
- package/src/internal/passkey-managed.ts +360 -0
- package/src/internal/passkey-native-ceremony.ts +66 -0
- package/src/internal/passkey-native-flow.ts +140 -0
- package/src/internal/passkey-native-registration.ts +221 -0
- package/src/internal/passkey-native-state.ts +335 -0
- package/src/internal/passkey-native-write.ts +611 -0
- package/src/internal/passkey-native.ts +372 -0
- package/src/internal/passkey-policy.ts +246 -0
- package/src/internal/password-credentials.ts +52 -10
- package/src/internal/password-native.ts +571 -0
- package/src/internal/password-policy.ts +307 -0
- package/src/internal/password-registration-native.ts +322 -0
- package/src/internal/persistence.ts +336 -290
- package/src/internal/phone-composed.ts +86 -0
- package/src/internal/phone-native.ts +659 -0
- package/src/internal/proof-native.ts +448 -0
- package/src/internal/registration.ts +96 -143
- package/src/internal/session-native-authority.ts +247 -0
- package/src/internal/session-native-cleanup.ts +65 -0
- package/src/internal/session-native-login.ts +205 -0
- package/src/internal/session-native-pending-read.ts +68 -0
- package/src/internal/session-native-pending.ts +223 -0
- package/src/internal/session-native-record.ts +141 -0
- package/src/internal/session-native-state.ts +259 -0
- package/src/internal/session-native-stateful.ts +512 -0
- package/src/internal/session-native-step-up.ts +450 -0
- package/src/internal/session-native-validity.ts +208 -0
- package/src/internal/session-policy.ts +59 -0
- package/src/internal/sql-authority.ts +56 -0
- package/src/internal/sql-change.ts +38 -0
- package/src/internal/sql-cleanup.ts +56 -0
- package/src/internal/sql-commit.ts +435 -0
- package/src/internal/sql-expression.ts +94 -0
- package/src/internal/sql-metadata.ts +100 -0
- package/src/internal/sql-oauth-connected-model.ts +6 -95
- package/src/internal/sql-oauth-model.ts +31 -134
- package/src/internal/sql-persistence.ts +2 -6
- package/src/internal/sql-storage-validation.ts +1 -2
- package/src/internal/sql-table.ts +19 -52
- package/src/internal/standalone.ts +2 -11
- package/src/internal/step-up-state.ts +4 -17
- package/src/internal/storage-clock.ts +58 -0
- package/src/internal/storage-mapping.ts +125 -340
- package/src/internal/storage-plans.ts +14 -80
- package/src/internal/storage-tables.ts +28 -212
- package/src/internal/storage-validation.ts +0 -58
- package/src/internal/table-model.ts +24 -0
- package/src/internal/totp-native.ts +701 -0
- package/dist/internal/PasswordPreparedPostconditions.d.mts +0 -22
- package/dist/internal/PasswordPreparedPostconditions.mjs +0 -12
- package/dist/internal/PasswordPreparedPostconditions.mjs.map +0 -1
- package/dist/internal/authority-snapshot.mjs +0 -53
- package/dist/internal/authority-snapshot.mjs.map +0 -1
- package/dist/internal/email-kernel.d.mts +0 -276
- package/dist/internal/email-kernel.mjs +0 -497
- package/dist/internal/email-kernel.mjs.map +0 -1
- package/dist/internal/models/passkey-registration-ceremony-model.mjs +0 -18
- package/dist/internal/models/passkey-registration-ceremony-model.mjs.map +0 -1
- package/dist/internal/oauth/accounts.d.mts +0 -8
- package/dist/internal/oauth/accounts.mjs +0 -379
- package/dist/internal/oauth/accounts.mjs.map +0 -1
- package/dist/internal/oauth/connected-access.d.mts +0 -9
- package/dist/internal/oauth/connected-access.mjs +0 -229
- package/dist/internal/oauth/connected-access.mjs.map +0 -1
- package/dist/internal/oauth/connected-collection.d.mts +0 -7
- package/dist/internal/oauth/connected-collection.mjs +0 -214
- package/dist/internal/oauth/connected-collection.mjs.map +0 -1
- package/dist/internal/oauth/connected-custody.d.mts +0 -6
- package/dist/internal/oauth/connected-custody.mjs +0 -165
- package/dist/internal/oauth/connected-custody.mjs.map +0 -1
- package/dist/internal/oauth/connected-flow.d.mts +0 -7
- package/dist/internal/oauth/connected-flow.mjs +0 -324
- package/dist/internal/oauth/connected-flow.mjs.map +0 -1
- package/dist/internal/oauth/connected-input.mjs +0 -122
- package/dist/internal/oauth/connected-input.mjs.map +0 -1
- package/dist/internal/oauth/connected-keys.d.mts +0 -2
- package/dist/internal/oauth/connected-keys.mjs +0 -22
- package/dist/internal/oauth/connected-keys.mjs.map +0 -1
- package/dist/internal/oauth/connected-maintenance.d.mts +0 -9
- package/dist/internal/oauth/connected-maintenance.mjs +0 -226
- package/dist/internal/oauth/connected-maintenance.mjs.map +0 -1
- package/dist/internal/oauth/connected-management.d.mts +0 -9
- package/dist/internal/oauth/connected-management.mjs +0 -243
- package/dist/internal/oauth/connected-management.mjs.map +0 -1
- package/dist/internal/oauth/connected-reference.mjs +0 -63
- package/dist/internal/oauth/connected-reference.mjs.map +0 -1
- package/dist/internal/oauth/connected-settlement.d.mts +0 -8
- package/dist/internal/oauth/connected-settlement.mjs +0 -141
- package/dist/internal/oauth/connected-settlement.mjs.map +0 -1
- package/dist/internal/oauth/connected-sign-in.d.mts +0 -10
- package/dist/internal/oauth/connected-sign-in.mjs +0 -281
- package/dist/internal/oauth/connected-sign-in.mjs.map +0 -1
- package/dist/internal/oauth/connected-state.d.mts +0 -14
- package/dist/internal/oauth/connected-state.mjs +0 -469
- package/dist/internal/oauth/connected-state.mjs.map +0 -1
- package/dist/internal/oauth/connected-target.d.mts +0 -21
- package/dist/internal/oauth/connected-target.mjs +0 -117
- package/dist/internal/oauth/connected-target.mjs.map +0 -1
- package/dist/internal/oauth/flow.d.mts +0 -5
- package/dist/internal/oauth/flow.mjs +0 -279
- package/dist/internal/oauth/flow.mjs.map +0 -1
- package/dist/internal/oauth/input.mjs +0 -127
- package/dist/internal/oauth/input.mjs.map +0 -1
- package/dist/internal/oauth/owner.d.mts +0 -10
- package/dist/internal/oauth/owner.mjs +0 -10
- package/dist/internal/oauth/owner.mjs.map +0 -1
- package/dist/internal/oauth/query-compiler.d.mts +0 -7
- package/dist/internal/oauth/query-compiler.mjs +0 -9
- package/dist/internal/oauth/query-compiler.mjs.map +0 -1
- package/dist/internal/oauth/registration.d.mts +0 -7
- package/dist/internal/oauth/registration.mjs +0 -393
- package/dist/internal/oauth/registration.mjs.map +0 -1
- package/dist/internal/oauth/target.d.mts +0 -31
- package/dist/internal/oauth/target.mjs +0 -273
- package/dist/internal/oauth/target.mjs.map +0 -1
- package/dist/internal/oauth-kernel.d.mts +0 -1423
- package/dist/internal/oauth-kernel.mjs +0 -187
- package/dist/internal/oauth-kernel.mjs.map +0 -1
- package/dist/internal/passkey/admission.d.mts +0 -6
- package/dist/internal/passkey/admission.mjs +0 -220
- package/dist/internal/passkey/admission.mjs.map +0 -1
- package/dist/internal/passkey/credentials.d.mts +0 -14
- package/dist/internal/passkey/credentials.mjs +0 -249
- package/dist/internal/passkey/credentials.mjs.map +0 -1
- package/dist/internal/passkey/enrollment.mjs +0 -138
- package/dist/internal/passkey/enrollment.mjs.map +0 -1
- package/dist/internal/passkey/flow.d.mts +0 -21
- package/dist/internal/passkey/flow.mjs +0 -452
- package/dist/internal/passkey/flow.mjs.map +0 -1
- package/dist/internal/passkey/management.mjs +0 -231
- package/dist/internal/passkey/management.mjs.map +0 -1
- package/dist/internal/passkey/registration-ceremony.d.mts +0 -9
- package/dist/internal/passkey/registration-ceremony.mjs +0 -129
- package/dist/internal/passkey/registration-ceremony.mjs.map +0 -1
- package/dist/internal/passkey/registration-custody.d.mts +0 -2
- package/dist/internal/passkey/registration-custody.mjs +0 -52
- package/dist/internal/passkey/registration-custody.mjs.map +0 -1
- package/dist/internal/passkey/registration-write.mjs +0 -211
- package/dist/internal/passkey/registration-write.mjs.map +0 -1
- package/dist/internal/passkey/state.d.mts +0 -10
- package/dist/internal/passkey/state.mjs +0 -234
- package/dist/internal/passkey/state.mjs.map +0 -1
- package/dist/internal/passkey/target.d.mts +0 -20
- package/dist/internal/passkey/target.mjs +0 -200
- package/dist/internal/passkey/target.mjs.map +0 -1
- package/dist/internal/passkey/write-state.d.mts +0 -17
- package/dist/internal/passkey/write-state.mjs +0 -346
- package/dist/internal/passkey/write-state.mjs.map +0 -1
- package/dist/internal/passkey/write-target.mjs +0 -192
- package/dist/internal/passkey/write-target.mjs.map +0 -1
- package/dist/internal/passkey-kernel.d.mts +0 -6045
- package/dist/internal/passkey-kernel.mjs +0 -49
- package/dist/internal/passkey-kernel.mjs.map +0 -1
- package/dist/internal/passkeys.d.mts +0 -7
- package/dist/internal/passkeys.mjs +0 -387
- package/dist/internal/passkeys.mjs.map +0 -1
- package/dist/internal/password-credentials.d.mts +0 -11
- package/dist/internal/password-kernel.d.mts +0 -278
- package/dist/internal/password-kernel.mjs +0 -508
- package/dist/internal/password-kernel.mjs.map +0 -1
- package/dist/internal/phone-kernel.d.mts +0 -162
- package/dist/internal/phone-kernel.mjs +0 -437
- package/dist/internal/phone-kernel.mjs.map +0 -1
- package/dist/internal/proof-kernel.d.mts +0 -94
- package/dist/internal/proof-kernel.mjs +0 -624
- package/dist/internal/proof-kernel.mjs.map +0 -1
- package/dist/internal/query-operations.d.mts +0 -68
- package/dist/internal/session-kernel.d.mts +0 -62
- package/dist/internal/session-kernel.mjs +0 -820
- package/dist/internal/session-kernel.mjs.map +0 -1
- package/dist/internal/sql-oauth-connected-model.mjs +0 -7
- package/dist/internal/sql-oauth-connected-model.mjs.map +0 -1
- package/dist/internal/sql-query.d.mts +0 -12
- package/dist/internal/sql-query.mjs +0 -206
- package/dist/internal/sql-query.mjs.map +0 -1
- package/dist/internal/step-up-state.d.mts +0 -49
- package/dist/internal/transaction-execution-kernel.d.mts +0 -37
- package/dist/internal/transaction-execution-kernel.mjs +0 -120
- package/dist/internal/transaction-execution-kernel.mjs.map +0 -1
- package/dist/internal/transaction-kernel.d.mts +0 -81
- package/dist/internal/transaction-kernel.mjs +0 -264
- package/dist/internal/transaction-kernel.mjs.map +0 -1
- package/src/internal/PasswordPreparedPostconditions.ts +0 -30
- package/src/internal/authority-snapshot.ts +0 -91
- package/src/internal/email-kernel.ts +0 -1555
- package/src/internal/oauth/accounts.ts +0 -838
- package/src/internal/oauth/connected-access.ts +0 -388
- package/src/internal/oauth/connected-collection.ts +0 -345
- package/src/internal/oauth/connected-custody.ts +0 -308
- package/src/internal/oauth/connected-flow.ts +0 -562
- package/src/internal/oauth/connected-input.ts +0 -147
- package/src/internal/oauth/connected-keys.ts +0 -31
- package/src/internal/oauth/connected-maintenance.ts +0 -379
- package/src/internal/oauth/connected-management.ts +0 -391
- package/src/internal/oauth/connected-reference.ts +0 -135
- package/src/internal/oauth/connected-settlement.ts +0 -278
- package/src/internal/oauth/connected-sign-in.ts +0 -472
- package/src/internal/oauth/connected-state.ts +0 -924
- package/src/internal/oauth/connected-target.ts +0 -307
- package/src/internal/oauth/flow.ts +0 -505
- package/src/internal/oauth/input.ts +0 -201
- package/src/internal/oauth/owner.ts +0 -22
- package/src/internal/oauth/query-compiler.ts +0 -15
- package/src/internal/oauth/registration.ts +0 -676
- package/src/internal/oauth/target.ts +0 -803
- package/src/internal/oauth-kernel.ts +0 -294
- package/src/internal/passkey/admission.ts +0 -368
- package/src/internal/passkey/credentials.ts +0 -511
- package/src/internal/passkey/enrollment.ts +0 -326
- package/src/internal/passkey/flow.ts +0 -1062
- package/src/internal/passkey/management.ts +0 -426
- package/src/internal/passkey/registration-ceremony.ts +0 -283
- package/src/internal/passkey/registration-custody.ts +0 -91
- package/src/internal/passkey/registration-write.ts +0 -426
- package/src/internal/passkey/state.ts +0 -351
- package/src/internal/passkey/target.ts +0 -598
- package/src/internal/passkey/write-state.ts +0 -678
- package/src/internal/passkey/write-target.ts +0 -450
- package/src/internal/passkey-kernel.ts +0 -112
- package/src/internal/passkeys.ts +0 -652
- package/src/internal/password-kernel.ts +0 -1522
- package/src/internal/phone-kernel.ts +0 -872
- package/src/internal/proof-kernel.ts +0 -1992
- package/src/internal/query-operations.ts +0 -91
- package/src/internal/session-kernel.ts +0 -2406
- package/src/internal/sql-query.ts +0 -304
- package/src/internal/transaction-execution-kernel.ts +0 -335
- package/src/internal/transaction-kernel.ts +0 -603
|
@@ -1,820 +0,0 @@
|
|
|
1
|
-
import { PersistenceMappingError, isMappedConstraintConflict } from "./mapping-error.mjs";
|
|
2
|
-
import { makeNativeSqlTables, sqlMapping } from "./native-sql-table.mjs";
|
|
3
|
-
import { NativeDatabase } from "./transaction-kernel.mjs";
|
|
4
|
-
import { makeAuthoritySnapshot } from "./authority-snapshot.mjs";
|
|
5
|
-
import { decodeStepUpIntent, encodeStepUpIntent, sameStepUpRevision, stepUpIntentLive, stepUpRotationMatches, validateStepUpPlan } from "./step-up-state.mjs";
|
|
6
|
-
import { canJoinTextColumns } from "./storage-validation.mjs";
|
|
7
|
-
import { Cause, Context, DateTime, Effect, Option, Schema } from "effect";
|
|
8
|
-
import { CurrentCommitJournal, LifecycleHooks, coordinateCommit, hasCommitScope } from "@yielded/auth/Hooks";
|
|
9
|
-
import { AuthenticationCapture, PendingAuthenticationInvalid, SessionConflict, SessionInvalid, SessionMetadata, SessionStepUpInvalid, SessionUnavailable, StaleAuthentication, assessAuthentication, pendingAuthenticationContext, snapshotPendingAuthenticationContext, snapshotSessionAuthenticationProvenance } from "@yielded/auth/Sessions";
|
|
10
|
-
import { reportPersistenceFailure } from "@yielded/auth/Persistence";
|
|
11
|
-
//#region src/internal/session-kernel.ts
|
|
12
|
-
const decodeRevocationFlag = Schema.decodeUnknownEffect(Schema.Literals([0, 1]));
|
|
13
|
-
/** Reads need no transaction of their own. A caller-owned transaction still
|
|
14
|
-
* needs a savepoint so catching an SQL failure does not leave it aborted. */
|
|
15
|
-
const withVerificationSavepoint = Effect.fnUntraced(function* (effect) {
|
|
16
|
-
const { $client } = yield* NativeDatabase;
|
|
17
|
-
const transaction = yield* Effect.serviceOption($client.transactionService);
|
|
18
|
-
return yield* Option.isSome(transaction) ? $client.withTransaction(effect) : effect;
|
|
19
|
-
});
|
|
20
|
-
/** Native SQL authority for the current transaction or savepoint. */
|
|
21
|
-
var CurrentSessionSql = class extends Context.Service()("effect-auth/drizzle/CurrentSessionSql") {};
|
|
22
|
-
const makeSessionKernel = (operations, nativeTables = (client) => makeNativeSqlTables(client)) => {
|
|
23
|
-
const { and, eq, gt, lte, inArray, or, sql, column, updateValues } = operations;
|
|
24
|
-
const unavailable = () => SessionUnavailable.make({});
|
|
25
|
-
const stale = () => StaleAuthentication.make({});
|
|
26
|
-
const invalidPending = () => PendingAuthenticationInvalid.make({});
|
|
27
|
-
const invalidSession = () => SessionInvalid.make({});
|
|
28
|
-
const mapFailureCause = (effect, map) => Effect.catchCause(effect, (cause) => Effect.failCause(Cause.map(cause, map)));
|
|
29
|
-
const isExpectedMutationError = (error) => {
|
|
30
|
-
const tag = typeof error === "object" && error !== null ? Reflect.get(error, "_tag") : void 0;
|
|
31
|
-
return tag === "SessionStepUpInvalid" || tag === "StaleAuthentication" || tag === "PendingAuthenticationInvalid" || tag === "SessionConflict" || tag === "SessionInvalid" || tag === "SessionUnavailable";
|
|
32
|
-
};
|
|
33
|
-
const normalizeMutation = (mapping) => (effect) => effect.pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => isMappedConstraintConflict(mapping.isConstraintConflict, error) ? SessionConflict.make({}) : error))));
|
|
34
|
-
const safeTransaction = (effect) => reportPersistenceFailure(effect, isExpectedMutationError).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => isExpectedMutationError(error) ? error : unavailable()))));
|
|
35
|
-
const selectRows = (query, locking) => locking && typeof query.for === "function" ? query.for("update") : query;
|
|
36
|
-
const inTransaction = (database, effect) => Effect.suspend(() => database.transaction((current) => effect.pipe(Effect.provideService(CurrentSessionSql, current))));
|
|
37
|
-
const owned = (database, options, isConstraintConflict, body) => {
|
|
38
|
-
const run = coordinateCommit(() => database.transaction((current) => body.pipe(Effect.provideService(CurrentSessionSql, current))), { mode: options.mode }).pipe((effect) => reportPersistenceFailure(effect, (error) => isExpectedMutationError(error) || isMappedConstraintConflict(isConstraintConflict, error)), Effect.map((result) => result.value), Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (error) => isExpectedMutationError(error) ? error : unavailable()))));
|
|
39
|
-
return Effect.gen(function* () {
|
|
40
|
-
const current = yield* Effect.serviceOption(CurrentSessionSql);
|
|
41
|
-
if (!(Option.isSome(current) && current.value === database)) {
|
|
42
|
-
if (yield* hasCommitScope) return yield* unavailable();
|
|
43
|
-
yield* options.standaloneGuard;
|
|
44
|
-
}
|
|
45
|
-
return yield* run;
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
const uniqueStrings = (values) => [...new Set(values)].sort();
|
|
49
|
-
const preservesRevision = (completed, original) => {
|
|
50
|
-
const current = new Map(completed.revision.credentials.map((item) => [item.credentialId, item.revision]));
|
|
51
|
-
return completed.flowId === original.flowId && completed.bindingDigest === original.bindingDigest && completed.revision.subjectId === original.revision.subjectId && completed.revision.securityRevision === original.revision.securityRevision && original.revision.credentials.every((item) => current.get(item.credentialId) === item.revision) && original.proofs.every((expected) => completed.proofs.some((proof) => proof.method === expected.method && proof.credentialId === expected.credentialId && proof.userVerified === expected.userVerified && proof.phishingResistant === expected.phishingResistant && DateTime.toEpochMillis(proof.verifiedAt) === DateTime.toEpochMillis(expected.verifiedAt) && proof.factors.length === expected.factors.length && proof.factors.every((factor, index) => factor === expected.factors[index])));
|
|
52
|
-
};
|
|
53
|
-
const authorityColumns = (mapping) => ({
|
|
54
|
-
subjectId: column(mapping.subject.table, mapping.subject.id),
|
|
55
|
-
subjectStatus: column(mapping.subject.table, mapping.subject.status),
|
|
56
|
-
subjectRevision: column(mapping.subject.table, mapping.subject.securityRevision),
|
|
57
|
-
credentialSubjectId: column(mapping.credential.table, mapping.credential.subjectId),
|
|
58
|
-
credentialId: column(mapping.credential.table, mapping.credential.credentialId),
|
|
59
|
-
credentialRevision: column(mapping.credential.table, mapping.credential.revision),
|
|
60
|
-
...mapping.credential.status === void 0 ? {} : { credentialStatus: column(mapping.credential.table, mapping.credential.status) }
|
|
61
|
-
});
|
|
62
|
-
const subjectColumns = (mapping) => ({
|
|
63
|
-
subjectId: column(mapping.subject.table, mapping.subject.id),
|
|
64
|
-
subjectStatus: column(mapping.subject.table, mapping.subject.status),
|
|
65
|
-
subjectRevision: column(mapping.subject.table, mapping.subject.securityRevision)
|
|
66
|
-
});
|
|
67
|
-
const readSubject = Effect.fn("DrizzleSession.readSubject")(function* (mapping, nativeSubjectId, locking) {
|
|
68
|
-
const database = yield* CurrentSessionSql;
|
|
69
|
-
const columns = subjectColumns(mapping);
|
|
70
|
-
return yield* selectRows(database.select().from(mapping.subject.table).where(eq(columns.subjectId, nativeSubjectId)).limit(1), locking);
|
|
71
|
-
});
|
|
72
|
-
const captureDetailsIn = Effect.fn("DrizzleSession.captureDetails")(function* (mapping, subjectId, credentialIds, locking) {
|
|
73
|
-
const database = yield* CurrentSessionSql;
|
|
74
|
-
const requested = uniqueStrings(credentialIds);
|
|
75
|
-
if (requested.length !== credentialIds.length) return yield* stale();
|
|
76
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(subjectId);
|
|
77
|
-
const subject = (yield* readSubject(mapping, nativeSubjectId, locking))[0];
|
|
78
|
-
const columns = authorityColumns(mapping);
|
|
79
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status])) return yield* stale();
|
|
80
|
-
const query = database.select().from(mapping.credential.table).where(and(eq(columns.credentialSubjectId, nativeSubjectId), requested.length === 0 ? sql`false` : inArray(columns.credentialId, requested))).orderBy(columns.credentialId);
|
|
81
|
-
const credentialRows = requested.length === 0 ? [] : yield* selectRows(query, locking);
|
|
82
|
-
if (credentialRows.length !== requested.length) return yield* stale();
|
|
83
|
-
const credentials = credentialRows.map((row) => ({
|
|
84
|
-
credentialId: row[mapping.credential.credentialId],
|
|
85
|
-
revision: row[mapping.credential.revision],
|
|
86
|
-
active: mapping.credential.status === void 0 || mapping.credential.isActiveStatus?.(row[mapping.credential.status]) === true
|
|
87
|
-
})).sort((left, right) => left.credentialId.localeCompare(right.credentialId));
|
|
88
|
-
if (credentials.some((item) => !item.active)) return yield* stale();
|
|
89
|
-
return {
|
|
90
|
-
subject,
|
|
91
|
-
revision: {
|
|
92
|
-
subjectId,
|
|
93
|
-
securityRevision: subject[mapping.subject.securityRevision],
|
|
94
|
-
credentials: credentials.map(({ credentialId, revision }) => ({
|
|
95
|
-
credentialId,
|
|
96
|
-
revision
|
|
97
|
-
}))
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
const validateEvidenceIn = Effect.fn("DrizzleSession.validateEvidence")(function* (mapping, evidence, locking) {
|
|
102
|
-
const captured = yield* captureDetailsIn(mapping, evidence.revision.subjectId, evidence.revision.credentials.map((item) => item.credentialId), locking);
|
|
103
|
-
return yield* validateCapturedEvidence(mapping, evidence, captured);
|
|
104
|
-
});
|
|
105
|
-
const validateCapturedEvidence = Effect.fnUntraced(function* (mapping, evidence, captured) {
|
|
106
|
-
if (captured.revision.securityRevision !== evidence.revision.securityRevision || captured.revision.credentials.length !== evidence.revision.credentials.length || captured.revision.credentials.some((item, index) => {
|
|
107
|
-
const expected = [...evidence.revision.credentials].sort((a, b) => a.credentialId.localeCompare(b.credentialId))[index];
|
|
108
|
-
return expected === void 0 || expected.credentialId !== item.credentialId || expected.revision !== item.revision;
|
|
109
|
-
})) return yield* stale();
|
|
110
|
-
return {
|
|
111
|
-
nativeSubjectId: yield* mapping.subjectId.toNative(evidence.revision.subjectId),
|
|
112
|
-
requirement: yield* mapping.subject.decodeRequirement(captured.subject)
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
const flowColumns = (mapping) => ({
|
|
116
|
-
flowId: column(mapping.flow.table, mapping.flow.flowId),
|
|
117
|
-
subjectId: column(mapping.flow.table, mapping.flow.subjectId),
|
|
118
|
-
state: column(mapping.flow.table, mapping.flow.state),
|
|
119
|
-
pendingDigest: column(mapping.flow.table, mapping.flow.pendingDigest),
|
|
120
|
-
dedupUntil: column(mapping.flow.table, mapping.flow.dedupUntil)
|
|
121
|
-
});
|
|
122
|
-
const readFlow = Effect.fn("DrizzleSession.readFlow")(function* (mapping, flowId, locking) {
|
|
123
|
-
const database = yield* CurrentSessionSql;
|
|
124
|
-
const columns = flowColumns(mapping);
|
|
125
|
-
return yield* selectRows(database.select().from(mapping.flow.table).where(eq(columns.flowId, flowId)).limit(1), locking);
|
|
126
|
-
});
|
|
127
|
-
const ensureDirectFlowAvailable = Effect.fn("DrizzleSession.ensureFlowAvailable")(function* (mapping, evidence, nativeSubjectId, dedupUntil) {
|
|
128
|
-
const database = yield* CurrentSessionSql;
|
|
129
|
-
const existing = (yield* readFlow(mapping, evidence.flowId, true))[0];
|
|
130
|
-
if (existing !== void 0) {
|
|
131
|
-
const now = yield* freshNow;
|
|
132
|
-
if (DateTime.toEpochMillis(now) < DateTime.toEpochMillis(yield* mapping.flow.decodeInstant(existing[mapping.flow.dedupUntil]))) return yield* SessionConflict.make({});
|
|
133
|
-
if (mapping.pending !== void 0) yield* database.delete(mapping.pending.table).where(eq(column(mapping.pending.table, mapping.pending.flowId), evidence.flowId));
|
|
134
|
-
yield* database.delete(mapping.flow.table).where(eq(flowColumns(mapping).flowId, evidence.flowId));
|
|
135
|
-
}
|
|
136
|
-
return mapping.flow.encodeEstablishedInsert({
|
|
137
|
-
evidence,
|
|
138
|
-
subjectId: nativeSubjectId,
|
|
139
|
-
dedupUntil
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
const pendingColumns = (mapping) => ({
|
|
143
|
-
digest: column(mapping.pending.table, mapping.pending.digest),
|
|
144
|
-
version: column(mapping.pending.table, mapping.pending.version),
|
|
145
|
-
flowId: column(mapping.pending.table, mapping.pending.flowId),
|
|
146
|
-
subjectId: column(mapping.pending.table, mapping.pending.subjectId),
|
|
147
|
-
bindingDigest: column(mapping.pending.table, mapping.pending.bindingDigest),
|
|
148
|
-
expiresAt: column(mapping.pending.table, mapping.pending.expiresAt),
|
|
149
|
-
attemptLimit: column(mapping.pending.table, mapping.pending.attemptLimit),
|
|
150
|
-
failedAttempts: column(mapping.pending.table, mapping.pending.failedAttempts),
|
|
151
|
-
consumed: column(mapping.pending.table, mapping.pending.consumed)
|
|
152
|
-
});
|
|
153
|
-
const readPending = Effect.fn("DrizzleSession.readPending")(function* (mapping, digest, locking) {
|
|
154
|
-
const database = yield* CurrentSessionSql;
|
|
155
|
-
return yield* selectRows(database.select().from(mapping.pending.table).where(eq(pendingColumns(mapping).digest, digest)).limit(1), locking);
|
|
156
|
-
});
|
|
157
|
-
const validatePending = Effect.fn("DrizzleSession.validatePending")(function* (mapping, input, projection = "record") {
|
|
158
|
-
const row = (yield* readPending(mapping, input.digest, true))[0];
|
|
159
|
-
if (row === void 0) return yield* invalidPending();
|
|
160
|
-
const record = yield* (projection === "context" ? mapping.pending.decodeContext : mapping.pending.decode)(row);
|
|
161
|
-
const failedAttempts = Number(row[mapping.pending.failedAttempts]);
|
|
162
|
-
if (record.version !== input.version || record.evidence.flowId !== input.flowId || record.evidence.bindingDigest !== input.bindingDigest || row[mapping.pending.consumed] !== false || failedAttempts >= record.attemptLimit) return yield* invalidPending();
|
|
163
|
-
const flow = (yield* readFlow(mapping, input.flowId, true))[0];
|
|
164
|
-
if (flow === void 0 || flow[mapping.flow.state] !== mapping.flow.pendingStateValue || flow[mapping.flow.pendingDigest] !== input.digest) return yield* invalidPending();
|
|
165
|
-
if (DateTime.toEpochMillis(yield* freshNow) >= DateTime.toEpochMillis(record.expiresAt)) return yield* invalidPending();
|
|
166
|
-
return record;
|
|
167
|
-
});
|
|
168
|
-
const consumePending = Effect.fn("DrizzleSession.consumePending")(function* (mapping, input, until) {
|
|
169
|
-
const database = yield* CurrentSessionSql;
|
|
170
|
-
yield* Effect.all([database.update(mapping.pending.table).set(updateValues([[mapping.pending.consumed, true]])).where(and(eq(pendingColumns(mapping).digest, input.digest), eq(pendingColumns(mapping).version, input.version), eq(pendingColumns(mapping).consumed, false))), database.update(mapping.flow.table).set(updateValues([
|
|
171
|
-
[mapping.flow.state, mapping.flow.establishedStateValue],
|
|
172
|
-
[mapping.flow.pendingDigest, null],
|
|
173
|
-
[mapping.flow.dedupUntil, mapping.flow.encodeInstant(until)]
|
|
174
|
-
])).where(eq(flowColumns(mapping).flowId, input.flowId))]);
|
|
175
|
-
});
|
|
176
|
-
const freshNow = DateTime.now;
|
|
177
|
-
const allocate = (mode, asynchronous, synchronous) => {
|
|
178
|
-
if (mode === "synchronous") return synchronous === void 0 ? Effect.fail(unavailable()) : Effect.try({
|
|
179
|
-
try: synchronous,
|
|
180
|
-
catch: (cause) => PersistenceMappingError.make({
|
|
181
|
-
operation: "allocate",
|
|
182
|
-
cause
|
|
183
|
-
})
|
|
184
|
-
});
|
|
185
|
-
if (asynchronous !== void 0) return asynchronous;
|
|
186
|
-
return synchronous === void 0 ? Effect.fail(unavailable()) : Effect.try({
|
|
187
|
-
try: synchronous,
|
|
188
|
-
catch: (cause) => PersistenceMappingError.make({
|
|
189
|
-
operation: "allocate",
|
|
190
|
-
cause
|
|
191
|
-
})
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
const makeSqlAuthenticationAuthority = Effect.fnUntraced(function* (mapping, options) {
|
|
195
|
-
const database = yield* CurrentSessionSql;
|
|
196
|
-
if (!options.coordinated) yield* (operations.validateStorage?.(mapping) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
197
|
-
const hooks = yield* LifecycleHooks;
|
|
198
|
-
const root = yield* NativeDatabase;
|
|
199
|
-
const sqlClient = root.$client.withoutTransforms();
|
|
200
|
-
const tables = yield* sqlMapping(() => nativeTables(sqlClient, root)).pipe(Effect.mapError(unavailable));
|
|
201
|
-
const readSnapshot = makeAuthoritySnapshot(tables, mapping);
|
|
202
|
-
const service = {
|
|
203
|
-
capture: (subjectId, credentialIds) => safeTransaction(readSnapshot(subjectId, credentialIds).pipe(Effect.flatMap((value) => Effect.flatMap(mapping.subject.decodeRequirement(value.subject), (requirement) => Schema.decodeEffect(AuthenticationCapture)({
|
|
204
|
-
revision: value.revision,
|
|
205
|
-
requirement
|
|
206
|
-
}))))),
|
|
207
|
-
requirements: (evidence) => safeTransaction(readSnapshot(evidence.revision.subjectId, evidence.revision.credentials.map((item) => item.credentialId)).pipe(Effect.flatMap((captured) => validateCapturedEvidence(mapping, evidence, captured)), Effect.map((value) => value.requirement))),
|
|
208
|
-
approve: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
209
|
-
const journal = yield* CurrentCommitJournal;
|
|
210
|
-
const { requirement } = yield* options.locking ? validateEvidenceIn(mapping, input.evidence, true) : Effect.flatMap(readSnapshot(input.evidence.revision.subjectId, input.evidence.revision.credentials.map((item) => item.credentialId)), (captured) => validateCapturedEvidence(mapping, input.evidence, captured));
|
|
211
|
-
if (input.pending === void 0) {
|
|
212
|
-
const assessed = yield* assessAuthentication(input.evidence, requirement).pipe(Effect.mapError(unavailable));
|
|
213
|
-
const now = yield* freshNow;
|
|
214
|
-
if (!assessed.satisfied || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.expiresAt) || DateTime.toEpochMillis(input.expiresAt) > DateTime.toEpochMillis(input.absoluteExpiresAt)) return yield* stale();
|
|
215
|
-
return prepare(void 0, journal);
|
|
216
|
-
}
|
|
217
|
-
if (mapping.pending === void 0) return yield* invalidPending();
|
|
218
|
-
const pendingMapping = {
|
|
219
|
-
...mapping,
|
|
220
|
-
...mapping.pending
|
|
221
|
-
};
|
|
222
|
-
const pending = yield* validatePending(pendingMapping, input.pending);
|
|
223
|
-
if (!preservesRevision(input.evidence, pending.evidence)) return yield* invalidPending();
|
|
224
|
-
const assessed = yield* assessAuthentication(input.evidence, requirement).pipe(Effect.mapError(unavailable));
|
|
225
|
-
const now = yield* freshNow;
|
|
226
|
-
if (!assessed.satisfied || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(pending.expiresAt) || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.expiresAt) || DateTime.toEpochMillis(input.expiresAt) > DateTime.toEpochMillis(input.absoluteExpiresAt)) return yield* stale();
|
|
227
|
-
const receipt = prepare(void 0, journal);
|
|
228
|
-
yield* consumePending(pendingMapping, input.pending, input.absoluteExpiresAt);
|
|
229
|
-
return receipt;
|
|
230
|
-
}))
|
|
231
|
-
};
|
|
232
|
-
return {
|
|
233
|
-
capture: (subjectId, credentialIds) => service.capture(subjectId, credentialIds).pipe(Effect.provideService(NativeDatabase, root), Effect.provideService(LifecycleHooks, hooks)),
|
|
234
|
-
requirements: (evidence) => service.requirements(evidence).pipe(Effect.provideService(NativeDatabase, root), Effect.provideService(LifecycleHooks, hooks)),
|
|
235
|
-
approve: (input, prepare) => service.approve(input, prepare).pipe(Effect.provideService(NativeDatabase, root), Effect.provideService(LifecycleHooks, hooks))
|
|
236
|
-
};
|
|
237
|
-
});
|
|
238
|
-
/** The same locked security checks serve full consumption reads and the
|
|
239
|
-
* claims-free additional-factor context. No lock spans proof verification. */
|
|
240
|
-
const readAuthenticatedPending = Effect.fn("DrizzleSession.readAuthenticatedPending")(function* (mapping, input, projection) {
|
|
241
|
-
const initial = (yield* readPending(mapping, input.digest, false))[0];
|
|
242
|
-
if (initial === void 0) return yield* invalidPending();
|
|
243
|
-
const initialNativeSubjectId = initial[mapping.pending.subjectId];
|
|
244
|
-
if ((yield* readSubject(mapping, initialNativeSubjectId, true))[0] === void 0) return yield* invalidPending();
|
|
245
|
-
const current = (yield* readPending(mapping, input.digest, true))[0];
|
|
246
|
-
if (current === void 0 || !mapping.subjectId.equals(current[mapping.pending.subjectId], initialNativeSubjectId)) return yield* invalidPending();
|
|
247
|
-
const record = yield* (projection === "context" ? mapping.pending.decodeContext : mapping.pending.decode)(current);
|
|
248
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(record.evidence.revision.subjectId);
|
|
249
|
-
const failedAttempts = Number(current[mapping.pending.failedAttempts]);
|
|
250
|
-
if (!mapping.subjectId.equals(nativeSubjectId, initialNativeSubjectId) || input.bindingDigest !== void 0 && record.evidence.bindingDigest !== input.bindingDigest || current[mapping.pending.version] !== record.version || current[mapping.pending.flowId] !== record.evidence.flowId || current[mapping.pending.bindingDigest] !== record.evidence.bindingDigest || current[mapping.pending.consumed] !== false || failedAttempts >= record.attemptLimit) return yield* invalidPending();
|
|
251
|
-
const flow = (yield* readFlow(mapping, record.evidence.flowId, true))[0];
|
|
252
|
-
if (flow === void 0 || flow[mapping.flow.state] !== mapping.flow.pendingStateValue || flow[mapping.flow.pendingDigest] !== input.digest) return yield* invalidPending();
|
|
253
|
-
const { requirement } = yield* mapFailureCause(validateEvidenceIn(mapping, record.evidence, true), (error) => Schema.is(StaleAuthentication)(error) ? invalidPending() : error);
|
|
254
|
-
yield* assessAuthentication(record.evidence, requirement).pipe(Effect.mapError(() => invalidPending()));
|
|
255
|
-
if (DateTime.toEpochMillis(yield* freshNow) >= DateTime.toEpochMillis(record.expiresAt)) return yield* invalidPending();
|
|
256
|
-
return record;
|
|
257
|
-
});
|
|
258
|
-
const makeSqlPendingAuthentication = Effect.fnUntraced(function* (mapping, options) {
|
|
259
|
-
const database = yield* CurrentSessionSql;
|
|
260
|
-
if (!options.coordinated) yield* (operations.validateStorage?.(mapping) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
261
|
-
const hooks = yield* LifecycleHooks;
|
|
262
|
-
const service = {
|
|
263
|
-
create: (input, _inputNow, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
264
|
-
const transaction = yield* CurrentSessionSql;
|
|
265
|
-
const journal = yield* CurrentCommitJournal;
|
|
266
|
-
const { nativeSubjectId, requirement } = yield* validateEvidenceIn(mapping, input.evidence, true);
|
|
267
|
-
const existing = (yield* readFlow(mapping, input.evidence.flowId, true))[0];
|
|
268
|
-
if (existing !== void 0) {
|
|
269
|
-
const dedupUntil = yield* mapping.flow.decodeInstant(existing[mapping.flow.dedupUntil]);
|
|
270
|
-
if (DateTime.toEpochMillis(yield* freshNow) < DateTime.toEpochMillis(dedupUntil)) return yield* SessionConflict.make({});
|
|
271
|
-
yield* transaction.delete(mapping.pending.table).where(eq(pendingColumns(mapping).flowId, input.evidence.flowId));
|
|
272
|
-
yield* transaction.delete(mapping.flow.table).where(eq(flowColumns(mapping).flowId, input.evidence.flowId));
|
|
273
|
-
}
|
|
274
|
-
const version = yield* allocate(options.mode, mapping.pending.allocateVersion, mapping.pending.allocateVersionSync);
|
|
275
|
-
yield* assessAuthentication(input.evidence, requirement);
|
|
276
|
-
const now = yield* freshNow;
|
|
277
|
-
if (DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.expiresAt)) return yield* stale();
|
|
278
|
-
const record = {
|
|
279
|
-
...input,
|
|
280
|
-
version
|
|
281
|
-
};
|
|
282
|
-
const receipt = prepare(record, journal);
|
|
283
|
-
yield* transaction.insert(mapping.flow.table).values(mapping.flow.encodePendingInsert({
|
|
284
|
-
evidence: input.evidence,
|
|
285
|
-
subjectId: nativeSubjectId,
|
|
286
|
-
pendingDigest: input.digest,
|
|
287
|
-
dedupUntil: input.expiresAt
|
|
288
|
-
}));
|
|
289
|
-
yield* transaction.insert(mapping.pending.table).values(mapping.pending.encodeInsert(record, {
|
|
290
|
-
subjectId: nativeSubjectId,
|
|
291
|
-
failedAttempts: 0,
|
|
292
|
-
consumed: false
|
|
293
|
-
}));
|
|
294
|
-
return receipt;
|
|
295
|
-
}).pipe(normalizeMutation(mapping))),
|
|
296
|
-
context: (input) => safeTransaction(inTransaction(database, readAuthenticatedPending(mapping, input, "context"))).pipe(Effect.flatMap(pendingAuthenticationContext)),
|
|
297
|
-
read: (input) => safeTransaction(inTransaction(database, readAuthenticatedPending(mapping, input, "record"))).pipe(Effect.map((record) => record)),
|
|
298
|
-
reject: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
299
|
-
const transaction = yield* CurrentSessionSql;
|
|
300
|
-
const journal = yield* CurrentCommitJournal;
|
|
301
|
-
const initial = (yield* readPending(mapping, input.digest, false))[0];
|
|
302
|
-
if (initial === void 0) return prepare({ _tag: "Rejected" }, journal);
|
|
303
|
-
const record = yield* mapping.pending.decodeContext(initial);
|
|
304
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(record.evidence.revision.subjectId);
|
|
305
|
-
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
306
|
-
const current = (yield* readPending(mapping, input.digest, true))[0];
|
|
307
|
-
const now = yield* freshNow;
|
|
308
|
-
const receipt = prepare({ _tag: "Rejected" }, journal);
|
|
309
|
-
if (subject !== void 0 && mapping.subject.isActiveStatus(subject[mapping.subject.status]) && subject[mapping.subject.securityRevision] === record.evidence.revision.securityRevision && current !== void 0 && current[mapping.pending.consumed] === false && record.evidence.bindingDigest === input.bindingDigest && DateTime.toEpochMillis(now) < DateTime.toEpochMillis(record.expiresAt)) yield* transaction.update(mapping.pending.table).set(updateValues([[mapping.pending.failedAttempts, sql`case when ${pendingColumns(mapping).failedAttempts} < ${pendingColumns(mapping).attemptLimit} then ${pendingColumns(mapping).failedAttempts} + 1 else ${pendingColumns(mapping).failedAttempts} end`]])).where(eq(pendingColumns(mapping).digest, input.digest));
|
|
310
|
-
return receipt;
|
|
311
|
-
}))
|
|
312
|
-
};
|
|
313
|
-
return {
|
|
314
|
-
create: (input, now, prepare) => service.create(input, now, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
315
|
-
context: (input) => service.context(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
316
|
-
read: (input) => service.read(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
317
|
-
reject: (input, prepare) => service.reject(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks))
|
|
318
|
-
};
|
|
319
|
-
});
|
|
320
|
-
const sessionColumns = (mapping) => ({
|
|
321
|
-
sessionId: column(mapping.session.table, mapping.session.sessionId),
|
|
322
|
-
subjectId: column(mapping.session.table, mapping.session.subjectId),
|
|
323
|
-
digest: column(mapping.session.table, mapping.session.digest),
|
|
324
|
-
version: column(mapping.session.table, mapping.session.version),
|
|
325
|
-
securityRevision: column(mapping.session.table, mapping.session.securityRevision),
|
|
326
|
-
issuedAt: column(mapping.session.table, mapping.session.issuedAt),
|
|
327
|
-
expiresAt: column(mapping.session.table, mapping.session.expiresAt),
|
|
328
|
-
absoluteExpiresAt: column(mapping.session.table, mapping.session.absoluteExpiresAt)
|
|
329
|
-
});
|
|
330
|
-
const makeSqlStatefulSessions = Effect.fnUntraced(function* (mapping, options) {
|
|
331
|
-
const database = yield* CurrentSessionSql;
|
|
332
|
-
if (!options.coordinated) yield* (operations.validateStorage?.(mapping) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
333
|
-
const hooks = yield* LifecycleHooks;
|
|
334
|
-
const root = yield* NativeDatabase;
|
|
335
|
-
const tables = yield* sqlMapping(() => nativeTables(root.$client.withoutTransforms(), root)).pipe(Effect.mapError(unavailable));
|
|
336
|
-
const readSnapshot = makeAuthoritySnapshot(tables, mapping);
|
|
337
|
-
const c = sessionColumns(mapping);
|
|
338
|
-
const verification = yield* safeTransaction(Effect.gen(function* () {
|
|
339
|
-
const { session, subject } = yield* sqlMapping(() => ({
|
|
340
|
-
session: tables(mapping.session.table).as("auth_session"),
|
|
341
|
-
subject: tables(mapping.subject.table).as("auth_subject")
|
|
342
|
-
}));
|
|
343
|
-
const [sessionOwner, subjectOwner] = yield* sqlMapping(() => [session.unencodedTextColumn?.(mapping.session.subjectId), subject.unencodedTextColumn?.(mapping.subject.id)]);
|
|
344
|
-
return {
|
|
345
|
-
session,
|
|
346
|
-
subject,
|
|
347
|
-
canJoinOwner: yield* canJoinTextColumns(sessionOwner, subjectOwner)
|
|
348
|
-
};
|
|
349
|
-
}));
|
|
350
|
-
const persistence = {
|
|
351
|
-
establish: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
352
|
-
const transaction = yield* CurrentSessionSql;
|
|
353
|
-
const journal = yield* CurrentCommitJournal;
|
|
354
|
-
const { nativeSubjectId, requirement } = yield* options.locking ? validateEvidenceIn(mapping, input.evidence, true) : Effect.flatMap(readSnapshot(input.evidence.revision.subjectId, input.evidence.revision.credentials.map((item) => item.credentialId)), (captured) => validateCapturedEvidence(mapping, input.evidence, captured));
|
|
355
|
-
let flowInsert;
|
|
356
|
-
let pendingExpiresAt;
|
|
357
|
-
if (input.pending === void 0) {
|
|
358
|
-
if (input.fresh !== true || input.handoffSourceSessionId !== void 0) flowInsert = yield* ensureDirectFlowAvailable(mapping, input.evidence, nativeSubjectId, input.session.absoluteExpiresAt);
|
|
359
|
-
} else {
|
|
360
|
-
if (mapping.pending === void 0) return yield* invalidPending();
|
|
361
|
-
const pending = yield* validatePending(mapping, input.pending);
|
|
362
|
-
if (!preservesRevision(input.evidence, pending.evidence)) return yield* invalidPending();
|
|
363
|
-
pendingExpiresAt = pending.expiresAt;
|
|
364
|
-
}
|
|
365
|
-
const nativeSessionId = yield* allocate(options.mode, mapping.session.allocateId, mapping.session.allocateIdSync);
|
|
366
|
-
const sessionId = yield* mapping.sessionId.toSession(nativeSessionId);
|
|
367
|
-
if (sessionId === input.handoffSourceSessionId) return yield* SessionConflict.make({});
|
|
368
|
-
const version = yield* allocate(options.mode, mapping.session.allocateVersion, mapping.session.allocateVersionSync);
|
|
369
|
-
const assessed = yield* assessAuthentication(input.evidence, requirement);
|
|
370
|
-
const now = yield* freshNow;
|
|
371
|
-
if (!assessed.satisfied || pendingExpiresAt !== void 0 && DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(pendingExpiresAt) || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(input.session.expiresAt) || DateTime.toEpochMillis(input.session.expiresAt) > DateTime.toEpochMillis(input.session.absoluteExpiresAt)) return yield* stale();
|
|
372
|
-
const record = {
|
|
373
|
-
...input.session,
|
|
374
|
-
sessionId,
|
|
375
|
-
version,
|
|
376
|
-
subjectId: input.evidence.revision.subjectId,
|
|
377
|
-
securityRevision: input.evidence.revision.securityRevision,
|
|
378
|
-
assurance: input.handoffSourceSessionId === void 0 ? assessed.assurance : input.session.assurance,
|
|
379
|
-
provenance: yield* snapshotSessionAuthenticationProvenance({ evidence: input.evidence }),
|
|
380
|
-
issuedAt: now
|
|
381
|
-
};
|
|
382
|
-
const receipt = prepare(record, journal);
|
|
383
|
-
if (flowInsert !== void 0) yield* transaction.insert(mapping.flow.table).values(flowInsert);
|
|
384
|
-
else if (input.pending !== void 0) yield* consumePending({
|
|
385
|
-
...mapping,
|
|
386
|
-
pending: mapping.pending
|
|
387
|
-
}, input.pending, input.session.absoluteExpiresAt);
|
|
388
|
-
yield* transaction.insert(mapping.session.table).values(mapping.session.encodeInsert(record, {
|
|
389
|
-
subjectId: nativeSubjectId,
|
|
390
|
-
sessionId: nativeSessionId
|
|
391
|
-
}));
|
|
392
|
-
const commitNow = yield* freshNow;
|
|
393
|
-
if (DateTime.toEpochMillis(commitNow) < DateTime.toEpochMillis(record.issuedAt) || DateTime.toEpochMillis(commitNow) >= DateTime.toEpochMillis(record.expiresAt) || !(yield* assessAuthentication(input.evidence, requirement)).satisfied) return yield* stale();
|
|
394
|
-
return receipt;
|
|
395
|
-
}).pipe(normalizeMutation(mapping))),
|
|
396
|
-
verify: (input) => safeTransaction(withVerificationSavepoint(Effect.gen(function* () {
|
|
397
|
-
const sql = root.$client.withoutTransforms();
|
|
398
|
-
const { session, subject, canJoinOwner } = verification;
|
|
399
|
-
const owner = canJoinOwner ? void 0 : (yield* database.select({ subjectId: c.subjectId }).from(mapping.session.table).where(eq(c.digest, input.digest)).limit(1))[0];
|
|
400
|
-
if (!canJoinOwner && owner === void 0) return yield* invalidSession();
|
|
401
|
-
const row = (yield* sqlMapping(() => sql`select ${session.fields("v_")}, ${subject.fields("s_")}
|
|
402
|
-
from ${session.name} inner join ${subject.name} on
|
|
403
|
-
${subject.column(mapping.subject.id)} = ${owner === void 0 ? session.column(mapping.session.subjectId) : subject.value(mapping.subject.id, owner.subjectId)}
|
|
404
|
-
where ${session.column(mapping.session.digest)} = ${session.value(mapping.session.digest, input.digest)}
|
|
405
|
-
limit 1`).pipe(Effect.flatten))[0];
|
|
406
|
-
if (row === void 0) return yield* invalidSession();
|
|
407
|
-
const sessionRow = yield* sqlMapping(() => session.decode(row, "v_"));
|
|
408
|
-
const subjectRow = yield* sqlMapping(() => subject.decode(row, "s_"));
|
|
409
|
-
const record = yield* mapping.session.decode(sessionRow);
|
|
410
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(record.subjectId);
|
|
411
|
-
const now = yield* freshNow;
|
|
412
|
-
if (!mapping.subjectId.equals(nativeSubjectId, sessionRow[mapping.session.subjectId]) || !mapping.subjectId.equals(nativeSubjectId, subjectRow[mapping.subject.id]) || !mapping.subject.isActiveStatus(subjectRow[mapping.subject.status]) || subjectRow[mapping.subject.securityRevision] !== record.securityRevision || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.expiresAt) || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.absoluteExpiresAt)) return yield* invalidSession();
|
|
413
|
-
return record;
|
|
414
|
-
}))),
|
|
415
|
-
rotate: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
416
|
-
const transaction = yield* CurrentSessionSql;
|
|
417
|
-
const journal = yield* CurrentCommitJournal;
|
|
418
|
-
const nativeSessionId = yield* mapping.sessionId.toNative(input.sessionId);
|
|
419
|
-
const initial = (yield* transaction.select().from(mapping.session.table).where(eq(c.sessionId, nativeSessionId)).limit(1))[0];
|
|
420
|
-
if (initial === void 0) return yield* SessionConflict.make({});
|
|
421
|
-
const initialRecord = yield* mapping.session.decode(initial);
|
|
422
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(initialRecord.subjectId);
|
|
423
|
-
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
424
|
-
const row = (yield* selectRows(transaction.select().from(mapping.session.table).where(eq(c.sessionId, nativeSessionId)).limit(1), options.locking))[0];
|
|
425
|
-
if (row === void 0) return yield* SessionConflict.make({});
|
|
426
|
-
const record = yield* mapping.session.decode(row);
|
|
427
|
-
const version = yield* allocate(options.mode, mapping.session.allocateVersion, mapping.session.allocateVersionSync);
|
|
428
|
-
const now = yield* freshNow;
|
|
429
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status]) || subject[mapping.subject.securityRevision] !== input.expectedSecurityRevision || record.securityRevision !== input.expectedSecurityRevision || record.digest !== input.expectedDigest || record.version !== input.expectedVersion || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.expiresAt) || DateTime.toEpochMillis(now) >= DateTime.toEpochMillis(record.absoluteExpiresAt) || DateTime.toEpochMillis(input.nextExpiresAt) > DateTime.toEpochMillis(record.absoluteExpiresAt) || DateTime.toEpochMillis(input.nextExpiresAt) <= DateTime.toEpochMillis(now)) return yield* SessionConflict.make({});
|
|
430
|
-
const next = {
|
|
431
|
-
...record,
|
|
432
|
-
digest: input.nextDigest,
|
|
433
|
-
credentialVersion: input.nextCredentialVersion,
|
|
434
|
-
version,
|
|
435
|
-
issuedAt: now,
|
|
436
|
-
expiresAt: input.nextExpiresAt
|
|
437
|
-
};
|
|
438
|
-
const receipt = prepare(next, journal);
|
|
439
|
-
yield* transaction.update(mapping.session.table).set(mapping.session.encodeRotation(next)).where(and(eq(c.sessionId, nativeSessionId), eq(c.digest, input.expectedDigest), eq(c.version, input.expectedVersion)));
|
|
440
|
-
return receipt;
|
|
441
|
-
})),
|
|
442
|
-
revokeDigest: (digest, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
443
|
-
const transaction = yield* CurrentSessionSql;
|
|
444
|
-
const journal = yield* CurrentCommitJournal;
|
|
445
|
-
const initial = (yield* transaction.select().from(mapping.session.table).where(eq(c.digest, digest)).limit(1))[0];
|
|
446
|
-
if (initial === void 0) return prepare(false, journal);
|
|
447
|
-
const record = yield* mapping.session.decode(initial);
|
|
448
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(record.subjectId);
|
|
449
|
-
yield* readSubject(mapping, nativeSubjectId, true);
|
|
450
|
-
const row = (yield* selectRows(transaction.select().from(mapping.session.table).where(eq(c.digest, digest)).limit(1), options.locking))[0];
|
|
451
|
-
const receipt = prepare(row !== void 0, journal);
|
|
452
|
-
if (row !== void 0) yield* transaction.delete(mapping.session.table).where(eq(c.digest, digest));
|
|
453
|
-
return receipt;
|
|
454
|
-
})),
|
|
455
|
-
revoke: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
456
|
-
const transaction = yield* CurrentSessionSql;
|
|
457
|
-
const journal = yield* CurrentCommitJournal;
|
|
458
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
459
|
-
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
460
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status]) || subject[mapping.subject.securityRevision] !== input.expectedSecurityRevision) return yield* stale();
|
|
461
|
-
const nativeSessionId = yield* mapping.sessionId.toNative(input.sessionId);
|
|
462
|
-
const receipt = prepare(void 0, journal);
|
|
463
|
-
yield* transaction.delete(mapping.session.table).where(and(eq(c.subjectId, nativeSubjectId), eq(c.sessionId, nativeSessionId)));
|
|
464
|
-
return receipt;
|
|
465
|
-
})),
|
|
466
|
-
revokeAll: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
467
|
-
const transaction = yield* CurrentSessionSql;
|
|
468
|
-
const journal = yield* CurrentCommitJournal;
|
|
469
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
470
|
-
const subject = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
471
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status]) || subject[mapping.subject.securityRevision] !== input.expectedSecurityRevision) return yield* stale();
|
|
472
|
-
const nextRevisionSync = mapping.subject.nextSecurityRevisionSync;
|
|
473
|
-
const next = yield* allocate(options.mode, mapping.subject.nextSecurityRevision?.(input.expectedSecurityRevision), nextRevisionSync === void 0 ? void 0 : () => nextRevisionSync(input.expectedSecurityRevision));
|
|
474
|
-
const receipt = prepare(void 0, journal);
|
|
475
|
-
yield* transaction.update(mapping.subject.table).set(updateValues([[mapping.subject.securityRevision, next]])).where(and(eq(authorityColumns(mapping).subjectId, nativeSubjectId), eq(authorityColumns(mapping).subjectRevision, input.expectedSecurityRevision)));
|
|
476
|
-
yield* transaction.delete(mapping.session.table).where(eq(c.subjectId, nativeSubjectId));
|
|
477
|
-
return receipt;
|
|
478
|
-
}))
|
|
479
|
-
};
|
|
480
|
-
const repository = { list: (input) => safeTransaction(inTransaction(database, Effect.gen(function* () {
|
|
481
|
-
const read = yield* CurrentSessionSql;
|
|
482
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
483
|
-
const subject = (yield* readSubject(mapping, nativeSubjectId, false))[0];
|
|
484
|
-
if (subject === void 0 || !mapping.subject.isActiveStatus(subject[mapping.subject.status])) return { sessions: [] };
|
|
485
|
-
const cursor = input.cursor === void 0 ? void 0 : yield* mapping.sessionId.toNative(input.cursor);
|
|
486
|
-
const now = yield* freshNow;
|
|
487
|
-
const rows = yield* read.select().from(mapping.session.table).where(and(eq(c.subjectId, nativeSubjectId), eq(c.securityRevision, subject[mapping.subject.securityRevision]), gt(c.expiresAt, mapping.session.encodeInstant(now)), gt(c.absoluteExpiresAt, mapping.session.encodeInstant(now)), cursor === void 0 ? void 0 : gt(c.sessionId, cursor))).orderBy(c.sessionId).limit(input.limit + 1);
|
|
488
|
-
const decoded = yield* Effect.forEach(rows, (row) => mapping.session.decode(row));
|
|
489
|
-
const codec = Schema.toCodecJson(Schema.toType(SessionMetadata));
|
|
490
|
-
const sessions = yield* Effect.forEach(decoded.slice(0, input.limit), (record) => Schema.encodeEffect(codec)(record).pipe(Effect.flatMap(Schema.decodeEffect(codec))));
|
|
491
|
-
const nextCursor = decoded[input.limit] === void 0 ? void 0 : sessions.at(-1)?.sessionId;
|
|
492
|
-
return {
|
|
493
|
-
sessions,
|
|
494
|
-
...nextCursor === void 0 ? {} : { nextCursor }
|
|
495
|
-
};
|
|
496
|
-
}))) };
|
|
497
|
-
return {
|
|
498
|
-
statefulSessionPersistence: {
|
|
499
|
-
establish: (input, prepare) => persistence.establish(input, prepare).pipe(Effect.provideService(NativeDatabase, root), Effect.provideService(LifecycleHooks, hooks)),
|
|
500
|
-
verify: (input) => persistence.verify(input).pipe(Effect.provideService(NativeDatabase, root), Effect.provideService(LifecycleHooks, hooks)),
|
|
501
|
-
rotate: (input, prepare) => persistence.rotate(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
502
|
-
revokeDigest: (digest, prepare) => persistence.revokeDigest(digest, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
503
|
-
revoke: (input, prepare) => persistence.revoke(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
504
|
-
revokeAll: (input, prepare) => persistence.revokeAll(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks))
|
|
505
|
-
},
|
|
506
|
-
sessionRepository: { list: (input) => repository.list(input).pipe(Effect.provideService(LifecycleHooks, hooks)) }
|
|
507
|
-
};
|
|
508
|
-
});
|
|
509
|
-
const makeSqlSignedValidity = Effect.fnUntraced(function* (mapping, options) {
|
|
510
|
-
const database = yield* CurrentSessionSql;
|
|
511
|
-
if (!options.coordinated) yield* (operations.validateStorage?.(mapping) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
512
|
-
const hooks = yield* LifecycleHooks;
|
|
513
|
-
const subject = subjectColumns(mapping);
|
|
514
|
-
const tombstone = {
|
|
515
|
-
subjectId: column(mapping.tombstone.table, mapping.tombstone.subjectId),
|
|
516
|
-
sessionId: column(mapping.tombstone.table, mapping.tombstone.sessionId),
|
|
517
|
-
absoluteExpiresAt: column(mapping.tombstone.table, mapping.tombstone.absoluteExpiresAt)
|
|
518
|
-
};
|
|
519
|
-
const root = yield* NativeDatabase;
|
|
520
|
-
const tables = yield* sqlMapping(() => nativeTables(root.$client.withoutTransforms(), root)).pipe(Effect.mapError(unavailable));
|
|
521
|
-
const service = {
|
|
522
|
-
verify: (session, _now) => safeTransaction(withVerificationSavepoint(Effect.gen(function* () {
|
|
523
|
-
const sql = root.$client.withoutTransforms();
|
|
524
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(session.subjectId);
|
|
525
|
-
const nativeSessionId = yield* mapping.sessionId.toNative(session.sessionId);
|
|
526
|
-
const readNow = yield* freshNow;
|
|
527
|
-
const { subjectTable, rows } = yield* sqlMapping(() => {
|
|
528
|
-
const subjectTable = tables(mapping.subject.table).as("auth_subject");
|
|
529
|
-
const revoked = tables(mapping.tombstone.table).as("auth_revocation");
|
|
530
|
-
return {
|
|
531
|
-
subjectTable,
|
|
532
|
-
rows: sql`
|
|
533
|
-
select ${subjectTable.fields("s_")},
|
|
534
|
-
case when exists (
|
|
535
|
-
select 1 from ${revoked.name}
|
|
536
|
-
where ${revoked.column(mapping.tombstone.subjectId)} = ${revoked.value(mapping.tombstone.subjectId, nativeSubjectId)}
|
|
537
|
-
and ${revoked.column(mapping.tombstone.sessionId)} = ${revoked.value(mapping.tombstone.sessionId, nativeSessionId)}
|
|
538
|
-
and ${revoked.column(mapping.tombstone.absoluteExpiresAt)} > ${revoked.value(mapping.tombstone.absoluteExpiresAt, mapping.tombstone.encodeInstant(readNow))}
|
|
539
|
-
) then 1 else 0 end as auth_revoked
|
|
540
|
-
from ${subjectTable.name}
|
|
541
|
-
where ${subjectTable.column(mapping.subject.id)} = ${subjectTable.value(mapping.subject.id, nativeSubjectId)}
|
|
542
|
-
limit 1`
|
|
543
|
-
};
|
|
544
|
-
});
|
|
545
|
-
const result = (yield* rows)[0];
|
|
546
|
-
if (result === void 0) return yield* invalidSession();
|
|
547
|
-
const row = yield* sqlMapping(() => subjectTable.decode(result, "s_"));
|
|
548
|
-
const revoked = yield* decodeRevocationFlag(result.auth_revoked);
|
|
549
|
-
const authoritativeNow = yield* freshNow;
|
|
550
|
-
if (!mapping.subjectId.equals(nativeSubjectId, row[mapping.subject.id]) || !mapping.subject.isActiveStatus(row[mapping.subject.status]) || row[mapping.subject.securityRevision] !== session.securityRevision || revoked === 1 || DateTime.toEpochMillis(authoritativeNow) >= DateTime.toEpochMillis(session.expiresAt) || DateTime.toEpochMillis(authoritativeNow) >= DateTime.toEpochMillis(session.absoluteExpiresAt)) return yield* invalidSession();
|
|
551
|
-
}))),
|
|
552
|
-
revoke: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
553
|
-
const transaction = yield* CurrentSessionSql;
|
|
554
|
-
const journal = yield* CurrentCommitJournal;
|
|
555
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
556
|
-
const row = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
557
|
-
if (row === void 0 || !mapping.subject.isActiveStatus(row[mapping.subject.status]) || row[mapping.subject.securityRevision] !== input.expectedSecurityRevision) return yield* stale();
|
|
558
|
-
const nativeSessionId = yield* mapping.sessionId.toNative(input.sessionId);
|
|
559
|
-
const existing = yield* transaction.select().from(mapping.tombstone.table).where(and(eq(tombstone.subjectId, nativeSubjectId), eq(tombstone.sessionId, nativeSessionId))).limit(1);
|
|
560
|
-
const receipt = prepare(void 0, journal);
|
|
561
|
-
if (existing[0] === void 0) yield* transaction.insert(mapping.tombstone.table).values(mapping.tombstone.encodeInsert({
|
|
562
|
-
subjectId: nativeSubjectId,
|
|
563
|
-
sessionId: nativeSessionId,
|
|
564
|
-
absoluteExpiresAt: input.absoluteExpiresAt
|
|
565
|
-
}));
|
|
566
|
-
else {
|
|
567
|
-
const existingExpiry = yield* mapping.tombstone.decodeInstant(existing[0][mapping.tombstone.absoluteExpiresAt]);
|
|
568
|
-
if (DateTime.toEpochMillis(input.absoluteExpiresAt) > DateTime.toEpochMillis(existingExpiry)) yield* transaction.update(mapping.tombstone.table).set(updateValues([[mapping.tombstone.absoluteExpiresAt, mapping.tombstone.encodeInstant(input.absoluteExpiresAt)]])).where(and(eq(tombstone.subjectId, nativeSubjectId), eq(tombstone.sessionId, nativeSessionId)));
|
|
569
|
-
}
|
|
570
|
-
return receipt;
|
|
571
|
-
})),
|
|
572
|
-
revokeAll: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
573
|
-
const transaction = yield* CurrentSessionSql;
|
|
574
|
-
const journal = yield* CurrentCommitJournal;
|
|
575
|
-
const nativeSubjectId = yield* mapping.subjectId.toNative(input.subjectId);
|
|
576
|
-
const row = (yield* readSubject(mapping, nativeSubjectId, true))[0];
|
|
577
|
-
if (row === void 0 || !mapping.subject.isActiveStatus(row[mapping.subject.status]) || row[mapping.subject.securityRevision] !== input.expectedSecurityRevision) return yield* stale();
|
|
578
|
-
const nextRevisionSync = mapping.subject.nextSecurityRevisionSync;
|
|
579
|
-
const next = yield* allocate(options.mode, mapping.subject.nextSecurityRevision?.(input.expectedSecurityRevision), nextRevisionSync === void 0 ? void 0 : () => nextRevisionSync(input.expectedSecurityRevision));
|
|
580
|
-
const receipt = prepare(void 0, journal);
|
|
581
|
-
yield* transaction.update(mapping.subject.table).set(updateValues([[mapping.subject.securityRevision, next]])).where(and(eq(subject.subjectId, nativeSubjectId), eq(subject.subjectRevision, input.expectedSecurityRevision)));
|
|
582
|
-
return receipt;
|
|
583
|
-
}))
|
|
584
|
-
};
|
|
585
|
-
return {
|
|
586
|
-
verify: (session, now) => service.verify(session, now).pipe(Effect.provideService(NativeDatabase, root), Effect.provideService(LifecycleHooks, hooks)),
|
|
587
|
-
revoke: (input, prepare) => service.revoke(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
588
|
-
revokeAll: (input, prepare) => service.revokeAll(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks))
|
|
589
|
-
};
|
|
590
|
-
});
|
|
591
|
-
const stepUpColumns = (mapping) => Object.fromEntries([
|
|
592
|
-
"digest",
|
|
593
|
-
"version",
|
|
594
|
-
"flowId",
|
|
595
|
-
"subjectId",
|
|
596
|
-
"bindingDigest",
|
|
597
|
-
"snapshot",
|
|
598
|
-
"expiresAt",
|
|
599
|
-
"attemptLimit",
|
|
600
|
-
"failedAttempts",
|
|
601
|
-
"consumed"
|
|
602
|
-
].map((key) => [key, column(mapping.intent.table, mapping.intent[key])]));
|
|
603
|
-
const stepUpLocator = Effect.fn("DrizzleStepUp.locator")(function* (mapping, digest, locking, expiresAt) {
|
|
604
|
-
const database = yield* CurrentSessionSql;
|
|
605
|
-
return yield* selectRows(database.select().from(mapping.intent.table).where(and(eq(stepUpColumns(mapping).digest, digest), expiresAt === void 0 ? void 0 : eq(stepUpColumns(mapping).expiresAt, mapping.intent.encodeInstant(expiresAt)))).limit(1), locking).pipe(Effect.map((rows) => rows[0]));
|
|
606
|
-
});
|
|
607
|
-
const stepUpAuthority = Effect.fn("DrizzleStepUp.authority")(function* (mapping, revision, locking) {
|
|
608
|
-
const current = yield* captureDetailsIn(mapping, revision.subjectId, revision.credentials.map((c) => c.credentialId), locking);
|
|
609
|
-
if (!sameStepUpRevision(current.revision, revision)) return yield* stale();
|
|
610
|
-
const requirement = yield* mapping.subject.decodeRequirement(current.subject);
|
|
611
|
-
return {
|
|
612
|
-
nativeSubjectId: yield* mapping.subjectId.toNative(revision.subjectId),
|
|
613
|
-
requirement
|
|
614
|
-
};
|
|
615
|
-
});
|
|
616
|
-
const stepUpSource = Effect.fn("DrizzleStepUp.source")(function* (mapping, intent, nativeSubjectId, now, locking) {
|
|
617
|
-
const database = yield* CurrentSessionSql;
|
|
618
|
-
if (!stepUpIntentLive(intent, mapping.source.kind, now)) return yield* SessionStepUpInvalid.make({});
|
|
619
|
-
const source = mapping.source;
|
|
620
|
-
if (source.kind === "StatelessSigned") return {
|
|
621
|
-
nativeSessionId: void 0,
|
|
622
|
-
row: void 0
|
|
623
|
-
};
|
|
624
|
-
const nativeSessionId = yield* source.sessionId.toNative(intent.sourceSessionId);
|
|
625
|
-
if (source.kind === "StateAssistedSigned") {
|
|
626
|
-
const t = source.tombstone;
|
|
627
|
-
if ((yield* selectRows(database.select().from(t.table).where(and(eq(column(t.table, t.subjectId), nativeSubjectId), eq(column(t.table, t.sessionId), nativeSessionId), gt(column(t.table, t.absoluteExpiresAt), t.encodeInstant(now)))).limit(1), locking)).length > 0) return yield* SessionStepUpInvalid.make({});
|
|
628
|
-
return {
|
|
629
|
-
nativeSessionId,
|
|
630
|
-
row: void 0
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
const s = source.session, c = sessionColumns(source);
|
|
634
|
-
const row = (yield* selectRows(database.select().from(s.table).where(and(eq(c.sessionId, nativeSessionId), eq(c.subjectId, nativeSubjectId), eq(c.securityRevision, intent.revision.securityRevision), eq(column(s.table, s.credentialVersion), intent.sourceCredentialVersion), eq(column(s.table, s.authenticatedAt), s.encodeInstant(intent.sourceAuthenticatedAt)), eq(c.expiresAt, s.encodeInstant(intent.sourceExpiresAt)), eq(c.absoluteExpiresAt, s.encodeInstant(intent.sourceAbsoluteExpiresAt)), gt(c.expiresAt, s.encodeInstant(now)), gt(c.absoluteExpiresAt, s.encodeInstant(now)))).limit(1), locking))[0];
|
|
635
|
-
if (row === void 0) return yield* SessionStepUpInvalid.make({});
|
|
636
|
-
return {
|
|
637
|
-
nativeSessionId,
|
|
638
|
-
row
|
|
639
|
-
};
|
|
640
|
-
});
|
|
641
|
-
const readSqlStepUp = Effect.fn("DrizzleStepUp.read")(function* (mapping, digest, locking) {
|
|
642
|
-
const first = yield* stepUpLocator(mapping, digest, false);
|
|
643
|
-
if (first === void 0) return yield* SessionStepUpInvalid.make({});
|
|
644
|
-
const intent = yield* decodeStepUpIntent(first[mapping.intent.snapshot]);
|
|
645
|
-
const authority = yield* stepUpAuthority(mapping, intent.revision, locking);
|
|
646
|
-
const source = yield* stepUpSource(mapping, intent, authority.nativeSubjectId, yield* freshNow, locking);
|
|
647
|
-
const row = yield* stepUpLocator(mapping, digest, locking, intent.expiresAt);
|
|
648
|
-
const m = mapping.intent;
|
|
649
|
-
if (row === void 0 || row[m.snapshot] !== first[m.snapshot] || row[m.version] !== intent.version || row[m.digest] !== intent.digest || digest !== intent.digest || row[m.flowId] !== intent.flowId || row[m.bindingDigest] !== intent.bindingDigest || !mapping.subjectId.equals(row[m.subjectId], authority.nativeSubjectId) || Boolean(row[m.consumed]) || !Schema.is(Schema.Natural)(row[m.failedAttempts]) || row[m.failedAttempts] >= row[m.attemptLimit] || row[m.attemptLimit] !== intent.attemptLimit || !stepUpIntentLive(intent, mapping.source.kind, yield* freshNow)) return yield* SessionStepUpInvalid.make({});
|
|
650
|
-
return {
|
|
651
|
-
row,
|
|
652
|
-
intent,
|
|
653
|
-
source,
|
|
654
|
-
...authority
|
|
655
|
-
};
|
|
656
|
-
});
|
|
657
|
-
const isSqlStepUpRejectAbsence = (error) => {
|
|
658
|
-
const tag = typeof error === "object" && error !== null ? Reflect.get(error, "_tag") : void 0;
|
|
659
|
-
return tag === "SessionStepUpInvalid" || tag === "StaleAuthentication";
|
|
660
|
-
};
|
|
661
|
-
const recoverSqlStepUpRejectAbsence = (effect, rejected) => effect.pipe(Effect.catchCause((cause) => {
|
|
662
|
-
if (cause.reasons.length > 0 && cause.reasons.every((reason) => Cause.isFailReason(reason) && isSqlStepUpRejectAbsence(reason.error))) return Effect.succeed(rejected);
|
|
663
|
-
return Effect.failCause(Cause.map(cause, (error) => isSqlStepUpRejectAbsence(error) ? unavailable() : error));
|
|
664
|
-
}));
|
|
665
|
-
return {
|
|
666
|
-
makeSqlAuthenticationAuthority,
|
|
667
|
-
makeSqlPendingAuthentication,
|
|
668
|
-
makeSqlStatefulSessions,
|
|
669
|
-
makeSqlSignedValidity,
|
|
670
|
-
makeSqlSessionStepUp: Effect.fnUntraced(function* (mapping, options) {
|
|
671
|
-
const database = yield* CurrentSessionSql;
|
|
672
|
-
if (!options.coordinated) yield* (operations.validateStorage?.(mapping) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
673
|
-
const hooks = yield* LifecycleHooks;
|
|
674
|
-
const m = mapping.intent, c = stepUpColumns(mapping);
|
|
675
|
-
const read = (digest) => mapFailureCause(safeTransaction(inTransaction(database, readSqlStepUp(mapping, digest, options.locking))), (error) => error._tag === "StaleAuthentication" ? SessionStepUpInvalid.make({}) : error);
|
|
676
|
-
const service = {
|
|
677
|
-
create: (input, _now, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
678
|
-
const tx = yield* CurrentSessionSql;
|
|
679
|
-
const journal = yield* CurrentCommitJournal;
|
|
680
|
-
const authority = yield* stepUpAuthority(mapping, input.revision, options.locking);
|
|
681
|
-
const version = yield* allocate(options.mode, m.allocateVersion, m.allocateVersionSync);
|
|
682
|
-
const record = {
|
|
683
|
-
...input,
|
|
684
|
-
version
|
|
685
|
-
};
|
|
686
|
-
yield* stepUpSource(mapping, record, authority.nativeSubjectId, yield* freshNow, options.locking);
|
|
687
|
-
if ((yield* selectRows(tx.select().from(m.table).where(or(eq(c.digest, input.digest), eq(c.flowId, input.flowId))).limit(1), options.locking)).length > 0) return yield* SessionConflict.make({});
|
|
688
|
-
const snapshot = yield* encodeStepUpIntent(record);
|
|
689
|
-
const values = {
|
|
690
|
-
...m.encodeInsert(record, { subjectId: authority.nativeSubjectId }),
|
|
691
|
-
...updateValues([
|
|
692
|
-
[m.digest, record.digest],
|
|
693
|
-
[m.version, version],
|
|
694
|
-
[m.flowId, record.flowId],
|
|
695
|
-
[m.subjectId, authority.nativeSubjectId],
|
|
696
|
-
[m.bindingDigest, record.bindingDigest],
|
|
697
|
-
[m.snapshot, snapshot],
|
|
698
|
-
[m.expiresAt, m.encodeInstant(record.expiresAt)],
|
|
699
|
-
[m.attemptLimit, record.attemptLimit],
|
|
700
|
-
[m.failedAttempts, 0],
|
|
701
|
-
[m.consumed, false]
|
|
702
|
-
])
|
|
703
|
-
};
|
|
704
|
-
const receipt = prepare(record, journal);
|
|
705
|
-
yield* tx.insert(m.table).values(values).pipe(normalizeMutation(mapping));
|
|
706
|
-
if ((yield* tx.select().from(m.table).where(and(eq(c.digest, record.digest), eq(c.version, version), eq(c.flowId, record.flowId), eq(c.subjectId, authority.nativeSubjectId), eq(c.bindingDigest, record.bindingDigest), eq(c.snapshot, snapshot), eq(c.expiresAt, m.encodeInstant(record.expiresAt)), eq(c.attemptLimit, record.attemptLimit), eq(c.failedAttempts, 0), eq(c.consumed, false))).limit(1))[0] === void 0) return yield* unavailable();
|
|
707
|
-
return receipt;
|
|
708
|
-
})).pipe((effect) => mapFailureCause(effect, (error) => error._tag === "SessionStepUpInvalid" ? stale() : error)),
|
|
709
|
-
context: (input) => mapFailureCause(read(input.digest).pipe(Effect.flatMap(({ intent }) => snapshotPendingAuthenticationContext({
|
|
710
|
-
flowId: intent.flowId,
|
|
711
|
-
bindingDigest: intent.bindingDigest,
|
|
712
|
-
revision: intent.revision,
|
|
713
|
-
expiresAtMillis: DateTime.toEpochMillis(intent.expiresAt)
|
|
714
|
-
}))), (error) => error._tag === "PendingAuthenticationInvalid" ? unavailable() : error),
|
|
715
|
-
read: (input) => read(input.digest).pipe(Effect.flatMap((value) => value.intent.bindingDigest === input.bindingDigest ? Effect.succeed(value.intent) : Effect.fail(SessionStepUpInvalid.make({})))),
|
|
716
|
-
reject: (input, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
717
|
-
const tx = yield* CurrentSessionSql;
|
|
718
|
-
const journal = yield* CurrentCommitJournal;
|
|
719
|
-
const selected = yield* recoverSqlStepUpRejectAbsence(readSqlStepUp(mapping, input.digest, options.locking).pipe(Effect.map((value) => ({
|
|
720
|
-
_tag: "Found",
|
|
721
|
-
value
|
|
722
|
-
}))), { _tag: "Rejected" });
|
|
723
|
-
if (selected._tag === "Rejected") return prepare({ _tag: "Rejected" }, journal);
|
|
724
|
-
const { row, intent } = selected.value;
|
|
725
|
-
const receipt = prepare({ _tag: "Rejected" }, journal);
|
|
726
|
-
yield* tx.update(m.table).set(updateValues([[m.failedAttempts, sql`${c.failedAttempts} + 1`]])).where(and(eq(c.digest, input.digest), eq(c.snapshot, row[m.snapshot]), eq(c.version, intent.version), eq(c.consumed, false), sql`${c.failedAttempts} < ${c.attemptLimit}`));
|
|
727
|
-
const written = yield* stepUpLocator(mapping, input.digest, false);
|
|
728
|
-
if (written === void 0 || written[m.version] !== intent.version || written[m.snapshot] !== row[m.snapshot] || written[m.failedAttempts] !== row[m.failedAttempts] + 1) return yield* unavailable();
|
|
729
|
-
return receipt;
|
|
730
|
-
})),
|
|
731
|
-
complete: (plan, prepare) => owned(database, options, mapping.isConstraintConflict, Effect.gen(function* () {
|
|
732
|
-
const tx = yield* CurrentSessionSql;
|
|
733
|
-
const journal = yield* CurrentCommitJournal;
|
|
734
|
-
yield* validateStepUpPlan(plan);
|
|
735
|
-
const current = yield* stepUpAuthority(mapping, plan.evidence.revision, options.locking);
|
|
736
|
-
const stored = yield* readSqlStepUp(mapping, plan.intent.digest, options.locking);
|
|
737
|
-
if ((yield* encodeStepUpIntent(stored.intent)) !== (yield* encodeStepUpIntent(plan.intent))) return yield* SessionStepUpInvalid.make({});
|
|
738
|
-
const base = yield* assessAuthentication(plan.evidence, current.requirement).pipe(Effect.mapError(() => stale()));
|
|
739
|
-
const profile = yield* assessAuthentication(plan.evidence, stored.intent.requirement).pipe(Effect.mapError(() => stale()));
|
|
740
|
-
if (!base.satisfied || !profile.satisfied) return yield* stale();
|
|
741
|
-
const replacement = plan.replacement, now = yield* freshNow;
|
|
742
|
-
if (DateTime.toEpochMillis(replacement.inspection.session.expiresAt) > DateTime.toEpochMillis(stored.intent.sourceAbsoluteExpiresAt) || DateTime.toEpochMillis(now) < DateTime.toEpochMillis(replacement.inspection.session.issuedAt) || DateTime.toEpochMillis(now) >= Math.min(DateTime.toEpochMillis(replacement.inspection.session.expiresAt), DateTime.toEpochMillis(stored.intent.expiresAt))) return yield* SessionStepUpInvalid.make({});
|
|
743
|
-
let rotation;
|
|
744
|
-
if (replacement._tag === "Stateful") {
|
|
745
|
-
if (mapping.source.kind !== "Stateful") return yield* SessionStepUpInvalid.make({});
|
|
746
|
-
const s = mapping.source.session, row = stored.source.row;
|
|
747
|
-
if (row[s.digest] !== replacement.expectedDigest || row[s.version] !== replacement.expectedRowVersion) return yield* SessionConflict.make({});
|
|
748
|
-
const version = yield* allocate(options.mode, s.allocateVersion, s.allocateVersionSync);
|
|
749
|
-
const next = {
|
|
750
|
-
...replacement.inspection.session,
|
|
751
|
-
provenance: replacement.inspection.provenance,
|
|
752
|
-
credentialVersion: replacement.inspection.credentialVersion,
|
|
753
|
-
digest: replacement.nextDigest,
|
|
754
|
-
version
|
|
755
|
-
};
|
|
756
|
-
rotation = {
|
|
757
|
-
...s.encodeRotation(next),
|
|
758
|
-
...updateValues([
|
|
759
|
-
[s.version, version],
|
|
760
|
-
[s.digest, next.digest],
|
|
761
|
-
[s.credentialVersion, next.credentialVersion],
|
|
762
|
-
[s.authenticatedAt, s.encodeInstant(next.assurance.authenticatedAt)],
|
|
763
|
-
[s.issuedAt, s.encodeInstant(next.issuedAt)],
|
|
764
|
-
[s.expiresAt, s.encodeInstant(next.expiresAt)],
|
|
765
|
-
[s.absoluteExpiresAt, s.encodeInstant(next.absoluteExpiresAt)]
|
|
766
|
-
])
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
const completionVersion = yield* allocate(options.mode, m.allocateVersion, m.allocateVersionSync);
|
|
770
|
-
if (completionVersion === stored.intent.version) return yield* unavailable();
|
|
771
|
-
const completionSnapshot = yield* encodeStepUpIntent({
|
|
772
|
-
...stored.intent,
|
|
773
|
-
version: completionVersion
|
|
774
|
-
});
|
|
775
|
-
const receipt = prepare(replacement.inspection, journal);
|
|
776
|
-
if (replacement._tag === "Stateful" && mapping.source.kind === "Stateful") {
|
|
777
|
-
const s = mapping.source.session, sc = sessionColumns(mapping.source);
|
|
778
|
-
yield* tx.update(s.table).set(rotation).where(and(eq(sc.sessionId, stored.source.nativeSessionId), eq(sc.digest, replacement.expectedDigest), eq(sc.version, replacement.expectedRowVersion)));
|
|
779
|
-
const written = (yield* tx.select().from(s.table).where(eq(sc.sessionId, stored.source.nativeSessionId)).limit(1))[0];
|
|
780
|
-
if (written === void 0 || written[s.version] !== rotation[s.version]) return yield* unavailable();
|
|
781
|
-
const decoded = yield* s.decode(written);
|
|
782
|
-
if (decoded.version !== rotation[s.version] || !stepUpRotationMatches(plan, decoded)) return yield* unavailable();
|
|
783
|
-
} else if (replacement._tag === "StateAssistedSigned" && mapping.source.kind === "StateAssistedSigned") {
|
|
784
|
-
const t = mapping.source.tombstone;
|
|
785
|
-
const owner = column(t.table, t.subjectId), id = column(t.table, t.sessionId), expiry = column(t.table, t.absoluteExpiresAt);
|
|
786
|
-
yield* tx.delete(t.table).where(and(eq(owner, stored.nativeSubjectId), eq(id, stored.source.nativeSessionId), lte(expiry, t.encodeInstant(yield* freshNow))));
|
|
787
|
-
const values = t.encodeInsert({
|
|
788
|
-
subjectId: stored.nativeSubjectId,
|
|
789
|
-
sessionId: stored.source.nativeSessionId,
|
|
790
|
-
absoluteExpiresAt: replacement.tombstoneUntil
|
|
791
|
-
});
|
|
792
|
-
yield* tx.insert(t.table).values(values).pipe(normalizeMutation(mapping));
|
|
793
|
-
if ((yield* tx.select().from(t.table).where(and(eq(owner, stored.nativeSubjectId), eq(id, stored.source.nativeSessionId), eq(expiry, t.encodeInstant(replacement.tombstoneUntil)))).limit(1))[0] === void 0) return yield* unavailable();
|
|
794
|
-
}
|
|
795
|
-
yield* tx.update(m.table).set(updateValues([
|
|
796
|
-
[m.consumed, true],
|
|
797
|
-
[m.version, completionVersion],
|
|
798
|
-
[m.snapshot, completionSnapshot]
|
|
799
|
-
])).where(and(eq(c.digest, stored.intent.digest), eq(c.version, stored.intent.version), eq(c.snapshot, stored.row[m.snapshot]), eq(c.consumed, false), eq(c.failedAttempts, stored.row[m.failedAttempts])));
|
|
800
|
-
const completed = yield* stepUpLocator(mapping, stored.intent.digest, false);
|
|
801
|
-
if (completed === void 0 || !completed[m.consumed] || completed[m.version] !== completionVersion || completed[m.snapshot] !== completionSnapshot) return yield* unavailable();
|
|
802
|
-
const commitNow = yield* freshNow;
|
|
803
|
-
if (!stepUpIntentLive(stored.intent, mapping.source.kind, commitNow) || DateTime.toEpochMillis(commitNow) >= DateTime.toEpochMillis(replacement.inspection.session.expiresAt) || !(yield* assessAuthentication(plan.evidence, current.requirement).pipe(Effect.mapError(() => stale()))).satisfied || !(yield* assessAuthentication(plan.evidence, stored.intent.requirement).pipe(Effect.mapError(() => stale()))).satisfied) return yield* stale();
|
|
804
|
-
return receipt;
|
|
805
|
-
}))
|
|
806
|
-
};
|
|
807
|
-
return {
|
|
808
|
-
create: (input, now, prepare) => service.create(input, now, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
809
|
-
context: (input) => service.context(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
810
|
-
read: (input) => service.read(input).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
811
|
-
reject: (input, prepare) => service.reject(input, prepare).pipe(Effect.provideService(LifecycleHooks, hooks)),
|
|
812
|
-
complete: (plan, prepare) => service.complete(plan, prepare).pipe(Effect.provideService(LifecycleHooks, hooks))
|
|
813
|
-
};
|
|
814
|
-
})
|
|
815
|
-
};
|
|
816
|
-
};
|
|
817
|
-
//#endregion
|
|
818
|
-
export { CurrentSessionSql, makeSessionKernel };
|
|
819
|
-
|
|
820
|
-
//# sourceMappingURL=session-kernel.mjs.map
|