@yielded/auth-persistence 0.1.0-beta.23 → 0.1.0-beta.25

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 (182) 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/email-kernel.d.mts +1 -1
  13. package/dist/internal/email-kernel.mjs +1 -1
  14. package/dist/internal/email-kernel.mjs.map +1 -1
  15. package/dist/internal/models/oauth-connected-model.d.mts +294 -0
  16. package/dist/internal/models/oauth-connected-model.mjs +22 -0
  17. package/dist/internal/models/oauth-connected-model.mjs.map +1 -0
  18. package/dist/internal/models/oauth-model.d.mts +467 -0
  19. package/dist/internal/models/oauth-model.mjs +49 -0
  20. package/dist/internal/models/oauth-model.mjs.map +1 -0
  21. package/dist/internal/models/password-model.d.mts +6 -48
  22. package/dist/internal/models/password-model.mjs +0 -1
  23. package/dist/internal/models/password-model.mjs.map +1 -1
  24. package/dist/internal/native-sql-table.d.mts +4 -0
  25. package/dist/internal/native-sql-table.mjs +7 -0
  26. package/dist/internal/native-sql-table.mjs.map +1 -1
  27. package/dist/internal/oauth/accounts.d.mts +8 -0
  28. package/dist/internal/oauth/accounts.mjs +379 -0
  29. package/dist/internal/oauth/accounts.mjs.map +1 -0
  30. package/dist/internal/oauth/connected-access.d.mts +9 -0
  31. package/dist/internal/oauth/connected-access.mjs +229 -0
  32. package/dist/internal/oauth/connected-access.mjs.map +1 -0
  33. package/dist/internal/oauth/connected-collection.d.mts +7 -0
  34. package/dist/internal/oauth/connected-collection.mjs +214 -0
  35. package/dist/internal/oauth/connected-collection.mjs.map +1 -0
  36. package/dist/internal/oauth/connected-custody.d.mts +6 -0
  37. package/dist/internal/oauth/connected-custody.mjs +165 -0
  38. package/dist/internal/oauth/connected-custody.mjs.map +1 -0
  39. package/dist/internal/oauth/connected-flow.d.mts +7 -0
  40. package/dist/internal/oauth/connected-flow.mjs +324 -0
  41. package/dist/internal/oauth/connected-flow.mjs.map +1 -0
  42. package/dist/internal/oauth/connected-input.mjs +122 -0
  43. package/dist/internal/oauth/connected-input.mjs.map +1 -0
  44. package/dist/internal/oauth/connected-keys.d.mts +2 -0
  45. package/dist/internal/oauth/connected-keys.mjs +22 -0
  46. package/dist/internal/oauth/connected-keys.mjs.map +1 -0
  47. package/dist/internal/oauth/connected-maintenance.d.mts +9 -0
  48. package/dist/internal/oauth/connected-maintenance.mjs +226 -0
  49. package/dist/internal/oauth/connected-maintenance.mjs.map +1 -0
  50. package/dist/internal/oauth/connected-management.d.mts +9 -0
  51. package/dist/internal/oauth/connected-management.mjs +243 -0
  52. package/dist/internal/oauth/connected-management.mjs.map +1 -0
  53. package/dist/internal/oauth/connected-reference.mjs +63 -0
  54. package/dist/internal/oauth/connected-reference.mjs.map +1 -0
  55. package/dist/internal/oauth/connected-settlement.d.mts +8 -0
  56. package/dist/internal/oauth/connected-settlement.mjs +141 -0
  57. package/dist/internal/oauth/connected-settlement.mjs.map +1 -0
  58. package/dist/internal/oauth/connected-sign-in.d.mts +10 -0
  59. package/dist/internal/oauth/connected-sign-in.mjs +281 -0
  60. package/dist/internal/oauth/connected-sign-in.mjs.map +1 -0
  61. package/dist/internal/oauth/connected-state.d.mts +14 -0
  62. package/dist/internal/oauth/connected-state.mjs +469 -0
  63. package/dist/internal/oauth/connected-state.mjs.map +1 -0
  64. package/dist/internal/oauth/connected-target.d.mts +21 -0
  65. package/dist/internal/oauth/connected-target.mjs +117 -0
  66. package/dist/internal/oauth/connected-target.mjs.map +1 -0
  67. package/dist/internal/oauth/flow.d.mts +5 -0
  68. package/dist/internal/oauth/flow.mjs +279 -0
  69. package/dist/internal/oauth/flow.mjs.map +1 -0
  70. package/dist/internal/oauth/input.mjs +127 -0
  71. package/dist/internal/oauth/input.mjs.map +1 -0
  72. package/dist/internal/oauth/owner.d.mts +10 -0
  73. package/dist/internal/oauth/owner.mjs +10 -0
  74. package/dist/internal/oauth/owner.mjs.map +1 -0
  75. package/dist/internal/oauth/query-compiler.d.mts +7 -0
  76. package/dist/internal/oauth/query-compiler.mjs +9 -0
  77. package/dist/internal/oauth/query-compiler.mjs.map +1 -0
  78. package/dist/internal/oauth/registration.d.mts +7 -0
  79. package/dist/internal/oauth/registration.mjs +393 -0
  80. package/dist/internal/oauth/registration.mjs.map +1 -0
  81. package/dist/internal/oauth/state.mjs +107 -0
  82. package/dist/internal/oauth/state.mjs.map +1 -0
  83. package/dist/internal/oauth/target.d.mts +31 -0
  84. package/dist/internal/oauth/target.mjs +273 -0
  85. package/dist/internal/oauth/target.mjs.map +1 -0
  86. package/dist/internal/oauth-kernel.d.mts +1423 -0
  87. package/dist/internal/oauth-kernel.mjs +187 -0
  88. package/dist/internal/oauth-kernel.mjs.map +1 -0
  89. package/dist/internal/oauth-proxy.d.mts +31 -0
  90. package/dist/internal/oauth-proxy.mjs +129 -0
  91. package/dist/internal/oauth-proxy.mjs.map +1 -0
  92. package/dist/internal/passkey/write-state.mjs +9 -1
  93. package/dist/internal/passkey/write-state.mjs.map +1 -1
  94. package/dist/internal/passkey-kernel.d.mts +9 -9
  95. package/dist/internal/{password-attempts.d.mts → password-credentials.d.mts} +3 -4
  96. package/dist/internal/password-credentials.mjs +121 -0
  97. package/dist/internal/password-credentials.mjs.map +1 -0
  98. package/dist/internal/password-kernel.d.mts +8 -24
  99. package/dist/internal/password-kernel.mjs +5 -43
  100. package/dist/internal/password-kernel.mjs.map +1 -1
  101. package/dist/internal/persistence.d.mts +1 -1
  102. package/dist/internal/persistence.mjs +2 -2
  103. package/dist/internal/persistence.mjs.map +1 -1
  104. package/dist/internal/query-operations.d.mts +2 -0
  105. package/dist/internal/session-kernel.d.mts +2 -2
  106. package/dist/internal/session-kernel.mjs +74 -18
  107. package/dist/internal/session-kernel.mjs.map +1 -1
  108. package/dist/internal/sql-oauth-connected-model.d.mts +29 -0
  109. package/dist/internal/sql-oauth-connected-model.mjs +7 -0
  110. package/dist/internal/sql-oauth-connected-model.mjs.map +1 -0
  111. package/dist/internal/sql-oauth-model.d.mts +60 -0
  112. package/dist/internal/sql-oauth-model.mjs +10 -0
  113. package/dist/internal/sql-oauth-model.mjs.map +1 -0
  114. package/dist/internal/sql-query.d.mts +12 -0
  115. package/dist/internal/sql-query.mjs +15 -18
  116. package/dist/internal/sql-query.mjs.map +1 -1
  117. package/dist/internal/sql-storage-validation.mjs +54 -0
  118. package/dist/internal/sql-storage-validation.mjs.map +1 -0
  119. package/dist/internal/storage-mapping.mjs +1 -37
  120. package/dist/internal/storage-mapping.mjs.map +1 -1
  121. package/dist/internal/storage-plans.d.mts +7 -0
  122. package/dist/internal/storage-plans.mjs +189 -0
  123. package/dist/internal/storage-plans.mjs.map +1 -0
  124. package/dist/internal/storage-tables.d.mts +0 -56
  125. package/dist/internal/storage-tables.mjs +0 -17
  126. package/dist/internal/storage-tables.mjs.map +1 -1
  127. package/dist/internal/storage-validation.d.mts +6 -1
  128. package/dist/internal/storage-validation.mjs +42 -1
  129. package/dist/internal/storage-validation.mjs.map +1 -1
  130. package/dist/internal/transaction-kernel.mjs +3 -2
  131. package/dist/internal/transaction-kernel.mjs.map +1 -1
  132. package/package.json +1 -1
  133. package/src/Adapter.ts +89 -5
  134. package/src/OAuthPersistence.ts +427 -0
  135. package/src/index.ts +3 -0
  136. package/src/internal/configuration.ts +1 -3
  137. package/src/internal/email-kernel.ts +2 -1
  138. package/src/internal/models/oauth-connected-model.ts +396 -0
  139. package/src/internal/models/oauth-model.ts +708 -0
  140. package/src/internal/models/password-model.ts +2 -57
  141. package/src/internal/native-sql-table.ts +14 -0
  142. package/src/internal/oauth/accounts.ts +839 -0
  143. package/src/internal/oauth/connected-access.ts +388 -0
  144. package/src/internal/oauth/connected-collection.ts +345 -0
  145. package/src/internal/oauth/connected-custody.ts +308 -0
  146. package/src/internal/oauth/connected-flow.ts +562 -0
  147. package/src/internal/oauth/connected-input.ts +147 -0
  148. package/src/internal/oauth/connected-keys.ts +31 -0
  149. package/src/internal/oauth/connected-maintenance.ts +379 -0
  150. package/src/internal/oauth/connected-management.ts +391 -0
  151. package/src/internal/oauth/connected-reference.ts +135 -0
  152. package/src/internal/oauth/connected-settlement.ts +278 -0
  153. package/src/internal/oauth/connected-sign-in.ts +472 -0
  154. package/src/internal/oauth/connected-state.ts +924 -0
  155. package/src/internal/oauth/connected-target.ts +307 -0
  156. package/src/internal/oauth/flow.ts +505 -0
  157. package/src/internal/oauth/input.ts +201 -0
  158. package/src/internal/oauth/owner.ts +22 -0
  159. package/src/internal/oauth/query-compiler.ts +15 -0
  160. package/src/internal/oauth/registration.ts +676 -0
  161. package/src/internal/oauth/state.ts +218 -0
  162. package/src/internal/oauth/target.ts +803 -0
  163. package/src/internal/oauth-kernel.ts +294 -0
  164. package/src/internal/oauth-proxy.ts +176 -0
  165. package/src/internal/passkey/write-state.ts +18 -4
  166. package/src/internal/password-credentials.ts +245 -0
  167. package/src/internal/password-kernel.ts +7 -99
  168. package/src/internal/persistence.ts +1 -1
  169. package/src/internal/query-operations.ts +2 -0
  170. package/src/internal/session-kernel.ts +143 -55
  171. package/src/internal/sql-oauth-connected-model.ts +145 -0
  172. package/src/internal/sql-oauth-model.ts +263 -0
  173. package/src/internal/sql-query.ts +16 -13
  174. package/src/internal/sql-storage-validation.ts +64 -0
  175. package/src/internal/storage-mapping.ts +0 -37
  176. package/src/internal/storage-plans.ts +218 -0
  177. package/src/internal/storage-tables.ts +0 -20
  178. package/src/internal/storage-validation.ts +58 -0
  179. package/src/internal/transaction-kernel.ts +6 -2
  180. package/dist/internal/password-attempts.mjs +0 -197
  181. package/dist/internal/password-attempts.mjs.map +0 -1
  182. package/src/internal/password-attempts.ts +0 -466
