@startsimpli/integrations 0.2.126 → 0.2.127
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.127",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://startsimpli.com",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.12",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
-
"@startsimpli/auth": "^0.4.50",
|
|
54
53
|
"@startsimpli/ui": "^0.4.171",
|
|
54
|
+
"@startsimpli/auth": "^0.4.50",
|
|
55
55
|
"@startsimpli/utils": "^0.4.17"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { planMorningNotification, syncMorningNotification, type MorningNotifier } from '../notify';
|
|
4
|
+
|
|
5
|
+
const NY = 'America/New_York';
|
|
6
|
+
// Wednesday 2026-11-04 10:00 in New York.
|
|
7
|
+
const NOW = Date.parse('2026-11-04T15:00:00Z');
|
|
8
|
+
|
|
9
|
+
describe('planMorningNotification', () => {
|
|
10
|
+
it('test_local_notification_scheduled_for_morning_time_with_deeplink_to_briefing', () => {
|
|
11
|
+
const plan = planMorningNotification({ morningTime: '07:30', timeZone: NY, now: NOW, scheme: 'tandemgo' });
|
|
12
|
+
// 10:00 has passed 07:30 today, so the next one is tomorrow 07:30 in New York = 12:30Z (EST, UTC-5).
|
|
13
|
+
expect(new Date(plan!.at).toISOString()).toBe('2026-11-05T12:30:00.000Z');
|
|
14
|
+
expect(plan).toMatchObject({ repeat: 'daily', time: '07:30', timeZone: NY, deepLink: 'tandemgo://briefing' });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('is later today when the time has not come yet', () => {
|
|
18
|
+
const plan = planMorningNotification({ morningTime: '18:00', timeZone: NY, now: NOW, scheme: 'x' });
|
|
19
|
+
expect(new Date(plan!.at).toISOString()).toBe('2026-11-04T23:00:00.000Z');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('follows the zone across a DST change (07:30 is 11:30Z after the spring-forward in March)', () => {
|
|
23
|
+
const plan = planMorningNotification({ morningTime: '07:30', timeZone: NY, now: Date.parse('2026-03-07T20:00:00Z'), scheme: 'x' });
|
|
24
|
+
expect(new Date(plan!.at).toISOString()).toBe('2026-03-08T11:30:00.000Z');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('is in the listener zone, not the device UTC', () => {
|
|
28
|
+
const plan = planMorningNotification({ morningTime: '07:30', timeZone: 'Asia/Singapore', now: NOW, scheme: 'x' });
|
|
29
|
+
expect(new Date(plan!.at).toISOString()).toBe('2026-11-04T23:30:00.000Z'); // 07:30 on the 5th in Singapore
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('refuses a malformed time instead of guessing', () => {
|
|
33
|
+
expect(planMorningNotification({ morningTime: '7:30am', timeZone: NY, now: NOW, scheme: 'x' })).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('syncMorningNotification', () => {
|
|
38
|
+
const notifier = (id: string | null = 'n1'): MorningNotifier => ({ schedule: vi.fn(async () => id), cancel: vi.fn(async () => {}) });
|
|
39
|
+
|
|
40
|
+
it('schedules when on and cancels when off', async () => {
|
|
41
|
+
const n = notifier();
|
|
42
|
+
const plan = await syncMorningNotification(n, { enabled: true, morningTime: '07:30', timeZone: NY, scheme: 'tandemgo', now: NOW });
|
|
43
|
+
expect(n.schedule).toHaveBeenCalledWith(plan);
|
|
44
|
+
expect(await syncMorningNotification(n, { enabled: false, morningTime: '07:30', timeZone: NY, scheme: 'tandemgo', now: NOW })).toBeNull();
|
|
45
|
+
expect(n.cancel).toHaveBeenCalledTimes(1);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('reports nothing scheduled when the device does not allow notifications', async () => {
|
|
49
|
+
const n = notifier(null);
|
|
50
|
+
expect(await syncMorningNotification(n, { enabled: true, morningTime: '07:30', timeZone: NY, scheme: 'x', now: NOW })).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -5,3 +5,5 @@ export { createBriefingController, transcriptParts } from './controller';
|
|
|
5
5
|
export type { BriefingApi, BriefingController, BriefingMessages, BriefingPhase, BriefingPlayer, BriefingState } from './controller';
|
|
6
6
|
export { createFakeBriefingApi } from './fake';
|
|
7
7
|
export { BriefingCard } from './BriefingCard';
|
|
8
|
+
export { planMorningNotification, syncMorningNotification } from './notify';
|
|
9
|
+
export type { MorningNotifier, NotificationPlan } from './notify';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE MORNING NOTIFICATION, as an interface only (bd startsim-hfmyb).
|
|
3
|
+
*
|
|
4
|
+
* The audio is generated by central's beat before the person asks (see
|
|
5
|
+
* start-simpli-api `apps/briefing`). This is the other half: a LOCAL notification
|
|
6
|
+
* at the same wall-clock time that opens the briefing. No APNs (a later child,
|
|
7
|
+
* startsim-congb); expo-notifications is NOT a dependency of this package yet, so
|
|
8
|
+
* the shell supplies the `MorningNotifier` and this module only decides WHAT to
|
|
9
|
+
* schedule: when, and where tapping it goes. Nothing here imports a native module.
|
|
10
|
+
*/
|
|
11
|
+
import { localDate } from '../../corpus/briefing';
|
|
12
|
+
|
|
13
|
+
export interface NotificationPlan {
|
|
14
|
+
/** Epoch ms of the next time it should fire. */
|
|
15
|
+
at: number;
|
|
16
|
+
/** Fires every day at the same local time after that. */
|
|
17
|
+
repeat: 'daily';
|
|
18
|
+
/** Local time of day, `HH:MM`, in `timeZone`. */
|
|
19
|
+
time: string;
|
|
20
|
+
timeZone: string;
|
|
21
|
+
title: string;
|
|
22
|
+
body: string;
|
|
23
|
+
/** Opens the briefing: `<app scheme>://briefing`. */
|
|
24
|
+
deepLink: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** What the shell implements over expo-notifications (or anything else). */
|
|
28
|
+
export interface MorningNotifier {
|
|
29
|
+
/** Replace any earlier morning notification with this one; resolves to its id, or null when notifications are not allowed. */
|
|
30
|
+
schedule(plan: NotificationPlan): Promise<string | null>;
|
|
31
|
+
cancel(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
35
|
+
|
|
36
|
+
/** The instant `HH:MM` falls on in `timeZone` on a given local date (DST-safe: converges on the wall-clock time). */
|
|
37
|
+
function instantAt(date: string, time: string, timeZone: string): number {
|
|
38
|
+
const [h, m] = time.split(':').map(Number);
|
|
39
|
+
let guess = Date.parse(`${date}T${time}:00Z`);
|
|
40
|
+
for (let i = 0; i < 3; i += 1) {
|
|
41
|
+
const parts = new Intl.DateTimeFormat('en-US', {
|
|
42
|
+
timeZone, hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit',
|
|
43
|
+
}).formatToParts(new Date(guess));
|
|
44
|
+
const get = (t: string) => Number(parts.find((p) => p.type === t)?.value);
|
|
45
|
+
const shown = Date.UTC(get('year'), get('month') - 1, get('day'), get('hour'), get('minute'));
|
|
46
|
+
const want = Date.UTC(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1, Number(date.slice(8, 10)), h, m);
|
|
47
|
+
if (shown === want) break;
|
|
48
|
+
guess += want - shown;
|
|
49
|
+
}
|
|
50
|
+
return guess;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function planMorningNotification(input: {
|
|
54
|
+
/** `HH:MM`, the same setting central's generation uses. */
|
|
55
|
+
morningTime: string;
|
|
56
|
+
timeZone: string;
|
|
57
|
+
now: number;
|
|
58
|
+
/** The app's URL scheme (`config.app.scheme`). */
|
|
59
|
+
scheme: string;
|
|
60
|
+
}): NotificationPlan | null {
|
|
61
|
+
if (!TIME.test(input.morningTime)) return null;
|
|
62
|
+
const today = localDate(input.now, input.timeZone);
|
|
63
|
+
let at = instantAt(today, input.morningTime, input.timeZone);
|
|
64
|
+
if (at <= input.now) {
|
|
65
|
+
const tomorrow = new Date(Date.parse(`${today}T12:00:00Z`) + 86_400_000).toISOString().slice(0, 10);
|
|
66
|
+
at = instantAt(tomorrow, input.morningTime, input.timeZone);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
at, repeat: 'daily', time: input.morningTime, timeZone: input.timeZone,
|
|
70
|
+
title: 'Your day', body: 'Tap to hear what is on your plate today.',
|
|
71
|
+
deepLink: `${input.scheme}://briefing`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Make the device match the setting: schedule when on, cancel when off. Returns the plan that was scheduled, if any. */
|
|
76
|
+
export async function syncMorningNotification(
|
|
77
|
+
notifier: MorningNotifier,
|
|
78
|
+
setting: { enabled: boolean; morningTime: string; timeZone: string; scheme: string; now?: number },
|
|
79
|
+
): Promise<NotificationPlan | null> {
|
|
80
|
+
if (!setting.enabled) { await notifier.cancel(); return null; }
|
|
81
|
+
const plan = planMorningNotification({ ...setting, now: setting.now ?? Date.now() });
|
|
82
|
+
if (!plan) { await notifier.cancel(); return null; }
|
|
83
|
+
const id = await notifier.schedule(plan);
|
|
84
|
+
return id === null ? null : plan;
|
|
85
|
+
}
|