@nest-omni/core 4.1.3-1 → 4.1.3-11
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/audit/audit.module.d.ts +10 -0
- package/audit/audit.module.js +39 -1
- package/audit/controllers/audit.controller.d.ts +24 -0
- package/audit/controllers/audit.controller.js +24 -0
- package/audit/decorators/audit-controller.decorator.d.ts +9 -1
- package/audit/decorators/audit-controller.decorator.js +11 -2
- package/audit/decorators/audit-operation.decorator.d.ts +45 -0
- package/audit/decorators/audit-operation.decorator.js +49 -0
- package/audit/decorators/entity-audit.decorator.d.ts +76 -1
- package/audit/decorators/entity-audit.decorator.js +135 -3
- package/audit/decorators/index.d.ts +1 -0
- package/audit/decorators/index.js +1 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -0
- package/audit/entities/entity-audit-log.entity.d.ts +8 -0
- package/audit/entities/entity-audit-log.entity.js +33 -1
- package/audit/entities/entity-transaction.entity.d.ts +10 -0
- package/audit/entities/entity-transaction.entity.js +33 -1
- package/audit/entities/index.d.ts +2 -0
- package/audit/entities/index.js +2 -0
- package/audit/entities/manual-operation-log.entity.d.ts +4 -0
- package/audit/entities/manual-operation-log.entity.js +4 -0
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +45 -5
- package/audit/enums/audit.enums.js +47 -4
- package/audit/index.d.ts +3 -1
- package/audit/index.js +30 -1
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interfaces/audit.interfaces.d.ts +182 -2
- package/audit/services/audit-context.service.d.ts +15 -0
- package/audit/services/audit-context.service.js +15 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +129 -3
- package/audit/services/entity-audit.service.js +301 -6
- package/audit/services/index.d.ts +2 -0
- package/audit/services/index.js +2 -0
- package/audit/services/manual-audit-log.service.d.ts +124 -0
- package/audit/services/manual-audit-log.service.js +138 -0
- package/audit/services/multi-database.service.d.ts +12 -0
- package/audit/services/multi-database.service.js +12 -0
- package/audit/services/operation-description.service.d.ts +59 -0
- package/audit/services/operation-description.service.js +76 -2
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +47 -0
- package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
- package/audit/subscribers/entity-audit.subscriber.js +29 -1
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +86 -0
- package/cache/cache.module.js +71 -0
- package/cache/cache.service.d.ts +140 -0
- package/cache/cache.service.js +157 -0
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +45 -0
- package/cache/dependencies/db.dependency.js +48 -1
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +36 -0
- package/cache/dependencies/tag.dependency.js +36 -0
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.js +9 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +81 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/memory-cache.provider.d.ts +23 -0
- package/cache/providers/memory-cache.provider.js +26 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +142 -4
- package/common/boilerplate.polyfill.js +24 -100
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.js +8 -1
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -0
- package/decorators/transform.decorators.js +29 -0
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- package/filters/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +15 -0
- package/http-client/config/http-client.config.js +25 -9
- package/http-client/decorators/http-client.decorators.d.ts +63 -0
- package/http-client/decorators/http-client.decorators.js +71 -3
- package/http-client/entities/http-log.entity.d.ts +229 -0
- package/http-client/entities/http-log.entity.js +6 -1
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +41 -0
- package/http-client/examples/advanced-usage.example.js +68 -24
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- package/http-client/http-client.module.d.ts +13 -0
- package/http-client/http-client.module.js +20 -5
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
- package/http-client/services/api-client-registry.service.d.ts +57 -0
- package/http-client/services/api-client-registry.service.js +84 -1
- package/http-client/services/cache.service.d.ts +52 -0
- package/http-client/services/cache.service.js +72 -3
- package/http-client/services/circuit-breaker.service.d.ts +46 -0
- package/http-client/services/circuit-breaker.service.js +52 -0
- package/http-client/services/http-client.service.d.ts +67 -0
- package/http-client/services/http-client.service.js +105 -4
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +122 -1
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +40 -0
- package/http-client/services/logging.service.js +53 -0
- package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
- package/http-client/utils/call-stack-extractor.util.js +48 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +52 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/i18n/en_US/validation.json +2 -1
- package/i18n/zh_CN/validation.json +2 -1
- package/index.js +8 -0
- package/interceptors/translation-interceptor.service.js +5 -0
- package/package.json +1 -1
- package/providers/context.provider.js +2 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -0
- package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.d.ts +2 -0
- package/redis-lock/index.js +8 -1
- package/redis-lock/lock-heartbeat.service.d.ts +78 -0
- package/redis-lock/lock-heartbeat.service.js +222 -0
- package/redis-lock/redis-lock.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +278 -0
- package/redis-lock/redis-lock.service.js +282 -12
- package/setup/bootstrap.setup.js +20 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -0
- package/setup/schedule.decorator.d.ts +227 -0
- package/setup/schedule.decorator.js +235 -12
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +88 -0
- package/shared/serviceRegistryModule.js +27 -14
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +20 -9
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +96 -0
- package/validators/custom-validate.examples.js +400 -0
- package/validators/custom-validate.validator.d.ts +134 -0
- package/validators/custom-validate.validator.js +214 -0
- package/validators/index.d.ts +2 -0
- package/validators/index.js +2 -0
- package/validators/is-exists.validator.d.ts +18 -4
- package/validators/is-exists.validator.js +67 -6
- package/validators/is-unique.validator.d.ts +32 -5
- package/validators/is-unique.validator.js +99 -17
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
|
@@ -11,7 +11,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.VaultConfigLoader = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
|
+
/**
|
|
15
|
+
* Vault 配置加载器
|
|
16
|
+
* 负责在应用启动时从 Vault 加载配置并注入到 process.env
|
|
17
|
+
* 配置优先级: base.env < 环境.env < Vault
|
|
18
|
+
*/
|
|
14
19
|
class VaultConfigLoader {
|
|
20
|
+
/**
|
|
21
|
+
* 从环境变量构建 Vault 配置
|
|
22
|
+
*/
|
|
15
23
|
static buildVaultOptions() {
|
|
16
24
|
var _a;
|
|
17
25
|
const enabled = process.env.VAULT_ENABLED === 'true';
|
|
@@ -29,6 +37,7 @@ class VaultConfigLoader {
|
|
|
29
37
|
this.logger.warn('Vault enabled but VAULT_SECRET_PATHS is empty');
|
|
30
38
|
return null;
|
|
31
39
|
}
|
|
40
|
+
// 构建认证配置
|
|
32
41
|
const auth = {};
|
|
33
42
|
if (process.env.VAULT_TOKEN) {
|
|
34
43
|
auth.token = process.env.VAULT_TOKEN;
|
|
@@ -57,13 +66,17 @@ class VaultConfigLoader {
|
|
|
57
66
|
timeout: parseInt(process.env.VAULT_TIMEOUT || '5000', 10),
|
|
58
67
|
enableHotReload: process.env.VAULT_HOT_RELOAD === 'true',
|
|
59
68
|
hotReloadInterval: parseInt(process.env.VAULT_HOT_RELOAD_INTERVAL || '300', 10),
|
|
60
|
-
failOnError: process.env.VAULT_FAIL_ON_ERROR !== 'false',
|
|
69
|
+
failOnError: process.env.VAULT_FAIL_ON_ERROR !== 'false', // 默认失败时终止
|
|
61
70
|
};
|
|
62
71
|
this.logger.log(`Vault configuration loaded: ${secretPaths.length} secret path(s)`);
|
|
63
72
|
return options;
|
|
64
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* 初始化 Vault 客户端并进行认证
|
|
76
|
+
*/
|
|
65
77
|
static initializeVaultClient(options) {
|
|
66
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
// 动态导入 node-vault
|
|
67
80
|
let vault;
|
|
68
81
|
try {
|
|
69
82
|
vault = yield Promise.resolve().then(() => require('node-vault'));
|
|
@@ -79,12 +92,15 @@ class VaultConfigLoader {
|
|
|
79
92
|
timeout: options.timeout,
|
|
80
93
|
},
|
|
81
94
|
});
|
|
95
|
+
// 根据认证方式进行认证
|
|
82
96
|
try {
|
|
83
97
|
if (options.auth.token) {
|
|
98
|
+
// Token 认证
|
|
84
99
|
client.token = options.auth.token;
|
|
85
100
|
this.logger.log('Vault Token authentication configured');
|
|
86
101
|
}
|
|
87
102
|
else if (options.auth.roleId && options.auth.secretId) {
|
|
103
|
+
// AppRole 认证
|
|
88
104
|
const result = yield client.approleLogin({
|
|
89
105
|
role_id: options.auth.roleId,
|
|
90
106
|
secret_id: options.auth.secretId,
|
|
@@ -93,7 +109,9 @@ class VaultConfigLoader {
|
|
|
93
109
|
this.logger.log('Vault AppRole authentication successful');
|
|
94
110
|
}
|
|
95
111
|
else if (options.auth.k8sRole) {
|
|
112
|
+
// Kubernetes 认证
|
|
96
113
|
let jwt = options.auth.k8sServiceAccountToken;
|
|
114
|
+
// 如果没有提供 token,从默认路径读取
|
|
97
115
|
if (!jwt) {
|
|
98
116
|
const fs = yield Promise.resolve().then(() => require('fs'));
|
|
99
117
|
const K8S_SA_TOKEN_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token';
|
|
@@ -114,6 +132,7 @@ class VaultConfigLoader {
|
|
|
114
132
|
else {
|
|
115
133
|
throw new Error('No valid Vault authentication method configured');
|
|
116
134
|
}
|
|
135
|
+
// 验证 token 是否有效
|
|
117
136
|
yield client.tokenLookupSelf();
|
|
118
137
|
this.logger.log('Vault authentication verified');
|
|
119
138
|
return client;
|
|
@@ -124,6 +143,9 @@ class VaultConfigLoader {
|
|
|
124
143
|
}
|
|
125
144
|
});
|
|
126
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* 从 Vault 读取指定路径的配置
|
|
148
|
+
*/
|
|
127
149
|
static readSecrets(client, secretPath, apiVersion) {
|
|
128
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
151
|
try {
|
|
@@ -133,6 +155,8 @@ class VaultConfigLoader {
|
|
|
133
155
|
this.logger.warn(`No data found at path: ${secretPath}`);
|
|
134
156
|
return {};
|
|
135
157
|
}
|
|
158
|
+
// KV v2 引擎的数据在 data.data 中
|
|
159
|
+
// KV v1 引擎的数据在 data 中
|
|
136
160
|
const secrets = apiVersion === 'v2' ? result.data.data : result.data;
|
|
137
161
|
if (!secrets || typeof secrets !== 'object') {
|
|
138
162
|
this.logger.warn(`Invalid secret format at path: ${secretPath}`);
|
|
@@ -148,6 +172,10 @@ class VaultConfigLoader {
|
|
|
148
172
|
}
|
|
149
173
|
});
|
|
150
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* 加载 Vault 配置并注入到 process.env
|
|
177
|
+
* 配置优先级: base.env < 环境.env < Vault(Vault 会覆盖之前的配置)
|
|
178
|
+
*/
|
|
151
179
|
static loadVaultConfig() {
|
|
152
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
181
|
const options = this.buildVaultOptions();
|
|
@@ -158,11 +186,14 @@ class VaultConfigLoader {
|
|
|
158
186
|
try {
|
|
159
187
|
this.logger.log(`Connecting to Vault at ${options.endpoint}`);
|
|
160
188
|
this.vaultClient = yield this.initializeVaultClient(options);
|
|
189
|
+
// 从所有配置路径读取配置(后面的路径会覆盖前面的)
|
|
161
190
|
const allSecrets = {};
|
|
162
191
|
for (const secretPath of options.secretPaths) {
|
|
163
192
|
const secrets = yield this.readSecrets(this.vaultClient, secretPath, options.apiVersion);
|
|
193
|
+
// 合并配置(后面的路径会覆盖前面的)
|
|
164
194
|
Object.assign(allSecrets, secrets);
|
|
165
195
|
}
|
|
196
|
+
// 注入到 process.env(覆盖所有已有的环境变量)
|
|
166
197
|
let injectedCount = 0;
|
|
167
198
|
let overriddenCount = 0;
|
|
168
199
|
for (const [key, value] of Object.entries(allSecrets)) {
|
|
@@ -177,12 +208,14 @@ class VaultConfigLoader {
|
|
|
177
208
|
}
|
|
178
209
|
}
|
|
179
210
|
this.logger.log(`Vault configuration loaded: ${injectedCount} new, ${overriddenCount} overridden`);
|
|
211
|
+
// 启动热更新(如果启用)
|
|
180
212
|
if (options.enableHotReload) {
|
|
181
213
|
this.startHotReload(options);
|
|
182
214
|
}
|
|
183
215
|
}
|
|
184
216
|
catch (error) {
|
|
185
217
|
this.logger.error('Failed to load Vault configuration', error.message);
|
|
218
|
+
// 根据配置决定是否在 Vault 失败时继续启动
|
|
186
219
|
if (options.failOnError) {
|
|
187
220
|
this.logger.error('Application startup failed due to Vault error');
|
|
188
221
|
throw error;
|
|
@@ -193,8 +226,12 @@ class VaultConfigLoader {
|
|
|
193
226
|
}
|
|
194
227
|
});
|
|
195
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* 启动配置热更新
|
|
231
|
+
*/
|
|
196
232
|
static startHotReload(options) {
|
|
197
233
|
this.logger.log(`Starting Vault hot reload with interval: ${options.hotReloadInterval}s`);
|
|
234
|
+
// 清除之前的定时器
|
|
198
235
|
if (this.hotReloadTimer) {
|
|
199
236
|
clearInterval(this.hotReloadTimer);
|
|
200
237
|
}
|
|
@@ -206,6 +243,7 @@ class VaultConfigLoader {
|
|
|
206
243
|
const secrets = yield this.readSecrets(this.vaultClient, secretPath, options.apiVersion);
|
|
207
244
|
Object.assign(allSecrets, secrets);
|
|
208
245
|
}
|
|
246
|
+
// 更新 process.env
|
|
209
247
|
let changedCount = 0;
|
|
210
248
|
for (const [key, value] of Object.entries(allSecrets)) {
|
|
211
249
|
const newValue = String(value);
|
|
@@ -227,6 +265,9 @@ class VaultConfigLoader {
|
|
|
227
265
|
}
|
|
228
266
|
}), options.hotReloadInterval * 1000);
|
|
229
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* 停止热更新
|
|
270
|
+
*/
|
|
230
271
|
static stopHotReload() {
|
|
231
272
|
if (this.hotReloadTimer) {
|
|
232
273
|
clearInterval(this.hotReloadTimer);
|
|
@@ -234,9 +275,15 @@ class VaultConfigLoader {
|
|
|
234
275
|
this.logger.log('Vault hot reload stopped');
|
|
235
276
|
}
|
|
236
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* 获取 Vault 客户端(用于运行时动态读取)
|
|
280
|
+
*/
|
|
237
281
|
static getVaultClient() {
|
|
238
282
|
return this.vaultClient;
|
|
239
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* 检查 Vault 是否已连接
|
|
286
|
+
*/
|
|
240
287
|
static isConnected() {
|
|
241
288
|
return this.vaultClient !== null && this.vaultClient !== undefined;
|
|
242
289
|
}
|
|
@@ -1,18 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault 配置服务
|
|
3
|
+
* 提供运行时动态访问 Vault 配置的能力
|
|
4
|
+
* 用于读取敏感配置而不缓存到 process.env
|
|
5
|
+
*/
|
|
1
6
|
export declare class VaultConfigService {
|
|
2
7
|
private readonly logger;
|
|
3
8
|
private vaultClient;
|
|
4
9
|
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* 检查 Vault 是否可用
|
|
12
|
+
*/
|
|
5
13
|
isAvailable(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 运行时动态读取 Vault 配置
|
|
16
|
+
* @param path Vault 配置路径
|
|
17
|
+
* @param key 可选,指定要读取的配置键,不指定则返回整个配置对象
|
|
18
|
+
* @returns 配置值
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // 读取整个配置对象
|
|
22
|
+
* const config = await vaultConfigService.getSecret('secret/data/app/config');
|
|
23
|
+
*
|
|
24
|
+
* // 读取指定键
|
|
25
|
+
* const apiKey = await vaultConfigService.getSecret('secret/data/app/config', 'API_KEY');
|
|
26
|
+
*/
|
|
6
27
|
getSecret(path: string, key?: string): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* 写入配置到 Vault(需要相应权限)
|
|
30
|
+
* @param path Vault 配置路径
|
|
31
|
+
* @param data 配置数据
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* await vaultConfigService.setSecret('secret/data/app/config', {
|
|
35
|
+
* API_KEY: 'new-key',
|
|
36
|
+
* DB_PASSWORD: 'new-password',
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
7
39
|
setSecret(path: string, data: Record<string, any>): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 删除 Vault 中的配置(需要相应权限)
|
|
42
|
+
* @param path Vault 配置路径
|
|
43
|
+
*/
|
|
8
44
|
deleteSecret(path: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* 列出指定路径下的所有配置键
|
|
47
|
+
* @param path Vault 配置路径
|
|
48
|
+
* @returns 配置键列表
|
|
49
|
+
*/
|
|
9
50
|
listSecrets(path: string): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* 检查 Vault 健康状态
|
|
53
|
+
* @returns 是否健康
|
|
54
|
+
*/
|
|
10
55
|
healthCheck(): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* 获取 Vault 状态信息
|
|
58
|
+
* @returns Vault 状态
|
|
59
|
+
*/
|
|
11
60
|
getStatus(): Promise<{
|
|
12
61
|
initialized: boolean;
|
|
13
62
|
sealed: boolean;
|
|
14
63
|
standby: boolean;
|
|
15
64
|
version: string;
|
|
16
65
|
} | null>;
|
|
66
|
+
/**
|
|
67
|
+
* 续订 Token(对于有时限的 Token)
|
|
68
|
+
* @param increment 续订时长(秒)
|
|
69
|
+
*/
|
|
17
70
|
renewToken(increment?: number): Promise<void>;
|
|
18
71
|
}
|
|
@@ -22,6 +22,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.VaultConfigService = void 0;
|
|
23
23
|
const common_1 = require("@nestjs/common");
|
|
24
24
|
const vault_config_loader_1 = require("./vault-config.loader");
|
|
25
|
+
/**
|
|
26
|
+
* Vault 配置服务
|
|
27
|
+
* 提供运行时动态访问 Vault 配置的能力
|
|
28
|
+
* 用于读取敏感配置而不缓存到 process.env
|
|
29
|
+
*/
|
|
25
30
|
let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
26
31
|
constructor() {
|
|
27
32
|
this.logger = new common_1.Logger(VaultConfigService_1.name);
|
|
@@ -30,9 +35,25 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
30
35
|
this.logger.warn('Vault client not initialized. VaultConfigService methods will throw errors.');
|
|
31
36
|
}
|
|
32
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* 检查 Vault 是否可用
|
|
40
|
+
*/
|
|
33
41
|
isAvailable() {
|
|
34
42
|
return vault_config_loader_1.VaultConfigLoader.isConnected();
|
|
35
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* 运行时动态读取 Vault 配置
|
|
46
|
+
* @param path Vault 配置路径
|
|
47
|
+
* @param key 可选,指定要读取的配置键,不指定则返回整个配置对象
|
|
48
|
+
* @returns 配置值
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // 读取整个配置对象
|
|
52
|
+
* const config = await vaultConfigService.getSecret('secret/data/app/config');
|
|
53
|
+
*
|
|
54
|
+
* // 读取指定键
|
|
55
|
+
* const apiKey = await vaultConfigService.getSecret('secret/data/app/config', 'API_KEY');
|
|
56
|
+
*/
|
|
36
57
|
getSecret(path, key) {
|
|
37
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
59
|
if (!this.vaultClient) {
|
|
@@ -44,16 +65,19 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
44
65
|
if (!result || !result.data) {
|
|
45
66
|
throw new Error(`No data found at path: ${path}`);
|
|
46
67
|
}
|
|
68
|
+
// KV v2 引擎的数据在 data.data 中
|
|
47
69
|
const data = apiVersion === 'v2' ? result.data.data : result.data;
|
|
48
70
|
if (!data || typeof data !== 'object') {
|
|
49
71
|
throw new Error(`Invalid secret format at path: ${path}`);
|
|
50
72
|
}
|
|
73
|
+
// 如果指定了 key,返回对应的值
|
|
51
74
|
if (key) {
|
|
52
75
|
if (!(key in data)) {
|
|
53
76
|
throw new Error(`Key '${key}' not found in secret at path: ${path}`);
|
|
54
77
|
}
|
|
55
78
|
return data[key];
|
|
56
79
|
}
|
|
80
|
+
// 否则返回整个配置对象
|
|
57
81
|
return data;
|
|
58
82
|
}
|
|
59
83
|
catch (error) {
|
|
@@ -62,6 +86,17 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
62
86
|
}
|
|
63
87
|
});
|
|
64
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* 写入配置到 Vault(需要相应权限)
|
|
91
|
+
* @param path Vault 配置路径
|
|
92
|
+
* @param data 配置数据
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* await vaultConfigService.setSecret('secret/data/app/config', {
|
|
96
|
+
* API_KEY: 'new-key',
|
|
97
|
+
* DB_PASSWORD: 'new-password',
|
|
98
|
+
* });
|
|
99
|
+
*/
|
|
65
100
|
setSecret(path, data) {
|
|
66
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
102
|
if (!this.vaultClient) {
|
|
@@ -70,6 +105,7 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
70
105
|
try {
|
|
71
106
|
const apiVersion = process.env.VAULT_API_VERSION || 'v2';
|
|
72
107
|
if (apiVersion === 'v2') {
|
|
108
|
+
// KV v2 引擎需要将数据包装在 data 字段中
|
|
73
109
|
yield this.vaultClient.write(path, { data });
|
|
74
110
|
}
|
|
75
111
|
else {
|
|
@@ -83,6 +119,10 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
83
119
|
}
|
|
84
120
|
});
|
|
85
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* 删除 Vault 中的配置(需要相应权限)
|
|
124
|
+
* @param path Vault 配置路径
|
|
125
|
+
*/
|
|
86
126
|
deleteSecret(path) {
|
|
87
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
128
|
if (!this.vaultClient) {
|
|
@@ -98,6 +138,11 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
98
138
|
}
|
|
99
139
|
});
|
|
100
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* 列出指定路径下的所有配置键
|
|
143
|
+
* @param path Vault 配置路径
|
|
144
|
+
* @returns 配置键列表
|
|
145
|
+
*/
|
|
101
146
|
listSecrets(path) {
|
|
102
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
148
|
if (!this.vaultClient) {
|
|
@@ -116,6 +161,10 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
116
161
|
}
|
|
117
162
|
});
|
|
118
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* 检查 Vault 健康状态
|
|
166
|
+
* @returns 是否健康
|
|
167
|
+
*/
|
|
119
168
|
healthCheck() {
|
|
120
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
170
|
if (!this.vaultClient) {
|
|
@@ -131,6 +180,10 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
131
180
|
}
|
|
132
181
|
});
|
|
133
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* 获取 Vault 状态信息
|
|
185
|
+
* @returns Vault 状态
|
|
186
|
+
*/
|
|
134
187
|
getStatus() {
|
|
135
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
189
|
if (!this.vaultClient) {
|
|
@@ -151,6 +204,10 @@ let VaultConfigService = VaultConfigService_1 = class VaultConfigService {
|
|
|
151
204
|
}
|
|
152
205
|
});
|
|
153
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* 续订 Token(对于有时限的 Token)
|
|
209
|
+
* @param increment 续订时长(秒)
|
|
210
|
+
*/
|
|
154
211
|
renewToken(increment) {
|
|
155
212
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
213
|
if (!this.vaultClient) {
|
package/vault/vault.module.d.ts
CHANGED
package/vault/vault.module.js
CHANGED
|
@@ -9,6 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.VaultModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const vault_config_service_1 = require("./vault-config.service");
|
|
12
|
+
/**
|
|
13
|
+
* Vault 模块
|
|
14
|
+
* 全局模块,提供 VaultConfigService 供整个应用使用
|
|
15
|
+
*/
|
|
12
16
|
let VaultModule = class VaultModule {
|
|
13
17
|
};
|
|
14
18
|
exports.VaultModule = VaultModule;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export declare class ContactDto {
|
|
2
|
-
email?: string;
|
|
3
|
-
phone?: string;
|
|
4
|
-
wechat?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class SearchDto {
|
|
7
|
-
keyword?: string;
|
|
8
|
-
category?: string;
|
|
9
|
-
tags?: string[];
|
|
10
|
-
}
|
|
11
|
-
export declare class PasswordDto {
|
|
12
|
-
password: string;
|
|
13
|
-
}
|
|
14
|
-
export declare class EmailCheckDto {
|
|
15
|
-
email: string;
|
|
16
|
-
userService?: any;
|
|
17
|
-
}
|
|
18
|
-
export declare class OrderDto {
|
|
19
|
-
orderType: 'standard' | 'express';
|
|
20
|
-
deliveryDate?: Date;
|
|
21
|
-
}
|
|
22
|
-
export declare class DiscountDto {
|
|
23
|
-
discountType: 'percentage' | 'fixed';
|
|
24
|
-
discountValue: number;
|
|
25
|
-
get validatedDiscountValue(): number;
|
|
26
|
-
}
|
|
27
|
-
export declare class UserRegistrationDto {
|
|
28
|
-
username: string;
|
|
29
|
-
password: string;
|
|
30
|
-
confirmPassword: string;
|
|
31
|
-
validatePassword(password: string): boolean;
|
|
32
|
-
validatePasswordMatch(confirmPassword: string): boolean;
|
|
33
|
-
}
|
|
34
|
-
export declare class CreateProductDto {
|
|
35
|
-
name: string;
|
|
36
|
-
sku: string;
|
|
37
|
-
categoryId: string;
|
|
38
|
-
get validatedCategoryId(): string;
|
|
39
|
-
productService?: any;
|
|
40
|
-
categoryService?: any;
|
|
41
|
-
checkSkuUniqueness(sku: string): Promise<boolean>;
|
|
42
|
-
validateCategoryExists(categoryId: string): Promise<boolean>;
|
|
43
|
-
}
|
|
44
|
-
export declare class EmployeeDto {
|
|
45
|
-
name: string;
|
|
46
|
-
personalEmail?: string;
|
|
47
|
-
workEmail?: string;
|
|
48
|
-
phone?: string;
|
|
49
|
-
validatePhoneFormat(phone: string): boolean;
|
|
50
|
-
}
|
|
51
|
-
export declare class PaymentMethodDto {
|
|
52
|
-
paymentType: 'credit_card' | 'bank_transfer' | 'digital_wallet';
|
|
53
|
-
creditCard?: {
|
|
54
|
-
number: string;
|
|
55
|
-
expiryDate: string;
|
|
56
|
-
cvv: string;
|
|
57
|
-
};
|
|
58
|
-
bankAccount?: {
|
|
59
|
-
accountNumber: string;
|
|
60
|
-
routingNumber: string;
|
|
61
|
-
};
|
|
62
|
-
digitalWallet?: {
|
|
63
|
-
provider: string;
|
|
64
|
-
walletId: string;
|
|
65
|
-
};
|
|
66
|
-
validateCreditCard(creditCard: any): boolean;
|
|
67
|
-
validateBankAccount(bankAccount: any): boolean;
|
|
68
|
-
validateDigitalWallet(digitalWallet: any): boolean;
|
|
69
|
-
}
|