@hot-updater/cloudflare 1.2.0-rc.42 → 1.2.0-rc.44

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/cloudflare",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.42",
4
+ "version": "1.2.0-rc.44",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -52,11 +52,11 @@
52
52
  "cloudflare": "4.2.0",
53
53
  "hono": "4.12.34",
54
54
  "uuidv7": "^1.0.2",
55
- "@hot-updater/cli-tools": "1.2.0-rc.42",
56
- "@hot-updater/protocol": "1.2.0-rc.42",
57
- "@hot-updater/server": "1.2.0-rc.42",
58
- "@hot-updater/plugin-core": "1.2.0-rc.42",
59
- "@hot-updater/storage-s3": "1.2.0-rc.42"
55
+ "@hot-updater/cli-tools": "1.2.0-rc.44",
56
+ "@hot-updater/plugin-core": "1.2.0-rc.44",
57
+ "@hot-updater/protocol": "1.2.0-rc.44",
58
+ "@hot-updater/server": "1.2.0-rc.44",
59
+ "@hot-updater/storage-s3": "1.2.0-rc.44"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@aws-sdk/client-s3": "3.1066.0",
@@ -75,7 +75,7 @@
75
75
  "vitest": "4.1.4",
76
76
  "wrangler": "^4.69.0",
77
77
  "xdg-app-paths": "^8.3.0",
78
- "@hot-updater/test-utils": "1.2.0-rc.42"
78
+ "@hot-updater/test-utils": "1.2.0-rc.44"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsdown && pnpm build:worker",
package/sql/bundles.sql CHANGED
@@ -42,6 +42,8 @@ CREATE INDEX IF NOT EXISTS "native_builds_byScope" ON "native_builds" ("scope_ke
42
42
 
43
43
  CREATE INDEX IF NOT EXISTS "native_builds_byBuildKey" ON "native_builds" ("scope_key", "build_key", "id");
44
44
 
45
+ CREATE INDEX IF NOT EXISTS "native_builds_byScopeKind" ON "native_builds" ("scope_key", "artifact_kind", "id");
46
+
45
47
  CREATE UNIQUE INDEX IF NOT EXISTS "native_builds_byStoreBuild" ON "native_builds" ("store_build_scope_key");
46
48
 
47
49
  CREATE INDEX IF NOT EXISTS "native_builds_byChannel" ON "native_builds" ("channel_id", "id");
@@ -62,6 +64,8 @@ CREATE INDEX IF NOT EXISTS "bundle_events_movementsByInstall" ON "bundle_events"
62
64
 
63
65
  CREATE TABLE IF NOT EXISTS "bundle_events__byBundle" ("platform" TEXT NOT NULL, "channel" TEXT NOT NULL, "type" TEXT NOT NULL, "bundle_ref" TEXT NOT NULL, "day" INTEGER NOT NULL, "received_at_ms" INTEGER NOT NULL, "id" TEXT NOT NULL, PRIMARY KEY ("platform", "channel", "type", "bundle_ref", "day", "received_at_ms", "id"));
64
66
 
67
+ CREATE INDEX IF NOT EXISTS "bundle_events__byBundle__key" ON "bundle_events__byBundle" ("id");
68
+
65
69
  CREATE INDEX IF NOT EXISTS "bundle_events_byDay" ON "bundle_events" ("day", "received_at_ms", "id");
66
70
 
67
71
  CREATE TABLE IF NOT EXISTS "bundle_event_heads" ("install_id" TEXT NOT NULL, "id" TEXT NOT NULL, "type" TEXT NOT NULL, "user_id" TEXT, "from_release_id" TEXT, "from_bundle_id" TEXT, "to_release_id" TEXT, "to_bundle_id" TEXT NOT NULL, "platform" TEXT NOT NULL, "app_version" TEXT NOT NULL, "channel" TEXT NOT NULL, "metadata" TEXT NOT NULL, "received_at_ms" INTEGER NOT NULL, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("install_id"));
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2026-11-13T12:43:17.237Z.
1
+ This folder contains the built output assets for the worker "hot-updater" generated at 2026-11-14T13:37:26.058Z.
@@ -2194,7 +2194,12 @@ var sqlTableShapes = /* @__PURE__ */ __name((dialect, tables, tablePrefix = "")
2194
2194
  name: `${name}__${index.name}`,
2195
2195
  columns: entries,
2196
2196
  key: columns,
2197
- indexes: []
2197
+ indexes: [{
2198
+ kind: "index",
2199
+ name: shortSqlName(`${name}__${index.name}__key`),
2200
+ unique: false,
2201
+ columns: table.key
2202
+ }]
2198
2203
  }
2199
2204
  }];
