@hot-updater/firebase 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.
@@ -2377,7 +2377,11 @@ const channels = defineTable({
2377
2377
  * `is_sandbox` is true on a sandbox build, set when it registers and never
2378
2378
  * changed, and `sandbox_url_scheme` is the URL scheme its artifact registers,
2379
2379
  * which its preview links open; null on any other build, and on a sandbox
2380
- * build registered before the column, which registered the derived one. Boolean columns follow one rule: `is_*` for a fact about the row or
2380
+ * build registered before the column, which registered the derived one.
2381
+ * `export_method` is how an `.ipa` was exported, read from its profile when
2382
+ * it registers and never changed; null on any other artifact, on an `.ipa`
2383
+ * whose profile couldn't be read, and on one registered before the column.
2384
+ * Boolean columns follow one rule: `is_*` for a fact about the row or
2381
2385
  * `should_*` for an instruction to the client, never null; a unique index over
2382
2386
  * the rows where one is true keys a derived slot, not the boolean.
2383
2387
  */
@@ -2464,6 +2468,11 @@ const nativeBuilds = defineTable({
2464
2468
  maxLength: 255,
2465
2469
  ascii: true,
2466
2470
  required: false
2471
+ },
2472
+ export_method: {
2473
+ type: "string",
2474
+ maxLength: 16,
2475
+ required: false
2467
2476
  }
2468
2477
  }, {
2469
2478
  key: ["id"],
@@ -2500,6 +2509,115 @@ store_build_scope_key: {
2500
2509
  }
2501
2510
  }
2502
2511
  });
2512
+ /**
2513
+ * The iPhones a team asks to install ad hoc builds on. A row decides what the
2514
+ * CLI registers with Apple, not what an export includes: Xcode's automatic ad
2515
+ * hoc profile lists every device the Apple account has enabled. `status` is
2516
+ * `pending` until someone approves it, `approved` until a build or
2517
+ * `native-build devices add` registers it with Apple, then `registered`;
2518
+ * declining or removing one deletes its row. `udid` is the UDID in lower case.
2519
+ * `apple_issuer_id` is the App Store Connect issuer whose key registered it,
2520
+ * set once: a build signed by another account never registers these rows.
2521
+ * `apple_error` is Apple's refusal of the device, or why it stopped counting
2522
+ * it, cleared by the next success. `build_id` is the newest native build whose
2523
+ * .ipa the CLI checked lists it; deleting that build never touches the row.
2524
+ * It holds personal data: a UDID, a name, and the emails of who asked and who
2525
+ * approved, null for the CLI.
2526
+ */
2527
+ const iosDevices = defineTable({
2528
+ id: {
2529
+ type: "string",
2530
+ maxLength: 36
2531
+ },
2532
+ udid: {
2533
+ type: "string",
2534
+ maxLength: 40,
2535
+ ascii: true,
2536
+ unique: true
2537
+ },
2538
+ name: {
2539
+ type: "string",
2540
+ maxLength: 100
2541
+ },
2542
+ status: {
2543
+ type: "string",
2544
+ maxLength: 16
2545
+ },
2546
+ requested_by: {
2547
+ type: "string",
2548
+ maxLength: 320,
2549
+ required: false
2550
+ },
2551
+ created_at_ms: { type: "integer" },
2552
+ approved_by: {
2553
+ type: "string",
2554
+ maxLength: 320,
2555
+ required: false
2556
+ },
2557
+ approved_at_ms: {
2558
+ type: "integer",
2559
+ required: false
2560
+ },
2561
+ registered_at_ms: {
2562
+ type: "integer",
2563
+ required: false
2564
+ },
2565
+ apple_issuer_id: {
2566
+ type: "string",
2567
+ maxLength: 64,
2568
+ ascii: true,
2569
+ required: false
2570
+ },
2571
+ apple_error: {
2572
+ type: "string",
2573
+ maxLength: 512,
2574
+ required: false
2575
+ },
2576
+ build_id: {
2577
+ type: "string",
2578
+ maxLength: 36,
2579
+ required: false
2580
+ }
2581
+ }, {
2582
+ key: ["id"],
2583
+ indexes: {
2584
+ byStatus: {
2585
+ eq: ["status"],
2586
+ sort: ["id"]
2587
+ },
2588
+ all: {
2589
+ eq: [],
2590
+ sort: ["id"]
2591
+ }
2592
+ }
2593
+ });
2594
+ /**
2595
+ * The Apple account the iOS device registry belongs to: one row, keyed
2596
+ * `registry`, holding the App Store Connect issuer that first registered a
2597
+ * device. A build claims it before it sends Apple anything, and its key makes
2598
+ * the claim atomic on every store, so two builds of two accounts can't both
2599
+ * spend a slot; another account's build then registers nothing. Removing
2600
+ * devices never releases it.
2601
+ */
2602
+ const iosDeviceAccount = defineTable({
2603
+ id: {
2604
+ type: "string",
2605
+ maxLength: 16,
2606
+ ascii: true
2607
+ },
2608
+ apple_issuer_id: {
2609
+ type: "string",
2610
+ maxLength: 64,
2611
+ ascii: true
2612
+ },
2613
+ claimed_at_ms: { type: "integer" }
2614
+ }, {
2615
+ key: ["id"],
2616
+ indexes: { all: {
2617
+ eq: [],
2618
+ sort: ["id"]
2619
+ } }
2620
+ });
2503
2621
  /** Core's module: always installed, never a plugin. */
