@nest-omni/core 4.1.3-2 → 4.1.3-4

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.
Files changed (235) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +15 -0
  3. package/audit/controllers/audit.controller.d.ts +24 -0
  4. package/audit/controllers/audit.controller.js +24 -0
  5. package/audit/decorators/audit-controller.decorator.d.ts +8 -0
  6. package/audit/decorators/audit-controller.decorator.js +9 -0
  7. package/audit/decorators/audit-operation.decorator.d.ts +45 -0
  8. package/audit/decorators/audit-operation.decorator.js +49 -0
  9. package/audit/decorators/entity-audit.decorator.d.ts +8 -0
  10. package/audit/decorators/entity-audit.decorator.js +9 -0
  11. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  12. package/audit/dto/audit-log-query.dto.js +3 -0
  13. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  14. package/audit/dto/begin-transaction.dto.js +3 -0
  15. package/audit/dto/compare-entities.dto.d.ts +3 -0
  16. package/audit/dto/compare-entities.dto.js +3 -0
  17. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  18. package/audit/dto/pre-check-restore.dto.js +3 -0
  19. package/audit/dto/restore-entity.dto.d.ts +3 -0
  20. package/audit/dto/restore-entity.dto.js +3 -0
  21. package/audit/entities/entity-audit-log.entity.d.ts +3 -0
  22. package/audit/entities/entity-audit-log.entity.js +3 -0
  23. package/audit/entities/entity-transaction.entity.d.ts +3 -0
  24. package/audit/entities/entity-transaction.entity.js +3 -0
  25. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  26. package/audit/entities/manual-operation-log.entity.js +4 -0
  27. package/audit/entities/operation-template.entity.d.ts +4 -0
  28. package/audit/entities/operation-template.entity.js +4 -0
  29. package/audit/enums/audit.enums.d.ts +17 -2
  30. package/audit/enums/audit.enums.js +15 -0
  31. package/audit/index.js +10 -0
  32. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  33. package/audit/interceptors/audit.interceptor.js +23 -1
  34. package/audit/interfaces/audit.interfaces.d.ts +42 -0
  35. package/audit/services/audit-context.service.d.ts +15 -0
  36. package/audit/services/audit-context.service.js +15 -0
  37. package/audit/services/audit-strategy.service.d.ts +6 -0
  38. package/audit/services/audit-strategy.service.js +13 -0
  39. package/audit/services/entity-audit.service.d.ts +57 -0
  40. package/audit/services/entity-audit.service.js +91 -0
  41. package/audit/services/manual-audit-log.service.d.ts +124 -0
  42. package/audit/services/manual-audit-log.service.js +138 -0
  43. package/audit/services/multi-database.service.d.ts +12 -0
  44. package/audit/services/multi-database.service.js +12 -0
  45. package/audit/services/operation-description.service.d.ts +59 -0
  46. package/audit/services/operation-description.service.js +76 -2
  47. package/audit/services/transaction-audit.service.d.ts +30 -0
  48. package/audit/services/transaction-audit.service.js +47 -0
  49. package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
  50. package/audit/subscribers/entity-audit.subscriber.js +29 -1
  51. package/cache/cache-metrics.service.d.ts +67 -0
  52. package/cache/cache-metrics.service.js +68 -4
  53. package/cache/cache-serialization.service.d.ts +31 -0
  54. package/cache/cache-serialization.service.js +25 -0
  55. package/cache/cache.constants.d.ts +9 -0
  56. package/cache/cache.constants.js +9 -0
  57. package/cache/cache.health.d.ts +26 -0
  58. package/cache/cache.health.js +30 -0
  59. package/cache/cache.module.d.ts +86 -0
  60. package/cache/cache.module.js +71 -0
  61. package/cache/cache.service.d.ts +140 -0
  62. package/cache/cache.service.js +157 -0
  63. package/cache/cache.warmup.service.d.ts +39 -0
  64. package/cache/cache.warmup.service.js +32 -0
  65. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  66. package/cache/decorators/cache-evict.decorator.js +56 -0
  67. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  68. package/cache/decorators/cache-put.decorator.js +39 -0
  69. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  70. package/cache/decorators/cacheable.decorator.js +55 -0
  71. package/cache/dependencies/callback.dependency.d.ts +33 -0
  72. package/cache/dependencies/callback.dependency.js +39 -1
  73. package/cache/dependencies/chain.dependency.d.ts +28 -0
  74. package/cache/dependencies/chain.dependency.js +34 -0
  75. package/cache/dependencies/db.dependency.d.ts +45 -0
  76. package/cache/dependencies/db.dependency.js +48 -1
  77. package/cache/dependencies/file.dependency.d.ts +32 -0
  78. package/cache/dependencies/file.dependency.js +34 -0
  79. package/cache/dependencies/tag.dependency.d.ts +36 -0
  80. package/cache/dependencies/tag.dependency.js +36 -0
  81. package/cache/dependencies/time.dependency.d.ts +43 -0
  82. package/cache/dependencies/time.dependency.js +43 -0
  83. package/cache/examples/basic-usage.d.ts +15 -0
  84. package/cache/examples/basic-usage.js +62 -8
  85. package/cache/index.js +9 -0
  86. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  87. package/cache/interfaces/cache-options.interface.d.ts +81 -0
  88. package/cache/interfaces/cache-options.interface.js +6 -0
  89. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  90. package/cache/providers/base-cache.provider.d.ts +14 -0
  91. package/cache/providers/base-cache.provider.js +16 -0
  92. package/cache/providers/cls-cache.provider.d.ts +20 -0
  93. package/cache/providers/cls-cache.provider.js +28 -0
  94. package/cache/providers/memory-cache.provider.d.ts +23 -0
  95. package/cache/providers/memory-cache.provider.js +26 -0
  96. package/cache/providers/redis-cache.provider.d.ts +26 -0
  97. package/cache/providers/redis-cache.provider.js +29 -0
  98. package/cache/utils/dependency-manager.util.d.ts +52 -0
  99. package/cache/utils/dependency-manager.util.js +59 -0
  100. package/cache/utils/key-generator.util.d.ts +42 -0
  101. package/cache/utils/key-generator.util.js +53 -1
  102. package/common/abstract.entity.d.ts +14 -0
  103. package/common/abstract.entity.js +14 -0
  104. package/common/boilerplate.polyfill.d.ts +142 -0
  105. package/common/boilerplate.polyfill.js +17 -0
  106. package/common/dto/dto-container.d.ts +16 -0
  107. package/common/dto/dto-container.js +20 -0
  108. package/common/dto/dto-decorators.d.ts +18 -0
  109. package/common/dto/dto-decorators.js +14 -0
  110. package/common/dto/dto-extensions.d.ts +11 -0
  111. package/common/dto/dto-extensions.js +9 -0
  112. package/common/dto/dto-service-accessor.d.ts +17 -0
  113. package/common/dto/dto-service-accessor.js +18 -0
  114. package/common/dto/dto-transformer.d.ts +12 -0
  115. package/common/dto/dto-transformer.js +9 -0
  116. package/common/dto/index.js +2 -0
  117. package/common/examples/paginate-and-map.example.d.ts +6 -0
  118. package/common/examples/paginate-and-map.example.js +26 -0
  119. package/common/utils.d.ts +15 -0
  120. package/common/utils.js +15 -0
  121. package/constants/language-code.js +1 -0
  122. package/decorators/field.decorators.js +8 -1
  123. package/decorators/property.decorators.js +1 -0
  124. package/decorators/public-route.decorator.js +1 -0
  125. package/decorators/transform.decorators.d.ts +27 -0
  126. package/decorators/transform.decorators.js +29 -0
  127. package/decorators/translate.decorator.js +1 -0
  128. package/decorators/user.decorator.js +1 -0
  129. package/decorators/validator.decorators.d.ts +8 -18
  130. package/decorators/validator.decorators.js +22 -190
  131. package/filters/constraint-errors.js +1 -0
  132. package/helpers/common.helper.d.ts +13 -0
  133. package/helpers/common.helper.js +13 -0
  134. package/http-client/config/http-client.config.d.ts +15 -0
  135. package/http-client/config/http-client.config.js +25 -9
  136. package/http-client/decorators/http-client.decorators.d.ts +63 -0
  137. package/http-client/decorators/http-client.decorators.js +71 -3
  138. package/http-client/entities/http-log.entity.d.ts +229 -0
  139. package/http-client/entities/http-log.entity.js +6 -1
  140. package/http-client/errors/http-client.errors.d.ts +57 -0
  141. package/http-client/errors/http-client.errors.js +58 -0
  142. package/http-client/examples/advanced-usage.example.d.ts +41 -0
  143. package/http-client/examples/advanced-usage.example.js +68 -24
  144. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  145. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  146. package/http-client/examples/basic-usage.example.d.ts +60 -0
  147. package/http-client/examples/basic-usage.example.js +60 -0
  148. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  149. package/http-client/examples/multi-api-configuration.example.js +76 -5
  150. package/http-client/http-client.module.d.ts +13 -0
  151. package/http-client/http-client.module.js +19 -0
  152. package/http-client/index.js +8 -0
  153. package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
  154. package/http-client/interfaces/api-client-config.interface.js +3 -0
  155. package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
  156. package/http-client/services/api-client-registry.service.d.ts +57 -0
  157. package/http-client/services/api-client-registry.service.js +84 -1
  158. package/http-client/services/cache.service.d.ts +52 -0
  159. package/http-client/services/cache.service.js +72 -3
  160. package/http-client/services/circuit-breaker.service.d.ts +46 -0
  161. package/http-client/services/circuit-breaker.service.js +52 -0
  162. package/http-client/services/http-client.service.d.ts +67 -0
  163. package/http-client/services/http-client.service.js +105 -4
  164. package/http-client/services/http-log-query.service.d.ts +83 -0
  165. package/http-client/services/http-log-query.service.js +122 -1
  166. package/http-client/services/http-replay.service.d.ts +101 -0
  167. package/http-client/services/http-replay.service.js +86 -0
  168. package/http-client/services/log-cleanup.service.d.ts +63 -0
  169. package/http-client/services/log-cleanup.service.js +54 -2
  170. package/http-client/services/logging.service.d.ts +40 -0
  171. package/http-client/services/logging.service.js +53 -0
  172. package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
  173. package/http-client/utils/call-stack-extractor.util.js +48 -0
  174. package/http-client/utils/context-extractor.util.d.ts +49 -0
  175. package/http-client/utils/context-extractor.util.js +52 -0
  176. package/http-client/utils/curl-generator.util.d.ts +21 -0
  177. package/http-client/utils/curl-generator.util.js +44 -3
  178. package/http-client/utils/request-id.util.d.ts +18 -0
  179. package/http-client/utils/request-id.util.js +20 -0
  180. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  181. package/http-client/utils/retry-recorder.util.js +44 -0
  182. package/index.js +8 -0
  183. package/interceptors/translation-interceptor.service.js +5 -0
  184. package/package.json +1 -1
  185. package/providers/context.provider.js +2 -0
  186. package/providers/generator.provider.d.ts +4 -0
  187. package/providers/generator.provider.js +4 -0
  188. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  189. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  190. package/redis-lock/index.js +3 -0
  191. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  192. package/redis-lock/redis-lock.decorator.js +120 -0
  193. package/redis-lock/redis-lock.module.d.ts +60 -0
  194. package/redis-lock/redis-lock.module.js +46 -0
  195. package/redis-lock/redis-lock.service.d.ts +251 -0
  196. package/redis-lock/redis-lock.service.js +219 -3
  197. package/setup/bootstrap.setup.js +20 -0
  198. package/setup/mode.setup.d.ts +44 -0
  199. package/setup/mode.setup.js +44 -0
  200. package/setup/schedule.decorator.d.ts +226 -0
  201. package/setup/schedule.decorator.js +214 -1
  202. package/setup/worker.decorator.d.ts +86 -0
  203. package/setup/worker.decorator.js +88 -0
  204. package/shared/serviceRegistryModule.js +5 -1
  205. package/shared/services/api-config.service.d.ts +3 -0
  206. package/shared/services/api-config.service.js +20 -9
  207. package/validator-json/decorators.d.ts +17 -0
  208. package/validator-json/decorators.js +17 -2
  209. package/validator-json/default.d.ts +6 -0
  210. package/validator-json/default.js +30 -2
  211. package/validator-json/defaultConverters.js +1 -0
  212. package/validator-json/options.d.ts +23 -0
  213. package/validators/common-validators.d.ts +143 -0
  214. package/validators/common-validators.js +249 -0
  215. package/validators/custom-validate.examples.d.ts +23 -0
  216. package/validators/custom-validate.examples.js +78 -6
  217. package/validators/custom-validate.validator.d.ts +107 -0
  218. package/validators/custom-validate.validator.js +84 -0
  219. package/validators/index.d.ts +1 -0
  220. package/validators/index.js +1 -0
  221. package/validators/is-exists.validator.d.ts +11 -0
  222. package/validators/is-exists.validator.js +22 -0
  223. package/validators/is-unique.validator.d.ts +11 -0
  224. package/validators/is-unique.validator.js +31 -3
  225. package/validators/skip-empty.validator.d.ts +5 -0
  226. package/validators/skip-empty.validator.js +5 -0
  227. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  228. package/vault/vault-config.loader.d.ts +30 -0
  229. package/vault/vault-config.loader.js +48 -1
  230. package/vault/vault-config.service.d.ts +53 -0
  231. package/vault/vault-config.service.js +57 -0
  232. package/vault/vault.module.d.ts +4 -0
  233. package/vault/vault.module.js +4 -0
  234. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  235. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -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) {
@@ -1,2 +1,6 @@
1
+ /**
2
+ * Vault 模块
3
+ * 全局模块,提供 VaultConfigService 供整个应用使用
4
+ */
1
5
  export declare class VaultModule {
2
6
  }
@@ -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
- }
@@ -1,331 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
- return new (P || (P = Promise))(function (resolve, reject) {
14
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
- step((generator = generator.apply(thisArg, _arguments || [])).next());
18
- });
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.PaymentMethodDto = exports.EmployeeDto = exports.CreateProductDto = exports.UserRegistrationDto = exports.DiscountDto = exports.OrderDto = exports.EmailCheckDto = exports.PasswordDto = exports.SearchDto = exports.ContactDto = void 0;
22
- const class_validator_1 = require("class-validator");
23
- const swagger_1 = require("@nestjs/swagger");
24
- const validator_decorators_1 = require("../validator.decorators");
25
- const field_decorators_1 = require("../field.decorators");
26
- class ContactDto {
27
- }
28
- exports.ContactDto = ContactDto;
29
- __decorate([
30
- (0, swagger_1.ApiProperty)({ required: false }),
31
- (0, class_validator_1.IsEmail)(),
32
- (0, validator_decorators_1.AtLeastOneField)(['email', 'phone', 'wechat']),
33
- __metadata("design:type", String)
34
- ], ContactDto.prototype, "email", void 0);
35
- __decorate([
36
- (0, swagger_1.ApiProperty)({ required: false }),
37
- (0, class_validator_1.IsString)(),
38
- __metadata("design:type", String)
39
- ], ContactDto.prototype, "phone", void 0);
40
- __decorate([
41
- (0, swagger_1.ApiProperty)({ required: false }),
42
- (0, class_validator_1.IsString)(),
43
- __metadata("design:type", String)
44
- ], ContactDto.prototype, "wechat", void 0);
45
- class SearchDto {
46
- }
47
- exports.SearchDto = SearchDto;
48
- __decorate([
49
- (0, field_decorators_1.StringFieldOptional)(),
50
- (0, validator_decorators_1.AtLeastOneField)(['keyword', 'category', 'tags'], {
51
- message: 'Please provide at least one search criteria: keyword, category, or tags',
52
- }),
53
- __metadata("design:type", String)
54
- ], SearchDto.prototype, "keyword", void 0);
55
- __decorate([
56
- (0, field_decorators_1.StringFieldOptional)(),
57
- __metadata("design:type", String)
58
- ], SearchDto.prototype, "category", void 0);
59
- __decorate([
60
- (0, field_decorators_1.StringFieldOptional)({ each: true }),
61
- __metadata("design:type", Array)
62
- ], SearchDto.prototype, "tags", void 0);
63
- class PasswordDto {
64
- }
65
- exports.PasswordDto = PasswordDto;
66
- __decorate([
67
- (0, validator_decorators_1.CustomValidation)((value) => {
68
- if (!value || value.length < 8)
69
- return false;
70
- const hasUppercase = /[A-Z]/.test(value);
71
- const hasLowercase = /[a-z]/.test(value);
72
- const hasNumber = /[0-9]/.test(value);
73
- return hasUppercase && hasLowercase && hasNumber;
74
- }, {
75
- message: 'Password must be at least 8 characters with uppercase, lowercase, and number',
76
- }),
77
- (0, swagger_1.ApiProperty)(),
78
- __metadata("design:type", String)
79
- ], PasswordDto.prototype, "password", void 0);
80
- class EmailCheckDto {
81
- }
82
- exports.EmailCheckDto = EmailCheckDto;
83
- __decorate([
84
- (0, validator_decorators_1.CustomValidation)((value, args) => __awaiter(void 0, void 0, void 0, function* () {
85
- const userService = args.object.userService;
86
- if (!userService) {
87
- console.warn('UserService not found, skipping email check');
88
- return true;
89
- }
90
- const exists = yield userService.checkEmailExists(value);
91
- return !exists;
92
- }), {
93
- message: 'Email already exists in the system',
94
- }),
95
- (0, class_validator_1.IsEmail)(),
96
- (0, swagger_1.ApiProperty)(),
97
- __metadata("design:type", String)
98
- ], EmailCheckDto.prototype, "email", void 0);
99
- class OrderDto {
100
- }
101
- exports.OrderDto = OrderDto;
102
- __decorate([
103
- (0, swagger_1.ApiProperty)({ enum: ['standard', 'express'] }),
104
- (0, class_validator_1.IsString)(),
105
- __metadata("design:type", String)
106
- ], OrderDto.prototype, "orderType", void 0);
107
- __decorate([
108
- (0, validator_decorators_1.CustomValidation)((value, args) => {
109
- const object = args.object;
110
- if (object.orderType === 'express') {
111
- return value !== null && value !== undefined;
112
- }
113
- return true;
114
- }, {
115
- message: 'Delivery date is required for express orders',
116
- }),
117
- (0, swagger_1.ApiProperty)({ required: false }),
118
- __metadata("design:type", Date)
119
- ], OrderDto.prototype, "deliveryDate", void 0);
120
- class DiscountDto {
121
- get validatedDiscountValue() {
122
- return this.discountValue;
123
- }
124
- }
125
- exports.DiscountDto = DiscountDto;
126
- __decorate([
127
- (0, swagger_1.ApiProperty)(),
128
- __metadata("design:type", String)
129
- ], DiscountDto.prototype, "discountType", void 0);
130
- __decorate([
131
- (0, swagger_1.ApiProperty)(),
132
- __metadata("design:type", Number)
133
- ], DiscountDto.prototype, "discountValue", void 0);
134
- __decorate([
135
- (0, validator_decorators_1.CustomValidation)((value, args) => {
136
- const object = args.object;
137
- if (object.discountType === 'percentage') {
138
- return value >= 0 && value <= 100;
139
- }
140
- else if (object.discountType === 'fixed') {
141
- return value > 0;
142
- }
143
- return false;
144
- }, {
145
- message: 'Invalid discount value for the selected discount type',
146
- }),
147
- __metadata("design:type", Object),
148
- __metadata("design:paramtypes", [])
149
- ], DiscountDto.prototype, "validatedDiscountValue", null);
150
- class UserRegistrationDto {
151
- validatePassword(password) {
152
- if (!password || password.length < 8)
153
- return false;
154
- const hasUppercase = /[A-Z]/.test(password);
155
- const hasLowercase = /[a-z]/.test(password);
156
- const hasNumber = /[0-9]/.test(password);
157
- const hasSpecial = /[!@#$%^&*]/.test(password);
158
- return hasUppercase && hasLowercase && hasNumber && hasSpecial;
159
- }
160
- validatePasswordMatch(confirmPassword) {
161
- return confirmPassword === this.password;
162
- }
163
- }
164
- exports.UserRegistrationDto = UserRegistrationDto;
165
- __decorate([
166
- (0, swagger_1.ApiProperty)(),
167
- (0, class_validator_1.IsString)(),
168
- __metadata("design:type", String)
169
- ], UserRegistrationDto.prototype, "username", void 0);
170
- __decorate([
171
- (0, validator_decorators_1.CustomValidationMethod)('validatePassword', {
172
- message: 'Password does not meet security requirements',
173
- }),
174
- (0, swagger_1.ApiProperty)(),
175
- __metadata("design:type", String)
176
- ], UserRegistrationDto.prototype, "password", void 0);
177
- __decorate([
178
- (0, validator_decorators_1.CustomValidationMethod)('validatePasswordMatch'),
179
- (0, swagger_1.ApiProperty)(),
180
- __metadata("design:type", String)
181
- ], UserRegistrationDto.prototype, "confirmPassword", void 0);
182
- class CreateProductDto {
183
- get validatedCategoryId() {
184
- return this.categoryId;
185
- }
186
- checkSkuUniqueness(sku) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- if (!this.productService) {
189
- console.warn('ProductService not found');
190
- return true;
191
- }
192
- const exists = yield this.productService.skuExists(sku);
193
- return !exists;
194
- });
195
- }
196
- validateCategoryExists(categoryId) {
197
- return __awaiter(this, void 0, void 0, function* () {
198
- if (!this.categoryService) {
199
- console.warn('CategoryService not found');
200
- return true;
201
- }
202
- return yield this.categoryService.exists(categoryId);
203
- });
204
- }
205
- }
206
- exports.CreateProductDto = CreateProductDto;
207
- __decorate([
208
- (0, swagger_1.ApiProperty)(),
209
- (0, class_validator_1.IsString)(),
210
- __metadata("design:type", String)
211
- ], CreateProductDto.prototype, "name", void 0);
212
- __decorate([
213
- (0, validator_decorators_1.CustomValidationMethod)('checkSkuUniqueness', {
214
- message: 'SKU already exists',
215
- }),
216
- (0, swagger_1.ApiProperty)(),
217
- __metadata("design:type", String)
218
- ], CreateProductDto.prototype, "sku", void 0);
219
- __decorate([
220
- (0, swagger_1.ApiProperty)(),
221
- __metadata("design:type", String)
222
- ], CreateProductDto.prototype, "categoryId", void 0);
223
- __decorate([
224
- (0, validator_decorators_1.CustomValidationMethod)('validateCategoryExists', {
225
- message: 'Category does not exist',
226
- }),
227
- __metadata("design:type", Object),
228
- __metadata("design:paramtypes", [])
229
- ], CreateProductDto.prototype, "validatedCategoryId", null);
230
- class EmployeeDto {
231
- validatePhoneFormat(phone) {
232
- if (!phone)
233
- return true;
234
- const phoneRegex = /^\+?[1-9]\d{1,14}$/;
235
- return phoneRegex.test(phone);
236
- }
237
- }
238
- exports.EmployeeDto = EmployeeDto;
239
- __decorate([
240
- (0, swagger_1.ApiProperty)(),
241
- (0, class_validator_1.IsString)(),
242
- __metadata("design:type", String)
243
- ], EmployeeDto.prototype, "name", void 0);
244
- __decorate([
245
- (0, validator_decorators_1.CustomValidation)((value) => {
246
- const workDomains = ['company.com', 'corp.com'];
247
- const domain = value === null || value === void 0 ? void 0 : value.split('@')[1];
248
- return !workDomains.includes(domain);
249
- }, {
250
- message: 'Personal email should not be from work domains',
251
- }),
252
- (0, class_validator_1.IsEmail)(),
253
- (0, validator_decorators_1.AtLeastOneField)(['personalEmail', 'workEmail']),
254
- (0, swagger_1.ApiProperty)({ required: false }),
255
- __metadata("design:type", String)
256
- ], EmployeeDto.prototype, "personalEmail", void 0);
257
- __decorate([
258
- (0, validator_decorators_1.CustomValidation)((value) => {
259
- const workDomains = ['company.com', 'corp.com'];
260
- const domain = value === null || value === void 0 ? void 0 : value.split('@')[1];
261
- return workDomains.includes(domain);
262
- }, {
263
- message: 'Work email must be from company domains',
264
- }),
265
- (0, class_validator_1.IsEmail)(),
266
- (0, swagger_1.ApiProperty)({ required: false }),
267
- __metadata("design:type", String)
268
- ], EmployeeDto.prototype, "workEmail", void 0);
269
- __decorate([
270
- (0, validator_decorators_1.CustomValidationMethod)('validatePhoneFormat'),
271
- (0, swagger_1.ApiProperty)({ required: false }),
272
- __metadata("design:type", String)
273
- ], EmployeeDto.prototype, "phone", void 0);
274
- class PaymentMethodDto {
275
- validateCreditCard(creditCard) {
276
- var _a;
277
- if (!creditCard)
278
- return true;
279
- const number = (_a = creditCard.number) === null || _a === void 0 ? void 0 : _a.replace(/\s/g, '');
280
- if (!/^\d{13,19}$/.test(number))
281
- return false;
282
- let sum = 0;
283
- let isEven = false;
284
- for (let i = number.length - 1; i >= 0; i--) {
285
- let digit = parseInt(number[i], 10);
286
- if (isEven) {
287
- digit *= 2;
288
- if (digit > 9)
289
- digit -= 9;
290
- }
291
- sum += digit;
292
- isEven = !isEven;
293
- }
294
- return sum % 10 === 0;
295
- }
296
- validateBankAccount(bankAccount) {
297
- if (!bankAccount)
298
- return true;
299
- const accountValid = /^\d{8,17}$/.test(bankAccount.accountNumber);
300
- const routingValid = /^\d{9}$/.test(bankAccount.routingNumber);
301
- return accountValid && routingValid;
302
- }
303
- validateDigitalWallet(digitalWallet) {
304
- var _a;
305
- if (!digitalWallet)
306
- return true;
307
- const validProviders = ['paypal', 'alipay', 'wechat_pay', 'apple_pay'];
308
- return validProviders.includes((_a = digitalWallet.provider) === null || _a === void 0 ? void 0 : _a.toLowerCase());
309
- }
310
- }
311
- exports.PaymentMethodDto = PaymentMethodDto;
312
- __decorate([
313
- (0, swagger_1.ApiProperty)(),
314
- __metadata("design:type", String)
315
- ], PaymentMethodDto.prototype, "paymentType", void 0);
316
- __decorate([
317
- (0, validator_decorators_1.CustomValidationMethod)('validateCreditCard'),
318
- (0, validator_decorators_1.AtLeastOneField)(['creditCard', 'bankAccount', 'digitalWallet']),
319
- (0, swagger_1.ApiProperty)({ required: false }),
320
- __metadata("design:type", Object)
321
- ], PaymentMethodDto.prototype, "creditCard", void 0);
322
- __decorate([
323
- (0, validator_decorators_1.CustomValidationMethod)('validateBankAccount'),
324
- (0, swagger_1.ApiProperty)({ required: false }),
325
- __metadata("design:type", Object)
326
- ], PaymentMethodDto.prototype, "bankAccount", void 0);
327
- __decorate([
328
- (0, validator_decorators_1.CustomValidationMethod)('validateDigitalWallet'),
329
- (0, swagger_1.ApiProperty)({ required: false }),
330
- __metadata("design:type", Object)
331
- ], PaymentMethodDto.prototype, "digitalWallet", void 0);