create-expo-updates-server 0.3.0 → 0.6.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 (191) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +5 -10
  4. package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
  5. package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
  6. package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
  7. package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
  8. package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
  9. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
  10. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
  11. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
  13. package/dist/template/app/api/admin/updates/route.test.ts +21 -0
  14. package/dist/template/app/api/admin/updates/route.ts +12 -1
  15. package/dist/template/app/globals.css +65 -68
  16. package/dist/template/app/login/page.tsx +66 -42
  17. package/dist/template/app/updates/[encodedKey]/page.tsx +382 -248
  18. package/dist/template/app/updates/devices/page.tsx +187 -145
  19. package/dist/template/app/updates/embedded/page.tsx +80 -34
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +385 -274
  23. package/dist/template/app/updates/releases.test.tsx +156 -0
  24. package/dist/template/components/admin/admin-role.ts +5 -0
  25. package/dist/template/components/admin/admin-shell.tsx +166 -95
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +27 -16
  28. package/dist/template/components/admin/release-badges.test.tsx +50 -0
  29. package/dist/template/components/admin/release-badges.tsx +101 -0
  30. package/dist/template/components/ui/alert.tsx +10 -3
  31. package/dist/template/components/ui/avatar.tsx +108 -0
  32. package/dist/template/components/ui/badge.tsx +2 -2
  33. package/dist/template/components/ui/breadcrumb.tsx +108 -0
  34. package/dist/template/components/ui/button.tsx +5 -5
  35. package/dist/template/components/ui/card.tsx +2 -2
  36. package/dist/template/components/ui/chart.tsx +1 -1
  37. package/dist/template/components/ui/collapsible.tsx +7 -0
  38. package/dist/template/components/ui/dialog.tsx +13 -4
  39. package/dist/template/components/ui/empty.tsx +103 -0
  40. package/dist/template/components/ui/field.tsx +248 -0
  41. package/dist/template/components/ui/input-group.tsx +170 -0
  42. package/dist/template/components/ui/input.tsx +1 -1
  43. package/dist/template/components/ui/native-select.tsx +1 -1
  44. package/dist/template/components/ui/radio-group.tsx +41 -0
  45. package/dist/template/components/ui/sheet.tsx +6 -2
  46. package/dist/template/components/ui/sidebar.tsx +62 -17
  47. package/dist/template/components/ui/status-tones.ts +15 -0
  48. package/dist/template/components/ui/table.tsx +1 -1
  49. package/dist/template/components/ui/textarea.tsx +1 -1
  50. package/dist/template/docs/admin-ui.md +22 -24
  51. package/dist/template/docs/device-targeting.md +6 -12
  52. package/dist/template/docs/doctor.md +2 -2
  53. package/dist/template/docs/expo-app-setup.md +9 -27
  54. package/dist/template/docs/getting-started.md +3 -4
  55. package/dist/template/docs/getting-started.ru.md +11 -544
  56. package/dist/template/docs/index.md +1 -1
  57. package/dist/template/docs/installation-telemetry.md +6 -12
  58. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  59. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  60. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  61. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  62. package/dist/template/docs/migrations/schema.sql +349 -0
  63. package/dist/template/docs/npm-installer.md +3 -3
  64. package/dist/template/docs/operations-guide.md +9 -7
  65. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  66. package/dist/template/docs/ota-emergency-recovery.md +34 -57
  67. package/dist/template/docs/ota-update-policy.md +9 -20
  68. package/dist/template/docs/ru/admin-ui.md +33 -0
  69. package/dist/template/docs/ru/device-targeting.md +59 -0
  70. package/dist/template/docs/ru/doctor.md +98 -0
  71. package/dist/template/docs/ru/expo-app-setup.md +497 -0
  72. package/dist/template/docs/ru/getting-started.md +391 -0
  73. package/dist/template/docs/ru/index.md +50 -0
  74. package/dist/template/docs/ru/installation-telemetry.md +125 -0
  75. package/dist/template/docs/ru/npm-installer.md +71 -0
  76. package/dist/template/docs/ru/operations-guide.md +322 -0
  77. package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
  78. package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
  79. package/dist/template/docs/ru/ota-update-policy.md +69 -0
  80. package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
  81. package/dist/template/docs/ru/supabase-setup.md +120 -0
  82. package/dist/template/docs/uk/admin-ui.md +33 -0
  83. package/dist/template/docs/uk/device-targeting.md +59 -0
  84. package/dist/template/docs/uk/doctor.md +98 -0
  85. package/dist/template/docs/uk/expo-app-setup.md +497 -0
  86. package/dist/template/docs/uk/getting-started.md +391 -0
  87. package/dist/template/docs/uk/index.md +50 -0
  88. package/dist/template/docs/uk/installation-telemetry.md +125 -0
  89. package/dist/template/docs/uk/npm-installer.md +71 -0
  90. package/dist/template/docs/uk/operations-guide.md +322 -0
  91. package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
  92. package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
  93. package/dist/template/docs/uk/ota-update-policy.md +69 -0
  94. package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
  95. package/dist/template/docs/uk/supabase-setup.md +120 -0
  96. package/dist/template/lib/audience-ids.ts +4 -0
  97. package/dist/template/package-lock.json +46 -0
  98. package/dist/template/package.json +4 -1
  99. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  100. package/dist/template/scripts/create-access-token.mjs +1 -1
  101. package/dist/template/scripts/lib/doctor.mjs +10 -7
  102. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  103. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  104. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  105. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  106. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  107. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  108. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  109. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  110. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  111. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  112. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  113. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  114. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  115. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  116. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  117. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  118. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  119. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  120. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  121. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  122. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  123. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  124. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  125. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  126. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  127. package/dist/template/src/client/admin-api.ts +45 -10
  128. package/dist/template/src/client/admin-types.ts +35 -1
  129. package/dist/template/src/client/devices/analytics.tsx +169 -219
  130. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  131. package/dist/template/src/client/devices/device-name.tsx +37 -21
  132. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  133. package/dist/template/src/client/devices/registry.tsx +265 -233
  134. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  135. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  136. package/dist/template/src/client/devices/version-adoption-chart.tsx +48 -38
  137. package/dist/template/src/client/distribution-control.tsx +98 -53
  138. package/dist/template/src/client/distribution-history.tsx +353 -0
  139. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  140. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  141. package/dist/template/src/client/guard-action-combobox.tsx +134 -234
  142. package/dist/template/src/client/guard-action-options.ts +4 -6
  143. package/dist/template/src/client/i18n/en.json +335 -2
  144. package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
  145. package/dist/template/src/client/i18n/messages.test.ts +102 -19
  146. package/dist/template/src/client/i18n/messages.ts +31 -16
  147. package/dist/template/src/client/i18n/provider.tsx +6 -3
  148. package/dist/template/src/client/i18n/ru.json +619 -0
  149. package/dist/template/src/client/i18n/uk.json +619 -0
  150. package/dist/template/src/client/i18n/use-formatters.ts +5 -0
  151. package/dist/template/src/client/logout-button.tsx +3 -3
  152. package/dist/template/src/client/policy-draft.ts +138 -0
  153. package/dist/template/src/client/update-audience-editor.tsx +597 -199
  154. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  155. package/dist/template/src/client/update-policy-editor.tsx +466 -307
  156. package/dist/template/src/client/use-filtered-results.ts +55 -0
  157. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  158. package/dist/template/src/server/controllers/manifest.ts +15 -1
  159. package/dist/template/src/server/devices/audience.ts +9 -5
  160. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  161. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  162. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  163. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  164. package/dist/template/src/server/lib/supabase.js +24 -0
  165. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  166. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  167. package/dist/template/src/server/lib/update-policy.ts +23 -10
  168. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  169. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  170. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  171. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  172. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  173. package/dist/template/tsconfig.json +2 -2
  174. package/dist/template-manifest.json +571 -271
  175. package/package.json +1 -1
  176. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  177. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  178. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  179. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  180. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  181. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  182. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  183. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  184. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  185. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  186. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  187. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  188. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  189. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  190. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  191. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -0,0 +1,97 @@
