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
@@ -6,9 +6,11 @@ receiving and publishing updates.
6
6
  ## Automatic configuration
7
7
 
8
8
  Applications using a static `app.json` can be configured from the OTA server
9
- repository:
9
+ repository. Install the server dependencies on the host first, including when
10
+ the server itself runs in Docker:
10
11
 
11
12
  ```bash
13
+ npm ci
12
14
  npm run configure-app
13
15
  ```
14
16
 
@@ -27,26 +29,145 @@ npm run configure-app -- \
27
29
  ```
28
30
 
29
31
  The command patches `app.json` and `package.json`, copies the public
30
- certificate, installs `expo-updates`, adds the portable publisher and runs
32
+ certificate, installs `expo-updates` and the identity/telemetry dependencies, adds the portable publisher and runs
31
33
  `expo prebuild`. It supports npm, pnpm, Yarn and Bun lockfiles.
32
34
 
35
+ It also generates `ota-client/` and starts identity/installation telemetry from
36
+ `ota-entry.js`, preserving the original application entry. For Expo Router,
37
+ the configurator inserts `useOtaUpdates` into `src/app/_layout` (or `app/_layout`)
38
+ and wraps the root's rendered content with `OtaUpdateGate`. Standard `App`
39
+ entry components are supported too, including platform variants. No manual
40
+ Installation ID, Device ID, or heartbeat wiring is needed. The initial hook
41
+ options are `{ autoCheck: true, autoUpdate: false, autoReload: false }`;
42
+ customized options are preserved on later configurations. See the generated
43
+ [OTA client lifecycle](./ota-client-lifecycle.md) for update modes and the hook API.
44
+ If generation is unavailable, follow [manual hook integration](./ota-client-lifecycle.md#manual-integration).
45
+
46
+ The source patch uses syntax-tree locations and keeps existing imports, comments,
47
+ directives, component code and nested callbacks. Unsupported root exports
48
+ (such as a class, asynchronous function, HOC or re-export) stop configuration
49
+ before any application writes. Export a synchronous root function or a local
50
+ function identifier to make the patch possible. A custom entry whose root
51
+ cannot be identified keeps its existing startup behavior and prints a warning
52
+ that update orchestration still needs integration in its root component;
53
+ identity and telemetry remain connected through the generated bootstrap.
54
+ An existing `useOtaUpdates` import must use a relative path to `ota-client`.
55
+ Unresolved aliases such as `@/ota-client` stop the patch before writing, so a
56
+ second hook cannot silently override an existing automation configuration.
57
+
33
58
  Options:
34
59
 
35
60
  ```text
36
61
  --platform all|ios|android
37
62
  --force
