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