@startsimpli/integrations 0.2.67 → 0.2.69
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/README.md +25 -0
- package/package.json +2 -2
- package/src/__tests__/entity-query.test.ts +122 -0
- package/src/__tests__/helpers/fake-tenant.ts +67 -0
- package/src/__tests__/voice-refile.test.ts +218 -0
- package/src/corpus/client.ts +34 -42
- package/src/corpus/commitments.ts +2 -1
- package/src/corpus/entities.ts +2 -0
- package/src/corpus/entity-query.ts +269 -0
- package/src/corpus/extract.ts +3 -1
- package/src/corpus/filing.ts +29 -1
- package/src/corpus/index.ts +9 -0
- package/src/corpus/types.ts +8 -0
- package/src/corpus/voice-refile.ts +142 -0
- package/src/corpus/voice.ts +26 -12
- package/src/native/components/FoundryTabsShell.tsx +81 -0
- package/src/native/components/NotesShell.tsx +19 -26
- package/src/native/corpus/__tests__/api.test.ts +155 -0
- package/src/native/corpus/__tests__/fake-tenant.test.ts +123 -0
- package/src/native/corpus/__tests__/paged.test.ts +91 -0
- package/src/native/corpus/api.ts +161 -0
- package/src/native/corpus/ask.ts +16 -0
- package/src/native/corpus/fake-data.ts +56 -0
- package/src/native/corpus/fake-tenant.ts +275 -0
- package/src/native/corpus/fake.ts +30 -0
- package/src/native/corpus/paged.ts +103 -0
- package/src/native/index.ts +11 -1
- package/src/native/shell/__tests__/navigator.test.ts +96 -0
- package/src/native/shell/navigator.ts +107 -0
- package/src/native/voice/__tests__/http.test.ts +10 -6
- package/src/native/voice/http.ts +6 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample tenant rows (projects, to-dos, documents, edges) for the fakes. Shaped
|
|
3
|
+
* exactly like the wire rows the real mappers read, and consistent with
|
|
4
|
+
* `sampleVoiceFocuses()` (f287 / fma / fdbg) so the Notes and Tracker fakes agree.
|
|
5
|
+
*/
|
|
6
|
+
import type { TenantEntity, TenantRelationship } from '../../corpus/entities';
|
|
7
|
+
|
|
8
|
+
const at = (iso: string) => iso;
|
|
9
|
+
const row = (id: string, type: string, external: string, name: string, createdAt: string, data: Record<string, unknown>): TenantEntity =>
|
|
10
|
+
({ id, entity_type: type, external_id: external, name, created_at: at(createdAt), org_id: 'tandem', data });
|
|
11
|
+
|
|
12
|
+
const commitment = (id: string, title: string, createdAt: string, data: Record<string, unknown>) =>
|
|
13
|
+
row(id, 'commitment', `commit:${id}`, title, createdAt, {
|
|
14
|
+
title, subtype: 'action', source: 'voice', source_label: 'Voice note', mentions: [], extractor_version: 'fake-1',
|
|
15
|
+
first_seen_at: createdAt, last_seen_at: createdAt, ...data,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export function sampleTenantEntities(): TenantEntity[] {
|
|
19
|
+
return [
|
|
20
|
+
row('f287', 'focus', 'focus:287a', '287A', '2026-09-01T00:00:00Z', { title: '287A', status: 'active', category: 'milestone', detail: 'The 287A hearing and filing.', progress: 0.4, sort_order: 1 }),
|
|
21
|
+
row('fma', 'focus', 'focus:marketing-agents', 'Marketing agents', '2026-09-02T00:00:00Z', { title: 'Marketing agents', status: 'on_track', category: 'product', progress: 0.7, sort_order: 2 }),
|
|
22
|
+
row('fdbg', 'focus', 'focus:debug', 'Debug', '2026-09-03T00:00:00Z', { title: 'Debug', status: 'at_risk', category: 'team', progress: 0.2, sort_order: 3 }),
|
|
23
|
+
|
|
24
|
+
commitment('c1', 'Finish exhibit list', '2026-11-03T14:40:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-05T17:00:00Z', priority: 1, detail: 'Needed before the hearing.' }),
|
|
25
|
+
commitment('c2', 'Call Megan about the filing receipt', '2026-11-03T14:41:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-04T17:00:00Z', priority: 2 }),
|
|
26
|
+
commitment('c3', 'Move weekly report to Monday', '2026-11-03T14:42:00Z', { status: 'open', owner_name: 'Quinn' }),
|
|
27
|
+
commitment('c4', 'Book the dentist', '2026-11-03T14:43:00Z', { status: 'open', owner_name: 'Quinn', due_at: '2026-11-06T09:00:00Z' }),
|
|
28
|
+
commitment('c5', 'Send the revised proposal', '2026-10-28T10:00:00Z', { status: 'done', owner_name: 'Rae', resolved_at: '2026-10-30T10:00:00Z' }),
|
|
29
|
+
commitment('c6', 'Waiting on court clerk reply', '2026-10-29T10:00:00Z', { status: 'blocked', owner_name: 'Quinn', status_reason: 'Clerk has not answered' }),
|
|
30
|
+
|
|
31
|
+
row('d1', 'source_document', 'voice:d1', 'Hearing prep and a dentist reminder', '2026-11-03T14:38:00Z', {
|
|
32
|
+
title: 'Hearing prep and a dentist reminder', source: 'voice', subtype: 'voice_note', occurred_at: '2026-11-03T14:38:00Z',
|
|
33
|
+
summary: 'Prep for the 287A hearing; marketing agents stand-up; dentist on Friday.',
|
|
34
|
+
}),
|
|
35
|
+
row('d2', 'source_document', 'granola:d2', 'Weekly sync with Rae', '2026-11-02T16:00:00Z', {
|
|
36
|
+
title: 'Weekly sync with Rae', source: 'granola', subtype: 'meeting', occurred_at: '2026-11-02T15:00:00Z',
|
|
37
|
+
summary: 'Agreed the marketing agents report goes out Mondays. Rae owns the proposal revision.',
|
|
38
|
+
}),
|
|
39
|
+
row('d3', 'source_document', 'drive:d3', 'Debug launch checklist', '2026-10-25T09:00:00Z', {
|
|
40
|
+
title: 'Debug launch checklist', source: 'drive', subtype: 'document', occurred_at: '2026-10-25T09:00:00Z', path: '/Debug',
|
|
41
|
+
summary: 'Checklist for the Debug launch: smoke tests, status page, support rota.',
|
|
42
|
+
}),
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function sampleTenantRelationships(): TenantRelationship[] {
|
|
47
|
+
return [
|
|
48
|
+
{ id: 'e1', rel_type: 'in_focus', source: 'c1', target: 'f287' },
|
|
49
|
+
{ id: 'e2', rel_type: 'in_focus', source: 'c2', target: 'f287' },
|
|
50
|
+
{ id: 'e3', rel_type: 'in_focus', source: 'c3', target: 'fma' },
|
|
51
|
+
{ id: 'e4', rel_type: 'in_focus', source: 'c6', target: 'f287' },
|
|
52
|
+
{ id: 'e5', rel_type: 'about_focus', source: 'd1', target: 'f287' },
|
|
53
|
+
{ id: 'e6', rel_type: 'about_focus', source: 'd2', target: 'fma' },
|
|
54
|
+
{ id: 'e7', rel_type: 'about_focus', source: 'd3', target: 'fdbg' },
|
|
55
|
+
];
|
|
56
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-memory tenant data plane for simulators, demos and tests: it answers
|
|
3
|
+
* `GET api/v1/entities`, `entities/facets`, `relationships` and the upsert/edge
|
|
4
|
+
* writes by the SAME contract as `tenant-starter/apps/api/filters.py` - server
|
|
5
|
+
* paging (cap 200) with `next`, `order`, `search`, the entity filters, edge
|
|
6
|
+
* walks and `attr.*` operators - and reports `applied_filters` /
|
|
7
|
+
* `ignored_filters` honestly. Because the real adapters run on top of it, a
|
|
8
|
+
* screen proven here exercises the same mapping, paging and reconcile code as
|
|
9
|
+
* production. Pass `unsupported` to play an older fork that ignores a filter.
|
|
10
|
+
*/
|
|
11
|
+
import type { TenantEntity, TenantRelationship } from '../../corpus/entities';
|
|
12
|
+
import { MAX_PAGE_SIZE } from '../../corpus/entity-query';
|
|
13
|
+
import type { AuthorizedHttp } from '../voice/http';
|
|
14
|
+
|
|
15
|
+
type Params = Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
export interface FakeTenantOptions {
|
|
18
|
+
entities?: TenantEntity[];
|
|
19
|
+
relationships?: TenantRelationship[];
|
|
20
|
+
pageSize?: number;
|
|
21
|
+
/** Filter names this "tenant" does not understand: reported ignored, never applied. */
|
|
22
|
+
unsupported?: string[];
|
|
23
|
+
onRequest?: (method: string, path: string, params: Params) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const NOT_FILTERS = new Set(['page', 'page_size', 'format']);
|
|
27
|
+
const REL_KEYS = new Set(['source', 'target', 'entity', 'source__in', 'target__in', 'entity__in', 'rel_type', 'source_type', 'target_type']);
|
|
28
|
+
|
|
29
|
+
const asList = (v: unknown): string[] => (Array.isArray(v) ? v.map(String) : v === undefined ? [] : String(v).split(',').map((s) => s.trim()).filter(Boolean));
|
|
30
|
+
const dataOf = (e: TenantEntity): Record<string, unknown> => (e.data ?? {}) as Record<string, unknown>;
|
|
31
|
+
const created = (e: TenantEntity) => String(e.created_at ?? e.createdAt ?? '');
|
|
32
|
+
const typeOf = (e: TenantEntity) => String(e.entity_type ?? e.entityType ?? '');
|
|
33
|
+
const status = (code: number, message: string) => Object.assign(new Error(message), { status: code });
|
|
34
|
+
|
|
35
|
+
function strings(value: unknown): string[] {
|
|
36
|
+
if (typeof value === 'string') return [value];
|
|
37
|
+
if (Array.isArray(value)) return value.flatMap(strings);
|
|
38
|
+
if (value && typeof value === 'object') return Object.values(value).flatMap(strings);
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `attr.<name>[__op]` over one row, as the tenant's typed columns compare them. */
|
|
43
|
+
function attrMatches(entity: TenantEntity, key: string, raw: unknown): boolean {
|
|
44
|
+
const body = key.slice('attr.'.length);
|
|
45
|
+
const m = /^(.*?)(?:__(in|gte|gt|lte|lt|icontains|isnull|isblank|startswith|istartswith|under))?$/.exec(body)!;
|
|
46
|
+
const [, name, op = ''] = m;
|
|
47
|
+
const value = dataOf(entity)[name];
|
|
48
|
+
const missing = value === undefined || value === null;
|
|
49
|
+
const text = missing ? '' : String(value);
|
|
50
|
+
const want = String(raw);
|
|
51
|
+
switch (op) {
|
|
52
|
+
case '': return !missing && text === want;
|
|
53
|
+
case 'in': return !missing && asList(raw).includes(text);
|
|
54
|
+
case 'gt': return !missing && (Number.isNaN(Number(text)) ? text > want : Number(text) > Number(want));
|
|
55
|
+
case 'gte': return !missing && (Number.isNaN(Number(text)) ? text >= want : Number(text) >= Number(want));
|
|
56
|
+
case 'lt': return !missing && (Number.isNaN(Number(text)) ? text < want : Number(text) < Number(want));
|
|
57
|
+
case 'lte': return !missing && (Number.isNaN(Number(text)) ? text <= want : Number(text) <= Number(want));
|
|
58
|
+
case 'icontains': return text.toLowerCase().includes(want.toLowerCase());
|
|
59
|
+
case 'isnull': return want === 'true' ? missing : !missing;
|
|
60
|
+
case 'isblank': return want === 'true' ? missing || text === '' : !missing && text !== '';
|
|
61
|
+
case 'startswith': return text.startsWith(want);
|
|
62
|
+
case 'istartswith': return text.toLowerCase().startsWith(want.toLowerCase());
|
|
63
|
+
case 'under': {
|
|
64
|
+
const base = want.replace(/\/+$/, '') || '';
|
|
65
|
+
return text === (base || '/') || text.startsWith(`${base}/`);
|
|
66
|
+
}
|
|
67
|
+
default: return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function pageOf<T>(rows: T[], params: Params, fallback: number) {
|
|
72
|
+
const page = Number(params.page ?? 1) || 1;
|
|
73
|
+
const asked = Number(params.page_size);
|
|
74
|
+
const size = Number.isFinite(asked) && asked > 0 ? Math.min(asked, MAX_PAGE_SIZE) : fallback;
|
|
75
|
+
const start = (page - 1) * size;
|
|
76
|
+
return {
|
|
77
|
+
count: rows.length,
|
|
78
|
+
next: start + size < rows.length ? `?page=${page + 1}` : null,
|
|
79
|
+
previous: page > 1 ? `?page=${page - 1}` : null,
|
|
80
|
+
results: rows.slice(start, start + size),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface FakeTenant {
|
|
85
|
+
http: AuthorizedHttp;
|
|
86
|
+
requests: Array<{ method: string; path: string; params: Params }>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenant {
|
|
90
|
+
const entities = options.entities ?? [];
|
|
91
|
+
const relationships = options.relationships ?? [];
|
|
92
|
+
const pageSize = options.pageSize ?? 50;
|
|
93
|
+
const unsupported = new Set(options.unsupported ?? []);
|
|
94
|
+
const requests: Array<{ method: string; path: string; params: Params }> = [];
|
|
95
|
+
let seq = 0;
|
|
96
|
+
|
|
97
|
+
function list(params: Params) {
|
|
98
|
+
const applied: string[] = [];
|
|
99
|
+
const ignored: string[] = [];
|
|
100
|
+
const ok = (key: string) => key in params && !unsupported.has(key);
|
|
101
|
+
let rows = entities.slice();
|
|
102
|
+
const narrow = (key: string, test: (e: TenantEntity) => boolean) => { rows = rows.filter(test); applied.push(key); };
|
|
103
|
+
|
|
104
|
+
if (ok('type')) narrow('type', (e) => typeOf(e) === String(params.type));
|
|
105
|
+
if (ok('id')) narrow('id', (e) => String(e.id) === String(params.id));
|
|
106
|
+
if (ok('id__in')) { const w = asList(params.id__in); narrow('id__in', (e) => w.includes(String(e.id))); }
|
|
107
|
+
if (ok('external_id')) narrow('external_id', (e) => String(e.external_id ?? e.externalId) === String(params.external_id));
|
|
108
|
+
if (ok('external_id__in')) { const w = asList(Array.isArray(params.external_id__in) ? params.external_id__in : [params.external_id__in]); narrow('external_id__in', (e) => w.includes(String(e.external_id ?? e.externalId))); }
|
|
109
|
+
if (ok('source')) narrow('source', (e) => String(dataOf(e).source ?? '') === String(params.source));
|
|
110
|
+
if (ok('scope')) narrow('scope', (e) => attrMatches(e, 'attr.path__under', params.scope));
|
|
111
|
+
for (const [key, field, after] of [
|
|
112
|
+
['occurred_after', 'occurred_at', true], ['occurred_before', 'occurred_at', false],
|
|
113
|
+
] as const) {
|
|
114
|
+
if (ok(key)) narrow(key, (e) => { const v = String(dataOf(e)[field] ?? ''); return v !== '' && (after ? v >= String(params[key]) : v <= String(params[key])); });
|
|
115
|
+
}
|
|
116
|
+
for (const [key, after] of [['created_after', true], ['created_before', false]] as const) {
|
|
117
|
+
if (ok(key)) narrow(key, (e) => (after ? created(e) >= String(params[key]) : created(e) <= String(params[key])));
|
|
118
|
+
}
|
|
119
|
+
if (ok('related_to') || ok('party')) {
|
|
120
|
+
const label = ok('related_to') ? 'related_to' : 'party';
|
|
121
|
+
const target = String(params[label]);
|
|
122
|
+
const via = asList(params.related_via);
|
|
123
|
+
const direction = String(params.related_direction ?? 'any');
|
|
124
|
+
const hits = new Set<string>();
|
|
125
|
+
for (const edge of relationships) {
|
|
126
|
+
if (via.length && !via.includes(String(edge.rel_type ?? edge.relType))) continue;
|
|
127
|
+
if (direction !== 'in' && String(edge.target) === target) hits.add(String(edge.source));
|
|
128
|
+
if (direction !== 'out' && String(edge.source) === target) hits.add(String(edge.target));
|
|
129
|
+
}
|
|
130
|
+
narrow(label, (e) => hits.has(String(e.id)));
|
|
131
|
+
if (label === 'related_to') {
|
|
132
|
+
for (const companion of ['related_via', 'related_direction', 'related_depth']) {
|
|
133
|
+
if (companion in params && !unsupported.has(companion)) applied.push(companion);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const [key, value] of Object.entries(params)) {
|
|
138
|
+
if (key.startsWith('attr.') && !unsupported.has(key)) narrow(key, (e) => attrMatches(e, key, value));
|
|
139
|
+
}
|
|
140
|
+
const term = ok('search') ? String(params.search).trim().toLowerCase() : '';
|
|
141
|
+
// Like the tenant's websearch full text: words AND together, `or` separates alternatives.
|
|
142
|
+
const groups = term.split(/\s+or\s+/).map((g) => g.split(/[^\p{L}\p{N}]+/u).filter(Boolean)).filter((g) => g.length);
|
|
143
|
+
const hitCount = (e: TenantEntity) => {
|
|
144
|
+
const hay = [e.name ?? '', ...strings(dataOf(e))].join(' ').toLowerCase();
|
|
145
|
+
return groups.reduce((n, words) => (words.every((w) => hay.includes(w)) ? n + words.reduce((m, w) => m + hay.split(w).length - 1, 0) : n), 0);
|
|
146
|
+
};
|
|
147
|
+
if (term) narrow('search', (e) => hitCount(e) > 0);
|
|
148
|
+
|
|
149
|
+
// ordering -------------------------------------------------------------
|
|
150
|
+
const order = ok('order') ? String(params.order) : '';
|
|
151
|
+
const byRecent = (a: TenantEntity, b: TenantEntity) => created(b).localeCompare(created(a)) || String(a.id).localeCompare(String(b.id));
|
|
152
|
+
if (!order || order === 'recent') { rows.sort(byRecent); if (order) applied.push('order'); }
|
|
153
|
+
else if (order === 'oldest') { rows.sort((a, b) => created(a).localeCompare(created(b)) || String(a.id).localeCompare(String(b.id))); applied.push('order'); }
|
|
154
|
+
else if (order === 'relevance') {
|
|
155
|
+
if (term) { rows.sort((a, b) => hitCount(b) - hitCount(a) || byRecent(a, b)); applied.push('order'); }
|
|
156
|
+
else { rows.sort(byRecent); ignored.push('order'); }
|
|
157
|
+
} else if (/^-?attr\./.test(order)) {
|
|
158
|
+
const desc = order.startsWith('-');
|
|
159
|
+
const name = order.replace(/^-?attr\./, '');
|
|
160
|
+
rows.sort((a, b) => {
|
|
161
|
+
const av = dataOf(a)[name]; const bv = dataOf(b)[name];
|
|
162
|
+
const am = av === undefined || av === null; const bm = bv === undefined || bv === null;
|
|
163
|
+
if (am || bm) return am === bm ? byRecent(a, b) : am ? 1 : -1; // undated sorts last, both directions
|
|
164
|
+
const cmp = typeof av === 'number' && typeof bv === 'number' ? av - bv : String(av).localeCompare(String(bv));
|
|
165
|
+
return (desc ? -cmp : cmp) || byRecent(a, b);
|
|
166
|
+
});
|
|
167
|
+
applied.push('order');
|
|
168
|
+
} else if (order) {
|
|
169
|
+
throw status(400, 'order: expected recent, oldest, relevance, or attr.<name>');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
for (const key of Object.keys(params)) {
|
|
173
|
+
if (NOT_FILTERS.has(key) || applied.includes(key) || ignored.includes(key)) continue;
|
|
174
|
+
ignored.push(key);
|
|
175
|
+
}
|
|
176
|
+
return { ...pageOf(rows, params, pageSize), applied_filters: applied, ignored_filters: ignored };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function facets(params: Params) {
|
|
180
|
+
const base = list({ ...params, attr: undefined, under: undefined, page: 1, page_size: MAX_PAGE_SIZE * 1000 } as Params);
|
|
181
|
+
// Re-run the row filter over every page: `list` is paged, so ask for it all in-process.
|
|
182
|
+
const rows = (base as { results: TenantEntity[] }).results;
|
|
183
|
+
const attr = String(params.attr ?? '');
|
|
184
|
+
const under = String(params.under ?? '/').replace(/\/+$/, '');
|
|
185
|
+
const groups = new Map<string, { count: number; has_children: boolean }>();
|
|
186
|
+
for (const e of rows) {
|
|
187
|
+
const value = String(dataOf(e)[attr] ?? '');
|
|
188
|
+
if (!value || (under && value !== under && !value.startsWith(`${under}/`))) continue;
|
|
189
|
+
const rest = value.slice(under.length).replace(/^\//, '');
|
|
190
|
+
const first = rest.split('/')[0];
|
|
191
|
+
const node = first ? `${under}/${first}` : value;
|
|
192
|
+
const g = groups.get(node) ?? { count: 0, has_children: false };
|
|
193
|
+
g.count += 1; g.has_children = g.has_children || rest.includes('/');
|
|
194
|
+
groups.set(node, g);
|
|
195
|
+
}
|
|
196
|
+
const results = [...groups].map(([value, g]) => ({ value, ...g })).sort((a, b) => a.value.localeCompare(b.value));
|
|
197
|
+
return { ...pageOf(results, params, pageSize), applied_filters: [...base.applied_filters.filter((k) => k !== 'order'), 'attr', 'under'], ignored_filters: [] as string[] };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function edges(params: Params) {
|
|
201
|
+
const applied: string[] = [];
|
|
202
|
+
const ignored: string[] = [];
|
|
203
|
+
let rows = relationships.slice();
|
|
204
|
+
const typeById = (id: unknown) => { const e = entities.find((x) => String(x.id) === String(id)); return e ? typeOf(e) : ''; };
|
|
205
|
+
for (const [key, test] of [
|
|
206
|
+
['source', (r: TenantRelationship) => String(r.source) === String(params.source)],
|
|
207
|
+
['target', (r: TenantRelationship) => String(r.target) === String(params.target)],
|
|
208
|
+
['entity', (r: TenantRelationship) => [String(r.source), String(r.target)].includes(String(params.entity))],
|
|
209
|
+
['source__in', (r: TenantRelationship) => asList(params.source__in).includes(String(r.source))],
|
|
210
|
+
['target__in', (r: TenantRelationship) => asList(params.target__in).includes(String(r.target))],
|
|
211
|
+
['entity__in', (r: TenantRelationship) => { const w = asList(params.entity__in); return w.includes(String(r.source)) || w.includes(String(r.target)); }],
|
|
212
|
+
['rel_type', (r: TenantRelationship) => asList(params.rel_type).includes(String(r.rel_type ?? r.relType))],
|
|
213
|
+
['source_type', (r: TenantRelationship) => typeById(r.source) === String(params.source_type)],
|
|
214
|
+
['target_type', (r: TenantRelationship) => typeById(r.target) === String(params.target_type)],
|
|
215
|
+
] as const) {
|
|
216
|
+
if (key in params && !unsupported.has(key)) { rows = rows.filter(test); applied.push(key); }
|
|
217
|
+
}
|
|
218
|
+
for (const key of Object.keys(params)) if (!NOT_FILTERS.has(key) && !REL_KEYS.has(key)) ignored.push(key);
|
|
219
|
+
for (const key of REL_KEYS) if (key in params && unsupported.has(key)) ignored.push(key);
|
|
220
|
+
return { ...pageOf(rows, params, pageSize), applied_filters: applied, ignored_filters: ignored };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const http: AuthorizedHttp = {
|
|
224
|
+
async get<T>(path: string, init?: { params?: Params }): Promise<T> {
|
|
225
|
+
const params = init?.params ?? {};
|
|
226
|
+
requests.push({ method: 'GET', path, params });
|
|
227
|
+
options.onRequest?.('GET', path, params);
|
|
228
|
+
const p = path.replace(/^\/+|\/+$/g, '');
|
|
229
|
+
if (p === 'api/v1/relationships') return edges(params) as T;
|
|
230
|
+
if (p === 'api/v1/entities/facets') return facets(params) as T;
|
|
231
|
+
if (p === 'api/v1/entities') return list(params) as T;
|
|
232
|
+
const detail = /^api\/v1\/entities\/(.+)$/.exec(p);
|
|
233
|
+
if (detail) {
|
|
234
|
+
const found = entities.find((e) => String(e.id) === decodeURIComponent(detail[1]));
|
|
235
|
+
if (!found) throw status(404, `No record ${detail[1]}`);
|
|
236
|
+
return found as T;
|
|
237
|
+
}
|
|
238
|
+
throw status(404, `${path} responded 404`);
|
|
239
|
+
},
|
|
240
|
+
async post<T>(path: string, body?: unknown): Promise<T> {
|
|
241
|
+
const b = (body ?? {}) as Record<string, unknown>;
|
|
242
|
+
requests.push({ method: 'POST', path, params: b });
|
|
243
|
+
options.onRequest?.('POST', path, b);
|
|
244
|
+
const p = path.replace(/^\/+|\/+$/g, '');
|
|
245
|
+
if (p === 'api/v1/entities/upsert') {
|
|
246
|
+
const external = String(b.external_id ?? '');
|
|
247
|
+
const type = String(b.entity_type ?? '');
|
|
248
|
+
const at = entities.findIndex((e) => (e.external_id ?? e.externalId) === external && typeOf(e) === type);
|
|
249
|
+
if (at >= 0) {
|
|
250
|
+
const merged = { ...entities[at], ...(b.name ? { name: String(b.name) } : {}), data: { ...dataOf(entities[at]), ...((b.data as object) ?? {}) } };
|
|
251
|
+
entities[at] = merged;
|
|
252
|
+
return merged as T;
|
|
253
|
+
}
|
|
254
|
+
const made: TenantEntity = { id: `fake${++seq}`, entity_type: type, external_id: external, name: String(b.name ?? ''), data: (b.data as Record<string, unknown>) ?? {}, created_at: new Date().toISOString() };
|
|
255
|
+
entities.push(made);
|
|
256
|
+
return made as T;
|
|
257
|
+
}
|
|
258
|
+
if (p === 'api/v1/relationships') {
|
|
259
|
+
const edge: TenantRelationship = { id: `edge${++seq}`, rel_type: String(b.rel_type), source: String(b.source), target: String(b.target) };
|
|
260
|
+
relationships.push(edge);
|
|
261
|
+
return edge as T;
|
|
262
|
+
}
|
|
263
|
+
throw status(404, `${path} responded 404`);
|
|
264
|
+
},
|
|
265
|
+
async delete<T>(path: string): Promise<T> {
|
|
266
|
+
requests.push({ method: 'DELETE', path, params: {} });
|
|
267
|
+
const id = /relationships\/(.+?)\/?$/.exec(path)?.[1];
|
|
268
|
+
const at = relationships.findIndex((r) => String(r.id) === id);
|
|
269
|
+
if (at < 0) throw status(404, 'not found');
|
|
270
|
+
relationships.splice(at, 1);
|
|
271
|
+
return undefined as T;
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
return { http, requests };
|
|
275
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-memory `NativeCorpusApi` for simulators, demos and tests: the real
|
|
3
|
+
* adapters, mappers and paging run over a fake tenant (`createFakeTenantHttp`)
|
|
4
|
+
* that honours the endpoint contract, so a tab shown here behaves as it will
|
|
5
|
+
* against the tenant - minus the network and any prod data. Ask answers from the
|
|
6
|
+
* fake corpus with the provider-free fixture model (`live: false`).
|
|
7
|
+
*/
|
|
8
|
+
import { askCorpus } from '../../corpus/ask';
|
|
9
|
+
import { createFixtureLlm } from '../../corpus/fixtures';
|
|
10
|
+
import type { AskRequest, AskResult, CorpusAskApi, CorpusApi } from '../../corpus/types';
|
|
11
|
+
import { createNativeCorpusApi, type NativeCorpusApi } from './api';
|
|
12
|
+
import { sampleTenantEntities, sampleTenantRelationships } from './fake-data';
|
|
13
|
+
import { createFakeTenantHttp, type FakeTenant, type FakeTenantOptions } from './fake-tenant';
|
|
14
|
+
|
|
15
|
+
export type FakeNativeCorpusApi = NativeCorpusApi & { tenant: FakeTenant };
|
|
16
|
+
|
|
17
|
+
export function createFakeNativeCorpusApi(options: FakeTenantOptions = {}): FakeNativeCorpusApi {
|
|
18
|
+
const tenant = createFakeTenantHttp({
|
|
19
|
+
entities: sampleTenantEntities(),
|
|
20
|
+
relationships: sampleTenantRelationships(),
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
const base = createNativeCorpusApi({ http: tenant.http, scope: { orgId: 'tandem' } });
|
|
24
|
+
const llm = createFixtureLlm();
|
|
25
|
+
const ask: CorpusAskApi = {
|
|
26
|
+
ask: (request: AskRequest): Promise<AskResult> =>
|
|
27
|
+
askCorpus(request, { corpus: base.corpus as CorpusApi, llm }),
|
|
28
|
+
};
|
|
29
|
+
return { ...base, ask, tenant };
|
|
30
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A server-paged list as a framework-free controller (same pattern as
|
|
3
|
+
* `VoiceNotesController`): load page 1, append the next page on demand, refresh,
|
|
4
|
+
* change the query. It NEVER loads a whole list and narrows it locally - every
|
|
5
|
+
* page is one server request, and `ignoredFilters` carries the server's own
|
|
6
|
+
* report so a screen can say "this filter was not applied" instead of showing an
|
|
7
|
+
* unfiltered list as if it were filtered.
|
|
8
|
+
*/
|
|
9
|
+
export interface PageResult<T> {
|
|
10
|
+
items: T[];
|
|
11
|
+
count?: number;
|
|
12
|
+
/** The page number to request next, or null on the last page. */
|
|
13
|
+
nextPage: number | null;
|
|
14
|
+
/** Filters the server did not confirm. */
|
|
15
|
+
ignoredFilters?: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PagedListState<T> {
|
|
19
|
+
items: T[];
|
|
20
|
+
/** Total matching rows, from the server's COUNT. */
|
|
21
|
+
count: number | null;
|
|
22
|
+
/** True until the first page has arrived. */
|
|
23
|
+
loading: boolean;
|
|
24
|
+
loadingMore: boolean;
|
|
25
|
+
hasMore: boolean;
|
|
26
|
+
ignoredFilters: string[];
|
|
27
|
+
error: string | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface PagedList<T, Q> {
|
|
31
|
+
getState(): PagedListState<T>;
|
|
32
|
+
subscribe(listener: () => void): () => void;
|
|
33
|
+
/** Restart from page 1 (no-op while the first page is already loading). */
|
|
34
|
+
refresh(): Promise<void>;
|
|
35
|
+
/** Append the next page (no-op when there is none or one is in flight). */
|
|
36
|
+
loadMore(): Promise<void>;
|
|
37
|
+
/** Change the query and restart from page 1; a response to the old query is discarded. */
|
|
38
|
+
setQuery(query: Q): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PagedListOptions<T, Q> {
|
|
42
|
+
fetchPage(page: number, query: Q): Promise<PageResult<T>>;
|
|
43
|
+
query?: Q;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const message = (e: unknown) => (e instanceof Error && e.message ? e.message : 'That did not work.');
|
|
47
|
+
|
|
48
|
+
export function createPagedList<T, Q = undefined>(options: PagedListOptions<T, Q>): PagedList<T, Q> {
|
|
49
|
+
let query = options.query as Q;
|
|
50
|
+
let nextPage: number | null = 1;
|
|
51
|
+
let generation = 0;
|
|
52
|
+
let inFlight: 'first' | 'more' | null = null;
|
|
53
|
+
let state: PagedListState<T> = {
|
|
54
|
+
items: [], count: null, loading: true, loadingMore: false, hasMore: false, ignoredFilters: [], error: null,
|
|
55
|
+
};
|
|
56
|
+
const listeners = new Set<() => void>();
|
|
57
|
+
const set = (patch: Partial<PagedListState<T>>) => {
|
|
58
|
+
state = { ...state, ...patch };
|
|
59
|
+
listeners.forEach((l) => l());
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
async function load(page: number, append: boolean): Promise<void> {
|
|
63
|
+
const mine = ++generation;
|
|
64
|
+
inFlight = append ? 'more' : 'first';
|
|
65
|
+
set(append ? { loadingMore: true, error: null } : { loading: state.items.length === 0 && state.count === null, error: null });
|
|
66
|
+
try {
|
|
67
|
+
const result = await options.fetchPage(page, query);
|
|
68
|
+
if (mine !== generation) return;
|
|
69
|
+
nextPage = result.nextPage;
|
|
70
|
+
set({
|
|
71
|
+
items: append ? [...state.items, ...result.items] : result.items,
|
|
72
|
+
count: result.count ?? null,
|
|
73
|
+
hasMore: result.nextPage !== null,
|
|
74
|
+
ignoredFilters: result.ignoredFilters ?? [],
|
|
75
|
+
loading: false, loadingMore: false,
|
|
76
|
+
});
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (mine !== generation) return;
|
|
79
|
+
set({ error: message(e), loading: false, loadingMore: false });
|
|
80
|
+
} finally {
|
|
81
|
+
if (mine === generation) inFlight = null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
getState: () => state,
|
|
87
|
+
subscribe(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
|
88
|
+
refresh() {
|
|
89
|
+
if (inFlight === 'first') return Promise.resolve();
|
|
90
|
+
return load(1, false);
|
|
91
|
+
},
|
|
92
|
+
loadMore() {
|
|
93
|
+
if (inFlight || nextPage === null) return Promise.resolve();
|
|
94
|
+
return load(nextPage, true);
|
|
95
|
+
},
|
|
96
|
+
setQuery(next) {
|
|
97
|
+
query = next;
|
|
98
|
+
nextPage = 1;
|
|
99
|
+
set({ items: [], count: null, loading: true, hasMore: false, ignoredFilters: [] });
|
|
100
|
+
return load(1, false);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
package/src/native/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @startsimpli/integrations/native — the React Native side of voice notes
|
|
2
|
+
* @startsimpli/integrations/native — the React Native side of Tandem: voice notes,
|
|
3
|
+
* the generic tabbed shell and the shared corpus data layer.
|
|
3
4
|
* Pure logic (controller, sections, http) has no react-native import; the
|
|
4
5
|
* screens do, and need the optional peers `react-native` + `@startsimpli/ui-native`.
|
|
5
6
|
*/
|
|
@@ -12,3 +13,12 @@ export { useVoiceNotes } from './components/useVoiceNotes';
|
|
|
12
13
|
export { NotesListScreen, type NotesListScreenProps } from './components/NotesListScreen';
|
|
13
14
|
export { NoteDetailScreen, type NoteDetailScreenProps } from './components/NoteDetailScreen';
|
|
14
15
|
export { NotesShell, type NotesShellProps } from './components/NotesShell';
|
|
16
|
+
export { FoundryTabsShell, type FoundryTab, type FoundryTabsShellProps, type TabContext } from './components/FoundryTabsShell';
|
|
17
|
+
export * from './shell/navigator';
|
|
18
|
+
export * from './corpus/api';
|
|
19
|
+
export * from './corpus/ask';
|
|
20
|
+
export * from './corpus/paged';
|
|
21
|
+
export * from './corpus/fake';
|
|
22
|
+
export * from './corpus/fake-tenant';
|
|
23
|
+
export * from './corpus/fake-data';
|
|
24
|
+
export * from '../corpus/entity-query';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createTabsNavigator, parseTabLink, readTabLaunchTarget } from '../navigator';
|
|
3
|
+
|
|
4
|
+
const tabs = [{ key: 'go' }, { key: 'notes', resetOnLeave: true }, { key: 'tracker' }];
|
|
5
|
+
|
|
6
|
+
describe('createTabsNavigator', () => {
|
|
7
|
+
it('opens on the first tab by default, with empty stacks', () => {
|
|
8
|
+
const nav = createTabsNavigator({ tabs });
|
|
9
|
+
expect(nav.getState().activeKey).toBe('go');
|
|
10
|
+
expect(nav.top('notes')).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
it('opens on initialTab', () => {
|
|
13
|
+
expect(createTabsNavigator({ tabs, initialTab: 'tracker' }).getState().activeKey).toBe('tracker');
|
|
14
|
+
});
|
|
15
|
+
it('an unknown initial tab falls back to the first', () => {
|
|
16
|
+
expect(createTabsNavigator({ tabs, initialTab: 'nope' }).getState().activeKey).toBe('go');
|
|
17
|
+
});
|
|
18
|
+
it('initialDetail implies its tab and seeds that stack', () => {
|
|
19
|
+
const nav = createTabsNavigator({ tabs, initialDetail: { tab: 'notes', id: 'n1' } });
|
|
20
|
+
expect(nav.getState().activeKey).toBe('notes');
|
|
21
|
+
expect(nav.top('notes')).toEqual({ id: 'n1' });
|
|
22
|
+
});
|
|
23
|
+
it('pushes onto the active tab and pops back to the list', () => {
|
|
24
|
+
const nav = createTabsNavigator({ tabs, initialTab: 'tracker' });
|
|
25
|
+
nav.push({ id: 'c1', params: { from: 'list' } });
|
|
26
|
+
expect(nav.top('tracker')).toEqual({ id: 'c1', params: { from: 'list' } });
|
|
27
|
+
nav.push({ id: 'c2' });
|
|
28
|
+
nav.pop();
|
|
29
|
+
expect(nav.top('tracker')?.id).toBe('c1');
|
|
30
|
+
nav.pop();
|
|
31
|
+
expect(nav.top('tracker')).toBeNull();
|
|
32
|
+
nav.pop(); // popping an empty stack is a no-op
|
|
33
|
+
expect(nav.top('tracker')).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
it('keeps each tab\'s stack when switching away and back', () => {
|
|
36
|
+
const nav = createTabsNavigator({ tabs, initialTab: 'tracker' });
|
|
37
|
+
nav.push({ id: 'c1' });
|
|
38
|
+
nav.select('go');
|
|
39
|
+
nav.select('tracker');
|
|
40
|
+
expect(nav.top('tracker')?.id).toBe('c1');
|
|
41
|
+
});
|
|
42
|
+
it('resetOnLeave pops a tab to its list when the user leaves it', () => {
|
|
43
|
+
const nav = createTabsNavigator({ tabs, initialTab: 'notes' });
|
|
44
|
+
nav.push({ id: 'n1' });
|
|
45
|
+
nav.select('go');
|
|
46
|
+
expect(nav.top('notes')).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
it('tracks which tabs were visited, so unvisited tabs are never mounted', () => {
|
|
49
|
+
const nav = createTabsNavigator({ tabs });
|
|
50
|
+
expect(nav.getState().visited).toEqual(['go']);
|
|
51
|
+
nav.select('tracker');
|
|
52
|
+
expect(nav.getState().visited).toEqual(['go', 'tracker']);
|
|
53
|
+
});
|
|
54
|
+
it('open() deep-links: selects the tab and replaces its stack with the detail', () => {
|
|
55
|
+
const nav = createTabsNavigator({ tabs });
|
|
56
|
+
nav.push({ id: 'stale' }, 'tracker');
|
|
57
|
+
nav.open('tracker', { id: 'c9' });
|
|
58
|
+
expect(nav.getState().activeKey).toBe('tracker');
|
|
59
|
+
expect(nav.getState().stacks.tracker).toEqual([{ id: 'c9' }]);
|
|
60
|
+
nav.open('tracker', null);
|
|
61
|
+
expect(nav.top('tracker')).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
it('ignores unknown tabs', () => {
|
|
64
|
+
const nav = createTabsNavigator({ tabs });
|
|
65
|
+
nav.select('missing');
|
|
66
|
+
nav.open('missing', { id: 'x' });
|
|
67
|
+
expect(nav.getState().activeKey).toBe('go');
|
|
68
|
+
});
|
|
69
|
+
it('notifies subscribers on change, and not after unsubscribe', () => {
|
|
70
|
+
const nav = createTabsNavigator({ tabs });
|
|
71
|
+
const fn = vi.fn();
|
|
72
|
+
const off = nav.subscribe(fn);
|
|
73
|
+
nav.select('tracker');
|
|
74
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
75
|
+
nav.select('tracker'); // no change
|
|
76
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
77
|
+
off();
|
|
78
|
+
nav.select('go');
|
|
79
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('deep links and launch args', () => {
|
|
84
|
+
it('parses tab, tab/id and a scheme url', () => {
|
|
85
|
+
expect(parseTabLink('tracker')).toEqual({ tab: 'tracker' });
|
|
86
|
+
expect(parseTabLink('notes/n1')).toEqual({ tab: 'notes', id: 'n1' });
|
|
87
|
+
expect(parseTabLink('tandemgo://tab/notes/n%201')).toEqual({ tab: 'notes', id: 'n 1' });
|
|
88
|
+
expect(parseTabLink('')).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
it('reads -tgTab / -tgDetail launch args', () => {
|
|
91
|
+
const args: Record<string, unknown> = { tgTab: 'tracker', tgDetail: 'c1' };
|
|
92
|
+
expect(readTabLaunchTarget((k) => args[k])).toEqual({ tab: 'tracker', id: 'c1' });
|
|
93
|
+
expect(readTabLaunchTarget(() => undefined)).toBeNull();
|
|
94
|
+
expect(readTabLaunchTarget((k) => (k === 'tgTab' ? 'library' : ''))).toEqual({ tab: 'library' });
|
|
95
|
+
});
|
|
96
|
+
});
|