gloomberb 0.20.13 → 0.20.16

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.
Files changed (275) hide show
  1. package/package.json +2 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
  3. package/src/account/auth-dialog.tsx +22 -4
  4. package/src/account/auth-form.tsx +6 -1
  5. package/src/account/checkout-handoff.tsx +7 -14
  6. package/src/account/device-signin-dialog.tsx +35 -24
  7. package/src/api-client/crypto-markets.ts +10 -0
  8. package/src/api-client/errors.ts +3 -1
  9. package/src/api-client/index.ts +54 -0
  10. package/src/api-client/install-experiments.ts +8 -7
  11. package/src/api-client/money-markets.ts +7 -0
  12. package/src/api-client/paths.ts +2 -1
  13. package/src/api-client/product-waitlist.ts +63 -0
  14. package/src/api-client/request.ts +16 -4
  15. package/src/api-client/types/billing.ts +45 -0
  16. package/src/api-client/yearly-plan.ts +132 -0
  17. package/src/app/global-shortcuts.ts +5 -3
  18. package/src/app/pane-runtime/index.tsx +2 -2
  19. package/src/app/pane-runtime/plugin-bindings.ts +3 -1
  20. package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
  21. package/src/app/since-last-visit/keys.ts +26 -0
  22. package/src/app/since-last-visit/model.ts +266 -0
  23. package/src/app/since-last-visit/strip.tsx +193 -0
  24. package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
  25. package/src/app/since-last-visit/visit-tracker.ts +191 -0
  26. package/src/app.tsx +15 -0
  27. package/src/architecture/floating-promise-allowlist.json +0 -1
  28. package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
  29. package/src/cli/commands/market.ts +103 -27
  30. package/src/cli/commands/overview.ts +18 -4
  31. package/src/cli/commands/system.ts +29 -1
  32. package/src/cli/commands/ticker.ts +12 -5
  33. package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
  34. package/src/cli/desktop-pane-shot-browser.ts +2 -1
  35. package/src/cli/desktop-pane-shot-view.ts +3 -7
  36. package/src/cli/desktop-pane-shot.ts +26 -28
  37. package/src/cli/errors.ts +3 -1
  38. package/src/cli/freshness.ts +7 -2
  39. package/src/cli/glossary.ts +10 -5
  40. package/src/cli/help.ts +1 -0
  41. package/src/cli/helpers.ts +8 -16
  42. package/src/cli/history-export.ts +4 -0
  43. package/src/cli/history-rows.ts +24 -0
  44. package/src/cli/index.ts +4 -0
  45. package/src/cli/known-gaps.ts +2 -2
  46. package/src/cli/listing-arg.ts +79 -11
  47. package/src/cli/not-a-ticker.ts +4 -0
  48. package/src/cli/options.ts +29 -1
  49. package/src/cli/pane-functions/catalog.ts +70 -12
  50. package/src/cli/pane-functions/function-help.ts +1 -1
  51. package/src/cli/pane-functions/headless.ts +68 -3
  52. package/src/cli/pane-functions/index.ts +2 -2
  53. package/src/cli/pane-functions/options.ts +7 -0
  54. package/src/cli/pane-functions/resolver.ts +104 -15
  55. package/src/cli/pane-functions/screenshot-payload.ts +3 -0
  56. package/src/cli/report-tables.ts +20 -5
  57. package/src/cli/result.ts +22 -4
  58. package/src/cli/shot-temp-dir.ts +30 -0
  59. package/src/cli/suffixed-listing-rows.ts +11 -0
  60. package/src/cli/symbol-args.ts +5 -3
  61. package/src/cli/symbol-list.ts +23 -10
  62. package/src/cli/symbol-rows.ts +135 -3
  63. package/src/cli/treasury-yields.ts +15 -1
  64. package/src/components/chart/composite/composite-chart.tsx +3 -3
  65. package/src/components/chart/composite/format.ts +2 -1
  66. package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
  67. package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
  68. package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
  69. package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
  70. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
  71. package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
  72. package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
  73. package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
  74. package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
  75. package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
  76. package/src/components/chart/composite/panel-surface/props.ts +79 -0
  77. package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
  78. package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
  79. package/src/components/chart/composite/panel-surface.tsx +81 -1177
  80. package/src/components/command-bar/commands/collection-list.ts +1 -0
  81. package/src/components/command-bar/commands/direct/index.ts +31 -8
  82. package/src/components/command-bar/commands/registry.ts +7 -0
  83. package/src/components/command-bar/routes/root/command-items.ts +8 -0
  84. package/src/components/command-bar/routes/root/results.ts +19 -2
  85. package/src/components/command-bar/routes/root/runtime.ts +3 -2
  86. package/src/components/command-bar/routes/root/selection.ts +3 -2
  87. package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
  88. package/src/components/company-logo.tsx +10 -3
  89. package/src/components/data-table/sections.ts +6 -1
  90. package/src/components/layout/pane/title.ts +16 -6
  91. package/src/components/layout/shell/index.tsx +5 -1
  92. package/src/components/layout/shell/ticker-link-menu.ts +12 -9
  93. package/src/components/pane-settings-dialog/tui.tsx +6 -3
  94. package/src/components/pane-settings-dialog.tsx +2 -1
  95. package/src/components/pane-template-wizard.tsx +2 -0
  96. package/src/components/ticker/badge/format.ts +12 -3
  97. package/src/components/ticker/badge/index.tsx +9 -3
  98. package/src/components/ticker/list-table-view.tsx +119 -17
  99. package/src/components/ui/choice-dialog.tsx +1 -1
  100. package/src/components/ui/confirm-dialog.tsx +3 -2
  101. package/src/components/ui/data-table/display-columns.ts +16 -0
  102. package/src/components/ui/data-table/index.tsx +40 -9
  103. package/src/components/ui/data-table/types.ts +14 -0
  104. package/src/components/ui/frame.tsx +7 -3
  105. package/src/components/ui/icon.tsx +4 -2
  106. package/src/components/ui/list-view.tsx +8 -0
  107. package/src/components/ui/number-prompt-dialog.tsx +2 -1
  108. package/src/components/use-pane-notice-footer.tsx +3 -1
  109. package/src/core/state/app/layout-reducer.ts +3 -1
  110. package/src/core/state/app/layout.ts +2 -2
  111. package/src/data/config/layout.ts +14 -0
  112. package/src/data/config/store/normalize.ts +11 -1
  113. package/src/docs/snapshot.json +2 -2
  114. package/src/i18n/es.ts +39 -0
  115. package/src/i18n/ja.ts +39 -0
  116. package/src/i18n/ko.ts +39 -0
  117. package/src/i18n/zh-cn.ts +39 -0
  118. package/src/i18n/zh-tw.ts +39 -0
  119. package/src/layout/pane-follow.ts +141 -4
  120. package/src/layout/pane-layout-move.ts +10 -7
  121. package/src/layout/ticker-navigation.ts +13 -19
  122. package/src/layout/ticker-retarget.ts +3 -2
  123. package/src/market-data/market/format.ts +35 -1
  124. package/src/market-data/market/index-level.ts +19 -0
  125. package/src/market-data/quotes/contributions.ts +13 -0
  126. package/src/market-data/quotes/export-identity.ts +36 -1
  127. package/src/market-data/quotes/resolution.ts +16 -0
  128. package/src/plugins/builtin/account-management/keyboard.ts +14 -0
  129. package/src/plugins/builtin/account-management/model.ts +2 -0
  130. package/src/plugins/builtin/account-management/pane.tsx +79 -7
  131. package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
  132. package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
  133. package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
  134. package/src/plugins/builtin/analytics/risk-client.ts +12 -2
  135. package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
  136. package/src/plugins/builtin/analytics/risk-math.ts +23 -6
  137. package/src/plugins/builtin/analytics/risk-model.ts +20 -9
  138. package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
  139. package/src/plugins/builtin/awards/pane.tsx +6 -8
  140. package/src/plugins/builtin/changelog/index.tsx +6 -44
  141. package/src/plugins/builtin/changelog/versions.ts +17 -68
  142. package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
  143. package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
  144. package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
  145. package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
  146. package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
  147. package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
  148. package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
  149. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  150. package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
  151. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
  152. package/src/plugins/builtin/cpi/headless.ts +6 -1
  153. package/src/plugins/builtin/cpi/model.ts +17 -0
  154. package/src/plugins/builtin/cpi/pane.tsx +4 -2
  155. package/src/plugins/builtin/crypto-board/client.ts +6 -1
  156. package/src/plugins/builtin/crypto-board/headless.ts +10 -2
  157. package/src/plugins/builtin/crypto-board/model.ts +89 -11
  158. package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
  159. package/src/plugins/builtin/debt-maturities/model.ts +1 -1
  160. package/src/plugins/builtin/dividend-yield/client.ts +24 -2
  161. package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
  162. package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
  163. package/src/plugins/builtin/dividend-yield/view.ts +5 -1
  164. package/src/plugins/builtin/earnings/board-table.ts +1 -1
  165. package/src/plugins/builtin/earnings/board.tsx +36 -16
  166. package/src/plugins/builtin/earnings/highlight.ts +47 -0
  167. package/src/plugins/builtin/earnings/history-table.ts +9 -1
  168. package/src/plugins/builtin/earnings/index.tsx +1 -1
  169. package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
  170. package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
  171. package/src/plugins/builtin/econ/calendar-model.ts +17 -1
  172. package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
  173. package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
  174. package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
  175. package/src/plugins/builtin/exposure/index.tsx +1 -1
  176. package/src/plugins/builtin/macro-day/headless.ts +21 -10
  177. package/src/plugins/builtin/macro-day/model.ts +42 -3
  178. package/src/plugins/builtin/macro-day/pane.tsx +26 -8
  179. package/src/plugins/builtin/macro-day/releases.ts +24 -1
  180. package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
  181. package/src/plugins/builtin/market-valuation/headless.ts +11 -4
  182. package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
  183. package/src/plugins/builtin/market-valuation/view.ts +14 -0
  184. package/src/plugins/builtin/money-markets/client.ts +4 -1
  185. package/src/plugins/builtin/money-markets/headless.ts +15 -4
  186. package/src/plugins/builtin/money-markets/index.tsx +1 -1
  187. package/src/plugins/builtin/money-markets/pane.tsx +7 -1
  188. package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
  189. package/src/plugins/builtin/pe-band/pane.tsx +1 -1
  190. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
  191. package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
  192. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
  193. package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
  194. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +178 -17
  195. package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
  196. package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
  197. package/src/plugins/builtin/portfolio-list/pane/index.tsx +95 -18
  198. package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
  199. package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
  200. package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
  201. package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
  202. package/src/plugins/builtin/portfolio-list/table.tsx +38 -16
  203. package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
  204. package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
  205. package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
  206. package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
  207. package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
  208. package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
  209. package/src/plugins/builtin/shared/headless-options.ts +1 -1
  210. package/src/plugins/builtin/social-mentions/model.ts +2 -2
  211. package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
  212. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
  213. package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
  214. package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
  215. package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
  216. package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
  217. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
  218. package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
  219. package/src/plugins/builtin/ticker-detail/headless.ts +280 -35
  220. package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
  221. package/src/plugins/builtin/ticker-detail/overview/model.ts +9 -2
  222. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
  223. package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
  224. package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
  225. package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
  226. package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
  227. package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
  228. package/src/portfolio/collection-name.ts +2 -1
  229. package/src/portfolio/column-values.ts +34 -12
  230. package/src/portfolio/listed-symbol.ts +4 -2
  231. package/src/portfolio/period-pnl.ts +51 -1
  232. package/src/portfolio/suffixed-listings.ts +3 -1
  233. package/src/portfolio/watchlist-groups.ts +212 -0
  234. package/src/react/ticker-source.ts +3 -1
  235. package/src/renderers/dom/dialog-host.tsx +5 -5
  236. package/src/renderers/dom/styles.css +7 -0
  237. package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
  238. package/src/renderers/opentui/dialog-host.tsx +3 -4
  239. package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
  240. package/src/sources/provider-router/history.ts +5 -2
  241. package/src/state/app/bootstrap.ts +11 -0
  242. package/src/state/app/context/index.tsx +6 -0
  243. package/src/sync/collections-contributor.ts +5 -2
  244. package/src/sync/config-merge.ts +10 -2
  245. package/src/sync/sanitize.ts +28 -0
  246. package/src/telemetry/usage-counts.ts +17 -0
  247. package/src/test-support/plugin-persistence.ts +12 -0
  248. package/src/tickers/company-name-listing.ts +4 -3
  249. package/src/tickers/company-name.ts +19 -1
  250. package/src/tickers/instrument-coverage.ts +27 -0
  251. package/src/tickers/search/home-listing.ts +38 -1
  252. package/src/tickers/search/index.ts +3 -2
  253. package/src/tickers/search/ranking.ts +21 -2
  254. package/src/time-series/base-series.ts +4 -0
  255. package/src/time-series/chart-seed.ts +1 -1
  256. package/src/time-series/financial-period-coverage.ts +4 -12
  257. package/src/time-series/parsed-history-cache.ts +1 -1
  258. package/src/time-series/resolve.ts +1 -1
  259. package/src/time-series/types.ts +5 -2
  260. package/src/time-series/use-chart-resolution.ts +6 -1
  261. package/src/types/config.ts +32 -0
  262. package/src/types/financials.ts +13 -0
  263. package/src/types/headless.ts +7 -0
  264. package/src/types/plugin-context.ts +5 -0
  265. package/src/types/ticker.ts +14 -0
  266. package/src/ui/ascii-font.ts +1 -4
  267. package/src/ui/dialog-stack.ts +17 -0
  268. package/src/ui/dialog.tsx +6 -2
  269. package/src/utils/async-deadline.ts +2 -2
  270. package/src/utils/crypto-pair.ts +9 -0
  271. package/src/utils/csv.ts +44 -5
  272. package/src/utils/exchanges.ts +13 -0
  273. package/src/utils/financial-statements.ts +60 -3
  274. package/src/utils/futures-generic.ts +17 -0
  275. package/src/utils/trailing-dividend.ts +13 -3
