@cortexkit/anthropic-auth-core 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,6 +68,7 @@ export type AccountScopedQuotaWindow = AccountQuotaWindow & {
68
68
  };
69
69
  export type OAuthQuotaSnapshot = Partial<Record<QuotaWindowName, AccountQuotaWindow>> & {
70
70
  scoped?: AccountScopedQuotaWindow[];
71
+ checkedAt?: number;
71
72
  };
72
73
  export type RoutingMode = 'main-first' | 'fallback-first';
73
74
  export type KillswitchThresholds = Partial<Record<QuotaWindowName | '5h' | '1w' | 'scoped', number>>;
package/dist/accounts.js CHANGED
@@ -178,6 +178,14 @@ function normalizeQuota(value) {
178
178
  if (normalized)
179
179
  quota[key] = normalized;
180
180
  }
181
+ // Persist a top-level snapshot checkedAt through normalize so the
182
+ // mergeAccountRuntimeState freshness comparison stays meaningful when the
183
+ // snapshot has no per-window checkedAt (e.g. {scoped:[]}). Pre-feature
184
+ // inputs without this key are unaffected — only on-disk snapshots that
185
+ // already carry it reach this branch.
186
+ if (typeof value.checkedAt === 'number' && Number.isFinite(value.checkedAt)) {
187
+ quota.checkedAt = value.checkedAt;
188
+ }
181
189
  if (Array.isArray(value.scoped)) {
182
190
  const scoped = value.scoped
183
191
  .map((entry) => {
@@ -206,8 +214,11 @@ function normalizeQuota(value) {
206
214
  };
207
215
  })
208
216
  .filter((entry) => entry != null);
209
- if (scoped.length)
210
- quota.scoped = scoped;
217
+ // Preserve empty `[]` so a downstream reader can distinguish "scoped
218
+ // owned by anthropic-auth, none visible" from "no scoped data on this
219
+ // snapshot". Pre-feature inputs without a `scoped` key are not affected
220
+ // — only inputs that already carried an array reach this line.
221
+ quota.scoped = scoped;
211
222
  }
212
223
  return Object.keys(quota).length ? quota : undefined;
213
224
  }
@@ -384,7 +395,7 @@ function accountRuntimeState(account) {
384
395
  });
385
396
  }
386
397
  function quotaSnapshotCheckedAt(quota) {
387
- return Math.max(quota?.five_hour?.checkedAt ?? 0, quota?.seven_day?.checkedAt ?? 0, ...(quota?.scoped?.map((window) => window.checkedAt) ?? []));
398
+ return Math.max(quota?.five_hour?.checkedAt ?? 0, quota?.seven_day?.checkedAt ?? 0, ...(quota?.scoped?.map((window) => window.checkedAt) ?? []), quota?.checkedAt ?? 0);
388
399
  }
389
400
  function mergeAccountRuntimeState(existing, incoming) {
390
401
  if (!isRecord(existing))
@@ -1404,7 +1415,7 @@ function slugForQuotaIdentity(value) {
1404
1415
  }
1405
1416
  function mapScopedWeeklyLimits(limits, checkedAt) {
1406
1417
  if (!Array.isArray(limits))
1407
- return undefined;
1418
+ return [];
1408
1419
  const seen = new Set();
1409
1420
  const scoped = [];
1410
1421
  for (const limit of limits) {
@@ -1437,7 +1448,7 @@ function mapScopedWeeklyLimits(limits, checkedAt) {
1437
1448
  checkedAt,
1438
1449
  });
1439
1450
  }
1440
- return scoped.length ? scoped : undefined;
1451
+ return scoped;
1441
1452
  }
1442
1453
  function mapUsageWindow(window, checkedAt) {
1443
1454
  if (typeof window?.utilization !== 'number')
@@ -1478,6 +1489,7 @@ export async function fetchOAuthQuotaSnapshot(input) {
1478
1489
  five_hour: mapUsageWindow(usage.five_hour, checkedAt),
1479
1490
  seven_day: mapUsageWindow(usage.seven_day, checkedAt),
1480
1491
  scoped: mapScopedWeeklyLimits(usage.limits, checkedAt),
1492
+ checkedAt,
1481
1493
  };
1482
1494
  }
1483
1495
  function updateStoredAccount(storage, account) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",