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 @@
|
|
|
1
|
+
{"version":3,"file":"media-input.validator.js","sourceRoot":"","sources":["../../../../src/common/validators/media-input.validator.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,iBAAiB,EAGjB,mBAAmB,GAEpB,MAAM,iBAAiB,CAAC;AAGzB,gDAAgD;AAChD,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;GAGG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAU,EAAE,IAAyB;QAC5C,8CAA8C;QAC9C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,sCAAsC;QACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC;YAC7C,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,KAAK,SAAS,I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C;QACf,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,sBAAsB,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,cAAc,CAAC,IAAyB;QACtC,OAAO,oJAAoJ,uBAAuB,qEAAqE,CAAC;IAC1P,CAAC;CACF,CAAA;AAvBY,2BAA2B;IADvC,mBAAmB,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GACpD,2BAA2B,CAuBvC;;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,iBAAqC;IACrE,OAAO,UAAU,MAAc,EAAE,YAAoB;QACnD,iBAAiB,CAAC;YAChB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,OAAO,EAAE,iBAAiB;YAC1B,WAAW,EAAE,EAAE;YACf,SAAS,EAAE,2BAA2B;SACvC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PostRequestDto } from '../../modules/post/dto/post-request.dto.js';
|
|
2
|
+
import { PostType } from '../enums/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validator and detector for media fields based on strict priority
|
|
5
|
+
* Implements soft comparison where higher priority fields take precedence
|
|
6
|
+
*/
|
|
7
|
+
export declare class MediaPriorityValidator {
|
|
8
|
+
/**
|
|
9
|
+
* Detects the primary media field based on priority:
|
|
10
|
+
* 1. media[] -> ALBUM
|
|
11
|
+
* 2. document -> DOCUMENT
|
|
12
|
+
* 3. audio -> AUDIO
|
|
13
|
+
* 4. video -> VIDEO
|
|
14
|
+
*
|
|
15
|
+
* @param request The post request
|
|
16
|
+
* @returns The detected PostType or null if no primary media found
|
|
17
|
+
*/
|
|
18
|
+
static detectPrimaryMediaField(request: PostRequestDto): PostType | null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PostType } from '../enums/index.js';
|
|
2
|
+
import { MediaInputHelper } from '../helpers/media-input.helper.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validator and detector for media fields based on strict priority
|
|
5
|
+
* Implements soft comparison where higher priority fields take precedence
|
|
6
|
+
*/
|
|
7
|
+
export class MediaPriorityValidator {
|
|
8
|
+
/**
|
|
9
|
+
* Detects the primary media field based on priority:
|
|
10
|
+
* 1. media[] -> ALBUM
|
|
11
|
+
* 2. document -> DOCUMENT
|
|
12
|
+
* 3. audio -> AUDIO
|
|
13
|
+
* 4. video -> VIDEO
|
|
14
|
+
*
|
|
15
|
+
* @param request The post request
|
|
16
|
+
* @returns The detected PostType or null if no primary media found
|
|
17
|
+
*/
|
|
18
|
+
static detectPrimaryMediaField(request) {
|
|
19
|
+
// Priority 1: media[] -> ALBUM
|
|
20
|
+
if (MediaInputHelper.isNotEmpty(request.media)) {
|
|
21
|
+
return PostType.ALBUM;
|
|
22
|
+
}
|
|
23
|
+
// Priority 2: document -> DOCUMENT
|
|
24
|
+
if (MediaInputHelper.isDefined(request.document)) {
|
|
25
|
+
return PostType.DOCUMENT;
|
|
26
|
+
}
|
|
27
|
+
// Priority 3: audio -> AUDIO
|
|
28
|
+
if (MediaInputHelper.isDefined(request.audio)) {
|
|
29
|
+
return PostType.AUDIO;
|
|
30
|
+
}
|
|
31
|
+
// Priority 4: video -> VIDEO
|
|
32
|
+
if (MediaInputHelper.isDefined(request.video)) {
|
|
33
|
+
return PostType.VIDEO;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=media-priority.validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-priority.validator.js","sourceRoot":"","sources":["../../../../src/common/validators/media-priority.validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IAC/B;;;;;;;;;OASG;IACH,MAAM,CAAC,uBAAuB,CAAC,OAAuB;QAClD,+BAA+B;QAC/B,IAAI,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,OAAO,QAAQ,CAAC,KAAK,CAAC;QAC1B,CAAC;QAED,mCAAmC;QACnC,IAAI,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/C,OAAO,QAAQ,CAAC,QAAQ,CAAC;QAC7B,CAAC;QAED,6BAA6B;QAC7B,IAAI,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,OAAO,QAAQ,CAAC,KAAK,CAAC;QAC1B,CAAC;QAED,6BAA6B;QAC7B,IAAI,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,OAAO,QAAQ,CAAC,KAAK,CAAC;QAC1B,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application configuration class
|
|
3
|
+
* Validates environment variables and provides type-safe configuration
|
|
4
|
+
*/
|
|
5
|
+
export declare class AppConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Port number for the HTTP server
|
|
8
|
+
* Must be between 1 and 65535
|
|
9
|
+
*/
|
|
10
|
+
port: number;
|
|
11
|
+
/**
|
|
12
|
+
* Host address to bind the server to
|
|
13
|
+
* Examples: 'localhost', '0.0.0.0', '127.0.0.1'
|
|
14
|
+
*/
|
|
15
|
+
host: string;
|
|
16
|
+
/**
|
|
17
|
+
* Base path for the application
|
|
18
|
+
* If set, API will be available at {basePath}/api/v1
|
|
19
|
+
*/
|
|
20
|
+
basePath: string;
|
|
21
|
+
/**
|
|
22
|
+
* Node environment mode
|
|
23
|
+
* Determines logging behavior and other environment-specific settings
|
|
24
|
+
*/
|
|
25
|
+
nodeEnv: string;
|
|
26
|
+
/**
|
|
27
|
+
* Logging level for Pino logger
|
|
28
|
+
* Controls the verbosity of application logs
|
|
29
|
+
*/
|
|
30
|
+
logLevel: string;
|
|
31
|
+
}
|
|
32
|
+
declare const _default: (() => AppConfig) & import("@nestjs/config").ConfigFactoryKeyHost<AppConfig>;
|
|
33
|
+
export default _default;
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { registerAs } from '@nestjs/config';
|
|
11
|
+
import { IsInt, IsString, IsIn, Min, Max, validateSync } from 'class-validator';
|
|
12
|
+
import { plainToClass } from 'class-transformer';
|
|
13
|
+
/**
|
|
14
|
+
* Application configuration class
|
|
15
|
+
* Validates environment variables and provides type-safe configuration
|
|
16
|
+
*/
|
|
17
|
+
export class AppConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Port number for the HTTP server
|
|
20
|
+
* Must be between 1 and 65535
|
|
21
|
+
*/
|
|
22
|
+
port;
|
|
23
|
+
/**
|
|
24
|
+
* Host address to bind the server to
|
|
25
|
+
* Examples: 'localhost', '0.0.0.0', '127.0.0.1'
|
|
26
|
+
*/
|
|
27
|
+
host;
|
|
28
|
+
/**
|
|
29
|
+
* Base path for the application
|
|
30
|
+
* If set, API will be available at {basePath}/api/v1
|
|
31
|
+
*/
|
|
32
|
+
basePath;
|
|
33
|
+
/**
|
|
34
|
+
* Node environment mode
|
|
35
|
+
* Determines logging behavior and other environment-specific settings
|
|
36
|
+
*/
|
|
37
|
+
nodeEnv;
|
|
38
|
+
/**
|
|
39
|
+
* Logging level for Pino logger
|
|
40
|
+
* Controls the verbosity of application logs
|
|
41
|
+
*/
|
|
42
|
+
logLevel;
|
|
43
|
+
}
|
|
44
|
+
__decorate([
|
|
45
|
+
IsInt(),
|
|
46
|
+
Min(1),
|
|
47
|
+
Max(65535),
|
|
48
|
+
__metadata("design:type", Number)
|
|
49
|
+
], AppConfig.prototype, "port", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
IsString(),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], AppConfig.prototype, "host", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
IsString(),
|
|
56
|
+
__metadata("design:type", String)
|
|
57
|
+
], AppConfig.prototype, "basePath", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
IsIn(['development', 'production', 'test']),
|
|
60
|
+
__metadata("design:type", String)
|
|
61
|
+
], AppConfig.prototype, "nodeEnv", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
IsIn(['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent']),
|
|
64
|
+
__metadata("design:type", String)
|
|
65
|
+
], AppConfig.prototype, "logLevel", void 0);
|
|
66
|
+
export default registerAs('app', () => {
|
|
67
|
+
const config = plainToClass(AppConfig, {
|
|
68
|
+
port: parseInt(process.env.LISTEN_PORT ?? '8080', 10),
|
|
69
|
+
host: process.env.LISTEN_HOST ?? '0.0.0.0',
|
|
70
|
+
basePath: (process.env.BASE_PATH ?? '').replace(/^\/+|\/+$/g, ''),
|
|
71
|
+
nodeEnv: process.env.NODE_ENV ?? 'production',
|
|
72
|
+
logLevel: process.env.LOG_LEVEL ?? 'warn',
|
|
73
|
+
});
|
|
74
|
+
const errors = validateSync(config, {
|
|
75
|
+
skipMissingProperties: false,
|
|
76
|
+
});
|
|
77
|
+
if (errors.length > 0) {
|
|
78
|
+
const errorMessages = errors.map(err => Object.values(err.constraints ?? {}).join(', '));
|
|
79
|
+
throw new Error(`App config validation error: ${errorMessages.join('; ')}`);
|
|
80
|
+
}
|
|
81
|
+
return config;
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=app.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.config.js","sourceRoot":"","sources":["../../../src/config/app.config.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,MAAM,OAAO,SAAS;IACpB;;;OAGG;IAII,IAAI,CAAU;IAErB;;;OAGG;IAEI,IAAI,CAAU;IAErB;;;OAGG;IAEI,QAAQ,CAAU;IAEzB;;;OAGG;IAEI,OAAO,CAAU;IAExB;;;OAGG;IAEI,QAAQ,CAAU;CAC1B;AA7BQ;IAHN,KAAK,EAAE;IACP,GAAG,CAAC,CAAC,CAAC;IACN,GAAG,CAAC,KAAK,CAAC;;uCACU;AAOd;IADN,QAAQ,EAAE;;uCACU;AAOd;IADN,QAAQ,EAAE;;2CACc;AAOlB;IADN,IAAI,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;;0CACpB;AAOjB;IADN,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;;2CAC5C;AAG3B,eAAe,UAAU,CAAC,KAAK,EAAE,GAAc,EAAE;IAC/C,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,EAAE;QACrC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,MAAM,EAAE,EAAE,CAAC;QACrD,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,SAAS;QAC1C,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;QACjE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY;QAC7C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM;KAC1C,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE;QAClC,qBAAqB,EAAE,KAAK;KAC7B,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzF,MAAM,IAAI,KAAK,CAAC,gCAAgC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AppConfigService } from '../modules/app-config/app-config.service.js';
|
|
2
|
+
import type { AccountConfig } from '../modules/app-config/interfaces/app-config.interface.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validatable configuration class for library mode
|
|
5
|
+
*/
|
|
6
|
+
export declare class LibraryConfigDto {
|
|
7
|
+
/**
|
|
8
|
+
* Named account configurations
|
|
9
|
+
*/
|
|
10
|
+
accounts: Record<string, any>;
|
|
11
|
+
/**
|
|
12
|
+
* Request timeout in seconds
|
|
13
|
+
* Must be between 1 and 600 (10 minutes)
|
|
14
|
+
*/
|
|
15
|
+
requestTimeoutSecs: number;
|
|
16
|
+
/**
|
|
17
|
+
* Number of retry attempts on error
|
|
18
|
+
* Must be between 0 and 10
|
|
19
|
+
*/
|
|
20
|
+
retryAttempts: number;
|
|
21
|
+
/**
|
|
22
|
+
* Delay between retry attempts in milliseconds
|
|
23
|
+
* Must be between 0 and 60000 (1 minute)
|
|
24
|
+
*/
|
|
25
|
+
retryDelayMs: number;
|
|
26
|
+
/**
|
|
27
|
+
* Time-to-live for idempotency records in cache (minutes)
|
|
28
|
+
* Must be between 1 and 1440 (24 hours)
|
|
29
|
+
*/
|
|
30
|
+
idempotencyTtlMinutes: number;
|
|
31
|
+
/**
|
|
32
|
+
* Logging level
|
|
33
|
+
*/
|
|
34
|
+
logLevel: 'debug' | 'info' | 'warn' | 'error';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Library configuration service implementation
|
|
38
|
+
* Validates provided config object and implements AppConfigService interface
|
|
39
|
+
*/
|
|
40
|
+
export declare class LibraryConfigService extends AppConfigService {
|
|
41
|
+
private readonly config;
|
|
42
|
+
constructor(config: any);
|
|
43
|
+
private validate;
|
|
44
|
+
get<T = any>(path: string): T | undefined;
|
|
45
|
+
getAccount(accountName: string): AccountConfig;
|
|
46
|
+
getAllAccounts(): Record<string, AccountConfig>;
|
|
47
|
+
get requestTimeoutSecs(): number;
|
|
48
|
+
get retryAttempts(): number;
|
|
49
|
+
get retryDelayMs(): number;
|
|
50
|
+
get idempotencyTtlMinutes(): number;
|
|
51
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
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 { IsInt, IsObject, IsOptional, IsString, Min, Max, validateSync, IsIn, } from 'class-validator';
|
|
11
|
+
import { plainToClass } from 'class-transformer';
|
|
12
|
+
import { AppConfigService } from '../modules/app-config/app-config.service.js';
|
|
13
|
+
/**
|
|
14
|
+
* Validatable configuration class for library mode
|
|
15
|
+
*/
|
|
16
|
+
export class LibraryConfigDto {
|
|
17
|
+
/**
|
|
18
|
+
* Named account configurations
|
|
19
|
+
*/
|
|
20
|
+
accounts;
|
|
21
|
+
/**
|
|
22
|
+
* Request timeout in seconds
|
|
23
|
+
* Must be between 1 and 600 (10 minutes)
|
|
24
|
+
*/
|
|
25
|
+
requestTimeoutSecs = 60;
|
|
26
|
+
/**
|
|
27
|
+
* Number of retry attempts on error
|
|
28
|
+
* Must be between 0 and 10
|
|
29
|
+
*/
|
|
30
|
+
retryAttempts = 3;
|
|
31
|
+
/**
|
|
32
|
+
* Delay between retry attempts in milliseconds
|
|
33
|
+
* Must be between 0 and 60000 (1 minute)
|
|
34
|
+
*/
|
|
35
|
+
retryDelayMs = 1000;
|
|
36
|
+
/**
|
|
37
|
+
* Time-to-live for idempotency records in cache (minutes)
|
|
38
|
+
* Must be between 1 and 1440 (24 hours)
|
|
39
|
+
*/
|
|
40
|
+
idempotencyTtlMinutes = 10;
|
|
41
|
+
/**
|
|
42
|
+
* Logging level
|
|
43
|
+
*/
|
|
44
|
+
logLevel = 'warn';
|
|
45
|
+
}
|
|
46
|
+
__decorate([
|
|
47
|
+
IsObject(),
|
|
48
|
+
__metadata("design:type", Object)
|
|
49
|
+
], LibraryConfigDto.prototype, "accounts", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
IsOptional(),
|
|
52
|
+
IsInt(),
|
|
53
|
+
Min(1),
|
|
54
|
+
Max(600),
|
|
55
|
+
__metadata("design:type", Number)
|
|
56
|
+
], LibraryConfigDto.prototype, "requestTimeoutSecs", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
IsOptional(),
|
|
59
|
+
IsInt(),
|
|
60
|
+
Min(0),
|
|
61
|
+
Max(10),
|
|
62
|
+
__metadata("design:type", Number)
|
|
63
|
+
], LibraryConfigDto.prototype, "retryAttempts", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
IsOptional(),
|
|
66
|
+
IsInt(),
|
|
67
|
+
Min(0),
|
|
68
|
+
Max(60000),
|
|
69
|
+
__metadata("design:type", Number)
|
|
70
|
+
], LibraryConfigDto.prototype, "retryDelayMs", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
IsOptional(),
|
|
73
|
+
IsInt(),
|
|
74
|
+
Min(1),
|
|
75
|
+
Max(1440),
|
|
76
|
+
__metadata("design:type", Number)
|
|
77
|
+
], LibraryConfigDto.prototype, "idempotencyTtlMinutes", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
IsOptional(),
|
|
80
|
+
IsIn(['debug', 'info', 'warn', 'error']),
|
|
81
|
+
__metadata("design:type", String)
|
|
82
|
+
], LibraryConfigDto.prototype, "logLevel", void 0);
|
|
83
|
+
/**
|
|
84
|
+
* Account configuration validation class
|
|
85
|
+
*/
|
|
86
|
+
class AccountConfigValidationDto {
|
|
87
|
+
platform;
|
|
88
|
+
auth;
|
|
89
|
+
channelId;
|
|
90
|
+
maxBody;
|
|
91
|
+
}
|
|
92
|
+
__decorate([
|
|
93
|
+
IsString(),
|
|
94
|
+
__metadata("design:type", String)
|
|
95
|
+
], AccountConfigValidationDto.prototype, "platform", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
IsOptional(),
|
|
98
|
+
IsObject(),
|
|
99
|
+
__metadata("design:type", Object)
|
|
100
|
+
], AccountConfigValidationDto.prototype, "auth", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
IsOptional(),
|
|
103
|
+
__metadata("design:type", Object)
|
|
104
|
+
], AccountConfigValidationDto.prototype, "channelId", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
IsOptional(),
|
|
107
|
+
IsInt(),
|
|
108
|
+
Min(1),
|
|
109
|
+
Max(500000),
|
|
110
|
+
__metadata("design:type", Number)
|
|
111
|
+
], AccountConfigValidationDto.prototype, "maxBody", void 0);
|
|
112
|
+
/**
|
|
113
|
+
* Library configuration service implementation
|
|
114
|
+
* Validates provided config object and implements AppConfigService interface
|
|
115
|
+
*/
|
|
116
|
+
export class LibraryConfigService extends AppConfigService {
|
|
117
|
+
config;
|
|
118
|
+
constructor(config) {
|
|
119
|
+
super();
|
|
120
|
+
this.config = this.validate(config);
|
|
121
|
+
}
|
|
122
|
+
validate(config) {
|
|
123
|
+
const dto = plainToClass(LibraryConfigDto, config);
|
|
124
|
+
const errors = validateSync(dto, {
|
|
125
|
+
skipMissingProperties: false,
|
|
126
|
+
whitelist: true, // true here differs from YamlConfigDto false, but for library mode strict is probably better
|
|
127
|
+
});
|
|
128
|
+
const errorMessages = [];
|
|
129
|
+
if (errors.length > 0) {
|
|
130
|
+
for (const err of errors) {
|
|
131
|
+
const constraints = err.constraints ? Object.values(err.constraints).join(', ') : '';
|
|
132
|
+
errorMessages.push(`${err.property}: ${constraints}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Validate accounts manually
|
|
136
|
+
const accountErrorMessages = [];
|
|
137
|
+
if (dto.accounts && typeof dto.accounts === 'object') {
|
|
138
|
+
for (const [accountName, accountConfig] of Object.entries(dto.accounts)) {
|
|
139
|
+
const accountDto = plainToClass(AccountConfigValidationDto, accountConfig);
|
|
140
|
+
const accountErrors = validateSync(accountDto);
|
|
141
|
+
if (accountErrors.length > 0) {
|
|
142
|
+
const constraints = accountErrors
|
|
143
|
+
.map(err => {
|
|
144
|
+
const msg = err.constraints ? Object.values(err.constraints).join(', ') : '';
|
|
145
|
+
return `${err.property}: ${msg}`;
|
|
146
|
+
})
|
|
147
|
+
.join('; ');
|
|
148
|
+
accountErrorMessages.push(`account "${accountName}": ${constraints}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (!errorMessages.some(e => e.includes('accounts'))) {
|
|
153
|
+
// Only add this error if accounts is missing/invalid type was not already caught (but IsObject catches types)
|
|
154
|
+
// Wait, if accounts is missing, 'validateSync' will catch it if I didn't make it optional?
|
|
155
|
+
// I didn't make it optional in LibraryConfigDto, so it is required.
|
|
156
|
+
}
|
|
157
|
+
const allErrors = [...errorMessages, ...accountErrorMessages];
|
|
158
|
+
if (allErrors.length > 0) {
|
|
159
|
+
throw new Error(`Library config validation error: ${allErrors.join('; ')}`);
|
|
160
|
+
}
|
|
161
|
+
return dto;
|
|
162
|
+
}
|
|
163
|
+
get(path) {
|
|
164
|
+
const keys = path.split('.');
|
|
165
|
+
let value = this.config;
|
|
166
|
+
for (const key of keys) {
|
|
167
|
+
if (value === undefined || value === null) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
value = value[key];
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
getAccount(accountName) {
|
|
175
|
+
const account = this.config.accounts[accountName];
|
|
176
|
+
if (!account) {
|
|
177
|
+
throw new Error(`Account "${accountName}" not found in configuration`);
|
|
178
|
+
}
|
|
179
|
+
return account;
|
|
180
|
+
}
|
|
181
|
+
getAllAccounts() {
|
|
182
|
+
return this.config.accounts;
|
|
183
|
+
}
|
|
184
|
+
get requestTimeoutSecs() {
|
|
185
|
+
return this.config.requestTimeoutSecs;
|
|
186
|
+
}
|
|
187
|
+
get retryAttempts() {
|
|
188
|
+
return this.config.retryAttempts;
|
|
189
|
+
}
|
|
190
|
+
get retryDelayMs() {
|
|
191
|
+
return this.config.retryDelayMs;
|
|
192
|
+
}
|
|
193
|
+
get idempotencyTtlMinutes() {
|
|
194
|
+
return this.config.idempotencyTtlMinutes;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=library.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.config.js","sourceRoot":"","sources":["../../../src/config/library.config.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,GAAG,EACH,GAAG,EACH,YAAY,EACZ,IAAI,GACL,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAG/E;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IAEH,QAAQ,CAAuB;IAE/B;;;OAGG;IAKH,kBAAkB,GAAW,EAAE,CAAC;IAEhC;;;OAGG;IAKH,aAAa,GAAW,CAAC,CAAC;IAE1B;;;OAGG;IAKH,YAAY,GAAW,IAAI,CAAC;IAE5B;;;OAGG;IAKH,qBAAqB,GAAW,EAAE,CAAC;IAEnC;;OAEG;IAGH,QAAQ,GAAwC,MAAM,CAAC;CACxD;AAhDC;IADC,QAAQ,EAAE;;kDACoB;AAU/B;IAJC,UAAU,EAAE;IACZ,KAAK,EAAE;IACP,GAAG,CAAC,CAAC,CAAC;IACN,GAAG,CAAC,GAAG,CAAC;;4DACuB;AAUhC;IAJC,UAAU,EAAE;IACZ,KAAK,EAAE;IACP,GAAG,CAA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AAC,kBAAkB,CAAC;IACxC,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;IACnC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;IAClC,CAAC;IAED,IAAI,qBAAqB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML configuration validation class
|
|
3
|
+
* Validates the structure and values from config.yaml
|
|
4
|
+
*/
|
|
5
|
+
export declare class YamlConfigDto {
|
|
6
|
+
/**
|
|
7
|
+
* Request timeout in seconds
|
|
8
|
+
* Must be between 1 and 600 (10 minutes)
|
|
9
|
+
*/
|
|
10
|
+
requestTimeoutSecs: number;
|
|
11
|
+
/**
|
|
12
|
+
* Number of retry attempts on error
|
|
13
|
+
* Must be between 0 and 10
|
|
14
|
+
*/
|
|
15
|
+
retryAttempts: number;
|
|
16
|
+
/**
|
|
17
|
+
* Delay between retry attempts in milliseconds
|
|
18
|
+
* Must be between 0 and 60000 (1 minute)
|
|
19
|
+
*/
|
|
20
|
+
retryDelayMs: number;
|
|
21
|
+
/**
|
|
22
|
+
* Time-to-live for idempotency records in cache (minutes)
|
|
23
|
+
* Must be between 1 and 1440 (24 hours)
|
|
24
|
+
*/
|
|
25
|
+
idempotencyTtlMinutes: number;
|
|
26
|
+
/**
|
|
27
|
+
* Named account configurations
|
|
28
|
+
*/
|
|
29
|
+
accounts: Record<string, any>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates YAML configuration object
|
|
33
|
+
* @param config - Raw configuration object from YAML file
|
|
34
|
+
* @throws Error if validation fails
|
|
35
|
+
* @returns Validated configuration object
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateYamlConfig(config: any): YamlConfigDto;
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { IsInt, IsString, IsObject, IsOptional, Min, Max, validateSync } from 'class-validator';
|
|
11
|
+
import { plainToClass } from 'class-transformer';
|
|
12
|
+
/**
|
|
13
|
+
* Account configuration validation class
|
|
14
|
+
* Validates the structure and values of account configurations
|
|
15
|
+
*/
|
|
16
|
+
class AccountConfigValidationDto {
|
|
17
|
+
/**
|
|
18
|
+
* Platform name
|
|
19
|
+
* Must be a non-empty string
|
|
20
|
+
*/
|
|
21
|
+
platform;
|
|
22
|
+
/**
|
|
23
|
+
* Authentication configuration
|
|
24
|
+
* Optional, must be an object if present
|
|
25
|
+
*/
|
|
26
|
+
auth;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum body length for this account (characters)
|
|
29
|
+
* Optional, must be between 1 and 500000
|
|
30
|
+
*/
|
|
31
|
+
maxBody;
|
|
32
|
+
}
|
|
33
|
+
__decorate([
|
|
34
|
+
IsString(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], AccountConfigValidationDto.prototype, "platform", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
IsOptional(),
|
|
39
|
+
IsObject(),
|
|
40
|
+
__metadata("design:type", Object)
|
|
41
|
+
], AccountConfigValidationDto.prototype, "auth", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
IsOptional(),
|
|
44
|
+
IsInt(),
|
|
45
|
+
Min(1),
|
|
46
|
+
Max(500000),
|
|
47
|
+
__metadata("design:type", Number)
|
|
48
|
+
], AccountConfigValidationDto.prototype, "maxBody", void 0);
|
|
49
|
+
/**
|
|
50
|
+
* YAML configuration validation class
|
|
51
|
+
* Validates the structure and values from config.yaml
|
|
52
|
+
*/
|
|
53
|
+
export class YamlConfigDto {
|
|
54
|
+
/**
|
|
55
|
+
* Request timeout in seconds
|
|
56
|
+
* Must be between 1 and 600 (10 minutes)
|
|
57
|
+
*/
|
|
58
|
+
requestTimeoutSecs = 60;
|
|
59
|
+
/**
|
|
60
|
+
* Number of retry attempts on error
|
|
61
|
+
* Must be between 0 and 10
|
|
62
|
+
*/
|
|
63
|
+
retryAttempts = 3;
|
|
64
|
+
/**
|
|
65
|
+
* Delay between retry attempts in milliseconds
|
|
66
|
+
* Must be between 0 and 60000 (1 minute)
|
|
67
|
+
*/
|
|
68
|
+
retryDelayMs = 1000;
|
|
69
|
+
/**
|
|
70
|
+
* Time-to-live for idempotency records in cache (minutes)
|
|
71
|
+
* Must be between 1 and 1440 (24 hours)
|
|
72
|
+
*/
|
|
73
|
+
idempotencyTtlMinutes = 10;
|
|
74
|
+
/**
|
|
75
|
+
* Named account configurations
|
|
76
|
+
*/
|
|
77
|
+
accounts = {};
|
|
78
|
+
}
|
|
79
|
+
__decorate([
|
|
80
|
+
IsInt(),
|
|
81
|
+
Min(1),
|
|
82
|
+
Max(600),
|
|
83
|
+
__metadata("design:type", Number)
|
|
84
|
+
], YamlConfigDto.prototype, "requestTimeoutSecs", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
IsInt(),
|
|
87
|
+
Min(0),
|
|
88
|
+
Max(10),
|
|
89
|
+
__metadata("design:type", Number)
|
|
90
|
+
], YamlConfigDto.prototype, "retryAttempts", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
IsInt(),
|
|
93
|
+
Min(0),
|
|
94
|
+
Max(60000),
|
|
95
|
+
__metadata("design:type", Number)
|
|
96
|
+
], YamlConfigDto.prototype, "retryDelayMs", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
IsInt(),
|
|
99
|
+
Min(1),
|
|
100
|
+
Max(1440),
|
|
101
|
+
__metadata("design:type", Number)
|
|
102
|
+
], YamlConfigDto.prototype, "idempotencyTtlMinutes", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
IsOptional(),
|
|
105
|
+
IsObject(),
|
|
106
|
+
__metadata("design:type", Object)
|
|
107
|
+
], YamlConfigDto.prototype, "accounts", void 0);
|
|
108
|
+
/**
|
|
109
|
+
* Validates YAML configuration object
|
|
110
|
+
* @param config - Raw configuration object from YAML file
|
|
111
|
+
* @throws Error if validation fails
|
|
112
|
+
* @returns Validated configuration object
|
|
113
|
+
*/
|
|
114
|
+
export function validateYamlConfig(config) {
|
|
115
|
+
const dto = plainToClass(YamlConfigDto, config);
|
|
116
|
+
const errors = validateSync(dto, {
|
|
117
|
+
skipMissingProperties: false,
|
|
118
|
+
whitelist: false, // Allow additional properties in accounts
|
|
119
|
+
});
|
|
120
|
+
const errorMessages = [];
|
|
121
|
+
if (errors.length > 0) {
|
|
122
|
+
for (const err of errors) {
|
|
123
|
+
const constraints = err.constraints ? Object.values(err.constraints).join(', ') : '';
|
|
124
|
+
errorMessages.push(`${err.property}: ${constraints}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const accountErrorMessages = [];
|
|
128
|
+
if (dto.accounts && typeof dto.accounts === 'object') {
|
|
129
|
+
for (const [accountName, accountConfig] of Object.entries(dto.accounts)) {
|
|
130
|
+
const accountDto = plainToClass(AccountConfigValidationDto, accountConfig);
|
|
131
|
+
const accountErrors = validateSync(accountDto, {
|
|
132
|
+
skipMissingProperties: false,
|
|
133
|
+
whitelist: false,
|
|
134
|
+
});
|
|
135
|
+
if (accountErrors.length > 0) {
|
|
136
|
+
const constraints = accountErrors
|
|
137
|
+
.map(err => {
|
|
138
|
+
const msg = err.constraints ? Object.values(err.constraints).join(', ') : '';
|
|
139
|
+
return `${err.property}: ${msg}`;
|
|
140
|
+
})
|
|
141
|
+
.join('; ');
|
|
142
|
+
accountErrorMessages.push(`account "${accountName}": ${constraints}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const allErrors = [...errorMessages, ...accountErrorMessages];
|
|
147
|
+
if (allErrors.length > 0) {
|
|
148
|
+
throw new Error(`YAML config validation error: ${allErrors.join('; ')}`);
|
|
149
|
+
}
|
|
150
|
+
return dto;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=yaml-config.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-config.dto.js","sourceRoot":"","sources":["../../../src/config/yaml-config.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,MAAM,0BAA0B;IAC9B;;;OAGG;IAEH,QAAQ,CAAU;IAElB;;;OAGG;IAGH,IAAI,CAAuB;IAE3B;;;OAGG;IAKH,OAAO,CAAU;CAClB;AAnBC;IADC,QAAQ,EAAE;;4DACO;AAQlB;IAFC,UAAU,EAAE;IACZ,QAAQ,EAAE;;wDACgB;AAU3B;IAJC,UAAU,EAAE;IACZ,KAAK,EAAE;IACP,GAAG,CAAC,CAAC,CAAC;IACN,GAAG,CAAC,MAAM,CAAC;;2DACK;AAGnB;;;GAGG;AACH,MAAM,OAAO,aAAa;IACxB;;;OAGG;IAIH,kBAAkB,GAAW,EAAE,CAAC;IAEhC;;;OAGG;IAIH,aAAa,GAAW,CAAC,CAAC;IAE1B;;;OAGG;IAIH,Y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@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace for YAML configuration in NestJS ConfigService
|
|
3
|
+
*/
|
|
4
|
+
export declare const YAML_CONFIG_NAMESPACE = "yaml_config";
|
|
5
|
+
/**
|
|
6
|
+
* Loads and parses YAML configuration file
|
|
7
|
+
* Reads the file from CONFIG_PATH environment variable or default location
|
|
8
|
+
* Automatically substitutes environment variables in the configuration
|
|
9
|
+
* Validates the configuration structure and values
|
|
10
|
+
* @returns Parsed and validated configuration object with environment variables resolved
|
|
11
|
+
* @throws Error if the configuration file cannot be loaded, parsed, or validated
|
|
12
|
+
*/
|
|
13
|
+
declare const _default: (() => import("./yaml-config.dto.js").YamlConfigDto) & import("@nestjs/config").ConfigFactoryKeyHost<import("./yaml-config.dto.js").YamlConfigDto>;
|
|
14
|
+
export default _default;
|