bugg-lens-nestjs 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # bugg-lens-nestjs
2
+
3
+ NestJS integration for Bugg Lens.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install bugg-lens-nestjs
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { BuggLensModule } from 'bugg-lens-nestjs';
15
+
16
+ @Module({
17
+ imports: [
18
+ BuggLensModule.forRoot({
19
+ dsn: 'https://your-backend.example.com',
20
+ apiKey: process.env.BUGG_LENS_API_KEY,
21
+ }),
22
+ ],
23
+ })
24
+ export class AppModule {}
25
+ ```
26
+
27
+ By default, `apiKey` is sent as the `x-api-key` header. You can customize it:
28
+
29
+ ```ts
30
+ BuggLensModule.forRoot({
31
+ dsn: process.env.BUGG_LENS_DSN!,
32
+ apiKey: process.env.BUGG_LENS_API_KEY,
33
+ apiKeyHeader: 'authorization',
34
+ })
35
+ ```
36
+
37
+ You can also pass custom headers:
38
+
39
+ ```ts
40
+ BuggLensModule.forRoot({
41
+ dsn: process.env.BUGG_LENS_DSN!,
42
+ headers: {
43
+ Authorization: `Bearer ${process.env.BUGG_LENS_TOKEN}`,
44
+ },
45
+ })
46
+ ```
47
+
48
+ ## Capture an Error
49
+
50
+ ```ts
51
+ import { Inject, Injectable } from '@nestjs/common';
52
+ import { BUGG_LENS, BuggLens } from 'bugg-lens-nestjs';
53
+
54
+ @Injectable()
55
+ export class AppService {
56
+ constructor(@Inject(BUGG_LENS) private readonly buggLens: BuggLens) {}
57
+
58
+ async run() {
59
+ try {
60
+ throw new Error('Something failed');
61
+ } catch (error) {
62
+ await this.buggLens.captureAsync(error as Error);
63
+ }
64
+ }
65
+ }
66
+ ```
@@ -0,0 +1,21 @@
1
+ export interface BuggLensOptions {
2
+ dsn: string;
3
+ apiKey?: string;
4
+ apiKeyHeader?: string;
5
+ headers?: Record<string, string>;
6
+ timeoutMs?: number;
7
+ }
8
+ export declare class BuggLens {
9
+ private readonly options;
10
+ private readonly http;
11
+ constructor(options: BuggLensOptions);
12
+ connect(): Promise<void>;
13
+ disconnect(): Promise<void>;
14
+ private buildHeaders;
15
+ capture(error: Error): void;
16
+ captureAsync(error: Error, occurredAt: Date): Promise<void>;
17
+ private extractErrorMeta;
18
+ private sendSourceContext;
19
+ private extractFrame;
20
+ }
21
+ //# sourceMappingURL=bugg-lens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.d.ts","sourceRoot":"","sources":["../bugg-lens.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AASD,qBAAa,QAAQ;IAIb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;gBAGhB,OAAO,EAAE,eAAe;IASvC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAOrB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IASjE,OAAO,CAAC,gBAAgB;YAYV,iBAAiB;IAY/B,OAAO,CAAC,YAAY;CAkBvB"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BuggLens = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const bugg_lens_util_1 = require("./bugg-lens.util");
9
+ class BuggLens {
10
+ constructor(options) {
11
+ this.options = options;
12
+ this.http = axios_1.default.create({
13
+ baseURL: this.options.dsn,
14
+ headers: this.buildHeaders(options),
15
+ timeout: this.options.timeoutMs ?? 5000,
16
+ });
17
+ }
18
+ async connect() {
19
+ }
20
+ async disconnect() {
21
+ }
22
+ buildHeaders(options) {
23
+ if (!options.apiKey)
24
+ return options.headers;
25
+ return {
26
+ ...options.headers,
27
+ [options.apiKeyHeader ?? 'x-api-key']: options.apiKey,
28
+ };
29
+ }
30
+ capture(error) {
31
+ const occurredAt = new Date();
32
+ setImmediate(() => {
33
+ void this.captureAsync(error, occurredAt).catch(() => undefined);
34
+ });
35
+ }
36
+ async captureAsync(error, occurredAt) {
37
+ const frame = this.extractFrame(error, occurredAt);
38
+ if (!frame)
39
+ return;
40
+ await this.sendSourceContext({ ...frame, occurredAt });
41
+ }
42
+ extractErrorMeta(error) {
43
+ const match = /^([A-Za-z]+(?:Error|Exception)?): (.+)$/m.exec(error.stack ?? '');
44
+ return {
45
+ type: match?.[1] ?? 'UnknownError',
46
+ message: match?.[2] ?? 'Unknown error',
47
+ name: error?.constructor?.name ?? 'UnknownError',
48
+ stack: error?.stack ?? 'No stack trace available',
49
+ };
50
+ }
51
+ async sendSourceContext(frame) {
52
+ let sourceContext = frame;
53
+ try {
54
+ sourceContext = await (0, bugg_lens_util_1.getSourceContext)(frame);
55
+ }
56
+ catch {
57
+ sourceContext = frame;
58
+ }
59
+ await this.http.post('/errors', sourceContext);
60
+ }
61
+ extractFrame(error, occurredAt) {
62
+ const match = /\((.+):(\d+):(\d+)\)/.exec(error.stack ?? '');
63
+ if (!match)
64
+ return null;
65
+ const [, file, line, column] = match;
66
+ const meta = this.extractErrorMeta(error);
67
+ return {
68
+ ...meta,
69
+ file,
70
+ line: Number(line),
71
+ column: Number(column),
72
+ occurredAt
73
+ };
74
+ }
75
+ }
76
+ exports.BuggLens = BuggLens;
77
+ //# sourceMappingURL=bugg-lens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.js","sourceRoot":"","sources":["../bugg-lens.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,qDAA0E;AAiB1E,MAAa,QAAQ;IAGjB,YACqB,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAEzC,IAAI,CAAC,IAAI,GAAG,eAAK,CAAC,MAAM,CAAC;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;YACzB,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;YACnC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS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D,CAAC;IACN,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,KAAY;QACxC,IAAI,aAAa,GAA0B,KAAK,CAAC;QAEjD,IAAI,CAAC;YACD,aAAa,GAAG,MAAM,IAAA,iCAAgB,EAAC,KAAK,CAAC,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACL,aAAa,GAAG,KAAK,CAAC;QAC1B,CAAC;QAED,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;IAEO,YAAY,CAAC,KAAY,EAAE,UAAgB;QAE/C,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;QAE7D,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;QAErC,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAE1C,OAAO;YACH,GAAG,IAAI;YACP,IAAI;YACJ,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,UAAU;SACb,CAAC;IACN,CAAC;CACJ;AAxFD,4BAwFC"}
@@ -0,0 +1,13 @@
1
+ import { DynamicModule, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
2
+ import { BuggLensOptions, BuggLens } from './bugg-lens';
3
+ export declare const BUGG_LENS: unique symbol;
4
+ export interface BuggLensModuleOptions extends BuggLensOptions {
5
+ }
6
+ export declare class BuggLensModule implements OnModuleInit, OnModuleDestroy {
7
+ private readonly buggLens;
8
+ static forRoot(options: BuggLensModuleOptions): DynamicModule;
9
+ constructor(buggLens: BuggLens);
10
+ onModuleInit(): Promise<void>;
11
+ onModuleDestroy(): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=bugg-lens.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.module.d.ts","sourceRoot":"","sources":["../bugg-lens.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAGb,eAAe,EACf,YAAY,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAExD,eAAO,MAAM,SAAS,eAAsB,CAAC;AAE7C,MAAM,WAAW,qBAAsB,SAAQ,eAAe;CAE7D;AAED,qBACa,cAAe,YAAW,YAAY,EAAE,eAAe;IAkBzC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAhBhD,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,aAAa;gBAgBrB,QAAQ,EAAE,QAAQ;IAKpD,YAAY;IAIZ,eAAe;CAGxB"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var BuggLensModule_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.BuggLensModule = exports.BUGG_LENS = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const bugg_lens_1 = require("./bugg-lens");
19
+ exports.BUGG_LENS = Symbol('BUGG_LENS');
20
+ let BuggLensModule = BuggLensModule_1 = class BuggLensModule {
21
+ static forRoot(options) {
22
+ const buggLensProvider = {
23
+ provide: exports.BUGG_LENS,
24
+ useFactory: () => new bugg_lens_1.BuggLens(options),
25
+ };
26
+ return {
27
+ module: BuggLensModule_1,
28
+ providers: [buggLensProvider],
29
+ exports: [buggLensProvider],
30
+ global: true,
31
+ };
32
+ }
33
+ constructor(buggLens) {
34
+ this.buggLens = buggLens;
35
+ }
36
+ async onModuleInit() {
37
+ await this.buggLens.connect();
38
+ }
39
+ async onModuleDestroy() {
40
+ await this.buggLens.disconnect();
41
+ }
42
+ };
43
+ exports.BuggLensModule = BuggLensModule;
44
+ exports.BuggLensModule = BuggLensModule = BuggLensModule_1 = __decorate([
45
+ (0, common_1.Module)({}),
46
+ __param(0, (0, common_1.Inject)(exports.BUGG_LENS)),
47
+ __metadata("design:paramtypes", [bugg_lens_1.BuggLens])
48
+ ], BuggLensModule);
49
+ //# sourceMappingURL=bugg-lens.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.module.js","sourceRoot":"","sources":["../bugg-lens.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,2CAAwD;AAE3C,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAOtC,IAAM,cAAc,sBAApB,MAAM,cAAc;IAEvB,MAAM,CAAC,OAAO,CAAC,OAA8B;QAEzC,MAAM,gBAAgB,GAAG;YACrB,OAAO,EAAE,iBAAS;YAClB,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,oBAAQ,CAAC,OAAO,CAAC;SAC1C,CAAC;QAEF,OAAO;YACH,MAAM,EAAE,gBAAc;YACtB,SAAS,EAAE,CAAC,gBAAgB,CAAC;YAC7B,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,MAAM,EAAE,IAAI;SACf,CAAC;IACN,CAAC;IAED,YACwC,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;IAG1D,CAAC;IAED,KAAK,CAAC,YAAY;QACd,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,eAAe;QACjB,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AA9BY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;IAmBF,WAAA,IAAA,eAAM,EAAC,iBAAS,CAAC,CAAA;qCAA4B,oBAAQ;GAlBjD,cAAc,CA8B1B"}
@@ -0,0 +1,27 @@
1
+ export interface Frame {
2
+ file: string;
3
+ line: number;
4
+ column: number;
5
+ message: string;
6
+ type: string;
7
+ name: string;
8
+ stack: string;
9
+ occurredAt: Date;
10
+ }
11
+ export interface SourceContext {
12
+ file: string;
13
+ line: number;
14
+ column: number;
15
+ startLine: number;
16
+ endLine: number;
17
+ code: string;
18
+ preContext: string[];
19
+ postContext: string[];
20
+ message: string;
21
+ type: string;
22
+ name: string;
23
+ stack: string;
24
+ occurredAt: Date;
25
+ }
26
+ export declare function getSourceContext(frame: Frame): Promise<SourceContext>;
27
+ //# sourceMappingURL=bugg-lens.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.util.d.ts","sourceRoot":"","sources":["../bugg-lens.util.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,KAAK;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,IAAI,CAAA;CACnB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,IAAI,CAAA;CACnB;AAMD,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,CAG3E"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getSourceContext = getSourceContext;
40
+ const fs = __importStar(require("node:fs"));
41
+ const path = __importStar(require("node:path"));
42
+ const piscina_1 = __importDefault(require("piscina"));
43
+ const WORKER_PATH = path.resolve(__dirname, 'bugg-lens.worker.js');
44
+ const pool = new piscina_1.default({ filename: WORKER_PATH, maxThreads: 4 });
45
+ async function getSourceContext(frame) {
46
+ const source = await fs.promises.readFile(frame.file, 'utf8');
47
+ return pool.run({ ...frame, source });
48
+ }
49
+ //# sourceMappingURL=bugg-lens.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.util.js","sourceRoot":"","sources":["../bugg-lens.util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,4CAGC;AAvCD,4CAA8B;AAC9B,gDAAkC;AAElC,sDAA8B;AA6B9B,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AAEnE,MAAM,IAAI,GAAG,IAAI,iBAAO,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAA;AAE3D,KAAK,UAAU,gBAAgB,CAAC,KAAY;IAC/C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Frame, SourceContext } from './bugg-lens.util';
2
+ interface WorkerInput extends Frame {
3
+ source: string;
4
+ }
5
+ declare function worker(input: WorkerInput): SourceContext;
6
+ export = worker;
7
+ //# sourceMappingURL=bugg-lens.worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.worker.d.ts","sourceRoot":"","sources":["../bugg-lens.worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE7D,UAAU,WAAY,SAAQ,KAAK;IAC/B,MAAM,EAAE,MAAM,CAAC;CAClB;AAeD,iBAAS,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CAyCjD;AAED,SAAS,MAAM,CAAC"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ const ts = __importStar(require("typescript"));
36
+ function findNode(node, pos) {
37
+ let result = node;
38
+ node.forEachChild(child => {
39
+ if (pos >= child.getFullStart() && pos <= child.getEnd()) {
40
+ result = findNode(child, pos);
41
+ }
42
+ });
43
+ return result;
44
+ }
45
+ function worker(input) {
46
+ const { source, ...frame } = input;
47
+ const sourceFile = ts.createSourceFile(frame.file, source, ts.ScriptTarget.Latest, true);
48
+ const pos = ts.getPositionOfLineAndCharacter(sourceFile, frame.line - 1, frame.column - 1);
49
+ let node = findNode(sourceFile, pos);
50
+ while (node.parent && !ts.isStatement(node)) {
51
+ node = node.parent;
52
+ }
53
+ const startLine = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
54
+ const endLine = sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line + 1;
55
+ const lines = source.split('\n');
56
+ return {
57
+ file: frame.file,
58
+ line: frame.line,
59
+ column: frame.column,
60
+ startLine,
61
+ endLine,
62
+ code: lines.slice(startLine - 1, endLine).join('\n'),
63
+ preContext: lines.slice(Math.max(0, startLine - 4), startLine - 1),
64
+ postContext: lines.slice(endLine, Math.min(lines.length, endLine + 3)),
65
+ message: frame.message,
66
+ stack: frame.stack,
67
+ type: frame.type,
68
+ name: frame.name,
69
+ occurredAt: frame.occurredAt
70
+ };
71
+ }
72
+ module.exports = worker;
73
+ //# sourceMappingURL=bugg-lens.worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bugg-lens.worker.js","sourceRoot":"","sources":["../bugg-lens.worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAOjC,SAAS,QAAQ,CAAC,IAAa,EAAE,GAAW;IACxC,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QACtB,IAAI,GAAG,IAAI,KAAK,CAAC,YAAY,EAAE,IAAI,GA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CAAC,SAAS,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACpD,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC;QAClE,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;QACtE,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,UAAU,EAAE,KAAK,CAAC,UAAU;KAC/B,CAAC;AACN,CAAC;AAED,iBAAS,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './bugg-lens';
2
+ export * from './bugg-lens.module';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bugg-lens"), exports);
18
+ __exportStar(require("./bugg-lens.module"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,qDAAmC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "bugg-lens-nestjs",
3
+ "version": "0.1.0",
4
+ "description": "NestJS integration for Bugg Lens.",
5
+ "license": "MIT",
6
+ "author": "",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": ""
10
+ },
11
+ "bugs": {
12
+ "url": ""
13
+ },
14
+ "homepage": "",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.json",
24
+ "clean": "rm -rf dist",
25
+ "prepack": "npm run build",
26
+ "test": "npm run build && node smoke-test.cjs"
27
+ },
28
+ "keywords": [
29
+ "bugg-lens",
30
+ "nestjs",
31
+ "errors",
32
+ "monitoring"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {
38
+ "axios": "^1.18.0",
39
+ "piscina": "^4.6.1",
40
+ "typescript": "^5.5.0"
41
+ },
42
+ "peerDependencies": {
43
+ "@nestjs/common": "^10.0.0 || ^11.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@nestjs/common": "^10.0.0",
47
+ "@types/node": "^20.0.0"
48
+ }
49
+ }