@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.
Files changed (175) hide show
  1. package/README.md +11 -0
  2. package/dist/Adapter.d.mts +12 -6
  3. package/dist/Adapter.mjs +8 -3
  4. package/dist/OAuthPersistence.d.mts +87 -0
  5. package/dist/OAuthPersistence.mjs +125 -0
  6. package/dist/OAuthPersistence.mjs.map +1 -0
  7. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  8. package/dist/index.d.mts +3 -1
  9. package/dist/index.mjs +3 -1
  10. package/dist/internal/configuration.d.mts +1 -1
  11. package/dist/internal/configuration.mjs.map +1 -1
  12. package/dist/internal/models/oauth-connected-model.d.mts +294 -0
  13. package/dist/internal/models/oauth-connected-model.mjs +22 -0
  14. package/dist/internal/models/oauth-connected-model.mjs.map +1 -0
  15. package/dist/internal/models/oauth-model.d.mts +467 -0
  16. package/dist/internal/models/oauth-model.mjs +49 -0
  17. package/dist/internal/models/oauth-model.mjs.map +1 -0
  18. package/dist/internal/models/password-model.d.mts +4 -47
  19. package/dist/internal/models/password-model.mjs +0 -1
  20. package/dist/internal/models/password-model.mjs.map +1 -1
  21. package/dist/internal/native-sql-table.d.mts +4 -0
  22. package/dist/internal/native-sql-table.mjs +7 -0
  23. package/dist/internal/native-sql-table.mjs.map +1 -1
  24. package/dist/internal/oauth/accounts.d.mts +8 -0
  25. package/dist/internal/oauth/accounts.mjs +379 -0
  26. package/dist/internal/oauth/accounts.mjs.map +1 -0
  27. package/dist/internal/oauth/connected-access.d.mts +9 -0
  28. package/dist/internal/oauth/connected-access.mjs +229 -0
  29. package/dist/internal/oauth/connected-access.mjs.map +1 -0
  30. package/dist/internal/oauth/connected-collection.d.mts +7 -0
  31. package/dist/internal/oauth/connected-collection.mjs +214 -0
  32. package/dist/internal/oauth/connected-collection.mjs.map +1 -0
  33. package/dist/internal/oauth/connected-custody.d.mts +6 -0
  34. package/dist/internal/oauth/connected-custody.mjs +165 -0
  35. package/dist/internal/oauth/connected-custody.mjs.map +1 -0
  36. package/dist/internal/oauth/connected-flow.d.mts +7 -0
  37. package/dist/internal/oauth/connected-flow.mjs +324 -0
  38. package/dist/internal/oauth/connected-flow.mjs.map +1 -0
  39. package/dist/internal/oauth/connected-input.mjs +122 -0
  40. package/dist/internal/oauth/connected-input.mjs.map +1 -0
  41. package/dist/internal/oauth/connected-keys.d.mts +2 -0
  42. package/dist/internal/oauth/connected-keys.mjs +22 -0
  43. package/dist/internal/oauth/connected-keys.mjs.map +1 -0
  44. package/dist/internal/oauth/connected-maintenance.d.mts +9 -0
  45. package/dist/internal/oauth/connected-maintenance.mjs +226 -0
  46. package/dist/internal/oauth/connected-maintenance.mjs.map +1 -0
  47. package/dist/internal/oauth/connected-management.d.mts +9 -0
  48. package/dist/internal/oauth/connected-management.mjs +243 -0
  49. package/dist/internal/oauth/connected-management.mjs.map +1 -0
  50. package/dist/internal/oauth/connected-reference.mjs +63 -0
  51. package/dist/internal/oauth/connected-reference.mjs.map +1 -0
  52. package/dist/internal/oauth/connected-settlement.d.mts +8 -0
  53. package/dist/internal/oauth/connected-settlement.mjs +141 -0
  54. package/dist/internal/oauth/connected-settlement.mjs.map +1 -0
  55. package/dist/internal/oauth/connected-sign-in.d.mts +10 -0
  56. package/dist/internal/oauth/connected-sign-in.mjs +281 -0
  57. package/dist/internal/oauth/connected-sign-in.mjs.map +1 -0
  58. package/dist/internal/oauth/connected-state.d.mts +14 -0
  59. package/dist/internal/oauth/connected-state.mjs +469 -0
  60. package/dist/internal/oauth/connected-state.mjs.map +1 -0
  61. package/dist/internal/oauth/connected-target.d.mts +21 -0
  62. package/dist/internal/oauth/connected-target.mjs +117 -0
  63. package/dist/internal/oauth/connected-target.mjs.map +1 -0
  64. package/dist/internal/oauth/flow.d.mts +5 -0
  65. package/dist/internal/oauth/flow.mjs +279 -0
  66. package/dist/internal/oauth/flow.mjs.map +1 -0
  67. package/dist/internal/oauth/input.mjs +127 -0
  68. package/dist/internal/oauth/input.mjs.map +1 -0
  69. package/dist/internal/oauth/owner.d.mts +10 -0
  70. package/dist/internal/oauth/owner.mjs +10 -0
  71. package/dist/internal/oauth/owner.mjs.map +1 -0
  72. package/dist/internal/oauth/query-compiler.d.mts +7 -0
  73. package/dist/internal/oauth/query-compiler.mjs +9 -0
  74. package/dist/internal/oauth/query-compiler.mjs.map +1 -0
  75. package/dist/internal/oauth/registration.d.mts +7 -0
  76. package/dist/internal/oauth/registration.mjs +393 -0
  77. package/dist/internal/oauth/registration.mjs.map +1 -0
  78. package/dist/internal/oauth/state.mjs +107 -0
  79. package/dist/internal/oauth/state.mjs.map +1 -0
  80. package/dist/internal/oauth/target.d.mts +31 -0
  81. package/dist/internal/oauth/target.mjs +273 -0
  82. package/dist/internal/oauth/target.mjs.map +1 -0
  83. package/dist/internal/oauth-kernel.d.mts +1423 -0
  84. package/dist/internal/oauth-kernel.mjs +187 -0
  85. package/dist/internal/oauth-kernel.mjs.map +1 -0
  86. package/dist/internal/oauth-proxy.d.mts +31 -0
  87. package/dist/internal/oauth-proxy.mjs +129 -0
  88. package/dist/internal/oauth-proxy.mjs.map +1 -0
  89. package/dist/internal/passkey-kernel.d.mts +5 -5
  90. package/dist/internal/{password-attempts.d.mts → password-credentials.d.mts} +3 -4
  91. package/dist/internal/password-credentials.mjs +121 -0
  92. package/dist/internal/password-credentials.mjs.map +1 -0
  93. package/dist/internal/password-kernel.d.mts +8 -24
  94. package/dist/internal/password-kernel.mjs +4 -42
  95. package/dist/internal/password-kernel.mjs.map +1 -1
  96. package/dist/internal/persistence.d.mts +1 -1
  97. package/dist/internal/persistence.mjs +2 -2
  98. package/dist/internal/persistence.mjs.map +1 -1
  99. package/dist/internal/query-operations.d.mts +2 -0
  100. package/dist/internal/session-kernel.d.mts +2 -2
  101. package/dist/internal/session-kernel.mjs +74 -18
  102. package/dist/internal/session-kernel.mjs.map +1 -1
  103. package/dist/internal/sql-oauth-connected-model.d.mts +29 -0
  104. package/dist/internal/sql-oauth-connected-model.mjs +7 -0
  105. package/dist/internal/sql-oauth-connected-model.mjs.map +1 -0
  106. package/dist/internal/sql-oauth-model.d.mts +60 -0
  107. package/dist/internal/sql-oauth-model.mjs +10 -0
  108. package/dist/internal/sql-oauth-model.mjs.map +1 -0
  109. package/dist/internal/sql-query.d.mts +12 -0
  110. package/dist/internal/sql-query.mjs +15 -18
  111. package/dist/internal/sql-query.mjs.map +1 -1
  112. package/dist/internal/sql-storage-validation.mjs +54 -0
  113. package/dist/internal/sql-storage-validation.mjs.map +1 -0
  114. package/dist/internal/storage-mapping.mjs +1 -37
  115. package/dist/internal/storage-mapping.mjs.map +1 -1
  116. package/dist/internal/storage-plans.d.mts +7 -0
  117. package/dist/internal/storage-plans.mjs +189 -0
  118. package/dist/internal/storage-plans.mjs.map +1 -0
  119. package/dist/internal/storage-tables.d.mts +0 -56
  120. package/dist/internal/storage-tables.mjs +0 -17
  121. package/dist/internal/storage-tables.mjs.map +1 -1
  122. package/dist/internal/storage-validation.d.mts +6 -1
  123. package/dist/internal/storage-validation.mjs +42 -1
  124. package/dist/internal/storage-validation.mjs.map +1 -1
  125. package/dist/internal/transaction-kernel.mjs +3 -2
  126. package/dist/internal/transaction-kernel.mjs.map +1 -1
  127. package/package.json +1 -1
  128. package/src/Adapter.ts +89 -5
  129. package/src/OAuthPersistence.ts +427 -0
  130. package/src/index.ts +3 -0
  131. package/src/internal/configuration.ts +1 -3
  132. package/src/internal/models/oauth-connected-model.ts +396 -0
  133. package/src/internal/models/oauth-model.ts +708 -0
  134. package/src/internal/models/password-model.ts +0 -56
  135. package/src/internal/native-sql-table.ts +14 -0
  136. package/src/internal/oauth/accounts.ts +838 -0
  137. package/src/internal/oauth/connected-access.ts +388 -0
  138. package/src/internal/oauth/connected-collection.ts +345 -0
  139. package/src/internal/oauth/connected-custody.ts +308 -0
  140. package/src/internal/oauth/connected-flow.ts +562 -0
  141. package/src/internal/oauth/connected-input.ts +147 -0
  142. package/src/internal/oauth/connected-keys.ts +31 -0
  143. package/src/internal/oauth/connected-maintenance.ts +379 -0
  144. package/src/internal/oauth/connected-management.ts +391 -0
  145. package/src/internal/oauth/connected-reference.ts +135 -0
  146. package/src/internal/oauth/connected-settlement.ts +278 -0
  147. package/src/internal/oauth/connected-sign-in.ts +472 -0
  148. package/src/internal/oauth/connected-state.ts +924 -0
  149. package/src/internal/oauth/connected-target.ts +307 -0
  150. package/src/internal/oauth/flow.ts +505 -0
  151. package/src/internal/oauth/input.ts +201 -0
  152. package/src/internal/oauth/owner.ts +22 -0
  153. package/src/internal/oauth/query-compiler.ts +15 -0
  154. package/src/internal/oauth/registration.ts +676 -0
  155. package/src/internal/oauth/state.ts +218 -0
  156. package/src/internal/oauth/target.ts +803 -0
  157. package/src/internal/oauth-kernel.ts +294 -0
  158. package/src/internal/oauth-proxy.ts +176 -0
  159. package/src/internal/password-credentials.ts +245 -0
  160. package/src/internal/password-kernel.ts +5 -98
  161. package/src/internal/persistence.ts +1 -1
  162. package/src/internal/query-operations.ts +2 -0
  163. package/src/internal/session-kernel.ts +143 -55
  164. package/src/internal/sql-oauth-connected-model.ts +145 -0
  165. package/src/internal/sql-oauth-model.ts +263 -0
  166. package/src/internal/sql-query.ts +16 -13
  167. package/src/internal/sql-storage-validation.ts +64 -0
  168. package/src/internal/storage-mapping.ts +0 -37
  169. package/src/internal/storage-plans.ts +218 -0
  170. package/src/internal/storage-tables.ts +0 -20
  171. package/src/internal/storage-validation.ts +58 -0
  172. package/src/internal/transaction-kernel.ts +6 -2
  173. package/dist/internal/password-attempts.mjs +0 -197
  174. package/dist/internal/password-attempts.mjs.map +0 -1
  175. package/src/internal/password-attempts.ts +0 -466
