@cortexkit/opencode-openai-auth 1.23.1 → 1.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +7 -7
- package/dist/{index-7hy72nfy.js → index-9kges8jy.js} +2 -2
- package/dist/index-ekt6aq17.js +60 -0
- package/dist/index-nd2ks7er.js +2 -0
- package/dist/{index-p81hxfe6.js → index-vf4nn20q.js} +1 -1
- package/dist/{index-bd18sfjj.js → index-x00sxt2w.js} +10 -10
- package/dist/{index-3ya2s179.js → index-xkngfyvc.js} +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/{runtime-layout-B07ApQZL.d.ts → internal-DacVgEWs.d.ts} +86 -663
- package/dist/rpc/port-file.js +1 -1
- package/dist/runtime-layout-Dcbj_Rq3.d.ts +650 -0
- package/dist/{sidebar-state--OTpRzFd.d.ts → sidebar-state-L--CdbLi.d.ts} +4 -15
- package/dist/sidebar-state.d.ts +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/tui.d.ts +5 -2
- package/dist/v2/server.d.ts +2 -1
- package/dist/v2/server.js +4 -4
- package/package.json +1 -1
- package/src/tui-compiled/raw/shared/054118b2705fdc20-ansi.js +98 -0
- package/src/tui-compiled/raw/shared/0895e780489c494d-window.js +33 -0
- package/src/tui-compiled/raw/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
- package/src/tui-compiled/raw/shared/0c9533222cb4380c-namespace.js +224 -0
- package/src/tui-compiled/raw/shared/112607e46a5b5f58-accounts.js +393 -0
- package/src/tui-compiled/raw/shared/136fa4abe48ad69d-cachekeep.js +411 -0
- package/src/tui-compiled/raw/shared/1547bd74f4214d2d-index.js +28 -0
- package/src/tui-compiled/raw/shared/1567207f323dc733-codex-http.js +44 -0
- package/src/tui-compiled/raw/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
- package/src/tui-compiled/raw/shared/18df43cab4563acf-families.js +149 -0
- package/src/tui-compiled/raw/shared/1a4c289eec261e04-codex-instructions.js +59 -0
- package/src/tui-compiled/raw/shared/1afd446e190ef85c-vault-messages.js +12 -0
- package/src/tui-compiled/raw/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
- package/src/tui-compiled/raw/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
- package/src/tui-compiled/raw/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
- package/src/tui-compiled/raw/shared/22b2bce42f2d6806-handle.js +10 -0
- package/src/tui-compiled/raw/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
- package/src/tui-compiled/raw/shared/26055d4e5ad5e71f-codex-request.js +198 -0
- package/src/tui-compiled/raw/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
- package/src/tui-compiled/raw/shared/2bb681e99c2721d7-registry.js +538 -0
- package/src/tui-compiled/raw/shared/2dce6e9613993329-quota-manager.js +13 -20
- package/src/tui-compiled/raw/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
- package/src/tui-compiled/raw/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
- package/src/tui-compiled/raw/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
- package/src/tui-compiled/raw/shared/3b31b36bf0877602-wording.js +120 -0
- package/src/tui-compiled/raw/shared/3c4c1a2d3fc92726-failure.js +59 -0
- package/src/tui-compiled/raw/shared/3dfe71eec6e0487d-presets.js +240 -0
- package/src/tui-compiled/raw/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
- package/src/tui-compiled/raw/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
- package/src/tui-compiled/raw/shared/4adf46e07e025363-axes.js +7 -0
- package/src/tui-compiled/raw/shared/4ba847b77580b1eb-confirm.js +21 -0
- package/src/tui-compiled/raw/shared/4d05c2d7a531aece-oauth.js +48 -36
- package/src/tui-compiled/raw/shared/5018d4665e969588-limit-policy.js +159 -0
- package/src/tui-compiled/raw/shared/595bdf3fff13ba79-limit-identity.js +49 -0
- package/src/tui-compiled/raw/shared/59def9e82b61204a-session-cache-activity.js +35 -0
- package/src/tui-compiled/raw/shared/5d806e1a305d14f5-commands.js +879 -0
- package/src/tui-compiled/raw/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
- package/src/tui-compiled/raw/shared/63c1ee7e70e85e8d-vault.js +1 -0
- package/src/tui-compiled/raw/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
- package/src/tui-compiled/raw/shared/66937534c260d20b-stable-json.js +11 -0
- package/src/tui-compiled/raw/shared/7056acef1b021f19-bridge.js +10 -0
- package/src/tui-compiled/raw/shared/72d2ca42883809b4-marker.js +107 -0
- package/src/tui-compiled/raw/shared/775431e21f469203-record.js +3 -0
- package/src/tui-compiled/raw/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
- package/src/tui-compiled/raw/shared/7b2a0471b29e4f5e-wake.js +47 -0
- package/src/tui-compiled/raw/shared/7b5d6afff4ff32b9-select.js +159 -0
- package/src/tui-compiled/raw/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
- package/src/tui-compiled/raw/shared/7c98bde36aad4819-input-transformations.js +34 -0
- package/src/tui-compiled/raw/shared/7fb0418303f20a10-index.js +3 -0
- package/src/tui-compiled/raw/shared/806e12ccbad34388-pi-wait.js +51 -0
- package/src/tui-compiled/raw/shared/81ae201b724cac14-menu.js +73 -0
- package/src/tui-compiled/raw/shared/8349ed25dc629e97-scope.js +10 -0
- package/src/tui-compiled/raw/shared/86da3379973780b9-limit-provenance.js +60 -0
- package/src/tui-compiled/raw/shared/8aba66ed486d30a7-decide.js +425 -0
- package/src/tui-compiled/raw/shared/8c0c8df25a5dca1f-manager.js +735 -0
- package/src/tui-compiled/raw/shared/8c42bbec02f59636-vault-routing.js +212 -0
- package/src/tui-compiled/raw/shared/8ca6175bfae53e13-envelope.js +123 -0
- package/src/tui-compiled/raw/shared/8d0245e41049d83f-header-classifier.js +121 -0
- package/src/tui-compiled/raw/shared/9c162809179c7560-login.js +89 -0
- package/src/tui-compiled/raw/shared/a1f495296a4b756f-frame-turn.js +72 -0
- package/src/tui-compiled/raw/shared/a37138dcbd893f55-hold-bounds.js +5 -0
- package/src/tui-compiled/raw/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
- package/src/tui-compiled/raw/shared/adc5eeb5a8d28280-persistence.js +9 -0
- package/src/tui-compiled/raw/shared/b301c79e6378d1fb-vault.js +678 -0
- package/src/tui-compiled/raw/shared/b3c11de5f36e617a-reset.js +44 -0
- package/src/tui-compiled/raw/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
- package/src/tui-compiled/raw/shared/bd4aef685681048c-duration.js +20 -0
- package/src/tui-compiled/raw/shared/bd5977eca210d2b8-index.js +662 -0
- package/src/tui-compiled/raw/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
- package/src/tui-compiled/raw/shared/c66495424ad84aee-hold.js +25 -0
- package/src/tui-compiled/raw/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
- package/src/tui-compiled/raw/shared/c9340fb545c4e5de-internal.js +73 -0
- package/src/tui-compiled/raw/shared/c954c6447b7b9b64-activity.js +52 -0
- package/src/tui-compiled/raw/shared/cba8b0aee46b8526-codex-lite.js +85 -0
- package/src/tui-compiled/raw/shared/cec39ccddab4fe9c-labels.js +11 -0
- package/src/tui-compiled/raw/shared/cef0f2346957e83c-index.js +552 -0
- package/src/tui-compiled/raw/shared/cf7dedf24f902d68-dump-size.js +41 -0
- package/src/tui-compiled/raw/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
- package/src/tui-compiled/raw/shared/d5b268767d330507-doctor.js +81 -0
- package/src/tui-compiled/raw/shared/d7ac5ca41f49121b-index.js +12 -0
- package/src/tui-compiled/raw/shared/d7fa77560855dee2-jitter.js +9 -0
- package/src/tui-compiled/raw/shared/de7f7d8803624369-path.js +31 -0
- package/src/tui-compiled/raw/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
- package/src/tui-compiled/raw/shared/e26c2bb5722ab047-routing-hold.js +23 -0
- package/src/tui-compiled/raw/shared/e2ae081583adfce3-dump.js +80 -0
- package/src/tui-compiled/raw/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
- package/src/tui-compiled/raw/shared/e5229952fc12f647-codex-models.js +34 -0
- package/src/tui-compiled/raw/shared/e8fda84e90176436-uuid-v7.js +13 -0
- package/src/tui-compiled/raw/shared/ea56007991dbf068-terminal.js +19 -0
- package/src/tui-compiled/raw/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
- package/src/tui-compiled/raw/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
- package/src/tui-compiled/raw/shared/f1012265b3a768c7-merge-laws.js +31 -0
- package/src/tui-compiled/raw/shared/f2ca864fe967415a-cache-policy.js +198 -0
- package/src/tui-compiled/raw/shared/f317a4740f9d76f8-identity.js +21 -0
- package/src/tui-compiled/raw/shared/f607353c4126272a-routing-wait.js +19 -0
- package/src/tui-compiled/raw/shared/f6189f5c9aee31eb-decision.js +55 -0
- package/src/tui-compiled/raw/shared/f6d728f5e601f98b-request-history.js +120 -0
- package/src/tui-compiled/raw/shared/f981e6b15fb76cdb-codex-body.js +28 -0
- package/src/tui-compiled/raw/shared/fda579e5a0a54165-codex-effort.js +60 -0
- package/src/tui-compiled/raw/sidebar-state.js +54 -4
- package/src/tui-compiled/raw/tui/v2-dialog.js +1 -1
- package/src/tui-compiled/raw/tui.tsx +27 -5
- package/src/tui-compiled/runtime/shared/054118b2705fdc20-ansi.js +98 -0
- package/src/tui-compiled/runtime/shared/0895e780489c494d-window.js +33 -0
- package/src/tui-compiled/runtime/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
- package/src/tui-compiled/runtime/shared/0c9533222cb4380c-namespace.js +224 -0
- package/src/tui-compiled/runtime/shared/112607e46a5b5f58-accounts.js +393 -0
- package/src/tui-compiled/runtime/shared/136fa4abe48ad69d-cachekeep.js +411 -0
- package/src/tui-compiled/runtime/shared/1547bd74f4214d2d-index.js +28 -0
- package/src/tui-compiled/runtime/shared/1567207f323dc733-codex-http.js +44 -0
- package/src/tui-compiled/runtime/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
- package/src/tui-compiled/runtime/shared/18df43cab4563acf-families.js +149 -0
- package/src/tui-compiled/runtime/shared/1a4c289eec261e04-codex-instructions.js +59 -0
- package/src/tui-compiled/runtime/shared/1afd446e190ef85c-vault-messages.js +12 -0
- package/src/tui-compiled/runtime/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
- package/src/tui-compiled/runtime/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
- package/src/tui-compiled/runtime/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
- package/src/tui-compiled/runtime/shared/22b2bce42f2d6806-handle.js +10 -0
- package/src/tui-compiled/runtime/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
- package/src/tui-compiled/runtime/shared/26055d4e5ad5e71f-codex-request.js +198 -0
- package/src/tui-compiled/runtime/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
- package/src/tui-compiled/runtime/shared/2bb681e99c2721d7-registry.js +538 -0
- package/src/tui-compiled/runtime/shared/2dce6e9613993329-quota-manager.js +13 -20
- package/src/tui-compiled/runtime/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
- package/src/tui-compiled/runtime/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
- package/src/tui-compiled/runtime/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
- package/src/tui-compiled/runtime/shared/3b31b36bf0877602-wording.js +120 -0
- package/src/tui-compiled/runtime/shared/3c4c1a2d3fc92726-failure.js +59 -0
- package/src/tui-compiled/runtime/shared/3dfe71eec6e0487d-presets.js +240 -0
- package/src/tui-compiled/runtime/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
- package/src/tui-compiled/runtime/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
- package/src/tui-compiled/runtime/shared/4adf46e07e025363-axes.js +7 -0
- package/src/tui-compiled/runtime/shared/4ba847b77580b1eb-confirm.js +21 -0
- package/src/tui-compiled/runtime/shared/4d05c2d7a531aece-oauth.js +48 -36
- package/src/tui-compiled/runtime/shared/5018d4665e969588-limit-policy.js +159 -0
- package/src/tui-compiled/runtime/shared/595bdf3fff13ba79-limit-identity.js +49 -0
- package/src/tui-compiled/runtime/shared/59def9e82b61204a-session-cache-activity.js +35 -0
- package/src/tui-compiled/runtime/shared/5d806e1a305d14f5-commands.js +879 -0
- package/src/tui-compiled/runtime/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
- package/src/tui-compiled/runtime/shared/63c1ee7e70e85e8d-vault.js +1 -0
- package/src/tui-compiled/runtime/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
- package/src/tui-compiled/runtime/shared/66937534c260d20b-stable-json.js +11 -0
- package/src/tui-compiled/runtime/shared/7056acef1b021f19-bridge.js +10 -0
- package/src/tui-compiled/runtime/shared/72d2ca42883809b4-marker.js +107 -0
- package/src/tui-compiled/runtime/shared/775431e21f469203-record.js +3 -0
- package/src/tui-compiled/runtime/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
- package/src/tui-compiled/runtime/shared/7b2a0471b29e4f5e-wake.js +47 -0
- package/src/tui-compiled/runtime/shared/7b5d6afff4ff32b9-select.js +159 -0
- package/src/tui-compiled/runtime/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
- package/src/tui-compiled/runtime/shared/7c98bde36aad4819-input-transformations.js +34 -0
- package/src/tui-compiled/runtime/shared/7fb0418303f20a10-index.js +3 -0
- package/src/tui-compiled/runtime/shared/806e12ccbad34388-pi-wait.js +51 -0
- package/src/tui-compiled/runtime/shared/81ae201b724cac14-menu.js +73 -0
- package/src/tui-compiled/runtime/shared/8349ed25dc629e97-scope.js +10 -0
- package/src/tui-compiled/runtime/shared/86da3379973780b9-limit-provenance.js +60 -0
- package/src/tui-compiled/runtime/shared/8aba66ed486d30a7-decide.js +425 -0
- package/src/tui-compiled/runtime/shared/8c0c8df25a5dca1f-manager.js +735 -0
- package/src/tui-compiled/runtime/shared/8c42bbec02f59636-vault-routing.js +212 -0
- package/src/tui-compiled/runtime/shared/8ca6175bfae53e13-envelope.js +123 -0
- package/src/tui-compiled/runtime/shared/8d0245e41049d83f-header-classifier.js +121 -0
- package/src/tui-compiled/runtime/shared/9c162809179c7560-login.js +89 -0
- package/src/tui-compiled/runtime/shared/a1f495296a4b756f-frame-turn.js +72 -0
- package/src/tui-compiled/runtime/shared/a37138dcbd893f55-hold-bounds.js +5 -0
- package/src/tui-compiled/runtime/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
- package/src/tui-compiled/runtime/shared/adc5eeb5a8d28280-persistence.js +9 -0
- package/src/tui-compiled/runtime/shared/b301c79e6378d1fb-vault.js +678 -0
- package/src/tui-compiled/runtime/shared/b3c11de5f36e617a-reset.js +44 -0
- package/src/tui-compiled/runtime/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
- package/src/tui-compiled/runtime/shared/bd4aef685681048c-duration.js +20 -0
- package/src/tui-compiled/runtime/shared/bd5977eca210d2b8-index.js +662 -0
- package/src/tui-compiled/runtime/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
- package/src/tui-compiled/runtime/shared/c66495424ad84aee-hold.js +25 -0
- package/src/tui-compiled/runtime/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
- package/src/tui-compiled/runtime/shared/c9340fb545c4e5de-internal.js +73 -0
- package/src/tui-compiled/runtime/shared/c954c6447b7b9b64-activity.js +52 -0
- package/src/tui-compiled/runtime/shared/cba8b0aee46b8526-codex-lite.js +85 -0
- package/src/tui-compiled/runtime/shared/cec39ccddab4fe9c-labels.js +11 -0
- package/src/tui-compiled/runtime/shared/cef0f2346957e83c-index.js +552 -0
- package/src/tui-compiled/runtime/shared/cf7dedf24f902d68-dump-size.js +41 -0
- package/src/tui-compiled/runtime/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
- package/src/tui-compiled/runtime/shared/d5b268767d330507-doctor.js +81 -0
- package/src/tui-compiled/runtime/shared/d7ac5ca41f49121b-index.js +12 -0
- package/src/tui-compiled/runtime/shared/d7fa77560855dee2-jitter.js +9 -0
- package/src/tui-compiled/runtime/shared/de7f7d8803624369-path.js +31 -0
- package/src/tui-compiled/runtime/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
- package/src/tui-compiled/runtime/shared/e26c2bb5722ab047-routing-hold.js +23 -0
- package/src/tui-compiled/runtime/shared/e2ae081583adfce3-dump.js +80 -0
- package/src/tui-compiled/runtime/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
- package/src/tui-compiled/runtime/shared/e5229952fc12f647-codex-models.js +34 -0
- package/src/tui-compiled/runtime/shared/e8fda84e90176436-uuid-v7.js +13 -0
- package/src/tui-compiled/runtime/shared/ea56007991dbf068-terminal.js +19 -0
- package/src/tui-compiled/runtime/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
- package/src/tui-compiled/runtime/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
- package/src/tui-compiled/runtime/shared/f1012265b3a768c7-merge-laws.js +31 -0
- package/src/tui-compiled/runtime/shared/f2ca864fe967415a-cache-policy.js +198 -0
- package/src/tui-compiled/runtime/shared/f317a4740f9d76f8-identity.js +21 -0
- package/src/tui-compiled/runtime/shared/f607353c4126272a-routing-wait.js +19 -0
- package/src/tui-compiled/runtime/shared/f6189f5c9aee31eb-decision.js +55 -0
- package/src/tui-compiled/runtime/shared/f6d728f5e601f98b-request-history.js +120 -0
- package/src/tui-compiled/runtime/shared/f981e6b15fb76cdb-codex-body.js +28 -0
- package/src/tui-compiled/runtime/shared/fda579e5a0a54165-codex-effort.js +60 -0
- package/src/tui-compiled/runtime/sidebar-state.js +54 -4
- package/src/tui-compiled/runtime/tui/v2-dialog.js +1 -1
- package/src/tui-compiled/runtime/tui.js +11 -4
- package/dist/index-0p8r7cpy.js +0 -60
- package/dist/index-px1t650b.js +0 -2
- package/dist/map-D5PHhv4z.d.ts +0 -72
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { validateIdentityFence } from "./f317a4740f9d76f8-identity.js";
|
|
2
|
+
import { mergeAccessState, mergeTimedMarkEntries } from "./f1012265b3a768c7-merge-laws.js";
|
|
3
|
+
import { sameAccount } from "./f6d728f5e601f98b-request-history.js";
|
|
4
|
+
export const LIMITS_HISTORY_BOUND = 1024;
|
|
5
|
+
function storedCause(cause) {
|
|
6
|
+
return cause === 'rate-limit' || cause === 'payment-balance'
|
|
7
|
+
? cause
|
|
8
|
+
: undefined;
|
|
9
|
+
}
|
|
10
|
+
/** An absent cause is the conservative all-cause fence used by older writers. */
|
|
11
|
+
export function tombstoneCoversCause(clear, cause) {
|
|
12
|
+
return storedCause(clear.cause) === undefined || clear.cause === cause;
|
|
13
|
+
}
|
|
14
|
+
export function clearTombstoneId(clear) {
|
|
15
|
+
return JSON.stringify([timedMarkKeyId(clear.key), storedCause(clear.cause)]);
|
|
16
|
+
}
|
|
17
|
+
export function createLimitsNamespace(namespace, generation) {
|
|
18
|
+
return {
|
|
19
|
+
schemaVersion: 1,
|
|
20
|
+
namespace,
|
|
21
|
+
generation,
|
|
22
|
+
revision: 0,
|
|
23
|
+
lowWatermark: 0,
|
|
24
|
+
marks: [],
|
|
25
|
+
tombstones: [],
|
|
26
|
+
operationIds: [],
|
|
27
|
+
access: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function accountId(account) {
|
|
31
|
+
return JSON.stringify([
|
|
32
|
+
account.namespace,
|
|
33
|
+
account.accountId,
|
|
34
|
+
account.incarnation,
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
export function timedMarkKeyId(key) {
|
|
38
|
+
const scope = key.scope;
|
|
39
|
+
return JSON.stringify([
|
|
40
|
+
accountId(key.account),
|
|
41
|
+
scope.kind,
|
|
42
|
+
scope.kind === 'model'
|
|
43
|
+
? scope.model
|
|
44
|
+
: scope.kind === 'family'
|
|
45
|
+
? scope.family
|
|
46
|
+
: null,
|
|
47
|
+
key.window,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
function operationId(op) {
|
|
51
|
+
return JSON.stringify([op.producerId, op.operationId]);
|
|
52
|
+
}
|
|
53
|
+
/** Apply tombstones before compacting them; the watermark then fences delayed commands. */
|
|
54
|
+
export function pruneLimitsNamespace(snapshot, now) {
|
|
55
|
+
const clears = new Map();
|
|
56
|
+
for (const clear of snapshot.tombstones) {
|
|
57
|
+
const id = timedMarkKeyId(clear.key);
|
|
58
|
+
const list = clears.get(id);
|
|
59
|
+
if (list)
|
|
60
|
+
list.push(clear);
|
|
61
|
+
else
|
|
62
|
+
clears.set(id, [clear]);
|
|
63
|
+
}
|
|
64
|
+
const marks = snapshot.marks.flatMap((mark) => {
|
|
65
|
+
const fences = clears.get(timedMarkKeyId(mark.key));
|
|
66
|
+
const entries = mergeTimedMarkEntries(mark.mergeLaw, fences
|
|
67
|
+
? mark.entries.filter((entry) => !fences.some((clear) => tombstoneCoversCause(clear, entry.cause) &&
|
|
68
|
+
entry.baseRevision < clear.revision))
|
|
69
|
+
: mark.entries, now);
|
|
70
|
+
return entries.length ? [{ ...mark, entries }] : [];
|
|
71
|
+
});
|
|
72
|
+
let lowWatermark = snapshot.lowWatermark;
|
|
73
|
+
const compact = (entries) => {
|
|
74
|
+
const ordered = [...entries].sort((a, b) => a.revision - b.revision);
|
|
75
|
+
const count = Math.max(0, ordered.length - LIMITS_HISTORY_BOUND);
|
|
76
|
+
for (const entry of ordered.slice(0, count)) {
|
|
77
|
+
lowWatermark = Math.max(lowWatermark, entry.revision + 1);
|
|
78
|
+
}
|
|
79
|
+
return ordered.slice(count);
|
|
80
|
+
};
|
|
81
|
+
const tombstones = compact(snapshot.tombstones);
|
|
82
|
+
const operationIds = compact(snapshot.operationIds);
|
|
83
|
+
return {
|
|
84
|
+
...snapshot,
|
|
85
|
+
revision: Math.max(snapshot.revision, lowWatermark),
|
|
86
|
+
marks,
|
|
87
|
+
tombstones,
|
|
88
|
+
operationIds,
|
|
89
|
+
lowWatermark,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Pure transaction body; load namespace state and identity bindings under one lock. */
|
|
93
|
+
export function applyLimitsCommands(initial, commands, context) {
|
|
94
|
+
let snapshot = pruneLimitsNamespace(initial, context.now);
|
|
95
|
+
const outcomes = [];
|
|
96
|
+
for (const command of commands) {
|
|
97
|
+
const reject = (reason) => {
|
|
98
|
+
outcomes.push({
|
|
99
|
+
producerId: command.producerId,
|
|
100
|
+
operationId: command.operationId,
|
|
101
|
+
status: 'rejected',
|
|
102
|
+
reason,
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
if (command.binding.account.namespace !== snapshot.namespace) {
|
|
106
|
+
reject('wrong-namespace');
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (command.baseRevision < snapshot.lowWatermark) {
|
|
110
|
+
reject('below-watermark');
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (command.baseRevision > snapshot.revision) {
|
|
114
|
+
reject('future-revision');
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const authoritative = context.bindings.find((b) => sameAccount(b.account, command.binding.account));
|
|
118
|
+
if (!authoritative) {
|
|
119
|
+
reject('unknown-account');
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const fence = validateIdentityFence(command.binding, authoritative, context.authorizeEpoch);
|
|
123
|
+
if (fence) {
|
|
124
|
+
reject(fence);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const duplicate = snapshot.operationIds.find((op) => operationId(op) === operationId(command));
|
|
128
|
+
if (duplicate) {
|
|
129
|
+
outcomes.push({ ...duplicate, status: 'duplicate' });
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const account = authoritative.account;
|
|
133
|
+
const revision = snapshot.revision + 1;
|
|
134
|
+
let marks = [...snapshot.marks];
|
|
135
|
+
let tombstones = [...snapshot.tombstones];
|
|
136
|
+
let access = [...snapshot.access];
|
|
137
|
+
if (command.type === 'mark') {
|
|
138
|
+
const key = { account, scope: command.scope, window: command.window };
|
|
139
|
+
const id = timedMarkKeyId(key);
|
|
140
|
+
const previous = marks.find((m) => timedMarkKeyId(m.key) === id);
|
|
141
|
+
if (tombstones.some((clear) => command.baseRevision < clear.revision &&
|
|
142
|
+
tombstoneCoversCause(clear, command.cause) &&
|
|
143
|
+
timedMarkKeyId(clear.key) === id)) {
|
|
144
|
+
reject('cleared');
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (previous && previous.mergeLaw !== command.mergeLaw) {
|
|
148
|
+
reject('merge-law-conflict');
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const entries = mergeTimedMarkEntries(command.mergeLaw, [
|
|
152
|
+
...(previous?.entries ?? []),
|
|
153
|
+
{
|
|
154
|
+
until: command.until,
|
|
155
|
+
evidenceAt: command.evidenceAt,
|
|
156
|
+
baseRevision: command.baseRevision,
|
|
157
|
+
committedRevision: revision,
|
|
158
|
+
...(command.cause === 'rate-limit' ||
|
|
159
|
+
command.cause === 'payment-balance'
|
|
160
|
+
? { cause: command.cause }
|
|
161
|
+
: {}),
|
|
162
|
+
},
|
|
163
|
+
], context.now);
|
|
164
|
+
marks = marks.filter((m) => timedMarkKeyId(m.key) !== id);
|
|
165
|
+
if (entries.length)
|
|
166
|
+
marks.push({ key, mergeLaw: command.mergeLaw, entries });
|
|
167
|
+
}
|
|
168
|
+
else if (command.type === 'clear') {
|
|
169
|
+
const cause = storedCause(command.cause);
|
|
170
|
+
const keys = command.keys
|
|
171
|
+
.map((key) => ({ ...key, account }))
|
|
172
|
+
.filter((key) => command.cause === undefined ||
|
|
173
|
+
!marks.some((mark) => timedMarkKeyId(mark.key) === timedMarkKeyId(key) &&
|
|
174
|
+
mark.entries.some((entry) => entry.cause !== command.cause)));
|
|
175
|
+
const ids = new Set(keys.map(timedMarkKeyId));
|
|
176
|
+
const evidenceAt = command.evidenceAt;
|
|
177
|
+
if (evidenceAt !== undefined &&
|
|
178
|
+
marks.some((m) => ids.has(timedMarkKeyId(m.key)) &&
|
|
179
|
+
m.entries.some((e) => e.evidenceAt > evidenceAt))) {
|
|
180
|
+
reject('newer-evidence');
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
marks = marks.filter((m) => !ids.has(timedMarkKeyId(m.key)));
|
|
184
|
+
// Keep earlier fences for other causes, including an earlier all-cause clear.
|
|
185
|
+
// Replacing them would either lose a fence or extend it to unrelated evidence.
|
|
186
|
+
tombstones = tombstones.filter((t) => !ids.has(timedMarkKeyId(t.key)) ||
|
|
187
|
+
(cause !== undefined && t.cause !== cause));
|
|
188
|
+
// A clear enumerates covered keys, not all scopes on the account.
|
|
189
|
+
for (const key of new Map(keys.map((k) => [timedMarkKeyId(k), k])).values()) {
|
|
190
|
+
tombstones.push({
|
|
191
|
+
key,
|
|
192
|
+
revision,
|
|
193
|
+
...(cause === undefined ? {} : { cause }),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const incoming = {
|
|
199
|
+
account,
|
|
200
|
+
state: command.state,
|
|
201
|
+
eligibilityStateUpdatedAt: command.eligibilityStateUpdatedAt,
|
|
202
|
+
committedRevision: revision,
|
|
203
|
+
};
|
|
204
|
+
const previous = access.find((a) => sameAccount(a.account, account));
|
|
205
|
+
access = access.filter((a) => !sameAccount(a.account, account));
|
|
206
|
+
access.push(previous ? mergeAccessState(previous, incoming) : incoming);
|
|
207
|
+
}
|
|
208
|
+
const op = {
|
|
209
|
+
producerId: command.producerId,
|
|
210
|
+
operationId: command.operationId,
|
|
211
|
+
revision,
|
|
212
|
+
};
|
|
213
|
+
snapshot = pruneLimitsNamespace({
|
|
214
|
+
...snapshot,
|
|
215
|
+
revision,
|
|
216
|
+
marks,
|
|
217
|
+
tombstones,
|
|
218
|
+
access,
|
|
219
|
+
operationIds: [...snapshot.operationIds, op],
|
|
220
|
+
}, context.now);
|
|
221
|
+
outcomes.push({ ...op, status: 'committed' });
|
|
222
|
+
}
|
|
223
|
+
return { snapshot, outcomes };
|
|
224
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { hasVaultHost, VAULT_HOST_STATUS } from "./c97089ed4243981c-host.js";
|
|
2
|
+
import { formatQuota, isQuotaMap, projectQuota, quotaTextParts, } from "./d5a8f1061ee2f114-index.js";
|
|
3
|
+
import { PoolOperationError, } from "./54eba94fd64c8c3c-index.js";
|
|
4
|
+
import { doctorAction } from "./d5b268767d330507-doctor.js";
|
|
5
|
+
import { runMenuLogin } from "./9c162809179c7560-login.js";
|
|
6
|
+
import { runMenu, } from "./81ae201b724cac14-menu.js";
|
|
7
|
+
/** The reason recorded on a row the menu disables. */
|
|
8
|
+
export const MENU_DISABLE_REASON = 'disabled from the auth menu';
|
|
9
|
+
/** At most this many account lines are shown above the actions. */
|
|
10
|
+
const STATUS_ACCOUNT_LINES = 8;
|
|
11
|
+
async function readRows(store) {
|
|
12
|
+
const load = await store.read();
|
|
13
|
+
if (load.status === 'ready')
|
|
14
|
+
return { rows: load.rows };
|
|
15
|
+
if (load.status === 'pending-migration')
|
|
16
|
+
return { rows: [], problem: 'The account store has not been migrated yet.' };
|
|
17
|
+
return {
|
|
18
|
+
rows: [],
|
|
19
|
+
problem: `The account store could not be read (${load.file}: ${load.reason}).`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether the store holds any usable credential. Meant as one half of an
|
|
24
|
+
* `hasCredential` predicate (the other being the host's own slot); a row with
|
|
25
|
+
* no credential does not count, since it gives the menu nothing to manage.
|
|
26
|
+
*/
|
|
27
|
+
export async function poolHasCredential(store) {
|
|
28
|
+
const { rows } = await readRows(store);
|
|
29
|
+
return rows.some((row) => row.credential !== undefined);
|
|
30
|
+
}
|
|
31
|
+
function describeRow(row) {
|
|
32
|
+
const parts = [];
|
|
33
|
+
if (row.label)
|
|
34
|
+
parts.push(row.label);
|
|
35
|
+
if (row.invalid)
|
|
36
|
+
parts.push(`invalid ${row.invalid}`);
|
|
37
|
+
else if (!row.enabled)
|
|
38
|
+
parts.push(row.disabledReason ? `disabled: ${row.disabledReason}` : 'disabled');
|
|
39
|
+
else
|
|
40
|
+
parts.push('enabled');
|
|
41
|
+
if (!row.credential && !row.invalid)
|
|
42
|
+
parts.push('no credential');
|
|
43
|
+
return parts.join(', ');
|
|
44
|
+
}
|
|
45
|
+
function accountLines(read) {
|
|
46
|
+
if (read.problem)
|
|
47
|
+
return [read.problem];
|
|
48
|
+
if (read.rows.length === 0)
|
|
49
|
+
return ['No accounts yet.'];
|
|
50
|
+
const lines = read.rows
|
|
51
|
+
.slice(0, STATUS_ACCOUNT_LINES)
|
|
52
|
+
.map((row) => `${row.id}: ${describeRow(row)}`);
|
|
53
|
+
const more = read.rows.length - STATUS_ACCOUNT_LINES;
|
|
54
|
+
if (more > 0)
|
|
55
|
+
lines.push(`... and ${more} more`);
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
58
|
+
function errorText(error) {
|
|
59
|
+
return error instanceof Error ? error.message : String(error);
|
|
60
|
+
}
|
|
61
|
+
async function pickAccount(context, rows, message) {
|
|
62
|
+
if (rows.length === 0) {
|
|
63
|
+
context.print('There are no accounts.');
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return context.select(rows.map((row) => ({ label: row.id, value: row, hint: describeRow(row) })), { message });
|
|
67
|
+
}
|
|
68
|
+
function defaultAccountId(account, rows) {
|
|
69
|
+
const taken = new Set(rows.map((row) => row.id));
|
|
70
|
+
if (account.id && !taken.has(account.id))
|
|
71
|
+
return account.id;
|
|
72
|
+
for (let n = 1;; n++) {
|
|
73
|
+
const id = `account-${n}`;
|
|
74
|
+
if (!taken.has(id))
|
|
75
|
+
return id;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Formats a row's stored quota map as one line per window, in the shared
|
|
80
|
+
* quota wording (`5h 58% left, resets 2h`; see `formatQuota` in `/quota`).
|
|
81
|
+
* `now` is the current time in ms and defaults to the clock.
|
|
82
|
+
*/
|
|
83
|
+
export function quotaLines(row, now = Date.now()) {
|
|
84
|
+
const projected = isQuotaMap(row.quota) ? projectQuota(row.quota) : undefined;
|
|
85
|
+
const parts = quotaTextParts(projected, { now, form: 'full' });
|
|
86
|
+
// With nothing to list, the line is the shared formatter's own sentence.
|
|
87
|
+
return (parts.length > 0 ? parts : [formatQuota(projected, { now })]).map((line) => ` ${line}`);
|
|
88
|
+
}
|
|
89
|
+
/** Adds an account through the plugin's login and reports what the store did. */
|
|
90
|
+
export function addAccountAction(options) {
|
|
91
|
+
return {
|
|
92
|
+
id: 'add-account',
|
|
93
|
+
label: 'Add account',
|
|
94
|
+
hint: 'sign in to another account',
|
|
95
|
+
async run(context) {
|
|
96
|
+
const login = options.login;
|
|
97
|
+
if (!login)
|
|
98
|
+
throw new Error('No login is configured');
|
|
99
|
+
const account = await runMenuLogin(login, context);
|
|
100
|
+
const { rows } = await readRows(options.store);
|
|
101
|
+
const id = (options.newAccountId ?? defaultAccountId)(account, rows);
|
|
102
|
+
const added = await options.store.add({
|
|
103
|
+
id,
|
|
104
|
+
credential: account.credential,
|
|
105
|
+
...(account.identity !== undefined
|
|
106
|
+
? { identity: account.identity }
|
|
107
|
+
: {}),
|
|
108
|
+
...(account.label !== undefined ? { label: account.label } : {}),
|
|
109
|
+
}, options.extraLocks ? { extraLocks: options.extraLocks } : {});
|
|
110
|
+
if (added.outcome === 'rotated')
|
|
111
|
+
context.print(`That sign-in is already account ${added.id}; its credential was updated.`);
|
|
112
|
+
else if (added.outcome === 'added-disabled')
|
|
113
|
+
context.print(`Added account ${added.id}, disabled: another enabled account is the same provider account.`);
|
|
114
|
+
else if (added.outcome === 'completed')
|
|
115
|
+
context.print(`Finished adding account ${added.id}.`);
|
|
116
|
+
else
|
|
117
|
+
context.print(`Added account ${added.id}.`);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Signs an existing account in again and replaces its credential. A login
|
|
123
|
+
* that comes back as a different provider account is refused: replacing
|
|
124
|
+
* would silently turn the row into another account.
|
|
125
|
+
*/
|
|
126
|
+
export function reauthenticateAction(options) {
|
|
127
|
+
return {
|
|
128
|
+
id: 'reauthenticate',
|
|
129
|
+
label: 'Re-authenticate account',
|
|
130
|
+
hint: 'sign an account in again',
|
|
131
|
+
async run(context) {
|
|
132
|
+
const login = options.login;
|
|
133
|
+
if (!login)
|
|
134
|
+
throw new Error('No login is configured');
|
|
135
|
+
const { rows } = await readRows(options.store);
|
|
136
|
+
const row = await pickAccount(context, rows, 'Re-authenticate which account?');
|
|
137
|
+
if (!row)
|
|
138
|
+
return;
|
|
139
|
+
const account = await runMenuLogin(login, context);
|
|
140
|
+
if (account.identity !== undefined &&
|
|
141
|
+
row.identity !== undefined &&
|
|
142
|
+
account.identity !== row.identity) {
|
|
143
|
+
context.print(`That sign-in is a different account from ${row.id}; nothing was changed. Use Add account to add it.`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const identity = account.identity ?? row.identity;
|
|
147
|
+
await options.store.replace(row.id, account.credential, identity !== undefined ? { identity } : {}, options.extraLocks ? { extraLocks: options.extraLocks } : {});
|
|
148
|
+
context.print(`Updated the sign-in of account ${row.id}.`);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function removeOptions(options) {
|
|
153
|
+
return {
|
|
154
|
+
...(options.protect ? { protect: options.protect } : {}),
|
|
155
|
+
...(options.extraLocks ? { extraLocks: options.extraLocks } : {}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function protectedReason(error) {
|
|
159
|
+
return error instanceof PoolOperationError && error.kind === 'row-protected'
|
|
160
|
+
? error.message
|
|
161
|
+
: undefined;
|
|
162
|
+
}
|
|
163
|
+
/** Removes one account after the operator confirms it by name. */
|
|
164
|
+
export function removeAccountAction(options) {
|
|
165
|
+
return {
|
|
166
|
+
id: 'remove-account',
|
|
167
|
+
label: 'Remove account',
|
|
168
|
+
hint: 'delete one account',
|
|
169
|
+
async run(context) {
|
|
170
|
+
const { rows } = await readRows(options.store);
|
|
171
|
+
const row = await pickAccount(context, rows, 'Remove which account?');
|
|
172
|
+
if (!row)
|
|
173
|
+
return;
|
|
174
|
+
if (!(await context.confirm(`Remove account ${row.id}?`))) {
|
|
175
|
+
context.print('Cancelled; nothing was changed.');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
await options.store.remove(row.id, removeOptions(options));
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
const reason = protectedReason(error);
|
|
183
|
+
if (reason === undefined)
|
|
184
|
+
throw error;
|
|
185
|
+
context.print(`Account ${row.id} was kept: ${reason}`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
context.print(`Removed account ${row.id}.`);
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** Disables an enabled account, or enables a disabled one. */
|
|
193
|
+
export function toggleAccountAction(options) {
|
|
194
|
+
return {
|
|
195
|
+
id: 'toggle-account',
|
|
196
|
+
label: 'Enable or disable account',
|
|
197
|
+
hint: 'stop or resume using an account',
|
|
198
|
+
async run(context) {
|
|
199
|
+
const { rows } = await readRows(options.store);
|
|
200
|
+
const row = await pickAccount(context, rows, 'Enable or disable which account?');
|
|
201
|
+
if (!row)
|
|
202
|
+
return;
|
|
203
|
+
const toggle = options.extraLocks
|
|
204
|
+
? { extraLocks: options.extraLocks }
|
|
205
|
+
: {};
|
|
206
|
+
if (row.enabled) {
|
|
207
|
+
await options.store.disable(row.id, options.disableReason ?? MENU_DISABLE_REASON, toggle);
|
|
208
|
+
context.print(`Disabled account ${row.id}.`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
await options.store.enable(row.id, toggle);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (error instanceof PoolOperationError &&
|
|
216
|
+
error.kind === 'duplicate-identity') {
|
|
217
|
+
context.print(`Account ${row.id} stays disabled: another enabled account is the same provider account.`);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
context.print(`Enabled account ${row.id}.`);
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/** Prints every account and its state, changing nothing. */
|
|
227
|
+
export function listAccountsAction(options) {
|
|
228
|
+
return {
|
|
229
|
+
id: 'list-accounts',
|
|
230
|
+
label: 'List accounts',
|
|
231
|
+
hint: 'show every account',
|
|
232
|
+
async run(context) {
|
|
233
|
+
const read = await readRows(options.store);
|
|
234
|
+
if (read.problem) {
|
|
235
|
+
context.print(read.problem);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (read.rows.length === 0)
|
|
239
|
+
context.print('No accounts yet.');
|
|
240
|
+
for (const row of read.rows)
|
|
241
|
+
context.print(`${row.id}: ${describeRow(row)}`);
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Polls each account's quota once, in order, records each reading through
|
|
247
|
+
* the store (so it lands only on the credential it was taken with), then
|
|
248
|
+
* prints every account's windows from what is stored.
|
|
249
|
+
*/
|
|
250
|
+
export function checkQuotasAction(options) {
|
|
251
|
+
return {
|
|
252
|
+
id: 'check-quotas',
|
|
253
|
+
label: 'Check quotas',
|
|
254
|
+
hint: 'poll and show the windows of each account',
|
|
255
|
+
async run(context) {
|
|
256
|
+
const before = await readRows(options.store);
|
|
257
|
+
if (before.problem) {
|
|
258
|
+
context.print(before.problem);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const errors = new Map();
|
|
262
|
+
const poll = options.pollQuota;
|
|
263
|
+
if (poll) {
|
|
264
|
+
for (const row of before.rows) {
|
|
265
|
+
if (row.invalid ||
|
|
266
|
+
!row.credential ||
|
|
267
|
+
row.credentialEpoch === undefined) {
|
|
268
|
+
errors.set(row.id, 'no usable credential');
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const observation = await poll(row);
|
|
273
|
+
await options.store.recordQuota(row.id, {
|
|
274
|
+
credentialEpoch: row.credentialEpoch,
|
|
275
|
+
...(row.identity !== undefined
|
|
276
|
+
? { identity: row.identity }
|
|
277
|
+
: {}),
|
|
278
|
+
}, observation);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
errors.set(row.id, errorText(error));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const after = await readRows(options.store);
|
|
286
|
+
if (after.rows.length === 0)
|
|
287
|
+
context.print('No accounts yet.');
|
|
288
|
+
for (const row of after.rows) {
|
|
289
|
+
context.print(`${row.id}:`);
|
|
290
|
+
const error = errors.get(row.id);
|
|
291
|
+
if (error)
|
|
292
|
+
context.print(` quota check failed: ${error}`);
|
|
293
|
+
for (const line of quotaLines(row, (options.now ?? Date.now)()))
|
|
294
|
+
context.print(line);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Removes every account the plugin does not protect. Each removal goes
|
|
301
|
+
* through `store.remove` with the plugin's `protect`, so a protected id is
|
|
302
|
+
* refused under the store's locks and stays, with its files untouched.
|
|
303
|
+
*/
|
|
304
|
+
export function deleteAllAction(options) {
|
|
305
|
+
return {
|
|
306
|
+
id: 'delete-all',
|
|
307
|
+
label: 'Delete all accounts',
|
|
308
|
+
destructive: true,
|
|
309
|
+
confirm: 'Delete every account? Accounts the plugin keeps are not deleted.',
|
|
310
|
+
async run(context) {
|
|
311
|
+
const read = await readRows(options.store);
|
|
312
|
+
if (read.problem) {
|
|
313
|
+
context.print(read.problem);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const removed = [];
|
|
317
|
+
const kept = [];
|
|
318
|
+
for (const row of read.rows) {
|
|
319
|
+
try {
|
|
320
|
+
await options.store.remove(row.id, removeOptions(options));
|
|
321
|
+
removed.push(row.id);
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
const reason = protectedReason(error);
|
|
325
|
+
if (reason === undefined)
|
|
326
|
+
throw error;
|
|
327
|
+
kept.push(`${row.id} (${reason})`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
context.print(`Deleted ${removed.length} account(s).`);
|
|
331
|
+
if (kept.length > 0)
|
|
332
|
+
context.print(`Kept: ${kept.join(', ')}.`);
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* The menu's actions for this plugin and mode. Local mode: add,
|
|
338
|
+
* re-authenticate, remove, enable/disable, check quotas, doctor, the
|
|
339
|
+
* plugin's extras, delete all. Custody mode: list, enable/disable, check
|
|
340
|
+
* quotas, doctor and the extras; nothing that adds, signs in or removes.
|
|
341
|
+
*/
|
|
342
|
+
export async function accountMenuActions(options) {
|
|
343
|
+
return actionsFor(options, hasVaultHost() || (await options.custody?.()) === true);
|
|
344
|
+
}
|
|
345
|
+
function actionsFor(options, custody) {
|
|
346
|
+
const doctor = options.doctor?.length
|
|
347
|
+
? [doctorAction({ checks: options.doctor })]
|
|
348
|
+
: [];
|
|
349
|
+
const extras = [...(options.extraActions ?? [])];
|
|
350
|
+
if (custody) {
|
|
351
|
+
return [
|
|
352
|
+
listAccountsAction(options),
|
|
353
|
+
toggleAccountAction(options),
|
|
354
|
+
checkQuotasAction(options),
|
|
355
|
+
...doctor,
|
|
356
|
+
...extras,
|
|
357
|
+
];
|
|
358
|
+
}
|
|
359
|
+
return [
|
|
360
|
+
...(options.login
|
|
361
|
+
? [addAccountAction(options), reauthenticateAction(options)]
|
|
362
|
+
: []),
|
|
363
|
+
removeAccountAction(options),
|
|
364
|
+
toggleAccountAction(options),
|
|
365
|
+
checkQuotasAction(options),
|
|
366
|
+
...doctor,
|
|
367
|
+
...extras,
|
|
368
|
+
deleteAllAction(options),
|
|
369
|
+
];
|
|
370
|
+
}
|
|
371
|
+
/** Shows the account menu once and runs the chosen action. */
|
|
372
|
+
export async function runAccountMenu(options) {
|
|
373
|
+
const hosted = hasVaultHost();
|
|
374
|
+
const custody = hosted || (await options.custody?.()) === true;
|
|
375
|
+
const actions = actionsFor(options, custody);
|
|
376
|
+
const [read, status] = await Promise.all([
|
|
377
|
+
readRows(options.store),
|
|
378
|
+
options.status?.() ?? [],
|
|
379
|
+
]);
|
|
380
|
+
return runMenu({
|
|
381
|
+
title: options.title,
|
|
382
|
+
subtitle: custody
|
|
383
|
+
? 'Accounts come from the vault; select an action'
|
|
384
|
+
: 'Select an account action',
|
|
385
|
+
status: [
|
|
386
|
+
...status,
|
|
387
|
+
...(hosted ? [VAULT_HOST_STATUS] : []),
|
|
388
|
+
...accountLines(read),
|
|
389
|
+
],
|
|
390
|
+
actions,
|
|
391
|
+
...(options.terminal ? { terminal: options.terminal } : {}),
|
|
392
|
+
});
|
|
393
|
+
}
|