1
+ import { supabase } from "./supabase.js";
2
+ import { OtaDistributionBlockedError } from "./distribution-control";
3
+
4
+ type Release = {
5
+ updateId: string;
6
+ appVersion: string | null;
7
+ comment: string | null;
8
+ createdAt: string;
9
+ activatedAt: string | null;
10
+ };
11
+
12
+ type HistoryRow = {
13
+ id: number;
14
+ runtime_version: string;
15
+ channel: string;
16
+ platform: "ios" | "android";
17
+ revision: string;
18
+ current_release: Release | null;
19
+ previous_release: Release | null;
20
+ };
21
+
22
+ function releaseLink(release: Release | null) {
23
+ return (
24
+ release && {
25
+ ...release,
26
+ encodedKey: Buffer.from(release.updateId).toString("base64url"),
27
+ }
28
+ );
29
+ }
30
+
31
+ export async function getDistributionHistory() {
32
+ const scopes: Array<{
33
+ runtimeVersion: string;
34
+ platform: HistoryRow["platform"];
35
+ channel: string;
36
+ revision: string;
37
+ current: ReturnType<typeof releaseLink>;
38
+ previous: ReturnType<typeof releaseLink>;
39
+ }> = [];
40
+ let cursor = 0;
41
+ for (;;) {
42
+ const { data, error } = await supabase
43
+ .from("ota_distribution_history")
44
+ .select(
45
+ "id,runtime_version,channel,platform,revision,current_release,previous_release",
46
+ )
47
+ .neq("revision", "0")
48
+ .gt("id", cursor)
49
+ .order("id")
50
+ .limit(200)
51
+ .execute();
52
+ if (error) throw new Error(error.message);
53
+ const rows = (data ?? []) as HistoryRow[];
54
+ if (!rows.length) return scopes;
55
+ for (const row of rows)
56
+ scopes.push({
57
+ runtimeVersion: row.runtime_version,
58
+ channel: row.channel,
59
+ platform: row.platform,
60
+ revision: row.revision,
61
+ current: releaseLink(row.current_release),
62
+ previous: releaseLink(row.previous_release),
63
+ });
64
+ cursor = rows[rows.length - 1].id;
65
+ }
66
+ }
67
+
68
+ export class DistributionHistoryConflictError extends Error {}
69
+
70
+ export async function changeDistribution(
71
+ updateId: string,
72
+ action:
73
+ | "activate"
74
+ | "stop"
75
+ | "restore"
76
+ | "rollback"
77
+ | "promote"
78
+ | "select-latest"
79
+ | "retire"
80
+ | "delete",
81
+ revision: string | null = null,
82
+ ) {
83
+ const { data, error } = await supabase.rpc("ota_change_distribution", {
84
+ p_update: updateId,
85
+ p_action: action,
86
+ p_revision: revision,
87
+ });
88
+ if (error?.message.includes("OTA_DISTRIBUTION_BLOCKED"))
89
+ throw new OtaDistributionBlockedError();
90
+ if (error?.message.includes("DISTRIBUTION_CONFLICT:"))
91
+ throw new DistributionHistoryConflictError(
92
+ error.message.split("DISTRIBUTION_CONFLICT:")[1].trim(),
93
+ );
94
+ if (error || !data?.[0]?.result)
95
+ throw new Error(error?.message || "Missing distribution result.");
96
+ return data[0].result;
97
+ }
@@ -160,6 +160,13 @@ function toSqlColumns(columns) {
160
160
  .split(",")
161
161
  .map((part) => part.trim())
162
162
  .filter(Boolean)
163
+ .map((part) => {
164
+ if (!part.includes(":")) return part;
165
+ // Match PostgREST's alias:json_column->key syntax using literal keys.
166
+ const [alias, expression] = part.split(":");
167
+ const [column, ...keys] = expression.split("->").map(assertSqlIdentifier);
168
+ return `${column}${keys.map((key) => `->'${key}'`).join("")} AS ${assertSqlIdentifier(alias)}`;
169
+ })
163
170
  .join(", ");
164
171
  }