63
+ --server-env /full/path/to/server.env
38
64
  ```
39
65
 
40
66
  The CLI intentionally refuses dynamic `app.config.*` projects and refuses to
41
67
  replace generated files unless `--force` is provided. The sections below
42
- document the equivalent manual configuration.
68
+ document native configuration; [manual hook integration](./ota-client-lifecycle.md#manual-integration)
69
+ covers client files, dependencies, root wiring and controls. `--force` permits generated
70
+ file replacement; it does not bypass unsupported dynamic configs or root shapes.
71
+ `--server-env` selects the local server environment used to prepare publisher settings.
72
+ For an isolated test stand, explicitly pass its `.env.ota-test`.
73
+
74
+ ## Verify generation in a fresh application
75
+
76
+ Use a separate app to check first-time generation, and retain an existing app to
77
+ check upgrades/reruns. Do not reuse another app's runtime just to make a test OTA
78
+ appear: the new app has its own native compatibility boundary.
79
+
80
+ Create a sibling Expo Router application using the SDK 58 template used for this
81
+ client's integration checks:
82
+
83
+ ```bash
84
+ npx create-expo-app@latest ota-smoke-app --template default@sdk-58
85
+ ```
86
+
87
+ The explicit template pins the SDK family; see the official
88
+ [create-expo-app reference](https://docs.expo.dev/more/create-expo/). For another SDK,
89
+ use its compatible packages and repeat the release-device checks below.
90
+
91
+ Prepare a reachable HTTPS OTA server and its matching public signing certificate.
92
+ Then run from the **server repository**, adjusting the application/certificate paths:
93
+
94
+ ```bash
95
+ npm run configure-app -- \
96
+ --app /full/path/to/ota-smoke-app \
97
+ --certificate /full/path/code-signing-certificate.pem \
98
+ --server-url https://updates.example.com \
99
+ --channel hook-smoke \
100
+ --runtime-version hook-smoke-sdk58-v1 \
101
+ --platform android
102
+ ```
103
+
104
+ For the isolated local stand, add `--server-env .env.ota-test` and use the public
105
+ tunnel URL for `--server-url`. Configure the same public base on the server so
106
+ asset downloads also work from the phone. Use a distinct Android package/iOS bundle
107
+ identifier when installing this app alongside an existing test app.
108
+
109
+ Inspect the resulting diff before building:
43
110
 
44
- ## 1. Install Expo Updates
111
+ | File/change | Expected result |
112
+ | --- | --- |
113
+ | `app.json` | Correct HTTPS URL, certificate, runtime, channel; native automatic checks disabled |
114
+ | `package.json` | Client dependencies, `main: "ota-entry.js"`, publisher and selected platform build scripts |
115
+ | `ota-client-entry.json` | Original application entry retained |
116
+ | `ota-client/` | Public API, nested model/UI files and public `config.json` |
117
+ | Root `_layout` / `App` | One unconditional hook and a gate; existing navigation/providers retained |
118
+ | `.env.ota` | Local publisher/build credentials; ignored by Git, never imported by app code |
45
119
 
46
- Install the Expo-compatible version of `expo-updates`:
120
+ Before building, add the
121
+ [manual controls example](./ota-client-lifecycle.md#_3-add-manual-update-controls)
122
+ to a test screen, or explicitly enable download/reload automation through the hook
123
+ options. The default root only checks; a stock Expo template has no OTA test buttons.
124
+ These controls/options must be in the binary you install so it can receive the first OTA.
125
+
126
+ From the **application directory**, run:
47
127
 
48
128
  ```bash
49
- npx expo install expo-updates
129
+ npx expo lint
130
+ npx tsc --noEmit
131
+ npm run ota:build:android:apk
132
+ ```
133
+
134
+ The Android command requires a working local Java/Android toolchain. Before running
135
+ it, configure embedded registration in `.env.ota`: local Docker can use the generated
136
+ `OTA_DATABASE_URL`; HTTP registration requires `OTA_SERVER_URL` and an
137
+ `OTA_ACCESS_TOKEN` with `updates:write`. The generated script treats registration
138
+ failure as a build failure. See [embedded registration](#_6-register-embedded-updates).
139
+ For iOS, configure with `--platform ios`/`all` and build a signed Release/Archive.
140
+
141
+ Install the release APK from `android/app/build/outputs/apk/release/app-release.apk`.
142
+ After its first launch, verify the installation in `/updates/devices`.
143
+
144
+ Make a visible JS change and update `expo.version` for a distinct chart label,
145
+ keeping the compatible runtime unchanged. Publish **after the native build**:
146
+
147
+ ```bash
148
+ npm run ota:publish -- --platform android --message "Fresh app hook smoke test"
149
+ ```
150
+
151
+ The release appears inactive in `/updates`. Select the intended device audience,
152
+ activate it, then check/download/restart. A check or download alone must not move
153
+ the installation to the new running version in analytics; the next launch heartbeat
154
+ should. Confirm the Installation ID stays unchanged across the OTA restart.
155
+
156
+ Finally, rerun the same configurator command. Check that it does not duplicate the
157
+ hook/gate or replace the stored original entry. Change a hook option in the root
158
+ and rerun to verify that the option survives. Use `--force` only when intentionally
159
+ replacing changed generated files; it does not bypass unsupported root shapes.
160
+ For the manual fallback test, use a separate clean copy and follow
161
+ [manual integration](./ota-client-lifecycle.md#manual-integration) without running
162
+ the generator. Keep these as separate checks so generated leftovers cannot hide
163
+ missing manual setup steps.
164
+
165
+ ## 1. Install client dependencies
166
+
167
+ For manual setup, install Expo-compatible versions of all client dependencies:
168
+
169
+ ```bash
170
+ npx expo install expo-updates expo-application expo-crypto expo-secure-store @react-native-async-storage/async-storage
50
171
  ```
51
172
 
52
173
  The application does not send an admin access token when checking for an
@@ -112,8 +233,10 @@ an unknown key.
112
233
 
113
234
  ## 3. Configure the Expo application
114
235
 
115
- Use a dynamic Expo config so the channel cannot accidentally remain
116
- `development` in a production binary.
236
+ The automatic path updates static `app.json`. For manual setup, the dynamic config
237
+ below requires an explicit channel and runtime for each build. The current configurator
238
+ and stock publisher read static `app.json`; they do not evaluate dynamic config.
239
+ Do not use the stock publisher with conflicting static and resolved dynamic values.
117
240
 
118
241
  Example `app.config.ts`:
119
242
 
@@ -187,8 +310,10 @@ Each native binary requests an update using three selection keys:
187
310
  runtimeVersion + channel + platform
188
311
  ```
