@terreno/admin-frontend 57.19.2 → 57.21.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 (190) hide show
  1. package/CHANGELOG.md +443 -0
  2. package/dist/AdminFieldRenderer.d.ts +3 -2
  3. package/dist/AdminFieldRenderer.d.ts.map +1 -1
  4. package/dist/AdminFieldRenderer.js +12 -5
  5. package/dist/AdminFieldRenderer.js.map +1 -1
  6. package/dist/AdminFieldRendererCore.d.ts +6 -3
  7. package/dist/AdminFieldRendererCore.d.ts.map +1 -1
  8. package/dist/AdminFieldRendererCore.js +10 -7
  9. package/dist/AdminFieldRendererCore.js.map +1 -1
  10. package/dist/AdminFilterDrawer.d.ts.map +1 -1
  11. package/dist/AdminFilterDrawer.js +2 -3
  12. package/dist/AdminFilterDrawer.js.map +1 -1
  13. package/dist/AdminHome.d.ts.map +1 -1
  14. package/dist/AdminHome.js +5 -2
  15. package/dist/AdminHome.js.map +1 -1
  16. package/dist/AdminModelForm.d.ts.map +1 -1
  17. package/dist/AdminModelForm.js +4 -0
  18. package/dist/AdminModelForm.js.map +1 -1
  19. package/dist/AdminNestedArrayField.d.ts +2 -0
  20. package/dist/AdminNestedArrayField.d.ts.map +1 -1
  21. package/dist/AdminNestedArrayField.js +51 -25
  22. package/dist/AdminNestedArrayField.js.map +1 -1
  23. package/dist/AdminNestedObjectField.d.ts +43 -0
  24. package/dist/AdminNestedObjectField.d.ts.map +1 -0
  25. package/dist/AdminNestedObjectField.js +72 -0
  26. package/dist/AdminNestedObjectField.js.map +1 -0
  27. package/dist/AdminRolesField.d.ts +3 -1
  28. package/dist/AdminRolesField.d.ts.map +1 -1
  29. package/dist/AdminRolesField.js +6 -2
  30. package/dist/AdminRolesField.js.map +1 -1
  31. package/dist/AdminShell.d.ts +3 -3
  32. package/dist/AdminShell.d.ts.map +1 -1
  33. package/dist/AdminShell.js +4 -6
  34. package/dist/AdminShell.js.map +1 -1
  35. package/dist/ConfigurationScreen.d.ts.map +1 -1
  36. package/dist/ConfigurationScreen.js +3 -3
  37. package/dist/ConfigurationScreen.js.map +1 -1
  38. package/dist/ConsentHistory.d.ts.map +1 -1
  39. package/dist/ConsentHistory.js +17 -2
  40. package/dist/ConsentHistory.js.map +1 -1
  41. package/dist/ConsentResponseViewer.d.ts.map +1 -1
  42. package/dist/ConsentResponseViewer.js +20 -2
  43. package/dist/ConsentResponseViewer.js.map +1 -1
  44. package/dist/Constants.d.ts +5 -2
  45. package/dist/Constants.d.ts.map +1 -1
  46. package/dist/Constants.js +5 -2
  47. package/dist/Constants.js.map +1 -1
  48. package/dist/UserSecurityScreen.d.ts +45 -0
  49. package/dist/UserSecurityScreen.d.ts.map +1 -0
  50. package/dist/UserSecurityScreen.js +66 -0
  51. package/dist/UserSecurityScreen.js.map +1 -0
  52. package/dist/consentPdfTemplates.d.ts +64 -0
  53. package/dist/consentPdfTemplates.d.ts.map +1 -0
  54. package/dist/consentPdfTemplates.js +160 -0
  55. package/dist/consentPdfTemplates.js.map +1 -0
  56. package/dist/generateConsentHistoryPdf.d.ts.map +1 -1
  57. package/dist/generateConsentHistoryPdf.js +7 -55
  58. package/dist/generateConsentHistoryPdf.js.map +1 -1
  59. package/dist/generateConsentPdf.d.ts +1 -26
  60. package/dist/generateConsentPdf.d.ts.map +1 -1
  61. package/dist/generateConsentPdf.js +7 -69
  62. package/dist/generateConsentPdf.js.map +1 -1
  63. package/dist/index.d.ts +4 -1
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +3 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/orgs/MemberSecurityPanel.d.ts +34 -0
  68. package/dist/orgs/MemberSecurityPanel.d.ts.map +1 -0
  69. package/dist/orgs/MemberSecurityPanel.js +204 -0
  70. package/dist/orgs/MemberSecurityPanel.js.map +1 -0
  71. package/dist/orgs/OrgMembersScreen.d.ts.map +1 -1
  72. package/dist/orgs/OrgMembersScreen.js +33 -6
  73. package/dist/orgs/OrgMembersScreen.js.map +1 -1
  74. package/dist/orgs/adminModelEndpoints.d.ts +13 -1
  75. package/dist/orgs/adminModelEndpoints.d.ts.map +1 -1
  76. package/dist/orgs/adminModelEndpoints.js +30 -13
  77. package/dist/orgs/adminModelEndpoints.js.map +1 -1
  78. package/dist/orgs/useMemberSecurityApi.d.ts +97 -0
  79. package/dist/orgs/useMemberSecurityApi.d.ts.map +1 -0
  80. package/dist/orgs/useMemberSecurityApi.js +98 -0
  81. package/dist/orgs/useMemberSecurityApi.js.map +1 -0
  82. package/dist/pdfUtils.d.ts +15 -0
  83. package/dist/pdfUtils.d.ts.map +1 -1
  84. package/dist/pdfUtils.js +70 -0
  85. package/dist/pdfUtils.js.map +1 -1
  86. package/dist/types.d.ts +7 -1
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/types.js.map +1 -1
  89. package/dist/useAdminApi.d.ts +8 -2
  90. package/dist/useAdminApi.d.ts.map +1 -1
  91. package/dist/useAdminApi.js +11 -46
  92. package/dist/useAdminApi.js.map +1 -1
  93. package/dist/useAdminRoles.d.ts +5 -1
  94. package/dist/useAdminRoles.d.ts.map +1 -1
  95. package/dist/useAdminRoles.js +3 -3
  96. package/dist/useAdminRoles.js.map +1 -1
  97. package/dist/useAdminRpc.d.ts.map +1 -1
  98. package/dist/useAdminRpc.js +18 -3
  99. package/dist/useAdminRpc.js.map +1 -1
  100. package/dist/useConsentHistory.d.ts +7 -0
  101. package/dist/useConsentHistory.d.ts.map +1 -1
  102. package/dist/useConsentHistory.js.map +1 -1
  103. package/package.json +7 -3
  104. package/src/AdminBreadcrumbs.test.tsx +1 -1
  105. package/src/AdminFieldRenderer.test.tsx +2 -1
  106. package/src/AdminFieldRenderer.tsx +48 -3
  107. package/src/AdminFieldRendererCore.tsx +12 -5
  108. package/src/AdminFilterDrawer.tsx +3 -4
  109. package/src/AdminHome.test.tsx +65 -1
  110. package/src/AdminHome.tsx +14 -6
  111. package/src/AdminModelForm.tsx +4 -0
  112. package/src/AdminModelTable.test.tsx +16 -12
  113. package/src/AdminModelTable.windowed.test.tsx +11 -5
  114. package/src/AdminNestedArrayField.tsx +116 -44
  115. package/src/AdminNestedObjectField.test.tsx +239 -0
  116. package/src/AdminNestedObjectField.tsx +145 -0
  117. package/src/AdminPrimitiveArrayField.test.tsx +3 -3
  118. package/src/AdminProvider.test.tsx +11 -6
  119. package/src/AdminRolesField.tsx +6 -2
  120. package/src/AdminRolesList.test.tsx +47 -14
  121. package/src/AdminScreenPage.test.tsx +1 -1
  122. package/src/AdminScreenRouter.test.tsx +15 -5
  123. package/src/AdminScriptList.test.tsx +9 -2
  124. package/src/AdminShell.test.tsx +16 -2
  125. package/src/AdminShell.tsx +5 -8
  126. package/src/AdminVersionConfig.test.tsx +4 -4
  127. package/src/AnnouncementOverviewScreenWidget.test.tsx +6 -1
  128. package/src/CheckboxListEditor.test.tsx +11 -9
  129. package/src/ConfigurationScreen.test.tsx +2 -2
  130. package/src/ConfigurationScreen.tsx +6 -2
  131. package/src/ConsentHistory.test.tsx +69 -1
  132. package/src/ConsentHistory.tsx +39 -1
  133. package/src/ConsentResponseViewer.test.tsx +113 -1
  134. package/src/ConsentResponseViewer.tsx +106 -8
  135. package/src/Constants.ts +5 -2
  136. package/src/UserSecurityScreen.tsx +184 -0
  137. package/src/adminRequest.test.ts +3 -3
  138. package/src/adminWindowedTable.test.ts +4 -2
  139. package/src/comms/CommsDashboardScreen.test.tsx +5 -5
  140. package/src/comms/CommsMessageDetail.test.tsx +1 -1
  141. package/src/consentPdfTemplates.test.ts +180 -0
  142. package/src/consentPdfTemplates.ts +228 -0
  143. package/src/generateConsentHistoryPdf.ts +9 -63
  144. package/src/generateConsentPdf.ts +14 -107
  145. package/src/index.tsx +20 -0
  146. package/src/isolated/AdminFieldRenderer.isolated.tsx +11 -6
  147. package/src/isolated/AdminFilterDrawer.isolated.tsx +8 -6
  148. package/src/isolated/AdminFilterDrawerMobile.isolated.tsx +3 -1
  149. package/src/isolated/AdminHomeWidgets.isolated.tsx +2 -0
  150. package/src/isolated/AdminNestedArrayField.isolated.tsx +103 -10
  151. package/src/isolated/AdminObjectPicker.isolated.tsx +9 -10
  152. package/src/isolated/AiPromptsListScreen.isolated.tsx +1 -1
  153. package/src/isolated/DocumentStorageBrowser.isolated.tsx +16 -8
  154. package/src/isolated/RecentActivityWidget.isolated.tsx +2 -0
  155. package/src/isolated/UserSecurityScreen.isolated.tsx +365 -0
  156. package/src/isolated/adminWidgets.isolated.tsx +46 -6
  157. package/src/isolated/aiObservabilityScreens.isolated.tsx +18 -9
  158. package/src/isolated/generateConsentHistoryPdf.isolated.ts +60 -7
  159. package/src/isolated/generateConsentPdf.isolated.ts +47 -0
  160. package/src/isolated/generateConsentPdfMobile.isolated.ts +28 -0
  161. package/src/isolated/generateConsentPdfsMobile.isolated.ts +59 -2
  162. package/src/isolated/hooks.isolated.tsx +163 -42
  163. package/src/isolated/rpcDualRun.isolated.tsx +9 -2
  164. package/src/jobs/JobsDashboardScreen.test.tsx +3 -3
  165. package/src/jobs/JobsHomeWidget.test.tsx +1 -1
  166. package/src/jobs/JobsJobDetail.test.tsx +1 -1
  167. package/src/orgs/MemberSecurityPanel.test.tsx +584 -0
  168. package/src/orgs/MemberSecurityPanel.tsx +520 -0
  169. package/src/orgs/OrgManagementScreens.test.tsx +121 -2
  170. package/src/orgs/OrgMembersScreen.tsx +71 -4
  171. package/src/orgs/adminModelEndpoints.test.ts +1 -1
  172. package/src/orgs/adminModelEndpoints.ts +56 -15
  173. package/src/orgs/useMemberSecurityApi.ts +198 -0
  174. package/src/pdfUtils.test.ts +24 -1
  175. package/src/pdfUtils.ts +93 -0
  176. package/src/testing/useAdminApiDouble.ts +2 -1
  177. package/src/types.ts +7 -1
  178. package/src/useAdminApi.ts +23 -3
  179. package/src/useAdminRoles.ts +11 -3
  180. package/src/useAdminRpc.test.tsx +116 -2
  181. package/src/useAdminRpc.ts +19 -3
  182. package/src/useConsentHistory.ts +5 -0
  183. package/src/widgets/AIRequestsScreenWidget.test.tsx +20 -3
  184. package/src/widgets/ModelsGridWidget.test.tsx +25 -5
  185. package/src/widgets/aiObservability/datasets/AiDatasetDetailView.test.tsx +4 -2
  186. package/src/widgets/aiObservability/datasets/datasetTypes.test.ts +0 -1
  187. package/src/widgets/aiObservability/evaluators/AiEvaluatorPanels.test.tsx +89 -23
  188. package/src/widgets/aiObservability/experiments/AiExperimentNewView.test.tsx +4 -0
  189. package/src/widgets/aiObservability/shell/ObservabilityTable.test.tsx +7 -1
  190. package/src/widgets/builtInFieldWidgets.test.tsx +16 -3
