create-expo-updates-server 0.1.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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/bin/create-expo-updates-server.mjs +5 -0
  4. package/dist/template/.env.docker.example +15 -0
  5. package/dist/template/.env.example +35 -0
  6. package/dist/template/Dockerfile +42 -0
  7. package/dist/template/LICENSE +21 -0
  8. package/dist/template/README.md +665 -0
  9. package/dist/template/app/api/admin/access-tokens/[id]/route.ts +25 -0
  10. package/dist/template/app/api/admin/access-tokens/route.test.ts +73 -0
  11. package/dist/template/app/api/admin/access-tokens/route.ts +90 -0
  12. package/dist/template/app/api/admin/embedded-updates/[embeddedUpdateId]/route.ts +25 -0
  13. package/dist/template/app/api/admin/embedded-updates/route.test.ts +102 -0
  14. package/dist/template/app/api/admin/embedded-updates/route.ts +47 -0
  15. package/dist/template/app/api/admin/emergency-redirects/[id]/route.ts +62 -0
  16. package/dist/template/app/api/admin/emergency-redirects/route.test.ts +84 -0
  17. package/dist/template/app/api/admin/emergency-redirects/route.ts +56 -0
  18. package/dist/template/app/api/admin/login/route.test.ts +55 -0
  19. package/dist/template/app/api/admin/login/route.ts +52 -0
  20. package/dist/template/app/api/admin/logout/route.ts +20 -0
  21. package/dist/template/app/api/admin/session/route.ts +15 -0
  22. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +33 -0
  23. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +29 -0
  24. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +29 -0
  25. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +96 -0
  26. package/dist/template/app/api/admin/updates/route.test.ts +142 -0
  27. package/dist/template/app/api/admin/updates/route.ts +32 -0
  28. package/dist/template/app/api/assets/route.ts +6 -0
  29. package/dist/template/app/api/health/route.test.ts +26 -0
  30. package/dist/template/app/api/health/route.ts +42 -0
  31. package/dist/template/app/api/manifest/route.ts +6 -0
  32. package/dist/template/app/api/update-complete/route.ts +6 -0
  33. package/dist/template/app/favicon.ico +0 -0
  34. package/dist/template/app/globals.css +26 -0
  35. package/dist/template/app/layout.tsx +34 -0
  36. package/dist/template/app/login/page.tsx +77 -0
  37. package/dist/template/app/page.tsx +12 -0
  38. package/dist/template/app/updates/[encodedKey]/page.tsx +482 -0
  39. package/dist/template/app/updates/embedded/page.tsx +164 -0
  40. package/dist/template/app/updates/emergency-redirects/page.tsx +430 -0
  41. package/dist/template/app/updates/layout.tsx +14 -0
  42. package/dist/template/app/updates/page.tsx +281 -0
  43. package/dist/template/docker-compose.yml +100 -0
  44. package/dist/template/docs/expo-app-setup.md +497 -0
  45. package/dist/template/docs/getting-started.md +502 -0
  46. package/dist/template/docs/getting-started.ru.md +623 -0
  47. package/dist/template/docs/index.md +57 -0
  48. package/dist/template/docs/migrations/schema.sql +363 -0
  49. package/dist/template/docs/npm-installer.md +83 -0
  50. package/dist/template/docs/operations-guide.md +270 -0
  51. package/dist/template/docs/ota-emergency-recovery.md +109 -0
  52. package/dist/template/docs/supabase-setup.md +133 -0
  53. package/dist/template/eslint.config.mjs +30 -0
  54. package/dist/template/gitignore.template +58 -0
  55. package/dist/template/next.config.ts +7 -0
  56. package/dist/template/package-lock.json +12156 -0
  57. package/dist/template/package.json +50 -0
  58. package/dist/template/postcss.config.mjs +7 -0
  59. package/dist/template/public/file.svg +1 -0
  60. package/dist/template/public/globe.svg +1 -0
  61. package/dist/template/public/next.svg +1 -0
  62. package/dist/template/public/vercel.svg +1 -0
  63. package/dist/template/public/window.svg +1 -0
  64. package/dist/template/scripts/configure-expo-app.mjs +145 -0
  65. package/dist/template/scripts/create-access-token.mjs +135 -0
  66. package/dist/template/scripts/create-admin.mjs +169 -0
  67. package/dist/template/scripts/import-emergency-redirects.mjs +126 -0
  68. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +64 -0
  69. package/dist/template/scripts/lib/expo-app-configurator.mjs +666 -0
  70. package/dist/template/scripts/lib/expo-app-configurator.test.ts +463 -0
  71. package/dist/template/scripts/lib/expo-app-prompts.mjs +139 -0
  72. package/dist/template/scripts/lib/expo-app-prompts.test.ts +97 -0
  73. package/dist/template/scripts/lib/expo-export-command.test.ts +31 -0
  74. package/dist/template/scripts/lib/ota-publish-retry.test.ts +33 -0
  75. package/dist/template/scripts/manage-emergency-redirect.mjs +483 -0
  76. package/dist/template/scripts/sync-docker-database-password.sh +16 -0
  77. package/dist/template/src/client/admin-api.ts +174 -0
  78. package/dist/template/src/client/admin-types.ts +93 -0
  79. package/dist/template/src/client/logout-button.tsx +31 -0
  80. package/dist/template/src/server/controllers/assets.ts +216 -0
  81. package/dist/template/src/server/controllers/manifest.test.ts +403 -0
  82. package/dist/template/src/server/controllers/manifest.ts +626 -0
  83. package/dist/template/src/server/controllers/update-complete.ts +36 -0
  84. package/dist/template/src/server/lib/admin-access-tokens.ts +169 -0
  85. package/dist/template/src/server/lib/admin-api.ts +101 -0
  86. package/dist/template/src/server/lib/admin-auth.ts +208 -0
  87. package/dist/template/src/server/lib/admin-embedded-updates.ts +150 -0
  88. package/dist/template/src/server/lib/admin-updates.ts +1282 -0
  89. package/dist/template/src/server/lib/common.js +24 -0
  90. package/dist/template/src/server/lib/emergency-channel-redirects.ts +310 -0
  91. package/dist/template/src/server/lib/env.js +8 -0
  92. package/dist/template/src/server/lib/manifest-helpers.js +91 -0
  93. package/dist/template/src/server/lib/response.js +11 -0
  94. package/dist/template/src/server/lib/signing.js +55 -0
  95. package/dist/template/src/server/lib/supabase.js +763 -0
  96. package/dist/template/src/server/manifest/manifest-repository.ts +269 -0
  97. package/dist/template/src/server/manifest/manifest-request.ts +21 -0
  98. package/dist/template/src/server/manifest/manifest-response.ts +235 -0
  99. package/dist/template/src/server/manifest/manifest-values.ts +62 -0
  100. package/dist/template/templates/expo-app/.env.ota.example +18 -0
  101. package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +6 -0
  102. package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +36 -0
  103. package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +33 -0
  104. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +87 -0
  105. package/dist/template/templates/expo-app/scripts/ota-publish/api/storage-client.mjs +57 -0
  106. package/dist/template/templates/expo-app/scripts/ota-publish/index.mjs +182 -0
  107. package/dist/template/templates/expo-app/scripts/ota-publish/lib/common.mjs +84 -0
  108. package/dist/template/templates/expo-app/scripts/ota-publish/lib/expo-export-command.mjs +24 -0
  109. package/dist/template/templates/expo-app/scripts/ota-publish/lib/retry.mjs +25 -0
  110. package/dist/template/templates/expo-app/scripts/ota-publish/shared/config.mjs +48 -0
  111. package/dist/template/templates/expo-app/scripts/ota-register-embedded/android-register-embedded-update.sh +18 -0
  112. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +275 -0
  113. package/dist/template/tsconfig.json +36 -0
  114. package/dist/template/vitest.config.mts +20 -0
  115. package/dist/template-manifest.json +564 -0
  116. package/lib/cli.mjs +549 -0
  117. package/package.json +41 -0
