@terreno/admin-frontend 57.2.0 → 57.3.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 (115) hide show
  1. package/.ai/guidelines/core.md +10 -7
  2. package/README.md +2 -0
  3. package/dist/AdminScreenPage.d.ts +18 -0
  4. package/dist/AdminScreenPage.js +35 -0
  5. package/dist/AdminScreenPage.js.map +1 -0
  6. package/dist/AdminScreenRouter.js +4 -3
  7. package/dist/AdminScreenRouter.js.map +1 -1
  8. package/dist/DocumentStorageBrowser.js +4 -3
  9. package/dist/DocumentStorageBrowser.js.map +1 -1
  10. package/dist/comms/CommsDashboardScreen.d.ts +10 -0
  11. package/dist/comms/CommsDashboardScreen.js +183 -0
  12. package/dist/comms/CommsDashboardScreen.js.map +1 -0
  13. package/dist/comms/CommsDashboardScreenWidget.d.ts +4 -0
  14. package/dist/comms/CommsDashboardScreenWidget.js +11 -0
  15. package/dist/comms/CommsDashboardScreenWidget.js.map +1 -0
  16. package/dist/comms/CommsMessageDetail.d.ts +8 -0
  17. package/dist/comms/CommsMessageDetail.js +50 -0
  18. package/dist/comms/CommsMessageDetail.js.map +1 -0
  19. package/dist/comms/CommsStatCard.d.ts +17 -0
  20. package/dist/comms/CommsStatCard.js +14 -0
  21. package/dist/comms/CommsStatCard.js.map +1 -0
  22. package/dist/comms/CommsStatusBadge.d.ts +5 -0
  23. package/dist/comms/CommsStatusBadge.js +14 -0
  24. package/dist/comms/CommsStatusBadge.js.map +1 -0
  25. package/dist/comms/commsDashboardParams.d.ts +17 -0
  26. package/dist/comms/commsDashboardParams.js +71 -0
  27. package/dist/comms/commsDashboardParams.js.map +1 -0
  28. package/dist/comms/commsMessagePayload.d.ts +49 -0
  29. package/dist/comms/commsMessagePayload.js +43 -0
  30. package/dist/comms/commsMessagePayload.js.map +1 -0
  31. package/dist/comms/commsRetrySummary.d.ts +4 -0
  32. package/dist/comms/commsRetrySummary.js +12 -0
  33. package/dist/comms/commsRetrySummary.js.map +1 -0
  34. package/dist/comms/useCommsDashboardApi.d.ts +78 -0
  35. package/dist/comms/useCommsDashboardApi.js +60 -0
  36. package/dist/comms/useCommsDashboardApi.js.map +1 -0
  37. package/dist/comms/useCommsDashboardUrlFilters.d.ts +5 -0
  38. package/dist/comms/useCommsDashboardUrlFilters.js +16 -0
  39. package/dist/comms/useCommsDashboardUrlFilters.js.map +1 -0
  40. package/dist/index.d.ts +7 -0
  41. package/dist/index.js +7 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/types.d.ts +2 -0
  44. package/dist/useAdminBackgroundTask.d.ts +10 -2
  45. package/dist/useAdminBackgroundTask.js.map +1 -1
  46. package/dist/useConfigurationApi.d.ts +13 -15
  47. package/dist/useConfigurationApi.js.map +1 -1
  48. package/dist/widgets/AIRequestsScreenWidget.js +4 -3
  49. package/dist/widgets/AIRequestsScreenWidget.js.map +1 -1
  50. package/dist/widgets/DocumentsScreenWidget.js +2 -2
  51. package/dist/widgets/DocumentsScreenWidget.js.map +1 -1
  52. package/dist/widgets/builtInWidgets.js +2 -1
  53. package/dist/widgets/builtInWidgets.js.map +1 -1
  54. package/package.json +17 -3
  55. package/src/AdminActionMenu.test.tsx +1 -1
  56. package/src/AdminBreadcrumbs.test.tsx +1 -1
  57. package/src/AdminFieldRenderer.test.tsx +6 -1
  58. package/src/AdminHome.test.tsx +1 -1
  59. package/src/AdminModelForm.test.tsx +1 -1
  60. package/src/AdminModelList.test.tsx +1 -1
  61. package/src/AdminModelTable.test.tsx +1 -1
  62. package/src/AdminPrimitiveArrayField.test.tsx +1 -1
  63. package/src/AdminRolesList.test.tsx +1 -1
  64. package/src/AdminScreenPage.test.tsx +81 -0
  65. package/src/AdminScreenPage.tsx +37 -0
  66. package/src/AdminScreenRouter.test.tsx +2 -1
  67. package/src/AdminScreenRouter.tsx +18 -5
  68. package/src/AdminScriptList.test.tsx +1 -1
  69. package/src/AdminShell.test.tsx +1 -1
  70. package/src/AdminVersionConfig.test.tsx +1 -1
  71. package/src/CheckboxListEditor.test.tsx +1 -1
  72. package/src/ConfigurationScreen.test.tsx +1 -1
  73. package/src/ConsentFormEditor.test.tsx +1 -1
  74. package/src/ConsentFormList.test.tsx +1 -1
  75. package/src/ConsentHistory.test.tsx +1 -1
  76. package/src/ConsentResponseViewer.test.tsx +1 -1
  77. package/src/DocumentStorageBrowser.test.tsx +1 -1
  78. package/src/DocumentStorageBrowser.tsx +10 -3
  79. package/src/LocaleContentEditor.test.tsx +1 -1
  80. package/src/adminModelListQueryParams.test.ts +59 -0
  81. package/src/comms/CommsDashboardScreen.test.tsx +397 -0
  82. package/src/comms/CommsDashboardScreen.tsx +500 -0
  83. package/src/comms/CommsDashboardScreenWidget.test.tsx +62 -0
  84. package/src/comms/CommsDashboardScreenWidget.tsx +20 -0
  85. package/src/comms/CommsMessageDetail.test.tsx +245 -0
  86. package/src/comms/CommsMessageDetail.tsx +239 -0
  87. package/src/comms/CommsStatCard.test.tsx +69 -0
  88. package/src/comms/CommsStatCard.tsx +60 -0
  89. package/src/comms/CommsStatusBadge.tsx +14 -0
  90. package/src/comms/commsDashboardParams.test.ts +75 -0
  91. package/src/comms/commsDashboardParams.ts +91 -0
  92. package/src/comms/commsMessagePayload.test.ts +22 -0
  93. package/src/comms/commsMessagePayload.ts +83 -0
  94. package/src/comms/commsRetrySummary.ts +10 -0
  95. package/src/comms/useCommsDashboardApi.test.tsx +144 -0
  96. package/src/comms/useCommsDashboardApi.tsx +128 -0
  97. package/src/comms/useCommsDashboardUrlFilters.test.tsx +58 -0
  98. package/src/comms/useCommsDashboardUrlFilters.tsx +31 -0
  99. package/src/dynamicHookApi.ts +1 -1
  100. package/src/index.tsx +14 -0
  101. package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -1
  102. package/src/{AdminFilterDrawer.test.tsx → isolated/AdminFilterDrawer.isolated.tsx} +8 -2
  103. package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -1
  104. package/src/isolated/AdminObjectPicker.isolated.tsx +1 -1
  105. package/src/isolated/AdminRefField.isolated.tsx +1 -1
  106. package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -1
  107. package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -1
  108. package/src/isolated/hooks.isolated.tsx +1 -1
  109. package/src/types.ts +2 -0
  110. package/src/useAdminBackgroundTask.ts +7 -5
  111. package/src/useConfigurationApi.ts +13 -16
  112. package/src/widgets/AIRequestsScreenWidget.tsx +5 -4
  113. package/src/widgets/DocumentsScreenWidget.tsx +9 -2
  114. package/src/widgets/builtInWidgets.ts +2 -0
  115. package/src/widgets/pluginWidgets.test.tsx +3 -1
