@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,413 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BundleEventRow,
|
|
3
|
-
BundlePatchRow,
|
|
4
|
-
BundleRow,
|
|
5
|
-
ChannelRow,
|
|
6
|
-
ApiKeyRow,
|
|
7
|
-
InsightsInstallationRow,
|
|
8
|
-
ReleaseCatalogRow,
|
|
9
|
-
ReleaseRow,
|
|
10
|
-
} from "@hot-updater/plugin-core";
|
|
11
|
-
import { compareInsightsText } from "@hot-updater/plugin-core";
|
|
12
|
-
|
|
13
|
-
type Row =
|
|
14
|
-
| BundleEventRow
|
|
15
|
-
| BundlePatchRow
|
|
16
|
-
| BundleRow
|
|
17
|
-
| ChannelRow
|
|
18
|
-
| ApiKeyRow
|
|
19
|
-
| InsightsInstallationRow
|
|
20
|
-
| ReleaseRow
|
|
21
|
-
| ReleaseCatalogRow;
|
|
22
|
-
type Table = Row[];
|
|
23
|
-
type Tables = {
|
|
24
|
-
bundle_patches: Table;
|
|
25
|
-
bundles: Table;
|
|
26
|
-
bundle_events: Table;
|
|
27
|
-
bundle_installations: Table;
|
|
28
|
-
channels: Table;
|
|
29
|
-
api_keys: Table;
|
|
30
|
-
releases: Table;
|
|
31
|
-
release_catalogs: Table;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type Hooks = {
|
|
35
|
-
beforeNextBundleUpdateMany: ((tables: Tables) => void) | undefined;
|
|
36
|
-
failNextBundleDelete: boolean;
|
|
37
|
-
transactionOptions: ({ readonly isolationLevel?: string } | undefined)[];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
type QueryArgs = {
|
|
41
|
-
readonly orderBy?: unknown;
|
|
42
|
-
readonly skip?: number;
|
|
43
|
-
readonly take?: number;
|
|
44
|
-
readonly where?: unknown;
|
|
45
|
-
};
|
|
46
|
-
type CreateArgs = QueryArgs & { readonly data: Row };
|
|
47
|
-
type UpdateArgs = QueryArgs & {
|
|
48
|
-
readonly data: Readonly<Record<string, unknown>>;
|
|
49
|
-
};
|
|
50
|
-
type UpsertArgs = QueryArgs & {
|
|
51
|
-
readonly create: Row;
|
|
52
|
-
readonly update: Partial<Row>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
class PrismaTestConstraintError extends Error {
|
|
56
|
-
readonly name = "PrismaTestConstraintError";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
60
|
-
typeof value === "object" && value !== null;
|
|
61
|
-
|
|
62
|
-
const compare = (left: unknown, right: unknown): number => {
|
|
63
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
64
|
-
return left - right;
|
|
65
|
-
}
|
|
66
|
-
if (typeof left === "string" && typeof right === "string") {
|
|
67
|
-
return compareInsightsText(left, right);
|
|
68
|
-
}
|
|
69
|
-
return 0;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const normalize = (value: unknown, insensitive: boolean): unknown =>
|
|
73
|
-
insensitive && typeof value === "string" ? value.toLocaleLowerCase() : value;
|
|
74
|
-
|
|
75
|
-
const readField = (row: Row, field: string): unknown =>
|
|
76
|
-
Object.entries(row).find(([key]) => key === field)?.[1];
|
|
77
|
-
|
|
78
|
-
const rowKey = (model: keyof Tables, row: Row): string =>
|
|
79
|
-
model === "bundle_installations" && "install_id" in row
|
|
80
|
-
? row.install_id
|
|
81
|
-
: "id" in row
|
|
82
|
-
? row.id
|
|
83
|
-
: row.scope_key;
|
|
84
|
-
|
|
85
|
-
const matchesCondition = (current: unknown, condition: unknown): boolean => {
|
|
86
|
-
if (!isRecord(condition)) return Object.is(current, condition);
|
|
87
|
-
const insensitive = condition["mode"] === "insensitive";
|
|
88
|
-
const value = normalize(current, insensitive);
|
|
89
|
-
if ("equals" in condition) {
|
|
90
|
-
return Object.is(value, normalize(condition["equals"], insensitive));
|
|
91
|
-
}
|
|
92
|
-
if ("not" in condition) {
|
|
93
|
-
return (
|
|
94
|
-
value !== null &&
|
|
95
|
-
value !== undefined &&
|
|
96
|
-
!Object.is(value, normalize(condition["not"], insensitive))
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
if (Array.isArray(condition["in"])) {
|
|
100
|
-
return condition["in"].some((item) => Object.is(value, item));
|
|
101
|
-
}
|
|
102
|
-
if (Array.isArray(condition["notIn"])) {
|
|
103
|
-
return (
|
|
104
|
-
condition["notIn"].length === 0 ||
|
|
105
|
-
(value !== null &&
|
|
106
|
-
value !== undefined &&
|
|
107
|
-
condition["notIn"].every((item) => !Object.is(value, item)))
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
if (value === null || value === undefined) return false;
|
|
111
|
-
if ("gt" in condition) return compare(value, condition["gt"]) > 0;
|
|
112
|
-
if ("gte" in condition) return compare(value, condition["gte"]) >= 0;
|
|
113
|
-
if ("lt" in condition) return compare(value, condition["lt"]) < 0;
|
|
114
|
-
if ("lte" in condition) return compare(value, condition["lte"]) <= 0;
|
|
115
|
-
if (typeof value !== "string") return false;
|
|
116
|
-
if (typeof condition["contains"] === "string") {
|
|
117
|
-
const target = normalize(condition["contains"], insensitive);
|
|
118
|
-
return typeof target === "string" && value.includes(target);
|
|
119
|
-
}
|
|
120
|
-
if (typeof condition["startsWith"] === "string") {
|
|
121
|
-
const target = normalize(condition["startsWith"], insensitive);
|
|
122
|
-
return typeof target === "string" && value.startsWith(target);
|
|
123
|
-
}
|
|
124
|
-
if (typeof condition["endsWith"] === "string") {
|
|
125
|
-
const target = normalize(condition["endsWith"], insensitive);
|
|
126
|
-
return typeof target === "string" && value.endsWith(target);
|
|
127
|
-
}
|
|
128
|
-
return false;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const matchesWhere = (row: Row, where: unknown): boolean => {
|
|
132
|
-
if (!isRecord(where)) return true;
|
|
133
|
-
const conjunction = where["AND"];
|
|
134
|
-
if (Array.isArray(conjunction)) {
|
|
135
|
-
return conjunction.every((item) => matchesWhere(row, item));
|
|
136
|
-
}
|
|
137
|
-
const disjunction = where["OR"];
|
|
138
|
-
if (Array.isArray(disjunction)) {
|
|
139
|
-
return disjunction.some((item) => matchesWhere(row, item));
|
|
140
|
-
}
|
|
141
|
-
return Object.entries(where).every(([field, condition]) =>
|
|
142
|
-
matchesCondition(readField(row, field), condition),
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const sortRows = (rows: Row[], orderBy: unknown): Row[] => {
|
|
147
|
-
const clauses = Array.isArray(orderBy)
|
|
148
|
-
? orderBy.filter(isRecord)
|
|
149
|
-
: isRecord(orderBy)
|
|
150
|
-
? [orderBy]
|
|
151
|
-
: [];
|
|
152
|
-
if (clauses.length === 0) return rows;
|
|
153
|
-
return rows.toSorted((left, right) => {
|
|
154
|
-
for (const clause of clauses) {
|
|
155
|
-
const entry = Object.entries(clause)[0];
|
|
156
|
-
if (entry === undefined) continue;
|
|
157
|
-
const [field, direction] = entry;
|
|
158
|
-
const result = compare(readField(left, field), readField(right, field));
|
|
159
|
-
if (result !== 0) {
|
|
160
|
-
return direction === "desc" ? -result : result;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return 0;
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const assertReferences = (
|
|
168
|
-
tables: Tables,
|
|
169
|
-
model: keyof Tables,
|
|
170
|
-
row: Row,
|
|
171
|
-
): void => {
|
|
172
|
-
if (model === "bundle_patches" && "base_bundle_id" in row) {
|
|
173
|
-
const bundleIds = new Set(
|
|
174
|
-
tables.bundles.flatMap((bundle) => ("id" in bundle ? [bundle.id] : [])),
|
|
175
|
-
);
|
|
176
|
-
if (!bundleIds.has(row.bundle_id) || !bundleIds.has(row.base_bundle_id)) {
|
|
177
|
-
throw new PrismaTestConstraintError("missing patch reference");
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (model === "releases" && "kind" in row) {
|
|
181
|
-
if (
|
|
182
|
-
!tables.channels.some(
|
|
183
|
-
(channel) => "id" in channel && channel.id === row.channel_id,
|
|
184
|
-
) ||
|
|
185
|
-
(row.bundle_id !== null &&
|
|
186
|
-
!tables.bundles.some(
|
|
187
|
-
(bundle) =>
|
|
188
|
-
"file_hash" in bundle &&
|
|
189
|
-
bundle.id === row.bundle_id &&
|
|
190
|
-
bundle.platform === row.platform,
|
|
191
|
-
))
|
|
192
|
-
) {
|
|
193
|
-
throw new PrismaTestConstraintError("missing Release reference");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const createDelegate = (tables: Tables, model: keyof Tables, hooks: Hooks) => ({
|
|
199
|
-
count: async (args?: QueryArgs): Promise<number> =>
|
|
200
|
-
tables[model].filter((row) => matchesWhere(row, args?.where)).length,
|
|
201
|
-
create: async ({ data }: CreateArgs): Promise<Row> => {
|
|
202
|
-
if (
|
|
203
|
-
tables[model].some((row) => rowKey(model, row) === rowKey(model, data))
|
|
204
|
-
) {
|
|
205
|
-
throw new PrismaTestConstraintError("duplicate id");
|
|
206
|
-
}
|
|
207
|
-
if (
|
|
208
|
-
model === "channels" &&
|
|
209
|
-
"name" in data &&
|
|
210
|
-
tables.channels.some((row) => "name" in row && row.name === data.name)
|
|
211
|
-
) {
|
|
212
|
-
throw new PrismaTestConstraintError("duplicate channel name");
|
|
213
|
-
}
|
|
214
|
-
if (
|
|
215
|
-
model === "api_keys" &&
|
|
216
|
-
"hash" in data &&
|
|
217
|
-
tables.api_keys.some((row) => "hash" in row && row.hash === data.hash)
|
|
218
|
-
) {
|
|
219
|
-
throw new PrismaTestConstraintError("duplicate hash");
|
|
220
|
-
}
|
|
221
|
-
assertReferences(tables, model, data);
|
|
222
|
-
tables[model].push(structuredClone(data));
|
|
223
|
-
return structuredClone(data);
|
|
224
|
-
},
|
|
225
|
-
deleteMany: async (args?: QueryArgs): Promise<void> => {
|
|
226
|
-
if (model === "bundles" && hooks.failNextBundleDelete) {
|
|
227
|
-
hooks.failNextBundleDelete = false;
|
|
228
|
-
throw new PrismaTestConstraintError("injected bundle delete failure");
|
|
229
|
-
}
|
|
230
|
-
const selected = tables[model].filter((row) =>
|
|
231
|
-
matchesWhere(row, args?.where),
|
|
232
|
-
);
|
|
233
|
-
if (model === "bundles") {
|
|
234
|
-
const ids = new Set(selected.map((row) => rowKey(model, row)));
|
|
235
|
-
if (
|
|
236
|
-
tables.releases.some(
|
|
237
|
-
(row) =>
|
|
238
|
-
"bundle_id" in row &&
|
|
239
|
-
row.bundle_id !== null &&
|
|
240
|
-
ids.has(row.bundle_id),
|
|
241
|
-
)
|
|
242
|
-
) {
|
|
243
|
-
throw new PrismaTestConstraintError("referenced bundle");
|
|
244
|
-
}
|
|
245
|
-
tables.bundle_patches = tables.bundle_patches.filter(
|
|
246
|
-
(row) =>
|
|
247
|
-
!("base_bundle_id" in row) ||
|
|
248
|
-
(!ids.has(row.bundle_id) && !ids.has(row.base_bundle_id)),
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
tables[model] = tables[model].filter(
|
|
252
|
-
(row) => !matchesWhere(row, args?.where),
|
|
253
|
-
);
|
|
254
|
-
},
|
|
255
|
-
findFirst: async (args?: QueryArgs): Promise<Row | null> =>
|
|
256
|
-
structuredClone(
|
|
257
|
-
tables[model].find((row) => matchesWhere(row, args?.where)) ?? null,
|
|
258
|
-
),
|
|
259
|
-
findMany: async (args?: QueryArgs): Promise<Row[]> => {
|
|
260
|
-
const filtered = tables[model].filter((row) =>
|
|
261
|
-
matchesWhere(row, args?.where),
|
|
262
|
-
);
|
|
263
|
-
const sorted = sortRows(filtered, args?.orderBy);
|
|
264
|
-
const start = args?.skip ?? 0;
|
|
265
|
-
const end = start + (args?.take ?? sorted.length);
|
|
266
|
-
return structuredClone(sorted.slice(start, end));
|
|
267
|
-
},
|
|
268
|
-
update: async ({ data, where }: UpdateArgs): Promise<Row> => {
|
|
269
|
-
const index = tables[model].findIndex((row) => matchesWhere(row, where));
|
|
270
|
-
const current = tables[model][index];
|
|
271
|
-
if (current === undefined) {
|
|
272
|
-
throw new PrismaTestConstraintError("missing update row");
|
|
273
|
-
}
|
|
274
|
-
const updated = { ...current, ...data } as Row;
|
|
275
|
-
assertReferences(tables, model, updated);
|
|
276
|
-
tables[model][index] = updated;
|
|
277
|
-
return structuredClone(updated);
|
|
278
|
-
},
|
|
279
|
-
updateMany: async ({
|
|
280
|
-
data,
|
|
281
|
-
where,
|
|
282
|
-
}: UpdateArgs): Promise<{ count: number }> => {
|
|
283
|
-
if (model === "bundles") {
|
|
284
|
-
const hook = hooks.beforeNextBundleUpdateMany;
|
|
285
|
-
hooks.beforeNextBundleUpdateMany = undefined;
|
|
286
|
-
hook?.(tables);
|
|
287
|
-
}
|
|
288
|
-
let count = 0;
|
|
289
|
-
tables[model] = tables[model].map((row) => {
|
|
290
|
-
if (!matchesWhere(row, where)) return row;
|
|
291
|
-
const updated = { ...row, ...data } as Row;
|
|
292
|
-
assertReferences(tables, model, updated);
|
|
293
|
-
count += 1;
|
|
294
|
-
return updated;
|
|
295
|
-
});
|
|
296
|
-
return { count };
|
|
297
|
-
},
|
|
298
|
-
upsert: async ({ create, update, where }: UpsertArgs): Promise<Row> => {
|
|
299
|
-
const index = tables[model].findIndex((row) => matchesWhere(row, where));
|
|
300
|
-
const current = tables[model][index];
|
|
301
|
-
if (current !== undefined) {
|
|
302
|
-
const updated = { ...current, ...update } as Row;
|
|
303
|
-
assertReferences(tables, model, updated);
|
|
304
|
-
tables[model][index] = updated;
|
|
305
|
-
return structuredClone(updated);
|
|
306
|
-
}
|
|
307
|
-
if (
|
|
308
|
-
tables[model].some((row) => rowKey(model, row) === rowKey(model, create))
|
|
309
|
-
) {
|
|
310
|
-
throw new PrismaTestConstraintError("duplicate id");
|
|
311
|
-
}
|
|
312
|
-
assertReferences(tables, model, create);
|
|
313
|
-
tables[model].push(structuredClone(create));
|
|
314
|
-
return structuredClone(create);
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
const createClient = (tables: Tables, hooks: Hooks) => ({
|
|
319
|
-
bundle_events: createDelegate(tables, "bundle_events", hooks),
|
|
320
|
-
bundle_installations: createDelegate(tables, "bundle_installations", hooks),
|
|
321
|
-
bundle_patches: createDelegate(tables, "bundle_patches", hooks),
|
|
322
|
-
bundles: createDelegate(tables, "bundles", hooks),
|
|
323
|
-
channels: createDelegate(tables, "channels", hooks),
|
|
324
|
-
api_keys: createDelegate(tables, "api_keys", hooks),
|
|
325
|
-
releases: createDelegate(tables, "releases", hooks),
|
|
326
|
-
release_catalogs: createDelegate(tables, "release_catalogs", hooks),
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
export const createPrismaTestHarness = () => {
|
|
330
|
-
let tables: Tables = {
|
|
331
|
-
bundle_patches: [],
|
|
332
|
-
bundles: [],
|
|
333
|
-
bundle_events: [],
|
|
334
|
-
bundle_installations: [],
|
|
335
|
-
channels: [],
|
|
336
|
-
api_keys: [],
|
|
337
|
-
releases: [],
|
|
338
|
-
release_catalogs: [],
|
|
339
|
-
};
|
|
340
|
-
const hooks: Hooks = {
|
|
341
|
-
beforeNextBundleUpdateMany: undefined,
|
|
342
|
-
failNextBundleDelete: false,
|
|
343
|
-
transactionOptions: [],
|
|
344
|
-
};
|
|
345
|
-
let transactionQueue = Promise.resolve();
|
|
346
|
-
const client = {
|
|
347
|
-
...createClient(tables, hooks),
|
|
348
|
-
$transaction: async <TResult>(
|
|
349
|
-
callback: (transaction: object) => Promise<TResult>,
|
|
350
|
-
options?: { readonly isolationLevel?: string },
|
|
351
|
-
): Promise<TResult> => {
|
|
352
|
-
hooks.transactionOptions.push(options);
|
|
353
|
-
const previous = transactionQueue;
|
|
354
|
-
let release!: () => void;
|
|
355
|
-
transactionQueue = new Promise<void>((resolve) => {
|
|
356
|
-
release = resolve;
|
|
357
|
-
});
|
|
358
|
-
await previous;
|
|
359
|
-
try {
|
|
360
|
-
const transactionTables = structuredClone(tables);
|
|
361
|
-
const result = await callback(createClient(transactionTables, hooks));
|
|
362
|
-
tables.bundle_patches = transactionTables.bundle_patches;
|
|
363
|
-
tables.bundles = transactionTables.bundles;
|
|
364
|
-
tables.bundle_events = transactionTables.bundle_events;
|
|
365
|
-
tables.bundle_installations = transactionTables.bundle_installations;
|
|
366
|
-
tables.channels = transactionTables.channels;
|
|
367
|
-
tables.api_keys = transactionTables.api_keys;
|
|
368
|
-
tables.releases = transactionTables.releases;
|
|
369
|
-
tables.release_catalogs = transactionTables.release_catalogs;
|
|
370
|
-
return result;
|
|
371
|
-
} finally {
|
|
372
|
-
release();
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
};
|
|
376
|
-
return {
|
|
377
|
-
client,
|
|
378
|
-
clearTargetBeforeNextBundleUpdate: (
|
|
379
|
-
id: string,
|
|
380
|
-
field: "fingerprint_hash" | "target_app_version",
|
|
381
|
-
): void => {
|
|
382
|
-
hooks.beforeNextBundleUpdateMany = (transactionTables) => {
|
|
383
|
-
for (const currentTables of new Set([tables, transactionTables])) {
|
|
384
|
-
const index = currentTables.bundles.findIndex(
|
|
385
|
-
(candidate) => "id" in candidate && candidate.id === id,
|
|
386
|
-
);
|
|
387
|
-
const row = currentTables.bundles[index];
|
|
388
|
-
if (row !== undefined && "target_app_version" in row) {
|
|
389
|
-
currentTables.bundles[index] = { ...row, [field]: null };
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
},
|
|
394
|
-
failNextBundleDelete: (): void => {
|
|
395
|
-
hooks.failNextBundleDelete = true;
|
|
396
|
-
},
|
|
397
|
-
getTransactionOptions: () => structuredClone(hooks.transactionOptions),
|
|
398
|
-
reset: (): void => {
|
|
399
|
-
hooks.failNextBundleDelete = false;
|
|
400
|
-
hooks.beforeNextBundleUpdateMany = undefined;
|
|
401
|
-
hooks.transactionOptions.length = 0;
|
|
402
|
-
transactionQueue = Promise.resolve();
|
|
403
|
-
tables.bundle_patches = [];
|
|
404
|
-
tables.bundles = [];
|
|
405
|
-
tables.bundle_events = [];
|
|
406
|
-
tables.bundle_installations = [];
|
|
407
|
-
tables.channels = [];
|
|
408
|
-
tables.api_keys = [];
|
|
409
|
-
tables.releases = [];
|
|
410
|
-
tables.release_catalogs = [];
|
|
411
|
-
},
|
|
412
|
-
};
|
|
413
|
-
};
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { createInMemoryDatabasePlugin } from "../../test-utils/test/inMemoryDatabasePlugin";
|
|
4
|
-
import { registerApiKey } from "./apiKeys";
|
|
5
|
-
import { API_KEY_HEADER_NAME, createHotUpdater } from "./index";
|
|
6
|
-
|
|
7
|
-
const API_KEY = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE";
|
|
8
|
-
const updateUrl =
|
|
9
|
-
"https://example.com/release-catalogs/app-version/ios/" +
|
|
10
|
-
"cHJvZHVjdGlvbg/1.0.0";
|
|
11
|
-
|
|
12
|
-
const withApiKey = (url: string, init?: RequestInit) =>
|
|
13
|
-
new Request(url, {
|
|
14
|
-
...init,
|
|
15
|
-
headers: {
|
|
16
|
-
...Object.fromEntries(new Headers(init?.headers)),
|
|
17
|
-
[API_KEY_HEADER_NAME]: API_KEY,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("createHotUpdater API keys", () => {
|
|
22
|
-
it("rejects an invalid API key header name", () => {
|
|
23
|
-
expect(() =>
|
|
24
|
-
createHotUpdater({
|
|
25
|
-
clientAccess: {
|
|
26
|
-
headerName: "invalid header",
|
|
27
|
-
type: "api-key",
|
|
28
|
-
},
|
|
29
|
-
database: createInMemoryDatabasePlugin(),
|
|
30
|
-
}),
|
|
31
|
-
).toThrow("clientAccess.headerName must be a valid header name.");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("protects only client OTA and Insights write routes", async () => {
|
|
35
|
-
const database = createInMemoryDatabasePlugin();
|
|
36
|
-
await registerApiKey({
|
|
37
|
-
apiKeys: database.models.apiKeys,
|
|
38
|
-
apiKey: API_KEY,
|
|
39
|
-
name: "App",
|
|
40
|
-
});
|
|
41
|
-
const hotUpdater = createHotUpdater({
|
|
42
|
-
clientAccess: { type: "api-key" },
|
|
43
|
-
database,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
expect(
|
|
47
|
-
(await hotUpdater.handlers.client(new Request(updateUrl))).status,
|
|
48
|
-
).toBe(401);
|
|
49
|
-
expect(
|
|
50
|
-
(await hotUpdater.handlers.client(withApiKey(updateUrl))).status,
|
|
51
|
-
).toBe(404);
|
|
52
|
-
expect(
|
|
53
|
-
(
|
|
54
|
-
await hotUpdater.handlers.client(
|
|
55
|
-
new Request("https://example.com/version"),
|
|
56
|
-
)
|
|
57
|
-
).status,
|
|
58
|
-
).toBe(200);
|
|
59
|
-
expect(
|
|
60
|
-
(
|
|
61
|
-
await hotUpdater.handlers.admin(
|
|
62
|
-
withApiKey("https://example.com/events"),
|
|
63
|
-
)
|
|
64
|
-
).status,
|
|
65
|
-
).toBe(200);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("creates, lists, and revokes API keys without exposing hashes", async () => {
|
|
69
|
-
const hotUpdater = createHotUpdater({
|
|
70
|
-
clientAccess: { type: "public" },
|
|
71
|
-
database: createInMemoryDatabasePlugin(),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const created = await hotUpdater.apiKeys.create({ name: "Production" });
|
|
75
|
-
expect(created.apiKey).toMatch(/^[A-Za-z0-9_-]{43}$/u);
|
|
76
|
-
expect(created.record).not.toHaveProperty("hash");
|
|
77
|
-
|
|
78
|
-
await expect(hotUpdater.apiKeys.list()).resolves.toEqual([created.record]);
|
|
79
|
-
const revoked = await hotUpdater.apiKeys.revoke({
|
|
80
|
-
id: created.record.id,
|
|
81
|
-
});
|
|
82
|
-
expect(revoked).toMatchObject({
|
|
83
|
-
id: created.record.id,
|
|
84
|
-
revoked_at_ms: expect.any(Number),
|
|
85
|
-
});
|
|
86
|
-
expect(revoked).not.toHaveProperty("hash");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("authenticates before parsing Insights event bodies", async () => {
|
|
90
|
-
const database = createInMemoryDatabasePlugin();
|
|
91
|
-
await registerApiKey({
|
|
92
|
-
apiKeys: database.models.apiKeys,
|
|
93
|
-
apiKey: API_KEY,
|
|
94
|
-
name: "App",
|
|
95
|
-
});
|
|
96
|
-
const hotUpdater = createHotUpdater({
|
|
97
|
-
clientAccess: { type: "api-key" },
|
|
98
|
-
database,
|
|
99
|
-
});
|
|
100
|
-
const invalidBody = {
|
|
101
|
-
method: "POST",
|
|
102
|
-
headers: { "content-type": "application/json" },
|
|
103
|
-
body: "not-json",
|
|
104
|
-
} satisfies RequestInit;
|
|
105
|
-
|
|
106
|
-
expect(
|
|
107
|
-
(
|
|
108
|
-
await hotUpdater.handlers.client(
|
|
109
|
-
new Request("https://example.com/events", invalidBody),
|
|
110
|
-
)
|
|
111
|
-
).status,
|
|
112
|
-
).toBe(401);
|
|
113
|
-
expect(
|
|
114
|
-
(
|
|
115
|
-
await hotUpdater.handlers.client(
|
|
116
|
-
withApiKey("https://example.com/events", invalidBody),
|
|
117
|
-
)
|
|
118
|
-
).status,
|
|
119
|
-
).toBe(400);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("returns 503 when credential storage is unavailable", async () => {
|
|
123
|
-
const database = createInMemoryDatabasePlugin();
|
|
124
|
-
vi.spyOn(database.models.apiKeys, "findByHash").mockRejectedValue(
|
|
125
|
-
new Error("database offline"),
|
|
126
|
-
);
|
|
127
|
-
const hotUpdater = createHotUpdater({
|
|
128
|
-
clientAccess: { type: "api-key" },
|
|
129
|
-
database,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const response = await hotUpdater.handlers.client(withApiKey(updateUrl));
|
|
133
|
-
|
|
134
|
-
expect(response.status).toBe(503);
|
|
135
|
-
await expect(response.json()).resolves.toEqual({
|
|
136
|
-
error: "Service unavailable",
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("keeps client routes public with the public access policy", async () => {
|
|
141
|
-
const hotUpdater = createHotUpdater({
|
|
142
|
-
clientAccess: { type: "public" },
|
|
143
|
-
database: createInMemoryDatabasePlugin(),
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
expect(
|
|
147
|
-
(await hotUpdater.handlers.client(new Request(updateUrl))).status,
|
|
148
|
-
).toBe(404);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("reads API keys only from the configured header", async () => {
|
|
152
|
-
const database = createInMemoryDatabasePlugin();
|
|
153
|
-
await registerApiKey({
|
|
154
|
-
apiKeys: database.models.apiKeys,
|
|
155
|
-
apiKey: API_KEY,
|
|
156
|
-
name: "App",
|
|
157
|
-
});
|
|
158
|
-
const hotUpdater = createHotUpdater({
|
|
159
|
-
clientAccess: {
|
|
160
|
-
headerName: "X-Hot-Updater-Key",
|
|
161
|
-
type: "api-key",
|
|
162
|
-
},
|
|
163
|
-
database,
|
|
164
|
-
});
|
|
165
|
-
const invalidBody = {
|
|
166
|
-
method: "POST",
|
|
167
|
-
headers: { "content-type": "application/json" },
|
|
168
|
-
body: "not-json",
|
|
169
|
-
} satisfies RequestInit;
|
|
170
|
-
|
|
171
|
-
expect(
|
|
172
|
-
(
|
|
173
|
-
await hotUpdater.handlers.client(
|
|
174
|
-
withApiKey("https://example.com/events", invalidBody),
|
|
175
|
-
)
|
|
176
|
-
).status,
|
|
177
|
-
).toBe(401);
|
|
178
|
-
expect(
|
|
179
|
-
(
|
|
180
|
-
await hotUpdater.handlers.client(
|
|
181
|
-
new Request("https://example.com/events", {
|
|
182
|
-
...invalidBody,
|
|
183
|
-
headers: {
|
|
184
|
-
...invalidBody.headers,
|
|
185
|
-
"x-hot-updater-key": API_KEY,
|
|
186
|
-
},
|
|
187
|
-
}),
|
|
188
|
-
)
|
|
189
|
-
).status,
|
|
190
|
-
).toBe(400);
|
|
191
|
-
});
|
|
192
|
-
});
|