create-expo-updates-server 0.4.0 → 0.6.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 (175) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +4 -9
  4. package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
  5. package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
  6. package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
  7. package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
  8. package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
  9. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
  10. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
  11. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
  13. package/dist/template/app/api/admin/updates/route.test.ts +21 -0
  14. package/dist/template/app/api/admin/updates/route.ts +12 -1
  15. package/dist/template/app/globals.css +65 -68
  16. package/dist/template/app/login/page.tsx +66 -42
  17. package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
  18. package/dist/template/app/updates/devices/page.tsx +188 -152
  19. package/dist/template/app/updates/embedded/page.tsx +63 -29
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +381 -283
  23. package/dist/template/app/updates/releases.test.tsx +156 -0
  24. package/dist/template/components/admin/admin-role.ts +5 -0
  25. package/dist/template/components/admin/admin-shell.tsx +166 -101
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +25 -17
  28. package/dist/template/components/admin/release-badges.test.tsx +50 -0
  29. package/dist/template/components/admin/release-badges.tsx +101 -0
  30. package/dist/template/components/ui/alert.tsx +10 -3
  31. package/dist/template/components/ui/avatar.tsx +108 -0
  32. package/dist/template/components/ui/badge.tsx +2 -2
  33. package/dist/template/components/ui/breadcrumb.tsx +108 -0
  34. package/dist/template/components/ui/button.tsx +5 -5
  35. package/dist/template/components/ui/card.tsx +2 -2
  36. package/dist/template/components/ui/chart.tsx +1 -1
  37. package/dist/template/components/ui/collapsible.tsx +7 -0
  38. package/dist/template/components/ui/empty.tsx +103 -0
  39. package/dist/template/components/ui/field.tsx +248 -0
  40. package/dist/template/components/ui/input-group.tsx +170 -0
  41. package/dist/template/components/ui/input.tsx +1 -1
  42. package/dist/template/components/ui/native-select.tsx +1 -1
  43. package/dist/template/components/ui/radio-group.tsx +41 -0
  44. package/dist/template/components/ui/status-tones.ts +15 -0
  45. package/dist/template/components/ui/table.tsx +1 -1
  46. package/dist/template/components/ui/textarea.tsx +1 -1
  47. package/dist/template/docs/admin-ui.md +7 -3
  48. package/dist/template/docs/device-targeting.md +2 -7
  49. package/dist/template/docs/doctor.md +2 -2
  50. package/dist/template/docs/expo-app-setup.md +9 -27
  51. package/dist/template/docs/getting-started.md +3 -4
  52. package/dist/template/docs/installation-telemetry.md +2 -8
  53. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  54. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  55. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  56. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  57. package/dist/template/docs/migrations/schema.sql +349 -0
  58. package/dist/template/docs/npm-installer.md +3 -3
  59. package/dist/template/docs/operations-guide.md +8 -6
  60. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  61. package/dist/template/docs/ota-update-policy.md +9 -20
  62. package/dist/template/docs/ru/admin-ui.md +7 -3
  63. package/dist/template/docs/ru/device-targeting.md +2 -2
  64. package/dist/template/docs/ru/doctor.md +2 -2
  65. package/dist/template/docs/ru/expo-app-setup.md +9 -9
  66. package/dist/template/docs/ru/getting-started.md +3 -3
  67. package/dist/template/docs/ru/installation-telemetry.md +2 -2
  68. package/dist/template/docs/ru/npm-installer.md +3 -3
  69. package/dist/template/docs/ru/operations-guide.md +8 -3
  70. package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
  71. package/dist/template/docs/ru/ota-update-policy.md +9 -7
  72. package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
  73. package/dist/template/docs/uk/admin-ui.md +7 -3
  74. package/dist/template/docs/uk/device-targeting.md +2 -2
  75. package/dist/template/docs/uk/doctor.md +2 -2
  76. package/dist/template/docs/uk/expo-app-setup.md +9 -9
  77. package/dist/template/docs/uk/getting-started.md +3 -3
  78. package/dist/template/docs/uk/installation-telemetry.md +2 -2
  79. package/dist/template/docs/uk/npm-installer.md +3 -3
  80. package/dist/template/docs/uk/operations-guide.md +8 -3
  81. package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
  82. package/dist/template/docs/uk/ota-update-policy.md +9 -7
  83. package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
  84. package/dist/template/lib/audience-ids.ts +4 -0
  85. package/dist/template/package-lock.json +46 -0
  86. package/dist/template/package.json +3 -1
  87. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  88. package/dist/template/scripts/create-access-token.mjs +1 -1
  89. package/dist/template/scripts/lib/doctor.mjs +10 -7
  90. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  91. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  92. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  93. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  94. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  95. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  96. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  97. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  98. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  99. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  100. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  101. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  102. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  103. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  104. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  105. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  106. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  107. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  108. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  109. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  110. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  111. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  112. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  113. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  114. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  115. package/dist/template/src/client/admin-api.ts +45 -10
  116. package/dist/template/src/client/admin-types.ts +35 -1
  117. package/dist/template/src/client/devices/analytics.tsx +168 -231
  118. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  119. package/dist/template/src/client/devices/device-name.tsx +37 -23
  120. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  121. package/dist/template/src/client/devices/registry.tsx +258 -245
  122. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  123. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  124. package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
  125. package/dist/template/src/client/distribution-control.tsx +89 -57
  126. package/dist/template/src/client/distribution-history.tsx +353 -0
  127. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  128. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  129. package/dist/template/src/client/guard-action-combobox.tsx +133 -239
  130. package/dist/template/src/client/guard-action-options.ts +4 -6
  131. package/dist/template/src/client/i18n/en.json +133 -2
  132. package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
  133. package/dist/template/src/client/i18n/ru.json +133 -2
  134. package/dist/template/src/client/i18n/uk.json +133 -2
  135. package/dist/template/src/client/logout-button.tsx +3 -3
  136. package/dist/template/src/client/policy-draft.ts +138 -0
  137. package/dist/template/src/client/update-audience-editor.tsx +597 -206
  138. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  139. package/dist/template/src/client/update-policy-editor.tsx +454 -320
  140. package/dist/template/src/client/use-filtered-results.ts +55 -0
  141. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  142. package/dist/template/src/server/controllers/manifest.ts +15 -1
  143. package/dist/template/src/server/devices/audience.ts +9 -5
  144. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  145. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  146. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  147. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  148. package/dist/template/src/server/lib/supabase.js +24 -0
  149. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  150. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  151. package/dist/template/src/server/lib/update-policy.ts +23 -10
  152. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  153. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  154. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  155. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  156. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  157. package/dist/template/tsconfig.json +2 -2
  158. package/dist/template-manifest.json +446 -301
  159. package/package.json +1 -1
  160. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  161. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  162. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  163. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  164. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  165. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  166. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  167. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  168. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  169. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  170. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  171. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  172. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  173. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  174. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  175. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -45,11 +45,11 @@ export default function Layout() { useOtaUpdates(${options}); return null; }`;
45
45
  roots.push(directory);
46
46
  const layout = path.join(directory, "src/app/_layout.tsx");
47
47
  fs.mkdirSync(path.dirname(layout), { recursive: true });
48
- fs.mkdirSync(path.join(directory, "ota-client"));
48
+ fs.mkdirSync(path.join(directory, "node_modules/expo-updates-server-client"), { recursive: true });
49
49
  fs.writeFileSync(layout, result);
50
50
  fs.writeFileSync(
51
- path.join(directory, "ota-client/index.ts"),
52
- "export function OtaUpdates(props: { autoCheck?: boolean; autoUpdate?: boolean; autoReload?: boolean }) { return null; }",
51
+ path.join(directory, "node_modules/expo-updates-server-client/index.d.ts"),
52
+ "export declare function OtaUpdates(props: { autoCheck?: boolean; autoUpdate?: boolean; autoReload?: boolean }): null;",
53
53
  );
54
54
  const program = ts.createProgram([layout], {
55
55
  noEmit: true,
@@ -101,7 +101,7 @@ export default function Layout() {
101
101
  }`);
