@startsimpli/integrations 0.2.172 → 0.2.173

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.172",
3
+ "version": "0.2.173",
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,8 +50,8 @@
50
50
  "react-native": ">=0.74.0",
51
51
  "@startsimpli/ui-native": ">=0.1.12",
52
52
  "react-native-safe-area-context": ">=4.0.0",
53
+ "@startsimpli/ui": "^0.4.184",
53
54
  "@startsimpli/auth": "^0.4.53",
54
- "@startsimpli/ui": "^0.4.183",
55
55
  "@startsimpli/utils": "^0.4.19"
56
56
  },
57
57
  "peerDependenciesMeta": {
@@ -99,8 +99,8 @@
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
101
  "@startsimpli/llm": "0.4.31",
102
- "@startsimpli/ui": "0.4.183",
103
- "@startsimpli/ui-native": "0.1.14",
102
+ "@startsimpli/ui": "0.4.184",
103
+ "@startsimpli/ui-native": "0.1.15",
104
104
  "@startsimpli/auth": "0.4.53",
105
105
  "@startsimpli/utils": "0.4.19"
106
106
  },
@@ -0,0 +1,48 @@
1
+ // @vitest-environment jsdom
2
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
3
+ import * as React from 'react';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import { ConnectorPage } from '../components/pages/ConnectorPage';
6
+ import type { OAuthConnectionsApi } from '../api/oauth-connections';
7
+
8
+ afterEach(cleanup);
9
+ const row = { id: 'fam1', workspace: { slug: 'tandem', name: 'Tandem' }, client: { claimed_name: 'Claude', host: 'claude.ai', operator_registered: false }, connected_since: '2026-11-13T10:00:00Z', last_active: '2026-11-13T11:00:00Z', access_expires: null };
10
+ const api = (over: Partial<OAuthConnectionsApi> = {}): OAuthConnectionsApi => ({
11
+ list: vi.fn(async () => ({ connections: [row], revocation_takes_effect_within_seconds: 900 })),
12
+ revoke: vi.fn(async () => ({ revoked: true, renewal_stopped: true, revoked_effective_at: 't', notice: 'Disconnected; access ends within 15 minutes.' })),
13
+ ...over,
14
+ });
15
+
16
+ describe('ConnectorPage', () => {
17
+ it('shows the workspace address from its own document, with steps, and no token to paste', async () => {
18
+ render(<ConnectorPage connections={api()} fetchWellKnown={async () => ({ resource: 'https://tandem.example.com/api/v1/mcp/' })} />);
19
+ expect(await screen.findByText('https://tandem.example.com/api/v1/mcp/')).toBeTruthy();
20
+ expect(screen.getByText(/Add custom connector/)).toBeTruthy();
21
+ expect(screen.queryByText(/Create connection token/)).toBeNull();
22
+ });
23
+ it('lists connections and disconnects one, saying what is true', async () => {
24
+ const a = api();
25
+ render(<ConnectorPage connections={a} mcpUrl="https://x/api/v1/mcp/" />);
26
+ await screen.findByTestId('connection-fam1');
27
+ fireEvent.click(screen.getByText('Disconnect'));
28
+ await waitFor(() => expect(a.revoke).toHaveBeenCalledWith('fam1'));
29
+ expect(await screen.findByText(/access ends within 15 minutes/)).toBeTruthy();
30
+ expect(a.list).toHaveBeenCalledTimes(2);
31
+ });
32
+ it('says nothing is connected, and a failing list does not hide the address', async () => {
33
+ const a = api({ list: vi.fn(async () => { throw new Error('boom'); }) });
34
+ render(<ConnectorPage connections={a} mcpUrl="https://x/api/v1/mcp/" />);
35
+ expect(await screen.findByRole('alert')).toBeTruthy();
36
+ expect(screen.getByText('https://x/api/v1/mcp/')).toBeTruthy();
37
+ });
38
+ it('loads the token flow only when Advanced is opened', async () => {
39
+ const tokens = { list: vi.fn(async () => ({ foundries: [], max_ttl_days: 30, default_ttl_days: 7 })), mint: vi.fn(), listTokens: vi.fn(), revokeToken: vi.fn() };
40
+ render(<ConnectorPage connections={api()} tokens={tokens as never} mcpUrl="https://x/api/v1/mcp/" />);
41
+ await screen.findByText('Advanced: use a token instead');
42
+ expect(tokens.list).not.toHaveBeenCalled();
43
+ const details = document.querySelector('details') as HTMLDetailsElement;
44
+ details.open = true;
45
+ fireEvent(details, new Event('toggle'));
46
+ await waitFor(() => expect(tokens.list).toHaveBeenCalled());
47
+ });
48
+ });
package/src/api/index.ts CHANGED
@@ -6,4 +6,5 @@ export * from './connections';
6
6
  // The MCP bearer mint (bd startsim-hj5zh / startsim-62dca). Central, not the
