create-expo-updates-server 0.1.6 → 0.2.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 (139) hide show
  1. package/dist/template/.dockerignore +16 -0
  2. package/dist/template/README.md +51 -660
  3. package/dist/template/app/api/admin/device-targets/route.test.ts +43 -0
  4. package/dist/template/app/api/admin/device-targets/route.ts +91 -0
  5. package/dist/template/app/api/admin/devices/route.test.ts +41 -0
  6. package/dist/template/app/api/admin/devices/route.ts +15 -0
  7. package/dist/template/app/api/admin/updates/[encodedKey]/audience/route.ts +75 -0
  8. package/dist/template/app/api/device-heartbeat/route.ts +2 -0
  9. package/dist/template/app/globals.css +114 -15
  10. package/dist/template/app/layout.tsx +12 -4
  11. package/dist/template/app/login/page.tsx +22 -18
  12. package/dist/template/app/updates/[encodedKey]/page.tsx +112 -88
  13. package/dist/template/app/updates/devices/page.tsx +264 -0
  14. package/dist/template/app/updates/embedded/page.tsx +102 -68
  15. package/dist/template/app/updates/emergency-redirects/page.tsx +144 -111
  16. package/dist/template/app/updates/layout.tsx +6 -1
  17. package/dist/template/app/updates/page.tsx +262 -212
  18. package/dist/template/components/admin/admin-shell.tsx +196 -0
  19. package/dist/template/components/admin/language-switcher.tsx +25 -0
  20. package/dist/template/components/admin/theme-provider.tsx +15 -0
  21. package/dist/template/components/ui/alert.tsx +65 -0
  22. package/dist/template/components/ui/badge.tsx +47 -0
  23. package/dist/template/components/ui/button.tsx +63 -0
  24. package/dist/template/components/ui/card.tsx +91 -0
  25. package/dist/template/components/ui/chart.tsx +373 -0
  26. package/dist/template/components/ui/checkbox.tsx +31 -0
  27. package/dist/template/components/ui/dialog.tsx +158 -0
  28. package/dist/template/components/ui/dropdown-menu.tsx +256 -0
  29. package/dist/template/components/ui/input.tsx +20 -0
  30. package/dist/template/components/ui/label.tsx +23 -0
  31. package/dist/template/components/ui/native-select.tsx +61 -0
  32. package/dist/template/components/ui/popover.tsx +88 -0
  33. package/dist/template/components/ui/scroll-area.tsx +57 -0
  34. package/dist/template/components/ui/select.tsx +189 -0
  35. package/dist/template/components/ui/separator.tsx +27 -0
  36. package/dist/template/components/ui/sheet.tsx +142 -0
  37. package/dist/template/components/ui/sidebar.tsx +736 -0
  38. package/dist/template/components/ui/skeleton.tsx +13 -0
  39. package/dist/template/components/ui/switch.tsx +34 -0
  40. package/dist/template/components/ui/table.tsx +115 -0
  41. package/dist/template/components/ui/tabs.tsx +90 -0
  42. package/dist/template/components/ui/textarea.tsx +17 -0
  43. package/dist/template/components/ui/tooltip.tsx +56 -0
  44. package/dist/template/components.json +22 -0
  45. package/dist/template/docs/admin-ui.md +35 -0
  46. package/dist/template/docs/device-targeting.md +129 -0
  47. package/dist/template/docs/doctor.md +137 -0
  48. package/dist/template/docs/expo-app-setup.md +174 -47
  49. package/dist/template/docs/getting-started.md +105 -146
  50. package/dist/template/docs/getting-started.ru.md +106 -191
  51. package/dist/template/docs/index.md +14 -33
  52. package/dist/template/docs/installation-telemetry.md +233 -0
  53. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +89 -0
  54. package/dist/template/docs/migrations/2026-10-19-device-heartbeat.sql +131 -0
  55. package/dist/template/docs/migrations/2026-10-22-device-analytics.sql +264 -0
  56. package/dist/template/docs/migrations/2026-10-22-device-targeting-activation.sql +108 -0
  57. package/dist/template/docs/migrations/2026-10-22-device-targeting.sql +130 -0
  58. package/dist/template/docs/migrations/2026-10-22-device-version-metadata.sql +154 -0
  59. package/dist/template/docs/migrations/schema.sql +868 -6
  60. package/dist/template/docs/npm-installer.md +15 -30
  61. package/dist/template/docs/operations-guide.md +87 -0
  62. package/dist/template/docs/ota-client-lifecycle.md +263 -0
  63. package/dist/template/docs/ota-update-policy.md +36 -2
  64. package/dist/template/docs/supabase-setup.md +4 -0
  65. package/dist/template/hooks/use-mobile.ts +21 -0
  66. package/dist/template/lib/utils.ts +6 -0
  67. package/dist/template/package-lock.json +2325 -101
  68. package/dist/template/package.json +13 -3
  69. package/dist/template/scripts/configure-expo-app.mjs +11 -15
  70. package/dist/template/scripts/doctor.mjs +51 -0
  71. package/dist/template/scripts/ensure-test-bucket.mjs +21 -0
  72. package/dist/template/scripts/lib/device-identity.test.ts +29 -0
  73. package/dist/template/scripts/lib/doctor-probes.mjs +139 -0
  74. package/dist/template/scripts/lib/doctor.mjs +208 -0
  75. package/dist/template/scripts/lib/doctor.test.mjs +262 -0
  76. package/dist/template/scripts/lib/expo-app-configurator.mjs +14 -9
  77. package/dist/template/scripts/lib/expo-app-configurator.test.ts +3 -2
  78. package/dist/template/scripts/lib/ota-client-configurator.mjs +69 -0
  79. package/dist/template/scripts/lib/ota-client-configurator.test.ts +88 -0
  80. package/dist/template/scripts/lib/ota-client.test.ts +55 -0
  81. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +173 -0
  82. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +123 -0
  83. package/dist/template/scripts/lib/ota-update-controller.test.ts +231 -0
  84. package/dist/template/scripts/tests/device-analytics-migrations.mjs +80 -0
  85. package/dist/template/scripts/tests/device-analytics.mjs +126 -0
  86. package/dist/template/scripts/tests/device-heartbeat.mjs +86 -0
  87. package/dist/template/scripts/tests/device-targeting-activation.mjs +111 -0
  88. package/dist/template/scripts/tests/device-targeting.mjs +39 -0
  89. package/dist/template/scripts/tests/device-version-metadata.mjs +31 -0
  90. package/dist/template/scripts/tests/manifest-identity-concurrency.mjs +106 -0
  91. package/dist/template/scripts/tests/manifest-identity.sql +204 -0
  92. package/dist/template/src/client/admin-types.ts +1 -0
  93. package/dist/template/src/client/devices/analytics.tsx +429 -0
  94. package/dist/template/src/client/devices/device-name.tsx +82 -0
  95. package/dist/template/src/client/devices/registry.tsx +399 -0
  96. package/dist/template/src/client/devices/use-devices-report.ts +108 -0
  97. package/dist/template/src/client/devices/version-adoption-chart.tsx +269 -0
  98. package/dist/template/src/client/devices/version-groups.test.ts +57 -0
  99. package/dist/template/src/client/devices/version-groups.ts +101 -0
  100. package/dist/template/src/client/distribution-control.tsx +135 -81
  101. package/dist/template/src/client/guard-action-combobox.tsx +13 -24
  102. package/dist/template/src/client/i18n/en.json +286 -0
  103. package/dist/template/src/client/i18n/messages.test.ts +42 -0
  104. package/dist/template/src/client/i18n/messages.ts +31 -0
  105. package/dist/template/src/client/i18n/provider.tsx +55 -0
  106. package/dist/template/src/client/i18n/use-formatters.ts +38 -0
  107. package/dist/template/src/client/logout-button.tsx +3 -1
  108. package/dist/template/src/client/update-audience-editor.tsx +285 -0
  109. package/dist/template/src/client/update-policy-editor.tsx +53 -41
  110. package/dist/template/src/server/controllers/manifest.test.ts +250 -7
  111. package/dist/template/src/server/controllers/manifest.ts +39 -31
  112. package/dist/template/src/server/devices/audience.test.ts +48 -0
  113. package/dist/template/src/server/devices/audience.ts +86 -0
  114. package/dist/template/src/server/devices/heartbeat.test.ts +39 -0
  115. package/dist/template/src/server/devices/heartbeat.ts +75 -0
  116. package/dist/template/src/server/devices/report-types.ts +114 -0
  117. package/dist/template/src/server/devices/report.test.ts +29 -0
  118. package/dist/template/src/server/devices/report.ts +27 -0
  119. package/dist/template/src/server/lib/admin-audience-activation.test.ts +94 -0
  120. package/dist/template/src/server/lib/admin-updates.ts +32 -168
  121. package/dist/template/src/server/lib/supabase.js +10 -10
  122. package/dist/template/src/server/lib/supabase.test.ts +11 -0
  123. package/dist/template/src/server/manifest/manifest-identity.test.ts +30 -0
  124. package/dist/template/src/server/manifest/manifest-identity.ts +24 -0
  125. package/dist/template/src/server/manifest/manifest-repository.ts +31 -102
  126. package/dist/template/src/server/manifest/manifest-response.ts +1 -1
  127. package/dist/template/templates/expo-app/ota-client/README.md +59 -0
  128. package/dist/template/templates/expo-app/ota-client/controller.js +60 -0
  129. package/dist/template/templates/expo-app/ota-client/device-identity.js +26 -0
  130. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +52 -0
  131. package/dist/template/templates/expo-app/ota-client/index.d.ts +47 -0
  132. package/dist/template/templates/expo-app/ota-client/index.js +3 -0
  133. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +48 -0
  134. package/dist/template/templates/expo-app/ota-client/model/update-controller.js +182 -0
  135. package/dist/template/templates/expo-app/ota-client/runtime.js +112 -0
  136. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +56 -0
  137. package/dist/template-manifest.json +578 -73
  138. package/lib/cli.mjs +4 -6
  139. package/package.json +1 -1
