@hot-updater/server 1.2.0-rc.3 → 1.2.0-rc.31

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.
@@ -1,4 +1,5 @@
1
1
  import { after } from "./reads.mjs";
2
+ import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./nativeBuildDestinations.mjs";
2
3
  import { insertChannel } from "./writes.mjs";
3
4
  import { DatabaseConstraintError, isUUIDv7 } from "@hot-updater/plugin-core";
4
5
  import { createReleaseCatalogScopeKey, encodeChannelKey } from "@hot-updater/protocol";
@@ -18,6 +19,13 @@ const GIT_COMMIT_HASH_MAX_LENGTH = 255;
18
19
  * and looks up nothing else.
19
20
  */
20
21
  const BUILD_KEY = /^nbk1:[0-9a-f]{64}$/;
22
+ /** `native_builds.sandbox_url_scheme`'s bound in core's schema. */
23
+ const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
24
+ /**
25
+ * A URL scheme as RFC 3986 spells it, in lower case: what a sandbox build's
26
+ * artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
27
+ */
28
+ const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
21
29
  /** A native build or scope core cannot store or look up: the caller's input. */
22
30
  var NativeBuildInputError = class extends TypeError {
23
31
  name = "NativeBuildInputError";
@@ -39,13 +47,33 @@ const pick = (row) => ({
39
47
  build_number: row.build_number ?? null,
40
48
  submitted_to: row.submitted_to ?? null,
41
49
  submitted_at_ms: row.submitted_at_ms ?? null,
42
- submitted_version: row.submitted_version ?? null
50
+ submitted_version: row.submitted_version ?? null,
51
+ is_store_build: row.is_store_build === true,
52
+ is_sandbox: row.is_sandbox === true,
53
+ sandbox_url_scheme: row.sandbox_url_scheme ?? null,
54
+ export_method: row.export_method ?? null,
55
+ native_app_version: row.native_app_version ?? null
43
56
  });
44
- /** The store track each platform's builds are submitted to. */
45
- const SUBMISSION_DESTINATIONS = {
46
- android: "play-internal",
47
- ios: "testflight"
48
- };
57
+ /** The export methods an `.ipa` registers with. */
58
+ const EXPORT_METHODS = /* @__PURE__ */ new Set([
59
+ "app-store",
60
+ "ad-hoc",
61
+ "development",
62
+ "enterprise"
63
+ ]);
64
+ /**
65
+ * The channels only sandbox builds register on: a registration's `sandbox`
66
+ * must agree with it. The registry's convention, as
67
+ * `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
68
+ */
69
+ const SANDBOX_CHANNEL_PREFIX = "sandbox-";
70
+ /**
71
+ * How many older builds of a scope one read takes, looking for one older than
72
+ * a bundle when a build made after the bundle is the newest.
73
+ */
74
+ const OLDER_BUILDS_PAGE = 20;
75
+ /** How many times a mark runs again after losing its scope's mark to another. */
76
+ const MARK_ATTEMPTS = 8;
49
77
  /** `native_builds.build_number`'s bound in core's schema. */
50
78
  const BUILD_NUMBER_MAX_LENGTH = 64;
51
79
  /** `native_builds.submitted_version`'s bound in core's schema. */
@@ -78,17 +106,30 @@ const nativeBuildScopeKey = (scope) => {
78
106
  };
79
107
  /** Whether `bundleId` is a native build's built-in bundle: one unique read. */
80
108
  const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
81
- const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, artifact }) => {
109
+ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
82
110
  if (!isUUIDv7(id)) return "id must be a UUIDv7";
83
111
  if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
84
112
  if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
85
113
  if (channel.trim().length === 0) return "channel is required";
114
+ if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
115
+ const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
116
+ if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
117
+ if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
118
+ if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
119
+ if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
120
+ if (typeof sandboxUrlScheme !== "string" || !URL_SCHEME.test(sandboxUrlScheme)) return `sandboxUrlScheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters, or null`;
121
+ }
86
122
  if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
87
123
  if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
88
124
  if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
