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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/bin/create-expo-updates-server.mjs +5 -0
  4. package/dist/template/.env.docker.example +15 -0
  5. package/dist/template/.env.example +35 -0
  6. package/dist/template/Dockerfile +42 -0
  7. package/dist/template/LICENSE +21 -0
  8. package/dist/template/README.md +665 -0
  9. package/dist/template/app/api/admin/access-tokens/[id]/route.ts +25 -0
  10. package/dist/template/app/api/admin/access-tokens/route.test.ts +73 -0
  11. package/dist/template/app/api/admin/access-tokens/route.ts +90 -0
  12. package/dist/template/app/api/admin/embedded-updates/[embeddedUpdateId]/route.ts +25 -0
  13. package/dist/template/app/api/admin/embedded-updates/route.test.ts +102 -0
  14. package/dist/template/app/api/admin/embedded-updates/route.ts +47 -0
  15. package/dist/template/app/api/admin/emergency-redirects/[id]/route.ts +62 -0
  16. package/dist/template/app/api/admin/emergency-redirects/route.test.ts +84 -0
  17. package/dist/template/app/api/admin/emergency-redirects/route.ts +56 -0
  18. package/dist/template/app/api/admin/login/route.test.ts +55 -0
  19. package/dist/template/app/api/admin/login/route.ts +52 -0
  20. package/dist/template/app/api/admin/logout/route.ts +20 -0
  21. package/dist/template/app/api/admin/session/route.ts +15 -0
  22. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +33 -0
  23. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +29 -0
  24. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +29 -0
  25. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +96 -0
  26. package/dist/template/app/api/admin/updates/route.test.ts +142 -0
  27. package/dist/template/app/api/admin/updates/route.ts +32 -0
  28. package/dist/template/app/api/assets/route.ts +6 -0
  29. package/dist/template/app/api/health/route.test.ts +26 -0
  30. package/dist/template/app/api/health/route.ts +42 -0
  31. package/dist/template/app/api/manifest/route.ts +6 -0
  32. package/dist/template/app/api/update-complete/route.ts +6 -0
  33. package/dist/template/app/favicon.ico +0 -0
  34. package/dist/template/app/globals.css +26 -0
  35. package/dist/template/app/layout.tsx +34 -0
  36. package/dist/template/app/login/page.tsx +77 -0
  37. package/dist/template/app/page.tsx +12 -0
  38. package/dist/template/app/updates/[encodedKey]/page.tsx +482 -0
  39. package/dist/template/app/updates/embedded/page.tsx +164 -0
  40. package/dist/template/app/updates/emergency-redirects/page.tsx +430 -0
  41. package/dist/template/app/updates/layout.tsx +14 -0
  42. package/dist/template/app/updates/page.tsx +281 -0
  43. package/dist/template/docker-compose.yml +100 -0
  44. package/dist/template/docs/expo-app-setup.md +497 -0
  45. package/dist/template/docs/getting-started.md +502 -0
  46. package/dist/template/docs/getting-started.ru.md +623 -0
  47. package/dist/template/docs/index.md +57 -0
  48. package/dist/template/docs/migrations/schema.sql +363 -0
  49. package/dist/template/docs/npm-installer.md +83 -0
  50. package/dist/template/docs/operations-guide.md +270 -0
  51. package/dist/template/docs/ota-emergency-recovery.md +109 -0
  52. package/dist/template/docs/supabase-setup.md +133 -0
  53. package/dist/template/eslint.config.mjs +30 -0
  54. package/dist/template/gitignore.template +58 -0
  55. package/dist/template/next.config.ts +7 -0
  56. package/dist/template/package-lock.json +12156 -0
  57. package/dist/template/package.json +50 -0
  58. package/dist/template/postcss.config.mjs +7 -0
  59. package/dist/template/public/file.svg +1 -0
  60. package/dist/template/public/globe.svg +1 -0
  61. package/dist/template/public/next.svg +1 -0
  62. package/dist/template/public/vercel.svg +1 -0
  63. package/dist/template/public/window.svg +1 -0
  64. package/dist/template/scripts/configure-expo-app.mjs +145 -0
  65. package/dist/template/scripts/create-access-token.mjs +135 -0
  66. package/dist/template/scripts/create-admin.mjs +169 -0
  67. package/dist/template/scripts/import-emergency-redirects.mjs +126 -0
  68. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +64 -0
  69. package/dist/template/scripts/lib/expo-app-configurator.mjs +666 -0
  70. package/dist/template/scripts/lib/expo-app-configurator.test.ts +463 -0
  71. package/dist/template/scripts/lib/expo-app-prompts.mjs +139 -0
  72. package/dist/template/scripts/lib/expo-app-prompts.test.ts +97 -0
  73. package/dist/template/scripts/lib/expo-export-command.test.ts +31 -0
  74. package/dist/template/scripts/lib/ota-publish-retry.test.ts +33 -0
  75. package/dist/template/scripts/manage-emergency-redirect.mjs +483 -0
  76. package/dist/template/scripts/sync-docker-database-password.sh +16 -0
  77. package/dist/template/src/client/admin-api.ts +174 -0
  78. package/dist/template/src/client/admin-types.ts +93 -0
  79. package/dist/template/src/client/logout-button.tsx +31 -0
  80. package/dist/template/src/server/controllers/assets.ts +216 -0
  81. package/dist/template/src/server/controllers/manifest.test.ts +403 -0
  82. package/dist/template/src/server/controllers/manifest.ts +626 -0
  83. package/dist/template/src/server/controllers/update-complete.ts +36 -0
  84. package/dist/template/src/server/lib/admin-access-tokens.ts +169 -0
  85. package/dist/template/src/server/lib/admin-api.ts +101 -0
  86. package/dist/template/src/server/lib/admin-auth.ts +208 -0
  87. package/dist/template/src/server/lib/admin-embedded-updates.ts +150 -0
  88. package/dist/template/src/server/lib/admin-updates.ts +1282 -0
  89. package/dist/template/src/server/lib/common.js +24 -0
  90. package/dist/template/src/server/lib/emergency-channel-redirects.ts +310 -0
  91. package/dist/template/src/server/lib/env.js +8 -0
  92. package/dist/template/src/server/lib/manifest-helpers.js +91 -0
  93. package/dist/template/src/server/lib/response.js +11 -0
  94. package/dist/template/src/server/lib/signing.js +55 -0
  95. package/dist/template/src/server/lib/supabase.js +763 -0
  96. package/dist/template/src/server/manifest/manifest-repository.ts +269 -0
  97. package/dist/template/src/server/manifest/manifest-request.ts +21 -0
  98. package/dist/template/src/server/manifest/manifest-response.ts +235 -0
  99. package/dist/template/src/server/manifest/manifest-values.ts +62 -0
  100. package/dist/template/templates/expo-app/.env.ota.example +18 -0
  101. package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +6 -0
  102. package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +36 -0
  103. package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +33 -0
  104. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +87 -0
  105. package/dist/template/templates/expo-app/scripts/ota-publish/api/storage-client.mjs +57 -0
  106. package/dist/template/templates/expo-app/scripts/ota-publish/index.mjs +182 -0
  107. package/dist/template/templates/expo-app/scripts/ota-publish/lib/common.mjs +84 -0
  108. package/dist/template/templates/expo-app/scripts/ota-publish/lib/expo-export-command.mjs +24 -0
  109. package/dist/template/templates/expo-app/scripts/ota-publish/lib/retry.mjs +25 -0
  110. package/dist/template/templates/expo-app/scripts/ota-publish/shared/config.mjs +48 -0
  111. package/dist/template/templates/expo-app/scripts/ota-register-embedded/android-register-embedded-update.sh +18 -0
  112. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +275 -0
  113. package/dist/template/tsconfig.json +36 -0
  114. package/dist/template/vitest.config.mts +20 -0
  115. package/dist/template-manifest.json +564 -0
  116. package/lib/cli.mjs +549 -0
  117. package/package.json +41 -0
