@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,238 +0,0 @@
|
|
|
1
|
-
import { encodeChannelKey } from "@hot-updater/core";
|
|
2
|
-
import { commitReleaseCatalogMutation } from "@hot-updater/plugin-core";
|
|
3
|
-
import { describe, expect, it, vi } from "vitest";
|
|
4
|
-
|
|
5
|
-
import { createInMemoryDatabasePlugin } from "../../test-utils/test/inMemoryDatabasePlugin";
|
|
6
|
-
import { registerApiKey } from "./apiKeys";
|
|
7
|
-
import { createHotUpdater } from "./index";
|
|
8
|
-
|
|
9
|
-
const API_KEY = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE";
|
|
10
|
-
|
|
11
|
-
const channelKey = encodeChannelKey("production");
|
|
12
|
-
const scopeKey = `v1:app-version:ios:${channelKey}`;
|
|
13
|
-
|
|
14
|
-
const createCatalogDatabase = async () => {
|
|
15
|
-
const database = createInMemoryDatabasePlugin();
|
|
16
|
-
const channel = { id: "channel-production", name: "production" };
|
|
17
|
-
await database.models.channels.insert({
|
|
18
|
-
onConflict: "returnExisting",
|
|
19
|
-
row: channel,
|
|
20
|
-
});
|
|
21
|
-
const bundleId = "00000000-0000-7001-8000-000000000001";
|
|
22
|
-
await database.commit({
|
|
23
|
-
changes: [
|
|
24
|
-
{
|
|
25
|
-
model: "bundles",
|
|
26
|
-
operation: "insert",
|
|
27
|
-
row: {
|
|
28
|
-
asset_base_storage_uri: null,
|
|
29
|
-
archive_byte_size: 3_000_000_001,
|
|
30
|
-
file_hash: "bundle-hash",
|
|
31
|
-
git_commit_hash: null,
|
|
32
|
-
id: bundleId,
|
|
33
|
-
manifest_file_hash: null,
|
|
34
|
-
manifest_storage_uri: null,
|
|
35
|
-
metadata: {},
|
|
36
|
-
platform: "ios",
|
|
37
|
-
storage_uri: "storage://bundle.zip",
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
});
|
|
42
|
-
await commitReleaseCatalogMutation({
|
|
43
|
-
database,
|
|
44
|
-
mutation: {
|
|
45
|
-
operation: "insert",
|
|
46
|
-
row: {
|
|
47
|
-
bundle_id: bundleId,
|
|
48
|
-
channel_id: channel.id,
|
|
49
|
-
created_at_ms: 1,
|
|
50
|
-
enabled: true,
|
|
51
|
-
fingerprint_hash: null,
|
|
52
|
-
id: "00000000-0000-7000-8000-000000000001",
|
|
53
|
-
kind: "BUNDLE",
|
|
54
|
-
message: "Stable Release",
|
|
55
|
-
operation: "DEPLOY",
|
|
56
|
-
platform: "ios",
|
|
57
|
-
revision: 1,
|
|
58
|
-
rollout_cohort_count: 1000,
|
|
59
|
-
scope_key: scopeKey,
|
|
60
|
-
should_force_update: false,
|
|
61
|
-
source_release_id: null,
|
|
62
|
-
strategy: "APP_VERSION",
|
|
63
|
-
target_app_version: ">=1.0.0 <2.0.0",
|
|
64
|
-
target_cohorts: [],
|
|
65
|
-
updated_at_ms: 1,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
scope: {
|
|
69
|
-
channelId: channel.id,
|
|
70
|
-
channelName: channel.name,
|
|
71
|
-
fingerprintHash: null,
|
|
72
|
-
platform: "ios",
|
|
73
|
-
scopeKey,
|
|
74
|
-
strategy: "APP_VERSION",
|
|
75
|
-
},
|
|
76
|
-
updatedAtMs: 1,
|
|
77
|
-
});
|
|
78
|
-
return database;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
describe("Release catalog routes", () => {
|
|
82
|
-
it("serves persisted Catalog identity without configuration and keeps it across server restarts", async () => {
|
|
83
|
-
const database = await createCatalogDatabase();
|
|
84
|
-
const storedCatalog =
|
|
85
|
-
await database.models.releaseCatalogs.findByScopeKey(scopeKey);
|
|
86
|
-
const hotUpdater = createHotUpdater({
|
|
87
|
-
database,
|
|
88
|
-
clientAccess: { type: "public" },
|
|
89
|
-
});
|
|
90
|
-
const catalogRead = vi.spyOn(
|
|
91
|
-
database.models.releaseCatalogs,
|
|
92
|
-
"findByScopeKey",
|
|
93
|
-
);
|
|
94
|
-
const url =
|
|
95
|
-
`https://updates.example.com/release-catalogs/app-version/` +
|
|
96
|
-
`ios/${channelKey}/1.5.0`;
|
|
97
|
-
|
|
98
|
-
const response = await hotUpdater.handlers.client(new Request(url));
|
|
99
|
-
expect(response.status).toBe(200);
|
|
100
|
-
expect(response.headers.get("cache-control")).toBe(
|
|
101
|
-
"public, max-age=0, s-maxage=5",
|
|
102
|
-
);
|
|
103
|
-
expect(response.headers.get("content-type")).toBe(
|
|
104
|
-
"application/vnd.hot-updater.release-catalog+json; version=1",
|
|
105
|
-
);
|
|
106
|
-
const body = await response.json();
|
|
107
|
-
expect(body).toMatchObject({
|
|
108
|
-
catalogId: storedCatalog!.catalog_id,
|
|
109
|
-
fallbackPolicy: "BUILTIN_IF_ACTIVE_INELIGIBLE",
|
|
110
|
-
generation: 1,
|
|
111
|
-
releases: [
|
|
112
|
-
{
|
|
113
|
-
bundleId: "00000000-0000-7001-8000-000000000001",
|
|
114
|
-
kind: "BUNDLE",
|
|
115
|
-
message: "Stable Release",
|
|
116
|
-
shouldForceUpdate: false,
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
rollbackReleases: [
|
|
120
|
-
{
|
|
121
|
-
bundleId: "00000000-0000-7001-8000-000000000001",
|
|
122
|
-
kind: "BUNDLE",
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
scopeKey,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const etag = response.headers.get("etag");
|
|
129
|
-
expect(etag).toMatch(/^"sha256:[0-9a-f]{64}"$/);
|
|
130
|
-
const revalidated = await hotUpdater.handlers.client(
|
|
131
|
-
new Request(url, { headers: { "if-none-match": etag! } }),
|
|
132
|
-
);
|
|
133
|
-
expect(revalidated.status).toBe(304);
|
|
134
|
-
expect(await revalidated.text()).toBe("");
|
|
135
|
-
expect(catalogRead).toHaveBeenCalledOnce();
|
|
136
|
-
|
|
137
|
-
const nonCanonicalVersion = await hotUpdater.handlers.client(
|
|
138
|
-
new Request(url.replace("/1.5.0", "/v1.5")),
|
|
139
|
-
);
|
|
140
|
-
expect(nonCanonicalVersion.status).toBe(400);
|
|
141
|
-
expect(nonCanonicalVersion.headers.get("cache-control")).toBe(
|
|
142
|
-
"private, no-store",
|
|
143
|
-
);
|
|
144
|
-
expect(catalogRead).toHaveBeenCalledOnce();
|
|
145
|
-
|
|
146
|
-
const invalidPlatform = await hotUpdater.handlers.client(
|
|
147
|
-
new Request(url.replace("/ios/", "/windows/")),
|
|
148
|
-
);
|
|
149
|
-
expect(invalidPlatform.status).toBe(400);
|
|
150
|
-
expect(catalogRead).toHaveBeenCalledOnce();
|
|
151
|
-
|
|
152
|
-
const otherChannel = await hotUpdater.handlers.client(
|
|
153
|
-
new Request(
|
|
154
|
-
url.replace(`/${channelKey}/`, `/${encodeChannelKey("beta")}/`),
|
|
155
|
-
),
|
|
156
|
-
);
|
|
157
|
-
expect(otherChannel.status).toBe(404);
|
|
158
|
-
expect(catalogRead).toHaveBeenCalledTimes(2);
|
|
159
|
-
|
|
160
|
-
const legacyAuthorityPath = await hotUpdater.handlers.client(
|
|
161
|
-
new Request(
|
|
162
|
-
`https://updates.example.com/release-catalogs/app-version/` +
|
|
163
|
-
`old-authority/ios/${channelKey}/1.5.0`,
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
expect(legacyAuthorityPath.status).toBe(404);
|
|
167
|
-
expect(legacyAuthorityPath.headers.get("cache-control")).toBe(
|
|
168
|
-
"private, no-store",
|
|
169
|
-
);
|
|
170
|
-
expect(catalogRead).toHaveBeenCalledTimes(2);
|
|
171
|
-
const commit = vi.spyOn(database, "commit");
|
|
172
|
-
const restarted = createHotUpdater({
|
|
173
|
-
database,
|
|
174
|
-
clientAccess: { type: "public" },
|
|
175
|
-
});
|
|
176
|
-
const relocated = await restarted.handlers.client(
|
|
177
|
-
new Request(url.replace("updates.example.com", "new.example.com")),
|
|
178
|
-
);
|
|
179
|
-
expect(await relocated.json()).toEqual(body);
|
|
180
|
-
expect(commit).not.toHaveBeenCalled();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("singleflights concurrent cold requests into one exact catalog read", async () => {
|
|
184
|
-
const database = await createCatalogDatabase();
|
|
185
|
-
const catalogRead = vi.spyOn(
|
|
186
|
-
database.models.releaseCatalogs,
|
|
187
|
-
"findByScopeKey",
|
|
188
|
-
);
|
|
189
|
-
const hotUpdater = createHotUpdater({
|
|
190
|
-
database,
|
|
191
|
-
clientAccess: { type: "public" },
|
|
192
|
-
});
|
|
193
|
-
const url =
|
|
194
|
-
`https://updates.example.com/release-catalogs/app-version/` +
|
|
195
|
-
`ios/${channelKey}/1.5.0`;
|
|
196
|
-
|
|
197
|
-
const responses = await Promise.all(
|
|
198
|
-
Array.from({ length: 100 }, () =>
|
|
199
|
-
hotUpdater.handlers.client(new Request(url)),
|
|
200
|
-
),
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
expect(responses.every(({ status }) => status === 200)).toBe(true);
|
|
204
|
-
expect(catalogRead).toHaveBeenCalledOnce();
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("varies authenticated catalog responses by the configured header", async () => {
|
|
208
|
-
const database = await createCatalogDatabase();
|
|
209
|
-
await registerApiKey({
|
|
210
|
-
apiKeys: database.models.apiKeys,
|
|
211
|
-
apiKey: API_KEY,
|
|
212
|
-
name: "App",
|
|
213
|
-
});
|
|
214
|
-
const hotUpdater = createHotUpdater({
|
|
215
|
-
clientAccess: {
|
|
216
|
-
headerName: "X-Hot-Updater-Key",
|
|
217
|
-
type: "api-key",
|
|
218
|
-
},
|
|
219
|
-
database,
|
|
220
|
-
});
|
|
221
|
-
const url =
|
|
222
|
-
`https://updates.example.com/release-catalogs/app-version/` +
|
|
223
|
-
`ios/${channelKey}/1.5.0`;
|
|
224
|
-
|
|
225
|
-
const unauthorized = await hotUpdater.handlers.client(
|
|
226
|
-
new Request(url, { headers: { "x-api-key": API_KEY } }),
|
|
227
|
-
);
|
|
228
|
-
expect(unauthorized.status).toBe(401);
|
|
229
|
-
|
|
230
|
-
const response = await hotUpdater.handlers.client(
|
|
231
|
-
new Request(url, { headers: { "x-hot-updater-key": API_KEY } }),
|
|
232
|
-
);
|
|
233
|
-
expect(response.status).toBe(200);
|
|
234
|
-
expect(response.headers.get("vary")).toBe(
|
|
235
|
-
"Accept-Encoding, x-hot-updater-key",
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
});
|
package/src/runtime.spec.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStoragePlugin,
|
|
3
|
-
type DatabasePlugin,
|
|
4
|
-
type ConfigInput,
|
|
5
|
-
} from "@hot-updater/plugin-core";
|
|
6
|
-
import { describe, expect, expectTypeOf, it, vi } from "vitest";
|
|
7
|
-
|
|
8
|
-
import { createInMemoryDatabasePlugin } from "../../test-utils/test/inMemoryDatabasePlugin";
|
|
9
|
-
import packageJson from "../package.json" with { type: "json" };
|
|
10
|
-
import { createHotUpdater } from "./index";
|
|
11
|
-
import type {
|
|
12
|
-
ClientAccessPolicy,
|
|
13
|
-
CreateHotUpdaterOptions,
|
|
14
|
-
HandlerAPI,
|
|
15
|
-
} from "./index";
|
|
16
|
-
import {
|
|
17
|
-
createRuntimeDatabase,
|
|
18
|
-
createSchemaManagedDatabase,
|
|
19
|
-
} from "./runtime.testFixtures";
|
|
20
|
-
import { HOT_UPDATER_SCHEMA_VERSION } from "./schema/types";
|
|
21
|
-
import { HOT_UPDATER_SERVER_VERSION } from "./version";
|
|
22
|
-
|
|
23
|
-
const publicClientAccess = {
|
|
24
|
-
type: "public",
|
|
25
|
-
} satisfies ClientAccessPolicy;
|
|
26
|
-
|
|
27
|
-
describe("runtime createHotUpdater", () => {
|
|
28
|
-
it.each(["authorityId", "catalogId"])("rejects a user-supplied %s", (key) => {
|
|
29
|
-
expect(() =>
|
|
30
|
-
createHotUpdater({
|
|
31
|
-
clientAccess: publicClientAccess,
|
|
32
|
-
database: createInMemoryDatabasePlugin(),
|
|
33
|
-
[key]: "user-controlled",
|
|
34
|
-
}),
|
|
35
|
-
).toThrow(`Remove ${key}`);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("publishes only the supported runtime and database subpaths", () => {
|
|
39
|
-
const packageExports = packageJson.exports;
|
|
40
|
-
|
|
41
|
-
const databaseEntry = packageExports["./db"];
|
|
42
|
-
const hasRuntimeEntry = Object.hasOwn(packageExports, "./runtime");
|
|
43
|
-
|
|
44
|
-
expect(databaseEntry).toBeDefined();
|
|
45
|
-
expect(hasRuntimeEntry).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("exports runtime-safe handler types from the root entry", () => {
|
|
49
|
-
expectTypeOf<ConfigInput>().not.toHaveProperty("authorityId");
|
|
50
|
-
expectTypeOf<ConfigInput>().not.toHaveProperty("catalogId");
|
|
51
|
-
expectTypeOf<HandlerAPI>().toHaveProperty("getBundles");
|
|
52
|
-
expectTypeOf<keyof CreateHotUpdaterOptions>().toEqualTypeOf<
|
|
53
|
-
"clientAccess" | "database" | "storage"
|
|
54
|
-
>();
|
|
55
|
-
expectTypeOf<CreateHotUpdaterOptions>().toHaveProperty("clientAccess");
|
|
56
|
-
expectTypeOf<
|
|
57
|
-
CreateHotUpdaterOptions["clientAccess"]
|
|
58
|
-
>().toEqualTypeOf<ClientAccessPolicy>();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("accepts a direct v2 plugin object without exposing maintenance methods", () => {
|
|
62
|
-
const database: DatabasePlugin = {
|
|
63
|
-
...createInMemoryDatabasePlugin(),
|
|
64
|
-
name: "contextlessTestDatabase",
|
|
65
|
-
};
|
|
66
|
-
const storage = createStoragePlugin({
|
|
67
|
-
name: "contextlessTestStorage",
|
|
68
|
-
protocol: "s3",
|
|
69
|
-
get: async () => ({ response: null }),
|
|
70
|
-
getDownloadUrl: async () => ({
|
|
71
|
-
url: "https://assets.example.com/bundle.zip",
|
|
72
|
-
}),
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const hotUpdater = createHotUpdater({
|
|
76
|
-
clientAccess: publicClientAccess,
|
|
77
|
-
database,
|
|
78
|
-
storage: [storage],
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(hotUpdater.adapterName).toBe("contextlessTestDatabase");
|
|
82
|
-
expect(hotUpdater.handlers.client).toEqual(expect.any(Function));
|
|
83
|
-
expect(hotUpdater.handlers.admin).toEqual(expect.any(Function));
|
|
84
|
-
expect("createMigrator" in hotUpdater).toBe(false);
|
|
85
|
-
expect("generateSchema" in hotUpdater).toBe(false);
|
|
86
|
-
expect(hotUpdater).not.toHaveProperty("authorityId");
|
|
87
|
-
expect(hotUpdater).not.toHaveProperty("catalogId");
|
|
88
|
-
expectTypeOf(hotUpdater).not.toHaveProperty("createMigrator");
|
|
89
|
-
expectTypeOf(hotUpdater).not.toHaveProperty("generateSchema");
|
|
90
|
-
expectTypeOf(hotUpdater.handlers.client)
|
|
91
|
-
.parameter(0)
|
|
92
|
-
.toEqualTypeOf<Request>();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("rejects access when a managed schema is not initialized", async () => {
|
|
96
|
-
const hotUpdater = createHotUpdater({
|
|
97
|
-
clientAccess: publicClientAccess,
|
|
98
|
-
database: createSchemaManagedDatabase("kysely", undefined),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const result = hotUpdater.getBundles({ limit: 10 });
|
|
102
|
-
|
|
103
|
-
await expect(result).rejects.toThrow(
|
|
104
|
-
"Hot Updater database schema is not initialized for kysely.",
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it.each(["s3", "https"])(
|
|
109
|
-
"rejects registered %s storage without getDownloadUrl",
|
|
110
|
-
(protocol) => {
|
|
111
|
-
const storage = createStoragePlugin({
|
|
112
|
-
name: "deployOnlyStorage",
|
|
113
|
-
protocol,
|
|
114
|
-
get: async () => ({ response: null }),
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
expect(() =>
|
|
118
|
-
createHotUpdater({
|
|
119
|
-
clientAccess: publicClientAccess,
|
|
120
|
-
database: createRuntimeDatabase(),
|
|
121
|
-
storage: [storage],
|
|
122
|
-
}),
|
|
123
|
-
).toThrow(
|
|
124
|
-
'Storage plugin "deployOnlyStorage" does not implement getDownloadUrl.',
|
|
125
|
-
);
|
|
126
|
-
},
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
it("rejects access when a managed schema is stale", async () => {
|
|
130
|
-
const hotUpdater = createHotUpdater({
|
|
131
|
-
clientAccess: publicClientAccess,
|
|
132
|
-
database: createSchemaManagedDatabase("mongodb", "0.21.0"),
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const result = hotUpdater.getChannels();
|
|
136
|
-
|
|
137
|
-
await expect(result).rejects.toThrow(
|
|
138
|
-
"Hot Updater v1 cannot migrate schema 0.21.0 in place.",
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("checks a ready managed schema only once", async () => {
|
|
143
|
-
const database = createSchemaManagedDatabase(
|
|
144
|
-
"kysely",
|
|
145
|
-
HOT_UPDATER_SCHEMA_VERSION,
|
|
146
|
-
);
|
|
147
|
-
const createMigrator = vi.spyOn(database, "createMigrator");
|
|
148
|
-
const hotUpdater = createHotUpdater({
|
|
149
|
-
clientAccess: publicClientAccess,
|
|
150
|
-
database,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
await hotUpdater.getChannels();
|
|
154
|
-
await hotUpdater.getChannels();
|
|
155
|
-
|
|
156
|
-
expect(createMigrator).toHaveBeenCalledOnce();
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("keeps the version route mounted on the client handler", async () => {
|
|
160
|
-
const hotUpdater = createHotUpdater({
|
|
161
|
-
clientAccess: publicClientAccess,
|
|
162
|
-
database: createRuntimeDatabase(),
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const response = await hotUpdater.handlers.client(
|
|
166
|
-
new Request("https://updates.example.com/version"),
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
expect(response.status).toBe(200);
|
|
170
|
-
await expect(response.json()).resolves.toEqual({
|
|
171
|
-
infrastructureGeneration: 1,
|
|
172
|
-
version: HOT_UPDATER_SERVER_VERSION,
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("rejects a missing client access policy", () => {
|
|
177
|
-
expect(() =>
|
|
178
|
-
createHotUpdater({
|
|
179
|
-
database: createRuntimeDatabase(),
|
|
180
|
-
} as unknown as CreateHotUpdaterOptions),
|
|
181
|
-
).toThrow("clientAccess must be an object.");
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("rejects an unsupported client access policy", () => {
|
|
185
|
-
expect(() =>
|
|
186
|
-
createHotUpdater({
|
|
187
|
-
clientAccess: {
|
|
188
|
-
type: "private" as unknown as "public",
|
|
189
|
-
},
|
|
190
|
-
database: createRuntimeDatabase(),
|
|
191
|
-
}),
|
|
192
|
-
).toThrow('clientAccess.type must be either "public" or "api-key".');
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Bundle } from "@hot-updater/core";
|
|
2
|
-
import type {
|
|
3
|
-
DatabasePlugin,
|
|
4
|
-
StoragePlugin,
|
|
5
|
-
StoragePluginWith,
|
|
6
|
-
} from "@hot-updater/plugin-core";
|
|
7
|
-
import { createStoragePlugin } from "@hot-updater/plugin-core";
|
|
8
|
-
|
|
9
|
-
import { createInMemoryDatabasePlugin } from "../../test-utils/test/inMemoryDatabasePlugin";
|
|
10
|
-
import type { DatabaseAdapterCapabilities, Migrator } from "./db/types";
|
|
11
|
-
|
|
12
|
-
export const runtimeBundle: Bundle = {
|
|
13
|
-
id: "00000000-0000-0000-0000-000000000001",
|
|
14
|
-
platform: "ios",
|
|
15
|
-
fileHash: "hash123",
|
|
16
|
-
gitCommitHash: null,
|
|
17
|
-
storageUri: "s3://test-bucket/bundles/bundle.zip",
|
|
18
|
-
archiveByteSize: 3_000_000_001,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const createRuntimeStorage = (
|
|
22
|
-
get: NonNullable<StoragePlugin["get"]> = async () => ({ response: null }),
|
|
23
|
-
getDownloadUrl?: StoragePlugin["getDownloadUrl"],
|
|
24
|
-
): StoragePluginWith<"get"> =>
|
|
25
|
-
createStoragePlugin({
|
|
26
|
-
name: "testStorage",
|
|
27
|
-
protocol: "s3",
|
|
28
|
-
get,
|
|
29
|
-
...(getDownloadUrl ? { getDownloadUrl } : {}),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const createMigrator = (version: string | undefined): Migrator => ({
|
|
33
|
-
async getVersion() {
|
|
34
|
-
return version;
|
|
35
|
-
},
|
|
36
|
-
async getNameVariants() {
|
|
37
|
-
return {};
|
|
38
|
-
},
|
|
39
|
-
async next() {
|
|
40
|
-
return undefined;
|
|
41
|
-
},
|
|
42
|
-
async previous() {
|
|
43
|
-
return undefined;
|
|
44
|
-
},
|
|
45
|
-
async up() {
|
|
46
|
-
throw new Error("not implemented");
|
|
47
|
-
},
|
|
48
|
-
async down() {
|
|
49
|
-
throw new Error("not implemented");
|
|
50
|
-
},
|
|
51
|
-
async migrateTo() {
|
|
52
|
-
throw new Error("not implemented");
|
|
53
|
-
},
|
|
54
|
-
async migrateToLatest() {
|
|
55
|
-
throw new Error("not implemented");
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export const createRuntimeDatabase = (): DatabasePlugin => ({
|
|
60
|
-
...createInMemoryDatabasePlugin(),
|
|
61
|
-
name: "testDatabase",
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export const createSchemaManagedDatabase = (
|
|
65
|
-
adapterName: string,
|
|
66
|
-
version: string | undefined,
|
|
67
|
-
): DatabasePlugin & DatabaseAdapterCapabilities => ({
|
|
68
|
-
...createRuntimeDatabase(),
|
|
69
|
-
adapterName,
|
|
70
|
-
createMigrator: () => createMigrator(version),
|
|
71
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { hotUpdaterSchemaVersions } from "./index";
|
|
4
|
-
import { createSettingsTable } from "./settings";
|
|
5
|
-
import {
|
|
6
|
-
bundlePatchesV100,
|
|
7
|
-
bundleInstallationsV100,
|
|
8
|
-
bundlesV100,
|
|
9
|
-
channelsV100,
|
|
10
|
-
releaseCatalogsV100,
|
|
11
|
-
releasesV100,
|
|
12
|
-
v1_0_0,
|
|
13
|
-
} from "./v1_0_0";
|
|
14
|
-
|
|
15
|
-
describe("versioned schema DSL", () => {
|
|
16
|
-
it("uses the local functional DSL for the current schema", () => {
|
|
17
|
-
expect(v1_0_0.dsl).toBe("schema");
|
|
18
|
-
expect(channelsV100.dsl).toBe("table");
|
|
19
|
-
expect(bundlesV100.dsl).toBe("table");
|
|
20
|
-
expect(bundlePatchesV100.dsl).toBe("table");
|
|
21
|
-
expect(bundleInstallationsV100.dsl).toBe("table");
|
|
22
|
-
expect(releasesV100.dsl).toBe("table");
|
|
23
|
-
expect(releaseCatalogsV100.dsl).toBe("table");
|
|
24
|
-
expect(createSettingsTable("1.0.0").dsl).toBe("table");
|
|
25
|
-
|
|
26
|
-
expect(Object.keys(v1_0_0)).not.toContain("dsl");
|
|
27
|
-
for (const table of v1_0_0.tables) {
|
|
28
|
-
expect(Object.keys(table)).not.toContain("dsl");
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("registers only the initial schema 1.0.0", () => {
|
|
33
|
-
expect(hotUpdaterSchemaVersions.map((item) => item.version)).toEqual([
|
|
34
|
-
"1.0.0",
|
|
35
|
-
]);
|
|
36
|
-
});
|
|
37
|
-
});
|