@@ -0,0 +1,75 @@
1
+ import {describe, expect, it} from "bun:test";
2
+ import {
3
+ parseCommsDashboardSearchParams,
4
+ serializeCommsDashboardSearchParams,
5
+ withDefaultCommsDashboardDates,
6
+ } from "./commsDashboardParams";
7
+ import {summarizeSkippedReasons} from "./commsRetrySummary";
8
+
9
+ describe("commsDashboardParams", () => {
10
+ it("round-trips filters through the URL query object", () => {
11
+ const filters = {
12
+ channel: "mail",
13
+ endDate: "2026-08-20T00:00:00.000Z",
14
+ errorClass: "transient",
15
+ page: 3,
16
+ provider: "sendgrid",
17
+ q: "timeout",
18
+ startDate: "2026-08-13T00:00:00.000Z",
19
+ status: "failed",
20
+ };
21
+ const serialized = serializeCommsDashboardSearchParams(filters);
22
+ expect(parseCommsDashboardSearchParams(serialized)).toEqual(filters);
23
+ });
24
+
25
+ it("fills a trailing seven-day range when both dates are omitted", () => {
26
+ const withDefaults = withDefaultCommsDashboardDates({status: "failed"});
27
+ expect(withDefaults.status).toBe("failed");
28
+ expect(withDefaults.startDate).toBeTruthy();
29
+ expect(withDefaults.endDate).toBeTruthy();
30
+ expect(withDefaultCommsDashboardDates({startDate: "2026-08-01T00:00:00.000Z"}).startDate).toBe(
31
+ "2026-08-01T00:00:00.000Z"
32
+ );
33
+ });
34
+
35
+ it("drops empty values and page 1 from the URL", () => {
36
+ expect(
37
+ serializeCommsDashboardSearchParams({
38
+ channel: "",
39
+ page: 1,
40
+ q: " ",
41
+ })
42
+ ).toEqual({});
43
+ });
44
+
45
+ it("reads the first value when expo-router supplies arrays", () => {
46
+ expect(
47
+ parseCommsDashboardSearchParams({
48
+ channel: ["sms", "mail"],
49
+ page: ["2"],
50
+ })
51
+ ).toEqual({
52
+ channel: "sms",
53
+ endDate: undefined,
54
+ errorClass: undefined,
55
+ page: 2,
56
+ provider: undefined,
57
+ q: undefined,
58
+ startDate: undefined,
59
+ status: undefined,
60
+ });
61
+ });
62
+ });
63
+
64
+ describe("summarizeSkippedReasons", () => {
65
+ it("groups skipped retry reasons for the result toast", () => {
66
+ expect(summarizeSkippedReasons([])).toBe("none skipped");
67
+ expect(
68
+ summarizeSkippedReasons([
69
+ {id: "a", reason: "Permanent failures cannot be retried"},
70
+ {id: "b", reason: "Permanent failures cannot be retried"},
71
+ {id: "c", reason: "Verification messages are not retryable"},
72
+ ])
73
+ ).toBe("2× Permanent failures cannot be retried; 1× Verification messages are not retryable");
74
+ });
75
+ });
@@ -0,0 +1,91 @@
1
+ import {DateTime} from "luxon";
2
+
3
+ export interface CommsDashboardFilters {
4
+ channel?: string;
5
+ endDate?: string;
6
+ errorClass?: string;
7
+ page?: number;
8
+ provider?: string;
9
+ q?: string;
10
+ startDate?: string;
11
+ status?: string;
12
+ }
13
+
14
+ const asString = (value: unknown): string | undefined => {
15
+ if (Array.isArray(value)) {
16
+ return asString(value[0]);
17
+ }
18
+ if (typeof value !== "string") {
19
+ return undefined;
20
+ }
21
+ const trimmed = value.trim();
22
+ return trimmed.length > 0 ? trimmed : undefined;
23
+ };
24
+
25
+ export const parseCommsDashboardSearchParams = (
26
+ params: Record<string, unknown>
27
+ ): CommsDashboardFilters => {
28
+ const pageValue = asString(params.page);
29
+ const page = pageValue ? Number.parseInt(pageValue, 10) : undefined;
30
+ return {
31
+ channel: asString(params.channel),
32
+ endDate: asString(params.endDate),
33
+ errorClass: asString(params.errorClass),
34
+ page: page && page > 0 ? page : undefined,
35
+ provider: asString(params.provider),
36
+ q: asString(params.q),
37
+ startDate: asString(params.startDate),
38
+ status: asString(params.status),
39
+ };
40
+ };
41
+
42
+ export const serializeCommsDashboardSearchParams = (
43
+ filters: CommsDashboardFilters
44
+ ): Record<string, string> => {
45
+ const params: Record<string, string> = {};
46
+ if (filters.channel) {
47
+ params.channel = filters.channel;
48
+ }
49
+ if (filters.provider) {
50
+ params.provider = filters.provider;
51
+ }
52
+ if (filters.status) {
53
+ params.status = filters.status;
54
+ }
55
+ if (filters.errorClass) {
56
+ params.errorClass = filters.errorClass;
57
+ }
58
+ if (filters.q?.trim()) {
59
+ params.q = filters.q.trim();
60
+ }
61
+ if (filters.startDate) {
62
+ params.startDate = filters.startDate;
63
+ }
64
+ if (filters.endDate) {
65
+ params.endDate = filters.endDate;
66
+ }
67
+ if (filters.page && filters.page > 1) {
68
+ params.page = String(filters.page);
69
+ }
70
+ return params;
71
+ };
72
+
73
+ const DEFAULT_STATS_DAYS = 7;
74
+
75
+ export const defaultCommsDashboardDateRange = (): {endDate: string; startDate: string} => {
76
+ const endDate = DateTime.utc();
77
+ const startDate = endDate.minus({days: DEFAULT_STATS_DAYS});
78
+ return {
79
+ endDate: endDate.toISO() ?? "",
80
+ startDate: startDate.toISO() ?? "",
81
+ };
82
+ };
83
+
84
+ export const withDefaultCommsDashboardDates = (
85
+ filters: CommsDashboardFilters
86
+ ): CommsDashboardFilters => {
87
+ if (filters.startDate || filters.endDate) {
88
+ return filters;
89
+ }
90
+ return {...filters, ...defaultCommsDashboardDateRange()};
91
+ };
@@ -0,0 +1,22 @@
1
+ import {describe, it} from "bun:test";
2
+ import {assert} from "chai";
3
+ import {DateTime} from "luxon";
4
+ import {formatCommsTimestamp} from "./commsMessagePayload";
5
+
6
+ describe("formatCommsTimestamp", () => {
7
+ it("prints a valid ISO timestamp in the local locale", () => {
8
+ const value = "2026-08-20T00:00:00.000Z";
9
+ const expected = DateTime.fromISO(value).toLocal().toLocaleString(DateTime.DATETIME_MED);
10
+ assert.equal(formatCommsTimestamp({value}), expected);
11
+ assert.notInclude(formatCommsTimestamp({value}), "T00:00:00");
12
+ });
13
+
14
+ it("returns the empty fallback when the value is missing", () => {
15
+ assert.equal(formatCommsTimestamp({empty: "—"}), "—");
16
+ assert.equal(formatCommsTimestamp({}), "");
17
+ });
18
+
19
+ it("keeps an unparseable string so a bad provider clock still shows", () => {
20
+ assert.equal(formatCommsTimestamp({value: "not-a-timestamp"}), "not-a-timestamp");
21
+ });
22
+ });
@@ -0,0 +1,83 @@
1
+ import {DateTime} from "luxon";
2
+
3
+ export interface CommsMessageAttempt {
4
+ at?: string;
5
+ error?: string;
6
+ errorClass?: string;
7
+ errorCode?: string;
8
+ provider?: string;
9
+ providerMessageId?: string;
10
+ }
11
+
12
+ export interface CommsMessageRow {
13
+ _id?: string;
14
+ attemptCount?: number;
15
+ attempts?: CommsMessageAttempt[];
16
+ channel: string;
17
+ created?: string;
18
+ error?: string;
19
+ errorClass?: string;
20
+ errorCode?: string;
21
+ id?: string;
22
+ metadata?: Record<string, unknown>;
23
+ payload?: unknown;
24
+ provider: string;
25
+ retriedById?: string;
26
+ retriedFromId?: string;
27
+ retryDisabledReason?: string;
28
+ retryable?: boolean;
29
+ retries?: CommsMessageRow[];
30
+ status: string;
31
+ subject?: string;
32
+ templateId?: string;
33
+ to: string;
34
+ userId?: string;
35
+ }
36
+
37
+ /**
38
+ * Reads a message row out of a dashboard response.
39
+ *
40
+ * Hosts differ in how they unwrap responses: the example app's Better Auth base query
41
+ * strips `{data}` envelopes unless the body carries `more`, so detail and retry hooks
42
+ * yield the row itself while list responses stay wrapped. Accept both shapes.
43
+ */
44
+ export const unwrapCommsMessage = (payload: unknown): CommsMessageRow | undefined => {
45
+ if (!payload || typeof payload !== "object") {
46
+ return undefined;
47
+ }
48
+ const record = payload as Record<string, unknown>;
49
+ if (record.data && typeof record.data === "object" && !Array.isArray(record.data)) {
50
+ return unwrapCommsMessage(record.data);
51
+ }
52
+ const rawId = record._id ?? record.id;
53
+ const id = typeof rawId === "string" ? rawId : rawId != null ? String(rawId) : "";
54
+ if (id.length === 0) {
55
+ return undefined;
56
+ }
57
+ return {...record, _id: id} as CommsMessageRow;
58
+ };
59
+
60
+ export const commsMessageId = (row: CommsMessageRow): string => {
61
+ return row._id ?? row.id ?? "";
62
+ };
63
+
64
+ /**
65
+ * Prints a comms timestamp for operators. Invalid or missing values stay as-is so a
66
+ * bad provider clock does not blank the cell.
67
+ */
68
+ export const formatCommsTimestamp = ({
69
+ empty = "",
70
+ value,
71
+ }: {
72
+ empty?: string;
73
+ value?: string;
74
+ }): string => {
75
+ if (!value) {
76
+ return empty;
77
+ }
78
+ const parsed = DateTime.fromISO(value);
79
+ if (!parsed.isValid) {
80
+ return value;
81
+ }
82
+ return parsed.toLocal().toLocaleString(DateTime.DATETIME_MED);
83
+ };
@@ -0,0 +1,10 @@
1
+ export const summarizeSkippedReasons = (skipped: Array<{id: string; reason: string}>): string => {
2
+ if (skipped.length === 0) {
3
+ return "none skipped";
4
+ }
5
+ const counts = new Map<string, number>();
6
+ for (const row of skipped) {
7
+ counts.set(row.reason, (counts.get(row.reason) ?? 0) + 1);
8
+ }
9
+ return [...counts.entries()].map(([reason, count]) => `${count}× ${reason}`).join("; ");
10
+ };
@@ -0,0 +1,144 @@
1
+ import {describe, expect, it, mock} from "bun:test";
2
+ import {renderHook} from "@testing-library/react-native";
3
+ import type {AdminApi, EndpointBuilder} from "../types";
4
+ import {commsMessageId, unwrapCommsMessage} from "./commsMessagePayload";
5
+ import {useCommsDashboardApi} from "./useCommsDashboardApi";
6
+
7
+ interface CapturedQuery {
8
+ body?: Record<string, unknown>;
9
+ method: string;
10
+ params?: Record<string, unknown>;
11
+ url: string;
12
+ }
13
+
14
+ interface CapturedEndpoint {
15
+ invalidatesTags?: string[];
16
+ providesTags?: unknown;
17
+ query: (arg: never) => CapturedQuery;
18
+ }
19
+
20
+ /**
21
+ * Stands in for the host RTK Query API. `injectEndpoints` is invoked eagerly so the
22
+ * endpoint definitions can be asserted, then hook names are returned the way RTK Query
23
+ * generates them from endpoint keys.
24
+ */
25
+ const createApiDouble = (): {
26
+ addTagTypes: string[][];
27
+ api: AdminApi;
28
+ endpoints: Record<string, CapturedEndpoint>;
29
+ } => {
30
+ const endpoints: Record<string, CapturedEndpoint> = {};
31
+ const addTagTypes: string[][] = [];
32
+ const api = {
33
+ enhanceEndpoints: ({addTagTypes: tags}: {addTagTypes: string[]}) => {
34
+ addTagTypes.push(tags);
35
+ return api;
36
+ },
37
+ injectEndpoints: ({
38
+ endpoints: build,
39
+ }: {
40
+ endpoints: (builder: EndpointBuilder) => Record<string, CapturedEndpoint>;
41
+ }) => {
42
+ const builder = {
43
+ mutation: (spec: CapturedEndpoint) => spec,
44
+ query: (spec: CapturedEndpoint) => spec,
45
+ } as unknown as EndpointBuilder;
46
+ Object.assign(endpoints, build(builder));
47
+ return {
48
+ useCommsDashboardDetailQuery: mock(() => ({isLoading: false})),
49
+ useCommsDashboardListQuery: mock(() => ({isLoading: false})),
50
+ useCommsDashboardRetryManyMutation: mock(() => [mock(() => ({})), {isLoading: false}]),
51
+ useCommsDashboardRetryMutation: mock(() => [mock(() => ({})), {isLoading: false}]),
52
+ useCommsDashboardStatsQuery: mock(() => ({isLoading: false})),
53
+ };
54
+ },
55
+ } as unknown as AdminApi & {injectEndpoints: unknown};
56
+ return {addTagTypes, api: api as AdminApi, endpoints};
57
+ };
58
+
59
+ describe("useCommsDashboardApi", () => {
60
+ it("injects every dashboard endpoint against the comms base path", () => {
61
+ const {addTagTypes, api, endpoints} = createApiDouble();
62
+ const {result} = renderHook(() => useCommsDashboardApi(api));
63
+
64
+ expect(addTagTypes[0]).toEqual(["commsMessages"]);
65
+ expect(endpoints.commsDashboardList.query({} as never)).toEqual({
66
+ method: "GET",
67
+ params: {},
68
+ url: "/comms/messages",
69
+ });
70
+ expect(endpoints.commsDashboardDetail.query("m1" as never)).toEqual({
71
+ method: "GET",
72
+ url: "/comms/messages/m1",
73
+ });
74
+ expect(endpoints.commsDashboardRetry.query("m1" as never)).toEqual({
75
+ method: "POST",
76
+ url: "/comms/messages/m1/retry",
77
+ });
78
+ expect(endpoints.commsDashboardRetryMany.query({limit: 5} as never)).toEqual({
79
+ body: {limit: 5},
80
+ method: "POST",
81
+ url: "/comms/messages/retryMany",
82
+ });
83
+ expect(endpoints.commsDashboardStats.query({} as never)).toEqual({
84
+ method: "GET",
85
+ params: {},
86
+ url: "/comms/stats",
87
+ });
88
+
89
+ expect(typeof result.current.useListQuery).toBe("function");
90
+ expect(typeof result.current.useDetailQuery).toBe("function");
91
+ expect(typeof result.current.useStatsQuery).toBe("function");
92
+ expect(typeof result.current.useRetryMutation).toBe("function");
93
+ expect(typeof result.current.useRetryManyMutation).toBe("function");
94
+ });
95
+
96
+ it("invalidates the collection on both retry mutations and tags detail reads by id", () => {
97
+ const {api, endpoints} = createApiDouble();
98
+ renderHook(() => useCommsDashboardApi(api));
99
+
100
+ expect(endpoints.commsDashboardRetry.invalidatesTags).toEqual(["commsMessages"]);
101
+ expect(endpoints.commsDashboardRetryMany.invalidatesTags).toEqual(["commsMessages"]);
102
+ expect(endpoints.commsDashboardList.providesTags).toEqual(["commsMessages"]);
103
+ expect(endpoints.commsDashboardStats.providesTags).toEqual(["commsMessages"]);
104
+
105
+ const providesTags = endpoints.commsDashboardDetail.providesTags as (
106
+ result: unknown,
107
+ error: unknown,
108
+ id: string
109
+ ) => unknown;
110
+ expect(providesTags(undefined, undefined, "m1")).toEqual([{id: "m1", type: "commsMessages"}]);
111
+ });
112
+ });
113
+
114
+ describe("unwrapCommsMessage", () => {
115
+ it("reads the row out of a {data} envelope or an already-unwrapped row", () => {
116
+ expect(unwrapCommsMessage({_id: "a"})?._id).toBe("a");
117
+ expect(unwrapCommsMessage({data: {_id: "b"}})?._id).toBe("b");
118
+ expect(unwrapCommsMessage({data: {data: {id: "c"}}})?._id).toBe("c");
119
+ });
120
+
121
+ it("normalizes a non-string id", () => {
122
+ expect(unwrapCommsMessage({id: 42})?._id).toBe("42");
123
+ });
124
+
125
+ it("returns undefined for payloads without an id", () => {
126
+ expect(unwrapCommsMessage(undefined)).toBeUndefined();
127
+ expect(unwrapCommsMessage("row")).toBeUndefined();
128
+ expect(unwrapCommsMessage({status: "failed"})).toBeUndefined();
129
+ expect(unwrapCommsMessage({_id: ""})).toBeUndefined();
130
+ expect(unwrapCommsMessage({data: []})).toBeUndefined();
131
+ });
132
+ });
133
+
134
+ describe("commsMessageId", () => {
135
+ it("prefers _id, falls back to id, and degrades to an empty string", () => {
136
+ expect(
137
+ commsMessageId({_id: "a", channel: "mail", provider: "p", status: "failed", to: "t"})
138
+ ).toBe("a");
139
+ expect(
140
+ commsMessageId({channel: "mail", id: "b", provider: "p", status: "failed", to: "t"})
141
+ ).toBe("b");
142
+ expect(commsMessageId({channel: "mail", provider: "p", status: "failed", to: "t"})).toBe("");
143
+ });
144
+ });
@@ -0,0 +1,128 @@
1
+ import {useMemo} from "react";
2
+ import {asDynamicHookApi} from "../dynamicHookApi";
3
+ import type {AdminApi, EndpointBuilder} from "../types";
4
+ import type {CommsDashboardFilters} from "./commsDashboardParams";
5
+ import type {CommsMessageRow} from "./commsMessagePayload";
6
+
7
+ export type {CommsMessageAttempt, CommsMessageRow} from "./commsMessagePayload";
8
+
9
+ export interface CommsListResponse {
10
+ data: CommsMessageRow[];
11
+ limit: number;
12
+ more: boolean;
13
+ page: number;
14
+ total: number;
15
+ }
16
+
17
+ export interface CommsStatsResponse {
18
+ buckets: Array<{channel: string; count: number; day: string; provider: string; status: string}>;
19
+ byProvider: Array<{
20
+ bounced: number;
21
+ delivered: number;
22
+ failed: number;
23
+ failureRate: number;
24
+ provider: string;
25
+ sent: number;
26
+ total: number;
27
+ }>;
28
+ totals: {
29
+ bounced: number;
30
+ cancelled: number;
31
+ delivered: number;
32
+ failed: number;
33
+ failureRate: number;
34
+ sent: number;
35
+ total: number;
36
+ };
37
+ }
38
+
39
+ export interface CommsRetryManyResponse {
40
+ retried: CommsMessageRow[];
41
+ skipped: Array<{id: string; reason: string}>;
42
+ }
43
+
44
+ const LIST_KEY = "commsDashboardList";
45
+ const DETAIL_KEY = "commsDashboardDetail";
46
+ const STATS_KEY = "commsDashboardStats";
47
+ const RETRY_KEY = "commsDashboardRetry";
48
+ const RETRY_MANY_KEY = "commsDashboardRetryMany";
49
+
50
+ export const useCommsDashboardApi = (api: AdminApi) => {
51
+ const enhancedApi = useMemo(
52
+ () =>
53
+ api.enhanceEndpoints({addTagTypes: ["commsMessages"]}).injectEndpoints({
54
+ endpoints: (build: EndpointBuilder) => ({
55
+ [DETAIL_KEY]: build.query({
56
+ providesTags: (_result: unknown, _error: unknown, id: string) => [
57
+ {id, type: "commsMessages"},
58
+ ],
59
+ query: (id: string) => ({method: "GET", url: `/comms/messages/${id}`}),
60
+ }),
61
+ [LIST_KEY]: build.query({
62
+ providesTags: ["commsMessages"],
63
+ query: (params: Record<string, unknown>) => ({
64
+ method: "GET",
65
+ params,
66
+ url: "/comms/messages",
67
+ }),
68
+ }),
69
+ [RETRY_KEY]: build.mutation({
70
+ invalidatesTags: ["commsMessages"],
71
+ query: (id: string) => ({
72
+ method: "POST",
73
+ url: `/comms/messages/${id}/retry`,
74
+ }),
75
+ }),
76
+ [RETRY_MANY_KEY]: build.mutation({
77
+ invalidatesTags: ["commsMessages"],
78
+ query: (body: Record<string, unknown>) => ({
79
+ body,
80
+ method: "POST",
81
+ url: "/comms/messages/retryMany",
82
+ }),
83
+ }),
84
+ [STATS_KEY]: build.query({
85
+ providesTags: ["commsMessages"],
86
+ query: (params: Record<string, unknown>) => ({
87
+ method: "GET",
88
+ params,
89
+ url: "/comms/stats",
90
+ }),
91
+ }),
92
+ }),
93
+ overrideExisting: true,
94
+ }),
95
+ [api]
96
+ );
97
+
98
+ const hooks = asDynamicHookApi(enhancedApi);
99
+ return {
100
+ useDetailQuery: hooks.useCommsDashboardDetailQuery as (id: string) => {
101
+ data?: CommsMessageRow | {data: CommsMessageRow};
102
+ error?: unknown;
103
+ isLoading: boolean;
104
+ },
105
+ useListQuery: hooks.useCommsDashboardListQuery as (
106
+ params: CommsDashboardFilters & {
107
+ limit?: number;
108
+ }
109
+ ) => {
110
+ data?: CommsListResponse;
111
+ error?: unknown;
112
+ isLoading: boolean;
113
+ },
114
+ useRetryManyMutation: hooks.useCommsDashboardRetryManyMutation as () => [
115
+ (body: Record<string, unknown>) => {unwrap: () => Promise<CommsRetryManyResponse>},
116
+ {isLoading: boolean},
117
+ ],
118
+ useRetryMutation: hooks.useCommsDashboardRetryMutation as () => [
119
+ (id: string) => {unwrap: () => Promise<CommsMessageRow | {data: CommsMessageRow}>},
120
+ {isLoading: boolean},
121
+ ],
122
+ useStatsQuery: hooks.useCommsDashboardStatsQuery as (params: CommsDashboardFilters) => {
123
+ data?: CommsStatsResponse;
124
+ error?: unknown;
125
+ isLoading: boolean;
126
+ },
127
+ };
128
+ };
@@ -0,0 +1,58 @@
1
+ import {beforeEach, describe, expect, it, mock} from "bun:test";
2
+ import {renderHook} from "@testing-library/react-native";
3
+
4
+ const replaceMock = mock((_href: string) => {});
5
+ let searchParams: Record<string, unknown> = {};
6
+
7
+ mock.module("expo-router", () => ({
8
+ router: {push: mock(() => {}), replace: replaceMock},
9
+ useLocalSearchParams: () => searchParams,
10
+ }));
11
+
12
+ import {useCommsDashboardUrlFilters} from "./useCommsDashboardUrlFilters";
13
+
14
+ const lastHref = (): string => String(replaceMock.mock.calls.at(-1)?.[0] ?? "");
15
+
16
+ describe("useCommsDashboardUrlFilters", () => {
17
+ beforeEach(() => {
18
+ searchParams = {};
19
+ replaceMock.mockClear();
20
+ });
21
+
22
+ it("parses the current query into filters", () => {
23
+ searchParams = {channel: "mail", page: "2", q: "timeout"};
24
+ const {result} = renderHook(() => useCommsDashboardUrlFilters("/admin"));
25
+ expect(result.current.filters).toEqual({
26
+ channel: "mail",
27
+ endDate: undefined,
28
+ errorClass: undefined,
29
+ page: 2,
30
+ provider: undefined,
31
+ q: "timeout",
32
+ startDate: undefined,
33
+ status: undefined,
34
+ });
35
+ });
36
+
37
+ it("writes filters back onto the route as a query string", () => {
38
+ const {result} = renderHook(() => useCommsDashboardUrlFilters("/admin"));
39
+ result.current.onFiltersChange({channel: "sms", page: 3, status: "failed"});
40
+ const href = lastHref();
41
+ expect(href.startsWith("/admin/comms?")).toBe(true);
42
+ expect(href).toContain("channel=sms");
43
+ expect(href).toContain("status=failed");
44
+ expect(href).toContain("page=3");
45
+ });
46
+
47
+ it("drops the query entirely when no filters remain", () => {
48
+ const {result} = renderHook(() => useCommsDashboardUrlFilters("/admin"));
49
+ result.current.onFiltersChange({page: 1});
50
+ expect(lastHref()).toBe("/admin/comms");
51
+ });
52
+
53
+ it("defaults to a root-relative route when the host has no route base", () => {
54
+ const {result} = renderHook(() => useCommsDashboardUrlFilters());
55
+ result.current.onFiltersChange({});
56
+ expect(lastHref()).toBe("/comms");
57
+ });
58
+ });
@@ -0,0 +1,31 @@
1
+ import type {Href} from "expo-router";
2
+ import {router, useLocalSearchParams} from "expo-router";
3
+ import {useCallback, useMemo} from "react";
4
+ import {
5
+ type CommsDashboardFilters,
6
+ parseCommsDashboardSearchParams,
7
+ serializeCommsDashboardSearchParams,
8
+ } from "./commsDashboardParams";
9
+
10
+ export const useCommsDashboardUrlFilters = (
11
+ routeBase?: string
12
+ ): {
13
+ filters: CommsDashboardFilters;
14
+ onFiltersChange: (next: CommsDashboardFilters) => void;
15
+ } => {
16
+ const params = useLocalSearchParams();
17
+ const filters = useMemo(() => parseCommsDashboardSearchParams(params), [params]);
18
+ const base = routeBase ?? "";
19
+
20
+ const onFiltersChange = useCallback(
21
+ (next: CommsDashboardFilters): void => {
22
+ const serialized = serializeCommsDashboardSearchParams(next);
23
+ const query = new URLSearchParams(serialized).toString();
24
+ const path = `${base}/comms`;
25
+ router.replace((query ? `${path}?${query}` : path) as Href);
26
+ },
27
+ [base]
28
+ );
29
+
30
+ return {filters, onFiltersChange};
31
+ };
@@ -2,7 +2,7 @@
2
2
  * RTK Query APIs after dynamic `injectEndpoints` expose hooks as string-keyed properties.
