usetraceforge 0.1.28 → 0.1.29
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/nestjs.d.ts +10 -0
- package/dist/nestjs.js +92 -0
- package/package.json +20 -9
package/dist/nestjs.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
export declare class TraceForgeExceptionFilter implements ExceptionFilter {
|
|
3
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
4
|
+
}
|
|
5
|
+
export declare const TraceForgeNest: {
|
|
6
|
+
TraceForgeExceptionFilter: typeof TraceForgeExceptionFilter;
|
|
7
|
+
init: (options: import("./index.js").TraceForgeConfig) => void;
|
|
8
|
+
captureException: (error: unknown, extras?: import("./index.js").CapturePayload) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export default TraceForgeNest;
|
package/dist/nestjs.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { Catch, HttpException, HttpStatus } from '@nestjs/common';
|
|
36
|
+
import TraceForge from './index.js';
|
|
37
|
+
let TraceForgeExceptionFilter = (() => {
|
|
38
|
+
let _classDecorators = [Catch()];
|
|
39
|
+
let _classDescriptor;
|
|
40
|
+
let _classExtraInitializers = [];
|
|
41
|
+
let _classThis;
|
|
42
|
+
var TraceForgeExceptionFilter = class {
|
|
43
|
+
static { _classThis = this; }
|
|
44
|
+
static {
|
|
45
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
46
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
47
|
+
TraceForgeExceptionFilter = _classThis = _classDescriptor.value;
|
|
48
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
49
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
50
|
+
}
|
|
51
|
+
catch(exception, host) {
|
|
52
|
+
const ctx = host.switchToHttp();
|
|
53
|
+
const request = ctx.getRequest();
|
|
54
|
+
const response = ctx.getResponse();
|
|
55
|
+
// Default status to 500
|
|
56
|
+
const status = exception instanceof HttpException
|
|
57
|
+
? exception.getStatus()
|
|
58
|
+
: HttpStatus.INTERNAL_SERVER_ERROR;
|
|
59
|
+
const url = `${request.protocol || 'http'}://${request.get('host') || 'localhost'}${request.originalUrl || request.url}`;
|
|
60
|
+
// Send the error to TraceForge in the background
|
|
61
|
+
TraceForge.captureException(exception, {
|
|
62
|
+
tags: { framework: 'nestjs' },
|
|
63
|
+
payload: {
|
|
64
|
+
url,
|
|
65
|
+
method: request.method,
|
|
66
|
+
statusCode: status
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// We do NOT block or modify the response structure! We return a standard JSON response.
|
|
70
|
+
// However, if the user wants to use TraceForge but KEEP their own exception filter format,
|
|
71
|
+
// they should manually inject `TraceForgeNest.captureException()` into their own `@Catch` block.
|
|
72
|
+
// Standard NestJS JSON response format
|
|
73
|
+
const message = exception instanceof HttpException
|
|
74
|
+
? exception.getResponse()
|
|
75
|
+
: 'Internal server error';
|
|
76
|
+
response.status(status).json({
|
|
77
|
+
statusCode: status,
|
|
78
|
+
timestamp: new Date().toISOString(),
|
|
79
|
+
path: request.url,
|
|
80
|
+
message: typeof message === 'string' ? message : message?.message || message,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return TraceForgeExceptionFilter = _classThis;
|
|
85
|
+
})();
|
|
86
|
+
export { TraceForgeExceptionFilter };
|
|
87
|
+
export const TraceForgeNest = {
|
|
88
|
+
TraceForgeExceptionFilter,
|
|
89
|
+
init: TraceForge.init,
|
|
90
|
+
captureException: TraceForge.captureException
|
|
91
|
+
};
|
|
92
|
+
export default TraceForgeNest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usetraceforge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TraceForge JavaScript SDK for sending errors to a TraceForge ingest endpoint.",
|
|
6
6
|
"type": "module",
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
"require": "./dist/fastify.js",
|
|
43
43
|
"types": "./dist/fastify.d.ts"
|
|
44
44
|
},
|
|
45
|
+
"./nestjs": {
|
|
46
|
+
"import": "./dist/nestjs.js",
|
|
47
|
+
"require": "./dist/nestjs.js",
|
|
48
|
+
"types": "./dist/nestjs.d.ts"
|
|
49
|
+
},
|
|
45
50
|
"./express": {
|
|
46
51
|
"types": "./dist/express.d.ts",
|
|
47
52
|
"import": "./dist/express.js",
|
|
@@ -84,19 +89,25 @@
|
|
|
84
89
|
"publishConfig": {
|
|
85
90
|
"access": "public"
|
|
86
91
|
},
|
|
87
|
-
"dependencies": {},
|
|
88
92
|
"devDependencies": {
|
|
89
|
-
"
|
|
90
|
-
"
|
|
93
|
+
"@nestjs/common": "^11.1.27",
|
|
94
|
+
"@types/express": "^4.17.21",
|
|
91
95
|
"@types/react": "^18.2.0",
|
|
92
|
-
"
|
|
96
|
+
"reflect-metadata": "^0.2.2",
|
|
97
|
+
"rxjs": "^7.8.2",
|
|
98
|
+
"tsx": "^4.16.2",
|
|
99
|
+
"typescript": "^5.5.4"
|
|
93
100
|
},
|
|
94
101
|
"peerDependencies": {
|
|
95
|
-
"
|
|
96
|
-
"
|
|
102
|
+
"express": ">=4.0.0",
|
|
103
|
+
"react": ">=16.8.0"
|
|
97
104
|
},
|
|
98
105
|
"peerDependenciesMeta": {
|
|
99
|
-
"react": {
|
|
100
|
-
|
|
106
|
+
"react": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"express": {
|
|
110
|
+
"optional": true
|
|
111
|
+
}
|
|
101
112
|
}
|
|
102
113
|
}
|