@hot-updater/vercel 1.2.0-rc.42 → 1.2.0-rc.43

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.
@@ -2505,6 +2505,10 @@ const nativeBuilds = defineTable({
2505
2505
  eq: ["scope_key", "build_key"],
2506
2506
  sort: ["id"]
2507
2507
  },
2508
+ byScopeKind: {
2509
+ eq: ["scope_key", "artifact_kind"],
2510
+ sort: ["id"]
2511
+ },
2508
2512
  byStoreBuild: {
2509
2513
  eq: ["store_build_scope_key"],
2510
2514
  sort: [],
@@ -17735,7 +17739,7 @@ const postgres = (config) => {
17735
17739
  };
17736
17740
  //#endregion
17737
17741
  //#region ../../packages/server/dist/version.mjs
17738
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.42";
17742
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.43";
17739
17743
  //#endregion
17740
17744
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
17741
17745
  const createVersionRouteHandlers = (plugins = []) => {
@@ -19261,6 +19265,39 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
19261
19265
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
19262
19266
  return null;
19263
19267
  };
19268
+ const SIBLING_KINDS = {
19269
+ app: "ipa",
19270
+ ipa: "app"
19271
+ };
19272
+ const isInstallTarget = (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");
19273
+ const siblingSandboxScopeKey = (build, artifactKind) => {
19274
+ const [version, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
19275
+ if (version !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
19276
+ const target = build.fingerprint_hash === null ? {
19277
+ platform: build.platform,
19278
+ fingerprintHash: null,
19279
+ appVersion: build.app_version ?? ""
19280
+ } : {
19281
+ platform: build.platform,
19282
+ fingerprintHash: build.fingerprint_hash,
19283
+ appVersion: null
19284
+ };
19285
+ try {
19286
+ return sandboxScopeKey(target, {
19287
+ appId,
19288
+ urlScheme,
19289
+ artifactKind: build.artifact_kind,
19290
+ distribution: registeredDistribution(build.artifact_kind, build.export_method)
19291
+ }) === build.scope_key ? sandboxScopeKey(target, {
19292
+ appId,
19293
+ urlScheme,
19294
+ artifactKind,
19295
+ distribution: "direct"
19296
+ }) : null;
19297
+ } catch {
19298
+ return null;
19299
+ }
19300
+ };
19264
19301
  const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19265
19302
  async registerNativeBuild(registration) {
19266
19303
  const problem = problemOf(registration);
@@ -19328,9 +19365,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19328
19365
  const scopeKey = nativeBuildScopeKey(scope);
19329
19366
  const buildKey = options?.buildKey;
19330
19367
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
19368
+ const artifactKind = options?.artifactKind;
19369
+ 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 ")}.`);
19370
+ const ofKind = (row) => artifactKind === void 0 || row.artifact_kind === artifactKind;
19331
19371
  if (options?.storeBuild) {
19332
19372
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
19333
- return marked === null ? null : pick(marked);
19373
+ return marked === null || !ofKind(marked) ? null : pick(marked);
19334
19374
  }
19335
19375
  const read = (limit, before) => {
19336
19376
  const page = {
@@ -19338,34 +19378,60 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19338
19378
  limit,
19339
19379
  ...before === void 0 ? {} : { range: { lt: before } }
19340
19380
  };
19341
- return buildKey === void 0 ? db.findMany("native_builds", {
19342
- index: "byScope",
19343
- where: { scope_key: scopeKey },
19344
- ...page
19345
- }) : db.findMany("native_builds", {
19381
+ return buildKey !== void 0 ? db.findMany("native_builds", {
19346
19382
  index: "byBuildKey",
19347
19383
  where: {
19348
19384
  scope_key: scopeKey,
19349
19385
  build_key: buildKey
19350
19386
  },
19351
19387
  ...page
19388
+ }) : artifactKind !== void 0 ? db.findMany("native_builds", {
19389
+ index: "byScopeKind",
19390
+ where: {
19391
+ scope_key: scopeKey,
19392
+ artifact_kind: artifactKind
19393
+ },
19394
+ ...page
19395
+ }) : db.findMany("native_builds", {
19396
+ index: "byScope",
19397
+ where: { scope_key: scopeKey },
19398
+ ...page
19352
19399
  });
19353
19400
  };
19354
19401
  const bundleId = options?.builtInOlderThan;
19355
19402
  if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
19356
19403
  const { rows } = await read(1);
19357
- const newest = rows[0];
19358
- if (newest === void 0) return null;
19359
- if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
19404
+ const newest = (rows[0] === void 0 ? void 0 : pick(rows[0])) ?? (artifactKind !== void 0 && buildKey === void 0 ? await db.findMany("native_builds", {
19405
+ index: "byScope",
19406
+ where: { scope_key: scopeKey },
19407
+ order: "desc",
19408
+ limit: 1
19409
+ }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
19410
+ if (newest === void 0 || !ofKind(newest)) return null;
19411
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
19360
19412
  for (let before = newest.id;;) {
19361
19413
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
19362
19414
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
19363
- if (usable !== void 0) return pick(usable);
19415
+ if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
19364
19416
  const last = older.at(-1);
19365
19417
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
19366
19418
  before = last.id;
19367
19419
  }
19368
19420
  },
19421
+ async findNativeBuildSibling(build) {
19422
+ const artifactKind = SIBLING_KINDS[build.artifact_kind];
19423
+ if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
19424
+ const scopeKey = siblingSandboxScopeKey(build, artifactKind);
19425
+ if (scopeKey === null) return null;
19426
+ const { rows } = await db.findMany("native_builds", {
19427
+ index: "byScope",
19428
+ where: { scope_key: scopeKey },
19429
+ order: "desc",
19430
+ limit: 1
19431
+ });
19432
+ const sibling = rows[0] === void 0 ? null : pick(rows[0]);
19433
+ return sibling !== null && isInstallTarget(sibling) ? sibling : null;
19434
+ },
19369
19435
  async recordNativeBuildSubmission(id, { destination, version }) {
19370
19436
  if (version.trim().length === 0 || version.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.`);
19371
19437
  return db.transaction(async (tx) => {
@@ -20489,13 +20555,19 @@ const createAdminRouteHandlers = () => ({
20489
20555
  const scope = nativeBuildScopeOf(url);
20490
20556
  const buildKey = url.searchParams.get("buildKey");
20491
20557
  const builtInOlderThan = url.searchParams.get("builtInOlderThan");
20558
+ const kind = url.searchParams.get("kind");
20492
20559
  const options = {
20493
20560
  ...buildKey === null ? {} : { buildKey },
20494
20561
  ...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
20495
- ...builtInOlderThan === null ? {} : { builtInOlderThan }
20562
+ ...builtInOlderThan === null ? {} : { builtInOlderThan },
20563
+ ...kind === null ? {} : { artifactKind: kind }
20496
20564
  };
20497
20565
  return json$2({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
20498
20566
  }),
20567
+ findNativeBuildSibling: onCore(async (core, _request, params) => {
20568
+ const build = await core.getNativeBuild(requireRouteParam(params, "id"));
20569
+ return json$2({ data: build === null ? null : await core.findNativeBuildSibling(build) });
20570
+ }),
20499
20571
  getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
20500
20572
  listNativeBuilds: onCore(async (core, request) => {
20501
20573
  const url = new URL(request.url);
@@ -20726,6 +20798,11 @@ const ADMIN_ROUTES = [
20726
20798
  path: "/native-builds/latest",
20727
20799
  handler: "findNativeBuild"
20728
20800
  },
20801
+ {
20802
+ method: "GET",
20803
+ path: "/native-builds/:id/sibling",
20804
+ handler: "findNativeBuildSibling"
20805
+ },
20729
20806
  {
20730
20807
  method: "GET",
20731
20808
  path: "/native-builds/:id",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/vercel",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.42",
4
+ "version": "1.2.0-rc.43",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -41,11 +41,11 @@
41
41
  "@vercel/cli-auth": "0.3.10",
42
42
  "@vercel/cli-config": "0.3.1",
43
43
  "pg": "8.13.1",
44
- "@hot-updater/plugin-core": "1.2.0-rc.42",
45
- "@hot-updater/cli-tools": "1.2.0-rc.42",
46
- "@hot-updater/postgres": "1.2.0-rc.42",
47
- "@hot-updater/server": "1.2.0-rc.42",
48
- "@hot-updater/protocol": "1.2.0-rc.42"
44
+ "@hot-updater/plugin-core": "1.2.0-rc.43",
45
+ "@hot-updater/cli-tools": "1.2.0-rc.43",
46
+ "@hot-updater/server": "1.2.0-rc.43",
47
+ "@hot-updater/postgres": "1.2.0-rc.43",
48
+ "@hot-updater/protocol": "1.2.0-rc.43"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^20",
@@ -54,7 +54,7 @@
54
54
  "execa": "9.5.2",
55
55
  "kysely": "0.28.17",
56
56
  "vitest": "4.1.4",
57
- "@hot-updater/test-utils": "1.2.0-rc.42"
57
+ "@hot-updater/test-utils": "1.2.0-rc.43"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsdown",