gloomberb 0.19.4 → 0.19.6
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/package.json +3 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
- package/src/api-client/equity-screener.ts +23 -0
- package/src/app/pane-runtime/index.tsx +2 -0
- package/src/app/pane-runtime/plugin-bindings.ts +10 -1
- package/src/app.tsx +63 -16
- package/src/cli/commands/command-utils.ts +4 -0
- package/src/cli/commands/market.ts +264 -33
- package/src/cli/commands/search.ts +22 -4
- package/src/cli/commands/ticker.ts +84 -39
- package/src/cli/currency-name-hint.ts +60 -0
- package/src/cli/glossary.ts +3 -3
- package/src/cli/history-rows.ts +18 -1
- package/src/cli/known-gaps.ts +25 -2
- package/src/cli/listing-arg.ts +12 -0
- package/src/cli/not-a-ticker.ts +5 -3
- package/src/cli/pane-functions/capabilities.ts +2 -0
- package/src/cli/pane-functions/catalog.ts +31 -5
- package/src/cli/pane-functions/function-help.ts +8 -5
- package/src/cli/pane-functions/headless.ts +11 -6
- package/src/cli/pane-functions/market-session.ts +6 -7
- package/src/cli/pane-functions/resolver.ts +75 -2
- package/src/cli/quote-answer.ts +9 -0
- package/src/cli/series-search.ts +4 -5
- package/src/cli/symbol-list.ts +54 -2
- package/src/cli/symbol-rows.ts +14 -2
- package/src/cli/ticker-resolution.ts +89 -20
- package/src/components/chart/composite/axis-overlays.tsx +60 -27
- package/src/components/chart/composite/composite-chart.tsx +118 -63
- package/src/components/chart/composite/cursor-source.ts +111 -0
- package/src/components/chart/composite/format.ts +168 -6
- package/src/components/chart/composite/legend.tsx +8 -4
- package/src/components/chart/composite/panel-bitmap.ts +28 -2
- package/src/components/chart/composite/panel-labels.ts +20 -1
- package/src/components/chart/composite/panel-surface.tsx +201 -92
- package/src/components/chart/composite/price-axis-labels.tsx +92 -46
- package/src/components/chart/composite/price-series.ts +31 -8
- package/src/components/chart/composite/scene.ts +154 -59
- package/src/components/chart/composite/series-axis-tags.tsx +4 -2
- package/src/components/chart/composite/time-axis.ts +30 -7
- package/src/components/chart/composite/time-scale.ts +211 -56
- package/src/components/chart/composite/types.ts +11 -1
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
- package/src/components/chart/curve/curve-surface.tsx +5 -2
- package/src/components/chart/curve/model.ts +4 -1
- package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
- package/src/components/chart/static/series.ts +3 -0
- package/src/components/command-bar/commands/collection-list.ts +81 -0
- package/src/components/command-bar/commands/direct/index.ts +6 -0
- package/src/components/command-bar/commands/registry.ts +8 -0
- package/src/components/command-bar/layout-items/current-layout.ts +22 -1
- package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
- package/src/components/command-bar/pane-templates/items.ts +19 -3
- package/src/components/command-bar/pane-templates/workflow.ts +5 -0
- package/src/components/command-bar/routes/root/results.ts +23 -3
- package/src/components/command-bar/routes/root/selection.ts +4 -2
- package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
- package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
- package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
- package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
- package/src/components/command-bar/surface/environment.ts +2 -0
- package/src/components/command-bar/view-model.ts +7 -0
- package/src/components/command-bar/workflow/ops.ts +2 -1
- package/src/components/command-bar/workflow/tickers.ts +20 -0
- package/src/components/layout/shell/active-drag.ts +38 -7
- package/src/components/layout/shell/drag/magnets.ts +106 -0
- package/src/components/layout/shell/menu.ts +15 -1
- package/src/components/layout/shell/pane/actions.ts +4 -0
- package/src/components/layout/shell/ticker-link-menu.ts +12 -3
- package/src/components/layout/status-bar.tsx +20 -0
- package/src/components/layout/window-controls.tsx +96 -35
- package/src/components/layout/window-fullscreen.ts +20 -0
- package/src/components/onboarding/onboarding-keyboard.ts +5 -1
- package/src/components/onboarding/onboarding-wizard.tsx +15 -4
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
- package/src/components/onboarding/use-onboarding-progress.ts +20 -1
- package/src/components/price-sparkline/view.tsx +14 -6
- package/src/components/quote-flash.ts +36 -32
- package/src/components/ticker/badge/index.tsx +8 -4
- package/src/components/ticker/badge/list.tsx +23 -7
- package/src/components/ui/column-grid.tsx +8 -2
- package/src/components/ui/data-table/opentui/model.ts +4 -1
- package/src/components/ui/tabs.tsx +5 -2
- package/src/core/state/app/layout.ts +18 -3
- package/src/core/state/app/state.ts +2 -0
- package/src/core/state/app/types.ts +5 -0
- package/src/data/config/layout.ts +3 -0
- package/src/data/config/store/normalize.ts +39 -4
- package/src/i18n/es.ts +10 -0
- package/src/i18n/ja.ts +10 -0
- package/src/i18n/ko.ts +10 -0
- package/src/i18n/zh-cn.ts +10 -0
- package/src/i18n/zh-tw.ts +10 -0
- package/src/layout/pane-manager/floating-placement.ts +7 -4
- package/src/layout/pane-manager/floating.ts +5 -2
- package/src/market-data/bond-funds.ts +19 -0
- package/src/market-data/coordinator/events.ts +17 -1
- package/src/market-data/frame-scheduler.ts +47 -10
- package/src/market-data/frame-wake.ts +74 -0
- package/src/market-data/futures-board.ts +7 -6
- package/src/market-data/futures-contract.ts +14 -3
- package/src/market-data/hooks.tsx +12 -3
- package/src/market-data/market/freshness.ts +18 -0
- package/src/market-data/market/status.ts +15 -2
- package/src/market-data/performance.ts +78 -9
- package/src/market-data/request-types.ts +6 -3
- package/src/plugins/builtin/alerts/cli.ts +2 -1
- package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
- package/src/plugins/builtin/attention/evidence.ts +1 -1
- package/src/plugins/builtin/awards/client.ts +1 -1
- package/src/plugins/builtin/awards/evidence.ts +1 -1
- package/src/plugins/builtin/awards/pane.tsx +2 -1
- package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
- package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
- package/src/plugins/builtin/bond-calculator/math.ts +1 -1
- package/src/plugins/builtin/bond-calculator/model.ts +14 -5
- package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
- package/src/plugins/builtin/broker-manager/footer.ts +3 -2
- package/src/plugins/builtin/broker-manager/index.tsx +2 -1
- package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
- package/src/plugins/builtin/buildout/cells.tsx +25 -45
- package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
- package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
- package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
- package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
- package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
- package/src/plugins/builtin/buildout/format.ts +23 -1
- package/src/plugins/builtin/buildout/model/types.ts +1 -0
- package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
- package/src/plugins/builtin/buildout/table-model.ts +12 -4
- package/src/plugins/builtin/catalysts/evidence.ts +1 -1
- package/src/plugins/builtin/catalysts/pane.tsx +2 -1
- package/src/plugins/builtin/cds/headless.ts +1 -0
- package/src/plugins/builtin/cds/index.tsx +1 -1
- package/src/plugins/builtin/chart-composer/headless.ts +40 -1
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
- package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
- package/src/plugins/builtin/comment-letters/client.ts +2 -1
- package/src/plugins/builtin/company-kpis/client.ts +1 -1
- package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
- package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
- package/src/plugins/builtin/correlation/headless.ts +3 -2
- package/src/plugins/builtin/cot/headless.ts +9 -3
- package/src/plugins/builtin/cot/model.ts +44 -3
- package/src/plugins/builtin/credit-documents/client.ts +1 -1
- package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
- package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
- package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
- package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
- package/src/plugins/builtin/debt-maturities/model.ts +66 -0
- package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
- package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
- package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
- package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
- package/src/plugins/builtin/econ/calendar-model.ts +30 -6
- package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
- package/src/plugins/builtin/econ/print-watch.ts +3 -1
- package/src/plugins/builtin/equity-screener/client.ts +1 -1
- package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
- package/src/plugins/builtin/equity-screener/headless.ts +4 -2
- package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
- package/src/plugins/builtin/equity-screener/model.ts +180 -12
- package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
- package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
- package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
- package/src/plugins/builtin/futures/series.ts +16 -1
- package/src/plugins/builtin/futures-curve/client.ts +19 -0
- package/src/plugins/builtin/futures-curve/headless.ts +52 -13
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +77 -6
- package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
- package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
- package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
- package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
- package/src/plugins/builtin/gpu/headless.ts +2 -1
- package/src/plugins/builtin/help/function-card.tsx +2 -1
- package/src/plugins/builtin/help/index.tsx +2 -1
- package/src/plugins/builtin/insider/display.ts +45 -6
- package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
- package/src/plugins/builtin/iv-history/client.ts +2 -1
- package/src/plugins/builtin/iv-history/headless.ts +2 -1
- package/src/plugins/builtin/jobs/pages.ts +4 -4
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
- package/src/plugins/builtin/macro-day/client.ts +41 -0
- package/src/plugins/builtin/macro-day/headless.ts +19 -9
- package/src/plugins/builtin/macro-day/model.ts +3 -1
- package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
- package/src/plugins/builtin/market-movers/index.tsx +4 -3
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/mna/distress/client.ts +1 -0
- package/src/plugins/builtin/mna/distress/headless.ts +1 -0
- package/src/plugins/builtin/mna/pane.tsx +4 -1
- package/src/plugins/builtin/options/market-reference.ts +1 -1
- package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
- package/src/plugins/builtin/options/view.tsx +2 -1
- package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
- package/src/plugins/builtin/options-scenario/csp.ts +28 -9
- package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/client.ts +1 -1
- package/src/plugins/builtin/perps/pane.tsx +3 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
- package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
- package/src/plugins/builtin/rate-path/headless.ts +24 -10
- package/src/plugins/builtin/research/analyst-model.ts +1 -0
- package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
- package/src/plugins/builtin/research/event-model.ts +10 -3
- package/src/plugins/builtin/research/events-headless.ts +20 -2
- package/src/plugins/builtin/research/index.tsx +1 -0
- package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
- package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
- package/src/plugins/builtin/research-search/snippet.ts +1 -0
- package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
- package/src/plugins/builtin/seasonality/headless.ts +2 -1
- package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
- package/src/plugins/builtin/sec/fund-facts.ts +17 -1
- package/src/plugins/builtin/sec/index.tsx +8 -5
- package/src/plugins/builtin/sec/row-summaries.ts +28 -12
- package/src/plugins/builtin/shared/members-menu.tsx +103 -38
- package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
- package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
- package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
- package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
- package/src/plugins/builtin/social-mentions/client.ts +2 -1
- package/src/plugins/builtin/supply-chain/client.ts +1 -1
- package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
- package/src/plugins/builtin/time-sales/client.ts +1 -0
- package/src/plugins/builtin/time-sales/pane.tsx +3 -2
- package/src/plugins/builtin/trace-bonds/client.ts +7 -4
- package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
- package/src/plugins/builtin/vol-surface/client.ts +2 -1
- package/src/plugins/builtin/volatility/client.ts +6 -1
- package/src/plugins/builtin/volatility/headless.ts +0 -1
- package/src/plugins/builtin/yield-curve/curves.ts +15 -0
- package/src/plugins/builtin/yield-curve/headless.ts +9 -2
- package/src/plugins/builtin/yield-curve/index.tsx +5 -8
- package/src/plugins/host-modules.ts +22 -3
- package/src/plugins/host-smoke.ts +6 -3
- package/src/portfolio/collection-name.ts +19 -0
- package/src/portfolio/column-values.ts +76 -10
- package/src/renderers/browser/http-proxy-transport.ts +78 -8
- package/src/renderers/cloudflare/http-proxy.ts +13 -2
- package/src/renderers/cloudflare/proxy-session.ts +47 -24
- package/src/renderers/cloudflare/worker.ts +15 -2
- package/src/renderers/desktop/geometry.ts +279 -0
- package/src/renderers/desktop/screen-setup.ts +246 -0
- package/src/renderers/desktop/sequential-window-host.ts +179 -0
- package/src/renderers/desktop/test-utils.ts +71 -0
- package/src/renderers/desktop/window-controller.ts +433 -0
- package/src/renderers/desktop/window-host.ts +70 -0
- package/src/renderers/desktop/window-layouts.ts +630 -0
- package/src/renderers/dom/data-frames.ts +15 -4
- package/src/renderers/dom/host/box.tsx +204 -176
- package/src/renderers/dom/host/style.ts +49 -20
- package/src/renderers/dom/host/text.tsx +3 -2
- package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
- package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
- package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
- package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
- package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
- package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
- package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
- package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
- package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
- package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
- package/src/renderers/electrobun/bun/index.ts +4 -97
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
- package/src/renderers/electrobun/bun/window/focus.ts +0 -25
- package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
- package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
- package/src/renderers/electrobun/shared/protocol.ts +50 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
- package/src/renderers/electrobun/view/main.tsx +13 -7
- package/src/renderers/electrobun/view/ui-host.tsx +7 -0
- package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
- package/src/series/fred-argument.ts +17 -0
- package/src/sources/provider-router/financial-routes.ts +7 -1
- package/src/sources/provider-router/index.ts +7 -1
- package/src/state/app/context/index.tsx +16 -2
- package/src/state/desktop-windows.ts +63 -0
- package/src/sync/other-window-tabs.ts +62 -0
- package/src/tickers/company-name-listing.ts +23 -3
- package/src/tickers/listing-fate.ts +147 -1
- package/src/tickers/terminal-codes.ts +5 -0
- package/src/time-series/price-units.ts +11 -0
- package/src/time-series/types.ts +6 -0
- package/src/types/config.ts +10 -1
- package/src/types/desktop-window.ts +71 -2
- package/src/types/financials.ts +4 -0
- package/src/types/headless.ts +19 -0
- package/src/types/plugin.ts +6 -0
- package/src/ui/host.tsx +2 -0
- package/src/ui/index.tsx +14 -13
- package/src/ui/same-props.ts +58 -0
- package/src/utils/cli-output.ts +33 -4
- package/src/utils/currency-names.ts +20 -0
- package/src/utils/currency-pair.ts +6 -0
- package/src/utils/exchange-rate-snapshot.ts +20 -2
- package/src/utils/format.ts +7 -2
- package/src/utils/futures-generic.ts +12 -0
- package/src/utils/fx-market-hours.ts +43 -0
- package/src/utils/http-proxy-upstream.ts +6 -2
- package/src/utils/plugin-proxy-hosts.json +0 -4
- package/src/utils/plugin-proxy-hosts.ts +22 -0
- package/src/utils/sec-filings.ts +7 -1
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
HeadlessPaneDefinition,
|
|
4
4
|
} from "../../../types/plugin";
|
|
5
5
|
import {
|
|
6
|
-
compareDate, curveCutoff, curveIdOf, curveOption, curveSpreadFigures, curveTenorMove, loadComparePoints,
|
|
6
|
+
compareDate, curveCutoff, curveIdOf, curveOption, curveSpreadFigures, curveSpreadText, curveTenorMove, loadComparePoints,
|
|
7
7
|
parseCompareInput, parseCurveArgument, unknownCurveMessage, type CurveData, type CurveId,
|
|
8
8
|
} from "./curves";
|
|
9
9
|
import { yieldTenorRows, type YieldLookbackCurves } from "./chart";
|
|
@@ -16,6 +16,7 @@ import { SWAP_TENORS, type SwapCurvePayload, type SwapTenor } from "../../../api
|
|
|
16
16
|
import { fetchSwapCurve, loadSavedCurve, loadSavedWorldRows } from "./client";
|
|
17
17
|
import { savedCopyMark } from "../../../data/saved-copies";
|
|
18
18
|
import { formatSwapBp, selectedSwapTenor } from "./swaps-model";
|
|
19
|
+
import { logFailure } from "../../../utils/log-failure";
|
|
19
20
|
|
|
20
21
|
const percent = (value: unknown) => value == null ? "-" : `${Number(value).toFixed(2)}%`;
|
|
21
22
|
/** A move already in basis points: `+3bp`, `-1bp`, `0bp`. */
|
|
@@ -164,6 +165,7 @@ export function createYieldCurveHeadless(
|
|
|
164
165
|
const curve = curveIdOf(args.options.curve) ?? parseCurveArgument(args.argument).curve ?? "us";
|
|
165
166
|
return `Yield Curves | ${curveOption(curve).label}`;
|
|
166
167
|
} catch {
|
|
168
|
+
// Intentional ignore: the load reports a curve it cannot read, so the title stays generic.
|
|
167
169
|
return "Yield Curves";
|
|
168
170
|
}
|
|
169
171
|
},
|
|
@@ -206,7 +208,7 @@ export function createYieldCurveHeadless(
|
|
|
206
208
|
const compareAsOf = comparePoints ? curveAsOf(comparePoints) : null;
|
|
207
209
|
const compareAt = (maturity: string) => comparePoints?.find((point) => point.maturity === maturity)?.yield ?? null;
|
|
208
210
|
// The stored curve brings its look-backs; the FRED fallback's load after it, and a failure leaves the move blank.
|
|
209
|
-
const lookbacks: YieldLookbackCurves = data.lookbacks ?? (session ? await loadLookbacks(session, context).catch((
|
|
211
|
+
const lookbacks: YieldLookbackCurves = data.lookbacks ?? (session ? await loadLookbacks(session, context).catch(logFailure("yield-curve.headless", "Load yield curve lookbacks failed", {})) : {});
|
|
210
212
|
const tenorRows = new Map(yieldTenorRows(points, lookbacks).map((row) => [row.id, row]));
|
|
211
213
|
const rows = [...points].sort((a, b) => a.maturityYears - b.maturityYears);
|
|
212
214
|
const missing = points.filter((point) => point.yield == null);
|
|
@@ -239,6 +241,11 @@ export function createYieldCurveHeadless(
|
|
|
239
241
|
...(requestedDate ? { basis: "historical curve" } : { basis: "daily curve", cadence: "daily" }) },
|
|
240
242
|
...(comparePoints ? { columns: compareColumns(compareAsOf) } : ranked ? { columns: RANKED_COLUMNS } : {}),
|
|
241
243
|
...(ranked ? { notes: [RANK_NOTE] } : {}),
|
|
244
|
+
// The spreads the pane shows over its table, each with its day move and where it sits in the last year.
|
|
245
|
+
...(spreads.length ? { textSections: [{ title: "Spreads", entries: spreads.map((figure) => {
|
|
246
|
+
const text = curveSpreadText(figure);
|
|
247
|
+
return { key: figure.id, label: figure.id, value: bp(figure.value), formatted: `${text.value} ${text.detail}` };
|
|
248
|
+
}) }] } : {}),
|
|
242
249
|
rows: rows.map((point) => {
|
|
243
250
|
const compare = compareAt(point.maturity);
|
|
244
251
|
const change = tenorRows.get(point.maturity)?.change1d ?? null;
|
|
@@ -20,7 +20,6 @@ import { GOVERNMENT_BOND_SERIES, TREASURY_SERIES } from "./series";
|
|
|
20
20
|
import { useAutoRefresh } from "../../../react/auto-refresh";
|
|
21
21
|
import { usePaneStatusFooter } from "../../../components/layout/pane/status-footer";
|
|
22
22
|
import { savedCopyFooterSegment, type PaneFooterSegment } from "../../../components/layout/pane/footer";
|
|
23
|
-
import { formatPercentileRank } from "../../../utils/format";
|
|
24
23
|
import { SERIES_COLORS } from "../../../theme/series-colors";
|
|
25
24
|
import type { CurveSeries } from "../../../components/chart/curve";
|
|
26
25
|
import { yieldCurveHeadless } from "./headless";
|
|
@@ -29,7 +28,7 @@ import {
|
|
|
29
28
|
type YieldTenorRow,
|
|
30
29
|
} from "./chart";
|
|
31
30
|
import {
|
|
32
|
-
compareDate, curveCutoff, curveIdOf, CURVE_OPTIONS, curveSpreadFigures, curveTenorMove, loadComparePoints,
|
|
31
|
+
compareDate, curveCutoff, curveIdOf, CURVE_OPTIONS, curveSpreadFigures, curveSpreadText, curveTenorMove, loadComparePoints,
|
|
33
32
|
parseCompareInput, parseCurveArgument, type CurveId,
|
|
34
33
|
} from "./curves";
|
|
35
34
|
import { formatMoveRank, MOVE_HORIZONS } from "../shared/move-rank";
|
|
@@ -291,11 +290,9 @@ function CurveTab({ curve, onCurveChange, focused, width, height }: {
|
|
|
291
290
|
// last year; an inverted one is the warning the curve's shape gives. Then the
|
|
292
291
|
// selected tenor's 1D and 1W moves, ranked by size against its whole history.
|
|
293
292
|
const figures = useMemo<StatItem[]>(() => [
|
|
294
|
-
...curveSpreadFigures(current, lookbackCurves).map((
|
|
295
|
-
id, label: id,
|
|
296
|
-
|
|
297
|
-
...(percentile1y == null ? [] : [formatPercentileRank(percentile1y, "1Y")])].join(" · "),
|
|
298
|
-
tone: value != null && Math.round(value * 100) < 0 ? "warning" : undefined,
|
|
293
|
+
...curveSpreadFigures(current, lookbackCurves).map((figure): StatItem => ({
|
|
294
|
+
id: figure.id, label: figure.id, ...curveSpreadText(figure),
|
|
295
|
+
tone: figure.value != null && Math.round(figure.value * 100) < 0 ? "warning" : undefined,
|
|
299
296
|
})),
|
|
300
297
|
...(selectedId ? MOVE_HORIZONS : []).flatMap((horizon): StatItem[] => {
|
|
301
298
|
const move = curveTenorMove(current, selectedId!, horizon);
|
|
@@ -507,7 +504,7 @@ export const yieldCurveModule: PluginModule = {
|
|
|
507
504
|
label: "Yield Curve",
|
|
508
505
|
description: "Government bond curves, a world grid, and USD SOFR swap rates, swap spreads and tenor history.",
|
|
509
506
|
keywords: ["yield", "curve", "treasury", "bonds", "rates", "gc", "interest", "tips", "breakeven", "bund", "gilt", "jgb",
|
|
510
|
-
"sovereign", "world", "forward", "swaps", "sofr", "ois", "swap spread"],
|
|
507
|
+
"sovereign", "world", "forward", "swaps", "sofr", "ois", "swap spread", "2s10s", "steepener", "flattener"],
|
|
511
508
|
shortcut: { prefix: "GC", argPlaceholder: "[curve] [date]", argKind: "text", argOptional: true },
|
|
512
509
|
headless: yieldCurveHeadless,
|
|
513
510
|
createInstance: (_context, options) => {
|
|
@@ -23,6 +23,25 @@ interface HostModule {
|
|
|
23
23
|
native?: true;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* A CommonJS package's exports as an ES module's: each property of its
|
|
28
|
+
* `module.exports` a named export, beside `default`.
|
|
29
|
+
*
|
|
30
|
+
* The terminal binary and the desktop app's terminal are bundled with
|
|
31
|
+
* `--splitting` (scripts/build.ts, scripts/install-electrobun-tui-shim.ts),
|
|
32
|
+
* and once any module default-imports React, as the OpenTUI renderer does,
|
|
33
|
+
* Bun answers `import("react")` with a chunk that exports `module.exports`
|
|
34
|
+
* as `default` and nothing else. Served like that, a plugin's
|
|
35
|
+
* `import React from "react"` linked and its `import { useEffect } from
|
|
36
|
+
* "react"` did not, and nearly every plugin failed to load there.
|
|
37
|
+
*/
|
|
38
|
+
async function importCommonJs(load: HostModuleImporter): Promise<object> {
|
|
39
|
+
const namespace = (await load()) as Record<string, unknown>;
|
|
40
|
+
const moduleExports = namespace.default;
|
|
41
|
+
if (moduleExports === null || typeof moduleExports !== "object") return namespace;
|
|
42
|
+
return { ...moduleExports, ...namespace };
|
|
43
|
+
}
|
|
44
|
+
|
|
26
45
|
/**
|
|
27
46
|
* Every specifier a plugin may import that must resolve to the host's copy.
|
|
28
47
|
* Anything else is a plugin's own dependency and gets bundled normally.
|
|
@@ -37,9 +56,9 @@ interface HostModule {
|
|
|
37
56
|
* desktop and break in the TUI.
|
|
38
57
|
*/
|
|
39
58
|
const HOST_MODULES: Readonly<Record<string, HostModule>> = {
|
|
40
|
-
"react": { load: () => import("react") },
|
|
41
|
-
"react/jsx-runtime": { load: () => import("react/jsx-runtime") },
|
|
42
|
-
"react/jsx-dev-runtime": { load: () => import("react/jsx-dev-runtime") },
|
|
59
|
+
"react": { load: () => importCommonJs(() => import("react")) },
|
|
60
|
+
"react/jsx-runtime": { load: () => importCommonJs(() => import("react/jsx-runtime")) },
|
|
61
|
+
"react/jsx-dev-runtime": { load: () => importCommonJs(() => import("react/jsx-dev-runtime")) },
|
|
43
62
|
"gloomberb/types/plugin": { load: () => import("../types/plugin") },
|
|
44
63
|
"gloomberb/types/persistence": { load: () => import("../types/persistence") },
|
|
45
64
|
// Type modules also export runtime values (`TICKER_RESEARCH_PANE_ID`,
|
|
@@ -7,13 +7,15 @@ import { loadExternalPlugin } from "./loader";
|
|
|
7
7
|
/**
|
|
8
8
|
* The plugin the smoke writes: one import from each kind of module a real
|
|
9
9
|
* plugin uses. `react` and the JSX runtime have to be the host's own
|
|
10
|
-
* instance,
|
|
10
|
+
* instance, imported by name as registry plugins do: a host that served
|
|
11
|
+
* React's default export alone passed a default import and failed every
|
|
12
|
+
* plugin. `gloomberb/ui` is shared state, `gloomberb/types/config` is a
|
|
11
13
|
* value from a module that used to be bundled from the package directory,
|
|
12
14
|
* and `smoke-dep` stands in for a dependency `bun install` put in the
|
|
13
15
|
* plugin's own `node_modules`.
|
|
14
16
|
*/
|
|
15
17
|
const SMOKE_PLUGIN_SOURCE = `
|
|
16
|
-
import React from "react";
|
|
18
|
+
import React, { memo, useCallback, useEffect, useState, useSyncExternalStore } from "react";
|
|
17
19
|
import { Box, Text } from "gloomberb/ui";
|
|
18
20
|
import { formatNumber } from "gloomberb/utils";
|
|
19
21
|
import { TICKER_RESEARCH_PANE_ID } from "gloomberb/types/config";
|
|
@@ -31,7 +33,8 @@ export default {
|
|
|
31
33
|
const element = <Probe />;
|
|
32
34
|
const tree = Probe();
|
|
33
35
|
return {
|
|
34
|
-
react: typeof React.createElement === "function"
|
|
36
|
+
react: typeof React.createElement === "function"
|
|
37
|
+
&& [memo, useCallback, useEffect, useState, useSyncExternalStore].every((value) => typeof value === "function"),
|
|
35
38
|
jsx: typeof element.type === "function" && tree != null && typeof tree === "object" && "type" in tree,
|
|
36
39
|
paneId: TICKER_RESEARCH_PANE_ID,
|
|
37
40
|
platform,
|
|
@@ -25,6 +25,25 @@ export function findNamedCollection<T extends { id: string; name: string }>(
|
|
|
25
25
|
)) ?? null;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* What a list argument that names a watchlist reads (`SIW HY3`): its symbols,
|
|
30
|
+
* at most a function's `maximum`, and a note saying the name was read as the
|
|
31
|
+
* watchlist, which matters when it is a ticker too (`AI`): `Read AI as
|
|
32
|
+
* watchlist AI (12 symbols).` or `Read HY3 as watchlist HY3 (70 symbols); the
|
|
33
|
+
* first 60 are read.` Every function's list argument, in `fn` and in the
|
|
34
|
+
* command bar, reads a watchlist's name here.
|
|
35
|
+
*/
|
|
36
|
+
export function readWatchlistArgument(
|
|
37
|
+
typed: string,
|
|
38
|
+
watchlist: { name: string },
|
|
39
|
+
members: readonly string[],
|
|
40
|
+
maximum: number | undefined,
|
|
41
|
+
): { symbols: string[]; note: string } {
|
|
42
|
+
const read = `Read ${typed.trim()} as watchlist ${watchlist.name} (${members.length} symbol${members.length === 1 ? "" : "s"})`;
|
|
43
|
+
if (maximum == null || members.length <= maximum) return { symbols: [...members], note: `${read}.` };
|
|
44
|
+
return { symbols: members.slice(0, maximum), note: `${read}; the first ${maximum} are read.` };
|
|
45
|
+
}
|
|
46
|
+
|
|
28
47
|
/**
|
|
29
48
|
* The command bar's row for a function typed with a portfolio or watchlist
|
|
30
49
|
* nothing has (`PF Nope`, `PORT Nope`), or null when one of `collections` has
|
|
@@ -397,6 +397,80 @@ function futuresContractSizeLabel(
|
|
|
397
397
|
return !metrics.unknownContractSize && multiplier > 1 ? { size: formatMarketQuantity(multiplier) } : null;
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
interface RowPositionMetrics {
|
|
401
|
+
quoteCurrency: string;
|
|
402
|
+
quote: Quote | undefined;
|
|
403
|
+
/** What the figures were worked out for: a context that disagrees works them out again. */
|
|
404
|
+
activeTab: string | undefined;
|
|
405
|
+
baseCurrency: string;
|
|
406
|
+
exchangeRates: Map<string, number>;
|
|
407
|
+
/** In the position's own currency. */
|
|
408
|
+
position: PortfolioPositionMetrics;
|
|
409
|
+
/** Converted into the pane's currency (`ctx.baseCurrency`). */
|
|
410
|
+
base: PortfolioPositionMetrics;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** Each shared context's row figures, by record. */
|
|
414
|
+
const sharedRowMetrics = new WeakMap<ColumnContext, WeakMap<TickerRecord, RowPositionMetrics>>();
|
|
415
|
+
const rowMetricsByOwner = new WeakMap<object, WeakMap<TickerRecord, RowPositionMetrics>>();
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Lets the cells and sort keys read with `ctx` work out each row's position
|
|
419
|
+
* figures once per quote, rather than twice a cell: a pane's rows recompute
|
|
420
|
+
* every visible cell when a quote ticks. Contexts given the same `owner` share
|
|
421
|
+
* the figures while they agree on the tab, currency and rates (a context that
|
|
422
|
+
* disagrees works them out again). Only for records that are replaced when
|
|
423
|
+
* they change, never edited in place.
|
|
424
|
+
*/
|
|
425
|
+
export function sharePositionMetrics<T extends ColumnContext>(ctx: T, owner: object = ctx): T {
|
|
426
|
+
let rows = rowMetricsByOwner.get(owner);
|
|
427
|
+
if (!rows) {
|
|
428
|
+
rows = new WeakMap();
|
|
429
|
+
rowMetricsByOwner.set(owner, rows);
|
|
430
|
+
}
|
|
431
|
+
sharedRowMetrics.set(ctx, rows);
|
|
432
|
+
return ctx;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function computeRowPositionMetrics(ticker: TickerRecord, ctx: ColumnContext, quoteCurrency: string, quote: Quote | undefined): RowPositionMetrics {
|
|
436
|
+
const { activeTab, baseCurrency, exchangeRates } = ctx;
|
|
437
|
+
return {
|
|
438
|
+
quoteCurrency,
|
|
439
|
+
quote,
|
|
440
|
+
activeTab,
|
|
441
|
+
baseCurrency,
|
|
442
|
+
exchangeRates,
|
|
443
|
+
position: getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, undefined, quote),
|
|
444
|
+
base: getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, {
|
|
445
|
+
currency: baseCurrency,
|
|
446
|
+
convert: (value, currency) => convertCurrency(value, currency, baseCurrency, exchangeRates),
|
|
447
|
+
}, quote),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** A row's position figures, in its own currency and in the pane's (sharePositionMetrics). */
|
|
452
|
+
function rowPositionMetrics(
|
|
453
|
+
ticker: TickerRecord,
|
|
454
|
+
ctx: ColumnContext,
|
|
455
|
+
quoteCurrency: string,
|
|
456
|
+
quote: Quote | undefined,
|
|
457
|
+
): RowPositionMetrics {
|
|
458
|
+
const rows = sharedRowMetrics.get(ctx);
|
|
459
|
+
if (!rows) return computeRowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
460
|
+
const cached = rows.get(ticker);
|
|
461
|
+
if (
|
|
462
|
+
cached
|
|
463
|
+
&& cached.quote === quote
|
|
464
|
+
&& cached.quoteCurrency === quoteCurrency
|
|
465
|
+
&& cached.activeTab === ctx.activeTab
|
|
466
|
+
&& cached.baseCurrency === ctx.baseCurrency
|
|
467
|
+
&& cached.exchangeRates === ctx.exchangeRates
|
|
468
|
+
) return cached;
|
|
469
|
+
const entry = computeRowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
470
|
+
rows.set(ticker, entry);
|
|
471
|
+
return entry;
|
|
472
|
+
}
|
|
473
|
+
|
|
400
474
|
export function getColumnValue(
|
|
401
475
|
col: ColumnConfig,
|
|
402
476
|
ticker: TickerRecord,
|
|
@@ -408,7 +482,7 @@ export function getColumnValue(
|
|
|
408
482
|
const fundamentals = financials?.fundamentals;
|
|
409
483
|
const quoteCurrency = quote?.currency || ticker.metadata.currency || "USD";
|
|
410
484
|
|
|
411
|
-
const positionMetrics =
|
|
485
|
+
const { position: positionMetrics, base: baseMetrics } = rowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
412
486
|
const futures = positionMetrics.isFuture ? ctx.futuresTerms?.get(ticker.metadata.ticker) : undefined;
|
|
413
487
|
// The latest print, which the quote columns read, and the price the position is valued at.
|
|
414
488
|
const liveQuote = getPortfolioQuoteDisplay(positionMetrics, quote);
|
|
@@ -416,10 +490,6 @@ export function getColumnValue(
|
|
|
416
490
|
const displayQuote = tradedQuoteDisplay(positionMetrics, liveQuote, quote);
|
|
417
491
|
const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? headlineQuoteDisplay(displayQuote, quote);
|
|
418
492
|
const { positionCurrency, totalShares, totalCost, totalCostUnits, totalPriceUnits, multiplierHint, brokerMarkPrice } = positionMetrics;
|
|
419
|
-
const baseMetrics = getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, {
|
|
420
|
-
currency: ctx.baseCurrency,
|
|
421
|
-
convert: (value, currency) => convertCurrency(value, currency, ctx.baseCurrency, ctx.exchangeRates),
|
|
422
|
-
}, quote);
|
|
423
493
|
|
|
424
494
|
const toBaseQuote = (value: number) =>
|
|
425
495
|
convertCurrency(value, quoteCurrency, ctx.baseCurrency, ctx.exchangeRates);
|
|
@@ -685,17 +755,13 @@ export function getSortValue(
|
|
|
685
755
|
const fundamentals = financials?.fundamentals;
|
|
686
756
|
const quoteCurrency = quote?.currency || ticker.metadata.currency || "USD";
|
|
687
757
|
|
|
688
|
-
const positionMetrics =
|
|
758
|
+
const { position: positionMetrics, base: baseMetrics } = rowPositionMetrics(ticker, ctx, quoteCurrency, quote);
|
|
689
759
|
const futures = positionMetrics.isFuture ? ctx.futuresTerms?.get(ticker.metadata.ticker) : undefined;
|
|
690
760
|
const liveQuote = getPortfolioQuoteDisplay(positionMetrics, quote);
|
|
691
761
|
const activeQuote = getPortfolioValuationDisplay(positionMetrics, quote, ctx.valuationBasis, futures?.settlement);
|
|
692
762
|
const displayQuote = tradedQuoteDisplay(positionMetrics, liveQuote, quote);
|
|
693
763
|
const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? headlineQuoteDisplay(displayQuote, quote);
|
|
694
764
|
const { positionCurrency, totalShares, totalCost, totalCostUnits, totalPriceUnits, brokerMarkPrice } = positionMetrics;
|
|
695
|
-
const baseMetrics = getPortfolioPositionMetrics(ticker, ctx.activeTab, quoteCurrency, {
|
|
696
|
-
currency: ctx.baseCurrency,
|
|
697
|
-
convert: (value, currency) => convertCurrency(value, currency, ctx.baseCurrency, ctx.exchangeRates),
|
|
698
|
-
}, quote);
|
|
699
765
|
|
|
700
766
|
const toBaseQuote = (value: number) =>
|
|
701
767
|
convertCurrency(value, quoteCurrency, ctx.baseCurrency, ctx.exchangeRates);
|
|
@@ -6,6 +6,70 @@ import {
|
|
|
6
6
|
import type { HttpFetchTransport } from "../../utils/http-transport";
|
|
7
7
|
import { HTTP_PROXY_PATH, isProxiedHost, PROXY_ALLOWED_HOSTS } from "../../utils/plugin-proxy-hosts";
|
|
8
8
|
|
|
9
|
+
/** Thrown when the worker refuses or cannot complete a proxied request. */
|
|
10
|
+
class ProxyRefusedError extends Error {
|
|
11
|
+
constructor(message: string, readonly status: number) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ProxyRefusedError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const UNREACHABLE = "The data source could not be reached. Check your connection and try again.";
|
|
18
|
+
const UNREADABLE = "The data source's answer could not be read. Try again shortly.";
|
|
19
|
+
/** Longer than any sentence the worker writes; anything past it is not one of them. */
|
|
20
|
+
const MAX_REFUSAL_LENGTH = 160;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The sentence a pane shows for a refusal. The worker answers with
|
|
24
|
+
* `{ error }` in plain words; anything else (an edge error page, a body cut
|
|
25
|
+
* short, a message that is not one short line) gets a sentence for its
|
|
26
|
+
* status, never the raw body.
|
|
27
|
+
*/
|
|
28
|
+
async function refusalMessage(response: Response): Promise<string> {
|
|
29
|
+
const body = await response.json().catch(() => null) as { error?: unknown } | null;
|
|
30
|
+
const error = typeof body?.error === "string" ? body.error.trim() : "";
|
|
31
|
+
if (error && error.length <= MAX_REFUSAL_LENGTH && !/[{}<>\n]/.test(error)) return error;
|
|
32
|
+
if (response.status === 429) return "Too many requests right now. Try again in a minute.";
|
|
33
|
+
if (response.status >= 500) return "The data source could not be reached. Try again shortly.";
|
|
34
|
+
return "This request could not be completed.";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isEnvelope(value: unknown): value is HttpProxyResponseEnvelope {
|
|
38
|
+
if (!value || typeof value !== "object") return false;
|
|
39
|
+
const { status, headers, body } = value as Partial<HttpProxyResponseEnvelope>;
|
|
40
|
+
return typeof status === "number" && !!headers && typeof headers === "object" && typeof body === "string";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A request that never got an answer fails with the browser's own words
|
|
45
|
+
* ("Failed to fetch", "Load failed"), which a pane would print as they are.
|
|
46
|
+
* It becomes a sentence instead, keeping the original as `cause` for code
|
|
47
|
+
* that classifies network failures. A caller's abort or timeout stays as it
|
|
48
|
+
* was, since callers check for those by name.
|
|
49
|
+
*/
|
|
50
|
+
async function answered(request: () => Promise<Response>, signal: AbortSignal | null | undefined): Promise<Response> {
|
|
51
|
+
try {
|
|
52
|
+
return await request();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const name = (error as { name?: unknown } | null)?.name;
|
|
55
|
+
if (signal?.aborted || name === "AbortError" || name === "TimeoutError") throw error;
|
|
56
|
+
throw new Error(UNREACHABLE, { cause: error });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A browser owns `User-Agent`. Chrome drops one set by script, but Firefox
|
|
62
|
+
* sends it, which turns a simple cross-origin GET into a preflight that some
|
|
63
|
+
* of the hosts called directly do not allow. Every browser leaves it out.
|
|
64
|
+
*/
|
|
65
|
+
function withoutUserAgent(init: RequestInit | undefined): RequestInit | undefined {
|
|
66
|
+
if (!init?.headers) return init;
|
|
67
|
+
const headers = new Headers(init.headers);
|
|
68
|
+
if (!headers.has("user-agent")) return init;
|
|
69
|
+
headers.delete("user-agent");
|
|
70
|
+
return { ...init, headers };
|
|
71
|
+
}
|
|
72
|
+
|
|
9
73
|
function needsProxy(url: string, hosts: readonly string[]): boolean {
|
|
10
74
|
try {
|
|
11
75
|
const target = new URL(url, typeof location === "undefined" ? undefined : location.href);
|
|
@@ -36,20 +100,26 @@ export function createBrowserHttpProxyTransport(
|
|
|
36
100
|
hosts: readonly string[] = PROXY_ALLOWED_HOSTS,
|
|
37
101
|
): HttpFetchTransport {
|
|
38
102
|
return async function proxiedFetch(url: string, init?: RequestInit): Promise<Response> {
|
|
39
|
-
if (!needsProxy(url, hosts)) return send(url, init);
|
|
103
|
+
if (!needsProxy(url, hosts)) return answered(() => send(url, withoutUserAgent(init)), init?.signal);
|
|
40
104
|
|
|
41
|
-
const
|
|
105
|
+
const envelope = await toRequestEnvelope(url, init);
|
|
106
|
+
const proxied = await answered(() => send(HTTP_PROXY_PATH, {
|
|
42
107
|
method: "POST",
|
|
43
108
|
headers: { "content-type": "application/json" },
|
|
44
109
|
credentials: "include",
|
|
45
110
|
signal: init?.signal ?? null,
|
|
46
|
-
body: JSON.stringify(
|
|
47
|
-
});
|
|
111
|
+
body: JSON.stringify(envelope),
|
|
112
|
+
}), init?.signal);
|
|
48
113
|
|
|
49
|
-
if (!proxied.ok)
|
|
50
|
-
|
|
51
|
-
|
|
114
|
+
if (!proxied.ok) throw new ProxyRefusedError(await refusalMessage(proxied), proxied.status);
|
|
115
|
+
// A 200 that is not an envelope (an HTML page from a route that is not
|
|
116
|
+
// the worker's) would otherwise surface as a JSON SyntaxError quoting it.
|
|
117
|
+
const answer = await proxied.json().catch(() => null);
|
|
118
|
+
if (!isEnvelope(answer)) throw new ProxyRefusedError(UNREADABLE, proxied.status);
|
|
119
|
+
try {
|
|
120
|
+
return createProxyResponse(answer);
|
|
121
|
+
} catch {
|
|
122
|
+
throw new ProxyRefusedError(UNREADABLE, proxied.status);
|
|
52
123
|
}
|
|
53
|
-
return createProxyResponse(await proxied.json() as HttpProxyResponseEnvelope);
|
|
54
124
|
};
|
|
55
125
|
}
|
|
@@ -25,6 +25,13 @@ import { fetchCheckingRedirects, readBytesWithin, type ProxyUpstreamResult } fro
|
|
|
25
25
|
import type { ProxySessionGate } from "./proxy-session";
|
|
26
26
|
|
|
27
27
|
const PROXY_METHODS = new Set(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"]);
|
|
28
|
+
/**
|
|
29
|
+
* What a caller without a confirmed session may send. The functions that work
|
|
30
|
+
* signed out only read (a POST carries a search, as FINRA's tape does), and
|
|
31
|
+
* the Origin check is no barrier to a script, so anonymous use stays a
|
|
32
|
+
* read-only proxy to the allowlisted hosts.
|
|
33
|
+
*/
|
|
34
|
+
const ANONYMOUS_METHODS = new Set(["GET", "HEAD", "POST"]);
|
|
28
35
|
const MAX_BODY_BYTES = 5 * 1024 * 1024;
|
|
29
36
|
/** Plugin request bodies are small JSON; anything near this is not one. */
|
|
30
37
|
const MAX_REQUEST_BYTES = 1024 * 1024;
|
|
@@ -74,13 +81,14 @@ function proxyError(message: string, status: number, headers: Record<string, str
|
|
|
74
81
|
return Response.json({ error: message }, { status, headers: { "cache-control": "no-store", ...headers } });
|
|
75
82
|
}
|
|
76
83
|
|
|
84
|
+
/** The pane shows `error` as is, so it says what happened in plain words. */
|
|
77
85
|
function upstreamFailure(error: unknown): Response {
|
|
78
86
|
const timedOut = error instanceof Error && error.name === "TimeoutError";
|
|
79
|
-
return proxyError(timedOut ? "The
|
|
87
|
+
return proxyError(timedOut ? "The data source timed out. Try again shortly." : "The data source could not be reached. Try again shortly.", 504);
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
export interface HttpProxyOptions {
|
|
83
|
-
/**
|
|
91
|
+
/** Rate limits the caller, by user when signed in. One per isolate, so its cache is shared. */
|
|
84
92
|
sessions: ProxySessionGate;
|
|
85
93
|
/** Reaches the Gloomberb API for that check. */
|
|
86
94
|
fetchApi: (request: Request) => Promise<Response>;
|
|
@@ -134,6 +142,9 @@ export async function handleHttpProxy(request: Request, options: HttpProxyOption
|
|
|
134
142
|
if (!PROXY_METHODS.has(init.method)) {
|
|
135
143
|
return proxyError("Method not allowed", 405);
|
|
136
144
|
}
|
|
145
|
+
if (!admission.signedIn && !ANONYMOUS_METHODS.has(init.method)) {
|
|
146
|
+
return proxyError("Sign in to Gloom to send this request.", 401);
|
|
147
|
+
}
|
|
137
148
|
|
|
138
149
|
const signal = AbortSignal.timeout(Math.min(init.timeoutMs ?? DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS));
|
|
139
150
|
let result: ProxyUpstreamResult;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* How much of the plugin HTTP proxy a caller gets. Everyone may use it, since
|
|
3
|
+
* the functions behind it show free public data that works signed out on the
|
|
4
|
+
* desktop too; what differs is the rate limit. A signed-in Gloomberb session,
|
|
5
|
+
* confirmed by the API rather than by the cookie merely being present, is
|
|
6
|
+
* counted per user. Everyone else, including a session the API rejects or
|
|
7
|
+
* cannot confirm right now, is counted per IP address against a smaller
|
|
8
|
+
* window, so a failed check never grants more than signing out would.
|
|
4
9
|
*
|
|
5
10
|
* Plugin panes fire requests in bursts, so a confirmed session is remembered
|
|
6
11
|
* for a minute per isolate and concurrent requests share one check. A session
|
|
7
|
-
* the API rejects is not remembered, so signing in again works at once.
|
|
8
|
-
* the API cannot answer, the proxy refuses rather than guessing.
|
|
12
|
+
* the API rejects is not remembered, so signing in again works at once.
|
|
9
13
|
*
|
|
10
14
|
* The cache is keyed by the exact cookies that were confirmed, but the rate
|
|
11
15
|
* limit is keyed by the user the API named. The API reads only part of those
|
|
@@ -42,6 +46,12 @@ const SHARED_CHECK_GRACE_MS = 500;
|
|
|
42
46
|
* stopping a script from turning one account into a free proxy.
|
|
43
47
|
*/
|
|
44
48
|
const DEFAULT_REQUESTS_PER_WINDOW = 300;
|
|
49
|
+
/**
|
|
50
|
+
* Per IP address, per isolate, for callers without a confirmed session. A
|
|
51
|
+
* signed-out layout of the heaviest proxied panes (prediction markets, bond
|
|
52
|
+
* tape, Treasury, halts) stays well under this; a script does not.
|
|
53
|
+
*/
|
|
54
|
+
const DEFAULT_ANONYMOUS_REQUESTS_PER_WINDOW = 240;
|
|
45
55
|
const DEFAULT_WINDOW_MS = 60_000;
|
|
46
56
|
/**
|
|
47
57
|
* Confirmed cookie variants one user may hold in the cache at once. A user
|
|
@@ -69,7 +79,8 @@ interface RateWindow {
|
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
type ProxyAdmission =
|
|
72
|
-
|
|
82
|
+
/** `signedIn` is true only for a session the API confirmed. */
|
|
83
|
+
| { ok: true; signedIn: boolean }
|
|
73
84
|
| { ok: false; status: number; error: string; retryAfterSeconds?: number };
|
|
74
85
|
|
|
75
86
|
export interface ProxySessionGate {
|
|
@@ -84,16 +95,26 @@ export interface ProxySessionGateOptions {
|
|
|
84
95
|
maxEntries?: number;
|
|
85
96
|
maxEntriesPerUser?: number;
|
|
86
97
|
requestsPerWindow?: number;
|
|
98
|
+
anonymousRequestsPerWindow?: number;
|
|
87
99
|
windowMs?: number;
|
|
88
100
|
checkTimeoutMs?: number;
|
|
89
101
|
}
|
|
90
102
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
/**
|
|
104
|
+
* The window an anonymous caller is counted in. Cloudflare sets
|
|
105
|
+
* `cf-connecting-ip` on every request that reaches the worker. An IPv6 caller
|
|
106
|
+
* is counted by its /64, the block one subscriber is usually handed, so
|
|
107
|
+
* rotating through it does not open fresh windows.
|
|
108
|
+
*/
|
|
109
|
+
function anonymousRateKey(request: Request): string {
|
|
110
|
+
const ip = request.headers.get("cf-connecting-ip")?.trim().toLowerCase() ?? "";
|
|
111
|
+
if (!ip.includes(":")) return `ip:${ip || "unknown"}`;
|
|
112
|
+
const [head = "", tail] = ip.split("::", 2);
|
|
113
|
+
const front = head ? head.split(":") : [];
|
|
114
|
+
const back = tail === undefined ? [] : tail ? tail.split(":") : [];
|
|
115
|
+
const groups = tail === undefined ? front : [...front, ...Array(Math.max(0, 8 - front.length - back.length)).fill("0"), ...back];
|
|
116
|
+
return `ip6:${groups.slice(0, 4).map((group) => group.replace(/^0+(?=.)/, "")).join(":")}`;
|
|
117
|
+
}
|
|
97
118
|
|
|
98
119
|
/** The session cookies (and `dont_remember`) from a Cookie header, in order. */
|
|
99
120
|
function forwardedCookies(header: string | null): string | null {
|
|
@@ -186,13 +207,18 @@ export function createProxySessionGate(options: ProxySessionGateOptions): ProxyS
|
|
|
186
207
|
const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
187
208
|
const maxEntriesPerUser = Math.max(1, options.maxEntriesPerUser ?? DEFAULT_MAX_ENTRIES_PER_USER);
|
|
188
209
|
const requestsPerWindow = options.requestsPerWindow ?? DEFAULT_REQUESTS_PER_WINDOW;
|
|
210
|
+
const anonymousRequestsPerWindow = options.anonymousRequestsPerWindow ?? DEFAULT_ANONYMOUS_REQUESTS_PER_WINDOW;
|
|
189
211
|
const windowMs = options.windowMs ?? DEFAULT_WINDOW_MS;
|
|
190
212
|
const checkTimeoutMs = options.checkTimeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
191
213
|
const sharedWaitMs = checkTimeoutMs + SHARED_CHECK_GRACE_MS;
|
|
192
214
|
/** Cookie key to whose session it is and when that stops being trusted. */
|
|
193
215
|
const confirmed = new Map<string, Confirmation>();
|
|
194
216
|
const pending = new Map<string, PendingCheck>();
|
|
195
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Keyed by user id, not cookie, so every variant of a session shares one
|
|
219
|
+
* window, or by address for anonymous callers. The prefixes keep the two
|
|
220
|
+
* apart.
|
|
221
|
+
*/
|
|
196
222
|
const windows = new Map<string, RateWindow>();
|
|
197
223
|
|
|
198
224
|
/** Remembers `key` for `userId`, first dropping that user's oldest variants past the per-user cap. */
|
|
@@ -237,21 +263,21 @@ export function createProxySessionGate(options: ProxySessionGateOptions): ProxyS
|
|
|
237
263
|
return verdict;
|
|
238
264
|
}
|
|
239
265
|
|
|
240
|
-
function withinRate(
|
|
266
|
+
function withinRate(windowKey: string, limit: number, signedIn: boolean): ProxyAdmission {
|
|
241
267
|
const at = now();
|
|
242
|
-
let window = windows.get(
|
|
268
|
+
let window = windows.get(windowKey);
|
|
243
269
|
if (!window || at - window.startedAt >= windowMs) {
|
|
244
|
-
windows.delete(
|
|
270
|
+
windows.delete(windowKey);
|
|
245
271
|
makeRoom(windows, maxEntries, (entry) => at - entry.startedAt >= windowMs);
|
|
246
272
|
window = { startedAt: at, count: 0 };
|
|
247
|
-
windows.set(
|
|
273
|
+
windows.set(windowKey, window);
|
|
248
274
|
}
|
|
249
275
|
window.count += 1;
|
|
250
|
-
if (window.count <=
|
|
276
|
+
if (window.count <= limit) return { ok: true, signedIn };
|
|
251
277
|
return {
|
|
252
278
|
ok: false,
|
|
253
279
|
status: 429,
|
|
254
|
-
error: "Too many
|
|
280
|
+
error: "Too many requests right now. Try again in a minute.",
|
|
255
281
|
retryAfterSeconds: Math.max(1, Math.ceil((window.startedAt + windowMs - at) / 1_000)),
|
|
256
282
|
};
|
|
257
283
|
}
|
|
@@ -259,12 +285,9 @@ export function createProxySessionGate(options: ProxySessionGateOptions): ProxyS
|
|
|
259
285
|
return {
|
|
260
286
|
async admit(request, fetchApi) {
|
|
261
287
|
const cookie = forwardedCookies(request.headers.get("cookie"));
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (verdict === "invalid") return SIGN_IN;
|
|
266
|
-
if (verdict === "unavailable") return UNAVAILABLE;
|
|
267
|
-
return withinRate(verdict.userId);
|
|
288
|
+
const verdict = cookie ? await verdictFor(await cacheKey(cookie), cookie, request, fetchApi) : "invalid";
|
|
289
|
+
if (typeof verdict === "object") return withinRate(`user:${verdict.userId}`, requestsPerWindow, true);
|
|
290
|
+
return withinRate(anonymousRateKey(request), anonymousRequestsPerWindow, false);
|
|
268
291
|
},
|
|
269
292
|
};
|
|
270
293
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { handleHttpProxy } from "./http-proxy";
|
|
2
2
|
import { createProxySessionGate } from "./proxy-session";
|
|
3
|
-
import { HTTP_PROXY_PATH } from "../../utils/plugin-proxy-hosts";
|
|
3
|
+
import { HTTP_PROXY_PATH, WEB_DIRECT_HOSTS } from "../../utils/plugin-proxy-hosts";
|
|
4
4
|
|
|
5
5
|
interface StaticAssetsBinding {
|
|
6
6
|
fetch(request: Request): Promise<Response>;
|
|
@@ -70,8 +70,21 @@ type ApiFetch = (request: Request) => Promise<Response>;
|
|
|
70
70
|
/** Module scope, so every request this isolate serves shares one session cache. */
|
|
71
71
|
const proxySessions = createProxySessionGate({ sessionUrl: `${API_ORIGIN}/auth/get-session` });
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* What the page may fetch: itself (the API and the plugin proxy are both
|
|
75
|
+
* same-origin), the app's own hosts, and the plugin hosts the browser calls
|
|
76
|
+
* directly. Every other plugin host goes through the proxy.
|
|
77
|
+
*/
|
|
78
|
+
const CONNECT_SRC = [
|
|
79
|
+
"'self'",
|
|
80
|
+
"https://api.github.com",
|
|
81
|
+
"https://plugins.gloom.sh",
|
|
82
|
+
"https://gloom.sh",
|
|
83
|
+
...WEB_DIRECT_HOSTS.map((host) => `https://${host}`),
|
|
84
|
+
].join(" ");
|
|
85
|
+
|
|
73
86
|
export const SECURITY_HEADERS = {
|
|
74
|
-
"content-security-policy":
|
|
87
|
+
"content-security-policy": `default-src 'self'; base-uri 'none'; object-src 'none'; frame-ancestors 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; media-src 'self' https:; connect-src ${CONNECT_SRC}; form-action 'self'; upgrade-insecure-requests`,
|
|
75
88
|
"cross-origin-opener-policy": "same-origin",
|
|
76
89
|
"cross-origin-resource-policy": "same-origin",
|
|
77
90
|
"permissions-policy": "camera=(), geolocation=(), microphone=(), payment=(), usb=()",
|