@hot-updater/server 1.0.0-rc.2 → 1.0.0-rc.21
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/LICENSE +12 -14
- package/dist/adapters/drizzle.cjs +32 -75
- package/dist/adapters/drizzle.d.cts +13 -5
- package/dist/adapters/drizzle.d.mts +13 -5
- package/dist/adapters/drizzle.mjs +32 -77
- package/dist/adapters/drizzleExecutor.cjs +114 -0
- package/dist/adapters/drizzleExecutor.d.cts +9 -0
- package/dist/adapters/drizzleExecutor.d.mts +9 -0
- package/dist/adapters/drizzleExecutor.mjs +112 -0
- package/dist/adapters/kysely.cjs +22 -31
- package/dist/adapters/kysely.d.cts +10 -6
- package/dist/adapters/kysely.d.mts +10 -6
- package/dist/adapters/kysely.mjs +23 -33
- package/dist/adapters/kyselyExecutor.cjs +32 -0
- package/dist/adapters/kyselyExecutor.d.cts +11 -0
- package/dist/adapters/kyselyExecutor.d.mts +11 -0
- package/dist/adapters/kyselyExecutor.mjs +32 -0
- package/dist/adapters/mongodb.cjs +18 -54
- package/dist/adapters/mongodb.d.cts +10 -5
- package/dist/adapters/mongodb.d.mts +10 -5
- package/dist/adapters/mongodb.mjs +19 -56
- package/dist/adapters/mongodbAdapter.cjs +192 -0
- package/dist/adapters/mongodbAdapter.d.cts +9 -0
- package/dist/adapters/mongodbAdapter.d.mts +9 -0
- package/dist/adapters/mongodbAdapter.mjs +191 -0
- package/dist/adapters/prisma.cjs +35 -267
- package/dist/adapters/prisma.d.cts +12 -7
- package/dist/adapters/prisma.d.mts +12 -7
- package/dist/adapters/prisma.mjs +36 -268
- package/dist/adapters/prismaExecutor.cjs +63 -0
- package/dist/adapters/prismaExecutor.mjs +63 -0
- package/dist/adapters/sqlProviders.cjs +14 -0
- package/dist/adapters/sqlProviders.mjs +14 -0
- package/dist/assembly/assemblePlugins.cjs +144 -0
- package/dist/assembly/assemblePlugins.d.cts +5 -0
- package/dist/assembly/assemblePlugins.d.mts +5 -0
- package/dist/assembly/assemblePlugins.mjs +139 -0
- package/dist/assembly/clientPlugins.cjs +88 -0
- package/dist/assembly/clientPlugins.mjs +88 -0
- package/dist/assembly/configError.d.cts +2 -0
- package/dist/assembly/configError.d.mts +2 -0
- package/dist/assembly/configError.mjs +2 -0
- package/dist/core/api.cjs +51 -0
- package/dist/core/api.d.cts +54 -0
- package/dist/core/api.d.mts +54 -0
- package/dist/core/api.mjs +51 -0
- package/dist/core/baseCandidates.cjs +28 -0
- package/dist/core/baseCandidates.mjs +28 -0
- package/dist/core/operations.cjs +351 -0
- package/dist/core/operations.mjs +351 -0
- package/dist/core/reads.cjs +273 -0
- package/dist/core/reads.d.cts +9 -0
- package/dist/core/reads.d.mts +9 -0
- package/dist/core/reads.mjs +267 -0
- package/dist/core/releases.cjs +193 -0
- package/dist/core/releases.mjs +190 -0
- package/dist/core/writes.cjs +96 -0
- package/dist/core/writes.mjs +91 -0
- package/dist/createHotUpdaterCore.cjs +72 -91
- package/dist/createHotUpdaterCore.d.cts +106 -38
- package/dist/createHotUpdaterCore.d.mts +106 -38
- package/dist/createHotUpdaterCore.mjs +74 -89
- package/dist/db/engineDrizzleSchema.cjs +53 -0
- package/dist/db/engineDrizzleSchema.mjs +53 -0
- package/dist/db/enginePrismaSchema.cjs +84 -0
- package/dist/db/enginePrismaSchema.d.cts +5 -0
- package/dist/db/enginePrismaSchema.d.mts +5 -0
- package/dist/db/enginePrismaSchema.mjs +83 -0
- package/dist/db/releaseCatalog.cjs +24 -47
- package/dist/db/releaseCatalog.mjs +20 -44
- package/dist/db/updateArtifacts.cjs +43 -72
- package/dist/db/updateArtifacts.mjs +40 -69
- package/dist/handler.cjs +59 -43
- package/dist/handler.d.cts +3 -5
- package/dist/handler.d.mts +3 -5
- package/dist/handler.mjs +61 -43
- package/dist/handlerAdminRoutes.cjs +374 -0
- package/dist/handlerAdminRoutes.mjs +372 -0
- package/dist/handlerParameters.cjs +6 -11
- package/dist/handlerParameters.mjs +6 -10
- package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
- package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
- package/dist/handlerTypes.d.cts +2 -55
- package/dist/handlerTypes.d.mts +2 -55
- package/dist/handlerVersionRoutes.cjs +20 -4
- package/dist/handlerVersionRoutes.mjs +20 -4
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -9
- package/dist/index.d.mts +8 -9
- package/dist/index.mjs +3 -4
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/node.mjs +4 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +9 -0
- package/dist/plugins/api-keys/index.d.cts +1 -0
- package/dist/plugins/api-keys/index.d.mts +1 -0
- package/dist/plugins/api-keys/index.mjs +2 -0
- package/dist/plugins/definePlugin.d.cts +2 -0
- package/dist/plugins/definePlugin.d.mts +2 -0
- package/dist/plugins/insights/index.cjs +9 -0
- package/dist/plugins/insights/index.d.cts +1 -0
- package/dist/plugins/insights/index.d.mts +1 -0
- package/dist/plugins/insights/index.mjs +2 -0
- package/dist/plugins/official.cjs +30 -0
- package/dist/plugins/official.mjs +29 -0
- package/dist/storageAccess.cjs +13 -10
- package/dist/storageAccess.mjs +13 -10
- package/dist/types/index.d.cts +2 -28
- package/dist/types/index.d.mts +2 -28
- package/package.json +26 -14
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/adapters/databaseConstraintErrors.cjs +0 -22
- package/dist/adapters/databaseConstraintErrors.mjs +0 -21
- package/dist/adapters/databasePluginUtils.cjs +0 -116
- package/dist/adapters/databasePluginUtils.mjs +0 -106
- package/dist/adapters/drizzleCrud.cjs +0 -311
- package/dist/adapters/drizzleCrud.mjs +0 -308
- package/dist/adapters/drizzleLazyDB.cjs +0 -106
- package/dist/adapters/drizzleLazyDB.mjs +0 -106
- package/dist/adapters/drizzleQuery.cjs +0 -69
- package/dist/adapters/drizzleQuery.mjs +0 -69
- package/dist/adapters/insightsTransaction.cjs +0 -22
- package/dist/adapters/insightsTransaction.mjs +0 -22
- package/dist/adapters/kyselyCrud.cjs +0 -305
- package/dist/adapters/kyselyCrud.mjs +0 -304
- package/dist/adapters/kyselyQuery.cjs +0 -56
- package/dist/adapters/kyselyQuery.mjs +0 -56
- package/dist/adapters/mongodbCollections.cjs +0 -38
- package/dist/adapters/mongodbCollections.mjs +0 -32
- package/dist/adapters/mongodbQuery.cjs +0 -94
- package/dist/adapters/mongodbQuery.mjs +0 -86
- package/dist/adapters/mongodbReads.cjs +0 -210
- package/dist/adapters/mongodbReads.mjs +0 -210
- package/dist/adapters/mongodbWrites.cjs +0 -148
- package/dist/adapters/mongodbWrites.mjs +0 -148
- package/dist/adapters/prismaQuery.cjs +0 -57
- package/dist/adapters/prismaQuery.mjs +0 -56
- package/dist/adapters/prismaRows.cjs +0 -219
- package/dist/adapters/prismaRows.mjs +0 -209
- package/dist/apiKeys.cjs +0 -143
- package/dist/apiKeys.d.cts +0 -49
- package/dist/apiKeys.d.mts +0 -49
- package/dist/apiKeys.mjs +0 -133
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -16
- package/dist/db/createBundleDiff.d.mts +0 -16
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/databasePluginCore.cjs +0 -137
- package/dist/db/databasePluginCore.mjs +0 -137
- package/dist/db/fixedMigrator.cjs +0 -79
- package/dist/db/fixedMigrator.mjs +0 -78
- package/dist/db/fixedMigratorMongo.cjs +0 -321
- package/dist/db/fixedMigratorMongo.mjs +0 -321
- package/dist/db/fixedMigratorShared.cjs +0 -23
- package/dist/db/fixedMigratorShared.mjs +0 -18
- package/dist/db/index.cjs +0 -27
- package/dist/db/index.d.cts +0 -12
- package/dist/db/index.d.mts +0 -12
- package/dist/db/index.mjs +0 -22
- package/dist/db/mongoMigrationExecution.cjs +0 -11
- package/dist/db/mongoMigrationExecution.mjs +0 -11
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schema/insightsCollation.cjs +0 -14
- package/dist/db/schema/insightsCollation.mjs +0 -14
- package/dist/db/schema/mongodb.cjs +0 -25
- package/dist/db/schema/mongodb.mjs +0 -25
- package/dist/db/schema/registry.cjs +0 -21
- package/dist/db/schema/registry.mjs +0 -17
- package/dist/db/schema/sql.cjs +0 -105
- package/dist/db/schema/sql.mjs +0 -97
- package/dist/db/schema/sqlOperations.cjs +0 -27
- package/dist/db/schema/sqlOperations.mjs +0 -26
- package/dist/db/schemaGenerators.cjs +0 -275
- package/dist/db/schemaGenerators.mjs +0 -273
- package/dist/db/schemaReadiness.cjs +0 -26
- package/dist/db/schemaReadiness.d.cts +0 -9
- package/dist/db/schemaReadiness.d.mts +0 -9
- package/dist/db/schemaReadiness.mjs +0 -25
- package/dist/db/sqlMigrationExecution.cjs +0 -67
- package/dist/db/sqlMigrationExecution.mjs +0 -67
- package/dist/db/types.cjs +0 -22
- package/dist/db/types.d.cts +0 -118
- package/dist/db/types.d.mts +0 -118
- package/dist/db/types.mjs +0 -19
- package/dist/handlerBundleRoutes.cjs +0 -155
- package/dist/handlerBundleRoutes.mjs +0 -155
- package/dist/handlerReleaseManagementRoutes.cjs +0 -124
- package/dist/handlerReleaseManagementRoutes.mjs +0 -124
- package/dist/insights/domain.d.cts +0 -89
- package/dist/insights/domain.d.mts +0 -89
- package/dist/insights/errors.cjs +0 -15
- package/dist/insights/errors.mjs +0 -14
- package/dist/insights/eventInput.cjs +0 -155
- package/dist/insights/eventInput.mjs +0 -153
- package/dist/insights/provider.cjs +0 -314
- package/dist/insights/provider.d.cts +0 -6
- package/dist/insights/provider.d.mts +0 -6
- package/dist/insights/provider.mjs +0 -314
- package/dist/insights/queryInput.cjs +0 -93
- package/dist/insights/queryInput.mjs +0 -91
- package/dist/insights/routes.cjs +0 -58
- package/dist/insights/routes.mjs +0 -56
- package/dist/insights/types.d.cts +0 -32
- package/dist/insights/types.d.mts +0 -32
- package/dist/schema/dsl.cjs +0 -103
- package/dist/schema/dsl.mjs +0 -87
- package/dist/schema/index.cjs +0 -20
- package/dist/schema/index.mjs +0 -7
- package/dist/schema/settings.cjs +0 -9
- package/dist/schema/settings.mjs +0 -9
- package/dist/schema/types.cjs +0 -8
- package/dist/schema/types.mjs +0 -6
- package/dist/schema/v1_0_0.cjs +0 -406
- package/dist/schema/v1_0_0.mjs +0 -398
- package/src/adapters/databaseConstraintErrors.ts +0 -25
- package/src/adapters/databasePluginTestDatabase.ts +0 -120
- package/src/adapters/databasePluginUtils.spec.ts +0 -29
- package/src/adapters/databasePluginUtils.ts +0 -214
- package/src/adapters/drizzle.spec.ts +0 -336
- package/src/adapters/drizzle.ts +0 -162
- package/src/adapters/drizzleCrud.ts +0 -571
- package/src/adapters/drizzleLazyDB.ts +0 -271
- package/src/adapters/drizzleQuery.ts +0 -164
- package/src/adapters/insightsTransaction.ts +0 -32
- package/src/adapters/kysely.spec.ts +0 -174
- package/src/adapters/kysely.ts +0 -110
- package/src/adapters/kyselyCrud.ts +0 -709
- package/src/adapters/kyselyQuery.ts +0 -128
- package/src/adapters/mongodb.integration.spec.ts +0 -210
- package/src/adapters/mongodb.spec.ts +0 -209
- package/src/adapters/mongodb.ts +0 -138
- package/src/adapters/mongodbCollections.ts +0 -67
- package/src/adapters/mongodbQuery.ts +0 -255
- package/src/adapters/mongodbReads.ts +0 -380
- package/src/adapters/mongodbRows.spec.ts +0 -64
- package/src/adapters/mongodbRows.ts +0 -118
- package/src/adapters/mongodbTestClient.ts +0 -377
- package/src/adapters/mongodbTestFilter.ts +0 -169
- package/src/adapters/mongodbWrites.ts +0 -287
- package/src/adapters/prisma.spec.ts +0 -293
- package/src/adapters/prisma.ts +0 -565
- package/src/adapters/prismaQuery.ts +0 -129
- package/src/adapters/prismaRows.spec.ts +0 -98
- package/src/adapters/prismaRows.ts +0 -337
- package/src/adapters/prismaTestClient.ts +0 -413
- package/src/apiKeys.integration.spec.ts +0 -192
- package/src/apiKeys.spec.ts +0 -162
- package/src/apiKeys.ts +0 -220
- package/src/calculatePagination.ts +0 -34
- package/src/createHotUpdaterCore.ts +0 -246
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/createBundleDiff.spec.ts +0 -450
- package/src/db/createBundleDiff.ts +0 -364
- package/src/db/databasePluginCore.spec.ts +0 -62
- package/src/db/databasePluginCore.testFixtures.ts +0 -76
- package/src/db/databasePluginCore.ts +0 -185
- package/src/db/databasePluginUpdateCheck.bench.ts +0 -110
- package/src/db/fixedMigrator.spec.ts +0 -296
- package/src/db/fixedMigrator.ts +0 -147
- package/src/db/fixedMigratorMongo.spec.ts +0 -239
- package/src/db/fixedMigratorMongo.ts +0 -425
- package/src/db/fixedMigratorShared.ts +0 -36
- package/src/db/hotUpdaterSchema.ts +0 -5
- package/src/db/index.spec.ts +0 -1269
- package/src/db/index.ts +0 -47
- package/src/db/mongoMigrationExecution.ts +0 -23
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/releaseCatalog.ts +0 -148
- package/src/db/schema/definitions.ts +0 -1
- package/src/db/schema/insightsCollation.ts +0 -21
- package/src/db/schema/mongodb.ts +0 -40
- package/src/db/schema/registry.ts +0 -55
- package/src/db/schema/sql.ts +0 -244
- package/src/db/schema/sqlOperations.ts +0 -63
- package/src/db/schema/types.ts +0 -1
- package/src/db/schemaGenerators.ts +0 -494
- package/src/db/schemaReadiness.ts +0 -34
- package/src/db/sqlMigrationExecution.spec.ts +0 -65
- package/src/db/sqlMigrationExecution.ts +0 -108
- package/src/db/types.spec.ts +0 -63
- package/src/db/types.ts +0 -228
- package/src/db/updateArtifacts.spec.ts +0 -359
- package/src/db/updateArtifacts.ts +0 -541
- package/src/handler-standalone.integration.spec.ts +0 -528
- package/src/handler.spec.ts +0 -190
- package/src/handler.testFixtures.ts +0 -30
- package/src/handler.ts +0 -245
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerBundleRoutes.ts +0 -259
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -262
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -154
- package/src/handlerReleaseManagementRoutes.ts +0 -213
- package/src/handlerTypes.ts +0 -96
- package/src/handlerVersionRoutes.ts +0 -12
- package/src/index.ts +0 -30
- package/src/insights/domain.ts +0 -103
- package/src/insights/errors.ts +0 -11
- package/src/insights/eventInput.ts +0 -225
- package/src/insights/insights.integration.spec.ts +0 -381
- package/src/insights/provider.spec.ts +0 -385
- package/src/insights/provider.ts +0 -591
- package/src/insights/queryInput.ts +0 -141
- package/src/insights/routes.ts +0 -104
- package/src/insights/types.ts +0 -55
- package/src/internalRouter.ts +0 -104
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
- package/src/runtime.spec.ts +0 -194
- package/src/runtime.testFixtures.ts +0 -71
- package/src/schema/dsl-all-versions.spec.ts +0 -37
- package/src/schema/dsl.ts +0 -187
- package/src/schema/index.ts +0 -10
- package/src/schema/settings.ts +0 -15
- package/src/schema/types.ts +0 -79
- package/src/schema/v1_0_0.spec.ts +0 -220
- package/src/schema/v1_0_0.ts +0 -529
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/types/index.ts +0 -34
- package/src/version.ts +0 -3
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { HandlerBadRequestError } from "./handlerErrors.mjs";
|
|
2
|
+
import { decodeMaybe, isPlatform, parseBooleanSearchParam, requireRouteParam } from "./handlerParameters.mjs";
|
|
3
|
+
import { DatabaseBundleNotFoundError, DatabaseRowReferencedError, ReleaseCatalogMutationError, ReleaseManagementError } from "@hot-updater/plugin-core";
|
|
4
|
+
//#region src/handlerAdminRoutes.ts
|
|
5
|
+
const json = (body, status = 200) => Response.json(body, { status });
|
|
6
|
+
const notFound = () => json({ error: "Not found" }, 404);
|
|
7
|
+
const noContent = () => new Response(null, { status: 204 });
|
|
8
|
+
/** Runs `route` on core, answering its refusals. */
|
|
9
|
+
const onCore = (route) => async (params, request, api) => answer(() => route(api.core, request, params));
|
|
10
|
+
/** Core's refusals as HTTP answers; anything else is a server error. */
|
|
11
|
+
const answer = async (operation) => {
|
|
12
|
+
try {
|
|
13
|
+
return await operation();
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (error instanceof ReleaseManagementError || error instanceof ReleaseCatalogMutationError) {
|
|
16
|
+
const status = error.code === "RELEASE_NOT_FOUND" ? 404 : error.code === "VERSION_CONFLICT" ? 409 : 400;
|
|
17
|
+
return json({
|
|
18
|
+
code: error.code,
|
|
19
|
+
error: error.message
|
|
20
|
+
}, status);
|
|
21
|
+
}
|
|
22
|
+
if (error instanceof DatabaseBundleNotFoundError) return json({
|
|
23
|
+
code: "BUNDLE_NOT_FOUND",
|
|
24
|
+
error: error.message
|
|
25
|
+
}, 404);
|
|
26
|
+
if (error instanceof DatabaseRowReferencedError) return json({
|
|
27
|
+
code: "REFERENCED",
|
|
28
|
+
error: error.message
|
|
29
|
+
}, 409);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const LIMITS = {
|
|
34
|
+
defaultValue: 50,
|
|
35
|
+
maxValue: 500
|
|
36
|
+
};
|
|
37
|
+
/** `order`, `cursor`, and `limit`: one keyset page. */
|
|
38
|
+
const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
39
|
+
const order = url.searchParams.get("order") ?? "desc";
|
|
40
|
+
if (order !== "asc" && order !== "desc") throw new HandlerBadRequestError("order must be 'asc' or 'desc'.");
|
|
41
|
+
const limitParam = url.searchParams.get("limit");
|
|
42
|
+
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
43
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
44
|
+
const cursor = url.searchParams.get("cursor");
|
|
45
|
+
return {
|
|
46
|
+
order,
|
|
47
|
+
limit,
|
|
48
|
+
...cursor === null ? {} : { after: cursor }
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** A page and the cursor of the next one, when the page is full. */
|
|
52
|
+
const page = (rows, { limit }, keyOf, extra = {}) => json({
|
|
53
|
+
data: rows,
|
|
54
|
+
...rows.length === limit && rows.length > 0 ? { next: keyOf(rows.at(-1)) } : {},
|
|
55
|
+
...extra
|
|
56
|
+
});
|
|
57
|
+
const platformOf = (url) => {
|
|
58
|
+
const platform = url.searchParams.get("platform");
|
|
59
|
+
if (platform === null) return void 0;
|
|
60
|
+
if (!isPlatform(platform)) throw new HandlerBadRequestError(`Invalid platform: ${platform}. Expected 'ios' or 'android'.`);
|
|
61
|
+
return platform;
|
|
62
|
+
};
|
|
63
|
+
/** The one filter set a release list names; any other mix of filters is refused. */
|
|
64
|
+
const releaseFilter = (url) => {
|
|
65
|
+
const params = url.searchParams;
|
|
66
|
+
const named = [
|
|
67
|
+
"channelId",
|
|
68
|
+
"platform",
|
|
69
|
+
"bundleId",
|
|
70
|
+
"scopeKey"
|
|
71
|
+
].filter((name) => params.has(name));
|
|
72
|
+
const enabled = parseBooleanSearchParam(url, "enabled");
|
|
73
|
+
const withEnabled = enabled === void 0 ? {} : { enabled };
|
|
74
|
+
const set = named.join(",");
|
|
75
|
+
if (set === "" && enabled === void 0) return { kind: "all" };
|
|
76
|
+
if (set === "channelId,platform") {
|
|
77
|
+
const platform = platformOf(url);
|
|
78
|
+
return {
|
|
79
|
+
kind: "channelPlatform",
|
|
80
|
+
channelId: params.get("channelId"),
|
|
81
|
+
platform,
|
|
82
|
+
...withEnabled
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (set === "bundleId" && enabled === void 0) return {
|
|
86
|
+
kind: "bundle",
|
|
87
|
+
bundleId: params.get("bundleId")
|
|
88
|
+
};
|
|
89
|
+
if (set === "scopeKey") return {
|
|
90
|
+
kind: "scope",
|
|
91
|
+
scopeKey: params.get("scopeKey"),
|
|
92
|
+
...withEnabled
|
|
93
|
+
};
|
|
94
|
+
throw new HandlerBadRequestError("Releases filter by none, channelId and platform (with enabled), bundleId, or scopeKey (with enabled).");
|
|
95
|
+
};
|
|
96
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
97
|
+
const body = async (request) => {
|
|
98
|
+
const value = await request.json();
|
|
99
|
+
if (!isRecord(value)) throw new HandlerBadRequestError("Invalid body");
|
|
100
|
+
return value;
|
|
101
|
+
};
|
|
102
|
+
const isText = (value) => typeof value === "string" && value.length > 0;
|
|
103
|
+
const isTextOrNull = (value) => value === null || isText(value);
|
|
104
|
+
const isBundle = (bundle) => isRecord(bundle) && isText(bundle.id) && typeof bundle.platform === "string" && isPlatform(bundle.platform) && isTextOrNull(bundle.gitCommitHash) && isText(bundle.manifestStorageUri) && isText(bundle.manifestFileHash) && isText(bundle.assetBaseStorageUri) && (bundle.metadata === void 0 || isRecord(bundle.metadata)) && (bundle.patches === void 0 || bundle.patches === null || Array.isArray(bundle.patches));
|
|
105
|
+
const isReleasePolicy = (release) => isRecord(release) && isText(release.channel) && typeof release.enabled === "boolean" && typeof release.shouldForceUpdate === "boolean" && isTextOrNull(release.fingerprintHash) && isTextOrNull(release.targetAppVersion) && (release.message === null || typeof release.message === "string") && (release.rolloutCohortCount === void 0 || Number.isSafeInteger(release.rolloutCohortCount) && release.rolloutCohortCount >= 0 && release.rolloutCohortCount <= 1e3) && (release.targetCohorts === void 0 || Array.isArray(release.targetCohorts) && release.targetCohorts.every(isText));
|
|
106
|
+
/** A deployment's shape: a new bundle or a stored bundle's id, and its release policy. */
|
|
107
|
+
const isDeployment = (value) => isRecord(value) && isReleasePolicy(value.release) && ("bundleId" in value ? isText(value.bundleId) && !("bundle" in value) : isBundle(value.bundle));
|
|
108
|
+
/** An expected release revision from a body number or a query string. */
|
|
109
|
+
const revisionOf = (value) => {
|
|
110
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
111
|
+
const revision = typeof value === "string" ? Number(value) : value;
|
|
112
|
+
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 1) throw new HandlerBadRequestError("Invalid expected Release revision");
|
|
113
|
+
return revision;
|
|
114
|
+
};
|
|
115
|
+
/** A policy change's body: `{ expectedRevision?, patch }`. */
|
|
116
|
+
const policyInput = async (request) => {
|
|
117
|
+
const input = await body(request);
|
|
118
|
+
if (!isRecord(input.patch)) throw new HandlerBadRequestError("Invalid Release policy mutation");
|
|
119
|
+
const expectedRevision = revisionOf(input.expectedRevision);
|
|
120
|
+
return {
|
|
121
|
+
patch: input.patch,
|
|
122
|
+
...expectedRevision === void 0 ? {} : { expectedRevision }
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/** A bundle update's body: the fields it changes, never another bundle's id. */
|
|
126
|
+
const bundleUpdateOf = (value, bundleId) => {
|
|
127
|
+
if (!isRecord(value)) throw new HandlerBadRequestError("Invalid bundle payload");
|
|
128
|
+
const { id, ...update } = value;
|
|
129
|
+
if (id !== void 0 && id !== bundleId) throw new HandlerBadRequestError("Bundle id mismatch");
|
|
130
|
+
return update;
|
|
131
|
+
};
|
|
132
|
+
const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
|
|
133
|
+
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
134
|
+
const createAdminRouteHandlers = () => ({
|
|
135
|
+
listBundles: onCore(async (core, request) => {
|
|
136
|
+
const url = new URL(request.url);
|
|
137
|
+
const input = keyset(url, 100);
|
|
138
|
+
const platform = platformOf(url);
|
|
139
|
+
const withTotal = parseBooleanSearchParam(url, "total") === true;
|
|
140
|
+
const [rows, total] = await Promise.all([core.listBundles({
|
|
141
|
+
...input,
|
|
142
|
+
...platform ? { platform } : {}
|
|
143
|
+
}), withTotal ? core.countBundles(platform) : void 0]);
|
|
144
|
+
return page(rows, input, (row) => row.bundle.id, total === void 0 ? {} : { total });
|
|
145
|
+
}),
|
|
146
|
+
getBundle: onCore(async (core, _request, params) => {
|
|
147
|
+
const detail = await core.getBundle(requireRouteParam(params, "id"));
|
|
148
|
+
return detail === null ? notFound() : json({ data: detail });
|
|
149
|
+
}),
|
|
150
|
+
listReleases: onCore(async (core, request) => {
|
|
151
|
+
const url = new URL(request.url);
|
|
152
|
+
const input = keyset(url);
|
|
153
|
+
const rows = await core.listReleases({
|
|
154
|
+
...input,
|
|
155
|
+
filter: releaseFilter(url)
|
|
156
|
+
});
|
|
157
|
+
return page(rows, input, (row) => row.id);
|
|
158
|
+
}),
|
|
159
|
+
listReleaseCatalogs: onCore(async (core, request) => {
|
|
160
|
+
const input = keyset(new URL(request.url));
|
|
161
|
+
const rows = await core.listReleaseCatalogs(input);
|
|
162
|
+
return page(rows, input, (row) => row.scope_key);
|
|
163
|
+
}),
|
|
164
|
+
/** With `name`, the one channel of that name: 1 read. */
|
|
165
|
+
getChannels: onCore(async (core, request) => {
|
|
166
|
+
const name = new URL(request.url).searchParams.get("name");
|
|
167
|
+
if (name === null) return json({ data: await core.listChannels() });
|
|
168
|
+
const channel = await core.findChannelByName(name);
|
|
169
|
+
return channel === null ? notFound() : json({ data: channel });
|
|
170
|
+
}),
|
|
171
|
+
/** The channel named in the body, created when missing. */
|
|
172
|
+
createChannel: onCore(async (core, request) => {
|
|
173
|
+
const { name } = await body(request);
|
|
174
|
+
if (typeof name !== "string" || name.trim().length === 0) throw new HandlerBadRequestError("Invalid channel name");
|
|
175
|
+
return json({ data: await core.ensureChannel(name) });
|
|
176
|
+
}),
|
|
177
|
+
/** 204 when deleted; 404 or 409 with the reason otherwise. */
|
|
178
|
+
deleteChannel: onCore(async (core, _request, params) => {
|
|
179
|
+
const result = await core.deleteChannel(decodeMaybe(requireRouteParam(params, "id")) ?? "");
|
|
180
|
+
if (result.deleted) return noContent();
|
|
181
|
+
return json({ data: result }, result.reason === "not_found" ? 404 : 409);
|
|
182
|
+
}),
|
|
183
|
+
getRelease: onCore(async (core, _request, params) => {
|
|
184
|
+
const row = await core.getRelease(requireRouteParam(params, "id"));
|
|
185
|
+
return row === null ? notFound() : json({ data: row });
|
|
186
|
+
}),
|
|
187
|
+
updateRelease: onCore(async (core, request, params) => json({ data: await core.updateReleasePolicy({
|
|
188
|
+
...await policyInput(request),
|
|
189
|
+
releaseId: requireRouteParam(params, "id")
|
|
190
|
+
}) })),
|
|
191
|
+
preflightRelease: onCore(async (core, request, params) => json({ data: await core.preflightReleasePolicy({
|
|
192
|
+
...await policyInput(request),
|
|
193
|
+
releaseId: requireRouteParam(params, "id")
|
|
194
|
+
}) })),
|
|
195
|
+
/** Hard deletion names the release twice: in the path and as `confirm`. */
|
|
196
|
+
deleteRelease: onCore(async (core, request, params) => {
|
|
197
|
+
const releaseId = requireRouteParam(params, "id");
|
|
198
|
+
const url = new URL(request.url);
|
|
199
|
+
if (url.searchParams.get("confirm") !== releaseId) throw new HandlerBadRequestError("Release hard deletion requires confirm=<release-id>");
|
|
200
|
+
const expectedRevision = revisionOf(url.searchParams.get("expectedRevision"));
|
|
201
|
+
return json({ data: await core.deleteRelease({
|
|
202
|
+
releaseId,
|
|
203
|
+
...expectedRevision === void 0 ? {} : { expectedRevision }
|
|
204
|
+
}) });
|
|
205
|
+
}),
|
|
206
|
+
getReleaseCatalogRow: onCore(async (core, _request, params) => {
|
|
207
|
+
const row = await core.getReleaseCatalogRow(scopeKeyOf(params));
|
|
208
|
+
return row === null ? notFound() : json({ data: row });
|
|
209
|
+
}),
|
|
210
|
+
rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
211
|
+
updateBundle: onCore(async (core, request, params) => {
|
|
212
|
+
const bundleId = requireRouteParam(params, "id");
|
|
213
|
+
await core.updateBundle(bundleId, bundleUpdateOf(await request.json(), bundleId));
|
|
214
|
+
return noContent();
|
|
215
|
+
}),
|
|
216
|
+
countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
217
|
+
countBundleChildren: onCore(async (core, request) => {
|
|
218
|
+
const ids = (new URL(request.url).searchParams.get("ids") ?? "").split(",").filter((id) => id.length > 0);
|
|
219
|
+
if (ids.length === 0 || ids.length > 100) throw new HandlerBadRequestError("Bundle child counts take ids=<bundle id>,... with 1 to 100 ids.");
|
|
220
|
+
return json({ data: await core.countBundleChildren(ids) });
|
|
221
|
+
}),
|
|
222
|
+
listBundleChildren: onCore(async (core, request, params) => {
|
|
223
|
+
const input = keyset(new URL(request.url));
|
|
224
|
+
const rows = await core.listPatchesFromBase(requireRouteParam(params, "id"), input);
|
|
225
|
+
return page(rows, input, (row) => row.bundle_id);
|
|
226
|
+
}),
|
|
227
|
+
findBaseCandidates: onCore(async (core, request, params) => {
|
|
228
|
+
const url = new URL(request.url);
|
|
229
|
+
const before = url.searchParams.get("before");
|
|
230
|
+
const limit = Number(url.searchParams.get("limit") ?? "3");
|
|
231
|
+
if (before === null || !Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new HandlerBadRequestError("Base candidates need before=<bundle id> and a limit between 1 and 100.");
|
|
232
|
+
return json({ data: await core.findBaseBundleIds(decodeMaybe(requireRouteParam(params, "candidateKey")) ?? "", before, limit) });
|
|
233
|
+
}),
|
|
234
|
+
deployReleases: onCore(async (core, request) => {
|
|
235
|
+
const { deployments } = await body(request);
|
|
236
|
+
if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
|
|
237
|
+
return json({ data: await core.deploy(deployments) }, 201);
|
|
238
|
+
}),
|
|
239
|
+
promoteRelease: onCore(async (core, request, params) => {
|
|
240
|
+
const input = await body(request);
|
|
241
|
+
if (typeof input.targetChannel !== "string" || input.action !== void 0 && input.action !== "copy" && input.action !== "move") throw new HandlerBadRequestError("Invalid Release promotion");
|
|
242
|
+
const expectedRevision = revisionOf(input.expectedRevision);
|
|
243
|
+
return json({ data: await core.promoteRelease({
|
|
244
|
+
releaseId: requireRouteParam(params, "id"),
|
|
245
|
+
targetChannel: input.targetChannel,
|
|
246
|
+
...input.action === void 0 ? {} : { action: input.action },
|
|
247
|
+
...expectedRevision === void 0 ? {} : { expectedRevision }
|
|
248
|
+
}) });
|
|
249
|
+
}),
|
|
250
|
+
preflightReleaseCatalogRebuild: onCore(async (core, _request, params) => json({ data: await core.preflightReleaseCatalogRebuild(scopeKeyOf(params)) })),
|
|
251
|
+
deleteBundles: onCore(async (core, request) => {
|
|
252
|
+
const { ids } = await body(request);
|
|
253
|
+
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
|
|
254
|
+
await core.deleteBundles(ids);
|
|
255
|
+
return noContent();
|
|
256
|
+
})
|
|
257
|
+
});
|
|
258
|
+
/** The admin mount's routes, by the handler that serves each. */
|
|
259
|
+
const ADMIN_ROUTES = [
|
|
260
|
+
{
|
|
261
|
+
method: "POST",
|
|
262
|
+
path: "/releases",
|
|
263
|
+
handler: "deployReleases"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
method: "POST",
|
|
267
|
+
path: "/releases/:id/promote",
|
|
268
|
+
handler: "promoteRelease"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
method: "GET",
|
|
272
|
+
path: "/releases/:id",
|
|
273
|
+
handler: "getRelease"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
method: "GET",
|
|
277
|
+
path: "/releases",
|
|
278
|
+
handler: "listReleases"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
method: "PATCH",
|
|
282
|
+
path: "/releases/:id",
|
|
283
|
+
handler: "updateRelease"
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
method: "POST",
|
|
287
|
+
path: "/releases/:id/preflight",
|
|
288
|
+
handler: "preflightRelease"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
method: "DELETE",
|
|
292
|
+
path: "/releases/:id",
|
|
293
|
+
handler: "deleteRelease"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
method: "GET",
|
|
297
|
+
path: "/release-catalogs/:scopeKey",
|
|
298
|
+
handler: "getReleaseCatalogRow"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
method: "GET",
|
|
302
|
+
path: "/release-catalogs",
|
|
303
|
+
handler: "listReleaseCatalogs"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
method: "POST",
|
|
307
|
+
path: "/release-catalogs/:scopeKey/rebuild",
|
|
308
|
+
handler: "rebuildReleaseCatalog"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
method: "POST",
|
|
312
|
+
path: "/release-catalogs/:scopeKey/preflight",
|
|
313
|
+
handler: "preflightReleaseCatalogRebuild"
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
method: "GET",
|
|
317
|
+
path: "/channels",
|
|
318
|
+
handler: "getChannels"
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
method: "POST",
|
|
322
|
+
path: "/channels",
|
|
323
|
+
handler: "createChannel"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
method: "DELETE",
|
|
327
|
+
path: "/channels/:id",
|
|
328
|
+
handler: "deleteChannel"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
method: "GET",
|
|
332
|
+
path: "/bundles/count",
|
|
333
|
+
handler: "countBundles"
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
method: "GET",
|
|
337
|
+
path: "/bundles/child-counts",
|
|
338
|
+
handler: "countBundleChildren"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
method: "GET",
|
|
342
|
+
path: "/bundles/:id",
|
|
343
|
+
handler: "getBundle"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
method: "GET",
|
|
347
|
+
path: "/bundles",
|
|
348
|
+
handler: "listBundles"
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
method: "PATCH",
|
|
352
|
+
path: "/bundles/:id",
|
|
353
|
+
handler: "updateBundle"
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
method: "POST",
|
|
357
|
+
path: "/bundles/delete",
|
|
358
|
+
handler: "deleteBundles"
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
method: "GET",
|
|
362
|
+
path: "/bundles/:id/children",
|
|
363
|
+
handler: "listBundleChildren"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
method: "GET",
|
|
367
|
+
path: "/base-candidates/:candidateKey",
|
|
368
|
+
handler: "findBaseCandidates"
|
|
369
|
+
}
|
|
370
|
+
];
|
|
371
|
+
//#endregion
|
|
372
|
+
export { ADMIN_ROUTES, answer, createAdminRouteHandlers };
|
|
@@ -19,21 +19,16 @@ const requirePlatformParam = (params) => {
|
|
|
19
19
|
if (!isPlatform(platform)) throw new require_handlerErrors.HandlerBadRequestError(`Invalid platform: ${platform}. Expected 'ios' or 'android'.`);
|
|
20
20
|
return platform;
|
|
21
21
|
};
|
|
22
|
-
const
|
|
23
|
-
const values = url.searchParams.getAll(key);
|
|
24
|
-
return values.length > 0 ? values : void 0;
|
|
25
|
-
};
|
|
26
|
-
const parsePositiveIntegerSearchParam = (url, key, bounds) => {
|
|
22
|
+
const parseBooleanSearchParam = (url, key) => {
|
|
27
23
|
const value = url.searchParams.get(key);
|
|
28
|
-
if (value === null) return
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
24
|
+
if (value === null) return void 0;
|
|
25
|
+
if (value === "true") return true;
|
|
26
|
+
if (value === "false") return false;
|
|
27
|
+
throw new require_handlerErrors.HandlerBadRequestError(`The '${key}' query parameter must be 'true' or 'false'.`);
|
|
32
28
|
};
|
|
33
29
|
//#endregion
|
|
34
30
|
exports.decodeMaybe = decodeMaybe;
|
|
35
31
|
exports.isPlatform = isPlatform;
|
|
36
|
-
exports.
|
|
37
|
-
exports.parseStringArraySearchParam = parseStringArraySearchParam;
|
|
32
|
+
exports.parseBooleanSearchParam = parseBooleanSearchParam;
|
|
38
33
|
exports.requirePlatformParam = requirePlatformParam;
|
|
39
34
|
exports.requireRouteParam = requireRouteParam;
|
|
@@ -19,16 +19,12 @@ const requirePlatformParam = (params) => {
|
|
|
19
19
|
if (!isPlatform(platform)) throw new HandlerBadRequestError(`Invalid platform: ${platform}. Expected 'ios' or 'android'.`);
|
|
20
20
|
return platform;
|
|
21
21
|
};
|
|
22
|
-
const
|
|
23
|
-
const values = url.searchParams.getAll(key);
|
|
24
|
-
return values.length > 0 ? values : void 0;
|
|
25
|
-
};
|
|
26
|
-
const parsePositiveIntegerSearchParam = (url, key, bounds) => {
|
|
22
|
+
const parseBooleanSearchParam = (url, key) => {
|
|
27
23
|
const value = url.searchParams.get(key);
|
|
28
|
-
if (value === null) return
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
24
|
+
if (value === null) return void 0;
|
|
25
|
+
if (value === "true") return true;
|
|
26
|
+
if (value === "false") return false;
|
|
27
|
+
throw new HandlerBadRequestError(`The '${key}' query parameter must be 'true' or 'false'.`);
|
|
32
28
|
};
|
|
33
29
|
//#endregion
|
|
34
|
-
export { decodeMaybe, isPlatform,
|
|
30
|
+
export { decodeMaybe, isPlatform, parseBooleanSearchParam, requirePlatformParam, requireRouteParam };
|
|
@@ -2,25 +2,45 @@ const require_handlerParameters = require("./handlerParameters.cjs");
|
|
|
2
2
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
3
|
//#region src/handlerReleaseCatalogRoutes.ts
|
|
4
4
|
const CATALOG_CONTENT_TYPE = "application/vnd.hot-updater.release-catalog+json; version=1";
|
|
5
|
+
const ARTIFACT_CONTENT_TYPE = "application/vnd.hot-updater.artifact+json; version=1";
|
|
5
6
|
const ORIGIN_CACHE_TTL_MS = 5e3;
|
|
6
7
|
const ORIGIN_CACHE_MAX_ENTRIES = 128;
|
|
8
|
+
/** Marks the 404 of a scope that has no catalog. */
|
|
9
|
+
const NO_CATALOG_HEADER = "x-hot-updater-catalog";
|
|
10
|
+
/** A shared cache keeps a catalog, or a scope's lack of one, five seconds. */
|
|
11
|
+
const CATALOG_CACHE_CONTROL = "public, max-age=0, s-maxage=5";
|
|
7
12
|
const privateNotFound = () => Response.json({ error: "Not found" }, {
|
|
8
13
|
status: 404,
|
|
9
14
|
headers: { "cache-control": "private, no-store" }
|
|
10
15
|
});
|
|
16
|
+
/**
|
|
17
|
+
* A scope with no catalog yet, such as a store version before its first
|
|
18
|
+
* OTA release: cached like a catalog, so its update checks don't all reach
|
|
19
|
+
* the origin, and it holds nothing an API key protects. The header tells it
|
|
20
|
+
* apart from a 404 for a wrong URL: clients read it as "no update", and
|
|
21
|
+
* doctor as a live catalog route.
|
|
22
|
+
*/
|
|
23
|
+
const missingCatalog = () => Response.json({ error: "Not found" }, {
|
|
24
|
+
status: 404,
|
|
25
|
+
headers: {
|
|
26
|
+
"cache-control": CATALOG_CACHE_CONTROL,
|
|
27
|
+
vary: "Accept-Encoding",
|
|
28
|
+
[NO_CATALOG_HEADER]: "none"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
11
31
|
const responseHash = async (body) => {
|
|
12
32
|
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body));
|
|
13
33
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
14
34
|
};
|
|
15
|
-
const catalogResponse = async (catalog, request
|
|
16
|
-
if (catalog === null) return
|
|
35
|
+
const catalogResponse = async (catalog, request) => {
|
|
36
|
+
if (catalog === null) return missingCatalog();
|
|
17
37
|
const body = JSON.stringify(catalog);
|
|
18
38
|
const etag = `"sha256:${await responseHash(body)}"`;
|
|
19
39
|
const headers = {
|
|
20
|
-
"cache-control":
|
|
40
|
+
"cache-control": CATALOG_CACHE_CONTROL,
|
|
21
41
|
"content-type": CATALOG_CONTENT_TYPE,
|
|
22
42
|
etag,
|
|
23
|
-
vary:
|
|
43
|
+
vary: "Accept-Encoding"
|
|
24
44
|
};
|
|
25
45
|
if (request.headers.get("if-none-match") === etag) return new Response(null, {
|
|
26
46
|
headers,
|
|
@@ -31,7 +51,7 @@ const catalogResponse = async (catalog, request, clientAccessHeaderName) => {
|
|
|
31
51
|
status: 200
|
|
32
52
|
});
|
|
33
53
|
};
|
|
34
|
-
const createReleaseCatalogRouteHandlers = (
|
|
54
|
+
const createReleaseCatalogRouteHandlers = () => {
|
|
35
55
|
const cache = /* @__PURE__ */ new Map();
|
|
36
56
|
const inFlight = /* @__PURE__ */ new Map();
|
|
37
57
|
const loadCatalog = async (key, load) => {
|
|
@@ -66,8 +86,7 @@ const createReleaseCatalogRouteHandlers = (clientAccessHeaderName = "x-api-key")
|
|
|
66
86
|
}
|
|
67
87
|
};
|
|
68
88
|
return {
|
|
69
|
-
appVersionReleaseCatalog: async (params, request,
|
|
70
|
-
if (api.getReleaseCatalog === void 0) return privateNotFound();
|
|
89
|
+
appVersionReleaseCatalog: async (params, request, { core }) => {
|
|
71
90
|
const rawAppVersion = require_handlerParameters.requireRouteParam(params, "appVersion");
|
|
72
91
|
const appVersion = (0, _hot_updater_plugin_core.canonicalizeAppVersion)(rawAppVersion);
|
|
73
92
|
if (appVersion === null || appVersion !== rawAppVersion) return Response.json({ error: "Invalid app version" }, {
|
|
@@ -80,27 +99,25 @@ const createReleaseCatalogRouteHandlers = (clientAccessHeaderName = "x-api-key")
|
|
|
80
99
|
platform: require_handlerParameters.requirePlatformParam(params),
|
|
81
100
|
strategy: "APP_VERSION"
|
|
82
101
|
};
|
|
83
|
-
return catalogResponse(await loadCatalog(`app-version:${JSON.stringify(input)}`, () =>
|
|
102
|
+
return catalogResponse(await loadCatalog(`app-version:${JSON.stringify(input)}`, () => core.getReleaseCatalog(input)), request);
|
|
84
103
|
},
|
|
85
|
-
fingerprintReleaseCatalog: async (params, request,
|
|
86
|
-
if (api.getReleaseCatalog === void 0) return privateNotFound();
|
|
104
|
+
fingerprintReleaseCatalog: async (params, request, { core }) => {
|
|
87
105
|
const input = {
|
|
88
106
|
channelKey: require_handlerParameters.requireRouteParam(params, "channelKey"),
|
|
89
107
|
fingerprintHash: require_handlerParameters.requireRouteParam(params, "fingerprintHash"),
|
|
90
108
|
platform: require_handlerParameters.requirePlatformParam(params),
|
|
91
109
|
strategy: "FINGERPRINT"
|
|
92
110
|
};
|
|
93
|
-
return catalogResponse(await loadCatalog(`fingerprint:${JSON.stringify(input)}`, () =>
|
|
111
|
+
return catalogResponse(await loadCatalog(`fingerprint:${JSON.stringify(input)}`, () => core.getReleaseCatalog(input)), request);
|
|
94
112
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const info = await api.getArtifactInfo(require_handlerParameters.requireRouteParam(params, "targetBundleId"), require_handlerParameters.requireRouteParam(params, "currentBundleId"));
|
|
113
|
+
artifactV1: async (params, _request, { core }) => {
|
|
114
|
+
const info = await core.getArtifactInfo(require_handlerParameters.requireRouteParam(params, "targetBundleId"), require_handlerParameters.requireRouteParam(params, "currentBundleId"), 1);
|
|
98
115
|
if (info === null) return privateNotFound();
|
|
99
116
|
return new Response(JSON.stringify(info), {
|
|
100
117
|
status: 200,
|
|
101
118
|
headers: {
|
|
102
119
|
"cache-control": "private, no-store",
|
|
103
|
-
"content-type":
|
|
120
|
+
"content-type": ARTIFACT_CONTENT_TYPE
|
|
104
121
|
}
|
|
105
122
|
});
|
|
106
123
|
}
|
|
@@ -2,25 +2,45 @@ import { requirePlatformParam, requireRouteParam } from "./handlerParameters.mjs
|
|
|
2
2
|
import { canonicalizeAppVersion } from "@hot-updater/plugin-core";
|
|
3
3
|
//#region src/handlerReleaseCatalogRoutes.ts
|
|
4
4
|
const CATALOG_CONTENT_TYPE = "application/vnd.hot-updater.release-catalog+json; version=1";
|
|
5
|
+
const ARTIFACT_CONTENT_TYPE = "application/vnd.hot-updater.artifact+json; version=1";
|
|
5
6
|
const ORIGIN_CACHE_TTL_MS = 5e3;
|
|
6
7
|
const ORIGIN_CACHE_MAX_ENTRIES = 128;
|
|
8
|
+
/** Marks the 404 of a scope that has no catalog. */
|
|
9
|
+
const NO_CATALOG_HEADER = "x-hot-updater-catalog";
|
|
10
|
+
/** A shared cache keeps a catalog, or a scope's lack of one, five seconds. */
|
|
11
|
+
const CATALOG_CACHE_CONTROL = "public, max-age=0, s-maxage=5";
|
|
7
12
|
const privateNotFound = () => Response.json({ error: "Not found" }, {
|
|
8
13
|
status: 404,
|
|
9
14
|
headers: { "cache-control": "private, no-store" }
|
|
10
15
|
});
|
|
16
|
+
/**
|
|
17
|
+
* A scope with no catalog yet, such as a store version before its first
|
|
18
|
+
* OTA release: cached like a catalog, so its update checks don't all reach
|
|
19
|
+
* the origin, and it holds nothing an API key protects. The header tells it
|
|
20
|
+
* apart from a 404 for a wrong URL: clients read it as "no update", and
|
|
21
|
+
* doctor as a live catalog route.
|
|
22
|
+
*/
|
|
23
|
+
const missingCatalog = () => Response.json({ error: "Not found" }, {
|
|
24
|
+
status: 404,
|
|
25
|
+
headers: {
|
|
26
|
+
"cache-control": CATALOG_CACHE_CONTROL,
|
|
27
|
+
vary: "Accept-Encoding",
|
|
28
|
+
[NO_CATALOG_HEADER]: "none"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
11
31
|
const responseHash = async (body) => {
|
|
12
32
|
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body));
|
|
13
33
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
14
34
|
};
|
|
15
|
-
const catalogResponse = async (catalog, request
|
|
16
|
-
if (catalog === null) return
|
|
35
|
+
const catalogResponse = async (catalog, request) => {
|
|
36
|
+
if (catalog === null) return missingCatalog();
|
|
17
37
|
const body = JSON.stringify(catalog);
|
|
18
38
|
const etag = `"sha256:${await responseHash(body)}"`;
|
|
19
39
|
const headers = {
|
|
20
|
-
"cache-control":
|
|
40
|
+
"cache-control": CATALOG_CACHE_CONTROL,
|
|
21
41
|
"content-type": CATALOG_CONTENT_TYPE,
|
|
22
42
|
etag,
|
|
23
|
-
vary:
|
|
43
|
+
vary: "Accept-Encoding"
|
|
24
44
|
};
|
|
25
45
|
if (request.headers.get("if-none-match") === etag) return new Response(null, {
|
|
26
46
|
headers,
|
|
@@ -31,7 +51,7 @@ const catalogResponse = async (catalog, request, clientAccessHeaderName) => {
|
|
|
31
51
|
status: 200
|
|
32
52
|
});
|
|
33
53
|
};
|
|
34
|
-
const createReleaseCatalogRouteHandlers = (
|
|
54
|
+
const createReleaseCatalogRouteHandlers = () => {
|
|
35
55
|
const cache = /* @__PURE__ */ new Map();
|
|
36
56
|
const inFlight = /* @__PURE__ */ new Map();
|
|
37
57
|
const loadCatalog = async (key, load) => {
|
|
@@ -66,8 +86,7 @@ const createReleaseCatalogRouteHandlers = (clientAccessHeaderName = "x-api-key")
|
|
|
66
86
|
}
|
|
67
87
|
};
|
|
68
88
|
return {
|
|
69
|
-
appVersionReleaseCatalog: async (params, request,
|
|
70
|
-
if (api.getReleaseCatalog === void 0) return privateNotFound();
|
|
89
|
+
appVersionReleaseCatalog: async (params, request, { core }) => {
|
|
71
90
|
const rawAppVersion = requireRouteParam(params, "appVersion");
|
|
72
91
|
const appVersion = canonicalizeAppVersion(rawAppVersion);
|
|
73
92
|
if (appVersion === null || appVersion !== rawAppVersion) return Response.json({ error: "Invalid app version" }, {
|
|
@@ -80,27 +99,25 @@ const createReleaseCatalogRouteHandlers = (clientAccessHeaderName = "x-api-key")
|
|
|
80
99
|
platform: requirePlatformParam(params),
|
|
81
100
|
strategy: "APP_VERSION"
|
|
82
101
|
};
|
|
83
|
-
return catalogResponse(await loadCatalog(`app-version:${JSON.stringify(input)}`, () =>
|
|
102
|
+
return catalogResponse(await loadCatalog(`app-version:${JSON.stringify(input)}`, () => core.getReleaseCatalog(input)), request);
|
|
84
103
|
},
|
|
85
|
-
fingerprintReleaseCatalog: async (params, request,
|
|
86
|
-
if (api.getReleaseCatalog === void 0) return privateNotFound();
|
|
104
|
+
fingerprintReleaseCatalog: async (params, request, { core }) => {
|
|
87
105
|
const input = {
|
|
88
106
|
channelKey: requireRouteParam(params, "channelKey"),
|
|
89
107
|
fingerprintHash: requireRouteParam(params, "fingerprintHash"),
|
|
90
108
|
platform: requirePlatformParam(params),
|
|
91
109
|
strategy: "FINGERPRINT"
|
|
92
110
|
};
|
|
93
|
-
return catalogResponse(await loadCatalog(`fingerprint:${JSON.stringify(input)}`, () =>
|
|
111
|
+
return catalogResponse(await loadCatalog(`fingerprint:${JSON.stringify(input)}`, () => core.getReleaseCatalog(input)), request);
|
|
94
112
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const info = await api.getArtifactInfo(requireRouteParam(params, "targetBundleId"), requireRouteParam(params, "currentBundleId"));
|
|
113
|
+
artifactV1: async (params, _request, { core }) => {
|
|
114
|
+
const info = await core.getArtifactInfo(requireRouteParam(params, "targetBundleId"), requireRouteParam(params, "currentBundleId"), 1);
|
|
98
115
|
if (info === null) return privateNotFound();
|
|
99
116
|
return new Response(JSON.stringify(info), {
|
|
100
117
|
status: 200,
|
|
101
118
|
headers: {
|
|
102
119
|
"cache-control": "private, no-store",
|
|
103
|
-
"content-type":
|
|
120
|
+
"content-type": ARTIFACT_CONTENT_TYPE
|
|
104
121
|
}
|
|
105
122
|
});
|
|
106
123
|
}
|