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,363 @@
1
+ create extension if not exists pgcrypto;
2
+
3
+ create table if not exists public.ota_updates (
4
+ id uuid primary key default gen_random_uuid(),
5
+ update_id uuid not null unique,
6
+ build_id uuid not null,
7
+ runtime_version text not null,
8
+ channel text not null,
9
+ platform text not null check (platform in ('ios', 'android')),
10
+ created_at timestamptz not null,
11
+ created_at_path text not null,
12
+ storage_bucket text not null,
13
+ storage_base_path text not null,
14
+ is_active boolean not null default false,
15
+ updated_at timestamptz null,
16
+ disabled_at timestamptz null,
17
+ assets_count integer not null default 0,
18
+ launch_asset_path text null,
19
+ comment text null,
20
+ rolled_back_from_update_id uuid null,
21
+ manifest jsonb not null,
22
+ inserted_at timestamptz not null default now(),
23
+ modified_at timestamptz not null default now(),
24
+ constraint ota_updates_active_dates_chk check (
25
+ not is_active or disabled_at is null
26
+ )
27
+ );
28
+
29
+ create index if not exists idx_ota_updates_lookup
30
+ on public.ota_updates (runtime_version, channel, platform, created_at desc);
31
+
32
+ create unique index if not exists idx_ota_updates_one_active_per_scope
33
+ on public.ota_updates (runtime_version, channel, platform)
34
+ where is_active;
35
+
36
+ create table if not exists public.ota_update_channels (
37
+ id bigserial primary key,
38
+ runtime_version text not null,
39
+ channel text not null,
40
+ platform text not null check (platform in ('ios', 'android')),
41
+ latest_update_id uuid null references public.ota_updates(update_id) on delete set null,
42
+ latest_created_at timestamptz null,
43
+ latest_created_at_path text null,
44
+ active_update_id uuid null references public.ota_updates(update_id) on delete set null,
45
+ active_changed_at timestamptz null,
46
+ inserted_at timestamptz not null default now(),
47
+ modified_at timestamptz not null default now(),
48
+ unique (runtime_version, channel, platform)
49
+ );
50
+
51
+ create or replace function public.set_modified_at()
52
+ returns trigger
53
+ language plpgsql
54
+ as $$
55
+ begin
56
+ new.modified_at = now();
57
+ return new;
58
+ end;
59
+ $$;
60
+
61
+ drop trigger if exists trg_ota_updates_modified_at on public.ota_updates;
62
+ create trigger trg_ota_updates_modified_at
63
+ before update on public.ota_updates
64
+ for each row execute function public.set_modified_at();
65
+
66
+ drop trigger if exists trg_ota_update_channels_modified_at on public.ota_update_channels;
67
+ create trigger trg_ota_update_channels_modified_at
68
+ before update on public.ota_update_channels
69
+ for each row execute function public.set_modified_at();
70
+
71
+ alter table public.ota_update_channels
72
+ add column if not exists served_manifest_id uuid not null default gen_random_uuid();
73
+
74
+ alter table public.ota_update_channels
75
+ add column if not exists served_manifest_changed_at timestamptz not null default now();
76
+
77
+ create or replace function public.ota_channels_rotate_served_manifest_id()
78
+ returns trigger
79
+ language plpgsql
80
+ as $$
81
+ begin
82
+ if (
83
+ old.latest_update_id is distinct from new.latest_update_id
84
+ or old.active_update_id is distinct from new.active_update_id
85
+ ) then
86
+ new.served_manifest_id := gen_random_uuid();
87
+ new.served_manifest_changed_at := now();
88
+ end if;
89
+
90
+ return new;
91
+ end;
92
+ $$;
93
+
94
+ -- 4) Триггер
95
+ drop trigger if exists trg_ota_channels_rotate_served_manifest_id on public.ota_update_channels;
96
+
97
+ create trigger trg_ota_channels_rotate_served_manifest_id
98
+ before update on public.ota_update_channels
99
+ for each row
100
+ execute function public.ota_channels_rotate_served_manifest_id();
101
+
102
+ -- 5) Индекс (не обязателен, но полезен для отладки/поиска)
103
+ create index if not exists idx_ota_channels_served_manifest_id
104
+ on public.ota_update_channels(served_manifest_id);
105
+
106
+ create or replace function public.ota_channels_validate_scope_pointers()
107
+ returns trigger
108
+ language plpgsql
109
+ as $$
110
+ declare
111
+ latest_row record;
112
+ active_row record;
113
+ begin
114
+ if new.latest_update_id is not null then
115
+ select runtime_version, channel, platform
116
+ into latest_row
117
+ from public.ota_updates
118
+ where update_id = new.latest_update_id;
119
+
120
+ if not found then
121
+ raise exception
122
+ 'latest_update_id % does not exist in ota_updates',
123
+ new.latest_update_id;
124
+ end if;
125
+
126
+ if latest_row.runtime_version is distinct from new.runtime_version
127
+ or latest_row.channel is distinct from new.channel
128
+ or latest_row.platform is distinct from new.platform then
129
+ raise exception
130
+ 'latest_update_id % points outside scope (%/%/%), row scope is (%/%/%)',
131
+ new.latest_update_id,
132
+ latest_row.runtime_version,
133
+ latest_row.channel,
134
+ latest_row.platform,
135
+ new.runtime_version,
136
+ new.channel,
137
+ new.platform;
138
+ end if;
139
+ end if;
140
+
141
+ if new.active_update_id is not null then
142
+ select runtime_version, channel, platform
143
+ into active_row
144
+ from public.ota_updates
145
+ where update_id = new.active_update_id;
146
+
147
+ if not found then
148
+ raise exception
149
+ 'active_update_id % does not exist in ota_updates',
150
+ new.active_update_id;
151
+ end if;
152
+
153
+ if active_row.runtime_version is distinct from new.runtime_version
154
+ or active_row.channel is distinct from new.channel
155
+ or active_row.platform is distinct from new.platform then
156
+ raise exception
157
+ 'active_update_id % points outside scope (%/%/%), row scope is (%/%/%)',
158
+ new.active_update_id,
159
+ active_row.runtime_version,
160
+ active_row.channel,
161
+ active_row.platform,
162
+ new.runtime_version,
163
+ new.channel,
164
+ new.platform;
165
+ end if;
166
+ end if;
167
+
168
+ return new;
169
+ end;
170
+ $$;
171
+
172
+ drop trigger if exists trg_ota_channels_validate_scope_pointers
173
+ on public.ota_update_channels;
174
+ create trigger trg_ota_channels_validate_scope_pointers
175
+ before insert or update on public.ota_update_channels
176
+ for each row
177
+ execute function public.ota_channels_validate_scope_pointers();
178
+
179
+ create table if not exists public.ota_embedded_updates (
180
+ id uuid primary key default gen_random_uuid(),
181
+ embedded_update_id uuid not null unique,
182
+ created_at timestamptz not null,
183
+ channel text not null,
184
+ platform text not null check (platform in ('ios', 'android')),
185
+ is_embedded boolean not null default true,
186
+ inserted_at timestamptz not null default now(),
187
+ modified_at timestamptz not null default now()
188
+ );
189
+
190
+ create index if not exists idx_ota_embedded_updates_lookup
191
+ on public.ota_embedded_updates (channel, platform, created_at desc);
192
+
193
+ drop trigger if exists trg_ota_embedded_updates_modified_at
194
+ on public.ota_embedded_updates;
195
+ create trigger trg_ota_embedded_updates_modified_at
196
+ before update on public.ota_embedded_updates
197
+ for each row execute function public.set_modified_at();
198
+
199
+ create table if not exists public.ota_served_manifest_log (
200
+ served_manifest_id uuid primary key,
201
+ update_id uuid not null
202
+ references public.ota_updates(update_id) on delete cascade,
203
+ runtime_version text not null,
204
+ channel text not null,
205
+ platform text not null check (platform in ('ios', 'android')),
206
+ reason text null,
207
+ created_at timestamptz not null default now()
208
+ );
209
+
210
+ create index if not exists idx_ota_served_manifest_log_update_id
211
+ on public.ota_served_manifest_log (update_id);
212
+
213
+ create index if not exists idx_ota_served_manifest_log_scope
214
+ on public.ota_served_manifest_log (
215
+ runtime_version,
216
+ channel,
217
+ platform,
218
+ created_at desc
219
+ );
220
+
221
+ create table if not exists public.ota_device_state (
222
+ installation_id text not null,
223
+ platform text not null check (platform in ('ios', 'android')),
224
+ runtime_version text not null,
225
+ embedded_update_id uuid null,
226
+ current_update_id uuid null
227
+ references public.ota_updates(update_id) on delete set null,
228
+ served_manifest_id uuid null,
229
+ channel text not null,
230
+ first_seen_at timestamptz not null default now(),
231
+ last_seen_at timestamptz not null default now(),
232
+ primary key (installation_id, platform)
233
+ );
234
+
235
+ create index if not exists idx_ota_device_state_runtime
236
+ on public.ota_device_state (runtime_version, channel, platform);
237
+
238
+ create index if not exists idx_ota_device_state_update_id
239
+ on public.ota_device_state (current_update_id);
240
+
241
+ create table if not exists public.ota_device_transitions (
242
+ id bigserial primary key,
243
+ installation_id text not null,
244
+ platform text not null check (platform in ('ios', 'android')),
245
+ from_runtime text null,
246
+ from_update_id uuid null,
247
+ to_runtime text not null,
248
+ to_update_id uuid null,
249
+ transition_type text not null,
250
+ occurred_at timestamptz not null default now()
251
+ );
252
+
253
+ create index if not exists idx_ota_device_transitions_installation
254
+ on public.ota_device_transitions (
255
+ installation_id,
256
+ platform,
257
+ occurred_at desc
258
+ );
259
+
260
+ create index if not exists idx_ota_device_transitions_from_update
261
+ on public.ota_device_transitions (from_update_id);
262
+
263
+ create index if not exists idx_ota_device_transitions_to_update
264
+ on public.ota_device_transitions (to_update_id);
265
+
266
+ create table if not exists public.ota_access_tokens (
267
+ id uuid primary key default gen_random_uuid(),
268
+ name text not null check (char_length(name) between 1 and 100),
269
+ token_prefix text not null,
270
+ token_hash text not null unique check (token_hash ~ '^[0-9a-f]{64}$'),
271
+ scopes text[] not null check (cardinality(scopes) > 0),
272
+ expires_at timestamptz null,
273
+ revoked_at timestamptz null,
274
+ last_used_at timestamptz null,
275
+ created_at timestamptz not null default now(),
276
+ constraint ota_access_tokens_scopes_chk check (
277
+ scopes <@ array[
278
+ 'updates:read',
279
+ 'updates:write',
280
+ 'redirects:read',
281
+ 'redirects:write'
282
+ ]::text[]
283
+ )
284
+ );
285
+
286
+ create index if not exists idx_ota_access_tokens_active_hash
287
+ on public.ota_access_tokens (token_hash)
288
+ where revoked_at is null;
289
+
290
+ create table if not exists public.ota_emergency_redirects (
291
+ id uuid primary key default gen_random_uuid(),
292
+ name text not null unique check (char_length(name) between 1 and 120),
293
+ enabled boolean not null default true,
294
+ embedded_update_id uuid not null,
295
+ runtime_version text not null,
296
+ platform text not null check (platform in ('ios', 'android')),
297
+ from_channel text not null,
298
+ to_channel text not null,
299
+ target_mode text not null check (target_mode in ('pinned', 'follow')),
300
+ expected_update_id uuid null,
301
+ created_at timestamptz not null default now(),
302
+ modified_at timestamptz not null default now(),
303
+ constraint ota_emergency_redirect_channels_chk check (
304
+ from_channel <> to_channel
305
+ ),
306
+ constraint ota_emergency_redirect_pinned_target_chk check (
307
+ target_mode <> 'pinned' or expected_update_id is not null
308
+ ),
309
+ unique (embedded_update_id, runtime_version, platform, from_channel)
310
+ );
311
+
312
+ create index if not exists idx_ota_emergency_redirect_lookup
313
+ on public.ota_emergency_redirects (
314
+ embedded_update_id,
315
+ runtime_version,
316
+ platform,
317
+ from_channel
318
+ )
319
+ where enabled;
320
+
321
+ drop trigger if exists trg_ota_emergency_redirects_modified_at
322
+ on public.ota_emergency_redirects;
323
+ create trigger trg_ota_emergency_redirects_modified_at
324
+ before update on public.ota_emergency_redirects
325
+ for each row execute function public.set_modified_at();
326
+
327
+ create table if not exists public.ota_admin_users (
328
+ id uuid primary key default gen_random_uuid(),
329
+ username text not null unique,
330
+ password_hash text not null,
331
+ role text not null check (role in ('admin', 'operator', 'viewer')),
332
+ is_active boolean not null default true,
333
+ last_login_at timestamptz null,
334
+ created_at timestamptz not null default now(),
335
+ modified_at timestamptz not null default now(),
336
+ constraint ota_admin_users_username_chk check (
337
+ username = lower(username)
338
+ and username ~ '^[a-z0-9._-]{3,64}$'
339
+ )
340
+ );
341
+
342
+ create table if not exists public.ota_admin_sessions (
343
+ id uuid primary key default gen_random_uuid(),
344
+ user_id uuid not null references public.ota_admin_users(id) on delete cascade,
345
+ token_hash text not null unique check (token_hash ~ '^[0-9a-f]{64}$'),
346
+ expires_at timestamptz not null,
347
+ revoked_at timestamptz null,
348
+ last_used_at timestamptz not null default now(),
349
+ created_at timestamptz not null default now()
350
+ );
351
+
352
+ create index if not exists idx_ota_admin_sessions_active_hash
353
+ on public.ota_admin_sessions (token_hash)
354
+ where revoked_at is null;
355
+
356
+ create index if not exists idx_ota_admin_sessions_user
357
+ on public.ota_admin_sessions (user_id, expires_at desc);
358
+
359
+ drop trigger if exists trg_ota_admin_users_modified_at
360
+ on public.ota_admin_users;
361
+ create trigger trg_ota_admin_users_modified_at
362
+ before update on public.ota_admin_users
363
+ for each row execute function public.set_modified_at();
@@ -0,0 +1,83 @@
1
+ # Create a server with NPX
2
+
3
+ The npm initializer is the quickest way to create a standalone copy of Expo
4
+ Updates Server. Node.js 20.9 or newer is required.
5
+
6
+ ```bash
7
+ npx create-expo-updates-server@latest my-server
8
+ cd my-server
9
+ ```
10
+
11
+ `npx` downloads the published initializer package from npm. After it starts,
12
+ the initializer makes no network requests: the server template and its
13
+ SHA-256 manifest are bundled in the package.
14
+
15
+ ## Safety behavior
16
+
17
+ The initializer:
18
+
19
+ - accepts exactly one destination directory;
20
+ - requires the destination path not to exist and refuses existing empty or
21
+ non-empty directories, files, and symbolic links;
22
+ - creates a unique sibling staging directory with mode `0700`;
23
+ - builds the complete project in staging and verifies its full path set, file
24
+ types, sizes, and SHA-256 digests before installation;
25
+ - checks the destination again immediately before one final rename, so normal
26
+ installation exposes either the complete verified project or no project;
27
+ - never merges files, incrementally copies into the destination, or
28
+ recursively deletes the destination;
29
+ - leaves the unique staging directory in place after any failure and reports
30
+ its exact path for manual inspection or removal.
31
+
32
+ The destination must remain absent for the entire command. If another process
33
+ creates a file, symbolic link, or non-empty directory before the final rename,
34
+ the initializer fails and leaves it unchanged. Portable filesystem APIs do not
35
+ provide a cross-platform, atomic no-clobber directory rename. In the narrow
36
+ race where another process creates an empty destination directory after the
37
+ last absence check, the rename may replace that empty directory.
38
+
39
+ Staging contains only public template files. On success, the final rename
40
+ consumes it, so no staging directory remains.
41
+
42
+ It deliberately does not install dependencies, initialize a Git repository,
43
+ write `.env` files, or generate signing keys and other secrets. There is no
44
+ `--force` option.
45
+
46
+ ## Start with Docker
47
+
48
+ Review the example first, choose strong passwords, and then start the stack:
49
+
50
+ ```bash
51
+ cp .env.docker.example .env
52
+ docker compose up -d --build
53
+ docker compose exec app npm run create-admin
54
+ ```
55
+
56
+ Follow the [quick start](/getting-started) to generate the required signing
57
+ key pair and connect an Expo application.
58
+
59
+ ## Start with npm
60
+
61
+ Install exactly the dependencies in the bundled lockfile:
62
+
63
+ ```bash
64
+ npm ci
65
+ cp .env.example .env.local
66
+ npm run dev
67
+ ```
68
+
69
+ Configure PostgreSQL and S3-compatible storage (or Supabase), signing keys,
70
+ and all required environment values before using the server in production.
71
+ See [Supabase setup](/supabase-setup), [Expo application
72
+ setup](/expo-app-setup), and the [operations guide](/operations-guide).
73
+
74
+ ## Reproducibility and source
75
+
76
+ Each published package contains a filtered snapshot whose bytes are read
77
+ directly from the Git objects at the recorded source commit in
78
+ [tonichiga/expo-updates-server](https://github.com/tonichiga/expo-updates-server).
79
+ Dirty or untracked working-tree content cannot affect that snapshot. The
80
+ package records the exact source commit and file size and SHA-256 digest for
81
+ every generated file. Build output, credentials, populated sensitive values,
82
+ real environment files, internal planning documents, and the initializer
83
+ itself are excluded.
@@ -0,0 +1,270 @@
1
+ # Operations Guide
2
+
3
+ This guide describes installation, day-to-day administration, incident
4
+ recovery, backups and upgrades for the OTA update server.
5
+
6
+ ## 1. Required infrastructure
7
+
8
+ - Node.js 24 and npm, or Docker with Docker Compose;
9
+ - PostgreSQL 15 or newer;
10
+ - S3-compatible object storage such as Cloudflare R2 or MinIO;
11
+ - HTTPS public URL for production;
12
+ - optional CDN for immutable OTA assets.
13
+
14
+ ## 2. Environment
15
+
16
+ Copy `.env.example` to `.env.local` for a manual installation.
17
+
18
+ Required for PostgreSQL and S3:
19
+
20
+ ```env
21
+ DATABASE_PROVIDER=pg
22
+ DATABASE_URL=postgresql://user:password@host:5432/database
23
+ DATABASE_SSL=true
24
+
25
+ R2_ENDPOINT=https://storage.example.com
26
+ R2_ACCESS_KEY_ID=...
27
+ R2_SECRET_ACCESS_KEY=...
28
+ R2_BUCKET=expo-updates
29
+ R2_REGION=auto
30
+
31
+ OTA_PUBLIC_BASE_URL=https://updates.example.com
32
+ ```
33
+
34
+ For MinIO, also set:
35
+
36
+ ```env
37
+ S3_FORCE_PATH_STYLE=true
38
+ ```
39
+
40
+ Never commit `.env.local`, database passwords, storage keys, access tokens or
41
+ code-signing private keys.
42
+
43
+ ## 3. Database installation
44
+
45
+ For PostgreSQL or Supabase, apply the single canonical schema:
46
+
47
+ ```bash
48
+ psql "$DATABASE_URL" -f docs/migrations/schema.sql
49
+ ```
50
+
51
+ Supabase SQL Editor installation is described in
52
+ [`supabase-setup.md`](supabase-setup.md).
53
+
54
+ The schema uses idempotent object creation and can also fill missing objects in
55
+ an existing installation. Back up the database before applying it.
56
+
57
+ ## 4. First administrator
58
+
59
+ Create or reset a user interactively:
60
+
61
+ ```bash
62
+ npm run create-admin
63
+ ```
64
+
65
+ Roles:
66
+
67
+ | Role | Permissions |
68
+ |---|---|
69
+ | `admin` | Full access and access-token management |
70
+ | `operator` | Manage updates and emergency redirects |
71
+ | `viewer` | Read-only access |
72
+
73
+ Passwords must contain at least 12 characters. Only bcrypt hashes are stored.
74
+
75
+ ## 5. Manual startup
76
+
77
+ ```bash
78
+ npm ci
79
+ npm run build
80
+ npm run start
81
+ ```
82
+
83
+ Readiness:
84
+
85
+ ```bash
86
+ curl -fsS http://localhost:3000/api/health
87
+ ```
88
+
89
+ Expected response:
90
+
91
+ ```json
92
+ {
93
+ "status": "ok",
94
+ "checks": {
95
+ "database": "ok"
96
+ }
97
+ }
98
+ ```
99
+
100
+ ## 6. Docker Compose quick start
101
+
102
+ ```bash
103
+ cp .env.docker.example .env
104
+ ```
105
+
106
+ Replace both passwords in `.env`. Generate or copy the code-signing private
107
+ key before starting:
108
+
109
+ ```bash
110
+ mkdir -p secrets
111
+ cp /secure/path/code-signing-private-key.pem \
112
+ secrets/code-signing-private-key.pem
113
+ chmod 600 secrets/code-signing-private-key.pem
114
+ ```
115
+
116
+ Then start the stack:
117
+
118
+ ```bash
119
+ docker compose up -d --build
120
+ docker compose ps
121
+ ```
122
+
123
+ If port `3000` is already used, update both values in `.env`:
124
+
125
+ ```env
126
+ OTA_HTTP_PORT=3100
127
+ OTA_PUBLIC_BASE_URL=http://localhost:3100
128
+ ```
129
+
130
+ Services:
131
+
132
+ - admin and OTA server: `http://localhost:3000`;
133
+ - MinIO console: `http://localhost:9001`;
134
+ - PostgreSQL and MinIO API are available only inside the Compose network.
135
+
136
+ The private key is mounted read-only at
137
+ `/run/secrets/ota/code-signing-private-key.pem`. The public certificate belongs
138
+ in each Expo application, never in the server container.
139
+
140
+ On a fresh PostgreSQL volume, `docs/migrations/schema.sql` is applied
141
+ automatically. Create the first administrator inside the application
142
+ container:
143
+
144
+ ```bash
145
+ docker compose exec app npm run create-admin
146
+ ```
147
+
148
+ Stop without deleting data:
149
+
150
+ ```bash
151
+ docker compose down
152
+ ```
153
+
154
+ Delete the local database and object storage only when a full reset is
155
+ intended:
156
+
157
+ ```bash
158
+ docker compose down --volumes
159
+ ```
160
+
161
+ Changing `POSTGRES_PASSWORD` in `.env` does not update the role password inside
162
+ an existing PostgreSQL volume. Synchronize it without deleting data:
163
+
164
+ ```bash
165
+ npm run docker:sync-db-password
166
+ docker compose restart app
167
+ ```
168
+
169
+ ## 7. Access tokens
170
+
171
+ Access tokens are intended for CI, scripts and a future publish CLI. They are
172
+ not sent by mobile devices.
173
+
174
+ Create them through `POST /api/admin/access-tokens` while authenticated as an
175
+ `admin`. Store the returned raw token immediately; it is shown only once.
176
+
177
+ Example:
178
+
179
+ ```bash
180
+ curl \
181
+ -H "Authorization: Bearer $OTA_ACCESS_TOKEN" \
182
+ https://updates.example.com/api/admin/updates
183
+ ```
184
+
185
+ Available scopes:
186
+
187
+ - `updates:read`;
188
+ - `updates:write`;
189
+ - `redirects:read`;
190
+ - `redirects:write`.
191
+
192
+ Revoke unused or exposed tokens immediately.
193
+
194
+ ## 8. Updates and rollback
195
+
196
+ The update list is available at `/updates`.
197
+
198
+ - **Deactivate** stops serving an update.
199
+ - **Rollback** pins the channel to an older active update.
200
+ - **Promote** ends rollback mode and resumes serving the latest update.
201
+ - Do not manually edit channel pointers directly in PostgreSQL during normal
202
+ operation.
203
+
204
+ After rollback, verify both platforms and the exact runtime/channel scope.
205
+
206
+ ## 9. Emergency redirects
207
+
208
+ Rules are managed at `/updates/emergency-redirects`.
209
+
210
+ Use `pinned` first:
211
+
212
+ 1. Match the exact embedded update ID, runtime, platform and source channel.
213
+ 2. Set the correct target channel.
214
+ 3. Pin a verified recovery update ID.
215
+ 4. Confirm the affected build receives and launches the recovery OTA.
216
+ 5. Switch to `follow` so the old binary receives future target-channel
217
+ updates.
218
+
219
+ If migrating from the legacy JSON configuration:
220
+
221
+ ```bash
222
+ npm run emergency:import
223
+ ```
224
+
225
+ The manifest runtime reads only `ota_emergency_redirects` after migration.
226
+
227
+ ## 10. Backups
228
+
229
+ PostgreSQL:
230
+
231
+ ```bash
232
+ pg_dump --format=custom "$DATABASE_URL" > ota-database.dump
233
+ ```
234
+
235
+ Restore into an empty database:
236
+
237
+ ```bash
238
+ pg_restore --clean --if-exists --dbname="$DATABASE_URL" ota-database.dump
239
+ ```
240
+
241
+ Object storage must be backed up separately using the provider's replication,
242
+ versioning or S3 synchronization tools. A database backup without assets is
243
+ not sufficient to restore OTA delivery.
244
+
245
+ For Docker volumes:
246
+
247
+ ```bash
248
+ docker compose exec -T postgres \
249
+ pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" --format=custom \
250
+ > ota-database.dump
251
+ ```
252
+
253
+ ## 11. Safe upgrade order
254
+
255
+ 1. Back up PostgreSQL and object storage.
256
+ 2. Read the new migration files.
257
+ 3. Apply backward-compatible migrations.
258
+ 4. Run tests and build the new image.
259
+ 5. Deploy the application.
260
+ 6. Check `/api/health`.
261
+ 7. Verify manifest requests for production iOS and Android scopes.
262
+ 8. Keep the previous image available for application rollback.
263
+
264
+ Never deploy code that reads a new table before creating that table.
265
+
266
+ ## 12. Expo application integration
267
+
268
+ Client configuration, code-signing certificates, embedded update registration,
269
+ manual update checks and the current publish workflow are described in
270
+ [`expo-app-setup.md`](expo-app-setup.md).