@cortexkit/common-auth 0.11.8 → 0.12.0
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/commands/builtins.js +2 -0
- package/dist/fs/atomic-write.d.ts +13 -0
- package/dist/fs/atomic-write.js +52 -0
- package/dist/opencode2/integration.d.ts +6 -7
- package/dist/opencode2/integration.js +12 -8
- package/dist/store/attribution.js +1 -0
- package/dist/store/errors.d.ts +2 -2
- package/dist/store/identity.js +2 -0
- package/dist/store/index.d.ts +2 -1
- package/dist/store/mutate.d.ts +22 -2
- package/dist/store/mutate.js +140 -34
- package/dist/store/pool.d.ts +9 -2
- package/dist/store/pool.js +4 -0
- package/dist/store/publication.d.ts +47 -0
- package/dist/store/publication.js +304 -0
- package/dist/store/pull.js +6 -1
- package/dist/store/refresh.js +2 -0
- package/dist/store/reserved.d.ts +3 -0
- package/dist/store/reserved.js +13 -0
- package/dist/store/rows.d.ts +62 -13
- package/dist/store/rows.js +331 -42
- package/dist/store/runtime.js +13 -1
- package/dist/store/schema.d.ts +18 -0
- package/dist/store/schema.js +58 -2
- package/dist/store/torn.js +1 -1
- package/package.json +1 -1
package/dist/store/schema.js
CHANGED
|
@@ -27,6 +27,48 @@ export const REFRESH_STAMP_TOLERANCE_MS = 5 * 60_000;
|
|
|
27
27
|
* credential beside it belongs to. Older readers ignore it.
|
|
28
28
|
*/
|
|
29
29
|
export const CREDENTIAL_STAMP_KEY = POOL_KEY;
|
|
30
|
+
/** Canonical JSON: recursively sorted object keys, preserved array order. */
|
|
31
|
+
export function canonicalJson(value) {
|
|
32
|
+
const normalized = JSON.parse(JSON.stringify(value));
|
|
33
|
+
const encode = (item) => {
|
|
34
|
+
if (Array.isArray(item))
|
|
35
|
+
return `[${item.map(encode).join(',')}]`;
|
|
36
|
+
if (isRecord(item))
|
|
37
|
+
return `{${Object.keys(item)
|
|
38
|
+
.sort()
|
|
39
|
+
.map((key) => `${JSON.stringify(key)}:${encode(item[key])}`)
|
|
40
|
+
.join(',')}}`;
|
|
41
|
+
return JSON.stringify(item);
|
|
42
|
+
};
|
|
43
|
+
return encode(normalized);
|
|
44
|
+
}
|
|
45
|
+
export function canonicalDigest(value) {
|
|
46
|
+
return createHash('sha256').update(canonicalJson(value)).digest('hex');
|
|
47
|
+
}
|
|
48
|
+
export function parseReservation(raw) {
|
|
49
|
+
if (!isRecord(raw) ||
|
|
50
|
+
Object.keys(raw).length !== 1 ||
|
|
51
|
+
typeof raw.reservation !== 'string' ||
|
|
52
|
+
!raw.reservation)
|
|
53
|
+
return undefined;
|
|
54
|
+
return { reservation: raw.reservation };
|
|
55
|
+
}
|
|
56
|
+
function parseStagedStamp(raw) {
|
|
57
|
+
if (!isRecord(raw) ||
|
|
58
|
+
typeof raw.reservation !== 'string' ||
|
|
59
|
+
!raw.reservation ||
|
|
60
|
+
typeof raw.disabledReason !== 'string')
|
|
61
|
+
return undefined;
|
|
62
|
+
if (Object.keys(raw).some((key) => !['reservation', 'label', 'disabledReason', 'providerState'].includes(key)))
|
|
63
|
+
return undefined;
|
|
64
|
+
if ('label' in raw && typeof raw.label !== 'string')
|
|
65
|
+
return undefined;
|
|
66
|
+
if ('providerState' in raw &&
|
|
67
|
+
(typeof raw.providerState !== 'string' ||
|
|
68
|
+
!/^[a-f0-9]{64}$/.test(raw.providerState)))
|
|
69
|
+
return undefined;
|
|
70
|
+
return raw;
|
|
71
|
+
}
|
|
30
72
|
/**
|
|
31
73
|
* Key, inside a state-file account entry, of the provider state kept beside
|
|
32
74
|
* the credential. Older readers ignore it.
|
|
@@ -192,7 +234,11 @@ export function parseStamp(raw) {
|
|
|
192
234
|
return undefined;
|
|
193
235
|
if ('providerState' in raw && typeof raw.providerState !== 'string')
|
|
194
236
|
return undefined;
|
|
237
|
+
const staged = 'staged' in raw ? parseStagedStamp(raw.staged) : undefined;
|
|
238
|
+
if ('staged' in raw && !staged)
|
|
239
|
+
return undefined;
|
|
195
240
|
const marks = {
|
|
241
|
+
...(staged ? { staged } : {}),
|
|
196
242
|
...(typeof raw.dispatch === 'string' ? { dispatch: raw.dispatch } : {}),
|
|
197
243
|
...(raw.replace === true ? { replace: true } : {}),
|
|
198
244
|
...(typeof raw.providerState === 'string'
|
|
@@ -203,7 +249,10 @@ export function parseStamp(raw) {
|
|
|
203
249
|
// written with a binding; one without is not a stamp this store writes,
|
|
204
250
|
// and it would leave the row's identity unchecked.
|
|
205
251
|
if (!('binding' in raw))
|
|
206
|
-
return 'dispatch' in raw ||
|
|
252
|
+
return 'dispatch' in raw ||
|
|
253
|
+
'replace' in raw ||
|
|
254
|
+
'providerState' in raw ||
|
|
255
|
+
'staged' in raw
|
|
207
256
|
? undefined
|
|
208
257
|
: { credentialEpoch: epoch, digest: raw.digest };
|
|
209
258
|
const binding = raw.binding;
|
|
@@ -373,6 +422,8 @@ function parseEntry(raw, codec) {
|
|
|
373
422
|
return undefined;
|
|
374
423
|
if ('quota' in raw && !codec.validate(raw.quota))
|
|
375
424
|
return undefined;
|
|
425
|
+
if ('staged' in raw && !parseReservation(raw.staged))
|
|
426
|
+
return undefined;
|
|
376
427
|
return {
|
|
377
428
|
credentialEpoch: epoch,
|
|
378
429
|
needsFirstReading: raw.needsFirstReading === true,
|
|
@@ -532,6 +583,9 @@ export function buildRawRows(config, state, codec, providerCodec) {
|
|
|
532
583
|
for (const raw of rosterOf(config)) {
|
|
533
584
|
const problem = rosterRowProblem(raw);
|
|
534
585
|
const id = isRecord(raw) && typeof raw.id === 'string' ? raw.id : undefined;
|
|
586
|
+
const rawEntry = id === undefined ? undefined : entries[id];
|
|
587
|
+
const reserved = isRecord(rawEntry) && Object.hasOwn(rawEntry, 'staged');
|
|
588
|
+
const staged = reserved ? parseReservation(rawEntry.staged) : undefined;
|
|
535
589
|
if (problem || !isRecord(raw) || id === undefined || seen.has(id)) {
|
|
536
590
|
if (id !== undefined && !seen.has(id))
|
|
537
591
|
seen.add(id);
|
|
@@ -545,6 +599,7 @@ export function buildRawRows(config, state, codec, providerCodec) {
|
|
|
545
599
|
candidate: false,
|
|
546
600
|
invalid: 'roster',
|
|
547
601
|
stamp: 'none',
|
|
602
|
+
...(staged ? { staged } : {}),
|
|
548
603
|
});
|
|
549
604
|
continue;
|
|
550
605
|
}
|
|
@@ -574,6 +629,7 @@ export function buildRawRows(config, state, codec, providerCodec) {
|
|
|
574
629
|
? { credential, fingerprint: fingerprintOf(credential) }
|
|
575
630
|
: {}),
|
|
576
631
|
...(entry ? { credentialEpoch: entry.credentialEpoch } : {}),
|
|
632
|
+
...(staged ? { staged } : {}),
|
|
577
633
|
...(entry?.disabledReason !== undefined
|
|
578
634
|
? { disabledReason: entry.disabledReason }
|
|
579
635
|
: {}),
|
|
@@ -585,7 +641,7 @@ export function buildRawRows(config, state, codec, providerCodec) {
|
|
|
585
641
|
row.invalid = 'entry';
|
|
586
642
|
}
|
|
587
643
|
else {
|
|
588
|
-
row.candidate = enabled && credential !== undefined;
|
|
644
|
+
row.candidate = enabled && credential !== undefined && !reserved;
|
|
589
645
|
}
|
|
590
646
|
rows.push(row);
|
|
591
647
|
}
|
package/dist/store/torn.js
CHANGED
|
@@ -140,7 +140,7 @@ export function tornStamps(config, state, codec, options = {}) {
|
|
|
140
140
|
const accounts = isRecord(state.accounts) ? state.accounts : {};
|
|
141
141
|
const torn = new Map();
|
|
142
142
|
for (const row of buildRawRows(config, state, codec)) {
|
|
143
|
-
if (row.invalid || !row.credential)
|
|
143
|
+
if (row.invalid || row.staged || !row.credential)
|
|
144
144
|
continue;
|
|
145
145
|
const account = Object.hasOwn(accounts, row.id)
|
|
146
146
|
? accounts[row.id]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/common-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|