@edgible-team/cli 1.2.13 → 1.2.17
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/README.md +5 -3
- package/dist/client/api-client.d.ts +13 -1
- package/dist/client/api-client.d.ts.map +1 -1
- package/dist/client/api-client.js +19 -0
- package/dist/commands/agent/install.d.ts +2 -1
- package/dist/commands/agent/install.d.ts.map +1 -1
- package/dist/commands/agent/install.js +24 -7
- package/dist/commands/agent/start.d.ts +5 -1
- package/dist/commands/agent/start.d.ts.map +1 -1
- package/dist/commands/agent/start.js +19 -280
- package/dist/commands/agent/uninstall.d.ts.map +1 -1
- package/dist/commands/agent/uninstall.js +14 -7
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +3 -2
- package/dist/commands/ai/setup.d.ts +1 -1
- package/dist/commands/ai/setup.d.ts.map +1 -1
- package/dist/commands/ai.js +1 -1
- package/dist/commands/application/create-docker-compose.d.ts +3 -1
- package/dist/commands/application/create-docker-compose.d.ts.map +1 -1
- package/dist/commands/application/create-docker-compose.js +25 -69
- package/dist/commands/application/create-existing.d.ts +2 -2
- package/dist/commands/application/create-existing.d.ts.map +1 -1
- package/dist/commands/application/create-existing.js +27 -132
- package/dist/commands/application/create-managed-process.d.ts +3 -1
- package/dist/commands/application/create-managed-process.d.ts.map +1 -1
- package/dist/commands/application/create-managed-process.js +31 -75
- package/dist/commands/application/delete.d.ts +2 -1
- package/dist/commands/application/delete.d.ts.map +1 -1
- package/dist/commands/application/delete.js +19 -5
- package/dist/commands/application/update.d.ts +3 -0
- package/dist/commands/application/update.d.ts.map +1 -1
- package/dist/commands/application/update.js +45 -1
- package/dist/commands/application.d.ts.map +1 -1
- package/dist/commands/application.js +33 -19
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +44 -0
- package/dist/commands/debug.js +1 -1
- package/dist/commands/device/application-health.d.ts +7 -0
- package/dist/commands/device/application-health.d.ts.map +1 -0
- package/dist/commands/device/application-health.js +103 -0
- package/dist/commands/device/delete.d.ts +7 -0
- package/dist/commands/device/delete.d.ts.map +1 -0
- package/dist/commands/device/delete.js +69 -0
- package/dist/commands/device/health.d.ts +7 -0
- package/dist/commands/device/health.d.ts.map +1 -0
- package/dist/commands/device/health.js +78 -0
- package/dist/commands/device/list.d.ts +5 -0
- package/dist/commands/device/list.d.ts.map +1 -0
- package/dist/commands/device/list.js +46 -0
- package/dist/commands/device/telemetry.d.ts +8 -0
- package/dist/commands/device/telemetry.d.ts.map +1 -0
- package/dist/commands/device/telemetry.js +59 -0
- package/dist/commands/device.d.ts +6 -0
- package/dist/commands/device.d.ts.map +1 -0
- package/dist/commands/device.js +86 -0
- package/dist/commands/stack/deploy.d.ts +8 -0
- package/dist/commands/stack/deploy.d.ts.map +1 -0
- package/dist/commands/stack/deploy.js +61 -0
- package/dist/commands/stack/diff.d.ts +7 -0
- package/dist/commands/stack/diff.d.ts.map +1 -0
- package/dist/commands/stack/diff.js +66 -0
- package/dist/commands/stack/status.d.ts +9 -0
- package/dist/commands/stack/status.d.ts.map +1 -0
- package/dist/commands/stack/status.js +55 -0
- package/dist/commands/stack/teardown.d.ts +8 -0
- package/dist/commands/stack/teardown.d.ts.map +1 -0
- package/dist/commands/stack/teardown.js +107 -0
- package/dist/commands/stack/validate.d.ts +7 -0
- package/dist/commands/stack/validate.d.ts.map +1 -0
- package/dist/commands/stack/validate.js +44 -0
- package/dist/commands/stack.d.ts +10 -0
- package/dist/commands/stack.d.ts.map +1 -0
- package/dist/commands/stack.js +117 -0
- package/dist/commands/utils/auth-prompt.d.ts +25 -0
- package/dist/commands/utils/auth-prompt.d.ts.map +1 -0
- package/dist/commands/utils/auth-prompt.js +115 -0
- package/dist/commands/utils/device-prompt.d.ts +18 -0
- package/dist/commands/utils/device-prompt.d.ts.map +1 -0
- package/dist/commands/utils/device-prompt.js +58 -0
- package/dist/commands/utils/output-formatter.d.ts +13 -0
- package/dist/commands/utils/output-formatter.d.ts.map +1 -1
- package/dist/commands/utils/output-formatter.js +21 -0
- package/dist/index.js +4 -0
- package/dist/services/LocalAgentManager.d.ts +2 -1
- package/dist/services/LocalAgentManager.d.ts.map +1 -1
- package/dist/services/LocalAgentManager.js +6 -4
- package/dist/services/application/ApplicationService.d.ts +19 -0
- package/dist/services/application/ApplicationService.d.ts.map +1 -1
- package/dist/services/application/ApplicationService.js +14 -1
- package/dist/services/device/DeviceService.d.ts +62 -0
- package/dist/services/device/DeviceService.d.ts.map +1 -0
- package/dist/services/device/DeviceService.js +235 -0
- package/dist/services/edgible.d.ts +3 -1
- package/dist/services/edgible.d.ts.map +1 -1
- package/dist/services/edgible.js +5 -4
- package/dist/services/instances.d.ts +27 -1
- package/dist/services/instances.d.ts.map +1 -1
- package/dist/services/instances.js +53 -4
- package/dist/services/stack/DependencyGraphManager.d.ts +69 -0
- package/dist/services/stack/DependencyGraphManager.d.ts.map +1 -0
- package/dist/services/stack/DependencyGraphManager.js +204 -0
- package/dist/services/stack/DeviceResolver.d.ts +63 -0
- package/dist/services/stack/DeviceResolver.d.ts.map +1 -0
- package/dist/services/stack/DeviceResolver.js +147 -0
- package/dist/services/stack/GatewayResolver.d.ts +84 -0
- package/dist/services/stack/GatewayResolver.d.ts.map +1 -0
- package/dist/services/stack/GatewayResolver.js +179 -0
- package/dist/services/stack/StackParser.d.ts +38 -0
- package/dist/services/stack/StackParser.d.ts.map +1 -0
- package/dist/services/stack/StackParser.js +234 -0
- package/dist/services/stack/StackService.d.ts +76 -0
- package/dist/services/stack/StackService.d.ts.map +1 -0
- package/dist/services/stack/StackService.js +476 -0
- package/dist/types/AgentConfig.d.ts +26 -0
- package/dist/types/AgentConfig.d.ts.map +1 -1
- package/dist/types/ApiRequests.d.ts +5 -1
- package/dist/types/ApiRequests.d.ts.map +1 -1
- package/dist/types/ApiResponses.d.ts +5 -0
- package/dist/types/ApiResponses.d.ts.map +1 -1
- package/dist/types/JobTypes.d.ts +103 -0
- package/dist/types/JobTypes.d.ts.map +1 -0
- package/dist/types/JobTypes.js +80 -0
- package/dist/types/WebSocketMessages.d.ts +89 -0
- package/dist/types/WebSocketMessages.d.ts.map +1 -0
- package/dist/types/WebSocketMessages.js +5 -0
- package/dist/types/backendJobs.d.ts +102 -0
- package/dist/types/backendJobs.d.ts.map +1 -0
- package/dist/types/backendJobs.js +5 -0
- package/dist/types/models/ApplicationData.d.ts +1 -1
- package/dist/types/models/ApplicationData.d.ts.map +1 -1
- package/dist/types/models/DeviceData.d.ts +4 -0
- package/dist/types/models/DeviceData.d.ts.map +1 -1
- package/dist/types/stack.d.ts +191 -0
- package/dist/types/stack.d.ts.map +1 -0
- package/dist/types/stack.js +5 -0
- package/dist/types/validation/schemas.d.ts +20 -20
- package/dist/types/validation/schemas.js +1 -1
- package/dist/utils/stack-errors.d.ts +103 -0
- package/dist/utils/stack-errors.d.ts.map +1 -0
- package/dist/utils/stack-errors.js +158 -0
- package/dist/utils/stack-file.d.ts +11 -0
- package/dist/utils/stack-file.d.ts.map +1 -0
- package/dist/utils/stack-file.js +66 -0
- package/dist/validation/stack-schemas.d.ts +535 -0
- package/dist/validation/stack-schemas.d.ts.map +1 -0
- package/dist/validation/stack-schemas.js +178 -0
- package/package.json +4 -2
- package/dist/commands/agent/agent-handlers.d.ts +0 -45
- package/dist/commands/agent/agent-handlers.d.ts.map +0 -1
- package/dist/commands/agent/agent-handlers.js +0 -1159
- package/dist/commands/application/api-keys.d.ts +0 -3
- package/dist/commands/application/api-keys.d.ts.map +0 -1
- package/dist/commands/application/api-keys.js +0 -227
- package/dist/commands/application/create-compose.d.ts +0 -3
- package/dist/commands/application/create-compose.d.ts.map +0 -1
- package/dist/commands/application/create-compose.js +0 -381
- package/dist/commands/application/create-interactive.d.ts +0 -3
- package/dist/commands/application/create-interactive.d.ts.map +0 -1
- package/dist/commands/application/create-interactive.js +0 -326
- package/dist/commands/application/create-workload.d.ts +0 -5
- package/dist/commands/application/create-workload.d.ts.map +0 -1
- package/dist/commands/application/create-workload.js +0 -48
- package/dist/commands/application/short-codes.d.ts +0 -3
- package/dist/commands/application/short-codes.d.ts.map +0 -1
- package/dist/commands/application/short-codes.js +0 -226
- package/dist/commands/application/toggle.d.ts +0 -2
- package/dist/commands/application/toggle.d.ts.map +0 -1
- package/dist/commands/application/toggle.js +0 -78
- package/dist/commands/examples/migrated-command-example.d.ts +0 -31
- package/dist/commands/examples/migrated-command-example.d.ts.map +0 -1
- package/dist/commands/examples/migrated-command-example.js +0 -180
- package/dist/commands/managedGateway/create.d.ts +0 -6
- package/dist/commands/managedGateway/create.d.ts.map +0 -1
- package/dist/commands/managedGateway/create.js +0 -50
- package/dist/commands/managedGateway/delete.d.ts +0 -5
- package/dist/commands/managedGateway/delete.d.ts.map +0 -1
- package/dist/commands/managedGateway/delete.js +0 -57
- package/dist/commands/managedGateway/get.d.ts +0 -4
- package/dist/commands/managedGateway/get.d.ts.map +0 -1
- package/dist/commands/managedGateway/get.js +0 -71
- package/dist/commands/managedGateway/haproxy-stats.d.ts +0 -6
- package/dist/commands/managedGateway/haproxy-stats.d.ts.map +0 -1
- package/dist/commands/managedGateway/haproxy-stats.js +0 -131
- package/dist/commands/managedGateway/list.d.ts +0 -4
- package/dist/commands/managedGateway/list.d.ts.map +0 -1
- package/dist/commands/managedGateway/list.js +0 -50
- package/dist/commands/managedGateway/logs.d.ts +0 -10
- package/dist/commands/managedGateway/logs.d.ts.map +0 -1
- package/dist/commands/managedGateway/logs.js +0 -100
- package/dist/commands/managedGateway/reboot.d.ts +0 -5
- package/dist/commands/managedGateway/reboot.d.ts.map +0 -1
- package/dist/commands/managedGateway/reboot.js +0 -95
- package/dist/commands/managedGateway/resync.d.ts +0 -10
- package/dist/commands/managedGateway/resync.d.ts.map +0 -1
- package/dist/commands/managedGateway/resync.js +0 -69
- package/dist/commands/managedGateway/ssh.d.ts +0 -4
- package/dist/commands/managedGateway/ssh.d.ts.map +0 -1
- package/dist/commands/managedGateway/ssh.js +0 -130
- package/dist/commands/managedGateway/wipe-logs.d.ts +0 -4
- package/dist/commands/managedGateway/wipe-logs.d.ts.map +0 -1
- package/dist/commands/managedGateway/wipe-logs.js +0 -67
- package/dist/commands/managedGateway/wireguard.d.ts +0 -4
- package/dist/commands/managedGateway/wireguard.d.ts.map +0 -1
- package/dist/commands/managedGateway/wireguard.js +0 -68
- package/dist/di/bindings.d.ts +0 -15
- package/dist/di/bindings.d.ts.map +0 -1
- package/dist/di/bindings.js +0 -99
- package/dist/di/container.d.ts +0 -44
- package/dist/di/container.d.ts.map +0 -1
- package/dist/di/container.js +0 -88
- package/dist/di/types.d.ts +0 -23
- package/dist/di/types.d.ts.map +0 -1
- package/dist/di/types.js +0 -32
- package/dist/repositories/config-repository.d.ts +0 -46
- package/dist/repositories/config-repository.d.ts.map +0 -1
- package/dist/repositories/config-repository.js +0 -62
- package/dist/repositories/gateway-repository.d.ts +0 -37
- package/dist/repositories/gateway-repository.d.ts.map +0 -1
- package/dist/repositories/gateway-repository.js +0 -35
|
@@ -7,15 +7,18 @@
|
|
|
7
7
|
* Services are instantiated once and shared across the application.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.agentDeploymentService = exports.diagnosticsService = exports.managedGatewayService = exports.localAgentManager = exports.
|
|
10
|
+
exports.stackService = exports.agentDeploymentService = exports.diagnosticsService = exports.managedGatewayService = exports.edgibleService = exports.localAgentManager = exports.deviceService = exports.gatewayService = exports.applicationService = exports.authService = exports.tokenManager = exports.configManager = exports.logger = void 0;
|
|
11
|
+
exports.getStackService = getStackService;
|
|
11
12
|
exports.createConnectivityTester = createConnectivityTester;
|
|
12
13
|
exports.createWorkloadDetector = createWorkloadDetector;
|
|
14
|
+
exports.getServiceInstances = getServiceInstances;
|
|
13
15
|
const console_logger_1 = require("../utils/console-logger");
|
|
14
16
|
const config_1 = require("../state/config");
|
|
15
17
|
const TokenManager_1 = require("./token/TokenManager");
|
|
16
18
|
const AuthService_1 = require("./auth/AuthService");
|
|
17
19
|
const ApplicationService_1 = require("./application/ApplicationService");
|
|
18
20
|
const GatewayService_1 = require("./gateway/GatewayService");
|
|
21
|
+
const DeviceService_1 = require("./device/DeviceService");
|
|
19
22
|
const edgible_1 = require("./edgible");
|
|
20
23
|
const LocalAgentManager_1 = require("./LocalAgentManager");
|
|
21
24
|
const ConnectivityTester_1 = require("./ConnectivityTester");
|
|
@@ -23,6 +26,8 @@ const WorkloadDetector_1 = require("../detection/WorkloadDetector");
|
|
|
23
26
|
const ManagedGatewayService_1 = require("./managedGateway/ManagedGatewayService");
|
|
24
27
|
const DiagnosticsService_1 = require("./diagnostics/DiagnosticsService");
|
|
25
28
|
const AgentDeploymentService_1 = require("./agentDeployment/AgentDeploymentService");
|
|
29
|
+
const StackService_1 = require("./stack/StackService");
|
|
30
|
+
const client_1 = require("../client");
|
|
26
31
|
const app_config_1 = require("../config/app-config");
|
|
27
32
|
const logger_1 = require("../utils/logger");
|
|
28
33
|
// Get application configuration
|
|
@@ -43,16 +48,39 @@ exports.authService = new AuthService_1.AuthServiceImpl(appConfig.apiBaseUrl, ex
|
|
|
43
48
|
exports.applicationService = new ApplicationService_1.ApplicationServiceImpl(appConfig.apiBaseUrl, exports.configManager, exports.authService, exports.tokenManager, exports.logger);
|
|
44
49
|
// Create gateway service
|
|
45
50
|
exports.gatewayService = new GatewayService_1.GatewayServiceImpl(appConfig.apiBaseUrl, exports.configManager, exports.authService, exports.tokenManager, exports.logger);
|
|
51
|
+
// Create device service
|
|
52
|
+
exports.deviceService = new DeviceService_1.DeviceServiceImpl(appConfig.apiBaseUrl, exports.configManager, exports.authService, exports.tokenManager, exports.logger);
|
|
53
|
+
// Create local agent manager (pass shared configManager)
|
|
54
|
+
exports.localAgentManager = new LocalAgentManager_1.LocalAgentManager(exports.configManager);
|
|
46
55
|
// Create Edgible service (legacy - being refactored in phases)
|
|
47
|
-
exports.edgibleService = new edgible_1.EdgibleService(appConfig.apiBaseUrl, exports.configManager, exports.tokenManager, exports.logger);
|
|
48
|
-
// Create local agent manager
|
|
49
|
-
exports.localAgentManager = new LocalAgentManager_1.LocalAgentManager();
|
|
56
|
+
exports.edgibleService = new edgible_1.EdgibleService(appConfig.apiBaseUrl, exports.configManager, exports.tokenManager, exports.logger, exports.localAgentManager);
|
|
50
57
|
// Create managed gateway service
|
|
51
58
|
exports.managedGatewayService = new ManagedGatewayService_1.ManagedGatewayServiceImpl(exports.edgibleService);
|
|
52
59
|
// Create diagnostics service
|
|
53
60
|
exports.diagnosticsService = new DiagnosticsService_1.DiagnosticsServiceImpl(exports.edgibleService);
|
|
54
61
|
// Create agent deployment service
|
|
55
62
|
exports.agentDeploymentService = new AgentDeploymentService_1.AgentDeploymentServiceImpl(exports.edgibleService);
|
|
63
|
+
// Create stack service
|
|
64
|
+
let _stackService = null;
|
|
65
|
+
function getStackService() {
|
|
66
|
+
if (!_stackService) {
|
|
67
|
+
const config = exports.configManager.getConfig();
|
|
68
|
+
const organizationId = config.organizationId;
|
|
69
|
+
if (!organizationId) {
|
|
70
|
+
throw new Error('Organization ID not set. Please authenticate first.');
|
|
71
|
+
}
|
|
72
|
+
const apiClient = (0, client_1.createApiClient)(appConfig.apiBaseUrl);
|
|
73
|
+
exports.tokenManager.restoreTokensFromConfig(apiClient);
|
|
74
|
+
_stackService = new StackService_1.StackService(apiClient, exports.applicationService, organizationId, exports.logger);
|
|
75
|
+
}
|
|
76
|
+
return _stackService;
|
|
77
|
+
}
|
|
78
|
+
// Export stackService as a getter to ensure it's initialized with proper organizationId
|
|
79
|
+
exports.stackService = {
|
|
80
|
+
get instance() {
|
|
81
|
+
return getStackService();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
56
84
|
// Create connectivity tester (transient - create new instances as needed)
|
|
57
85
|
function createConnectivityTester() {
|
|
58
86
|
return new ConnectivityTester_1.ConnectivityTester();
|
|
@@ -61,4 +89,25 @@ function createConnectivityTester() {
|
|
|
61
89
|
function createWorkloadDetector() {
|
|
62
90
|
return new WorkloadDetector_1.WorkloadDetector();
|
|
63
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Get all service instances
|
|
94
|
+
* Convenience function for commands that need multiple services
|
|
95
|
+
*/
|
|
96
|
+
function getServiceInstances() {
|
|
97
|
+
return {
|
|
98
|
+
logger: exports.logger,
|
|
99
|
+
configManager: exports.configManager,
|
|
100
|
+
tokenManager: exports.tokenManager,
|
|
101
|
+
authService: exports.authService,
|
|
102
|
+
applicationService: exports.applicationService,
|
|
103
|
+
gatewayService: exports.gatewayService,
|
|
104
|
+
deviceService: exports.deviceService,
|
|
105
|
+
edgibleService: exports.edgibleService,
|
|
106
|
+
localAgentManager: exports.localAgentManager,
|
|
107
|
+
managedGatewayService: exports.managedGatewayService,
|
|
108
|
+
diagnosticsService: exports.diagnosticsService,
|
|
109
|
+
agentDeploymentService: exports.agentDeploymentService,
|
|
110
|
+
stackService: getStackService(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
64
113
|
//# sourceMappingURL=instances.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency Graph Manager
|
|
3
|
+
* Handles dependency resolution and topological sorting for application deployments
|
|
4
|
+
*/
|
|
5
|
+
import { StackApplication } from '../../types/stack';
|
|
6
|
+
import { Logger } from '../../utils/logger';
|
|
7
|
+
export declare class DependencyGraphManager {
|
|
8
|
+
private logger;
|
|
9
|
+
constructor(logger: Logger);
|
|
10
|
+
/**
|
|
11
|
+
* Build dependency graph from applications
|
|
12
|
+
* @param applications List of stack applications
|
|
13
|
+
* @returns Adjacency list representation of the graph
|
|
14
|
+
*/
|
|
15
|
+
buildGraph(applications: StackApplication[]): Map<string, string[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Detect circular dependencies in the graph
|
|
18
|
+
* @param applications List of stack applications
|
|
19
|
+
* @returns Array of application names forming a cycle, or null if no cycle
|
|
20
|
+
*/
|
|
21
|
+
detectCycles(applications: StackApplication[]): string[] | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get deployment order using topological sort
|
|
24
|
+
* Applications with no dependencies come first
|
|
25
|
+
* @param applications List of stack applications
|
|
26
|
+
* @returns Ordered list of application names for deployment
|
|
27
|
+
* @throws CircularDependencyError if cycle detected
|
|
28
|
+
*/
|
|
29
|
+
getDeploymentOrder(applications: StackApplication[]): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Get teardown order (reverse of deployment order)
|
|
32
|
+
* Applications with dependents are removed last
|
|
33
|
+
* @param applications List of stack applications
|
|
34
|
+
* @returns Ordered list of application names for teardown
|
|
35
|
+
*/
|
|
36
|
+
getTeardownOrder(applications: StackApplication[]): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Get direct dependencies for an application
|
|
39
|
+
* @param appName Application name
|
|
40
|
+
* @param applications List of stack applications
|
|
41
|
+
* @returns List of application names that this app depends on
|
|
42
|
+
*/
|
|
43
|
+
getDependencies(appName: string, applications: StackApplication[]): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Get all applications that depend on the given application (dependents)
|
|
46
|
+
* @param appName Application name
|
|
47
|
+
* @param applications List of stack applications
|
|
48
|
+
* @returns List of application names that depend on this app
|
|
49
|
+
*/
|
|
50
|
+
getDependents(appName: string, applications: StackApplication[]): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Check if an application can be deployed independently
|
|
53
|
+
* (has no dependencies or all dependencies are already deployed)
|
|
54
|
+
* @param appName Application name
|
|
55
|
+
* @param applications List of stack applications
|
|
56
|
+
* @param deployedApps Set of already deployed application names
|
|
57
|
+
* @returns True if app can be deployed
|
|
58
|
+
*/
|
|
59
|
+
canDeploy(appName: string, applications: StackApplication[], deployedApps: Set<string>): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Validate dependency graph
|
|
62
|
+
* Checks for cycles and non-existent dependencies
|
|
63
|
+
* @param applications List of stack applications
|
|
64
|
+
* @throws CircularDependencyError if cycle detected
|
|
65
|
+
* @throws Error if dependency not found
|
|
66
|
+
*/
|
|
67
|
+
validate(applications: StackApplication[]): void;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=DependencyGraphManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DependencyGraphManager.d.ts","sourceRoot":"","sources":["../../../src/services/stack/DependencyGraphManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,qBAAa,sBAAsB;IACrB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;OAIG;IACH,UAAU,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAoBnE;;;;OAIG;IACH,YAAY,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI;IAwC/D;;;;;;OAMG;IACH,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE;IAqD9D;;;;;OAKG;IACH,gBAAgB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE;IAQ5D;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE;IAK5E;;;;;OAKG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE;IAY1E;;;;;;;OAOG;IACH,SAAS,CACP,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,gBAAgB,EAAE,EAChC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,OAAO;IAOV;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,IAAI;CAwBjD"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Dependency Graph Manager
|
|
4
|
+
* Handles dependency resolution and topological sorting for application deployments
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DependencyGraphManager = void 0;
|
|
8
|
+
const stack_errors_1 = require("../../utils/stack-errors");
|
|
9
|
+
class DependencyGraphManager {
|
|
10
|
+
constructor(logger) {
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build dependency graph from applications
|
|
15
|
+
* @param applications List of stack applications
|
|
16
|
+
* @returns Adjacency list representation of the graph
|
|
17
|
+
*/
|
|
18
|
+
buildGraph(applications) {
|
|
19
|
+
const graph = new Map();
|
|
20
|
+
// Initialize all nodes
|
|
21
|
+
for (const app of applications) {
|
|
22
|
+
if (!graph.has(app.name)) {
|
|
23
|
+
graph.set(app.name, []);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Add edges (dependencies)
|
|
27
|
+
for (const app of applications) {
|
|
28
|
+
if (app.dependsOn && app.dependsOn.length > 0) {
|
|
29
|
+
graph.set(app.name, [...app.dependsOn]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return graph;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Detect circular dependencies in the graph
|
|
36
|
+
* @param applications List of stack applications
|
|
37
|
+
* @returns Array of application names forming a cycle, or null if no cycle
|
|
38
|
+
*/
|
|
39
|
+
detectCycles(applications) {
|
|
40
|
+
const graph = this.buildGraph(applications);
|
|
41
|
+
const visited = new Set();
|
|
42
|
+
const recursionStack = new Set();
|
|
43
|
+
const path = [];
|
|
44
|
+
const dfs = (node) => {
|
|
45
|
+
visited.add(node);
|
|
46
|
+
recursionStack.add(node);
|
|
47
|
+
path.push(node);
|
|
48
|
+
const neighbors = graph.get(node) || [];
|
|
49
|
+
for (const neighbor of neighbors) {
|
|
50
|
+
if (!visited.has(neighbor)) {
|
|
51
|
+
const cycle = dfs(neighbor);
|
|
52
|
+
if (cycle)
|
|
53
|
+
return cycle;
|
|
54
|
+
}
|
|
55
|
+
else if (recursionStack.has(neighbor)) {
|
|
56
|
+
// Found a cycle
|
|
57
|
+
const cycleStart = path.indexOf(neighbor);
|
|
58
|
+
return [...path.slice(cycleStart), neighbor];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
path.pop();
|
|
62
|
+
recursionStack.delete(node);
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
for (const app of applications) {
|
|
66
|
+
if (!visited.has(app.name)) {
|
|
67
|
+
const cycle = dfs(app.name);
|
|
68
|
+
if (cycle) {
|
|
69
|
+
return cycle;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get deployment order using topological sort
|
|
77
|
+
* Applications with no dependencies come first
|
|
78
|
+
* @param applications List of stack applications
|
|
79
|
+
* @returns Ordered list of application names for deployment
|
|
80
|
+
* @throws CircularDependencyError if cycle detected
|
|
81
|
+
*/
|
|
82
|
+
getDeploymentOrder(applications) {
|
|
83
|
+
// First, check for cycles
|
|
84
|
+
const cycle = this.detectCycles(applications);
|
|
85
|
+
if (cycle) {
|
|
86
|
+
throw new stack_errors_1.CircularDependencyError(cycle);
|
|
87
|
+
}
|
|
88
|
+
const graph = this.buildGraph(applications);
|
|
89
|
+
const inDegree = new Map();
|
|
90
|
+
const result = [];
|
|
91
|
+
// Calculate in-degree for each node
|
|
92
|
+
for (const app of applications) {
|
|
93
|
+
inDegree.set(app.name, 0);
|
|
94
|
+
}
|
|
95
|
+
for (const app of applications) {
|
|
96
|
+
const deps = graph.get(app.name) || [];
|
|
97
|
+
for (const dep of deps) {
|
|
98
|
+
inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Queue of nodes with no dependencies
|
|
102
|
+
const queue = [];
|
|
103
|
+
for (const [node, degree] of inDegree.entries()) {
|
|
104
|
+
if (degree === 0) {
|
|
105
|
+
queue.push(node);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Process queue (Kahn's algorithm)
|
|
109
|
+
while (queue.length > 0) {
|
|
110
|
+
const current = queue.shift();
|
|
111
|
+
result.push(current);
|
|
112
|
+
// Find all apps that depend on current
|
|
113
|
+
for (const app of applications) {
|
|
114
|
+
if (app.dependsOn && app.dependsOn.includes(current)) {
|
|
115
|
+
const currentInDegree = inDegree.get(app.name) || 0;
|
|
116
|
+
inDegree.set(app.name, currentInDegree - 1);
|
|
117
|
+
if (inDegree.get(app.name) === 0) {
|
|
118
|
+
queue.push(app.name);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
this.logger.debug(`Deployment order: ${result.join(' -> ')}`);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get teardown order (reverse of deployment order)
|
|
128
|
+
* Applications with dependents are removed last
|
|
129
|
+
* @param applications List of stack applications
|
|
130
|
+
* @returns Ordered list of application names for teardown
|
|
131
|
+
*/
|
|
132
|
+
getTeardownOrder(applications) {
|
|
133
|
+
const deploymentOrder = this.getDeploymentOrder(applications);
|
|
134
|
+
const teardownOrder = [...deploymentOrder].reverse();
|
|
135
|
+
this.logger.debug(`Teardown order: ${teardownOrder.join(' -> ')}`);
|
|
136
|
+
return teardownOrder;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get direct dependencies for an application
|
|
140
|
+
* @param appName Application name
|
|
141
|
+
* @param applications List of stack applications
|
|
142
|
+
* @returns List of application names that this app depends on
|
|
143
|
+
*/
|
|
144
|
+
getDependencies(appName, applications) {
|
|
145
|
+
const app = applications.find(a => a.name === appName);
|
|
146
|
+
return app?.dependsOn || [];
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get all applications that depend on the given application (dependents)
|
|
150
|
+
* @param appName Application name
|
|
151
|
+
* @param applications List of stack applications
|
|
152
|
+
* @returns List of application names that depend on this app
|
|
153
|
+
*/
|
|
154
|
+
getDependents(appName, applications) {
|
|
155
|
+
const dependents = [];
|
|
156
|
+
for (const app of applications) {
|
|
157
|
+
if (app.dependsOn && app.dependsOn.includes(appName)) {
|
|
158
|
+
dependents.push(app.name);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return dependents;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Check if an application can be deployed independently
|
|
165
|
+
* (has no dependencies or all dependencies are already deployed)
|
|
166
|
+
* @param appName Application name
|
|
167
|
+
* @param applications List of stack applications
|
|
168
|
+
* @param deployedApps Set of already deployed application names
|
|
169
|
+
* @returns True if app can be deployed
|
|
170
|
+
*/
|
|
171
|
+
canDeploy(appName, applications, deployedApps) {
|
|
172
|
+
const dependencies = this.getDependencies(appName, applications);
|
|
173
|
+
// Can deploy if all dependencies are already deployed
|
|
174
|
+
return dependencies.every(dep => deployedApps.has(dep));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Validate dependency graph
|
|
178
|
+
* Checks for cycles and non-existent dependencies
|
|
179
|
+
* @param applications List of stack applications
|
|
180
|
+
* @throws CircularDependencyError if cycle detected
|
|
181
|
+
* @throws Error if dependency not found
|
|
182
|
+
*/
|
|
183
|
+
validate(applications) {
|
|
184
|
+
const appNames = new Set(applications.map(app => app.name));
|
|
185
|
+
// Check for non-existent dependencies
|
|
186
|
+
for (const app of applications) {
|
|
187
|
+
if (app.dependsOn) {
|
|
188
|
+
for (const dep of app.dependsOn) {
|
|
189
|
+
if (!appNames.has(dep)) {
|
|
190
|
+
throw new Error(`Application '${app.name}' depends on non-existent application '${dep}'`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Check for cycles
|
|
196
|
+
const cycle = this.detectCycles(applications);
|
|
197
|
+
if (cycle) {
|
|
198
|
+
throw new stack_errors_1.CircularDependencyError(cycle);
|
|
199
|
+
}
|
|
200
|
+
this.logger.debug('Dependency graph validation passed');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.DependencyGraphManager = DependencyGraphManager;
|
|
204
|
+
//# sourceMappingURL=DependencyGraphManager.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device Resolver Service
|
|
3
|
+
* Resolves device names to device IDs by querying the organization's devices
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from '../../client';
|
|
6
|
+
import { DeviceData } from '../../types/models/DeviceData';
|
|
7
|
+
import { Logger } from '../../utils/logger';
|
|
8
|
+
export interface DeviceResolutionResult {
|
|
9
|
+
deviceName: string;
|
|
10
|
+
deviceId: string;
|
|
11
|
+
device: DeviceData;
|
|
12
|
+
}
|
|
13
|
+
export declare class DeviceResolver {
|
|
14
|
+
private apiClient;
|
|
15
|
+
private organizationId;
|
|
16
|
+
private logger;
|
|
17
|
+
private deviceCache;
|
|
18
|
+
private cacheTimestamp;
|
|
19
|
+
private readonly CACHE_TTL_MS;
|
|
20
|
+
constructor(apiClient: ApiClient, organizationId: string, logger: Logger);
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a device name to device ID
|
|
23
|
+
* @param deviceName Name of the device to resolve
|
|
24
|
+
* @returns DeviceResolutionResult with device ID and full device data
|
|
25
|
+
* @throws DeviceNotFoundError if device not found
|
|
26
|
+
* @throws DeviceAmbiguousError if multiple devices match
|
|
27
|
+
*/
|
|
28
|
+
resolveDevice(deviceName: string): Promise<DeviceResolutionResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve multiple device names to IDs
|
|
31
|
+
* @param deviceNames Array of device names to resolve
|
|
32
|
+
* @returns Map of deviceName -> deviceId
|
|
33
|
+
* @throws DeviceNotFoundError or DeviceAmbiguousError for any device
|
|
34
|
+
*/
|
|
35
|
+
resolveDevices(deviceNames: string[]): Promise<Map<string, string>>;
|
|
36
|
+
/**
|
|
37
|
+
* Get all devices in the organization (with caching)
|
|
38
|
+
* @returns Array of DeviceData
|
|
39
|
+
*/
|
|
40
|
+
private getDevices;
|
|
41
|
+
/**
|
|
42
|
+
* Clear the device cache (useful for testing or forcing refresh)
|
|
43
|
+
*/
|
|
44
|
+
clearCache(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a device exists by name
|
|
47
|
+
* @param deviceName Name of the device
|
|
48
|
+
* @returns True if device exists
|
|
49
|
+
*/
|
|
50
|
+
deviceExists(deviceName: string): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* List all available device names
|
|
53
|
+
* @returns Array of device names
|
|
54
|
+
*/
|
|
55
|
+
listDeviceNames(): Promise<string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Get device details by name
|
|
58
|
+
* @param deviceName Name of the device
|
|
59
|
+
* @returns DeviceData or null if not found
|
|
60
|
+
*/
|
|
61
|
+
getDeviceByName(deviceName: string): Promise<DeviceData | null>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=DeviceResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceResolver.d.ts","sourceRoot":"","sources":["../../../src/services/stack/DeviceResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,qBAAa,cAAc;IAMvB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,WAAW,CAA0C;IAC7D,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAG5B,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM;IAGxB;;;;;;OAMG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA2BxE;;;;;OAKG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAYzE;;;OAGG;YACW,UAAU;IAqCxB;;OAEG;IACH,UAAU,IAAI,IAAI;IAMlB;;;;OAIG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYxD;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAK1C;;;;OAIG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;CAWtE"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Device Resolver Service
|
|
4
|
+
* Resolves device names to device IDs by querying the organization's devices
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DeviceResolver = void 0;
|
|
8
|
+
const stack_errors_1 = require("../../utils/stack-errors");
|
|
9
|
+
class DeviceResolver {
|
|
10
|
+
constructor(apiClient, organizationId, logger) {
|
|
11
|
+
this.apiClient = apiClient;
|
|
12
|
+
this.organizationId = organizationId;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.deviceCache = null;
|
|
15
|
+
this.cacheTimestamp = null;
|
|
16
|
+
this.CACHE_TTL_MS = 60000; // 1 minute cache
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a device name to device ID
|
|
20
|
+
* @param deviceName Name of the device to resolve
|
|
21
|
+
* @returns DeviceResolutionResult with device ID and full device data
|
|
22
|
+
* @throws DeviceNotFoundError if device not found
|
|
23
|
+
* @throws DeviceAmbiguousError if multiple devices match
|
|
24
|
+
*/
|
|
25
|
+
async resolveDevice(deviceName) {
|
|
26
|
+
this.logger.debug(`Resolving device: ${deviceName}`);
|
|
27
|
+
const devices = await this.getDevices();
|
|
28
|
+
// Find devices with matching name (case-sensitive)
|
|
29
|
+
const matchingDevices = devices.filter(d => d.name === deviceName);
|
|
30
|
+
if (matchingDevices.length === 0) {
|
|
31
|
+
throw new stack_errors_1.DeviceNotFoundError(deviceName);
|
|
32
|
+
}
|
|
33
|
+
if (matchingDevices.length > 1) {
|
|
34
|
+
const deviceIds = matchingDevices.map(d => d.id);
|
|
35
|
+
throw new stack_errors_1.DeviceAmbiguousError(deviceName, deviceIds);
|
|
36
|
+
}
|
|
37
|
+
const device = matchingDevices[0];
|
|
38
|
+
this.logger.debug(`Resolved device '${deviceName}' to ID: ${device.id}`);
|
|
39
|
+
return {
|
|
40
|
+
deviceName,
|
|
41
|
+
deviceId: device.id,
|
|
42
|
+
device,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolve multiple device names to IDs
|
|
47
|
+
* @param deviceNames Array of device names to resolve
|
|
48
|
+
* @returns Map of deviceName -> deviceId
|
|
49
|
+
* @throws DeviceNotFoundError or DeviceAmbiguousError for any device
|
|
50
|
+
*/
|
|
51
|
+
async resolveDevices(deviceNames) {
|
|
52
|
+
const uniqueNames = [...new Set(deviceNames)];
|
|
53
|
+
const result = new Map();
|
|
54
|
+
for (const name of uniqueNames) {
|
|
55
|
+
const resolution = await this.resolveDevice(name);
|
|
56
|
+
result.set(name, resolution.deviceId);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get all devices in the organization (with caching)
|
|
62
|
+
* @returns Array of DeviceData
|
|
63
|
+
*/
|
|
64
|
+
async getDevices() {
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
// Return cached devices if still valid
|
|
67
|
+
if (this.deviceCache !== null &&
|
|
68
|
+
this.cacheTimestamp !== null &&
|
|
69
|
+
now - this.cacheTimestamp < this.CACHE_TTL_MS) {
|
|
70
|
+
const cached = this.deviceCache.get(this.organizationId);
|
|
71
|
+
if (cached) {
|
|
72
|
+
this.logger.debug('Using cached device list');
|
|
73
|
+
return cached;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Fetch devices from API
|
|
77
|
+
this.logger.debug(`Fetching devices for organization: ${this.organizationId}`);
|
|
78
|
+
try {
|
|
79
|
+
const response = await this.apiClient.getOrganizationDevices(this.organizationId);
|
|
80
|
+
const devices = response.devices || [];
|
|
81
|
+
// Update cache
|
|
82
|
+
if (this.deviceCache === null) {
|
|
83
|
+
this.deviceCache = new Map();
|
|
84
|
+
}
|
|
85
|
+
this.deviceCache.set(this.organizationId, devices);
|
|
86
|
+
this.cacheTimestamp = now;
|
|
87
|
+
this.logger.debug(`Fetched ${devices.length} devices`);
|
|
88
|
+
return devices;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.logger.error(`Failed to fetch devices: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
92
|
+
throw new Error(`Failed to fetch organization devices: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Clear the device cache (useful for testing or forcing refresh)
|
|
97
|
+
*/
|
|
98
|
+
clearCache() {
|
|
99
|
+
this.deviceCache = null;
|
|
100
|
+
this.cacheTimestamp = null;
|
|
101
|
+
this.logger.debug('Device cache cleared');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if a device exists by name
|
|
105
|
+
* @param deviceName Name of the device
|
|
106
|
+
* @returns True if device exists
|
|
107
|
+
*/
|
|
108
|
+
async deviceExists(deviceName) {
|
|
109
|
+
try {
|
|
110
|
+
await this.resolveDevice(deviceName);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (error instanceof stack_errors_1.DeviceNotFoundError) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* List all available device names
|
|
122
|
+
* @returns Array of device names
|
|
123
|
+
*/
|
|
124
|
+
async listDeviceNames() {
|
|
125
|
+
const devices = await this.getDevices();
|
|
126
|
+
return devices.map(d => d.name);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get device details by name
|
|
130
|
+
* @param deviceName Name of the device
|
|
131
|
+
* @returns DeviceData or null if not found
|
|
132
|
+
*/
|
|
133
|
+
async getDeviceByName(deviceName) {
|
|
134
|
+
try {
|
|
135
|
+
const result = await this.resolveDevice(deviceName);
|
|
136
|
+
return result.device;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error instanceof stack_errors_1.DeviceNotFoundError) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.DeviceResolver = DeviceResolver;
|
|
147
|
+
//# sourceMappingURL=DeviceResolver.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway Resolver Service
|
|
3
|
+
* Resolves gateway requirements for published applications
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from '../../client';
|
|
6
|
+
import { Logger } from '../../utils/logger';
|
|
7
|
+
import { StackApplication } from '../../types/stack';
|
|
8
|
+
export interface GatewayResolutionResult {
|
|
9
|
+
appName: string;
|
|
10
|
+
gatewayIds: string[];
|
|
11
|
+
gatewayCreated: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ManagedGatewayInfo {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
region: string;
|
|
17
|
+
status: string;
|
|
18
|
+
applicationsCount?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class GatewayResolver {
|
|
21
|
+
private apiClient;
|
|
22
|
+
private organizationId;
|
|
23
|
+
private logger;
|
|
24
|
+
private gatewayCache;
|
|
25
|
+
private cacheTimestamp;
|
|
26
|
+
private readonly CACHE_TTL_MS;
|
|
27
|
+
constructor(apiClient: ApiClient, organizationId: string, logger: Logger);
|
|
28
|
+
/**
|
|
29
|
+
* Resolve gateway requirements for applications
|
|
30
|
+
* For published apps, finds or suggests managed gateways
|
|
31
|
+
* @param applications List of applications to resolve gateways for
|
|
32
|
+
* @param autoCreate If true, will create gateways automatically (requires confirmation in caller)
|
|
33
|
+
* @returns Map of appName -> gatewayIds
|
|
34
|
+
*/
|
|
35
|
+
resolveGateways(applications: StackApplication[], autoCreate?: boolean): Promise<Map<string, string[]>>;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve gateway for a single application
|
|
38
|
+
* @param appName Application name
|
|
39
|
+
* @param published Whether the app should be published
|
|
40
|
+
* @returns Array of gateway IDs (empty if not published)
|
|
41
|
+
*/
|
|
42
|
+
resolveGateway(appName: string, published: boolean): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* List all managed gateways (with caching)
|
|
45
|
+
* @returns Array of managed gateway info
|
|
46
|
+
*/
|
|
47
|
+
listManagedGateways(): Promise<ManagedGatewayInfo[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if gateway creation is needed
|
|
50
|
+
* @param applications List of applications
|
|
51
|
+
* @returns True if any published app needs a gateway but none available
|
|
52
|
+
*/
|
|
53
|
+
needsGatewayCreation(applications: StackApplication[]): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Select best gateway for an application
|
|
56
|
+
* Future enhancement: implement intelligent selection based on:
|
|
57
|
+
* - Region proximity to device
|
|
58
|
+
* - Current capacity/load
|
|
59
|
+
* - Application count
|
|
60
|
+
* - Performance metrics
|
|
61
|
+
*
|
|
62
|
+
* @param appName Application name
|
|
63
|
+
* @param deviceRegion Region where device is located
|
|
64
|
+
* @returns Gateway ID or null if none suitable
|
|
65
|
+
*/
|
|
66
|
+
selectBestGateway(appName: string, deviceRegion?: string): Promise<string | null>;
|
|
67
|
+
/**
|
|
68
|
+
* Clear the gateway cache (useful for testing or forcing refresh)
|
|
69
|
+
*/
|
|
70
|
+
clearCache(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get gateway details
|
|
73
|
+
* @param gatewayId Gateway ID
|
|
74
|
+
* @returns Gateway info or null if not found
|
|
75
|
+
*/
|
|
76
|
+
getGateway(gatewayId: string): Promise<ManagedGatewayInfo | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if a gateway exists and is available
|
|
79
|
+
* @param gatewayId Gateway ID
|
|
80
|
+
* @returns True if gateway exists and is active
|
|
81
|
+
*/
|
|
82
|
+
gatewayAvailable(gatewayId: string): Promise<boolean>;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=GatewayResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatewayResolver.d.ts","sourceRoot":"","sources":["../../../src/services/stack/GatewayResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,eAAe;IAMxB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,MAAM;IAPhB,OAAO,CAAC,YAAY,CAAqC;IACzD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAG5B,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM;IAGxB;;;;;;OAMG;IACG,eAAe,CACnB,YAAY,EAAE,gBAAgB,EAAE,EAChC,UAAU,GAAE,OAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IA0CjC;;;;;OAKG;IACG,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC;IAqBpB;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAgD1D;;;;OAIG;IACG,oBAAoB,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAU9E;;;;;;;;;;;OAWG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYzB;;OAEG;IACH,UAAU,IAAI,IAAI;IAMlB;;;;OAIG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAKvE;;;;OAIG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAI5D"}
|