2504
2622
  const coreModule = {
2505
2623
  id: "core",
@@ -2520,7 +2638,9 @@ const coreModule = {
2520
2638
  sort: []
2521
2639
  } }
2522
2640
  }),
2523
- native_builds: nativeBuilds
2641
+ native_builds: nativeBuilds,
2642
+ ios_devices: iosDevices,
2643
+ ios_device_account: iosDeviceAccount
2524
2644
  }
2525
2645
  };
2526
2646
  //#endregion
@@ -4625,7 +4745,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
4625
4745
  };
4626
4746
  //#endregion
4627
4747
  //#region ../../packages/server/dist/version.mjs
4628
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.27";
4748
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.28";
4629
4749
  //#endregion
4630
4750
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
4631
4751
  /**
@@ -5418,8 +5538,8 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
5418
5538
  //#endregion
5419
5539
  //#region ../../packages/server/dist/core/reads.mjs
5420
5540
  const PAGE$3 = 500;
5421
- const pick$1 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
5422
- const toBundleRow = pick$1([
5541
+ const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
5542
+ const toBundleRow = pick$2([
5423
5543
  "id",
5424
5544
  "platform",
5425
5545
  "git_commit_hash",
@@ -5428,7 +5548,7 @@ const toBundleRow = pick$1([
5428
5548
  "manifest_file_hash",
5429
5549
  "asset_base_storage_uri"
5430
5550
  ]);
5431
- const toPatchRow = pick$1([
5551
+ const toPatchRow = pick$2([
5432
5552
  "id",
5433
5553
  "bundle_id",
5434
5554
  "base_bundle_id",
@@ -5438,7 +5558,7 @@ const toPatchRow = pick$1([
5438
5558
  "byte_size",
5439
5559
  "order_index"
5440
5560
  ]);
5441
- const toReleaseRow = pick$1([
5561
+ const toReleaseRow = pick$2([
5442
5562
  "id",
5443
5563
  "revision",
5444
5564
  "scope_key",
@@ -5459,7 +5579,7 @@ const toReleaseRow = pick$1([
5459
5579
  "created_at_ms",
5460
5580
  "updated_at_ms"
5461
5581
  ]);
5462
- const toCatalogRow = pick$1([
5582
+ const toCatalogRow = pick$2([
5463
5583
  "scope_key",
5464
5584
  "catalog_id",
5465
5585
  "strategy",
@@ -5474,7 +5594,7 @@ const toCatalogRow = pick$1([
5474
5594
  "is_tombstone",
5475
5595
  "updated_at_ms"
5476
5596
  ]);
5477
- const toChannelRow = pick$1(["id", "name"]);
5597
+ const toChannelRow = pick$2(["id", "name"]);
5478
5598
  /** Every page of one read, in order. */
