create-expo-updates-server 0.1.6 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/template/.dockerignore +16 -0
  2. package/dist/template/Dockerfile +5 -0
  3. package/dist/template/README.md +51 -660
  4. package/dist/template/app/api/admin/device-targets/route.test.ts +43 -0
  5. package/dist/template/app/api/admin/device-targets/route.ts +91 -0
  6. package/dist/template/app/api/admin/devices/route.test.ts +41 -0
  7. package/dist/template/app/api/admin/devices/route.ts +15 -0
  8. package/dist/template/app/api/admin/updates/[encodedKey]/audience/route.ts +75 -0
  9. package/dist/template/app/api/device-heartbeat/route.ts +2 -0
  10. package/dist/template/app/globals.css +114 -15
  11. package/dist/template/app/layout.tsx +12 -4
  12. package/dist/template/app/login/page.tsx +22 -18
  13. package/dist/template/app/updates/[encodedKey]/page.tsx +112 -88
  14. package/dist/template/app/updates/devices/page.tsx +264 -0
  15. package/dist/template/app/updates/embedded/page.tsx +102 -68
  16. package/dist/template/app/updates/emergency-redirects/page.tsx +144 -111
  17. package/dist/template/app/updates/layout.tsx +6 -1
  18. package/dist/template/app/updates/page.tsx +262 -212
  19. package/dist/template/components/admin/admin-shell.tsx +196 -0
  20. package/dist/template/components/admin/language-switcher.tsx +25 -0
  21. package/dist/template/components/admin/theme-provider.tsx +15 -0
  22. package/dist/template/components/ui/alert.tsx +65 -0
  23. package/dist/template/components/ui/badge.tsx +47 -0
  24. package/dist/template/components/ui/button.tsx +63 -0
  25. package/dist/template/components/ui/card.tsx +91 -0
  26. package/dist/template/components/ui/chart.tsx +373 -0
  27. package/dist/template/components/ui/checkbox.tsx +31 -0
  28. package/dist/template/components/ui/dialog.tsx +158 -0
  29. package/dist/template/components/ui/dropdown-menu.tsx +256 -0
  30. package/dist/template/components/ui/input.tsx +20 -0
  31. package/dist/template/components/ui/label.tsx +23 -0
  32. package/dist/template/components/ui/native-select.tsx +61 -0
  33. package/dist/template/components/ui/popover.tsx +88 -0
  34. package/dist/template/components/ui/scroll-area.tsx +57 -0
  35. package/dist/template/components/ui/select.tsx +189 -0
  36. package/dist/template/components/ui/separator.tsx +27 -0
  37. package/dist/template/components/ui/sheet.tsx +142 -0
  38. package/dist/template/components/ui/sidebar.tsx +736 -0
  39. package/dist/template/components/ui/skeleton.tsx +13 -0
  40. package/dist/template/components/ui/switch.tsx +34 -0
  41. package/dist/template/components/ui/table.tsx +115 -0
  42. package/dist/template/components/ui/tabs.tsx +90 -0
  43. package/dist/template/components/ui/textarea.tsx +17 -0
  44. package/dist/template/components/ui/tooltip.tsx +56 -0
  45. package/dist/template/components.json +22 -0
  46. package/dist/template/docker/minio.Dockerfile +11 -0
  47. package/dist/template/docker-compose.yml +7 -9
  48. package/dist/template/docs/admin-ui.md +35 -0
  49. package/dist/template/docs/device-targeting.md +129 -0
  50. package/dist/template/docs/doctor.md +137 -0
  51. package/dist/template/docs/expo-app-setup.md +174 -47
  52. package/dist/template/docs/getting-started.md +109 -146
  53. package/dist/template/docs/getting-started.ru.md +110 -193
  54. package/dist/template/docs/index.md +14 -33
  55. package/dist/template/docs/installation-telemetry.md +233 -0
  56. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +89 -0
  57. package/dist/template/docs/migrations/2026-10-19-device-heartbeat.sql +131 -0
  58. package/dist/template/docs/migrations/2026-10-22-device-analytics.sql +264 -0
  59. package/dist/template/docs/migrations/2026-10-22-device-targeting-activation.sql +108 -0
  60. package/dist/template/docs/migrations/2026-10-22-device-targeting.sql +130 -0
  61. package/dist/template/docs/migrations/2026-10-22-device-version-metadata.sql +154 -0
  62. package/dist/template/docs/migrations/schema.sql +868 -6
  63. package/dist/template/docs/npm-installer.md +15 -30
  64. package/dist/template/docs/operations-guide.md +87 -0
  65. package/dist/template/docs/ota-client-lifecycle.md +263 -0
  66. package/dist/template/docs/ota-update-policy.md +36 -2
  67. package/dist/template/docs/supabase-setup.md +4 -0
  68. package/dist/template/hooks/use-mobile.ts +21 -0
  69. package/dist/template/lib/utils.ts +6 -0
  70. package/dist/template/package-lock.json +2325 -101
  71. package/dist/template/package.json +13 -3
  72. package/dist/template/scripts/configure-expo-app.mjs +11 -15
  73. package/dist/template/scripts/doctor.mjs +51 -0
  74. package/dist/template/scripts/ensure-storage-bucket.mjs +25 -0
  75. package/dist/template/scripts/ensure-test-bucket.mjs +21 -0
  76. package/dist/template/scripts/lib/device-identity.test.ts +29 -0
  77. package/dist/template/scripts/lib/doctor-probes.mjs +139 -0
  78. package/dist/template/scripts/lib/doctor.mjs +208 -0
  79. package/dist/template/scripts/lib/doctor.test.mjs +262 -0
  80. package/dist/template/scripts/lib/expo-app-configurator.mjs +14 -9
  81. package/dist/template/scripts/lib/expo-app-configurator.test.ts +3 -2
  82. package/dist/template/scripts/lib/ota-client-configurator.mjs +69 -0
  83. package/dist/template/scripts/lib/ota-client-configurator.test.ts +88 -0
  84. package/dist/template/scripts/lib/ota-client.test.ts +55 -0
  85. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +173 -0
  86. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +123 -0
  87. package/dist/template/scripts/lib/ota-update-controller.test.ts +231 -0
  88. package/dist/template/scripts/tests/device-analytics-migrations.mjs +80 -0
  89. package/dist/template/scripts/tests/device-analytics.mjs +126 -0
  90. package/dist/template/scripts/tests/device-heartbeat.mjs +86 -0
  91. package/dist/template/scripts/tests/device-targeting-activation.mjs +111 -0
  92. package/dist/template/scripts/tests/device-targeting.mjs +39 -0
  93. package/dist/template/scripts/tests/device-version-metadata.mjs +31 -0
  94. package/dist/template/scripts/tests/manifest-identity-concurrency.mjs +106 -0
  95. package/dist/template/scripts/tests/manifest-identity.sql +204 -0
  96. package/dist/template/src/client/admin-types.ts +1 -0
  97. package/dist/template/src/client/devices/analytics.tsx +429 -0
  98. package/dist/template/src/client/devices/device-name.tsx +82 -0
  99. package/dist/template/src/client/devices/registry.tsx +399 -0
  100. package/dist/template/src/client/devices/use-devices-report.ts +108 -0
  101. package/dist/template/src/client/devices/version-adoption-chart.tsx +269 -0
  102. package/dist/template/src/client/devices/version-groups.test.ts +57 -0
  103. package/dist/template/src/client/devices/version-groups.ts +101 -0
  104. package/dist/template/src/client/distribution-control.tsx +135 -81
  105. package/dist/template/src/client/guard-action-combobox.tsx +13 -24
  106. package/dist/template/src/client/i18n/en.json +286 -0
  107. package/dist/template/src/client/i18n/messages.test.ts +42 -0
  108. package/dist/template/src/client/i18n/messages.ts +31 -0
  109. package/dist/template/src/client/i18n/provider.tsx +55 -0
  110. package/dist/template/src/client/i18n/use-formatters.ts +38 -0
  111. package/dist/template/src/client/logout-button.tsx +3 -1
  112. package/dist/template/src/client/update-audience-editor.tsx +285 -0
  113. package/dist/template/src/client/update-policy-editor.tsx +53 -41
  114. package/dist/template/src/server/controllers/manifest.test.ts +250 -7
  115. package/dist/template/src/server/controllers/manifest.ts +39 -31
  116. package/dist/template/src/server/devices/audience.test.ts +48 -0
  117. package/dist/template/src/server/devices/audience.ts +86 -0
  118. package/dist/template/src/server/devices/heartbeat.test.ts +39 -0
  119. package/dist/template/src/server/devices/heartbeat.ts +75 -0
  120. package/dist/template/src/server/devices/report-types.ts +114 -0
  121. package/dist/template/src/server/devices/report.test.ts +29 -0
  122. package/dist/template/src/server/devices/report.ts +27 -0
  123. package/dist/template/src/server/lib/admin-audience-activation.test.ts +94 -0
  124. package/dist/template/src/server/lib/admin-updates.ts +32 -168
  125. package/dist/template/src/server/lib/supabase.js +10 -10
  126. package/dist/template/src/server/lib/supabase.test.ts +11 -0
  127. package/dist/template/src/server/manifest/manifest-identity.test.ts +30 -0
  128. package/dist/template/src/server/manifest/manifest-identity.ts +24 -0
  129. package/dist/template/src/server/manifest/manifest-repository.ts +31 -102
  130. package/dist/template/src/server/manifest/manifest-response.ts +1 -1
  131. package/dist/template/templates/expo-app/ota-client/README.md +59 -0
  132. package/dist/template/templates/expo-app/ota-client/controller.js +60 -0
  133. package/dist/template/templates/expo-app/ota-client/device-identity.js +26 -0
  134. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +52 -0
  135. package/dist/template/templates/expo-app/ota-client/index.d.ts +47 -0
  136. package/dist/template/templates/expo-app/ota-client/index.js +3 -0
  137. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +48 -0
  138. package/dist/template/templates/expo-app/ota-client/model/update-controller.js +182 -0
  139. package/dist/template/templates/expo-app/ota-client/runtime.js +112 -0
  140. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +56 -0
  141. package/dist/template-manifest.json +592 -77
  142. package/lib/cli.mjs +4 -6
  143. package/package.json +1 -1
