@startsimpli/integrations 0.2.101 → 0.2.103
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 +3 -3
- package/src/__tests__/focus-standings.test.tsx +119 -0
- package/src/components/pages/PlanningPage.tsx +16 -4
- package/src/corpus/client.ts +5 -0
- package/src/corpus/entity-query.ts +67 -4
- package/src/corpus/index.ts +4 -2
- package/src/corpus/standings.ts +75 -0
- package/src/corpus/types.ts +6 -0
- package/src/native/app/config/__tests__/validate.test.ts +9 -1
- package/src/native/app/config/types.ts +3 -1
- package/src/native/app/config/validate.ts +7 -3
- package/src/native/corpus/__tests__/counts.test.ts +82 -0
- package/src/native/corpus/__tests__/display.test.ts +37 -0
- package/src/native/corpus/api.ts +35 -2
- package/src/native/corpus/counts.ts +16 -0
- package/src/native/corpus/display.ts +62 -0
- package/src/native/corpus/fake-counts.ts +59 -0
- package/src/native/corpus/fake-tenant.ts +31 -3
- package/src/native/home/__tests__/controller.test.ts +24 -11
- package/src/native/home/controller.ts +23 -17
- package/src/native/index.ts +3 -1
- package/src/native/screens/planning/__tests__/controller.test.ts +17 -23
- package/src/native/screens/planning/controller.ts +18 -26
- package/src/native/tracker/__tests__/detail.test.ts +17 -0
- package/src/native/tracker/detail.ts +32 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.103",
|
|
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.0",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
+
"@startsimpli/auth": "^0.4.49",
|
|
53
54
|
"@startsimpli/utils": "^0.4.17",
|
|
54
|
-
"@startsimpli/ui": "^0.4.170"
|
|
55
|
-
"@startsimpli/auth": "^0.4.49"
|
|
55
|
+
"@startsimpli/ui": "^0.4.170"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { PlanningPage } from '../components/pages/PlanningPage';
|
|
4
|
+
import { createPlanningApi } from '../corpus/client';
|
|
5
|
+
import { readStandings, standingsFrom } from '../corpus/standings';
|
|
6
|
+
import type { FocusStanding, PlanningApi } from '../corpus/types';
|
|
7
|
+
import { FIXTURE_DOCUMENTS } from '../corpus/fixtures';
|
|
8
|
+
import type { TenantEntity, TenantRelationship } from '../corpus/entities';
|
|
9
|
+
import { createFakeTenantHttp } from '../native/corpus/fake-tenant';
|
|
10
|
+
|
|
11
|
+
const SCOPE = FIXTURE_DOCUMENTS[0].scope;
|
|
12
|
+
const NOW = Date.parse('2026-11-05T00:00:00Z');
|
|
13
|
+
|
|
14
|
+
function countsHttp() {
|
|
15
|
+
const gets: Array<{ path: string; params: Record<string, unknown> }> = [];
|
|
16
|
+
return {
|
|
17
|
+
gets,
|
|
18
|
+
http: {
|
|
19
|
+
async get<T>(path: string, init?: { params?: Record<string, unknown> }): Promise<T> {
|
|
20
|
+
const params = init?.params ?? {};
|
|
21
|
+
gets.push({ path, params });
|
|
22
|
+
if (params.group_by === 'edge:in_focus,attr.status') {
|
|
23
|
+
return { results: [
|
|
24
|
+
{ values: ['a', 'open'], count: 2 },
|
|
25
|
+
{ values: ['a', 'done'], count: 1 },
|
|
26
|
+
{ values: ['b', 'open'], count: 1 },
|
|
27
|
+
] } as T;
|
|
28
|
+
}
|
|
29
|
+
return { results: [{ values: ['a'], count: 1 }] } as T;
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('readStandings: never a false zero from a truncated page', () => {
|
|
36
|
+
it('reads EVERY page of the grouped answer: 100 projects x 3 statuses is 300 rows', async () => {
|
|
37
|
+
const focuses = Array.from({ length: 100 }, (_, i) => ({ id: `p${String(i).padStart(3, '0')}`, entity_type: 'focus', name: `P${i}`, created_at: '2026-09-01T00:00:00Z', data: {} }));
|
|
38
|
+
const todos: TenantEntity[] = [];
|
|
39
|
+
const edges: TenantRelationship[] = [];
|
|
40
|
+
focuses.forEach((f, i) => (['open', 'done', 'blocked'] as const).forEach((status, k) => {
|
|
41
|
+
const id = `t${i}-${k}`;
|
|
42
|
+
todos.push({ id, entity_type: 'commitment', name: id, created_at: '2026-09-02T00:00:00Z', data: { status } });
|
|
43
|
+
edges.push({ id: `e${id}`, rel_type: 'in_focus', source: id, target: f.id });
|
|
44
|
+
}));
|
|
45
|
+
const tenant = createFakeTenantHttp({ entities: [...(focuses as TenantEntity[]), ...todos], relationships: edges });
|
|
46
|
+
const out = await readStandings(tenant.http as never, focuses.map((f) => f.id), NOW);
|
|
47
|
+
expect(Object.values(out).every((s) => s.total === 3 && s.done === 1)).toBe(true);
|
|
48
|
+
expect(out.p099).toMatchObject({ total: 3, done: 1 });
|
|
49
|
+
// 300 rows at 200 per page: two pages for the status read, one for overdue.
|
|
50
|
+
expect(tenant.requests.filter((r) => r.path.endsWith('counts'))).toHaveLength(3);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('readStandings: a page of projects in two grouped reads', () => {
|
|
55
|
+
it('computes total, done and overdue and includes every id asked for', async () => {
|
|
56
|
+
const { http, gets } = countsHttp();
|
|
57
|
+
const out = await readStandings(http, ['a', 'b', 'c'], NOW);
|
|
58
|
+
expect(out).toEqual({
|
|
59
|
+
a: { focusId: 'a', total: 3, done: 1, overdue: 1 },
|
|
60
|
+
b: { focusId: 'b', total: 1, done: 0, overdue: 0 },
|
|
61
|
+
c: { focusId: 'c', total: 0, done: 0, overdue: 0 },
|
|
62
|
+
});
|
|
63
|
+
expect(gets).toHaveLength(2);
|
|
64
|
+
expect(gets[0]).toMatchObject({ path: 'api/v1/entities/counts', params: { type: 'commitment', edge_targets: 'a,b,c', group_by: 'edge:in_focus,attr.status' } });
|
|
65
|
+
expect(gets[1].params).toMatchObject({ 'attr.status': 'open', 'attr.due_at__lte': '2026-11-05T00:00:00.000Z', group_by: 'edge:in_focus' });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('more than 200 projects go out in chunks of 200', async () => {
|
|
69
|
+
const { http, gets } = countsHttp();
|
|
70
|
+
const ids = Array.from({ length: 250 }, (_, i) => `f${i}`);
|
|
71
|
+
const out = await readStandings(http, ids, NOW);
|
|
72
|
+
expect(Object.keys(out)).toHaveLength(250);
|
|
73
|
+
expect(gets).toHaveLength(4);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('no projects, no requests; duplicates are asked once', async () => {
|
|
77
|
+
const { http, gets } = countsHttp();
|
|
78
|
+
expect(await readStandings(http, [], NOW)).toEqual({});
|
|
79
|
+
await readStandings(http, ['a', 'a'], NOW);
|
|
80
|
+
expect(gets[0].params.edge_targets).toBe('a');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('createPlanningApi exposes it as focusStandings with its own type key and path', async () => {
|
|
84
|
+
const { http, gets } = countsHttp();
|
|
85
|
+
const api = createPlanningApi({ http: http as never, scope: SCOPE, typeKeys: { commitment: 'todo' }, paths: { entities: 'v1/e' } });
|
|
86
|
+
await api.focusStandings!(['a'], NOW);
|
|
87
|
+
expect(gets[0]).toMatchObject({ path: 'v1/e/counts', params: { type: 'todo' } });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('standingsFrom ignores a group for a project not on the page', () => {
|
|
91
|
+
expect(standingsFrom(['a'], [{ group: { 'edge:in_focus': 'zzz', 'attr.status': 'open' }, count: 5 }], [])).toEqual({ a: { focusId: 'a', total: 0, done: 0, overdue: 0 } });
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const page = <T,>(results: T[]) => ({ count: results.length, next: null, previous: null, results, appliedFilters: ['status'] });
|
|
96
|
+
const FOCUS = { id: 'f1', title: 'Crochets', status: 'active', scope: SCOPE } as never;
|
|
97
|
+
|
|
98
|
+
function planning(extra: Partial<PlanningApi>): PlanningApi {
|
|
99
|
+
return { listCommitments: async () => page([]), listFocuses: async () => page([FOCUS]), ...extra } as PlanningApi;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe('PlanningPage standings', () => {
|
|
103
|
+
it('uses ONE batched read for every card and never the per-card path', async () => {
|
|
104
|
+
const focusStanding = vi.fn();
|
|
105
|
+
const focusStandings = vi.fn(async (): Promise<Record<string, FocusStanding>> => ({ f1: { focusId: 'f1', total: 40, done: 12, overdue: 3 } }));
|
|
106
|
+
render(<PlanningPage api={planning({ focusStanding, focusStandings })} scope={SCOPE} now={NOW} />);
|
|
107
|
+
await waitFor(() => expect(screen.getByText(/12 of 40 done/)).toBeInTheDocument());
|
|
108
|
+
expect(focusStandings).toHaveBeenCalledTimes(1);
|
|
109
|
+
expect(focusStanding).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('falls back to a standing per card on a tenant that predates the endpoint', async () => {
|
|
113
|
+
const focusStandings = vi.fn(async () => { throw new Error('400'); });
|
|
114
|
+
const focusStanding = vi.fn(async (focusId: string): Promise<FocusStanding> => ({ focusId, total: 10, done: 5, overdue: 0 }));
|
|
115
|
+
render(<PlanningPage api={planning({ focusStanding, focusStandings })} scope={SCOPE} now={NOW} />);
|
|
116
|
+
await waitFor(() => expect(screen.getByText(/5 of 10 done/)).toBeInTheDocument());
|
|
117
|
+
expect(focusStanding).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -171,10 +171,22 @@ export function PlanningPage({
|
|
|
171
171
|
let live = true;
|
|
172
172
|
void (async () => {
|
|
173
173
|
const loaded = await loadFocuses();
|
|
174
|
-
if (!live
|
|
175
|
-
|
|
176
|
-
//
|
|
177
|
-
|
|
174
|
+
if (!live) return;
|
|
175
|
+
const api = apiRef.current;
|
|
176
|
+
// The clock is passed IN so "overdue" is computed against the frozen mount
|
|
177
|
+
// time rather than a fresh Date.now() per call.
|
|
178
|
+
if (api.focusStandings) {
|
|
179
|
+
// The whole page in two grouped reads. A tenant that predates the
|
|
180
|
+
// endpoint refuses it, and the per-card path below still works.
|
|
181
|
+
try {
|
|
182
|
+
const found = await api.focusStandings(loaded.map((f) => f.id), clock);
|
|
183
|
+
if (!live) return;
|
|
184
|
+
setStandings((prev) => ({ ...prev, ...found }));
|
|
185
|
+
return;
|
|
186
|
+
} catch { /* fall through to one standing per card */ }
|
|
187
|
+
}
|
|
188
|
+
if (!api.focusStanding) return;
|
|
189
|
+
const standing = api.focusStanding.bind(api);
|
|
178
190
|
for (let i = 0; i < loaded.length && live; i += STANDING_CONCURRENCY) {
|
|
179
191
|
const slice = loaded.slice(i, i + STANDING_CONCURRENCY);
|
|
180
192
|
const results = await Promise.all(
|
package/src/corpus/client.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* second copy of the graph that will drift; the edge is the declared contract,
|
|
31
31
|
* so the edge is what is read. The join is cached, bounded and fails soft.
|
|
32
32
|
*/
|
|
33
|
+
import { readStandings } from './standings';
|
|
33
34
|
import {
|
|
34
35
|
DEFAULT_PARTICIPANT_EDGES,
|
|
35
36
|
FOLDER_ROOT,
|
|
@@ -1449,6 +1450,10 @@ export function createPlanningApi(options: CreateCorpusApiOptions): PlanningApi
|
|
|
1449
1450
|
return { focusId, total, done, overdue };
|
|
1450
1451
|
},
|
|
1451
1452
|
|
|
1453
|
+
focusStandings: (focusIds, now) => readStandings(http, focusIds, now ?? Date.now(), {
|
|
1454
|
+
commitmentType: types.commitment, entitiesPath: entities,
|
|
1455
|
+
}),
|
|
1456
|
+
|
|
1452
1457
|
/**
|
|
1453
1458
|
* The tenant's real members, for the owner picker — what closes the
|
|
1454
1459
|
* free-text-owner gap (bd startsim-768w.38.29).
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Server contract: start-simpli-api `tenant-starter/apps/api/filters.py`.
|
|
11
11
|
* page, page_size (max 200), search, order=recent|oldest|relevance|[-]attr.<name>,
|
|
12
|
-
* type, id, id__in (comma list), external_id, external_id__in (REPEATED param),
|
|
13
|
-
* source, party, scope, occurred_after/before, created_after/before,
|
|
12
|
+
* type, type__in (comma list), id, id__in (comma list), external_id, external_id__in (REPEATED param),
|
|
13
|
+
* source, party, scope, occurred_after/before, created_after/before, updated_after,
|
|
14
14
|
* related_to + related_via/related_direction/related_depth,
|
|
15
15
|
* unrelated_via + unrelated_direction (rows with NO such edge),
|
|
16
16
|
* attr.<name>[__op] (op: in gt gte lt lte icontains isnull isblank startswith
|
|
@@ -31,6 +31,8 @@ export type EntityOrder =
|
|
|
31
31
|
export type AttrValue = string | number | boolean | null | undefined;
|
|
32
32
|
|
|
33
33
|
export interface EntityFilters {
|
|
34
|
+
/** Several types in one read (`type__in`): the newest rows across a Home's types. Use instead of `EntityQuery.type`. */
|
|
35
|
+
typeIn?: string[];
|
|
34
36
|
id?: string;
|
|
35
37
|
idIn?: string[];
|
|
36
38
|
externalId?: string;
|
|
@@ -43,6 +45,12 @@ export interface EntityFilters {
|
|
|
43
45
|
occurredBefore?: string;
|
|
44
46
|
createdAfter?: string;
|
|
45
47
|
createdBefore?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Only rows touched strictly AFTER this instant (`updated_after`): pass back the
|
|
50
|
+
* newest `updated_at` held for a cheap refresh. Deletions are not reported; a
|
|
51
|
+
* client reconciles those with a full read.
|
|
52
|
+
*/
|
|
53
|
+
updatedAfter?: string;
|
|
46
54
|
relatedTo?: string;
|
|
47
55
|
relatedVia?: string | string[];
|
|
48
56
|
relatedDirection?: 'out' | 'in' | 'any';
|
|
@@ -57,7 +65,8 @@ export interface EntityFilters {
|
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
export interface EntityQuery {
|
|
60
|
-
|
|
68
|
+
/** Omit only with `filters.typeIn`. */
|
|
69
|
+
type?: string;
|
|
61
70
|
search?: string;
|
|
62
71
|
order?: EntityOrder;
|
|
63
72
|
filters?: EntityFilters;
|
|
@@ -90,6 +99,7 @@ function put(out: Record<string, unknown>, key: string, value: unknown): void {
|
|
|
90
99
|
/** Filters that are common to the list and to facets. */
|
|
91
100
|
export function entityFilterParams(filters: EntityFilters = {}): Record<string, unknown> {
|
|
92
101
|
const out: Record<string, unknown> = {};
|
|
102
|
+
if (filters.typeIn?.length) out.type__in = filters.typeIn.join(',');
|
|
93
103
|
put(out, 'id', filters.id);
|
|
94
104
|
if (filters.idIn?.length) out.id__in = idList('id__in', filters.idIn);
|
|
95
105
|
put(out, 'external_id', filters.externalId);
|
|
@@ -106,6 +116,7 @@ export function entityFilterParams(filters: EntityFilters = {}): Record<string,
|
|
|
106
116
|
put(out, 'occurred_before', filters.occurredBefore);
|
|
107
117
|
put(out, 'created_after', filters.createdAfter);
|
|
108
118
|
put(out, 'created_before', filters.createdBefore);
|
|
119
|
+
put(out, 'updated_after', filters.updatedAfter);
|
|
109
120
|
if (filters.relatedTo) {
|
|
110
121
|
out.related_to = filters.relatedTo;
|
|
111
122
|
// Companions only ride along with a target: alone the server ignores them.
|
|
@@ -138,7 +149,9 @@ export function attrParams(attr: EntityQuery['attr'] = {}): Record<string, unkno
|
|
|
138
149
|
|
|
139
150
|
/** `EntityQuery` -> the query string parameters of `GET api/v1/entities/`. */
|
|
140
151
|
export function entityParams(query: EntityQuery): Record<string, unknown> {
|
|
141
|
-
const out: Record<string, unknown> = {
|
|
152
|
+
const out: Record<string, unknown> = {};
|
|
153
|
+
put(out, 'type', query.type);
|
|
154
|
+
out.page = query.page ?? 1;
|
|
142
155
|
if (query.pageSize) out.page_size = Math.min(Math.max(1, query.pageSize), MAX_PAGE_SIZE);
|
|
143
156
|
const search = query.search?.trim();
|
|
144
157
|
if (search) out.search = search.slice(0, TEXT_FILTER_MAX);
|
|
@@ -164,6 +177,56 @@ export function facetParams(query: FacetQuery): Record<string, unknown> {
|
|
|
164
177
|
return out;
|
|
165
178
|
}
|
|
166
179
|
|
|
180
|
+
/**
|
|
181
|
+
* `GET api/v1/entities/counts/`: how many rows, grouped by up to two keys - ONE
|
|
182
|
+
* request for a Home tile row, a filter badge row or a page of project cards.
|
|
183
|
+
* Every list filter narrows it exactly as it narrows the list.
|
|
184
|
+
*
|
|
185
|
+
* Group keys: `type`, `attr.<name>`, `edge:<rel_type>[:out|in]` (the id at the
|
|
186
|
+
* other end of the row's edge; the row is the source for `out`, the default).
|
|
187
|
+
* `edgeTargets` bounds an edge key to one page of far-end ids.
|
|
188
|
+
*/
|
|
189
|
+
export type CountGroup = 'type' | `attr.${string}` | `edge:${string}`;
|
|
190
|
+
|
|
191
|
+
export interface CountQuery extends Omit<EntityQuery, 'order'> {
|
|
192
|
+
groupBy: CountGroup[];
|
|
193
|
+
edgeTargets?: string[];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A group value: an id, a status, a type key; `null` is "none" (unfiled, no status). */
|
|
197
|
+
export type CountValue = string | number | boolean | null;
|
|
198
|
+
|
|
199
|
+
export interface CountRow {
|
|
200
|
+
/** Keyed by the group token the query asked for, e.g. `{ 'edge:in_focus': 'f1', 'attr.status': 'open' }`. */
|
|
201
|
+
group: Record<string, CountValue>;
|
|
202
|
+
count: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* What the server sends: values by POSITION (`group_by` order), never keyed by
|
|
207
|
+
* token. A group token is data, and the apps' API client camelCases response
|
|
208
|
+
* KEYS (`edge:in_focus` -> `edge:inFocus`), which would make every lookup miss.
|
|
209
|
+
*/
|
|
210
|
+
export interface WireCountRow { values: CountValue[]; count: number }
|
|
211
|
+
|
|
212
|
+
/** Wire rows -> rows keyed by the tokens the CALLER asked for, in that order. */
|
|
213
|
+
export function toCountRows(groupBy: CountGroup[], rows: WireCountRow[] | undefined): CountRow[] {
|
|
214
|
+
return (rows ?? []).map((row) => ({
|
|
215
|
+
group: Object.fromEntries(groupBy.map((token, i) => [token, row.values?.[i] ?? null])),
|
|
216
|
+
count: row.count,
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function countParams(query: CountQuery): Record<string, unknown> {
|
|
221
|
+
if (query.groupBy.length < 1 || query.groupBy.length > 2) {
|
|
222
|
+
throw new Error('groupBy: name one or two keys.');
|
|
223
|
+
}
|
|
224
|
+
const out = entityParams({ ...query, order: undefined });
|
|
225
|
+
out.group_by = query.groupBy.join(',');
|
|
226
|
+
if (query.edgeTargets?.length) out.edge_targets = idList('edge_targets', query.edgeTargets);
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
|
|
167
230
|
export interface RelationshipListQuery {
|
|
168
231
|
source?: string;
|
|
169
232
|
target?: string;
|
package/src/corpus/index.ts
CHANGED
|
@@ -262,11 +262,13 @@ export type {
|
|
|
262
262
|
VoiceTranscriber,
|
|
263
263
|
} from './voice';
|
|
264
264
|
|
|
265
|
+
export { readStandings, standingsFrom } from './standings';
|
|
266
|
+
export type { StandingsOptions } from './standings';
|
|
265
267
|
export {
|
|
266
|
-
attrParams, entityFilterParams, entityParams, facetParams, reconcileFilters, relationshipParams,
|
|
268
|
+
attrParams, countParams, entityFilterParams, entityParams, facetParams, reconcileFilters, relationshipParams,
|
|
267
269
|
sentFilterNames, toEntityPage,
|
|
268
270
|
} from './entity-query';
|
|
269
271
|
export type {
|
|
270
|
-
AttrValue, EntityFilters, EntityOrder, EntityPage, EntityQuery, FacetQuery, FilterReport,
|
|
272
|
+
AttrValue, CountGroup, CountQuery, CountRow, EntityFilters, EntityOrder, EntityPage, EntityQuery, FacetQuery, FilterReport,
|
|
271
273
|
FilterVerdict, RelationshipListQuery,
|
|
272
274
|
} from './entity-query';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "12 of 40 done, 3 overdue" for a PAGE of projects, from two grouped reads of
|
|
3
|
+
* `GET api/v1/entities/counts/` (bd startsim-09zue) - however many projects the
|
|
4
|
+
* page holds. It replaces `focusStanding`'s three count-only reads PER project
|
|
5
|
+
* (a 100-project web page was 300 requests). The web and native Planning screens
|
|
6
|
+
* share this one reader.
|
|
7
|
+
*
|
|
8
|
+
* `all` to-dos per project x status -> total, done
|
|
9
|
+
* `overdue` open to-dos past due, per project -> overdue
|
|
10
|
+
*
|
|
11
|
+
* Every id asked for is in the result, zeros when the project holds nothing, so a
|
|
12
|
+
* card never waits on a count that will not come.
|
|
13
|
+
*/
|
|
14
|
+
import { MAX_PAGE_SIZE, countParams, toCountRows, type CountQuery, type CountRow, type WireCountRow } from './entity-query';
|
|
15
|
+
import type { CorpusHttp } from './client';
|
|
16
|
+
import type { FocusStanding } from './types';
|
|
17
|
+
import { MAX_ID_LIST } from './entities';
|
|
18
|
+
|
|
19
|
+
const IN_FOCUS_KEY = 'edge:in_focus';
|
|
20
|
+
const STATUS_KEY = 'attr.status';
|
|
21
|
+
|
|
22
|
+
export interface StandingsOptions {
|
|
23
|
+
/** The tenant's commitment type key (default `commitment`). */
|
|
24
|
+
commitmentType?: string;
|
|
25
|
+
entitiesPath?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function standingsFrom(focusIds: string[], all: CountRow[], overdue: CountRow[]): Record<string, FocusStanding> {
|
|
29
|
+
const out: Record<string, FocusStanding> = {};
|
|
30
|
+
for (const focusId of focusIds) out[focusId] = { focusId, total: 0, done: 0, overdue: 0 };
|
|
31
|
+
for (const row of all) {
|
|
32
|
+
const target = out[String(row.group[IN_FOCUS_KEY])];
|
|
33
|
+
if (!target) continue;
|
|
34
|
+
target.total += row.count;
|
|
35
|
+
if (row.group[STATUS_KEY] === 'done') target.done += row.count;
|
|
36
|
+
}
|
|
37
|
+
for (const row of overdue) {
|
|
38
|
+
const target = out[String(row.group[IN_FOCUS_KEY])];
|
|
39
|
+
if (target) target.overdue += row.count;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function readStandings(
|
|
45
|
+
http: Pick<CorpusHttp, 'get'>,
|
|
46
|
+
focusIds: string[],
|
|
47
|
+
now: number,
|
|
48
|
+
options: StandingsOptions = {},
|
|
49
|
+
): Promise<Record<string, FocusStanding>> {
|
|
50
|
+
const ids = [...new Set(focusIds)];
|
|
51
|
+
if (!ids.length) return {};
|
|
52
|
+
const path = `${options.entitiesPath ?? 'api/v1/entities'}/counts`;
|
|
53
|
+
const type = options.commitmentType ?? 'commitment';
|
|
54
|
+
const asOf = new Date(now).toISOString();
|
|
55
|
+
// EVERY page of a grouped read: a chunk of ids x their statuses can exceed one
|
|
56
|
+
// page, and a row that is not read becomes a false zero on a project card.
|
|
57
|
+
const rows = async (query: CountQuery): Promise<CountRow[]> => {
|
|
58
|
+
const out: CountRow[] = [];
|
|
59
|
+
for (let page = 1; ; page += 1) {
|
|
60
|
+
const body = await http.get<{ results?: WireCountRow[]; next?: string | null }>(path, { params: countParams({ ...query, page }) });
|
|
61
|
+
out.push(...toCountRows(query.groupBy, body.results));
|
|
62
|
+
if (!body.next) return out;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const chunks: string[][] = [];
|
|
66
|
+
for (let i = 0; i < ids.length; i += MAX_ID_LIST) chunks.push(ids.slice(i, i + MAX_ID_LIST));
|
|
67
|
+
const parts = await Promise.all(chunks.map(async (edgeTargets) => {
|
|
68
|
+
const [all, overdue] = await Promise.all([
|
|
69
|
+
rows({ type, groupBy: [IN_FOCUS_KEY, STATUS_KEY], edgeTargets, pageSize: MAX_PAGE_SIZE }),
|
|
70
|
+
rows({ type, groupBy: [IN_FOCUS_KEY], edgeTargets, pageSize: MAX_PAGE_SIZE, attr: { status: 'open', due_at__lte: asOf } }),
|
|
71
|
+
]);
|
|
72
|
+
return standingsFrom(edgeTargets, all, overdue);
|
|
73
|
+
}));
|
|
74
|
+
return Object.assign({}, ...parts);
|
|
75
|
+
}
|
package/src/corpus/types.ts
CHANGED
|
@@ -1373,6 +1373,12 @@ export interface PlanningApi extends CommitmentApi {
|
|
|
1373
1373
|
listChildFocuses?(focusId: string): Promise<CorpusPage<Focus>>;
|
|
1374
1374
|
/** Counts for one focus, from `count` alone — no row bodies cross the wire. */
|
|
1375
1375
|
focusStanding?(focusId: string, now?: number): Promise<FocusStanding>;
|
|
1376
|
+
/**
|
|
1377
|
+
* Counts for a whole PAGE of projects in two grouped reads (`entities/counts`),
|
|
1378
|
+
* keyed by focus id. Prefer it over calling `focusStanding` per card; a tenant
|
|
1379
|
+
* that predates the endpoint rejects it and the caller falls back.
|
|
1380
|
+
*/
|
|
1381
|
+
focusStandings?(focusIds: string[], now?: number): Promise<Record<string, FocusStanding>>;
|
|
1376
1382
|
/** The tenant's real members, for the owner picker. Absent when the fork is
|
|
1377
1383
|
* not wired to central, in which case owners stay free text. */
|
|
1378
1384
|
listMembers?(): Promise<Array<{ sub: string; email: string; name?: string }>>;
|
|
@@ -8,11 +8,19 @@ describe('validateFoundryApp', () => {
|
|
|
8
8
|
const c = resolveFoundryApp(minimal);
|
|
9
9
|
expect(c.app).toEqual({ name: 'Acme Go', slug: 'acme-go', scheme: 'acmego', bundleId: 'com.startsimpli.acmego' });
|
|
10
10
|
expect(c.tenant).toEqual({ url: 'https://acme.ai.startsimpli.com', centralUrl: 'https://api.startsimpli.com' });
|
|
11
|
-
expect(c.brand).toMatchObject({ name: 'Acme Go', authApp: '
|
|
11
|
+
expect(c.brand).toMatchObject({ name: 'Acme Go', authApp: 'acme', logTag: 'acmego' });
|
|
12
12
|
expect(c.tabs.map((t) => t.key)).toEqual(['home', 'go', 'notes', 'tracker', 'library', 'ask', 'planning', 'connections', 'connect-claude']);
|
|
13
13
|
expect(c.maxVisibleTabs).toBe(5);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
+
it('the auth app is the tenant slug: explicit, else the *.ai.startsimpli.com host, else the scheme', () => {
|
|
17
|
+
const auth = (input: object) => resolveFoundryApp(input).brand.authApp;
|
|
18
|
+
expect(auth({ app: { name: 'A Go' }, tenant: { url: 'http://localhost:4300', slug: 'hours' } })).toBe('hours');
|
|
19
|
+
expect(auth({ app: { name: 'A Go' }, tenant: { url: 'https://hours.ai.startsimpli.com' } })).toBe('hours');
|
|
20
|
+
expect(auth({ app: { name: 'A Go' }, tenant: { url: 'http://localhost:4300' } })).toBe('ago');
|
|
21
|
+
expect(auth({ app: { name: 'A Go' }, brand: { authApp: 'x' }, tenant: { url: 'http://localhost', slug: 'hours' } })).toBe('x');
|
|
22
|
+
});
|
|
23
|
+
|
|
16
24
|
it('features drive the default tab list', () => {
|
|
17
25
|
const c = resolveFoundryApp({ ...minimal, features: { recording: false, ask: false, connectClaude: false, planning: false } });
|
|
18
26
|
expect(c.tabs.map((t) => t.screen)).toEqual(['home', 'notes', 'tracker', 'library', 'connections']);
|
|
@@ -78,7 +78,7 @@ export interface FoundryAppConfig {
|
|
|
78
78
|
/** The Foundry's product name: Home title, sign-in title. */
|
|
79
79
|
name: string;
|
|
80
80
|
tagline: string;
|
|
81
|
-
/** The app slug central auth signs in against. */
|
|
81
|
+
/** The app slug central auth signs in against: it picks the token's audience, so it must be the tenant's slug. */
|
|
82
82
|
authApp: string;
|
|
83
83
|
/** Prefix of the diagnostics log. */
|
|
84
84
|
logTag: string;
|
|
@@ -86,6 +86,8 @@ export interface FoundryAppConfig {
|
|
|
86
86
|
tenant: {
|
|
87
87
|
/** The Foundry's tenant API origin. */
|
|
88
88
|
url: string;
|
|
89
|
+
/** The tenant slug. Central auth mints the token for this audience, so `brand.authApp` defaults to it (else to the host's first label on *.ai.startsimpli.com, else the scheme). */
|
|
90
|
+
slug?: string;
|
|
89
91
|
/** Central auth + member-level APIs. */
|
|
90
92
|
centralUrl: string;
|
|
91
93
|
};
|
|
@@ -32,6 +32,9 @@ export function deriveAppNames(name: string): { slug: string; scheme: string; bu
|
|
|
32
32
|
return { slug, scheme, bundleId: `com.startsimpli.${scheme}` };
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** `https://acme.ai.startsimpli.com` -> `acme`. */
|
|
36
|
+
const hostSlug = (url: string): string | undefined => /^https?:\/\/([a-z][a-z0-9-]*)\.ai\.startsimpli\.com(?:[/:]|$)/i.exec(url)?.[1]?.toLowerCase();
|
|
37
|
+
|
|
35
38
|
const str = (v: unknown): v is string => typeof v === 'string' && v.trim() !== '';
|
|
36
39
|
|
|
37
40
|
/**
|
|
@@ -77,7 +80,8 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
|
|
|
77
80
|
|
|
78
81
|
// tenant
|
|
79
82
|
const tenant = section('tenant', true);
|
|
80
|
-
allowed(tenant, ['url', 'centralUrl'], 'tenant');
|
|
83
|
+
allowed(tenant, ['url', 'centralUrl', 'slug'], 'tenant');
|
|
84
|
+
if (tenant.slug !== undefined && !(str(tenant.slug) && KEY.test(tenant.slug))) bad('tenant.slug', 'must be lowercase letters, digits and dashes');
|
|
81
85
|
if (!str(tenant.url)) bad('tenant.url', 'is required (the Foundry tenant URL)');
|
|
82
86
|
else if (!HTTP.test(tenant.url)) bad('tenant.url', `"${tenant.url}" must start with http:// or https://`);
|
|
83
87
|
if (tenant.centralUrl !== undefined && !(str(tenant.centralUrl) && HTTP.test(tenant.centralUrl))) bad('tenant.centralUrl', 'must start with http:// or https://');
|
|
@@ -181,10 +185,10 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
|
|
|
181
185
|
brand: {
|
|
182
186
|
name: resolvedBrandName,
|
|
183
187
|
tagline: (brand.tagline as string | undefined) ?? defaultBrandTagline(),
|
|
184
|
-
authApp: (brand.authApp as string | undefined) ?? scheme,
|
|
188
|
+
authApp: (brand.authApp as string | undefined) ?? (tenant.slug as string | undefined) ?? hostSlug(tenant.url as string) ?? scheme,
|
|
185
189
|
logTag: (brand.logTag as string | undefined) ?? scheme,
|
|
186
190
|
},
|
|
187
|
-
tenant: { url: trimSlash(tenant.url as string), centralUrl: trimSlash((tenant.centralUrl as string | undefined) ?? DEFAULT_CENTRAL_URL) },
|
|
191
|
+
tenant: { url: trimSlash(tenant.url as string), centralUrl: trimSlash((tenant.centralUrl as string | undefined) ?? DEFAULT_CENTRAL_URL), ...(tenant.slug ? { slug: tenant.slug as string } : {}) },
|
|
188
192
|
theme: { mode: (theme.mode as FoundryAppConfig['theme']['mode'] | undefined) ?? DEFAULT_BASE.theme.mode },
|
|
189
193
|
features,
|
|
190
194
|
tabs,
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { countParams } from '../../../corpus/entity-query';
|
|
3
|
+
import { createFakeNativeCorpusApi } from '../fake';
|
|
4
|
+
import { countsBy } from '../counts';
|
|
5
|
+
|
|
6
|
+
describe('countParams: the grouped-count query spelled for the wire', () => {
|
|
7
|
+
it('spells group_by, edge targets and the shared list filters', () => {
|
|
8
|
+
expect(countParams({
|
|
9
|
+
type: 'commitment', groupBy: ['edge:in_focus', 'attr.status'], edgeTargets: ['f1', 'f2'],
|
|
10
|
+
attr: { status__in: ['open', 'blocked'] }, filters: { updatedAfter: '2026-11-01T00:00:00Z' },
|
|
11
|
+
})).toEqual({
|
|
12
|
+
type: 'commitment', group_by: 'edge:in_focus,attr.status', edge_targets: 'f1,f2',
|
|
13
|
+
'attr.status__in': 'open,blocked', updated_after: '2026-11-01T00:00:00Z', page: 1,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it('refuses zero or more than two keys before it reaches the server', () => {
|
|
17
|
+
expect(() => countParams({ groupBy: [] })).toThrow(/one or two/);
|
|
18
|
+
expect(() => countParams({ groupBy: ['type', 'attr.a', 'attr.b'] })).toThrow(/one or two/);
|
|
19
|
+
});
|
|
20
|
+
it('typeIn rides as type__in', () => {
|
|
21
|
+
expect(countParams({ groupBy: ['type'], filters: { typeIn: ['a', 'b'] } })).toMatchObject({ type__in: 'a,b' });
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('entities.counts over the fake tenant', () => {
|
|
26
|
+
it('rows arrive by position and are keyed by the tokens the caller asked for, in order', async () => {
|
|
27
|
+
const api = createFakeNativeCorpusApi();
|
|
28
|
+
const page = await api.entities.counts({ type: 'commitment', groupBy: ['edge:in_focus', 'attr.status'] });
|
|
29
|
+
const first = page.items[0];
|
|
30
|
+
expect(Object.keys(first.group)).toEqual(['edge:in_focus', 'attr.status']);
|
|
31
|
+
// the wire never keys data: a camelCasing client cannot break the lookup
|
|
32
|
+
const wire = await api.http.get<{ results: Array<Record<string, unknown>>; group_by: string[] }>('api/v1/entities/counts', { params: { type: 'commitment', group_by: 'edge:in_focus,attr.status' } });
|
|
33
|
+
expect(wire.group_by).toEqual(['edge:in_focus', 'attr.status']);
|
|
34
|
+
expect(Object.keys(wire.results[0]).sort()).toEqual(['count', 'values']);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('one read gives the count per type', async () => {
|
|
38
|
+
const api = createFakeNativeCorpusApi();
|
|
39
|
+
const page = await api.entities.counts({ groupBy: ['type'] });
|
|
40
|
+
expect(countsBy(page.items, 'type')).toEqual({ commitment: 6, focus: 3, source_document: 3 });
|
|
41
|
+
expect(page.appliedFilters).toContain('group_by');
|
|
42
|
+
expect(api.tenant.requests.filter((r) => r.path.includes('counts'))).toHaveLength(1);
|
|
43
|
+
});
|
|
44
|
+
it('groups to-dos per project, keeping the unfiled bucket under null', async () => {
|
|
45
|
+
const api = createFakeNativeCorpusApi();
|
|
46
|
+
const page = await api.entities.counts({ type: 'commitment', groupBy: ['edge:in_focus'] });
|
|
47
|
+
expect(countsBy(page.items, 'edge:in_focus')).toEqual({ f287: 3, fma: 1, '': 2 });
|
|
48
|
+
});
|
|
49
|
+
it('edgeTargets bounds the answer to the ids asked', async () => {
|
|
50
|
+
const api = createFakeNativeCorpusApi();
|
|
51
|
+
const page = await api.entities.counts({ type: 'commitment', groupBy: ['edge:in_focus'], edgeTargets: ['fma'] });
|
|
52
|
+
expect(countsBy(page.items, 'edge:in_focus')).toEqual({ fma: 1 });
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('entities.list: typeIn and updatedAfter', () => {
|
|
57
|
+
it('one read spans several types', async () => {
|
|
58
|
+
const api = createFakeNativeCorpusApi();
|
|
59
|
+
const page = await api.entities.list({ type: undefined as never, filters: { typeIn: ['commitment', 'focus'] }, order: 'recent' });
|
|
60
|
+
expect(new Set(page.items.map((e) => e.entity_type))).toEqual(new Set(['commitment', 'focus']));
|
|
61
|
+
expect(page.appliedFilters).toContain('type__in');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('standings: a page of project cards in two reads', () => {
|
|
66
|
+
it('total, done and overdue per project from grouped counts', async () => {
|
|
67
|
+
const api = createFakeNativeCorpusApi();
|
|
68
|
+
const before = api.tenant.requests.length;
|
|
69
|
+
const standings = await api.standings(['f287', 'fma', 'fdbg'], Date.parse('2026-11-05T00:00:00Z'));
|
|
70
|
+
expect(api.tenant.requests.length - before).toBe(2);
|
|
71
|
+
expect(standings).toEqual({
|
|
72
|
+
f287: { focusId: 'f287', total: 3, done: 0, overdue: 1 },
|
|
73
|
+
fma: { focusId: 'fma', total: 1, done: 0, overdue: 0 },
|
|
74
|
+
fdbg: { focusId: 'fdbg', total: 0, done: 0, overdue: 0 },
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it('no ids, no requests', async () => {
|
|
78
|
+
const api = createFakeNativeCorpusApi();
|
|
79
|
+
expect(await api.standings([], 0)).toEqual({});
|
|
80
|
+
expect(api.tenant.requests).toHaveLength(0);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { displaysFrom, resolveDisplay } from '../display';
|
|
3
|
+
import { createFakeNativeCorpusApi } from '../fake';
|
|
4
|
+
|
|
5
|
+
const todo = { id: 't1', entity_type: 'todo', name: 'Call Megan', data: { owner: 'Quinn', due_at: '2026-11-05', status: 'blocked' } };
|
|
6
|
+
const config = { title: 'name', subtitle: 'owner', date: 'due_at', status: 'status', tones: { blocked: 'bad', done: 'good' }, icon: 'check-circle' } as const;
|
|
7
|
+
|
|
8
|
+
describe('resolveDisplay', () => {
|
|
9
|
+
it('reads title, subtitle, date, status tone and icon from the declaration', () => {
|
|
10
|
+
expect(resolveDisplay(config, todo)).toEqual({
|
|
11
|
+
title: 'Call Megan', subtitle: 'Quinn', date: '2026-11-05', status: { value: 'blocked', tone: 'bad' }, icon: 'check-circle',
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it('a type that declares nothing reads as its name', () => {
|
|
15
|
+
expect(resolveDisplay(undefined, todo)).toEqual({ title: 'Call Megan', subtitle: null, date: null, status: null, icon: null });
|
|
16
|
+
});
|
|
17
|
+
it('an unmapped status is neutral and a missing attribute is null, never "undefined"', () => {
|
|
18
|
+
expect(resolveDisplay(config, { ...todo, data: { status: 'weird' } })).toMatchObject({ subtitle: null, date: null, status: { value: 'weird', tone: 'neutral' } });
|
|
19
|
+
});
|
|
20
|
+
it('falls back to the external id then the id for a nameless row', () => {
|
|
21
|
+
expect(resolveDisplay(undefined, { id: 'x', external_id: 'ext:1', name: '' }).title).toBe('ext:1');
|
|
22
|
+
expect(resolveDisplay(undefined, { id: 'x' }).title).toBe('x');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('displaysFrom / api.schema.displays', () => {
|
|
27
|
+
it('keeps only the types that declare a display', () => {
|
|
28
|
+
expect(displaysFrom([{ key: 'a', config: { display: { title: 'name' } } }, { key: 'b', config: {} }, { key: 'c' }])).toEqual({ a: { title: 'name' } });
|
|
29
|
+
});
|
|
30
|
+
it('reads the tenant schema once', async () => {
|
|
31
|
+
const api = createFakeNativeCorpusApi();
|
|
32
|
+
const first = await api.schema.displays();
|
|
33
|
+
expect(first.commitment).toMatchObject({ status: 'status' });
|
|
34
|
+
await api.schema.displays();
|
|
35
|
+
expect(api.tenant.requests.filter((r) => r.path.includes('schema/types'))).toHaveLength(1);
|
|
36
|
+
});
|
|
37
|
+
});
|