@buka/nestjs-kit 4.0.0 → 4.1.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/CHANGELOG.md +22 -3
- package/dist/index.d.mts +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +187 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -19
- package/dist/index.mjs.map +1 -1
- package/docs/core/urn.md +11 -11
- package/docs/exception.md +123 -121
- package/docs/index.md +6 -0
- package/docs/logger.md +289 -0
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [4.
|
|
3
|
+
## [4.1.2](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.1.1...v4.1.2) (2026-05-21)
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
### Performance Improvements
|
|
7
|
+
|
|
8
|
+
* 优化 openbao module 报错信息提示准确性 ([2245b17](https://github.com/buka-ltd/npm.nestjs-kit/commit/2245b1765b7d65ee4827727eb2f5fddb67b523a2))
|
|
9
|
+
|
|
10
|
+
## [4.1.1](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.1.0...v4.1.1) (2026-05-10)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* rename buka-inc to buka-ltd ([43e72ca](https://github.com/buka-ltd/npm.nestjs-kit/commit/43e72ca4065676cc384f07daf1953f2e04565244))
|
|
16
|
+
|
|
17
|
+
## [4.1.0](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.0.0...v4.1.0) (2026-05-10)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- add logger module ([5ead6da](https://github.com/buka-ltd/npm.nestjs-kit/commit/5ead6da6c15ae46929e713063b2dd0d580d63996))
|
|
22
|
+
|
|
23
|
+
## [4.0.0](https://github.com/buka-ltd/npm.nestjs-kit/compare/v3.0.1...v4.0.0) (2026-05-06)
|
|
24
|
+
|
|
6
25
|
### ⚠ BREAKING CHANGES
|
|
7
26
|
|
|
8
|
-
|
|
27
|
+
- overhaul entire project architecture
|
|
9
28
|
|
|
10
29
|
### Code Refactoring
|
|
11
30
|
|
|
12
|
-
|
|
31
|
+
- overhaul entire project architecture ([b4047a7](https://github.com/buka-ltd/npm.nestjs-kit/commit/b4047a790498a9f4b967d33830d6786ba3b24642))
|
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ import { ApiPropertyOptions, OpenAPIObject } from "@nestjs/swagger";
|
|
|
6
6
|
import { Keq, KeqMiddleware, KeqOperation, KeqPathParameterInit, KeqQueryInit, KeqRequest } from "keq";
|
|
7
7
|
import { Base32, ErrorCategory, ErrorCategory as ErrorCategory$1, ErrorCode, ErrorCodeOptions } from "@buka/error-codes";
|
|
8
8
|
import { Exception, ExceptionDetail, ExceptionDetail as ExceptionDetail$1, ExceptionOptions as ExceptionOptions$1 } from "@buka/exception";
|
|
9
|
+
import { Logger, LoggerErrorInterceptor } from "nestjs-pino";
|
|
9
10
|
import { Readable } from "node:stream";
|
|
10
11
|
import * as _$type_fest0 from "type-fest";
|
|
11
12
|
import { Class, JsonValue, ValueOf } from "type-fest";
|
|
@@ -18451,6 +18452,79 @@ declare class EnvelopeEncryptionService {
|
|
|
18451
18452
|
listCiphers(): CipherMetadata[];
|
|
18452
18453
|
}
|
|
18453
18454
|
//#endregion
|
|
18455
|
+
//#region src/modules/logger/types/logger-module-options.d.ts
|
|
18456
|
+
/**
|
|
18457
|
+
* LoggerModule 配置
|
|
18458
|
+
*
|
|
18459
|
+
* 与 LoggerConfig 基类字段一一对应
|
|
18460
|
+
*/
|
|
18461
|
+
interface LoggerModuleOptions {
|
|
18462
|
+
/** 服务名称,Grafana/Loki 中按服务过滤日志 */
|
|
18463
|
+
serviceName?: string;
|
|
18464
|
+
/** 运行环境,默认取 NODE_ENV */
|
|
18465
|
+
environment?: string;
|
|
18466
|
+
/** 服务版本号,生产环境由 CI/CD 注入 */
|
|
18467
|
+
version?: string;
|
|
18468
|
+
/** 日志级别,默认 info */
|
|
18469
|
+
level?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
18470
|
+
/** 开发模式——启用 pino-pretty 彩色输出 */
|
|
18471
|
+
pretty?: boolean;
|
|
18472
|
+
}
|
|
18473
|
+
//#endregion
|
|
18474
|
+
//#region src/modules/logger/logger.module.d.ts
|
|
18475
|
+
/**
|
|
18476
|
+
* 统一日志模块
|
|
18477
|
+
*
|
|
18478
|
+
* 基于 nestjs-pino,预配置 Grafana/Loki 友好的 JSON 日志格式。
|
|
18479
|
+
*
|
|
18480
|
+
* @example
|
|
18481
|
+
* // 直接使用
|
|
18482
|
+
* LoggerModule.register({ serviceName: 'my-service' })
|
|
18483
|
+
*
|
|
18484
|
+
* // 配合 @buka/nestjs-config
|
|
18485
|
+
* ConfigModule.inject(PinoConfig, LoggerModule, (config) => ({...config}))
|
|
18486
|
+
*/
|
|
18487
|
+
declare class LoggerModule {
|
|
18488
|
+
static register(options?: LoggerModuleOptions): DynamicModule;
|
|
18489
|
+
static registerAsync(options: {
|
|
18490
|
+
imports?: any[];
|
|
18491
|
+
inject?: any[];
|
|
18492
|
+
useFactory: (...args: any[]) => LoggerModuleOptions | Promise<LoggerModuleOptions>;
|
|
18493
|
+
}): DynamicModule;
|
|
18494
|
+
/**
|
|
18495
|
+
* 将 LoggerModuleOptions 转换为 nestjs-pino 的 Params
|
|
18496
|
+
*/
|
|
18497
|
+
private static buildParams;
|
|
18498
|
+
}
|
|
18499
|
+
//#endregion
|
|
18500
|
+
//#region src/modules/logger/decorators/inject-logger.decorator.d.ts
|
|
18501
|
+
/**
|
|
18502
|
+
* 注入 Logger,自动以类名为日志上下文
|
|
18503
|
+
*
|
|
18504
|
+
* 用法:
|
|
18505
|
+
* @InjectLogger()
|
|
18506
|
+
* private readonly logger: Logger
|
|
18507
|
+
*
|
|
18508
|
+
* 等价于:
|
|
18509
|
+
* @InjectPinoLogger(MyService.name)
|
|
18510
|
+
* private readonly logger: Logger
|
|
18511
|
+
*/
|
|
18512
|
+
declare function InjectLogger(context?: string): ParameterDecorator;
|
|
18513
|
+
//#endregion
|
|
18514
|
+
//#region src/modules/logger/logger.config.d.ts
|
|
18515
|
+
/**
|
|
18516
|
+
* 日志配置基类
|
|
18517
|
+
*
|
|
18518
|
+
* 项目中的日志配置应继承此类并通过 @Configuration('xxx') 绑定环境变量前缀
|
|
18519
|
+
*/
|
|
18520
|
+
declare class LoggerConfig {
|
|
18521
|
+
pretty: boolean;
|
|
18522
|
+
level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
18523
|
+
serviceName: string;
|
|
18524
|
+
environment: string;
|
|
18525
|
+
version: string;
|
|
18526
|
+
}
|
|
18527
|
+
//#endregion
|
|
18454
18528
|
//#region src/modules/object-storage/types/options.d.ts
|
|
18455
18529
|
interface ObjectStorageOptions {
|
|
18456
18530
|
prefix?: boolean;
|
|
@@ -18578,5 +18652,5 @@ declare class ObjectStorageService implements OnModuleInit {
|
|
|
18578
18652
|
*/
|
|
18579
18653
|
declare function stableStringify(value: unknown): string;
|
|
18580
18654
|
//#endregion
|
|
18581
|
-
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, EagerType, type EncryptCommand, EncryptedPayload, EntityRef, Enum, EnumPropertyMetadata, EnvelopeEncryptionModule, type EnvelopeEncryptionModuleOptions, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, type ErrorCodeOptions, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, type ExceptionConstructor, type ExceptionConstructorWithArgs, type ExceptionDetail, ExceptionDetailSchema, ExceptionModule, type ExceptionModuleOptions as ExceptionNestModuleOptions, type ExceptionOptions, type ExceptionOptionsWithFactory, type ExceptionOptionsWithMessage, ExcludeDefinedOpt, ExcludeHidden, ExcludeOpt, ExcludeRef, ExcludeScalarClass, FeatureException, FilterQuery, FilterQueryOperator, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, type HttpExceptionOptions, IEntityPrimaryKey, IFilter, IFilterQuery, IFilterQueryCollectionCondition, IFilterQueryCondition, IFilterQueryNestedProperty, IFilterQueryObject, IFilterQueryProperty, IListResponseBody, IListResponseBodyMeta, INextCursorPageParameters, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IResponseBody, IS_CROCKFORD_BASE32, IS_IDENTIFIER_URN, IS_NAMESPACE_URN, IS_RESOURCE_URN, IS_SCALAR_DICTIONARY, IS_URN, IdentifierUrn, IsBrowserRequest, IsCrockfordBase32, IsHidden, IsIdentifierUrn, IsNamespaceUrn, IsOpt, IsResourceUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListPropertyMetadata, ListResponseBodyType, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, Model, ModelMetadata, ModelOptions, ModelRegister, ModelSchemaOptions, ModuleExceptions, type ExceptionModuleOptions$1 as ModuleExceptionsOptions, NamespaceUrn, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageModuleOptions, ObjectStorageOptions, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuth, OpenBaoAppRoleAuthConfig, OpenBaoAuthMethod, OpenBaoAuthResponse, OpenBaoHttpClient, OpenBaoKubernetesAuth, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoModuleOptions, OpenBaoTokenAuth, OpenBaoTokenAuthConfig, OpenBaoTokenLookupSelfResponse, OpenBaoTokenManager, OpenBaoUserpassAuth, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, PropertyKind, PropertyMetadata, RateLimitException, type ReencryptCommand, RefAssociationMetadata, type ResolveExceptions, ResourceUrn, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
18655
|
+
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, EagerType, type EncryptCommand, EncryptedPayload, EntityRef, Enum, EnumPropertyMetadata, EnvelopeEncryptionModule, type EnvelopeEncryptionModuleOptions, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, type ErrorCodeOptions, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, type ExceptionConstructor, type ExceptionConstructorWithArgs, type ExceptionDetail, ExceptionDetailSchema, ExceptionModule, type ExceptionModuleOptions as ExceptionNestModuleOptions, type ExceptionOptions, type ExceptionOptionsWithFactory, type ExceptionOptionsWithMessage, ExcludeDefinedOpt, ExcludeHidden, ExcludeOpt, ExcludeRef, ExcludeScalarClass, FeatureException, FilterQuery, FilterQueryOperator, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, type HttpExceptionOptions, IEntityPrimaryKey, IFilter, IFilterQuery, IFilterQueryCollectionCondition, IFilterQueryCondition, IFilterQueryNestedProperty, IFilterQueryObject, IFilterQueryProperty, IListResponseBody, IListResponseBodyMeta, INextCursorPageParameters, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IResponseBody, IS_CROCKFORD_BASE32, IS_IDENTIFIER_URN, IS_NAMESPACE_URN, IS_RESOURCE_URN, IS_SCALAR_DICTIONARY, IS_URN, IdentifierUrn, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsHidden, IsIdentifierUrn, IsNamespaceUrn, IsOpt, IsResourceUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListPropertyMetadata, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, type LoggerModuleOptions, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, Model, ModelMetadata, ModelOptions, ModelRegister, ModelSchemaOptions, ModuleExceptions, type ExceptionModuleOptions$1 as ModuleExceptionsOptions, NamespaceUrn, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageModuleOptions, ObjectStorageOptions, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuth, OpenBaoAppRoleAuthConfig, OpenBaoAuthMethod, OpenBaoAuthResponse, OpenBaoHttpClient, OpenBaoKubernetesAuth, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoModuleOptions, OpenBaoTokenAuth, OpenBaoTokenAuthConfig, OpenBaoTokenLookupSelfResponse, OpenBaoTokenManager, OpenBaoUserpassAuth, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, PropertyKind, PropertyMetadata, RateLimitException, type ReencryptCommand, RefAssociationMetadata, type ResolveExceptions, ResourceUrn, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
18582
18656
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { AnyEntity, Config, Cursor, DefineConfig, EmbeddedOptions, EntityManager
|
|
|
8
8
|
import { Keq, KeqMiddleware, KeqOperation, KeqPathParameterInit, KeqQueryInit, KeqRequest } from "keq";
|
|
9
9
|
import { Base32, ErrorCategory, ErrorCategory as ErrorCategory$1, ErrorCode, ErrorCodeOptions } from "@buka/error-codes";
|
|
10
10
|
import { Exception, ExceptionDetail, ExceptionDetail as ExceptionDetail$1, ExceptionOptions as ExceptionOptions$1 } from "@buka/exception";
|
|
11
|
+
import { Logger, LoggerErrorInterceptor } from "nestjs-pino";
|
|
11
12
|
import { Readable } from "node:stream";
|
|
12
13
|
|
|
13
14
|
//#region src/swagger-patcher/deep-objectify-queries.d.ts
|
|
@@ -18451,6 +18452,79 @@ declare class EnvelopeEncryptionService {
|
|
|
18451
18452
|
listCiphers(): CipherMetadata[];
|
|
18452
18453
|
}
|
|
18453
18454
|
//#endregion
|
|
18455
|
+
//#region src/modules/logger/types/logger-module-options.d.ts
|
|
18456
|
+
/**
|
|
18457
|
+
* LoggerModule 配置
|
|
18458
|
+
*
|
|
18459
|
+
* 与 LoggerConfig 基类字段一一对应
|
|
18460
|
+
*/
|
|
18461
|
+
interface LoggerModuleOptions {
|
|
18462
|
+
/** 服务名称,Grafana/Loki 中按服务过滤日志 */
|
|
18463
|
+
serviceName?: string;
|
|
18464
|
+
/** 运行环境,默认取 NODE_ENV */
|
|
18465
|
+
environment?: string;
|
|
18466
|
+
/** 服务版本号,生产环境由 CI/CD 注入 */
|
|
18467
|
+
version?: string;
|
|
18468
|
+
/** 日志级别,默认 info */
|
|
18469
|
+
level?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
18470
|
+
/** 开发模式——启用 pino-pretty 彩色输出 */
|
|
18471
|
+
pretty?: boolean;
|
|
18472
|
+
}
|
|
18473
|
+
//#endregion
|
|
18474
|
+
//#region src/modules/logger/logger.module.d.ts
|
|
18475
|
+
/**
|
|
18476
|
+
* 统一日志模块
|
|
18477
|
+
*
|
|
18478
|
+
* 基于 nestjs-pino,预配置 Grafana/Loki 友好的 JSON 日志格式。
|
|
18479
|
+
*
|
|
18480
|
+
* @example
|
|
18481
|
+
* // 直接使用
|
|
18482
|
+
* LoggerModule.register({ serviceName: 'my-service' })
|
|
18483
|
+
*
|
|
18484
|
+
* // 配合 @buka/nestjs-config
|
|
18485
|
+
* ConfigModule.inject(PinoConfig, LoggerModule, (config) => ({...config}))
|
|
18486
|
+
*/
|
|
18487
|
+
declare class LoggerModule {
|
|
18488
|
+
static register(options?: LoggerModuleOptions): DynamicModule;
|
|
18489
|
+
static registerAsync(options: {
|
|
18490
|
+
imports?: any[];
|
|
18491
|
+
inject?: any[];
|
|
18492
|
+
useFactory: (...args: any[]) => LoggerModuleOptions | Promise<LoggerModuleOptions>;
|
|
18493
|
+
}): DynamicModule;
|
|
18494
|
+
/**
|
|
18495
|
+
* 将 LoggerModuleOptions 转换为 nestjs-pino 的 Params
|
|
18496
|
+
*/
|
|
18497
|
+
private static buildParams;
|
|
18498
|
+
}
|
|
18499
|
+
//#endregion
|
|
18500
|
+
//#region src/modules/logger/decorators/inject-logger.decorator.d.ts
|
|
18501
|
+
/**
|
|
18502
|
+
* 注入 Logger,自动以类名为日志上下文
|
|
18503
|
+
*
|
|
18504
|
+
* 用法:
|
|
18505
|
+
* @InjectLogger()
|
|
18506
|
+
* private readonly logger: Logger
|
|
18507
|
+
*
|
|
18508
|
+
* 等价于:
|
|
18509
|
+
* @InjectPinoLogger(MyService.name)
|
|
18510
|
+
* private readonly logger: Logger
|
|
18511
|
+
*/
|
|
18512
|
+
declare function InjectLogger(context?: string): ParameterDecorator;
|
|
18513
|
+
//#endregion
|
|
18514
|
+
//#region src/modules/logger/logger.config.d.ts
|
|
18515
|
+
/**
|
|
18516
|
+
* 日志配置基类
|
|
18517
|
+
*
|
|
18518
|
+
* 项目中的日志配置应继承此类并通过 @Configuration('xxx') 绑定环境变量前缀
|
|
18519
|
+
*/
|
|
18520
|
+
declare class LoggerConfig {
|
|
18521
|
+
pretty: boolean;
|
|
18522
|
+
level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
18523
|
+
serviceName: string;
|
|
18524
|
+
environment: string;
|
|
18525
|
+
version: string;
|
|
18526
|
+
}
|
|
18527
|
+
//#endregion
|
|
18454
18528
|
//#region src/modules/object-storage/types/options.d.ts
|
|
18455
18529
|
interface ObjectStorageOptions {
|
|
18456
18530
|
prefix?: boolean;
|
|
@@ -18578,5 +18652,5 @@ declare class ObjectStorageService implements OnModuleInit {
|
|
|
18578
18652
|
*/
|
|
18579
18653
|
declare function stableStringify(value: unknown): string;
|
|
18580
18654
|
//#endregion
|
|
18581
|
-
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, EagerType, type EncryptCommand, EncryptedPayload, EntityRef, Enum, EnumPropertyMetadata, EnvelopeEncryptionModule, type EnvelopeEncryptionModuleOptions, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, type ErrorCodeOptions, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, type ExceptionConstructor, type ExceptionConstructorWithArgs, type ExceptionDetail, ExceptionDetailSchema, ExceptionModule, type ExceptionModuleOptions as ExceptionNestModuleOptions, type ExceptionOptions, type ExceptionOptionsWithFactory, type ExceptionOptionsWithMessage, ExcludeDefinedOpt, ExcludeHidden, ExcludeOpt, ExcludeRef, ExcludeScalarClass, FeatureException, FilterQuery, FilterQueryOperator, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, type HttpExceptionOptions, IEntityPrimaryKey, IFilter, IFilterQuery, IFilterQueryCollectionCondition, IFilterQueryCondition, IFilterQueryNestedProperty, IFilterQueryObject, IFilterQueryProperty, IListResponseBody, IListResponseBodyMeta, INextCursorPageParameters, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IResponseBody, IS_CROCKFORD_BASE32, IS_IDENTIFIER_URN, IS_NAMESPACE_URN, IS_RESOURCE_URN, IS_SCALAR_DICTIONARY, IS_URN, IdentifierUrn, IsBrowserRequest, IsCrockfordBase32, IsHidden, IsIdentifierUrn, IsNamespaceUrn, IsOpt, IsResourceUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListPropertyMetadata, ListResponseBodyType, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, Model, ModelMetadata, ModelOptions, ModelRegister, ModelSchemaOptions, ModuleExceptions, type ExceptionModuleOptions$1 as ModuleExceptionsOptions, NamespaceUrn, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageModuleOptions, ObjectStorageOptions, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuth, OpenBaoAppRoleAuthConfig, OpenBaoAuthMethod, OpenBaoAuthResponse, OpenBaoHttpClient, OpenBaoKubernetesAuth, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoModuleOptions, OpenBaoTokenAuth, OpenBaoTokenAuthConfig, OpenBaoTokenLookupSelfResponse, OpenBaoTokenManager, OpenBaoUserpassAuth, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, PropertyKind, PropertyMetadata, RateLimitException, type ReencryptCommand, RefAssociationMetadata, type ResolveExceptions, ResourceUrn, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
18655
|
+
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, EagerType, type EncryptCommand, EncryptedPayload, EntityRef, Enum, EnumPropertyMetadata, EnvelopeEncryptionModule, type EnvelopeEncryptionModuleOptions, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, type ErrorCodeOptions, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, type ExceptionConstructor, type ExceptionConstructorWithArgs, type ExceptionDetail, ExceptionDetailSchema, ExceptionModule, type ExceptionModuleOptions as ExceptionNestModuleOptions, type ExceptionOptions, type ExceptionOptionsWithFactory, type ExceptionOptionsWithMessage, ExcludeDefinedOpt, ExcludeHidden, ExcludeOpt, ExcludeRef, ExcludeScalarClass, FeatureException, FilterQuery, FilterQueryOperator, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, type HttpExceptionOptions, IEntityPrimaryKey, IFilter, IFilterQuery, IFilterQueryCollectionCondition, IFilterQueryCondition, IFilterQueryNestedProperty, IFilterQueryObject, IFilterQueryProperty, IListResponseBody, IListResponseBodyMeta, INextCursorPageParameters, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IResponseBody, IS_CROCKFORD_BASE32, IS_IDENTIFIER_URN, IS_NAMESPACE_URN, IS_RESOURCE_URN, IS_SCALAR_DICTIONARY, IS_URN, IdentifierUrn, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsHidden, IsIdentifierUrn, IsNamespaceUrn, IsOpt, IsResourceUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListPropertyMetadata, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, type LoggerModuleOptions, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, Model, ModelMetadata, ModelOptions, ModelRegister, ModelSchemaOptions, ModuleExceptions, type ExceptionModuleOptions$1 as ModuleExceptionsOptions, NamespaceUrn, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageModuleOptions, ObjectStorageOptions, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuth, OpenBaoAppRoleAuthConfig, OpenBaoAuthMethod, OpenBaoAuthResponse, OpenBaoHttpClient, OpenBaoKubernetesAuth, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoModuleOptions, OpenBaoTokenAuth, OpenBaoTokenAuthConfig, OpenBaoTokenLookupSelfResponse, OpenBaoTokenManager, OpenBaoUserpassAuth, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, PropertyKind, PropertyMetadata, RateLimitException, type ReencryptCommand, RefAssociationMetadata, type ResolveExceptions, ResourceUrn, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
18582
18656
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -33,9 +33,9 @@ let ramda = require("ramda");
|
|
|
33
33
|
ramda = __toESM(ramda);
|
|
34
34
|
let class_transformer_cjs_storage_js = require("class-transformer/cjs/storage.js");
|
|
35
35
|
class_transformer_cjs_storage_js = __toESM(class_transformer_cjs_storage_js);
|
|
36
|
-
let
|
|
37
|
-
let
|
|
38
|
-
let
|
|
36
|
+
let _nestjs_swagger_dist_services_model_properties_accessor = require("@nestjs/swagger/dist/services/model-properties-accessor");
|
|
37
|
+
let _nestjs_swagger_dist_constants = require("@nestjs/swagger/dist/constants");
|
|
38
|
+
let _nestjs_swagger_dist_plugin_plugin_constants = require("@nestjs/swagger/dist/plugin/plugin-constants");
|
|
39
39
|
let _nestjs_swagger_dist_type_helpers_mapped_types_utils = require("@nestjs/swagger/dist/type-helpers/mapped-types.utils");
|
|
40
40
|
let _nestjs_common_utils_shared_utils = require("@nestjs/common/utils/shared.utils");
|
|
41
41
|
require("@nestjs/swagger/dist/utils/is-built-in-type.util");
|
|
@@ -51,11 +51,13 @@ node_fs = __toESM(node_fs);
|
|
|
51
51
|
let keq = require("keq");
|
|
52
52
|
let _keq_request_url = require("@keq-request/url");
|
|
53
53
|
let _keq_request_exception = require("@keq-request/exception");
|
|
54
|
-
let crypto = require("crypto");
|
|
54
|
+
let crypto$1 = require("crypto");
|
|
55
55
|
let bcryptjs = require("bcryptjs");
|
|
56
56
|
bcryptjs = __toESM(bcryptjs);
|
|
57
57
|
let _buka_error_codes = require("@buka/error-codes");
|
|
58
58
|
let _buka_exception = require("@buka/exception");
|
|
59
|
+
let nestjs_pino = require("nestjs-pino");
|
|
60
|
+
let pino = require("pino");
|
|
59
61
|
let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
|
|
60
62
|
let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
61
63
|
let _aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
|
|
@@ -506,7 +508,7 @@ function IsUrn(validationOptions) {
|
|
|
506
508
|
}
|
|
507
509
|
},
|
|
508
510
|
defaultMessage() {
|
|
509
|
-
return "$property must be a valid URN (urn:buka
|
|
511
|
+
return "$property must be a valid URN (urn:buka:<namespace>[:<resource>[:<identifier>]])";
|
|
510
512
|
}
|
|
511
513
|
}
|
|
512
514
|
});
|
|
@@ -540,7 +542,7 @@ function IsNamespaceUrn(validationOptions) {
|
|
|
540
542
|
}
|
|
541
543
|
},
|
|
542
544
|
defaultMessage() {
|
|
543
|
-
return "$property must be a namespace-level URN (urn:buka
|
|
545
|
+
return "$property must be a namespace-level URN (urn:buka:<namespace>)";
|
|
544
546
|
}
|
|
545
547
|
}
|
|
546
548
|
});
|
|
@@ -574,7 +576,7 @@ function IsResourceUrn(validationOptions) {
|
|
|
574
576
|
}
|
|
575
577
|
},
|
|
576
578
|
defaultMessage() {
|
|
577
|
-
return "$property must be a resource-level URN (urn:buka
|
|
579
|
+
return "$property must be a resource-level URN (urn:buka:<namespace>:<resource>)";
|
|
578
580
|
}
|
|
579
581
|
}
|
|
580
582
|
});
|
|
@@ -608,7 +610,7 @@ function IsIdentifierUrn(validationOptions) {
|
|
|
608
610
|
}
|
|
609
611
|
},
|
|
610
612
|
defaultMessage() {
|
|
611
|
-
return "$property must be an identifier-level URN (urn:buka
|
|
613
|
+
return "$property must be an identifier-level URN (urn:buka:<namespace>:<resource>:<identifier>)";
|
|
612
614
|
}
|
|
613
615
|
}
|
|
614
616
|
});
|
|
@@ -1433,7 +1435,7 @@ function getPropertyOperators(target, propertyKey) {
|
|
|
1433
1435
|
}
|
|
1434
1436
|
//#endregion
|
|
1435
1437
|
//#region src/utils/nestjs-swagger-utils.ts
|
|
1436
|
-
const modelPropertiesAccessor = new
|
|
1438
|
+
const modelPropertiesAccessor = new _nestjs_swagger_dist_services_model_properties_accessor.ModelPropertiesAccessor();
|
|
1437
1439
|
/**
|
|
1438
1440
|
* 克隆 @nestjs/swagger Plugin 添加的元数据
|
|
1439
1441
|
*/
|
|
@@ -1445,12 +1447,12 @@ function cloneMetadata(target, source, keys) {
|
|
|
1445
1447
|
}
|
|
1446
1448
|
}
|
|
1447
1449
|
function getMetadataOfDecorator(classRef, propertyKey) {
|
|
1448
|
-
if (propertyKey) return Reflect.getMetadata(
|
|
1450
|
+
if (propertyKey) return Reflect.getMetadata(_nestjs_swagger_dist_constants.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, propertyKey);
|
|
1449
1451
|
const props = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
1450
|
-
return ramda.fromPairs(props.map((prop) => [prop, Reflect.getMetadata(
|
|
1452
|
+
return ramda.fromPairs(props.map((prop) => [prop, Reflect.getMetadata(_nestjs_swagger_dist_constants.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, prop)]));
|
|
1451
1453
|
}
|
|
1452
1454
|
function getMetadataOfPlugin(classRef, propertyKey) {
|
|
1453
|
-
const propsInPlugin = typeof classRef[
|
|
1455
|
+
const propsInPlugin = typeof classRef[_nestjs_swagger_dist_plugin_plugin_constants.METADATA_FACTORY_NAME] === "function" ? classRef[_nestjs_swagger_dist_plugin_plugin_constants.METADATA_FACTORY_NAME]() : {};
|
|
1454
1456
|
if (propertyKey) return propsInPlugin[propertyKey];
|
|
1455
1457
|
return propsInPlugin;
|
|
1456
1458
|
}
|
|
@@ -8089,6 +8091,51 @@ function setOpenBaoToken(getToken) {
|
|
|
8089
8091
|
return middleware;
|
|
8090
8092
|
}
|
|
8091
8093
|
//#endregion
|
|
8094
|
+
//#region src/modules/open-bao/request/format-error.ts
|
|
8095
|
+
/**
|
|
8096
|
+
* 根据 HTTP 状态码生成中文操作建议
|
|
8097
|
+
*/
|
|
8098
|
+
function getStatusCodeGuidance(statusCode) {
|
|
8099
|
+
if (statusCode === 400) return "请检查请求参数是否正确";
|
|
8100
|
+
if (statusCode === 403) return "请检查 OpenBao 策略(Policy)是否为该 Token 授予了足够的权限";
|
|
8101
|
+
if (statusCode === 404) return "请检查请求的路径或密钥是否存在";
|
|
8102
|
+
if (statusCode >= 500) return "请检查 OpenBao 服务器日志以获取更多信息";
|
|
8103
|
+
return "";
|
|
8104
|
+
}
|
|
8105
|
+
/**
|
|
8106
|
+
* OpenBao 请求错误格式化中间件
|
|
8107
|
+
*
|
|
8108
|
+
* 必须注册在 `validateStatusCode` 之后,作为中间件链的最外层,
|
|
8109
|
+
* 捕获 `RequestException` 并重写其错误消息,补充请求上下文和操作建议。
|
|
8110
|
+
*
|
|
8111
|
+
* 非 RequestException 错误(网络故障、超时等)原样透传。
|
|
8112
|
+
*/
|
|
8113
|
+
function formatError() {
|
|
8114
|
+
const middleware = async (ctx, next) => {
|
|
8115
|
+
try {
|
|
8116
|
+
await next();
|
|
8117
|
+
} catch (err) {
|
|
8118
|
+
if (!(err instanceof keq.RequestException)) throw err;
|
|
8119
|
+
const method = ctx.request.method.toUpperCase();
|
|
8120
|
+
const url = ctx.request.url.toString();
|
|
8121
|
+
const statusCode = err.statusCode;
|
|
8122
|
+
const statusText = err.response?.statusText ?? "";
|
|
8123
|
+
let message = `OpenBaoModule API 请求失败: ${method} ${url}`;
|
|
8124
|
+
message += `\n响应状态: ${String(statusCode)} ${statusText}`;
|
|
8125
|
+
if (err.response) try {
|
|
8126
|
+
const bodyText = await err.response.clone().text();
|
|
8127
|
+
if (bodyText) message += `\n响应体: ${bodyText}`;
|
|
8128
|
+
} catch {}
|
|
8129
|
+
const guidance = getStatusCodeGuidance(typeof statusCode === "number" ? statusCode : parseInt(String(statusCode), 10));
|
|
8130
|
+
if (guidance) message += `\n建议: ${guidance}`;
|
|
8131
|
+
err.message = message;
|
|
8132
|
+
throw err;
|
|
8133
|
+
}
|
|
8134
|
+
};
|
|
8135
|
+
middleware.__keqMiddlewareName__ = "formatError";
|
|
8136
|
+
return middleware;
|
|
8137
|
+
}
|
|
8138
|
+
//#endregion
|
|
8092
8139
|
//#region src/modules/open-bao/open-bao.module.ts
|
|
8093
8140
|
/**
|
|
8094
8141
|
* 内部 KeqRequest 注入 Token
|
|
@@ -8104,6 +8151,7 @@ const KEQ_REQUEST_PROVIDER = {
|
|
|
8104
8151
|
request.use((0, _keq_request_url.setBaseUrl)(options.address + "/v1/"));
|
|
8105
8152
|
request.use(setOpenBaoToken(() => tokenManager.getToken()));
|
|
8106
8153
|
request.use((0, _keq_request_exception.validateStatusCode)());
|
|
8154
|
+
request.use(formatError());
|
|
8107
8155
|
return request;
|
|
8108
8156
|
},
|
|
8109
8157
|
inject: [MODULE_OPTIONS_TOKEN$3, OpenBaoTokenManager]
|
|
@@ -8248,7 +8296,7 @@ let BlindIndexV1Hasher = class BlindIndexV1Hasher {
|
|
|
8248
8296
|
if (data === null || data === void 0) throw new TypeError("Cannot hash null or undefined data");
|
|
8249
8297
|
const jsonString = stableStringify(data);
|
|
8250
8298
|
return {
|
|
8251
|
-
value: (0, crypto.createHash)("sha256").update(jsonString, "utf8").digest("hex"),
|
|
8299
|
+
value: (0, crypto$1.createHash)("sha256").update(jsonString, "utf8").digest("hex"),
|
|
8252
8300
|
version: 1
|
|
8253
8301
|
};
|
|
8254
8302
|
}
|
|
@@ -9453,8 +9501,8 @@ let EnvelopeEncryptionV1Cipher = _EnvelopeEncryptionV1Cipher = class EnvelopeEnc
|
|
|
9453
9501
|
}
|
|
9454
9502
|
async encrypt(cmd) {
|
|
9455
9503
|
const { dek, encryptedDek, kekVersion } = await this.kmsProvider.generateDek(cmd.kekId, "aes256-gcm96");
|
|
9456
|
-
const cipherIv = (0, crypto.randomBytes)(12);
|
|
9457
|
-
const cipher = (0, crypto.createCipheriv)(this.algorithm, dek, cipherIv, { authTagLength: 16 });
|
|
9504
|
+
const cipherIv = (0, crypto$1.randomBytes)(12);
|
|
9505
|
+
const cipher = (0, crypto$1.createCipheriv)(this.algorithm, dek, cipherIv, { authTagLength: 16 });
|
|
9458
9506
|
const aad = this.buildAad(cmd.kekId, cmd.extraAad);
|
|
9459
9507
|
cipher.setAAD(aad);
|
|
9460
9508
|
const cipherBlob = Buffer.concat([cipher.update(cmd.plaintext), cipher.final()]);
|
|
@@ -9474,7 +9522,7 @@ let EnvelopeEncryptionV1Cipher = _EnvelopeEncryptionV1Cipher = class EnvelopeEnc
|
|
|
9474
9522
|
async decrypt(cmd) {
|
|
9475
9523
|
if (cmd.payload.cipherVersion !== this.version) throw new Error(`Cipher version mismatch: expected ${this.version}, got ${cmd.payload.cipherVersion}`);
|
|
9476
9524
|
const dek = await this.kmsProvider.decryptDek(cmd.envelope.kekId, cmd.envelope.kekVersion, cmd.envelope.dek);
|
|
9477
|
-
const decipher = (0, crypto.createDecipheriv)(this.algorithm, dek, cmd.payload.cipherIv, { authTagLength: 16 });
|
|
9525
|
+
const decipher = (0, crypto$1.createDecipheriv)(this.algorithm, dek, cmd.payload.cipherIv, { authTagLength: 16 });
|
|
9478
9526
|
const aad = this.buildAad(cmd.envelope.kekId, cmd.extraAad);
|
|
9479
9527
|
decipher.setAAD(aad);
|
|
9480
9528
|
decipher.setAuthTag(cmd.payload.cipherTag);
|
|
@@ -9579,6 +9627,109 @@ EnvelopeEncryptionModule = __decorate([(0, _nestjs_common.Global)(), (0, _nestjs
|
|
|
9579
9627
|
exports: [EnvelopeEncryptionService]
|
|
9580
9628
|
})], EnvelopeEncryptionModule);
|
|
9581
9629
|
//#endregion
|
|
9630
|
+
//#region src/modules/logger/logger.module.ts
|
|
9631
|
+
var _LoggerModule;
|
|
9632
|
+
let LoggerModule = _LoggerModule = class LoggerModule {
|
|
9633
|
+
static register(options = {}) {
|
|
9634
|
+
return {
|
|
9635
|
+
module: _LoggerModule,
|
|
9636
|
+
imports: [nestjs_pino.LoggerModule.forRoot(this.buildParams(options))],
|
|
9637
|
+
providers: [nestjs_pino.LoggerErrorInterceptor],
|
|
9638
|
+
exports: [nestjs_pino.LoggerModule, nestjs_pino.LoggerErrorInterceptor]
|
|
9639
|
+
};
|
|
9640
|
+
}
|
|
9641
|
+
static registerAsync(options) {
|
|
9642
|
+
return {
|
|
9643
|
+
module: _LoggerModule,
|
|
9644
|
+
imports: [...options.imports || [], nestjs_pino.LoggerModule.forRootAsync({
|
|
9645
|
+
imports: options.imports || [],
|
|
9646
|
+
inject: options.inject || [],
|
|
9647
|
+
useFactory: async (...args) => {
|
|
9648
|
+
const opts = await options.useFactory(...args);
|
|
9649
|
+
return _LoggerModule.buildParams(opts);
|
|
9650
|
+
}
|
|
9651
|
+
})],
|
|
9652
|
+
providers: [nestjs_pino.LoggerErrorInterceptor],
|
|
9653
|
+
exports: [nestjs_pino.LoggerModule, nestjs_pino.LoggerErrorInterceptor]
|
|
9654
|
+
};
|
|
9655
|
+
}
|
|
9656
|
+
/**
|
|
9657
|
+
* 将 LoggerModuleOptions 转换为 nestjs-pino 的 Params
|
|
9658
|
+
*/
|
|
9659
|
+
static buildParams(options) {
|
|
9660
|
+
const { serviceName = "unknown", environment = process.env.NODE_ENV || "development", version = "0.0.0", level = "info", pretty = false } = options;
|
|
9661
|
+
return { pinoHttp: {
|
|
9662
|
+
...pretty ? { transport: { target: "pino-pretty" } } : {},
|
|
9663
|
+
level,
|
|
9664
|
+
genReqId: (req) => req.headers["x-request-id"] || crypto.randomUUID(),
|
|
9665
|
+
autoLogging: { ignore: (req) => req.url?.startsWith("/api/v1/health") ?? false },
|
|
9666
|
+
customAttributeKeys: {
|
|
9667
|
+
reqId: "reqId",
|
|
9668
|
+
responseTime: "responseTime"
|
|
9669
|
+
},
|
|
9670
|
+
serializers: {
|
|
9671
|
+
req: (req) => ({
|
|
9672
|
+
method: req.method,
|
|
9673
|
+
url: req.url
|
|
9674
|
+
}),
|
|
9675
|
+
res: (res) => ({ statusCode: res.statusCode }),
|
|
9676
|
+
err: pino.stdSerializers.err
|
|
9677
|
+
},
|
|
9678
|
+
formatters: {
|
|
9679
|
+
level: (label) => ({ level: label }),
|
|
9680
|
+
bindings: (bindings) => ({
|
|
9681
|
+
...bindings,
|
|
9682
|
+
service: serviceName,
|
|
9683
|
+
environment,
|
|
9684
|
+
version
|
|
9685
|
+
})
|
|
9686
|
+
}
|
|
9687
|
+
} };
|
|
9688
|
+
}
|
|
9689
|
+
};
|
|
9690
|
+
LoggerModule = _LoggerModule = __decorate([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({})], LoggerModule);
|
|
9691
|
+
//#endregion
|
|
9692
|
+
//#region src/modules/logger/decorators/inject-logger.decorator.ts
|
|
9693
|
+
/**
|
|
9694
|
+
* 注入 Logger,自动以类名为日志上下文
|
|
9695
|
+
*
|
|
9696
|
+
* 用法:
|
|
9697
|
+
* @InjectLogger()
|
|
9698
|
+
* private readonly logger: Logger
|
|
9699
|
+
*
|
|
9700
|
+
* 等价于:
|
|
9701
|
+
* @InjectPinoLogger(MyService.name)
|
|
9702
|
+
* private readonly logger: Logger
|
|
9703
|
+
*/
|
|
9704
|
+
function InjectLogger(context) {
|
|
9705
|
+
return (target, propertyKey, parameterIndex) => {
|
|
9706
|
+
(0, nestjs_pino.InjectPinoLogger)(context || target.constructor.name)(target, propertyKey, parameterIndex);
|
|
9707
|
+
};
|
|
9708
|
+
}
|
|
9709
|
+
//#endregion
|
|
9710
|
+
//#region src/modules/logger/logger.config.ts
|
|
9711
|
+
/**
|
|
9712
|
+
* 日志配置基类
|
|
9713
|
+
*
|
|
9714
|
+
* 项目中的日志配置应继承此类并通过 @Configuration('xxx') 绑定环境变量前缀
|
|
9715
|
+
*/
|
|
9716
|
+
var LoggerConfig = class {
|
|
9717
|
+
pretty = false;
|
|
9718
|
+
level = "info";
|
|
9719
|
+
serviceName = "unknown";
|
|
9720
|
+
environment = process.env.NODE_ENV || "development";
|
|
9721
|
+
version = process.env.npm_package_version || "0.0.0";
|
|
9722
|
+
};
|
|
9723
|
+
__decorate([(0, _buka_class_transformer_extra.ToBoolean)(), __decorateMetadata("design:type", Boolean)], LoggerConfig.prototype, "pretty", void 0);
|
|
9724
|
+
__decorate([(0, class_validator.IsIn)([
|
|
9725
|
+
"fatal",
|
|
9726
|
+
"error",
|
|
9727
|
+
"warn",
|
|
9728
|
+
"info",
|
|
9729
|
+
"debug",
|
|
9730
|
+
"trace"
|
|
9731
|
+
]), __decorateMetadata("design:type", String)], LoggerConfig.prototype, "level", void 0);
|
|
9732
|
+
//#endregion
|
|
9582
9733
|
//#region src/modules/object-storage/object-storage.config.ts
|
|
9583
9734
|
var ObjectStorageModuleConfig = class {
|
|
9584
9735
|
endpoint;
|
|
@@ -9896,6 +10047,7 @@ exports.IS_NAMESPACE_URN = IS_NAMESPACE_URN;
|
|
|
9896
10047
|
exports.IS_RESOURCE_URN = IS_RESOURCE_URN;
|
|
9897
10048
|
exports.IS_SCALAR_DICTIONARY = IS_SCALAR_DICTIONARY;
|
|
9898
10049
|
exports.IS_URN = IS_URN;
|
|
10050
|
+
exports.InjectLogger = InjectLogger;
|
|
9899
10051
|
exports.IsBrowserRequest = IsBrowserRequest;
|
|
9900
10052
|
exports.IsCrockfordBase32 = IsCrockfordBase32;
|
|
9901
10053
|
exports.IsIdentifierUrn = IsIdentifierUrn;
|
|
@@ -9914,6 +10066,25 @@ exports.LinearEntity = LinearEntity;
|
|
|
9914
10066
|
exports.List = List;
|
|
9915
10067
|
exports.ListErrorCodesResponseDto = ListErrorCodesResponseDto;
|
|
9916
10068
|
exports.ListResponseBodyType = ListResponseBodyType;
|
|
10069
|
+
Object.defineProperty(exports, "Logger", {
|
|
10070
|
+
enumerable: true,
|
|
10071
|
+
get: function() {
|
|
10072
|
+
return nestjs_pino.Logger;
|
|
10073
|
+
}
|
|
10074
|
+
});
|
|
10075
|
+
exports.LoggerConfig = LoggerConfig;
|
|
10076
|
+
Object.defineProperty(exports, "LoggerErrorInterceptor", {
|
|
10077
|
+
enumerable: true,
|
|
10078
|
+
get: function() {
|
|
10079
|
+
return nestjs_pino.LoggerErrorInterceptor;
|
|
10080
|
+
}
|
|
10081
|
+
});
|
|
10082
|
+
Object.defineProperty(exports, "LoggerModule", {
|
|
10083
|
+
enumerable: true,
|
|
10084
|
+
get: function() {
|
|
10085
|
+
return LoggerModule;
|
|
10086
|
+
}
|
|
10087
|
+
});
|
|
9917
10088
|
exports.MATCH_JSON_SCHEMA = MATCH_JSON_SCHEMA;
|
|
9918
10089
|
exports.MODULE_OPTIONS_TOKEN = MODULE_OPTIONS_TOKEN;
|
|
9919
10090
|
exports.MatchJsonSchema = MatchJsonSchema;
|