@@ -10,8 +10,15 @@
10
10
  * - the returned hook functions correspond to the generated hook names
11
11
  */
12
12
  import {describe, expect, it, mock} from "bun:test";
13
+ import {configureStore} from "@reduxjs/toolkit";
14
+ import {createApi} from "@reduxjs/toolkit/query/react";
15
+ import {act, waitFor} from "@testing-library/react-native";
13
16
  import React from "react";
17
+ import {Provider} from "react-redux";
14
18
  import {renderWithTheme} from "../../../ui/src/test-utils";
19
+ import {adminOrgScopedArg} from "../orgs/adminModelEndpoints";
20
+ import {OrgContextProvider, useOrgContext} from "../orgs/useOrgContext";
21
+ import type {AdminApi} from "../types";
15
22
  import {useAdminApi} from "../useAdminApi";
16
23
  import {useAdminBackgroundTaskMutation} from "../useAdminBackgroundTask";
17
24
  import {useAdminConfig} from "../useAdminConfig";
@@ -20,19 +27,50 @@ import {useAdminScripts} from "../useAdminScripts";
20
27
  import {useConfigurationApi} from "../useConfigurationApi";
21
28
  import {useDocumentStorageApi} from "../useDocumentStorageApi";
22
29
 
23
- interface BuildSpec {
24
- query?: (arg?: unknown) => unknown;
25
- mutation?: (arg?: unknown) => unknown;
30
+ /** What an injected endpoint's `query` returns: an RTK Query request description. */
31
+ interface QuerySpec {
32
+ [key: string]: unknown;
33
+ method?: string;
34
+ responseHandler?: (response: unknown) => Promise<unknown>;
35
+ url?: string;
36
+ }
37
+
38
+ type TagsFn = (result: unknown, error: unknown, arg: unknown) => unknown;
39
+
40
+ /** An endpoint definition as captured by the mock builder. */
41
+ interface CapturedEndpoint {
42
+ __kind?: "query" | "mutation";
43
+ query: (arg?: unknown) => QuerySpec;
26
44
  providesTags?: unknown;
27
45
  invalidatesTags?: unknown;
28
- extraOptions?: unknown;
46
+ serializeQueryArgs?: (args: {endpointName: string; queryArgs: unknown}) => string;
29
47
  }
30
48
 
31
- interface CapturedEndpoints {
32
- [key: string]: BuildSpec;
33
- }
49
+ type CapturedEndpoints = Record<string, CapturedEndpoint>;
50
+
51
+ /** The proxy double handed to the hooks, plus what it recorded. */
52
+ type MockAdminApi = AdminApi & {
53
+ readonly __injected: CapturedEndpoints;
54
+ readonly __tagTypes: string[];
55
+ };
34
56
 
35
- const makeMockApi = () => {
57
+ /** Calls an endpoint's function-form `providesTags` / `invalidatesTags` for `arg`. */
58
+ const callTags = (tags: unknown, arg: unknown): unknown => {
59
+ if (typeof tags !== "function") {
60
+ throw new Error("Expected a tag function");
61
+ }
62
+ return (tags as TagsFn)(null, null, arg);
63
+ };
64
+
65
+ /** Calls an endpoint's `serializeQueryArgs`, failing when the endpoint has none. */
66
+ const serializeArgs = (endpoint: CapturedEndpoint, endpointName: string, queryArgs: unknown) => {
67
+ if (!endpoint.serializeQueryArgs) {
68
+ throw new Error(`${endpointName} has no serializeQueryArgs`);
69
+ }
70
+ return endpoint.serializeQueryArgs({endpointName, queryArgs});
71
+ };
72
+
73
+ const makeMockApi = (): MockAdminApi => {
36
74
  const injected: CapturedEndpoints = {};
37
75
  const enhancedTagTypes: string[] = [];
38
76
 
@@ -69,16 +107,15 @@ const makeMockApi = () => {
69
107
  };
70
108
  }
71
109
  if (prop === "injectEndpoints") {
72
- return ({endpoints}: {endpoints: (build: unknown) => Record<string, BuildSpec>}) => {
110
+ return ({endpoints}: {endpoints: (build: unknown) => CapturedEndpoints}) => {
73
111
  const build = {
74
- mutation: (spec: BuildSpec) => ({...spec, __kind: "mutation"}),
75
- query: (spec: BuildSpec) => ({...spec, __kind: "query"}),
112
+ mutation: (spec: CapturedEndpoint): CapturedEndpoint => ({...spec, __kind: "mutation"}),
113
+ query: (spec: CapturedEndpoint): CapturedEndpoint => ({...spec, __kind: "query"}),
76
114
  };
77
115
  const defs = endpoints(build);
78
116
  for (const [key, def] of Object.entries(defs)) {
79
117
  injected[key] = def;
80
- const kind =
81
- (def as Record<string, unknown>).__kind === "mutation" ? "mutation" : "query";
118
+ const kind = def.__kind === "mutation" ? "mutation" : "query";
82
119
  addHookFor(key, kind);
83
120
  }
84
121
  return apiProxy;
@@ -94,7 +131,8 @@ const makeMockApi = () => {
94
131
  },
95
132
  });
96
133
 
97
- return apiProxy;
134
+ // Test double: the proxy answers only the Api members the hooks touch.
135
+ return apiProxy as unknown as MockAdminApi;
98
136
  };
99
137
 
100
138
  const runHook = <T,>(fn: () => T): T => {
@@ -112,7 +150,7 @@ describe("useAdminApi", () => {
112
150
  const api = makeMockApi();
113
151
  const result = runHook(() => useAdminApi(api, "/admin/users", "User"));
114
152
 
115
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
153
+ const injected = api.__injected;
116
154
  expect(injected.adminList_User).toBeDefined();
117
155
  expect(injected.adminRead_User).toBeDefined();
118
156
  expect(injected.adminCreate_User).toBeDefined();
@@ -120,7 +158,7 @@ describe("useAdminApi", () => {
120
158
  expect(injected.adminDelete_User).toBeDefined();
121
159
 
122
160
  // tag types include the admin_<model>
123
- expect((api as Record<string, unknown>).__tagTypes).toContain("admin_User");
161
+ expect(api.__tagTypes).toContain("admin_User");
124
162
 
125
163
  // Each endpoint's query fn produces expected URL/method
126
164
  const listDef = injected.adminList_User;
@@ -141,7 +179,7 @@ describe("useAdminApi", () => {
141
179
  method: "GET",
142
180
  url: "/admin/users/abc",
143
181
  });
144
- expect(readDef.providesTags(null, null, "abc")).toEqual([{id: "abc", type: "admin_User"}]);
182
+ expect(callTags(readDef.providesTags, "abc")).toEqual([{id: "abc", type: "admin_User"}]);
145
183
 
146
184
  const createDef = injected.adminCreate_User;
147
185
  expect(createDef.query({name: "x"})).toEqual({
@@ -159,7 +197,7 @@ describe("useAdminApi", () => {
159
197
  method: "PATCH",
160
198
  url: "/admin/users/123",
161
199
  });
162
- expect(updateDef.invalidatesTags(null, null, {id: "123"})).toEqual([
200
+ expect(callTags(updateDef.invalidatesTags, {id: "123"})).toEqual([
163
201
  {id: "123", type: "admin_User"},
164
202
  "admin_User",
165
203
  ]);
@@ -191,7 +229,7 @@ describe("useAdminApi", () => {
191
229
  it("pins list/read/create/update/delete/bulk-patch URLs for String-_id routePath", () => {
192
230
  const api = makeMockApi();
193
231
  const result = runHook(() => useAdminApi(api, "/admin/todos", "Todo"));
194
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
232
+ const injected = api.__injected;
195
233
 
196
234
  expect(
197
235
  injected.adminList_Todo.query({limit: 20, page: 1, q: "Alpha", sort: "-created"})
@@ -234,12 +272,93 @@ describe("useAdminApi", () => {
234
272
  });
235
273
  });
236
274
 
275
+ describe("useAdminApi organization switches", () => {
276
+ // A real RTK Query store whose server answers with the organization header it was sent.
277
+ const buildStore = () => {
278
+ const requests: {orgId?: string; url: string}[] = [];
279
+ const api = createApi({
280
+ baseQuery: async (args: {headers?: Record<string, string>; url: string}) => {
281
+ const orgId = args.headers?.["X-Organization-Id"];
282
+ requests.push({orgId, url: args.url});
283
+ return {data: {_id: "user-1", org: orgId ?? "none"}};
284
+ },
285
+ endpoints: () => ({}),
286
+ reducerPath: "terreno-rtk",
287
+ });
288
+ const store = configureStore({
289
+ middleware: (getDefault) => getDefault({serializableCheck: false}).concat(api.middleware),
290
+ reducer: {[api.reducerPath]: api.reducer},
291
+ });
292
+ return {api, requests, store};
293
+ };
294
+
295
+ it("reads the record again for the organization chosen after the first read started", async () => {
296
+ const {api, requests, store} = buildStore();
297
+ let selectOrganization: (organization: {_id: string; name: string}) => void = () => {};
298
+ let latest: {data?: {org?: string}; isLoading?: boolean} = {};
299
+ const Probe: React.FC = () => {
300
+ selectOrganization = useOrgContext().selectOrganization;
301
+ const {useReadQuery} = useAdminApi(api as never, "/admin/users", "User");
302
+ latest = useReadQuery("user-1");
303
+ return null;
304
+ };
305
+ renderWithTheme(
306
+ <Provider store={store}>
307
+ <OrgContextProvider>
308
+ <Probe />
309
+ </OrgContextProvider>
310
+ </Provider>
311
+ );
312
+ await waitFor(() => expect(latest.data?.org).toBe("none"));
313
+
314
+ // The org switcher settles on a default organization after the screen's first read.
315
+ act(() => {
316
+ selectOrganization({_id: "org-a", name: "Alpha"});
317
+ });
318
+
319
+ await waitFor(() => expect(latest.data?.org).toBe("org-a"));
320
+ expect(latest.isLoading).toBe(false);
321
+ expect(requests).toEqual([
322
+ {orgId: undefined, url: "/admin/users/user-1"},
323
+ {orgId: "org-a", url: "/admin/users/user-1"},
324
+ ]);
325
+ });
326
+
327
+ it("keys list and read entries by the organization carried in the argument", () => {
328
+ const api = makeMockApi();
329
+ runHook(() => useAdminApi(api, "/admin/users", "User"));
330
+ const injected = api.__injected;
331
+ const read = injected.adminRead_User;
332
+ const list = injected.adminList_User;
333
+
334
+ expect(read.query(adminOrgScopedArg("abc", "org-b"))).toEqual({
335
+ headers: {"X-Organization-Id": "org-b"},
336
+ method: "GET",
337
+ url: "/admin/users/abc",
338
+ });
339
+ expect(callTags(read.providesTags, adminOrgScopedArg("abc", "org-b"))).toEqual([
340
+ {id: "abc", type: "admin_User"},
341
+ ]);
342
+ expect(serializeArgs(read, "adminRead_User", adminOrgScopedArg("abc", "org-b"))).toBe(
343
+ "adminRead_User:org-b:abc"
344
+ );
345
+ expect(list.query(adminOrgScopedArg({limit: 1}, undefined))).toEqual({
346
+ headers: undefined,
347
+ method: "GET",
348
+ url: "/admin/users?limit=1",
349
+ });
350
+ expect(serializeArgs(list, "adminList_User", adminOrgScopedArg({limit: 1}, "org-b"))).toBe(
351
+ 'adminList_User:org-b:{"limit":1}'
352
+ );
353
+ });
354
+ });
355
+
237
356
  describe("useAdminConfig", () => {
238
357
  it("injects adminConfig query and exposes config hook data", () => {
239
358
  const api = makeMockApi();
240
359
  const result = runHook(() => useAdminConfig(api, "/admin"));
241
360
 
242
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
361
+ const injected = api.__injected;
243
362
  expect(injected.adminConfig).toBeDefined();
244
363
  const def = injected.adminConfig;
245
364
  expect(def.query()).toEqual({method: "GET", url: "/admin/config"});
@@ -257,7 +376,7 @@ describe("useAdminScripts", () => {
257
376
  const api = makeMockApi();
258
377
  const result = runHook(() => useAdminScripts(api, "/admin"));
259
378
 
260
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
379
+ const injected = api.__injected;
261
380
  expect(injected.adminRunScript).toBeDefined();
262
381
  expect(injected.adminGetScriptTask).toBeDefined();
263
382
  expect(injected.adminCancelScriptTask).toBeDefined();
@@ -302,7 +421,9 @@ describe("useAdminScripts", () => {
302
421
  it("returns safe script hooks when endpoint injection is unavailable", async () => {
303
422
  const result = runHook(() => useAdminScripts({} as never, "/admin"));
304
423
 
305
- expect(await result.useCancelScriptTaskMutation()[0]("task-1").unwrap()).toEqual({});
424
+ // The no-op fallback resolves to an empty object rather than a typed task response.
425
+ const cancelled: unknown = await result.useCancelScriptTaskMutation()[0]("task-1").unwrap();
426
+ expect(cancelled).toEqual({});
306
427
  expect(result.useGetScriptTaskQuery("task-1")).toEqual({
307
428
  data: undefined,
308
429
  error: null,
@@ -324,7 +445,7 @@ describe("useAdminRoles", () => {
324
445
  it("injects RBAC endpoints outside the admin base", () => {
325
446
  const api = makeMockApi();
326
447
  const result = runHook(() => useAdminRoles(api, "/admin"));
327
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
448
+ const injected = api.__injected;
328
449
 
329
450
  expect(
330
451
  injected.adminCreateRbacRole.query({
@@ -392,7 +513,7 @@ describe("useAdminBackgroundTaskMutation", () => {
392
513
  it("injects a background-task request at a normalized admin root", () => {
393
514
  const api = makeMockApi();
394
515
  const result = runHook(() => useAdminBackgroundTaskMutation(api, "/admin/"));
395
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
516
+ const injected = api.__injected;
396
517
 
397
518
  expect(
398
519
  injected.adminPostBackgroundTask.query({
@@ -420,33 +541,29 @@ describe("useConfigurationApi", () => {
420
541
  const api = makeMockApi();
421
542
  const result = runHook(() => useConfigurationApi({api, basePath: "/admin/configuration"}));
422
543
 
423
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
544
+ const injected = api.__injected;
424
545
  expect(injected.configMeta).toBeDefined();
425
546
  expect(injected.configValues).toBeDefined();
426
547
  expect(injected.configUpdate).toBeDefined();
427
548
  expect(injected.configRefreshSecrets).toBeDefined();
428
- expect((api as Record<string, unknown>).__tagTypes).toContain("configuration");
549
+ expect(api.__tagTypes).toContain("configuration");
429
550
 
430
- expect((injected.configMeta as BuildSpec & Record<string, unknown>).query()).toEqual({
551
+ expect(injected.configMeta.query()).toEqual({
431
552
  method: "GET",
432
553
  url: "/admin/configuration/meta",
433
554
  });
434
- expect((injected.configValues as BuildSpec & Record<string, unknown>).query()).toEqual({
555
+ expect(injected.configValues.query()).toEqual({
435
556
  method: "GET",
436
557
  url: "/admin/configuration",
437
558
  });
438
- expect((injected.configValues as BuildSpec & Record<string, unknown>).providesTags).toEqual([
439
- "configuration",
440
- ]);
441
- expect((injected.configUpdate as BuildSpec & Record<string, unknown>).query({a: 1})).toEqual({
559
+ expect(injected.configValues.providesTags).toEqual(["configuration"]);
560
+ expect(injected.configUpdate.query({a: 1})).toEqual({
442
561
  body: {a: 1},
443
562
  method: "PATCH",
444
563
  url: "/admin/configuration",
445
564
  });
446
- expect((injected.configUpdate as BuildSpec & Record<string, unknown>).invalidatesTags).toEqual([
447
- "configuration",
448
- ]);
449
- expect((injected.configRefreshSecrets as BuildSpec & Record<string, unknown>).query()).toEqual({
565
+ expect(injected.configUpdate.invalidatesTags).toEqual(["configuration"]);
566
+ expect(injected.configRefreshSecrets.query()).toEqual({
450
567
  method: "POST",
451
568
  url: "/admin/configuration/refresh-secrets",
452
569
  });
@@ -463,7 +580,7 @@ describe("useDocumentStorageApi", () => {
463
580
  const api = makeMockApi();
464
581
  const result = runHook(() => useDocumentStorageApi(api, "/documents"));
465
582
 
466
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
583
+ const injected = api.__injected;
467
584
  expect(injected.documentStorageList).toBeDefined();
468
585
  expect(injected.documentStorageUpload).toBeDefined();
469
586
  expect(injected.documentStorageDownload).toBeDefined();
@@ -517,6 +634,10 @@ describe("useDocumentStorageApi", () => {
517
634
  expect(dlSpec.url).toBe("/documents/download/my%20folder%2Ffile.pdf");
518
635
  expect(dlSpec.method).toBe("GET");
519
636
  expect(typeof dlSpec.responseHandler).toBe("function");
637
+ const responseHandler = dlSpec.responseHandler;
638
+ if (!responseHandler) {
639
+ throw new Error("download endpoint has no responseHandler");
640
+ }
520
641
 
521
642
  // responseHandler returns the blob on ok
522
643
  const okBlob = {size: 5, type: "text/plain"};
@@ -527,7 +648,7 @@ describe("useDocumentStorageApi", () => {
527
648
  status: 200,
528
649
  statusText: "OK",
529
650
  };
530
- return dlSpec.responseHandler(okResp).then(async (blob: unknown) => {
651
+ return responseHandler(okResp).then(async (blob: unknown) => {
531
652
  expect(blob).toBe(okBlob);
532
653
 
533
654
  // non-ok JSON response
@@ -539,7 +660,7 @@ describe("useDocumentStorageApi", () => {
539
660
  statusText: "Bad Request",
540
661
  text: async () => errJson,
541
662
  };
542
- const parsed = await dlSpec.responseHandler(jsonResp);
663
+ const parsed = await responseHandler(jsonResp);
543
664
  expect(parsed).toEqual({detail: "Bad", status: 400});
544
665
 
545
666
  // non-ok non-JSON response (fallback)
@@ -550,7 +671,7 @@ describe("useDocumentStorageApi", () => {
550
671
  statusText: "err",
551
672
  text: async () => "boom",
552
673
  };
553
- const textParsed = await dlSpec.responseHandler(textResp);
674
+ const textParsed = await responseHandler(textResp);
554
675
  expect(textParsed).toEqual({detail: "boom", status: 500});
555
676
 
556
677
  // Delete endpoints
@@ -587,7 +708,7 @@ describe("useAdminBackgroundTaskMutation", () => {
587
708
  it("posts to the background-tasks collection under the admin root", () => {
588
709
  const api = makeMockApi();
589
710
  const result = runHook(() => useAdminBackgroundTaskMutation(api as never, "/admin/"));
590
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
711
+ const injected = api.__injected;
591
712
  expect(injected.adminPostBackgroundTask.query({ids: ["a"], kind: "reindex"})).toEqual({
592
713
  body: {ids: ["a"], kind: "reindex"},
593
714
  method: "POST",
@@ -610,7 +731,7 @@ describe("useAdminRoles", () => {
610
731
  it("injects rbac list and mutation endpoints at the API root", () => {
611
732
  const api = makeMockApi();
612
733
  const result = runHook(() => useAdminRoles(api as never, "/v1/admin"));
613
- const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
734
+ const injected = api.__injected;
614
735
  expect(injected.adminListRbacRoles.query()).toEqual({method: "GET", url: "/v1/rbac/roles"});
615
736
  expect(injected.adminListRbacStatements.query()).toEqual({
616
737
  method: "GET",
@@ -7,7 +7,7 @@ import {AdminObjectPicker} from "../AdminObjectPicker";
7
7
  import {AdminProvider} from "../AdminProvider";
8
8
  import {AdminVersionConfig} from "../AdminVersionConfig";
9
9
  import {useCommsDashboardApi} from "../comms/useCommsDashboardApi";
10
- import type {AdminApi} from "../types";
10
+ import type {AdminApi, AdminConfigResponse} from "../types";
11
11
  import {useAdminBackgroundTaskMutation} from "../useAdminBackgroundTask";
12
12
  import {useAdminConfig} from "../useAdminConfig";
13
13
  import {useAdminRoles} from "../useAdminRoles";
@@ -18,6 +18,8 @@ import {useConsentHistory} from "../useConsentHistory";
18
18
  import {useDocumentStorageApi} from "../useDocumentStorageApi";
19
19
  import {AIRequestsScreenWidget} from "../widgets/AIRequestsScreenWidget";
20
20
 
21
+ const emptyConfig: AdminConfigResponse = {customScreens: [], models: [], scripts: []};
22
+
21
23
  const makeApi = (): AdminApi => {
22
24
  const api: Record<string, unknown> = {};
23
25
  const hooks = new Proxy(
@@ -332,7 +334,12 @@ describe("admin RPC dual-run", () => {
332
334
  credentials="same-origin"
333
335
  getAuthHeaders={() => ({})}
334
336
  >
335
- <AIRequestsScreenWidget api={makeApi()} routeBase="/admin" />
337
+ <AIRequestsScreenWidget
338
+ api={makeApi()}
339
+ config={emptyConfig}
340
+ routeBase="/admin"
341
+ screenName="aiRequests"
342
+ />
336
343
  </AdminProvider>
337
344
  );
338
345
  await flushEffects();
@@ -5,7 +5,7 @@ import React from "react";
5
5
  import {renderWithTheme} from "../../../ui/src/test-utils";
6
6
  import type {AdminApi} from "../types";
7
7
 
8
- const pushMock = mock(() => {});
8
+ const pushMock = mock((_href: unknown) => {});
9
9
  mock.module("expo-router", () => ({
10
10
  router: {push: pushMock, replace: mock(() => {})},
11
11
  useLocalSearchParams: () => ({}),
@@ -162,7 +162,7 @@ describe("JobsDashboardScreen", () => {
162
162
  schedulesState.data = [
163
163
  {cron: "0 0 * * *", enabled: true, id: "sched-1", name: "nightly", timezone: "UTC"},
164
164
  ];
165
- const onFiltersChange = mock(() => {});
165
+ const onFiltersChange = mock((_next: unknown) => {});
166
166
  const {UNSAFE_root, getByTestId} = renderWithTheme(
167
167
  <JobsDashboardScreen
168
168
  api={createJobsApi()}
@@ -203,7 +203,7 @@ describe("JobsDashboardScreen", () => {
203
203
 
204
204
  it("pages through results without dropping the active filters", async () => {
205
205
  listState.data = {data: [deadRow], more: true, page: 1, total: 60};
206
- const onFiltersChange = mock(() => {});
206
+ const onFiltersChange = mock((_next: unknown) => {});
207
207
  const {getByTestId} = renderWithTheme(
208
208
  <JobsDashboardScreen
209
209
  api={createJobsApi()}
@@ -5,7 +5,7 @@ import React from "react";
5
5
  import {renderWithTheme} from "../../../ui/src/test-utils";
6
6
  import type {AdminApi, AdminConfigResponse} from "../types";
7
7
 
8
- const pushMock = mock(() => {});
8
+ const pushMock = mock((_href: unknown) => {});
9
9
  mock.module("expo-router", () => ({
10
10
  router: {push: pushMock, replace: mock(() => {})},
11
11
  }));
@@ -4,7 +4,7 @@ import React from "react";
4
4
  import {renderWithTheme} from "../../../ui/src/test-utils";
5
5
  import type {AdminApi} from "../types";
6
6
 
7
- const pushMock = mock(() => {});
7
+ const pushMock = mock((_href: unknown) => {});
8
8
  mock.module("expo-router", () => ({
9
9
  router: {push: pushMock, replace: mock(() => {})},
10
10
  }));