@orangecharts/wrun-chart-host 0.10.0 → 0.11.1

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 (152) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/feature-flags.constants.d.ts +9 -0
  3. package/dist/constants/feature-flags.constants.js +67 -4
  4. package/dist/constants/governed-exchanges.constants.d.ts +12 -0
  5. package/dist/constants/governed-exchanges.constants.js +16 -0
  6. package/dist/constants/option-venues.constants.d.ts +2 -2
  7. package/dist/host-env.d.ts +1 -9
  8. package/dist/host-ports.types.d.ts +36 -7
  9. package/dist/index.d.ts +7 -1
  10. package/dist/index.js +7 -1
  11. package/dist/indicators/controls/tpo-session.util.d.ts +36 -13
  12. package/dist/indicators/controls/tpo-session.util.js +217 -236
  13. package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
  14. package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
  15. package/dist/interfaces/cme-realtime.interface.js +6 -3
  16. package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
  17. package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
  18. package/dist/interfaces/prediction-market.interface.d.ts +7 -0
  19. package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
  20. package/dist/interfaces/stocks-realtime.interface.js +32 -0
  21. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +48 -117
  22. package/dist/kscript-data/controls/live-trades-merge.util.js +97 -207
  23. package/dist/market-data/billing.interface.d.ts +86 -12
  24. package/dist/market-data/billing.interface.js +23 -4
  25. package/dist/market-data/venue.d.ts +65 -2
  26. package/dist/market-data/venues/index.d.ts +135 -5
  27. package/dist/market-data/venues/index.js +2 -1
  28. package/dist/market-data/venues/opra.contract.copy.json +3 -2
  29. package/dist/market-data/venues/opra.d.ts +2 -2
  30. package/dist/market-data/venues/opra.js +5 -2
  31. package/dist/market-data/venues/stocks.contract.copy.json +64 -0
  32. package/dist/market-data/venues/stocks.d.ts +130 -0
  33. package/dist/market-data/venues/stocks.js +117 -0
  34. package/dist/settings-templates/footprint-rows.js +35 -2
  35. package/dist/settings-templates/form-rows.d.ts +2 -1
  36. package/dist/settings-templates/indicator-fields.js +34 -4
  37. package/dist/settings-templates/tool-rules.d.ts +12 -5
  38. package/dist/settings-templates/tool-rules.js +11 -5
  39. package/dist/settings-templates/tool-tables.generated.js +4 -0
  40. package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
  41. package/dist/utility/chart/cme-cache-context.util.js +10 -6
  42. package/dist/utility/chart/cme-realtime.util.js +10 -0
  43. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
  44. package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
  45. package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
  46. package/dist/utility/chart/effective-chart-session.util.js +39 -0
  47. package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
  48. package/dist/utility/chart/host-bar-placement.util.js +170 -30
  49. package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
  50. package/dist/utility/chart/index-host-tier.util.js +7 -2
  51. package/dist/utility/chart/index-mode-admission.util.js +25 -11
  52. package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
  53. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +6 -9
  54. package/dist/utility/chart/kscript-live-coalesce.util.js +8 -9
  55. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
  56. package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
  57. package/dist/utility/chart/kscript-provenance-keys.util.js +7 -0
  58. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
  59. package/dist/utility/chart/kscript-venue-policy.util.d.ts +115 -21
  60. package/dist/utility/chart/kscript-venue-policy.util.js +194 -40
  61. package/dist/utility/chart/live-bucket.util.d.ts +24 -8
  62. package/dist/utility/chart/live-bucket.util.js +85 -27
  63. package/dist/utility/chart/market-sessions.util.d.ts +83 -0
  64. package/dist/utility/chart/market-sessions.util.js +220 -0
  65. package/dist/utility/chart/marketKind.util.js +5 -0
  66. package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
  67. package/dist/utility/chart/mixed-mode.util.js +14 -0
  68. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
  69. package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
  70. package/dist/utility/chart/rth-session.util.d.ts +9 -8
  71. package/dist/utility/chart/rth-session.util.js +23 -20
  72. package/dist/utility/chart/session-interval.util.d.ts +2 -1
  73. package/dist/utility/chart/session-interval.util.js +1 -3
  74. package/dist/utility/chart/trading-day.util.d.ts +17 -0
  75. package/dist/utility/chart/trading-day.util.js +59 -0
  76. package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
  77. package/dist/utility/chart/window-owner.leaf.js +45 -3
  78. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
  79. package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
  80. package/dist/utility/intl-locale.util.js +5 -0
  81. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
  82. package/dist/utility/v2/gate-plane.util.d.ts +12 -3
  83. package/dist/utility/v2/gate-plane.util.js +30 -4
  84. package/dist/utility/v2/gate-session-latch.util.js +1 -1
  85. package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
  86. package/dist/utility/v2/stocks-governed.util.js +34 -0
  87. package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
  88. package/dist/utility/wrun/derived-roots.leaf.js +27 -0
  89. package/dist/utility/wrun/derived-roots.util.d.ts +1 -9
  90. package/dist/utility/wrun/derived-roots.util.js +3 -23
  91. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +4 -3
  92. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
  93. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
  94. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +2 -0
  95. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +63 -16
  96. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +58 -14
  97. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +34 -11
  98. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +106 -30
  99. package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
  100. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +7 -4
  101. package/dist/utility/wrun/wrun-chart-market-facts.util.js +12 -8
  102. package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
  103. package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
  104. package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
  105. package/dist/utility/wrun/wrun-handles.util.js +9 -8
  106. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
  107. package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
  108. package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
  109. package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
  110. package/dist/utility/wrun/wrun-live-intake.util.d.ts +26 -12
  111. package/dist/utility/wrun/wrun-live-intake.util.js +219 -155
  112. package/dist/utility/wrun/wrun-live-tick.util.d.ts +9 -5
  113. package/dist/utility/wrun/wrun-live-tick.util.js +130 -94
  114. package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
  115. package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
  116. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +20 -10
  117. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +10 -5
  118. package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
  119. package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
  120. package/dist/utility/wrun/wrun-option-views.util.d.ts +281 -20
  121. package/dist/utility/wrun/wrun-option-views.util.js +391 -50
  122. package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
  123. package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
  124. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +15 -2
  125. package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
  126. package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
  127. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +60 -11
  128. package/dist/utility/wrun/wrun-overlay-run.util.js +529 -113
  129. package/dist/utility/wrun/wrun-panel-mount.util.js +51 -6
  130. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
  131. package/dist/utility/wrun/wrun-pin-spelling.util.js +27 -3
  132. package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
  133. package/dist/utility/wrun/wrun-refusal.util.js +22 -0
  134. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
  135. package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
  136. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
  137. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
  138. package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
  139. package/dist/utility/wrun/wrun-run-interval.util.d.ts +39 -7
  140. package/dist/utility/wrun/wrun-run-interval.util.js +49 -9
  141. package/dist/utility/wrun/wrun-socket-row-source.js +7 -2
  142. package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -22
  143. package/dist/utility/wrun/wrun-source-rows.util.js +62 -41
  144. package/dist/utility/wrun/wrun-tape-per-order.util.js +1 -20
  145. package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
  146. package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
  147. package/dist/utility/wrun/wrun-volume-profile.util.js +37 -29
  148. package/dist/workers/constants/socket-slots.d.ts +91 -6
  149. package/dist/workers/constants/socket-slots.js +85 -6
  150. package/package.json +5 -5
  151. package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +0 -56
  152. package/dist/kscript-data/controls/live-trades-order-gate.util.js +0 -107
