@hot-updater/server 0.36.6 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/databaseConstraintErrors.cjs +23 -0
- package/dist/adapters/databaseConstraintErrors.mjs +21 -0
- package/dist/adapters/databasePluginUtils.cjs +117 -0
- package/dist/adapters/databasePluginUtils.mjs +106 -0
- package/dist/adapters/drizzle.cjs +53 -176
- package/dist/adapters/drizzle.d.cts +6 -4
- package/dist/adapters/drizzle.d.mts +6 -4
- package/dist/adapters/drizzle.mjs +54 -177
- package/dist/adapters/drizzleCrud.cjs +250 -0
- package/dist/adapters/drizzleCrud.mjs +249 -0
- package/dist/adapters/drizzleLazyDB.cjs +84 -36
- package/dist/adapters/drizzleLazyDB.mjs +84 -36
- package/dist/adapters/drizzleQuery.cjs +68 -0
- package/dist/adapters/drizzleQuery.mjs +67 -0
- package/dist/adapters/kysely.cjs +18 -138
- package/dist/adapters/kysely.d.cts +3 -12
- package/dist/adapters/kysely.d.mts +3 -12
- package/dist/adapters/kysely.mjs +19 -139
- package/dist/adapters/kyselyCrud.cjs +254 -0
- package/dist/adapters/kyselyCrud.mjs +253 -0
- package/dist/adapters/kyselyQuery.cjs +56 -0
- package/dist/adapters/kyselyQuery.mjs +55 -0
- package/dist/adapters/mongodb.cjs +21 -174
- package/dist/adapters/mongodb.d.cts +3 -2
- package/dist/adapters/mongodb.d.mts +3 -2
- package/dist/adapters/mongodb.mjs +21 -174
- package/dist/adapters/mongodbCollections.cjs +36 -0
- package/dist/adapters/mongodbCollections.mjs +30 -0
- package/dist/adapters/mongodbQuery.cjs +77 -0
- package/dist/adapters/mongodbQuery.mjs +70 -0
- package/dist/adapters/mongodbReads.cjs +148 -0
- package/dist/adapters/mongodbReads.mjs +147 -0
- package/dist/adapters/mongodbWrites.cjs +134 -0
- package/dist/adapters/mongodbWrites.mjs +133 -0
- package/dist/adapters/prisma.cjs +205 -180
- package/dist/adapters/prisma.d.cts +3 -3
- package/dist/adapters/prisma.d.mts +3 -3
- package/dist/adapters/prisma.mjs +206 -181
- package/dist/adapters/prismaQuery.cjs +58 -0
- package/dist/adapters/prismaQuery.mjs +56 -0
- package/dist/adapters/prismaRows.cjs +198 -0
- package/dist/adapters/prismaRows.mjs +188 -0
- package/dist/analytics/bounded/activeOverview.cjs +87 -0
- package/dist/analytics/bounded/activeOverview.mjs +85 -0
- package/dist/analytics/bounded/installationSearch.cjs +42 -0
- package/dist/analytics/bounded/installationSearch.mjs +42 -0
- package/dist/analytics/bounded/persistence.cjs +39 -0
- package/dist/analytics/bounded/persistence.mjs +38 -0
- package/dist/analytics/bounded/provider.cjs +170 -0
- package/dist/analytics/bounded/provider.d.cts +7 -0
- package/dist/analytics/bounded/provider.d.mts +7 -0
- package/dist/analytics/bounded/provider.mjs +170 -0
- package/dist/analytics/bounded/scan.cjs +144 -0
- package/dist/analytics/bounded/scan.mjs +138 -0
- package/dist/analytics/domain.d.cts +121 -0
- package/dist/analytics/domain.d.mts +121 -0
- package/dist/analytics/errors.cjs +22 -0
- package/dist/analytics/errors.mjs +20 -0
- package/dist/analytics/eventInput.cjs +111 -0
- package/dist/analytics/eventInput.mjs +111 -0
- package/dist/analytics/persistence.d.cts +6 -0
- package/dist/analytics/persistence.d.mts +6 -0
- package/dist/analytics/queryInput.cjs +58 -0
- package/dist/analytics/queryInput.mjs +55 -0
- package/dist/analytics/routes.cjs +63 -0
- package/dist/analytics/routes.mjs +61 -0
- package/dist/analytics/types.d.cts +17 -0
- package/dist/analytics/types.d.mts +17 -0
- package/dist/apiKeys.cjs +139 -0
- package/dist/apiKeys.d.cts +50 -0
- package/dist/apiKeys.d.mts +50 -0
- package/dist/apiKeys.mjs +133 -0
- package/dist/createHotUpdaterCore.cjs +48 -26
- package/dist/createHotUpdaterCore.d.cts +49 -17
- package/dist/createHotUpdaterCore.d.mts +49 -17
- package/dist/createHotUpdaterCore.mjs +51 -29
- package/dist/db/createBundleDiff.cjs +45 -68
- package/dist/db/createBundleDiff.d.cts +3 -3
- package/dist/db/createBundleDiff.d.mts +3 -3
- package/dist/db/createBundleDiff.mjs +47 -68
- package/dist/db/databasePluginCore.cjs +138 -0
- package/dist/db/databasePluginCore.mjs +137 -0
- package/dist/db/fixedMigrator.cjs +36 -93
- package/dist/db/fixedMigrator.mjs +36 -93
- package/dist/db/fixedMigratorMongo.cjs +319 -0
- package/dist/db/fixedMigratorMongo.mjs +319 -0
- package/dist/db/fixedMigratorShared.cjs +23 -0
- package/dist/db/fixedMigratorShared.mjs +18 -0
- package/dist/db/mongoMigrationExecution.cjs +11 -0
- package/dist/db/mongoMigrationExecution.mjs +11 -0
- package/dist/db/releaseCatalog.cjs +66 -0
- package/dist/db/releaseCatalog.d.cts +17 -0
- package/dist/db/releaseCatalog.d.mts +17 -0
- package/dist/db/releaseCatalog.mjs +64 -0
- package/dist/db/schema/mongodb.cjs +14 -6
- package/dist/db/schema/mongodb.mjs +14 -6
- package/dist/db/schema/registry.cjs +0 -2
- package/dist/db/schema/registry.mjs +1 -2
- package/dist/db/schema/sql.cjs +31 -14
- package/dist/db/schema/sql.mjs +32 -13
- package/dist/db/schema/sqlOperations.cjs +4 -4
- package/dist/db/schema/sqlOperations.mjs +5 -5
- package/dist/db/schemaGenerators.cjs +52 -18
- package/dist/db/schemaGenerators.mjs +52 -18
- package/dist/db/schemaReadiness.cjs +4 -3
- package/dist/db/schemaReadiness.mjs +4 -3
- package/dist/db/sqlMigrationExecution.cjs +67 -0
- package/dist/db/sqlMigrationExecution.mjs +66 -0
- package/dist/db/types.cjs +2 -6
- package/dist/db/types.d.cts +60 -16
- package/dist/db/types.d.mts +60 -16
- package/dist/db/types.mjs +3 -6
- package/dist/db/updateArtifacts.cjs +114 -60
- package/dist/db/updateArtifacts.mjs +117 -62
- package/dist/handler.cjs +108 -282
- package/dist/handler.d.cts +3 -46
- package/dist/handler.d.mts +3 -46
- package/dist/handler.mjs +107 -281
- package/dist/handlerBundleRoutes.cjs +155 -0
- package/dist/handlerBundleRoutes.mjs +155 -0
- package/dist/handlerErrors.cjs +9 -0
- package/dist/handlerErrors.mjs +9 -0
- package/dist/handlerParameters.cjs +39 -0
- package/dist/handlerParameters.mjs +34 -0
- package/dist/handlerReleaseCatalogRoutes.cjs +111 -0
- package/dist/handlerReleaseCatalogRoutes.mjs +110 -0
- package/dist/handlerReleaseManagementRoutes.cjs +125 -0
- package/dist/handlerReleaseManagementRoutes.mjs +124 -0
- package/dist/handlerTypes.d.cts +63 -0
- package/dist/handlerTypes.d.mts +63 -0
- package/dist/handlerVersionRoutes.cjs +10 -0
- package/dist/handlerVersionRoutes.d.cts +4 -0
- package/dist/handlerVersionRoutes.d.mts +4 -0
- package/dist/handlerVersionRoutes.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +5 -2
- package/dist/node.cjs +19 -12
- package/dist/node.d.cts +15 -10
- package/dist/node.d.mts +15 -10
- package/dist/node.mjs +19 -13
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/schema/dsl.cjs +19 -2
- package/dist/schema/dsl.mjs +17 -3
- package/dist/schema/index.cjs +1 -8
- package/dist/schema/index.mjs +2 -8
- package/dist/schema/types.cjs +3 -1
- package/dist/schema/types.mjs +3 -2
- package/dist/schema/v1_0_0.cjs +364 -0
- package/dist/schema/v1_0_0.mjs +357 -0
- package/dist/storageAccess.cjs +69 -25
- package/dist/storageAccess.mjs +68 -25
- package/dist/types/index.d.cts +4 -3
- package/dist/types/index.d.mts +5 -4
- package/package.json +8 -7
- package/src/adapters/databaseConstraintErrors.ts +25 -0
- package/src/adapters/databasePluginTestDatabase.ts +106 -0
- package/src/adapters/databasePluginUtils.spec.ts +29 -0
- package/src/adapters/databasePluginUtils.ts +214 -0
- package/src/adapters/drizzle.spec.ts +208 -47
- package/src/adapters/drizzle.ts +106 -293
- package/src/adapters/drizzleCrud.ts +419 -0
- package/src/adapters/drizzleLazyDB.ts +206 -100
- package/src/adapters/drizzleQuery.ts +164 -0
- package/src/adapters/kysely.spec.ts +126 -88
- package/src/adapters/kysely.ts +76 -334
- package/src/adapters/kyselyCrud.ts +588 -0
- package/src/adapters/kyselyQuery.ts +128 -0
- package/src/adapters/mongodb.spec.ts +141 -0
- package/src/adapters/mongodb.ts +60 -288
- package/src/adapters/mongodbCollections.ts +62 -0
- package/src/adapters/mongodbQuery.ts +226 -0
- package/src/adapters/mongodbReads.ts +311 -0
- package/src/adapters/mongodbRows.spec.ts +64 -0
- package/src/adapters/mongodbRows.ts +118 -0
- package/src/adapters/mongodbTestClient.ts +342 -0
- package/src/adapters/mongodbTestFilter.ts +166 -0
- package/src/adapters/mongodbWrites.ts +260 -0
- package/src/adapters/prisma.spec.ts +196 -0
- package/src/adapters/prisma.ts +417 -292
- package/src/adapters/prismaQuery.ts +129 -0
- package/src/adapters/prismaRows.spec.ts +98 -0
- package/src/adapters/prismaRows.ts +301 -0
- package/src/adapters/prismaTestClient.ts +396 -0
- package/src/analytics/analytics.integration.spec.ts +144 -0
- package/src/analytics/bounded/activeOverview.spec.ts +189 -0
- package/src/analytics/bounded/activeOverview.ts +148 -0
- package/src/analytics/bounded/installationSearch.spec.ts +130 -0
- package/src/analytics/bounded/installationSearch.ts +69 -0
- package/src/analytics/bounded/persistence.ts +43 -0
- package/src/analytics/bounded/provider.spec.ts +219 -0
- package/src/analytics/bounded/provider.ts +229 -0
- package/src/analytics/bounded/scan.ts +235 -0
- package/src/analytics/domain.ts +139 -0
- package/src/analytics/errors.ts +18 -0
- package/src/analytics/eventInput.ts +168 -0
- package/src/analytics/persistence.ts +10 -0
- package/src/analytics/queryInput.ts +102 -0
- package/src/analytics/routes.ts +123 -0
- package/src/analytics/types.ts +44 -0
- package/src/apiKeys.integration.spec.ts +192 -0
- package/src/apiKeys.spec.ts +162 -0
- package/src/apiKeys.ts +220 -0
- package/src/createHotUpdaterCore.ts +164 -100
- package/src/db/bundleRows.spec.ts +164 -0
- package/src/db/bundleRows.ts +10 -140
- package/src/db/createBundleDiff.spec.ts +172 -127
- package/src/db/createBundleDiff.ts +91 -110
- package/src/db/databasePluginCore.spec.ts +62 -0
- package/src/db/databasePluginCore.testFixtures.ts +76 -0
- package/src/db/databasePluginCore.ts +185 -0
- package/src/db/databasePluginUpdateCheck.bench.ts +107 -0
- package/src/db/fixedMigrator.spec.ts +184 -42
- package/src/db/fixedMigrator.ts +64 -205
- package/src/db/fixedMigratorMongo.spec.ts +192 -0
- package/src/db/fixedMigratorMongo.ts +425 -0
- package/src/db/fixedMigratorShared.ts +36 -0
- package/src/db/hotUpdaterSchema.ts +0 -1
- package/src/db/index.spec.ts +333 -1025
- package/src/db/mongoMigrationExecution.ts +23 -0
- package/src/db/node-sqlite.d.ts +25 -0
- package/src/db/releaseCatalog.ts +148 -0
- package/src/db/schema/mongodb.ts +20 -6
- package/src/db/schema/sql.ts +52 -11
- package/src/db/schema/sqlOperations.ts +5 -4
- package/src/db/schemaGenerators.ts +107 -23
- package/src/db/schemaReadiness.ts +2 -1
- package/src/db/sqlMigrationExecution.spec.ts +65 -0
- package/src/db/sqlMigrationExecution.ts +108 -0
- package/src/db/types.spec.ts +55 -0
- package/src/db/types.ts +129 -65
- package/src/db/updateArtifacts.spec.ts +359 -0
- package/src/db/updateArtifacts.ts +290 -126
- package/src/handler-standalone.integration.spec.ts +401 -364
- package/src/handler.spec.ts +137 -582
- package/src/handler.testFixtures.ts +30 -0
- package/src/handler.ts +218 -616
- package/src/handlerAuth.integration.spec.ts +33 -0
- package/src/handlerBundleRoutes.ts +259 -0
- package/src/handlerErrors.ts +7 -0
- package/src/handlerManagement.spec.ts +262 -0
- package/src/handlerParameters.ts +105 -0
- package/src/handlerReleaseCatalogRoutes.ts +154 -0
- package/src/handlerReleaseManagementRoutes.ts +213 -0
- package/src/handlerTypes.ts +96 -0
- package/src/handlerVersionRoutes.ts +12 -0
- package/src/index.ts +22 -2
- package/src/node.spec.ts +79 -10
- package/src/node.ts +20 -17
- package/src/releaseCatalogRoutes.integration.spec.ts +238 -0
- package/src/runtime.spec.ts +126 -959
- package/src/runtime.testFixtures.ts +71 -0
- package/src/schema/dsl-all-versions.spec.ts +26 -17
- package/src/schema/dsl.ts +41 -2
- package/src/schema/index.ts +3 -9
- package/src/schema/types.ts +9 -3
- package/src/schema/v1_0_0.spec.ts +146 -0
- package/src/schema/v1_0_0.ts +465 -0
- package/src/storageAccess.spec.ts +127 -32
- package/src/storageAccess.ts +106 -55
- package/src/types/index.ts +2 -1
- package/dist/db/bundleRows.cjs +0 -82
- package/dist/db/bundleRows.d.cts +0 -33
- package/dist/db/bundleRows.d.mts +0 -33
- package/dist/db/bundleRows.mjs +0 -79
- package/dist/db/pluginCore.cjs +0 -242
- package/dist/db/pluginCore.mjs +0 -241
- package/dist/db/schema/sqlMigrations.cjs +0 -74
- package/dist/db/schema/sqlMigrations.mjs +0 -73
- package/dist/db/schemaEnhancements.cjs +0 -20
- package/dist/db/schemaEnhancements.mjs +0 -19
- package/dist/route.cjs +0 -7
- package/dist/route.mjs +0 -7
- package/dist/schema/v0_21_0.cjs +0 -38
- package/dist/schema/v0_21_0.mjs +0 -37
- package/dist/schema/v0_29_0.cjs +0 -45
- package/dist/schema/v0_29_0.mjs +0 -44
- package/dist/schema/v0_31_0.cjs +0 -82
- package/dist/schema/v0_31_0.mjs +0 -80
- package/src/db/pluginCore.spec.ts +0 -1095
- package/src/db/pluginCore.ts +0 -475
- package/src/db/pluginUpdateCheck.bench.ts +0 -254
- package/src/db/schema/sqlMigrations.ts +0 -219
- package/src/db/schemaEnhancements.ts +0 -55
- package/src/route.ts +0 -7
- package/src/schema/v0_21_0.ts +0 -52
- package/src/schema/v0_29_0.ts +0 -62
- package/src/schema/v0_31_0.spec.ts +0 -73
- package/src/schema/v0_31_0.ts +0 -120
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export type CreateBundleEventRequestBase = {
|
|
2
|
+
readonly installId: string;
|
|
3
|
+
readonly toBundleId: string;
|
|
4
|
+
readonly userId?: string;
|
|
5
|
+
readonly username?: string;
|
|
6
|
+
readonly platform: "ios" | "android";
|
|
7
|
+
readonly appVersion: string;
|
|
8
|
+
readonly channel: string;
|
|
9
|
+
readonly cohort: string;
|
|
10
|
+
readonly fingerprintHash: string | null;
|
|
11
|
+
readonly sdkVersion?: string | null;
|
|
12
|
+
readonly fromReleaseId: string | null;
|
|
13
|
+
readonly toReleaseId: string | null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type CreateBundleEventRequest =
|
|
17
|
+
| (CreateBundleEventRequestBase & {
|
|
18
|
+
readonly type: "UPDATE_APPLIED";
|
|
19
|
+
readonly fromBundleId: string;
|
|
20
|
+
readonly updateStrategy: "fingerprint" | "appVersion";
|
|
21
|
+
})
|
|
22
|
+
| (CreateBundleEventRequestBase & {
|
|
23
|
+
readonly type: "RECOVERED";
|
|
24
|
+
readonly fromBundleId: string;
|
|
25
|
+
readonly updateStrategy: "fingerprint" | "appVersion";
|
|
26
|
+
})
|
|
27
|
+
| (CreateBundleEventRequestBase & {
|
|
28
|
+
readonly type: "RELEASE_ADOPTED";
|
|
29
|
+
readonly fromBundleId: string;
|
|
30
|
+
readonly updateStrategy: "fingerprint" | "appVersion";
|
|
31
|
+
})
|
|
32
|
+
| (CreateBundleEventRequestBase & {
|
|
33
|
+
readonly type: "UNCHANGED";
|
|
34
|
+
readonly fromBundleId: null;
|
|
35
|
+
readonly updateStrategy: null;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type BundleEventSummary = {
|
|
39
|
+
readonly installed: number;
|
|
40
|
+
readonly recovered: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type BundleEventSummaryByBundle = BundleEventSummary & {
|
|
44
|
+
readonly bundleId: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type BundleEventAnalyticsWindow = "24h" | "7d" | "30d" | "all";
|
|
48
|
+
export type ActiveInstallationWindow = "24h" | "7d" | "30d";
|
|
49
|
+
|
|
50
|
+
export type InstallationSearchRow = {
|
|
51
|
+
readonly installId: string;
|
|
52
|
+
readonly username: string | null;
|
|
53
|
+
readonly userId: string | null;
|
|
54
|
+
readonly lastKnownBundleId: string;
|
|
55
|
+
readonly latestStatus:
|
|
56
|
+
| "UPDATE_APPLIED"
|
|
57
|
+
| "RECOVERED"
|
|
58
|
+
| "RELEASE_ADOPTED"
|
|
59
|
+
| "UNCHANGED";
|
|
60
|
+
readonly platform: "ios" | "android";
|
|
61
|
+
readonly appVersion: string;
|
|
62
|
+
readonly channel: string;
|
|
63
|
+
readonly cohort: string;
|
|
64
|
+
readonly receivedAtMs: number;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type InstallationHistoryRow = {
|
|
68
|
+
readonly id: string;
|
|
69
|
+
readonly type: "UPDATE_APPLIED" | "RECOVERED";
|
|
70
|
+
readonly fromBundleId: string;
|
|
71
|
+
readonly toBundleId: string;
|
|
72
|
+
readonly username: string | null;
|
|
73
|
+
readonly userId: string | null;
|
|
74
|
+
readonly platform: "ios" | "android";
|
|
75
|
+
readonly appVersion: string;
|
|
76
|
+
readonly channel: string;
|
|
77
|
+
readonly cohort: string;
|
|
78
|
+
readonly receivedAtMs: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type OffsetPaginationResult<TData> = {
|
|
82
|
+
readonly data: readonly TData[];
|
|
83
|
+
readonly pagination: {
|
|
84
|
+
readonly total: number;
|
|
85
|
+
readonly limit: number;
|
|
86
|
+
readonly offset: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type AnalyticsSeriesPoint = {
|
|
91
|
+
readonly bucketStartMs: number;
|
|
92
|
+
readonly value: number;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type AnalyticsCohortPoint = {
|
|
96
|
+
readonly cohort: string;
|
|
97
|
+
readonly value: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export type BundleEventAnalyticsResult = {
|
|
101
|
+
readonly summary: BundleEventSummary;
|
|
102
|
+
readonly series: {
|
|
103
|
+
readonly installed: readonly AnalyticsSeriesPoint[];
|
|
104
|
+
readonly recovered: readonly AnalyticsSeriesPoint[];
|
|
105
|
+
};
|
|
106
|
+
readonly cohorts: {
|
|
107
|
+
readonly installed: readonly AnalyticsCohortPoint[];
|
|
108
|
+
readonly recovered: readonly AnalyticsCohortPoint[];
|
|
109
|
+
};
|
|
110
|
+
readonly recentEvents: OffsetPaginationResult<InstallationHistoryRow>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type BundleEventOverview = {
|
|
114
|
+
readonly trackedInstallations: number;
|
|
115
|
+
readonly bundles: readonly {
|
|
116
|
+
readonly bundleId: string;
|
|
117
|
+
readonly installations: number;
|
|
118
|
+
}[];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type ActiveInstallationOverview = {
|
|
122
|
+
readonly asOfMs: number;
|
|
123
|
+
readonly window: ActiveInstallationWindow;
|
|
124
|
+
readonly activeInstallations: number;
|
|
125
|
+
readonly series: readonly AnalyticsSeriesPoint[];
|
|
126
|
+
readonly bundleSeries: readonly {
|
|
127
|
+
readonly bundleId: string;
|
|
128
|
+
readonly series: readonly AnalyticsSeriesPoint[];
|
|
129
|
+
}[];
|
|
130
|
+
readonly bundles: readonly {
|
|
131
|
+
readonly bundleId: string;
|
|
132
|
+
readonly installations: number;
|
|
133
|
+
}[];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type ActiveInstallationInput = {
|
|
137
|
+
readonly window: ActiveInstallationWindow;
|
|
138
|
+
readonly userId?: string;
|
|
139
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class AnalyticsScanLimitExceededError extends Error {
|
|
2
|
+
constructor(readonly limit: number) {
|
|
3
|
+
super(`Analytics event scan exceeded ${limit} rows.`);
|
|
4
|
+
this.name = "AnalyticsScanLimitExceededError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class AnalyticsBadRequestError extends Error {
|
|
9
|
+
readonly name = "AnalyticsBadRequestError";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class AnalyticsPayloadTooLargeError extends Error {
|
|
13
|
+
readonly name = "AnalyticsPayloadTooLargeError";
|
|
14
|
+
|
|
15
|
+
constructor(readonly maximumBytes: number) {
|
|
16
|
+
super(`Event payload exceeds ${maximumBytes} bytes`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CreateBundleEventRequest,
|
|
3
|
+
CreateBundleEventRequestBase,
|
|
4
|
+
} from "./domain";
|
|
5
|
+
import {
|
|
6
|
+
AnalyticsBadRequestError,
|
|
7
|
+
AnalyticsPayloadTooLargeError,
|
|
8
|
+
} from "./errors";
|
|
9
|
+
|
|
10
|
+
const MAX_EVENT_STRING_LENGTH = 1_024;
|
|
11
|
+
export const EVENT_BODY_MAX_BYTES = 16 * 1_024;
|
|
12
|
+
|
|
13
|
+
const eventKeys = new Set([
|
|
14
|
+
"type",
|
|
15
|
+
"installId",
|
|
16
|
+
"toBundleId",
|
|
17
|
+
"userId",
|
|
18
|
+
"username",
|
|
19
|
+
"platform",
|
|
20
|
+
"appVersion",
|
|
21
|
+
"channel",
|
|
22
|
+
"cohort",
|
|
23
|
+
"fingerprintHash",
|
|
24
|
+
"fromBundleId",
|
|
25
|
+
"fromReleaseId",
|
|
26
|
+
"toReleaseId",
|
|
27
|
+
"updateStrategy",
|
|
28
|
+
"sdkVersion",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function requireStringField(
|
|
36
|
+
payload: Readonly<Record<string, unknown>>,
|
|
37
|
+
key: string,
|
|
38
|
+
): string {
|
|
39
|
+
const value = payload[key];
|
|
40
|
+
if (
|
|
41
|
+
typeof value !== "string" ||
|
|
42
|
+
value.length === 0 ||
|
|
43
|
+
value.length > MAX_EVENT_STRING_LENGTH
|
|
44
|
+
) {
|
|
45
|
+
throw new AnalyticsBadRequestError(`Invalid event field: ${key}`);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function requireNullableStringField(
|
|
51
|
+
payload: Readonly<Record<string, unknown>>,
|
|
52
|
+
key: string,
|
|
53
|
+
): string | null {
|
|
54
|
+
if (payload[key] === null) return null;
|
|
55
|
+
return requireStringField(payload, key);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function readBoundedText(request: Request): Promise<string> {
|
|
59
|
+
const contentLength = request.headers.get("content-length");
|
|
60
|
+
const declaredByteLength = Number(contentLength);
|
|
61
|
+
if (
|
|
62
|
+
contentLength !== null &&
|
|
63
|
+
Number.isSafeInteger(declaredByteLength) &&
|
|
64
|
+
declaredByteLength > EVENT_BODY_MAX_BYTES
|
|
65
|
+
) {
|
|
66
|
+
throw new AnalyticsPayloadTooLargeError(EVENT_BODY_MAX_BYTES);
|
|
67
|
+
}
|
|
68
|
+
if (request.body === null) return "";
|
|
69
|
+
const reader = request.body.getReader();
|
|
70
|
+
const decoder = new TextDecoder();
|
|
71
|
+
let byteLength = 0;
|
|
72
|
+
let text = "";
|
|
73
|
+
while (true) {
|
|
74
|
+
const result = await reader.read();
|
|
75
|
+
if (result.done) break;
|
|
76
|
+
byteLength += result.value.byteLength;
|
|
77
|
+
if (byteLength > EVENT_BODY_MAX_BYTES) {
|
|
78
|
+
await reader.cancel();
|
|
79
|
+
throw new AnalyticsPayloadTooLargeError(EVENT_BODY_MAX_BYTES);
|
|
80
|
+
}
|
|
81
|
+
text += decoder.decode(result.value, { stream: true });
|
|
82
|
+
}
|
|
83
|
+
return text + decoder.decode();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function parseJson(request: Request): Promise<unknown> {
|
|
87
|
+
const text = await readBoundedText(request);
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(text);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof SyntaxError) {
|
|
92
|
+
throw new AnalyticsBadRequestError("Invalid event payload");
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function requireEvent(payload: unknown): CreateBundleEventRequest {
|
|
99
|
+
if (
|
|
100
|
+
!isRecord(payload) ||
|
|
101
|
+
Object.keys(payload).some((key) => !eventKeys.has(key))
|
|
102
|
+
) {
|
|
103
|
+
throw new AnalyticsBadRequestError("Invalid event payload");
|
|
104
|
+
}
|
|
105
|
+
const platform = requireStringField(payload, "platform");
|
|
106
|
+
if (platform !== "ios" && platform !== "android") {
|
|
107
|
+
throw new AnalyticsBadRequestError("Invalid event field: platform");
|
|
108
|
+
}
|
|
109
|
+
const base: CreateBundleEventRequestBase = {
|
|
110
|
+
installId: requireStringField(payload, "installId"),
|
|
111
|
+
toBundleId: requireStringField(payload, "toBundleId"),
|
|
112
|
+
...(payload.userId === undefined
|
|
113
|
+
? {}
|
|
114
|
+
: { userId: requireStringField(payload, "userId") }),
|
|
115
|
+
...(payload.username === undefined
|
|
116
|
+
? {}
|
|
117
|
+
: { username: requireStringField(payload, "username") }),
|
|
118
|
+
platform,
|
|
119
|
+
appVersion: requireStringField(payload, "appVersion"),
|
|
120
|
+
channel: requireStringField(payload, "channel"),
|
|
121
|
+
cohort: requireStringField(payload, "cohort"),
|
|
122
|
+
fingerprintHash: requireNullableStringField(payload, "fingerprintHash"),
|
|
123
|
+
sdkVersion:
|
|
124
|
+
payload.sdkVersion === undefined
|
|
125
|
+
? null
|
|
126
|
+
: requireNullableStringField(payload, "sdkVersion"),
|
|
127
|
+
fromReleaseId: requireNullableStringField(payload, "fromReleaseId"),
|
|
128
|
+
toReleaseId: requireNullableStringField(payload, "toReleaseId"),
|
|
129
|
+
};
|
|
130
|
+
const type = requireStringField(payload, "type");
|
|
131
|
+
switch (type) {
|
|
132
|
+
case "UPDATE_APPLIED":
|
|
133
|
+
case "RECOVERED":
|
|
134
|
+
case "RELEASE_ADOPTED": {
|
|
135
|
+
const updateStrategy = requireStringField(payload, "updateStrategy");
|
|
136
|
+
if (updateStrategy !== "fingerprint" && updateStrategy !== "appVersion") {
|
|
137
|
+
throw new AnalyticsBadRequestError(
|
|
138
|
+
"Invalid event field: updateStrategy",
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
...base,
|
|
143
|
+
type,
|
|
144
|
+
fromBundleId: requireStringField(payload, "fromBundleId"),
|
|
145
|
+
updateStrategy,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
case "UNCHANGED":
|
|
149
|
+
if (payload.fromBundleId !== null || payload.updateStrategy !== null) {
|
|
150
|
+
throw new AnalyticsBadRequestError("Invalid unchanged event shape");
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
...base,
|
|
154
|
+
type,
|
|
155
|
+
fromBundleId: null,
|
|
156
|
+
updateStrategy: null,
|
|
157
|
+
};
|
|
158
|
+
default:
|
|
159
|
+
throw new AnalyticsBadRequestError("Invalid event field: type");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function parseBundleEventRequest(
|
|
164
|
+
request: Request,
|
|
165
|
+
): Promise<CreateBundleEventRequest> {
|
|
166
|
+
const payload = await parseJson(request);
|
|
167
|
+
return requireEvent(payload);
|
|
168
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnalyticsScanCursor,
|
|
3
|
+
AnalyticsScanInput,
|
|
4
|
+
AnalyticsModel,
|
|
5
|
+
BundleEventRow,
|
|
6
|
+
} from "@hot-updater/plugin-core";
|
|
7
|
+
|
|
8
|
+
export type BundleEventPersistenceRow = BundleEventRow;
|
|
9
|
+
export type AnalyticsPersistence = AnalyticsModel;
|
|
10
|
+
export type { AnalyticsScanCursor, AnalyticsScanInput };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ActiveInstallationInput,
|
|
3
|
+
BundleEventAnalyticsWindow,
|
|
4
|
+
} from "./domain";
|
|
5
|
+
import { AnalyticsBadRequestError } from "./errors";
|
|
6
|
+
|
|
7
|
+
type IntegerBounds = {
|
|
8
|
+
readonly defaultValue: number;
|
|
9
|
+
readonly minimum: number;
|
|
10
|
+
readonly maximum?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const EVENT_LIST_BOUNDS = {
|
|
14
|
+
defaultValue: 50,
|
|
15
|
+
maximum: 100,
|
|
16
|
+
minimum: 1,
|
|
17
|
+
} as const satisfies IntegerBounds;
|
|
18
|
+
const EVENT_LIST_OFFSET_BOUNDS = {
|
|
19
|
+
defaultValue: 0,
|
|
20
|
+
minimum: 0,
|
|
21
|
+
} as const satisfies IntegerBounds;
|
|
22
|
+
const MAX_USER_ID_LENGTH = 1_024;
|
|
23
|
+
|
|
24
|
+
export type PaginationInput = {
|
|
25
|
+
readonly limit: number;
|
|
26
|
+
readonly offset: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type AnalyticsQueryInput = PaginationInput & {
|
|
30
|
+
readonly window: BundleEventAnalyticsWindow;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function parseInteger(url: URL, key: string, bounds: IntegerBounds): number {
|
|
34
|
+
const value = url.searchParams.get(key);
|
|
35
|
+
if (value === null) return bounds.defaultValue;
|
|
36
|
+
const parsed = Number(value);
|
|
37
|
+
if (
|
|
38
|
+
!Number.isSafeInteger(parsed) ||
|
|
39
|
+
parsed < bounds.minimum ||
|
|
40
|
+
(bounds.maximum !== undefined && parsed > bounds.maximum)
|
|
41
|
+
) {
|
|
42
|
+
throw new AnalyticsBadRequestError(`Invalid '${key}' query parameter.`);
|
|
43
|
+
}
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const parsePagination = (request: Request): PaginationInput => {
|
|
48
|
+
const url = new URL(request.url);
|
|
49
|
+
return {
|
|
50
|
+
limit: parseInteger(url, "limit", EVENT_LIST_BOUNDS),
|
|
51
|
+
offset: parseInteger(url, "offset", EVENT_LIST_OFFSET_BOUNDS),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const parseAnalyticsQuery = (request: Request): AnalyticsQueryInput => {
|
|
56
|
+
const url = new URL(request.url);
|
|
57
|
+
const window = url.searchParams.get("window") ?? "24h";
|
|
58
|
+
if (
|
|
59
|
+
window !== "24h" &&
|
|
60
|
+
window !== "7d" &&
|
|
61
|
+
window !== "30d" &&
|
|
62
|
+
window !== "all"
|
|
63
|
+
) {
|
|
64
|
+
throw new AnalyticsBadRequestError("Invalid 'window' query parameter.");
|
|
65
|
+
}
|
|
66
|
+
return { ...parsePagination(request), window };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const parseActiveInstallationInput = (
|
|
70
|
+
request: Request,
|
|
71
|
+
): ActiveInstallationInput => {
|
|
72
|
+
const url = new URL(request.url);
|
|
73
|
+
const windows = url.searchParams.getAll("window");
|
|
74
|
+
if (windows.length > 1) {
|
|
75
|
+
throw new AnalyticsBadRequestError("Duplicate 'window' query parameter.");
|
|
76
|
+
}
|
|
77
|
+
const window = windows[0] ?? "30d";
|
|
78
|
+
if (window !== "24h" && window !== "7d" && window !== "30d") {
|
|
79
|
+
throw new AnalyticsBadRequestError("Invalid 'window' query parameter.");
|
|
80
|
+
}
|
|
81
|
+
const userIds = url.searchParams.getAll("userId");
|
|
82
|
+
if (userIds.length > 1) {
|
|
83
|
+
throw new AnalyticsBadRequestError("Duplicate 'userId' query parameter.");
|
|
84
|
+
}
|
|
85
|
+
const userId = userIds[0];
|
|
86
|
+
if (
|
|
87
|
+
userId !== undefined &&
|
|
88
|
+
(userId.length === 0 || userId.length > MAX_USER_ID_LENGTH)
|
|
89
|
+
) {
|
|
90
|
+
throw new AnalyticsBadRequestError("Invalid 'userId' query parameter.");
|
|
91
|
+
}
|
|
92
|
+
return userId === undefined ? { window } : { window, userId };
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const parseSearchInput = (
|
|
96
|
+
request: Request,
|
|
97
|
+
): PaginationInput & { readonly query: string } => ({
|
|
98
|
+
...parsePagination(request),
|
|
99
|
+
query: new URL(request.url).searchParams.get("query")?.trim() ?? "",
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export const parseEmptyInput = (): undefined => undefined;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { RouteHandler } from "../handlerTypes";
|
|
2
|
+
import {
|
|
3
|
+
AnalyticsBadRequestError,
|
|
4
|
+
AnalyticsPayloadTooLargeError,
|
|
5
|
+
AnalyticsScanLimitExceededError,
|
|
6
|
+
} from "./errors";
|
|
7
|
+
import { parseBundleEventRequest } from "./eventInput";
|
|
8
|
+
import {
|
|
9
|
+
parseActiveInstallationInput,
|
|
10
|
+
parseAnalyticsQuery,
|
|
11
|
+
parsePagination,
|
|
12
|
+
parseSearchInput,
|
|
13
|
+
} from "./queryInput";
|
|
14
|
+
import type { AnalyticsProvider } from "./types";
|
|
15
|
+
|
|
16
|
+
const json = (body: unknown, status: number): Response =>
|
|
17
|
+
Response.json(body, {
|
|
18
|
+
headers: { "cache-control": "private, no-store" },
|
|
19
|
+
status,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const requireParam = (
|
|
23
|
+
params: Readonly<Record<string, string>>,
|
|
24
|
+
key: string,
|
|
25
|
+
): string => {
|
|
26
|
+
const value = params[key];
|
|
27
|
+
if (value === undefined || value.length === 0) {
|
|
28
|
+
throw new AnalyticsBadRequestError(`Missing route parameter: ${key}`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const run = async (operation: () => Promise<Response>): Promise<Response> => {
|
|
34
|
+
try {
|
|
35
|
+
return await operation();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error instanceof AnalyticsBadRequestError) {
|
|
38
|
+
return json({ error: error.message }, 400);
|
|
39
|
+
}
|
|
40
|
+
if (error instanceof AnalyticsPayloadTooLargeError) {
|
|
41
|
+
return json({ error: error.message }, 413);
|
|
42
|
+
}
|
|
43
|
+
if (error instanceof AnalyticsScanLimitExceededError) {
|
|
44
|
+
return json(
|
|
45
|
+
{
|
|
46
|
+
error: {
|
|
47
|
+
code: "ANALYTICS_SCAN_LIMIT_EXCEEDED",
|
|
48
|
+
limit: error.limit,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
503,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const query = (operation: () => Promise<unknown>): Promise<Response> =>
|
|
59
|
+
run(async () => json(await operation(), 200));
|
|
60
|
+
|
|
61
|
+
export const createAnalyticsRouteHandlers = (
|
|
62
|
+
provider: AnalyticsProvider,
|
|
63
|
+
): Record<string, RouteHandler> => ({
|
|
64
|
+
appendBundleEvent: async (_params, request) =>
|
|
65
|
+
run(async () => {
|
|
66
|
+
await provider.appendBundleEvent(await parseBundleEventRequest(request));
|
|
67
|
+
return new Response(null, { status: 204 });
|
|
68
|
+
}),
|
|
69
|
+
getBundleEventSummary: (params) =>
|
|
70
|
+
query(() => provider.getBundleEventSummary(requireParam(params, "id"))),
|
|
71
|
+
getBundleEventAnalytics: (params, request) =>
|
|
72
|
+
query(() => {
|
|
73
|
+
const input = parseAnalyticsQuery(request);
|
|
74
|
+
return provider.getBundleEventAnalytics(
|
|
75
|
+
requireParam(params, "id"),
|
|
76
|
+
input.window,
|
|
77
|
+
input.limit,
|
|
78
|
+
input.offset,
|
|
79
|
+
);
|
|
80
|
+
}),
|
|
81
|
+
getBundleEventOverview: () => query(() => provider.getBundleEventOverview()),
|
|
82
|
+
getActiveInstallationOverview: (_params, request) =>
|
|
83
|
+
query(() =>
|
|
84
|
+
provider.getActiveInstallationOverview(
|
|
85
|
+
parseActiveInstallationInput(request),
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
searchInstallations: (_params, request) =>
|
|
89
|
+
query(() => {
|
|
90
|
+
const input = parseSearchInput(request);
|
|
91
|
+
return provider.searchInstallations(
|
|
92
|
+
input.query,
|
|
93
|
+
input.limit,
|
|
94
|
+
input.offset,
|
|
95
|
+
);
|
|
96
|
+
}),
|
|
97
|
+
getInstallationHistory: (params, request) =>
|
|
98
|
+
query(() => {
|
|
99
|
+
const input = parsePagination(request);
|
|
100
|
+
return provider.getInstallationHistory(
|
|
101
|
+
requireParam(params, "installId"),
|
|
102
|
+
input.limit,
|
|
103
|
+
input.offset,
|
|
104
|
+
);
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export const registerAnalyticsClientRoutes = (
|
|
109
|
+
add: (method: string, path: string, handler: string) => void,
|
|
110
|
+
): void => {
|
|
111
|
+
add("POST", "/events", "appendBundleEvent");
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const registerAnalyticsAdminRoutes = (
|
|
115
|
+
add: (method: string, path: string, handler: string) => void,
|
|
116
|
+
): void => {
|
|
117
|
+
add("GET", "/bundles/:id/events/summary", "getBundleEventSummary");
|
|
118
|
+
add("GET", "/bundles/:id/events/analytics", "getBundleEventAnalytics");
|
|
119
|
+
add("GET", "/installations/overview", "getBundleEventOverview");
|
|
120
|
+
add("GET", "/installations/active", "getActiveInstallationOverview");
|
|
121
|
+
add("GET", "/installations", "searchInstallations");
|
|
122
|
+
add("GET", "/installations/:installId/events", "getInstallationHistory");
|
|
123
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ActiveInstallationInput,
|
|
3
|
+
ActiveInstallationOverview,
|
|
4
|
+
BundleEventAnalyticsResult,
|
|
5
|
+
BundleEventAnalyticsWindow,
|
|
6
|
+
BundleEventOverview,
|
|
7
|
+
BundleEventSummary,
|
|
8
|
+
BundleEventSummaryByBundle,
|
|
9
|
+
CreateBundleEventRequest,
|
|
10
|
+
InstallationHistoryRow,
|
|
11
|
+
InstallationSearchRow,
|
|
12
|
+
OffsetPaginationResult,
|
|
13
|
+
} from "./domain";
|
|
14
|
+
|
|
15
|
+
export type AnalyticsProvider = {
|
|
16
|
+
readonly mode: "bounded";
|
|
17
|
+
readonly maxMatchingRows: number;
|
|
18
|
+
appendBundleEvent(input: CreateBundleEventRequest): Promise<void>;
|
|
19
|
+
getBundleEventSummary(bundleId: string): Promise<BundleEventSummary>;
|
|
20
|
+
getBundleEventSummaries(
|
|
21
|
+
bundleIds: readonly string[],
|
|
22
|
+
window: BundleEventAnalyticsWindow,
|
|
23
|
+
): Promise<readonly BundleEventSummaryByBundle[]>;
|
|
24
|
+
getBundleEventAnalytics(
|
|
25
|
+
bundleId: string,
|
|
26
|
+
window: BundleEventAnalyticsWindow,
|
|
27
|
+
limit: number,
|
|
28
|
+
offset: number,
|
|
29
|
+
): Promise<BundleEventAnalyticsResult>;
|
|
30
|
+
getBundleEventOverview(): Promise<BundleEventOverview>;
|
|
31
|
+
getActiveInstallationOverview(
|
|
32
|
+
input: ActiveInstallationInput,
|
|
33
|
+
): Promise<ActiveInstallationOverview>;
|
|
34
|
+
searchInstallations(
|
|
35
|
+
query: string,
|
|
36
|
+
limit: number,
|
|
37
|
+
offset: number,
|
|
38
|
+
): Promise<OffsetPaginationResult<InstallationSearchRow>>;
|
|
39
|
+
getInstallationHistory(
|
|
40
|
+
installId: string,
|
|
41
|
+
limit: number,
|
|
42
|
+
offset: number,
|
|
43
|
+
): Promise<OffsetPaginationResult<InstallationHistoryRow>>;
|
|
44
|
+
};
|