@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.
- package/LICENSE +40 -0
- package/README.md +444 -0
- package/THIRD-PARTY-NOTICES.txt +894 -0
- package/dist/application/dtos/index.js +24 -0
- package/dist/application/dtos/request/delete-instance.request.dto.js +3 -0
- package/dist/application/dtos/request/get-config.request.dto.js +3 -0
- package/dist/application/dtos/request/get-credentials.request.dto.js +3 -0
- package/dist/application/dtos/request/index.js +27 -0
- package/dist/application/dtos/request/install-instance.request.dto.js +3 -0
- package/dist/application/dtos/request/list-charts.request.dto.js +3 -0
- package/dist/application/dtos/request/set-config.request.dto.js +16 -0
- package/dist/application/dtos/request/setup-environment.request.dto.js +16 -0
- package/dist/application/dtos/request/show-logs.request.dto.js +19 -0
- package/dist/application/dtos/request/start-instance.request.dto.js +3 -0
- package/dist/application/dtos/request/stop-instance.request.dto.js +3 -0
- package/dist/application/dtos/response/credentials.response.dto.js +3 -0
- package/dist/application/dtos/response/delete-instance.response.dto.js +3 -0
- package/dist/application/dtos/response/index.js +26 -0
- package/dist/application/dtos/response/install-instance.response.dto.js +3 -0
- package/dist/application/dtos/response/instance-list.response.dto.js +3 -0
- package/dist/application/dtos/response/instance-status.response.dto.js +3 -0
- package/dist/application/dtos/response/setup-result.response.dto.js +3 -0
- package/dist/application/dtos/response/show-logs.response.dto.js +3 -0
- package/dist/application/dtos/response/start-instance.response.dto.js +3 -0
- package/dist/application/dtos/response/stop-instance.response.dto.js +3 -0
- package/dist/application/index.js +25 -0
- package/dist/application/interfaces/index.js +24 -0
- package/dist/application/interfaces/use-case.interface.js +3 -0
- package/dist/application/use-cases/config/get-config.use-case.js +66 -0
- package/dist/application/use-cases/config/set-config.use-case.js +49 -0
- package/dist/application/use-cases/credentials/get-credentials.use-case.js +57 -0
- package/dist/application/use-cases/index.js +28 -0
- package/dist/application/use-cases/instance/delete-instance.use-case.js +81 -0
- package/dist/application/use-cases/instance/index.js +23 -0
- package/dist/application/use-cases/instance/install-instance.use-case.js +424 -0
- package/dist/application/use-cases/instance/list-charts.use-case.js +43 -0
- package/dist/application/use-cases/instance/list-instances.use-case.js +62 -0
- package/dist/application/use-cases/instance/start-instance.use-case.js +154 -0
- package/dist/application/use-cases/instance/stop-instance.use-case.js +55 -0
- package/dist/application/use-cases/logs/show-logs.use-case.js +66 -0
- package/dist/application/use-cases/setup/setup-environment.use-case.js +53 -0
- package/dist/cli.js +286 -0
- package/dist/constants/config-defaults.js +23 -0
- package/dist/constants/defaults.js +89 -0
- package/dist/constants/deployment.js +39 -0
- package/dist/constants/environments.js +93 -0
- package/dist/constants/index.js +53 -0
- package/dist/constants/oci-artifacts.js +25 -0
- package/dist/constants/paths.js +92 -0
- package/dist/constants/timeouts.js +60 -0
- package/dist/di/container.js +34 -0
- package/dist/di/index.js +22 -0
- package/dist/di/modules/application.module.js +54 -0
- package/dist/di/modules/infrastructure.module.js +206 -0
- package/dist/di/modules/interceptor.module.js +68 -0
- package/dist/di/modules/presentation.module.js +31 -0
- package/dist/di/tokens.js +149 -0
- package/dist/domain/decorators/sensitive.decorator.js +39 -0
- package/dist/domain/entities/credentials-resolver.entity.js +127 -0
- package/dist/domain/entities/credentials.entity.js +65 -0
- package/dist/domain/entities/delete-instance-validation.entity.js +100 -0
- package/dist/domain/entities/deployment-parameters.entity.js +120 -0
- package/dist/domain/entities/environment-validation.entity.js +125 -0
- package/dist/domain/entities/index.js +29 -0
- package/dist/domain/entities/instance-lifecycle-state.entity.js +100 -0
- package/dist/domain/entities/instance-list-aggregator.entity.js +104 -0
- package/dist/domain/entities/instance-metadata.entity.js +86 -0
- package/dist/domain/entities/instance-status.entity.js +79 -0
- package/dist/domain/entities/instance.entity.js +128 -0
- package/dist/domain/entities/log-filter.entity.js +141 -0
- package/dist/domain/index.js +29 -0
- package/dist/domain/interfaces/safe-loggable.interface.js +3 -0
- package/dist/domain/ports/app-config.port.js +3 -0
- package/dist/domain/ports/base-image.port.js +3 -0
- package/dist/domain/ports/chart-version.port.js +3 -0
- package/dist/domain/ports/correlation-id.port.js +3 -0
- package/dist/domain/ports/credentials.port.js +3 -0
- package/dist/domain/ports/deployment.port.js +3 -0
- package/dist/domain/ports/error-handler.port.js +3 -0
- package/dist/domain/ports/index.js +46 -0
- package/dist/domain/ports/instance-manager.port.js +3 -0
- package/dist/domain/ports/instance-metadata.port.js +8 -0
- package/dist/domain/ports/instance-storage.port.js +3 -0
- package/dist/domain/ports/k8s-deployer.port.js +3 -0
- package/dist/domain/ports/logger.port.js +14 -0
- package/dist/domain/ports/output.port.js +3 -0
- package/dist/domain/ports/runtime-environment.port.js +6 -0
- package/dist/domain/ports/user-interaction.port.js +9 -0
- package/dist/domain/ports/user-settings.port.js +3 -0
- package/dist/domain/types/index.js +22 -0
- package/dist/domain/types/logger.types.js +29 -0
- package/dist/domain/types/validation.types.js +9 -0
- package/dist/domain/value-objects/acr-credentials.value-object.js +92 -0
- package/dist/domain/value-objects/chart-version.value-object.js +124 -0
- package/dist/domain/value-objects/config-log-level.value-object.js +84 -0
- package/dist/domain/value-objects/connection-info.value-object.js +65 -0
- package/dist/domain/value-objects/index.js +25 -0
- package/dist/domain/value-objects/instance-name.value-object.js +91 -0
- package/dist/domain/value-objects/jwt-key.value-object.js +97 -0
- package/dist/domain/value-objects/mssql-password.value-object.js +140 -0
- package/dist/domain/value-objects/rsa-key-pair.value-object.js +181 -0
- package/dist/index.js +6 -0
- package/dist/infrastructure/config/app-config.interface.js +3 -0
- package/dist/infrastructure/config/app-config.service.js +280 -0
- package/dist/infrastructure/config/config-validator.js +31 -0
- package/dist/infrastructure/config/crypto.service.js +125 -0
- package/dist/infrastructure/deployment/deployment.adapter.js +118 -0
- package/dist/infrastructure/deployment/interfaces/acr-credential-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/app-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/helm-registry.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/infra-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/k8s-job-runner.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-database-init.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-helm-deployment.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-storage.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/mssql-user-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/oci-artifact.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/secret-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/service-manager.interface.js +3 -0
- package/dist/infrastructure/deployment/interfaces/version-compatibility.interface.js +3 -0
- package/dist/infrastructure/deployment/services/acr-credential-manager.service.js +144 -0
- package/dist/infrastructure/deployment/services/app-manager.service.js +193 -0
- package/dist/infrastructure/deployment/services/base-helm-deployment.service.js +163 -0
- package/dist/infrastructure/deployment/services/helm-registry.service.js +126 -0
- package/dist/infrastructure/deployment/services/infra-manager.service.js +130 -0
- package/dist/infrastructure/deployment/services/k8s-job-runner.service.js +194 -0
- package/dist/infrastructure/deployment/services/mssql-database-init.service.js +139 -0
- package/dist/infrastructure/deployment/services/mssql-helm-deployment.service.js +100 -0
- package/dist/infrastructure/deployment/services/mssql-storage.service.js +54 -0
- package/dist/infrastructure/deployment/services/mssql-user-manager.service.js +66 -0
- package/dist/infrastructure/deployment/services/oci-artifact.service.js +289 -0
- package/dist/infrastructure/deployment/services/secret-manager.service.js +179 -0
- package/dist/infrastructure/deployment/services/service-manager.service.js +82 -0
- package/dist/infrastructure/deployment/services/version-compatibility.service.js +291 -0
- package/dist/infrastructure/environment/interfaces/hardware-info.interface.js +3 -0
- package/dist/infrastructure/environment/interfaces/network-checker.interface.js +3 -0
- package/dist/infrastructure/environment/services/hardware-info.service.js +135 -0
- package/dist/infrastructure/environment/services/network-checker.service.js +142 -0
- package/dist/infrastructure/environment/windows-environment.adapter.js +162 -0
- package/dist/infrastructure/errors/app-error.js +73 -0
- package/dist/infrastructure/errors/error-handler.interface.js +3 -0
- package/dist/infrastructure/errors/error-handler.js +218 -0
- package/dist/infrastructure/errors/exit-codes.js +27 -0
- package/dist/infrastructure/errors/index.js +25 -0
- package/dist/infrastructure/execution/builders/base-command.builder.js +122 -0
- package/dist/infrastructure/execution/builders/host-command.builder.js +58 -0
- package/dist/infrastructure/execution/builders/windows-host-command.builder.js +50 -0
- package/dist/infrastructure/execution/builders/wsl-command.builder.js +29 -0
- package/dist/infrastructure/execution/command-builder.js +252 -0
- package/dist/infrastructure/execution/command-executor.service.js +230 -0
- package/dist/infrastructure/execution/environments/wsl-execution.environment.js +70 -0
- package/dist/infrastructure/execution/execution-environment.factory.js +53 -0
- package/dist/infrastructure/execution/index.js +25 -0
- package/dist/infrastructure/execution/interfaces/command-builder.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/command-executor.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/execution-environment-factory.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/execution-environment.interface.js +7 -0
- package/dist/infrastructure/execution/interfaces/host-command-builder.interface.js +3 -0
- package/dist/infrastructure/execution/interfaces/index.js +23 -0
- package/dist/infrastructure/execution/interfaces/script-executor.interface.js +3 -0
- package/dist/infrastructure/execution/script-executor.service.js +171 -0
- package/dist/infrastructure/http/http-client.service.js +176 -0
- package/dist/infrastructure/http/index.js +18 -0
- package/dist/infrastructure/http/interfaces/http-client.interface.js +3 -0
- package/dist/infrastructure/interceptors/index.js +8 -0
- package/dist/infrastructure/interceptors/interceptor.factory.js +44 -0
- package/dist/infrastructure/interceptors/interceptor.interface.js +3 -0
- package/dist/infrastructure/interceptors/logging.interceptor.js +171 -0
- package/dist/infrastructure/logger/correlation-id.adapter.js +68 -0
- package/dist/infrastructure/logger/index.js +23 -0
- package/dist/infrastructure/logger/interfaces/index.js +22 -0
- package/dist/infrastructure/logger/interfaces/log-reader.repository.interface.js +7 -0
- package/dist/infrastructure/logger/interfaces/log-writer.repository.interface.js +7 -0
- package/dist/infrastructure/logger/logger.adapter.js +274 -0
- package/dist/infrastructure/logger/services/file-log-reader.repository.js +148 -0
- package/dist/infrastructure/logger/services/file-log-writer.repository.js +307 -0
- package/dist/infrastructure/logger/services/index.js +22 -0
- package/dist/infrastructure/persistence/index.js +25 -0
- package/dist/infrastructure/persistence/instance-metadata.adapter.js +100 -0
- package/dist/infrastructure/persistence/instance-storage.adapter.js +64 -0
- package/dist/infrastructure/persistence/interfaces/config.repository.interface.js +3 -0
- package/dist/infrastructure/persistence/interfaces/index.js +22 -0
- package/dist/infrastructure/persistence/interfaces/instance.repository.interface.js +3 -0
- package/dist/infrastructure/persistence/services/file-system-config.repository.js +168 -0
- package/dist/infrastructure/persistence/services/file-system-instance.repository.js +170 -0
- package/dist/infrastructure/persistence/services/index.js +22 -0
- package/dist/infrastructure/persistence/user-settings.adapter.js +55 -0
- package/dist/infrastructure/platform-detector.js +71 -0
- package/dist/infrastructure/platforms/windows/interfaces/microk8s.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/rootfs-manager.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/windows-features.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/windows-info.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-config.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-info.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-inspection.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-lifecycle.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-instance-naming.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-manager.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-resources.interface.js +8 -0
- package/dist/infrastructure/platforms/windows/interfaces/wsl-updater.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/interfaces/wslconfig-parser.interface.js +3 -0
- package/dist/infrastructure/platforms/windows/parsers/wsl-version.parser.js +133 -0
- package/dist/infrastructure/platforms/windows/services/microk8s.service.js +168 -0
- package/dist/infrastructure/platforms/windows/services/rootfs-manager.service.js +336 -0
- package/dist/infrastructure/platforms/windows/services/windows-features.service.js +191 -0
- package/dist/infrastructure/platforms/windows/services/windows-info.service.js +138 -0
- package/dist/infrastructure/platforms/windows/services/wsl-config.service.js +171 -0
- package/dist/infrastructure/platforms/windows/services/wsl-info.service.js +226 -0
- package/dist/infrastructure/platforms/windows/services/wsl-instance-inspection.service.js +325 -0
- package/dist/infrastructure/platforms/windows/services/wsl-instance-lifecycle.service.js +442 -0
- package/dist/infrastructure/platforms/windows/services/wsl-instance-naming.service.js +93 -0
- package/dist/infrastructure/platforms/windows/services/wsl-updater.service.js +273 -0
- package/dist/infrastructure/platforms/windows/services/wslconfig-parser.service.js +222 -0
- package/dist/infrastructure/platforms/windows/wsl-base-image.adapter.js +41 -0
- package/dist/infrastructure/platforms/windows/wsl-instance-manager.adapter.js +150 -0
- package/dist/infrastructure/utils/error-formatter.util.js +29 -0
- package/dist/infrastructure/utils/file-operations.util.js +201 -0
- package/dist/infrastructure/utils/input-validator.util.js +152 -0
- package/dist/infrastructure/utils/retry.util.js +98 -0
- package/dist/presentation/controllers/config.controller.js +146 -0
- package/dist/presentation/controllers/credentials.controller.js +105 -0
- package/dist/presentation/controllers/index.js +25 -0
- package/dist/presentation/controllers/instance.controller.js +363 -0
- package/dist/presentation/controllers/logs.controller.js +103 -0
- package/dist/presentation/controllers/setup.controller.js +175 -0
- package/dist/presentation/interfaces/cli-options.interface.js +8 -0
- package/dist/presentation/prompts/acr-credentials.prompt.js +76 -0
- package/dist/presentation/prompts/index.js +21 -0
- package/dist/presentation/ui/cli-progress.service.js +193 -0
- package/dist/presentation/ui/constants/output-symbols.js +42 -0
- package/dist/presentation/ui/index.js +27 -0
- package/dist/presentation/ui/interaction.service.js +276 -0
- package/dist/presentation/ui/interfaces/cli-progress.interface.js +9 -0
- package/dist/presentation/ui/interfaces/output-formatter.interface.js +23 -0
- package/dist/presentation/ui/log-level.enum.js +66 -0
- package/dist/presentation/ui/output-builder.service.js +378 -0
- package/dist/presentation/ui/output-formatter.service.js +393 -0
- package/package.json +65 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger Infrastructure
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./logger.adapter"), exports);
|
|
21
|
+
__exportStar(require("./interfaces"), exports);
|
|
22
|
+
__exportStar(require("./services"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger Interfaces
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./log-writer.repository.interface"), exports);
|
|
21
|
+
__exportStar(require("./log-reader.repository.interface"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger Adapter
|
|
4
|
+
*
|
|
5
|
+
* 實作 ILoggerPort
|
|
6
|
+
* 整合日誌寫入和讀取能力
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
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;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
};
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
48
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
49
|
+
};
|
|
50
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
51
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.LoggerAdapter = void 0;
|
|
55
|
+
exports.generateCorrelationId = generateCorrelationId;
|
|
56
|
+
const tsyringe_1 = require("tsyringe");
|
|
57
|
+
const crypto = __importStar(require("crypto"));
|
|
58
|
+
const tokens_1 = require("../../di/tokens");
|
|
59
|
+
const logger_types_1 = require("../../domain/types/logger.types");
|
|
60
|
+
/**
|
|
61
|
+
* 產生 Correlation ID
|
|
62
|
+
* 用於追蹤同一次命令執行的所有日誌
|
|
63
|
+
*/
|
|
64
|
+
function generateCorrelationId() {
|
|
65
|
+
return crypto.randomBytes(8).toString('hex');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Logger Adapter 實作
|
|
69
|
+
*/
|
|
70
|
+
let LoggerAdapter = class LoggerAdapter {
|
|
71
|
+
constructor(logWriter, logReader) {
|
|
72
|
+
this.logWriter = logWriter;
|
|
73
|
+
this.logReader = logReader;
|
|
74
|
+
this.currentLevel = logger_types_1.LogLevel.ERROR;
|
|
75
|
+
}
|
|
76
|
+
// =========================================================================
|
|
77
|
+
// 日誌記錄方法
|
|
78
|
+
// =========================================================================
|
|
79
|
+
/**
|
|
80
|
+
* 記錄除錯訊息
|
|
81
|
+
*/
|
|
82
|
+
debug(message, context) {
|
|
83
|
+
this.log(logger_types_1.LogLevel.DEBUG, message, context);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 記錄一般資訊
|
|
87
|
+
*/
|
|
88
|
+
info(message, context) {
|
|
89
|
+
this.log(logger_types_1.LogLevel.INFO, message, context);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 記錄警告訊息
|
|
93
|
+
*/
|
|
94
|
+
warn(message, context) {
|
|
95
|
+
this.log(logger_types_1.LogLevel.WARN, message, context);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 記錄錯誤
|
|
99
|
+
*/
|
|
100
|
+
error(error, context) {
|
|
101
|
+
const errorDetails = {
|
|
102
|
+
name: error.name,
|
|
103
|
+
message: error.message,
|
|
104
|
+
stack: error.stack,
|
|
105
|
+
};
|
|
106
|
+
if ('code' in error) {
|
|
107
|
+
errorDetails.code = error.code;
|
|
108
|
+
}
|
|
109
|
+
this.log(logger_types_1.LogLevel.ERROR, error.message, context, errorDetails);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 記錄致命錯誤
|
|
113
|
+
*/
|
|
114
|
+
fatal(error, context) {
|
|
115
|
+
const errorDetails = {
|
|
116
|
+
name: error.name,
|
|
117
|
+
message: error.message,
|
|
118
|
+
stack: error.stack,
|
|
119
|
+
};
|
|
120
|
+
if ('code' in error) {
|
|
121
|
+
errorDetails.code = error.code;
|
|
122
|
+
}
|
|
123
|
+
this.log(logger_types_1.LogLevel.FATAL, error.message, context, errorDetails);
|
|
124
|
+
}
|
|
125
|
+
// =========================================================================
|
|
126
|
+
// 日誌讀取方法
|
|
127
|
+
// =========================================================================
|
|
128
|
+
/**
|
|
129
|
+
* 讀取最近的日誌項目
|
|
130
|
+
*/
|
|
131
|
+
async readLogs(count = 50) {
|
|
132
|
+
return await this.logReader.readRecentEntries(count);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 清除日誌檔案
|
|
136
|
+
*/
|
|
137
|
+
async clearLogs() {
|
|
138
|
+
await this.logWriter.clearLogFile();
|
|
139
|
+
}
|
|
140
|
+
// =========================================================================
|
|
141
|
+
// 日誌級別控制
|
|
142
|
+
// =========================================================================
|
|
143
|
+
/**
|
|
144
|
+
* 設定日誌級別
|
|
145
|
+
*/
|
|
146
|
+
setLogLevel(level) {
|
|
147
|
+
this.currentLevel = level;
|
|
148
|
+
this.logWriter.setLogLevel(level);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 取得目前的日誌級別
|
|
152
|
+
*/
|
|
153
|
+
getLogLevel() {
|
|
154
|
+
return this.currentLevel;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 取得日誌檔案路徑
|
|
158
|
+
*/
|
|
159
|
+
getLogFilePath() {
|
|
160
|
+
return this.logWriter.getLogFilePath();
|
|
161
|
+
}
|
|
162
|
+
// =========================================================================
|
|
163
|
+
// 執行上下文管理
|
|
164
|
+
// =========================================================================
|
|
165
|
+
/**
|
|
166
|
+
* 設定執行上下文
|
|
167
|
+
*/
|
|
168
|
+
setExecutionContext(context) {
|
|
169
|
+
this.executionContext = context;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 取得目前的執行上下文
|
|
173
|
+
*/
|
|
174
|
+
getExecutionContext() {
|
|
175
|
+
return this.executionContext;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 清除執行上下文
|
|
179
|
+
*/
|
|
180
|
+
clearExecutionContext() {
|
|
181
|
+
this.executionContext = undefined;
|
|
182
|
+
}
|
|
183
|
+
// =========================================================================
|
|
184
|
+
// 私有方法
|
|
185
|
+
// =========================================================================
|
|
186
|
+
/**
|
|
187
|
+
* 核心日誌方法
|
|
188
|
+
*/
|
|
189
|
+
log(level, message, context, error) {
|
|
190
|
+
// 檢查日誌級別
|
|
191
|
+
if (level < this.currentLevel) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
// 準備並遮罩敏感資料
|
|
195
|
+
const safeContext = this.prepareContext(context);
|
|
196
|
+
// 合併執行上下文到日誌 context
|
|
197
|
+
const mergedContext = {
|
|
198
|
+
...safeContext,
|
|
199
|
+
};
|
|
200
|
+
// 注入執行上下文(如果存在)
|
|
201
|
+
if (this.executionContext) {
|
|
202
|
+
mergedContext.command = mergedContext.command ?? this.executionContext.command;
|
|
203
|
+
mergedContext.commandGroup = mergedContext.commandGroup ?? this.executionContext.commandGroup;
|
|
204
|
+
mergedContext.correlationId = mergedContext.correlationId ?? this.executionContext.correlationId;
|
|
205
|
+
}
|
|
206
|
+
// 建立日誌項目
|
|
207
|
+
let entry = {
|
|
208
|
+
timestamp: new Date().toISOString(),
|
|
209
|
+
level,
|
|
210
|
+
levelName: logger_types_1.LogLevelNames[level],
|
|
211
|
+
message,
|
|
212
|
+
correlationId: mergedContext.correlationId,
|
|
213
|
+
context: mergedContext,
|
|
214
|
+
error,
|
|
215
|
+
metadata: {
|
|
216
|
+
pid: process.pid,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
// AOP: beforeLog hook
|
|
220
|
+
if (this.beforeLog) {
|
|
221
|
+
entry = this.beforeLog(entry);
|
|
222
|
+
}
|
|
223
|
+
// AOP: shouldLog check
|
|
224
|
+
if (this.shouldLog && !this.shouldLog(entry)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
// 寫入日誌
|
|
228
|
+
this.logWriter.write(entry);
|
|
229
|
+
// AOP: afterLog hook
|
|
230
|
+
if (this.afterLog) {
|
|
231
|
+
this.afterLog(entry);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 檢查物件是否實作 ISafeLoggable 介面
|
|
236
|
+
*/
|
|
237
|
+
isSafeLoggable(obj) {
|
|
238
|
+
return obj !== null && typeof obj === 'object' && 'toSafeLog' in obj && typeof obj.toSafeLog === 'function';
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* 準備日誌上下文,自動檢測並遮罩敏感資料
|
|
242
|
+
* 遞迴檢查物件,若實作 ISafeLoggable 則自動呼叫 toSafeLog()
|
|
243
|
+
*/
|
|
244
|
+
prepareContext(obj) {
|
|
245
|
+
if (obj === null || obj === undefined) {
|
|
246
|
+
return obj;
|
|
247
|
+
}
|
|
248
|
+
if (typeof obj !== 'object') {
|
|
249
|
+
return obj;
|
|
250
|
+
}
|
|
251
|
+
// 檢查是否實作 ISafeLoggable
|
|
252
|
+
if (this.isSafeLoggable(obj)) {
|
|
253
|
+
return obj.toSafeLog();
|
|
254
|
+
}
|
|
255
|
+
// 處理陣列
|
|
256
|
+
if (Array.isArray(obj)) {
|
|
257
|
+
return obj.map(item => this.prepareContext(item));
|
|
258
|
+
}
|
|
259
|
+
// 遞迴處理物件屬性
|
|
260
|
+
const result = {};
|
|
261
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
262
|
+
result[key] = this.prepareContext(value);
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
exports.LoggerAdapter = LoggerAdapter;
|
|
268
|
+
exports.LoggerAdapter = LoggerAdapter = __decorate([
|
|
269
|
+
(0, tsyringe_1.injectable)(),
|
|
270
|
+
__param(0, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.FileLogWriter)),
|
|
271
|
+
__param(1, (0, tsyringe_1.inject)(tokens_1.TOKENS.Internal.FileLogReader)),
|
|
272
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
273
|
+
], LoggerAdapter);
|
|
274
|
+
//# sourceMappingURL=logger.adapter.js.map
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* File Log Reader Repository
|
|
4
|
+
* 負責從檔案系統讀取日誌
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
23
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
+
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;
|
|
26
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
+
};
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
46
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.FileLogReaderRepository = void 0;
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const os = __importStar(require("os"));
|
|
53
|
+
const readline = __importStar(require("readline"));
|
|
54
|
+
const tsyringe_1 = require("tsyringe");
|
|
55
|
+
const index_1 = require("../../../constants/index");
|
|
56
|
+
/**
|
|
57
|
+
* 預設配置
|
|
58
|
+
*/
|
|
59
|
+
const DEFAULT_CONFIG = {
|
|
60
|
+
baseDir: path.join(os.homedir(), index_1.WINDOWS_PATHS.USER_CONFIG_DIR, 'logs'),
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* File Log Reader Repository 實作
|
|
64
|
+
*/
|
|
65
|
+
let FileLogReaderRepository = class FileLogReaderRepository {
|
|
66
|
+
constructor() {
|
|
67
|
+
// 使用默認配置
|
|
68
|
+
// 如果未來需要自定義配置,應該從 IAppConfig 注入
|
|
69
|
+
this.config = DEFAULT_CONFIG;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 取得日誌基礎目錄
|
|
73
|
+
*/
|
|
74
|
+
getBaseDir() {
|
|
75
|
+
return this.config.baseDir;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 讀取最近的日誌項目
|
|
79
|
+
*/
|
|
80
|
+
async readRecentEntries(count = 50) {
|
|
81
|
+
const entries = [];
|
|
82
|
+
try {
|
|
83
|
+
if (!fs.existsSync(this.config.baseDir)) {
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
const files = await fs.promises.readdir(this.config.baseDir);
|
|
87
|
+
const logFiles = files
|
|
88
|
+
.filter((f) => f.startsWith('uofx-') && f.endsWith('.jsonl'))
|
|
89
|
+
.sort()
|
|
90
|
+
.reverse();
|
|
91
|
+
for (const logFile of logFiles) {
|
|
92
|
+
if (entries.length >= count)
|
|
93
|
+
break;
|
|
94
|
+
const filePath = path.join(this.config.baseDir, logFile);
|
|
95
|
+
const remaining = count - entries.length;
|
|
96
|
+
const fileEntries = await this.readEntriesFromFile(filePath, remaining);
|
|
97
|
+
entries.push(...fileEntries);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// 靜默處理:讀取日誌失敗時返回空陣列
|
|
102
|
+
}
|
|
103
|
+
return entries.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 從單個檔案讀取日誌項目
|
|
107
|
+
*/
|
|
108
|
+
async readEntriesFromFile(filePath, count) {
|
|
109
|
+
const entries = [];
|
|
110
|
+
if (!fs.existsSync(filePath)) {
|
|
111
|
+
return entries;
|
|
112
|
+
}
|
|
113
|
+
return new Promise((resolve) => {
|
|
114
|
+
const lines = [];
|
|
115
|
+
const rl = readline.createInterface({
|
|
116
|
+
input: fs.createReadStream(filePath, { encoding: 'utf8' }),
|
|
117
|
+
crlfDelay: Infinity,
|
|
118
|
+
});
|
|
119
|
+
rl.on('line', (line) => {
|
|
120
|
+
if (line.trim()) {
|
|
121
|
+
lines.push(line);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
rl.on('close', () => {
|
|
125
|
+
const recentLines = lines.slice(-count);
|
|
126
|
+
for (const line of recentLines) {
|
|
127
|
+
try {
|
|
128
|
+
const entry = JSON.parse(line);
|
|
129
|
+
entries.push(entry);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// 非 JSON 格式,忽略
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
resolve(entries);
|
|
136
|
+
});
|
|
137
|
+
rl.on('error', () => {
|
|
138
|
+
resolve(entries);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.FileLogReaderRepository = FileLogReaderRepository;
|
|
144
|
+
exports.FileLogReaderRepository = FileLogReaderRepository = __decorate([
|
|
145
|
+
(0, tsyringe_1.injectable)(),
|
|
146
|
+
__metadata("design:paramtypes", [])
|
|
147
|
+
], FileLogReaderRepository);
|
|
148
|
+
//# sourceMappingURL=file-log-reader.repository.js.map
|