@hot-updater/cloudflare 1.2.0-rc.27 → 1.2.0-rc.28

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.
@@ -2608,6 +2608,11 @@ var nativeBuilds = defineTable({
2608
2608
  maxLength: 255,
2609
2609
  ascii: true,
2610
2610
  required: false
2611
+ },
2612
+ export_method: {
2613
+ type: "string",
2614
+ maxLength: 16,
2615
+ required: false
2611
2616
  }
2612
2617
  }, {
2613
2618
  key: ["id"],
@@ -2645,6 +2650,92 @@ var nativeBuilds = defineTable({
2645
2650
  }
2646
2651
  }
2647
2652
  });
2653
+ var iosDevices = defineTable({
2654
+ id: {
2655
+ type: "string",
2656
+ maxLength: 36
2657
+ },
2658
+ udid: {
2659
+ type: "string",
2660
+ maxLength: 40,
2661
+ ascii: true,
2662
+ unique: true
2663
+ },
2664
+ name: {
2665
+ type: "string",
2666
+ maxLength: 100
2667
+ },
2668
+ status: {
2669
+ type: "string",
2670
+ maxLength: 16
2671
+ },
2672
+ requested_by: {
2673
+ type: "string",
2674
+ maxLength: 320,
2675
+ required: false
2676
+ },
2677
+ created_at_ms: { type: "integer" },
2678
+ approved_by: {
2679
+ type: "string",
2680
+ maxLength: 320,
2681
+ required: false
2682
+ },
2683
+ approved_at_ms: {
2684
+ type: "integer",
2685
+ required: false
2686
+ },
2687
+ registered_at_ms: {
2688
+ type: "integer",
2689
+ required: false
2690
+ },
2691
+ apple_issuer_id: {
2692
+ type: "string",
2693
+ maxLength: 64,
2694
+ ascii: true,
2695
+ required: false
2696
+ },
2697
+ apple_error: {
2698
+ type: "string",
2699
+ maxLength: 512,
2700
+ required: false
2701
+ },
2702
+ build_id: {
2703
+ type: "string",
2704
+ maxLength: 36,
2705
+ required: false
2706
+ }
2707
+ }, {
2708
+ key: ["id"],
2709
+ indexes: {
2710
+ byStatus: {
2711
+ eq: ["status"],
2712
+ sort: ["id"]
2713
+ },
2714
+ all: {
2715
+ eq: [],
2716
+ sort: ["id"]
2717
+ }
2718
+ }
2719
+ });
2720
+ var iosDeviceAccount = defineTable({
2721
+ id: {
2722
+ type: "string",
2723
+ maxLength: 16,
2724
+ ascii: true
2725
+ },
2726
+ apple_issuer_id: {
2727
+ type: "string",
2728
+ maxLength: 64,
2729
+ ascii: true
2730
+ },
2731
+ claimed_at_ms: { type: "integer" }
2732
+ }, {
2733
+ key: ["id"],
2734
+ indexes: { all: {
2735
+ eq: [],
2736
+ sort: ["id"]
2737
+ } }
2738
+ });
2648
2739
  var coreSchema = {
2649
2740
  bundles,
2650
2741
  bundle_patches: bundlePatches,
@@ -2662,7 +2753,9 @@ var coreSchema = {
2662
2753
  sort: []
2663
2754
  } }
2664
2755
  }),
2665
- native_builds: nativeBuilds
2756
+ native_builds: nativeBuilds,
2757
+ ios_devices: iosDevices,
2758
+ ios_device_account: iosDeviceAccount
2666
2759
  };
2667
2760
  var coreModule = {
2668
2761
  id: "core",
@@ -4575,7 +4668,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4575
4668
  }, "createSqlAdapter");
4576
4669
 
4577
4670
  // ../../packages/server/dist/package.mjs
4578
- var version = "1.2.0-rc.27";
4671
+ var version = "1.2.0-rc.28";
4579
4672
 
4580
4673
  // ../../packages/server/dist/version.mjs
4581
4674
  var HOT_UPDATER_SERVER_VERSION = version;
