@terreno/syncdb 58.0.5 → 58.1.0

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 (50) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/auth/TerrenoOAuthConsentScreen.d.ts +65 -0
  3. package/dist/auth/TerrenoOAuthConsentScreen.d.ts.map +1 -0
  4. package/dist/auth/TerrenoOAuthConsentScreen.js +119 -0
  5. package/dist/auth/TerrenoOAuthConsentScreen.js.map +1 -0
  6. package/dist/auth/auth.d.ts +2 -0
  7. package/dist/auth/auth.d.ts.map +1 -1
  8. package/dist/auth/auth.js +2 -0
  9. package/dist/auth/auth.js.map +1 -1
  10. package/dist/auth/useLoginController.d.ts +23 -1
  11. package/dist/auth/useLoginController.d.ts.map +1 -1
  12. package/dist/auth/useLoginController.js +14 -4
  13. package/dist/auth/useLoginController.js.map +1 -1
  14. package/dist/auth/useMcpOAuthConsent.d.ts +65 -0
  15. package/dist/auth/useMcpOAuthConsent.d.ts.map +1 -0
  16. package/dist/auth/useMcpOAuthConsent.js +133 -0
  17. package/dist/auth/useMcpOAuthConsent.js.map +1 -0
  18. package/dist/codegen/discoverOperations.test.d.ts +2 -0
  19. package/dist/codegen/discoverOperations.test.d.ts.map +1 -0
  20. package/dist/codegen/discoverOperations.test.js +66 -0
  21. package/dist/codegen/discoverOperations.test.js.map +1 -0
  22. package/dist/devMcpRegistry.d.ts.map +1 -1
  23. package/dist/devMcpRegistry.isolated.js +6 -0
  24. package/dist/devMcpRegistry.isolated.js.map +1 -1
  25. package/dist/devMcpRegistry.js +3 -1
  26. package/dist/devMcpRegistry.js.map +1 -1
  27. package/dist/isolated/TerrenoLoginScreen.isolated.js +59 -0
  28. package/dist/isolated/TerrenoLoginScreen.isolated.js.map +1 -1
  29. package/dist/isolated/TerrenoOAuthConsentScreen.isolated.d.ts +2 -0
  30. package/dist/isolated/TerrenoOAuthConsentScreen.isolated.d.ts.map +1 -0
  31. package/dist/isolated/TerrenoOAuthConsentScreen.isolated.js +532 -0
  32. package/dist/isolated/TerrenoOAuthConsentScreen.isolated.js.map +1 -0
  33. package/dist/isolated/useLoginController.isolated.js +94 -0
  34. package/dist/isolated/useLoginController.isolated.js.map +1 -1
  35. package/dist/isolated/useMcpOAuthConsent.isolated.d.ts +2 -0
  36. package/dist/isolated/useMcpOAuthConsent.isolated.d.ts.map +1 -0
  37. package/dist/isolated/useMcpOAuthConsent.isolated.js +273 -0
  38. package/dist/isolated/useMcpOAuthConsent.isolated.js.map +1 -0
  39. package/package.json +4 -4
  40. package/src/auth/TerrenoOAuthConsentScreen.tsx +365 -0
  41. package/src/auth/auth.ts +2 -0
  42. package/src/auth/useLoginController.ts +47 -3
  43. package/src/auth/useMcpOAuthConsent.ts +242 -0
  44. package/src/codegen/discoverOperations.test.ts +69 -0
  45. package/src/devMcpRegistry.isolated.ts +6 -0
  46. package/src/devMcpRegistry.ts +3 -1
  47. package/src/isolated/TerrenoLoginScreen.isolated.tsx +93 -0
  48. package/src/isolated/TerrenoOAuthConsentScreen.isolated.tsx +637 -0
  49. package/src/isolated/useLoginController.isolated.ts +109 -0
  50. package/src/isolated/useMcpOAuthConsent.isolated.ts +330 -0
@@ -1368,6 +1368,115 @@ describe("useLoginController", () => {
1368
1368
  expect(offline.result.current.screenProps.oauthProviders).toEqual([]);
1369
1369
  expect(offline.result.current.screenProps.genericProviders).toEqual([]);
1370
1370
  });
