@flamingo-stack/openframe-frontend-core 0.0.643 → 0.0.644-2208.6319.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.
- package/dist/chat-protocol/index.cjs +20 -3
- package/dist/chat-protocol/index.cjs.map +1 -1
- package/dist/chat-protocol/index.js +20 -3
- package/dist/chat-protocol/index.js.map +1 -1
- package/dist/chat-protocol/source-metadata.d.ts +7 -1
- package/dist/chat-protocol/source-metadata.d.ts.map +1 -1
- package/dist/{chunk-B42INNRA.cjs → chunk-2UA3DT5O.cjs} +199 -199
- package/dist/{chunk-B42INNRA.cjs.map → chunk-2UA3DT5O.cjs.map} +1 -1
- package/dist/{chunk-KX2FT7AS.cjs → chunk-2ZGEXLQW.cjs} +28 -28
- package/dist/{chunk-KX2FT7AS.cjs.map → chunk-2ZGEXLQW.cjs.map} +1 -1
- package/dist/{chunk-2NRLRRMR.cjs → chunk-3HSRNCDV.cjs} +226 -203
- package/dist/chunk-3HSRNCDV.cjs.map +1 -0
- package/dist/{chunk-64KDKDYC.js → chunk-5ELZ2NQ5.js} +6 -6
- package/dist/{chunk-2DJH6KHA.cjs → chunk-B46Q4DTN.cjs} +382 -386
- package/dist/chunk-B46Q4DTN.cjs.map +1 -0
- package/dist/{chunk-N7UYD57Q.js → chunk-C7RU466R.js} +3 -3
- package/dist/{chunk-2NODQ7FO.js → chunk-DSJZYRS6.js} +17 -21
- package/dist/{chunk-2NODQ7FO.js.map → chunk-DSJZYRS6.js.map} +1 -1
- package/dist/{chunk-26D6FM6L.cjs → chunk-EKSCVXA3.cjs} +6 -6
- package/dist/{chunk-26D6FM6L.cjs.map → chunk-EKSCVXA3.cjs.map} +1 -1
- package/dist/{chunk-7HL2PNQ3.js → chunk-GEGE3JXC.js} +5 -5
- package/dist/{chunk-7T673MHJ.cjs → chunk-GUB6BR26.cjs} +22 -22
- package/dist/{chunk-7T673MHJ.cjs.map → chunk-GUB6BR26.cjs.map} +1 -1
- package/dist/{chunk-3IPL6G7S.js → chunk-GXNQPCL4.js} +164 -141
- package/dist/chunk-GXNQPCL4.js.map +1 -0
- package/dist/{chunk-D6TWJEFW.cjs → chunk-GZXW5QWQ.cjs} +15 -15
- package/dist/{chunk-D6TWJEFW.cjs.map → chunk-GZXW5QWQ.cjs.map} +1 -1
- package/dist/{chunk-4TE53O6U.js → chunk-HAQRGJFL.js} +4 -4
- package/dist/{chunk-TIOHTWDA.js → chunk-INISTVWK.js} +6 -6
- package/dist/{chunk-IU3IYXMM.js → chunk-IRV2W7GN.js} +7 -7
- package/dist/{chunk-R2IU2Y2O.cjs → chunk-JWCAWGLG.cjs} +33 -33
- package/dist/{chunk-R2IU2Y2O.cjs.map → chunk-JWCAWGLG.cjs.map} +1 -1
- package/dist/{chunk-77EO26XV.cjs → chunk-LNLNPCII.cjs} +5 -5
- package/dist/{chunk-77EO26XV.cjs.map → chunk-LNLNPCII.cjs.map} +1 -1
- package/dist/{chunk-42NXGOTG.cjs → chunk-N3M56EE5.cjs} +3 -3
- package/dist/{chunk-42NXGOTG.cjs.map → chunk-N3M56EE5.cjs.map} +1 -1
- package/dist/{chunk-O7JMF5OT.js → chunk-O47SGDBV.js} +3 -3
- package/dist/{chunk-EWQI5MV6.cjs → chunk-OANRA5ML.cjs} +20 -20
- package/dist/{chunk-EWQI5MV6.cjs.map → chunk-OANRA5ML.cjs.map} +1 -1
- package/dist/{chunk-NCHLLTAR.js → chunk-PR6IR22M.js} +3 -3
- package/dist/{chunk-6MQBLFUM.js → chunk-Q7JDIDE2.js} +5 -5
- package/dist/{chunk-YG7KLZE7.js → chunk-R5EIFOW2.js} +4 -4
- package/dist/{chunk-5E6Y6766.cjs → chunk-S2E4I3WP.cjs} +29 -29
- package/dist/{chunk-5E6Y6766.cjs.map → chunk-S2E4I3WP.cjs.map} +1 -1
- package/dist/{chunk-SE6YRE3R.cjs → chunk-SAD5IUSO.cjs} +32 -32
- package/dist/{chunk-SE6YRE3R.cjs.map → chunk-SAD5IUSO.cjs.map} +1 -1
- package/dist/{chunk-3LXJEXPH.js → chunk-TAP4MJPF.js} +2 -2
- package/dist/{chunk-M3W5Y5DK.cjs → chunk-TEKH3J65.cjs} +11 -11
- package/dist/{chunk-M3W5Y5DK.cjs.map → chunk-TEKH3J65.cjs.map} +1 -1
- package/dist/{chunk-HA2U7WHU.js → chunk-TXNWDP3M.js} +3 -3
- package/dist/{chunk-IIZX3K2R.js → chunk-URGDDCJL.js} +2 -2
- package/dist/{chunk-TQ7KTANJ.js → chunk-V52INSJH.js} +3 -3
- package/dist/{chunk-FO7SD2IQ.cjs → chunk-VA6N7IVZ.cjs} +6 -6
- package/dist/{chunk-FO7SD2IQ.cjs.map → chunk-VA6N7IVZ.cjs.map} +1 -1
- package/dist/{chunk-CWHLVXUW.cjs → chunk-WYS66RIO.cjs} +10 -10
- package/dist/{chunk-CWHLVXUW.cjs.map → chunk-WYS66RIO.cjs.map} +1 -1
- package/dist/{chunk-XJLWGYL4.cjs → chunk-XVGWYNRY.cjs} +81 -81
- package/dist/{chunk-XJLWGYL4.cjs.map → chunk-XVGWYNRY.cjs.map} +1 -1
- package/dist/{chunk-ZU2JBBOE.cjs → chunk-XYJ3URIN.cjs} +59 -59
- package/dist/{chunk-ZU2JBBOE.cjs.map → chunk-XYJ3URIN.cjs.map} +1 -1
- package/dist/{chunk-FVIT23I5.js → chunk-Z5KAIEZ4.js} +3 -3
- package/dist/{chunk-YT6RGA3X.js → chunk-ZPLT4XLC.js} +3 -3
- package/dist/components/case-studies/index.cjs +16 -16
- package/dist/components/case-studies/index.js +4 -4
- package/dist/components/chat/entity-cards/dispatch.d.ts.map +1 -1
- package/dist/components/chat/entity-cards/program-card.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +3 -9
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +2 -8
- package/dist/components/chat/types/entities/program-types.d.ts +29 -18
- package/dist/components/chat/types/entities/program-types.d.ts.map +1 -1
- package/dist/components/chat/utils/compact-card-classes.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +5 -5
- package/dist/components/contact/index.js +4 -4
- package/dist/components/docs/index.cjs +8 -8
- package/dist/components/docs/index.js +7 -7
- package/dist/components/embeds/index.cjs +5 -5
- package/dist/components/embeds/index.js +4 -4
- package/dist/components/faq/index.cjs +5 -5
- package/dist/components/faq/index.js +4 -4
- package/dist/components/features/index.cjs +4 -4
- package/dist/components/features/index.js +3 -3
- package/dist/components/help-center-pages/index.cjs +24 -24
- package/dist/components/help-center-pages/index.js +15 -15
- package/dist/components/index.cjs +53 -59
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +15 -21
- package/dist/components/index.js.map +1 -1
- package/dist/components/meeting-scheduler/index.cjs +34 -34
- package/dist/components/meeting-scheduler/index.js +3 -3
- package/dist/components/navigation/index.cjs +7 -7
- package/dist/components/navigation/index.js +6 -6
- package/dist/components/onboarding-guides/index.cjs +7 -7
- package/dist/components/onboarding-guides/index.js +6 -6
- package/dist/components/related-content/index.cjs +3 -3
- package/dist/components/related-content/index.js +2 -2
- package/dist/components/tickets/index.cjs +8 -8
- package/dist/components/tickets/index.js +7 -7
- package/dist/components/ui/index.cjs +4 -10
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +3 -9
- package/dist/index.cjs +24 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -14
- package/dist/index.js.map +1 -1
- package/dist/utils/format.d.ts +127 -4
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/index.cjs +113 -5
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +103 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/program-instant.d.ts +171 -0
- package/dist/utils/program-instant.d.ts.map +1 -0
- package/dist/utils/program-meta-renderers.d.ts +3 -0
- package/dist/utils/program-meta-renderers.d.ts.map +1 -0
- package/dist/utils/url-safety.d.ts +35 -0
- package/dist/utils/url-safety.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/chat-protocol/__tests__/source-metadata.test.ts +76 -0
- package/src/chat-protocol/source-metadata.ts +40 -6
- package/src/components/chat/entity-cards/.program-card.md +1 -1
- package/src/components/chat/entity-cards/dispatch.tsx +9 -27
- package/src/components/chat/entity-cards/program-card.tsx +42 -81
- package/src/components/chat/types/entities/program-types.ts +29 -89
- package/src/components/chat/utils/.compact-card-classes.md +1 -1
- package/src/components/chat/utils/compact-card-classes.ts +5 -3
- package/src/utils/.format.md +5 -2
- package/src/utils/__tests__/format-program-dates.test.ts +180 -0
- package/src/utils/__tests__/program-instant.test.ts +170 -0
- package/src/utils/__tests__/url-safety.test.ts +44 -0
- package/src/utils/format.ts +228 -13
- package/src/utils/index.ts +22 -0
- package/src/utils/program-instant.ts +211 -0
- package/src/utils/program-meta-renderers.ts +18 -0
- package/src/utils/url-safety.ts +45 -0
- package/dist/chunk-2DJH6KHA.cjs.map +0 -1
- package/dist/chunk-2NRLRRMR.cjs.map +0 -1
- package/dist/chunk-3IPL6G7S.js.map +0 -1
- /package/dist/{chunk-64KDKDYC.js.map → chunk-5ELZ2NQ5.js.map} +0 -0
- /package/dist/{chunk-N7UYD57Q.js.map → chunk-C7RU466R.js.map} +0 -0
- /package/dist/{chunk-7HL2PNQ3.js.map → chunk-GEGE3JXC.js.map} +0 -0
- /package/dist/{chunk-4TE53O6U.js.map → chunk-HAQRGJFL.js.map} +0 -0
- /package/dist/{chunk-TIOHTWDA.js.map → chunk-INISTVWK.js.map} +0 -0
- /package/dist/{chunk-IU3IYXMM.js.map → chunk-IRV2W7GN.js.map} +0 -0
- /package/dist/{chunk-O7JMF5OT.js.map → chunk-O47SGDBV.js.map} +0 -0
- /package/dist/{chunk-NCHLLTAR.js.map → chunk-PR6IR22M.js.map} +0 -0
- /package/dist/{chunk-6MQBLFUM.js.map → chunk-Q7JDIDE2.js.map} +0 -0
- /package/dist/{chunk-YG7KLZE7.js.map → chunk-R5EIFOW2.js.map} +0 -0
- /package/dist/{chunk-3LXJEXPH.js.map → chunk-TAP4MJPF.js.map} +0 -0
- /package/dist/{chunk-HA2U7WHU.js.map → chunk-TXNWDP3M.js.map} +0 -0
- /package/dist/{chunk-IIZX3K2R.js.map → chunk-URGDDCJL.js.map} +0 -0
- /package/dist/{chunk-TQ7KTANJ.js.map → chunk-V52INSJH.js.map} +0 -0
- /package/dist/{chunk-FVIT23I5.js.map → chunk-Z5KAIEZ4.js.map} +0 -0
- /package/dist/{chunk-YT6RGA3X.js.map → chunk-ZPLT4XLC.js.map} +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
formatDateWithTimezone,
|
|
5
|
+
formatDurationCompact,
|
|
6
|
+
formatProgramDate,
|
|
7
|
+
formatProgramTimeRange,
|
|
8
|
+
formatTimeWithTimezone,
|
|
9
|
+
formatWebinarTimeMeta,
|
|
10
|
+
} from '../format';
|
|
11
|
+
import { programDateInstant, programMetaLine } from '../program-instant';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The rule every program surface renders by. It lived as prose in two
|
|
15
|
+
* components that "mirrored" each other, and they drifted: the public card was
|
|
16
|
+
* fixed while the chat card kept rendering the date in the VIEWER's zone beside
|
|
17
|
+
* a time in the EVENT's zone. One owner, pinned here.
|
|
18
|
+
*/
|
|
19
|
+
describe('programDateInstant', () => {
|
|
20
|
+
const zoned = {
|
|
21
|
+
date: '2026-03-20T01:18:00.000Z',
|
|
22
|
+
start_at: '2026-03-20T01:18:00.000Z',
|
|
23
|
+
timezone: 'America/New_York',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
it('renders date and time from ONE instant in ONE zone', () => {
|
|
27
|
+
const r = programDateInstant(zoned);
|
|
28
|
+
expect(r.instant).toBe('2026-03-20T01:18:00.000Z');
|
|
29
|
+
expect(r.timezone).toBe('America/New_York');
|
|
30
|
+
// 01:18Z is 9:18 PM on the 19th in New York — both halves must say the 19th.
|
|
31
|
+
expect(formatDateWithTimezone(r.instant, r.timezone)).toBe('Mar 19, 2026');
|
|
32
|
+
expect(formatTimeWithTimezone(r.instant, r.timezone)).toBe('9:18 PM');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('prefers item.date, so an admin display override moves the card', () => {
|
|
36
|
+
// item.date is the host-resolved instant with the override already applied.
|
|
37
|
+
const r = programDateInstant({ ...zoned, date: '2026-02-09T15:00:00.000Z' });
|
|
38
|
+
expect(r.instant).toBe('2026-02-09T15:00:00.000Z');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('falls back to start_at when the item carries no resolved date', () => {
|
|
42
|
+
expect(programDateInstant({ start_at: '2026-03-20T01:18:00.000Z', timezone: 'America/New_York' }).instant).toBe(
|
|
43
|
+
'2026-03-20T01:18:00.000Z',
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('keeps the UTC pin when the row declares no zone (React #418)', () => {
|
|
48
|
+
// Returning an instant here would let a caller render viewer-local, which
|
|
49
|
+
// differs between server and client.
|
|
50
|
+
expect(programDateInstant({ date: '2026-03-20T01:18:00.000Z' }).instant).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('flags an admin display override — the shape a producer ACTUALLY emits', () => {
|
|
54
|
+
// This is what the DAL hands over: the override column is timestamptz and
|
|
55
|
+
// the route normalizes through toISOString(), so the value is a FULL
|
|
56
|
+
// INSTANT. An earlier version of this test hand-built a bare `YYYY-MM-DD`
|
|
57
|
+
// row that no producer can emit, which made it pass while the bug it named
|
|
58
|
+
// stayed live.
|
|
59
|
+
const r = programDateInstant({
|
|
60
|
+
date: '2026-03-19T00:00:00.000Z',
|
|
61
|
+
start_at: '2026-04-01T20:00:00.000Z',
|
|
62
|
+
timezone: 'America/New_York',
|
|
63
|
+
date_is_display_override: true,
|
|
64
|
+
});
|
|
65
|
+
expect(r.dateOnly).toBe(true);
|
|
66
|
+
// The resolved value carries NO ZONE, so a consumer cannot render or label
|
|
67
|
+
// one. Three surfaces had to remember that gate and two forgot; nulling it
|
|
68
|
+
// makes the mistake unrepresentable rather than merely documented.
|
|
69
|
+
expect(r.timezone).toBeNull();
|
|
70
|
+
// The admin who asked for March 19 sees March 19 — not March 18 at 8 PM,
|
|
71
|
+
// which is what a zoned render of UTC midnight gives.
|
|
72
|
+
expect(formatProgramDate(r)).toBe('Mar 19, 2026');
|
|
73
|
+
// ...and that is true precisely BECAUSE the zone was dropped: rendering the
|
|
74
|
+
// same value in the row's declared zone still lands on the 18th.
|
|
75
|
+
expect(formatDateWithTimezone(r.utcDate, 'America/New_York')).toBe('Mar 18, 2026');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('renders the same shape whether or not the row declares a zone', () => {
|
|
79
|
+
// The UTC fallback used to be a separate date-fns branch at each call site,
|
|
80
|
+
// and it emitted a DIFFERENT SHAPE ("Thursday 19 March" vs "Thursday,
|
|
81
|
+
// March 19"), so whether a row happened to carry a zone decided how its
|
|
82
|
+
// headline read.
|
|
83
|
+
const withZone = formatProgramDate(programDateInstant(zoned), 'weekday');
|
|
84
|
+
const withoutZone = formatProgramDate(programDateInstant({ date: '2026-03-19T12:00:00.000Z' }), 'weekday');
|
|
85
|
+
expect(withZone).toBe('Thursday, March 19');
|
|
86
|
+
expect(withoutZone).toBe('Thursday, March 19');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('treats a real timestamp as an instant', () => {
|
|
90
|
+
expect(programDateInstant(zoned).dateOnly).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The compact meta line. The public card and the chat card built this
|
|
96
|
+
* separately, under a comment saying the second "mirrors" the first — and it
|
|
97
|
+
* drifted twice, each time only on the copy nobody was looking at.
|
|
98
|
+
*/
|
|
99
|
+
describe('programMetaLine', () => {
|
|
100
|
+
const FMT = {
|
|
101
|
+
date: (at: ReturnType<typeof programDateInstant>) => formatProgramDate(at, 'medium'),
|
|
102
|
+
duration: formatDurationCompact,
|
|
103
|
+
webinarMeta: (at: ReturnType<typeof programDateInstant>, o: { startAt: string | null; endAt: string | null }) =>
|
|
104
|
+
formatWebinarTimeMeta(at, { ...o, withZoneLabel: true }),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
it('a webinar: day, clock and duration, all from one instant', () => {
|
|
108
|
+
const { line } = programMetaLine(
|
|
109
|
+
{
|
|
110
|
+
date: '2026-03-20T01:18:00.000Z',
|
|
111
|
+
start_at: '2026-03-20T01:18:00.000Z',
|
|
112
|
+
end_at: '2026-03-20T02:03:00.000Z',
|
|
113
|
+
timezone: 'America/New_York',
|
|
114
|
+
},
|
|
115
|
+
'webinar',
|
|
116
|
+
FMT,
|
|
117
|
+
);
|
|
118
|
+
expect(line).toBe('Mar 19, 2026 · 9:18 PM EDT · 45m');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('an overridden webinar: the chosen day, no clock, no zone', () => {
|
|
122
|
+
const { line } = programMetaLine(
|
|
123
|
+
{
|
|
124
|
+
date: '2026-01-05T00:00:00.000Z',
|
|
125
|
+
start_at: '2026-03-20T01:18:00.000Z',
|
|
126
|
+
end_at: '2026-03-20T02:03:00.000Z',
|
|
127
|
+
timezone: 'America/New_York',
|
|
128
|
+
date_is_display_override: true,
|
|
129
|
+
},
|
|
130
|
+
'webinar',
|
|
131
|
+
FMT,
|
|
132
|
+
);
|
|
133
|
+
expect(line).toBe('Jan 5, 2026 · 45m');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('a scheduled podcast does not present its stored duration as elapsed time', () => {
|
|
137
|
+
const row = { date: '2026-03-20T01:18:00.000Z', duration_seconds: 1800 };
|
|
138
|
+
expect(programMetaLine(row, 'podcast', FMT).typeMeta).not.toBeNull();
|
|
139
|
+
expect(programMetaLine({ ...row, status: 'scheduled' }, 'podcast', FMT).typeMeta).toBeNull();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('an event falls back to nothing rather than a blank separator', () => {
|
|
143
|
+
const { line } = programMetaLine({ date: '2026-03-20T01:18:00.000Z', location_name: ' ' }, 'event', FMT);
|
|
144
|
+
// No zone on this row, so the day is UTC-pinned (the React #418 rule) —
|
|
145
|
+
// and a whitespace-only location contributes nothing at all.
|
|
146
|
+
expect(line).toBe('Mar 20, 2026');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('formatProgramTimeRange', () => {
|
|
151
|
+
it('an end with no usable start says nothing, rather than showing a FINISH as a start', () => {
|
|
152
|
+
const at = programDateInstant({ timezone: 'America/New_York' });
|
|
153
|
+
expect(formatProgramTimeRange(at, { endAt: '2026-03-20T17:00:00Z' })).toBe('');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('refuses an inverted range, keeping the start that is still true', () => {
|
|
157
|
+
// The sibling duration formatter already refuses this — a card once shipped
|
|
158
|
+
// "-45m" — and rendering "11:00 PM - 9:00 PM" is the same impossible value
|
|
159
|
+
// one field over. Luma has no ingest guard against it.
|
|
160
|
+
const at = programDateInstant({ date: '2026-03-20T03:00:00Z', timezone: 'America/New_York' });
|
|
161
|
+
expect(formatProgramTimeRange(at, { endAt: '2026-03-20T01:00:00Z', withZoneLabel: true })).toBe('11:00 PM EDT');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('labels only the last clock of a range', () => {
|
|
165
|
+
const at = programDateInstant({ date: '2026-03-20T13:00:00Z', timezone: 'America/New_York' });
|
|
166
|
+
expect(formatProgramTimeRange(at, { endAt: '2026-03-20T17:00:00Z', withZoneLabel: true })).toBe(
|
|
167
|
+
'9:00 AM - 1:00 PM EDT',
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { safeHref } from '../../components/chat/utils/compact-card-classes';
|
|
4
|
+
import { UNSAFE_URL_CHARS, isSameOriginPath } from '../url-safety';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shared URL-safety predicate, tested once for BOTH callers — the wire
|
|
8
|
+
* decoder (`linkUrl`) and the render-time guard (`safeHref`). They used to hold
|
|
9
|
+
* their own copies, kept in sync by a comment, and the copies already disagreed
|
|
10
|
+
* on the backslash case: a single-slash path that the URL parser resolves to a
|
|
11
|
+
* third-party origin passed every "starts with exactly one slash" check and
|
|
12
|
+
* reached an anchor tag.
|
|
13
|
+
*/
|
|
14
|
+
describe('isSameOriginPath', () => {
|
|
15
|
+
const escapes = ['/\\evil.test/x', '/\\\\evil.test/x', '//evil.test/x', '/\\/evil.test/x', 'https://evil.test/x'];
|
|
16
|
+
|
|
17
|
+
it.each(escapes)('rejects %s — it does not stay on this origin', href => {
|
|
18
|
+
expect(isSameOriginPath(href)).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it.each(['/ok/x', '/a/b?q=1#frag', '/%2Fnot-an-authority', '/'])('accepts %s', href => {
|
|
22
|
+
expect(isSameOriginPath(href)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('safeHref uses the same rule', () => {
|
|
27
|
+
it('rejects the backslash escape the decoder rejects', () => {
|
|
28
|
+
expect(safeHref('/\\evil.test/x')).toBeNull();
|
|
29
|
+
expect(safeHref('//evil.test/x')).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('still accepts what it is supposed to', () => {
|
|
33
|
+
expect(safeHref('/onboarding-guides/x')).toBe('/onboarding-guides/x');
|
|
34
|
+
expect(safeHref('#section')).toBe('#section');
|
|
35
|
+
expect(safeHref('https://x.test/a')).toBe('https://x.test/a');
|
|
36
|
+
expect(safeHref('mailto:a@b.test')).toBe('mailto:a@b.test');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('rejects control and zero-width characters', () => {
|
|
40
|
+
expect(UNSAFE_URL_CHARS.test('/a' + String.fromCharCode(0) + 'b')).toBe(true);
|
|
41
|
+
expect(safeHref('/a' + String.fromCharCode(0x200b) + 'b')).toBeNull();
|
|
42
|
+
expect(UNSAFE_URL_CHARS.test('/ordinary/path')).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
package/src/utils/format.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Utility functions for formatting data
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import type { ProgramInstant } from './program-instant';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Format a date to a human-readable string
|
|
7
9
|
* @param date - The date to format (Date object or ISO string)
|
|
@@ -273,46 +275,170 @@ export function formatDurationCompact(seconds: number | null | undefined): strin
|
|
|
273
275
|
* fixing the React #418 hydration mismatch — AND shows the true event time
|
|
274
276
|
* (4:00 PM EDT, not the 8:00 PM UTC a plain UTC pin would show, nor the
|
|
275
277
|
* viewer-local time the old unpinned call produced). Falls back to UTC when no
|
|
276
|
-
* zone is given, and tolerates
|
|
277
|
-
* The zone LABEL is rendered separately by callers
|
|
278
|
+
* zone is given, and tolerates an unresolvable label (legacy data) without throwing.
|
|
279
|
+
* The zone LABEL is rendered separately by callers that have room for their own
|
|
280
|
+
* styled span; pass `withZoneLabel` where the output is a plain joined string
|
|
281
|
+
* (the compact card densities) and the short name is appended inline — an
|
|
282
|
+
* unlabelled wall clock beside a date is readable but still ambiguous about
|
|
283
|
+
* WHICH zone it is stating.
|
|
278
284
|
*
|
|
279
|
-
* Returns: "4:00 PM"
|
|
285
|
+
* Returns: "4:00 PM", or "4:00 PM EDT" with `withZoneLabel`.
|
|
280
286
|
*/
|
|
281
|
-
export function formatTimeWithTimezone(
|
|
287
|
+
export function formatTimeWithTimezone(
|
|
288
|
+
date: Date | string | null | undefined,
|
|
289
|
+
timezone?: string | null,
|
|
290
|
+
options?: { withZoneLabel?: boolean },
|
|
291
|
+
): string {
|
|
282
292
|
if (!date) return '';
|
|
283
293
|
|
|
284
294
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
295
|
+
if (Number.isNaN(dateObj.getTime())) return '';
|
|
285
296
|
const opts: Intl.DateTimeFormatOptions = {
|
|
286
297
|
hour: 'numeric',
|
|
287
298
|
minute: '2-digit',
|
|
288
299
|
hour12: true,
|
|
289
300
|
timeZone: timezone || 'UTC',
|
|
301
|
+
...(options?.withZoneLabel ? { timeZoneName: 'short' as const } : {}),
|
|
290
302
|
};
|
|
291
303
|
try {
|
|
292
304
|
return dateObj.toLocaleTimeString('en-US', opts);
|
|
293
305
|
} catch {
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
306
|
+
// An UNRESOLVABLE `timezone` makes Intl throw a RangeError. Fall back to a
|
|
307
|
+
// UTC-pinned render so we stay deterministic (still no #418) instead of
|
|
308
|
+
// crashing. Note a bare "EST" does NOT land here: Node resolves it as a
|
|
309
|
+
// legacy fixed UTC-5 alias, which is a different wall clock from
|
|
310
|
+
// America/New_York whenever DST is in effect — a data problem, not a
|
|
311
|
+
// crash, and not one this catch can see.
|
|
297
312
|
return dateObj.toLocaleTimeString('en-US', { ...opts, timeZone: 'UTC' });
|
|
298
313
|
}
|
|
299
314
|
}
|
|
300
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Format a webinar/event DATE as the calendar day in its OWN timezone — the
|
|
318
|
+
* sibling of `formatTimeWithTimezone`, and the reason it exists.
|
|
319
|
+
*
|
|
320
|
+
* A card that prints the date in UTC and the time beside it in the event's zone
|
|
321
|
+
* can name a moment that never existed: a webinar at `2026-03-20T01:18Z` in
|
|
322
|
+
* `America/New_York` read "Mar 20, 2026 · 9:18 PM" — 9:18 PM on the 20th is not
|
|
323
|
+
* when it happens, 9:18 PM on the 19th is. Both halves of one timestamp must be
|
|
324
|
+
* rendered in ONE zone. Same UTC fallback and same non-IANA tolerance as the
|
|
325
|
+
* time formatter, so the pair can never disagree about which zone it used.
|
|
326
|
+
*
|
|
327
|
+
* `style` picks the two shapes the program cards actually render:
|
|
328
|
+
* `'medium'` → "Mar 19, 2026" (compact densities), `'weekday'` →
|
|
329
|
+
* "Thursday, March 19" (default density).
|
|
330
|
+
*
|
|
331
|
+
* Returns: "Mar 19, 2026"
|
|
332
|
+
*/
|
|
333
|
+
export type ZonedDateStyle = 'medium' | 'weekday' | 'long';
|
|
334
|
+
|
|
335
|
+
const ZONED_DATE_STYLES: Record<ZonedDateStyle, Intl.DateTimeFormatOptions> = {
|
|
336
|
+
medium: { year: 'numeric', month: 'short', day: 'numeric' },
|
|
337
|
+
weekday: { weekday: 'long', day: 'numeric', month: 'long' },
|
|
338
|
+
// Spelled-out month, no weekday — what an SEO description reads best as.
|
|
339
|
+
long: { year: 'numeric', month: 'long', day: 'numeric' },
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export function formatDateWithTimezone(
|
|
343
|
+
date: Date | string | null | undefined,
|
|
344
|
+
timezone?: string | null,
|
|
345
|
+
style: ZonedDateStyle = 'medium',
|
|
346
|
+
): string {
|
|
347
|
+
if (!date) return '';
|
|
348
|
+
|
|
349
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
350
|
+
if (Number.isNaN(dateObj.getTime())) return '';
|
|
351
|
+
const opts: Intl.DateTimeFormatOptions = {
|
|
352
|
+
...ZONED_DATE_STYLES[style],
|
|
353
|
+
timeZone: timezone || 'UTC',
|
|
354
|
+
};
|
|
355
|
+
try {
|
|
356
|
+
return dateObj.toLocaleDateString('en-US', opts);
|
|
357
|
+
} catch {
|
|
358
|
+
// An unresolvable `timezone` throws a RangeError — same tolerance as
|
|
359
|
+
// `formatTimeWithTimezone`, so a bad row degrades to UTC on BOTH halves
|
|
360
|
+
// rather than only one, which is the whole point of the pair.
|
|
361
|
+
return dateObj.toLocaleDateString('en-US', { ...opts, timeZone: 'UTC' });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* THE program date — the date half of what `formatWebinarTimeMeta` renders as
|
|
367
|
+
* the time half, taking the same already-resolved `ProgramInstant` so the two
|
|
368
|
+
* cannot name different moments.
|
|
369
|
+
*
|
|
370
|
+
* Every program surface used to write this branch itself:
|
|
371
|
+
* `zoned.instant && !zoned.dateOnly ? formatDateWithTimezone(...) :
|
|
372
|
+
* formatUtc(new Date(item.date), 'EEEE d MMMM')` — four copies, and they did
|
|
373
|
+
* not agree. Three stated the condition off the resolved instant and the
|
|
374
|
+
* fourth off a local timezone variable; worse, the two branches rendered
|
|
375
|
+
* DIFFERENT SHAPES, so whether a row happened to declare a zone decided
|
|
376
|
+
* whether its headline read "Thursday, March 19" or "Thursday 19 March".
|
|
377
|
+
*
|
|
378
|
+
* There is no UTC branch here because there never needed to be one:
|
|
379
|
+
* `formatDateWithTimezone` already pins to UTC when handed no zone, which is
|
|
380
|
+
* the same React #418 fix the hand-rolled `formatUtc` twins existed for — they
|
|
381
|
+
* were a date-fns re-implementation of a fallback that was already inside the
|
|
382
|
+
* function they sat next to.
|
|
383
|
+
*/
|
|
384
|
+
export function formatProgramDate(at: ProgramInstant, style: ZonedDateStyle = 'medium'): string {
|
|
385
|
+
// `timezone` is already null for a day-valued row, so this one call covers
|
|
386
|
+
// the zoned render, the no-zone render and the override render alike.
|
|
387
|
+
return formatDateWithTimezone(at.instant ?? at.utcDate, at.timezone, style);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Do these two endpoints describe a forward-running interval?
|
|
392
|
+
*
|
|
393
|
+
* THE ordering rule for every renderer in this file. A range that runs
|
|
394
|
+
* backwards is not a short range, it is a false one: a card shipped "-45m"
|
|
395
|
+
* from a row whose `end_at` preceded its `start_at`, and the clock renderer
|
|
396
|
+
* printed "11:00 PM - 9:00 PM" from the same shape. Both refuse it here.
|
|
397
|
+
*
|
|
398
|
+
* The host app enforces the same rule at INGEST (it drops such an `end_at`
|
|
399
|
+
* rather than storing it) and states the comparison itself, because the module
|
|
400
|
+
* that owns it there is a dependency-free leaf its mapper tests rely on. Two
|
|
401
|
+
* statements of one comparison, across a package boundary, knowingly — if this
|
|
402
|
+
* one changes, that one has to.
|
|
403
|
+
*/
|
|
404
|
+
export function isOrderedRange(from: Date | string | null | undefined, to: Date | string | null | undefined): boolean {
|
|
405
|
+
if (!from || !to) return false;
|
|
406
|
+
const a = (typeof from === 'string' ? new Date(from) : from).getTime();
|
|
407
|
+
const b = (typeof to === 'string' ? new Date(to) : to).getTime();
|
|
408
|
+
return Number.isFinite(a) && Number.isFinite(b) && b > a;
|
|
409
|
+
}
|
|
410
|
+
|
|
301
411
|
/**
|
|
302
412
|
* Calculate and format duration between two timestamps
|
|
303
413
|
* Used for webinar durations
|
|
304
414
|
* Returns: "1h 30m" or "45m"
|
|
415
|
+
*
|
|
416
|
+
* Returns `''` — the same "nothing to show" this function already returns for a
|
|
417
|
+
* missing endpoint — when the range is not a positive, real duration. An event
|
|
418
|
+
* whose `end_at` precedes its `start_at` is corrupt data, and the unguarded
|
|
419
|
+
* subtraction printed it literally: a live webinar row rendered "-45m" on the
|
|
420
|
+
* card. An unparseable timestamp printed "NaNm" the same way. A renderer shows
|
|
421
|
+
* nothing rather than an impossible value; the write path is what must reject
|
|
422
|
+
* the row. (Note the negative case never even reached the `>= 60` branch, so
|
|
423
|
+
* -90 minutes rendered as "-90m" rather than "-1h 30m" — the output was not
|
|
424
|
+
* just wrong, it was inconsistently wrong.)
|
|
305
425
|
*/
|
|
306
426
|
export function formatDurationFromRange(
|
|
307
427
|
startAt: string | Date | null | undefined,
|
|
308
428
|
endAt: string | Date | null | undefined,
|
|
309
429
|
): string {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
430
|
+
// ONE statement of "is this a forward-running interval", shared with
|
|
431
|
+
// `formatProgramTimeRange`. This function's guard and that one's were written
|
|
432
|
+
// separately — the second one's comment even named this as its sibling — and
|
|
433
|
+
// an ordering rule stated twice is a rule that can disagree with itself about
|
|
434
|
+
// the same row.
|
|
435
|
+
if (!isOrderedRange(startAt, endAt)) return '';
|
|
436
|
+
|
|
437
|
+
// Non-null past the guard above, which rejects null/unparseable endpoints.
|
|
438
|
+
const start = typeof startAt === 'string' ? new Date(startAt) : (startAt as Date);
|
|
439
|
+
const end = typeof endAt === 'string' ? new Date(endAt) : (endAt as Date);
|
|
440
|
+
const minutes = Math.round((end.getTime() - start.getTime()) / 60000);
|
|
441
|
+
if (minutes <= 0) return '';
|
|
316
442
|
|
|
317
443
|
if (minutes >= 60) {
|
|
318
444
|
const hours = Math.floor(minutes / 60);
|
|
@@ -734,3 +860,92 @@ export function formatBioText(aboutHtml: string | null | undefined, fallback: st
|
|
|
734
860
|
|
|
735
861
|
return stripHtml(aboutHtml).trim() || fallback;
|
|
736
862
|
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* THE program CLOCK — one time, or a start–end range, in the resolved zone.
|
|
866
|
+
*
|
|
867
|
+
* The third member of the set beside `formatProgramDate` (the day) and
|
|
868
|
+
* `formatWebinarTimeMeta` (time + duration), and it exists because the page
|
|
869
|
+
* header rebuilt it locally: an `instant ?? utcDate` fallback, a `dateOnly`
|
|
870
|
+
* suppression and a zone-labelled render — the same three things the meta
|
|
871
|
+
* helper owns, re-applied at the call site, which is exactly what that
|
|
872
|
+
* helper's docblock says goes wrong. The header also appended the RAW IANA
|
|
873
|
+
* name while the slot beneath it used the short name, so one component
|
|
874
|
+
* printed "America/New_York" and "EDT" six lines apart.
|
|
875
|
+
*
|
|
876
|
+
* Only the LAST clock carries the zone label, so a range reads
|
|
877
|
+
* "9:00 AM - 5:00 PM EDT" rather than labelling both ends.
|
|
878
|
+
*/
|
|
879
|
+
export function formatProgramTimeRange(
|
|
880
|
+
at: ProgramInstant,
|
|
881
|
+
opts: { startAt?: string | null; endAt?: string | null; withZoneLabel?: boolean } = {},
|
|
882
|
+
): string {
|
|
883
|
+
// A chosen display day has no clock the admin meant. THE one statement of
|
|
884
|
+
// that rule for every clock this package renders — `formatWebinarTimeMeta`
|
|
885
|
+
// composes over this rather than repeating it.
|
|
886
|
+
if (at.dateOnly) return '';
|
|
887
|
+
// `instant` is null when the row declares no zone; `utcDate` is the canonical
|
|
888
|
+
// value then, and the formatter's own UTC pin renders it deterministically.
|
|
889
|
+
// Resolved ONCE — spelling this chain twice is how the previous version of
|
|
890
|
+
// this pair drifted apart.
|
|
891
|
+
const source = at.instant ?? at.utcDate ?? opts.startAt;
|
|
892
|
+
const label = opts.withZoneLabel === true;
|
|
893
|
+
// Each of these builds an `Intl.DateTimeFormat`, so they are computed once
|
|
894
|
+
// rather than per branch.
|
|
895
|
+
const bare = formatTimeWithTimezone(source, at.timezone);
|
|
896
|
+
const labelled = label ? formatTimeWithTimezone(source, at.timezone, { withZoneLabel: true }) : bare;
|
|
897
|
+
// An INVERTED range is not rendered as a range. Its sibling
|
|
898
|
+
// `formatDurationFromRange` already refuses exactly this — its docblock
|
|
899
|
+
// records the "-45m" that shipped on a card — and this renderer guarded the
|
|
900
|
+
// unusable-endpoint cases but stopped one step short of the ordering check,
|
|
901
|
+
// so a corrupt row read "11:00 PM - 9:00 PM EDT". The START is still true, so
|
|
902
|
+
// it is kept; only the impossible pairing is dropped.
|
|
903
|
+
const ordered = isOrderedRange(source, opts.endAt);
|
|
904
|
+
const end = ordered && opts.endAt ? formatTimeWithTimezone(opts.endAt, at.timezone, { withZoneLabel: label }) : '';
|
|
905
|
+
// An end with no usable start is not a range, and rendering it alone puts a
|
|
906
|
+
// FINISH time where the reader expects a start. Say nothing instead.
|
|
907
|
+
if (!bare) return '';
|
|
908
|
+
// Only the LAST clock carries the label, so a range reads "9:00 AM - 5:00 PM EDT".
|
|
909
|
+
return end ? `${bare} - ${end}` : labelled;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* "4:00 PM EDT · 45m" — a webinar's time and duration as one meta string.
|
|
914
|
+
*
|
|
915
|
+
* Extracted because this exact three-line composition existed in the chat card
|
|
916
|
+
* and the public page header, and they DRIFTED: the card was corrected to read
|
|
917
|
+
* the resolved display instant while the page still read the raw `start_at`, so
|
|
918
|
+
* an admin override printed two different clock times for one webinar. One
|
|
919
|
+
* review round apart, on the same three lines.
|
|
920
|
+
*
|
|
921
|
+
* The split is the point: the TIME comes from the resolved display `instant`
|
|
922
|
+
* (which carries any override), the DURATION from `startAt`/`endAt`, because
|
|
923
|
+
* elapsed time is not a display date. Both sides of the separator are gated, so
|
|
924
|
+
* neither a suppressed duration nor an unrenderable time can leave one dangling.
|
|
925
|
+
*
|
|
926
|
+
* `dateOnly` lives in HERE rather than at the call sites on purpose: when each
|
|
927
|
+
* caller applied it, two of the three forgot and the surfaces disagreed about
|
|
928
|
+
* the same row. A chosen display date has no clock the admin meant, so the time
|
|
929
|
+
* half is dropped and only the duration remains.
|
|
930
|
+
*
|
|
931
|
+
* It takes the RESOLVED `ProgramInstant`, exactly as `formatProgramDate` does,
|
|
932
|
+
* for the same reason. While it took `instant` / `timezone` / `dateOnly` as
|
|
933
|
+
* loose fields, all four callers re-projected them off the same resolved value
|
|
934
|
+
* and no two projections matched — so a zoneless webinar rendered "4:00 PM UTC"
|
|
935
|
+
* on the public card and "4:00 PM" on the chat card, which exist to mirror each
|
|
936
|
+
* other, and the detail page fell back to a different source instant from the
|
|
937
|
+
* card's. Taking the value whole is what makes those disagreements unsayable.
|
|
938
|
+
*/
|
|
939
|
+
export function formatWebinarTimeMeta(
|
|
940
|
+
at: ProgramInstant,
|
|
941
|
+
opts: { startAt: string | null; endAt: string | null; withZoneLabel?: boolean },
|
|
942
|
+
): string {
|
|
943
|
+
// The CLOCK is `formatProgramTimeRange`'s, not a second rendering of it: this
|
|
944
|
+
// function restated the same three decisions (the `dateOnly` gate, the
|
|
945
|
+
// instant fallback, the labelled render) thirty lines below the sibling that
|
|
946
|
+
// owns them, and the two had already drifted apart on the fallback chain.
|
|
947
|
+
// Only the DURATION is this function's own contribution.
|
|
948
|
+
const duration = formatDurationFromRange(opts.startAt, opts.endAt);
|
|
949
|
+
const time = formatProgramTimeRange(at, { startAt: opts.startAt, withZoneLabel: opts.withZoneLabel });
|
|
950
|
+
return [time, duration].filter(Boolean).join(' · ');
|
|
951
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -138,7 +138,13 @@ export {
|
|
|
138
138
|
formatDurationMMSS,
|
|
139
139
|
formatDurationCompact,
|
|
140
140
|
formatTimeWithTimezone,
|
|
141
|
+
formatDateWithTimezone,
|
|
142
|
+
formatWebinarTimeMeta,
|
|
143
|
+
formatProgramDate,
|
|
144
|
+
formatProgramTimeRange,
|
|
145
|
+
type ZonedDateStyle,
|
|
141
146
|
formatDurationFromRange,
|
|
147
|
+
isOrderedRange,
|
|
142
148
|
type FormatDateUTCOptions,
|
|
143
149
|
formatDateUTC,
|
|
144
150
|
formatEntryMonthUTC,
|
|
@@ -393,3 +399,19 @@ export * from './csv';
|
|
|
393
399
|
export * from './social-platforms';
|
|
394
400
|
// The ODS badge palette a row whose colour is data picks from (departments).
|
|
395
401
|
export { BADGE_PALETTE, isBadgePaletteKey, pickBadgePaletteColor, type BadgePaletteKey } from './badge-palette';
|
|
402
|
+
|
|
403
|
+
// "Which instant does a program render, in which zone, and does it have a
|
|
404
|
+
// clock" — THE resolver every webinar/event/podcast surface reads, in this
|
|
405
|
+
// package and in the hub. Exported because the hub re-derived it by hand while
|
|
406
|
+
// it was package-private, and the copies drifted.
|
|
407
|
+
export {
|
|
408
|
+
programDateInstant,
|
|
409
|
+
programMetaFormatters,
|
|
410
|
+
programMetaLine,
|
|
411
|
+
programStr,
|
|
412
|
+
webinarTiming,
|
|
413
|
+
} from './program-instant';
|
|
414
|
+
// The concrete renderer bundle, so every surface in BOTH repos builds its meta
|
|
415
|
+
// line from one set rather than mirroring the triple.
|
|
416
|
+
export { PROGRAM_META_RENDERERS } from './program-meta-renderers';
|
|
417
|
+
export type { ProgramDateFields, ProgramInstant, ProgramMetaRenderers } from './program-instant';
|