catalyst-core 0.2.0-beta.3 → 0.3.0-beta.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/babel.native.config.cjs +8 -0
- package/bin/catalyst.js +49 -105
- package/changelog.md +8 -0
- package/dist/caching.js +1 -1
- package/dist/index.jsx +8 -0
- package/dist/logger.js +74 -3
- package/dist/native/androidSetup.js +300 -8
- package/dist/native/bridge/WebBridge.js +481 -59
- package/dist/native/bridge/constants/NativeInterfaces.js +290 -45
- package/dist/native/bridge/errors.js +250 -26
- package/dist/native/bridge/hooks/index.js +125 -1
- package/dist/native/bridge/hooks/useCamera.js +347 -9
- package/dist/native/bridge/hooks/useDataProtection.js +200 -2
- package/dist/native/bridge/hooks/useDeviceInfo.js +71 -2
- package/dist/native/bridge/hooks/useFilePicker.js +429 -2
- package/dist/native/bridge/hooks/useGoogleSignIn.js +81 -1
- package/dist/native/bridge/hooks/useHapticFeedback.js +196 -1
- package/dist/native/bridge/hooks/useIntent.js +95 -1
- package/dist/native/bridge/hooks/useNativeTransition.js +202 -27
- package/dist/native/bridge/hooks/useNetworkStatus.js +84 -3
- package/dist/native/bridge/hooks/useNotification.js +318 -2
- package/dist/native/bridge/hooks/useSafeArea.js +84 -2
- package/dist/native/bridge/hooks/useVideoStream.js +434 -6
- package/dist/native/bridge/hooks/utils.js +27 -1
- package/dist/native/bridge/hooks.js +16 -1
- package/dist/native/bridge/perf/collectors/ApiCollector.js +66 -3
- package/dist/native/bridge/perf/collectors/CacheCollector.js +186 -11
- package/dist/native/bridge/perf/collectors/HookCollector.js +141 -19
- package/dist/native/bridge/perf/collectors/InsightsCollector.js +481 -23
- package/dist/native/bridge/perf/collectors/InteractionCollector.js +245 -10
- package/dist/native/bridge/perf/collectors/KeyboardCollector.js +107 -8
- package/dist/native/bridge/perf/collectors/NavigationCollector.js +273 -32
- package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +178 -2
- package/dist/native/bridge/perf/collectors/RenderCollector.js +258 -14
- package/dist/native/bridge/perf/collectors/ScrollCollector.js +95 -9
- package/dist/native/bridge/perf/collectors/ThreadCollector.js +90 -6
- package/dist/native/bridge/perf/core/constants.js +103 -20
- package/dist/native/bridge/perf/core/measure.js +179 -30
- package/dist/native/bridge/perf/core/session.js +89 -23
- package/dist/native/bridge/perf/core/store.js +554 -1
- package/dist/native/bridge/perf/core/summary.js +174 -1
- package/dist/native/bridge/perf/core/traceExport.js +240 -1
- package/dist/native/bridge/perf/core/waterfalls.js +146 -1
- package/dist/native/bridge/perf/index.js +359 -38
- package/dist/native/bridge/safeArea.js +53 -5
- package/dist/native/bridge/standardizedHooks.js +595 -82
- package/dist/native/bridge/useBaseHook.js +274 -38
- package/dist/native/bridge/utils/CameraUtils.js +201 -56
- package/dist/native/bridge/utils/FileObjectConverter.js +129 -18
- package/dist/native/bridge/utils/NativeBridge.js +425 -141
- package/dist/native/buildAndroid/assets.js +510 -13
- package/dist/native/buildAndroid/build.js +296 -19
- package/dist/native/buildAndroid/config.js +87 -1
- package/dist/native/buildAndroid/index.js +374 -1
- package/dist/native/buildAppAndroid.js +34 -2
- package/dist/native/buildAppIos.js +62 -2
- package/dist/native/buildIos/assets.js +609 -8
- package/dist/native/buildIos/build.js +639 -20
- package/dist/native/buildIos/config.js +294 -12
- package/dist/native/buildIos/index.js +343 -6
- package/dist/native/buildIos/plugins.js +343 -16
- package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +43 -0
- package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +28 -0
- package/dist/native/internal-plugins/device-info-plugin/manifest.json +19 -0
- package/dist/native/internalPluginUtils.js +232 -7
- package/dist/native/package.json +3 -0
- package/dist/native/plugin-bridge/PluginBridge.js +227 -1
- package/dist/native/pluginComposerAndroid.js +407 -23
- package/dist/native/pluginComposerIos.js +435 -11
- package/dist/native/renameAndroidProject.js +1094 -88
- package/dist/native/setupEmulatorIos.js +289 -22
- package/dist/native/setupServer.js +160 -19
- package/dist/native/terminalProgress.js +199 -11
- package/dist/native/utils.js +193 -15
- package/dist/offline/catalyst-sw.js +145 -1
- package/dist/offline/registerServiceWorker.js +33 -1
- package/dist/otel.js +375 -46
- package/dist/router/ClientRouter.js +14 -2
- package/dist/router/ServerRouter.js +9 -1
- package/dist/router.js +1 -1
- package/dist/scripts/build.js +112 -3
- package/dist/scripts/checkVersion.js +3 -1
- package/dist/scripts/cleanCache.js +30 -1
- package/dist/scripts/generateOfflineManifest.js +116 -1
- package/dist/scripts/loadEnvironmentVariables.js +32 -6
- package/dist/scripts/plugins.js +309 -1
- package/dist/scripts/preServerInit.js +13 -0
- package/dist/scripts/scriptUtils.js +54 -3
- package/dist/scripts/serve.js +51 -4
- package/dist/scripts/start.js +47 -10
- package/dist/scripts/validator.js +149 -1
- package/dist/sentry.cjs +127 -0
- package/dist/sentry.js +125 -5
- package/dist/server/expressServer.js +250 -5
- package/dist/server/manifestCache.js +36 -0
- package/dist/server/renderer/ChunkExtractor.js +144 -0
- package/dist/server/renderer/document/Body.jsx +59 -0
- package/dist/server/renderer/document/FastRefresh.jsx +20 -0
- package/dist/server/renderer/document/Head.jsx +60 -0
- package/dist/server/renderer/document/index.jsx +2 -0
- package/dist/server/renderer/extract.js +149 -31
- package/dist/server/renderer/handler.jsx +433 -0
- package/dist/server/renderer/index.js +8 -1
- package/dist/server/renderer/render.js +47 -0
- package/dist/server/utils/botDetectionMiddleware.js +29 -0
- package/dist/server/utils/cjsRequire.js +10 -0
- package/dist/server/utils/userAgentUtil.js +87 -9
- package/dist/server/utils/validator.js +164 -1
- package/dist/vite/FastRefresh.jsx +20 -0
- package/dist/vite/inject-cache-key-plugin.js +276 -0
- package/dist/vite/loadCustomViteConfig.js +22 -0
- package/dist/vite/manifest-categorization-plugin.js +455 -0
- package/dist/vite/node-loader.mjs +458 -0
- package/dist/vite/scssParams.js +21 -0
- package/dist/vite/vite.config.client.js +130 -0
- package/dist/vite/vite.config.js +422 -0
- package/dist/vite/vite.config.server.js +84 -0
- package/dist/web-router/components/MetaTag.jsx +34 -0
- package/dist/web-router/components/RouterDataProvider.jsx +332 -0
- package/dist/web-router/components/Split.jsx +200 -0
- package/dist/web-router/components/SplitInview.jsx +106 -0
- package/dist/web-router/components/SsrRequestContext.jsx +14 -0
- package/dist/web-router/context.jsx +12 -0
- package/dist/web-router/hooks.jsx +72 -0
- package/dist/web-router/types/components/MetaTag.d.ts +2 -0
- package/dist/web-router/types/components/RouterDataProvider.d.ts +95 -0
- package/dist/web-router/types/context.d.ts +14 -0
- package/dist/web-router/types/hooks.d.ts +1 -0
- package/dist/web-router/types/index.d.ts +3 -0
- package/dist/web-router/types/utils/metaDataUtils.d.ts +24 -0
- package/dist/web-router/utils/metaDataUtils.jsx +119 -0
- package/mcp_v2/conversion-tasks.json +35 -17
- package/mcp_v2/knowledge-base.json +124 -13
- package/mcp_v2/lib/helpers.js +10 -0
- package/mcp_v2/mcp.js +4 -4
- package/mcp_v2/package.json +1 -0
- package/mcp_v2/tools/build.js +116 -20
- package/mcp_v2/tools/conversion.js +106 -5
- package/mcp_v2/tools/tasks.js +18 -14
- package/package.json +35 -68
- package/babel.config.js +0 -32
- package/dist/index.js +0 -1
- package/dist/scripts/devBuild.js +0 -3
- package/dist/scripts/devServe.js +0 -3
- package/dist/scripts/loadScriptsBeforeServerStarts.js +0 -4
- package/dist/scripts/registerAliases.js +0 -6
- package/dist/server/renderer/document/Body.js +0 -11
- package/dist/server/renderer/document/Head.js +0 -9
- package/dist/server/renderer/document/index.js +0 -1
- package/dist/server/renderer/handler.js +0 -47
- package/dist/server/startServer.js +0 -57
- package/dist/webpack/babel-plugins/remove-client.plugin.js +0 -5
- package/dist/webpack/babel-plugins/remove-ssr.plugin.js +0 -5
- package/dist/webpack/babel.config.client.js +0 -1
- package/dist/webpack/babel.config.ssr.js +0 -1
- package/dist/webpack/base.babel.js +0 -7
- package/dist/webpack/development.client.babel.js +0 -10
- package/dist/webpack/production.client.babel.js +0 -4
- package/dist/webpack/production.ssr.babel.js +0 -8
- package/dist/webpack/scssParams.js +0 -9
package/dist/scripts/start.js
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
import path from "path"
|
|
2
|
+
import { spawnSync } from "child_process"
|
|
3
|
+
import { arrayToObject } from "./scriptUtils.js"
|
|
4
|
+
import { fileURLToPath } from "url"
|
|
5
|
+
import { dirname } from "path"
|
|
6
|
+
import { readFileSync } from "fs"
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
9
|
+
const __dirname = dirname(__filename)
|
|
10
|
+
const loaderPath = path.resolve(__dirname, "../../dist/vite/node-loader.mjs")
|
|
11
|
+
const preInitPath = path.resolve(__dirname, "preServerInit.js")
|
|
12
|
+
|
|
13
|
+
/**
|
|
2
14
|
* @description - starts webpack dev server and node server.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
*/
|
|
16
|
+
function start() {
|
|
17
|
+
const commandLineArguments = process.argv.slice(2)
|
|
18
|
+
const argumentsObject = arrayToObject(commandLineArguments)
|
|
19
|
+
const dirname = path.resolve(__dirname, "../../")
|
|
20
|
+
|
|
21
|
+
// Read package.json
|
|
22
|
+
const packageJson = JSON.parse(readFileSync(path.join(process.env.PWD, "package.json"), "utf-8"))
|
|
23
|
+
const { name } = packageJson
|
|
24
|
+
|
|
25
|
+
const command = `node --import ${preInitPath} --loader ${loaderPath} ./dist/server/expressServer.js`
|
|
26
|
+
spawnSync(command, [], {
|
|
27
|
+
cwd: dirname,
|
|
28
|
+
stdio: "inherit",
|
|
29
|
+
shell: true,
|
|
30
|
+
env: {
|
|
31
|
+
...process.env,
|
|
32
|
+
src_path: process.env.PWD,
|
|
33
|
+
NODE_ENV: "development",
|
|
34
|
+
IS_DEV_COMMAND: false,
|
|
35
|
+
APPLICATION: name || "catalyst_app",
|
|
36
|
+
...argumentsObject,
|
|
37
|
+
filterKeys: JSON.stringify([
|
|
38
|
+
"src_path",
|
|
39
|
+
"NODE_ENV",
|
|
40
|
+
"IS_DEV_COMMAND",
|
|
41
|
+
"APPLICATION",
|
|
42
|
+
...Object.keys(argumentsObject),
|
|
43
|
+
]),
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
start()
|
|
@@ -1 +1,149 @@
|
|
|
1
|
-
|
|
1
|
+
import pc from "picocolors"
|
|
2
|
+
|
|
3
|
+
const handleError = (e) => {
|
|
4
|
+
console.log(pc.red("Failed to start server: "), e)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const validatePreInitServer = (fn) => {
|
|
8
|
+
try {
|
|
9
|
+
if (!fn) throw new Error("preServerInit named function should be defined in server/index.js")
|
|
10
|
+
if (typeof fn !== "function")
|
|
11
|
+
throw new Error("preServerInit should be function present in server/index.js")
|
|
12
|
+
return true
|
|
13
|
+
} catch (e) {
|
|
14
|
+
handleError(e)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const validateMiddleware = (fn) => {
|
|
19
|
+
try {
|
|
20
|
+
if (!fn) throw new Error("addMiddlewares named function not found in server/server.js")
|
|
21
|
+
if (typeof fn !== "function")
|
|
22
|
+
throw new Error("addMiddlewares should be function present in server/server.js")
|
|
23
|
+
return true
|
|
24
|
+
} catch (e) {
|
|
25
|
+
handleError(e)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const validateReducerFunction = (fn) => {
|
|
30
|
+
try {
|
|
31
|
+
if (!fn) throw new Error("reducer not found in src/js/containers/App/reducer")
|
|
32
|
+
if (typeof fn !== "function")
|
|
33
|
+
throw new Error("reducer should present in src/js/containers/App/reducer")
|
|
34
|
+
return true
|
|
35
|
+
} catch (e) {
|
|
36
|
+
handleError(e)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const validateConfigFile = (obj) => {
|
|
41
|
+
try {
|
|
42
|
+
if (!obj) throw new Error("config not found in config folder")
|
|
43
|
+
if (typeof obj !== "object")
|
|
44
|
+
throw new Error(
|
|
45
|
+
"config object should be exported from config folder inside your project root directory"
|
|
46
|
+
)
|
|
47
|
+
if (typeof obj === "object") {
|
|
48
|
+
const requiredConfigKeys = {
|
|
49
|
+
NODE_SERVER_HOSTNAME: "",
|
|
50
|
+
NODE_SERVER_PORT: "",
|
|
51
|
+
WEBPACK_DEV_SERVER_HOSTNAME: "",
|
|
52
|
+
WEBPACK_DEV_SERVER_PORT: "",
|
|
53
|
+
BUILD_OUTPUT_PATH: "",
|
|
54
|
+
PUBLIC_STATIC_ASSET_PATH: "",
|
|
55
|
+
PUBLIC_STATIC_ASSET_URL: "",
|
|
56
|
+
CLIENT_ENV_VARIABLES: [],
|
|
57
|
+
ANALYZE_BUNDLE: "",
|
|
58
|
+
}
|
|
59
|
+
for (let key in requiredConfigKeys) {
|
|
60
|
+
if (!(key in obj)) throw new Error(`${key} key not found inside config.json`)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true
|
|
64
|
+
} catch (e) {
|
|
65
|
+
handleError(e)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const validatePackageJson = (obj) => {
|
|
70
|
+
try {
|
|
71
|
+
if (!obj) throw new Error("package.json not found in the project")
|
|
72
|
+
if (typeof obj !== "object")
|
|
73
|
+
throw new Error("package.json should be defined in project root directory")
|
|
74
|
+
return true
|
|
75
|
+
} catch (e) {
|
|
76
|
+
handleError(e)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const validateModuleAlias = (obj) => {
|
|
81
|
+
try {
|
|
82
|
+
if (!obj) throw new Error("moduleAliases not found in package.json file present in root directory.")
|
|
83
|
+
if (typeof obj !== "object")
|
|
84
|
+
throw new Error("moduleAliases named object should be exported from package.json")
|
|
85
|
+
if (typeof obj === "object") {
|
|
86
|
+
const requiredModuleAliases = {
|
|
87
|
+
"@api": "api.js",
|
|
88
|
+
"@containers": "src/js/containers",
|
|
89
|
+
"@server": "server",
|
|
90
|
+
"@config": "config",
|
|
91
|
+
"@css": "src/static/css",
|
|
92
|
+
"@routes": "src/js/routes/",
|
|
93
|
+
}
|
|
94
|
+
for (let key in requiredModuleAliases) {
|
|
95
|
+
if (key.includes("catalyst"))
|
|
96
|
+
throw new Error(`Catalyst keyword is restricted for defining aliases`)
|
|
97
|
+
if (!(key in obj)) throw new Error(`${key} module alias not defined inside package.json`)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return true
|
|
101
|
+
} catch (e) {
|
|
102
|
+
handleError(e)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const validateConfigureStore = (fn) => {
|
|
107
|
+
try {
|
|
108
|
+
if (!fn) throw new Error("configureStore not found in file src/js/store/index.js")
|
|
109
|
+
if (typeof fn !== "function")
|
|
110
|
+
throw new Error("configureStore should be function exported from src/js/store/index.js")
|
|
111
|
+
return true
|
|
112
|
+
} catch (e) {
|
|
113
|
+
handleError(e)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const validateGetRoutes = (fn) => {
|
|
118
|
+
try {
|
|
119
|
+
if (!fn) throw new Error("getRoutes not found in file src/js/routes/utils.js")
|
|
120
|
+
if (typeof fn !== "function")
|
|
121
|
+
throw new Error("getRoutes should be function exported from src/js/routers/index.js")
|
|
122
|
+
return true
|
|
123
|
+
} catch (e) {
|
|
124
|
+
handleError(e)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const validateCustomDocument = (fn) => {
|
|
129
|
+
try {
|
|
130
|
+
if (!fn) throw new Error("document not found in file server/document.js")
|
|
131
|
+
if (typeof fn !== "function")
|
|
132
|
+
throw new Error("document should be a react component exported from server/document.js")
|
|
133
|
+
return true
|
|
134
|
+
} catch (e) {
|
|
135
|
+
handleError(e)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
validateConfigFile,
|
|
141
|
+
validateConfigureStore,
|
|
142
|
+
validateCustomDocument,
|
|
143
|
+
validateGetRoutes,
|
|
144
|
+
validatePackageJson,
|
|
145
|
+
validateReducerFunction,
|
|
146
|
+
validateModuleAlias,
|
|
147
|
+
validatePreInitServer,
|
|
148
|
+
validateMiddleware,
|
|
149
|
+
}
|
package/dist/sentry.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ErrorBoundary = void 0;
|
|
7
|
+
exports.addBreadcrumb = addBreadcrumb;
|
|
8
|
+
exports.captureException = captureException;
|
|
9
|
+
exports.captureMessage = captureMessage;
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
exports.init = init;
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
let sentryInitialized = false;
|
|
16
|
+
function getSentryInstance() {
|
|
17
|
+
let instance = null;
|
|
18
|
+
const isServer = typeof window === "undefined";
|
|
19
|
+
if (isServer) {
|
|
20
|
+
try {
|
|
21
|
+
const sentryNodeModule = "@sentry/node";
|
|
22
|
+
// eslint-disable-next-line security/detect-eval-with-expression, no-eval
|
|
23
|
+
instance = eval(`require("${sentryNodeModule}")`);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.warn("Failed to load @sentry/node:", error.message);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
try {
|
|
30
|
+
instance = require("@sentry/react");
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.warn("Failed to load @sentry/react:", error.message);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return instance;
|
|
37
|
+
}
|
|
38
|
+
const Sentry = getSentryInstance();
|
|
39
|
+
function init() {
|
|
40
|
+
if (sentryInitialized) {
|
|
41
|
+
console.warn("Sentry has already been initialized");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let sentryConfig = process.env.SENTRY_CONFIG;
|
|
45
|
+
if (!sentryConfig) {
|
|
46
|
+
console.warn("Sentry configuration not found, skipping initialization");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
sentryConfig = JSON.parse(sentryConfig);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn("Invalid sentry configuration", error);
|
|
53
|
+
}
|
|
54
|
+
const isServer = typeof window === "undefined";
|
|
55
|
+
if (!sentryConfig.dsn) {
|
|
56
|
+
console.warn("Sentry DSN not found in configuration, skipping initialization");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
if (isServer) {
|
|
61
|
+
Sentry.init({
|
|
62
|
+
dsn: sentryConfig.dsn,
|
|
63
|
+
tracesSampleRate: sentryConfig.tracesSampleRate || 1.0,
|
|
64
|
+
...sentryConfig.serverOptions
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
Sentry.init({
|
|
68
|
+
dsn: sentryConfig.dsn,
|
|
69
|
+
tracesSampleRate: sentryConfig.tracesSampleRate || 1.0,
|
|
70
|
+
...sentryConfig.clientOptions
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
sentryInitialized = true;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error("Failed to initialize Sentry:", error.message);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function captureException(error, context = {}) {
|
|
80
|
+
Sentry.captureException(error, context);
|
|
81
|
+
}
|
|
82
|
+
function captureMessage(message, level = "info") {
|
|
83
|
+
Sentry.captureMessage(message, level);
|
|
84
|
+
}
|
|
85
|
+
function addBreadcrumb(breadcrumb) {
|
|
86
|
+
Sentry.addBreadcrumb(breadcrumb);
|
|
87
|
+
}
|
|
88
|
+
class ErrorBoundary extends _react.default.Component {
|
|
89
|
+
constructor(props) {
|
|
90
|
+
super(props);
|
|
91
|
+
this.state = {
|
|
92
|
+
hasError: false
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
static getDerivedStateFromError() {
|
|
96
|
+
return {
|
|
97
|
+
hasError: true
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
componentDidCatch(error, errorInfo) {
|
|
101
|
+
captureException(error, {
|
|
102
|
+
componentStack: errorInfo.componentStack
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
if (this.state.hasError) {
|
|
107
|
+
// eslint-disable-next-line react/prop-types
|
|
108
|
+
if (this.props.fallback) {
|
|
109
|
+
// eslint-disable-next-line react/prop-types
|
|
110
|
+
return this.props.fallback;
|
|
111
|
+
}
|
|
112
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("h1", {
|
|
113
|
+
children: "Something went wrong."
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// eslint-disable-next-line react/prop-types
|
|
118
|
+
return this.props.children;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
122
|
+
var _default = exports.default = {
|
|
123
|
+
init,
|
|
124
|
+
captureException,
|
|
125
|
+
captureMessage,
|
|
126
|
+
addBreadcrumb
|
|
127
|
+
};
|
package/dist/sentry.js
CHANGED
|
@@ -1,5 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import React from "react"
|
|
2
|
+
|
|
3
|
+
let sentryInitialized = false
|
|
4
|
+
|
|
5
|
+
function getSentryInstance() {
|
|
6
|
+
let instance = null
|
|
7
|
+
const isServer = typeof window === "undefined"
|
|
8
|
+
|
|
9
|
+
if (isServer) {
|
|
10
|
+
try {
|
|
11
|
+
const sentryNodeModule = "@sentry/node"
|
|
12
|
+
// eslint-disable-next-line security/detect-eval-with-expression, no-eval
|
|
13
|
+
instance = eval(`require("${sentryNodeModule}")`)
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.warn("Failed to load @sentry/node:", error.message)
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
try {
|
|
20
|
+
instance = require("@sentry/react")
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.warn("Failed to load @sentry/react:", error.message)
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return instance
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const Sentry = getSentryInstance()
|
|
30
|
+
|
|
31
|
+
export function init() {
|
|
32
|
+
if (sentryInitialized) {
|
|
33
|
+
console.warn("Sentry has already been initialized")
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let sentryConfig = process.env.SENTRY_CONFIG
|
|
38
|
+
|
|
39
|
+
if (!sentryConfig) {
|
|
40
|
+
console.warn("Sentry configuration not found, skipping initialization")
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
sentryConfig = JSON.parse(sentryConfig)
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.warn("Invalid sentry configuration", error)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const isServer = typeof window === "undefined"
|
|
51
|
+
|
|
52
|
+
if (!sentryConfig.dsn) {
|
|
53
|
+
console.warn("Sentry DSN not found in configuration, skipping initialization")
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
if (isServer) {
|
|
59
|
+
Sentry.init({
|
|
60
|
+
dsn: sentryConfig.dsn,
|
|
61
|
+
tracesSampleRate: sentryConfig.tracesSampleRate || 1.0,
|
|
62
|
+
...sentryConfig.serverOptions,
|
|
63
|
+
})
|
|
64
|
+
} else {
|
|
65
|
+
Sentry.init({
|
|
66
|
+
dsn: sentryConfig.dsn,
|
|
67
|
+
tracesSampleRate: sentryConfig.tracesSampleRate || 1.0,
|
|
68
|
+
...sentryConfig.clientOptions,
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
sentryInitialized = true
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error("Failed to initialize Sentry:", error.message)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function captureException(error, context = {}) {
|
|
80
|
+
Sentry.captureException(error, context)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function captureMessage(message, level = "info") {
|
|
84
|
+
Sentry.captureMessage(message, level)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function addBreadcrumb(breadcrumb) {
|
|
88
|
+
Sentry.addBreadcrumb(breadcrumb)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class ErrorBoundary extends React.Component {
|
|
92
|
+
constructor(props) {
|
|
93
|
+
super(props)
|
|
94
|
+
this.state = { hasError: false }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static getDerivedStateFromError() {
|
|
98
|
+
return { hasError: true }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
componentDidCatch(error, errorInfo) {
|
|
102
|
+
captureException(error, { componentStack: errorInfo.componentStack })
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
render() {
|
|
106
|
+
if (this.state.hasError) {
|
|
107
|
+
// eslint-disable-next-line react/prop-types
|
|
108
|
+
if (this.props.fallback) {
|
|
109
|
+
// eslint-disable-next-line react/prop-types
|
|
110
|
+
return this.props.fallback
|
|
111
|
+
}
|
|
112
|
+
return <h1>Something went wrong.</h1>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// eslint-disable-next-line react/prop-types
|
|
116
|
+
return this.props.children
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default {
|
|
121
|
+
init,
|
|
122
|
+
captureException,
|
|
123
|
+
captureMessage,
|
|
124
|
+
addBreadcrumb,
|
|
125
|
+
}
|