189
312
 
190
- The server looks up only the latest active update inside that exact scope.
191
- Updates do not cross runtime versions, channels, or platforms.
313
+ Within that scope, the server applies activation/rollback rules and the device
314
+ audience before selecting an eligible update. Ordinary delivery does not cross
315
+ runtime versions, channels or platforms; explicit emergency redirects are a separate
316
+ [recovery mechanism](./ota-emergency-recovery.md).
192
317
 
193
318
  ```mermaid
194
319
  flowchart TD
@@ -327,32 +452,28 @@ expected URL, runtime, channel and certificate.
327
452
 
328
453
  ## 5. Check and install updates in the application
329
454
 
330
- With `checkAutomatically: "NEVER"`, the application controls the user
331
- experience:
332
-
333
- ```ts
334
- import * as Updates from "expo-updates";
455
+ Use the generated `useOtaUpdates` controller with `OtaUpdateGate` in the root
456
+ layout. `configure-app` inserts this integration automatically. If the files or root
457
+ patch are missing, follow [manual integration](./ota-client-lifecycle.md#manual-integration),
458
+ including the complete Router example and manual controls.
335
459
 
336
- export async function checkForOtaUpdate() {
337
- if (__DEV__) {
338
- return { available: false };
339
- }
340
-
341
- const result = await Updates.checkForUpdateAsync();
342
- return { available: result.isAvailable };
343
- }
344
-
345
- export async function installOtaUpdate() {
346
- const result = await Updates.fetchUpdateAsync();
347
-
348
- if (!result.isNew) {
349
- return;
350
- }
460
+ The root defaults to automatic checks and manual download/restart:
351
461
 
352
- await Updates.reloadAsync();
353
- }
462
+ ```tsx
463
+ const ota = useOtaUpdates({
464
+ autoCheck: true,
465
+ autoUpdate: false,
466
+ autoReload: false,
467
+ });
354
468
  ```
355
469
 
470
+ Screens use `useOtaUpdates()` and its `check()`, `download()` and `reload()` methods.
471
+ Identity setup, telemetry and update policies share one controller. Do not replace
472
+ these actions with direct `Updates.checkForUpdateAsync()`/`fetchUpdateAsync()` calls:
473
+ those bypass hook orchestration. Keep native `checkAutomatically: "NEVER"`.
474
+ See [the lifecycle reference](./ota-client-lifecycle.md) for force/store/background
475
+ behavior, errors and custom guard handlers.
476
+
356
477
  Expo Updates automatically sends the runtime headers used by the server,
357
478
  including:
358
479
 
@@ -390,13 +511,18 @@ to the trimmed string `expo.version` from the project's static `app.json`.
390
511
  Missing, blank, malformed or unreadable fallback configuration leaves
391
512
  `app_version` null without blocking an otherwise valid registration.
392
513
 
393
- The MIEX application contains a reference implementation:
514
+ The configurator installs the implementation from `templates/expo-app/`:
394
515
 
395
516
  ```text
396
- scripts/build-update/register-embedded-update.mjs
397
- android/ci_scripts/register_embedded_update_android.sh
517
+ scripts/ota-register-embedded/register-android.sh
518
+ scripts/ota-register-embedded/register-ios.sh
519
+ plugins/with-ota-embedded-registration.js
398
520
  ```
399
521
 
522
+ If configuring entirely by hand, integrate these registrar scripts with your build
523
+ pipeline and configure their server URL/access token; copying the client hook alone
524
+ does not register native builds.
525
+
400
526
  Registration should be a required CI step for production builds. If it fails,
401
527
  the binary should not be distributed.
402
528
 
@@ -419,32 +545,33 @@ A publisher performs these steps:
419
545
  8. Leave the update inactive when manual activation is required.
420
546
  9. Activate or roll back from the admin panel after validation.
421
547
 
422
- The MIEX application already implements this workflow under:
548
+ The configurator installs the portable publisher under `scripts/ota-publish/`
549
+ and adds `ota:publish` to the application's `package.json`. It uses static `app.json`
550
+ for runtime/channel metadata. Configure the application's ignored `.env.ota` using
551
+ `.env.ota.example`; local Docker values can be prepared with `--server-env`.
423
552
 
424
- ```text
425
- scripts/build-update/
553
+ Run from the **application** directory:
554
+
555
+ ```bash
556
+ npm run ota:publish -- --platform android --message "Fix checkout validation"
426
557
  ```
427
558
 
428
- Its relevant environment is:
559
+ Use `--platform ios` or `--platform all` as needed. This command exports and uploads
560
+ the OTA and creates an inactive release in the admin panel; activation is separate.
561
+ Do not use EAS Update to publish to this self-hosted server.
562
+
563
+ Required publisher settings include:
429
564
 
430
565
  ```env
431
566
  EXPO_UPDATE_CHANNEL=production
432
567
  OTA_DATABASE_URL=postgresql://...
433
568
  OTA_DATABASE_SSL=true
434
- OTA_SYNC_UPDATES_DB=true
435
-
436
569
  R2_ENDPOINT=https://...
437
570
  R2_ACCESS_KEY_ID=...
438
571
  R2_SECRET_ACCESS_KEY=...
439
572
  R2_BUCKET=expo-updates
440
573
  ```
441
574
 
442
- Example publish command in that application:
443
-
444
- ```bash
445
- npm run local-update:production -- -m "Fix checkout validation"
446
- ```
447
-
448
575
  The application's configured channel, exported runtime, uploaded storage path
449
576
  and database records must all use the same values. Publishing JavaScript for a
450
577
  different `runtimeVersion` is safe but the binary will not select it.
@@ -4,6 +4,23 @@ This guide takes you from an empty machine to a working OTA server and a
4
4
  connected Expo application. Deep Docker, PostgreSQL or Supabase knowledge is
5
5
  not required.
6
6
 
7
+ ## Before you start
8
+
9
+ Use Node.js 24 and npm on the host (also for Docker-based setup), Docker Compose,
10
+ and OpenSSL. Building the app also needs the platform's native toolchain: Java/Android
11
+ SDK or macOS/Xcode. The server's Docker image does not provide the mobile toolchain.
12
+
13
+ Create the server files, or use an existing source checkout:
14
+
15
+ ```bash
16
+ npx create-expo-updates-server@latest my-server
17
+ cd my-server
18
+ ```
19
+
20
+ NPX only creates files; Docker/Supabase determine where those files run.
21
+ Follow the Docker path below for a first test. Run server commands from this folder
22
+ until the guide explicitly switches to the application folder.
23
+
7
24
  ## What you will have
8
25
 
9
26
  At the end you can:
@@ -58,7 +75,10 @@ POSTGRES_PASSWORD=choose-a-long-random-password
58
75
  MINIO_ROOT_PASSWORD=choose-another-long-random-password
59
76
  ```
60
77
 
61
- Do not publish `.env` to GitHub.
78
+ For this Docker setup, use separate random hexadecimal passwords, for example
79
+ values generated with `openssl rand -hex 32`. Compose embeds the database password
80
+ in a URL and the configurator copies storage values between env files; special
81
+ characters currently need additional handling. Do not publish `.env` to GitHub.
62
82
 
63
83
  If port `3000` is busy:
64
84
 
@@ -105,7 +125,23 @@ docker compose up -d --build
105
125
  docker compose ps
106
126
  ```
107
127
 
108
- Wait until `postgres`, `minio` and `app` are `healthy`.
128
+ Wait until `postgres`, `minio` and `app` are `healthy`. `/api/health` currently
129
+ checks the database only. Verify that the app can also read a valid signing key:
130
+
131
+ ```bash
132
+ docker compose exec app node -e "require('node:crypto').createPrivateKey(require('node:fs').readFileSync('/run/secrets/ota/code-signing-private-key.pem')); console.log('Signing key OK')"
133
+ ```
134
+
135
+ On Linux bind mounts, a host-owned `chmod 600` key can be unreadable to the
136
+ container's UID/GID `1001`. If the check reports `EACCES`, grant that group read
137
+ access and rerun the check:
138
+
139
+ ```bash
140
+ sudo chgrp 1001 secrets/code-signing-private-key.pem
141
+ chmod 640 secrets/code-signing-private-key.pem
142
+ ```
143
+
144
+ The `secrets` directory must also allow traversal by the container user.
109
145
 
110
146
  ## Step 6. Database setup is automatic
111
147
 
@@ -254,6 +290,10 @@ role key is a backend secret. Never place it in the Expo application.
254
290
 
255
291
  ## Step 6. Configure the OTA server
256
292
 
293
+ Create a matching [signing key pair](#step-4-create-the-signing-key-pair) first.
294
+ Set the private-key path below to the actual server-readable file; retain the
295
+ public certificate for application configuration.
296
+
257
297
  Create `.env.local`:
258
298
 
259
299
  ```env
@@ -291,186 +331,105 @@ Choose the `admin` role for the first user.
291
331
 
292
332
  These steps are the same for Docker and Supabase.
293
333
 
294
- ## Automatic CLI configuration
295
-
296
- For an Expo application with a static `app.json`, run this command from the OTA
297
- server repository:
298
-
299
- ```bash
300
- npm run configure-app
301
- ```
334
+ ## 1. Configure the application
302
335
 
303
- The CLI asks for the application path, public certificate, server URL, channel,
304
- runtime, platform and overwrite preference. It displays a summary and requires
305
- confirmation before changing files or running `expo prebuild`.
336
+ Prerequisites: Node.js/npm on the host, a static `app.json` Expo project, the
337
+ public signing certificate, and the HTTPS server URL reachable from the phone.
338
+ Use the same URL for the server's `OTA_PUBLIC_BASE_URL`. The configurator runs
339
+ on the host even when the server runs in Docker.
306
340
 
307
- For CI or advanced usage, pass the same values as flags:
341
+ From the **server directory**:
308
342
 
309
343
  ```bash
310
- npm run configure-app -- \
311
- --app /full/path/to/expo-application \
312
- --certificate /full/path/code-signing-certificate.pem \
313
- --server-url https://updates.example.com \
314
- --channel production \
315
- --runtime-version 1.0.0
344
+ npm ci
345
+ npm run configure-app
316
346
  ```
317
347
 
318
- The CLI:
319
-
320
- 1. validates the Expo project;
321
- 2. installs the Expo-compatible `expo-updates` version;
322
- 3. configures URL, channel, runtime and code signing in `app.json`;
323
- 4. copies the public certificate;
324
- 5. installs a portable publish script;
325
- 6. creates `.env.ota.example`;
326
- 7. adds `npm run ota:publish`;
327
- 8. installs publisher dependencies;
328
- 9. installs Android, Xcode and Xcode Cloud embedded registration hooks;
329
- 10. runs `expo prebuild` to synchronize native projects.
330
-
331
- Use `--platform ios` or `--platform android` to prebuild one platform. The
332
- default is both platforms.
348
+ Select the app directory, certificate, public URL, channel, runtime and platform.
349
+ The CLI installs dependencies, configures native updates, generates the identity
350
+ and telemetry client, inserts the root hook/gate, installs publisher/registration
351
+ scripts and runs prebuild. Review its summary before applying changes.
333
352
 
334
- Existing generated publisher or certificate files are not overwritten. Add
335
- `--force` only when replacement is intentional.
353
+ For flags, supported root components and reruns, see
354
+ [automatic configuration](./expo-app-setup.md#automatic-configuration).
355
+ Dynamic `app.config.*` projects require [manual client integration](./ota-client-lifecycle.md#manual-integration);
356
+ the bundled publisher currently reads static `app.json` only.
336
357
 
337
- The CLI stops when `app.config.ts`, `app.config.js`, `app.config.mjs` or
338
- `app.config.cjs` exists because dynamic Expo config overrides `app.json`.
358
+ ## 2. Check publisher and build credentials
339
359
 
340
- After configuration:
360
+ Switch to the **application directory**. For local Docker exposed through
361
+ localhost or `*.devtunnels.ms`, the configurator can create `.env.ota` from the
362
+ server's `.env`. Keep that generated file. If it does not exist, create it once:
341
363
 
342
364
  ```bash
343
365
  cd /full/path/to/expo-application
344
- cp .env.ota.example .env.ota
366
+ [ -f .env.ota ] || cp .env.ota.example .env.ota
345
367
  ```
346
368
 
347
- Fill in the publisher credentials, then run:
369
+ Fill any missing database and storage credentials from your server setup. Keep
370
+ this file ignored by Git and out of application imports. The publisher needs
371
+ `OTA_DATABASE_URL` and S3 credentials; an admin access token does not replace them.
348
372
 
349
- ```bash
350
- npm run ota:publish -- --message "Describe the change"
351
- ```
373
+ Embedded-build registration can use the same local `OTA_DATABASE_URL`. For
374
+ registration over HTTP, provide `OTA_SERVER_URL` and an `OTA_ACCESS_TOKEN` with
375
+ `updates:write`; create it with `docker compose exec app npm run create-access-token`
376
+ from the **server directory** for Docker, or `npm run create-access-token` for
377
+ a server running directly with npm. See [embedded registration](./expo-app-setup.md#_6-register-embedded-updates).
352
378
 
353
- For local Docker with a `localhost` server URL, the CLI creates the ignored
354
- `.env.ota` automatically from the OTA server `.env`. Manual configuration is
355
- only required for a remote server, Supabase or another storage provider.
356
- Microsoft Dev Tunnel URLs (`*.devtunnels.ms`) are also recognized as local
357
- Docker exposure: the public tunnel is used for `OTA_SERVER_URL`, while the
358
- publisher connects directly to MinIO at `http://127.0.0.1:9000`.
379
+ ## 3. Build and install a native release
359
380
 
360
- The update is uploaded as inactive. Activate it in the admin panel after
361
- review. The following sections describe the equivalent manual setup.
381
+ Before building, choose how the app will download and apply updates.
362
382
 
363
- ## Register the update embedded in a binary
383
+ The generated root checks automatically, but defaults to manual download/restart.
384
+ Add the [manual controls example](./ota-client-lifecycle.md#_3-add-manual-update-controls)
385
+ to a test screen, or explicitly configure automation using the [hook options](./ota-client-lifecycle.md).
386
+ The generator does not add test buttons to your application's UI.
364
387
 
365
- Every release binary contains an embedded update. The server needs its ID for
366
- reliable rollback and emergency redirects. The configurator installs this flow
367
- automatically.
368
-
369
- For local Docker, build Android with:
388
+ From the **application directory**, with the Android toolchain installed:
370
389
 
371
390
  ```bash
372
391
  npm run ota:build:android:apk
373
392
  ```
374
393
 
375
- Use `npm run ota:build:android:aab` for an App Bundle. After Gradle succeeds,
376
- `scripts/ota-register-embedded/register-android.sh` finds `app.manifest` and
377
- registers the embedded update. For iOS, the configurator adds an Xcode Build
378
- Phase that invokes `scripts/ota-register-embedded/register-ios.sh`, so a
379
- Release/Archive build in Xcode performs registration automatically.
380
- The registrar uses an app version from the embedded manifest when available;
381
- otherwise it falls back to the normalized `expo.version` in the project's
382
- static `app.json`. A missing or invalid fallback remains `null` and does not
383
- fail an otherwise valid registration.
394
+ Install `android/app/build/outputs/apk/release/app-release.apk` on the phone.
395
+ For iOS, build a signed Release/Archive in Xcode; the generated build phase
396
+ registers the embedded update. Registration must succeed before continuing.
384
397
 
385
- For remote CI or Xcode Cloud, do not provide PostgreSQL credentials. Create a
386
- dedicated token:
398
+ URL, runtime, channel, certificate and added native modules require a new native
399
+ build. Expo Go and development mode do not test this lifecycle. Launch the release
400
+ and confirm it appears under `/updates/devices`; confirm its embedded update under
401
+ `/updates/embedded`.
387
402
 
388
- ```bash
389
- docker compose exec app npm run create-access-token
390
- ```
403
+ ## 4. Publish the first OTA
391
404
 
392
- Keep the default `updates:write` scope and add the displayed token to CI
393
- secrets:
394
-
395
- ```env
396
- OTA_SERVER_URL=https://updates.example.com
397
- OTA_ACCESS_TOKEN=ota_...
398
- ```
399
-
400
- The configurator also creates `ci_scripts/ci_post_xcodebuild.sh`, a thin Xcode
401
- Cloud lifecycle adapter that invokes the same `register-ios.sh`. The token is
402
- shown only once and must never be committed or included in the mobile binary.
403
- Verify registered binaries at `/updates/embedded`.
404
-
405
- ## Step 1. Install Expo Updates
405
+ Make a visible JavaScript change **after building the binary**. Keep its compatible
406
+ runtime and channel; change `expo.version` if you want a distinct version label.
407
+ From the **application directory**:
406
408
 
407
409
  ```bash
408
- npx expo install expo-updates
410
+ npm run ota:publish -- --platform android --message "First OTA smoke test"
409
411
  ```
410
412
 
411
- ## Step 2. Copy the public certificate
412
-
413
- Copy `code-signing-certificate.pem` into a `certificates` directory in the Expo
414
- application. Never copy the private key into the mobile project.
415
-
416
- ## Step 3. Configure Expo
417
-
418
- Use the `app.config.ts` example in
419
- [`expo-app-setup.md`](https://github.com/tonichiga/expo-updates-server/blob/main/docs/expo-app-setup.md).
420
- Set:
421
-
422
- - `EXPO_OTA_SERVER_URL`;
423
- - `EXPO_UPDATE_CHANNEL`;
424
- - `EXPO_RUNTIME_VERSION`.
425
-
426
- A physical device cannot reach the computer through `localhost`. Production
427
- requires a public HTTPS URL. For local device testing, use the
428
- [HTTPS Dev Tunnel setup](#recommended-use-an-https-tunnel-for-device-testing)
429
- instead of a plain HTTP LAN address.
430
-
431
- ## Step 4. Build a new native binary
432
-
433
- The OTA URL, channel, runtime and certificate are native settings. Build the
434
- iOS or Android application again after changing them.
435
-
436
- ## Step 5. Publish an update
437
-
438
- After automatic configuration, use:
439
-
440
- ```bash
441
- npm run ota:publish -- --message "Describe the change"
442
- ```
443
-
444
- The publisher exports JavaScript, uploads assets and inserts database records.
445
- The new update remains inactive until you approve it.
446
-
447
- ## Step 6. Activate the update
448
-
449
- 1. Open `/updates` in the admin panel.
450
- 2. Find the new update.
451
- 3. Confirm its channel, runtime and platform.
452
- 4. Activate it manually.
413
+ Use `--platform ios` for iOS. The command exports and uploads the update as inactive.
414
+ In `/updates`, verify platform/runtime/channel, select the intended device audience,
415
+ then activate the update.
453
416
 
454
- ## Step 7. Test on a device
417
+ ## 5. Download, restart and verify
455
418
 
456
- Before testing, complete the
457
- [Expo application setup tutorial](https://github.com/tonichiga/expo-updates-server/blob/main/docs/expo-app-setup.md).
458
- In particular, add the
459
- [`checkForUpdateAsync`, `fetchUpdateAsync`, and `reloadAsync` flow](https://github.com/tonichiga/expo-updates-server/blob/main/docs/expo-app-setup.md#5-check-and-install-updates-in-the-application)
460
- to a screen or startup flow in the application.
419
+ Check → download → restart. Confirm the visible change and the new running version
420
+ under `/updates/devices`. Download alone must not change the reported running version.
421
+ The Installation ID should stay unchanged across an OTA restart.
461
422
 
462
- Then:
423
+ For a separate first-install test and idempotent configurator reruns, use
424
+ [fresh app verification](./expo-app-setup.md#verify-generation-in-a-fresh-application).
463
425
 
464
- 1. Create and install a release build containing the OTA URL, runtime,
465
- channel, and public certificate.
466
- 2. Publish an update with a visible test change.
467
- 3. Activate the update in the admin panel.
468
- 4. Open the release build and trigger the update check.
469
- 5. Download the update, reload the application, and confirm the test change.
426
+ ## Diagnose the setup
470
427
 
471
- Expo Go and development mode are not suitable for this test because the
472
- application must use the native update configuration embedded in the release
473
- binary.
428
+ From the **server directory**, run `npm run doctor -- --app /full/path/to/expo-application`.
429
+ This checks the running Docker stack and app source without changing them.
430
+ For npm/remote deployments add `--mode remote --server-env .env.local`.
431
+ Use `--offline` before starting services. See [doctor](./doctor.md) for custom
432
+ Compose projects, JSON output and the checks that still require a real device.
474
433
 
475
434
  ## Troubleshooting
476
435