@@ -5427,7 +5520,14 @@ var drain = /* @__PURE__ */ __name(async (read) => {
5427
5520
  } while (cursor !== void 0);
5428
5521
  return rows;
5429
5522
  }, "drain");
5430
- var after = /* @__PURE__ */ __name((input) => input.after === void 0 ? {} : { range: (input.order ?? "asc") === "asc" ? { gt: input.after } : { lt: input.after } }, "after");
5523
+ var after = /* @__PURE__ */ __name((input) => {
5524
+ const asc = (input.order ?? "asc") === "asc";
5525
+ const range = {
5526
+ ...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
5527
+ ...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
5528
+ };
5529
+ return Object.keys(range).length === 0 ? {} : { range };
5530
+ }, "after");
5431
5531
  var createCoreReads = /* @__PURE__ */ __name((db, storage) => {
5432
5532
  const detail = /* @__PURE__ */ __name(async (row) => {
5433
5533
  const count = row._refs_bundle_patches_bundle_id ?? 0;
@@ -5630,6 +5730,285 @@ var createCoreReads = /* @__PURE__ */ __name((db, storage) => {
5630
5730
  };
5631
5731
  }, "createCoreReads");
5632
5732
 
5733
+ // ../../packages/server/dist/core/iosDevices.mjs
5734
+ var UDID = /^(?:[0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16})$/iu;
5735
+ var normalizeIosUdid = /* @__PURE__ */ __name((value) => {
5736
+ const trimmed = value.trim();
5737
+ return UDID.test(trimmed) ? trimmed.toLowerCase() : null;
5738
+ }, "normalizeIosUdid");
5739
+ var NAME_MAX_LENGTH = 100;
5740
+ var EMAIL_MAX_LENGTH = 320;
5741
+ var ISSUER_MAX_LENGTH = 64;
5742
+ var ACCOUNT_SCAN_PAGE = 200;
5743
+ var ACCOUNT_ROW = "registry";
5744
+ var ERROR_MAX_LENGTH = 512;
5745
+ var STATUSES = [
5746
+ "pending",
5747
+ "approved",
5748
+ "registered"
5749
+ ];
5750
+ var OUTCOMES = [
5751
+ "registered",
5752
+ "refused",
5753
+ "disabled",
5754
+ "missing"
5755
+ ];
5756
+ var IOS_DEVICE_DISABLED_ERROR = "Disabled in the Apple account.";
5757
+ var IOS_DEVICE_MISSING_ERROR = "Gone from the Apple account. Approve it again to register it.";
5758
+ var IosDeviceInputError = class extends TypeError {
5759
+ static {
5760
+ __name(this, "IosDeviceInputError");
5761
+ }
5762
+ name = "IosDeviceInputError";
5763
+ };
5764
+ var pick2 = /* @__PURE__ */ __name((row) => ({
5765
+ id: row.id,
5766
+ udid: row.udid,
5767
+ name: row.name,
5768
+ status: row.status,
5769
+ requested_by: row.requested_by ?? null,
5770
+ created_at_ms: row.created_at_ms,
5771
+ approved_by: row.approved_by ?? null,
5772
+ approved_at_ms: row.approved_at_ms ?? null,
5773
+ registered_at_ms: row.registered_at_ms ?? null,
5774
+ apple_issuer_id: row.apple_issuer_id ?? null,
5775
+ apple_error: row.apple_error ?? null,
5776
+ build_id: row.build_id ?? null
5777
+ }), "pick");
5778
+ var udidOf = /* @__PURE__ */ __name((udid) => {
5779
+ const key = typeof udid === "string" ? normalizeIosUdid(udid) : null;
5780
+ if (key === null) throw new IosDeviceInputError("Invalid iOS device: udid must be 40 hex digits, or 8 and 16 joined by a hyphen.");
5781
+ return key;
5782
+ }, "udidOf");
5783
+ var nameOf = /* @__PURE__ */ __name((name) => {
5784
+ const trimmed = typeof name === "string" ? name.trim() : "";
5785
+ if (trimmed.length === 0 || trimmed.length > NAME_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: name must be 1 to ${NAME_MAX_LENGTH} characters.`);
5786
+ return trimmed;
5787
+ }, "nameOf");
5788
+ var personOf = /* @__PURE__ */ __name((value, field) => {
5789
+ if (value === null) return null;
5790
+ const email = typeof value === "string" ? value.trim().toLowerCase() : "";
5791
+ if (email.length === 0 || email.length > EMAIL_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: ${field} must be an email of at most ${EMAIL_MAX_LENGTH} characters, or null.`);
5792
+ return email;
5793
+ }, "personOf");
5794
+ var errorText = /* @__PURE__ */ __name((text) => {
5795
+ const line = text.replace(/\s+/gu, " ").trim();
5796
+ return line.length > ERROR_MAX_LENGTH ? `${line.slice(0, 511)}\u2026` : line;
5797
+ }, "errorText");
5798
+ var createIosDeviceApi = /* @__PURE__ */ __name((db, { now = Date.now } = {}) => {
5799
+ const findIosDevice = /* @__PURE__ */ __name(async (udid) => {
5800
+ const key = normalizeIosUdid(udid);
5801
+ if (key === null) return null;
5802
+ const row = await db.findOne("ios_devices", { udid: key });
5803
+ return row === null ? null : pick2(row);
5804
+ }, "findIosDevice");
5805
+ const accountOfRows = /* @__PURE__ */ __name(async () => {
5806
+ let earliest = null;
5807
+ for (let after2; ; ) {
5808
+ const { rows } = await db.findMany("ios_devices", {
5809
+ index: "all",
5810
+ where: {},
5811
+ order: "asc",
5812
+ limit: ACCOUNT_SCAN_PAGE,
5813
+ ...after2 === void 0 ? {} : { range: { gt: after2 } }
5814
+ });
5815
+ for (const row of rows.map(pick2)) {
5816
+ if (row.apple_issuer_id === null) continue;
5817
+ if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
5818
+ }
5819
+ if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
5820
+ after2 = rows.at(-1).id;
5821
+ }
5822
+ }, "accountOfRows");
5823
+ return {
5824
+ async listIosDevices(input) {
5825
+ if (input.status !== void 0 && !STATUSES.includes(input.status)) throw new IosDeviceInputError(`Invalid iOS device status: ${String(input.status)}. Expected ${STATUSES.join(", ")}.`);
5826
+ const page2 = {
5827
+ order: input.order ?? "asc",
5828
+ limit: input.limit,
5829
+ ...after(input)
5830
+ };
5831
+ const { rows } = input.status === void 0 ? await db.findMany("ios_devices", {
5832
+ index: "all",
5833
+ where: {},
5834
+ ...page2
5835
+ }) : await db.findMany("ios_devices", {
5836
+ index: "byStatus",
5837
+ where: { status: input.status },
5838
+ ...page2
5839
+ });
5840
+ return rows.map(pick2);
5841
+ },
5842
+ findIosDevice,
5843
+ async requestIosDevice(input) {
5844
+ const udid = udidOf(input.udid);
5845
+ const name = nameOf(input.name);
5846
+ const requestedBy = personOf(input.requestedBy, "requestedBy");
5847
+ const existing = await db.findOne("ios_devices", { udid });
5848
+ if (existing !== null) return {
5849
+ device: pick2(existing),
5850
+ created: false
5851
+ };
5852
+ const device = {
5853
+ id: createUUIDv7(),
5854
+ udid,
5855
+ name,
5856
+ status: "pending",
5857
+ requested_by: requestedBy,
5858
+ created_at_ms: now(),
5859
+ approved_by: null,
5860
+ approved_at_ms: null,
5861
+ registered_at_ms: null,
5862
+ apple_issuer_id: null,
5863
+ apple_error: null,
5864
+ build_id: null
5865
+ };
5866
+ try {
5867
+ await db.transaction(async (tx) => {
5868
+ tx.create("ios_devices", device);
5869
+ });
5870
+ } catch (error) {
5871
+ if (error instanceof DatabaseConstraintError && error.reason === "unique") {
5872
+ const winner = await db.findOne("ios_devices", { udid });
5873
+ if (winner !== null) return {
5874
+ device: pick2(winner),
5875
+ created: false
5876
+ };
5877
+ }
5878
+ throw error;
5879
+ }
5880
+ return {
5881
+ device,
5882
+ created: true
5883
+ };
5884
+ },
5885
+ async approveIosDevice(id, input) {
5886
+ const name = input.name === void 0 ? void 0 : nameOf(input.name);
5887
+ const approvedBy = personOf(input.approvedBy, "approvedBy");
5888
+ return db.transaction(async (tx) => {
5889
+ const row = await tx.findOne("ios_devices", { id });
5890
+ if (row === null) return null;
5891
+ const device = pick2(row);
5892
+ const set = {
5893
+ ...name === void 0 || name === device.name ? {} : { name },
5894
+ ...device.status === "pending" ? {
5895
+ status: "approved",
5896
+ approved_by: approvedBy,
5897
+ approved_at_ms: now()
5898
+ } : {}
5899
+ };
5900
+ if (Object.keys(set).length === 0) return device;
5901
+ tx.update("ios_devices", row, set);
5902
+ return {
5903
+ ...device,
5904
+ ...set
5905
+ };
5906
+ });
5907
+ },
5908
+ async renameIosDevice(id, input) {
5909
+ const name = nameOf(input);
5910
+ return db.transaction(async (tx) => {
5911
+ const row = await tx.findOne("ios_devices", { id });
5912
+ if (row === null) return null;
5913
+ const device = pick2(row);
5914
+ if (device.name === name) return device;
5915
+ tx.update("ios_devices", row, { name });
5916
+ return {
5917
+ ...device,
5918
+ name
5919
+ };
5920
+ });
5921
+ },
5922
+ async recordIosDeviceOutcome({ id, seen, issuerId, outcome, reason }) {
5923
+ if (!OUTCOMES.includes(outcome)) throw new IosDeviceInputError(`Invalid iOS device outcome: ${String(outcome)}. Expected ${OUTCOMES.join(", ")}.`);
5924
+ if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device outcome: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
5925
+ return db.transaction(async (tx) => {
5926
+ const row = await tx.findOne("ios_devices", { id });
5927
+ if (row === null) return null;
5928
+ const device = pick2(row);
5929
+ if (device.status !== seen.status || device.approved_at_ms !== seen.approvedAtMs || device.apple_issuer_id !== null && device.apple_issuer_id !== issuerId) return null;
5930
+ let set;
5931
+ switch (outcome) {
5932
+ case "registered":
5933
+ if (device.status === "pending") return null;
5934
+ set = {
5935
+ status: "registered",
5936
+ registered_at_ms: device.registered_at_ms ?? now(),
5937
+ apple_issuer_id: issuerId,
5938
+ apple_error: null
5939
+ };
5940
+ break;
5941
+ case "refused":
5942
+ if (device.status !== "approved") return null;
5943
+ set = { apple_error: errorText(reason === void 0 || reason.trim() === "" ? "Apple refused it." : reason) };
5944
+ break;
5945
+ case "disabled":
5946
+ if (device.status === "pending") return null;
5947
+ set = { apple_error: IOS_DEVICE_DISABLED_ERROR };
5948
+ break;
5949
+ case "missing":
5950
+ if (device.status !== "registered") return null;
5951
+ set = {
5952
+ status: "pending",
5953
+ approved_by: null,
5954
+ approved_at_ms: null,
5955
+ apple_error: IOS_DEVICE_MISSING_ERROR
5956
+ };
5957
+ }
5958
+ if (Object.entries(set).some(([column, value]) => device[column] !== (value ?? null))) tx.update("ios_devices", row, set);
5959
+ return {
5960
+ ...device,
5961
+ ...set
5962
+ };
5963
+ });
5964
+ },
5965
+ async markIosDevicesInBuild({ buildId, ids }) {
5966
+ for (const id of new Set(ids)) await db.transaction(async (tx) => {
5967
+ const row = await tx.findOne("ios_devices", { id });
5968
+ if (row === null || typeof row.build_id === "string" && row.build_id >= buildId) return;
5969
+ tx.update("ios_devices", row, { build_id: buildId });
5970
+ });
5971
+ },
5972
+ async claimIosDeviceAccount(issuerId) {
5973
+ if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device account: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
5974
+ const answer2 = /* @__PURE__ */ __name((held) => ({
5975
+ issuerId: held,
5976
+ claimed: held === issuerId
5977
+ }), "answer");
5978
+ const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
5979
+ if (existing !== null) return answer2(existing.apple_issuer_id);
5980
+ const holder = await accountOfRows() ?? issuerId;
5981
+ try {
5982
+ await db.transaction(async (tx) => {
5983
+ tx.create("ios_device_account", {
5984
+ id: ACCOUNT_ROW,
5985
+ apple_issuer_id: holder,
5986
+ claimed_at_ms: now()
5987
+ });
5988
+ });
5989
+ return answer2(holder);
5990
+ } catch (error) {
5991
+ if (error instanceof DatabaseConstraintError && (error.reason === "exists" || error.reason === "unique")) {
5992
+ const winner = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
5993
+ if (winner !== null) return answer2(winner.apple_issuer_id);
5994
+ }
5995
+ throw error;
5996
+ }
5997
+ },
5998
+ async deleteIosDevice(id, only) {
5999
+ const requestedBy = only?.requestedBy === void 0 ? void 0 : personOf(only.requestedBy, "requestedBy");
6000
+ return db.transaction(async (tx) => {
6001
+ const row = await tx.findOne("ios_devices", { id });
6002
+ if (row === null) return null;
6003
+ const device = pick2(row);
6004
+ if (only?.status !== void 0 && device.status !== only.status || requestedBy !== void 0 && device.requested_by !== requestedBy) return null;
6005
+ await tx.delete("ios_devices", row);
6006
+ return device;
6007
+ });
6008
+ }
6009
+ };
6010
+ }, "createIosDeviceApi");
6011
+
5633
6012
  // ../../packages/server/dist/core/nativeBuildDestinations.mjs
5634
6013
  var NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
5635
6014
  android: [
@@ -5746,7 +6125,7 @@ var NativeBuildInputError = class extends TypeError {
5746
6125
  }
5747
6126
  name = "NativeBuildInputError";
5748
6127
  };
5749
- var pick2 = /* @__PURE__ */ __name((row) => ({
6128
+ var pick3 = /* @__PURE__ */ __name((row) => ({
5750
6129
  id: row.id,
5751
6130
  scope_key: row.scope_key,
5752
6131
  platform: row.platform,
@@ -5766,8 +6145,15 @@ var pick2 = /* @__PURE__ */ __name((row) => ({
5766
6145
  submitted_version: row.submitted_version ?? null,
5767
6146
  is_store_build: row.is_store_build === true,
5768
6147
  is_sandbox: row.is_sandbox === true,
5769
- sandbox_url_scheme: row.sandbox_url_scheme ?? null
6148
+ sandbox_url_scheme: row.sandbox_url_scheme ?? null,
6149
+ export_method: row.export_method ?? null
5770
6150
  }), "pick");
6151
+ var EXPORT_METHODS = /* @__PURE__ */ new Set([
6152
+ "app-store",
6153
+ "ad-hoc",
6154
+ "development",
6155
+ "enterprise"
6156
+ ]);
5771
6157
  var SANDBOX_CHANNEL_PREFIX = "sandbox-";
5772
6158
  var OLDER_BUILDS_PAGE = 20;
5773
6159
  var MARK_ATTEMPTS = 8;
@@ -5794,7 +6180,7 @@ var nativeBuildScopeKey = /* @__PURE__ */ __name((scope) => {
5794
6180
  return scopeKey;
5795
6181
  }, "nativeBuildScopeKey");
5796
6182
  var isBuiltInBundle = /* @__PURE__ */ __name(async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null, "isBuiltInBundle");
5797
- var problemOf = /* @__PURE__ */ __name(({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, artifact }) => {
6183
+ var problemOf = /* @__PURE__ */ __name(({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, artifact }) => {
5798
6184
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
5799
6185
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
5800
6186
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
@@ -5813,6 +6199,10 @@ var problemOf = /* @__PURE__ */ __name(({ id, minBundleId, platform, channel, fi
5813
6199
  if (buildNumber !== void 0 && buildNumber !== null && (buildNumber.trim().length === 0 || buildNumber.length > BUILD_NUMBER_MAX_LENGTH)) return `buildNumber must be the artifact's build number, up to ${BUILD_NUMBER_MAX_LENGTH} characters, or null`;
5814
6200
  const kinds = ARTIFACT_KINDS[platform];
5815
6201
  if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
6202
+ if (exportMethod !== void 0 && exportMethod !== null) {
6203
+ if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
6204
+ if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
6205
+ }
5816
6206
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
5817
6207
  return null;
5818
6208
  }, "problemOf");
@@ -5843,7 +6233,8 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5843
6233
  submitted_version: null,
5844
6234
  is_store_build: false,
5845
6235
  is_sandbox: registration.isSandbox === true,
5846
- sandbox_url_scheme: registration.sandboxUrlScheme ?? null
6236
+ sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
6237
+ export_method: registration.exportMethod ?? null
5847
6238
  };
5848
6239
  for (let attempt = 1; ; attempt += 1) {
5849
6240
  await insertChannel(db, {
@@ -5875,7 +6266,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5875
6266
  },
5876
6267
  async getNativeBuild(id) {
5877
6268
  const row = await db.findOne("native_builds", { id });
5878
- return row === null ? null : pick2(row);
6269
+ return row === null ? null : pick3(row);
5879
6270
  },
5880
6271
  async findNativeBuild(scope, options) {
5881
6272
  const scopeKey = nativeBuildScopeKey(scope);
@@ -5883,7 +6274,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5883
6274
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
5884
6275
  if (options?.storeBuild) {
5885
6276
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
5886
- return marked === null ? null : pick2(marked);
6277
+ return marked === null ? null : pick3(marked);
5887
6278
  }
5888
6279
  const read = /* @__PURE__ */ __name((limit, before) => {
5889
6280
  const page2 = {
@@ -5908,11 +6299,11 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5908
6299
  const newest = rows[0];
5909
6300
  if (newest === void 0) return null;
5910
6301
  const bundleId = options?.builtInOlderThan;
5911
- if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick2(newest);
6302
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick3(newest);
5912
6303
  for (let before = newest.id; ; ) {
5913
6304
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
5914
6305
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
5915
- if (usable !== void 0) return pick2(usable);
6306
+ if (usable !== void 0) return pick3(usable);
5916
6307
  const last = older.at(-1);
5917
6308
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
5918
6309
  before = last.id;
@@ -5923,7 +6314,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5923
6314
  return db.transaction(async (tx) => {
5924
6315
  const row = await tx.findOne("native_builds", { id });
5925
6316
  if (row === null) return null;
5926
- const build = pick2(row);
6317
+ const build = pick3(row);
5927
6318
  if (!NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].includes(destination)) throw new NativeBuildInputError(`Invalid native build submission: an ${build.platform} build is submitted to ${NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].join(" or ")}, not ${destination}.`);
5928
6319
  if (build.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
5929
6320
  const set = {
@@ -5943,7 +6334,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5943
6334
  return await db.transaction(async (tx) => {
5944
6335
  const row = await tx.findOne("native_builds", { id });
5945
6336
  if (row === null) return null;
5946
- const build = pick2(row);
6337
+ const build = pick3(row);
5947
6338
  if (!storeBuild) {
5948
6339
  if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
5949
6340
  return {
@@ -5968,7 +6359,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5968
6359
  is_store_build: true
5969
6360
  },
5970
6361
  previous: holder === null ? null : {
5971
- ...pick2(holder),
6362
+ ...pick3(holder),
5972
6363
  is_store_build: false
5973
6364
  }
5974
6365
  };
@@ -5990,7 +6381,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
5990
6381
  if (bundle !== null) await tx.delete("bundles", bundle);
5991
6382
  return {
5992
6383
  deleted: true,
5993
- nativeBuild: pick2(row)
6384
+ nativeBuild: pick3(row)
5994
6385
  };
5995
6386
  });
5996
6387
  },
@@ -6010,7 +6401,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6010
6401
  ...page2,
6011
6402
  ...after(input)
6012
6403
  });
6013
- return rows.map(pick2);
6404
+ return rows.map(pick3);
6014
6405
  }
6015
6406
  }), "createNativeBuildApi");
6016
6407
 
@@ -6560,6 +6951,7 @@ var createCoreApi = /* @__PURE__ */ __name((db, storage, options = {}) => {
6560
6951
  ...reads,
6561
6952
  ...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
6562
6953
  ...createNativeBuildApi(db, options),
6954
+ ...createIosDeviceApi(db, options),
6563
6955
  /** One read, which checks the schema settings first. */
6564
6956
  ready: /* @__PURE__ */ __name(async () => {
6565
6957
  await reads.listReleaseCatalogs({ limit: 1 });
@@ -6773,10 +7165,12 @@ var keyset = /* @__PURE__ */ __name((url, maxValue = LIMITS.maxValue) => {
6773
7165
  const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
6774
7166
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
6775
7167
  const cursor = url.searchParams.get("cursor");
7168
+ const through = url.searchParams.get("through");
6776
7169
  return {
6777
7170
  order,
6778
7171
  limit,
6779
- ...cursor === null ? {} : { after: cursor }
7172
+ ...cursor === null ? {} : { after: cursor },
7173
+ ...through === null ? {} : { through }
6780
7174
  };
6781
7175
  }, "keyset");
6782
7176
  var page = /* @__PURE__ */ __name((rows, { limit }, keyOf, extra = {}) => json({
@@ -6883,11 +7277,11 @@ var refusingInvalid = /* @__PURE__ */ __name(async (operation) => {
6883
7277
  try {
6884
7278
  return await operation();
6885
7279
  } catch (error) {
6886
- if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
7280
+ if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
6887
7281
  throw error;
6888
7282
  }
6889
7283
  }, "refusingInvalid");
6890
- var isNativeBuildRegistration = /* @__PURE__ */ __name((value) => isRecord3(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && isRecord3(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord3(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord3(value.embeddedBundle.metadata)), "isNativeBuildRegistration");
7284
+ var isNativeBuildRegistration = /* @__PURE__ */ __name((value) => isRecord3(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull(value.exportMethod)) && isRecord3(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord3(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord3(value.embeddedBundle.metadata)), "isNativeBuildRegistration");
6891
7285
  var scopeKeyOf = /* @__PURE__ */ __name((params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "", "scopeKeyOf");
6892
7286
  var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
6893
7287
  listBundles: onCore(async (core, request) => {
@@ -7049,6 +7443,81 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
7049
7443
  return json({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
7050
7444
  }),
7051
7445
  deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
7446
+ listIosDevices: onCore(async (core, request) => {
7447
+ const url = new URL(request.url);
7448
+ const input = keyset(url);
7449
+ const status = url.searchParams.get("status");
7450
+ return page(await refusingInvalid(() => core.listIosDevices({
7451
+ ...input,
7452
+ ...status === null ? {} : { status }
7453
+ })), input, ({ id }) => id);
7454
+ }),
7455
+ findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
7456
+ requestIosDevice: onCore(async (core, request) => {
7457
+ const input = await body(request);
7458
+ if (!isText(input.udid) || !isText(input.name) || !isTextOrNull(input.requestedBy)) throw new HandlerBadRequestError("An iOS device request needs udid, name, and requestedBy, an email or null.");
7459
+ const device = {
7460
+ udid: input.udid,
7461
+ name: input.name,
7462
+ requestedBy: input.requestedBy
7463
+ };
7464
+ return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
7465
+ }),
7466
+ approveIosDevice: onCore(async (core, request, params) => {
7467
+ const input = await body(request);
7468
+ if (!isTextOrNull(input.approvedBy) || input.name !== void 0 && !isText(input.name)) throw new HandlerBadRequestError("An iOS device approval needs approvedBy, an email or null, and an optional name.");
7469
+ const approval = {
7470
+ approvedBy: input.approvedBy,
7471
+ ...input.name === void 0 ? {} : { name: input.name }
7472
+ };
7473
+ return json({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
7474
+ }),
7475
+ renameIosDevice: onCore(async (core, request, params) => {
7476
+ const input = await body(request);
7477
+ if (!isText(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
7478
+ const name = input.name;
7479
+ return json({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
7480
+ }),
7481
+ recordIosDeviceOutcome: onCore(async (core, request, params) => {
7482
+ const input = await body(request);
7483
+ const seen = input.seen;
7484
+ if (!isRecord3(seen) || typeof seen.status !== "string" || !(seen.approvedAtMs === null || Number.isSafeInteger(seen.approvedAtMs)) || !isText(input.issuerId) || typeof input.outcome !== "string" || input.reason !== void 0 && typeof input.reason !== "string") throw new HandlerBadRequestError("An iOS device outcome needs seen { status, approvedAtMs }, issuerId, outcome, and an optional reason.");
7485
+ const outcome = {
7486
+ id: requireRouteParam(params, "id"),
7487
+ seen: {
7488
+ status: seen.status,
7489
+ approvedAtMs: seen.approvedAtMs
7490
+ },
7491
+ issuerId: input.issuerId,
7492
+ outcome: input.outcome,
7493
+ ...input.reason === void 0 ? {} : { reason: input.reason }
7494
+ };
7495
+ return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
7496
+ }),
7497
+ claimIosDeviceAccount: onCore(async (core, request) => {
7498
+ const { issuerId } = await body(request);
7499
+ if (!isText(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
7500
+ return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
7501
+ }),
7502
+ markIosDevicesInBuild: onCore(async (core, request) => {
7503
+ const { buildId, ids } = await body(request);
7504
+ if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
7505
+ await core.markIosDevicesInBuild({
7506
+ buildId,
7507
+ ids
7508
+ });
7509
+ return noContent();
7510
+ }),
7511
+ deleteIosDevice: onCore(async (core, request, params) => {
7512
+ const url = new URL(request.url);
7513
+ const status = url.searchParams.get("status");
7514
+ const requestedBy = url.searchParams.get("requestedBy");
7515
+ const only = {
7516
+ ...status === null ? {} : { status },
7517
+ ...requestedBy === null ? {} : { requestedBy }
7518
+ };
7519
+ return json({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
7520
+ }),
7052
7521
  deleteBundles: onCore(async (core, request) => {
7053
7522
  const { ids } = await body(request);
7054
7523
  if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
@@ -7201,6 +7670,51 @@ var ADMIN_ROUTES = [
7201
7670
  method: "DELETE",
7202
7671
  path: "/native-builds/:id",
7203
7672
  handler: "deleteNativeBuild"
7673
+ },
7674
+ {
7675
+ method: "GET",
7676
+ path: "/ios-devices",
7677
+ handler: "listIosDevices"
7678
+ },
7679
+ {
7680
+ method: "POST",
7681
+ path: "/ios-devices",
7682
+ handler: "requestIosDevice"
7683
+ },
7684
+ {
7685
+ method: "GET",
7686
+ path: "/ios-devices/udid/:udid",
7687
+ handler: "findIosDevice"
7688
+ },
7689
+ {
7690
+ method: "POST",
7691
+ path: "/ios-devices/in-build",
7692
+ handler: "markIosDevicesInBuild"
7693
+ },
7694
+ {
7695
+ method: "POST",
7696
+ path: "/ios-devices/account",
7697
+ handler: "claimIosDeviceAccount"
7698
+ },
7699
+ {
7700
+ method: "POST",
7701
+ path: "/ios-devices/:id/approval",
7702
+ handler: "approveIosDevice"
7703
+ },
7704
+ {
7705
+ method: "POST",
7706
+ path: "/ios-devices/:id/outcome",
7707
+ handler: "recordIosDeviceOutcome"
7708
+ },
7709
+ {
7710
+ method: "PATCH",
7711
+ path: "/ios-devices/:id",
7712
+ handler: "renameIosDevice"
7713
+ },
7714
+ {
7715
+ method: "DELETE",
7716
+ path: "/ios-devices/:id",
7717
+ handler: "deleteIosDevice"
7204
7718
  }
7205
7719
  ];
7206
7720