@@ -24,20 +24,18 @@ For a named target, successful plain-text output looks like this (interactive
24
24
  terminals add color):
25
25
 
26
26
  ```text
27
- ✓ Expo Updates Server is ready
27
+ ✓ Expo Updates Server project files created
28
28
  Project: /path/to/my-server
29
29
 
30
30
  Next steps (Docker):
31
31
  1. cd -- 'my-server'
32
- 2. cp .env.docker.example .env
33
- 3. docker compose up -d --build
34
- 4. docker compose exec app npm run create-admin
32
+ 2. npm ci
33
+ 3. Follow docs/getting-started.md: prepare settings and signing keys before starting Docker.
35
34
 
36
35
  Next steps (npm):
37
36
  1. cd -- 'my-server'
38
37
  2. npm ci
39
- 3. cp .env.example .env.local
40
- 4. npm run dev
38
+ 3. Follow docs/operations-guide.md: configure database, storage and signing keys before startup.
41
39
  ```
42
40
 
43
41
  With `.`, the redundant `cd` step is omitted. Color is disabled when output is
@@ -93,33 +91,20 @@ It deliberately does not install dependencies, initialize a Git repository,
93
91
  write `.env` files, or generate signing keys and other secrets. There is no
94
92
  `--force` option.
95
93
 