@@ -38,6 +38,7 @@ interface CloudPricingTier {
38
38
 
39
39
  /** `/account/cloud`, reduced to the plan fields the apps read. */
40
40
  export interface CloudAccountPlan {
41
+ subscription?: { status: string | null };
41
42
  effectivePlan?: "free" | "pro";
42
43
  /** Whether a checkout started now comes with the free trial attached. */
43
44
  trialAvailable?: boolean;
@@ -45,6 +46,50 @@ export interface CloudAccountPlan {
45
46
  paymentFailed?: boolean;
46
47
  }
47
48
 
49
+ /** Moving a monthly Pro subscription to yearly billing, in integer cents. */
50
+ export interface CloudYearlyOffer {
51
+ currency: "usd";
52
+ monthlyAmount: number;
53
+ yearlyAmount: number;
54
+ /** Twelve monthly payments, and what the yearly price saves on them. */
55
+ twelveMonthlyAmount: number;
56
+ savingsAmount: number;
57
+ }
58
+
59
+ /** Whether this account can switch to yearly billing now. */
60
+ export type CloudYearlyPlanStatus =
61
+ | { state: "unavailable" }
62
+ | { state: "available"; offer: CloudYearlyOffer }
63
+ /** A switch waiting for its payment; `invoiceUrl` is Stripe's hosted invoice. */
64
+ | { state: "pending"; invoiceUrl: string | null; expiresAt: string | null };
65
+
66
+ /** The exact charge of a switch made now, from the billing provider's own preview. */
67
+ export interface CloudYearlyReview {
68
+ /** Confirms this review, and only this one, for a few minutes. */
69
+ token: string;
70
+ expiresAt: string;
71
+ currency: "usd";
72
+ /** Charged today, after any account credit. */
73
+ amountDue: number;
74
+ /** The yearly price from today to the first yearly billing date. */
75
+ yearlyAmount: number;
76
+ /** Credit for the unused part of the month already paid. */
77
+ credit: number;
78
+ tax: number;
79
+ /** Account credit the charge uses up. */
80
+ balanceApplied: number;
81
+ renewalAmount: number;
82
+ renewsAt: string;
83
+ renewalTaxed: boolean;
84
+ offer: CloudYearlyOffer;
85
+ }
86
+
87
+ /** What a confirmed switch came to. Only `switched` is a completed, paid switch. */
88
+ export type CloudYearlyResult =
89
+ | { state: "switched"; amountPaid: number | null; renewalAmount: number; renewsAt: string | null }
90
+ | { state: "payment_required"; invoiceUrl: string | null; expiresAt: string | null }
91
+ | { state: "processing" };
92
+
48
93
  /** Public `/pricing` payload; no session required. */
49
94
  export interface CloudPricing {
50
95
  currency: "usd";
@@ -0,0 +1,132 @@
1
+ import { ApiRequestError } from "./errors";
2
+ import type {
3
+ CloudYearlyOffer,
4
+ CloudYearlyPlanStatus,
5
+ CloudYearlyResult,
6
+ CloudYearlyReview,
7
+ } from "./types/billing";
8
+
9
+ /**
10
+ * The yearly billing switch's answers, checked before anything is shown: an
11
+ * offer whose figures disagree, a review whose lines do not add up to its
12
+ * total, or a link that is not Stripe's own hosted invoice is never shown
13
+ * as it came.
14
+ */
15
+
16
+ function isCents(value: unknown): value is number {
17
+ return typeof value === "number" && Number.isInteger(value) && value >= 0;
18
+ }
19
+
20
+ function record(value: unknown): Record<string, unknown> {
21
+ return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
22
+ }
23
+
24
+ function optionalString(value: unknown): string | null {
25
+ return typeof value === "string" ? value : null;
26
+ }
27
+
28
+ /** Stripe's hosted invoice page, else null. */
29
+ export function hostedInvoiceUrl(value: unknown): string | null {
30
+ if (typeof value !== "string") return null;
31
+ try {
32
+ const url = new URL(value);
33
+ if (url.origin !== "https://invoice.stripe.com" || url.username || url.password) return null;
34
+ return url.href;
35
+ } catch {
36
+ // Intentional ignore: a link that does not parse is never opened.
37
+ return null;
38
+ }
39
+ }
40
+
41
+ export function readYearlyOffer(value: unknown): CloudYearlyOffer | null {
42
+ const offer = record(value);
43
+ if (
44
+ offer.currency !== "usd"
45
+ || !isCents(offer.monthlyAmount)
46
+ || !isCents(offer.yearlyAmount)
47
+ || !isCents(offer.twelveMonthlyAmount)
48
+ || !isCents(offer.savingsAmount)
49
+ || offer.twelveMonthlyAmount !== offer.monthlyAmount * 12
50
+ || offer.savingsAmount !== offer.twelveMonthlyAmount - offer.yearlyAmount
51
+ || offer.savingsAmount <= 0
52
+ ) return null;
53
+ return {
54
+ currency: "usd",
55
+ monthlyAmount: offer.monthlyAmount,
56
+ yearlyAmount: offer.yearlyAmount,
57
+ twelveMonthlyAmount: offer.twelveMonthlyAmount,
58
+ savingsAmount: offer.savingsAmount,
59
+ };
60
+ }
61
+
62
+ export function readYearlyPlanStatus(value: unknown): CloudYearlyPlanStatus {
63
+ const body = record(value);
64
+ if (body.state === "available") {
65
+ const offer = readYearlyOffer(body.offer);
66
+ return offer ? { state: "available", offer } : { state: "unavailable" };
67
+ }
68
+ if (body.state === "pending") {
69
+ return { state: "pending", invoiceUrl: hostedInvoiceUrl(body.invoiceUrl), expiresAt: optionalString(body.expiresAt) };
70
+ }
71
+ return { state: "unavailable" };
72
+ }
73
+
74
+ export function readYearlyReview(value: unknown): CloudYearlyReview | null {
75
+ const review = record(value);
76
+ const offer = readYearlyOffer(review.offer);
77
+ const { amountDue, yearlyAmount, credit, tax, balanceApplied, renewalAmount } = review;
78
+ if (
79
+ !offer
80
+ || typeof review.token !== "string"
81
+ || !review.token
82
+ || typeof review.expiresAt !== "string"
83
+ || typeof review.renewsAt !== "string"
84
+ || !isCents(amountDue)
85
+ || !isCents(yearlyAmount)
86
+ || !isCents(credit)
87
+ || !isCents(tax)
88
+ || !isCents(balanceApplied)
89
+ || !isCents(renewalAmount)
90
+ ) return null;
91
+ // The lines must add up to the total shown, or nothing is shown.
92
+ if (yearlyAmount - credit + tax - balanceApplied !== amountDue) return null;
93
+ return {
94
+ token: review.token,
95
+ expiresAt: review.expiresAt,
96
+ currency: "usd",
97
+ amountDue,
98
+ yearlyAmount,
99
+ credit,
100
+ tax,
101
+ balanceApplied,
102
+ renewalAmount,
103
+ renewsAt: review.renewsAt,
104
+ renewalTaxed: review.renewalTaxed === true,
105
+ offer,
106
+ };
107
+ }
108
+
109
+ /** An answer this app does not know is never read as a switch. */
110
+ export function readYearlyResult(value: unknown): CloudYearlyResult | null {
111
+ const body = record(value);
112
+ if (body.state === "switched") {
113
+ return {
114
+ state: "switched",
115
+ amountPaid: isCents(body.amountPaid) ? body.amountPaid : null,
116
+ renewalAmount: isCents(body.renewalAmount) ? body.renewalAmount : 0,
117
+ renewsAt: optionalString(body.renewsAt),
118
+ };
119
+ }
120
+ if (body.state === "payment_required") {
121
+ return { state: "payment_required", invoiceUrl: hostedInvoiceUrl(body.invoiceUrl), expiresAt: optionalString(body.expiresAt) };
122
+ }
123
+ if (body.state === "processing") return { state: "processing" };
124
+ return null;
125
+ }
126
+
127
+ /** The refusal a switch request came back with (`review_changed`, `busy`, ...), if any. */
128
+ export function yearlyRefusalCode(error: unknown): string | null {
129
+ if (!(error instanceof ApiRequestError)) return null;
130
+ const code = error.details?.code;
131
+ return typeof code === "string" ? code : null;
132
+ }
@@ -18,6 +18,7 @@ import { DOCS_PANE_TEMPLATE_ID } from "../docs/content";
18
18
  import { registerPaneDocsHandler } from "../docs/requests";
19
19
  import { isMoveDownShortcut, isMoveUpShortcut } from "../components/command-bar/keyboard-handlers";
20
20
  import { pressStarPromptKey } from "./star-prompt/runtime";
21
+ import { pressSinceLastVisitKey } from "./since-last-visit/keys";
21
22
  import {
22
23
  copyActiveSelection,
23
24
  isCopyShortcut,
@@ -176,19 +177,20 @@ export function useAppGlobalShortcuts({
176
177
  }
177
178
 
178
179
  // Toasts float above everything, so their keys work over a dialog too.
179
- // The status bar's star line answers the same keys once no toast does,
180
- // but only over the workspace itself.
180
+ // The since-last-visit strip, then the status bar's star line, answer
181
+ // the same keys once no toast does, but only over the workspace itself.
181
182
  if (action === "notification-action" || action === "notification-dismiss") {
182
183
  if (ranAlready(action)) return;
183
184
  const toastHandled = action === "notification-action"
184
185
  ? toastHost.activateNewest?.() === true
185
186
  : toastHost.dismissNewest?.() === true;
187
+ const kind = action === "notification-action" ? "open" : "dismiss";
186
188
  const handled = toastHandled || (
187
189
  !dialogOpen
188
190
  && !state.commandBarOpen
189
191
  && !state.inputCaptured
190
192
  && !isDetachedWindow
191
- && pressStarPromptKey(action === "notification-action" ? "open" : "dismiss")
193
+ && (pressSinceLastVisitKey(kind) || pressStarPromptKey(kind))
192
194
  );
193
195
  if (handled) {
194
196
  event.preventDefault();
@@ -21,7 +21,7 @@ import {
21
21
  type AppState,
22
22
  } from "../../state/app/context";
23
23
  import { scheduleConfigSave } from "../../state/config-save-scheduler";
24
- import { pinFollowingPane } from "../../layout/pane-follow";
24
+ import { pinOrphanedFollower } from "../../layout/pane-follow";
25
25
  import {
26
26
  createPaneInstance,
27
27
  isTickerPaneId,
@@ -91,7 +91,7 @@ export function useAppPaneRuntime({
91
91
  const currentState = stateRef.current;
92
92
  const normalizedLayout = normalizePaneLayout(layout, {
93
93
  resolveOrphanSymbol: (instanceId) => resolveTickerForPane(currentState, instanceId),
94
- pinOrphan: pinFollowingPane,
94
+ pinOrphan: pinOrphanedFollower(currentState.config.layout),
95
95
  externalSourceIds: linkedSourceIds(currentState),
96
96
  });
97
97
  if (options?.pushHistory !== false) {
@@ -42,6 +42,7 @@ import {
42
42
  resolveTickerNavigationReplacementPane,
43
43
  shouldFocusTickerNavigationTarget,
44
44
  } from "../../layout/ticker-navigation";
45
+ import { userUnlinkedFrom } from "../../layout/pane-follow";
45
46
  import {
46
47
  resolveTickerForPane,
47
48
  type AppAction,
@@ -367,11 +368,12 @@ export function bindAppPanePluginRegistry({
367
368
  ...(instrument !== undefined ? { instrument } : {}),
368
369
  ...(target.listing ? { listing: target.listing } : {}),
369
370
  };
371
+ const unlinkedFrom = userUnlinkedFrom(detailPane, currentLayout);
370
372
  const nextLayout = {
371
373
  ...currentLayout,
372
374
  instances: currentLayout.instances.map((instance) => (
373
375
  instance.instanceId === detailPane.instanceId
374
- ? { ...instance, title: tickerInstrumentLabel(symbol, instrument), binding }
376
+ ? { ...instance, title: tickerInstrumentLabel(symbol, instrument), binding, ...(unlinkedFrom ? { unlinkedFrom } : {}) }
375
377
  : instance
376
378
  )),
377
379
  };
@@ -132,6 +132,11 @@ function findTargetPane(
132
132
  ], symbol);
133
133
  }) ?? null;
134
134
  }
135
+ // Enter on a list row with no research pane of its own shows the ticker in a pinned one.
136
+ if (!existing && options?.reusePaneId) {
137
+ const reuse = findPaneInstance(layout, options.reusePaneId);
138
+ if (reuse?.paneId === paneType && reuse.binding?.kind === "fixed" && isPaneInLayout(layout, reuse.instanceId)) existing = reuse;
139
+ }
135
140
  return { existing, keepBinding };
136
141
  }
137
142
 
@@ -300,7 +305,7 @@ export function useAppTickerOpenRuntime({
300
305
  const paneType = normalizePaneId(options?.paneType ?? TICKER_RESEARCH_PANE_ID);
301
306
  const paneDef = pluginRegistry.panes.get(paneType);
302
307
  const symbol = normalizeTickerInput(null, rawSymbol);
303
- if (paneType !== TICKER_RESEARCH_PANE_ID || !paneDef || !symbol || options?.instrument) return null;
308
+ if (paneType !== TICKER_RESEARCH_PANE_ID || !paneDef || !symbol || options?.instrument || options?.reusePaneId) return null;
304
309
  const state = stateRef.current;
305
310
  const layout = state.config.layout;
306
311
  if (savedTickerForQuery(rawSymbol, state.tickers)) return null;
@@ -0,0 +1,26 @@
1
+ interface SinceLastVisitKeyHandlers {
2
+ open(): void;
3
+ dismiss(): void;
4
+ }
5
+
6
+ /** What the notification keys do while the strip shows; null otherwise. */
7
+ let keyHandlers: SinceLastVisitKeyHandlers | null = null;
8
+
9
+ /** Hands the notification keys to the strip while it shows; returns the release. */
10
+ export function bindSinceLastVisitKeys(handlers: SinceLastVisitKeyHandlers): () => void {
11
+ keyHandlers = handlers;
12
+ return () => {
13
+ if (keyHandlers === handlers) keyHandlers = null;
14
+ };
15
+ }
16
+
17
+ /**
18
+ * Runs the strip's open (its biggest move) or hide for the notification keys.
19
+ * False when the strip is not showing, so the key goes on to whatever else wants it.
20
+ */
21
+ export function pressSinceLastVisitKey(kind: "open" | "dismiss"): boolean {
22
+ if (!keyHandlers) return false;
23
+ if (kind === "open") keyHandlers.open();
24
+ else keyHandlers.dismiss();
25
+ return true;
26
+ }
@@ -0,0 +1,266 @@
1
+ import { instrumentFromTicker, type InstrumentRef } from "../../market-data/request-types";
2
+ import { hasValidQuoteObservationTime, isQuoteStaleForCurrentSession } from "../../market-data/quotes/freshness";
3
+ import { savedCopyAt } from "../../data/saved-copies";
4
+ import type { AppConfig } from "../../types/config";
5
+ import type { Quote } from "../../types/financials";
6
+ import type { TickerRecord } from "../../types/ticker";
7
+ import { formatClockTime, formatShortDate } from "../../utils/datetime-format";
8
+ import { canonicalExchange } from "../../utils/exchanges";
9
+ import { instrumentIdentityKey } from "../../utils/instrument-identity";
10
+ import { isRecord } from "../../utils/guards";
11
+
12
+ /**
13
+ * What moved in the user's own tickers since their last visit. A visit keeps
14
+ * the last price it had of each listing in the user's portfolios and
15
+ * watchlists; the next visit compares the price it has now with that one.
16
+ * A move is only ever the difference between two prices of the same listing,
17
+ * in the same currency and on the same basis, the newer printed after the
18
+ * older; a listing with no such pair has no move, never a zero.
19
+ */
20
+
21
+ /** Listings a visit keeps, portfolios first: one batch of quotes, and a small row in the state store. */
22
+ const MAX_TRACKED_LISTINGS = 50;
23
+ /** Less time away than this is the same visit (a restart, an update). */
24
+ export const MIN_AWAY_MS = 60 * 60_000;
25
+ /** The smallest move, in percent either way, the strip names. */
26
+ const MIN_MOVE_PERCENT = 1;
27
+ /** The most moves the strip names; a narrow window shows fewer. */
28
+ const MAX_STRIP_MOVES = 5;
29
+
30
+ /** One price of a listing, as a visit keeps it for the next one. */
31
+ export interface VisitObservation {
32
+ /** The key the ticker is saved under (`TickerMetadata.ticker`). */
33
+ symbol: string;
34
+ price: number;
35
+ currency: string;
36
+ /** What the price counts: `per-unit`, `percent-of-par`, `points`, `thirty-seconds`, or a fund's `nav`. */
37
+ basis: string;
38
+ /** The listing's venue as the quote named it, canonical; empty when it named none. */
39
+ venue: string;
40
+ /** When the source printed the price (the quote's `lastUpdated`), epoch ms. */
41
+ at: number;
42
+ /** The quote came from the session a split took effect in, so a price from before it is on another share basis. */
43
+ split?: true;
44
+ }
45
+
46
+ /** What a visit leaves for the next one. */
47
+ export interface VisitBaseline {
48
+ /** The account the prices were seen under (`visitScope`): another account never reads them. */
49
+ scope: string;
50
+ /** The last moment the user was in the app with these prices. */
51
+ seenAt: number;
52
+ /** By listing (`instrumentIdentityKey`). */
53
+ observations: Record<string, VisitObservation>;
54
+ }
55
+
56
+ export interface VisitMove {
57
+ /** The listing (`instrumentIdentityKey`). */
58
+ key: string;
59
+ symbol: string;
60
+ /** Percent from the last visit's price to the current one, when the recap was made. */
61
+ percent: number;
62
+ /** The last visit's price, which the move keeps being measured from. */
63
+ before: VisitObservation;
64
+ }
65
+
66
+ /** The return recap: the moves since `seenAt`, biggest first. */
67
+ export interface VisitRecap {
68
+ seenAt: number;
69
+ moves: VisitMove[];
70
+ }
71
+
72
+ export interface TrackedListing {
73
+ key: string;
74
+ symbol: string;
75
+ instrument: InstrumentRef;
76
+ }
77
+
78
+ /** Whose prices a visit keeps: the signed-in account, or this device signed out. */
79
+ export function visitScope(accountId: string | null | undefined): string {
80
+ return accountId ? `account:${accountId}` : "local";
81
+ }
82
+
83
+ /** Option contracts move by tens of percent on a quiet day; the strip is about tickers. */
84
+ const OPTION_CATEGORIES = new Set(["OPT", "FOP"]);
85
+
86
+ /**
87
+ * The listings in the user's own portfolios and watchlists, holdings first,
88
+ * at most `limit`. Collections shared with a team (the server keeps their
89
+ * rows) and portfolios imported from someone else's filing are not the
90
+ * user's own and are left out, as is a ticker whose listing is ambiguous.
91
+ */
92
+ export function trackedListings(
93
+ config: Pick<AppConfig, "portfolios" | "watchlists">,
94
+ tickers: ReadonlyMap<string, TickerRecord>,
95
+ limit = MAX_TRACKED_LISTINGS,
96
+ ): TrackedListing[] {
97
+ const portfolios = new Set(config.portfolios.filter((entry) => !entry.teamId && !entry.importedFrom).map((entry) => entry.id));
98
+ const watchlists = new Set(config.watchlists.filter((entry) => !entry.teamId).map((entry) => entry.id));
99
+ const held: TrackedListing[] = [];
100
+ const watched: TrackedListing[] = [];
101
+ const seen = new Set<string>();
102
+ for (const [symbol, ticker] of tickers) {
103
+ const metadata = ticker.metadata;
104
+ if (OPTION_CATEGORIES.has(metadata.assetCategory?.toUpperCase() ?? "")) continue;
105
+ const inPortfolio = metadata.portfolios.some((id) => portfolios.has(id));
106
+ const inWatchlist = metadata.watchlists.some((id) => watchlists.has(id));
107
+ if (!inPortfolio && !inWatchlist) continue;
108
+ const instrument = instrumentFromTicker(ticker, symbol);
109
+ if (!instrument) continue;
110
+ const key = instrumentIdentityKey(instrument);
111
+ if (seen.has(key)) continue;
112
+ seen.add(key);
113
+ (inPortfolio ? held : watched).push({ key, symbol, instrument });
114
+ }
115
+ return [...held, ...watched].slice(0, Math.max(0, limit));
116
+ }
117
+
118
+ /**
119
+ * A quote as a price the user can be said to have seen, or null when it is
120
+ * not one: no positive price or currency, no valid print time, stale for its
121
+ * market's current session, answered from a saved copy after a refresh
122
+ * failed, a nominal price nothing traded at, or a line that stopped trading.
123
+ */
124
+ export function observeQuote(symbol: string, quote: Quote | null | undefined, now: number): VisitObservation | null {
125
+ if (!quote) return null;
126
+ if (!Number.isFinite(quote.price) || quote.price <= 0) return null;
127
+ if (typeof quote.currency !== "string" || !quote.currency.trim()) return null;
128
+ if (!hasValidQuoteObservationTime(quote, now)) return null;
129
+ if (quote.nominalPrice || quote.delisting || savedCopyAt(quote) != null) return null;
130
+ if (isQuoteStaleForCurrentSession(quote, now)) return null;
131
+ return {
132
+ symbol,
133
+ price: quote.price,
134
+ currency: quote.currency.trim(),
135
+ basis: quote.priceObservation === "nav" ? "nav" : quote.priceBasis ?? "per-unit",
136
+ venue: canonicalExchange(quote.listingExchangeName || quote.exchangeName || ""),
137
+ at: quote.lastUpdated,
138
+ ...(quote.sessionSplit ? { split: true as const } : {}),
139
+ };
140
+ }
141
+
142
+ /**
143
+ * Share counts a split multiplies by: a price that moved by one of these
144
+ * (or its inverse, a reverse split) cannot be told from a split, and a move
145
+ * that is a split was never made.
146
+ */
147
+ const SPLIT_FACTORS = [2, 3, 4, 5, 6, 7, 8, 10, 12, 15, 20, 25, 30, 40, 50, 100, 1.5];
148
+ const SPLIT_TOLERANCE = 0.01;
149
+
150
+ function looksLikeSplit(ratio: number): boolean {
151
+ return SPLIT_FACTORS.some((factor) => (
152
+ Math.abs(ratio * factor - 1) <= SPLIT_TOLERANCE || Math.abs(ratio / factor - 1) <= SPLIT_TOLERANCE
153
+ ));
154
+ }
155
+
156
+ /**
157
+ * Percent from `before` to `after`, or null when the two are not two prices
158
+ * of one listing that can be compared: another ticker, currency, basis or
159
+ * venue, a print no newer than the one before, either side in a split's
160
+ * session, or a ratio a split would give.
161
+ */
162
+ export function moveSince(before: VisitObservation, after: VisitObservation): number | null {
163
+ if (before.symbol !== after.symbol || before.currency !== after.currency
164
+ || before.basis !== after.basis || before.venue !== after.venue) return null;
165
+ if (before.split || after.split) return null;
166
+ if (!(after.at > before.at)) return null;
167
+ if (!(before.price > 0) || !(after.price > 0)) return null;
168
+ const ratio = after.price / before.price;
169
+ if (!Number.isFinite(ratio) || looksLikeSplit(ratio)) return null;
170
+ return (ratio - 1) * 100;
171
+ }
172
+
173
+ /**
174
+ * The moves since `baseline` for the listings still tracked, from the
175
+ * prices on hand now (`current`, by listing): the ones of at least
176
+ * `minPercent` either way, biggest first, at most `limit`. Null when
177
+ * there is no baseline, the user was away less than `minAwayMs`, or
178
+ * nothing moved enough; the strip then does not show.
179
+ */
180
+ export function recapSince(
181
+ baseline: VisitBaseline | null,
182
+ tracked: readonly TrackedListing[],
183
+ current: ReadonlyMap<string, VisitObservation>,
184
+ now: number,
185
+ { minAwayMs = MIN_AWAY_MS, minPercent = MIN_MOVE_PERCENT, limit = MAX_STRIP_MOVES } = {},
186
+ ): VisitRecap | null {
187
+ if (!baseline || !(now - baseline.seenAt >= minAwayMs)) return null;
188
+ const moves: VisitMove[] = [];
189
+ for (const listing of tracked) {
190
+ const before = baseline.observations[listing.key];
191
+ const after = current.get(listing.key);
192
+ if (!before || !after) continue;
193
+ const percent = moveSince(before, after);
194
+ if (percent == null || !(Math.abs(percent) >= minPercent)) continue;
195
+ moves.push({ key: listing.key, symbol: listing.symbol, percent, before });
196
+ }
197
+ if (moves.length === 0) return null;
198
+ moves.sort((left, right) => Math.abs(right.percent) - Math.abs(left.percent) || left.symbol.localeCompare(right.symbol));
199
+ return { seenAt: baseline.seenAt, moves: moves.slice(0, Math.max(0, limit)) };
200
+ }
201
+
202
+ /**
203
+ * A recap's move as of now, so a strip left up for hours keeps saying what
204
+ * is true rather than a number from its first second: measured again from
205
+ * the last visit's price to the quote on hand, or as it was when the recap
206
+ * was made while no current price is on hand (a stale or missing quote).
207
+ * Null once the quote on hand is a price the last one no longer compares
208
+ * with (another currency, a split): the move is not shown at all.
209
+ */
210
+ export function liveMovePercent(move: VisitMove, quote: Quote | null | undefined, now: number): number | null {
211
+ const after = observeQuote(move.symbol, quote, now);
212
+ return after ? moveSince(move.before, after) : move.percent;
213
+ }
214
+
215
+ const WEEKDAY = new Intl.DateTimeFormat("en-US", { weekday: "short" });
216
+ const DAY_MS = 24 * 60 * 60_000;
217
+
218
+ function localDayStart(time: number): number {
219
+ const date = new Date(time);
220
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
221
+ }
222
+
223
+ /**
224
+ * When the last visit was, as the strip dates its moves, in local time on
225
+ * the 24-hour clock: `09:30` earlier today, `yesterday 16:05`, `Wed 16:05`
226
+ * within the week, then the day (`4 Nov`, `4 Nov 2025` in another year).
227
+ */
228
+ export function formatVisitTime(seenAt: number, now: number): string {
229
+ const days = Math.round((localDayStart(now) - localDayStart(seenAt)) / DAY_MS);
230
+ const clock = formatClockTime(seenAt);
231
+ if (days <= 0) return clock;
232
+ if (days === 1) return `yesterday ${clock}`;
233
+ if (days < 7) return `${WEEKDAY.format(new Date(seenAt))} ${clock}`;
234
+ const sameYear = new Date(seenAt).getFullYear() === new Date(now).getFullYear();
235
+ return formatShortDate(seenAt, { year: sameYear ? false : "numeric" });
236
+ }
237
+
238
+ /** The most observations a stored baseline is read with, whatever it holds. */
239
+ const MAX_STORED_OBSERVATIONS = MAX_TRACKED_LISTINGS * 2;
240
+
241
+ function readObservation(value: unknown): VisitObservation | null {
242
+ if (!isRecord(value)) return null;
243
+ const { symbol, price, currency, basis, venue, at, split } = value;
244
+ if (typeof symbol !== "string" || !symbol || typeof currency !== "string" || !currency
245
+ || typeof basis !== "string" || !basis || typeof venue !== "string") return null;
246
+ if (typeof price !== "number" || !Number.isFinite(price) || price <= 0) return null;
247
+ if (typeof at !== "number" || !Number.isFinite(at) || at <= 0) return null;
248
+ return { symbol, price, currency, basis, venue, at, ...(split === true ? { split: true as const } : {}) };
249
+ }
250
+
251
+ /** A stored baseline as this build reads it: null unless it is whole and belongs to `scope`. */
252
+ export function readVisitBaseline(value: unknown, scope: string): VisitBaseline | null {
253
+ if (!isRecord(value) || value.scope !== scope || !isRecord(value.observations)) return null;
254
+ const seenAt = value.seenAt;
255
+ if (typeof seenAt !== "number" || !Number.isFinite(seenAt) || seenAt <= 0) return null;
256
+ const observations: Record<string, VisitObservation> = {};
257
+ let count = 0;
258
+ for (const [key, entry] of Object.entries(value.observations)) {
259
+ if (count >= MAX_STORED_OBSERVATIONS) break;
260
+ const observation = readObservation(entry);
261
+ if (!key || !observation) continue;
262
+ observations[key] = observation;
263
+ count += 1;
264
+ }
265
+ return { scope, seenAt, observations };
266
+ }