@drakkar.software/sunglasses-react-native 0.8.0 → 0.10.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.
- package/dist/index.d.mts +42 -4
- package/dist/index.d.ts +42 -4
- package/dist/index.js +63 -2
- package/dist/index.mjs +50 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
|
-
import { ISunglassesClient, ScreenTrackingOptions } from '@drakkar.software/sunglasses-core';
|
|
3
|
-
export { ConsentStatus, ISunglassesClient, ScreenTrackingOptions, SunglassesConfig, SunglassesCore, SunglassesEvent } from '@drakkar.software/sunglasses-core';
|
|
2
|
+
import { ISunglassesClient, CaptureExceptionOptions, ScreenTrackingOptions } from '@drakkar.software/sunglasses-core';
|
|
3
|
+
export { CaptureExceptionOptions, ConsentStatus, ISunglassesClient, ScreenTrackingOptions, SunglassesConfig, SunglassesCore, SunglassesEvent, captureException } from '@drakkar.software/sunglasses-core';
|
|
4
4
|
|
|
5
5
|
interface SunglassesProviderProps {
|
|
6
6
|
/** An initialized ISunglassesClient (from SunglassesCore.create()). */
|
|
7
7
|
client: ISunglassesClient;
|
|
8
|
+
/**
|
|
9
|
+
* Automatically capture unhandled JS errors as `$error` events
|
|
10
|
+
* (`$error_handled: false`) via React Native's global `ErrorUtils` handler.
|
|
11
|
+
* Pass `true` for defaults, or an options object to configure truncation /
|
|
12
|
+
* stack inclusion. The previous global handler is preserved and still
|
|
13
|
+
* invoked. Default: off.
|
|
14
|
+
*/
|
|
15
|
+
autoCaptureErrors?: boolean | CaptureExceptionOptions;
|
|
8
16
|
children: React$1.ReactNode;
|
|
9
17
|
}
|
|
10
18
|
/**
|
|
@@ -42,7 +50,7 @@ interface SunglassesProviderProps {
|
|
|
42
50
|
* }
|
|
43
51
|
* ```
|
|
44
52
|
*/
|
|
45
|
-
declare function SunglassesProvider({ client, children, }: SunglassesProviderProps): React$1.ReactElement;
|
|
53
|
+
declare function SunglassesProvider({ client, autoCaptureErrors, children, }: SunglassesProviderProps): React$1.ReactElement;
|
|
46
54
|
|
|
47
55
|
/**
|
|
48
56
|
* Access the SunGlasses client from React context (React Native).
|
|
@@ -184,4 +192,34 @@ declare function useLinkingUtmCapture(client: ISunglassesClient): void;
|
|
|
184
192
|
*/
|
|
185
193
|
declare function useExpoRouterUtmCapture(client: ISunglassesClient): void;
|
|
186
194
|
|
|
187
|
-
|
|
195
|
+
interface SunglassesErrorBoundaryProps {
|
|
196
|
+
/**
|
|
197
|
+
* SunGlasses client. Optional — defaults to the client provided by the
|
|
198
|
+
* nearest `<SunglassesProvider>`.
|
|
199
|
+
*/
|
|
200
|
+
client?: ISunglassesClient;
|
|
201
|
+
/** Rendered when an error is caught. Defaults to rendering nothing. */
|
|
202
|
+
fallback?: React$1.ReactNode;
|
|
203
|
+
/** Error capture configuration forwarded to `captureException`. */
|
|
204
|
+
config?: CaptureExceptionOptions;
|
|
205
|
+
children: React$1.ReactNode;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* React Native error boundary that captures render-phase errors as SunGlasses
|
|
209
|
+
* `$error` events (`$error_handled: true`).
|
|
210
|
+
*
|
|
211
|
+
* The client is read from the nearest `<SunglassesProvider>` by default; pass
|
|
212
|
+
* an explicit `client` prop to override.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```tsx
|
|
216
|
+
* <SunglassesProvider client={client}>
|
|
217
|
+
* <SunglassesErrorBoundary fallback={<ErrorScreen />}>
|
|
218
|
+
* <App />
|
|
219
|
+
* </SunglassesErrorBoundary>
|
|
220
|
+
* </SunglassesProvider>
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function SunglassesErrorBoundary(props: SunglassesErrorBoundaryProps): React$1.ReactElement;
|
|
224
|
+
|
|
225
|
+
export { SunglassesErrorBoundary, type SunglassesErrorBoundaryProps, SunglassesProvider, type SunglassesProviderProps, captureDeepLinkUtmParams, useExpoRouterScreenTracking, useExpoRouterUtmCapture, useLinkingUtmCapture, useNavigationScreenTracking, useSunglasses };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
|
-
import { ISunglassesClient, ScreenTrackingOptions } from '@drakkar.software/sunglasses-core';
|
|
3
|
-
export { ConsentStatus, ISunglassesClient, ScreenTrackingOptions, SunglassesConfig, SunglassesCore, SunglassesEvent } from '@drakkar.software/sunglasses-core';
|
|
2
|
+
import { ISunglassesClient, CaptureExceptionOptions, ScreenTrackingOptions } from '@drakkar.software/sunglasses-core';
|
|
3
|
+
export { CaptureExceptionOptions, ConsentStatus, ISunglassesClient, ScreenTrackingOptions, SunglassesConfig, SunglassesCore, SunglassesEvent, captureException } from '@drakkar.software/sunglasses-core';
|
|
4
4
|
|
|
5
5
|
interface SunglassesProviderProps {
|
|
6
6
|
/** An initialized ISunglassesClient (from SunglassesCore.create()). */
|
|
7
7
|
client: ISunglassesClient;
|
|
8
|
+
/**
|
|
9
|
+
* Automatically capture unhandled JS errors as `$error` events
|
|
10
|
+
* (`$error_handled: false`) via React Native's global `ErrorUtils` handler.
|
|
11
|
+
* Pass `true` for defaults, or an options object to configure truncation /
|
|
12
|
+
* stack inclusion. The previous global handler is preserved and still
|
|
13
|
+
* invoked. Default: off.
|
|
14
|
+
*/
|
|
15
|
+
autoCaptureErrors?: boolean | CaptureExceptionOptions;
|
|
8
16
|
children: React$1.ReactNode;
|
|
9
17
|
}
|
|
10
18
|
/**
|
|
@@ -42,7 +50,7 @@ interface SunglassesProviderProps {
|
|
|
42
50
|
* }
|
|
43
51
|
* ```
|
|
44
52
|
*/
|
|
45
|
-
declare function SunglassesProvider({ client, children, }: SunglassesProviderProps): React$1.ReactElement;
|
|
53
|
+
declare function SunglassesProvider({ client, autoCaptureErrors, children, }: SunglassesProviderProps): React$1.ReactElement;
|
|
46
54
|
|
|
47
55
|
/**
|
|
48
56
|
* Access the SunGlasses client from React context (React Native).
|
|
@@ -184,4 +192,34 @@ declare function useLinkingUtmCapture(client: ISunglassesClient): void;
|
|
|
184
192
|
*/
|
|
185
193
|
declare function useExpoRouterUtmCapture(client: ISunglassesClient): void;
|
|
186
194
|
|
|
187
|
-
|
|
195
|
+
interface SunglassesErrorBoundaryProps {
|
|
196
|
+
/**
|
|
197
|
+
* SunGlasses client. Optional — defaults to the client provided by the
|
|
198
|
+
* nearest `<SunglassesProvider>`.
|
|
199
|
+
*/
|
|
200
|
+
client?: ISunglassesClient;
|
|
201
|
+
/** Rendered when an error is caught. Defaults to rendering nothing. */
|
|
202
|
+
fallback?: React$1.ReactNode;
|
|
203
|
+
/** Error capture configuration forwarded to `captureException`. */
|
|
204
|
+
config?: CaptureExceptionOptions;
|
|
205
|
+
children: React$1.ReactNode;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* React Native error boundary that captures render-phase errors as SunGlasses
|
|
209
|
+
* `$error` events (`$error_handled: true`).
|
|
210
|
+
*
|
|
211
|
+
* The client is read from the nearest `<SunglassesProvider>` by default; pass
|
|
212
|
+
* an explicit `client` prop to override.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```tsx
|
|
216
|
+
* <SunglassesProvider client={client}>
|
|
217
|
+
* <SunglassesErrorBoundary fallback={<ErrorScreen />}>
|
|
218
|
+
* <App />
|
|
219
|
+
* </SunglassesErrorBoundary>
|
|
220
|
+
* </SunglassesProvider>
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function SunglassesErrorBoundary(props: SunglassesErrorBoundaryProps): React$1.ReactElement;
|
|
224
|
+
|
|
225
|
+
export { SunglassesErrorBoundary, type SunglassesErrorBoundaryProps, SunglassesProvider, type SunglassesProviderProps, captureDeepLinkUtmParams, useExpoRouterScreenTracking, useExpoRouterUtmCapture, useLinkingUtmCapture, useNavigationScreenTracking, useSunglasses };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,14 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
23
|
-
SunglassesCore: () =>
|
|
33
|
+
SunglassesCore: () => import_sunglasses_core3.SunglassesCore,
|
|
34
|
+
SunglassesErrorBoundary: () => SunglassesErrorBoundary,
|
|
24
35
|
SunglassesProvider: () => SunglassesProvider,
|
|
25
36
|
captureDeepLinkUtmParams: () => captureDeepLinkUtmParams,
|
|
37
|
+
captureException: () => import_sunglasses_core3.captureException,
|
|
26
38
|
useExpoRouterScreenTracking: () => useExpoRouterScreenTracking,
|
|
27
39
|
useExpoRouterUtmCapture: () => useExpoRouterUtmCapture,
|
|
28
40
|
useLinkingUtmCapture: () => useLinkingUtmCapture,
|
|
@@ -34,6 +46,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
34
46
|
// src/SunglassesProvider.tsx
|
|
35
47
|
var import_react2 = require("react");
|
|
36
48
|
var import_react_native = require("react-native");
|
|
49
|
+
var import_sunglasses_core = require("@drakkar.software/sunglasses-core");
|
|
37
50
|
|
|
38
51
|
// src/context.ts
|
|
39
52
|
var import_react = require("react");
|
|
@@ -52,6 +65,7 @@ function useSunglasses() {
|
|
|
52
65
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
66
|
function SunglassesProvider({
|
|
54
67
|
client,
|
|
68
|
+
autoCaptureErrors,
|
|
55
69
|
children
|
|
56
70
|
}) {
|
|
57
71
|
(0, import_react2.useEffect)(() => {
|
|
@@ -60,6 +74,19 @@ function SunglassesProvider({
|
|
|
60
74
|
});
|
|
61
75
|
};
|
|
62
76
|
}, [client]);
|
|
77
|
+
(0, import_react2.useEffect)(() => {
|
|
78
|
+
if (!autoCaptureErrors) return;
|
|
79
|
+
if (typeof ErrorUtils === "undefined" || !ErrorUtils.setGlobalHandler) return;
|
|
80
|
+
const options = typeof autoCaptureErrors === "object" ? autoCaptureErrors : {};
|
|
81
|
+
const previous = ErrorUtils.getGlobalHandler?.();
|
|
82
|
+
ErrorUtils.setGlobalHandler((error, isFatal) => {
|
|
83
|
+
(0, import_sunglasses_core.captureException)(client, error, { handled: false, ...options });
|
|
84
|
+
previous?.(error, isFatal);
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
if (previous) ErrorUtils.setGlobalHandler?.(previous);
|
|
88
|
+
};
|
|
89
|
+
}, [client, autoCaptureErrors]);
|
|
63
90
|
(0, import_react2.useEffect)(() => {
|
|
64
91
|
const subscription = import_react_native.AppState.addEventListener("change", (nextState) => {
|
|
65
92
|
if (nextState === "background") {
|
|
@@ -198,13 +225,47 @@ function useExpoRouterUtmCapture(client) {
|
|
|
198
225
|
}, [params, client]);
|
|
199
226
|
}
|
|
200
227
|
|
|
228
|
+
// src/SunglassesErrorBoundary.tsx
|
|
229
|
+
var import_react7 = __toESM(require("react"));
|
|
230
|
+
var import_sunglasses_core2 = require("@drakkar.software/sunglasses-core");
|
|
231
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
232
|
+
var ErrorBoundaryInner = class extends import_react7.default.Component {
|
|
233
|
+
constructor() {
|
|
234
|
+
super(...arguments);
|
|
235
|
+
this.state = { hasError: false };
|
|
236
|
+
}
|
|
237
|
+
static getDerivedStateFromError() {
|
|
238
|
+
return { hasError: true };
|
|
239
|
+
}
|
|
240
|
+
componentDidCatch(error) {
|
|
241
|
+
const { client, config } = this.props;
|
|
242
|
+
(0, import_sunglasses_core2.captureException)(client, error, { handled: true, ...config });
|
|
243
|
+
}
|
|
244
|
+
render() {
|
|
245
|
+
if (this.state.hasError) return this.props.fallback ?? null;
|
|
246
|
+
return this.props.children;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
function SunglassesErrorBoundary(props) {
|
|
250
|
+
const contextClient = (0, import_react7.useContext)(SunglassesContext);
|
|
251
|
+
const client = props.client ?? contextClient;
|
|
252
|
+
if (client === null) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
"[SunGlasses] <SunglassesErrorBoundary> must be inside a <SunglassesProvider> or receive a `client` prop."
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorBoundaryInner, { ...props, client });
|
|
258
|
+
}
|
|
259
|
+
|
|
201
260
|
// src/index.ts
|
|
202
|
-
var
|
|
261
|
+
var import_sunglasses_core3 = require("@drakkar.software/sunglasses-core");
|
|
203
262
|
// Annotate the CommonJS export names for ESM import in node:
|
|
204
263
|
0 && (module.exports = {
|
|
205
264
|
SunglassesCore,
|
|
265
|
+
SunglassesErrorBoundary,
|
|
206
266
|
SunglassesProvider,
|
|
207
267
|
captureDeepLinkUtmParams,
|
|
268
|
+
captureException,
|
|
208
269
|
useExpoRouterScreenTracking,
|
|
209
270
|
useExpoRouterUtmCapture,
|
|
210
271
|
useLinkingUtmCapture,
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
// src/SunglassesProvider.tsx
|
|
9
9
|
import { useEffect } from "react";
|
|
10
10
|
import { AppState } from "react-native";
|
|
11
|
+
import { captureException } from "@drakkar.software/sunglasses-core";
|
|
11
12
|
|
|
12
13
|
// src/context.ts
|
|
13
14
|
import { createContext, useContext } from "react";
|
|
@@ -26,6 +27,7 @@ function useSunglasses() {
|
|
|
26
27
|
import { jsx } from "react/jsx-runtime";
|
|
27
28
|
function SunglassesProvider({
|
|
28
29
|
client,
|
|
30
|
+
autoCaptureErrors,
|
|
29
31
|
children
|
|
30
32
|
}) {
|
|
31
33
|
useEffect(() => {
|
|
@@ -34,6 +36,19 @@ function SunglassesProvider({
|
|
|
34
36
|
});
|
|
35
37
|
};
|
|
36
38
|
}, [client]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!autoCaptureErrors) return;
|
|
41
|
+
if (typeof ErrorUtils === "undefined" || !ErrorUtils.setGlobalHandler) return;
|
|
42
|
+
const options = typeof autoCaptureErrors === "object" ? autoCaptureErrors : {};
|
|
43
|
+
const previous = ErrorUtils.getGlobalHandler?.();
|
|
44
|
+
ErrorUtils.setGlobalHandler((error, isFatal) => {
|
|
45
|
+
captureException(client, error, { handled: false, ...options });
|
|
46
|
+
previous?.(error, isFatal);
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
if (previous) ErrorUtils.setGlobalHandler?.(previous);
|
|
50
|
+
};
|
|
51
|
+
}, [client, autoCaptureErrors]);
|
|
37
52
|
useEffect(() => {
|
|
38
53
|
const subscription = AppState.addEventListener("change", (nextState) => {
|
|
39
54
|
if (nextState === "background") {
|
|
@@ -172,12 +187,46 @@ function useExpoRouterUtmCapture(client) {
|
|
|
172
187
|
}, [params, client]);
|
|
173
188
|
}
|
|
174
189
|
|
|
190
|
+
// src/SunglassesErrorBoundary.tsx
|
|
191
|
+
import React2, { useContext as useContext2 } from "react";
|
|
192
|
+
import { captureException as captureException2 } from "@drakkar.software/sunglasses-core";
|
|
193
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
194
|
+
var ErrorBoundaryInner = class extends React2.Component {
|
|
195
|
+
constructor() {
|
|
196
|
+
super(...arguments);
|
|
197
|
+
this.state = { hasError: false };
|
|
198
|
+
}
|
|
199
|
+
static getDerivedStateFromError() {
|
|
200
|
+
return { hasError: true };
|
|
201
|
+
}
|
|
202
|
+
componentDidCatch(error) {
|
|
203
|
+
const { client, config } = this.props;
|
|
204
|
+
captureException2(client, error, { handled: true, ...config });
|
|
205
|
+
}
|
|
206
|
+
render() {
|
|
207
|
+
if (this.state.hasError) return this.props.fallback ?? null;
|
|
208
|
+
return this.props.children;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
function SunglassesErrorBoundary(props) {
|
|
212
|
+
const contextClient = useContext2(SunglassesContext);
|
|
213
|
+
const client = props.client ?? contextClient;
|
|
214
|
+
if (client === null) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
"[SunGlasses] <SunglassesErrorBoundary> must be inside a <SunglassesProvider> or receive a `client` prop."
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return /* @__PURE__ */ jsx2(ErrorBoundaryInner, { ...props, client });
|
|
220
|
+
}
|
|
221
|
+
|
|
175
222
|
// src/index.ts
|
|
176
|
-
import { SunglassesCore } from "@drakkar.software/sunglasses-core";
|
|
223
|
+
import { SunglassesCore, captureException as captureException3 } from "@drakkar.software/sunglasses-core";
|
|
177
224
|
export {
|
|
178
225
|
SunglassesCore,
|
|
226
|
+
SunglassesErrorBoundary,
|
|
179
227
|
SunglassesProvider,
|
|
180
228
|
captureDeepLinkUtmParams,
|
|
229
|
+
captureException3 as captureException,
|
|
181
230
|
useExpoRouterScreenTracking,
|
|
182
231
|
useExpoRouterUtmCapture,
|
|
183
232
|
useLinkingUtmCapture,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drakkar.software/sunglasses-react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "React Native / Expo provider and hooks for SunGlasses event tracking",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@drakkar.software/sunglasses-core": "0.
|
|
19
|
+
"@drakkar.software/sunglasses-core": "0.10.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"expo-router": ">=3.0.0",
|