@hot-updater/plugin-insights 1.0.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +33 -0
- package/README.md +24 -0
- package/client/package.json +7 -0
- package/dist/client/eventId.cjs +181 -0
- package/dist/client/eventId.mjs +179 -0
- package/dist/client/index.cjs +234 -0
- package/dist/client/index.d.cts +42 -0
- package/dist/client/index.d.mts +42 -0
- package/dist/client/index.mjs +233 -0
- package/dist/client/sender.cjs +103 -0
- package/dist/client/sender.mjs +103 -0
- package/dist/client/state.cjs +121 -0
- package/dist/client/state.mjs +119 -0
- package/dist/internal.cjs +9 -0
- package/dist/internal.d.cts +5 -0
- package/dist/internal.d.mts +5 -0
- package/dist/internal.mjs +5 -0
- package/dist/server/contract.cjs +193 -0
- package/dist/server/contract.mjs +189 -0
- package/dist/server/domain.d.cts +149 -0
- package/dist/server/domain.d.mts +149 -0
- package/dist/server/errors.cjs +15 -0
- package/dist/server/errors.d.cts +6 -0
- package/dist/server/errors.d.mts +6 -0
- package/dist/server/errors.mjs +14 -0
- package/dist/server/eventInput.cjs +284 -0
- package/dist/server/eventInput.d.cts +6 -0
- package/dist/server/eventInput.d.mts +6 -0
- package/dist/server/eventInput.mjs +282 -0
- package/dist/server/eventRow.cjs +49 -0
- package/dist/server/eventRow.d.cts +64 -0
- package/dist/server/eventRow.d.mts +64 -0
- package/dist/server/eventRow.mjs +47 -0
- package/dist/server/index.cjs +128 -0
- package/dist/server/index.d.cts +394 -0
- package/dist/server/index.d.mts +394 -0
- package/dist/server/index.mjs +121 -0
- package/dist/server/model.cjs +17 -0
- package/dist/server/model.d.cts +10 -0
- package/dist/server/model.d.mts +10 -0
- package/dist/server/model.mjs +17 -0
- package/dist/server/modelTypes.d.cts +176 -0
- package/dist/server/modelTypes.d.mts +176 -0
- package/dist/server/overview.cjs +109 -0
- package/dist/server/overview.d.cts +15 -0
- package/dist/server/overview.d.mts +15 -0
- package/dist/server/overview.mjs +107 -0
- package/dist/server/provider.cjs +375 -0
- package/dist/server/provider.d.cts +6 -0
- package/dist/server/provider.d.mts +6 -0
- package/dist/server/provider.mjs +374 -0
- package/dist/server/queryInput.cjs +93 -0
- package/dist/server/queryInput.mjs +91 -0
- package/dist/server/reads.cjs +681 -0
- package/dist/server/reads.d.cts +60 -0
- package/dist/server/reads.d.mts +60 -0
- package/dist/server/reads.mjs +674 -0
- package/dist/server/recordEvent.cjs +319 -0
- package/dist/server/recordEvent.d.cts +17 -0
- package/dist/server/recordEvent.d.mts +17 -0
- package/dist/server/recordEvent.mjs +316 -0
- package/dist/server/routes.cjs +96 -0
- package/dist/server/routes.d.cts +36 -0
- package/dist/server/routes.d.mts +36 -0
- package/dist/server/routes.mjs +95 -0
- package/dist/server/schema.cjs +489 -0
- package/dist/server/schema.d.cts +706 -0
- package/dist/server/schema.d.mts +706 -0
- package/dist/server/schema.mjs +483 -0
- package/dist/server/testing/eventRow.d.mts +64 -0
- package/dist/server/testing/expectInsightsIndex.mjs +18 -0
- package/dist/server/testing/fixtures.d.mts +8 -0
- package/dist/server/testing/fixtures.mjs +25 -0
- package/dist/server/testing/index.d.mts +24 -0
- package/dist/server/testing/index.mjs +25 -0
- package/dist/server/testing/insightsModelTests.mjs +714 -0
- package/dist/server/testing/modelTypes.d.mts +176 -0
- package/dist/server/testing/setupInsightsHttpTestSuite.d.mts +11 -0
- package/dist/server/testing/setupInsightsHttpTestSuite.mjs +107 -0
- package/dist/server/testing/setupInsightsModelTestSuite.d.mts +11 -0
- package/dist/server/testing/setupInsightsModelTestSuite.mjs +31 -0
- package/dist/server/testing/types.d.mts +26 -0
- package/dist/server/types.d.cts +33 -0
- package/dist/server/types.d.mts +33 -0
- package/package.json +68 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { BundleEventRow } from "./eventRow.mjs";
|
|
2
|
+
//#region src/server/modelTypes.d.ts
|
|
3
|
+
interface InsightsEventCursor {
|
|
4
|
+
readonly receivedAtMs: number;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
}
|
|
7
|
+
interface InsightsScope {
|
|
8
|
+
readonly platform: "ios" | "android";
|
|
9
|
+
readonly channel: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Raw event predicates; recovery is attributed to the source bundle. An
|
|
13
|
+
* UNCHANGED report is kept as no event, so no filter names it.
|
|
14
|
+
*/
|
|
15
|
+
type InsightsBundleEventFilter = InsightsScope & ({
|
|
16
|
+
readonly type: "RECOVERED";
|
|
17
|
+
readonly fromBundleId: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: "UPDATE_DOWNLOADED" | "UPDATE_APPLIED" | "UPDATE_FAILED";
|
|
20
|
+
readonly toBundleId: string;
|
|
21
|
+
});
|
|
22
|
+
type InsightsEventFilter = {
|
|
23
|
+
readonly kind: "all";
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "installationMovement";
|
|
26
|
+
readonly installId: string;
|
|
27
|
+
} | ({
|
|
28
|
+
readonly kind: "bundle";
|
|
29
|
+
} & InsightsBundleEventFilter);
|
|
30
|
+
interface InsightsRecordEventInput {
|
|
31
|
+
readonly event: BundleEventRow;
|
|
32
|
+
}
|
|
33
|
+
interface InsightsListEventsInput {
|
|
34
|
+
readonly filter: InsightsEventFilter;
|
|
35
|
+
readonly sinceMs?: number;
|
|
36
|
+
readonly beforeReceivedAtMs: number;
|
|
37
|
+
readonly after?: InsightsEventCursor;
|
|
38
|
+
readonly limit: number;
|
|
39
|
+
}
|
|
40
|
+
type InsightsFindLatestEventsInput = {
|
|
41
|
+
readonly installId: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly userId: string;
|
|
44
|
+
readonly afterInstallId?: string;
|
|
45
|
+
readonly limit: number;
|
|
46
|
+
};
|
|
47
|
+
interface InsightsCountLatestEventsInput extends InsightsScope {
|
|
48
|
+
/** A UTC day's start: latest events are counted by the day they fall in. */
|
|
49
|
+
readonly sinceMs: number;
|
|
50
|
+
/** Optional OR of one or two fixed predicates; count a matching event once. */
|
|
51
|
+
readonly bundle?: readonly {
|
|
52
|
+
readonly field: "from_bundle_id" | "to_bundle_id";
|
|
53
|
+
readonly value: string;
|
|
54
|
+
readonly types: readonly BundleEventRow["type"][];
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
interface InsightsCountEventsInput {
|
|
58
|
+
readonly filter: InsightsBundleEventFilter;
|
|
59
|
+
readonly sinceMs: number;
|
|
60
|
+
readonly beforeReceivedAtMs: number;
|
|
61
|
+
}
|
|
62
|
+
interface ReleaseReference {
|
|
63
|
+
readonly releaseId: string;
|
|
64
|
+
readonly platform: "ios" | "android";
|
|
65
|
+
readonly channel: string;
|
|
66
|
+
}
|
|
67
|
+
interface InsightsTimeRange {
|
|
68
|
+
/** Inclusive UTC Unix timestamp in milliseconds. */
|
|
69
|
+
readonly start: number;
|
|
70
|
+
/** Exclusive UTC Unix timestamp in milliseconds. */
|
|
71
|
+
readonly end: number;
|
|
72
|
+
}
|
|
73
|
+
type InsightsCoverage = {
|
|
74
|
+
readonly kind: "complete";
|
|
75
|
+
readonly sinceMs: number;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: "partial";
|
|
78
|
+
readonly sinceMs: number | null;
|
|
79
|
+
};
|
|
80
|
+
interface ReleaseActivityMetrics {
|
|
81
|
+
readonly downloads: number;
|
|
82
|
+
readonly launches: number;
|
|
83
|
+
readonly failedLaunches: number;
|
|
84
|
+
/** Omitted for lifetime-only bundle-row reads. */
|
|
85
|
+
readonly uniqueUsers?: number;
|
|
86
|
+
/** Daily points, present only for period reads. */
|
|
87
|
+
readonly series?: readonly {
|
|
88
|
+
readonly startMs: number;
|
|
89
|
+
readonly launches: number;
|
|
90
|
+
readonly failedLaunches: number;
|
|
91
|
+
}[];
|
|
92
|
+
}
|
|
93
|
+
type InsightsGetReleaseActivityInput = {
|
|
94
|
+
readonly releases: readonly ReleaseReference[];
|
|
95
|
+
readonly timeRange?: InsightsTimeRange;
|
|
96
|
+
readonly scope?: never;
|
|
97
|
+
} | {
|
|
98
|
+
readonly scope: InsightsScope;
|
|
99
|
+
readonly timeRange: InsightsTimeRange;
|
|
100
|
+
readonly releases?: never;
|
|
101
|
+
};
|
|
102
|
+
interface InsightsGetReleaseActivityResult {
|
|
103
|
+
readonly coverage: InsightsCoverage;
|
|
104
|
+
readonly data: readonly {
|
|
105
|
+
readonly release?: ReleaseReference;
|
|
106
|
+
readonly scope?: InsightsScope;
|
|
107
|
+
readonly metrics: ReleaseActivityMetrics;
|
|
108
|
+
}[];
|
|
109
|
+
readonly measuredAtMs: number;
|
|
110
|
+
}
|
|
111
|
+
interface InsightsGetAppUsageInput {
|
|
112
|
+
readonly channel: string;
|
|
113
|
+
readonly platform: "all" | "ios" | "android";
|
|
114
|
+
readonly appVersion?: string;
|
|
115
|
+
readonly timeRange: InsightsTimeRange;
|
|
116
|
+
readonly intervalMs: number;
|
|
117
|
+
}
|
|
118
|
+
interface InsightsGetAppUsageResult {
|
|
119
|
+
readonly coverage: InsightsCoverage;
|
|
120
|
+
readonly activeInstallations: number;
|
|
121
|
+
readonly points: readonly {
|
|
122
|
+
readonly startMs: number;
|
|
123
|
+
readonly installations: number;
|
|
124
|
+
}[];
|
|
125
|
+
readonly appVersions: readonly string[];
|
|
126
|
+
readonly versions: readonly {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly installations: number;
|
|
129
|
+
}[];
|
|
130
|
+
readonly platforms: readonly {
|
|
131
|
+
readonly name: string;
|
|
132
|
+
readonly installations: number;
|
|
133
|
+
}[];
|
|
134
|
+
readonly bundleDistribution: readonly {
|
|
135
|
+
readonly appVersion: string;
|
|
136
|
+
readonly platform: "ios" | "android";
|
|
137
|
+
readonly releaseId: string | null;
|
|
138
|
+
readonly installations: number;
|
|
139
|
+
}[];
|
|
140
|
+
readonly measuredAtMs: number;
|
|
141
|
+
}
|
|
142
|
+
interface InsightsModel {
|
|
143
|
+
/**
|
|
144
|
+
* Persist the immutable event once. A private latest-event index, if used,
|
|
145
|
+
* advances atomically for a greater (received_at_ms, id). Duplicate event
|
|
146
|
+
* IDs are complete no-ops, whichever installation sends them.
|
|
147
|
+
* Retry the identical prepared input after an ambiguous commit outcome.
|
|
148
|
+
*/
|
|
149
|
+
recordEvent(input: InsightsRecordEventInput): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Descending (received_at_ms, id), in [sinceMs ?? 0, beforeReceivedAtMs).
|
|
152
|
+
* Apply filters and the exclusive cursor before limit (1..101). Return the
|
|
153
|
+
* complete matching prefix; native continuation pages must not truncate it.
|
|
154
|
+
* A global or bundle list may reject a range longer than 90 × 24 hours;
|
|
155
|
+
* the server asks for older events with an earlier range instead.
|
|
156
|
+
*/
|
|
157
|
+
listEvents(input: InsightsListEventsInput): Promise<readonly BundleEventRow[]>;
|
|
158
|
+
/**
|
|
159
|
+
* Choose each installation's greatest (received_at_ms, id) before filtering.
|
|
160
|
+
* Exact installation lookup returns zero or one canonical event. User lookup
|
|
161
|
+
* returns current membership ordered by UTF-8 installation ID, exclusive
|
|
162
|
+
* afterInstallId and limit 1..101. Check lagging index candidates against
|
|
163
|
+
* canonical state; newly indexed associations may temporarily be absent.
|
|
164
|
+
*/
|
|
165
|
+
findLatestEvents(input: InsightsFindLatestEventsInput): Promise<readonly BundleEventRow[]>;
|
|
166
|
+
/** Count latest events once per installation, then apply the supplied predicates. */
|
|
167
|
+
countLatestEvents(input: InsightsCountLatestEventsInput): Promise<number>;
|
|
168
|
+
/** Count accepted reports in [sinceMs, beforeReceivedAtMs), across all pages. */
|
|
169
|
+
countEvents(input: InsightsCountEventsInput): Promise<number>;
|
|
170
|
+
/** Read maintained release/scope summaries without scanning raw events. */
|
|
171
|
+
getReleaseActivity(input: InsightsGetReleaseActivityInput): Promise<InsightsGetReleaseActivityResult>;
|
|
172
|
+
/** Read maintained App usage summaries and latest-report distribution. */
|
|
173
|
+
getAppUsage(input: InsightsGetAppUsageInput): Promise<InsightsGetAppUsageResult>;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { InsightsBundleEventFilter, InsightsCountEventsInput, InsightsCountLatestEventsInput, InsightsCoverage, InsightsEventCursor, InsightsEventFilter, InsightsFindLatestEventsInput, InsightsGetAppUsageInput, InsightsGetAppUsageResult, InsightsGetReleaseActivityInput, InsightsGetReleaseActivityResult, InsightsListEventsInput, InsightsModel, InsightsRecordEventInput, InsightsScope, InsightsTimeRange, ReleaseActivityMetrics, ReleaseReference };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpTestClient } from "./types.mjs";
|
|
2
|
+
//#region src/server/testing/setupInsightsHttpTestSuite.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The Insights plugin's routes on a database: a client reports an event, and
|
|
5
|
+
* the admin routes read it back. The server must run `insights()`.
|
|
6
|
+
*/
|
|
7
|
+
declare const setupInsightsHttpTestSuite: (options: {
|
|
8
|
+
readonly getClient: () => HttpTestClient;
|
|
9
|
+
}) => void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { setupInsightsHttpTestSuite };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { expectInsightsIndex } from "./expectInsightsIndex.mjs";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
//#region src/server/testing/setupInsightsHttpTestSuite.ts
|
|
4
|
+
const jsonRequest = (method, body) => ({
|
|
5
|
+
method,
|
|
6
|
+
headers: { "content-type": "application/json" },
|
|
7
|
+
body: JSON.stringify(body)
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* The Insights plugin's routes on a database: a client reports an event, and
|
|
11
|
+
* the admin routes read it back. The server must run `insights()`.
|
|
12
|
+
*/
|
|
13
|
+
const setupInsightsHttpTestSuite = (options) => {
|
|
14
|
+
describe("Insights HTTP routes", () => {
|
|
15
|
+
it("records a reported event and reads it back", async () => {
|
|
16
|
+
const client = options.getClient();
|
|
17
|
+
const installId = `install-${crypto.randomUUID()}`;
|
|
18
|
+
const userId = `user-${crypto.randomUUID()}`;
|
|
19
|
+
const channel = `insights-${crypto.randomUUID()}`;
|
|
20
|
+
const event = {
|
|
21
|
+
appVersion: "1.0.0",
|
|
22
|
+
channel,
|
|
23
|
+
cohort: "default",
|
|
24
|
+
fingerprintHash: null,
|
|
25
|
+
fromBundleId: null,
|
|
26
|
+
fromReleaseId: null,
|
|
27
|
+
installId,
|
|
28
|
+
platform: "ios",
|
|
29
|
+
toBundleId: "00000000-0000-7000-8000-000000000001",
|
|
30
|
+
toReleaseId: null,
|
|
31
|
+
type: "UNCHANGED",
|
|
32
|
+
updateStrategy: null,
|
|
33
|
+
userId,
|
|
34
|
+
sdkVersion: "2.0.0"
|
|
35
|
+
};
|
|
36
|
+
const reported = await client.client("/events", jsonRequest("POST", event));
|
|
37
|
+
expect(reported.status).toBe(204);
|
|
38
|
+
await reported.text();
|
|
39
|
+
const installation = await client.admin(`/installations/${encodeURIComponent(installId)}`);
|
|
40
|
+
expect(installation.status).toBe(200);
|
|
41
|
+
expect(await installation.json()).toMatchObject({
|
|
42
|
+
installId,
|
|
43
|
+
latestStatus: "UNCHANGED",
|
|
44
|
+
lastKnownBundleId: event.toBundleId,
|
|
45
|
+
channel
|
|
46
|
+
});
|
|
47
|
+
await expectInsightsIndex(async () => {
|
|
48
|
+
return (await (await client.admin(`/installations?userId=${encodeURIComponent(userId)}`)).json()).data.map(({ installId: id }) => id);
|
|
49
|
+
}, [installId]);
|
|
50
|
+
await expectInsightsIndex(async () => {
|
|
51
|
+
return (await (await client.admin(`/overview?platform=ios&channel=${encodeURIComponent(channel)}&window=24h`)).json()).reportingInstallations.count;
|
|
52
|
+
}, 1);
|
|
53
|
+
});
|
|
54
|
+
it("records an update failure in installation history and the failures read", async () => {
|
|
55
|
+
const client = options.getClient();
|
|
56
|
+
const installId = `install-${crypto.randomUUID()}`;
|
|
57
|
+
const channel = `insights-${crypto.randomUUID()}`;
|
|
58
|
+
const releaseId = "00000000-0000-7000-8000-0000000000b2";
|
|
59
|
+
const reported = await client.client("/events", jsonRequest("POST", {
|
|
60
|
+
appVersion: "1.0.0",
|
|
61
|
+
channel,
|
|
62
|
+
cohort: "default",
|
|
63
|
+
fingerprintHash: null,
|
|
64
|
+
fromBundleId: "00000000-0000-7000-8000-000000000001",
|
|
65
|
+
fromReleaseId: null,
|
|
66
|
+
installId,
|
|
67
|
+
platform: "ios",
|
|
68
|
+
toBundleId: "00000000-0000-7000-8000-000000000002",
|
|
69
|
+
toReleaseId: releaseId,
|
|
70
|
+
type: "UPDATE_FAILED",
|
|
71
|
+
updateStrategy: "appVersion",
|
|
72
|
+
metadata: { failure: {
|
|
73
|
+
stage: "download",
|
|
74
|
+
reason: "http",
|
|
75
|
+
httpStatus: 403
|
|
76
|
+
} }
|
|
77
|
+
}));
|
|
78
|
+
expect(reported.status).toBe(204);
|
|
79
|
+
await reported.text();
|
|
80
|
+
await expectInsightsIndex(async () => {
|
|
81
|
+
return (await (await client.admin(`/installations/${encodeURIComponent(installId)}/events?limit=10`)).json()).data.map(({ type, failure }) => ({
|
|
82
|
+
type,
|
|
83
|
+
failure
|
|
84
|
+
}));
|
|
85
|
+
}, [{
|
|
86
|
+
type: "UPDATE_FAILED",
|
|
87
|
+
failure: {
|
|
88
|
+
stage: "download",
|
|
89
|
+
reason: "http",
|
|
90
|
+
httpStatus: 403
|
|
91
|
+
}
|
|
92
|
+
}]);
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
await expectInsightsIndex(async () => {
|
|
95
|
+
const body = await (await client.admin(`/failures?platform=ios&channel=${encodeURIComponent(channel)}&releaseId=${releaseId}&start=${now - 864e5}&end=${now + 36e5}`)).json();
|
|
96
|
+
return [body.failedUpdates, body.failedInstallations];
|
|
97
|
+
}, [1, 1]);
|
|
98
|
+
});
|
|
99
|
+
it("refuses a malformed event", async () => {
|
|
100
|
+
const response = await options.getClient().client("/events", jsonRequest("POST", { type: "UNCHANGED" }));
|
|
101
|
+
expect(response.status).toBe(400);
|
|
102
|
+
await response.text();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { setupInsightsHttpTestSuite };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InsightsModel } from "./modelTypes.mjs";
|
|
2
|
+
import { DatabaseTestLifecycle } from "./types.mjs";
|
|
3
|
+
//#region src/server/testing/setupInsightsModelTestSuite.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Insights report contract on one database: pass the Insights plugin's
|
|
6
|
+
* model over it, `createInsightsModel(createDatabasePluginApis(database,
|
|
7
|
+
* [insights()]).insights)`, as `createDatabase`.
|
|
8
|
+
*/
|
|
9
|
+
declare const setupInsightsModelTestSuite: (lifecycle: DatabaseTestLifecycle<InsightsModel>) => void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { setupInsightsModelTestSuite };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { registerInsightsModelTests } from "./insightsModelTests.mjs";
|
|
2
|
+
import { afterAll, beforeAll, beforeEach, describe } from "vitest";
|
|
3
|
+
//#region src/server/testing/setupInsightsModelTestSuite.ts
|
|
4
|
+
/**
|
|
5
|
+
* The Insights report contract on one database: pass the Insights plugin's
|
|
6
|
+
* model over it, `createInsightsModel(createDatabasePluginApis(database,
|
|
7
|
+
* [insights()]).insights)`, as `createDatabase`.
|
|
8
|
+
*/
|
|
9
|
+
const setupInsightsModelTestSuite = (lifecycle) => {
|
|
10
|
+
describe(lifecycle.name, () => {
|
|
11
|
+
let model;
|
|
12
|
+
const getDatabase = () => {
|
|
13
|
+
if (model === void 0) throw new Error("The model is unavailable outside the test lifecycle");
|
|
14
|
+
return model;
|
|
15
|
+
};
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
await lifecycle.migrate();
|
|
18
|
+
model = await lifecycle.createDatabase();
|
|
19
|
+
});
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
await lifecycle.reset(getDatabase());
|
|
22
|
+
});
|
|
23
|
+
afterAll(async () => {
|
|
24
|
+
await lifecycle.dispose(getDatabase());
|
|
25
|
+
model = void 0;
|
|
26
|
+
});
|
|
27
|
+
registerInsightsModelTests({ getDatabase });
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { setupInsightsModelTestSuite };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/server/testing/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The shapes `@hot-updater/test-utils` passes a plugin's suite, restated
|
|
4
|
+
* here so the plugin's tests need no dependency on that package.
|
|
5
|
+
*/
|
|
6
|
+
type HttpTestRequest = (path: string, init?: NonNullable<ConstructorParameters<typeof Request>[1]>) => Promise<Response>;
|
|
7
|
+
/** A running server's client and admin mounts. */
|
|
8
|
+
interface HttpTestClient {
|
|
9
|
+
readonly client: HttpTestRequest;
|
|
10
|
+
readonly admin: HttpTestRequest;
|
|
11
|
+
}
|
|
12
|
+
type DatabaseTestState<TDatabase> = {
|
|
13
|
+
readonly getDatabase: () => TDatabase;
|
|
14
|
+
};
|
|
15
|
+
type Awaitable<T> = Promise<T> | T;
|
|
16
|
+
/** How a suite gets a database, and gives it back. */
|
|
17
|
+
type DatabaseTestLifecycle<TDatabase> = {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly migrate: () => Awaitable<void>;
|
|
20
|
+
readonly createDatabase: () => Awaitable<TDatabase>;
|
|
21
|
+
/** Empties every table between tests. */
|
|
22
|
+
readonly reset: (database: TDatabase) => Awaitable<void>;
|
|
23
|
+
readonly dispose: (database: TDatabase) => Awaitable<void>;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DatabaseTestLifecycle, DatabaseTestState, HttpTestClient, HttpTestRequest };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { InsightsScope } from "./modelTypes.cjs";
|
|
2
|
+
import { ActiveInstallationWindow, CreateBundleEventRequest, CursorPage, EventCursorPage, EventHistoryRow, InsightsBundleSelection, InstallationHistoryRow, InstallationRow, ReportingOverview } from "./domain.cjs";
|
|
3
|
+
//#region src/server/types.d.ts
|
|
4
|
+
type InsightsEventPageInput = {
|
|
5
|
+
readonly beforeReceivedAtMs?: number;
|
|
6
|
+
readonly sinceMs?: number;
|
|
7
|
+
readonly bundle?: InsightsBundleSelection;
|
|
8
|
+
readonly cursor?: string;
|
|
9
|
+
readonly limit?: number;
|
|
10
|
+
};
|
|
11
|
+
type InsightsInstallationEventPageInput = Omit<InsightsEventPageInput, "bundle"> & {
|
|
12
|
+
readonly installId: string;
|
|
13
|
+
};
|
|
14
|
+
type InsightsUserInstallationPageInput = {
|
|
15
|
+
readonly userId: string;
|
|
16
|
+
readonly cursor?: string;
|
|
17
|
+
readonly limit?: number;
|
|
18
|
+
};
|
|
19
|
+
type InsightsProvider = {
|
|
20
|
+
appendBundleEvent(input: CreateBundleEventRequest): Promise<void>;
|
|
21
|
+
listEvents(input: InsightsEventPageInput): Promise<EventCursorPage<EventHistoryRow>>;
|
|
22
|
+
listInstallationEvents(input: InsightsInstallationEventPageInput): Promise<EventCursorPage<InstallationHistoryRow>>;
|
|
23
|
+
getInstallation(input: {
|
|
24
|
+
readonly installId: string;
|
|
25
|
+
}): Promise<InstallationRow | null>;
|
|
26
|
+
pageInstallationsByCurrentUserId(input: InsightsUserInstallationPageInput): Promise<CursorPage<InstallationRow>>;
|
|
27
|
+
getReportingOverview(input: InsightsScope & {
|
|
28
|
+
readonly window: ActiveInstallationWindow;
|
|
29
|
+
readonly bundleId?: string;
|
|
30
|
+
}): Promise<ReportingOverview>;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { InsightsEventPageInput, InsightsInstallationEventPageInput, InsightsProvider, InsightsUserInstallationPageInput };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { InsightsScope } from "./modelTypes.mjs";
|
|
2
|
+
import { ActiveInstallationWindow, CreateBundleEventRequest, CursorPage, EventCursorPage, EventHistoryRow, InsightsBundleSelection, InstallationHistoryRow, InstallationRow, ReportingOverview } from "./domain.mjs";
|
|
3
|
+
//#region src/server/types.d.ts
|
|
4
|
+
type InsightsEventPageInput = {
|
|
5
|
+
readonly beforeReceivedAtMs?: number;
|
|
6
|
+
readonly sinceMs?: number;
|
|
7
|
+
readonly bundle?: InsightsBundleSelection;
|
|
8
|
+
readonly cursor?: string;
|
|
9
|
+
readonly limit?: number;
|
|
10
|
+
};
|
|
11
|
+
type InsightsInstallationEventPageInput = Omit<InsightsEventPageInput, "bundle"> & {
|
|
12
|
+
readonly installId: string;
|
|
13
|
+
};
|
|
14
|
+
type InsightsUserInstallationPageInput = {
|
|
15
|
+
readonly userId: string;
|
|
16
|
+
readonly cursor?: string;
|
|
17
|
+
readonly limit?: number;
|
|
18
|
+
};
|
|
19
|
+
type InsightsProvider = {
|
|
20
|
+
appendBundleEvent(input: CreateBundleEventRequest): Promise<void>;
|
|
21
|
+
listEvents(input: InsightsEventPageInput): Promise<EventCursorPage<EventHistoryRow>>;
|
|
22
|
+
listInstallationEvents(input: InsightsInstallationEventPageInput): Promise<EventCursorPage<InstallationHistoryRow>>;
|
|
23
|
+
getInstallation(input: {
|
|
24
|
+
readonly installId: string;
|
|
25
|
+
}): Promise<InstallationRow | null>;
|
|
26
|
+
pageInstallationsByCurrentUserId(input: InsightsUserInstallationPageInput): Promise<CursorPage<InstallationRow>>;
|
|
27
|
+
getReportingOverview(input: InsightsScope & {
|
|
28
|
+
readonly window: ActiveInstallationWindow;
|
|
29
|
+
readonly bundleId?: string;
|
|
30
|
+
}): Promise<ReportingOverview>;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { InsightsEventPageInput, InsightsInstallationEventPageInput, InsightsProvider, InsightsUserInstallationPageInput };
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hot-updater/plugin-insights",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-rc.20",
|
|
5
|
+
"description": "Hot Updater's Insights plugin: launch, download, and update failure events, for the server and the React Native app",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./client": {
|
|
8
|
+
"import": "./dist/client/index.mjs",
|
|
9
|
+
"require": "./dist/client/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./internal": {
|
|
12
|
+
"import": "./dist/internal.mjs",
|
|
13
|
+
"require": "./dist/internal.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./server": {
|
|
16
|
+
"import": "./dist/server/index.mjs",
|
|
17
|
+
"require": "./dist/server/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
"./testing": {
|
|
21
|
+
"import": "./dist/server/testing/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/gronxb/hot-updater"
|
|
28
|
+
},
|
|
29
|
+
"author": "gronxb <gron1gh1@gmail.com> (https://github.com/gronxb)",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/gronxb/hot-updater/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/gronxb/hot-updater#readme",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"client",
|
|
40
|
+
"package.json"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@hot-updater/core": "1.0.0-rc.20",
|
|
44
|
+
"@hot-updater/plugin-core": "1.0.0-rc.20"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"vitest": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"vitest": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^20",
|
|
56
|
+
"vitest": "4.1.4",
|
|
57
|
+
"@hot-updater/test-utils": "1.0.0-rc.20"
|
|
58
|
+
},
|
|
59
|
+
"nx": {
|
|
60
|
+
"implicitDependencies": [
|
|
61
|
+
"!@hot-updater/test-utils"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsdown",
|
|
66
|
+
"test:type": "tsc --noEmit"
|
|
67
|
+
}
|
|
68
|
+
}
|