create-expo-updates-server 0.1.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/LICENSE +21 -0
- package/README.md +19 -0
- package/bin/create-expo-updates-server.mjs +5 -0
- package/dist/template/.env.docker.example +15 -0
- package/dist/template/.env.example +35 -0
- package/dist/template/Dockerfile +42 -0
- package/dist/template/LICENSE +21 -0
- package/dist/template/README.md +665 -0
- package/dist/template/app/api/admin/access-tokens/[id]/route.ts +25 -0
- package/dist/template/app/api/admin/access-tokens/route.test.ts +73 -0
- package/dist/template/app/api/admin/access-tokens/route.ts +90 -0
- package/dist/template/app/api/admin/embedded-updates/[embeddedUpdateId]/route.ts +25 -0
- package/dist/template/app/api/admin/embedded-updates/route.test.ts +102 -0
- package/dist/template/app/api/admin/embedded-updates/route.ts +47 -0
- package/dist/template/app/api/admin/emergency-redirects/[id]/route.ts +62 -0
- package/dist/template/app/api/admin/emergency-redirects/route.test.ts +84 -0
- package/dist/template/app/api/admin/emergency-redirects/route.ts +56 -0
- package/dist/template/app/api/admin/login/route.test.ts +55 -0
- package/dist/template/app/api/admin/login/route.ts +52 -0
- package/dist/template/app/api/admin/logout/route.ts +20 -0
- package/dist/template/app/api/admin/session/route.ts +15 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +33 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +29 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +29 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +96 -0
- package/dist/template/app/api/admin/updates/route.test.ts +142 -0
- package/dist/template/app/api/admin/updates/route.ts +32 -0
- package/dist/template/app/api/assets/route.ts +6 -0
- package/dist/template/app/api/health/route.test.ts +26 -0
- package/dist/template/app/api/health/route.ts +42 -0
- package/dist/template/app/api/manifest/route.ts +6 -0
- package/dist/template/app/api/update-complete/route.ts +6 -0
- package/dist/template/app/favicon.ico +0 -0
- package/dist/template/app/globals.css +26 -0
- package/dist/template/app/layout.tsx +34 -0
- package/dist/template/app/login/page.tsx +77 -0
- package/dist/template/app/page.tsx +12 -0
- package/dist/template/app/updates/[encodedKey]/page.tsx +482 -0
- package/dist/template/app/updates/embedded/page.tsx +164 -0
- package/dist/template/app/updates/emergency-redirects/page.tsx +430 -0
- package/dist/template/app/updates/layout.tsx +14 -0
- package/dist/template/app/updates/page.tsx +281 -0
- package/dist/template/docker-compose.yml +100 -0
- package/dist/template/docs/expo-app-setup.md +497 -0
- package/dist/template/docs/getting-started.md +502 -0
- package/dist/template/docs/getting-started.ru.md +623 -0
- package/dist/template/docs/index.md +57 -0
- package/dist/template/docs/migrations/schema.sql +363 -0
- package/dist/template/docs/npm-installer.md +83 -0
- package/dist/template/docs/operations-guide.md +270 -0
- package/dist/template/docs/ota-emergency-recovery.md +109 -0
- package/dist/template/docs/supabase-setup.md +133 -0
- package/dist/template/eslint.config.mjs +30 -0
- package/dist/template/gitignore.template +58 -0
- package/dist/template/next.config.ts +7 -0
- package/dist/template/package-lock.json +12156 -0
- package/dist/template/package.json +50 -0
- package/dist/template/postcss.config.mjs +7 -0
- package/dist/template/public/file.svg +1 -0
- package/dist/template/public/globe.svg +1 -0
- package/dist/template/public/next.svg +1 -0
- package/dist/template/public/vercel.svg +1 -0
- package/dist/template/public/window.svg +1 -0
- package/dist/template/scripts/configure-expo-app.mjs +145 -0
- package/dist/template/scripts/create-access-token.mjs +135 -0
- package/dist/template/scripts/create-admin.mjs +169 -0
- package/dist/template/scripts/import-emergency-redirects.mjs +126 -0
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +64 -0
- package/dist/template/scripts/lib/expo-app-configurator.mjs +666 -0
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +463 -0
- package/dist/template/scripts/lib/expo-app-prompts.mjs +139 -0
- package/dist/template/scripts/lib/expo-app-prompts.test.ts +97 -0
- package/dist/template/scripts/lib/expo-export-command.test.ts +31 -0
- package/dist/template/scripts/lib/ota-publish-retry.test.ts +33 -0
- package/dist/template/scripts/manage-emergency-redirect.mjs +483 -0
- package/dist/template/scripts/sync-docker-database-password.sh +16 -0
- package/dist/template/src/client/admin-api.ts +174 -0
- package/dist/template/src/client/admin-types.ts +93 -0
- package/dist/template/src/client/logout-button.tsx +31 -0
- package/dist/template/src/server/controllers/assets.ts +216 -0
- package/dist/template/src/server/controllers/manifest.test.ts +403 -0
- package/dist/template/src/server/controllers/manifest.ts +626 -0
- package/dist/template/src/server/controllers/update-complete.ts +36 -0
- package/dist/template/src/server/lib/admin-access-tokens.ts +169 -0
- package/dist/template/src/server/lib/admin-api.ts +101 -0
- package/dist/template/src/server/lib/admin-auth.ts +208 -0
- package/dist/template/src/server/lib/admin-embedded-updates.ts +150 -0
- package/dist/template/src/server/lib/admin-updates.ts +1282 -0
- package/dist/template/src/server/lib/common.js +24 -0
- package/dist/template/src/server/lib/emergency-channel-redirects.ts +310 -0
- package/dist/template/src/server/lib/env.js +8 -0
- package/dist/template/src/server/lib/manifest-helpers.js +91 -0
- package/dist/template/src/server/lib/response.js +11 -0
- package/dist/template/src/server/lib/signing.js +55 -0
- package/dist/template/src/server/lib/supabase.js +763 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +269 -0
- package/dist/template/src/server/manifest/manifest-request.ts +21 -0
- package/dist/template/src/server/manifest/manifest-response.ts +235 -0
- package/dist/template/src/server/manifest/manifest-values.ts +62 -0
- package/dist/template/templates/expo-app/.env.ota.example +18 -0
- package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +6 -0
- package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +36 -0
- package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +33 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +87 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/api/storage-client.mjs +57 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/index.mjs +182 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/common.mjs +84 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/expo-export-command.mjs +24 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/retry.mjs +25 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/shared/config.mjs +48 -0
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/android-register-embedded-update.sh +18 -0
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +275 -0
- package/dist/template/tsconfig.json +36 -0
- package/dist/template/vitest.config.mts +20 -0
- package/dist/template-manifest.json +564 -0
- package/lib/cli.mjs +549 -0
- package/package.json +41 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { getExpoExportCommand } from "../../templates/expo-app/scripts/ota-publish/lib/expo-export-command.mjs";
|
|
4
|
+
|
|
5
|
+
describe("getExpoExportCommand", () => {
|
|
6
|
+
it("invokes the local Expo binary without duplicating the expo command", () => {
|
|
7
|
+
const result = getExpoExportCommand({
|
|
8
|
+
appRoot: "/tmp/example-app",
|
|
9
|
+
outputDir: "/tmp/example-app/.ota-dist/android",
|
|
10
|
+
platform: "android",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(result.command).toBe(
|
|
14
|
+
path.join(
|
|
15
|
+
"/tmp/example-app",
|
|
16
|
+
"node_modules",
|
|
17
|
+
".bin",
|
|
18
|
+
process.platform === "win32" ? "expo.cmd" : "expo",
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
expect(result.args).toEqual([
|
|
22
|
+
"export",
|
|
23
|
+
"--clear",
|
|
24
|
+
"--platform",
|
|
25
|
+
"android",
|
|
26
|
+
"--output-dir",
|
|
27
|
+
"/tmp/example-app/.ota-dist/android",
|
|
28
|
+
]);
|
|
29
|
+
expect(result.args[0]).not.toBe("expo");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
const retryUrl = pathToFileURL(
|
|
6
|
+
path.resolve("templates/expo-app/scripts/ota-publish/lib/retry.mjs"),
|
|
7
|
+
).href;
|
|
8
|
+
|
|
9
|
+
describe("portable publisher retry", () => {
|
|
10
|
+
it("retries transient failures", async () => {
|
|
11
|
+
const { withRetry } = await import(retryUrl);
|
|
12
|
+
const task = vi
|
|
13
|
+
.fn()
|
|
14
|
+
.mockRejectedValueOnce(new Error("temporary"))
|
|
15
|
+
.mockResolvedValue("ok");
|
|
16
|
+
|
|
17
|
+
await expect(
|
|
18
|
+
withRetry("upload", task, { attempts: 3, baseDelayMs: 1 }),
|
|
19
|
+
).resolves.toBe("ok");
|
|
20
|
+
expect(task).toHaveBeenCalledTimes(2);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("surfaces the final failure", async () => {
|
|
24
|
+
const { withRetry } = await import(retryUrl);
|
|
25
|
+
const task = vi.fn(async () => {
|
|
26
|
+
throw new Error("offline");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await expect(
|
|
30
|
+
withRetry("database", task, { attempts: 2, baseDelayMs: 1 }),
|
|
31
|
+
).rejects.toThrow("database failed after 2 attempts: offline");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { createInterface } from "node:readline/promises";
|
|
5
|
+
import { stdin, stdout } from "node:process";
|
|
6
|
+
|
|
7
|
+
const CONFIG_PATH = path.resolve(
|
|
8
|
+
process.env.OTA_EMERGENCY_REDIRECT_CONFIG_PATH ||
|
|
9
|
+
path.join(process.cwd(), "config/ota-emergency-channel-redirects.json"),
|
|
10
|
+
);
|
|
11
|
+
const UUID_PATTERN =
|
|
12
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
13
|
+
|
|
14
|
+
function parseArgs(argv) {
|
|
15
|
+
const [command, ...rest] = argv;
|
|
16
|
+
const options = {};
|
|
17
|
+
|
|
18
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
19
|
+
const argument = rest[index];
|
|
20
|
+
if (!argument.startsWith("--")) {
|
|
21
|
+
throw new Error(`Unexpected argument: ${argument}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const key = argument.slice(2);
|
|
25
|
+
const value = rest[index + 1];
|
|
26
|
+
if (!value || value.startsWith("--")) {
|
|
27
|
+
throw new Error(`Missing value for --${key}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
options[key] = value;
|
|
31
|
+
index += 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { command, options };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readRules() {
|
|
38
|
+
return JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function writeRules(rules) {
|
|
42
|
+
fs.writeFileSync(CONFIG_PATH, `${JSON.stringify(rules, null, 2)}\n`, "utf8");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function printRules(rules) {
|
|
46
|
+
if (rules.length === 0) {
|
|
47
|
+
console.log("No emergency redirects configured.");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const rule of rules) {
|
|
52
|
+
console.log(
|
|
53
|
+
[
|
|
54
|
+
`${rule.enabled ? "[enabled]" : "[disabled]"} ${rule.id}`,
|
|
55
|
+
` ${rule.platform} runtime=${rule.runtimeVersion}`,
|
|
56
|
+
` ${rule.fromChannel} -> ${rule.toChannel}`,
|
|
57
|
+
` target mode=${rule.targetMode}`,
|
|
58
|
+
` embedded=${rule.embeddedUpdateId}`,
|
|
59
|
+
` expected OTA=${rule.expectedUpdateId}`,
|
|
60
|
+
].join("\n"),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function required(options, key) {
|
|
66
|
+
const value = options[key]?.trim();
|
|
67
|
+
if (!value) {
|
|
68
|
+
throw new Error(`Missing required --${key}`);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function assertUuid(name, value) {
|
|
74
|
+
if (!UUID_PATTERN.test(value)) {
|
|
75
|
+
throw new Error(`${name} must be a UUID`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function addRule(options) {
|
|
80
|
+
const id = required(options, "id");
|
|
81
|
+
const embeddedUpdateId = required(options, "embedded-update-id").toLowerCase();
|
|
82
|
+
const runtimeVersion = required(options, "runtime-version");
|
|
83
|
+
const platform = required(options, "platform").toLowerCase();
|
|
84
|
+
const fromChannel = required(options, "from-channel").toLowerCase();
|
|
85
|
+
const toChannel = required(options, "to-channel").toLowerCase();
|
|
86
|
+
const expectedUpdateId = required(
|
|
87
|
+
options,
|
|
88
|
+
"expected-update-id",
|
|
89
|
+
).toLowerCase();
|
|
90
|
+
const targetMode = (options["target-mode"] || "pinned").toLowerCase();
|
|
91
|
+
|
|
92
|
+
assertUuid("embedded-update-id", embeddedUpdateId);
|
|
93
|
+
assertUuid("expected-update-id", expectedUpdateId);
|
|
94
|
+
|
|
95
|
+
if (platform !== "android" && platform !== "ios") {
|
|
96
|
+
throw new Error("platform must be android or ios");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (fromChannel === toChannel) {
|
|
100
|
+
throw new Error("from-channel and to-channel must differ");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (targetMode !== "pinned" && targetMode !== "follow") {
|
|
104
|
+
throw new Error("target-mode must be pinned or follow");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const rules = readRules();
|
|
108
|
+
if (rules.some((rule) => rule.id === id)) {
|
|
109
|
+
throw new Error(`Rule already exists: ${id}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
rules.push({
|
|
113
|
+
id,
|
|
114
|
+
enabled: true,
|
|
115
|
+
embeddedUpdateId,
|
|
116
|
+
runtimeVersion,
|
|
117
|
+
platform,
|
|
118
|
+
fromChannel,
|
|
119
|
+
toChannel,
|
|
120
|
+
targetMode,
|
|
121
|
+
expectedUpdateId,
|
|
122
|
+
});
|
|
123
|
+
writeRules(rules);
|
|
124
|
+
console.log(`Added emergency redirect: ${id}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function removeRule(options) {
|
|
128
|
+
const id = required(options, "id");
|
|
129
|
+
const rules = readRules();
|
|
130
|
+
const nextRules = rules.filter((rule) => rule.id !== id);
|
|
131
|
+
|
|
132
|
+
if (nextRules.length === rules.length) {
|
|
133
|
+
throw new Error(`Rule not found: ${id}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
writeRules(nextRules);
|
|
137
|
+
console.log(`Removed emergency redirect: ${id}`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function setRuleEnabled(options, enabled) {
|
|
141
|
+
const id = required(options, "id");
|
|
142
|
+
const rules = readRules();
|
|
143
|
+
const rule = rules.find((candidate) => candidate.id === id);
|
|
144
|
+
|
|
145
|
+
if (!rule) {
|
|
146
|
+
throw new Error(`Rule not found: ${id}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
rule.enabled = enabled;
|
|
150
|
+
writeRules(rules);
|
|
151
|
+
console.log(`${enabled ? "Enabled" : "Disabled"} emergency redirect: ${id}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function setRuleTargetMode(options, targetMode) {
|
|
155
|
+
const id = required(options, "id");
|
|
156
|
+
const rules = readRules();
|
|
157
|
+
const rule = rules.find((candidate) => candidate.id === id);
|
|
158
|
+
|
|
159
|
+
if (!rule) {
|
|
160
|
+
throw new Error(`Rule not found: ${id}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (targetMode === "pinned" && options["expected-update-id"]) {
|
|
164
|
+
const expectedUpdateId = options["expected-update-id"].toLowerCase();
|
|
165
|
+
assertUuid("expected-update-id", expectedUpdateId);
|
|
166
|
+
rule.expectedUpdateId = expectedUpdateId;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
rule.targetMode = targetMode;
|
|
170
|
+
writeRules(rules);
|
|
171
|
+
console.log(`Set emergency redirect "${id}" to ${targetMode} mode`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function runCommand(command, args) {
|
|
175
|
+
const result = spawnSync(command, args, {
|
|
176
|
+
cwd: process.cwd(),
|
|
177
|
+
stdio: "inherit",
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (result.status !== 0) {
|
|
181
|
+
throw new Error(`${command} ${args.join(" ")} failed`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function ask(terminal, question, defaultValue = "") {
|
|
186
|
+
const suffix = defaultValue ? ` [${defaultValue}]` : "";
|
|
187
|
+
const answer = (await terminal.question(`${question}${suffix}: `)).trim();
|
|
188
|
+
return answer || defaultValue;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function confirm(terminal, question, defaultValue = false) {
|
|
192
|
+
const hint = defaultValue ? "Y/n" : "y/N";
|
|
193
|
+
const answer = (
|
|
194
|
+
await terminal.question(`${question} (${hint}): `)
|
|
195
|
+
).trim().toLowerCase();
|
|
196
|
+
|
|
197
|
+
if (!answer) {
|
|
198
|
+
return defaultValue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return answer === "y" || answer === "yes";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function printActions() {
|
|
205
|
+
console.log(
|
|
206
|
+
[
|
|
207
|
+
"Choose an action:",
|
|
208
|
+
" 1. List redirects",
|
|
209
|
+
" 2. Add redirect",
|
|
210
|
+
" 3. Enable redirect",
|
|
211
|
+
" 4. Disable redirect",
|
|
212
|
+
" 5. Remove redirect",
|
|
213
|
+
" 6. Pin redirect to one OTA",
|
|
214
|
+
" 7. Follow target channel",
|
|
215
|
+
" 8. Exit",
|
|
216
|
+
].join("\n"),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function normalizeAction(value) {
|
|
221
|
+
const actions = {
|
|
222
|
+
"1": "list",
|
|
223
|
+
"2": "add",
|
|
224
|
+
"3": "enable",
|
|
225
|
+
"4": "disable",
|
|
226
|
+
"5": "remove",
|
|
227
|
+
"6": "pin",
|
|
228
|
+
"7": "follow",
|
|
229
|
+
"8": "exit",
|
|
230
|
+
list: "list",
|
|
231
|
+
add: "add",
|
|
232
|
+
enable: "enable",
|
|
233
|
+
disable: "disable",
|
|
234
|
+
remove: "remove",
|
|
235
|
+
pin: "pin",
|
|
236
|
+
follow: "follow",
|
|
237
|
+
exit: "exit",
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
return actions[value.toLowerCase()] || null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async function promptForRule(terminal) {
|
|
244
|
+
const platform = await ask(terminal, "Platform", "android");
|
|
245
|
+
const runtimeVersion = await ask(
|
|
246
|
+
terminal,
|
|
247
|
+
"Runtime version from the device request",
|
|
248
|
+
);
|
|
249
|
+
const embeddedUpdateId = await ask(
|
|
250
|
+
terminal,
|
|
251
|
+
"Affected expo-embedded-update-id",
|
|
252
|
+
);
|
|
253
|
+
const fromChannel = await ask(
|
|
254
|
+
terminal,
|
|
255
|
+
"Incorrect channel requested by the binary",
|
|
256
|
+
"development",
|
|
257
|
+
);
|
|
258
|
+
const toChannel = await ask(
|
|
259
|
+
terminal,
|
|
260
|
+
"Channel containing the recovery OTA",
|
|
261
|
+
"production",
|
|
262
|
+
);
|
|
263
|
+
const expectedUpdateId = await ask(
|
|
264
|
+
terminal,
|
|
265
|
+
"Production OTA update ID that must be served",
|
|
266
|
+
);
|
|
267
|
+
const targetMode = await ask(
|
|
268
|
+
terminal,
|
|
269
|
+
"Target mode: pinned for rescue, follow for normal future OTA",
|
|
270
|
+
"pinned",
|
|
271
|
+
);
|
|
272
|
+
const suggestedId =
|
|
273
|
+
`${platform}-${runtimeVersion}-${fromChannel}-to-${toChannel}`.replace(
|
|
274
|
+
/[^a-zA-Z0-9-]+/g,
|
|
275
|
+
"-",
|
|
276
|
+
);
|
|
277
|
+
const id = await ask(terminal, "Rule name", suggestedId);
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
id,
|
|
281
|
+
"embedded-update-id": embeddedUpdateId,
|
|
282
|
+
"runtime-version": runtimeVersion,
|
|
283
|
+
platform,
|
|
284
|
+
"from-channel": fromChannel,
|
|
285
|
+
"to-channel": toChannel,
|
|
286
|
+
"target-mode": targetMode,
|
|
287
|
+
"expected-update-id": expectedUpdateId,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function runPostChangeFlow(terminal) {
|
|
292
|
+
const shouldValidate = await confirm(
|
|
293
|
+
terminal,
|
|
294
|
+
"Run lint and production build locally",
|
|
295
|
+
true,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
if (shouldValidate) {
|
|
299
|
+
runCommand("npm", [
|
|
300
|
+
"run",
|
|
301
|
+
"lint",
|
|
302
|
+
"--",
|
|
303
|
+
"--quiet",
|
|
304
|
+
"src/server/controllers/manifest.ts",
|
|
305
|
+
"src/server/lib/emergency-channel-redirects.ts",
|
|
306
|
+
"scripts/manage-emergency-redirect.mjs",
|
|
307
|
+
]);
|
|
308
|
+
runCommand("npm", ["run", "build"]);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const shouldDeploy = await confirm(
|
|
312
|
+
terminal,
|
|
313
|
+
"Deploy this redirect configuration to production",
|
|
314
|
+
false,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
if (!shouldDeploy) {
|
|
318
|
+
console.log("Production was not changed.");
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const confirmation = await ask(
|
|
323
|
+
terminal,
|
|
324
|
+
'Type "DEPLOY PRODUCTION" to continue',
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
if (confirmation !== "DEPLOY PRODUCTION") {
|
|
328
|
+
console.log("Deployment cancelled.");
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
runCommand("vercel", ["--prod", "--yes"]);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function runInteractive() {
|
|
336
|
+
const terminal = createInterface({ input: stdin, output: stdout });
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
console.log("OTA Emergency Redirect Wizard\n");
|
|
340
|
+
printActions();
|
|
341
|
+
const action = normalizeAction(
|
|
342
|
+
await ask(terminal, "Action", "1"),
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
if (!action) {
|
|
346
|
+
throw new Error("Unknown action");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (action === "exit") {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (action === "list") {
|
|
354
|
+
printRules(readRules());
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (action === "add") {
|
|
359
|
+
const options = await promptForRule(terminal);
|
|
360
|
+
console.log("\nRule to add:");
|
|
361
|
+
printRules([
|
|
362
|
+
{
|
|
363
|
+
id: options.id,
|
|
364
|
+
enabled: true,
|
|
365
|
+
embeddedUpdateId: options["embedded-update-id"],
|
|
366
|
+
runtimeVersion: options["runtime-version"],
|
|
367
|
+
platform: options.platform,
|
|
368
|
+
fromChannel: options["from-channel"],
|
|
369
|
+
toChannel: options["to-channel"],
|
|
370
|
+
targetMode: options["target-mode"],
|
|
371
|
+
expectedUpdateId: options["expected-update-id"],
|
|
372
|
+
},
|
|
373
|
+
]);
|
|
374
|
+
|
|
375
|
+
if (!(await confirm(terminal, "Write this rule", false))) {
|
|
376
|
+
console.log("No changes made.");
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
addRule(options);
|
|
381
|
+
await runPostChangeFlow(terminal);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const rules = readRules();
|
|
386
|
+
printRules(rules);
|
|
387
|
+
const id = await ask(terminal, "Rule name");
|
|
388
|
+
|
|
389
|
+
if (action === "remove") {
|
|
390
|
+
if (!(await confirm(terminal, `Remove "${id}"`, false))) {
|
|
391
|
+
console.log("No changes made.");
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
removeRule({ id });
|
|
395
|
+
} else if (action === "pin") {
|
|
396
|
+
const expectedUpdateId = await ask(
|
|
397
|
+
terminal,
|
|
398
|
+
"OTA update ID to pin",
|
|
399
|
+
rules.find((rule) => rule.id === id)?.expectedUpdateId || "",
|
|
400
|
+
);
|
|
401
|
+
setRuleTargetMode(
|
|
402
|
+
{ id, "expected-update-id": expectedUpdateId },
|
|
403
|
+
"pinned",
|
|
404
|
+
);
|
|
405
|
+
} else if (action === "follow") {
|
|
406
|
+
setRuleTargetMode({ id }, "follow");
|
|
407
|
+
} else {
|
|
408
|
+
setRuleEnabled({ id }, action === "enable");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
await runPostChangeFlow(terminal);
|
|
412
|
+
} finally {
|
|
413
|
+
terminal.close();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function printHelp() {
|
|
418
|
+
console.log(
|
|
419
|
+
[
|
|
420
|
+
"Interactive mode:",
|
|
421
|
+
" npm run emergency:redirect",
|
|
422
|
+
"",
|
|
423
|
+
"Automation:",
|
|
424
|
+
" npm run emergency:redirect -- list",
|
|
425
|
+
" npm run emergency:redirect -- add --id NAME --embedded-update-id UUID --runtime-version VERSION --platform android --from-channel development --to-channel production --target-mode pinned --expected-update-id UUID",
|
|
426
|
+
" npm run emergency:redirect -- enable --id NAME",
|
|
427
|
+
" npm run emergency:redirect -- disable --id NAME",
|
|
428
|
+
" npm run emergency:redirect -- pin --id NAME --expected-update-id UUID",
|
|
429
|
+
" npm run emergency:redirect -- follow --id NAME",
|
|
430
|
+
" npm run emergency:redirect -- remove --id NAME",
|
|
431
|
+
].join("\n"),
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async function main() {
|
|
436
|
+
const { command, options } = parseArgs(process.argv.slice(2));
|
|
437
|
+
|
|
438
|
+
if (!command) {
|
|
439
|
+
await runInteractive();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (command === "--help" || command === "help") {
|
|
444
|
+
printHelp();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (command === "list") {
|
|
449
|
+
printRules(readRules());
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (command === "add") {
|
|
454
|
+
addRule(options);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (command === "remove") {
|
|
459
|
+
removeRule(options);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (command === "enable" || command === "disable") {
|
|
464
|
+
setRuleEnabled(options, command === "enable");
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (command === "pin" || command === "follow") {
|
|
469
|
+
setRuleTargetMode(options, command === "pin" ? "pinned" : "follow");
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
throw new Error(
|
|
474
|
+
"Use: list, add, remove, enable, disable, pin, or follow",
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
try {
|
|
479
|
+
await main();
|
|
480
|
+
} catch (error) {
|
|
481
|
+
console.error(`Emergency redirect command failed: ${error.message}`);
|
|
482
|
+
process.exit(1);
|
|
483
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -eu
|
|
4
|
+
|
|
5
|
+
docker compose exec -T postgres sh -c '
|
|
6
|
+
psql \
|
|
7
|
+
-v ON_ERROR_STOP=1 \
|
|
8
|
+
-v db_user="$POSTGRES_USER" \
|
|
9
|
+
-v db_password="$POSTGRES_PASSWORD" \
|
|
10
|
+
-U "$POSTGRES_USER" \
|
|
11
|
+
-d "$POSTGRES_DB"
|
|
12
|
+
' <<'SQL'
|
|
13
|
+
ALTER ROLE :"db_user" WITH PASSWORD :'db_password';
|
|
14
|
+
SQL
|
|
15
|
+
|
|
16
|
+
echo "Docker PostgreSQL password synchronized with .env."
|