1371
+
1372
+ describe("methods allowlist", () => {
1373
+ const providerIds = (result: {
1374
+ current: ReturnType<typeof useLoginController>;
1375
+ }): {branded: string[]; generic: string[]} => ({
1376
+ branded: (result.current.screenProps.oauthProviders ?? []).map(({provider}) => provider),
1377
+ generic: (result.current.screenProps.genericProviders ?? []).map(({id}) => id),
1378
+ });
1379
+
1380
+ it("shows only the allowed branded provider when the server offers google, github, apple", async () => {
1381
+ const client = fakeClient({
1382
+ methods: {...METHODS, providers: ["google", "github", "apple"]},
1383
+ });
1384
+ const {result} = renderController({client, methods: {providers: ["google"]}});
1385
+ await waitForLoginScreen(result);
1386
+ expect(providerIds(result)).toEqual({branded: ["google"], generic: []});
1387
+ });
1388
+
1389
+ it("ignores an allowed provider the server does not offer", async () => {
1390
+ const client = fakeClient({methods: {...METHODS, providers: ["google", "mock-oidc"]}});
1391
+ const {result} = renderController({client, methods: {providers: ["mock-oidc", "apple"]}});
1392
+ await waitForLoginScreen(result);
1393
+ expect(providerIds(result)).toEqual({branded: [], generic: ["mock-oidc"]});
1394
+ });
1395
+
1396
+ it("keeps the server's order, not the allowlist's", async () => {
1397
+ const client = fakeClient({
1398
+ methods: {...METHODS, providers: ["a-oidc", "b-oidc", "c-oidc"]},
1399
+ });
1400
+ const {result} = renderController({client, methods: {providers: ["c-oidc", "a-oidc"]}});
1401
+ await waitForLoginScreen(result);
1402
+ expect(providerIds(result).generic).toEqual(["a-oidc", "c-oidc"]);
1403
+ });
1404
+
1405
+ it("shows no social buttons for an empty provider list but keeps the email form", async () => {
1406
+ const {result} = renderController({client: fakeClient(), methods: {providers: []}});
1407
+ await waitForLoginScreen(result);
1408
+ expect(providerIds(result)).toEqual({branded: [], generic: []});
1409
+ expect(result.current.isEmailPasswordEnabled).toBe(true);
1410
+ });
1411
+
1412
+ it("shows every server provider when providers is undefined", async () => {
1413
+ const {result} = renderController({client: fakeClient(), methods: {emailPassword: true}});
1414
+ await waitForLoginScreen(result);
1415
+ expect(providerIds(result)).toEqual({branded: ["google", "github"], generic: ["mock-oidc"]});
1416
+ });
1417
+
1418
+ it("hides the email form with emailPassword false and forgot-password with it", async () => {
1419
+ const onForgotPasswordPress = mock(() => {});
1420
+ const {result} = renderController({
1421
+ client: fakeClient(),
1422
+ methods: {emailPassword: false},
1423
+ onForgotPasswordPress,
1424
+ });
1425
+ await waitForLoginScreen(result);
1426
+ expect(result.current.isEmailPasswordEnabled).toBe(false);
1427
+ expect(result.current.screenProps.onForgotPasswordPress).toBeUndefined();
1428
+ });
1429
+
1430
+ it("never shows email and password the server disables, and keeps it when both agree", async () => {
1431
+ const off = renderController({
1432
+ client: fakeClient({methods: {...METHODS, emailPassword: false}}),
1433
+ methods: {emailPassword: true},
1434
+ });
1435
+ await waitForLoginScreen(off.result);
1436
+ expect(off.result.current.isEmailPasswordEnabled).toBe(false);
1437
+
1438
+ const on = renderController({client: fakeClient(), methods: {emailPassword: true}});
1439
+ await waitForLoginScreen(on.result);
1440
+ expect(on.result.current.isEmailPasswordEnabled).toBe(true);
1441
+ });
1442
+
1443
+ it("hides the passkey button and skips passkey autofill with passkey false", async () => {
1444
+ globalWithWindow.window = {
1445
+ PublicKeyCredential: {isConditionalMediationAvailable: async (): Promise<boolean> => true},
1446
+ };
1447
+ // Autofill waits for the browser, so the screen stays on the login step.
1448
+ const client = fakeClient({}, {passkey: () => new Promise(() => {})});
1449
+ const {result, onSignedIn} = renderController({client, methods: {passkey: false}});
1450
+ await waitForLoginScreen(result);
1451
+ expect(result.current.screenProps.onPasskeyPress).toBeUndefined();
1452
+ expect(result.current.screenProps.passkeyAutofill).toBe(false);
1453
+ expect(client.calls.passkey).toEqual([]);
1454
+ expect(onSignedIn).not.toHaveBeenCalled();
1455
+ });
1456
+
1457
+ it("never shows a passkey the server disables, and keeps it when both agree", async () => {
1458
+ const off = renderController({
1459
+ client: fakeClient({methods: {...METHODS, passkey: false}}),
1460
+ methods: {passkey: true},
1461
+ });
1462
+ await waitForLoginScreen(off.result);
1463
+ expect(off.result.current.screenProps.onPasskeyPress).toBeUndefined();
1464
+
1465
+ const on = renderController({client: fakeClient(), methods: {passkey: true}});
1466
+ await waitForLoginScreen(on.result);
1467
+ expect(on.result.current.screenProps.onPasskeyPress).toBeDefined();
1468
+ });
1469
+
1470
+ it("does not sign in with a hidden provider from a remembered account", async () => {
1471
+ const client = fakeClient();
1472
+ const {result} = renderController({client, methods: {providers: ["google"]}});
1473
+ await waitForLoginScreen(result);
1474
+ await act(async () => {
1475
+ await result.current.continueAs({id: "u1", method: "github"}, "remembered");
1476
+ });
1477
+ expect(client.calls.social).toEqual([]);
1478
+ });
1479
+ });
1371
1480
  });
