@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
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
2
|
-
let
|
|
2
|
+
let _hot_updater_protocol = require("@hot-updater/protocol");
|
|
3
3
|
//#region src/db/updateArtifacts.ts
|
|
4
4
|
const HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
5
5
|
const asByteSize = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
6
|
-
const sumByteSizes = (byteSizes) => {
|
|
7
|
-
let total = 0;
|
|
8
|
-
for (const byteSize of byteSizes) {
|
|
9
|
-
if (byteSize === null || total > Number.MAX_SAFE_INTEGER - byteSize) return null;
|
|
10
|
-
total += byteSize;
|
|
11
|
-
}
|
|
12
|
-
return total;
|
|
13
|
-
};
|
|
14
|
-
const shouldUseArchive = (targetBundle, downloadByteSize) => {
|
|
15
|
-
const archiveByteSize = asByteSize(targetBundle.archiveByteSize);
|
|
16
|
-
return archiveByteSize !== null && downloadByteSize !== null && downloadByteSize >= archiveByteSize;
|
|
17
|
-
};
|
|
18
6
|
const resolveUniqueHbcAssetPath = (manifest) => {
|
|
19
7
|
const candidates = Object.keys(manifest.assets).sort((left, right) => left.localeCompare(right)).filter((candidate) => HBC_ASSET_PATH_RE.test(candidate));
|
|
20
8
|
return candidates.length === 1 ? candidates[0] : null;
|
|
@@ -40,13 +28,10 @@ async function fetchBundleManifest(storageUri, readStorageText) {
|
|
|
40
28
|
return null;
|
|
41
29
|
}
|
|
42
30
|
if (!isBundleManifest(payload)) return null;
|
|
43
|
-
return
|
|
44
|
-
byteSize: asByteSize(new TextEncoder().encode(storageText).byteLength),
|
|
45
|
-
manifest: payload
|
|
46
|
-
};
|
|
31
|
+
return payload;
|
|
47
32
|
}
|
|
48
33
|
function resolveHbcPatchPlan({ currentBundle, targetBundle, targetManifest }) {
|
|
49
|
-
const matchingPatch = currentBundle ? (0,
|
|
34
|
+
const matchingPatch = currentBundle ? (0, _hot_updater_protocol.getBundlePatch)(targetBundle, currentBundle.id) : null;
|
|
50
35
|
const patchAssetPath = resolveUniqueHbcAssetPath(targetManifest);
|
|
51
36
|
if (!currentBundle || !matchingPatch || !patchAssetPath || !matchingPatch.patchStorageUri || !matchingPatch.patchFileHash || !matchingPatch.baseFileHash) return null;
|
|
52
37
|
return {
|
|
@@ -60,14 +45,13 @@ function resolveHbcPatchPlan({ currentBundle, targetBundle, targetManifest }) {
|
|
|
60
45
|
}
|
|
61
46
|
};
|
|
62
47
|
}
|
|
63
|
-
function createManifestArtifactPlan({ assetBaseStorageUri,
|
|
48
|
+
function createManifestArtifactPlan({ assetBaseStorageUri, currentBundle, targetBundle, targetManifest }) {
|
|
64
49
|
const patchCandidate = resolveHbcPatchPlan({
|
|
65
50
|
currentBundle,
|
|
66
51
|
targetBundle,
|
|
67
52
|
targetManifest
|
|
68
53
|
});
|
|
69
|
-
|
|
70
|
-
if ((currentManifest?.assets[assetPath])?.fileHash === asset.fileHash) return [];
|
|
54
|
+
return { assets: Object.entries(targetManifest.assets).map(([assetPath, asset]) => {
|
|
71
55
|
const downloadByteSize = asByteSize(asset.downloadByteSize);
|
|
72
56
|
const downloadPath = (0, _hot_updater_plugin_core.getManifestAssetDownloadPath)(assetPath);
|
|
73
57
|
const isTransformedDownload = downloadPath !== assetPath;
|
|
@@ -83,28 +67,16 @@ function createManifestArtifactPlan({ assetBaseStorageUri, currentManifest, curr
|
|
|
83
67
|
};
|
|
84
68
|
if (isTransformedDownload) file.compression = "br";
|
|
85
69
|
const patch = patchCandidate?.assetPath === assetPath ? patchCandidate.patch : null;
|
|
86
|
-
return
|
|
70
|
+
return {
|
|
87
71
|
assetPath,
|
|
88
72
|
file,
|
|
89
73
|
fileHash: asset.fileHash,
|
|
90
74
|
patch
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
const allPossibleByteSizesKnown = targetManifestByteSize !== null && changedAssets.every((asset) => asset.file.byteSize !== null && (asset.patch === null || asset.patch.byteSize !== null));
|
|
94
|
-
const primaryByteSizes = changedAssets.map((asset) => {
|
|
95
|
-
if (!asset.patch) return asset.file.byteSize;
|
|
96
|
-
if (asset.patch.byteSize === null || asset.file.byteSize === null) return null;
|
|
97
|
-
return Math.min(asset.patch.byteSize, asset.file.byteSize);
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
allPossibleByteSizesKnown,
|
|
101
|
-
changedAssets,
|
|
102
|
-
manifestByteSize: targetManifestByteSize,
|
|
103
|
-
minimumDownloadByteSize: allPossibleByteSizesKnown ? sumByteSizes([targetManifestByteSize, ...primaryByteSizes]) : null
|
|
104
|
-
};
|
|
75
|
+
};
|
|
76
|
+
}) };
|
|
105
77
|
}
|
|
106
|
-
async function
|
|
107
|
-
const patchAsset = plan.
|
|
78
|
+
async function resolveAssets(plan, resolveFileUrl) {
|
|
79
|
+
const patchAsset = plan.assets.find((asset) => asset.patch !== null);
|
|
108
80
|
let resolvedPatch = null;
|
|
109
81
|
if (patchAsset?.patch) {
|
|
110
82
|
const patchUrl = await resolveFileUrl(patchAsset.patch.storageUri);
|
|
@@ -115,11 +87,12 @@ async function resolveChangedAssets(plan, resolveFileUrl) {
|
|
|
115
87
|
baseBundleId: patchAsset.patch.baseBundleId,
|
|
116
88
|
baseFileHash: patchAsset.patch.baseFileHash,
|
|
117
89
|
patchFileHash: patchAsset.patch.patchFileHash,
|
|
118
|
-
patchUrl
|
|
90
|
+
patchUrl,
|
|
91
|
+
...patchAsset.patch.byteSize === null ? {} : { byteSize: patchAsset.patch.byteSize }
|
|
119
92
|
}
|
|
120
93
|
};
|
|
121
94
|
}
|
|
122
|
-
const
|
|
95
|
+
const entries = await Promise.all(plan.assets.map(async (asset) => {
|
|
123
96
|
let patch = resolvedPatch?.assetPath === asset.assetPath ? resolvedPatch.patch : null;
|
|
124
97
|
let fileUrl = null;
|
|
125
98
|
try {
|
|
@@ -128,52 +101,50 @@ async function resolveChangedAssets(plan, resolveFileUrl) {
|
|
|
128
101
|
if (!patch) throw error;
|
|
129
102
|
}
|
|
130
103
|
if (fileUrl && patch && asset.file.byteSize !== null && asset.patch !== null && asset.patch.byteSize !== null && asset.patch.byteSize >= asset.file.byteSize) patch = null;
|
|
131
|
-
if (!fileUrl
|
|
132
|
-
const changedAsset = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (asset.file.compression) changedAsset.file.compression = asset.file.compression;
|
|
136
|
-
}
|
|
137
|
-
if (patch) changedAsset.patch = patch;
|
|
138
|
-
return {
|
|
139
|
-
asset: [asset.assetPath, changedAsset],
|
|
140
|
-
primaryByteSize: patch ? asset.patch?.byteSize ?? null : asset.file.byteSize
|
|
104
|
+
if (!fileUrl) return null;
|
|
105
|
+
const changedAsset = {
|
|
106
|
+
file: { url: fileUrl },
|
|
107
|
+
fileHash: asset.fileHash
|
|
141
108
|
};
|
|
109
|
+
if (asset.file.compression) changedAsset.file.compression = asset.file.compression;
|
|
110
|
+
if (patch) changedAsset.patch = patch;
|
|
111
|
+
return { asset: [asset.assetPath, changedAsset] };
|
|
142
112
|
}));
|
|
143
|
-
if (
|
|
144
|
-
const resolvedEntries =
|
|
145
|
-
return {
|
|
146
|
-
changedAssets: Object.fromEntries(resolvedEntries.map((entry) => entry.asset)),
|
|
147
|
-
primaryByteSizes: resolvedEntries.map((entry) => entry.primaryByteSize)
|
|
148
|
-
};
|
|
113
|
+
if (entries.some((entry) => entry === null)) return null;
|
|
114
|
+
const resolvedEntries = entries.filter((entry) => entry !== null);
|
|
115
|
+
return { assets: Object.fromEntries(resolvedEntries.map((entry) => entry.asset)) };
|
|
149
116
|
}
|
|
150
|
-
async function resolveManifestArtifacts({
|
|
151
|
-
const manifestStorageUri = targetBundle ? (0,
|
|
152
|
-
const manifestFileHash = targetBundle ? (0,
|
|
153
|
-
const assetBaseStorageUri = targetBundle ? (0,
|
|
117
|
+
async function resolveManifestArtifacts({ currentBundle, resolveFileUrl, readStorageText, targetBundle }) {
|
|
118
|
+
const manifestStorageUri = targetBundle ? (0, _hot_updater_protocol.getManifestStorageUri)(targetBundle) : null;
|
|
119
|
+
const manifestFileHash = targetBundle ? (0, _hot_updater_protocol.getManifestFileHash)(targetBundle) : null;
|
|
120
|
+
const assetBaseStorageUri = targetBundle ? (0, _hot_updater_protocol.getAssetBaseStorageUri)(targetBundle) : null;
|
|
154
121
|
if (!targetBundle || !manifestStorageUri || !manifestFileHash || !assetBaseStorageUri) return null;
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
if (!targetManifestResult) return null;
|
|
122
|
+
const targetManifest = await fetchBundleManifest(manifestStorageUri, readStorageText);
|
|
123
|
+
if (!targetManifest) return null;
|
|
158
124
|
const plan = createManifestArtifactPlan({
|
|
159
125
|
assetBaseStorageUri,
|
|
160
|
-
currentManifest: currentManifestResult?.manifest ?? null,
|
|
161
126
|
currentBundle,
|
|
162
127
|
targetBundle,
|
|
163
|
-
targetManifest
|
|
164
|
-
targetManifestByteSize: targetManifestResult.byteSize
|
|
128
|
+
targetManifest
|
|
165
129
|
});
|
|
166
|
-
if (archiveUrlUsable && plan.allPossibleByteSizesKnown && shouldUseArchive(targetBundle, plan.minimumDownloadByteSize)) return null;
|
|
167
130
|
const manifestUrl = await resolveFileUrl(manifestStorageUri);
|
|
168
131
|
if (!manifestUrl) return null;
|
|
169
|
-
const resolved = await
|
|
132
|
+
const resolved = await resolveAssets(plan, resolveFileUrl);
|
|
170
133
|
if (!resolved) return null;
|
|
171
|
-
|
|
172
|
-
|
|
134
|
+
let archiveUrl = null;
|
|
135
|
+
const archive = targetManifest.archive;
|
|
136
|
+
if (archive && (0, _hot_updater_plugin_core.isContentAddressedAssetFileHash)(archive.downloadFileHash) && (asByteSize(archive.downloadByteSize) ?? 0) > 0 && (asByteSize(archive.tarByteSize) ?? 0) > 0) try {
|
|
137
|
+
archiveUrl = await resolveFileUrl((0, _hot_updater_plugin_core.getBundleArchiveStorageUri)({
|
|
138
|
+
manifestStorageUri,
|
|
139
|
+
bundleId: targetBundle.id
|
|
140
|
+
}));
|
|
141
|
+
} catch {}
|
|
173
142
|
return {
|
|
174
|
-
|
|
143
|
+
artifactProtocolVersion: _hot_updater_protocol.ARTIFACT_PROTOCOL_VERSION,
|
|
144
|
+
assets: resolved.assets,
|
|
175
145
|
manifestFileHash,
|
|
176
|
-
manifestUrl
|
|
146
|
+
manifestUrl,
|
|
147
|
+
...archiveUrl ? { archiveUrl } : {}
|
|
177
148
|
};
|
|
178
149
|
}
|
|
179
150
|
//#endregion
|
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import { getManifestAssetDownloadPath, isContentAddressedAssetFileHash, resolveManifestAssetStorageUri } from "@hot-updater/plugin-core";
|
|
2
|
-
import { getAssetBaseStorageUri, getBundlePatch, getManifestFileHash, getManifestStorageUri } from "@hot-updater/
|
|
1
|
+
import { getBundleArchiveStorageUri, getManifestAssetDownloadPath, isContentAddressedAssetFileHash, resolveManifestAssetStorageUri } from "@hot-updater/plugin-core";
|
|
2
|
+
import { ARTIFACT_PROTOCOL_VERSION, getAssetBaseStorageUri, getBundlePatch, getManifestFileHash, getManifestStorageUri } from "@hot-updater/protocol";
|
|
3
3
|
//#region src/db/updateArtifacts.ts
|
|
4
4
|
const HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
5
5
|
const asByteSize = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
6
|
-
const sumByteSizes = (byteSizes) => {
|
|
7
|
-
let total = 0;
|
|
8
|
-
for (const byteSize of byteSizes) {
|
|
9
|
-
if (byteSize === null || total > Number.MAX_SAFE_INTEGER - byteSize) return null;
|
|
10
|
-
total += byteSize;
|
|
11
|
-
}
|
|
12
|
-
return total;
|
|
13
|
-
};
|
|
14
|
-
const shouldUseArchive = (targetBundle, downloadByteSize) => {
|
|
15
|
-
const archiveByteSize = asByteSize(targetBundle.archiveByteSize);
|
|
16
|
-
return archiveByteSize !== null && downloadByteSize !== null && downloadByteSize >= archiveByteSize;
|
|
17
|
-
};
|
|
18
6
|
const resolveUniqueHbcAssetPath = (manifest) => {
|
|
19
7
|
const candidates = Object.keys(manifest.assets).sort((left, right) => left.localeCompare(right)).filter((candidate) => HBC_ASSET_PATH_RE.test(candidate));
|
|
20
8
|
return candidates.length === 1 ? candidates[0] : null;
|
|
@@ -40,10 +28,7 @@ async function fetchBundleManifest(storageUri, readStorageText) {
|
|
|
40
28
|
return null;
|
|
41
29
|
}
|
|
42
30
|
if (!isBundleManifest(payload)) return null;
|
|
43
|
-
return
|
|
44
|
-
byteSize: asByteSize(new TextEncoder().encode(storageText).byteLength),
|
|
45
|
-
manifest: payload
|
|
46
|
-
};
|
|
31
|
+
return payload;
|
|
47
32
|
}
|
|
48
33
|
function resolveHbcPatchPlan({ currentBundle, targetBundle, targetManifest }) {
|
|
49
34
|
const matchingPatch = currentBundle ? getBundlePatch(targetBundle, currentBundle.id) : null;
|
|
@@ -60,14 +45,13 @@ function resolveHbcPatchPlan({ currentBundle, targetBundle, targetManifest }) {
|
|
|
60
45
|
}
|
|
61
46
|
};
|
|
62
47
|
}
|
|
63
|
-
function createManifestArtifactPlan({ assetBaseStorageUri,
|
|
48
|
+
function createManifestArtifactPlan({ assetBaseStorageUri, currentBundle, targetBundle, targetManifest }) {
|
|
64
49
|
const patchCandidate = resolveHbcPatchPlan({
|
|
65
50
|
currentBundle,
|
|
66
51
|
targetBundle,
|
|
67
52
|
targetManifest
|
|
68
53
|
});
|
|
69
|
-
|
|
70
|
-
if ((currentManifest?.assets[assetPath])?.fileHash === asset.fileHash) return [];
|
|
54
|
+
return { assets: Object.entries(targetManifest.assets).map(([assetPath, asset]) => {
|
|
71
55
|
const downloadByteSize = asByteSize(asset.downloadByteSize);
|
|
72
56
|
const downloadPath = getManifestAssetDownloadPath(assetPath);
|
|
73
57
|
const isTransformedDownload = downloadPath !== assetPath;
|
|
@@ -83,28 +67,16 @@ function createManifestArtifactPlan({ assetBaseStorageUri, currentManifest, curr
|
|
|
83
67
|
};
|
|
84
68
|
if (isTransformedDownload) file.compression = "br";
|
|
85
69
|
const patch = patchCandidate?.assetPath === assetPath ? patchCandidate.patch : null;
|
|
86
|
-
return
|
|
70
|
+
return {
|
|
87
71
|
assetPath,
|
|
88
72
|
file,
|
|
89
73
|
fileHash: asset.fileHash,
|
|
90
74
|
patch
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
const allPossibleByteSizesKnown = targetManifestByteSize !== null && changedAssets.every((asset) => asset.file.byteSize !== null && (asset.patch === null || asset.patch.byteSize !== null));
|
|
94
|
-
const primaryByteSizes = changedAssets.map((asset) => {
|
|
95
|
-
if (!asset.patch) return asset.file.byteSize;
|
|
96
|
-
if (asset.patch.byteSize === null || asset.file.byteSize === null) return null;
|
|
97
|
-
return Math.min(asset.patch.byteSize, asset.file.byteSize);
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
allPossibleByteSizesKnown,
|
|
101
|
-
changedAssets,
|
|
102
|
-
manifestByteSize: targetManifestByteSize,
|
|
103
|
-
minimumDownloadByteSize: allPossibleByteSizesKnown ? sumByteSizes([targetManifestByteSize, ...primaryByteSizes]) : null
|
|
104
|
-
};
|
|
75
|
+
};
|
|
76
|
+
}) };
|
|
105
77
|
}
|
|
106
|
-
async function
|
|
107
|
-
const patchAsset = plan.
|
|
78
|
+
async function resolveAssets(plan, resolveFileUrl) {
|
|
79
|
+
const patchAsset = plan.assets.find((asset) => asset.patch !== null);
|
|
108
80
|
let resolvedPatch = null;
|
|
109
81
|
if (patchAsset?.patch) {
|
|
110
82
|
const patchUrl = await resolveFileUrl(patchAsset.patch.storageUri);
|
|
@@ -115,11 +87,12 @@ async function resolveChangedAssets(plan, resolveFileUrl) {
|
|
|
115
87
|
baseBundleId: patchAsset.patch.baseBundleId,
|
|
116
88
|
baseFileHash: patchAsset.patch.baseFileHash,
|
|
117
89
|
patchFileHash: patchAsset.patch.patchFileHash,
|
|
118
|
-
patchUrl
|
|
90
|
+
patchUrl,
|
|
91
|
+
...patchAsset.patch.byteSize === null ? {} : { byteSize: patchAsset.patch.byteSize }
|
|
119
92
|
}
|
|
120
93
|
};
|
|
121
94
|
}
|
|
122
|
-
const
|
|
95
|
+
const entries = await Promise.all(plan.assets.map(async (asset) => {
|
|
123
96
|
let patch = resolvedPatch?.assetPath === asset.assetPath ? resolvedPatch.patch : null;
|
|
124
97
|
let fileUrl = null;
|
|
125
98
|
try {
|
|
@@ -128,52 +101,50 @@ async function resolveChangedAssets(plan, resolveFileUrl) {
|
|
|
128
101
|
if (!patch) throw error;
|
|
129
102
|
}
|
|
130
103
|
if (fileUrl && patch && asset.file.byteSize !== null && asset.patch !== null && asset.patch.byteSize !== null && asset.patch.byteSize >= asset.file.byteSize) patch = null;
|
|
131
|
-
if (!fileUrl
|
|
132
|
-
const changedAsset = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (asset.file.compression) changedAsset.file.compression = asset.file.compression;
|
|
136
|
-
}
|
|
137
|
-
if (patch) changedAsset.patch = patch;
|
|
138
|
-
return {
|
|
139
|
-
asset: [asset.assetPath, changedAsset],
|
|
140
|
-
primaryByteSize: patch ? asset.patch?.byteSize ?? null : asset.file.byteSize
|
|
104
|
+
if (!fileUrl) return null;
|
|
105
|
+
const changedAsset = {
|
|
106
|
+
file: { url: fileUrl },
|
|
107
|
+
fileHash: asset.fileHash
|
|
141
108
|
};
|
|
109
|
+
if (asset.file.compression) changedAsset.file.compression = asset.file.compression;
|
|
110
|
+
if (patch) changedAsset.patch = patch;
|
|
111
|
+
return { asset: [asset.assetPath, changedAsset] };
|
|
142
112
|
}));
|
|
143
|
-
if (
|
|
144
|
-
const resolvedEntries =
|
|
145
|
-
return {
|
|
146
|
-
changedAssets: Object.fromEntries(resolvedEntries.map((entry) => entry.asset)),
|
|
147
|
-
primaryByteSizes: resolvedEntries.map((entry) => entry.primaryByteSize)
|
|
148
|
-
};
|
|
113
|
+
if (entries.some((entry) => entry === null)) return null;
|
|
114
|
+
const resolvedEntries = entries.filter((entry) => entry !== null);
|
|
115
|
+
return { assets: Object.fromEntries(resolvedEntries.map((entry) => entry.asset)) };
|
|
149
116
|
}
|
|
150
|
-
async function resolveManifestArtifacts({
|
|
117
|
+
async function resolveManifestArtifacts({ currentBundle, resolveFileUrl, readStorageText, targetBundle }) {
|
|
151
118
|
const manifestStorageUri = targetBundle ? getManifestStorageUri(targetBundle) : null;
|
|
152
119
|
const manifestFileHash = targetBundle ? getManifestFileHash(targetBundle) : null;
|
|
153
120
|
const assetBaseStorageUri = targetBundle ? getAssetBaseStorageUri(targetBundle) : null;
|
|
154
121
|
if (!targetBundle || !manifestStorageUri || !manifestFileHash || !assetBaseStorageUri) return null;
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
if (!targetManifestResult) return null;
|
|
122
|
+
const targetManifest = await fetchBundleManifest(manifestStorageUri, readStorageText);
|
|
123
|
+
if (!targetManifest) return null;
|
|
158
124
|
const plan = createManifestArtifactPlan({
|
|
159
125
|
assetBaseStorageUri,
|
|
160
|
-
currentManifest: currentManifestResult?.manifest ?? null,
|
|
161
126
|
currentBundle,
|
|
162
127
|
targetBundle,
|
|
163
|
-
targetManifest
|
|
164
|
-
targetManifestByteSize: targetManifestResult.byteSize
|
|
128
|
+
targetManifest
|
|
165
129
|
});
|
|
166
|
-
if (archiveUrlUsable && plan.allPossibleByteSizesKnown && shouldUseArchive(targetBundle, plan.minimumDownloadByteSize)) return null;
|
|
167
130
|
const manifestUrl = await resolveFileUrl(manifestStorageUri);
|
|
168
131
|
if (!manifestUrl) return null;
|
|
169
|
-
const resolved = await
|
|
132
|
+
const resolved = await resolveAssets(plan, resolveFileUrl);
|
|
170
133
|
if (!resolved) return null;
|
|
171
|
-
|
|
172
|
-
|
|
134
|
+
let archiveUrl = null;
|
|
135
|
+
const archive = targetManifest.archive;
|
|
136
|
+
if (archive && isContentAddressedAssetFileHash(archive.downloadFileHash) && (asByteSize(archive.downloadByteSize) ?? 0) > 0 && (asByteSize(archive.tarByteSize) ?? 0) > 0) try {
|
|
137
|
+
archiveUrl = await resolveFileUrl(getBundleArchiveStorageUri({
|
|
138
|
+
manifestStorageUri,
|
|
139
|
+
bundleId: targetBundle.id
|
|
140
|
+
}));
|
|
141
|
+
} catch {}
|
|
173
142
|
return {
|
|
174
|
-
|
|
143
|
+
artifactProtocolVersion: ARTIFACT_PROTOCOL_VERSION,
|
|
144
|
+
assets: resolved.assets,
|
|
175
145
|
manifestFileHash,
|
|
176
|
-
manifestUrl
|
|
146
|
+
manifestUrl,
|
|
147
|
+
...archiveUrl ? { archiveUrl } : {}
|
|
177
148
|
};
|
|
178
149
|
}
|
|
179
150
|
//#endregion
|
package/dist/handler.cjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const require_handlerErrors = require("./handlerErrors.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_handlerAdminRoutes = require("./handlerAdminRoutes.cjs");
|
|
3
3
|
const require_handlerReleaseCatalogRoutes = require("./handlerReleaseCatalogRoutes.cjs");
|
|
4
|
-
const require_handlerReleaseManagementRoutes = require("./handlerReleaseManagementRoutes.cjs");
|
|
5
4
|
const require_handlerVersionRoutes = require("./handlerVersionRoutes.cjs");
|
|
6
|
-
const require_routes = require("./insights/routes.cjs");
|
|
7
5
|
const require_internalRouter = require("./internalRouter.cjs");
|
|
6
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
8
7
|
//#region src/handler.ts
|
|
9
8
|
const withPrivateNoStore = (response) => {
|
|
10
9
|
const headers = new Headers(response.headers);
|
|
@@ -19,15 +18,29 @@ const errorResponse = (error, status) => Response.json({ error }, {
|
|
|
19
18
|
headers: { "cache-control": "private, no-store" },
|
|
20
19
|
status
|
|
21
20
|
});
|
|
22
|
-
|
|
23
|
-
const
|
|
21
|
+
/** `/version` and storage downloads never pass through the client policy. */
|
|
22
|
+
const PUBLIC_CLIENT_ROUTES = /* @__PURE__ */ new Set(["version", "downloadStorageObject"]);
|
|
23
|
+
const routesOf = Symbol.for("@hot-updater/server/routes");
|
|
24
|
+
const withVary = (response, varyHeaders) => {
|
|
25
|
+
const cacheControl = response.headers.get("cache-control") ?? "";
|
|
26
|
+
if (varyHeaders.length === 0 || cacheControl === "" || /private|no-store/u.test(cacheControl)) return response;
|
|
27
|
+
const headers = new Headers(response.headers);
|
|
28
|
+
headers.set("vary", [response.headers.get("vary"), ...varyHeaders].filter(Boolean).join(", "));
|
|
29
|
+
return new Response(response.body, {
|
|
30
|
+
headers,
|
|
31
|
+
status: response.status,
|
|
32
|
+
statusText: response.statusText
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const createRequestHandler = ({ api, clientPolicy, privateResponses = false, routeHandlers, router }) => async (request) => {
|
|
24
36
|
try {
|
|
25
37
|
const match = require_internalRouter.findRoute(router, request.method, new URL(request.url).pathname);
|
|
26
38
|
if (!match) return errorResponse("Not found", 404);
|
|
27
|
-
|
|
39
|
+
const guarded = clientPolicy !== void 0 && !PUBLIC_CLIENT_ROUTES.has(match.data);
|
|
40
|
+
if (guarded) {
|
|
28
41
|
let authenticated;
|
|
29
42
|
try {
|
|
30
|
-
authenticated = await
|
|
43
|
+
authenticated = await clientPolicy.authenticate(request);
|
|
31
44
|
} catch {
|
|
32
45
|
return errorResponse("Service unavailable", 503);
|
|
33
46
|
}
|
|
@@ -36,9 +49,14 @@ const createRequestHandler = ({ api, apiKeyAuth, privateResponses = false, route
|
|
|
36
49
|
const handler = routeHandlers[match.data];
|
|
37
50
|
if (!handler) return errorResponse("Handler not found", 500);
|
|
38
51
|
const response = await handler(match.params, request, api);
|
|
39
|
-
|
|
52
|
+
if (privateResponses) return withPrivateNoStore(response);
|
|
53
|
+
return guarded ? withVary(response, clientPolicy.varyHeaders) : response;
|
|
40
54
|
} catch (error) {
|
|
41
55
|
if (error instanceof require_handlerErrors.HandlerBadRequestError) return errorResponse(error.message, 400);
|
|
56
|
+
if (error instanceof _hot_updater_plugin_core.HotUpdaterSchemaMigrationRequiredError) {
|
|
57
|
+
console.error(error.message);
|
|
58
|
+
return errorResponse("Service unavailable", 503);
|
|
59
|
+
}
|
|
42
60
|
console.error("Hot Updater handler error:", error);
|
|
43
61
|
return Response.json({ error: "Internal server error" }, {
|
|
44
62
|
headers: { "cache-control": "private, no-store" },
|
|
@@ -60,50 +78,47 @@ const createDownloadStorageRouteHandler = (downloadStorageObject) => async (para
|
|
|
60
78
|
statusText: response.statusText
|
|
61
79
|
});
|
|
62
80
|
};
|
|
63
|
-
function
|
|
64
|
-
return createHotUpdaterHandlers(api);
|
|
65
|
-
}
|
|
66
|
-
function createHotUpdaterHandlers(api, insights, apiKeyAuth, downloadStorageObject) {
|
|
81
|
+
function createHotUpdaterHandlers({ api, clientPolicy, downloadStorageObject, endpoints = [], plugins = [] }) {
|
|
67
82
|
const routeHandlers = {
|
|
68
|
-
...require_handlerVersionRoutes.createVersionRouteHandlers(),
|
|
69
|
-
...require_handlerReleaseCatalogRoutes.createReleaseCatalogRouteHandlers(
|
|
70
|
-
...
|
|
71
|
-
...require_handlerBundleRoutes.createBundleRouteHandlers(),
|
|
72
|
-
...insights === void 0 ? {} : require_routes.createInsightsRouteHandlers(insights),
|
|
83
|
+
...require_handlerVersionRoutes.createVersionRouteHandlers(plugins),
|
|
84
|
+
...require_handlerReleaseCatalogRoutes.createReleaseCatalogRouteHandlers(),
|
|
85
|
+
...require_handlerAdminRoutes.createAdminRouteHandlers(),
|
|
73
86
|
...downloadStorageObject === void 0 ? {} : { downloadStorageObject: createDownloadStorageRouteHandler(downloadStorageObject) }
|
|
74
87
|
};
|
|
88
|
+
const routes = [];
|
|
89
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
90
|
+
const mount = (router, admin) => (method, path, handler) => {
|
|
91
|
+
const shape = `${admin ? "admin" : "client"} ${method} ${path.replaceAll(/:[^/]+/gu, ":")}`;
|
|
92
|
+
const taken = shapes.get(shape);
|
|
93
|
+
if (taken !== void 0) throw new _hot_updater_plugin_core.HotUpdaterConfigError(`${handler} (${method} ${path}) collides with ${taken} on handlers.${admin ? "admin" : "client"}.`);
|
|
94
|
+
shapes.set(shape, handler);
|
|
95
|
+
require_internalRouter.addRoute(router, method, path, handler);
|
|
96
|
+
routes.push({
|
|
97
|
+
method,
|
|
98
|
+
path,
|
|
99
|
+
access: admin ? "admin" : PUBLIC_CLIENT_ROUTES.has(handler) ? "public" : "client"
|
|
100
|
+
});
|
|
101
|
+
};
|
|
75
102
|
const clientRouter = require_internalRouter.createRouter();
|
|
76
|
-
const addClientRoute = (
|
|
103
|
+
const addClientRoute = mount(clientRouter, false);
|
|
77
104
|
addClientRoute("GET", "/version", "version");
|
|
78
105
|
if (downloadStorageObject !== void 0) addClientRoute("GET", "/storage/:token/:signature", "downloadStorageObject");
|
|
79
106
|
addClientRoute("GET", "/release-catalogs/app-version/:platform/:channelKey/:appVersion", "appVersionReleaseCatalog");
|
|
80
107
|
addClientRoute("GET", "/release-catalogs/fingerprint/:platform/:channelKey/:fingerprintHash", "fingerprintReleaseCatalog");
|
|
81
|
-
addClientRoute("GET", "/artifacts/:targetBundleId/from/:currentBundleId", "
|
|
82
|
-
if (insights !== void 0) require_routes.registerInsightsClientRoutes(addClientRoute);
|
|
108
|
+
addClientRoute("GET", "/artifacts/v1/:targetBundleId/from/:currentBundleId", "artifactV1");
|
|
83
109
|
const adminRouter = require_internalRouter.createRouter();
|
|
84
|
-
const addAdminRoute = (
|
|
85
|
-
addAdminRoute("GET", "/
|
|
86
|
-
addAdminRoute(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
addAdminRoute("POST", "/database/commit", "commitDatabase");
|
|
94
|
-
addAdminRoute("GET", "/channels", "getChannels");
|
|
95
|
-
addAdminRoute("POST", "/channels", "createChannel");
|
|
96
|
-
addAdminRoute("DELETE", "/channels/:id", "deleteChannel");
|
|
97
|
-
addAdminRoute("GET", "/bundles/:id", "getBundle");
|
|
98
|
-
addAdminRoute("GET", "/bundles", "getBundles");
|
|
99
|
-
addAdminRoute("POST", "/bundles", "createBundles");
|
|
100
|
-
addAdminRoute("PATCH", "/bundles/:id", "updateBundle");
|
|
101
|
-
addAdminRoute("DELETE", "/bundles/:id", "deleteBundle");
|
|
102
|
-
if (insights !== void 0) require_routes.registerInsightsAdminRoutes(addAdminRoute);
|
|
103
|
-
return Object.freeze({
|
|
110
|
+
const addAdminRoute = mount(adminRouter, true);
|
|
111
|
+
addAdminRoute("GET", "/version", "adminVersion");
|
|
112
|
+
for (const route of require_handlerAdminRoutes.ADMIN_ROUTES) addAdminRoute(route.method, route.path, route.handler);
|
|
113
|
+
for (const endpoint of endpoints) {
|
|
114
|
+
const name = `plugin ${endpoint.plugin}: ${endpoint.method} ${endpoint.path}`;
|
|
115
|
+
routeHandlers[name] = (params, request) => endpoint.handler(request, params);
|
|
116
|
+
(endpoint.access === "admin" ? addAdminRoute : addClientRoute)(endpoint.method, endpoint.path, name);
|
|
117
|
+
}
|
|
118
|
+
const handlers = {
|
|
104
119
|
client: createRequestHandler({
|
|
105
120
|
api,
|
|
106
|
-
|
|
121
|
+
...clientPolicy === void 0 ? {} : { clientPolicy },
|
|
107
122
|
routeHandlers,
|
|
108
123
|
router: clientRouter
|
|
109
124
|
}),
|
|
@@ -113,8 +128,9 @@ function createHotUpdaterHandlers(api, insights, apiKeyAuth, downloadStorageObje
|
|
|
113
128
|
routeHandlers,
|
|
114
129
|
router: adminRouter
|
|
115
130
|
})
|
|
116
|
-
}
|
|
131
|
+
};
|
|
132
|
+
Object.defineProperty(handlers, routesOf, { value: Object.freeze(routes) });
|
|
133
|
+
return Object.freeze(handlers);
|
|
117
134
|
}
|
|
118
135
|
//#endregion
|
|
119
|
-
exports.createHandlers = createHandlers;
|
|
120
136
|
exports.createHotUpdaterHandlers = createHotUpdaterHandlers;
|
package/dist/handler.d.cts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#endregion
|
|
5
|
-
export { type HandlerAPI, type HotUpdaterHandler, type HotUpdaterHandlers, createHandlers };
|
|
1
|
+
import "./assembly/assemblePlugins.cjs";
|
|
2
|
+
import { HotUpdaterHandler, HotUpdaterHandlers } from "./handlerTypes.cjs";
|
|
3
|
+
export type { HotUpdaterHandler, HotUpdaterHandlers };
|
package/dist/handler.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#endregion
|
|
5
|
-
export { type HandlerAPI, type HotUpdaterHandler, type HotUpdaterHandlers, createHandlers };
|
|
1
|
+
import "./assembly/assemblePlugins.mjs";
|
|
2
|
+
import { HotUpdaterHandler, HotUpdaterHandlers } from "./handlerTypes.mjs";
|
|
3
|
+
export type { HotUpdaterHandler, HotUpdaterHandlers };
|