@spectosh/browser 0.2.2 → 0.2.4

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.
@@ -0,0 +1,54 @@
1
+ // Types for @spectosh/browser/react.
2
+ import type { Component, ErrorInfo as ReactErrorInfo, ReactNode } from 'react'
3
+ import type { RecordingOptions, Traits, ErrorInfo, Recorder } from './index.js'
4
+
5
+ export interface SpectoUser extends Traits {
6
+ id: string | number
7
+ }
8
+
9
+ export interface SpectoProviderProps extends Omit<RecordingOptions, 'key'> {
10
+ /** The project's publishable key: `pk_…`, or `pk_…@host` for an EU-region or self-hosted project. */
11
+ apiKey: string
12
+ /** The signed-in user — identified whenever it changes. */
13
+ user?: SpectoUser | null
14
+ children?: ReactNode
15
+ }
16
+
17
+ /**
18
+ * Starts recording during its first render, before any child's effects run.
19
+ * Once per page (StrictMode, remounts and hot reloads reuse it); never stops
20
+ * on unmount; does nothing on the server.
21
+ */
22
+ export function SpectoProvider(props: SpectoProviderProps): ReactNode
23
+
24
+ export interface SpectoApi {
25
+ identify(id: string | number, traits?: Traits): void
26
+ track(name: string, props?: Record<string, unknown>): void
27
+ captureError(error: unknown, info?: ErrorInfo): void
28
+ sessionUrl(): string | null
29
+ stop(): void
30
+ grantConsent(): Recorder | null
31
+ revokeConsent(): void
32
+ optOut(): void
33
+ optIn(): void
34
+ }
35
+ export function useSpecto(): SpectoApi
36
+
37
+ export interface SpectoErrorBoundaryProps {
38
+ children?: ReactNode
39
+ /** Shown instead of the children after an error; or a render function. */
40
+ fallback?: ReactNode | ((args: { error: unknown; reset: () => void }) => ReactNode)
41
+ onError?: (error: unknown, info: ReactErrorInfo) => void
42
+ }
43
+ /** Reports what it catches — with the component stack — to Specto. */
44
+ export class SpectoErrorBoundary extends Component<SpectoErrorBoundaryProps, { error: unknown }> {}
45
+
46
+ /**
47
+ * React 19 root error hooks: `createRoot(el, { onCaughtError: spectoErrorHandler(), onUncaughtError: spectoErrorHandler() })`.
48
+ * Reports the error, then calls `next` — or logs it, as React does by default.
49
+ */
50
+ export function spectoErrorHandler(
51
+ next?: (error: unknown, errorInfo: { componentStack?: string | null }) => void,
52
+ ): (error: unknown, errorInfo: { componentStack?: string | null }) => void
53
+
54
+ export { captureError } from './index.js'