@xrayradar/react 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.
- package/dist/index.d.mts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +109 -0
- package/dist/index.mjs +81 -0
- package/package.json +35 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
import { BrowserClient } from '@xrayradar/browser';
|
|
3
|
+
export { BrowserClient, addBreadcrumb, captureException, captureMessage, getClient, init, resetGlobal, setContext, setExtra, setTag, setUser } from '@xrayradar/browser';
|
|
4
|
+
|
|
5
|
+
interface ErrorBoundaryProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
fallback?: ReactNode | ((error: Error, reset: () => void) => ReactNode);
|
|
8
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
9
|
+
}
|
|
10
|
+
interface ErrorBoundaryState {
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
14
|
+
constructor(props: ErrorBoundaryProps);
|
|
15
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
16
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
17
|
+
reset: () => void;
|
|
18
|
+
render(): ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface XrayRadarProviderProps {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
client?: BrowserClient | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Optional provider to expose the client via useXrayRadar().
|
|
27
|
+
* If client is not provided, useXrayRadar() returns getClient() (global).
|
|
28
|
+
*/
|
|
29
|
+
declare function XrayRadarProvider({ children, client }: XrayRadarProviderProps): ReactNode;
|
|
30
|
+
declare function useXrayRadar(): BrowserClient | null;
|
|
31
|
+
|
|
32
|
+
export { ErrorBoundary, type ErrorBoundaryProps, XrayRadarProvider, type XrayRadarProviderProps, useXrayRadar };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
import { BrowserClient } from '@xrayradar/browser';
|
|
3
|
+
export { BrowserClient, addBreadcrumb, captureException, captureMessage, getClient, init, resetGlobal, setContext, setExtra, setTag, setUser } from '@xrayradar/browser';
|
|
4
|
+
|
|
5
|
+
interface ErrorBoundaryProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
fallback?: ReactNode | ((error: Error, reset: () => void) => ReactNode);
|
|
8
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
9
|
+
}
|
|
10
|
+
interface ErrorBoundaryState {
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
14
|
+
constructor(props: ErrorBoundaryProps);
|
|
15
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
16
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
17
|
+
reset: () => void;
|
|
18
|
+
render(): ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface XrayRadarProviderProps {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
client?: BrowserClient | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Optional provider to expose the client via useXrayRadar().
|
|
27
|
+
* If client is not provided, useXrayRadar() returns getClient() (global).
|
|
28
|
+
*/
|
|
29
|
+
declare function XrayRadarProvider({ children, client }: XrayRadarProviderProps): ReactNode;
|
|
30
|
+
declare function useXrayRadar(): BrowserClient | null;
|
|
31
|
+
|
|
32
|
+
export { ErrorBoundary, type ErrorBoundaryProps, XrayRadarProvider, type XrayRadarProviderProps, useXrayRadar };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
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.tsx
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ErrorBoundary: () => ErrorBoundary,
|
|
24
|
+
XrayRadarProvider: () => XrayRadarProvider,
|
|
25
|
+
addBreadcrumb: () => import_browser3.addBreadcrumb,
|
|
26
|
+
captureException: () => import_browser3.captureException,
|
|
27
|
+
captureMessage: () => import_browser3.captureMessage,
|
|
28
|
+
getClient: () => import_browser3.getClient,
|
|
29
|
+
init: () => import_browser3.init,
|
|
30
|
+
resetGlobal: () => import_browser3.resetGlobal,
|
|
31
|
+
setContext: () => import_browser3.setContext,
|
|
32
|
+
setExtra: () => import_browser3.setExtra,
|
|
33
|
+
setTag: () => import_browser3.setTag,
|
|
34
|
+
setUser: () => import_browser3.setUser,
|
|
35
|
+
useXrayRadar: () => useXrayRadar
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/ErrorBoundary.tsx
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
var import_browser = require("@xrayradar/browser");
|
|
42
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
var ErrorBoundary = class extends import_react.Component {
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super(props);
|
|
46
|
+
this.reset = () => {
|
|
47
|
+
this.setState({ error: null });
|
|
48
|
+
};
|
|
49
|
+
this.state = { error: null };
|
|
50
|
+
}
|
|
51
|
+
static getDerivedStateFromError(error) {
|
|
52
|
+
return { error };
|
|
53
|
+
}
|
|
54
|
+
componentDidCatch(error, errorInfo) {
|
|
55
|
+
(0, import_browser.captureException)(error, { message: errorInfo.componentStack ?? void 0 });
|
|
56
|
+
this.props.onError?.(error, errorInfo);
|
|
57
|
+
}
|
|
58
|
+
render() {
|
|
59
|
+
const { error } = this.state;
|
|
60
|
+
if (error) {
|
|
61
|
+
const { fallback } = this.props;
|
|
62
|
+
if (typeof fallback === "function") {
|
|
63
|
+
return fallback(error, this.reset);
|
|
64
|
+
}
|
|
65
|
+
if (fallback !== void 0) {
|
|
66
|
+
return fallback;
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { role: "alert", style: { padding: 16, border: "1px solid #ccc" }, children: [
|
|
69
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Something went wrong" }),
|
|
70
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { style: { overflow: "auto" }, children: error.message }),
|
|
71
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: this.reset, children: "Try again" })
|
|
72
|
+
] });
|
|
73
|
+
}
|
|
74
|
+
return this.props.children;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/provider.tsx
|
|
79
|
+
var import_react2 = require("react");
|
|
80
|
+
var import_browser2 = require("@xrayradar/browser");
|
|
81
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
82
|
+
var XrayRadarContext = (0, import_react2.createContext)(null);
|
|
83
|
+
function XrayRadarProvider({ children, client }) {
|
|
84
|
+
const value = (0, import_react2.useMemo)(() => client ?? (0, import_browser2.getClient)(), [client]);
|
|
85
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(XrayRadarContext.Provider, { value, children });
|
|
86
|
+
}
|
|
87
|
+
function useXrayRadar() {
|
|
88
|
+
const context = (0, import_react2.useContext)(XrayRadarContext);
|
|
89
|
+
return context ?? (0, import_browser2.getClient)();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/index.tsx
|
|
93
|
+
var import_browser3 = require("@xrayradar/browser");
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
ErrorBoundary,
|
|
97
|
+
XrayRadarProvider,
|
|
98
|
+
addBreadcrumb,
|
|
99
|
+
captureException,
|
|
100
|
+
captureMessage,
|
|
101
|
+
getClient,
|
|
102
|
+
init,
|
|
103
|
+
resetGlobal,
|
|
104
|
+
setContext,
|
|
105
|
+
setExtra,
|
|
106
|
+
setTag,
|
|
107
|
+
setUser,
|
|
108
|
+
useXrayRadar
|
|
109
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/ErrorBoundary.tsx
|
|
2
|
+
import { Component } from "react";
|
|
3
|
+
import { captureException } from "@xrayradar/browser";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
var ErrorBoundary = class extends Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.reset = () => {
|
|
9
|
+
this.setState({ error: null });
|
|
10
|
+
};
|
|
11
|
+
this.state = { error: null };
|
|
12
|
+
}
|
|
13
|
+
static getDerivedStateFromError(error) {
|
|
14
|
+
return { error };
|
|
15
|
+
}
|
|
16
|
+
componentDidCatch(error, errorInfo) {
|
|
17
|
+
captureException(error, { message: errorInfo.componentStack ?? void 0 });
|
|
18
|
+
this.props.onError?.(error, errorInfo);
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
const { error } = this.state;
|
|
22
|
+
if (error) {
|
|
23
|
+
const { fallback } = this.props;
|
|
24
|
+
if (typeof fallback === "function") {
|
|
25
|
+
return fallback(error, this.reset);
|
|
26
|
+
}
|
|
27
|
+
if (fallback !== void 0) {
|
|
28
|
+
return fallback;
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ jsxs("div", { role: "alert", style: { padding: 16, border: "1px solid #ccc" }, children: [
|
|
31
|
+
/* @__PURE__ */ jsx("h3", { children: "Something went wrong" }),
|
|
32
|
+
/* @__PURE__ */ jsx("pre", { style: { overflow: "auto" }, children: error.message }),
|
|
33
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: this.reset, children: "Try again" })
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
return this.props.children;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/provider.tsx
|
|
41
|
+
import { createContext, useContext, useMemo } from "react";
|
|
42
|
+
import { getClient } from "@xrayradar/browser";
|
|
43
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
44
|
+
var XrayRadarContext = createContext(null);
|
|
45
|
+
function XrayRadarProvider({ children, client }) {
|
|
46
|
+
const value = useMemo(() => client ?? getClient(), [client]);
|
|
47
|
+
return /* @__PURE__ */ jsx2(XrayRadarContext.Provider, { value, children });
|
|
48
|
+
}
|
|
49
|
+
function useXrayRadar() {
|
|
50
|
+
const context = useContext(XrayRadarContext);
|
|
51
|
+
return context ?? getClient();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/index.tsx
|
|
55
|
+
import {
|
|
56
|
+
init,
|
|
57
|
+
getClient as getClient2,
|
|
58
|
+
resetGlobal,
|
|
59
|
+
captureException as captureException2,
|
|
60
|
+
captureMessage,
|
|
61
|
+
addBreadcrumb,
|
|
62
|
+
setUser,
|
|
63
|
+
setTag,
|
|
64
|
+
setExtra,
|
|
65
|
+
setContext
|
|
66
|
+
} from "@xrayradar/browser";
|
|
67
|
+
export {
|
|
68
|
+
ErrorBoundary,
|
|
69
|
+
XrayRadarProvider,
|
|
70
|
+
addBreadcrumb,
|
|
71
|
+
captureException2 as captureException,
|
|
72
|
+
captureMessage,
|
|
73
|
+
getClient2 as getClient,
|
|
74
|
+
init,
|
|
75
|
+
resetGlobal,
|
|
76
|
+
setContext,
|
|
77
|
+
setExtra,
|
|
78
|
+
setTag,
|
|
79
|
+
setUser,
|
|
80
|
+
useXrayRadar
|
|
81
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xrayradar/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "XrayRadar SDK for React – ErrorBoundary, hooks, provider",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.tsx --format cjs,esm --dts --clean",
|
|
18
|
+
"test": "vitest run --passWithNoTests",
|
|
19
|
+
"lint": "eslint src",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=17.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@xrayradar/browser": "*"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^18.2.0",
|
|
30
|
+
"react": "^18.2.0",
|
|
31
|
+
"tsup": "^8.0.0",
|
|
32
|
+
"typescript": "^5.3.3",
|
|
33
|
+
"vitest": "^4.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|