@hot-updater/aws 1.2.0-rc.27 → 1.2.0-rc.29

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 +583 -16
  2. package/package.json +8 -8
@@ -2406,7 +2406,11 @@ const channels = defineTable({
2406
2406
  * `is_sandbox` is true on a sandbox build, set when it registers and never
2407
2407
  * changed, and `sandbox_url_scheme` is the URL scheme its artifact registers,
2408
2408
  * which its preview links open; null on any other build, and on a sandbox
2409
- * build registered before the column, which registered the derived one. Boolean columns follow one rule: `is_*` for a fact about the row or
2409
+ * build registered before the column, which registered the derived one.
2410
+ * `export_method` is how an `.ipa` was exported, read from its profile when
2411
+ * it registers and never changed; null on any other artifact, on an `.ipa`
2412
+ * whose profile couldn't be read, and on one registered before the column.
2413
+ * Boolean columns follow one rule: `is_*` for a fact about the row or
2410
2414
  * `should_*` for an instruction to the client, never null; a unique index over
2411
2415
  * the rows where one is true keys a derived slot, not the boolean.
2412
2416
  */
@@ -2493,6 +2497,11 @@ const nativeBuilds = defineTable({
2493
2497
  maxLength: 255,
2494
2498
  ascii: true,
2495
2499
  required: false
2500
+ },
2501
+ export_method: {
2502
+ type: "string",
2503
+ maxLength: 16,
2504
+ required: false
2496
2505
  }
2497
2506
  }, {
2498
2507
  key: ["id"],
@@ -2529,6 +2538,115 @@ store_build_scope_key: {
2529
2538
  }
2530
2539
  }
2531
2540
  });
2541
+ /**
2542
+ * The iPhones a team asks to install ad hoc builds on. A row decides what the
2543
+ * CLI registers with Apple, not what an export includes: Xcode's automatic ad
2544
+ * hoc profile lists every device the Apple account has enabled. `status` is
2545
+ * `pending` until someone approves it, `approved` until a build or
2546
+ * `native-build devices add` registers it with Apple, then `registered`;
2547
+ * declining or removing one deletes its row. `udid` is the UDID in lower case.
2548
+ * `apple_issuer_id` is the App Store Connect issuer whose key registered it,
2549
+ * set once: a build signed by another account never registers these rows.
2550
+ * `apple_error` is Apple's refusal of the device, or why it stopped counting
2551
+ * it, cleared by the next success. `build_id` is the newest native build whose
2552
+ * .ipa the CLI checked lists it; deleting that build never touches the row.
2553
+ * It holds personal data: a UDID, a name, and the emails of who asked and who
2554
+ * approved, null for the CLI.
2555
+ */
2556
+ const iosDevices = defineTable({
2557
+ id: {
2558
+ type: "string",
2559
+ maxLength: 36
2560
+ },
2561
+ udid: {
2562
+ type: "string",
2563
+ maxLength: 40,
2564
+ ascii: true,
2565
+ unique: true
2566
+ },
2567
+ name: {
2568
+ type: "string",
2569
+ maxLength: 100
2570
+ },
2571
+ status: {
2572
+ type: "string",
2573
+ maxLength: 16
2574
+ },
2575
+ requested_by: {
2576
+ type: "string",
2577
+ maxLength: 320,
2578
+ required: false
2579
+ },
2580
+ created_at_ms: { type: "integer" },
2581
+ approved_by: {
2582
+ type: "string",
2583
+ maxLength: 320,
2584
+ required: false
2585
+ },
2586
+ approved_at_ms: {
2587
+ type: "integer",
2588
+ required: false
2589
+ },
2590
+ registered_at_ms: {
2591
+ type: "integer",
2592
+ required: false
2593
+ },
2594
+ apple_issuer_id: {
2595
+ type: "string",
2596
+ maxLength: 64,
2597
+ ascii: true,
2598
+ required: false
2599
+ },
2600
+ apple_error: {
2601
+ type: "string",
2602
+ maxLength: 512,
2603
+ required: false
2604
+ },
2605
+ build_id: {
2606
+ type: "string",
2607
+ maxLength: 36,
2608
+ required: false
2609
+ }
2610
+ }, {
2611
+ key: ["id"],
2612
+ indexes: {
2613
+ byStatus: {
2614
+ eq: ["status"],
2615
+ sort: ["id"]
2616
+ },
2617
+ all: {
2618
+ eq: [],
2619
+ sort: ["id"]
2620
+ }
2621
+ }
2622
+ });
2623
+ /**
2624
+ * The Apple account the iOS device registry belongs to: one row, keyed
2625
+ * `registry`, holding the App Store Connect issuer that first registered a
2626
+ * device. A build claims it before it sends Apple anything, and its key makes
2627
+ * the claim atomic on every store, so two builds of two accounts can't both
2628
+ * spend a slot; another account's build then registers nothing. Removing
2629
+ * devices never releases it.
2630
+ */
2631
+ const iosDeviceAccount = defineTable({
2632
+ id: {
2633
+ type: "string",
2634
+ maxLength: 16,
2635
+ ascii: true
2636
+ },
2637
+ apple_issuer_id: {
2638
+ type: "string",
2639
+ maxLength: 64,
2640
+ ascii: true
2641
+ },
2642
+ claimed_at_ms: { type: "integer" }
2643
+ }, {
2644
+ key: ["id"],
2645
+ indexes: { all: {
2646
+ eq: [],
2647
+ sort: ["id"]
2648
+ } }
2649
+ });
2532
2650
  /** Core's module: always installed, never a plugin. */