5479
5599
  const drain$1 = async (read) => {
5480
5600
  const rows = [];
@@ -5487,7 +5607,15 @@ const drain$1 = async (read) => {
5487
5607
  return rows;
5488
5608
  };
5489
5609
  /** A keyset page's range: the keys strictly after `after`, in `order`. */
5490
- const after = (input) => input.after === void 0 ? {} : { range: (input.order ?? "asc") === "asc" ? { gt: input.after } : { lt: input.after } };
5610
+ /** A keyset read's range on its index's order: past `after`, up to `through`. */
5611
+ const after = (input) => {
5612
+ const asc = (input.order ?? "asc") === "asc";
5613
+ const range = {
5614
+ ...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
5615
+ ...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
5616
+ };
5617
+ return Object.keys(range).length === 0 ? {} : { range };
5618
+ };
5491
5619
  /** Core's reads, each through one declared index or key. */
5492
5620
  const createCoreReads = (db, storage) => {
5493
5621
  /** A bundle row's patches, exactly as many as its reference counter holds. */
@@ -5692,6 +5820,309 @@ const createCoreReads = (db, storage) => {
5692
5820
  };
5693
5821
  };
5694
5822
  //#endregion
5823
+ //#region ../../packages/server/dist/core/iosDevices.mjs
5824
+ /**
5825
+ * A device's UDID: 40 hex digits, or 8 and 16 joined by a hyphen. The same
5826
+ * rule as `normalizeIosUdid` of `@hot-updater/protocol/native-artifact`,
5827
+ * implemented here so the server's runtime never loads the artifact readers.
5828
+ */
5829
+ const UDID = /^(?:[0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16})$/iu;
5830
+ /** The form the registry stores and compares a UDID in, or null for text that isn't one. */
5831
+ const normalizeIosUdid = (value) => {
5832
+ const trimmed = value.trim();
5833
+ return UDID.test(trimmed) ? trimmed.toLowerCase() : null;
5834
+ };
5835
+ /** `ios_devices.name`'s bound in core's schema. */
5836
+ const NAME_MAX_LENGTH = 100;
5837
+ /** `ios_devices.requested_by` and `approved_by`'s bound: an email address. */
5838
+ const EMAIL_MAX_LENGTH = 320;
5839
+ /** `ios_devices.apple_issuer_id`'s bound. */
5840
+ const ISSUER_MAX_LENGTH = 64;
5841
+ /** How many registry rows one read takes while finding its account. */
5842
+ const ACCOUNT_SCAN_PAGE = 200;
5843
+ /** The one row of `ios_device_account`. */
5844
+ const ACCOUNT_ROW = "registry";
5845
+ /** `ios_devices.apple_error`'s bound. */
5846
+ const ERROR_MAX_LENGTH = 512;
5847
+ const STATUSES = [
5848
+ "pending",
5849
+ "approved",
5850
+ "registered"
5851
+ ];
5852
+ const OUTCOMES = [
5853
+ "registered",
5854
+ "refused",
5855
+ "disabled",
5856
+ "missing"
5857
+ ];
5858
+ /** The `apple_error` of a device Apple has disabled. */
5859
+ const IOS_DEVICE_DISABLED_ERROR = "Disabled in the Apple account.";
5860
+ /** The `apple_error` of a registered device Apple no longer lists. */
5861
+ const IOS_DEVICE_MISSING_ERROR = "Gone from the Apple account. Approve it again to register it.";
5862
+ /** A device or registry request core cannot store: the caller's input. */
5863
+ var IosDeviceInputError = class extends TypeError {
5864
+ name = "IosDeviceInputError";
5865
+ };
5866
+ const pick$1 = (row) => ({
5867
+ id: row.id,
5868
+ udid: row.udid,
5869
+ name: row.name,
5870
+ status: row.status,
5871
+ requested_by: row.requested_by ?? null,
5872
+ created_at_ms: row.created_at_ms,
5873
+ approved_by: row.approved_by ?? null,
5874
+ approved_at_ms: row.approved_at_ms ?? null,
5875
+ registered_at_ms: row.registered_at_ms ?? null,
5876
+ apple_issuer_id: row.apple_issuer_id ?? null,
5877
+ apple_error: row.apple_error ?? null,
5878
+ build_id: row.build_id ?? null
5879
+ });
5880
+ const udidOf = (udid) => {
5881
+ const key = typeof udid === "string" ? normalizeIosUdid(udid) : null;
5882
+ if (key === null) throw new IosDeviceInputError("Invalid iOS device: udid must be 40 hex digits, or 8 and 16 joined by a hyphen.");
5883
+ return key;
5884
+ };
5885
+ const nameOf = (name) => {
5886
+ const trimmed = typeof name === "string" ? name.trim() : "";
5887
+ if (trimmed.length === 0 || trimmed.length > NAME_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: name must be 1 to ${NAME_MAX_LENGTH} characters.`);
5888
+ return trimmed;
5889
+ };
5890
+ /** An email, lower-cased, or null for the CLI. */
5891
+ const personOf = (value, field) => {
5892
+ if (value === null) return null;
5893
+ const email = typeof value === "string" ? value.trim().toLowerCase() : "";
5894
+ 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.`);
5895
+ return email;
5896
+ };
5897
+ /** Apple's words, on one line and within the column's bound. */
5898
+ const errorText = (text) => {
5899
+ const line = text.replace(/\s+/gu, " ").trim();
5900
+ return line.length > ERROR_MAX_LENGTH ? `${line.slice(0, 511)}…` : line;
5901
+ };
5902
+ /**
5903
+ * The iOS device registry: the iPhones and iPads a team asked to install ad hoc
5904
+ * builds on. The Console writes requests and approvals, and the CLI what Apple
5905
+ * said, each over the row it read.
5906
+ */
5907
+ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
5908
+ const findIosDevice = async (udid) => {
5909
+ const key = normalizeIosUdid(udid);
5910
+ if (key === null) return null;
5911
+ const row = await db.findOne("ios_devices", { udid: key });
5912
+ return row === null ? null : pick$1(row);
5913
+ };
5914
+ /**
5915
+ * The issuer of the registry's earliest registration among its rows, by
5916
+ * when and then by ID, or null when no row names one: read only while the
5917
+ * registry has no account yet, a page at a time.
5918
+ */
5919
+ const accountOfRows = async () => {
5920
+ let earliest = null;
5921
+ for (let after;;) {
5922
+ const { rows } = await db.findMany("ios_devices", {
5923
+ index: "all",
5924
+ where: {},
5925
+ order: "asc",
5926
+ limit: ACCOUNT_SCAN_PAGE,
5927
+ ...after === void 0 ? {} : { range: { gt: after } }
5928
+ });
5929
+ for (const row of rows.map(pick$1)) {
5930
+ if (row.apple_issuer_id === null) continue;
5931
+ if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
5932
+ }
5933
+ if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
5934
+ after = rows.at(-1).id;
5935
+ }
5936
+ };
5937
+ return {
5938
+ async listIosDevices(input) {
5939
+ if (input.status !== void 0 && !STATUSES.includes(input.status)) throw new IosDeviceInputError(`Invalid iOS device status: ${String(input.status)}. Expected ${STATUSES.join(", ")}.`);
5940
+ const page = {
5941
+ order: input.order ?? "asc",
5942
+ limit: input.limit,
5943
+ ...after(input)
5944
+ };
5945
+ const { rows } = input.status === void 0 ? await db.findMany("ios_devices", {
5946
+ index: "all",
5947
+ where: {},
5948
+ ...page
5949
+ }) : await db.findMany("ios_devices", {
5950
+ index: "byStatus",
5951
+ where: { status: input.status },
5952
+ ...page
5953
+ });
5954
+ return rows.map(pick$1);
5955
+ },
5956
+ findIosDevice,
5957
+ async requestIosDevice(input) {
5958
+ const udid = udidOf(input.udid);
5959
+ const name = nameOf(input.name);
5960
+ const requestedBy = personOf(input.requestedBy, "requestedBy");
5961
+ const existing = await db.findOne("ios_devices", { udid });
5962
+ if (existing !== null) return {
5963
+ device: pick$1(existing),
5964
+ created: false
5965
+ };
5966
+ const device = {
5967
+ id: createUUIDv7(),
5968
+ udid,
5969
+ name,
5970
+ status: "pending",
5971
+ requested_by: requestedBy,
5972
+ created_at_ms: now(),
5973
+ approved_by: null,
5974
+ approved_at_ms: null,
5975
+ registered_at_ms: null,
5976
+ apple_issuer_id: null,
5977
+ apple_error: null,
5978
+ build_id: null
5979
+ };
5980
+ try {
5981
+ await db.transaction(async (tx) => {
5982
+ tx.create("ios_devices", device);
5983
+ });
5984
+ } catch (error) {
5985
+ if (error instanceof DatabaseConstraintError && error.reason === "unique") {
5986
+ const winner = await db.findOne("ios_devices", { udid });
5987
+ if (winner !== null) return {
5988
+ device: pick$1(winner),
5989
+ created: false
5990
+ };
5991
+ }
5992
+ throw error;
5993
+ }
5994
+ return {
5995
+ device,
5996
+ created: true
5997
+ };
5998
+ },
5999
+ async approveIosDevice(id, input) {
6000
+ const name = input.name === void 0 ? void 0 : nameOf(input.name);
6001
+ const approvedBy = personOf(input.approvedBy, "approvedBy");
6002
+ return db.transaction(async (tx) => {
6003
+ const row = await tx.findOne("ios_devices", { id });
6004
+ if (row === null) return null;
6005
+ const device = pick$1(row);
6006
+ const set = {
6007
+ ...name === void 0 || name === device.name ? {} : { name },
6008
+ ...device.status === "pending" ? {
6009
+ status: "approved",
6010
+ approved_by: approvedBy,
6011
+ approved_at_ms: now()
6012
+ } : {}
6013
+ };
6014
+ if (Object.keys(set).length === 0) return device;
6015
+ tx.update("ios_devices", row, set);
6016
+ return {
6017
+ ...device,
6018
+ ...set
6019
+ };
6020
+ });
6021
+ },
6022
+ async renameIosDevice(id, input) {
6023
+ const name = nameOf(input);
6024
+ return db.transaction(async (tx) => {
6025
+ const row = await tx.findOne("ios_devices", { id });
6026
+ if (row === null) return null;
6027
+ const device = pick$1(row);
6028
+ if (device.name === name) return device;
6029
+ tx.update("ios_devices", row, { name });
6030
+ return {
6031
+ ...device,
6032
+ name
6033
+ };
6034
+ });
6035
+ },
6036
+ async recordIosDeviceOutcome({ id, seen, issuerId, outcome, reason }) {
6037
+ if (!OUTCOMES.includes(outcome)) throw new IosDeviceInputError(`Invalid iOS device outcome: ${String(outcome)}. Expected ${OUTCOMES.join(", ")}.`);
6038
+ 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.`);
6039
+ return db.transaction(async (tx) => {
6040
+ const row = await tx.findOne("ios_devices", { id });
6041
+ if (row === null) return null;
6042
+ const device = pick$1(row);
6043
+ if (device.status !== seen.status || device.approved_at_ms !== seen.approvedAtMs || device.apple_issuer_id !== null && device.apple_issuer_id !== issuerId) return null;
6044
+ let set;
6045
+ switch (outcome) {
6046
+ case "registered":
6047
+ if (device.status === "pending") return null;
6048
+ set = {
6049
+ status: "registered",
6050
+ registered_at_ms: device.registered_at_ms ?? now(),
6051
+ apple_issuer_id: issuerId,
6052
+ apple_error: null
6053
+ };
6054
+ break;
6055
+ case "refused":
6056
+ if (device.status !== "approved") return null;
6057
+ set = { apple_error: errorText(reason === void 0 || reason.trim() === "" ? "Apple refused it." : reason) };
6058
+ break;
6059
+ case "disabled":
6060
+ if (device.status === "pending") return null;
6061
+ set = { apple_error: IOS_DEVICE_DISABLED_ERROR };
6062
+ break;
6063
+ case "missing":
6064
+ if (device.status !== "registered") return null;
6065
+ set = {
6066
+ status: "pending",
6067
+ approved_by: null,
6068
+ approved_at_ms: null,
6069
+ apple_error: IOS_DEVICE_MISSING_ERROR
6070
+ };
6071
+ }
6072
+ if (Object.entries(set).some(([column, value]) => device[column] !== (value ?? null))) tx.update("ios_devices", row, set);
6073
+ return {
6074
+ ...device,
6075
+ ...set
6076
+ };
6077
+ });
6078
+ },
6079
+ async markIosDevicesInBuild({ buildId, ids }) {
6080
+ for (const id of new Set(ids)) await db.transaction(async (tx) => {
6081
+ const row = await tx.findOne("ios_devices", { id });
6082
+ if (row === null || typeof row.build_id === "string" && row.build_id >= buildId) return;
6083
+ tx.update("ios_devices", row, { build_id: buildId });
6084
+ });
6085
+ },
6086
+ async claimIosDeviceAccount(issuerId) {
6087
+ 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.`);
6088
+ const answer = (held) => ({
6089
+ issuerId: held,
6090
+ claimed: held === issuerId
6091
+ });
6092
+ const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
6093
+ if (existing !== null) return answer(existing.apple_issuer_id);
6094
+ const holder = await accountOfRows() ?? issuerId;
6095
+ try {
6096
+ await db.transaction(async (tx) => {
6097
+ tx.create("ios_device_account", {
6098
+ id: ACCOUNT_ROW,
6099
+ apple_issuer_id: holder,
6100
+ claimed_at_ms: now()
6101
+ });
6102
+ });
6103
+ return answer(holder);
6104
+ } catch (error) {
6105
+ if (error instanceof DatabaseConstraintError && (error.reason === "exists" || error.reason === "unique")) {
6106
+ const winner = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
6107
+ if (winner !== null) return answer(winner.apple_issuer_id);
6108
+ }
6109
+ throw error;
6110
+ }
6111
+ },
6112
+ async deleteIosDevice(id, only) {
6113
+ const requestedBy = only?.requestedBy === void 0 ? void 0 : personOf(only.requestedBy, "requestedBy");
6114
+ return db.transaction(async (tx) => {
6115
+ const row = await tx.findOne("ios_devices", { id });
6116
+ if (row === null) return null;
6117
+ const device = pick$1(row);
6118
+ if (only?.status !== void 0 && device.status !== only.status || requestedBy !== void 0 && device.requested_by !== requestedBy) return null;
6119
+ await tx.delete("ios_devices", row);
6120
+ return device;
6121
+ });
6122
+ }
6123
+ };
6124
+ };
6125
+ //#endregion
5695
6126
  //#region ../../packages/server/dist/core/nativeBuildDestinations.mjs
