dicoshot-nest 0.2.0 → 0.2.2
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/dicoshot.constants.d.ts +1 -0
- package/dist/dicoshot.constants.js +2 -1
- package/dist/dicoshot.constants.js.map +1 -1
- package/dist/dicoshot.listener.d.ts +3 -2
- package/dist/dicoshot.listener.js +5 -4
- package/dist/dicoshot.listener.js.map +1 -1
- package/dist/dicoshot.module.d.ts +4 -2
- package/dist/dicoshot.module.js +50 -7
- package/dist/dicoshot.module.js.map +1 -1
- package/dist/dicoshot.service.d.ts +14 -0
- package/dist/dicoshot.service.js +47 -0
- package/dist/dicoshot.service.js.map +1 -0
- package/dist/filters/dicoshot-exception.filter.d.ts +13 -0
- package/dist/filters/dicoshot-exception.filter.js +124 -0
- package/dist/filters/dicoshot-exception.filter.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptors/dicoshot.interceptor.d.ts +14 -0
- package/dist/interceptors/dicoshot.interceptor.js +126 -0
- package/dist/interceptors/dicoshot.interceptor.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/throttle.util.d.ts +4 -0
- package/dist/utils/throttle.util.js +17 -0
- package/dist/utils/throttle.util.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DICOSHOT_OPTIONS = void 0;
|
|
3
|
+
exports.DICOSHOT_CLIENT = exports.DICOSHOT_OPTIONS = void 0;
|
|
4
4
|
exports.DICOSHOT_OPTIONS = 'DICOSHOT_OPTIONS';
|
|
5
|
+
exports.DICOSHOT_CLIENT = 'DICOSHOT_CLIENT';
|
|
5
6
|
//# sourceMappingURL=dicoshot.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dicoshot.constants.js","sourceRoot":"","sources":["../src/dicoshot.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"dicoshot.constants.js","sourceRoot":"","sources":["../src/dicoshot.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AACtC,QAAA,eAAe,GAAG,iBAAiB,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import type { DicoshotOptions } from 'dicoshot-core';
|
|
3
|
+
import { DicoshotClientImpl } from 'dicoshot-core';
|
|
3
4
|
export declare class DicoshotListener implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
4
5
|
private readonly options;
|
|
5
|
-
private readonly logger;
|
|
6
6
|
private readonly client;
|
|
7
|
+
private readonly logger;
|
|
7
8
|
private readonly factory;
|
|
8
|
-
constructor(options: DicoshotOptions);
|
|
9
|
+
constructor(options: DicoshotOptions, client: DicoshotClientImpl);
|
|
9
10
|
onApplicationBootstrap(): Promise<void>;
|
|
10
11
|
onApplicationShutdown(): Promise<void>;
|
|
11
12
|
}
|
|
@@ -19,12 +19,12 @@ const dicoshot_core_1 = require("dicoshot-core");
|
|
|
19
19
|
const dicoshot_constants_1 = require("./dicoshot.constants");
|
|
20
20
|
let DicoshotListener = DicoshotListener_1 = class DicoshotListener {
|
|
21
21
|
options;
|
|
22
|
-
logger = new common_1.Logger(DicoshotListener_1.name);
|
|
23
22
|
client;
|
|
23
|
+
logger = new common_1.Logger(DicoshotListener_1.name);
|
|
24
24
|
factory;
|
|
25
|
-
constructor(options) {
|
|
25
|
+
constructor(options, client) {
|
|
26
26
|
this.options = options;
|
|
27
|
-
this.client =
|
|
27
|
+
this.client = client;
|
|
28
28
|
this.factory = new dicoshot_core_1.MessageFactory(options);
|
|
29
29
|
}
|
|
30
30
|
async onApplicationBootstrap() {
|
|
@@ -56,6 +56,7 @@ exports.DicoshotListener = DicoshotListener;
|
|
|
56
56
|
exports.DicoshotListener = DicoshotListener = DicoshotListener_1 = __decorate([
|
|
57
57
|
(0, common_1.Injectable)(),
|
|
58
58
|
__param(0, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_OPTIONS)),
|
|
59
|
-
|
|
59
|
+
__param(1, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_CLIENT)),
|
|
60
|
+
__metadata("design:paramtypes", [Object, dicoshot_core_1.DicoshotClientImpl])
|
|
60
61
|
], DicoshotListener);
|
|
61
62
|
//# sourceMappingURL=dicoshot.listener.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dicoshot.listener.js","sourceRoot":"","sources":["../src/dicoshot.listener.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AAExB,iDAAmE;AACnE,
|
|
1
|
+
{"version":3,"file":"dicoshot.listener.js","sourceRoot":"","sources":["../src/dicoshot.listener.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AAExB,iDAAmE;AACnE,6DAAyE;AAGlE,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAOkB;IACD;IAL3B,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,CAAiB;IAEzC,YAC6C,OAAwB,EACzB,MAA0B;QADzB,YAAO,GAAP,OAAO,CAAiB;QACzB,WAAM,GAAN,MAAM,CAAoB;QAEpE,IAAI,CAAC,OAAO,GAAG,IAAI,8BAAc,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,KAAK;YAAE,OAAO;QACvE,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,KAAK;YAAE,OAAO;QACnD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,wCAAyC,GAAa,CAAC,OAAO,EAAE,CACjE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,KAAK;YAAE,OAAO;QACvE,IAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB,KAAK,KAAK;YAAE,OAAO;QACpD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,yCAA0C,GAAa,CAAC,OAAO,EAAE,CAClE,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AApCY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,qCAAgB,CAAC,CAAA;IACxB,WAAA,IAAA,eAAM,EAAC,oCAAe,CAAC,CAAA;6CAA0B,kCAAkB;GAR3D,gBAAgB,CAoC5B"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { DynamicModule, ModuleMetadata } from '@nestjs/common';
|
|
2
|
-
import { DicoshotOptions } from 'dicoshot-core';
|
|
2
|
+
import { DicoshotOptions, FilterOptions, InterceptorOptions } from 'dicoshot-core';
|
|
3
3
|
interface DicoshotAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
4
4
|
useFactory: (...args: unknown[]) => Promise<DicoshotOptions> | DicoshotOptions;
|
|
5
5
|
inject?: unknown[];
|
|
6
|
+
filter?: boolean | FilterOptions;
|
|
7
|
+
interceptor?: boolean | InterceptorOptions;
|
|
6
8
|
}
|
|
7
9
|
export declare class DicoshotModule {
|
|
8
10
|
static register(options: DicoshotOptions): DynamicModule;
|
|
9
|
-
static registerAsync({ useFactory, inject, imports }: DicoshotAsyncOptions): DynamicModule;
|
|
11
|
+
static registerAsync({ useFactory, inject, imports, filter, interceptor, }: DicoshotAsyncOptions): DynamicModule;
|
|
10
12
|
}
|
|
11
13
|
export {};
|
package/dist/dicoshot.module.js
CHANGED
|
@@ -9,28 +9,71 @@ var DicoshotModule_1;
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.DicoshotModule = void 0;
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const dicoshot_core_1 = require("dicoshot-core");
|
|
12
14
|
const dicoshot_constants_1 = require("./dicoshot.constants");
|
|
13
15
|
const dicoshot_listener_1 = require("./dicoshot.listener");
|
|
16
|
+
const dicoshot_service_1 = require("./dicoshot.service");
|
|
17
|
+
const dicoshot_exception_filter_1 = require("./filters/dicoshot-exception.filter");
|
|
18
|
+
const dicoshot_interceptor_1 = require("./interceptors/dicoshot.interceptor");
|
|
19
|
+
const clientProvider = {
|
|
20
|
+
provide: dicoshot_constants_1.DICOSHOT_CLIENT,
|
|
21
|
+
useFactory: (options) => new dicoshot_core_1.DicoshotClientImpl(options),
|
|
22
|
+
inject: [dicoshot_constants_1.DICOSHOT_OPTIONS],
|
|
23
|
+
};
|
|
24
|
+
function buildProviders(options) {
|
|
25
|
+
const providers = [
|
|
26
|
+
{ provide: dicoshot_constants_1.DICOSHOT_OPTIONS, useValue: options },
|
|
27
|
+
clientProvider,
|
|
28
|
+
dicoshot_listener_1.DicoshotListener,
|
|
29
|
+
dicoshot_service_1.DicoshotService,
|
|
30
|
+
];
|
|
31
|
+
if (options.filter) {
|
|
32
|
+
providers.push({ provide: core_1.APP_FILTER, useClass: dicoshot_exception_filter_1.DicoshotExceptionFilter });
|
|
33
|
+
}
|
|
34
|
+
if (options.interceptor) {
|
|
35
|
+
providers.push({ provide: core_1.APP_INTERCEPTOR, useClass: dicoshot_interceptor_1.DicoshotInterceptor });
|
|
36
|
+
}
|
|
37
|
+
return providers;
|
|
38
|
+
}
|
|
14
39
|
let DicoshotModule = DicoshotModule_1 = class DicoshotModule {
|
|
15
40
|
static register(options) {
|
|
16
41
|
return {
|
|
17
42
|
module: DicoshotModule_1,
|
|
18
|
-
providers:
|
|
19
|
-
|
|
20
|
-
dicoshot_listener_1.DicoshotListener,
|
|
21
|
-
],
|
|
43
|
+
providers: buildProviders(options),
|
|
44
|
+
exports: [dicoshot_service_1.DicoshotService],
|
|
22
45
|
};
|
|
23
46
|
}
|
|
24
|
-
static registerAsync({ useFactory, inject, imports }) {
|
|
47
|
+
static registerAsync({ useFactory, inject, imports, filter, interceptor, }) {
|
|
25
48
|
const optionsProvider = {
|
|
26
49
|
provide: dicoshot_constants_1.DICOSHOT_OPTIONS,
|
|
27
|
-
useFactory
|
|
50
|
+
useFactory: async (...args) => {
|
|
51
|
+
const opts = await useFactory(...args);
|
|
52
|
+
return {
|
|
53
|
+
...opts,
|
|
54
|
+
...(filter !== undefined && { filter }),
|
|
55
|
+
...(interceptor !== undefined && { interceptor }),
|
|
56
|
+
};
|
|
57
|
+
},
|
|
28
58
|
inject: inject ?? [],
|
|
29
59
|
};
|
|
60
|
+
const providers = [
|
|
61
|
+
optionsProvider,
|
|
62
|
+
clientProvider,
|
|
63
|
+
dicoshot_listener_1.DicoshotListener,
|
|
64
|
+
dicoshot_service_1.DicoshotService,
|
|
65
|
+
];
|
|
66
|
+
if (filter) {
|
|
67
|
+
providers.push({ provide: core_1.APP_FILTER, useClass: dicoshot_exception_filter_1.DicoshotExceptionFilter });
|
|
68
|
+
}
|
|
69
|
+
if (interceptor) {
|
|
70
|
+
providers.push({ provide: core_1.APP_INTERCEPTOR, useClass: dicoshot_interceptor_1.DicoshotInterceptor });
|
|
71
|
+
}
|
|
30
72
|
return {
|
|
31
73
|
module: DicoshotModule_1,
|
|
32
74
|
imports: imports ?? [],
|
|
33
|
-
providers
|
|
75
|
+
providers,
|
|
76
|
+
exports: [dicoshot_service_1.DicoshotService],
|
|
34
77
|
};
|
|
35
78
|
}
|
|
36
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dicoshot.module.js","sourceRoot":"","sources":["../src/dicoshot.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"dicoshot.module.js","sourceRoot":"","sources":["../src/dicoshot.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAKwB;AACxB,uCAA2D;AAC3D,iDAAuG;AACvG,6DAAyE;AACzE,2DAAuD;AACvD,yDAAqD;AACrD,mFAA8E;AAC9E,8EAA0E;AAmB1E,MAAM,cAAc,GAAa;IAC/B,OAAO,EAAE,oCAAe;IACxB,UAAU,EAAE,CAAC,OAAwB,EAAE,EAAE,CAAC,IAAI,kCAAkB,CAAC,OAAO,CAAC;IACzE,MAAM,EAAE,CAAC,qCAAgB,CAAC;CAC3B,CAAC;AAEF,SAAS,cAAc,CAAC,OAAwB;IAC9C,MAAM,SAAS,GAAe;QAC5B,EAAE,OAAO,EAAE,qCAAgB,EAAE,QAAQ,EAAE,OAAO,EAAE;QAChD,cAAc;QACd,oCAAgB;QAChB,kCAAe;KAChB,CAAC;IAEF,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,iBAAU,EAAE,QAAQ,EAAE,mDAAuB,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,sBAAe,EAAE,QAAQ,EAAE,0CA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YACtB,SAAS;YACT,OAAO,EAAE,CAAC,kCAAe,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF,CAAA;AApDY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CAoD1B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DiscordMessage } from 'dicoshot-core';
|
|
2
|
+
import { DicoshotClientImpl } from 'dicoshot-core';
|
|
3
|
+
export type ColorPreset = 'success' | 'danger' | 'warning' | 'info';
|
|
4
|
+
export interface CustomMessageOptions {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
color?: ColorPreset | number;
|
|
8
|
+
}
|
|
9
|
+
export declare class DicoshotService {
|
|
10
|
+
private readonly client;
|
|
11
|
+
constructor(client: DicoshotClientImpl);
|
|
12
|
+
send(message: DiscordMessage): Promise<void>;
|
|
13
|
+
sendCustom({ title, description, color }: CustomMessageOptions): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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.DicoshotService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const dicoshot_core_1 = require("dicoshot-core");
|
|
18
|
+
const dicoshot_constants_1 = require("./dicoshot.constants");
|
|
19
|
+
const COLOR_MAP = {
|
|
20
|
+
success: 0x57f287,
|
|
21
|
+
danger: 0xed4245,
|
|
22
|
+
warning: 0xfee75c,
|
|
23
|
+
info: 0x5865f2,
|
|
24
|
+
};
|
|
25
|
+
let DicoshotService = class DicoshotService {
|
|
26
|
+
client;
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client;
|
|
29
|
+
}
|
|
30
|
+
async send(message) {
|
|
31
|
+
await this.client.send(message);
|
|
32
|
+
}
|
|
33
|
+
async sendCustom({ title, description, color }) {
|
|
34
|
+
const resolvedColor = typeof color === 'string' ? COLOR_MAP[color] : color;
|
|
35
|
+
const message = {
|
|
36
|
+
embeds: [{ title, description, color: resolvedColor }],
|
|
37
|
+
};
|
|
38
|
+
await this.client.send(message);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.DicoshotService = DicoshotService;
|
|
42
|
+
exports.DicoshotService = DicoshotService = __decorate([
|
|
43
|
+
(0, common_1.Injectable)(),
|
|
44
|
+
__param(0, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_CLIENT)),
|
|
45
|
+
__metadata("design:paramtypes", [dicoshot_core_1.DicoshotClientImpl])
|
|
46
|
+
], DicoshotService);
|
|
47
|
+
//# sourceMappingURL=dicoshot.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.service.js","sourceRoot":"","sources":["../src/dicoshot.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,iDAAmD;AACnD,6DAAuD;AAUvD,MAAM,SAAS,GAAgC;IAC7C,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,QAAQ;CACf,CAAC;AAGK,IAAM,eAAe,GAArB,MAAM,eAAe;IAEkB;IAD5C,YAC4C,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IACnE,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAwB;QAClE,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAE3E,MAAM,OAAO,GAAmB;YAC9B,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;SACvD,CAAC;QACF,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;CACF,CAAA;AAjBY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,oCAAe,CAAC,CAAA;qCAA0B,kCAAkB;GAF3D,eAAe,CAiB3B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import type { DicoshotOptions } from 'dicoshot-core';
|
|
3
|
+
import { DicoshotClientImpl } from 'dicoshot-core';
|
|
4
|
+
export declare class DicoshotExceptionFilter implements ExceptionFilter {
|
|
5
|
+
private readonly client;
|
|
6
|
+
private readonly options;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(client: DicoshotClientImpl, options: DicoshotOptions);
|
|
9
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
10
|
+
private resolveOptions;
|
|
11
|
+
private shouldNotify;
|
|
12
|
+
private notify;
|
|
13
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 DicoshotExceptionFilter_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.DicoshotExceptionFilter = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const dicoshot_core_1 = require("dicoshot-core");
|
|
19
|
+
const dicoshot_constants_1 = require("../dicoshot.constants");
|
|
20
|
+
const throttle_util_1 = require("../utils/throttle.util");
|
|
21
|
+
const ERROR_COLOR = 0xed4245;
|
|
22
|
+
let DicoshotExceptionFilter = DicoshotExceptionFilter_1 = class DicoshotExceptionFilter {
|
|
23
|
+
client;
|
|
24
|
+
options;
|
|
25
|
+
logger = new common_1.Logger(DicoshotExceptionFilter_1.name);
|
|
26
|
+
constructor(client, options) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
this.options = options;
|
|
29
|
+
}
|
|
30
|
+
catch(exception, host) {
|
|
31
|
+
if (host.getType() !== 'http')
|
|
32
|
+
return;
|
|
33
|
+
const ctx = host.switchToHttp();
|
|
34
|
+
const response = ctx.getResponse();
|
|
35
|
+
const request = ctx.getRequest();
|
|
36
|
+
const status = exception instanceof common_1.HttpException ? exception.getStatus() : 500;
|
|
37
|
+
if (this.options.filter) {
|
|
38
|
+
const opts = this.resolveOptions();
|
|
39
|
+
if (this.shouldNotify(exception, request, status, opts)) {
|
|
40
|
+
this.notify(exception, request, status, opts).catch((err) => this.logger.warn(`Failed to send exception notification: ${err.message}`));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const body = exception instanceof common_1.HttpException
|
|
44
|
+
? exception.getResponse()
|
|
45
|
+
: { statusCode: status, message: 'Internal server error' };
|
|
46
|
+
response.status(status).json(body);
|
|
47
|
+
}
|
|
48
|
+
resolveOptions() {
|
|
49
|
+
const filter = this.options.filter;
|
|
50
|
+
if (!filter || filter === true)
|
|
51
|
+
return {};
|
|
52
|
+
return filter;
|
|
53
|
+
}
|
|
54
|
+
shouldNotify(exception, request, status, opts) {
|
|
55
|
+
if (opts.ignore?.includes(status))
|
|
56
|
+
return false;
|
|
57
|
+
if (opts.environment) {
|
|
58
|
+
const envs = Array.isArray(opts.environment) ? opts.environment : [opts.environment];
|
|
59
|
+
if (!envs.includes(process.env.NODE_ENV ?? 'development'))
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (opts.throttle) {
|
|
63
|
+
const name = exception instanceof Error ? exception.constructor.name : 'Error';
|
|
64
|
+
const key = `${name}_${request.method}_${request.path}`;
|
|
65
|
+
if (throttle_util_1.ThrottleUtil.shouldThrottle(key, opts.throttle))
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
async notify(exception, request, status, opts) {
|
|
71
|
+
const webhookUrl = this.options.webhooks?.error ?? this.options.webhookUrl;
|
|
72
|
+
if (!webhookUrl) {
|
|
73
|
+
this.logger.warn('No error webhook URL configured; skipping Discord notification');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const env = process.env.NODE_ENV ?? 'development';
|
|
77
|
+
const appName = this.options.applicationName ?? 'Unknown';
|
|
78
|
+
const errorName = exception instanceof Error ? exception.constructor.name : 'UnknownError';
|
|
79
|
+
const errorMessage = exception instanceof Error ? exception.message : String(exception);
|
|
80
|
+
const stack = exception instanceof Error ? exception.stack : undefined;
|
|
81
|
+
const now = new Date().toISOString();
|
|
82
|
+
const fields = [
|
|
83
|
+
{ name: 'Service', value: appName, inline: true },
|
|
84
|
+
{ name: 'Environment', value: env, inline: true },
|
|
85
|
+
{ name: 'Status', value: String(status), inline: true },
|
|
86
|
+
{ name: 'Method', value: request.method, inline: true },
|
|
87
|
+
{ name: 'Path', value: request.path, inline: true },
|
|
88
|
+
];
|
|
89
|
+
if (opts.includeRequest !== false) {
|
|
90
|
+
const body = request.body;
|
|
91
|
+
if (body && typeof body === 'object' && Object.keys(body).length > 0) {
|
|
92
|
+
fields.push({
|
|
93
|
+
name: 'Request Body',
|
|
94
|
+
value: `\`\`\`json\n${JSON.stringify(body).slice(0, 900)}\n\`\`\``,
|
|
95
|
+
inline: false,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (opts.includeStack !== false && stack) {
|
|
100
|
+
fields.push({
|
|
101
|
+
name: 'Stack Trace',
|
|
102
|
+
value: `\`\`\`\n${stack.slice(0, 1000)}\n\`\`\``,
|
|
103
|
+
inline: false,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const mention = opts.mention ? `\n${opts.mention}` : '';
|
|
107
|
+
const embed = {
|
|
108
|
+
title: `🚨 [${env}] ${appName} — ${errorName}`,
|
|
109
|
+
description: `\`${errorMessage}\`${mention}`,
|
|
110
|
+
color: ERROR_COLOR,
|
|
111
|
+
fields,
|
|
112
|
+
timestamp: now,
|
|
113
|
+
};
|
|
114
|
+
await this.client.sendTo(webhookUrl, { username: this.options.username, embeds: [embed] });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.DicoshotExceptionFilter = DicoshotExceptionFilter;
|
|
118
|
+
exports.DicoshotExceptionFilter = DicoshotExceptionFilter = DicoshotExceptionFilter_1 = __decorate([
|
|
119
|
+
(0, common_1.Catch)(),
|
|
120
|
+
__param(0, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_CLIENT)),
|
|
121
|
+
__param(1, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_OPTIONS)),
|
|
122
|
+
__metadata("design:paramtypes", [dicoshot_core_1.DicoshotClientImpl, Object])
|
|
123
|
+
], DicoshotExceptionFilter);
|
|
124
|
+
//# sourceMappingURL=dicoshot-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot-exception.filter.js","sourceRoot":"","sources":["../../src/filters/dicoshot-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAOwB;AAGxB,iDAAmD;AACnD,8DAA0E;AAC1E,0DAAsD;AAEtD,MAAM,WAAW,GAAG,QAAQ,CAAC;AAGtB,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAIU;IACC;IAJ5B,MAAM,GAAG,IAAI,eAAM,CAAC,yBAAuB,CAAC,IAAI,CAAC,CAAC;IAEnE,YAC4C,MAA0B,EACzB,OAAwB;QADzB,WAAM,GAAN,MAAM,CAAoB;QACzB,YAAO,GAAP,OAAO,CAAiB;IAClE,CAAC;IAEJ,KAAK,CAAC,SAAkB,EAAE,IAAmB;QAE3C,IAAI,IAAI,CAAC,OAAO,EAAU,KAAK,MAAM;YAAE,OAAO;QAE9C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAE1C,MAAM,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,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,IAAI,KAAK,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,aAAa;gBACnB,KAAK,EAAE,WAAW,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU;gBAChD,MAAM,EAAE,KAAK;aACd,CAAC,CAAC;QACL,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAExD,MAAM,KAAK,GAAiB;YAC1B,KAAK,EAAE,OAAO,GAAG,KAAK,OAAO,MAAM,SAAS,EAAE;YAC9C,WAAW,EAAE,KAAK,YAAY,KAAK,OAAO,EAAE;YAC5C,KAAK,EAAE,WAAW;YAClB,MAAM;YACN,SAAS,EAAE,GAAG;SACf,CAAC;QAEF,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC7F,CAAC;CACF,CAAA;AA1HY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,cAAK,GAAE;IAKH,WAAA,IAAA,eAAM,EAAC,oCAAe,CAAC,CAAA;IACvB,WAAA,IAAA,eAAM,EAAC,qCAAgB,CAAC,CAAA;qCADyB,kCAAkB;GAJ3D,uBAAuB,CA0HnC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export { DicoshotModule } from './dicoshot.module';
|
|
2
2
|
export { DicoshotListener } from './dicoshot.listener';
|
|
3
|
+
export { DicoshotService } from './dicoshot.service';
|
|
4
|
+
export { DicoshotExceptionFilter } from './filters/dicoshot-exception.filter';
|
|
5
|
+
export { DicoshotInterceptor } from './interceptors/dicoshot.interceptor';
|
|
3
6
|
export { DICOSHOT_OPTIONS } from './dicoshot.constants';
|
|
4
|
-
export type { DicoshotOptions } from 'dicoshot-core';
|
|
7
|
+
export type { DicoshotOptions, FilterOptions, InterceptorOptions, DicoshotWebhooks, RetryOptions } from 'dicoshot-core';
|
|
8
|
+
export type { CustomMessageOptions, ColorPreset } from './dicoshot.service';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DICOSHOT_OPTIONS = exports.DicoshotListener = exports.DicoshotModule = void 0;
|
|
3
|
+
exports.DICOSHOT_OPTIONS = exports.DicoshotInterceptor = exports.DicoshotExceptionFilter = exports.DicoshotService = exports.DicoshotListener = exports.DicoshotModule = void 0;
|
|
4
4
|
var dicoshot_module_1 = require("./dicoshot.module");
|
|
5
5
|
Object.defineProperty(exports, "DicoshotModule", { enumerable: true, get: function () { return dicoshot_module_1.DicoshotModule; } });
|
|
6
6
|
var dicoshot_listener_1 = require("./dicoshot.listener");
|
|
7
7
|
Object.defineProperty(exports, "DicoshotListener", { enumerable: true, get: function () { return dicoshot_listener_1.DicoshotListener; } });
|
|
8
|
+
var dicoshot_service_1 = require("./dicoshot.service");
|
|
9
|
+
Object.defineProperty(exports, "DicoshotService", { enumerable: true, get: function () { return dicoshot_service_1.DicoshotService; } });
|
|
10
|
+
var dicoshot_exception_filter_1 = require("./filters/dicoshot-exception.filter");
|
|
11
|
+
Object.defineProperty(exports, "DicoshotExceptionFilter", { enumerable: true, get: function () { return dicoshot_exception_filter_1.DicoshotExceptionFilter; } });
|
|
12
|
+
var dicoshot_interceptor_1 = require("./interceptors/dicoshot.interceptor");
|
|
13
|
+
Object.defineProperty(exports, "DicoshotInterceptor", { enumerable: true, get: function () { return dicoshot_interceptor_1.DicoshotInterceptor; } });
|
|
8
14
|
var dicoshot_constants_1 = require("./dicoshot.constants");
|
|
9
15
|
Object.defineProperty(exports, "DICOSHOT_OPTIONS", { enumerable: true, get: function () { return dicoshot_constants_1.DICOSHOT_OPTIONS; } });
|
|
10
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,iFAA8E;AAArE,oIAAA,uBAAuB,OAAA;AAChC,4EAA0E;AAAjE,2HAAA,mBAAmB,OAAA;AAC5B,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import type { DicoshotOptions } from 'dicoshot-core';
|
|
4
|
+
import { DicoshotClientImpl } from 'dicoshot-core';
|
|
5
|
+
export declare class DicoshotInterceptor implements NestInterceptor {
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(client: DicoshotClientImpl, options: DicoshotOptions);
|
|
10
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
11
|
+
private resolveOptions;
|
|
12
|
+
private notifySlow;
|
|
13
|
+
private notifyError;
|
|
14
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 DicoshotInterceptor_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.DicoshotInterceptor = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const rxjs_1 = require("rxjs");
|
|
19
|
+
const operators_1 = require("rxjs/operators");
|
|
20
|
+
const dicoshot_core_1 = require("dicoshot-core");
|
|
21
|
+
const dicoshot_constants_1 = require("../dicoshot.constants");
|
|
22
|
+
const SLOW_COLOR = 0xfee75c;
|
|
23
|
+
const ERROR_COLOR = 0xed4245;
|
|
24
|
+
let DicoshotInterceptor = DicoshotInterceptor_1 = class DicoshotInterceptor {
|
|
25
|
+
client;
|
|
26
|
+
options;
|
|
27
|
+
logger = new common_1.Logger(DicoshotInterceptor_1.name);
|
|
28
|
+
constructor(client, options) {
|
|
29
|
+
this.client = client;
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
intercept(context, next) {
|
|
33
|
+
if (!this.options.interceptor)
|
|
34
|
+
return next.handle();
|
|
35
|
+
const start = Date.now();
|
|
36
|
+
const request = context.switchToHttp().getRequest();
|
|
37
|
+
const opts = this.resolveOptions();
|
|
38
|
+
const threshold = opts.slowThreshold ?? 3000;
|
|
39
|
+
if (opts.excludePaths?.some((p) => request.path.startsWith(p))) {
|
|
40
|
+
return next.handle();
|
|
41
|
+
}
|
|
42
|
+
return next.handle().pipe((0, operators_1.tap)(() => {
|
|
43
|
+
if (opts.onlyErrors)
|
|
44
|
+
return;
|
|
45
|
+
const duration = Date.now() - start;
|
|
46
|
+
if (duration >= threshold) {
|
|
47
|
+
this.notifySlow(request, duration).catch((err) => this.logger.warn(`Failed to send slow request notification: ${err.message}`));
|
|
48
|
+
}
|
|
49
|
+
}), (0, operators_1.catchError)((err) => {
|
|
50
|
+
if (!this.options.filter) {
|
|
51
|
+
const duration = Date.now() - start;
|
|
52
|
+
this.notifyError(request, err, duration).catch((e) => this.logger.warn(`Failed to send error notification: ${e.message}`));
|
|
53
|
+
}
|
|
54
|
+
return (0, rxjs_1.throwError)(() => err);
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
resolveOptions() {
|
|
58
|
+
const interceptor = this.options.interceptor;
|
|
59
|
+
if (!interceptor || interceptor === true)
|
|
60
|
+
return {};
|
|
61
|
+
return interceptor;
|
|
62
|
+
}
|
|
63
|
+
async notifySlow(request, duration) {
|
|
64
|
+
const webhookUrl = this.options.webhooks?.slow ?? this.options.webhookUrl;
|
|
65
|
+
if (!webhookUrl) {
|
|
66
|
+
this.logger.warn('No slow-response webhook URL configured; skipping Discord notification');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const env = process.env.NODE_ENV ?? 'development';
|
|
70
|
+
const appName = this.options.applicationName ?? 'Unknown';
|
|
71
|
+
const now = new Date().toISOString();
|
|
72
|
+
const embed = {
|
|
73
|
+
title: `🐢 [${env}] ${appName} — Slow Response`,
|
|
74
|
+
color: SLOW_COLOR,
|
|
75
|
+
fields: [
|
|
76
|
+
{ name: 'Service', value: appName, inline: true },
|
|
77
|
+
{ name: 'Environment', value: env, inline: true },
|
|
78
|
+
{ name: 'Method', value: request.method, inline: true },
|
|
79
|
+
{ name: 'Path', value: request.path, inline: true },
|
|
80
|
+
{ name: 'Duration', value: `${duration}ms`, inline: true },
|
|
81
|
+
],
|
|
82
|
+
timestamp: now,
|
|
83
|
+
};
|
|
84
|
+
await this.client.sendTo(webhookUrl, {
|
|
85
|
+
username: this.options.username,
|
|
86
|
+
embeds: [embed],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async notifyError(request, err, duration) {
|
|
90
|
+
const webhookUrl = this.options.webhooks?.error ?? this.options.webhookUrl;
|
|
91
|
+
if (!webhookUrl) {
|
|
92
|
+
this.logger.warn('No error webhook URL configured; skipping Discord notification');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const env = process.env.NODE_ENV ?? 'development';
|
|
96
|
+
const appName = this.options.applicationName ?? 'Unknown';
|
|
97
|
+
const errorName = err instanceof Error ? err.constructor.name : 'UnknownError';
|
|
98
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
99
|
+
const now = new Date().toISOString();
|
|
100
|
+
const embed = {
|
|
101
|
+
title: `🚨 [${env}] ${appName} — ${errorName}`,
|
|
102
|
+
description: `\`${errorMessage}\``,
|
|
103
|
+
color: ERROR_COLOR,
|
|
104
|
+
fields: [
|
|
105
|
+
{ name: 'Service', value: appName, inline: true },
|
|
106
|
+
{ name: 'Environment', value: env, inline: true },
|
|
107
|
+
{ name: 'Method', value: request.method, inline: true },
|
|
108
|
+
{ name: 'Path', value: request.path, inline: true },
|
|
109
|
+
{ name: 'Duration', value: `${duration}ms`, inline: true },
|
|
110
|
+
],
|
|
111
|
+
timestamp: now,
|
|
112
|
+
};
|
|
113
|
+
await this.client.sendTo(webhookUrl, {
|
|
114
|
+
username: this.options.username,
|
|
115
|
+
embeds: [embed],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.DicoshotInterceptor = DicoshotInterceptor;
|
|
120
|
+
exports.DicoshotInterceptor = DicoshotInterceptor = DicoshotInterceptor_1 = __decorate([
|
|
121
|
+
(0, common_1.Injectable)(),
|
|
122
|
+
__param(0, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_CLIENT)),
|
|
123
|
+
__param(1, (0, common_1.Inject)(dicoshot_constants_1.DICOSHOT_OPTIONS)),
|
|
124
|
+
__metadata("design:paramtypes", [dicoshot_core_1.DicoshotClientImpl, Object])
|
|
125
|
+
], DicoshotInterceptor);
|
|
126
|
+
//# sourceMappingURL=dicoshot.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dicoshot.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/dicoshot.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,+BAA8C;AAC9C,8CAAiD;AAOjD,iDAAmD;AACnD,8DAA0E;AAE1E,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,WAAW,GAAG,QAAQ,CAAC;AAGtB,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAIc;IACC;IAJ5B,MAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAE/D,YAC4C,MAA0B,EACzB,OAAwB;QADzB,WAAM,GAAN,MAAM,CAAoB;QACzB,YAAO,GAAP,OAAO,CAAiB;IAClE,CAAC;IAEJ,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAEpD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QAEpD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAW,CAAC;QAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACnC,MAAM,SAAS,G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