2533
2651
  const coreModule = {
2534
2652
  id: "core",
@@ -2549,7 +2667,9 @@ const coreModule = {
2549
2667
  sort: []
2550
2668
  } }
2551
2669
  }),
2552
- native_builds: nativeBuilds
2670
+ native_builds: nativeBuilds,
2671
+ ios_devices: iosDevices,
2672
+ ios_device_account: iosDeviceAccount
2553
2673
  }
2554
2674
  };
2555
2675
  //#endregion
@@ -4654,7 +4774,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
4654
4774
  };
4655
4775
  //#endregion
4656
4776
  //#region ../../packages/server/dist/version.mjs
4657
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.27";
4777
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.29";
4658
4778
  //#endregion
4659
4779
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
4660
4780
  /**
@@ -5447,8 +5567,8 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
5447
5567
  //#endregion
5448
5568
  //#region ../../packages/server/dist/core/reads.mjs
5449
5569
  const PAGE$3 = 500;
5450
- const pick$1 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
5451
- const toBundleRow = pick$1([
5570
+ const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
5571
+ const toBundleRow = pick$2([
5452
5572
  "id",
5453
5573
  "platform",
5454
5574
  "git_commit_hash",
@@ -5457,7 +5577,7 @@ const toBundleRow = pick$1([
5457
5577
  "manifest_file_hash",
5458
5578
  "asset_base_storage_uri"
5459
5579
  ]);
5460
- const toPatchRow = pick$1([
5580
+ const toPatchRow = pick$2([
5461
5581
  "id",
5462
5582
  "bundle_id",
5463
5583
  "base_bundle_id",
@@ -5467,7 +5587,7 @@ const toPatchRow = pick$1([
5467
5587
  "byte_size",
5468
5588
  "order_index"
5469
5589
  ]);
5470
- const toReleaseRow = pick$1([
5590
+ const toReleaseRow = pick$2([
5471
5591
  "id",
5472
5592
  "revision",
5473
5593
  "scope_key",
@@ -5488,7 +5608,7 @@ const toReleaseRow = pick$1([
5488
5608
  "created_at_ms",
5489
5609
  "updated_at_ms"
5490
5610
  ]);
5491
- const toCatalogRow = pick$1([
5611
+ const toCatalogRow = pick$2([
5492
5612
  "scope_key",
5493
5613
  "catalog_id",
5494
5614
  "strategy",
@@ -5503,7 +5623,7 @@ const toCatalogRow = pick$1([
5503
5623
  "is_tombstone",
5504
5624
  "updated_at_ms"
5505
5625
  ]);
5506
- const toChannelRow = pick$1(["id", "name"]);
5626
+ const toChannelRow = pick$2(["id", "name"]);
5507
5627
  /** Every page of one read, in order. */
