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,269 @@
|
|
|
1
|
+
import { supabase } from "../lib/supabase.js";
|
|
2
|
+
|
|
3
|
+
export type OtaUpdateRow = {
|
|
4
|
+
update_id: string;
|
|
5
|
+
build_id: string;
|
|
6
|
+
runtime_version: string;
|
|
7
|
+
channel: string;
|
|
8
|
+
platform: "ios" | "android";
|
|
9
|
+
created_at: string | Date;
|
|
10
|
+
created_at_path: string;
|
|
11
|
+
storage_base_path: string;
|
|
12
|
+
is_active: boolean;
|
|
13
|
+
manifest: Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type OtaChannelRow = {
|
|
17
|
+
latest_update_id: string | null;
|
|
18
|
+
active_update_id: string | null;
|
|
19
|
+
active_changed_at: string | Date | null;
|
|
20
|
+
served_manifest_id: string;
|
|
21
|
+
served_manifest_changed_at: string | Date;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type EmbeddedUpdateMeta = {
|
|
25
|
+
embedded_update_id: string;
|
|
26
|
+
created_at: string | Date;
|
|
27
|
+
channel: string;
|
|
28
|
+
platform: "ios" | "android";
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let hasServedManifestLogTable: boolean | null = null;
|
|
32
|
+
|
|
33
|
+
function isMissingServedManifestLogTableError(error: unknown): boolean {
|
|
34
|
+
if (!error || typeof error !== "object") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const message =
|
|
39
|
+
"message" in error && typeof error.message === "string"
|
|
40
|
+
? error.message.toLowerCase()
|
|
41
|
+
: "";
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
message.includes("ota_served_manifest_log") &&
|
|
45
|
+
message.includes("does not exist")
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function resolveManifestId(
|
|
50
|
+
servedManifestId: string | null,
|
|
51
|
+
updateId: string,
|
|
52
|
+
): string {
|
|
53
|
+
return hasServedManifestLogTable === true && servedManifestId
|
|
54
|
+
? servedManifestId
|
|
55
|
+
: updateId;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function resolveUpdateIdFromServedManifestId(
|
|
59
|
+
servedManifestId: string,
|
|
60
|
+
): Promise<string | null> {
|
|
61
|
+
if (hasServedManifestLogTable === false) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const { data, error } = await supabase
|
|
67
|
+
.from("ota_served_manifest_log")
|
|
68
|
+
.select("update_id")
|
|
69
|
+
.eq("served_manifest_id", servedManifestId)
|
|
70
|
+
.maybeSingle();
|
|
71
|
+
|
|
72
|
+
if (isMissingServedManifestLogTableError(error)) {
|
|
73
|
+
hasServedManifestLogTable = false;
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (error || !data) {
|
|
78
|
+
if (hasServedManifestLogTable === null) {
|
|
79
|
+
hasServedManifestLogTable = true;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
hasServedManifestLogTable = true;
|
|
85
|
+
return (data as { update_id: string }).update_id || null;
|
|
86
|
+
} catch (error: unknown) {
|
|
87
|
+
if (isMissingServedManifestLogTableError(error)) {
|
|
88
|
+
hasServedManifestLogTable = false;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function logServedManifest({
|
|
95
|
+
servedManifestId,
|
|
96
|
+
updateId,
|
|
97
|
+
runtimeVersion,
|
|
98
|
+
channel,
|
|
99
|
+
platform,
|
|
100
|
+
reason,
|
|
101
|
+
}: {
|
|
102
|
+
servedManifestId: string;
|
|
103
|
+
updateId: string;
|
|
104
|
+
runtimeVersion: string;
|
|
105
|
+
channel: string;
|
|
106
|
+
platform: string;
|
|
107
|
+
reason: string;
|
|
108
|
+
}): void {
|
|
109
|
+
if (hasServedManifestLogTable === false) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
supabase
|
|
114
|
+
.from("ota_served_manifest_log")
|
|
115
|
+
.upsert(
|
|
116
|
+
{
|
|
117
|
+
served_manifest_id: servedManifestId,
|
|
118
|
+
update_id: updateId,
|
|
119
|
+
runtime_version: runtimeVersion,
|
|
120
|
+
channel,
|
|
121
|
+
platform,
|
|
122
|
+
reason,
|
|
123
|
+
},
|
|
124
|
+
{ onConflict: "served_manifest_id" },
|
|
125
|
+
)
|
|
126
|
+
.then(({ error }) => {
|
|
127
|
+
if (isMissingServedManifestLogTableError(error)) {
|
|
128
|
+
hasServedManifestLogTable = false;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!error && hasServedManifestLogTable === null) {
|
|
133
|
+
hasServedManifestLogTable = true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (
|
|
137
|
+
error &&
|
|
138
|
+
!error.message?.includes("duplicate") &&
|
|
139
|
+
!error.message?.includes("unique")
|
|
140
|
+
) {
|
|
141
|
+
console.warn(
|
|
142
|
+
`[${new Date().toLocaleTimeString()}] ⚠️ Failed to log served manifest: ${error.message}`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
.catch(() => undefined);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function getChannelRow({
|
|
150
|
+
runtimeVersion,
|
|
151
|
+
channel,
|
|
152
|
+
platform,
|
|
153
|
+
}: {
|
|
154
|
+
runtimeVersion: string;
|
|
155
|
+
channel: string;
|
|
156
|
+
platform: "ios" | "android";
|
|
157
|
+
}): Promise<OtaChannelRow | null> {
|
|
158
|
+
const { data, error } = await supabase
|
|
159
|
+
.from("ota_update_channels")
|
|
160
|
+
.select(
|
|
161
|
+
"latest_update_id,active_update_id,active_changed_at,served_manifest_id,served_manifest_changed_at",
|
|
162
|
+
)
|
|
163
|
+
.eq("runtime_version", runtimeVersion)
|
|
164
|
+
.eq("channel", channel)
|
|
165
|
+
.eq("platform", platform)
|
|
166
|
+
.maybeSingle();
|
|
167
|
+
|
|
168
|
+
if (error) {
|
|
169
|
+
throw new Error(`Failed to load channel state: ${error.message}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return (data as OtaChannelRow | null) || null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export async function getUpdateByUpdateId(
|
|
176
|
+
updateId: string,
|
|
177
|
+
): Promise<OtaUpdateRow | null> {
|
|
178
|
+
const { data, error } = await supabase
|
|
179
|
+
.from("ota_updates")
|
|
180
|
+
.select("*")
|
|
181
|
+
.eq("update_id", updateId)
|
|
182
|
+
.maybeSingle();
|
|
183
|
+
|
|
184
|
+
if (error) {
|
|
185
|
+
throw new Error(`Failed to load update row: ${error.message}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return (data as OtaUpdateRow | null) || null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function getEmbeddedUpdateMetaById(
|
|
192
|
+
embeddedUpdateId: string,
|
|
193
|
+
): Promise<EmbeddedUpdateMeta | null> {
|
|
194
|
+
const { data, error } = await supabase
|
|
195
|
+
.from("ota_embedded_updates")
|
|
196
|
+
.select("embedded_update_id,created_at,channel,platform")
|
|
197
|
+
.eq("embedded_update_id", embeddedUpdateId)
|
|
198
|
+
.maybeSingle();
|
|
199
|
+
|
|
200
|
+
if (error) {
|
|
201
|
+
throw new Error(`Failed to load embedded update row: ${error.message}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return (data as EmbeddedUpdateMeta | null) || null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function resolveDeviceUpdateRow(
|
|
208
|
+
deviceUpdateId: string,
|
|
209
|
+
): Promise<OtaUpdateRow | null> {
|
|
210
|
+
const directUpdate = await getUpdateByUpdateId(deviceUpdateId);
|
|
211
|
+
if (directUpdate) {
|
|
212
|
+
return directUpdate;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const resolvedUpdateId =
|
|
216
|
+
await resolveUpdateIdFromServedManifestId(deviceUpdateId);
|
|
217
|
+
if (!resolvedUpdateId || resolvedUpdateId === deviceUpdateId) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return getUpdateByUpdateId(resolvedUpdateId);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function toEmbeddedUpdateMeta(updateRow: OtaUpdateRow): EmbeddedUpdateMeta {
|
|
225
|
+
return {
|
|
226
|
+
embedded_update_id: updateRow.update_id,
|
|
227
|
+
created_at: updateRow.created_at,
|
|
228
|
+
channel: updateRow.channel,
|
|
229
|
+
platform: updateRow.platform,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export async function resolveDeviceBaselineMeta(
|
|
234
|
+
deviceUpdateId: string,
|
|
235
|
+
): Promise<EmbeddedUpdateMeta | null> {
|
|
236
|
+
const otaUpdate = await resolveDeviceUpdateRow(deviceUpdateId);
|
|
237
|
+
return otaUpdate
|
|
238
|
+
? toEmbeddedUpdateMeta(otaUpdate)
|
|
239
|
+
: getEmbeddedUpdateMetaById(deviceUpdateId);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export async function getLatestActiveUpdate({
|
|
243
|
+
runtimeVersion,
|
|
244
|
+
channel,
|
|
245
|
+
platform,
|
|
246
|
+
}: {
|
|
247
|
+
runtimeVersion: string;
|
|
248
|
+
channel: string;
|
|
249
|
+
platform: "ios" | "android";
|
|
250
|
+
}): Promise<OtaUpdateRow | null> {
|
|
251
|
+
const { data, error } = await supabase
|
|
252
|
+
.from("ota_updates")
|
|
253
|
+
.select("*")
|
|
254
|
+
.eq("runtime_version", runtimeVersion)
|
|
255
|
+
.eq("channel", channel)
|
|
256
|
+
.eq("platform", platform)
|
|
257
|
+
.eq("is_active", true)
|
|
258
|
+
.order("created_at", { ascending: false })
|
|
259
|
+
.limit(1)
|
|
260
|
+
.maybeSingle();
|
|
261
|
+
|
|
262
|
+
if (error) {
|
|
263
|
+
throw new Error(
|
|
264
|
+
`Failed to load latest active update row: ${error.message}`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return (data as OtaUpdateRow | null) || null;
|
|
269
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NextRequest } from "next/server";
|
|
2
|
+
|
|
3
|
+
function normalizeChannel(value: string | null): string | null {
|
|
4
|
+
const normalized = value?.trim().toLowerCase();
|
|
5
|
+
return normalized || null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getRequestedChannel(request: NextRequest): string {
|
|
9
|
+
const channel = normalizeChannel(
|
|
10
|
+
request.headers.get("expo-channel-name"),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (!channel) {
|
|
14
|
+
console.warn(
|
|
15
|
+
`[${new Date().toLocaleTimeString()}] ⚠️ Missing or invalid expo-channel-name header. Returning "production" channel.`,
|
|
16
|
+
);
|
|
17
|
+
return "production";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return channel;
|
|
21
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import NodeFormData from "form-data";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { NextRequest } from "next/server";
|
|
4
|
+
import { toPosixPath } from "../lib/manifest-helpers.js";
|
|
5
|
+
import { createSignatureHeaderIfRequested } from "../lib/signing.js";
|
|
6
|
+
|
|
7
|
+
const CONTENT_TYPE_BY_EXTENSION: Record<string, string> = {
|
|
8
|
+
png: "image/png",
|
|
9
|
+
jpg: "image/jpeg",
|
|
10
|
+
jpeg: "image/jpeg",
|
|
11
|
+
webp: "image/webp",
|
|
12
|
+
svg: "image/svg+xml",
|
|
13
|
+
ttf: "font/ttf",
|
|
14
|
+
otf: "font/otf",
|
|
15
|
+
woff: "font/woff",
|
|
16
|
+
woff2: "font/woff2",
|
|
17
|
+
json: "application/json",
|
|
18
|
+
js: "application/javascript",
|
|
19
|
+
hbc: "application/octet-stream",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function firstForwardedValue(value: string | null): string | null {
|
|
23
|
+
return value?.split(",")[0]?.trim() || null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function removeTrailingSlash(value: string): string {
|
|
27
|
+
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isLocalHost(host: string): boolean {
|
|
31
|
+
const hostname = host.split(":")[0]?.toLowerCase();
|
|
32
|
+
return (
|
|
33
|
+
hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getServerBaseUrl(request: NextRequest): string {
|
|
38
|
+
const envBaseUrl = process.env.OTA_PUBLIC_BASE_URL?.trim();
|
|
39
|
+
if (envBaseUrl) {
|
|
40
|
+
return removeTrailingSlash(envBaseUrl);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const host =
|
|
44
|
+
firstForwardedValue(request.headers.get("x-forwarded-host")) ||
|
|
45
|
+
request.headers.get("host") ||
|
|
46
|
+
request.nextUrl.host;
|
|
47
|
+
const forwardedProto = firstForwardedValue(
|
|
48
|
+
request.headers.get("x-forwarded-proto"),
|
|
49
|
+
);
|
|
50
|
+
let protocol =
|
|
51
|
+
forwardedProto || request.nextUrl.protocol.replace(":", "") || "http";
|
|
52
|
+
|
|
53
|
+
if (protocol !== "http" && protocol !== "https") {
|
|
54
|
+
protocol = protocol.includes("https") ? "https" : "http";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (protocol === "http" && !isLocalHost(host)) {
|
|
58
|
+
protocol = "https";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return `${protocol}://${host}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getCdnBaseUrl(): string | null {
|
|
65
|
+
const value = process.env.OTA_CDN_BASE_URL?.trim();
|
|
66
|
+
return value ? removeTrailingSlash(value) : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function buildAssetUrl({
|
|
70
|
+
request,
|
|
71
|
+
runtimeVersion,
|
|
72
|
+
platform,
|
|
73
|
+
createdAtPath,
|
|
74
|
+
channel,
|
|
75
|
+
updateId,
|
|
76
|
+
assetPath,
|
|
77
|
+
storageBasePath,
|
|
78
|
+
}: {
|
|
79
|
+
request: NextRequest;
|
|
80
|
+
runtimeVersion: string;
|
|
81
|
+
platform: string;
|
|
82
|
+
createdAtPath: string;
|
|
83
|
+
channel: string;
|
|
84
|
+
updateId: string;
|
|
85
|
+
assetPath: string;
|
|
86
|
+
storageBasePath: string;
|
|
87
|
+
}): string {
|
|
88
|
+
const cdnBaseUrl = getCdnBaseUrl();
|
|
89
|
+
if (cdnBaseUrl && storageBasePath) {
|
|
90
|
+
const objectPath = toPosixPath(
|
|
91
|
+
path.posix.join(storageBasePath, toPosixPath(assetPath)),
|
|
92
|
+
);
|
|
93
|
+
return `${cdnBaseUrl}/${objectPath}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const params = new URLSearchParams({
|
|
97
|
+
runtimeVersion,
|
|
98
|
+
platform,
|
|
99
|
+
createdAtPath,
|
|
100
|
+
channel,
|
|
101
|
+
updateId,
|
|
102
|
+
assetPath: toPosixPath(assetPath),
|
|
103
|
+
});
|
|
104
|
+
return `${getServerBaseUrl(request)}/api/assets?${params.toString()}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function createSignatureRequest(request: NextRequest) {
|
|
108
|
+
return {
|
|
109
|
+
headers: {
|
|
110
|
+
"expo-expect-signature": request.headers.get("expo-expect-signature"),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function createMultipartResponse({
|
|
116
|
+
protocolVersion,
|
|
117
|
+
boundary,
|
|
118
|
+
buffer,
|
|
119
|
+
}: {
|
|
120
|
+
protocolVersion: number;
|
|
121
|
+
boundary: string;
|
|
122
|
+
buffer: Uint8Array;
|
|
123
|
+
}) {
|
|
124
|
+
const body = new Uint8Array(buffer.byteLength);
|
|
125
|
+
body.set(buffer);
|
|
126
|
+
|
|
127
|
+
return new Response(body.buffer, {
|
|
128
|
+
status: 200,
|
|
129
|
+
headers: {
|
|
130
|
+
"expo-protocol-version": String(protocolVersion),
|
|
131
|
+
"expo-sfv-version": "0",
|
|
132
|
+
"cache-control": "private, max-age=0",
|
|
133
|
+
"content-type": `multipart/mixed; boundary=${boundary}`,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function createNoUpdateResponse(
|
|
139
|
+
request: NextRequest,
|
|
140
|
+
protocolVersion: number,
|
|
141
|
+
) {
|
|
142
|
+
const directiveString = JSON.stringify({ type: "noUpdateAvailable" });
|
|
143
|
+
let signature: string | null = null;
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
signature = await createSignatureHeaderIfRequested(
|
|
147
|
+
createSignatureRequest(request),
|
|
148
|
+
directiveString,
|
|
149
|
+
);
|
|
150
|
+
} catch (signatureError: unknown) {
|
|
151
|
+
return Response.json(
|
|
152
|
+
{ error: (signatureError as Error).message },
|
|
153
|
+
{ status: 400 },
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const form = new NodeFormData();
|
|
158
|
+
form.append("directive", directiveString, {
|
|
159
|
+
contentType: "application/json",
|
|
160
|
+
header: {
|
|
161
|
+
"content-type": "application/json; charset=utf-8",
|
|
162
|
+
...(signature ? { "expo-signature": signature } : {}),
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return createMultipartResponse({
|
|
167
|
+
protocolVersion,
|
|
168
|
+
boundary: form.getBoundary(),
|
|
169
|
+
buffer: new Uint8Array(form.getBuffer()),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function normalizeFileExtension(
|
|
174
|
+
fileExtension: string | undefined,
|
|
175
|
+
metadataExt: string | undefined,
|
|
176
|
+
): string | undefined {
|
|
177
|
+
const rawValue = fileExtension?.trim() || metadataExt?.trim() || "";
|
|
178
|
+
if (!rawValue) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const normalized = rawValue.startsWith(".")
|
|
183
|
+
? rawValue.toLowerCase()
|
|
184
|
+
: `.${rawValue.toLowerCase()}`;
|
|
185
|
+
|
|
186
|
+
return normalized === "." ? undefined : normalized;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function normalizeContentType(
|
|
190
|
+
contentType: string | undefined,
|
|
191
|
+
fileExtension: string | undefined,
|
|
192
|
+
isLaunchAsset: boolean,
|
|
193
|
+
): string {
|
|
194
|
+
if (isLaunchAsset) {
|
|
195
|
+
return "application/javascript";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (contentType && contentType !== "application/octet-stream") {
|
|
199
|
+
return contentType;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const normalizedExt = fileExtension?.replace(/^\./, "").toLowerCase();
|
|
203
|
+
if (normalizedExt && CONTENT_TYPE_BY_EXTENSION[normalizedExt]) {
|
|
204
|
+
return CONTENT_TYPE_BY_EXTENSION[normalizedExt];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return contentType || "application/octet-stream";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function createExpoClientConfig(
|
|
211
|
+
value: Record<string, unknown> | undefined,
|
|
212
|
+
): Record<string, unknown> | null {
|
|
213
|
+
if (!value) {
|
|
214
|
+
console.warn(
|
|
215
|
+
`[${new Date().toLocaleTimeString()}] ⚠️ Missing or invalid expoClient config in update-info.json. Returning null expoClient config.`,
|
|
216
|
+
);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const ios =
|
|
221
|
+
value.ios && typeof value.ios === "object"
|
|
222
|
+
? (value.ios as Record<string, unknown>)
|
|
223
|
+
: {};
|
|
224
|
+
const android =
|
|
225
|
+
value.android && typeof value.android === "object"
|
|
226
|
+
? (value.android as Record<string, unknown>)
|
|
227
|
+
: {};
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
...value,
|
|
231
|
+
scheme: value.scheme,
|
|
232
|
+
ios: { ...ios },
|
|
233
|
+
android: { ...android },
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export function normalizeId(
|
|
2
|
+
value: string | null | undefined,
|
|
3
|
+
): string | null {
|
|
4
|
+
if (typeof value !== "string") {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const normalized = value.trim();
|
|
9
|
+
return normalized || null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function debugString(value: string | null | undefined): string {
|
|
13
|
+
return normalizeId(value) || "none";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function normalizeExpoManifestDate(
|
|
17
|
+
value: string | Date | null | undefined,
|
|
18
|
+
): string | null {
|
|
19
|
+
if (!value) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (value instanceof Date) {
|
|
24
|
+
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const parsed = Date.parse(value);
|
|
28
|
+
return Number.isNaN(parsed) ? null : new Date(parsed).toISOString();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function latestExpoManifestDate(
|
|
32
|
+
...values: Array<string | Date | null | undefined>
|
|
33
|
+
): string | null {
|
|
34
|
+
const normalized = values
|
|
35
|
+
.map(normalizeExpoManifestDate)
|
|
36
|
+
.filter((value): value is string => value !== null);
|
|
37
|
+
|
|
38
|
+
if (normalized.length === 0) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return normalized.reduce((latest, value) =>
|
|
43
|
+
Date.parse(value) > Date.parse(latest) ? value : latest,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isSameOrNewerDate(
|
|
48
|
+
candidate: string | null | undefined,
|
|
49
|
+
baseline: string | null | undefined,
|
|
50
|
+
): boolean {
|
|
51
|
+
if (!candidate || !baseline) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const candidateTs = Date.parse(candidate);
|
|
56
|
+
const baselineTs = Date.parse(baseline);
|
|
57
|
+
if (Number.isNaN(candidateTs) || Number.isNaN(baselineTs)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return candidateTs >= baselineTs;
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Expo update selection
|
|
2
|
+
EXPO_UPDATE_CHANNEL=production
|
|
3
|
+
|
|
4
|
+
# Authenticated embedded-build registration
|
|
5
|
+
OTA_SERVER_URL=https://updates.example.com
|
|
6
|
+
OTA_ACCESS_TOKEN=
|
|
7
|
+
|
|
8
|
+
# Direct publisher database access
|
|
9
|
+
OTA_DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DATABASE
|
|
10
|
+
OTA_DATABASE_SSL=true
|
|
11
|
+
|
|
12
|
+
# S3-compatible update storage
|
|
13
|
+
R2_ENDPOINT=https://storage.example.com
|
|
14
|
+
R2_ACCESS_KEY_ID=
|
|
15
|
+
R2_SECRET_ACCESS_KEY=
|
|
16
|
+
R2_BUCKET=expo-updates
|
|
17
|
+
R2_REGION=auto
|
|
18
|
+
S3_FORCE_PATH_STYLE=false
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -eu
|
|
4
|
+
|
|
5
|
+
if [ "${CONFIGURATION:-Release}" = "Debug" ]; then
|
|
6
|
+
exit 0
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
PROJECT_ROOT="${CI_PRIMARY_REPOSITORY_PATH:-$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)}"
|
|
10
|
+
MANIFEST_PATH=""
|
|
11
|
+
|
|
12
|
+
for candidate in \
|
|
13
|
+
"${TARGET_BUILD_DIR:-}/${UNLOCALIZED_RESOURCES_FOLDER_PATH:-}/app.manifest" \
|
|
14
|
+
"${CI_ARCHIVE_PATH:-}/Products/Applications/"*.app/app.manifest
|
|
15
|
+
do
|
|
16
|
+
if [ -f "$candidate" ]; then
|
|
17
|
+
MANIFEST_PATH="$candidate"
|
|
18
|
+
break
|
|
19
|
+
fi
|
|
20
|
+
done
|
|
21
|
+
|
|
22
|
+
if [ -z "$MANIFEST_PATH" ] && [ -n "${TARGET_BUILD_DIR:-}" ]; then
|
|
23
|
+
MANIFEST_PATH="$(find "$TARGET_BUILD_DIR" -type f -name app.manifest 2>/dev/null | head -n 1 || true)"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
if [ -z "$MANIFEST_PATH" ]; then
|
|
27
|
+
echo "Embedded update registration failed: iOS app.manifest was not found." >&2
|
|
28
|
+
[ "${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
|
|
29
|
+
exit 0
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
if ! node "$PROJECT_ROOT/scripts/ota-register-embedded/index.mjs" \
|
|
33
|
+
--manifest "$MANIFEST_PATH" \
|
|
34
|
+
--platform ios; then
|
|
35
|
+
[ "${OTA_EMBEDDED_REGISTER_STRICT:-false}" = "true" ] && exit 1
|
|
36
|
+
fi
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { withXcodeProject } = require("expo/config-plugins");
|
|
2
|
+
|
|
3
|
+
const PHASE_NAME = "Register Expo embedded update";
|
|
4
|
+
|
|
5
|
+
module.exports = function withOtaEmbeddedRegistration(config) {
|
|
6
|
+
return withXcodeProject(config, (projectConfig) => {
|
|
7
|
+
const project = projectConfig.modResults;
|
|
8
|
+
const phases =
|
|
9
|
+
project.hash.project.objects.PBXShellScriptBuildPhase || {};
|
|
10
|
+
const phaseExists = Object.values(phases).some(
|
|
11
|
+
(phase) =>
|
|
12
|
+
phase &&
|
|
13
|
+
typeof phase === "object" &&
|
|
14
|
+
phase.name === `"${PHASE_NAME}"`,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
if (!phaseExists) {
|
|
18
|
+
project.addBuildPhase(
|
|
19
|
+
[],
|
|
20
|
+
"PBXShellScriptBuildPhase",
|
|
21
|
+
PHASE_NAME,
|
|
22
|
+
project.getFirstTarget().uuid,
|
|
23
|
+
{
|
|
24
|
+
shellPath: "/bin/sh",
|
|
25
|
+
shellScript:
|
|
26
|
+
'OTA_EMBEDDED_REGISTER_STRICT=true sh "$PROJECT_DIR/../ci_scripts/register-embedded-update.sh"',
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return projectConfig;
|
|
32
|
+
});
|
|
33
|
+
};
|