@flareapp/react 2.4.0 → 2.5.1

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.mjs CHANGED
@@ -1,198 +1,9 @@
1
- import { convertToError, flare } from "@flareapp/js";
2
- import * as React from "react";
3
- import { Component, version } from "react";
1
+ import { i as registerReactSdkIdentity, n as FlareErrorBoundary, r as registerDefaultFlare, t as flareReactErrorHandler } from "./flareReactErrorHandler-FqJ6hQZc.mjs";
2
+ import { flare } from "@flareapp/js";
4
3
 
5
- //#region src/constants.ts
6
- const CHROMIUM_STACK_REGEX = /^at\s+(\S+)(?:\s+\((.+):(\d+):(\d+)\))?$/;
7
- const FIREFOX_SAFARI_STACK_REGEX = /^(\S+?)@(.+):(\d+):(\d+)$/;
8
- const PACKAGE_VERSION = typeof process !== "undefined" && true ? "2.4.0" : "?";
9
-
10
- //#endregion
11
- //#region src/identify.ts
12
- let registered = false;
13
- function registerReactSdkIdentity() {
14
- if (registered) return;
15
- registered = true;
16
- flare.setSdkInfo({
17
- name: "@flareapp/react",
18
- version: PACKAGE_VERSION
19
- });
20
- flare.setFramework({
21
- name: "React",
22
- version: React.version
23
- });
24
- }
25
-
26
- //#endregion
27
- //#region src/formatComponentStack.ts
28
- function formatComponentStack(stack) {
29
- return stack.split(/\s*\n\s*/g).filter((line) => line.length > 0);
30
- }
31
-
32
- //#endregion
33
- //#region src/parseComponentStack.ts
34
- function parseComponentStack(stack) {
35
- return stack.split(/\s*\n\s*/g).filter((line) => line.length > 0).map((line) => {
36
- const chromeMatch = line.match(CHROMIUM_STACK_REGEX);
37
- if (chromeMatch) return {
38
- component: chromeMatch[1],
39
- file: chromeMatch[2] ?? null,
40
- line: chromeMatch[3] ? Number(chromeMatch[3]) : null,
41
- column: chromeMatch[4] ? Number(chromeMatch[4]) : null
42
- };
43
- const firefoxSafariMatch = line.match(FIREFOX_SAFARI_STACK_REGEX);
44
- if (firefoxSafariMatch) return {
45
- component: firefoxSafariMatch[1],
46
- file: firefoxSafariMatch[2],
47
- line: Number(firefoxSafariMatch[3]),
48
- column: Number(firefoxSafariMatch[4])
49
- };
50
- return {
51
- component: line.replace(/^at\s+/, ""),
52
- file: null,
53
- line: null,
54
- column: null
55
- };
56
- });
57
- }
58
-
59
- //#endregion
60
- //#region src/parseMinifiedReactError.ts
61
- const NUMBER_PATTERN = /Minified React error #(\d+)/;
62
- const ARG_PATTERN = /args\[\]=([^&\s]*)/g;
63
- const URL_PATTERN = /(https?:\/\/\S+)/;
64
- function safeDecode(value) {
65
- try {
66
- return decodeURIComponent(value);
67
- } catch {
68
- return value;
69
- }
70
- }
71
- function parseMinifiedReactError(error) {
72
- const message = error?.message;
73
- if (!message) return null;
74
- const numberMatch = message.match(NUMBER_PATTERN);
75
- if (!numberMatch) return null;
76
- const args = [];
77
- for (const match of message.matchAll(ARG_PATTERN)) args.push(safeDecode(match[1]));
78
- const urlMatch = message.match(URL_PATTERN);
79
- return {
80
- number: Number(numberMatch[1]),
81
- args,
82
- url: urlMatch ? urlMatch[1] : null
83
- };
84
- }
85
-
86
- //#endregion
87
- //#region src/buildReactContext.ts
88
- function buildReactContext(rawStack, error) {
89
- const minifiedError = parseMinifiedReactError(error);
90
- return { react: {
91
- componentStack: formatComponentStack(rawStack),
92
- componentStackFrames: parseComponentStack(rawStack),
93
- version,
94
- ...minifiedError ? { minifiedError } : {}
95
- } };
96
- }
97
-
98
- //#endregion
99
- //#region src/contextToAttributes.ts
100
- function contextToAttributes(context) {
101
- return { "context.custom": { react: {
102
- componentStack: context.react.componentStack,
103
- componentStackFrames: context.react.componentStackFrames,
104
- ...context.react.version ? { version: context.react.version } : {},
105
- ...context.react.minifiedError ? { minifiedError: context.react.minifiedError } : {}
106
- } } };
107
- }
108
-
109
- //#endregion
110
- //#region src/FlareErrorBoundary.ts
111
- var FlareErrorBoundary = class extends Component {
112
- state = {
113
- error: null,
114
- componentStack: []
115
- };
116
- static getDerivedStateFromError(error) {
117
- return { error };
118
- }
119
- componentDidCatch(error, errorInfo) {
120
- this.props.beforeEvaluate?.({
121
- error,
122
- errorInfo
123
- });
124
- const context = buildReactContext(errorInfo.componentStack ?? "", error);
125
- const finalContext = this.props.beforeSubmit?.({
126
- error,
127
- errorInfo,
128
- context
129
- }) ?? context;
130
- this.setState({ componentStack: finalContext.react.componentStack });
131
- flare.reportSilently(error, contextToAttributes(finalContext));
132
- this.props.afterSubmit?.({
133
- error,
134
- errorInfo,
135
- context: finalContext
136
- });
137
- }
138
- componentDidUpdate(prevProps) {
139
- if (this.state.error === null || !this.props.resetKeys) return;
140
- const prevKeys = prevProps.resetKeys;
141
- const nextKeys = this.props.resetKeys;
142
- const lengthChanged = prevKeys?.length !== nextKeys.length;
143
- const valuesChanged = nextKeys.some((key, i) => !Object.is(key, prevKeys?.[i]));
144
- if (lengthChanged || valuesChanged) this.reset();
145
- }
146
- reset = () => {
147
- const { error } = this.state;
148
- this.props.onReset?.(error);
149
- this.setState({
150
- error: null,
151
- componentStack: []
152
- });
153
- };
154
- render() {
155
- const { error } = this.state;
156
- if (error !== null) {
157
- const { fallback } = this.props;
158
- if (typeof fallback === "function") return fallback({
159
- error,
160
- componentStack: this.state.componentStack,
161
- resetErrorBoundary: this.reset
162
- });
163
- return fallback ?? null;
164
- }
165
- return this.props.children;
166
- }
167
- };
168
-
169
- //#endregion
170
- //#region src/flareReactErrorHandler.ts
171
- function flareReactErrorHandler(options) {
172
- return (error, errorInfo) => {
173
- const errorObject = convertToError(error);
174
- options?.beforeEvaluate?.({
175
- error: errorObject,
176
- errorInfo
177
- });
178
- const context = buildReactContext(errorInfo.componentStack ?? "", errorObject);
179
- const finalContext = options?.beforeSubmit?.({
180
- error: errorObject,
181
- errorInfo,
182
- context
183
- }) ?? context;
184
- flare.reportSilently(errorObject, contextToAttributes(finalContext));
185
- options?.afterSubmit?.({
186
- error: errorObject,
187
- errorInfo,
188
- context: finalContext
189
- });
190
- };
191
- }
192
-
193
- //#endregion
194
4
  //#region src/index.ts