3
3
  * Hook names are generated at runtime from endpoint keys and are not statically expressible.
4
4
  */
5
- // noExplicitAny: RTK Query generates hook names dynamically from injectEndpoints keys
5
+ // noExplicitAny: injectEndpoints adds hook properties at runtime; Record<string, unknown> makes every hook `unknown` and breaks all admin call sites that invoke them without casts
6
6
  // biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
7
7
  export type DynamicHookApi = Record<string, any>;
8
8
 
package/src/index.tsx CHANGED
@@ -22,6 +22,7 @@ export {
22
22
  export {AdminRefField, type AdminRefFieldProps} from "./AdminRefField";
23
23
  export {AdminRolesField} from "./AdminRolesField";
24
24
  export {AdminRolesList} from "./AdminRolesList";
25
+ export {AdminScreenPage, type AdminScreenPageProps} from "./AdminScreenPage";
25
26
  export {AdminScreenRouter, type AdminScreenRouterProps} from "./AdminScreenRouter";
26
27
  export {AdminScriptList} from "./AdminScriptList";
27
28
  export {AdminScriptRunModal} from "./AdminScriptRunModal";
@@ -37,6 +38,19 @@ export {ConsentFormList} from "./ConsentFormList";
37
38
  export {ConsentHistory} from "./ConsentHistory";
38
39
  export {ConsentResponseViewer} from "./ConsentResponseViewer";
39
40
  export {ADMIN_FILTER_MOBILE_BREAKPOINT, ADMIN_SEARCH_DEBOUNCE_MS} from "./Constants";
41
+ export {CommsDashboardScreen, type CommsDashboardScreenProps} from "./comms/CommsDashboardScreen";
42
+ export {
43
+ COMMS_ADMIN_WIDGETS,
44
+ CommsDashboardScreenWidget,
45
+ } from "./comms/CommsDashboardScreenWidget";
46
+ export {CommsMessageDetail, type CommsMessageDetailProps} from "./comms/CommsMessageDetail";
47
+ export {CommsStatCard, type CommsStatCardProps} from "./comms/CommsStatCard";
48
+ export {CommsStatusBadge} from "./comms/CommsStatusBadge";
49
+ export {
50
+ type CommsDashboardFilters,
51
+ parseCommsDashboardSearchParams,
52
+ serializeCommsDashboardSearchParams,
53
+ } from "./comms/commsDashboardParams";
40
54
  export {DocumentStorageBrowser} from "./DocumentStorageBrowser";
41
55
  export {generateConsentHistoryPdf} from "./generateConsentHistoryPdf";
42
56
  export {LocaleContentEditor} from "./LocaleContentEditor";