@cortexkit/opencode-antigravity-auth 3.0.11 → 3.0.12
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/cli.js +1607 -1189
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +164 -102
- package/dist/index.js +1752 -1333
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +167 -105
- package/dist/server.js +1752 -1333
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +7 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +17 -2
- package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -1
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
- package/dist/src/common-auth-embedded/claustrum/quota-writer.js +4 -54
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +31 -0
- package/dist/src/common-auth-embedded/claustrum/roster.js +72 -0
- package/dist/src/common-auth-embedded/commands/builtins.d.ts +37 -0
- package/dist/src/common-auth-embedded/commands/builtins.js +95 -13
- package/dist/src/common-auth-embedded/commands/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +3 -2
- package/dist/src/common-auth-embedded/opencode2/install.js +184 -63
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +43 -6
- package/dist/src/common-auth-embedded/quota/pending.js +48 -0
- package/dist/src/common-auth-embedded/setup/enroll.d.ts +1 -1
- package/dist/src/common-auth-embedded/setup/enroll.js +1 -1
- package/dist/src/common-auth-embedded/source-output.json +89 -73
- package/dist/src/common-auth-embedded/store/attribution.d.ts +5 -0
- package/dist/src/common-auth-embedded/store/attribution.js +39 -25
- package/dist/src/common-auth-embedded/store/pool.d.ts +17 -0
- package/dist/src/common-auth-embedded/store/pool.js +18 -3
- package/dist/src/common-auth-embedded/store/pull.js +3 -1
- package/dist/src/common-auth-embedded/store/quota-writer.js +298 -0
- package/dist/src/common-auth-embedded/store/runtime.d.ts +2 -0
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +1 -0
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/vault-custody.js +2 -2
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +31 -0
- package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +37 -0
- package/dist/types/src/common-auth-embedded/commands/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +3 -2
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +43 -6
- package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/attribution.d.ts +5 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +17 -0
- package/dist/types/src/common-auth-embedded/store/runtime.d.ts +2 -0
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/consumer.d.ts +7 -1
- package/src/common-auth-embedded/claustrum/consumer.js +17 -2
- package/src/common-auth-embedded/claustrum/errors.d.ts +1 -1
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/claustrum/index.js +1 -1
- package/src/common-auth-embedded/claustrum/quota-writer.js +4 -54
- package/src/common-auth-embedded/claustrum/roster.d.ts +31 -0
- package/src/common-auth-embedded/claustrum/roster.js +72 -0
- package/src/common-auth-embedded/commands/builtins.d.ts +37 -0
- package/src/common-auth-embedded/commands/builtins.js +95 -13
- package/src/common-auth-embedded/commands/index.d.ts +1 -1
- package/src/common-auth-embedded/opencode2/install.d.ts +3 -2
- package/src/common-auth-embedded/opencode2/install.js +184 -63
- package/src/common-auth-embedded/opencode2/types.d.ts +43 -6
- package/src/common-auth-embedded/quota/pending.js +48 -0
- package/src/common-auth-embedded/setup/enroll.d.ts +1 -1
- package/src/common-auth-embedded/setup/enroll.js +1 -1
- package/src/common-auth-embedded/source-output.json +89 -73
- package/src/common-auth-embedded/store/attribution.d.ts +5 -0
- package/src/common-auth-embedded/store/attribution.js +39 -25
- package/src/common-auth-embedded/store/pool.d.ts +17 -0
- package/src/common-auth-embedded/store/pool.js +18 -3
- package/src/common-auth-embedded/store/pull.js +3 -1
- package/src/common-auth-embedded/store/quota-writer.js +298 -0
- package/src/common-auth-embedded/store/runtime.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -3196,13 +3196,40 @@ var init_runtime = __esm({
|
|
|
3196
3196
|
});
|
|
3197
3197
|
|
|
3198
3198
|
// ../core/dist/common-auth-embedded/store/attribution.js
|
|
3199
|
+
function assertQuotaEpoch(id, attribution) {
|
|
3200
|
+
if (!isCredentialEpoch(attribution?.credentialEpoch))
|
|
3201
|
+
throw refusal2("pull", id, "invalid-input", "the credential epoch the reading was issued for must be a positive safe integer");
|
|
3202
|
+
}
|
|
3203
|
+
function assertQuotaRow(id, attribution, row) {
|
|
3204
|
+
if (!row)
|
|
3205
|
+
throw unknownRow("pull", id);
|
|
3206
|
+
if (row.invalid)
|
|
3207
|
+
throw refusal2("pull", id, "invalid-row", `row ${id} is invalid`);
|
|
3208
|
+
if (!row.credential)
|
|
3209
|
+
throw refusal2("pull", id, "no-credential", `row ${id} holds no credential`);
|
|
3210
|
+
requireBound("pull", row);
|
|
3211
|
+
if (row.torn || !row.hasEntry || row.credentialEpoch !== attribution.credentialEpoch || row.identity !== attribution.identity)
|
|
3212
|
+
throw new PoolOperationError({
|
|
3213
|
+
operation: "pull",
|
|
3214
|
+
rowId: id,
|
|
3215
|
+
phase: "pull",
|
|
3216
|
+
retryable: true,
|
|
3217
|
+
kind: "attribution",
|
|
3218
|
+
message: `quota for ${id} was issued for a credential the row no longer holds`
|
|
3219
|
+
});
|
|
3220
|
+
}
|
|
3221
|
+
function mergedQuota(ctx, id, stored, observation) {
|
|
3222
|
+
const merged = ctx.codec.merge(stored, observation);
|
|
3223
|
+
if (!ctx.codec.validate(merged))
|
|
3224
|
+
throw refusal2("pull", id, "invalid-quota", "the quota codec rejected the merged map");
|
|
3225
|
+
return merged;
|
|
3226
|
+
}
|
|
3199
3227
|
async function recordQuota(rt, id, attribution, observation) {
|
|
3200
3228
|
const { ctx } = rt;
|
|
3201
3229
|
const locks = new LockStack(ctx.lockDefaults, ctx.lockEnv);
|
|
3202
3230
|
const progress = { writes: 0 };
|
|
3203
3231
|
try {
|
|
3204
|
-
|
|
3205
|
-
throw refusal2("pull", id, "invalid-input", "the credential epoch the reading was issued for must be a positive safe integer");
|
|
3232
|
+
assertQuotaEpoch(id, attribution);
|
|
3206
3233
|
await withTransaction(
|
|
3207
3234
|
ctx,
|
|
3208
3235
|
locks,
|
|
@@ -3211,26 +3238,11 @@ async function recordQuota(rt, id, attribution, observation) {
|
|
|
3211
3238
|
async (tx) => {
|
|
3212
3239
|
tx.assertNotStaged(id);
|
|
3213
3240
|
const row = tx.row(id);
|
|
3214
|
-
|
|
3215
|
-
throw unknownRow("pull", id);
|
|
3216
|
-
if (row.invalid)
|
|
3217
|
-
throw refusal2("pull", id, "invalid-row", `row ${id} is invalid`);
|
|
3218
|
-
if (!row.credential)
|
|
3219
|
-
throw refusal2("pull", id, "no-credential", `row ${id} holds no credential`);
|
|
3220
|
-
requireBound("pull", row);
|
|
3241
|
+
assertQuotaRow(id, attribution, row);
|
|
3221
3242
|
const entry = tx.entry(id);
|
|
3222
|
-
if (
|
|
3223
|
-
throw
|
|
3224
|
-
|
|
3225
|
-
rowId: id,
|
|
3226
|
-
phase: "pull",
|
|
3227
|
-
retryable: true,
|
|
3228
|
-
kind: "attribution",
|
|
3229
|
-
message: `quota for ${id} was issued for a credential the row no longer holds`
|
|
3230
|
-
});
|
|
3231
|
-
const merged = ctx.codec.merge(entry.quota, observation);
|
|
3232
|
-
if (!ctx.codec.validate(merged))
|
|
3233
|
-
throw refusal2("pull", id, "invalid-quota", "the quota codec rejected the merged map");
|
|
3243
|
+
if (!entry)
|
|
3244
|
+
throw unknownRow("pull", id);
|
|
3245
|
+
const merged = mergedQuota(ctx, id, entry.quota, observation);
|
|
3234
3246
|
tx.setEntry(id, { ...entry, quota: merged, needsFirstReading: false });
|
|
3235
3247
|
await tx.commitConfig();
|
|
3236
3248
|
},
|
|
@@ -4640,7 +4652,8 @@ var init_pull = __esm({
|
|
|
4640
4652
|
cause
|
|
4641
4653
|
});
|
|
4642
4654
|
}
|
|
4643
|
-
|
|
4655
|
+
const publish = rt.publishQuota ?? ((rowId2, attribution, value) => recordQuota(rt, rowId2, attribution, value));
|
|
4656
|
+
await publish(id, {
|
|
4644
4657
|
credentialEpoch: request.credentialEpoch,
|
|
4645
4658
|
...request.identity !== void 0 ? { identity: request.identity } : {}
|
|
4646
4659
|
}, observation);
|
|
@@ -4670,1378 +4683,1655 @@ var init_pull = __esm({
|
|
|
4670
4683
|
}
|
|
4671
4684
|
});
|
|
4672
4685
|
|
|
4673
|
-
// ../core/dist/common-auth-embedded/
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
throw refusal2("refresh", id, "row-disabled", `row ${id} is disabled`);
|
|
4685
|
-
return row;
|
|
4686
|
-
}
|
|
4687
|
-
function stampAhead(id) {
|
|
4688
|
-
return refusal2("refresh", id, "refresh-stamp-ahead", `row ${id}'s stored refresh stamp is ahead of the clock; a rotation now could not be stamped newer within the trust bound`, true);
|
|
4689
|
-
}
|
|
4690
|
-
async function refreshRow(rt, id, provider2, options = {}) {
|
|
4691
|
-
assertNotInsideHook("refresh");
|
|
4692
|
-
const { ctx } = rt;
|
|
4693
|
-
return runOperation(ctx, "refresh", id, options.onFailure, async (locks, progress) => {
|
|
4694
|
-
const { row: seen } = await readRow(rt, "refresh", id);
|
|
4695
|
-
requireRefreshable(id, seen);
|
|
4696
|
-
const early = await options.refuse?.(seen);
|
|
4697
|
-
if (early !== void 0)
|
|
4698
|
-
return { status: "refused", rowId: id, reason: early };
|
|
4699
|
-
let key = rowLockKey(seen);
|
|
4700
|
-
let captured;
|
|
4701
|
-
for (let attempt = 0; ; attempt++) {
|
|
4702
|
-
await locks.acquire(rowLockSpec(rt, { id, identity: key === id ? void 0 : key }));
|
|
4703
|
-
await locks.acquire(options.providerLock ?? rt.providerLock);
|
|
4704
|
-
for (const extra of options.extraLocks ?? [])
|
|
4705
|
-
await locks.acquire(extra);
|
|
4706
|
-
const captureProgress = { writes: 0 };
|
|
4707
|
-
const read = await withTransaction(ctx, locks, captureProgress, { operation: "refresh", rowId: id }, async (tx) => {
|
|
4708
|
-
let row = requireRefreshable(id, tx.row(id));
|
|
4709
|
-
requireBound("refresh", row);
|
|
4710
|
-
if (!row.hasEntry) {
|
|
4711
|
-
tx.setEntry(id, { credentialEpoch: 1, needsFirstReading: true });
|
|
4712
|
-
await tx.commitConfig();
|
|
4713
|
-
row = requireRefreshable(id, tx.row(id));
|
|
4714
|
-
}
|
|
4715
|
-
if (rowLockKey(row) !== key)
|
|
4716
|
-
return { keyNow: rowLockKey(row) };
|
|
4717
|
-
const reason = await options.refuse?.(row);
|
|
4718
|
-
if (reason !== void 0)
|
|
4719
|
-
return { refused: reason };
|
|
4720
|
-
return {
|
|
4721
|
-
row,
|
|
4722
|
-
credential: row.credential,
|
|
4723
|
-
credentialEpoch: row.credentialEpoch,
|
|
4724
|
-
identity: row.identity
|
|
4725
|
-
};
|
|
4726
|
-
});
|
|
4727
|
-
if ("refused" in read)
|
|
4728
|
-
return { status: "refused", rowId: id, reason: read.refused };
|
|
4729
|
-
if ("keyNow" in read) {
|
|
4730
|
-
await locks.releaseAll();
|
|
4731
|
-
if (attempt >= 1)
|
|
4732
|
-
throw refusal2("refresh", id, "row-key-changed", `row ${id}'s wire identity changed twice while its lock was held`, true);
|
|
4733
|
-
key = read.keyNow;
|
|
4734
|
-
continue;
|
|
4735
|
-
}
|
|
4736
|
-
captured = read;
|
|
4737
|
-
break;
|
|
4738
|
-
}
|
|
4739
|
-
if (rotationStampUntrusted(captured.credential.lastRefreshedAt, ctx.now()))
|
|
4740
|
-
throw stampAhead(id);
|
|
4741
|
-
await ctx.hold?.("refresh-before-provider", id);
|
|
4742
|
-
await locks.assertAll();
|
|
4743
|
-
let result;
|
|
4744
|
-
try {
|
|
4745
|
-
result = await provider2(captured.credential, captured.row);
|
|
4746
|
-
} catch (cause) {
|
|
4747
|
-
throw new PoolOperationError({
|
|
4748
|
-
operation: "refresh",
|
|
4749
|
-
rowId: id,
|
|
4750
|
-
phase: "before-first-write",
|
|
4751
|
-
retryable: true,
|
|
4752
|
-
kind: "provider",
|
|
4753
|
-
message: "the provider refresh failed",
|
|
4754
|
-
cause
|
|
4755
|
-
});
|
|
4756
|
-
}
|
|
4757
|
-
if (typeof result?.refresh !== "string" || !result.refresh.trim())
|
|
4758
|
-
throw refusal2("refresh", id, "provider", "the provider returned no refresh token", true);
|
|
4759
|
-
const incoming = result.providerState === void 0 ? void 0 : acceptProviderState(ctx.providerState, "refresh", id, result.providerState, "the provider state the provider returned");
|
|
4760
|
-
const commit = await withTransaction(ctx, locks, progress, { operation: "refresh", rowId: id }, async (tx) => {
|
|
4761
|
-
const current = tx.row(id);
|
|
4762
|
-
const entry = tx.entry(id);
|
|
4763
|
-
if (!current || current.invalid || !entry || entry.credentialEpoch !== captured.credentialEpoch || current.identity !== captured.identity)
|
|
4764
|
-
throw new PoolOperationError({
|
|
4765
|
-
operation: "refresh",
|
|
4766
|
-
rowId: id,
|
|
4767
|
-
phase: "before-first-write",
|
|
4768
|
-
retryable: true,
|
|
4769
|
-
kind: "attribution",
|
|
4770
|
-
message: `row ${id} changed credential while its refresh was in flight; the rotation is discarded`
|
|
4771
|
-
});
|
|
4772
|
-
requireBound("refresh", current);
|
|
4773
|
-
const reason = await options.refuse?.(current);
|
|
4774
|
-
if (reason !== void 0)
|
|
4775
|
-
return { refused: reason };
|
|
4776
|
-
const now = ctx.now();
|
|
4777
|
-
const prior = current.credential?.type === "oauth" ? current.credential.lastRefreshedAt : void 0;
|
|
4778
|
-
if (rotationStampUntrusted(prior, now))
|
|
4779
|
-
throw stampAhead(id);
|
|
4780
|
-
const credential = {
|
|
4781
|
-
type: "oauth",
|
|
4782
|
-
access: result.access,
|
|
4783
|
-
refresh: result.refresh,
|
|
4784
|
-
expires: result.expires
|
|
4785
|
-
};
|
|
4786
|
-
const contradiction = current.identity !== void 0 && result.identity !== void 0 && current.identity !== result.identity ? {
|
|
4787
|
-
expectedIdentity: current.identity,
|
|
4788
|
-
returnedIdentity: result.identity
|
|
4789
|
-
} : void 0;
|
|
4790
|
-
const transition = contradiction ? {
|
|
4791
|
-
mark: randomUUID11(),
|
|
4792
|
-
enabled: false,
|
|
4793
|
-
reason: `${IDENTITY_CONTRADICTED_REASON_PREFIX}${JSON.stringify(contradiction)}`
|
|
4794
|
-
} : void 0;
|
|
4795
|
-
const learnt = current.identity === void 0 && result.identity ? result.identity : void 0;
|
|
4796
|
-
const stored = await rotateIn(rt, tx, id, credential, {
|
|
4797
|
-
stamp: rotationStamp(prior, now),
|
|
4798
|
-
// Write state first with the disable marker, then config below.
|
|
4799
|
-
// Once the successor is durable, recovery projects the disable even
|
|
4800
|
-
// if config has not landed. A crash before the first rename still
|
|
4801
|
-
// loses an in-memory provider reply, as in any ordinary refresh.
|
|
4802
|
-
transition,
|
|
4803
|
-
identity: learnt,
|
|
4804
|
-
...incoming !== void 0 ? {
|
|
4805
|
-
providerState: mergedProviderState(ctx.providerState, "refresh", id, current.providerState, incoming)
|
|
4806
|
-
} : {}
|
|
4807
|
-
});
|
|
4808
|
-
if (transition !== void 0) {
|
|
4809
|
-
applyTransition(tx, id, transition);
|
|
4810
|
-
await tx.commitConfig();
|
|
4811
|
-
}
|
|
4812
|
-
let identity = current.identity;
|
|
4813
|
-
if (learnt !== void 0) {
|
|
4814
|
-
recordIdentityIn(tx, id, learnt);
|
|
4815
|
-
identity = learnt;
|
|
4816
|
-
await tx.commitConfig();
|
|
4817
|
-
}
|
|
4818
|
-
return { stored, identity, contradiction, refused: void 0 };
|
|
4819
|
-
});
|
|
4820
|
-
if (commit.refused !== void 0)
|
|
4821
|
-
return { status: "refused", rowId: id, reason: commit.refused };
|
|
4822
|
-
if (commit.contradiction !== void 0)
|
|
4823
|
-
return {
|
|
4824
|
-
status: "identity-contradicted",
|
|
4825
|
-
rowId: id,
|
|
4826
|
-
...commit.contradiction,
|
|
4827
|
-
credential: commit.stored
|
|
4828
|
-
};
|
|
4829
|
-
if (options.onPersisted) {
|
|
4830
|
-
try {
|
|
4831
|
-
const persisted = options.onPersisted;
|
|
4832
|
-
await runInsideHook("refresh", () => persisted(id, commit.stored));
|
|
4833
|
-
} catch (cause) {
|
|
4834
|
-
throw new PoolOperationError({
|
|
4835
|
-
operation: "refresh",
|
|
4836
|
-
rowId: id,
|
|
4837
|
-
phase: "after-first-write",
|
|
4838
|
-
retryable: false,
|
|
4839
|
-
kind: "after-persist-hook",
|
|
4840
|
-
committed: commit.stored,
|
|
4841
|
-
message: "the after-persist hook threw; the rotation stays committed",
|
|
4842
|
-
cause
|
|
4843
|
-
});
|
|
4844
|
-
}
|
|
4686
|
+
// ../core/dist/common-auth-embedded/logger/capture-sink.js
|
|
4687
|
+
function createCaptureSink() {
|
|
4688
|
+
const records = [];
|
|
4689
|
+
const sink = (record3) => {
|
|
4690
|
+
records.push(record3);
|
|
4691
|
+
};
|
|
4692
|
+
return {
|
|
4693
|
+
records,
|
|
4694
|
+
sink,
|
|
4695
|
+
clear: () => {
|
|
4696
|
+
records.length = 0;
|
|
4845
4697
|
}
|
|
4846
|
-
|
|
4847
|
-
status: "rotated",
|
|
4848
|
-
rowId: id,
|
|
4849
|
-
credential: commit.stored,
|
|
4850
|
-
...commit.identity !== void 0 ? { identity: commit.identity } : {}
|
|
4851
|
-
};
|
|
4852
|
-
});
|
|
4698
|
+
};
|
|
4853
4699
|
}
|
|
4854
|
-
var
|
|
4855
|
-
"../core/dist/common-auth-embedded/
|
|
4700
|
+
var init_capture_sink = __esm({
|
|
4701
|
+
"../core/dist/common-auth-embedded/logger/capture-sink.js"() {
|
|
4856
4702
|
"use strict";
|
|
4857
|
-
init_errors();
|
|
4858
|
-
init_hooks();
|
|
4859
|
-
init_identity();
|
|
4860
|
-
init_mutate();
|
|
4861
|
-
init_provider_state();
|
|
4862
|
-
init_reserved();
|
|
4863
|
-
init_rows();
|
|
4864
|
-
init_runtime();
|
|
4865
|
-
init_schema();
|
|
4866
|
-
init_torn();
|
|
4867
4703
|
}
|
|
4868
4704
|
});
|
|
4869
4705
|
|
|
4870
|
-
// ../core/dist/common-auth-embedded/
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
const settings = {};
|
|
4874
|
-
for (const [key, value] of Object.entries(config))
|
|
4875
|
-
if (!POOL_OWNED_KEYS.includes(key))
|
|
4876
|
-
defineKey(settings, key, value);
|
|
4877
|
-
return settings;
|
|
4878
|
-
}
|
|
4879
|
-
function defineKey(target, key, value) {
|
|
4880
|
-
Object.defineProperty(target, key, {
|
|
4881
|
-
value,
|
|
4882
|
-
enumerable: true,
|
|
4883
|
-
writable: true,
|
|
4884
|
-
configurable: true
|
|
4885
|
-
});
|
|
4706
|
+
// ../core/dist/common-auth-embedded/logger/redact.js
|
|
4707
|
+
function isError(value) {
|
|
4708
|
+
return value instanceof Error || Object.prototype.toString.call(value) === "[object Error]";
|
|
4886
4709
|
}
|
|
4887
|
-
function
|
|
4888
|
-
const
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
else if (Object.hasOwn(next, key))
|
|
4893
|
-
defineKey(out, key, next[key]);
|
|
4710
|
+
function createRedactor(options = {}) {
|
|
4711
|
+
const patterns = [TOKEN_VALUE, ...options.extraValuePatterns ?? []].map((pattern) => new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`));
|
|
4712
|
+
function isSecretKey(key) {
|
|
4713
|
+
const normalized = key.toLowerCase().replace(/[-_]/g, "");
|
|
4714
|
+
return SECRET_KEY_EXACT.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
4894
4715
|
}
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
}
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
for (const extra of options.extraLocks ?? [])
|
|
4921
|
-
await locks.acquire(extra);
|
|
4922
|
-
const mark = locks.held.length;
|
|
4716
|
+
function errorEntries(error) {
|
|
4717
|
+
const fields2 = error;
|
|
4718
|
+
const entries = [
|
|
4719
|
+
["name", error.name],
|
|
4720
|
+
["message", error.message],
|
|
4721
|
+
["stack", error.stack]
|
|
4722
|
+
];
|
|
4723
|
+
for (const key of ["code", "status", "cause"])
|
|
4724
|
+
if (fields2[key] !== void 0)
|
|
4725
|
+
entries.push([key, fields2[key]]);
|
|
4726
|
+
const listed = new Set(entries.map(([key]) => key));
|
|
4727
|
+
for (const entry of Object.entries(error))
|
|
4728
|
+
if (!listed.has(entry[0]))
|
|
4729
|
+
entries.push(entry);
|
|
4730
|
+
return entries;
|
|
4731
|
+
}
|
|
4732
|
+
function walk(value, keys, seen, errorDepth = 0) {
|
|
4733
|
+
if (typeof value === "string") {
|
|
4734
|
+
return patterns.reduce((text2, pattern) => text2.replace(pattern, MASK), value);
|
|
4735
|
+
}
|
|
4736
|
+
if (!value || typeof value !== "object")
|
|
4737
|
+
return value;
|
|
4738
|
+
if (seen.has(value))
|
|
4739
|
+
return "[Circular]";
|
|
4740
|
+
seen.add(value);
|
|
4923
4741
|
try {
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
const
|
|
4927
|
-
if (
|
|
4928
|
-
|
|
4929
|
-
const
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
throw settingsRefusal("the settings mutator must produce an object");
|
|
4935
|
-
const owned = POOL_OWNED_KEYS.filter((key) => Object.hasOwn(next, key));
|
|
4936
|
-
if (owned.length > 0)
|
|
4937
|
-
throw settingsRefusal(`settings cannot set the pool-owned key(s) ${owned.join(", ")}`);
|
|
4938
|
-
if (isDeepStrictEqual3(next, current))
|
|
4939
|
-
return { settings: current, outcome: "unchanged" };
|
|
4940
|
-
const config = composeConfig(result.config, next);
|
|
4941
|
-
const info = { operation: "updateSettings", rowId: void 0 };
|
|
4942
|
-
await writeJsonAtomic2(ctx.configPath, config, {
|
|
4943
|
-
beforeRename: async () => {
|
|
4944
|
-
await ctx.onStep?.("before-config-write", info);
|
|
4945
|
-
await locks.assertAll();
|
|
4946
|
-
}
|
|
4947
|
-
});
|
|
4948
|
-
progress.writes++;
|
|
4949
|
-
await ctx.onStep?.("after-config-write", info);
|
|
4950
|
-
return { settings: settingsOf2(config), outcome: "updated" };
|
|
4742
|
+
if (Array.isArray(value))
|
|
4743
|
+
return value.map((item) => walk(item, keys, seen, errorDepth));
|
|
4744
|
+
const error = isError(value);
|
|
4745
|
+
if (error && errorDepth >= MAX_ERROR_DEPTH)
|
|
4746
|
+
return "[Truncated]";
|
|
4747
|
+
const childDepth = error ? errorDepth + 1 : errorDepth;
|
|
4748
|
+
return Object.fromEntries((error ? errorEntries(value) : Object.entries(value)).map(([key, item]) => [
|
|
4749
|
+
key,
|
|
4750
|
+
keys && isSecretKey(key) ? MASK : walk(item, keys, seen, childDepth)
|
|
4751
|
+
]));
|
|
4951
4752
|
} finally {
|
|
4952
|
-
|
|
4753
|
+
seen.delete(value);
|
|
4953
4754
|
}
|
|
4954
|
-
}
|
|
4755
|
+
}
|
|
4756
|
+
return {
|
|
4757
|
+
redact: (value) => walk(value, true, /* @__PURE__ */ new WeakSet()),
|
|
4758
|
+
// Schema keys describe arguments, not credentials; only their string values are scrubbed.
|
|
4759
|
+
redactStrings: (value) => walk(value, false, /* @__PURE__ */ new WeakSet())
|
|
4760
|
+
};
|
|
4955
4761
|
}
|
|
4956
|
-
var
|
|
4957
|
-
var
|
|
4958
|
-
"../core/dist/common-auth-embedded/
|
|
4762
|
+
var SECRET_KEY_EXACT, TOKEN_VALUE, MASK, MAX_ERROR_DEPTH, defaultRedactor, redact, redactStrings;
|
|
4763
|
+
var init_redact = __esm({
|
|
4764
|
+
"../core/dist/common-auth-embedded/logger/redact.js"() {
|
|
4959
4765
|
"use strict";
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
"accounts",
|
|
4968
|
-
POOL_KEY
|
|
4969
|
-
]);
|
|
4766
|
+
SECRET_KEY_EXACT = /^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i;
|
|
4767
|
+
TOKEN_VALUE = /\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;
|
|
4768
|
+
MASK = "***REDACTED***";
|
|
4769
|
+
MAX_ERROR_DEPTH = 8;
|
|
4770
|
+
defaultRedactor = createRedactor();
|
|
4771
|
+
redact = defaultRedactor.redact;
|
|
4772
|
+
redactStrings = defaultRedactor.redactStrings;
|
|
4970
4773
|
}
|
|
4971
4774
|
});
|
|
4972
4775
|
|
|
4973
|
-
// ../core/dist/common-auth-embedded/
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4776
|
+
// ../core/dist/common-auth-embedded/logger/engine.js
|
|
4777
|
+
import { appendFileSync, chmodSync, existsSync, renameSync, statSync } from "node:fs";
|
|
4778
|
+
import { open as open5 } from "node:fs/promises";
|
|
4779
|
+
import { dirname as dirname8, resolve as resolve3 } from "node:path";
|
|
4780
|
+
function chmodPrivate(path5) {
|
|
4781
|
+
try {
|
|
4782
|
+
chmodSync(path5, 384);
|
|
4783
|
+
} catch {
|
|
4979
4784
|
}
|
|
4980
|
-
return memory;
|
|
4981
|
-
}
|
|
4982
|
-
function toLoad(result) {
|
|
4983
|
-
if (result.status === "ready")
|
|
4984
|
-
return {
|
|
4985
|
-
status: "ready",
|
|
4986
|
-
schemaVersion: POOL_SCHEMA_VERSION,
|
|
4987
|
-
rows: result.rows
|
|
4988
|
-
};
|
|
4989
|
-
if (result.status === "pending-migration")
|
|
4990
|
-
return {
|
|
4991
|
-
status: "pending-migration",
|
|
4992
|
-
roster: Array.isArray(result.config.accounts) ? result.config.accounts : []
|
|
4993
|
-
};
|
|
4994
|
-
return result;
|
|
4995
4785
|
}
|
|
4996
|
-
function
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
statePath: options.statePath,
|
|
5006
|
-
codec: options.quota,
|
|
5007
|
-
...options.providerState ? { providerState: options.providerState } : {},
|
|
5008
|
-
now: options.now ?? Date.now,
|
|
5009
|
-
storeLocks: options.storeLocks ?? [
|
|
5010
|
-
{ name: "save", path: options.configPath },
|
|
5011
|
-
{ name: "save", path: options.statePath }
|
|
5012
|
-
],
|
|
5013
|
-
lockDefaults,
|
|
5014
|
-
lockEnv: {
|
|
5015
|
-
...options.onLockEvent ? { onLockEvent: options.onLockEvent } : {},
|
|
5016
|
-
...options.onLockStep ? { onLockStep: options.onLockStep } : {},
|
|
5017
|
-
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
5018
|
-
},
|
|
5019
|
-
removedIds: memory.removedIds,
|
|
5020
|
-
requireCredentialStamps: options.requireCredentialStamps === true,
|
|
5021
|
-
requireRemovedFingerprint: options.requireRemovedFingerprint === true,
|
|
5022
|
-
...options.logger ? { logger: options.logger } : {},
|
|
5023
|
-
...options.onStep ? { onStep: options.onStep } : {},
|
|
5024
|
-
...options.hold ? { hold: options.hold } : {}
|
|
5025
|
-
};
|
|
5026
|
-
const pulls = new PullScheduler(() => rt, options.pull, options.onPullFailure, memory.firedAtLoad, options.logger);
|
|
5027
|
-
const rt = {
|
|
5028
|
-
ctx,
|
|
5029
|
-
providerLock: options.providerLock ?? {
|
|
5030
|
-
name: `provider-${encodeURIComponent(options.provider)}`,
|
|
5031
|
-
path: options.statePath
|
|
5032
|
-
},
|
|
5033
|
-
rowLockOptions: options.rowLockOptions ?? {},
|
|
5034
|
-
firePull: (id, reason) => pulls.fire(id, reason)
|
|
5035
|
-
};
|
|
5036
|
-
return {
|
|
5037
|
-
async load() {
|
|
5038
|
-
const result = await readPool(ctx);
|
|
5039
|
-
if (result.status === "ready") {
|
|
5040
|
-
for (const row of result.rows)
|
|
5041
|
-
if ((row.candidate || row.torn && row.enabled) && row.type === "oauth" && row.needsFirstReading)
|
|
5042
|
-
pulls.fire(row.id, "load");
|
|
4786
|
+
function rotateIfNeeded(f) {
|
|
4787
|
+
try {
|
|
4788
|
+
if (!(existsSync(f) && statSync(f).size >= MAX_BYTES))
|
|
4789
|
+
return;
|
|
4790
|
+
for (let i = ROTATE_KEEP - 1; i >= 1; i--) {
|
|
4791
|
+
if (existsSync(`${f}.${i}`)) {
|
|
4792
|
+
const rotated2 = `${f}.${i + 1}`;
|
|
4793
|
+
renameSync(`${f}.${i}`, rotated2);
|
|
4794
|
+
chmodPrivate(rotated2);
|
|
5043
4795
|
}
|
|
5044
|
-
|
|
5045
|
-
}
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
async initialize(input2 = {}) {
|
|
5050
|
-
return { status: await initializePool(ctx, input2.dropKeys ?? []) };
|
|
5051
|
-
},
|
|
5052
|
-
add: (input2, callOptions) => addRow(rt, input2, callOptions),
|
|
5053
|
-
publishRoster: (plan, callOptions) => publishRoster(rt, plan, callOptions),
|
|
5054
|
-
publication: (operationId) => publication(rt, operationId),
|
|
5055
|
-
replace: (id, credential, input2, callOptions) => replaceRow(rt, id, credential, input2, callOptions),
|
|
5056
|
-
rotate: (id, credential, input2, callOptions) => rotateRow(rt, id, credential, input2, callOptions),
|
|
5057
|
-
updateProviderState: (id, fence, mutator, callOptions) => updateProviderStateRow(rt, id, fence, mutator, callOptions),
|
|
5058
|
-
disable: (id, reason, callOptions) => disableRow(rt, id, reason, callOptions),
|
|
5059
|
-
enable: (id, callOptions) => enableRow(rt, id, callOptions),
|
|
5060
|
-
remove: (id, callOptions) => removeRow(rt, id, callOptions),
|
|
5061
|
-
reorder: (ids, callOptions) => reorderRows(rt, ids, callOptions),
|
|
5062
|
-
readSettings: () => readPoolSettings(rt),
|
|
5063
|
-
updateSettings: (mutator, callOptions) => updatePoolSettings(rt, mutator, callOptions),
|
|
5064
|
-
recordIdentity: (id, identity, attribution, callOptions) => recordRowIdentity(rt, id, identity, attribution, callOptions),
|
|
5065
|
-
refresh: (id, provider2, callOptions) => refreshRow(rt, id, provider2, callOptions),
|
|
5066
|
-
recordQuota: (id, attribution, observation) => recordQuota(rt, id, attribution, observation),
|
|
5067
|
-
requestReading: (id) => pulls.fire(id, "admission"),
|
|
5068
|
-
pullsSettled: () => pulls.settled()
|
|
5069
|
-
};
|
|
5070
|
-
}
|
|
5071
|
-
var processMemory;
|
|
5072
|
-
var init_pool = __esm({
|
|
5073
|
-
"../core/dist/common-auth-embedded/store/pool.js"() {
|
|
5074
|
-
"use strict";
|
|
5075
|
-
init_attribution();
|
|
5076
|
-
init_mutate();
|
|
5077
|
-
init_provider_state();
|
|
5078
|
-
init_publication();
|
|
5079
|
-
init_pull();
|
|
5080
|
-
init_refresh();
|
|
5081
|
-
init_refresh_lock();
|
|
5082
|
-
init_rows();
|
|
5083
|
-
init_schema();
|
|
5084
|
-
init_settings();
|
|
5085
|
-
processMemory = /* @__PURE__ */ new Map();
|
|
4796
|
+
}
|
|
4797
|
+
const rotated = `${f}.1`;
|
|
4798
|
+
renameSync(f, rotated);
|
|
4799
|
+
chmodPrivate(rotated);
|
|
4800
|
+
} catch {
|
|
5086
4801
|
}
|
|
5087
|
-
}
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
}
|
|
5109
|
-
var init_store = __esm({
|
|
5110
|
-
"../core/dist/common-auth-embedded/store/index.js"() {
|
|
5111
|
-
"use strict";
|
|
5112
|
-
init_errors();
|
|
5113
|
-
init_identity();
|
|
5114
|
-
init_pool();
|
|
5115
|
-
init_provider_state();
|
|
5116
|
-
init_refresh_lock();
|
|
5117
|
-
init_schema();
|
|
5118
|
-
init_settings();
|
|
4802
|
+
}
|
|
4803
|
+
async function closeWindowsFile(sink) {
|
|
4804
|
+
const { file, handle } = sink;
|
|
4805
|
+
sink.file = void 0;
|
|
4806
|
+
sink.handle = void 0;
|
|
4807
|
+
if (file && handle)
|
|
4808
|
+
await privateOperation(file, "log-close", () => handle.close());
|
|
4809
|
+
}
|
|
4810
|
+
async function openWindowsFile(sink, file) {
|
|
4811
|
+
await ensurePrivateDirectory(dirname8(file));
|
|
4812
|
+
try {
|
|
4813
|
+
await verifyPrivate(file, "file", true);
|
|
4814
|
+
} catch (error) {
|
|
4815
|
+
if (error.code !== "ENOENT")
|
|
4816
|
+
throw error;
|
|
4817
|
+
try {
|
|
4818
|
+
await createPrivateBytes(file, "");
|
|
4819
|
+
} catch (creationError) {
|
|
4820
|
+
if (creationError.code !== "EEXIST")
|
|
4821
|
+
throw creationError;
|
|
4822
|
+
await verifyPrivate(file, "file", true);
|
|
4823
|
+
}
|
|
5119
4824
|
}
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
4825
|
+
sink.handle = await privateOperation(file, "log-open", () => open5(file, "a"));
|
|
4826
|
+
sink.file = file;
|
|
4827
|
+
return sink.handle;
|
|
4828
|
+
}
|
|
4829
|
+
async function flushWindowsFile(sink, file, text2) {
|
|
4830
|
+
file = resolve3(file);
|
|
4831
|
+
try {
|
|
4832
|
+
if (sink.file !== file)
|
|
4833
|
+
await closeWindowsFile(sink);
|
|
4834
|
+
let handle = sink.handle ?? await openWindowsFile(sink, file);
|
|
4835
|
+
const info = await privateOperation(file, "log-stat", () => handle.stat());
|
|
4836
|
+
if (info.size >= MAX_BYTES) {
|
|
4837
|
+
await closeWindowsFile(sink);
|
|
4838
|
+
for (let i = ROTATE_KEEP - 1; i >= 0; i--) {
|
|
4839
|
+
const source = i === 0 ? file : `${file}.${i}`;
|
|
4840
|
+
const target = `${file}.${i + 1}`;
|
|
4841
|
+
try {
|
|
4842
|
+
await verifyPrivate(source, "file", true);
|
|
4843
|
+
} catch (error) {
|
|
4844
|
+
if (error.code === "ENOENT")
|
|
4845
|
+
continue;
|
|
4846
|
+
throw error;
|
|
4847
|
+
}
|
|
4848
|
+
try {
|
|
4849
|
+
await verifyPrivate(target, "file", true);
|
|
4850
|
+
} catch (error) {
|
|
4851
|
+
if (error.code !== "ENOENT")
|
|
4852
|
+
throw error;
|
|
4853
|
+
}
|
|
4854
|
+
await replaceWindowsFile(source, target);
|
|
4855
|
+
await verifyPrivate(target, "file");
|
|
4856
|
+
}
|
|
4857
|
+
handle = await openWindowsFile(sink, file);
|
|
4858
|
+
}
|
|
4859
|
+
await privateOperation(file, "log-append", () => handle.appendFile(text2, "utf8"));
|
|
4860
|
+
} catch (error) {
|
|
4861
|
+
await closeWindowsFile(sink).catch(() => {
|
|
5140
4862
|
});
|
|
4863
|
+
throw error;
|
|
5141
4864
|
}
|
|
5142
|
-
}
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
LockOwnershipError: () => LockOwnershipError,
|
|
5149
|
-
PrivateFileError: () => PrivateFileError,
|
|
5150
|
-
WRITER_LOCK_CONSTANTS: () => WRITER_LOCK_CONSTANTS,
|
|
5151
|
-
acquireRefreshFileLock: () => acquireRefreshFileLock,
|
|
5152
|
-
isLostMarkerRaceError: () => isLostMarkerRaceError,
|
|
5153
|
-
lockPathFor: () => lockPathFor,
|
|
5154
|
-
withLock: () => withLock,
|
|
5155
|
-
writeJsonAtomic: () => writeJsonAtomic2
|
|
5156
|
-
});
|
|
5157
|
-
var init_fs = __esm({
|
|
5158
|
-
"../core/dist/common-auth-embedded/fs/index.js"() {
|
|
5159
|
-
"use strict";
|
|
5160
|
-
init_atomic_write();
|
|
5161
|
-
init_lock_constants();
|
|
5162
|
-
init_private_files();
|
|
5163
|
-
init_refresh_file_lock();
|
|
5164
|
-
init_with_lock();
|
|
4865
|
+
}
|
|
4866
|
+
function safeSerialize(data) {
|
|
4867
|
+
try {
|
|
4868
|
+
return ` ${JSON.stringify(data)}`;
|
|
4869
|
+
} catch {
|
|
4870
|
+
return " [unserializable]";
|
|
5165
4871
|
}
|
|
5166
|
-
}
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
4872
|
+
}
|
|
4873
|
+
function createEngine(options) {
|
|
4874
|
+
let logFileSource;
|
|
4875
|
+
let initLevelSource;
|
|
4876
|
+
let runtimeLevel;
|
|
4877
|
+
let redactor = createRedactor();
|
|
4878
|
+
let captureSink;
|
|
4879
|
+
let buffer = [];
|
|
4880
|
+
let timer;
|
|
4881
|
+
let orderedSink = Promise.resolve();
|
|
4882
|
+
let sinkError;
|
|
4883
|
+
const windowsFile = {};
|
|
4884
|
+
function queueWindows(operation) {
|
|
4885
|
+
const next = orderedSink.then(operation);
|
|
4886
|
+
orderedSink = next.catch((error) => {
|
|
4887
|
+
sinkError = error;
|
|
4888
|
+
});
|
|
4889
|
+
return next;
|
|
5173
4890
|
}
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
4891
|
+
function configure(next) {
|
|
4892
|
+
if (windowsPrivateFiles && next.file !== logFileSource)
|
|
4893
|
+
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
4894
|
+
});
|
|
4895
|
+
logFileSource = next.file;
|
|
4896
|
+
initLevelSource = next.level;
|
|
4897
|
+
redactor = createRedactor(next);
|
|
4898
|
+
captureSink = next.captureSink;
|
|
5177
4899
|
}
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
if (projection.limits.length === 0) {
|
|
5182
|
-
return {
|
|
5183
|
-
id,
|
|
5184
|
-
stage: 1,
|
|
5185
|
-
gate: 2,
|
|
5186
|
-
reason: "needs-first-reading",
|
|
5187
|
-
pullRequested: true
|
|
5188
|
-
};
|
|
4900
|
+
function setLogLevel3(l) {
|
|
4901
|
+
if (l === void 0 || l in ORDER)
|
|
4902
|
+
runtimeLevel = l;
|
|
5189
4903
|
}
|
|
5190
|
-
|
|
5191
|
-
if (
|
|
5192
|
-
return
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
gate: 3,
|
|
5196
|
-
reason: "unknown-window",
|
|
5197
|
-
window: { scope: projection.scope, label },
|
|
5198
|
-
pullRequested: true
|
|
5199
|
-
};
|
|
5200
|
-
}
|
|
4904
|
+
function logFilePath() {
|
|
4905
|
+
if (logFileSource === void 0)
|
|
4906
|
+
return void 0;
|
|
4907
|
+
const resolved = typeof logFileSource === "function" ? logFileSource() : logFileSource;
|
|
4908
|
+
return resolved || void 0;
|
|
5201
4909
|
}
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
reason: "unknown-reset",
|
|
5210
|
-
window: { scope: limit.scope, label: limit.label },
|
|
5211
|
-
pullRequested: true
|
|
5212
|
-
};
|
|
5213
|
-
}
|
|
4910
|
+
function configuredLevel() {
|
|
4911
|
+
if (runtimeLevel)
|
|
4912
|
+
return runtimeLevel;
|
|
4913
|
+
const floor = typeof initLevelSource === "function" ? initLevelSource() : initLevelSource;
|
|
4914
|
+
if (floor && floor in ORDER)
|
|
4915
|
+
return floor;
|
|
4916
|
+
return "info";
|
|
5214
4917
|
}
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
id,
|
|
5220
|
-
stage: 1,
|
|
5221
|
-
gate: 5,
|
|
5222
|
-
reason: "exhausted",
|
|
5223
|
-
window: { scope: limit.scope, label: limit.label },
|
|
5224
|
-
resetsAt: limit.resetsAt,
|
|
5225
|
-
resetAtMs
|
|
5226
|
-
};
|
|
4918
|
+
function flushLogs3(close = true) {
|
|
4919
|
+
if (timer) {
|
|
4920
|
+
clearTimeout(timer);
|
|
4921
|
+
timer = void 0;
|
|
5227
4922
|
}
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
for (const row of input2.rows) {
|
|
5238
|
-
const exclusion = exclusionFor(row.id, input2, input2.now);
|
|
5239
|
-
if (exclusion) {
|
|
5240
|
-
excluded.push(exclusion);
|
|
5241
|
-
continue;
|
|
4923
|
+
if (!buffer.length) {
|
|
4924
|
+
if (windowsPrivateFiles)
|
|
4925
|
+
return queueWindows(async () => {
|
|
4926
|
+
if (close)
|
|
4927
|
+
await closeWindowsFile(windowsFile);
|
|
4928
|
+
if (sinkError)
|
|
4929
|
+
throw sinkError;
|
|
4930
|
+
});
|
|
4931
|
+
return;
|
|
5242
4932
|
}
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
4933
|
+
let file;
|
|
4934
|
+
try {
|
|
4935
|
+
file = logFilePath();
|
|
4936
|
+
} catch {
|
|
4937
|
+
buffer = [];
|
|
4938
|
+
if (windowsPrivateFiles && close)
|
|
4939
|
+
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
4940
|
+
return;
|
|
5246
4941
|
}
|
|
5247
|
-
const
|
|
5248
|
-
|
|
5249
|
-
if (
|
|
5250
|
-
|
|
5251
|
-
|
|
4942
|
+
const text2 = buffer.join("");
|
|
4943
|
+
buffer = [];
|
|
4944
|
+
if (!file) {
|
|
4945
|
+
if (windowsPrivateFiles && close)
|
|
4946
|
+
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
4947
|
+
return;
|
|
4948
|
+
}
|
|
4949
|
+
if (windowsPrivateFiles) {
|
|
4950
|
+
return queueWindows(async () => {
|
|
4951
|
+
try {
|
|
4952
|
+
await flushWindowsFile(windowsFile, file, text2);
|
|
4953
|
+
} finally {
|
|
4954
|
+
if (close)
|
|
4955
|
+
await closeWindowsFile(windowsFile);
|
|
4956
|
+
}
|
|
4957
|
+
});
|
|
4958
|
+
}
|
|
4959
|
+
try {
|
|
4960
|
+
rotateIfNeeded(file);
|
|
4961
|
+
if (existsSync(file))
|
|
4962
|
+
chmodPrivate(file);
|
|
4963
|
+
appendFileSync(file, text2, { encoding: "utf8", mode: 384 });
|
|
4964
|
+
} catch {
|
|
5252
4965
|
}
|
|
5253
|
-
survivors.push({ id: row.id, kind: row.kind, projection });
|
|
5254
4966
|
}
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
4967
|
+
function schedule2() {
|
|
4968
|
+
if (!timer)
|
|
4969
|
+
timer = setTimeout(() => {
|
|
4970
|
+
timer = void 0;
|
|
4971
|
+
const flushed = flushLogs3(false);
|
|
4972
|
+
if (flushed instanceof Promise)
|
|
4973
|
+
void flushed.catch(() => {
|
|
4974
|
+
});
|
|
4975
|
+
}, 500);
|
|
4976
|
+
}
|
|
4977
|
+
function emit(channel, level, message, data) {
|
|
4978
|
+
if (logFileSource === void 0 && captureSink === void 0)
|
|
4979
|
+
return;
|
|
4980
|
+
try {
|
|
4981
|
+
if (ORDER[level] > ORDER[configuredLevel()])
|
|
4982
|
+
return;
|
|
4983
|
+
const scrubbedMessage = redactor.redactStrings(message);
|
|
4984
|
+
let scrubbedData;
|
|
4985
|
+
try {
|
|
4986
|
+
scrubbedData = redactor.redact(data);
|
|
4987
|
+
} catch {
|
|
4988
|
+
scrubbedData = "[unserializable]";
|
|
4989
|
+
}
|
|
4990
|
+
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${level.toUpperCase()} [${channel}] ${scrubbedMessage}` + (data === void 0 ? "" : safeSerialize(scrubbedData)) + "\n";
|
|
4991
|
+
try {
|
|
4992
|
+
captureSink?.({
|
|
4993
|
+
channel,
|
|
4994
|
+
level,
|
|
4995
|
+
message: scrubbedMessage,
|
|
4996
|
+
data: scrubbedData
|
|
4997
|
+
});
|
|
4998
|
+
} catch {
|
|
4999
|
+
}
|
|
5000
|
+
if (logFileSource === void 0)
|
|
5001
|
+
return;
|
|
5002
|
+
buffer.push(line);
|
|
5003
|
+
if (buffer.length >= 50) {
|
|
5004
|
+
const flushed = flushLogs3(false);
|
|
5005
|
+
if (flushed instanceof Promise)
|
|
5006
|
+
void flushed.catch(() => {
|
|
5007
|
+
});
|
|
5008
|
+
} else
|
|
5009
|
+
schedule2();
|
|
5010
|
+
} catch {
|
|
5269
5011
|
}
|
|
5270
5012
|
}
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
}
|
|
5279
|
-
var init_admission = __esm({
|
|
5280
|
-
"../core/dist/common-auth-embedded/routing/admission.js"() {
|
|
5281
|
-
"use strict";
|
|
5282
|
-
init_map();
|
|
5283
|
-
init_projection();
|
|
5013
|
+
function createLogger5(channel) {
|
|
5014
|
+
return {
|
|
5015
|
+
error: (m, d) => emit(channel, "error", m, d),
|
|
5016
|
+
warn: (m, d) => emit(channel, "warn", m, d),
|
|
5017
|
+
info: (m, d) => emit(channel, "info", m, d),
|
|
5018
|
+
debug: (m, d) => emit(channel, "debug", m, d),
|
|
5019
|
+
trace: (m, d) => emit(channel, "trace", m, d)
|
|
5020
|
+
};
|
|
5284
5021
|
}
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5022
|
+
function reset() {
|
|
5023
|
+
if (windowsPrivateFiles)
|
|
5024
|
+
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
5025
|
+
});
|
|
5026
|
+
sinkError = void 0;
|
|
5027
|
+
buffer = [];
|
|
5028
|
+
if (timer) {
|
|
5029
|
+
clearTimeout(timer);
|
|
5030
|
+
timer = void 0;
|
|
5031
|
+
}
|
|
5032
|
+
logFileSource = void 0;
|
|
5033
|
+
initLevelSource = void 0;
|
|
5034
|
+
runtimeLevel = void 0;
|
|
5035
|
+
redactor = createRedactor();
|
|
5036
|
+
captureSink = void 0;
|
|
5298
5037
|
}
|
|
5038
|
+
if (options)
|
|
5039
|
+
configure(options);
|
|
5040
|
+
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3, reset };
|
|
5299
5041
|
}
|
|
5300
|
-
function
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
const rest = ids.filter((id) => id !== formerMainId);
|
|
5304
|
-
return placement === "main-first" ? [formerMainId, ...rest] : [...rest, formerMainId];
|
|
5042
|
+
function createLoggerInstance(options) {
|
|
5043
|
+
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = createEngine(options);
|
|
5044
|
+
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
5305
5045
|
}
|
|
5306
|
-
function
|
|
5307
|
-
|
|
5308
|
-
const
|
|
5309
|
-
|
|
5310
|
-
return { order, admission };
|
|
5046
|
+
function initLogger(options) {
|
|
5047
|
+
defaultEngine.configure(options);
|
|
5048
|
+
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = defaultEngine;
|
|
5049
|
+
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
5311
5050
|
}
|
|
5312
|
-
function
|
|
5313
|
-
|
|
5314
|
-
if (last !== void 0) {
|
|
5315
|
-
if (last.status === void 0 || !retryStatuses.includes(last.status)) {
|
|
5316
|
-
return void 0;
|
|
5317
|
-
}
|
|
5318
|
-
}
|
|
5319
|
-
const tried = new Set(attempts2.map((attempt) => attempt.id));
|
|
5320
|
-
return order.find((id) => !tried.has(id));
|
|
5051
|
+
function setLogLevel(l) {
|
|
5052
|
+
defaultEngine.setLogLevel(l);
|
|
5321
5053
|
}
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5054
|
+
function flushLogs() {
|
|
5055
|
+
return defaultEngine.flushLogs();
|
|
5056
|
+
}
|
|
5057
|
+
function createLogger2(channel) {
|
|
5058
|
+
return defaultEngine.createLogger(channel);
|
|
5059
|
+
}
|
|
5060
|
+
async function flushForTest() {
|
|
5061
|
+
return defaultEngine.flushLogs();
|
|
5062
|
+
}
|
|
5063
|
+
function resetLoggerForTest() {
|
|
5064
|
+
defaultEngine.reset();
|
|
5065
|
+
}
|
|
5066
|
+
var ORDER, MAX_BYTES, ROTATE_KEEP, defaultEngine;
|
|
5067
|
+
var init_engine = __esm({
|
|
5068
|
+
"../core/dist/common-auth-embedded/logger/engine.js"() {
|
|
5325
5069
|
"use strict";
|
|
5326
|
-
|
|
5327
|
-
|
|
5070
|
+
init_private_files();
|
|
5071
|
+
init_redact();
|
|
5072
|
+
ORDER = {
|
|
5073
|
+
error: 0,
|
|
5074
|
+
warn: 1,
|
|
5075
|
+
info: 2,
|
|
5076
|
+
debug: 3,
|
|
5077
|
+
trace: 4
|
|
5078
|
+
};
|
|
5079
|
+
MAX_BYTES = 5 * 1024 * 1024;
|
|
5080
|
+
ROTATE_KEEP = 3;
|
|
5081
|
+
defaultEngine = createEngine();
|
|
5328
5082
|
}
|
|
5329
5083
|
});
|
|
5330
5084
|
|
|
5331
|
-
// ../core/dist/common-auth-embedded/
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
var init_pins = __esm({
|
|
5349
|
-
"../core/dist/common-auth-embedded/routing/pins.js"() {
|
|
5085
|
+
// ../core/dist/common-auth-embedded/logger/index.js
|
|
5086
|
+
var logger_exports = {};
|
|
5087
|
+
__export(logger_exports, {
|
|
5088
|
+
createCaptureSink: () => createCaptureSink,
|
|
5089
|
+
createLogger: () => createLogger2,
|
|
5090
|
+
createLoggerInstance: () => createLoggerInstance,
|
|
5091
|
+
createRedactor: () => createRedactor,
|
|
5092
|
+
flushForTest: () => flushForTest,
|
|
5093
|
+
flushLogs: () => flushLogs,
|
|
5094
|
+
initLogger: () => initLogger,
|
|
5095
|
+
redact: () => redact,
|
|
5096
|
+
redactStrings: () => redactStrings,
|
|
5097
|
+
resetLoggerForTest: () => resetLoggerForTest,
|
|
5098
|
+
setLogLevel: () => setLogLevel
|
|
5099
|
+
});
|
|
5100
|
+
var init_logger = __esm({
|
|
5101
|
+
"../core/dist/common-auth-embedded/logger/index.js"() {
|
|
5350
5102
|
"use strict";
|
|
5103
|
+
init_capture_sink();
|
|
5104
|
+
init_engine();
|
|
5105
|
+
init_redact();
|
|
5351
5106
|
}
|
|
5352
5107
|
});
|
|
5353
5108
|
|
|
5354
|
-
// ../core/dist/common-auth-embedded/
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5109
|
+
// ../core/dist/common-auth-embedded/store/quota-writer.js
|
|
5110
|
+
var COALESCE_MS, POOL_QUOTA_QUEUE_LIMIT, PoolQuotaWriter;
|
|
5111
|
+
var init_quota_writer = __esm({
|
|
5112
|
+
"../core/dist/common-auth-embedded/store/quota-writer.js"() {
|
|
5113
|
+
"use strict";
|
|
5114
|
+
init_logger();
|
|
5115
|
+
init_attribution();
|
|
5116
|
+
init_errors();
|
|
5117
|
+
init_mutate();
|
|
5118
|
+
init_refresh_lock();
|
|
5119
|
+
init_runtime();
|
|
5120
|
+
init_schema();
|
|
5121
|
+
COALESCE_MS = 100;
|
|
5122
|
+
POOL_QUOTA_QUEUE_LIMIT = 128;
|
|
5123
|
+
PoolQuotaWriter = class {
|
|
5124
|
+
rt;
|
|
5125
|
+
timeoutMs;
|
|
5126
|
+
pending = /* @__PURE__ */ new Map();
|
|
5127
|
+
warned = /* @__PURE__ */ new Set();
|
|
5128
|
+
wake = /* @__PURE__ */ new Set();
|
|
5129
|
+
logger;
|
|
5130
|
+
timer;
|
|
5131
|
+
running;
|
|
5132
|
+
closing;
|
|
5133
|
+
closed = false;
|
|
5134
|
+
stopped = false;
|
|
5135
|
+
failures = 0;
|
|
5136
|
+
constructor(rt, timeoutMs = 1e3) {
|
|
5137
|
+
this.rt = rt;
|
|
5138
|
+
this.timeoutMs = timeoutMs;
|
|
5139
|
+
this.logger = rt.ctx.logger ?? createLogger2("store");
|
|
5140
|
+
}
|
|
5141
|
+
async record(id, attribution, observation) {
|
|
5142
|
+
try {
|
|
5143
|
+
this.assertOpen(id);
|
|
5144
|
+
assertQuotaEpoch(id, attribution);
|
|
5145
|
+
const publication2 = structuredClone({
|
|
5146
|
+
id,
|
|
5147
|
+
attribution,
|
|
5148
|
+
observation
|
|
5149
|
+
});
|
|
5150
|
+
const { row, result } = await readRow(this.rt, "pull", id);
|
|
5151
|
+
assertQuotaRow(id, publication2.attribution, row);
|
|
5152
|
+
mergedQuota(this.rt.ctx, id, this.overlayRow({ ...row, quota: entryIn(result.config, id)?.quota }).quota, publication2.observation);
|
|
5153
|
+
await this.room(id);
|
|
5154
|
+
this.assertOpen(id);
|
|
5155
|
+
const queue2 = this.pending.get(id) ?? [];
|
|
5156
|
+
queue2.push(publication2);
|
|
5157
|
+
this.pending.set(id, queue2);
|
|
5158
|
+
if (queue2.length >= POOL_QUOTA_QUEUE_LIMIT)
|
|
5159
|
+
this.flushNow();
|
|
5160
|
+
else
|
|
5161
|
+
this.schedule(COALESCE_MS);
|
|
5162
|
+
} catch (error) {
|
|
5163
|
+
throw toFailure(error, "pull", id, { writes: 0 });
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
queued(id) {
|
|
5167
|
+
return this.pending.get(id)?.length ?? 0;
|
|
5168
|
+
}
|
|
5169
|
+
// Waits while the row's queue is full, flushing at once on every wake-up,
|
|
5170
|
+
// for at most the store's own lock acquisition budget.
|
|
5171
|
+
async room(id) {
|
|
5172
|
+
if (this.queued(id) < POOL_QUOTA_QUEUE_LIMIT)
|
|
5173
|
+
return;
|
|
5174
|
+
const { ctx } = this.rt;
|
|
5175
|
+
const budget = Math.max(0, ...ctx.storeLocks.map((spec) => spec.timeoutMs ?? ctx.lockDefaults.timeoutMs));
|
|
5176
|
+
const deadline = performance.now() + budget;
|
|
5177
|
+
while (this.queued(id) >= POOL_QUOTA_QUEUE_LIMIT) {
|
|
5178
|
+
this.assertOpen(id);
|
|
5179
|
+
this.flushNow();
|
|
5180
|
+
const left = deadline - performance.now();
|
|
5181
|
+
if (left <= 0)
|
|
5182
|
+
throw refusal2("pull", id, "lock-contention", `pool quota queue for ${id} is full (${POOL_QUOTA_QUEUE_LIMIT} readings) and the store locks stayed held`, true);
|
|
5183
|
+
await new Promise((resolve20) => {
|
|
5184
|
+
const done = () => {
|
|
5185
|
+
clearTimeout(timer);
|
|
5186
|
+
this.wake.delete(done);
|
|
5187
|
+
resolve20();
|
|
5188
|
+
};
|
|
5189
|
+
const timer = setTimeout(done, left);
|
|
5190
|
+
this.wake.add(done);
|
|
5191
|
+
});
|
|
5192
|
+
}
|
|
5193
|
+
}
|
|
5194
|
+
assertOpen(id) {
|
|
5195
|
+
if (this.closed)
|
|
5196
|
+
throw refusal2("pull", id, "invalid-input", "pool quota writer is closed");
|
|
5197
|
+
}
|
|
5198
|
+
// What read() and load() show: the stored map, then each queued reading of
|
|
5199
|
+
// the row still bound to it, in arrival order through the codec's merge.
|
|
5200
|
+
// A reading the codec now refuses is left out, as the flush drops it.
|
|
5201
|
+
overlayRow(row) {
|
|
5202
|
+
let next = row;
|
|
5203
|
+
for (const publication2 of this.pending.get(row.id) ?? []) {
|
|
5204
|
+
try {
|
|
5205
|
+
assertQuotaRow(row.id, publication2.attribution, row);
|
|
5206
|
+
next = {
|
|
5207
|
+
...next,
|
|
5208
|
+
quota: mergedQuota(this.rt.ctx, row.id, next.quota, publication2.observation),
|
|
5209
|
+
needsFirstReading: false
|
|
5210
|
+
};
|
|
5211
|
+
} catch {
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
return next;
|
|
5215
|
+
}
|
|
5216
|
+
overlay(rows) {
|
|
5217
|
+
return rows.map((row) => this.overlayRow(row));
|
|
5218
|
+
}
|
|
5219
|
+
schedule(delay3) {
|
|
5220
|
+
if (this.running || this.timer || !this.pending.size || this.stopped)
|
|
5221
|
+
return;
|
|
5222
|
+
this.timer = setTimeout(() => {
|
|
5223
|
+
this.timer = void 0;
|
|
5224
|
+
this.flush();
|
|
5225
|
+
}, delay3);
|
|
5226
|
+
if (!this.closed)
|
|
5227
|
+
this.timer.unref?.();
|
|
5228
|
+
}
|
|
5229
|
+
// Starts a flush now rather than at the coalescing timer or retry backoff;
|
|
5230
|
+
// a flush already running is left to finish.
|
|
5231
|
+
flushNow() {
|
|
5232
|
+
if (this.running)
|
|
5233
|
+
return;
|
|
5234
|
+
clearTimeout(this.timer);
|
|
5235
|
+
this.timer = void 0;
|
|
5236
|
+
this.flush();
|
|
5237
|
+
}
|
|
5238
|
+
flush() {
|
|
5239
|
+
if (this.running || this.stopped || !this.pending.size)
|
|
5240
|
+
return;
|
|
5241
|
+
const batch = [...this.pending.values()].flat();
|
|
5242
|
+
const ctx = {
|
|
5243
|
+
...this.rt.ctx,
|
|
5244
|
+
storeLocks: this.rt.ctx.storeLocks.map((spec) => ({
|
|
5245
|
+
...spec,
|
|
5246
|
+
timeoutMs: Math.min(spec.timeoutMs ?? this.rt.ctx.lockDefaults.timeoutMs, 100)
|
|
5247
|
+
}))
|
|
5248
|
+
};
|
|
5249
|
+
const locks = new LockStack(ctx.lockDefaults, ctx.lockEnv);
|
|
5250
|
+
this.running = (async () => {
|
|
5251
|
+
try {
|
|
5252
|
+
await withTransaction(ctx, locks, { writes: 0 }, { operation: "pull", rowId: void 0 }, async (tx) => {
|
|
5253
|
+
if (this.stopped)
|
|
5254
|
+
return;
|
|
5255
|
+
let changed = false;
|
|
5256
|
+
for (const publication2 of batch) {
|
|
5257
|
+
const { id, attribution, observation } = publication2;
|
|
5258
|
+
const witness = JSON.stringify([
|
|
5259
|
+
id,
|
|
5260
|
+
attribution.credentialEpoch,
|
|
5261
|
+
attribution.identity
|
|
5262
|
+
]);
|
|
5263
|
+
try {
|
|
5264
|
+
tx.assertNotStaged(id);
|
|
5265
|
+
assertQuotaRow(id, attribution, tx.row(id));
|
|
5266
|
+
} catch (error) {
|
|
5267
|
+
if (!(error instanceof PoolOperationError))
|
|
5268
|
+
throw error;
|
|
5269
|
+
if (!this.warned.has(witness)) {
|
|
5270
|
+
this.warned.add(witness);
|
|
5271
|
+
this.warn("pool quota publication dropped; account binding changed", { id, kind: error.kind });
|
|
5272
|
+
}
|
|
5273
|
+
continue;
|
|
5274
|
+
}
|
|
5275
|
+
const entry = tx.entry(id);
|
|
5276
|
+
if (!entry)
|
|
5277
|
+
continue;
|
|
5278
|
+
let quota;
|
|
5279
|
+
try {
|
|
5280
|
+
quota = mergedQuota(ctx, id, entry.quota, observation);
|
|
5281
|
+
} catch (error) {
|
|
5282
|
+
const key = `codec:${witness}`;
|
|
5283
|
+
if (!this.warned.has(key)) {
|
|
5284
|
+
this.warned.add(key);
|
|
5285
|
+
this.warn("pool quota publication dropped; the quota codec refused it", {
|
|
5286
|
+
id,
|
|
5287
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5288
|
+
});
|
|
5289
|
+
}
|
|
5290
|
+
continue;
|
|
5291
|
+
}
|
|
5292
|
+
tx.setEntry(id, { ...entry, quota, needsFirstReading: false });
|
|
5293
|
+
changed = true;
|
|
5294
|
+
}
|
|
5295
|
+
if (changed && !this.stopped)
|
|
5296
|
+
await tx.commitConfig();
|
|
5297
|
+
}, { completeTorn: false });
|
|
5298
|
+
const flushed = new Set(batch);
|
|
5299
|
+
for (const [id, queue2] of this.pending) {
|
|
5300
|
+
const rest = queue2.filter((publication2) => !flushed.has(publication2));
|
|
5301
|
+
if (rest.length)
|
|
5302
|
+
this.pending.set(id, rest);
|
|
5303
|
+
else
|
|
5304
|
+
this.pending.delete(id);
|
|
5305
|
+
}
|
|
5306
|
+
this.failures = 0;
|
|
5307
|
+
} catch (error) {
|
|
5308
|
+
if (!this.stopped && this.failures++ === 0)
|
|
5309
|
+
this.warn("pool quota publication delayed; retrying", {
|
|
5310
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5311
|
+
});
|
|
5312
|
+
} finally {
|
|
5313
|
+
await locks.releaseAll();
|
|
5314
|
+
this.running = void 0;
|
|
5315
|
+
for (const wake of this.wake)
|
|
5316
|
+
wake();
|
|
5317
|
+
const delay3 = this.failures ? Math.min(5e3, 100 * 2 ** Math.min(this.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
|
|
5318
|
+
this.schedule(delay3);
|
|
5319
|
+
}
|
|
5320
|
+
})();
|
|
5321
|
+
}
|
|
5322
|
+
warn(message, data) {
|
|
5323
|
+
try {
|
|
5324
|
+
this.logger.warn(message, data);
|
|
5325
|
+
} catch {
|
|
5326
|
+
}
|
|
5327
|
+
}
|
|
5328
|
+
close() {
|
|
5329
|
+
if (this.closing)
|
|
5330
|
+
return this.closing;
|
|
5331
|
+
this.closed = true;
|
|
5332
|
+
this.closing = this.drain();
|
|
5333
|
+
return this.closing;
|
|
5334
|
+
}
|
|
5335
|
+
async drain() {
|
|
5336
|
+
clearTimeout(this.timer);
|
|
5337
|
+
this.timer = void 0;
|
|
5338
|
+
let deadline;
|
|
5339
|
+
let wake;
|
|
5340
|
+
const drained = new Promise((done) => {
|
|
5341
|
+
wake = () => {
|
|
5342
|
+
if (!this.pending.size)
|
|
5343
|
+
done();
|
|
5344
|
+
};
|
|
5345
|
+
this.wake.add(wake);
|
|
5346
|
+
wake();
|
|
5347
|
+
});
|
|
5348
|
+
try {
|
|
5349
|
+
this.flush();
|
|
5350
|
+
await Promise.race([
|
|
5351
|
+
drained,
|
|
5352
|
+
new Promise((done) => {
|
|
5353
|
+
deadline = setTimeout(done, Math.max(0, this.timeoutMs));
|
|
5354
|
+
})
|
|
5355
|
+
]);
|
|
5356
|
+
} finally {
|
|
5357
|
+
this.stopped = true;
|
|
5358
|
+
clearTimeout(deadline);
|
|
5359
|
+
clearTimeout(this.timer);
|
|
5360
|
+
this.wake.delete(wake);
|
|
5361
|
+
if (this.pending.size)
|
|
5362
|
+
this.warn("pool quota drain timed out; pending readings left", {
|
|
5363
|
+
accounts: this.pending.size,
|
|
5364
|
+
readings: [...this.pending.values()].reduce((sum, queue2) => sum + queue2.length, 0)
|
|
5365
|
+
});
|
|
5366
|
+
this.pending.clear();
|
|
5367
|
+
for (const wake2 of this.wake)
|
|
5368
|
+
wake2();
|
|
5369
|
+
}
|
|
5370
|
+
}
|
|
5371
|
+
};
|
|
5368
5372
|
}
|
|
5369
|
-
|
|
5373
|
+
});
|
|
5374
|
+
|
|
5375
|
+
// ../core/dist/common-auth-embedded/store/refresh.js
|
|
5376
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
5377
|
+
function requireRefreshable(id, row) {
|
|
5378
|
+
assertNotReserved("refresh", id, row?.staged);
|
|
5379
|
+
if (!row)
|
|
5380
|
+
throw refusal2("refresh", id, "unknown-row", `no row ${id} in the pool`);
|
|
5381
|
+
if (row.invalid)
|
|
5382
|
+
throw refusal2("refresh", id, "invalid-row", `row ${id} is invalid`);
|
|
5383
|
+
if (row.type !== "oauth" || row.credential?.type !== "oauth")
|
|
5384
|
+
throw refusal2("refresh", id, "no-credential", `row ${id} holds no OAuth credential`);
|
|
5385
|
+
if (!row.enabled)
|
|
5386
|
+
throw refusal2("refresh", id, "row-disabled", `row ${id} is disabled`);
|
|
5387
|
+
return row;
|
|
5370
5388
|
}
|
|
5371
|
-
function
|
|
5372
|
-
return
|
|
5373
|
-
const leftKnown = left.windowMinutes !== void 0;
|
|
5374
|
-
const rightKnown = right.windowMinutes !== void 0;
|
|
5375
|
-
if (leftKnown !== rightKnown)
|
|
5376
|
-
return leftKnown ? -1 : 1;
|
|
5377
|
-
if (leftKnown && rightKnown) {
|
|
5378
|
-
return (right.windowMinutes ?? 0) - (left.windowMinutes ?? 0);
|
|
5379
|
-
}
|
|
5380
|
-
return 0;
|
|
5381
|
-
});
|
|
5389
|
+
function stampAhead(id) {
|
|
5390
|
+
return refusal2("refresh", id, "refresh-stamp-ahead", `row ${id}'s stored refresh stamp is ahead of the clock; a rotation now could not be stamped newer within the trust bound`, true);
|
|
5382
5391
|
}
|
|
5383
|
-
function
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5392
|
+
async function refreshRow(rt, id, provider2, options = {}) {
|
|
5393
|
+
assertNotInsideHook("refresh");
|
|
5394
|
+
const { ctx } = rt;
|
|
5395
|
+
return runOperation(ctx, "refresh", id, options.onFailure, async (locks, progress) => {
|
|
5396
|
+
const { row: seen } = await readRow(rt, "refresh", id);
|
|
5397
|
+
requireRefreshable(id, seen);
|
|
5398
|
+
const early = await options.refuse?.(seen);
|
|
5399
|
+
if (early !== void 0)
|
|
5400
|
+
return { status: "refused", rowId: id, reason: early };
|
|
5401
|
+
let key = rowLockKey(seen);
|
|
5402
|
+
let captured;
|
|
5403
|
+
for (let attempt = 0; ; attempt++) {
|
|
5404
|
+
await locks.acquire(rowLockSpec(rt, { id, identity: key === id ? void 0 : key }));
|
|
5405
|
+
await locks.acquire(options.providerLock ?? rt.providerLock);
|
|
5406
|
+
for (const extra of options.extraLocks ?? [])
|
|
5407
|
+
await locks.acquire(extra);
|
|
5408
|
+
const captureProgress = { writes: 0 };
|
|
5409
|
+
const read = await withTransaction(ctx, locks, captureProgress, { operation: "refresh", rowId: id }, async (tx) => {
|
|
5410
|
+
let row = requireRefreshable(id, tx.row(id));
|
|
5411
|
+
requireBound("refresh", row);
|
|
5412
|
+
if (!row.hasEntry) {
|
|
5413
|
+
tx.setEntry(id, { credentialEpoch: 1, needsFirstReading: true });
|
|
5414
|
+
await tx.commitConfig();
|
|
5415
|
+
row = requireRefreshable(id, tx.row(id));
|
|
5416
|
+
}
|
|
5417
|
+
if (rowLockKey(row) !== key)
|
|
5418
|
+
return { keyNow: rowLockKey(row) };
|
|
5419
|
+
const reason = await options.refuse?.(row);
|
|
5420
|
+
if (reason !== void 0)
|
|
5421
|
+
return { refused: reason };
|
|
5422
|
+
return {
|
|
5423
|
+
row,
|
|
5424
|
+
credential: row.credential,
|
|
5425
|
+
credentialEpoch: row.credentialEpoch,
|
|
5426
|
+
identity: row.identity
|
|
5427
|
+
};
|
|
5428
|
+
});
|
|
5429
|
+
if ("refused" in read)
|
|
5430
|
+
return { status: "refused", rowId: id, reason: read.refused };
|
|
5431
|
+
if ("keyNow" in read) {
|
|
5432
|
+
await locks.releaseAll();
|
|
5433
|
+
if (attempt >= 1)
|
|
5434
|
+
throw refusal2("refresh", id, "row-key-changed", `row ${id}'s wire identity changed twice while its lock was held`, true);
|
|
5435
|
+
key = read.keyNow;
|
|
5436
|
+
continue;
|
|
5437
|
+
}
|
|
5438
|
+
captured = read;
|
|
5439
|
+
break;
|
|
5440
|
+
}
|
|
5441
|
+
if (rotationStampUntrusted(captured.credential.lastRefreshedAt, ctx.now()))
|
|
5442
|
+
throw stampAhead(id);
|
|
5443
|
+
await ctx.hold?.("refresh-before-provider", id);
|
|
5444
|
+
await locks.assertAll();
|
|
5445
|
+
let result;
|
|
5446
|
+
try {
|
|
5447
|
+
result = await provider2(captured.credential, captured.row);
|
|
5448
|
+
} catch (cause) {
|
|
5449
|
+
throw new PoolOperationError({
|
|
5450
|
+
operation: "refresh",
|
|
5451
|
+
rowId: id,
|
|
5452
|
+
phase: "before-first-write",
|
|
5453
|
+
retryable: true,
|
|
5454
|
+
kind: "provider",
|
|
5455
|
+
message: "the provider refresh failed",
|
|
5456
|
+
cause
|
|
5457
|
+
});
|
|
5458
|
+
}
|
|
5459
|
+
if (typeof result?.refresh !== "string" || !result.refresh.trim())
|
|
5460
|
+
throw refusal2("refresh", id, "provider", "the provider returned no refresh token", true);
|
|
5461
|
+
const incoming = result.providerState === void 0 ? void 0 : acceptProviderState(ctx.providerState, "refresh", id, result.providerState, "the provider state the provider returned");
|
|
5462
|
+
const commit = await withTransaction(ctx, locks, progress, { operation: "refresh", rowId: id }, async (tx) => {
|
|
5463
|
+
const current = tx.row(id);
|
|
5464
|
+
const entry = tx.entry(id);
|
|
5465
|
+
if (!current || current.invalid || !entry || entry.credentialEpoch !== captured.credentialEpoch || current.identity !== captured.identity)
|
|
5466
|
+
throw new PoolOperationError({
|
|
5467
|
+
operation: "refresh",
|
|
5468
|
+
rowId: id,
|
|
5469
|
+
phase: "before-first-write",
|
|
5470
|
+
retryable: true,
|
|
5471
|
+
kind: "attribution",
|
|
5472
|
+
message: `row ${id} changed credential while its refresh was in flight; the rotation is discarded`
|
|
5473
|
+
});
|
|
5474
|
+
requireBound("refresh", current);
|
|
5475
|
+
const reason = await options.refuse?.(current);
|
|
5476
|
+
if (reason !== void 0)
|
|
5477
|
+
return { refused: reason };
|
|
5478
|
+
const now = ctx.now();
|
|
5479
|
+
const prior = current.credential?.type === "oauth" ? current.credential.lastRefreshedAt : void 0;
|
|
5480
|
+
if (rotationStampUntrusted(prior, now))
|
|
5481
|
+
throw stampAhead(id);
|
|
5482
|
+
const credential = {
|
|
5483
|
+
type: "oauth",
|
|
5484
|
+
access: result.access,
|
|
5485
|
+
refresh: result.refresh,
|
|
5486
|
+
expires: result.expires
|
|
5487
|
+
};
|
|
5488
|
+
const contradiction = current.identity !== void 0 && result.identity !== void 0 && current.identity !== result.identity ? {
|
|
5489
|
+
expectedIdentity: current.identity,
|
|
5490
|
+
returnedIdentity: result.identity
|
|
5491
|
+
} : void 0;
|
|
5492
|
+
const transition = contradiction ? {
|
|
5493
|
+
mark: randomUUID11(),
|
|
5494
|
+
enabled: false,
|
|
5495
|
+
reason: `${IDENTITY_CONTRADICTED_REASON_PREFIX}${JSON.stringify(contradiction)}`
|
|
5496
|
+
} : void 0;
|
|
5497
|
+
const learnt = current.identity === void 0 && result.identity ? result.identity : void 0;
|
|
5498
|
+
const stored = await rotateIn(rt, tx, id, credential, {
|
|
5499
|
+
stamp: rotationStamp(prior, now),
|
|
5500
|
+
// Write state first with the disable marker, then config below.
|
|
5501
|
+
// Once the successor is durable, recovery projects the disable even
|
|
5502
|
+
// if config has not landed. A crash before the first rename still
|
|
5503
|
+
// loses an in-memory provider reply, as in any ordinary refresh.
|
|
5504
|
+
transition,
|
|
5505
|
+
identity: learnt,
|
|
5506
|
+
...incoming !== void 0 ? {
|
|
5507
|
+
providerState: mergedProviderState(ctx.providerState, "refresh", id, current.providerState, incoming)
|
|
5508
|
+
} : {}
|
|
5509
|
+
});
|
|
5510
|
+
if (transition !== void 0) {
|
|
5511
|
+
applyTransition(tx, id, transition);
|
|
5512
|
+
await tx.commitConfig();
|
|
5513
|
+
}
|
|
5514
|
+
let identity = current.identity;
|
|
5515
|
+
if (learnt !== void 0) {
|
|
5516
|
+
recordIdentityIn(tx, id, learnt);
|
|
5517
|
+
identity = learnt;
|
|
5518
|
+
await tx.commitConfig();
|
|
5519
|
+
}
|
|
5520
|
+
return { stored, identity, contradiction, refused: void 0 };
|
|
5521
|
+
});
|
|
5522
|
+
if (commit.refused !== void 0)
|
|
5523
|
+
return { status: "refused", rowId: id, reason: commit.refused };
|
|
5524
|
+
if (commit.contradiction !== void 0)
|
|
5400
5525
|
return {
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5526
|
+
status: "identity-contradicted",
|
|
5527
|
+
rowId: id,
|
|
5528
|
+
...commit.contradiction,
|
|
5529
|
+
credential: commit.stored
|
|
5405
5530
|
};
|
|
5531
|
+
if (options.onPersisted) {
|
|
5532
|
+
try {
|
|
5533
|
+
const persisted = options.onPersisted;
|
|
5534
|
+
await runInsideHook("refresh", () => persisted(id, commit.stored));
|
|
5535
|
+
} catch (cause) {
|
|
5536
|
+
throw new PoolOperationError({
|
|
5537
|
+
operation: "refresh",
|
|
5538
|
+
rowId: id,
|
|
5539
|
+
phase: "after-first-write",
|
|
5540
|
+
retryable: false,
|
|
5541
|
+
kind: "after-persist-hook",
|
|
5542
|
+
committed: commit.stored,
|
|
5543
|
+
message: "the after-persist hook threw; the rotation stays committed",
|
|
5544
|
+
cause
|
|
5545
|
+
});
|
|
5546
|
+
}
|
|
5406
5547
|
}
|
|
5407
|
-
}
|
|
5408
|
-
const budgetReset = budgetExhaustedResetAt(input2.quota, input2.now);
|
|
5409
|
-
if (budgetReset) {
|
|
5410
5548
|
return {
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5549
|
+
status: "rotated",
|
|
5550
|
+
rowId: id,
|
|
5551
|
+
credential: commit.stored,
|
|
5552
|
+
...commit.identity !== void 0 ? { identity: commit.identity } : {}
|
|
5414
5553
|
};
|
|
5415
|
-
}
|
|
5416
|
-
return { action: "retain", reason: statusClass };
|
|
5554
|
+
});
|
|
5417
5555
|
}
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5556
|
+
var init_refresh = __esm({
|
|
5557
|
+
"../core/dist/common-auth-embedded/store/refresh.js"() {
|
|
5558
|
+
"use strict";
|
|
5559
|
+
init_errors();
|
|
5560
|
+
init_hooks();
|
|
5561
|
+
init_identity();
|
|
5562
|
+
init_mutate();
|
|
5563
|
+
init_provider_state();
|
|
5564
|
+
init_reserved();
|
|
5565
|
+
init_rows();
|
|
5566
|
+
init_runtime();
|
|
5567
|
+
init_schema();
|
|
5568
|
+
init_torn();
|
|
5569
|
+
}
|
|
5570
|
+
});
|
|
5571
|
+
|
|
5572
|
+
// ../core/dist/common-auth-embedded/store/settings.js
|
|
5573
|
+
import { isDeepStrictEqual as isDeepStrictEqual3 } from "node:util";
|
|
5574
|
+
function settingsOf2(config) {
|
|
5575
|
+
const settings = {};
|
|
5576
|
+
for (const [key, value] of Object.entries(config))
|
|
5577
|
+
if (!POOL_OWNED_KEYS.includes(key))
|
|
5578
|
+
defineKey(settings, key, value);
|
|
5579
|
+
return settings;
|
|
5429
5580
|
}
|
|
5430
|
-
function
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5581
|
+
function defineKey(target, key, value) {
|
|
5582
|
+
Object.defineProperty(target, key, {
|
|
5583
|
+
value,
|
|
5584
|
+
enumerable: true,
|
|
5585
|
+
writable: true,
|
|
5586
|
+
configurable: true
|
|
5587
|
+
});
|
|
5436
5588
|
}
|
|
5437
|
-
function
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
const weights = windowReadings(candidate.quota).map((limit) => sustainableWindowWeight({
|
|
5445
|
-
remainingPercent: limit.remainingPercent ?? Number.NaN,
|
|
5446
|
-
...limit.resetsAt === void 0 ? {} : { resetsAt: limit.resetsAt }
|
|
5447
|
-
}, candidate.reservePercent[limit.label] ?? 0, now));
|
|
5448
|
-
const budget = candidate.quota.budget;
|
|
5449
|
-
if (budget && typeof budget.remainingPercent === "number" && Number.isFinite(budget.remainingPercent)) {
|
|
5450
|
-
weights.push(sustainableWindowWeight({
|
|
5451
|
-
remainingPercent: budget.remainingPercent,
|
|
5452
|
-
...budget.resetsAt === void 0 ? {} : { resetsAt: budget.resetsAt }
|
|
5453
|
-
}, 0, now));
|
|
5589
|
+
function composeConfig(config, next) {
|
|
5590
|
+
const out = {};
|
|
5591
|
+
for (const [key, value] of Object.entries(config)) {
|
|
5592
|
+
if (POOL_OWNED_KEYS.includes(key))
|
|
5593
|
+
defineKey(out, key, value);
|
|
5594
|
+
else if (Object.hasOwn(next, key))
|
|
5595
|
+
defineKey(out, key, next[key]);
|
|
5454
5596
|
}
|
|
5455
|
-
const
|
|
5456
|
-
|
|
5597
|
+
for (const [key, value] of Object.entries(next))
|
|
5598
|
+
if (!Object.hasOwn(config, key))
|
|
5599
|
+
defineKey(out, key, value);
|
|
5600
|
+
return out;
|
|
5457
5601
|
}
|
|
5458
|
-
function
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5602
|
+
function settingsRefusal(message) {
|
|
5603
|
+
return new PoolOperationError({
|
|
5604
|
+
operation: "updateSettings",
|
|
5605
|
+
phase: "before-first-write",
|
|
5606
|
+
retryable: false,
|
|
5607
|
+
kind: "invalid-input",
|
|
5608
|
+
message
|
|
5609
|
+
});
|
|
5610
|
+
}
|
|
5611
|
+
async function readPoolSettings(rt) {
|
|
5612
|
+
const result = await readPool(rt.ctx);
|
|
5613
|
+
if (result.status === "error")
|
|
5614
|
+
return result;
|
|
5615
|
+
return { status: result.status, settings: settingsOf2(result.config) };
|
|
5616
|
+
}
|
|
5617
|
+
async function updatePoolSettings(rt, mutator, options = {}) {
|
|
5618
|
+
assertNotInsideHook("updateSettings");
|
|
5619
|
+
const { ctx } = rt;
|
|
5620
|
+
const onFailure = options.onFailure;
|
|
5621
|
+
return runOperation(ctx, "updateSettings", void 0, onFailure && ((_rowId, error) => onFailure(error)), async (locks, progress) => {
|
|
5622
|
+
for (const extra of options.extraLocks ?? [])
|
|
5623
|
+
await locks.acquire(extra);
|
|
5624
|
+
const mark = locks.held.length;
|
|
5625
|
+
try {
|
|
5626
|
+
for (const spec of ctx.storeLocks)
|
|
5627
|
+
await locks.acquire(spec);
|
|
5628
|
+
const result = await readPool(ctx);
|
|
5629
|
+
if (result.status !== "ready")
|
|
5630
|
+
throw notReadyError(result, "updateSettings", void 0);
|
|
5631
|
+
const current = settingsOf2(result.config);
|
|
5632
|
+
const draft = structuredClone(current);
|
|
5633
|
+
const returned = await runInsideHook("updateSettings", () => mutator(draft));
|
|
5634
|
+
const next = returned === void 0 ? draft : returned;
|
|
5635
|
+
if (!isRecord4(next))
|
|
5636
|
+
throw settingsRefusal("the settings mutator must produce an object");
|
|
5637
|
+
const owned = POOL_OWNED_KEYS.filter((key) => Object.hasOwn(next, key));
|
|
5638
|
+
if (owned.length > 0)
|
|
5639
|
+
throw settingsRefusal(`settings cannot set the pool-owned key(s) ${owned.join(", ")}`);
|
|
5640
|
+
if (isDeepStrictEqual3(next, current))
|
|
5641
|
+
return { settings: current, outcome: "unchanged" };
|
|
5642
|
+
const config = composeConfig(result.config, next);
|
|
5643
|
+
const info = { operation: "updateSettings", rowId: void 0 };
|
|
5644
|
+
await writeJsonAtomic2(ctx.configPath, config, {
|
|
5645
|
+
beforeRename: async () => {
|
|
5646
|
+
await ctx.onStep?.("before-config-write", info);
|
|
5647
|
+
await locks.assertAll();
|
|
5648
|
+
}
|
|
5649
|
+
});
|
|
5650
|
+
progress.writes++;
|
|
5651
|
+
await ctx.onStep?.("after-config-write", info);
|
|
5652
|
+
return { settings: settingsOf2(config), outcome: "updated" };
|
|
5653
|
+
} finally {
|
|
5654
|
+
await locks.releaseTo(mark);
|
|
5479
5655
|
}
|
|
5656
|
+
});
|
|
5657
|
+
}
|
|
5658
|
+
var POOL_OWNED_KEYS;
|
|
5659
|
+
var init_settings = __esm({
|
|
5660
|
+
"../core/dist/common-auth-embedded/store/settings.js"() {
|
|
5661
|
+
"use strict";
|
|
5662
|
+
init_atomic_write();
|
|
5663
|
+
init_errors();
|
|
5664
|
+
init_hooks();
|
|
5665
|
+
init_mutate();
|
|
5666
|
+
init_schema();
|
|
5667
|
+
POOL_OWNED_KEYS = Object.freeze([
|
|
5668
|
+
"version",
|
|
5669
|
+
"accounts",
|
|
5670
|
+
POOL_KEY
|
|
5671
|
+
]);
|
|
5480
5672
|
}
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5673
|
+
});
|
|
5674
|
+
|
|
5675
|
+
// ../core/dist/common-auth-embedded/store/pool.js
|
|
5676
|
+
function memoryFor(configPath) {
|
|
5677
|
+
let memory = processMemory.get(configPath);
|
|
5678
|
+
if (!memory) {
|
|
5679
|
+
memory = { removedIds: /* @__PURE__ */ new Set(), firedAtLoad: /* @__PURE__ */ new Set() };
|
|
5680
|
+
processMemory.set(configPath, memory);
|
|
5489
5681
|
}
|
|
5490
|
-
return
|
|
5491
|
-
accountId: fallback.accountId,
|
|
5492
|
-
quotaCheckedAt: snapshotCheckedAt(fallback.quota, fallback.quotaCheckedAt),
|
|
5493
|
-
source: "mode-fallback"
|
|
5494
|
-
};
|
|
5682
|
+
return memory;
|
|
5495
5683
|
}
|
|
5496
|
-
function
|
|
5497
|
-
|
|
5498
|
-
const admitted = new Map(admission.admitted.map((row) => [row.id, row]));
|
|
5499
|
-
const refusals = new Map(admission.refused.map((r) => [r.id, r]));
|
|
5500
|
-
const excluded = new Set(admission.excluded.map((row) => row.id));
|
|
5501
|
-
const validIds = new Set(input2.rows.map((row) => row.id));
|
|
5502
|
-
const pinValid = input2.pin !== void 0 && isPinValid(input2.pin, validIds, input2.identities?.get(input2.pin.accountId));
|
|
5503
|
-
if (pinValid && input2.pin) {
|
|
5504
|
-
const pinned = admitted.get(input2.pin.accountId);
|
|
5505
|
-
if (pinned && input2.killswitch?.get(pinned.id) !== false) {
|
|
5506
|
-
return {
|
|
5507
|
-
outcome: "dispatch",
|
|
5508
|
-
accountId: pinned.id,
|
|
5509
|
-
source: "pin",
|
|
5510
|
-
...pinned.projection?.checkedAt === void 0 ? {} : { quotaCheckedAt: pinned.projection.checkedAt },
|
|
5511
|
-
pin: { action: "retain" },
|
|
5512
|
-
refusedSelections: [],
|
|
5513
|
-
admission
|
|
5514
|
-
};
|
|
5515
|
-
}
|
|
5516
|
-
}
|
|
5517
|
-
const pinRefusal = input2.pin ? refusals.get(input2.pin.accountId) : void 0;
|
|
5518
|
-
const pinMoves = pinValid && input2.pin !== void 0 && input2.refusedPinPolicy === "move-on-confirmed-exhaustion" && (input2.killswitch?.get(input2.pin.accountId) === false || pinRefusal?.reason === "exhausted" || pinRefusal?.reason === "budget-spent");
|
|
5519
|
-
const reserveFor = (row) => {
|
|
5520
|
-
const perRow = typeof input2.rowReservePercent === "function" ? input2.rowReservePercent(row) : input2.rowReservePercent?.get(row.id);
|
|
5521
|
-
return perRow ?? input2.reservePercent ?? {};
|
|
5522
|
-
};
|
|
5523
|
-
const scope = input2.scope;
|
|
5524
|
-
let candidates = input2.rows.map((row, configuredOrder) => ({ row, configuredOrder })).filter(({ row }) => !excluded.has(row.id)).map(({ row, configuredOrder }) => {
|
|
5525
|
-
const killswitchPasses = input2.killswitch?.get(row.id);
|
|
5526
|
-
const credits = input2.resetCreditsApplicable?.get(row.id);
|
|
5684
|
+
function toLoad(result) {
|
|
5685
|
+
if (result.status === "ready")
|
|
5527
5686
|
return {
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
configuredOrder,
|
|
5532
|
-
...credits === void 0 ? {} : { resetCreditsApplicable: credits },
|
|
5533
|
-
...killswitchPasses === void 0 ? {} : { killswitchPasses }
|
|
5687
|
+
status: "ready",
|
|
5688
|
+
schemaVersion: POOL_SCHEMA_VERSION,
|
|
5689
|
+
rows: result.rows
|
|
5534
5690
|
};
|
|
5535
|
-
|
|
5536
|
-
const refusedSelections = [];
|
|
5537
|
-
const unplaced = pinValid ? { action: "retain" } : input2.pin ? { action: "clear" } : { action: "none" };
|
|
5538
|
-
while (candidates.length > 0) {
|
|
5539
|
-
const selection = selectStickyCandidate({
|
|
5540
|
-
candidates,
|
|
5541
|
-
pendingBytes: input2.pendingBytes ?? /* @__PURE__ */ new Map(),
|
|
5542
|
-
requestBytes: input2.requestBytes,
|
|
5543
|
-
now: input2.now,
|
|
5544
|
-
...input2.onEmptyWeightedSet ? { onEmptyWeightedSet: input2.onEmptyWeightedSet } : {}
|
|
5545
|
-
});
|
|
5546
|
-
if (!selection)
|
|
5547
|
-
break;
|
|
5548
|
-
const refusal3 = refusals.get(selection.accountId);
|
|
5549
|
-
if (refusal3) {
|
|
5550
|
-
refusedSelections.push(refusal3);
|
|
5551
|
-
candidates = candidates.filter((candidate) => candidate.accountId !== selection.accountId);
|
|
5552
|
-
continue;
|
|
5553
|
-
}
|
|
5554
|
-
const identity = input2.identities?.get(selection.accountId);
|
|
5691
|
+
if (result.status === "pending-migration")
|
|
5555
5692
|
return {
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
source: selection.source,
|
|
5559
|
-
...selection.quotaCheckedAt === void 0 ? {} : { quotaCheckedAt: selection.quotaCheckedAt },
|
|
5560
|
-
pin: pinValid && !pinMoves ? { action: "retain" } : {
|
|
5561
|
-
action: "assign",
|
|
5562
|
-
pin: {
|
|
5563
|
-
accountId: selection.accountId,
|
|
5564
|
-
inputBytes: input2.requestBytes,
|
|
5565
|
-
...identity === void 0 ? {} : { wireIdentity: identity },
|
|
5566
|
-
...selection.quotaCheckedAt === void 0 ? {} : { quotaCheckedAt: selection.quotaCheckedAt }
|
|
5567
|
-
}
|
|
5568
|
-
},
|
|
5569
|
-
refusedSelections,
|
|
5570
|
-
admission
|
|
5693
|
+
status: "pending-migration",
|
|
5694
|
+
roster: Array.isArray(result.config.accounts) ? result.config.accounts : []
|
|
5571
5695
|
};
|
|
5572
|
-
|
|
5696
|
+
return result;
|
|
5697
|
+
}
|
|
5698
|
+
function openPoolStore(options) {
|
|
5699
|
+
const memory = memoryFor(options.configPath);
|
|
5700
|
+
const lockDefaults = {
|
|
5701
|
+
...POOL_LOCK_DEFAULTS,
|
|
5702
|
+
...options.lockOptions
|
|
5703
|
+
};
|
|
5704
|
+
const ctx = {
|
|
5705
|
+
provider: options.provider,
|
|
5706
|
+
configPath: options.configPath,
|
|
5707
|
+
statePath: options.statePath,
|
|
5708
|
+
codec: options.quota,
|
|
5709
|
+
...options.providerState ? { providerState: options.providerState } : {},
|
|
5710
|
+
now: options.now ?? Date.now,
|
|
5711
|
+
storeLocks: options.storeLocks ?? [
|
|
5712
|
+
{ name: "save", path: options.configPath },
|
|
5713
|
+
{ name: "save", path: options.statePath }
|
|
5714
|
+
],
|
|
5715
|
+
lockDefaults,
|
|
5716
|
+
lockEnv: {
|
|
5717
|
+
...options.onLockEvent ? { onLockEvent: options.onLockEvent } : {},
|
|
5718
|
+
...options.onLockStep ? { onLockStep: options.onLockStep } : {},
|
|
5719
|
+
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
5720
|
+
},
|
|
5721
|
+
removedIds: memory.removedIds,
|
|
5722
|
+
requireCredentialStamps: options.requireCredentialStamps === true,
|
|
5723
|
+
requireRemovedFingerprint: options.requireRemovedFingerprint === true,
|
|
5724
|
+
...options.logger ? { logger: options.logger } : {},
|
|
5725
|
+
...options.onStep ? { onStep: options.onStep } : {},
|
|
5726
|
+
...options.hold ? { hold: options.hold } : {}
|
|
5727
|
+
};
|
|
5728
|
+
const pulls = new PullScheduler(() => rt, options.pull, options.onPullFailure, memory.firedAtLoad, options.logger);
|
|
5729
|
+
const rt = {
|
|
5730
|
+
ctx,
|
|
5731
|
+
providerLock: options.providerLock ?? {
|
|
5732
|
+
name: `provider-${encodeURIComponent(options.provider)}`,
|
|
5733
|
+
path: options.statePath
|
|
5734
|
+
},
|
|
5735
|
+
rowLockOptions: options.rowLockOptions ?? {},
|
|
5736
|
+
firePull: (id, reason) => pulls.fire(id, reason)
|
|
5737
|
+
};
|
|
5738
|
+
const quotaWriter = options.coalesceQuota ? new PoolQuotaWriter(rt, options.quotaDrainTimeoutMs) : void 0;
|
|
5739
|
+
const record3 = (id, attribution, observation) => quotaWriter ? quotaWriter.record(id, attribution, observation) : recordQuota(rt, id, attribution, observation);
|
|
5740
|
+
rt.publishQuota = record3;
|
|
5741
|
+
const overlay = (result) => {
|
|
5742
|
+
if (result.status === "ready" && quotaWriter)
|
|
5743
|
+
return { ...result, rows: quotaWriter.overlay(result.rows) };
|
|
5744
|
+
return result;
|
|
5745
|
+
};
|
|
5573
5746
|
return {
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5747
|
+
async load() {
|
|
5748
|
+
const result = overlay(await readPool(ctx));
|
|
5749
|
+
if (result.status === "ready") {
|
|
5750
|
+
for (const row of result.rows)
|
|
5751
|
+
if ((row.candidate || row.torn && row.enabled) && row.type === "oauth" && row.needsFirstReading)
|
|
5752
|
+
pulls.fire(row.id, "load");
|
|
5753
|
+
}
|
|
5754
|
+
return toLoad(result);
|
|
5755
|
+
},
|
|
5756
|
+
async read() {
|
|
5757
|
+
return toLoad(overlay(await readPool(ctx)));
|
|
5758
|
+
},
|
|
5759
|
+
async initialize(input2 = {}) {
|
|
5760
|
+
return { status: await initializePool(ctx, input2.dropKeys ?? []) };
|
|
5761
|
+
},
|
|
5762
|
+
add: (input2, callOptions) => addRow(rt, input2, callOptions),
|
|
5763
|
+
publishRoster: (plan, callOptions) => publishRoster(rt, plan, callOptions),
|
|
5764
|
+
publication: (operationId) => publication(rt, operationId),
|
|
5765
|
+
replace: (id, credential, input2, callOptions) => replaceRow(rt, id, credential, input2, callOptions),
|
|
5766
|
+
rotate: (id, credential, input2, callOptions) => rotateRow(rt, id, credential, input2, callOptions),
|
|
5767
|
+
updateProviderState: (id, fence, mutator, callOptions) => updateProviderStateRow(rt, id, fence, mutator, callOptions),
|
|
5768
|
+
disable: (id, reason, callOptions) => disableRow(rt, id, reason, callOptions),
|
|
5769
|
+
enable: (id, callOptions) => enableRow(rt, id, callOptions),
|
|
5770
|
+
remove: (id, callOptions) => removeRow(rt, id, callOptions),
|
|
5771
|
+
reorder: (ids, callOptions) => reorderRows(rt, ids, callOptions),
|
|
5772
|
+
readSettings: () => readPoolSettings(rt),
|
|
5773
|
+
updateSettings: (mutator, callOptions) => updatePoolSettings(rt, mutator, callOptions),
|
|
5774
|
+
recordIdentity: (id, identity, attribution, callOptions) => recordRowIdentity(rt, id, identity, attribution, callOptions),
|
|
5775
|
+
refresh: (id, provider2, callOptions) => refreshRow(rt, id, provider2, callOptions),
|
|
5776
|
+
recordQuota: record3,
|
|
5777
|
+
close: () => quotaWriter?.close() ?? Promise.resolve(),
|
|
5778
|
+
dispose: () => quotaWriter?.close() ?? Promise.resolve(),
|
|
5779
|
+
requestReading: (id) => pulls.fire(id, "admission"),
|
|
5780
|
+
pullsSettled: () => pulls.settled()
|
|
5578
5781
|
};
|
|
5579
5782
|
}
|
|
5580
|
-
var
|
|
5581
|
-
var
|
|
5582
|
-
"../core/dist/common-auth-embedded/
|
|
5783
|
+
var processMemory;
|
|
5784
|
+
var init_pool = __esm({
|
|
5785
|
+
"../core/dist/common-auth-embedded/store/pool.js"() {
|
|
5583
5786
|
"use strict";
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5787
|
+
init_attribution();
|
|
5788
|
+
init_mutate();
|
|
5789
|
+
init_provider_state();
|
|
5790
|
+
init_publication();
|
|
5791
|
+
init_pull();
|
|
5792
|
+
init_quota_writer();
|
|
5793
|
+
init_refresh();
|
|
5794
|
+
init_refresh_lock();
|
|
5795
|
+
init_rows();
|
|
5796
|
+
init_schema();
|
|
5797
|
+
init_settings();
|
|
5798
|
+
processMemory = /* @__PURE__ */ new Map();
|
|
5590
5799
|
}
|
|
5591
5800
|
});
|
|
5592
5801
|
|
|
5593
|
-
// ../core/dist/common-auth-embedded/
|
|
5594
|
-
var
|
|
5595
|
-
__export(
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
snapshotCheckedAt: () => snapshotCheckedAt,
|
|
5613
|
-
sustainableWindowWeight: () => sustainableWindowWeight
|
|
5802
|
+
// ../core/dist/common-auth-embedded/store/index.js
|
|
5803
|
+
var store_exports = {};
|
|
5804
|
+
__export(store_exports, {
|
|
5805
|
+
DECLINE_TRANSITION: () => DECLINE_TRANSITION,
|
|
5806
|
+
DUPLICATE_IDENTITY_REASON: () => DUPLICATE_IDENTITY_REASON,
|
|
5807
|
+
LEGACY_STORE_VERSION: () => LEGACY_STORE_VERSION,
|
|
5808
|
+
POOL_KEY: () => POOL_KEY,
|
|
5809
|
+
POOL_LOCK_DEFAULTS: () => POOL_LOCK_DEFAULTS,
|
|
5810
|
+
POOL_OWNED_KEYS: () => POOL_OWNED_KEYS,
|
|
5811
|
+
POOL_ROWS_KEY: () => POOL_ROWS_KEY,
|
|
5812
|
+
POOL_SCHEMA_VERSION: () => POOL_SCHEMA_VERSION,
|
|
5813
|
+
PROVIDER_STATE_KEY: () => PROVIDER_STATE_KEY,
|
|
5814
|
+
PoolOperationError: () => PoolOperationError,
|
|
5815
|
+
PoolReentryError: () => PoolReentryError,
|
|
5816
|
+
REFRESH_STAMP_TOLERANCE_MS: () => REFRESH_STAMP_TOLERANCE_MS,
|
|
5817
|
+
countUnknownIdentityRows: () => countUnknownIdentityRows,
|
|
5818
|
+
fingerprintOf: () => fingerprintOf,
|
|
5819
|
+
openPoolStore: () => openPoolStore,
|
|
5820
|
+
rowLockKey: () => rowLockKey
|
|
5614
5821
|
});
|
|
5615
|
-
var
|
|
5616
|
-
"../core/dist/common-auth-embedded/
|
|
5822
|
+
var init_store = __esm({
|
|
5823
|
+
"../core/dist/common-auth-embedded/store/index.js"() {
|
|
5617
5824
|
"use strict";
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5825
|
+
init_errors();
|
|
5826
|
+
init_identity();
|
|
5827
|
+
init_pool();
|
|
5828
|
+
init_provider_state();
|
|
5829
|
+
init_refresh_lock();
|
|
5830
|
+
init_schema();
|
|
5831
|
+
init_settings();
|
|
5622
5832
|
}
|
|
5623
5833
|
});
|
|
5624
5834
|
|
|
5625
|
-
// ../core/dist/common-auth-embedded/
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
records.push(record3);
|
|
5630
|
-
};
|
|
5631
|
-
return {
|
|
5632
|
-
records,
|
|
5633
|
-
sink,
|
|
5634
|
-
clear: () => {
|
|
5635
|
-
records.length = 0;
|
|
5636
|
-
}
|
|
5637
|
-
};
|
|
5638
|
-
}
|
|
5639
|
-
var init_capture_sink = __esm({
|
|
5640
|
-
"../core/dist/common-auth-embedded/logger/capture-sink.js"() {
|
|
5835
|
+
// ../core/dist/common-auth-embedded/fs/lock-constants.js
|
|
5836
|
+
var WRITER_LOCK_CONSTANTS;
|
|
5837
|
+
var init_lock_constants = __esm({
|
|
5838
|
+
"../core/dist/common-auth-embedded/fs/lock-constants.js"() {
|
|
5641
5839
|
"use strict";
|
|
5840
|
+
WRITER_LOCK_CONSTANTS = Object.freeze({
|
|
5841
|
+
sidebar: Object.freeze({
|
|
5842
|
+
name: "sidebar-write",
|
|
5843
|
+
ttlMs: 1e4,
|
|
5844
|
+
timeoutMs: 15e3,
|
|
5845
|
+
renew: true
|
|
5846
|
+
}),
|
|
5847
|
+
preferences: Object.freeze({
|
|
5848
|
+
name: "preferences",
|
|
5849
|
+
ttlMs: 1e4,
|
|
5850
|
+
timeoutMs: 2e3,
|
|
5851
|
+
renew: true
|
|
5852
|
+
})
|
|
5853
|
+
});
|
|
5642
5854
|
}
|
|
5643
5855
|
});
|
|
5644
5856
|
|
|
5645
|
-
// ../core/dist/common-auth-embedded/
|
|
5646
|
-
|
|
5647
|
-
|
|
5857
|
+
// ../core/dist/common-auth-embedded/fs/index.js
|
|
5858
|
+
var fs_exports = {};
|
|
5859
|
+
__export(fs_exports, {
|
|
5860
|
+
LockContentionError: () => LockContentionError,
|
|
5861
|
+
LockOwnershipError: () => LockOwnershipError,
|
|
5862
|
+
PrivateFileError: () => PrivateFileError,
|
|
5863
|
+
WRITER_LOCK_CONSTANTS: () => WRITER_LOCK_CONSTANTS,
|
|
5864
|
+
acquireRefreshFileLock: () => acquireRefreshFileLock,
|
|
5865
|
+
isLostMarkerRaceError: () => isLostMarkerRaceError,
|
|
5866
|
+
lockPathFor: () => lockPathFor,
|
|
5867
|
+
withLock: () => withLock,
|
|
5868
|
+
writeJsonAtomic: () => writeJsonAtomic2
|
|
5869
|
+
});
|
|
5870
|
+
var init_fs = __esm({
|
|
5871
|
+
"../core/dist/common-auth-embedded/fs/index.js"() {
|
|
5872
|
+
"use strict";
|
|
5873
|
+
init_atomic_write();
|
|
5874
|
+
init_lock_constants();
|
|
5875
|
+
init_private_files();
|
|
5876
|
+
init_refresh_file_lock();
|
|
5877
|
+
init_with_lock();
|
|
5878
|
+
}
|
|
5879
|
+
});
|
|
5880
|
+
|
|
5881
|
+
// ../core/dist/common-auth-embedded/routing/admission.js
|
|
5882
|
+
function exclusionFor(id, inputs, now) {
|
|
5883
|
+
const markedUntil = inputs.rateLimitMarks?.get(id);
|
|
5884
|
+
if (markedUntil !== void 0 && now < markedUntil) {
|
|
5885
|
+
return { id, reason: "rate-limited", until: markedUntil };
|
|
5886
|
+
}
|
|
5887
|
+
const backoffUntil = inputs.refreshBackoff?.get(id);
|
|
5888
|
+
if (backoffUntil !== void 0 && now < backoffUntil) {
|
|
5889
|
+
return { id, reason: "refresh-backoff", until: backoffUntil };
|
|
5890
|
+
}
|
|
5891
|
+
return void 0;
|
|
5648
5892
|
}
|
|
5649
|
-
function
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5893
|
+
function judgeStageOne(id, projection, requiredLabels, now) {
|
|
5894
|
+
if (projection.limits.length === 0) {
|
|
5895
|
+
return {
|
|
5896
|
+
id,
|
|
5897
|
+
stage: 1,
|
|
5898
|
+
gate: 2,
|
|
5899
|
+
reason: "needs-first-reading",
|
|
5900
|
+
pullRequested: true
|
|
5901
|
+
};
|
|
5654
5902
|
}
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
for (const entry of Object.entries(error))
|
|
5667
|
-
if (!listed.has(entry[0]))
|
|
5668
|
-
entries.push(entry);
|
|
5669
|
-
return entries;
|
|
5903
|
+
for (const label of requiredLabels) {
|
|
5904
|
+
if (!projection.limits.some((limit) => limit.label === label)) {
|
|
5905
|
+
return {
|
|
5906
|
+
id,
|
|
5907
|
+
stage: 1,
|
|
5908
|
+
gate: 3,
|
|
5909
|
+
reason: "unknown-window",
|
|
5910
|
+
window: { scope: projection.scope, label },
|
|
5911
|
+
pullRequested: true
|
|
5912
|
+
};
|
|
5913
|
+
}
|
|
5670
5914
|
}
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5915
|
+
const exhausted = projection.limits.filter(readsExhausted);
|
|
5916
|
+
for (const limit of exhausted) {
|
|
5917
|
+
if (futureResetAt(limit, now) === void 0) {
|
|
5918
|
+
return {
|
|
5919
|
+
id,
|
|
5920
|
+
stage: 1,
|
|
5921
|
+
gate: 4,
|
|
5922
|
+
reason: "unknown-reset",
|
|
5923
|
+
window: { scope: limit.scope, label: limit.label },
|
|
5924
|
+
pullRequested: true
|
|
5925
|
+
};
|
|
5674
5926
|
}
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
key,
|
|
5689
|
-
keys && isSecretKey(key) ? MASK : walk(item, keys, seen, childDepth)
|
|
5690
|
-
]));
|
|
5691
|
-
} finally {
|
|
5692
|
-
seen.delete(value);
|
|
5927
|
+
}
|
|
5928
|
+
for (const limit of exhausted) {
|
|
5929
|
+
const resetAtMs = futureResetAt(limit, now);
|
|
5930
|
+
if (resetAtMs !== void 0 && typeof limit.resetsAt === "string") {
|
|
5931
|
+
return {
|
|
5932
|
+
id,
|
|
5933
|
+
stage: 1,
|
|
5934
|
+
gate: 5,
|
|
5935
|
+
reason: "exhausted",
|
|
5936
|
+
window: { scope: limit.scope, label: limit.label },
|
|
5937
|
+
resetsAt: limit.resetsAt,
|
|
5938
|
+
resetAtMs
|
|
5939
|
+
};
|
|
5693
5940
|
}
|
|
5694
5941
|
}
|
|
5695
|
-
return
|
|
5696
|
-
redact: (value) => walk(value, true, /* @__PURE__ */ new WeakSet()),
|
|
5697
|
-
// Schema keys describe arguments, not credentials; only their string values are scrubbed.
|
|
5698
|
-
redactStrings: (value) => walk(value, false, /* @__PURE__ */ new WeakSet())
|
|
5699
|
-
};
|
|
5942
|
+
return void 0;
|
|
5700
5943
|
}
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5944
|
+
function admit(input2) {
|
|
5945
|
+
const scope = input2.scope ?? ALL_SCOPE;
|
|
5946
|
+
const requiredLabels = input2.requiredLabels ?? DEFAULT_REQUIRED_LABELS;
|
|
5947
|
+
const excluded = [];
|
|
5948
|
+
const refused = [];
|
|
5949
|
+
const survivors = [];
|
|
5950
|
+
for (const row of input2.rows) {
|
|
5951
|
+
const exclusion = exclusionFor(row.id, input2, input2.now);
|
|
5952
|
+
if (exclusion) {
|
|
5953
|
+
excluded.push(exclusion);
|
|
5954
|
+
continue;
|
|
5955
|
+
}
|
|
5956
|
+
if (row.kind === "api-key") {
|
|
5957
|
+
survivors.push({ id: row.id, kind: row.kind });
|
|
5958
|
+
continue;
|
|
5959
|
+
}
|
|
5960
|
+
const projection = projectQuota(row.quota, scope);
|
|
5961
|
+
const refusal3 = judgeStageOne(row.id, projection, requiredLabels, input2.now);
|
|
5962
|
+
if (refusal3) {
|
|
5963
|
+
refused.push(refusal3);
|
|
5964
|
+
continue;
|
|
5965
|
+
}
|
|
5966
|
+
survivors.push({ id: row.id, kind: row.kind, projection });
|
|
5967
|
+
}
|
|
5968
|
+
const spent = new Map(survivors.flatMap((row) => {
|
|
5969
|
+
const reset = budgetExhaustedResetAt(row.projection, input2.now);
|
|
5970
|
+
return reset ? [[row.id, reset]] : [];
|
|
5971
|
+
}));
|
|
5972
|
+
const lastPath = spent.size > 0 && spent.size === survivors.length;
|
|
5973
|
+
const admitted = [];
|
|
5974
|
+
for (const row of survivors) {
|
|
5975
|
+
const reset = spent.get(row.id);
|
|
5976
|
+
if (reset === void 0) {
|
|
5977
|
+
admitted.push(row);
|
|
5978
|
+
} else if (lastPath) {
|
|
5979
|
+
admitted.push({ ...row, lastPath: true });
|
|
5980
|
+
} else {
|
|
5981
|
+
refused.push({ id: row.id, stage: 2, reason: "budget-spent", ...reset });
|
|
5982
|
+
}
|
|
5983
|
+
}
|
|
5984
|
+
const order = new Map(input2.rows.map((row, index) => [row.id, index]));
|
|
5985
|
+
const byInput = (left, right) => (order.get(left.id) ?? 0) - (order.get(right.id) ?? 0);
|
|
5986
|
+
refused.sort(byInput);
|
|
5987
|
+
const pulls = refused.filter((refusal3) => "pullRequested" in refusal3).map((refusal3) => refusal3.id);
|
|
5988
|
+
for (const id of pulls)
|
|
5989
|
+
input2.requestPull?.(id);
|
|
5990
|
+
return { admitted, refused, excluded, pulls };
|
|
5991
|
+
}
|
|
5992
|
+
var init_admission = __esm({
|
|
5993
|
+
"../core/dist/common-auth-embedded/routing/admission.js"() {
|
|
5704
5994
|
"use strict";
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
MASK = "***REDACTED***";
|
|
5708
|
-
MAX_ERROR_DEPTH = 8;
|
|
5709
|
-
defaultRedactor = createRedactor();
|
|
5710
|
-
redact = defaultRedactor.redact;
|
|
5711
|
-
redactStrings = defaultRedactor.redactStrings;
|
|
5995
|
+
init_map();
|
|
5996
|
+
init_projection();
|
|
5712
5997
|
}
|
|
5713
5998
|
});
|
|
5714
5999
|
|
|
5715
|
-
// ../core/dist/common-auth-embedded/
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
6000
|
+
// ../core/dist/common-auth-embedded/routing/ordered.js
|
|
6001
|
+
function resolveRoutingMode(value) {
|
|
6002
|
+
switch (value) {
|
|
6003
|
+
case "sticky-balanced":
|
|
6004
|
+
return { mode: "sticky-balanced", placement: "roster" };
|
|
6005
|
+
case "main-first":
|
|
6006
|
+
return { mode: "ordered", placement: "main-first" };
|
|
6007
|
+
case "fallback-first":
|
|
6008
|
+
return { mode: "ordered", placement: "fallback-first" };
|
|
6009
|
+
default:
|
|
6010
|
+
return { mode: "ordered", placement: "roster" };
|
|
5723
6011
|
}
|
|
5724
6012
|
}
|
|
5725
|
-
function
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
if (existsSync(`${f}.${i}`)) {
|
|
5731
|
-
const rotated2 = `${f}.${i + 1}`;
|
|
5732
|
-
renameSync(`${f}.${i}`, rotated2);
|
|
5733
|
-
chmodPrivate(rotated2);
|
|
5734
|
-
}
|
|
5735
|
-
}
|
|
5736
|
-
const rotated = `${f}.1`;
|
|
5737
|
-
renameSync(f, rotated);
|
|
5738
|
-
chmodPrivate(rotated);
|
|
5739
|
-
} catch {
|
|
5740
|
-
}
|
|
6013
|
+
function orderForPlacement(ids, placement, formerMainId = DEFAULT_FORMER_MAIN_ID) {
|
|
6014
|
+
if (placement === "roster" || !ids.includes(formerMainId))
|
|
6015
|
+
return [...ids];
|
|
6016
|
+
const rest = ids.filter((id) => id !== formerMainId);
|
|
6017
|
+
return placement === "main-first" ? [formerMainId, ...rest] : [...rest, formerMainId];
|
|
5741
6018
|
}
|
|
5742
|
-
|
|
5743
|
-
const
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
await privateOperation(file, "log-close", () => handle.close());
|
|
6019
|
+
function routeOrdered(input2) {
|
|
6020
|
+
const admission = admit(input2);
|
|
6021
|
+
const admitted = new Set(admission.admitted.map((row) => row.id));
|
|
6022
|
+
const order = orderForPlacement(input2.rows.map((row) => row.id), input2.placement ?? "roster", input2.formerMainId).filter((id) => admitted.has(id) && input2.killswitch?.get(id) !== false);
|
|
6023
|
+
return { order, admission };
|
|
5748
6024
|
}
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
if (error.code !== "ENOENT")
|
|
5755
|
-
throw error;
|
|
5756
|
-
try {
|
|
5757
|
-
await createPrivateBytes(file, "");
|
|
5758
|
-
} catch (creationError) {
|
|
5759
|
-
if (creationError.code !== "EEXIST")
|
|
5760
|
-
throw creationError;
|
|
5761
|
-
await verifyPrivate(file, "file", true);
|
|
6025
|
+
function nextOrderedAttempt(order, attempts2, retryStatuses) {
|
|
6026
|
+
const last = attempts2.at(-1);
|
|
6027
|
+
if (last !== void 0) {
|
|
6028
|
+
if (last.status === void 0 || !retryStatuses.includes(last.status)) {
|
|
6029
|
+
return void 0;
|
|
5762
6030
|
}
|
|
5763
6031
|
}
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
return sink.handle;
|
|
6032
|
+
const tried = new Set(attempts2.map((attempt) => attempt.id));
|
|
6033
|
+
return order.find((id) => !tried.has(id));
|
|
5767
6034
|
}
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
const info = await privateOperation(file, "log-stat", () => handle.stat());
|
|
5775
|
-
if (info.size >= MAX_BYTES) {
|
|
5776
|
-
await closeWindowsFile(sink);
|
|
5777
|
-
for (let i = ROTATE_KEEP - 1; i >= 0; i--) {
|
|
5778
|
-
const source = i === 0 ? file : `${file}.${i}`;
|
|
5779
|
-
const target = `${file}.${i + 1}`;
|
|
5780
|
-
try {
|
|
5781
|
-
await verifyPrivate(source, "file", true);
|
|
5782
|
-
} catch (error) {
|
|
5783
|
-
if (error.code === "ENOENT")
|
|
5784
|
-
continue;
|
|
5785
|
-
throw error;
|
|
5786
|
-
}
|
|
5787
|
-
try {
|
|
5788
|
-
await verifyPrivate(target, "file", true);
|
|
5789
|
-
} catch (error) {
|
|
5790
|
-
if (error.code !== "ENOENT")
|
|
5791
|
-
throw error;
|
|
5792
|
-
}
|
|
5793
|
-
await replaceWindowsFile(source, target);
|
|
5794
|
-
await verifyPrivate(target, "file");
|
|
5795
|
-
}
|
|
5796
|
-
handle = await openWindowsFile(sink, file);
|
|
5797
|
-
}
|
|
5798
|
-
await privateOperation(file, "log-append", () => handle.appendFile(text2, "utf8"));
|
|
5799
|
-
} catch (error) {
|
|
5800
|
-
await closeWindowsFile(sink).catch(() => {
|
|
5801
|
-
});
|
|
5802
|
-
throw error;
|
|
6035
|
+
var DEFAULT_FORMER_MAIN_ID;
|
|
6036
|
+
var init_ordered = __esm({
|
|
6037
|
+
"../core/dist/common-auth-embedded/routing/ordered.js"() {
|
|
6038
|
+
"use strict";
|
|
6039
|
+
init_admission();
|
|
6040
|
+
DEFAULT_FORMER_MAIN_ID = "main";
|
|
5803
6041
|
}
|
|
6042
|
+
});
|
|
6043
|
+
|
|
6044
|
+
// ../core/dist/common-auth-embedded/routing/pins.js
|
|
6045
|
+
function isPinValid(pin, validIds, currentIdentity) {
|
|
6046
|
+
if (!validIds.has(pin.accountId))
|
|
6047
|
+
return false;
|
|
6048
|
+
return !(typeof pin.wireIdentity === "string" && typeof currentIdentity === "string" && pin.wireIdentity !== currentIdentity);
|
|
5804
6049
|
}
|
|
5805
|
-
function
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
6050
|
+
function pendingBytesForPins(pins, quotaCheckedAtById, excludedSessionKey) {
|
|
6051
|
+
const pending = /* @__PURE__ */ new Map();
|
|
6052
|
+
for (const [sessionKey, pin] of pins) {
|
|
6053
|
+
if (sessionKey === excludedSessionKey)
|
|
6054
|
+
continue;
|
|
6055
|
+
if (pin.quotaCheckedAt !== quotaCheckedAtById.get(pin.accountId))
|
|
6056
|
+
continue;
|
|
6057
|
+
pending.set(pin.accountId, (pending.get(pin.accountId) ?? 0) + (pin.inputBytes ?? 0));
|
|
5810
6058
|
}
|
|
6059
|
+
return pending;
|
|
5811
6060
|
}
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
let runtimeLevel;
|
|
5816
|
-
let redactor = createRedactor();
|
|
5817
|
-
let captureSink;
|
|
5818
|
-
let buffer = [];
|
|
5819
|
-
let timer;
|
|
5820
|
-
let orderedSink = Promise.resolve();
|
|
5821
|
-
let sinkError;
|
|
5822
|
-
const windowsFile = {};
|
|
5823
|
-
function queueWindows(operation) {
|
|
5824
|
-
const next = orderedSink.then(operation);
|
|
5825
|
-
orderedSink = next.catch((error) => {
|
|
5826
|
-
sinkError = error;
|
|
5827
|
-
});
|
|
5828
|
-
return next;
|
|
5829
|
-
}
|
|
5830
|
-
function configure(next) {
|
|
5831
|
-
if (windowsPrivateFiles && next.file !== logFileSource)
|
|
5832
|
-
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
5833
|
-
});
|
|
5834
|
-
logFileSource = next.file;
|
|
5835
|
-
initLevelSource = next.level;
|
|
5836
|
-
redactor = createRedactor(next);
|
|
5837
|
-
captureSink = next.captureSink;
|
|
5838
|
-
}
|
|
5839
|
-
function setLogLevel3(l) {
|
|
5840
|
-
if (l === void 0 || l in ORDER)
|
|
5841
|
-
runtimeLevel = l;
|
|
5842
|
-
}
|
|
5843
|
-
function logFilePath() {
|
|
5844
|
-
if (logFileSource === void 0)
|
|
5845
|
-
return void 0;
|
|
5846
|
-
const resolved = typeof logFileSource === "function" ? logFileSource() : logFileSource;
|
|
5847
|
-
return resolved || void 0;
|
|
5848
|
-
}
|
|
5849
|
-
function configuredLevel() {
|
|
5850
|
-
if (runtimeLevel)
|
|
5851
|
-
return runtimeLevel;
|
|
5852
|
-
const floor = typeof initLevelSource === "function" ? initLevelSource() : initLevelSource;
|
|
5853
|
-
if (floor && floor in ORDER)
|
|
5854
|
-
return floor;
|
|
5855
|
-
return "info";
|
|
6061
|
+
var init_pins = __esm({
|
|
6062
|
+
"../core/dist/common-auth-embedded/routing/pins.js"() {
|
|
6063
|
+
"use strict";
|
|
5856
6064
|
}
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
if (
|
|
5863
|
-
|
|
5864
|
-
return queueWindows(async () => {
|
|
5865
|
-
if (close)
|
|
5866
|
-
await closeWindowsFile(windowsFile);
|
|
5867
|
-
if (sinkError)
|
|
5868
|
-
throw sinkError;
|
|
5869
|
-
});
|
|
5870
|
-
return;
|
|
5871
|
-
}
|
|
5872
|
-
let file;
|
|
5873
|
-
try {
|
|
5874
|
-
file = logFilePath();
|
|
5875
|
-
} catch {
|
|
5876
|
-
buffer = [];
|
|
5877
|
-
if (windowsPrivateFiles && close)
|
|
5878
|
-
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
5879
|
-
return;
|
|
5880
|
-
}
|
|
5881
|
-
const text2 = buffer.join("");
|
|
5882
|
-
buffer = [];
|
|
5883
|
-
if (!file) {
|
|
5884
|
-
if (windowsPrivateFiles && close)
|
|
5885
|
-
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
5886
|
-
return;
|
|
5887
|
-
}
|
|
5888
|
-
if (windowsPrivateFiles) {
|
|
5889
|
-
return queueWindows(async () => {
|
|
5890
|
-
try {
|
|
5891
|
-
await flushWindowsFile(windowsFile, file, text2);
|
|
5892
|
-
} finally {
|
|
5893
|
-
if (close)
|
|
5894
|
-
await closeWindowsFile(windowsFile);
|
|
5895
|
-
}
|
|
5896
|
-
});
|
|
6065
|
+
});
|
|
6066
|
+
|
|
6067
|
+
// ../core/dist/common-auth-embedded/routing/sticky.js
|
|
6068
|
+
function snapshotCheckedAt(quota, entryCheckedAt) {
|
|
6069
|
+
for (const checkedAt of [quota?.checkedAt, entryCheckedAt]) {
|
|
6070
|
+
if (typeof checkedAt === "number" && Number.isFinite(checkedAt)) {
|
|
6071
|
+
return checkedAt;
|
|
5897
6072
|
}
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
6073
|
+
}
|
|
6074
|
+
return void 0;
|
|
6075
|
+
}
|
|
6076
|
+
function defaultStickyStatusClass(status) {
|
|
6077
|
+
if (status === 401 || status === 403)
|
|
6078
|
+
return "permanent";
|
|
6079
|
+
if (status === void 0 || status === 0 || !Number.isFinite(status) || status >= 500 && status <= 599 || status === 429) {
|
|
6080
|
+
return "transient";
|
|
6081
|
+
}
|
|
6082
|
+
return "healthy";
|
|
6083
|
+
}
|
|
6084
|
+
function windowReadings(quota) {
|
|
6085
|
+
return quota.limits.filter((limit) => limit.kind === "reading").sort((left, right) => {
|
|
6086
|
+
const leftKnown = left.windowMinutes !== void 0;
|
|
6087
|
+
const rightKnown = right.windowMinutes !== void 0;
|
|
6088
|
+
if (leftKnown !== rightKnown)
|
|
6089
|
+
return leftKnown ? -1 : 1;
|
|
6090
|
+
if (leftKnown && rightKnown) {
|
|
6091
|
+
return (right.windowMinutes ?? 0) - (left.windowMinutes ?? 0);
|
|
5904
6092
|
}
|
|
6093
|
+
return 0;
|
|
6094
|
+
});
|
|
6095
|
+
}
|
|
6096
|
+
function decideStickyBreak(input2) {
|
|
6097
|
+
const statusClass = (input2.classifyStatus ?? defaultStickyStatusClass)(input2.status);
|
|
6098
|
+
if (statusClass === "permanent") {
|
|
6099
|
+
return { action: "migrate", reason: "permanent" };
|
|
5905
6100
|
}
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
if (flushed instanceof Promise)
|
|
5912
|
-
void flushed.catch(() => {
|
|
5913
|
-
});
|
|
5914
|
-
}, 500);
|
|
6101
|
+
if (!input2.quota)
|
|
6102
|
+
return { action: "retain", reason: "unknown" };
|
|
6103
|
+
const checkedAt = snapshotCheckedAt(input2.quota, input2.quotaCheckedAt);
|
|
6104
|
+
if (checkedAt === void 0 || !Number.isFinite(checkedAt) || input2.now - checkedAt > QUOTA_STALENESS_MS) {
|
|
6105
|
+
return { action: "retain", reason: "stale" };
|
|
5915
6106
|
}
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
}
|
|
5929
|
-
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${level.toUpperCase()} [${channel}] ${scrubbedMessage}` + (data === void 0 ? "" : safeSerialize(scrubbedData)) + "\n";
|
|
5930
|
-
try {
|
|
5931
|
-
captureSink?.({
|
|
5932
|
-
channel,
|
|
5933
|
-
level,
|
|
5934
|
-
message: scrubbedMessage,
|
|
5935
|
-
data: scrubbedData
|
|
5936
|
-
});
|
|
5937
|
-
} catch {
|
|
5938
|
-
}
|
|
5939
|
-
if (logFileSource === void 0)
|
|
5940
|
-
return;
|
|
5941
|
-
buffer.push(line);
|
|
5942
|
-
if (buffer.length >= 50) {
|
|
5943
|
-
const flushed = flushLogs3(false);
|
|
5944
|
-
if (flushed instanceof Promise)
|
|
5945
|
-
void flushed.catch(() => {
|
|
5946
|
-
});
|
|
5947
|
-
} else
|
|
5948
|
-
schedule2();
|
|
5949
|
-
} catch {
|
|
6107
|
+
if (input2.killswitchPasses === false) {
|
|
6108
|
+
return { action: "migrate", reason: "killswitch" };
|
|
6109
|
+
}
|
|
6110
|
+
for (const limit of windowReadings(input2.quota)) {
|
|
6111
|
+
const remaining = limit.remainingPercent;
|
|
6112
|
+
if (typeof remaining === "number" && Number.isFinite(remaining) && remaining <= 0) {
|
|
6113
|
+
return {
|
|
6114
|
+
action: "migrate",
|
|
6115
|
+
reason: "exhausted",
|
|
6116
|
+
window: { scope: limit.scope, label: limit.label },
|
|
6117
|
+
...typeof limit.resetsAt === "string" ? { resetsAt: limit.resetsAt } : {}
|
|
6118
|
+
};
|
|
5950
6119
|
}
|
|
5951
6120
|
}
|
|
5952
|
-
|
|
6121
|
+
const budgetReset = budgetExhaustedResetAt(input2.quota, input2.now);
|
|
6122
|
+
if (budgetReset) {
|
|
5953
6123
|
return {
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
debug: (m, d) => emit(channel, "debug", m, d),
|
|
5958
|
-
trace: (m, d) => emit(channel, "trace", m, d)
|
|
6124
|
+
action: "migrate",
|
|
6125
|
+
reason: "exhausted",
|
|
6126
|
+
resetsAt: budgetReset.resetsAt
|
|
5959
6127
|
};
|
|
5960
6128
|
}
|
|
5961
|
-
|
|
5962
|
-
if (windowsPrivateFiles)
|
|
5963
|
-
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
5964
|
-
});
|
|
5965
|
-
sinkError = void 0;
|
|
5966
|
-
buffer = [];
|
|
5967
|
-
if (timer) {
|
|
5968
|
-
clearTimeout(timer);
|
|
5969
|
-
timer = void 0;
|
|
5970
|
-
}
|
|
5971
|
-
logFileSource = void 0;
|
|
5972
|
-
initLevelSource = void 0;
|
|
5973
|
-
runtimeLevel = void 0;
|
|
5974
|
-
redactor = createRedactor();
|
|
5975
|
-
captureSink = void 0;
|
|
5976
|
-
}
|
|
5977
|
-
if (options)
|
|
5978
|
-
configure(options);
|
|
5979
|
-
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3, reset };
|
|
5980
|
-
}
|
|
5981
|
-
function createLoggerInstance(options) {
|
|
5982
|
-
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = createEngine(options);
|
|
5983
|
-
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
5984
|
-
}
|
|
5985
|
-
function initLogger(options) {
|
|
5986
|
-
defaultEngine.configure(options);
|
|
5987
|
-
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = defaultEngine;
|
|
5988
|
-
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
6129
|
+
return { action: "retain", reason: statusClass };
|
|
5989
6130
|
}
|
|
5990
|
-
function
|
|
5991
|
-
|
|
6131
|
+
function sustainableWindowWeight(window, reservePercent, now) {
|
|
6132
|
+
const spendable = Math.max(0, window.remainingPercent - reservePercent);
|
|
6133
|
+
if (spendable <= 0)
|
|
6134
|
+
return 0;
|
|
6135
|
+
if (!window.resetsAt)
|
|
6136
|
+
return spendable;
|
|
6137
|
+
const resetMs = Date.parse(window.resetsAt);
|
|
6138
|
+
if (!Number.isFinite(resetMs) || resetMs <= now)
|
|
6139
|
+
return spendable;
|
|
6140
|
+
const hours = Math.max((resetMs - now) / 36e5, MIN_RESET_HOURS);
|
|
6141
|
+
return spendable / hours;
|
|
5992
6142
|
}
|
|
5993
|
-
function
|
|
5994
|
-
|
|
6143
|
+
function compareAccountIds(left, right) {
|
|
6144
|
+
if (left < right)
|
|
6145
|
+
return -1;
|
|
6146
|
+
if (left > right)
|
|
6147
|
+
return 1;
|
|
6148
|
+
return 0;
|
|
5995
6149
|
}
|
|
5996
|
-
function
|
|
5997
|
-
|
|
6150
|
+
function candidateWeight(candidate, now) {
|
|
6151
|
+
if (!candidate.quota)
|
|
6152
|
+
return void 0;
|
|
6153
|
+
const quotaCheckedAt = snapshotCheckedAt(candidate.quota, candidate.quotaCheckedAt);
|
|
6154
|
+
if (quotaCheckedAt === void 0 || now - quotaCheckedAt > QUOTA_STALENESS_MS) {
|
|
6155
|
+
return void 0;
|
|
6156
|
+
}
|
|
6157
|
+
const weights = windowReadings(candidate.quota).map((limit) => sustainableWindowWeight({
|
|
6158
|
+
remainingPercent: limit.remainingPercent ?? Number.NaN,
|
|
6159
|
+
...limit.resetsAt === void 0 ? {} : { resetsAt: limit.resetsAt }
|
|
6160
|
+
}, candidate.reservePercent[limit.label] ?? 0, now));
|
|
6161
|
+
const budget = candidate.quota.budget;
|
|
6162
|
+
if (budget && typeof budget.remainingPercent === "number" && Number.isFinite(budget.remainingPercent)) {
|
|
6163
|
+
weights.push(sustainableWindowWeight({
|
|
6164
|
+
remainingPercent: budget.remainingPercent,
|
|
6165
|
+
...budget.resetsAt === void 0 ? {} : { resetsAt: budget.resetsAt }
|
|
6166
|
+
}, 0, now));
|
|
6167
|
+
}
|
|
6168
|
+
const weight = weights.length > 0 ? Math.min(...weights) : 0;
|
|
6169
|
+
return weight > 0 ? { candidate, quotaCheckedAt, weight } : void 0;
|
|
5998
6170
|
}
|
|
5999
|
-
|
|
6000
|
-
|
|
6171
|
+
function selectStickyCandidate(input2) {
|
|
6172
|
+
const eligibleCandidates = input2.candidates.filter((candidate) => candidate.killswitchPasses !== false);
|
|
6173
|
+
if (input2.candidates.length === 0) {
|
|
6174
|
+
throw new Error("Cannot select a sticky candidate: input.candidates is empty");
|
|
6175
|
+
}
|
|
6176
|
+
if (eligibleCandidates.length === 0)
|
|
6177
|
+
return void 0;
|
|
6178
|
+
const weighted = eligibleCandidates.map((candidate) => candidateWeight(candidate, input2.now)).filter((candidate) => candidate !== void 0);
|
|
6179
|
+
if (weighted.length > 0) {
|
|
6180
|
+
weighted.sort((left, right) => {
|
|
6181
|
+
const leftScore = ((input2.pendingBytes.get(left.candidate.accountId) ?? 0) + input2.requestBytes) / Math.max(left.weight, MIN_WEIGHT);
|
|
6182
|
+
const rightScore = ((input2.pendingBytes.get(right.candidate.accountId) ?? 0) + input2.requestBytes) / Math.max(right.weight, MIN_WEIGHT);
|
|
6183
|
+
return leftScore - rightScore || left.candidate.configuredOrder - right.candidate.configuredOrder || compareAccountIds(left.candidate.accountId, right.candidate.accountId);
|
|
6184
|
+
});
|
|
6185
|
+
const selected = weighted[0];
|
|
6186
|
+
if (selected) {
|
|
6187
|
+
return {
|
|
6188
|
+
accountId: selected.candidate.accountId,
|
|
6189
|
+
quotaCheckedAt: selected.quotaCheckedAt,
|
|
6190
|
+
source: "weighted"
|
|
6191
|
+
};
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
input2.onEmptyWeightedSet?.();
|
|
6195
|
+
const fallback = [...eligibleCandidates].sort((left, right) => {
|
|
6196
|
+
const leftHasCredits = (left.resetCreditsApplicable ?? 0) > 0 ? 1 : 0;
|
|
6197
|
+
const rightHasCredits = (right.resetCreditsApplicable ?? 0) > 0 ? 1 : 0;
|
|
6198
|
+
return rightHasCredits - leftHasCredits || left.configuredOrder - right.configuredOrder || compareAccountIds(left.accountId, right.accountId);
|
|
6199
|
+
})[0];
|
|
6200
|
+
if (!fallback) {
|
|
6201
|
+
throw new Error("Cannot select a sticky candidate: input.candidates is empty");
|
|
6202
|
+
}
|
|
6203
|
+
return {
|
|
6204
|
+
accountId: fallback.accountId,
|
|
6205
|
+
quotaCheckedAt: snapshotCheckedAt(fallback.quota, fallback.quotaCheckedAt),
|
|
6206
|
+
source: "mode-fallback"
|
|
6207
|
+
};
|
|
6001
6208
|
}
|
|
6002
|
-
function
|
|
6003
|
-
|
|
6209
|
+
function routeSticky(input2) {
|
|
6210
|
+
const admission = admit(input2);
|
|
6211
|
+
const admitted = new Map(admission.admitted.map((row) => [row.id, row]));
|
|
6212
|
+
const refusals = new Map(admission.refused.map((r) => [r.id, r]));
|
|
6213
|
+
const excluded = new Set(admission.excluded.map((row) => row.id));
|
|
6214
|
+
const validIds = new Set(input2.rows.map((row) => row.id));
|
|
6215
|
+
const pinValid = input2.pin !== void 0 && isPinValid(input2.pin, validIds, input2.identities?.get(input2.pin.accountId));
|
|
6216
|
+
if (pinValid && input2.pin) {
|
|
6217
|
+
const pinned = admitted.get(input2.pin.accountId);
|
|
6218
|
+
if (pinned && input2.killswitch?.get(pinned.id) !== false) {
|
|
6219
|
+
return {
|
|
6220
|
+
outcome: "dispatch",
|
|
6221
|
+
accountId: pinned.id,
|
|
6222
|
+
source: "pin",
|
|
6223
|
+
...pinned.projection?.checkedAt === void 0 ? {} : { quotaCheckedAt: pinned.projection.checkedAt },
|
|
6224
|
+
pin: { action: "retain" },
|
|
6225
|
+
refusedSelections: [],
|
|
6226
|
+
admission
|
|
6227
|
+
};
|
|
6228
|
+
}
|
|
6229
|
+
}
|
|
6230
|
+
const pinRefusal = input2.pin ? refusals.get(input2.pin.accountId) : void 0;
|
|
6231
|
+
const pinMoves = pinValid && input2.pin !== void 0 && input2.refusedPinPolicy === "move-on-confirmed-exhaustion" && (input2.killswitch?.get(input2.pin.accountId) === false || pinRefusal?.reason === "exhausted" || pinRefusal?.reason === "budget-spent");
|
|
6232
|
+
const reserveFor = (row) => {
|
|
6233
|
+
const perRow = typeof input2.rowReservePercent === "function" ? input2.rowReservePercent(row) : input2.rowReservePercent?.get(row.id);
|
|
6234
|
+
return perRow ?? input2.reservePercent ?? {};
|
|
6235
|
+
};
|
|
6236
|
+
const scope = input2.scope;
|
|
6237
|
+
let candidates = input2.rows.map((row, configuredOrder) => ({ row, configuredOrder })).filter(({ row }) => !excluded.has(row.id)).map(({ row, configuredOrder }) => {
|
|
6238
|
+
const killswitchPasses = input2.killswitch?.get(row.id);
|
|
6239
|
+
const credits = input2.resetCreditsApplicable?.get(row.id);
|
|
6240
|
+
return {
|
|
6241
|
+
accountId: row.id,
|
|
6242
|
+
quota: row.kind === "api-key" ? void 0 : admitted.get(row.id)?.projection ?? projectQuota(row.quota, scope),
|
|
6243
|
+
reservePercent: reserveFor(row),
|
|
6244
|
+
configuredOrder,
|
|
6245
|
+
...credits === void 0 ? {} : { resetCreditsApplicable: credits },
|
|
6246
|
+
...killswitchPasses === void 0 ? {} : { killswitchPasses }
|
|
6247
|
+
};
|
|
6248
|
+
});
|
|
6249
|
+
const refusedSelections = [];
|
|
6250
|
+
const unplaced = pinValid ? { action: "retain" } : input2.pin ? { action: "clear" } : { action: "none" };
|
|
6251
|
+
while (candidates.length > 0) {
|
|
6252
|
+
const selection = selectStickyCandidate({
|
|
6253
|
+
candidates,
|
|
6254
|
+
pendingBytes: input2.pendingBytes ?? /* @__PURE__ */ new Map(),
|
|
6255
|
+
requestBytes: input2.requestBytes,
|
|
6256
|
+
now: input2.now,
|
|
6257
|
+
...input2.onEmptyWeightedSet ? { onEmptyWeightedSet: input2.onEmptyWeightedSet } : {}
|
|
6258
|
+
});
|
|
6259
|
+
if (!selection)
|
|
6260
|
+
break;
|
|
6261
|
+
const refusal3 = refusals.get(selection.accountId);
|
|
6262
|
+
if (refusal3) {
|
|
6263
|
+
refusedSelections.push(refusal3);
|
|
6264
|
+
candidates = candidates.filter((candidate) => candidate.accountId !== selection.accountId);
|
|
6265
|
+
continue;
|
|
6266
|
+
}
|
|
6267
|
+
const identity = input2.identities?.get(selection.accountId);
|
|
6268
|
+
return {
|
|
6269
|
+
outcome: "dispatch",
|
|
6270
|
+
accountId: selection.accountId,
|
|
6271
|
+
source: selection.source,
|
|
6272
|
+
...selection.quotaCheckedAt === void 0 ? {} : { quotaCheckedAt: selection.quotaCheckedAt },
|
|
6273
|
+
pin: pinValid && !pinMoves ? { action: "retain" } : {
|
|
6274
|
+
action: "assign",
|
|
6275
|
+
pin: {
|
|
6276
|
+
accountId: selection.accountId,
|
|
6277
|
+
inputBytes: input2.requestBytes,
|
|
6278
|
+
...identity === void 0 ? {} : { wireIdentity: identity },
|
|
6279
|
+
...selection.quotaCheckedAt === void 0 ? {} : { quotaCheckedAt: selection.quotaCheckedAt }
|
|
6280
|
+
}
|
|
6281
|
+
},
|
|
6282
|
+
refusedSelections,
|
|
6283
|
+
admission
|
|
6284
|
+
};
|
|
6285
|
+
}
|
|
6286
|
+
return {
|
|
6287
|
+
outcome: "no-admissible-account",
|
|
6288
|
+
pin: unplaced,
|
|
6289
|
+
refusedSelections,
|
|
6290
|
+
admission
|
|
6291
|
+
};
|
|
6004
6292
|
}
|
|
6005
|
-
var
|
|
6006
|
-
var
|
|
6007
|
-
"../core/dist/common-auth-embedded/
|
|
6293
|
+
var QUOTA_STALENESS_MS, MIN_RESET_HOURS, MIN_WEIGHT;
|
|
6294
|
+
var init_sticky = __esm({
|
|
6295
|
+
"../core/dist/common-auth-embedded/routing/sticky.js"() {
|
|
6008
6296
|
"use strict";
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
debug: 3,
|
|
6016
|
-
trace: 4
|
|
6017
|
-
};
|
|
6018
|
-
MAX_BYTES = 5 * 1024 * 1024;
|
|
6019
|
-
ROTATE_KEEP = 3;
|
|
6020
|
-
defaultEngine = createEngine();
|
|
6297
|
+
init_projection();
|
|
6298
|
+
init_admission();
|
|
6299
|
+
init_pins();
|
|
6300
|
+
QUOTA_STALENESS_MS = 15 * 6e4;
|
|
6301
|
+
MIN_RESET_HOURS = 1 / 60;
|
|
6302
|
+
MIN_WEIGHT = 1e-6;
|
|
6021
6303
|
}
|
|
6022
6304
|
});
|
|
6023
6305
|
|
|
6024
|
-
// ../core/dist/common-auth-embedded/
|
|
6025
|
-
var
|
|
6026
|
-
__export(
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6306
|
+
// ../core/dist/common-auth-embedded/routing/index.js
|
|
6307
|
+
var routing_exports = {};
|
|
6308
|
+
__export(routing_exports, {
|
|
6309
|
+
DEFAULT_FORMER_MAIN_ID: () => DEFAULT_FORMER_MAIN_ID,
|
|
6310
|
+
MIN_RESET_HOURS: () => MIN_RESET_HOURS,
|
|
6311
|
+
MIN_WEIGHT: () => MIN_WEIGHT,
|
|
6312
|
+
QUOTA_STALENESS_MS: () => QUOTA_STALENESS_MS,
|
|
6313
|
+
admit: () => admit,
|
|
6314
|
+
decideStickyBreak: () => decideStickyBreak,
|
|
6315
|
+
defaultStickyStatusClass: () => defaultStickyStatusClass,
|
|
6316
|
+
exclusionFor: () => exclusionFor,
|
|
6317
|
+
isPinValid: () => isPinValid,
|
|
6318
|
+
nextOrderedAttempt: () => nextOrderedAttempt,
|
|
6319
|
+
orderForPlacement: () => orderForPlacement,
|
|
6320
|
+
pendingBytesForPins: () => pendingBytesForPins,
|
|
6321
|
+
resolveRoutingMode: () => resolveRoutingMode,
|
|
6322
|
+
routeOrdered: () => routeOrdered,
|
|
6323
|
+
routeSticky: () => routeSticky,
|
|
6324
|
+
selectStickyCandidate: () => selectStickyCandidate,
|
|
6325
|
+
snapshotCheckedAt: () => snapshotCheckedAt,
|
|
6326
|
+
sustainableWindowWeight: () => sustainableWindowWeight
|
|
6038
6327
|
});
|
|
6039
|
-
var
|
|
6040
|
-
"../core/dist/common-auth-embedded/
|
|
6328
|
+
var init_routing = __esm({
|
|
6329
|
+
"../core/dist/common-auth-embedded/routing/index.js"() {
|
|
6041
6330
|
"use strict";
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6331
|
+
init_admission();
|
|
6332
|
+
init_ordered();
|
|
6333
|
+
init_pins();
|
|
6334
|
+
init_sticky();
|
|
6045
6335
|
}
|
|
6046
6336
|
});
|
|
6047
6337
|
|
|
@@ -6338,13 +6628,16 @@ function addedText(name, result) {
|
|
|
6338
6628
|
function failureMessage(error) {
|
|
6339
6629
|
return projectFailure(error).text;
|
|
6340
6630
|
}
|
|
6341
|
-
async function snapshot(
|
|
6631
|
+
async function snapshot(options) {
|
|
6632
|
+
const { store } = options;
|
|
6342
6633
|
const load = await store.read();
|
|
6343
6634
|
const read = await store.readSettings();
|
|
6635
|
+
const vault = await options.routing?.vaultOrder?.();
|
|
6344
6636
|
return {
|
|
6345
6637
|
load,
|
|
6346
6638
|
rows: distinctRows(load),
|
|
6347
|
-
settings: read.status === "error" ? {} : read.settings
|
|
6639
|
+
settings: read.status === "error" ? {} : read.settings,
|
|
6640
|
+
...vault ? { vault } : {}
|
|
6348
6641
|
};
|
|
6349
6642
|
}
|
|
6350
6643
|
function accountView(row, options) {
|
|
@@ -6551,6 +6844,57 @@ function quotaSection2(options, snap) {
|
|
|
6551
6844
|
}
|
|
6552
6845
|
};
|
|
6553
6846
|
}
|
|
6847
|
+
async function reorderVault(vault, order) {
|
|
6848
|
+
try {
|
|
6849
|
+
return await vault.reorder(order);
|
|
6850
|
+
} catch (error) {
|
|
6851
|
+
if (error instanceof Error && error.name === "ClaustrumConsumerError" && error.kind === "invalid-order")
|
|
6852
|
+
throw new CommandError("vault-invalid-order", error.message, {
|
|
6853
|
+
cause: error
|
|
6854
|
+
});
|
|
6855
|
+
throw error;
|
|
6856
|
+
}
|
|
6857
|
+
}
|
|
6858
|
+
function invalidVaultOrder(message) {
|
|
6859
|
+
return new CommandError("vault-invalid-order", message);
|
|
6860
|
+
}
|
|
6861
|
+
function vaultNames(vault) {
|
|
6862
|
+
const rows = vault.rows.map((row) => ({
|
|
6863
|
+
id: row.id,
|
|
6864
|
+
label: row.label.trim() || row.id
|
|
6865
|
+
}));
|
|
6866
|
+
const matches2 = (entry) => rows.filter((row) => row.id === entry || row.label === entry);
|
|
6867
|
+
return {
|
|
6868
|
+
ids: rows.map((row) => row.id),
|
|
6869
|
+
nameOf: (id) => rows.find((row) => row.id === id)?.label ?? id,
|
|
6870
|
+
/**
|
|
6871
|
+
* What the order input starts with for an account: its label when
|
|
6872
|
+
* typing that label back names this account alone, else its route id
|
|
6873
|
+
* (two accounts sharing a label, or a label with a comma or line break
|
|
6874
|
+
* in it, either of which would split it into two entries).
|
|
6875
|
+
*/
|
|
6876
|
+
entryOf: (id) => {
|
|
6877
|
+
const row = rows.find((entry) => entry.id === id);
|
|
6878
|
+
return row && !/[,\n]/.test(row.label) && matches2(row.label).length === 1 ? row.label : id;
|
|
6879
|
+
},
|
|
6880
|
+
/** The route ids the typed entries name, in order; refuses before any write. */
|
|
6881
|
+
resolve: (entries) => {
|
|
6882
|
+
const ids = [];
|
|
6883
|
+
for (const entry of entries) {
|
|
6884
|
+
const found = matches2(entry);
|
|
6885
|
+
if (found.length === 0)
|
|
6886
|
+
throw invalidVaultOrder(`"${entry}" is not a vault account.`);
|
|
6887
|
+
if (found.length > 1)
|
|
6888
|
+
throw invalidVaultOrder(`"${entry}" matches more than one vault account; enter those accounts by route id.`);
|
|
6889
|
+
const id = found[0].id;
|
|
6890
|
+
if (ids.includes(id))
|
|
6891
|
+
throw invalidVaultOrder(`"${entry}" names an account already in the order.`);
|
|
6892
|
+
ids.push(id);
|
|
6893
|
+
}
|
|
6894
|
+
return ids;
|
|
6895
|
+
}
|
|
6896
|
+
};
|
|
6897
|
+
}
|
|
6554
6898
|
function routingSection2(options, snap) {
|
|
6555
6899
|
const { store, extraLocks } = options;
|
|
6556
6900
|
const locks = extraLocks ? { extraLocks } : {};
|
|
@@ -6562,14 +6906,16 @@ function routingSection2(options, snap) {
|
|
|
6562
6906
|
const raw = record(snap.settings.routing).mode;
|
|
6563
6907
|
const current = typeof raw === "string" && choices.some((choice) => choice.value === raw) ? raw : "ordered";
|
|
6564
6908
|
const resolved = resolveRoutingMode(current);
|
|
6565
|
-
const
|
|
6909
|
+
const vault = snap.vault ? vaultNames(snap.vault) : void 0;
|
|
6910
|
+
const ids = vault ? vault.ids : snap.rows.map((row) => row.id);
|
|
6911
|
+
const nameOf = (id) => vault ? vault.nameOf(id) : id;
|
|
6566
6912
|
const tried = orderForPlacement(ids, resolved.placement, options.routing?.formerMainId ?? DEFAULT_FORMER_MAIN_ID);
|
|
6567
6913
|
const label = choices.find((choice) => choice.value === current)?.label ?? current;
|
|
6568
6914
|
const lines = [`Mode: ${label}`];
|
|
6569
6915
|
if (ids.length > 0)
|
|
6570
|
-
lines.push(
|
|
6916
|
+
lines.push(`${vault ? "Vault account order" : "Roster order"}: ${ids.map(nameOf).join(", ")}`);
|
|
6571
6917
|
if (resolved.mode === "ordered" && tried.join() !== ids.join())
|
|
6572
|
-
lines.push(`Tried in order: ${tried.join(", ")}`);
|
|
6918
|
+
lines.push(`Tried in order: ${tried.map(nameOf).join(", ")}`);
|
|
6573
6919
|
const actions = [
|
|
6574
6920
|
{
|
|
6575
6921
|
id: "mode",
|
|
@@ -6597,15 +6943,16 @@ function routingSection2(options, snap) {
|
|
|
6597
6943
|
{
|
|
6598
6944
|
kind: "text",
|
|
6599
6945
|
id: "order",
|
|
6600
|
-
label: "Account ids, first to last",
|
|
6601
|
-
value: ids.join(", "),
|
|
6946
|
+
label: vault ? "Vault accounts, first to last, separated by commas" : "Account ids, first to last",
|
|
6947
|
+
value: vault ? ids.map(vault.entryOf).join(", ") : ids.join(", "),
|
|
6602
6948
|
required: true
|
|
6603
6949
|
}
|
|
6604
6950
|
],
|
|
6605
6951
|
run: async ({ values }) => {
|
|
6606
|
-
const
|
|
6607
|
-
const
|
|
6608
|
-
|
|
6952
|
+
const text2 = String(values.order);
|
|
6953
|
+
const entries = text2.split(vault ? /[,\n]+/ : /[\s,]+/).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
6954
|
+
const result = snap.vault && vault ? await reorderVault(snap.vault, vault.resolve(entries)) : await store.reorder(entries, locks);
|
|
6955
|
+
return result.outcome === "unchanged" ? "The order is unchanged." : `Order set to ${result.ids.map(nameOf).join(", ")}.`;
|
|
6609
6956
|
}
|
|
6610
6957
|
});
|
|
6611
6958
|
return {
|
|
@@ -6734,7 +7081,7 @@ function limitsSection2(options, snap) {
|
|
|
6734
7081
|
};
|
|
6735
7082
|
}
|
|
6736
7083
|
async function builtinSections(options) {
|
|
6737
|
-
const snap = await snapshot(options
|
|
7084
|
+
const snap = await snapshot(options);
|
|
6738
7085
|
return [
|
|
6739
7086
|
accountsSection2(options, snap),
|
|
6740
7087
|
quotaSection2(options, snap),
|
|
@@ -10169,6 +10516,59 @@ var init_custody = __esm({
|
|
|
10169
10516
|
}
|
|
10170
10517
|
});
|
|
10171
10518
|
|
|
10519
|
+
// ../core/dist/common-auth-embedded/quota/pending.js
|
|
10520
|
+
function quotaFields(publication2, witness = "") {
|
|
10521
|
+
const result = /* @__PURE__ */ new Map();
|
|
10522
|
+
const { observation } = publication2;
|
|
10523
|
+
const add = (key, at, part) => result.set(`${witness}:${key}`, {
|
|
10524
|
+
at,
|
|
10525
|
+
order: 0,
|
|
10526
|
+
publication: { ...publication2, observation: part }
|
|
10527
|
+
});
|
|
10528
|
+
const keyFor = (scope, label) => JSON.stringify([scope ?? "all", label]);
|
|
10529
|
+
const read = /* @__PURE__ */ new Set();
|
|
10530
|
+
for (const reading of observation.readings ?? []) {
|
|
10531
|
+
const key = keyFor(reading.scope, reading.label);
|
|
10532
|
+
read.add(key);
|
|
10533
|
+
add(key, observation.checkedAt, {
|
|
10534
|
+
checkedAt: observation.checkedAt,
|
|
10535
|
+
readings: [{ ...reading }]
|
|
10536
|
+
});
|
|
10537
|
+
}
|
|
10538
|
+
for (const pair of observation.coverage ?? []) {
|
|
10539
|
+
const key = keyFor(pair.scope, pair.label);
|
|
10540
|
+
if (!read.has(key))
|
|
10541
|
+
add(key, observation.checkedAt, {
|
|
10542
|
+
checkedAt: observation.checkedAt,
|
|
10543
|
+
coverage: [{ ...pair }]
|
|
10544
|
+
});
|
|
10545
|
+
}
|
|
10546
|
+
if (observation.budget)
|
|
10547
|
+
add("budget", observation.checkedAt, {
|
|
10548
|
+
checkedAt: observation.checkedAt,
|
|
10549
|
+
budget: { ...observation.budget }
|
|
10550
|
+
});
|
|
10551
|
+
for (const [name, counter] of Object.entries(observation.counters ?? {})) {
|
|
10552
|
+
add(`counter:${name}`, counter.checkedAt, {
|
|
10553
|
+
checkedAt: observation.checkedAt,
|
|
10554
|
+
counters: { [name]: { ...counter } }
|
|
10555
|
+
});
|
|
10556
|
+
}
|
|
10557
|
+
if (observation.credits)
|
|
10558
|
+
add("credits", observation.credits.checkedAt, {
|
|
10559
|
+
checkedAt: observation.checkedAt,
|
|
10560
|
+
credits: { ...observation.credits }
|
|
10561
|
+
});
|
|
10562
|
+
if (!result.size)
|
|
10563
|
+
add("empty", observation.checkedAt, { checkedAt: observation.checkedAt });
|
|
10564
|
+
return result;
|
|
10565
|
+
}
|
|
10566
|
+
var init_pending = __esm({
|
|
10567
|
+
"../core/dist/common-auth-embedded/quota/pending.js"() {
|
|
10568
|
+
"use strict";
|
|
10569
|
+
}
|
|
10570
|
+
});
|
|
10571
|
+
|
|
10172
10572
|
// ../core/dist/common-auth-embedded/claustrum/interlock.js
|
|
10173
10573
|
function matches(entry, credentialId, accountIdentity) {
|
|
10174
10574
|
if (entry.accountIdentity !== void 0 && accountIdentity !== void 0)
|
|
@@ -10469,6 +10869,52 @@ function acceptVaultRoute(path5, routeId) {
|
|
|
10469
10869
|
};
|
|
10470
10870
|
});
|
|
10471
10871
|
}
|
|
10872
|
+
function invalidOrder(message) {
|
|
10873
|
+
return new ClaustrumConsumerError("invalid-order", message);
|
|
10874
|
+
}
|
|
10875
|
+
function vaultOrderProblem(rows, routeIds) {
|
|
10876
|
+
if (!Array.isArray(routeIds))
|
|
10877
|
+
return "route ids must be an array of route ids";
|
|
10878
|
+
const rosterIds = new Set(rows.map((row) => row.routeId));
|
|
10879
|
+
const given = /* @__PURE__ */ new Set();
|
|
10880
|
+
for (const id of routeIds) {
|
|
10881
|
+
if (typeof id !== "string")
|
|
10882
|
+
return "route ids must be an array of route ids";
|
|
10883
|
+
if (given.has(id))
|
|
10884
|
+
return `route id ${id} appears more than once`;
|
|
10885
|
+
if (!rosterIds.has(id))
|
|
10886
|
+
return `route id ${id} is not in the roster`;
|
|
10887
|
+
given.add(id);
|
|
10888
|
+
}
|
|
10889
|
+
const missing = [...rosterIds].filter((id) => !given.has(id)).length;
|
|
10890
|
+
if (missing > 0)
|
|
10891
|
+
return `the order leaves out ${missing} roster route id${missing === 1 ? "" : "s"}`;
|
|
10892
|
+
return void 0;
|
|
10893
|
+
}
|
|
10894
|
+
function reorderVaultRoster(path5, routeIds, options = {}) {
|
|
10895
|
+
return mutateVaultRoster(path5, (current) => {
|
|
10896
|
+
const rows = current?.rows ?? [];
|
|
10897
|
+
const problem = vaultOrderProblem(rows, routeIds);
|
|
10898
|
+
if (problem)
|
|
10899
|
+
throw invalidOrder(problem);
|
|
10900
|
+
const byId = /* @__PURE__ */ new Map();
|
|
10901
|
+
for (const row of rows) {
|
|
10902
|
+
const group = byId.get(row.routeId);
|
|
10903
|
+
if (group)
|
|
10904
|
+
group.push(row);
|
|
10905
|
+
else
|
|
10906
|
+
byId.set(row.routeId, [row]);
|
|
10907
|
+
}
|
|
10908
|
+
const ids = [...routeIds];
|
|
10909
|
+
const next = ids.flatMap((id) => byId.get(id) ?? []);
|
|
10910
|
+
if (!current || next.every((row, index) => row === rows[index]))
|
|
10911
|
+
return { result: { ids, outcome: "unchanged" } };
|
|
10912
|
+
return {
|
|
10913
|
+
next: { ...current, rows: next },
|
|
10914
|
+
result: { ids, outcome: "reordered" }
|
|
10915
|
+
};
|
|
10916
|
+
}, { ...options.signal && { signal: options.signal } });
|
|
10917
|
+
}
|
|
10472
10918
|
function receiptFence(row, receipt2) {
|
|
10473
10919
|
if (!memberIds(row).includes(receipt2.credentialId))
|
|
10474
10920
|
return "refuse";
|
|
@@ -10614,8 +11060,8 @@ var init_roster = __esm({
|
|
|
10614
11060
|
init_quota();
|
|
10615
11061
|
init_errors2();
|
|
10616
11062
|
init_interlock();
|
|
10617
|
-
|
|
10618
|
-
|
|
11063
|
+
init_quota_writer2();
|
|
11064
|
+
init_quota_writer2();
|
|
10619
11065
|
DEFAULT_ROUTE_PREFIX = "vault:";
|
|
10620
11066
|
SKIPPED_REASONS = /* @__PURE__ */ new Set([
|
|
10621
11067
|
"empty credential id",
|
|
@@ -10664,56 +11110,12 @@ function retainVaultQuotaWriter(path5, listener) {
|
|
|
10664
11110
|
})();
|
|
10665
11111
|
}
|
|
10666
11112
|
function fields(publication2) {
|
|
10667
|
-
|
|
10668
|
-
const { observation } = publication2;
|
|
10669
|
-
const witness = JSON.stringify([
|
|
11113
|
+
return quotaFields(publication2, JSON.stringify([
|
|
10670
11114
|
publication2.routeId,
|
|
10671
11115
|
publication2.receipt?.credentialId,
|
|
10672
11116
|
publication2.receipt?.accountIdentitySource,
|
|
10673
11117
|
publication2.receipt?.expectedAccountIdentity
|
|
10674
|
-
]);
|
|
10675
|
-
const add = (key, at, part) => result.set(`${witness}:${key}`, {
|
|
10676
|
-
at,
|
|
10677
|
-
order: 0,
|
|
10678
|
-
publication: { ...publication2, observation: part }
|
|
10679
|
-
});
|
|
10680
|
-
const keyFor = (scope, label) => JSON.stringify([scope ?? "all", label]);
|
|
10681
|
-
const read = /* @__PURE__ */ new Set();
|
|
10682
|
-
for (const reading of observation.readings ?? []) {
|
|
10683
|
-
const key = keyFor(reading.scope, reading.label);
|
|
10684
|
-
read.add(key);
|
|
10685
|
-
add(key, observation.checkedAt, {
|
|
10686
|
-
checkedAt: observation.checkedAt,
|
|
10687
|
-
readings: [{ ...reading }]
|
|
10688
|
-
});
|
|
10689
|
-
}
|
|
10690
|
-
for (const pair of observation.coverage ?? []) {
|
|
10691
|
-
const key = keyFor(pair.scope, pair.label);
|
|
10692
|
-
if (!read.has(key))
|
|
10693
|
-
add(key, observation.checkedAt, {
|
|
10694
|
-
checkedAt: observation.checkedAt,
|
|
10695
|
-
coverage: [{ ...pair }]
|
|
10696
|
-
});
|
|
10697
|
-
}
|
|
10698
|
-
if (observation.budget)
|
|
10699
|
-
add("budget", observation.checkedAt, {
|
|
10700
|
-
checkedAt: observation.checkedAt,
|
|
10701
|
-
budget: { ...observation.budget }
|
|
10702
|
-
});
|
|
10703
|
-
for (const [name, counter] of Object.entries(observation.counters ?? {})) {
|
|
10704
|
-
add(`counter:${name}`, counter.checkedAt, {
|
|
10705
|
-
checkedAt: observation.checkedAt,
|
|
10706
|
-
counters: { [name]: { ...counter } }
|
|
10707
|
-
});
|
|
10708
|
-
}
|
|
10709
|
-
if (observation.credits)
|
|
10710
|
-
add("credits", observation.credits.checkedAt, {
|
|
10711
|
-
checkedAt: observation.checkedAt,
|
|
10712
|
-
credits: { ...observation.credits }
|
|
10713
|
-
});
|
|
10714
|
-
if (!result.size)
|
|
10715
|
-
add("empty", observation.checkedAt, { checkedAt: observation.checkedAt });
|
|
10716
|
-
return result;
|
|
11118
|
+
]));
|
|
10717
11119
|
}
|
|
10718
11120
|
function enqueueVaultQuota(path5, publication2) {
|
|
10719
11121
|
if (!isQuotaObservation(publication2.observation))
|
|
@@ -10737,7 +11139,7 @@ function enqueueVaultQuota(path5, publication2) {
|
|
|
10737
11139
|
writer.pending.set(account, pending);
|
|
10738
11140
|
for (const listener of writer.listeners)
|
|
10739
11141
|
listener(publication2);
|
|
10740
|
-
schedule(writer,
|
|
11142
|
+
schedule(writer, COALESCE_MS2);
|
|
10741
11143
|
return Promise.resolve(true);
|
|
10742
11144
|
}
|
|
10743
11145
|
function orderedFields(pending) {
|
|
@@ -10802,7 +11204,7 @@ function flush(writer) {
|
|
|
10802
11204
|
writer.running = void 0;
|
|
10803
11205
|
for (const wake of writer.wake)
|
|
10804
11206
|
wake();
|
|
10805
|
-
const backoff = writer.failures ? Math.min(5e3, 100 * 2 ** Math.min(writer.failures, 6)) * (0.5 + Math.random()) :
|
|
11207
|
+
const backoff = writer.failures ? Math.min(5e3, 100 * 2 ** Math.min(writer.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS2;
|
|
10806
11208
|
schedule(writer, backoff);
|
|
10807
11209
|
}
|
|
10808
11210
|
})();
|
|
@@ -10848,16 +11250,17 @@ async function drainVaultQuota(path5, timeoutMs = 1e3) {
|
|
|
10848
11250
|
}
|
|
10849
11251
|
}
|
|
10850
11252
|
}
|
|
10851
|
-
var writers, logger,
|
|
10852
|
-
var
|
|
11253
|
+
var writers, logger, COALESCE_MS2;
|
|
11254
|
+
var init_quota_writer2 = __esm({
|
|
10853
11255
|
"../core/dist/common-auth-embedded/claustrum/quota-writer.js"() {
|
|
10854
11256
|
"use strict";
|
|
10855
11257
|
init_logger();
|
|
10856
11258
|
init_quota();
|
|
11259
|
+
init_pending();
|
|
10857
11260
|
init_roster();
|
|
10858
11261
|
writers = /* @__PURE__ */ new Map();
|
|
10859
11262
|
logger = createLogger2("claustrum");
|
|
10860
|
-
|
|
11263
|
+
COALESCE_MS2 = 100;
|
|
10861
11264
|
}
|
|
10862
11265
|
});
|
|
10863
11266
|
|
|
@@ -10872,7 +11275,7 @@ var init_consumer = __esm({
|
|
|
10872
11275
|
init_enrollment();
|
|
10873
11276
|
init_errors2();
|
|
10874
11277
|
init_insula();
|
|
10875
|
-
|
|
11278
|
+
init_quota_writer2();
|
|
10876
11279
|
init_roster();
|
|
10877
11280
|
init_watch();
|
|
10878
11281
|
ClaustrumConsumer = class {
|
|
@@ -11303,7 +11706,10 @@ var init_consumer = __esm({
|
|
|
11303
11706
|
let current;
|
|
11304
11707
|
try {
|
|
11305
11708
|
current = await this.authorize(routeId, signal);
|
|
11306
|
-
|
|
11709
|
+
signal?.throwIfAborted();
|
|
11710
|
+
} catch (error) {
|
|
11711
|
+
if (signal?.aborted)
|
|
11712
|
+
throw error;
|
|
11307
11713
|
}
|
|
11308
11714
|
if (decideScopedRetryAfter401(options.site, served, current, this.#logger)) {
|
|
11309
11715
|
await response.body?.cancel().catch(() => {
|
|
@@ -11333,6 +11739,17 @@ var init_consumer = __esm({
|
|
|
11333
11739
|
await acceptVaultRoute(this.#options.rosterPath, routeId);
|
|
11334
11740
|
this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
11335
11741
|
}
|
|
11742
|
+
/**
|
|
11743
|
+
* Set the order vault accounts are tried in (`reorderVaultRoster`), then
|
|
11744
|
+
* re-read the roster, so the next routing decision in this process uses
|
|
11745
|
+
* the new order without waiting for a discovery. Never contacts the vault.
|
|
11746
|
+
*/
|
|
11747
|
+
async reorder(routeIds) {
|
|
11748
|
+
this.#assertOpen();
|
|
11749
|
+
const result = await reorderVaultRoster(this.#options.rosterPath, routeIds);
|
|
11750
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
11751
|
+
return result;
|
|
11752
|
+
}
|
|
11336
11753
|
/**
|
|
11337
11754
|
* Store a quota or profile observation for a vault route. The receipt the
|
|
11338
11755
|
* reading was taken with is required: the observation lands only while the
|
|
@@ -11448,6 +11865,7 @@ __export(claustrum_exports, {
|
|
|
11448
11865
|
recordVaultAccountQuota: () => recordVaultAccountQuota,
|
|
11449
11866
|
recordVaultQuota: () => recordVaultQuota,
|
|
11450
11867
|
refreshVaultRoster: () => refreshVaultRoster,
|
|
11868
|
+
reorderVaultRoster: () => reorderVaultRoster,
|
|
11451
11869
|
resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
|
|
11452
11870
|
resolveVaultPrimary: () => resolveVaultPrimary,
|
|
11453
11871
|
vaultRoutingRows: () => vaultRoutingRows
|
|
@@ -11470,7 +11888,7 @@ var init_claustrum = __esm({
|
|
|
11470
11888
|
init_host_slot();
|
|
11471
11889
|
init_insula();
|
|
11472
11890
|
init_interlock();
|
|
11473
|
-
|
|
11891
|
+
init_quota_writer2();
|
|
11474
11892
|
init_roster();
|
|
11475
11893
|
init_watch();
|
|
11476
11894
|
}
|
|
@@ -31401,7 +31819,7 @@ async function assertHostsStopped(fence, env3) {
|
|
|
31401
31819
|
|
|
31402
31820
|
// src/common-auth-embedded/setup/enroll.js
|
|
31403
31821
|
var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
|
|
31404
|
-
var UNSUPPORTED_VAULT_MESSAGE =
|
|
31822
|
+
var UNSUPPORTED_VAULT_MESSAGE = 'This Claustrum vault is too old to connect plugins. Run ck upgrade to move to Claustrum v0.2.0 or newer (read "Upgrading from v0.1.3" in its release notes first), or run setup without --claustrum to use local accounts.';
|
|
31405
31823
|
var ENROLLMENT_WAIT_MS = 3e5;
|
|
31406
31824
|
var APPROVAL_POLL_MS = 1e3;
|
|
31407
31825
|
var PROPOSE_BACKOFF_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
@@ -32818,7 +33236,7 @@ function describeEnrollment(status) {
|
|
|
32818
33236
|
case "blocked":
|
|
32819
33237
|
return `blocked (${status.code})`;
|
|
32820
33238
|
case "unavailable":
|
|
32821
|
-
return isUnsupportedEnrollment(status) ? "
|
|
33239
|
+
return isUnsupportedEnrollment(status) ? "vault too old to connect plugins" : `vault unavailable (${status.code})`;
|
|
32822
33240
|
case "busy":
|
|
32823
33241
|
return "another setup step is running";
|
|
32824
33242
|
}
|
|
@@ -32888,7 +33306,7 @@ function enrollmentGuidance(status) {
|
|
|
32888
33306
|
if (status.state === "unavailable") {
|
|
32889
33307
|
if (isUnsupportedEnrollment(status))
|
|
32890
33308
|
return [
|
|
32891
|
-
|
|
33309
|
+
'This Claustrum vault is too old to connect plugins. Run ck upgrade to move to Claustrum v0.2.0 or newer (read "Upgrading from v0.1.3" in its release notes first), or keep using your local accounts.'
|
|
32892
33310
|
];
|
|
32893
33311
|
return [
|
|
32894
33312
|
"Check that the vault is running and its connection file is available, then request vault access again."
|
|
@@ -47928,6 +48346,7 @@ function createRequestExecutor(deps) {
|
|
|
47928
48346
|
next = await deadline.wait(
|
|
47929
48347
|
() => credentials.admit({ account, signal: abortSignal })
|
|
47930
48348
|
);
|
|
48349
|
+
checkAborted();
|
|
47931
48350
|
} catch {
|
|
47932
48351
|
checkAborted();
|
|
47933
48352
|
}
|