create-expo-updates-server 0.4.0 → 0.6.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 (175) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +4 -9
  4. package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
  5. package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
  6. package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
  7. package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
  8. package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
  9. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
  10. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
  11. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
  13. package/dist/template/app/api/admin/updates/route.test.ts +21 -0
  14. package/dist/template/app/api/admin/updates/route.ts +12 -1
  15. package/dist/template/app/globals.css +65 -68
  16. package/dist/template/app/login/page.tsx +66 -42
  17. package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
  18. package/dist/template/app/updates/devices/page.tsx +188 -152
  19. package/dist/template/app/updates/embedded/page.tsx +63 -29
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +381 -283
  23. package/dist/template/app/updates/releases.test.tsx +156 -0
  24. package/dist/template/components/admin/admin-role.ts +5 -0
  25. package/dist/template/components/admin/admin-shell.tsx +166 -101
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +25 -17
  28. package/dist/template/components/admin/release-badges.test.tsx +50 -0
  29. package/dist/template/components/admin/release-badges.tsx +101 -0
  30. package/dist/template/components/ui/alert.tsx +10 -3
  31. package/dist/template/components/ui/avatar.tsx +108 -0
  32. package/dist/template/components/ui/badge.tsx +2 -2
  33. package/dist/template/components/ui/breadcrumb.tsx +108 -0
  34. package/dist/template/components/ui/button.tsx +5 -5
  35. package/dist/template/components/ui/card.tsx +2 -2
  36. package/dist/template/components/ui/chart.tsx +1 -1
  37. package/dist/template/components/ui/collapsible.tsx +7 -0
  38. package/dist/template/components/ui/empty.tsx +103 -0
  39. package/dist/template/components/ui/field.tsx +248 -0
  40. package/dist/template/components/ui/input-group.tsx +170 -0
  41. package/dist/template/components/ui/input.tsx +1 -1
  42. package/dist/template/components/ui/native-select.tsx +1 -1
  43. package/dist/template/components/ui/radio-group.tsx +41 -0
  44. package/dist/template/components/ui/status-tones.ts +15 -0
  45. package/dist/template/components/ui/table.tsx +1 -1
  46. package/dist/template/components/ui/textarea.tsx +1 -1
  47. package/dist/template/docs/admin-ui.md +7 -3
  48. package/dist/template/docs/device-targeting.md +2 -7
  49. package/dist/template/docs/doctor.md +2 -2
  50. package/dist/template/docs/expo-app-setup.md +9 -27
  51. package/dist/template/docs/getting-started.md +3 -4
  52. package/dist/template/docs/installation-telemetry.md +2 -8
  53. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  54. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  55. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  56. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  57. package/dist/template/docs/migrations/schema.sql +349 -0
  58. package/dist/template/docs/npm-installer.md +3 -3
  59. package/dist/template/docs/operations-guide.md +8 -6
  60. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  61. package/dist/template/docs/ota-update-policy.md +9 -20
  62. package/dist/template/docs/ru/admin-ui.md +7 -3
  63. package/dist/template/docs/ru/device-targeting.md +2 -2
  64. package/dist/template/docs/ru/doctor.md +2 -2
  65. package/dist/template/docs/ru/expo-app-setup.md +9 -9
  66. package/dist/template/docs/ru/getting-started.md +3 -3
  67. package/dist/template/docs/ru/installation-telemetry.md +2 -2
  68. package/dist/template/docs/ru/npm-installer.md +3 -3
  69. package/dist/template/docs/ru/operations-guide.md +8 -3
  70. package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
  71. package/dist/template/docs/ru/ota-update-policy.md +9 -7
  72. package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
  73. package/dist/template/docs/uk/admin-ui.md +7 -3
  74. package/dist/template/docs/uk/device-targeting.md +2 -2
  75. package/dist/template/docs/uk/doctor.md +2 -2
  76. package/dist/template/docs/uk/expo-app-setup.md +9 -9
  77. package/dist/template/docs/uk/getting-started.md +3 -3
  78. package/dist/template/docs/uk/installation-telemetry.md +2 -2
  79. package/dist/template/docs/uk/npm-installer.md +3 -3
  80. package/dist/template/docs/uk/operations-guide.md +8 -3
  81. package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
  82. package/dist/template/docs/uk/ota-update-policy.md +9 -7
  83. package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
  84. package/dist/template/lib/audience-ids.ts +4 -0
  85. package/dist/template/package-lock.json +46 -0
  86. package/dist/template/package.json +3 -1
  87. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  88. package/dist/template/scripts/create-access-token.mjs +1 -1
  89. package/dist/template/scripts/lib/doctor.mjs +10 -7
  90. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  91. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  92. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  93. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  94. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  95. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  96. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  97. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  98. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  99. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  100. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  101. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  102. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  103. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  104. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  105. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  106. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  107. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  108. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  109. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  110. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  111. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  112. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  113. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  114. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  115. package/dist/template/src/client/admin-api.ts +45 -10
  116. package/dist/template/src/client/admin-types.ts +35 -1
  117. package/dist/template/src/client/devices/analytics.tsx +168 -231
  118. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  119. package/dist/template/src/client/devices/device-name.tsx +37 -23
  120. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  121. package/dist/template/src/client/devices/registry.tsx +258 -245
  122. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  123. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  124. package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
  125. package/dist/template/src/client/distribution-control.tsx +89 -57
  126. package/dist/template/src/client/distribution-history.tsx +353 -0
  127. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  128. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  129. package/dist/template/src/client/guard-action-combobox.tsx +133 -239
  130. package/dist/template/src/client/guard-action-options.ts +4 -6
  131. package/dist/template/src/client/i18n/en.json +133 -2
  132. package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
  133. package/dist/template/src/client/i18n/ru.json +133 -2
  134. package/dist/template/src/client/i18n/uk.json +133 -2
  135. package/dist/template/src/client/logout-button.tsx +3 -3
  136. package/dist/template/src/client/policy-draft.ts +138 -0
  137. package/dist/template/src/client/update-audience-editor.tsx +597 -206
  138. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  139. package/dist/template/src/client/update-policy-editor.tsx +454 -320
  140. package/dist/template/src/client/use-filtered-results.ts +55 -0
  141. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  142. package/dist/template/src/server/controllers/manifest.ts +15 -1
  143. package/dist/template/src/server/devices/audience.ts +9 -5
  144. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  145. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  146. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  147. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  148. package/dist/template/src/server/lib/supabase.js +24 -0
  149. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  150. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  151. package/dist/template/src/server/lib/update-policy.ts +23 -10
  152. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  153. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  154. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  155. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  156. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  157. package/dist/template/tsconfig.json +2 -2
  158. package/dist/template-manifest.json +446 -301
  159. package/package.json +1 -1
  160. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  161. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  162. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  163. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  164. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  165. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  166. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  167. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  168. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  169. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  170. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  171. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  172. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  173. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  174. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  175. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -0,0 +1,353 @@
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import { useEffect, useState } from "react";
5
+ import {
6
+ ArrowUpRight,
7
+ ChevronLeft,
8
+ ChevronRight,
9
+ CircleOff,
10
+ History,
11
+ Layers,
12
+ RotateCcw,
13
+ Search,
14
+ } from "lucide-react";
15
+ import { useConfirmAction } from "@/components/admin/confirm-action";
16
+ import { Alert, AlertDescription } from "@/components/ui/alert";
17
+ import { ChannelBadge, PlatformBadge } from "@/components/admin/release-badges";
18
+ import { Button } from "@/components/ui/button";
19
+ import {
20
+ Card,
21
+ CardDescription,
22
+ CardHeader,
23
+ CardTitle,
24
+ } from "@/components/ui/card";
25
+ import {
26
+ Empty,
27
+ EmptyDescription,
28
+ EmptyHeader,
29
+ EmptyMedia,
30
+ EmptyTitle,
31
+ } from "@/components/ui/empty";
32
+ import {
33
+ InputGroup,
34
+ InputGroupAddon,
35
+ InputGroupInput,
36
+ } from "@/components/ui/input-group";
37
+ import { Skeleton } from "@/components/ui/skeleton";
38
+ import {
39
+ AdminApiError,
40
+ getDistributionHistory,
41
+ restorePreviousRelease,
42
+ } from "./admin-api";
43
+ import type {
44
+ DistributionHistoryRelease,
45
+ DistributionHistoryResponse,
46
+ DistributionHistoryScope,
47
+ } from "./admin-types";
48
+ import type { TranslationMessage } from "./i18n/messages";
49
+ import { useI18n } from "./i18n/provider";
50
+ import { useFormatters } from "./i18n/use-formatters";
51
+
52
+ function ReleaseLink({ release }: { release: DistributionHistoryRelease }) {
53
+ const { t } = useI18n();
54
+ const { fullDate } = useFormatters();
55
+ return (
56
+ <div className="min-w-0">
57
+ <Link
58
+ href={"/updates/" + release.encodedKey}
59
+ className="inline-flex max-w-full items-baseline gap-1.5 rounded-sm text-sm font-medium hover:text-primary hover:underline focus-visible:outline-ring"
60
+ >
61
+ <span className="truncate">
62
+ {release.comment || release.appVersion || release.updateId}
63
+ </span>
64
+ <ArrowUpRight
65
+ aria-hidden="true"
66
+ className="size-3 shrink-0 self-center text-muted-foreground"
67
+ />
68
+ </Link>
69
+ <div className="mt-0.5 flex flex-wrap items-center gap-x-2 text-xs tabular-nums text-muted-foreground">
70
+ {release.appVersion && <span>v{release.appVersion}</span>}
71
+ <code>{release.updateId.slice(0, 8)}</code>
72
+ {release.activatedAt && (
73
+ <time dateTime={release.activatedAt} title={t("Activated at")}>
74
+ {fullDate(release.activatedAt)}
75
+ </time>
76
+ )}
77
+ </div>
78
+ </div>
79
+ );
80
+ }
81
+
82
+ const pageSize = 5;
83
+ export default function DistributionHistory({
84
+ revision,
85
+ blocked,
86
+ onRestored,
87
+ }: {
88
+ revision: number;
89
+ blocked: boolean;
90
+ onRestored: () => void;
91
+ }) {
92
+ const { t } = useI18n();
93
+ const confirm = useConfirmAction();
94
+ const [data, setData] = useState<DistributionHistoryResponse | null>(null);
95
+ const [filter, setFilter] = useState("");
96
+ const [page, setPage] = useState(0);
97
+ const [loadError, setLoadError] = useState("");
98
+ const [actionError, setActionError] = useState("");
99
+ const [notice, setNotice] = useState<TranslationMessage>("");
100
+ const [busy, setBusy] = useState(false);
101
+ const [retry, setRetry] = useState(0);
102
+ useEffect(() => {
103
+ const controller = new AbortController();
104
+ getDistributionHistory(controller.signal)
105
+ .then((value) => {
106
+ if (!controller.signal.aborted) {
107
+ setData(value);
108
+ setLoadError("");
109
+ }
110
+ })
111
+ .catch((err: Error) => {
112
+ if (!controller.signal.aborted)
113
+ setLoadError(err.message || "Unable to load delivery history.");
114
+ });
115
+ return () => controller.abort();
116
+ }, [revision, retry]);
117
+
118
+ async function restore(scope: DistributionHistoryScope) {
119
+ const target = scope.previous;
120
+ if (!target || blocked || busy) return;
121
+ const scopeName = [
122
+ scope.channel,
123
+ scope.platform,
124
+ scope.runtimeVersion,
125
+ ].join(" / ");
126
+ if (
127
+ !(await confirm(
128
+ t("Restore release"),
129
+ t("Resume public delivery of {0} in {1}?", [
130
+ target.comment || target.updateId,
131
+ scopeName,
132
+ ]),
133
+ true,
134
+ ))
135
+ )
136
+ return;
137
+ setBusy(true);
138
+ setActionError("");
139
+ setNotice("");
140
+ try {
141
+ await restorePreviousRelease(target.updateId, scope.revision);
142
+ setNotice({
143
+ key: "Restored {0} in {1}.",
144
+ values: [target.appVersion || target.updateId.slice(0, 8), scopeName],
145
+ });
146
+ onRestored();
147
+ } catch (err) {
148
+ setActionError(
149
+ err instanceof AdminApiError && err.status === 409
150
+ ? "Delivery changed. Review the refreshed scope before restoring."
151
+ : err instanceof Error
152
+ ? err.message
153
+ : "Could not restore release.",
154
+ );
155
+ setRetry((n) => n + 1);
156
+ } finally {
157
+ setBusy(false);
158
+ }
159
+ }
160
+
161
+ const query = filter.trim().toLowerCase();
162
+ const scopes = (data?.scopes || []).filter((scope) =>
163
+ [scope.channel, scope.runtimeVersion, scope.platform].some((v) =>
164
+ v.toLowerCase().includes(query),
165
+ ),
166
+ );
167
+ const pages = Math.ceil(scopes.length / pageSize);
168
+ const visiblePage = Math.min(page, Math.max(0, pages - 1));
169
+ return (
170
+ <Card
171
+ aria-labelledby="public-distribution"
172
+ className="min-w-0 gap-0 overflow-hidden py-0"
173
+ >
174
+ <CardHeader className="flex flex-wrap items-center justify-between gap-3 px-4 py-4 sm:px-5">
175
+ <div className="space-y-1">
176
+ <CardTitle
177
+ id="public-distribution"
178
+ className="flex items-center gap-2 text-base"
179
+ >
180
+ <History className="size-4 text-primary" aria-hidden="true" />
181
+ {t("Public delivery")}
182
+ </CardTitle>
183
+ <CardDescription>
184
+ {t(
185
+ "Current and previous releases served to all devices in each scope.",
186
+ )}
187
+ </CardDescription>
188
+ </div>
189
+ {(data?.scopes.length ?? 0) > 0 && (
190
+ <InputGroup className="w-full sm:w-52">
191
+ <InputGroupAddon>
192
+ <Search />
193
+ </InputGroupAddon>
194
+ <InputGroupInput
195
+ aria-label={t("Find a delivery scope")}
196
+ placeholder={t("Find a delivery scope")}
197
+ value={filter}
198
+ onChange={(e) => {
199
+ setFilter(e.target.value);
200
+ setPage(0);
201
+ }}
202
+ />
203
+ </InputGroup>
204
+ )}
205
+ </CardHeader>
206
+ {loadError && (
207
+ <Alert variant="destructive" className="rounded-none">
208
+ <AlertDescription>
209
+ {t(loadError)}
210
+ <Button
211
+ size="sm"
212
+ variant="outline"
213
+ onClick={() => setRetry((n) => n + 1)}
214
+ >
215
+ {t("Retry")}
216
+ </Button>
217
+ </AlertDescription>
218
+ </Alert>
219
+ )}
220
+ {actionError && (
221
+ <Alert variant="destructive" className="rounded-none">
222
+ <AlertDescription>{t(actionError)}</AlertDescription>
223
+ </Alert>
224
+ )}
225
+ {notice && (
226
+ <p role="status" className="border-t px-5 py-2 text-sm">
227
+ {t(notice)}
228
+ </p>
229
+ )}
230
+ {!data && !loadError && <Skeleton className="mx-5 mb-4 h-16" />}
231
+ {data && !scopes.length && (
232
+ <Empty className="gap-2 rounded-none border-t border-solid p-4 md:p-5">
233
+ <EmptyHeader>
234
+ <EmptyMedia variant="icon">
235
+ <Layers />
236
+ </EmptyMedia>
237
+ <EmptyTitle className="text-sm">
238
+ {t(
239
+ query ? "No matching scopes" : "No public release history yet",
240
+ )}
241
+ </EmptyTitle>
242
+ <EmptyDescription>
243
+ {t(
244
+ query
245
+ ? "Try another runtime, channel or platform."
246
+ : "Manually activate a release for all devices to start its history.",
247
+ )}
248
+ </EmptyDescription>
249
+ </EmptyHeader>
250
+ </Empty>
251
+ )}
252
+ {scopes.length > 0 && (
253
+ <div>
254
+ <div
255
+ aria-hidden="true"
256
+ className="hidden grid-cols-[1fr_1.15fr_1.15fr_auto] gap-4 border-y bg-muted/45 px-5 py-2 text-xs font-medium text-muted-foreground lg:grid"
257
+ >
258
+ <span>{t("Delivery scope")}</span>
259
+ <span>{t("Currently serving")}</span>
260
+ <span>{t("Previous public release")}</span>
261
+ <span className="w-24" />
262
+ </div>
263
+ {scopes
264
+ .slice(visiblePage * pageSize, (visiblePage + 1) * pageSize)
265
+ .map((scope) => (
266
+ <section
267
+ key={JSON.stringify([
268
+ scope.runtimeVersion,
269
+ scope.platform,
270
+ scope.channel,
271
+ ])}
272
+ aria-label={[
273
+ scope.channel,
274
+ scope.platform,
275
+ scope.runtimeVersion,
276
+ ].join(" / ")}
277
+ className="grid min-w-0 gap-3 border-t px-4 py-3.5 sm:px-5 lg:grid-cols-[1fr_1.15fr_1.15fr_auto] lg:items-center lg:gap-4 lg:first-of-type:border-t-0"
278
+ >
279
+ <div className="min-w-0">
280
+ <ChannelBadge channel={scope.channel} />
281
+ <div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">
282
+ <PlatformBadge platform={scope.platform} />
283
+ {t("Runtime {0}", [scope.runtimeVersion])}
284
+ </div>
285
+ </div>
286
+ <div className="min-w-0">
287
+ <div className="mb-1 text-xs text-muted-foreground lg:sr-only">
288
+ {t("Currently serving")}
289
+ </div>
290
+ {scope.current ? (
291
+ <ReleaseLink release={scope.current} />
292
+ ) : (
293
+ <span className="inline-flex items-center gap-1.5 text-sm text-muted-foreground">
294
+ <CircleOff className="size-3.5" />
295
+ {t("No active release")}
296
+ </span>
297
+ )}
298
+ </div>
299
+ <div className="min-w-0">
300
+ <div className="mb-1 text-xs text-muted-foreground lg:sr-only">
301
+ {t("Previous public release")}
302
+ </div>
303
+ {scope.previous ? (
304
+ <ReleaseLink release={scope.previous} />
305
+ ) : (
306
+ <span className="text-sm text-muted-foreground">
307
+ {t("No previous release")}
308
+ </span>
309
+ )}
310
+ </div>
311
+ <div className="lg:min-w-24 lg:text-right">
312
+ {scope.previous && data?.canWrite && (
313
+ <Button
314
+ variant="destructive"
315
+ size="sm"
316
+ disabled={blocked || busy || !!loadError}
317
+ onClick={() => void restore(scope)}
318
+ >
319
+ <RotateCcw />
320
+ {t("Restore")}
321
+ </Button>
322
+ )}
323
+ </div>
324
+ </section>
325
+ ))}
326
+ {pages > 1 && (
327
+ <div className="flex items-center justify-end gap-3 border-t px-4 py-2 text-xs text-muted-foreground">
328
+ <span>{t("Page {0} of {1}", [visiblePage + 1, pages])}</span>
329
+ <Button
330
+ variant="outline"
331
+ size="icon"
332
+ disabled={!visiblePage}
333
+ aria-label={t("Назад")}
334
+ onClick={() => setPage(visiblePage - 1)}
335
+ >
336
+ <ChevronLeft />
337
+ </Button>
338
+ <Button
339
+ variant="outline"
340
+ size="icon"
341
+ disabled={visiblePage + 1 >= pages}
342
+ aria-label={t("Вперёд")}
343
+ onClick={() => setPage(visiblePage + 1)}
344
+ >
345
+ <ChevronRight />
346
+ </Button>
347
+ </div>
348
+ )}
349
+ </div>
350
+ )}
351
+ </Card>
352
+ );
353
+ }
@@ -0,0 +1,183 @@
1
+ "use client";
2
+
3
+ import { useState, type FormEvent } from "react";
4
+ import { ChevronDown, Trash2 } from "lucide-react";
5
+ import { Button } from "@/components/ui/button";
6
+ import {
7
+ Collapsible,
8
+ CollapsibleContent,
9
+ CollapsibleTrigger,
10
+ } from "@/components/ui/collapsible";
11
+ import { Field, FieldLabel, FieldDescription } from "@/components/ui/field";
12
+ import { Input } from "@/components/ui/input";
13
+ import { useConfirmAction } from "@/components/admin/confirm-action";
14
+ import { createGuardAction, deleteGuardAction } from "./admin-api";
15
+ import type { GuardActionItem } from "./admin-types";
16
+ import {
17
+ filterGuardActionOptions,
18
+ normalizeCreatableGuardAction,
19
+ } from "./guard-action-options";
20
+ import { useI18n } from "./i18n/provider";
21
+
22
+ export default function GuardActionCatalog({
23
+ items,
24
+ writable,
25
+ onAdd,
26
+ onDelete,
27
+ }: {
28
+ items: GuardActionItem[];
29
+ writable: boolean;
30
+ onAdd: (item: GuardActionItem) => void;
31
+ onDelete: (id: string) => void;
32
+ }) {
33
+ const { t } = useI18n();
34
+ const confirm = useConfirmAction();
35
+ const [name, setName] = useState("");
36
+ const [query, setQuery] = useState("");
37
+ const [error, setError] = useState("");
38
+ const [busy, setBusy] = useState(false);
39
+ const filtered = filterGuardActionOptions(items, query);
40
+ async function add(event: FormEvent) {
41
+ event.preventDefault();
42
+ if (!writable || busy) return;
43
+ setError("");
44
+ setBusy(true);
45
+ setQuery("");
46
+ try {
47
+ onAdd(await createGuardAction(normalizeCreatableGuardAction(name)));
48
+ setName("");
49
+ } catch (cause) {
50
+ setError(
51
+ (cause as Error).message || "Failed to add action to the catalog.",
52
+ );
53
+ } finally {
54
+ setBusy(false);
55
+ }
56
+ }
57
+ async function remove(item: GuardActionItem) {
58
+ if (
59
+ !writable ||
60
+ busy ||
61
+ !(await confirm(
62
+ t("Delete from catalog"),
63
+ t(
64
+ 'Delete "{0}" from the action catalog? Existing policies are unaffected.',
65
+ [item.actionKey],
66
+ ),
67
+ true,
68
+ ))
69
+ )
70
+ return;
71
+ setError("");
72
+ setBusy(true);
73
+ try {
74
+ await deleteGuardAction(item.id);
75
+ onDelete(item.id);
76
+ } catch (cause) {
77
+ setError(
78
+ (cause as Error).message || "Failed to delete action from catalog",
79
+ );
80
+ } finally {
81
+ setBusy(false);
82
+ }
83
+ }
84
+ return (
85
+ <Collapsible className="border-t px-5 py-3">
86
+ <CollapsibleTrigger asChild>
87
+ <Button type="button" size="sm" variant="ghost" className="group -ml-2">
88
+ {t("Action catalog")}
89
+ <ChevronDown className="group-data-[state=open]:rotate-180" />
90
+ </Button>
91
+ </CollapsibleTrigger>
92
+ <CollapsibleContent className="mt-3 grid gap-4">
93
+ {writable && (
94
+ <form onSubmit={add}>
95
+ <Field className="gap-1.5">
96
+ <FieldLabel htmlFor="policy-catalog-new">
97
+ {t("Add action to catalog")}
98
+ </FieldLabel>
99
+ <div className="flex flex-wrap gap-2">
100
+ <Input
101
+ id="policy-catalog-new"
102
+ className="min-w-32 flex-1"
103
+ maxLength={100}
104
+ value={name}
105
+ disabled={busy}
106
+ aria-describedby="policy-catalog-help"
107
+ onChange={(e) => {
108
+ setName(e.target.value);
109
+ setError("");
110
+ }}
111
+ placeholder={t("Reusable action name")}
112
+ />
113
+ <Button
114
+ type="submit"
115
+ size="sm"
116
+ variant="outline"
117
+ disabled={busy || !name.trim()}
118
+ >
119
+ {t("Add to catalog")}
120
+ </Button>
121
+ </div>
122
+ <FieldDescription id="policy-catalog-help">
123
+ {t(
124
+ "Adds a reusable catalog item without changing this policy.",
125
+ )}
126
+ </FieldDescription>
127
+ </Field>
128
+ </form>
129
+ )}
130
+ {items.length > 0 && (
131
+ <Input
132
+ type="search"
133
+ value={query}
134
+ onChange={(e) => setQuery(e.target.value)}
135
+ aria-label={t("Search action catalog")}
136
+ placeholder={t("Search action catalog")}
137
+ />
138
+ )}
139
+ {filtered.length > 0 ? (
140
+ <ul
141
+ aria-label={t("Guard action catalog entries")}
142
+ className="max-h-44 divide-y overflow-auto rounded-md border"
143
+ >
144
+ {filtered.map((item) => (
145
+ <li
146
+ key={item.id}
147
+ className="flex items-center justify-between gap-2 px-3 py-1.5 text-sm"
148
+ >
149
+ <span className="min-w-0 break-all font-mono text-xs">
150
+ {item.actionKey}
151
+ </span>
152
+ {writable && (
153
+ <Button
154
+ type="button"
155
+ variant="ghost"
156
+ className="text-destructive hover:bg-destructive/10 hover:text-destructive"
157
+ size="icon-sm"
158
+ disabled={busy}
159
+ aria-label={t("Delete {0} from action catalog", [
160
+ item.actionKey,
161
+ ])}
162
+ onClick={() => void remove(item)}
163
+ >
164
+ <Trash2 className="size-4" />
165
+ </Button>
166
+ )}
167
+ </li>
168
+ ))}
169
+ </ul>
170
+ ) : (
171
+ <p className="text-sm text-muted-foreground">
172
+ {t(query ? "No matching actions" : "No catalog actions found.")}
173
+ </p>
174
+ )}
175
+ {error && (
176
+ <p className="text-sm text-destructive" role="alert">
177
+ {t(error)}
178
+ </p>
179
+ )}
180
+ </CollapsibleContent>
181
+ </Collapsible>
182
+ );
183
+ }
@@ -1,26 +1,20 @@
1
- import { readFileSync } from "node:fs";
2
1
  import { describe, expect, it } from "vitest";
