@koderlabs/tasks-sdk-rn 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.
@@ -0,0 +1,174 @@
1
+ import { InitOptions, Client } from '@koderlabs/tasks-sdk';
2
+
3
+ interface RnInitOptions extends InitOptions {
4
+ /**
5
+ * Capture global uncaught JS errors via ErrorUtils.setGlobalHandler.
6
+ * Default: true.
7
+ */
8
+ captureGlobalErrors?: boolean;
9
+ /**
10
+ * Capture unhandled promise rejections.
11
+ * Default: true. Uses HermesInternal where available, falls back to
12
+ * process.on('unhandledRejection') for legacy JSC.
13
+ */
14
+ captureUnhandledRejections?: boolean;
15
+ /**
16
+ * Capture console.error / console.warn as breadcrumbs.
17
+ * Default: true.
18
+ */
19
+ captureConsole?: boolean;
20
+ /**
21
+ * Capture fetch() request/response metadata as breadcrumbs.
22
+ * Default: true. Bodies are never captured (PII risk).
23
+ */
24
+ captureNetwork?: boolean;
25
+ /** Allowlist regex — only record breadcrumbs for matching URLs. */
26
+ networkIncludeUrls?: RegExp[];
27
+ /** Denylist regex — skip URLs (ingest endpoint is always skipped). */
28
+ networkExcludeUrls?: RegExp[];
29
+ /** Tag requests above this duration as `slow:true`. Default 2000ms. */
30
+ networkSlowThresholdMs?: number;
31
+ /**
32
+ * Include URL query string in network breadcrumbs. Default false — query
33
+ * strings often contain tokens / emails / IDs that you don't want shipped.
34
+ * Set to true only if you've already stripped sensitive params upstream.
35
+ */
36
+ networkIncludeQueryString?: boolean;
37
+ /**
38
+ * Capture AppState foreground/background transitions as breadcrumbs.
39
+ * Default: true.
40
+ */
41
+ captureAppState?: boolean;
42
+ /**
43
+ * Recover native crash JSON written by the Expo config plugin's
44
+ * uncaught-exception handler on the previous launch. Default: true.
45
+ * No-op when `expo-file-system` isn't installed.
46
+ */
47
+ captureNativeCrash?: boolean;
48
+ /**
49
+ * Max breadcrumbs to retain in ring buffer.
50
+ * Default: 50.
51
+ */
52
+ maxBreadcrumbs?: number;
53
+ /**
54
+ * Surface native-crash recovery errors (file IO, parse, native module load).
55
+ * Without this, a failed crash decode is indistinguishable from "no crash" —
56
+ * operators rely on this to detect silent capture regressions.
57
+ */
58
+ onNativeCrashError?: (err: {
59
+ stage: string;
60
+ message: string;
61
+ cause?: unknown;
62
+ }) => void;
63
+ /**
64
+ * Override the platform/release info auto-detected from react-native.
65
+ * Useful in tests where react-native is not loaded.
66
+ */
67
+ platformOverride?: {
68
+ os?: string;
69
+ osVersion?: string;
70
+ deviceModel?: string;
71
+ bundleId?: string;
72
+ };
73
+ }
74
+ interface Breadcrumb {
75
+ ts: string;
76
+ category: 'navigation' | 'http' | 'console' | 'user' | 'custom';
77
+ message: string;
78
+ level?: 'info' | 'warning' | 'error';
79
+ data?: Record<string, unknown>;
80
+ }
81
+
82
+ declare class BreadcrumbBuffer {
83
+ private max;
84
+ private buf;
85
+ constructor(max?: number);
86
+ add(b: Breadcrumb): void;
87
+ drain(): Breadcrumb[];
88
+ clear(): void;
89
+ }
90
+
91
+ /**
92
+ * Navigation breadcrumb helpers. Router-agnostic.
93
+ *
94
+ * Two integration styles are supported:
95
+ *
96
+ * 1. Manual — the app pushes a breadcrumb on every screen change by calling
97
+ * `recordNavigation(from, to, params?)`. Works with any navigator (React
98
+ * Navigation, Expo Router, custom).
99
+ *
100
+ * 2. Helper-attached — the app passes a navigation listener / state observer
101
+ * into `attachReactNavigation()` or `attachExpoRouter()` which wires the
102
+ * internal callbacks. These are thin wrappers — they only call
103
+ * `recordNavigation` — but keep the integration surface obvious for
104
+ * copy-paste setup code.
105
+ *
106
+ * Navigation breadcrumbs use category 'navigation' so triagers can filter
107
+ * them alongside AppState transitions and deep-link openings.
108
+ */
109
+
110
+ /**
111
+ * Record a manual navigation breadcrumb. Safe to call from any router.
112
+ * Empty `from` is allowed for the initial route.
113
+ */
114
+ declare function recordNavigation(buffer: BreadcrumbBuffer, to: string, opts?: {
115
+ from?: string;
116
+ params?: Record<string, unknown>;
117
+ }): void;
118
+ /**
119
+ * Attach to React Navigation 6/7 — pass the navigation container ref.
120
+ * Listens to 'state' and records the active route name on every change.
121
+ *
122
+ * Usage:
123
+ * const navRef = useNavigationContainerRef();
124
+ * useEffect(() => attachReactNavigation(client.buffer, navRef), [navRef]);
125
+ */
126
+ declare function attachReactNavigation(buffer: BreadcrumbBuffer, navRef: {
127
+ addListener: (event: 'state' | string, fn: () => void) => () => void;
128
+ getCurrentRoute?: () => {
129
+ name: string;
130
+ params?: Record<string, unknown>;
131
+ } | undefined;
132
+ }): () => void;
133
+ /**
134
+ * Attach to Expo Router. Expo Router doesn't surface a single listener
135
+ * channel — pass `usePathname()` output to `recordNavigation` from a
136
+ * top-level effect. This helper provides a callback the app calls each
137
+ * time its top-level `_layout.tsx` sees a path change.
138
+ *
139
+ * Usage:
140
+ * const pathname = usePathname();
141
+ * const reportPath = useExpoRouterReporter(client.buffer);
142
+ * useEffect(() => reportPath(pathname), [pathname]);
143
+ */
144
+ declare function useExpoRouterReporter(buffer: BreadcrumbBuffer): (pathname: string) => void;
145
+
146
+ interface RnClientHandle {
147
+ client: Client;
148
+ buffer: BreadcrumbBuffer;
149
+ /** Manually capture an error. */
150
+ captureException(err: unknown, ctx?: {
151
+ level?: 'fatal' | 'error' | 'warning';
152
+ }): void;
153
+ /** Add a manual breadcrumb. */
154
+ addBreadcrumb(b: {
155
+ category: 'navigation' | 'http' | 'console' | 'user' | 'custom';
156
+ message: string;
157
+ data?: Record<string, unknown>;
158
+ level?: 'info' | 'warning' | 'error';
159
+ }): void;
160
+ /** Record a navigation transition. */
161
+ recordNavigation(to: string, opts?: {
162
+ from?: string;
163
+ params?: Record<string, unknown>;
164
+ }): void;
165
+ /** Flush queued events / spans. Best-effort; resolves when done. */
166
+ flush(): Promise<void>;
167
+ /** Stop all auto-instrumentation. */
168
+ close(): Promise<void>;
169
+ }
170
+ declare function init(opts: RnInitOptions): RnClientHandle;
171
+ declare function getClient(): Client | null;
172
+ declare function getBuffer(): BreadcrumbBuffer | null;
173
+
174
+ export { type Breadcrumb, BreadcrumbBuffer, type RnClientHandle, type RnInitOptions, attachReactNavigation, getBuffer, getClient, init, recordNavigation, useExpoRouterReporter };
@@ -0,0 +1,174 @@
1
+ import { InitOptions, Client } from '@koderlabs/tasks-sdk';
2
+
3
+ interface RnInitOptions extends InitOptions {
4
+ /**
5
+ * Capture global uncaught JS errors via ErrorUtils.setGlobalHandler.
6
+ * Default: true.
7
+ */
8
+ captureGlobalErrors?: boolean;
9
+ /**
10
+ * Capture unhandled promise rejections.
11
+ * Default: true. Uses HermesInternal where available, falls back to
12
+ * process.on('unhandledRejection') for legacy JSC.
13
+ */
14
+ captureUnhandledRejections?: boolean;
15
+ /**
16
+ * Capture console.error / console.warn as breadcrumbs.
17
+ * Default: true.
18
+ */
19
+ captureConsole?: boolean;
20
+ /**
21
+ * Capture fetch() request/response metadata as breadcrumbs.
22
+ * Default: true. Bodies are never captured (PII risk).
23
+ */
24
+ captureNetwork?: boolean;
25
+ /** Allowlist regex — only record breadcrumbs for matching URLs. */
26
+ networkIncludeUrls?: RegExp[];
27
+ /** Denylist regex — skip URLs (ingest endpoint is always skipped). */
28
+ networkExcludeUrls?: RegExp[];
29
+ /** Tag requests above this duration as `slow:true`. Default 2000ms. */
30
+ networkSlowThresholdMs?: number;
31
+ /**
32
+ * Include URL query string in network breadcrumbs. Default false — query
33
+ * strings often contain tokens / emails / IDs that you don't want shipped.
34
+ * Set to true only if you've already stripped sensitive params upstream.
35
+ */
36
+ networkIncludeQueryString?: boolean;
37
+ /**
38
+ * Capture AppState foreground/background transitions as breadcrumbs.
39
+ * Default: true.
40
+ */
41
+ captureAppState?: boolean;
42
+ /**
43
+ * Recover native crash JSON written by the Expo config plugin's
44
+ * uncaught-exception handler on the previous launch. Default: true.
45
+ * No-op when `expo-file-system` isn't installed.
46
+ */
47
+ captureNativeCrash?: boolean;
48
+ /**
49
+ * Max breadcrumbs to retain in ring buffer.
50
+ * Default: 50.
51
+ */
52
+ maxBreadcrumbs?: number;
53
+ /**
54
+ * Surface native-crash recovery errors (file IO, parse, native module load).
55
+ * Without this, a failed crash decode is indistinguishable from "no crash" —
56
+ * operators rely on this to detect silent capture regressions.
57
+ */
58
+ onNativeCrashError?: (err: {
59
+ stage: string;
60
+ message: string;
61
+ cause?: unknown;
62
+ }) => void;
63
+ /**
64
+ * Override the platform/release info auto-detected from react-native.
65
+ * Useful in tests where react-native is not loaded.
66
+ */
67
+ platformOverride?: {
68
+ os?: string;
69
+ osVersion?: string;
70
+ deviceModel?: string;
71
+ bundleId?: string;
72
+ };
73
+ }
74
+ interface Breadcrumb {
75
+ ts: string;
76
+ category: 'navigation' | 'http' | 'console' | 'user' | 'custom';
77
+ message: string;
78
+ level?: 'info' | 'warning' | 'error';
79
+ data?: Record<string, unknown>;
80
+ }
81
+
82
+ declare class BreadcrumbBuffer {
83
+ private max;
84
+ private buf;
85
+ constructor(max?: number);
86
+ add(b: Breadcrumb): void;
87
+ drain(): Breadcrumb[];
88
+ clear(): void;
89
+ }
90
+
91
+ /**
92
+ * Navigation breadcrumb helpers. Router-agnostic.
93
+ *
94
+ * Two integration styles are supported:
95
+ *
96
+ * 1. Manual — the app pushes a breadcrumb on every screen change by calling
97
+ * `recordNavigation(from, to, params?)`. Works with any navigator (React
98
+ * Navigation, Expo Router, custom).
99
+ *
100
+ * 2. Helper-attached — the app passes a navigation listener / state observer
101
+ * into `attachReactNavigation()` or `attachExpoRouter()` which wires the
102
+ * internal callbacks. These are thin wrappers — they only call
103
+ * `recordNavigation` — but keep the integration surface obvious for
104
+ * copy-paste setup code.
105
+ *
106
+ * Navigation breadcrumbs use category 'navigation' so triagers can filter
107
+ * them alongside AppState transitions and deep-link openings.
108
+ */
109
+
110
+ /**
111
+ * Record a manual navigation breadcrumb. Safe to call from any router.
112
+ * Empty `from` is allowed for the initial route.
113
+ */
114
+ declare function recordNavigation(buffer: BreadcrumbBuffer, to: string, opts?: {
115
+ from?: string;
116
+ params?: Record<string, unknown>;
117
+ }): void;
118
+ /**
119
+ * Attach to React Navigation 6/7 — pass the navigation container ref.
120
+ * Listens to 'state' and records the active route name on every change.
121
+ *
122
+ * Usage:
123
+ * const navRef = useNavigationContainerRef();
124
+ * useEffect(() => attachReactNavigation(client.buffer, navRef), [navRef]);
125
+ */
126
+ declare function attachReactNavigation(buffer: BreadcrumbBuffer, navRef: {
127
+ addListener: (event: 'state' | string, fn: () => void) => () => void;
128
+ getCurrentRoute?: () => {
129
+ name: string;
130
+ params?: Record<string, unknown>;
131
+ } | undefined;
132
+ }): () => void;
133
+ /**
134
+ * Attach to Expo Router. Expo Router doesn't surface a single listener
135
+ * channel — pass `usePathname()` output to `recordNavigation` from a
136
+ * top-level effect. This helper provides a callback the app calls each
137
+ * time its top-level `_layout.tsx` sees a path change.
138
+ *
139
+ * Usage:
140
+ * const pathname = usePathname();
141
+ * const reportPath = useExpoRouterReporter(client.buffer);
142
+ * useEffect(() => reportPath(pathname), [pathname]);
143
+ */
144
+ declare function useExpoRouterReporter(buffer: BreadcrumbBuffer): (pathname: string) => void;
145
+
146
+ interface RnClientHandle {
147
+ client: Client;
148
+ buffer: BreadcrumbBuffer;
149
+ /** Manually capture an error. */
150
+ captureException(err: unknown, ctx?: {
151
+ level?: 'fatal' | 'error' | 'warning';
152
+ }): void;
153
+ /** Add a manual breadcrumb. */
154
+ addBreadcrumb(b: {
155
+ category: 'navigation' | 'http' | 'console' | 'user' | 'custom';
156
+ message: string;
157
+ data?: Record<string, unknown>;
158
+ level?: 'info' | 'warning' | 'error';
159
+ }): void;
160
+ /** Record a navigation transition. */
161
+ recordNavigation(to: string, opts?: {
162
+ from?: string;
163
+ params?: Record<string, unknown>;
164
+ }): void;
165
+ /** Flush queued events / spans. Best-effort; resolves when done. */
166
+ flush(): Promise<void>;
167
+ /** Stop all auto-instrumentation. */
168
+ close(): Promise<void>;
169
+ }
170
+ declare function init(opts: RnInitOptions): RnClientHandle;
171
+ declare function getClient(): Client | null;
172
+ declare function getBuffer(): BreadcrumbBuffer | null;
173
+
174
+ export { type Breadcrumb, BreadcrumbBuffer, type RnClientHandle, type RnInitOptions, attachReactNavigation, getBuffer, getClient, init, recordNavigation, useExpoRouterReporter };