@flamingo-stack/openframe-frontend-core 0.0.643 → 0.0.644-2208.6318.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 (130) hide show
  1. package/dist/chat-protocol/index.cjs +10 -3
  2. package/dist/chat-protocol/index.cjs.map +1 -1
  3. package/dist/chat-protocol/index.js +10 -3
  4. package/dist/chat-protocol/index.js.map +1 -1
  5. package/dist/chat-protocol/source-metadata.d.ts +7 -1
  6. package/dist/chat-protocol/source-metadata.d.ts.map +1 -1
  7. package/dist/{chunk-42NXGOTG.cjs → chunk-2G47VKPD.cjs} +3 -3
  8. package/dist/{chunk-42NXGOTG.cjs.map → chunk-2G47VKPD.cjs.map} +1 -1
  9. package/dist/{chunk-HA2U7WHU.js → chunk-3AUBCCTI.js} +3 -3
  10. package/dist/{chunk-5E6Y6766.cjs → chunk-3ENJITQA.cjs} +29 -29
  11. package/dist/{chunk-5E6Y6766.cjs.map → chunk-3ENJITQA.cjs.map} +1 -1
  12. package/dist/{chunk-64KDKDYC.js → chunk-3ENOAHWR.js} +6 -6
  13. package/dist/{chunk-3IPL6G7S.js → chunk-3W563UVF.js} +40 -10
  14. package/dist/chunk-3W563UVF.js.map +1 -0
  15. package/dist/{chunk-IU3IYXMM.js → chunk-4WIS7COJ.js} +7 -7
  16. package/dist/{chunk-4TE53O6U.js → chunk-53RGBCL7.js} +4 -4
  17. package/dist/{chunk-FVIT23I5.js → chunk-5GAWR7RX.js} +3 -3
  18. package/dist/{chunk-B42INNRA.cjs → chunk-5QRNCWHS.cjs} +199 -199
  19. package/dist/{chunk-B42INNRA.cjs.map → chunk-5QRNCWHS.cjs.map} +1 -1
  20. package/dist/{chunk-IIZX3K2R.js → chunk-6O2XNGUE.js} +2 -2
  21. package/dist/{chunk-ZU2JBBOE.cjs → chunk-7FI2YKEU.cjs} +59 -59
  22. package/dist/{chunk-ZU2JBBOE.cjs.map → chunk-7FI2YKEU.cjs.map} +1 -1
  23. package/dist/{chunk-7T673MHJ.cjs → chunk-CTGCWBU3.cjs} +22 -22
  24. package/dist/{chunk-7T673MHJ.cjs.map → chunk-CTGCWBU3.cjs.map} +1 -1
  25. package/dist/{chunk-NCHLLTAR.js → chunk-DSKO3GPD.js} +3 -3
  26. package/dist/{chunk-EWQI5MV6.cjs → chunk-DYJQPJBW.cjs} +20 -20
  27. package/dist/{chunk-EWQI5MV6.cjs.map → chunk-DYJQPJBW.cjs.map} +1 -1
  28. package/dist/{chunk-YT6RGA3X.js → chunk-GLGERQO7.js} +3 -3
  29. package/dist/{chunk-2NRLRRMR.cjs → chunk-GSC2NB5C.cjs} +108 -78
  30. package/dist/chunk-GSC2NB5C.cjs.map +1 -0
  31. package/dist/{chunk-TQ7KTANJ.js → chunk-JWRMSVNZ.js} +3 -3
  32. package/dist/{chunk-2DJH6KHA.cjs → chunk-K6KKARAF.cjs} +155 -148
  33. package/dist/{chunk-2DJH6KHA.cjs.map → chunk-K6KKARAF.cjs.map} +1 -1
  34. package/dist/{chunk-FO7SD2IQ.cjs → chunk-KCO7MZ34.cjs} +6 -6
  35. package/dist/{chunk-FO7SD2IQ.cjs.map → chunk-KCO7MZ34.cjs.map} +1 -1
  36. package/dist/{chunk-YG7KLZE7.js → chunk-KCS64Q7P.js} +4 -4
  37. package/dist/{chunk-XJLWGYL4.cjs → chunk-KSSBW5W7.cjs} +81 -81
  38. package/dist/{chunk-XJLWGYL4.cjs.map → chunk-KSSBW5W7.cjs.map} +1 -1
  39. package/dist/{chunk-M3W5Y5DK.cjs → chunk-LJ5VSU2Q.cjs} +11 -11
  40. package/dist/{chunk-M3W5Y5DK.cjs.map → chunk-LJ5VSU2Q.cjs.map} +1 -1
  41. package/dist/{chunk-R2IU2Y2O.cjs → chunk-M7NQPYQB.cjs} +33 -33
  42. package/dist/{chunk-R2IU2Y2O.cjs.map → chunk-M7NQPYQB.cjs.map} +1 -1
  43. package/dist/{chunk-D6TWJEFW.cjs → chunk-ODZ4JBFQ.cjs} +15 -15
  44. package/dist/{chunk-D6TWJEFW.cjs.map → chunk-ODZ4JBFQ.cjs.map} +1 -1
  45. package/dist/{chunk-3LXJEXPH.js → chunk-QH6KJ4OZ.js} +2 -2
  46. package/dist/{chunk-O7JMF5OT.js → chunk-QX3K5SXC.js} +3 -3
  47. package/dist/{chunk-N7UYD57Q.js → chunk-REAWHAOH.js} +3 -3
  48. package/dist/{chunk-CWHLVXUW.cjs → chunk-S7UGTAIP.cjs} +10 -10
  49. package/dist/{chunk-CWHLVXUW.cjs.map → chunk-S7UGTAIP.cjs.map} +1 -1
  50. package/dist/{chunk-2NODQ7FO.js → chunk-TN46CQSO.js} +12 -5
  51. package/dist/{chunk-2NODQ7FO.js.map → chunk-TN46CQSO.js.map} +1 -1
  52. package/dist/{chunk-77EO26XV.cjs → chunk-V37CP6CT.cjs} +5 -5
  53. package/dist/{chunk-77EO26XV.cjs.map → chunk-V37CP6CT.cjs.map} +1 -1
  54. package/dist/{chunk-SE6YRE3R.cjs → chunk-W7VZHI37.cjs} +32 -32
  55. package/dist/{chunk-SE6YRE3R.cjs.map → chunk-W7VZHI37.cjs.map} +1 -1
  56. package/dist/{chunk-TIOHTWDA.js → chunk-WTUX4SNF.js} +6 -6
  57. package/dist/{chunk-KX2FT7AS.cjs → chunk-YCO7DTCF.cjs} +28 -28
  58. package/dist/{chunk-KX2FT7AS.cjs.map → chunk-YCO7DTCF.cjs.map} +1 -1
  59. package/dist/{chunk-7HL2PNQ3.js → chunk-YRGIQZSU.js} +5 -5
  60. package/dist/{chunk-6MQBLFUM.js → chunk-YRWXGZLV.js} +5 -5
  61. package/dist/{chunk-26D6FM6L.cjs → chunk-ZAQ6CKTU.cjs} +6 -6
  62. package/dist/{chunk-26D6FM6L.cjs.map → chunk-ZAQ6CKTU.cjs.map} +1 -1
  63. package/dist/components/case-studies/index.cjs +16 -16
  64. package/dist/components/case-studies/index.js +4 -4
  65. package/dist/components/chat/entity-cards/program-card.d.ts.map +1 -1
  66. package/dist/components/chat/index.cjs +3 -3
  67. package/dist/components/chat/index.js +2 -2
  68. package/dist/components/contact/index.cjs +5 -5
  69. package/dist/components/contact/index.js +4 -4
  70. package/dist/components/docs/index.cjs +8 -8
  71. package/dist/components/docs/index.js +7 -7
  72. package/dist/components/embeds/index.cjs +5 -5
  73. package/dist/components/embeds/index.js +4 -4
  74. package/dist/components/faq/index.cjs +5 -5
  75. package/dist/components/faq/index.js +4 -4
  76. package/dist/components/features/index.cjs +4 -4
  77. package/dist/components/features/index.js +3 -3
  78. package/dist/components/help-center-pages/index.cjs +24 -24
  79. package/dist/components/help-center-pages/index.js +15 -15
  80. package/dist/components/index.cjs +53 -53
  81. package/dist/components/index.js +15 -15
  82. package/dist/components/meeting-scheduler/index.cjs +34 -34
  83. package/dist/components/meeting-scheduler/index.js +3 -3
  84. package/dist/components/navigation/index.cjs +7 -7
  85. package/dist/components/navigation/index.js +6 -6
  86. package/dist/components/onboarding-guides/index.cjs +7 -7
  87. package/dist/components/onboarding-guides/index.js +6 -6
  88. package/dist/components/related-content/index.cjs +3 -3
  89. package/dist/components/related-content/index.js +2 -2
  90. package/dist/components/tickets/index.cjs +8 -8
  91. package/dist/components/tickets/index.js +7 -7
  92. package/dist/components/ui/index.cjs +4 -4
  93. package/dist/components/ui/index.js +3 -3
  94. package/dist/index.cjs +10 -8
  95. package/dist/index.cjs.map +1 -1
  96. package/dist/index.js +9 -7
  97. package/dist/index.js.map +1 -1
  98. package/dist/utils/format.d.ts +39 -4
  99. package/dist/utils/format.d.ts.map +1 -1
  100. package/dist/utils/index.cjs +25 -2
  101. package/dist/utils/index.cjs.map +1 -1
  102. package/dist/utils/index.d.ts +1 -1
  103. package/dist/utils/index.d.ts.map +1 -1
  104. package/dist/utils/index.js +25 -3
  105. package/dist/utils/index.js.map +1 -1
  106. package/package.json +1 -1
  107. package/src/chat-protocol/__tests__/source-metadata.test.ts +49 -0
  108. package/src/chat-protocol/source-metadata.ts +46 -6
  109. package/src/components/chat/entity-cards/program-card.tsx +46 -8
  110. package/src/utils/__tests__/format-program-dates.test.ts +91 -0
  111. package/src/utils/format.ts +79 -7
  112. package/src/utils/index.ts +2 -0
  113. package/dist/chunk-2NRLRRMR.cjs.map +0 -1
  114. package/dist/chunk-3IPL6G7S.js.map +0 -1
  115. /package/dist/{chunk-HA2U7WHU.js.map → chunk-3AUBCCTI.js.map} +0 -0
  116. /package/dist/{chunk-64KDKDYC.js.map → chunk-3ENOAHWR.js.map} +0 -0
  117. /package/dist/{chunk-IU3IYXMM.js.map → chunk-4WIS7COJ.js.map} +0 -0
  118. /package/dist/{chunk-4TE53O6U.js.map → chunk-53RGBCL7.js.map} +0 -0
  119. /package/dist/{chunk-FVIT23I5.js.map → chunk-5GAWR7RX.js.map} +0 -0
  120. /package/dist/{chunk-IIZX3K2R.js.map → chunk-6O2XNGUE.js.map} +0 -0
  121. /package/dist/{chunk-NCHLLTAR.js.map → chunk-DSKO3GPD.js.map} +0 -0
  122. /package/dist/{chunk-YT6RGA3X.js.map → chunk-GLGERQO7.js.map} +0 -0
  123. /package/dist/{chunk-TQ7KTANJ.js.map → chunk-JWRMSVNZ.js.map} +0 -0
  124. /package/dist/{chunk-YG7KLZE7.js.map → chunk-KCS64Q7P.js.map} +0 -0
  125. /package/dist/{chunk-3LXJEXPH.js.map → chunk-QH6KJ4OZ.js.map} +0 -0
  126. /package/dist/{chunk-O7JMF5OT.js.map → chunk-QX3K5SXC.js.map} +0 -0
  127. /package/dist/{chunk-N7UYD57Q.js.map → chunk-REAWHAOH.js.map} +0 -0
  128. /package/dist/{chunk-TIOHTWDA.js.map → chunk-WTUX4SNF.js.map} +0 -0
  129. /package/dist/{chunk-7HL2PNQ3.js.map → chunk-YRGIQZSU.js.map} +0 -0
  130. /package/dist/{chunk-6MQBLFUM.js.map → chunk-YRWXGZLV.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flamingo-stack/openframe-frontend-core",
3
- "version": "0.0.643",
3
+ "version": "0.0.644-2208.6318.1",
4
4
  "description": "Shared design system and components for all Flamingo platforms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -117,6 +117,55 @@ describe('sourceMetadataEvent', () => {
117
117
  expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
118
118
  });
