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

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,3 +1,5 @@
1
+ import { IosDeviceInputError } from "./core/iosDevices.mjs";
2
+ import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./core/nativeBuildDestinations.mjs";
1
3
  import { NativeBuildInputError } from "./core/nativeBuilds.mjs";
2
4
  import { HandlerBadRequestError } from "./handlerErrors.mjs";
3
5
  import { decodeMaybe, isPlatform, parseBooleanSearchParam, requireRouteParam } from "./handlerParameters.mjs";
@@ -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 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 NativeBuildInputError) throw new HandlerBadRequestError(error.message);
172
+ if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new 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" && 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" && 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)) && 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) => decodeMaybe(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(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 HandlerBadRequestError("A native build submission needs destination (testflight or play-internal) and version.");
325
+ if (!isRecord(input) || !Object.values(NATIVE_BUILD_SUBMISSION_DESTINATIONS).flat().includes(input.destination) || !isText(input.version)) throw new 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(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 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(requireRouteParam(params, "id"), mark)) });
337
+ }),
322
338
  deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(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(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 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 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(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 HandlerBadRequestError("An iOS device's new name is required.");
371
+ const name = input.name;
372
+ return json({ data: await refusingInvalid(() => core.renameIosDevice(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 HandlerBadRequestError("An iOS device outcome needs seen { status, approvedAtMs }, issuerId, outcome, and an optional reason.");
378
+ const outcome = {
379
+ id: 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 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 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(requireRouteParam(params, "id")) : core.deleteIosDevice(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 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
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.3";
2
+ var version = "1.2.0-rc.30";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "1.2.0-rc.3";
2
+ var version = "1.2.0-rc.30";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/server",
3
- "version": "1.2.0-rc.3",
3
+ "version": "1.2.0-rc.30",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -50,11 +50,11 @@
50
50
  "dependencies": {
51
51
  "rou3": "0.7.9",
52
52
  "verkit": "0.4.0",
53
- "@hot-updater/plugin-api-keys": "1.2.0-rc.3",
54
- "@hot-updater/plugin-core": "1.2.0-rc.3",
55
- "@hot-updater/protocol": "1.2.0-rc.3",
56
- "@hot-updater/plugin-insights": "1.2.0-rc.3",
57
- "@hot-updater/plugin-remote-config": "1.2.0-rc.3"
53
+ "@hot-updater/plugin-core": "1.2.0-rc.30",
54
+ "@hot-updater/protocol": "1.2.0-rc.30",
55
+ "@hot-updater/plugin-api-keys": "1.2.0-rc.30",
56
+ "@hot-updater/plugin-insights": "1.2.0-rc.30",
57
+ "@hot-updater/plugin-remote-config": "1.2.0-rc.30"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@prisma/client": "*",
@@ -94,14 +94,7 @@
94
94
  "pg": "8.13.1",
95
95
  "prisma": "6.19.3",
96
96
  "uuidv7": "^1.0.2",
97
- "wrangler": "^4.69.0",
98
- "@hot-updater/standalone": "1.2.0-rc.3",
99
- "@hot-updater/test-utils": "1.2.0-rc.3"
100
- },
101
- "nx": {
102
- "implicitDependencies": [
103
- "!@hot-updater/test-utils"
104
- ]
97
+ "wrangler": "^4.69.0"
105
98
  },
106
99
  "scripts": {
107
100
  "build": "tsdown",