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,109 @@
1
+ # Аварийное восстановление OTA
2
+
3
+ Emergency redirect используется, когда опубликованный binary build запрашивает
4
+ неправильный нативный Expo channel. JavaScript OTA не может изменить channel,
5
+ записанный в Android Manifest или iOS Expo.plist, поэтому сервер точечно
6
+ перенаправляет affected build.
7
+
8
+ Правило применяется только при точном совпадении:
9
+
10
+ - `expo-embedded-update-id`;
11
+ - runtime version;
12
+ - platform;
13
+ - исходного channel.
14
+
15
+ Нельзя перенаправлять весь runtime: development и production builds могут
16
+ использовать одинаковую runtime version.
17
+
18
+ ## Подготовка БД
19
+
20
+ ```bash
21
+ psql "$DATABASE_URL" -f docs/migrations/schema.sql
22
+ ```
23
+
24
+ Если раньше правила хранились в
25
+ `config/ota-emergency-channel-redirects.json`, импортируйте их до deploy:
26
+
27
+ ```bash
28
+ npm run emergency:import
29
+ ```
30
+
31
+ После успешного импорта JSON больше не используется сервером.
32
+
33
+ ## Управление
34
+
35
+ Откройте:
36
+
37
+ ```text
38
+ /updates/emergency-redirects
39
+ ```
40
+
41
+ Роли `admin` и `operator` могут:
42
+
43
+ - создавать и редактировать правила;
44
+ - включать и отключать redirect;
45
+ - переключать `pinned` и `follow`;
46
+ - удалять правила.
47
+
48
+ Роль `viewer` имеет read-only доступ.
49
+
50
+ ## Режимы
51
+
52
+ ### Pinned
53
+
54
+ Сервер разрешает только `expectedUpdateId`. Если target channel указывает на
55
+ другой update, устройство получает `noUpdateAvailable`.
56
+
57
+ Используйте `pinned` во время первичного восстановления, чтобы affected build
58
+ получил только проверенный recovery OTA.
59
+
60
+ ### Follow
61
+
62
+ Сервер использует актуальный active/latest update целевого channel. После
63
+ успешной установки recovery OTA правило можно переключить в `follow`, чтобы
64
+ старый binary продолжил получать обычные обновления.
65
+
66
+ ## Пример инцидента
67
+
68
+ Android build может быть опубликован с:
69
+
70
+ ```text
71
+ runtime: 1.1.20
72
+ native channel: development
73
+ expected environment: production
74
+ ```
75
+
76
+ Экран приложения при этом способен показывать `production`, если читает
77
+ JavaScript-конфигурацию. Expo Updates всё равно отправит:
78
+
79
+ ```text
80
+ expo-channel-name: development
81
+ ```
82
+
83
+ Для affected embedded update создайте правило:
84
+
85
+ ```text
86
+ platform: android
87
+ runtimeVersion: 1.1.20
88
+ fromChannel: development
89
+ toChannel: production
90
+ targetMode: pinned
91
+ expectedUpdateId: <verified-recovery-update-id>
92
+ ```
93
+
94
+ После подтверждения recovery переключите правило в `follow`.
95
+
96
+ ## Проверка
97
+
98
+ ```bash
99
+ curl -fsS \
100
+ 'https://updates.example.com/api/manifest' \
101
+ -H 'expo-protocol-version: 1' \
102
+ -H 'expo-platform: android' \
103
+ -H 'expo-runtime-version: 1.1.20' \
104
+ -H 'expo-channel-name: development' \
105
+ -H 'expo-embedded-update-id: <affected-embedded-update-id>'
106
+ ```
107
+
108
+ Проверьте, что multipart manifest содержит ожидаемый update и asset URLs
109
+ целевого channel.
@@ -0,0 +1,133 @@
1
+ # Supabase Setup
2
+
3
+ Supabase is the simplest hosted PostgreSQL option for the OTA server. It is
4
+ not a reduced or development-only installation: the same canonical schema is
5
+ used by Supabase, standalone PostgreSQL and Docker Compose.
6
+
7
+ ## 1. Create a project
8
+
9
+ Create a Supabase project and wait until its database is ready.
10
+
11
+ Keep these server-side values:
12
+
13
+ - project URL;
14
+ - service role key;
15
+ - direct PostgreSQL connection string, if scripts will connect with `pg`.
16
+
17
+ Never put the service role key or database connection string in an Expo
18
+ application.
19
+
20
+ ## 2. Apply the complete schema
21
+
22
+ Open **SQL Editor** in the Supabase dashboard:
23
+
24
+ 1. Select **New query**.
25
+ 2. Open
26
+ [`docs/migrations/schema.sql`](https://github.com/tonichiga/expo-updates-server/blob/main/docs/migrations/schema.sql)
27
+ from this repository.
28
+ 3. Copy the complete file into the editor.
29
+ 4. Select **Run**.
30
+
31
+ The file is idempotent and is the canonical schema for a new installation. It
32
+ creates:
33
+
34
+ | Table | Purpose |
35
+ |---|---|
36
+ | `ota_updates` | Published OTA update metadata |
37
+ | `ota_update_channels` | Latest and active update pointers |
38
+ | `ota_embedded_updates` | Embedded native update metadata |
39
+ | `ota_served_manifest_log` | Served manifest to update mapping |
40
+ | `ota_device_state` | Last known state of each installation |
41
+ | `ota_device_transitions` | Runtime and update transition history |
42
+ | `ota_admin_users` | Admin users and roles |
43
+ | `ota_admin_sessions` | Revocable browser sessions |
44
+ | `ota_access_tokens` | Hashed automation tokens |
45
+ | `ota_emergency_redirects` | Emergency channel rules |
46
+
47
+ Do not run a pgAdmin schema dump as the installation script. Dumps contain
48
+ database-specific owners and session commands. `schema.sql` contains only the
49
+ portable application schema.
50
+
51
+ ## 3. Configure the server
52
+
53
+ The recommended Supabase adapter configuration is:
54
+
55
+ ```env
56
+ DATABASE_PROVIDER=supabase
57
+ SUPABASE_PROJECT_URL=https://PROJECT.supabase.co
58
+ SUPABASE_SERVICE_ROLE_KEY=...
59
+ SUPABASE_UPDATES_BUCKET=expo-updates
60
+
61
+ OTA_PUBLIC_BASE_URL=https://updates.example.com
62
+ CODE_SIGNING_PRIVATE_KEY_PATH=/run/secrets/code-signing-private-key.pem
63
+ ```
64
+
65
+ Use the **service role key**, not an anonymous or publishable browser key. The
66
+ OTA server is a trusted backend and needs access to all management tables.
67
+
68
+ Alternatively, use Supabase only as hosted PostgreSQL and object storage while
69
+ the server uses the PostgreSQL/S3 adapter:
70
+
71
+ ```env
72
+ DATABASE_PROVIDER=pg
73
+ DATABASE_URL=postgresql://...
74
+ DATABASE_SSL=true
75
+
76
+ R2_ENDPOINT=https://PROJECT.supabase.co/storage/v1/s3
77
+ R2_ACCESS_KEY_ID=...
78
+ R2_SECRET_ACCESS_KEY=...
79
+ R2_BUCKET=expo-updates
80
+ R2_REGION=...
81
+ S3_FORCE_PATH_STYLE=true
82
+ ```
83
+
84
+ Use the exact S3 endpoint and credentials shown by the Supabase Storage S3
85
+ configuration page.
86
+
87
+ ## 4. Create the storage bucket
88
+
89
+ Create a private bucket named `expo-updates`, or use another name and set the
90
+ same value in:
91
+
92
+ ```env
93
+ SUPABASE_UPDATES_BUCKET=expo-updates
94
+ R2_BUCKET=expo-updates
95
+ OTA_STORAGE_BUCKET=expo-updates
96
+ ```
97
+
98
+ The bucket must remain private when assets are delivered through signed URLs.
99
+
100
+ ## 5. Create the first administrator
101
+
102
+ Set the server environment locally, then run:
103
+
104
+ ```bash
105
+ npm ci
106
+ npm run create-admin
107
+ ```
108
+
109
+ The command writes a bcrypt password hash to `ota_admin_users`. It does not
110
+ store the plaintext password.
111
+
112
+ ## 6. Verify the installation
113
+
114
+ Start the server and check:
115
+
116
+ ```bash
117
+ curl -fsS https://updates.example.com/api/health
118
+ ```
119
+
120
+ Then sign in at:
121
+
122
+ ```text
123
+ https://updates.example.com/login
124
+ ```
125
+
126
+ The **Table Editor** should show all ten OTA tables listed above.
127
+
128
+ ## 7. Upgrades
129
+
130
+ Back up the database before upgrades, then apply the current
131
+ `docs/migrations/schema.sql`. The schema is idempotent and adds missing
132
+ objects. Release notes must explicitly document any future data migration or
133
+ destructive change that cannot be represented safely in this file.
@@ -0,0 +1,30 @@
1
+ import { defineConfig, globalIgnores } from "eslint/config";
2
+ import nextVitals from "eslint-config-next/core-web-vitals";
3
+ import nextTs from "eslint-config-next/typescript";
4
+
5
+ const eslintConfig = defineConfig([
6
+ ...nextVitals,
7
+ ...nextTs,
8
+ // Override default ignores of eslint-config-next.
9
+ globalIgnores([
10
+ // Default ignores of eslint-config-next:
11
+ ".next/**",
12
+ "out/**",
13
+ "build/**",
14
+ "docs/.vitepress/cache/**",
15
+ "docs/.vitepress/dist/**",
16
+ "packages/create-expo-updates-server/dist/**",
17
+ "packages/create-expo-updates-server/.dist-building-*/**",
18
+ "packages/create-expo-updates-server/.test-work/**",
19
+ "packages/create-expo-updates-server/.smoke-work/**",
20
+ "next-env.d.ts",
21
+ ]),
22
+ {
23
+ files: ["templates/expo-app/plugins/**/*.js"],
24
+ rules: {
25
+ "@typescript-eslint/no-require-imports": "off",
26
+ },
27
+ },
28
+ ]);
29
+
30
+ export default eslintConfig;
@@ -0,0 +1,58 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.*
7
+ .yarn/*
8
+ !.yarn/patches
9
+ !.yarn/plugins
10
+ !.yarn/releases
11
+ !.yarn/versions
12
+
13
+ # testing
14
+ /coverage
15
+
16
+ # next.js
17
+ /.next/
18
+ /out/
19
+
20
+ # vitepress
21
+ /docs/.vitepress/cache/
22
+ /docs/.vitepress/dist/
23
+
24
+ # production
25
+ /build
26
+
27
+ # misc
28
+ .DS_Store
29
+ *.pem
30
+
31
+ # debug
32
+ npm-debug.log*
33
+ yarn-debug.log*
34
+ yarn-error.log*
35
+ .pnpm-debug.log*
36
+
37
+ # env files (can opt-in for committing if needed)
38
+ .env*
39
+ !.env.example
40
+ !.env.docker.example
41
+ !templates/expo-app/.env.ota.example
42
+ secrets/
43
+ local-certificates/
44
+
45
+ # vercel
46
+ .vercel
47
+
48
+ # typescript
49
+ *.tsbuildinfo
50
+ next-env.d.ts
51
+ .env*.local
52
+
53
+ # create-expo-updates-server generated artifacts
54
+ /packages/create-expo-updates-server/dist/
55
+ /packages/create-expo-updates-server/.dist-building-*/
56
+ /packages/create-expo-updates-server/.test-work/
57
+ /packages/create-expo-updates-server/.smoke-work/
58
+ *.tgz
@@ -0,0 +1,7 @@
1
+ import type { NextConfig } from "next";
2
+
3
+ const nextConfig: NextConfig = {
4
+ output: "standalone",
5
+ };
6
+
7
+ export default nextConfig;