2
+ import { mergeGuardActionOptions } from "./guard-action-options";
3
+ import { isBuiltInAction } from "./policy-draft";
3
4
 
4
- const source = readFileSync(
5
- new URL("./guard-action-combobox.tsx", import.meta.url),
6
- "utf8",
7
- );
8
-
9
- describe("Guard action combobox semantics", () => {
10
- it("uses a named dialog popup instead of interactive listbox options", () => {
11
- expect(source).toContain('aria-haspopup="dialog"');
12
- expect(source).toContain('role="dialog"');
13
- expect(source).toContain('aria-label={t("Guard action catalog")}');
14
- expect(source).not.toMatch(/role="(?:listbox|option)"/);
15
- });
16
-
17
- it("keeps selection and catalog deletion as sibling buttons", () => {
18
- const optionRow = source.slice(
19
- source.indexOf("filteredOptions.map"),
20
- source.indexOf("{showCreate ?"),
21
- );
22
- expect(optionRow.match(/<button/g)).toHaveLength(2);
23
- expect(optionRow).toContain("chooseOption(option)");
24
- expect(optionRow).toContain("void onDelete(option)");
5
+ describe("custom action selection", () => {
6
+ it("offers catalog and orphaned action keys, with built-in actions in their own profiles", () => {
7
+ const catalog = [
8
+ { id: "1", actionKey: "ota-force-update", createdAt: "" },
9
+ { id: "2", actionKey: "app-check", createdAt: "" },
10
+ ];
11
+ const custom = mergeGuardActionOptions(catalog, [
12
+ "missing-from-catalog",
13
+ "ota-force-store-update",
14
+ ]).filter((option) => !isBuiltInAction(option.actionKey));
15
+ expect(custom.map((o) => [o.actionKey, o.persisted])).toEqual([
16
+ ["app-check", true],
17
+ ["missing-from-catalog", false],
18
+ ]);
25
19
  });
26
20
  });