@startsimpli/integrations 0.2.117 → 0.2.118

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.117",
3
+ "version": "0.2.118",
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,9 +50,9 @@
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/ui": "^0.4.170",
54
53
  "@startsimpli/auth": "^0.4.50",
55
- "@startsimpli/utils": "^0.4.17"
54
+ "@startsimpli/utils": "^0.4.17",
55
+ "@startsimpli/ui": "^0.4.171"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -98,11 +98,11 @@
98
98
  "vitest": "^3.0.0",
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
- "@startsimpli/llm": "0.4.28",
102
- "@startsimpli/auth": "0.4.50",
101
+ "@startsimpli/llm": "0.4.30",
102
+ "@startsimpli/ui": "0.4.171",
103
103
  "@startsimpli/ui-native": "0.1.14",
104
- "@startsimpli/utils": "0.4.17",
105
- "@startsimpli/ui": "0.4.170"
104
+ "@startsimpli/auth": "0.4.50",
105
+ "@startsimpli/utils": "0.4.17"
106
106
  },
107
107
  "scripts": {
108
108
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -0,0 +1,102 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { composeBriefing, localDate, type BriefingItem } from '../corpus/briefing';
4
+
5
+ const ME = 'user-me';
6
+ // 2026-11-05 09:00 in New York (14:00Z).
7
+ const NOW = Date.parse('2026-11-05T14:00:00Z');
8
+ const TZ = 'America/New_York';
9
+
10
+ const item = (over: Partial<BriefingItem> & { id: string }): BriefingItem => ({
11
+ title: `Item ${over.id}`,
12
+ status: 'open',
13
+ ownerSub: ME,
14
+ dueAt: '2026-11-05',
15
+ ...over,
16
+ });
17
+ const compose = (items: BriefingItem[], over = {}) =>
18
+ composeBriefing(items, { ownerSub: ME, now: NOW, timeZone: TZ, ...over });
19
+
20
+ describe('composeBriefing', () => {
21
+ it('lists overdue, then in progress, then due today, each ordered by priority then date', () => {
22
+ const b = compose([
23
+ item({ id: 'today-hi', priority: 0 }),
24
+ item({ id: 'today-lo', priority: 3 }),
25
+ item({ id: 'prog', status: 'in_progress', dueAt: null, priority: 2 }),
26
+ item({ id: 'over-lo', dueAt: '2026-11-01', priority: 3 }),
27
+ item({ id: 'over-hi', dueAt: '2026-11-03', priority: 1 }),
28
+ ]);
29
+ expect(b.items.map((i) => i.id)).toEqual(['over-hi', 'over-lo', 'prog', 'today-hi', 'today-lo']);
30
+ expect(b.items.map((i) => i.kind)).toEqual(['overdue', 'overdue', 'in_progress', 'due_today', 'due_today']);
31
+ });
32
+
33
+ it('never includes done, dropped, or Linear completed/canceled items', () => {
34
+ const b = compose([
35
+ item({ id: 'done', status: 'done' }),
36
+ item({ id: 'dropped', status: 'dropped' }),
37
+ item({ id: 'lin-done', linearState: 'completed' }),
38
+ item({ id: 'lin-cancel', linearState: 'canceled' }),
39
+ item({ id: 'ok', linearState: 'started' }),
40
+ ]);
41
+ expect(b.items.map((i) => i.id)).toEqual(['ok']);
42
+ });
43
+
44
+ it('is owner scoped: other users (and unowned rows) are never included', () => {
45
+ const b = compose([item({ id: 'mine' }), item({ id: 'theirs', ownerSub: 'someone-else' }), item({ id: 'nobody', ownerSub: undefined })]);
46
+ expect(b.items.map((i) => i.id)).toEqual(['mine']);
47
+ });
48
+
49
+ it('groups by project focus name, else Personal', () => {
50
+ const b = compose([item({ id: 'a', focusName: 'Tandem' }), item({ id: 'b' })]);
51
+ expect(b.items.map((i) => i.group)).toEqual(['Tandem', 'Personal']);
52
+ });
53
+
54
+ it('caps at 8 spoken items and reports how many more', () => {
55
+ const items = Array.from({ length: 11 }, (_, n) => item({ id: `i${n}`, priority: n % 5 }));
56
+ const b = compose(items);
57
+ expect(b.items).toHaveLength(8);
58
+ expect(b.remaining).toBe(3);
59
+ expect(b.total).toBe(11);
60
+ });
61
+
62
+ it('returns an explicit empty state', () => {
63
+ const b = compose([item({ id: 'later', dueAt: '2026-11-20' }), item({ id: 'undated', dueAt: null })]);
64
+ expect(b.empty).toBe(true);
65
+ expect(b.items).toEqual([]);
66
+ expect(b.counts).toEqual({ overdue: 0, in_progress: 0, due_today: 0 });
67
+ });
68
+
69
+ it('returns the ordered item ids as the briefing context', () => {
70
+ const b = compose([item({ id: 'x', priority: 2 }), item({ id: 'y', priority: 1 })]);
71
+ expect(b.context.itemIds).toEqual(['y', 'x']);
72
+ expect(b.context.localDate).toBe('2026-11-05');
73
+ });
74
+
75
+ it('carries the Linear identifier when linked', () => {
76
+ const b = compose([item({ id: 'l', linearIdentifier: 'LIN-123' }), item({ id: 'n' })]);
77
+ expect(b.items[0].linearIdentifier).toBe('LIN-123');
78
+ expect(b.items[1].linearIdentifier).toBeUndefined();
79
+ });
80
+
81
+ it('uses the time zone, not UTC, for today (midnight boundary)', () => {
82
+ // 2026-11-06T02:00Z is still Nov 5 evening in New York, already Nov 6 in UTC.
83
+ const late = Date.parse('2026-11-06T02:00:00Z');
84
+ expect(localDate(late, TZ)).toBe('2026-11-05');
85
+ expect(localDate(late, 'UTC')).toBe('2026-11-06');
86
+ const ny = composeBriefing([item({ id: 't', dueAt: '2026-11-05' })], { ownerSub: ME, now: late, timeZone: TZ });
87
+ expect(ny.items[0].kind).toBe('due_today');
88
+ const utc = composeBriefing([item({ id: 't', dueAt: '2026-11-05' })], { ownerSub: ME, now: late, timeZone: 'UTC' });
89
+ expect(utc.items[0].kind).toBe('overdue');
90
+ });
91
+
92
+ it('reads a full ISO due date in the user zone', () => {
93
+ // 2026-11-05T03:00Z is Nov 4 at 10pm in New York: overdue, not today.
94
+ const b = compose([item({ id: 'iso', dueAt: '2026-11-05T03:00:00Z' })]);
95
+ expect(b.items[0].kind).toBe('overdue');
96
+ });
97
+
98
+ it('keeps an in-progress item even when it has no date, and tolerates unknown status words', () => {
99
+ const b = compose([item({ id: 'p', status: 'in_progress', dueAt: null }), item({ id: 'weird', status: 'whatever' as never })]);
100
+ expect(b.items.map((i) => i.id)).toEqual(['p', 'weird']);
101
+ });
102
+ });
@@ -0,0 +1,83 @@
1
+ /**
2
+ * THE BRIEFING CONTENT (bd startsim-nwc7t): what is on this person's plate today.
3
+ *
4
+ * PURE. No clock, no network, no zone database beyond `Intl`: the caller passes
5
+ * `now` and `timeZone`, so the same function runs on the server route, in the
6
+ * native app and in a test. Eligibility is one rule set: owned by the caller,
7
+ * not done / dropped, not completed or canceled in Linear, and either overdue,
8
+ * in progress, or due today in the CALLER'S zone.
9
+ */
10
+ import type {
11
+ Briefing, BriefingEntry, BriefingItem, BriefingKind, BriefingOptions,
12
+ } from './types';
13
+
14
+ const FINISHED = new Set(['done', 'dropped']);
15
+ const LINEAR_FINISHED = new Set(['completed', 'canceled', 'cancelled']);
16
+ const DEFAULT_MAX_ITEMS = 8;
17
+ const KIND_RANK: Record<BriefingKind, number> = { overdue: 0, in_progress: 1, due_today: 2 };
18
+
19
+ /** `YYYY-MM-DD` of an instant in a zone. */
20
+ export function localDate(instant: number, timeZone = 'UTC'): string {
21
+ const parts = new Intl.DateTimeFormat('en-US', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' })
22
+ .formatToParts(new Date(instant));
23
+ const get = (type: string) => parts.find((p) => p.type === type)?.value ?? '';
24
+ return `${get('year')}-${get('month')}-${get('day')}`;
25
+ }
26
+
27
+ /** The calendar day a due value means: a bare date as written, an instant in the zone. */
28
+ function dueDate(dueAt: string | null | undefined, timeZone: string): string | null {
29
+ if (!dueAt) return null;
30
+ if (/^\d{4}-\d{2}-\d{2}$/.test(dueAt)) return dueAt;
31
+ const t = Date.parse(dueAt);
32
+ return Number.isNaN(t) ? null : localDate(t, timeZone);
33
+ }
34
+
35
+ function kindOf(item: BriefingItem, due: string | null, today: string): BriefingKind | null {
36
+ if (due && due < today) return 'overdue';
37
+ if (item.status === 'in_progress') return 'in_progress';
38
+ if (due === today) return 'due_today';
39
+ return null;
40
+ }
41
+
42
+ export function composeBriefing(items: BriefingItem[], options: BriefingOptions): Briefing {
43
+ const timeZone = options.timeZone ?? 'UTC';
44
+ const today = localDate(options.now, timeZone);
45
+ const max = options.maxItems ?? DEFAULT_MAX_ITEMS;
46
+
47
+ const eligible: BriefingEntry[] = [];
48
+ for (const item of items) {
49
+ if (!item.ownerSub || item.ownerSub !== options.ownerSub) continue;
50
+ if (FINISHED.has(item.status)) continue;
51
+ if (item.linearState && LINEAR_FINISHED.has(item.linearState.toLowerCase())) continue;
52
+ const due = dueDate(item.dueAt, timeZone);
53
+ const kind = kindOf(item, due, today);
54
+ if (!kind) continue;
55
+ eligible.push({
56
+ id: item.id,
57
+ title: item.title,
58
+ kind,
59
+ group: item.focusName?.trim() || 'Personal',
60
+ dueDate: due,
61
+ ...(item.priority !== undefined ? { priority: item.priority } : {}),
62
+ ...(item.linearIdentifier ? { linearIdentifier: item.linearIdentifier } : {}),
63
+ });
64
+ }
65
+
66
+ // Array.sort is stable: equal rows keep the order they arrived in.
67
+ eligible.sort((a, b) =>
68
+ KIND_RANK[a.kind] - KIND_RANK[b.kind]
69
+ || (a.priority ?? 99) - (b.priority ?? 99)
70
+ || (a.dueDate ?? '9999').localeCompare(b.dueDate ?? '9999'));
71
+
72
+ const counts: Briefing['counts'] = { overdue: 0, in_progress: 0, due_today: 0 };
73
+ for (const entry of eligible) counts[entry.kind] += 1;
74
+ const spoken = eligible.slice(0, max);
75
+ return {
76
+ items: spoken,
77
+ remaining: eligible.length - spoken.length,
78
+ total: eligible.length,
79
+ counts,
80
+ empty: eligible.length === 0,
81
+ context: { itemIds: spoken.map((e) => e.id), localDate: today, timeZone },
82
+ };
83
+ }
@@ -0,0 +1,4 @@
1
+ export { composeBriefing, localDate } from './compose';
2
+ export type {
3
+ Briefing, BriefingContext, BriefingEntry, BriefingItem, BriefingKind, BriefingOptions,
4
+ } from './types';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The briefing's input and output. The input is STRUCTURAL: a to-do from the
3
+ * tenant (a `Commitment`) or a Linear-synced item both fit, so the composer needs
4
+ * no mapping layer and no import of either type.
5
+ */
6
+ export interface BriefingItem {
7
+ id: string;
8
+ title: string;
9
+ /** `open` | `in_progress` | `blocked` | `done` | `dropped`; other words are treated as open. */
10
+ status: string;
11
+ /** A date (`2026-11-05`) or a full ISO instant; the reader's zone decides which day an instant is. */
12
+ dueAt?: string | null;
13
+ /** 0 critical .. 4 backlog. Unset sorts last. */
14
+ priority?: number;
15
+ /** The member who owns it. Items without one are not anybody's briefing. */
16
+ ownerSub?: string;
17
+ /** The project (focus) it is filed under, by name. */
18
+ focusName?: string;
19
+ /** Linear's own state type when the item is synced (`started`, `completed`, `canceled`, ...). */
20
+ linearState?: string;
21
+ linearIdentifier?: string;
22
+ }
23
+
24
+ export type BriefingKind = 'overdue' | 'in_progress' | 'due_today';
25
+
26
+ export interface BriefingEntry {
27
+ id: string;
28
+ title: string;
29
+ kind: BriefingKind;
30
+ /** Project name, or `Personal`. */
31
+ group: string;
32
+ dueDate: string | null;
33
+ priority?: number;
34
+ linearIdentifier?: string;
35
+ }
36
+
37
+ export interface BriefingOptions {
38
+ ownerSub: string;
39
+ now: number;
40
+ /** IANA zone of the person hearing it. Default UTC. */
41
+ timeZone?: string;
42
+ /** Items spoken before "and N more". Default 8. */
43
+ maxItems?: number;
44
+ }
45
+
46
+ /** What a voice reply is resolved against: the spoken order, and the day it was composed for. */
47
+ export interface BriefingContext {
48
+ itemIds: string[];
49
+ localDate: string;
50
+ timeZone: string;
51
+ }
52
+
53
+ export interface Briefing {
54
+ items: BriefingEntry[];
55
+ /** Eligible items beyond the spoken ones. */
56
+ remaining: number;
57
+ /** All eligible items. */
58
+ total: number;
59
+ counts: Record<BriefingKind, number>;
60
+ empty: boolean;
61
+ context: BriefingContext;
62
+ }
@@ -272,3 +272,6 @@ export type {
272
272
  AttrValue, CountGroup, CountQuery, CountRow, EntityFilters, EntityOrder, EntityPage, EntityQuery, FacetQuery, FilterReport,
273
273
  FilterVerdict, RelationshipListQuery,
274
274
  } from './entity-query';
275
+
276
+ // Daily briefing: what is on one person's plate today (bd startsim-kgkp1).
277
+ export * from './briefing';