@@ -0,0 +1,665 @@
1
+ # Expo Updates Server
2
+
3
+ The easiest way to create a standalone server project is the npm initializer:
4
+
5
+ ```bash
6
+ npx create-expo-updates-server@latest my-server
7
+ cd my-server
8
+ ```
9
+
10
+ The downloaded initializer uses its bundled, checksum-verified template. It
11
+ does not fetch source code, install project dependencies, initialize Git, or
12
+ create secrets while scaffolding. The target path must not already exist.
13
+ Continue with either Docker:
14
+
15
+ ```bash
16
+ cp .env.docker.example .env
17
+ docker compose up -d --build
18
+ ```
19
+
20
+ or a local npm setup:
21
+
22
+ ```bash
23
+ npm ci
24
+ cp .env.example .env.local
25
+ npm run dev
26
+ ```
27
+
28
+ See the [npm initializer guide](docs/npm-installer.md) for safety behavior and
29
+ complete next steps. Cloning the
30
+ [GitHub repository](https://github.com/tonichiga/expo-updates-server) remains
31
+ supported for contributors and manual installations.
32
+
33
+ # Beginner Quick Start
34
+
35
+ This guide takes you from an empty machine to a working OTA server and a
36
+ connected Expo application. Deep Docker, PostgreSQL or Supabase knowledge is
37
+ not required.
38
+
39
+ ## What you will have
40
+
41
+ At the end you can:
42
+
43
+ 1. open the OTA admin panel;
44
+ 2. sign in as an administrator;
45
+ 3. connect an Expo application;
46
+ 4. publish updates;
47
+ 5. activate an update manually;
48
+ 6. roll back or configure an emergency redirect.
49
+
50
+ ## Choose one installation path
51
+
52
+ - **NPX** creates a clean standalone copy without cloning the repository.
53
+ - **Docker** runs the server, PostgreSQL and MinIO together.
54
+ - **Supabase** hosts the database and storage; the OTA server is deployed
55
+ separately.
56
+
57
+ Use Docker for the quickest local test.
58
+
59
+ ---
60
+
61
+ # Option A: Docker
62
+
63
+ ## Step 1. Install and start Docker Desktop
64
+
65
+ Download Docker Desktop from:
66
+
67
+ ```text
68
+ https://www.docker.com/products/docker-desktop/
69
+ ```
70
+
71
+ Open it and wait until Docker Engine is running.
72
+
73
+ ## Step 2. Open the project folder
74
+
75
+ In Terminal:
76
+
77
+ ```bash
78
+ cd /path/to/expo-updates-server
79
+ ```
80
+
81
+ ## Step 3. Create the settings file
82
+
83
+ ```bash
84
+ cp .env.docker.example .env
85
+ ```
86
+
87
+ Open `.env` and replace:
88
+
89
+ ```env
90
+ POSTGRES_PASSWORD=choose-a-long-random-password
91
+ MINIO_ROOT_PASSWORD=choose-another-long-random-password
92
+ ```
93
+
94
+ Do not publish `.env` to GitHub.
95
+
96
+ If port `3000` is busy:
97
+
98
+ ```env
99
+ OTA_HTTP_PORT=3100
100
+ OTA_PUBLIC_BASE_URL=http://localhost:3100
101
+ ```
102
+
103
+ If another project already uses PostgreSQL port `5432`, set:
104
+
105
+ ```env
106
+ POSTGRES_PORT=5433
107
+ ```
108
+
109
+ ## Step 4. Create the signing key pair
110
+
111
+ ```bash
112
+ mkdir -p secrets local-certificates
113
+
114
+ openssl req \
115
+ -x509 \
116
+ -newkey rsa:2048 \
117
+ -nodes \
118
+ -sha256 \
119
+ -days 3650 \
120
+ -subj "/CN=expo-updates" \
121
+ -addext "basicConstraints=critical,CA:FALSE" \
122
+ -addext "keyUsage=critical,digitalSignature" \
123
+ -addext "extendedKeyUsage=codeSigning" \
124
+ -keyout secrets/code-signing-private-key.pem \
125
+ -out local-certificates/code-signing-certificate.pem
126
+
127
+ chmod 600 secrets/code-signing-private-key.pem
128
+ ```
129
+
130
+ Keep `secrets/code-signing-private-key.pem` on the server. Copy
131
+ `local-certificates/code-signing-certificate.pem` to the Expo application.
132
+ The two files must remain a matching pair.
133
+
134
+ ## Step 5. Start everything
135
+
136
+ ```bash
137
+ docker compose up -d --build
138
+ docker compose ps
139
+ ```
140
+
141
+ Wait until `postgres`, `minio` and `app` are `healthy`.
142
+
143
+ ## Step 6. Database setup is automatic
144
+
145
+ Docker automatically applies:
146
+
147
+ ```text
148
+ docs/migrations/schema.sql
149
+ ```
150
+
151
+ You do not need pgAdmin or manual SQL commands for a new Docker installation.
152
+
153
+ ## Step 7. Create the first administrator
154
+
155
+ ```bash
156
+ docker compose exec app npm run create-admin
157
+ ```
158
+
159
+ Enter a username, a password of at least 12 characters and choose `admin`.
160
+
161
+ ## Step 8. Open the admin panel
162
+
163
+ ```text
164
+ http://localhost:3000/login
165
+ ```
166
+
167
+ Use `3100` if you changed `OTA_HTTP_PORT`.
168
+
169
+ ## Step 9. Local publisher settings
170
+
171
+ The Expo publisher can reach Docker services through loopback-only ports:
172
+
173
+ ```env
174
+ OTA_DATABASE_URL=postgresql://expo_updates:YOUR_POSTGRES_PASSWORD@localhost:YOUR_POSTGRES_PORT/expo_updates
175
+ OTA_DATABASE_SSL=false
176
+
177
+ R2_ENDPOINT=http://localhost:9000
178
+ R2_ACCESS_KEY_ID=expo_updates
179
+ R2_SECRET_ACCESS_KEY=YOUR_MINIO_ROOT_PASSWORD
180
+ R2_BUCKET=expo-updates
181
+ ```
182
+
183
+ Use `5432` when `POSTGRES_PORT` was not changed. If `.env` contains
184
+ `POSTGRES_PORT=5433`, use `5433` in `OTA_DATABASE_URL` as well.
185
+
186
+ MinIO Console is available at `http://localhost:9001`.
187
+
188
+ ---
189
+
190
+ # Option B: Supabase
191
+
192
+ Supabase replaces PostgreSQL and MinIO. It does not run the OTA web server.
193
+
194
+ ## Step 1. Create a project
195
+
196
+ 1. Open `https://supabase.com`.
197
+ 2. Select **New project**.
198
+ 3. Enter a project name.
199
+ 4. Create and save a strong database password.
200
+ 5. Select a nearby region.
201
+ 6. Wait until the project is ready.
202
+
203
+ ## Step 2. Install the schema
204
+
205
+ 1. Open **SQL Editor** in the left sidebar.
206
+ 2. Select **New query**.
207
+ 3. Open `docs/migrations/schema.sql` on your computer.
208
+ 4. Copy the entire file.
209
+ 5. Paste it into Supabase SQL Editor.
210
+ 6. Select **Run**.
211
+ 7. Wait for the success message.
212
+
213
+ No other migration files are required.
214
+
215
+ ## Step 3. Confirm the tables
216
+
217
+ Open **Table Editor**. You should see:
218
+
219
+ ```text
220
+ ota_access_tokens
221
+ ota_admin_sessions
222
+ ota_admin_users
223
+ ota_device_state
224
+ ota_device_transitions
225
+ ota_embedded_updates
226
+ ota_emergency_redirects
227
+ ota_served_manifest_log
228
+ ota_update_channels
229
+ ota_updates
230
+ ```
231
+
232
+ ## Step 4. Create storage
233
+
234
+ 1. Open **Storage**.
235
+ 2. Select **New bucket**.
236
+ 3. Name it `expo-updates`.
237
+ 4. Keep the bucket private.
238
+ 5. Select **Create bucket**.
239
+
240
+ ## Step 5. Get server credentials
241
+
242
+ Find the project URL and `service_role` key in project settings. The service
243
+ role key is a backend secret. Never place it in the Expo application.
244
+
245
+ ## Step 6. Configure the OTA server
246
+
247
+ Create `.env.local`:
248
+
249
+ ```env
250
+ DATABASE_PROVIDER=supabase
251
+ SUPABASE_PROJECT_URL=https://YOUR-PROJECT.supabase.co
252
+ SUPABASE_SERVICE_ROLE_KEY=YOUR_SERVICE_ROLE_KEY
253
+ SUPABASE_UPDATES_BUCKET=expo-updates
254
+
255
+ OTA_PUBLIC_BASE_URL=https://updates.example.com
256
+ CODE_SIGNING_PRIVATE_KEY_PATH=/full/path/code-signing-private-key.pem
257
+ ```
258
+
259
+ ## Step 7. Start and check the server
260
+
261
+ ```bash
262
+ npm ci
263
+ npm run build
264
+ npm run start
265
+ ```
266
+
267
+ Open `http://localhost:3000/api/health`. A response containing
268
+ `"status":"ok"` means the database connection works.
269
+
270
+ ## Step 8. Create the administrator
271
+
272
+ ```bash
273
+ npm run create-admin
274
+ ```
275
+
276
+ Choose the `admin` role for the first user.
277
+
278
+ ---
279
+
280
+ # Connect the Expo application
281
+
282
+ These steps are the same for Docker and Supabase.
283
+
284
+ ## Automatic CLI configuration
285
+
286
+ For an Expo application with a static `app.json`, run this command from the OTA
287
+ server repository:
288
+
289
+ ```bash
290
+ npm run configure-app
291
+ ```
292
+
293
+ The CLI asks for the application path, public certificate, server URL, channel,
294
+ runtime, platform and overwrite preference. It displays a summary and requires
295
+ confirmation before changing files or running `expo prebuild`.
296
+
297
+ For CI or advanced usage, pass the same values as flags:
298
+
299
+ ```bash
300
+ npm run configure-app -- \
301
+ --app /full/path/to/expo-application \
302
+ --certificate /full/path/code-signing-certificate.pem \
303
+ --server-url https://updates.example.com \
304
+ --channel production \
305
+ --runtime-version 1.0.0
306
+ ```
307
+
308
+ The CLI:
309
+
310
+ 1. validates the Expo project;
311
+ 2. installs the Expo-compatible `expo-updates` version;
312
+ 3. configures URL, channel, runtime and code signing in `app.json`;
313
+ 4. copies the public certificate;
314
+ 5. installs a portable publish script;
315
+ 6. creates `.env.ota.example`;
316
+ 7. adds `npm run ota:publish`;
317
+ 8. installs publisher dependencies;
318
+ 9. installs Android, Xcode and Xcode Cloud embedded registration hooks;
319
+ 10. runs `expo prebuild` to synchronize native projects.
320
+
321
+ Use `--platform ios` or `--platform android` to prebuild one platform. The
322
+ default is both platforms.
323
+
324
+ Existing generated publisher or certificate files are not overwritten. Add
325
+ `--force` only when replacement is intentional.
326
+
327
+ The CLI stops when `app.config.ts`, `app.config.js`, `app.config.mjs` or
328
+ `app.config.cjs` exists because dynamic Expo config overrides `app.json`.
329
+
330
+ After configuration:
331
+
332
+ ```bash
333
+ cd /full/path/to/expo-application
334
+ cp .env.ota.example .env.ota
335
+ ```
336
+
337
+ Fill in the publisher credentials, then run:
338
+
339
+ ```bash
340
+ npm run ota:publish -- --message "Describe the change"
341
+ ```
342
+
343
+ For local Docker with a `localhost` server URL, the CLI creates the ignored
344
+ `.env.ota` automatically from the OTA server `.env`. Manual configuration is
345
+ only required for a remote server, Supabase or another storage provider.
346
+ Microsoft Dev Tunnel URLs (`*.devtunnels.ms`) are also recognized as local
347
+ Docker exposure: the public tunnel is used for `OTA_SERVER_URL`, while the
348
+ publisher connects directly to MinIO at `http://127.0.0.1:9000`.
349
+
350
+ The update is uploaded as inactive. Activate it in the admin panel after
351
+ review. The following sections describe the equivalent manual setup.
352
+
353
+ ## Register the update embedded in a binary
354
+
355
+ Every release binary contains an embedded update. The server needs its ID for
356
+ reliable rollback and emergency redirects. The configurator installs this flow
357
+ automatically.
358
+
359
+ For local Docker, build Android with:
360
+
361
+ ```bash
362
+ npm run ota:build:android:apk
363
+ ```
364
+
365
+ Use `npm run ota:build:android:aab` for an App Bundle. After Gradle succeeds,
366
+ the generated script finds `app.manifest` and registers the embedded update.
367
+ For iOS, the configurator adds an Xcode Build Phase, so a Release/Archive build
368
+ in Xcode performs registration automatically.
369
+
370
+ For remote CI or Xcode Cloud, do not provide PostgreSQL credentials. Create a
371
+ dedicated token:
372
+
373
+ ```bash
374
+ docker compose exec app npm run create-access-token
375
+ ```
376
+
377
+ Keep the default `updates:write` scope and add the displayed token to CI
378
+ secrets:
379
+
380
+ ```env
381
+ OTA_SERVER_URL=https://updates.example.com
382
+ OTA_ACCESS_TOKEN=ota_...
383
+ ```
384
+
385
+ The configurator also creates `ci_scripts/ci_post_xcodebuild.sh`, which Xcode
386
+ Cloud runs after a build. The token is shown only once and must never be
387
+ committed or included in the mobile binary. Verify registered binaries at
388
+ `/updates/embedded`.
389
+
390
+ ## Step 1. Install Expo Updates
391
+
392
+ ```bash
393
+ npx expo install expo-updates
394
+ ```
395
+
396
+ ## Step 2. Copy the public certificate
397
+
398
+ Copy `code-signing-certificate.pem` into a `certificates` directory in the Expo
399
+ application. Never copy the private key into the mobile project.
400
+
401
+ ## Step 3. Configure Expo
402
+
403
+ Use the `app.config.ts` example in
404
+ [`docs/expo-app-setup.md`](docs/expo-app-setup.md). Set:
405
+
406
+ - `EXPO_OTA_SERVER_URL`;
407
+ - `EXPO_UPDATE_CHANNEL`;
408
+ - `EXPO_RUNTIME_VERSION`.
409
+
410
+ A physical device cannot reach the computer through `localhost`. Production
411
+ requires a public HTTPS URL.
412
+
413
+ ## Step 4. Build a new native binary
414
+
415
+ The OTA URL, channel, runtime and certificate are native settings. Build the
416
+ iOS or Android application again after changing them.
417
+
418
+ ## Step 5. Publish an update
419
+
420
+ After automatic configuration, use:
421
+
422
+ ```bash
423
+ npm run ota:publish -- --message "Describe the change"
424
+ ```
425
+
426
+ The publisher exports JavaScript, uploads assets and inserts database records.
427
+ The new update remains inactive until you approve it.
428
+
429
+ ## Step 6. Activate the update
430
+
431
+ 1. Open `/updates` in the admin panel.
432
+ 2. Find the new update.
433
+ 3. Confirm its channel, runtime and platform.
434
+ 4. Activate it manually.
435
+
436
+ ## Step 7. Test on a device
437
+
438
+ Use a release build, run the update check, download the update and reload the
439
+ application. Expo Go is not suitable for this test.
440
+
441
+ ## Troubleshooting
442
+
443
+ - Server failure: `docker compose logs app`.
444
+ - Container state: `docker compose ps`.
445
+ - Port conflict: change the matching `*_PORT` in `.env`.
446
+ - `password authentication failed for user "expo_updates"` after editing
447
+ `.env`: the existing PostgreSQL volume still has its original password. Run:
448
+
449
+ ```bash
450
+ npm run docker:sync-db-password
451
+ docker compose restart app
452
+ ```
453
+
454
+ - Missing Supabase tables: run the complete `schema.sql` again.
455
+ - Missing update: compare platform, runtime and channel.
456
+ - Signature error: the server private key does not match the app certificate.
457
+ - `SignatureDoesNotMatch`: `.env.ota` storage credentials do not match MinIO
458
+ or R2. For local Docker, run `npm run configure-app` again and allow generated
459
+ files to be replaced so `.env.ota` is synchronized from the server `.env`.
460
+ If the OTA server uses a Dev Tunnel, put the tunnel URL in `OTA_SERVER_URL`
461
+ but keep `R2_ENDPOINT=http://127.0.0.1:9000` for a local publisher. Sending
462
+ signed S3 requests through a
463
+ generic HTTP tunnel can change the host and
464
+ invalidate the AWS signature.
465
+ - `unknown or unexpected option: --platform`: the publisher was generated by
466
+ an older CLI version. Run `npm run configure-app` again and allow generated
467
+ files to be replaced.
468
+ - Missing embedded update: confirm that a Release configuration was built and
469
+ CI has `OTA_SERVER_URL` plus an `OTA_ACCESS_TOKEN` with `updates:write`.
470
+
471
+ Technical reference:
472
+
473
+ - [`docs/operations-guide.md`](docs/operations-guide.md);
474
+ - [`docs/supabase-setup.md`](docs/supabase-setup.md);
475
+ - [`docs/expo-app-setup.md`](docs/expo-app-setup.md).
476
+
477
+ <!-- ## OTA Update Admin Panel
478
+
479
+ Админ-панель для управления `expo-updates` в PostgreSQL + S3-совместимом bucket (Cloudflare R2).
480
+
481
+ Аварийное восстановление ошибочного OTA-канала описано в
482
+ [`docs/ota-emergency-recovery.md`](docs/ota-emergency-recovery.md).
483
+
484
+ Установка, Docker, резервное копирование и безопасное обновление описаны в
485
+ [`docs/operations-guide.md`](docs/operations-guide.md).
486
+
487
+ Пошаговая инструкция для начинающих:
488
+ [`Русский`](docs/getting-started.ru.md) |
489
+ [`English`](docs/getting-started.md).
490
+
491
+ Быстрый запуск через Supabase SQL Editor описан в
492
+ [`docs/supabase-setup.md`](docs/supabase-setup.md).
493
+
494
+ Настройка Expo-приложения, code signing, получение и публикация OTA описаны в
495
+ [`docs/expo-app-setup.md`](docs/expo-app-setup.md).
496
+
497
+ Автоматическая настройка Expo-приложения со статическим `app.json`:
498
+
499
+ ```bash
500
+ npm run configure-app
501
+ ```
502
+
503
+ CLI задаст вопросы и покажет итоговые настройки перед изменением приложения.
504
+ Для CI также поддерживаются flags:
505
+
506
+ ```bash
507
+ npm run configure-app -- \
508
+ --app /path/to/expo-app \
509
+ --certificate /path/to/code-signing-certificate.pem \
510
+ --server-url https://updates.example.com \
511
+ --channel production \
512
+ --runtime-version 1.0.0
513
+ ```
514
+
515
+ ### Основные возможности
516
+
517
+ - Логин по сессионной cookie (без регистрации)
518
+ - Список апдейтов с сортировкой и пагинацией
519
+ - Детальная страница апдейта
520
+ - Удаление апдейта из bucket
521
+ - Редактирование JSON-файлов (`update-info.json`, `metadata.json`, `channels/*/latest.json`)
522
+ - Rollback через перезапись `latest.json`
523
+ - Деактивация/активация апдейта
524
+
525
+ ### Переменные окружения
526
+
527
+ Обязательные:
528
+
529
+ - `DATABASE_PROVIDER` - провайдер БД: `pg` или `supabase` (по умолчанию `pg`)
530
+ - `DATABASE_URL` - строка подключения к PostgreSQL
531
+ - `R2_ENDPOINT` - S3 endpoint для Cloudflare R2
532
+ - `R2_ACCESS_KEY_ID` - access key для R2
533
+ - `R2_SECRET_ACCESS_KEY` - secret key для R2
534
+ - `R2_BUCKET` (или `OTA_STORAGE_BUCKET`) - bucket с OTA ассетами
535
+
536
+ Для `DATABASE_PROVIDER=supabase`:
537
+
538
+ - `SUPABASE_PROJECT_URL` (или `SUPABASE_URL`)
539
+ - `SUPABASE_SERVICE_ROLE_KEY` (или `SUPABASE_PUBLISHED_KEY`)
540
+
541
+ ### Пользователи админки
542
+
543
+ Пользователи, password hashes, роли и активные сессии хранятся в PostgreSQL.
544
+ Environment credentials не используются.
545
+
546
+ Примените единую схему и создайте первого администратора:
547
+
548
+ ```bash
549
+ psql "$DATABASE_URL" -f docs/migrations/schema.sql
550
+ npm run create-admin
551
+ ```
552
+
553
+ Доступны роли:
554
+
555
+ - `admin` — полный доступ, включая управление access tokens;
556
+ - `operator` — управление updates и emergency redirects;
557
+ - `viewer` — только просмотр updates и redirects.
558
+
559
+ Опционально:
560
+
561
+ - `OTA_PUBLIC_BASE_URL` - публичный URL OTA сервера (для `/api/manifest` и `/api/assets`)
562
+ - `OTA_CDN_BASE_URL` - публичный CDN URL для прямой раздачи ассетов (например `https://cdn.cogitize.tech`)
563
+ - `OTA_SIGNED_URL_TTL` - TTL signed URL в секундах (по умолчанию `3600`)
564
+ - `R2_REGION` - регион для S3 клиента (по умолчанию `auto`)
565
+
566
+ ### Маршруты
567
+
568
+ - `/login` — страница входа
569
+ - `/updates` — список апдейтов
570
+ - `/updates/[id]` — страница конкретного апдейта
571
+
572
+ ### Access tokens
573
+
574
+ Admin API поддерживает cookie-сессию и Bearer tokens. Перед первым
575
+ использованием примените миграцию:
576
+
577
+ ```bash
578
+ psql "$DATABASE_URL" -f docs/migrations/schema.sql
579
+ ```
580
+
581
+ Создание токена доступно только через cookie-сессию администратора:
582
+
583
+ ```http
584
+ POST /api/admin/access-tokens
585
+ Content-Type: application/json
586
+
587
+ {
588
+ "name": "Deployment CI",
589
+ "scopes": ["updates:read", "updates:write"],
590
+ "expiresAt": "2027-01-01T00:00:00.000Z"
591
+ }
592
+ ```
593
+
594
+ Raw token возвращается только при создании. В базе хранится SHA-256 hash.
595
+ Поддерживаемые scopes: `updates:read`, `updates:write`, `redirects:read`,
596
+ `redirects:write`.
597
+
598
+ Использование:
599
+
600
+ ```bash
601
+ curl -H "Authorization: Bearer $OTA_ACCESS_TOKEN" \
602
+ https://updates.example.com/api/admin/updates
603
+ ```
604
+
605
+ ### Emergency redirects
606
+
607
+ Правила хранятся в таблице `ota_emergency_redirects` и управляются на странице
608
+ `/updates/emergency-redirects`.
609
+
610
+ Перед deploy примените миграцию:
611
+
612
+ ```bash
613
+ psql "$DATABASE_URL" -f docs/migrations/schema.sql
614
+ ```
615
+
616
+ Если раньше использовался JSON-конфиг, импортируйте его до deploy новой версии:
617
+
618
+ ```bash
619
+ npm run emergency:import
620
+ ```
621
+
622
+ ## Getting Started
623
+
624
+ Docker Compose:
625
+
626
+ ```bash
627
+ cp .env.docker.example .env
628
+ mkdir -p secrets
629
+ # Copy code-signing-private-key.pem into ./secrets
630
+ docker compose up -d --build
631
+ docker compose exec app npm run create-admin
632
+ ```
633
+
634
+ First, run the development server:
635
+
636
+ ```bash
637
+ npm run dev
638
+ # or
639
+ yarn dev
640
+ # or
641
+ pnpm dev
642
+ # or
643
+ bun dev
644
+ ```
645
+
646
+ Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
647
+
648
+ You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
649
+
650
+ This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
651
+
652
+ ## Learn More
653
+
654
+ To learn more about Next.js, take a look at the following resources:
655
+
656
+ - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
657
+ - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
658
+
659
+ You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
660
+
661
+ ## Deploy on Vercel
662
+
663
+ The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
664
+
665
+ Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. -->
@@ -0,0 +1,25 @@
1
+ import { revokeAccessToken } from "@/src/server/lib/admin-access-tokens";
2
+ import { requireAdminSession } from "@/src/server/lib/admin-api";
3
+ import { NextRequest, NextResponse } from "next/server";
4
+
5
+ type RouteContext = {
6
+ params: Promise<{ id: string }>;
7
+ };
8
+
9
+ export async function DELETE(request: NextRequest, context: RouteContext) {
10
+ const session = await requireAdminSession(request, ["admin"]);
11
+ if (session instanceof NextResponse) {
12
+ return session;
13
+ }
14
+
15
+ try {
16
+ const { id } = await context.params;
17
+ await revokeAccessToken(id);
18
+ return NextResponse.json({ ok: true });
19
+ } catch (error: unknown) {
20
+ return NextResponse.json(
21
+ { error: (error as Error).message || "Failed to revoke access token" },
22
+ { status: 500 },
23
+ );
24
+ }
25
+ }