@startsimpli/integrations 0.2.216 → 0.2.218

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.
Files changed (49) hide show
  1. package/package.json +5 -5
  2. package/src/__tests__/briefing-timezone-memory.test.ts +56 -0
  3. package/src/__tests__/corpus-storage.test.ts +6 -0
  4. package/src/__tests__/corpus-tracker.test.tsx +37 -0
  5. package/src/__tests__/engine-near-date.test.ts +136 -0
  6. package/src/__tests__/fleet-page.test.tsx +24 -0
  7. package/src/__tests__/near-date-ui.test.tsx +74 -0
  8. package/src/__tests__/relay-cli.test.ts +1 -1
  9. package/src/__tests__/share-default-row.test.tsx +44 -0
  10. package/src/__tests__/shared-with.test.tsx +87 -0
  11. package/src/__tests__/sync-health.test.ts +70 -0
  12. package/src/__tests__/task-detail.test.tsx +1 -1
  13. package/src/api/_fetch.ts +1 -1
  14. package/src/api/connections.ts +14 -0
  15. package/src/components/DocumentDetail.tsx +3 -0
  16. package/src/components/SharedWith.tsx +140 -0
  17. package/src/components/index.ts +1 -0
  18. package/src/components/pages/FleetPage.tsx +16 -4
  19. package/src/components/pages/SyncHealthCard.tsx +42 -0
  20. package/src/components/pages/TaskDetailPage.tsx +4 -2
  21. package/src/components/pages/TrackerPage.tsx +27 -7
  22. package/src/components/pages/connections/ConnectionCard.tsx +5 -0
  23. package/src/components/pages/connections/ShareDefaultRow.tsx +91 -0
  24. package/src/components/pages/connections/bound-api.ts +4 -1
  25. package/src/components/pages/tracker/PossiblyDone.tsx +28 -2
  26. package/src/components/pages/tracker/Suggestion.tsx +15 -11
  27. package/src/components/pages/types.ts +11 -0
  28. package/src/components/table/todo-model.ts +3 -0
  29. package/src/corpus/briefing/generate-weekly.ts +2 -1
  30. package/src/corpus/briefing/generate.ts +2 -1
  31. package/src/corpus/briefing/zone.ts +24 -0
  32. package/src/corpus/client.ts +6 -0
  33. package/src/corpus/commitments.ts +48 -3
  34. package/src/corpus/converse/fleet-view.ts +1 -1
  35. package/src/corpus/converse/fleet.ts +1 -1
  36. package/src/corpus/converse/index.ts +2 -0
  37. package/src/corpus/converse/respond.ts +2 -1
  38. package/src/corpus/converse/sync-health.ts +96 -0
  39. package/src/corpus/engine/apply.ts +10 -3
  40. package/src/corpus/engine/decide.ts +3 -2
  41. package/src/corpus/engine/near-match.ts +71 -0
  42. package/src/corpus/engine/proposed-due.ts +44 -0
  43. package/src/corpus/engine/suggestion.ts +5 -0
  44. package/src/corpus/engine/types.ts +2 -0
  45. package/src/corpus/entities.ts +13 -0
  46. package/src/corpus/extract.ts +10 -4
  47. package/src/corpus/index.ts +2 -0
  48. package/src/corpus/sharing.ts +135 -0
  49. package/src/corpus/types.ts +21 -1
@@ -25,6 +25,7 @@
25
25
  import { briefingSections } from './briefing-text';
26
26
  import { readPossiblyDone, writePossiblyDone } from './possibly-done';
27
27
  import { readSuggestion, writeSuggestion } from './engine/suggestion';
28
+ import { readProposedDue, writeProposedDue } from './engine/proposed-due';
28
29
  import { withSourceEntity } from './source-entity';
29
30
  import { decodeOwnerSubs, encodeOwnerSubs } from './owner-link';
30
31
  import { readItemSync, type ItemSync } from '../task-tracker/item-sync';
@@ -231,6 +232,14 @@ function asText(value: unknown): string {
231
232
  return '';
232
233
  }
