create-expo-updates-server 0.3.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.
- package/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +5 -10
- 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 +382 -248
- package/dist/template/app/updates/devices/page.tsx +187 -145
- package/dist/template/app/updates/embedded/page.tsx +80 -34
- package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +385 -274
- 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 -95
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +27 -16
- 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/dialog.tsx +13 -4
- 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/sheet.tsx +6 -2
- package/dist/template/components/ui/sidebar.tsx +62 -17
- 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 +22 -24
- package/dist/template/docs/device-targeting.md +6 -12
- 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/getting-started.ru.md +11 -544
- package/dist/template/docs/index.md +1 -1
- package/dist/template/docs/installation-telemetry.md +6 -12
- 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 +9 -7
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-emergency-recovery.md +34 -57
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +33 -0
- package/dist/template/docs/ru/device-targeting.md +59 -0
- package/dist/template/docs/ru/doctor.md +98 -0
- package/dist/template/docs/ru/expo-app-setup.md +497 -0
- package/dist/template/docs/ru/getting-started.md +391 -0
- package/dist/template/docs/ru/index.md +50 -0
- package/dist/template/docs/ru/installation-telemetry.md +125 -0
- package/dist/template/docs/ru/npm-installer.md +71 -0
- package/dist/template/docs/ru/operations-guide.md +322 -0
- package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/ru/ota-update-policy.md +69 -0
- package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
- package/dist/template/docs/ru/supabase-setup.md +120 -0
- package/dist/template/docs/uk/admin-ui.md +33 -0
- package/dist/template/docs/uk/device-targeting.md +59 -0
- package/dist/template/docs/uk/doctor.md +98 -0
- package/dist/template/docs/uk/expo-app-setup.md +497 -0
- package/dist/template/docs/uk/getting-started.md +391 -0
- package/dist/template/docs/uk/index.md +50 -0
- package/dist/template/docs/uk/installation-telemetry.md +125 -0
- package/dist/template/docs/uk/npm-installer.md +71 -0
- package/dist/template/docs/uk/operations-guide.md +322 -0
- package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/uk/ota-update-policy.md +69 -0
- package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
- package/dist/template/docs/uk/supabase-setup.md +120 -0
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +4 -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 +307 -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 +169 -219
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -21
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +265 -233
- 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 +48 -38
- package/dist/template/src/client/distribution-control.tsx +98 -53
- 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 +134 -234
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +335 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
- package/dist/template/src/client/i18n/messages.test.ts +102 -19
- package/dist/template/src/client/i18n/messages.ts +31 -16
- package/dist/template/src/client/i18n/provider.tsx +6 -3
- package/dist/template/src/client/i18n/ru.json +619 -0
- package/dist/template/src/client/i18n/uk.json +619 -0
- package/dist/template/src/client/i18n/use-formatters.ts +5 -0
- 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 -199
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +466 -307
- package/dist/template/src/client/use-filtered-results.ts +55 -0
- package/dist/template/src/server/controllers/manifest.test.ts +23 -3
- package/dist/template/src/server/controllers/manifest.ts +15 -1
- 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 +11 -3
- 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 +571 -271
- 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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const clientPackage = "expo-updates-server-client";
|
|
2
|
+
export const clientVersion = "0.1.0";
|
|
3
|
+
export const nativeClientDependencies = [
|
|
4
|
+
"expo-updates",
|
|
5
|
+
"expo-application",
|
|
6
|
+
"expo-crypto",
|
|
7
|
+
"expo-secure-store",
|
|
8
|
+
"@react-native-async-storage/async-storage",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export function originalEntryCode(entry) {
|
|
12
|
+
if (entry === "__platform_default__") return "require('./ota-original-entry');";
|
|
13
|
+
if (entry === "__app_fallback__")
|
|
14
|
+
return "require('expo').registerRootComponent(require('./App').default);";
|
|
15
|
+
return `require(${JSON.stringify(entry)});`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function bootstrapCode(entry) {
|
|
19
|
+
return [
|
|
20
|
+
`const otaClient = require('${clientPackage}');`,
|
|
21
|
+
"otaClient.initializeOtaClient(require('./ota-client/config.json'));",
|
|
22
|
+
"otaClient.start();",
|
|
23
|
+
originalEntryCode(entry),
|
|
24
|
+
].join("\n");
|
|
25
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import ts from "typescript";
|
|
4
|
+
import { clientPackage } from "./ota-client-package.mjs";
|
|
4
5
|
|
|
5
6
|
const extensions = ["tsx", "jsx", "ts", "js"];
|
|
6
7
|
const suffixes = ["", ".android", ".ios", ".native", ".web"];
|
|
@@ -84,16 +85,16 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
84
85
|
const newline = text.includes("\r\n") ? "\r\n" : "\n";
|
|
85
86
|
const clientPath = path.join(appRoot, "ota-client");
|
|
86
87
|
const imports = source.statements.filter(ts.isImportDeclaration);
|
|
87
|
-
const clientImports = imports.filter(
|
|
88
|
-
(node)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
);
|
|
88
|
+
const clientImports = imports.filter((node) => {
|
|
89
|
+
if (!ts.isStringLiteral(node.moduleSpecifier)) return false;
|
|
90
|
+
const specifier = node.moduleSpecifier.text;
|
|
91
|
+
if (specifier === clientPackage) return true;
|
|
92
|
+
if (!specifier.startsWith(".")) return false;
|
|
93
|
+
const resolved = path.resolve(path.dirname(filename), specifier);
|
|
94
|
+
return ["", "/index", "/index.js", "/index.ts"].some(
|
|
95
|
+
(suffix) => resolved === clientPath + suffix,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
97
98
|
const binding = (nodes, name) =>
|
|
98
99
|
nodes
|
|
99
100
|
.flatMap((node) =>
|
|
@@ -116,15 +117,26 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
116
117
|
)
|
|
117
118
|
)
|
|
118
119
|
fail(
|
|
119
|
-
"use
|
|
120
|
+
"use an import from expo-updates-server-client or the relative ota-client path so existing configuration can be preserved",
|
|
120
121
|
);
|
|
121
|
-
const
|
|
122
|
-
|
|
122
|
+
const namespaces = clientImports.flatMap(({ importClause }) =>
|
|
123
|
+
!importClause?.isTypeOnly && importClause?.namedBindings &&
|
|
124
|
+
ts.isNamespaceImport(importClause.namedBindings)
|
|
125
|
+
? [importClause.namedBindings.name.text]
|
|
126
|
+
: [],
|
|
127
|
+
);
|
|
128
|
+
const otaBindings = (member) => new Set([
|
|
129
|
+
...clientImports.map((node) => binding([node], member)).filter(Boolean),
|
|
130
|
+
...namespaces.map((name) => `${name}.${member}`),
|
|
131
|
+
]);
|
|
132
|
+
const hookNames = otaBindings("useOtaUpdates");
|
|
133
|
+
const gateNames = otaBindings("OtaUpdateGate");
|
|
123
134
|
const createName = binding(
|
|
124
135
|
imports.filter((node) => node.moduleSpecifier.text === "react"),
|
|
125
136
|
"createElement",
|
|
126
137
|
);
|
|
127
|
-
const
|
|
138
|
+
const componentNames = otaBindings("OtaUpdates");
|
|
139
|
+
const existingName = componentNames.values().next().value;
|
|
128
140
|
const identifiers = new Set();
|
|
129
141
|
const gather = (node) => {
|
|
130
142
|
if (ts.isIdentifier(node)) identifiers.add(node.text);
|
|
@@ -135,7 +147,7 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
135
147
|
if (!existingName)
|
|
136
148
|
for (let i = 2; identifiers.has(name); i++) name = `OtaUpdates${i}`;
|
|
137
149
|
const watched = new Set(
|
|
138
|
-
[
|
|
150
|
+
[...namespaces, ...hookNames, ...gateNames, ...componentNames, createName].filter(Boolean),
|
|
139
151
|
);
|
|
140
152
|
const checkBinding = (node) => {
|
|
141
153
|
if (!node) return;
|
|
@@ -159,8 +171,7 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
159
171
|
if (ts.isReturnStatement(node)) returns.push(node);
|
|
160
172
|
if (
|
|
161
173
|
ts.isCallExpression(node) &&
|
|
162
|
-
|
|
163
|
-
node.expression.text === hookName
|
|
174
|
+
hookNames.has(node.expression.getText(source))
|
|
164
175
|
) {
|
|
165
176
|
if (hook) fail("multiple update hooks in the root");
|
|
166
177
|
hook = node;
|
|
@@ -225,7 +236,7 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
225
236
|
if (!node) return false;
|
|
226
237
|
if (
|
|
227
238
|
(ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) &&
|
|
228
|
-
tagName(node)
|
|
239
|
+
componentNames.has(tagName(node))
|
|
229
240
|
)
|
|
230
241
|
return true;
|
|
231
242
|
if (ts.isJsxElement(node) || ts.isJsxFragment(node))
|
|
@@ -237,12 +248,12 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
237
248
|
if (!node) return false;
|
|
238
249
|
if (
|
|
239
250
|
(ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) &&
|
|
240
|
-
tagName(node)
|
|
251
|
+
componentNames.has(tagName(node))
|
|
241
252
|
)
|
|
242
253
|
return true;
|
|
243
254
|
return ts.forEachChild(node, containsComponent) || false;
|
|
244
255
|
};
|
|
245
|
-
const obsolete = new Set([
|
|
256
|
+
const obsolete = new Set([...hookNames, ...gateNames, createName].filter(Boolean));
|
|
246
257
|
const expressions = ts.isBlock(component.body)
|
|
247
258
|
? returns.map((node) => ({ node, expression: node.expression }))
|
|
248
259
|
: [{ expression: component.body }];
|
|
@@ -266,7 +277,7 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
266
277
|
ts.isCallExpression(child) &&
|
|
267
278
|
ts.isIdentifier(child.expression) &&
|
|
268
279
|
child.expression.text === createName &&
|
|
269
|
-
child.arguments[0]?.getText(source)
|
|
280
|
+
gateNames.has(child.arguments[0]?.getText(source))
|
|
270
281
|
) {
|
|
271
282
|
const settings = child.arguments[1];
|
|
272
283
|
if (
|
|
@@ -285,7 +296,7 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
285
296
|
} else if (
|
|
286
297
|
child &&
|
|
287
298
|
(ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child)) &&
|
|
288
|
-
tagName(child)
|
|
299
|
+
gateNames.has(tagName(child))
|
|
289
300
|
) {
|
|
290
301
|
const opening = child.openingElement || child;
|
|
291
302
|
const attrs = opening.attributes.properties;
|
|
@@ -335,24 +346,20 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
335
346
|
};
|
|
336
347
|
inspectReferences(component.body);
|
|
337
348
|
}
|
|
349
|
+
const migrateImportsOnly = !edits.length;
|
|
338
350
|
for (const node of clientImports) {
|
|
339
|
-
if (node.moduleSpecifier.text
|
|
351
|
+
if (node.moduleSpecifier.text !== clientPackage) {
|
|
340
352
|
const specifier = node.moduleSpecifier;
|
|
341
353
|
const quote = text[specifier.getStart(source)];
|
|
342
354
|
edits.push({
|
|
343
355
|
start: specifier.getStart(source),
|
|
344
356
|
end: specifier.end,
|
|
345
|
-
content: `${quote}${
|
|
357
|
+
content: `${quote}${clientPackage}${quote}`,
|
|
346
358
|
});
|
|
347
359
|
}
|
|
348
360
|
}
|
|
349
361
|
if (!edits.length) return text;
|
|
350
362
|
if (!existingName) {
|
|
351
|
-
let relative = path
|
|
352
|
-
.relative(path.dirname(filename), clientPath)
|
|
353
|
-
.split(path.sep)
|
|
354
|
-
.join("/");
|
|
355
|
-
if (!relative.startsWith(".")) relative = `./${relative}`;
|
|
356
363
|
let at =
|
|
357
364
|
imports.at(-1)?.end ??
|
|
358
365
|
source.statements[0]?.getStart(source) ??
|
|
@@ -366,11 +373,12 @@ export function patchOtaRootHook(text, filename, appRoot) {
|
|
|
366
373
|
edits.push({
|
|
367
374
|
start: at,
|
|
368
375
|
end: at,
|
|
369
|
-
content: `${newline}import { ${specifier} } from '${
|
|
376
|
+
content: `${newline}import { ${specifier} } from '${clientPackage}';${newline}`,
|
|
370
377
|
});
|
|
371
378
|
}
|
|
372
379
|
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
373
380
|
text = text.slice(0, edit.start) + edit.content + text.slice(edit.end);
|
|
381
|
+
if (migrateImportsOnly) return text;
|
|
374
382
|
// Drop only obsolete imports which no longer have references after migration.
|
|
375
383
|
const updated = ts.createSourceFile(
|
|
376
384
|
filename,
|
|
@@ -443,6 +451,44 @@ function formatRoot(text, filename, newline) {
|
|
|
443
451
|
}
|
|
444
452
|
}
|
|
445
453
|
|
|
454
|
+
// Expo's blank template imports App and registers it directly in index.js.
|
|
455
|
+
function registersDefaultApp(filename) {
|
|
456
|
+
const source = ts.createSourceFile(
|
|
457
|
+
filename,
|
|
458
|
+
fs.readFileSync(filename, "utf8"),
|
|
459
|
+
ts.ScriptTarget.Latest,
|
|
460
|
+
true,
|
|
461
|
+
);
|
|
462
|
+
if (source.parseDiagnostics.length || source.statements.length !== 3)
|
|
463
|
+
return false;
|
|
464
|
+
const imports = source.statements.filter(ts.isImportDeclaration);
|
|
465
|
+
const registration = imports.find(
|
|
466
|
+
(node) => node.moduleSpecifier.text === "expo",
|
|
467
|
+
)?.importClause?.namedBindings;
|
|
468
|
+
const app = imports.find((node) => node.moduleSpecifier.text === "./App")
|
|
469
|
+
?.importClause?.name;
|
|
470
|
+
if (!app || !registration || !ts.isNamedImports(registration)) return false;
|
|
471
|
+
const register = registration.elements.find(
|
|
472
|
+
(element) =>
|
|
473
|
+
(element.propertyName ?? element.name).text === "registerRootComponent",
|
|
474
|
+
);
|
|
475
|
+
const last = source.statements[2];
|
|
476
|
+
if (
|
|
477
|
+
!register ||
|
|
478
|
+
!ts.isExpressionStatement(last) ||
|
|
479
|
+
!ts.isCallExpression(last.expression)
|
|
480
|
+
)
|
|
481
|
+
return false;
|
|
482
|
+
const call = last.expression;
|
|
483
|
+
return (
|
|
484
|
+
ts.isIdentifier(call.expression) &&
|
|
485
|
+
call.expression.text === register.name.text &&
|
|
486
|
+
call.arguments.length === 1 &&
|
|
487
|
+
ts.isIdentifier(call.arguments[0]) &&
|
|
488
|
+
call.arguments[0].text === app.text
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
|
|
446
492
|
export function planOtaRootHook({ appRoot, originalEntry }) {
|
|
447
493
|
const candidates = (base) =>
|
|
448
494
|
suffixes
|
|
@@ -458,9 +504,21 @@ export function planOtaRootHook({ appRoot, originalEntry }) {
|
|
|
458
504
|
? "src/app/_layout"
|
|
459
505
|
: "app/_layout",
|
|
460
506
|
);
|
|
507
|
+
} else if (
|
|
508
|
+
/^(?:\.\/)?index(?:\.[jt]sx?)?$/.test(originalEntry) ||
|
|
509
|
+
originalEntry === "__platform_default__"
|
|
510
|
+
) {
|
|
511
|
+
const entries = candidates("index");
|
|
512
|
+
if (
|
|
513
|
+
entries.length &&
|
|
514
|
+
entries.every((entry) => registersDefaultApp(path.join(appRoot, entry)))
|
|
515
|
+
) {
|
|
516
|
+
roots = candidates("App");
|
|
517
|
+
} else if (!entries.length && originalEntry === "__platform_default__") {
|
|
518
|
+
roots = candidates("App");
|
|
519
|
+
}
|
|
461
520
|
} else if (
|
|
462
521
|
[
|
|
463
|
-
"__platform_default__",
|
|
464
522
|
"__app_fallback__",
|
|
465
523
|
"node_modules/expo/AppEntry.js",
|
|
466
524
|
"expo/AppEntry",
|
|
@@ -474,7 +532,7 @@ export function planOtaRootHook({ appRoot, originalEntry }) {
|
|
|
474
532
|
return {
|
|
475
533
|
files: [],
|
|
476
534
|
warnings: [
|
|
477
|
-
"The OTA identity/telemetry bootstrap is configured, but no safely identifiable root component was found. Render <OtaUpdates /> from
|
|
535
|
+
"The OTA identity/telemetry bootstrap is configured, but no safely identifiable root component was found. Render <OtaUpdates /> from expo-updates-server-client beside navigation in your main layout to enable update orchestration.",
|
|
478
536
|
],
|
|
479
537
|
};
|
|
480
538
|
return {
|
|
@@ -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
|
+
}
|