@debugkit/dashboard 0.4.0 → 0.6.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.
Files changed (55) hide show
  1. package/.env.example +3 -0
  2. package/dist/client/assets/_authed-BMdIkvB6.js +7 -0
  3. package/dist/client/assets/_authed-Rg-Gabby.js +1 -0
  4. package/dist/client/assets/{charts-C76vsG2N.js → charts-QIIL2Fv7.js} +18 -18
  5. package/dist/client/assets/index-CMjwqklY.js +10 -0
  6. package/dist/client/assets/invite._token-CDogkC9p.js +1 -0
  7. package/dist/client/assets/issues._fingerprint-DLe_lV5d.js +1 -0
  8. package/dist/client/assets/login-BG9v4zhc.js +1 -0
  9. package/dist/client/assets/preload-helper-Dscj_TcA.js +3 -0
  10. package/dist/client/assets/settings-Ce1uqKl0.js +1 -0
  11. package/dist/client/assets/styles-DztngwT9.css +2 -0
  12. package/dist/client/assets/team-TUMAZ4jv.js +1 -0
  13. package/dist/client/assets/ui-C0HGOza2.js +1 -0
  14. package/dist/server/assets/_authed-DDQ5yYfy.js +73 -0
  15. package/dist/server/assets/{_authed-ClbGOSDJ.js → _authed-Dray_9Ct.js} +296 -70
  16. package/dist/server/assets/_tanstack-start-manifest_v-BItoYCqL.js +61 -0
  17. package/dist/server/assets/{charts-CNlV7Pga.js → charts-DzTVqJ8z.js} +21 -4
  18. package/dist/server/assets/{demo-DTdlXNgj.js → demo-BsMMDk_F.js} +87 -10
  19. package/dist/server/assets/dynamodb-Zkk1-mgz.js +445 -0
  20. package/dist/server/assets/firestore-C52q_vwM.js +237 -0
  21. package/dist/server/assets/fns-DwGaMi8S.js +107 -0
  22. package/dist/server/assets/fns-mbUIXXep.js +529 -0
  23. package/dist/server/assets/invite._token-BWiwnST7.js +136 -0
  24. package/dist/server/assets/{issues._fingerprint-D78dy5os.js → issues._fingerprint-D9vjIk3M.js} +159 -17
  25. package/dist/server/assets/{login-h3B5Vdhl.js → login-BXi46U4B.js} +3 -3
  26. package/dist/server/assets/{queries-DIVV-5j6.js → memory-BssaqdZm.js} +234 -504
  27. package/dist/server/assets/queries-BJxX3Kjp.js +1669 -0
  28. package/dist/server/assets/range-picker-0zbSGr3Z.js +106 -0
  29. package/dist/server/assets/rolldown-runtime-D8jQpDG7.js +12 -0
  30. package/dist/server/assets/{router-DqTf7XfT.js → router-m6Hpq6Ep.js} +114 -51
  31. package/dist/server/assets/settings-ByFLIJce.js +371 -0
  32. package/dist/server/assets/src-D83GYTrp.js +9 -0
  33. package/dist/server/assets/team-CifrrNkf.js +255 -0
  34. package/dist/server/assets/{ui-Lv-KcOoP.js → ui-BJokJdYa.js} +25 -3
  35. package/dist/server/server.js +60 -8
  36. package/handler.mjs +95 -0
  37. package/lambda.mjs +61 -0
  38. package/package.json +16 -7
  39. package/server.mjs +4 -39
  40. package/dist/client/assets/_authed-Bi62GTX3.js +0 -7
  41. package/dist/client/assets/_authed-mWCAMokt.js +0 -1
  42. package/dist/client/assets/index-D7uhDdvA.js +0 -12
  43. package/dist/client/assets/issues._fingerprint-fVGLnT37.js +0 -1
  44. package/dist/client/assets/login-MqvT094Y.js +0 -1
  45. package/dist/client/assets/styles-CZZRuG1z.css +0 -2
  46. package/dist/client/assets/ui-Bj6uJIr8.js +0 -1
  47. package/dist/server/assets/_authed-BaehIntL.js +0 -40
  48. package/dist/server/assets/_tanstack-start-manifest_v-eNUCOzFz.js +0 -40
  49. package/dist/server/assets/dynamodb-DejcakaF.js +0 -187
  50. package/dist/server/assets/firestore-BH-gx9no.js +0 -112
  51. package/dist/server/assets/fns-CgB12FUN.js +0 -31
  52. package/dist/server/assets/fns-Yg8sT1Cb.js +0 -87
  53. package/dist/server/assets/memory-4DwW5cTO.js +0 -59
  54. package/dist/server/assets/rollups-JXbazRNh.js +0 -22
  55. package/dist/server/assets/src-D5jyi_C4.js +0 -235
