@hot-updater/server 1.2.0-rc.5 → 1.2.0-rc.51
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/adapters/drizzle.cjs +8 -4
- package/dist/adapters/drizzle.d.cts +3 -2
- package/dist/adapters/drizzle.d.mts +3 -2
- package/dist/adapters/drizzle.mjs +8 -4
- package/dist/adapters/drizzleExecutor.cjs +4 -2
- package/dist/adapters/drizzleExecutor.mjs +4 -2
- package/dist/adapters/kysely.cjs +3 -2
- package/dist/adapters/kysely.mjs +3 -2
- package/dist/adapters/mongodb.cjs +1 -1
- package/dist/adapters/mongodb.mjs +1 -1
- package/dist/adapters/mongodbAdapter.cjs +15 -3
- package/dist/adapters/mongodbAdapter.mjs +15 -3
- package/dist/adapters/prisma.cjs +9 -13
- package/dist/adapters/prisma.mjs +10 -14
- package/dist/adapters/prismaExecutor.cjs +25 -20
- package/dist/adapters/prismaExecutor.mjs +25 -20
- package/dist/core/api.cjs +2 -0
- package/dist/core/api.d.cts +48 -1
- package/dist/core/api.d.mts +48 -1
- package/dist/core/api.mjs +2 -0
- package/dist/core/iosDevices.cjs +306 -0
- package/dist/core/iosDevices.mjs +303 -0
- package/dist/core/labels.cjs +317 -0
- package/dist/core/labels.mjs +310 -0
- package/dist/core/nativeBuildDestinations.cjs +13 -0
- package/dist/core/nativeBuildDestinations.mjs +13 -0
- package/dist/core/nativeBuilds.cjs +291 -22
- package/dist/core/nativeBuilds.mjs +291 -23
- package/dist/core/operations.cjs +45 -24
- package/dist/core/operations.mjs +48 -27
- package/dist/core/reads.cjs +69 -5
- package/dist/core/reads.mjs +70 -6
- package/dist/core/releases.cjs +121 -38
- package/dist/core/releases.mjs +121 -41
- package/dist/core/writes.cjs +14 -2
- package/dist/core/writes.mjs +14 -2
- package/dist/createHotUpdaterCore.d.cts +2 -4
- package/dist/createHotUpdaterCore.d.mts +2 -4
- package/dist/db/engineDrizzleSchema.cjs +21 -5
- package/dist/db/engineDrizzleSchema.mjs +21 -6
- package/dist/db/enginePrismaSchema.cjs +6 -14
- package/dist/db/enginePrismaSchema.mjs +7 -15
- package/dist/db/releaseCatalog.cjs +13 -4
- package/dist/db/releaseCatalog.mjs +12 -5
- package/dist/handlerAdminRoutes.cjs +288 -16
- package/dist/handlerAdminRoutes.mjs +289 -17
- package/dist/handlerReleaseCatalogRoutes.cjs +43 -27
- package/dist/handlerReleaseCatalogRoutes.mjs +43 -27
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +7 -14
|
@@ -1,7 +1,9 @@
|
|
|
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";
|
|
4
|
-
import { DatabaseBundleNotFoundError, DatabaseConstraintError, DatabaseRowReferencedError, ReleaseCatalogMutationError, ReleaseManagementError } from "@hot-updater/plugin-core";
|
|
6
|
+
import { DatabaseBundleNotFoundError, DatabaseConstraintError, DatabaseRowReferencedError, ReleaseCatalogCompilationError, ReleaseCatalogMutationError, ReleaseManagementError } from "@hot-updater/plugin-core";
|
|
5
7
|
//#region src/handlerAdminRoutes.ts
|
|
6
8
|
const json = (body, status = 200) => Response.json(body, { status });
|
|
7
9
|
const notFound = () => json({ error: "Not found" }, 404);
|
|
@@ -20,6 +22,10 @@ const answer = async (operation) => {
|
|
|
20
22
|
error: error.message
|
|
21
23
|
}, status);
|
|
22
24
|
}
|
|
25
|
+
if (error instanceof ReleaseCatalogCompilationError && error.code === "CATALOG_OVERSIZE") return json({
|
|
26
|
+
code: error.code,
|
|
27
|
+
error: error.message
|
|
28
|
+
}, 400);
|
|
23
29
|
if (error instanceof DatabaseBundleNotFoundError) return json({
|
|
24
30
|
code: "BUNDLE_NOT_FOUND",
|
|
25
31
|
error: error.message
|
|
@@ -39,18 +45,22 @@ const LIMITS = {
|
|
|
39
45
|
defaultValue: 50,
|
|
40
46
|
maxValue: 500
|
|
41
47
|
};
|
|
48
|
+
/** The most IDs one request names: a lookup's, or a write's. */
|
|
49
|
+
const MAX_IDS = 100;
|
|
42
50
|
/** `order`, `cursor`, and `limit`: one keyset page. */
|
|
43
|
-
const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
44
|
-
const order = url.searchParams.get("order") ??
|
|
51
|
+
const keyset = (url, maxValue = LIMITS.maxValue, defaultOrder = "desc") => {
|
|
52
|
+
const order = url.searchParams.get("order") ?? defaultOrder;
|
|
45
53
|
if (order !== "asc" && order !== "desc") throw new HandlerBadRequestError("order must be 'asc' or 'desc'.");
|
|
46
54
|
const limitParam = url.searchParams.get("limit");
|
|
47
55
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
48
56
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
49
57
|
const cursor = url.searchParams.get("cursor");
|
|
58
|
+
const through = url.searchParams.get("through");
|
|
50
59
|
return {
|
|
51
60
|
order,
|
|
52
61
|
limit,
|
|
53
|
-
...cursor === null ? {} : { after: cursor }
|
|
62
|
+
...cursor === null ? {} : { after: cursor },
|
|
63
|
+
...through === null ? {} : { through }
|
|
54
64
|
};
|
|
55
65
|
};
|
|
56
66
|
/** A page and the cursor of the next one, when the page is full. */
|
|
@@ -148,7 +158,8 @@ const nativeBuildScopeOf = (url) => {
|
|
|
148
158
|
const fingerprintHash = params.get("fingerprintHash");
|
|
149
159
|
const appVersion = params.get("appVersion");
|
|
150
160
|
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
|
-
|
|
161
|
+
const sandbox = sandboxScopeOf(params);
|
|
162
|
+
const scope = fingerprintHash !== null ? {
|
|
152
163
|
platform,
|
|
153
164
|
channel,
|
|
154
165
|
fingerprintHash,
|
|
@@ -159,17 +170,49 @@ const nativeBuildScopeOf = (url) => {
|
|
|
159
170
|
fingerprintHash: null,
|
|
160
171
|
appVersion
|
|
161
172
|
};
|
|
173
|
+
return sandbox === null ? scope : {
|
|
174
|
+
...scope,
|
|
175
|
+
sandbox
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
/** The query parameters a sandbox lookup names, all four or none. */
|
|
179
|
+
const SANDBOX_SCOPE_PARAMS = [
|
|
180
|
+
"sandboxAppId",
|
|
181
|
+
"sandboxUrlScheme",
|
|
182
|
+
"artifactKind",
|
|
183
|
+
"distribution"
|
|
184
|
+
];
|
|
185
|
+
/**
|
|
186
|
+
* A lookup's sandbox scope: null without one, and a bad request for one
|
|
187
|
+
* named in part. Core checks each value.
|
|
188
|
+
*/
|
|
189
|
+
const sandboxScopeOf = (params) => {
|
|
190
|
+
const [appId, urlScheme, artifactKind, distribution] = SANDBOX_SCOPE_PARAMS.map((name) => params.get(name));
|
|
191
|
+
const named = [
|
|
192
|
+
appId,
|
|
193
|
+
urlScheme,
|
|
194
|
+
artifactKind,
|
|
195
|
+
distribution
|
|
196
|
+
].filter((value) => value !== null).length;
|
|
197
|
+
if (named === 0) return null;
|
|
198
|
+
if (named !== SANDBOX_SCOPE_PARAMS.length) throw new HandlerBadRequestError(`A sandbox build lookup needs ${SANDBOX_SCOPE_PARAMS.join(", ")}.`);
|
|
199
|
+
return {
|
|
200
|
+
appId,
|
|
201
|
+
urlScheme,
|
|
202
|
+
artifactKind,
|
|
203
|
+
distribution
|
|
204
|
+
};
|
|
162
205
|
};
|
|
163
206
|
/** A native build or scope core refuses: a bad request. */
|
|
164
207
|
const refusingInvalid = async (operation) => {
|
|
165
208
|
try {
|
|
166
209
|
return await operation();
|
|
167
210
|
} catch (error) {
|
|
168
|
-
if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
|
|
211
|
+
if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
|
|
169
212
|
throw error;
|
|
170
213
|
}
|
|
171
214
|
};
|
|
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));
|
|
215
|
+
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
216
|
const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
|
|
174
217
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
175
218
|
const createAdminRouteHandlers = () => ({
|
|
@@ -202,12 +245,40 @@ const createAdminRouteHandlers = () => ({
|
|
|
202
245
|
const rows = await core.listReleaseCatalogs(input);
|
|
203
246
|
return page(rows, input, (row) => row.scope_key);
|
|
204
247
|
}),
|
|
205
|
-
/**
|
|
248
|
+
/** Up to 100 scope keys that have releases, after `cursor`: one seek each. */
|
|
249
|
+
listReleaseScopeKeys: onCore(async (core, request) => {
|
|
250
|
+
const input = keyset(new URL(request.url), 100, "asc");
|
|
251
|
+
if (input.order !== "asc" || input.through !== void 0) throw new HandlerBadRequestError("Release scopes are listed ascending, by limit and cursor only.");
|
|
252
|
+
const rows = await core.listReleaseScopeKeys({
|
|
253
|
+
limit: input.limit,
|
|
254
|
+
...input.after === void 0 ? {} : { after: input.after }
|
|
255
|
+
});
|
|
256
|
+
return page(rows, input, (scopeKey) => scopeKey);
|
|
257
|
+
}),
|
|
258
|
+
/**
|
|
259
|
+
* With `name`, the one channel of that name: 1 read. With `ids`, the
|
|
260
|
+
* channels of up to 100 IDs: 1 batch read. With `limit` or `cursor`, one
|
|
261
|
+
* page by name. With none, every channel, as servers before pages answered.
|
|
262
|
+
*/
|
|
206
263
|
getChannels: onCore(async (core, request) => {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
264
|
+
const url = new URL(request.url);
|
|
265
|
+
const name = url.searchParams.get("name");
|
|
266
|
+
if (name !== null) {
|
|
267
|
+
const channel = await core.findChannelByName(name);
|
|
268
|
+
return channel === null ? notFound() : json({ data: channel });
|
|
269
|
+
}
|
|
270
|
+
const ids = url.searchParams.get("ids");
|
|
271
|
+
if (ids !== null) {
|
|
272
|
+
const list = ids.split(",").filter((id) => id.length > 0);
|
|
273
|
+
if (list.length === 0 || list.length > MAX_IDS) throw new HandlerBadRequestError(`Channels by ID take ids=<channel id>,... with 1 to ${MAX_IDS} ids.`);
|
|
274
|
+
return json({ data: await core.getChannels(list) });
|
|
275
|
+
}
|
|
276
|
+
if (url.searchParams.has("limit") || url.searchParams.has("cursor")) {
|
|
277
|
+
const input = keyset(url, LIMITS.maxValue, "asc");
|
|
278
|
+
const rows = await core.listChannels(input);
|
|
279
|
+
return page(rows, input, (row) => row.name);
|
|
280
|
+
}
|
|
281
|
+
return json({ data: await core.listChannels() });
|
|
211
282
|
}),
|
|
212
283
|
/** The channel named in the body, created when missing. */
|
|
213
284
|
createChannel: onCore(async (core, request) => {
|
|
@@ -249,15 +320,40 @@ const createAdminRouteHandlers = () => ({
|
|
|
249
320
|
return row === null ? notFound() : json({ data: row });
|
|
250
321
|
}),
|
|
251
322
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
323
|
+
/**
|
|
324
|
+
* The release a label names, or `null`: never 404, which tells a client
|
|
325
|
+
* the server has no such route.
|
|
326
|
+
*/
|
|
327
|
+
getReleaseByLabel: onCore(async (core, request) => {
|
|
328
|
+
const url = new URL(request.url);
|
|
329
|
+
const channel = url.searchParams.get("channel");
|
|
330
|
+
const platform = platformOf(url);
|
|
331
|
+
const label = Number(url.searchParams.get("label"));
|
|
332
|
+
if (channel === null || channel.length === 0 || platform === void 0 || !Number.isSafeInteger(label) || label < 1) throw new HandlerBadRequestError("A release label lookup takes channel, platform, and a label of 1 or more.");
|
|
333
|
+
return json({ data: await core.getReleaseByLabel({
|
|
334
|
+
channel,
|
|
335
|
+
platform,
|
|
336
|
+
label
|
|
337
|
+
}) });
|
|
338
|
+
}),
|
|
339
|
+
fillReleaseLabels: onCore(async (core, request) => {
|
|
340
|
+
const body = await request.json().catch(() => ({}));
|
|
341
|
+
const input = body !== null && typeof body === "object" ? body : {};
|
|
342
|
+
return json({ data: await core.fillReleaseLabels({
|
|
343
|
+
dryRun: input.dryRun === true,
|
|
344
|
+
catalogs: input.catalogs !== false
|
|
345
|
+
}) });
|
|
346
|
+
}),
|
|
252
347
|
updateBundle: onCore(async (core, request, params) => {
|
|
253
348
|
const bundleId = requireRouteParam(params, "id");
|
|
254
|
-
|
|
349
|
+
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
350
|
+
await refusingInvalid(() => core.updateBundle(bundleId, update));
|
|
255
351
|
return noContent();
|
|
256
352
|
}),
|
|
257
353
|
countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
258
354
|
countBundleChildren: onCore(async (core, request) => {
|
|
259
355
|
const ids = (new URL(request.url).searchParams.get("ids") ?? "").split(",").filter((id) => id.length > 0);
|
|
260
|
-
if (ids.length === 0 || ids.length >
|
|
356
|
+
if (ids.length === 0 || ids.length > MAX_IDS) throw new HandlerBadRequestError(`Bundle child counts take ids=<bundle id>,... with 1 to ${MAX_IDS} ids.`);
|
|
261
357
|
return json({ data: await core.countBundleChildren(ids) });
|
|
262
358
|
}),
|
|
263
359
|
listBundleChildren: onCore(async (core, request, params) => {
|
|
@@ -275,7 +371,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
275
371
|
deployReleases: onCore(async (core, request) => {
|
|
276
372
|
const { deployments } = await body(request);
|
|
277
373
|
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);
|
|
374
|
+
return json({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
|
|
279
375
|
}),
|
|
280
376
|
promoteRelease: onCore(async (core, request, params) => {
|
|
281
377
|
const input = await body(request);
|
|
@@ -298,9 +394,22 @@ const createAdminRouteHandlers = () => ({
|
|
|
298
394
|
const url = new URL(request.url);
|
|
299
395
|
const scope = nativeBuildScopeOf(url);
|
|
300
396
|
const buildKey = url.searchParams.get("buildKey");
|
|
301
|
-
|
|
397
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
398
|
+
const kind = url.searchParams.get("kind");
|
|
399
|
+
const options = {
|
|
400
|
+
...buildKey === null ? {} : { buildKey },
|
|
401
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
402
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan },
|
|
403
|
+
...kind === null ? {} : { artifactKind: kind }
|
|
404
|
+
};
|
|
405
|
+
return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
406
|
+
}),
|
|
407
|
+
findNativeBuildSibling: onCore(async (core, _request, params) => {
|
|
408
|
+
const build = await core.getNativeBuild(requireRouteParam(params, "id"));
|
|
409
|
+
return json({ data: build === null ? null : await core.findNativeBuildSibling(build) });
|
|
302
410
|
}),
|
|
303
411
|
getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
412
|
+
findNativeBuildByBuiltInBundle: onCore(async (core, _request, params) => json({ data: await core.findNativeBuildByBuiltInBundle(requireRouteParam(params, "bundleId")) })),
|
|
304
413
|
listNativeBuilds: onCore(async (core, request) => {
|
|
305
414
|
const url = new URL(request.url);
|
|
306
415
|
const input = keyset(url);
|
|
@@ -312,14 +421,97 @@ const createAdminRouteHandlers = () => ({
|
|
|
312
421
|
}),
|
|
313
422
|
recordNativeBuildSubmission: onCore(async (core, request, params) => {
|
|
314
423
|
const input = await body(request);
|
|
315
|
-
if (!isRecord(input) ||
|
|
424
|
+
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
425
|
const submission = {
|
|
317
426
|
destination: input.destination,
|
|
318
427
|
version: input.version
|
|
319
428
|
};
|
|
320
429
|
return json({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(requireRouteParam(params, "id"), submission)) });
|
|
321
430
|
}),
|
|
431
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
432
|
+
const input = await body(request);
|
|
433
|
+
if (!isRecord(input) || typeof input.storeBuild !== "boolean") throw new HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
434
|
+
const mark = { storeBuild: input.storeBuild };
|
|
435
|
+
return json({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
|
|
436
|
+
}),
|
|
322
437
|
deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
|
|
438
|
+
listIosDevices: onCore(async (core, request) => {
|
|
439
|
+
const url = new URL(request.url);
|
|
440
|
+
const input = keyset(url);
|
|
441
|
+
const status = url.searchParams.get("status");
|
|
442
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
443
|
+
...input,
|
|
444
|
+
...status === null ? {} : { status }
|
|
445
|
+
})), input, ({ id }) => id);
|
|
446
|
+
}),
|
|
447
|
+
findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
|
|
448
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
449
|
+
const input = await body(request);
|
|
450
|
+
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.");
|
|
451
|
+
const device = {
|
|
452
|
+
udid: input.udid,
|
|
453
|
+
name: input.name,
|
|
454
|
+
requestedBy: input.requestedBy
|
|
455
|
+
};
|
|
456
|
+
return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
457
|
+
}),
|
|
458
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
459
|
+
const input = await body(request);
|
|
460
|
+
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.");
|
|
461
|
+
const approval = {
|
|
462
|
+
approvedBy: input.approvedBy,
|
|
463
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
464
|
+
};
|
|
465
|
+
return json({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
|
|
466
|
+
}),
|
|
467
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
468
|
+
const input = await body(request);
|
|
469
|
+
if (!isText(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
|
|
470
|
+
const name = input.name;
|
|
471
|
+
return json({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
|
|
472
|
+
}),
|
|
473
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
474
|
+
const input = await body(request);
|
|
475
|
+
const seen = input.seen;
|
|
476
|
+
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.");
|
|
477
|
+
const outcome = {
|
|
478
|
+
id: requireRouteParam(params, "id"),
|
|
479
|
+
seen: {
|
|
480
|
+
status: seen.status,
|
|
481
|
+
approvedAtMs: seen.approvedAtMs
|
|
482
|
+
},
|
|
483
|
+
issuerId: input.issuerId,
|
|
484
|
+
outcome: input.outcome,
|
|
485
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
486
|
+
};
|
|
487
|
+
return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
488
|
+
}),
|
|
489
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
490
|
+
const { issuerId } = await body(request);
|
|
491
|
+
if (!isText(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
492
|
+
return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
493
|
+
}),
|
|
494
|
+
findIosDeviceAccount: onCore(async (core) => json({ data: await core.findIosDeviceAccount() })),
|
|
495
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
496
|
+
const { buildId, ids } = await body(request);
|
|
497
|
+
if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
498
|
+
if (ids.length > MAX_IDS) throw new HandlerBadRequestError(`Marking iOS devices in a build takes at most ${MAX_IDS} ids a request.`);
|
|
499
|
+
await core.markIosDevicesInBuild({
|
|
500
|
+
buildId,
|
|
501
|
+
ids
|
|
502
|
+
});
|
|
503
|
+
return noContent();
|
|
504
|
+
}),
|
|
505
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
506
|
+
const url = new URL(request.url);
|
|
507
|
+
const status = url.searchParams.get("status");
|
|
508
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
509
|
+
const only = {
|
|
510
|
+
...status === null ? {} : { status },
|
|
511
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
512
|
+
};
|
|
513
|
+
return json({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
|
|
514
|
+
}),
|
|
323
515
|
deleteBundles: onCore(async (core, request) => {
|
|
324
516
|
const { ids } = await body(request);
|
|
325
517
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -374,6 +566,21 @@ const ADMIN_ROUTES = [
|
|
|
374
566
|
path: "/release-catalogs",
|
|
375
567
|
handler: "listReleaseCatalogs"
|
|
376
568
|
},
|
|
569
|
+
{
|
|
570
|
+
method: "GET",
|
|
571
|
+
path: "/release-scopes",
|
|
572
|
+
handler: "listReleaseScopeKeys"
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
method: "GET",
|
|
576
|
+
path: "/release-labels",
|
|
577
|
+
handler: "getReleaseByLabel"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
method: "POST",
|
|
581
|
+
path: "/release-labels/fill",
|
|
582
|
+
handler: "fillReleaseLabels"
|
|
583
|
+
},
|
|
377
584
|
{
|
|
378
585
|
method: "POST",
|
|
379
586
|
path: "/release-catalogs/:scopeKey/rebuild",
|
|
@@ -449,6 +656,16 @@ const ADMIN_ROUTES = [
|
|
|
449
656
|
path: "/native-builds/latest",
|
|
450
657
|
handler: "findNativeBuild"
|
|
451
658
|
},
|
|
659
|
+
{
|
|
660
|
+
method: "GET",
|
|
661
|
+
path: "/native-builds/built-in/:bundleId",
|
|
662
|
+
handler: "findNativeBuildByBuiltInBundle"
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
method: "GET",
|
|
666
|
+
path: "/native-builds/:id/sibling",
|
|
667
|
+
handler: "findNativeBuildSibling"
|
|
668
|
+
},
|
|
452
669
|
{
|
|
453
670
|
method: "GET",
|
|
454
671
|
path: "/native-builds/:id",
|
|
@@ -464,10 +681,65 @@ const ADMIN_ROUTES = [
|
|
|
464
681
|
path: "/native-builds/:id/submission",
|
|
465
682
|
handler: "recordNativeBuildSubmission"
|
|
466
683
|
},
|
|
684
|
+
{
|
|
685
|
+
method: "POST",
|
|
686
|
+
path: "/native-builds/:id/store-build",
|
|
687
|
+
handler: "markNativeBuild"
|
|
688
|
+
},
|
|
467
689
|
{
|
|
468
690
|
method: "DELETE",
|
|
469
691
|
path: "/native-builds/:id",
|
|
470
692
|
handler: "deleteNativeBuild"
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
method: "GET",
|
|
696
|
+
path: "/ios-devices",
|
|
697
|
+
handler: "listIosDevices"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
method: "POST",
|
|
701
|
+
path: "/ios-devices",
|
|
702
|
+
handler: "requestIosDevice"
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
method: "GET",
|
|
706
|
+
path: "/ios-devices/udid/:udid",
|
|
707
|
+
handler: "findIosDevice"
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
method: "POST",
|
|
711
|
+
path: "/ios-devices/in-build",
|
|
712
|
+
handler: "markIosDevicesInBuild"
|
|
713
|
+
},
|
|
714
|
+
{
|
|
715
|
+
method: "GET",
|
|
716
|
+
path: "/ios-devices/account",
|
|
717
|
+
handler: "findIosDeviceAccount"
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
method: "POST",
|
|
721
|
+
path: "/ios-devices/account",
|
|
722
|
+
handler: "claimIosDeviceAccount"
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
method: "POST",
|
|
726
|
+
path: "/ios-devices/:id/approval",
|
|
727
|
+
handler: "approveIosDevice"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
method: "POST",
|
|
731
|
+
path: "/ios-devices/:id/outcome",
|
|
732
|
+
handler: "recordIosDeviceOutcome"
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
method: "PATCH",
|
|
736
|
+
path: "/ios-devices/:id",
|
|
737
|
+
handler: "renameIosDevice"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
method: "DELETE",
|
|
741
|
+
path: "/ios-devices/:id",
|
|
742
|
+
handler: "deleteIosDevice"
|
|
471
743
|
}
|
|
472
744
|
];
|
|
473
745
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_releaseCatalog = require("./db/releaseCatalog.cjs");
|
|
1
2
|
const require_handlerParameters = require("./handlerParameters.cjs");
|
|
2
3
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
4
|
let _hot_updater_protocol = require("@hot-updater/protocol");
|
|
@@ -20,9 +21,9 @@ const CATALOG_CACHE_CONTROL = "public, max-age=0, s-maxage=5";
|
|
|
20
21
|
* background. `stale-if-error=0` keeps origin errors visible: without it,
|
|
21
22
|
* Cloudflare serves a stale copy on error indefinitely.
|
|
22
23
|
*
|
|
23
|
-
* A device can see a catalog
|
|
24
|
-
* replaced it: the origin's 5-second catalog
|
|
25
|
-
* 5 stale at the CDN. A revoked API key can read a cached catalog up to
|
|
24
|
+
* A device can see a catalog, or a scope's lack of one, up to 15 seconds
|
|
25
|
+
* after a deploy or a Roll back replaced it: the origin's 5-second catalog
|
|
26
|
+
* memo, then 5 seconds fresh and 5 stale at the CDN. A revoked API key can read a cached catalog up to
|
|
26
27
|
* 10 seconds. Devices and caches that don't read the header keep
|
|
27
28
|
* `Cache-Control`.
|
|
28
29
|
*/
|
|
@@ -101,38 +102,53 @@ const catalogResponse = async (catalog, request) => {
|
|
|
101
102
|
};
|
|
102
103
|
const createReleaseCatalogRouteHandlers = () => {
|
|
103
104
|
const cache = /* @__PURE__ */ new Map();
|
|
105
|
+
const evict = (insertedHit) => {
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
let oldestMiss;
|
|
108
|
+
let oldest;
|
|
109
|
+
for (const [key, entry] of cache) if (entry.expiresAt <= now) cache.delete(key);
|
|
110
|
+
else {
|
|
111
|
+
if (entry.row === null) oldestMiss ??= key;
|
|
112
|
+
oldest ??= key;
|
|
113
|
+
}
|
|
114
|
+
if (cache.size <= ORIGIN_CACHE_MAX_ENTRIES) return;
|
|
115
|
+
const victim = oldestMiss ?? (insertedHit ? oldest : void 0);
|
|
116
|
+
if (victim !== void 0) cache.delete(victim);
|
|
117
|
+
};
|
|
104
118
|
const inFlight = /* @__PURE__ */ new Map();
|
|
105
|
-
const
|
|
106
|
-
const cached = cache.get(
|
|
119
|
+
const loadRow = async (scopeKey, load) => {
|
|
120
|
+
const cached = cache.get(scopeKey);
|
|
107
121
|
if (cached !== void 0 && cached.expiresAt > Date.now()) {
|
|
108
|
-
cache.delete(
|
|
109
|
-
cache.set(
|
|
110
|
-
return cached.
|
|
122
|
+
cache.delete(scopeKey);
|
|
123
|
+
cache.set(scopeKey, cached);
|
|
124
|
+
return cached.row;
|
|
111
125
|
}
|
|
112
|
-
if (cached !== void 0) cache.delete(
|
|
113
|
-
const pending = inFlight.get(
|
|
126
|
+
if (cached !== void 0) cache.delete(scopeKey);
|
|
127
|
+
const pending = inFlight.get(scopeKey);
|
|
114
128
|
if (pending !== void 0) return pending;
|
|
115
|
-
const next = load().then((
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const oldestKey = cache.keys().next().value;
|
|
123
|
-
if (oldestKey === void 0) break;
|
|
124
|
-
cache.delete(oldestKey);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return catalog;
|
|
129
|
+
const next = load().then((row) => {
|
|
130
|
+
cache.set(scopeKey, {
|
|
131
|
+
row,
|
|
132
|
+
expiresAt: Date.now() + ORIGIN_CACHE_TTL_MS
|
|
133
|
+
});
|
|
134
|
+
if (cache.size > ORIGIN_CACHE_MAX_ENTRIES) evict(row !== null);
|
|
135
|
+
return row;
|
|
128
136
|
});
|
|
129
|
-
inFlight.set(
|
|
137
|
+
inFlight.set(scopeKey, next);
|
|
130
138
|
try {
|
|
131
139
|
return await next;
|
|
132
140
|
} finally {
|
|
133
|
-
inFlight.delete(
|
|
141
|
+
inFlight.delete(scopeKey);
|
|
134
142
|
}
|
|
135
143
|
};
|
|
144
|
+
const loadCatalog = async (core, input) => {
|
|
145
|
+
const scopeKey = require_releaseCatalog.releaseCatalogScopeKeyOf(input);
|
|
146
|
+
const parsed = await loadRow(scopeKey, async () => {
|
|
147
|
+
const row = await core.getReleaseCatalogRow(scopeKey);
|
|
148
|
+
return row === null ? null : require_releaseCatalog.parseReleaseCatalogRow(row);
|
|
149
|
+
});
|
|
150
|
+
return require_releaseCatalog.projectParsedReleaseCatalogRow(parsed, input, scopeKey);
|
|
151
|
+
};
|
|
136
152
|
return {
|
|
137
153
|
appVersionReleaseCatalog: async (params, request, { core }) => {
|
|
138
154
|
const rawAppVersion = require_handlerParameters.requireRouteParam(params, "appVersion");
|
|
@@ -146,7 +162,7 @@ const createReleaseCatalogRouteHandlers = () => {
|
|
|
146
162
|
};
|
|
147
163
|
const invalid = invalidScope(input);
|
|
148
164
|
if (invalid) return invalid;
|
|
149
|
-
return catalogResponse(await loadCatalog(
|
|
165
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
150
166
|
},
|
|
151
167
|
fingerprintReleaseCatalog: async (params, request, { core }) => {
|
|
152
168
|
const input = {
|
|
@@ -157,7 +173,7 @@ const createReleaseCatalogRouteHandlers = () => {
|
|
|
157
173
|
};
|
|
158
174
|
const invalid = invalidScope(input);
|
|
159
175
|
if (invalid) return invalid;
|
|
160
|
-
return catalogResponse(await loadCatalog(
|
|
176
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
161
177
|
},
|
|
162
178
|
artifactV2: async (params, _request, { core }) => {
|
|
163
179
|
const info = await core.getArtifactInfo(require_handlerParameters.requireRouteParam(params, "targetBundleId"), require_handlerParameters.requireRouteParam(params, "currentBundleId"), 2);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseReleaseCatalogRow, projectParsedReleaseCatalogRow, releaseCatalogScopeKeyOf } from "./db/releaseCatalog.mjs";
|
|
1
2
|
import { requirePlatformParam, requireRouteParam } from "./handlerParameters.mjs";
|
|
2
3
|
import { canonicalizeAppVersion } from "@hot-updater/plugin-core";
|
|
3
4
|
import { ARTIFACT_FILES_REQUEST_LIMIT, createReleaseCatalogScopeKey } from "@hot-updater/protocol";
|
|
@@ -20,9 +21,9 @@ const CATALOG_CACHE_CONTROL = "public, max-age=0, s-maxage=5";
|
|
|
20
21
|
* background. `stale-if-error=0` keeps origin errors visible: without it,
|
|
21
22
|
* Cloudflare serves a stale copy on error indefinitely.
|
|
22
23
|
*
|
|
23
|
-
* A device can see a catalog
|
|
24
|
-
* replaced it: the origin's 5-second catalog
|
|
25
|
-
* 5 stale at the CDN. A revoked API key can read a cached catalog up to
|
|
24
|
+
* A device can see a catalog, or a scope's lack of one, up to 15 seconds
|
|
25
|
+
* after a deploy or a Roll back replaced it: the origin's 5-second catalog
|
|
26
|
+
* memo, then 5 seconds fresh and 5 stale at the CDN. A revoked API key can read a cached catalog up to
|
|
26
27
|
* 10 seconds. Devices and caches that don't read the header keep
|
|
27
28
|
* `Cache-Control`.
|
|
28
29
|
*/
|
|
@@ -101,38 +102,53 @@ const catalogResponse = async (catalog, request) => {
|
|
|
101
102
|
};
|
|
102
103
|
const createReleaseCatalogRouteHandlers = () => {
|
|
103
104
|
const cache = /* @__PURE__ */ new Map();
|
|
105
|
+
const evict = (insertedHit) => {
|
|
106
|
+
const now = Date.now();
|
|
107
|
+
let oldestMiss;
|
|
108
|
+
let oldest;
|
|
109
|
+
for (const [key, entry] of cache) if (entry.expiresAt <= now) cache.delete(key);
|
|
110
|
+
else {
|
|
111
|
+
if (entry.row === null) oldestMiss ??= key;
|
|
112
|
+
oldest ??= key;
|
|
113
|
+
}
|
|
114
|
+
if (cache.size <= ORIGIN_CACHE_MAX_ENTRIES) return;
|
|
115
|
+
const victim = oldestMiss ?? (insertedHit ? oldest : void 0);
|
|
116
|
+
if (victim !== void 0) cache.delete(victim);
|
|
117
|
+
};
|
|
104
118
|
const inFlight = /* @__PURE__ */ new Map();
|
|
105
|
-
const
|
|
106
|
-
const cached = cache.get(
|
|
119
|
+
const loadRow = async (scopeKey, load) => {
|
|
120
|
+
const cached = cache.get(scopeKey);
|
|
107
121
|
if (cached !== void 0 && cached.expiresAt > Date.now()) {
|
|
108
|
-
cache.delete(
|
|
109
|
-
cache.set(
|
|
110
|
-
return cached.
|
|
122
|
+
cache.delete(scopeKey);
|
|
123
|
+
cache.set(scopeKey, cached);
|
|
124
|
+
return cached.row;
|
|
111
125
|
}
|
|
112
|
-
if (cached !== void 0) cache.delete(
|
|
113
|
-
const pending = inFlight.get(
|
|
126
|
+
if (cached !== void 0) cache.delete(scopeKey);
|
|
127
|
+
const pending = inFlight.get(scopeKey);
|
|
114
128
|
if (pending !== void 0) return pending;
|
|
115
|
-
const next = load().then((
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const oldestKey = cache.keys().next().value;
|
|
123
|
-
if (oldestKey === void 0) break;
|
|
124
|
-
cache.delete(oldestKey);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return catalog;
|
|
129
|
+
const next = load().then((row) => {
|
|
130
|
+
cache.set(scopeKey, {
|
|
131
|
+
row,
|
|
132
|
+
expiresAt: Date.now() + ORIGIN_CACHE_TTL_MS
|
|
133
|
+
});
|
|
134
|
+
if (cache.size > ORIGIN_CACHE_MAX_ENTRIES) evict(row !== null);
|
|
135
|
+
return row;
|
|
128
136
|
});
|
|
129
|
-
inFlight.set(
|
|
137
|
+
inFlight.set(scopeKey, next);
|
|
130
138
|
try {
|
|
131
139
|
return await next;
|
|
132
140
|
} finally {
|
|
133
|
-
inFlight.delete(
|
|
141
|
+
inFlight.delete(scopeKey);
|
|
134
142
|
}
|
|
135
143
|
};
|
|
144
|
+
const loadCatalog = async (core, input) => {
|
|
145
|
+
const scopeKey = releaseCatalogScopeKeyOf(input);
|
|
146
|
+
const parsed = await loadRow(scopeKey, async () => {
|
|
147
|
+
const row = await core.getReleaseCatalogRow(scopeKey);
|
|
148
|
+
return row === null ? null : parseReleaseCatalogRow(row);
|
|
149
|
+
});
|
|
150
|
+
return projectParsedReleaseCatalogRow(parsed, input, scopeKey);
|
|
151
|
+
};
|
|
136
152
|
return {
|
|
137
153
|
appVersionReleaseCatalog: async (params, request, { core }) => {
|
|
138
154
|
const rawAppVersion = requireRouteParam(params, "appVersion");
|
|
@@ -146,7 +162,7 @@ const createReleaseCatalogRouteHandlers = () => {
|
|
|
146
162
|
};
|
|
147
163
|
const invalid = invalidScope(input);
|
|
148
164
|
if (invalid) return invalid;
|
|
149
|
-
return catalogResponse(await loadCatalog(
|
|
165
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
150
166
|
},
|
|
151
167
|
fingerprintReleaseCatalog: async (params, request, { core }) => {
|
|
152
168
|
const input = {
|
|
@@ -157,7 +173,7 @@ const createReleaseCatalogRouteHandlers = () => {
|
|
|
157
173
|
};
|
|
158
174
|
const invalid = invalidScope(input);
|
|
159
175
|
if (invalid) return invalid;
|
|
160
|
-
return catalogResponse(await loadCatalog(
|
|
176
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
161
177
|
},
|
|
162
178
|
artifactV2: async (params, _request, { core }) => {
|
|
163
179
|
const info = await core.getArtifactInfo(requireRouteParam(params, "targetBundleId"), requireRouteParam(params, "currentBundleId"), 2);
|
package/dist/package.cjs
CHANGED