create-expo-updates-server 0.4.0 → 0.6.1
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/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +4 -9
- package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
- package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
- package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
- package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
- package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
- package/dist/template/app/api/admin/updates/route.test.ts +21 -0
- package/dist/template/app/api/admin/updates/route.ts +12 -1
- package/dist/template/app/globals.css +65 -68
- package/dist/template/app/login/page.tsx +66 -42
- package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
- package/dist/template/app/updates/devices/page.tsx +188 -152
- package/dist/template/app/updates/embedded/page.tsx +63 -29
- package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +381 -283
- package/dist/template/app/updates/releases.test.tsx +156 -0
- package/dist/template/components/admin/admin-role.ts +5 -0
- package/dist/template/components/admin/admin-shell.tsx +166 -101
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -17
- package/dist/template/components/admin/release-badges.test.tsx +50 -0
- package/dist/template/components/admin/release-badges.tsx +101 -0
- package/dist/template/components/ui/alert.tsx +10 -3
- package/dist/template/components/ui/avatar.tsx +108 -0
- package/dist/template/components/ui/badge.tsx +2 -2
- package/dist/template/components/ui/breadcrumb.tsx +108 -0
- package/dist/template/components/ui/button.tsx +5 -5
- package/dist/template/components/ui/card.tsx +2 -2
- package/dist/template/components/ui/chart.tsx +1 -1
- package/dist/template/components/ui/collapsible.tsx +7 -0
- package/dist/template/components/ui/empty.tsx +103 -0
- package/dist/template/components/ui/field.tsx +248 -0
- package/dist/template/components/ui/input-group.tsx +170 -0
- package/dist/template/components/ui/input.tsx +1 -1
- package/dist/template/components/ui/native-select.tsx +1 -1
- package/dist/template/components/ui/radio-group.tsx +41 -0
- package/dist/template/components/ui/status-tones.ts +15 -0
- package/dist/template/components/ui/table.tsx +1 -1
- package/dist/template/components/ui/textarea.tsx +1 -1
- package/dist/template/docs/admin-ui.md +7 -3
- package/dist/template/docs/device-targeting.md +2 -7
- package/dist/template/docs/doctor.md +2 -2
- package/dist/template/docs/expo-app-setup.md +9 -27
- package/dist/template/docs/getting-started.md +3 -4
- package/dist/template/docs/installation-telemetry.md +2 -8
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
- package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
- package/dist/template/docs/migrations/schema.sql +349 -0
- package/dist/template/docs/npm-installer.md +3 -3
- package/dist/template/docs/operations-guide.md +8 -6
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +7 -3
- package/dist/template/docs/ru/device-targeting.md +2 -2
- package/dist/template/docs/ru/doctor.md +2 -2
- package/dist/template/docs/ru/expo-app-setup.md +9 -9
- package/dist/template/docs/ru/getting-started.md +3 -3
- package/dist/template/docs/ru/installation-telemetry.md +2 -2
- package/dist/template/docs/ru/npm-installer.md +3 -3
- package/dist/template/docs/ru/operations-guide.md +8 -3
- package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/ru/ota-update-policy.md +9 -7
- package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
- package/dist/template/docs/uk/admin-ui.md +7 -3
- package/dist/template/docs/uk/device-targeting.md +2 -2
- package/dist/template/docs/uk/doctor.md +2 -2
- package/dist/template/docs/uk/expo-app-setup.md +9 -9
- package/dist/template/docs/uk/getting-started.md +3 -3
- package/dist/template/docs/uk/installation-telemetry.md +2 -2
- package/dist/template/docs/uk/npm-installer.md +3 -3
- package/dist/template/docs/uk/operations-guide.md +8 -3
- package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/uk/ota-update-policy.md +9 -7
- package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +3 -1
- package/dist/template/scripts/configure-expo-app.mjs +3 -3
- package/dist/template/scripts/create-access-token.mjs +1 -1
- package/dist/template/scripts/lib/doctor.mjs +10 -7
- package/dist/template/scripts/lib/doctor.test.mjs +7 -5
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
- package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
- package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
- package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
- package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
- package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
- package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
- package/dist/template/scripts/tests/e2e/console.mjs +86 -0
- package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
- package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
- package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
- package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
- package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
- package/dist/template/scripts/tests/e2e/release-matrix.mjs +303 -0
- package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
- package/dist/template/scripts/tests/e2e/run.mjs +224 -0
- package/dist/template/scripts/tests/manifest-identity.sql +7 -5
- package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
- package/dist/template/src/client/admin-api.ts +45 -10
- package/dist/template/src/client/admin-types.ts +35 -1
- package/dist/template/src/client/devices/analytics.tsx +168 -231
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -23
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +258 -245
- package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
- package/dist/template/src/client/devices/use-devices-report.ts +53 -82
- package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
- package/dist/template/src/client/distribution-control.tsx +89 -57
- package/dist/template/src/client/distribution-history.tsx +353 -0
- package/dist/template/src/client/guard-action-catalog.tsx +183 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
- package/dist/template/src/client/guard-action-combobox.tsx +133 -239
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +133 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
- package/dist/template/src/client/i18n/ru.json +133 -2
- package/dist/template/src/client/i18n/uk.json +133 -2
- package/dist/template/src/client/logout-button.tsx +3 -3
- package/dist/template/src/client/policy-draft.ts +138 -0
- package/dist/template/src/client/update-audience-editor.tsx +597 -206
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +454 -320
- package/dist/template/src/client/use-filtered-results.ts +55 -0
- package/dist/template/src/server/controllers/manifest.test.ts +25 -3
- package/dist/template/src/server/controllers/manifest.ts +1 -2
- package/dist/template/src/server/devices/audience.ts +9 -5
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
- package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
- package/dist/template/src/server/lib/admin-updates.ts +160 -534
- package/dist/template/src/server/lib/distribution-history.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +24 -0
- package/dist/template/src/server/lib/supabase.test.ts +38 -1
- package/dist/template/src/server/lib/update-policy.test.ts +20 -0
- package/dist/template/src/server/lib/update-policy.ts +23 -10
- package/dist/template/src/server/manifest/manifest-repository.ts +2 -2
- package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
- package/dist/template/src/server/manifest/manifest-values.ts +21 -13
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
- package/dist/template/tsconfig.json +2 -2
- package/dist/template-manifest.json +445 -300
- package/package.json +1 -1
- package/dist/template/scripts/lib/device-identity.test.ts +0 -29
- package/dist/template/scripts/lib/ota-client.test.ts +0 -55
- package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
- package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
- package/dist/template/templates/expo-app/ota-client/README.md +0 -73
- package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
- package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
- package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
- package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
- 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, "
|
|
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, "
|
|
52
|
-
"export function OtaUpdates(props: { autoCheck?: boolean; autoUpdate?: boolean; autoReload?: boolean })
|
|
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 '
|
|
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 '
|
|
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
|
-
|
|
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
|
-
//
|
|
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),
|
|
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
|
+
}
|