@@ -1,5 +1,5 @@
1
- import { MemoryStore } from "./memory-4DwW5cTO.js";
2
- import { n as ingest } from "./src-D5jyi_C4.js";
1
+ import { t as MemoryStore } from "./memory-BssaqdZm.js";
2
+ import { v as ingest } from "./queries-BJxX3Kjp.js";
3
3
  // src/server/demo.ts
4
4
  /**
5
5
  * Builds a realistic 14-day dataset for a fictional app by pushing synthetic SDK
@@ -171,10 +171,62 @@ async function seedDemo() {
171
171
  }
172
172
  ];
173
173
  const successFlows = [
174
- "auth.login",
175
- "checkout.payment",
176
- "feed.load",
177
- "profile.update"
174
+ ["auth.login", "submit_otp"],
175
+ ["checkout.payment", "create_intent"],
176
+ ["feed.load", "parse"],
177
+ ["profile.update", "upload_avatar"]
178
+ ];
179
+ const endpoints = [
180
+ [
181
+ "GET /v1/feed",
182
+ 380,
183
+ 900,
184
+ .03
185
+ ],
186
+ [
187
+ "POST /v2/auth/otp/verify",
188
+ 420,
189
+ 500,
190
+ .01
191
+ ],
192
+ [
193
+ "POST /v1/payments/intent",
194
+ 1900,
195
+ 9e3,
196
+ .06
197
+ ],
198
+ [
199
+ "GET /v1/profile",
200
+ 160,
201
+ 250,
202
+ .002
203
+ ]
204
+ ];
205
+ const EDGES = [
206
+ 50,
207
+ 100,
208
+ 200,
209
+ 300,
210
+ 500,
211
+ 750,
212
+ 1e3,
213
+ 1500,
214
+ 2e3,
215
+ 3e3,
216
+ 5e3,
217
+ 1e4
218
+ ];
219
+ const rand2 = mulberry32(7);
220
+ const pick2 = (xs) => xs[Math.floor(rand2() * xs.length)];
221
+ const places = [
222
+ ["Africa/Johannesburg", "en-ZA"],
223
+ ["Africa/Johannesburg", "en-ZA"],
224
+ ["Africa/Johannesburg", "en-ZA"],
225
+ ["Africa/Johannesburg", "en-US"],
226
+ ["Africa/Johannesburg", "en-ZA"],
227
+ ["Europe/London", "en-GB"],
228
+ ["Africa/Windhoek", "en-NA"],
229
+ ["Africa/Gaborone", "en-BW"]
178
230
  ];
179
231
  for (let dayAgo = 13; dayAgo >= 0; dayAgo--) {
180
232
  const version = dayAgo <= 3 ? pick([
@@ -253,14 +305,37 @@ async function seedDemo() {
253
305
  });
254
306
  }
255
307
  }
256
- for (const flow of successFlows) if (rand() < .55) events.push({
308
+ for (const [flow, step] of successFlows) if (rand() < .55) events.push({
257
309
  type: "event",
258
310
  id: `evt_${(seq++).toString().padStart(10, "0")}`,
259
311
  ts,
260
- name: `${flow}.complete`,
312
+ name: `${flow}.${step}`,
261
313
  flow,
314
+ step,
262
315
  outcome: "success"
263
316
  });
317
+ for (const [key, typical, spread, failRate] of endpoints) {
318
+ if (rand2() < .4) continue;
319
+ const buckets = new Array(13).fill(0);
320
+ const count = 1 + Math.floor(rand2() * 6);
321
+ let errors = 0;
322
+ for (let k = 0; k < count; k++) {
323
+ const msTaken = typical * (.5 + rand2()) + (rand2() < .1 ? rand2() * spread : 0);
324
+ const b = EDGES.findIndex((e) => msTaken <= e);
325
+ buckets[b === -1 ? 12 : b]++;
326
+ if (rand2() < failRate) errors++;
327
+ }
328
+ events.push({
329
+ type: "metric",
330
+ id: id(),
331
+ ts,
332
+ name: "http",
333
+ key,
334
+ count,
335
+ errors,
336
+ buckets
337
+ });
338
+ }
264
339
  events.unshift({
265
340
  type: "session",
266
341
  id: id(),
@@ -298,8 +373,10 @@ async function seedDemo() {
298
373
  engine: "hermes"
299
374
  },
300
375
  network: { type: pick(networks) },
301
- locale: "en-ZA",
302
- timezone: "Africa/Johannesburg"
376
+ ...(([timezone, locale]) => ({
377
+ timezone,
378
+ locale
379
+ }))(pick2(places))
303
380
  },
304
381
  user: {
305
382
  id: userId,
@@ -0,0 +1,445 @@
1
+ import { f as coalesceRollups, s as isRegression } from "./memory-BssaqdZm.js";
2
+ import "./src-D83GYTrp.js";
3
+ import { BatchWriteCommand, GetCommand, PutCommand, QueryCommand, UpdateCommand } from "@aws-sdk/lib-dynamodb";
4
+ // ../../packages/adapters/src/dynamodb.ts
5
+ /**
6
+ * Single-table layout. Table needs: partition key `pk` (S), sort key `sk` (S),
7
+ * and TTL enabled on attribute `ttl`.
8
+ *
9
+ * APPS | {app} app marker
10
+ * APP#{app}#ISSUE | {fingerprint} Issue
11
+ * APP#{app}#ROLLUP#{dimension} | {day}#{key} RollupRow (ADD counters)
12
+ * APP#{app}#ISSUEEV#{fp} | {ts}#{id} StoredEvent (error events by issue)
13
+ * APP#{app}#EV#{day} | {ts}#{id} StoredEvent (all events by day)
14
+ * APP#{app}#SETTINGS | app AppSettings
15
+ * APP#{app}#USERS#{scope} | {member} { lastDay } (hashed ids; for "users affected")
16
+ *
17
+ * TEAM | M#{email} TeamMember (dashboard logins)
18
+ * TEAM | I#{sha256} TeamInvite
19
+ *
20
+ * Hourly rollups (dimension issueHour) also carry `ttl`, so they expire after 7 days.
21
+ */
22
+ var DynamoStore = class {
23
+ doc;
24
+ opts;
25
+ constructor(doc, opts) {
26
+ this.doc = doc;
27
+ this.opts = opts;
28
+ }
29
+ get table() {
30
+ return this.opts.table;
31
+ }
32
+ async getMember(email) {
33
+ const out = await this.doc.send(new GetCommand({
34
+ TableName: this.table,
35
+ Key: {
36
+ pk: "TEAM",
37
+ sk: `M#${email}`
38
+ }
39
+ }));
40
+ return out.Item ? clean(out.Item) : null;
41
+ }
42
+ async putMember(m) {
43
+ await this.doc.send(new PutCommand({
44
+ TableName: this.table,
45
+ Item: {
46
+ ...dropUndefined(m),
47
+ pk: "TEAM",
48
+ sk: `M#${m.email}`
49
+ }
50
+ }));
51
+ }
52
+ async listMembers() {
53
+ return await this.teamItems("M#");
54
+ }
55
+ async getInvite(id) {
56
+ const out = await this.doc.send(new GetCommand({
57
+ TableName: this.table,
58
+ Key: {
59
+ pk: "TEAM",
60
+ sk: `I#${id}`
61
+ }
62
+ }));
63
+ return out.Item ? clean(out.Item) : null;
64
+ }
65
+ async putInvite(i) {
66
+ await this.doc.send(new PutCommand({
67
+ TableName: this.table,
68
+ Item: {
69
+ ...dropUndefined(i),
70
+ pk: "TEAM",
71
+ sk: `I#${i.id}`
72
+ }
73
+ }));
74
+ }
75
+ async claimInvite(id, by, at) {
76
+ try {
77
+ await this.doc.send(new UpdateCommand({
78
+ TableName: this.table,
79
+ Key: {
80
+ pk: "TEAM",
81
+ sk: `I#${id}`
82
+ },
83
+ UpdateExpression: "SET usedAt = :at, usedBy = :by",
84
+ ConditionExpression: "attribute_exists(pk) AND attribute_not_exists(usedAt) AND attribute_not_exists(revokedAt)",
85
+ ExpressionAttributeValues: {
86
+ ":at": at,
87
+ ":by": by
88
+ }
89
+ }));
90
+ return true;
91
+ } catch (e) {
92
+ if (e.name === "ConditionalCheckFailedException") return false;
93
+ throw e;
94
+ }
95
+ }
96
+ async listInvites() {
97
+ return (await this.teamItems("I#")).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
98
+ }
99
+ async teamItems(prefix) {
100
+ const items = [];
101
+ let ExclusiveStartKey;
102
+ do {
103
+ const out = await this.doc.send(new QueryCommand({
104
+ TableName: this.table,
105
+ KeyConditionExpression: "pk = :pk AND begins_with(sk, :p)",
106
+ ExpressionAttributeValues: {
107
+ ":pk": "TEAM",
108
+ ":p": prefix
109
+ },
110
+ ExclusiveStartKey
111
+ }));
112
+ items.push(...(out.Items ?? []).map(clean));
113
+ ExclusiveStartKey = out.LastEvaluatedKey;
114
+ } while (ExclusiveStartKey);
115
+ return items;
116
+ }
117
+ async registerApp(app) {
118
+ await this.doc.send(new PutCommand({
119
+ TableName: this.table,
120
+ Item: {
121
+ pk: "APPS",
122
+ sk: app
123
+ }
124
+ }));
125
+ }
126
+ async writeEvents(events, opts = {}) {
127
+ const days = opts.retentionDays ?? this.opts.retentionDays ?? 30;
128
+ const ttl = (e) => Math.floor(Date.parse(e.receivedAt) / 1e3) + days * 86400;
129
+ const items = events.flatMap((e) => {
130
+ const sk = `${e.event.ts}#${e.event.id}`;
131
+ const base = {
132
+ ...e,
133
+ ttl: ttl(e)
134
+ };
135
+ const rows = [{
136
+ pk: `APP#${e.app}#EV#${e.day}`,
137
+ sk,
138
+ ...base
139
+ }];
140
+ if (e.fingerprint) rows.push({
141
+ pk: `APP#${e.app}#ISSUEEV#${e.fingerprint}`,
142
+ sk,
143
+ ...base
144
+ });
145
+ return rows;
146
+ });
147
+ for (let i = 0; i < items.length; i += 25) {
148
+ let req = { [this.table]: items.slice(i, i + 25).map((Item) => ({ PutRequest: { Item } })) };
149
+ for (let attempt = 0; req && Object.keys(req).length && attempt < 5; attempt++) {
150
+ req = (await this.doc.send(new BatchWriteCommand({ RequestItems: req }))).UnprocessedItems;
151
+ if (req && Object.keys(req).length) await new Promise((r) => setTimeout(r, 50 * 2 ** attempt));
152
+ }
153
+ }
154
+ }
155
+ async upsertIssues(updates) {
156
+ const outcome = {
157
+ created: [],
158
+ regressed: []
159
+ };
160
+ await Promise.all(updates.map(async (u) => {
161
+ if ((await this.doc.send(new UpdateCommand({
162
+ TableName: this.table,
163
+ Key: {
164
+ pk: `APP#${u.app}#ISSUE`,
165
+ sk: u.fingerprint
166
+ },
167
+ UpdateExpression: "ADD #count :by SET app = :app, fingerprint = :fp, title = :title, flow = :flow, culprit = :culprit, firstSeen = if_not_exists(firstSeen, :first)",
168
+ ExpressionAttributeNames: { "#count": "count" },
169
+ ExpressionAttributeValues: {
170
+ ":by": u.by,
171
+ ":app": u.app,
172
+ ":fp": u.fingerprint,
173
+ ":title": u.title,
174
+ ":flow": u.flow ?? null,
175
+ ":culprit": u.culprit ?? null,
176
+ ":first": u.firstTs
177
+ },
178
+ ReturnValues: "UPDATED_OLD"
179
+ }))).Attributes?.count === void 0) outcome.created.push(u.fingerprint);
180
+ await this.doc.send(new UpdateCommand({
181
+ TableName: this.table,
182
+ Key: {
183
+ pk: `APP#${u.app}#ISSUE`,
184
+ sk: u.fingerprint
185
+ },
186
+ UpdateExpression: "SET lastSeen = :ts, lastEvent = :ev, lastVersion = :v, firstVersion = if_not_exists(firstVersion, :v)",
187
+ ConditionExpression: "attribute_not_exists(lastSeen) OR lastSeen < :ts",
188
+ ExpressionAttributeValues: {
189
+ ":ts": u.ts,
190
+ ":ev": u.lastEvent,
191
+ ":v": u.version ?? null
192
+ }
193
+ })).catch((e) => {
194
+ if (e.name !== "ConditionalCheckFailedException") throw e;
195
+ });
196
+ const cur = (await this.doc.send(new GetCommand({
197
+ TableName: this.table,
198
+ Key: {
199
+ pk: `APP#${u.app}#ISSUE`,
200
+ sk: u.fingerprint
201
+ },
202
+ ProjectionExpression: "#s, resolvedIn, resolvedAt",
203
+ ExpressionAttributeNames: { "#s": "status" }
204
+ }))).Item;
205
+ if (cur?.status === "resolved" && isRegression(cur.resolvedIn, u.version, cur.resolvedAt, u.ts)) await this.doc.send(new UpdateCommand({
206
+ TableName: this.table,
207
+ Key: {
208
+ pk: `APP#${u.app}#ISSUE`,
209
+ sk: u.fingerprint
210
+ },
211
+ UpdateExpression: "SET #s = :r, regressedAt = :ts",
212
+ ConditionExpression: "#s = :resolved",
213
+ ExpressionAttributeNames: { "#s": "status" },
214
+ ExpressionAttributeValues: {
215
+ ":r": "regressed",
216
+ ":ts": u.ts,
217
+ ":resolved": "resolved"
218
+ }
219
+ })).then(() => outcome.regressed.push(u.fingerprint)).catch((e) => {
220
+ if (e.name !== "ConditionalCheckFailedException") throw e;
221
+ });
222
+ await this.doc.send(new UpdateCommand({
223
+ TableName: this.table,
224
+ Key: {
225
+ pk: `APP#${u.app}#ISSUE`,
226
+ sk: u.fingerprint
227
+ },
228
+ UpdateExpression: "SET firstSeen = :first",
229
+ ConditionExpression: "firstSeen > :first",
230
+ ExpressionAttributeValues: { ":first": u.firstTs }
231
+ })).catch((e) => {
232
+ if (e.name !== "ConditionalCheckFailedException") throw e;
233
+ });
234
+ }));
235
+ return outcome;
236
+ }
237
+ async incrementRollups(incs) {
238
+ await Promise.all(coalesceRollups(incs).map((r) => this.doc.send(new UpdateCommand({
239
+ TableName: this.table,
240
+ Key: {
241
+ pk: `APP#${r.app}#ROLLUP#${r.dimension}`,
242
+ sk: `${r.day}#${r.key}`
243
+ },
244
+ UpdateExpression: `ADD errors :e, events :v SET app = :app, #day = :day, dimension = :dim, #key = :key${r.dimension === "issueHour" ? ", #ttl = :ttl" : ""}`,
245
+ ExpressionAttributeNames: {
246
+ "#day": "day",
247
+ "#key": "key",
248
+ ...r.dimension === "issueHour" ? { "#ttl": "ttl" } : {}
249
+ },
250
+ ExpressionAttributeValues: {
251
+ ":e": r.errors,
252
+ ":v": r.events,
253
+ ":app": r.app,
254
+ ":day": r.day,
255
+ ":dim": r.dimension,
256
+ ":key": r.key,
257
+ ...r.dimension === "issueHour" ? { ":ttl": Math.floor(Date.parse(`${r.day}:00:00Z`) / 1e3) + 604800 } : {}
258
+ }
259
+ }))));
260
+ }
261
+ async markUsers(app, marks) {
262
+ await Promise.all(marks.map((m) => this.doc.send(new UpdateCommand({
263
+ TableName: this.table,
264
+ Key: {
265
+ pk: `APP#${app}#USERS#${m.scope}`,
266
+ sk: m.member
267
+ },
268
+ UpdateExpression: "SET lastDay = :d",
269
+ ConditionExpression: "attribute_not_exists(lastDay) OR lastDay < :d",
270
+ ExpressionAttributeValues: { ":d": m.day }
271
+ })).catch((e) => {
272
+ if (e.name !== "ConditionalCheckFailedException") throw e;
273
+ })));
274
+ }
275
+ async countUsers(app, scope, sinceDay) {
276
+ let n = 0;
277
+ let ExclusiveStartKey;
278
+ do {
279
+ const out = await this.doc.send(new QueryCommand({
280
+ TableName: this.table,
281
+ KeyConditionExpression: "pk = :pk",
282
+ FilterExpression: "lastDay >= :d",
283
+ ExpressionAttributeValues: {
284
+ ":pk": `APP#${app}#USERS#${scope}`,
285
+ ":d": sinceDay
286
+ },
287
+ Select: "COUNT",
288
+ ExclusiveStartKey
289
+ }));
290
+ n += out.Count ?? 0;
291
+ ExclusiveStartKey = out.LastEvaluatedKey;
292
+ } while (ExclusiveStartKey);
293
+ return n;
294
+ }
295
+ async setIssueStatus(app, fp, change) {
296
+ const resolved = change.status === "resolved";
297
+ const out = await this.doc.send(new UpdateCommand({
298
+ TableName: this.table,
299
+ Key: {
300
+ pk: `APP#${app}#ISSUE`,
301
+ sk: fp
302
+ },
303
+ UpdateExpression: resolved ? "SET #s = :s, resolvedAt = :at, resolvedIn = :in REMOVE regressedAt" : "SET #s = :s REMOVE resolvedIn, resolvedAt, regressedAt",
304
+ ConditionExpression: "attribute_exists(pk)",
305
+ ExpressionAttributeNames: { "#s": "status" },
306
+ ExpressionAttributeValues: resolved ? {
307
+ ":s": change.status,
308
+ ":at": (/* @__PURE__ */ new Date()).toISOString(),
309
+ ":in": change.resolvedIn ?? null
310
+ } : { ":s": change.status },
311
+ ReturnValues: "ALL_NEW"
312
+ })).catch((e) => {
313
+ if (e.name === "ConditionalCheckFailedException") return null;
314
+ throw e;
315
+ });
316
+ return out?.Attributes ? clean(out.Attributes) : null;
317
+ }
318
+ async getSettings(app) {
319
+ const out = await this.doc.send(new GetCommand({
320
+ TableName: this.table,
321
+ Key: {
322
+ pk: `APP#${app}#SETTINGS`,
323
+ sk: "app"
324
+ }
325
+ }));
326
+ return out.Item ? clean(out.Item) : null;
327
+ }
328
+ async putSettings(app, s) {
329
+ const next = Object.fromEntries(Object.entries({
330
+ ...s,
331
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
332
+ }).filter(([, v]) => v !== void 0));
333
+ const names = Object.keys(next);
334
+ return clean((await this.doc.send(new UpdateCommand({
335
+ TableName: this.table,
336
+ Key: {
337
+ pk: `APP#${app}#SETTINGS`,
338
+ sk: "app"
339
+ },
340
+ UpdateExpression: `SET ${names.map((n, i) => `#n${i} = :v${i}`).join(", ")}`,
341
+ ExpressionAttributeNames: Object.fromEntries(names.map((n, i) => [`#n${i}`, n])),
342
+ ExpressionAttributeValues: Object.fromEntries(names.map((n, i) => [`:v${i}`, next[n]])),
343
+ ReturnValues: "ALL_NEW"
344
+ }))).Attributes ?? next);
345
+ }
346
+ /**
347
+ * Events live in one partition per day (and a copy per issue). Walk the day partitions newest
348
+ * first, one per call; the cursor is how many days back we've got. Stops after 10 years.
349
+ */
350
+ async restampExpiry(app, retentionDays, { cursor } = {}) {
351
+ let back = cursor ? Number(cursor) : 0;
352
+ let updated = 0;
353
+ for (let n = 0; n < 30 && back <= 3650; n++, back++) {
354
+ const day = (/* @__PURE__ */ new Date(Date.now() - back * 864e5)).toISOString().slice(0, 10);
355
+ const items = await this.queryAll({ pk: `APP#${app}#EV#${day}` });
356
+ for (const item of items) {
357
+ const ttl = Math.floor(Date.parse(item.receivedAt) / 1e3) + retentionDays * 86400;
358
+ const keys = [{
359
+ pk: item.pk,
360
+ sk: item.sk
361
+ }, ...item.fingerprint ? [{
362
+ pk: `APP#${app}#ISSUEEV#${item.fingerprint}`,
363
+ sk: item.sk
364
+ }] : []];
365
+ await Promise.all(keys.map((Key) => this.doc.send(new UpdateCommand({
366
+ TableName: this.table,
367
+ Key,
368
+ UpdateExpression: "SET #t = :t",
369
+ ConditionExpression: "attribute_exists(pk)",
370
+ ExpressionAttributeNames: { "#t": "ttl" },
371
+ ExpressionAttributeValues: { ":t": ttl }
372
+ })).catch((e) => {
373
+ if (e.name !== "ConditionalCheckFailedException") throw e;
374
+ })));
375
+ updated++;
376
+ }
377
+ if (items.length) {
378
+ back++;
379
+ break;
380
+ }
381
+ }
382
+ return {
383
+ updated,
384
+ cursor: back <= 3650 ? String(back) : void 0
385
+ };
386
+ }
387
+ async listApps() {
388
+ return (await this.queryAll({ pk: "APPS" })).map((i) => i.sk).sort();
389
+ }
390
+ async listIssues(app, { limit = 200 } = {}) {
391
+ return (await this.queryAll({ pk: `APP#${app}#ISSUE` })).sort((a, b) => b.lastSeen.localeCompare(a.lastSeen)).slice(0, limit).map(clean);
392
+ }
393
+ async getIssue(app, fp) {
394
+ const out = await this.doc.send(new GetCommand({
395
+ TableName: this.table,
396
+ Key: {
397
+ pk: `APP#${app}#ISSUE`,
398
+ sk: fp
399
+ }
400
+ }));
401
+ return out.Item ? clean(out.Item) : null;
402
+ }
403
+ async getRollups(app, dimension, fromDay, toDay) {
404
+ return (await this.queryAll({
405
+ pk: `APP#${app}#ROLLUP#${dimension}`,
406
+ between: [`${fromDay}#`, `${toDay}#￿`]
407
+ })).map((i) => clean(i));
408
+ }
409
+ async listIssueEvents(app, fp, { limit = 50 } = {}) {
410
+ return ((await this.doc.send(new QueryCommand({
411
+ TableName: this.table,
412
+ KeyConditionExpression: "pk = :pk",
413
+ ExpressionAttributeValues: { ":pk": `APP#${app}#ISSUEEV#${fp}` },
414
+ ScanIndexForward: false,
415
+ Limit: limit
416
+ }))).Items ?? []).map((i) => clean(i));
417
+ }
418
+ async queryAll({ pk, between }) {
419
+ const items = [];
420
+ let ExclusiveStartKey;
421
+ do {
422
+ const out = await this.doc.send(new QueryCommand({
423
+ TableName: this.table,
424
+ KeyConditionExpression: between ? "pk = :pk AND sk BETWEEN :a AND :b" : "pk = :pk",
425
+ ExpressionAttributeValues: between ? {
426
+ ":pk": pk,
427
+ ":a": between[0],
428
+ ":b": between[1]
429
+ } : { ":pk": pk },
430
+ ExclusiveStartKey
431
+ }));
432
+ items.push(...out.Items ?? []);
433
+ ExclusiveStartKey = out.LastEvaluatedKey;
434
+ } while (ExclusiveStartKey);
435
+ return items;
436
+ }
437
+ };
438
+ function clean(item) {
439
+ const { pk: _p, sk: _s, ttl: _t, ...rest } = item;
440
+ return rest;
441
+ }
442
+ function dropUndefined(v) {
443
+ return Object.fromEntries(Object.entries(v).filter(([, x]) => x !== void 0));
444
+ }
445
+ export { DynamoStore };