@hot-updater/server 1.0.0-rc.1 → 1.0.0-rc.14
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/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/adapters/databaseConstraintErrors.cjs +0 -1
- package/dist/adapters/databasePluginUtils.cjs +14 -1
- package/dist/adapters/databasePluginUtils.mjs +14 -2
- package/dist/adapters/drizzle.cjs +8 -3
- package/dist/adapters/drizzle.d.cts +0 -1
- package/dist/adapters/drizzle.d.mts +0 -1
- package/dist/adapters/drizzle.mjs +9 -3
- package/dist/adapters/drizzleCrud.cjs +93 -3
- package/dist/adapters/drizzleCrud.mjs +93 -5
- package/dist/adapters/drizzleLazyDB.cjs +2 -0
- package/dist/adapters/drizzleLazyDB.mjs +2 -0
- package/dist/adapters/drizzleQuery.cjs +3 -2
- package/dist/adapters/drizzleQuery.mjs +3 -1
- package/dist/adapters/kysely.cjs +1 -1
- package/dist/adapters/kysely.d.cts +0 -1
- package/dist/adapters/kysely.d.mts +0 -1
- package/dist/adapters/kysely.mjs +2 -1
- package/dist/adapters/kyselyCrud.cjs +44 -5
- package/dist/adapters/kyselyCrud.mjs +45 -6
- package/dist/adapters/kyselyQuery.cjs +2 -2
- package/dist/adapters/kyselyQuery.mjs +2 -1
- package/dist/adapters/mongodb.cjs +36 -1
- package/dist/adapters/mongodb.d.cts +1 -1
- package/dist/adapters/mongodb.d.mts +1 -1
- package/dist/adapters/mongodb.mjs +36 -0
- package/dist/adapters/mongodbCollections.cjs +2 -0
- package/dist/adapters/mongodbCollections.mjs +2 -0
- package/dist/adapters/mongodbQuery.cjs +17 -4
- package/dist/adapters/mongodbQuery.mjs +17 -4
- package/dist/adapters/mongodbReads.cjs +88 -30
- package/dist/adapters/mongodbReads.mjs +88 -29
- package/dist/adapters/mongodbWrites.cjs +1 -2
- package/dist/adapters/mongodbWrites.mjs +1 -1
- package/dist/adapters/prisma.cjs +44 -7
- package/dist/adapters/prisma.d.cts +0 -1
- package/dist/adapters/prisma.d.mts +0 -1
- package/dist/adapters/prisma.mjs +44 -6
- package/dist/adapters/prismaInsights.cjs +99 -0
- package/dist/adapters/prismaInsights.mjs +97 -0
- package/dist/adapters/prismaQuery.cjs +0 -1
- package/dist/adapters/prismaRows.cjs +7 -8
- package/dist/adapters/prismaRows.mjs +8 -8
- package/dist/apiKeys.cjs +6 -2
- package/dist/apiKeys.d.cts +0 -1
- package/dist/apiKeys.d.mts +0 -1
- package/dist/apiKeys.mjs +3 -3
- package/dist/createHotUpdaterCore.cjs +24 -9
- package/dist/createHotUpdaterCore.d.cts +1 -1
- package/dist/createHotUpdaterCore.d.mts +1 -1
- package/dist/createHotUpdaterCore.mjs +23 -9
- package/dist/db/createBundleDiff.cjs +2 -2
- package/dist/db/createBundleDiff.d.cts +1 -5
- package/dist/db/createBundleDiff.d.mts +1 -5
- package/dist/db/databasePluginCore.cjs +0 -1
- package/dist/db/fixedMigrator.cjs +2 -2
- package/dist/db/fixedMigrator.mjs +2 -2
- package/dist/db/fixedMigratorMongo.cjs +6 -4
- package/dist/db/fixedMigratorMongo.mjs +6 -4
- package/dist/db/index.d.cts +0 -1
- package/dist/db/index.d.mts +0 -1
- package/dist/db/releaseCatalog.cjs +0 -1
- package/dist/db/releaseCatalog.d.cts +0 -1
- package/dist/db/releaseCatalog.d.mts +0 -1
- package/dist/db/schema/insightsCollation.cjs +14 -0
- package/dist/db/schema/insightsCollation.mjs +14 -0
- package/dist/db/schema/sql.cjs +11 -7
- package/dist/db/schema/sql.mjs +8 -8
- package/dist/db/schemaGenerators.cjs +29 -9
- package/dist/db/schemaGenerators.mjs +29 -9
- package/dist/db/schemaReadiness.cjs +2 -0
- package/dist/db/schemaReadiness.d.cts +1 -0
- package/dist/db/schemaReadiness.d.mts +1 -0
- package/dist/db/schemaReadiness.mjs +2 -0
- package/dist/db/sqlMigrationExecution.cjs +1 -1
- package/dist/db/sqlMigrationExecution.mjs +1 -0
- package/dist/db/types.cjs +3 -1
- package/dist/db/types.d.cts +3 -6
- package/dist/db/types.d.mts +3 -6
- package/dist/db/types.mjs +2 -2
- package/dist/db/updateArtifacts.cjs +0 -1
- package/dist/handler.d.cts +1 -2
- package/dist/handler.d.mts +1 -2
- package/dist/handlerReleaseCatalogRoutes.cjs +0 -1
- package/dist/handlerReleaseManagementRoutes.cjs +0 -1
- package/dist/handlerTypes.d.cts +0 -1
- package/dist/handlerTypes.d.mts +0 -1
- package/dist/handlerVersionRoutes.d.cts +1 -0
- package/dist/handlerVersionRoutes.d.mts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/insights/domain.d.cts +41 -70
- package/dist/insights/domain.d.mts +41 -70
- package/dist/insights/errors.cjs +1 -8
- package/dist/insights/errors.mjs +2 -8
- package/dist/insights/eventInput.cjs +52 -7
- package/dist/insights/eventInput.mjs +51 -8
- package/dist/insights/provider.cjs +332 -0
- package/dist/insights/provider.d.cts +6 -0
- package/dist/insights/provider.d.mts +6 -0
- package/dist/insights/provider.mjs +332 -0
- package/dist/insights/queryInput.cjs +78 -43
- package/dist/insights/queryInput.mjs +76 -40
- package/dist/insights/routes.cjs +20 -25
- package/dist/insights/routes.mjs +22 -27
- package/dist/insights/types.d.cts +27 -12
- package/dist/insights/types.d.mts +27 -12
- package/dist/node.d.cts +0 -1
- package/dist/node.d.mts +0 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/schema/index.cjs +17 -3
- package/dist/schema/index.mjs +4 -4
- package/dist/schema/v1_0_0.cjs +64 -35
- package/dist/schema/v1_0_0.mjs +64 -36
- package/dist/storageAccess.cjs +0 -1
- package/dist/types/index.d.cts +0 -1
- package/dist/types/index.d.mts +0 -1
- package/package.json +7 -7
- package/src/adapters/databasePluginTestDatabase.ts +15 -5
- package/src/adapters/databasePluginUtils.ts +24 -0
- package/src/adapters/drizzle.spec.ts +203 -5
- package/src/adapters/drizzle.ts +15 -3
- package/src/adapters/drizzleCrud.ts +200 -9
- package/src/adapters/drizzleLazyDB.ts +33 -6
- package/src/adapters/kysely.spec.ts +62 -0
- package/src/adapters/kysely.ts +7 -1
- package/src/adapters/kyselyCrud.ts +115 -7
- package/src/adapters/kyselyInsights.spec.ts +168 -0
- package/src/adapters/mongodb.integration.spec.ts +483 -0
- package/src/adapters/mongodb.spec.ts +89 -0
- package/src/adapters/mongodb.ts +59 -1
- package/src/adapters/mongodbCollections.ts +16 -0
- package/src/adapters/mongodbQuery.ts +22 -3
- package/src/adapters/mongodbReads.ts +78 -2
- package/src/adapters/mongodbTestClient.ts +107 -6
- package/src/adapters/mongodbTestFilter.ts +5 -1
- package/src/adapters/mongodbWrites.ts +1 -0
- package/src/adapters/prisma.spec.ts +270 -0
- package/src/adapters/prisma.ts +75 -2
- package/src/adapters/prismaInsights.ts +190 -0
- package/src/adapters/prismaRows.ts +17 -10
- package/src/adapters/prismaTestClient.ts +89 -7
- package/src/apiKeys.integration.spec.ts +1 -1
- package/src/createHotUpdaterCore.ts +21 -7
- package/src/db/databasePluginUpdateCheck.bench.ts +10 -0
- package/src/db/fixedMigrator.spec.ts +63 -0
- package/src/db/fixedMigratorMongo.spec.ts +70 -9
- package/src/db/fixedMigratorMongo.ts +10 -10
- package/src/db/index.spec.ts +6 -1
- package/src/db/schema/insightsCollation.ts +21 -0
- package/src/db/schema/sql.ts +8 -5
- package/src/db/schemaGenerators.ts +42 -13
- package/src/db/types.spec.ts +8 -0
- package/src/db/types.ts +10 -4
- package/src/handler-standalone.integration.spec.ts +5 -7
- package/src/index.ts +2 -2
- package/src/insights/domain.ts +44 -77
- package/src/insights/errors.ts +0 -7
- package/src/insights/eventInput.ts +55 -5
- package/src/insights/insights.integration.spec.ts +348 -17
- package/src/insights/provider.spec.ts +396 -0
- package/src/insights/provider.ts +611 -0
- package/src/insights/queryInput.ts +113 -73
- package/src/insights/routes.ts +37 -56
- package/src/insights/types.ts +47 -36
- package/src/schema/dsl-all-versions.spec.ts +1 -1
- package/src/schema/v1_0_0.spec.ts +77 -3
- package/src/schema/v1_0_0.ts +83 -37
- package/dist/insights/bounded/activeOverview.cjs +0 -87
- package/dist/insights/bounded/activeOverview.mjs +0 -85
- package/dist/insights/bounded/installationSearch.cjs +0 -42
- package/dist/insights/bounded/installationSearch.mjs +0 -42
- package/dist/insights/bounded/persistence.cjs +0 -39
- package/dist/insights/bounded/persistence.mjs +0 -38
- package/dist/insights/bounded/provider.cjs +0 -170
- package/dist/insights/bounded/provider.d.cts +0 -7
- package/dist/insights/bounded/provider.d.mts +0 -7
- package/dist/insights/bounded/provider.mjs +0 -170
- package/dist/insights/bounded/scan.cjs +0 -144
- package/dist/insights/bounded/scan.mjs +0 -138
- package/dist/insights/persistence.d.cts +0 -6
- package/dist/insights/persistence.d.mts +0 -6
- package/src/insights/bounded/activeOverview.spec.ts +0 -189
- package/src/insights/bounded/activeOverview.ts +0 -148
- package/src/insights/bounded/installationSearch.spec.ts +0 -130
- package/src/insights/bounded/installationSearch.ts +0 -69
- package/src/insights/bounded/persistence.ts +0 -43
- package/src/insights/bounded/provider.spec.ts +0 -219
- package/src/insights/bounded/provider.ts +0 -229
- package/src/insights/bounded/scan.ts +0 -235
- package/src/insights/persistence.ts +0 -10
|
@@ -7,11 +7,13 @@ import {
|
|
|
7
7
|
type HotUpdaterTableSchema,
|
|
8
8
|
type HotUpdaterVersionedSchema,
|
|
9
9
|
} from "../schema/types";
|
|
10
|
+
import { getInsightsCollationSql } from "./schema/insightsCollation";
|
|
10
11
|
import {
|
|
11
12
|
getHotUpdaterSchemaVersion,
|
|
12
13
|
hotUpdaterSchema,
|
|
13
14
|
schemaIndexAppliesToProvider,
|
|
14
15
|
} from "./schema/registry";
|
|
16
|
+
import { getSqlType } from "./schema/sql";
|
|
15
17
|
import type { ORMProvider, ORMSQLProvider, SchemaGenerator } from "./types";
|
|
16
18
|
import { getSQLProvider } from "./types";
|
|
17
19
|
|
|
@@ -28,6 +30,7 @@ const toPascalCase = (value: string): string =>
|
|
|
28
30
|
.join("");
|
|
29
31
|
|
|
30
32
|
const prismaDb = (type: HotUpdaterColumnType, provider: ORMProvider) => {
|
|
33
|
+
if (provider === "cockroachdb" && type === "uuid") return " @db.Uuid";
|
|
31
34
|
if (provider === "postgresql") {
|
|
32
35
|
if (type === "uuid") return " @db.Uuid";
|
|
33
36
|
if (type.startsWith("varchar")) {
|
|
@@ -154,19 +157,33 @@ const prismaIndexes = (
|
|
|
154
157
|
export const generatePrismaSchema = (
|
|
155
158
|
provider: ORMProvider,
|
|
156
159
|
schema: HotUpdaterVersionedSchema = hotUpdaterSchema,
|
|
157
|
-
) =>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
.join("\n")
|
|
168
|
-
|
|
169
|
-
|
|
160
|
+
) => {
|
|
161
|
+
const sqlProvider = getSQLProvider(provider);
|
|
162
|
+
const collationSql = sqlProvider ? getInsightsCollationSql(sqlProvider) : [];
|
|
163
|
+
const header =
|
|
164
|
+
collationSql.length === 0
|
|
165
|
+
? ""
|
|
166
|
+
: [
|
|
167
|
+
"// Apply these statements in the initial Prisma SQL migration to preserve exact Insights identities and cursors:",
|
|
168
|
+
...collationSql.map((statement) => `// ${statement};`),
|
|
169
|
+
"",
|
|
170
|
+
].join("\n");
|
|
171
|
+
return (
|
|
172
|
+
header +
|
|
173
|
+
schema.tables
|
|
174
|
+
.map((table) => {
|
|
175
|
+
const lines = [
|
|
176
|
+
...table.columns.map((column) => prismaField(column, provider)),
|
|
177
|
+
...prismaRelationFields(table, schema),
|
|
178
|
+
...prismaIndexes(table, provider),
|
|
179
|
+
];
|
|
180
|
+
return `model ${table.ormName} {\n${lines
|
|
181
|
+
.map((line) => ` ${line}`)
|
|
182
|
+
.join("\n")}\n}`;
|
|
183
|
+
})
|
|
184
|
+
.join("\n\n")
|
|
185
|
+
);
|
|
186
|
+
};
|
|
170
187
|
|
|
171
188
|
const drizzleImportSource = (provider: ORMSQLProvider) =>
|
|
172
189
|
provider === "sqlite"
|
|
@@ -186,6 +203,18 @@ const drizzleColumnFn = (
|
|
|
186
203
|
column: HotUpdaterColumnSchema,
|
|
187
204
|
provider: ORMSQLProvider,
|
|
188
205
|
): { code: string; imports: readonly string[] } => {
|
|
206
|
+
const collation = column.providerCollations?.[provider];
|
|
207
|
+
if (collation !== undefined) {
|
|
208
|
+
const charset =
|
|
209
|
+
provider === "mysql"
|
|
210
|
+
? ` character set ${collation === "ascii_bin" ? "ascii" : "utf8mb4"}`
|
|
211
|
+
: "";
|
|
212
|
+
const dataType = `${getSqlType(column.type, provider)}${charset} collate ${collation}`;
|
|
213
|
+
return {
|
|
214
|
+
code: `customType<{ data: string }>({ dataType: () => ${literal(dataType)} })(${literal(column.ormName)})`,
|
|
215
|
+
imports: ["customType"],
|
|
216
|
+
};
|
|
217
|
+
}
|
|
189
218
|
if (provider === "sqlite") {
|
|
190
219
|
if (column.type === "bool") {
|
|
191
220
|
return {
|
package/src/db/types.spec.ts
CHANGED
|
@@ -26,6 +26,13 @@ describe("isDatabasePlugin", () => {
|
|
|
26
26
|
...plugin,
|
|
27
27
|
models: { ...plugin.models, insights: undefined },
|
|
28
28
|
};
|
|
29
|
+
const malformedInsights = {
|
|
30
|
+
...plugin,
|
|
31
|
+
models: {
|
|
32
|
+
...plugin.models,
|
|
33
|
+
insights: { ...plugin.models.insights, listEvents: null },
|
|
34
|
+
},
|
|
35
|
+
};
|
|
29
36
|
const malformedChannels = {
|
|
30
37
|
...plugin,
|
|
31
38
|
models: {
|
|
@@ -48,6 +55,7 @@ describe("isDatabasePlugin", () => {
|
|
|
48
55
|
expect(isDatabasePlugin(factory)).toBe(false);
|
|
49
56
|
expect(isDatabasePlugin(malformedBundles)).toBe(false);
|
|
50
57
|
expect(isDatabasePlugin(missingInsights)).toBe(false);
|
|
58
|
+
expect(isDatabasePlugin(malformedInsights)).toBe(false);
|
|
51
59
|
expect(isDatabasePlugin(malformedChannels)).toBe(false);
|
|
52
60
|
expect(isDatabasePlugin(malformedApiKeys)).toBe(false);
|
|
53
61
|
expect(isDatabasePlugin(malformedDispose)).toBe(false);
|
package/src/db/types.ts
CHANGED
|
@@ -126,10 +126,16 @@ export function isDatabasePlugin(plugin: unknown): plugin is DatabasePlugin {
|
|
|
126
126
|
"insights" in plugin.models &&
|
|
127
127
|
typeof plugin.models.insights === "object" &&
|
|
128
128
|
plugin.models.insights !== null &&
|
|
129
|
-
"
|
|
130
|
-
typeof plugin.models.insights.
|
|
131
|
-
"
|
|
132
|
-
typeof plugin.models.insights.
|
|
129
|
+
"recordEvent" in plugin.models.insights &&
|
|
130
|
+
typeof plugin.models.insights.recordEvent === "function" &&
|
|
131
|
+
"listEvents" in plugin.models.insights &&
|
|
132
|
+
typeof plugin.models.insights.listEvents === "function" &&
|
|
133
|
+
"findLatestEvents" in plugin.models.insights &&
|
|
134
|
+
typeof plugin.models.insights.findLatestEvents === "function" &&
|
|
135
|
+
"countEvents" in plugin.models.insights &&
|
|
136
|
+
typeof plugin.models.insights.countEvents === "function" &&
|
|
137
|
+
"countLatestEvents" in plugin.models.insights &&
|
|
138
|
+
typeof plugin.models.insights.countLatestEvents === "function" &&
|
|
133
139
|
"apiKeys" in plugin.models &&
|
|
134
140
|
typeof plugin.models.apiKeys === "object" &&
|
|
135
141
|
plugin.models.apiKeys !== null &&
|
|
@@ -186,15 +186,13 @@ describe("Handler <-> Standalone Repository Integration", () => {
|
|
|
186
186
|
}),
|
|
187
187
|
}),
|
|
188
188
|
);
|
|
189
|
-
const
|
|
190
|
-
new Request(`${baseUrl}/installations/overview`),
|
|
191
|
-
);
|
|
189
|
+
const events = await api.handlers.admin(new Request(`${baseUrl}/events`));
|
|
192
190
|
|
|
193
191
|
expect(ingestion.status).toBe(204);
|
|
194
|
-
expect(
|
|
195
|
-
await expect(
|
|
196
|
-
|
|
197
|
-
|
|
192
|
+
expect(events.status).toBe(200);
|
|
193
|
+
await expect(events.json()).resolves.toMatchObject({
|
|
194
|
+
data: [{ installId, toBundleId: bundleId, type: "UPDATE_APPLIED" }],
|
|
195
|
+
nextCursor: null,
|
|
198
196
|
});
|
|
199
197
|
});
|
|
200
198
|
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,9 @@ export type {
|
|
|
4
4
|
HotUpdaterHandler,
|
|
5
5
|
HotUpdaterHandlers,
|
|
6
6
|
} from "./handler";
|
|
7
|
-
export { createInsightsProvider } from "./insights/
|
|
7
|
+
export { createInsightsProvider } from "./insights/provider";
|
|
8
8
|
export type * from "./insights/domain";
|
|
9
|
-
export type
|
|
9
|
+
export type * from "./insights/types";
|
|
10
10
|
export {
|
|
11
11
|
API_KEY_HEADER_NAME,
|
|
12
12
|
createApiKey,
|
package/src/insights/domain.ts
CHANGED
|
@@ -15,17 +15,7 @@ export type CreateBundleEventRequestBase = {
|
|
|
15
15
|
|
|
16
16
|
export type CreateBundleEventRequest =
|
|
17
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";
|
|
18
|
+
readonly type: "UPDATE_DOWNLOADED" | "UPDATE_APPLIED" | "RECOVERED";
|
|
29
19
|
readonly fromBundleId: string;
|
|
30
20
|
readonly updateStrategy: "fingerprint" | "appVersion";
|
|
31
21
|
})
|
|
@@ -35,28 +25,20 @@ export type CreateBundleEventRequest =
|
|
|
35
25
|
readonly updateStrategy: null;
|
|
36
26
|
});
|
|
37
27
|
|
|
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 BundleEventInsightsWindow = "24h" | "7d" | "30d" | "all";
|
|
48
28
|
export type ActiveInstallationWindow = "24h" | "7d" | "30d";
|
|
49
29
|
|
|
50
|
-
export type
|
|
30
|
+
export type EventHistoryRow = {
|
|
31
|
+
readonly id: string;
|
|
51
32
|
readonly installId: string;
|
|
52
|
-
readonly
|
|
53
|
-
|
|
54
|
-
readonly lastKnownBundleId: string;
|
|
55
|
-
readonly latestStatus:
|
|
33
|
+
readonly type:
|
|
34
|
+
| "UPDATE_DOWNLOADED"
|
|
56
35
|
| "UPDATE_APPLIED"
|
|
57
36
|
| "RECOVERED"
|
|
58
|
-
| "RELEASE_ADOPTED"
|
|
59
37
|
| "UNCHANGED";
|
|
38
|
+
readonly fromBundleId: string | null;
|
|
39
|
+
readonly toBundleId: string;
|
|
40
|
+
readonly username: string | null;
|
|
41
|
+
readonly userId: string | null;
|
|
60
42
|
readonly platform: "ios" | "android";
|
|
61
43
|
readonly appVersion: string;
|
|
62
44
|
readonly channel: string;
|
|
@@ -64,13 +46,19 @@ export type InstallationSearchRow = {
|
|
|
64
46
|
readonly receivedAtMs: number;
|
|
65
47
|
};
|
|
66
48
|
|
|
67
|
-
export type InstallationHistoryRow = {
|
|
68
|
-
readonly
|
|
69
|
-
readonly type: "UPDATE_APPLIED" | "RECOVERED";
|
|
49
|
+
export type InstallationHistoryRow = EventHistoryRow & {
|
|
50
|
+
readonly type: "UPDATE_DOWNLOADED" | "UPDATE_APPLIED" | "RECOVERED";
|
|
70
51
|
readonly fromBundleId: string;
|
|
71
|
-
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type InstallationRow = {
|
|
55
|
+
readonly installId: string;
|
|
72
56
|
readonly username: string | null;
|
|
73
57
|
readonly userId: string | null;
|
|
58
|
+
readonly lastKnownBundleId: string;
|
|
59
|
+
readonly pendingBundleId: string | null;
|
|
60
|
+
readonly pendingReleaseId: string | null;
|
|
61
|
+
readonly latestStatus: EventHistoryRow["type"];
|
|
74
62
|
readonly platform: "ios" | "android";
|
|
75
63
|
readonly appVersion: string;
|
|
76
64
|
readonly channel: string;
|
|
@@ -78,62 +66,41 @@ export type InstallationHistoryRow = {
|
|
|
78
66
|
readonly receivedAtMs: number;
|
|
79
67
|
};
|
|
80
68
|
|
|
81
|
-
export type
|
|
82
|
-
readonly data: readonly
|
|
83
|
-
readonly
|
|
84
|
-
readonly total: number;
|
|
85
|
-
readonly limit: number;
|
|
86
|
-
readonly offset: number;
|
|
87
|
-
};
|
|
69
|
+
export type CursorPage<T> = {
|
|
70
|
+
readonly data: readonly T[];
|
|
71
|
+
readonly nextCursor: string | null;
|
|
88
72
|
};
|
|
89
73
|
|
|
90
|
-
export type
|
|
91
|
-
readonly
|
|
92
|
-
readonly value: number;
|
|
74
|
+
export type EventCursorPage<T extends EventHistoryRow> = CursorPage<T> & {
|
|
75
|
+
readonly beforeReceivedAtMs: number;
|
|
93
76
|
};
|
|
94
77
|
|
|
95
|
-
export type
|
|
96
|
-
readonly
|
|
97
|
-
readonly
|
|
78
|
+
export type InsightsScope = {
|
|
79
|
+
readonly platform: "ios" | "android";
|
|
80
|
+
readonly channel: string;
|
|
98
81
|
};
|
|
99
82
|
|
|
100
|
-
export type
|
|
101
|
-
readonly
|
|
102
|
-
readonly
|
|
103
|
-
readonly installed: readonly InsightsSeriesPoint[];
|
|
104
|
-
readonly recovered: readonly InsightsSeriesPoint[];
|
|
105
|
-
};
|
|
106
|
-
readonly cohorts: {
|
|
107
|
-
readonly installed: readonly InsightsCohortPoint[];
|
|
108
|
-
readonly recovered: readonly InsightsCohortPoint[];
|
|
109
|
-
};
|
|
110
|
-
readonly recentEvents: OffsetPaginationResult<InstallationHistoryRow>;
|
|
83
|
+
export type InsightsBundleSelection = InsightsScope & {
|
|
84
|
+
readonly bundleId: string;
|
|
85
|
+
readonly outcome: "downloaded" | "applied" | "recovered" | "unchanged";
|
|
111
86
|
};
|
|
112
87
|
|
|
113
|
-
export type
|
|
114
|
-
readonly
|
|
115
|
-
readonly
|
|
116
|
-
readonly bundleId: string;
|
|
117
|
-
readonly installations: number;
|
|
118
|
-
}[];
|
|
88
|
+
export type InsightsCountMeasurement = {
|
|
89
|
+
readonly count: number;
|
|
90
|
+
readonly measuredAtMs: number;
|
|
119
91
|
};
|
|
120
92
|
|
|
121
|
-
export type
|
|
122
|
-
readonly asOfMs: number;
|
|
93
|
+
export type ReportingOverview = InsightsScope & {
|
|
123
94
|
readonly window: ActiveInstallationWindow;
|
|
124
|
-
readonly
|
|
125
|
-
readonly
|
|
126
|
-
readonly
|
|
127
|
-
|
|
128
|
-
readonly series: readonly InsightsSeriesPoint[];
|
|
129
|
-
}[];
|
|
130
|
-
readonly bundles: readonly {
|
|
95
|
+
readonly sinceMs: number;
|
|
96
|
+
readonly beforeReceivedAtMs: number;
|
|
97
|
+
readonly reportingInstallations: InsightsCountMeasurement;
|
|
98
|
+
readonly bundle?: {
|
|
131
99
|
readonly bundleId: string;
|
|
132
|
-
readonly
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
readonly userId?: string;
|
|
100
|
+
readonly reportingInstallations: InsightsCountMeasurement;
|
|
101
|
+
readonly downloadedReports: InsightsCountMeasurement;
|
|
102
|
+
readonly appliedReports: InsightsCountMeasurement;
|
|
103
|
+
readonly recoveredReports: InsightsCountMeasurement;
|
|
104
|
+
readonly unchangedReports: InsightsCountMeasurement;
|
|
105
|
+
};
|
|
139
106
|
};
|
package/src/insights/errors.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export class InsightsScanLimitExceededError extends Error {
|
|
2
|
-
constructor(readonly limit: number) {
|
|
3
|
-
super(`Insights event scan exceeded ${limit} rows.`);
|
|
4
|
-
this.name = "InsightsScanLimitExceededError";
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
1
|
export class InsightsBadRequestError extends Error {
|
|
9
2
|
readonly name = "InsightsBadRequestError";
|
|
10
3
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createUUIDv7, type BundleEventRow } from "@hot-updater/plugin-core";
|
|
2
|
+
|
|
1
3
|
import type {
|
|
2
4
|
CreateBundleEventRequest,
|
|
3
5
|
CreateBundleEventRequestBase,
|
|
@@ -8,6 +10,7 @@ import {
|
|
|
8
10
|
} from "./errors";
|
|
9
11
|
|
|
10
12
|
const MAX_EVENT_STRING_LENGTH = 1_024;
|
|
13
|
+
const MAX_IDENTITY_LENGTH = 255;
|
|
11
14
|
export const EVENT_BODY_MAX_BYTES = 16 * 1_024;
|
|
12
15
|
|
|
13
16
|
const eventKeys = new Set([
|
|
@@ -40,7 +43,10 @@ function requireStringField(
|
|
|
40
43
|
if (
|
|
41
44
|
typeof value !== "string" ||
|
|
42
45
|
value.length === 0 ||
|
|
43
|
-
value.length > MAX_EVENT_STRING_LENGTH
|
|
46
|
+
value.length > MAX_EVENT_STRING_LENGTH ||
|
|
47
|
+
new TextDecoder("utf-8", { ignoreBOM: true }).decode(
|
|
48
|
+
new TextEncoder().encode(value),
|
|
49
|
+
) !== value
|
|
44
50
|
) {
|
|
45
51
|
throw new InsightsBadRequestError(`Invalid event field: ${key}`);
|
|
46
52
|
}
|
|
@@ -55,6 +61,17 @@ function requireNullableStringField(
|
|
|
55
61
|
return requireStringField(payload, key);
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
function requireIdentityField(
|
|
65
|
+
payload: Readonly<Record<string, unknown>>,
|
|
66
|
+
key: "installId" | "userId",
|
|
67
|
+
): string {
|
|
68
|
+
const value = requireStringField(payload, key);
|
|
69
|
+
if (value.length > MAX_IDENTITY_LENGTH) {
|
|
70
|
+
throw new InsightsBadRequestError(`Invalid event field: ${key}`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
async function readBoundedText(request: Request): Promise<string> {
|
|
59
76
|
const contentLength = request.headers.get("content-length");
|
|
60
77
|
const declaredByteLength = Number(contentLength);
|
|
@@ -107,11 +124,11 @@ function requireEvent(payload: unknown): CreateBundleEventRequest {
|
|
|
107
124
|
throw new InsightsBadRequestError("Invalid event field: platform");
|
|
108
125
|
}
|
|
109
126
|
const base: CreateBundleEventRequestBase = {
|
|
110
|
-
installId:
|
|
127
|
+
installId: requireIdentityField(payload, "installId"),
|
|
111
128
|
toBundleId: requireStringField(payload, "toBundleId"),
|
|
112
129
|
...(payload.userId === undefined
|
|
113
130
|
? {}
|
|
114
|
-
: { userId:
|
|
131
|
+
: { userId: requireIdentityField(payload, "userId") }),
|
|
115
132
|
...(payload.username === undefined
|
|
116
133
|
? {}
|
|
117
134
|
: { username: requireStringField(payload, "username") }),
|
|
@@ -129,9 +146,9 @@ function requireEvent(payload: unknown): CreateBundleEventRequest {
|
|
|
129
146
|
};
|
|
130
147
|
const type = requireStringField(payload, "type");
|
|
131
148
|
switch (type) {
|
|
149
|
+
case "UPDATE_DOWNLOADED":
|
|
132
150
|
case "UPDATE_APPLIED":
|
|
133
|
-
case "RECOVERED":
|
|
134
|
-
case "RELEASE_ADOPTED": {
|
|
151
|
+
case "RECOVERED": {
|
|
135
152
|
const updateStrategy = requireStringField(payload, "updateStrategy");
|
|
136
153
|
if (updateStrategy !== "fingerprint" && updateStrategy !== "appVersion") {
|
|
137
154
|
throw new InsightsBadRequestError(
|
|
@@ -166,3 +183,36 @@ export async function parseBundleEventRequest(
|
|
|
166
183
|
const payload = await parseJson(request);
|
|
167
184
|
return requireEvent(payload);
|
|
168
185
|
}
|
|
186
|
+
|
|
187
|
+
export function createBundleEventRow(
|
|
188
|
+
input: CreateBundleEventRequest,
|
|
189
|
+
): BundleEventRow {
|
|
190
|
+
input = requireEvent(input);
|
|
191
|
+
const base = {
|
|
192
|
+
app_version: input.appVersion,
|
|
193
|
+
channel: input.channel,
|
|
194
|
+
from_release_id: input.fromReleaseId,
|
|
195
|
+
id: createUUIDv7(),
|
|
196
|
+
install_id: input.installId,
|
|
197
|
+
platform: input.platform,
|
|
198
|
+
received_at_ms: Date.now(),
|
|
199
|
+
to_bundle_id: input.toBundleId,
|
|
200
|
+
to_release_id: input.toReleaseId,
|
|
201
|
+
user_id: input.userId ?? null,
|
|
202
|
+
metadata: {
|
|
203
|
+
cohort: input.cohort,
|
|
204
|
+
fingerprint_hash: input.fingerprintHash,
|
|
205
|
+
sdk_version: input.sdkVersion ?? null,
|
|
206
|
+
username: input.username ?? null,
|
|
207
|
+
update_strategy: input.updateStrategy,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
switch (input.type) {
|
|
211
|
+
case "UPDATE_DOWNLOADED":
|
|
212
|
+
case "UPDATE_APPLIED":
|
|
213
|
+
case "RECOVERED":
|
|
214
|
+
return { ...base, from_bundle_id: input.fromBundleId, type: input.type };
|
|
215
|
+
case "UNCHANGED":
|
|
216
|
+
return { ...base, from_bundle_id: null, type: input.type };
|
|
217
|
+
}
|
|
218
|
+
}
|