5508
5628
  const drain$1 = async (read) => {
5509
5629
  const rows = [];
@@ -5516,7 +5636,15 @@ const drain$1 = async (read) => {
5516
5636
  return rows;
5517
5637
  };
5518
5638
  /** A keyset page's range: the keys strictly after `after`, in `order`. */
5519
- const after = (input) => input.after === void 0 ? {} : { range: (input.order ?? "asc") === "asc" ? { gt: input.after } : { lt: input.after } };
5639
+ /** A keyset read's range on its index's order: past `after`, up to `through`. */
5640
+ const after = (input) => {
5641
+ const asc = (input.order ?? "asc") === "asc";
5642
+ const range = {
5643
+ ...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
5644
+ ...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
5645
+ };
5646
+ return Object.keys(range).length === 0 ? {} : { range };
5647
+ };
5520
5648
  /** Core's reads, each through one declared index or key. */
5521
5649
  const createCoreReads = (db, storage) => {
5522
5650
  /** A bundle row's patches, exactly as many as its reference counter holds. */
@@ -5721,6 +5849,309 @@ const createCoreReads = (db, storage) => {
5721
5849
  };
5722
5850
  };
5723
5851
  //#endregion
5852
+ //#region ../../packages/server/dist/core/iosDevices.mjs
5853
+ /**
5854
+ * A device's UDID: 40 hex digits, or 8 and 16 joined by a hyphen. The same
5855
+ * rule as `normalizeIosUdid` of `@hot-updater/protocol/native-artifact`,
5856
+ * implemented here so the server's runtime never loads the artifact readers.
5857
+ */
5858
+ const UDID = /^(?:[0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16})$/iu;
5859
+ /** The form the registry stores and compares a UDID in, or null for text that isn't one. */
5860
+ const normalizeIosUdid = (value) => {
5861
+ const trimmed = value.trim();
5862
+ return UDID.test(trimmed) ? trimmed.toLowerCase() : null;
5863
+ };
5864
+ /** `ios_devices.name`'s bound in core's schema. */
5865
+ const NAME_MAX_LENGTH = 100;
5866
+ /** `ios_devices.requested_by` and `approved_by`'s bound: an email address. */
5867
+ const EMAIL_MAX_LENGTH = 320;
5868
+ /** `ios_devices.apple_issuer_id`'s bound. */
5869
+ const ISSUER_MAX_LENGTH = 64;
5870
+ /** How many registry rows one read takes while finding its account. */
5871
+ const ACCOUNT_SCAN_PAGE = 200;
5872
+ /** The one row of `ios_device_account`. */
5873
+ const ACCOUNT_ROW = "registry";
5874
+ /** `ios_devices.apple_error`'s bound. */
5875
+ const ERROR_MAX_LENGTH = 512;
5876
+ const STATUSES = [
5877
+ "pending",
5878
+ "approved",
5879
+ "registered"
5880
+ ];
5881
+ const OUTCOMES = [
5882
+ "registered",
5883
+ "refused",
5884
+ "disabled",
5885
+ "missing"
5886
+ ];
5887
+ /** The `apple_error` of a device Apple has disabled. */
5888
+ const IOS_DEVICE_DISABLED_ERROR = "Disabled in the Apple account.";
5889
+ /** The `apple_error` of a registered device Apple no longer lists. */
5890
+ const IOS_DEVICE_MISSING_ERROR = "Gone from the Apple account. Approve it again to register it.";
5891
+ /** A device or registry request core cannot store: the caller's input. */
5892
+ var IosDeviceInputError = class extends TypeError {
5893
+ name = "IosDeviceInputError";
5894
+ };
5895
+ const pick$1 = (row) => ({
5896
+ id: row.id,
5897
+ udid: row.udid,
5898
+ name: row.name,
5899
+ status: row.status,
5900
+ requested_by: row.requested_by ?? null,
5901
+ created_at_ms: row.created_at_ms,
5902
+ approved_by: row.approved_by ?? null,
5903
+ approved_at_ms: row.approved_at_ms ?? null,
5904
+ registered_at_ms: row.registered_at_ms ?? null,
5905
+ apple_issuer_id: row.apple_issuer_id ?? null,
5906
+ apple_error: row.apple_error ?? null,
5907
+ build_id: row.build_id ?? null
5908
+ });
5909
+ const udidOf = (udid) => {
5910
+ const key = typeof udid === "string" ? normalizeIosUdid(udid) : null;
5911
+ if (key === null) throw new IosDeviceInputError("Invalid iOS device: udid must be 40 hex digits, or 8 and 16 joined by a hyphen.");
5912
+ return key;
5913
+ };
5914
+ const nameOf$1 = (name) => {
5915
+ const trimmed = typeof name === "string" ? name.trim() : "";
5916
+ if (trimmed.length === 0 || trimmed.length > NAME_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: name must be 1 to ${NAME_MAX_LENGTH} characters.`);
5917
+ return trimmed;
5918
+ };
5919
+ /** An email, lower-cased, or null for the CLI. */
5920
+ const personOf = (value, field) => {
5921
+ if (value === null) return null;
5922
+ const email = typeof value === "string" ? value.trim().toLowerCase() : "";
5923
+ 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.`);
5924
+ return email;
5925
+ };
5926
+ /** Apple's words, on one line and within the column's bound. */
5927
+ const errorText = (text) => {
5928
+ const line = text.replace(/\s+/gu, " ").trim();
5929
+ return line.length > ERROR_MAX_LENGTH ? `${line.slice(0, 511)}…` : line;
5930
+ };
5931
+ /**
5932
+ * The iOS device registry: the iPhones and iPads a team asked to install ad hoc
5933
+ * builds on. The Console writes requests and approvals, and the CLI what Apple
5934
+ * said, each over the row it read.
5935
+ */
5936
+ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
5937
+ const findIosDevice = async (udid) => {
5938
+ const key = normalizeIosUdid(udid);
5939
+ if (key === null) return null;
5940
+ const row = await db.findOne("ios_devices", { udid: key });
5941
+ return row === null ? null : pick$1(row);
5942
+ };
5943
+ /**
5944
+ * The issuer of the registry's earliest registration among its rows, by
5945
+ * when and then by ID, or null when no row names one: read only while the
5946
+ * registry has no account yet, a page at a time.
5947
+ */
5948
+ const accountOfRows = async () => {
5949
+ let earliest = null;
5950
+ for (let after;;) {
5951
+ const { rows } = await db.findMany("ios_devices", {
5952
+ index: "all",
5953
+ where: {},
5954
+ order: "asc",
5955
+ limit: ACCOUNT_SCAN_PAGE,
5956
+ ...after === void 0 ? {} : { range: { gt: after } }
5957
+ });
5958
+ for (const row of rows.map(pick$1)) {
5959
+ if (row.apple_issuer_id === null) continue;
5960
+ if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
5961
+ }
5962
+ if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
5963
+ after = rows.at(-1).id;
5964
+ }
5965
+ };
5966
+ return {
5967
+ async listIosDevices(input) {
5968
+ if (input.status !== void 0 && !STATUSES.includes(input.status)) throw new IosDeviceInputError(`Invalid iOS device status: ${String(input.status)}. Expected ${STATUSES.join(", ")}.`);
5969
+ const page = {
5970
+ order: input.order ?? "asc",
5971
+ limit: input.limit,
5972
+ ...after(input)
5973
+ };
5974
+ const { rows } = input.status === void 0 ? await db.findMany("ios_devices", {
5975
+ index: "all",
5976
+ where: {},
5977
+ ...page
5978
+ }) : await db.findMany("ios_devices", {
5979
+ index: "byStatus",
5980
+ where: { status: input.status },
5981
+ ...page
5982
+ });
5983
+ return rows.map(pick$1);
5984
+ },
5985
+ findIosDevice,
5986
+ async requestIosDevice(input) {
5987
+ const udid = udidOf(input.udid);
5988
+ const name = nameOf$1(input.name);
5989
+ const requestedBy = personOf(input.requestedBy, "requestedBy");
5990
+ const existing = await db.findOne("ios_devices", { udid });
5991
+ if (existing !== null) return {
5992
+ device: pick$1(existing),
5993
+ created: false
5994
+ };
5995
+ const device = {
5996
+ id: createUUIDv7(),
5997
+ udid,
5998
+ name,
5999
+ status: "pending",
6000
+ requested_by: requestedBy,
6001
+ created_at_ms: now(),
6002
+ approved_by: null,
6003
+ approved_at_ms: null,
6004
+ registered_at_ms: null,
6005
+ apple_issuer_id: null,
6006
+ apple_error: null,
6007
+ build_id: null
6008
+ };
6009
+ try {
6010
+ await db.transaction(async (tx) => {
6011
+ tx.create("ios_devices", device);
6012
+ });
6013
+ } catch (error) {
6014
+ if (error instanceof DatabaseConstraintError && error.reason === "unique") {
6015
+ const winner = await db.findOne("ios_devices", { udid });
6016
+ if (winner !== null) return {
6017
+ device: pick$1(winner),
6018
+ created: false
6019
+ };
6020
+ }
6021
+ throw error;
6022
+ }
6023
+ return {
6024
+ device,
6025
+ created: true
6026
+ };
6027
+ },
6028
+ async approveIosDevice(id, input) {
6029
+ const name = input.name === void 0 ? void 0 : nameOf$1(input.name);
6030
+ const approvedBy = personOf(input.approvedBy, "approvedBy");
6031
+ return db.transaction(async (tx) => {
6032
+ const row = await tx.findOne("ios_devices", { id });
6033
+ if (row === null) return null;
6034
+ const device = pick$1(row);
6035
+ const set = {
6036
+ ...name === void 0 || name === device.name ? {} : { name },
6037
+ ...device.status === "pending" ? {
6038
+ status: "approved",
6039
+ approved_by: approvedBy,
6040
+ approved_at_ms: now()
6041
+ } : {}
6042
+ };
6043
+ if (Object.keys(set).length === 0) return device;
6044
+ tx.update("ios_devices", row, set);
6045
+ return {
6046
+ ...device,
6047
+ ...set
6048
+ };
6049
+ });
6050
+ },
6051
+ async renameIosDevice(id, input) {
6052
+ const name = nameOf$1(input);
6053
+ return db.transaction(async (tx) => {
6054
+ const row = await tx.findOne("ios_devices", { id });
6055
+ if (row === null) return null;
6056
+ const device = pick$1(row);
6057
+ if (device.name === name) return device;
6058
+ tx.update("ios_devices", row, { name });
6059
+ return {
6060
+ ...device,
6061
+ name
6062
+ };
6063
+ });
6064
+ },
6065
+ async recordIosDeviceOutcome({ id, seen, issuerId, outcome, reason }) {
6066
+ if (!OUTCOMES.includes(outcome)) throw new IosDeviceInputError(`Invalid iOS device outcome: ${String(outcome)}. Expected ${OUTCOMES.join(", ")}.`);
6067
+ 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.`);
6068
+ return db.transaction(async (tx) => {
6069
+ const row = await tx.findOne("ios_devices", { id });
6070
+ if (row === null) return null;
6071
+ const device = pick$1(row);
6072
+ if (device.status !== seen.status || device.approved_at_ms !== seen.approvedAtMs || device.apple_issuer_id !== null && device.apple_issuer_id !== issuerId) return null;
6073
+ let set;
6074
+ switch (outcome) {
6075
+ case "registered":
6076
+ if (device.status === "pending") return null;
6077
+ set = {
6078
+ status: "registered",
6079
+ registered_at_ms: device.registered_at_ms ?? now(),
6080
+ apple_issuer_id: issuerId,
6081
+ apple_error: null
6082
+ };
6083
+ break;
6084
+ case "refused":
6085
+ if (device.status !== "approved") return null;
6086
+ set = { apple_error: errorText(reason === void 0 || reason.trim() === "" ? "Apple refused it." : reason) };
6087
+ break;
6088
+ case "disabled":
6089
+ if (device.status === "pending") return null;
6090
+ set = { apple_error: IOS_DEVICE_DISABLED_ERROR };
6091
+ break;
6092
+ case "missing":
6093
+ if (device.status !== "registered") return null;
6094
+ set = {
6095
+ status: "pending",
6096
+ approved_by: null,
6097
+ approved_at_ms: null,
6098
+ apple_error: IOS_DEVICE_MISSING_ERROR
6099
+ };
6100
+ }
6101
+ if (Object.entries(set).some(([column, value]) => device[column] !== (value ?? null))) tx.update("ios_devices", row, set);
6102
+ return {
6103
+ ...device,
6104
+ ...set
6105
+ };
6106
+ });
6107
+ },
6108
+ async markIosDevicesInBuild({ buildId, ids }) {
6109
+ for (const id of new Set(ids)) await db.transaction(async (tx) => {
6110
+ const row = await tx.findOne("ios_devices", { id });
6111
+ if (row === null || typeof row.build_id === "string" && row.build_id >= buildId) return;
6112
+ tx.update("ios_devices", row, { build_id: buildId });
6113
+ });
6114
+ },
6115
+ async claimIosDeviceAccount(issuerId) {
6116
+ 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.`);
6117
+ const answer = (held) => ({
6118
+ issuerId: held,
6119
+ claimed: held === issuerId
6120
+ });
6121
+ const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
6122
+ if (existing !== null) return answer(existing.apple_issuer_id);
6123
+ const holder = await accountOfRows() ?? issuerId;
6124
+ try {
6125
+ await db.transaction(async (tx) => {
6126
+ tx.create("ios_device_account", {
6127
+ id: ACCOUNT_ROW,
6128
+ apple_issuer_id: holder,
6129
+ claimed_at_ms: now()
6130
+ });
6131
+ });
6132
+ return answer(holder);
6133
+ } catch (error) {
6134
+ if (error instanceof DatabaseConstraintError && (error.reason === "exists" || error.reason === "unique")) {
6135
+ const winner = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
6136
+ if (winner !== null) return answer(winner.apple_issuer_id);
6137
+ }
6138
+ throw error;
6139
+ }
6140
+ },
6141
+ async deleteIosDevice(id, only) {
6142
+ const requestedBy = only?.requestedBy === void 0 ? void 0 : personOf(only.requestedBy, "requestedBy");
6143
+ return db.transaction(async (tx) => {
6144
+ const row = await tx.findOne("ios_devices", { id });
6145
+ if (row === null) return null;
6146
+ const device = pick$1(row);
6147
+ if (only?.status !== void 0 && device.status !== only.status || requestedBy !== void 0 && device.requested_by !== requestedBy) return null;
6148
+ await tx.delete("ios_devices", row);
6149
+ return device;
6150
+ });
6151
+ }
6152
+ };
6153
+ };
6154
+ //#endregion
5724
6155
  //#region ../../packages/server/dist/core/nativeBuildDestinations.mjs
