create-expo-updates-server 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/template/.env.docker.example +1 -0
  2. package/dist/template/.env.example +2 -0
  3. package/dist/template/README.md +16 -8
  4. package/dist/template/app/api/admin/distribution-control/route.test.ts +153 -0
  5. package/dist/template/app/api/admin/distribution-control/route.ts +111 -0
  6. package/dist/template/app/api/admin/embedded-updates/route.test.ts +36 -1
  7. package/dist/template/app/api/admin/guard-actions/[id]/route.test.ts +60 -0
  8. package/dist/template/app/api/admin/guard-actions/[id]/route.ts +32 -0
  9. package/dist/template/app/api/admin/guard-actions/route.test.ts +123 -0
  10. package/dist/template/app/api/admin/guard-actions/route.ts +66 -0
  11. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +4 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.test.ts +171 -0
  13. package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.ts +75 -0
  14. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +4 -1
  15. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +4 -1
  16. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +4 -1
  17. package/dist/template/app/api/admin/updates/route.test.ts +29 -1
  18. package/dist/template/app/updates/[encodedKey]/page.tsx +74 -6
  19. package/dist/template/app/updates/embedded/page.tsx +6 -2
  20. package/dist/template/app/updates/page.tsx +28 -3
  21. package/dist/template/docs/expo-app-setup.md +14 -3
  22. package/dist/template/docs/getting-started.md +13 -7
  23. package/dist/template/docs/getting-started.ru.md +15 -7
  24. package/dist/template/docs/migrations/2026-09-01-app-version-columns.sql +23 -0
  25. package/dist/template/docs/migrations/2026-09-01-ota-update-policy.sql +108 -0
  26. package/dist/template/docs/migrations/2026-09-01-p1-guard-actions.sql +19 -0
  27. package/dist/template/docs/migrations/2026-09-01-p2-simplify-ota-guard-policy.sql +69 -0
  28. package/dist/template/docs/migrations/2026-09-01-policy-publication-correction.sql +44 -0
  29. package/dist/template/docs/migrations/2026-09-02-ota-distribution-control.sql +377 -0
  30. package/dist/template/docs/migrations/schema.sql +561 -2
  31. package/dist/template/docs/operations-guide.md +52 -1
  32. package/dist/template/docs/ota-emergency-recovery.md +22 -0
  33. package/dist/template/docs/ota-update-policy.md +89 -0
  34. package/dist/template/docs/supabase-setup.md +2 -1
  35. package/dist/template/package-lock.json +2 -2
  36. package/dist/template/package.json +1 -1
  37. package/dist/template/scripts/configure-expo-app.mjs +6 -0
  38. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +383 -3
  39. package/dist/template/scripts/lib/expo-app-configurator.mjs +165 -9
  40. package/dist/template/scripts/lib/expo-app-configurator.test.ts +658 -9
  41. package/dist/template/src/client/admin-api.ts +80 -1
  42. package/dist/template/src/client/admin-types.ts +52 -2
  43. package/dist/template/src/client/distribution-control.tsx +231 -0
  44. package/dist/template/src/client/guard-action-combobox.test.ts +26 -0
  45. package/dist/template/src/client/guard-action-combobox.tsx +267 -0
  46. package/dist/template/src/client/guard-action-options.test.ts +62 -0
  47. package/dist/template/src/client/guard-action-options.ts +70 -0
  48. package/dist/template/src/client/update-policy-editor.test.ts +36 -0
  49. package/dist/template/src/client/update-policy-editor.tsx +436 -0
  50. package/dist/template/src/server/controllers/assets.test.ts +87 -0
  51. package/dist/template/src/server/controllers/assets.ts +26 -0
  52. package/dist/template/src/server/controllers/manifest.test.ts +413 -2
  53. package/dist/template/src/server/controllers/manifest.ts +103 -38
  54. package/dist/template/src/server/lib/admin-distribution-guard.test.ts +61 -0
  55. package/dist/template/src/server/lib/admin-embedded-updates.test.ts +57 -0
  56. package/dist/template/src/server/lib/admin-embedded-updates.ts +42 -25
  57. package/dist/template/src/server/lib/admin-update-policy.test.ts +176 -0
  58. package/dist/template/src/server/lib/admin-updates.test.ts +133 -0
  59. package/dist/template/src/server/lib/admin-updates.ts +174 -9
  60. package/dist/template/src/server/lib/distribution-control-migration.test.ts +94 -0
  61. package/dist/template/src/server/lib/distribution-control.test.ts +160 -0
  62. package/dist/template/src/server/lib/distribution-control.ts +250 -0
  63. package/dist/template/src/server/lib/guard-actions-migration.test.ts +56 -0
  64. package/dist/template/src/server/lib/guard-actions.test.ts +142 -0
  65. package/dist/template/src/server/lib/guard-actions.ts +106 -0
  66. package/dist/template/src/server/lib/ota-policy-migrations.test.ts +64 -0
  67. package/dist/template/src/server/lib/simple-policy-migration.test.ts +97 -0
  68. package/dist/template/src/server/lib/supabase.js +95 -8
  69. package/dist/template/src/server/lib/supabase.test.ts +194 -0
  70. package/dist/template/src/server/lib/update-policy.test.ts +98 -0
  71. package/dist/template/src/server/lib/update-policy.ts +171 -0
  72. package/dist/template/src/server/manifest/manifest-repository.ts +10 -1
  73. package/dist/template/src/server/manifest/manifest-response.ts +0 -16
  74. package/dist/template/src/server/manifest/manifest-values.test.ts +54 -0
  75. package/dist/template/src/server/manifest/manifest-values.ts +145 -0
  76. package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +23 -1
  77. package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +13 -4
  78. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +53 -7
  79. package/dist/template/templates/expo-app/scripts/ota-register-embedded/register-ios.sh +87 -0
  80. package/dist/template/tsconfig.json +4 -1
  81. package/dist/template-manifest.json +283 -88
  82. package/package.json +1 -1
  83. package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +0 -36
  84. /package/dist/template/templates/expo-app/scripts/ota-register-embedded/{android-register-embedded-update.sh → register-android.sh} +0 -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 Error(message);
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
+ }
@@ -1,6 +1,7 @@
1
1
  export type UpdateItem = {
2
2
  key: string;
3
3
  encodedKey: string;
4
+ appVersion: string | null;
4
5
  comment: string | null;
5
6
  runtimeVersion: string;
6
7
  platform: "ios" | "android";
@@ -15,6 +16,24 @@ export type UpdateItem = {
15
16
  autoDeliveryEnabled: boolean;
16
17
  isIgnoredByRollback: boolean;
17
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;
18
37
  };
19
38
 
20
39
  export type UpdatesListResponse = {
@@ -35,7 +54,7 @@ export type UpdatesListResponse = {
35
54
  }>;
36
55
  };
37
56
 
38
- export type UpdateDetail = UpdateItem & {
57
+ export interface UpdateDetail extends UpdateItem {
39
58
  updateInfo: Record<string, unknown>;
40
59
  updateMeta: {
41
60
  isActive: boolean;
@@ -44,10 +63,11 @@ export type UpdateDetail = UpdateItem & {
44
63
  };
45
64
  metadata: Record<string, unknown> | null;
46
65
  channelLatest: Record<string, unknown> | null;
47
- };
66
+ }
48
67
 
49
68
  export type EmbeddedUpdateItem = {
50
69
  embeddedUpdateId: string;
70
+ appVersion: string | null;
51
71
  createdAt: string;
52
72
  channel: string;
53
73
  platform: "ios" | "android";
@@ -68,6 +88,25 @@ export type AdminSessionResponse = {
68
88
  role: AdminRole;
69
89
  };
70
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
+
71
110
  export type EmergencyRedirectItem = {
72
111
  id: string;
73
112
  name: string;
@@ -91,3 +130,14 @@ export type EmergencyRedirectInput = Omit<
91
130
  export type EmergencyRedirectsListResponse = {
92
131
  items: EmergencyRedirectItem[];
93
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
+ });