create-expo-updates-server 0.1.6 → 0.2.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.
- package/dist/template/.dockerignore +16 -0
- package/dist/template/README.md +51 -660
- package/dist/template/app/api/admin/device-targets/route.test.ts +43 -0
- package/dist/template/app/api/admin/device-targets/route.ts +91 -0
- package/dist/template/app/api/admin/devices/route.test.ts +41 -0
- package/dist/template/app/api/admin/devices/route.ts +15 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/audience/route.ts +75 -0
- package/dist/template/app/api/device-heartbeat/route.ts +2 -0
- package/dist/template/app/globals.css +114 -15
- package/dist/template/app/layout.tsx +12 -4
- package/dist/template/app/login/page.tsx +22 -18
- package/dist/template/app/updates/[encodedKey]/page.tsx +112 -88
- package/dist/template/app/updates/devices/page.tsx +264 -0
- package/dist/template/app/updates/embedded/page.tsx +102 -68
- package/dist/template/app/updates/emergency-redirects/page.tsx +144 -111
- package/dist/template/app/updates/layout.tsx +6 -1
- package/dist/template/app/updates/page.tsx +262 -212
- package/dist/template/components/admin/admin-shell.tsx +196 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -0
- package/dist/template/components/admin/theme-provider.tsx +15 -0
- package/dist/template/components/ui/alert.tsx +65 -0
- package/dist/template/components/ui/badge.tsx +47 -0
- package/dist/template/components/ui/button.tsx +63 -0
- package/dist/template/components/ui/card.tsx +91 -0
- package/dist/template/components/ui/chart.tsx +373 -0
- package/dist/template/components/ui/checkbox.tsx +31 -0
- package/dist/template/components/ui/dialog.tsx +158 -0
- package/dist/template/components/ui/dropdown-menu.tsx +256 -0
- package/dist/template/components/ui/input.tsx +20 -0
- package/dist/template/components/ui/label.tsx +23 -0
- package/dist/template/components/ui/native-select.tsx +61 -0
- package/dist/template/components/ui/popover.tsx +88 -0
- package/dist/template/components/ui/scroll-area.tsx +57 -0
- package/dist/template/components/ui/select.tsx +189 -0
- package/dist/template/components/ui/separator.tsx +27 -0
- package/dist/template/components/ui/sheet.tsx +142 -0
- package/dist/template/components/ui/sidebar.tsx +736 -0
- package/dist/template/components/ui/skeleton.tsx +13 -0
- package/dist/template/components/ui/switch.tsx +34 -0
- package/dist/template/components/ui/table.tsx +115 -0
- package/dist/template/components/ui/tabs.tsx +90 -0
- package/dist/template/components/ui/textarea.tsx +17 -0
- package/dist/template/components/ui/tooltip.tsx +56 -0
- package/dist/template/components.json +22 -0
- package/dist/template/docs/admin-ui.md +35 -0
- package/dist/template/docs/device-targeting.md +129 -0
- package/dist/template/docs/doctor.md +137 -0
- package/dist/template/docs/expo-app-setup.md +174 -47
- package/dist/template/docs/getting-started.md +105 -146
- package/dist/template/docs/getting-started.ru.md +106 -191
- package/dist/template/docs/index.md +14 -33
- package/dist/template/docs/installation-telemetry.md +233 -0
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +89 -0
- package/dist/template/docs/migrations/2026-10-19-device-heartbeat.sql +131 -0
- package/dist/template/docs/migrations/2026-10-22-device-analytics.sql +264 -0
- package/dist/template/docs/migrations/2026-10-22-device-targeting-activation.sql +108 -0
- package/dist/template/docs/migrations/2026-10-22-device-targeting.sql +130 -0
- package/dist/template/docs/migrations/2026-10-22-device-version-metadata.sql +154 -0
- package/dist/template/docs/migrations/schema.sql +868 -6
- package/dist/template/docs/npm-installer.md +15 -30
- package/dist/template/docs/operations-guide.md +87 -0
- package/dist/template/docs/ota-client-lifecycle.md +263 -0
- package/dist/template/docs/ota-update-policy.md +36 -2
- package/dist/template/docs/supabase-setup.md +4 -0
- package/dist/template/hooks/use-mobile.ts +21 -0
- package/dist/template/lib/utils.ts +6 -0
- package/dist/template/package-lock.json +2325 -101
- package/dist/template/package.json +13 -3
- package/dist/template/scripts/configure-expo-app.mjs +11 -15
- package/dist/template/scripts/doctor.mjs +51 -0
- package/dist/template/scripts/ensure-test-bucket.mjs +21 -0
- package/dist/template/scripts/lib/device-identity.test.ts +29 -0
- package/dist/template/scripts/lib/doctor-probes.mjs +139 -0
- package/dist/template/scripts/lib/doctor.mjs +208 -0
- package/dist/template/scripts/lib/doctor.test.mjs +262 -0
- package/dist/template/scripts/lib/expo-app-configurator.mjs +14 -9
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +3 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +69 -0
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +88 -0
- package/dist/template/scripts/lib/ota-client.test.ts +55 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +173 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +123 -0
- package/dist/template/scripts/lib/ota-update-controller.test.ts +231 -0
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +80 -0
- package/dist/template/scripts/tests/device-analytics.mjs +126 -0
- package/dist/template/scripts/tests/device-heartbeat.mjs +86 -0
- package/dist/template/scripts/tests/device-targeting-activation.mjs +111 -0
- package/dist/template/scripts/tests/device-targeting.mjs +39 -0
- package/dist/template/scripts/tests/device-version-metadata.mjs +31 -0
- package/dist/template/scripts/tests/manifest-identity-concurrency.mjs +106 -0
- package/dist/template/scripts/tests/manifest-identity.sql +204 -0
- package/dist/template/src/client/admin-types.ts +1 -0
- package/dist/template/src/client/devices/analytics.tsx +429 -0
- package/dist/template/src/client/devices/device-name.tsx +82 -0
- package/dist/template/src/client/devices/registry.tsx +399 -0
- package/dist/template/src/client/devices/use-devices-report.ts +108 -0
- package/dist/template/src/client/devices/version-adoption-chart.tsx +269 -0
- package/dist/template/src/client/devices/version-groups.test.ts +57 -0
- package/dist/template/src/client/devices/version-groups.ts +101 -0
- package/dist/template/src/client/distribution-control.tsx +135 -81
- package/dist/template/src/client/guard-action-combobox.tsx +13 -24
- package/dist/template/src/client/i18n/en.json +286 -0
- package/dist/template/src/client/i18n/messages.test.ts +42 -0
- package/dist/template/src/client/i18n/messages.ts +31 -0
- package/dist/template/src/client/i18n/provider.tsx +55 -0
- package/dist/template/src/client/i18n/use-formatters.ts +38 -0
- package/dist/template/src/client/logout-button.tsx +3 -1
- package/dist/template/src/client/update-audience-editor.tsx +285 -0
- package/dist/template/src/client/update-policy-editor.tsx +53 -41
- package/dist/template/src/server/controllers/manifest.test.ts +250 -7
- package/dist/template/src/server/controllers/manifest.ts +39 -31
- package/dist/template/src/server/devices/audience.test.ts +48 -0
- package/dist/template/src/server/devices/audience.ts +86 -0
- package/dist/template/src/server/devices/heartbeat.test.ts +39 -0
- package/dist/template/src/server/devices/heartbeat.ts +75 -0
- package/dist/template/src/server/devices/report-types.ts +114 -0
- package/dist/template/src/server/devices/report.test.ts +29 -0
- package/dist/template/src/server/devices/report.ts +27 -0
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +94 -0
- package/dist/template/src/server/lib/admin-updates.ts +32 -168
- package/dist/template/src/server/lib/supabase.js +10 -10
- package/dist/template/src/server/lib/supabase.test.ts +11 -0
- package/dist/template/src/server/manifest/manifest-identity.test.ts +30 -0
- package/dist/template/src/server/manifest/manifest-identity.ts +24 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +31 -102
- package/dist/template/src/server/manifest/manifest-response.ts +1 -1
- package/dist/template/templates/expo-app/ota-client/README.md +59 -0
- package/dist/template/templates/expo-app/ota-client/controller.js +60 -0
- package/dist/template/templates/expo-app/ota-client/device-identity.js +26 -0
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +52 -0
- package/dist/template/templates/expo-app/ota-client/index.d.ts +47 -0
- package/dist/template/templates/expo-app/ota-client/index.js +3 -0
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +48 -0
- package/dist/template/templates/expo-app/ota-client/model/update-controller.js +182 -0
- package/dist/template/templates/expo-app/ota-client/runtime.js +112 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +56 -0
- package/dist/template-manifest.json +578 -73
- package/lib/cli.mjs +4 -6
- package/package.json +1 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useI18n } from "@/src/client/i18n/provider";
|
|
3
|
+
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import {
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CardTitle,
|
|
11
|
+
} from "@/components/ui/card";
|
|
12
|
+
import { Button } from "@/components/ui/button";
|
|
13
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
14
|
+
import { Input } from "@/components/ui/input";
|
|
15
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
16
|
+
import { NativeSelect } from "@/components/ui/native-select";
|
|
17
|
+
import type { Audience } from "@/src/server/devices/audience";
|
|
18
|
+
|
|
19
|
+
type Target = {
|
|
20
|
+
installation_id: string;
|
|
21
|
+
device_id: string | null;
|
|
22
|
+
name: string | null;
|
|
23
|
+
platform: string;
|
|
24
|
+
runtime_version: string;
|
|
25
|
+
channel: string;
|
|
26
|
+
};
|
|
27
|
+
async function json(response: Response) {
|
|
28
|
+
const value = await response.json();
|
|
29
|
+
if (!response.ok) throw new Error(value.error || "Ошибка запроса");
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
const splitIds = (value: string) => [
|
|
33
|
+
...new Set(value.split(/[\s,]+/).filter(Boolean)),
|
|
34
|
+
];
|
|
35
|
+
export default function UpdateAudienceEditor({
|
|
36
|
+
encodedKey,
|
|
37
|
+
platform,
|
|
38
|
+
}: {
|
|
39
|
+
encodedKey: string;
|
|
40
|
+
platform: string;
|
|
41
|
+
}) {
|
|
42
|
+
const { t } = useI18n();
|
|
43
|
+
const [audience, setAudience] = useState<Audience | null>(null);
|
|
44
|
+
const [devices, setDevices] = useState<Target[]>([]);
|
|
45
|
+
const [mode, setMode] = useState("all");
|
|
46
|
+
const [deviceIds, setDeviceIds] = useState("");
|
|
47
|
+
const [installationIds, setInstallationIds] = useState("");
|
|
48
|
+
const [search, setSearch] = useState("");
|
|
49
|
+
const [busy, setBusy] = useState(false);
|
|
50
|
+
const [error, setError] = useState("");
|
|
51
|
+
const [success, setSuccess] = useState("");
|
|
52
|
+
const [revision, setRevision] = useState(0);
|
|
53
|
+
const url = `/api/admin/updates/${encodedKey}/audience`;
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const abort = new AbortController();
|
|
56
|
+
Promise.all([
|
|
57
|
+
fetch(url, { signal: abort.signal }).then(json),
|
|
58
|
+
fetch(`/api/admin/device-targets?platform=${platform}`, {
|
|
59
|
+
signal: abort.signal,
|
|
60
|
+
}).then(json),
|
|
61
|
+
])
|
|
62
|
+
.then(([a, d]) => {
|
|
63
|
+
setAudience(a);
|
|
64
|
+
setMode(a.audience_mode);
|
|
65
|
+
setDeviceIds(a.audience_device_ids.join("\n"));
|
|
66
|
+
setInstallationIds(a.audience_installation_ids.join("\n"));
|
|
67
|
+
setDevices(d.devices);
|
|
68
|
+
setError("");
|
|
69
|
+
})
|
|
70
|
+
.catch((e) => {
|
|
71
|
+
if (!abort.signal.aborted) setError(e.message);
|
|
72
|
+
});
|
|
73
|
+
return () => abort.abort();
|
|
74
|
+
}, [url, platform, revision]);
|
|
75
|
+
const selectedDevices = splitIds(deviceIds);
|
|
76
|
+
const selectedInstallations = splitIds(installationIds);
|
|
77
|
+
const seen = new Set<string>();
|
|
78
|
+
const options = devices
|
|
79
|
+
.filter((d) => {
|
|
80
|
+
const key = d.device_id || d.installation_id;
|
|
81
|
+
if (seen.has(key)) return false;
|
|
82
|
+
const matches = [
|
|
83
|
+
d.name,
|
|
84
|
+
key,
|
|
85
|
+
d.installation_id,
|
|
86
|
+
d.channel,
|
|
87
|
+
d.runtime_version,
|
|
88
|
+
]
|
|
89
|
+
.join(" ")
|
|
90
|
+
.toLowerCase()
|
|
91
|
+
.includes(search.toLowerCase());
|
|
92
|
+
if (matches) seen.add(key);
|
|
93
|
+
return matches;
|
|
94
|
+
})
|
|
95
|
+
.slice(0, 50);
|
|
96
|
+
async function save() {
|
|
97
|
+
if (!audience) return;
|
|
98
|
+
setBusy(true);
|
|
99
|
+
setError("");
|
|
100
|
+
setSuccess("");
|
|
101
|
+
try {
|
|
102
|
+
const saved = await fetch(url, {
|
|
103
|
+
method: "PUT",
|
|
104
|
+
headers: { "Content-Type": "application/json" },
|
|
105
|
+
body: JSON.stringify({
|
|
106
|
+
audience_mode: mode,
|
|
107
|
+
audience_device_ids: selectedDevices,
|
|
108
|
+
audience_installation_ids: selectedInstallations,
|
|
109
|
+
audience_version: audience.audience_version,
|
|
110
|
+
}),
|
|
111
|
+
}).then(json);
|
|
112
|
+
setAudience(saved);
|
|
113
|
+
setSuccess(
|
|
114
|
+
t(
|
|
115
|
+
"Аудитория сохранена. Для черновика отдельно включите распространение.",
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
setError((e as Error).message);
|
|
120
|
+
} finally {
|
|
121
|
+
setBusy(false);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return (
|
|
125
|
+
<Card>
|
|
126
|
+
<CardHeader>
|
|
127
|
+
<CardTitle>{t("Аудитория обновления")}</CardTitle>
|
|
128
|
+
<CardDescription>
|
|
129
|
+
{t(
|
|
130
|
+
"Сначала ограничьте аудиторию черновика, затем активируйте OTA. После smoke-теста выберите «Все» и сохраните. Runtime, канал и платформа по-прежнему должны совпадать.",
|
|
131
|
+
)}
|
|
132
|
+
</CardDescription>
|
|
133
|
+
</CardHeader>
|
|
134
|
+
<CardContent className="space-y-4">
|
|
135
|
+
{error && (
|
|
136
|
+
<p role="alert" className="text-sm text-destructive">
|
|
137
|
+
{t(error)}
|
|
138
|
+
</p>
|
|
139
|
+
)}
|
|
140
|
+
{success && (
|
|
141
|
+
<p role="status" className="text-sm text-muted-foreground">
|
|
142
|
+
{success}
|
|
143
|
+
</p>
|
|
144
|
+
)}
|
|
145
|
+
{audience && (
|
|
146
|
+
<>
|
|
147
|
+
<label className="block space-y-2 text-sm">
|
|
148
|
+
<span>{t("Кому доступен OTA")}</span>
|
|
149
|
+
<NativeSelect
|
|
150
|
+
value={mode}
|
|
151
|
+
onChange={(e) => {
|
|
152
|
+
setMode(e.target.value);
|
|
153
|
+
setSuccess("");
|
|
154
|
+
}}
|
|
155
|
+
disabled={busy}
|
|
156
|
+
>
|
|
157
|
+
<option value="all">{t("Все совместимые устройства")}</option>
|
|
158
|
+
<option value="devices">
|
|
159
|
+
{t("Только выбранные устройства / установки")}
|
|
160
|
+
</option>
|
|
161
|
+
</NativeSelect>
|
|
162
|
+
</label>
|
|
163
|
+
{mode === "devices" && (
|
|
164
|
+
<div className="space-y-4">
|
|
165
|
+
<Input
|
|
166
|
+
aria-label={t("Поиск адресата")}
|
|
167
|
+
placeholder={t("Имя, ID, runtime или канал")}
|
|
168
|
+
value={search}
|
|
169
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
170
|
+
/>
|
|
171
|
+
<p className="text-xs text-muted-foreground">
|
|
172
|
+
{t("Последние 500 установок ")}
|
|
173
|
+
{platform}
|
|
174
|
+
{t(
|
|
175
|
+
", до 50 совпадений. Device ID сохраняет адресата при переустановке; Installation ID относится к одной установке.",
|
|
176
|
+
)}
|
|
177
|
+
</p>
|
|
178
|
+
<div className="max-h-64 overflow-y-auto rounded-md border divide-y">
|
|
179
|
+
{options.map((d) => {
|
|
180
|
+
const id = d.device_id || d.installation_id;
|
|
181
|
+
const selected = d.device_id
|
|
182
|
+
? selectedDevices
|
|
183
|
+
: selectedInstallations;
|
|
184
|
+
const set = d.device_id ? setDeviceIds : setInstallationIds;
|
|
185
|
+
const kind = d.device_id ? t("Устройство") : t("Установка");
|
|
186
|
+
return (
|
|
187
|
+
<label
|
|
188
|
+
key={id}
|
|
189
|
+
className="flex cursor-pointer items-start gap-3 p-3 text-sm"
|
|
190
|
+
>
|
|
191
|
+
<Checkbox
|
|
192
|
+
aria-label={d.name || `${kind} ${id}`}
|
|
193
|
+
className="mt-1"
|
|
194
|
+
disabled={busy}
|
|
195
|
+
checked={selected.includes(id)}
|
|
196
|
+
onCheckedChange={(checked) =>
|
|
197
|
+
set(
|
|
198
|
+
(checked === true
|
|
199
|
+
? [...selected, id]
|
|
200
|
+
: selected.filter((x) => x !== id)
|
|
201
|
+
).join("\n"),
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
/>
|
|
205
|
+
<span className="min-w-0">
|
|
206
|
+
<span className="font-medium">
|
|
207
|
+
{d.name || `${kind} ${id.slice(0, 12)}…`}
|
|
208
|
+
</span>
|
|
209
|
+
<span className="block text-xs text-muted-foreground break-all">
|
|
210
|
+
{d.runtime_version} · {d.channel} ·{" "}
|
|
211
|
+
{d.installation_id}
|
|
212
|
+
</span>
|
|
213
|
+
</span>
|
|
214
|
+
</label>
|
|
215
|
+
);
|
|
216
|
+
})}
|
|
217
|
+
{options.length === 0 && (
|
|
218
|
+
<p className="p-4 text-sm text-muted-foreground">
|
|
219
|
+
{t(
|
|
220
|
+
"Устройства не найдены. Запустите приложение с обновлённым OTA-клиентом или укажите ID ниже.",
|
|
221
|
+
)}
|
|
222
|
+
</p>
|
|
223
|
+
)}
|
|
224
|
+
</div>
|
|
225
|
+
<details>
|
|
226
|
+
<summary className="cursor-pointer text-sm">
|
|
227
|
+
{t("Выбранные ID и ручное добавление ·")}{" "}
|
|
228
|
+
{selectedDevices.length + selectedInstallations.length}
|
|
229
|
+
</summary>
|
|
230
|
+
<div className="mt-3 grid gap-3 md:grid-cols-2">
|
|
231
|
+
<label className="space-y-2 text-sm">
|
|
232
|
+
<span>{t("Device ID (по одному в строке)")}</span>
|
|
233
|
+
<Textarea
|
|
234
|
+
aria-label="Device IDs"
|
|
235
|
+
value={deviceIds}
|
|
236
|
+
disabled={busy}
|
|
237
|
+
onChange={(e) => setDeviceIds(e.target.value)}
|
|
238
|
+
/>
|
|
239
|
+
</label>
|
|
240
|
+
<label className="space-y-2 text-sm">
|
|
241
|
+
<span>{t("Installation ID (по одному в строке)")}</span>
|
|
242
|
+
<Textarea
|
|
243
|
+
aria-label="Installation IDs"
|
|
244
|
+
value={installationIds}
|
|
245
|
+
disabled={busy}
|
|
246
|
+
onChange={(e) => setInstallationIds(e.target.value)}
|
|
247
|
+
/>
|
|
248
|
+
</label>
|
|
249
|
+
</div>
|
|
250
|
+
</details>
|
|
251
|
+
</div>
|
|
252
|
+
)}
|
|
253
|
+
<p className="text-xs text-muted-foreground">
|
|
254
|
+
{t(
|
|
255
|
+
"Ограничение влияет на следующие проверки OTA. Уже скачанное обновление нельзя отозвать изменением аудитории. Force update действует только для её участников.",
|
|
256
|
+
)}
|
|
257
|
+
</p>
|
|
258
|
+
<Button
|
|
259
|
+
className="mr-2"
|
|
260
|
+
onClick={save}
|
|
261
|
+
disabled={
|
|
262
|
+
busy ||
|
|
263
|
+
(mode === "devices" &&
|
|
264
|
+
!selectedDevices.length &&
|
|
265
|
+
!selectedInstallations.length)
|
|
266
|
+
}
|
|
267
|
+
>
|
|
268
|
+
{t("Сохранить аудиторию")}
|
|
269
|
+
</Button>
|
|
270
|
+
</>
|
|
271
|
+
)}
|
|
272
|
+
<Button
|
|
273
|
+
variant="outline"
|
|
274
|
+
disabled={busy}
|
|
275
|
+
onClick={() => {
|
|
276
|
+
setSuccess("");
|
|
277
|
+
setRevision((n) => n + 1);
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
280
|
+
{t("Перечитать")}
|
|
281
|
+
</Button>
|
|
282
|
+
</CardContent>
|
|
283
|
+
</Card>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
4
|
+
|
|
5
|
+
import { NativeSelect } from "@/components/ui/native-select";
|
|
6
|
+
|
|
7
|
+
import { Button } from "@/components/ui/button";
|
|
8
|
+
import { Card } from "@/components/ui/card";
|
|
9
|
+
import { Input as TextInput } from "@/components/ui/input";
|
|
10
|
+
|
|
3
11
|
import {
|
|
4
12
|
createGuardAction,
|
|
5
13
|
deleteGuardAction,
|
|
@@ -81,9 +89,9 @@ export default function UpdatePolicyEditor({
|
|
|
81
89
|
|
|
82
90
|
if (!policy) {
|
|
83
91
|
return (
|
|
84
|
-
<
|
|
92
|
+
<Card className="rounded-xl border border-border bg-card p-5 text-sm shadow-none">
|
|
85
93
|
{error || "Loading update policy…"}
|
|
86
|
-
</
|
|
94
|
+
</Card>
|
|
87
95
|
);
|
|
88
96
|
}
|
|
89
97
|
|
|
@@ -193,9 +201,7 @@ export default function UpdatePolicyEditor({
|
|
|
193
201
|
const trimmedPayload = payload.trim();
|
|
194
202
|
guard = {
|
|
195
203
|
action: policy.guard.action,
|
|
196
|
-
...(trimmedPayload
|
|
197
|
-
? { payload: JSON.parse(trimmedPayload) }
|
|
198
|
-
: {}),
|
|
204
|
+
...(trimmedPayload ? { payload: JSON.parse(trimmedPayload) } : {}),
|
|
199
205
|
};
|
|
200
206
|
}
|
|
201
207
|
const saved = await putUpdatePolicy(
|
|
@@ -219,11 +225,11 @@ export default function UpdatePolicyEditor({
|
|
|
219
225
|
};
|
|
220
226
|
|
|
221
227
|
return (
|
|
222
|
-
<
|
|
228
|
+
<Card className="gap-4 p-5 shadow-none">
|
|
223
229
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
224
230
|
<div>
|
|
225
231
|
<h2 className="font-semibold">Update policy</h2>
|
|
226
|
-
<p className="text-xs text-
|
|
232
|
+
<p className="text-xs text-muted-foreground">
|
|
227
233
|
Version {policy.policyVersion}
|
|
228
234
|
{policy.publishedAt
|
|
229
235
|
? ` · published ${new Date(policy.publishedAt).toLocaleString()}`
|
|
@@ -232,7 +238,7 @@ export default function UpdatePolicyEditor({
|
|
|
232
238
|
</div>
|
|
233
239
|
<label className="text-sm">
|
|
234
240
|
Delivery{" "}
|
|
235
|
-
<
|
|
241
|
+
<NativeSelect
|
|
236
242
|
value={policy.delivery}
|
|
237
243
|
disabled={editingDisabled}
|
|
238
244
|
onChange={(event) =>
|
|
@@ -241,16 +247,16 @@ export default function UpdatePolicyEditor({
|
|
|
241
247
|
delivery: event.target.value as UpdatePolicy["delivery"],
|
|
242
248
|
})
|
|
243
249
|
}
|
|
244
|
-
className="rounded-md border border-
|
|
250
|
+
className="rounded-md border border-input bg-background px-2 py-2 "
|
|
245
251
|
>
|
|
246
252
|
<option value="manual">Manual</option>
|
|
247
253
|
<option value="background">Background</option>
|
|
248
|
-
</
|
|
254
|
+
</NativeSelect>
|
|
249
255
|
</label>
|
|
250
256
|
</div>
|
|
251
257
|
|
|
252
258
|
{readOnly ? (
|
|
253
|
-
<div className="rounded-md border border-
|
|
259
|
+
<div className="rounded-md border border-border bg-muted/30 p-3 text-sm ">
|
|
254
260
|
Published policies are read-only. Publish a new update ID to change
|
|
255
261
|
policy.
|
|
256
262
|
</div>
|
|
@@ -270,23 +276,24 @@ export default function UpdatePolicyEditor({
|
|
|
270
276
|
className="flex items-center gap-2 text-sm text-amber-700 dark:text-amber-300"
|
|
271
277
|
>
|
|
272
278
|
<span>Action catalog: {catalogError}</span>
|
|
273
|
-
<
|
|
279
|
+
<Button
|
|
280
|
+
variant="outline"
|
|
281
|
+
size="sm"
|
|
274
282
|
type="button"
|
|
275
283
|
onClick={() => void loadGuardActions()}
|
|
276
|
-
className="underline"
|
|
277
284
|
>
|
|
278
285
|
Retry
|
|
279
|
-
</
|
|
286
|
+
</Button>
|
|
280
287
|
</div>
|
|
281
288
|
) : null}
|
|
282
289
|
{canWriteGuardActions ? (
|
|
283
290
|
<form
|
|
284
291
|
onSubmit={(event) => void createCatalogOnlyAction(event)}
|
|
285
|
-
className="flex flex-wrap items-end gap-2 rounded-md border border-
|
|
292
|
+
className="flex flex-wrap items-end gap-2 rounded-md border border-border p-3 "
|
|
286
293
|
>
|
|
287
|
-
<label className="min-w-56 flex-1 text-xs text-
|
|
294
|
+
<label className="min-w-56 flex-1 text-xs text-muted-foreground">
|
|
288
295
|
Add action to catalog
|
|
289
|
-
<
|
|
296
|
+
<TextInput
|
|
290
297
|
value={catalogCreateValue}
|
|
291
298
|
maxLength={100}
|
|
292
299
|
disabled={catalogCreatePending}
|
|
@@ -295,20 +302,21 @@ export default function UpdatePolicyEditor({
|
|
|
295
302
|
setCatalogCreateError("");
|
|
296
303
|
}}
|
|
297
304
|
aria-describedby="guard-action-catalog-create-help"
|
|
298
|
-
className="mt-1 w-full rounded border border-
|
|
305
|
+
className="mt-1 w-full rounded border border-input bg-background p-2 text-sm "
|
|
299
306
|
placeholder="Reusable action name"
|
|
300
307
|
/>
|
|
301
308
|
</label>
|
|
302
|
-
<
|
|
309
|
+
<Button
|
|
310
|
+
variant="outline"
|
|
311
|
+
size="sm"
|
|
303
312
|
type="submit"
|
|
304
313
|
disabled={catalogCreatePending}
|
|
305
|
-
className="rounded border border-zinc-300 px-3 py-2 text-sm disabled:opacity-40 dark:border-zinc-700"
|
|
306
314
|
>
|
|
307
315
|
{catalogCreatePending ? "Adding…" : "Add to catalog"}
|
|
308
|
-
</
|
|
316
|
+
</Button>
|
|
309
317
|
<p
|
|
310
318
|
id="guard-action-catalog-create-help"
|
|
311
|
-
className="w-full text-xs text-
|
|
319
|
+
className="w-full text-xs text-muted-foreground"
|
|
312
320
|
>
|
|
313
321
|
Adds a reusable catalog item without changing this policy.
|
|
314
322
|
</p>
|
|
@@ -318,14 +326,14 @@ export default function UpdatePolicyEditor({
|
|
|
318
326
|
className="flex w-full items-center gap-2 text-xs text-amber-700 dark:text-amber-300"
|
|
319
327
|
>
|
|
320
328
|
<span>{catalogCreateError}</span>
|
|
321
|
-
<
|
|
329
|
+
<Button variant="outline" size="sm" type="submit">
|
|
322
330
|
Retry
|
|
323
|
-
</
|
|
331
|
+
</Button>
|
|
324
332
|
</div>
|
|
325
333
|
) : null}
|
|
326
334
|
</form>
|
|
327
335
|
) : null}
|
|
328
|
-
<div className="space-y-2 rounded-md border border-
|
|
336
|
+
<div className="space-y-2 rounded-md border border-border p-3 ">
|
|
329
337
|
<h3 className="text-sm font-medium">Action catalog</h3>
|
|
330
338
|
{guardActions.length > 0 ? (
|
|
331
339
|
<ul
|
|
@@ -335,13 +343,15 @@ export default function UpdatePolicyEditor({
|
|
|
335
343
|
{guardActions.map((item) => (
|
|
336
344
|
<li
|
|
337
345
|
key={item.id}
|
|
338
|
-
className="flex items-center justify-between gap-2 rounded bg-
|
|
346
|
+
className="flex items-center justify-between gap-2 rounded bg-muted/30 px-2 py-1 text-sm dark:bg-muted/20"
|
|
339
347
|
>
|
|
340
348
|
<span className="min-w-0 truncate" title={item.actionKey}>
|
|
341
349
|
{item.actionKey}
|
|
342
350
|
</span>
|
|
343
351
|
{canWriteGuardActions ? (
|
|
344
|
-
<
|
|
352
|
+
<Button
|
|
353
|
+
variant="destructive"
|
|
354
|
+
size="sm"
|
|
345
355
|
type="button"
|
|
346
356
|
aria-label={`Delete ${item.actionKey} from action catalog`}
|
|
347
357
|
onClick={() =>
|
|
@@ -351,22 +361,23 @@ export default function UpdatePolicyEditor({
|
|
|
351
361
|
persisted: true,
|
|
352
362
|
})
|
|
353
363
|
}
|
|
354
|
-
className="rounded px-2 py-1 text-xs text-red-600"
|
|
355
364
|
>
|
|
356
365
|
Delete
|
|
357
|
-
</
|
|
366
|
+
</Button>
|
|
358
367
|
) : null}
|
|
359
368
|
</li>
|
|
360
369
|
))}
|
|
361
370
|
</ul>
|
|
362
371
|
) : (
|
|
363
|
-
<p className="text-xs text-
|
|
372
|
+
<p className="text-xs text-muted-foreground">
|
|
373
|
+
No catalog actions found.
|
|
374
|
+
</p>
|
|
364
375
|
)}
|
|
365
376
|
</div>
|
|
366
377
|
|
|
367
|
-
<div className="space-y-3 rounded-lg border border-
|
|
378
|
+
<div className="space-y-3 rounded-lg border border-input p-3 ">
|
|
368
379
|
<label className="flex items-center gap-2 text-sm font-medium">
|
|
369
|
-
<input
|
|
380
|
+
<input className="size-4 rounded border-input accent-primary"
|
|
370
381
|
type="checkbox"
|
|
371
382
|
checked={policy.guard !== null}
|
|
372
383
|
disabled={editingDisabled}
|
|
@@ -384,7 +395,7 @@ export default function UpdatePolicyEditor({
|
|
|
384
395
|
/>
|
|
385
396
|
Guard enabled
|
|
386
397
|
</label>
|
|
387
|
-
<p className="text-xs text-
|
|
398
|
+
<p className="text-xs text-muted-foreground">
|
|
388
399
|
When enabled, this Guard applies unconditionally whenever this OTA is
|
|
389
400
|
selected for a client.
|
|
390
401
|
</p>
|
|
@@ -405,32 +416,33 @@ export default function UpdatePolicyEditor({
|
|
|
405
416
|
: undefined
|
|
406
417
|
}
|
|
407
418
|
/>
|
|
408
|
-
<label className="block text-xs text-
|
|
419
|
+
<label className="block text-xs text-muted-foreground">
|
|
409
420
|
Optional custom JSON payload
|
|
410
|
-
<
|
|
421
|
+
<Textarea
|
|
411
422
|
value={payload}
|
|
412
423
|
disabled={editingDisabled}
|
|
413
424
|
onChange={(event) => setPayload(event.target.value)}
|
|
414
|
-
className="mt-1 h-24 w-full rounded border border-
|
|
425
|
+
className="mt-1 h-24 w-full rounded border border-input bg-background p-2 font-mono text-xs "
|
|
415
426
|
placeholder='{"message":"Optional"}'
|
|
416
427
|
/>
|
|
417
428
|
</label>
|
|
418
429
|
</>
|
|
419
430
|
) : (
|
|
420
|
-
<p className="text-sm text-
|
|
431
|
+
<p className="text-sm text-muted-foreground">
|
|
421
432
|
No Guard will be emitted in the update manifest.
|
|
422
433
|
</p>
|
|
423
434
|
)}
|
|
424
435
|
</div>
|
|
425
436
|
|
|
426
|
-
<
|
|
437
|
+
<Button
|
|
438
|
+
variant="default"
|
|
439
|
+
size="sm"
|
|
427
440
|
type="button"
|
|
428
441
|
disabled={editingDisabled}
|
|
429
442
|
onClick={() => void save()}
|
|
430
|
-
className="rounded bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-40"
|
|
431
443
|
>
|
|
432
444
|
Save policy
|
|
433
|
-
</
|
|
434
|
-
</
|
|
445
|
+
</Button>
|
|
446
|
+
</Card>
|
|
435
447
|
);
|
|
436
448
|
}
|