@@ -0,0 +1,469 @@
1
+ import { digest } from "../crypto.mjs";
2
+ import { CurrentOAuthTransaction } from "./owner.mjs";
3
+ import { OAuthQueryCompiler } from "./query-compiler.mjs";
4
+ import { invariant, oauthIdentityKey, sameRevision, satisfies, storage, unavailable } from "./state.mjs";
5
+ import { OAuthFlow } from "./flow.mjs";
6
+ import { clientKey, cohortKey, key, scopeKey, strings } from "./connected-keys.mjs";
7
+ import { Context, DateTime, Effect, Layer, Schema } from "effect";
8
+ import { AuthenticationRequirement } from "@yielded/auth/Sessions";
9
+ import * as M from "@yielded/auth/OAuth";
10
+ import { snapshotOAuthSync } from "@yielded/auth/OAuth";
11
+ //#region src/internal/oauth/connected-state.ts
12
+ const make$1 = Effect.gen(function* () {
13
+ const operations = yield* OAuthQueryCompiler;
14
+ const flow = yield* OAuthFlow;
15
+ const { and, eq, isNull, sql } = operations;
16
+ const { currentSubject } = flow;
17
+ const { both, col, copiedRow, equal } = operations;
18
+ const contextStorage = storage(M.OAuthConnectedTransactionContext);
19
+ const flowStorage = storage(M.OAuthConnectedPendingFlow);
20
+ const claimStorage = storage(M.OAuthConnectedClaim);
21
+ const tokenContextStorage = storage(M.OAuthConnectedTokenContext);
22
+ const sealedStorage = storage(M.OAuthConnectedSealedTokens);
23
+ const grantStorage = storage(M.OAuthConnectedStoredGrant);
24
+ const admissionStorage = storage(Schema.Struct({
25
+ grant: M.OAuthConnectedStoredGrant,
26
+ authorization: M.OAuthConnectedUseAuthorization
27
+ }));
28
+ const commandStorage = storage(Schema.Struct({
29
+ context: M.OAuthConnectedTokenContext,
30
+ originalDigest: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),
31
+ revocationJobId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256)))
32
+ }));
33
+ const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);
34
+ const refreshStorage = storage(M.OAuthConnectedRefreshClaim);
35
+ const jobStorage = storage(M.OAuthConnectedRevocationJob);
36
+ const summaryStorage = storage(M.OAuthConnectedSummary);
37
+ const disconnectedStorage = storage(M.OAuthConnectedDisconnected);
38
+ const safeInteger = Schema.Int.check(Schema.isBetween({
39
+ minimum: 0,
40
+ maximum: Number.MAX_SAFE_INTEGER
41
+ }));
42
+ const orderParser = Schema.decodeSync(safeInteger);
43
+ const canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));
44
+ const orderTextParser = Schema.decodeSync(canonicalOrder);
45
+ const orderNumber = (value) => {
46
+ const number = orderParser(Number(orderTextParser(value)));
47
+ invariant(String(number) === value);
48
+ return number;
49
+ };
50
+ const nativeOrder = (mapping, value) => orderParser(mapping.order.decode(value));
51
+ const initialGeneration = (cohort) => digest(cohort).pipe(Effect.map((value) => M.OAuthConnectedTarget.fields.cohortGeneration.make("initial:" + value)));
52
+ const configuration = (flow) => snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);
53
+ const retainedUntil = (mapping, now) => {
54
+ invariant(Number.isSafeInteger(mapping.retentionMillis) && mapping.retentionMillis >= 12e4 && mapping.retentionMillis <= 2592e6);
55
+ return orderParser(now + mapping.retentionMillis);
56
+ };
57
+ const rowCount = Effect.fn("oauthConnected.rowCount")(function* (table, where) {
58
+ const rows = yield* (yield* CurrentOAuthTransaction).database.select({ value: sql`count(*)`.mapWith(Number) }).from(table).where(where).pipe(Effect.mapError(unavailable));
59
+ invariant(rows.length === 1);
60
+ return orderParser(rows[0].value);
61
+ });
62
+ const countCondition = (table, where, count) => sql`(select count(*) from ${table} where ${where}) = ${count}`;
63
+ const current = Effect.fn("oauthConnected.current")(function* (mapping, subject) {
64
+ const native = yield* mapping.subjectId.toNative(subject);
65
+ return yield* currentSubject(mapping, native);
66
+ });
67
+ const nativeCopy = (value) => copiedRow({ value }).value;
68
+ const policyData = (input) => Object.freeze({
69
+ ...input,
70
+ subjectId: nativeCopy(input.subjectId),
71
+ revision: snapshotOAuthSync(M.OAuthConnectedUseAuthorization.fields.revision, input.revision),
72
+ ...input.kind === "sign-in" ? {
73
+ credential: snapshotOAuthSync(M.OAuthCredentialSnapshot, input.credential),
74
+ configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration)
75
+ } : {
76
+ authorization: input.kind === "action" ? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization) : snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),
77
+ ...input.kind === "action" ? { configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration) } : {}
78
+ },
79
+ ...input.grant === void 0 ? {} : { grant: snapshotOAuthSync(M.OAuthConnectedTokenContext, input.grant) }
80
+ });
81
+ const jobTable = (mapping) => {
82
+ const direct = mapping.job;
83
+ const configured = mapping.revocation;
84
+ return direct ?? (configured?.mode === "cohort" ? configured.job : void 0);
85
+ };
86
+ const policy = Effect.fn("oauthConnected.policy")(function* (mapping, input) {
87
+ const owner = yield* CurrentOAuthTransaction;
88
+ invariant((mapping.policy.guards?.length ?? 0) <= 32);
89
+ for (const guard of mapping.policy.guards ?? []) {
90
+ const read = yield* owner.read(guard.table, guard.condition(policyData(input)), { orderBy: col(guard.table, guard.orderBy) });
91
+ invariant(read.rows.length > 0);
92
+ }
93
+ const condition = mapping.policy.condition(policyData(input));
94
+ const accepted = yield* owner.check(condition);
95
+ if (accepted) owner.postconditions.push(condition);
96
+ return accepted;
97
+ });
98
+ const action = Effect.fn("oauthConnected.action")(function* (mapping, found, authorization, operation, expected) {
99
+ const owner = yield* CurrentOAuthTransaction;
100
+ const challenge = authorization.challenge, evidence = authorization.evidence;
101
+ const name = operation === "issue" ? "connected-begin" : operation === "disconnect" ? "connected-disconnect" : "connected-complete";
102
+ const intentDigest = yield* digest(expected.intent);
103
+ const binding = yield* digest(strings.encode([
104
+ "effect-auth/oauth-connected-action/v1",
105
+ expected.moduleId,
106
+ name,
107
+ expected.flowId,
108
+ expected.commandId,
109
+ intentDigest
110
+ ]));
111
+ if (challenge.moduleId !== expected.moduleId || challenge.action !== name || challenge.flowId !== expected.flowId || challenge.commandId !== expected.commandId || challenge.intentDigest !== intentDigest || challenge.bindingDigest !== binding || evidence.flowId !== expected.flowId || evidence.bindingDigest !== binding || !sameRevision(challenge.revision, expected.revision) || !sameRevision(evidence.revision, expected.revision) || !sameRevision(found.revision, expected.revision)) return false;
112
+ const now = yield* owner.now(mapping.clock);
113
+ const requirement = snapshotOAuthSync(AuthenticationRequirement, mapping.subject.decodeActionRequirement(copiedRow(found.row), name));
114
+ const revisions = new Map(found.revision.credentials.map((item) => [item.credentialId, item.revision]));
115
+ if (evidence.proofs.some((proof) => !revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now)) return false;
116
+ for (const required of [authorization.requirement, requirement]) {
117
+ const age = Math.min(expected.maximumAgeMillis, required.maximumAgeMillis);
118
+ const fresh = evidence.proofs.filter((proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < age);
119
+ if (!satisfies(fresh, required)) return false;
120
+ owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${now} and ${both(...fresh.map((proof) => sql`${mapping.clock.engineNowMillis} < ${DateTime.toEpochMillis(proof.verifiedAt) + age}`))}`);
121
+ }
122
+ return yield* policy(mapping, {
123
+ subjectId: found.nativeId,
124
+ revision: found.revision,
125
+ kind: "action",
126
+ operation,
127
+ authorization,
128
+ configuration: expected.configuration,
129
+ ...expected.grant === void 0 ? {} : { grant: expected.grant }
130
+ });
131
+ });
132
+ const useAuthority = Effect.fn("oauthConnected.useAuthority")(function* (mapping, authorization, kind, grant) {
133
+ const owner = yield* CurrentOAuthTransaction;
134
+ const found = yield* current(mapping, authorization.revision.subjectId);
135
+ const now = yield* owner.now(mapping.clock);
136
+ if (found === void 0 || authorization.purpose !== kind || !sameRevision(found.revision, authorization.revision) || now >= authorization.expiresAtMillis || grant !== void 0 && (grant.moduleId !== authorization.moduleId || grant.subjectId !== authorization.revision.subjectId || authorization.grantId !== void 0 && authorization.grantId !== grant.grantId || authorization.profileKey !== void 0 && authorization.profileKey !== grant.configuration.profile.key)) return void 0;
137
+ if (!(yield* policy(mapping, {
138
+ subjectId: found.nativeId,
139
+ revision: found.revision,
140
+ kind,
141
+ authorization,
142
+ ...grant === void 0 ? {} : { grant }
143
+ }))) return void 0;
144
+ owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${authorization.expiresAtMillis}`);
145
+ return found;
146
+ });
147
+ const scopeCache = /* @__PURE__ */ new WeakMap();
148
+ const clientCache = /* @__PURE__ */ new WeakMap();
149
+ const anchors = Effect.fn("oauthConnected.anchors")(function* (cache, table) {
150
+ const owner = yield* CurrentOAuthTransaction;
151
+ let tables = cache.get(owner);
152
+ if (tables === void 0) {
153
+ tables = /* @__PURE__ */ new Map();
154
+ cache.set(owner, tables);
155
+ }
156
+ let rows = tables.get(table);
157
+ if (rows === void 0) {
158
+ rows = /* @__PURE__ */ new Map();
159
+ tables.set(table, rows);
160
+ }
161
+ return rows;
162
+ });
163
+ /** Empty registration ID is impossible in the public profile label schema. The
164
+ * distinct 52-byte key domain shares the physical table, never a client counter. */
165
+ const scope = Effect.fn("oauthConnected.scope")(function* (mapping, config, create) {
166
+ const owner = yield* CurrentOAuthTransaction;
167
+ const c = mapping.client, id = yield* scopeKey(config.provider, config.issuer), cache = yield* anchors(scopeCache, c.table);
168
+ const existing = cache.get(id);
169
+ if (existing !== void 0) return existing;
170
+ const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 });
171
+ if (read.rows.length === 0) {
172
+ const related = [
173
+ mapping.flow,
174
+ mapping.grant,
175
+ mapping.cohort,
176
+ ...jobTable(mapping) === void 0 ? [] : [jobTable(mapping)]
177
+ ];
178
+ invariant(yield* owner.check(both(sql`not exists(select 1 from ${c.table} where ${owner.exact(c.table, {
179
+ [c.provider]: config.provider,
180
+ [c.issuer]: config.issuer
181
+ })})`, ...related.map((v) => sql`not exists(select 1 from ${v.table} where not exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(v.table, v.clientKey)}))`))));
182
+ if (!create) return void 0;
183
+ invariant(c.encodeInsert !== void 0);
184
+ read.rows = (yield* owner.insert(c.table, {
185
+ ...c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config)),
186
+ [c.clientKey]: id,
187
+ [c.provider]: config.provider,
188
+ [c.issuer]: config.issuer,
189
+ [c.clientRegistrationId]: "",
190
+ [c.counter]: mapping.order.encode(0),
191
+ [c.version]: owner.marker
192
+ }, { [c.clientKey]: id }, true)).rows;
193
+ }
194
+ const row = read.rows[0];
195
+ invariant(row[c.provider] === config.provider && row[c.issuer] === config.issuer && row[c.clientRegistrationId] === "" && nativeOrder(mapping, row[c.counter]) === 0);
196
+ const found = {
197
+ id,
198
+ row
199
+ };
200
+ cache.set(id, found);
201
+ return found;
202
+ });
203
+ const touchScope = Effect.fn("oauthConnected.touchScope")(function* (mapping, found) {
204
+ const owner = yield* CurrentOAuthTransaction;
205
+ const c = mapping.client;
206
+ yield* owner.update(c.table, {
207
+ [c.clientKey]: found.id,
208
+ [c.version]: found.row[c.version]
209
+ }, { [c.version]: owner.marker });
210
+ found.row = {
211
+ ...found.row,
212
+ [c.version]: owner.marker
213
+ };
214
+ });
215
+ const readScope = Effect.fn("oauthConnected.readScope")(function* (mapping, provider, issuer) {
216
+ const owner = yield* CurrentOAuthTransaction;
217
+ const c = mapping.client, id = yield* scopeKey(provider, issuer), cache = yield* anchors(scopeCache, c.table), cached = cache.get(id);
218
+ if (cached !== void 0) return cached;
219
+ const row = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 })).rows[0];
220
+ invariant(row !== void 0 && row[c.provider] === provider && row[c.issuer] === issuer && row[c.clientRegistrationId] === "" && nativeOrder(mapping, row[c.counter]) === 0);
221
+ const found = {
222
+ id,
223
+ row
224
+ };
225
+ cache.set(id, found);
226
+ return found;
227
+ });
228
+ const lockClientById = Effect.fn("oauthConnected.lockClientById")(function* (mapping, id) {
229
+ const owner = yield* CurrentOAuthTransaction;
230
+ const c = mapping.client, cache = yield* anchors(clientCache, c.table), cached = cache.get(id);
231
+ if (cached !== void 0) return cached;
232
+ const initial = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {
233
+ limit: 1,
234
+ observe: false,
235
+ lock: false
236
+ })).rows[0];
237
+ invariant(initial !== void 0);
238
+ const scope = yield* readScope(mapping, initial[c.provider], initial[c.issuer]);
239
+ const row = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 })).rows[0];
240
+ invariant(row !== void 0 && row[c.clientRegistrationId] !== "" && id === (yield* key("effect-auth/oauth-connected-client/v1", [
241
+ row[c.provider],
242
+ row[c.issuer],
243
+ row[c.clientRegistrationId]
244
+ ])) && scope.id === (yield* scopeKey(row[c.provider], row[c.issuer])));
245
+ const found = {
246
+ id,
247
+ row,
248
+ counter: nativeOrder(mapping, row[c.counter]),
249
+ scope
250
+ };
251
+ cache.set(id, found);
252
+ return found;
253
+ });
254
+ const heldScope = Effect.fnUntraced(function* (mapping, provider, issuer) {
255
+ return (yield* anchors(scopeCache, mapping.client.table)).get(yield* scopeKey(provider, issuer));
256
+ });
257
+ /** Cleanup obtains every scope then every client before entering any tuple. */
258
+ const prelockClients = Effect.fn("oauthConnected.prelockClients")(function* (mapping, ids, releaseScopes = []) {
259
+ const owner = yield* CurrentOAuthTransaction;
260
+ const unique = [...new Set(ids)].sort(), c = mapping.client;
261
+ invariant(unique.length <= 4e3);
262
+ const scopes = /* @__PURE__ */ new Map();
263
+ for (const value of releaseScopes) scopes.set(yield* scopeKey(value.provider, value.issuer), {
264
+ ...value,
265
+ required: false
266
+ });
267
+ for (const id of unique) {
268
+ const row = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {
269
+ limit: 1,
270
+ lock: false,
271
+ observe: false
272
+ })).rows[0];
273
+ invariant(row !== void 0);
274
+ scopes.set(yield* scopeKey(row[c.provider], row[c.issuer]), {
275
+ provider: row[c.provider],
276
+ issuer: row[c.issuer],
277
+ required: true
278
+ });
279
+ }
280
+ for (const [id, { provider, issuer, required }] of [...scopes].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) if (required) yield* readScope(mapping, provider, issuer);
281
+ else {
282
+ const row = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 })).rows[0];
283
+ if (row !== void 0) {
284
+ invariant(row[c.provider] === provider && row[c.issuer] === issuer && row[c.clientRegistrationId] === "" && nativeOrder(mapping, row[c.counter]) === 0);
285
+ (yield* anchors(scopeCache, c.table)).set(id, {
286
+ id,
287
+ row
288
+ });
289
+ }
290
+ }
291
+ for (const id of unique) yield* lockClientById(mapping, id);
292
+ });
293
+ const client = Effect.fn("oauthConnected.client")(function* (mapping, config, create) {
294
+ const owner = yield* CurrentOAuthTransaction;
295
+ const c = mapping.client, id = yield* clientKey(config), where = { [c.clientKey]: id };
296
+ const heldScope = yield* scope(mapping, config, create);
297
+ if (heldScope === void 0) return void 0;
298
+ const cache = yield* anchors(clientCache, c.table), cached = cache.get(id);
299
+ if (cached !== void 0) return cached;
300
+ let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });
301
+ if (read.rows.length === 0) {
302
+ const related = [
303
+ mapping.flow,
304
+ mapping.grant,
305
+ mapping.cohort,
306
+ ...jobTable(mapping) === void 0 ? [] : [jobTable(mapping)]
307
+ ];
308
+ invariant(yield* owner.check(both(...related.map((v) => sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.clientKey), id)})`))));
309
+ }
310
+ if (read.rows.length === 0 && create) read.rows = (yield* owner.insert(c.table, {
311
+ ...(invariant(c.encodeInsert !== void 0), c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config))),
312
+ ...where,
313
+ [c.provider]: config.provider,
314
+ [c.issuer]: config.issuer,
315
+ [c.clientRegistrationId]: config.profile.clientRegistrationId,
316
+ [c.counter]: mapping.order.encode(0),
317
+ [c.version]: owner.marker
318
+ }, where, true)).rows;
319
+ const row = read.rows[0];
320
+ if (row === void 0) return void 0;
321
+ invariant(row[c.provider] === config.provider && row[c.issuer] === config.issuer && row[c.clientRegistrationId] === config.profile.clientRegistrationId);
322
+ const found = {
323
+ id,
324
+ row,
325
+ counter: nativeOrder(mapping, row[c.counter]),
326
+ scope: heldScope
327
+ };
328
+ cache.set(id, found);
329
+ return found;
330
+ });
331
+ const nextOrder = Effect.fn("oauthConnected.nextOrder")(function* (mapping, found) {
332
+ const owner = yield* CurrentOAuthTransaction;
333
+ const next = orderParser(found.counter + 1), c = mapping.client;
334
+ yield* owner.update(c.table, {
335
+ [c.clientKey]: found.id,
336
+ [c.counter]: mapping.order.encode(found.counter)
337
+ }, {
338
+ [c.counter]: mapping.order.encode(next),
339
+ [c.version]: owner.marker
340
+ });
341
+ found.counter = next;
342
+ return next;
343
+ });
344
+ const cohort = Effect.fn("oauthConnected.cohort")(function* (mapping, clientId, identityId, create) {
345
+ const owner = yield* CurrentOAuthTransaction;
346
+ const c = mapping.cohort, id = yield* cohortKey(clientId, identityId), where = { [c.cohortKey]: id };
347
+ let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });
348
+ if (read.rows.length === 0) {
349
+ const related = [
350
+ mapping.flow,
351
+ mapping.grant,
352
+ ...jobTable(mapping) === void 0 ? [] : [jobTable(mapping)]
353
+ ];
354
+ invariant(yield* owner.check(both(...related.map((v) => sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.cohortKey), id)})`))));
355
+ }
356
+ if (read.rows.length === 0 && create) read.rows = (yield* owner.insert(c.table, {
357
+ ...(invariant(c.encodeInsert !== void 0), c.encodeInsert({
358
+ clientKey: clientId,
359
+ identityKey: identityId
360
+ })),
361
+ ...where,
362
+ [c.clientKey]: clientId,
363
+ [c.identityKey]: identityId,
364
+ [c.generation]: yield* initialGeneration(id),
365
+ [c.cutoff]: mapping.order.encode(0),
366
+ [c.state]: "Open",
367
+ [c.version]: owner.marker
368
+ }, where, true)).rows;
369
+ const row = read.rows[0];
370
+ if (row === void 0) return {
371
+ id,
372
+ row: void 0,
373
+ generation: yield* initialGeneration(id),
374
+ cutoff: 0,
375
+ blocked: false
376
+ };
377
+ invariant(row[c.clientKey] === clientId && row[c.identityKey] === identityId && ["Open", "Blocked"].includes(row[c.state]));
378
+ return {
379
+ id,
380
+ row,
381
+ generation: snapshotOAuthSync(M.OAuthConnectedTarget.fields.cohortGeneration, row[c.generation]),
382
+ cutoff: nativeOrder(mapping, row[c.cutoff]),
383
+ blocked: row[c.state] === "Blocked"
384
+ };
385
+ });
386
+ const readGrant = Effect.fn("oauthConnected.readGrant")(function* (mapping, moduleId, grantId, lock = true) {
387
+ const owner = yield* CurrentOAuthTransaction;
388
+ const g = mapping.grant;
389
+ const read = yield* owner.read(g.table, equal(g.table, {
390
+ [g.moduleId]: moduleId,
391
+ [g.grantId]: grantId
392
+ }), {
393
+ limit: 1,
394
+ lock,
395
+ admissionOnly: lock,
396
+ observe: false
397
+ });
398
+ const row = read.rows[0];
399
+ if (row === void 0) return void 0;
400
+ if (lock) owner.observations.push(read);
401
+ const context = tokenContextStorage.decode(row[g.context]);
402
+ const native = yield* mapping.subjectId.toNative(context.subjectId);
403
+ invariant(context.moduleId === moduleId && context.grantId === grantId && mapping.subjectId.equals(native, row[g.subjectId]) && row[g.identityKey] === (yield* oauthIdentityKey(context.identity)) && row[g.clientKey] === (yield* clientKey(context.configuration)) && row[g.cohortKey] === (yield* cohortKey(row[g.clientKey], row[g.identityKey])) && row[g.profileKey] === context.configuration.profile.key && row[g.grantVersion] === context.grantVersion && row[g.tokenVersion] === context.tokenVersion && row[g.cohortGeneration] === context.cohortGeneration);
404
+ return {
405
+ row,
406
+ context,
407
+ native,
408
+ sealed: row[g.sealed] === null ? void 0 : sealedStorage.decode(row[g.sealed])
409
+ };
410
+ });
411
+ const unknownWork = (mapping, clientId, cutoff) => {
412
+ const f = mapping.flow;
413
+ return both(eq(col(f.table, f.clientKey), clientId), eq(col(f.table, f.work), "Unresolved"), isNull(col(f.table, f.cohortKey)), cutoff === void 0 ? void 0 : sql`${col(f.table, f.claimOrder)} <= ${mapping.order.encode(cutoff)}`);
414
+ };
415
+ const cohortWork = (mapping, id) => {
416
+ const f = mapping.flow, g = mapping.grant;
417
+ return both(sql`not exists(select 1 from ${f.table} where ${and(eq(col(f.table, f.cohortKey), id), eq(col(f.table, f.work), "Unresolved"))})`, sql`not exists(select 1 from ${g.table} where ${and(eq(col(g.table, g.cohortKey), id), eq(col(g.table, g.refreshWork), "Unresolved"))})`);
418
+ };
419
+ return {
420
+ contextStorage,
421
+ flowStorage,
422
+ claimStorage,
423
+ tokenContextStorage,
424
+ sealedStorage,
425
+ grantStorage,
426
+ admissionStorage,
427
+ commandStorage,
428
+ disconnectStorage,
429
+ refreshStorage,
430
+ jobStorage,
431
+ summaryStorage,
432
+ disconnectedStorage,
433
+ orderNumber,
434
+ nativeOrder,
435
+ clientKey,
436
+ cohortKey,
437
+ initialGeneration,
438
+ configuration,
439
+ retainedUntil,
440
+ rowCount,
441
+ countCondition,
442
+ current,
443
+ nativeCopy,
444
+ jobTable,
445
+ policy,
446
+ action,
447
+ useAuthority,
448
+ scopeKey,
449
+ scope,
450
+ touchScope,
451
+ readScope,
452
+ lockClientById,
453
+ heldScope,
454
+ prelockClients,
455
+ client,
456
+ nextOrder,
457
+ cohort,
458
+ readGrant,
459
+ unknownWork,
460
+ cohortWork
461
+ };
462
+ });
463
+ var OAuthConnectedState = class OAuthConnectedState extends Context.Service()("effect-auth/persistence/OAuthConnectedState") {
464
+ static layer = Layer.effect(OAuthConnectedState, make$1);
465
+ };
466
+ //#endregion
467
+ export { OAuthConnectedState };
468
+
469
+ //# sourceMappingURL=connected-state.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connected-state.mjs","names":["make"],"sources":["../../../src/internal/oauth/connected-state.ts"],"sourcesContent":["/* oxlint-disable no-explicit-any -- compiler table shapes are erased; domain codecs and error channels remain typed. */\nimport { type OAuthAccountRevision, snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport * as M from \"@yielded/auth/OAuth\";\nimport { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\nimport { DateTime, Effect, Schema, Context, Layer } from \"effect\";\n\nimport type {\n OAuthConnectedAuthorityMapping,\n OAuthConnectedClientRegistrationTable,\n OAuthConnectedCohortTable,\n OAuthConnectedMapping,\n OAuthConnectedPolicyInput,\n OAuthConnectedRevocationMapping,\n} from \"../models/oauth-connected-model\";\nimport type { SqlExpression as SQL, QueryFailure } from \"../query-operations\";\nimport { strings, clientKey, cohortKey, scopeKey, key } from \"./connected-keys\";\nimport { OAuthFlow } from \"./flow\";\nimport { CurrentOAuthTransaction } from \"./owner\";\nimport type { OAuthOwner, Row } from \"./owner\";\nimport { OAuthQueryCompiler } from \"./query-compiler\";\nimport {\n digest,\n invariant,\n oauthIdentityKey,\n sameRevision,\n satisfies,\n storage,\n unavailable,\n} from \"./state\";\ntype Table = object;\n\nexport type Authority = OAuthConnectedAuthorityMapping<any, any, any, any, any, any, any> & {\n readonly client: Partial<Pick<OAuthConnectedClientRegistrationTable<any>, \"encodeInsert\">>;\n readonly cohort: Partial<Pick<OAuthConnectedCohortTable<any>, \"encodeInsert\">>;\n};\n\n// Expression handles are supplied by the owning compiler, never decoded domain data.\nexport type Mapping = OAuthConnectedMapping<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\n\nexport type Revocations = OAuthConnectedRevocationMapping<any, any, any, any, any, any, any, any>;\n\nexport type Current = NonNullable<\n Effect.Success<ReturnType<OAuthFlow[\"Service\"][\"currentSubject\"]>>\n>;\n\nexport interface ScopeAnchor {\n readonly id: string;\n row: Row;\n}\n\nexport interface ClientAnchor {\n readonly id: string;\n row: Row;\n counter: number;\n readonly scope: ScopeAnchor;\n}\n\nconst make = Effect.gen(function* () {\n const operations = yield* OAuthQueryCompiler;\n const flow = yield* OAuthFlow;\n\n const { and, eq, isNull, sql } = operations;\n const { currentSubject } = flow;\n const { both, col, copiedRow, equal } = operations;\n\n const contextStorage = storage(M.OAuthConnectedTransactionContext);\n\n const flowStorage = storage(M.OAuthConnectedPendingFlow);\n\n const claimStorage = storage(M.OAuthConnectedClaim);\n\n const tokenContextStorage = storage(M.OAuthConnectedTokenContext);\n\n const sealedStorage = storage(M.OAuthConnectedSealedTokens);\n\n const grantStorage = storage(M.OAuthConnectedStoredGrant);\n\n const admissionStorage = storage(\n Schema.Struct({\n grant: M.OAuthConnectedStoredGrant,\n authorization: M.OAuthConnectedUseAuthorization,\n }),\n );\n\n const commandStorage = storage(\n Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n originalDigest: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),\n revocationJobId: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n }),\n );\n\n const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);\n\n const refreshStorage = storage(M.OAuthConnectedRefreshClaim);\n\n const jobStorage = storage(M.OAuthConnectedRevocationJob);\n\n const summaryStorage = storage(M.OAuthConnectedSummary);\n\n const disconnectedStorage = storage(M.OAuthConnectedDisconnected);\n\n const safeInteger = Schema.Int.check(\n Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),\n );\n\n const orderParser = Schema.decodeSync(safeInteger);\n\n const canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));\n\n const orderTextParser = Schema.decodeSync(canonicalOrder);\n\n const orderNumber = (value: string) => {\n const number = orderParser(Number(orderTextParser(value)));\n\n invariant(String(number) === value);\n\n return number;\n };\n\n const nativeOrder = (mapping: Authority, value: unknown) =>\n orderParser(mapping.order.decode(value));\n\n const initialGeneration = (cohort: string) =>\n digest(cohort).pipe(\n Effect.map((value) =>\n M.OAuthConnectedTarget.fields.cohortGeneration.make(\"initial:\" + value),\n ),\n );\n\n const configuration = (flow: M.OAuthConnectedPendingFlow): M.OAuthConnectedConfiguration =>\n snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);\n\n const retainedUntil = (mapping: Authority, now: number) => {\n invariant(\n Number.isSafeInteger(mapping.retentionMillis) &&\n mapping.retentionMillis >= 120000 &&\n mapping.retentionMillis <= 2592000000,\n );\n\n return orderParser(now + mapping.retentionMillis);\n };\n\n const rowCount = Effect.fn(\"oauthConnected.rowCount\")(function* (table: Table, where: SQL) {\n const owner = yield* CurrentOAuthTransaction;\n\n const rows = yield* (\n owner.database\n .select({ value: sql`count(*)`.mapWith(Number) })\n .from(table)\n .where(where) as Effect.Effect<ReadonlyArray<{ value: number }>, QueryFailure>\n ).pipe(Effect.mapError(unavailable));\n\n invariant(rows.length === 1);\n\n return orderParser(rows[0]!.value);\n });\n\n const countCondition = (table: Table, where: SQL, count: number) =>\n sql`(select count(*) from ${table} where ${where}) = ${count}`;\n\n const current = Effect.fn(\"oauthConnected.current\")(function* (\n mapping: Mapping,\n subject: OAuthAccountRevision[\"subjectId\"],\n ) {\n const native = yield* mapping.subjectId.toNative(subject);\n\n return yield* currentSubject(mapping, native);\n });\n\n const nativeCopy = <N>(value: N): N => copiedRow({ value }).value as N;\n\n const policyData = (input: OAuthConnectedPolicyInput<any>): OAuthConnectedPolicyInput<any> =>\n Object.freeze({\n ...input,\n subjectId: nativeCopy(input.subjectId),\n revision: snapshotOAuthSync(M.OAuthConnectedUseAuthorization.fields.revision, input.revision),\n ...(input.kind === \"sign-in\"\n ? {\n credential: snapshotOAuthSync(M.OAuthCredentialSnapshot, input.credential),\n configuration: snapshotOAuthSync(M.OAuthConnectedConfiguration, input.configuration),\n }\n : {\n authorization:\n input.kind === \"action\"\n ? snapshotOAuthSync(M.OAuthConnectedActionAuthorization, input.authorization)\n : snapshotOAuthSync(M.OAuthConnectedUseAuthorization, input.authorization),\n ...(input.kind === \"action\"\n ? {\n configuration: snapshotOAuthSync(\n M.OAuthConnectedConfiguration,\n input.configuration,\n ),\n }\n : {}),\n }),\n ...(input.grant === undefined\n ? {}\n : { grant: snapshotOAuthSync(M.OAuthConnectedTokenContext, input.grant) }),\n }) as OAuthConnectedPolicyInput<any>;\n\n const jobTable = (mapping: Authority) => {\n const direct = (mapping as Partial<Revocations>).job;\n const configured = (mapping as Partial<Mapping>).revocation;\n\n return direct ?? (configured?.mode === \"cohort\" ? configured.job : undefined);\n };\n\n const policy = Effect.fn(\"oauthConnected.policy\")(function* (\n mapping: Mapping,\n input: OAuthConnectedPolicyInput<any>,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n invariant((mapping.policy.guards?.length ?? 0) <= 32);\n for (const guard of mapping.policy.guards ?? []) {\n const read = yield* owner.read(guard.table, guard.condition(policyData(input)), {\n orderBy: col(guard.table, guard.orderBy),\n });\n\n invariant(read.rows.length > 0);\n }\n const condition = mapping.policy.condition(policyData(input));\n const accepted = yield* owner.check(condition);\n\n if (accepted) owner.postconditions.push(condition);\n\n return accepted;\n });\n\n const action = Effect.fn(\"oauthConnected.action\")(function* (\n mapping: Mapping,\n found: Current,\n authorization: M.OAuthConnectedActionAuthorization,\n operation: \"issue\" | \"claim\" | \"settle\" | \"disconnect\",\n expected: {\n readonly moduleId: string;\n readonly flowId: string;\n readonly commandId: string;\n readonly revision: OAuthAccountRevision;\n readonly intent: string;\n readonly maximumAgeMillis: number;\n readonly configuration: M.OAuthConnectedConfiguration;\n readonly grant?: M.OAuthConnectedTokenContext;\n },\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const challenge = authorization.challenge,\n evidence = authorization.evidence;\n\n const name =\n operation === \"issue\"\n ? \"connected-begin\"\n : operation === \"disconnect\"\n ? \"connected-disconnect\"\n : \"connected-complete\";\n\n const intentDigest = yield* digest(expected.intent);\n\n const binding = yield* digest(\n strings.encode([\n \"effect-auth/oauth-connected-action/v1\",\n expected.moduleId,\n name,\n expected.flowId,\n expected.commandId,\n intentDigest,\n ]),\n );\n\n if (\n challenge.moduleId !== expected.moduleId ||\n challenge.action !== name ||\n challenge.flowId !== expected.flowId ||\n challenge.commandId !== expected.commandId ||\n challenge.intentDigest !== intentDigest ||\n challenge.bindingDigest !== binding ||\n evidence.flowId !== expected.flowId ||\n evidence.bindingDigest !== binding ||\n !sameRevision(challenge.revision, expected.revision) ||\n !sameRevision(evidence.revision, expected.revision) ||\n !sameRevision(found.revision, expected.revision)\n )\n return false;\n const now = yield* owner.now(mapping.clock);\n\n const requirement = snapshotOAuthSync(\n AuthenticationRequirement,\n mapping.subject.decodeActionRequirement(copiedRow(found.row), name),\n );\n\n const revisions = new Map(\n found.revision.credentials.map((item) => [item.credentialId, item.revision]),\n );\n\n if (\n evidence.proofs.some(\n (proof) =>\n !revisions.has(proof.credentialId) || DateTime.toEpochMillis(proof.verifiedAt) > now,\n )\n )\n return false;\n for (const required of [authorization.requirement, requirement]) {\n const age = Math.min(expected.maximumAgeMillis, required.maximumAgeMillis);\n\n const fresh = evidence.proofs.filter(\n (proof) => now - DateTime.toEpochMillis(proof.verifiedAt) < age,\n );\n\n if (!satisfies(fresh, required)) return false;\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${now} and ${both(...fresh.map((proof) => sql`${mapping.clock.engineNowMillis} < ${DateTime.toEpochMillis(proof.verifiedAt) + age}`))}`,\n );\n }\n\n return yield* policy(mapping, {\n subjectId: found.nativeId,\n revision: found.revision,\n kind: \"action\",\n operation,\n authorization,\n configuration: expected.configuration,\n ...(expected.grant === undefined ? {} : { grant: expected.grant }),\n });\n });\n\n const useAuthority = Effect.fn(\"oauthConnected.useAuthority\")(function* (\n mapping: Mapping,\n authorization: M.OAuthConnectedUseAuthorization,\n kind: \"metadata\" | \"use\",\n grant?: M.OAuthConnectedTokenContext,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n const found = yield* current(mapping, authorization.revision.subjectId);\n const now = yield* owner.now(mapping.clock);\n\n if (\n found === undefined ||\n authorization.purpose !== kind ||\n !sameRevision(found.revision, authorization.revision) ||\n now >= authorization.expiresAtMillis ||\n (grant !== undefined &&\n (grant.moduleId !== authorization.moduleId ||\n grant.subjectId !== authorization.revision.subjectId ||\n (authorization.grantId !== undefined && authorization.grantId !== grant.grantId) ||\n (authorization.profileKey !== undefined &&\n authorization.profileKey !== grant.configuration.profile.key)))\n )\n return undefined;\n if (\n !(yield* policy(mapping, {\n subjectId: found.nativeId,\n revision: found.revision,\n kind,\n authorization,\n ...(grant === undefined ? {} : { grant }),\n }))\n )\n return undefined;\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${authorization.expiresAtMillis}`,\n );\n\n return found;\n });\n\n const scopeCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ScopeAnchor>>>();\n\n const clientCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ClientAnchor>>>();\n\n const anchors = Effect.fn(\"oauthConnected.anchors\")(function* <A>(\n cache: WeakMap<OAuthOwner, Map<Table, Map<string, A>>>,\n table: Table,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n let tables = cache.get(owner);\n\n if (tables === undefined) {\n tables = new Map();\n cache.set(owner, tables);\n }\n let rows = tables.get(table);\n\n if (rows === undefined) {\n rows = new Map();\n tables.set(table, rows);\n }\n\n return rows;\n });\n\n /** Empty registration ID is impossible in the public profile label schema. The\n * distinct 52-byte key domain shares the physical table, never a client counter. */\n const scope = Effect.fn(\"oauthConnected.scope\")(function* (\n mapping: Authority,\n config: M.OAuthConnectedConfiguration,\n create: boolean,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = yield* scopeKey(config.provider, config.issuer),\n cache = yield* anchors(scopeCache, c.table);\n\n const existing = cache.get(id);\n\n if (existing !== undefined) return existing;\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n mapping.cohort,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n sql`not exists(select 1 from ${c.table} where ${owner.exact(c.table, { [c.provider]: config.provider, [c.issuer]: config.issuer })})`,\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where not exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(v.table, v.clientKey)}))`,\n ),\n ),\n ),\n );\n if (!create) return undefined;\n invariant(c.encodeInsert !== undefined);\n\n const inserted = yield* owner.insert(\n c.table,\n {\n ...c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config)),\n [c.clientKey]: id,\n [c.provider]: config.provider,\n [c.issuer]: config.issuer,\n [c.clientRegistrationId]: \"\",\n [c.counter]: mapping.order.encode(0),\n [c.version]: owner.marker,\n },\n { [c.clientKey]: id },\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0]!;\n\n invariant(\n row[c.provider] === config.provider &&\n row[c.issuer] === config.issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n const found = { id, row };\n\n cache.set(id, found);\n\n return found;\n });\n\n const touchScope = Effect.fn(\"oauthConnected.touchScope\")(function* (\n mapping: Authority,\n found: ScopeAnchor,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n const c = mapping.client;\n\n yield* owner.update(\n c.table,\n { [c.clientKey]: found.id, [c.version]: found.row[c.version] },\n { [c.version]: owner.marker },\n );\n found.row = { ...found.row, [c.version]: owner.marker };\n });\n\n const readScope = Effect.fn(\"oauthConnected.readScope\")(function* (\n mapping: Authority,\n provider: string,\n issuer: string,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = yield* scopeKey(provider, issuer),\n cache = yield* anchors(scopeCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n invariant(\n row !== undefined &&\n row[c.provider] === provider &&\n row[c.issuer] === issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n const found = { id, row };\n\n cache.set(id, found);\n\n return found;\n });\n\n const lockClientById = Effect.fn(\"oauthConnected.lockClientById\")(function* (\n mapping: Authority,\n id: string,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n cache = yield* anchors(clientCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n\n const discovery = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n observe: false,\n lock: false,\n }),\n initial = discovery.rows[0];\n\n invariant(initial !== undefined);\n const scope = yield* readScope(mapping, initial[c.provider], initial[c.issuer]);\n\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 }),\n row = read.rows[0];\n\n invariant(\n row !== undefined &&\n row[c.clientRegistrationId] !== \"\" &&\n id ===\n (yield* key(\"effect-auth/oauth-connected-client/v1\", [\n row[c.provider],\n row[c.issuer],\n row[c.clientRegistrationId],\n ])) &&\n scope.id === (yield* scopeKey(row[c.provider], row[c.issuer])),\n );\n const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope };\n\n cache.set(id, found);\n\n return found;\n });\n\n const heldScope = Effect.fnUntraced(function* (\n mapping: Authority,\n provider: string,\n issuer: string,\n ) {\n const cache = yield* anchors(scopeCache, mapping.client.table);\n\n return cache.get(yield* scopeKey(provider, issuer));\n });\n\n /** Cleanup obtains every scope then every client before entering any tuple. */\n const prelockClients = Effect.fn(\"oauthConnected.prelockClients\")(function* (\n mapping: Authority,\n ids: ReadonlyArray<string>,\n releaseScopes: ReadonlyArray<{ readonly provider: string; readonly issuer: string }> = [],\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const unique = [...new Set(ids)].sort(),\n c = mapping.client;\n\n invariant(unique.length <= 4000);\n const scopes = new Map<string, { provider: string; issuer: string; required: boolean }>();\n\n for (const value of releaseScopes)\n scopes.set(yield* scopeKey(value.provider, value.issuer), { ...value, required: false });\n for (const id of unique) {\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n lock: false,\n observe: false,\n }),\n row = read.rows[0];\n\n invariant(row !== undefined);\n scopes.set(yield* scopeKey(row[c.provider], row[c.issuer]), {\n provider: row[c.provider],\n issuer: row[c.issuer],\n required: true,\n });\n }\n for (const [id, { provider, issuer, required }] of [...scopes].sort(([a], [b]) =>\n a < b ? -1 : a > b ? 1 : 0,\n )) {\n if (required) yield* readScope(mapping, provider, issuer);\n else {\n const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), {\n limit: 1,\n }),\n row = read.rows[0];\n\n if (row !== undefined) {\n invariant(\n row[c.provider] === provider &&\n row[c.issuer] === issuer &&\n row[c.clientRegistrationId] === \"\" &&\n nativeOrder(mapping, row[c.counter]) === 0,\n );\n (yield* anchors(scopeCache, c.table)).set(id, { id, row });\n }\n }\n }\n for (const id of unique) yield* lockClientById(mapping, id);\n });\n\n const client = Effect.fn(\"oauthConnected.client\")(function* (\n mapping: Authority,\n config: M.OAuthConnectedConfiguration,\n create: boolean,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.client,\n id = yield* clientKey(config),\n where = { [c.clientKey]: id };\n\n const heldScope = yield* scope(mapping, config, create);\n\n if (heldScope === undefined) return undefined;\n\n const cache = yield* anchors(clientCache, c.table),\n cached = cache.get(id);\n\n if (cached !== undefined) return cached;\n let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n mapping.cohort,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.clientKey), id)})`,\n ),\n ),\n ),\n );\n }\n if (read.rows.length === 0 && create) {\n const inserted = yield* owner.insert(\n c.table,\n {\n ...(invariant(c.encodeInsert !== undefined),\n c.encodeInsert(snapshotOAuthSync(M.OAuthConnectedConfiguration, config))),\n ...where,\n [c.provider]: config.provider,\n [c.issuer]: config.issuer,\n [c.clientRegistrationId]: config.profile.clientRegistrationId,\n [c.counter]: mapping.order.encode(0),\n [c.version]: owner.marker,\n },\n where,\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0];\n\n if (row === undefined) return undefined;\n invariant(\n row[c.provider] === config.provider &&\n row[c.issuer] === config.issuer &&\n row[c.clientRegistrationId] === config.profile.clientRegistrationId,\n );\n const found = { id, row, counter: nativeOrder(mapping, row[c.counter]), scope: heldScope };\n\n cache.set(id, found);\n\n return found;\n });\n\n const nextOrder = Effect.fn(\"oauthConnected.nextOrder\")(function* (\n mapping: Authority,\n found: NonNullable<Effect.Success<ReturnType<typeof client>>>,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const next = orderParser(found.counter + 1),\n c = mapping.client;\n\n yield* owner.update(\n c.table,\n { [c.clientKey]: found.id, [c.counter]: mapping.order.encode(found.counter) },\n { [c.counter]: mapping.order.encode(next), [c.version]: owner.marker },\n );\n found.counter = next;\n\n return next;\n });\n\n const cohort = Effect.fn(\"oauthConnected.cohort\")(function* (\n mapping: Authority,\n clientId: string,\n identityId: string,\n create: boolean,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = mapping.cohort,\n id = yield* cohortKey(clientId, identityId),\n where = { [c.cohortKey]: id };\n\n let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });\n\n if (read.rows.length === 0) {\n const related = [\n mapping.flow,\n mapping.grant,\n ...(jobTable(mapping) === undefined ? [] : [jobTable(mapping)!]),\n ];\n\n invariant(\n yield* owner.check(\n both(\n ...related.map(\n (v) =>\n sql`not exists(select 1 from ${v.table} where ${eq(col(v.table, v.cohortKey), id)})`,\n ),\n ),\n ),\n );\n }\n if (read.rows.length === 0 && create) {\n const inserted = yield* owner.insert(\n c.table,\n {\n ...(invariant(c.encodeInsert !== undefined),\n c.encodeInsert({ clientKey: clientId, identityKey: identityId })),\n ...where,\n [c.clientKey]: clientId,\n [c.identityKey]: identityId,\n [c.generation]: yield* initialGeneration(id),\n [c.cutoff]: mapping.order.encode(0),\n [c.state]: \"Open\",\n [c.version]: owner.marker,\n },\n where,\n true,\n );\n\n read.rows = inserted.rows;\n }\n const row = read.rows[0];\n\n if (row === undefined)\n return {\n id,\n row: undefined,\n generation: yield* initialGeneration(id),\n cutoff: 0,\n blocked: false,\n };\n invariant(\n row[c.clientKey] === clientId &&\n row[c.identityKey] === identityId &&\n [\"Open\", \"Blocked\"].includes(row[c.state]),\n );\n\n const generation = snapshotOAuthSync(\n M.OAuthConnectedTarget.fields.cohortGeneration,\n row[c.generation],\n );\n\n return {\n id,\n row,\n generation,\n cutoff: nativeOrder(mapping, row[c.cutoff]),\n blocked: row[c.state] === \"Blocked\",\n };\n });\n\n const readGrant = Effect.fn(\"oauthConnected.readGrant\")(function* (\n mapping: Authority,\n moduleId: string,\n grantId: string,\n lock = true,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n const g = mapping.grant;\n\n const read = yield* owner.read(\n g.table,\n equal(g.table, { [g.moduleId]: moduleId, [g.grantId]: grantId }),\n { limit: 1, lock, admissionOnly: lock, observe: false },\n );\n\n const row = read.rows[0];\n\n if (row === undefined) return undefined;\n if (lock) owner.observations.push(read);\n const context = tokenContextStorage.decode(row[g.context]);\n const native = yield* mapping.subjectId.toNative(context.subjectId);\n\n invariant(\n context.moduleId === moduleId &&\n context.grantId === grantId &&\n mapping.subjectId.equals(native, row[g.subjectId]) &&\n row[g.identityKey] === (yield* oauthIdentityKey(context.identity)) &&\n row[g.clientKey] === (yield* clientKey(context.configuration)) &&\n row[g.cohortKey] === (yield* cohortKey(row[g.clientKey], row[g.identityKey])) &&\n row[g.profileKey] === context.configuration.profile.key &&\n row[g.grantVersion] === context.grantVersion &&\n row[g.tokenVersion] === context.tokenVersion &&\n row[g.cohortGeneration] === context.cohortGeneration,\n );\n\n return {\n row,\n context,\n native,\n sealed: row[g.sealed] === null ? undefined : sealedStorage.decode(row[g.sealed]),\n };\n });\n\n const unknownWork = (mapping: Authority, clientId: string | SQL, cutoff?: number) => {\n const f = mapping.flow;\n\n return both(\n eq(col(f.table, f.clientKey), clientId),\n eq(col(f.table, f.work), \"Unresolved\"),\n isNull(col(f.table, f.cohortKey)),\n cutoff === undefined\n ? undefined\n : sql`${col(f.table, f.claimOrder)} <= ${mapping.order.encode(cutoff)}`,\n );\n };\n\n const cohortWork = (mapping: Authority, id: string | SQL) => {\n const f = mapping.flow,\n g = mapping.grant;\n\n return both(\n sql`not exists(select 1 from ${f.table} where ${and(eq(col(f.table, f.cohortKey), id), eq(col(f.table, f.work), \"Unresolved\"))})`,\n sql`not exists(select 1 from ${g.table} where ${and(eq(col(g.table, g.cohortKey), id), eq(col(g.table, g.refreshWork), \"Unresolved\"))})`,\n );\n };\n\n return {\n contextStorage,\n flowStorage,\n claimStorage,\n tokenContextStorage,\n sealedStorage,\n grantStorage,\n admissionStorage,\n commandStorage,\n disconnectStorage,\n refreshStorage,\n jobStorage,\n summaryStorage,\n disconnectedStorage,\n orderNumber,\n nativeOrder,\n clientKey,\n cohortKey,\n initialGeneration,\n configuration,\n retainedUntil,\n rowCount,\n countCondition,\n current,\n nativeCopy,\n jobTable,\n policy,\n action,\n useAuthority,\n scopeKey,\n scope,\n touchScope,\n readScope,\n lockClientById,\n heldScope,\n prelockClients,\n client,\n nextOrder,\n cohort,\n readGrant,\n unknownWork,\n cohortWork,\n };\n});\n\nexport class OAuthConnectedState extends Context.Service<\n OAuthConnectedState,\n Effect.Success<typeof make>\n>()(\"effect-auth/persistence/OAuthConnectedState\") {\n static readonly layer = Layer.effect(OAuthConnectedState, make);\n}\n"],"mappings":";;;;;;;;;;;AAuEA,MAAMA,SAAO,OAAO,IAAI,aAAa;CACnC,MAAM,aAAa,OAAO;CAC1B,MAAM,OAAO,OAAO;CAEpB,MAAM,EAAE,KAAK,IAAI,QAAQ,QAAQ;CACjC,MAAM,EAAE,mBAAmB;CAC3B,MAAM,EAAE,MAAM,KAAK,WAAW,UAAU;CAExC,MAAM,iBAAiB,QAAQ,EAAE,gCAAgC;CAEjE,MAAM,cAAc,QAAQ,EAAE,yBAAyB;CAEvD,MAAM,eAAe,QAAQ,EAAE,mBAAmB;CAEl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AAoB,UAAwB,WAAoB;EACnF,MAAM,IAAI,QAAQ;EAElB,OAAO,KACL,GAAG,IAAI,EAAE,OAAO,EAAE,SAAS,GAAG,QAAQ,GACtC,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,YAAY,GACrC,OAAO,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,GAChC,WAAW,KAAA,IACP,KAAA,IACA,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,MAAM,OAAO,MAAM,GACxE;CACF;CAEA,MAAM,cAAc,SAAoB,OAAqB;EAC3D,MAAM,IAAI,QAAQ,MAChB,IAAI,QAAQ;EAEd,OAAO,KACL,GAAG,4BAA4B,EAAE,MAAM,SAAS,IAAI,GAAG,IAAI,EAAE,OAAO,EAAE,SAAS,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,YAAY,CAAC,EAAE,IAC/H,GAAG,4BAA4B,EAAE,MAAM,SAAS,IAAI,GAAG,IAAI,EAAE,OAAO,EAAE,SAAS,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,YAAY,CAAC,EAAE,EACxI;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF,CAAC;AAED,IAAa,sBAAb,MAAa,4BAA4B,QAAQ,QAG/C,CAAC,CAAC,6CAA6C,CAAC,CAAC;CACjD,OAAgB,QAAQ,MAAM,OAAO,qBAAqBA,MAAI;AAChE"}
@@ -0,0 +1,21 @@
1
+ import "../transaction-kernel.mjs";
2
+ import "./connected-state.mjs";
3
+ import "./target.mjs";
4
+ import "./connected-flow.mjs";
5
+ import "./connected-settlement.mjs";
6
+ import "./connected-access.mjs";
7
+ import "./connected-maintenance.mjs";
8
+ import "./connected-management.mjs";
9
+ import "./connected-sign-in.mjs";
10
+ import { Context, Crypto, Effect, Layer, Schema } from "effect";
11
+ import { Statement } from "effect/sql/Statement";
12
+ import { OAuthConnectedPersistence, OAuthConnectedRevocationDecision, OAuthConnectedRevocations, OAuthExternalIdentity, OAuthUnavailable, PrepareOAuthCommit } from "@yielded/auth/OAuth";
13
+ //#region src/internal/oauth/connected-target.d.ts
14
+ export declare const oauthConnectedPersistenceLayer: <E, R>(services: Effect.Effect<{
15
+ readonly oauthConnectedPersistence: OAuthConnectedPersistence["Service"];
16
+ }, E, R>) => Layer.Layer<OAuthConnectedPersistence, E, Exclude<R, import("effect/Scope").Scope>>;
17
+ export declare const oauthConnectedRevocationsLayer: <E, R>(services: Effect.Effect<{
18
+ readonly oauthConnectedRevocations: OAuthConnectedRevocations["Service"];
19
+ }, E, R>) => Layer.Layer<OAuthConnectedRevocations, E, Exclude<R, import("effect/Scope").Scope>>;
20
+ //#endregion
21
+ //# sourceMappingURL=connected-target.d.mts.map