@hot-updater/server 1.0.0-rc.0 → 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 +9 -4
- package/dist/adapters/drizzle.d.cts +0 -1
- package/dist/adapters/drizzle.d.mts +0 -1
- package/dist/adapters/drizzle.mjs +10 -4
- 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 +27 -12
- package/dist/createHotUpdaterCore.d.cts +8 -8
- package/dist/createHotUpdaterCore.d.mts +8 -8
- package/dist/createHotUpdaterCore.mjs +26 -12
- 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.cjs +5 -5
- package/dist/handler.d.cts +1 -2
- package/dist/handler.d.mts +1 -2
- package/dist/handler.mjs +5 -5
- 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 +2 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/insights/domain.d.cts +92 -0
- package/dist/insights/domain.d.mts +92 -0
- package/dist/insights/errors.cjs +15 -0
- package/dist/insights/errors.mjs +14 -0
- package/dist/{analytics → insights}/eventInput.cjs +61 -16
- package/dist/{analytics → insights}/eventInput.mjs +61 -18
- 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 +93 -0
- package/dist/insights/queryInput.mjs +91 -0
- package/dist/insights/routes.cjs +58 -0
- package/dist/insights/routes.mjs +56 -0
- package/dist/insights/types.d.cts +32 -0
- package/dist/insights/types.d.mts +32 -0
- 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 +16 -4
- 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 +3 -3
- package/src/createHotUpdaterCore.ts +30 -16
- 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 +11 -3
- package/src/db/types.ts +13 -7
- package/src/handler-standalone.integration.spec.ts +6 -8
- package/src/handler.ts +12 -12
- package/src/index.ts +3 -3
- package/src/insights/domain.ts +106 -0
- package/src/insights/errors.ts +11 -0
- package/src/{analytics → insights}/eventInput.ts +66 -16
- package/src/insights/insights.integration.spec.ts +475 -0
- package/src/insights/provider.spec.ts +396 -0
- package/src/insights/provider.ts +611 -0
- package/src/insights/queryInput.ts +142 -0
- package/src/insights/routes.ts +104 -0
- package/src/insights/types.ts +55 -0
- 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/analytics/bounded/activeOverview.cjs +0 -87
- package/dist/analytics/bounded/activeOverview.mjs +0 -85
- package/dist/analytics/bounded/installationSearch.cjs +0 -42
- package/dist/analytics/bounded/installationSearch.mjs +0 -42
- package/dist/analytics/bounded/persistence.cjs +0 -39
- package/dist/analytics/bounded/persistence.mjs +0 -38
- package/dist/analytics/bounded/provider.cjs +0 -170
- package/dist/analytics/bounded/provider.d.cts +0 -7
- package/dist/analytics/bounded/provider.d.mts +0 -7
- package/dist/analytics/bounded/provider.mjs +0 -170
- package/dist/analytics/bounded/scan.cjs +0 -144
- package/dist/analytics/bounded/scan.mjs +0 -138
- package/dist/analytics/domain.d.cts +0 -121
- package/dist/analytics/domain.d.mts +0 -121
- package/dist/analytics/errors.cjs +0 -22
- package/dist/analytics/errors.mjs +0 -20
- package/dist/analytics/persistence.d.cts +0 -6
- package/dist/analytics/persistence.d.mts +0 -6
- package/dist/analytics/queryInput.cjs +0 -58
- package/dist/analytics/queryInput.mjs +0 -55
- package/dist/analytics/routes.cjs +0 -63
- package/dist/analytics/routes.mjs +0 -61
- package/dist/analytics/types.d.cts +0 -17
- package/dist/analytics/types.d.mts +0 -17
- package/src/analytics/analytics.integration.spec.ts +0 -144
- package/src/analytics/bounded/activeOverview.spec.ts +0 -189
- package/src/analytics/bounded/activeOverview.ts +0 -148
- package/src/analytics/bounded/installationSearch.spec.ts +0 -130
- package/src/analytics/bounded/installationSearch.ts +0 -69
- package/src/analytics/bounded/persistence.ts +0 -43
- package/src/analytics/bounded/provider.spec.ts +0 -219
- package/src/analytics/bounded/provider.ts +0 -229
- package/src/analytics/bounded/scan.ts +0 -235
- package/src/analytics/domain.ts +0 -139
- package/src/analytics/errors.ts +0 -18
- package/src/analytics/persistence.ts +0 -10
- package/src/analytics/queryInput.ts +0 -102
- package/src/analytics/routes.ts +0 -123
- package/src/analytics/types.ts +0 -44
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { createInMemoryDatabasePlugin } from "../../../test-utils/test/inMemoryDatabasePlugin";
|
|
4
|
+
import { createHotUpdater } from "../index";
|
|
5
|
+
import { createSchemaManagedDatabase } from "../runtime.testFixtures";
|
|
6
|
+
import { HOT_UPDATER_SCHEMA_VERSION } from "../schema/types";
|
|
7
|
+
|
|
8
|
+
const event = {
|
|
9
|
+
appVersion: "1.0.0",
|
|
10
|
+
channel: "production",
|
|
11
|
+
cohort: "default",
|
|
12
|
+
fingerprintHash: null,
|
|
13
|
+
fromBundleId: null,
|
|
14
|
+
fromReleaseId: null,
|
|
15
|
+
installId: "install-1",
|
|
16
|
+
platform: "ios",
|
|
17
|
+
toBundleId: "bundle-1",
|
|
18
|
+
toReleaseId: null,
|
|
19
|
+
type: "UNCHANGED",
|
|
20
|
+
updateStrategy: null,
|
|
21
|
+
userId: "user-1",
|
|
22
|
+
username: "Jane",
|
|
23
|
+
sdkVersion: "2.0.0",
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
const eventRequest = (body: unknown = event) =>
|
|
27
|
+
new Request("https://example.com/events", {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "content-type": "application/json" },
|
|
30
|
+
body: JSON.stringify(body),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
vi.useRealTimers();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("createHotUpdater Insights", () => {
|
|
38
|
+
it("ingests a downloaded bundle and exposes the running and pending state until apply", async () => {
|
|
39
|
+
const hotUpdater = createHotUpdater({
|
|
40
|
+
database: createInMemoryDatabasePlugin(),
|
|
41
|
+
clientAccess: { type: "public" },
|
|
42
|
+
});
|
|
43
|
+
const downloaded = {
|
|
44
|
+
...event,
|
|
45
|
+
type: "UPDATE_DOWNLOADED",
|
|
46
|
+
fromBundleId: "bundle-1",
|
|
47
|
+
toBundleId: "bundle-2",
|
|
48
|
+
toReleaseId: "release-2",
|
|
49
|
+
updateStrategy: "appVersion",
|
|
50
|
+
};
|
|
51
|
+
expect(
|
|
52
|
+
(await hotUpdater.handlers.client(eventRequest(downloaded))).status,
|
|
53
|
+
).toBe(204);
|
|
54
|
+
const downloads = await hotUpdater.handlers.admin(
|
|
55
|
+
new Request(
|
|
56
|
+
`https://example.com/events?platform=ios&channel=production&bundleId=bundle-2&outcome=downloaded&beforeReceivedAtMs=${Date.now() + 1}`,
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
expect(downloads.status).toBe(200);
|
|
60
|
+
await expect(downloads.json()).resolves.toMatchObject({
|
|
61
|
+
data: [{ type: "UPDATE_DOWNLOADED", toBundleId: "bundle-2" }],
|
|
62
|
+
});
|
|
63
|
+
const lookup = () =>
|
|
64
|
+
hotUpdater.handlers.admin(
|
|
65
|
+
new Request("https://example.com/installations/install-1"),
|
|
66
|
+
);
|
|
67
|
+
await expect((await lookup()).json()).resolves.toMatchObject({
|
|
68
|
+
latestStatus: "UPDATE_DOWNLOADED",
|
|
69
|
+
lastKnownBundleId: "bundle-1",
|
|
70
|
+
pendingBundleId: "bundle-2",
|
|
71
|
+
pendingReleaseId: "release-2",
|
|
72
|
+
});
|
|
73
|
+
expect(
|
|
74
|
+
(
|
|
75
|
+
await hotUpdater.handlers.client(
|
|
76
|
+
eventRequest({ ...downloaded, type: "UPDATE_APPLIED" }),
|
|
77
|
+
)
|
|
78
|
+
).status,
|
|
79
|
+
).toBe(204);
|
|
80
|
+
await expect((await lookup()).json()).resolves.toMatchObject({
|
|
81
|
+
latestStatus: "UPDATE_APPLIED",
|
|
82
|
+
lastKnownBundleId: "bundle-2",
|
|
83
|
+
pendingBundleId: null,
|
|
84
|
+
pendingReleaseId: null,
|
|
85
|
+
});
|
|
86
|
+
expect(
|
|
87
|
+
(
|
|
88
|
+
await hotUpdater.handlers.client(
|
|
89
|
+
eventRequest({ ...downloaded, fromBundleId: null }),
|
|
90
|
+
)
|
|
91
|
+
).status,
|
|
92
|
+
).toBe(400);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("persists an event and serves the lean Insights views", async () => {
|
|
96
|
+
vi.useFakeTimers();
|
|
97
|
+
vi.setSystemTime(new Date("2026-08-12T00:00:00.000Z"));
|
|
98
|
+
const receivedAtMs = Date.now();
|
|
99
|
+
const database = createInMemoryDatabasePlugin();
|
|
100
|
+
const append = vi.spyOn(database.models.insights, "recordEvent");
|
|
101
|
+
const hotUpdater = createHotUpdater({
|
|
102
|
+
database,
|
|
103
|
+
clientAccess: { type: "public" },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const ingestion = await hotUpdater.handlers.client(eventRequest());
|
|
107
|
+
vi.advanceTimersByTime(1);
|
|
108
|
+
const events = await hotUpdater.handlers.admin(
|
|
109
|
+
new Request("https://example.com/events"),
|
|
110
|
+
);
|
|
111
|
+
const installation = await hotUpdater.handlers.admin(
|
|
112
|
+
new Request("https://example.com/installations/install-1"),
|
|
113
|
+
);
|
|
114
|
+
const matches = await hotUpdater.handlers.admin(
|
|
115
|
+
new Request("https://example.com/installations?userId=user-1"),
|
|
116
|
+
);
|
|
117
|
+
const active = await hotUpdater.handlers.admin(
|
|
118
|
+
new Request(
|
|
119
|
+
"https://example.com/overview?platform=ios&channel=production&window=24h",
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(ingestion.status).toBe(204);
|
|
124
|
+
expect(append).toHaveBeenCalledWith(
|
|
125
|
+
expect.objectContaining({
|
|
126
|
+
event: expect.objectContaining({
|
|
127
|
+
install_id: "install-1",
|
|
128
|
+
metadata: expect.objectContaining({ sdk_version: "2.0.0" }),
|
|
129
|
+
to_bundle_id: "bundle-1",
|
|
130
|
+
type: "UNCHANGED",
|
|
131
|
+
}),
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
expect(events.status).toBe(200);
|
|
135
|
+
await expect(events.json()).resolves.toMatchObject({
|
|
136
|
+
data: [
|
|
137
|
+
{
|
|
138
|
+
id: expect.any(String),
|
|
139
|
+
installId: "install-1",
|
|
140
|
+
receivedAtMs,
|
|
141
|
+
type: "UNCHANGED",
|
|
142
|
+
userId: "user-1",
|
|
143
|
+
username: "Jane",
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
nextCursor: null,
|
|
147
|
+
});
|
|
148
|
+
expect(installation.status).toBe(200);
|
|
149
|
+
await expect(installation.json()).resolves.toMatchObject({
|
|
150
|
+
installId: "install-1",
|
|
151
|
+
latestStatus: "UNCHANGED",
|
|
152
|
+
userId: "user-1",
|
|
153
|
+
});
|
|
154
|
+
expect(matches.status).toBe(200);
|
|
155
|
+
await expect(matches.json()).resolves.toMatchObject({
|
|
156
|
+
data: [{ installId: "install-1", userId: "user-1" }],
|
|
157
|
+
nextCursor: null,
|
|
158
|
+
});
|
|
159
|
+
expect(active.status).toBe(200);
|
|
160
|
+
await expect(active.json()).resolves.toEqual({
|
|
161
|
+
platform: "ios",
|
|
162
|
+
channel: "production",
|
|
163
|
+
sinceMs: Date.now() - 24 * 60 * 60 * 1_000,
|
|
164
|
+
beforeReceivedAtMs: Date.now(),
|
|
165
|
+
reportingInstallations: { count: 1, measuredAtMs: Date.now() },
|
|
166
|
+
window: "24h",
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("serves scoped bundle counts and the same half-open recovery drill-down", async () => {
|
|
171
|
+
vi.useFakeTimers();
|
|
172
|
+
const hotUpdater = createHotUpdater({
|
|
173
|
+
database: createInMemoryDatabasePlugin(),
|
|
174
|
+
clientAccess: { type: "public" },
|
|
175
|
+
});
|
|
176
|
+
const report = async (
|
|
177
|
+
receivedAtMs: number,
|
|
178
|
+
overrides: Record<string, unknown>,
|
|
179
|
+
) => {
|
|
180
|
+
vi.setSystemTime(receivedAtMs);
|
|
181
|
+
const response = await hotUpdater.handlers.client(
|
|
182
|
+
eventRequest({ ...event, ...overrides }),
|
|
183
|
+
);
|
|
184
|
+
expect(response.status).toBe(204);
|
|
185
|
+
};
|
|
186
|
+
await report(100, {
|
|
187
|
+
type: "UPDATE_APPLIED",
|
|
188
|
+
fromBundleId: "A",
|
|
189
|
+
toBundleId: "B",
|
|
190
|
+
updateStrategy: "appVersion",
|
|
191
|
+
});
|
|
192
|
+
await report(200, {
|
|
193
|
+
type: "RECOVERED",
|
|
194
|
+
fromBundleId: "B",
|
|
195
|
+
toBundleId: "A",
|
|
196
|
+
updateStrategy: "appVersion",
|
|
197
|
+
});
|
|
198
|
+
await report(300, {
|
|
199
|
+
installId: "install-2",
|
|
200
|
+
type: "UNCHANGED",
|
|
201
|
+
fromBundleId: null,
|
|
202
|
+
toBundleId: "B",
|
|
203
|
+
updateStrategy: null,
|
|
204
|
+
});
|
|
205
|
+
await report(400, {
|
|
206
|
+
installId: "install-3",
|
|
207
|
+
platform: "android",
|
|
208
|
+
toBundleId: "B",
|
|
209
|
+
});
|
|
210
|
+
vi.setSystemTime(500);
|
|
211
|
+
const overview = await hotUpdater.handlers.admin(
|
|
212
|
+
new Request(
|
|
213
|
+
"https://example.com/overview?platform=ios&channel=production&window=24h&bundleId=B",
|
|
214
|
+
),
|
|
215
|
+
);
|
|
216
|
+
expect(overview.status).toBe(200);
|
|
217
|
+
await expect(overview.json()).resolves.toMatchObject({
|
|
218
|
+
sinceMs: 0,
|
|
219
|
+
beforeReceivedAtMs: 500,
|
|
220
|
+
reportingInstallations: { count: 2 },
|
|
221
|
+
bundle: {
|
|
222
|
+
bundleId: "B",
|
|
223
|
+
reportingInstallations: { count: 1 },
|
|
224
|
+
appliedReports: { count: 1 },
|
|
225
|
+
recoveredReports: { count: 1 },
|
|
226
|
+
unchangedReports: { count: 1 },
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
const drilldown = await hotUpdater.handlers.admin(
|
|
230
|
+
new Request(
|
|
231
|
+
"https://example.com/events?platform=ios&channel=production&bundleId=B&outcome=recovered&sinceMs=200&beforeReceivedAtMs=300",
|
|
232
|
+
),
|
|
233
|
+
);
|
|
234
|
+
await expect(drilldown.json()).resolves.toMatchObject({
|
|
235
|
+
data: [
|
|
236
|
+
{
|
|
237
|
+
type: "RECOVERED",
|
|
238
|
+
fromBundleId: "B",
|
|
239
|
+
toBundleId: "A",
|
|
240
|
+
receivedAtMs: 200,
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
nextCursor: null,
|
|
244
|
+
});
|
|
245
|
+
const outside = await hotUpdater.handlers.admin(
|
|
246
|
+
new Request(
|
|
247
|
+
"https://example.com/events?platform=ios&channel=production&bundleId=B&outcome=recovered&sinceMs=0&beforeReceivedAtMs=200",
|
|
248
|
+
),
|
|
249
|
+
);
|
|
250
|
+
await expect(outside.json()).resolves.toMatchObject({
|
|
251
|
+
data: [],
|
|
252
|
+
nextCursor: null,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it.each([
|
|
257
|
+
"/overview?window=24h",
|
|
258
|
+
"/overview?platform=ios&channel=production&platform=android",
|
|
259
|
+
"/events?bundleId=B",
|
|
260
|
+
"/events?platform=ios&channel=production&bundleId=B&outcome=UNCHANGED",
|
|
261
|
+
"/events?sinceMs=20&beforeReceivedAtMs=10",
|
|
262
|
+
"/installations/install-1/events?platform=ios&channel=production&bundleId=B&outcome=applied",
|
|
263
|
+
])("rejects ambiguous or invalid Insights query %s", async (path) => {
|
|
264
|
+
const hotUpdater = createHotUpdater({
|
|
265
|
+
database: createInMemoryDatabasePlugin(),
|
|
266
|
+
clientAccess: { type: "public" },
|
|
267
|
+
});
|
|
268
|
+
expect(
|
|
269
|
+
(
|
|
270
|
+
await hotUpdater.handlers.admin(
|
|
271
|
+
new Request(`https://example.com${path}`),
|
|
272
|
+
)
|
|
273
|
+
).status,
|
|
274
|
+
).toBe(400);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("checks the official schema before Insights reads and writes", async () => {
|
|
278
|
+
const database = createSchemaManagedDatabase(
|
|
279
|
+
"kysely",
|
|
280
|
+
HOT_UPDATER_SCHEMA_VERSION,
|
|
281
|
+
);
|
|
282
|
+
const createMigrator = vi.spyOn(database, "createMigrator");
|
|
283
|
+
const hotUpdater = createHotUpdater({
|
|
284
|
+
database,
|
|
285
|
+
clientAccess: { type: "public" },
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect((await hotUpdater.handlers.client(eventRequest())).status).toBe(204);
|
|
289
|
+
await hotUpdater.insights.listEvents({});
|
|
290
|
+
|
|
291
|
+
expect(createMigrator).toHaveBeenCalledOnce();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("keeps ingestion and queries on separate handler surfaces", async () => {
|
|
295
|
+
const hotUpdater = createHotUpdater({
|
|
296
|
+
database: createInMemoryDatabasePlugin(),
|
|
297
|
+
clientAccess: { type: "public" },
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
expect((await hotUpdater.handlers.client(eventRequest())).status).toBe(204);
|
|
301
|
+
const clientQuery = await hotUpdater.handlers.client(
|
|
302
|
+
new Request("https://example.com/events"),
|
|
303
|
+
);
|
|
304
|
+
const adminIngestion = await hotUpdater.handlers.admin(eventRequest());
|
|
305
|
+
const adminQuery = await hotUpdater.handlers.admin(
|
|
306
|
+
new Request("https://example.com/events"),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
expect(clientQuery.status).toBe(404);
|
|
310
|
+
expect(adminIngestion.status).toBe(404);
|
|
311
|
+
expect(adminQuery.status).toBe(200);
|
|
312
|
+
expect(adminQuery.headers.get("cache-control")).toBe("private, no-store");
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("records same-file selection as no change and rejects a fourth event type", async () => {
|
|
316
|
+
const database = createInMemoryDatabasePlugin();
|
|
317
|
+
const recordEvent = vi.spyOn(database.models.insights, "recordEvent");
|
|
318
|
+
const hotUpdater = createHotUpdater({
|
|
319
|
+
database,
|
|
320
|
+
clientAccess: { type: "public" },
|
|
321
|
+
});
|
|
322
|
+
const selection = {
|
|
323
|
+
...event,
|
|
324
|
+
fromReleaseId: "previous-release",
|
|
325
|
+
toReleaseId: "selected-release",
|
|
326
|
+
};
|
|
327
|
+
expect(
|
|
328
|
+
(await hotUpdater.handlers.client(eventRequest(selection))).status,
|
|
329
|
+
).toBe(204);
|
|
330
|
+
expect(recordEvent).toHaveBeenCalledWith({
|
|
331
|
+
event: expect.objectContaining({
|
|
332
|
+
type: "UNCHANGED",
|
|
333
|
+
from_bundle_id: null,
|
|
334
|
+
metadata: expect.objectContaining({ update_strategy: null }),
|
|
335
|
+
from_release_id: "previous-release",
|
|
336
|
+
to_release_id: "selected-release",
|
|
337
|
+
to_bundle_id: event.toBundleId,
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
const response = await hotUpdater.handlers.client(
|
|
341
|
+
eventRequest({
|
|
342
|
+
...selection,
|
|
343
|
+
type: "RELEASE_ADOPTED",
|
|
344
|
+
fromBundleId: event.toBundleId,
|
|
345
|
+
updateStrategy: "appVersion",
|
|
346
|
+
}),
|
|
347
|
+
);
|
|
348
|
+
expect(response.status).toBe(400);
|
|
349
|
+
expect(recordEvent).toHaveBeenCalledTimes(1);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("returns a stable client error for malformed event payloads", async () => {
|
|
353
|
+
const hotUpdater = createHotUpdater({
|
|
354
|
+
database: createInMemoryDatabasePlugin(),
|
|
355
|
+
clientAccess: { type: "public" },
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const response = await hotUpdater.handlers.client(
|
|
359
|
+
eventRequest({ ...event, platform: "web" }),
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
expect(response.status).toBe(400);
|
|
363
|
+
await expect(response.json()).resolves.toEqual({
|
|
364
|
+
error: "Invalid event field: platform",
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it.each(["installId", "userId"] as const)(
|
|
369
|
+
"rejects a 256-character event %s",
|
|
370
|
+
async (field) => {
|
|
371
|
+
const hotUpdater = createHotUpdater({
|
|
372
|
+
database: createInMemoryDatabasePlugin(),
|
|
373
|
+
clientAccess: { type: "public" },
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const response = await hotUpdater.handlers.client(
|
|
377
|
+
eventRequest({ ...event, [field]: "x".repeat(256) }),
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
expect(response.status).toBe(400);
|
|
381
|
+
await expect(response.json()).resolves.toEqual({
|
|
382
|
+
error: `Invalid event field: ${field}`,
|
|
383
|
+
});
|
|
384
|
+
},
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
it("preserves a leading Unicode BOM in exact installation and current-user IDs", async () => {
|
|
388
|
+
const hotUpdater = createHotUpdater({
|
|
389
|
+
database: createInMemoryDatabasePlugin(),
|
|
390
|
+
clientAccess: { type: "public" },
|
|
391
|
+
});
|
|
392
|
+
const installId = "\uFEFFinstall";
|
|
393
|
+
const userId = "\uFEFFuser";
|
|
394
|
+
expect(
|
|
395
|
+
(
|
|
396
|
+
await hotUpdater.handlers.client(
|
|
397
|
+
eventRequest({ ...event, installId, userId }),
|
|
398
|
+
)
|
|
399
|
+
).status,
|
|
400
|
+
).toBe(204);
|
|
401
|
+
const installation = await hotUpdater.handlers.admin(
|
|
402
|
+
new Request(
|
|
403
|
+
`https://example.com/installations/${encodeURIComponent(installId)}`,
|
|
404
|
+
),
|
|
405
|
+
);
|
|
406
|
+
expect(installation.status).toBe(200);
|
|
407
|
+
await expect(installation.json()).resolves.toMatchObject({
|
|
408
|
+
installId,
|
|
409
|
+
userId,
|
|
410
|
+
});
|
|
411
|
+
const matches = await hotUpdater.handlers.admin(
|
|
412
|
+
new Request(
|
|
413
|
+
`https://example.com/installations?userId=${encodeURIComponent(userId)}`,
|
|
414
|
+
),
|
|
415
|
+
);
|
|
416
|
+
expect(matches.status).toBe(200);
|
|
417
|
+
await expect(matches.json()).resolves.toMatchObject({
|
|
418
|
+
data: [{ installId, userId }],
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it.each(["\uD800", "\uDC00"])(
|
|
423
|
+
"rejects an unmatched surrogate identity %j",
|
|
424
|
+
async (installId) => {
|
|
425
|
+
const hotUpdater = createHotUpdater({
|
|
426
|
+
database: createInMemoryDatabasePlugin(),
|
|
427
|
+
clientAccess: { type: "public" },
|
|
428
|
+
});
|
|
429
|
+
expect(
|
|
430
|
+
(
|
|
431
|
+
await hotUpdater.handlers.client(
|
|
432
|
+
eventRequest({ ...event, installId }),
|
|
433
|
+
)
|
|
434
|
+
).status,
|
|
435
|
+
).toBe(400);
|
|
436
|
+
},
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
it("rejects 256-character installation query identities", async () => {
|
|
440
|
+
const hotUpdater = createHotUpdater({
|
|
441
|
+
database: createInMemoryDatabasePlugin(),
|
|
442
|
+
clientAccess: { type: "public" },
|
|
443
|
+
});
|
|
444
|
+
const tooLong = "x".repeat(256);
|
|
445
|
+
|
|
446
|
+
const user = await hotUpdater.handlers.admin(
|
|
447
|
+
new Request(`https://example.com/installations?userId=${tooLong}`),
|
|
448
|
+
);
|
|
449
|
+
const installation = await hotUpdater.handlers.admin(
|
|
450
|
+
new Request(`https://example.com/installations/${tooLong}`),
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
expect(user.status).toBe(400);
|
|
454
|
+
expect(installation.status).toBe(400);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it.each(["fromReleaseId", "toReleaseId"] as const)(
|
|
458
|
+
"rejects an omitted %s instead of treating it as null",
|
|
459
|
+
async (field) => {
|
|
460
|
+
const hotUpdater = createHotUpdater({
|
|
461
|
+
database: createInMemoryDatabasePlugin(),
|
|
462
|
+
clientAccess: { type: "public" },
|
|
463
|
+
});
|
|
464
|
+
const payload: Record<string, unknown> = { ...event };
|
|
465
|
+
delete payload[field];
|
|
466
|
+
|
|
467
|
+
const response = await hotUpdater.handlers.client(eventRequest(payload));
|
|
468
|
+
|
|
469
|
+
expect(response.status).toBe(400);
|
|
470
|
+
await expect(response.json()).resolves.toEqual({
|
|
471
|
+
error: `Invalid event field: ${field}`,
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
);
|
|
475
|
+
});
|