@@ -1,26 +1,48 @@
1
- import dayjs from 'dayjs';
2
- import isoWeek from 'dayjs/plugin/isoWeek.js';
3
- import timezone from 'dayjs/plugin/timezone.js';
4
- import utc from 'dayjs/plugin/utc.js';
5
- import { zoneWallMsAt, zoneWallToUtcMs } from '../../utility/chart/ny-calendar.util.js';
1
+ import { MARKET_SESSION_SPLIT, marketSessionInstantsOn, marketSessionNamed, sessionClockText, zoneWallEdgeToUtcMs, } from '../../utility/chart/market-sessions.util.js';
2
+ import { NY_TIME_ZONE, zoneOffsetMsAt, zoneWallMsAt } from '../../utility/chart/ny-calendar.util.js';
6
3
  import { getTradingDayAnchor, getTradingDayTpoTimeRange } from '../../utility/chart/trading-day.util.js';
7
- dayjs.extend(utc);
8
- dayjs.extend(isoWeek);
9
- dayjs.extend(timezone);
10
- export const TPO_TRADING_HOUR_TIME_RANGES = {
11
- 'Pre-Market': { start_time: '04:00', end_time: '09:30', timezone: 'ET' },
12
- Regular: { start_time: '09:30', end_time: '16:00', timezone: 'ET' },
13
- 'Post-Market': { start_time: '16:00', end_time: '20:00', timezone: 'ET' },
14
- Asia: { start_time: '00:00', end_time: '06:00', timezone: 'UTC' },
15
- 'Asia Full': { start_time: '00:00', end_time: '09:00', timezone: 'UTC' },
16
- London: { start_time: '06:00', end_time: '12:00', timezone: 'UTC' },
17
- 'London Full': { start_time: '08:00', end_time: '17:00', timezone: 'UTC' },
18
- 'New York': { start_time: '12:00', end_time: '20:00', timezone: 'UTC' },
19
- 'New York Full': { start_time: '08:00', end_time: '17:00', timezone: 'ET' },
20
- 'Pre-Close': { start_time: '20:00', end_time: '00:00', timezone: 'UTC' },
21
- 'All Hours': { start_time: '00:00', end_time: '00:00', timezone: 'UTC' },
22
- Custom: { start_time: '00:00', end_time: '00:00', timezone: 'UTC' },
23
- };
4
+ /** A gateway TradingHour session's row: its hours on the gateway's own clock, its weeks and months on UTC. */
5
+ function gatewaySessionRange(start_time, end_time, timezone) {
6
+ return Object.freeze({ start_time, end_time, timezone, periodCalendar: 'UTC' });
7
+ }
8
+ /** The presets that are market sessions: hours from market-sessions.util, sent as a range, never a fixed-UTC enum. */
9
+ export const TPO_MARKET_SESSION_PRESETS = Object.freeze([
10
+ 'Asia',
11
+ 'Asia Full',
12
+ 'London',
13
+ 'London Full',
14
+ 'New York',
15
+ 'New York Full',
16
+ ]);
17
+ /** The zone a range names on the wire: New York as 'ET' (the gateway keys it apart from 'America/New_York'). */
18
+ function tpoWireTimezone(timeZone) {
19
+ return timeZone === NY_TIME_ZONE ? 'ET' : timeZone;
20
+ }
21
+ /** A market session preset's daily window, read from the shared session table, never written here. */
22
+ function marketSessionRange(name) {
23
+ const session = marketSessionNamed(name);
24
+ if (!session)
25
+ throw new Error(`TPO preset ${name} is not a market session`);
26
+ return Object.freeze({
27
+ start_time: sessionClockText(session.openMinutes),
28
+ end_time: sessionClockText(session.closeMinutes),
29
+ timezone: tpoWireTimezone(session.timeZone),
30
+ });
31
+ }
32
+ /** Every choice's daily window: the gateway's own sessions (BuildWhereTradingHour serves these rows), the markets'. */
33
+ export const TPO_TRADING_HOUR_TIME_RANGES = Object.freeze({
34
+ 'Pre-Market': gatewaySessionRange('04:00', '09:30', 'ET'),
35
+ Regular: gatewaySessionRange('09:30', '16:00', 'ET'),
36
+ 'Post-Market': gatewaySessionRange('16:00', '20:00', 'ET'),
37
+ ...Object.fromEntries(TPO_MARKET_SESSION_PRESETS.map((name) => [name, marketSessionRange(name)])),
38
+ 'Pre-Close': gatewaySessionRange('20:00', '00:00', 'UTC'),
39
+ 'All Hours': Object.freeze({ start_time: '00:00', end_time: '00:00', timezone: 'UTC' }),
40
+ Custom: Object.freeze({ start_time: '00:00', end_time: '00:00', timezone: 'UTC' }),
41
+ });
42
+ /** A range's wall times and clock alone, as the wire and the cache key carry it. */
43
+ export function tpoWireTimeRange(range) {
44
+ return { start_time: range.start_time, end_time: range.end_time, timezone: range.timezone };
45
+ }
24
46
  function parseTpoTimeToMinutes(value) {
25
47
  const match = String(value ?? '').match(/^(\d{1,2}):(\d{2})$/);
26
48
  if (!match)
@@ -42,10 +64,11 @@ function isTpoCrossDay(customTimeRange) {
42
64
  return false;
43
65
  return startMinutes >= endMinutes;
44
66
  }
45
- function getTpoCrossDayOffset(customTimeRange) {
67
+ /** Minutes past local midnight a period's first day opens at: a range crossing midnight keeps its spill-over night. */
68
+ function getTpoCrossDayOffsetMinutes(customTimeRange) {
46
69
  if (!customTimeRange || !isTpoCrossDay(customTimeRange))
47
70
  return 0;
48
- return (parseTpoTimeToMinutes(customTimeRange.end_time) ?? 0) * 60;
71
+ return parseTpoTimeToMinutes(customTimeRange.end_time) ?? 0;
49
72
  }
50
73
  /**
51
74
  * The venue anchor these settings run on. It is venue knowledge, never
@@ -79,175 +102,173 @@ export function resolveTradingDayTpoTimeRange(settings) {
79
102
  return undefined;
80
103
  return getTradingDayTpoTimeRange(resolveTpoTradingDayAnchor(settings));
81
104
  }
82
- /**
83
- * Precedence: explicit custom range, then the trading-day anchored range
84
- * (which itself yields to non-'All Hours' trading hours and custom
85
- * sessions), then the trading-hour preset table.
86
- */
87
- export function resolveTpoSettingsTimeRange(settings) {
88
- if (settings.customTimeRange)
89
- return settings.customTimeRange;
90
- const anchored = resolveTradingDayTpoTimeRange(settings);
91
- if (anchored)
92
- return anchored;
93
- const tradingHour = typeof settings.tradingHour === 'string' ? settings.tradingHour : undefined;
94
- if (!tradingHour)
95
- return undefined;
96
- return TPO_TRADING_HOUR_TIME_RANGES[tradingHour];
97
- }
98
- function timezoneName(value) {
99
- const raw = String(value || 'UTC');
100
- if (raw.toUpperCase() === 'ET')
101
- return 'America/New_York';
102
- return raw || 'UTC';
105
+ /** The trading-hour choice the settings hold: no choice is All Hours, as every TPO payload sends it. */
106
+ export function tpoTradingHourOf(settings) {
107
+ const tradingHour = settings?.tradingHour;
108
+ return typeof tradingHour === 'string' && tradingHour ? tradingHour : 'All Hours';
103
109
  }
104
- function unixInTimeZone(timestamp, zone) {
105
- try {
106
- return dayjs.unix(timestamp).tz(zone);
107
- }
108
- catch {
109
- return dayjs.unix(timestamp).utc();
110
+ /** A choice's window, venue day aside: a preset's table row (never the range saved beside it), else the saved range. */
111
+ export function tpoTradingHourTimeRange(tradingHour, savedRange) {
112
+ if (tradingHour !== 'Custom' && Object.prototype.hasOwnProperty.call(TPO_TRADING_HOUR_TIME_RANGES, tradingHour)) {
113
+ return TPO_TRADING_HOUR_TIME_RANGES[tradingHour];
110
114
  }
115
+ return savedRange && typeof savedRange === 'object' ? savedRange : undefined;
111
116
  }
112
- const zonedDayByZone = new Map();
113
- function zonedDayFor(timestamp, zone) {
114
- const cached = zonedDayByZone.get(zone);
115
- if (cached && timestamp >= cached.startUnix && timestamp < cached.endUnix)
116
- return cached;
117
- const dayStart = unixInTimeZone(timestamp, zone).startOf('day');
118
- const fresh = { dayStart, startUnix: dayStart.unix(), endUnix: dayStart.add(1, 'day').unix() };
119
- zonedDayByZone.set(zone, fresh);
120
- return fresh;
121
- }
122
- const WALL_TIME_MEMO_CAP = 512;
123
- const wallTimeUnixMemo = new Map();
124
- /**
125
- * The instant whose wall clock in `zone` reads `minutes` past midnight on
126
- * the calendar date `dayKey` ('YYYY-MM-DD'). Parsing the wall string with
127
- * dayjs.tz is DST-exact: `startOf('day').add(minutes, 'minute')` counts REAL
128
- * minutes, which drifts by the offset delta on 23h/25h transition days. For
129
- * UTC zones both agree.
130
- */
131
- function wallTimeOnDay(dayKey, minutes, zone) {
132
- const hours = String(Math.floor(minutes / 60)).padStart(2, '0');
133
- const mins = String(minutes % 60).padStart(2, '0');
134
- const wall = `${dayKey} ${hours}:${mins}`;
135
- try {
136
- return dayjs.tz(wall, zone);
137
- }
138
- catch {
139
- return dayjs.utc(wall);
140
- }
117
+ /** The one window a TPO cuts its sessions to, for every reader: a saved range beside a preset holds its old hours. */
118
+ export function resolveTpoSettingsTimeRange(settings, options = {}) {
119
+ const tradingHour = tpoTradingHourOf(settings);
120
+ if (tradingHour !== 'All Hours')
121
+ return tpoTradingHourTimeRange(tradingHour, settings.customTimeRange);
122
+ return options.venueTradingDay === false ? undefined : resolveTradingDayTpoTimeRange(settings);
141
123
  }
142
- /** `wallTimeOnDay(...).unix()`, memoised per (day, minutes, zone): the same few wall times are asked every tick. */
143
- function wallTimeUnixOnDay(dayKey, minutes, zone) {
144
- const key = `${dayKey}|${minutes}|${zone}`;
145
- const hit = wallTimeUnixMemo.get(key);
146
- if (hit !== undefined)
147
- return hit;
148
- const value = wallTimeOnDay(dayKey, minutes, zone).unix();
149
- if (wallTimeUnixMemo.size >= WALL_TIME_MEMO_CAP)
150
- wallTimeUnixMemo.clear();
151
- wallTimeUnixMemo.set(key, value);
152
- return value;
124
+ /** The IANA zone a range's clock names: 'ET' is New York, nothing is UTC. */
125
+ export function tpoTimeZone(value) {
126
+ const raw = String(value || 'UTC');
127
+ return raw.toUpperCase() === 'ET' ? NY_TIME_ZONE : raw;
128
+ }
129
+ const servedZones = new Map();
130
+ /** The zone a range is read on: its own where the runtime's zone data knows it, else UTC (a bad saved zone). */
131
+ function servedTimeZone(value) {
132
+ const zone = tpoTimeZone(value);
133
+ let served = servedZones.get(zone);
134
+ if (served === undefined) {
135
+ try {
136
+ zoneOffsetMsAt(zone, 0);
137
+ served = zone;
138
+ }
139
+ catch {
140
+ served = 'UTC';
141
+ }
142
+ if (servedZones.size >= 64)
143
+ servedZones.clear();
144
+ servedZones.set(zone, served);
145
+ }
146
+ return served;
153
147
  }
148
+ const MINUTE_MS = 60_000;
154
149
  const DAY_MS = 86_400_000;
155
- const pad = (value, width) => String(value).padStart(width, '0');
156
- /**
157
- * The 'YYYY-MM-DD' key of the `zone` calendar date after the one holding
158
- * `timestamp` (unix seconds), as `unixInTimeZone(...).startOf('day').add(1, 'day')`
159
- * formats it, from the zone clock (ny-calendar.util: one Intl reading per UTC
160
- * day). An unknown zone reads UTC, as `unixInTimeZone` does; dayjs reads the
161
- * instants the zone clock does not serve. The day cache is left alone: its
162
- * last-day span is the one `resolveTpoTimeRangeWindow` answers from.
163
- */
164
- function nextZoneDateKey(timestamp, zone) {
150
+ /** A range's hours as a session on its own clock (open, close, zone); undefined for times that do not parse. */
151
+ function tpoRangeSession(range) {
152
+ if (!range)
153
+ return undefined;
154
+ const openMinutes = parseTpoTimeToMinutes(range.start_time);
155
+ const closeMinutes = parseTpoTimeToMinutes(range.end_time);
156
+ if (openMinutes === undefined || closeMinutes === undefined)
157
+ return undefined;
158
+ return { timeZone: servedTimeZone(range.timezone), openMinutes, closeMinutes };
159
+ }
160
+ /** `zone`'s wall clock at `ms` as a UTC-shaped epoch; the instant itself where the zone clock serves none. */
161
+ function zoneWallMsOr(zone, ms) {
162
+ if (zone === 'UTC')
163
+ return ms;
165
164
  let wallMs;
166
165
  try {
167
- wallMs = zoneWallMsAt(zone, timestamp * 1000);
166
+ wallMs = zoneWallMsAt(zone, ms);
168
167
  }
169
168
  catch {
170
- wallMs = timestamp * 1000;
169
+ wallMs = Number.NaN;
171
170
  }
172
- if (Number.isNaN(wallMs))
173
- return unixInTimeZone(timestamp, zone).startOf('day').add(1, 'day').format('YYYY-MM-DD');
174
- const next = new Date(Math.floor(wallMs / DAY_MS) * DAY_MS + DAY_MS);
175
- return `${pad(next.getUTCFullYear(), 4)}-${pad(next.getUTCMonth() + 1, 2)}-${pad(next.getUTCDate(), 2)}`;
171
+ return Number.isNaN(wallMs) ? ms : wallMs;
176
172
  }
177
- export function resolveTpoTimeRangeWindow(timestamp, customTimeRange) {
178
- if (!customTimeRange)
179
- return undefined;
180
- const startMinutes = parseTpoTimeToMinutes(customTimeRange.start_time);
181
- const endMinutes = parseTpoTimeToMinutes(customTimeRange.end_time);
182
- if (startMinutes === undefined || endMinutes === undefined)
183
- return undefined;
184
- const zone = timezoneName(customTimeRange.timezone);
185
- // Cached zoned day plus memoised wall times: the same instants as the
186
- // per-call dayjs chain, compared as unix seconds (`isBefore` on instants).
187
- const { dayStart } = zonedDayFor(timestamp, zone);
188
- const dayKey = dayStart.format('YYYY-MM-DD');
189
- const previousDay = dayStart.subtract(1, 'day');
190
- const nextDay = dayStart.add(1, 'day');
191
- const previousKey = previousDay.format('YYYY-MM-DD');
192
- const nextKey = nextDay.format('YYYY-MM-DD');
193
- const startToday = wallTimeUnixOnDay(dayKey, startMinutes, zone);
194
- const endToday = wallTimeUnixOnDay(dayKey, endMinutes, zone);
195
- if (startMinutes === endMinutes) {
196
- const crossesIntoToday = timestamp < startToday;
197
- const start = crossesIntoToday ? wallTimeUnixOnDay(previousKey, startMinutes, zone) : startToday;
198
- const end = crossesIntoToday ? startToday : wallTimeUnixOnDay(nextKey, startMinutes, zone);
199
- return { startSec: start, endSec: end, fullSession: true };
173
+ /** The session's [open, close) in unix seconds on the local day `dayWallMs`, each edge read on its own date. */
174
+ function sessionInstantsSec(session, dayWallMs) {
175
+ const [openMs, closeMs] = session.timeZone === 'UTC' ? [Number.NaN, Number.NaN] : marketSessionInstantsOn(session, dayWallMs);
176
+ if (Number.isNaN(openMs) || Number.isNaN(closeMs)) {
177
+ const closeDayMs = session.closeMinutes <= session.openMinutes ? dayWallMs + DAY_MS : dayWallMs;
178
+ return [
179
+ Math.floor((dayWallMs + session.openMinutes * MINUTE_MS) / 1000),
180
+ Math.floor((closeDayMs + session.closeMinutes * MINUTE_MS) / 1000),
181
+ ];
200
182
  }
201
- if (startMinutes < endMinutes) {
202
- return { startSec: startToday, endSec: endToday, fullSession: false };
183
+ return [Math.floor(openMs / 1000), Math.floor(closeMs / 1000)];
184
+ }
185
+ /** The local calendar day holding `timestamp` (unix seconds) on `zone`'s clock, as its midnight's UTC-shaped epoch. */
186
+ function zoneDayWallMs(zone, timestamp) {
187
+ return Math.floor(zoneWallMsOr(zone, timestamp * 1000) / DAY_MS) * DAY_MS;
188
+ }
189
+ /** The window holding `timestamp` and the local day it opened on. */
190
+ function tpoWindowOn(timestamp, session) {
191
+ const dayWallMs = zoneDayWallMs(session.timeZone, timestamp);
192
+ const [startToday, endToday] = sessionInstantsSec(session, dayWallMs);
193
+ const fullSession = session.openMinutes === session.closeMinutes;
194
+ if (session.openMinutes < session.closeMinutes) {
195
+ return { window: { startSec: startToday, endSec: endToday, fullSession }, openDayWallMs: dayWallMs };
203
196
  }
204
- const isPostMidnightContinuation = timestamp < endToday;
205
- const start = isPostMidnightContinuation ? wallTimeUnixOnDay(previousKey, startMinutes, zone) : startToday;
206
- const end = isPostMidnightContinuation ? endToday : wallTimeUnixOnDay(nextKey, endMinutes, zone);
207
- return { startSec: start, endSec: end, fullSession: false };
197
+ // Crossing midnight: before today's open, yesterday's session holds the timestamp while it is still open.
198
+ const [startYesterday, endYesterday] = sessionInstantsSec(session, dayWallMs - DAY_MS);
199
+ if (timestamp < (fullSession ? startToday : endYesterday)) {
200
+ return {
201
+ window: { startSec: startYesterday, endSec: endYesterday, fullSession },
202
+ openDayWallMs: dayWallMs - DAY_MS,
203
+ };
204
+ }
205
+ return { window: { startSec: startToday, endSec: endToday, fullSession }, openDayWallMs: dayWallMs };
206
+ }
207
+ /** The daily window `timestamp` reads, on the range's own zone clock: device-independent, daylight saving included. */
208
+ export function resolveTpoTimeRangeWindow(timestamp, customTimeRange) {
209
+ const session = tpoRangeSession(customTimeRange);
210
+ return session ? tpoWindowOn(timestamp, session).window : undefined;
208
211
  }
209
212
  export function containsTpoWindowTime(timestamp, window) {
210
213
  return timestamp >= window.startSec && timestamp < window.endSec;
211
214
  }
215
+ /** The first local day of the day, ISO week (Monday) or month holding the local day `dayWallMs`. */
216
+ function periodFirstDayWallMs(dayWallMs, sessionType) {
217
+ const day = new Date(dayWallMs);
218
+ if (sessionType === 'Weekly')
219
+ return dayWallMs - ((day.getUTCDay() + 6) % 7) * DAY_MS;
220
+ if (sessionType === 'Monthly')
221
+ return Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), 1);
222
+ return dayWallMs;
223
+ }
224
+ /** The first local day of the next day, ISO week or month after the one opening on `firstDayWallMs`. */
225
+ function nextPeriodFirstDayWallMs(firstDayWallMs, sessionType) {
226
+ if (sessionType === 'Weekly')
227
+ return firstDayWallMs + 7 * DAY_MS;
228
+ if (sessionType === 'Monthly') {
229
+ const day = new Date(firstDayWallMs);
230
+ return Date.UTC(day.getUTCFullYear(), day.getUTCMonth() + 1, 1);
231
+ }
232
+ return firstDayWallMs + DAY_MS;
233
+ }
234
+ /**
235
+ * The instant (unix seconds) a window edge `wallMs` means on `zone`'s clock, by the one edge rule
236
+ * (market-sessions.util zoneWallEdgeToUtcMs): a wall time the clock skips opens at the change itself, a repeated one
237
+ * at its first occurrence. The wall time read as UTC where the zone clock serves no reading.
238
+ */
239
+ function zoneWallInstantSec(zone, wallMs) {
240
+ const ms = zoneWallEdgeToUtcMs(zone, wallMs);
241
+ return Math.floor((Number.isNaN(ms) ? wallMs : ms) / 1000);
242
+ }
243
+ /** The day, week or month holding `timestamp` on the range's own calendar, from its close if it crosses midnight. */
244
+ function tpoCalendarPeriodSec(timestamp, sessionType, range) {
245
+ const zone = !range || range.periodCalendar === 'UTC' ? 'UTC' : servedTimeZone(range.timezone);
246
+ const offsetMs = getTpoCrossDayOffsetMinutes(range) * MINUTE_MS;
247
+ const shiftedDayWallMs = Math.floor((zoneWallMsOr(zone, timestamp * 1000) - offsetMs) / DAY_MS) * DAY_MS;
248
+ const firstDayWallMs = periodFirstDayWallMs(shiftedDayWallMs, sessionType);
249
+ return [
250
+ zoneWallInstantSec(zone, firstDayWallMs + offsetMs),
251
+ zoneWallInstantSec(zone, nextPeriodFirstDayWallMs(firstDayWallMs, sessionType) + offsetMs),
252
+ ];
253
+ }
212
254
  export function getTpoSessionStart(timestamp, sessionType, customTimeRange) {
213
- const timeWindow = resolveTpoTimeRangeWindow(timestamp, customTimeRange);
214
- if (sessionType === 'Daily' && timeWindow)
215
- return timeWindow.startSec;
216
- const date = dayjs.unix(timestamp).utc();
217
- const offset = getTpoCrossDayOffset(customTimeRange);
218
- switch (sessionType) {
219
- case 'Weekly':
220
- return date.startOf('isoWeek').unix() + offset;
221
- case 'Monthly':
222
- return date.startOf('month').unix() + offset;
223
- case 'Daily':
224
- default:
225
- return date.startOf('day').unix() + offset;
255
+ if (sessionType === 'Daily' || !(sessionType === 'Weekly' || sessionType === 'Monthly')) {
256
+ const session = tpoRangeSession(customTimeRange);
257
+ if (session)
258
+ return tpoWindowOn(timestamp, session).window.startSec;
259
+ return tpoCalendarPeriodSec(timestamp, 'Daily', customTimeRange)[0];
226
260
  }
261
+ return tpoCalendarPeriodSec(timestamp, sessionType, customTimeRange)[0];
227
262
  }
228
263
  export function getNextTpoSessionStart(timestamp, sessionType, customTimeRange) {
229
- const timeWindow = resolveTpoTimeRangeWindow(timestamp, customTimeRange);
230
- if (sessionType === 'Daily' && timeWindow) {
231
- // The next session opens at the window's start wall time on the next
232
- // wall day, computed wall-exactly: a flat +24h drifts by an hour across
233
- // DST transitions (23h/25h days). The date from the zone clock and the
234
- // instant from the window's own wall-time memo: the TPO folds ask once
235
- // per period, where three dayjs conversions ran each time.
236
- const zone = timezoneName(customTimeRange?.timezone);
237
- const startMinutes = parseTpoTimeToMinutes(customTimeRange?.start_time) ?? 0;
238
- return wallTimeUnixOnDay(nextZoneDateKey(timeWindow.startSec, zone), startMinutes, zone);
239
- }
240
- const date = dayjs.unix(timestamp).utc();
241
- const offset = getTpoCrossDayOffset(customTimeRange);
242
- switch (sessionType) {
243
- case 'Weekly':
244
- return date.add(1, 'week').startOf('isoWeek').unix() + offset;
245
- case 'Monthly':
246
- return date.add(1, 'month').startOf('month').unix() + offset;
247
- case 'Daily':
248
- default:
249
- return date.add(1, 'day').startOf('day').unix() + offset;
264
+ if (sessionType === 'Daily' || !(sessionType === 'Weekly' || sessionType === 'Monthly')) {
265
+ const session = tpoRangeSession(customTimeRange);
266
+ // The next local day's open, read on that date: a flat +24h drifts an hour across a clock change.
267
+ if (session)
268
+ return sessionInstantsSec(session, tpoWindowOn(timestamp, session).openDayWallMs + DAY_MS)[0];
269
+ return tpoCalendarPeriodSec(timestamp, 'Daily', customTimeRange)[1];
250
270
  }
271
+ return tpoCalendarPeriodSec(timestamp, sessionType, customTimeRange)[1];
251
272
  }
252
273
  function formatTpoLetter(index) {
253
274
  if (!Number.isInteger(index) || index < 0) {
@@ -277,14 +298,24 @@ function formatTpoLetter(index) {
277
298
  export function generateTpoLetters(blockIds, _sessionType, _tpoBlockSizeMinutes) {
278
299
  return blockIds.map(formatTpoLetter);
279
300
  }
280
- /** Editable starting template (Asia / London / New York / Close, UTC) — a
281
- * default for the editor, never a hard-coded behavior. */
282
- export const DEFAULT_TPO_CUSTOM_SESSION_SEGMENTS = [
283
- { label: 'Asia', start: '00:00', end: '06:00', color: '#4f8cff' },
284
- { label: 'London', start: '06:00', end: '12:00', color: '#22c39b' },
285
- { label: 'New York', start: '12:00', end: '20:00', color: '#f2a33c' },
286
- { label: 'Close', start: '20:00', end: '00:00', color: '#a06bff' },
287
- ];
301
+ /** Each slice of the day split's colour (Asia, London and New York keep the colours their sessions always had). */
302
+ const SPLIT_SEGMENT_COLORS = Object.freeze({
303
+ asia: '#4f8cff',
304
+ london: '#22c39b',
305
+ newYork: '#f2a33c',
306
+ afterHours: '#a06bff',
307
+ });
308
+ /** The editor's starting set: the day split's slices on its clock, named by `labelOf`; hours from the split only. */
309
+ export function defaultTpoCustomSessionSegments(labelOf) {
310
+ return MARKET_SESSION_SPLIT.slices.map((slice) => ({
311
+ label: labelOf(slice.id),
312
+ start: sessionClockText(slice.startMinutes),
313
+ end: sessionClockText(slice.endMinutes),
314
+ color: SPLIT_SEGMENT_COLORS[slice.id],
315
+ }));
316
+ }
317
+ /** The starting set's clock, the split's own: New York, stored as 'ET'. */
318
+ export const DEFAULT_TPO_CUSTOM_SESSIONS_TIMEZONE = tpoCustomSessionsTimezoneOf(MARKET_SESSION_SPLIT.timeZone);
288
319
  const MINUTES_PER_DAY = 1440;
289
320
  const SECONDS_PER_DAY = 86_400;
290
321
  function parseTpoSegmentEndToMinutes(value) {
@@ -310,7 +341,7 @@ export function normalizeTpoCustomSessionSegments(value, timezone) {
310
341
  if (!Array.isArray(value) || value.length === 0)
311
342
  return null;
312
343
  const clock = tpoCustomSessionsTimezoneOf(timezone);
313
- const zone = timezoneName(clock);
344
+ const zone = tpoTimeZone(clock);
314
345
  const parsed = [];
315
346
  for (const raw of value) {
316
347
  if (!raw || typeof raw !== 'object')
@@ -401,60 +432,10 @@ function toTpoCustomSessionWindow(segment, startDaySec) {
401
432
  color: segment.color,
402
433
  };
403
434
  }
404
- const MS_PER_MINUTE = 60_000;
405
- /** `zone`'s wall clock at `ms` as a UTC-shaped epoch; the instant itself where the zone clock serves none. */
406
- function zoneWallMsOr(zone, ms) {
407
- let wallMs;
408
- try {
409
- wallMs = zoneWallMsAt(zone, ms);
410
- }
411
- catch {
412
- wallMs = Number.NaN;
413
- }
414
- return Number.isNaN(wallMs) ? ms : wallMs;
415
- }
416
- /**
417
- * The instant (unix seconds) `zone`'s wall clock reads `wallMs`; the wall reading itself where the clock serves none.
418
- * A wall time the clock skips (the spring-forward hour) opens at the first instant reading at or after it, the change
419
- * itself: the solver settles a skipped time on an instant reading earlier, and a session start read that way would
420
- * open before the instant asked from (a walk over starts would stall on it).
421
- */
422
- function zoneWallInstantSec(zone, wallMs) {
423
- let ms;
424
- try {
425
- ms = zoneWallToUtcMs(zone, wallMs);
426
- }
427
- catch {
428
- ms = Number.NaN;
429
- }
430
- if (Number.isNaN(ms))
431
- return Math.floor(wallMs / 1000);
432
- const readMs = zoneWallMsOr(zone, ms);
433
- return Math.floor((readMs === wallMs ? ms : firstInstantReadingAtLeast(zone, wallMs, ms, readMs)) / 1000);
434
- }
435
- /**
436
- * The first whole second whose `zone` wall reading is at least `wallMs`, for a skipped wall time: `ms` (reading
437
- * `readMs`) sits on one side of the skipped span and the instant one span away on the other, so a bisection between
438
- * them lands on the change. `ms` itself when the far side reads no later (no skipped span after all).
439
- */
440
- function firstInstantReadingAtLeast(zone, wallMs, ms, readMs) {
441
- let low = readMs < wallMs ? ms : ms - (readMs - wallMs);
442
- let high = readMs < wallMs ? ms + (wallMs - readMs) : ms;
443
- if (!(zoneWallMsOr(zone, high) >= wallMs) || zoneWallMsOr(zone, low) >= wallMs)
444
- return ms;
445
- for (let step = 0; step < 64 && high - low > 1000; step += 1) {
446
- const mid = low + Math.floor((high - low) / 2000) * 1000;
447
- if (zoneWallMsOr(zone, mid) >= wallMs)
448
- high = mid;
449
- else
450
- low = mid;
451
- }
452
- return high;
453
- }
454
435
  function zonedTpoCustomSessionWindow(segment, dayWallMs, zone) {
455
436
  return {
456
- startSec: zoneWallInstantSec(zone, dayWallMs + segment.startMinute * MS_PER_MINUTE),
457
- endSec: zoneWallInstantSec(zone, dayWallMs + segment.endMinute * MS_PER_MINUTE),
437
+ startSec: zoneWallInstantSec(zone, dayWallMs + segment.startMinute * MINUTE_MS),
438
+ endSec: zoneWallInstantSec(zone, dayWallMs + segment.endMinute * MINUTE_MS),
458
439
  index: segment.index,
459
440
  label: segment.label,
460
441
  color: segment.color,
@@ -464,10 +445,10 @@ function zonedTpoCustomSessionWindow(segment, dayWallMs, zone) {
464
445
  * date, each edge converted on its own date, so a session keeps its wall
465
446
  * hours across daylight saving (the 23 and 25 hour days included). */
466
447
  function newYorkTpoCustomSessionDay(timestamp, segments) {
467
- const zone = segments[0].zone || timezoneName('ET');
448
+ const zone = segments[0].zone || tpoTimeZone('ET');
468
449
  const wallMs = zoneWallMsOr(zone, timestamp * 1000);
469
450
  const dayWallMs = Math.floor(wallMs / DAY_MS) * DAY_MS;
470
- return { zone, dayWallMs, minuteOfDay: (wallMs - dayWallMs) / MS_PER_MINUTE };
451
+ return { zone, dayWallMs, minuteOfDay: (wallMs - dayWallMs) / MINUTE_MS };
471
452
  }
472
453
  /** The segment window containing `timestamp` (unix seconds), or null when
473
454
  * the timestamp falls in a gap between segments. Segments read on their
@@ -487,7 +468,7 @@ export function getTpoCustomSessionWindow(timestamp, segments) {
487
468
  }
488
469
  return null;
489
470
  }
490
- const dayStart = dayjs.unix(timestamp).utc().startOf('day').unix();
471
+ const dayStart = Math.floor(timestamp / SECONDS_PER_DAY) * SECONDS_PER_DAY;
491
472
  const minuteOfDay = Math.floor((timestamp - dayStart) / 60);
492
473
  // The post-midnight tail of the wrapping segment (always the last one)
493
474
  // belongs to the session that opened the previous day.
@@ -514,7 +495,7 @@ export function getNextTpoCustomSessionStart(timestamp, segments) {
514
495
  for (const segment of segments) {
515
496
  if (day === 0 && segment.startMinute <= minuteOfDay)
516
497
  continue;
517
- const startSec = zoneWallInstantSec(zone, dayWallMs + day * DAY_MS + segment.startMinute * MS_PER_MINUTE);
498
+ const startSec = zoneWallInstantSec(zone, dayWallMs + day * DAY_MS + segment.startMinute * MINUTE_MS);
518
499
  if (startSec > timestamp)
519
500
  return startSec;
520
501
  }
@@ -522,7 +503,7 @@ export function getNextTpoCustomSessionStart(timestamp, segments) {
522
503
  // Unreachable while the zone clock serves (the next day's first start lies a day ahead); still a step forward.
523
504
  return Math.floor(timestamp) + SECONDS_PER_DAY;
524
505
  }
525
- const dayStart = dayjs.unix(timestamp).utc().startOf('day').unix();
506
+ const dayStart = Math.floor(timestamp / SECONDS_PER_DAY) * SECONDS_PER_DAY;
526
507
  const minuteOfDay = (timestamp - dayStart) / 60;
527
508
  for (const segment of segments) {
528
509
  if (segment.startMinute > minuteOfDay)
@@ -19,6 +19,6 @@ export interface CancelReasonSelection {
19
19
  comment: string;
20
20
  }
21
21
  /** The product a cancel ends, as the `billing:cancel` event names it. */
22
- export type CancelProduct = 'plus' | 'api' | 'cme' | 'opra';
22
+ export type CancelProduct = 'plus' | 'api' | 'cme' | 'opra' | 'stocks';
23
23
  /** The server's comment limit, in UTF-16 code units (what a textarea's maxlength and a JS length count). */
24
24
  export declare const CANCEL_COMMENT_MAX_LENGTH = 500;
@@ -171,25 +171,32 @@ export type CmeServedAccessByExchange = Record<string, CmeServedAccess>;
171
171
  /** Attestation validity is derived at read time from expiresAt, never cached. */
172
172
  export declare function isCmeAttestationValid(attestation: CmeAttestation | null, now?: number): boolean;
173
173
  /**
174
- * Stable, transport-free error surface for billing calls. 'attestation_rejected'
175
- * covers the checkout 403 gates (missing OR expired attestation); callers
176
- * re-fetch attestation state to learn which, rather than matching message text.
177
- * 'invoice_owed' is the checkout refusal while Stripe is still collecting a CME
178
- * invoice (the renewal is in retries): a retry gets the same answer until that
179
- * invoice is paid, so it carries the pay link instead of reading as a conflict.
174
+ * Stable, transport-free error surface for billing calls. The kind says what a
175
+ * flow can do next, never what a page says: the words for a refusal come from
176
+ * the purchase-refusal resolver (docs/features/billing/purchase-refusals.md),
177
+ * which reads `cause`, the failure as it arrived (the server's tagged answer,
178
+ * or the transport's). 'refused': the server answered and refused, so what the
179
+ * account holds may differ from what the page shows (the store reads it
180
+ * again). 'unauthorized': a 401 or an expired session. 'server': a 5xx or a
181
+ * rate limit, where a retry can succeed. 'network': no answer. 'aborted': the
182
+ * caller's own abort, which is no refusal at all.
180
183
  */
181
- export type CmeBillingErrorKind = 'attestation_rejected' | 'conflict' | 'invoice_owed' | 'unauthorized' | 'network' | 'aborted' | 'server';
184
+ export type CmeBillingErrorKind = 'refused' | 'unauthorized' | 'network' | 'aborted' | 'server';
182
185
  export declare class CmeBillingError extends Error {
183
186
  readonly kind: CmeBillingErrorKind;
184
187
  readonly status: number | null;
185
- /** Raw backend message: diagnostic/fallback content only, never primary UI copy. */
188
+ /** Raw backend message: diagnostic content only, never UI copy. */
186
189
  readonly diagnosticMessage: string | null;
187
- /** Stripe's hosted invoice on an 'invoice_owed' refusal; null when Stripe published none, and on every other kind. */
190
+ /**
191
+ * Stripe's hosted invoice on the owed-invoice refusal (SUBSCRIPTION_INVOICE_OWED); null when Stripe published
192
+ * none, and on every other failure.
193
+ */
188
194
  readonly invoiceUrl: string | null;
189
195
  constructor(kind: CmeBillingErrorKind, options?: {
190
196
  status?: number | null;
191
197
  diagnosticMessage?: string | null;
192
198
  invoiceUrl?: string | null;
199
+ cause?: unknown;
193
200
  });
194
201
  }
195
202
  export interface CmeBillingRepository {
@@ -31,12 +31,15 @@ export function isCmeAttestationValid(attestation, now = Date.now()) {
31
31
  export class CmeBillingError extends Error {
32
32
  kind;
33
33
  status;
34
- /** Raw backend message: diagnostic/fallback content only, never primary UI copy. */
34
+ /** Raw backend message: diagnostic content only, never UI copy. */
35
35
  diagnosticMessage;
36
- /** Stripe's hosted invoice on an 'invoice_owed' refusal; null when Stripe published none, and on every other kind. */
36
+ /**
37
+ * Stripe's hosted invoice on the owed-invoice refusal (SUBSCRIPTION_INVOICE_OWED); null when Stripe published
38
+ * none, and on every other failure.
39
+ */
37
40
  invoiceUrl;
38
41
  constructor(kind, options) {
39
- super(`cme billing error: ${kind}`);
42
+ super(`cme billing error: ${kind}`, options?.cause === undefined ? undefined : { cause: options.cause });
40
43
  this.name = 'CmeBillingError';
41
44
  this.kind = kind;
42
45
  this.status = options?.status ?? null;
@@ -27,6 +27,12 @@ export interface RuntimeDiagnostic {
27
27
  * run carrying the OPRA mark). The editor console shows it, and every console export strips it.
28
28
  */
29
29
  opra?: true;
30
+ /**
31
+ * The row was computed over CME data by a CME chart study (the `cme-user-scripts` gate, the display boundary): the
32
+ * run that reported it read the CME plane (its own fact from before it computed: the wrun runtime trap of a run on a
33
+ * CME chart). Read beside `opra`: the editor console shows it, and every console export strips it.
34
+ */
35
+ cme?: true;
30
36
  }
31
37
  /** `details` of a FE_KSCRIPT_PERF_SLOW row: what the chip and the compact card show. */
32
38
  export interface KScriptPerfSlowDetails {