89
125
  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`;
126
+ if (nativeAppVersion !== void 0 && nativeAppVersion !== null && (typeof nativeAppVersion !== "string" || nativeAppVersion.trim().length === 0)) return "nativeAppVersion must be the artifact's app version, or null";
90
127
  const kinds = ARTIFACT_KINDS[platform];
91
128
  if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
129
+ if (exportMethod !== void 0 && exportMethod !== null) {
130
+ if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
131
+ if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
132
+ }
92
133
  if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
93
134
  return null;
94
135
  };
@@ -117,7 +158,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
117
158
  build_number: registration.buildNumber ?? null,
118
159
  submitted_to: null,
119
160
  submitted_at_ms: null,
120
- submitted_version: null
161
+ submitted_version: null,
162
+ is_store_build: false,
163
+ is_sandbox: registration.isSandbox === true,
164
+ sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
165
+ export_method: registration.exportMethod ?? null,
166
+ native_app_version: registration.nativeAppVersion ?? null
121
167
  };
122
168
  for (let attempt = 1;; attempt += 1) {
123
169
  await insertChannel(db, {
@@ -155,21 +201,42 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
155
201
  const scopeKey = nativeBuildScopeKey(scope);
156
202
  const buildKey = options?.buildKey;
157
203
  if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
158
- const { rows } = buildKey === void 0 ? await db.findMany("native_builds", {
159
- index: "byScope",
160
- where: { scope_key: scopeKey },
161
- order: "desc",
162
- limit: 1
163
- }) : await db.findMany("native_builds", {
164
- index: "byBuildKey",
165
- where: {
166
- scope_key: scopeKey,
167
- build_key: buildKey
168
- },
169
- order: "desc",
170
- limit: 1
171
- });
172
- return rows[0] === void 0 ? null : pick(rows[0]);
204
+ if (options?.storeBuild) {
205
+ const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
206
+ return marked === null ? null : pick(marked);
207
+ }
208
+ const read = (limit, before) => {
209
+ const page = {
210
+ order: "desc",
211
+ limit,
212
+ ...before === void 0 ? {} : { range: { lt: before } }
213
+ };
214
+ return buildKey === void 0 ? db.findMany("native_builds", {
215
+ index: "byScope",
216
+ where: { scope_key: scopeKey },
217
+ ...page
218
+ }) : db.findMany("native_builds", {
219
+ index: "byBuildKey",
220
+ where: {
221
+ scope_key: scopeKey,
222
+ build_key: buildKey
223
+ },
224
+ ...page
225
+ });
226
+ };
227
+ const { rows } = await read(1);
228
+ const newest = rows[0];
229
+ if (newest === void 0) return null;
230
+ const bundleId = options?.builtInOlderThan;
231
+ if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
232
+ for (let before = newest.id;;) {
233
+ const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
234
+ const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
235
+ if (usable !== void 0) return pick(usable);
236
+ const last = older.at(-1);
237
+ if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
238
+ before = last.id;
239
+ }
173
240
  },
174
241
  async recordNativeBuildSubmission(id, { destination, version }) {
175
242
  if (version.trim().length === 0 || version.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
@@ -177,7 +244,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
177
244
  const row = await tx.findOne("native_builds", { id });
178
245
  if (row === null) return null;
179
246
  const build = pick(row);
180
- if (SUBMISSION_DESTINATIONS[build.platform] !== destination) throw new NativeBuildInputError(`Invalid native build submission: an ${build.platform} build is submitted to ${SUBMISSION_DESTINATIONS[build.platform]}, not ${destination}.`);
247
+ 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}.`);
248
+ if (build.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
181
249
  const set = {
182
250
  submitted_to: destination,
183
251
  submitted_at_ms: now(),
@@ -190,6 +258,46 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
190
258
  };
191
259
  });
192
260
  },
