@startsimpli/integrations 0.2.133 → 0.2.135

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 (31) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/corpus-planning.test.tsx +13 -3
  3. package/src/__tests__/corpus-tracker.test.tsx +53 -69
  4. package/src/__tests__/focus-standings.test.tsx +3 -1
  5. package/src/__tests__/home-brief.test.tsx +84 -0
  6. package/src/__tests__/project-surfaces.test.tsx +1 -1
  7. package/src/__tests__/work-groups.test.ts +181 -0
  8. package/src/components/index.ts +1 -0
  9. package/src/components/pages/ConnectionsPage.tsx +7 -1402
  10. package/src/components/pages/PlanningPage.tsx +129 -67
  11. package/src/components/pages/TrackerPage.tsx +174 -149
  12. package/src/components/pages/connections/CapabilityPicker.tsx +75 -0
  13. package/src/components/pages/connections/CatalogCard.tsx +300 -0
  14. package/src/components/pages/connections/ConnectionCard.tsx +489 -0
  15. package/src/components/pages/connections/ConnectionForms.tsx +215 -0
  16. package/src/components/pages/connections/MemberPolicyToggle.tsx +106 -0
  17. package/src/components/pages/connections/bound-api.ts +175 -0
  18. package/src/components/pages/connections/copy.ts +74 -0
  19. package/src/components/pages/home/BriefCard.tsx +84 -0
  20. package/src/components/pages/home/CompactItemRow.tsx +61 -0
  21. package/src/components/pages/home/DueAcrossProjects.tsx +74 -0
  22. package/src/components/pages/home/HomeBriefPage.tsx +112 -0
  23. package/src/components/pages/home/RecentNotes.tsx +69 -0
  24. package/src/components/pages/home/index.ts +10 -0
  25. package/src/components/pages/home/useProjectNames.ts +23 -0
  26. package/src/components/pages/work-items.tsx +15 -9
  27. package/src/corpus/due-groups.ts +81 -0
  28. package/src/corpus/focus-overview.ts +54 -0
  29. package/src/corpus/index.ts +10 -0
  30. package/src/corpus/note-actions.ts +44 -0
  31. package/src/corpus/tracker-groups.ts +84 -0
