@debugkit/dashboard 0.7.0 → 0.9.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/client/assets/_authed-C29P68T-.js +1 -0
- package/dist/client/assets/_authed-D-dYbHoP.js +7 -0
- package/dist/client/assets/{charts-XyOWJI9T.js → charts--S1o8iId.js} +6 -6
- package/dist/client/assets/copy-button-BJkvWYRY.js +1 -0
- package/dist/client/assets/customers-Cwx5qEO1.js +1 -0
- package/dist/client/assets/endpoints-zz1TotR2.js +1 -0
- package/dist/client/assets/events._eventId-Bx6TfUjv.js +3 -0
- package/dist/client/assets/index-COHr_cc3.js +10 -0
- package/dist/client/assets/invite._token-DiDJMnQu.js +1 -0
- package/dist/client/assets/issues._fingerprint-Cv522h2j.js +1 -0
- package/dist/client/assets/login-CKkpc0t5.js +1 -0
- package/dist/client/assets/sessions._sessionId-B0NxM46y.js +1 -0
- package/dist/client/assets/settings-CIlF10MI.js +1 -0
- package/dist/client/assets/src-BKSiJUs3.js +3 -0
- package/dist/client/assets/styles-GAsMUS4-.css +2 -0
- package/dist/client/assets/team-BRuVQ2bU.js +1 -0
- package/dist/client/assets/timeline-BIGo9MCA.js +1 -0
- package/dist/client/assets/ui-CaEZB1j2.js +1 -0
- package/dist/client/assets/version-banner-VFvyqbPh.js +1 -0
- package/dist/server/assets/_authed-BJWDiF9i.js +92 -0
- package/dist/server/assets/{_authed-C-sIPXSO.js → _authed-X9u_5JUy.js} +318 -126
- package/dist/server/assets/_tanstack-start-manifest_v-C6vaeBdY.js +90 -0
- package/dist/server/assets/copy-button-D3RddzTw.js +52 -0
- package/dist/server/assets/customers-827fC5I3.js +163 -0
- package/dist/server/assets/{demo-BsMMDk_F.js → demo-DDNiXCgj.js} +29 -7
- package/dist/server/assets/{dynamodb-Zkk1-mgz.js → dynamodb-Cd4blXkh.js} +98 -17
- package/dist/server/assets/endpoints-_T0NSOyA.js +371 -0
- package/dist/server/assets/{queries-BJxX3Kjp.js → errors-Po4Tt5zd.js} +893 -66
- package/dist/server/assets/events._eventId-Dcsu4oVO.js +765 -0
- package/dist/server/assets/{firestore-C52q_vwM.js → firestore-c8Sz2Q4O.js} +26 -6
- package/dist/server/assets/{fns-DwGaMi8S.js → fns-BiUOnY1_.js} +27 -3
- package/dist/server/assets/fns-CVbk8Gf9.js +1310 -0
- package/dist/server/assets/{invite._token-xnpnkdRv.js → invite._token-7DjEeeaD.js} +3 -3
- package/dist/server/assets/{issues._fingerprint-e7ubdJf0.js → issues._fingerprint-vc9r3jgg.js} +89 -11
- package/dist/server/assets/{login-EopnOJXA.js → login-CwKAx9Bj.js} +3 -3
- package/dist/server/assets/{memory-BssaqdZm.js → memory-Bv4C8uyK.js} +431 -28
- package/dist/server/assets/router-Dk3XHn7B.js +512 -0
- package/dist/server/assets/sessions._sessionId-BvXxK9qF.js +264 -0
- package/dist/server/assets/{settings-CaJN69N6.js → settings-B9NLQjl1.js} +221 -5
- package/dist/server/assets/{src-D83GYTrp.js → src-oWPSAvXv.js} +1 -1
- package/dist/server/assets/{team-B1UcM1jA.js → team-Bsm2wFG0.js} +3 -3
- package/dist/server/assets/timeline-MDRNDhiA.js +132 -0
- package/dist/server/assets/{ui-BJokJdYa.js → ui-SAkSlP7f.js} +53 -13
- package/dist/server/assets/version-banner-nf-yZurq.js +106 -0
- package/dist/server/assets/versions-BOlL8jam.js +58 -0
- package/dist/server/server.js +41 -21
- package/package.json +4 -4
- package/dist/client/assets/_authed-BN39b-7H.js +0 -1
- package/dist/client/assets/_authed-CspAf0jN.js +0 -7
- package/dist/client/assets/index-Bfb2UOzB.js +0 -10
- package/dist/client/assets/invite._token-B4HN51-h.js +0 -1
- package/dist/client/assets/issues._fingerprint-BV1QrETY.js +0 -1
- package/dist/client/assets/login-COlvJ5Je.js +0 -1
- package/dist/client/assets/preload-helper-Dscj_TcA.js +0 -3
- package/dist/client/assets/settings-Dl4EWeWC.js +0 -1
- package/dist/client/assets/styles-DztngwT9.css +0 -2
- package/dist/client/assets/team-7Zekz_Er.js +0 -1
- package/dist/client/assets/ui-C0HGOza2.js +0 -1
- package/dist/server/assets/_authed-CrjuC0O3.js +0 -73
- package/dist/server/assets/_tanstack-start-manifest_v-CqaE4wze.js +0 -61
- package/dist/server/assets/fns-mbUIXXep.js +0 -529
- package/dist/server/assets/router-G99085_Q.js +0 -315
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { a as joined, i as clock, r as OutcomeBadge } from "./timeline-MDRNDhiA.js";
|
|
2
|
+
import { l as timeAgo, t as Card } from "./ui-SAkSlP7f.js";
|
|
3
|
+
import { l as Route } from "./router-Dk3XHn7B.js";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { Link, useNavigate } from "@tanstack/react-router";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/routes/_authed/customers.tsx?tsr-split=component
|
|
8
|
+
/** "No errors", "3 errors, all caught", "3 errors, 1 caught". */
|
|
9
|
+
function errorCount(errors, handled) {
|
|
10
|
+
if (!errors) return "No errors";
|
|
11
|
+
const n = `${errors} error${errors === 1 ? "" : "s"}`;
|
|
12
|
+
return handled === errors ? `${n}, ${errors === 1 ? "caught" : "all caught"}` : handled ? `${n}, ${handled} caught` : n;
|
|
13
|
+
}
|
|
14
|
+
var MATCHED = {
|
|
15
|
+
id: "customer number",
|
|
16
|
+
anonymousId: "install id"
|
|
17
|
+
};
|
|
18
|
+
function CustomersPage() {
|
|
19
|
+
const { apps, app, store, lookup, missingIndex } = Route.useLoaderData();
|
|
20
|
+
const search = Route.useSearch();
|
|
21
|
+
const navigate = useNavigate({ from: Route.fullPath });
|
|
22
|
+
const [q, setQ] = useState(search.q ?? "");
|
|
23
|
+
useEffect(() => setQ(search.q ?? ""), [search.q]);
|
|
24
|
+
const where = app ?? (apps.length > 1 ? "any app" : apps[0]);
|
|
25
|
+
return /* @__PURE__ */ jsxs("main", {
|
|
26
|
+
className: "mx-auto max-w-5xl space-y-5 px-4 py-6 sm:px-6",
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h1", {
|
|
29
|
+
className: "text-xl font-semibold tracking-tight",
|
|
30
|
+
children: "Find a customer"
|
|
31
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
32
|
+
className: "mt-1 text-sm text-muted",
|
|
33
|
+
children: "A customer number in any format (0841234567, 27841234567, +27 84 123 4567) or an install id. Their sessions are listed newest first."
|
|
34
|
+
})] }),
|
|
35
|
+
/* @__PURE__ */ jsxs("form", {
|
|
36
|
+
role: "search",
|
|
37
|
+
className: "flex flex-wrap items-center gap-2",
|
|
38
|
+
onSubmit: (e) => {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
navigate({ search: (s) => ({
|
|
41
|
+
...s,
|
|
42
|
+
q: q.trim() || void 0
|
|
43
|
+
}) });
|
|
44
|
+
},
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx("input", {
|
|
47
|
+
type: "search",
|
|
48
|
+
"aria-label": "Customer number or install id",
|
|
49
|
+
value: q,
|
|
50
|
+
onChange: (e) => setQ(e.target.value),
|
|
51
|
+
placeholder: "Customer number or install id",
|
|
52
|
+
autoFocus: true,
|
|
53
|
+
className: "min-w-0 flex-1 rounded-md border border-line bg-panel px-3 py-2 font-mono text-sm text-ink sm:max-w-md"
|
|
54
|
+
}),
|
|
55
|
+
apps.length > 1 && /* @__PURE__ */ jsxs("select", {
|
|
56
|
+
"aria-label": "App",
|
|
57
|
+
value: app ?? "",
|
|
58
|
+
onChange: (e) => navigate({ search: (s) => ({
|
|
59
|
+
...s,
|
|
60
|
+
app: e.target.value || void 0
|
|
61
|
+
}) }),
|
|
62
|
+
className: "rounded-md border border-line bg-panel px-2 py-2 text-sm",
|
|
63
|
+
children: [/* @__PURE__ */ jsx("option", {
|
|
64
|
+
value: "",
|
|
65
|
+
children: "All apps"
|
|
66
|
+
}), apps.map((a) => /* @__PURE__ */ jsx("option", { children: a }, a))]
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx("button", {
|
|
69
|
+
type: "submit",
|
|
70
|
+
className: "rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:opacity-90",
|
|
71
|
+
children: "Find"
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
missingIndex && /* @__PURE__ */ jsx("p", {
|
|
76
|
+
className: "text-sm text-muted",
|
|
77
|
+
children: "Firestore needs deBug's new indexes on events (user.id, ts) and (user.anonymousId, ts). Deploy them with: firebase deploy --only firestore:indexes, using deBug's firestore.indexes.json. They take a few minutes to build."
|
|
78
|
+
}),
|
|
79
|
+
!apps.length && /* @__PURE__ */ jsx("p", {
|
|
80
|
+
className: "text-sm text-muted",
|
|
81
|
+
children: "No apps have sent events yet."
|
|
82
|
+
}),
|
|
83
|
+
lookup && (lookup.sessions.length === 0 ? /* @__PURE__ */ jsxs("p", {
|
|
84
|
+
className: "text-sm text-muted",
|
|
85
|
+
children: [
|
|
86
|
+
"No sessions found for ",
|
|
87
|
+
/* @__PURE__ */ jsx("span", {
|
|
88
|
+
className: "font-mono text-ink",
|
|
89
|
+
children: lookup.query
|
|
90
|
+
}),
|
|
91
|
+
" in ",
|
|
92
|
+
where,
|
|
93
|
+
". Events are kept for the retention period only, and a customer number is only known once the app sets it.",
|
|
94
|
+
store === "dynamodb" && " On DynamoDB, only events stored since deBug started keeping them by customer can be found."
|
|
95
|
+
]
|
|
96
|
+
}) : /* @__PURE__ */ jsxs(Card, {
|
|
97
|
+
title: `${lookup.sessions.length} session${lookup.sessions.length === 1 ? "" : "s"}`,
|
|
98
|
+
subtitle: `Matched by ${lookup.matched.map((m) => MATCHED[m]).join(" and ")}. Only sessions with a stored error or flow event are listed.`,
|
|
99
|
+
children: [/* @__PURE__ */ jsx("ul", {
|
|
100
|
+
className: "divide-y divide-line",
|
|
101
|
+
children: lookup.sessions.map((s) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(Link, {
|
|
102
|
+
to: "/sessions/$sessionId",
|
|
103
|
+
params: { sessionId: s.sessionId },
|
|
104
|
+
search: { app: s.app },
|
|
105
|
+
className: "grid grid-cols-[1fr_auto] items-center gap-x-4 gap-y-1 px-1 py-2.5 hover:bg-panel-2 sm:grid-cols-[11rem_6.5rem_1fr_auto]",
|
|
106
|
+
children: [
|
|
107
|
+
/* @__PURE__ */ jsxs("span", {
|
|
108
|
+
className: "text-sm",
|
|
109
|
+
title: `First stored event ${s.start}, last ${s.end}`,
|
|
110
|
+
children: [clock(s.end), /* @__PURE__ */ jsx("span", {
|
|
111
|
+
className: "block text-xs text-muted",
|
|
112
|
+
children: timeAgo(s.end)
|
|
113
|
+
})]
|
|
114
|
+
}),
|
|
115
|
+
/* @__PURE__ */ jsx("span", {
|
|
116
|
+
className: "justify-self-end sm:justify-self-start",
|
|
117
|
+
children: /* @__PURE__ */ jsx(OutcomeBadge, { outcome: s.outcome })
|
|
118
|
+
}),
|
|
119
|
+
/* @__PURE__ */ jsxs("span", {
|
|
120
|
+
className: "min-w-0 text-sm",
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ jsx("span", {
|
|
123
|
+
className: "text-muted",
|
|
124
|
+
children: "App "
|
|
125
|
+
}),
|
|
126
|
+
joined([s.context.app.version, s.context.app.build && `(${s.context.app.build})`]) ?? "—",
|
|
127
|
+
/* @__PURE__ */ jsx("span", {
|
|
128
|
+
className: "text-muted",
|
|
129
|
+
children: " · "
|
|
130
|
+
}),
|
|
131
|
+
joined([s.context.device.brand, s.context.device.model]) ?? joined([s.context.os.name, s.context.os.version]) ?? "—",
|
|
132
|
+
!app && apps.length > 1 && /* @__PURE__ */ jsxs("span", {
|
|
133
|
+
className: "text-muted",
|
|
134
|
+
children: [" · ", s.app]
|
|
135
|
+
}),
|
|
136
|
+
s.user.id && s.user.id !== lookup.query && /* @__PURE__ */ jsx("span", {
|
|
137
|
+
className: "ml-2 font-mono text-xs text-muted",
|
|
138
|
+
children: s.user.id
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsxs("span", {
|
|
143
|
+
className: "text-xs text-muted sm:text-right",
|
|
144
|
+
children: [errorCount(s.errors, s.handled), s.failedFlows > 0 && /* @__PURE__ */ jsxs("span", {
|
|
145
|
+
className: "block font-medium text-sev-high",
|
|
146
|
+
children: [
|
|
147
|
+
s.failedFlows,
|
|
148
|
+
" failed flow",
|
|
149
|
+
s.failedFlows === 1 ? "" : "s"
|
|
150
|
+
]
|
|
151
|
+
})]
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
}) }, s.sessionId))
|
|
155
|
+
}), lookup.truncated && /* @__PURE__ */ jsx("p", {
|
|
156
|
+
className: "mt-3 text-xs text-muted",
|
|
157
|
+
children: "This customer has more stored events than one lookup reads: older sessions are left out, and the oldest one listed may be only partly read."
|
|
158
|
+
})]
|
|
159
|
+
}))
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
export { CustomersPage as component };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as MemoryStore } from "./memory-
|
|
2
|
-
import {
|
|
1
|
+
import { t as MemoryStore } from "./memory-Bv4C8uyK.js";
|
|
2
|
+
import { C as ingest } from "./errors-Po4Tt5zd.js";
|
|
3
|
+
import { n as version } from "./versions-BOlL8jam.js";
|
|
3
4
|
// src/server/demo.ts
|
|
4
5
|
/**
|
|
5
6
|
* Builds a realistic 14-day dataset for a fictional app by pushing synthetic SDK
|
|
@@ -146,7 +147,26 @@ async function seedDemo() {
|
|
|
146
147
|
method: "GET",
|
|
147
148
|
url: "/v1/feed",
|
|
148
149
|
status: 502,
|
|
149
|
-
message: "GET /v1/feed responded 502"
|
|
150
|
+
message: "GET /v1/feed responded 502",
|
|
151
|
+
captured: {
|
|
152
|
+
request: {
|
|
153
|
+
query: "page=2&session=[redacted]",
|
|
154
|
+
headers: {
|
|
155
|
+
accept: "application/json",
|
|
156
|
+
authorization: "[redacted]",
|
|
157
|
+
"x-app-version": "2.4.0"
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
response: {
|
|
161
|
+
status: 502,
|
|
162
|
+
headers: {
|
|
163
|
+
"content-type": "text/html",
|
|
164
|
+
server: "nginx"
|
|
165
|
+
},
|
|
166
|
+
body: "<html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center></body></html>",
|
|
167
|
+
bodySize: 108
|
|
168
|
+
}
|
|
169
|
+
}
|
|
150
170
|
}
|
|
151
171
|
},
|
|
152
172
|
{
|
|
@@ -229,7 +249,7 @@ async function seedDemo() {
|
|
|
229
249
|
["Africa/Gaborone", "en-BW"]
|
|
230
250
|
];
|
|
231
251
|
for (let dayAgo = 13; dayAgo >= 0; dayAgo--) {
|
|
232
|
-
const version = dayAgo <= 3 ? pick([
|
|
252
|
+
const version$1 = dayAgo <= 3 ? pick([
|
|
233
253
|
"2.4.0",
|
|
234
254
|
"2.4.0",
|
|
235
255
|
"2.4.0",
|
|
@@ -242,7 +262,7 @@ async function seedDemo() {
|
|
|
242
262
|
for (let s = 0; s < 70; s++) {
|
|
243
263
|
const ts = (/* @__PURE__ */ new Date(now - dayAgo * 864e5 - Math.floor(rand() * 864e5))).toISOString();
|
|
244
264
|
const dev = pick(devices);
|
|
245
|
-
const appVersion = rand() < .85 ? version : "2.3.1";
|
|
265
|
+
const appVersion = rand() < .85 ? version$1 : "2.3.1";
|
|
246
266
|
const events = [];
|
|
247
267
|
const userId = `user_${Math.floor(rand() * 400)}`;
|
|
248
268
|
const id = () => `evt_${(seq++).toString().padStart(10, "0")}`;
|
|
@@ -269,8 +289,10 @@ async function seedDemo() {
|
|
|
269
289
|
method: r.method,
|
|
270
290
|
url: r.url,
|
|
271
291
|
status: r.status,
|
|
272
|
-
durationMs: r.status ? 2210 : 3e4
|
|
292
|
+
durationMs: r.status ? 2210 : 3e4,
|
|
293
|
+
...r.captured?.request
|
|
273
294
|
},
|
|
295
|
+
...r.captured ? { response: r.captured.response } : {},
|
|
274
296
|
breadcrumbs: (sc.crumbs ?? []).map((c) => ({
|
|
275
297
|
ts,
|
|
276
298
|
level: c.level ?? "info",
|
|
@@ -357,7 +379,7 @@ async function seedDemo() {
|
|
|
357
379
|
const env = {
|
|
358
380
|
sdk: {
|
|
359
381
|
name: "@debugkit/sdk",
|
|
360
|
-
version
|
|
382
|
+
version
|
|
361
383
|
},
|
|
362
384
|
context: {
|
|
363
385
|
app: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./src-
|
|
1
|
+
import { o as versionKey, p as isRegression, s as coalesceRollups } from "./memory-Bv4C8uyK.js";
|
|
2
|
+
import "./src-oWPSAvXv.js";
|
|
3
3
|
import { BatchWriteCommand, GetCommand, PutCommand, QueryCommand, UpdateCommand } from "@aws-sdk/lib-dynamodb";
|
|
4
4
|
// ../../packages/adapters/src/dynamodb.ts
|
|
5
5
|
/**
|
|
@@ -11,7 +11,11 @@ import { BatchWriteCommand, GetCommand, PutCommand, QueryCommand, UpdateCommand
|
|
|
11
11
|
* APP#{app}#ROLLUP#{dimension} | {day}#{key} RollupRow (ADD counters)
|
|
12
12
|
* APP#{app}#ISSUEEV#{fp} | {ts}#{id} StoredEvent (error events by issue)
|
|
13
13
|
* APP#{app}#EV#{day} | {ts}#{id} StoredEvent (all events by day)
|
|
14
|
+
* APP#{app}#SESSEV#{sessionId} | {ts}#{id} StoredEvent (all events by session)
|
|
15
|
+
* APP#{app}#USEREV#id#{userId} | {ts}#{id} StoredEvent (by customer number, user.id)
|
|
16
|
+
* APP#{app}#USEREV#anonymousId#{anonymousId} | {ts}#{id} StoredEvent (by install id)
|
|
14
17
|
* APP#{app}#SETTINGS | app AppSettings
|
|
18
|
+
* APP#{app}#VERSIONS | v Versions (sdk, sdkKey, sdkSeenAt, ingest, ingestAt)
|
|
15
19
|
* APP#{app}#USERS#{scope} | {member} { lastDay } (hashed ids; for "users affected")
|
|
16
20
|
*
|
|
17
21
|
* TEAM | M#{email} TeamMember (dashboard logins)
|
|
@@ -123,6 +127,58 @@ var DynamoStore = class {
|
|
|
123
127
|
}
|
|
124
128
|
}));
|
|
125
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* The SDK version only moves forward: a conditional update on its sortable key (versionKey), so two
|
|
132
|
+
* ingests seeing different SDKs keep the newer, and the same one again moves its seenAt on. The
|
|
133
|
+
* ingest version is whoever wrote last.
|
|
134
|
+
*/
|
|
135
|
+
async recordVersions(app, seen) {
|
|
136
|
+
const Key = {
|
|
137
|
+
pk: `APP#${app}#VERSIONS`,
|
|
138
|
+
sk: "v"
|
|
139
|
+
};
|
|
140
|
+
const key = versionKey(seen.sdk);
|
|
141
|
+
await Promise.all([key && this.doc.send(new UpdateCommand({
|
|
142
|
+
TableName: this.table,
|
|
143
|
+
Key,
|
|
144
|
+
UpdateExpression: "SET sdk = :v, sdkKey = :k, sdkSeenAt = :at",
|
|
145
|
+
ConditionExpression: "attribute_not_exists(sdkKey) OR sdkKey <= :k",
|
|
146
|
+
ExpressionAttributeValues: {
|
|
147
|
+
":v": seen.sdk,
|
|
148
|
+
":k": key,
|
|
149
|
+
":at": seen.at
|
|
150
|
+
}
|
|
151
|
+
})).catch((e) => {
|
|
152
|
+
if (e.name !== "ConditionalCheckFailedException") throw e;
|
|
153
|
+
}), this.doc.send(new UpdateCommand({
|
|
154
|
+
TableName: this.table,
|
|
155
|
+
Key,
|
|
156
|
+
UpdateExpression: "SET ingest = :v, ingestAt = :at",
|
|
157
|
+
ExpressionAttributeValues: {
|
|
158
|
+
":v": seen.ingest,
|
|
159
|
+
":at": seen.at
|
|
160
|
+
}
|
|
161
|
+
}))]);
|
|
162
|
+
}
|
|
163
|
+
async getVersions(app) {
|
|
164
|
+
const i = (await this.doc.send(new GetCommand({
|
|
165
|
+
TableName: this.table,
|
|
166
|
+
Key: {
|
|
167
|
+
pk: `APP#${app}#VERSIONS`,
|
|
168
|
+
sk: "v"
|
|
169
|
+
}
|
|
170
|
+
}))).Item;
|
|
171
|
+
return {
|
|
172
|
+
...i?.sdk && i.sdkSeenAt ? { sdk: {
|
|
173
|
+
version: i.sdk,
|
|
174
|
+
seenAt: i.sdkSeenAt
|
|
175
|
+
} } : {},
|
|
176
|
+
...i?.ingest && i.ingestAt ? { ingest: {
|
|
177
|
+
version: i.ingest,
|
|
178
|
+
at: i.ingestAt
|
|
179
|
+
} } : {}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
126
182
|
async writeEvents(events, opts = {}) {
|
|
127
183
|
const days = opts.retentionDays ?? this.opts.retentionDays ?? 30;
|
|
128
184
|
const ttl = (e) => Math.floor(Date.parse(e.receivedAt) / 1e3) + days * 86400;
|
|
@@ -132,17 +188,11 @@ var DynamoStore = class {
|
|
|
132
188
|
...e,
|
|
133
189
|
ttl: ttl(e)
|
|
134
190
|
};
|
|
135
|
-
|
|
136
|
-
pk
|
|
137
|
-
sk,
|
|
138
|
-
...base
|
|
139
|
-
}];
|
|
140
|
-
if (e.fingerprint) rows.push({
|
|
141
|
-
pk: `APP#${e.app}#ISSUEEV#${e.fingerprint}`,
|
|
191
|
+
return [`APP#${e.app}#EV#${e.day}`, ...copyKeys(e)].map((pk) => ({
|
|
192
|
+
pk,
|
|
142
193
|
sk,
|
|
143
194
|
...base
|
|
144
|
-
});
|
|
145
|
-
return rows;
|
|
195
|
+
}));
|
|
146
196
|
});
|
|
147
197
|
for (let i = 0; i < items.length; i += 25) {
|
|
148
198
|
let req = { [this.table]: items.slice(i, i + 25).map((Item) => ({ PutRequest: { Item } })) };
|
|
@@ -355,13 +405,10 @@ var DynamoStore = class {
|
|
|
355
405
|
const items = await this.queryAll({ pk: `APP#${app}#EV#${day}` });
|
|
356
406
|
for (const item of items) {
|
|
357
407
|
const ttl = Math.floor(Date.parse(item.receivedAt) / 1e3) + retentionDays * 86400;
|
|
358
|
-
const keys = [{
|
|
359
|
-
pk
|
|
408
|
+
const keys = [item.pk, ...copyKeys(item)].map((pk) => ({
|
|
409
|
+
pk,
|
|
360
410
|
sk: item.sk
|
|
361
|
-
}
|
|
362
|
-
pk: `APP#${app}#ISSUEEV#${item.fingerprint}`,
|
|
363
|
-
sk: item.sk
|
|
364
|
-
}] : []];
|
|
411
|
+
}));
|
|
365
412
|
await Promise.all(keys.map((Key) => this.doc.send(new UpdateCommand({
|
|
366
413
|
TableName: this.table,
|
|
367
414
|
Key,
|
|
@@ -406,6 +453,30 @@ var DynamoStore = class {
|
|
|
406
453
|
between: [`${fromDay}#`, `${toDay}#`]
|
|
407
454
|
})).map((i) => clean(i));
|
|
408
455
|
}
|
|
456
|
+
async listSessionEvents(app, sessionId, { limit = 500 } = {}) {
|
|
457
|
+
return (await this.newest(`APP#${app}#SESSEV#${sessionId}`, limit)).map((i) => clean(i)).reverse();
|
|
458
|
+
}
|
|
459
|
+
/** A partition's newest `limit` items, a page at a time: a query stops at 1 MB, well short of 500 events with trails. */
|
|
460
|
+
async newest(pk, limit) {
|
|
461
|
+
const items = [];
|
|
462
|
+
let ExclusiveStartKey;
|
|
463
|
+
do {
|
|
464
|
+
const out = await this.doc.send(new QueryCommand({
|
|
465
|
+
TableName: this.table,
|
|
466
|
+
KeyConditionExpression: "pk = :pk",
|
|
467
|
+
ExpressionAttributeValues: { ":pk": pk },
|
|
468
|
+
ScanIndexForward: false,
|
|
469
|
+
Limit: limit - items.length,
|
|
470
|
+
ExclusiveStartKey
|
|
471
|
+
}));
|
|
472
|
+
items.push(...out.Items ?? []);
|
|
473
|
+
ExclusiveStartKey = out.LastEvaluatedKey;
|
|
474
|
+
} while (ExclusiveStartKey && items.length < limit);
|
|
475
|
+
return items;
|
|
476
|
+
}
|
|
477
|
+
async listUserEvents(app, field, values, { limit = 500 } = {}) {
|
|
478
|
+
return (await Promise.all(values.map((v) => this.newest(userKey(app, field, v), limit)))).flat().sort((a, b) => String(b.sk).localeCompare(String(a.sk))).slice(0, limit).map((i) => clean(i));
|
|
479
|
+
}
|
|
409
480
|
async listIssueEvents(app, fp, { limit = 50 } = {}) {
|
|
410
481
|
return ((await this.doc.send(new QueryCommand({
|
|
411
482
|
TableName: this.table,
|
|
@@ -435,6 +506,16 @@ var DynamoStore = class {
|
|
|
435
506
|
return items;
|
|
436
507
|
}
|
|
437
508
|
};
|
|
509
|
+
var userKey = (app, field, value) => `APP#${app}#USEREV#${field}#${value}`;
|
|
510
|
+
/** The partitions an event is copied into besides its day: by issue, session and user. */
|
|
511
|
+
function copyKeys(e) {
|
|
512
|
+
return [
|
|
513
|
+
...e.fingerprint ? [`APP#${e.app}#ISSUEEV#${e.fingerprint}`] : [],
|
|
514
|
+
...e.sessionId ? [`APP#${e.app}#SESSEV#${e.sessionId}`] : [],
|
|
515
|
+
...e.user?.id ? [userKey(e.app, "id", e.user.id)] : [],
|
|
516
|
+
...e.user?.anonymousId ? [userKey(e.app, "anonymousId", e.user.anonymousId)] : []
|
|
517
|
+
];
|
|
518
|
+
}
|
|
438
519
|
function clean(item) {
|
|
439
520
|
const { pk: _p, sk: _s, ttl: _t, ...rest } = item;
|
|
440
521
|
return rest;
|