create-expo-updates-server 0.1.4 → 0.1.6
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/.env.docker.example +1 -0
- package/dist/template/.env.example +2 -0
- package/dist/template/README.md +4 -1
- package/dist/template/app/api/admin/distribution-control/route.test.ts +153 -0
- package/dist/template/app/api/admin/distribution-control/route.ts +111 -0
- package/dist/template/app/api/admin/guard-actions/[id]/route.test.ts +60 -0
- package/dist/template/app/api/admin/guard-actions/[id]/route.ts +32 -0
- package/dist/template/app/api/admin/guard-actions/route.test.ts +123 -0
- package/dist/template/app/api/admin/guard-actions/route.ts +66 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.test.ts +171 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.ts +75 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +4 -1
- package/dist/template/app/updates/[encodedKey]/page.tsx +74 -6
- package/dist/template/app/updates/page.tsx +22 -1
- package/dist/template/docs/getting-started.md +1 -0
- package/dist/template/docs/getting-started.ru.md +2 -1
- package/dist/template/docs/migrations/2026-09-01-ota-update-policy.sql +108 -0
- package/dist/template/docs/migrations/2026-09-01-p1-guard-actions.sql +19 -0
- package/dist/template/docs/migrations/2026-09-01-p2-simplify-ota-guard-policy.sql +69 -0
- package/dist/template/docs/migrations/2026-09-01-policy-publication-correction.sql +44 -0
- package/dist/template/docs/migrations/2026-09-02-ota-distribution-control.sql +377 -0
- package/dist/template/docs/migrations/schema.sql +539 -2
- package/dist/template/docs/operations-guide.md +52 -1
- package/dist/template/docs/ota-emergency-recovery.md +22 -0
- package/dist/template/docs/ota-update-policy.md +89 -0
- package/dist/template/docs/supabase-setup.md +2 -1
- package/dist/template/package-lock.json +2 -2
- package/dist/template/package.json +1 -1
- package/dist/template/src/client/admin-api.ts +80 -1
- package/dist/template/src/client/admin-types.ts +50 -2
- package/dist/template/src/client/distribution-control.tsx +231 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +26 -0
- package/dist/template/src/client/guard-action-combobox.tsx +267 -0
- package/dist/template/src/client/guard-action-options.test.ts +62 -0
- package/dist/template/src/client/guard-action-options.ts +70 -0
- package/dist/template/src/client/update-policy-editor.test.ts +36 -0
- package/dist/template/src/client/update-policy-editor.tsx +436 -0
- package/dist/template/src/server/controllers/assets.test.ts +87 -0
- package/dist/template/src/server/controllers/assets.ts +26 -0
- package/dist/template/src/server/controllers/manifest.test.ts +413 -2
- package/dist/template/src/server/controllers/manifest.ts +103 -38
- package/dist/template/src/server/lib/admin-distribution-guard.test.ts +61 -0
- package/dist/template/src/server/lib/admin-update-policy.test.ts +176 -0
- package/dist/template/src/server/lib/admin-updates.test.ts +72 -0
- package/dist/template/src/server/lib/admin-updates.ts +169 -24
- package/dist/template/src/server/lib/distribution-control-migration.test.ts +94 -0
- package/dist/template/src/server/lib/distribution-control.test.ts +181 -0
- package/dist/template/src/server/lib/distribution-control.ts +259 -0
- package/dist/template/src/server/lib/guard-actions-migration.test.ts +56 -0
- package/dist/template/src/server/lib/guard-actions.test.ts +142 -0
- package/dist/template/src/server/lib/guard-actions.ts +106 -0
- package/dist/template/src/server/lib/ota-policy-migrations.test.ts +64 -0
- package/dist/template/src/server/lib/simple-policy-migration.test.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +95 -8
- package/dist/template/src/server/lib/supabase.test.ts +194 -0
- package/dist/template/src/server/lib/update-policy.test.ts +98 -0
- package/dist/template/src/server/lib/update-policy.ts +171 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +10 -1
- package/dist/template/src/server/manifest/manifest-response.ts +0 -16
- package/dist/template/src/server/manifest/manifest-values.test.ts +54 -0
- package/dist/template/src/server/manifest/manifest-values.ts +145 -0
- package/dist/template/tsconfig.json +4 -1
- package/dist/template-manifest.json +239 -59
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# OTA update policy client contract
|
|
2
|
+
|
|
3
|
+
Every served update manifest includes `extra.updatePolicy`:
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"schemaVersion": 1,
|
|
8
|
+
"policyVersion": 2,
|
|
9
|
+
"delivery": "background",
|
|
10
|
+
"guard": {
|
|
11
|
+
"action": "require-confirmation",
|
|
12
|
+
"payload": { "message": "Restart when ready" }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The `guard` property is omitted when no Guard is configured. A configured
|
|
18
|
+
Guard is unconditional: it is included for every client to which the existing
|
|
19
|
+
runtime, channel, platform, and update selection logic serves that OTA.
|
|
20
|
+
Catalog membership is advisory and is not required to save or serve an action.
|
|
21
|
+
|
|
22
|
+
- `Updates.checkForUpdateAsync()` returns the policy on the **candidate**
|
|
23
|
+
manifest in the check result.
|
|
24
|
+
- `Updates.manifest` contains the policy of the update that is **currently
|
|
25
|
+
running**. Do not use it as the candidate policy before downloading.
|
|
26
|
+
- `manual` is the default and leaves fetch/reload behavior to the application.
|
|
27
|
+
- `background` means fetch the candidate silently, do not reload immediately,
|
|
28
|
+
and apply it on the next cold start.
|
|
29
|
+
- Legacy clients safely ignore the additional `extra` value.
|
|
30
|
+
|
|
31
|
+
An inactive upload is a draft, even though its initial `disabled_at` value is
|
|
32
|
+
equal to `created_at`. Its delivery mode and simple Guard remain editable until
|
|
33
|
+
activation. `disabled_at` by itself is not evidence that an update was
|
|
34
|
+
published.
|
|
35
|
+
|
|
36
|
+
`ota_update_channels.latest_update_id` identifies the newest upload and may
|
|
37
|
+
therefore point to an inactive draft. That pointer is not publication evidence;
|
|
38
|
+
manifest selection falls back to the latest active update. An
|
|
39
|
+
`active_update_id` rollback pointer or an `ota_served_manifest_log` row is
|
|
40
|
+
publication evidence.
|
|
41
|
+
|
|
42
|
+
Activation is the publication event. Once activated, promoted, used as a
|
|
43
|
+
rollback target, or demonstrably served, a policy remains immutable even if the
|
|
44
|
+
update is later disabled. Publish a new update ID when policy needs to change.
|
|
45
|
+
|
|
46
|
+
## Production upgrade order
|
|
47
|
+
|
|
48
|
+
Back up the database. Existing installations should apply these idempotent
|
|
49
|
+
migrations in order:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
psql "$DATABASE_URL" -f docs/migrations/2026-09-01-p1-guard-actions.sql
|
|
53
|
+
psql "$DATABASE_URL" -f docs/migrations/2026-09-01-p2-simplify-ota-guard-policy.sql
|
|
54
|
+
psql "$DATABASE_URL" -f docs/migrations/2026-09-01-policy-publication-correction.sql
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The simplification migration deliberately drops `guard_rules` without
|
|
58
|
+
converting old rules. It adds nullable `guard_action` and `guard_payload`
|
|
59
|
+
columns and recreates the policy immutability trigger for the simple model.
|
|
60
|
+
The final corrective migration only clears incorrectly inferred publication
|
|
61
|
+
markers for conservative, inactive, never-served default policies. It does not
|
|
62
|
+
unlock active, rollback, or served updates.
|
|
63
|
+
|
|
64
|
+
Environments that already successfully ran
|
|
65
|
+
`2026-09-01-policy-publication-correction.sql` and verified that no drafts
|
|
66
|
+
remain falsely marked as published may skip the third step. Otherwise, the
|
|
67
|
+
correction must run third because it references the `guard_action` and
|
|
68
|
+
`guard_payload` columns created by the simplification migration.
|
|
69
|
+
|
|
70
|
+
Supabase users can run the same files in SQL Editor in the listed order. Fresh
|
|
71
|
+
installations should apply only the canonical
|
|
72
|
+
`docs/migrations/schema.sql`, which contains the simple model.
|
|
73
|
+
|
|
74
|
+
## Guard action catalog
|
|
75
|
+
|
|
76
|
+
The policy editor loads reusable action names from `ota_guard_actions`. New
|
|
77
|
+
installations receive the `ota-force-store-update` action. Operators can create
|
|
78
|
+
an action by typing it in the action combobox or through the catalog-only form,
|
|
79
|
+
which remains available while viewing an immutable policy and never changes
|
|
80
|
+
that policy.
|
|
81
|
+
|
|
82
|
+
Persisted catalog entries can be removed with the trash control. Catalog
|
|
83
|
+
deletion does not modify an existing policy. Its action remains visible as a
|
|
84
|
+
synthetic option until deliberately changed, and synthetic options have no
|
|
85
|
+
delete control.
|
|
86
|
+
|
|
87
|
+
Catalog action keys are trimmed when created, contain 1–100 characters, and
|
|
88
|
+
cannot contain control characters. Viewers can list catalog entries but cannot
|
|
89
|
+
create or delete them.
|
|
@@ -42,6 +42,7 @@ creates:
|
|
|
42
42
|
| `ota_admin_users` | Admin users and roles |
|
|
43
43
|
| `ota_admin_sessions` | Revocable browser sessions |
|
|
44
44
|
| `ota_access_tokens` | Hashed automation tokens |
|
|
45
|
+
| `ota_guard_actions` | Reusable Guard action catalog |
|
|
45
46
|
| `ota_emergency_redirects` | Emergency channel rules |
|
|
46
47
|
|
|
47
48
|
Do not run a pgAdmin schema dump as the installation script. Dumps contain
|
|
@@ -123,7 +124,7 @@ Then sign in at:
|
|
|
123
124
|
https://updates.example.com/login
|
|
124
125
|
```
|
|
125
126
|
|
|
126
|
-
The **Table Editor** should show all
|
|
127
|
+
The **Table Editor** should show all eleven OTA tables listed above.
|
|
127
128
|
|
|
128
129
|
## 7. Upgrades
|
|
129
130
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-updates-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "expo-updates-server",
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.5",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-s3": "^3.888.0",
|
|
@@ -1,22 +1,58 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AdminSessionResponse,
|
|
3
|
+
DistributionControlResponse,
|
|
4
|
+
DistributionControlState,
|
|
3
5
|
EmbeddedUpdatesListResponse,
|
|
4
6
|
EmergencyRedirectInput,
|
|
5
7
|
EmergencyRedirectItem,
|
|
6
8
|
EmergencyRedirectsListResponse,
|
|
9
|
+
GuardActionItem,
|
|
10
|
+
GuardActionsListResponse,
|
|
7
11
|
UpdateDetail,
|
|
12
|
+
UpdatePolicy,
|
|
8
13
|
UpdatesListResponse,
|
|
9
14
|
} from "./admin-types";
|
|
10
15
|
|
|
16
|
+
export class AdminApiError extends Error {
|
|
17
|
+
constructor(
|
|
18
|
+
message: string,
|
|
19
|
+
readonly status: number,
|
|
20
|
+
) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "AdminApiError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
11
26
|
async function parseJson<T>(response: Response): Promise<T> {
|
|
12
27
|
const data = await response.json().catch(() => ({}));
|
|
13
28
|
if (!response.ok) {
|
|
14
29
|
const message = (data as { error?: string })?.error || "Request failed";
|
|
15
|
-
throw new
|
|
30
|
+
throw new AdminApiError(message, response.status);
|
|
16
31
|
}
|
|
32
|
+
|
|
17
33
|
return data as T;
|
|
18
34
|
}
|
|
19
35
|
|
|
36
|
+
export async function getDistributionControl() {
|
|
37
|
+
const response = await fetch("/api/admin/distribution-control", {
|
|
38
|
+
cache: "no-store",
|
|
39
|
+
});
|
|
40
|
+
return parseJson<DistributionControlResponse>(response);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function setDistributionControl(input: {
|
|
44
|
+
blocked: boolean;
|
|
45
|
+
reason?: string;
|
|
46
|
+
expectedVersion: number;
|
|
47
|
+
}) {
|
|
48
|
+
const response = await fetch("/api/admin/distribution-control", {
|
|
49
|
+
method: "PUT",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
body: JSON.stringify(input),
|
|
52
|
+
});
|
|
53
|
+
return parseJson<DistributionControlState>(response);
|
|
54
|
+
}
|
|
55
|
+
|
|
20
56
|
export async function adminLogin(username: string, password: string) {
|
|
21
57
|
const response = await fetch("/api/admin/login", {
|
|
22
58
|
method: "POST",
|
|
@@ -65,6 +101,26 @@ export async function getUpdate(encodedKey: string) {
|
|
|
65
101
|
return parseJson<UpdateDetail>(response);
|
|
66
102
|
}
|
|
67
103
|
|
|
104
|
+
export async function getUpdatePolicy(encodedKey: string) {
|
|
105
|
+
const response = await fetch(`/api/admin/updates/${encodedKey}/policy`, {
|
|
106
|
+
cache: "no-store",
|
|
107
|
+
});
|
|
108
|
+
return parseJson<UpdatePolicy>(response);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function putUpdatePolicy(
|
|
112
|
+
encodedKey: string,
|
|
113
|
+
policy: Pick<UpdatePolicy, "delivery" | "guard">,
|
|
114
|
+
expectedPolicyVersion: number,
|
|
115
|
+
) {
|
|
116
|
+
const response = await fetch(`/api/admin/updates/${encodedKey}/policy`, {
|
|
117
|
+
method: "PUT",
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({ ...policy, expectedPolicyVersion }),
|
|
120
|
+
});
|
|
121
|
+
return parseJson<UpdatePolicy>(response);
|
|
122
|
+
}
|
|
123
|
+
|
|
68
124
|
export async function deleteUpdate(encodedKey: string) {
|
|
69
125
|
const response = await fetch(`/api/admin/updates/${encodedKey}`, {
|
|
70
126
|
method: "DELETE",
|
|
@@ -172,3 +228,26 @@ export async function deleteEmergencyRedirect(id: string) {
|
|
|
172
228
|
});
|
|
173
229
|
return parseJson<{ ok: boolean }>(response);
|
|
174
230
|
}
|
|
231
|
+
|
|
232
|
+
export async function getGuardActions() {
|
|
233
|
+
const response = await fetch("/api/admin/guard-actions", {
|
|
234
|
+
cache: "no-store",
|
|
235
|
+
});
|
|
236
|
+
return parseJson<GuardActionsListResponse>(response);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export async function createGuardAction(actionKey: string) {
|
|
240
|
+
const response = await fetch("/api/admin/guard-actions", {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: { "Content-Type": "application/json" },
|
|
243
|
+
body: JSON.stringify({ actionKey }),
|
|
244
|
+
});
|
|
245
|
+
return parseJson<GuardActionItem>(response);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export async function deleteGuardAction(id: string) {
|
|
249
|
+
const response = await fetch(`/api/admin/guard-actions/${id}`, {
|
|
250
|
+
method: "DELETE",
|
|
251
|
+
});
|
|
252
|
+
return parseJson<{ ok: boolean }>(response);
|
|
253
|
+
}
|
|
@@ -16,6 +16,24 @@ export type UpdateItem = {
|
|
|
16
16
|
autoDeliveryEnabled: boolean;
|
|
17
17
|
isIgnoredByRollback: boolean;
|
|
18
18
|
assetsCount: number;
|
|
19
|
+
deliveryMode: UpdateDeliveryMode;
|
|
20
|
+
hasGuard: boolean;
|
|
21
|
+
policyVersion: number;
|
|
22
|
+
policyPublishedAt: string | null;
|
|
23
|
+
policyEditable: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type UpdateDeliveryMode = "manual" | "background";
|
|
27
|
+
export type UpdatePolicyGuard = {
|
|
28
|
+
action: string;
|
|
29
|
+
payload?: unknown;
|
|
30
|
+
};
|
|
31
|
+
export type UpdatePolicy = {
|
|
32
|
+
delivery: UpdateDeliveryMode;
|
|
33
|
+
guard: UpdatePolicyGuard | null;
|
|
34
|
+
policyVersion: number;
|
|
35
|
+
publishedAt: string | null;
|
|
36
|
+
editable: boolean;
|
|
19
37
|
};
|
|
20
38
|
|
|
21
39
|
export type UpdatesListResponse = {
|
|
@@ -36,7 +54,7 @@ export type UpdatesListResponse = {
|
|
|
36
54
|
}>;
|
|
37
55
|
};
|
|
38
56
|
|
|
39
|
-
export
|
|
57
|
+
export interface UpdateDetail extends UpdateItem {
|
|
40
58
|
updateInfo: Record<string, unknown>;
|
|
41
59
|
updateMeta: {
|
|
42
60
|
isActive: boolean;
|
|
@@ -45,7 +63,7 @@ export type UpdateDetail = UpdateItem & {
|
|
|
45
63
|
};
|
|
46
64
|
metadata: Record<string, unknown> | null;
|
|
47
65
|
channelLatest: Record<string, unknown> | null;
|
|
48
|
-
}
|
|
66
|
+
}
|
|
49
67
|
|
|
50
68
|
export type EmbeddedUpdateItem = {
|
|
51
69
|
embeddedUpdateId: string;
|
|
@@ -70,6 +88,25 @@ export type AdminSessionResponse = {
|
|
|
70
88
|
role: AdminRole;
|
|
71
89
|
};
|
|
72
90
|
|
|
91
|
+
export type DistributionControlPrincipal = {
|
|
92
|
+
type: "session" | "access-token" | "system";
|
|
93
|
+
id: string;
|
|
94
|
+
label: string;
|
|
95
|
+
role?: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type DistributionControlState = {
|
|
99
|
+
blocked: boolean;
|
|
100
|
+
version: number;
|
|
101
|
+
reason: string | null;
|
|
102
|
+
changedAt: string;
|
|
103
|
+
changedBy: DistributionControlPrincipal;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type DistributionControlResponse = DistributionControlState & {
|
|
107
|
+
canWrite: boolean;
|
|
108
|
+
};
|
|
109
|
+
|
|
73
110
|
export type EmergencyRedirectItem = {
|
|
74
111
|
id: string;
|
|
75
112
|
name: string;
|
|
@@ -93,3 +130,14 @@ export type EmergencyRedirectInput = Omit<
|
|
|
93
130
|
export type EmergencyRedirectsListResponse = {
|
|
94
131
|
items: EmergencyRedirectItem[];
|
|
95
132
|
};
|
|
133
|
+
|
|
134
|
+
export type GuardActionItem = {
|
|
135
|
+
id: string;
|
|
136
|
+
actionKey: string;
|
|
137
|
+
createdAt: string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type GuardActionsListResponse = {
|
|
141
|
+
items: GuardActionItem[];
|
|
142
|
+
canWrite: boolean;
|
|
143
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AdminApiError,
|
|
5
|
+
getDistributionControl,
|
|
6
|
+
setDistributionControl,
|
|
7
|
+
} from "./admin-api";
|
|
8
|
+
import type { DistributionControlResponse } from "./admin-types";
|
|
9
|
+
import { useCallback, useEffect, useState } from "react";
|
|
10
|
+
|
|
11
|
+
export function useDistributionControlState() {
|
|
12
|
+
const [state, setState] = useState<DistributionControlResponse | null>(null);
|
|
13
|
+
const [loading, setLoading] = useState(true);
|
|
14
|
+
const [error, setError] = useState("");
|
|
15
|
+
|
|
16
|
+
const refresh = useCallback(async () => {
|
|
17
|
+
setLoading(true);
|
|
18
|
+
try {
|
|
19
|
+
setState(await getDistributionControl());
|
|
20
|
+
setError("");
|
|
21
|
+
} catch (loadError: unknown) {
|
|
22
|
+
setError(
|
|
23
|
+
loadError instanceof Error
|
|
24
|
+
? loadError.message
|
|
25
|
+
: "Не удалось загрузить глобальный статус OTA",
|
|
26
|
+
);
|
|
27
|
+
} finally {
|
|
28
|
+
setLoading(false);
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const timeoutId = window.setTimeout(() => {
|
|
34
|
+
void refresh();
|
|
35
|
+
}, 0);
|
|
36
|
+
|
|
37
|
+
return () => window.clearTimeout(timeoutId);
|
|
38
|
+
}, [refresh]);
|
|
39
|
+
|
|
40
|
+
return { state, setState, loading, error, setError, refresh };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function formatChangedBy(state: DistributionControlResponse): string {
|
|
44
|
+
const role = state.changedBy.role ? ` (${state.changedBy.role})` : "";
|
|
45
|
+
return `${state.changedBy.label}${role}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function DistributionControlBanner({
|
|
49
|
+
state,
|
|
50
|
+
loading,
|
|
51
|
+
error,
|
|
52
|
+
}: {
|
|
53
|
+
state: DistributionControlResponse | null;
|
|
54
|
+
loading: boolean;
|
|
55
|
+
error: string;
|
|
56
|
+
}) {
|
|
57
|
+
if (loading) {
|
|
58
|
+
return (
|
|
59
|
+
<section className="rounded-xl border border-zinc-300 bg-zinc-100 p-4 text-sm dark:border-zinc-700 dark:bg-zinc-900">
|
|
60
|
+
Проверка глобального статуса OTA…
|
|
61
|
+
</section>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (error || !state) {
|
|
66
|
+
return (
|
|
67
|
+
<section className="rounded-xl border border-red-400 bg-red-50 p-4 text-sm text-red-900 dark:border-red-700 dark:bg-red-950/40 dark:text-red-200">
|
|
68
|
+
⚠️ Глобальный статус OTA недоступен. Распространяющие действия
|
|
69
|
+
отключены до восстановления связи.
|
|
70
|
+
{error ? <p className="mt-1 text-xs">{error}</p> : null}
|
|
71
|
+
</section>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!state.blocked) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<section className="rounded-xl border-2 border-red-500 bg-red-50 p-4 text-red-950 dark:bg-red-950/50 dark:text-red-100">
|
|
81
|
+
<p className="font-semibold">⛔ OTA DISTRIBUTION BLOCKED</p>
|
|
82
|
+
<p className="mt-1 text-sm">{state.reason}</p>
|
|
83
|
+
<p className="mt-2 text-xs">
|
|
84
|
+
{new Date(state.changedAt).toLocaleString("uk-UA")} ·{" "}
|
|
85
|
+
{formatChangedBy(state)}
|
|
86
|
+
</p>
|
|
87
|
+
</section>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default function DistributionControl() {
|
|
92
|
+
const { state, setState, loading, error, setError, refresh } =
|
|
93
|
+
useDistributionControlState();
|
|
94
|
+
const [reason, setReason] = useState("");
|
|
95
|
+
const [saving, setSaving] = useState(false);
|
|
96
|
+
const [message, setMessage] = useState("");
|
|
97
|
+
|
|
98
|
+
const changeState = async (blocked: boolean) => {
|
|
99
|
+
if (!state) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const normalizedReason = reason.trim();
|
|
104
|
+
if (blocked && !normalizedReason) {
|
|
105
|
+
setError("Укажите причину аварийной блокировки.");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const confirmed = window.confirm(
|
|
110
|
+
blocked
|
|
111
|
+
? "Немедленно остановить выдачу manifest и всех OTA assets для всех клиентов?"
|
|
112
|
+
: "Возобновить глобальное OTA-распространение?",
|
|
113
|
+
);
|
|
114
|
+
if (!confirmed) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setSaving(true);
|
|
119
|
+
setError("");
|
|
120
|
+
setMessage("");
|
|
121
|
+
try {
|
|
122
|
+
const updated = await setDistributionControl({
|
|
123
|
+
blocked,
|
|
124
|
+
...(blocked ? { reason: normalizedReason } : {}),
|
|
125
|
+
expectedVersion: state.version,
|
|
126
|
+
});
|
|
127
|
+
setState({ ...updated, canWrite: state.canWrite });
|
|
128
|
+
setReason("");
|
|
129
|
+
setMessage(
|
|
130
|
+
blocked
|
|
131
|
+
? "OTA-распространение остановлено."
|
|
132
|
+
: "OTA-распространение возобновлено.",
|
|
133
|
+
);
|
|
134
|
+
} catch (saveError: unknown) {
|
|
135
|
+
if (saveError instanceof AdminApiError && saveError.status === 409) {
|
|
136
|
+
await refresh();
|
|
137
|
+
setError(
|
|
138
|
+
"Состояние уже изменил другой оператор. Данные обновлены; проверьте их и повторите действие.",
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
setError(
|
|
142
|
+
saveError instanceof Error
|
|
143
|
+
? saveError.message
|
|
144
|
+
: "Не удалось изменить глобальный статус OTA",
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
} finally {
|
|
148
|
+
setSaving(false);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<section
|
|
154
|
+
className={`rounded-xl border-2 p-4 ${
|
|
155
|
+
state?.blocked
|
|
156
|
+
? "border-red-500 bg-red-50 dark:bg-red-950/50"
|
|
157
|
+
: "border-emerald-400 bg-emerald-50 dark:bg-emerald-950/30"
|
|
158
|
+
}`}
|
|
159
|
+
>
|
|
160
|
+
<div className="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">
|
|
161
|
+
<div>
|
|
162
|
+
<p className="text-xs font-semibold uppercase tracking-wider">
|
|
163
|
+
Global OTA emergency switch
|
|
164
|
+
</p>
|
|
165
|
+
<h2 className="mt-1 text-xl font-bold">
|
|
166
|
+
{loading ? "LOADING…" : state?.blocked ? "BLOCKED" : "ACTIVE"}
|
|
167
|
+
</h2>
|
|
168
|
+
{state ? (
|
|
169
|
+
<div className="mt-2 space-y-1 text-sm">
|
|
170
|
+
<p>
|
|
171
|
+
{state.blocked
|
|
172
|
+
? state.reason
|
|
173
|
+
: "Manifest и assets выдаются в обычном режиме."}
|
|
174
|
+
</p>
|
|
175
|
+
<p className="text-xs opacity-75">
|
|
176
|
+
Изменено: {new Date(state.changedAt).toLocaleString("uk-UA")} ·{" "}
|
|
177
|
+
{formatChangedBy(state)} · version {state.version}
|
|
178
|
+
</p>
|
|
179
|
+
</div>
|
|
180
|
+
) : null}
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
{state?.canWrite ? (
|
|
184
|
+
<div className="w-full max-w-xl">
|
|
185
|
+
{!state.blocked ? (
|
|
186
|
+
<textarea
|
|
187
|
+
value={reason}
|
|
188
|
+
onChange={(event) => setReason(event.target.value)}
|
|
189
|
+
maxLength={500}
|
|
190
|
+
aria-label="Причина аварийной блокировки OTA"
|
|
191
|
+
placeholder="Обязательная причина остановки (до 500 символов)"
|
|
192
|
+
className="min-h-20 w-full rounded-md border border-red-300 bg-white p-2 text-sm text-zinc-950 dark:border-red-800 dark:bg-zinc-950 dark:text-zinc-100"
|
|
193
|
+
/>
|
|
194
|
+
) : null}
|
|
195
|
+
<button
|
|
196
|
+
type="button"
|
|
197
|
+
disabled={saving || loading}
|
|
198
|
+
onClick={() => void changeState(!state.blocked)}
|
|
199
|
+
className={`mt-2 rounded-md px-4 py-3 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-60 ${
|
|
200
|
+
state.blocked
|
|
201
|
+
? "bg-emerald-700 hover:bg-emerald-800"
|
|
202
|
+
: "bg-red-700 hover:bg-red-800"
|
|
203
|
+
}`}
|
|
204
|
+
>
|
|
205
|
+
{saving
|
|
206
|
+
? "Сохранение…"
|
|
207
|
+
: state.blocked
|
|
208
|
+
? "Возобновить OTA"
|
|
209
|
+
: "Остановить все OTA"}
|
|
210
|
+
</button>
|
|
211
|
+
</div>
|
|
212
|
+
) : state ? (
|
|
213
|
+
<p className="rounded-md border border-zinc-300 px-3 py-2 text-xs dark:border-zinc-700">
|
|
214
|
+
Read-only: требуется updates:write
|
|
215
|
+
</p>
|
|
216
|
+
) : null}
|
|
217
|
+
</div>
|
|
218
|
+
|
|
219
|
+
{error ? (
|
|
220
|
+
<p className="mt-3 rounded-md bg-red-100 p-2 text-sm text-red-900 dark:bg-red-950 dark:text-red-200">
|
|
221
|
+
{error}
|
|
222
|
+
</p>
|
|
223
|
+
) : null}
|
|
224
|
+
{message ? (
|
|
225
|
+
<p className="mt-3 rounded-md bg-emerald-100 p-2 text-sm text-emerald-900 dark:bg-emerald-950 dark:text-emerald-200">
|
|
226
|
+
{message}
|
|
227
|
+
</p>
|
|
228
|
+
) : null}
|
|
229
|
+
</section>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
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="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)");
|
|
25
|
+
});
|
|
26
|
+
});
|