usetraceforge 0.1.7 → 0.1.9

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 CHANGED
@@ -2,7 +2,19 @@
2
2
 
3
3
  TraceForge JavaScript SDK for sending errors to your TraceForge backend.
4
4
 
5
- ## Install
5
+ ## 🪄 The 2-Click Installation (Recommended)
6
+
7
+ The easiest way to install and configure TraceForge in a Next.js or Node.js app is to use our interactive CLI wizard. It will automatically install the SDK and write the configuration code for you!
8
+
9
+ ```bash
10
+ npx usetraceforge-cli init
11
+ ```
12
+
13
+ That's it! If you prefer to do it manually, read the manual instructions below.
14
+
15
+ ---
16
+
17
+ ## Manual Installation
6
18
 
7
19
  ```bash
8
20
  npm install usetraceforge
@@ -0,0 +1 @@
1
+ export declare function withTraceForgeConfig(nextConfig?: any): any;
@@ -0,0 +1,26 @@
1
+ import path from "path";
2
+ import { fileURLToPath } from "url";
3
+ const __filename = fileURLToPath(import.meta.url);
4
+ const __dirname = path.dirname(__filename);
5
+ export function withTraceForgeConfig(nextConfig = {}) {
6
+ return {
7
+ ...nextConfig,
8
+ webpack(config, options) {
9
+ // Add our custom loader to the Webpack rules
10
+ config.module.rules.push({
11
+ test: /app\/api\/.*\/route\.(ts|js|tsx|jsx)$/,
12
+ use: [
13
+ {
14
+ // Point to our compiled ESM loader
15
+ loader: path.resolve(__dirname, 'webpack-loader.js'),
16
+ },
17
+ ],
18
+ });
19
+ // Call the user's existing webpack config if they have one
20
+ if (typeof nextConfig.webpack === 'function') {
21
+ return nextConfig.webpack(config, options);
22
+ }
23
+ return config;
24
+ },
25
+ };
26
+ }
@@ -0,0 +1 @@
1
+ export default function traceForgeLoader(source: string): string;
@@ -0,0 +1,32 @@
1
+ const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
2
+ export default function traceForgeLoader(source) {
3
+ let modifiedSource = source;
4
+ let exportedMethods = [];
5
+ methods.forEach(method => {
6
+ // Matches: export async function GET OR export function GET
7
+ const funcRegex = new RegExp(`export\\s+(async\\s+)?function\\s+${method}\\b`, 'g');
8
+ // Matches: export const GET =
9
+ const arrowRegex = new RegExp(`export\\s+(const|let|var)\\s+${method}\\s*=`, 'g');
10
+ let matched = false;
11
+ if (funcRegex.test(modifiedSource)) {
12
+ matched = true;
13
+ modifiedSource = modifiedSource.replace(funcRegex, `const _tf_${method} = $1 function ${method}`);
14
+ }
15
+ if (arrowRegex.test(modifiedSource)) {
16
+ matched = true;
17
+ modifiedSource = modifiedSource.replace(arrowRegex, `const _tf_${method} =`);
18
+ }
19
+ if (matched) {
20
+ exportedMethods.push(method);
21
+ }
22
+ });
23
+ // If we found any API route exports, wrap them!
24
+ if (exportedMethods.length > 0) {
25
+ modifiedSource = `import { withTraceForge } from "usetraceforge/next";\n` + modifiedSource;
26
+ exportedMethods.forEach(method => {
27
+ modifiedSource += `\nexport const ${method} = withTraceForge(_tf_${method});`;
28
+ });
29
+ }
30
+ return modifiedSource;
31
+ }
32
+ ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usetraceforge",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "private": false,
5
5
  "description": "TraceForge JavaScript SDK for sending errors to a TraceForge ingest endpoint.",
6
6
  "type": "module",
@@ -40,6 +40,9 @@
40
40
  "./next": {
41
41
  "types": "./dist/next.d.ts",
42
42
  "import": "./dist/next.js"
43
+ },
44
+ "./next-plugin": {
45
+ "import": "./dist/next-plugin.js"
43
46
  }
44
47
  },
45
48
  "files": [