@yielded/auth-persistence 0.1.0-beta.23 → 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 +12 -6
- package/dist/Adapter.mjs +8 -3
- 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/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 -47
- package/dist/internal/models/password-model.mjs +0 -1
- package/dist/internal/models/password-model.mjs.map +1 -1
- package/dist/internal/native-sql-table.d.mts +4 -0
- package/dist/internal/native-sql-table.mjs +7 -0
- package/dist/internal/native-sql-table.mjs.map +1 -1
- 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-kernel.d.mts +5 -5
- package/dist/internal/{password-attempts.d.mts → password-credentials.d.mts} +3 -4
- package/dist/internal/password-credentials.mjs +121 -0
- package/dist/internal/password-credentials.mjs.map +1 -0
- package/dist/internal/password-kernel.d.mts +8 -24
- package/dist/internal/password-kernel.mjs +4 -42
- package/dist/internal/password-kernel.mjs.map +1 -1
- package/dist/internal/persistence.d.mts +1 -1
- package/dist/internal/persistence.mjs +2 -2
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/query-operations.d.mts +2 -0
- package/dist/internal/session-kernel.d.mts +2 -2
- package/dist/internal/session-kernel.mjs +74 -18
- 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-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 +1 -37
- 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 -56
- package/dist/internal/storage-tables.mjs +0 -17
- 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-kernel.mjs +3 -2
- package/dist/internal/transaction-kernel.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Adapter.ts +89 -5
- package/src/OAuthPersistence.ts +427 -0
- package/src/index.ts +3 -0
- package/src/internal/configuration.ts +1 -3
- 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 -56
- package/src/internal/native-sql-table.ts +14 -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 +5 -98
- package/src/internal/persistence.ts +1 -1
- package/src/internal/query-operations.ts +2 -0
- package/src/internal/session-kernel.ts +143 -55
- package/src/internal/sql-oauth-connected-model.ts +145 -0
- package/src/internal/sql-oauth-model.ts +263 -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 -37
- package/src/internal/storage-plans.ts +218 -0
- package/src/internal/storage-tables.ts +0 -20
- package/src/internal/storage-validation.ts +58 -0
- package/src/internal/transaction-kernel.ts +6 -2
- package/dist/internal/password-attempts.mjs +0 -197
- package/dist/internal/password-attempts.mjs.map +0 -1
- package/src/internal/password-attempts.ts +0 -466
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.mjs","names":[],"sources":["../../../src/internal/oauth/input.ts"],"sourcesContent":["import {\n OAuthAccountRevision,\n OAuthActionAuthorization,\n OAuthLinkAccess,\n OAuthLinkClaim,\n OAuthLinkOutcome,\n OAuthLinkPendingFlow,\n OAuthRegistrationAccess,\n OAuthRegistrationFingerprint,\n OAuthRegistrationIntent,\n OAuthClaim,\n OAuthClaimId,\n OAuthCleanupInput,\n OAuthCommandId,\n OAuthCredentialSnapshot,\n OAuthInstant,\n OAuthModuleId,\n OAuthPendingFlow,\n OAuthSignInTransactionContext,\n OAuthVerifiedExternalIdentity,\n snapshotOAuthSync,\n type OAuthUnavailable,\n} from \"@yielded/auth/OAuth\";\nimport { SessionInvalidationWindow } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- private adapter wraps only the Effect-valued semantic ports. */\nimport { Effect, Schema } from \"effect\";\n\nimport { invariant, unavailable } from \"./state\";\n\nconst fields = OAuthSignInTransactionContext.fields;\n\nconst claimInput = Schema.Struct({\n moduleId: fields.moduleId,\n generation: fields.generation,\n flowId: fields.flowId,\n provider: fields.provider,\n callbackId: fields.callbackId,\n stateDigest: fields.stateDigest,\n requestBindingVerifier: fields.requestBindingVerifier,\n requestBindingExpiresAtMillis: fields.requestBindingExpiresAtMillis,\n responseIssuer: Schema.optionalKey(fields.issuer),\n claimId: OAuthClaimId,\n nowMillis: OAuthInstant,\n});\n\nconst signInOutcome = Schema.Union([\n Schema.TaggedStruct(\"Verified\", { identity: OAuthVerifiedExternalIdentity }),\n Schema.TaggedStruct(\"Cancelled\", {}),\n Schema.TaggedStruct(\"Rejected\", {}),\n Schema.TaggedStruct(\"Ambiguous\", {}),\n]);\n\nconst signInSettle = Schema.Struct({\n claim: OAuthClaim,\n outcome: signInOutcome,\n nowMillis: OAuthInstant,\n});\n\nconst registrationSettle = Schema.Struct({\n claim: OAuthClaim,\n identity: OAuthVerifiedExternalIdentity,\n intent: Schema.optionalKey(OAuthRegistrationIntent),\n nowMillis: OAuthInstant,\n});\n\nconst registerPrivate = Schema.Struct({\n access: OAuthRegistrationAccess,\n intent: OAuthRegistrationIntent,\n commandId: OAuthCommandId,\n fingerprint: OAuthRegistrationFingerprint,\n});\n\nconst capture = Schema.Struct({\n moduleId: OAuthModuleId,\n subjectId: OAuthAccountRevision.fields.subjectId,\n});\n\nconst linkIssue = Schema.Struct({\n flow: OAuthLinkPendingFlow,\n authorization: OAuthActionAuthorization,\n});\n\nconst linkClaim = Schema.Struct({\n access: OAuthLinkAccess,\n flow: OAuthLinkPendingFlow,\n claimId: OAuthClaimId,\n authorization: OAuthActionAuthorization,\n});\n\nconst linkSettle = Schema.Struct({\n claim: OAuthLinkClaim,\n outcome: OAuthLinkOutcome,\n authorization: OAuthActionAuthorization,\n invalidation: SessionInvalidationWindow,\n nowMillis: OAuthInstant,\n});\n\nconst unlinkInspect = Schema.Struct({\n moduleId: OAuthModuleId,\n subjectId: OAuthAccountRevision.fields.subjectId,\n commandId: OAuthCommandId,\n credentialId: OAuthCredentialSnapshot.fields.credentialId,\n});\n\nconst unlink = Schema.Struct({\n moduleId: OAuthModuleId,\n commandId: OAuthCommandId,\n credential: OAuthCredentialSnapshot,\n authorization: OAuthActionAuthorization,\n invalidation: SessionInvalidationWindow,\n nowMillis: OAuthInstant,\n retentionUntilMillis: OAuthInstant,\n});\n\nconst snapshot = (schema: Schema.Codec<any, any, never, never>) => (input: any) =>\n snapshotOAuthSync(schema, input);\n\nexport const signInInputs = {\n issue: snapshot(OAuthPendingFlow),\n claim: snapshot(claimInput),\n settle: snapshot(signInSettle),\n cleanup: snapshot(OAuthCleanupInput),\n};\n\nexport const registrationIntentInputs = { settle: snapshot(registrationSettle) };\n\nconst capturedApplication = (\n application: { readonly encode: (data: any) => string; readonly decode: (stored: string) => any },\n data: any,\n) => {\n const encoded = application.encode(data);\n\n invariant(typeof encoded === \"string\" && new TextEncoder().encode(encoded).length <= 1048576);\n const retained = application.decode(encoded);\n\n invariant(application.encode(retained) === encoded);\n\n return retained;\n};\n\nexport const registrationInputs = (application: {\n readonly encode: (data: any) => string;\n readonly decode: (stored: string) => any;\n}) => ({\n read: snapshot(OAuthRegistrationAccess),\n inspect: (input: any) => ({\n intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent),\n registration: capturedApplication(application, input.registration),\n }),\n register: (input: any) => ({\n ...snapshotOAuthSync(registerPrivate, input),\n registration: capturedApplication(application, input.registration),\n }),\n cleanup: snapshot(OAuthCleanupInput),\n});\n\nexport const accountsInputs = {\n capture: snapshot(capture),\n issue: snapshot(linkIssue),\n preflight: snapshot(OAuthLinkAccess),\n claim: snapshot(linkClaim),\n settle: snapshot(linkSettle),\n inspectUnlink: snapshot(unlinkInspect),\n unlink: snapshot(unlink),\n cleanup: snapshot(OAuthCleanupInput),\n};\n\n/** Snapshot before the first asynchronous owner/allocator step; closed bound\n * authorities reject before running even an application codec or inspector. */\nexport const capturedOAuthService = <\n S extends { [K in keyof S]: (...args: any[]) => Effect.Effect<any, OAuthUnavailable> },\n>(\n service: S,\n inputs: { readonly [K in keyof S]: (input: any) => any },\n active: () => boolean,\n poison: () => void,\n): S =>\n Object.freeze(\n Object.fromEntries(\n Object.entries(service).map(([key, method]) => [\n key,\n (input: any, prepare?: any) =>\n Effect.suspend(() => {\n if (!active()) return Effect.fail(unavailable());\n const retained = inputs[key as keyof S](input);\n\n return (method as (...args: any[]) => Effect.Effect<any, OAuthUnavailable>)(\n retained,\n prepare,\n );\n }).pipe(\n Effect.onExit((exit) =>\n Effect.sync(() => {\n if (exit._tag === \"Failure\") poison();\n }),\n ),\n Effect.catchDefect(() => Effect.fail(unavailable())),\n ),\n ]),\n ),\n ) as S;\n"],"mappings":";;;;;AA6BA,MAAM,SAAS,8BAA8B;AAE7C,MAAM,aAAa,OAAO,OAAO;CAC/B,UAAU,OAAO;CACjB,YAAY,OAAO;CACnB,QAAQ,OAAO;CACf,UAAU,OAAO;CACjB,YAAY,OAAO;CACnB,aAAa,OAAO;CACpB,wBAAwB,OAAO;CAC/B,+BAA+B,OAAO;CACtC,gBAAgB,OAAO,YAAY,OAAO,MAAM;CAChD,SAAS;CACT,WAAW;AACb,CAAC;AAED,MAAM,gBAAgB,OAAO,MAAM;CACjC,OAAO,aAAa,YAAY,EAAE,UAAU,8BAA8B,CAAC;CAC3E,OAAO,aAAa,aAAa,CAAC,CAAC;CACnC,OAAO,aAAa,YAAY,CAAC,CAAC;CAClC,OAAO,aAAa,aAAa,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,eAAe,OAAO,OAAO;CACjC,OAAO;CACP,SAAS;CACT,WAAW;AACb,CAAC;AAED,MAAM,qBAAqB,OAAO,OAAO;CACvC,OAAO;CACP,UAAU;CACV,QAAQ,OAAO,YAAY,uBAAuB;CAClD,WAAW;AACb,CAAC;AAED,MAAM,kBAAkB,OAAO,OAAO;CACpC,QAAQ;CACR,QAAQ;CACR,WAAW;CACX,aAA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ACnE;CACA,WAAW,WAAgB;EACzB,GAAG,kBAAkB,iBAAiB,KAAK;EAC3C,cAAc,oBAAoB,aAAa,MAAM,YAAY;CACnE;CACA,SAAS,SAAS,iBAAiB;AACrC;AAEA,MAAa,iBAAiB;CAC5B,SAAS,SAAS,OAAO;CACzB,OAAO,SAAS,SAAS;CACzB,WAAW,SAAS,eAAe;CACnC,OAAO,SAAS,SAAS;CACzB,QAAQ,SAAS,UAAU;CAC3B,eAAe,SAAS,aAAa;CACrC,QAAQ,SAAS,MAAM;CACvB,SAAS,SAAS,iBAAiB;AACrC;;;AAIA,MAAa,wBAGX,SACA,QACA,QACA,WAEA,OAAO,OACL,OAAO,YACL,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CAC7C,MACC,OAAY,YACX,OAAO,cAAc;CACnB,IAAI,CAAC,OAAO,GAAG,OAAO,OAAO,KAAK,YAAY,CAAC;CAG/C,OAAQ,OAFS,OAAO,IAAe,CAAC,KAG/B,GACP,OACF;AACF,CAAC,CAAC,CAAC,KACD,OAAO,QAAQ,SACb,OAAO,WAAW;CAChB,IAAI,KAAK,SAAS,WAAW,OAAO;AACtC,CAAC,CACH,GACA,OAAO,kBAAkB,OAAO,KAAK,YAAY,CAAC,CAAC,CACrD,CACJ,CAAC,CACH,CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Observation, Row, TransactionOwner } from "../transaction-kernel.mjs";
|
|
2
|
+
import "../transaction-execution-kernel.mjs";
|
|
3
|
+
import { Context } from "effect";
|
|
4
|
+
import { OAuthUnavailable } from "@yielded/auth/OAuth";
|
|
5
|
+
//#region src/internal/oauth/owner.d.ts
|
|
6
|
+
export type OAuthOwner = TransactionOwner<OAuthUnavailable>;
|
|
7
|
+
declare const CurrentOAuthTransaction_base: Context.ServiceClass<CurrentOAuthTransaction, "effect-auth/persistence/CurrentOAuthTransaction", OAuthOwner>;
|
|
8
|
+
export declare class CurrentOAuthTransaction extends CurrentOAuthTransaction_base {}
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=owner.d.mts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
2
|
+
//#region src/internal/oauth/owner.ts
|
|
3
|
+
var CurrentOAuthTransaction = class extends Context.Service()("effect-auth/persistence/CurrentOAuthTransaction") {};
|
|
4
|
+
/** Transaction execution is selected by the adapter; its methods retain the
|
|
5
|
+
* root-database and active-owner requirements in their Effects. */
|
|
6
|
+
var OAuthTransactionExecution = class extends Context.Service()("effect-auth/persistence/OAuthTransactionExecution") {};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { CurrentOAuthTransaction, OAuthTransactionExecution };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=owner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner.mjs","names":[],"sources":["../../../src/internal/oauth/owner.ts"],"sourcesContent":["import type { OAuthUnavailable } from \"@yielded/auth/OAuth\";\n/* oxlint-disable no-explicit-any -- private adapter preserves the existing driver boundary. */\nimport { Context } from \"effect\";\n\nimport type { makeTransactionExecutionKernel } from \"../transaction-execution-kernel\";\nimport type { TransactionNativeDatabase, TransactionOwner } from \"../transaction-kernel\";\nexport type { Observation, Row } from \"../transaction-kernel\";\n\nexport type OAuthOwner = TransactionOwner<OAuthUnavailable>;\n\nexport class CurrentOAuthTransaction extends Context.Service<CurrentOAuthTransaction, OAuthOwner>()(\n \"effect-auth/persistence/CurrentOAuthTransaction\",\n) {}\n\nexport type OAuthNativeDatabase = TransactionNativeDatabase;\n\n/** Transaction execution is selected by the adapter; its methods retain the\n * root-database and active-owner requirements in their Effects. */\nexport class OAuthTransactionExecution extends Context.Service<\n OAuthTransactionExecution,\n ReturnType<typeof makeTransactionExecutionKernel>\n>()(\"effect-auth/persistence/OAuthTransactionExecution\") {}\n"],"mappings":";;AAUA,IAAa,0BAAb,cAA6C,QAAQ,QAA6C,CAAC,CACjG,iDACF,CAAC,CAAC,CAAC;;;AAMH,IAAa,4BAAb,cAA+C,QAAQ,QAGrD,CAAC,CAAC,mDAAmD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
2
|
+
//#region src/internal/oauth/query-compiler.ts
|
|
3
|
+
/** Adapter-owned SQL expressions and mapped-row compilation. Runtime database
|
|
4
|
+
* and transaction authority remain NativeDatabase and CurrentOAuthTransaction. */
|
|
5
|
+
var OAuthQueryCompiler = class extends Context.Service()("effect-auth/persistence/OAuthQueryCompiler") {};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { OAuthQueryCompiler };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=query-compiler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-compiler.mjs","names":[],"sources":["../../../src/internal/oauth/query-compiler.ts"],"sourcesContent":["import { Context } from \"effect\";\n\nimport type { QueryOperations } from \"../query-operations\";\nimport type { makeTransactionKernel } from \"../transaction-kernel\";\nimport type { makeOAuthConnectedReferenceKernel } from \"./connected-reference\";\n\n/** Adapter-owned SQL expressions and mapped-row compilation. Runtime database\n * and transaction authority remain NativeDatabase and CurrentOAuthTransaction. */\nexport class OAuthQueryCompiler extends Context.Service<\n OAuthQueryCompiler,\n QueryOperations &\n ReturnType<ReturnType<typeof makeTransactionKernel>[\"makeTransactionRows\"]> &\n Pick<ReturnType<typeof makeTransactionKernel>, \"both\"> &\n Pick<ReturnType<typeof makeOAuthConnectedReferenceKernel>, \"connectedReferenceCondition\">\n>()(\"effect-auth/persistence/OAuthQueryCompiler\") {}\n"],"mappings":";;;;AAQA,IAAa,qBAAb,cAAwC,QAAQ,QAM9C,CAAC,CAAC,4CAA4C,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "../models/common.mjs";
|
|
2
|
+
import "../models/oauth-model.mjs";
|
|
3
|
+
import "./owner.mjs";
|
|
4
|
+
import "./query-compiler.mjs";
|
|
5
|
+
import "./flow.mjs";
|
|
6
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
7
|
+
import { OAuthExternalIdentity, OAuthRegistrationAccess, OAuthRegistrationIntent } from "@yielded/auth/OAuth";
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { CurrentOAuthTransaction } from "./owner.mjs";
|
|
2
|
+
import { OAuthQueryCompiler } from "./query-compiler.mjs";
|
|
3
|
+
import { invariant, oauthIdentityKey, sameIdentity, storage } from "./state.mjs";
|
|
4
|
+
import { OAuthFlow } from "./flow.mjs";
|
|
5
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
6
|
+
import { OAuthCredentialSnapshot, OAuthDisplayProfile, OAuthRegistrationAccess, OAuthRegistrationDecision, OAuthRegistrationFingerprint, OAuthRegistrationInspection, OAuthRegistrationIntent, OAuthSignInTransactionContext, snapshotOAuthSync } from "@yielded/auth/OAuth";
|
|
7
|
+
//#region src/internal/oauth/registration.ts
|
|
8
|
+
const make = Effect.gen(function* () {
|
|
9
|
+
const operations = yield* OAuthQueryCompiler;
|
|
10
|
+
const flow = yield* OAuthFlow;
|
|
11
|
+
const { eq, sql } = operations;
|
|
12
|
+
const { discoverOwned, exactClaim, resolveOwned, terminalFlow } = flow;
|
|
13
|
+
const { both, col, equal, matchesNativeRow } = operations;
|
|
14
|
+
const intentStorage = storage(OAuthRegistrationIntent);
|
|
15
|
+
const decisionStorage = storage(OAuthRegistrationDecision);
|
|
16
|
+
const contextStorage = storage(OAuthSignInTransactionContext);
|
|
17
|
+
const profileStorage = storage(Schema.NullOr(OAuthDisplayProfile));
|
|
18
|
+
const reservationStorage = storage(Schema.Struct({
|
|
19
|
+
moduleId: Schema.String,
|
|
20
|
+
reference: Schema.String,
|
|
21
|
+
commandId: Schema.String,
|
|
22
|
+
fingerprint: Schema.String,
|
|
23
|
+
provisioningIdentity: Schema.String
|
|
24
|
+
}));
|
|
25
|
+
const readTuple = (ownership, identity) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
26
|
+
const t = ownership.tuple, key = yield* oauthIdentityKey(identity);
|
|
27
|
+
const where = { [t.identityKey]: key };
|
|
28
|
+
const observed = yield* owner.read(t.table, equal(t.table, where), { limit: 1 });
|
|
29
|
+
if (observed.rows.length === 0) {
|
|
30
|
+
const values = {
|
|
31
|
+
...t.encodeInsert({
|
|
32
|
+
identityKey: key,
|
|
33
|
+
identity
|
|
34
|
+
}),
|
|
35
|
+
...where,
|
|
36
|
+
[t.provider]: identity.provider,
|
|
37
|
+
[t.issuer]: identity.issuer,
|
|
38
|
+
[t.externalSubject]: identity.subject,
|
|
39
|
+
[t.state]: "Unowned",
|
|
40
|
+
[t.version]: owner.marker,
|
|
41
|
+
[t.subjectId]: null,
|
|
42
|
+
[t.reservation]: null
|
|
43
|
+
};
|
|
44
|
+
observed.rows = (yield* owner.insert(t.table, values, where, true)).rows;
|
|
45
|
+
}
|
|
46
|
+
const row = observed.rows[0];
|
|
47
|
+
invariant(row[t.provider] === identity.provider && row[t.issuer] === identity.issuer && row[t.externalSubject] === identity.subject && [
|
|
48
|
+
"Unowned",
|
|
49
|
+
"Reserved",
|
|
50
|
+
"Owned"
|
|
51
|
+
].includes(row[t.state]));
|
|
52
|
+
invariant(row[t.state] === "Owned" ? row[t.subjectId] !== null : row[t.subjectId] === null && (row[t.state] === "Reserved" ? typeof row[t.reservation] === "string" : row[t.reservation] === null));
|
|
53
|
+
if (ownership.mode === "separate") {
|
|
54
|
+
const o = ownership.external;
|
|
55
|
+
const external = yield* owner.read(o.table, equal(o.table, { [o.identityKey]: key }), { limit: 1 });
|
|
56
|
+
if (row[t.state] === "Owned") {
|
|
57
|
+
const linked = external.rows[0];
|
|
58
|
+
invariant(linked !== void 0 && linked[o.provider] === identity.provider && linked[o.issuer] === identity.issuer && linked[o.externalSubject] === identity.subject && matchesNativeRow(o.table, linked, { [o.subjectId]: row[t.subjectId] }));
|
|
59
|
+
const owned = sql`exists(select 1 from ${o.table} where ${both(equal(o.table, { [o.identityKey]: key }), o.ownedCondition)})`;
|
|
60
|
+
invariant(yield* owner.check(owned));
|
|
61
|
+
owner.postconditions.push(owned);
|
|
62
|
+
} else invariant(external.rows.length === 0);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
observed,
|
|
66
|
+
row,
|
|
67
|
+
key
|
|
68
|
+
};
|
|
69
|
+
}));
|
|
70
|
+
const acquireTuple = (ownership, identity, key, subjectId) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
71
|
+
const t = ownership.tuple;
|
|
72
|
+
yield* owner.update(t.table, { [t.identityKey]: key }, {
|
|
73
|
+
[t.state]: "Owned",
|
|
74
|
+
[t.subjectId]: subjectId,
|
|
75
|
+
[t.reservation]: null,
|
|
76
|
+
[t.version]: owner.marker
|
|
77
|
+
});
|
|
78
|
+
if (ownership.mode === "separate") {
|
|
79
|
+
const o = ownership.external;
|
|
80
|
+
const values = {
|
|
81
|
+
...o.encodeInsert({
|
|
82
|
+
identity,
|
|
83
|
+
identityKey: key,
|
|
84
|
+
subjectId
|
|
85
|
+
}),
|
|
86
|
+
[o.identityKey]: key,
|
|
87
|
+
[o.provider]: identity.provider,
|
|
88
|
+
[o.issuer]: identity.issuer,
|
|
89
|
+
[o.externalSubject]: identity.subject,
|
|
90
|
+
[o.subjectId]: subjectId
|
|
91
|
+
};
|
|
92
|
+
yield* owner.insert(o.table, values, { [o.identityKey]: key });
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
const settleRegistrationIntent = (mapping, input) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
96
|
+
const identity = input.identity.identity, context = input.claim.flow.context;
|
|
97
|
+
invariant(identity.provider === context.provider && identity.issuer === context.issuer);
|
|
98
|
+
const found = yield* discoverOwned(mapping.signIn, identity);
|
|
99
|
+
const tuple = found.owned ? void 0 : yield* readTuple(mapping.ownership, identity);
|
|
100
|
+
const exact = yield* exactClaim(mapping.signIn, input.claim, "sign-in");
|
|
101
|
+
if (exact === void 0) return { _tag: "Rejected" };
|
|
102
|
+
const credential = resolveOwned(mapping.signIn, context.moduleId, identity, found);
|
|
103
|
+
if (credential !== void 0) {
|
|
104
|
+
yield* terminalFlow(mapping.signIn, input.claim.flow, "Verified");
|
|
105
|
+
return {
|
|
106
|
+
_tag: "Verified",
|
|
107
|
+
credential
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
let decision = { _tag: "Rejected" };
|
|
111
|
+
if (!found.owned && tuple?.row[mapping.ownership.tuple.state] === "Unowned" && input.intent !== void 0) {
|
|
112
|
+
const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent);
|
|
113
|
+
const c = intent.context;
|
|
114
|
+
invariant(sameIdentity(intent.identity, identity) && profileStorage.encode(intent.profile ?? null) === profileStorage.encode(input.identity.profile ?? null) && intent.claimId === input.claim.claimId && intent.claimedAtMillis === input.claim.claimedAtMillis && contextStorage.encode(c) === contextStorage.encode(context));
|
|
115
|
+
if (intent.issuedAtMillis >= intent.claimedAtMillis && intent.verifiedAtMillis <= intent.issuedAtMillis && intent.issuedAtMillis <= exact.now && exact.now < intent.expiresAtMillis && intent.expiresAtMillis <= c.requestBindingExpiresAtMillis && intent.retentionUntilMillis >= intent.expiresAtMillis && (yield* owner.check(mapping.eligibility.condition({ intent })))) {
|
|
116
|
+
const i = mapping.intent, encode = mapping.signIn.clock.encodeInstant;
|
|
117
|
+
const key = {
|
|
118
|
+
[i.moduleId]: c.moduleId,
|
|
119
|
+
[i.reference]: intent.reference
|
|
120
|
+
};
|
|
121
|
+
const values = {
|
|
122
|
+
...i.encodeInsert(snapshotOAuthSync(OAuthRegistrationIntent, intent)),
|
|
123
|
+
...key,
|
|
124
|
+
[i.flowId]: c.flowId,
|
|
125
|
+
[i.claimId]: intent.claimId,
|
|
126
|
+
[i.identityKey]: tuple.key,
|
|
127
|
+
[i.version]: owner.marker,
|
|
128
|
+
[i.state]: "Unbound",
|
|
129
|
+
[i.snapshot]: intentStorage.encode(intent),
|
|
130
|
+
[i.commandId]: null,
|
|
131
|
+
[i.fingerprint]: null,
|
|
132
|
+
[i.pendingReference]: null,
|
|
133
|
+
[i.expiresAt]: encode(intent.expiresAtMillis),
|
|
134
|
+
[i.retentionUntil]: encode(intent.retentionUntilMillis)
|
|
135
|
+
};
|
|
136
|
+
yield* owner.insert(i.table, values, key);
|
|
137
|
+
owner.postconditions.push(mapping.eligibility.condition({ intent }), sql`${mapping.signIn.clock.engineNowMillis} >= ${intent.issuedAtMillis} and
|
|
138
|
+
${mapping.signIn.clock.engineNowMillis} < ${intent.expiresAtMillis}`);
|
|
139
|
+
decision = {
|
|
140
|
+
_tag: "RegistrationIssued",
|
|
141
|
+
intent
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
yield* terminalFlow(mapping.signIn, input.claim.flow, decision._tag);
|
|
146
|
+
return decision;
|
|
147
|
+
}));
|
|
148
|
+
const inspectIntent = (mapping, original, discovery = false) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
149
|
+
const access = snapshotOAuthSync(OAuthRegistrationAccess, original), i = mapping.intent;
|
|
150
|
+
const observed = yield* owner.read(i.table, equal(i.table, {
|
|
151
|
+
[i.moduleId]: access.moduleId,
|
|
152
|
+
[i.reference]: access.reference
|
|
153
|
+
}), {
|
|
154
|
+
limit: 1,
|
|
155
|
+
...discovery ? {
|
|
156
|
+
lock: false,
|
|
157
|
+
observe: false
|
|
158
|
+
} : {}
|
|
159
|
+
});
|
|
160
|
+
const row = observed.rows[0];
|
|
161
|
+
if (row === void 0) return void 0;
|
|
162
|
+
const intent = intentStorage.decode(row[i.snapshot]), c = intent.context, now = yield* owner.now(mapping.clock);
|
|
163
|
+
invariant(row[i.moduleId] === c.moduleId && row[i.reference] === intent.reference && row[i.flowId] === c.flowId && row[i.claimId] === intent.claimId && row[i.identityKey] === (yield* oauthIdentityKey(intent.identity)) && mapping.clock.decodeInstant(row[i.expiresAt]) === intent.expiresAtMillis && mapping.clock.decodeInstant(row[i.retentionUntil]) === intent.retentionUntilMillis);
|
|
164
|
+
if (access.moduleId !== c.moduleId || access.reference !== intent.reference || access.flowId !== c.flowId || access.requestBindingVerifier !== c.requestBindingVerifier || access.requestBindingExpiresAtMillis !== c.requestBindingExpiresAtMillis || access.credentialDigest !== intent.credentialDigest || now < intent.issuedAtMillis || now >= intent.expiresAtMillis) return void 0;
|
|
165
|
+
let application;
|
|
166
|
+
if (row[i.state] === "Unbound") {
|
|
167
|
+
invariant(row[i.commandId] === null && row[i.fingerprint] === null && row[i.pendingReference] === null);
|
|
168
|
+
application = { _tag: "Unbound" };
|
|
169
|
+
} else application = {
|
|
170
|
+
_tag: row[i.state],
|
|
171
|
+
commandId: row[i.commandId],
|
|
172
|
+
fingerprint: row[i.fingerprint],
|
|
173
|
+
...row[i.state] === "ProvisioningPending" ? { reference: row[i.pendingReference] } : {}
|
|
174
|
+
};
|
|
175
|
+
const inspection = snapshotOAuthSync(OAuthRegistrationInspection, {
|
|
176
|
+
intent,
|
|
177
|
+
application
|
|
178
|
+
});
|
|
179
|
+
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${intent.issuedAtMillis} and
|
|
180
|
+
${mapping.clock.engineNowMillis} < ${intent.expiresAtMillis}`);
|
|
181
|
+
return {
|
|
182
|
+
observed,
|
|
183
|
+
row,
|
|
184
|
+
inspection
|
|
185
|
+
};
|
|
186
|
+
}));
|
|
187
|
+
const registrationResources = (mapping) => Effect.gen(function* () {
|
|
188
|
+
const provisioningIdentity = yield* mapping.allocateProvisioningIdentity;
|
|
189
|
+
invariant(typeof provisioningIdentity === "string" && provisioningIdentity.length > 0 && provisioningIdentity.length <= 256);
|
|
190
|
+
if (mapping.mode === "pending") {
|
|
191
|
+
const pendingReference = yield* mapping.allocatePendingReference;
|
|
192
|
+
invariant(typeof pendingReference === "string" && pendingReference.length > 0 && pendingReference.length <= 256);
|
|
193
|
+
return {
|
|
194
|
+
provisioningIdentity,
|
|
195
|
+
pendingReference
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const subjectId = yield* mapping.allocateSubjectId;
|
|
199
|
+
const publicId = yield* mapping.subjectId.toSubject(subjectId);
|
|
200
|
+
invariant(mapping.subjectId.equals(subjectId, yield* mapping.subjectId.toNative(publicId)));
|
|
201
|
+
return {
|
|
202
|
+
provisioningIdentity,
|
|
203
|
+
subjectId,
|
|
204
|
+
credentialId: snapshotOAuthSync(OAuthCredentialSnapshot.fields.credentialId, yield* mapping.allocateCredentialId),
|
|
205
|
+
revision: snapshotOAuthSync(OAuthCredentialSnapshot.fields.credentialRevision, yield* mapping.allocateRevision)
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
const registrationData = (mapping, input, bound) => Effect.gen(function* () {
|
|
209
|
+
const snapshot = bound ? (invariant(mapping.snapshotSync !== void 0), mapping.snapshotSync(input.registration)) : yield* mapping.snapshot(input.registration);
|
|
210
|
+
const encoded = mapping.application.encode(snapshot);
|
|
211
|
+
invariant(typeof encoded === "string" && new TextEncoder().encode(encoded).length <= 1048576);
|
|
212
|
+
const detached = mapping.application.decode(encoded);
|
|
213
|
+
invariant(mapping.application.encode(detached) === encoded);
|
|
214
|
+
const checked = bound ? (invariant(mapping.inspectSync !== void 0), mapping.inspectSync({
|
|
215
|
+
intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent),
|
|
216
|
+
registration: mapping.application.decode(encoded)
|
|
217
|
+
})) : yield* mapping.inspect({
|
|
218
|
+
intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent),
|
|
219
|
+
registration: mapping.application.decode(encoded)
|
|
220
|
+
});
|
|
221
|
+
const fingerprint = snapshotOAuthSync(OAuthRegistrationFingerprint, checked.fingerprint);
|
|
222
|
+
invariant(typeof checked.eligible === "boolean");
|
|
223
|
+
return {
|
|
224
|
+
encoded,
|
|
225
|
+
registration: detached,
|
|
226
|
+
fingerprint,
|
|
227
|
+
eligible: checked.eligible && fingerprint === input.fingerprint
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
const register = (mapping, input, data, resources) => Effect.flatMap(CurrentOAuthTransaction, (owner) => Effect.gen(function* () {
|
|
231
|
+
const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent), c = intent.context;
|
|
232
|
+
const discovered = yield* inspectIntent(mapping, input.access, true);
|
|
233
|
+
if (discovered === void 0 || intentStorage.encode(discovered.inspection.intent) !== intentStorage.encode(intent)) return { _tag: "Rejected" };
|
|
234
|
+
const nativeSubjectId = resources.subjectId;
|
|
235
|
+
const policyInput = () => ({
|
|
236
|
+
intent: snapshotOAuthSync(OAuthRegistrationIntent, intent),
|
|
237
|
+
registration: mapping.application.decode(data.encoded),
|
|
238
|
+
...mapping.mode === "atomic" ? { nativeSubjectId } : {}
|
|
239
|
+
});
|
|
240
|
+
invariant((mapping.eligibility.guards?.length ?? 0) <= 32);
|
|
241
|
+
for (const guard of mapping.eligibility.guards ?? []) {
|
|
242
|
+
const locked = yield* owner.read(guard.table, guard.condition(policyInput()), {
|
|
243
|
+
orderBy: col(guard.table, guard.orderBy),
|
|
244
|
+
admissionOnly: true
|
|
245
|
+
});
|
|
246
|
+
invariant(locked.rows.length > 0);
|
|
247
|
+
}
|
|
248
|
+
const tuple = yield* readTuple(mapping.ownership, intent.identity);
|
|
249
|
+
const inspected = yield* inspectIntent(mapping, input.access);
|
|
250
|
+
if (inspected === void 0 || intentStorage.encode(inspected.inspection.intent) !== intentStorage.encode(intent)) return { _tag: "Rejected" };
|
|
251
|
+
const r = mapping.command, i = mapping.intent, t = mapping.ownership.tuple;
|
|
252
|
+
const commandKey = {
|
|
253
|
+
[r.moduleId]: c.moduleId,
|
|
254
|
+
[r.commandId]: input.commandId
|
|
255
|
+
};
|
|
256
|
+
const command = yield* owner.read(r.table, equal(r.table, commandKey), { limit: 1 });
|
|
257
|
+
const previous = command.rows[0];
|
|
258
|
+
if (previous !== void 0) {
|
|
259
|
+
if (previous[r.reference] !== intent.reference || previous[r.identityKey] !== tuple.key || previous[r.fingerprint] !== data.fingerprint || previous[r.intentSnapshot] !== intentStorage.encode(intent) || previous[r.applicationSnapshot] !== data.encoded) return { _tag: "Conflict" };
|
|
260
|
+
invariant(mapping.application.encode(mapping.application.decode(previous[r.applicationSnapshot])) === data.encoded);
|
|
261
|
+
const old = decisionStorage.decode(previous[r.decision]);
|
|
262
|
+
invariant(inspected.inspection.application._tag === old._tag);
|
|
263
|
+
return old._tag === "Registered" || old._tag === "ProvisioningPending" ? {
|
|
264
|
+
...old,
|
|
265
|
+
replayed: true
|
|
266
|
+
} : old;
|
|
267
|
+
}
|
|
268
|
+
if (inspected.inspection.application._tag !== "Unbound" || tuple.row[t.state] !== "Unowned") return { _tag: "Conflict" };
|
|
269
|
+
if (data.fingerprint !== input.fingerprint) return { _tag: "Rejected" };
|
|
270
|
+
const admitted = data.eligible && (yield* owner.check(mapping.eligibility.admission(policyInput())));
|
|
271
|
+
let decision;
|
|
272
|
+
if (!admitted) decision = { _tag: "Rejected" };
|
|
273
|
+
else if (mapping.mode === "pending") {
|
|
274
|
+
invariant(resources.pendingReference !== void 0);
|
|
275
|
+
const reservation = reservationStorage.encode({
|
|
276
|
+
moduleId: c.moduleId,
|
|
277
|
+
reference: intent.reference,
|
|
278
|
+
commandId: input.commandId,
|
|
279
|
+
fingerprint: data.fingerprint,
|
|
280
|
+
provisioningIdentity: resources.provisioningIdentity
|
|
281
|
+
});
|
|
282
|
+
yield* owner.update(t.table, { [t.identityKey]: tuple.key }, {
|
|
283
|
+
[t.state]: "Reserved",
|
|
284
|
+
[t.version]: owner.marker,
|
|
285
|
+
[t.reservation]: reservation
|
|
286
|
+
});
|
|
287
|
+
decision = {
|
|
288
|
+
_tag: "ProvisioningPending",
|
|
289
|
+
reference: resources.pendingReference,
|
|
290
|
+
replayed: false
|
|
291
|
+
};
|
|
292
|
+
} else {
|
|
293
|
+
invariant(resources.credentialId !== void 0 && resources.revision !== void 0);
|
|
294
|
+
const s = mapping.subject, cr = mapping.credential, a = mapping.authority;
|
|
295
|
+
const subjectValues = {
|
|
296
|
+
...mapping.encodeSubjectInsert(policyInput(), {
|
|
297
|
+
subjectId: nativeSubjectId,
|
|
298
|
+
securityRevision: resources.revision
|
|
299
|
+
}),
|
|
300
|
+
[s.id]: nativeSubjectId,
|
|
301
|
+
[s.securityRevision]: resources.revision
|
|
302
|
+
};
|
|
303
|
+
yield* owner.insert(s.table, subjectValues, { [s.id]: nativeSubjectId });
|
|
304
|
+
const credentialValues = {
|
|
305
|
+
...cr.encodeInsert({
|
|
306
|
+
moduleId: c.moduleId,
|
|
307
|
+
subjectId: nativeSubjectId,
|
|
308
|
+
identityKey: tuple.key,
|
|
309
|
+
credentialId: resources.credentialId,
|
|
310
|
+
credentialRevision: resources.revision
|
|
311
|
+
}),
|
|
312
|
+
[cr.moduleId]: c.moduleId,
|
|
313
|
+
[cr.subjectId]: nativeSubjectId,
|
|
314
|
+
[cr.identityKey]: tuple.key,
|
|
315
|
+
[cr.credentialId]: resources.credentialId,
|
|
316
|
+
[cr.credentialRevision]: resources.revision
|
|
317
|
+
};
|
|
318
|
+
invariant(cr.isActiveStatus(credentialValues[cr.status]) && s.isActiveStatus(subjectValues[s.status]));
|
|
319
|
+
yield* owner.insert(cr.table, credentialValues, { [cr.credentialId]: resources.credentialId });
|
|
320
|
+
const authorityValues = {
|
|
321
|
+
...a.encodeInsert({
|
|
322
|
+
subjectId: nativeSubjectId,
|
|
323
|
+
credentialId: resources.credentialId,
|
|
324
|
+
revision: resources.revision
|
|
325
|
+
}),
|
|
326
|
+
[a.subjectId]: nativeSubjectId,
|
|
327
|
+
[a.credentialId]: resources.credentialId,
|
|
328
|
+
[a.revision]: resources.revision
|
|
329
|
+
};
|
|
330
|
+
invariant(a.isActiveStatus(authorityValues[a.status]));
|
|
331
|
+
yield* owner.insert(a.table, authorityValues, {
|
|
332
|
+
[a.subjectId]: nativeSubjectId,
|
|
333
|
+
[a.credentialId]: resources.credentialId
|
|
334
|
+
});
|
|
335
|
+
yield* acquireTuple(mapping.ownership, intent.identity, tuple.key, nativeSubjectId);
|
|
336
|
+
owner.postconditions.push(sql`exists(select 1 from ${s.table} where ${both(eq(col(s.table, s.id), nativeSubjectId), s.activeCondition)})`, sql`exists(select 1 from ${cr.table} where ${both(eq(col(cr.table, cr.credentialId), resources.credentialId), cr.activeCondition)})`, sql`exists(select 1 from ${a.table} where ${both(eq(col(a.table, a.credentialId), resources.credentialId), eq(col(a.table, a.subjectId), nativeSubjectId), a.activeCondition)})`);
|
|
337
|
+
decision = {
|
|
338
|
+
_tag: "Registered",
|
|
339
|
+
replayed: false
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
const now = yield* owner.now(mapping.clock);
|
|
343
|
+
invariant(Number.isSafeInteger(mapping.retentionMillis) && mapping.retentionMillis >= 12e4);
|
|
344
|
+
const values = {
|
|
345
|
+
...r.encodeInsert({
|
|
346
|
+
intent: snapshotOAuthSync(OAuthRegistrationIntent, intent),
|
|
347
|
+
commandId: input.commandId,
|
|
348
|
+
fingerprint: data.fingerprint,
|
|
349
|
+
registration: mapping.application.decode(data.encoded),
|
|
350
|
+
provisioningIdentity: resources.provisioningIdentity
|
|
351
|
+
}),
|
|
352
|
+
...commandKey,
|
|
353
|
+
[r.reference]: intent.reference,
|
|
354
|
+
[r.identityKey]: tuple.key,
|
|
355
|
+
[r.fingerprint]: data.fingerprint,
|
|
356
|
+
[r.intentSnapshot]: intentStorage.encode(intent),
|
|
357
|
+
[r.applicationSnapshot]: data.encoded,
|
|
358
|
+
[r.provisioningIdentity]: resources.provisioningIdentity,
|
|
359
|
+
[r.decision]: decisionStorage.encode(decision),
|
|
360
|
+
[r.retentionUntil]: mapping.clock.encodeInstant(Math.max(intent.retentionUntilMillis, now + mapping.retentionMillis))
|
|
361
|
+
};
|
|
362
|
+
command.rows = (yield* owner.insert(r.table, values, commandKey)).rows;
|
|
363
|
+
yield* owner.update(i.table, {
|
|
364
|
+
[i.moduleId]: c.moduleId,
|
|
365
|
+
[i.reference]: intent.reference
|
|
366
|
+
}, {
|
|
367
|
+
[i.state]: decision._tag,
|
|
368
|
+
[i.commandId]: input.commandId,
|
|
369
|
+
[i.fingerprint]: data.fingerprint,
|
|
370
|
+
[i.version]: owner.marker,
|
|
371
|
+
[i.pendingReference]: decision._tag === "ProvisioningPending" ? decision.reference : null
|
|
372
|
+
});
|
|
373
|
+
if (admitted) owner.postconditions.push(mapping.eligibility.postcondition(policyInput()));
|
|
374
|
+
return decision;
|
|
375
|
+
}));
|
|
376
|
+
return {
|
|
377
|
+
intentStorage,
|
|
378
|
+
readTuple,
|
|
379
|
+
acquireTuple,
|
|
380
|
+
settleRegistrationIntent,
|
|
381
|
+
inspectIntent,
|
|
382
|
+
registrationResources,
|
|
383
|
+
registrationData,
|
|
384
|
+
register
|
|
385
|
+
};
|
|
386
|
+
});
|
|
387
|
+
var OAuthRegistration = class OAuthRegistration extends Context.Service()("effect-auth/persistence/OAuthRegistration") {
|
|
388
|
+
static layer = Layer.effect(OAuthRegistration, make);
|
|
389
|
+
};
|
|
390
|
+
//#endregion
|
|
391
|
+
export { OAuthRegistration };
|
|
392
|
+
|
|
393
|
+
//# sourceMappingURL=registration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.mjs","names":[],"sources":["../../../src/internal/oauth/registration.ts"],"sourcesContent":["/* oxlint-disable no-explicit-any -- compiler table shapes are erased; domain codecs and error channels remain typed. */\nimport {\n OAuthRegistrationAccess,\n OAuthRegistrationDecision,\n OAuthRegistrationFingerprint,\n OAuthRegistrationInspection,\n OAuthRegistrationIntent,\n OAuthCredentialSnapshot,\n OAuthDisplayProfile,\n OAuthSignInTransactionContext,\n type OAuthExternalIdentity,\n snapshotOAuthSync,\n} from \"@yielded/auth/OAuth\";\nimport type { SecurityRevision } from \"@yielded/auth/Sessions\";\nimport { Effect, Schema, Context, Layer } from \"effect\";\n\nimport type { PersistenceMappingError, SubjectIdCodec } from \"../models/common\";\nimport type { OAuthRegistrationBase } from \"../models/oauth-model\";\nimport { OAuthFlow } from \"./flow\";\nimport { CurrentOAuthTransaction } from \"./owner\";\nimport { OAuthQueryCompiler } from \"./query-compiler\";\nimport { invariant, oauthIdentityKey, sameIdentity, storage } from \"./state\";\n\nexport interface RegistrationResources {\n readonly provisioningIdentity: string;\n readonly pendingReference?: string;\n readonly subjectId?: unknown;\n readonly credentialId?: string;\n readonly revision?: string;\n}\n\n/** Public mapping callbacks are closed Effects; erasing native row shapes must\n * not erase their error or requirements channels. */\nexport type RegistrationCallbacks<Registration> = Pick<\n OAuthRegistrationBase<Registration, any, any, any, any, unknown>,\n \"snapshot\" | \"snapshotSync\" | \"inspect\" | \"inspectSync\"\n>;\n\nconst make = Effect.gen(function* () {\n const operations = yield* OAuthQueryCompiler;\n const flow = yield* OAuthFlow;\n\n const { eq, sql } = operations;\n const { discoverOwned, exactClaim, resolveOwned, terminalFlow } = flow;\n const { both, col, equal, matchesNativeRow } = operations;\n\n const intentStorage = storage(OAuthRegistrationIntent);\n\n const decisionStorage = storage(OAuthRegistrationDecision);\n\n const contextStorage = storage(OAuthSignInTransactionContext);\n\n const profileStorage = storage(Schema.NullOr(OAuthDisplayProfile));\n\n const reservationStorage = storage(\n Schema.Struct({\n moduleId: Schema.String,\n reference: Schema.String,\n commandId: Schema.String,\n fingerprint: Schema.String,\n provisioningIdentity: Schema.String,\n }),\n );\n\n const readTuple = (ownership: any, identity: typeof OAuthExternalIdentity.Type) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.gen(function* () {\n const t = ownership.tuple,\n key = yield* oauthIdentityKey(identity);\n\n const where = { [t.identityKey]: key };\n const observed = yield* owner.read(t.table, equal(t.table, where), { limit: 1 });\n\n if (observed.rows.length === 0) {\n const values = {\n ...t.encodeInsert({ identityKey: key, identity }),\n ...where,\n [t.provider]: identity.provider,\n [t.issuer]: identity.issuer,\n [t.externalSubject]: identity.subject,\n [t.state]: \"Unowned\",\n [t.version]: owner.marker,\n [t.subjectId]: null,\n [t.reservation]: null,\n };\n\n const inserted = yield* owner.insert(t.table, values, where, true);\n\n observed.rows = inserted.rows;\n }\n const row = observed.rows[0]!;\n\n invariant(\n row[t.provider] === identity.provider &&\n row[t.issuer] === identity.issuer &&\n row[t.externalSubject] === identity.subject &&\n [\"Unowned\", \"Reserved\", \"Owned\"].includes(row[t.state]),\n );\n invariant(\n row[t.state] === \"Owned\"\n ? row[t.subjectId] !== null\n : row[t.subjectId] === null &&\n (row[t.state] === \"Reserved\"\n ? typeof row[t.reservation] === \"string\"\n : row[t.reservation] === null),\n );\n if (ownership.mode === \"separate\") {\n const o = ownership.external;\n\n const external = yield* owner.read(o.table, equal(o.table, { [o.identityKey]: key }), {\n limit: 1,\n });\n\n if (row[t.state] === \"Owned\") {\n const linked = external.rows[0];\n\n invariant(\n linked !== undefined &&\n linked[o.provider] === identity.provider &&\n linked[o.issuer] === identity.issuer &&\n linked[o.externalSubject] === identity.subject &&\n matchesNativeRow(o.table, linked, { [o.subjectId]: row[t.subjectId] }),\n );\n const owned = sql`exists(select 1 from ${o.table} where ${both(equal(o.table, { [o.identityKey]: key }), o.ownedCondition)})`;\n\n invariant(yield* owner.check(owned));\n owner.postconditions.push(owned);\n } else invariant(external.rows.length === 0);\n }\n\n return { observed, row, key };\n }),\n );\n\n const acquireTuple = (\n ownership: any,\n identity: typeof OAuthExternalIdentity.Type,\n key: string,\n subjectId: unknown,\n ) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.gen(function* () {\n const t = ownership.tuple;\n\n yield* owner.update(\n t.table,\n { [t.identityKey]: key },\n {\n [t.state]: \"Owned\",\n [t.subjectId]: subjectId,\n [t.reservation]: null,\n [t.version]: owner.marker,\n },\n );\n if (ownership.mode === \"separate\") {\n const o = ownership.external;\n\n const values = {\n ...o.encodeInsert({ identity, identityKey: key, subjectId }),\n [o.identityKey]: key,\n [o.provider]: identity.provider,\n [o.issuer]: identity.issuer,\n [o.externalSubject]: identity.subject,\n [o.subjectId]: subjectId,\n };\n\n yield* owner.insert(o.table, values, { [o.identityKey]: key });\n }\n }),\n );\n\n const settleRegistrationIntent = (mapping: any, input: any) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.gen(function* () {\n const identity = input.identity.identity,\n context = input.claim.flow.context;\n\n invariant(identity.provider === context.provider && identity.issuer === context.issuer);\n const found = yield* discoverOwned(mapping.signIn, identity);\n const tuple = found.owned ? undefined : yield* readTuple(mapping.ownership, identity);\n const exact = yield* exactClaim(mapping.signIn, input.claim, \"sign-in\");\n\n if (exact === undefined) return { _tag: \"Rejected\" } as const;\n const credential = resolveOwned(mapping.signIn, context.moduleId, identity, found);\n\n if (credential !== undefined) {\n yield* terminalFlow(mapping.signIn, input.claim.flow, \"Verified\");\n\n return { _tag: \"Verified\", credential } as const;\n }\n let decision: any = { _tag: \"Rejected\" };\n\n if (\n !found.owned &&\n tuple?.row[mapping.ownership.tuple.state] === \"Unowned\" &&\n input.intent !== undefined\n ) {\n const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent);\n const c = intent.context;\n\n invariant(\n sameIdentity(intent.identity, identity) &&\n profileStorage.encode(intent.profile ?? null) ===\n profileStorage.encode(input.identity.profile ?? null) &&\n intent.claimId === input.claim.claimId &&\n intent.claimedAtMillis === input.claim.claimedAtMillis &&\n contextStorage.encode(c) === contextStorage.encode(context),\n );\n\n const allowed =\n intent.issuedAtMillis >= intent.claimedAtMillis &&\n intent.verifiedAtMillis <= intent.issuedAtMillis &&\n intent.issuedAtMillis <= exact.now &&\n exact.now < intent.expiresAtMillis &&\n intent.expiresAtMillis <= c.requestBindingExpiresAtMillis &&\n intent.retentionUntilMillis >= intent.expiresAtMillis &&\n (yield* owner.check(mapping.eligibility.condition({ intent })));\n\n if (allowed) {\n const i = mapping.intent,\n encode = mapping.signIn.clock.encodeInstant;\n\n const key = { [i.moduleId]: c.moduleId, [i.reference]: intent.reference };\n\n const values = {\n ...i.encodeInsert(snapshotOAuthSync(OAuthRegistrationIntent, intent)),\n ...key,\n [i.flowId]: c.flowId,\n [i.claimId]: intent.claimId,\n [i.identityKey]: tuple.key,\n [i.version]: owner.marker,\n [i.state]: \"Unbound\",\n [i.snapshot]: intentStorage.encode(intent),\n [i.commandId]: null,\n [i.fingerprint]: null,\n [i.pendingReference]: null,\n [i.expiresAt]: encode(intent.expiresAtMillis),\n [i.retentionUntil]: encode(intent.retentionUntilMillis),\n };\n\n yield* owner.insert(i.table, values, key);\n owner.postconditions.push(\n mapping.eligibility.condition({ intent }),\n sql`${mapping.signIn.clock.engineNowMillis} >= ${intent.issuedAtMillis} and\n ${mapping.signIn.clock.engineNowMillis} < ${intent.expiresAtMillis}`,\n );\n decision = { _tag: \"RegistrationIssued\", intent };\n }\n }\n yield* terminalFlow(mapping.signIn, input.claim.flow, decision._tag);\n\n return decision;\n }),\n );\n\n const inspectIntent = (\n mapping: any,\n original: typeof OAuthRegistrationAccess.Type,\n discovery = false,\n ) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.gen(function* () {\n const access = snapshotOAuthSync(OAuthRegistrationAccess, original),\n i = mapping.intent;\n\n const observed = yield* owner.read(\n i.table,\n equal(i.table, {\n [i.moduleId]: access.moduleId,\n [i.reference]: access.reference,\n }),\n { limit: 1, ...(discovery ? { lock: false, observe: false } : {}) },\n );\n\n const row = observed.rows[0];\n\n if (row === undefined) return undefined;\n\n const intent = intentStorage.decode(row[i.snapshot]),\n c = intent.context,\n now = yield* owner.now(mapping.clock);\n\n invariant(\n row[i.moduleId] === c.moduleId &&\n row[i.reference] === intent.reference &&\n row[i.flowId] === c.flowId &&\n row[i.claimId] === intent.claimId &&\n row[i.identityKey] === (yield* oauthIdentityKey(intent.identity)) &&\n mapping.clock.decodeInstant(row[i.expiresAt]) === intent.expiresAtMillis &&\n mapping.clock.decodeInstant(row[i.retentionUntil]) === intent.retentionUntilMillis,\n );\n if (\n access.moduleId !== c.moduleId ||\n access.reference !== intent.reference ||\n access.flowId !== c.flowId ||\n access.requestBindingVerifier !== c.requestBindingVerifier ||\n access.requestBindingExpiresAtMillis !== c.requestBindingExpiresAtMillis ||\n access.credentialDigest !== intent.credentialDigest ||\n now < intent.issuedAtMillis ||\n now >= intent.expiresAtMillis\n )\n return undefined;\n let application: any;\n\n if (row[i.state] === \"Unbound\") {\n invariant(\n row[i.commandId] === null &&\n row[i.fingerprint] === null &&\n row[i.pendingReference] === null,\n );\n application = { _tag: \"Unbound\" };\n } else {\n application = {\n _tag: row[i.state],\n commandId: row[i.commandId],\n fingerprint: row[i.fingerprint],\n ...(row[i.state] === \"ProvisioningPending\"\n ? { reference: row[i.pendingReference] }\n : {}),\n };\n }\n const inspection = snapshotOAuthSync(OAuthRegistrationInspection, { intent, application });\n\n owner.postconditions\n .push(sql`${mapping.clock.engineNowMillis} >= ${intent.issuedAtMillis} and\n ${mapping.clock.engineNowMillis} < ${intent.expiresAtMillis}`);\n\n return { observed, row, inspection };\n }),\n );\n\n const registrationResources = (mapping: any) =>\n Effect.gen(function* () {\n const provisioningIdentity = yield* mapping.allocateProvisioningIdentity as Effect.Effect<\n string,\n PersistenceMappingError\n >;\n\n invariant(\n typeof provisioningIdentity === \"string\" &&\n provisioningIdentity.length > 0 &&\n provisioningIdentity.length <= 256,\n );\n if (mapping.mode === \"pending\") {\n const pendingReference = yield* mapping.allocatePendingReference as Effect.Effect<\n string,\n PersistenceMappingError\n >;\n\n invariant(\n typeof pendingReference === \"string\" &&\n pendingReference.length > 0 &&\n pendingReference.length <= 256,\n );\n\n return { provisioningIdentity, pendingReference } as RegistrationResources;\n }\n\n const subjectId = yield* mapping.allocateSubjectId as Effect.Effect<\n unknown,\n PersistenceMappingError\n >;\n\n const publicId = yield* (mapping.subjectId as SubjectIdCodec<unknown>).toSubject(subjectId);\n\n invariant(\n mapping.subjectId.equals(\n subjectId,\n yield* (mapping.subjectId as SubjectIdCodec<unknown>).toNative(publicId),\n ),\n );\n\n const credentialId = snapshotOAuthSync(\n OAuthCredentialSnapshot.fields.credentialId,\n yield* mapping.allocateCredentialId as Effect.Effect<string, PersistenceMappingError>,\n );\n\n const revision = snapshotOAuthSync(\n OAuthCredentialSnapshot.fields.credentialRevision,\n yield* mapping.allocateRevision as Effect.Effect<SecurityRevision, PersistenceMappingError>,\n );\n\n return { provisioningIdentity, subjectId, credentialId, revision } as RegistrationResources;\n });\n\n const registrationData = <Registration>(\n mapping: any,\n input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n readonly fingerprint: string;\n },\n bound: boolean,\n ) =>\n Effect.gen(function* () {\n const snapshot = bound\n ? (invariant(mapping.snapshotSync !== undefined), mapping.snapshotSync(input.registration))\n : yield* (mapping as RegistrationCallbacks<Registration>).snapshot(input.registration);\n\n const encoded = mapping.application.encode(snapshot);\n\n invariant(typeof encoded === \"string\" && new TextEncoder().encode(encoded).length <= 1048576);\n const detached = mapping.application.decode(encoded);\n\n invariant(mapping.application.encode(detached) === encoded);\n\n const checked = bound\n ? (invariant(mapping.inspectSync !== undefined),\n mapping.inspectSync({\n intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent),\n registration: mapping.application.decode(encoded),\n }))\n : yield* (mapping as RegistrationCallbacks<Registration>).inspect({\n intent: snapshotOAuthSync(OAuthRegistrationIntent, input.intent),\n registration: mapping.application.decode(encoded),\n });\n\n const fingerprint = snapshotOAuthSync(OAuthRegistrationFingerprint, checked.fingerprint);\n\n invariant(typeof checked.eligible === \"boolean\");\n\n return {\n encoded,\n registration: detached as Registration,\n fingerprint,\n eligible: checked.eligible && fingerprint === input.fingerprint,\n };\n });\n\n const register = (\n mapping: any,\n input: any,\n data: { readonly encoded: string; readonly fingerprint: string; readonly eligible: boolean },\n resources: RegistrationResources,\n ) =>\n Effect.flatMap(CurrentOAuthTransaction, (owner) =>\n Effect.gen(function* () {\n const intent = snapshotOAuthSync(OAuthRegistrationIntent, input.intent),\n c = intent.context;\n\n const discovered = yield* inspectIntent(mapping, input.access, true);\n\n if (\n discovered === undefined ||\n intentStorage.encode(discovered.inspection.intent) !== intentStorage.encode(intent)\n )\n return { _tag: \"Rejected\" } as const;\n const nativeSubjectId = resources.subjectId;\n\n const policyInput = () => ({\n intent: snapshotOAuthSync(OAuthRegistrationIntent, intent),\n registration: mapping.application.decode(data.encoded),\n ...(mapping.mode === \"atomic\" ? { nativeSubjectId } : {}),\n });\n\n invariant((mapping.eligibility.guards?.length ?? 0) <= 32);\n for (const guard of mapping.eligibility.guards ?? []) {\n const locked = yield* owner.read(guard.table, guard.condition(policyInput()), {\n orderBy: col(guard.table, guard.orderBy),\n admissionOnly: true,\n });\n\n invariant(locked.rows.length > 0);\n }\n const tuple = yield* readTuple(mapping.ownership, intent.identity);\n const inspected = yield* inspectIntent(mapping, input.access);\n\n if (\n inspected === undefined ||\n intentStorage.encode(inspected.inspection.intent) !== intentStorage.encode(intent)\n )\n return { _tag: \"Rejected\" } as const;\n\n const r = mapping.command,\n i = mapping.intent,\n t = mapping.ownership.tuple;\n\n const commandKey = { [r.moduleId]: c.moduleId, [r.commandId]: input.commandId };\n const command = yield* owner.read(r.table, equal(r.table, commandKey), { limit: 1 });\n const previous = command.rows[0];\n\n if (previous !== undefined) {\n if (\n previous[r.reference] !== intent.reference ||\n previous[r.identityKey] !== tuple.key ||\n previous[r.fingerprint] !== data.fingerprint ||\n previous[r.intentSnapshot] !== intentStorage.encode(intent) ||\n previous[r.applicationSnapshot] !== data.encoded\n )\n return { _tag: \"Conflict\" } as const;\n invariant(\n mapping.application.encode(\n mapping.application.decode(previous[r.applicationSnapshot]),\n ) === data.encoded,\n );\n const old = decisionStorage.decode(previous[r.decision]);\n\n invariant(inspected.inspection.application._tag === old._tag);\n\n return old._tag === \"Registered\" || old._tag === \"ProvisioningPending\"\n ? { ...old, replayed: true }\n : old;\n }\n if (inspected.inspection.application._tag !== \"Unbound\" || tuple.row[t.state] !== \"Unowned\")\n return { _tag: \"Conflict\" } as const;\n if (data.fingerprint !== input.fingerprint) return { _tag: \"Rejected\" } as const;\n\n const admitted =\n data.eligible && (yield* owner.check(mapping.eligibility.admission(policyInput())));\n\n let decision: typeof OAuthRegistrationDecision.Type;\n\n if (!admitted) decision = { _tag: \"Rejected\" };\n else if (mapping.mode === \"pending\") {\n invariant(resources.pendingReference !== undefined);\n\n const reservation = reservationStorage.encode({\n moduleId: c.moduleId,\n reference: intent.reference,\n commandId: input.commandId,\n fingerprint: data.fingerprint,\n provisioningIdentity: resources.provisioningIdentity,\n });\n\n yield* owner.update(\n t.table,\n { [t.identityKey]: tuple.key },\n {\n [t.state]: \"Reserved\",\n [t.version]: owner.marker,\n [t.reservation]: reservation,\n },\n );\n decision = {\n _tag: \"ProvisioningPending\",\n reference: resources.pendingReference,\n replayed: false,\n };\n } else {\n invariant(resources.credentialId !== undefined && resources.revision !== undefined);\n\n const s = mapping.subject,\n cr = mapping.credential,\n a = mapping.authority;\n\n const subjectValues = {\n ...mapping.encodeSubjectInsert(policyInput(), {\n subjectId: nativeSubjectId,\n securityRevision: resources.revision,\n }),\n [s.id]: nativeSubjectId,\n [s.securityRevision]: resources.revision,\n };\n\n yield* owner.insert(s.table, subjectValues, { [s.id]: nativeSubjectId });\n\n const credentialValues = {\n ...cr.encodeInsert({\n moduleId: c.moduleId,\n subjectId: nativeSubjectId,\n identityKey: tuple.key,\n credentialId: resources.credentialId,\n credentialRevision: resources.revision,\n }),\n [cr.moduleId]: c.moduleId,\n [cr.subjectId]: nativeSubjectId,\n [cr.identityKey]: tuple.key,\n [cr.credentialId]: resources.credentialId,\n [cr.credentialRevision]: resources.revision,\n };\n\n invariant(\n cr.isActiveStatus(credentialValues[cr.status]) &&\n s.isActiveStatus(subjectValues[s.status]),\n );\n yield* owner.insert(cr.table, credentialValues, {\n [cr.credentialId]: resources.credentialId,\n });\n\n const authorityValues = {\n ...a.encodeInsert({\n subjectId: nativeSubjectId,\n credentialId: resources.credentialId,\n revision: resources.revision,\n }),\n [a.subjectId]: nativeSubjectId,\n [a.credentialId]: resources.credentialId,\n [a.revision]: resources.revision,\n };\n\n invariant(a.isActiveStatus(authorityValues[a.status]));\n yield* owner.insert(a.table, authorityValues, {\n [a.subjectId]: nativeSubjectId,\n [a.credentialId]: resources.credentialId,\n });\n yield* acquireTuple(mapping.ownership, intent.identity, tuple.key, nativeSubjectId);\n owner.postconditions.push(\n sql`exists(select 1 from ${s.table} where ${both(\n eq(col(s.table, s.id), nativeSubjectId),\n s.activeCondition,\n )})`,\n sql`exists(select 1 from ${cr.table} where ${both(eq(col(cr.table, cr.credentialId), resources.credentialId), cr.activeCondition)})`,\n sql`exists(select 1 from ${a.table} where ${both(\n eq(col(a.table, a.credentialId), resources.credentialId),\n eq(col(a.table, a.subjectId), nativeSubjectId),\n a.activeCondition,\n )})`,\n );\n decision = { _tag: \"Registered\", replayed: false };\n }\n const now = yield* owner.now(mapping.clock);\n\n invariant(\n Number.isSafeInteger(mapping.retentionMillis) && mapping.retentionMillis >= 120000,\n );\n\n const values = {\n ...r.encodeInsert({\n intent: snapshotOAuthSync(OAuthRegistrationIntent, intent),\n commandId: input.commandId,\n fingerprint: data.fingerprint,\n registration: mapping.application.decode(data.encoded),\n provisioningIdentity: resources.provisioningIdentity,\n }),\n ...commandKey,\n [r.reference]: intent.reference,\n [r.identityKey]: tuple.key,\n [r.fingerprint]: data.fingerprint,\n [r.intentSnapshot]: intentStorage.encode(intent),\n [r.applicationSnapshot]: data.encoded,\n [r.provisioningIdentity]: resources.provisioningIdentity,\n [r.decision]: decisionStorage.encode(decision),\n [r.retentionUntil]: mapping.clock.encodeInstant(\n Math.max(intent.retentionUntilMillis, now + mapping.retentionMillis),\n ),\n };\n\n const inserted = yield* owner.insert(r.table, values, commandKey);\n\n command.rows = inserted.rows;\n yield* owner.update(\n i.table,\n { [i.moduleId]: c.moduleId, [i.reference]: intent.reference },\n {\n [i.state]: decision._tag,\n [i.commandId]: input.commandId,\n [i.fingerprint]: data.fingerprint,\n [i.version]: owner.marker,\n [i.pendingReference]:\n decision._tag === \"ProvisioningPending\" ? decision.reference : null,\n },\n );\n if (admitted) owner.postconditions.push(mapping.eligibility.postcondition(policyInput()));\n\n return decision;\n }),\n );\n\n return {\n intentStorage,\n readTuple,\n acquireTuple,\n settleRegistrationIntent,\n inspectIntent,\n registrationResources,\n registrationData,\n register,\n };\n});\n\nexport class OAuthRegistration extends Context.Service<\n OAuthRegistration,\n Effect.Success<typeof make>\n>()(\"effect-auth/persistence/OAuthRegistration\") {\n static readonly layer = Layer.effect(OAuthRegistration, make);\n}\n"],"mappings":";;;;;;;AAsCA,MAAM,OAAO,OAAO,IAAI,aAAa;CACnC,MAAM,aAAa,OAAO;CAC1B,MAAM,OAAO,OAAO;CAEpB,MAAM,EAAE,IAAI,QAAQ;CACpB,MAAM,EAAE,eAAe,YAAY,cAAc,iBAAiB;CAClE,MAAM,EAAE,MAAM,KAAK,OAAO,qBAAqB;CAE/C,MAAM,gBAAgB,QAAQ,uBAAuB;CAErD,MAAM,kBAAkB,QAAQ,yBAAyB;CAEzD,MAAM,iBAAiB,QAAQ,6BAA6B;CAE5D,MAAM,iBAAiB,QAAQ,OAAO,OAAO,mBAAmB,CAAC;CAEjE,MAAM,qBAAqB,QACzB,OAAO,OAAO;EACZ,UAAU,OAAO;EACjB,WAAW,OAAO;EAClB,WAAW,OAAO;EAClB,aAAa,OAAO;EACpB,sBAAsB,OAAO;CAC/B,CAAC,CACH;CAEA,MAAM,aAAa,WAAgB,aACjC,OAAO,QAAQ,0BAA0B,UACvC,OAAO,IAAI,aAAa;EACtB,MAAM,IAAI,UAAU,OAClB,MAAM,OAAO,iBAAiB,QAAQ;EAExC,MAAM,QAAQ,GAAG,EAAE,cAAc,IAAI;EACrC,MAAM,WAAW,OAAO,MAAM,KAAK,EAAE,OAAO,MAAM,EAAE,OAAO,KAAK,GAAG,EAAE,OAAO,EAAE,CAAC;EAE/E,IAAI,SAAS,KAAK,WAAW,GAAG;GAC9B,MAAM,SA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