96
- ## Start with Docker
97
-
98
- Review the example first, choose strong passwords, and then start the stack:
99
-
100
- ```bash
101
- cp .env.docker.example .env
102
- docker compose up -d --build
103
- docker compose exec app npm run create-admin
104
- ```
94
+ ## Start the generated project
105
95
 
106
- Follow the [quick start](/getting-started) to generate the required signing
107
- key pair and connect an Expo application.
96
+ Follow the bundled [Quick Start](./getting-started.md) in order: environment,
97
+ signing keys, Docker startup, administrator, reachable phone URL, app configuration,
98
+ native build and first OTA. Node/npm and `npm ci` are needed on the host for
99
+ `configure-app`, even if the server runs in Docker.
108
100
 
109
- ## Start with npm
110
-
111
- Install exactly the dependencies in the bundled lockfile:
112
-
113
- ```bash
114
- npm ci
115
- cp .env.example .env.local
116
- npm run dev
117
- ```
101
+ For hosted infrastructure use [Supabase setup](./supabase-setup.md) and the
102
+ [operations guide](./operations-guide.md). Configure the database, storage and
103
+ signing key before starting the server with npm.
118
104
 
119
- Configure PostgreSQL and S3-compatible storage (or Supabase), signing keys,
120
- and all required environment values before using the server in production.
121
- See [Supabase setup](/supabase-setup), [Expo application
122
- setup](/expo-app-setup), and the [operations guide](/operations-guide).
105
+ The package contains the template at its recorded source commit. An unpublished
106
+ feature in a checkout is not available through `npx ...@latest`; maintainers should
107
+ follow the [release workflow](https://github.com/tonichiga/expo-updates-server/blob/main/docs/publishing-npm-installer.md).
123
108
 
124
109
  ## Reproducibility and source
125
110
 
@@ -75,6 +75,11 @@ Passwords must contain at least 12 characters. Only bcrypt hashes are stored.
75
75
 
76
76
  ## 5. Manual startup
77
77
 
78
+ Before starting, create the [signing key pair](./expo-app-setup.md#_2-create-the-code-signing-certificate)
79
+ and set `CODE_SIGNING_PRIVATE_KEY_PATH` to the private key's absolute path.
80
+ The server process must be able to read it; retain the public certificate for the app.
81
+ The health endpoint below verifies the database, not signing or storage readiness.
82
+
78
83
  ```bash
79
84
  npm ci
80
85
  npm run build
@@ -314,8 +319,90 @@ docker compose exec -T postgres \
314
319
 
315
320
  Never deploy code that reads a new table before creating that table.
316
321
 
322
+ ### Manifest identity migration (2026-10-16)
323
+
324
+ Apply `docs/migrations/2026-10-16-manifest-identity.sql` before deploying the
325
+ matching server code. Fresh installations receive these changes from
326
+ `schema.sql`. Existing installations must already have the distribution
327
+ control migration described above.
328
+
329
+ For this upgrade, stop OTA distribution, apply the migration, replace all
330
+ server instances, and then resume distribution. Do not serve traffic from a
331
+ mixture of old and new instances: older code can return a manifest even when
332
+ its asynchronous mapping write fails. Reverting to that code reintroduces
333
+ the identity bug; keeping the new SQL triggers alone is insufficient.
334
+
335
+ Each manifest UUID is now derived from the channel publication epoch and the
336
+ actual selected update UUID. An inactive upload can therefore use the stable
337
+ fallback without sharing its manifest ID with the eventual activated update.
338
+ Activation advances the channel epoch even if its latest pointer is unchanged.
339
+ Pointer changes and repeated rollback operations advance the epoch clock by
340
+ at least one millisecond, so successive publications remain ordered for Expo.
341
+
342
+ The server records the manifest-to-update mapping before returning a manifest.
343
+ Missing mapping tables, lookup errors, or failed mapping writes now fail the
344
+ request instead of silently changing IDs or losing history. Identical mapping
345
+ retries are allowed; assigning an existing manifest ID to a different update
346
+ or scope is rejected by PostgreSQL. No-update responses need no new mapping.
347
+
348
+ Existing mapping rows are preserved and remain readable by the new server.
349
+ Previously overwritten historical mappings cannot be automatically repaired.
350
+ This change protects ID-to-update correspondence; it does not freeze all
351
+ published JSON/assets or change the existing deletion/retention policy.
352
+ Current admin channel IDs represent publication epochs, not the derived UUIDs
353
+ returned to devices.
354
+
355
+ The SQL regression script can be run against a **disposable** database after
356
+ applying the schema and migration:
357
+
358
+ ```bash
359
+ psql "$OTA_TEST_DATABASE_URL" -v ON_ERROR_STOP=1 \
360
+ -f scripts/tests/manifest-identity.sql
361
+ ```
362
+
363
+ It verifies draft activation, repeated activation/rollback, monotonic clocks,
364
+ the global distribution guard, and immutable mapping upserts. It temporarily
365
+ changes the global switch and rolls back its fixtures; do not run it against
366
+ a live OTA database.
367
+
317
368
  ## 12. Expo application integration
318
369
 
319
370
  Client configuration, code-signing certificates, embedded update registration,
320
371
  manual update checks and the current publish workflow are described in
321
372
  [`expo-app-setup.md`](expo-app-setup.md).
373
+
374
+ ## Installation telemetry
375
+
376
+ After the manifest identity and distribution-control migrations above, apply the
377
+ following files in order before deploying the updated server:
378
+
379
+ ```sh
380
+ psql "$DATABASE_URL" -v ON_ERROR_STOP=1 \
381
+ -f docs/migrations/2026-10-19-device-heartbeat.sql \
382
+ -f docs/migrations/2026-10-22-device-analytics.sql \
383
+ -f docs/migrations/2026-10-22-device-version-metadata.sql \
384
+ -f docs/migrations/2026-10-22-device-targeting.sql \
385
+ -f docs/migrations/2026-10-22-device-targeting-activation.sql
386
+ ```
387
+
388
+ Fresh installations use only `schema.sql`, which includes these changes. Reapplying
389
+ these migrations preserves collection start, installation records and release audiences.
390
+ The final migration moves public-versus-targeted activation into an atomic database
391
+ operation, allows deactivation cleanup during the global stop, and adds the separate
392
+ `ota-force-update` catalog entry. Apply it before deploying the matching server.
393
+
394
+ Rerun the stock app configurator to install the generated identity/telemetry client and
395
+ root `useOtaUpdates`/`OtaUpdateGate` integration. Adding SecureStore or the other native
396
+ client dependencies requires a native rebuild with a compatible runtime; do not publish
397
+ JavaScript that imports unavailable native modules to an older runtime. Existing clients
398
+ already sending heartbeats can populate analytics without a native rebuild, but the new
399
+ Device ID and hook lifecycle need the updated client. See
400
+ [client lifecycle](./ota-client-lifecycle.md) and [device targeting](./device-targeting.md).
401
+
402
+ The **Установки** page (`/updates/devices`) shows current launch adoption, daily
403
+ activity, and cohorts. Daily history begins at migration time; pre-upgrade
404
+ history is unavailable. Retention has an independent 90-day window and uses
405
+ fully observed later days. Existing installations remain visible in current
406
+ composition cohorts. See [installation telemetry](./installation-telemetry.md)
407
+ for exact filter/window semantics, migration checks, the event contract, client
408
+ entry behavior, access rules and limitations.
@@ -0,0 +1,263 @@
1
+ # Generated OTA client lifecycle
2
+
3
+ `configure-app` inserts `useOtaUpdates({ autoCheck: true, autoUpdate: false,
4
+ autoReload: false })` in the root layout/App and wraps its content in `OtaUpdateGate`.
5
+ All screens can call `useOtaUpdates()` to observe the same state and use `check()`,
6
+ `download()` and `reload()`. No provider is needed. Configure automation in one root;
7
+ additional consumers default to observation/manual actions. Multiple configured roots
8
+ combine boolean options with OR. Guard handlers should be stable references.
9
+
10
+ Identity is persisted and installed in Expo request parameters before any check/download.
11
+ Launch/foreground heartbeats report only the **running** bundle, never a downloaded
12
+ candidate. Network telemetry does not block app launch or update checks. Development,
13
+ Expo Go, web and disabled-updates builds leave automation off.
14
+
15
+ | Policy/options | Behavior |
16
+ | --- | --- |
17
+ | manual, default options | Check exposes candidate; caller downloads and reloads |
18
+ | autoCheck | Check on mount and foreground, minimum interval 60 seconds |
19
+ | autoUpdate | Also download eligible manual candidates |
20
+ | autoReload | Reload a pending non-background bundle while app is active |
21
+ | delivery=background | Download silently; apply on next cold launch or manual reload |
22
+ | guard=ota-force-update | Block with gate, download automatically; restart button when ready |
23
+ | guard=ota-force-store-update | Block with gate; open store, never download this candidate |
24
+ | custom/unknown guard | Block until guardHandlers[action] explicitly returns `allow` |
25
+
26
+ Store guard payload: `{ "androidUrl": "market://details?id=com.example.app",
27
+ "iosUrl": "https://apps.apple.com/app/id123" }`; `url` is a common fallback. Only
28
+ https, market and itms-apps URLs are accepted. Native upgrades still require a store
29
+ release; OTA cannot add native modules or change the installed runtime.
30
+
31
+ The built-in gate is a non-dismissable modal that preserves mounted navigation and providers.
32
+ It is customizable with `renderBlocked`. Keep the gate mounted around
33
+ the application; a hook alone exposes `blocked` but cannot prevent interaction with
34
+ your own screens. Unknown guards fail closed. Required checks are online policy,
35
+ not authentication or a tamper-proof access restriction. Offline check failure keeps
36
+ the running app usable unless a required candidate was already discovered or the running bundle requires a store/custom guard.
37
+
38
+ Calls are single-flight per action; a different action while busy rejects. Errors are
39
+ available in `error` and returned promises reject, so handle manual calls with try/catch.
40
+ Retry rechecks the server and reevaluates a pending candidate's custom guard.
41
+ Download reevaluates the fetched manifest's policy because it can differ from the
42
+ checked candidate. A pending bundle owns the gate until reload; checking another
43
+ candidate does not authorize an older cached bundle. Native rollback directives are
44
+ supported. Expo controls cold-start loading of already downloaded bundles; JS guards
45
+ cannot revoke that native cache. Store/custom guards are checked again from the running
46
+ manifest on the next launch; force OTA is already fulfilled by launching that bundle.
47
+ Do not mix direct expo-updates calls or native automatic
48
+ checks with hook orchestration: configure-app uses checkAutomatically=NEVER.
49
+
50
+ Legacy exports `checkForUpdateAsync`/`fetchUpdateAsync` remain identity-aware low-level
51
+ APIs for existing integrations. They intentionally do not implement hook policies.
52
+ No database/admin credentials are shipped: the server persists public heartbeat reports.
53
+
54
+ ## Integration and customization
55
+
56
+ Use the stock `npm run configure-app -- ...` command from the server project. It
57
+ preserves the original app entry, generates the client and inserts the hook/gate in
58
+ supported root components. For Expo Router this is `src/app/_layout` (preferred when
59
+ `src/app` exists) or `app/_layout`, including platform variants. For the default entry
60
+ it is `App`, provided no custom `index` registers a different root. Synchronous function
61
+ components and supported default-export forms are patched without changing navigation.
62
+ An unsupported root shape is rejected before writing; an unidentified custom root keeps
63
+ automatic identity/telemetry setup and emits a warning to connect the lifecycle manually.
64
+ The generated integration starts with:
65
+
66
+ ```tsx
67
+ const ota = useOtaUpdates({
68
+ autoCheck: true,
69
+ autoUpdate: false,
70
+ autoReload: false,
71
+ });
72
+
73
+ return <OtaUpdateGate controller={ota}>{/* app content */}</OtaUpdateGate>;
74
+ ```
75
+
76
+ Adjust these options in the root component. Use `useOtaUpdates()` in other screens for
77
+ manual controls and shared state. The configurator selects the appropriate import path;
78
+ no database or admin credentials belong in the application. Generated source includes
79
+ `ota-client/docs/update-lifecycle.md` with this contract for application developers.
80
+
81
+ For an already configured project, review generated-file changes and rerun the existing
82
+ `--force` flow when replacing generated files. Native dependencies need a new binary;
83
+ use a new runtime when older installed binaries lack those modules. Publishing remains
84
+ the generated `npm run ota:publish` workflow. See [device targeting](./device-targeting.md)
85
+ for selecting a smoke-test audience and [installation telemetry](./installation-telemetry.md)
86
+ for receipt/analytics semantics.
87
+
88
+ ## Manual integration
89
+
90
+ Use this path when `configure-app` cannot patch your root component, your project
91
+ uses dynamic `app.config.*`, or you want to integrate the client yourself. The hook
92
+ is source code supplied by this repository, **not an npm package**. Do not import
93
+ it from `expo-updates`.
94
+
95
+ ### 1. Prepare the client and native configuration
96
+
97
+ If `ota-client/index.js`, `ota-client/index.d.ts` and `ota-client/config.json` already
98
+ exist after configuration, keep them and continue with step 2. A warning about an
99
+ unidentified custom root means the bootstrap/client were installed; an unsupported
100
+ root error stops configuration before writes, so check which files actually exist.
101
+
102
+ For an application with no generated client, run from the application directory:
103
+
104
+ ```bash
105
+ npx expo install expo-updates expo-application expo-crypto expo-secure-store @react-native-async-storage/async-storage
106
+ ```
107
+
108
+ Copy the **whole** `templates/expo-app/ota-client/` directory from the OTA server
109
+ repository to `<application>/ota-client/`. Keep its nested `model/`, `ui/`, runtime,
110
+ identity, telemetry and type declaration files together. For example, when the
111
+ application does not already contain that directory:
112
+
113
+ ```bash
114
+ cp -R /full/path/to/expo-updates-server/templates/expo-app/ota-client ./ota-client
115
+ ```
116
+
117
+ Create `<application>/ota-client/config.json`:
118
+
119
+ ```json
120
+ {
121
+ "channel": "preview",
122
+ "heartbeatUrl": "https://updates.example.com/api/device-heartbeat",
123
+ "identityNamespace": "https://updates.example.com"
124
+ }
125
+ ```
126
+
127
+ Use your actual server URL. `channel` must equal the native `expo-channel-name`
128
+ request header. `identityNamespace` is a stable identity scope: preserve an existing
129
+ value when changing a tunnel/domain, runtime or channel. It contains no secret.
130
+ Do not copy an Installation ID, Device ID, database password or admin token into
131
+ this file: the client generates identities and sends public heartbeat requests.
132
+
133
+ Complete the [native Expo configuration](./expo-app-setup.md#_3-configure-the-expo-application):
134
+ server manifest URL, matching public signing certificate, runtime and channel.
135
+ Set `updates.checkAutomatically` to `NEVER`; checks must wait for identity setup.
136
+ Keep the signing private key and publisher credentials outside the mobile bundle.
137
+ A dynamic config must resolve the same channel used in `ota-client/config.json`.
138
+
139
+ ### 2. Connect the root layout or App
140
+
141
+ For Expo Router, add the hook to the existing `src/app/_layout.tsx`. This minimal
142
+ example shows the integration; preserve your current navigation, providers, fonts,
143
+ splash-screen handling and other layout code inside the gate:
144
+
145
+ ```tsx
146
+ import { Stack } from 'expo-router';
147
+ import { OtaUpdateGate, useOtaUpdates } from '../../ota-client';
148
+
149
+ export default function RootLayout() {
150
+ const ota = useOtaUpdates({
151
+ autoCheck: true,
152
+ autoUpdate: false,
153
+ autoReload: false,
154
+ });
155
+
156
+ return (
157
+ <OtaUpdateGate controller={ota}>
158
+ <Stack />
159
+ </OtaUpdateGate>
160
+ );
161
+ }
162
+ ```
163
+
164
+ Adjust the relative import to the file location:
165
+
166
+ | Root file | Import from |
167
+ | --- | --- |
168
+ | `src/app/_layout.tsx` | `../../ota-client` |
169
+ | `app/_layout.tsx` | `../ota-client` |
170
+ | `App.tsx` at the application root | `./ota-client` |
171
+
172
+ For a non-Router application, call the hook in your existing function `App` and
173
+ wrap its existing returned content with the same gate. A class component can stay
174
+ inside a function wrapper that owns the hook. Call the hook unconditionally, before
175
+ early returns, keep the gate on loading/early-return paths as well, and configure
176
+ automation in one persistent root. A custom entry
177
+ must still register that root using its existing registration mechanism.
178
+
179
+ Keep an existing generated `ota-entry.js` and its `package.json.main` setting.
180
+ When integrating entirely by hand, changing the entry is **not required**: the
181
+ mounted hook calls the idempotent telemetry `start()` itself. Identity is persisted
182
+ before hook update requests; heartbeat network failures do not block rendering or
183
+ checks. Do not add another heartbeat implementation or call Expo checks at module
184
+ initialization. For an app that needs registration before its root mounts, the
185
+ public `start()` can also be called in its existing entry without replacing the
186
+ original registration code.
187
+
188
+ The gate is required for the default force-update UI. Using the hook without it
189
+ requires your own UI to enforce `blocked`. A custom gate view is supported through
190
+ `renderBlocked`; this does not change the controller's guard decision.
191
+
192
+ ### 3. Add manual update controls
193
+
194
+ The root above checks automatically but leaves ordinary manual-policy updates for
195
+ the user to download and apply. A separate screen can subscribe without enabling
196
+ another automatic workflow. For example, `src/components/ota-controls.tsx`:
197
+
198
+ ```tsx
199
+ import { useState } from 'react';
200
+ import { Button, Text, View } from 'react-native';
201
+ import { useOtaUpdates } from '../../ota-client';
202
+
203
+ export function OtaControls() {
204
+ const ota = useOtaUpdates();
205
+ const [message, setMessage] = useState('');
206
+
207
+ async function perform(action: () => Promise<unknown>) {
208
+ try {
209
+ setMessage('');
210
+ await action();
211
+ } catch (error) {
212
+ setMessage(error instanceof Error ? error.message : String(error));
213
+ }
214
+ }
215
+
216
+ return (
217
+ <View>
218
+ <Text>Installation: {ota.installationId ?? 'Initializing'}</Text>
219
+ <Text>Device: {ota.deviceId ?? 'Unavailable'}</Text>
220
+ <Text>State: {ota.status}</Text>
221
+ <Text accessibilityLiveRegion="polite">{message || ota.error?.message}</Text>
222
+ <Button title="Check OTA" disabled={!ota.enabled || ota.isBusy}
223
+ onPress={() => { void perform(ota.check); }} />
224
+ <Button title="Download OTA"
225
+ disabled={!ota.enabled || ota.isBusy || !ota.available || ota.pending || ota.blocked}
226
+ onPress={() => { void perform(ota.download); }} />
227
+ <Button title="Restart with OTA"
228
+ disabled={!ota.enabled || ota.isBusy || !ota.pending || ota.blocked}
229
+ onPress={() => { void perform(ota.reload); }} />
230
+ </View>
231
+ );
232
+ }
233
+ ```
234
+
235
+ The gate supplies required-update actions while these ordinary screen controls are
236
+ blocked. To download ordinary updates automatically, set `autoUpdate: true` in the
237
+ root; add `autoReload: true` only when automatic foreground restarts suit your app.
238
+ Server `background` delivery still prevents an automatic immediate restart. Custom
239
+ guards need an explicit `guardHandlers[action]` decision; returning `allow` should
240
+ follow your actual application condition, not simply silence an unknown action.
241
+
242
+ ### 4. Rebuild and verify
243
+
244
+ After adding native dependencies or changing URL/runtime/channel/certificate,
245
+ prebuild and install a new release binary. Use the environment required by a dynamic
246
+ config when running Expo commands. Expo Go and ordinary development mode do not
247
+ exercise this client's telemetry/update lifecycle.
248
+
249
+ 1. Check TypeScript and lint, then build/install the release binary.
250
+ 2. Launch it and verify an installation appears under `/updates/devices`.
251
+ 3. Publish a fresh OTA **after** building the binary, for its exact scope, then activate it.
252
+ 4. Check → download → restart; verify the new running version in the admin panel.
253
+ 5. Confirm Installation ID is unchanged after OTA. A reinstall may change it;
254
+ Device ID persistence has the [platform limitations](./device-targeting.md).
255
+ 6. Check background delivery, force OTA, store upgrade and your custom guards separately.
256
+
257
+ Copying `ota-client/` and adding the hook does not install publisher scripts or
258
+ embedded-build registration. Those are separate setup steps in the
259
+ [application guide](./expo-app-setup.md#_6-register-embedded-updates). If the automatic
260
+ configurator already installed them, keep using its `npm run ota:publish` command.
261
+ The bundled publisher reads static `app.json` only: manual hook integration does
262
+ not make a dynamic `app.config.*` project a supported end-to-end publishing setup.
263
+ Such projects need separate publisher/build integration before step 3 above.
@@ -16,7 +16,8 @@ Every served update manifest includes `extra.updatePolicy`:
16
16
 
17
17
  The `guard` property is omitted when no Guard is configured. A configured
18
18
  Guard is unconditional: it is included for every client to which the existing
19
- runtime, channel, platform, and update selection logic serves that OTA.
19
+ runtime, channel, platform, audience and update selection logic serves that OTA.
20
+ A force guard never bypasses a device audience.
20
21
  Catalog membership is advisory and is not required to save or serve an action.
21
22
 
22
23
  - `Updates.checkForUpdateAsync()` returns the policy on the **candidate**
@@ -74,7 +75,8 @@ installations should apply only the canonical
74
75
  ## Guard action catalog
75
76
 
76
77
  The policy editor loads reusable action names from `ota_guard_actions`. New
77
- installations receive the `ota-force-store-update` action. Operators can create
78
+ installations receive the separate `ota-force-update` and `ota-force-store-update`
79
+ actions. Operators can create
78
80
  an action by typing it in the action combobox or through the catalog-only form,
79
81
  which remains available while viewing an immutable policy and never changes
80
82
  that policy.
@@ -87,3 +89,35 @@ delete control.
87
89
  Catalog action keys are trimmed when created, contain 1–100 characters, and
88
90
  cannot contain control characters. Viewers can list catalog entries but cannot
89
91
  create or delete them.
92
+
93
+ ## Generated client hook
94
+
95
+ The configurator installs `useOtaUpdates(options)` and automatically connects it in the
96
+ root layout/App, with `OtaUpdateGate` around application content. See the
97
+ [client lifecycle guide](./ota-client-lifecycle.md) for configuration and methods.
98
+ The hook evaluates the candidate policy from `check()`, then validates the fetched
99
+ manifest again because the selected release may change between checking and downloading.
100
+
101
+ - `ota-force-update` requires a compatible **OTA**: the gate blocks interaction, the
102
+ hook downloads the update and shows a restart action when ready.
103
+ - `ota-force-store-update` requires a **new native binary**: the gate opens the platform
104
+ store URL; it does not download this OTA candidate. OTA cannot change runtime or add
105
+ native modules. Payload supports `androidUrl`, `iosUrl`, or a shared `url` fallback.
106
+ - Unknown/custom actions remain blocked until an explicit `guardHandlers[action]`
107
+ returns `allow`. Catalog entries alone do not implement guard behavior.
108
+ - `delivery: background` downloads silently and waits for a cold launch or a manual
109
+ reload. It does not immediately reload because `autoReload` is enabled.
110
+ - A manual candidate is displayed for explicit download/reload unless root options
111
+ enable `autoUpdate`/`autoReload`. The generated root enables automatic checks only.
112
+
113
+ The gate is required to block the application's UI; a hook alone only exposes state.
114
+ Before a required candidate has been discovered, offline check failure leaves the
115
+ running app usable. Expo may apply a previously downloaded bundle at native startup;
116
+ JavaScript cannot revoke that native cache. These are delivery policies, not client
117
+ authentication. Legacy clients may ignore policy fields, so deploy the configured native
118
+ client before relying on a guard.
119
+
120
+ Existing installations receive the new OTA guard catalog entry through
121
+ `2026-10-22-device-targeting-activation.sql`, after the targeting migrations listed in
122
+ the [operations guide](./operations-guide.md#installation-telemetry). The migration is
123
+ idempotent and does not rewrite published policies.
@@ -51,6 +51,10 @@ portable application schema.
51
51
 
52
52
  ## 3. Configure the server
53
53
 
54
+ Generate a [signing key pair](./expo-app-setup.md#_2-create-the-code-signing-certificate)
55
+ before starting the server. Use its actual server-readable private-key path below
56
+ and retain the matching public certificate for the application.
57
+
54
58
  The recommended Supabase adapter configuration is:
55
59
 
56
60
  ```env
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+
3
+ const MOBILE_BREAKPOINT = 768;
4
+
5
+ export function useIsMobile() {
6
+ const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
7
+ undefined,
8
+ );
9
+
10
+ React.useEffect(() => {
11
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
12
+ const onChange = () => {
13
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
14
+ };
15
+ mql.addEventListener("change", onChange);
16
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
17
+ return () => mql.removeEventListener("change", onChange);
18
+ }, []);
19
+
20
+ return !!isMobile;
21
+ }
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }