@yielded/auth-persistence 0.1.0-beta.22 → 0.1.0-beta.24
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 +11 -0
- package/dist/Adapter.d.mts +13 -5
- package/dist/Adapter.mjs +9 -2
- package/dist/OAuthPersistence.d.mts +87 -0
- package/dist/OAuthPersistence.mjs +125 -0
- package/dist/OAuthPersistence.mjs.map +1 -0
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +3 -1
- package/dist/internal/authority-snapshot.mjs +53 -0
- package/dist/internal/authority-snapshot.mjs.map +1 -0
- package/dist/internal/configuration.d.mts +1 -1
- package/dist/internal/configuration.mjs.map +1 -1
- package/dist/internal/models/oauth-connected-model.d.mts +294 -0
- package/dist/internal/models/oauth-connected-model.mjs +22 -0
- package/dist/internal/models/oauth-connected-model.mjs.map +1 -0
- package/dist/internal/models/oauth-model.d.mts +467 -0
- package/dist/internal/models/oauth-model.mjs +49 -0
- package/dist/internal/models/oauth-model.mjs.map +1 -0
- package/dist/internal/models/password-model.d.mts +4 -97
- package/dist/internal/models/password-model.mjs +0 -3
- package/dist/internal/models/password-model.mjs.map +1 -1
- package/dist/internal/native-sql-table.d.mts +34 -0
- package/dist/internal/native-sql-table.mjs +111 -0
- package/dist/internal/native-sql-table.mjs.map +1 -0
- package/dist/internal/oauth/accounts.d.mts +8 -0
- package/dist/internal/oauth/accounts.mjs +379 -0
- package/dist/internal/oauth/accounts.mjs.map +1 -0
- package/dist/internal/oauth/connected-access.d.mts +9 -0
- package/dist/internal/oauth/connected-access.mjs +229 -0
- package/dist/internal/oauth/connected-access.mjs.map +1 -0
- package/dist/internal/oauth/connected-collection.d.mts +7 -0
- package/dist/internal/oauth/connected-collection.mjs +214 -0
- package/dist/internal/oauth/connected-collection.mjs.map +1 -0
- package/dist/internal/oauth/connected-custody.d.mts +6 -0
- package/dist/internal/oauth/connected-custody.mjs +165 -0
- package/dist/internal/oauth/connected-custody.mjs.map +1 -0
- package/dist/internal/oauth/connected-flow.d.mts +7 -0
- package/dist/internal/oauth/connected-flow.mjs +324 -0
- package/dist/internal/oauth/connected-flow.mjs.map +1 -0
- package/dist/internal/oauth/connected-input.mjs +122 -0
- package/dist/internal/oauth/connected-input.mjs.map +1 -0
- package/dist/internal/oauth/connected-keys.d.mts +2 -0
- package/dist/internal/oauth/connected-keys.mjs +22 -0
- package/dist/internal/oauth/connected-keys.mjs.map +1 -0
- package/dist/internal/oauth/connected-maintenance.d.mts +9 -0
- package/dist/internal/oauth/connected-maintenance.mjs +226 -0
- package/dist/internal/oauth/connected-maintenance.mjs.map +1 -0
- package/dist/internal/oauth/connected-management.d.mts +9 -0
- package/dist/internal/oauth/connected-management.mjs +243 -0
- package/dist/internal/oauth/connected-management.mjs.map +1 -0
- package/dist/internal/oauth/connected-reference.mjs +63 -0
- package/dist/internal/oauth/connected-reference.mjs.map +1 -0
- package/dist/internal/oauth/connected-settlement.d.mts +8 -0
- package/dist/internal/oauth/connected-settlement.mjs +141 -0
- package/dist/internal/oauth/connected-settlement.mjs.map +1 -0
- package/dist/internal/oauth/connected-sign-in.d.mts +10 -0
- package/dist/internal/oauth/connected-sign-in.mjs +281 -0
- package/dist/internal/oauth/connected-sign-in.mjs.map +1 -0
- package/dist/internal/oauth/connected-state.d.mts +14 -0
- package/dist/internal/oauth/connected-state.mjs +469 -0
- package/dist/internal/oauth/connected-state.mjs.map +1 -0
- package/dist/internal/oauth/connected-target.d.mts +21 -0
- package/dist/internal/oauth/connected-target.mjs +117 -0
- package/dist/internal/oauth/connected-target.mjs.map +1 -0
- package/dist/internal/oauth/flow.d.mts +5 -0
- package/dist/internal/oauth/flow.mjs +279 -0
- package/dist/internal/oauth/flow.mjs.map +1 -0
- package/dist/internal/oauth/input.mjs +127 -0
- package/dist/internal/oauth/input.mjs.map +1 -0
- package/dist/internal/oauth/owner.d.mts +10 -0
- package/dist/internal/oauth/owner.mjs +10 -0
- package/dist/internal/oauth/owner.mjs.map +1 -0
- package/dist/internal/oauth/query-compiler.d.mts +7 -0
- package/dist/internal/oauth/query-compiler.mjs +9 -0
- package/dist/internal/oauth/query-compiler.mjs.map +1 -0
- package/dist/internal/oauth/registration.d.mts +7 -0
- package/dist/internal/oauth/registration.mjs +393 -0
- package/dist/internal/oauth/registration.mjs.map +1 -0
- package/dist/internal/oauth/state.mjs +107 -0
- package/dist/internal/oauth/state.mjs.map +1 -0
- package/dist/internal/oauth/target.d.mts +31 -0
- package/dist/internal/oauth/target.mjs +273 -0
- package/dist/internal/oauth/target.mjs.map +1 -0
- package/dist/internal/oauth-kernel.d.mts +1423 -0
- package/dist/internal/oauth-kernel.mjs +187 -0
- package/dist/internal/oauth-kernel.mjs.map +1 -0
- package/dist/internal/oauth-proxy.d.mts +31 -0
- package/dist/internal/oauth-proxy.mjs +129 -0
- package/dist/internal/oauth-proxy.mjs.map +1 -0
- package/dist/internal/passkey/target.d.mts +1 -1
- package/dist/internal/passkey-kernel.d.mts +5 -5
- package/dist/internal/passkeys.mjs +1 -1
- package/dist/internal/password-credentials.d.mts +11 -0
- package/dist/internal/password-credentials.mjs +121 -0
- package/dist/internal/password-credentials.mjs.map +1 -0
- package/dist/internal/password-kernel.d.mts +15 -28
- package/dist/internal/password-kernel.mjs +35 -236
- package/dist/internal/password-kernel.mjs.map +1 -1
- package/dist/internal/persistence.d.mts +2 -0
- package/dist/internal/persistence.mjs +5 -5
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/query-operations.d.mts +2 -0
- package/dist/internal/session-kernel.d.mts +5 -3
- package/dist/internal/session-kernel.mjs +95 -29
- package/dist/internal/session-kernel.mjs.map +1 -1
- package/dist/internal/sql-oauth-connected-model.d.mts +29 -0
- package/dist/internal/sql-oauth-connected-model.mjs +7 -0
- package/dist/internal/sql-oauth-connected-model.mjs.map +1 -0
- package/dist/internal/sql-oauth-model.d.mts +60 -0
- package/dist/internal/sql-oauth-model.mjs +10 -0
- package/dist/internal/sql-oauth-model.mjs.map +1 -0
- package/dist/internal/sql-persistence.mjs +3 -1
- package/dist/internal/sql-persistence.mjs.map +1 -1
- package/dist/internal/sql-query.d.mts +12 -0
- package/dist/internal/sql-query.mjs +15 -18
- package/dist/internal/sql-query.mjs.map +1 -1
- package/dist/internal/sql-storage-validation.mjs +54 -0
- package/dist/internal/sql-storage-validation.mjs.map +1 -0
- package/dist/internal/storage-mapping.mjs +2 -67
- package/dist/internal/storage-mapping.mjs.map +1 -1
- package/dist/internal/storage-plans.d.mts +7 -0
- package/dist/internal/storage-plans.mjs +189 -0
- package/dist/internal/storage-plans.mjs.map +1 -0
- package/dist/internal/storage-tables.d.mts +0 -99
- package/dist/internal/storage-tables.mjs +0 -43
- package/dist/internal/storage-tables.mjs.map +1 -1
- package/dist/internal/storage-validation.d.mts +6 -1
- package/dist/internal/storage-validation.mjs +42 -1
- package/dist/internal/storage-validation.mjs.map +1 -1
- package/dist/internal/transaction-execution-kernel.d.mts +1 -1
- package/dist/internal/transaction-kernel.d.mts +1 -1
- package/dist/internal/transaction-kernel.mjs +3 -2
- package/dist/internal/transaction-kernel.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Adapter.ts +97 -8
- package/src/OAuthPersistence.ts +427 -0
- package/src/index.ts +3 -0
- package/src/internal/authority-snapshot.ts +91 -0
- package/src/internal/configuration.ts +1 -8
- package/src/internal/models/oauth-connected-model.ts +396 -0
- package/src/internal/models/oauth-model.ts +708 -0
- package/src/internal/models/password-model.ts +0 -120
- package/src/internal/native-sql-table.ts +178 -0
- package/src/internal/oauth/accounts.ts +838 -0
- package/src/internal/oauth/connected-access.ts +388 -0
- package/src/internal/oauth/connected-collection.ts +345 -0
- package/src/internal/oauth/connected-custody.ts +308 -0
- package/src/internal/oauth/connected-flow.ts +562 -0
- package/src/internal/oauth/connected-input.ts +147 -0
- package/src/internal/oauth/connected-keys.ts +31 -0
- package/src/internal/oauth/connected-maintenance.ts +379 -0
- package/src/internal/oauth/connected-management.ts +391 -0
- package/src/internal/oauth/connected-reference.ts +135 -0
- package/src/internal/oauth/connected-settlement.ts +278 -0
- package/src/internal/oauth/connected-sign-in.ts +472 -0
- package/src/internal/oauth/connected-state.ts +924 -0
- package/src/internal/oauth/connected-target.ts +307 -0
- package/src/internal/oauth/flow.ts +505 -0
- package/src/internal/oauth/input.ts +201 -0
- package/src/internal/oauth/owner.ts +22 -0
- package/src/internal/oauth/query-compiler.ts +15 -0
- package/src/internal/oauth/registration.ts +676 -0
- package/src/internal/oauth/state.ts +218 -0
- package/src/internal/oauth/target.ts +803 -0
- package/src/internal/oauth-kernel.ts +294 -0
- package/src/internal/oauth-proxy.ts +176 -0
- package/src/internal/password-credentials.ts +245 -0
- package/src/internal/password-kernel.ts +98 -712
- package/src/internal/persistence.ts +5 -10
- package/src/internal/query-operations.ts +2 -0
- package/src/internal/session-kernel.ts +231 -81
- package/src/internal/sql-oauth-connected-model.ts +145 -0
- package/src/internal/sql-oauth-model.ts +263 -0
- package/src/internal/sql-persistence.ts +2 -0
- package/src/internal/sql-query.ts +16 -13
- package/src/internal/sql-storage-validation.ts +64 -0
- package/src/internal/storage-mapping.ts +0 -66
- package/src/internal/storage-plans.ts +218 -0
- package/src/internal/storage-tables.ts +0 -35
- package/src/internal/storage-validation.ts +58 -0
- package/src/internal/transaction-kernel.ts +6 -2
package/README.md
CHANGED
|
@@ -9,10 +9,21 @@ Drizzle integrations live in `@yielded/auth-persistence-drizzle`; this package h
|
|
|
9
9
|
no Drizzle dependency or exports. Core workflows and replaceable service contracts
|
|
10
10
|
remain in `@yielded/auth`.
|
|
11
11
|
|
|
12
|
+
`OAuthPersistence` supplies upstream provider sign-in, registration, login linking and
|
|
13
|
+
unlinking, and retained grants through explicit table mappings on PostgreSQL and
|
|
14
|
+
SQLite with interactive transactions. Provide `SqlClient`, Effect `Crypto`, and
|
|
15
|
+
lifecycle hooks; applications own subjects, policies, keys, and migrations. See the
|
|
16
|
+
[OAuth adapter reference](../../docs/src/content/docs/reference/adapters.md#oauth)
|
|
17
|
+
and [runnable Effect SQL consumer](../../examples/persistence-sql).
|
|
18
|
+
|
|
12
19
|
`OAuthServerPersistence` supplies independent, single-table consent and grant
|
|
13
20
|
storage for [MCP authorization](../../docs/src/content/docs/guide/oauth.mdx#authorize-mcp-clients).
|
|
14
21
|
Its conditional writes and monotonic revocation require standalone commits.
|
|
15
22
|
|
|
23
|
+
`OAuthProxyPersistence` stores encrypted attempts for the
|
|
24
|
+
[OAuth callback proxy](../../docs/src/content/docs/reference/oauth.md#callback-proxy)
|
|
25
|
+
on SQLite/D1 or PostgreSQL. Its operations require standalone commits.
|
|
26
|
+
|
|
16
27
|
Applications own subject provisioning, policy, claims, delivery, and their database
|
|
17
28
|
connection and migration runner.
|
|
18
29
|
|
package/dist/Adapter.d.mts
CHANGED
|
@@ -6,11 +6,12 @@ import { AnyEmailAddressMapping, AnyEmailRegistrationMapping, AnyEmailSignInMapp
|
|
|
6
6
|
import { D1PasskeyMapping, PasskeyAdmissionTable, PasskeyCeremonyMapping, PasskeyChargeInsert, PasskeyChargeKind, PasskeyChargeTable, PasskeyClock, PasskeyColumn, PasskeyCredentialMapping, PasskeyCredentialOwnershipTable, PasskeyCredentialReadTable, PasskeyCredentialServices, PasskeyEnrollmentContextMapping, PasskeyEnrollmentContextServices, PasskeyFactorReadTable, PasskeyFlowInsert, PasskeyFlowState, PasskeyFlowTable, PasskeyHandleOwnershipTable, PasskeyHandleReadTable, PasskeyHandleReservationTable, PasskeyMappingSource, PasskeyModuleTable, PasskeyPersistenceMapping, PasskeyPersistenceServices, PasskeyPolicyGuard, PasskeySubjectIdCodec, PasskeySubjectReadTable, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyPersistenceLayer, passkeyPolicyGuard, requiredPasskeyCredentialConstraints, requiredPasskeyPersistenceConstraints } from "./internal/models/passkey-model.mjs";
|
|
7
7
|
import { PasskeyRegistrationCeremonyCapabilities, PasskeyRegistrationCeremonyMapping, PasskeyRegistrationCeremonyServices, PasskeyRegistrationIntentReadTable, requiredPasskeyRegistrationCeremonyConstraints } from "./internal/models/passkey-registration-ceremony-model.mjs";
|
|
8
8
|
import { PasskeyCommandTable, PasskeyCredentialInsert, PasskeyInvalidationInput, PasskeyInvalidationMutation, PasskeyManagementMapping, PasskeyManagementServices, PasskeyRegistrationMapping, PasskeyRegistrationServices, PasskeyRegistrationWriter, PasskeyWriteTables, passkeyInvalidationMutation, requiredPasskeyManagementConstraints, requiredPasskeyRegistrationWriteConstraints } from "./internal/models/passkey-write-model.mjs";
|
|
9
|
-
import { AnyPasswordPersistenceMapping, AnyPasswordRegistrationMapping, D1PasswordPersistenceMapping,
|
|
9
|
+
import { AnyPasswordPersistenceMapping, AnyPasswordRegistrationMapping, D1PasswordPersistenceMapping, PasswordAuthorityCredentialTable, PasswordCommandTable, PasswordConstraintClassifier, PasswordCredentialTable, PasswordD1Clock, PasswordIdentifierTable, PasswordPersistenceMapping, PasswordRegistrationConstraintClassifier, PasswordRegistrationIntent, PasswordRegistrationMapping, PasswordRegistrationProvisioning, PasswordRegistrationState, PasswordRegistrationTable, PasswordSubjectTable, RequiredPasswordConstraints, RequiredPasswordRegistrationConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "./internal/models/password-model.mjs";
|
|
10
10
|
import { AnyProofPersistenceMapping, D1ProofPersistenceMapping, ProofAbuseEventTable, ProofAction, ProofAuthorityInput, ProofAuthorityTables, ProofCommandDecision, ProofCommandKind, ProofCommandTable, ProofConstraintClassifier, ProofContinuationRecord, ProofContinuationTable, ProofD1Clock, ProofDeliveryState, ProofFailureEventTable, ProofGenerationState, ProofGenerationTable, ProofPersistenceMapping, ProofRateScopeTable, ProofRequestTable, ProofScopeKeys, ProofScopeKind, ProofSeriesTable, RequiredProofConstraints, requiredProofConstraints } from "./internal/models/proof-model.mjs";
|
|
11
11
|
import { AuthenticationAuthorityMapping, D1AuthenticationAuthorityMapping, D1PendingAuthenticationMapping, D1SessionClockMapping, D1SignedSessionValidityMapping, D1StatefulSessionMapping, PendingAuthenticationMapping, PendingAuthenticationTables, RequiredPendingAuthenticationConstraints, RequiredSessionConstraints, RequiredSignedValidityConstraints, RequiredStatefulPendingConstraints, SessionAuthorityTables, SessionConstraintClassifier, SessionFlowTables, SessionIdCodec, SessionSubjectTables, SignedSessionValidityMapping, SignedSessionValidityTables, StatefulSessionMapping, StatefulSessionTables, requiredPendingAuthenticationConstraints, requiredSessionConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints } from "./internal/models/session-model.mjs";
|
|
12
12
|
import { D1SessionStepUpMapping, RequiredSessionStepUpConstraints, SessionStepUpIntentTables, SessionStepUpMapping, SessionStepUpSourceTables, requiredSessionStepUpConstraints } from "./internal/models/step-up-model.mjs";
|
|
13
13
|
import { requireStandalone } from "./internal/standalone.mjs";
|
|
14
|
+
import { OAuthProxySqlTable, makeOAuthProxyPersistence, oauthProxyColumns } from "./internal/oauth-proxy.mjs";
|
|
14
15
|
import { decodeStepUpIntent, encodeStepUpIntent, stepUpIntentLive, validateStepUpPlan } from "./internal/step-up-state.mjs";
|
|
15
16
|
import { CurrentProofSql, ProofSqlConfiguration, ProofSqlDatabase, ProofSqlQuery, makeProofKernel } from "./internal/proof-kernel.mjs";
|
|
16
17
|
import { CurrentAddress, CurrentEmailSql, EmailSqlConfiguration, EmailSqlDatabase, EmailSqlQuery, makeEmailKernel } from "./internal/email-kernel.mjs";
|
|
@@ -18,15 +19,22 @@ import { CurrentPasskeyTransaction, PasskeyOwner } from "./internal/passkey/stat
|
|
|
18
19
|
import { TransactionBound, TransactionCoordinatorError, TransactionExecution, TransactionTargetConfiguration, makeTransactionExecutionKernel } from "./internal/transaction-execution-kernel.mjs";
|
|
19
20
|
import { PasskeyCoordinatorError, PasskeyExecution, PasskeyTargetConfiguration } from "./internal/passkey/target.mjs";
|
|
20
21
|
import { PasskeyKernel, makePasskeyKernel } from "./internal/passkey-kernel.mjs";
|
|
22
|
+
import { StorageTable } from "./internal/storage-tables.mjs";
|
|
23
|
+
import { BoundPersistence, ClaimsCodec, Definition, PersistenceApi, PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
24
|
+
import { PhysicalStorageTable, StorageValidation, validateStorage, validateStorageBatch, withStorageValidation } from "./internal/storage-validation.mjs";
|
|
25
|
+
import { NativeSqlTables, SqlTable, makeNativeSqlTables, nativeSqlAlias } from "./internal/native-sql-table.mjs";
|
|
26
|
+
import { samePasswordCredentialSnapshot } from "./internal/password-credentials.mjs";
|
|
21
27
|
import { CurrentPasswordSql, PasswordSqlConfiguration, PasswordSqlDatabase, PasswordSqlQuery, makePasswordKernel } from "./internal/password-kernel.mjs";
|
|
22
28
|
import { CurrentPasswordPreparedTransaction, PasswordPreparedJournalGuards, PasswordPreparedPostcondition, PasswordPreparedPostconditions } from "./internal/PasswordPreparedPostconditions.mjs";
|
|
23
29
|
import { CurrentPhoneTransaction, makePhoneKernel } from "./internal/phone-kernel.mjs";
|
|
24
30
|
import { CurrentSessionSql, SessionSqlDatabase, SessionSqlOptions, makeSessionKernel } from "./internal/session-kernel.mjs";
|
|
25
|
-
import { StorageTable } from "./internal/storage-tables.mjs";
|
|
26
|
-
import { BoundPersistence, ClaimsCodec, Definition, PersistenceApi, PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
27
31
|
import { createPersistence } from "./internal/persistence.mjs";
|
|
28
32
|
import { makeComposedPasskeys } from "./internal/passkeys.mjs";
|
|
29
33
|
import { makeMappings } from "./internal/storage-mapping.mjs";
|
|
30
34
|
import { PasswordRegistrationAuthority } from "./internal/registration-contract.mjs";
|
|
31
|
-
import {
|
|
32
|
-
|
|
35
|
+
import { OAuthAccountsMapping, OAuthAction, OAuthAuthorityReadTable, OAuthAuthorityTable, OAuthCleanupDescriptor, OAuthCleanupTable, OAuthClock, OAuthCredentialReadTable, OAuthCredentialTable, OAuthD1Mapping, OAuthEligibilityDescriptor, OAuthEligibilityFact, OAuthEligibilityTable, OAuthFlowState, OAuthFlowTable, OAuthMetadataPolicy, OAuthOwnershipMutation, OAuthOwnershipReadTable, OAuthOwnershipTable, OAuthReferenceGuardDescriptor, OAuthReferenceGuardTable, OAuthRegistrationAuthority, OAuthRegistrationBase, OAuthRegistrationCommandTable, OAuthRegistrationEligibility, OAuthRegistrationGuardDescriptor, OAuthRegistrationGuardTable, OAuthRegistrationIntentMapping, OAuthRegistrationIntentTable, OAuthRegistrationMapping, OAuthRegistrationState, OAuthSignInMapping, OAuthSubjectReadTable, OAuthSubjectTable, OAuthTupleAuthorityTable, OAuthTupleState, OAuthUnlinkCommandTable, oauthCleanupTable, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable, requiredOAuthAccountsConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints } from "./internal/models/oauth-model.mjs";
|
|
36
|
+
import { OAuthConnectedAction, OAuthConnectedAdmissionTable, OAuthConnectedAuthorityMapping, OAuthConnectedClientRegistrationTable, OAuthConnectedCohortTable, OAuthConnectedCommandTable, OAuthConnectedFlowTable, OAuthConnectedGrantTable, OAuthConnectedMapping, OAuthConnectedOrderCodec, OAuthConnectedOwnershipRead, OAuthConnectedPolicyGuard, OAuthConnectedPolicyGuardTable, OAuthConnectedPolicyInput, OAuthConnectedRevocationJobTable, OAuthConnectedRevocationMapping, OAuthConnectedSqlPolicy, OAuthConnectedSubjectTable, oauthConnectedPolicyGuard, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints } from "./internal/models/oauth-connected-model.mjs";
|
|
37
|
+
import { OAuthCoordinatorError, OAuthExecution, OAuthTargetConfiguration } from "./internal/oauth/target.mjs";
|
|
38
|
+
import { OAuthKernel, makeOAuthKernel } from "./internal/oauth-kernel.mjs";
|
|
39
|
+
import { storageKeyPlans } from "./internal/storage-plans.mjs";
|
|
40
|
+
export { type AnyEmailAddressMapping, type AnyEmailRegistrationMapping, type AnyEmailSignInMapping, type AnyPasswordPersistenceMapping, type AnyPasswordRegistrationMapping, type AnyProofPersistenceMapping, type AuthenticationAuthorityMapping, type BoundPersistence, type ClaimsCodec, type CurrentAddress, CurrentEmailSql, CurrentPasskeyTransaction, CurrentPasswordPreparedTransaction, CurrentPasswordSql, CurrentPhoneTransaction, CurrentProofSql, CurrentSessionSql, type D1AuthenticationAuthorityMapping, type D1EmailAddressMapping, type D1EmailRegistrationMapping, type D1PasskeyMapping, type D1PasswordPersistenceMapping, type D1PendingAuthenticationMapping, type D1ProofPersistenceMapping, type D1SessionClockMapping, type D1SessionStepUpMapping, type D1SignedSessionValidityMapping, type D1StatefulSessionMapping, type Definition, type EmailAddressMapping, type EmailAuthorityCredentialTable, type EmailCommandTable, type EmailCredentialReadTable, type EmailCredentialTable, type EmailD1Clock, type EmailIdentifierReadTable, type EmailIdentifierTable, type EmailRegistrationAuthorityCredentialTable, type EmailRegistrationCredentialTable, type EmailRegistrationIdentifierTable, type EmailRegistrationIntent, type EmailRegistrationMapping, type EmailRegistrationProvisioning, type EmailRegistrationState, type EmailRegistrationTable, type EmailSignInMapping, type EmailSqlConfiguration, type EmailSqlDatabase, type EmailSqlQuery, type EmailSubjectReadTable, type EmailSubjectTable, type GuardedUpdate, NativeDatabase, type NativeSqlTables, type OAuthAccountsMapping, type OAuthAction, type OAuthAuthorityReadTable, type OAuthAuthorityTable, type OAuthCleanupDescriptor, type OAuthCleanupTable, type OAuthClock, type OAuthConnectedAction, type OAuthConnectedAdmissionTable, type OAuthConnectedAuthorityMapping, type OAuthConnectedClientRegistrationTable, type OAuthConnectedCohortTable, type OAuthConnectedCommandTable, type OAuthConnectedFlowTable, type OAuthConnectedGrantTable, type OAuthConnectedMapping, type OAuthConnectedOrderCodec, type OAuthConnectedOwnershipRead, type OAuthConnectedPolicyGuard, type OAuthConnectedPolicyGuardTable, type OAuthConnectedPolicyInput, type OAuthConnectedRevocationJobTable, type OAuthConnectedRevocationMapping, type OAuthConnectedSqlPolicy, type OAuthConnectedSubjectTable, type OAuthCoordinatorError, type OAuthCredentialReadTable, type OAuthCredentialTable, type OAuthD1Mapping, type OAuthEligibilityDescriptor, type OAuthEligibilityFact, type OAuthEligibilityTable, type OAuthExecution, type OAuthFlowState, type OAuthFlowTable, type OAuthKernel, type OAuthMetadataPolicy, type OAuthOwnershipMutation, type OAuthOwnershipReadTable, type OAuthOwnershipTable, type OAuthProxySqlTable, type OAuthReferenceGuardDescriptor, type OAuthReferenceGuardTable, type OAuthRegistrationAuthority, type OAuthRegistrationBase, type OAuthRegistrationCommandTable, type OAuthRegistrationEligibility, type OAuthRegistrationGuardDescriptor, type OAuthRegistrationGuardTable, type OAuthRegistrationIntentMapping, type OAuthRegistrationIntentTable, type OAuthRegistrationMapping, type OAuthRegistrationState, type OAuthSignInMapping, type OAuthSubjectReadTable, type OAuthSubjectTable, type OAuthTargetConfiguration, type OAuthTupleAuthorityTable, type OAuthTupleState, type OAuthUnlinkCommandTable, type Observation, type PasskeyAdmissionTable, type PasskeyCeremonyMapping, type PasskeyChargeInsert, type PasskeyChargeKind, type PasskeyChargeTable, type PasskeyClock, type PasskeyColumn, type PasskeyCommandTable, type PasskeyCoordinatorError, type PasskeyCredentialInsert, type PasskeyCredentialMapping, type PasskeyCredentialOwnershipTable, type PasskeyCredentialReadTable, type PasskeyCredentialServices, type PasskeyEnrollmentContextMapping, type PasskeyEnrollmentContextServices, type PasskeyExecution, type PasskeyFactorReadTable, type PasskeyFlowInsert, type PasskeyFlowState, type PasskeyFlowTable, type PasskeyHandleOwnershipTable, type PasskeyHandleReadTable, type PasskeyHandleReservationTable, type PasskeyInvalidationInput, type PasskeyInvalidationMutation, type PasskeyKernel, type PasskeyManagementMapping, type PasskeyManagementServices, type PasskeyMappingSource, type PasskeyModuleTable, type PasskeyOwner, type PasskeyPersistenceMapping, type PasskeyPersistenceServices, type PasskeyPolicyGuard, type PasskeyRegistrationCeremonyCapabilities, type PasskeyRegistrationCeremonyMapping, type PasskeyRegistrationCeremonyServices, type PasskeyRegistrationIntentReadTable, type PasskeyRegistrationMapping, type PasskeyRegistrationServices, type PasskeyRegistrationWriter, type PasskeySubjectIdCodec, type PasskeySubjectReadTable, type PasskeyTargetConfiguration, type PasskeyWriteTables, type PasswordAuthorityCredentialTable, type PasswordCommandTable, type PasswordConstraintClassifier, type PasswordCredentialTable, type PasswordD1Clock, type PasswordIdentifierTable, type PasswordPersistenceMapping, PasswordPreparedJournalGuards, type PasswordPreparedPostcondition, PasswordPreparedPostconditions, type PasswordRegistrationAuthority, type PasswordRegistrationConstraintClassifier, type PasswordRegistrationIntent, type PasswordRegistrationMapping, type PasswordRegistrationProvisioning, type PasswordRegistrationState, type PasswordRegistrationTable, type PasswordSqlConfiguration, type PasswordSqlDatabase, type PasswordSqlQuery, type PasswordSubjectTable, type PendingAuthenticationMapping, type PendingAuthenticationTables, type PersistenceApi, PersistenceConfigurationError, PersistenceMappingError, type PhysicalStorageTable, type ProofAbuseEventTable, type ProofAction, type ProofAuthorityInput, type ProofAuthorityTables, type ProofCommandDecision, type ProofCommandKind, type ProofCommandTable, type ProofConstraintClassifier, type ProofContinuationRecord, type ProofContinuationTable, type ProofD1Clock, type ProofDeliveryState, type ProofFailureEventTable, type ProofGenerationState, type ProofGenerationTable, type ProofPersistenceMapping, type ProofRateScopeTable, type ProofRequestTable, type ProofScopeKeys, type ProofScopeKind, type ProofSeriesTable, type ProofSqlConfiguration, type ProofSqlDatabase, type ProofSqlQuery, type QueryFailure, type QueryOperations, type RequiredEmailAddressConstraints, type RequiredEmailRegistrationConstraints, type RequiredEmailSignInConstraints, type RequiredPasswordConstraints, type RequiredPasswordRegistrationConstraints, type RequiredPendingAuthenticationConstraints, type RequiredProofConstraints, type RequiredSessionConstraints, type RequiredSessionStepUpConstraints, type RequiredSignedValidityConstraints, type RequiredStatefulPendingConstraints, type Row, type SessionAuthorityTables, type SessionConstraintClassifier, type SessionFlowTables, type SessionIdCodec, type SessionSqlDatabase, type SessionSqlOptions, type SessionStepUpIntentTables, type SessionStepUpMapping, type SessionStepUpSourceTables, type SessionSubjectTables, type SignedSessionValidityMapping, type SignedSessionValidityTables, type SqlColumn, type SqlExpression, type SqlFragment, type SqlTable, type StatefulSessionMapping, type StatefulSessionTables, type StorageTable, type StorageValidation, type SubjectIdCodec, type TableModel, type TransactionBound, type TransactionCoordinatorError, type TransactionExecution, type TransactionNativeDatabase, type TransactionOwner, type TransactionTargetConfiguration, createPersistence, decodeStepUpIntent, encodeStepUpIntent, isMappedConstraintConflict, makeComposedPasskeys, makeEmailKernel, makeNativeSqlTables, makeOAuthKernel, makeOAuthProxyPersistence, makePasskeyKernel, makePasswordKernel, makePhoneKernel, makeProofKernel, makeSessionKernel, makeMappings as makeStorageMappings, makeTransactionExecutionKernel, makeTransactionKernel, nativeSqlAlias, oauthCleanupTable, oauthConnectedPolicyGuard, oauthEligibilityTable, oauthProxyColumns, oauthReferenceGuardTable, oauthRegistrationGuardTable, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyPersistenceLayer, passkeyPolicyGuard, requireStandalone, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, samePasswordCredentialSnapshot, stepUpIntentLive, storageKeyPlans, validateStepUpPlan, validateStorage, validateStorageBatch, withStorageValidation };
|
package/dist/Adapter.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
2
2
|
import { PersistenceMappingError, isMappedConstraintConflict } from "./internal/mapping-error.mjs";
|
|
3
|
+
import { makeNativeSqlTables, nativeSqlAlias } from "./internal/native-sql-table.mjs";
|
|
3
4
|
import { passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyPersistenceLayer, passkeyPolicyGuard, requiredPasskeyCredentialConstraints, requiredPasskeyPersistenceConstraints } from "./internal/models/passkey-model.mjs";
|
|
4
5
|
import { passkeyInvalidationMutation, requiredPasskeyManagementConstraints, requiredPasskeyRegistrationWriteConstraints } from "./internal/models/passkey-write-model.mjs";
|
|
5
6
|
import { requiredPasskeyRegistrationCeremonyConstraints } from "./internal/models/passkey-registration-ceremony-model.mjs";
|
|
@@ -15,13 +16,19 @@ import { makeComposedPasskeys } from "./internal/passkeys.mjs";
|
|
|
15
16
|
import { requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints } from "./internal/models/email-model.mjs";
|
|
16
17
|
import { CurrentEmailSql, makeEmailKernel } from "./internal/email-kernel.mjs";
|
|
17
18
|
import { requiredPasswordConstraints, requiredPasswordRegistrationConstraints } from "./internal/models/password-model.mjs";
|
|
19
|
+
import { samePasswordCredentialSnapshot } from "./internal/password-credentials.mjs";
|
|
18
20
|
import { CurrentPasswordSql, makePasswordKernel } from "./internal/password-kernel.mjs";
|
|
19
21
|
import { CurrentPhoneTransaction, makePhoneKernel } from "./internal/phone-kernel.mjs";
|
|
20
22
|
import { decodeStepUpIntent, encodeStepUpIntent, stepUpIntentLive, validateStepUpPlan } from "./internal/step-up-state.mjs";
|
|
23
|
+
import { validateStorage, validateStorageBatch, withStorageValidation } from "./internal/storage-validation.mjs";
|
|
21
24
|
import { CurrentSessionSql, makeSessionKernel } from "./internal/session-kernel.mjs";
|
|
22
25
|
import { makeMappings } from "./internal/storage-mapping.mjs";
|
|
23
|
-
import { validateStorage, validateStorageBatch, withStorageValidation } from "./internal/storage-validation.mjs";
|
|
24
26
|
import { createPersistence } from "./internal/persistence.mjs";
|
|
27
|
+
import { makeOAuthProxyPersistence, oauthProxyColumns } from "./internal/oauth-proxy.mjs";
|
|
28
|
+
import { oauthCleanupTable, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable, requiredOAuthAccountsConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints } from "./internal/models/oauth-model.mjs";
|
|
29
|
+
import { makeOAuthKernel } from "./internal/oauth-kernel.mjs";
|
|
30
|
+
import { storageKeyPlans } from "./internal/storage-plans.mjs";
|
|
31
|
+
import { oauthConnectedPolicyGuard, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints } from "./internal/models/oauth-connected-model.mjs";
|
|
25
32
|
import { requiredPendingAuthenticationConstraints, requiredSessionConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints } from "./internal/models/session-model.mjs";
|
|
26
33
|
import { requiredSessionStepUpConstraints } from "./internal/models/step-up-model.mjs";
|
|
27
|
-
export { CurrentEmailSql, CurrentPasskeyTransaction, CurrentPasswordPreparedTransaction, CurrentPasswordSql, CurrentPhoneTransaction, CurrentProofSql, CurrentSessionSql, NativeDatabase, PasswordPreparedJournalGuards, PasswordPreparedPostconditions, PersistenceConfigurationError, PersistenceMappingError, createPersistence, decodeStepUpIntent, encodeStepUpIntent, isMappedConstraintConflict, makeComposedPasskeys, makeEmailKernel, makePasskeyKernel, makePasswordKernel, makePhoneKernel, makeProofKernel, makeSessionKernel, makeMappings as makeStorageMappings, makeTransactionExecutionKernel, makeTransactionKernel, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyPersistenceLayer, passkeyPolicyGuard, requireStandalone, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, stepUpIntentLive, validateStepUpPlan, validateStorage, validateStorageBatch, withStorageValidation };
|
|
34
|
+
export { CurrentEmailSql, CurrentPasskeyTransaction, CurrentPasswordPreparedTransaction, CurrentPasswordSql, CurrentPhoneTransaction, CurrentProofSql, CurrentSessionSql, NativeDatabase, PasswordPreparedJournalGuards, PasswordPreparedPostconditions, PersistenceConfigurationError, PersistenceMappingError, createPersistence, decodeStepUpIntent, encodeStepUpIntent, isMappedConstraintConflict, makeComposedPasskeys, makeEmailKernel, makeNativeSqlTables, makeOAuthKernel, makeOAuthProxyPersistence, makePasskeyKernel, makePasswordKernel, makePhoneKernel, makeProofKernel, makeSessionKernel, makeMappings as makeStorageMappings, makeTransactionExecutionKernel, makeTransactionKernel, nativeSqlAlias, oauthCleanupTable, oauthConnectedPolicyGuard, oauthEligibilityTable, oauthProxyColumns, oauthReferenceGuardTable, oauthRegistrationGuardTable, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyPersistenceLayer, passkeyPolicyGuard, requireStandalone, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, samePasswordCredentialSnapshot, stepUpIntentLive, storageKeyPlans, validateStepUpPlan, validateStorage, validateStorageBatch, withStorageValidation };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { AuthenticationAuthorityMapping } from "./internal/models/session-model.mjs";
|
|
2
|
+
import { StorageTable } from "./internal/storage-tables.mjs";
|
|
3
|
+
import { PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
4
|
+
import { OAuthAction, OAuthD1Mapping, OAuthEligibilityFact, OAuthFlowState, OAuthRegistrationAuthority, OAuthRegistrationState, OAuthTupleState, requiredOAuthAccountsConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints } from "./internal/models/oauth-model.mjs";
|
|
5
|
+
import { OAuthConnectedAction, OAuthConnectedOrderCodec, OAuthConnectedPolicyInput, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints } from "./internal/models/oauth-connected-model.mjs";
|
|
6
|
+
import { OAuthCoordinatorError, oauthAccountsPersistenceLayer as oauthAccountsPersistenceLayer$1, oauthRegistrationAuthorityLayer as oauthRegistrationAuthorityLayer$1, oauthRegistrationIntentsLayer as oauthRegistrationIntentsLayer$1, oauthSignInPersistenceLayer as oauthSignInPersistenceLayer$1 } from "./internal/oauth/target.mjs";
|
|
7
|
+
import { Fragment, Table } from "./internal/sql-table.mjs";
|
|
8
|
+
import { OAuthAccountsMapping, OAuthAuthorityReadTable, OAuthAuthorityTable, OAuthCleanupDescriptor, OAuthCleanupTable, OAuthClock, OAuthCredentialReadTable, OAuthCredentialTable, OAuthEligibilityDescriptor, OAuthEligibilityTable, OAuthFlowTable, OAuthMetadataPolicy, OAuthOwnershipMutation, OAuthOwnershipReadTable, OAuthOwnershipTable, OAuthReferenceGuardDescriptor, OAuthReferenceGuardTable, OAuthRegistrationBase, OAuthRegistrationCommandTable, OAuthRegistrationEligibility, OAuthRegistrationGuardDescriptor, OAuthRegistrationGuardTable, OAuthRegistrationIntentMapping, OAuthRegistrationIntentTable, OAuthRegistrationMapping, OAuthSignInMapping, OAuthSubjectReadTable, OAuthSubjectTable, OAuthTupleAuthorityTable, OAuthUnlinkCommandTable, SqlTableModel, oauthCleanupTable, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable } from "./internal/sql-oauth-model.mjs";
|
|
9
|
+
import { oauthConnectedPersistenceLayer as oauthConnectedPersistenceLayer$1, oauthConnectedRevocationsLayer as oauthConnectedRevocationsLayer$1 } from "./internal/oauth/connected-target.mjs";
|
|
10
|
+
import { OAuthConnectedAdmissionTable, OAuthConnectedAuthorityMapping, OAuthConnectedClientRegistrationTable, OAuthConnectedCohortTable, OAuthConnectedCommandTable, OAuthConnectedFlowTable, OAuthConnectedGrantTable, OAuthConnectedMapping, OAuthConnectedOwnershipRead, OAuthConnectedPolicyGuard, OAuthConnectedPolicyGuardTable, OAuthConnectedRevocationJobTable, OAuthConnectedRevocationMapping, OAuthConnectedSqlPolicy, OAuthConnectedSubjectTable, oauthConnectedPolicyGuard } from "./internal/sql-oauth-connected-model.mjs";
|
|
11
|
+
import { and, eq, sql } from "./internal/sql-query.mjs";
|
|
12
|
+
import { Context, Crypto, Effect } from "effect";
|
|
13
|
+
import { SqlClient } from "effect/sql";
|
|
14
|
+
import { LifecycleHooks } from "@yielded/auth/Hooks";
|
|
15
|
+
import { AuthenticationAuthority, SessionUnavailable } from "@yielded/auth/Sessions";
|
|
16
|
+
import { OAuthAccountsPersistence, OAuthConnectedPersistence, OAuthConnectedRevocations, OAuthRegistrationIntents, OAuthSignInPersistence, OAuthUnavailable } from "@yielded/auth/OAuth";
|
|
17
|
+
declare namespace OAuthPersistence_d_exports {
|
|
18
|
+
export { OAuthAccountsMapping, OAuthAction, OAuthAuthorityReadTable, OAuthAuthorityTable, OAuthCleanupDescriptor, OAuthCleanupTable, OAuthClock, OAuthConnectedAction, OAuthConnectedAdmissionTable, OAuthConnectedAuthorityMapping, OAuthConnectedClientRegistrationTable, OAuthConnectedCohortTable, OAuthConnectedCommandTable, OAuthConnectedFlowTable, OAuthConnectedGrantTable, OAuthConnectedMapping, OAuthConnectedOrderCodec, OAuthConnectedOwnershipRead, OAuthConnectedPolicyGuard, OAuthConnectedPolicyGuardTable, OAuthConnectedPolicyInput, OAuthConnectedRevocationJobTable, OAuthConnectedRevocationMapping, OAuthConnectedSqlPolicy, OAuthConnectedSubjectTable, OAuthCredentialReadTable, OAuthCredentialTable, OAuthD1Mapping, OAuthEligibilityDescriptor, OAuthEligibilityFact, OAuthEligibilityTable, OAuthFlowState, OAuthFlowTable, OAuthMetadataPolicy, OAuthOwnershipMutation, OAuthOwnershipReadTable, OAuthOwnershipTable, OAuthReferenceGuardDescriptor, OAuthReferenceGuardTable, OAuthRegistrationAuthority, OAuthRegistrationBase, OAuthRegistrationCommandTable, OAuthRegistrationEligibility, OAuthRegistrationGuardDescriptor, OAuthRegistrationGuardTable, OAuthRegistrationIntentMapping, OAuthRegistrationIntentTable, OAuthRegistrationMapping, OAuthRegistrationState, OAuthSignInMapping, OAuthSubjectReadTable, OAuthSubjectTable, OAuthTupleAuthorityTable, OAuthTupleState, OAuthUnlinkCommandTable, SqlTableModel, and, clock, coordinateOAuthAccounts, coordinateOAuthConnected, coordinateOAuthConnectedRevocations, coordinateOAuthRegistration, coordinateOAuthRegistrationIntents, coordinateOAuthSignIn, eq, makeAuthenticationAuthorityServices, makeOAuthAccountsServices, makeOAuthConnectedRevocationServices, makeOAuthConnectedServices, makeOAuthRegistrationIntentServices, makeOAuthRegistrationServices, makeOAuthSignInServices, oauthAccountsPersistenceLayer, oauthCleanupTable, oauthConnectedOwnershipReferences, oauthConnectedPersistenceLayer, oauthConnectedPolicyGuard, oauthConnectedRevocationsLayer, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationAuthorityLayer, oauthRegistrationGuardTable, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, sql, table };
|
|
19
|
+
}
|
|
20
|
+
/** Physical identifiers and representations only; applications own migrations. */
|
|
21
|
+
export declare const table: (definition: StorageTable) => Table;
|
|
22
|
+
/** Integer-millisecond engine clock, sampled after locks on either supported dialect. */
|
|
23
|
+
export declare const clock: {
|
|
24
|
+
encodeInstant: (input: number, options?: import("effect/SchemaAST").ParseOptions) => number;
|
|
25
|
+
decodeInstant: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => number;
|
|
26
|
+
engineNowMillis: Fragment;
|
|
27
|
+
};
|
|
28
|
+
export declare const makeOAuthSignInServices: <N>(mapping: OAuthSignInMapping<Table, Table, Table, Table, Table, N>) => Effect.Effect<{
|
|
29
|
+
readonly oauthSignInPersistence: OAuthSignInPersistence["Service"];
|
|
30
|
+
}, OAuthUnavailable | PersistenceConfigurationError, Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
31
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
32
|
+
export declare const coordinateOAuthSignIn: <N, A, E, R>(options: {
|
|
33
|
+
readonly mapping: OAuthSignInMapping<Table, Table, Table, Table, Table, N>;
|
|
34
|
+
}, body: Effect.Effect<A, E, R>) => Effect.Effect<A, OAuthCoordinatorError<E> | PersistenceConfigurationError, Exclude<R, OAuthSignInPersistence> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
35
|
+
export declare const makeOAuthRegistrationIntentServices: <N>(mapping: OAuthRegistrationIntentMapping<Table, Table, Table, Table, Table, Table, Table, N>) => Effect.Effect<{
|
|
36
|
+
readonly oauthRegistrationIntents: OAuthRegistrationIntents["Service"];
|
|
37
|
+
}, OAuthUnavailable | PersistenceConfigurationError, Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
38
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
39
|
+
export declare const coordinateOAuthRegistrationIntents: <N, A, E, R>(options: {
|
|
40
|
+
readonly mapping: OAuthRegistrationIntentMapping<Table, Table, Table, Table, Table, Table, Table, N>;
|
|
41
|
+
}, body: Effect.Effect<A, E, R>) => Effect.Effect<A, OAuthCoordinatorError<E> | PersistenceConfigurationError, Exclude<R, OAuthRegistrationIntents> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
42
|
+
export declare const makeOAuthAccountsServices: <N>(mapping: OAuthAccountsMapping<Table, Table, Table, Table, Table, Table, Table, N>) => Effect.Effect<{
|
|
43
|
+
readonly oauthAccountsPersistence: OAuthAccountsPersistence["Service"];
|
|
44
|
+
}, OAuthUnavailable | PersistenceConfigurationError, Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
45
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
46
|
+
export declare const coordinateOAuthAccounts: <N, A, E, R>(options: {
|
|
47
|
+
readonly mapping: OAuthAccountsMapping<Table, Table, Table, Table, Table, Table, Table, N>;
|
|
48
|
+
}, body: Effect.Effect<A, E, R>) => Effect.Effect<A, OAuthCoordinatorError<E> | PersistenceConfigurationError, Exclude<R, OAuthAccountsPersistence> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
49
|
+
export declare const makeOAuthConnectedServices: <N>(mapping: OAuthConnectedMapping<Table, Table, Table, Table, Table, Table, Table, Table, Table, Table, N, Table>) => Effect.Effect<{
|
|
50
|
+
readonly oauthConnectedPersistence: OAuthConnectedPersistence["Service"];
|
|
51
|
+
}, OAuthUnavailable | PersistenceConfigurationError, Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
52
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
53
|
+
export declare const coordinateOAuthConnected: <N, A, E, R>(options: {
|
|
54
|
+
readonly mapping: OAuthConnectedMapping<Table, Table, Table, Table, Table, Table, Table, Table, Table, Table, N, Table>;
|
|
55
|
+
}, body: Effect.Effect<A, E, R>) => Effect.Effect<A, OAuthCoordinatorError<E> | PersistenceConfigurationError, Exclude<R, OAuthConnectedPersistence> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
56
|
+
export declare const makeOAuthConnectedRevocationServices: <N>(mapping: OAuthConnectedRevocationMapping<Table, Table, Table, Table, Table, Table, Table, N>) => Effect.Effect<{
|
|
57
|
+
readonly oauthConnectedRevocations: OAuthConnectedRevocations["Service"];
|
|
58
|
+
}, OAuthUnavailable | PersistenceConfigurationError, Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
59
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
60
|
+
export declare const coordinateOAuthConnectedRevocations: <N, A, E, R>(options: {
|
|
61
|
+
readonly mapping: OAuthConnectedRevocationMapping<Table, Table, Table, Table, Table, Table, Table, N>;
|
|
62
|
+
}, body: Effect.Effect<A, E, R>) => Effect.Effect<A, OAuthCoordinatorError<E> | PersistenceConfigurationError, Exclude<R, OAuthConnectedRevocations> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
63
|
+
export declare const makeOAuthRegistrationServices: <Registration, N>(mapping: OAuthRegistrationMapping<Registration, Table, Table, Table, Table, Table, Table, Table, N>) => Effect.Effect<{
|
|
64
|
+
readonly registrationAuthority: OAuthRegistrationAuthority<Registration>;
|
|
65
|
+
}, OAuthUnavailable | PersistenceConfigurationError, Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
66
|
+
export declare const coordinateOAuthRegistration: <Id, Registration, N, A, E, R>(options: {
|
|
67
|
+
readonly mapping: OAuthRegistrationMapping<NoInfer<Registration>, Table, Table, Table, Table, Table, Table, Table, N>;
|
|
68
|
+
readonly target: Context.Key<Id, OAuthRegistrationAuthority<Registration>>;
|
|
69
|
+
}, body: Effect.Effect<A, E, R>) => Effect.Effect<A, OAuthCoordinatorError<E> | PersistenceConfigurationError, Exclude<R, Id> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient>;
|
|
70
|
+
/** Include these guards when login ownership may also hold retained grants. */
|
|
71
|
+
export declare const oauthConnectedOwnershipReferences: <N>(mapping: OAuthConnectedMapping<Table, Table, Table, Table, Table, Table, Table, Table, Table, Table, N, Table>, dialect: "pg" | "sqlite") => {
|
|
72
|
+
readonly connectedReferenceGuards: ReadonlyArray<OAuthReferenceGuardDescriptor<N>>;
|
|
73
|
+
readonly connectedReference: (input: {
|
|
74
|
+
readonly identityKey: string;
|
|
75
|
+
readonly subjectId: N;
|
|
76
|
+
}) => Fragment;
|
|
77
|
+
};
|
|
78
|
+
export declare const oauthAccountsPersistenceLayer: typeof oauthAccountsPersistenceLayer$1, oauthSignInPersistenceLayer: typeof oauthSignInPersistenceLayer$1, oauthRegistrationIntentsLayer: typeof oauthRegistrationIntentsLayer$1, oauthRegistrationAuthorityLayer: typeof oauthRegistrationAuthorityLayer$1;
|
|
79
|
+
export declare const oauthConnectedPersistenceLayer: typeof oauthConnectedPersistenceLayer$1, oauthConnectedRevocationsLayer: typeof oauthConnectedRevocationsLayer$1;
|
|
80
|
+
/** Shared session issuance must validate the same subject and credential authority
|
|
81
|
+
* as OAuth. Supply this service when it is not already provided by session storage. */
|
|
82
|
+
export declare const makeAuthenticationAuthorityServices: <Claims, N>(mapping: AuthenticationAuthorityMapping<Claims, SqlTableModel, SqlTableModel, SqlTableModel, SqlTableModel, N>) => Effect.Effect<{
|
|
83
|
+
readonly authenticationAuthority: AuthenticationAuthority["Service"];
|
|
84
|
+
}, SessionUnavailable | PersistenceConfigurationError, LifecycleHooks | SqlClient.SqlClient>;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { OAuthAccountsMapping, type OAuthAction, OAuthAuthorityReadTable, OAuthAuthorityTable, OAuthCleanupDescriptor, OAuthCleanupTable, OAuthClock, type OAuthConnectedAction, OAuthConnectedAdmissionTable, OAuthConnectedAuthorityMapping, OAuthConnectedClientRegistrationTable, OAuthConnectedCohortTable, OAuthConnectedCommandTable, OAuthConnectedFlowTable, OAuthConnectedGrantTable, OAuthConnectedMapping, type OAuthConnectedOrderCodec, OAuthConnectedOwnershipRead, OAuthConnectedPolicyGuard, OAuthConnectedPolicyGuardTable, type OAuthConnectedPolicyInput, OAuthConnectedRevocationJobTable, OAuthConnectedRevocationMapping, OAuthConnectedSqlPolicy, OAuthConnectedSubjectTable, OAuthCredentialReadTable, OAuthCredentialTable, type OAuthD1Mapping, OAuthEligibilityDescriptor, type OAuthEligibilityFact, OAuthEligibilityTable, type OAuthFlowState, OAuthFlowTable, OAuthMetadataPolicy, OAuthOwnershipMutation, OAuthOwnershipReadTable, OAuthOwnershipTable, OAuthPersistence_d_exports, OAuthReferenceGuardDescriptor, OAuthReferenceGuardTable, type OAuthRegistrationAuthority, OAuthRegistrationBase, OAuthRegistrationCommandTable, OAuthRegistrationEligibility, OAuthRegistrationGuardDescriptor, OAuthRegistrationGuardTable, OAuthRegistrationIntentMapping, OAuthRegistrationIntentTable, OAuthRegistrationMapping, type OAuthRegistrationState, OAuthSignInMapping, OAuthSubjectReadTable, OAuthSubjectTable, OAuthTupleAuthorityTable, type OAuthTupleState, OAuthUnlinkCommandTable, SqlTableModel, and, eq, oauthCleanupTable, oauthConnectedPolicyGuard, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, sql };
|
|
87
|
+
//# sourceMappingURL=OAuthPersistence.d.mts.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
3
|
+
import { Fragment, Table } from "./internal/sql-table.mjs";
|
|
4
|
+
import { makeNativeSqlTables } from "./internal/native-sql-table.mjs";
|
|
5
|
+
import { requireStandalone } from "./internal/standalone.mjs";
|
|
6
|
+
import { NativeDatabase } from "./internal/transaction-kernel.mjs";
|
|
7
|
+
import { CurrentSessionSql, makeSessionKernel } from "./internal/session-kernel.mjs";
|
|
8
|
+
import { and, eq, makeSqlDatabase, sql, sqlQueryOperations } from "./internal/sql-query.mjs";
|
|
9
|
+
import { requiredOAuthAccountsConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints } from "./internal/models/oauth-model.mjs";
|
|
10
|
+
import { makeOAuthKernel } from "./internal/oauth-kernel.mjs";
|
|
11
|
+
import { validateSqlStorage } from "./internal/sql-storage-validation.mjs";
|
|
12
|
+
import { oauthCleanupTable, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable } from "./internal/sql-oauth-model.mjs";
|
|
13
|
+
import { requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints } from "./internal/models/oauth-connected-model.mjs";
|
|
14
|
+
import { oauthConnectedPolicyGuard } from "./internal/sql-oauth-connected-model.mjs";
|
|
15
|
+
import { Effect, Predicate, Schema } from "effect";
|
|
16
|
+
import { SqlClient } from "effect/sql";
|
|
17
|
+
import { SessionUnavailable } from "@yielded/auth/Sessions";
|
|
18
|
+
import { OAuthAccountsPersistence, OAuthConnectedPersistence, OAuthConnectedRevocations, OAuthRegistrationIntents, OAuthSignInPersistence, OAuthUnavailable } from "@yielded/auth/OAuth";
|
|
19
|
+
//#region src/OAuthPersistence.ts
|
|
20
|
+
var OAuthPersistence_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
and: () => and,
|
|
22
|
+
clock: () => clock,
|
|
23
|
+
coordinateOAuthAccounts: () => coordinateOAuthAccounts,
|
|
24
|
+
coordinateOAuthConnected: () => coordinateOAuthConnected,
|
|
25
|
+
coordinateOAuthConnectedRevocations: () => coordinateOAuthConnectedRevocations,
|
|
26
|
+
coordinateOAuthRegistration: () => coordinateOAuthRegistration,
|
|
27
|
+
coordinateOAuthRegistrationIntents: () => coordinateOAuthRegistrationIntents,
|
|
28
|
+
coordinateOAuthSignIn: () => coordinateOAuthSignIn,
|
|
29
|
+
eq: () => eq,
|
|
30
|
+
makeAuthenticationAuthorityServices: () => makeAuthenticationAuthorityServices,
|
|
31
|
+
makeOAuthAccountsServices: () => makeOAuthAccountsServices,
|
|
32
|
+
makeOAuthConnectedRevocationServices: () => makeOAuthConnectedRevocationServices,
|
|
33
|
+
makeOAuthConnectedServices: () => makeOAuthConnectedServices,
|
|
34
|
+
makeOAuthRegistrationIntentServices: () => makeOAuthRegistrationIntentServices,
|
|
35
|
+
makeOAuthRegistrationServices: () => makeOAuthRegistrationServices,
|
|
36
|
+
makeOAuthSignInServices: () => makeOAuthSignInServices,
|
|
37
|
+
oauthAccountsPersistenceLayer: () => oauthAccountsPersistenceLayer,
|
|
38
|
+
oauthCleanupTable: () => oauthCleanupTable,
|
|
39
|
+
oauthConnectedOwnershipReferences: () => oauthConnectedOwnershipReferences,
|
|
40
|
+
oauthConnectedPersistenceLayer: () => oauthConnectedPersistenceLayer,
|
|
41
|
+
oauthConnectedPolicyGuard: () => oauthConnectedPolicyGuard,
|
|
42
|
+
oauthConnectedRevocationsLayer: () => oauthConnectedRevocationsLayer,
|
|
43
|
+
oauthEligibilityTable: () => oauthEligibilityTable,
|
|
44
|
+
oauthReferenceGuardTable: () => oauthReferenceGuardTable,
|
|
45
|
+
oauthRegistrationAuthorityLayer: () => oauthRegistrationAuthorityLayer,
|
|
46
|
+
oauthRegistrationGuardTable: () => oauthRegistrationGuardTable,
|
|
47
|
+
oauthRegistrationIntentsLayer: () => oauthRegistrationIntentsLayer,
|
|
48
|
+
oauthSignInPersistenceLayer: () => oauthSignInPersistenceLayer,
|
|
49
|
+
requiredOAuthAccountsConstraints: () => requiredOAuthAccountsConstraints,
|
|
50
|
+
requiredOAuthConnectedConstraints: () => requiredOAuthConnectedConstraints,
|
|
51
|
+
requiredOAuthConnectedRevocationConstraints: () => requiredOAuthConnectedRevocationConstraints,
|
|
52
|
+
requiredOAuthRegistrationConstraints: () => requiredOAuthRegistrationConstraints,
|
|
53
|
+
requiredOAuthSignInConstraints: () => requiredOAuthSignInConstraints,
|
|
54
|
+
requiredOAuthTupleConstraints: () => requiredOAuthTupleConstraints,
|
|
55
|
+
sql: () => sql,
|
|
56
|
+
table: () => table
|
|
57
|
+
});
|
|
58
|
+
/** Physical identifiers and representations only; applications own migrations. */
|
|
59
|
+
const table = (definition) => new Table(definition.name, definition.columns, definition.unique, definition.schema);
|
|
60
|
+
/** Integer-millisecond engine clock, sampled after locks on either supported dialect. */
|
|
61
|
+
const clock = {
|
|
62
|
+
encodeInstant: Schema.encodeSync(Schema.Int),
|
|
63
|
+
decodeInstant: Schema.decodeUnknownSync(Schema.Int),
|
|
64
|
+
engineNowMillis: new Fragment((compiler) => compiler.dialect === "pg" ? "cast(extract(epoch from clock_timestamp()) * 1000 as bigint)" : "cast(round((julianday('now') - 2440587.5) * 86400000) as integer)")
|
|
65
|
+
};
|
|
66
|
+
const operations = {
|
|
67
|
+
...sqlQueryOperations,
|
|
68
|
+
validateStorage: validateSqlStorage
|
|
69
|
+
};
|
|
70
|
+
const kernels = {
|
|
71
|
+
pg: makeOAuthKernel(operations, () => "pg"),
|
|
72
|
+
sqlite: makeOAuthKernel(operations, () => "sqlite")
|
|
73
|
+
};
|
|
74
|
+
const acquire = Effect.gen(function* () {
|
|
75
|
+
const client = yield* SqlClient.SqlClient;
|
|
76
|
+
const dialect = client.onDialectOrElse({
|
|
77
|
+
pg: () => "pg",
|
|
78
|
+
sqlite: () => "sqlite",
|
|
79
|
+
orElse: () => void 0
|
|
80
|
+
});
|
|
81
|
+
if (dialect === void 0 || Predicate.hasProperty(client, "~@effect/sql-d1/D1Client")) return yield* PersistenceConfigurationError.make({ reason: "OAuth persistence requires PostgreSQL or SQLite with interactive transactions" });
|
|
82
|
+
return {
|
|
83
|
+
database: yield* makeSqlDatabase(dialect),
|
|
84
|
+
configuration: {
|
|
85
|
+
mode: "interactive",
|
|
86
|
+
dialect,
|
|
87
|
+
locking: dialect === "pg",
|
|
88
|
+
standaloneGuard: (service) => requireStandalone(() => OAuthUnavailable.make({}), service)
|
|
89
|
+
},
|
|
90
|
+
kernel: kernels[dialect]
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
const using = (body) => Effect.flatMap(acquire, (input) => body(input).pipe(Effect.provideService(NativeDatabase, input.database)));
|
|
94
|
+
const makeOAuthSignInServices = (mapping) => using(({ kernel, configuration }) => kernel.target.makeTargetOAuthSignInServices(mapping, configuration));
|
|
95
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
96
|
+
const coordinateOAuthSignIn = (options, body) => using(({ kernel, configuration, database }) => kernel.target.coordinateTargetOAuthSignIn(database, options.mapping, configuration, (_transaction, services) => Effect.provideService(body, OAuthSignInPersistence, services.oauthSignInPersistence)));
|
|
97
|
+
const makeOAuthRegistrationIntentServices = (mapping) => using(({ kernel, configuration }) => kernel.target.makeTargetOAuthRegistrationIntentServices(mapping, configuration));
|
|
98
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
99
|
+
const coordinateOAuthRegistrationIntents = (options, body) => using(({ kernel, configuration, database }) => kernel.target.coordinateTargetOAuthRegistrationIntents(database, options.mapping, configuration, (_transaction, services) => Effect.provideService(body, OAuthRegistrationIntents, services.oauthRegistrationIntents)));
|
|
100
|
+
const makeOAuthAccountsServices = (mapping) => using(({ kernel, configuration }) => kernel.target.makeTargetOAuthAccountsServices(mapping, configuration));
|
|
101
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
102
|
+
const coordinateOAuthAccounts = (options, body) => using(({ kernel, configuration, database }) => kernel.target.coordinateTargetOAuthAccounts(database, options.mapping, configuration, (_transaction, services) => Effect.provideService(body, OAuthAccountsPersistence, services.oauthAccountsPersistence)));
|
|
103
|
+
const makeOAuthConnectedServices = (mapping) => using(({ kernel, configuration }) => kernel.connectedTarget.makeTargetOAuthConnectedServices(mapping, configuration));
|
|
104
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
105
|
+
const coordinateOAuthConnected = (options, body) => using(({ kernel, configuration, database }) => kernel.connectedTarget.coordinateTargetOAuthConnected(database, options.mapping, configuration, (_transaction, services) => Effect.provideService(body, OAuthConnectedPersistence, services.oauthConnectedPersistence)));
|
|
106
|
+
const makeOAuthConnectedRevocationServices = (mapping) => using(({ kernel, configuration }) => kernel.connectedTarget.makeTargetOAuthConnectedRevocationServices(mapping, configuration));
|
|
107
|
+
/** Run auth and application SQL in one adapter-owned transaction and commit journal. */
|
|
108
|
+
const coordinateOAuthConnectedRevocations = (options, body) => using(({ kernel, configuration, database }) => kernel.connectedTarget.coordinateTargetOAuthConnectedRevocations(database, options.mapping, configuration, (_transaction, services) => Effect.provideService(body, OAuthConnectedRevocations, services.oauthConnectedRevocations)));
|
|
109
|
+
const makeOAuthRegistrationServices = (mapping) => using(({ kernel, configuration }) => kernel.target.makeTargetOAuthRegistrationServices(mapping, configuration));
|
|
110
|
+
const coordinateOAuthRegistration = (options, body) => using(({ kernel, configuration, database }) => kernel.target.coordinateTargetOAuthRegistration(database, options.mapping, configuration, (_transaction, services) => Effect.provideService(body, options.target, services.registrationAuthority)));
|
|
111
|
+
/** Include these guards when login ownership may also hold retained grants. */
|
|
112
|
+
const oauthConnectedOwnershipReferences = (mapping, dialect) => kernels[dialect].connectedReference.oauthConnectedOwnershipReferences(mapping);
|
|
113
|
+
const { oauthAccountsPersistenceLayer, oauthSignInPersistenceLayer, oauthRegistrationIntentsLayer, oauthRegistrationAuthorityLayer } = kernels.sqlite.target;
|
|
114
|
+
const { oauthConnectedPersistenceLayer, oauthConnectedRevocationsLayer } = kernels.sqlite.connectedTarget;
|
|
115
|
+
/** Shared session issuance must validate the same subject and credential authority
|
|
116
|
+
* as OAuth. Supply this service when it is not already provided by session storage. */
|
|
117
|
+
const makeAuthenticationAuthorityServices = (mapping) => using(({ database, configuration }) => makeSessionKernel(operations, (client) => makeNativeSqlTables(client)).makeSqlAuthenticationAuthority(mapping, {
|
|
118
|
+
mode: "interactive",
|
|
119
|
+
locking: configuration.locking,
|
|
120
|
+
standaloneGuard: requireStandalone(() => SessionUnavailable.make({}), database.$client.transactionService)
|
|
121
|
+
}).pipe(Effect.provideService(CurrentSessionSql, database), Effect.map((authenticationAuthority) => ({ authenticationAuthority }))));
|
|
122
|
+
//#endregion
|
|
123
|
+
export { OAuthPersistence_exports, and, clock, coordinateOAuthAccounts, coordinateOAuthConnected, coordinateOAuthConnectedRevocations, coordinateOAuthRegistration, coordinateOAuthRegistrationIntents, coordinateOAuthSignIn, eq, makeAuthenticationAuthorityServices, makeOAuthAccountsServices, makeOAuthConnectedRevocationServices, makeOAuthConnectedServices, makeOAuthRegistrationIntentServices, makeOAuthRegistrationServices, makeOAuthSignInServices, oauthAccountsPersistenceLayer, oauthCleanupTable, oauthConnectedOwnershipReferences, oauthConnectedPersistenceLayer, oauthConnectedPolicyGuard, oauthConnectedRevocationsLayer, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationAuthorityLayer, oauthRegistrationGuardTable, oauthRegistrationIntentsLayer, oauthSignInPersistenceLayer, requiredOAuthAccountsConstraints, requiredOAuthConnectedConstraints, requiredOAuthConnectedRevocationConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints, sql, table };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=OAuthPersistence.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthPersistence.mjs","names":[],"sources":["../src/OAuthPersistence.ts"],"sourcesContent":["/** Direct Effect SQL persistence for upstream OAuth accounts. PostgreSQL and SQLite\n * require interactive transactions; provider exchanges occur outside coordinators. */\nimport type { LifecycleHooks } from \"@yielded/auth/Hooks\";\nimport {\n OAuthAccountsPersistence,\n OAuthSignInPersistence,\n OAuthRegistrationIntents,\n OAuthConnectedPersistence,\n OAuthConnectedRevocations,\n OAuthUnavailable,\n} from \"@yielded/auth/OAuth\";\nimport type { AuthenticationAuthority } from \"@yielded/auth/Sessions\";\nimport { SessionUnavailable } from \"@yielded/auth/Sessions\";\nimport { type Context, type Crypto, Effect, Predicate, Schema } from \"effect\";\nimport { SqlClient } from \"effect/sql\";\n\nimport { PersistenceConfigurationError } from \"./internal/configuration\";\nimport type { AuthenticationAuthorityMapping as AuthorityMapping } from \"./internal/models/session-model\";\nimport { makeNativeSqlTables } from \"./internal/native-sql-table\";\nimport { makeOAuthKernel } from \"./internal/oauth-kernel\";\nimport type { OAuthCoordinatorError, OAuthTargetConfiguration } from \"./internal/oauth/target\";\nimport {\n CurrentSessionSql,\n makeSessionKernel,\n type SessionSqlDatabase,\n} from \"./internal/session-kernel\";\nimport type {\n OAuthConnectedMapping,\n OAuthConnectedRevocationMapping,\n} from \"./internal/sql-oauth-connected-model\";\nimport type {\n SqlTableModel,\n OAuthAccountsMapping,\n OAuthSignInMapping,\n OAuthRegistrationIntentMapping,\n OAuthRegistrationMapping,\n OAuthRegistrationAuthority,\n OAuthReferenceGuardDescriptor,\n} from \"./internal/sql-oauth-model\";\nimport { makeSqlDatabase, sqlQueryOperations, sql } from \"./internal/sql-query\";\nimport { validateSqlStorage } from \"./internal/sql-storage-validation\";\nimport { Table, Fragment } from \"./internal/sql-table\";\nimport { requireStandalone } from \"./internal/standalone\";\nimport type { StorageTable } from \"./internal/storage-tables\";\nimport { NativeDatabase } from \"./internal/transaction-kernel\";\nimport type { TransactionNativeDatabase } from \"./internal/transaction-kernel\";\nexport * from \"./internal/sql-oauth-model\";\nexport * from \"./internal/sql-oauth-connected-model\";\nexport { sql };\nexport { and, eq } from \"./internal/sql-query\";\n\n/** Physical identifiers and representations only; applications own migrations. */\nexport const table = (definition: StorageTable) =>\n new Table(definition.name, definition.columns, definition.unique, definition.schema);\n\n/** Integer-millisecond engine clock, sampled after locks on either supported dialect. */\nexport const clock = {\n encodeInstant: Schema.encodeSync(Schema.Int),\n decodeInstant: Schema.decodeUnknownSync(Schema.Int),\n engineNowMillis: new Fragment((compiler) =>\n compiler.dialect === \"pg\"\n ? \"cast(extract(epoch from clock_timestamp()) * 1000 as bigint)\"\n : \"cast(round((julianday('now') - 2440587.5) * 86400000) as integer)\",\n ),\n};\n\nconst operations = { ...sqlQueryOperations, validateStorage: validateSqlStorage };\n\nconst kernels = {\n pg: makeOAuthKernel(operations, () => \"pg\"),\n sqlite: makeOAuthKernel(operations, () => \"sqlite\"),\n};\n\nconst acquire = Effect.gen(function* () {\n const client = yield* SqlClient.SqlClient;\n\n const dialect = client.onDialectOrElse({\n pg: () => \"pg\" as const,\n sqlite: () => \"sqlite\" as const,\n orElse: () => undefined,\n });\n\n // D1 exposes the SQLite compiler but its public driver brand identifies a\n // batch-only client. Keep the default package free of a D1 runtime dependency.\n if (dialect === undefined || Predicate.hasProperty(client, \"~@effect/sql-d1/D1Client\"))\n return yield* PersistenceConfigurationError.make({\n reason: \"OAuth persistence requires PostgreSQL or SQLite with interactive transactions\",\n });\n\n const database = yield* makeSqlDatabase(dialect);\n\n const configuration: OAuthTargetConfiguration = {\n mode: \"interactive\",\n dialect,\n locking: dialect === \"pg\",\n standaloneGuard: (service) => requireStandalone(() => OAuthUnavailable.make({}), service),\n };\n\n // Erase only the query-builder handle; batch methods are never selected by this adapter.\n return {\n database: database as unknown as TransactionNativeDatabase,\n configuration,\n kernel: kernels[dialect],\n };\n});\n\nconst using = <A, E, R>(body: (input: Effect.Success<typeof acquire>) => Effect.Effect<A, E, R>) =>\n Effect.flatMap(acquire, (input) =>\n body(input).pipe(Effect.provideService(NativeDatabase, input.database)),\n );\n\nexport const makeOAuthSignInServices = <N>(\n mapping: OAuthSignInMapping<Table, Table, Table, Table, Table, N>,\n): Effect.Effect<\n { readonly oauthSignInPersistence: OAuthSignInPersistence[\"Service\"] },\n OAuthUnavailable | PersistenceConfigurationError,\n Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration }) =>\n kernel.target.makeTargetOAuthSignInServices(mapping, configuration),\n );\n\n/** Run auth and application SQL in one adapter-owned transaction and commit journal. */\nexport const coordinateOAuthSignIn = <N, A, E, R>(\n options: { readonly mapping: OAuthSignInMapping<Table, Table, Table, Table, Table, N> },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E> | PersistenceConfigurationError,\n Exclude<R, OAuthSignInPersistence> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration, database }) =>\n kernel.target.coordinateTargetOAuthSignIn(\n database,\n options.mapping,\n configuration,\n (_transaction, services) =>\n Effect.provideService(body, OAuthSignInPersistence, services.oauthSignInPersistence),\n ),\n );\n\nexport const makeOAuthRegistrationIntentServices = <N>(\n mapping: OAuthRegistrationIntentMapping<Table, Table, Table, Table, Table, Table, Table, N>,\n): Effect.Effect<\n { readonly oauthRegistrationIntents: OAuthRegistrationIntents[\"Service\"] },\n OAuthUnavailable | PersistenceConfigurationError,\n Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration }) =>\n kernel.target.makeTargetOAuthRegistrationIntentServices(mapping, configuration),\n );\n\n/** Run auth and application SQL in one adapter-owned transaction and commit journal. */\nexport const coordinateOAuthRegistrationIntents = <N, A, E, R>(\n options: {\n readonly mapping: OAuthRegistrationIntentMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N\n >;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E> | PersistenceConfigurationError,\n Exclude<R, OAuthRegistrationIntents> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration, database }) =>\n kernel.target.coordinateTargetOAuthRegistrationIntents(\n database,\n options.mapping,\n configuration,\n (_transaction, services) =>\n Effect.provideService(body, OAuthRegistrationIntents, services.oauthRegistrationIntents),\n ),\n );\n\nexport const makeOAuthAccountsServices = <N>(\n mapping: OAuthAccountsMapping<Table, Table, Table, Table, Table, Table, Table, N>,\n): Effect.Effect<\n { readonly oauthAccountsPersistence: OAuthAccountsPersistence[\"Service\"] },\n OAuthUnavailable | PersistenceConfigurationError,\n Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration }) =>\n kernel.target.makeTargetOAuthAccountsServices(mapping, configuration),\n );\n\n/** Run auth and application SQL in one adapter-owned transaction and commit journal. */\nexport const coordinateOAuthAccounts = <N, A, E, R>(\n options: {\n readonly mapping: OAuthAccountsMapping<Table, Table, Table, Table, Table, Table, Table, N>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E> | PersistenceConfigurationError,\n Exclude<R, OAuthAccountsPersistence> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration, database }) =>\n kernel.target.coordinateTargetOAuthAccounts(\n database,\n options.mapping,\n configuration,\n (_transaction, services) =>\n Effect.provideService(body, OAuthAccountsPersistence, services.oauthAccountsPersistence),\n ),\n );\n\nexport const makeOAuthConnectedServices = <N>(\n mapping: OAuthConnectedMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N,\n Table\n >,\n): Effect.Effect<\n { readonly oauthConnectedPersistence: OAuthConnectedPersistence[\"Service\"] },\n OAuthUnavailable | PersistenceConfigurationError,\n Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration }) =>\n kernel.connectedTarget.makeTargetOAuthConnectedServices(mapping, configuration),\n );\n\n/** Run auth and application SQL in one adapter-owned transaction and commit journal. */\nexport const coordinateOAuthConnected = <N, A, E, R>(\n options: {\n readonly mapping: OAuthConnectedMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N,\n Table\n >;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E> | PersistenceConfigurationError,\n Exclude<R, OAuthConnectedPersistence> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration, database }) =>\n kernel.connectedTarget.coordinateTargetOAuthConnected(\n database,\n options.mapping,\n configuration,\n (_transaction, services) =>\n Effect.provideService(body, OAuthConnectedPersistence, services.oauthConnectedPersistence),\n ),\n );\n\nexport const makeOAuthConnectedRevocationServices = <N>(\n mapping: OAuthConnectedRevocationMapping<Table, Table, Table, Table, Table, Table, Table, N>,\n): Effect.Effect<\n { readonly oauthConnectedRevocations: OAuthConnectedRevocations[\"Service\"] },\n OAuthUnavailable | PersistenceConfigurationError,\n Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration }) =>\n kernel.connectedTarget.makeTargetOAuthConnectedRevocationServices(mapping, configuration),\n );\n\n/** Run auth and application SQL in one adapter-owned transaction and commit journal. */\nexport const coordinateOAuthConnectedRevocations = <N, A, E, R>(\n options: {\n readonly mapping: OAuthConnectedRevocationMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N\n >;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E> | PersistenceConfigurationError,\n Exclude<R, OAuthConnectedRevocations> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration, database }) =>\n kernel.connectedTarget.coordinateTargetOAuthConnectedRevocations(\n database,\n options.mapping,\n configuration,\n (_transaction, services) =>\n Effect.provideService(body, OAuthConnectedRevocations, services.oauthConnectedRevocations),\n ),\n );\n\nexport const makeOAuthRegistrationServices = <Registration, N>(\n mapping: OAuthRegistrationMapping<\n Registration,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N\n >,\n): Effect.Effect<\n { readonly registrationAuthority: OAuthRegistrationAuthority<Registration> },\n OAuthUnavailable | PersistenceConfigurationError,\n Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration }) =>\n kernel.target.makeTargetOAuthRegistrationServices<Registration>(mapping, configuration),\n );\n\nexport const coordinateOAuthRegistration = <Id, Registration, N, A, E, R>(\n options: {\n readonly mapping: OAuthRegistrationMapping<\n NoInfer<Registration>,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N\n >;\n readonly target: Context.Key<Id, OAuthRegistrationAuthority<Registration>>;\n },\n body: Effect.Effect<A, E, R>,\n): Effect.Effect<\n A,\n OAuthCoordinatorError<E> | PersistenceConfigurationError,\n Exclude<R, Id> | Crypto.Crypto | LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ kernel, configuration, database }) =>\n kernel.target.coordinateTargetOAuthRegistration<Registration, unknown, A, E, Exclude<R, Id>>(\n database,\n options.mapping,\n configuration,\n (_transaction, services) =>\n Effect.provideService(body, options.target, services.registrationAuthority),\n ),\n );\n\n/** Include these guards when login ownership may also hold retained grants. */\nexport const oauthConnectedOwnershipReferences = <N>(\n mapping: OAuthConnectedMapping<\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n Table,\n N,\n Table\n >,\n dialect: \"pg\" | \"sqlite\",\n) =>\n // The selected compiler supplies Fragment handles; domain values retain their codecs.\n kernels[dialect].connectedReference.oauthConnectedOwnershipReferences(mapping) as {\n readonly connectedReferenceGuards: ReadonlyArray<OAuthReferenceGuardDescriptor<N>>;\n readonly connectedReference: (input: {\n readonly identityKey: string;\n readonly subjectId: N;\n }) => Fragment;\n };\n\nexport const {\n oauthAccountsPersistenceLayer,\n oauthSignInPersistenceLayer,\n oauthRegistrationIntentsLayer,\n oauthRegistrationAuthorityLayer,\n} = kernels.sqlite.target;\n\nexport const { oauthConnectedPersistenceLayer, oauthConnectedRevocationsLayer } =\n kernels.sqlite.connectedTarget;\n\n/** Shared session issuance must validate the same subject and credential authority\n * as OAuth. Supply this service when it is not already provided by session storage. */\nexport const makeAuthenticationAuthorityServices = <Claims, N>(\n mapping: AuthorityMapping<Claims, SqlTableModel, SqlTableModel, SqlTableModel, SqlTableModel, N>,\n): Effect.Effect<\n { readonly authenticationAuthority: AuthenticationAuthority[\"Service\"] },\n SessionUnavailable | PersistenceConfigurationError,\n LifecycleHooks | SqlClient.SqlClient\n> =>\n using(({ database, configuration }) =>\n makeSessionKernel(operations, (client) => makeNativeSqlTables(client))\n .makeSqlAuthenticationAuthority(mapping, {\n mode: \"interactive\",\n locking: configuration.locking,\n standaloneGuard: requireStandalone(\n () => SessionUnavailable.make({}),\n database.$client.transactionService,\n ),\n })\n .pipe(\n // Both kernels capture the same raw SQL query-builder handle and client.\n Effect.provideService(CurrentSessionSql, database as unknown as SessionSqlDatabase),\n Effect.map((authenticationAuthority) => ({ authenticationAuthority })),\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAa,SAAS,eACpB,IAAI,MAAM,WAAW,MAAM,WAAW,SAAS,WAAW,QAAQ,WAAW,MAAM;;AAGrF,MAAa,QAAQ;CACnB,eAAe,OAAO,WAAW,OAAO,GAAG;CAC3C,eAAe,OAAO,kBAAkB,OAAO,GAAG;CAClD,iBAAiB,IAAI,UAAU,aAC7B,SAAS,YAAY,OACjB,iEACA,mEACN;AACF;AAEA,MAAM,aAAa;CAAE,GAAG;CAAoB,iBAAiB;AAAmB;AAEhF,MAAM,UAAU;CACd,IAAI,gBAAgB,kBAAkB,IAAI;CAC1C,QAAQ,gBAAgB,kBAAkB,QAAQ;AACpD;AAEA,MAAM,UAAU,OAAO,IAAI,aAAa;CACtC,MAAM,SAAS,OAAO,UAAU;CAEhC,MAAM,UAAU,OAAO,gBAAgB;EACrC,UAAU;EACV,cAAc;EACd,cAAc,KAAA;CAChB,CAAC;CAID,IAAI,YAAY,KAAA,KAAa,UAAU,YAAY,QAAQ,0BAA0B,GACnF,OAAO,OAAO,8BAA8B,KAAK,EAC/C,QAAQ,gFACV,CAAC;CAYH,OAAO;EACL,UAAU,OAXY,gBAAgB,OAAO;EAY7C,eAAA;GATA,MAAM;GACN;GACA,SAAS,YAAY;GACrB,kBAAkB,YAAY,wBAAwB,iBAAiB,KAAK,CAAC,CAAC,GAAG,OAAO;EAM5E;EACZ,QAAQ,QAAQ;CAClB;AACF,CAAC;AAED,MAAM,SAAkB,SACtB,OAAO,QAAQ,UAAU,UACvB,KAAK,KAAK,CAAC,CAAC,KAAK,OAAO,eAAe,gBAAgB,MAAM,QAAQ,CAAC,CACxE;AAEF,MAAa,2BACX,YAMA,OAAO,EAAE,QAAQ,oBACf,OAAO,OAAO,8BAA8B,SAAS,aAAa,CACpE;;AAGF,MAAa,yBACX,SACA,SAMA,OAAO,EAAE,QAAQ,eAAe,eAC9B,OAAO,OAAO,4BACZ,UACA,QAAQ,SACR,gBACC,cAAc,aACb,OAAO,eAAe,MAAM,wBAAwB,SAAS,sBAAsB,CACvF,CACF;AAEF,MAAa,uCACX,YAMA,OAAO,EAAE,QAAQ,oBACf,OAAO,OAAO,0CAA0C,SAAS,aAAa,CAChF;;AAGF,MAAa,sCACX,SAYA,SAMA,OAAO,EAAE,QAAQ,eAAe,eAC9B,OAAO,OAAO,yCACZ,UACA,QAAQ,SACR,gBACC,cAAc,aACb,OAAO,eAAe,MAAM,0BAA0B,SAAS,wBAAwB,CAC3F,CACF;AAEF,MAAa,6BACX,YAMA,OAAO,EAAE,QAAQ,oBACf,OAAO,OAAO,gCAAgC,SAAS,aAAa,CACtE;;AAGF,MAAa,2BACX,SAGA,SAMA,OAAO,EAAE,QAAQ,eAAe,eAC9B,OAAO,OAAO,8BACZ,UACA,QAAQ,SACR,gBACC,cAAc,aACb,OAAO,eAAe,MAAM,0BAA0B,SAAS,wBAAwB,CAC3F,CACF;AAEF,MAAa,8BACX,YAmBA,OAAO,EAAE,QAAQ,oBACf,OAAO,gBAAgB,iCAAiC,SAAS,aAAa,CAChF;;AAGF,MAAa,4BACX,SAgBA,SAMA,OAAO,EAAE,QAAQ,eAAe,eAC9B,OAAO,gBAAgB,+BACrB,UACA,QAAQ,SACR,gBACC,cAAc,aACb,OAAO,eAAe,MAAM,2BAA2B,SAAS,yBAAyB,CAC7F,CACF;AAEF,MAAa,wCACX,YAMA,OAAO,EAAE,QAAQ,oBACf,OAAO,gBAAgB,2CAA2C,SAAS,aAAa,CAC1F;;AAGF,MAAa,uCACX,SAYA,SAMA,OAAO,EAAE,QAAQ,eAAe,eAC9B,OAAO,gBAAgB,0CACrB,UACA,QAAQ,SACR,gBACC,cAAc,aACb,OAAO,eAAe,MAAM,2BAA2B,SAAS,yBAAyB,CAC7F,CACF;AAEF,MAAa,iCACX,YAgBA,OAAO,EAAE,QAAQ,oBACf,OAAO,OAAO,oCAAkD,SAAS,aAAa,CACxF;AAEF,MAAa,+BACX,SAcA,SAMA,OAAO,EAAE,QAAQ,eAAe,eAC9B,OAAO,OAAO,kCACZ,UACA,QAAQ,SACR,gBACC,cAAc,aACb,OAAO,eAAe,MAAM,QAAQ,QAAQ,SAAS,qBAAqB,CAC9E,CACF;;AAGF,MAAa,qCACX,SAcA,YAGA,QAAQ,QAAQ,CAAC,mBAAmB,kCAAkC,OAAO;AAQ/E,MAAa,EACX,+BACA,6BACA,+BACA,oCACE,QAAQ,OAAO;AAEnB,MAAa,EAAE,gCAAgC,mCAC7C,QAAQ,OAAO;;;AAIjB,MAAa,uCACX,YAMA,OAAO,EAAE,UAAU,oBACjB,kBAAkB,aAAa,WAAW,oBAAoB,MAAM,CAAC,CAAC,CACnE,+BAA+B,SAAS;CACvC,MAAM;CACN,SAAS,cAAc;CACvB,iBAAiB,wBACT,mBAAmB,KAAK,CAAC,CAAC,GAChC,SAAS,QAAQ,kBACnB;AACF,CAAC,CAAC,CACD,KAEC,OAAO,eAAe,mBAAmB,QAAyC,GAClF,OAAO,KAAK,6BAA6B,EAAE,wBAAwB,EAAE,CACvE,CACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { PersistenceMappingError } from "./internal/mapping-error.mjs";
|
|
2
|
+
import { OAuthProxyPersistence } from "./internal/oauth-proxy.mjs";
|
|
2
3
|
import { StorageColumn, StorageTable } from "./internal/storage-tables.mjs";
|
|
3
4
|
import { PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
5
|
+
import { OAuthPersistence_d_exports } from "./OAuthPersistence.mjs";
|
|
4
6
|
import { AuthPersistence } from "./internal/sql-persistence.mjs";
|
|
5
7
|
import { OAuthServerPersistence } from "./internal/oauth-server.mjs";
|
|
6
8
|
import { BrowserLoginPersistence } from "./internal/browser-login.mjs";
|
|
7
|
-
export { AuthPersistence, BrowserLoginPersistence, OAuthServerPersistence, PersistenceConfigurationError, PersistenceMappingError, StorageColumn, StorageTable };
|
|
9
|
+
export { AuthPersistence, BrowserLoginPersistence, OAuthPersistence_d_exports as OAuthPersistence, OAuthProxyPersistence, OAuthServerPersistence, PersistenceConfigurationError, PersistenceMappingError, StorageColumn, StorageTable };
|
package/dist/index.mjs
CHANGED
|
@@ -3,5 +3,7 @@ import { PersistenceMappingError } from "./internal/mapping-error.mjs";
|
|
|
3
3
|
import { StorageColumn, StorageTable } from "./internal/storage-tables.mjs";
|
|
4
4
|
import { AuthPersistence } from "./internal/sql-persistence.mjs";
|
|
5
5
|
import { OAuthServerPersistence } from "./internal/oauth-server.mjs";
|
|
6
|
+
import { OAuthProxyPersistence } from "./internal/oauth-proxy.mjs";
|
|
6
7
|
import { BrowserLoginPersistence } from "./internal/browser-login.mjs";
|
|
7
|
-
|
|
8
|
+
import { OAuthPersistence_exports } from "./OAuthPersistence.mjs";
|
|
9
|
+
export { AuthPersistence, BrowserLoginPersistence, OAuthPersistence_exports as OAuthPersistence, OAuthProxyPersistence, OAuthServerPersistence, PersistenceConfigurationError, PersistenceMappingError, StorageColumn, StorageTable };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { sqlMapping } from "./native-sql-table.mjs";
|
|
2
|
+
import { NativeDatabase } from "./transaction-kernel.mjs";
|
|
3
|
+
import { Effect, Schema } from "effect";
|
|
4
|
+
import { AuthenticationRevision, StaleAuthentication } from "@yielded/auth/Sessions";
|
|
5
|
+
//#region src/internal/authority-snapshot.ts
|
|
6
|
+
/** One unlocked statement reads the subject and requested credentials: a coherent
|
|
7
|
+
* preflight view, or a commit owner's view where writers are already serialized.
|
|
8
|
+
* Row-locking commit owners lock and revalidate through their ordered reads.
|
|
9
|
+
*/
|
|
10
|
+
const makeAuthoritySnapshot = (tables, mapping) => Effect.fnUntraced(function* (subjectId, credentialIds) {
|
|
11
|
+
const sql = (yield* NativeDatabase).$client.withoutTransforms();
|
|
12
|
+
if (new Set(credentialIds).size !== credentialIds.length) return yield* StaleAuthentication.make({});
|
|
13
|
+
const { s, c } = yield* sqlMapping(() => ({
|
|
14
|
+
s: tables(mapping.subject.table).as("auth_subject"),
|
|
15
|
+
c: tables(mapping.credential.table).as("auth_credential")
|
|
16
|
+
}));
|
|
17
|
+
const nativeId = yield* sqlMapping(() => mapping.subjectId.toNative(subjectId)).pipe(Effect.flatten);
|
|
18
|
+
const requested = [...credentialIds].sort((a, b) => a.localeCompare(b));
|
|
19
|
+
const rows = yield* sqlMapping(() => sql`select ${s.fields("s_")}
|
|
20
|
+
${requested.length === 0 ? sql.literal("") : sql`, ${c.fields("c_")}`}
|
|
21
|
+
from ${s.name}
|
|
22
|
+
${requested.length === 0 ? sql.literal("") : sql`inner join ${c.name} on
|
|
23
|
+
${c.column(mapping.credential.subjectId)} = ${c.value(mapping.credential.subjectId, nativeId)}
|
|
24
|
+
and ${sql.or(requested.map((id) => sql`${c.column(mapping.credential.credentialId)} = ${c.value(mapping.credential.credentialId, id)}`))}`}
|
|
25
|
+
where ${s.column(mapping.subject.id)} = ${s.value(mapping.subject.id, nativeId)}`).pipe(Effect.flatten);
|
|
26
|
+
const first = rows[0];
|
|
27
|
+
if (first === void 0 || rows.length !== Math.max(1, requested.length)) return yield* StaleAuthentication.make({});
|
|
28
|
+
const subject = yield* sqlMapping(() => s.decode(first, "s_"));
|
|
29
|
+
if (!(yield* sqlMapping(() => mapping.subject.isActiveStatus(subject[mapping.subject.status])))) return yield* StaleAuthentication.make({});
|
|
30
|
+
const credentials = yield* sqlMapping(() => requested.length === 0 ? [] : rows.map((row) => c.decode(row, "c_")));
|
|
31
|
+
if (yield* sqlMapping(() => credentials.some((row) => mapping.credential.status !== void 0 && mapping.credential.isActiveStatus?.(row[mapping.credential.status]) !== true))) return yield* StaleAuthentication.make({});
|
|
32
|
+
const revision = yield* Schema.decodeUnknownEffect(AuthenticationRevision)({
|
|
33
|
+
subjectId,
|
|
34
|
+
securityRevision: subject[mapping.subject.securityRevision],
|
|
35
|
+
credentials: credentials.map((row) => ({
|
|
36
|
+
credentialId: row[mapping.credential.credentialId],
|
|
37
|
+
revision: row[mapping.credential.revision]
|
|
38
|
+
}))
|
|
39
|
+
});
|
|
40
|
+
const sorted = [...revision.credentials].sort((a, b) => a.credentialId.localeCompare(b.credentialId));
|
|
41
|
+
if (sorted.some((item, index) => item.credentialId !== requested[index])) return yield* StaleAuthentication.make({});
|
|
42
|
+
return {
|
|
43
|
+
subject,
|
|
44
|
+
revision: {
|
|
45
|
+
...revision,
|
|
46
|
+
credentials: sorted
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
//#endregion
|
|
51
|
+
export { makeAuthoritySnapshot };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=authority-snapshot.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-snapshot.mjs","names":[],"sources":["../../src/internal/authority-snapshot.ts"],"sourcesContent":["import type { SubjectId } from \"@yielded/auth/Schema\";\nimport { AuthenticationRevision, StaleAuthentication } from \"@yielded/auth/Sessions\";\nimport { Effect, Schema } from \"effect\";\n\nimport type { SessionAuthorityTables } from \"./models/session-model\";\nimport { sqlMapping, type NativeSqlTables } from \"./native-sql-table\";\nimport type { AnyTableModel } from \"./query-operations\";\nimport { NativeDatabase } from \"./transaction-kernel\";\n\n/** One unlocked statement reads the subject and requested credentials: a coherent\n * preflight view, or a commit owner's view where writers are already serialized.\n * Row-locking commit owners lock and revalidate through their ordered reads.\n */\nexport const makeAuthoritySnapshot = (\n tables: NativeSqlTables,\n mapping: SessionAuthorityTables<AnyTableModel, AnyTableModel, unknown>,\n) =>\n Effect.fnUntraced(function* (subjectId: SubjectId, credentialIds: ReadonlyArray<string>) {\n const sql = (yield* NativeDatabase).$client.withoutTransforms();\n\n if (new Set(credentialIds).size !== credentialIds.length)\n return yield* StaleAuthentication.make({});\n\n const { s, c } = yield* sqlMapping(() => ({\n s: tables(mapping.subject.table).as(\"auth_subject\"),\n c: tables(mapping.credential.table).as(\"auth_credential\"),\n }));\n\n const nativeId = yield* sqlMapping(() => mapping.subjectId.toNative(subjectId)).pipe(\n Effect.flatten,\n );\n\n const requested = [...credentialIds].sort((a, b) => a.localeCompare(b));\n\n const rows = yield* sqlMapping(\n () => sql<Record<string, unknown>>`select ${s.fields(\"s_\")}\n ${requested.length === 0 ? sql.literal(\"\") : sql`, ${c.fields(\"c_\")}`}\n from ${s.name}\n ${\n requested.length === 0\n ? sql.literal(\"\")\n : sql`inner join ${c.name} on\n ${c.column(mapping.credential.subjectId)} = ${c.value(mapping.credential.subjectId, nativeId)}\n and ${sql.or(requested.map((id) => sql`${c.column(mapping.credential.credentialId)} = ${c.value(mapping.credential.credentialId, id)}`))}`\n }\n where ${s.column(mapping.subject.id)} = ${s.value(mapping.subject.id, nativeId)}`,\n ).pipe(Effect.flatten);\n\n const first = rows[0];\n\n if (first === undefined || rows.length !== Math.max(1, requested.length))\n return yield* StaleAuthentication.make({});\n\n const subject = yield* sqlMapping(() => s.decode(first, \"s_\"));\n\n if (!(yield* sqlMapping(() => mapping.subject.isActiveStatus(subject[mapping.subject.status]))))\n return yield* StaleAuthentication.make({});\n\n const credentials = yield* sqlMapping(() =>\n requested.length === 0 ? [] : rows.map((row) => c.decode(row, \"c_\")),\n );\n\n if (\n yield* sqlMapping(() =>\n credentials.some(\n (row) =>\n mapping.credential.status !== undefined &&\n mapping.credential.isActiveStatus?.(row[mapping.credential.status]) !== true,\n ),\n )\n )\n return yield* StaleAuthentication.make({});\n\n const revision = yield* Schema.decodeUnknownEffect(AuthenticationRevision)({\n subjectId,\n securityRevision: subject[mapping.subject.securityRevision],\n credentials: credentials.map((row) => ({\n credentialId: row[mapping.credential.credentialId],\n revision: row[mapping.credential.revision],\n })),\n });\n\n const sorted = [...revision.credentials].sort((a, b) =>\n a.credentialId.localeCompare(b.credentialId),\n );\n\n if (sorted.some((item, index) => item.credentialId !== requested[index]))\n return yield* StaleAuthentication.make({});\n\n return { subject, revision: { ...revision, credentials: sorted } };\n });\n"],"mappings":";;;;;;;;;AAaA,MAAa,yBACX,QACA,YAEA,OAAO,WAAW,WAAW,WAAsB,eAAsC;CACvF,MAAM,OAAO,OAAO,eAAA,CAAgB,QAAQ,kBAAkB;CAE9D,IAAI,IAAI,IAAI,aAAa,CAAC,CAAC,SAAS,cAAc,QAChD,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;CAE3C,MAAM,EAAE,GAAG,MAAM,OAAO,kBAAkB;EACxC,GAAG,OAAO,QAAQ,QAAQ,KAAK,CAAC,CAAC,GAAG,cAAc;EAClD,GAAG,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC,GAAG,iBAAiB;CAC1D,EAAE;CAEF,MAAM,WAAW,OAAO,iBAAiB,QAAQ,UAAU,SAAS,SAAS,CAAC,CAAC,CAAC,KAC9E,OAAO,OACT;CAEA,MAAM,YAAY,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;CAEtE,MAAM,OAAO,OAAO,iBACZ,GAA4B,UAAU,EAAE,OAAO,IAAI,EAAE;QACzD,UAAU,WAAW,IAAI,IAAI,QAAQ,EAAE,IAAI,GAAG,KAAK,EAAE,OAAO,IAAI,IAAI;aAC/D,EAAE,KAAK;QAEZ,UAAU,WAAW,IACjB,IAAI,QAAQ,EAAE,IACd,GAAG,cAAc,EAAE,KAAK;UAC1B,EAAE,OAAO,QAAQ,WAAW,SAAS,EAAE,KAAK,EAAE,MAAM,QAAQ,WAAW,WAAW,QAAQ,EAAE;cACxF,IAAI,GAAG,UAAU,KAAK,OAAO,GAAG,GAAG,EAAE,OAAO,QAAQ,WAAW,YAAY,EAAE,KAAK,EAAE,MAAM,QAAQ,WAAW,cAAc,EAAE,GAAG,CAAC,IACxI;cACO,EAAE,OAAO,QAAQ,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,QAAQ,QAAQ,IAAI,QAAQ,GAChF,CAAC,CAAC,KAAK,OAAO,OAAO;CAErB,MAAM,QAAQ,KAAK;CAEnB,IAAI,UAAU,KAAA,KAAa,KAAK,WAAW,KAAK,IAAI,GAAG,UAAU,MAAM,GACrE,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;CAE3C,MAAM,UAAU,OAAO,iBAAiB,EAAE,OAAO,OAAO,IAAI,CAAC;CAE7D,IAAI,EAAE,OAAO,iBAAiB,QAAQ,QAAQ,eAAe,QAAQ,QAAQ,QAAQ,OAAO,CAAC,IAC3F,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;CAE3C,MAAM,cAAc,OAAO,iBACzB,UAAU,WAAW,IAAI,CAAC,IAAI,KAAK,KAAK,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC,CACrE;CAEA,IACE,OAAO,iBACL,YAAY,MACT,QACC,QAAQ,WAAW,WAAW,KAAA,KAC9B,QAAQ,WAAW,iBAAiB,IAAI,QAAQ,WAAW,OAAO,MAAM,IAC5E,CACF,GAEA,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;CAE3C,MAAM,WAAW,OAAO,OAAO,oBAAoB,sBAAsB,CAAC,CAAC;EACzE;EACA,kBAAkB,QAAQ,QAAQ,QAAQ;EAC1C,aAAa,YAAY,KAAK,SAAS;GACrC,cAAc,IAAI,QAAQ,WAAW;GACrC,UAAU,IAAI,QAAQ,WAAW;EACnC,EAAE;CACJ,CAAC;CAED,MAAM,SAAS,CAAC,GAAG,SAAS,WAAW,CAAC,CAAC,MAAM,GAAG,MAChD,EAAE,aAAa,cAAc,EAAE,YAAY,CAC7C;CAEA,IAAI,OAAO,MAAM,MAAM,UAAU,KAAK,iBAAiB,UAAU,MAAM,GACrE,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;CAE3C,OAAO;EAAE;EAAS,UAAU;GAAE,GAAG;GAAU,aAAa;EAAO;CAAE;AACnE,CAAC"}
|
|
@@ -98,7 +98,7 @@ type UsesProofs<A extends {
|
|
|
98
98
|
readonly strategies: Readonly<Record<string, Strategy>>;
|
|
99
99
|
}> = Enabled<A, "phone"> | Enabled<A, "email"> | ManagedPassword<A>;
|
|
100
100
|
export type Ports<C extends ClaimsCodec, Id extends string, A extends Definition<C, Id>> = AuthenticationAuthority | KeyId<A["sessions"]["StatefulSessionPersistence"]> | KeyId<A["sessions"]["SessionRepository"]> | (Enabled<A, "password"> extends never ? never : PasswordPersistence) | KeyId<RegistrationKey<ManagedPassword<A>>> | (Enabled<A, "passkey"> extends never ? never : PasskeyPersistence | PasskeyCredentials) | (ManagedPasskey<A> extends never ? never : PasskeyManagementPersistence | PasskeyEnrollmentContext) | (Enabled<A, "email"> extends never ? never : EmailAddressPersistence) | (UsesProofs<A> extends never ? never : ProofPersistence) | (Enabled<A, "phone"> extends never ? never : PhoneAdmission | PhoneSignInTargets);
|
|
101
|
-
export type Roles<C extends ClaimsCodec, Id extends string, A extends Definition<C, Id>> = "identifiers" | "credentials" | "sessions" | "sessionFlows" | (Enabled<A, "password"> extends never ? never : "passwords" | "
|
|
101
|
+
export type Roles<C extends ClaimsCodec, Id extends string, A extends Definition<C, Id>> = "identifiers" | "credentials" | "sessions" | "sessionFlows" | (Enabled<A, "password"> extends never ? never : "passwords" | "passwordCommands") | (ManagedPassword<A> extends never ? never : "passwordRegistrations") | (Enabled<A, "phone"> extends never ? never : "phoneState") | (Enabled<A, "email"> extends never ? never : "emailCredentials" | "emailCommands") | (Enabled<A, "passkey"> extends never ? never : "passkeyCredentials" | "passkeyOwnership" | "passkeyHandles" | "passkeyModules" | "passkeyFlows" | "passkeyAdmissions" | "passkeyCharges") | (ManagedPasskey<A> extends never ? never : "passkeyCommands") | (UsesProofs<A> extends never ? never : ProofRoles);
|
|
102
102
|
export interface SubjectOptions<T extends object, NativeId> {
|
|
103
103
|
readonly table: T;
|
|
104
104
|
readonly id: string;
|