bozonx-social-media-posting 1.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 +21 -0
- package/README.md +1003 -0
- package/dist/src/app.constants.d.ts +8 -0
- package/dist/src/app.constants.js +9 -0
- package/dist/src/app.constants.js.map +1 -0
- package/dist/src/common/enums/body-format.enum.d.ts +12 -0
- package/dist/src/common/enums/body-format.enum.js +14 -0
- package/dist/src/common/enums/body-format.enum.js.map +1 -0
- package/dist/src/common/enums/error-code.enum.d.ts +12 -0
- package/dist/src/common/enums/error-code.enum.js +14 -0
- package/dist/src/common/enums/error-code.enum.js.map +1 -0
- package/dist/src/common/enums/index.d.ts +3 -0
- package/dist/src/common/enums/index.js +4 -0
- package/dist/src/common/enums/index.js.map +1 -0
- package/dist/src/common/enums/post-type.enum.d.ts +28 -0
- package/dist/src/common/enums/post-type.enum.js +30 -0
- package/dist/src/common/enums/post-type.enum.js.map +1 -0
- package/dist/src/common/filters/all-exceptions.filter.d.ts +13 -0
- package/dist/src/common/filters/all-exceptions.filter.js +103 -0
- package/dist/src/common/filters/all-exceptions.filter.js.map +1 -0
- package/dist/src/common/helpers/media-input.helper.d.ts +73 -0
- package/dist/src/common/helpers/media-input.helper.js +122 -0
- package/dist/src/common/helpers/media-input.helper.js.map +1 -0
- package/dist/src/common/interceptors/shutdown.interceptor.d.ts +12 -0
- package/dist/src/common/interceptors/shutdown.interceptor.js +41 -0
- package/dist/src/common/interceptors/shutdown.interceptor.js.map +1 -0
- package/dist/src/common/interfaces/logger.interface.d.ts +44 -0
- package/dist/src/common/interfaces/logger.interface.js +44 -0
- package/dist/src/common/interfaces/logger.interface.js.map +1 -0
- package/dist/src/common/services/shutdown.module.d.ts +2 -0
- package/dist/src/common/services/shutdown.module.js +18 -0
- package/dist/src/common/services/shutdown.module.js.map +1 -0
- package/dist/src/common/services/shutdown.service.d.ts +40 -0
- package/dist/src/common/services/shutdown.service.js +122 -0
- package/dist/src/common/services/shutdown.service.js.map +1 -0
- package/dist/src/common/types/index.d.ts +1 -0
- package/dist/src/common/types/index.js +2 -0
- package/dist/src/common/types/index.js.map +1 -0
- package/dist/src/common/types/media-input.type.d.ts +29 -0
- package/dist/src/common/types/media-input.type.js +2 -0
- package/dist/src/common/types/media-input.type.js.map +1 -0
- package/dist/src/common/validators/body-length.validator.d.ts +24 -0
- package/dist/src/common/validators/body-length.validator.js +57 -0
- package/dist/src/common/validators/body-length.validator.js.map +1 -0
- package/dist/src/common/validators/channel-id.validator.d.ts +19 -0
- package/dist/src/common/validators/channel-id.validator.js +58 -0
- package/dist/src/common/validators/channel-id.validator.js.map +1 -0
- package/dist/src/common/validators/has-content.validator.d.ts +23 -0
- package/dist/src/common/validators/has-content.validator.js +57 -0
- package/dist/src/common/validators/has-content.validator.js.map +1 -0
- package/dist/src/common/validators/media-input.validator.d.ts +44 -0
- package/dist/src/common/validators/media-input.validator.js +112 -0
- package/dist/src/common/validators/media-input.validator.js.map +1 -0
- package/dist/src/common/validators/media-priority.validator.d.ts +19 -0
- package/dist/src/common/validators/media-priority.validator.js +38 -0
- package/dist/src/common/validators/media-priority.validator.js.map +1 -0
- package/dist/src/config/app.config.d.ts +33 -0
- package/dist/src/config/app.config.js +83 -0
- package/dist/src/config/app.config.js.map +1 -0
- package/dist/src/config/library.config.d.ts +51 -0
- package/dist/src/config/library.config.js +197 -0
- package/dist/src/config/library.config.js.map +1 -0
- package/dist/src/config/yaml-config.dto.d.ts +37 -0
- package/dist/src/config/yaml-config.dto.js +152 -0
- package/dist/src/config/yaml-config.dto.js.map +1 -0
- package/dist/src/config/yaml.config.d.ts +14 -0
- package/dist/src/config/yaml.config.js +72 -0
- package/dist/src/config/yaml.config.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/library.d.ts +57 -0
- package/dist/src/library.js +92 -0
- package/dist/src/library.js.map +1 -0
- package/dist/src/modules/app-config/app-config.module.d.ts +2 -0
- package/dist/src/modules/app-config/app-config.module.js +26 -0
- package/dist/src/modules/app-config/app-config.module.js.map +1 -0
- package/dist/src/modules/app-config/app-config.service.d.ts +14 -0
- package/dist/src/modules/app-config/app-config.service.js +18 -0
- package/dist/src/modules/app-config/app-config.service.js.map +1 -0
- package/dist/src/modules/app-config/interfaces/app-config.interface.d.ts +31 -0
- package/dist/src/modules/app-config/interfaces/app-config.interface.js +2 -0
- package/dist/src/modules/app-config/interfaces/app-config.interface.js.map +1 -0
- package/dist/src/modules/app-config/nest-config.service.d.ts +41 -0
- package/dist/src/modules/app-config/nest-config.service.js +91 -0
- package/dist/src/modules/app-config/nest-config.service.js.map +1 -0
- package/dist/src/modules/health/health.controller.d.ts +12 -0
- package/dist/src/modules/health/health.controller.js +33 -0
- package/dist/src/modules/health/health.controller.js.map +1 -0
- package/dist/src/modules/health/health.module.d.ts +2 -0
- package/dist/src/modules/health/health.module.js +17 -0
- package/dist/src/modules/health/health.module.js.map +1 -0
- package/dist/src/modules/media/media.module.d.ts +2 -0
- package/dist/src/modules/media/media.module.js +18 -0
- package/dist/src/modules/media/media.module.js.map +1 -0
- package/dist/src/modules/media/media.service.d.ts +15 -0
- package/dist/src/modules/media/media.service.js +49 -0
- package/dist/src/modules/media/media.service.js.map +1 -0
- package/dist/src/modules/platforms/base/auth-validator-registry.service.d.ts +25 -0
- package/dist/src/modules/platforms/base/auth-validator-registry.service.js +50 -0
- package/dist/src/modules/platforms/base/auth-validator-registry.service.js.map +1 -0
- package/dist/src/modules/platforms/base/auth-validator.interface.d.ts +16 -0
- package/dist/src/modules/platforms/base/auth-validator.interface.js +2 -0
- package/dist/src/modules/platforms/base/auth-validator.interface.js.map +1 -0
- package/dist/src/modules/platforms/base/index.d.ts +4 -0
- package/dist/src/modules/platforms/base/index.js +5 -0
- package/dist/src/modules/platforms/base/index.js.map +1 -0
- package/dist/src/modules/platforms/base/platform-registry.service.d.ts +31 -0
- package/dist/src/modules/platforms/base/platform-registry.service.js +54 -0
- package/dist/src/modules/platforms/base/platform-registry.service.js.map +1 -0
- package/dist/src/modules/platforms/base/platform.interface.d.ts +39 -0
- package/dist/src/modules/platforms/base/platform.interface.js +2 -0
- package/dist/src/modules/platforms/base/platform.interface.js.map +1 -0
- package/dist/src/modules/platforms/platforms.module.d.ts +13 -0
- package/dist/src/modules/platforms/platforms.module.js +59 -0
- package/dist/src/modules/platforms/platforms.module.js.map +1 -0
- package/dist/src/modules/platforms/telegram/telegram-auth.validator.d.ts +19 -0
- package/dist/src/modules/platforms/telegram/telegram-auth.validator.js +51 -0
- package/dist/src/modules/platforms/telegram/telegram-auth.validator.js.map +1 -0
- package/dist/src/modules/platforms/telegram/telegram-type-detector.service.d.ts +18 -0
- package/dist/src/modules/platforms/telegram/telegram-type-detector.service.js +47 -0
- package/dist/src/modules/platforms/telegram/telegram-type-detector.service.js.map +1 -0
- package/dist/src/modules/platforms/telegram/telegram.platform.d.ts +58 -0
- package/dist/src/modules/platforms/telegram/telegram.platform.js +434 -0
- package/dist/src/modules/platforms/telegram/telegram.platform.js.map +1 -0
- package/dist/src/modules/post/base-post.service.d.ts +64 -0
- package/dist/src/modules/post/base-post.service.js +99 -0
- package/dist/src/modules/post/base-post.service.js.map +1 -0
- package/dist/src/modules/post/dto/index.d.ts +3 -0
- package/dist/src/modules/post/dto/index.js +4 -0
- package/dist/src/modules/post/dto/index.js.map +1 -0
- package/dist/src/modules/post/dto/post-request.dto.d.ts +56 -0
- package/dist/src/modules/post/dto/post-request.dto.js +195 -0
- package/dist/src/modules/post/dto/post-request.dto.js.map +1 -0
- package/dist/src/modules/post/dto/post-response.dto.d.ts +41 -0
- package/dist/src/modules/post/dto/post-response.dto.js +2 -0
- package/dist/src/modules/post/dto/post-response.dto.js.map +1 -0
- package/dist/src/modules/post/dto/preview-response.dto.d.ts +33 -0
- package/dist/src/modules/post/dto/preview-response.dto.js +2 -0
- package/dist/src/modules/post/dto/preview-response.dto.js.map +1 -0
- package/dist/src/modules/post/idempotency.service.d.ts +95 -0
- package/dist/src/modules/post/idempotency.service.js +229 -0
- package/dist/src/modules/post/idempotency.service.js.map +1 -0
- package/dist/src/modules/post/post.controller.d.ts +13 -0
- package/dist/src/modules/post/post.controller.js +97 -0
- package/dist/src/modules/post/post.controller.js.map +1 -0
- package/dist/src/modules/post/post.module.d.ts +2 -0
- package/dist/src/modules/post/post.module.js +25 -0
- package/dist/src/modules/post/post.module.js.map +1 -0
- package/dist/src/modules/post/post.service.d.ts +62 -0
- package/dist/src/modules/post/post.service.js +325 -0
- package/dist/src/modules/post/post.service.js.map +1 -0
- package/dist/src/modules/post/preview.service.d.ts +23 -0
- package/dist/src/modules/post/preview.service.js +69 -0
- package/dist/src/modules/post/preview.service.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global application constants
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Graceful shutdown timeout in milliseconds
|
|
6
|
+
* Maximum time to wait for in-flight requests to complete before forcing shutdown
|
|
7
|
+
*/
|
|
8
|
+
export const GRACEFUL_SHUTDOWN_TIMEOUT_MS = 25000;
|
|
9
|
+
//# sourceMappingURL=app.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.constants.js","sourceRoot":"","sources":["../../src/app.constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported body content formats for post text
|
|
3
|
+
* Used for content conversion and platform-specific formatting
|
|
4
|
+
*/
|
|
5
|
+
export declare enum BodyFormat {
|
|
6
|
+
/** HTML markup */
|
|
7
|
+
HTML = "html",
|
|
8
|
+
/** Markdown syntax */
|
|
9
|
+
MARKDOWN = "md",
|
|
10
|
+
/** Plain text without formatting */
|
|
11
|
+
TEXT = "text"
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported body content formats for post text
|
|
3
|
+
* Used for content conversion and platform-specific formatting
|
|
4
|
+
*/
|
|
5
|
+
export var BodyFormat;
|
|
6
|
+
(function (BodyFormat) {
|
|
7
|
+
/** HTML markup */
|
|
8
|
+
BodyFormat["HTML"] = "html";
|
|
9
|
+
/** Markdown syntax */
|
|
10
|
+
BodyFormat["MARKDOWN"] = "md";
|
|
11
|
+
/** Plain text without formatting */
|
|
12
|
+
BodyFormat["TEXT"] = "text";
|
|
13
|
+
})(BodyFormat || (BodyFormat = {}));
|
|
14
|
+
//# sourceMappingURL=body-format.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-format.enum.js","sourceRoot":"","sources":["../../../../src/common/enums/body-format.enum.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAN,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,kBAAkB;IAClB,2BAAa,CAAA;IACb,sBAAsB;IACtB,6BAAe,CAAA;IACf,oCAAoC;IACpC,2BAAa,CAAA;AACf,CAAC,EAPW,UAAU,KAAV,UAAU,QAOrB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for categorizing different types of failures
|
|
3
|
+
* Used in error responses to provide machine-readable error classification
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ErrorCode {
|
|
6
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
7
|
+
TIMEOUT_ERROR = "TIMEOUT_ERROR",
|
|
8
|
+
RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR",
|
|
9
|
+
PLATFORM_ERROR = "PLATFORM_ERROR",
|
|
10
|
+
AUTH_ERROR = "AUTH_ERROR",
|
|
11
|
+
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for categorizing different types of failures
|
|
3
|
+
* Used in error responses to provide machine-readable error classification
|
|
4
|
+
*/
|
|
5
|
+
export var ErrorCode;
|
|
6
|
+
(function (ErrorCode) {
|
|
7
|
+
ErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
8
|
+
ErrorCode["TIMEOUT_ERROR"] = "TIMEOUT_ERROR";
|
|
9
|
+
ErrorCode["RATE_LIMIT_ERROR"] = "RATE_LIMIT_ERROR";
|
|
10
|
+
ErrorCode["PLATFORM_ERROR"] = "PLATFORM_ERROR";
|
|
11
|
+
ErrorCode["AUTH_ERROR"] = "AUTH_ERROR";
|
|
12
|
+
ErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
13
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
14
|
+
//# sourceMappingURL=error-code.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-code.enum.js","sourceRoot":"","sources":["../../../../src/common/enums/error-code.enum.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACjB,kDAAqC,CAAA;IACrC,4CAA+B,CAAA;IAC/B,kDAAqC,CAAA;IACrC,8CAAiC,CAAA;IACjC,sCAAyB,CAAA;IACzB,8CAAiC,CAAA;AACrC,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/enums/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported post types across different social media platforms
|
|
3
|
+
* AUTO allows the system to automatically detect the appropriate type based on content
|
|
4
|
+
*/
|
|
5
|
+
export declare enum PostType {
|
|
6
|
+
/** Automatically detect post type based on provided media fields */
|
|
7
|
+
AUTO = "auto",
|
|
8
|
+
/** Text-only post without media */
|
|
9
|
+
POST = "post",
|
|
10
|
+
/** Long-form article with rich formatting */
|
|
11
|
+
ARTICLE = "article",
|
|
12
|
+
/** Single image post */
|
|
13
|
+
IMAGE = "image",
|
|
14
|
+
/** Multiple images/videos in a single post */
|
|
15
|
+
ALBUM = "album",
|
|
16
|
+
/** Video post */
|
|
17
|
+
VIDEO = "video",
|
|
18
|
+
/** Short-form video (e.g., TikTok, Reels) */
|
|
19
|
+
SHORT = "short",
|
|
20
|
+
/** Audio file post */
|
|
21
|
+
AUDIO = "audio",
|
|
22
|
+
/** Document file post */
|
|
23
|
+
DOCUMENT = "document",
|
|
24
|
+
/** Story/status update (temporary content) */
|
|
25
|
+
STORY = "story",
|
|
26
|
+
/** Poll/survey post */
|
|
27
|
+
POLL = "poll"
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported post types across different social media platforms
|
|
3
|
+
* AUTO allows the system to automatically detect the appropriate type based on content
|
|
4
|
+
*/
|
|
5
|
+
export var PostType;
|
|
6
|
+
(function (PostType) {
|
|
7
|
+
/** Automatically detect post type based on provided media fields */
|
|
8
|
+
PostType["AUTO"] = "auto";
|
|
9
|
+
/** Text-only post without media */
|
|
10
|
+
PostType["POST"] = "post";
|
|
11
|
+
/** Long-form article with rich formatting */
|
|
12
|
+
PostType["ARTICLE"] = "article";
|
|
13
|
+
/** Single image post */
|
|
14
|
+
PostType["IMAGE"] = "image";
|
|
15
|
+
/** Multiple images/videos in a single post */
|
|
16
|
+
PostType["ALBUM"] = "album";
|
|
17
|
+
/** Video post */
|
|
18
|
+
PostType["VIDEO"] = "video";
|
|
19
|
+
/** Short-form video (e.g., TikTok, Reels) */
|
|
20
|
+
PostType["SHORT"] = "short";
|
|
21
|
+
/** Audio file post */
|
|
22
|
+
PostType["AUDIO"] = "audio";
|
|
23
|
+
/** Document file post */
|
|
24
|
+
PostType["DOCUMENT"] = "document";
|
|
25
|
+
/** Story/status update (temporary content) */
|
|
26
|
+
PostType["STORY"] = "story";
|
|
27
|
+
/** Poll/survey post */
|
|
28
|
+
PostType["POLL"] = "poll";
|
|
29
|
+
})(PostType || (PostType = {}));
|
|
30
|
+
//# sourceMappingURL=post-type.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-type.enum.js","sourceRoot":"","sources":["../../../../src/common/enums/post-type.enum.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAN,IAAY,QAuBX;AAvBD,WAAY,QAAQ;IAClB,oEAAoE;IACpE,yBAAa,CAAA;IACb,mCAAmC;IACnC,yBAAa,CAAA;IACb,6CAA6C;IAC7C,+BAAmB,CAAA;IACnB,wBAAwB;IACxB,2BAAe,CAAA;IACf,8CAA8C;IAC9C,2BAAe,CAAA;IACf,iBAAiB;IACjB,2BAAe,CAAA;IACf,6CAA6C;IAC7C,2BAAe,CAAA;IACf,sBAAsB;IACtB,2BAAe,CAAA;IACf,yBAAyB;IACzB,iCAAqB,CAAA;IACrB,8CAA8C;IAC9C,2BAAe,CAAA;IACf,uBAAuB;IACvB,yBAAa,CAAA;AACf,CAAC,EAvBW,QAAQ,KAAR,QAAQ,QAuBnB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ArgumentsHost, type ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import { PinoLogger } from 'nestjs-pino';
|
|
3
|
+
/**
|
|
4
|
+
* Global exception filter that catches all exceptions
|
|
5
|
+
* and formats them in a consistent way for Fastify responses
|
|
6
|
+
*/
|
|
7
|
+
export declare class AllExceptionsFilter implements ExceptionFilter {
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(logger: PinoLogger);
|
|
10
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
11
|
+
private extractMessage;
|
|
12
|
+
private buildErrorResponse;
|
|
13
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var AllExceptionsFilter_1;
|
|
14
|
+
import { Catch, HttpException, HttpStatus, Inject, } from '@nestjs/common';
|
|
15
|
+
import { PinoLogger } from 'nestjs-pino';
|
|
16
|
+
/**
|
|
17
|
+
* Global exception filter that catches all exceptions
|
|
18
|
+
* and formats them in a consistent way for Fastify responses
|
|
19
|
+
*/
|
|
20
|
+
let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
|
|
21
|
+
logger;
|
|
22
|
+
constructor(logger) {
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
logger.setContext(AllExceptionsFilter_1.name);
|
|
25
|
+
}
|
|
26
|
+
catch(exception, host) {
|
|
27
|
+
const ctx = host.switchToHttp();
|
|
28
|
+
const response = ctx.getResponse();
|
|
29
|
+
const request = ctx.getRequest();
|
|
30
|
+
// Preserve statusCode from non-HttpException errors (e.g., Fastify plugins)
|
|
31
|
+
const status = exception instanceof HttpException
|
|
32
|
+
? exception.getStatus()
|
|
33
|
+
: typeof exception?.statusCode === 'number'
|
|
34
|
+
? exception.statusCode
|
|
35
|
+
: HttpStatus.INTERNAL_SERVER_ERROR;
|
|
36
|
+
const message = this.extractMessage(exception);
|
|
37
|
+
const errorResponse = this.buildErrorResponse(exception);
|
|
38
|
+
const logContext = {
|
|
39
|
+
status,
|
|
40
|
+
method: request.method,
|
|
41
|
+
url: request.url,
|
|
42
|
+
requestId: request.id,
|
|
43
|
+
err: exception,
|
|
44
|
+
};
|
|
45
|
+
// Log error for internal tracking
|
|
46
|
+
if (status >= 500) {
|
|
47
|
+
this.logger.error(logContext, message);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.logger.warn(logContext, message);
|
|
51
|
+
}
|
|
52
|
+
void response.status(status).send({
|
|
53
|
+
statusCode: status,
|
|
54
|
+
timestamp: new Date().toISOString(),
|
|
55
|
+
path: request.url,
|
|
56
|
+
method: request.method,
|
|
57
|
+
message,
|
|
58
|
+
error: errorResponse,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
extractMessage(exception) {
|
|
62
|
+
if (exception instanceof HttpException) {
|
|
63
|
+
const response = exception.getResponse();
|
|
64
|
+
if (typeof response === 'string') {
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
if (typeof response === 'object' && response !== null && 'message' in response) {
|
|
68
|
+
const msg = response.message;
|
|
69
|
+
if (Array.isArray(msg)) {
|
|
70
|
+
return msg.join(', ');
|
|
71
|
+
}
|
|
72
|
+
if (typeof msg === 'string') {
|
|
73
|
+
return msg;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return exception.message;
|
|
77
|
+
}
|
|
78
|
+
if (exception instanceof Error) {
|
|
79
|
+
return exception.message;
|
|
80
|
+
}
|
|
81
|
+
return 'Internal server error';
|
|
82
|
+
}
|
|
83
|
+
buildErrorResponse(exception) {
|
|
84
|
+
if (exception instanceof HttpException) {
|
|
85
|
+
const response = exception.getResponse();
|
|
86
|
+
if (typeof response === 'object' && response !== null) {
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
return exception.name;
|
|
90
|
+
}
|
|
91
|
+
if (exception instanceof Error) {
|
|
92
|
+
return exception.name;
|
|
93
|
+
}
|
|
94
|
+
return 'UnknownError';
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
AllExceptionsFilter = AllExceptionsFilter_1 = __decorate([
|
|
98
|
+
Catch(),
|
|
99
|
+
__param(0, Inject(PinoLogger)),
|
|
100
|
+
__metadata("design:paramtypes", [PinoLogger])
|
|
101
|
+
], AllExceptionsFilter);
|
|
102
|
+
export { AllExceptionsFilter };
|
|
103
|
+
//# sourceMappingURL=all-exceptions.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all-exceptions.filter.js","sourceRoot":"","sources":["../../../../src/common/filters/all-exceptions.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAEL,KAAK,EAEL,aAAa,EACb,UAAU,EACV,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;GAGG;AAEI,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IACmB;IAAjD,YAAiD,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QACjE,MAAM,CAAC,UAAU,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,SAAkB,EAAE,IAAmB;QAClD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAgB,CAAC;QACjD,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAkB,CAAC;QAEjD,4EAA4E;QAC5E,MAAM,MAAM,GACV,SAAS,YAAY,aAAa;YAChC,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE;YACvB,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,KAAK,IAAI,IAAI,SAAS,IAAI,QAAQ,EAAE,CAAC;gBAC/E,MAAM,GAAG,GAAI,QAAiC,CAAC,OAAO,CAAC;gBACvD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBACvB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACxB,CAAC;gBACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAC5B,OAAO,GAAG,CAAC;gBACb,CAAC;YACH,CAAC;YACD,OAAO,SAAS,CAAC,OAAO,CAAC;QAC3B,CAAC;QAED,IAAI,SAAS,YAAY,KAAK,EAAE,CAAC;YAC/B,OAAO,SAAS,CAAC,OAAO,CAAC;QAC3B,CAAC;QAED,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAEO,kBAAkB,CAAC,SAAkB;QAC3C,IAAI,SAAS,YAAY,aAAa,EAAE,CAAC;YACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;YACzC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACtD,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,CAAC;QAED,IAAI,SAAS,YAAY,KAAK,EAAE,CAAC;YAC/B,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAA;AAtFY,mBAAmB;IAD/B,KAAK,EAAE;IAEO,WAAA,MAAM,CAAC,UAAU,CAAC,CAAA;qCAA0B,UAAU;GADxD,mBAAmB,CAsF/B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { MediaInput, MediaInputObject, MediaType } from '../types/media-input.type.js';
|
|
2
|
+
import { InputFile } from 'grammy';
|
|
3
|
+
/**
|
|
4
|
+
* Helper class for working with MediaInput
|
|
5
|
+
*/
|
|
6
|
+
export declare class MediaInputHelper {
|
|
7
|
+
/**
|
|
8
|
+
* Check if a string is a valid URL
|
|
9
|
+
* @param str - String to check
|
|
10
|
+
* @returns True if string is a valid URL
|
|
11
|
+
*/
|
|
12
|
+
private static isValidUrl;
|
|
13
|
+
/**
|
|
14
|
+
* Type guard to check if MediaInput is an object with src property
|
|
15
|
+
* @param input - MediaInput to check
|
|
16
|
+
* @returns True if input is a MediaInputObject
|
|
17
|
+
*/
|
|
18
|
+
static isObject(input: MediaInput): input is MediaInputObject;
|
|
19
|
+
/**
|
|
20
|
+
* Extract URL from MediaInput
|
|
21
|
+
* Checks if the src value is a valid URL
|
|
22
|
+
* @param input - MediaInput to extract URL from
|
|
23
|
+
* @returns URL string if available, undefined otherwise
|
|
24
|
+
*/
|
|
25
|
+
static getUrl(input: MediaInput): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Extract Telegram file_id from MediaInput
|
|
28
|
+
* Available when src is not a valid URL
|
|
29
|
+
* @param input - MediaInput to extract file_id from
|
|
30
|
+
* @returns Telegram file_id if available, undefined otherwise
|
|
31
|
+
*/
|
|
32
|
+
static getFileId(input: MediaInput): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Extract hasSpoiler flag from MediaInput
|
|
35
|
+
* Used for Telegram spoiler animation feature
|
|
36
|
+
* @param input - MediaInput to extract flag from
|
|
37
|
+
* @returns True if spoiler is enabled, false otherwise (defaults to false)
|
|
38
|
+
*/
|
|
39
|
+
static getHasSpoiler(input: MediaInput): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Extract explicit media type from MediaInput
|
|
42
|
+
* Used in media arrays to override auto-detection by URL extension
|
|
43
|
+
* @param input - MediaInput to extract type from
|
|
44
|
+
* @returns MediaType if specified, undefined otherwise
|
|
45
|
+
*/
|
|
46
|
+
static getType(input: MediaInput): MediaType | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Convert MediaInput to Telegram-compatible format
|
|
49
|
+
* Prioritizes file_id over URL for better performance and reliability
|
|
50
|
+
* @param input - MediaInput to convert
|
|
51
|
+
* @returns Telegram file_id string or URL string
|
|
52
|
+
* @throws Error if src is missing or invalid
|
|
53
|
+
*/
|
|
54
|
+
static toTelegramInput(input: MediaInput): string | InputFile;
|
|
55
|
+
/**
|
|
56
|
+
* Check if input has valid MediaInput structure
|
|
57
|
+
* @param input - Input to check
|
|
58
|
+
* @returns True if input is an object with src
|
|
59
|
+
*/
|
|
60
|
+
static isValidShape(input: any): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Check if MediaInput array is not empty and contains valid items
|
|
63
|
+
* @param input - Optional array of MediaInput
|
|
64
|
+
* @returns True if array exists and has at least one valid element
|
|
65
|
+
*/
|
|
66
|
+
static isNotEmpty(input?: MediaInput[]): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Check if MediaInput is defined, not null, and has valid shape
|
|
69
|
+
* @param input - Optional MediaInput to check
|
|
70
|
+
* @returns True if input is defined, not null, and valid
|
|
71
|
+
*/
|
|
72
|
+
static isDefined(input?: MediaInput): boolean;
|
|
73
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BadRequestException } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Helper class for working with MediaInput
|
|
4
|
+
*/
|
|
5
|
+
export class MediaInputHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Check if a string is a valid URL
|
|
8
|
+
* @param str - String to check
|
|
9
|
+
* @returns True if string is a valid URL
|
|
10
|
+
*/
|
|
11
|
+
static isValidUrl(str) {
|
|
12
|
+
try {
|
|
13
|
+
new URL(str);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to check if MediaInput is an object with src property
|
|
22
|
+
* @param input - MediaInput to check
|
|
23
|
+
* @returns True if input is a MediaInputObject
|
|
24
|
+
*/
|
|
25
|
+
static isObject(input) {
|
|
26
|
+
return typeof input === 'object' && input !== null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extract URL from MediaInput
|
|
30
|
+
* Checks if the src value is a valid URL
|
|
31
|
+
* @param input - MediaInput to extract URL from
|
|
32
|
+
* @returns URL string if available, undefined otherwise
|
|
33
|
+
*/
|
|
34
|
+
static getUrl(input) {
|
|
35
|
+
if (this.isObject(input)) {
|
|
36
|
+
return this.isValidUrl(input.src) ? input.src : undefined;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extract Telegram file_id from MediaInput
|
|
42
|
+
* Available when src is not a valid URL
|
|
43
|
+
* @param input - MediaInput to extract file_id from
|
|
44
|
+
* @returns Telegram file_id if available, undefined otherwise
|
|
45
|
+
*/
|
|
46
|
+
static getFileId(input) {
|
|
47
|
+
if (this.isObject(input)) {
|
|
48
|
+
return this.isValidUrl(input.src) ? undefined : input.src;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Extract hasSpoiler flag from MediaInput
|
|
54
|
+
* Used for Telegram spoiler animation feature
|
|
55
|
+
* @param input - MediaInput to extract flag from
|
|
56
|
+
* @returns True if spoiler is enabled, false otherwise (defaults to false)
|
|
57
|
+
*/
|
|
58
|
+
static getHasSpoiler(input) {
|
|
59
|
+
if (this.isObject(input)) {
|
|
60
|
+
return input.hasSpoiler ?? false;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extract explicit media type from MediaInput
|
|
66
|
+
* Used in media arrays to override auto-detection by URL extension
|
|
67
|
+
* @param input - MediaInput to extract type from
|
|
68
|
+
* @returns MediaType if specified, undefined otherwise
|
|
69
|
+
*/
|
|
70
|
+
static getType(input) {
|
|
71
|
+
if (this.isObject(input)) {
|
|
72
|
+
return input.type;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert MediaInput to Telegram-compatible format
|
|
78
|
+
* Prioritizes file_id over URL for better performance and reliability
|
|
79
|
+
* @param input - MediaInput to convert
|
|
80
|
+
* @returns Telegram file_id string or URL string
|
|
81
|
+
* @throws Error if src is missing or invalid
|
|
82
|
+
*/
|
|
83
|
+
static toTelegramInput(input) {
|
|
84
|
+
const fileId = this.getFileId(input);
|
|
85
|
+
if (fileId) {
|
|
86
|
+
return fileId;
|
|
87
|
+
}
|
|
88
|
+
const url = this.getUrl(input);
|
|
89
|
+
if (url) {
|
|
90
|
+
return url;
|
|
91
|
+
}
|
|
92
|
+
throw new BadRequestException('MediaInput must be either a string or an object with src property');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if input has valid MediaInput structure
|
|
96
|
+
* @param input - Input to check
|
|
97
|
+
* @returns True if input is an object with src
|
|
98
|
+
*/
|
|
99
|
+
static isValidShape(input) {
|
|
100
|
+
if (typeof input === 'object' && input !== null) {
|
|
101
|
+
return typeof input.src === 'string' && input.src.length > 0;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if MediaInput array is not empty and contains valid items
|
|
107
|
+
* @param input - Optional array of MediaInput
|
|
108
|
+
* @returns True if array exists and has at least one valid element
|
|
109
|
+
*/
|
|
110
|
+
static isNotEmpty(input) {
|
|
111
|
+
return Array.isArray(input) && input.some(item => this.isValidShape(item));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if MediaInput is defined, not null, and has valid shape
|
|
115
|
+
* @param input - Optional MediaInput to check
|
|
116
|
+
* @returns True if input is defined, not null, and valid
|
|
117
|
+
*/
|
|
118
|
+
static isDefined(input) {
|
|
119
|
+
return input !== undefined && input !== null && this.isValidShape(input);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=media-input.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-input.helper.js","sourceRoot":"","sources":["../../../../src/common/helpers/media-input.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;;;OAIG;IACK,MAAM,CAAC,UAAU,CAAC,GAAW;QACnC,IAAI,CAAC;YACH,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAID;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAiB;QAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,KAAiB;QAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5D,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,KAAiB;QAChC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;QAC5D,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,KAAiB;QACpC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,U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AAI,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ShutdownService } from '../services/shutdown.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Interceptor that rejects new requests during shutdown
|
|
6
|
+
* and tracks in-flight requests for graceful shutdown
|
|
7
|
+
*/
|
|
8
|
+
export declare class ShutdownInterceptor implements NestInterceptor {
|
|
9
|
+
private readonly shutdownService;
|
|
10
|
+
constructor(shutdownService: ShutdownService);
|
|
11
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Injectable, ServiceUnavailableException, } from '@nestjs/common';
|
|
11
|
+
import { throwError } from 'rxjs';
|
|
12
|
+
import { tap, catchError } from 'rxjs/operators';
|
|
13
|
+
import { ShutdownService } from '../services/shutdown.service.js';
|
|
14
|
+
/**
|
|
15
|
+
* Interceptor that rejects new requests during shutdown
|
|
16
|
+
* and tracks in-flight requests for graceful shutdown
|
|
17
|
+
*/
|
|
18
|
+
let ShutdownInterceptor = class ShutdownInterceptor {
|
|
19
|
+
shutdownService;
|
|
20
|
+
constructor(shutdownService) {
|
|
21
|
+
this.shutdownService = shutdownService;
|
|
22
|
+
}
|
|
23
|
+
intercept(context, next) {
|
|
24
|
+
if (this.shutdownService.shuttingDown) {
|
|
25
|
+
throw new ServiceUnavailableException('Server is shutting down');
|
|
26
|
+
}
|
|
27
|
+
this.shutdownService.trackRequest();
|
|
28
|
+
return next.handle().pipe(tap(() => {
|
|
29
|
+
this.shutdownService.untrackRequest();
|
|
30
|
+
}), catchError(err => {
|
|
31
|
+
this.shutdownService.untrackRequest();
|
|
32
|
+
return throwError(() => err);
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
ShutdownInterceptor = __decorate([
|
|
37
|
+
Injectable(),
|
|
38
|
+
__metadata("design:paramtypes", [ShutdownService])
|
|
39
|
+
], ShutdownInterceptor);
|
|
40
|
+
export { ShutdownInterceptor };
|
|
41
|
+
//# sourceMappingURL=shutdown.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.interceptor.js","sourceRoot":"","sources":["../../../../src/common/interceptors/shutdown.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,UAAU,EAIV,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAc,UAAU,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE;;;GAGG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAEjE,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,IAAI,IAAI,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,2BAA2B,CAAC,yBAAyB,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;QAEpC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,GAAG,CAAC,GAAG,EAAE;YACP,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE,CAAC;QACxC,CAAC,CAAC,EACF,UAAU,CAAC,GAAG,CAAC,EAAE;YACf,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE,CAAC;YACtC,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AApBY,mBAAmB;IAD/B,UAAU,EAAE;qCAEmC,eAAe;GADlD,mBAAmB,CAoB/B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger interface for library mode
|
|
3
|
+
* Allows users to provide their own logger implementation
|
|
4
|
+
*/
|
|
5
|
+
export interface ILogger {
|
|
6
|
+
/**
|
|
7
|
+
* Log debug message
|
|
8
|
+
* @param message - Message to log
|
|
9
|
+
* @param context - Optional context/source of the log
|
|
10
|
+
*/
|
|
11
|
+
debug(message: string, context?: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Log informational message
|
|
14
|
+
* @param message - Message to log
|
|
15
|
+
* @param context - Optional context/source of the log
|
|
16
|
+
*/
|
|
17
|
+
log(message: string, context?: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Log warning message
|
|
20
|
+
* @param message - Message to log
|
|
21
|
+
* @param context - Optional context/source of the log
|
|
22
|
+
*/
|
|
23
|
+
warn(message: string, context?: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Log error message
|
|
26
|
+
* @param message - Message to log
|
|
27
|
+
* @param trace - Optional stack trace
|
|
28
|
+
* @param context - Optional context/source of the log
|
|
29
|
+
*/
|
|
30
|
+
error(message: string, trace?: string, context?: string): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Simple console logger implementation
|
|
34
|
+
* Used as default logger in library mode
|
|
35
|
+
*/
|
|
36
|
+
export declare class ConsoleLogger implements ILogger {
|
|
37
|
+
private readonly logLevel;
|
|
38
|
+
constructor(logLevel?: 'debug' | 'info' | 'warn' | 'error');
|
|
39
|
+
private shouldLog;
|
|
40
|
+
debug(message: string, context?: string): void;
|
|
41
|
+
log(message: string, context?: string): void;
|
|
42
|
+
warn(message: string, context?: string): void;
|
|
43
|
+
error(message: string, trace?: string, context?: string): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple console logger implementation
|
|
3
|
+
* Used as default logger in library mode
|
|
4
|
+
*/
|
|
5
|
+
export class ConsoleLogger {
|
|
6
|
+
logLevel;
|
|
7
|
+
constructor(logLevel = 'warn') {
|
|
8
|
+
this.logLevel = logLevel;
|
|
9
|
+
}
|
|
10
|
+
shouldLog(level) {
|
|
11
|
+
const levels = ['debug', 'info', 'warn', 'error'];
|
|
12
|
+
const currentLevelIndex = levels.indexOf(this.logLevel);
|
|
13
|
+
const messageLevelIndex = levels.indexOf(level);
|
|
14
|
+
return messageLevelIndex >= currentLevelIndex;
|
|
15
|
+
}
|
|
16
|
+
debug(message, context) {
|
|
17
|
+
if (this.shouldLog('debug')) {
|
|
18
|
+
const prefix = context ? `[${context}]` : '';
|
|
19
|
+
console.debug(`${prefix} ${message}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
log(message, context) {
|
|
23
|
+
if (this.shouldLog('info')) {
|
|
24
|
+
const prefix = context ? `[${context}]` : '';
|
|
25
|
+
console.log(`${prefix} ${message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
warn(message, context) {
|
|
29
|
+
if (this.shouldLog('warn')) {
|
|
30
|
+
const prefix = context ? `[${context}]` : '';
|
|
31
|
+
console.warn(`${prefix} ${message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
error(message, trace, context) {
|
|
35
|
+
if (this.shouldLog('error')) {
|
|
36
|
+
const prefix = context ? `[${context}]` : '';
|
|
37
|
+
console.error(`${prefix} ${message}`);
|
|
38
|
+
if (trace) {
|
|
39
|
+
console.error(trace);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=logger.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.interface.js","sourceRoot":"","sources":["../../../../src/common/interfaces/logger.interface.ts"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,MAAM,OAAO,aAAa;IACK;IAA7B,YAA6B,WAAgD,MAAM;QAAtD,aAAQ,GAAR,QAAQ,CAA8C;IAAG,CAAC;IAE/E,SAAS,CAAC,KAA0C;QAC1D,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxD,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAChD,OAAO,iBAAiB,IAAI,iBAAiB,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,OAAgB;QACrC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,GAAG,CAAC,OAAe,EAAE,OAAgB;QACnC,IAAI,IAAI,CAAC,SAAS,CAAC,M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