@tarslogs/client 0.1.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/hono-DIKyVc9C.d.cts +112 -0
- package/dist/hono-DIKyVc9C.d.ts +112 -0
- package/dist/hono.cjs +328 -0
- package/dist/hono.cjs.map +1 -0
- package/dist/hono.d.cts +1 -0
- package/dist/hono.d.ts +1 -0
- package/dist/hono.js +300 -0
- package/dist/hono.js.map +1 -0
- package/dist/index.cjs +463 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +450 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/dist/hono.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// src/transport.ts
|
|
2
|
+
var Transport = class {
|
|
3
|
+
config = null;
|
|
4
|
+
errorQueue = [];
|
|
5
|
+
metricQueue = [];
|
|
6
|
+
flushTimer = null;
|
|
7
|
+
rateLimitState = {
|
|
8
|
+
timestamps: [],
|
|
9
|
+
maxPerMinute: 30
|
|
10
|
+
};
|
|
11
|
+
retryQueue = [];
|
|
12
|
+
init(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.rateLimitState.maxPerMinute = config.rateLimitPerMinute ?? 30;
|
|
15
|
+
this.flushTimer = setInterval(() => {
|
|
16
|
+
this.flushAll();
|
|
17
|
+
}, 5e3);
|
|
18
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
19
|
+
window.addEventListener("visibilitychange", () => {
|
|
20
|
+
if (document.visibilityState === "hidden") {
|
|
21
|
+
this.flushAllBeacon();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
window.addEventListener("pagehide", () => {
|
|
25
|
+
this.flushAllBeacon();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
destroy() {
|
|
30
|
+
if (this.flushTimer) {
|
|
31
|
+
clearInterval(this.flushTimer);
|
|
32
|
+
this.flushTimer = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
log(...args) {
|
|
36
|
+
if (this.config?.debug) {
|
|
37
|
+
console.log("[tarslogs]", ...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
checkRateLimit() {
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
const windowStart = now - 6e4;
|
|
43
|
+
this.rateLimitState.timestamps = this.rateLimitState.timestamps.filter(
|
|
44
|
+
(t) => t > windowStart
|
|
45
|
+
);
|
|
46
|
+
if (this.rateLimitState.timestamps.length >= this.rateLimitState.maxPerMinute) {
|
|
47
|
+
this.log("Rate limit reached, dropping payload");
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
this.rateLimitState.timestamps.push(now);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
enqueueError(payload) {
|
|
54
|
+
if (!this.config) return;
|
|
55
|
+
if (!this.checkRateLimit()) return;
|
|
56
|
+
this.errorQueue.push(payload);
|
|
57
|
+
this.log("Error queued:", payload.message);
|
|
58
|
+
if (this.errorQueue.length >= 10) {
|
|
59
|
+
this.flushErrors();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
enqueueMetric(payload) {
|
|
63
|
+
if (!this.config) return;
|
|
64
|
+
if (!this.checkRateLimit()) return;
|
|
65
|
+
this.metricQueue.push(payload);
|
|
66
|
+
this.log("Metric queued:", payload.name, payload.value);
|
|
67
|
+
if (this.metricQueue.length >= 10) {
|
|
68
|
+
this.flushMetrics();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getHeaders() {
|
|
72
|
+
return {
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
"x-tarslogs-key": this.config.apiKey
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async sendFetch(url, body) {
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetch(url, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: this.getHeaders(),
|
|
82
|
+
body
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
this.log("Send failed:", res.status, res.statusText);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
this.log("Send success:", url);
|
|
89
|
+
return true;
|
|
90
|
+
} catch (err) {
|
|
91
|
+
this.log("Send error:", err);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async sendWithRetry(url, body) {
|
|
96
|
+
const success = await this.sendFetch(url, body);
|
|
97
|
+
if (!success) {
|
|
98
|
+
this.retryQueue.push({ url, body });
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
this.processRetryQueue();
|
|
101
|
+
}, 5e3);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async processRetryQueue() {
|
|
105
|
+
const items = this.retryQueue.splice(0, this.retryQueue.length);
|
|
106
|
+
for (const item of items) {
|
|
107
|
+
await this.sendFetch(item.url, item.body);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async flushErrors() {
|
|
111
|
+
if (!this.config || this.errorQueue.length === 0) return;
|
|
112
|
+
const errors = this.errorQueue.splice(0, this.errorQueue.length);
|
|
113
|
+
const url = `${this.config.url}/ingest/errors`;
|
|
114
|
+
const body = JSON.stringify({ errors });
|
|
115
|
+
this.log(`Flushing ${errors.length} errors`);
|
|
116
|
+
await this.sendWithRetry(url, body);
|
|
117
|
+
}
|
|
118
|
+
async flushMetrics() {
|
|
119
|
+
if (!this.config || this.metricQueue.length === 0) return;
|
|
120
|
+
const metrics = this.metricQueue.splice(0, this.metricQueue.length);
|
|
121
|
+
const url = `${this.config.url}/ingest/metrics`;
|
|
122
|
+
const body = JSON.stringify({ metrics });
|
|
123
|
+
this.log(`Flushing ${metrics.length} metrics`);
|
|
124
|
+
await this.sendWithRetry(url, body);
|
|
125
|
+
}
|
|
126
|
+
flushAllBeacon() {
|
|
127
|
+
if (!this.config) return;
|
|
128
|
+
if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
|
|
129
|
+
if (this.errorQueue.length > 0) {
|
|
130
|
+
const errors = this.errorQueue.splice(0, this.errorQueue.length);
|
|
131
|
+
const blob = new Blob(
|
|
132
|
+
[JSON.stringify({ errors })],
|
|
133
|
+
{ type: "application/json" }
|
|
134
|
+
);
|
|
135
|
+
navigator.sendBeacon(
|
|
136
|
+
`${this.config.url}/ingest/errors?key=${this.config.apiKey}`,
|
|
137
|
+
blob
|
|
138
|
+
);
|
|
139
|
+
this.log("Beacon sent errors:", errors.length);
|
|
140
|
+
}
|
|
141
|
+
if (this.metricQueue.length > 0) {
|
|
142
|
+
const metrics = this.metricQueue.splice(0, this.metricQueue.length);
|
|
143
|
+
const blob = new Blob(
|
|
144
|
+
[JSON.stringify({ metrics })],
|
|
145
|
+
{ type: "application/json" }
|
|
146
|
+
);
|
|
147
|
+
navigator.sendBeacon(
|
|
148
|
+
`${this.config.url}/ingest/metrics?key=${this.config.apiKey}`,
|
|
149
|
+
blob
|
|
150
|
+
);
|
|
151
|
+
this.log("Beacon sent metrics:", metrics.length);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
this.flushAll();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async flushAll() {
|
|
158
|
+
await Promise.all([this.flushErrors(), this.flushMetrics()]);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/core.ts
|
|
163
|
+
var TarslogsClient = class {
|
|
164
|
+
config = null;
|
|
165
|
+
transport = new Transport();
|
|
166
|
+
context = {};
|
|
167
|
+
/**
|
|
168
|
+
* Initialize the client with configuration.
|
|
169
|
+
* Must be called before any other methods.
|
|
170
|
+
*/
|
|
171
|
+
init(config) {
|
|
172
|
+
this.config = config;
|
|
173
|
+
this.transport.init(config);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Merge additional context that will be sent with all errors and metrics.
|
|
177
|
+
* Useful for setting userId, route, etc.
|
|
178
|
+
*/
|
|
179
|
+
setContext(ctx) {
|
|
180
|
+
this.context = { ...this.context, ...ctx };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Clear all context (e.g., on logout).
|
|
184
|
+
*/
|
|
185
|
+
clearContext() {
|
|
186
|
+
this.context = {};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Capture an error and send to TarsLogs.
|
|
190
|
+
*/
|
|
191
|
+
captureError(error, extra) {
|
|
192
|
+
if (!this.config) return;
|
|
193
|
+
let payload;
|
|
194
|
+
if (typeof error === "string") {
|
|
195
|
+
payload = {
|
|
196
|
+
message: error,
|
|
197
|
+
environment: this.config.environment,
|
|
198
|
+
version: this.config.version,
|
|
199
|
+
context: { ...this.context, ...extra },
|
|
200
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
201
|
+
};
|
|
202
|
+
} else {
|
|
203
|
+
payload = {
|
|
204
|
+
message: error.message,
|
|
205
|
+
stack: error.stack,
|
|
206
|
+
environment: this.config.environment,
|
|
207
|
+
version: this.config.version,
|
|
208
|
+
context: { ...this.context, ...extra },
|
|
209
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
210
|
+
};
|
|
211
|
+
if (error.stack) {
|
|
212
|
+
const match = error.stack.match(/(?:at\s+.+\s+\(|at\s+)(.+):(\d+):(\d+)\)?/);
|
|
213
|
+
if (match) {
|
|
214
|
+
payload.file = match[1];
|
|
215
|
+
payload.line = parseInt(match[2], 10);
|
|
216
|
+
payload.col = parseInt(match[3], 10);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
this.transport.enqueueError(payload);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Increment a counter metric.
|
|
224
|
+
*/
|
|
225
|
+
increment(name, value = 1, tags) {
|
|
226
|
+
if (!this.config) return;
|
|
227
|
+
const payload = {
|
|
228
|
+
name,
|
|
229
|
+
type: "counter",
|
|
230
|
+
value,
|
|
231
|
+
tags,
|
|
232
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
233
|
+
};
|
|
234
|
+
this.transport.enqueueMetric(payload);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Set a gauge metric (point-in-time value).
|
|
238
|
+
*/
|
|
239
|
+
gauge(name, value, tags) {
|
|
240
|
+
if (!this.config) return;
|
|
241
|
+
const payload = {
|
|
242
|
+
name,
|
|
243
|
+
type: "gauge",
|
|
244
|
+
value,
|
|
245
|
+
tags,
|
|
246
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
247
|
+
};
|
|
248
|
+
this.transport.enqueueMetric(payload);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Record a histogram metric (distribution of values).
|
|
252
|
+
*/
|
|
253
|
+
histogram(name, value, tags) {
|
|
254
|
+
if (!this.config) return;
|
|
255
|
+
const payload = {
|
|
256
|
+
name,
|
|
257
|
+
type: "histogram",
|
|
258
|
+
value,
|
|
259
|
+
tags,
|
|
260
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
261
|
+
};
|
|
262
|
+
this.transport.enqueueMetric(payload);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Flush all pending payloads immediately.
|
|
266
|
+
* Call before page unload or process exit.
|
|
267
|
+
*/
|
|
268
|
+
async flush() {
|
|
269
|
+
await this.transport.flushAll();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/hono.ts
|
|
274
|
+
function tarslogsMiddleware(client) {
|
|
275
|
+
return async (c, next) => {
|
|
276
|
+
try {
|
|
277
|
+
await next();
|
|
278
|
+
} catch (err) {
|
|
279
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
280
|
+
client.captureError(error, {
|
|
281
|
+
source: "hono-middleware",
|
|
282
|
+
method: c.req.method,
|
|
283
|
+
path: c.req.path,
|
|
284
|
+
url: c.req.url
|
|
285
|
+
});
|
|
286
|
+
throw err;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function tarslogsHono(app, config) {
|
|
291
|
+
const client = new TarslogsClient();
|
|
292
|
+
client.init(config);
|
|
293
|
+
app.use("*", tarslogsMiddleware(client));
|
|
294
|
+
return client;
|
|
295
|
+
}
|
|
296
|
+
export {
|
|
297
|
+
tarslogsHono,
|
|
298
|
+
tarslogsMiddleware
|
|
299
|
+
};
|
|
300
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/hono.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport.ts","../src/core.ts","../src/hono.ts"],"sourcesContent":["import type { TarslogsConfig, ErrorPayload, MetricPayload } from './types'\n\ninterface RateLimitState {\n timestamps: number[]\n maxPerMinute: number\n}\n\nexport class Transport {\n private config: TarslogsConfig | null = null\n private errorQueue: ErrorPayload[] = []\n private metricQueue: MetricPayload[] = []\n private flushTimer: ReturnType<typeof setInterval> | null = null\n private rateLimitState: RateLimitState = {\n timestamps: [],\n maxPerMinute: 30,\n }\n private retryQueue: Array<{ url: string; body: string }> = []\n\n init(config: TarslogsConfig): void {\n this.config = config\n this.rateLimitState.maxPerMinute = config.rateLimitPerMinute ?? 30\n\n // Start periodic flush\n this.flushTimer = setInterval(() => {\n this.flushAll()\n }, 5000)\n\n // Register page unload handler (browser only)\n if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {\n window.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'hidden') {\n this.flushAllBeacon()\n }\n })\n window.addEventListener('pagehide', () => {\n this.flushAllBeacon()\n })\n }\n }\n\n destroy(): void {\n if (this.flushTimer) {\n clearInterval(this.flushTimer)\n this.flushTimer = null\n }\n }\n\n private log(...args: unknown[]): void {\n if (this.config?.debug) {\n console.log('[tarslogs]', ...args)\n }\n }\n\n private checkRateLimit(): boolean {\n const now = Date.now()\n const windowStart = now - 60_000\n\n // Remove timestamps outside the window\n this.rateLimitState.timestamps = this.rateLimitState.timestamps.filter(\n (t) => t > windowStart\n )\n\n if (this.rateLimitState.timestamps.length >= this.rateLimitState.maxPerMinute) {\n this.log('Rate limit reached, dropping payload')\n return false\n }\n\n this.rateLimitState.timestamps.push(now)\n return true\n }\n\n enqueueError(payload: ErrorPayload): void {\n if (!this.config) return\n if (!this.checkRateLimit()) return\n\n this.errorQueue.push(payload)\n this.log('Error queued:', payload.message)\n\n if (this.errorQueue.length >= 10) {\n this.flushErrors()\n }\n }\n\n enqueueMetric(payload: MetricPayload): void {\n if (!this.config) return\n if (!this.checkRateLimit()) return\n\n this.metricQueue.push(payload)\n this.log('Metric queued:', payload.name, payload.value)\n\n if (this.metricQueue.length >= 10) {\n this.flushMetrics()\n }\n }\n\n private getHeaders(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n 'x-tarslogs-key': this.config!.apiKey,\n }\n }\n\n private async sendFetch(url: string, body: string): Promise<boolean> {\n try {\n const res = await fetch(url, {\n method: 'POST',\n headers: this.getHeaders(),\n body,\n })\n if (!res.ok) {\n this.log('Send failed:', res.status, res.statusText)\n return false\n }\n this.log('Send success:', url)\n return true\n } catch (err) {\n this.log('Send error:', err)\n return false\n }\n }\n\n private async sendWithRetry(url: string, body: string): Promise<void> {\n const success = await this.sendFetch(url, body)\n if (!success) {\n // Retry once after 5s\n this.retryQueue.push({ url, body })\n setTimeout(() => {\n this.processRetryQueue()\n }, 5000)\n }\n }\n\n private async processRetryQueue(): Promise<void> {\n const items = this.retryQueue.splice(0, this.retryQueue.length)\n for (const item of items) {\n await this.sendFetch(item.url, item.body)\n }\n }\n\n private async flushErrors(): Promise<void> {\n if (!this.config || this.errorQueue.length === 0) return\n\n const errors = this.errorQueue.splice(0, this.errorQueue.length)\n const url = `${this.config.url}/ingest/errors`\n const body = JSON.stringify({ errors })\n\n this.log(`Flushing ${errors.length} errors`)\n await this.sendWithRetry(url, body)\n }\n\n private async flushMetrics(): Promise<void> {\n if (!this.config || this.metricQueue.length === 0) return\n\n const metrics = this.metricQueue.splice(0, this.metricQueue.length)\n const url = `${this.config.url}/ingest/metrics`\n const body = JSON.stringify({ metrics })\n\n this.log(`Flushing ${metrics.length} metrics`)\n await this.sendWithRetry(url, body)\n }\n\n private flushAllBeacon(): void {\n if (!this.config) return\n\n if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {\n if (this.errorQueue.length > 0) {\n const errors = this.errorQueue.splice(0, this.errorQueue.length)\n const blob = new Blob(\n [JSON.stringify({ errors })],\n { type: 'application/json' }\n )\n // sendBeacon doesn't support custom headers, so we embed the key in the URL\n navigator.sendBeacon(\n `${this.config.url}/ingest/errors?key=${this.config.apiKey}`,\n blob\n )\n this.log('Beacon sent errors:', errors.length)\n }\n\n if (this.metricQueue.length > 0) {\n const metrics = this.metricQueue.splice(0, this.metricQueue.length)\n const blob = new Blob(\n [JSON.stringify({ metrics })],\n { type: 'application/json' }\n )\n navigator.sendBeacon(\n `${this.config.url}/ingest/metrics?key=${this.config.apiKey}`,\n blob\n )\n this.log('Beacon sent metrics:', metrics.length)\n }\n } else {\n // Fallback to fetch\n this.flushAll()\n }\n }\n\n async flushAll(): Promise<void> {\n await Promise.all([this.flushErrors(), this.flushMetrics()])\n }\n}\n","import type { TarslogsConfig, ErrorPayload, MetricPayload } from './types'\nimport { Transport } from './transport'\n\nexport type { TarslogsConfig } from './types'\n\nexport class TarslogsClient {\n private config: TarslogsConfig | null = null\n private transport = new Transport()\n private context: Record<string, any> = {}\n\n /**\n * Initialize the client with configuration.\n * Must be called before any other methods.\n */\n init(config: TarslogsConfig): void {\n this.config = config\n this.transport.init(config)\n }\n\n /**\n * Merge additional context that will be sent with all errors and metrics.\n * Useful for setting userId, route, etc.\n */\n setContext(ctx: Record<string, any>): void {\n this.context = { ...this.context, ...ctx }\n }\n\n /**\n * Clear all context (e.g., on logout).\n */\n clearContext(): void {\n this.context = {}\n }\n\n /**\n * Capture an error and send to TarsLogs.\n */\n captureError(error: Error | string, extra?: Record<string, any>): void {\n if (!this.config) return\n\n let payload: ErrorPayload\n\n if (typeof error === 'string') {\n payload = {\n message: error,\n environment: this.config.environment,\n version: this.config.version,\n context: { ...this.context, ...extra },\n timestamp: new Date().toISOString(),\n }\n } else {\n payload = {\n message: error.message,\n stack: error.stack,\n environment: this.config.environment,\n version: this.config.version,\n context: { ...this.context, ...extra },\n timestamp: new Date().toISOString(),\n }\n\n // Try to extract file/line/col from stack\n if (error.stack) {\n const match = error.stack.match(/(?:at\\s+.+\\s+\\(|at\\s+)(.+):(\\d+):(\\d+)\\)?/)\n if (match) {\n payload.file = match[1]\n payload.line = parseInt(match[2], 10)\n payload.col = parseInt(match[3], 10)\n }\n }\n }\n\n this.transport.enqueueError(payload)\n }\n\n /**\n * Increment a counter metric.\n */\n increment(name: string, value: number = 1, tags?: Record<string, string>): void {\n if (!this.config) return\n const payload: MetricPayload = {\n name,\n type: 'counter',\n value,\n tags,\n timestamp: new Date().toISOString(),\n }\n this.transport.enqueueMetric(payload)\n }\n\n /**\n * Set a gauge metric (point-in-time value).\n */\n gauge(name: string, value: number, tags?: Record<string, string>): void {\n if (!this.config) return\n const payload: MetricPayload = {\n name,\n type: 'gauge',\n value,\n tags,\n timestamp: new Date().toISOString(),\n }\n this.transport.enqueueMetric(payload)\n }\n\n /**\n * Record a histogram metric (distribution of values).\n */\n histogram(name: string, value: number, tags?: Record<string, string>): void {\n if (!this.config) return\n const payload: MetricPayload = {\n name,\n type: 'histogram',\n value,\n tags,\n timestamp: new Date().toISOString(),\n }\n this.transport.enqueueMetric(payload)\n }\n\n /**\n * Flush all pending payloads immediately.\n * Call before page unload or process exit.\n */\n async flush(): Promise<void> {\n await this.transport.flushAll()\n }\n}\n","import { TarslogsClient } from './core'\nimport type { TarslogsConfig } from './types'\n\n// Server-side Hono middleware — NO browser globals (window, document, navigator)\n\ninterface HonoContext {\n req: {\n method: string\n path: string\n url: string\n }\n res: {\n status: number\n }\n json: (data: unknown, status?: number) => Response\n}\n\ntype HonoNext = () => Promise<void>\n\ninterface HonoMiddleware {\n (c: HonoContext, next: HonoNext): Promise<Response | void>\n}\n\ninterface HonoApp {\n use: (path: string, ...handlers: HonoMiddleware[]) => void\n}\n\n/**\n * Hono middleware factory that catches errors in route handlers\n * and reports them to TarsLogs.\n *\n * Usage:\n * app.use('*', tarslogsMiddleware(tarslogsClient))\n */\nexport function tarslogsMiddleware(client: TarslogsClient): HonoMiddleware {\n return async (c: HonoContext, next: HonoNext): Promise<Response | void> => {\n try {\n await next()\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err))\n\n client.captureError(error, {\n source: 'hono-middleware',\n method: c.req.method,\n path: c.req.path,\n url: c.req.url,\n })\n\n // Re-throw so Hono's error handler can deal with it\n throw err\n }\n }\n}\n\n/**\n * One-line setup: initializes a TarslogsClient and attaches\n * the middleware to a Hono app.\n *\n * Usage:\n * const tarslogs = tarslogsHono(app, { url: '...', projectId: '...', apiKey: '...' })\n */\nexport function tarslogsHono(app: HonoApp, config: TarslogsConfig): TarslogsClient {\n const client = new TarslogsClient()\n client.init(config)\n app.use('*', tarslogsMiddleware(client))\n return client\n}\n"],"mappings":";AAOO,IAAM,YAAN,MAAgB;AAAA,EACb,SAAgC;AAAA,EAChC,aAA6B,CAAC;AAAA,EAC9B,cAA+B,CAAC;AAAA,EAChC,aAAoD;AAAA,EACpD,iBAAiC;AAAA,IACvC,YAAY,CAAC;AAAA,IACb,cAAc;AAAA,EAChB;AAAA,EACQ,aAAmD,CAAC;AAAA,EAE5D,KAAK,QAA8B;AACjC,SAAK,SAAS;AACd,SAAK,eAAe,eAAe,OAAO,sBAAsB;AAGhE,SAAK,aAAa,YAAY,MAAM;AAClC,WAAK,SAAS;AAAA,IAChB,GAAG,GAAI;AAGP,QAAI,OAAO,WAAW,eAAe,OAAO,OAAO,qBAAqB,YAAY;AAClF,aAAO,iBAAiB,oBAAoB,MAAM;AAChD,YAAI,SAAS,oBAAoB,UAAU;AACzC,eAAK,eAAe;AAAA,QACtB;AAAA,M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