create-expo-updates-server 0.3.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.
- package/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +5 -10
- package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
- package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
- package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
- package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
- package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
- package/dist/template/app/api/admin/updates/route.test.ts +21 -0
- package/dist/template/app/api/admin/updates/route.ts +12 -1
- package/dist/template/app/globals.css +65 -68
- package/dist/template/app/login/page.tsx +66 -42
- package/dist/template/app/updates/[encodedKey]/page.tsx +382 -248
- package/dist/template/app/updates/devices/page.tsx +187 -145
- package/dist/template/app/updates/embedded/page.tsx +80 -34
- package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +385 -274
- package/dist/template/app/updates/releases.test.tsx +156 -0
- package/dist/template/components/admin/admin-role.ts +5 -0
- package/dist/template/components/admin/admin-shell.tsx +166 -95
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +27 -16
- package/dist/template/components/admin/release-badges.test.tsx +50 -0
- package/dist/template/components/admin/release-badges.tsx +101 -0
- package/dist/template/components/ui/alert.tsx +10 -3
- package/dist/template/components/ui/avatar.tsx +108 -0
- package/dist/template/components/ui/badge.tsx +2 -2
- package/dist/template/components/ui/breadcrumb.tsx +108 -0
- package/dist/template/components/ui/button.tsx +5 -5
- package/dist/template/components/ui/card.tsx +2 -2
- package/dist/template/components/ui/chart.tsx +1 -1
- package/dist/template/components/ui/collapsible.tsx +7 -0
- package/dist/template/components/ui/dialog.tsx +13 -4
- package/dist/template/components/ui/empty.tsx +103 -0
- package/dist/template/components/ui/field.tsx +248 -0
- package/dist/template/components/ui/input-group.tsx +170 -0
- package/dist/template/components/ui/input.tsx +1 -1
- package/dist/template/components/ui/native-select.tsx +1 -1
- package/dist/template/components/ui/radio-group.tsx +41 -0
- package/dist/template/components/ui/sheet.tsx +6 -2
- package/dist/template/components/ui/sidebar.tsx +62 -17
- package/dist/template/components/ui/status-tones.ts +15 -0
- package/dist/template/components/ui/table.tsx +1 -1
- package/dist/template/components/ui/textarea.tsx +1 -1
- package/dist/template/docs/admin-ui.md +22 -24
- package/dist/template/docs/device-targeting.md +6 -12
- package/dist/template/docs/doctor.md +2 -2
- package/dist/template/docs/expo-app-setup.md +9 -27
- package/dist/template/docs/getting-started.md +3 -4
- package/dist/template/docs/getting-started.ru.md +11 -544
- package/dist/template/docs/index.md +1 -1
- package/dist/template/docs/installation-telemetry.md +6 -12
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
- package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
- package/dist/template/docs/migrations/schema.sql +349 -0
- package/dist/template/docs/npm-installer.md +3 -3
- package/dist/template/docs/operations-guide.md +9 -7
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-emergency-recovery.md +34 -57
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +33 -0
- package/dist/template/docs/ru/device-targeting.md +59 -0
- package/dist/template/docs/ru/doctor.md +98 -0
- package/dist/template/docs/ru/expo-app-setup.md +497 -0
- package/dist/template/docs/ru/getting-started.md +391 -0
- package/dist/template/docs/ru/index.md +50 -0
- package/dist/template/docs/ru/installation-telemetry.md +125 -0
- package/dist/template/docs/ru/npm-installer.md +71 -0
- package/dist/template/docs/ru/operations-guide.md +322 -0
- package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/ru/ota-update-policy.md +69 -0
- package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
- package/dist/template/docs/ru/supabase-setup.md +120 -0
- package/dist/template/docs/uk/admin-ui.md +33 -0
- package/dist/template/docs/uk/device-targeting.md +59 -0
- package/dist/template/docs/uk/doctor.md +98 -0
- package/dist/template/docs/uk/expo-app-setup.md +497 -0
- package/dist/template/docs/uk/getting-started.md +391 -0
- package/dist/template/docs/uk/index.md +50 -0
- package/dist/template/docs/uk/installation-telemetry.md +125 -0
- package/dist/template/docs/uk/npm-installer.md +71 -0
- package/dist/template/docs/uk/operations-guide.md +322 -0
- package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/uk/ota-update-policy.md +69 -0
- package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
- package/dist/template/docs/uk/supabase-setup.md +120 -0
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +4 -1
- package/dist/template/scripts/configure-expo-app.mjs +3 -3
- package/dist/template/scripts/create-access-token.mjs +1 -1
- package/dist/template/scripts/lib/doctor.mjs +10 -7
- package/dist/template/scripts/lib/doctor.test.mjs +7 -5
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
- package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
- package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
- package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
- package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
- package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
- package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
- package/dist/template/scripts/tests/e2e/console.mjs +86 -0
- package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
- package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
- package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
- package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
- package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
- package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
- package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
- package/dist/template/scripts/tests/e2e/run.mjs +224 -0
- package/dist/template/scripts/tests/manifest-identity.sql +7 -5
- package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
- package/dist/template/src/client/admin-api.ts +45 -10
- package/dist/template/src/client/admin-types.ts +35 -1
- package/dist/template/src/client/devices/analytics.tsx +169 -219
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -21
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +265 -233
- package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
- package/dist/template/src/client/devices/use-devices-report.ts +53 -82
- package/dist/template/src/client/devices/version-adoption-chart.tsx +48 -38
- package/dist/template/src/client/distribution-control.tsx +98 -53
- package/dist/template/src/client/distribution-history.tsx +353 -0
- package/dist/template/src/client/guard-action-catalog.tsx +183 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
- package/dist/template/src/client/guard-action-combobox.tsx +134 -234
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +335 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
- package/dist/template/src/client/i18n/messages.test.ts +102 -19
- package/dist/template/src/client/i18n/messages.ts +31 -16
- package/dist/template/src/client/i18n/provider.tsx +6 -3
- package/dist/template/src/client/i18n/ru.json +619 -0
- package/dist/template/src/client/i18n/uk.json +619 -0
- package/dist/template/src/client/i18n/use-formatters.ts +5 -0
- package/dist/template/src/client/logout-button.tsx +3 -3
- package/dist/template/src/client/policy-draft.ts +138 -0
- package/dist/template/src/client/update-audience-editor.tsx +597 -199
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +466 -307
- package/dist/template/src/client/use-filtered-results.ts +55 -0
- package/dist/template/src/server/controllers/manifest.test.ts +23 -3
- package/dist/template/src/server/controllers/manifest.ts +15 -1
- package/dist/template/src/server/devices/audience.ts +9 -5
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
- package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
- package/dist/template/src/server/lib/admin-updates.ts +160 -534
- package/dist/template/src/server/lib/distribution-history.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +24 -0
- package/dist/template/src/server/lib/supabase.test.ts +38 -1
- package/dist/template/src/server/lib/update-policy.test.ts +20 -0
- package/dist/template/src/server/lib/update-policy.ts +23 -10
- package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
- package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
- package/dist/template/src/server/manifest/manifest-values.ts +21 -13
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
- package/dist/template/tsconfig.json +2 -2
- package/dist/template-manifest.json +571 -271
- package/package.json +1 -1
- package/dist/template/scripts/lib/device-identity.test.ts +0 -29
- package/dist/template/scripts/lib/ota-client.test.ts +0 -55
- package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
- package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
- package/dist/template/templates/expo-app/ota-client/README.md +0 -73
- package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
- package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
- package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
- package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
- package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
|
@@ -1,59 +1,138 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { AdminRoleContext } from "@/components/admin/admin-role";
|
|
3
|
+
import {
|
|
4
|
+
Collapsible,
|
|
5
|
+
CollapsibleTrigger,
|
|
6
|
+
CollapsibleContent,
|
|
7
|
+
} from "@/components/ui/collapsible";
|
|
8
|
+
import {
|
|
9
|
+
ChevronDown,
|
|
10
|
+
Download,
|
|
11
|
+
ShieldCheck,
|
|
12
|
+
Zap,
|
|
13
|
+
MousePointer2,
|
|
14
|
+
Store,
|
|
15
|
+
Braces,
|
|
16
|
+
LockKeyhole,
|
|
17
|
+
} from "lucide-react";
|
|
18
|
+
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
|
19
|
+
import { Field, FieldLabel, FieldDescription } from "@/components/ui/field";
|
|
20
|
+
import { Label } from "@/components/ui/label";
|
|
21
|
+
import { Badge } from "@/components/ui/badge";
|
|
22
|
+
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
23
|
+
import {
|
|
24
|
+
Select,
|
|
25
|
+
SelectTrigger,
|
|
26
|
+
SelectValue,
|
|
27
|
+
SelectContent,
|
|
28
|
+
SelectItem,
|
|
29
|
+
} from "@/components/ui/select";
|
|
30
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
31
|
+
import {
|
|
32
|
+
behaviors,
|
|
33
|
+
chooseBehavior,
|
|
34
|
+
draftFromPolicy,
|
|
35
|
+
isDeliveryProfile,
|
|
36
|
+
policyFromDraft,
|
|
37
|
+
setStoreLink,
|
|
38
|
+
storePayloadObject,
|
|
39
|
+
validStoreLink,
|
|
40
|
+
type PolicyDraft,
|
|
41
|
+
type PolicyBehavior,
|
|
42
|
+
} from "./policy-draft";
|
|
43
|
+
import GuardActionCatalog from "./guard-action-catalog";
|
|
44
|
+
import type { TranslationMessage } from "@/src/client/i18n/messages";
|
|
45
|
+
import { useI18n } from "@/src/client/i18n/provider";
|
|
2
46
|
|
|
3
47
|
import { Textarea } from "@/components/ui/textarea";
|
|
4
48
|
|
|
5
|
-
import { NativeSelect } from "@/components/ui/native-select";
|
|
6
|
-
|
|
7
49
|
import { Button } from "@/components/ui/button";
|
|
8
50
|
import { Card } from "@/components/ui/card";
|
|
9
51
|
import { Input as TextInput } from "@/components/ui/input";
|
|
10
52
|
|
|
11
53
|
import {
|
|
12
54
|
createGuardAction,
|
|
13
|
-
deleteGuardAction,
|
|
14
55
|
getGuardActions,
|
|
15
56
|
getUpdatePolicy,
|
|
16
57
|
putUpdatePolicy,
|
|
17
58
|
} from "@/src/client/admin-api";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
UpdatePolicy,
|
|
21
|
-
UpdatePolicyGuard,
|
|
22
|
-
} from "@/src/client/admin-types";
|
|
23
|
-
import GuardActionCombobox from "@/src/client/guard-action-combobox";
|
|
59
|
+
import { GuardActionItem, UpdatePolicy } from "@/src/client/admin-types";
|
|
60
|
+
import GuardActionPicker from "@/src/client/guard-action-combobox";
|
|
24
61
|
import {
|
|
25
62
|
beginCatalogAttempt,
|
|
26
|
-
GuardActionOption,
|
|
27
63
|
isCurrentCatalogAttempt,
|
|
28
64
|
mergeGuardActionOptions,
|
|
29
|
-
normalizeCreatableGuardAction,
|
|
30
65
|
} from "@/src/client/guard-action-options";
|
|
31
|
-
import {
|
|
66
|
+
import { useContext, useEffect, useRef, useState } from "react";
|
|
32
67
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
:
|
|
37
|
-
|
|
68
|
+
const profiles = {
|
|
69
|
+
manual: {
|
|
70
|
+
label: "Optional update",
|
|
71
|
+
description:
|
|
72
|
+
"Users can download the update, restart to apply it, or continue with their current version.",
|
|
73
|
+
icon: MousePointer2,
|
|
74
|
+
},
|
|
75
|
+
"manual-postpone": {
|
|
76
|
+
label: "Download on postpone",
|
|
77
|
+
description:
|
|
78
|
+
"Offer the update first. If the user postpones it, download silently and apply it on the next full launch.",
|
|
79
|
+
icon: Download,
|
|
80
|
+
},
|
|
81
|
+
background: {
|
|
82
|
+
label: "Background update",
|
|
83
|
+
description:
|
|
84
|
+
"The app downloads the update silently and applies it on the next launch.",
|
|
85
|
+
icon: Download,
|
|
86
|
+
},
|
|
87
|
+
required: {
|
|
88
|
+
label: "Required OTA update",
|
|
89
|
+
description:
|
|
90
|
+
"The app blocks access and downloads this update. Users restart to continue.",
|
|
91
|
+
icon: ShieldCheck,
|
|
92
|
+
},
|
|
93
|
+
immediate: {
|
|
94
|
+
label: "Immediate required update",
|
|
95
|
+
description:
|
|
96
|
+
"The app silently downloads this update and restarts as soon as it is active and ready. Users can retry if the update fails.",
|
|
97
|
+
icon: Zap,
|
|
98
|
+
},
|
|
99
|
+
store: {
|
|
100
|
+
label: "Require a store update",
|
|
101
|
+
description:
|
|
102
|
+
"The app blocks access and opens the configured store link when the user chooses to upgrade.",
|
|
103
|
+
icon: Store,
|
|
104
|
+
},
|
|
105
|
+
custom: {
|
|
106
|
+
label: "Custom guard",
|
|
107
|
+
description:
|
|
108
|
+
"The app runs the selected action. Access stays blocked unless the app’s handler allows it.",
|
|
109
|
+
icon: Braces,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
38
112
|
|
|
39
113
|
export default function UpdatePolicyEditor({
|
|
40
114
|
encodedKey,
|
|
115
|
+
platform,
|
|
41
116
|
onSaved,
|
|
42
117
|
}: {
|
|
43
118
|
encodedKey: string;
|
|
119
|
+
platform?: string;
|
|
44
120
|
onSaved: () => Promise<void>;
|
|
45
121
|
}) {
|
|
122
|
+
const isViewer = useContext(AdminRoleContext) === "viewer";
|
|
123
|
+
const { t, formatLocale } = useI18n();
|
|
46
124
|
const [policy, setPolicy] = useState<UpdatePolicy | null>(null);
|
|
47
|
-
const [
|
|
125
|
+
const [draftState, setDraft] = useState<PolicyDraft | null>(null);
|
|
126
|
+
const previousDrafts = useRef<Partial<Record<PolicyBehavior, PolicyDraft>>>(
|
|
127
|
+
{},
|
|
128
|
+
);
|
|
129
|
+
const [loadSequence, setLoadSequence] = useState(0);
|
|
48
130
|
const [error, setError] = useState("");
|
|
49
|
-
const [message, setMessage] = useState("");
|
|
131
|
+
const [message, setMessage] = useState<TranslationMessage>("");
|
|
50
132
|
const [saving, setSaving] = useState(false);
|
|
51
133
|
const [guardActions, setGuardActions] = useState<GuardActionItem[]>([]);
|
|
52
134
|
const [canWriteGuardActions, setCanWriteGuardActions] = useState(false);
|
|
53
135
|
const [catalogError, setCatalogError] = useState("");
|
|
54
|
-
const [catalogCreateValue, setCatalogCreateValue] = useState("");
|
|
55
|
-
const [catalogCreateError, setCatalogCreateError] = useState("");
|
|
56
|
-
const [catalogCreatePending, setCatalogCreatePending] = useState(false);
|
|
57
136
|
const [actionError, setActionError] = useState("");
|
|
58
137
|
const actionAttempt = useRef({ current: 0 });
|
|
59
138
|
|
|
@@ -71,36 +150,79 @@ export default function UpdatePolicyEditor({
|
|
|
71
150
|
};
|
|
72
151
|
|
|
73
152
|
useEffect(() => {
|
|
153
|
+
let active = true;
|
|
74
154
|
void getUpdatePolicy(encodedKey)
|
|
75
155
|
.then((loaded) => {
|
|
156
|
+
if (!active) return;
|
|
76
157
|
beginCatalogAttempt(actionAttempt.current);
|
|
77
158
|
setActionError("");
|
|
78
159
|
setPolicy(loaded);
|
|
79
|
-
|
|
160
|
+
previousDrafts.current = {};
|
|
161
|
+
setDraft(draftFromPolicy(loaded));
|
|
162
|
+
setError("");
|
|
80
163
|
})
|
|
81
|
-
.catch(
|
|
82
|
-
|
|
164
|
+
.catch(
|
|
165
|
+
(loadError: unknown) =>
|
|
166
|
+
active &&
|
|
167
|
+
setError((loadError as Error).message || "Failed to load policy"),
|
|
83
168
|
);
|
|
84
|
-
|
|
169
|
+
return () => {
|
|
170
|
+
active = false;
|
|
171
|
+
};
|
|
172
|
+
}, [encodedKey, loadSequence]);
|
|
85
173
|
|
|
86
174
|
useEffect(() => {
|
|
87
175
|
void loadGuardActions();
|
|
88
176
|
}, []);
|
|
89
177
|
|
|
90
|
-
if (!policy) {
|
|
178
|
+
if (!policy || !draftState) {
|
|
91
179
|
return (
|
|
92
|
-
<Card className="
|
|
93
|
-
{error
|
|
180
|
+
<Card className="gap-3 p-5 shadow-none">
|
|
181
|
+
{error ? (
|
|
182
|
+
<>
|
|
183
|
+
<p role="alert">{t(error)}</p>
|
|
184
|
+
<Button
|
|
185
|
+
className="w-fit"
|
|
186
|
+
variant="outline"
|
|
187
|
+
size="sm"
|
|
188
|
+
onClick={() => setLoadSequence((n) => n + 1)}
|
|
189
|
+
>
|
|
190
|
+
{t("Retry")}
|
|
191
|
+
</Button>
|
|
192
|
+
</>
|
|
193
|
+
) : (
|
|
194
|
+
<>
|
|
195
|
+
<span role="status" className="text-sm text-muted-foreground">
|
|
196
|
+
{t("Loading update policy…")}
|
|
197
|
+
</span>
|
|
198
|
+
<Skeleton className="h-16 w-full" />
|
|
199
|
+
</>
|
|
200
|
+
)}
|
|
94
201
|
</Card>
|
|
95
202
|
);
|
|
96
203
|
}
|
|
97
|
-
|
|
98
|
-
const readOnly = !policy.editable;
|
|
204
|
+
const draft = draftState;
|
|
205
|
+
const readOnly = !policy.editable || isViewer;
|
|
99
206
|
const editingDisabled = readOnly || saving;
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
207
|
+
const catalogWritable = canWriteGuardActions && !isViewer;
|
|
208
|
+
const dirty =
|
|
209
|
+
JSON.stringify(draft) !== JSON.stringify(draftFromPolicy(policy));
|
|
210
|
+
const guarded = !isDeliveryProfile(draft.behavior);
|
|
211
|
+
const storeFields = storePayloadObject(draft.payload);
|
|
212
|
+
const profile = profiles[draft.behavior];
|
|
213
|
+
const guardActionOptions = mergeGuardActionOptions(guardActions, [
|
|
214
|
+
draft.action,
|
|
215
|
+
policy.guard?.action || "",
|
|
216
|
+
]);
|
|
217
|
+
const edit = (next: PolicyDraft) => {
|
|
218
|
+
if (next.action !== draft.action || next.behavior !== draft.behavior) {
|
|
219
|
+
beginCatalogAttempt(actionAttempt.current);
|
|
220
|
+
setActionError("");
|
|
221
|
+
}
|
|
222
|
+
setMessage("");
|
|
223
|
+
setError("");
|
|
224
|
+
setDraft(next);
|
|
225
|
+
};
|
|
104
226
|
|
|
105
227
|
const addGuardAction = (item: GuardActionItem) => {
|
|
106
228
|
setGuardActions((current) => {
|
|
@@ -113,16 +235,6 @@ export default function UpdatePolicyEditor({
|
|
|
113
235
|
});
|
|
114
236
|
};
|
|
115
237
|
|
|
116
|
-
const changeGuardAction = (action: string) => {
|
|
117
|
-
beginCatalogAttempt(actionAttempt.current);
|
|
118
|
-
setActionError("");
|
|
119
|
-
setPolicy((current) =>
|
|
120
|
-
current?.guard
|
|
121
|
-
? { ...current, guard: { ...current.guard, action } }
|
|
122
|
-
: current,
|
|
123
|
-
);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
238
|
const persistSelectedAction = async (action: string) => {
|
|
127
239
|
const attempt = beginCatalogAttempt(actionAttempt.current);
|
|
128
240
|
try {
|
|
@@ -140,78 +252,34 @@ export default function UpdatePolicyEditor({
|
|
|
140
252
|
}
|
|
141
253
|
};
|
|
142
254
|
|
|
143
|
-
const createCatalogOnlyAction = async (event: FormEvent) => {
|
|
144
|
-
event.preventDefault();
|
|
145
|
-
let action: string;
|
|
146
|
-
try {
|
|
147
|
-
action = normalizeCreatableGuardAction(catalogCreateValue);
|
|
148
|
-
} catch (validationError: unknown) {
|
|
149
|
-
setCatalogCreateError((validationError as Error).message);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
setCatalogCreatePending(true);
|
|
154
|
-
setCatalogCreateError("");
|
|
155
|
-
try {
|
|
156
|
-
addGuardAction(await createGuardAction(action));
|
|
157
|
-
setCatalogCreateValue("");
|
|
158
|
-
} catch (createError: unknown) {
|
|
159
|
-
setCatalogCreateError(
|
|
160
|
-
(createError as Error).message ||
|
|
161
|
-
"Failed to add action to the catalog.",
|
|
162
|
-
);
|
|
163
|
-
} finally {
|
|
164
|
-
setCatalogCreatePending(false);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const removeGuardAction = async (option: GuardActionOption) => {
|
|
169
|
-
if (
|
|
170
|
-
!option.id ||
|
|
171
|
-
!window.confirm(
|
|
172
|
-
`Delete "${option.actionKey}" from the action catalog? Existing policies are unaffected.`,
|
|
173
|
-
)
|
|
174
|
-
) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
await deleteGuardAction(option.id);
|
|
179
|
-
setGuardActions((current) =>
|
|
180
|
-
current.filter((item) => item.id !== option.id),
|
|
181
|
-
);
|
|
182
|
-
setCatalogError("");
|
|
183
|
-
} catch (deleteError: unknown) {
|
|
184
|
-
setCatalogError(
|
|
185
|
-
(deleteError as Error).message ||
|
|
186
|
-
"Failed to delete action from catalog",
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
255
|
const save = async () => {
|
|
192
256
|
setError("");
|
|
193
257
|
setMessage("");
|
|
194
258
|
setSaving(true);
|
|
195
259
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
260
|
+
const input = policyFromDraft(draft);
|
|
261
|
+
const original = draftFromPolicy(policy);
|
|
262
|
+
if (
|
|
263
|
+
draft.behavior === "store" &&
|
|
264
|
+
(original.behavior !== "store" || draft.payload !== original.payload) &&
|
|
265
|
+
!validStoreLink(draft.payload, platform)
|
|
266
|
+
) {
|
|
267
|
+
throw new Error(
|
|
268
|
+
"Enter a valid store link for this platform or a default store link.",
|
|
269
|
+
);
|
|
206
270
|
}
|
|
207
271
|
const saved = await putUpdatePolicy(
|
|
208
272
|
encodedKey,
|
|
209
|
-
|
|
273
|
+
input,
|
|
210
274
|
policy.policyVersion,
|
|
211
275
|
);
|
|
276
|
+
previousDrafts.current = {};
|
|
212
277
|
setPolicy(saved);
|
|
213
|
-
|
|
214
|
-
setMessage(
|
|
278
|
+
setDraft(draftFromPolicy(saved));
|
|
279
|
+
setMessage({
|
|
280
|
+
key: "Policy saved as version {0}.",
|
|
281
|
+
values: [saved.policyVersion],
|
|
282
|
+
});
|
|
215
283
|
await onSaved();
|
|
216
284
|
} catch (saveError: unknown) {
|
|
217
285
|
setError(
|
|
@@ -225,224 +293,315 @@ export default function UpdatePolicyEditor({
|
|
|
225
293
|
};
|
|
226
294
|
|
|
227
295
|
return (
|
|
228
|
-
<Card className="gap-
|
|
229
|
-
<div className="flex flex-wrap items-
|
|
296
|
+
<Card className="gap-0 overflow-hidden py-0 shadow-none">
|
|
297
|
+
<div className="flex flex-wrap items-start justify-between gap-3 border-b px-5 py-4">
|
|
230
298
|
<div>
|
|
231
|
-
<h2 className="font-semibold">Update policy</h2>
|
|
232
|
-
<p className="text-
|
|
233
|
-
|
|
234
|
-
{policy.publishedAt
|
|
235
|
-
? ` · published ${new Date(policy.publishedAt).toLocaleString()}`
|
|
236
|
-
: " · draft"}
|
|
299
|
+
<h2 className="font-semibold">{t("Update policy")}</h2>
|
|
300
|
+
<p className="mt-1 text-sm text-muted-foreground">
|
|
301
|
+
{t("Choose how this release reaches users.")}
|
|
237
302
|
</p>
|
|
238
303
|
</div>
|
|
239
|
-
<
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
304
|
+
<Badge
|
|
305
|
+
variant={policy.publishedAt ? "info" : "warning"}
|
|
306
|
+
className="whitespace-normal font-normal"
|
|
307
|
+
>
|
|
308
|
+
{t("Version {0}", [policy.policyVersion])}
|
|
309
|
+
{policy.publishedAt
|
|
310
|
+
? t(" · published {0}", [
|
|
311
|
+
new Date(policy.publishedAt).toLocaleString(formatLocale),
|
|
312
|
+
])
|
|
313
|
+
: t(" · draft")}
|
|
314
|
+
</Badge>
|
|
315
|
+
</div>
|
|
316
|
+
{readOnly && (
|
|
317
|
+
<div className="flex items-start gap-2 border-b bg-muted/40 px-5 py-3 text-sm text-muted-foreground">
|
|
318
|
+
<LockKeyhole className="mt-0.5 size-4 shrink-0" />
|
|
319
|
+
{t(
|
|
320
|
+
!policy.editable
|
|
321
|
+
? "Published policies are read-only. Publish a new update ID to change policy."
|
|
322
|
+
: "Your role has read-only access to this policy.",
|
|
323
|
+
)}
|
|
324
|
+
</div>
|
|
325
|
+
)}
|
|
326
|
+
<div className="grid gap-6 p-5 md:grid-cols-[minmax(13rem,0.8fr)_minmax(0,1.4fr)]">
|
|
327
|
+
<section className="min-w-0">
|
|
328
|
+
<h3 id="policy-behavior" className="mb-3 text-sm font-medium">
|
|
329
|
+
{t("Update behavior")}
|
|
330
|
+
</h3>
|
|
331
|
+
<RadioGroup
|
|
332
|
+
value={draft.behavior}
|
|
243
333
|
disabled={editingDisabled}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
334
|
+
aria-labelledby="policy-behavior"
|
|
335
|
+
className="gap-1.5"
|
|
336
|
+
onValueChange={(v) => {
|
|
337
|
+
const mode = v as PolicyBehavior;
|
|
338
|
+
previousDrafts.current[draft.behavior] = draft;
|
|
339
|
+
edit(previousDrafts.current[mode] ?? chooseBehavior(draft, mode));
|
|
340
|
+
}}
|
|
251
341
|
>
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
342
|
+
{behaviors.map((mode) => {
|
|
343
|
+
const Icon = profiles[mode].icon;
|
|
344
|
+
return (
|
|
345
|
+
<Label
|
|
346
|
+
key={mode}
|
|
347
|
+
htmlFor={`behavior-${mode}`}
|
|
348
|
+
className="flex min-h-10 cursor-pointer gap-2.5 rounded-md border px-3 py-2.5 text-sm font-normal has-[[data-state=checked]]:border-primary has-[[data-state=checked]]:bg-accent has-[[data-state=checked]]:font-medium has-[:disabled]:cursor-default"
|
|
349
|
+
>
|
|
350
|
+
<Icon
|
|
351
|
+
aria-hidden
|
|
352
|
+
className="size-4 shrink-0 text-muted-foreground"
|
|
353
|
+
/>
|
|
354
|
+
<span className="flex-1">{t(profiles[mode].label)}</span>
|
|
355
|
+
<RadioGroupItem id={`behavior-${mode}`} value={mode} />
|
|
356
|
+
</Label>
|
|
357
|
+
);
|
|
358
|
+
})}
|
|
359
|
+
</RadioGroup>
|
|
360
|
+
</section>
|
|
361
|
+
<section className="min-w-0 space-y-4 border-t pt-4 md:border-t-0 md:border-l md:pt-0 md:pl-6">
|
|
362
|
+
<div>
|
|
363
|
+
<h3 className="font-semibold">{t(profile.label)}</h3>
|
|
364
|
+
<p className="mt-1 text-sm text-muted-foreground">
|
|
365
|
+
{t(profile.description)}
|
|
366
|
+
</p>
|
|
367
|
+
</div>
|
|
368
|
+
{draft.behavior === "custom" && (
|
|
369
|
+
<GuardActionPicker
|
|
370
|
+
value={draft.action}
|
|
371
|
+
options={guardActionOptions}
|
|
372
|
+
disabled={editingDisabled}
|
|
373
|
+
onChange={(action) => edit({ ...draft, action })}
|
|
374
|
+
onCreate={persistSelectedAction}
|
|
375
|
+
/>
|
|
376
|
+
)}
|
|
377
|
+
{draft.behavior === "store" &&
|
|
378
|
+
(storeFields ? (
|
|
379
|
+
<div className="grid gap-3">
|
|
380
|
+
{(
|
|
381
|
+
[
|
|
382
|
+
["url", "Default store link"],
|
|
383
|
+
["iosUrl", "iOS store link"],
|
|
384
|
+
["androidUrl", "Android store link"],
|
|
385
|
+
] as const
|
|
386
|
+
).map(([key, label]) => (
|
|
387
|
+
<Field key={key} className="gap-1.5">
|
|
388
|
+
<FieldLabel htmlFor={`policy-store-${key}`}>
|
|
389
|
+
{t(label)}
|
|
390
|
+
</FieldLabel>
|
|
391
|
+
<TextInput
|
|
392
|
+
id={`policy-store-${key}`}
|
|
393
|
+
inputMode="url"
|
|
394
|
+
autoCapitalize="off"
|
|
395
|
+
spellCheck={false}
|
|
396
|
+
readOnly={editingDisabled}
|
|
397
|
+
value={String(storeFields[key] ?? "")}
|
|
398
|
+
onChange={(e) =>
|
|
399
|
+
edit({
|
|
400
|
+
...draft,
|
|
401
|
+
payload: setStoreLink(
|
|
402
|
+
storeFields,
|
|
403
|
+
key,
|
|
404
|
+
e.target.value,
|
|
405
|
+
),
|
|
406
|
+
})
|
|
407
|
+
}
|
|
408
|
+
/>
|
|
409
|
+
</Field>
|
|
410
|
+
))}
|
|
411
|
+
<FieldDescription>
|
|
412
|
+
{t(
|
|
413
|
+
"The app uses its platform link first, then the default link. Use https, market or itms-apps links.",
|
|
414
|
+
)}
|
|
415
|
+
</FieldDescription>
|
|
416
|
+
</div>
|
|
417
|
+
) : (
|
|
418
|
+
<p className="text-sm text-muted-foreground">
|
|
419
|
+
{t(
|
|
420
|
+
"Edit the existing store payload in advanced settings to preserve its structure.",
|
|
421
|
+
)}
|
|
422
|
+
</p>
|
|
423
|
+
))}
|
|
424
|
+
{guarded && (
|
|
425
|
+
<Collapsible
|
|
426
|
+
key={draft.behavior}
|
|
427
|
+
defaultOpen={
|
|
428
|
+
draft.behavior === "custom" ||
|
|
429
|
+
(draft.delivery === "background" &&
|
|
430
|
+
draft.behavior !== "immediate") ||
|
|
431
|
+
Boolean(draft.payload && draft.behavior !== "store") ||
|
|
432
|
+
(draft.behavior === "store" && !storeFields)
|
|
433
|
+
}
|
|
434
|
+
>
|
|
435
|
+
<CollapsibleTrigger asChild>
|
|
436
|
+
<Button
|
|
437
|
+
type="button"
|
|
438
|
+
size="sm"
|
|
439
|
+
variant="outline"
|
|
440
|
+
className="group"
|
|
441
|
+
>
|
|
442
|
+
{t("Advanced settings")}
|
|
443
|
+
<ChevronDown className="group-data-[state=open]:rotate-180" />
|
|
444
|
+
</Button>
|
|
445
|
+
</CollapsibleTrigger>
|
|
446
|
+
<CollapsibleContent className="pt-3">
|
|
447
|
+
<div className="space-y-4 rounded-md border bg-muted/20 p-3">
|
|
448
|
+
{draft.behavior !== "required" &&
|
|
449
|
+
draft.behavior !== "immediate" && (
|
|
450
|
+
<div className="grid gap-1.5">
|
|
451
|
+
<Label htmlFor="policy-delivery">{t("Delivery")}</Label>
|
|
452
|
+
<Select
|
|
453
|
+
value={draft.delivery}
|
|
454
|
+
disabled={editingDisabled}
|
|
455
|
+
onValueChange={(v) =>
|
|
456
|
+
edit({
|
|
457
|
+
...draft,
|
|
458
|
+
delivery: v as UpdatePolicy["delivery"],
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
>
|
|
462
|
+
<SelectTrigger
|
|
463
|
+
id="policy-delivery"
|
|
464
|
+
aria-describedby="policy-delivery-hint policy-guard-hint"
|
|
465
|
+
className="w-full"
|
|
466
|
+
>
|
|
467
|
+
<SelectValue />
|
|
468
|
+
</SelectTrigger>
|
|
469
|
+
<SelectContent>
|
|
470
|
+
<SelectItem value="manual">
|
|
471
|
+
{t("Manual")}
|
|
472
|
+
</SelectItem>
|
|
473
|
+
<SelectItem value="background">
|
|
474
|
+
{t("Background")}
|
|
475
|
+
</SelectItem>
|
|
476
|
+
</SelectContent>
|
|
477
|
+
</Select>
|
|
478
|
+
<p
|
|
479
|
+
id="policy-delivery-hint"
|
|
480
|
+
className="text-xs leading-relaxed text-muted-foreground"
|
|
481
|
+
>
|
|
482
|
+
{draft.delivery === "background"
|
|
483
|
+
? t(
|
|
484
|
+
"When OTA is allowed, the app downloads it silently during use. It takes effect on the next full launch. For an automatic restart, select Immediate required update.",
|
|
485
|
+
)
|
|
486
|
+
: t(
|
|
487
|
+
"When OTA is allowed, the default client lets the user choose when to download and restart. They can postpone the update.",
|
|
488
|
+
)}
|
|
489
|
+
</p>
|
|
490
|
+
<p
|
|
491
|
+
id="policy-guard-hint"
|
|
492
|
+
className="text-xs leading-relaxed text-muted-foreground"
|
|
493
|
+
>
|
|
494
|
+
{draft.behavior === "store"
|
|
495
|
+
? t(
|
|
496
|
+
"This release requires an update from the store. Both delivery modes show the store button and block the OTA download.",
|
|
497
|
+
)
|
|
498
|
+
: t(
|
|
499
|
+
"Delivery starts only after the app’s custom action allows the update.",
|
|
500
|
+
)}
|
|
501
|
+
</p>
|
|
502
|
+
</div>
|
|
503
|
+
)}
|
|
504
|
+
<div className="grid gap-1.5">
|
|
505
|
+
<Label htmlFor="policy-payload">
|
|
506
|
+
{t("Optional custom JSON payload")}
|
|
507
|
+
</Label>
|
|
508
|
+
<Textarea
|
|
509
|
+
id="policy-payload"
|
|
510
|
+
spellCheck={false}
|
|
511
|
+
value={draft.payload}
|
|
512
|
+
readOnly={editingDisabled}
|
|
513
|
+
className="min-h-24 font-mono text-xs"
|
|
514
|
+
onChange={(e) =>
|
|
515
|
+
edit({ ...draft, payload: e.target.value })
|
|
516
|
+
}
|
|
517
|
+
/>
|
|
518
|
+
</div>
|
|
519
|
+
</div>
|
|
520
|
+
</CollapsibleContent>
|
|
521
|
+
</Collapsible>
|
|
522
|
+
)}
|
|
523
|
+
{actionError && (
|
|
524
|
+
<div role="status" className="text-sm text-destructive">
|
|
525
|
+
{t(actionError)}{" "}
|
|
526
|
+
<Button
|
|
527
|
+
size="sm"
|
|
528
|
+
variant="outline"
|
|
529
|
+
onClick={() => void persistSelectedAction(draft.action)}
|
|
530
|
+
>
|
|
531
|
+
{t("Retry")}
|
|
532
|
+
</Button>
|
|
533
|
+
</div>
|
|
534
|
+
)}
|
|
535
|
+
</section>
|
|
256
536
|
</div>
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
<span>Action catalog: {catalogError}</span>
|
|
537
|
+
{!readOnly && (
|
|
538
|
+
<div className="flex flex-wrap items-center gap-2 border-t bg-muted/20 px-5 py-3">
|
|
539
|
+
<div
|
|
540
|
+
className="min-w-0 flex-1 text-sm text-muted-foreground"
|
|
541
|
+
role="status"
|
|
542
|
+
>
|
|
543
|
+
{message ? t(message) : dirty ? t("Unsaved changes") : null}
|
|
544
|
+
</div>
|
|
545
|
+
{dirty && (
|
|
546
|
+
<Button
|
|
547
|
+
size="sm"
|
|
548
|
+
variant="outline"
|
|
549
|
+
disabled={saving}
|
|
550
|
+
onClick={() => {
|
|
551
|
+
previousDrafts.current = {};
|
|
552
|
+
edit(draftFromPolicy(policy));
|
|
553
|
+
}}
|
|
554
|
+
>
|
|
555
|
+
{t("Discard changes")}
|
|
556
|
+
</Button>
|
|
557
|
+
)}
|
|
279
558
|
<Button
|
|
280
|
-
variant="outline"
|
|
281
559
|
size="sm"
|
|
282
|
-
|
|
283
|
-
onClick={() => void
|
|
560
|
+
disabled={saving || !dirty}
|
|
561
|
+
onClick={() => void save()}
|
|
284
562
|
>
|
|
285
|
-
|
|
563
|
+
{saving ? t("Saving…") : t("Save policy")}
|
|
286
564
|
</Button>
|
|
287
565
|
</div>
|
|
288
|
-
)
|
|
289
|
-
{
|
|
290
|
-
<
|
|
291
|
-
|
|
292
|
-
|
|
566
|
+
)}
|
|
567
|
+
{error && (
|
|
568
|
+
<Alert variant="destructive" className="mx-5 my-3 w-auto">
|
|
569
|
+
<AlertDescription>
|
|
570
|
+
{t(error)}
|
|
571
|
+
<Button
|
|
572
|
+
type="button"
|
|
573
|
+
variant="link"
|
|
574
|
+
className="h-auto px-0"
|
|
575
|
+
onClick={() => setLoadSequence((n) => n + 1)}
|
|
576
|
+
>
|
|
577
|
+
{t("Reload saved policy")}
|
|
578
|
+
</Button>
|
|
579
|
+
</AlertDescription>
|
|
580
|
+
</Alert>
|
|
581
|
+
)}
|
|
582
|
+
{catalogError && (
|
|
583
|
+
<div
|
|
584
|
+
role="status"
|
|
585
|
+
className="flex items-center gap-2 px-5 py-3 text-sm"
|
|
293
586
|
>
|
|
294
|
-
|
|
295
|
-
Add action to catalog
|
|
296
|
-
<TextInput
|
|
297
|
-
value={catalogCreateValue}
|
|
298
|
-
maxLength={100}
|
|
299
|
-
disabled={catalogCreatePending}
|
|
300
|
-
onChange={(event) => {
|
|
301
|
-
setCatalogCreateValue(event.target.value);
|
|
302
|
-
setCatalogCreateError("");
|
|
303
|
-
}}
|
|
304
|
-
aria-describedby="guard-action-catalog-create-help"
|
|
305
|
-
className="mt-1 w-full rounded border border-input bg-background p-2 text-sm "
|
|
306
|
-
placeholder="Reusable action name"
|
|
307
|
-
/>
|
|
308
|
-
</label>
|
|
587
|
+
{t(catalogError)}
|
|
309
588
|
<Button
|
|
310
589
|
variant="outline"
|
|
311
590
|
size="sm"
|
|
312
|
-
|
|
313
|
-
disabled={catalogCreatePending}
|
|
591
|
+
onClick={() => void loadGuardActions()}
|
|
314
592
|
>
|
|
315
|
-
{
|
|
593
|
+
{t("Retry")}
|
|
316
594
|
</Button>
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
>
|
|
328
|
-
<span>{catalogCreateError}</span>
|
|
329
|
-
<Button variant="outline" size="sm" type="submit">
|
|
330
|
-
Retry
|
|
331
|
-
</Button>
|
|
332
|
-
</div>
|
|
333
|
-
) : null}
|
|
334
|
-
</form>
|
|
335
|
-
) : null}
|
|
336
|
-
<div className="space-y-2 rounded-md border border-border p-3 ">
|
|
337
|
-
<h3 className="text-sm font-medium">Action catalog</h3>
|
|
338
|
-
{guardActions.length > 0 ? (
|
|
339
|
-
<ul
|
|
340
|
-
aria-label="Guard action catalog entries"
|
|
341
|
-
className="max-h-40 space-y-1 overflow-auto"
|
|
342
|
-
>
|
|
343
|
-
{guardActions.map((item) => (
|
|
344
|
-
<li
|
|
345
|
-
key={item.id}
|
|
346
|
-
className="flex items-center justify-between gap-2 rounded bg-muted/30 px-2 py-1 text-sm dark:bg-muted/20"
|
|
347
|
-
>
|
|
348
|
-
<span className="min-w-0 truncate" title={item.actionKey}>
|
|
349
|
-
{item.actionKey}
|
|
350
|
-
</span>
|
|
351
|
-
{canWriteGuardActions ? (
|
|
352
|
-
<Button
|
|
353
|
-
variant="destructive"
|
|
354
|
-
size="sm"
|
|
355
|
-
type="button"
|
|
356
|
-
aria-label={`Delete ${item.actionKey} from action catalog`}
|
|
357
|
-
onClick={() =>
|
|
358
|
-
void removeGuardAction({
|
|
359
|
-
id: item.id,
|
|
360
|
-
actionKey: item.actionKey,
|
|
361
|
-
persisted: true,
|
|
362
|
-
})
|
|
363
|
-
}
|
|
364
|
-
>
|
|
365
|
-
Delete
|
|
366
|
-
</Button>
|
|
367
|
-
) : null}
|
|
368
|
-
</li>
|
|
369
|
-
))}
|
|
370
|
-
</ul>
|
|
371
|
-
) : (
|
|
372
|
-
<p className="text-xs text-muted-foreground">
|
|
373
|
-
No catalog actions found.
|
|
374
|
-
</p>
|
|
375
|
-
)}
|
|
376
|
-
</div>
|
|
377
|
-
|
|
378
|
-
<div className="space-y-3 rounded-lg border border-input p-3 ">
|
|
379
|
-
<label className="flex items-center gap-2 text-sm font-medium">
|
|
380
|
-
<input className="size-4 rounded border-input accent-primary"
|
|
381
|
-
type="checkbox"
|
|
382
|
-
checked={policy.guard !== null}
|
|
383
|
-
disabled={editingDisabled}
|
|
384
|
-
onChange={(event) => {
|
|
385
|
-
beginCatalogAttempt(actionAttempt.current);
|
|
386
|
-
setActionError("");
|
|
387
|
-
setPolicy({
|
|
388
|
-
...policy,
|
|
389
|
-
guard: event.target.checked
|
|
390
|
-
? { action: guardActions[0]?.actionKey || "" }
|
|
391
|
-
: null,
|
|
392
|
-
});
|
|
393
|
-
if (!event.target.checked) setPayload("");
|
|
394
|
-
}}
|
|
395
|
-
/>
|
|
396
|
-
Guard enabled
|
|
397
|
-
</label>
|
|
398
|
-
<p className="text-xs text-muted-foreground">
|
|
399
|
-
When enabled, this Guard applies unconditionally whenever this OTA is
|
|
400
|
-
selected for a client.
|
|
401
|
-
</p>
|
|
402
|
-
{policy.guard ? (
|
|
403
|
-
<>
|
|
404
|
-
<GuardActionCombobox
|
|
405
|
-
value={policy.guard.action}
|
|
406
|
-
options={guardActionOptions}
|
|
407
|
-
selectionDisabled={editingDisabled}
|
|
408
|
-
canMutateCatalog={canWriteGuardActions}
|
|
409
|
-
mutationError={actionError}
|
|
410
|
-
onChange={changeGuardAction}
|
|
411
|
-
onCreate={persistSelectedAction}
|
|
412
|
-
onDelete={removeGuardAction}
|
|
413
|
-
onRetry={
|
|
414
|
-
actionError
|
|
415
|
-
? () => persistSelectedAction(policy.guard?.action || "")
|
|
416
|
-
: undefined
|
|
417
|
-
}
|
|
418
|
-
/>
|
|
419
|
-
<label className="block text-xs text-muted-foreground">
|
|
420
|
-
Optional custom JSON payload
|
|
421
|
-
<Textarea
|
|
422
|
-
value={payload}
|
|
423
|
-
disabled={editingDisabled}
|
|
424
|
-
onChange={(event) => setPayload(event.target.value)}
|
|
425
|
-
className="mt-1 h-24 w-full rounded border border-input bg-background p-2 font-mono text-xs "
|
|
426
|
-
placeholder='{"message":"Optional"}'
|
|
427
|
-
/>
|
|
428
|
-
</label>
|
|
429
|
-
</>
|
|
430
|
-
) : (
|
|
431
|
-
<p className="text-sm text-muted-foreground">
|
|
432
|
-
No Guard will be emitted in the update manifest.
|
|
433
|
-
</p>
|
|
434
|
-
)}
|
|
435
|
-
</div>
|
|
436
|
-
|
|
437
|
-
<Button
|
|
438
|
-
variant="default"
|
|
439
|
-
size="sm"
|
|
440
|
-
type="button"
|
|
441
|
-
disabled={editingDisabled}
|
|
442
|
-
onClick={() => void save()}
|
|
443
|
-
>
|
|
444
|
-
Save policy
|
|
445
|
-
</Button>
|
|
595
|
+
</div>
|
|
596
|
+
)}
|
|
597
|
+
<GuardActionCatalog
|
|
598
|
+
items={guardActions}
|
|
599
|
+
writable={catalogWritable}
|
|
600
|
+
onAdd={addGuardAction}
|
|
601
|
+
onDelete={(id) =>
|
|
602
|
+
setGuardActions((items) => items.filter((item) => item.id !== id))
|
|
603
|
+
}
|
|
604
|
+
/>
|
|
446
605
|
</Card>
|
|
447
606
|
);
|
|
448
607
|
}
|