233
234
 
235
+ /** Did a person set the due date? The tenant stamps `field_edited_at.due_at` on a person's edit (see commitment-edit.ts). */
236
+ function editedDueAt(data: Record<string, unknown>): boolean {
237
+ const stamps = pick(data, 'field_edited_at', 'fieldEditedAt');
238
+ if (!stamps || typeof stamps !== 'object') return false;
239
+ const s = stamps as Record<string, unknown>;
240
+ return Boolean(s.due_at ?? s.dueAt ?? s.DueAt);
241
+ }
242
+
234
243
  function asIso(value: unknown): string | null {
235
244
  const text = asText(value);
236
245
  if (!text) return null;
@@ -759,6 +768,9 @@ export function toCommitment(
759
768
  ...(readSuggestion(pick(data, 'suggestion')) ? { suggestion: readSuggestion(pick(data, 'suggestion')) } : {}),
760
769
  ...(readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')).length
761
770
  ? { possiblyDone: readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')) } : {}),
771
+ ...(readProposedDue(pick(data, 'proposed_due', 'proposedDue')).length
772
+ ? { proposedDue: readProposedDue(pick(data, 'proposed_due', 'proposedDue')) } : {}),
773
+ ...(editedDueAt(data) ? { dueSetByPerson: true } : {}),
762
774
  firstSeenAt: asIso(pick(data, 'first_seen_at', 'firstSeenAt')),
763
775
  lastSeenAt: asIso(pick(data, 'last_seen_at', 'lastSeenAt')),
764
776
  extractorVersion: asText(pick(data, 'extractor_version', 'extractorVersion')),
@@ -851,6 +863,7 @@ export function commitmentToEntity(commitment: Commitment): {
851
863
  })),
852
864
  ...(commitment.possiblyDone?.length ? { possibly_done: writePossiblyDone(commitment.possiblyDone) } : {}),
853
865
  ...(commitment.suggestion ? { suggestion: writeSuggestion(commitment.suggestion) } : {}),
866
+ ...(commitment.proposedDue?.length ? { proposed_due: writeProposedDue(commitment.proposedDue) } : {}),
854
867
  extractor_version: commitment.extractorVersion,
855
868
  source: commitment.source,
856
869
  // Marks the row as pipeline-written, the same way the corpus delivery
@@ -431,7 +431,15 @@ export async function extractCommitments(
431
431
 
432
432
  // 5. identity, dedupe within the run, then against what is stored.
433
433
  const groups = mergeDrafts([...ruleDrafts, ...modelDrafts]);
434
- const reconciled = reconcile(existing, groups, { scope: request.scope, documents });
434
+ // The owner's own reviews graduate a rule (./engine/graduation); automation never reviews.
435
+ const engineLabels = request.engine
436
+ ? request.engine.labels ?? labelsFrom(existing.filter((item) => item.scope?.ownerSub === request.engine!.ownerSub))
437
+ : undefined;
438
+ const reconciled = reconcile(existing, groups, {
439
+ scope: request.scope,
440
+ documents,
441
+ ...(request.engine ? { engine: { ownerSub: request.engine.ownerSub, labels: engineLabels } } : {}),
442
+ });
435
443
 
436
444
  // 6. resolutions, against the documents the scope guard approved and nothing else.
437
445
  const resolutions = applyResolutions(reconciled.commitments, claims, { documents, proposeOnly: Boolean(request.engine) });
@@ -492,9 +500,7 @@ export async function extractCommitments(
492
500
  let written = resolutions.commitments;
493
501
  if (request.engine) {
494
502
  const ownerNames = [...new Set([...request.engine.ownerNames, ...ownerNamesFrom(existing, request.engine.ownerSub)])];
495
- // The owner's own reviews graduate a rule (./engine/graduation); automation never reviews.
496
- const labels = request.engine.labels ?? labelsFrom(existing.filter((item) => item.scope?.ownerSub === request.engine!.ownerSub));
497
- policy = applyPolicy(fresh, { scope: { ...request.engine, ownerNames, labels }, documents });
503
+ policy = applyPolicy(fresh, { scope: { ...request.engine, ownerNames, labels: engineLabels }, documents, matches: reconciled.matches });
498
504
  const kept = new Map(policy.kept.map((item) => [item.externalId, item]));
499
505
  written = resolutions.commitments.flatMap((item) =>
500
506
  freshIds.has(item.externalId) ? (kept.has(item.externalId) ? [kept.get(item.externalId)!] : []) : [item]);
@@ -228,6 +228,8 @@ export {
228
228
  } from './voice-sections';
229
229
  export type { SaveCommitmentsOptions } from './types';
230
230
  export type { DocumentFiling } from './filing';
231
+ export { createSharingApi } from './sharing';
232
+ export type { RecordShare, RecordShares, ShareChoices, ShareKind, ShareLevel } from './sharing';
231
233
 
232
234
  export {
233
235
  VOICE_SOURCE,
@@ -0,0 +1,135 @@
1
+ /**
2
+ * SHARING A RECORD WITH PEOPLE, A TEAM, OR THE WHOLE ORGANISATION (Todo ENG-158).
3
+ *
4
+ * A record is private to whoever it belongs to until they share it. One row in the
5
+ * tenant's `grants` table is one share; its `subject_type` says who it names:
6
+ *
7
+ * user -> one colleague (subject_id = their sub)
8
+ * group -> a team (subject_id = the team slug)
9
+ * org -> everyone in the caller's own organisation (subject_id = the org)
10
+ *
11
+ * Nothing here is named after a company or a product: the people, teams and
12
+ * organisation come from the tenant (`/org/roster/`, `/org/teams/`, `/whoami/`).
13
+ * "Everyone in the subtree" is deliberately not offered.
14
+ */
15
+ import type { CorpusHttp } from './client';
16
+
17
+ export type ShareKind = 'user' | 'group' | 'org';
18
+ export type ShareLevel = 'viewer' | 'editor';
19
+
20
+ export interface RecordShare {
21
+ /** The grant row, for removing it. */
22
+ id: string;
23
+ kind: ShareKind;
24
+ subjectId: string;
25
+ level: ShareLevel;
26
+ }
27
+
28
+ export interface ShareChoices {
29
+ /** The caller's own organisation: the id a whole-organisation share names. */
30
+ org?: { id: string; label: string };
31
+ people: Array<{ id: string; label: string }>;
32
+ teams: Array<{ id: string; label: string }>;
33
+ }
34
+
35
+ export interface RecordShares {
36
+ shares: RecordShare[];
37
+ /** False when this caller may read the record but not change who else can. */
38
+ canShare: boolean;
39
+ reason?: string;
40
+ }
41
+
42
+ export interface SharingPaths {
43
+ grants?: string;
44
+ roster?: string;
45
+ teams?: string;
46
+ whoami?: string;
47
+ }
48
+
49
+ const DEFAULTS: Required<SharingPaths> = {
50
+ grants: '/api/v1/grants/',
51
+ roster: '/api/v1/org/roster/',
52
+ teams: '/api/v1/org/teams/',
53
+ whoami: '/api/v1/whoami/',
54
+ };
55
+
56
+ type Obj = Record<string, unknown>;
57
+ const str = (v: unknown) => (typeof v === 'string' ? v : '');
58
+ /** A key as the tenant spells it, or as a camelizing client hands it back. */
59
+ const pick = (row: Obj, snake: string) =>
60
+ row[snake] ?? row[snake.replace(/_([a-z])/g, (_, c: string) => c.toUpperCase())];
61
+ const rows = (body: unknown): Obj[] => {
62
+ const list = Array.isArray(body) ? body : (body as { results?: unknown })?.results;
63
+ return Array.isArray(list) ? (list.filter((r) => r && typeof r === 'object') as Obj[]) : [];
64
+ };
65
+
66
+ const KINDS: ShareKind[] = ['user', 'group', 'org'];
67
+
68
+ export async function listRecordShares(
69
+ http: CorpusHttp, documentId: string, paths: SharingPaths = {},
70
+ ): Promise<RecordShares> {
71
+ const p = { ...DEFAULTS, ...paths };
72
+ const body = await http.get<unknown>(p.grants, { params: { entity: documentId, page_size: 100 } });
73
+ const envelope = (body ?? {}) as Obj;
74
+ const shares: RecordShare[] = [];
75
+ for (const row of rows(body)) {
76
+ const kind = str(pick(row, 'subject_type')) as ShareKind;
77
+ if (!KINDS.includes(kind)) continue; // a public link is publishing, not sharing
78
+ shares.push({
79
+ id: str(row.id), kind, subjectId: str(pick(row, 'subject_id')),
80
+ level: str(row.level) === 'editor' ? 'editor' : 'viewer',
81
+ });
82
+ }
83
+ return { shares, canShare: pick(envelope, 'may_share') === true, reason: str(pick(envelope, 'may_share_reason')) || undefined };
84
+ }
85
+
86
+ export async function addRecordShare(
87
+ http: CorpusHttp, documentId: string, target: { kind: ShareKind; subjectId: string; level?: ShareLevel },
88
+ paths: SharingPaths = {},
89
+ ): Promise<void> {
90
+ const p = { ...DEFAULTS, ...paths };
91
+ if (!http.post) throw new Error('This client cannot share records.');
92
+ await http.post(p.grants, {
93
+ entity: documentId, subject_type: target.kind, subject_id: target.subjectId,
94
+ level: target.level ?? 'viewer',
95
+ });
96
+ }
97
+
98
+ export async function removeRecordShare(
99
+ http: CorpusHttp, shareId: string, paths: SharingPaths = {},
100
+ ): Promise<void> {
101
+ const p = { ...DEFAULTS, ...paths };
102
+ if (!http.delete) throw new Error('This client cannot change sharing.');
103
+ await http.delete(`${p.grants}${encodeURIComponent(shareId)}/`);
104
+ }
105
+
106
+ /** Who a record can be shared with. A list that fails to load is empty, not fatal. */
107
+ export async function listShareChoices(
108
+ http: CorpusHttp, paths: SharingPaths = {},
109
+ ): Promise<ShareChoices> {
110
+ const p = { ...DEFAULTS, ...paths };
111
+ const [who, roster, teams] = await Promise.all([
112
+ http.get<unknown>(p.whoami).catch(() => null),
113
+ http.get<unknown>(p.roster, { params: { page_size: 100 } }).catch(() => null),
114
+ http.get<unknown>(p.teams).catch(() => null),
115
+ ]);
116
+ const w = (who ?? {}) as Obj;
117
+ const orgId = str(pick(w, 'org_id')) || str((w.org as Obj | undefined)?.id) || str(w.org);
118
+ return {
119
+ org: orgId ? { id: orgId, label: str(pick(w, 'org_name')) || 'Everyone in my organisation' } : undefined,
120
+ people: rows(roster).map((r) => ({ id: str(r.sub), label: str(r.label) || str(r.sub) })).filter((r) => r.id),
121
+ teams: rows(teams).map((r) => ({ id: str(r.slug), label: str(r.name) || str(r.slug) })).filter((r) => r.id),
122
+ };
123
+ }
124
+
125
+ export function createSharingApi(http: CorpusHttp, paths: SharingPaths = {}) {
126
+ return {
127
+ listRecordShares: (documentId: string) => listRecordShares(http, documentId, paths),
128
+ listShareChoices: () => listShareChoices(http, paths),
129
+ ...(http.post
130
+ ? { addRecordShare: (documentId: string, target: { kind: ShareKind; subjectId: string; level?: ShareLevel }) =>
131
+ addRecordShare(http, documentId, target, paths) }
132
+ : {}),
133
+ ...(http.delete ? { removeRecordShare: (shareId: string) => removeRecordShare(http, shareId, paths) } : {}),
134
+ };
135
+ }
@@ -426,6 +426,8 @@ export interface ListSourcesOptions {
426
426
  * What the composers are handed. An app implements it over its own HTTP client;
427
427
  * `createCorpusApi` in `./client` does that for the tenant `/api/v1/*` endpoints.
428
428
  */
429
+ import type { RecordShares, ShareChoices, ShareKind, ShareLevel } from './sharing';
430
+
429
431
  export interface CorpusApi {
430
432
  /**
431
433
  * One page of documents. `options.participants: false` returns the rows WITHOUT
@@ -476,6 +478,15 @@ export interface CorpusApi {
476
478
  fileDocument?(documentId: string, focusId: string | null): Promise<void>;
477
479
  /** The projects a document can be filed under. */
478
480
  listFocusChoices?(): Promise<Array<{ id: string; title: string }>>;
481
+ /**
482
+ * SHARING (Todo ENG-158) — who may read a record beyond its owner. All optional:
483
+ * a client that cannot read shows nothing; one that cannot write shows the line
484
+ * without the menu.
485
+ */
486
+ listRecordShares?(documentId: string): Promise<RecordShares>;
487
+ listShareChoices?(): Promise<ShareChoices>;
488
+ addRecordShare?(documentId: string, target: { kind: ShareKind; subjectId: string; level?: ShareLevel }): Promise<void>;
489
+ removeRecordShare?(shareId: string): Promise<void>;
479
490
  /**
480
491
  * Optional because a tenant with no payment connector has no money events, and
481
492
  * a corpus surface that requires one would fail the Dropbox-only test.
@@ -839,6 +850,10 @@ export interface Commitment {
839
850
  possiblyDone?: PossiblyDone[];
840
851
  /** The engine decision that put this item here, and the owner's review of it (bd startsim-vrmx5). */
841
852
  suggestion?: import('./engine/suggestion').Suggestion;
853
+ /** A later source states a different date; the owner decides (bd startsim-81mzy). `dueAt` is untouched. */
854
+ proposedDue?: import('./engine/proposed-due').ProposedDue[];
855
+ /** A person set the due date, so a source never proposes over it (the tenant's `field_edited_at.due_at`). */
856
+ dueSetByPerson?: boolean;
842
857
  firstSeenAt: string | null;
843
858
  lastSeenAt: string | null;
844
859
  /** Which extractor produced it, so a later one can re-derive without orphaning. */
@@ -944,6 +959,11 @@ export interface CommitmentQuery {
944
959
  status?: CommitmentStatus | CommitmentStatus[];
945
960
  subtype?: CommitmentSubtype | CommitmentSubtype[];
946
961
  owner?: string;
962
+ /**
963
+ * Only the items this member owns (central user id). A SERVER filter on `attr.owner_sub` (declared on
964
+ * every tenant; `owner_subs` is not, and the tenant refuses it). Unlike `owner` it matches the person, not a spelling of the name.
965
+ */
966
+ ownerSub?: string;
947
967
  /** ISO instants over `dueAt`. */
948
968
  dueBefore?: string;
949
969
  /** ISO instant over `lastSeenAt` — "what changed since last week". */
@@ -1000,7 +1020,7 @@ export interface CommitmentApi {
1000
1020
  */
1001
1021
  updateCommitment?(item: Commitment, patch: Partial<Pick<Commitment,
1002
1022
  'status' | 'statusReason' | 'ownerName' | 'ownerSub' | 'ownerSubs' | 'dueAt' | 'subtype'
1003
- | 'title' | 'detail' | 'resolvedAt' | 'possiblyDone' | 'suggestion'>> & {
1023
+ | 'title' | 'detail' | 'resolvedAt' | 'possiblyDone' | 'suggestion' | 'proposedDue'>> & {
1004
1024
  /** `private` hides the item from everyone but its owner; `null` makes it shared again. */
1005
1025
  visibility?: 'private' | null;
1006
1026
  /** `null` clears it (undoing a voice-set priority). */