sitepong 0.0.1 → 0.0.5
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 +613 -61
- package/dist/index.d.mts +596 -3
- package/dist/index.d.ts +596 -3
- package/dist/index.js +4507 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4455 -10
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +409 -0
- package/dist/react/index.d.ts +409 -0
- package/dist/react/index.js +5922 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +5839 -0
- package/dist/react/index.mjs.map +1 -0
- package/package.json +66 -54
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import React, { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
import { TrackProperties, UserTraits, GroupTraits, DeviceSignals, WebVitals } from '../index.js';
|
|
3
|
+
export { CapturedError, CronCheckinOptions, CronHandle, DatabaseQueryEvent, DatabaseTrackerConfig, ErrorContext, FraudCheckResult, MetricOptions, PerformanceConfig, PerformanceSpan, PerformanceTransaction, ProfileData, ProfileFrame, ProfilerConfig, ReplayConfig, ReplayEvent, SitePongConfig, SitePongInitConfig, TraceContext, TracePropagator, VisitorIdResult, areFlagsReady, captureError, captureMessage, clearAnonymousId, createTraceContext, cronCheckin, cronStart, cronWrap, dbTrack, dbTrackSync, endSpan, endTransaction, extractTrace, flush, flushMetrics, flushProfiles, generateSpanId, generateTraceId, getAllFlags, getAnonymousId, getDbNPlusOnePatterns, getDbQueryCount, getDeviceSignals, getFlag, getFraudCheck, getLatestProfile, getProfiles, getReplaySessionId, getVariant, getVariantPayload, getVisitorId, getWebVitals, group, identify, init, isReplayRecording, metricDistribution, metricGauge, metricHistogram, metricIncrement, metricStartTimer, metricTime, profile, propagateTrace, refreshFlags, resetAnalytics, resetDbQueryCount, setAnonymousId, setContext, setTags, setUser, startProfileSpan, startReplay, startSpan, startTransaction, stopReplay, track, trackPageView, waitForFlags } from '../index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SitePong SDK Types
|
|
7
|
+
*/
|
|
8
|
+
interface SitePongConfig {
|
|
9
|
+
/** DSN in format: https://<public_key>@ingest.sitepong.com/<project_id> */
|
|
10
|
+
dsn?: string;
|
|
11
|
+
/** API key in format: sp_live_xxx or sp_test_xxx */
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** Environment name (e.g., 'production', 'staging', 'development') */
|
|
14
|
+
environment?: string;
|
|
15
|
+
/** Release/version string */
|
|
16
|
+
release?: string;
|
|
17
|
+
/** Enable debug logging */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/** Enable/disable the SDK entirely */
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
/** Sample rate for errors (0.0 to 1.0) */
|
|
22
|
+
sampleRate?: number;
|
|
23
|
+
/** Maximum number of breadcrumbs to keep */
|
|
24
|
+
maxBreadcrumbs?: number;
|
|
25
|
+
/** Hook to modify or filter events before sending */
|
|
26
|
+
beforeSend?: (event: ErrorEvent) => ErrorEvent | null;
|
|
27
|
+
/** Auto-capture configuration */
|
|
28
|
+
autoCapture?: {
|
|
29
|
+
errors?: boolean;
|
|
30
|
+
unhandledRejections?: boolean;
|
|
31
|
+
console?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/** Custom API endpoint (for self-hosted) */
|
|
34
|
+
apiEndpoint?: string;
|
|
35
|
+
}
|
|
36
|
+
interface User {
|
|
37
|
+
id?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
username?: string;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface Breadcrumb {
|
|
43
|
+
type: "default" | "http" | "navigation" | "ui" | "console" | "error";
|
|
44
|
+
category?: string;
|
|
45
|
+
message?: string;
|
|
46
|
+
level?: "fatal" | "error" | "warning" | "info" | "debug";
|
|
47
|
+
timestamp: number;
|
|
48
|
+
data?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface ErrorEvent {
|
|
51
|
+
event_id: string;
|
|
52
|
+
timestamp: string;
|
|
53
|
+
level: "fatal" | "error" | "warning" | "info" | "debug";
|
|
54
|
+
message: string;
|
|
55
|
+
exception?: {
|
|
56
|
+
type: string;
|
|
57
|
+
value: string;
|
|
58
|
+
stacktrace?: StackFrame[];
|
|
59
|
+
};
|
|
60
|
+
tags?: Record<string, string>;
|
|
61
|
+
extra?: Record<string, unknown>;
|
|
62
|
+
user?: User;
|
|
63
|
+
breadcrumbs?: Breadcrumb[];
|
|
64
|
+
context?: {
|
|
65
|
+
browser?: BrowserContext;
|
|
66
|
+
os?: OSContext;
|
|
67
|
+
device?: DeviceContext;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
};
|
|
70
|
+
environment?: string;
|
|
71
|
+
release?: string;
|
|
72
|
+
request?: {
|
|
73
|
+
url?: string;
|
|
74
|
+
method?: string;
|
|
75
|
+
headers?: Record<string, string>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface StackFrame {
|
|
79
|
+
filename?: string;
|
|
80
|
+
function?: string;
|
|
81
|
+
lineno?: number;
|
|
82
|
+
colno?: number;
|
|
83
|
+
in_app?: boolean;
|
|
84
|
+
context_line?: string;
|
|
85
|
+
pre_context?: string[];
|
|
86
|
+
post_context?: string[];
|
|
87
|
+
}
|
|
88
|
+
interface BrowserContext {
|
|
89
|
+
name?: string;
|
|
90
|
+
version?: string;
|
|
91
|
+
}
|
|
92
|
+
interface OSContext {
|
|
93
|
+
name?: string;
|
|
94
|
+
version?: string;
|
|
95
|
+
}
|
|
96
|
+
interface DeviceContext {
|
|
97
|
+
family?: string;
|
|
98
|
+
model?: string;
|
|
99
|
+
brand?: string;
|
|
100
|
+
}
|
|
101
|
+
type LogLevel = "fatal" | "error" | "warning" | "info" | "debug";
|
|
102
|
+
interface CaptureContext {
|
|
103
|
+
tags?: Record<string, string>;
|
|
104
|
+
extra?: Record<string, unknown>;
|
|
105
|
+
user?: User;
|
|
106
|
+
level?: LogLevel;
|
|
107
|
+
fingerprint?: string[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface SitePongContextValue {
|
|
111
|
+
isInitialized: boolean;
|
|
112
|
+
}
|
|
113
|
+
declare const SitePongContext: React.Context<SitePongContextValue>;
|
|
114
|
+
interface SitePongProviderProps {
|
|
115
|
+
/**
|
|
116
|
+
* DSN in format: https://<public_key>@ingest.sitepong.com/<project_id>
|
|
117
|
+
*/
|
|
118
|
+
dsn?: string;
|
|
119
|
+
/**
|
|
120
|
+
* API key in format: sp_live_xxx or sp_test_xxx
|
|
121
|
+
*/
|
|
122
|
+
apiKey?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Additional configuration options
|
|
125
|
+
*/
|
|
126
|
+
config?: Omit<SitePongConfig, "dsn" | "apiKey">;
|
|
127
|
+
/**
|
|
128
|
+
* Children to render
|
|
129
|
+
*/
|
|
130
|
+
children: React.ReactNode;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* SitePong Provider Component
|
|
134
|
+
*
|
|
135
|
+
* Initializes the SitePong SDK and provides context to child components.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* import { SitePongProvider } from '@sitepong/react';
|
|
140
|
+
*
|
|
141
|
+
* function App() {
|
|
142
|
+
* return (
|
|
143
|
+
* <SitePongProvider dsn={process.env.NEXT_PUBLIC_SITEPONG_DSN}>
|
|
144
|
+
* <MyApp />
|
|
145
|
+
* </SitePongProvider>
|
|
146
|
+
* );
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function SitePongProvider({ dsn, apiKey, config, children, }: SitePongProviderProps): React.ReactElement;
|
|
151
|
+
|
|
152
|
+
interface SitePongErrorBoundaryProps {
|
|
153
|
+
/**
|
|
154
|
+
* Fallback UI to render when an error occurs
|
|
155
|
+
*/
|
|
156
|
+
fallback?: ReactNode | ((error: Error, resetError: () => void) => ReactNode);
|
|
157
|
+
/**
|
|
158
|
+
* Callback when an error is caught
|
|
159
|
+
*/
|
|
160
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Callback before the error is sent to SitePong
|
|
163
|
+
*/
|
|
164
|
+
beforeCapture?: (error: Error) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Whether to show a dialog to the user (future feature)
|
|
167
|
+
*/
|
|
168
|
+
showDialog?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Children to render
|
|
171
|
+
*/
|
|
172
|
+
children: ReactNode;
|
|
173
|
+
}
|
|
174
|
+
interface ErrorBoundaryState {
|
|
175
|
+
hasError: boolean;
|
|
176
|
+
error: Error | null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* SitePong Error Boundary
|
|
180
|
+
*
|
|
181
|
+
* Catches React component errors and reports them to SitePong.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```tsx
|
|
185
|
+
* import { SitePongErrorBoundary } from '@sitepong/react';
|
|
186
|
+
*
|
|
187
|
+
* function App() {
|
|
188
|
+
* return (
|
|
189
|
+
* <SitePongErrorBoundary fallback={<ErrorPage />}>
|
|
190
|
+
* <MyApp />
|
|
191
|
+
* </SitePongErrorBoundary>
|
|
192
|
+
* );
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example With reset functionality
|
|
197
|
+
* ```tsx
|
|
198
|
+
* <SitePongErrorBoundary
|
|
199
|
+
* fallback={(error, resetError) => (
|
|
200
|
+
* <div>
|
|
201
|
+
* <p>Something went wrong: {error.message}</p>
|
|
202
|
+
* <button onClick={resetError}>Try again</button>
|
|
203
|
+
* </div>
|
|
204
|
+
* )}
|
|
205
|
+
* >
|
|
206
|
+
* <MyApp />
|
|
207
|
+
* </SitePongErrorBoundary>
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare class SitePongErrorBoundary extends Component<SitePongErrorBoundaryProps, ErrorBoundaryState> {
|
|
211
|
+
constructor(props: SitePongErrorBoundaryProps);
|
|
212
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
213
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
214
|
+
resetError: () => void;
|
|
215
|
+
render(): ReactNode;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Add a breadcrumb to the trail
|
|
220
|
+
*/
|
|
221
|
+
declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Hook to access all SitePong SDK methods
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```tsx
|
|
228
|
+
* function MyComponent() {
|
|
229
|
+
* const sitepong = useSitePong();
|
|
230
|
+
*
|
|
231
|
+
* useEffect(() => {
|
|
232
|
+
* sitepong.setUser({ id: 'user-123' });
|
|
233
|
+
* }, []);
|
|
234
|
+
*
|
|
235
|
+
* const handleError = () => {
|
|
236
|
+
* sitepong.captureMessage('Something happened', 'warning');
|
|
237
|
+
* };
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare function useSitePong(): {
|
|
242
|
+
isInitialized: boolean;
|
|
243
|
+
captureException: (error: Error | unknown, context?: CaptureContext) => string | null;
|
|
244
|
+
captureMessage: (message: string, level?: LogLevel, context?: CaptureContext) => string | null;
|
|
245
|
+
setUser: (user: User | null) => void;
|
|
246
|
+
clearUser: () => void;
|
|
247
|
+
setTag: (key: string, value: string) => void;
|
|
248
|
+
setTags: (tags: Record<string, string>) => void;
|
|
249
|
+
setContext: (name: string, context: Record<string, unknown>) => void;
|
|
250
|
+
addBreadcrumb: typeof addBreadcrumb;
|
|
251
|
+
getConfig: () => SitePongConfig | null;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Hook to capture errors with a stable callback
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```tsx
|
|
258
|
+
* function MyComponent() {
|
|
259
|
+
* const capture = useErrorCapture();
|
|
260
|
+
*
|
|
261
|
+
* const handleClick = async () => {
|
|
262
|
+
* try {
|
|
263
|
+
* await riskyOperation();
|
|
264
|
+
* } catch (error) {
|
|
265
|
+
* capture(error, { tags: { action: 'click' } });
|
|
266
|
+
* }
|
|
267
|
+
* };
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare function useErrorCapture(): (error: Error | unknown, context?: CaptureContext) => string | null;
|
|
272
|
+
/**
|
|
273
|
+
* Hook to capture exceptions (alias for useErrorCapture)
|
|
274
|
+
*/
|
|
275
|
+
declare function useCaptureException(): (error: Error | unknown, context?: CaptureContext) => string | null;
|
|
276
|
+
/**
|
|
277
|
+
* Hook to capture messages
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```tsx
|
|
281
|
+
* function MyComponent() {
|
|
282
|
+
* const capture = useCaptureMessage();
|
|
283
|
+
*
|
|
284
|
+
* useEffect(() => {
|
|
285
|
+
* capture('Component mounted', 'info');
|
|
286
|
+
* }, []);
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
declare function useCaptureMessage(): (message: string, level?: LogLevel, context?: CaptureContext) => string | null;
|
|
291
|
+
/**
|
|
292
|
+
* Hook to set the current user
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```tsx
|
|
296
|
+
* function useAuth() {
|
|
297
|
+
* const setUser = useSetUser();
|
|
298
|
+
*
|
|
299
|
+
* const login = (user) => {
|
|
300
|
+
* setUser({
|
|
301
|
+
* id: user.id,
|
|
302
|
+
* email: user.email,
|
|
303
|
+
* username: user.name,
|
|
304
|
+
* });
|
|
305
|
+
* };
|
|
306
|
+
* }
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
declare function useSetUser(): (user: User | null) => void;
|
|
310
|
+
/**
|
|
311
|
+
* Hook to add breadcrumbs
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```tsx
|
|
315
|
+
* function NavigationTracker() {
|
|
316
|
+
* const addBreadcrumb = useAddBreadcrumb();
|
|
317
|
+
*
|
|
318
|
+
* useEffect(() => {
|
|
319
|
+
* addBreadcrumb({
|
|
320
|
+
* type: 'navigation',
|
|
321
|
+
* category: 'route',
|
|
322
|
+
* message: 'Navigated to /dashboard',
|
|
323
|
+
* });
|
|
324
|
+
* }, []);
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
declare function useAddBreadcrumb(): (breadcrumb: Parameters<typeof addBreadcrumb>[0]) => void;
|
|
329
|
+
/**
|
|
330
|
+
* Hook to track custom events with a stable callback
|
|
331
|
+
*/
|
|
332
|
+
declare function useTrack(): (eventName: string, properties?: TrackProperties) => void;
|
|
333
|
+
/**
|
|
334
|
+
* Hook to track page views with a stable callback
|
|
335
|
+
*/
|
|
336
|
+
declare function useTrackPageView(): (url?: string, properties?: TrackProperties) => void;
|
|
337
|
+
/**
|
|
338
|
+
* Hook to identify users with a stable callback
|
|
339
|
+
*/
|
|
340
|
+
declare function useIdentify(): (userId: string, traits?: UserTraits) => void;
|
|
341
|
+
/**
|
|
342
|
+
* Hook to associate users with groups with a stable callback
|
|
343
|
+
*/
|
|
344
|
+
declare function useGroup(): (groupId: string, traits?: GroupTraits) => void;
|
|
345
|
+
/**
|
|
346
|
+
* Hook to get the visitor ID with loading/error state
|
|
347
|
+
*/
|
|
348
|
+
declare function useVisitorId(): {
|
|
349
|
+
visitorId: string | null;
|
|
350
|
+
loading: boolean;
|
|
351
|
+
error: Error | null;
|
|
352
|
+
refetch: () => Promise<void>;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Hook to perform a fraud check with loading/error state
|
|
356
|
+
*/
|
|
357
|
+
declare function useFraudCheck(): {
|
|
358
|
+
visitorId: string | null;
|
|
359
|
+
riskScore: number | null;
|
|
360
|
+
signals: DeviceSignals | null;
|
|
361
|
+
loading: boolean;
|
|
362
|
+
error: Error | null;
|
|
363
|
+
refetch: () => Promise<void>;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Hook to get a feature flag value with reactive updates
|
|
367
|
+
*/
|
|
368
|
+
declare function useFeatureFlag(key: string, defaultValue?: boolean): boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Hook to get a feature flag payload (the flag value and metadata)
|
|
371
|
+
*/
|
|
372
|
+
declare function useFeatureFlagPayload(key: string): {
|
|
373
|
+
enabled: boolean;
|
|
374
|
+
loading: boolean;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Hook for A/B experiments based on feature flags
|
|
378
|
+
* Returns the experiment variant (true/false) and loading state
|
|
379
|
+
*/
|
|
380
|
+
declare function useExperiment(experimentKey: string): {
|
|
381
|
+
variant: 'control' | 'test';
|
|
382
|
+
loading: boolean;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Hook to get all feature flags
|
|
386
|
+
*/
|
|
387
|
+
declare function useAllFlags(): Record<string, boolean>;
|
|
388
|
+
/**
|
|
389
|
+
* Hook to track component render performance as a transaction
|
|
390
|
+
*/
|
|
391
|
+
declare function usePerformanceTransaction(name: string): {
|
|
392
|
+
start: () => string;
|
|
393
|
+
end: (status?: "ok" | "error") => void;
|
|
394
|
+
transactionId: string | null;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Hook to get current Web Vitals
|
|
398
|
+
*/
|
|
399
|
+
declare function useWebVitals(): WebVitals;
|
|
400
|
+
/**
|
|
401
|
+
* Hook to control session replay recording
|
|
402
|
+
*/
|
|
403
|
+
declare function useReplay(): {
|
|
404
|
+
recording: boolean;
|
|
405
|
+
start: () => boolean;
|
|
406
|
+
stop: () => void;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export { DeviceSignals, GroupTraits, SitePongContext, SitePongErrorBoundary, type SitePongErrorBoundaryProps, SitePongProvider, type SitePongProviderProps, TrackProperties, UserTraits, WebVitals, useAddBreadcrumb, useAllFlags, useCaptureException, useCaptureMessage, useErrorCapture, useExperiment, useFeatureFlag, useFeatureFlagPayload, useFraudCheck, useGroup, useIdentify, usePerformanceTransaction, useReplay, useSetUser, useSitePong, useTrack, useTrackPageView, useVisitorId, useWebVitals };
|