@@ -0,0 +1,182 @@
1
+ // Pure lifecycle model. Native APIs, storage and React live in adapters.
2
+ export function createUpdateController(deps) {
3
+ let state = Object.freeze({ enabled: deps.enabled, status: 'idle', installationId: null,
4
+ deviceId: null, available: false, pending: false, candidate: null, policy: null,
5
+ blocked: false, blockReason: null, error: null });
6
+ const listeners = new Set();
7
+ const owners = new Map();
8
+ let flight;
9
+ let flightKind;
10
+ let lastAutomaticCheck = -Infinity;
11
+ let identityReady;
12
+ let pendingKey;
13
+ let pendingGeneration = 0;
14
+ const now = deps.now || Date.now;
15
+ function patch(value) {
16
+ state = Object.freeze({ ...state, ...value });
17
+ for (const listener of listeners) listener();
18
+ }
19
+ function options() {
20
+ const result = { autoCheck: false, autoUpdate: false, autoReload: false, guardHandlers: {} };
21
+ for (const owner of owners.values()) {
22
+ for (const key of ['autoCheck', 'autoUpdate', 'autoReload']) result[key] ||= owner[key] === true;
23
+ Object.assign(result.guardHandlers, owner.guardHandlers);
24
+ }
25
+ return result;
26
+ }
27
+ function initialize() {
28
+ deps.start();
29
+ if (!deps.enabled) return Promise.resolve();
30
+ if (!identityReady) identityReady = deps.identity().then(async (identity) => {
31
+ patch(identity);
32
+ await inspectRunning();
33
+ }).catch((error) => {
34
+ identityReady = undefined;
35
+ patch({ error });
36
+ throw error;
37
+ });
38
+ return identityReady;
39
+ }
40
+ function run(kind, task) {
41
+ if (!deps.enabled) return Promise.reject(new Error('OTA updates are unavailable in this build'));
42
+ if (flight) {
43
+ if (flightKind === kind) return flight;
44
+ return Promise.reject(new Error('Another OTA operation is in progress'));
45
+ }
46
+ flightKind = kind;
47
+ patch({ status: kind, error: null });
48
+ flight = Promise.resolve().then(initialize).then(task).catch((error) => {
49
+ patch({ error });
50
+ throw error;
51
+ }).finally(() => {
52
+ flight = undefined;
53
+ flightKind = undefined;
54
+ patch({ status: 'idle' });
55
+ });
56
+ return flight;
57
+ }
58
+ async function inspect(candidate) {
59
+ const policy = candidate?.manifest?.extra?.updatePolicy ?? null;
60
+ patch({ candidate, policy, blocked: false, blockReason: null });
61
+ if (!policy) return;
62
+ if (policy.schemaVersion !== 1 || !['manual', 'background'].includes(policy.delivery)) {
63
+ patch({ blocked: true, blockReason: 'unsupported-policy' });
64
+ return;
65
+ }
66
+ const guard = policy.guard;
67
+ if (!guard) return;
68
+ // Fail closed while an asynchronous application guard is being evaluated.
69
+ patch({ blocked: true, blockReason: guard.action || 'unsupported-policy' });
70
+ if (guard.action === 'ota-force-update' || guard.action === 'ota-force-store-update') return;
71
+ const handler = options().guardHandlers[guard.action];
72
+ if (!handler) return;
73
+ const decision = await handler({ action: guard.action, payload: guard.payload, manifest: candidate.manifest });
74
+ if (decision === 'allow') patch({ blocked: false, blockReason: null });
75
+ }
76
+ async function inspectRunning() {
77
+ const running = deps.runningCandidate?.();
78
+ // Force OTA is fulfilled by launching it. Store/custom guards still apply
79
+ // after a native cold start, including a bundle fetched during a release race.
80
+ if (running?.manifest?.extra?.updatePolicy?.guard?.action === 'ota-force-update') return inspect(null);
81
+ return inspect(running || null);
82
+ }
83
+ function canDownload() { return !state.blocked || state.blockReason === 'ota-force-update'; }
84
+ async function downloadInternal() {
85
+ if (!state.available && !state.pending) throw new Error('Check for an update before downloading');
86
+ if (!canDownload()) throw new Error('Update is blocked by its guard');
87
+ patch({ status: 'downloading' });
88
+ const result = await deps.fetch();
89
+ if (result.isNew || result.isRollBackToEmbedded) {
90
+ const candidate = target(result);
91
+ pendingKey = key(candidate);
92
+ pendingGeneration += 1;
93
+ // Fetch performs another manifest request: its policy can differ from check's.
94
+ patch({ pending: true, available: true });
95
+ await inspect(candidate);
96
+ }
97
+ return result;
98
+ }
99
+ async function reloadInternal() {
100
+ if (!state.pending) throw new Error('No downloaded update is ready');
101
+ if (!canDownload()) throw new Error('Update is blocked by its guard');
102
+ if (!deps.isActive()) throw new Error('Reload is only allowed while the app is active');
103
+ patch({ status: 'reloading' });
104
+ return deps.reload();
105
+ }
106
+ async function automate(allowDownload = true) {
107
+ const settings = options();
108
+ if (allowDownload && !state.pending && state.available && canDownload() &&
109
+ (settings.autoUpdate || state.policy?.delivery === 'background' || state.blockReason === 'ota-force-update')) {
110
+ await downloadInternal();
111
+ }
112
+ // A background policy always wins over autoReload. Guards are re-evaluated after fetch.
113
+ if (state.pending && canDownload() && settings.autoReload &&
114
+ state.policy?.delivery !== 'background' && deps.isActive()) await reloadInternal();
115
+ }
116
+ function check() {
117
+ return run('checking', async () => {
118
+ const result = await deps.check();
119
+ if (result.isAvailable || result.isRollBackToEmbedded) {
120
+ patch({ available: true });
121
+ // Never replace the policy governing an already downloaded bundle with a different candidate.
122
+ if (!state.pending) await inspect(target(result));
123
+ } else if (!state.pending) {
124
+ patch({ available: false });
125
+ await inspectRunning();
126
+ }
127
+ if (state.pending) await inspect(state.candidate);
128
+ await automate();
129
+ return result;
130
+ });
131
+ }
132
+ function automaticCheck() {
133
+ if (!deps.enabled || !options().autoCheck || !deps.isActive() || flight || now() - lastAutomaticCheck < 60000) return;
134
+ lastAutomaticCheck = now();
135
+ void check().catch(() => undefined);
136
+ }
137
+ const api = {
138
+ getSnapshot: () => state,
139
+ subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
140
+ initialize,
141
+ configure(owner, value) { owners.set(owner, value); },
142
+ removeOwner(owner) { owners.delete(owner); },
143
+ automaticCheck,
144
+ check,
145
+ download: () => run('downloading', async () => {
146
+ const result = await downloadInternal();
147
+ await automate(false);
148
+ return result;
149
+ }),
150
+ reload: () => run('reloading', reloadInternal),
151
+ retry: () => check(),
152
+ openStore: () => run('opening-store', async () => {
153
+ if (state.blockReason !== 'ota-force-store-update') throw new Error('No store upgrade is required');
154
+ await deps.openStore(state.policy.guard.payload);
155
+ }),
156
+ syncPending(candidate) {
157
+ if (!candidate || key(candidate) === pendingKey) return Promise.resolve();
158
+ if (flight) {
159
+ const observedGeneration = pendingGeneration;
160
+ return flight.catch(() => undefined).then(() => {
161
+ if (pendingGeneration === observedGeneration) return api.syncPending(candidate);
162
+ });
163
+ }
164
+ return run('checking', async () => {
165
+ pendingKey = key(candidate);
166
+ pendingGeneration += 1;
167
+ patch({ pending: true, available: true });
168
+ await inspect(candidate);
169
+ // Synchronizing native state never implicitly reloads a restored bundle.
170
+ });
171
+ },
172
+ };
173
+ return api;
174
+ }
175
+
176
+ function target(result) {
177
+ if (result.isRollBackToEmbedded) return { type: 'rollback', manifest: null };
178
+ return { type: 'new', manifest: result.manifest };
179
+ }
180
+ function key(candidate) {
181
+ return candidate.type === 'rollback' ? 'rollback' : candidate.manifest?.id;
182
+ }
@@ -0,0 +1,112 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import * as Application from 'expo-application';
3
+ import * as Crypto from 'expo-crypto';
4
+ import * as SecureStore from 'expo-secure-store';
5
+ import { createDeviceIdentity } from './device-identity';
6
+ import * as Updates from 'expo-updates';
7
+ import { AppState, Platform } from 'react-native';
8
+ import { createInstallationClient } from './controller';
9
+ import config from './config.json';
10
+
11
+ const STORAGE_KEY = '@ota-client/installation-v1';
12
+ export const enabled = Platform.OS !== 'web' && !__DEV__ && Updates.isEnabled;
13
+ const resolveDeviceId = createDeviceIdentity({
14
+ platform: Platform.OS,
15
+ scope: `${Application.applicationId}:${config.identityNamespace}`,
16
+ androidId: () => Application.getAndroidId(),
17
+ readSecure: (key) => SecureStore.getItemAsync(key),
18
+ writeSecure: (key, value) => SecureStore.setItemAsync(key, value, { keychainAccessible: SecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY }),
19
+ uuid: () => Crypto.randomUUID(),
20
+ digest: (value) => Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, value),
21
+ });
22
+ let deviceId = null;
23
+ const client = createInstallationClient({
24
+ read: () => AsyncStorage.getItem(STORAGE_KEY),
25
+ write: (value) => AsyncStorage.setItem(STORAGE_KEY, value),
26
+ uuid: () => Crypto.randomUUID(),
27
+ setIdentity: async (id) => {
28
+ await Updates.setExtraParamAsync('installation_id', id);
29
+ // Temporary Keychain failure must not stop installation telemetry or keep a stale identity.
30
+ deviceId = await resolveDeviceId().catch(() => null);
31
+ await Updates.setExtraParamAsync('device_id', deviceId);
32
+ },
33
+ snapshot: () => ({
34
+ ...(deviceId ? { deviceId } : {}),
35
+ platform: Platform.OS, channel: Updates.manifest?.metadata?.channel || config.channel, runtimeVersion: Updates.runtimeVersion,
36
+ updateId: Updates.updateId, nativeVersion: Application.nativeApplicationVersion,
37
+ nativeBuild: Application.nativeBuildVersion, isEmbeddedLaunch: Updates.isEmbeddedLaunch,
38
+ isEmergencyLaunch: Updates.isEmergencyLaunch,
39
+ }),
40
+ send: async (event) => {
41
+ const abort = new AbortController();
42
+ const timeout = setTimeout(() => abort.abort(), 8000);
43
+ try {
44
+ const response = await fetch(config.heartbeatUrl, {
45
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
46
+ body: JSON.stringify(event), signal: abort.signal,
47
+ });
48
+ if (!response.ok) {
49
+ const error = new Error(`Heartbeat HTTP ${response.status}`);
50
+ error.permanent = response.status === 400 || response.status === 409;
51
+ throw error;
52
+ }
53
+ const result = await response.json();
54
+ if (!['accepted', 'duplicate', 'stale'].includes(result.status)) throw new Error('Invalid heartbeat response');
55
+ } finally { clearTimeout(timeout); }
56
+ },
57
+ });
58
+
59
+ let started = false;
60
+ let timer;
61
+ let lastObservation = 0;
62
+ let failures = 0;
63
+ let ticking;
64
+ function schedule() {
65
+ clearTimeout(timer);
66
+ if (AppState.currentState !== 'active') return;
67
+ timer = setTimeout(tick, Math.min(60000 * 2 ** failures, 300000));
68
+ }
69
+ async function performTick() {
70
+ clearTimeout(timer);
71
+ try {
72
+ // Retry the exact durable event before replacing it with a fresh observation.
73
+ try { await client.flush(); } catch (error) { if (!error.permanent) throw error; }
74
+ if (Date.now() - lastObservation >= 60000) {
75
+ await client.observe();
76
+ lastObservation = Date.now();
77
+ }
78
+ failures = 0;
79
+ } catch { failures = Math.min(failures + 1, 3); }
80
+ finally { schedule(); }
81
+ }
82
+ function tick() {
83
+ if (ticking) return ticking;
84
+ ticking = performTick().finally(() => { ticking = undefined; });
85
+ return ticking;
86
+ }
87
+ export function start() {
88
+ if (started || !enabled) return;
89
+ started = true;
90
+ // Registration of the original application entry never waits for telemetry.
91
+ void client.observe().then(() => { lastObservation = Date.now(); }).catch(() => undefined).finally(schedule);
92
+ AppState.addEventListener('change', (state) => {
93
+ if (state === 'active') void tick();
94
+ else clearTimeout(timer);
95
+ });
96
+ }
97
+ export async function getInstallationId() {
98
+ if (!enabled) return null;
99
+ return client.ready();
100
+ }
101
+ export async function getDeviceId() {
102
+ await getInstallationId();
103
+ return deviceId;
104
+ }
105
+ export async function checkForUpdateAsync() {
106
+ await getInstallationId();
107
+ return Updates.checkForUpdateAsync();
108
+ }
109
+ export async function fetchUpdateAsync() {
110
+ await getInstallationId();
111
+ return Updates.fetchUpdateAsync();
112
+ }
@@ -0,0 +1,56 @@
1
+ import { createElement as h, Fragment } from 'react';
2
+ import { ActivityIndicator, Modal, Pressable, StyleSheet, Text, View } from 'react-native';
3
+
4
+ /** Replace this view using renderBlocked; keep the controller's guard decision intact. */
5
+ export function OtaUpdateGate({ controller, children, renderBlocked }) {
6
+ // Keep navigation/providers/splash handling mounted while the modal blocks interaction.
7
+ let overlay = null;
8
+ if (controller.blocked) {
9
+ let content = h(DefaultGate, { controller });
10
+ if (renderBlocked) content = renderBlocked(controller);
11
+ overlay = h(Modal, { visible: true, animationType: 'none',
12
+ presentationStyle: 'fullScreen', onRequestClose: () => {} }, content);
13
+ }
14
+ return h(Fragment, null, children, overlay);
15
+ }
16
+
17
+ function DefaultGate({ controller }) {
18
+ let title = 'Update required';
19
+ let description = 'An application update is required to continue.';
20
+ let label = 'Retry';
21
+ let action = controller.retry;
22
+ if (controller.blockReason === 'ota-force-store-update') {
23
+ description = 'Install the latest version from the store to continue.';
24
+ label = 'Open store';
25
+ action = controller.openStore;
26
+ } else if (controller.blockReason === 'ota-force-update') {
27
+ if (controller.pending) {
28
+ description = 'The update is ready. Restart the application to continue.';
29
+ label = 'Restart';
30
+ action = controller.reload;
31
+ }
32
+ } else {
33
+ title = 'Update needs attention';
34
+ description = 'This update requires an action before you can continue.';
35
+ }
36
+ const childrenList = [h(Text, { key: 'title', style: styles.title, accessibilityRole: 'header' }, title),
37
+ h(Text, { key: 'description', style: styles.text }, description)];
38
+ if (controller.error) childrenList.push(h(Text, { key: 'error', style: styles.error, accessibilityRole: 'alert' }, controller.error.message));
39
+ if (controller.isBusy) childrenList.push(h(ActivityIndicator, { key: 'busy', color: '#93c5fd', accessibilityLabel: 'Updating application' }));
40
+ childrenList.push(h(Pressable, { key: 'action', style: styles.button, accessibilityRole: 'button',
41
+ accessibilityState: { disabled: controller.isBusy }, disabled: controller.isBusy,
42
+ onPress: () => { void action().catch(() => undefined); } }, h(Text, { style: styles.buttonText }, label)));
43
+ if (controller.blockReason === 'ota-force-store-update') childrenList.push(h(Pressable, {
44
+ key: 'retry', style: styles.button, accessibilityRole: 'button', disabled: controller.isBusy,
45
+ onPress: () => { void controller.retry().catch(() => undefined); },
46
+ }, h(Text, { style: styles.buttonText }, 'Check again')));
47
+ return h(View, { style: styles.root }, ...childrenList);
48
+ }
49
+ const styles = StyleSheet.create({
50
+ root: { flex: 1, justifyContent: 'center', padding: 28, gap: 20, backgroundColor: '#0f172a' },
51
+ title: { color: '#f8fafc', fontSize: 26, fontWeight: '700' },
52
+ text: { color: '#cbd5e1', fontSize: 16, lineHeight: 24 },
53
+ error: { color: '#fca5a5', fontSize: 14 },
54
+ button: { minHeight: 48, justifyContent: 'center', alignItems: 'center', backgroundColor: '#2563eb', borderRadius: 12, padding: 12 },
55
+ buttonText: { color: '#fff', fontSize: 16, fontWeight: '600' },
56
+ });