@@ -0,0 +1,403 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { NextRequest } from "next/server";
3
+
4
+ type Row = Record<string, unknown>;
5
+
6
+ const database = vi.hoisted(() => ({
7
+ channels: [] as Row[],
8
+ updates: [] as Row[],
9
+ embeddedUpdates: [] as Row[],
10
+ servedManifests: [] as Row[],
11
+ emergencyRedirects: [] as Row[],
12
+ }));
13
+
14
+ vi.mock("../lib/supabase.js", () => {
15
+ class Query {
16
+ private filters: Array<{ column: string; value: unknown }> = [];
17
+
18
+ constructor(private readonly table: string) {}
19
+
20
+ select() {
21
+ return this;
22
+ }
23
+
24
+ eq(column: string, value: unknown) {
25
+ this.filters.push({ column, value });
26
+ return this;
27
+ }
28
+
29
+ order() {
30
+ return this;
31
+ }
32
+
33
+ limit() {
34
+ return this;
35
+ }
36
+
37
+ upsert(row: Row) {
38
+ if (this.table === "ota_served_manifest_log") {
39
+ database.servedManifests.push(row);
40
+ }
41
+ return Promise.resolve({ data: row, error: null });
42
+ }
43
+
44
+ maybeSingle() {
45
+ const rowsByTable: Record<string, Row[]> = {
46
+ ota_update_channels: database.channels,
47
+ ota_updates: database.updates,
48
+ ota_embedded_updates: database.embeddedUpdates,
49
+ ota_served_manifest_log: database.servedManifests,
50
+ ota_emergency_redirects: database.emergencyRedirects,
51
+ };
52
+ const rows = rowsByTable[this.table] || [];
53
+ const data =
54
+ rows.find((row) =>
55
+ this.filters.every(({ column, value }) => row[column] === value),
56
+ ) || null;
57
+ return Promise.resolve({ data, error: null });
58
+ }
59
+ }
60
+
61
+ return {
62
+ supabase: {
63
+ from(table: string) {
64
+ return new Query(table);
65
+ },
66
+ },
67
+ };
68
+ });
69
+
70
+ const selectedUpdateId = "11111111-1111-4111-8111-111111111111";
71
+ const previousUpdateId = "22222222-2222-4222-8222-222222222222";
72
+ const servedManifestId = "33333333-3333-4333-8333-333333333333";
73
+ const previousServedManifestId = "44444444-4444-4444-8444-444444444444";
74
+
75
+ function makeUpdate(overrides: Row = {}): Row {
76
+ return {
77
+ update_id: selectedUpdateId,
78
+ build_id: selectedUpdateId,
79
+ runtime_version: "1.0.0",
80
+ channel: "production",
81
+ platform: "android",
82
+ created_at: "2026-08-28T08:00:00.000Z",
83
+ created_at_path: "2026-08-28T08-00-00.000Z",
84
+ storage_base_path: "1.0.0/android/production/update",
85
+ is_active: true,
86
+ manifest: {
87
+ runtimeVersion: "1.0.0",
88
+ assets: [
89
+ {
90
+ hash: "asset-hash",
91
+ key: "asset-key",
92
+ path: "assets/icon.png",
93
+ fileExtension: ".png",
94
+ contentType: "image/png",
95
+ },
96
+ ],
97
+ launchAsset: {
98
+ hash: "bundle-hash",
99
+ key: "bundle-key",
100
+ path: "bundles/android.js",
101
+ fileExtension: ".js",
102
+ contentType: "application/javascript",
103
+ },
104
+ extra: {
105
+ expoClient: {
106
+ name: "Example",
107
+ slug: "example",
108
+ },
109
+ },
110
+ },
111
+ ...overrides,
112
+ };
113
+ }
114
+
115
+ function makeRequest(headers: Record<string, string> = {}) {
116
+ return new NextRequest("https://updates.example.com/api/manifest", {
117
+ headers: {
118
+ "expo-protocol-version": "1",
119
+ "expo-platform": "android",
120
+ "expo-runtime-version": "1.0.0",
121
+ "expo-channel-name": "production",
122
+ ...headers,
123
+ },
124
+ });
125
+ }
126
+
127
+ async function requestManifest(request: NextRequest) {
128
+ const { default: manifestController } = await import("./manifest");
129
+ return manifestController(request);
130
+ }
131
+
132
+ describe("GET /api/manifest", () => {
133
+ beforeEach(() => {
134
+ vi.resetModules();
135
+ database.channels = [];
136
+ database.updates = [];
137
+ database.embeddedUpdates = [];
138
+ database.servedManifests = [];
139
+ database.emergencyRedirects = [];
140
+ });
141
+
142
+ it("rejects unsupported platforms", async () => {
143
+ const response = await requestManifest(
144
+ makeRequest({ "expo-platform": "web" }),
145
+ );
146
+
147
+ expect(response.status).toBe(400);
148
+ await expect(response.json()).resolves.toEqual({
149
+ error: "Unsupported platform. Expected either ios or android.",
150
+ });
151
+ });
152
+
153
+ it("returns a noUpdateAvailable directive when the channel has no update", async () => {
154
+ const response = await requestManifest(makeRequest());
155
+ const body = await response.text();
156
+
157
+ expect(response.status).toBe(200);
158
+ expect(response.headers.get("expo-protocol-version")).toBe("1");
159
+ expect(response.headers.get("content-type")).toContain("multipart/mixed");
160
+ expect(body).toContain('{"type":"noUpdateAvailable"}');
161
+ });
162
+
163
+ it("returns the selected update as an Expo multipart manifest", async () => {
164
+ database.channels.push({
165
+ latest_update_id: selectedUpdateId,
166
+ active_update_id: null,
167
+ active_changed_at: "2026-08-27T09:00:00.000Z",
168
+ served_manifest_id: servedManifestId,
169
+ served_manifest_changed_at: "2026-08-28T09:00:00.000Z",
170
+ runtime_version: "1.0.0",
171
+ channel: "production",
172
+ platform: "android",
173
+ });
174
+ database.updates.push(
175
+ makeUpdate(),
176
+ makeUpdate({
177
+ update_id: previousUpdateId,
178
+ build_id: previousUpdateId,
179
+ created_at: "2026-08-27T08:00:00.000Z",
180
+ }),
181
+ );
182
+ database.servedManifests.push({
183
+ served_manifest_id: previousServedManifestId,
184
+ update_id: previousUpdateId,
185
+ });
186
+
187
+ const response = await requestManifest(
188
+ makeRequest({ "expo-current-update-id": previousServedManifestId }),
189
+ );
190
+ const body = await response.text();
191
+
192
+ expect(response.status).toBe(200);
193
+ expect(response.headers.get("cache-control")).toBe("private, max-age=0");
194
+ expect(body).toContain(`"id":"${servedManifestId}"`);
195
+ expect(body).toContain('"createdAt":"2026-08-28T09:00:00.000Z"');
196
+ expect(body).toContain('"runtimeVersion":"1.0.0"');
197
+ expect(body).toContain(
198
+ "https://updates.example.com/api/assets?runtimeVersion=1.0.0",
199
+ );
200
+ expect(body).toContain('"key":"bundle-key"');
201
+ });
202
+
203
+ it("returns no update when the device already runs the channel target", async () => {
204
+ database.channels.push({
205
+ latest_update_id: selectedUpdateId,
206
+ active_update_id: null,
207
+ active_changed_at: "2026-08-28T09:00:00.000Z",
208
+ served_manifest_id: servedManifestId,
209
+ served_manifest_changed_at: "2026-08-28T09:00:00.000Z",
210
+ runtime_version: "1.0.0",
211
+ channel: "production",
212
+ platform: "android",
213
+ });
214
+ database.updates.push(makeUpdate());
215
+
216
+ const response = await requestManifest(
217
+ makeRequest({ "expo-current-update-id": selectedUpdateId }),
218
+ );
219
+ const body = await response.text();
220
+
221
+ expect(response.status).toBe(200);
222
+ expect(body).toContain('{"type":"noUpdateAvailable"}');
223
+ expect(body).not.toContain('"launchAsset"');
224
+ });
225
+
226
+ it("serves an older active update when rollback mode is enabled", async () => {
227
+ database.channels.push({
228
+ latest_update_id: selectedUpdateId,
229
+ active_update_id: previousUpdateId,
230
+ active_changed_at: "2026-08-28T10:00:00.000Z",
231
+ served_manifest_id: servedManifestId,
232
+ served_manifest_changed_at: "2026-08-28T10:00:00.000Z",
233
+ runtime_version: "1.0.0",
234
+ channel: "production",
235
+ platform: "android",
236
+ });
237
+ database.updates.push(
238
+ makeUpdate(),
239
+ makeUpdate({
240
+ update_id: previousUpdateId,
241
+ build_id: previousUpdateId,
242
+ created_at: "2026-08-27T08:00:00.000Z",
243
+ storage_base_path: "1.0.0/android/production/previous",
244
+ }),
245
+ );
246
+
247
+ const response = await requestManifest(
248
+ makeRequest({ "expo-current-update-id": selectedUpdateId }),
249
+ );
250
+ const body = await response.text();
251
+
252
+ expect(response.status).toBe(200);
253
+ expect(body).toContain(`"id":"${previousUpdateId}"`);
254
+ expect(body).toContain(`updateId=${previousUpdateId}`);
255
+ expect(body).toContain('"launchAsset"');
256
+ });
257
+
258
+ it("redirects the affected embedded build to its emergency channel", async () => {
259
+ const recoveryUpdateId = "78947abc-8750-4d44-b6ab-53398ff6e4af";
260
+ database.emergencyRedirects.push({
261
+ id: "88888888-8888-4888-8888-888888888888",
262
+ name: "Android production recovery",
263
+ enabled: true,
264
+ embedded_update_id: "35c793d0-7d0a-409e-83cf-ffd4e5004e9d",
265
+ runtime_version: "1.1.20",
266
+ platform: "android",
267
+ from_channel: "development",
268
+ to_channel: "production",
269
+ target_mode: "follow",
270
+ expected_update_id: recoveryUpdateId,
271
+ created_at: "2026-08-28T10:00:00.000Z",
272
+ modified_at: "2026-08-28T10:00:00.000Z",
273
+ });
274
+ database.channels.push({
275
+ latest_update_id: recoveryUpdateId,
276
+ active_update_id: null,
277
+ active_changed_at: "2026-08-28T10:00:00.000Z",
278
+ served_manifest_id: servedManifestId,
279
+ served_manifest_changed_at: "2026-08-28T10:00:00.000Z",
280
+ runtime_version: "1.1.20",
281
+ channel: "production",
282
+ platform: "android",
283
+ });
284
+ database.updates.push(
285
+ makeUpdate({
286
+ update_id: recoveryUpdateId,
287
+ build_id: recoveryUpdateId,
288
+ runtime_version: "1.1.20",
289
+ channel: "production",
290
+ }),
291
+ );
292
+
293
+ const response = await requestManifest(
294
+ makeRequest({
295
+ "expo-runtime-version": "1.1.20",
296
+ "expo-channel-name": "development",
297
+ "expo-embedded-update-id": "35c793d0-7d0a-409e-83cf-ffd4e5004e9d",
298
+ }),
299
+ );
300
+ const body = await response.text();
301
+
302
+ expect(response.status).toBe(200);
303
+ expect(body).toContain(`updateId=${recoveryUpdateId}`);
304
+ expect(body).toContain("channel=production");
305
+ });
306
+
307
+ it("applies an emergency redirect stored in the database", async () => {
308
+ const embeddedUpdateId = "55555555-5555-4555-8555-555555555555";
309
+ const recoveryUpdateId = "66666666-6666-4666-8666-666666666666";
310
+ database.emergencyRedirects.push({
311
+ id: "77777777-7777-4777-8777-777777777777",
312
+ name: "Android beta recovery",
313
+ enabled: true,
314
+ embedded_update_id: embeddedUpdateId,
315
+ runtime_version: "2.0.0",
316
+ platform: "android",
317
+ from_channel: "beta",
318
+ to_channel: "production",
319
+ target_mode: "pinned",
320
+ expected_update_id: recoveryUpdateId,
321
+ created_at: "2026-08-28T10:00:00.000Z",
322
+ modified_at: "2026-08-28T10:00:00.000Z",
323
+ });
324
+ database.channels.push({
325
+ latest_update_id: recoveryUpdateId,
326
+ active_update_id: null,
327
+ active_changed_at: "2026-08-28T10:00:00.000Z",
328
+ served_manifest_id: servedManifestId,
329
+ served_manifest_changed_at: "2026-08-28T10:00:00.000Z",
330
+ runtime_version: "2.0.0",
331
+ channel: "production",
332
+ platform: "android",
333
+ });
334
+ database.updates.push(
335
+ makeUpdate({
336
+ update_id: recoveryUpdateId,
337
+ build_id: recoveryUpdateId,
338
+ runtime_version: "2.0.0",
339
+ channel: "production",
340
+ }),
341
+ );
342
+
343
+ const response = await requestManifest(
344
+ makeRequest({
345
+ "expo-runtime-version": "2.0.0",
346
+ "expo-channel-name": "beta",
347
+ "expo-embedded-update-id": embeddedUpdateId,
348
+ }),
349
+ );
350
+ const body = await response.text();
351
+
352
+ expect(response.status).toBe(200);
353
+ expect(body).toContain(`updateId=${recoveryUpdateId}`);
354
+ expect(body).toContain("channel=production");
355
+ });
356
+
357
+ it("returns no update when a pinned redirect target does not match", async () => {
358
+ const embeddedUpdateId = "99999999-9999-4999-8999-999999999999";
359
+ database.emergencyRedirects.push({
360
+ id: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
361
+ name: "Pinned recovery",
362
+ enabled: true,
363
+ embedded_update_id: embeddedUpdateId,
364
+ runtime_version: "3.0.0",
365
+ platform: "android",
366
+ from_channel: "beta",
367
+ to_channel: "production",
368
+ target_mode: "pinned",
369
+ expected_update_id: previousUpdateId,
370
+ created_at: "2026-08-28T10:00:00.000Z",
371
+ modified_at: "2026-08-28T10:00:00.000Z",
372
+ });
373
+ database.channels.push({
374
+ latest_update_id: selectedUpdateId,
375
+ active_update_id: null,
376
+ active_changed_at: "2026-08-28T10:00:00.000Z",
377
+ served_manifest_id: servedManifestId,
378
+ served_manifest_changed_at: "2026-08-28T10:00:00.000Z",
379
+ runtime_version: "3.0.0",
380
+ channel: "production",
381
+ platform: "android",
382
+ });
383
+ database.updates.push(
384
+ makeUpdate({
385
+ runtime_version: "3.0.0",
386
+ channel: "production",
387
+ }),
388
+ );
389
+
390
+ const response = await requestManifest(
391
+ makeRequest({
392
+ "expo-runtime-version": "3.0.0",
393
+ "expo-channel-name": "beta",
394
+ "expo-embedded-update-id": embeddedUpdateId,
395
+ }),
396
+ );
397
+ const body = await response.text();
398
+
399
+ expect(response.status).toBe(200);
400
+ expect(body).toContain('{"type":"noUpdateAvailable"}');
401
+ expect(body).not.toContain('"launchAsset"');
402
+ });
403
+ });