@temps-sdk/node-sdk 0.0.1-alpha.4 → 0.0.2
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/README.md +499 -7
- package/dist/client/client/client.gen.d.ts +0 -1
- package/dist/client/client/index.d.ts +0 -1
- package/dist/client/client/types.gen.d.ts +0 -1
- package/dist/client/client/utils.gen.d.ts +0 -1
- package/dist/client/client.gen.d.ts +0 -1
- package/dist/client/client.gen.js +3 -1
- package/dist/client/core/auth.gen.d.ts +0 -1
- package/dist/client/core/bodySerializer.gen.d.ts +0 -1
- package/dist/client/core/params.gen.d.ts +0 -1
- package/dist/client/core/pathSerializer.gen.d.ts +0 -1
- package/dist/client/core/serverSentEvents.gen.d.ts +0 -1
- package/dist/client/core/types.gen.d.ts +0 -1
- package/dist/client/core/utils.gen.d.ts +0 -1
- package/dist/client/index.d.ts +0 -1
- package/dist/client/sdk.gen.d.ts +805 -241
- package/dist/client/sdk.gen.js +2556 -1266
- package/dist/client/types.gen.d.ts +11881 -5262
- package/dist/errors/client.d.ts +46 -0
- package/dist/errors/client.js +261 -0
- package/dist/errors/hub.d.ts +22 -0
- package/dist/errors/hub.js +102 -0
- package/dist/errors/index.d.ts +35 -0
- package/dist/errors/index.js +167 -0
- package/dist/errors/scope.d.ts +23 -0
- package/dist/errors/scope.js +82 -0
- package/dist/errors/stacktrace.d.ts +5 -0
- package/dist/errors/stacktrace.js +113 -0
- package/dist/errors/transaction.d.ts +57 -0
- package/dist/errors/transaction.js +163 -0
- package/dist/errors/transport.d.ts +23 -0
- package/dist/errors/transport.js +72 -0
- package/dist/errors/types.d.ts +200 -0
- package/dist/errors/types.js +1 -0
- package/dist/index.d.ts +1727 -798
- package/dist/index.js +371 -280
- package/package.json +6 -4
- package/dist/client/client/client.gen.d.ts.map +0 -1
- package/dist/client/client/index.d.ts.map +0 -1
- package/dist/client/client/types.gen.d.ts.map +0 -1
- package/dist/client/client/utils.gen.d.ts.map +0 -1
- package/dist/client/client.gen.d.ts.map +0 -1
- package/dist/client/core/auth.gen.d.ts.map +0 -1
- package/dist/client/core/bodySerializer.gen.d.ts.map +0 -1
- package/dist/client/core/params.gen.d.ts.map +0 -1
- package/dist/client/core/pathSerializer.gen.d.ts.map +0 -1
- package/dist/client/core/serverSentEvents.gen.d.ts.map +0 -1
- package/dist/client/core/types.gen.d.ts.map +0 -1
- package/dist/client/core/utils.gen.d.ts.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/sdk.gen.d.ts.map +0 -1
- package/dist/client/types.gen.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,507 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/AnomalyCo/temps/main/temps-demo.gif" alt="Temps Platform" width="700" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">@temps-sdk/node-sdk</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@temps-sdk/node-sdk"><img src="https://img.shields.io/npm/v/@temps-sdk/node-sdk.svg" alt="npm version" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@temps-sdk/node-sdk"><img src="https://img.shields.io/npm/dm/@temps-sdk/node-sdk.svg" alt="npm downloads" /></a>
|
|
10
|
+
<a href="https://github.com/AnomalyCo/temps/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@temps-sdk/node-sdk.svg" alt="license" /></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
The official Node.js SDK for Temps. A typed API client for the entire platform and a Sentry-compatible error tracking client for server-side applications.
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
---
|
|
4
18
|
|
|
5
19
|
```bash
|
|
6
|
-
|
|
20
|
+
# npm
|
|
21
|
+
npm install @temps-sdk/node-sdk
|
|
22
|
+
|
|
23
|
+
# bun
|
|
24
|
+
bun add @temps-sdk/node-sdk
|
|
25
|
+
|
|
26
|
+
# pnpm
|
|
27
|
+
pnpm add @temps-sdk/node-sdk
|
|
28
|
+
|
|
29
|
+
# yarn
|
|
30
|
+
yarn add @temps-sdk/node-sdk
|
|
7
31
|
```
|
|
8
32
|
|
|
9
|
-
|
|
33
|
+
**Peer dependencies:** `typescript >= 5`
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
## API Client
|
|
36
|
+
|
|
37
|
+
### Setup
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { TempsClient } from '@temps-sdk/node-sdk';
|
|
41
|
+
|
|
42
|
+
const temps = new TempsClient({
|
|
43
|
+
baseUrl: 'https://your-instance.temps.dev',
|
|
44
|
+
apiKey: 'your-api-key',
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Namespaces
|
|
49
|
+
|
|
50
|
+
The client organizes all platform operations into 24 typed namespaces:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// Projects
|
|
54
|
+
const { data: projects } = await temps.projects.list();
|
|
55
|
+
const { data: project } = await temps.projects.get({ path: { project_id: 1 } });
|
|
56
|
+
|
|
57
|
+
// Deployments
|
|
58
|
+
const { data: deployments } = await temps.deployments.list({ path: { project_id: 1 } });
|
|
59
|
+
await temps.deployments.deploy({ path: { project_id: 1 }, body: { branch: 'main' } });
|
|
60
|
+
await temps.deployments.rollback({ path: { project_id: 1, deployment_id: 5 } });
|
|
61
|
+
|
|
62
|
+
// Git Providers
|
|
63
|
+
const { data: providers } = await temps.git.listProviders();
|
|
64
|
+
await temps.git.syncRepositories({ path: { provider_id: 1 } });
|
|
65
|
+
|
|
66
|
+
// External Services (PostgreSQL, Redis, S3)
|
|
67
|
+
const { data: services } = await temps.externalServices.list({ path: { project_id: 1 } });
|
|
68
|
+
|
|
69
|
+
// Domains & SSL
|
|
70
|
+
const { data: domains } = await temps.domains.list();
|
|
71
|
+
await temps.domains.provision({ path: { domain_id: 1 } });
|
|
72
|
+
|
|
73
|
+
// Monitoring
|
|
74
|
+
const { data: monitors } = await temps.monitoring.listMonitors();
|
|
75
|
+
const { data: incidents } = await temps.monitoring.listIncidents({ path: { monitor_id: 1 } });
|
|
76
|
+
|
|
77
|
+
// Analytics
|
|
78
|
+
const { data: stats } = await temps.analytics.getGeneralStats({ path: { project_id: 1 } });
|
|
79
|
+
const { data: visitors } = await temps.analytics.getVisitors({ path: { project_id: 1 } });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Full namespace list:**
|
|
83
|
+
|
|
84
|
+
| Namespace | Description |
|
|
85
|
+
|-----------|-------------|
|
|
86
|
+
| `temps.apiKeys` | API key CRUD, activate/deactivate |
|
|
87
|
+
| `temps.analytics` | Visitors, sessions, events, enrichment, stats |
|
|
88
|
+
| `temps.auditLogs` | Audit log retrieval |
|
|
89
|
+
| `temps.authentication` | Login, logout, magic links, MFA, password reset |
|
|
90
|
+
| `temps.backups` | Backup schedules, S3 sources, run/restore |
|
|
91
|
+
| `temps.crons` | Cron jobs and execution history |
|
|
92
|
+
| `temps.deployments` | Deploy, cancel, pause, resume, rollback, teardown, logs |
|
|
93
|
+
| `temps.dns` | DNS providers, managed domains, zone listing, A record lookup |
|
|
94
|
+
| `temps.domains` | SSL/TLS domains, ACME provisioning, challenge tokens |
|
|
95
|
+
| `temps.email` | Email providers, domains, send, stats |
|
|
96
|
+
| `temps.externalServices` | PostgreSQL, Redis, S3 service lifecycle, env vars, containers |
|
|
97
|
+
| `temps.files` | File retrieval by ID |
|
|
98
|
+
| `temps.funnels` | Funnel CRUD, metrics, previews |
|
|
99
|
+
| `temps.git` | GitHub/GitLab providers, repo connections, sync |
|
|
100
|
+
| `temps.loadBalancer` | Route management |
|
|
101
|
+
| `temps.monitoring` | Monitors, incidents, uptime history, status buckets |
|
|
102
|
+
| `temps.notifications` | Preferences, providers (email, Slack), test notifications |
|
|
103
|
+
| `temps.performance` | Web Vitals metrics, grouped page metrics |
|
|
104
|
+
| `temps.platform` | Instance info, IPs, geolocation, activity graph, presets |
|
|
105
|
+
| `temps.projects` | Full project lifecycle: environments, domains, env vars, containers, analytics, errors, session replay, webhooks, DSN, IP access |
|
|
106
|
+
| `temps.proxyLogs` | Proxy log queries, time bucket stats |
|
|
107
|
+
| `temps.repositories` | Synced repos, branches, tags, presets |
|
|
108
|
+
| `temps.sessionReplay` | Session init, events, deletion, visitor sessions |
|
|
109
|
+
| `temps.settings` | Platform settings |
|
|
110
|
+
| `temps.users` | User CRUD, MFA, roles |
|
|
111
|
+
|
|
112
|
+
### Raw Client Access
|
|
113
|
+
|
|
114
|
+
For advanced use cases or direct access to the underlying HTTP client:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const client = temps.rawClient;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### TypeScript
|
|
121
|
+
|
|
122
|
+
All request/response types are auto-generated from the OpenAPI spec and exported:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import type {
|
|
126
|
+
ProjectResponse,
|
|
127
|
+
DeploymentResponse,
|
|
128
|
+
CreateProjectRequest,
|
|
129
|
+
} from '@temps-sdk/node-sdk';
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Error Tracking
|
|
135
|
+
|
|
136
|
+
A Sentry-compatible error tracking client that captures exceptions, messages, and performance data from your Node.js application and sends them to your Temps instance.
|
|
137
|
+
|
|
138
|
+
### Setup
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { ErrorTracking } from '@temps-sdk/node-sdk';
|
|
142
|
+
|
|
143
|
+
ErrorTracking.init({
|
|
144
|
+
dsn: 'https://public-key@your-instance.temps.dev/1',
|
|
145
|
+
environment: 'production',
|
|
146
|
+
release: '1.0.0',
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The DSN follows the Sentry format: `https://<public-key>@<host>/<project-id>`. Find it in your project's settings in the Temps dashboard.
|
|
151
|
+
|
|
152
|
+
### Configuration
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
ErrorTracking.init({
|
|
156
|
+
// Required
|
|
157
|
+
dsn: 'https://key@host/project_id',
|
|
158
|
+
|
|
159
|
+
// Environment
|
|
160
|
+
environment: 'production', // Default: 'production'
|
|
161
|
+
release: '1.2.3', // Your app version
|
|
162
|
+
serverName: 'api-server-1', // Server identifier
|
|
163
|
+
|
|
164
|
+
// Sampling
|
|
165
|
+
sampleRate: 1.0, // Error sample rate (0.0 - 1.0, default: 1.0)
|
|
166
|
+
tracesSampleRate: 0.1, // Performance trace sample rate (0.0 - 1.0)
|
|
167
|
+
|
|
168
|
+
// Filtering
|
|
169
|
+
ignoreErrors: [ // Errors to suppress (strings or RegExp)
|
|
170
|
+
'ResizeObserver loop',
|
|
171
|
+
/^NetworkError/,
|
|
172
|
+
],
|
|
173
|
+
beforeSend: (event) => { // Modify or drop events before sending
|
|
174
|
+
if (event.tags?.internal) return null; // Return null to drop
|
|
175
|
+
return event;
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
// Behavior
|
|
179
|
+
maxBreadcrumbs: 100, // Max breadcrumbs to retain (default: 100)
|
|
180
|
+
attachStacktrace: true, // Attach stack traces to messages (default: true)
|
|
181
|
+
debug: false, // Log to console instead of sending (default: false)
|
|
182
|
+
|
|
183
|
+
// Integrations
|
|
184
|
+
integrations: [], // Custom integrations (call setupOnce() on init)
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Capturing Errors
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// Capture an exception
|
|
192
|
+
try {
|
|
193
|
+
riskyOperation();
|
|
194
|
+
} catch (error) {
|
|
195
|
+
const eventId = ErrorTracking.captureException(error);
|
|
196
|
+
console.log(`Reported as ${eventId}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Capture with extra context
|
|
200
|
+
ErrorTracking.captureException(error, {
|
|
201
|
+
tags: { subsystem: 'payments' },
|
|
202
|
+
extra: { orderId: '12345', amount: 99.99 },
|
|
203
|
+
level: 'fatal',
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Capture a message
|
|
207
|
+
ErrorTracking.captureMessage('Disk usage above 90%', 'warning');
|
|
208
|
+
|
|
209
|
+
// Capture a raw event
|
|
210
|
+
ErrorTracking.captureEvent({
|
|
211
|
+
message: 'Custom event',
|
|
212
|
+
level: 'info',
|
|
213
|
+
tags: { source: 'cron' },
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Context and Scope
|
|
218
|
+
|
|
219
|
+
Enrich error reports with user, tags, and structured data:
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// Set the current user (attached to all subsequent events)
|
|
223
|
+
ErrorTracking.setUser({
|
|
224
|
+
id: '123',
|
|
225
|
+
email: 'alice@example.com',
|
|
226
|
+
username: 'alice',
|
|
227
|
+
ip_address: '{{auto}}',
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// Set global tags
|
|
231
|
+
ErrorTracking.setTag('region', 'eu-west-1');
|
|
232
|
+
ErrorTracking.setTags({ service: 'api', version: '2.0' });
|
|
233
|
+
|
|
234
|
+
// Set extra data
|
|
235
|
+
ErrorTracking.setExtra('requestId', 'abc-123');
|
|
236
|
+
ErrorTracking.setExtras({ query: 'SELECT ...', duration: 150 });
|
|
237
|
+
|
|
238
|
+
// Set structured context
|
|
239
|
+
ErrorTracking.setContext('order', {
|
|
240
|
+
id: 'order-456',
|
|
241
|
+
total: 99.99,
|
|
242
|
+
items: 3,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Clear user on logout
|
|
246
|
+
ErrorTracking.setUser(null);
|
|
13
247
|
```
|
|
14
248
|
|
|
15
|
-
|
|
249
|
+
### Breadcrumbs
|
|
250
|
+
|
|
251
|
+
Breadcrumbs leave a trail of events leading up to an error -- invaluable for debugging:
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
ErrorTracking.addBreadcrumb({
|
|
255
|
+
category: 'auth',
|
|
256
|
+
message: 'User logged in',
|
|
257
|
+
level: 'info',
|
|
258
|
+
data: { method: 'oauth' },
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
ErrorTracking.addBreadcrumb({
|
|
262
|
+
category: 'http',
|
|
263
|
+
message: 'GET /api/users',
|
|
264
|
+
level: 'info',
|
|
265
|
+
type: 'http',
|
|
266
|
+
data: { status: 200, duration: 45 },
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Clear all breadcrumbs
|
|
270
|
+
ErrorTracking.clearBreadcrumbs();
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
| Property | Values |
|
|
274
|
+
|----------|--------|
|
|
275
|
+
| `type` | `'default'`, `'http'`, `'navigation'`, `'console'` |
|
|
276
|
+
| `level` | `'debug'`, `'info'`, `'warning'`, `'error'`, `'critical'` |
|
|
277
|
+
|
|
278
|
+
### Scoped Context
|
|
279
|
+
|
|
280
|
+
Isolate context for specific operations so it doesn't leak to other events:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
// configureScope modifies the current scope permanently
|
|
284
|
+
ErrorTracking.configureScope((scope) => {
|
|
285
|
+
scope.setTag('transaction', 'checkout');
|
|
286
|
+
scope.setUser({ id: '123' });
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// withScope creates a temporary scope -- discarded after the callback
|
|
290
|
+
ErrorTracking.withScope((scope) => {
|
|
291
|
+
scope.setTag('component', 'payment-form');
|
|
292
|
+
scope.setExtra('cardLast4', '4242');
|
|
293
|
+
ErrorTracking.captureMessage('Payment processed');
|
|
294
|
+
// These tags/extras don't affect other events
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Performance Monitoring
|
|
299
|
+
|
|
300
|
+
Track transactions and spans to measure latency across your stack:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
// Start a transaction
|
|
304
|
+
const transaction = ErrorTracking.startTransaction({
|
|
305
|
+
name: 'POST /api/checkout',
|
|
306
|
+
op: 'http.server',
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Create child spans for sub-operations
|
|
310
|
+
const dbSpan = transaction.startChild({
|
|
311
|
+
op: 'db.query',
|
|
312
|
+
description: 'SELECT * FROM orders WHERE id = ?',
|
|
313
|
+
});
|
|
314
|
+
// ... database query ...
|
|
315
|
+
dbSpan.finish();
|
|
316
|
+
|
|
317
|
+
const apiSpan = transaction.startChild({
|
|
318
|
+
op: 'http.client',
|
|
319
|
+
description: 'POST https://payments.example.com/charge',
|
|
320
|
+
});
|
|
321
|
+
// ... external API call ...
|
|
322
|
+
apiSpan.setStatus('ok');
|
|
323
|
+
apiSpan.finish();
|
|
324
|
+
|
|
325
|
+
// Add custom measurements
|
|
326
|
+
transaction.setMeasurement('order_total', 99.99, 'usd');
|
|
327
|
+
transaction.setMeasurement('items_count', 3, 'count');
|
|
328
|
+
|
|
329
|
+
// Finish the transaction (sends it to Temps if sampled)
|
|
330
|
+
transaction.setStatus('ok');
|
|
331
|
+
transaction.finish();
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Spans can be nested. Each span captures `startTimestamp`, `endTimestamp`, `op`, `description`, `status`, `tags`, and `data`.
|
|
335
|
+
|
|
336
|
+
### User Feedback
|
|
337
|
+
|
|
338
|
+
Collect feedback from users after an error occurs:
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
const eventId = ErrorTracking.captureException(error);
|
|
342
|
+
|
|
343
|
+
// Later, when the user submits a feedback form:
|
|
344
|
+
ErrorTracking.captureUserFeedback({
|
|
345
|
+
event_id: eventId,
|
|
346
|
+
name: 'Alice',
|
|
347
|
+
email: 'alice@example.com',
|
|
348
|
+
comments: 'The checkout button did nothing when I clicked it.',
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Global Error Handlers
|
|
353
|
+
|
|
354
|
+
The SDK automatically captures unhandled errors at the process level:
|
|
355
|
+
|
|
356
|
+
| Handler | Level | Behavior |
|
|
357
|
+
|---------|-------|----------|
|
|
358
|
+
| `process.on('uncaughtException')` | `fatal` | Captured, then `process.exit(1)` |
|
|
359
|
+
| `process.on('unhandledRejection')` | `error` | Captured, process continues |
|
|
360
|
+
|
|
361
|
+
Both are tagged with `handled: false` so you can filter them in the dashboard.
|
|
362
|
+
|
|
363
|
+
### Shutdown
|
|
364
|
+
|
|
365
|
+
Flush pending events before process exit:
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
// Flush pending events (waits up to 2s by default)
|
|
369
|
+
await ErrorTracking.flush(2000);
|
|
370
|
+
|
|
371
|
+
// Or close the client entirely (disables further capturing + flushes)
|
|
372
|
+
await ErrorTracking.close(2000);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Framework Integrations
|
|
376
|
+
|
|
377
|
+
#### Express.js
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
import express from 'express';
|
|
381
|
+
import { ErrorTracking } from '@temps-sdk/node-sdk';
|
|
382
|
+
|
|
383
|
+
ErrorTracking.init({ dsn: '...' });
|
|
384
|
+
|
|
385
|
+
const app = express();
|
|
386
|
+
|
|
387
|
+
// Add breadcrumbs for each request
|
|
388
|
+
app.use((req, res, next) => {
|
|
389
|
+
ErrorTracking.addBreadcrumb({
|
|
390
|
+
category: 'http',
|
|
391
|
+
message: `${req.method} ${req.path}`,
|
|
392
|
+
type: 'http',
|
|
393
|
+
data: { query: req.query },
|
|
394
|
+
});
|
|
395
|
+
next();
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// Set user context from auth middleware
|
|
399
|
+
app.use((req, res, next) => {
|
|
400
|
+
if (req.user) {
|
|
401
|
+
ErrorTracking.setUser({
|
|
402
|
+
id: req.user.id,
|
|
403
|
+
email: req.user.email,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
next();
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// Error handler (must be last)
|
|
410
|
+
app.use((err, req, res, next) => {
|
|
411
|
+
ErrorTracking.captureException(err, {
|
|
412
|
+
extra: {
|
|
413
|
+
method: req.method,
|
|
414
|
+
url: req.originalUrl,
|
|
415
|
+
body: req.body,
|
|
416
|
+
},
|
|
417
|
+
});
|
|
418
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
419
|
+
});
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### Hono
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
import { Hono } from 'hono';
|
|
426
|
+
import { ErrorTracking } from '@temps-sdk/node-sdk';
|
|
427
|
+
|
|
428
|
+
ErrorTracking.init({ dsn: '...' });
|
|
429
|
+
|
|
430
|
+
const app = new Hono();
|
|
431
|
+
|
|
432
|
+
app.onError((err, c) => {
|
|
433
|
+
ErrorTracking.captureException(err, {
|
|
434
|
+
extra: { path: c.req.path, method: c.req.method },
|
|
435
|
+
});
|
|
436
|
+
return c.json({ error: 'Internal server error' }, 500);
|
|
437
|
+
});
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Debug Mode
|
|
441
|
+
|
|
442
|
+
Log events to the console instead of sending them. Useful during development:
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
ErrorTracking.init({
|
|
446
|
+
dsn: '...',
|
|
447
|
+
debug: process.env.NODE_ENV !== 'production',
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## Complete Example
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
import { TempsClient, ErrorTracking } from '@temps-sdk/node-sdk';
|
|
457
|
+
|
|
458
|
+
// Initialize error tracking
|
|
459
|
+
ErrorTracking.init({
|
|
460
|
+
dsn: 'https://key@your-instance.temps.dev/1',
|
|
461
|
+
environment: process.env.NODE_ENV,
|
|
462
|
+
release: process.env.npm_package_version,
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// Initialize API client
|
|
466
|
+
const temps = new TempsClient({
|
|
467
|
+
baseUrl: 'https://your-instance.temps.dev',
|
|
468
|
+
apiKey: process.env.TEMPS_API_KEY,
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// Use both together
|
|
472
|
+
async function deployProject(projectId: number, branch: string) {
|
|
473
|
+
ErrorTracking.addBreadcrumb({
|
|
474
|
+
category: 'deploy',
|
|
475
|
+
message: `Starting deployment for project ${projectId}`,
|
|
476
|
+
level: 'info',
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
try {
|
|
480
|
+
const { data } = await temps.deployments.deploy({
|
|
481
|
+
path: { project_id: projectId },
|
|
482
|
+
body: { branch },
|
|
483
|
+
});
|
|
484
|
+
return data;
|
|
485
|
+
} catch (error) {
|
|
486
|
+
ErrorTracking.captureException(error, {
|
|
487
|
+
tags: { projectId: String(projectId), branch },
|
|
488
|
+
});
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Requirements
|
|
495
|
+
|
|
496
|
+
- Node.js 18+ or Bun
|
|
497
|
+
- TypeScript 5+ (peer dependency)
|
|
498
|
+
|
|
499
|
+
## Related
|
|
500
|
+
|
|
501
|
+
- [`@temps-sdk/kv`](https://www.npmjs.com/package/@temps-sdk/kv) -- Key-value store
|
|
502
|
+
- [`@temps-sdk/blob`](https://www.npmjs.com/package/@temps-sdk/blob) -- File storage
|
|
503
|
+
- [`@temps-sdk/react-analytics`](https://www.npmjs.com/package/@temps-sdk/react-analytics) -- React analytics, session replay, engagement tracking
|
|
504
|
+
|
|
505
|
+
## License
|
|
506
|
+
|
|
507
|
+
MIT
|
|
@@ -5,4 +5,3 @@ export { buildClientParams } from '../core/params.gen';
|
|
|
5
5
|
export { createClient } from './client.gen';
|
|
6
6
|
export type { Client, ClientOptions, Config, CreateClientConfig, Options, OptionsLegacyParser, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
7
7
|
export { createConfig, mergeHeaders } from './utils.gen';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -122,4 +122,3 @@ export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean =
|
|
|
122
122
|
headers?: any;
|
|
123
123
|
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers' | 'url'> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body'> : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'url'> & TData;
|
|
124
124
|
export {};
|
|
125
|
-
//# sourceMappingURL=types.gen.d.ts.map
|
|
@@ -36,4 +36,3 @@ export declare const createInterceptors: <Req, Res, Err, Options>() => {
|
|
|
36
36
|
};
|
|
37
37
|
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
38
38
|
export {};
|
|
39
|
-
//# sourceMappingURL=utils.gen.d.ts.map
|
|
@@ -10,4 +10,3 @@ import { type Config, type ClientOptions as DefaultClientOptions } from './clien
|
|
|
10
10
|
*/
|
|
11
11
|
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
|
|
12
12
|
export declare const client: import("./client").Client;
|
|
13
|
-
//# sourceMappingURL=client.gen.d.ts.map
|
|
@@ -69,4 +69,3 @@ export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unkn
|
|
|
69
69
|
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
70
70
|
};
|
|
71
71
|
export declare const createSseClient: <TData = unknown>({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }: ServerSentEventsOptions) => ServerSentEventsResult<TData>;
|
|
72
|
-
//# sourceMappingURL=serverSentEvents.gen.d.ts.map
|
package/dist/client/index.d.ts
CHANGED