7
7
  // tenant — it rides the tenant's own /api/v1/auth/ proxy, see the module.
8
8
  export * from './mcp-tokens';
9
+ export * from './oauth-connections';
9
10
  export { setApiBase, getApiBase, setAuthTokenProvider } from './_fetch';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `/api/v1/auth/oauth-connections/` — the OAuth connections (Claude, the relay, any MCP client that signed in through the
3
+ * consent screen) the signed-in person holds, and cutting one (bd startsim-ym54h, central: oauth_connections_view.py).
4
+ * Revoking stops RENEWAL at once; the access token already in the client's hands lives until its own short expiry, and the
5
+ * response says when, so a screen never has to claim more than is true.
6
+ */
7
+ import { createRequester, request, type ClientDeps, type Requester } from './_fetch';
8
+
9
+ export interface OAuthConnection {
10
+ id: string;
11
+ workspace: { slug: string; name: string };
12
+ client: { claimed_name: string; host: string; operator_registered: boolean };
13
+ connected_since: string;
14
+ last_active: string;
15
+ access_expires: string | null;
16
+ }
17
+ export interface OAuthConnectionList { connections: OAuthConnection[]; revocation_takes_effect_within_seconds: number }
18
+ export interface OAuthRevokeResult { revoked: boolean; renewal_stopped: boolean; revoked_effective_at: string; notice: string }
19
+
20
+ export interface OAuthConnectionsApi {
21
+ list(): Promise<OAuthConnectionList>;
22
+ revoke(id: string): Promise<OAuthRevokeResult>;
23
+ }
24
+
25
+ const BASE = '/auth/oauth-connections';
26
+
27
+ function build(req: Requester): OAuthConnectionsApi {
28
+ return {
29
+ list: () => req<OAuthConnectionList>(`${BASE}/`),
30
+ revoke: (id) => req<OAuthRevokeResult>(`${BASE}/${encodeURIComponent(id)}/`, { method: 'DELETE' }),
31
+ };
32
+ }
33
+
34
+ /** The web client: global base, token provider and fetch. */
35
+ export const oauthConnections: OAuthConnectionsApi = build(request);
36
+ /** The same client over an injected fetch (a phone's `authorizedFetch`). */
37
+ export const createOauthConnectionsApi = (deps: ClientDeps): OAuthConnectionsApi => build(createRequester(deps));
@@ -72,6 +72,8 @@ export * from './pages/VoiceNotesPage';
72
72
  export { VoiceRecordButton, VOICE_MIME_CANDIDATES } from './pages/VoiceRecordButton';
73
73
  export { ConversePage } from './pages/ConversePage';
74
74
  export type { ConversePageProps, ConverseClassNames } from './pages/ConversePage';
75
+ export { ConnectorPage } from './pages/ConnectorPage';
76
+ export type { ConnectorPageProps, ConnectorClassNames } from './pages/ConnectorPage';
75
77
  export { DecisionsPage } from './pages/DecisionsPage';
76
78
  export type { DecisionsPageProps, DecisionsClassNames } from './pages/DecisionsPage';
77
79
  export type { VoiceRecordButtonProps, VoiceRecordClassNames } from './pages/VoiceRecordButton';
