@cortexkit/opencode-openai-auth 1.20.1 → 1.20.3
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/dist/bin.js +7 -7
- package/dist/{codex-request-Dvj28zFK.d.ts → codex-request-D0oxrTkl.d.ts} +19 -1
- package/dist/{index-rrmycmen.js → index-66eejhpe.js} +1 -1
- package/dist/{index-qfer1qeq.js → index-6a1t612m.js} +1 -1
- package/dist/{index-q3j22pg7.js → index-8ap9gr0h.js} +2 -2
- package/dist/{index-mfvnmkrh.js → index-a7eep73q.js} +22 -22
- package/dist/{index-3yf405db.js → index-ahbghz6c.js} +2 -2
- package/dist/{index-j5fk9tyk.js → index-dsytdx0r.js} +1 -1
- package/dist/{index-09rjj0qc.js → index-eb631m0m.js} +2 -2
- package/dist/{index-vyc1q51y.js → index-gxa94644.js} +2 -2
- package/dist/index-kakqxnt5.js +101 -0
- package/dist/{index-h7veb7th.js → index-qtaqp1bf.js} +1 -1
- package/dist/{index-y9k6nshb.js → index-t15pb3n2.js} +1 -1
- package/dist/{index-x9h58tf9.js → index-t66h86ed.js} +2 -2
- package/dist/{index-hybc4q33.js → index-tn1ve0gx.js} +2 -2
- package/dist/{index-tv6zrkss.js → index-vjb3rsqh.js} +20 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/token-util-qgycqbjw.js +1 -0
- package/dist/{token-t7hstws6.js → token-y8xp4cbz.js} +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +4 -4
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +145 -8
- package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +32 -0
- package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +10 -0
- package/src/tui-compiled/raw/shared/c97089ed4243981c-host.js +8 -0
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +145 -8
- package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +32 -0
- package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +10 -0
- package/src/tui-compiled/runtime/shared/c97089ed4243981c-host.js +8 -0
- package/dist/index-62e0dx41.js +0 -101
- package/dist/token-util-33bcnrmj.js +0 -1
|
@@ -178,6 +178,34 @@ function rowFactsOf(row, { includeProviderIds = true } = {}) {
|
|
|
178
178
|
authMethod: metadata.authMethod,
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
|
+
function isVaultConditionReason(reason) {
|
|
182
|
+
return (reason === 'provider_verification_required' ||
|
|
183
|
+
reason === 'provider_ineligible');
|
|
184
|
+
}
|
|
185
|
+
function vaultConditionOf(row) {
|
|
186
|
+
const condition = row.condition;
|
|
187
|
+
if (!condition)
|
|
188
|
+
return undefined;
|
|
189
|
+
const { reason, sinceMs } = condition;
|
|
190
|
+
if (isVaultConditionReason(reason) &&
|
|
191
|
+
Number.isSafeInteger(sinceMs) &&
|
|
192
|
+
sinceMs > 0)
|
|
193
|
+
return Object.freeze({ reason, sinceMs });
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
function httpsActionUrl(actionUrl) {
|
|
197
|
+
if (typeof actionUrl !== 'string')
|
|
198
|
+
return undefined;
|
|
199
|
+
try {
|
|
200
|
+
// Keep the original spelling so the vault can enforce its own link rules.
|
|
201
|
+
if (new URL(actionUrl).protocol === 'https:')
|
|
202
|
+
return actionUrl;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// An unparseable link does not invalidate the condition itself.
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
181
209
|
/**
|
|
182
210
|
* The grants named in the vault's list reply, or undefined when it names none.
|
|
183
211
|
* Both fields must be present: a reply carrying only one of them is treated as
|
|
@@ -211,6 +239,10 @@ export class ClaustrumScopedCustody {
|
|
|
211
239
|
#logger;
|
|
212
240
|
#provenance = new WeakMap();
|
|
213
241
|
#reports = new WeakMap();
|
|
242
|
+
#conditionReports = new Map();
|
|
243
|
+
#conditionClears = new Map();
|
|
244
|
+
#conditionsUnsupported = false;
|
|
245
|
+
#pendingConditionCalls = 0;
|
|
214
246
|
#kept = new Map();
|
|
215
247
|
#keptAttempts = new WeakMap();
|
|
216
248
|
#usage;
|
|
@@ -229,8 +261,9 @@ export class ClaustrumScopedCustody {
|
|
|
229
261
|
#closed = false;
|
|
230
262
|
/** The view of the last successful `discover()`, for `watchRoster`. */
|
|
231
263
|
#discoveredView;
|
|
264
|
+
#discoveredConditions = new Map();
|
|
232
265
|
#watches = new Set();
|
|
233
|
-
#
|
|
266
|
+
#shutdownWork = new Set();
|
|
234
267
|
#warnShutdown;
|
|
235
268
|
#onDrainTimeout;
|
|
236
269
|
#disposing;
|
|
@@ -292,6 +325,7 @@ export class ClaustrumScopedCustody {
|
|
|
292
325
|
if (hasVaultHost() && !isVaultHostClient(next))
|
|
293
326
|
throw new ClaustrumUnreachableError();
|
|
294
327
|
this.#client = next;
|
|
328
|
+
this.#conditionsUnsupported = false;
|
|
295
329
|
for (const watch of this.#watches)
|
|
296
330
|
watch.restart();
|
|
297
331
|
}
|
|
@@ -372,13 +406,13 @@ export class ClaustrumScopedCustody {
|
|
|
372
406
|
phase: 'token read begin',
|
|
373
407
|
});
|
|
374
408
|
const pending = this.#readToken();
|
|
375
|
-
this.#
|
|
409
|
+
this.#shutdownWork.add(pending);
|
|
376
410
|
let value;
|
|
377
411
|
try {
|
|
378
412
|
value = await pending;
|
|
379
413
|
}
|
|
380
414
|
finally {
|
|
381
|
-
this.#
|
|
415
|
+
this.#shutdownWork.delete(pending);
|
|
382
416
|
if (phaseDiagnostics.hasSubscribers)
|
|
383
417
|
phaseDiagnostics.publish({
|
|
384
418
|
logger: this.#logger,
|
|
@@ -438,6 +472,11 @@ export class ClaustrumScopedCustody {
|
|
|
438
472
|
async discover(signal) {
|
|
439
473
|
const inventory = await this.#list(signal);
|
|
440
474
|
this.#discoveredView = inventory.view;
|
|
475
|
+
this.#discoveredConditions.clear();
|
|
476
|
+
for (const { credentialId, condition } of inventory.credentials) {
|
|
477
|
+
if (condition)
|
|
478
|
+
this.#discoveredConditions.set(credentialId, condition);
|
|
479
|
+
}
|
|
441
480
|
return inventory;
|
|
442
481
|
}
|
|
443
482
|
async #list(signal) {
|
|
@@ -514,6 +553,7 @@ export class ClaustrumScopedCustody {
|
|
|
514
553
|
});
|
|
515
554
|
continue;
|
|
516
555
|
}
|
|
556
|
+
const condition = vaultConditionOf(row);
|
|
517
557
|
credentials.push(Object.freeze({
|
|
518
558
|
credentialId: row.id,
|
|
519
559
|
credentialType: type,
|
|
@@ -524,6 +564,7 @@ export class ClaustrumScopedCustody {
|
|
|
524
564
|
state: row.state,
|
|
525
565
|
...(row.email !== undefined && { email: row.email }),
|
|
526
566
|
...(row.orgName !== undefined && { orgName: row.orgName }),
|
|
567
|
+
...(condition && { condition }),
|
|
527
568
|
}));
|
|
528
569
|
}
|
|
529
570
|
for (const record of skipped)
|
|
@@ -926,6 +967,101 @@ export class ClaustrumScopedCustody {
|
|
|
926
967
|
throw error;
|
|
927
968
|
}
|
|
928
969
|
}
|
|
970
|
+
/**
|
|
971
|
+
* Report a provider login condition as bookkeeping after handing back the
|
|
972
|
+
* reply, never on the request path. Pass the receipt actually sent with it.
|
|
973
|
+
*/
|
|
974
|
+
reportCondition(attempt, input) {
|
|
975
|
+
const provenance = this.#provenance.get(attempt);
|
|
976
|
+
if (!provenance)
|
|
977
|
+
return Promise.reject(new ClaustrumConsumerError('no-receipt', 'Claustrum condition report requires an original dispatch receipt'));
|
|
978
|
+
const { reason, providerStatus } = input ?? {};
|
|
979
|
+
if (this.#closed ||
|
|
980
|
+
this.#keptAttempts.has(attempt) ||
|
|
981
|
+
providerStatus !== 403 ||
|
|
982
|
+
!isVaultConditionReason(reason))
|
|
983
|
+
return Promise.resolve('skipped');
|
|
984
|
+
const { credentialId, recordVersion } = attempt;
|
|
985
|
+
const actionUrl = reason === 'provider_verification_required'
|
|
986
|
+
? httpsActionUrl(input.actionUrl)
|
|
987
|
+
: undefined;
|
|
988
|
+
return this.#conditionOnce(this.#conditionReports, JSON.stringify([credentialId, recordVersion, reason]), { credentialId, recordVersion, reason }, (client) => client.reportCondition?.({
|
|
989
|
+
credentialId,
|
|
990
|
+
recordVersion,
|
|
991
|
+
reason,
|
|
992
|
+
providerStatus,
|
|
993
|
+
...(actionUrl !== undefined && { actionUrl }),
|
|
994
|
+
enrollmentToken: provenance.token,
|
|
995
|
+
}));
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Clear a listed condition as bookkeeping after handing back a successful
|
|
999
|
+
* reply, never on the request path. Pass the receipt actually sent with it.
|
|
1000
|
+
*/
|
|
1001
|
+
clearCondition(attempt) {
|
|
1002
|
+
const provenance = this.#provenance.get(attempt);
|
|
1003
|
+
if (!provenance)
|
|
1004
|
+
return Promise.reject(new ClaustrumConsumerError('no-receipt', 'Claustrum condition clear requires an original dispatch receipt'));
|
|
1005
|
+
if (this.#closed || this.#keptAttempts.has(attempt))
|
|
1006
|
+
return Promise.resolve('skipped');
|
|
1007
|
+
const { credentialId, recordVersion } = attempt;
|
|
1008
|
+
const condition = this.#discoveredConditions.get(credentialId);
|
|
1009
|
+
if (!condition)
|
|
1010
|
+
return Promise.resolve('skipped');
|
|
1011
|
+
return this.#conditionOnce(this.#conditionClears, JSON.stringify([credentialId, condition.sinceMs]), { credentialId, recordVersion, reason: condition.reason }, (client) => client.clearCondition?.({
|
|
1012
|
+
credentialId,
|
|
1013
|
+
recordVersion,
|
|
1014
|
+
enrollmentToken: provenance.token,
|
|
1015
|
+
}));
|
|
1016
|
+
}
|
|
1017
|
+
#conditionOnce(outcomes, key, details, send) {
|
|
1018
|
+
const previous = outcomes.get(key);
|
|
1019
|
+
if (previous)
|
|
1020
|
+
return previous;
|
|
1021
|
+
if (this.#conditionsUnsupported)
|
|
1022
|
+
return Promise.resolve('unsupported');
|
|
1023
|
+
// A lost reply may already have committed. Keep the result so a later call
|
|
1024
|
+
// for the same key does not retry it, even after client replacement.
|
|
1025
|
+
const pending = Promise.resolve().then(async () => {
|
|
1026
|
+
const client = this.#client;
|
|
1027
|
+
if (this.#conditionsUnsupported)
|
|
1028
|
+
return 'unsupported';
|
|
1029
|
+
try {
|
|
1030
|
+
const sent = send(client);
|
|
1031
|
+
if (!sent)
|
|
1032
|
+
return 'unsupported';
|
|
1033
|
+
if ((await sent) === false)
|
|
1034
|
+
this.#debugCondition('scoped login condition not cleared', details);
|
|
1035
|
+
return 'reported';
|
|
1036
|
+
}
|
|
1037
|
+
catch (error) {
|
|
1038
|
+
if (error instanceof ClaustrumCredentialError &&
|
|
1039
|
+
error.code === 'unknown_method') {
|
|
1040
|
+
if (client === this.#client)
|
|
1041
|
+
this.#conditionsUnsupported = true;
|
|
1042
|
+
return 'unsupported';
|
|
1043
|
+
}
|
|
1044
|
+
this.#debugCondition('scoped login condition update failed', details);
|
|
1045
|
+
return 'failed';
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
outcomes.set(key, pending);
|
|
1049
|
+
this.#pendingConditionCalls++;
|
|
1050
|
+
this.#shutdownWork.add(pending);
|
|
1051
|
+
void pending.then(() => {
|
|
1052
|
+
this.#pendingConditionCalls--;
|
|
1053
|
+
this.#shutdownWork.delete(pending);
|
|
1054
|
+
});
|
|
1055
|
+
return pending;
|
|
1056
|
+
}
|
|
1057
|
+
#debugCondition(message, details) {
|
|
1058
|
+
try {
|
|
1059
|
+
this.#logger.debug(message, details);
|
|
1060
|
+
}
|
|
1061
|
+
catch {
|
|
1062
|
+
// A caller's logger must not turn bookkeeping into a rejection.
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
929
1065
|
/**
|
|
930
1066
|
* Watch this consumer's visible vault accounts instead of listing them on a
|
|
931
1067
|
* short timer. Opens one `watchScoped` on this custody's client and calls
|
|
@@ -1046,16 +1182,17 @@ export class ClaustrumScopedCustody {
|
|
|
1046
1182
|
this.#watches.clear();
|
|
1047
1183
|
this.#kept.clear();
|
|
1048
1184
|
const usage = this.#usage.close();
|
|
1185
|
+
const keepClientOpen = usage !== undefined || this.#pendingConditionCalls > 0;
|
|
1049
1186
|
if (usage) {
|
|
1050
|
-
this.#
|
|
1051
|
-
void usage.then(() => this.#
|
|
1187
|
+
this.#shutdownWork.add(usage);
|
|
1188
|
+
void usage.then(() => this.#shutdownWork.delete(usage));
|
|
1052
1189
|
}
|
|
1053
|
-
|
|
1190
|
+
if (!keepClientOpen)
|
|
1054
1191
|
this.#client.close();
|
|
1055
|
-
this.#disposing = drainShutdown(this.#
|
|
1192
|
+
this.#disposing = drainShutdown(this.#shutdownWork, (count) => (this.#onDrainTimeout ?? this.#warnShutdown)(count)).finally(() => {
|
|
1056
1193
|
this.#usage.drop();
|
|
1057
1194
|
this.#usageServed.clear();
|
|
1058
|
-
if (
|
|
1195
|
+
if (keepClientOpen)
|
|
1059
1196
|
this.#client.close();
|
|
1060
1197
|
});
|
|
1061
1198
|
}
|
|
@@ -798,6 +798,38 @@ export class ClaustrumConsumer {
|
|
|
798
798
|
throw new ClaustrumConsumerError('no-receipt', 'Claustrum dispatch receipt has no active owner');
|
|
799
799
|
await this.#custody.reportFailure(attempt, status, source);
|
|
800
800
|
}
|
|
801
|
+
/** The custody (or hub lease) that issued `attempt`, or a `no-receipt` refusal. */
|
|
802
|
+
#issuingCustody(attempt) {
|
|
803
|
+
const custody = this.#hub
|
|
804
|
+
? this.#issuedBy.get(attempt)?.custody
|
|
805
|
+
: this.#custody;
|
|
806
|
+
if (!custody)
|
|
807
|
+
throw new ClaustrumConsumerError('no-receipt', 'Claustrum dispatch receipt has no active owner');
|
|
808
|
+
return custody;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Report a provider login condition through the custody that issued the
|
|
812
|
+
* receipt; see `ClaustrumScopedCustody.reportCondition`. Bookkeeping: call it
|
|
813
|
+
* after handing back the reply, never on the request path. It resolves
|
|
814
|
+
* `skipped` after shutdown and rejects only with `no-receipt` for a receipt
|
|
815
|
+
* no live custody of this consumer issued.
|
|
816
|
+
*/
|
|
817
|
+
async reportCondition(attempt, input) {
|
|
818
|
+
if (this.#shutdown.signal.aborted)
|
|
819
|
+
return 'skipped';
|
|
820
|
+
return this.#issuingCustody(attempt).reportCondition(attempt, input);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Clear a listed login condition through the custody that issued the
|
|
824
|
+
* receipt; see `ClaustrumScopedCustody.clearCondition`. Safe to call after
|
|
825
|
+
* every successful reply: it sends nothing unless the login is marked.
|
|
826
|
+
* Same `skipped` and `no-receipt` rules as `reportCondition`.
|
|
827
|
+
*/
|
|
828
|
+
async clearCondition(attempt) {
|
|
829
|
+
if (this.#shutdown.signal.aborted)
|
|
830
|
+
return 'skipped';
|
|
831
|
+
return this.#issuingCustody(attempt).clearCondition(attempt);
|
|
832
|
+
}
|
|
801
833
|
/**
|
|
802
834
|
* Send on a vault route. `dispatch` builds and sends the request with the
|
|
803
835
|
* receipt's token and may be called twice, so it must be able to rebuild
|
|
@@ -533,6 +533,16 @@ export class ClaustrumDiscoveryHub {
|
|
|
533
533
|
check();
|
|
534
534
|
return custody.reportFailure(attempt, status, source);
|
|
535
535
|
},
|
|
536
|
+
reportCondition: async (attempt, input) => {
|
|
537
|
+
if (state.released || generation.ended)
|
|
538
|
+
return 'skipped';
|
|
539
|
+
return custody.reportCondition(attempt, input);
|
|
540
|
+
},
|
|
541
|
+
clearCondition: async (attempt) => {
|
|
542
|
+
if (state.released || generation.ended)
|
|
543
|
+
return 'skipped';
|
|
544
|
+
return custody.clearCondition(attempt);
|
|
545
|
+
},
|
|
536
546
|
reportUsage: (input) => {
|
|
537
547
|
if (!state.released && !generation.ended)
|
|
538
548
|
custody.reportUsage(input);
|
|
@@ -55,6 +55,8 @@ async function request(operation) {
|
|
|
55
55
|
function wrapHostClient(client) {
|
|
56
56
|
const watchScoped = client.watchScoped?.bind(client);
|
|
57
57
|
const reportUsageScoped = client.reportUsageScoped?.bind(client);
|
|
58
|
+
const reportCondition = client.reportCondition?.bind(client);
|
|
59
|
+
const clearCondition = client.clearCondition?.bind(client);
|
|
58
60
|
return {
|
|
59
61
|
listScoped: (...args) => request(() => client.listScoped(...args)),
|
|
60
62
|
getScoped: (...args) => request(() => client.getScoped(...args)),
|
|
@@ -77,6 +79,12 @@ function wrapHostClient(client) {
|
|
|
77
79
|
...(reportUsageScoped && {
|
|
78
80
|
reportUsageScoped: (...args) => request(() => reportUsageScoped(...args)),
|
|
79
81
|
}),
|
|
82
|
+
...(reportCondition && {
|
|
83
|
+
reportCondition: (...args) => request(() => reportCondition(...args)),
|
|
84
|
+
}),
|
|
85
|
+
...(clearCondition && {
|
|
86
|
+
clearCondition: (...args) => request(() => clearCondition(...args)),
|
|
87
|
+
}),
|
|
80
88
|
...(client.insula && {
|
|
81
89
|
insula: wrapInsula(client.insula),
|
|
82
90
|
}),
|
|
@@ -178,6 +178,34 @@ function rowFactsOf(row, { includeProviderIds = true } = {}) {
|
|
|
178
178
|
authMethod: metadata.authMethod,
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
|
+
function isVaultConditionReason(reason) {
|
|
182
|
+
return (reason === 'provider_verification_required' ||
|
|
183
|
+
reason === 'provider_ineligible');
|
|
184
|
+
}
|
|
185
|
+
function vaultConditionOf(row) {
|
|
186
|
+
const condition = row.condition;
|
|
187
|
+
if (!condition)
|
|
188
|
+
return undefined;
|
|
189
|
+
const { reason, sinceMs } = condition;
|
|
190
|
+
if (isVaultConditionReason(reason) &&
|
|
191
|
+
Number.isSafeInteger(sinceMs) &&
|
|
192
|
+
sinceMs > 0)
|
|
193
|
+
return Object.freeze({ reason, sinceMs });
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
function httpsActionUrl(actionUrl) {
|
|
197
|
+
if (typeof actionUrl !== 'string')
|
|
198
|
+
return undefined;
|
|
199
|
+
try {
|
|
200
|
+
// Keep the original spelling so the vault can enforce its own link rules.
|
|
201
|
+
if (new URL(actionUrl).protocol === 'https:')
|
|
202
|
+
return actionUrl;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// An unparseable link does not invalidate the condition itself.
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
181
209
|
/**
|
|
182
210
|
* The grants named in the vault's list reply, or undefined when it names none.
|
|
183
211
|
* Both fields must be present: a reply carrying only one of them is treated as
|
|
@@ -211,6 +239,10 @@ export class ClaustrumScopedCustody {
|
|
|
211
239
|
#logger;
|
|
212
240
|
#provenance = new WeakMap();
|
|
213
241
|
#reports = new WeakMap();
|
|
242
|
+
#conditionReports = new Map();
|
|
243
|
+
#conditionClears = new Map();
|
|
244
|
+
#conditionsUnsupported = false;
|
|
245
|
+
#pendingConditionCalls = 0;
|
|
214
246
|
#kept = new Map();
|
|
215
247
|
#keptAttempts = new WeakMap();
|
|
216
248
|
#usage;
|
|
@@ -229,8 +261,9 @@ export class ClaustrumScopedCustody {
|
|
|
229
261
|
#closed = false;
|
|
230
262
|
/** The view of the last successful `discover()`, for `watchRoster`. */
|
|
231
263
|
#discoveredView;
|
|
264
|
+
#discoveredConditions = new Map();
|
|
232
265
|
#watches = new Set();
|
|
233
|
-
#
|
|
266
|
+
#shutdownWork = new Set();
|
|
234
267
|
#warnShutdown;
|
|
235
268
|
#onDrainTimeout;
|
|
236
269
|
#disposing;
|
|
@@ -292,6 +325,7 @@ export class ClaustrumScopedCustody {
|
|
|
292
325
|
if (hasVaultHost() && !isVaultHostClient(next))
|
|
293
326
|
throw new ClaustrumUnreachableError();
|
|
294
327
|
this.#client = next;
|
|
328
|
+
this.#conditionsUnsupported = false;
|
|
295
329
|
for (const watch of this.#watches)
|
|
296
330
|
watch.restart();
|
|
297
331
|
}
|
|
@@ -372,13 +406,13 @@ export class ClaustrumScopedCustody {
|
|
|
372
406
|
phase: 'token read begin',
|
|
373
407
|
});
|
|
374
408
|
const pending = this.#readToken();
|
|
375
|
-
this.#
|
|
409
|
+
this.#shutdownWork.add(pending);
|
|
376
410
|
let value;
|
|
377
411
|
try {
|
|
378
412
|
value = await pending;
|
|
379
413
|
}
|
|
380
414
|
finally {
|
|
381
|
-
this.#
|
|
415
|
+
this.#shutdownWork.delete(pending);
|
|
382
416
|
if (phaseDiagnostics.hasSubscribers)
|
|
383
417
|
phaseDiagnostics.publish({
|
|
384
418
|
logger: this.#logger,
|
|
@@ -438,6 +472,11 @@ export class ClaustrumScopedCustody {
|
|
|
438
472
|
async discover(signal) {
|
|
439
473
|
const inventory = await this.#list(signal);
|
|
440
474
|
this.#discoveredView = inventory.view;
|
|
475
|
+
this.#discoveredConditions.clear();
|
|
476
|
+
for (const { credentialId, condition } of inventory.credentials) {
|
|
477
|
+
if (condition)
|
|
478
|
+
this.#discoveredConditions.set(credentialId, condition);
|
|
479
|
+
}
|
|
441
480
|
return inventory;
|
|
442
481
|
}
|
|
443
482
|
async #list(signal) {
|
|
@@ -514,6 +553,7 @@ export class ClaustrumScopedCustody {
|
|
|
514
553
|
});
|
|
515
554
|
continue;
|
|
516
555
|
}
|
|
556
|
+
const condition = vaultConditionOf(row);
|
|
517
557
|
credentials.push(Object.freeze({
|
|
518
558
|
credentialId: row.id,
|
|
519
559
|
credentialType: type,
|
|
@@ -524,6 +564,7 @@ export class ClaustrumScopedCustody {
|
|
|
524
564
|
state: row.state,
|
|
525
565
|
...(row.email !== undefined && { email: row.email }),
|
|
526
566
|
...(row.orgName !== undefined && { orgName: row.orgName }),
|
|
567
|
+
...(condition && { condition }),
|
|
527
568
|
}));
|
|
528
569
|
}
|
|
529
570
|
for (const record of skipped)
|
|
@@ -926,6 +967,101 @@ export class ClaustrumScopedCustody {
|
|
|
926
967
|
throw error;
|
|
927
968
|
}
|
|
928
969
|
}
|
|
970
|
+
/**
|
|
971
|
+
* Report a provider login condition as bookkeeping after handing back the
|
|
972
|
+
* reply, never on the request path. Pass the receipt actually sent with it.
|
|
973
|
+
*/
|
|
974
|
+
reportCondition(attempt, input) {
|
|
975
|
+
const provenance = this.#provenance.get(attempt);
|
|
976
|
+
if (!provenance)
|
|
977
|
+
return Promise.reject(new ClaustrumConsumerError('no-receipt', 'Claustrum condition report requires an original dispatch receipt'));
|
|
978
|
+
const { reason, providerStatus } = input ?? {};
|
|
979
|
+
if (this.#closed ||
|
|
980
|
+
this.#keptAttempts.has(attempt) ||
|
|
981
|
+
providerStatus !== 403 ||
|
|
982
|
+
!isVaultConditionReason(reason))
|
|
983
|
+
return Promise.resolve('skipped');
|
|
984
|
+
const { credentialId, recordVersion } = attempt;
|
|
985
|
+
const actionUrl = reason === 'provider_verification_required'
|
|
986
|
+
? httpsActionUrl(input.actionUrl)
|
|
987
|
+
: undefined;
|
|
988
|
+
return this.#conditionOnce(this.#conditionReports, JSON.stringify([credentialId, recordVersion, reason]), { credentialId, recordVersion, reason }, (client) => client.reportCondition?.({
|
|
989
|
+
credentialId,
|
|
990
|
+
recordVersion,
|
|
991
|
+
reason,
|
|
992
|
+
providerStatus,
|
|
993
|
+
...(actionUrl !== undefined && { actionUrl }),
|
|
994
|
+
enrollmentToken: provenance.token,
|
|
995
|
+
}));
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Clear a listed condition as bookkeeping after handing back a successful
|
|
999
|
+
* reply, never on the request path. Pass the receipt actually sent with it.
|
|
1000
|
+
*/
|
|
1001
|
+
clearCondition(attempt) {
|
|
1002
|
+
const provenance = this.#provenance.get(attempt);
|
|
1003
|
+
if (!provenance)
|
|
1004
|
+
return Promise.reject(new ClaustrumConsumerError('no-receipt', 'Claustrum condition clear requires an original dispatch receipt'));
|
|
1005
|
+
if (this.#closed || this.#keptAttempts.has(attempt))
|
|
1006
|
+
return Promise.resolve('skipped');
|
|
1007
|
+
const { credentialId, recordVersion } = attempt;
|
|
1008
|
+
const condition = this.#discoveredConditions.get(credentialId);
|
|
1009
|
+
if (!condition)
|
|
1010
|
+
return Promise.resolve('skipped');
|
|
1011
|
+
return this.#conditionOnce(this.#conditionClears, JSON.stringify([credentialId, condition.sinceMs]), { credentialId, recordVersion, reason: condition.reason }, (client) => client.clearCondition?.({
|
|
1012
|
+
credentialId,
|
|
1013
|
+
recordVersion,
|
|
1014
|
+
enrollmentToken: provenance.token,
|
|
1015
|
+
}));
|
|
1016
|
+
}
|
|
1017
|
+
#conditionOnce(outcomes, key, details, send) {
|
|
1018
|
+
const previous = outcomes.get(key);
|
|
1019
|
+
if (previous)
|
|
1020
|
+
return previous;
|
|
1021
|
+
if (this.#conditionsUnsupported)
|
|
1022
|
+
return Promise.resolve('unsupported');
|
|
1023
|
+
// A lost reply may already have committed. Keep the result so a later call
|
|
1024
|
+
// for the same key does not retry it, even after client replacement.
|
|
1025
|
+
const pending = Promise.resolve().then(async () => {
|
|
1026
|
+
const client = this.#client;
|
|
1027
|
+
if (this.#conditionsUnsupported)
|
|
1028
|
+
return 'unsupported';
|
|
1029
|
+
try {
|
|
1030
|
+
const sent = send(client);
|
|
1031
|
+
if (!sent)
|
|
1032
|
+
return 'unsupported';
|
|
1033
|
+
if ((await sent) === false)
|
|
1034
|
+
this.#debugCondition('scoped login condition not cleared', details);
|
|
1035
|
+
return 'reported';
|
|
1036
|
+
}
|
|
1037
|
+
catch (error) {
|
|
1038
|
+
if (error instanceof ClaustrumCredentialError &&
|
|
1039
|
+
error.code === 'unknown_method') {
|
|
1040
|
+
if (client === this.#client)
|
|
1041
|
+
this.#conditionsUnsupported = true;
|
|
1042
|
+
return 'unsupported';
|
|
1043
|
+
}
|
|
1044
|
+
this.#debugCondition('scoped login condition update failed', details);
|
|
1045
|
+
return 'failed';
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
outcomes.set(key, pending);
|
|
1049
|
+
this.#pendingConditionCalls++;
|
|
1050
|
+
this.#shutdownWork.add(pending);
|
|
1051
|
+
void pending.then(() => {
|
|
1052
|
+
this.#pendingConditionCalls--;
|
|
1053
|
+
this.#shutdownWork.delete(pending);
|
|
1054
|
+
});
|
|
1055
|
+
return pending;
|
|
1056
|
+
}
|
|
1057
|
+
#debugCondition(message, details) {
|
|
1058
|
+
try {
|
|
1059
|
+
this.#logger.debug(message, details);
|
|
1060
|
+
}
|
|
1061
|
+
catch {
|
|
1062
|
+
// A caller's logger must not turn bookkeeping into a rejection.
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
929
1065
|
/**
|
|
930
1066
|
* Watch this consumer's visible vault accounts instead of listing them on a
|
|
931
1067
|
* short timer. Opens one `watchScoped` on this custody's client and calls
|
|
@@ -1046,16 +1182,17 @@ export class ClaustrumScopedCustody {
|
|
|
1046
1182
|
this.#watches.clear();
|
|
1047
1183
|
this.#kept.clear();
|
|
1048
1184
|
const usage = this.#usage.close();
|
|
1185
|
+
const keepClientOpen = usage !== undefined || this.#pendingConditionCalls > 0;
|
|
1049
1186
|
if (usage) {
|
|
1050
|
-
this.#
|
|
1051
|
-
void usage.then(() => this.#
|
|
1187
|
+
this.#shutdownWork.add(usage);
|
|
1188
|
+
void usage.then(() => this.#shutdownWork.delete(usage));
|
|
1052
1189
|
}
|
|
1053
|
-
|
|
1190
|
+
if (!keepClientOpen)
|
|
1054
1191
|
this.#client.close();
|
|
1055
|
-
this.#disposing = drainShutdown(this.#
|
|
1192
|
+
this.#disposing = drainShutdown(this.#shutdownWork, (count) => (this.#onDrainTimeout ?? this.#warnShutdown)(count)).finally(() => {
|
|
1056
1193
|
this.#usage.drop();
|
|
1057
1194
|
this.#usageServed.clear();
|
|
1058
|
-
if (
|
|
1195
|
+
if (keepClientOpen)
|
|
1059
1196
|
this.#client.close();
|
|
1060
1197
|
});
|
|
1061
1198
|
}
|
|
@@ -798,6 +798,38 @@ export class ClaustrumConsumer {
|
|
|
798
798
|
throw new ClaustrumConsumerError('no-receipt', 'Claustrum dispatch receipt has no active owner');
|
|
799
799
|
await this.#custody.reportFailure(attempt, status, source);
|
|
800
800
|
}
|
|
801
|
+
/** The custody (or hub lease) that issued `attempt`, or a `no-receipt` refusal. */
|
|
802
|
+
#issuingCustody(attempt) {
|
|
803
|
+
const custody = this.#hub
|
|
804
|
+
? this.#issuedBy.get(attempt)?.custody
|
|
805
|
+
: this.#custody;
|
|
806
|
+
if (!custody)
|
|
807
|
+
throw new ClaustrumConsumerError('no-receipt', 'Claustrum dispatch receipt has no active owner');
|
|
808
|
+
return custody;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Report a provider login condition through the custody that issued the
|
|
812
|
+
* receipt; see `ClaustrumScopedCustody.reportCondition`. Bookkeeping: call it
|
|
813
|
+
* after handing back the reply, never on the request path. It resolves
|
|
814
|
+
* `skipped` after shutdown and rejects only with `no-receipt` for a receipt
|
|
815
|
+
* no live custody of this consumer issued.
|
|
816
|
+
*/
|
|
817
|
+
async reportCondition(attempt, input) {
|
|
818
|
+
if (this.#shutdown.signal.aborted)
|
|
819
|
+
return 'skipped';
|
|
820
|
+
return this.#issuingCustody(attempt).reportCondition(attempt, input);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Clear a listed login condition through the custody that issued the
|
|
824
|
+
* receipt; see `ClaustrumScopedCustody.clearCondition`. Safe to call after
|
|
825
|
+
* every successful reply: it sends nothing unless the login is marked.
|
|
826
|
+
* Same `skipped` and `no-receipt` rules as `reportCondition`.
|
|
827
|
+
*/
|
|
828
|
+
async clearCondition(attempt) {
|
|
829
|
+
if (this.#shutdown.signal.aborted)
|
|
830
|
+
return 'skipped';
|
|
831
|
+
return this.#issuingCustody(attempt).clearCondition(attempt);
|
|
832
|
+
}
|
|
801
833
|
/**
|
|
802
834
|
* Send on a vault route. `dispatch` builds and sends the request with the
|
|
803
835
|
* receipt's token and may be called twice, so it must be able to rebuild
|
|
@@ -533,6 +533,16 @@ export class ClaustrumDiscoveryHub {
|
|
|
533
533
|
check();
|
|
534
534
|
return custody.reportFailure(attempt, status, source);
|
|
535
535
|
},
|
|
536
|
+
reportCondition: async (attempt, input) => {
|
|
537
|
+
if (state.released || generation.ended)
|
|
538
|
+
return 'skipped';
|
|
539
|
+
return custody.reportCondition(attempt, input);
|
|
540
|
+
},
|
|
541
|
+
clearCondition: async (attempt) => {
|
|
542
|
+
if (state.released || generation.ended)
|
|
543
|
+
return 'skipped';
|
|
544
|
+
return custody.clearCondition(attempt);
|
|
545
|
+
},
|
|
536
546
|
reportUsage: (input) => {
|
|
537
547
|
if (!state.released && !generation.ended)
|
|
538
548
|
custody.reportUsage(input);
|
|
@@ -55,6 +55,8 @@ async function request(operation) {
|
|
|
55
55
|
function wrapHostClient(client) {
|
|
56
56
|
const watchScoped = client.watchScoped?.bind(client);
|
|
57
57
|
const reportUsageScoped = client.reportUsageScoped?.bind(client);
|
|
58
|
+
const reportCondition = client.reportCondition?.bind(client);
|
|
59
|
+
const clearCondition = client.clearCondition?.bind(client);
|
|
58
60
|
return {
|
|
59
61
|
listScoped: (...args) => request(() => client.listScoped(...args)),
|
|
60
62
|
getScoped: (...args) => request(() => client.getScoped(...args)),
|
|
@@ -77,6 +79,12 @@ function wrapHostClient(client) {
|
|
|
77
79
|
...(reportUsageScoped && {
|
|
78
80
|
reportUsageScoped: (...args) => request(() => reportUsageScoped(...args)),
|
|
79
81
|
}),
|
|
82
|
+
...(reportCondition && {
|
|
83
|
+
reportCondition: (...args) => request(() => reportCondition(...args)),
|
|
84
|
+
}),
|
|
85
|
+
...(clearCondition && {
|
|
86
|
+
clearCondition: (...args) => request(() => clearCondition(...args)),
|
|
87
|
+
}),
|
|
80
88
|
...(client.insula && {
|
|
81
89
|
insula: wrapInsula(client.insula),
|
|
82
90
|
}),
|