@@ -0,0 +1,243 @@
1
+ import { digest } from "../crypto.mjs";
2
+ import { CurrentOAuthTransaction } from "./owner.mjs";
3
+ import { OAuthQueryCompiler } from "./query-compiler.mjs";
4
+ import { invariant } from "./state.mjs";
5
+ import { OAuthConnectedState } from "./connected-state.mjs";
6
+ import { OAuthConnectedCustody } from "./connected-custody.mjs";
7
+ import { OAuthConnectedFlow } from "./connected-flow.mjs";
8
+ import { OAuthConnectedAccess } from "./connected-access.mjs";
9
+ import { Context, Effect, Layer } from "effect";
10
+ import * as M from "@yielded/auth/OAuth";
11
+ import { snapshotOAuthSync } from "@yielded/auth/OAuth";
12
+ //#region src/internal/oauth/connected-management.ts
13
+ const make = Effect.gen(function* () {
14
+ const operations = yield* OAuthQueryCompiler;
15
+ const A = yield* OAuthConnectedAccess;
16
+ const C = yield* OAuthConnectedCustody;
17
+ const F = yield* OAuthConnectedFlow;
18
+ const S = yield* OAuthConnectedState;
19
+ const { asc, eq, gt, lte } = operations;
20
+ const { both, col, equal } = operations;
21
+ const list = Effect.fn("oauthConnected.list")(function* (mapping, input) {
22
+ const owner = yield* CurrentOAuthTransaction;
23
+ const found = yield* S.useAuthority(mapping, input.authorization, "metadata");
24
+ if (found === void 0) return { items: [] };
25
+ invariant(Number.isSafeInteger(input.limit) && input.limit >= 1 && input.limit <= 100);
26
+ const g = mapping.grant, h = mapping.cohort, j = S.jobTable(mapping);
27
+ const cursor = input.cursor === void 0 ? void 0 : M.OAuthGrantId.make(input.cursor);
28
+ const where = both(equal(g.table, {
29
+ [g.moduleId]: input.authorization.moduleId,
30
+ [g.subjectId]: found.nativeId
31
+ }), cursor === void 0 ? void 0 : gt(col(g.table, g.grantId), cursor), input.authorization.grantId === void 0 ? void 0 : eq(col(g.table, g.grantId), input.authorization.grantId), input.authorization.profileKey === void 0 ? void 0 : eq(col(g.table, g.profileKey), input.authorization.profileKey));
32
+ const columns = [
33
+ g.moduleId,
34
+ g.grantId,
35
+ g.subjectId,
36
+ g.identityKey,
37
+ g.clientKey,
38
+ g.cohortKey,
39
+ g.cohortGeneration,
40
+ g.profileKey,
41
+ g.state,
42
+ g.summary,
43
+ g.revocationJobId,
44
+ g.version
45
+ ];
46
+ const read = yield* owner.read(g.table, where, {
47
+ columns,
48
+ limit: input.limit + 1,
49
+ takeOnly: true,
50
+ observe: false,
51
+ lock: false,
52
+ orderBy: asc(col(g.table, g.grantId))
53
+ });
54
+ const more = read.rows.length > input.limit, rows = read.rows.slice(0, input.limit), last = rows.at(-1)?.[g.grantId];
55
+ owner.observations.push({
56
+ table: g.table,
57
+ where: more ? both(where, lte(col(g.table, g.grantId), last)) : where,
58
+ rows
59
+ });
60
+ const items = [];
61
+ for (const row of rows) {
62
+ const summary = S.summaryStorage.decode(row[g.summary]);
63
+ invariant(summary.grantId === row[g.grantId] && summary.profileKey === row[g.profileKey] && mapping.subjectId.equals(found.nativeId, row[g.subjectId]));
64
+ const cr = (yield* owner.read(h.table, equal(h.table, { [h.cohortKey]: row[g.cohortKey] }), {
65
+ limit: 1,
66
+ lock: false
67
+ })).rows[0];
68
+ invariant(cr !== void 0 && cr[h.clientKey] === row[g.clientKey] && cr[h.identityKey] === row[g.identityKey]);
69
+ let status = row[g.state];
70
+ if (status !== "Disconnected" && (cr[h.state] !== "Open" || cr[h.generation] !== row[g.cohortGeneration])) status = "ReauthorizationRequired";
71
+ let remote = summary.remoteRevocation;
72
+ if (row[g.revocationJobId] !== null) {
73
+ if (j === void 0) remote = "Unknown";
74
+ else {
75
+ const jr = (yield* owner.read(j.table, equal(j.table, { [j.jobId]: row[g.revocationJobId] }), {
76
+ limit: 1,
77
+ lock: false,
78
+ columns: [
79
+ j.jobId,
80
+ j.moduleId,
81
+ j.grantId,
82
+ j.cohortKey,
83
+ j.state
84
+ ]
85
+ })).rows[0];
86
+ invariant(jr !== void 0 && jr[j.moduleId] === row[g.moduleId] && jr[j.grantId] === row[g.grantId] && jr[j.cohortKey] === row[g.cohortKey]);
87
+ remote = jr[j.state] === "Confirmed" ? "Confirmed" : jr[j.state] === "Unknown" ? "Unknown" : "Pending";
88
+ }
89
+ }
90
+ items.push(snapshotOAuthSync(M.OAuthConnectedSummary, {
91
+ ...summary,
92
+ status,
93
+ remoteRevocation: remote
94
+ }));
95
+ }
96
+ return {
97
+ items,
98
+ ...more ? { cursor: last } : {}
99
+ };
100
+ });
101
+ const command = Effect.fn("oauthConnected.disconnectCommand")(function* (mapping, moduleId, commandId, lock = true) {
102
+ const owner = yield* CurrentOAuthTransaction;
103
+ const d = mapping.command, read = yield* owner.read(d.table, equal(d.table, {
104
+ [d.moduleId]: moduleId,
105
+ [d.commandId]: commandId
106
+ }), {
107
+ limit: 1,
108
+ lock,
109
+ observe: lock
110
+ });
111
+ const row = read.rows[0];
112
+ if (row === void 0) return { read };
113
+ const grant = S.commandStorage.decode(row[d.intent]), result = S.disconnectedStorage.decode(row[d.decision]);
114
+ const native = yield* mapping.subjectId.toNative(grant.context.subjectId);
115
+ invariant(grant.context.moduleId === moduleId && grant.context.grantId === row[d.grantId] && result.grantId === grant.context.grantId && mapping.subjectId.equals(native, row[d.subjectId]) && !result.replayed);
116
+ return {
117
+ read,
118
+ row,
119
+ grant,
120
+ result
121
+ };
122
+ });
123
+ return {
124
+ list,
125
+ inspectDisconnect: Effect.fn("oauthConnected.inspectDisconnect")(function* (mapping, input) {
126
+ const found = yield* S.useAuthority(mapping, input.authorization, "metadata");
127
+ if (found === void 0 || input.subjectId !== found.revision.subjectId || input.moduleId !== input.authorization.moduleId) return { _tag: "Rejected" };
128
+ const discovered = yield* command(mapping, input.moduleId, input.commandId, false);
129
+ if (discovered.row !== void 0) {
130
+ if (discovered.grant.context.subjectId !== input.subjectId || discovered.grant.context.grantId !== input.grantId) return { _tag: "Conflict" };
131
+ if ((yield* S.useAuthority(mapping, input.authorization, "metadata", discovered.grant.context)) === void 0) return { _tag: "Rejected" };
132
+ const prior = yield* command(mapping, input.moduleId, input.commandId);
133
+ const d = mapping.command;
134
+ if (prior.row === void 0 || prior.row[d.intent] !== discovered.row[d.intent] || prior.row[d.decision] !== discovered.row[d.decision] || prior.row[d.version] !== discovered.row[d.version]) return { _tag: "Rejected" };
135
+ return {
136
+ _tag: "Replay",
137
+ result: {
138
+ ...prior.result,
139
+ replayed: true
140
+ }
141
+ };
142
+ }
143
+ const read = yield* A.locked(mapping, input.authorization, input.grantId, "metadata");
144
+ if (read === void 0) return { _tag: "Rejected" };
145
+ if ((yield* command(mapping, input.moduleId, input.commandId)).row !== void 0) return { _tag: "Rejected" };
146
+ return {
147
+ _tag: "Target",
148
+ grant: {
149
+ context: read.grant.context,
150
+ ...read.grant.sealed === void 0 ? {} : { sealed: read.grant.sealed }
151
+ },
152
+ revision: read.found.revision
153
+ };
154
+ }),
155
+ disconnect: Effect.fn("oauthConnected.disconnect")(function* (mapping, input) {
156
+ const owner = yield* CurrentOAuthTransaction;
157
+ const token = input.grant.context, found = yield* S.current(mapping, token.subjectId);
158
+ if (found === void 0 || input.moduleId !== token.moduleId || !(yield* S.action(mapping, found, input.authorization, "disconnect", {
159
+ moduleId: input.moduleId,
160
+ flowId: input.commandId,
161
+ commandId: input.commandId,
162
+ revision: input.authorization.challenge.revision,
163
+ intent: S.disconnectStorage.encode(input.grant),
164
+ maximumAgeMillis: 3e5,
165
+ configuration: token.configuration,
166
+ grant: token
167
+ }))) return { _tag: "Rejected" };
168
+ const client = yield* S.client(mapping, token.configuration, false);
169
+ if (client === void 0) return { _tag: "Rejected" };
170
+ const tuple = yield* F.inspectTuple(mapping, token.identity), t = mapping.ownership.tuple;
171
+ if (tuple.row?.[t.state] !== "Owned" || !mapping.subjectId.equals(tuple.row[t.subjectId], found.nativeId)) return { _tag: "Conflict" };
172
+ const cohort = yield* S.cohort(mapping, client.id, tuple.key, false);
173
+ invariant(cohort.row !== void 0);
174
+ const read = yield* S.readGrant(mapping, input.moduleId, token.grantId), g = mapping.grant;
175
+ if (read === void 0 || !C.sameContext(read.context, token) || S.disconnectStorage.encode({
176
+ context: read.context,
177
+ ...read.sealed === void 0 ? {} : { sealed: read.sealed }
178
+ }) !== S.disconnectStorage.encode(input.grant)) return { _tag: "Conflict" };
179
+ const prior = yield* command(mapping, input.moduleId, input.commandId);
180
+ if (prior.row !== void 0) return { _tag: "Conflict" };
181
+ const now = yield* owner.now(mapping.clock), wasOpen = !cohort.blocked;
182
+ invariant(input.retentionUntilMillis >= now && input.retentionUntilMillis <= now + 2592e6);
183
+ const affected = yield* C.fence(mapping, client, cohort);
184
+ let remote = "Unsupported";
185
+ if (input.revocation !== void 0) {
186
+ yield* C.storeJob(mapping, input.revocation, token, found.nativeId, now);
187
+ remote = "Pending";
188
+ } else if (token.configuration.profile.revocation === "cohort") {
189
+ invariant(read.sealed === void 0);
190
+ remote = "Unknown";
191
+ }
192
+ const result = snapshotOAuthSync(M.OAuthConnectedDisconnected, {
193
+ _tag: "Disconnected",
194
+ grantId: token.grantId,
195
+ remoteRevocation: remote,
196
+ affectedGrantCount: affected,
197
+ replayed: false
198
+ });
199
+ yield* owner.update(g.table, {
200
+ [g.moduleId]: input.moduleId,
201
+ [g.grantId]: token.grantId
202
+ }, {
203
+ [g.state]: "Disconnected",
204
+ [g.activeIdentityKey]: null,
205
+ [g.sealed]: null,
206
+ [g.revocationJobId]: input.revocation?.context.jobId ?? read.row[g.revocationJobId],
207
+ [g.version]: owner.marker
208
+ });
209
+ const d = mapping.command, key = {
210
+ [d.moduleId]: input.moduleId,
211
+ [d.commandId]: input.commandId
212
+ };
213
+ const inserted = yield* owner.insert(d.table, {
214
+ ...d.encodeInsert({
215
+ commandId: input.commandId,
216
+ grant: snapshotOAuthSync(M.OAuthConnectedDisconnectGrant, input.grant),
217
+ subjectId: S.nativeCopy(found.nativeId)
218
+ }),
219
+ ...key,
220
+ [d.subjectId]: found.nativeId,
221
+ [d.grantId]: token.grantId,
222
+ [d.intent]: S.commandStorage.encode({
223
+ context: token,
224
+ originalDigest: yield* digest(S.disconnectStorage.encode(input.grant)),
225
+ ...input.revocation === void 0 ? {} : { revocationJobId: input.revocation.context.jobId }
226
+ }),
227
+ [d.decision]: S.disconnectedStorage.encode(result),
228
+ [d.retentionUntil]: mapping.clock.encodeInstant(input.retentionUntilMillis),
229
+ [d.version]: owner.marker
230
+ }, key);
231
+ prior.read.rows = inserted.rows;
232
+ if (wasOpen && input.revocation === void 0 && token.configuration.profile.revocation === "unsupported") yield* C.clear(mapping, client, cohort, void 0, true);
233
+ return result;
234
+ })
235
+ };
236
+ });
237
+ var OAuthConnectedManagement = class OAuthConnectedManagement extends Context.Service()("effect-auth/persistence/OAuthConnectedManagement") {
238
+ static layer = Layer.effect(OAuthConnectedManagement, make);
239
+ };
240
+ //#endregion
241
+ export { OAuthConnectedManagement };
242
+
243
+ //# sourceMappingURL=connected-management.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connected-management.mjs","names":[],"sources":["../../../src/internal/oauth/connected-management.ts"],"sourcesContent":["import * as M from \"@yielded/auth/OAuth\";\nimport { snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport { Effect, Context, Layer } from \"effect\";\n\nimport { OAuthConnectedAccess } from \"./connected-access\";\nimport { OAuthConnectedCustody } from \"./connected-custody\";\nimport { OAuthConnectedFlow } from \"./connected-flow\";\nimport type * as FTypes from \"./connected-flow\";\nimport { OAuthConnectedState } from \"./connected-state\";\nimport type * as STypes from \"./connected-state\";\nimport { CurrentOAuthTransaction } from \"./owner\";\nimport { OAuthQueryCompiler } from \"./query-compiler\";\nimport { digest, invariant } from \"./state\";\n\nconst make = Effect.gen(function* () {\n const operations = yield* OAuthQueryCompiler;\n const A = yield* OAuthConnectedAccess;\n const C = yield* OAuthConnectedCustody;\n const F = yield* OAuthConnectedFlow;\n const S = yield* OAuthConnectedState;\n\n const { asc, eq, gt, lte } = operations;\n const { both, col, equal } = operations;\n\n const list = Effect.fn(\"oauthConnected.list\")(function* (\n mapping: STypes.Mapping,\n input: FTypes.Input<\"list\">,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n const found = yield* S.useAuthority(mapping, input.authorization, \"metadata\");\n\n if (found === undefined) return { items: [] };\n invariant(Number.isSafeInteger(input.limit) && input.limit >= 1 && input.limit <= 100);\n\n const g = mapping.grant,\n h = mapping.cohort,\n j = S.jobTable(mapping);\n\n const cursor = input.cursor === undefined ? undefined : M.OAuthGrantId.make(input.cursor);\n\n const where = both(\n equal(g.table, { [g.moduleId]: input.authorization.moduleId, [g.subjectId]: found.nativeId }),\n cursor === undefined ? undefined : gt(col(g.table, g.grantId), cursor),\n input.authorization.grantId === undefined\n ? undefined\n : eq(col(g.table, g.grantId), input.authorization.grantId),\n input.authorization.profileKey === undefined\n ? undefined\n : eq(col(g.table, g.profileKey), input.authorization.profileKey),\n );\n\n const columns = [\n g.moduleId,\n g.grantId,\n g.subjectId,\n g.identityKey,\n g.clientKey,\n g.cohortKey,\n g.cohortGeneration,\n g.profileKey,\n g.state,\n g.summary,\n g.revocationJobId,\n g.version,\n ];\n\n const read = yield* owner.read(g.table, where, {\n columns,\n limit: input.limit + 1,\n takeOnly: true,\n observe: false,\n lock: false,\n orderBy: asc(col(g.table, g.grantId)),\n });\n\n const more = read.rows.length > input.limit,\n rows = read.rows.slice(0, input.limit),\n last = rows.at(-1)?.[g.grantId];\n\n owner.observations.push({\n table: g.table,\n where: more ? both(where, lte(col(g.table, g.grantId), last)) : where,\n rows,\n });\n const items: Array<typeof M.OAuthConnectedSummary.Type> = [];\n\n for (const row of rows) {\n const summary = S.summaryStorage.decode(row[g.summary]);\n\n invariant(\n summary.grantId === row[g.grantId] &&\n summary.profileKey === row[g.profileKey] &&\n mapping.subjectId.equals(found.nativeId, row[g.subjectId]),\n );\n\n const co = yield* owner.read(h.table, equal(h.table, { [h.cohortKey]: row[g.cohortKey] }), {\n limit: 1,\n lock: false,\n });\n\n const cr = co.rows[0];\n\n invariant(\n cr !== undefined &&\n cr[h.clientKey] === row[g.clientKey] &&\n cr[h.identityKey] === row[g.identityKey],\n );\n let status = row[g.state] as (typeof M.OAuthConnectedSummary.Type)[\"status\"];\n\n if (\n status !== \"Disconnected\" &&\n (cr[h.state] !== \"Open\" || cr[h.generation] !== row[g.cohortGeneration])\n )\n status = \"ReauthorizationRequired\";\n let remote = summary.remoteRevocation;\n\n if (row[g.revocationJobId] !== null) {\n if (j === undefined) remote = \"Unknown\";\n else {\n const job = yield* owner.read(\n j.table,\n equal(j.table, { [j.jobId]: row[g.revocationJobId] }),\n {\n limit: 1,\n lock: false,\n columns: [j.jobId, j.moduleId, j.grantId, j.cohortKey, j.state],\n },\n );\n\n const jr = job.rows[0];\n\n invariant(\n jr !== undefined &&\n jr[j.moduleId] === row[g.moduleId] &&\n jr[j.grantId] === row[g.grantId] &&\n jr[j.cohortKey] === row[g.cohortKey],\n );\n remote =\n jr[j.state] === \"Confirmed\"\n ? \"Confirmed\"\n : jr[j.state] === \"Unknown\"\n ? \"Unknown\"\n : \"Pending\";\n }\n }\n items.push(\n snapshotOAuthSync(M.OAuthConnectedSummary, {\n ...summary,\n status,\n remoteRevocation: remote,\n }),\n );\n }\n\n return { items, ...(more ? { cursor: last as string } : {}) };\n });\n\n const command = Effect.fn(\"oauthConnected.disconnectCommand\")(function* (\n mapping: STypes.Mapping,\n moduleId: string,\n commandId: string,\n lock = true,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const d = mapping.command,\n read = yield* owner.read(\n d.table,\n equal(d.table, { [d.moduleId]: moduleId, [d.commandId]: commandId }),\n { limit: 1, lock, observe: lock },\n );\n\n const row = read.rows[0];\n\n if (row === undefined) return { read };\n\n const grant = S.commandStorage.decode(row[d.intent]),\n result = S.disconnectedStorage.decode(row[d.decision]);\n\n const native = yield* mapping.subjectId.toNative(grant.context.subjectId);\n\n invariant(\n grant.context.moduleId === moduleId &&\n grant.context.grantId === row[d.grantId] &&\n result.grantId === grant.context.grantId &&\n mapping.subjectId.equals(native, row[d.subjectId]) &&\n !result.replayed,\n );\n\n return { read, row, grant, result };\n });\n\n const inspectDisconnect = Effect.fn(\"oauthConnected.inspectDisconnect\")(function* (\n mapping: STypes.Mapping,\n input: FTypes.Input<\"inspectDisconnect\">,\n ) {\n const found = yield* S.useAuthority(mapping, input.authorization, \"metadata\");\n\n if (\n found === undefined ||\n input.subjectId !== found.revision.subjectId ||\n input.moduleId !== input.authorization.moduleId\n )\n return { _tag: \"Rejected\" } as const;\n const discovered = yield* command(mapping, input.moduleId, input.commandId, false);\n\n if (discovered.row !== undefined) {\n if (\n discovered.grant.context.subjectId !== input.subjectId ||\n discovered.grant.context.grantId !== input.grantId\n )\n return { _tag: \"Conflict\" } as const;\n if (\n (yield* S.useAuthority(\n mapping,\n input.authorization,\n \"metadata\",\n discovered.grant.context,\n )) === undefined\n )\n return { _tag: \"Rejected\" } as const;\n const prior = yield* command(mapping, input.moduleId, input.commandId);\n const d = mapping.command;\n\n if (\n prior.row === undefined ||\n prior.row[d.intent] !== discovered.row[d.intent] ||\n prior.row[d.decision] !== discovered.row[d.decision] ||\n prior.row[d.version] !== discovered.row[d.version]\n )\n return { _tag: \"Rejected\" } as const;\n\n return { _tag: \"Replay\", result: { ...prior.result, replayed: true } } as const;\n }\n const read = yield* A.locked(mapping, input.authorization, input.grantId, \"metadata\");\n\n if (read === undefined) return { _tag: \"Rejected\" } as const;\n const finalCommand = yield* command(mapping, input.moduleId, input.commandId);\n\n if (finalCommand.row !== undefined) return { _tag: \"Rejected\" } as const;\n\n return {\n _tag: \"Target\",\n grant: {\n context: read.grant.context,\n ...(read.grant.sealed === undefined ? {} : { sealed: read.grant.sealed }),\n },\n revision: read.found.revision,\n } as const;\n });\n\n const disconnect = Effect.fn(\"oauthConnected.disconnect\")(function* (\n mapping: STypes.Mapping,\n input: FTypes.Input<\"disconnect\">,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const token = input.grant.context,\n found = yield* S.current(mapping, token.subjectId);\n\n if (\n found === undefined ||\n input.moduleId !== token.moduleId ||\n !(yield* S.action(mapping, found, input.authorization, \"disconnect\", {\n moduleId: input.moduleId,\n flowId: input.commandId,\n commandId: input.commandId,\n revision: input.authorization.challenge.revision,\n intent: S.disconnectStorage.encode(input.grant),\n maximumAgeMillis: 300000,\n configuration: token.configuration,\n grant: token,\n }))\n )\n return { _tag: \"Rejected\" } as const;\n const client = yield* S.client(mapping, token.configuration, false);\n\n if (client === undefined) return { _tag: \"Rejected\" } as const;\n\n const tuple = yield* F.inspectTuple(mapping, token.identity),\n t = mapping.ownership.tuple;\n\n if (\n tuple.row?.[t.state] !== \"Owned\" ||\n !mapping.subjectId.equals(tuple.row[t.subjectId], found.nativeId)\n )\n return { _tag: \"Conflict\" } as const;\n const cohort = yield* S.cohort(mapping, client.id, tuple.key, false);\n\n invariant(cohort.row !== undefined);\n\n const read = yield* S.readGrant(mapping, input.moduleId, token.grantId),\n g = mapping.grant;\n\n if (\n read === undefined ||\n !C.sameContext(read.context, token) ||\n S.disconnectStorage.encode({\n context: read.context,\n ...(read.sealed === undefined ? {} : { sealed: read.sealed }),\n }) !== S.disconnectStorage.encode(input.grant)\n )\n return { _tag: \"Conflict\" } as const;\n const prior = yield* command(mapping, input.moduleId, input.commandId);\n\n // Only inspectDisconnect exposes replay. Mutation replay cannot repeat effects.\n if (prior.row !== undefined) return { _tag: \"Conflict\" } as const;\n\n const now = yield* owner.now(mapping.clock),\n wasOpen = !cohort.blocked;\n\n invariant(input.retentionUntilMillis >= now && input.retentionUntilMillis <= now + 2592000000);\n const affected = yield* C.fence(mapping, client, cohort);\n let remote: (typeof M.OAuthConnectedSummary.Type)[\"remoteRevocation\"] = \"Unsupported\";\n\n if (input.revocation !== undefined) {\n yield* C.storeJob(mapping, input.revocation, token, found.nativeId, now);\n remote = \"Pending\";\n } else if (token.configuration.profile.revocation === \"cohort\") {\n invariant(read.sealed === undefined);\n remote = \"Unknown\";\n }\n\n const result = snapshotOAuthSync(M.OAuthConnectedDisconnected, {\n _tag: \"Disconnected\",\n grantId: token.grantId,\n remoteRevocation: remote,\n affectedGrantCount: affected,\n replayed: false,\n });\n\n yield* owner.update(\n g.table,\n { [g.moduleId]: input.moduleId, [g.grantId]: token.grantId },\n {\n [g.state]: \"Disconnected\",\n [g.activeIdentityKey]: null,\n [g.sealed]: null,\n [g.revocationJobId]: input.revocation?.context.jobId ?? read.row[g.revocationJobId],\n [g.version]: owner.marker,\n },\n );\n\n const d = mapping.command,\n key = { [d.moduleId]: input.moduleId, [d.commandId]: input.commandId };\n\n const inserted = yield* owner.insert(\n d.table,\n {\n ...d.encodeInsert({\n commandId: input.commandId,\n grant: snapshotOAuthSync(M.OAuthConnectedDisconnectGrant, input.grant),\n subjectId: S.nativeCopy(found.nativeId),\n }),\n ...key,\n [d.subjectId]: found.nativeId,\n [d.grantId]: token.grantId,\n [d.intent]: S.commandStorage.encode({\n context: token,\n originalDigest: yield* digest(S.disconnectStorage.encode(input.grant)),\n ...(input.revocation === undefined\n ? {}\n : { revocationJobId: input.revocation.context.jobId }),\n }),\n [d.decision]: S.disconnectedStorage.encode(result),\n [d.retentionUntil]: mapping.clock.encodeInstant(input.retentionUntilMillis),\n [d.version]: owner.marker,\n },\n key,\n );\n\n prior.read.rows = inserted.rows;\n if (\n wasOpen &&\n input.revocation === undefined &&\n token.configuration.profile.revocation === \"unsupported\"\n )\n yield* C.clear(mapping, client, cohort, undefined, true);\n\n return result;\n });\n\n return { list, inspectDisconnect, disconnect };\n});\n\nexport class OAuthConnectedManagement extends Context.Service<\n OAuthConnectedManagement,\n Effect.Success<typeof make>\n>()(\"effect-auth/persistence/OAuthConnectedManagement\") {\n static readonly layer = Layer.effect(OAuthConnectedManagement, make);\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,OAAO,OAAO,IAAI,aAAa;CACnC,MAAM,aAAa,OAAO;CAC1B,MAAM,IAAI,OAAO;CACjB,MAAM,IAAI,OAAO;CACjB,MAAM,IAAI,OAAO;CACjB,MAAM,IAAI,OAAO;CAEjB,MAAM,EAAE,KAAK,IAA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AEvE,MAAM,WAAW,OAAO,MAAM,OAC5B,EAAE,OACF;IACE,GAAG,EAAE,aAAa;KAChB,WAAW,MAAM;KACjB,OAAO,kBAAkB,EAAE,+BAA+B,MAAM,KAAK;KACrE,WAAW,EAAE,WAAW,MAAM,QAAQ;IACxC,CAAC;IACD,GAAG;KACF,EAAE,YAAY,MAAM;KACpB,EAAE,UAAU,MAAM;KAClB,EAAE,SAAS,EAAE,eAAe,OAAO;KAClC,SAAS;KACT,gBAAgB,OAAO,OAAO,EAAE,kBAAkB,OAAO,MAAM,KAAK,CAAC;KACrE,GAAI,MAAM,eAAe,KAAA,IACrB,CAAC,IACD,EAAE,iBAAiB,MAAM,WAAW,QAAQ,MAAM;IACxD,CAAC;KACA,EAAE,WAAW,EAAE,oBAAoB,OAAO,MAAM;KAChD,EAAE,iBAAiB,QAAQ,MAAM,cAAc,MAAM,oBAAoB;KACzE,EAAE,UAAU,MAAM;GACrB,GACA,GACF;GAEA,MAAM,KAAK,OAAO,SAAS;GAC3B,IACE,WACA,MAAM,eAAe,KAAA,KACrB,MAAM,cAAc,QAAQ,eAAe,eAE3C,OAAO,EAAE,MAAM,SAAS,QAAQ,QAAQ,KAAA,GAAW,IAAI;GAEzD,OAAO;EACT,CAE2C;CAAE;AAC/C,CAAC;AAED,IAAa,2BAAb,MAAa,iCAAiC,QAAQ,QAGpD,CAAC,CAAC,kDAAkD,CAAC,CAAC;CACtD,OAAgB,QAAQ,MAAM,OAAO,0BAA0B,IAAI;AACrE"}
@@ -0,0 +1,63 @@
1
+ import { makeTransactionKernel } from "../transaction-kernel.mjs";
2
+ import { captureOAuthMapping, unavailable } from "./state.mjs";
3
+ import { scopeKey } from "./connected-keys.mjs";
4
+ import { oauthReferenceGuardTable } from "../models/oauth-model.mjs";
5
+ import { Effect } from "effect";
6
+ //#region src/internal/oauth/connected-reference.ts
7
+ const makeOAuthConnectedReferenceKernel = (operations, dialect) => {
8
+ const { eq, sql } = operations;
9
+ const transactions = makeTransactionKernel(operations);
10
+ const { both } = transactions;
11
+ const { col, equal } = transactions.makeTransactionRows(unavailable);
12
+ const exactText = (table, key, value) => {
13
+ const column = col(table, key), bound = sql.param(value, column);
14
+ return dialect(table) === "mysql" ? sql`binary ${column} = binary ${bound}` : dialect(table) === "pg" ? sql`convert_to(cast(${column} as text),'UTF8') = convert_to(cast(${bound} as text),'UTF8')` : sql`cast(${column} as blob) = cast(${bound} as blob)`;
15
+ };
16
+ /** Compose Accounts.Unlink with this connected authority. The stable scope lock
17
+ * serializes unknown claims across every client registration for an issuer. */
18
+ const oauthConnectedOwnershipReferences = (original) => {
19
+ const mapping = captureOAuthMapping(original), c = mapping.client;
20
+ return Object.freeze({
21
+ connectedReferenceGuards: [oauthReferenceGuardTable({
22
+ table: c.table,
23
+ orderBy: c.clientKey,
24
+ condition: (input) => Effect.gen(function* () {
25
+ const key = yield* scopeKey(input.identity.provider, input.identity.issuer);
26
+ return both(equal(c.table, {
27
+ [c.clientKey]: key,
28
+ [c.counter]: mapping.order.encode(0)
29
+ }), exactText(c.table, c.provider, input.identity.provider), exactText(c.table, c.issuer, input.identity.issuer), exactText(c.table, c.clientRegistrationId, ""));
30
+ })
31
+ })],
32
+ connectedReference: (input) => connectedReferenceCondition(mapping, input.identityKey)
33
+ });
34
+ };
35
+ const connectedReferenceCondition = (mapping, identityKey, knownIdentity) => {
36
+ const c = mapping.client, t = mapping.ownership.tuple, f = mapping.flow, g = mapping.grant, h = mapping.cohort, a = mapping.admission, j = mapping.revocation.mode === "cohort" ? mapping.revocation.job : void 0;
37
+ const tuple = equal(t.table, { [t.identityKey]: identityKey });
38
+ const knownFlow = sql`exists(select 1 from ${h.table} where ${col(h.table, h.cohortKey)} = ${col(f.table, f.cohortKey)} and ${col(h.table, h.identityKey)} = ${identityKey})`;
39
+ const unknownFlow = knownIdentity === void 0 ? sql`${col(f.table, f.cohortKey)} is null and exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(f.table, f.clientKey)} and exists(select 1 from ${t.table} where ${tuple} and ${col(c.table, c.provider)} = ${col(t.table, t.provider)} and ${col(c.table, c.issuer)} = ${col(t.table, t.issuer)}))` : sql`${col(f.table, f.cohortKey)} is null and exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(f.table, f.clientKey)} and ${col(c.table, c.provider)} = ${knownIdentity.provider} and ${col(c.table, c.issuer)} = ${knownIdentity.issuer})`;
40
+ const related = [
41
+ f,
42
+ g,
43
+ h,
44
+ ...j === void 0 ? [] : [j]
45
+ ];
46
+ return sql`(${sql.join([
47
+ sql`exists(select 1 from ${g.table} where ${eq(col(g.table, g.identityKey), identityKey)})`,
48
+ sql`exists(select 1 from ${a.table} where ${eq(col(a.table, a.identityKey), identityKey)})`,
49
+ sql`exists(select 1 from ${h.table} where ${both(eq(col(h.table, h.identityKey), identityKey), eq(col(h.table, h.state), "Blocked"))})`,
50
+ sql`exists(select 1 from ${f.table} where ${col(f.table, f.work)} = 'Unresolved' and (${knownFlow} or (${unknownFlow})))`,
51
+ ...j === void 0 ? [] : [sql`exists(select 1 from ${j.table} where ${eq(col(j.table, j.identityKey), identityKey)})`],
52
+ ...related.map((v) => sql`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)}))`)
53
+ ], sql` or `)})`;
54
+ };
55
+ return {
56
+ oauthConnectedOwnershipReferences,
57
+ connectedReferenceCondition
58
+ };
59
+ };
60
+ //#endregion
61
+ export { makeOAuthConnectedReferenceKernel };
62
+
63
+ //# sourceMappingURL=connected-reference.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connected-reference.mjs","names":[],"sources":["../../../src/internal/oauth/connected-reference.ts"],"sourcesContent":["import { Effect } from \"effect\";\n\nimport type { OAuthConnectedMapping } from \"../models/oauth-connected-model\";\nimport {\n oauthReferenceGuardTable,\n type OAuthReferenceGuardDescriptor,\n} from \"../models/oauth-model\";\n/* oxlint-disable no-explicit-any -- only adapter SQL expression handles are erased. */\nimport type { SqlExpression as SQL } from \"../query-operations\";\nimport type { QueryOperations } from \"../query-operations\";\nimport type { TableModel } from \"../query-operations\";\nimport { makeTransactionKernel } from \"../transaction-kernel\";\nimport { scopeKey } from \"./connected-keys\";\nimport type { Mapping } from \"./connected-state\";\nimport { unavailable, captureOAuthMapping } from \"./state\";\ntype Table = object;\n\nexport const makeOAuthConnectedReferenceKernel = (\n operations: QueryOperations,\n dialect: (table: object) => \"pg\" | \"sqlite\" | \"mysql\",\n) => {\n const { eq, sql } = operations;\n const transactions = makeTransactionKernel(operations);\n const { both } = transactions;\n const { col, equal } = transactions.makeTransactionRows(unavailable);\n\n const exactText = (table: Table, key: string, value: string) => {\n const column = col(table, key),\n bound = sql.param(value, column);\n\n return dialect(table) === \"mysql\"\n ? sql`binary ${column} = binary ${bound}`\n : dialect(table) === \"pg\"\n ? sql`convert_to(cast(${column} as text),'UTF8') = convert_to(cast(${bound} as text),'UTF8')`\n : sql`cast(${column} as blob) = cast(${bound} as blob)`;\n };\n\n /** Compose Accounts.Unlink with this connected authority. The stable scope lock\n * serializes unknown claims across every client registration for an issuer. */\n const oauthConnectedOwnershipReferences = <\n S extends TableModel,\n AC extends TableModel,\n T extends TableModel,\n O extends TableModel,\n F extends TableModel,\n G extends TableModel,\n C extends TableModel,\n H extends TableModel,\n A extends TableModel,\n D extends TableModel,\n N,\n J extends TableModel,\n >(\n original: OAuthConnectedMapping<S, AC, T, O, F, G, C, H, A, D, N, J, any>,\n ): {\n readonly connectedReferenceGuards: ReadonlyArray<OAuthReferenceGuardDescriptor<N>>;\n readonly connectedReference: (input: {\n readonly identityKey: string;\n readonly subjectId: N;\n }) => SQL;\n } => {\n const mapping = captureOAuthMapping(original),\n c = mapping.client;\n\n return Object.freeze({\n connectedReferenceGuards: [\n oauthReferenceGuardTable<C, N>({\n table: c.table,\n orderBy: c.clientKey,\n condition: (input) =>\n Effect.gen(function* () {\n const key = yield* scopeKey(input.identity.provider, input.identity.issuer);\n\n return both(\n equal(c.table, {\n [c.clientKey]: key,\n [c.counter]: mapping.order.encode(0),\n }),\n exactText(c.table, c.provider, input.identity.provider),\n exactText(c.table, c.issuer, input.identity.issuer),\n exactText(c.table, c.clientRegistrationId, \"\"),\n );\n }),\n }),\n ],\n connectedReference: (input) => connectedReferenceCondition(mapping, input.identityKey),\n });\n };\n\n const connectedReferenceCondition = (\n mapping: Mapping,\n identityKey: string | SQL,\n knownIdentity?: { readonly provider: string | SQL; readonly issuer: string | SQL },\n ) => {\n const c = mapping.client,\n t = mapping.ownership.tuple,\n f = mapping.flow,\n g = mapping.grant,\n h = mapping.cohort,\n a = mapping.admission,\n j = mapping.revocation.mode === \"cohort\" ? mapping.revocation.job : undefined;\n\n const tuple = equal(t.table, { [t.identityKey]: identityKey });\n const knownFlow = sql`exists(select 1 from ${h.table} where ${col(h.table, h.cohortKey)} = ${col(f.table, f.cohortKey)} and ${col(h.table, h.identityKey)} = ${identityKey})`;\n\n const unknownFlow =\n knownIdentity === undefined\n ? sql`${col(f.table, f.cohortKey)} is null and exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(f.table, f.clientKey)} and exists(select 1 from ${t.table} where ${tuple} and ${col(c.table, c.provider)} = ${col(t.table, t.provider)} and ${col(c.table, c.issuer)} = ${col(t.table, t.issuer)}))`\n : sql`${col(f.table, f.cohortKey)} is null and exists(select 1 from ${c.table} where ${col(c.table, c.clientKey)} = ${col(f.table, f.clientKey)} and ${col(c.table, c.provider)} = ${knownIdentity.provider} and ${col(c.table, c.issuer)} = ${knownIdentity.issuer})`;\n\n const related = [f, g, h, ...(j === undefined ? [] : [j])];\n\n return sql`(${sql.join(\n [\n sql`exists(select 1 from ${g.table} where ${eq(col(g.table, g.identityKey), identityKey)})`,\n sql`exists(select 1 from ${a.table} where ${eq(col(a.table, a.identityKey), identityKey)})`,\n sql`exists(select 1 from ${h.table} where ${both(eq(col(h.table, h.identityKey), identityKey), eq(col(h.table, h.state), \"Blocked\"))})`,\n sql`exists(select 1 from ${f.table} where ${col(f.table, f.work)} = 'Unresolved' and (${knownFlow} or (${unknownFlow})))`,\n ...(j === undefined\n ? []\n : [\n sql`exists(select 1 from ${j.table} where ${eq(col(j.table, j.identityKey), identityKey)})`,\n ]),\n // A missing real client cannot turn erased unknown work into absence.\n ...related.map(\n (v) =>\n sql`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 sql` or `,\n )})`;\n };\n\n return { oauthConnectedOwnershipReferences, connectedReferenceCondition };\n};\n"],"mappings":";;;;;;AAiBA,MAAa,qCACX,YACA,YACG;CACH,MAAM,EAAE,IAAI,QAAQ;CACpB,MAAM,eAAe,sBAAsB,UAAU;CACrD,MAAM,EAAE,SAAS;CACjB,MAAM,EAAE,KAAK,UAAU,aAAa,oBAAoB,WAAW;CAEnE,MAAM,aAAa,OAAc,KAAa,UAAkB;EAC9D,MAAM,SAAS,IAAI,OAAO,GAAG,GAC3B,QAAQ,IAAI,MAAM,OAAO,MAAM;EAEjC,OAAO,QAAQ,KAAK,MAAM,UACtB,GAAG,UAAU,OAAO,YAAY,UAChC,QAAQ,KAAK,MAAM,OACjB,GAAG,mBAAmB,OAAO,sCAAsC,MAAM,qBACzE,GAAG,QAAQ,OAAO,mBAAmB,MAAM;CACnD;;;CAIA,MAAM,qCAcJ,aAOG;EACH,MAAM,UAAU,oBAAoB,QAAQ,GAC1C,IAAI,QAAQ;EAEd,OAAO,OAAO,OAAO;GACnB,0BAA0B,CACxB,yBAA+B;IAC7B,OAAO,EAAE;IACT,SAAS,EAAE;IACX,YAAY,UACV,OAAO,IAAI,aAAa;KACtB,MAAM,MAAM,OAAO,SAAS,MAAM,SAAS,UAAU,MAAM,SAAS,MAAM;KAE1E,OAAO,KACL,MAAM,EAAE,OAAO;OACZ,EAAE,YAAY;OACd,EAAE,UAAU,QAAQ,MAAM,OAAO,CAAC;KACrC,CAAC,GACD,UAAU,EAAE,OAAO,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+ import "./connected-flow.mjs";
7
+ import { Context, Effect, Layer } from "effect";
8
+ import "@yielded/auth/OAuth";
@@ -0,0 +1,141 @@
1
+ import { CurrentOAuthTransaction } from "./owner.mjs";
2
+ import { OAuthQueryCompiler } from "./query-compiler.mjs";
3
+ import { invariant, oauthIdentityKey, sameIdentity } from "./state.mjs";
4
+ import { OAuthConnectedState } from "./connected-state.mjs";
5
+ import { OAuthConnectedCustody } from "./connected-custody.mjs";
6
+ import { OAuthConnectedFlow } from "./connected-flow.mjs";
7
+ import { Context, Effect, Layer } from "effect";
8
+ import * as M from "@yielded/auth/OAuth";
9
+ import { snapshotOAuthSync } from "@yielded/auth/OAuth";
10
+ //#region src/internal/oauth/connected-settlement.ts
11
+ const make = Effect.gen(function* () {
12
+ const operations = yield* OAuthQueryCompiler;
13
+ const C = yield* OAuthConnectedCustody;
14
+ const F = yield* OAuthConnectedFlow;
15
+ const S = yield* OAuthConnectedState;
16
+ const { ne, sql } = operations;
17
+ const { both, col, equal } = operations;
18
+ const validMetadata = (context, now) => {
19
+ const m = context.metadata, p = context.configuration.profile;
20
+ return p.provider === context.identity.provider && context.configuration.provider === context.identity.provider && context.configuration.issuer === context.identity.issuer && m.obtainedAtMillis <= now && m.useUntilMillis > m.obtainedAtMillis && m.useUntilMillis <= m.obtainedAtMillis + p.maximumAccessLifetimeMillis && (m.accessExpiresAtMillis === void 0 || m.useUntilMillis <= m.accessExpiresAtMillis) && m.scopes.every((v) => p.scopes.includes(v)) && m.resources.every((v) => p.resources.includes(v)) && new Set(m.scopes).size === m.scopes.length && new Set(m.resources).size === m.resources.length && (m.refreshUseUntilMillis === void 0 || p.retention === "access-and-refresh" && p.maximumRefreshLifetimeMillis !== void 0 && m.refreshUseUntilMillis > m.obtainedAtMillis && m.refreshUseUntilMillis <= m.obtainedAtMillis + p.maximumRefreshLifetimeMillis && (m.refreshExpiresAtMillis === void 0 || m.refreshUseUntilMillis <= m.refreshExpiresAtMillis));
21
+ };
22
+ /** The only writer that activates or replaces a confirmed connected grant. */
23
+ const activateGrant = Effect.fn("oauthConnected.activateGrant")(function* (mapping, grant, native, now, replacing) {
24
+ const owner = yield* CurrentOAuthTransaction;
25
+ const token = grant.context;
26
+ const g = mapping.grant;
27
+ const identityKey = yield* oauthIdentityKey(token.identity);
28
+ const clientKey = yield* S.clientKey(token.configuration);
29
+ const cohortKey = yield* S.cohortKey(clientKey, identityKey);
30
+ const values = {
31
+ ...g.encodeInsert({
32
+ grant: snapshotOAuthSync(M.OAuthConnectedStoredGrant, grant),
33
+ subjectId: S.nativeCopy(native)
34
+ }),
35
+ [g.moduleId]: token.moduleId,
36
+ [g.grantId]: token.grantId,
37
+ [g.subjectId]: native,
38
+ [g.identityKey]: identityKey,
39
+ [g.activeIdentityKey]: identityKey,
40
+ [g.clientKey]: clientKey,
41
+ [g.cohortKey]: cohortKey,
42
+ [g.profileKey]: token.configuration.profile.key,
43
+ [g.grantVersion]: token.grantVersion,
44
+ [g.tokenVersion]: token.tokenVersion,
45
+ [g.cohortGeneration]: token.cohortGeneration,
46
+ [g.state]: "Active",
47
+ [g.version]: owner.marker,
48
+ [g.context]: S.tokenContextStorage.encode(token),
49
+ [g.sealed]: S.sealedStorage.encode(grant.sealed),
50
+ [g.summary]: S.summaryStorage.encode(C.summary(token)),
51
+ [g.revocationJobId]: null,
52
+ [g.refreshWork]: "None",
53
+ [g.refreshClaim]: null,
54
+ [g.refreshClaimExpiresAt]: null,
55
+ [g.retentionUntil]: mapping.clock.encodeInstant(S.retainedUntil(mapping, Math.max(now, token.metadata.useUntilMillis, token.metadata.refreshUseUntilMillis ?? 0)))
56
+ };
57
+ if (!replacing) yield* owner.insert(g.table, values, {
58
+ [g.moduleId]: token.moduleId,
59
+ [g.grantId]: token.grantId
60
+ });
61
+ else yield* owner.update(g.table, {
62
+ [g.moduleId]: token.moduleId,
63
+ [g.grantId]: token.grantId
64
+ }, values);
65
+ });
66
+ return {
67
+ validMetadata,
68
+ activateGrant,
69
+ settle: Effect.fn("oauthConnected.settle")(function* (mapping, input) {
70
+ const owner = yield* CurrentOAuthTransaction;
71
+ const c = input.claim.flow.context, out = input.outcome;
72
+ const found = yield* S.current(mapping, c.revision.subjectId);
73
+ const authorized = found !== void 0 && (yield* S.action(mapping, found, input.authorization, "settle", F.expected(input.claim.flow)));
74
+ const cl = yield* S.client(mapping, S.configuration(input.claim.flow), false);
75
+ if (cl === void 0) return { _tag: "Rejected" };
76
+ if (out._tag !== "Verified" && out._tag !== "Quarantined") {
77
+ if ((yield* F.exact(mapping, input.claim)) === void 0) return { _tag: "Rejected" };
78
+ const state = out._tag === "Unissued" ? "Rejected" : out._tag;
79
+ yield* F.terminal(mapping, input.claim, state, out._tag === "Cancelled" || out._tag === "Unissued" ? "Resolved" : "Unresolved");
80
+ return { _tag: state };
81
+ }
82
+ const grant = snapshotOAuthSync(M.OAuthConnectedStoredGrant, out.grant), token = grant.context;
83
+ invariant(token.moduleId === c.moduleId && token.subjectId === c.revision.subjectId && token.grantId === c.grantId && token.identity.provider === c.provider && token.identity.issuer === c.issuer && (yield* S.clientKey(token.configuration)) === cl.id && S.tokenContextStorage.encode({
84
+ ...token,
85
+ configuration: S.configuration(input.claim.flow)
86
+ }) === S.tokenContextStorage.encode(token));
87
+ const native = yield* mapping.subjectId.toNative(c.revision.subjectId);
88
+ const tuple = yield* F.readTuple(mapping.ownership, token.identity), t = mapping.ownership.tuple;
89
+ if (tuple.row[t.state] === "Reserved" || tuple.row[t.state] === "Owned" && !mapping.subjectId.equals(tuple.row[t.subjectId], native)) {
90
+ if ((yield* F.exact(mapping, input.claim)) !== void 0) yield* F.terminal(mapping, input.claim, "Conflict", "Unresolved");
91
+ return { _tag: "Conflict" };
92
+ }
93
+ const co = yield* S.cohort(mapping, cl.id, tuple.key, true);
94
+ const original = yield* S.readGrant(mapping, c.moduleId, c.grantId);
95
+ const g = mapping.grant;
96
+ const other = yield* owner.read(g.table, both(equal(g.table, {
97
+ [g.moduleId]: c.moduleId,
98
+ [g.subjectId]: native,
99
+ [g.profileKey]: c.profile.key,
100
+ [g.activeIdentityKey]: tuple.key
101
+ }), ne(col(g.table, g.grantId), c.grantId)), { limit: 1 });
102
+ const claimed = yield* F.exact(mapping, input.claim);
103
+ if (claimed === void 0) return { _tag: "Rejected" };
104
+ invariant(token.exchangeOrder === input.claim.order && validMetadata(token, claimed.now) && token.metadata.obtainedAtMillis >= input.claim.claimedAtMillis);
105
+ const reconnect = c.reconnect;
106
+ const targetOkay = reconnect === void 0 ? original === void 0 : original !== void 0 && F.sameTarget(reconnect, original.context) && sameIdentity(reconnect.identity, token.identity) && original.row[g.refreshWork] !== "Unresolved";
107
+ const previousSafe = yield* C.noFormerOwner(mapping, tuple.key, cl.id, native);
108
+ if (!(out._tag === "Verified" && authorized && claimed.active && c.profile.issuance === "active" && token.metadata.useUntilMillis > claimed.now && !co.blocked && co.generation === token.cohortGeneration && S.orderNumber(input.claim.order) > co.cutoff && targetOkay && other.rows.length === 0 && previousSafe)) {
109
+ if (!previousSafe) {
110
+ yield* F.terminal(mapping, input.claim, "Conflict", "Unresolved");
111
+ return { _tag: "Conflict" };
112
+ }
113
+ if (tuple.row[t.state] === "Unowned") yield* F.acquireTuple(mapping.ownership, token.identity, tuple.key, S.nativeCopy(native));
114
+ yield* C.fence(mapping, cl, co);
115
+ if (out.cleanup !== void 0) {
116
+ yield* C.storeJob(mapping, out.cleanup, token, native, claimed.now);
117
+ yield* F.terminal(mapping, input.claim, "Quarantined", "Resolved", { cohort: co.id });
118
+ } else yield* F.terminal(mapping, input.claim, "Quarantined", "Unresolved", {
119
+ cohort: co.id,
120
+ sealed: grant
121
+ });
122
+ return { _tag: targetOkay && other.rows.length === 0 ? "Rejected" : "Conflict" };
123
+ }
124
+ if (tuple.row[t.state] === "Unowned") yield* F.acquireTuple(mapping.ownership, token.identity, tuple.key, S.nativeCopy(native));
125
+ yield* activateGrant(mapping, grant, native, claimed.now, original !== void 0);
126
+ yield* F.terminal(mapping, input.claim, "Connected", "Resolved", { cohort: co.id });
127
+ owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${claimed.now} and ${mapping.clock.engineNowMillis} < ${Math.min(input.claim.claimExpiresAtMillis, token.metadata.useUntilMillis)}`);
128
+ return {
129
+ _tag: "Connected",
130
+ grant
131
+ };
132
+ })
133
+ };
134
+ });
135
+ var OAuthConnectedSettlement = class OAuthConnectedSettlement extends Context.Service()("effect-auth/persistence/OAuthConnectedSettlement") {
136
+ static layer = Layer.effect(OAuthConnectedSettlement, make);
137
+ };
138
+ //#endregion
139
+ export { OAuthConnectedSettlement };
140
+
141
+ //# sourceMappingURL=connected-settlement.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connected-settlement.mjs","names":[],"sources":["../../../src/internal/oauth/connected-settlement.ts"],"sourcesContent":["import * as M from \"@yielded/auth/OAuth\";\nimport { snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport { Effect, Context, Layer } from \"effect\";\n\nimport { OAuthConnectedCustody } from \"./connected-custody\";\nimport { OAuthConnectedFlow } from \"./connected-flow\";\nimport type * as FTypes from \"./connected-flow\";\nimport { OAuthConnectedState } from \"./connected-state\";\nimport type * as STypes from \"./connected-state\";\nimport { CurrentOAuthTransaction } from \"./owner\";\nimport { OAuthQueryCompiler } from \"./query-compiler\";\nimport { invariant, sameIdentity, oauthIdentityKey } from \"./state\";\n\nconst make = Effect.gen(function* () {\n const operations = yield* OAuthQueryCompiler;\n const C = yield* OAuthConnectedCustody;\n const F = yield* OAuthConnectedFlow;\n const S = yield* OAuthConnectedState;\n\n const { ne, sql } = operations;\n const { both, col, equal } = operations;\n\n const validMetadata = (context: M.OAuthConnectedTokenContext, now: number) => {\n const m = context.metadata,\n p = context.configuration.profile;\n\n return (\n p.provider === context.identity.provider &&\n context.configuration.provider === context.identity.provider &&\n context.configuration.issuer === context.identity.issuer &&\n m.obtainedAtMillis <= now &&\n m.useUntilMillis > m.obtainedAtMillis &&\n m.useUntilMillis <= m.obtainedAtMillis + p.maximumAccessLifetimeMillis &&\n (m.accessExpiresAtMillis === undefined || m.useUntilMillis <= m.accessExpiresAtMillis) &&\n m.scopes.every((v) => p.scopes.includes(v)) &&\n m.resources.every((v) => p.resources.includes(v)) &&\n new Set(m.scopes).size === m.scopes.length &&\n new Set(m.resources).size === m.resources.length &&\n (m.refreshUseUntilMillis === undefined ||\n (p.retention === \"access-and-refresh\" &&\n p.maximumRefreshLifetimeMillis !== undefined &&\n m.refreshUseUntilMillis > m.obtainedAtMillis &&\n m.refreshUseUntilMillis <= m.obtainedAtMillis + p.maximumRefreshLifetimeMillis &&\n (m.refreshExpiresAtMillis === undefined ||\n m.refreshUseUntilMillis <= m.refreshExpiresAtMillis)))\n );\n };\n\n /** The only writer that activates or replaces a confirmed connected grant. */\n const activateGrant = Effect.fn(\"oauthConnected.activateGrant\")(function* (\n mapping: STypes.Mapping,\n grant: M.OAuthConnectedStoredGrant,\n native: unknown,\n now: number,\n replacing: boolean,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n const token = grant.context;\n const g = mapping.grant;\n const identityKey = yield* oauthIdentityKey(token.identity);\n const clientKey = yield* S.clientKey(token.configuration);\n const cohortKey = yield* S.cohortKey(clientKey, identityKey);\n\n const values = {\n ...g.encodeInsert({\n grant: snapshotOAuthSync(M.OAuthConnectedStoredGrant, grant),\n subjectId: S.nativeCopy(native),\n }),\n [g.moduleId]: token.moduleId,\n [g.grantId]: token.grantId,\n [g.subjectId]: native,\n [g.identityKey]: identityKey,\n [g.activeIdentityKey]: identityKey,\n [g.clientKey]: clientKey,\n [g.cohortKey]: cohortKey,\n [g.profileKey]: token.configuration.profile.key,\n [g.grantVersion]: token.grantVersion,\n [g.tokenVersion]: token.tokenVersion,\n [g.cohortGeneration]: token.cohortGeneration,\n [g.state]: \"Active\",\n [g.version]: owner.marker,\n [g.context]: S.tokenContextStorage.encode(token),\n [g.sealed]: S.sealedStorage.encode(grant.sealed),\n [g.summary]: S.summaryStorage.encode(C.summary(token)),\n [g.revocationJobId]: null,\n [g.refreshWork]: \"None\",\n [g.refreshClaim]: null,\n [g.refreshClaimExpiresAt]: null,\n [g.retentionUntil]: mapping.clock.encodeInstant(\n S.retainedUntil(\n mapping,\n Math.max(now, token.metadata.useUntilMillis, token.metadata.refreshUseUntilMillis ?? 0),\n ),\n ),\n };\n\n if (!replacing) {\n yield* owner.insert(g.table, values, {\n [g.moduleId]: token.moduleId,\n [g.grantId]: token.grantId,\n });\n } else\n yield* owner.update(\n g.table,\n { [g.moduleId]: token.moduleId, [g.grantId]: token.grantId },\n values,\n );\n });\n\n const settle = Effect.fn(\"oauthConnected.settle\")(function* (\n mapping: STypes.Mapping,\n input: FTypes.Input<\"settle\">,\n ) {\n const owner = yield* CurrentOAuthTransaction;\n\n const c = input.claim.flow.context,\n out = input.outcome;\n\n const found = yield* S.current(mapping, c.revision.subjectId);\n\n const authorized =\n found !== undefined &&\n (yield* S.action(\n mapping,\n found,\n input.authorization,\n \"settle\",\n F.expected(input.claim.flow),\n ));\n\n const cl = yield* S.client(mapping, S.configuration(input.claim.flow), false);\n\n if (cl === undefined) return { _tag: \"Rejected\" } as const;\n if (out._tag !== \"Verified\" && out._tag !== \"Quarantined\") {\n const claimed = yield* F.exact(mapping, input.claim);\n\n if (claimed === undefined) return { _tag: \"Rejected\" } as const;\n const state = out._tag === \"Unissued\" ? \"Rejected\" : out._tag;\n\n yield* F.terminal(\n mapping,\n input.claim,\n state,\n out._tag === \"Cancelled\" || out._tag === \"Unissued\" ? \"Resolved\" : \"Unresolved\",\n );\n\n return { _tag: state } as\n | { readonly _tag: \"Cancelled\" }\n | { readonly _tag: \"Rejected\" }\n | { readonly _tag: \"Conflict\" }\n | { readonly _tag: \"Ambiguous\" };\n }\n\n const grant = snapshotOAuthSync(M.OAuthConnectedStoredGrant, out.grant),\n token = grant.context;\n\n invariant(\n token.moduleId === c.moduleId &&\n token.subjectId === c.revision.subjectId &&\n token.grantId === c.grantId &&\n token.identity.provider === c.provider &&\n token.identity.issuer === c.issuer &&\n (yield* S.clientKey(token.configuration)) === cl.id &&\n S.tokenContextStorage.encode({\n ...token,\n configuration: S.configuration(input.claim.flow),\n }) === S.tokenContextStorage.encode(token),\n );\n const native = yield* mapping.subjectId.toNative(c.revision.subjectId);\n\n const tuple = yield* F.readTuple(mapping.ownership, token.identity),\n t = mapping.ownership.tuple;\n\n if (\n tuple.row[t.state] === \"Reserved\" ||\n (tuple.row[t.state] === \"Owned\" && !mapping.subjectId.equals(tuple.row[t.subjectId], native))\n ) {\n const claimed = yield* F.exact(mapping, input.claim);\n\n if (claimed !== undefined) yield* F.terminal(mapping, input.claim, \"Conflict\", \"Unresolved\");\n\n return { _tag: \"Conflict\" } as const;\n }\n const co = yield* S.cohort(mapping, cl.id, tuple.key, true);\n const original = yield* S.readGrant(mapping, c.moduleId, c.grantId);\n const g = mapping.grant;\n\n const other = yield* owner.read(\n g.table,\n both(\n equal(g.table, {\n [g.moduleId]: c.moduleId,\n [g.subjectId]: native,\n [g.profileKey]: c.profile.key,\n [g.activeIdentityKey]: tuple.key,\n }),\n ne(col(g.table, g.grantId), c.grantId),\n ),\n { limit: 1 },\n );\n\n const claimed = yield* F.exact(mapping, input.claim);\n\n if (claimed === undefined) return { _tag: \"Rejected\" } as const;\n invariant(\n token.exchangeOrder === input.claim.order &&\n validMetadata(token, claimed.now) &&\n token.metadata.obtainedAtMillis >= input.claim.claimedAtMillis,\n );\n const reconnect = c.reconnect;\n\n const targetOkay =\n reconnect === undefined\n ? original === undefined\n : original !== undefined &&\n F.sameTarget(reconnect, original.context) &&\n sameIdentity(reconnect.identity, token.identity) &&\n original.row[g.refreshWork] !== \"Unresolved\";\n\n const previousSafe = yield* C.noFormerOwner(mapping, tuple.key, cl.id, native);\n\n const active =\n out._tag === \"Verified\" &&\n authorized &&\n claimed.active &&\n c.profile.issuance === \"active\" &&\n token.metadata.useUntilMillis > claimed.now &&\n !co.blocked &&\n co.generation === token.cohortGeneration &&\n S.orderNumber(input.claim.order) > co.cutoff &&\n targetOkay &&\n other.rows.length === 0 &&\n previousSafe;\n\n if (!active) {\n // Foreign historical custody never authorizes a new remote operation.\n if (!previousSafe) {\n yield* F.terminal(mapping, input.claim, \"Conflict\", \"Unresolved\");\n\n return { _tag: \"Conflict\" } as const;\n }\n if (tuple.row[t.state] === \"Unowned\")\n yield* F.acquireTuple(mapping.ownership, token.identity, tuple.key, S.nativeCopy(native));\n yield* C.fence(mapping, cl, co);\n if (out.cleanup !== undefined) {\n yield* C.storeJob(mapping, out.cleanup, token, native, claimed.now);\n yield* F.terminal(mapping, input.claim, \"Quarantined\", \"Resolved\", { cohort: co.id });\n } else\n yield* F.terminal(mapping, input.claim, \"Quarantined\", \"Unresolved\", {\n cohort: co.id,\n sealed: grant,\n });\n\n return { _tag: targetOkay && other.rows.length === 0 ? \"Rejected\" : \"Conflict\" } as\n | { readonly _tag: \"Rejected\" }\n | { readonly _tag: \"Conflict\" };\n }\n if (tuple.row[t.state] === \"Unowned\")\n yield* F.acquireTuple(mapping.ownership, token.identity, tuple.key, S.nativeCopy(native));\n\n yield* activateGrant(mapping, grant, native, claimed.now, original !== undefined);\n yield* F.terminal(mapping, input.claim, \"Connected\", \"Resolved\", { cohort: co.id });\n owner.postconditions.push(\n sql`${mapping.clock.engineNowMillis} >= ${claimed.now} and ${mapping.clock.engineNowMillis} < ${Math.min(input.claim.claimExpiresAtMillis, token.metadata.useUntilMillis)}`,\n );\n\n return { _tag: \"Connected\", grant } as const;\n });\n\n return { validMetadata, activateGrant, settle };\n});\n\nexport class OAuthConnectedSettlement extends Context.Service<\n OAuthConnectedSettlement,\n Effect.Success<typeof make>\n>()(\"effect-auth/persistence/OAuthConnectedSettlement\") {\n static readonly layer = Layer.effect(OAuthConnectedSettlement, make);\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,OAAO,OAAO,IAAI,aAAa;CACnC,MAAM,aAAa,OAAO;CAC1B,MAAM,IAAI,OAAO;CACjB,MAAM,IAAI,OAAO;CACjB,MAAM,IAAI,OAAO;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,IAAa,2BAAb,MAAa,iCAAiC,QAAQ,QAGpD,CAAC,CAAC,kDAAkD,CAAC,CAAC;CACtD,OAAgB,QAAQ,MAAM,OAAO,0BAA0B,IAAI;AACrE"}
@@ -0,0 +1,10 @@
1
+ import "../mapping-error.mjs";
2
+ import "./owner.mjs";
3
+ import "./connected-state.mjs";
4
+ import "./query-compiler.mjs";
5
+ import "./flow.mjs";
6
+ import "./connected-custody.mjs";
7
+ import "./connected-flow.mjs";
8
+ import "./connected-settlement.mjs";
9
+ import { Context, Effect, Layer, Schema } from "effect";
10
+ import "@yielded/auth/OAuth";