@startsimpli/integrations 0.2.77 → 0.2.78
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 +6 -1
- package/package.json +3 -3
- package/src/__tests__/api-fetch-factories.test.ts +81 -0
- package/src/api/_fetch.ts +93 -61
- package/src/api/connections.ts +162 -152
- package/src/api/mcp-tokens.ts +25 -15
- package/src/components/pages/ConnectClaudePage.tsx +1 -14
- package/src/components/pages/MemberConnectionRoster.tsx +2 -5
- package/src/components/pages/PlanningPage.tsx +3 -15
- package/src/components/pages/connect-claude-format.ts +24 -0
- package/src/components/pages/connection-format.ts +20 -0
- package/src/components/pages/work-items.tsx +4 -51
- package/src/corpus/planning.ts +21 -0
- package/src/corpus/work-item-logic.ts +59 -0
- package/src/native/corpus/api.ts +2 -3
- package/src/native/index.ts +16 -0
- package/src/native/screens/connect-claude/ConnectClaudeScreen.tsx +102 -0
- package/src/native/screens/connect-claude/__tests__/controller.test.ts +116 -0
- package/src/native/screens/connect-claude/controller.ts +108 -0
- package/src/native/screens/connect-claude/fake.ts +57 -0
- package/src/native/screens/connect-claude/tab.tsx +19 -0
- package/src/native/screens/connections/ConnectionsScreens.tsx +108 -0
- package/src/native/screens/connections/__tests__/controller.test.ts +66 -0
- package/src/native/screens/connections/controller.ts +93 -0
- package/src/native/screens/connections/fake.ts +69 -0
- package/src/native/screens/connections/tab.tsx +15 -0
- package/src/native/screens/planning/PlanningScreens.tsx +178 -0
- package/src/native/screens/planning/__tests__/controller.test.ts +145 -0
- package/src/native/screens/planning/__tests__/format.test.ts +29 -0
- package/src/native/screens/planning/controller.ts +173 -0
- package/src/native/screens/planning/fake.ts +16 -0
- package/src/native/screens/planning/format.ts +49 -0
- package/src/native/screens/planning/tab.tsx +26 -0
- package/src/native/screens/shared/PressableCard.tsx +14 -0
- package/src/native/screens/shared/format.ts +10 -0
package/README.md
CHANGED
|
@@ -216,7 +216,12 @@ Rules every list tab follows: one server request per page (never load a list and
|
|
|
216
216
|
|
|
217
217
|
**Library and Ask tabs** (`src/native/screens/`, bd startsim-23np6.1.5): `libraryAskTabs(api)` returns both tabs for the `tabs` array. `libraryTab(api)` is documents list -> document (server-side search, source / type / project filters, newest / oldest, infinite scroll, Markdown body, change project through `corpus/filing.ts`); `askTab(api)` is project-scoped Ask with Markdown answers and citations (a citation calls `openTab('library', id)`). Both are controllers (`createLibraryController`, `createAskController`: pure, vitest) under screens that use `@startsimpli/ui-native` only. The words (failure messages, answer caveats, provenance) live in `corpus/view-text.ts` and are shared with the web `LibraryPage` / `AskPage`. `createFakeLibraryApi()` is the shared fake plus a few extra documents for simulator checks. Generate mode (web AskPage) is not on the phone.
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
**Planning, Connections, Connect Claude** (`src/native/screens/`, bd startsim-23np6.1.6). Each is a tab factory: `createPlanningTab({ api: createNativeCorpusApi(...), documentTab? })`, `createConnectionsTab({ api: createConnectionsMeApi({ baseUrl, fetch }) })`, `createConnectClaudeTab({ api: createMcpTokensApi({ baseUrl, fetch }), share? })`. `baseUrl` is the API root (`https://<tenant>/api/v1`) and `fetch` is the app's `authorizedFetch`; the tenant proxies `/api/v1/auth/*` (the MCP token mint) to central. Fakes for the simulator: `createFakePlanningApi()`, `createFakeConnectionsApi()`, `createFakeMcpTokensApi()`.
|
|
220
|
+
|
|
221
|
+
- Planning: projects worst-off first (server `orderBy=progress`, 25 a page), each card's done/overdue counts from `focusStanding` (the same three count reads as the web card, four at a time); a project opens onto its open or closed items (`in_focus` edge walk) and its notes (`about_focus`), each a server page.
|
|
222
|
+
- Connections: my connected accounts and their status, Test now, Disconnect (confirmed). Connecting a new account stays on the web.
|
|
223
|
+
- Connect Claude: mints only from the Create button, shows the token once, hands it to the system share sheet (Copy is on it), and forgets it on Done. The server has no list of issued tokens and no revoke (bd startsim-ja8mt), so the screen says so instead of offering either.
|
|
224
|
+
- `createMcpTokensApi` / `createConnectionsMeApi` take `{ baseUrl, fetch }` and never touch the web's module-global base, token provider or cookies; `mcpTokens` / `connectionsMe` are the same clients built over those globals.
|
|
220
225
|
|
|
221
226
|
## Verification
|
|
222
227
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.78",
|
|
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",
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
"react-native": "0.85.3",
|
|
92
92
|
"react-native-safe-area-context": "~5.7.0",
|
|
93
93
|
"@startsimpli/llm": "0.4.28",
|
|
94
|
-
"@startsimpli/ui
|
|
95
|
-
"@startsimpli/ui": "0.
|
|
94
|
+
"@startsimpli/ui": "0.4.167",
|
|
95
|
+
"@startsimpli/ui-native": "0.1.2"
|
|
96
96
|
},
|
|
97
97
|
"scripts": {
|
|
98
98
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createMcpTokensApi` / `createConnectionsMeApi` (bd startsim-23np6.1.8): the
|
|
3
|
+
* same two clients as the web exports, over an injected fetch. A phone's
|
|
4
|
+
* `authorizedFetch` carries the bearer itself, so these must use THAT fetch and
|
|
5
|
+
* never the module-global one, and must not read the web's global base/token.
|
|
6
|
+
*/
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { createConnectionsMeApi } from '../api/connections';
|
|
10
|
+
import { createMcpTokensApi } from '../api/mcp-tokens';
|
|
11
|
+
import { setApiBase, setAuthTokenProvider } from '../api/_fetch';
|
|
12
|
+
|
|
13
|
+
interface Call { url: string; init: RequestInit }
|
|
14
|
+
let calls: Call[];
|
|
15
|
+
let globalFetch: ReturnType<typeof vi.fn>;
|
|
16
|
+
|
|
17
|
+
const json = (payload: unknown, status = 200) =>
|
|
18
|
+
new Response(JSON.stringify(payload), { status, headers: { 'Content-Type': 'application/json' } });
|
|
19
|
+
|
|
20
|
+
function fakeFetch(answer: () => Response = () => json({})) {
|
|
21
|
+
return vi.fn(async (url: string, init: RequestInit = {}) => {
|
|
22
|
+
calls.push({ url: String(url), init });
|
|
23
|
+
return answer();
|
|
24
|
+
}) as unknown as typeof fetch;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
calls = [];
|
|
29
|
+
setApiBase('/web-base');
|
|
30
|
+
setAuthTokenProvider(() => 'WEB-TOKEN');
|
|
31
|
+
globalFetch = vi.fn(async () => json({}));
|
|
32
|
+
vi.stubGlobal('fetch', globalFetch);
|
|
33
|
+
});
|
|
34
|
+
afterEach(() => { vi.unstubAllGlobals(); setAuthTokenProvider(null); setApiBase('/api/v1'); });
|
|
35
|
+
|
|
36
|
+
describe('createMcpTokensApi', () => {
|
|
37
|
+
it('lists foundries through the injected fetch at baseUrl, not the global base', async () => {
|
|
38
|
+
const api = createMcpTokensApi({ baseUrl: 'https://t.example/api/v1/', fetch: fakeFetch(() => json({ foundries: [], default_ttl_days: 30, max_ttl_days: 90 })) });
|
|
39
|
+
const out = await api.list();
|
|
40
|
+
expect(out.max_ttl_days).toBe(90);
|
|
41
|
+
expect(calls[0].url).toBe('https://t.example/api/v1/auth/mcp-token/');
|
|
42
|
+
expect(globalFetch).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('does not add the web token (the injected fetch owns auth)', async () => {
|
|
46
|
+
await createMcpTokensApi({ baseUrl: 'https://t.example/api/v1', fetch: fakeFetch() }).list();
|
|
47
|
+
expect(JSON.stringify(calls[0].init.headers)).not.toContain('WEB-TOKEN');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('mints with POST and a JSON body', async () => {
|
|
51
|
+
const api = createMcpTokensApi({ baseUrl: 'https://t.example/api/v1', fetch: fakeFetch(() => json({ token: 'T' })) });
|
|
52
|
+
await api.mint({ foundry: 'tandem', ttl_days: 7 });
|
|
53
|
+
expect(calls[0].init.method).toBe('POST');
|
|
54
|
+
expect(JSON.parse(String(calls[0].init.body))).toEqual({ foundry: 'tandem', ttl_days: 7 });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('surfaces a refusal as an error carrying the status', async () => {
|
|
58
|
+
const api = createMcpTokensApi({ baseUrl: 'https://t.example/api/v1', fetch: fakeFetch(() => json({ detail: 'no seat' }, 403)) });
|
|
59
|
+
await expect(api.mint({ foundry: 'x' })).rejects.toMatchObject({ status: 403 });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('createConnectionsMeApi', () => {
|
|
64
|
+
it('reads my connections through the injected fetch under /connections/me/', async () => {
|
|
65
|
+
const api = createConnectionsMeApi({ baseUrl: 'https://t.example/api/v1', fetch: fakeFetch(() => json({ results: [], permissions: {} })) });
|
|
66
|
+
await api.connections();
|
|
67
|
+
await api.checkConnection('c1');
|
|
68
|
+
expect(calls.map((c) => c.url)).toEqual([
|
|
69
|
+
'https://t.example/api/v1/connections/me/',
|
|
70
|
+
'https://t.example/api/v1/connections/me/c1/check/',
|
|
71
|
+
]);
|
|
72
|
+
expect(calls[1].init.method).toBe('POST');
|
|
73
|
+
expect(globalFetch).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('disconnects with DELETE', async () => {
|
|
77
|
+
const api = createConnectionsMeApi({ baseUrl: 'https://t.example/api/v1', fetch: fakeFetch(() => new Response(null, { status: 204 })) });
|
|
78
|
+
await api.disconnect('c1');
|
|
79
|
+
expect(calls[0].init.method).toBe('DELETE');
|
|
80
|
+
});
|
|
81
|
+
});
|
package/src/api/_fetch.ts
CHANGED
|
@@ -42,80 +42,112 @@ export function setAuthTokenProvider(
|
|
|
42
42
|
_tokenProvider = provider;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
interface RequestOptions {
|
|
45
|
+
export interface RequestOptions {
|
|
46
46
|
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
47
47
|
body?: unknown;
|
|
48
48
|
query?: Record<string, string | number | boolean | undefined | null>;
|
|
49
49
|
headers?: Record<string, string>;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
export type Requester = <T>(path: string, opts?: RequestOptions) => Promise<T>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* What a client needs to talk to the API without the module-global state: where
|
|
56
|
+
* (`baseUrl`, ending at the API root, e.g. `https://tenant/api/v1`) and how
|
|
57
|
+
* (`fetch`). A phone passes its `authorizedFetch`, which adds the bearer itself,
|
|
58
|
+
* so no token provider and no cookies are involved on that path.
|
|
59
|
+
*/
|
|
60
|
+
export interface ClientDeps {
|
|
61
|
+
baseUrl: string | (() => string);
|
|
62
|
+
fetch: typeof fetch;
|
|
63
|
+
/** Optional bearer source, for callers whose fetch does not add one. */
|
|
64
|
+
getToken?: () => string | null | Promise<string | null>;
|
|
65
|
+
/** Web sends cookies (`include`); an injected fetch usually sends none. */
|
|
66
|
+
credentials?: RequestCredentials;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function createRequester(deps: ClientDeps): Requester {
|
|
70
|
+
return async function request<T>(path: string, opts: RequestOptions = {}): Promise<T> {
|
|
71
|
+
const { method = 'GET', body, query, headers = {} } = opts;
|
|
72
|
+
const base = (typeof deps.baseUrl === 'function' ? deps.baseUrl() : deps.baseUrl).replace(/\/$/, '');
|
|
73
|
+
let url = `${base}${path.startsWith('/') ? path : '/' + path}`;
|
|
74
|
+
if (query) {
|
|
75
|
+
const params = new URLSearchParams();
|
|
76
|
+
for (const [k, v] of Object.entries(query)) {
|
|
77
|
+
if (v === undefined || v === null) continue;
|
|
78
|
+
params.set(k, String(v));
|
|
79
|
+
}
|
|
80
|
+
const qs = params.toString();
|
|
81
|
+
if (qs) url += `?${qs}`;
|
|
60
82
|
}
|
|
61
|
-
const qs = params.toString();
|
|
62
|
-
if (qs) url += `?${qs}`;
|
|
63
|
-
}
|
|
64
83
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
const authHeaders: Record<string, string> = {};
|
|
85
|
+
if (deps.getToken) {
|
|
86
|
+
try {
|
|
87
|
+
const token = await deps.getToken();
|
|
88
|
+
if (token) authHeaders.Authorization = `Bearer ${token}`;
|
|
89
|
+
} catch {
|
|
90
|
+
// Token provider failure: surface as Unauthenticated below if Django rejects.
|
|
91
|
+
}
|
|
72
92
|
}
|
|
73
|
-
}
|
|
74
93
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
const init: RequestInit = {
|
|
95
|
+
method,
|
|
96
|
+
headers: {
|
|
97
|
+
Accept: 'application/json',
|
|
98
|
+
...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
|
|
99
|
+
...authHeaders,
|
|
100
|
+
...headers,
|
|
101
|
+
},
|
|
102
|
+
...(deps.credentials ? { credentials: deps.credentials } : {}),
|
|
103
|
+
};
|
|
104
|
+
if (body !== undefined) init.body = JSON.stringify(body);
|
|
86
105
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
const resp = await deps.fetch(url, init);
|
|
107
|
+
const contentType = resp.headers.get('Content-Type') || '';
|
|
108
|
+
let payload: unknown = null;
|
|
109
|
+
if (contentType.includes('application/json')) {
|
|
110
|
+
try {
|
|
111
|
+
payload = await resp.json();
|
|
112
|
+
} catch {
|
|
113
|
+
payload = null;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
try {
|
|
117
|
+
payload = await resp.text();
|
|
118
|
+
} catch {
|
|
119
|
+
payload = null;
|
|
120
|
+
}
|
|
95
121
|
}
|
|
96
|
-
} else {
|
|
97
|
-
try {
|
|
98
|
-
payload = await resp.text();
|
|
99
|
-
} catch {
|
|
100
|
-
payload = null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
122
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
if (!resp.ok) {
|
|
124
|
+
const errorPayload: ApiErrorPayload =
|
|
125
|
+
payload && typeof payload === 'object' ? (payload as ApiErrorPayload) : {};
|
|
126
|
+
if (resp.status === 401) {
|
|
127
|
+
throw new UnauthenticatedError(errorPayload);
|
|
128
|
+
}
|
|
129
|
+
if (resp.status === 403 && errorPayload.reconsent_url) {
|
|
130
|
+
throw new ReconsentRequiredError(errorPayload);
|
|
131
|
+
}
|
|
132
|
+
throw new ApiError(
|
|
133
|
+
errorPayload.error || errorPayload.detail || `HTTP ${resp.status}`,
|
|
134
|
+
resp.status,
|
|
135
|
+
errorPayload,
|
|
136
|
+
);
|
|
112
137
|
}
|
|
113
|
-
throw new ApiError(
|
|
114
|
-
errorPayload.error || errorPayload.detail || `HTTP ${resp.status}`,
|
|
115
|
-
resp.status,
|
|
116
|
-
errorPayload,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
138
|
|
|
120
|
-
|
|
139
|
+
return payload as T;
|
|
140
|
+
};
|
|
121
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The web's module-global client: base from `setApiBase`, bearer from
|
|
145
|
+
* `setAuthTokenProvider`, cookies included, and the GLOBAL `fetch` read at call
|
|
146
|
+
* time (so a test that stubs it still works).
|
|
147
|
+
*/
|
|
148
|
+
export const request: Requester = createRequester({
|
|
149
|
+
baseUrl: () => _apiBase,
|
|
150
|
+
fetch: (url, init) => fetch(url, init),
|
|
151
|
+
getToken: () => (_tokenProvider ? _tokenProvider() : null),
|
|
152
|
+
credentials: 'include',
|
|
153
|
+
});
|
package/src/api/connections.ts
CHANGED
|
@@ -45,169 +45,179 @@ import type {
|
|
|
45
45
|
MemberConnectionsApi,
|
|
46
46
|
OAuthStart,
|
|
47
47
|
} from '../components/pages/types';
|
|
48
|
-
import { request } from './_fetch';
|
|
48
|
+
import { createRequester, request, type ClientDeps, type Requester } from './_fetch';
|
|
49
49
|
|
|
50
50
|
/** Mounted at `/api/v1/connections/` (`config/urls.py`), so this rides the base. */
|
|
51
51
|
const BASE = '/connections/me';
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
function build(request: Requester): MemberConnectionsApi {
|
|
54
|
+
return {
|
|
55
|
+
/**
|
|
56
|
+
* The connectors THIS foundry has opened to its members — not the global
|
|
57
|
+
* catalog. The narrowing is `policy_service.member_connectable`, server-side,
|
|
58
|
+
* default-deny per connector per foundry. Rendered as handed: filtering in the
|
|
59
|
+
* browser would mean shipping the withheld vendors to be filtered out of.
|
|
60
|
+
*/
|
|
61
|
+
connectorCatalog(): Promise<{ results: ConnectorCatalogEntry[] }> {
|
|
62
|
+
return request<{ results: ConnectorCatalogEntry[] }>(`${BASE}/catalog/`);
|
|
63
|
+
},
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
/**
|
|
66
|
+
* MY cards. Already owner-scoped by `Connection.objects.for_owner(foundry,
|
|
67
|
+
* user)` — there is no query parameter that widens this and no id to swap.
|
|
68
|
+
*
|
|
69
|
+
* `permissions` comes back with `issue_tokens: false` because the router has
|
|
70
|
+
* no such route, not because of anything about the caller.
|
|
71
|
+
*/
|
|
72
|
+
connections(): Promise<{ results: Connection[]; permissions: ConnectionPermissions }> {
|
|
73
|
+
return request<{ results: Connection[]; permissions: ConnectionPermissions }>(`${BASE}/`);
|
|
74
|
+
},
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Connect my own account. BLOCKING: the server runs `check()` against the
|
|
78
|
+
* vendor before storing anything, so a key that has not been proven to work is
|
|
79
|
+
* never saved as connected.
|
|
80
|
+
*
|
|
81
|
+
* `capabilities_enabled` is chosen HERE and only here — there is no PATCH on
|
|
82
|
+
* this surface, so this request is the one place a member says what their
|
|
83
|
+
* account may do.
|
|
84
|
+
*
|
|
85
|
+
* A 403 back from this is not "you lack a permission": it is the foundry not
|
|
86
|
+
* having allowed members to connect their own account on this connector. The
|
|
87
|
+
* server re-checks that here rather than trusting that the catalog it rendered
|
|
88
|
+
* earlier is what the browser actually sent.
|
|
89
|
+
*/
|
|
90
|
+
connect(input: {
|
|
91
|
+
connector_key: string;
|
|
92
|
+
name?: string;
|
|
93
|
+
credentials?: Record<string, unknown>;
|
|
94
|
+
config?: Record<string, unknown>;
|
|
95
|
+
capabilities_enabled?: string[];
|
|
96
|
+
}): Promise<Connection> {
|
|
97
|
+
return request<Connection>(`${BASE}/`, { method: 'POST', body: input });
|
|
98
|
+
},
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
100
|
+
/**
|
|
101
|
+
* START a consent round trip on an OAuth connector (bd startsim-768w.22.25.21).
|
|
102
|
+
*
|
|
103
|
+
* ONE call, not create-then-initiate. The two halves have no independent
|
|
104
|
+
* meaning — a shell card with no consent URL is an orphan the member cannot
|
|
105
|
+
* act on, and a consent URL with no card has nowhere to put the token — so a
|
|
106
|
+
* refusal here leaves nothing behind.
|
|
107
|
+
*
|
|
108
|
+
* Takes `connector_key` rather than an id because the row does not exist yet;
|
|
109
|
+
* that is the whole bug this closes. The caller opens `authorization_url` and
|
|
110
|
+
* does nothing else: it is already complete, and the client has no `client_id`
|
|
111
|
+
* of its own to add to it.
|
|
112
|
+
*
|
|
113
|
+
* `return_to` is where the browser should land afterwards. It is VALIDATED
|
|
114
|
+
* server-side against this tenant's own recorded origins and folded into the
|
|
115
|
+
* signed state — the callback is an anonymous browser mid-redirect from the
|
|
116
|
+
* vendor and cannot be allowed to name its own destination.
|
|
117
|
+
*/
|
|
118
|
+
startOAuth(input: {
|
|
119
|
+
connector_key: string;
|
|
120
|
+
name?: string;
|
|
121
|
+
config?: Record<string, unknown>;
|
|
122
|
+
capabilities_enabled?: string[];
|
|
123
|
+
return_to?: string;
|
|
124
|
+
}): Promise<OAuthStart> {
|
|
125
|
+
return request<OAuthStart>(`${BASE}/oauth/start/`, { method: 'POST', body: input });
|
|
126
|
+
},
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
/**
|
|
129
|
+
* RE-consent an existing card whose grant the vendor stopped accepting. The
|
|
130
|
+
* first connect is `startOAuth`; this one takes an id because the card is
|
|
131
|
+
* already there and must not be duplicated.
|
|
132
|
+
*/
|
|
133
|
+
oauthInitiate(id: string, input?: { return_to?: string }): Promise<OAuthStart> {
|
|
134
|
+
return request<OAuthStart>(`${BASE}/${id}/oauth/initiate/`, {
|
|
135
|
+
method: 'POST', body: input ?? {},
|
|
136
|
+
});
|
|
137
|
+
},
|
|
137
138
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
/** Vendor-side setup steps, as DATA written by the connector in Python. */
|
|
140
|
+
connectionInstructions(id: string): Promise<ConnectionInstructions> {
|
|
141
|
+
return request<ConnectionInstructions>(`${BASE}/${id}/instructions/`);
|
|
142
|
+
},
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Test it now, against the STORED credential. The body is deliberately empty:
|
|
146
|
+
* a "test connection" button that accepts a pasted key is a second connect
|
|
147
|
+
* path, and the router does not read this body at all.
|
|
148
|
+
*/
|
|
149
|
+
checkConnection(id: string): Promise<{ ok: boolean; account_label: string; detail: string }> {
|
|
150
|
+
return request<{ ok: boolean; account_label: string; detail: string }>(
|
|
151
|
+
`${BASE}/${id}/check/`, { method: 'POST', body: {} },
|
|
152
|
+
);
|
|
153
|
+
},
|
|
153
154
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Rotate MY key. The old one stays live until the new one passes `check()`,
|
|
157
|
+
* so a bad paste changes nothing. A PARTIAL map is legal and normal: send the
|
|
158
|
+
* one field being replaced and the stored values fill in the rest.
|
|
159
|
+
*/
|
|
160
|
+
rotateCredential(id: string, credentials: Record<string, unknown>): Promise<Connection> {
|
|
161
|
+
return request<Connection>(`${BASE}/${id}/credential/`, {
|
|
162
|
+
method: 'POST', body: { credentials },
|
|
163
|
+
});
|
|
164
|
+
},
|
|
164
165
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
166
|
+
/**
|
|
167
|
+
* CHANGE THE SETTINGS OF MY OWN CARD (bd startsim-sfms2).
|
|
168
|
+
*
|
|
169
|
+
* The folder a Dropbox connection reads, and whether it recurses. On a
|
|
170
|
+
* personal connection that is not a pipeline setting — it is which of the
|
|
171
|
+
* member's own files this platform is allowed to see — so it is theirs to set,
|
|
172
|
+
* and the alternative was disconnect + re-consent, which throws a working
|
|
173
|
+
* token away to change a string.
|
|
174
|
+
*
|
|
175
|
+
* A SUB-ROUTE, not a PATCH on the detail view. `credential/` is the precedent
|
|
176
|
+
* one door down: rotation is not on PATCH either, because a new key has to
|
|
177
|
+
* pass `check()` before it replaces a working one. A scope change has the same
|
|
178
|
+
* shape — it must pass the connector's own refusal, and it restarts the walk.
|
|
179
|
+
*
|
|
180
|
+
* PARTIAL and MERGING, exactly like `rotateCredential`: send the fields that
|
|
181
|
+
* changed and the stored values fill in the rest. `null` unsets one. The server
|
|
182
|
+
* refuses any key the connector does not declare, and refuses any TOP-LEVEL key
|
|
183
|
+
* that is not `config` — a body naming `capabilities_enabled` is a 400 and not
|
|
184
|
+
* a silent no-op.
|
|
185
|
+
*
|
|
186
|
+
* The response may carry `notices`: sentences the server wrote about what the
|
|
187
|
+
* change costs. Rendered verbatim, never composed in the browser.
|
|
188
|
+
*/
|
|
189
|
+
updateConnectionConfig(
|
|
190
|
+
id: string, config: Record<string, unknown>,
|
|
191
|
+
): Promise<Connection> {
|
|
192
|
+
return request<Connection>(`${BASE}/${id}/config/`, {
|
|
193
|
+
method: 'PATCH', body: { config },
|
|
194
|
+
});
|
|
195
|
+
},
|
|
195
196
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
197
|
+
/**
|
|
198
|
+
* DISCONNECT, not delete. One transaction stops the scheduled fetches, revokes
|
|
199
|
+
* every token issued for the account and deletes the stored credential; the
|
|
200
|
+
* card survives as `disabled`, so the record that this vendor was connected is
|
|
201
|
+
* not thrown away.
|
|
202
|
+
*
|
|
203
|
+
* A card that is not mine answers 404 rather than 403 — on this surface
|
|
204
|
+
* existence is itself the payload.
|
|
205
|
+
*/
|
|
206
|
+
disconnect(id: string): Promise<void> {
|
|
207
|
+
return request<void>(`${BASE}/${id}/`, { method: 'DELETE' });
|
|
208
|
+
},
|
|
208
209
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
};
|
|
210
|
+
/** Recent activity on my card: a merge over the run tables it owns. */
|
|
211
|
+
connectionRuns(id: string): Promise<{ results: ConnectionRun[] }> {
|
|
212
|
+
return request<{ results: ConnectionRun[] }>(`${BASE}/${id}/runs/`);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** The web client: global base, token provider and fetch. */
|
|
218
|
+
export const connectionsMe: MemberConnectionsApi = build(request);
|
|
219
|
+
|
|
220
|
+
/** The same client over an injected fetch (a phone's `authorizedFetch`). */
|
|
221
|
+
export function createConnectionsMeApi(deps: ClientDeps): MemberConnectionsApi {
|
|
222
|
+
return build(createRequester(deps));
|
|
223
|
+
}
|