261
+ async markNativeBuild(id, { storeBuild }) {
262
+ for (let attempt = 1;; attempt += 1) try {
263
+ return await db.transaction(async (tx) => {
264
+ const row = await tx.findOne("native_builds", { id });
265
+ if (row === null) return null;
266
+ const build = pick(row);
267
+ if (!storeBuild) {
268
+ if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
269
+ return {
270
+ nativeBuild: {
271
+ ...build,
272
+ is_store_build: false
273
+ },
274
+ previous: null
275
+ };
276
+ }
277
+ if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
278
+ if (build.is_store_build) return {
279
+ nativeBuild: build,
280
+ previous: null
281
+ };
282
+ const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
283
+ if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
284
+ tx.update("native_builds", row, { is_store_build: true });
285
+ return {
286
+ nativeBuild: {
287
+ ...build,
288
+ is_store_build: true
289
+ },
290
+ previous: holder === null ? null : {
291
+ ...pick(holder),
292
+ is_store_build: false
293
+ }
294
+ };
295
+ });
296
+ } catch (error) {
297
+ if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
298
+ throw error;
299
+ }
300
+ },
193
301
  async deleteNativeBuild(id) {
194
302
  return db.transaction(async (tx) => {
195
303
  const row = await tx.findOne("native_builds", { id });
@@ -74,7 +74,15 @@ const drain = async (read) => {
74
74
  return rows;
75
75
  };
76
76
  /** A keyset page's range: the keys strictly after `after`, in `order`. */
77
- const after = (input) => input.after === void 0 ? {} : { range: (input.order ?? "asc") === "asc" ? { gt: input.after } : { lt: input.after } };
77
+ /** A keyset read's range on its index's order: past `after`, up to `through`. */
78
+ const after = (input) => {
79
+ const asc = (input.order ?? "asc") === "asc";
80
+ const range = {
81
+ ...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
82
+ ...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
83
+ };
84
+ return Object.keys(range).length === 0 ? {} : { range };
85
+ };
78
86
  /** Core's reads, each through one declared index or key. */
79
87
  const createCoreReads = (db, storage) => {
80
88
  /** A bundle row's patches, exactly as many as its reference counter holds. */
@@ -74,7 +74,15 @@ const drain = async (read) => {
74
74
  return rows;
75
75
  };
76
76
  /** A keyset page's range: the keys strictly after `after`, in `order`. */
77
- const after = (input) => input.after === void 0 ? {} : { range: (input.order ?? "asc") === "asc" ? { gt: input.after } : { lt: input.after } };
77
+ /** A keyset read's range on its index's order: past `after`, up to `through`. */
78
+ const after = (input) => {
79
+ const asc = (input.order ?? "asc") === "asc";
80
+ const range = {
81
+ ...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
82
+ ...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
83
+ };
84
+ return Object.keys(range).length === 0 ? {} : { range };
85
+ };
78
86
  /** Core's reads, each through one declared index or key. */
79
87
  const createCoreReads = (db, storage) => {
80
88
  /** A bundle row's patches, exactly as many as its reference counter holds. */
@@ -42,10 +42,8 @@ type RuntimeHotUpdaterAPI<TPlugins extends readonly AnyHotUpdaterPlugin[] = read
42
42
  /** The database's name, which `hot-updater db` commands read. */
43
43
  readonly adapterName: string;
44
44
  /**
45
- * Applies aggregate changes the database batches that are still pending:
46
- * this process's buffer, and the log rows no compaction has merged yet.
47
- * A long-lived server with `aggregateBatching: { mode: "memory" }` calls
48
- * it before it exits.
45
+ * Applies the log rows of batched aggregates that no compaction has merged
46
+ * yet. Nothing waits on it: they are durable, and a read compacts first.
49
47
  */
50
48
  readonly flush: () => Promise<void>;
51
49
  /**
@@ -42,10 +42,8 @@ type RuntimeHotUpdaterAPI<TPlugins extends readonly AnyHotUpdaterPlugin[] = read
42
42
  /** The database's name, which `hot-updater db` commands read. */
43
43
  readonly adapterName: string;
44
44
  /**
45
- * Applies aggregate changes the database batches that are still pending:
46
- * this process's buffer, and the log rows no compaction has merged yet.
47
- * A long-lived server with `aggregateBatching: { mode: "memory" }` calls
48
- * it before it exits.
45
+ * Applies the log rows of batched aggregates that no compaction has merged
46
+ * yet. Nothing waits on it: they are durable, and a read compacts first.
49
47
  */
50
48
  readonly flush: () => Promise<void>;
51
49
  /**
@@ -1,3 +1,5 @@
1
+ const require_iosDevices = require("./core/iosDevices.cjs");
2
+ const require_nativeBuildDestinations = require("./core/nativeBuildDestinations.cjs");
1
3
  const require_nativeBuilds = require("./core/nativeBuilds.cjs");
2
4
  const require_handlerErrors = require("./handlerErrors.cjs");
3
5
  const require_handlerParameters = require("./handlerParameters.cjs");
@@ -47,10 +49,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
47
49
  const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
48
50
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new require_handlerErrors.HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
49
51
  const cursor = url.searchParams.get("cursor");
52
+ const through = url.searchParams.get("through");
50
53
  return {
51
54
  order,
52
55
  limit,
53
- ...cursor === null ? {} : { after: cursor }
56
+ ...cursor === null ? {} : { after: cursor },
57
+ ...through === null ? {} : { through }
54
58
  };
55
59
  };
56
60
  /** A page and the cursor of the next one, when the page is full. */
@@ -165,11 +169,11 @@ const refusingInvalid = async (operation) => {
165
169
  try {
166
170
  return await operation();
167
171
  } catch (error) {
168
- if (error instanceof require_nativeBuilds.NativeBuildInputError) throw new require_handlerErrors.HandlerBadRequestError(error.message);
172
+ if (error instanceof require_nativeBuilds.NativeBuildInputError || error instanceof require_iosDevices.IosDeviceInputError) throw new require_handlerErrors.HandlerBadRequestError(error.message);
169
173
  throw error;
170
174
  }
171
175
  };
172
- const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && require_handlerParameters.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)) && isRecord(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 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
176
+ const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && require_handlerParameters.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)) && (value.nativeAppVersion === void 0 || isTextOrNull(value.nativeAppVersion)) && isRecord(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 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
173
177
  const scopeKeyOf = (params) => require_handlerParameters.decodeMaybe(require_handlerParameters.requireRouteParam(params, "scopeKey")) ?? "";
174
178
  /** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
175
179
  const createAdminRouteHandlers = () => ({
@@ -298,7 +302,13 @@ const createAdminRouteHandlers = () => ({
298
302
  const url = new URL(request.url);
299
303
  const scope = nativeBuildScopeOf(url);
300
304
  const buildKey = url.searchParams.get("buildKey");
301
- return json({ data: await refusingInvalid(() => buildKey === null ? core.findNativeBuild(scope) : core.findNativeBuild(scope, { buildKey })) });
305
+ const builtInOlderThan = url.searchParams.get("builtInOlderThan");
306
+ const options = {
307
+ ...buildKey === null ? {} : { buildKey },
308
+ ...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
309
+ ...builtInOlderThan === null ? {} : { builtInOlderThan }
310
+ };
311
+ return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
302
312
  }),
303
313
  getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
304
314
  listNativeBuilds: onCore(async (core, request) => {
@@ -312,14 +322,95 @@ const createAdminRouteHandlers = () => ({
312
322
  }),
313
323
  recordNativeBuildSubmission: onCore(async (core, request, params) => {
314
324
  const input = await body(request);
315
- if (!isRecord(input) || input.destination !== "testflight" && input.destination !== "play-internal" || !isText(input.version)) throw new require_handlerErrors.HandlerBadRequestError("A native build submission needs destination (testflight or play-internal) and version.");
325
+ if (!isRecord(input) || !Object.values(require_nativeBuildDestinations.NATIVE_BUILD_SUBMISSION_DESTINATIONS).flat().includes(input.destination) || !isText(input.version)) throw new require_handlerErrors.HandlerBadRequestError("A native build submission needs a valid store destination and version.");
316
326
  const submission = {
317
327
  destination: input.destination,
318
328
  version: input.version
319
329
  };
320
330
  return json({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(require_handlerParameters.requireRouteParam(params, "id"), submission)) });
321
331
  }),
332
+ markNativeBuild: onCore(async (core, request, params) => {
333
+ const input = await body(request);
334
+ if (!isRecord(input) || typeof input.storeBuild !== "boolean") throw new require_handlerErrors.HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
335
+ const mark = { storeBuild: input.storeBuild };
336
+ return json({ data: await refusingInvalid(() => core.markNativeBuild(require_handlerParameters.requireRouteParam(params, "id"), mark)) });
337
+ }),
322
338
  deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
339
+ listIosDevices: onCore(async (core, request) => {
340
+ const url = new URL(request.url);
341
+ const input = keyset(url);
342
+ const status = url.searchParams.get("status");
343
+ return page(await refusingInvalid(() => core.listIosDevices({
344
+ ...input,
345
+ ...status === null ? {} : { status }
346
+ })), input, ({ id }) => id);
347
+ }),
348
+ findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(require_handlerParameters.requireRouteParam(params, "udid")) })),
349
+ requestIosDevice: onCore(async (core, request) => {
350
+ const input = await body(request);
351
+ if (!isText(input.udid) || !isText(input.name) || !isTextOrNull(input.requestedBy)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device request needs udid, name, and requestedBy, an email or null.");
352
+ const device = {
353
+ udid: input.udid,
354
+ name: input.name,
355
+ requestedBy: input.requestedBy
356
+ };
357
+ return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
358
+ }),
359
+ approveIosDevice: onCore(async (core, request, params) => {
360
+ const input = await body(request);
361
+ if (!isTextOrNull(input.approvedBy) || input.name !== void 0 && !isText(input.name)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device approval needs approvedBy, an email or null, and an optional name.");
362
+ const approval = {
363
+ approvedBy: input.approvedBy,
364
+ ...input.name === void 0 ? {} : { name: input.name }
365
+ };
366
+ return json({ data: await refusingInvalid(() => core.approveIosDevice(require_handlerParameters.requireRouteParam(params, "id"), approval)) });
367
+ }),
368
+ renameIosDevice: onCore(async (core, request, params) => {
369
+ const input = await body(request);
370
+ if (!isText(input.name)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device's new name is required.");
371
+ const name = input.name;
372
+ return json({ data: await refusingInvalid(() => core.renameIosDevice(require_handlerParameters.requireRouteParam(params, "id"), name)) });
373
+ }),
374
+ recordIosDeviceOutcome: onCore(async (core, request, params) => {
375
+ const input = await body(request);
376
+ const seen = input.seen;
377
+ if (!isRecord(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 require_handlerErrors.HandlerBadRequestError("An iOS device outcome needs seen { status, approvedAtMs }, issuerId, outcome, and an optional reason.");
378
+ const outcome = {
379
+ id: require_handlerParameters.requireRouteParam(params, "id"),
380
+ seen: {
381
+ status: seen.status,
382
+ approvedAtMs: seen.approvedAtMs
383
+ },
384
+ issuerId: input.issuerId,
385
+ outcome: input.outcome,
386
+ ...input.reason === void 0 ? {} : { reason: input.reason }
387
+ };
388
+ return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
389
+ }),
390
+ claimIosDeviceAccount: onCore(async (core, request) => {
391
+ const { issuerId } = await body(request);
392
+ if (!isText(issuerId)) throw new require_handlerErrors.HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
393
+ return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
394
+ }),
395
+ markIosDevicesInBuild: onCore(async (core, request) => {
396
+ const { buildId, ids } = await body(request);
397
+ if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new require_handlerErrors.HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
398
+ await core.markIosDevicesInBuild({
399
+ buildId,
400
+ ids
401
+ });
402
+ return noContent();
403
+ }),
404
+ deleteIosDevice: onCore(async (core, request, params) => {
405
+ const url = new URL(request.url);
406
+ const status = url.searchParams.get("status");
407
+ const requestedBy = url.searchParams.get("requestedBy");
408
+ const only = {
409
+ ...status === null ? {} : { status },
410
+ ...requestedBy === null ? {} : { requestedBy }
411
+ };
412
+ return json({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(require_handlerParameters.requireRouteParam(params, "id")) : core.deleteIosDevice(require_handlerParameters.requireRouteParam(params, "id"), only)) });
413
+ }),
323
414
  deleteBundles: onCore(async (core, request) => {
324
415
  const { ids } = await body(request);
325
416
  if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new require_handlerErrors.HandlerBadRequestError("Bundle deletion needs ids");
@@ -464,10 +555,60 @@ const ADMIN_ROUTES = [
464
555
  path: "/native-builds/:id/submission",
465
556
  handler: "recordNativeBuildSubmission"
466
557
  },
558
+ {
559
+ method: "POST",
560
+ path: "/native-builds/:id/store-build",
561
+ handler: "markNativeBuild"
562
+ },
467
563
  {
468
564
  method: "DELETE",
469
565
  path: "/native-builds/:id",
470
566
  handler: "deleteNativeBuild"
567
+ },
568
+ {
569
+ method: "GET",
570
+ path: "/ios-devices",
571
+ handler: "listIosDevices"
572
+ },
573
+ {
574
+ method: "POST",
575
+ path: "/ios-devices",
576
+ handler: "requestIosDevice"
577
+ },
578
+ {
579
+ method: "GET",
580
+ path: "/ios-devices/udid/:udid",
581
+ handler: "findIosDevice"
582
+ },
583
+ {
584
+ method: "POST",
585
+ path: "/ios-devices/in-build",
586
+ handler: "markIosDevicesInBuild"
587
+ },
588
+ {
589
+ method: "POST",
590
+ path: "/ios-devices/account",
591
+ handler: "claimIosDeviceAccount"
592
+ },
593
+ {
594
+ method: "POST",
595
+ path: "/ios-devices/:id/approval",
596
+ handler: "approveIosDevice"
597
+ },
598
+ {
599
+ method: "POST",
600
+ path: "/ios-devices/:id/outcome",
601
+ handler: "recordIosDeviceOutcome"
602
+ },
603
+ {
604
+ method: "PATCH",
605
+ path: "/ios-devices/:id",
606
+ handler: "renameIosDevice"
607
+ },
608
+ {
609
+ method: "DELETE",
610
+ path: "/ios-devices/:id",
611
+ handler: "deleteIosDevice"
471
612
  }
472
613
  ];
473
614
  //#endregion