@yielded/auth-persistence-drizzle 0.1.0-beta.17 → 0.1.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/D1.d.mts +120 -120
- package/dist/Libsql.d.mts +154 -154
- package/dist/Mysql2.d.mts +166 -166
- package/dist/Pglite.d.mts +166 -166
- package/dist/Postgres.d.mts +152 -152
- package/dist/SqliteBun.d.mts +168 -168
- package/dist/SqliteDo.d.mts +237 -259
- package/dist/SqliteDo.mjs +30 -45
- package/dist/SqliteDo.mjs.map +1 -1
- package/dist/SqliteNode.d.mts +154 -154
- package/dist/SqliteWasm.d.mts +163 -163
- package/dist/drizzle/crypto.mjs +11 -0
- package/dist/drizzle/crypto.mjs.map +1 -0
- package/dist/drizzle/d1-identity.mjs +2 -2
- package/dist/drizzle/d1-identity.mjs.map +1 -1
- package/dist/drizzle/d1-oauth.d.mts +16 -16
- package/dist/drizzle/d1-oauth.mjs.map +1 -1
- package/dist/drizzle/d1-passkey.d.mts +6 -6
- package/dist/drizzle/d1-passkey.mjs.map +1 -1
- package/dist/drizzle/d1-password-prepared.mjs +3 -3
- package/dist/drizzle/d1-password-prepared.mjs.map +1 -1
- package/dist/drizzle/d1-passwords.d.mts +1 -1
- package/dist/drizzle/d1-passwords.mjs +1 -1
- package/dist/drizzle/d1-passwords.mjs.map +1 -1
- package/dist/drizzle/d1-phone.d.mts +3 -3
- package/dist/drizzle/d1-phone.mjs.map +1 -1
- package/dist/drizzle/d1-proofs.d.mts +1 -1
- package/dist/drizzle/d1-sessions.d.mts +1 -1
- package/dist/drizzle/d1-sessions.mjs +4 -3
- package/dist/drizzle/d1-sessions.mjs.map +1 -1
- package/dist/drizzle/d1-totp.d.mts +3 -3
- package/dist/drizzle/d1-totp.mjs.map +1 -1
- package/dist/drizzle/mysql-identity.mjs +2 -2
- package/dist/drizzle/mysql-identity.mjs.map +1 -1
- package/dist/drizzle/oauth-accounts.mjs +9 -8
- package/dist/drizzle/oauth-accounts.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-collection.mjs +1 -1
- package/dist/drizzle/oauth-connected-collection.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-custody.mjs +5 -4
- package/dist/drizzle/oauth-connected-custody.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-flow.mjs +8 -7
- package/dist/drizzle/oauth-connected-flow.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-management.mjs +3 -2
- package/dist/drizzle/oauth-connected-management.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-reference.mjs +8 -4
- package/dist/drizzle/oauth-connected-reference.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-settlement.mjs +4 -4
- package/dist/drizzle/oauth-connected-settlement.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-sign-in.mjs +11 -10
- package/dist/drizzle/oauth-connected-sign-in.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-state.d.mts +265 -265
- package/dist/drizzle/oauth-connected-state.mjs +23 -20
- package/dist/drizzle/oauth-connected-state.mjs.map +1 -1
- package/dist/drizzle/oauth-connected-target.d.mts +105 -105
- package/dist/drizzle/oauth-connected-target.mjs.map +1 -1
- package/dist/drizzle/oauth-drivers.mjs.map +1 -1
- package/dist/drizzle/oauth-flow.mjs +1 -1
- package/dist/drizzle/oauth-flow.mjs.map +1 -1
- package/dist/drizzle/oauth-model.d.mts +4 -4
- package/dist/drizzle/oauth-model.mjs.map +1 -1
- package/dist/drizzle/oauth-registration.mjs +2 -2
- package/dist/drizzle/oauth-registration.mjs.map +1 -1
- package/dist/drizzle/oauth-state.mjs +11 -12
- package/dist/drizzle/oauth-state.mjs.map +1 -1
- package/dist/drizzle/oauth-target.d.mts +4 -4
- package/dist/drizzle/oauth-target.mjs.map +1 -1
- package/dist/drizzle/passkey-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-drivers.mjs.map +1 -1
- package/dist/drizzle/passkey-write-target.d.mts +1 -1
- package/dist/drizzle/password-prepared-sql.mjs +1 -1
- package/dist/drizzle/password-prepared-sql.mjs.map +1 -1
- package/dist/drizzle/password-prepared-state.mjs +1 -1
- package/dist/drizzle/pg-identity.mjs +2 -2
- package/dist/drizzle/pg-identity.mjs.map +1 -1
- package/dist/drizzle/phone-model.d.mts +2 -2
- package/dist/drizzle/phone-model.mjs +3 -3
- package/dist/drizzle/phone-model.mjs.map +1 -1
- package/dist/drizzle/phone-target.d.mts +1 -1
- package/dist/drizzle/phone-target.mjs +2 -2
- package/dist/drizzle/phone-target.mjs.map +1 -1
- package/dist/drizzle/sqlite-do-database.d.mts +29 -0
- package/dist/drizzle/sqlite-do-database.mjs +45 -0
- package/dist/drizzle/sqlite-do-database.mjs.map +1 -0
- package/dist/drizzle/sqlite-emails.mjs.map +1 -1
- package/dist/drizzle/sqlite-identity.mjs +2 -2
- package/dist/drizzle/sqlite-identity.mjs.map +1 -1
- package/dist/drizzle/sqlite-passwords.mjs.map +1 -1
- package/dist/drizzle/sqlite-proofs.mjs.map +1 -1
- package/dist/drizzle/sqlite-sessions.mjs.map +1 -1
- package/dist/drizzle/storage-validation.mjs +17 -9
- package/dist/drizzle/storage-validation.mjs.map +1 -1
- package/dist/drizzle/totp-state.mjs +8 -8
- package/dist/drizzle/totp-state.mjs.map +1 -1
- package/dist/drizzle/totp-target.d.mts +1 -1
- package/dist/drizzle/totp-target.mjs +2 -2
- package/dist/drizzle/totp-target.mjs.map +1 -1
- package/package.json +1 -1
- package/src/SqliteDo.ts +63 -70
- package/src/drizzle/crypto.ts +14 -0
- package/src/drizzle/d1-identity.ts +2 -2
- package/src/drizzle/d1-oauth.ts +14 -5
- package/src/drizzle/d1-passkey.ts +5 -1
- package/src/drizzle/d1-password-prepared.ts +11 -5
- package/src/drizzle/d1-passwords.ts +1 -1
- package/src/drizzle/d1-phone.ts +2 -1
- package/src/drizzle/d1-sessions.ts +8 -2
- package/src/drizzle/d1-totp.ts +6 -2
- package/src/drizzle/mysql-identity.ts +2 -2
- package/src/drizzle/oauth-accounts.ts +14 -13
- package/src/drizzle/oauth-connected-collection.ts +1 -1
- package/src/drizzle/oauth-connected-custody.ts +8 -6
- package/src/drizzle/oauth-connected-drivers.ts +9 -3
- package/src/drizzle/oauth-connected-flow.ts +6 -6
- package/src/drizzle/oauth-connected-management.ts +1 -1
- package/src/drizzle/oauth-connected-reference.ts +14 -9
- package/src/drizzle/oauth-connected-settlement.ts +4 -4
- package/src/drizzle/oauth-connected-sign-in.ts +11 -10
- package/src/drizzle/oauth-connected-state.ts +40 -25
- package/src/drizzle/oauth-connected-target.ts +9 -5
- package/src/drizzle/oauth-drivers.ts +13 -5
- package/src/drizzle/oauth-flow.ts +1 -1
- package/src/drizzle/oauth-model.ts +4 -4
- package/src/drizzle/oauth-registration.ts +2 -2
- package/src/drizzle/oauth-state.ts +17 -15
- package/src/drizzle/oauth-target.ts +11 -3
- package/src/drizzle/passkey-drivers.ts +7 -3
- package/src/drizzle/passkey-write-drivers.ts +11 -2
- package/src/drizzle/password-prepared-sql.ts +1 -1
- package/src/drizzle/pg-identity.ts +2 -2
- package/src/drizzle/phone-model.ts +3 -3
- package/src/drizzle/phone-target.ts +11 -4
- package/src/drizzle/sqlite-do-database.ts +87 -0
- package/src/drizzle/sqlite-emails.ts +1 -1
- package/src/drizzle/sqlite-identity.ts +2 -2
- package/src/drizzle/sqlite-passwords.ts +1 -1
- package/src/drizzle/sqlite-proofs.ts +2 -2
- package/src/drizzle/sqlite-sessions.ts +2 -2
- package/src/drizzle/storage-validation.ts +15 -6
- package/src/drizzle/totp-state.ts +8 -8
- package/src/drizzle/totp-target.ts +11 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { digest
|
|
1
|
+
import { digest } from "./crypto.mjs";
|
|
2
|
+
import { invariant, oauthIdentityKey, sameRevision, satisfies, storage, unavailable } from "./oauth-state.mjs";
|
|
2
3
|
import { both } from "./transaction-owner.mjs";
|
|
3
4
|
import { CurrentOAuthTransaction, col, copiedRow, equal } from "./oauth-owner.mjs";
|
|
4
5
|
import { currentSubject } from "./oauth-flow.mjs";
|
|
@@ -44,17 +45,17 @@ const orderNumber = (value) => {
|
|
|
44
45
|
const nativeOrder = (mapping, value) => orderParser(mapping.order.decode(value));
|
|
45
46
|
const encoder = new TextEncoder();
|
|
46
47
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
47
|
-
const key = (domain, fields)
|
|
48
|
+
const key = Effect.fnUntraced(function* (domain, fields) {
|
|
48
49
|
for (const value of fields) invariant(decoder.decode(encoder.encode(value)) === value);
|
|
49
|
-
return "v1:" + digest(strings.encode([domain, ...fields]));
|
|
50
|
-
};
|
|
50
|
+
return "v1:" + (yield* digest(strings.encode([domain, ...fields])));
|
|
51
|
+
});
|
|
51
52
|
const clientKey = (configuration) => key("effect-auth/oauth-connected-client/v1", [
|
|
52
53
|
configuration.provider,
|
|
53
54
|
configuration.issuer,
|
|
54
55
|
configuration.profile.clientRegistrationId
|
|
55
56
|
]);
|
|
56
57
|
const cohortKey = (client, identity) => key("effect-auth/oauth-connected-cohort/v1", [client, identity]);
|
|
57
|
-
const initialGeneration = (cohort) => M.OAuthConnectedTarget.fields.cohortGeneration.make("initial:" +
|
|
58
|
+
const initialGeneration = (cohort) => digest(cohort).pipe(Effect.map((value) => M.OAuthConnectedTarget.fields.cohortGeneration.make("initial:" + value)));
|
|
58
59
|
const configuration = (flow) => snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);
|
|
59
60
|
const retainedUntil = (mapping, now) => {
|
|
60
61
|
invariant(Number.isSafeInteger(mapping.retentionMillis) && mapping.retentionMillis >= 12e4 && mapping.retentionMillis <= 2592e6);
|
|
@@ -105,8 +106,8 @@ const action = Effect.fn("oauthConnected.action")(function* (mapping, found, aut
|
|
|
105
106
|
const owner = yield* CurrentOAuthTransaction;
|
|
106
107
|
const challenge = authorization.challenge, evidence = authorization.evidence;
|
|
107
108
|
const name = operation === "issue" ? "connected-begin" : operation === "disconnect" ? "connected-disconnect" : "connected-complete";
|
|
108
|
-
const intentDigest = digest(expected.intent);
|
|
109
|
-
const binding = digest(strings.encode([
|
|
109
|
+
const intentDigest = yield* digest(expected.intent);
|
|
110
|
+
const binding = yield* digest(strings.encode([
|
|
110
111
|
"effect-auth/oauth-connected-action/v1",
|
|
111
112
|
expected.moduleId,
|
|
112
113
|
name,
|
|
@@ -150,7 +151,7 @@ const useAuthority = Effect.fn("oauthConnected.useAuthority")(function* (mapping
|
|
|
150
151
|
owner.postconditions.push(sql`${mapping.clock.engineNowMillis} >= ${now} and ${mapping.clock.engineNowMillis} < ${authorization.expiresAtMillis}`);
|
|
151
152
|
return found;
|
|
152
153
|
});
|
|
153
|
-
const scopeKey = (provider, issuer) =>
|
|
154
|
+
const scopeKey = (provider, issuer) => key("effect-auth/oauth-connected-provider-issuer/v1", [provider, issuer]).pipe(Effect.map((value) => "scope:" + value));
|
|
154
155
|
const scopeCache = /* @__PURE__ */ new WeakMap();
|
|
155
156
|
const clientCache = /* @__PURE__ */ new WeakMap();
|
|
156
157
|
const anchors = Effect.fn("oauthConnected.anchors")(function* (cache, table) {
|
|
@@ -171,7 +172,7 @@ const anchors = Effect.fn("oauthConnected.anchors")(function* (cache, table) {
|
|
|
171
172
|
* distinct 52-byte key domain shares the physical table, never a client counter. */
|
|
172
173
|
const scope = Effect.fn("oauthConnected.scope")(function* (mapping, config, create) {
|
|
173
174
|
const owner = yield* CurrentOAuthTransaction;
|
|
174
|
-
const c = mapping.client, id = scopeKey(config.provider, config.issuer), cache = yield* anchors(scopeCache, c.table);
|
|
175
|
+
const c = mapping.client, id = yield* scopeKey(config.provider, config.issuer), cache = yield* anchors(scopeCache, c.table);
|
|
175
176
|
const existing = cache.get(id);
|
|
176
177
|
if (existing !== void 0) return existing;
|
|
177
178
|
const read = yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 });
|
|
@@ -221,7 +222,7 @@ const touchScope = Effect.fn("oauthConnected.touchScope")(function* (mapping, fo
|
|
|
221
222
|
});
|
|
222
223
|
const readScope = Effect.fn("oauthConnected.readScope")(function* (mapping, provider, issuer) {
|
|
223
224
|
const owner = yield* CurrentOAuthTransaction;
|
|
224
|
-
const c = mapping.client, id = scopeKey(provider, issuer), cache = yield* anchors(scopeCache, c.table), cached = cache.get(id);
|
|
225
|
+
const c = mapping.client, id = yield* scopeKey(provider, issuer), cache = yield* anchors(scopeCache, c.table), cached = cache.get(id);
|
|
225
226
|
if (cached !== void 0) return cached;
|
|
226
227
|
const row = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 })).rows[0];
|
|
227
228
|
invariant(row !== void 0 && row[c.provider] === provider && row[c.issuer] === issuer && row[c.clientRegistrationId] === "" && nativeOrder(mapping, row[c.counter]) === 0);
|
|
@@ -244,11 +245,11 @@ const lockClientById = Effect.fn("oauthConnected.lockClientById")(function* (map
|
|
|
244
245
|
invariant(initial !== void 0);
|
|
245
246
|
const scope = yield* readScope(mapping, initial[c.provider], initial[c.issuer]);
|
|
246
247
|
const row = (yield* owner.read(c.table, equal(c.table, { [c.clientKey]: id }), { limit: 1 })).rows[0];
|
|
247
|
-
invariant(row !== void 0 && row[c.clientRegistrationId] !== "" && id === key("effect-auth/oauth-connected-client/v1", [
|
|
248
|
+
invariant(row !== void 0 && row[c.clientRegistrationId] !== "" && id === (yield* key("effect-auth/oauth-connected-client/v1", [
|
|
248
249
|
row[c.provider],
|
|
249
250
|
row[c.issuer],
|
|
250
251
|
row[c.clientRegistrationId]
|
|
251
|
-
]) && scope.id === scopeKey(row[c.provider], row[c.issuer]));
|
|
252
|
+
])) && scope.id === (yield* scopeKey(row[c.provider], row[c.issuer])));
|
|
252
253
|
const found = {
|
|
253
254
|
id,
|
|
254
255
|
row,
|
|
@@ -258,14 +259,16 @@ const lockClientById = Effect.fn("oauthConnected.lockClientById")(function* (map
|
|
|
258
259
|
cache.set(id, found);
|
|
259
260
|
return found;
|
|
260
261
|
});
|
|
261
|
-
const heldScope =
|
|
262
|
+
const heldScope = Effect.fnUntraced(function* (mapping, provider, issuer) {
|
|
263
|
+
return (yield* anchors(scopeCache, mapping.client.table)).get(yield* scopeKey(provider, issuer));
|
|
264
|
+
});
|
|
262
265
|
/** Cleanup obtains every scope then every client before entering any tuple. */
|
|
263
266
|
const prelockClients = Effect.fn("oauthConnected.prelockClients")(function* (mapping, ids, releaseScopes = []) {
|
|
264
267
|
const owner = yield* CurrentOAuthTransaction;
|
|
265
268
|
const unique = [...new Set(ids)].sort(), c = mapping.client;
|
|
266
269
|
invariant(unique.length <= 4e3);
|
|
267
270
|
const scopes = /* @__PURE__ */ new Map();
|
|
268
|
-
for (const value of releaseScopes) scopes.set(scopeKey(value.provider, value.issuer), {
|
|
271
|
+
for (const value of releaseScopes) scopes.set(yield* scopeKey(value.provider, value.issuer), {
|
|
269
272
|
...value,
|
|
270
273
|
required: false
|
|
271
274
|
});
|
|
@@ -276,7 +279,7 @@ const prelockClients = Effect.fn("oauthConnected.prelockClients")(function* (map
|
|
|
276
279
|
observe: false
|
|
277
280
|
})).rows[0];
|
|
278
281
|
invariant(row !== void 0);
|
|
279
|
-
scopes.set(scopeKey(row[c.provider], row[c.issuer]), {
|
|
282
|
+
scopes.set(yield* scopeKey(row[c.provider], row[c.issuer]), {
|
|
280
283
|
provider: row[c.provider],
|
|
281
284
|
issuer: row[c.issuer],
|
|
282
285
|
required: true
|
|
@@ -297,7 +300,7 @@ const prelockClients = Effect.fn("oauthConnected.prelockClients")(function* (map
|
|
|
297
300
|
});
|
|
298
301
|
const client = Effect.fn("oauthConnected.client")(function* (mapping, config, create) {
|
|
299
302
|
const owner = yield* CurrentOAuthTransaction;
|
|
300
|
-
const c = mapping.client, id = clientKey(config), where = { [c.clientKey]: id };
|
|
303
|
+
const c = mapping.client, id = yield* clientKey(config), where = { [c.clientKey]: id };
|
|
301
304
|
const heldScope = yield* scope(mapping, config, create);
|
|
302
305
|
if (heldScope === void 0) return void 0;
|
|
303
306
|
const cache = yield* anchors(clientCache, c.table), cached = cache.get(id);
|
|
@@ -348,7 +351,7 @@ const nextOrder = Effect.fn("oauthConnected.nextOrder")(function* (mapping, foun
|
|
|
348
351
|
});
|
|
349
352
|
const cohort = Effect.fn("oauthConnected.cohort")(function* (mapping, clientId, identityId, create) {
|
|
350
353
|
const owner = yield* CurrentOAuthTransaction;
|
|
351
|
-
const c = mapping.cohort, id = cohortKey(clientId, identityId), where = { [c.cohortKey]: id };
|
|
354
|
+
const c = mapping.cohort, id = yield* cohortKey(clientId, identityId), where = { [c.cohortKey]: id };
|
|
352
355
|
let read = yield* owner.read(c.table, equal(c.table, where), { limit: 1 });
|
|
353
356
|
if (read.rows.length === 0) {
|
|
354
357
|
const related = [
|
|
@@ -366,7 +369,7 @@ const cohort = Effect.fn("oauthConnected.cohort")(function* (mapping, clientId,
|
|
|
366
369
|
...where,
|
|
367
370
|
[c.clientKey]: clientId,
|
|
368
371
|
[c.identityKey]: identityId,
|
|
369
|
-
[c.generation]: initialGeneration(id),
|
|
372
|
+
[c.generation]: yield* initialGeneration(id),
|
|
370
373
|
[c.cutoff]: mapping.order.encode(0),
|
|
371
374
|
[c.state]: "Open",
|
|
372
375
|
[c.version]: owner.marker
|
|
@@ -375,7 +378,7 @@ const cohort = Effect.fn("oauthConnected.cohort")(function* (mapping, clientId,
|
|
|
375
378
|
if (row === void 0) return {
|
|
376
379
|
id,
|
|
377
380
|
row: void 0,
|
|
378
|
-
generation: initialGeneration(id),
|
|
381
|
+
generation: yield* initialGeneration(id),
|
|
379
382
|
cutoff: 0,
|
|
380
383
|
blocked: false
|
|
381
384
|
};
|
|
@@ -405,7 +408,7 @@ const readGrant = Effect.fn("oauthConnected.readGrant")(function* (mapping, modu
|
|
|
405
408
|
if (lock) owner.observations.push(read);
|
|
406
409
|
const context = tokenContextStorage.decode(row[g.context]);
|
|
407
410
|
const native = yield* mapping.subjectId.toNative(context.subjectId);
|
|
408
|
-
invariant(context.moduleId === moduleId && context.grantId === grantId && mapping.subjectId.equals(native, row[g.subjectId]) && row[g.identityKey] === oauthIdentityKey(context.identity) && row[g.clientKey] === clientKey(context.configuration) && row[g.cohortKey] === 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);
|
|
411
|
+
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);
|
|
409
412
|
return {
|
|
410
413
|
row,
|
|
411
414
|
context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-connected-state.mjs","names":[],"sources":["../../src/drizzle/oauth-connected-state.ts"],"sourcesContent":["import { type OAuthAccountRevision, snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport * as M from \"@yielded/auth/OAuth\";\nimport { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- private table erasure retains declared callback error/requirements channels. */\nimport { and, eq, isNull, sql, type SQL, type Table } from \"drizzle-orm\";\nimport type { EffectDrizzleQueryError } from \"drizzle-orm/effect-core\";\nimport { DateTime, Effect, Schema } from \"effect\";\n\nimport type {\n OAuthConnectedAuthorityMapping,\n OAuthConnectedClientRegistrationTable,\n OAuthConnectedCohortTable,\n OAuthConnectedMapping,\n OAuthConnectedPolicyInput,\n OAuthConnectedRevocationMapping,\n} from \"./oauth-connected-model\";\nimport { currentSubject } from \"./oauth-flow\";\nimport {\n both,\n col,\n copiedRow,\n equal,\n CurrentOAuthTransaction,\n type OAuthOwner,\n type Row,\n} from \"./oauth-owner\";\nimport {\n digest,\n invariant,\n oauthIdentityKey,\n sameRevision,\n satisfies,\n storage,\n unavailable,\n} from \"./oauth-state\";\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\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>;\n\nexport type Revocations = OAuthConnectedRevocationMapping<any, any, any, any, any, any, any, any>;\nexport type Current = NonNullable<Effect.Success<ReturnType<typeof currentSubject>>>;\nexport const contextStorage = storage(M.OAuthConnectedTransactionContext);\nexport const flowStorage = storage(M.OAuthConnectedPendingFlow);\nexport const claimStorage = storage(M.OAuthConnectedClaim);\nexport const tokenContextStorage = storage(M.OAuthConnectedTokenContext);\nexport const sealedStorage = storage(M.OAuthConnectedSealedTokens);\nexport const grantStorage = storage(M.OAuthConnectedStoredGrant);\n\nexport const admissionStorage = storage(\n Schema.Struct({\n grant: M.OAuthConnectedStoredGrant,\n authorization: M.OAuthConnectedUseAuthorization,\n }),\n);\n\nexport 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\nexport const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);\nexport const refreshStorage = storage(M.OAuthConnectedRefreshClaim);\nexport const jobStorage = storage(M.OAuthConnectedRevocationJob);\nexport const summaryStorage = storage(M.OAuthConnectedSummary);\nexport const disconnectedStorage = storage(M.OAuthConnectedDisconnected);\nconst strings = storage(Schema.Array(Schema.String));\n\nconst safeInteger = Schema.Int.check(\n Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),\n);\n\nconst orderParser = Schema.decodeSync(safeInteger);\nconst canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));\nconst orderTextParser = Schema.decodeSync(canonicalOrder);\n\nexport const orderNumber = (value: string) => {\n const number = orderParser(Number(orderTextParser(value)));\n\n invariant(String(number) === value);\n\n return number;\n};\n\nexport const nativeOrder = (mapping: Authority, value: unknown) =>\n orderParser(mapping.order.decode(value));\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\nconst key = (domain: string, fields: ReadonlyArray<string>) => {\n for (const value of fields) invariant(decoder.decode(encoder.encode(value)) === value);\n\n return \"v1:\" + digest(strings.encode([domain, ...fields]));\n};\n\nexport const clientKey = (configuration: M.OAuthConnectedConfiguration) =>\n key(\"effect-auth/oauth-connected-client/v1\", [\n configuration.provider,\n configuration.issuer,\n configuration.profile.clientRegistrationId,\n ]);\n\nexport const cohortKey = (client: string, identity: string) =>\n key(\"effect-auth/oauth-connected-cohort/v1\", [client, identity]);\n\nexport const initialGeneration = (cohort: string) =>\n M.OAuthConnectedTarget.fields.cohortGeneration.make(\"initial:\" + digest(cohort));\n\nexport const configuration = (flow: M.OAuthConnectedPendingFlow): M.OAuthConnectedConfiguration =>\n snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);\n\nexport 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\nexport 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<number>`count(*)`.mapWith(Number) })\n .from(table)\n .where(where) as Effect.Effect<ReadonlyArray<{ value: number }>, EffectDrizzleQueryError>\n ).pipe(Effect.mapError(unavailable));\n\n invariant(rows.length === 1);\n\n return orderParser(rows[0]!.value);\n});\n\nexport const countCondition = (table: Table, where: SQL, count: number) =>\n sql`(select count(*) from ${table} where ${where}) = ${count}`;\n\nexport 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\nexport const nativeCopy = <N>(value: N): N => copiedRow({ value }).value as N;\n\nconst 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\nexport 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\nexport 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\nexport 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 = digest(expected.intent);\n\n const binding = 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\nexport 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\nexport const scopeKey = (provider: string, issuer: string) =>\n \"scope:\" + key(\"effect-auth/oauth-connected-provider-issuer/v1\", [provider, issuer]);\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 scopeCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ScopeAnchor>>>();\nconst clientCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ClientAnchor>>>();\n\nconst 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. */\nexport 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 = 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\nexport 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\nexport 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 = 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\nexport 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 key(\"effect-auth/oauth-connected-client/v1\", [\n row[c.provider],\n row[c.issuer],\n row[c.clientRegistrationId],\n ]) &&\n scope.id === 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\nexport const heldScope = (mapping: Authority, provider: string, issuer: string) =>\n Effect.map(anchors(scopeCache, mapping.client.table), (cache) =>\n cache.get(scopeKey(provider, issuer)),\n );\n\n/** Cleanup obtains every scope then every client before entering any tuple. */\nexport 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(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(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 }), { limit: 1 }),\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\nexport 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 = 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\nexport 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\nexport 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 = 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]: 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 { id, row: undefined, generation: initialGeneration(id), cutoff: 0, blocked: false };\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\nexport 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] === oauthIdentityKey(context.identity) &&\n row[g.clientKey] === clientKey(context.configuration) &&\n row[g.cohortKey] === 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\nexport 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\nexport 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"],"mappings":";;;;;;;;;;AA0DA,MAAa,iBAAiB,QAAQ,EAAE,gCAAgC;AACxE,MAAa,cAAc,QAAQ,EAAE,yBAAyB;AAC9D,MAAa,eAAe,QAAQ,EAAE,mBAAmB;AACzD,MAAa,sBAAsB,QAAQ,EAAE,0BAA0B;AACvE,MAAa,gBAAgB,QAAQ,EAAE,0BAA0B;AACjE,MAAa,eAAe,QAAQ,EAAE,yBAAyB;AAE/D,MAAa,mBAAmB,QAC9B,OAAO,OAAO;CACZ,OAAO,EAAE;CACT,eAAe,EAAE;AACnB,CAAC,CACH;AAEA,MAAa,iBAAiB,QAC5B,OAAO,OAAO;CACZ,SAAS,EAAE;CACX,gBAAgB,OAAO,OAAO,MAAM,OAAO,UAAU,qBAAqB,CAAC;CAC3E,iBAAiB,OAAO,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,GAAG,CAAC,CAAC;AAClF,CAAC,CACH;AAEA,MAAa,oBAAoB,QAAQ,EAAE,6BAA6B;AACxE,MAAa,iBAAiB,QAAQ,EAAE,0BAA0B;AAClE,MAAa,aAAa,QAAQ,EAAE,2BAA2B;AAC/D,MAAa,iBAAiB,QAAQ,EAAE,qBAAqB;AAC7D,MAAa,sBAAsB,QAAQ,EAAE,0BAA0B;AACvE,MAAM,UAAU,QAAQ,OAAO,MAAM,OAAO,MAAM,CAAC;AAEnD,MAAM,cAAc,OAAO,IAAI,MAC7B,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS,OAAO;AAAiB,CAAC,CACnE;AAEA,MAAM,cAAc,OAAO,WAAW,W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MAAM,IAAI,QAAQ,MAChB,IAAI,QAAQ;CAEd,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;AACF"}
|
|
1
|
+
{"version":3,"file":"oauth-connected-state.mjs","names":[],"sources":["../../src/drizzle/oauth-connected-state.ts"],"sourcesContent":["import { type OAuthAccountRevision, snapshotOAuthSync } from \"@yielded/auth/OAuth\";\nimport * as M from \"@yielded/auth/OAuth\";\nimport { AuthenticationRequirement } from \"@yielded/auth/Sessions\";\n/* oxlint-disable no-explicit-any -- private table erasure retains declared callback error/requirements channels. */\nimport { and, eq, isNull, sql, type SQL, type Table } from \"drizzle-orm\";\nimport type { EffectDrizzleQueryError } from \"drizzle-orm/effect-core\";\nimport { DateTime, Effect, Schema } from \"effect\";\n\nimport type {\n OAuthConnectedAuthorityMapping,\n OAuthConnectedClientRegistrationTable,\n OAuthConnectedCohortTable,\n OAuthConnectedMapping,\n OAuthConnectedPolicyInput,\n OAuthConnectedRevocationMapping,\n} from \"./oauth-connected-model\";\nimport { currentSubject } from \"./oauth-flow\";\nimport {\n both,\n col,\n copiedRow,\n equal,\n CurrentOAuthTransaction,\n type OAuthOwner,\n type Row,\n} from \"./oauth-owner\";\nimport {\n digest,\n invariant,\n oauthIdentityKey,\n sameRevision,\n satisfies,\n storage,\n unavailable,\n} from \"./oauth-state\";\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\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>;\n\nexport type Revocations = OAuthConnectedRevocationMapping<any, any, any, any, any, any, any, any>;\nexport type Current = NonNullable<Effect.Success<ReturnType<typeof currentSubject>>>;\nexport const contextStorage = storage(M.OAuthConnectedTransactionContext);\nexport const flowStorage = storage(M.OAuthConnectedPendingFlow);\nexport const claimStorage = storage(M.OAuthConnectedClaim);\nexport const tokenContextStorage = storage(M.OAuthConnectedTokenContext);\nexport const sealedStorage = storage(M.OAuthConnectedSealedTokens);\nexport const grantStorage = storage(M.OAuthConnectedStoredGrant);\n\nexport const admissionStorage = storage(\n Schema.Struct({\n grant: M.OAuthConnectedStoredGrant,\n authorization: M.OAuthConnectedUseAuthorization,\n }),\n);\n\nexport 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\nexport const disconnectStorage = storage(M.OAuthConnectedDisconnectGrant);\nexport const refreshStorage = storage(M.OAuthConnectedRefreshClaim);\nexport const jobStorage = storage(M.OAuthConnectedRevocationJob);\nexport const summaryStorage = storage(M.OAuthConnectedSummary);\nexport const disconnectedStorage = storage(M.OAuthConnectedDisconnected);\nconst strings = storage(Schema.Array(Schema.String));\n\nconst safeInteger = Schema.Int.check(\n Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),\n);\n\nconst orderParser = Schema.decodeSync(safeInteger);\nconst canonicalOrder = Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]{0,15})$/));\nconst orderTextParser = Schema.decodeSync(canonicalOrder);\n\nexport const orderNumber = (value: string) => {\n const number = orderParser(Number(orderTextParser(value)));\n\n invariant(String(number) === value);\n\n return number;\n};\n\nexport const nativeOrder = (mapping: Authority, value: unknown) =>\n orderParser(mapping.order.decode(value));\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\nconst key = Effect.fnUntraced(function* (domain: string, fields: ReadonlyArray<string>) {\n for (const value of fields) invariant(decoder.decode(encoder.encode(value)) === value);\n\n return \"v1:\" + (yield* digest(strings.encode([domain, ...fields])));\n});\n\nexport const clientKey = (configuration: M.OAuthConnectedConfiguration) =>\n key(\"effect-auth/oauth-connected-client/v1\", [\n configuration.provider,\n configuration.issuer,\n configuration.profile.clientRegistrationId,\n ]);\n\nexport const cohortKey = (client: string, identity: string) =>\n key(\"effect-auth/oauth-connected-cohort/v1\", [client, identity]);\n\nexport const initialGeneration = (cohort: string) =>\n digest(cohort).pipe(\n Effect.map((value) => M.OAuthConnectedTarget.fields.cohortGeneration.make(\"initial:\" + value)),\n );\n\nexport const configuration = (flow: M.OAuthConnectedPendingFlow): M.OAuthConnectedConfiguration =>\n snapshotOAuthSync(M.OAuthConnectedConfiguration, flow.context);\n\nexport 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\nexport 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<number>`count(*)`.mapWith(Number) })\n .from(table)\n .where(where) as Effect.Effect<ReadonlyArray<{ value: number }>, EffectDrizzleQueryError>\n ).pipe(Effect.mapError(unavailable));\n\n invariant(rows.length === 1);\n\n return orderParser(rows[0]!.value);\n});\n\nexport const countCondition = (table: Table, where: SQL, count: number) =>\n sql`(select count(*) from ${table} where ${where}) = ${count}`;\n\nexport 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\nexport const nativeCopy = <N>(value: N): N => copiedRow({ value }).value as N;\n\nconst 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\nexport 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\nexport 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\nexport 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\nexport 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\nexport const scopeKey = (provider: string, issuer: string) =>\n key(\"effect-auth/oauth-connected-provider-issuer/v1\", [provider, issuer]).pipe(\n Effect.map((value) => \"scope:\" + value),\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 scopeCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ScopeAnchor>>>();\nconst clientCache = new WeakMap<OAuthOwner, Map<Table, Map<string, ClientAnchor>>>();\n\nconst 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. */\nexport 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\nexport 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\nexport 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\nexport 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\nexport 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. */\nexport 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 }), { limit: 1 }),\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\nexport 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\nexport 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\nexport 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\nexport 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\nexport 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\nexport 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"],"mappings":";;;;;;;;;;;AA0DA,MAAa,iBAAiB,QAAQ,EAAE,gCAAgC;AACxE,MAAa,cAAc,QAAQ,EAAE,yBAAyB;AAC9D,MAAa,eAAe,QAAQ,EAAE,mBAAmB;AACzD,MAAa,sBAAsB,QAAQ,EAAE,0BAA0B;AACvE,MAAa,gBAAgB,QAAQ,EAAE,0BAA0B;AACjE,MAAa,eAAe,QAAQ,EAAE,yBAAyB;AAE/D,MAAa,mBAAmB,QAC9B,OAAO,OAAO;CACZ,OAAO,EAAE;CACT,eAAe,EAAE;AACnB,CAAC,CACH;AAEA,MAAa,iBAAiB,QAC5B,OAAO,OAAO;CACZ,SAAS,EAAE;CACX,gBAAgB,OAAO,OAAO,MAAM,OAAO,UAAU,qBAAqB,CAAC;CAC3E,iBAAiB,OAAO,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,GAAG,CAAC,CAAC;AAClF,CAAC,CACH;AAEA,MAAa,oBAAoB,QAAQ,EAAE,6BAA6B;AACxE,MAAa,iBAAiB,QAAQ,EAAE,0BAA0B;AAClE,MAAa,aAAa,QAAQ,EAAE,2BAA2B;AAC/D,MAAa,iBAAiB,QAAQ,EAAE,qBAAqB;AAC7D,MAAa,sBAAsB,QAAQ,EAAE,0BAA0B;AACvE,MAAM,UAAU,QAAQ,OAAO,MAAM,OAAO,MAAM,CAAC;AAEnD,MAAM,cAAc,OAAO,IAAI,MAC7B,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS,OAAO;AAAiB,CAAC,CACnE;AAEA,MAAM,cAAc,OAAO,WAAW,WAAW;AACjD,MAAM,iBAAiB,OAAO,OAAO,MAAM,OAAO,UAAU,wBAAwB,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