5725
6156
  /** Store destinations accepted for each native platform. */
5726
6157
  const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
@@ -5881,8 +6312,16 @@ const pick = (row) => ({
5881
6312
  submitted_version: row.submitted_version ?? null,
5882
6313
  is_store_build: row.is_store_build === true,
5883
6314
  is_sandbox: row.is_sandbox === true,
5884
- sandbox_url_scheme: row.sandbox_url_scheme ?? null
6315
+ sandbox_url_scheme: row.sandbox_url_scheme ?? null,
6316
+ export_method: row.export_method ?? null
5885
6317
  });
6318
+ /** The export methods an `.ipa` registers with. */
6319
+ const EXPORT_METHODS = /* @__PURE__ */ new Set([
6320
+ "app-store",
6321
+ "ad-hoc",
6322
+ "development",
6323
+ "enterprise"
6324
+ ]);
5886
6325
  /**
5887
6326
  * The channels only sandbox builds register on: a registration's `sandbox`
5888
6327
  * must agree with it. The registry's convention, as
@@ -5928,7 +6367,7 @@ const nativeBuildScopeKey = (scope) => {
5928
6367
  };
5929
6368
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
5930
6369
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
5931
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, artifact }) => {
6370
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, artifact }) => {
5932
6371
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
5933
6372
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
5934
6373
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
@@ -5947,6 +6386,10 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
5947
6386
  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`;
5948
6387
  const kinds = ARTIFACT_KINDS[platform];
5949
6388
  if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
6389
+ if (exportMethod !== void 0 && exportMethod !== null) {
6390
+ if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
6391
+ if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
6392
+ }
5950
6393
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
5951
6394
  return null;
5952
6395
  };
@@ -5978,7 +6421,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
5978
6421
  submitted_version: null,
5979
6422
  is_store_build: false,
5980
6423
  is_sandbox: registration.isSandbox === true,
5981
- sandbox_url_scheme: registration.sandboxUrlScheme ?? null
6424
+ sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
6425
+ export_method: registration.exportMethod ?? null
5982
6426
  };
5983
6427
  for (let attempt = 1;; attempt += 1) {
5984
6428
  await insertChannel(db, {
@@ -6725,6 +7169,7 @@ const createCoreApi = (db, storage, options = {}) => {
6725
7169
  ...reads,
6726
7170
  ...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
6727
7171
  ...createNativeBuildApi(db, options),
7172
+ ...createIosDeviceApi(db, options),
6728
7173
  /** One read, which checks the schema settings first. */