5696
6127
  /** Store destinations accepted for each native platform. */
5697
6128
  const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
@@ -5852,8 +6283,16 @@ const pick = (row) => ({
5852
6283
  submitted_version: row.submitted_version ?? null,
5853
6284
  is_store_build: row.is_store_build === true,
5854
6285
  is_sandbox: row.is_sandbox === true,
5855
- sandbox_url_scheme: row.sandbox_url_scheme ?? null
6286
+ sandbox_url_scheme: row.sandbox_url_scheme ?? null,
6287
+ export_method: row.export_method ?? null
5856
6288
  });
6289
+ /** The export methods an `.ipa` registers with. */
6290
+ const EXPORT_METHODS = /* @__PURE__ */ new Set([
6291
+ "app-store",
6292
+ "ad-hoc",
6293
+ "development",
6294
+ "enterprise"
6295
+ ]);
5857
6296
  /**
5858
6297
  * The channels only sandbox builds register on: a registration's `sandbox`
5859
6298
  * must agree with it. The registry's convention, as
@@ -5899,7 +6338,7 @@ const nativeBuildScopeKey = (scope) => {
5899
6338
  };
5900
6339
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
5901
6340
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
5902
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, artifact }) => {
6341
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, artifact }) => {
5903
6342
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
5904
6343
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
5905
6344
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
@@ -5918,6 +6357,10 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
5918
6357
  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`;
5919
6358
  const kinds = ARTIFACT_KINDS[platform];
5920
6359
  if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
6360
+ if (exportMethod !== void 0 && exportMethod !== null) {
6361
+ if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
6362
+ if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
6363
+ }
5921
6364
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
5922
6365
  return null;
5923
6366
  };
@@ -5949,7 +6392,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
5949
6392
  submitted_version: null,
5950
6393
  is_store_build: false,
5951
6394
  is_sandbox: registration.isSandbox === true,
5952
- sandbox_url_scheme: registration.sandboxUrlScheme ?? null
6395
+ sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
6396
+ export_method: registration.exportMethod ?? null
5953
6397
  };
5954
6398
  for (let attempt = 1;; attempt += 1) {
5955
6399
  await insertChannel(db, {
@@ -6696,6 +7140,7 @@ const createCoreApi = (db, storage, options = {}) => {
6696
7140
  ...reads,
6697
7141
  ...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
6698
7142
  ...createNativeBuildApi(db, options),
7143
+ ...createIosDeviceApi(db, options),
6699
7144
  /** One read, which checks the schema settings first. */