@@ -0,0 +1,300 @@
1
+ /**
2
+ * One connectable connector: its form, and the foundry-level member policy. Split out of ConnectionsPage (bd startsim-ovq7f) with no behaviour change.
3
+ */
4
+ import * as React from 'react';
5
+
6
+ import { CredentialSchemaForm, isSecret, missingRequired, patternWarnings, schemaFields } from '../../CredentialSchemaForm';
7
+ import type { Connection, ConnectorCatalogEntry } from '../types';
8
+ import { CapabilityPicker, orderCapabilities } from './CapabilityPicker';
9
+ import { MemberPolicyToggle } from './MemberPolicyToggle';
10
+ import type { BoundApi } from './bound-api';
11
+ import { DEFAULTS } from './copy';
12
+
13
+ // --------------------------------------------------------------------------
14
+ // catalog
15
+ // --------------------------------------------------------------------------
16
+
17
+ export function CatalogCard({
18
+ api, personal, entry, existing, canManage, classNames: cn, onConnected,
19
+ onPolicyChanged,
20
+ }: {
21
+ api: BoundApi;
22
+ personal: boolean;
23
+ entry: ConnectorCatalogEntry;
24
+ /** Cards already held on this connector — the foundry's, or the member's own. */
25
+ existing: Connection[];
26
+ canManage: boolean;
27
+ classNames: typeof DEFAULTS;
28
+ onConnected: () => void;
29
+ /** Re-read the catalog after the member toggle is written. Foundry mode only. */
30
+ onPolicyChanged?: () => void;
31
+ }) {
32
+ const [open, setOpen] = React.useState(false);
33
+ const [values, setValues] = React.useState<Record<string, unknown>>({});
34
+ const [busy, setBusy] = React.useState(false);
35
+ const [error, setError] = React.useState('');
36
+ // Every declared capability starts ON. Not because "on" is a safe default in
37
+ // general, but because the alternative here is a connection that can do
38
+ // nothing — and the list is right there, unchecked with one click, before
39
+ // anything is saved. The privacy control that is genuinely opt-in lives one
40
+ // level down (a connector's own config, e.g. whether a poll fetches meeting
41
+ // transcript bytes at all) and is unaffected by this box.
42
+ const [capabilities, setCapabilities] = React.useState<string[]>(entry.capabilities);
43
+
44
+ // THE ONE THING THIS CARD BRANCHES ON (bd startsim-768w.22.25.14/.23).
45
+ // `schema.auth_mode_for` derives it server-side and its docstring says so;
46
+ // this component had no reference to it at all, so an OAuth connector got the
47
+ // same credential form as everything else — which on the admin catalog meant
48
+ // the product asking a human to paste a refresh token, the exact thing
49
+ // `auth_mode` exists to prevent.
50
+ const isOAuth = entry.auth_mode === 'oauth';
51
+ // A stale client is not a dead button. The verb is optional on both api
52
+ // shapes, so an app pinned to an older `@startsimpli/api` says the connector
53
+ // cannot be connected from here instead of rendering a hand-off that throws.
54
+ const canHandOff = isOAuth && typeof api.startOAuth === 'function';
55
+
56
+ // NO credential fields in OAuth mode. Not hidden — never collected: the whole
57
+ // point is that the token comes back from the vendor, and a form that
58
+ // "helpfully" accepted one would keep the paste-a-refresh-token path alive
59
+ // beside the consent flow that replaced it.
60
+ const credentialFields = isOAuth ? [] : schemaFields(entry.credential_schema);
61
+ // Config IS still asked for, in both modes. It is the folder a Dropbox card
62
+ // will poll, it is not a secret, and dropping it here would mean asking for it
63
+ // again after the round trip.
64
+ const configFields = schemaFields(entry.config_schema);
65
+ const fields = [...credentialFields, ...configFields];
66
+ const warnings = patternWarnings(fields, values);
67
+ const missing = missingRequired(fields, values);
68
+
69
+ /** Collect the config fields the form did gather. Shared by both submits. */
70
+ function collectConfig(): Record<string, unknown> {
71
+ const config: Record<string, unknown> = {};
72
+ for (const spec of configFields) {
73
+ const v = values[isSecret(spec) ? `${spec.key}__draft` : spec.key];
74
+ if (typeof v === 'boolean' || typeof v === 'number' || v) config[spec.key] = v;
75
+ }
76
+ return config;
77
+ }
78
+
79
+ /**
80
+ * Hand the browser to the vendor (bd startsim-768w.22.25.21/.22).
81
+ *
82
+ * ONE call: the server writes the shell card AND returns the consent URL,
83
+ * because neither half is usable alone. The URL is opened VERBATIM — it is
84
+ * already complete, and this client has no `client_id` to add to it and must
85
+ * not have one to choose.
86
+ *
87
+ * `return_to` is where the member should land afterwards. It is sent, not
88
+ * trusted: the server validates it against this tenant's own recorded origins
89
+ * before folding it into the signed state, because the callback is an
90
+ * anonymous browser mid-redirect from the vendor's domain.
91
+ *
92
+ * `location.assign`, not a new tab. A vendor consent screen that opens in a
93
+ * popup is the one an ad blocker eats, and the whole point of the round trip
94
+ * is that the browser comes BACK here.
95
+ */
96
+ async function handOff() {
97
+ setBusy(true);
98
+ setError('');
99
+ try {
100
+ const { authorization_url: url } = await api.startOAuth!({
101
+ connector_key: entry.key,
102
+ name: entry.name,
103
+ config: collectConfig(),
104
+ capabilities_enabled: orderCapabilities(entry.capabilities, capabilities),
105
+ return_to: typeof window !== 'undefined' ? window.location.href : undefined,
106
+ });
107
+ if (typeof window !== 'undefined') window.location.assign(url);
108
+ } catch (err) {
109
+ setError((err as { message?: string })?.message || 'Could not start sign-in.');
110
+ setBusy(false);
111
+ }
112
+ }
113
+
114
+ async function submit() {
115
+ setBusy(true);
116
+ setError('');
117
+ try {
118
+ const credentials: Record<string, unknown> = {};
119
+ const config: Record<string, unknown> = {};
120
+ for (const spec of credentialFields) {
121
+ const v = values[isSecret(spec) ? `${spec.key}__draft` : spec.key];
122
+ if (v) credentials[spec.key] = v;
123
+ }
124
+ for (const spec of configFields) {
125
+ const v = values[isSecret(spec) ? `${spec.key}__draft` : spec.key];
126
+ // `if (v)` DROPPED A FALSE, which for a checkbox makes "off" and
127
+ // "untouched" the same request. Harmless while every config field was a
128
+ // string; not harmless once one of them decides whether verbatim
129
+ // recordings are stored.
130
+ if (typeof v === 'boolean' || typeof v === 'number' || v) config[spec.key] = v;
131
+ }
132
+ await api.connect({
133
+ connector_key: entry.key, name: entry.name, credentials, config,
134
+ // Always sent. Leaving it off is what wrote the inert cards.
135
+ capabilities_enabled: orderCapabilities(entry.capabilities, capabilities),
136
+ });
137
+ setOpen(false);
138
+ setValues({});
139
+ setCapabilities(entry.capabilities);
140
+ onConnected();
141
+ } catch (err) {
142
+ // The server's typed answer, verbatim. It already scrubbed itself of the
143
+ // values just submitted, and it knows things the client cannot guess —
144
+ // "the vendor rejected this key" is not "the network failed".
145
+ setError((err as { message?: string })?.message || 'Could not connect.');
146
+ } finally {
147
+ setBusy(false);
148
+ }
149
+ }
150
+
151
+ return (
152
+ <div className={cn.card}>
153
+ <div className="flex items-start justify-between gap-4">
154
+ <div>
155
+ <p className="font-medium text-gray-900">{entry.name}</p>
156
+ <p className={cn.muted}>{entry.description}</p>
157
+ {entry.capabilities.length ? (
158
+ <p className="mt-1 text-xs text-gray-400">{entry.capabilities.join(' · ')}</p>
159
+ ) : null}
160
+ {/* A row whose class will not load says WHY and stays visible. The
161
+ catalog is data and outruns deployed bundles; blanking the menu
162
+ because one vendor's module moved is the failure this prevents. */}
163
+ {!entry.availability.available ? (
164
+ <p className={cn.error}>Unavailable: {entry.availability.reason}</p>
165
+ ) : null}
166
+ </div>
167
+ {canManage && entry.availability.available ? (
168
+ <button type="button" className={cn.button} onClick={() => setOpen((v) => !v)}>
169
+ {open ? 'Cancel' : 'Connect'}
170
+ </button>
171
+ ) : null}
172
+ </div>
173
+
174
+ {/* On the card it governs, not on a settings list of its own — an admin
175
+ should not have to hold two lists of connectors in their head to know
176
+ which ones members can use. */}
177
+ {!personal && api.setMemberConnectorPolicy && entry.member_policy ? (
178
+ <MemberPolicyToggle
179
+ connectorKey={entry.key}
180
+ policy={entry.member_policy}
181
+ canManage={canManage}
182
+ write={api.setMemberConnectorPolicy}
183
+ classNames={cn}
184
+ onChanged={onPolicyChanged}
185
+ />
186
+ ) : null}
187
+
188
+ {open ? (
189
+ <div className="mt-4 space-y-3">
190
+ {/* SAID BEFORE THE KEY IS PASTED, not after the server refuses.
191
+ Connecting again makes a SECOND account, which is legitimate and
192
+ stays available — but it is almost never what an admin holding a
193
+ rotated key wants, and it was the only thing this page offered
194
+ them. The server now answers the indistinguishable case with a 409
195
+ naming the card; this catches it a round trip earlier. */}
196
+ {existing.length > 0 ? (
197
+ <p className={cn.muted} data-already-connected={entry.key}>
198
+ Already connected as{' '}
199
+ <strong className="text-gray-900">
200
+ {existing.map((c) => c.name).join(', ')}
201
+ </strong>
202
+ . To install a new key, use <em>Replace key</em> on that
203
+ connection — it is tested before it replaces the working one.
204
+ Connecting here adds a SECOND account.
205
+ </p>
206
+ ) : null}
207
+ {/* SIGN IN AT THE VENDOR — never a form asking for token material.
208
+ `auth_mode: oauth` means the credential schema is `access_token` /
209
+ `refresh_token` / `expires_at`, and rendering those as inputs asks
210
+ a human to go and mint a refresh token by hand. That is what this
211
+ card did to every admin who opened Dropbox. */}
212
+ {isOAuth ? (
213
+ <div className="space-y-2" data-oauth-connect={entry.key}>
214
+ <p className={cn.muted}>
215
+ {entry.name} signs you in on its own site. You will be sent there
216
+ to approve access and returned here — no keys to copy, and
217
+ StartSimpli never sees your password.
218
+ </p>
219
+ {!canHandOff ? (
220
+ <p className={cn.error}>
221
+ This app cannot start a {entry.name} sign-in yet. Update it, or
222
+ connect {entry.name} from the foundry control plane.
223
+ </p>
224
+ ) : null}
225
+ </div>
226
+ ) : (
227
+ <CredentialSchemaForm
228
+ fields={fields}
229
+ values={values}
230
+ warnings={warnings}
231
+ idPrefix={`connect-${entry.key}`}
232
+ onChange={(key, value) => {
233
+ const spec = fields.find((f) => f.key === key);
234
+ setValues((prev) => ({
235
+ ...prev, [spec && isSecret(spec) ? `${key}__draft` : key]: value,
236
+ }));
237
+ }}
238
+ />
239
+ )}
240
+ {/* Config is asked for in BOTH modes — it is not a secret, and it is
241
+ the folder this card will poll. Rendered separately in OAuth mode
242
+ because the credential half of the same form is gone. */}
243
+ {isOAuth && configFields.length > 0 ? (
244
+ <CredentialSchemaForm
245
+ fields={configFields}
246
+ values={values}
247
+ warnings={warnings}
248
+ idPrefix={`connect-${entry.key}`}
249
+ onChange={(key, value) => {
250
+ const spec = configFields.find((f) => f.key === key);
251
+ setValues((prev) => ({
252
+ ...prev, [spec && isSecret(spec) ? `${key}__draft` : key]: value,
253
+ }));
254
+ }}
255
+ />
256
+ ) : null}
257
+ <CapabilityPicker
258
+ scope="catalog"
259
+ declared={entry.capabilities}
260
+ selected={capabilities}
261
+ disabled={busy}
262
+ idPrefix={`connect-${entry.key}`}
263
+ onToggle={(capability, on) => setCapabilities((prev) => (
264
+ on ? [...prev, capability] : prev.filter((c) => c !== capability)
265
+ ))}
266
+ classNames={cn}
267
+ />
268
+ {/* The server refuses an empty list with a 400 rather than storing a
269
+ card that can do nothing. Saying so here costs the admin a round
270
+ trip instead of a confusing error. */}
271
+ {entry.capabilities.length > 0 && capabilities.length === 0 ? (
272
+ <p className={cn.error}>
273
+ Enable at least one — a connection with nothing enabled can do nothing.
274
+ </p>
275
+ ) : null}
276
+ {error ? <p className={cn.error} role="alert">{error}</p> : null}
277
+ <button
278
+ type="button"
279
+ className={cn.button}
280
+ disabled={
281
+ busy
282
+ // `missing` counts only the fields this mode actually collects.
283
+ // In OAuth mode that is config alone — gating the hand-off on a
284
+ // required `access_token` would disable the very button whose job
285
+ // is to go and get one.
286
+ || missing.length > 0
287
+ || (isOAuth && !canHandOff)
288
+ || (entry.capabilities.length > 0 && capabilities.length === 0)
289
+ }
290
+ onClick={() => void (isOAuth ? handOff() : submit())}
291
+ >
292
+ {isOAuth
293
+ ? (busy ? 'Redirecting…' : `Continue to ${entry.name}`)
294
+ : (busy ? 'Testing…' : 'Test and save')}
295
+ </button>
296
+ </div>
297
+ ) : null}
298
+ </div>
299
+ );
300
+ }