@yielded/auth-persistence 0.1.0-beta.25 → 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 +14 -81
- 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 +26 -147
- 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 -354
- 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 -1556
- package/src/internal/oauth/accounts.ts +0 -839
- 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 -692
- 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 -1523
- 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,924 +0,0 @@
|
|
|
1
|
-
/* oxlint-disable no-explicit-any -- compiler table shapes are erased; domain codecs and error channels remain typed. */
|
|
2
|
-
import { type OAuthAccountRevision, snapshotOAuthSync } from "@yielded/auth/OAuth";
|
|
3
|
-
import * as M from "@yielded/auth/OAuth";
|
|
4
|
-
import { AuthenticationRequirement } from "@yielded/auth/Sessions";
|
|
5
|
-
import { DateTime, Effect, Schema, Context, Layer } from "effect";
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
OAuthConnectedAuthorityMapping,
|
|
9
|
-
OAuthConnectedClientRegistrationTable,
|
|
10
|
-
OAuthConnectedCohortTable,
|
|
11
|
-
OAuthConnectedMapping,
|
|
12
|
-
OAuthConnectedPolicyInput,
|
|
13
|
-
OAuthConnectedRevocationMapping,
|
|
14
|
-
} from "../models/oauth-connected-model";
|
|
15
|
-
import type { SqlExpression as SQL, QueryFailure } from "../query-operations";
|
|
16
|
-
import { strings, clientKey, cohortKey, scopeKey, key } from "./connected-keys";
|
|
17
|
-
import { OAuthFlow } from "./flow";
|
|
18
|
-
import { CurrentOAuthTransaction } from "./owner";
|
|
19
|
-
import type { OAuthOwner, Row } from "./owner";
|
|
20
|
-
import { OAuthQueryCompiler } from "./query-compiler";
|
|
21
|
-
import {
|
|
22
|
-
digest,
|
|
23
|
-
invariant,
|
|
24
|
-
oauthIdentityKey,
|
|
25
|
-
sameRevision,
|
|
26
|
-
satisfies,
|
|
27
|
-
storage,
|
|
28
|
-
unavailable,
|
|
29
|
-
} from "./state";
|
|
30
|
-
type Table = object;
|
|
31
|
-
|
|
32
|
-
export type Authority = OAuthConnectedAuthorityMapping<any, any, any, any, any, any, any> & {
|
|
33
|
-
readonly client: Partial<Pick<OAuthConnectedClientRegistrationTable<any>, "encodeInsert">>;
|
|
34
|
-
readonly cohort: Partial<Pick<OAuthConnectedCohortTable<any>, "encodeInsert">>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Expression handles are supplied by the owning compiler, never decoded domain data.
|
|
38
|
-
export type Mapping = OAuthConnectedMapping<
|
|
39
|
-
any,
|
|
40
|
-
any,
|
|
41
|
-
any,
|
|
42
|
-
any,
|
|
43
|
-
any,
|
|
44
|
-
any,
|
|
45
|
-
any,
|
|
46
|
-
any,
|
|
47
|
-
any,
|
|
48
|
-
any,
|
|
49
|
-
any,
|
|
50
|
-
any,
|
|
51
|
-
any
|
|
52
|
-
>;
|
|
53
|
-
|
|
54
|
-
export type Revocations = OAuthConnectedRevocationMapping<any, any, any, any, any, any, any, any>;
|
|
55
|
-
|
|
56
|
-
export type Current = NonNullable<
|
|
57
|
-
Effect.Success<ReturnType<OAuthFlow["Service"]["currentSubject"]>>
|
|
58
|
-
>;
|
|
59
|
-
|
|
60
|
-
export interface ScopeAnchor {
|
|
61
|
-
readonly id: string;
|
|
62
|
-
row: Row;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ClientAnchor {
|
|
66
|
-
readonly id: string;
|
|
67
|
-
row: Row;
|
|
68
|
-
counter: number;
|
|
69
|
-
readonly scope: ScopeAnchor;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const make = Effect.gen(function* () {
|
|
73
|
-
const operations = yield* OAuthQueryCompiler;
|
|
74
|
-
const flow = yield* OAuthFlow;
|
|
75
|
-
|
|
76
|
-
const { and, eq, isNull, sql } = operations;
|
|
77
|
-
const { currentSubject } = flow;
|
|
78
|
-
const { both, col, copiedRow, equal } = operations;
|
|
79
|
-
|
|
80
|
-
const contextStorage = storage(M.OAuthConnectedTransactionContext);
|
|
81
|
-
|
|
82
|
-
const flowStorage = storage(M.OAuthConnectedPendingFlow);
|
|
83
|
-
|
|
84
|
-
const claimStorage = storage(M.OAuthConnectedClaim);
|
|
85
|
-
|
|
86
|
-
const tokenContextStorage = storage(M.OAuthConnectedTokenContext);
|
|
87
|
-
|
|
88
|
-
const sealedStorage = storage(M.OAuthConnectedSealedTokens);
|
|
89
|
-
|
|
90
|
-
const grantStorage = storage(M.OAuthConnectedStoredGrant);
|
|
91
|
-
|
|
92
|
-
const admissionStorage = storage(
|
|
93
|
-
Schema.Struct({
|
|
94
|
-
grant: M.OAuthConnectedStoredGrant,
|
|
95
|
-
authorization: M.OAuthConnectedUseAuthorization,
|
|
96
|
-
}),
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const commandStorage = storage(
|
|
100
|
-
Schema.Struct({
|
|
101
|
-
context: M.OAuthConnectedTokenContext,
|
|
102
|
-
originalDigest: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),
|
|
103
|
-
revocationJobId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),
|
|
104
|
-
}),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);
|
|
108
|
-
|
|
109
|
-
const refreshStorage = storage(M.OAuthConnectedRefreshClaim);
|
|
110
|
-
|
|
111
|
-
const jobStorage = storage(M.OAuthConnectedRevocationJob);
|
|
112
|
-
|
|
113
|
-
const summaryStorage = storage(M.OAuthConnectedSummary);
|
|
114
|
-
|
|
115
|
-
const disconnectedStorage = storage(M.OAuthConnectedDisconnected);
|
|
116
|
-
|
|
117
|
-
const safeInteger = Schema.Int.check(
|
|
118
|
-
Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const orderParser = Schema.decodeSync(safeInteger);
|
|
122
|
-
|
|
123
|
-
const canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));
|
|
124
|
-
|
|
125
|
-
const orderTextParser = Schema.decodeSync(canonicalOrder);
|
|
126
|
-
|
|
127
|
-
const orderNumber = (value: string) => {
|
|
128
|
-
const number = orderParser(Number(orderTextParser(value)));
|
|
129
|
-
|
|
130
|
-
invariant(String(number) === value);
|
|
131
|
-
|
|
132
|
-
return number;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const nativeOrder = (mapping: Authority, value: unknown) =>
|
|
136
|
-
orderParser(mapping.order.decode(value));
|
|
137
|
-
|
|
138
|
-
const initialGeneration = (cohort: string) =>
|
|
139
|
-
digest(cohort).pipe(
|
|
140
|
-
Effect.map((value) =>
|
|
141
|
-
M.OAuthConnectedTarget.fields.cohortGeneration.make("initial:" + value),
|
|
142
|
-
),
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const configuration = (flow: M.OAuthConnectedPendingFlow): M.OAuthConnectedConfiguration =>
|
|
146
|
-
snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);
|
|
147
|
-
|
|
148
|
-
const retainedUntil = (mapping: Authority, now: number) => {
|
|
149
|
-
invariant(
|
|
150
|
-
Number.isSafeInteger(mapping.retentionMillis) &&
|
|
151
|
-
mapping.retentionMillis >= 120000 &&
|
|
152
|
-
mapping.retentionMillis <= 2592000000,
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
return orderParser(now + mapping.retentionMillis);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const rowCount = Effect.fn("oauthConnected.rowCount")(function* (table: Table, where: SQL) {
|
|
159
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
160
|
-
|
|
161
|
-
const rows = yield* (
|
|
162
|
-
owner.database
|
|
163
|
-
.select({ value: sql`count(*)`.mapWith(Number) })
|
|
164
|
-
.from(table)
|
|
165
|
-
.where(where) as Effect.Effect<ReadonlyArray<{ value: number }>, QueryFailure>
|
|
166
|
-
).pipe(Effect.mapError(unavailable));
|
|
167
|
-
|
|
168
|
-
invariant(rows.length === 1);
|
|
169
|
-
|
|
170
|
-
return orderParser(rows[0]!.value);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const countCondition = (table: Table, where: SQL, count: number) =>
|
|
174
|
-
sql`(select count(*) from ${table} where ${where}) = ${count}`;
|
|
175
|
-
|
|
176
|
-
const current = Effect.fn("oauthConnected.current")(function* (
|
|
177
|
-
mapping: Mapping,
|
|
178
|
-
subject: OAuthAccountRevision["subjectId"],
|
|
179
|
-
) {
|
|
180
|
-
const native = yield* mapping.subjectId.toNative(subject);
|
|
181
|
-
|
|
182
|
-
return yield* currentSubject(mapping, native);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const nativeCopy = <N>(value: N): N => copiedRow({ value }).value as N;
|
|
186
|
-
|
|
187
|
-
const policyData = (input: OAuthConnectedPolicyInput<any>): OAuthConnectedPolicyInput<any> =>
|
|
188
|
-
Object.freeze({
|
|
189
|
-
...input,
|
|
190
|
-
subjectId: nativeCopy(input.subjectId),
|
|
191
|
-
revision: snapshotOAuthSync(M.OAuthConnectedUseAuthorization.fields.revision, input.revision),
|
|
192
|
-
...(input.kind === "sign-in"
|
|
193
|
-
? {
|
|
194
|
-
credential: snapshotOAuthSync(M.OAuthCredentialSnapshot, input.credential),
|
|
195
|
-
configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration),
|
|
196
|
-
}
|
|
197
|
-
: {
|
|
198
|
-
authorization:
|
|
199
|
-
input.kind === "action"
|
|
200
|
-
? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization)
|
|
201
|
-
: snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),
|
|
202
|
-
...(input.kind === "action"
|
|
203
|
-
? {
|
|
204
|
-
configuration: snapshotOAuthSync(
|
|
205
|
-
M.OAuthConnectedConfiguration,
|
|
206
|
-
input.configuration,
|
|
207
|
-
),
|
|
208
|
-
}
|
|
209
|
-
: {}),
|
|
210
|
-
}),
|
|
211
|
-
...(input.grant === undefined
|
|
212
|
-
? {}
|
|
213
|
-
: { grant: snapshotOAuthSync(M.OAuthConnectedTokenContext, input.grant) }),
|
|
214
|
-
}) as OAuthConnectedPolicyInput<any>;
|
|
215
|
-
|
|
216
|
-
const jobTable = (mapping: Authority) => {
|
|
217
|
-
const direct = (mapping as Partial<Revocations>).job;
|
|
218
|
-
const configured = (mapping as Partial<Mapping>).revocation;
|
|
219
|
-
|
|
220
|
-
return direct ?? (configured?.mode === "cohort" ? configured.job : undefined);
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const policy = Effect.fn("oauthConnected.policy")(function* (
|
|
224
|
-
mapping: Mapping,
|
|
225
|
-
input: OAuthConnectedPolicyInput<any>,
|
|
226
|
-
) {
|
|
227
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
228
|
-
|
|
229
|
-
invariant((mapping.policy.guards?.length ?? 0) <= 32);
|
|
230
|
-
for (const guard of mapping.policy.guards ?? []) {
|
|
231
|
-
const read = yield* owner.read(guard.table, guard.condition(policyData(input)), {
|
|
232
|
-
orderBy: col(guard.table, guard.orderBy),
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
invariant(read.rows.length > 0);
|
|
236
|
-
}
|
|
237
|
-
const condition = mapping.policy.condition(policyData(input));
|
|
238
|
-
const accepted = yield* owner.check(condition);
|
|
239
|
-
|
|
240
|
-
if (accepted) owner.postconditions.push(condition);
|
|
241
|
-
|
|
242
|
-
return accepted;
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
const action = Effect.fn("oauthConnected.action")(function* (
|
|
246
|
-
mapping: Mapping,
|
|
247
|
-
found: Current,
|
|
248
|
-
authorization: M.OAuthConnectedActionAuthorization,
|
|
249
|
-
operation: "issue" | "claim" | "settle" | "disconnect",
|
|
250
|
-
expected: {
|
|
251
|
-
readonly moduleId: string;
|
|
252
|
-
readonly flowId: string;
|
|
253
|
-
readonly commandId: string;
|
|
254
|
-
readonly revision: OAuthAccountRevision;
|
|
255
|
-
readonly intent: string;
|
|
256
|
-
readonly maximumAgeMillis: number;
|
|
257
|
-
readonly configuration: M.OAuthConnectedConfiguration;
|
|
258
|
-
readonly grant?: M.OAuthConnectedTokenContext;
|
|
259
|
-
},
|
|
260
|
-
) {
|
|
261
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
262
|
-
|
|
263
|
-
const challenge = authorization.challenge,
|
|
264
|
-
evidence = authorization.evidence;
|
|
265
|
-
|
|
266
|
-
const name =
|
|
267
|
-
operation === "issue"
|
|
268
|
-
? "connected-begin"
|
|
269
|
-
: operation === "disconnect"
|
|
270
|
-
? "connected-disconnect"
|
|
271
|
-
: "connected-complete";
|
|
272
|
-
|
|
273
|
-
const intentDigest = yield* digest(expected.intent);
|
|
274
|
-
|
|
275
|
-
const binding = yield* digest(
|
|
276
|
-
strings.encode([
|
|
277
|
-
"effect-auth/oauth-connected-action/v1",
|
|
278
|
-
expected.moduleId,
|
|
279
|
-
name,
|
|
280
|
-
expected.flowId,
|
|
281
|
-
expected.commandId,
|
|
282
|
-
intentDigest,
|
|
283
|
-
]),
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
challenge.moduleId !== expected.moduleId ||
|
|
288
|
-
challenge.action !== name ||
|
|
289
|
-
challenge.flowId !== expected.flowId ||
|
|
290
|
-
challenge.commandId !== expected.commandId ||
|
|
291
|
-
challenge.intentDigest !== intentDigest ||
|
|
292
|
-
challenge.bindingDigest !== binding ||
|
|
293
|
-
evidence.flowId !== expected.flowId ||
|
|
294
|
-
evidence.bindingDigest !== binding ||
|
|
295
|
-
!sameRevision(challenge.revision, expected.revision) ||
|
|
296
|
-
!sameRevision(evidence.revision, expected.revision) ||
|
|
297
|
-
!sameRevision(found.revision, expected.revision)
|
|
298
|
-
)
|
|
299
|
-
return false;
|
|
300
|
-
const now = yield* owner.now(mapping.clock);
|
|
301
|
-
|
|
302
|
-
const requirement = snapshotOAuthSync(
|
|
303
|
-
AuthenticationRequirement,
|
|
304
|
-
mapping.subject.decodeActionRequirement(copiedRow(found.row), name),
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
const revisions = new Map(
|
|
308
|
-
found.revision.credentials.map((item) => [item.credentialId, item.revision]),
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
evidence.proofs.some(
|
|
313
|
-
(proof) =>
|
|
314
|
-
!revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now,
|
|
315
|
-
)
|
|
316
|
-
)
|
|
317
|
-
return false;
|
|
318
|
-
for (const required of [authorization.requirement, requirement]) {
|
|
319
|
-
const age = Math.min(expected.maximumAgeMillis, required.maximumAgeMillis);
|
|
320
|
-
|
|
321
|
-
const fresh = evidence.proofs.filter(
|
|
322
|
-
(proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < age,
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
if (!satisfies(fresh, required)) return false;
|
|
326
|
-
owner.postconditions.push(
|
|
327
|
-
sql`${mapping.clock.engineNowMillis} >= ${now} and ${both(...fresh.map((proof) => sql`${mapping.clock.engineNowMillis} < ${DateTime.toEpochMillis(proof.verifiedAt) + age}`))}`,
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return yield* policy(mapping, {
|
|
332
|
-
subjectId: found.nativeId,
|
|
333
|
-
revision: found.revision,
|
|
334
|
-
kind: "action",
|
|
335
|
-
operation,
|
|
336
|
-
authorization,
|
|
337
|
-
configuration: expected.configuration,
|
|
338
|
-
...(expected.grant === undefined ? {} : { grant: expected.grant }),
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
const useAuthority = Effect.fn("oauthConnected.useAuthority")(function* (
|
|
343
|
-
mapping: Mapping,
|
|
344
|
-
authorization: M.OAuthConnectedUseAuthorization,
|
|
345
|
-
kind: "metadata" | "use",
|
|
346
|
-
grant?: M.OAuthConnectedTokenContext,
|
|
347
|
-
) {
|
|
348
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
349
|
-
const found = yield* current(mapping, authorization.revision.subjectId);
|
|
350
|
-
const now = yield* owner.now(mapping.clock);
|
|
351
|
-
|
|
352
|
-
if (
|
|
353
|
-
found === undefined ||
|
|
354
|
-
authorization.purpose !== kind ||
|
|
355
|
-
!sameRevision(found.revision, authorization.revision) ||
|
|
356
|
-
now >= authorization.expiresAtMillis ||
|
|
357
|
-
(grant !== undefined &&
|
|
358
|
-
(grant.moduleId !== authorization.moduleId ||
|
|
359
|
-
grant.subjectId !== authorization.revision.subjectId ||
|
|
360
|
-
(authorization.grantId !== undefined && authorization.grantId !== grant.grantId) ||
|
|
361
|
-
(authorization.profileKey !== undefined &&
|
|
362
|
-
authorization.profileKey !== grant.configuration.profile.key)))
|
|
363
|
-
)
|
|
364
|
-
return undefined;
|
|
365
|
-
if (
|
|
366
|
-
!(yield* policy(mapping, {
|
|
367
|
-
subjectId: found.nativeId,
|
|
368
|
-
revision: found.revision,
|
|
369
|
-
kind,
|
|
370
|
-
authorization,
|
|
371
|
-
...(grant === undefined ? {} : { grant }),
|
|
372
|
-
}))
|
|
373
|
-
)
|
|
374
|
-
return undefined;
|
|
375
|
-
owner.postconditions.push(
|
|
376
|
-
sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${authorization.expiresAtMillis}`,
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
return found;
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
const scopeCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ScopeAnchor>>>();
|
|
383
|
-
|
|
384
|
-
const clientCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ClientAnchor>>>();
|
|
385
|
-
|
|
386
|
-
const anchors = Effect.fn("oauthConnected.anchors")(function* <A>(
|
|
387
|
-
cache: WeakMap<OAuthOwner, Map<Table, Map<string, A>>>,
|
|
388
|
-
table: Table,
|
|
389
|
-
) {
|
|
390
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
391
|
-
let tables = cache.get(owner);
|
|
392
|
-
|
|
393
|
-
if (tables === undefined) {
|
|
394
|
-
tables = new Map();
|
|
395
|
-
cache.set(owner, tables);
|
|
396
|
-
}
|
|
397
|
-
let rows = tables.get(table);
|
|
398
|
-
|
|
399
|
-
if (rows === undefined) {
|
|
400
|
-
rows = new Map();
|
|
401
|
-
tables.set(table, rows);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return rows;
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
/** Empty registration ID is impossible in the public profile label schema. The
|
|
408
|
-
* distinct 52-byte key domain shares the physical table, never a client counter. */
|
|
409
|
-
const scope = Effect.fn("oauthConnected.scope")(function* (
|
|
410
|
-
mapping: Authority,
|
|
411
|
-
config: M.OAuthConnectedConfiguration,
|
|
412
|
-
create: boolean,
|
|
413
|
-
) {
|
|
414
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
415
|
-
|
|
416
|
-
const c = mapping.client,
|
|
417
|
-
id = yield* scopeKey(config.provider, config.issuer),
|
|
418
|
-
cache = yield* anchors(scopeCache, c.table);
|
|
419
|
-
|
|
420
|
-
const existing = cache.get(id);
|
|
421
|
-
|
|
422
|
-
if (existing !== undefined) return existing;
|
|
423
|
-
const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 });
|
|
424
|
-
|
|
425
|
-
if (read.rows.length === 0) {
|
|
426
|
-
const related = [
|
|
427
|
-
mapping.flow,
|
|
428
|
-
mapping.grant,
|
|
429
|
-
mapping.cohort,
|
|
430
|
-
...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),
|
|
431
|
-
];
|
|
432
|
-
|
|
433
|
-
invariant(
|
|
434
|
-
yield* owner.check(
|
|
435
|
-
both(
|
|
436
|
-
sql`not exists(select 1 from ${c.table} where ${owner.exact(c.table, { [c.provider]: config.provider, [c.issuer]: config.issuer })})`,
|
|
437
|
-
...related.map(
|
|
438
|
-
(v) =>
|
|
439
|
-
sql`not exists(select 1 from ${v.table} where not exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(v.table, v.clientKey)}))`,
|
|
440
|
-
),
|
|
441
|
-
),
|
|
442
|
-
),
|
|
443
|
-
);
|
|
444
|
-
if (!create) return undefined;
|
|
445
|
-
invariant(c.encodeInsert !== undefined);
|
|
446
|
-
|
|
447
|
-
const inserted = yield* owner.insert(
|
|
448
|
-
c.table,
|
|
449
|
-
{
|
|
450
|
-
...c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config)),
|
|
451
|
-
[c.clientKey]: id,
|
|
452
|
-
[c.provider]: config.provider,
|
|
453
|
-
[c.issuer]: config.issuer,
|
|
454
|
-
[c.clientRegistrationId]: "",
|
|
455
|
-
[c.counter]: mapping.order.encode(0),
|
|
456
|
-
[c.version]: owner.marker,
|
|
457
|
-
},
|
|
458
|
-
{ [c.clientKey]: id },
|
|
459
|
-
true,
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
read.rows = inserted.rows;
|
|
463
|
-
}
|
|
464
|
-
const row = read.rows[0]!;
|
|
465
|
-
|
|
466
|
-
invariant(
|
|
467
|
-
row[c.provider] === config.provider &&
|
|
468
|
-
row[c.issuer] === config.issuer &&
|
|
469
|
-
row[c.clientRegistrationId] === "" &&
|
|
470
|
-
nativeOrder(mapping, row[c.counter]) === 0,
|
|
471
|
-
);
|
|
472
|
-
const found = { id, row };
|
|
473
|
-
|
|
474
|
-
cache.set(id, found);
|
|
475
|
-
|
|
476
|
-
return found;
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
const touchScope = Effect.fn("oauthConnected.touchScope")(function* (
|
|
480
|
-
mapping: Authority,
|
|
481
|
-
found: ScopeAnchor,
|
|
482
|
-
) {
|
|
483
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
484
|
-
const c = mapping.client;
|
|
485
|
-
|
|
486
|
-
yield* owner.update(
|
|
487
|
-
c.table,
|
|
488
|
-
{ [c.clientKey]: found.id, [c.version]: found.row[c.version] },
|
|
489
|
-
{ [c.version]: owner.marker },
|
|
490
|
-
);
|
|
491
|
-
found.row = { ...found.row, [c.version]: owner.marker };
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
const readScope = Effect.fn("oauthConnected.readScope")(function* (
|
|
495
|
-
mapping: Authority,
|
|
496
|
-
provider: string,
|
|
497
|
-
issuer: string,
|
|
498
|
-
) {
|
|
499
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
500
|
-
|
|
501
|
-
const c = mapping.client,
|
|
502
|
-
id = yield* scopeKey(provider, issuer),
|
|
503
|
-
cache = yield* anchors(scopeCache, c.table),
|
|
504
|
-
cached = cache.get(id);
|
|
505
|
-
|
|
506
|
-
if (cached !== undefined) return cached;
|
|
507
|
-
|
|
508
|
-
const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),
|
|
509
|
-
row = read.rows[0];
|
|
510
|
-
|
|
511
|
-
invariant(
|
|
512
|
-
row !== undefined &&
|
|
513
|
-
row[c.provider] === provider &&
|
|
514
|
-
row[c.issuer] === issuer &&
|
|
515
|
-
row[c.clientRegistrationId] === "" &&
|
|
516
|
-
nativeOrder(mapping, row[c.counter]) === 0,
|
|
517
|
-
);
|
|
518
|
-
const found = { id, row };
|
|
519
|
-
|
|
520
|
-
cache.set(id, found);
|
|
521
|
-
|
|
522
|
-
return found;
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
const lockClientById = Effect.fn("oauthConnected.lockClientById")(function* (
|
|
526
|
-
mapping: Authority,
|
|
527
|
-
id: string,
|
|
528
|
-
) {
|
|
529
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
530
|
-
|
|
531
|
-
const c = mapping.client,
|
|
532
|
-
cache = yield* anchors(clientCache, c.table),
|
|
533
|
-
cached = cache.get(id);
|
|
534
|
-
|
|
535
|
-
if (cached !== undefined) return cached;
|
|
536
|
-
|
|
537
|
-
const discovery = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {
|
|
538
|
-
limit: 1,
|
|
539
|
-
observe: false,
|
|
540
|
-
lock: false,
|
|
541
|
-
}),
|
|
542
|
-
initial = discovery.rows[0];
|
|
543
|
-
|
|
544
|
-
invariant(initial !== undefined);
|
|
545
|
-
const scope = yield* readScope(mapping, initial[c.provider], initial[c.issuer]);
|
|
546
|
-
|
|
547
|
-
const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),
|
|
548
|
-
row = read.rows[0];
|
|
549
|
-
|
|
550
|
-
invariant(
|
|
551
|
-
row !== undefined &&
|
|
552
|
-
row[c.clientRegistrationId] !== "" &&
|
|
553
|
-
id ===
|
|
554
|
-
(yield* key("effect-auth/oauth-connected-client/v1", [
|
|
555
|
-
row[c.provider],
|
|
556
|
-
row[c.issuer],
|
|
557
|
-
row[c.clientRegistrationId],
|
|
558
|
-
])) &&
|
|
559
|
-
scope.id === (yield* scopeKey(row[c.provider], row[c.issuer])),
|
|
560
|
-
);
|
|
561
|
-
const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope };
|
|
562
|
-
|
|
563
|
-
cache.set(id, found);
|
|
564
|
-
|
|
565
|
-
return found;
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
const heldScope = Effect.fnUntraced(function* (
|
|
569
|
-
mapping: Authority,
|
|
570
|
-
provider: string,
|
|
571
|
-
issuer: string,
|
|
572
|
-
) {
|
|
573
|
-
const cache = yield* anchors(scopeCache, mapping.client.table);
|
|
574
|
-
|
|
575
|
-
return cache.get(yield* scopeKey(provider, issuer));
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
/** Cleanup obtains every scope then every client before entering any tuple. */
|
|
579
|
-
const prelockClients = Effect.fn("oauthConnected.prelockClients")(function* (
|
|
580
|
-
mapping: Authority,
|
|
581
|
-
ids: ReadonlyArray<string>,
|
|
582
|
-
releaseScopes: ReadonlyArray<{ readonly provider: string; readonly issuer: string }> = [],
|
|
583
|
-
) {
|
|
584
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
585
|
-
|
|
586
|
-
const unique = [...new Set(ids)].sort(),
|
|
587
|
-
c = mapping.client;
|
|
588
|
-
|
|
589
|
-
invariant(unique.length <= 4000);
|
|
590
|
-
const scopes = new Map<string, { provider: string; issuer: string; required: boolean }>();
|
|
591
|
-
|
|
592
|
-
for (const value of releaseScopes)
|
|
593
|
-
scopes.set(yield* scopeKey(value.provider, value.issuer), { ...value, required: false });
|
|
594
|
-
for (const id of unique) {
|
|
595
|
-
const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {
|
|
596
|
-
limit: 1,
|
|
597
|
-
lock: false,
|
|
598
|
-
observe: false,
|
|
599
|
-
}),
|
|
600
|
-
row = read.rows[0];
|
|
601
|
-
|
|
602
|
-
invariant(row !== undefined);
|
|
603
|
-
scopes.set(yield* scopeKey(row[c.provider], row[c.issuer]), {
|
|
604
|
-
provider: row[c.provider],
|
|
605
|
-
issuer: row[c.issuer],
|
|
606
|
-
required: true,
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
for (const [id, { provider, issuer, required }] of [...scopes].sort(([a], [b]) =>
|
|
610
|
-
a < b ? -1 : a > b ? 1 : 0,
|
|
611
|
-
)) {
|
|
612
|
-
if (required) yield* readScope(mapping, provider, issuer);
|
|
613
|
-
else {
|
|
614
|
-
const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {
|
|
615
|
-
limit: 1,
|
|
616
|
-
}),
|
|
617
|
-
row = read.rows[0];
|
|
618
|
-
|
|
619
|
-
if (row !== undefined) {
|
|
620
|
-
invariant(
|
|
621
|
-
row[c.provider] === provider &&
|
|
622
|
-
row[c.issuer] === issuer &&
|
|
623
|
-
row[c.clientRegistrationId] === "" &&
|
|
624
|
-
nativeOrder(mapping, row[c.counter]) === 0,
|
|
625
|
-
);
|
|
626
|
-
(yield* anchors(scopeCache, c.table)).set(id, { id, row });
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
for (const id of unique) yield* lockClientById(mapping, id);
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
const client = Effect.fn("oauthConnected.client")(function* (
|
|
634
|
-
mapping: Authority,
|
|
635
|
-
config: M.OAuthConnectedConfiguration,
|
|
636
|
-
create: boolean,
|
|
637
|
-
) {
|
|
638
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
639
|
-
|
|
640
|
-
const c = mapping.client,
|
|
641
|
-
id = yield* clientKey(config),
|
|
642
|
-
where = { [c.clientKey]: id };
|
|
643
|
-
|
|
644
|
-
const heldScope = yield* scope(mapping, config, create);
|
|
645
|
-
|
|
646
|
-
if (heldScope === undefined) return undefined;
|
|
647
|
-
|
|
648
|
-
const cache = yield* anchors(clientCache, c.table),
|
|
649
|
-
cached = cache.get(id);
|
|
650
|
-
|
|
651
|
-
if (cached !== undefined) return cached;
|
|
652
|
-
let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });
|
|
653
|
-
|
|
654
|
-
if (read.rows.length === 0) {
|
|
655
|
-
const related = [
|
|
656
|
-
mapping.flow,
|
|
657
|
-
mapping.grant,
|
|
658
|
-
mapping.cohort,
|
|
659
|
-
...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),
|
|
660
|
-
];
|
|
661
|
-
|
|
662
|
-
invariant(
|
|
663
|
-
yield* owner.check(
|
|
664
|
-
both(
|
|
665
|
-
...related.map(
|
|
666
|
-
(v) =>
|
|
667
|
-
sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.clientKey), id)})`,
|
|
668
|
-
),
|
|
669
|
-
),
|
|
670
|
-
),
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
if (read.rows.length === 0 && create) {
|
|
674
|
-
const inserted = yield* owner.insert(
|
|
675
|
-
c.table,
|
|
676
|
-
{
|
|
677
|
-
...(invariant(c.encodeInsert !== undefined),
|
|
678
|
-
c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config))),
|
|
679
|
-
...where,
|
|
680
|
-
[c.provider]: config.provider,
|
|
681
|
-
[c.issuer]: config.issuer,
|
|
682
|
-
[c.clientRegistrationId]: config.profile.clientRegistrationId,
|
|
683
|
-
[c.counter]: mapping.order.encode(0),
|
|
684
|
-
[c.version]: owner.marker,
|
|
685
|
-
},
|
|
686
|
-
where,
|
|
687
|
-
true,
|
|
688
|
-
);
|
|
689
|
-
|
|
690
|
-
read.rows = inserted.rows;
|
|
691
|
-
}
|
|
692
|
-
const row = read.rows[0];
|
|
693
|
-
|
|
694
|
-
if (row === undefined) return undefined;
|
|
695
|
-
invariant(
|
|
696
|
-
row[c.provider] === config.provider &&
|
|
697
|
-
row[c.issuer] === config.issuer &&
|
|
698
|
-
row[c.clientRegistrationId] === config.profile.clientRegistrationId,
|
|
699
|
-
);
|
|
700
|
-
const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope: heldScope };
|
|
701
|
-
|
|
702
|
-
cache.set(id, found);
|
|
703
|
-
|
|
704
|
-
return found;
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
const nextOrder = Effect.fn("oauthConnected.nextOrder")(function* (
|
|
708
|
-
mapping: Authority,
|
|
709
|
-
found: NonNullable<Effect.Success<ReturnType<typeof client>>>,
|
|
710
|
-
) {
|
|
711
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
712
|
-
|
|
713
|
-
const next = orderParser(found.counter + 1),
|
|
714
|
-
c = mapping.client;
|
|
715
|
-
|
|
716
|
-
yield* owner.update(
|
|
717
|
-
c.table,
|
|
718
|
-
{ [c.clientKey]: found.id, [c.counter]: mapping.order.encode(found.counter) },
|
|
719
|
-
{ [c.counter]: mapping.order.encode(next), [c.version]: owner.marker },
|
|
720
|
-
);
|
|
721
|
-
found.counter = next;
|
|
722
|
-
|
|
723
|
-
return next;
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
const cohort = Effect.fn("oauthConnected.cohort")(function* (
|
|
727
|
-
mapping: Authority,
|
|
728
|
-
clientId: string,
|
|
729
|
-
identityId: string,
|
|
730
|
-
create: boolean,
|
|
731
|
-
) {
|
|
732
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
733
|
-
|
|
734
|
-
const c = mapping.cohort,
|
|
735
|
-
id = yield* cohortKey(clientId, identityId),
|
|
736
|
-
where = { [c.cohortKey]: id };
|
|
737
|
-
|
|
738
|
-
let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });
|
|
739
|
-
|
|
740
|
-
if (read.rows.length === 0) {
|
|
741
|
-
const related = [
|
|
742
|
-
mapping.flow,
|
|
743
|
-
mapping.grant,
|
|
744
|
-
...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),
|
|
745
|
-
];
|
|
746
|
-
|
|
747
|
-
invariant(
|
|
748
|
-
yield* owner.check(
|
|
749
|
-
both(
|
|
750
|
-
...related.map(
|
|
751
|
-
(v) =>
|
|
752
|
-
sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.cohortKey), id)})`,
|
|
753
|
-
),
|
|
754
|
-
),
|
|
755
|
-
),
|
|
756
|
-
);
|
|
757
|
-
}
|
|
758
|
-
if (read.rows.length === 0 && create) {
|
|
759
|
-
const inserted = yield* owner.insert(
|
|
760
|
-
c.table,
|
|
761
|
-
{
|
|
762
|
-
...(invariant(c.encodeInsert !== undefined),
|
|
763
|
-
c.encodeInsert({ clientKey: clientId, identityKey: identityId })),
|
|
764
|
-
...where,
|
|
765
|
-
[c.clientKey]: clientId,
|
|
766
|
-
[c.identityKey]: identityId,
|
|
767
|
-
[c.generation]: yield* initialGeneration(id),
|
|
768
|
-
[c.cutoff]: mapping.order.encode(0),
|
|
769
|
-
[c.state]: "Open",
|
|
770
|
-
[c.version]: owner.marker,
|
|
771
|
-
},
|
|
772
|
-
where,
|
|
773
|
-
true,
|
|
774
|
-
);
|
|
775
|
-
|
|
776
|
-
read.rows = inserted.rows;
|
|
777
|
-
}
|
|
778
|
-
const row = read.rows[0];
|
|
779
|
-
|
|
780
|
-
if (row === undefined)
|
|
781
|
-
return {
|
|
782
|
-
id,
|
|
783
|
-
row: undefined,
|
|
784
|
-
generation: yield* initialGeneration(id),
|
|
785
|
-
cutoff: 0,
|
|
786
|
-
blocked: false,
|
|
787
|
-
};
|
|
788
|
-
invariant(
|
|
789
|
-
row[c.clientKey] === clientId &&
|
|
790
|
-
row[c.identityKey] === identityId &&
|
|
791
|
-
["Open", "Blocked"].includes(row[c.state]),
|
|
792
|
-
);
|
|
793
|
-
|
|
794
|
-
const generation = snapshotOAuthSync(
|
|
795
|
-
M.OAuthConnectedTarget.fields.cohortGeneration,
|
|
796
|
-
row[c.generation],
|
|
797
|
-
);
|
|
798
|
-
|
|
799
|
-
return {
|
|
800
|
-
id,
|
|
801
|
-
row,
|
|
802
|
-
generation,
|
|
803
|
-
cutoff: nativeOrder(mapping, row[c.cutoff]),
|
|
804
|
-
blocked: row[c.state] === "Blocked",
|
|
805
|
-
};
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
const readGrant = Effect.fn("oauthConnected.readGrant")(function* (
|
|
809
|
-
mapping: Authority,
|
|
810
|
-
moduleId: string,
|
|
811
|
-
grantId: string,
|
|
812
|
-
lock = true,
|
|
813
|
-
) {
|
|
814
|
-
const owner = yield* CurrentOAuthTransaction;
|
|
815
|
-
const g = mapping.grant;
|
|
816
|
-
|
|
817
|
-
const read = yield* owner.read(
|
|
818
|
-
g.table,
|
|
819
|
-
equal(g.table, { [g.moduleId]: moduleId, [g.grantId]: grantId }),
|
|
820
|
-
{ limit: 1, lock, admissionOnly: lock, observe: false },
|
|
821
|
-
);
|
|
822
|
-
|
|
823
|
-
const row = read.rows[0];
|
|
824
|
-
|
|
825
|
-
if (row === undefined) return undefined;
|
|
826
|
-
if (lock) owner.observations.push(read);
|
|
827
|
-
const context = tokenContextStorage.decode(row[g.context]);
|
|
828
|
-
const native = yield* mapping.subjectId.toNative(context.subjectId);
|
|
829
|
-
|
|
830
|
-
invariant(
|
|
831
|
-
context.moduleId === moduleId &&
|
|
832
|
-
context.grantId === grantId &&
|
|
833
|
-
mapping.subjectId.equals(native, row[g.subjectId]) &&
|
|
834
|
-
row[g.identityKey] === (yield* oauthIdentityKey(context.identity)) &&
|
|
835
|
-
row[g.clientKey] === (yield* clientKey(context.configuration)) &&
|
|
836
|
-
row[g.cohortKey] === (yield* cohortKey(row[g.clientKey], row[g.identityKey])) &&
|
|
837
|
-
row[g.profileKey] === context.configuration.profile.key &&
|
|
838
|
-
row[g.grantVersion] === context.grantVersion &&
|
|
839
|
-
row[g.tokenVersion] === context.tokenVersion &&
|
|
840
|
-
row[g.cohortGeneration] === context.cohortGeneration,
|
|
841
|
-
);
|
|
842
|
-
|
|
843
|
-
return {
|
|
844
|
-
row,
|
|
845
|
-
context,
|
|
846
|
-
native,
|
|
847
|
-
sealed: row[g.sealed] === null ? undefined : sealedStorage.decode(row[g.sealed]),
|
|
848
|
-
};
|
|
849
|
-
});
|
|
850
|
-
|
|
851
|
-
const unknownWork = (mapping: Authority, clientId: string | SQL, cutoff?: number) => {
|
|
852
|
-
const f = mapping.flow;
|
|
853
|
-
|
|
854
|
-
return both(
|
|
855
|
-
eq(col(f.table, f.clientKey), clientId),
|
|
856
|
-
eq(col(f.table, f.work), "Unresolved"),
|
|
857
|
-
isNull(col(f.table, f.cohortKey)),
|
|
858
|
-
cutoff === undefined
|
|
859
|
-
? undefined
|
|
860
|
-
: sql`${col(f.table, f.claimOrder)} <= ${mapping.order.encode(cutoff)}`,
|
|
861
|
-
);
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
const cohortWork = (mapping: Authority, id: string | SQL) => {
|
|
865
|
-
const f = mapping.flow,
|
|
866
|
-
g = mapping.grant;
|
|
867
|
-
|
|
868
|
-
return both(
|
|
869
|
-
sql`not exists(select 1 from ${f.table} where ${and(eq(col(f.table, f.cohortKey), id), eq(col(f.table, f.work), "Unresolved"))})`,
|
|
870
|
-
sql`not exists(select 1 from ${g.table} where ${and(eq(col(g.table, g.cohortKey), id), eq(col(g.table, g.refreshWork), "Unresolved"))})`,
|
|
871
|
-
);
|
|
872
|
-
};
|
|
873
|
-
|
|
874
|
-
return {
|
|
875
|
-
contextStorage,
|
|
876
|
-
flowStorage,
|
|
877
|
-
claimStorage,
|
|
878
|
-
tokenContextStorage,
|
|
879
|
-
sealedStorage,
|
|
880
|
-
grantStorage,
|
|
881
|
-
admissionStorage,
|
|
882
|
-
commandStorage,
|
|
883
|
-
disconnectStorage,
|
|
884
|
-
refreshStorage,
|
|
885
|
-
jobStorage,
|
|
886
|
-
summaryStorage,
|
|
887
|
-
disconnectedStorage,
|
|
888
|
-
orderNumber,
|
|
889
|
-
nativeOrder,
|
|
890
|
-
clientKey,
|
|
891
|
-
cohortKey,
|
|
892
|
-
initialGeneration,
|
|
893
|
-
configuration,
|
|
894
|
-
retainedUntil,
|
|
895
|
-
rowCount,
|
|
896
|
-
countCondition,
|
|
897
|
-
current,
|
|
898
|
-
nativeCopy,
|
|
899
|
-
jobTable,
|
|
900
|
-
policy,
|
|
901
|
-
action,
|
|
902
|
-
useAuthority,
|
|
903
|
-
scopeKey,
|
|
904
|
-
scope,
|
|
905
|
-
touchScope,
|
|
906
|
-
readScope,
|
|
907
|
-
lockClientById,
|
|
908
|
-
heldScope,
|
|
909
|
-
prelockClients,
|
|
910
|
-
client,
|
|
911
|
-
nextOrder,
|
|
912
|
-
cohort,
|
|
913
|
-
readGrant,
|
|
914
|
-
unknownWork,
|
|
915
|
-
cohortWork,
|
|
916
|
-
};
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
export class OAuthConnectedState extends Context.Service<
|
|
920
|
-
OAuthConnectedState,
|
|
921
|
-
Effect.Success<typeof make>
|
|
922
|
-
>()("effect-auth/persistence/OAuthConnectedState") {
|
|
923
|
-
static readonly layer = Layer.effect(OAuthConnectedState, make);
|
|
924
|
-
}
|