6700
7145
  ready: async () => {
6701
7146
  await reads.listReleaseCatalogs({ limit: 1 });
@@ -6915,10 +7360,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
6915
7360
  const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
6916
7361
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
6917
7362
  const cursor = url.searchParams.get("cursor");
7363
+ const through = url.searchParams.get("through");
6918
7364
  return {
6919
7365
  order,
6920
7366
  limit,
6921
- ...cursor === null ? {} : { after: cursor }
7367
+ ...cursor === null ? {} : { after: cursor },
7368
+ ...through === null ? {} : { through }
6922
7369
  };
6923
7370
  };
6924
7371
  /** A page and the cursor of the next one, when the page is full. */
@@ -7033,11 +7480,11 @@ const refusingInvalid = async (operation) => {
7033
7480
  try {
7034
7481
  return await operation();
7035
7482
  } catch (error) {
7036
- if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
7483
+ if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
7037
7484
  throw error;
7038
7485
  }
7039
7486
  };
7040
- 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));
7487
+ 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));
7041
7488
  const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
7042
7489
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
7043
7490
  const createAdminRouteHandlers = () => ({
@@ -7200,6 +7647,81 @@ const createAdminRouteHandlers = () => ({
7200
7647
  return json$2({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
7201
7648
  }),
7202
7649
  deleteNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
7650
+ listIosDevices: onCore(async (core, request) => {
7651
+ const url = new URL(request.url);
7652
+ const input = keyset(url);
7653
+ const status = url.searchParams.get("status");
7654
+ return page(await refusingInvalid(() => core.listIosDevices({
7655
+ ...input,
7656
+ ...status === null ? {} : { status }
7657
+ })), input, ({ id }) => id);
7658
+ }),
7659
+ findIosDevice: onCore(async (core, _request, params) => json$2({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
7660
+ requestIosDevice: onCore(async (core, request) => {
7661
+ const input = await body(request);
7662
+ 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.");
7663
+ const device = {
7664
+ udid: input.udid,
7665
+ name: input.name,
7666
+ requestedBy: input.requestedBy
7667
+ };
7668
+ return json$2({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
7669
+ }),
7670
+ approveIosDevice: onCore(async (core, request, params) => {
7671
+ const input = await body(request);
7672
+ 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.");
7673
+ const approval = {
7674
+ approvedBy: input.approvedBy,
7675
+ ...input.name === void 0 ? {} : { name: input.name }
7676
+ };
7677
+ return json$2({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
7678
+ }),
7679
+ renameIosDevice: onCore(async (core, request, params) => {
7680
+ const input = await body(request);
7681
+ if (!isText$2(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
7682
+ const name = input.name;
7683
+ return json$2({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
7684
+ }),
7685
+ recordIosDeviceOutcome: onCore(async (core, request, params) => {
7686
+ const input = await body(request);
7687
+ const seen = input.seen;
7688
+ 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.");
7689
+ const outcome = {
7690
+ id: requireRouteParam(params, "id"),
7691
+ seen: {
7692
+ status: seen.status,
7693
+ approvedAtMs: seen.approvedAtMs
7694
+ },
7695
+ issuerId: input.issuerId,
7696
+ outcome: input.outcome,
7697
+ ...input.reason === void 0 ? {} : { reason: input.reason }
7698
+ };
7699
+ return json$2({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
7700
+ }),
7701
+ claimIosDeviceAccount: onCore(async (core, request) => {
7702
+ const { issuerId } = await body(request);
7703
+ if (!isText$2(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
7704
+ return json$2({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
7705
+ }),
7706
+ markIosDevicesInBuild: onCore(async (core, request) => {
7707
+ const { buildId, ids } = await body(request);
7708
+ 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.");
7709
+ await core.markIosDevicesInBuild({
7710
+ buildId,
7711
+ ids
7712
+ });
7713
+ return noContent();
7714
+ }),
7715
+ deleteIosDevice: onCore(async (core, request, params) => {
7716
+ const url = new URL(request.url);
7717
+ const status = url.searchParams.get("status");
7718
+ const requestedBy = url.searchParams.get("requestedBy");
7719
+ const only = {
7720
+ ...status === null ? {} : { status },
7721
+ ...requestedBy === null ? {} : { requestedBy }
7722
+ };
7723
+ return json$2({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
7724
+ }),
7203
7725
  deleteBundles: onCore(async (core, request) => {
7204
7726
  const { ids } = await body(request);
7205
7727
  if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
@@ -7353,6 +7875,51 @@ const ADMIN_ROUTES = [
7353
7875
  method: "DELETE",
7354
7876
  path: "/native-builds/:id",
7355
7877
  handler: "deleteNativeBuild"
7878
+ },
7879
+ {
7880
+ method: "GET",
7881
+ path: "/ios-devices",
7882
+ handler: "listIosDevices"
7883
+ },
7884
+ {
7885
+ method: "POST",
7886
+ path: "/ios-devices",
7887
+ handler: "requestIosDevice"
7888
+ },
7889
+ {
7890
+ method: "GET",
7891
+ path: "/ios-devices/udid/:udid",
7892
+ handler: "findIosDevice"
7893
+ },
7894
+ {
7895
+ method: "POST",
7896
+ path: "/ios-devices/in-build",
7897
+ handler: "markIosDevicesInBuild"
7898
+ },
7899
+ {
7900
+ method: "POST",
7901
+ path: "/ios-devices/account",
7902
+ handler: "claimIosDeviceAccount"
7903
+ },
7904
+ {
7905
+ method: "POST",
7906
+ path: "/ios-devices/:id/approval",
7907
+ handler: "approveIosDevice"
7908
+ },
7909
+ {
7910
+ method: "POST",
7911
+ path: "/ios-devices/:id/outcome",
7912
+ handler: "recordIosDeviceOutcome"
7913
+ },
7914
+ {
7915
+ method: "PATCH",
7916
+ path: "/ios-devices/:id",
7917
+ handler: "renameIosDevice"
7918
+ },
7919
+ {
7920
+ method: "DELETE",
7921
+ path: "/ios-devices/:id",
7922
+ handler: "deleteIosDevice"
7356
7923
  }
7357
7924
  ];
7358
7925
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/firebase",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.27",
4
+ "version": "1.2.0-rc.28",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "types": "dist/index.d.cts",
@@ -38,10 +38,10 @@
38
38
  "dependencies": {
39
39
  "hono": "4.12.34",
40
40
  "google-auth-library": "10.7.0",
41
- "@hot-updater/protocol": "1.2.0-rc.27",
42
- "@hot-updater/cli-tools": "1.2.0-rc.27",
43
- "@hot-updater/plugin-core": "1.2.0-rc.27",
44
- "@hot-updater/server": "1.2.0-rc.27"
41
+ "@hot-updater/cli-tools": "1.2.0-rc.28",
42
+ "@hot-updater/protocol": "1.2.0-rc.28",
43
+ "@hot-updater/server": "1.2.0-rc.28",
44
+ "@hot-updater/plugin-core": "1.2.0-rc.28"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
@@ -56,8 +56,8 @@
56
56
  "firebase-tools": "15.29.0",
57
57
  "fkill": "^9.0.0",
58
58
  "mime": "^4.0.4",
59
- "@hot-updater/mock": "1.2.0-rc.27",
60
- "@hot-updater/test-utils": "1.2.0-rc.27"
59
+ "@hot-updater/mock": "1.2.0-rc.28",
60
+ "@hot-updater/test-utils": "1.2.0-rc.28"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "firebase-admin": ">=11.10.0",