@hot-updater/server 1.2.0-rc.4 → 1.2.0-rc.41
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.
- package/dist/core/api.cjs +2 -0
- package/dist/core/api.d.cts +30 -0
- package/dist/core/api.d.mts +30 -0
- package/dist/core/api.mjs +2 -0
- package/dist/core/iosDevices.cjs +314 -0
- package/dist/core/iosDevices.mjs +311 -0
- package/dist/core/nativeBuildDestinations.cjs +13 -0
- package/dist/core/nativeBuildDestinations.mjs +13 -0
- package/dist/core/nativeBuilds.cjs +212 -29
- package/dist/core/nativeBuilds.mjs +212 -30
- package/dist/core/operations.cjs +6 -2
- package/dist/core/operations.mjs +7 -3
- package/dist/core/reads.cjs +9 -1
- package/dist/core/reads.mjs +9 -1
- package/dist/core/writes.cjs +4 -1
- package/dist/core/writes.mjs +4 -1
- package/dist/createHotUpdaterCore.d.cts +2 -4
- package/dist/createHotUpdaterCore.d.mts +2 -4
- package/dist/handlerAdminRoutes.cjs +189 -8
- package/dist/handlerAdminRoutes.mjs +189 -8
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +7 -14
|
@@ -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. */
|
|
@@ -148,7 +152,8 @@ const nativeBuildScopeOf = (url) => {
|
|
|
148
152
|
const fingerprintHash = params.get("fingerprintHash");
|
|
149
153
|
const appVersion = params.get("appVersion");
|
|
150
154
|
if (platform === void 0 || !isText(channel) || fingerprintHash === null === (appVersion === null) || fingerprintHash === "" || appVersion === "") throw new require_handlerErrors.HandlerBadRequestError("A native build lookup needs platform, channel, and fingerprintHash or appVersion.");
|
|
151
|
-
|
|
155
|
+
const sandbox = sandboxScopeOf(params);
|
|
156
|
+
const scope = fingerprintHash !== null ? {
|
|
152
157
|
platform,
|
|
153
158
|
channel,
|
|
154
159
|
fingerprintHash,
|
|
@@ -159,17 +164,49 @@ const nativeBuildScopeOf = (url) => {
|
|
|
159
164
|
fingerprintHash: null,
|
|
160
165
|
appVersion
|
|
161
166
|
};
|
|
167
|
+
return sandbox === null ? scope : {
|
|
168
|
+
...scope,
|
|
169
|
+
sandbox
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
/** The query parameters a sandbox lookup names, all four or none. */
|
|
173
|
+
const SANDBOX_SCOPE_PARAMS = [
|
|
174
|
+
"sandboxAppId",
|
|
175
|
+
"sandboxUrlScheme",
|
|
176
|
+
"artifactKind",
|
|
177
|
+
"distribution"
|
|
178
|
+
];
|
|
179
|
+
/**
|
|
180
|
+
* A lookup's sandbox scope: null without one, and a bad request for one
|
|
181
|
+
* named in part. Core checks each value.
|
|
182
|
+
*/
|
|
183
|
+
const sandboxScopeOf = (params) => {
|
|
184
|
+
const [appId, urlScheme, artifactKind, distribution] = SANDBOX_SCOPE_PARAMS.map((name) => params.get(name));
|
|
185
|
+
const named = [
|
|
186
|
+
appId,
|
|
187
|
+
urlScheme,
|
|
188
|
+
artifactKind,
|
|
189
|
+
distribution
|
|
190
|
+
].filter((value) => value !== null).length;
|
|
191
|
+
if (named === 0) return null;
|
|
192
|
+
if (named !== SANDBOX_SCOPE_PARAMS.length) throw new require_handlerErrors.HandlerBadRequestError(`A sandbox build lookup needs ${SANDBOX_SCOPE_PARAMS.join(", ")}.`);
|
|
193
|
+
return {
|
|
194
|
+
appId,
|
|
195
|
+
urlScheme,
|
|
196
|
+
artifactKind,
|
|
197
|
+
distribution
|
|
198
|
+
};
|
|
162
199
|
};
|
|
163
200
|
/** A native build or scope core refuses: a bad request. */
|
|
164
201
|
const refusingInvalid = async (operation) => {
|
|
165
202
|
try {
|
|
166
203
|
return await operation();
|
|
167
204
|
} catch (error) {
|
|
168
|
-
if (error instanceof require_nativeBuilds.NativeBuildInputError) throw new require_handlerErrors.HandlerBadRequestError(error.message);
|
|
205
|
+
if (error instanceof require_nativeBuilds.NativeBuildInputError || error instanceof require_iosDevices.IosDeviceInputError) throw new require_handlerErrors.HandlerBadRequestError(error.message);
|
|
169
206
|
throw error;
|
|
170
207
|
}
|
|
171
208
|
};
|
|
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));
|
|
209
|
+
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.sandboxAppId === void 0 || isTextOrNull(value.sandboxAppId)) && (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
210
|
const scopeKeyOf = (params) => require_handlerParameters.decodeMaybe(require_handlerParameters.requireRouteParam(params, "scopeKey")) ?? "";
|
|
174
211
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
175
212
|
const createAdminRouteHandlers = () => ({
|
|
@@ -251,7 +288,8 @@ const createAdminRouteHandlers = () => ({
|
|
|
251
288
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
252
289
|
updateBundle: onCore(async (core, request, params) => {
|
|
253
290
|
const bundleId = require_handlerParameters.requireRouteParam(params, "id");
|
|
254
|
-
|
|
291
|
+
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
292
|
+
await refusingInvalid(() => core.updateBundle(bundleId, update));
|
|
255
293
|
return noContent();
|
|
256
294
|
}),
|
|
257
295
|
countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
@@ -275,7 +313,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
275
313
|
deployReleases: onCore(async (core, request) => {
|
|
276
314
|
const { deployments } = await body(request);
|
|
277
315
|
if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new require_handlerErrors.HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
|
|
278
|
-
return json({ data: await core.deploy(deployments) }, 201);
|
|
316
|
+
return json({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
|
|
279
317
|
}),
|
|
280
318
|
promoteRelease: onCore(async (core, request, params) => {
|
|
281
319
|
const input = await body(request);
|
|
@@ -298,7 +336,13 @@ const createAdminRouteHandlers = () => ({
|
|
|
298
336
|
const url = new URL(request.url);
|
|
299
337
|
const scope = nativeBuildScopeOf(url);
|
|
300
338
|
const buildKey = url.searchParams.get("buildKey");
|
|
301
|
-
|
|
339
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
340
|
+
const options = {
|
|
341
|
+
...buildKey === null ? {} : { buildKey },
|
|
342
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
343
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan }
|
|
344
|
+
};
|
|
345
|
+
return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
302
346
|
}),
|
|
303
347
|
getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
|
|
304
348
|
listNativeBuilds: onCore(async (core, request) => {
|
|
@@ -312,14 +356,96 @@ const createAdminRouteHandlers = () => ({
|
|
|
312
356
|
}),
|
|
313
357
|
recordNativeBuildSubmission: onCore(async (core, request, params) => {
|
|
314
358
|
const input = await body(request);
|
|
315
|
-
if (!isRecord(input) ||
|
|
359
|
+
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
360
|
const submission = {
|
|
317
361
|
destination: input.destination,
|
|
318
362
|
version: input.version
|
|
319
363
|
};
|
|
320
364
|
return json({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(require_handlerParameters.requireRouteParam(params, "id"), submission)) });
|
|
321
365
|
}),
|
|
366
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
367
|
+
const input = await body(request);
|
|
368
|
+
if (!isRecord(input) || typeof input.storeBuild !== "boolean") throw new require_handlerErrors.HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
369
|
+
const mark = { storeBuild: input.storeBuild };
|
|
370
|
+
return json({ data: await refusingInvalid(() => core.markNativeBuild(require_handlerParameters.requireRouteParam(params, "id"), mark)) });
|
|
371
|
+
}),
|
|
322
372
|
deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
|
|
373
|
+
listIosDevices: onCore(async (core, request) => {
|
|
374
|
+
const url = new URL(request.url);
|
|
375
|
+
const input = keyset(url);
|
|
376
|
+
const status = url.searchParams.get("status");
|
|
377
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
378
|
+
...input,
|
|
379
|
+
...status === null ? {} : { status }
|
|
380
|
+
})), input, ({ id }) => id);
|
|
381
|
+
}),
|
|
382
|
+
findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(require_handlerParameters.requireRouteParam(params, "udid")) })),
|
|
383
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
384
|
+
const input = await body(request);
|
|
385
|
+
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.");
|
|
386
|
+
const device = {
|
|
387
|
+
udid: input.udid,
|
|
388
|
+
name: input.name,
|
|
389
|
+
requestedBy: input.requestedBy
|
|
390
|
+
};
|
|
391
|
+
return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
392
|
+
}),
|
|
393
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
394
|
+
const input = await body(request);
|
|
395
|
+
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.");
|
|
396
|
+
const approval = {
|
|
397
|
+
approvedBy: input.approvedBy,
|
|
398
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
399
|
+
};
|
|
400
|
+
return json({ data: await refusingInvalid(() => core.approveIosDevice(require_handlerParameters.requireRouteParam(params, "id"), approval)) });
|
|
401
|
+
}),
|
|
402
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
403
|
+
const input = await body(request);
|
|
404
|
+
if (!isText(input.name)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device's new name is required.");
|
|
405
|
+
const name = input.name;
|
|
406
|
+
return json({ data: await refusingInvalid(() => core.renameIosDevice(require_handlerParameters.requireRouteParam(params, "id"), name)) });
|
|
407
|
+
}),
|
|
408
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
409
|
+
const input = await body(request);
|
|
410
|
+
const seen = input.seen;
|
|
411
|
+
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.");
|
|
412
|
+
const outcome = {
|
|
413
|
+
id: require_handlerParameters.requireRouteParam(params, "id"),
|
|
414
|
+
seen: {
|
|
415
|
+
status: seen.status,
|
|
416
|
+
approvedAtMs: seen.approvedAtMs
|
|
417
|
+
},
|
|
418
|
+
issuerId: input.issuerId,
|
|
419
|
+
outcome: input.outcome,
|
|
420
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
421
|
+
};
|
|
422
|
+
return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
423
|
+
}),
|
|
424
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
425
|
+
const { issuerId } = await body(request);
|
|
426
|
+
if (!isText(issuerId)) throw new require_handlerErrors.HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
427
|
+
return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
428
|
+
}),
|
|
429
|
+
findIosDeviceAccount: onCore(async (core) => json({ data: await core.findIosDeviceAccount() })),
|
|
430
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
431
|
+
const { buildId, ids } = await body(request);
|
|
432
|
+
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.");
|
|
433
|
+
await core.markIosDevicesInBuild({
|
|
434
|
+
buildId,
|
|
435
|
+
ids
|
|
436
|
+
});
|
|
437
|
+
return noContent();
|
|
438
|
+
}),
|
|
439
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
440
|
+
const url = new URL(request.url);
|
|
441
|
+
const status = url.searchParams.get("status");
|
|
442
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
443
|
+
const only = {
|
|
444
|
+
...status === null ? {} : { status },
|
|
445
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
446
|
+
};
|
|
447
|
+
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)) });
|
|
448
|
+
}),
|
|
323
449
|
deleteBundles: onCore(async (core, request) => {
|
|
324
450
|
const { ids } = await body(request);
|
|
325
451
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new require_handlerErrors.HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -464,10 +590,65 @@ const ADMIN_ROUTES = [
|
|
|
464
590
|
path: "/native-builds/:id/submission",
|
|
465
591
|
handler: "recordNativeBuildSubmission"
|
|
466
592
|
},
|
|
593
|
+
{
|
|
594
|
+
method: "POST",
|
|
595
|
+
path: "/native-builds/:id/store-build",
|
|
596
|
+
handler: "markNativeBuild"
|
|
597
|
+
},
|
|
467
598
|
{
|
|
468
599
|
method: "DELETE",
|
|
469
600
|
path: "/native-builds/:id",
|
|
470
601
|
handler: "deleteNativeBuild"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
method: "GET",
|
|
605
|
+
path: "/ios-devices",
|
|
606
|
+
handler: "listIosDevices"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
method: "POST",
|
|
610
|
+
path: "/ios-devices",
|
|
611
|
+
handler: "requestIosDevice"
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
method: "GET",
|
|
615
|
+
path: "/ios-devices/udid/:udid",
|
|
616
|
+
handler: "findIosDevice"
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
method: "POST",
|
|
620
|
+
path: "/ios-devices/in-build",
|
|
621
|
+
handler: "markIosDevicesInBuild"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
method: "GET",
|
|
625
|
+
path: "/ios-devices/account",
|
|
626
|
+
handler: "findIosDeviceAccount"
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
method: "POST",
|
|
630
|
+
path: "/ios-devices/account",
|
|
631
|
+
handler: "claimIosDeviceAccount"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
method: "POST",
|
|
635
|
+
path: "/ios-devices/:id/approval",
|
|
636
|
+
handler: "approveIosDevice"
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
method: "POST",
|
|
640
|
+
path: "/ios-devices/:id/outcome",
|
|
641
|
+
handler: "recordIosDeviceOutcome"
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
method: "PATCH",
|
|
645
|
+
path: "/ios-devices/:id",
|
|
646
|
+
handler: "renameIosDevice"
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
method: "DELETE",
|
|
650
|
+
path: "/ios-devices/:id",
|
|
651
|
+
handler: "deleteIosDevice"
|
|
471
652
|
}
|
|
472
653
|
];
|
|
473
654
|
//#endregion
|
|
@@ -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. */
|
|
@@ -148,7 +152,8 @@ const nativeBuildScopeOf = (url) => {
|
|
|
148
152
|
const fingerprintHash = params.get("fingerprintHash");
|
|
149
153
|
const appVersion = params.get("appVersion");
|
|
150
154
|
if (platform === void 0 || !isText(channel) || fingerprintHash === null === (appVersion === null) || fingerprintHash === "" || appVersion === "") throw new HandlerBadRequestError("A native build lookup needs platform, channel, and fingerprintHash or appVersion.");
|
|
151
|
-
|
|
155
|
+
const sandbox = sandboxScopeOf(params);
|
|
156
|
+
const scope = fingerprintHash !== null ? {
|
|
152
157
|
platform,
|
|
153
158
|
channel,
|
|
154
159
|
fingerprintHash,
|
|
@@ -159,17 +164,49 @@ const nativeBuildScopeOf = (url) => {
|
|
|
159
164
|
fingerprintHash: null,
|
|
160
165
|
appVersion
|
|
161
166
|
};
|
|
167
|
+
return sandbox === null ? scope : {
|
|
168
|
+
...scope,
|
|
169
|
+
sandbox
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
/** The query parameters a sandbox lookup names, all four or none. */
|
|
173
|
+
const SANDBOX_SCOPE_PARAMS = [
|
|
174
|
+
"sandboxAppId",
|
|
175
|
+
"sandboxUrlScheme",
|
|
176
|
+
"artifactKind",
|
|
177
|
+
"distribution"
|
|
178
|
+
];
|
|
179
|
+
/**
|
|
180
|
+
* A lookup's sandbox scope: null without one, and a bad request for one
|
|
181
|
+
* named in part. Core checks each value.
|
|
182
|
+
*/
|
|
183
|
+
const sandboxScopeOf = (params) => {
|
|
184
|
+
const [appId, urlScheme, artifactKind, distribution] = SANDBOX_SCOPE_PARAMS.map((name) => params.get(name));
|
|
185
|
+
const named = [
|
|
186
|
+
appId,
|
|
187
|
+
urlScheme,
|
|
188
|
+
artifactKind,
|
|
189
|
+
distribution
|
|
190
|
+
].filter((value) => value !== null).length;
|
|
191
|
+
if (named === 0) return null;
|
|
192
|
+
if (named !== SANDBOX_SCOPE_PARAMS.length) throw new HandlerBadRequestError(`A sandbox build lookup needs ${SANDBOX_SCOPE_PARAMS.join(", ")}.`);
|
|
193
|
+
return {
|
|
194
|
+
appId,
|
|
195
|
+
urlScheme,
|
|
196
|
+
artifactKind,
|
|
197
|
+
distribution
|
|
198
|
+
};
|
|
162
199
|
};
|
|
163
200
|
/** A native build or scope core refuses: a bad request. */
|
|
164
201
|
const refusingInvalid = async (operation) => {
|
|
165
202
|
try {
|
|
166
203
|
return await operation();
|
|
167
204
|
} catch (error) {
|
|
168
|
-
if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
|
|
205
|
+
if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
|
|
169
206
|
throw error;
|
|
170
207
|
}
|
|
171
208
|
};
|
|
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));
|
|
209
|
+
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.sandboxAppId === void 0 || isTextOrNull(value.sandboxAppId)) && (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
210
|
const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
|
|
174
211
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
175
212
|
const createAdminRouteHandlers = () => ({
|
|
@@ -251,7 +288,8 @@ const createAdminRouteHandlers = () => ({
|
|
|
251
288
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
252
289
|
updateBundle: onCore(async (core, request, params) => {
|
|
253
290
|
const bundleId = requireRouteParam(params, "id");
|
|
254
|
-
|
|
291
|
+
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
292
|
+
await refusingInvalid(() => core.updateBundle(bundleId, update));
|
|
255
293
|
return noContent();
|
|
256
294
|
}),
|
|
257
295
|
countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
@@ -275,7 +313,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
275
313
|
deployReleases: onCore(async (core, request) => {
|
|
276
314
|
const { deployments } = await body(request);
|
|
277
315
|
if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
|
|
278
|
-
return json({ data: await core.deploy(deployments) }, 201);
|
|
316
|
+
return json({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
|
|
279
317
|
}),
|
|
280
318
|
promoteRelease: onCore(async (core, request, params) => {
|
|
281
319
|
const input = await body(request);
|
|
@@ -298,7 +336,13 @@ const createAdminRouteHandlers = () => ({
|
|
|
298
336
|
const url = new URL(request.url);
|
|
299
337
|
const scope = nativeBuildScopeOf(url);
|
|
300
338
|
const buildKey = url.searchParams.get("buildKey");
|
|
301
|
-
|
|
339
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
340
|
+
const options = {
|
|
341
|
+
...buildKey === null ? {} : { buildKey },
|
|
342
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
343
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan }
|
|
344
|
+
};
|
|
345
|
+
return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
302
346
|
}),
|
|
303
347
|
getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
304
348
|
listNativeBuilds: onCore(async (core, request) => {
|
|
@@ -312,14 +356,96 @@ const createAdminRouteHandlers = () => ({
|
|
|
312
356
|
}),
|
|
313
357
|
recordNativeBuildSubmission: onCore(async (core, request, params) => {
|
|
314
358
|
const input = await body(request);
|
|
315
|
-
if (!isRecord(input) ||
|
|
359
|
+
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
360
|
const submission = {
|
|
317
361
|
destination: input.destination,
|
|
318
362
|
version: input.version
|
|
319
363
|
};
|
|
320
364
|
return json({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(requireRouteParam(params, "id"), submission)) });
|
|
321
365
|
}),
|
|
366
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
367
|
+
const input = await body(request);
|
|
368
|
+
if (!isRecord(input) || typeof input.storeBuild !== "boolean") throw new HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
369
|
+
const mark = { storeBuild: input.storeBuild };
|
|
370
|
+
return json({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
|
|
371
|
+
}),
|
|
322
372
|
deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
|
|
373
|
+
listIosDevices: onCore(async (core, request) => {
|
|
374
|
+
const url = new URL(request.url);
|
|
375
|
+
const input = keyset(url);
|
|
376
|
+
const status = url.searchParams.get("status");
|
|
377
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
378
|
+
...input,
|
|
379
|
+
...status === null ? {} : { status }
|
|
380
|
+
})), input, ({ id }) => id);
|
|
381
|
+
}),
|
|
382
|
+
findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
|
|
383
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
384
|
+
const input = await body(request);
|
|
385
|
+
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.");
|
|
386
|
+
const device = {
|
|
387
|
+
udid: input.udid,
|
|
388
|
+
name: input.name,
|
|
389
|
+
requestedBy: input.requestedBy
|
|
390
|
+
};
|
|
391
|
+
return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
392
|
+
}),
|
|
393
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
394
|
+
const input = await body(request);
|
|
395
|
+
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.");
|
|
396
|
+
const approval = {
|
|
397
|
+
approvedBy: input.approvedBy,
|
|
398
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
399
|
+
};
|
|
400
|
+
return json({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
|
|
401
|
+
}),
|
|
402
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
403
|
+
const input = await body(request);
|
|
404
|
+
if (!isText(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
|
|
405
|
+
const name = input.name;
|
|
406
|
+
return json({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
|
|
407
|
+
}),
|
|
408
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
409
|
+
const input = await body(request);
|
|
410
|
+
const seen = input.seen;
|
|
411
|
+
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.");
|
|
412
|
+
const outcome = {
|
|
413
|
+
id: requireRouteParam(params, "id"),
|
|
414
|
+
seen: {
|
|
415
|
+
status: seen.status,
|
|
416
|
+
approvedAtMs: seen.approvedAtMs
|
|
417
|
+
},
|
|
418
|
+
issuerId: input.issuerId,
|
|
419
|
+
outcome: input.outcome,
|
|
420
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
421
|
+
};
|
|
422
|
+
return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
423
|
+
}),
|
|
424
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
425
|
+
const { issuerId } = await body(request);
|
|
426
|
+
if (!isText(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
427
|
+
return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
428
|
+
}),
|
|
429
|
+
findIosDeviceAccount: onCore(async (core) => json({ data: await core.findIosDeviceAccount() })),
|
|
430
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
431
|
+
const { buildId, ids } = await body(request);
|
|
432
|
+
if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
433
|
+
await core.markIosDevicesInBuild({
|
|
434
|
+
buildId,
|
|
435
|
+
ids
|
|
436
|
+
});
|
|
437
|
+
return noContent();
|
|
438
|
+
}),
|
|
439
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
440
|
+
const url = new URL(request.url);
|
|
441
|
+
const status = url.searchParams.get("status");
|
|
442
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
443
|
+
const only = {
|
|
444
|
+
...status === null ? {} : { status },
|
|
445
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
446
|
+
};
|
|
447
|
+
return json({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
|
|
448
|
+
}),
|
|
323
449
|
deleteBundles: onCore(async (core, request) => {
|
|
324
450
|
const { ids } = await body(request);
|
|
325
451
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -464,10 +590,65 @@ const ADMIN_ROUTES = [
|
|
|
464
590
|
path: "/native-builds/:id/submission",
|
|
465
591
|
handler: "recordNativeBuildSubmission"
|
|
466
592
|
},
|
|
593
|
+
{
|
|
594
|
+
method: "POST",
|
|
595
|
+
path: "/native-builds/:id/store-build",
|
|
596
|
+
handler: "markNativeBuild"
|
|
597
|
+
},
|
|
467
598
|
{
|
|
468
599
|
method: "DELETE",
|
|
469
600
|
path: "/native-builds/:id",
|
|
470
601
|
handler: "deleteNativeBuild"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
method: "GET",
|
|
605
|
+
path: "/ios-devices",
|
|
606
|
+
handler: "listIosDevices"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
method: "POST",
|
|
610
|
+
path: "/ios-devices",
|
|
611
|
+
handler: "requestIosDevice"
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
method: "GET",
|
|
615
|
+
path: "/ios-devices/udid/:udid",
|
|
616
|
+
handler: "findIosDevice"
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
method: "POST",
|
|
620
|
+
path: "/ios-devices/in-build",
|
|
621
|
+
handler: "markIosDevicesInBuild"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
method: "GET",
|
|
625
|
+
path: "/ios-devices/account",
|
|
626
|
+
handler: "findIosDeviceAccount"
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
method: "POST",
|
|
630
|
+
path: "/ios-devices/account",
|
|
631
|
+
handler: "claimIosDeviceAccount"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
method: "POST",
|
|
635
|
+
path: "/ios-devices/:id/approval",
|
|
636
|
+
handler: "approveIosDevice"
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
method: "POST",
|
|
640
|
+
path: "/ios-devices/:id/outcome",
|
|
641
|
+
handler: "recordIosDeviceOutcome"
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
method: "PATCH",
|
|
645
|
+
path: "/ios-devices/:id",
|
|
646
|
+
handler: "renameIosDevice"
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
method: "DELETE",
|
|
650
|
+
path: "/ios-devices/:id",
|
|
651
|
+
handler: "deleteIosDevice"
|
|
471
652
|
}
|
|
472
653
|
];
|
|
473
654
|
//#endregion
|
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/server",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.41",
|
|
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/protocol": "1.2.0-rc.
|
|
54
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
55
|
-
"@hot-updater/plugin-api-keys": "1.2.0-rc.
|
|
56
|
-
"@hot-updater/plugin-
|
|
57
|
-
"@hot-updater/plugin-
|
|
53
|
+
"@hot-updater/protocol": "1.2.0-rc.41",
|
|
54
|
+
"@hot-updater/plugin-core": "1.2.0-rc.41",
|
|
55
|
+
"@hot-updater/plugin-api-keys": "1.2.0-rc.41",
|
|
56
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.41",
|
|
57
|
+
"@hot-updater/plugin-remote-config": "1.2.0-rc.41"
|
|
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.4",
|
|
99
|
-
"@hot-updater/test-utils": "1.2.0-rc.4"
|
|
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",
|