195
- registerReactSdkIdentity();
5
+ registerDefaultFlare(() => flare);
6
+ registerReactSdkIdentity(flare);
196
7
 
197
8
  //#endregion
198
9
  export { FlareErrorBoundary, flareReactErrorHandler };
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_flareReactErrorHandler = require('./flareReactErrorHandler-BECMhASE.cjs');
3
+
4
+ exports.FlareErrorBoundary = require_flareReactErrorHandler.FlareErrorBoundary;
5
+ exports.flareReactErrorHandler = require_flareReactErrorHandler.flareReactErrorHandler;
@@ -0,0 +1,2 @@
1
+ import { a as FlareErrorBoundaryFallbackProps, c as FlareReactContext, i as FlareErrorBoundary, l as MinifiedReactError, n as FlareReactErrorHandlerOptions, o as FlareErrorBoundaryProps, r as flareReactErrorHandler, s as ComponentStackFrame, t as FlareReactErrorHandlerCallback } from "./flareReactErrorHandler-4Vgqlths.cjs";
2
+ export { type ComponentStackFrame, FlareErrorBoundary, type FlareErrorBoundaryFallbackProps, type FlareErrorBoundaryProps, type FlareReactContext, type FlareReactErrorHandlerCallback, type FlareReactErrorHandlerOptions, type MinifiedReactError, flareReactErrorHandler };
@@ -0,0 +1,2 @@
1
+ import { a as FlareErrorBoundaryFallbackProps, c as FlareReactContext, i as FlareErrorBoundary, l as MinifiedReactError, n as FlareReactErrorHandlerOptions, o as FlareErrorBoundaryProps, r as flareReactErrorHandler, s as ComponentStackFrame, t as FlareReactErrorHandlerCallback } from "./flareReactErrorHandler-BcVYRMtC.mjs";
2
+ export { type ComponentStackFrame, FlareErrorBoundary, type FlareErrorBoundaryFallbackProps, type FlareErrorBoundaryProps, type FlareReactContext, type FlareReactErrorHandlerCallback, type FlareReactErrorHandlerOptions, type MinifiedReactError, flareReactErrorHandler };
@@ -0,0 +1,3 @@
1
+ import { n as FlareErrorBoundary, t as flareReactErrorHandler } from "./flareReactErrorHandler-FqJ6hQZc.mjs";
2
+
3
+ export { FlareErrorBoundary, flareReactErrorHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/react",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "React client for flareapp.io",
5
5
  "homepage": "https://flareapp.io",
6
6
  "bugs": "https://github.com/spatie/flare-client-js/issues",
@@ -27,6 +27,10 @@
27
27
  "main": "./dist/index.cjs",
28
28
  "module": "./dist/index.mjs",
29
29
  "types": "./dist/index.d.cts",
30
+ "sideEffects": [
31
+ "./dist/index.cjs",
32
+ "./dist/index.mjs"
33
+ ],
30
34
  "exports": {
31
35
  ".": {
32
36
  "import": {
@@ -37,16 +41,31 @@
37
41
  "types": "./dist/index.d.cts",
38
42
  "default": "./dist/index.cjs"
39
43
  }
44
+ },
45
+ "./inject": {
46
+ "import": {
47
+ "types": "./dist/inject.d.mts",
48
+ "default": "./dist/inject.mjs"
49
+ },
50
+ "require": {
51
+ "types": "./dist/inject.d.cts",
52
+ "default": "./dist/inject.cjs"
53
+ }
40
54
  }
41
55
  },
42
56
  "scripts": {
43
57
  "prepublishOnly": "npm run build",
44
- "build": "tsdown src/index.ts --format cjs,esm --dts --env.PACKAGE_VERSION=$(node -p \"require('./package.json').version\") --clean",
58
+ "build": "tsdown src/index.ts src/inject.ts --format cjs,esm --dts --env.PACKAGE_VERSION=$(node -p \"require('./package.json').version\") --clean",
45
59
  "test": "vitest run",
46
60
  "typescript": "tsc --noEmit",
61
+ "verify:inject": "node scripts/verify-inject-no-root.mjs",
47
62
  "release": "release-it"
48
63
  },
64
+ "dependencies": {
65
+ "@flareapp/core": "2.5.1"
66
+ },
49
67
  "devDependencies": {
68
+ "@flareapp/electron": "file:../electron",
50
69
  "@flareapp/js": "file:../js",
51
70
  "@testing-library/jest-dom": "^6.9.1",
52
71
  "@testing-library/react": "^16.0.0",
@@ -60,7 +79,7 @@
60
79
  "vitest": "^4.0.0"
61
80
  },
62
81
  "peerDependencies": {
63
- "@flareapp/js": "^2.4.0",
82
+ "@flareapp/js": "^2.5.1",
64
83
  "react": "^16.0.0||^17.0.0||^18.0.0||^19.0.0"
65
84
  },
66
85
  "publishConfig": {