165
172
 
@@ -217,6 +224,11 @@ class TableQuery {
217
224
  return this;
218
225
  }
219
226
 
227
+ gt(column, value) {
228
+ this.filters.push({ type: "gt", column, value });
229
+ return this;
230
+ }
231
+
220
232
  is(column, value) {
221
233
  this.filters.push({ type: "is", column, value });
222
234
  return this;
@@ -295,6 +307,13 @@ class TableQuery {
295
307
  continue;
296
308
  }
297
309
 
310
+ if (filter.type === "gt") {
311
+ conditions.push(`${assertSqlIdentifier(filter.column)} > $${index}`);
312
+ params.push(filter.value);
313
+ index += 1;
314
+ continue;
315
+ }
316
+
298
317
  if (filter.type === "neq") {
299
318
  if (isNullLike(filter.value)) {
300
319
  conditions.push(`${filter.column} IS NOT NULL`);
@@ -710,6 +729,11 @@ class SupabaseTableQuery {
710
729
  return this;
711
730
  }
712
731
 
732
+ gt(column, value) {
733
+ this.builder = this.builder.gt(column, value);
734
+ return this;
735
+ }
736
+
713
737
  is(column, value) {
714
738
  this.builder = this.builder.is(column, value);
715
739
  return this;
@@ -11,6 +11,8 @@ const poolQuery = vi.hoisted(() =>
11
11
  );
12
12
  const supabaseUpdate = vi.hoisted(() => vi.fn());
13
13
  const supabaseUpsert = vi.hoisted(() => vi.fn());
14
+ const supabaseCursor = vi.hoisted(() => vi.fn());
15
+ const supabaseSelect = vi.hoisted(() => vi.fn());
14
16
 
15
17
  const supabaseBuilder = vi.hoisted(() => {
16
18
  const builder = {
@@ -25,7 +27,12 @@ const supabaseBuilder = vi.hoisted(() => {
25
27
  eq() {
26
28
  return builder;
27
29
  },
28
- select() {
30
+ select(columns: string) {
31
+ supabaseSelect(columns);
32
+ return builder;
33
+ },
34
+ gt(key: string, cursor: string) {
35
+ supabaseCursor(key, cursor);
29
36
  return builder;
30
37
  },
31
38
  maybeSingle() {
@@ -149,6 +156,36 @@ describe("common database abstraction", () => {
149
156
  );
150
157
  });
151
158
 
159
+ it("selects only release version fields and advances the PostgreSQL cursor", async () => {
160
+ const { supabase } = await import("./supabase.js");
161
+ await supabase
162
+ .from("ota_updates")
163
+ .select("id,app_version:manifest->extra->expoClient->version")
164
+ .gt("id", "last-id")
165
+ .order("id")
166
+ .limit(200)
167
+ .execute();
168
+ expect(poolQuery).toHaveBeenCalledWith(
169
+ "SELECT id, manifest->'extra'->'expoClient'->'version' AS app_version FROM ota_updates WHERE id > $1 ORDER BY id ASC NULLS LAST LIMIT $2",
170
+ ["last-id", 200],
171
+ );
172
+ });
173
+
174
+ it("forwards the release projection and cursor to PostgREST", async () => {
175
+ process.env.DATABASE_PROVIDER = "supabase";
176
+ process.env.SUPABASE_URL = "https://example.supabase.co";
177
+ process.env.SUPABASE_SERVICE_ROLE_KEY = "test-key";
178
+ const { supabase } = await import("./supabase.js");
179
+ const columns = "id,app_version:manifest->extra->expoClient->version";
180
+ await supabase
181
+ .from("ota_updates")
182
+ .select(columns)
183
+ .gt("id", "last-id")
184
+ .execute();
185
+ expect(supabaseSelect).toHaveBeenCalledWith(columns);
186
+ expect(supabaseCursor).toHaveBeenCalledWith("id", "last-id");
187
+ });
188
+
152
189
  it("unwraps JSONB payloads for Supabase without changing plain arrays", async () => {
153
190
  const payload = { message: "Ready" };
154
191
  vi.resetModules();
@@ -41,6 +41,26 @@ describe("simple update policy", () => {
41
41
  },
42
42
  );
43
43
 
44
+ it("keeps manual delivery compatible and only attaches the postpone hint to unguarded updates", () => {
45
+ expect(
46
+ createManifestUpdatePolicy({
47
+ delivery: "manual-postpone",
48
+ guard: null,
49
+ policyVersion: 2,
50
+ }),
51
+ ).toEqual({
52
+ schemaVersion: 1,
53
+ policyVersion: 2,
54
+ delivery: "manual",
55
+ onPostpone: "download",
56
+ });
57
+ expect(() =>
58
+ validateUpdatePolicy({
59
+ delivery: "manual-postpone",
60
+ guard: { action: "ota-force-update" },
61
+ }),
62
+ ).toThrow();
63
+ });
44
64
  it("rejects payload without an action", () => {
45
65
  expect(() =>
46
66
  validateUpdatePolicy({
@@ -1,6 +1,6 @@
1
1
  export const UPDATE_POLICY_SCHEMA_VERSION = 1 as const;
2
2
 
3
- export type UpdateDeliveryMode = "manual" | "background";
3
+ export type UpdateDeliveryMode = "manual" | "background" | "manual-postpone";
4
4
  export type UpdatePolicyGuard = {
5
5
  action: string;
6
6
  payload?: unknown;
@@ -12,7 +12,8 @@ export type UpdatePolicyInput = {
12
12
  export type ManifestUpdatePolicy = {
13
13
  schemaVersion: 1;
14
14
  policyVersion: number;
15
- delivery: UpdateDeliveryMode;
15
+ delivery: "manual" | "background";
16
+ onPostpone?: "download";
16
17
  guard?: UpdatePolicyGuard;
17
18
  };
18
19
 
@@ -36,11 +37,7 @@ function isObject(value: unknown): value is Record<string, unknown> {
36
37
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
37
38
  }
38
39
 
39
- function validateJsonValue(
40
- value: unknown,
41
- path: string,
42
- depth = 0,
43
- ): void {
40
+ function validateJsonValue(value: unknown, path: string, depth = 0): void {
44
41
  if (depth > MAX_PAYLOAD_DEPTH) {
45
42
  fail(path, `JSON depth must not exceed ${MAX_PAYLOAD_DEPTH}`);
46
43
  }
@@ -88,8 +85,12 @@ function validatePayload(payload: unknown): void {
88
85
 
89
86
  export function validateUpdatePolicy(value: unknown): UpdatePolicyInput {
90
87
  if (!isObject(value)) fail("policy", "must be an object");
91
- if (value.delivery !== "manual" && value.delivery !== "background") {
92
- fail("policy.delivery", "must be manual or background");
88
+ if (
89
+ value.delivery !== "manual" &&
90
+ value.delivery !== "background" &&
91
+ value.delivery !== "manual-postpone"
92
+ ) {
93
+ fail("policy.delivery", "must be manual, manual-postpone or background");
93
94
  }
94
95
 
95
96
  if (value.guard === null) {
@@ -109,6 +110,12 @@ export function validateUpdatePolicy(value: unknown): UpdatePolicyInput {
109
110
  }
110
111
  return { delivery: value.delivery, guard: null };
111
112
  }
113
+ if (value.delivery === "manual-postpone") {
114
+ fail(
115
+ "policy.guard",
116
+ "manual-postpone requires an optional update without a guard",
117
+ );
118
+ }
112
119
  if (
113
120
  action !== action.trim() ||
114
121
  Array.from(action).length > MAX_ACTION_LENGTH ||
@@ -154,7 +161,13 @@ export function createManifestUpdatePolicy({
154
161
  return {
155
162
  schemaVersion: UPDATE_POLICY_SCHEMA_VERSION,
156
163
  policyVersion: policyVersion as number,
157
- delivery: validated.delivery,
164
+ delivery:
165
+ validated.delivery === "manual-postpone"
166
+ ? "manual"
167
+ : validated.delivery,
168
+ ...(validated.delivery === "manual-postpone"
169
+ ? { onPostpone: "download" as const }
170
+ : {}),
158
171
  ...(validated.guard ? { guard: validated.guard } : {}),
159
172
  };
160
173
  } catch (error: unknown) {
@@ -164,8 +164,16 @@ async function resolveDeviceUpdateRow(
164
164
  return getUpdateByUpdateId(resolvedUpdateId);
165
165
  }
166
166
 
167
- function toEmbeddedUpdateMeta(updateRow: OtaUpdateRow): EmbeddedUpdateMeta {
167
+ type DeviceBaselineMeta = EmbeddedUpdateMeta & {
168
+ ota?: Pick<OtaUpdateRow, "is_active" | "runtime_version">;
169
+ };
170
+
171
+ function toDeviceBaselineMeta(updateRow: OtaUpdateRow): DeviceBaselineMeta {
168
172
  return {
173
+ ota: {
174
+ is_active: updateRow.is_active,
175
+ runtime_version: updateRow.runtime_version,
176
+ },
169
177
  embedded_update_id: updateRow.update_id,
170
178
  created_at: updateRow.created_at,
171
179
  channel: updateRow.channel,
@@ -176,10 +184,10 @@ function toEmbeddedUpdateMeta(updateRow: OtaUpdateRow): EmbeddedUpdateMeta {
176
184
 
177
185
  export async function resolveDeviceBaselineMeta(
178
186
  deviceUpdateId: string,
179
- ): Promise<EmbeddedUpdateMeta | null> {
187
+ ): Promise<DeviceBaselineMeta | null> {
180
188
  const otaUpdate = await resolveDeviceUpdateRow(deviceUpdateId);
181
189
  return otaUpdate
182
- ? toEmbeddedUpdateMeta(otaUpdate)
190
+ ? toDeviceBaselineMeta(otaUpdate)
183
191
  : getEmbeddedUpdateMetaById(deviceUpdateId);
184
192
  }
185
193
 
@@ -6,6 +6,8 @@ import {
6
6
 
7
7
  describe("compareAppVersions", () => {
8
8
  it.each([
9
+ ["0.1.1", "0.1.0", 1],
10
+ ["0.0.1", "1", -1],
9
11
  ["1.7.11", "1.7.10", 1],
10
12
  ["1.10", "1.9", 1],
11
13
  ["1.0.0", "1", 0],
@@ -13,6 +13,16 @@ export function debugString(value: string | null | undefined): string {
13
13
  return normalizeId(value) || "none";
14
14
  }
15
15
 
16
+ export function getAppVersionFromFields(
17
+ preferred: unknown,
18
+ legacy: unknown,
19
+ ): string | null {
20
+ for (const value of [preferred, legacy]) {
21
+ if (typeof value === "string" && value.trim()) return value.trim();
22
+ }
23
+ return null;
24
+ }
25
+
16
26
  export function getManifestAppVersion(manifest: unknown): string | null {
17
27
  if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) {
18
28
  return null;
@@ -25,20 +35,18 @@ export function getManifestAppVersion(manifest: unknown): string | null {
25
35
  !Array.isArray(manifestRecord.extra)
26
36
  ? (manifestRecord.extra as Record<string, unknown>)
27
37
  : null;
28
- for (const expoClient of [extra?.expoClient, manifestRecord.expoClient]) {
29
- if (
30
- expoClient &&
38
+ function version(expoClient: unknown) {
39
+ return expoClient &&
31
40
  typeof expoClient === "object" &&
32
- !Array.isArray(expoClient)
33
- ) {
34
- const version = (expoClient as Record<string, unknown>).version;
35
- if (typeof version === "string" && version.trim()) {
36
- return version.trim();
37
- }
38
- }
41
+ !Array.isArray(expoClient) &&
42
+ "version" in expoClient
43
+ ? expoClient.version
44
+ : null;
39
45
  }
40
-
41
- return null;
46
+ return getAppVersionFromFields(
47
+ version(extra?.expoClient),
48
+ version(manifestRecord.expoClient),
49
+ );
42
50
  }
43
51
 
44
52
  type ParsedAppVersion = {
@@ -49,7 +57,7 @@ type ParsedAppVersion = {
49
57
  function parseAppVersion(value: string): ParsedAppVersion | null {
50
58
  const normalized = value.trim();
51
59
  const match =
52
- /^(0|[1-9]\d*(?:\.(?:0|[1-9]\d*))*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
60
+ /^((?:0|[1-9]\d*)(?:\.(?:0|[1-9]\d*))*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
53
61
  normalized,
54
62
  );
55
63
  if (!match) {
@@ -29,20 +29,7 @@ export async function writeDatabaseRecords(pool, update, latest) {
29
29
  false, $5, $9, $10, $11,
30
30
  $12::jsonb
31
31
  )
32
- ON CONFLICT (id) DO UPDATE SET
33
- runtime_version = EXCLUDED.runtime_version,
34
- channel = EXCLUDED.channel,
35
- platform = EXCLUDED.platform,
36
- created_at = EXCLUDED.created_at,
37
- created_at_path = EXCLUDED.created_at_path,
38
- storage_bucket = EXCLUDED.storage_bucket,
39
- storage_base_path = EXCLUDED.storage_base_path,
40
- is_active = false,
41
- disabled_at = EXCLUDED.disabled_at,
42
- assets_count = EXCLUDED.assets_count,
43
- launch_asset_path = EXCLUDED.launch_asset_path,
44
- comment = EXCLUDED.comment,
45
- manifest = EXCLUDED.manifest`,
32
+ ON CONFLICT (id) DO NOTHING`,
46
33
  [
47
34
  update.id,
48
35
  update.runtimeVersion,
@@ -58,23 +45,13 @@ export async function writeDatabaseRecords(pool, update, latest) {
58
45
  JSON.stringify(update),
59
46
  ],
60
47
  );
48
+ // Retrying a publication must never disable an activated artifact or
49
+ // move serving pointers. A new scope starts empty until activation.
61
50
  await client.query(
62
- `INSERT INTO ota_update_channels (
63
- runtime_version, channel, platform,
64
- latest_update_id, latest_created_at, latest_created_at_path
65
- ) VALUES ($1, $2, $3, $4, $5, $6)
66
- ON CONFLICT (runtime_version, channel, platform) DO UPDATE SET
67
- latest_update_id = EXCLUDED.latest_update_id,
68
- latest_created_at = EXCLUDED.latest_created_at,
69
- latest_created_at_path = EXCLUDED.latest_created_at_path`,
70
- [
71
- latest.runtimeVersion,
72
- latest.channel,
73
- latest.platform,
74
- latest.updateId,
75
- latest.createdAt,
76
- latest.createdAtPath,
77
- ],
51
+ `INSERT INTO ota_update_channels (runtime_version, channel, platform)
52
+ VALUES ($1, $2, $3)
53
+ ON CONFLICT (runtime_version, channel, platform) DO NOTHING`,
54
+ [latest.runtimeVersion, latest.channel, latest.platform],
78
55
  );
79
56
  await client.query("COMMIT");
80
57
  } catch (error) {
@@ -313,7 +313,8 @@ async function main() {
313
313
  );
314
314
  }
315
315
 
316
- if (process.argv[1] === fileURLToPath(import.meta.url)) {
316
+ if (process.argv[1] && fs.existsSync(process.argv[1]) &&
317
+ fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url))) {
317
318
  main().catch((error) => {
318
319
  console.error(`Embedded update registration failed: ${error.message}`);
319
320
  process.exitCode = 1;
@@ -35,7 +35,7 @@
35
35
  "exclude": [
36
36
  "node_modules",
37
37
  "packages/create-expo-updates-server/dist",
38
- "templates/expo-app/ota-client",
39
- "scripts/lib/ota-updates-ui.test.tsx"
38
+ "packages/ota-client/src",
39
+ "packages/ota-client/test/ota-updates-ui.test.tsx"
40
40
  ]
41
41
  }