102
102
  expect(result).not.toContain("index.js");
103
103
  expect(result).toContain(
104
- "import { getInstallationId } from '../../ota-client';",
104
+ "import { getInstallationId } from 'expo-updates-server-client';",
105
105
  );
106
106
  expect(patch(result)).toBe(result);
107
107
  });
@@ -110,7 +110,7 @@ export default function Layout() {
110
110
  const result = patch(source);
111
111
  expect(result).toContain("'use client';");
112
112
  expect(result).toContain("// Keep this check.");
113
- expect(result).toContain("from '../../ota-client'");
113
+ expect(result).toContain("from 'expo-updates-server-client'");
114
114
  expect(result.match(/<OtaUpdates /g)).toHaveLength(2);
115
115
  expect(result).toContain("autoCheck autoUpdate={false} autoReload={false}");
116
116
  expect(result).not.toContain("createElement");
@@ -181,7 +181,26 @@ export default function Root() { return createElement(AppTabs); }`);
181
181
  it("supports an aliased existing component without adding a second instance", () => {
182
182
  const source = `import { OtaUpdates as Updates } from '../../ota-client';
183
183
  export default () => <><Updates autoUpdate /><Stack /></>;`;
184
- expect(patch(source)).toBe(source);
184
+ expect(patch(source)).toBe(source.replace("../../ota-client", "expo-updates-server-client"));
185
+ expect(patch(patch(source))).toBe(patch(source));
186
+ });
187
+ it("retains namespace imports, existing SDK mounts and component options", () => {
188
+ const source = `import * as Client from '../../ota-client';
189
+ export default () => <><Client.OtaUpdates autoCheck={false} /><Stack /></>;`;
190
+ const migrated = patch(source);
191
+ expect(migrated).toBe(source.replace("../../ota-client", "expo-updates-server-client"));
192
+ expect(patch(migrated)).toBe(migrated);
193
+ });
194
+ it("migrates namespace-qualified legacy hooks and gate without duplicating a mount", () => {
195
+ const result = patch(`import * as Client from '../../ota-client';
196
+ export default function App() {
197
+ const ota = Client.useOtaUpdates({ autoCheck: false });
198
+ return <Client.OtaUpdateGate controller={ota}><Stack /></Client.OtaUpdateGate>;
199
+ }`);
200
+ expect(result.match(/<Client\.OtaUpdates /g)).toHaveLength(1);
201
+ expect(result).not.toContain("Client.useOtaUpdates");
202
+ expect(result).not.toContain("OtaUpdateGate");
203
+ expect(patch(result)).toBe(result);
185
204
  });
186
205
  it("avoids collisions with local component names", () => {
187
206
  const result = patch(
@@ -268,6 +287,30 @@ describe("root selection", () => {
268
287
  planOtaRootHook({ appRoot, originalEntry: "__platform_default__" }).files,
269
288
  ).toHaveLength(0);
270
289
  });
290
+ it("mounts the client in a blank Expo app and leaves custom registrations alone", () => {
291
+ const index =
292
+ "import {registerRootComponent} from 'expo';\nimport App from './App';\n// Standard Expo entry\nregisterRootComponent(App);";
293
+ const appRoot = fixture({ "index.js": index, "App.js": component });
294
+ const plan = () =>
295
+ planOtaRootHook({ appRoot, originalEntry: "./index.js" });
296
+ const first = plan();
297
+ expect(first.warnings).toEqual([]);
298
+ const [[file, patched]] = first.files;
299
+ expect(file).toBe("App.js");
300
+ expect(patched).toContain(
301
+ "<OtaUpdates autoCheck autoUpdate={false} autoReload={false}",
302
+ );
303
+ fs.writeFileSync(path.join(appRoot, file), patched);
304
+ expect(plan().files[0][1]).toBe(patched);
305
+ fs.writeFileSync(
306
+ path.join(appRoot, "index.js"),
307
+ index.replace(
308
+ "registerRootComponent(App);",
309
+ "registerRootComponent(wrap(App));",
310
+ ),
311
+ );
312
+ expect(plan().files).toEqual([]);
313
+ });
271
314
  it("does not patch ignored app root when src/app exists without a layout", () => {
272
315
  const appRoot = fixture({
273
316
  "src/app/index.tsx": component,
@@ -16,6 +16,12 @@ const versionMigration = readFileSync(new URL('../../docs/migrations/2026-10-22-
16
16
  assert.ok(schema.includes(versionMigration.trim()), 'Canonical version metadata SQL must match migration');
17
17
  const targetingMigration = readFileSync(new URL('../../docs/migrations/2026-10-22-device-targeting.sql', import.meta.url), 'utf8');
18
18
  const activationMigration = readFileSync(new URL('../../docs/migrations/2026-10-22-device-targeting-activation.sql', import.meta.url), 'utf8');
19
+ const favoritesMigration = readFileSync(new URL('../../docs/migrations/2026-11-25-device-favorites.sql', import.meta.url), 'utf8');
20
+ const postponeMigration = readFileSync(new URL('../../docs/migrations/2026-11-25-download-on-postpone.sql', import.meta.url), 'utf8');
21
+ assert.ok(schema.includes(postponeMigration.trim()));
22
+ const historyMigration = readFileSync(new URL('../../docs/migrations/2026-11-25-public-distribution-history.sql', import.meta.url), 'utf8');
23
+ assert.ok(schema.includes(favoritesMigration.trim()), 'Canonical favorites SQL must match migration');
24
+ assert.ok(schema.includes(historyMigration.trim()), 'Canonical public distribution SQL must match migration');
19
25
  assert.ok(schema.includes(targetingMigration.trim()), 'Canonical targeting SQL must match migration');
20
26
  assert.ok(schema.includes(activationMigration.trim()), 'Canonical activation SQL must match migration');
21
27
  const marker = '-- Daily device analytics (2026-10-22).';
@@ -34,12 +40,14 @@ try {
34
40
  'Refusing a nonempty OTA database: use an empty disposable database');
35
41
  await pool.query(fresh ? schema : schema.split(marker)[0]);
36
42
  installed = true;
43
+ await pool.query(postponeMigration);
44
+ await pool.query(postponeMigration);
37
45
  let original;
38
46
  if (!fresh) {
39
47
  await send(event);
40
48
  original = (await pool.query('select to_jsonb(s) as state from ota_device_state s where installation_id=$1', [event.installationId])).rows[0].state;
41
49
  await pool.query(migration);
42
- await pool.query(versionMigration);
50
+ await pool.query(versionMigration);
43
51
  }
44
52
  const coverage = (await pool.query('select collection_started_at from ota_device_analytics_metadata')).rows[0].collection_started_at.toISOString();
45
53
  await pool.query(migration);
@@ -59,6 +67,9 @@ try {
59
67
  await pool.query(targetingMigration);
60
68
  await pool.query(activationMigration);
61
69
  await pool.query(activationMigration);
70
+ await pool.query(favoritesMigration);
71
+ await pool.query(historyMigration);
72
+ await pool.query(historyMigration);
62
73
  console.log(`PASS: ${fresh ? 'fresh canonical schema' : 'upgrade preserving existing state without backfill'}, SQL parity, and repeat migration preserving collection start.`);
63
74
  } finally {
64
75
  if (installed) {
@@ -64,15 +64,14 @@ try {
64
64
  assert.deepEqual(await active(tx), [pub]);
65
65
  await tx.query('rollback');
66
66
 
67
- // Widening keeps public fallback; subsequent public activation restores the
68
- // normal single-release behavior, including direct update-meta writes.
67
+ // Explicit widening starts public distribution in the same statement.
69
68
  await tx.query('begin');
70
69
  await tx.query('update ota_updates set is_active=true,disabled_at=null where update_id=$1', [pub]);
71
70
  await tx.query("select * from ota_replace_audience($1,'devices','[]',$2,(select audience_version from ota_updates where update_id=$1))", [target, JSON.stringify([device])]);
72
71
  await tx.query('update ota_updates set is_active=true,disabled_at=null where update_id=$1', [target]);
73
72
  assert.deepEqual(await active(tx), expectedBoth);
74
73
  await tx.query("select * from ota_replace_audience($1,'all','[]','[]',(select audience_version from ota_updates where update_id=$1))", [target]);
75
- assert.deepEqual(await active(tx), expectedBoth);
74
+ assert.deepEqual(await active(tx), [target]);
76
75
  await tx.query('update ota_updates set is_active=true,disabled_at=null where update_id=$1', [target]);
77
76
  assert.deepEqual(await active(tx), [target]);
78
77
  await tx.query('rollback');
@@ -0,0 +1,161 @@
1
+ import assert from "node:assert/strict";
2
+ import { randomUUID } from "node:crypto";
3
+ import path from "node:path";
4
+ import { mkdir, writeFile, readFile, symlink } from "node:fs/promises";
5
+ import { planOtaClient } from "../../lib/ota-client-configurator.mjs";
6
+ import { execFileSync, spawn } from "node:child_process";
7
+ import { existsSync } from "node:fs";
8
+ import { createRequire } from "node:module";
9
+ import { clientPackage, clientVersion } from "../../lib/ota-client-package.mjs";
10
+ import { once } from "node:events";
11
+ import { fileURLToPath } from "node:url";
12
+ import { seedPublication } from "./delivery.mjs";
13
+
14
+ export async function exerciseClientLifecycle({
15
+ origin,
16
+ db,
17
+ storage,
18
+ password,
19
+ publicKey,
20
+ scratch,
21
+ }) {
22
+ assert.equal(new URL(origin).hostname, "127.0.0.1");
23
+ const response = await fetch(origin + "/api/admin/login", {
24
+ method: "POST",
25
+ headers: { "content-type": "application/json" },
26
+ body: JSON.stringify({ username: "admin", password }),
27
+ });
28
+ assert.equal(response.status, 200);
29
+ const cookie = response.headers.get("set-cookie").split(";")[0];
30
+ const suite = "client-" + randomUUID();
31
+ const fixtures = {};
32
+ for (const platform of ["ios", "android"]) {
33
+ fixtures[platform] = {};
34
+ for (const kind of [
35
+ "manual",
36
+ "manual-postpone",
37
+ "background",
38
+ "required",
39
+ "immediate",
40
+ "store",
41
+ ]) {
42
+ const channel = suite + "-" + kind;
43
+ const scoped = { channel };
44
+ const release = await seedPublication(
45
+ db,
46
+ storage,
47
+ "Integration " + kind,
48
+ false,
49
+ platform,
50
+ scoped,
51
+ );
52
+ const policy = {
53
+ delivery:
54
+ kind === "background" || kind === "immediate"
55
+ ? "background"
56
+ : kind === "manual-postpone" ? kind : "manual",
57
+ expectedPolicyVersion: 1,
58
+ guard:
59
+ kind === "required" || kind === "immediate"
60
+ ? { action: "ota-force-update" }
61
+ : kind === "store"
62
+ ? {
63
+ action: "ota-force-store-update",
64
+ payload: { url: "https://example.invalid/store" },
65
+ }
66
+ : null,
67
+ };
68
+ for (const [path, method, body] of [
69
+ [release.path + "/policy", "PUT", policy],
70
+ [release.path + "/deactivate", "POST", { disabled: false }],
71
+ ]) {
72
+ const res = await fetch(origin + path, {
73
+ method,
74
+ headers: { cookie, "content-type": "application/json" },
75
+ body: JSON.stringify(body),
76
+ });
77
+ assert.equal(res.status, 200, await res.text());
78
+ }
79
+ fixtures[platform][kind] = { channel };
80
+ if (kind === "store" || kind === "required") {
81
+ const replacement = await seedPublication(
82
+ db,
83
+ storage,
84
+ "Unguarded replacement",
85
+ false,
86
+ platform,
87
+ scoped,
88
+ );
89
+ fixtures[platform][kind].replacement = replacement.path;
90
+ }
91
+ }
92
+ }
93
+ const root = fileURLToPath(new URL("../../../", import.meta.url));
94
+ const appRoot = path.join(scratch, "mobile");
95
+ await mkdir(appRoot);
96
+ await writeFile(
97
+ path.join(appRoot, "index.js"),
98
+ "import {registerRootComponent} from 'expo'; import App from './App'; registerRootComponent(App);",
99
+ );
100
+ await writeFile(
101
+ path.join(appRoot, "App.jsx"),
102
+ "export default function App() { return null; }",
103
+ );
104
+ const plan = planOtaClient({
105
+ appRoot,
106
+ templateRoot: path.join(root, "templates/expo-app"),
107
+ packageJson: { main: "index.js" },
108
+ manifestUrl: origin + "/api/manifest",
109
+ channel: suite,
110
+ });
111
+ assert.deepEqual(plan.warnings, []);
112
+ plan.apply();
113
+ assert.match(
114
+ await readFile(path.join(appRoot, "App.jsx"), "utf8"),
115
+ /<OtaUpdates autoCheck autoUpdate=\{false\} autoReload=\{false\}/,
116
+ );
117
+ await symlink(
118
+ path.join(root, "node_modules"),
119
+ path.join(appRoot, "node_modules"),
120
+ "dir",
121
+ );
122
+ // Run the policy scenarios against the files that a mobile app receives from npm.
123
+ const sdkWorkspace = path.join(root, "packages/ota-client");
124
+ const sdkSpec = existsSync(path.join(sdkWorkspace, "package.json"))
125
+ ? sdkWorkspace
126
+ : `${clientPackage}@${clientVersion}`;
127
+ const [{ filename, version }] = JSON.parse(execFileSync("npm", [
128
+ "pack", sdkSpec, "--json", "--pack-destination", scratch,
129
+ ], { encoding: "utf8", cwd: scratch }));
130
+ assert.equal(version, clientVersion);
131
+ const packedDirectory = path.join(appRoot, "sdk");
132
+ await mkdir(packedDirectory);
133
+ execFileSync("tar", ["-xzf", path.join(scratch, filename), "-C", packedDirectory, "--strip-components=1"]);
134
+ const resolveSdk = createRequire(path.join(packedDirectory, "package.json"));
135
+ const sdkSource = path.dirname(resolveSdk.resolve(clientPackage));
136
+ const child = spawn(
137
+ process.execPath,
138
+ [
139
+ "node_modules/vitest/vitest.mjs",
140
+ "run",
141
+ "--config",
142
+ "scripts/tests/e2e/client-vitest.mts",
143
+ ],
144
+ {
145
+ cwd: root,
146
+ stdio: "inherit",
147
+ env: {
148
+ ...process.env,
149
+ OTA_E2E_CLIENT_DIRECTORY: sdkSource,
150
+ OTA_LIFECYCLE_FIXTURE: JSON.stringify({
151
+ origin,
152
+ cookie,
153
+ platforms: fixtures,
154
+ publicKey: publicKey.export({ type: "spki", format: "pem" }),
155
+ }),
156
+ },
157
+ },
158
+ );
159
+ const [code] = await once(child, "exit");
160
+ assert.equal(code, 0, "OTA client lifecycle HTTP scenarios");
161
+ }