@watchupltd/svelte 1.0.0 → 1.0.3
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 +509 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +105 -0
- package/dist/index.mjs +73 -0
- package/package.json +8 -4
- package/src/index.ts +0 -84
- package/tsconfig.json +0 -9
package/README.md
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
# @watchupltd/svelte
|
|
2
|
+
|
|
3
|
+
Svelte integration for incident tracking with store-based state management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @watchupltd/svelte
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// main.ts
|
|
15
|
+
import { initIncident } from '@watchupltd/svelte';
|
|
16
|
+
import App from './App.svelte';
|
|
17
|
+
|
|
18
|
+
// Initialize incident tracking
|
|
19
|
+
initIncident({
|
|
20
|
+
apiKey: 'your-api-key',
|
|
21
|
+
projectId: 'your-project-id',
|
|
22
|
+
environment: 'production',
|
|
23
|
+
captureConsoleErrors: true
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const app = new App({
|
|
27
|
+
target: document.body
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default app;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage in Components
|
|
34
|
+
|
|
35
|
+
### Using Helper Functions
|
|
36
|
+
|
|
37
|
+
```svelte
|
|
38
|
+
<script>
|
|
39
|
+
import { captureError, captureMessage, addBreadcrumb, setUser } from '@watchupltd/svelte';
|
|
40
|
+
|
|
41
|
+
async function handleClick() {
|
|
42
|
+
addBreadcrumb({
|
|
43
|
+
message: 'User clicked button',
|
|
44
|
+
category: 'user-action'
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await fetchData();
|
|
49
|
+
captureMessage('Data loaded successfully', 'info');
|
|
50
|
+
} catch (error) {
|
|
51
|
+
captureError(error, {
|
|
52
|
+
tags: { component: 'DataFetcher' }
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<button on:click={handleClick}>Load Data</button>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Using the Store
|
|
62
|
+
|
|
63
|
+
```svelte
|
|
64
|
+
<script>
|
|
65
|
+
import { incidentStore } from '@watchupltd/svelte';
|
|
66
|
+
|
|
67
|
+
async function handleError() {
|
|
68
|
+
try {
|
|
69
|
+
await riskyOperation();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
$incidentStore?.captureError(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
</script>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Using the Client Directly
|
|
78
|
+
|
|
79
|
+
```svelte
|
|
80
|
+
<script>
|
|
81
|
+
import { getIncidentClient } from '@watchupltd/svelte';
|
|
82
|
+
|
|
83
|
+
const client = getIncidentClient();
|
|
84
|
+
|
|
85
|
+
function trackEvent() {
|
|
86
|
+
client?.captureMessage('Custom event', 'info');
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## What It Tracks
|
|
92
|
+
|
|
93
|
+
### Automatic Tracking
|
|
94
|
+
|
|
95
|
+
- **Global JavaScript Errors**: Via `window.onerror`
|
|
96
|
+
- **Unhandled Promise Rejections**: Via `window.onunhandledrejection`
|
|
97
|
+
- **Console Errors**: Optional via `captureConsoleErrors` config
|
|
98
|
+
|
|
99
|
+
### Manual Tracking
|
|
100
|
+
|
|
101
|
+
- Custom errors via `captureError()`
|
|
102
|
+
- Log messages via `captureMessage()`
|
|
103
|
+
- User context via `setUser()`
|
|
104
|
+
- Breadcrumbs via `addBreadcrumb()`
|
|
105
|
+
|
|
106
|
+
## API Reference
|
|
107
|
+
|
|
108
|
+
### `initIncident(config: SvelteIncidentConfig): IncidentClient`
|
|
109
|
+
|
|
110
|
+
Initialize the incident tracking SDK. Call once at app startup.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { initIncident } from '@watchupltd/svelte';
|
|
114
|
+
|
|
115
|
+
const client = initIncident({
|
|
116
|
+
apiKey: 'your-api-key',
|
|
117
|
+
projectId: 'your-project-id',
|
|
118
|
+
environment: 'production',
|
|
119
|
+
captureConsoleErrors: true
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Helper Functions
|
|
124
|
+
|
|
125
|
+
**`captureError(error: Error, context?: any): Promise<string | null>`**
|
|
126
|
+
```typescript
|
|
127
|
+
import { captureError } from '@watchupltd/svelte';
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
await riskyOperation();
|
|
131
|
+
} catch (error) {
|
|
132
|
+
captureError(error, {
|
|
133
|
+
tags: { operation: 'data-fetch' },
|
|
134
|
+
extra: { userId: '123' }
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**`captureMessage(message: string, level?: SeverityLevel, context?: any): Promise<string | null>`**
|
|
140
|
+
```typescript
|
|
141
|
+
import { captureMessage } from '@watchupltd/svelte';
|
|
142
|
+
|
|
143
|
+
captureMessage('User completed checkout', 'info', {
|
|
144
|
+
tags: { flow: 'checkout' }
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**`addBreadcrumb(breadcrumb: any): void`**
|
|
149
|
+
```typescript
|
|
150
|
+
import { addBreadcrumb } from '@watchupltd/svelte';
|
|
151
|
+
|
|
152
|
+
addBreadcrumb({
|
|
153
|
+
message: 'User clicked submit button',
|
|
154
|
+
category: 'user-action',
|
|
155
|
+
level: 'info'
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**`setUser(user: any): void`**
|
|
160
|
+
```typescript
|
|
161
|
+
import { setUser } from '@watchupltd/svelte';
|
|
162
|
+
|
|
163
|
+
setUser({
|
|
164
|
+
id: 'user-123',
|
|
165
|
+
email: 'user@example.com',
|
|
166
|
+
username: 'john_doe'
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Store
|
|
171
|
+
|
|
172
|
+
**`incidentStore`**
|
|
173
|
+
|
|
174
|
+
A Svelte store containing the `IncidentClient` instance.
|
|
175
|
+
|
|
176
|
+
```svelte
|
|
177
|
+
<script>
|
|
178
|
+
import { incidentStore } from '@watchupltd/svelte';
|
|
179
|
+
|
|
180
|
+
$: if ($incidentStore) {
|
|
181
|
+
$incidentStore.setTag('version', '1.0.0');
|
|
182
|
+
}
|
|
183
|
+
</script>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Client Access
|
|
187
|
+
|
|
188
|
+
**`getIncidentClient(): IncidentClient | null`**
|
|
189
|
+
|
|
190
|
+
Get the current client instance.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { getIncidentClient } from '@watchupltd/svelte';
|
|
194
|
+
|
|
195
|
+
const client = getIncidentClient();
|
|
196
|
+
if (client) {
|
|
197
|
+
client.captureMessage('App initialized', 'info');
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Configuration
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
interface SvelteIncidentConfig {
|
|
205
|
+
apiKey: string; // Required: Your API key
|
|
206
|
+
projectId: string; // Required: Your project ID
|
|
207
|
+
endpoint?: string; // Optional: Custom API endpoint
|
|
208
|
+
environment?: string; // Optional: Environment (default: 'production')
|
|
209
|
+
batchInterval?: number; // Optional: Batch interval in ms (default: 5000)
|
|
210
|
+
maxBatchSize?: number; // Optional: Max events per batch (default: 10)
|
|
211
|
+
maxRetries?: number; // Optional: Max retry attempts (default: 3)
|
|
212
|
+
enabled?: boolean; // Optional: Enable/disable SDK (default: true)
|
|
213
|
+
captureConsoleErrors?: boolean; // Optional: Capture console.error (default: false)
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Examples
|
|
218
|
+
|
|
219
|
+
### Track User Login
|
|
220
|
+
|
|
221
|
+
```svelte
|
|
222
|
+
<script>
|
|
223
|
+
import { captureError, captureMessage, setUser, addBreadcrumb } from '@watchupltd/svelte';
|
|
224
|
+
|
|
225
|
+
let email = '';
|
|
226
|
+
let password = '';
|
|
227
|
+
|
|
228
|
+
async function handleLogin() {
|
|
229
|
+
addBreadcrumb({
|
|
230
|
+
message: 'User attempting login',
|
|
231
|
+
category: 'auth'
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const user = await login(email, password);
|
|
236
|
+
|
|
237
|
+
setUser({
|
|
238
|
+
id: user.id,
|
|
239
|
+
email: user.email,
|
|
240
|
+
username: user.username
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
captureMessage('User logged in successfully', 'info');
|
|
244
|
+
} catch (error) {
|
|
245
|
+
captureError(error, {
|
|
246
|
+
tags: { flow: 'authentication' }
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
</script>
|
|
251
|
+
|
|
252
|
+
<form on:submit|preventDefault={handleLogin}>
|
|
253
|
+
<input type="email" bind:value={email} />
|
|
254
|
+
<input type="password" bind:value={password} />
|
|
255
|
+
<button type="submit">Login</button>
|
|
256
|
+
</form>
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Track API Calls
|
|
260
|
+
|
|
261
|
+
```svelte
|
|
262
|
+
<script>
|
|
263
|
+
import { onMount } from 'svelte';
|
|
264
|
+
import { captureError, addBreadcrumb } from '@watchupltd/svelte';
|
|
265
|
+
|
|
266
|
+
let data = null;
|
|
267
|
+
|
|
268
|
+
onMount(async () => {
|
|
269
|
+
addBreadcrumb({
|
|
270
|
+
message: 'Fetching user data',
|
|
271
|
+
category: 'api'
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
data = await fetchUserData();
|
|
276
|
+
} catch (error) {
|
|
277
|
+
captureError(error, {
|
|
278
|
+
tags: { api: 'users', endpoint: '/api/users' }
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
</script>
|
|
283
|
+
|
|
284
|
+
{#if data}
|
|
285
|
+
<div>{data.name}</div>
|
|
286
|
+
{/if}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Track Form Validation
|
|
290
|
+
|
|
291
|
+
```svelte
|
|
292
|
+
<script>
|
|
293
|
+
import { captureMessage } from '@watchupltd/svelte';
|
|
294
|
+
|
|
295
|
+
let formData = {
|
|
296
|
+
email: '',
|
|
297
|
+
message: ''
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
function validateForm() {
|
|
301
|
+
const errors = [];
|
|
302
|
+
|
|
303
|
+
if (!formData.email) {
|
|
304
|
+
errors.push('Email is required');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!formData.message) {
|
|
308
|
+
errors.push('Message is required');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (errors.length > 0) {
|
|
312
|
+
captureMessage(
|
|
313
|
+
`Form validation failed: ${errors.join(', ')}`,
|
|
314
|
+
'warning',
|
|
315
|
+
{
|
|
316
|
+
tags: { form: 'contact' },
|
|
317
|
+
extra: { errors }
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function handleSubmit() {
|
|
327
|
+
if (validateForm()) {
|
|
328
|
+
// Submit form
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
</script>
|
|
332
|
+
|
|
333
|
+
<form on:submit|preventDefault={handleSubmit}>
|
|
334
|
+
<input type="email" bind:value={formData.email} />
|
|
335
|
+
<textarea bind:value={formData.message}></textarea>
|
|
336
|
+
<button type="submit">Submit</button>
|
|
337
|
+
</form>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Track Store Changes
|
|
341
|
+
|
|
342
|
+
```svelte
|
|
343
|
+
<script>
|
|
344
|
+
import { writable } from 'svelte/store';
|
|
345
|
+
import { addBreadcrumb } from '@watchupltd/svelte';
|
|
346
|
+
|
|
347
|
+
const count = writable(0);
|
|
348
|
+
|
|
349
|
+
count.subscribe(value => {
|
|
350
|
+
addBreadcrumb({
|
|
351
|
+
message: `Count changed to ${value}`,
|
|
352
|
+
category: 'state-change',
|
|
353
|
+
data: { count: value }
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
function increment() {
|
|
358
|
+
count.update(n => n + 1);
|
|
359
|
+
}
|
|
360
|
+
</script>
|
|
361
|
+
|
|
362
|
+
<button on:click={increment}>
|
|
363
|
+
Count: {$count}
|
|
364
|
+
</button>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Error Boundary Pattern
|
|
368
|
+
|
|
369
|
+
```svelte
|
|
370
|
+
<script>
|
|
371
|
+
import { captureError } from '@watchupltd/svelte';
|
|
372
|
+
|
|
373
|
+
let error = null;
|
|
374
|
+
|
|
375
|
+
async function loadData() {
|
|
376
|
+
try {
|
|
377
|
+
error = null;
|
|
378
|
+
await fetchData();
|
|
379
|
+
} catch (e) {
|
|
380
|
+
error = e;
|
|
381
|
+
captureError(e, {
|
|
382
|
+
tags: { component: 'DataLoader' }
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
</script>
|
|
387
|
+
|
|
388
|
+
{#if error}
|
|
389
|
+
<div class="error">
|
|
390
|
+
<h2>Something went wrong</h2>
|
|
391
|
+
<p>We've been notified and are working on it.</p>
|
|
392
|
+
<button on:click={loadData}>Try Again</button>
|
|
393
|
+
</div>
|
|
394
|
+
{:else}
|
|
395
|
+
<!-- Your content -->
|
|
396
|
+
{/if}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## TypeScript Support
|
|
400
|
+
|
|
401
|
+
Full TypeScript support with type definitions included.
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
import type { SvelteIncidentConfig, IncidentClient } from '@watchupltd/svelte';
|
|
405
|
+
|
|
406
|
+
const config: SvelteIncidentConfig = {
|
|
407
|
+
apiKey: 'your-api-key',
|
|
408
|
+
projectId: 'your-project-id'
|
|
409
|
+
};
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## SvelteKit Support
|
|
413
|
+
|
|
414
|
+
Works with SvelteKit. Initialize in your root layout:
|
|
415
|
+
|
|
416
|
+
```svelte
|
|
417
|
+
<!-- +layout.svelte -->
|
|
418
|
+
<script>
|
|
419
|
+
import { browser } from '$app/environment';
|
|
420
|
+
import { initIncident } from '@watchupltd/svelte';
|
|
421
|
+
|
|
422
|
+
if (browser) {
|
|
423
|
+
initIncident({
|
|
424
|
+
apiKey: import.meta.env.VITE_INCIDENT_API_KEY,
|
|
425
|
+
projectId: import.meta.env.VITE_INCIDENT_PROJECT_ID
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
</script>
|
|
429
|
+
|
|
430
|
+
<slot />
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## Data Models
|
|
434
|
+
|
|
435
|
+
### Event Model
|
|
436
|
+
|
|
437
|
+
```json
|
|
438
|
+
{
|
|
439
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
440
|
+
"project_id": "proj_abc123",
|
|
441
|
+
"fingerprint": "a1b2c3d4e5f6...",
|
|
442
|
+
"title": "Error",
|
|
443
|
+
"message": "Something went wrong",
|
|
444
|
+
"stack_trace": "Error: Something went wrong\n at Component (App.svelte:10:5)",
|
|
445
|
+
"service": "frontend",
|
|
446
|
+
"environment": "production",
|
|
447
|
+
"severity": "error",
|
|
448
|
+
"timestamp": 1678901234567,
|
|
449
|
+
"platform": "javascript",
|
|
450
|
+
"release": "1.2.3",
|
|
451
|
+
"metadata": {
|
|
452
|
+
"svelte": {
|
|
453
|
+
"component": "App"
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
"user": {
|
|
457
|
+
"id": "user-123",
|
|
458
|
+
"email": "user@example.com",
|
|
459
|
+
"username": "john_doe"
|
|
460
|
+
},
|
|
461
|
+
"tags": {
|
|
462
|
+
"component": "App",
|
|
463
|
+
"version": "1.2.3"
|
|
464
|
+
},
|
|
465
|
+
"breadcrumbs": [
|
|
466
|
+
{
|
|
467
|
+
"timestamp": 1678901230000,
|
|
468
|
+
"message": "Component mounted",
|
|
469
|
+
"category": "svelte",
|
|
470
|
+
"level": "info",
|
|
471
|
+
"data": {"component": "App"}
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
"context": {
|
|
475
|
+
"svelte": {
|
|
476
|
+
"version": "4.0.0"
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### User Model
|
|
483
|
+
|
|
484
|
+
```json
|
|
485
|
+
{
|
|
486
|
+
"id": "user-123",
|
|
487
|
+
"email": "user@example.com",
|
|
488
|
+
"username": "john_doe",
|
|
489
|
+
"ip_address": "192.168.1.1"
|
|
490
|
+
}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
### Breadcrumb Model
|
|
494
|
+
|
|
495
|
+
```json
|
|
496
|
+
{
|
|
497
|
+
"timestamp": 1678901234567,
|
|
498
|
+
"message": "User action description",
|
|
499
|
+
"category": "user-action | navigation | http | database | console",
|
|
500
|
+
"level": "fatal | error | warning | info | debug",
|
|
501
|
+
"data": {
|
|
502
|
+
"key": "value"
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
## License
|
|
508
|
+
|
|
509
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as svelte_store from 'svelte/store';
|
|
2
|
+
import { IncidentClient, IncidentConfig } from '@watchupltd/core';
|
|
3
|
+
export { Breadcrumb, IncidentClient, IncidentConfig, SeverityLevel, User } from '@watchupltd/core';
|
|
4
|
+
|
|
5
|
+
declare const incidentStore: svelte_store.Writable<IncidentClient | null>;
|
|
6
|
+
interface SvelteIncidentConfig extends IncidentConfig {
|
|
7
|
+
captureConsoleErrors?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function initIncident(config: SvelteIncidentConfig): IncidentClient;
|
|
10
|
+
declare function getIncidentClient(): IncidentClient | null;
|
|
11
|
+
declare function captureError(error: Error, context?: any): Promise<string | null> | null;
|
|
12
|
+
declare function captureMessage(message: string, level?: any, context?: any): Promise<string | null> | null;
|
|
13
|
+
declare function addBreadcrumb(breadcrumb: any): void;
|
|
14
|
+
declare function setUser(user: any): void;
|
|
15
|
+
|
|
16
|
+
export { SvelteIncidentConfig, addBreadcrumb, captureError, captureMessage, getIncidentClient, incidentStore, initIncident, setUser };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as svelte_store from 'svelte/store';
|
|
2
|
+
import { IncidentClient, IncidentConfig } from '@watchupltd/core';
|
|
3
|
+
export { Breadcrumb, IncidentClient, IncidentConfig, SeverityLevel, User } from '@watchupltd/core';
|
|
4
|
+
|
|
5
|
+
declare const incidentStore: svelte_store.Writable<IncidentClient | null>;
|
|
6
|
+
interface SvelteIncidentConfig extends IncidentConfig {
|
|
7
|
+
captureConsoleErrors?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function initIncident(config: SvelteIncidentConfig): IncidentClient;
|
|
10
|
+
declare function getIncidentClient(): IncidentClient | null;
|
|
11
|
+
declare function captureError(error: Error, context?: any): Promise<string | null> | null;
|
|
12
|
+
declare function captureMessage(message: string, level?: any, context?: any): Promise<string | null> | null;
|
|
13
|
+
declare function addBreadcrumb(breadcrumb: any): void;
|
|
14
|
+
declare function setUser(user: any): void;
|
|
15
|
+
|
|
16
|
+
export { SvelteIncidentConfig, addBreadcrumb, captureError, captureMessage, getIncidentClient, incidentStore, initIncident, setUser };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
IncidentClient: () => import_core2.IncidentClient,
|
|
24
|
+
addBreadcrumb: () => addBreadcrumb,
|
|
25
|
+
captureError: () => captureError,
|
|
26
|
+
captureMessage: () => captureMessage,
|
|
27
|
+
getIncidentClient: () => getIncidentClient,
|
|
28
|
+
incidentStore: () => incidentStore,
|
|
29
|
+
initIncident: () => initIncident,
|
|
30
|
+
setUser: () => setUser
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(src_exports);
|
|
33
|
+
var import_store = require("svelte/store");
|
|
34
|
+
var import_core = require("@watchupltd/core");
|
|
35
|
+
var import_core2 = require("@watchupltd/core");
|
|
36
|
+
var client = null;
|
|
37
|
+
var incidentStore = (0, import_store.writable)(null);
|
|
38
|
+
function initIncident(config) {
|
|
39
|
+
if (client) {
|
|
40
|
+
return client;
|
|
41
|
+
}
|
|
42
|
+
client = new import_core.IncidentClient(config);
|
|
43
|
+
incidentStore.set(client);
|
|
44
|
+
if (typeof window !== "undefined") {
|
|
45
|
+
window.addEventListener("error", (event) => {
|
|
46
|
+
const error = event.error || new Error(event.message);
|
|
47
|
+
client?.captureError(error);
|
|
48
|
+
});
|
|
49
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
50
|
+
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
51
|
+
client?.captureError(error);
|
|
52
|
+
});
|
|
53
|
+
if (config.captureConsoleErrors) {
|
|
54
|
+
const originalError = console.error;
|
|
55
|
+
console.error = (...args) => {
|
|
56
|
+
originalError.apply(console, args);
|
|
57
|
+
const message = args.map(
|
|
58
|
+
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
59
|
+
).join(" ");
|
|
60
|
+
client?.captureMessage(message, "error");
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return client;
|
|
65
|
+
}
|
|
66
|
+
function getIncidentClient() {
|
|
67
|
+
return (0, import_store.get)(incidentStore);
|
|
68
|
+
}
|
|
69
|
+
function captureError(error, context) {
|
|
70
|
+
const client2 = (0, import_store.get)(incidentStore);
|
|
71
|
+
if (client2) {
|
|
72
|
+
return client2.captureError(error, context);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function captureMessage(message, level, context) {
|
|
77
|
+
const client2 = (0, import_store.get)(incidentStore);
|
|
78
|
+
if (client2) {
|
|
79
|
+
return client2.captureMessage(message, level, context);
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
function addBreadcrumb(breadcrumb) {
|
|
84
|
+
const client2 = (0, import_store.get)(incidentStore);
|
|
85
|
+
if (client2) {
|
|
86
|
+
client2.addBreadcrumb(breadcrumb);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function setUser(user) {
|
|
90
|
+
const client2 = (0, import_store.get)(incidentStore);
|
|
91
|
+
if (client2) {
|
|
92
|
+
client2.setUser(user);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
IncidentClient,
|
|
98
|
+
addBreadcrumb,
|
|
99
|
+
captureError,
|
|
100
|
+
captureMessage,
|
|
101
|
+
getIncidentClient,
|
|
102
|
+
incidentStore,
|
|
103
|
+
initIncident,
|
|
104
|
+
setUser
|
|
105
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { writable, get } from "svelte/store";
|
|
3
|
+
import { IncidentClient } from "@watchupltd/core";
|
|
4
|
+
import { IncidentClient as IncidentClient2 } from "@watchupltd/core";
|
|
5
|
+
var client = null;
|
|
6
|
+
var incidentStore = writable(null);
|
|
7
|
+
function initIncident(config) {
|
|
8
|
+
if (client) {
|
|
9
|
+
return client;
|
|
10
|
+
}
|
|
11
|
+
client = new IncidentClient(config);
|
|
12
|
+
incidentStore.set(client);
|
|
13
|
+
if (typeof window !== "undefined") {
|
|
14
|
+
window.addEventListener("error", (event) => {
|
|
15
|
+
const error = event.error || new Error(event.message);
|
|
16
|
+
client?.captureError(error);
|
|
17
|
+
});
|
|
18
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
19
|
+
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
20
|
+
client?.captureError(error);
|
|
21
|
+
});
|
|
22
|
+
if (config.captureConsoleErrors) {
|
|
23
|
+
const originalError = console.error;
|
|
24
|
+
console.error = (...args) => {
|
|
25
|
+
originalError.apply(console, args);
|
|
26
|
+
const message = args.map(
|
|
27
|
+
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
28
|
+
).join(" ");
|
|
29
|
+
client?.captureMessage(message, "error");
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return client;
|
|
34
|
+
}
|
|
35
|
+
function getIncidentClient() {
|
|
36
|
+
return get(incidentStore);
|
|
37
|
+
}
|
|
38
|
+
function captureError(error, context) {
|
|
39
|
+
const client2 = get(incidentStore);
|
|
40
|
+
if (client2) {
|
|
41
|
+
return client2.captureError(error, context);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function captureMessage(message, level, context) {
|
|
46
|
+
const client2 = get(incidentStore);
|
|
47
|
+
if (client2) {
|
|
48
|
+
return client2.captureMessage(message, level, context);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function addBreadcrumb(breadcrumb) {
|
|
53
|
+
const client2 = get(incidentStore);
|
|
54
|
+
if (client2) {
|
|
55
|
+
client2.addBreadcrumb(breadcrumb);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function setUser(user) {
|
|
59
|
+
const client2 = get(incidentStore);
|
|
60
|
+
if (client2) {
|
|
61
|
+
client2.setUser(user);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
IncidentClient2 as IncidentClient,
|
|
66
|
+
addBreadcrumb,
|
|
67
|
+
captureError,
|
|
68
|
+
captureMessage,
|
|
69
|
+
getIncidentClient,
|
|
70
|
+
incidentStore,
|
|
71
|
+
initIncident,
|
|
72
|
+
setUser
|
|
73
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watchupltd/svelte",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
7
11
|
"exports": {
|
|
8
12
|
".": {
|
|
9
13
|
"import": "./dist/index.mjs",
|
|
@@ -12,11 +16,11 @@
|
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"scripts": {
|
|
15
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --external svelte",
|
|
16
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --external svelte --watch"
|
|
19
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --external svelte --external @watchupltd/core --no-splitting",
|
|
20
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --external svelte --external @watchupltd/core --no-splitting --watch"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@watchupltd/core": "
|
|
23
|
+
"@watchupltd/core": "^1.0.0"
|
|
20
24
|
},
|
|
21
25
|
"peerDependencies": {
|
|
22
26
|
"svelte": ">=3.0.0"
|
package/src/index.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { writable, get } from 'svelte/store';
|
|
2
|
-
import { IncidentClient } from '@watchupltd/core';
|
|
3
|
-
import type { IncidentConfig } from '@watchupltd/core';
|
|
4
|
-
|
|
5
|
-
let client: IncidentClient | null = null;
|
|
6
|
-
|
|
7
|
-
export const incidentStore = writable<IncidentClient | null>(null);
|
|
8
|
-
|
|
9
|
-
export interface SvelteIncidentConfig extends IncidentConfig {
|
|
10
|
-
captureConsoleErrors?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function initIncident(config: SvelteIncidentConfig): IncidentClient {
|
|
14
|
-
if (client) {
|
|
15
|
-
return client;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
client = new IncidentClient(config);
|
|
19
|
-
incidentStore.set(client);
|
|
20
|
-
|
|
21
|
-
if (typeof window !== 'undefined') {
|
|
22
|
-
window.addEventListener('error', (event) => {
|
|
23
|
-
const error = event.error || new Error(event.message);
|
|
24
|
-
client?.captureError(error);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
window.addEventListener('unhandledrejection', (event) => {
|
|
28
|
-
const error = event.reason instanceof Error
|
|
29
|
-
? event.reason
|
|
30
|
-
: new Error(String(event.reason));
|
|
31
|
-
client?.captureError(error);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (config.captureConsoleErrors) {
|
|
35
|
-
const originalError = console.error;
|
|
36
|
-
console.error = (...args: any[]) => {
|
|
37
|
-
originalError.apply(console, args);
|
|
38
|
-
const message = args.map(arg =>
|
|
39
|
-
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
|
|
40
|
-
).join(' ');
|
|
41
|
-
client?.captureMessage(message, 'error');
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return client;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function getIncidentClient(): IncidentClient | null {
|
|
50
|
-
return get(incidentStore);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function captureError(error: Error, context?: any) {
|
|
54
|
-
const client = get(incidentStore);
|
|
55
|
-
if (client) {
|
|
56
|
-
return client.captureError(error, context);
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function captureMessage(message: string, level?: any, context?: any) {
|
|
62
|
-
const client = get(incidentStore);
|
|
63
|
-
if (client) {
|
|
64
|
-
return client.captureMessage(message, level, context);
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function addBreadcrumb(breadcrumb: any) {
|
|
70
|
-
const client = get(incidentStore);
|
|
71
|
-
if (client) {
|
|
72
|
-
client.addBreadcrumb(breadcrumb);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function setUser(user: any) {
|
|
77
|
-
const client = get(incidentStore);
|
|
78
|
-
if (client) {
|
|
79
|
-
client.setUser(user);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { IncidentClient } from '@watchupltd/core';
|
|
84
|
-
export type { IncidentConfig, SeverityLevel, User, Breadcrumb } from '@watchupltd/core';
|