@ngn-net/nestjs-telescope 0.2.2 → 0.2.3
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/telescope.module.js +18 -0
- package/dist/ui/manifest.json +2 -2
- package/dist/watchers/http-service.watcher.d.ts +14 -0
- package/dist/watchers/http-service.watcher.js +95 -0
- package/dist/watchers/model.subscriber.d.ts +14 -0
- package/dist/watchers/model.subscriber.js +70 -0
- package/package.json +1 -1
package/dist/telescope.module.js
CHANGED
|
@@ -33,11 +33,13 @@ const mail_watcher_1 = require("./watchers/mail.watcher");
|
|
|
33
33
|
const log_watcher_1 = require("./watchers/log.watcher");
|
|
34
34
|
const exception_watcher_1 = require("./watchers/exception.watcher");
|
|
35
35
|
const schedule_watcher_1 = require("./watchers/schedule.watcher");
|
|
36
|
+
const http_service_watcher_1 = require("./watchers/http-service.watcher");
|
|
36
37
|
const redis_watcher_1 = require("./watchers/redis.watcher");
|
|
37
38
|
const telescope_jwt_guard_1 = require("./guards/telescope-jwt.guard");
|
|
38
39
|
const command_watcher_1 = require("./watchers/command.watcher");
|
|
39
40
|
const model_watcher_1 = require("./watchers/model.watcher");
|
|
40
41
|
const notification_watcher_1 = require("./watchers/notification.watcher");
|
|
42
|
+
const gate_watcher_1 = require("./watchers/gate.watcher");
|
|
41
43
|
const constants_1 = require("./constants");
|
|
42
44
|
const entry_type_enum_1 = require("./enums/entry-type.enum");
|
|
43
45
|
let TelescopeModule = TelescopeModule_1 = class TelescopeModule {
|
|
@@ -233,6 +235,22 @@ let TelescopeModule = TelescopeModule_1 = class TelescopeModule {
|
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
}
|
|
238
|
+
// Additional optional watchers (non-interceptors)
|
|
239
|
+
if (!options.enabledEntryTypes || options.enabledEntryTypes.includes(entry_type_enum_1.EntryType.HTTP_CLIENT)) {
|
|
240
|
+
providers.push(http_service_watcher_1.HttpServiceWatcher);
|
|
241
|
+
}
|
|
242
|
+
if (!options.enabledEntryTypes || options.enabledEntryTypes.includes(entry_type_enum_1.EntryType.COMMAND)) {
|
|
243
|
+
providers.push(command_watcher_1.CommandWatcher);
|
|
244
|
+
}
|
|
245
|
+
if (!options.enabledEntryTypes || options.enabledEntryTypes.includes(entry_type_enum_1.EntryType.MODEL)) {
|
|
246
|
+
providers.push(model_watcher_1.ModelWatcher);
|
|
247
|
+
}
|
|
248
|
+
if (!options.enabledEntryTypes || options.enabledEntryTypes.includes(entry_type_enum_1.EntryType.NOTIFICATION)) {
|
|
249
|
+
providers.push(notification_watcher_1.NotificationWatcher);
|
|
250
|
+
}
|
|
251
|
+
if (!options.enabledEntryTypes || options.enabledEntryTypes.includes(entry_type_enum_1.EntryType.GATE)) {
|
|
252
|
+
providers.push(gate_watcher_1.GateWatcher);
|
|
253
|
+
}
|
|
236
254
|
// 2. CacheWatcher
|
|
237
255
|
try {
|
|
238
256
|
require('@nestjs/cache-manager');
|
package/dist/ui/manifest.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { TelescopeService } from '../telescope.service';
|
|
3
|
+
import { TelescopeOptions } from '../interfaces/telescope-options.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Watches outbound HTTP requests made via NestJS's HttpService (axios based).
|
|
6
|
+
* It patches the HttpService prototype methods to record request/response data.
|
|
7
|
+
* The watcher is optional – it only activates if @nestjs/axios is installed.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpServiceWatcher implements OnModuleInit {
|
|
10
|
+
private readonly telescope;
|
|
11
|
+
private readonly options?;
|
|
12
|
+
constructor(telescope: TelescopeService, options?: TelescopeOptions | undefined);
|
|
13
|
+
onModuleInit(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HttpServiceWatcher = void 0;
|
|
16
|
+
// src/watchers/http-service.watcher.ts
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const telescope_service_1 = require("../telescope.service");
|
|
19
|
+
const entry_type_enum_1 = require("../enums/entry-type.enum");
|
|
20
|
+
const constants_1 = require("../constants");
|
|
21
|
+
/**
|
|
22
|
+
* Watches outbound HTTP requests made via NestJS's HttpService (axios based).
|
|
23
|
+
* It patches the HttpService prototype methods to record request/response data.
|
|
24
|
+
* The watcher is optional – it only activates if @nestjs/axios is installed.
|
|
25
|
+
*/
|
|
26
|
+
let HttpServiceWatcher = class HttpServiceWatcher {
|
|
27
|
+
telescope;
|
|
28
|
+
options;
|
|
29
|
+
constructor(telescope, options) {
|
|
30
|
+
this.telescope = telescope;
|
|
31
|
+
this.options = options;
|
|
32
|
+
}
|
|
33
|
+
onModuleInit() {
|
|
34
|
+
try {
|
|
35
|
+
const { HttpService } = require('@nestjs/axios');
|
|
36
|
+
const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
37
|
+
for (const method of methods) {
|
|
38
|
+
if (typeof HttpService.prototype[method] !== 'function')
|
|
39
|
+
continue;
|
|
40
|
+
const original = HttpService.prototype[method];
|
|
41
|
+
const self = this;
|
|
42
|
+
HttpService.prototype[method] = async function (...args) {
|
|
43
|
+
const url = args[0];
|
|
44
|
+
const config = args[1] ?? {};
|
|
45
|
+
const start = Date.now();
|
|
46
|
+
try {
|
|
47
|
+
const response = await original.apply(this, args);
|
|
48
|
+
const duration = Date.now() - start;
|
|
49
|
+
// Record successful request
|
|
50
|
+
self.telescope
|
|
51
|
+
.record({
|
|
52
|
+
type: entry_type_enum_1.EntryType.HTTP_CLIENT,
|
|
53
|
+
content: {
|
|
54
|
+
method: method.toUpperCase(),
|
|
55
|
+
url,
|
|
56
|
+
requestConfig: config,
|
|
57
|
+
responseStatus: response?.status,
|
|
58
|
+
responseData: response?.data,
|
|
59
|
+
duration,
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
.catch(() => { });
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
const duration = Date.now() - start;
|
|
67
|
+
self.telescope
|
|
68
|
+
.record({
|
|
69
|
+
type: entry_type_enum_1.EntryType.HTTP_CLIENT,
|
|
70
|
+
content: {
|
|
71
|
+
method: method.toUpperCase(),
|
|
72
|
+
url,
|
|
73
|
+
requestConfig: config,
|
|
74
|
+
error: err?.message,
|
|
75
|
+
duration,
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
.catch(() => { });
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
// @nestjs/axios not installed – watcher remains inactive.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.HttpServiceWatcher = HttpServiceWatcher;
|
|
90
|
+
exports.HttpServiceWatcher = HttpServiceWatcher = __decorate([
|
|
91
|
+
(0, common_1.Injectable)(),
|
|
92
|
+
__param(1, (0, common_1.Inject)(constants_1.TELESCOPE_OPTIONS)),
|
|
93
|
+
__param(1, (0, common_1.Optional)()),
|
|
94
|
+
__metadata("design:paramtypes", [telescope_service_1.TelescopeService, Object])
|
|
95
|
+
], HttpServiceWatcher);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntitySubscriberInterface, InsertEvent, UpdateEvent, RemoveEvent } from 'typeorm';
|
|
2
|
+
import { TelescopeService } from '../telescope.service';
|
|
3
|
+
/**
|
|
4
|
+
* Subscribes to TypeORM entity lifecycle events and records them.
|
|
5
|
+
* This watcher is automatically registered when TypeORM is present.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ModelSubscriber implements EntitySubscriberInterface {
|
|
8
|
+
private readonly telescope;
|
|
9
|
+
constructor(telescope: TelescopeService);
|
|
10
|
+
listenTo(): ObjectConstructor;
|
|
11
|
+
afterInsert(event: InsertEvent<any>): void;
|
|
12
|
+
afterUpdate(event: UpdateEvent<any>): void;
|
|
13
|
+
afterRemove(event: RemoveEvent<any>): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ModelSubscriber = void 0;
|
|
13
|
+
// src/watchers/model.subscriber.ts
|
|
14
|
+
const typeorm_1 = require("typeorm");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const telescope_service_1 = require("../telescope.service");
|
|
17
|
+
const entry_type_enum_1 = require("../enums/entry-type.enum");
|
|
18
|
+
/**
|
|
19
|
+
* Subscribes to TypeORM entity lifecycle events and records them.
|
|
20
|
+
* This watcher is automatically registered when TypeORM is present.
|
|
21
|
+
*/
|
|
22
|
+
let ModelSubscriber = class ModelSubscriber {
|
|
23
|
+
telescope;
|
|
24
|
+
constructor(telescope) {
|
|
25
|
+
this.telescope = telescope;
|
|
26
|
+
}
|
|
27
|
+
listenTo() {
|
|
28
|
+
// Listen to all entities
|
|
29
|
+
return Object;
|
|
30
|
+
}
|
|
31
|
+
afterInsert(event) {
|
|
32
|
+
this.telescope.record({
|
|
33
|
+
type: entry_type_enum_1.EntryType.MODEL,
|
|
34
|
+
content: {
|
|
35
|
+
action: 'insert',
|
|
36
|
+
entity: event.metadata.name,
|
|
37
|
+
primaryKey: event.entity?.id ?? null,
|
|
38
|
+
data: event.entity,
|
|
39
|
+
},
|
|
40
|
+
}).catch(() => { });
|
|
41
|
+
}
|
|
42
|
+
afterUpdate(event) {
|
|
43
|
+
this.telescope.record({
|
|
44
|
+
type: entry_type_enum_1.EntryType.MODEL,
|
|
45
|
+
content: {
|
|
46
|
+
action: 'update',
|
|
47
|
+
entity: event.metadata.name,
|
|
48
|
+
primaryKey: event.entity?.id ?? null,
|
|
49
|
+
updatedColumns: event.updatedColumns.map(col => col.propertyName),
|
|
50
|
+
data: event.entity,
|
|
51
|
+
},
|
|
52
|
+
}).catch(() => { });
|
|
53
|
+
}
|
|
54
|
+
afterRemove(event) {
|
|
55
|
+
this.telescope.record({
|
|
56
|
+
type: entry_type_enum_1.EntryType.MODEL,
|
|
57
|
+
content: {
|
|
58
|
+
action: 'remove',
|
|
59
|
+
entity: event.metadata.name,
|
|
60
|
+
primaryKey: event.entityId,
|
|
61
|
+
},
|
|
62
|
+
}).catch(() => { });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports.ModelSubscriber = ModelSubscriber;
|
|
66
|
+
exports.ModelSubscriber = ModelSubscriber = __decorate([
|
|
67
|
+
(0, typeorm_1.EventSubscriber)(),
|
|
68
|
+
(0, common_1.Injectable)(),
|
|
69
|
+
__metadata("design:paramtypes", [telescope_service_1.TelescopeService])
|
|
70
|
+
], ModelSubscriber);
|