@tracewayapp/react 0.2.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/README.md +89 -0
- package/dist/index.d.mts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +103 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @tracewayapp/react
|
|
2
|
+
|
|
3
|
+
React integration for Traceway. Provides a context provider, error boundary, and hook.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { TracewayProvider } from "@tracewayapp/react";
|
|
9
|
+
|
|
10
|
+
function App() {
|
|
11
|
+
return (
|
|
12
|
+
<TracewayProvider connectionString="your-token@https://your-server.com/api/report">
|
|
13
|
+
<MyApp />
|
|
14
|
+
</TracewayProvider>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Error Boundary
|
|
20
|
+
|
|
21
|
+
Catches React render errors and reports them to Traceway.
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { TracewayErrorBoundary } from "@tracewayapp/react";
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<TracewayErrorBoundary
|
|
29
|
+
fallback={<div>Something went wrong</div>}
|
|
30
|
+
onError={(error, errorInfo) => {
|
|
31
|
+
console.log("Caught:", error.message);
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<MyPage />
|
|
35
|
+
</TracewayErrorBoundary>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## useTraceway Hook
|
|
41
|
+
|
|
42
|
+
Access capture methods from any component inside the provider.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { useTraceway } from "@tracewayapp/react";
|
|
46
|
+
|
|
47
|
+
function MyComponent() {
|
|
48
|
+
const { captureException, captureMessage } = useTraceway();
|
|
49
|
+
|
|
50
|
+
function handleClick() {
|
|
51
|
+
try {
|
|
52
|
+
doSomething();
|
|
53
|
+
} catch (err) {
|
|
54
|
+
captureException(err as Error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return <button onClick={handleClick}>Do Something</button>;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
### TracewayProvider
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Description |
|
|
67
|
+
|------|------|-------------|
|
|
68
|
+
| `connectionString` | `string` | Traceway connection string (`token@url`) |
|
|
69
|
+
| `options` | `TracewayFrontendOptions` | Optional SDK configuration |
|
|
70
|
+
| `children` | `ReactNode` | Child components |
|
|
71
|
+
|
|
72
|
+
### TracewayErrorBoundary
|
|
73
|
+
|
|
74
|
+
| Prop | Type | Description |
|
|
75
|
+
|------|------|-------------|
|
|
76
|
+
| `children` | `ReactNode` | Child components to wrap |
|
|
77
|
+
| `fallback` | `ReactNode` | UI to render when an error is caught |
|
|
78
|
+
| `onError` | `(error, errorInfo) => void` | Optional callback on error |
|
|
79
|
+
|
|
80
|
+
### useTraceway()
|
|
81
|
+
|
|
82
|
+
Returns `{ captureException, captureExceptionWithAttributes, captureMessage }`.
|
|
83
|
+
|
|
84
|
+
Throws if used outside a `TracewayProvider`.
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- React >= 18
|
|
89
|
+
- `@tracewayapp/frontend` (installed automatically as dependency)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import * as traceway from '@tracewayapp/frontend';
|
|
4
|
+
import { TracewayFrontendOptions } from '@tracewayapp/frontend';
|
|
5
|
+
|
|
6
|
+
interface TracewayContextValue {
|
|
7
|
+
captureException: typeof traceway.captureException;
|
|
8
|
+
captureExceptionWithAttributes: typeof traceway.captureExceptionWithAttributes;
|
|
9
|
+
captureMessage: typeof traceway.captureMessage;
|
|
10
|
+
}
|
|
11
|
+
declare const TracewayContext: React.Context<TracewayContextValue | null>;
|
|
12
|
+
interface TracewayProviderProps {
|
|
13
|
+
connectionString: string;
|
|
14
|
+
options?: TracewayFrontendOptions;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
declare function TracewayProvider({ connectionString, options, children, }: TracewayProviderProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare function useTraceway(): TracewayContextValue;
|
|
20
|
+
|
|
21
|
+
interface TracewayErrorBoundaryProps {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
fallback: React.ReactNode;
|
|
24
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
25
|
+
}
|
|
26
|
+
interface TracewayErrorBoundaryState {
|
|
27
|
+
hasError: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare class TracewayErrorBoundary extends Component<TracewayErrorBoundaryProps, TracewayErrorBoundaryState> {
|
|
30
|
+
constructor(props: TracewayErrorBoundaryProps);
|
|
31
|
+
static getDerivedStateFromError(): TracewayErrorBoundaryState;
|
|
32
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
|
33
|
+
render(): React.ReactNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { TracewayContext, type TracewayContextValue, TracewayErrorBoundary, type TracewayErrorBoundaryProps, TracewayProvider, type TracewayProviderProps, useTraceway };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import * as traceway from '@tracewayapp/frontend';
|
|
4
|
+
import { TracewayFrontendOptions } from '@tracewayapp/frontend';
|
|
5
|
+
|
|
6
|
+
interface TracewayContextValue {
|
|
7
|
+
captureException: typeof traceway.captureException;
|
|
8
|
+
captureExceptionWithAttributes: typeof traceway.captureExceptionWithAttributes;
|
|
9
|
+
captureMessage: typeof traceway.captureMessage;
|
|
10
|
+
}
|
|
11
|
+
declare const TracewayContext: React.Context<TracewayContextValue | null>;
|
|
12
|
+
interface TracewayProviderProps {
|
|
13
|
+
connectionString: string;
|
|
14
|
+
options?: TracewayFrontendOptions;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
declare function TracewayProvider({ connectionString, options, children, }: TracewayProviderProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
|
|
19
|
+
declare function useTraceway(): TracewayContextValue;
|
|
20
|
+
|
|
21
|
+
interface TracewayErrorBoundaryProps {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
fallback: React.ReactNode;
|
|
24
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
25
|
+
}
|
|
26
|
+
interface TracewayErrorBoundaryState {
|
|
27
|
+
hasError: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare class TracewayErrorBoundary extends Component<TracewayErrorBoundaryProps, TracewayErrorBoundaryState> {
|
|
30
|
+
constructor(props: TracewayErrorBoundaryProps);
|
|
31
|
+
static getDerivedStateFromError(): TracewayErrorBoundaryState;
|
|
32
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
|
33
|
+
render(): React.ReactNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { TracewayContext, type TracewayContextValue, TracewayErrorBoundary, type TracewayErrorBoundaryProps, TracewayProvider, type TracewayProviderProps, useTraceway };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
TracewayContext: () => TracewayContext,
|
|
34
|
+
TracewayErrorBoundary: () => TracewayErrorBoundary,
|
|
35
|
+
TracewayProvider: () => TracewayProvider,
|
|
36
|
+
useTraceway: () => useTraceway
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/provider.tsx
|
|
41
|
+
var import_react = require("react");
|
|
42
|
+
var traceway = __toESM(require("@tracewayapp/frontend"));
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
var TracewayContext = (0, import_react.createContext)(null);
|
|
45
|
+
function TracewayProvider({
|
|
46
|
+
connectionString,
|
|
47
|
+
options,
|
|
48
|
+
children
|
|
49
|
+
}) {
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
traceway.init(connectionString, options);
|
|
52
|
+
}, [connectionString]);
|
|
53
|
+
const value = (0, import_react.useMemo)(
|
|
54
|
+
() => ({
|
|
55
|
+
captureException: traceway.captureException,
|
|
56
|
+
captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,
|
|
57
|
+
captureMessage: traceway.captureMessage
|
|
58
|
+
}),
|
|
59
|
+
[]
|
|
60
|
+
);
|
|
61
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TracewayContext.Provider, { value, children });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/use-traceway.ts
|
|
65
|
+
var import_react2 = require("react");
|
|
66
|
+
function useTraceway() {
|
|
67
|
+
const context = (0, import_react2.useContext)(TracewayContext);
|
|
68
|
+
if (context === null) {
|
|
69
|
+
throw new Error("useTraceway must be used within a TracewayProvider");
|
|
70
|
+
}
|
|
71
|
+
return context;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/error-boundary.tsx
|
|
75
|
+
var import_react3 = require("react");
|
|
76
|
+
var traceway2 = __toESM(require("@tracewayapp/frontend"));
|
|
77
|
+
var TracewayErrorBoundary = class extends import_react3.Component {
|
|
78
|
+
constructor(props) {
|
|
79
|
+
super(props);
|
|
80
|
+
this.state = { hasError: false };
|
|
81
|
+
}
|
|
82
|
+
static getDerivedStateFromError() {
|
|
83
|
+
return { hasError: true };
|
|
84
|
+
}
|
|
85
|
+
componentDidCatch(error, errorInfo) {
|
|
86
|
+
traceway2.captureException(error);
|
|
87
|
+
this.props.onError?.(error, errorInfo);
|
|
88
|
+
}
|
|
89
|
+
render() {
|
|
90
|
+
if (this.state.hasError) {
|
|
91
|
+
return this.props.fallback;
|
|
92
|
+
}
|
|
93
|
+
return this.props.children;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
TracewayContext,
|
|
99
|
+
TracewayErrorBoundary,
|
|
100
|
+
TracewayProvider,
|
|
101
|
+
useTraceway
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/use-traceway.ts","../src/error-boundary.tsx"],"sourcesContent":["export { TracewayProvider, TracewayContext } from \"./provider.js\";\nexport type {\n TracewayProviderProps,\n TracewayContextValue,\n} from \"./provider.js\";\nexport { useTraceway } from \"./use-traceway.js\";\nexport {\n TracewayErrorBoundary,\n} from \"./error-boundary.js\";\nexport type { TracewayErrorBoundaryProps } from \"./error-boundary.js\";\n","import React, { createContext, useEffect, useMemo } from \"react\";\nimport * as traceway from \"@tracewayapp/frontend\";\nimport type { TracewayFrontendOptions } from \"@tracewayapp/frontend\";\n\nexport interface TracewayContextValue {\n captureException: typeof traceway.captureException;\n captureExceptionWithAttributes: typeof traceway.captureExceptionWithAttributes;\n captureMessage: typeof traceway.captureMessage;\n}\n\nexport const TracewayContext = createContext<TracewayContextValue | null>(null);\n\nexport interface TracewayProviderProps {\n connectionString: string;\n options?: TracewayFrontendOptions;\n children: React.ReactNode;\n}\n\nexport function TracewayProvider({\n connectionString,\n options,\n children,\n}: TracewayProviderProps) {\n useEffect(() => {\n traceway.init(connectionString, options);\n }, [connectionString]);\n\n const value = useMemo<TracewayContextValue>(\n () => ({\n captureException: traceway.captureException,\n captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,\n captureMessage: traceway.captureMessage,\n }),\n [],\n );\n\n return (\n <TracewayContext.Provider value={value}>{children}</TracewayContext.Provider>\n );\n}\n","import { useContext } from \"react\";\nimport { TracewayContext } from \"./provider.js\";\nimport type { TracewayContextValue } from \"./provider.js\";\n\nexport function useTraceway(): TracewayContextValue {\n const context = useContext(TracewayContext);\n if (context === null) {\n throw new Error(\"useTraceway must be used within a TracewayProvider\");\n }\n return context;\n}\n","import React, { Component } from \"react\";\nimport * as traceway from \"@tracewayapp/frontend\";\n\nexport interface TracewayErrorBoundaryProps {\n children: React.ReactNode;\n fallback: React.ReactNode;\n onError?: (error: Error, errorInfo: React.ErrorInfo) => void;\n}\n\ninterface TracewayErrorBoundaryState {\n hasError: boolean;\n}\n\nexport class TracewayErrorBoundary extends Component<\n TracewayErrorBoundaryProps,\n TracewayErrorBoundaryState\n> {\n constructor(props: TracewayErrorBoundaryProps) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(): TracewayErrorBoundaryState {\n return { hasError: true };\n }\n\n componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {\n traceway.captureException(error);\n this.props.onError?.(error, errorInfo);\n }\n\n render() {\n if (this.state.hasError) {\n return this.props.fallback;\n }\n return this.props.children;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyD;AACzD,eAA0B;AAoCtB;AA3BG,IAAM,sBAAkB,4BAA2C,IAAI;AAQvE,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,8BAAU,MAAM;AACd,IAAS,cAAK,kBAAkB,OAAO;AAAA,EACzC,GAAG,CAAC,gBAAgB,CAAC;AAErB,QAAM,YAAQ;AAAA,IACZ,OAAO;AAAA,MACL,kBAA2B;AAAA,MAC3B,gCAAyC;AAAA,MACzC,gBAAyB;AAAA,IAC3B;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,gBAAgB,UAAhB,EAAyB,OAAe,UAAS;AAEtD;;;ACvCA,IAAAA,gBAA2B;AAIpB,SAAS,cAAoC;AAClD,QAAM,cAAU,0BAAW,eAAe;AAC1C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;;;ACVA,IAAAC,gBAAiC;AACjC,IAAAC,YAA0B;AAYnB,IAAM,wBAAN,cAAoC,wBAGzC;AAAA,EACA,YAAY,OAAmC;AAC7C,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,UAAU,MAAM;AAAA,EACjC;AAAA,EAEA,OAAO,2BAAuD;AAC5D,WAAO,EAAE,UAAU,KAAK;AAAA,EAC1B;AAAA,EAEA,kBAAkB,OAAc,WAAkC;AAChE,IAAS,2BAAiB,KAAK;AAC/B,SAAK,MAAM,UAAU,OAAO,SAAS;AAAA,EACvC;AAAA,EAEA,SAAS;AACP,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO,KAAK,MAAM;AAAA,IACpB;AACA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;","names":["import_react","import_react","traceway"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/provider.tsx
|
|
2
|
+
import { createContext, useEffect, useMemo } from "react";
|
|
3
|
+
import * as traceway from "@tracewayapp/frontend";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var TracewayContext = createContext(null);
|
|
6
|
+
function TracewayProvider({
|
|
7
|
+
connectionString,
|
|
8
|
+
options,
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
traceway.init(connectionString, options);
|
|
13
|
+
}, [connectionString]);
|
|
14
|
+
const value = useMemo(
|
|
15
|
+
() => ({
|
|
16
|
+
captureException: traceway.captureException,
|
|
17
|
+
captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,
|
|
18
|
+
captureMessage: traceway.captureMessage
|
|
19
|
+
}),
|
|
20
|
+
[]
|
|
21
|
+
);
|
|
22
|
+
return /* @__PURE__ */ jsx(TracewayContext.Provider, { value, children });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/use-traceway.ts
|
|
26
|
+
import { useContext } from "react";
|
|
27
|
+
function useTraceway() {
|
|
28
|
+
const context = useContext(TracewayContext);
|
|
29
|
+
if (context === null) {
|
|
30
|
+
throw new Error("useTraceway must be used within a TracewayProvider");
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/error-boundary.tsx
|
|
36
|
+
import { Component } from "react";
|
|
37
|
+
import * as traceway2 from "@tracewayapp/frontend";
|
|
38
|
+
var TracewayErrorBoundary = class extends Component {
|
|
39
|
+
constructor(props) {
|
|
40
|
+
super(props);
|
|
41
|
+
this.state = { hasError: false };
|
|
42
|
+
}
|
|
43
|
+
static getDerivedStateFromError() {
|
|
44
|
+
return { hasError: true };
|
|
45
|
+
}
|
|
46
|
+
componentDidCatch(error, errorInfo) {
|
|
47
|
+
traceway2.captureException(error);
|
|
48
|
+
this.props.onError?.(error, errorInfo);
|
|
49
|
+
}
|
|
50
|
+
render() {
|
|
51
|
+
if (this.state.hasError) {
|
|
52
|
+
return this.props.fallback;
|
|
53
|
+
}
|
|
54
|
+
return this.props.children;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
TracewayContext,
|
|
59
|
+
TracewayErrorBoundary,
|
|
60
|
+
TracewayProvider,
|
|
61
|
+
useTraceway
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.tsx","../src/use-traceway.ts","../src/error-boundary.tsx"],"sourcesContent":["import React, { createContext, useEffect, useMemo } from \"react\";\nimport * as traceway from \"@tracewayapp/frontend\";\nimport type { TracewayFrontendOptions } from \"@tracewayapp/frontend\";\n\nexport interface TracewayContextValue {\n captureException: typeof traceway.captureException;\n captureExceptionWithAttributes: typeof traceway.captureExceptionWithAttributes;\n captureMessage: typeof traceway.captureMessage;\n}\n\nexport const TracewayContext = createContext<TracewayContextValue | null>(null);\n\nexport interface TracewayProviderProps {\n connectionString: string;\n options?: TracewayFrontendOptions;\n children: React.ReactNode;\n}\n\nexport function TracewayProvider({\n connectionString,\n options,\n children,\n}: TracewayProviderProps) {\n useEffect(() => {\n traceway.init(connectionString, options);\n }, [connectionString]);\n\n const value = useMemo<TracewayContextValue>(\n () => ({\n captureException: traceway.captureException,\n captureExceptionWithAttributes: traceway.captureExceptionWithAttributes,\n captureMessage: traceway.captureMessage,\n }),\n [],\n );\n\n return (\n <TracewayContext.Provider value={value}>{children}</TracewayContext.Provider>\n );\n}\n","import { useContext } from \"react\";\nimport { TracewayContext } from \"./provider.js\";\nimport type { TracewayContextValue } from \"./provider.js\";\n\nexport function useTraceway(): TracewayContextValue {\n const context = useContext(TracewayContext);\n if (context === null) {\n throw new Error(\"useTraceway must be used within a TracewayProvider\");\n }\n return context;\n}\n","import React, { Component } from \"react\";\nimport * as traceway from \"@tracewayapp/frontend\";\n\nexport interface TracewayErrorBoundaryProps {\n children: React.ReactNode;\n fallback: React.ReactNode;\n onError?: (error: Error, errorInfo: React.ErrorInfo) => void;\n}\n\ninterface TracewayErrorBoundaryState {\n hasError: boolean;\n}\n\nexport class TracewayErrorBoundary extends Component<\n TracewayErrorBoundaryProps,\n TracewayErrorBoundaryState\n> {\n constructor(props: TracewayErrorBoundaryProps) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(): TracewayErrorBoundaryState {\n return { hasError: true };\n }\n\n componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {\n traceway.captureException(error);\n this.props.onError?.(error, errorInfo);\n }\n\n render() {\n if (this.state.hasError) {\n return this.props.fallback;\n }\n return this.props.children;\n }\n}\n"],"mappings":";AAAA,SAAgB,eAAe,WAAW,eAAe;AACzD,YAAY,cAAc;AAoCtB;AA3BG,IAAM,kBAAkB,cAA2C,IAAI;AAQvE,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,YAAU,MAAM;AACd,IAAS,cAAK,kBAAkB,OAAO;AAAA,EACzC,GAAG,CAAC,gBAAgB,CAAC;AAErB,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL,kBAA2B;AAAA,MAC3B,gCAAyC;AAAA,MACzC,gBAAyB;AAAA,IAC3B;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SACE,oBAAC,gBAAgB,UAAhB,EAAyB,OAAe,UAAS;AAEtD;;;ACvCA,SAAS,kBAAkB;AAIpB,SAAS,cAAoC;AAClD,QAAM,UAAU,WAAW,eAAe;AAC1C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;;;ACVA,SAAgB,iBAAiB;AACjC,YAAYA,eAAc;AAYnB,IAAM,wBAAN,cAAoC,UAGzC;AAAA,EACA,YAAY,OAAmC;AAC7C,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,UAAU,MAAM;AAAA,EACjC;AAAA,EAEA,OAAO,2BAAuD;AAC5D,WAAO,EAAE,UAAU,KAAK;AAAA,EAC1B;AAAA,EAEA,kBAAkB,OAAc,WAAkC;AAChE,IAAS,2BAAiB,KAAK;AAC/B,SAAK,MAAM,UAAU,OAAO,SAAS;AAAA,EACvC;AAAA,EAEA,SAAS;AACP,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO,KAAK,MAAM;AAAA,IACpB;AACA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;","names":["traceway"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tracewayapp/react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Traceway React integration with ErrorBoundary and hooks",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@tracewayapp/frontend": "0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=18.0.0",
|
|
30
|
+
"react-dom": ">=18.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|