1372
1481
 
1373
1482
  describe("recordRememberedSignIn", () => {
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Isolated tests for useMcpOAuthConsent. The network is stubbed at the fetch boundary of a real
3
+ * request client mounted through ApiClientProvider; the hook itself is not mocked.
4
+ */
5
+ import {describe, expect, it} from "bun:test";
6
+ import {act, renderHook, waitFor} from "@testing-library/react-native";
7
+ import React from "react";
8
+
9
+ import {createApiClient, type FetchLike} from "../api/client";
10
+ import {type UseMcpOAuthConsentResult, useMcpOAuthConsent} from "../auth/useMcpOAuthConsent";
11
+ import {ApiClientProvider} from "../react/apiHooks";
12
+
13
+ const REQUEST_ID = "req-1";
14
+ const REQUEST_PATH = `/oauth/authorize/${REQUEST_ID}`;
15
+
16
+ const CONSENT = {
17
+ clientId: "client-1",
18
+ clientName: "Claude",
19
+ expiresAt: "2026-11-16T12:00:00.000Z",
20
+ // `as const` keeps `access` a literal so the fixture type-checks against McpOAuthConsentGrant.
21
+ grants: [
22
+ {access: "read" as const, description: "Read your data", label: "Read", scope: "mcp:read"},
23
+ {access: "write" as const, description: null, label: "Write", scope: "mcp:write"},
24
+ ],
25
+ redirectHost: "claude.ai",
26
+ redirectUri: "https://claude.ai/callback",
27
+ requestId: REQUEST_ID,
28
+ resource: "https://api.test/mcp",
29
+ scope: "mcp:read mcp:write",
30
+ };
31
+
32
+ interface Recorded {
33
+ body: unknown;
34
+ method: string;
35
+ path: string;
36
+ }
37
+
38
+ interface StubOptions {
39
+ /** HTTP status for GET (default 200). */
40
+ getStatus?: number;
41
+ /** HTTP status for approve (default 200). */
42
+ approveStatus?: number;
43
+ /** Delay approve until released, to observe `submitting`. */
44
+ holdApprove?: Promise<void>;
45
+ /** Delay GET until released, to unmount while it is in flight. */
46
+ holdGet?: Promise<void>;
47
+ /** Make GET reject with a network error instead of answering. */
48
+ getNetworkError?: boolean;
49
+ }
50
+
51
+ const json = (status: number, body: unknown): Response =>
52
+ new Response(JSON.stringify(body), {
53
+ headers: {"Content-Type": "application/json"},
54
+ status,
55
+ });
56
+
57
+ const stubServer = (
58
+ options: StubOptions = {}
59
+ ): {calls: Recorded[]; wrapper: React.FC<{children: React.ReactNode}>} => {
60
+ const calls: Recorded[] = [];
61
+ const fetchImpl: FetchLike = async (input, init) => {
62
+ const method = init?.method ?? "GET";
63
+ const path = new URL(input).pathname;
64
+ calls.push({body: init?.body ? JSON.parse(String(init.body)) : undefined, method, path});
65
+ if (method === "GET") {
66
+ await options.holdGet;
67
+ if (options.getNetworkError) {
68
+ throw new TypeError("Network request failed");
69
+ }
70
+ const status = options.getStatus ?? 200;
71
+ return status === 200 ? json(200, {data: CONSENT}) : json(status, {title: "failed"});
72
+ }
73
+ if (path.endsWith("/approve")) {
74
+ await options.holdApprove;
75
+ const status = options.approveStatus ?? 200;
76
+ return status === 200
77
+ ? json(200, {data: {redirectUrl: "https://claude.ai/callback?code=abc"}})
78
+ : json(status, {title: "failed"});
79
+ }
80
+ return json(200, {data: {redirectUrl: "https://claude.ai/callback?error=access_denied"}});
81
+ };
82
+ const client = createApiClient({baseUrl: "http://api.test", fetchImpl});
83
+ const wrapper: React.FC<{children: React.ReactNode}> = ({children}) =>
84
+ React.createElement(ApiClientProvider, {children, client});
85
+ return {calls, wrapper};
86
+ };
87
+
88
+ const mount = (
89
+ requestId: string | undefined,
90
+ options: StubOptions = {}
91
+ ): {
92
+ calls: Recorded[];
93
+ redirects: string[];
94
+ // Typed with the hook's result instead of `any` so the file passes Biome noExplicitAny.
95
+ hook: ReturnType<typeof renderHook<UseMcpOAuthConsentResult, unknown>>;
96
+ } => {
97
+ const {calls, wrapper} = stubServer(options);
98
+ const redirects: string[] = [];
99
+ const hook = renderHook(
100
+ () => useMcpOAuthConsent({onRedirect: (url) => redirects.push(url), requestId}),
101
+ {wrapper}
102
+ );
103
+ return {calls, hook, redirects};
104
+ };
105
+
106
+ const mountReady = async (options: StubOptions = {}): Promise<ReturnType<typeof mount>> => {
107
+ const mounted = mount(REQUEST_ID, options);
108
+ await waitFor(() => {
109
+ expect(mounted.hook.result.current.state).toBe("ready");
110
+ });
111
+ return mounted;
112
+ };
113
+
114
+ describe("useMcpOAuthConsent", () => {
115
+ it("reports missingRequest without any fetch when requestId is undefined", async () => {
116
+ const {calls, hook} = mount(undefined);
117
+ expect(hook.result.current.state).toBe("error");
118
+ expect(hook.result.current.errorKind).toBe("missingRequest");
119
+ await new Promise((resolve) => setTimeout(resolve, 20));
120
+ expect(calls).toEqual([]);
121
+ });
122
+
123
+ it("starts loading, then is ready with every grant selected in order", async () => {
124
+ const {calls, hook} = mount(REQUEST_ID);
125
+ expect(hook.result.current.state).toBe("loading");
126
+ await waitFor(() => {
127
+ expect(hook.result.current.state).toBe("ready");
128
+ });
129
+ expect(calls[0]).toMatchObject({method: "GET", path: REQUEST_PATH});
130
+ expect(hook.result.current.selectedScopes).toEqual(["mcp:read", "mcp:write"]);
131
+ expect(hook.result.current.request?.clientName).toBe("Claude");
132
+ expect(hook.result.current.request?.redirectHost).toBe("claude.ai");
133
+ expect(hook.result.current.request?.grants).toEqual(CONSENT.grants);
134
+ expect(hook.result.current.errorKind).toBeUndefined();
135
+ });
136
+
137
+ it("toggling mcp:write off then approve posts {scope: 'mcp:read'} and redirects", async () => {
138
+ const {calls, hook, redirects} = await mountReady();
139
+ act(() => hook.result.current.toggleScope("mcp:write"));
140
+ expect(hook.result.current.selectedScopes).toEqual(["mcp:read"]);
141
+ await act(async () => {
142
+ await hook.result.current.approve();
143
+ });
144
+ const post = calls.find((call) => call.method === "POST");
145
+ expect(post).toMatchObject({
146
+ body: {scope: "mcp:read"},
147
+ path: `${REQUEST_PATH}/approve`,
148
+ });
149
+ expect(redirects).toEqual(["https://claude.ai/callback?code=abc"]);
150
+ });
151
+
152
+ it("toggling a scope off and on again restores it", async () => {
153
+ const {hook} = await mountReady();
154
+ act(() => hook.result.current.toggleScope("mcp:write"));
155
+ act(() => hook.result.current.toggleScope("mcp:write"));
156
+ expect([...hook.result.current.selectedScopes].sort()).toEqual(["mcp:read", "mcp:write"]);
157
+ });
158
+
159
+ it("approve with every scope toggled off sends nothing and stays ready", async () => {
160
+ const {calls, hook, redirects} = await mountReady();
161
+ act(() => hook.result.current.toggleScope("mcp:read"));
162
+ act(() => hook.result.current.toggleScope("mcp:write"));
163
+ expect(hook.result.current.selectedScopes).toEqual([]);
164
+ await act(async () => {
165
+ await hook.result.current.approve();
166
+ });
167
+ expect(calls.filter((call) => call.method === "POST")).toEqual([]);
168
+ expect(hook.result.current.state).toBe("ready");
169
+ expect(redirects).toEqual([]);
170
+ });
171
+
172
+ it("is in submitting while approve is in flight", async () => {
173
+ let release: () => void = () => {};
174
+ const holdApprove = new Promise<void>((resolve) => {
175
+ release = resolve;
176
+ });
177
+ const {hook, redirects} = await mountReady({holdApprove});
178
+ let pending: Promise<void> = Promise.resolve();
179
+ act(() => {
180
+ pending = hook.result.current.approve();
181
+ });
182
+ await waitFor(() => {
183
+ expect(hook.result.current.state).toBe("submitting");
184
+ });
185
+ expect(redirects).toEqual([]);
186
+ release();
187
+ await act(async () => {
188
+ await pending;
189
+ });
190
+ expect(redirects).toEqual(["https://claude.ai/callback?code=abc"]);
191
+ });
192
+
193
+ it("deny posts to deny and redirects with the returned URL", async () => {
194
+ const {calls, hook, redirects} = await mountReady();
195
+ await act(async () => {
196
+ await hook.result.current.deny();
197
+ });
198
+ expect(calls.find((call) => call.method === "POST")).toMatchObject({
199
+ path: `${REQUEST_PATH}/deny`,
200
+ });
201
+ expect(redirects).toEqual(["https://claude.ai/callback?error=access_denied"]);
202
+ });
203
+
204
+ for (const [status, kind] of [
205
+ [404, "notFound"],
206
+ [409, "decided"],
207
+ [400, "expired"],
208
+ [401, "signedOut"],
209
+ [500, "unknown"],
210
+ ] as const) {
211
+ it(`maps GET ${status} to errorKind ${kind}`, async () => {
212
+ const {hook, redirects} = mount(REQUEST_ID, {getStatus: status});
213
+ await waitFor(() => {
214
+ expect(hook.result.current.state).toBe("error");
215
+ });
216
+ expect(hook.result.current.errorKind).toBe(kind);
217
+ expect(redirects).toEqual([]);
218
+ });
219
+ }
220
+
221
+ it("approve answering 409 sets errorKind decided and does not redirect", async () => {
222
+ const {hook, redirects} = await mountReady({approveStatus: 409});
223
+ await act(async () => {
224
+ await hook.result.current.approve();
225
+ });
226
+ expect(hook.result.current.state).toBe("error");
227
+ expect(hook.result.current.errorKind).toBe("decided");
228
+ expect(redirects).toEqual([]);
229
+ });
230
+
231
+ it("maps a GET network failure to errorKind unknown", async () => {
232
+ const {hook} = mount(REQUEST_ID, {getNetworkError: true});
233
+ await waitFor(() => {
234
+ expect(hook.result.current.state).toBe("error");
235
+ });
236
+ expect(hook.result.current.errorKind).toBe("unknown");
237
+ });
238
+
239
+ it("resets to loading and fetches the new request when requestId changes", async () => {
240
+ const {calls, wrapper} = stubServer();
241
+ const hook = renderHook(
242
+ ({requestId}: {requestId: string}) => useMcpOAuthConsent({onRedirect: () => {}, requestId}),
243
+ {initialProps: {requestId: REQUEST_ID}, wrapper}
244
+ );
245
+ await waitFor(() => {
246
+ expect(hook.result.current.state).toBe("ready");
247
+ });
248
+ hook.rerender({requestId: "req-2"});
249
+ expect(hook.result.current.state).toBe("loading");
250
+ expect(hook.result.current.request).toBeUndefined();
251
+ await waitFor(() => {
252
+ expect(hook.result.current.state).toBe("ready");
253
+ });
254
+ expect(calls.map((call) => call.path)).toEqual([REQUEST_PATH, "/oauth/authorize/req-2"]);
255
+ });
256
+
257
+ for (const getStatus of [200, 404]) {
258
+ it(`ignores a GET answering ${getStatus} after unmount`, async () => {
259
+ let release = (): void => {};
260
+ const holdGet = new Promise<void>((resolve) => {
261
+ release = resolve;
262
+ });
263
+ const {calls, hook} = mount(REQUEST_ID, {getStatus, holdGet});
264
+ expect(hook.result.current.state).toBe("loading");
265
+ hook.unmount();
266
+ release();
267
+ await new Promise((resolve) => setTimeout(resolve, 20));
268
+ expect(calls).toHaveLength(1);
269
+ expect(hook.result.current.state).toBe("loading");
270
+ });
271
+ }
272
+
273
+ it("toggleScope and deny do nothing before the request loads", async () => {
274
+ let release = (): void => {};
275
+ const holdGet = new Promise<void>((resolve) => {
276
+ release = resolve;
277
+ });
278
+ const {calls, hook} = mount(REQUEST_ID, {holdGet});
279
+ act(() => {
280
+ hook.result.current.toggleScope("mcp:read");
281
+ });
282
+ await act(async () => {
283
+ await hook.result.current.deny();
284
+ });
285
+ expect(hook.result.current.state).toBe("loading");
286
+ expect(hook.result.current.selectedScopes).toEqual([]);
287
+ expect(calls.filter((call) => call.method === "POST")).toEqual([]);
288
+ release();
289
+ await waitFor(() => {
290
+ expect(hook.result.current.state).toBe("ready");
291
+ });
292
+ });
293
+
294
+ it("a second approve while the first is in flight posts once", async () => {
295
+ let release = (): void => {};
296
+ const holdApprove = new Promise<void>((resolve) => {
297
+ release = resolve;
298
+ });
299
+ const {calls, hook, redirects} = await mountReady({holdApprove});
300
+ const {approve} = hook.result.current;
301
+ await act(async () => {
302
+ const first = approve();
303
+ const second = approve();
304
+ release();
305
+ await Promise.all([first, second]);
306
+ });
307
+ expect(calls.filter((call) => call.method === "POST")).toHaveLength(1);
308
+ expect(redirects).toEqual(["https://claude.ai/callback?code=abc"]);
309
+ });
310
+
311
+ it("without onRedirect, sends the browser to the redirect URL", async () => {
312
+ const assigned: string[] = [];
313
+ const globals = globalThis as {window?: unknown};
314
+ const previousWindow = globals.window;
315
+ globals.window = {location: {assign: (url: string): void => void assigned.push(url)}};
316
+ try {
317
+ const {wrapper} = stubServer();
318
+ const hook = renderHook(() => useMcpOAuthConsent({requestId: REQUEST_ID}), {wrapper});
319
+ await waitFor(() => {
320
+ expect(hook.result.current.state).toBe("ready");
321
+ });
322
+ await act(async () => {
323
+ await hook.result.current.deny();
324
+ });
325
+ expect(assigned).toEqual(["https://claude.ai/callback?error=access_denied"]);
326
+ } finally {
327
+ globals.window = previousWindow;
328
+ }
329
+ });
330
+ });