@@ -0,0 +1,105 @@
1
+ /**
2
+ * CONNECT CLAUDE, the normal way (bd startsim-ym54h): the workspace is an MCP server with OAuth, so connecting is adding
3
+ * its ADDRESS in Claude and approving a sign-in screen. Nothing is copied or pasted back; access renews by itself and is
4
+ * withdrawn here. The old token form is still available, folded away under Advanced, and is only loaded when opened so a
5
+ * session that cannot mint tokens never sees an error on the main path.
6
+ *
7
+ * The address comes from the workspace's own RFC 9728 document (same origin), not from a pattern this file guessed.
8
+ */
9
+ import * as React from 'react';
10
+
11
+ import type { OAuthConnection, OAuthConnectionsApi } from '../../api/oauth-connections';
12
+ import type { McpTokensApi } from '../../api/mcp-tokens';
13
+ import { ConnectClaudePage } from './ConnectClaudePage';
14
+
15
+ type Slot = 'root' | 'section' | 'heading' | 'card' | 'button' | 'muted' | 'error' | 'code';
16
+ export type ConnectorClassNames = Partial<Record<Slot, string>>;
17
+ const FALLBACK: Record<Slot, string> = {
18
+ root: 'space-y-6', section: 'space-y-3', heading: 'text-lg font-semibold', card: 'rounded-lg border p-4',
19
+ button: 'rounded-md border px-3 py-2 text-sm font-medium', muted: 'text-sm opacity-70', error: 'rounded-md border p-3 text-sm',
20
+ code: 'block w-full overflow-x-auto rounded p-3 font-mono text-xs',
21
+ };
22
+
23
+ export interface ConnectorPageProps {
24
+ connections: OAuthConnectionsApi;
25
+ /** The token flow, kept under Advanced. */
26
+ tokens?: McpTokensApi;
27
+ classNames?: ConnectorClassNames;
28
+ /** Skip the lookup when the app already knows the address. */
29
+ mcpUrl?: string | null;
30
+ fetchWellKnown?: () => Promise<{ resource?: string }>;
31
+ }
32
+
33
+ const readable = (iso: string) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? iso : d.toLocaleString(); };
34
+
35
+ export function ConnectorPage({ connections, tokens, classNames, mcpUrl, fetchWellKnown }: ConnectorPageProps) {
36
+ const cx = (k: Slot) => classNames?.[k] ?? FALLBACK[k];
37
+ const [url, setUrl] = React.useState<string | null>(mcpUrl ?? null);
38
+ const [rows, setRows] = React.useState<OAuthConnection[] | null>(null);
39
+ const [error, setError] = React.useState('');
40
+ const [notice, setNotice] = React.useState('');
41
+ const [copied, setCopied] = React.useState(false);
42
+ const [advanced, setAdvanced] = React.useState(false);
43
+
44
+ React.useEffect(() => {
45
+ if (url) return;
46
+ const look = fetchWellKnown ?? (() => fetch('/.well-known/oauth-protected-resource').then((r) => (r.ok ? (r.json() as Promise<{ resource?: string }>) : ({} as { resource?: string }))));
47
+ // The spec's resource is `<origin>/api/v1/mcp/`: used only when the workspace's own document cannot be read.
48
+ const fallback = typeof window !== 'undefined' ? `${window.location.origin}/api/v1/mcp/` : null;
49
+ look().then((d) => setUrl(d.resource ?? fallback), () => setUrl(fallback));
50
+ }, [url, fetchWellKnown]);
51
+
52
+ const load = React.useCallback(() => {
53
+ connections.list().then((r) => setRows(r.connections), (e: unknown) => { setRows([]); setError(e instanceof Error ? e.message : String(e)); });
54
+ }, [connections]);
55
+ React.useEffect(load, [load]);
56
+
57
+ async function copy() {
58
+ if (!url) return;
59
+ try { await navigator.clipboard.writeText(url); setCopied(true); window.setTimeout(() => setCopied(false), 2000); } catch { setCopied(false); }
60
+ }
61
+ async function disconnect(id: string) {
62
+ setError('');
63
+ try { const r = await connections.revoke(id); setNotice(r.notice); load(); } catch (e) { setError(e instanceof Error ? e.message : String(e)); }
64
+ }
65
+
66
+ return (
67
+ <div className={cx('root')}>
68
+ <section className={cx('section')} data-testid="connector-address">
69
+ <h2 className={cx('heading')}>Add it to Claude</h2>
70
+ <p className={cx('muted')}>
71
+ In Claude, open Settings, then Connectors, then Add custom connector, and enter this address. Claude opens a sign-in
72
+ screen here; approve it. There is nothing to copy back, and it stays connected until you disconnect it below.
73
+ </p>
74
+ {url ? (
75
+ <>
76
+ <code className={cx('code')}>{url}</code>
77
+ <button type="button" className={cx('button')} onClick={copy}>{copied ? 'Copied' : 'Copy address'}</button>
78
+ </>
79
+ ) : <p className={cx('muted')}>Looking up this workspace&rsquo;s address…</p>}
80
+ </section>
81
+
82
+ <section className={cx('section')}>
83
+ <h2 className={cx('heading')}>Your connections</h2>
84
+ {rows === null ? <p className={cx('muted')}>Loading…</p> : null}
85
+ {rows && !rows.length ? <p className={cx('muted')} data-testid="no-connections">Nothing is connected yet.</p> : null}
86
+ {(rows ?? []).map((c) => (
87
+ <div key={c.id} className={cx('card')} data-testid={`connection-${c.id}`}>
88
+ <p><strong>{c.client.claimed_name || c.client.host}</strong>{c.client.operator_registered ? '' : ` (${c.client.host}, not verified)`}</p>
89
+ <p className={cx('muted')}>{c.workspace.name} · connected {readable(c.connected_since)} · last used {readable(c.last_active)}</p>
90
+ <button type="button" className={cx('button')} onClick={() => void disconnect(c.id)}>Disconnect</button>
91
+ </div>
92
+ ))}
93
+ {notice ? <p className={cx('muted')} role="status">{notice}</p> : null}
94
+ {error ? <div className={cx('error')} role="alert">{error}</div> : null}
95
+ </section>
96
+
97
+ {tokens ? (
98
+ <details onToggle={(e) => setAdvanced((e.currentTarget as HTMLDetailsElement).open)}>
99
+ <summary className={cx('muted')}>Advanced: use a token instead</summary>
100
+ {advanced ? <ConnectClaudePage api={tokens} classNames={classNames} /> : null}
101
+ </details>
102
+ ) : null}
103
+ </div>
104
+ );
105
+ }