6729
7174
  ready: async () => {
6730
7175
  await reads.listReleaseCatalogs({ limit: 1 });
@@ -6944,10 +7389,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
6944
7389
  const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
6945
7390
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
6946
7391
  const cursor = url.searchParams.get("cursor");
7392
+ const through = url.searchParams.get("through");
6947
7393
  return {
6948
7394
  order,
6949
7395
  limit,
6950
- ...cursor === null ? {} : { after: cursor }
7396
+ ...cursor === null ? {} : { after: cursor },
7397
+ ...through === null ? {} : { through }
6951
7398
  };
6952
7399
  };
6953
7400
  /** A page and the cursor of the next one, when the page is full. */
@@ -7062,11 +7509,11 @@ const refusingInvalid = async (operation) => {
7062
7509
  try {
7063
7510
  return await operation();
7064
7511
  } catch (error) {
7065
- if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
7512
+ if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
7066
7513
  throw error;
7067
7514
  }
7068
7515
  };
7069
- const isNativeBuildRegistration = (value) => isRecord$5(value) && isText$2(value.id) && isText$2(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText$2(value.channel) && isTextOrNull$1(value.fingerprintHash) && isTextOrNull$1(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull$1(value.gitCommitHash) && isTextOrNull$1(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull$1(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull$1(value.sandboxUrlScheme)) && isRecord$5(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText$2(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord$5(value.embeddedBundle) && isText$2(value.embeddedBundle.manifestStorageUri) && isText$2(value.embeddedBundle.manifestFileHash) && isText$2(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord$5(value.embeddedBundle.metadata));
7516
+ const isNativeBuildRegistration = (value) => isRecord$5(value) && isText$2(value.id) && isText$2(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText$2(value.channel) && isTextOrNull$1(value.fingerprintHash) && isTextOrNull$1(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull$1(value.gitCommitHash) && isTextOrNull$1(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull$1(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull$1(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull$1(value.exportMethod)) && isRecord$5(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText$2(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord$5(value.embeddedBundle) && isText$2(value.embeddedBundle.manifestStorageUri) && isText$2(value.embeddedBundle.manifestFileHash) && isText$2(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord$5(value.embeddedBundle.metadata));
7070
7517
  const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
7071
7518
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
7072
7519
  const createAdminRouteHandlers = () => ({
@@ -7229,6 +7676,81 @@ const createAdminRouteHandlers = () => ({
7229
7676
  return json$2({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
7230
7677
  }),
7231
7678
  deleteNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
7679
+ listIosDevices: onCore(async (core, request) => {
7680
+ const url = new URL(request.url);
7681
+ const input = keyset(url);
7682
+ const status = url.searchParams.get("status");
7683
+ return page(await refusingInvalid(() => core.listIosDevices({
7684
+ ...input,
7685
+ ...status === null ? {} : { status }
7686
+ })), input, ({ id }) => id);
7687
+ }),
7688
+ findIosDevice: onCore(async (core, _request, params) => json$2({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
7689
+ requestIosDevice: onCore(async (core, request) => {
7690
+ const input = await body(request);
7691
+ if (!isText$2(input.udid) || !isText$2(input.name) || !isTextOrNull$1(input.requestedBy)) throw new HandlerBadRequestError("An iOS device request needs udid, name, and requestedBy, an email or null.");
7692
+ const device = {
7693
+ udid: input.udid,
7694
+ name: input.name,
7695
+ requestedBy: input.requestedBy
7696
+ };
7697
+ return json$2({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
7698
+ }),
7699
+ approveIosDevice: onCore(async (core, request, params) => {
7700
+ const input = await body(request);
7701
+ if (!isTextOrNull$1(input.approvedBy) || input.name !== void 0 && !isText$2(input.name)) throw new HandlerBadRequestError("An iOS device approval needs approvedBy, an email or null, and an optional name.");
7702
+ const approval = {
7703
+ approvedBy: input.approvedBy,
7704
+ ...input.name === void 0 ? {} : { name: input.name }
7705
+ };
7706
+ return json$2({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
7707
+ }),
7708
+ renameIosDevice: onCore(async (core, request, params) => {
7709
+ const input = await body(request);
7710
+ if (!isText$2(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
7711
+ const name = input.name;
7712
+ return json$2({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
7713
+ }),
7714
+ recordIosDeviceOutcome: onCore(async (core, request, params) => {
7715
+ const input = await body(request);
7716
+ const seen = input.seen;
7717
+ if (!isRecord$5(seen) || typeof seen.status !== "string" || !(seen.approvedAtMs === null || Number.isSafeInteger(seen.approvedAtMs)) || !isText$2(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.");
7718
+ const outcome = {
7719
+ id: requireRouteParam(params, "id"),
7720
+ seen: {
7721
+ status: seen.status,
7722
+ approvedAtMs: seen.approvedAtMs
7723
+ },
7724
+ issuerId: input.issuerId,
7725
+ outcome: input.outcome,
7726
+ ...input.reason === void 0 ? {} : { reason: input.reason }
7727
+ };
7728
+ return json$2({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
7729
+ }),
7730
+ claimIosDeviceAccount: onCore(async (core, request) => {
7731
+ const { issuerId } = await body(request);
7732
+ if (!isText$2(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
7733
+ return json$2({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
7734
+ }),
7735
+ markIosDevicesInBuild: onCore(async (core, request) => {
7736
+ const { buildId, ids } = await body(request);
7737
+ if (!isText$2(buildId) || !Array.isArray(ids) || !ids.every((id) => isText$2(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
7738
+ await core.markIosDevicesInBuild({
7739
+ buildId,
7740
+ ids
7741
+ });
7742
+ return noContent();
7743
+ }),
7744
+ deleteIosDevice: onCore(async (core, request, params) => {
7745
+ const url = new URL(request.url);
7746
+ const status = url.searchParams.get("status");
7747
+ const requestedBy = url.searchParams.get("requestedBy");
7748
+ const only = {
7749
+ ...status === null ? {} : { status },
7750
+ ...requestedBy === null ? {} : { requestedBy }
7751
+ };
7752
+ return json$2({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
7753
+ }),
7232
7754
  deleteBundles: onCore(async (core, request) => {
7233
7755
  const { ids } = await body(request);
7234
7756
  if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
@@ -7382,6 +7904,51 @@ const ADMIN_ROUTES = [
7382
7904
  method: "DELETE",
7383
7905
  path: "/native-builds/:id",
7384
7906
  handler: "deleteNativeBuild"
7907
+ },
7908
+ {
7909
+ method: "GET",
7910
+ path: "/ios-devices",
7911
+ handler: "listIosDevices"
7912
+ },
7913
+ {
7914
+ method: "POST",
7915
+ path: "/ios-devices",
7916
+ handler: "requestIosDevice"
7917
+ },
7918
+ {
7919
+ method: "GET",
7920
+ path: "/ios-devices/udid/:udid",
7921
+ handler: "findIosDevice"
7922
+ },
7923
+ {
7924
+ method: "POST",
7925
+ path: "/ios-devices/in-build",
7926
+ handler: "markIosDevicesInBuild"
7927
+ },
7928
+ {
7929
+ method: "POST",
7930
+ path: "/ios-devices/account",
7931
+ handler: "claimIosDeviceAccount"
7932
+ },
7933
+ {
7934
+ method: "POST",
7935
+ path: "/ios-devices/:id/approval",
7936
+ handler: "approveIosDevice"
7937
+ },
7938
+ {
7939
+ method: "POST",
7940
+ path: "/ios-devices/:id/outcome",
7941
+ handler: "recordIosDeviceOutcome"
7942
+ },
7943
+ {
7944
+ method: "PATCH",
7945
+ path: "/ios-devices/:id",
7946
+ handler: "renameIosDevice"
7947
+ },
7948
+ {
7949
+ method: "DELETE",
7950
+ path: "/ios-devices/:id",
7951
+ handler: "deleteIosDevice"
7385
7952
  }
7386
7953
  ];
7387
7954
  //#endregion
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.27",
4
+ "version": "1.2.0-rc.29",
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.27",
49
- "@hot-updater/mock": "1.2.0-rc.27",
50
- "@hot-updater/test-utils": "1.2.0-rc.27"
48
+ "@hot-updater/mock": "1.2.0-rc.29",
49
+ "@hot-updater/test-utils": "1.2.0-rc.29",
50
+ "@hot-updater/protocol": "1.2.0-rc.29"
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.27",
68
- "@hot-updater/plugin-core": "1.2.0-rc.27",
69
- "@hot-updater/server": "1.2.0-rc.27",
70
- "@hot-updater/storage-s3": "1.2.0-rc.27"
67
+ "@hot-updater/cli-tools": "1.2.0-rc.29",
68
+ "@hot-updater/plugin-core": "1.2.0-rc.29",
69
+ "@hot-updater/server": "1.2.0-rc.29",
70
+ "@hot-updater/storage-s3": "1.2.0-rc.29"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown",