@hot-updater/aws 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.
Files changed (2) hide show
  1. package/dist/lambda/index.cjs +101 -12
  2. package/package.json +8 -8
@@ -2535,6 +2535,10 @@ store_build_scope_key: {
2535
2535
  eq: ["scope_key", "build_key"],
2536
2536
  sort: ["id"]
2537
2537
  },
2538
+ byScopeKind: {
2539
+ eq: ["scope_key", "artifact_kind"],
2540
+ sort: ["id"]
2541
+ },
2538
2542
  byStoreBuild: {
2539
2543
  eq: ["store_build_scope_key"],
2540
2544
  sort: [],
@@ -4787,7 +4791,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
4787
4791
  };
4788
4792
  //#endregion
4789
4793
  //#region ../../packages/server/dist/version.mjs
4790
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.42";
4794
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.44";
4791
4795
  //#endregion
4792
4796
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
4793
4797
  /**
@@ -6489,6 +6493,51 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
6489
6493
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
6490
6494
  return null;
6491
6495
  };
6496
+ /** The other install target of an iOS sandbox build's native code. */
6497
+ const SIBLING_KINDS = {
6498
+ app: "ipa",
6499
+ ipa: "app"
6500
+ };
6501
+ /**
6502
+ * Whether a build is one a person installs from its file: a Simulator `.app`,
6503
+ * or an `.ipa` exported for direct install, that no store took and that isn't
6504
+ * the store build. One rule for a sibling and the build it is found from, so
6505
+ * a build that shows its sibling is shown by it.
6506
+ */
6507
+ 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");
6508
+ /**
6509
+ * The scope key of the other install target of a sandbox build, from its own
6510
+ * key's app ID and URL scheme, which hold no colon, and its row's fingerprint
6511
+ * or app version, through `sandboxScopeKey`; null for a key it didn't make.
6512
+ */
6513
+ const siblingSandboxScopeKey = (build, artifactKind) => {
6514
+ const [version, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
6515
+ if (version !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
6516
+ const target = build.fingerprint_hash === null ? {
6517
+ platform: build.platform,
6518
+ fingerprintHash: null,
6519
+ appVersion: build.app_version ?? ""
6520
+ } : {
6521
+ platform: build.platform,
6522
+ fingerprintHash: build.fingerprint_hash,
6523
+ appVersion: null
6524
+ };
6525
+ try {
6526
+ return sandboxScopeKey(target, {
6527
+ appId,
6528
+ urlScheme,
6529
+ artifactKind: build.artifact_kind,
6530
+ distribution: registeredDistribution(build.artifact_kind, build.export_method)
6531
+ }) === build.scope_key ? sandboxScopeKey(target, {
6532
+ appId,
6533
+ urlScheme,
6534
+ artifactKind,
6535
+ distribution: "direct"
6536
+ }) : null;
6537
+ } catch {
6538
+ return null;
6539
+ }
6540
+ };
6492
6541
  /** The native build registry: core's `native_builds` and the built-in bundle rows. */
6493
6542
  const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
6494
6543
  async registerNativeBuild(registration) {
@@ -6557,9 +6606,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
6557
6606
  const scopeKey = nativeBuildScopeKey(scope);
6558
6607
  const buildKey = options?.buildKey;
6559
6608
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
6609
+ const artifactKind = options?.artifactKind;
6610
+ 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 ")}.`);
6611
+ const ofKind = (row) => artifactKind === void 0 || row.artifact_kind === artifactKind;
6560
6612
  if (options?.storeBuild) {
6561
6613
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
6562
- return marked === null ? null : pick(marked);
6614
+ return marked === null || !ofKind(marked) ? null : pick(marked);
6563
6615
  }
6564
6616
  const read = (limit, before) => {
6565
6617
  const page = {
@@ -6567,34 +6619,60 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
6567
6619
  limit,
6568
6620
  ...before === void 0 ? {} : { range: { lt: before } }
6569
6621
  };
6570
- return buildKey === void 0 ? db.findMany("native_builds", {
6571
- index: "byScope",
6572
- where: { scope_key: scopeKey },
6573
- ...page
6574
- }) : db.findMany("native_builds", {
6622
+ return buildKey !== void 0 ? db.findMany("native_builds", {
6575
6623
  index: "byBuildKey",
6576
6624
  where: {
6577
6625
  scope_key: scopeKey,
6578
6626
  build_key: buildKey
6579
6627
  },
6580
6628
  ...page
6629
+ }) : artifactKind !== void 0 ? db.findMany("native_builds", {
6630
+ index: "byScopeKind",
6631
+ where: {
6632
+ scope_key: scopeKey,
6633
+ artifact_kind: artifactKind
6634
+ },
6635
+ ...page
6636
+ }) : db.findMany("native_builds", {
6637
+ index: "byScope",
6638
+ where: { scope_key: scopeKey },
6639
+ ...page
6581
6640
  });
6582
6641
  };
6583
6642
  const bundleId = options?.builtInOlderThan;
6584
6643
  if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
6585
6644
  const { rows } = await read(1);
6586
- const newest = rows[0];
6587
- if (newest === void 0) return null;
6588
- if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
6645
+ const newest = (rows[0] === void 0 ? void 0 : pick(rows[0])) ?? (artifactKind !== void 0 && buildKey === void 0 ? await db.findMany("native_builds", {
6646
+ index: "byScope",
6647
+ where: { scope_key: scopeKey },
6648
+ order: "desc",
6649
+ limit: 1
6650
+ }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
6651
+ if (newest === void 0 || !ofKind(newest)) return null;
6652
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
6589
6653
  for (let before = newest.id;;) {
6590
6654
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
6591
6655
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
6592
- if (usable !== void 0) return pick(usable);
6656
+ if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
6593
6657
  const last = older.at(-1);
6594
6658
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
6595
6659
  before = last.id;
6596
6660
  }
6597
6661
  },
6662
+ async findNativeBuildSibling(build) {
6663
+ const artifactKind = SIBLING_KINDS[build.artifact_kind];
6664
+ if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
6665
+ const scopeKey = siblingSandboxScopeKey(build, artifactKind);
6666
+ if (scopeKey === null) return null;
6667
+ const { rows } = await db.findMany("native_builds", {
6668
+ index: "byScope",
6669
+ where: { scope_key: scopeKey },
6670
+ order: "desc",
6671
+ limit: 1
6672
+ });
6673
+ const sibling = rows[0] === void 0 ? null : pick(rows[0]);
6674
+ return sibling !== null && isInstallTarget(sibling) ? sibling : null;
6675
+ },
6598
6676
  async recordNativeBuildSubmission(id, { destination, version }) {
6599
6677
  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.`);
6600
6678
  return db.transaction(async (tx) => {
@@ -7779,13 +7857,19 @@ const createAdminRouteHandlers = () => ({
7779
7857
  const scope = nativeBuildScopeOf(url);
7780
7858
  const buildKey = url.searchParams.get("buildKey");
7781
7859
  const builtInOlderThan = url.searchParams.get("builtInOlderThan");
7860
+ const kind = url.searchParams.get("kind");
7782
7861
  const options = {
7783
7862
  ...buildKey === null ? {} : { buildKey },
7784
7863
  ...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
7785
- ...builtInOlderThan === null ? {} : { builtInOlderThan }
7864
+ ...builtInOlderThan === null ? {} : { builtInOlderThan },
7865
+ ...kind === null ? {} : { artifactKind: kind }
7786
7866
  };
7787
7867
  return json$2({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
7788
7868
  }),
7869
+ findNativeBuildSibling: onCore(async (core, _request, params) => {
7870
+ const build = await core.getNativeBuild(requireRouteParam(params, "id"));
7871
+ return json$2({ data: build === null ? null : await core.findNativeBuildSibling(build) });
7872
+ }),
7789
7873
  getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
7790
7874
  listNativeBuilds: onCore(async (core, request) => {
7791
7875
  const url = new URL(request.url);
@@ -8017,6 +8101,11 @@ const ADMIN_ROUTES = [
8017
8101
  path: "/native-builds/latest",
8018
8102
  handler: "findNativeBuild"
8019
8103
  },
8104
+ {
8105
+ method: "GET",
8106
+ path: "/native-builds/:id/sibling",
8107
+ handler: "findNativeBuildSibling"
8108
+ },
8020
8109
  {
8021
8110
  method: "GET",
8022
8111
  path: "/native-builds/:id",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/aws",
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",
@@ -45,9 +45,9 @@
45
45
  "es-toolkit": "^1.32.0",
46
46
  "execa": "9.5.2",
47
47
  "mime": "^4.0.4",
48
- "@hot-updater/protocol": "1.2.0-rc.42",
49
- "@hot-updater/test-utils": "1.2.0-rc.42",
50
- "@hot-updater/mock": "1.2.0-rc.42"
48
+ "@hot-updater/protocol": "1.2.0-rc.44",
49
+ "@hot-updater/mock": "1.2.0-rc.44",
50
+ "@hot-updater/test-utils": "1.2.0-rc.44"
51
51
  },
52
52
  "dependencies": {
53
53
  "@aws-sdk/client-cloudfront": "3.1066.0",
@@ -64,10 +64,10 @@
64
64
  "@aws-sdk/lib-dynamodb": "3.1066.0",
65
65
  "@aws-sdk/s3-request-presigner": "3.1066.0",
66
66
  "hono": "4.12.34",
67
- "@hot-updater/cli-tools": "1.2.0-rc.42",
68
- "@hot-updater/plugin-core": "1.2.0-rc.42",
69
- "@hot-updater/server": "1.2.0-rc.42",
70
- "@hot-updater/storage-s3": "1.2.0-rc.42"
67
+ "@hot-updater/cli-tools": "1.2.0-rc.44",
68
+ "@hot-updater/plugin-core": "1.2.0-rc.44",
69
+ "@hot-updater/server": "1.2.0-rc.44",
70
+ "@hot-updater/storage-s3": "1.2.0-rc.44"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown",