@startsimpli/integrations 0.2.170 → 0.2.172

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.
@@ -0,0 +1,49 @@
1
+ /** Pending decisions: the list, one open decision with its numbered questions, and answering. */
2
+ import type { DecisionIndexRow, DecisionRecord, NotifyClient } from '../../corpus/notify';
3
+
4
+ export interface DecisionsState {
5
+ rows: DecisionIndexRow[];
6
+ loading: boolean;
7
+ /** The decision being read or answered. */
8
+ open: DecisionRecord | null;
9
+ saving: boolean;
10
+ error: string | null;
11
+ }
12
+
13
+ export interface DecisionsController {
14
+ getState(): DecisionsState;
15
+ subscribe(l: () => void): () => void;
16
+ load(): Promise<void>;
17
+ openDecision(id: string): Promise<void>;
18
+ close(): void;
19
+ answer(answers: Array<{ n: number; answer: string }>): Promise<void>;
20
+ }
21
+
22
+ export function createDecisionsController(deps: { client: Pick<NotifyClient, 'pending' | 'decision' | 'answer'> }): DecisionsController {
23
+ let s: DecisionsState = { rows: [], loading: false, open: null, saving: false, error: null };
24
+ const ls = new Set<() => void>();
25
+ const set = (p: Partial<DecisionsState>) => { s = { ...s, ...p }; ls.forEach((l) => l()); };
26
+ const msg = (e: unknown) => (e instanceof Error ? e.message : String(e));
27
+ return {
28
+ getState: () => s,
29
+ subscribe: (l) => { ls.add(l); return () => ls.delete(l); },
30
+ async load() {
31
+ set({ loading: true, error: null });
32
+ try { set({ rows: await deps.client.pending() }); } catch (e) { set({ error: msg(e) }); } finally { set({ loading: false }); }
33
+ },
34
+ async openDecision(id) {
35
+ set({ loading: true, error: null });
36
+ try { set({ open: await deps.client.decision(id) }); } catch (e) { set({ error: msg(e) }); } finally { set({ loading: false }); }
37
+ },
38
+ close() { set({ open: null, error: null }); },
39
+ async answer(answers) {
40
+ const current = s.open;
41
+ if (!current) return;
42
+ set({ saving: true, error: null });
43
+ try {
44
+ const done = await deps.client.answer(current.id, answers);
45
+ set({ open: done, rows: s.rows.filter((r) => r.id !== done.id || done.status === 'pending') });
46
+ } catch (e) { set({ error: msg(e) }); } finally { set({ saving: false }); }
47
+ },
48
+ };
49
+ }
@@ -0,0 +1,23 @@
1
+ import type { DecisionRecord, NotifyClient } from '../../corpus/notify';
2
+
3
+ /** A scripted tenant for `-tgFakeTabs`: one pending decision with two questions, an on-by-default push setting. Nothing leaves the phone. */
4
+ export function createFakeNotify(): { client: NotifyClient; registered: string[] } {
5
+ let push = true;
6
+ const decision: DecisionRecord = {
7
+ id: 'dec-1', title: 'Which build goes to Quinn first?', status: 'pending', created_at: '2026-11-13T12:00:00Z',
8
+ questions: [{ n: 1, text: 'Ship the Siri Shortcut build now?', options: ['Yes', 'Not yet'] }, { n: 2, text: 'Anything to change first?' }],
9
+ answers: [],
10
+ };
11
+ const client: NotifyClient = {
12
+ pending: async () => (decision.status === 'pending' ? [{ id: decision.id, title: decision.title, status: 'pending', created_at: decision.created_at }] : []),
13
+ decision: async () => ({ ...decision }),
14
+ answer: async (_id, answers) => {
15
+ for (const a of answers) decision.answers = [...decision.answers.filter((x) => x.n !== a.n), { n: a.n, answer: a.answer, answered_at: '2026-11-13T12:05:00Z' }];
16
+ if (decision.questions.every((q) => decision.answers.some((a) => a.n === q.n))) decision.status = 'answered';
17
+ return { ...decision };
18
+ },
19
+ settings: async () => ({ push, devices: 0 }),
20
+ setPush: async (on) => { push = on; return { push, devices: 0 }; },
21
+ };
22
+ return { client, registered: [] };
23
+ }
@@ -0,0 +1,7 @@
1
+ export * from './types';
2
+ export { createPushRegistry } from './registry';
3
+ export { createPushController, type PushController, type PushState } from './controller';
4
+ export { createDecisionsController, type DecisionsController, type DecisionsState } from './decisions';
5
+ export { decisionsTab } from './tab';
6
+ export { DecisionsScreen } from './DecisionsScreen';
7
+ export { createFakeNotify } from './fake';
@@ -0,0 +1,20 @@
1
+ import type { PushRegistry } from './types';
2
+
3
+ type AuthorizedFetch = (url: string, init?: RequestInit) => Promise<Response>;
4
+
5
+ /** POST/DELETE /corpus/devices with the person's login. */
6
+ export function createPushRegistry(deps: { tandemUrl: string; authorizedFetch: AuthorizedFetch }): PushRegistry {
7
+ const url = `${deps.tandemUrl.replace(/\/+$/, '')}/corpus/devices`;
8
+ const json = { 'content-type': 'application/json' };
9
+ return {
10
+ async register({ token, environment, label }) {
11
+ const res = await deps.authorizedFetch(url, { method: 'POST', headers: json, body: JSON.stringify({ token, environment, platform: 'ios', ...(label ? { label } : {}) }) });
12
+ if (!res.ok) throw new Error(`Registering this phone for notifications failed (${res.status})`);
13
+ return (await res.json()) as { registered: boolean; devices: number; push_enabled: boolean };
14
+ },
15
+ async unregister(token) {
16
+ const res = await deps.authorizedFetch(url, { method: 'DELETE', headers: json, body: JSON.stringify({ token }) });
17
+ if (!res.ok) throw new Error(`Removing this phone from notifications failed (${res.status})`);
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,9 @@
1
+ import type { FoundryTab } from '../components/FoundryTabsShell';
2
+ import { DecisionsScreen } from './DecisionsScreen';
3
+ import type { DecisionsController } from './decisions';
4
+ import type { PushController } from './controller';
5
+
6
+ /** The Decisions tab: pending decisions plus the notifications switch. A deep link `<scheme>://tab/<key>/<decision id>` opens one. */
7
+ export function decisionsTab(controllers: { decisions: DecisionsController; push: PushController }, over: Partial<Pick<FoundryTab, 'key' | 'label'>> = {}): FoundryTab {
8
+ return { key: 'decisions', label: 'Decisions', resetOnLeave: true, ...over, render: ({ route }) => <DecisionsScreen decisions={controllers.decisions} push={controllers.push} focus={route?.id} /> };
9
+ }
@@ -0,0 +1,26 @@
1
+ import type { PushEnvironment } from '../../corpus/notify';
2
+
3
+ /** What a tapped push carries (the APNs payload's custom keys, plus the alert text). */
4
+ export interface PushTap { kind?: string; thread_id?: string; decision_id?: string; ping_id?: string; title?: string; body?: string }
5
+
6
+ /** The device bindings of push (expo-notifications in the template): the permission, the APNs token and notification taps. */
7
+ export interface PushDevice {
8
+ /** 'sandbox' for a development-signed build, 'production' for an App Store / TestFlight one. */
9
+ environment: PushEnvironment;
10
+ /** Asks (once; iOS remembers) and resolves to whether alerts are allowed. */
11
+ requestPermission(): Promise<'granted' | 'denied'>;
12
+ /** The hex APNs device token, or null when it cannot be had (simulator, no entitlement). */
13
+ getToken(): Promise<string | null>;
14
+ /** A notification was tapped (app running or in the background). */
15
+ onTap(cb: (tap: PushTap) => void): () => void;
16
+ /** The tap that launched the app from a closed state, if any. */
17
+ launchTap(): Promise<PushTap | null>;
18
+ /** Optional, for the device label on the server. */
19
+ label?: string;
20
+ }
21
+
22
+ /** The per-device calls on the tenant. */
23
+ export interface PushRegistry {
24
+ register(input: { token: string; environment: PushEnvironment; label?: string }): Promise<{ registered: boolean; devices: number; push_enabled: boolean }>;
25
+ unregister(token: string): Promise<void>;
26
+ }