2200
2205
  }
@@ -2264,9 +2269,17 @@ var pruneStatements = /* @__PURE__ */ __name((dialect, table, tablePrefix, limit
2264
2269
  const order = retentionOrder(table).columns.map(quote);
2265
2270
  const list = /* @__PURE__ */ __name((alias, direction = "") => order.map((column) => `${alias}.${column}${direction}`).join(", "), "list");
2266
2271
  const oldest = /* @__PURE__ */ __name((before) => `SELECT ${list("i")} FROM ${name} i WHERE i.${at} <= ${before()} ORDER BY ${list("i", " ASC")} LIMIT ${limit}`, "oldest");
2267
- const doomed = /* @__PURE__ */ __name((alias, before) => `${alias}.${at} <= ${before()} AND (${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1)`, "doomed");
2272
+ const doomed = /* @__PURE__ */ __name((alias, before) => `(${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1) AND ${alias}.${at} <= ${before()}`, "doomed");
2268
2273
  const entries = table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => quote(`${tablePrefix}${table.name}__${index.name}`));
2269
2274
  const keyOf = /* @__PURE__ */ __name((left, right) => table.key.map((column) => `${left}.${quote(column)} = ${right}.${quote(column)}`).join(" AND "), "keyOf");
2275
+ if (dialect === "sqlite") return [...table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => {
2276
+ const columns = [...index.eq, ...indexOrderColumns(table, index)];
2277
+ const multi = columns.filter((column) => findPhysicalColumn(table, column).multi);
2278
+ const values = columns.map((column) => multi.includes(column) ? `j${multi.indexOf(column)}.${quote("value")}` : `b.${quote(column)}`);
2279
+ const each = multi.map((column, at2) => `, json_each(b.${quote(column)}) j${at2}`);
2280
+ const into = quote(`${tablePrefix}${table.name}__${index.name}`);
2281
+ return (before) => `DELETE FROM ${into} WHERE (${columns.map(quote).join(", ")}) IN (SELECT ${values.join(", ")} FROM ${name} b${each.join("")} WHERE ${doomed("b", before)})`;
2282
+ }), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
2270
2283
  if (dialect === "mysql") return [...entries.map((index) => (before) => `DELETE e FROM ${index} e JOIN (${oldest(before)}) d ON ${keyOf("e", "d")}`), (before) => `DELETE FROM ${name} WHERE ${at} <= ${before()} ORDER BY ${order.join(", ")} LIMIT ${limit}`];
2271
2284
  return [...entries.map((index) => (before) => `DELETE FROM ${index} WHERE EXISTS (SELECT * FROM ${name} b WHERE ${keyOf("b", index)} AND ${doomed("b", before)})`), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
2272
2285
  }, "pruneStatements");