119
119
 
120
+ // A same-origin href is the hub's NORMAL output when the owning platform is
121
+ // the serving platform. Dropping it left every guide chip with a name and no
122
+ // destination, before the consumer's own absolutiser could ever run.
123
+ it('keeps a root-relative external URL', () => {
124
+ const event = sourceMetadataEvent({
125
+ sources: [
126
+ {
127
+ index: 1,
128
+ name: 'Guide',
129
+ path: 'onboarding-guides/x',
130
+ documentType: 'onboarding_guide',
131
+ externalUrl: '/onboarding-guides/x',
132
+ },
133
+ ],
134
+ });
135
+ expect(event?.sources?.[0].externalUrl).toBe('/onboarding-guides/x');
136
+ });
137
+
138
+ it('keeps a root-relative external URL on a grouped item', () => {
139
+ const event = sourceMetadataEvent({
140
+ sources: [
141
+ {
142
+ index: 1,
143
+ name: 'Guides',
144
+ items: [{ id: 'a', documentType: 'onboarding_guide', name: 'A', externalUrl: '/onboarding-guides/a' }],
145
+ },
146
+ ],
147
+ });
148
+ expect(event?.sources?.[0].items?.[0].externalUrl).toBe('/onboarding-guides/a');
149
+ });
150
+
151
+ it('drops a protocol-relative URL, which is a third-party origin and not a path', () => {
152
+ const event = sourceMetadataEvent({
153
+ sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown', externalUrl: '//evil.test/x' }],
154
+ });
155
+ expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
156
+ });
157
+
158
+ it('drops an href carrying control or zero-width characters', () => {
159
+ const event = sourceMetadataEvent({
160
+ sources: [
161
+ { index: 1, name: 'A', externalUrl: '/docs/\u200bx' },
162
+ { index: 2, name: 'B', externalUrl: 'https://x.test/\u0000y' },
163
+ ],
164
+ });
165
+ expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
166
+ expect(event?.sources?.[1]).not.toHaveProperty('externalUrl');
167
+ });
168
+
120
169
  it('preserves an explicit null targetPlatform, which means "no destination"', () => {
121
170
  const event = sourceMetadataEvent({
122
171
  sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown', targetPlatform: null }],
@@ -10,7 +10,13 @@
10
10
  * Everything is validated, and anything that fails is DROPPED rather than
11
11
  * repaired: this payload is assembled from a remote MCP server's tool output,
12
12
  * so a malformed row means an upstream contract slip, and rendering a chip with
13
- * a blank title or a link to a non-https URL is worse than rendering nothing.
13
+ * a blank title or an unsafe href is worse than rendering nothing.
14
+ *
15
+ * "Unsafe" is the operative word, and it is not a synonym for "relative".
16
+ * Links go through `linkUrl` (absolute https OR a root-relative path); only
17
+ * MEDIA urls, which have no origin to resolve against, go through `httpsUrl`.
18
+ * Conflating the two is what made every same-origin source chip lose its
19
+ * destination while keeping its name.
14
20
  *
15
21
  * Server-safe: no React, no browser APIs beyond `URL`.
16
22
  */
@@ -44,11 +50,18 @@ function nullableText(value: unknown): string | null | undefined {
44
50
  return value === null ? null : text(value);
45
51
  }
46
52
 
47
- /** An https URL, or nothing. Plain http and non-URLs are dropped — these become
48
- * hrefs and video sources in the panel. */
53
+ /** Control, zero-width and line-separator characters — never legitimate in a
54
+ * URL we are about to render, and the classic way a payload smuggles one
55
+ * href past a reader's eye. Same set the render-time `safeHref` rejects. */
56
+ const UNSAFE_URL_CHARS = /[\u0000-\u001f\u007f\u200b-\u200d\u2028\u2029\ufeff]/;
57
+
58
+ /** An absolute https URL, or nothing. Plain http and non-URLs are dropped —
59
+ * these become MEDIA sources (`<video src>`, poster images), which have no
60
+ * origin to resolve against and so must be absolute. For a LINK, use
61
+ * `linkUrl` — a same-origin path is valid there and this would discard it. */
49
62
  function httpsUrl(value: unknown): string | undefined {
50
63
  const candidate = text(value);
51
- if (!candidate) return undefined;
64
+ if (!candidate || UNSAFE_URL_CHARS.test(candidate)) return undefined;
52
65
  try {
53
66
  return new URL(candidate).protocol === 'https:' ? candidate : undefined;
54
67
  } catch {
@@ -56,6 +69,33 @@ function httpsUrl(value: unknown): string | undefined {
56
69
  }
57
70
  }
58
71
 
72
+ /**
73
+ * A URL that is safe to render as a source chip's href: an absolute https URL,
74
+ * or a ROOT-RELATIVE path (`/onboarding-guides/foo`).
75
+ *
76
+ * Root-relative is the whole reason this exists separately from `httpsUrl`.
77
+ * The hub emits a relative href whenever the owning platform is the serving
78
+ * platform — correct for its own chat, and correct for any consumer that knows
79
+ * the hub origin (the dashboard absolutises hub-owned hrefs itself). Running
80
+ * `new URL()` with no base on such a path THROWS, so treating "not an absolute
81
+ * https URL" as hostile silently deleted every same-origin link before the code
82
+ * that would have resolved it ever ran, leaving a chip with a name and no
83
+ * destination.
84
+ *
85
+ * Deliberately STRICTER than the render-time `safeHref`, which also permits
86
+ * `http:` and `mailto:`. This payload is assembled from a remote MCP server's
87
+ * tool output, so the ingest guard stays fail-closed on scheme; the two differ
88
+ * on purpose, and only in the safe direction.
89
+ */
90
+ function linkUrl(value: unknown): string | undefined {
91
+ const candidate = text(value);
92
+ if (!candidate || UNSAFE_URL_CHARS.test(candidate)) return undefined;
93
+ // Same-origin path. `//host` is protocol-relative, not a path — it would
94
+ // resolve to a THIRD-PARTY origin, so it is rejected with the rest.
95
+ if (candidate.startsWith('/')) return candidate.startsWith('//') ? undefined : candidate;
96
+ return httpsUrl(candidate);
97
+ }
98
+
59
99
  /**
60
100
  * A YouTube video id, from either a bare id or any of the watch/short/embed URL
61
101
  * shapes. Returns the ID, never a URL — the player takes an id.
@@ -89,7 +129,7 @@ function sourceItems(value: unknown): NonNullable<ChatSource['items']> | undefin
89
129
  // A grouped row without these three has nothing to render OR navigate with.
90
130
  if (!id || !documentType || !name) return [];
91
131
 
92
- const externalUrl = httpsUrl(item.externalUrl);
132
+ const externalUrl = linkUrl(item.externalUrl);
93
133
  const targetPlatform = nullableText(item.targetPlatform);
94
134
  const path = nullableText(item.path);
95
135
  return [
@@ -133,7 +173,7 @@ function sources(value: unknown): ChatSource[] {
133
173
 
134
174
  const path = text(candidate.path);
135
175
  const documentType = text(candidate.documentType);
136
- const externalUrl = httpsUrl(candidate.externalUrl);
176
+ const externalUrl = linkUrl(candidate.externalUrl);
137
177
  const targetPlatform = nullableText(candidate.targetPlatform);
138
178
  const id = text(candidate.id);
139
179
  const sourceRepo = text(candidate.sourceRepo);
@@ -25,7 +25,12 @@ import type React from 'react';
25
25
  import { useState } from 'react';
26
26
  import Image from '../../../embed-shims/next-image';
27
27
  import { cn } from '../../../utils/cn';
28
- import { formatDurationCompact, formatTimeWithTimezone, formatDurationFromRange } from '../../../utils/format';
28
+ import {
29
+ formatDurationCompact,
30
+ formatTimeWithTimezone,
31
+ formatDateWithTimezone,
32
+ formatDurationFromRange,
33
+ } from '../../../utils/format';
29
34
  import { isImageMedia } from '../../../utils/media-type';
30
35
  import { Button } from '../../ui/button/button';
31
36
  import { ImageGalleryModal } from '../../ui/image-gallery-modal';
@@ -181,19 +186,45 @@ function getHosts(hosts: ProgramHost[] | null | undefined): Array<{ name: string
181
186
  * been `in`-guarded for `start_at`. Each field is validated rather than
182
187
  * asserted — the generic item type does not declare them.
183
188
  */
189
+ /** Read a string column off the generic item type, which does not declare it. */
190
+ const programStr = (value: unknown): string | null => (typeof value === 'string' && value ? value : null);
191
+
184
192
  function webinarTiming(item: BaseProgramItem): {
185
193
  startAt: string | null;
186
194
  endAt: string | null;
187
195
  timezone: string | null;
188
196
  } {
189
- const str = (value: unknown): string | null => (typeof value === 'string' && value ? value : null);
190
197
  return {
191
- startAt: 'start_at' in item ? str(item.start_at) : null,
192
- endAt: 'end_at' in item ? str(item.end_at) : null,
193
- timezone: 'timezone' in item ? str(item.timezone) : null,
198
+ startAt: 'start_at' in item ? programStr(item.start_at) : null,
199
+ endAt: 'end_at' in item ? programStr(item.end_at) : null,
200
+ timezone: 'timezone' in item ? programStr(item.timezone) : null,
194
201
  };
195
202
  }
196
203
 
204
+ /**
205
+ * The instant and zone this card renders its DATE in.
206
+ *
207
+ * A card must render every part of ONE timestamp in ONE zone. The date used to
208
+ * come from `item.date` pinned to UTC while the time printed beside it came
209
+ * from `start_at` in the event's own IANA zone, so a webinar at
210
+ * `2026-03-20T01:18Z` / `America/New_York` read "Mar 20, 2026 · 9:18 PM" — a
211
+ * date and a time that never coexisted. Where the row carries a zone, the date
212
+ * is now derived from the SAME instant the time is, in that same zone.
213
+ *
214
+ * A row with no zone keeps the UTC pin (`formatUtc`). That pin is the React
215
+ * #418 hydration fix, not an oversight: do not "fix the timezone" by making it
216
+ * render local — that produces a different wrong answer, one that also differs
217
+ * between server and client.
218
+ */
219
+ function programDateInstant(item: BaseProgramItem): { instant: string | null; timezone: string | null } {
220
+ const timezone = 'timezone' in item ? programStr(item.timezone) : null;
221
+ if (!timezone) return { instant: null, timezone: null };
222
+ // Prefer the scheduling instant the TIME is read from, so the two halves
223
+ // cannot disagree even if `item.date` carries a display override upstream.
224
+ const startAt = 'start_at' in item ? programStr(item.start_at) : null;
225
+ return { instant: startAt ?? programStr(item.date), timezone };
226
+ }
227
+
197
228
  function MediaGallery({ images, title }: { images: ProgramMedia[]; title: string }) {
198
229
  const [selectedImageIndex, setSelectedImageIndex] = useState<number | null>(null);
199
230
  const [isModalOpen, setIsModalOpen] = useState(false);
@@ -293,13 +324,18 @@ export function ProgramCard<T extends BaseProgramItem>({
293
324
  if (typeof loc === 'string' && loc.trim().length > 0) return loc;
294
325
  } else if (config.type === 'webinar' && 'start_at' in item) {
295
326
  const { startAt, endAt, timezone } = webinarTiming(item);
296
- const time = formatTimeWithTimezone(startAt, timezone);
327
+ // Compact densities join plain strings, so the zone rides inline here;
328
+ // the default density renders it as its own styled span instead.
329
+ const time = formatTimeWithTimezone(startAt, timezone, { withZoneLabel: true });
297
330
  const dur = formatDurationFromRange(startAt, endAt);
298
331
  return dur ? `${time} · ${dur}` : time;
299
332
  }
300
333
  return null;
301
334
  };
302
- const compactDate = formatUtc(new Date(item.date), 'MMM d, yyyy');
335
+ const zonedDate = programDateInstant(item);
336
+ const compactDate = zonedDate.instant
337
+ ? formatDateWithTimezone(zonedDate.instant, zonedDate.timezone, 'medium')
338
+ : formatUtc(new Date(item.date), 'MMM d, yyyy');
303
339
 
304
340
  if (size === 'portrait') {
305
341
  // Rail/strip density — mapped onto the shared <EntityPortraitCard> shell
@@ -378,7 +414,9 @@ export function ProgramCard<T extends BaseProgramItem>({
378
414
  }
379
415
 
380
416
  const itemDate = new Date(item.date);
381
- const dateFormat = formatUtc(itemDate, 'EEEE d MMMM');
417
+ const dateFormat = zonedDate.instant
418
+ ? formatDateWithTimezone(zonedDate.instant, zonedDate.timezone, 'weekday')
419
+ : formatUtc(itemDate, 'EEEE d MMMM');
382
420
 
383
421
  const defaultRenderMeta = () => {
384
422
  if (config.type === 'podcast' && 'duration_seconds' in item && !isScheduled) {
@@ -0,0 +1,91 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { formatDateWithTimezone, formatDurationFromRange, formatTimeWithTimezone } from '../format';
4
+
5
+ /**
6
+ * These three formatters render the date, time and duration of ONE event, side
7
+ * by side on the program card. They had no coverage at all, which is how a
8
+ * missing sign guard shipped: a live webinar row whose `end_at` preceded its
9
+ * `start_at` printed "-45m" on the card.
10
+ */
11
+ describe('formatDurationFromRange', () => {
12
+ it('formats a positive range', () => {
13
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T00:45:00Z')).toBe('45m');
14
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T01:30:00Z')).toBe('1h 30m');
15
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T02:00:00Z')).toBe('2h');
16
+ });
17
+
18
+ it('renders NOTHING when the event ends before it starts', () => {
19
+ // The live row that produced the bug report: e6cff6f8, end_at 45 minutes
20
+ // before start_at. It used to render "-45m" — and note that a -90 minute
21
+ // range never reached the `>= 60` branch, so it printed "-90m" rather than
22
+ // "-1h 30m": the output was not merely wrong, it was inconsistently wrong.
23
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-19T23:15:25Z')).toBe('');
24
+ expect(formatDurationFromRange('2026-03-20T02:00:00Z', '2026-03-20T00:30:00Z')).toBe('');
25
+ });
26
+
27
+ it('renders nothing for a zero-length or unparseable range', () => {
28
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T00:00:00Z')).toBe('');
29
+ // Used to print the literal string "NaNm".
30
+ expect(formatDurationFromRange('not-a-date', '2026-03-20T00:00:00Z')).toBe('');
31
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', 'not-a-date')).toBe('');
32
+ });
33
+
34
+ it('renders nothing when an endpoint is missing', () => {
35
+ expect(formatDurationFromRange(null, '2026-03-20T00:00:00Z')).toBe('');
36
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', undefined)).toBe('');
37
+ });
38
+ });
39
+
40
+ describe('formatDateWithTimezone / formatTimeWithTimezone agree on the zone', () => {
41
+ // The reported defect: the card printed the date in UTC and the time beside
42
+ // it in the event's own zone, so this instant read "Mar 20, 2026 · 9:18 PM"
43
+ // — 9:18 PM on the 20th is not when it happens, 9:18 PM on the 19th is.
44
+ const instant = '2026-03-20T01:18:00Z';
45
+ const zone = 'America/New_York';
46
+
47
+ it('puts the date on the event-local day, not the UTC day', () => {
48
+ expect(formatDateWithTimezone(instant, zone)).toBe('Mar 19, 2026');
49
+ expect(formatTimeWithTimezone(instant, zone)).toBe('9:18 PM');
50
+ });
51
+
52
+ it('renders the weekday style in the same zone', () => {
53
+ // Note the copy shift: the default density used to build this from the
54
+ // date-fns pattern 'EEEE d MMMM' ("Thursday 19 March"). Intl's en-US order
55
+ // is "Thursday, March 19". Preserving the old wording would mean composing
56
+ // the string from Intl parts by hand — re-introducing exactly the bespoke
57
+ // date arithmetic this change exists to remove — so the locale-correct
58
+ // form wins, consistent with every other formatter in this file.
59
+ expect(formatDateWithTimezone(instant, zone, 'weekday')).toBe('Thursday, March 19');
60
+ });
61
+
62
+ it('falls back to UTC on both halves when no zone is given', () => {
63
+ expect(formatDateWithTimezone(instant, null)).toBe('Mar 20, 2026');
64
+ expect(formatTimeWithTimezone(instant, null)).toBe('1:18 AM');
65
+ });
66
+
67
+ it('handles a legacy fixed-offset label consistently across both halves', () => {
68
+ // "EST" does NOT throw — Node resolves it as a legacy fixed UTC-5 alias, so
69
+ // it lands on the 19th at 8:18 PM (no DST, unlike America/New_York's EDT).
70
+ // What matters is that the date and the time agree about the zone.
71
+ expect(formatDateWithTimezone(instant, 'EST')).toBe('Mar 19, 2026');
72
+ expect(formatTimeWithTimezone(instant, 'EST')).toBe('8:18 PM');
73
+ });
74
+
75
+ it('degrades BOTH halves to UTC on a genuinely invalid zone', () => {
76
+ // A label Intl cannot resolve DOES throw a RangeError. Both formatters must
77
+ // catch it the same way, or the pair disagrees about which zone it used.
78
+ expect(formatDateWithTimezone(instant, 'Not/AZone')).toBe('Mar 20, 2026');
79
+ expect(formatTimeWithTimezone(instant, 'Not/AZone')).toBe('1:18 AM');
80
+ });
81
+
82
+ it('appends the zone label only when asked', () => {
83
+ expect(formatTimeWithTimezone(instant, zone, { withZoneLabel: true })).toBe('9:18 PM EDT');
84
+ });
85
+
86
+ it('renders nothing for a missing or unparseable date', () => {
87
+ expect(formatDateWithTimezone(null, zone)).toBe('');
88
+ expect(formatDateWithTimezone('not-a-date', zone)).toBe('');
89
+ expect(formatTimeWithTimezone('not-a-date', zone)).toBe('');
90
+ });
91
+ });
@@ -273,35 +273,105 @@ export function formatDurationCompact(seconds: number | null | undefined): strin
273
273
  * fixing the React #418 hydration mismatch — AND shows the true event time
274
274
  * (4:00 PM EDT, not the 8:00 PM UTC a plain UTC pin would show, nor the
275
275
  * viewer-local time the old unpinned call produced). Falls back to UTC when no
276
- * zone is given, and tolerates a non-IANA label (legacy data) without throwing.
277
- * The zone LABEL is rendered separately by callers, so it is never appended here.
276
+ * zone is given, and tolerates an unresolvable label (legacy data) without throwing.
277
+ * The zone LABEL is rendered separately by callers that have room for their own
278
+ * styled span; pass `withZoneLabel` where the output is a plain joined string
279
+ * (the compact card densities) and the short name is appended inline — an
280
+ * unlabelled wall clock beside a date is readable but still ambiguous about
281
+ * WHICH zone it is stating.
278
282
  *
279
- * Returns: "4:00 PM"
283
+ * Returns: "4:00 PM", or "4:00 PM EDT" with `withZoneLabel`.
280
284
  */
281
- export function formatTimeWithTimezone(date: Date | string | null | undefined, timezone?: string | null): string {
285
+ export function formatTimeWithTimezone(
286
+ date: Date | string | null | undefined,
287
+ timezone?: string | null,
288
+ options?: { withZoneLabel?: boolean },
289
+ ): string {
282
290
  if (!date) return '';
283
291
 
284
292
  const dateObj = typeof date === 'string' ? new Date(date) : date;
293
+ if (Number.isNaN(dateObj.getTime())) return '';
285
294
  const opts: Intl.DateTimeFormatOptions = {
286
295
  hour: 'numeric',
287
296
  minute: '2-digit',
288
297
  hour12: true,
289
298
  timeZone: timezone || 'UTC',
299
+ ...(options?.withZoneLabel ? { timeZoneName: 'short' as const } : {}),
290
300
  };
291
301
  try {
292
302
  return dateObj.toLocaleTimeString('en-US', opts);
293
303
  } catch {
294
- // Non-IANA `timezone` (e.g. a bare "EST" label) makes Intl throw a
295
- // RangeError. Fall back to a UTC-pinned render so we stay deterministic
296
- // (still no #418) instead of crashing.
304
+ // An UNRESOLVABLE `timezone` makes Intl throw a RangeError. Fall back to a
305
+ // UTC-pinned render so we stay deterministic (still no #418) instead of
306
+ // crashing. Note a bare "EST" does NOT land here: Node resolves it as a
307
+ // legacy fixed UTC-5 alias, which is a different wall clock from
308
+ // America/New_York whenever DST is in effect — a data problem, not a
309
+ // crash, and not one this catch can see.
297
310
  return dateObj.toLocaleTimeString('en-US', { ...opts, timeZone: 'UTC' });
298
311
  }
299
312
  }
300
313
 
314
+ /**
315
+ * Format a webinar/event DATE as the calendar day in its OWN timezone — the
316
+ * sibling of `formatTimeWithTimezone`, and the reason it exists.
317
+ *
318
+ * A card that prints the date in UTC and the time beside it in the event's zone
319
+ * can name a moment that never existed: a webinar at `2026-03-20T01:18Z` in
320
+ * `America/New_York` read "Mar 20, 2026 · 9:18 PM" — 9:18 PM on the 20th is not
321
+ * when it happens, 9:18 PM on the 19th is. Both halves of one timestamp must be
322
+ * rendered in ONE zone. Same UTC fallback and same non-IANA tolerance as the
323
+ * time formatter, so the pair can never disagree about which zone it used.
324
+ *
325
+ * `style` picks the two shapes the program cards actually render:
326
+ * `'medium'` → "Mar 19, 2026" (compact densities), `'weekday'` →
327
+ * "Thursday 19 March" (default density).
328
+ *
329
+ * Returns: "Mar 19, 2026"
330
+ */
331
+ export type ZonedDateStyle = 'medium' | 'weekday';
332
+
333
+ const ZONED_DATE_STYLES: Record<ZonedDateStyle, Intl.DateTimeFormatOptions> = {
334
+ medium: { year: 'numeric', month: 'short', day: 'numeric' },
335
+ weekday: { weekday: 'long', day: 'numeric', month: 'long' },
336
+ };
337
+
338
+ export function formatDateWithTimezone(
339
+ date: Date | string | null | undefined,
340
+ timezone?: string | null,
341
+ style: ZonedDateStyle = 'medium',
342
+ ): string {
343
+ if (!date) return '';
344
+
345
+ const dateObj = typeof date === 'string' ? new Date(date) : date;
346
+ if (Number.isNaN(dateObj.getTime())) return '';
347
+ const opts: Intl.DateTimeFormatOptions = {
348
+ ...ZONED_DATE_STYLES[style],
349
+ timeZone: timezone || 'UTC',
350
+ };
351
+ try {
352
+ return dateObj.toLocaleDateString('en-US', opts);
353
+ } catch {
354
+ // An unresolvable `timezone` throws a RangeError — same tolerance as
355
+ // `formatTimeWithTimezone`, so a bad row degrades to UTC on BOTH halves
356
+ // rather than only one, which is the whole point of the pair.
357
+ return dateObj.toLocaleDateString('en-US', { ...opts, timeZone: 'UTC' });
358
+ }
359
+ }
360
+
301
361
  /**
302
362
  * Calculate and format duration between two timestamps
303
363
  * Used for webinar durations
304
364
  * Returns: "1h 30m" or "45m"
365
+ *
366
+ * Returns `''` — the same "nothing to show" this function already returns for a
367
+ * missing endpoint — when the range is not a positive, real duration. An event
368
+ * whose `end_at` precedes its `start_at` is corrupt data, and the unguarded
369
+ * subtraction printed it literally: a live webinar row rendered "-45m" on the
370
+ * card. An unparseable timestamp printed "NaNm" the same way. A renderer shows
371
+ * nothing rather than an impossible value; the write path is what must reject
372
+ * the row. (Note the negative case never even reached the `>= 60` branch, so
373
+ * -90 minutes rendered as "-90m" rather than "-1h 30m" — the output was not
374
+ * just wrong, it was inconsistently wrong.)
305
375
  */
306
376
  export function formatDurationFromRange(
307
377
  startAt: string | Date | null | undefined,
@@ -312,7 +382,9 @@ export function formatDurationFromRange(
312
382
  const start = typeof startAt === 'string' ? new Date(startAt) : startAt;
313
383
  const end = typeof endAt === 'string' ? new Date(endAt) : endAt;
314
384
  const durationMs = end.getTime() - start.getTime();
385
+ if (!Number.isFinite(durationMs) || durationMs <= 0) return '';
315
386
  const minutes = Math.round(durationMs / 60000);
387
+ if (minutes <= 0) return '';
316
388
 
317
389
  if (minutes >= 60) {
318
390
  const hours = Math.floor(minutes / 60);
@@ -138,6 +138,8 @@ export {
138
138
  formatDurationMMSS,
139
139
  formatDurationCompact,
140
140
  formatTimeWithTimezone,
141
+ formatDateWithTimezone,
142
+ type ZonedDateStyle,
141
143
  formatDurationFromRange,
142
144
  type FormatDateUTCOptions,
143
145
  formatDateUTC,