@startsimpli/integrations 0.2.49 → 0.2.51

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.
@@ -18,7 +18,7 @@ import {
18
18
  import type { CommsApi } from '../api/comms';
19
19
  import { useSends } from '../hooks/index';
20
20
  import { COMEBACK_PROGRAM_KEY, PRODUCT_UPDATE_PROGRAM_KEY } from '../types/index';
21
- import { ErrorNotice, NativeSelect, formatDate, formatDateTime, useFieldId } from './_shared';
21
+ import { ErrorNotice, NativeSelect, formatDate, formatDateTime, formatLocalTime, useFieldId } from './_shared';
22
22
 
23
23
  export interface SendLogProps {
24
24
  api: CommsApi;
@@ -93,7 +93,9 @@ export function SendLog({ api, pageSize = 25 }: SendLogProps): ReactElement {
93
93
  <TableCell>{programLabel(s.program_key)}</TableCell>
94
94
  <TableCell>{s.status}</TableCell>
95
95
  <TableCell>
96
- {s.status === 'scheduled'
96
+ {s.send_mode === 'recipient_local' && (s.status === 'scheduled' || s.status === 'rolling')
97
+ ? `In each recipient's own time zone, from ${formatLocalTime(s.local_time)}`
98
+ : s.status === 'scheduled'
97
99
  ? formatDateTime(s.send_at, s.send_timezone)
98
100
  : s.status === 'cancelled'
99
101
  ? `Cancelled ${formatDateTime(s.cancelled_at)}`
@@ -21,7 +21,6 @@ import {
21
21
  usePrograms,
22
22
  useSendTest,
23
23
  useStepGeneration,
24
- useStepPreview,
25
24
  useUpdateProgram,
26
25
  } from '../hooks/index';
27
26
  import {
@@ -30,7 +29,7 @@ import {
30
29
  type SequenceProgram,
31
30
  type SequenceStep,
32
31
  } from '../types/index';
33
- import { EmailPreview } from './EmailPreview';
32
+ import { PreviewAsInbox } from './EmailPreviewPage';
34
33
  import { ErrorNotice, Note, humanize, useFieldId } from './_shared';
35
34
 
36
35
  export interface SequenceSettingsProps {
@@ -188,9 +187,7 @@ function StepRow({
188
187
  const step = program.config.steps[index];
189
188
  const status = stepStatus(step);
190
189
  const [editing, setEditing] = useState(false);
191
- const [previewing, setPreviewing] = useState(false);
192
190
  const [watching, setWatching] = useState(false);
193
- const preview = useStepPreview(api, program.key, index, previewing && status !== 'empty');
194
191
  const sendTest = useSendTest(api);
195
192
  const generate = useGenerateStep(api);
196
193
  const generation = useStepGeneration(api, program.key, index, watching, pollIntervalMs);
@@ -211,7 +208,7 @@ function StepRow({
211
208
  <Button type="button" size="sm" variant="outline" onClick={() => setEditing((v) => !v)}>Edit</Button>
212
209
  {status !== 'empty' ? (
213
210
  <>
214
- <Button type="button" size="sm" variant="outline" onClick={() => setPreviewing((v) => !v)}>Preview</Button>
211
+ <PreviewAsInbox api={api} source={{ kind: 'step', programKey: program.key, index }} label="Preview" />
215
212
  <Button
216
213
  type="button"
217
214
  size="sm"
@@ -251,9 +248,8 @@ function StepRow({
251
248
  {sendTest.data && !sendTest.data.sent ? (
252
249
  <ErrorNotice error={new Error(`Test not sent: ${humanize(sendTest.data.reason || 'refused')}`)} />
253
250
  ) : null}
254
- <ErrorNotice error={sendTest.error ?? generate.error ?? approve.error ?? preview.error ?? (failed ? new Error(failed) : null)} />
251
+ <ErrorNotice error={sendTest.error ?? generate.error ?? approve.error ?? (failed ? new Error(failed) : null)} />
255
252
  {editing ? <StepEditor api={api} program={program} index={index} onDone={() => setEditing(false)} /> : null}
256
- {previewing && preview.data ? <EmailPreview email={preview.data} /> : null}
257
253
  </li>
258
254
  );
259
255
  }
@@ -56,6 +56,14 @@ export function formatDateTime(iso: string | null | undefined, timeZone?: string
56
56
  }
57
57
  }
58
58
 
59
+ /** A wall-clock time with no zone ("2026-11-20T09:00:00"), shown as written: "Nov 20, 2026, 9:00 AM". */
60
+ export function formatLocalTime(local: string | null | undefined): string {
61
+ if (!local) return '';
62
+ const d = new Date(local);
63
+ if (Number.isNaN(d.getTime())) return '';
64
+ return d.toLocaleString(undefined, { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
65
+ }
66
+
59
67
  /** The viewer's IANA zone, or 'UTC' when the runtime cannot say. */
60
68
  export function localTimeZone(): string {
61
69
  try {
@@ -2,8 +2,10 @@ export * from './pages/CustomerEmailsPage';
2
2
  export * from './ProgramToggles';
3
3
  export * from './SequenceSettings';
4
4
  export * from './EmailPreview';
5
+ export * from './EmailPreviewPage';
5
6
  export * from './ApprovalModeSetting';
6
7
  export * from './VoiceSettings';
8
+ export * from './DefaultTimeZoneSetting';
7
9
  export * from './SendingDomain';
8
10
  export * from './ProductUpdates';
9
11
  export * from './DraftReview';
@@ -21,7 +21,9 @@ import type { CommsApi } from '../../api/comms';
21
21
  import { DEFAULT_POLL_MS, useCommsSettings, usePrograms } from '../../hooks/index';
22
22
  import { CommsApiError } from '../../types/index';
23
23
  import { AnnouncementComposer } from '../AnnouncementComposer';
24
+ import { ViewerLinksProvider } from '../EmailPreviewPage';
24
25
  import { ApprovalModeSetting } from '../ApprovalModeSetting';
26
+ import { DefaultTimeZoneSetting } from '../DefaultTimeZoneSetting';
25
27
  import { ProductUpdates } from '../ProductUpdates';
26
28
  import { ProgramToggles } from '../ProgramToggles';
27
29
  import { ResultsPanel } from '../ResultsPanel';
@@ -38,6 +40,15 @@ export interface CustomerEmailsPageProps {
38
40
  sendLogPageSize?: number;
39
41
  /** How often background work (AI writing) is re-checked. Default 2s. */
40
42
  pollIntervalMs?: number;
43
+ /** The foundry's own name: the sender shown in the viewer when none is configured. Default the slug. */
44
+ foundryName?: string;
45
+ /**
46
+ * Where the email viewer lives for an item id (a draft id, or `step.<program>.<index>`), when the
47
+ * host routes to it. Without it, previews open the same viewer over this page.
48
+ */
49
+ viewerHref?: (itemId: string) => string;
50
+ /** Follow a viewer href in the host (client navigation) rather than a full page load. */
51
+ onOpenViewer?: (href: string) => void;
41
52
  }
42
53
 
43
54
  function Fold({ value, title, children }: { value: string; title: string; children: ReactNode }) {
@@ -54,6 +65,9 @@ export function CustomerEmailsPage({
54
65
  foundrySlug,
55
66
  sendLogPageSize = 25,
56
67
  pollIntervalMs = DEFAULT_POLL_MS,
68
+ foundryName,
69
+ viewerHref,
70
+ onOpenViewer,
57
71
  }: CustomerEmailsPageProps): ReactElement {
58
72
  const settings = useCommsSettings(api);
59
73
  const programs = usePrograms(api);
@@ -93,6 +107,9 @@ export function CustomerEmailsPage({
93
107
  <Fold value="voice" title="Voice">
94
108
  <VoiceSettings api={api} />
95
109
  </Fold>
110
+ <Fold value="timezone" title="Time zone">
111
+ <DefaultTimeZoneSetting api={api} />
112
+ </Fold>
96
113
  <Fold value="domain" title="Sending domain">
97
114
  <SendingDomain api={api} />
98
115
  </Fold>
@@ -110,7 +127,9 @@ export function CustomerEmailsPage({
110
127
  return (
111
128
  <section className="mx-auto w-full max-w-4xl space-y-4">
112
129
  <h2 className="text-2xl font-semibold tracking-tight">Customer emails</h2>
113
- {body}
130
+ <ViewerLinksProvider value={{ href: viewerHref, open: onOpenViewer, foundryName: foundryName || foundrySlug }}>
131
+ {body}
132
+ </ViewerLinksProvider>
114
133
  </section>
115
134
  );
116
135
  }
@@ -75,6 +75,33 @@ export function useCommsSettings(api: CommsApi): UseQueryResult<CommsSettings> {
75
75
  return useQuery({ queryKey: commsKeys.settings(api.slug), queryFn: () => api.getSettings() });
76
76
  }
77
77
 
78
+ export interface Sender {
79
+ /** What an inbox lists as the sender. Never empty. */
80
+ name: string;
81
+ address?: string;
82
+ }
83
+
84
+ /** `Name <address>`, a bare address, or a bare name -> its parts (either may be empty). */
85
+ export function parseFromLine(from?: string | null): { name: string; address: string } {
86
+ const raw = (from ?? '').trim();
87
+ const m = raw.match(/^(.*?)\s*<([^>]+)>$/);
88
+ if (m) return { name: m[1].replace(/^"|"$/g, '').trim(), address: m[2] };
89
+ return raw.includes('@') ? { name: '', address: raw } : { name: raw, address: '' };
90
+ }
91
+
92
+ /**
93
+ * Who the email is from, as recipients see it: the configured sender name, else the name in the
94
+ * From line, else `fallbackName` (the foundry's own name). Fetched only while `enabled`.
95
+ */
96
+ export function useSender(api: CommsApi, enabled: boolean, fallbackName: string): Sender {
97
+ const q = useQuery({ queryKey: commsKeys.settings(api.slug), queryFn: () => api.getSettings(), enabled });
98
+ const from = parseFromLine(q.data?.from_address);
99
+ return {
100
+ name: q.data?.sender_name?.trim() || from.name || fallbackName,
101
+ ...(from.address ? { address: from.address } : {}),
102
+ };
103
+ }
104
+
78
105
  function useSettingsWrite<V>(api: CommsApi, fn: (v: V) => Promise<CommsSettings>) {
79
106
  const qc = useQueryClient();
80
107
  return useMutation<CommsSettings, Error, V>({
@@ -281,8 +308,8 @@ export type ApproveDraftVars = string | ({ id: string } & Partial<ScheduleInput>
281
308
  export function useApproveDraft(api: CommsApi): UseMutationResult<Draft, Error, ApproveDraftVars> {
282
309
  return useScheduleWrite(api, (v: ApproveDraftVars) => {
283
310
  if (typeof v === 'string') return api.approveDraft(v);
284
- const { id, send_at, timezone } = v;
285
- return api.approveDraft(id, send_at ? { send_at, timezone } : undefined);
311
+ const { id, send_at, ...rest } = v;
312
+ return api.approveDraft(id, send_at ? { send_at, ...rest } : undefined);
286
313
  });
287
314
  }
288
315
 
@@ -52,6 +52,11 @@ export interface CommsSettings {
52
52
  domain_records: DomainRecord[];
53
53
  domain_checked_at: string | null;
54
54
  paused: boolean;
55
+ /**
56
+ * IANA zone used for recipients with no known zone of their own when a send is
57
+ * timed per recipient. Blank = UTC.
58
+ */
59
+ default_timezone: string;
55
60
  source_repos: SourceRepo[];
56
61
  /**
57
62
  * The From address comms mail actually goes out with (UI gap G3): the
@@ -194,11 +199,11 @@ export interface ChangesResponse {
194
199
  unclassified: string[];
195
200
  }
196
201
 
197
- export type DraftApproval = 'pending' | 'scheduled' | 'expired' | 'failed' | 'approved' | 'discarded';
202
+ export type DraftApproval = 'pending' | 'scheduled' | 'rolling' | 'expired' | 'failed' | 'approved' | 'discarded';
198
203
 
199
204
  /** The named state of a draft/send (server `state`); every one has a reason and a next action. */
200
205
  export type DraftState =
201
- | 'generating' | 'writing_failed' | 'pending' | 'cancelled' | 'scheduled'
206
+ | 'generating' | 'writing_failed' | 'pending' | 'cancelled' | 'scheduled' | 'rolling'
202
207
  | 'expired' | 'failed' | 'sending' | 'sent' | 'discarded';
203
208
 
204
209
  export type DraftAction =
@@ -221,6 +226,42 @@ export interface DraftFailure {
221
226
  at?: string;
222
227
  }
223
228
 
229
+ /** One time zone's slice of a recipient-local send; counts come from the recipient rows. */
230
+ export type GroupState = 'waiting' | 'sending' | 'sent' | 'failed' | 'expired' | 'cancelled';
231
+
232
+ export interface DraftGroup {
233
+ zone: string;
234
+ /** UTC instant this zone's local time arrives. */
235
+ at: string;
236
+ state: GroupState;
237
+ /** Started well after `at` (the time had already passed when scheduled, or it was moved earlier). */
238
+ late: boolean;
239
+ /** 'gap': the local time is skipped by a clock change (it goes out at the first moment after the change); 'overlap': it happens twice (first one used). */
240
+ note: 'gap' | 'overlap' | null;
241
+ sources: { browser: number; foundry_default: number; utc: number };
242
+ count: number;
243
+ pending: number;
244
+ sent: number;
245
+ failed: number;
246
+ suppressed: number;
247
+ started_at: string | null;
248
+ completed_at: string | null;
249
+ failure: { stage: string; code: string; reason: string } | null;
250
+ reason: string | null;
251
+ }
252
+
253
+ export interface GroupSummary {
254
+ total: number;
255
+ waiting: number;
256
+ sending: number;
257
+ sent: number;
258
+ failed: number;
259
+ expired: number;
260
+ cancelled: number;
261
+ }
262
+
263
+ export type SendMode = 'fixed' | 'recipient_local';
264
+
224
265
  export interface Draft {
225
266
  id: string;
226
267
  program_key: string;
@@ -259,6 +300,13 @@ export interface Draft {
259
300
  /** A scheduled send whose audience lookup failed and is being retried. */
260
301
  dispatch_attempts?: number;
261
302
  dispatch_error?: string | null;
303
+ /** 'recipient_local': `local_time` is a wall-clock time in each recipient's own zone. */
304
+ send_mode?: SendMode;
305
+ /** The wall-clock time (no offset) of a recipient-local send, e.g. 2026-11-20T09:00:00. */
306
+ local_time?: string | null;
307
+ /** Per-zone progress, soonest first; empty until the plan is frozen at the first zone's time. */
308
+ groups?: DraftGroup[];
309
+ group_summary?: GroupSummary | null;
262
310
  }
263
311
 
264
312
  /** A tenant-evaluated segment: the key (and params) the foundry's backend understands. */
@@ -295,6 +343,8 @@ export interface AudiencePreview {
295
343
  excluded_total: number;
296
344
  sample: string[];
297
345
  excluded_sample: { email: string; reason: ExcludedReason }[];
346
+ /** Recipients with no known time zone of their own (a default or UTC applies to a per-zone send). */
347
+ no_timezone?: number;
298
348
  }
299
349
 
300
350
  export interface DraftAudience {
@@ -322,6 +372,11 @@ export interface AudienceSegments {
322
372
  export interface ScheduleInput {
323
373
  send_at: string;
324
374
  timezone?: string;
375
+ /**
376
+ * 'recipient_local': `send_at` is a wall-clock time with no offset, sent at that
377
+ * time in each recipient's own zone; `timezone` must be absent.
378
+ */
379
+ send_mode?: SendMode;
325
380
  }
326
381
 
327
382
  /** POST drafts/: either the email as written (201) or notes to write it from (202, generating). */
@@ -398,12 +453,16 @@ export interface ScheduledSend {
398
453
  id: string;
399
454
  program_key: string;
400
455
  subject: string;
401
- status: 'scheduled' | 'expired' | 'failed' | 'cancelled';
456
+ status: 'scheduled' | 'rolling' | 'expired' | 'failed' | 'cancelled';
402
457
  /** Why: the failure, the pause that expired it, or who cancelled it. */
403
458
  reason?: string;
404
459
  send_at: string | null;
405
460
  send_timezone: string | null;
406
461
  cancelled_at: string | null;
462
+ send_mode?: SendMode;
463
+ local_time?: string | null;
464
+ groups?: DraftGroup[];
465
+ group_summary?: GroupSummary | null;
407
466
  }
408
467
 
409
468
  /** GET sends/: the recipient rows (paginated) plus the not-yet-sent drafts. */