@@ -2638,6 +2651,10 @@ var nativeBuilds = defineTable({
2638
2651
  eq: ["scope_key", "build_key"],
2639
2652
  sort: ["id"]
2640
2653
  },
2654
+ byScopeKind: {
2655
+ eq: ["scope_key", "artifact_kind"],
2656
+ sort: ["id"]
2657
+ },
2641
2658
  byStoreBuild: {
2642
2659
  eq: ["store_build_scope_key"],
2643
2660
  sort: [],
@@ -4500,20 +4517,20 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4500
4517
  const where = /* @__PURE__ */ __name((bind, key, v) => `${keyMatch(bind, table, key)}${v === void 0 ? "" : ` AND ${version2} = ${bind(v)}`}${when ? ` AND ${when(bind)}` : ""}`, "where");
4501
4518
  const insert = /* @__PURE__ */ __name((bind, into, columns, values) => `INSERT INTO ${into} (${columns.map(quote).join(", ")}) ${when ? `SELECT ${values.join(", ")} WHERE ${when(bind)}` : `VALUES (${values.join(", ")})`}`, "insert");
4502
4519
  const insertRow = /* @__PURE__ */ __name((bind, row) => insert(bind, name, table.columns.map((column) => column.name), table.columns.map((column) => bind(row[column.name], column))), "insertRow");
4503
- const entries = /* @__PURE__ */ __name((key, row, changed) => table.indexes.flatMap((index) => {
4520
+ const entries = /* @__PURE__ */ __name((key, row, changed, stale = true) => table.indexes.flatMap((index) => {
4504
4521
  const columns = [...index.eq, ...indexOrderColumns(table, index)];
4505
4522
  if (!isMultiIndex(table, index) || changed && !columns.some((column) => changed.includes(column))) return [];
4506
4523
  const into = tableOf(table, index);
4507
4524
  const found = row ? indexEntries(table, index, row) : [];
4508
4525
  const order = found.length > 0 ? indexOrderTuple(table, index, row) : [];
4509
- return [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`), ...found.map((eq) => sql((bind) => {
4526
+ return [...stale ? [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`)] : [], ...found.map((eq) => sql((bind) => {
4510
4527
  const values = [...eq, ...order].map((value) => bind(value));
4511
4528
  return insert(bind, into, columns, values);
4512
4529
  }))];
4513
4530
  }), "entries");
4514
4531
  switch (op.type) {
4515
4532
  case "insert":
4516
- return [sql((bind) => insertRow(bind, op.row)), ...entries(rowKey(table, op.row), op.row)];
4533
+ return [sql((bind) => insertRow(bind, op.row)), ...entries(rowKey(table, op.row), op.row, void 0, false)];
4517
4534
  case "patch":
4518
4535
  return [sql((bind) => {
4519
4536
  const set = Object.entries(op.set).map(([column, value]) => `${quote(column)} = ${bind(value, findPhysicalColumn(table, column))}`);
@@ -4672,7 +4689,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4672
4689
  }, "createSqlAdapter");
4673
4690
 
4674
4691
  // ../../packages/server/dist/package.mjs
4675
- var version = "1.2.0-rc.42";
4692
+ var version = "1.2.0-rc.44";
4676
4693
 
4677
4694
  // ../../packages/server/dist/version.mjs
4678
4695
  var HOT_UPDATER_SERVER_VERSION = version;
@@ -6268,6 +6285,39 @@ var problemOf = /* @__PURE__ */ __name(({ id, minBundleId, platform, channel, fi
6268
6285
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
6269
6286
  return null;
6270
6287
  }, "problemOf");
6288
+ var SIBLING_KINDS = {
6289
+ app: "ipa",
6290
+ ipa: "app"
6291
+ };
6292
+ var isInstallTarget = /* @__PURE__ */ __name((build) => !build.is_store_build && build.submitted_to === null && (build.artifact_kind === "app" || build.artifact_kind === "ipa" && build.export_method !== null && build.export_method !== "app-store"), "isInstallTarget");
6293
+ var siblingSandboxScopeKey = /* @__PURE__ */ __name((build, artifactKind) => {
6294
+ const [version2, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
6295
+ if (version2 !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
6296
+ const target = build.fingerprint_hash === null ? {
6297
+ platform: build.platform,
6298
+ fingerprintHash: null,
6299
+ appVersion: build.app_version ?? ""
6300
+ } : {
6301
+ platform: build.platform,
6302
+ fingerprintHash: build.fingerprint_hash,
6303
+ appVersion: null
6304
+ };
6305
+ try {
6306
+ return sandboxScopeKey(target, {
6307
+ appId,
6308
+ urlScheme,
6309
+ artifactKind: build.artifact_kind,
6310
+ distribution: registeredDistribution(build.artifact_kind, build.export_method)
6311
+ }) === build.scope_key ? sandboxScopeKey(target, {
6312
+ appId,
6313
+ urlScheme,
6314
+ artifactKind,
6315
+ distribution: "direct"
6316
+ }) : null;
6317
+ } catch {
6318
+ return null;
6319
+ }
6320
+ }, "siblingSandboxScopeKey");
6271
6321
  var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {}) => ({
6272
6322
  async registerNativeBuild(registration) {
6273
6323
  const problem = problemOf(registration);
@@ -6335,9 +6385,12 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6335
6385
  const scopeKey = nativeBuildScopeKey(scope);
6336
6386
  const buildKey = options?.buildKey;
6337
6387
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
6388
+ const artifactKind = options?.artifactKind;
6389
+ if (artifactKind !== void 0 && !ARTIFACT_KINDS[scope.platform].includes(artifactKind)) throw new NativeBuildInputError(`Invalid native build kind: an ${scope.platform} build is ${ARTIFACT_KINDS[scope.platform].join(" or ")}.`);
6390
+ const ofKind = /* @__PURE__ */ __name((row) => artifactKind === void 0 || row.artifact_kind === artifactKind, "ofKind");
6338
6391
  if (options?.storeBuild) {
6339
6392
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
6340
- return marked === null ? null : pick3(marked);
6393
+ return marked === null || !ofKind(marked) ? null : pick3(marked);
6341
6394
  }
6342
6395
  const read = /* @__PURE__ */ __name((limit, before) => {
6343
6396
  const page2 = {
@@ -6345,34 +6398,60 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6345
6398
  limit,
6346
6399
  ...before === void 0 ? {} : { range: { lt: before } }
6347
6400
  };
6348
- return buildKey === void 0 ? db.findMany("native_builds", {
6349
- index: "byScope",
6350
- where: { scope_key: scopeKey },
6351
- ...page2
6352
- }) : db.findMany("native_builds", {
6401
+ return buildKey !== void 0 ? db.findMany("native_builds", {
6353
6402
  index: "byBuildKey",
6354
6403
  where: {
6355
6404
  scope_key: scopeKey,
6356
6405
  build_key: buildKey
6357
6406
  },
6358
6407
  ...page2
6408
+ }) : artifactKind !== void 0 ? db.findMany("native_builds", {
6409
+ index: "byScopeKind",
6410
+ where: {
6411
+ scope_key: scopeKey,
6412
+ artifact_kind: artifactKind
6413
+ },
6414
+ ...page2
6415
+ }) : db.findMany("native_builds", {
6416
+ index: "byScope",
6417
+ where: { scope_key: scopeKey },
6418
+ ...page2
6359
6419
  });
6360
6420
  }, "read");
6361
6421
  const bundleId = options?.builtInOlderThan;
6362
6422
  if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
6363
6423
  const { rows } = await read(1);
6364
- const newest = rows[0];
6365
- if (newest === void 0) return null;
6366
- if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick3(newest);
6424
+ const newest = (rows[0] === void 0 ? void 0 : pick3(rows[0])) ?? (artifactKind !== void 0 && buildKey === void 0 ? await db.findMany("native_builds", {
6425
+ index: "byScope",
6426
+ where: { scope_key: scopeKey },
6427
+ order: "desc",
6428
+ limit: 1
6429
+ }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick3(row) : void 0) : void 0);
6430
+ if (newest === void 0 || !ofKind(newest)) return null;
6431
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
6367
6432
  for (let before = newest.id; ; ) {
6368
6433
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
6369
6434
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
6370
- if (usable !== void 0) return pick3(usable);
6435
+ if (usable !== void 0) return ofKind(usable) ? pick3(usable) : null;
6371
6436
  const last = older.at(-1);
6372
6437
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
6373
6438
  before = last.id;
6374
6439
  }
6375
6440
  },
6441
+ async findNativeBuildSibling(build) {
6442
+ const artifactKind = SIBLING_KINDS[build.artifact_kind];
6443
+ if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
6444
+ const scopeKey = siblingSandboxScopeKey(build, artifactKind);
6445
+ if (scopeKey === null) return null;
6446
+ const { rows } = await db.findMany("native_builds", {
6447
+ index: "byScope",
6448
+ where: { scope_key: scopeKey },
6449
+ order: "desc",
6450
+ limit: 1
6451
+ });
6452
+ const sibling = rows[0] === void 0 ? null : pick3(rows[0]);
6453
+ return sibling !== null && isInstallTarget(sibling) ? sibling : null;
6454
+ },
6376
6455
  async recordNativeBuildSubmission(id, { destination, version: version2 }) {
6377
6456
  if (version2.trim().length === 0 || version2.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
6378
6457
  return db.transaction(async (tx) => {
@@ -7507,13 +7586,19 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
7507
7586
  const scope = nativeBuildScopeOf(url);
7508
7587
  const buildKey = url.searchParams.get("buildKey");
7509
7588
  const builtInOlderThan = url.searchParams.get("builtInOlderThan");
7589
+ const kind = url.searchParams.get("kind");
7510
7590
  const options = {
7511
7591
  ...buildKey === null ? {} : { buildKey },
7512
7592
  ...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
7513
- ...builtInOlderThan === null ? {} : { builtInOlderThan }
7593
+ ...builtInOlderThan === null ? {} : { builtInOlderThan },
7594
+ ...kind === null ? {} : { artifactKind: kind }
7514
7595
  };
7515
7596
  return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
7516
7597
  }),
7598
+ findNativeBuildSibling: onCore(async (core, _request, params) => {
7599
+ const build = await core.getNativeBuild(requireRouteParam(params, "id"));
7600
+ return json({ data: build === null ? null : await core.findNativeBuildSibling(build) });
7601
+ }),
7517
7602
  getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
7518
7603
  listNativeBuilds: onCore(async (core, request) => {
7519
7604
  const url = new URL(request.url);
@@ -7744,6 +7829,11 @@ var ADMIN_ROUTES = [
7744
7829
  path: "/native-builds/latest",
7745
7830
  handler: "findNativeBuild"
7746
7831
  },
7832
+ {
7833
+ method: "GET",
7834
+ path: "/native-builds/:id/sibling",
7835
+ handler: "findNativeBuildSibling"
7836
+ },
7747
7837
  {
7748
7838
  method: "GET",
7749
7839
  path: "/native-builds/:id",