@uofx/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +444 -0
  3. package/THIRD-PARTY-NOTICES.txt +894 -0
  4. package/dist/application/dtos/index.js +24 -0
  5. package/dist/application/dtos/request/delete-instance.request.dto.js +3 -0
  6. package/dist/application/dtos/request/get-config.request.dto.js +3 -0
  7. package/dist/application/dtos/request/get-credentials.request.dto.js +3 -0
  8. package/dist/application/dtos/request/index.js +27 -0
  9. package/dist/application/dtos/request/install-instance.request.dto.js +3 -0
  10. package/dist/application/dtos/request/list-charts.request.dto.js +3 -0
  11. package/dist/application/dtos/request/set-config.request.dto.js +16 -0
  12. package/dist/application/dtos/request/setup-environment.request.dto.js +16 -0
  13. package/dist/application/dtos/request/show-logs.request.dto.js +19 -0
  14. package/dist/application/dtos/request/start-instance.request.dto.js +3 -0
  15. package/dist/application/dtos/request/stop-instance.request.dto.js +3 -0
  16. package/dist/application/dtos/response/credentials.response.dto.js +3 -0
  17. package/dist/application/dtos/response/delete-instance.response.dto.js +3 -0
  18. package/dist/application/dtos/response/index.js +26 -0
  19. package/dist/application/dtos/response/install-instance.response.dto.js +3 -0
  20. package/dist/application/dtos/response/instance-list.response.dto.js +3 -0
  21. package/dist/application/dtos/response/instance-status.response.dto.js +3 -0
  22. package/dist/application/dtos/response/setup-result.response.dto.js +3 -0
  23. package/dist/application/dtos/response/show-logs.response.dto.js +3 -0
  24. package/dist/application/dtos/response/start-instance.response.dto.js +3 -0
  25. package/dist/application/dtos/response/stop-instance.response.dto.js +3 -0
  26. package/dist/application/index.js +25 -0
  27. package/dist/application/interfaces/index.js +24 -0
  28. package/dist/application/interfaces/use-case.interface.js +3 -0
  29. package/dist/application/use-cases/config/get-config.use-case.js +66 -0
  30. package/dist/application/use-cases/config/set-config.use-case.js +49 -0
  31. package/dist/application/use-cases/credentials/get-credentials.use-case.js +57 -0
  32. package/dist/application/use-cases/index.js +28 -0
  33. package/dist/application/use-cases/instance/delete-instance.use-case.js +81 -0
  34. package/dist/application/use-cases/instance/index.js +23 -0
  35. package/dist/application/use-cases/instance/install-instance.use-case.js +424 -0
  36. package/dist/application/use-cases/instance/list-charts.use-case.js +43 -0
  37. package/dist/application/use-cases/instance/list-instances.use-case.js +62 -0
  38. package/dist/application/use-cases/instance/start-instance.use-case.js +154 -0
  39. package/dist/application/use-cases/instance/stop-instance.use-case.js +55 -0
  40. package/dist/application/use-cases/logs/show-logs.use-case.js +66 -0
  41. package/dist/application/use-cases/setup/setup-environment.use-case.js +53 -0
  42. package/dist/cli.js +286 -0
  43. package/dist/constants/config-defaults.js +23 -0
  44. package/dist/constants/defaults.js +89 -0
  45. package/dist/constants/deployment.js +39 -0
  46. package/dist/constants/environments.js +93 -0
  47. package/dist/constants/index.js +53 -0
  48. package/dist/constants/oci-artifacts.js +25 -0
  49. package/dist/constants/paths.js +92 -0
  50. package/dist/constants/timeouts.js +60 -0
  51. package/dist/di/container.js +34 -0
  52. package/dist/di/index.js +22 -0
  53. package/dist/di/modules/application.module.js +54 -0
  54. package/dist/di/modules/infrastructure.module.js +206 -0
  55. package/dist/di/modules/interceptor.module.js +68 -0
  56. package/dist/di/modules/presentation.module.js +31 -0
  57. package/dist/di/tokens.js +149 -0
  58. package/dist/domain/decorators/sensitive.decorator.js +39 -0
  59. package/dist/domain/entities/credentials-resolver.entity.js +127 -0
  60. package/dist/domain/entities/credentials.entity.js +65 -0
  61. package/dist/domain/entities/delete-instance-validation.entity.js +100 -0
  62. package/dist/domain/entities/deployment-parameters.entity.js +120 -0
  63. package/dist/domain/entities/environment-validation.entity.js +125 -0
  64. package/dist/domain/entities/index.js +29 -0
  65. package/dist/domain/entities/instance-lifecycle-state.entity.js +100 -0
  66. package/dist/domain/entities/instance-list-aggregator.entity.js +104 -0
  67. package/dist/domain/entities/instance-metadata.entity.js +86 -0
  68. package/dist/domain/entities/instance-status.entity.js +79 -0
  69. package/dist/domain/entities/instance.entity.js +128 -0
  70. package/dist/domain/entities/log-filter.entity.js +141 -0
  71. package/dist/domain/index.js +29 -0
  72. package/dist/domain/interfaces/safe-loggable.interface.js +3 -0
  73. package/dist/domain/ports/app-config.port.js +3 -0
  74. package/dist/domain/ports/base-image.port.js +3 -0
  75. package/dist/domain/ports/chart-version.port.js +3 -0
  76. package/dist/domain/ports/correlation-id.port.js +3 -0
  77. package/dist/domain/ports/credentials.port.js +3 -0
  78. package/dist/domain/ports/deployment.port.js +3 -0
  79. package/dist/domain/ports/error-handler.port.js +3 -0
  80. package/dist/domain/ports/index.js +46 -0
  81. package/dist/domain/ports/instance-manager.port.js +3 -0
  82. package/dist/domain/ports/instance-metadata.port.js +8 -0
  83. package/dist/domain/ports/instance-storage.port.js +3 -0
  84. package/dist/domain/ports/k8s-deployer.port.js +3 -0
  85. package/dist/domain/ports/logger.port.js +14 -0
  86. package/dist/domain/ports/output.port.js +3 -0
  87. package/dist/domain/ports/runtime-environment.port.js +6 -0
  88. package/dist/domain/ports/user-interaction.port.js +9 -0
  89. package/dist/domain/ports/user-settings.port.js +3 -0
  90. package/dist/domain/types/index.js +22 -0
  91. package/dist/domain/types/logger.types.js +29 -0
  92. package/dist/domain/types/validation.types.js +9 -0
  93. package/dist/domain/value-objects/acr-credentials.value-object.js +92 -0
  94. package/dist/domain/value-objects/chart-version.value-object.js +124 -0
  95. package/dist/domain/value-objects/config-log-level.value-object.js +84 -0
  96. package/dist/domain/value-objects/connection-info.value-object.js +65 -0
  97. package/dist/domain/value-objects/index.js +25 -0
  98. package/dist/domain/value-objects/instance-name.value-object.js +91 -0
  99. package/dist/domain/value-objects/jwt-key.value-object.js +97 -0
  100. package/dist/domain/value-objects/mssql-password.value-object.js +140 -0
  101. package/dist/domain/value-objects/rsa-key-pair.value-object.js +181 -0
  102. package/dist/index.js +6 -0
  103. package/dist/infrastructure/config/app-config.interface.js +3 -0
  104. package/dist/infrastructure/config/app-config.service.js +280 -0
  105. package/dist/infrastructure/config/config-validator.js +31 -0
  106. package/dist/infrastructure/config/crypto.service.js +125 -0
  107. package/dist/infrastructure/deployment/deployment.adapter.js +118 -0
  108. package/dist/infrastructure/deployment/interfaces/acr-credential-manager.interface.js +3 -0
  109. package/dist/infrastructure/deployment/interfaces/app-manager.interface.js +3 -0
  110. package/dist/infrastructure/deployment/interfaces/helm-registry.interface.js +3 -0
  111. package/dist/infrastructure/deployment/interfaces/infra-manager.interface.js +3 -0
  112. package/dist/infrastructure/deployment/interfaces/k8s-job-runner.interface.js +3 -0
  113. package/dist/infrastructure/deployment/interfaces/mssql-database-init.interface.js +3 -0
  114. package/dist/infrastructure/deployment/interfaces/mssql-helm-deployment.interface.js +3 -0
  115. package/dist/infrastructure/deployment/interfaces/mssql-storage.interface.js +3 -0
  116. package/dist/infrastructure/deployment/interfaces/mssql-user-manager.interface.js +3 -0
  117. package/dist/infrastructure/deployment/interfaces/oci-artifact.interface.js +3 -0
  118. package/dist/infrastructure/deployment/interfaces/secret-manager.interface.js +3 -0
  119. package/dist/infrastructure/deployment/interfaces/service-manager.interface.js +3 -0
  120. package/dist/infrastructure/deployment/interfaces/version-compatibility.interface.js +3 -0
  121. package/dist/infrastructure/deployment/services/acr-credential-manager.service.js +144 -0
  122. package/dist/infrastructure/deployment/services/app-manager.service.js +193 -0
  123. package/dist/infrastructure/deployment/services/base-helm-deployment.service.js +163 -0
  124. package/dist/infrastructure/deployment/services/helm-registry.service.js +126 -0
  125. package/dist/infrastructure/deployment/services/infra-manager.service.js +130 -0
  126. package/dist/infrastructure/deployment/services/k8s-job-runner.service.js +194 -0
  127. package/dist/infrastructure/deployment/services/mssql-database-init.service.js +139 -0
  128. package/dist/infrastructure/deployment/services/mssql-helm-deployment.service.js +100 -0
  129. package/dist/infrastructure/deployment/services/mssql-storage.service.js +54 -0
  130. package/dist/infrastructure/deployment/services/mssql-user-manager.service.js +66 -0
  131. package/dist/infrastructure/deployment/services/oci-artifact.service.js +289 -0
  132. package/dist/infrastructure/deployment/services/secret-manager.service.js +179 -0
  133. package/dist/infrastructure/deployment/services/service-manager.service.js +82 -0
  134. package/dist/infrastructure/deployment/services/version-compatibility.service.js +291 -0
  135. package/dist/infrastructure/environment/interfaces/hardware-info.interface.js +3 -0
  136. package/dist/infrastructure/environment/interfaces/network-checker.interface.js +3 -0
  137. package/dist/infrastructure/environment/services/hardware-info.service.js +135 -0
  138. package/dist/infrastructure/environment/services/network-checker.service.js +142 -0
  139. package/dist/infrastructure/environment/windows-environment.adapter.js +162 -0
  140. package/dist/infrastructure/errors/app-error.js +73 -0
  141. package/dist/infrastructure/errors/error-handler.interface.js +3 -0
  142. package/dist/infrastructure/errors/error-handler.js +218 -0
  143. package/dist/infrastructure/errors/exit-codes.js +27 -0
  144. package/dist/infrastructure/errors/index.js +25 -0
  145. package/dist/infrastructure/execution/builders/base-command.builder.js +122 -0
  146. package/dist/infrastructure/execution/builders/host-command.builder.js +58 -0
  147. package/dist/infrastructure/execution/builders/windows-host-command.builder.js +50 -0
  148. package/dist/infrastructure/execution/builders/wsl-command.builder.js +29 -0
  149. package/dist/infrastructure/execution/command-builder.js +252 -0
  150. package/dist/infrastructure/execution/command-executor.service.js +230 -0
  151. package/dist/infrastructure/execution/environments/wsl-execution.environment.js +70 -0
  152. package/dist/infrastructure/execution/execution-environment.factory.js +53 -0
  153. package/dist/infrastructure/execution/index.js +25 -0
  154. package/dist/infrastructure/execution/interfaces/command-builder.interface.js +3 -0
  155. package/dist/infrastructure/execution/interfaces/command-executor.interface.js +3 -0
  156. package/dist/infrastructure/execution/interfaces/execution-environment-factory.interface.js +3 -0
  157. package/dist/infrastructure/execution/interfaces/execution-environment.interface.js +7 -0
  158. package/dist/infrastructure/execution/interfaces/host-command-builder.interface.js +3 -0
  159. package/dist/infrastructure/execution/interfaces/index.js +23 -0
  160. package/dist/infrastructure/execution/interfaces/script-executor.interface.js +3 -0
  161. package/dist/infrastructure/execution/script-executor.service.js +171 -0
  162. package/dist/infrastructure/http/http-client.service.js +176 -0
  163. package/dist/infrastructure/http/index.js +18 -0
  164. package/dist/infrastructure/http/interfaces/http-client.interface.js +3 -0
  165. package/dist/infrastructure/interceptors/index.js +8 -0
  166. package/dist/infrastructure/interceptors/interceptor.factory.js +44 -0
  167. package/dist/infrastructure/interceptors/interceptor.interface.js +3 -0
  168. package/dist/infrastructure/interceptors/logging.interceptor.js +171 -0
  169. package/dist/infrastructure/logger/correlation-id.adapter.js +68 -0
  170. package/dist/infrastructure/logger/index.js +23 -0
  171. package/dist/infrastructure/logger/interfaces/index.js +22 -0
  172. package/dist/infrastructure/logger/interfaces/log-reader.repository.interface.js +7 -0
  173. package/dist/infrastructure/logger/interfaces/log-writer.repository.interface.js +7 -0
  174. package/dist/infrastructure/logger/logger.adapter.js +274 -0
  175. package/dist/infrastructure/logger/services/file-log-reader.repository.js +148 -0
  176. package/dist/infrastructure/logger/services/file-log-writer.repository.js +307 -0
  177. package/dist/infrastructure/logger/services/index.js +22 -0
  178. package/dist/infrastructure/persistence/index.js +25 -0
  179. package/dist/infrastructure/persistence/instance-metadata.adapter.js +100 -0
  180. package/dist/infrastructure/persistence/instance-storage.adapter.js +64 -0
  181. package/dist/infrastructure/persistence/interfaces/config.repository.interface.js +3 -0
  182. package/dist/infrastructure/persistence/interfaces/index.js +22 -0
  183. package/dist/infrastructure/persistence/interfaces/instance.repository.interface.js +3 -0
  184. package/dist/infrastructure/persistence/services/file-system-config.repository.js +168 -0
  185. package/dist/infrastructure/persistence/services/file-system-instance.repository.js +170 -0
  186. package/dist/infrastructure/persistence/services/index.js +22 -0
  187. package/dist/infrastructure/persistence/user-settings.adapter.js +55 -0
  188. package/dist/infrastructure/platform-detector.js +71 -0
  189. package/dist/infrastructure/platforms/windows/interfaces/microk8s.interface.js +3 -0
  190. package/dist/infrastructure/platforms/windows/interfaces/rootfs-manager.interface.js +3 -0
  191. package/dist/infrastructure/platforms/windows/interfaces/windows-features.interface.js +3 -0
  192. package/dist/infrastructure/platforms/windows/interfaces/windows-info.interface.js +3 -0
  193. package/dist/infrastructure/platforms/windows/interfaces/wsl-config.interface.js +3 -0
  194. package/dist/infrastructure/platforms/windows/interfaces/wsl-info.interface.js +3 -0
  195. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-inspection.interface.js +3 -0
  196. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-lifecycle.interface.js +3 -0
  197. package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-naming.interface.js +3 -0
  198. package/dist/infrastructure/platforms/windows/interfaces/wsl-manager.interface.js +3 -0
  199. package/dist/infrastructure/platforms/windows/interfaces/wsl-resources.interface.js +8 -0
  200. package/dist/infrastructure/platforms/windows/interfaces/wsl-updater.interface.js +3 -0
  201. package/dist/infrastructure/platforms/windows/interfaces/wslconfig-parser.interface.js +3 -0
  202. package/dist/infrastructure/platforms/windows/parsers/wsl-version.parser.js +133 -0
  203. package/dist/infrastructure/platforms/windows/services/microk8s.service.js +168 -0
  204. package/dist/infrastructure/platforms/windows/services/rootfs-manager.service.js +336 -0
  205. package/dist/infrastructure/platforms/windows/services/windows-features.service.js +191 -0
  206. package/dist/infrastructure/platforms/windows/services/windows-info.service.js +138 -0
  207. package/dist/infrastructure/platforms/windows/services/wsl-config.service.js +171 -0
  208. package/dist/infrastructure/platforms/windows/services/wsl-info.service.js +226 -0
  209. package/dist/infrastructure/platforms/windows/services/wsl-instance-inspection.service.js +325 -0
  210. package/dist/infrastructure/platforms/windows/services/wsl-instance-lifecycle.service.js +442 -0
  211. package/dist/infrastructure/platforms/windows/services/wsl-instance-naming.service.js +93 -0
  212. package/dist/infrastructure/platforms/windows/services/wsl-updater.service.js +273 -0
  213. package/dist/infrastructure/platforms/windows/services/wslconfig-parser.service.js +222 -0
  214. package/dist/infrastructure/platforms/windows/wsl-base-image.adapter.js +41 -0
  215. package/dist/infrastructure/platforms/windows/wsl-instance-manager.adapter.js +150 -0
  216. package/dist/infrastructure/utils/error-formatter.util.js +29 -0
  217. package/dist/infrastructure/utils/file-operations.util.js +201 -0
  218. package/dist/infrastructure/utils/input-validator.util.js +152 -0
  219. package/dist/infrastructure/utils/retry.util.js +98 -0
  220. package/dist/presentation/controllers/config.controller.js +146 -0
  221. package/dist/presentation/controllers/credentials.controller.js +105 -0
  222. package/dist/presentation/controllers/index.js +25 -0
  223. package/dist/presentation/controllers/instance.controller.js +363 -0
  224. package/dist/presentation/controllers/logs.controller.js +103 -0
  225. package/dist/presentation/controllers/setup.controller.js +175 -0
  226. package/dist/presentation/interfaces/cli-options.interface.js +8 -0
  227. package/dist/presentation/prompts/acr-credentials.prompt.js +76 -0
  228. package/dist/presentation/prompts/index.js +21 -0
  229. package/dist/presentation/ui/cli-progress.service.js +193 -0
  230. package/dist/presentation/ui/constants/output-symbols.js +42 -0
  231. package/dist/presentation/ui/index.js +27 -0
  232. package/dist/presentation/ui/interaction.service.js +276 -0
  233. package/dist/presentation/ui/interfaces/cli-progress.interface.js +9 -0
  234. package/dist/presentation/ui/interfaces/output-formatter.interface.js +23 -0
  235. package/dist/presentation/ui/log-level.enum.js +66 -0
  236. package/dist/presentation/ui/output-builder.service.js +378 -0
  237. package/dist/presentation/ui/output-formatter.service.js +393 -0
  238. package/package.json +65 -0
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * 系統驗證相關類型定義
4
+ *
5
+ * 這些類型用於系統檢查和驗證流程,表示檢查結果的數據結構
6
+ * 注意:這些是數據傳輸對象(DTO),不是異常類型
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=validation.types.js.map
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AcrCredentials = void 0;
4
+ /**
5
+ * Azure Container Registry 憑證 Value Object
6
+ *
7
+ * 封裝 ACR 憑證的資料結構與驗證邏輯
8
+ */
9
+ class AcrCredentials {
10
+ constructor(name, account, password) {
11
+ this.name = name;
12
+ this.account = account;
13
+ this.password = password;
14
+ }
15
+ /**
16
+ * 建立 ACR 憑證
17
+ * @param name - ACR 名稱
18
+ * @param account - 帳號
19
+ * @param password - 密碼
20
+ * @returns ACR 憑證物件
21
+ * @throws 若任何欄位為空
22
+ */
23
+ static create(name, account, password) {
24
+ if (!this.isValid(name, account, password)) {
25
+ throw new Error('Invalid ACR credentials: name, account, and password are required');
26
+ }
27
+ return new AcrCredentials(name, account, password);
28
+ }
29
+ /**
30
+ * 從物件建立 ACR 憑證
31
+ * @param data - 包含 name, account, password 的物件
32
+ * @returns ACR 憑證物件
33
+ * @throws 若資料格式不正確
34
+ */
35
+ static fromObject(data) {
36
+ return this.create(data.name, data.account, data.password);
37
+ }
38
+ /**
39
+ * 驗證憑證資料是否完整
40
+ * @param name - ACR 名稱
41
+ * @param account - 帳號
42
+ * @param password - 密碼
43
+ * @returns 若所有欄位都非空則回傳 true
44
+ */
45
+ static isValid(name, account, password) {
46
+ return !!(name && account && password);
47
+ }
48
+ /**
49
+ * 取得完整的 ACR 登入伺服器位址
50
+ * @returns ACR 登入伺服器 URL
51
+ */
52
+ get loginServer() {
53
+ return `${this.name}.azurecr.io`;
54
+ }
55
+ /**
56
+ * 轉換為一般物件(用於序列化)
57
+ * @returns 包含 name, account, password 的物件
58
+ */
59
+ toObject() {
60
+ return {
61
+ name: this.name,
62
+ account: this.account,
63
+ password: this.password,
64
+ };
65
+ }
66
+ /**
67
+ * 比較兩個憑證是否相等
68
+ * @param other - 另一個憑證
69
+ * @returns 若所有欄位都相等則回傳 true
70
+ */
71
+ equals(other) {
72
+ return (this.name === other.name &&
73
+ this.account === other.account &&
74
+ this.password === other.password);
75
+ }
76
+ /**
77
+ * 回傳可安全記錄到日志的物件
78
+ * 密碼欄位將被遮罩
79
+ *
80
+ * @returns 遮罩後的物件,可安全寫入日志
81
+ */
82
+ toSafeLog() {
83
+ return {
84
+ name: this.name,
85
+ account: this.account,
86
+ password: '***MASKED***',
87
+ loginServer: this.loginServer,
88
+ };
89
+ }
90
+ }
91
+ exports.AcrCredentials = AcrCredentials;
92
+ //# sourceMappingURL=acr-credentials.value-object.js.map
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ChartVersion = void 0;
37
+ const semver = __importStar(require("semver"));
38
+ /**
39
+ * Chart 版本 Value Object
40
+ *
41
+ * 封裝 Helm Chart 版本的驗證規則與格式化邏輯
42
+ * 規則:
43
+ * - 必須是有效的 SemVer 格式 (例如:1.0.0, 2.1.3)
44
+ * - 或者是特殊關鍵字 'latest'
45
+ */
46
+ class ChartVersion {
47
+ constructor(value) {
48
+ this.value = value;
49
+ }
50
+ /**
51
+ * 建立 Chart 版本
52
+ * @param version - 版本字串
53
+ * @returns Chart 版本物件
54
+ * @throws 若版本格式不正確
55
+ */
56
+ static create(version) {
57
+ if (!this.isValid(version)) {
58
+ throw new Error(`Invalid chart version: "${version}". ` +
59
+ `Version must be a valid SemVer format (e.g., 1.0.0) or "latest".`);
60
+ }
61
+ return new ChartVersion(version);
62
+ }
63
+ /**
64
+ * 建立 'latest' 版本
65
+ * @returns Latest 版本物件
66
+ */
67
+ static createLatest() {
68
+ return new ChartVersion(this.LATEST);
69
+ }
70
+ /**
71
+ * 驗證版本格式
72
+ * @param version - 要驗證的版本
73
+ * @returns 若格式正確則回傳 true
74
+ */
75
+ static isValid(version) {
76
+ if (!version || typeof version !== 'string') {
77
+ return false;
78
+ }
79
+ // 允許 'latest'
80
+ if (version.toLowerCase() === this.LATEST) {
81
+ return true;
82
+ }
83
+ // 驗證 SemVer 格式
84
+ return semver.valid(version) !== null;
85
+ }
86
+ /**
87
+ * 檢查是否為 'latest' 版本
88
+ * @returns 若為 latest 則回傳 true
89
+ */
90
+ get isLatest() {
91
+ return this.value.toLowerCase() === ChartVersion.LATEST;
92
+ }
93
+ /**
94
+ * 取得版本字串
95
+ * @returns 版本字串
96
+ */
97
+ toString() {
98
+ return this.value;
99
+ }
100
+ /**
101
+ * 比較兩個版本是否相等
102
+ * @param other - 另一個版本
103
+ * @returns 若相等則回傳 true
104
+ */
105
+ equals(other) {
106
+ return this.value === other.value;
107
+ }
108
+ /**
109
+ * 比較版本大小
110
+ * @param other - 另一個版本
111
+ * @returns 若 this > other 則回傳 1,this < other 則回傳 -1,相等則回傳 0
112
+ * @throws 若任一版本為 'latest'
113
+ */
114
+ compare(other) {
115
+ if (this.isLatest || other.isLatest) {
116
+ throw new Error('Cannot compare versions when either is "latest"');
117
+ }
118
+ const result = semver.compare(this.value, other.value);
119
+ return result;
120
+ }
121
+ }
122
+ exports.ChartVersion = ChartVersion;
123
+ ChartVersion.LATEST = 'latest';
124
+ //# sourceMappingURL=chart-version.value-object.js.map
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigLogLevelValue = void 0;
4
+ /**
5
+ * 配置日誌級別 Value Object
6
+ *
7
+ * 封裝配置日誌級別的驗證邏輯
8
+ * 有效值:debug, info, error
9
+ */
10
+ class ConfigLogLevelValue {
11
+ constructor(value) {
12
+ this.value = value;
13
+ }
14
+ /**
15
+ * 建立日誌級別
16
+ * @param level - 日誌級別字串
17
+ * @returns ConfigLogLevelValue 實例
18
+ * @throws 若級別無效
19
+ */
20
+ static create(level) {
21
+ if (!this.isValid(level)) {
22
+ throw new Error(`Invalid log level: "${level}". Valid values: ${this.VALID_LEVELS.join(', ')}`);
23
+ }
24
+ return new ConfigLogLevelValue(level);
25
+ }
26
+ /**
27
+ * 嘗試建立日誌級別,若無效則返回 null
28
+ * @param level - 日誌級別字串
29
+ * @returns ConfigLogLevelValue 實例或 null
30
+ */
31
+ static tryCreate(level) {
32
+ if (!this.isValid(level)) {
33
+ return null;
34
+ }
35
+ return new ConfigLogLevelValue(level);
36
+ }
37
+ /**
38
+ * 驗證級別是否有效
39
+ * @param level - 日誌級別字串
40
+ * @returns 若有效則回傳 true
41
+ */
42
+ static isValid(level) {
43
+ return this.VALID_LEVELS.includes(level);
44
+ }
45
+ /**
46
+ * 取得日誌級別字串值
47
+ * @returns 日誌級別字串
48
+ */
49
+ toString() {
50
+ return this.value;
51
+ }
52
+ /**
53
+ * 轉換為配置類型
54
+ * @returns ConfigLogLevel 類型值
55
+ */
56
+ toConfigType() {
57
+ return this.value;
58
+ }
59
+ /**
60
+ * 比較兩個日誌級別是否相等
61
+ * @param other - 另一個日誌級別
62
+ * @returns 若相等則回傳 true
63
+ */
64
+ equals(other) {
65
+ return this.value === other.value;
66
+ }
67
+ /**
68
+ * 檢查此級別是否高於另一個級別
69
+ * @param other - 另一個日誌級別
70
+ * @returns 若此級別更高則回傳 true
71
+ */
72
+ isHigherThan(other) {
73
+ const order = {
74
+ 'debug': 0,
75
+ 'info': 1,
76
+ 'error': 2,
77
+ };
78
+ return order[this.value] > order[other.value];
79
+ }
80
+ }
81
+ exports.ConfigLogLevelValue = ConfigLogLevelValue;
82
+ /** 有效的日誌級別 */
83
+ ConfigLogLevelValue.VALID_LEVELS = ['debug', 'info', 'error'];
84
+ //# sourceMappingURL=config-log-level.value-object.js.map
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionInfo = void 0;
4
+ /**
5
+ * 連線資訊 Value Object
6
+ *
7
+ * 封裝實例連線資訊的生成邏輯
8
+ * 包含實例 IP、管理介面 URL、SQL Server 連線字串
9
+ */
10
+ class ConnectionInfo {
11
+ constructor(
12
+ /** 實例的 IP 位址 */
13
+ instanceIp,
14
+ /** 管理介面 URL */
15
+ adminUrl,
16
+ /** SQL Server 連線位址 */
17
+ sqlServer) {
18
+ this.instanceIp = instanceIp;
19
+ this.adminUrl = adminUrl;
20
+ this.sqlServer = sqlServer;
21
+ }
22
+ /**
23
+ * 從實例 IP 建立連線資訊
24
+ * @param instanceIp - 實例的 IP 位址,若為 null 則所有連線資訊皆為 null
25
+ * @returns 連線資訊物件
26
+ */
27
+ static create(instanceIp) {
28
+ if (!instanceIp) {
29
+ return new ConnectionInfo(null, null, null);
30
+ }
31
+ return new ConnectionInfo(instanceIp, `http://${instanceIp}:${this.ADMIN_PORT}`, `${instanceIp},${this.SQL_PORT}`);
32
+ }
33
+ /**
34
+ * 檢查連線資訊是否可用
35
+ * @returns 若 IP 存在則回傳 true
36
+ */
37
+ get isAvailable() {
38
+ return this.instanceIp !== null;
39
+ }
40
+ /**
41
+ * 轉換為 DTO 格式
42
+ * @returns 包含連線資訊的物件
43
+ */
44
+ toDto() {
45
+ return {
46
+ instanceIp: this.instanceIp,
47
+ adminUrl: this.adminUrl,
48
+ sqlServer: this.sqlServer,
49
+ };
50
+ }
51
+ /**
52
+ * 比較兩個連線資訊是否相等
53
+ * @param other - 另一個連線資訊
54
+ * @returns 若相等則回傳 true
55
+ */
56
+ equals(other) {
57
+ return this.instanceIp === other.instanceIp;
58
+ }
59
+ }
60
+ exports.ConnectionInfo = ConnectionInfo;
61
+ /** 管理介面埠號 */
62
+ ConnectionInfo.ADMIN_PORT = 16888;
63
+ /** SQL Server 埠號 */
64
+ ConnectionInfo.SQL_PORT = 30022;
65
+ //# sourceMappingURL=connection-info.value-object.js.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Domain Value Objects
4
+ *
5
+ * 不可變物件,封裝驗證規則與轉換邏輯
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ConfigLogLevelValue = exports.ConnectionInfo = exports.AcrCredentials = exports.RsaKeyPair = exports.JwtKey = exports.MssqlPassword = exports.ChartVersion = exports.InstanceName = void 0;
9
+ var instance_name_value_object_1 = require("./instance-name.value-object");
10
+ Object.defineProperty(exports, "InstanceName", { enumerable: true, get: function () { return instance_name_value_object_1.InstanceName; } });
11
+ var chart_version_value_object_1 = require("./chart-version.value-object");
12
+ Object.defineProperty(exports, "ChartVersion", { enumerable: true, get: function () { return chart_version_value_object_1.ChartVersion; } });
13
+ var mssql_password_value_object_1 = require("./mssql-password.value-object");
14
+ Object.defineProperty(exports, "MssqlPassword", { enumerable: true, get: function () { return mssql_password_value_object_1.MssqlPassword; } });
15
+ var jwt_key_value_object_1 = require("./jwt-key.value-object");
16
+ Object.defineProperty(exports, "JwtKey", { enumerable: true, get: function () { return jwt_key_value_object_1.JwtKey; } });
17
+ var rsa_key_pair_value_object_1 = require("./rsa-key-pair.value-object");
18
+ Object.defineProperty(exports, "RsaKeyPair", { enumerable: true, get: function () { return rsa_key_pair_value_object_1.RsaKeyPair; } });
19
+ var acr_credentials_value_object_1 = require("./acr-credentials.value-object");
20
+ Object.defineProperty(exports, "AcrCredentials", { enumerable: true, get: function () { return acr_credentials_value_object_1.AcrCredentials; } });
21
+ var connection_info_value_object_1 = require("./connection-info.value-object");
22
+ Object.defineProperty(exports, "ConnectionInfo", { enumerable: true, get: function () { return connection_info_value_object_1.ConnectionInfo; } });
23
+ var config_log_level_value_object_1 = require("./config-log-level.value-object");
24
+ Object.defineProperty(exports, "ConfigLogLevelValue", { enumerable: true, get: function () { return config_log_level_value_object_1.ConfigLogLevelValue; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstanceName = void 0;
4
+ /**
5
+ * 實例名稱 Value Object
6
+ *
7
+ * 封裝實例名稱的驗證規則與轉換邏輯
8
+ * 規則:
9
+ * - 長度:1-50 字元
10
+ * - 格式:開頭與結尾必須是英數字元,中間可包含連字號
11
+ * - 完整名稱格式:uofx-{name}
12
+ */
13
+ class InstanceName {
14
+ constructor(value) {
15
+ this.value = value;
16
+ }
17
+ /**
18
+ * 建立實例名稱
19
+ * @param name - 原始名稱(可包含或不包含 uofx- 前綴)
20
+ * @returns 實例名稱物件
21
+ * @throws 若名稱格式不正確
22
+ */
23
+ static create(name) {
24
+ // 如果輸入已有 uofx- 前綴,自動去除(允許用戶輸入完整名稱)
25
+ const prefix = 'uofx-';
26
+ const normalizedName = name.startsWith(prefix)
27
+ ? name.substring(prefix.length)
28
+ : name;
29
+ if (!this.isValid(normalizedName)) {
30
+ throw new Error(`Invalid instance name: "${name}". ` +
31
+ `Name must be ${this.MIN_LENGTH}-${this.MAX_LENGTH} characters, ` +
32
+ `start and end with alphanumeric characters, and may contain hyphens.`);
33
+ }
34
+ return new InstanceName(normalizedName);
35
+ }
36
+ /**
37
+ * 從完整名稱建立實例名稱
38
+ * @param fullName - 完整名稱 (uofx-{name})
39
+ * @returns 實例名稱物件
40
+ * @throws 若名稱格式不正確
41
+ */
42
+ static createFromFullName(fullName) {
43
+ const prefix = 'uofx-';
44
+ if (!fullName.startsWith(prefix)) {
45
+ throw new Error(`Invalid full instance name: "${fullName}". Expected format: uofx-{name}`);
46
+ }
47
+ const name = fullName.substring(prefix.length);
48
+ return this.create(name);
49
+ }
50
+ /**
51
+ * 驗證名稱格式
52
+ * @param name - 要驗證的名稱
53
+ * @returns 若格式正確則回傳 true
54
+ */
55
+ static isValid(name) {
56
+ if (!name || typeof name !== 'string') {
57
+ return false;
58
+ }
59
+ if (name.length < this.MIN_LENGTH || name.length > this.MAX_LENGTH) {
60
+ return false;
61
+ }
62
+ return this.PATTERN.test(name);
63
+ }
64
+ /**
65
+ * 取得完整的 WSL 實例名稱
66
+ * @returns 格式化後的完整名稱 (uofx-{name})
67
+ */
68
+ get fullName() {
69
+ return `uofx-${this.value}`;
70
+ }
71
+ /**
72
+ * 取得原始名稱
73
+ * @returns 原始名稱
74
+ */
75
+ toString() {
76
+ return this.value;
77
+ }
78
+ /**
79
+ * 比較兩個實例名稱是否相等
80
+ * @param other - 另一個實例名稱
81
+ * @returns 若相等則回傳 true
82
+ */
83
+ equals(other) {
84
+ return this.value === other.value;
85
+ }
86
+ }
87
+ exports.InstanceName = InstanceName;
88
+ InstanceName.PATTERN = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,48}[a-zA-Z0-9])?$/;
89
+ InstanceName.MIN_LENGTH = 1;
90
+ InstanceName.MAX_LENGTH = 50;
91
+ //# sourceMappingURL=instance-name.value-object.js.map
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.JwtKey = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ /**
9
+ * JWT 簽署金鑰 Value Object
10
+ *
11
+ * 封裝 JWT 簽署金鑰的生成與驗證邏輯
12
+ * 規則:
13
+ * - 長度至少 63 字元
14
+ * - 僅包含英數字元 (A-Za-z0-9)
15
+ */
16
+ class JwtKey {
17
+ constructor(value) {
18
+ this.value = value;
19
+ }
20
+ /**
21
+ * 生成 JWT 簽署金鑰
22
+ * @param length - 金鑰長度(預設:63)
23
+ * @returns JWT 金鑰物件
24
+ * @throws 若長度小於 63 或生成失敗
25
+ */
26
+ static generate(length = 63) {
27
+ if (length < this.MIN_LENGTH) {
28
+ throw new Error(`JWT key length must be at least ${this.MIN_LENGTH} characters`);
29
+ }
30
+ try {
31
+ let key = '';
32
+ for (let i = 0; i < length; i++) {
33
+ const randomIndex = crypto_1.default.randomInt(0, this.CHARSET.length);
34
+ key += this.CHARSET.charAt(randomIndex);
35
+ }
36
+ // 驗證生成的金鑰
37
+ if (!this.isValid(key)) {
38
+ throw new Error('Generated JWT key validation failed');
39
+ }
40
+ return new JwtKey(key);
41
+ }
42
+ catch (error) {
43
+ throw new Error(`Failed to generate JWT signing key: ${error instanceof Error ? error.message : String(error)}`);
44
+ }
45
+ }
46
+ /**
47
+ * 從現有金鑰建立金鑰物件
48
+ * @param key - 金鑰字串
49
+ * @returns JWT 金鑰物件
50
+ * @throws 若金鑰格式不正確
51
+ */
52
+ static create(key) {
53
+ if (!this.isValid(key)) {
54
+ throw new Error(`Invalid JWT signing key. Must be at least ${this.MIN_LENGTH} characters ` +
55
+ `and contain only alphanumeric characters.`);
56
+ }
57
+ return new JwtKey(key);
58
+ }
59
+ /**
60
+ * 驗證 JWT 簽署金鑰格式
61
+ * @param key - 要驗證的金鑰
62
+ * @returns 若格式正確則回傳 true
63
+ */
64
+ static isValid(key) {
65
+ if (!key || key.length < this.MIN_LENGTH) {
66
+ return false;
67
+ }
68
+ // 僅允許英數字元
69
+ return /^[A-Za-z0-9]+$/.test(key);
70
+ }
71
+ /**
72
+ * 取得金鑰明文
73
+ * @returns 金鑰字串
74
+ */
75
+ toString() {
76
+ return this.value;
77
+ }
78
+ /**
79
+ * 格式化 JWT Signing Key 給 Helm 使用 (Base64 編碼)
80
+ * @returns Base64 編碼後的金鑰
81
+ */
82
+ toBase64() {
83
+ return Buffer.from(this.value, 'utf8').toString('base64');
84
+ }
85
+ /**
86
+ * 比較兩個金鑰是否相等
87
+ * @param other - 另一個金鑰
88
+ * @returns 若相等則回傳 true
89
+ */
90
+ equals(other) {
91
+ return this.value === other.value;
92
+ }
93
+ }
94
+ exports.JwtKey = JwtKey;
95
+ JwtKey.MIN_LENGTH = 63;
96
+ JwtKey.CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
97
+ //# sourceMappingURL=jwt-key.value-object.js.map