@edgible-team/cli 1.0.1
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 +136 -0
- package/README.md +450 -0
- package/dist/client/api-client.js +1057 -0
- package/dist/client/index.js +21 -0
- package/dist/commands/agent.js +1280 -0
- package/dist/commands/ai.js +608 -0
- package/dist/commands/application.js +885 -0
- package/dist/commands/auth.js +570 -0
- package/dist/commands/base/BaseCommand.js +93 -0
- package/dist/commands/base/CommandHandler.js +7 -0
- package/dist/commands/base/command-wrapper.js +58 -0
- package/dist/commands/base/middleware.js +77 -0
- package/dist/commands/config.js +116 -0
- package/dist/commands/connectivity.js +59 -0
- package/dist/commands/debug.js +98 -0
- package/dist/commands/discover.js +144 -0
- package/dist/commands/examples/migrated-command-example.js +180 -0
- package/dist/commands/gateway.js +494 -0
- package/dist/commands/managedGateway.js +787 -0
- package/dist/commands/utils/config-validator.js +76 -0
- package/dist/commands/utils/gateway-prompt.js +79 -0
- package/dist/commands/utils/input-parser.js +120 -0
- package/dist/commands/utils/output-formatter.js +109 -0
- package/dist/config/app-config.js +99 -0
- package/dist/detection/SystemCapabilityDetector.js +1244 -0
- package/dist/detection/ToolDetector.js +305 -0
- package/dist/detection/WorkloadDetector.js +314 -0
- package/dist/di/bindings.js +99 -0
- package/dist/di/container.js +88 -0
- package/dist/di/types.js +32 -0
- package/dist/index.js +52 -0
- package/dist/interfaces/IDaemonManager.js +3 -0
- package/dist/repositories/config-repository.js +62 -0
- package/dist/repositories/gateway-repository.js +35 -0
- package/dist/scripts/postinstall.js +101 -0
- package/dist/services/AgentStatusManager.js +299 -0
- package/dist/services/ConnectivityTester.js +271 -0
- package/dist/services/DependencyInstaller.js +475 -0
- package/dist/services/LocalAgentManager.js +2216 -0
- package/dist/services/application/ApplicationService.js +299 -0
- package/dist/services/auth/AuthService.js +214 -0
- package/dist/services/aws.js +644 -0
- package/dist/services/daemon/DaemonManagerFactory.js +65 -0
- package/dist/services/daemon/DockerDaemonManager.js +395 -0
- package/dist/services/daemon/LaunchdDaemonManager.js +257 -0
- package/dist/services/daemon/PodmanDaemonManager.js +369 -0
- package/dist/services/daemon/SystemdDaemonManager.js +221 -0
- package/dist/services/daemon/WindowsServiceDaemonManager.js +210 -0
- package/dist/services/daemon/index.js +16 -0
- package/dist/services/edgible.js +3060 -0
- package/dist/services/gateway/GatewayService.js +334 -0
- package/dist/state/config.js +146 -0
- package/dist/types/AgentConfig.js +5 -0
- package/dist/types/AgentStatus.js +5 -0
- package/dist/types/ApiClient.js +5 -0
- package/dist/types/ApiRequests.js +5 -0
- package/dist/types/ApiResponses.js +5 -0
- package/dist/types/Application.js +5 -0
- package/dist/types/CaddyJson.js +5 -0
- package/dist/types/UnifiedAgentStatus.js +56 -0
- package/dist/types/WireGuard.js +5 -0
- package/dist/types/Workload.js +5 -0
- package/dist/types/agent.js +5 -0
- package/dist/types/command-options.js +5 -0
- package/dist/types/connectivity.js +5 -0
- package/dist/types/errors.js +250 -0
- package/dist/types/gateway-types.js +5 -0
- package/dist/types/index.js +48 -0
- package/dist/types/models/ApplicationData.js +5 -0
- package/dist/types/models/CertificateData.js +5 -0
- package/dist/types/models/DeviceData.js +5 -0
- package/dist/types/models/DevicePoolData.js +5 -0
- package/dist/types/models/OrganizationData.js +5 -0
- package/dist/types/models/OrganizationInviteData.js +5 -0
- package/dist/types/models/ProviderConfiguration.js +5 -0
- package/dist/types/models/ResourceData.js +5 -0
- package/dist/types/models/ServiceResourceData.js +5 -0
- package/dist/types/models/UserData.js +5 -0
- package/dist/types/route.js +5 -0
- package/dist/types/validation/schemas.js +218 -0
- package/dist/types/validation.js +5 -0
- package/dist/utils/FileIntegrityManager.js +256 -0
- package/dist/utils/PathMigration.js +219 -0
- package/dist/utils/PathResolver.js +235 -0
- package/dist/utils/PlatformDetector.js +277 -0
- package/dist/utils/console-logger.js +130 -0
- package/dist/utils/docker-compose-parser.js +179 -0
- package/dist/utils/errors.js +130 -0
- package/dist/utils/health-checker.js +155 -0
- package/dist/utils/json-logger.js +72 -0
- package/dist/utils/log-formatter.js +293 -0
- package/dist/utils/logger.js +59 -0
- package/dist/utils/network-utils.js +217 -0
- package/dist/utils/output.js +182 -0
- package/dist/utils/passwordValidation.js +91 -0
- package/dist/utils/progress.js +167 -0
- package/dist/utils/sudo-checker.js +22 -0
- package/dist/utils/urls.js +32 -0
- package/dist/utils/validation.js +31 -0
- package/dist/validation/schemas.js +175 -0
- package/dist/validation/validator.js +67 -0
- package/package.json +83 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Gateway service
|
|
4
|
+
* Handles gateway device management operations
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.GatewayServiceImpl = void 0;
|
|
8
|
+
const client_1 = require("../../client");
|
|
9
|
+
const aws_1 = require("../aws");
|
|
10
|
+
const PathResolver_1 = require("../../utils/PathResolver");
|
|
11
|
+
class GatewayServiceImpl {
|
|
12
|
+
constructor(baseUrl, configRepository, gatewayRepository, authService, logger) {
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
this.configRepository = configRepository;
|
|
15
|
+
this.gatewayRepository = gatewayRepository;
|
|
16
|
+
this.authService = authService;
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
this.apiClient = (0, client_1.createApiClient)(baseUrl);
|
|
19
|
+
this.restoreTokensFromApiClient();
|
|
20
|
+
}
|
|
21
|
+
restoreTokensFromApiClient() {
|
|
22
|
+
const accessToken = this.authService.getAccessToken();
|
|
23
|
+
const idToken = this.authService.getIdToken();
|
|
24
|
+
const refreshToken = this.authService.getRefreshToken();
|
|
25
|
+
if (accessToken) {
|
|
26
|
+
this.apiClient.setAccessToken(accessToken);
|
|
27
|
+
}
|
|
28
|
+
if (idToken) {
|
|
29
|
+
this.apiClient.setIdToken(idToken);
|
|
30
|
+
}
|
|
31
|
+
if (refreshToken) {
|
|
32
|
+
this.apiClient.setRefreshToken(refreshToken);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
generateAgentUserData(deviceId) {
|
|
36
|
+
const systemAgentPath = PathResolver_1.PathResolver.getSystemDataPath() + '/agent';
|
|
37
|
+
return `#!/bin/bash
|
|
38
|
+
# Update system
|
|
39
|
+
yum update -y
|
|
40
|
+
|
|
41
|
+
# Install required system dependencies
|
|
42
|
+
yum install -y iptables
|
|
43
|
+
|
|
44
|
+
# Install WireGuard
|
|
45
|
+
amazon-linux-extras install epel -y || yum install -y epel-release
|
|
46
|
+
yum install -y wireguard-tools
|
|
47
|
+
modprobe wireguard || true
|
|
48
|
+
|
|
49
|
+
# Install HAProxy
|
|
50
|
+
yum install -y haproxy
|
|
51
|
+
# Create HAProxy config directory
|
|
52
|
+
mkdir -p /etc/haproxy
|
|
53
|
+
# Create HAProxy runtime socket directory
|
|
54
|
+
mkdir -p /var/run/haproxy
|
|
55
|
+
# Set capabilities for HAProxy to bind to privileged ports
|
|
56
|
+
setcap cap_net_bind_service=+ep /usr/sbin/haproxy || true
|
|
57
|
+
# Create HAProxy chroot directory
|
|
58
|
+
mkdir -p /var/lib/haproxy
|
|
59
|
+
chown haproxy:haproxy /var/lib/haproxy || true
|
|
60
|
+
|
|
61
|
+
# Install Node.js
|
|
62
|
+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
|
|
63
|
+
export NVM_DIR="$HOME/.nvm"
|
|
64
|
+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
65
|
+
nvm install 18
|
|
66
|
+
nvm use 18
|
|
67
|
+
|
|
68
|
+
# Create system-wide symlink for Node.js
|
|
69
|
+
NODE_VERSION=$(nvm list | grep -oE 'v18\.[0-9]+\.[0-9]+' | head -1)
|
|
70
|
+
if [ -n "$NODE_VERSION" ]; then
|
|
71
|
+
sudo ln -sf "/home/ec2-user/.nvm/versions/node/$NODE_VERSION/bin/node" /usr/local/bin/node
|
|
72
|
+
sudo ln -sf "/home/ec2-user/.nvm/versions/node/$NODE_VERSION/bin/npm" /usr/local/bin/npm
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# Install PM2 for process management
|
|
76
|
+
npm install -g pm2
|
|
77
|
+
sudo npm install -g pm2 || true
|
|
78
|
+
|
|
79
|
+
# Create directory for agent
|
|
80
|
+
sudo mkdir -p /opt/edgible-agent
|
|
81
|
+
cd /opt/edgible-agent
|
|
82
|
+
sudo chown root:root /opt/edgible-agent
|
|
83
|
+
|
|
84
|
+
# Set up systemd service for agent
|
|
85
|
+
cat > /tmp/edgible-agent.service << 'EOF'
|
|
86
|
+
[Unit]
|
|
87
|
+
Description=Edgible Agent
|
|
88
|
+
After=network.target
|
|
89
|
+
|
|
90
|
+
[Service]
|
|
91
|
+
Type=simple
|
|
92
|
+
User=root
|
|
93
|
+
WorkingDirectory=/opt/edgible-agent
|
|
94
|
+
ExecStart=/usr/local/bin/node index.js start -c /opt/edgible-agent/agent.config.json
|
|
95
|
+
Restart=always
|
|
96
|
+
RestartSec=10
|
|
97
|
+
Environment=NODE_ENV=production
|
|
98
|
+
Environment=EDGIBLE_CONFIG_PATH=${PathResolver_1.PathResolver.getSystemDataPath()}/agent
|
|
99
|
+
Environment=DEVICE_ID=${deviceId}
|
|
100
|
+
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
101
|
+
|
|
102
|
+
[Install]
|
|
103
|
+
WantedBy=multi-user.target
|
|
104
|
+
EOF
|
|
105
|
+
sudo mv /tmp/edgible-agent.service /etc/systemd/system/edgible-agent.service
|
|
106
|
+
|
|
107
|
+
# Enable service
|
|
108
|
+
systemctl enable edgible-agent.service
|
|
109
|
+
|
|
110
|
+
echo "Edgible Agent setup complete for device: ${deviceId}"
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
async createGateway(config) {
|
|
114
|
+
try {
|
|
115
|
+
// Attempt auto re-login if tokens are missing but credentials are available
|
|
116
|
+
await this.authService.attemptAutoRelogin();
|
|
117
|
+
this.restoreTokensFromApiClient();
|
|
118
|
+
this.logger.info('Creating gateway');
|
|
119
|
+
// Get organization ID
|
|
120
|
+
const userConfig = this.configRepository.getConfig();
|
|
121
|
+
if (!userConfig.organizationId) {
|
|
122
|
+
throw new Error('No organization ID found. Please login first.');
|
|
123
|
+
}
|
|
124
|
+
// Initialize AWS service
|
|
125
|
+
const awsService = new aws_1.AWSService(config.awsProfile, config.region);
|
|
126
|
+
// Check AWS CLI availability
|
|
127
|
+
const awsCheck = await awsService.checkAWSCLI();
|
|
128
|
+
if (!awsCheck.available) {
|
|
129
|
+
throw new Error('AWS CLI is not installed or not available');
|
|
130
|
+
}
|
|
131
|
+
// Validate AWS credentials
|
|
132
|
+
const credentialsValid = await awsService.validateCredentials(config.awsProfile);
|
|
133
|
+
if (!credentialsValid) {
|
|
134
|
+
throw new Error('AWS credentials are invalid or not configured');
|
|
135
|
+
}
|
|
136
|
+
// Generate unique key pair name
|
|
137
|
+
const keyPairName = `edgible-gateway-${Date.now()}`;
|
|
138
|
+
// Create key pair
|
|
139
|
+
this.logger.debug('Creating SSH key pair');
|
|
140
|
+
const keyPair = await awsService.createKeyPair(keyPairName);
|
|
141
|
+
// Save SSH key locally
|
|
142
|
+
const keyPath = awsService.saveSSHKey(keyPair, keyPairName);
|
|
143
|
+
this.logger.debug(`SSH key saved to: ${keyPath}`);
|
|
144
|
+
// Create EC2 instance
|
|
145
|
+
this.logger.debug('Creating EC2 instance');
|
|
146
|
+
const ec2Instance = await awsService.createEC2Instance({
|
|
147
|
+
name: config.name,
|
|
148
|
+
instanceType: config.instanceType || 't3.micro',
|
|
149
|
+
keyPairName: keyPairName,
|
|
150
|
+
userData: this.generateAgentUserData(userConfig.deviceId || 'unknown'),
|
|
151
|
+
});
|
|
152
|
+
this.logger.debug(`EC2 instance created: ${ec2Instance.instanceId}`);
|
|
153
|
+
// Create gateway device via API
|
|
154
|
+
this.logger.debug('Creating gateway device');
|
|
155
|
+
const deviceRequest = {
|
|
156
|
+
name: config.name,
|
|
157
|
+
description: config.description || `Gateway: ${config.name}`,
|
|
158
|
+
organizationId: userConfig.organizationId,
|
|
159
|
+
type: 'gateway',
|
|
160
|
+
userEmail: userConfig.email || '',
|
|
161
|
+
configuration: {
|
|
162
|
+
awsProfile: config.awsProfile,
|
|
163
|
+
region: config.region || 'us-east-1',
|
|
164
|
+
instanceType: config.instanceType || 't3.micro',
|
|
165
|
+
keyPairName: keyPairName,
|
|
166
|
+
ec2InstanceId: ec2Instance.instanceId,
|
|
167
|
+
publicIp: ec2Instance.publicIp,
|
|
168
|
+
privateIp: ec2Instance.privateIp,
|
|
169
|
+
state: ec2Instance.state,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const response = await this.apiClient.createDevice(deviceRequest);
|
|
173
|
+
// Store gateway info in repository
|
|
174
|
+
this.gatewayRepository.addGateway(response.device.id, {
|
|
175
|
+
name: config.name,
|
|
176
|
+
deviceId: response.device.id,
|
|
177
|
+
ec2InstanceId: ec2Instance.instanceId,
|
|
178
|
+
publicIp: ec2Instance.publicIp,
|
|
179
|
+
privateIp: ec2Instance.privateIp,
|
|
180
|
+
keyPairName: keyPairName,
|
|
181
|
+
keyPath: keyPath,
|
|
182
|
+
region: config.region || 'us-east-1',
|
|
183
|
+
});
|
|
184
|
+
// Store AWS profile and region
|
|
185
|
+
if (config.awsProfile) {
|
|
186
|
+
this.configRepository.setAWSProfile(config.awsProfile);
|
|
187
|
+
}
|
|
188
|
+
if (config.region) {
|
|
189
|
+
this.configRepository.setAWSRegion(config.region);
|
|
190
|
+
}
|
|
191
|
+
this.logger.info('Gateway created successfully');
|
|
192
|
+
return {
|
|
193
|
+
message: 'Gateway created successfully',
|
|
194
|
+
gateway: {
|
|
195
|
+
id: response.device.id,
|
|
196
|
+
name: response.device.name,
|
|
197
|
+
description: response.device.description || '',
|
|
198
|
+
organizationId: response.device.organizationId,
|
|
199
|
+
createdAt: response.device.createdAt,
|
|
200
|
+
},
|
|
201
|
+
ec2Instance: {
|
|
202
|
+
instanceId: ec2Instance.instanceId,
|
|
203
|
+
publicIp: ec2Instance.publicIp,
|
|
204
|
+
privateIp: ec2Instance.privateIp,
|
|
205
|
+
state: ec2Instance.state,
|
|
206
|
+
keyPairName: keyPairName,
|
|
207
|
+
region: config.region || 'us-east-1',
|
|
208
|
+
},
|
|
209
|
+
sshKey: {
|
|
210
|
+
privateKey: keyPair.privateKey,
|
|
211
|
+
publicKey: keyPair.publicKey,
|
|
212
|
+
keyName: keyPairName,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
this.logger.error('Error creating gateway', error);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async listGateways() {
|
|
222
|
+
try {
|
|
223
|
+
// Attempt auto re-login if tokens are missing but credentials are available
|
|
224
|
+
await this.authService.attemptAutoRelogin();
|
|
225
|
+
this.restoreTokensFromApiClient();
|
|
226
|
+
const userConfig = this.configRepository.getConfig();
|
|
227
|
+
if (!userConfig.organizationId) {
|
|
228
|
+
throw new Error('No organization ID found. Please login first.');
|
|
229
|
+
}
|
|
230
|
+
// Get all devices from the organization
|
|
231
|
+
const devicesResponse = await this.apiClient.getOrganizationDevices(userConfig.organizationId);
|
|
232
|
+
// Filter for gateway devices - DeviceData.type can be various types, check the deviceId pattern or rely on API
|
|
233
|
+
const gatewayDevices = devicesResponse.devices.filter((device) => {
|
|
234
|
+
// Gateway devices typically have gateway in the name or we check a different property
|
|
235
|
+
// For now, we'll use a type assertion since the API should return the correct type
|
|
236
|
+
return device.type === 'gateway' || device.deviceId.includes('gateway');
|
|
237
|
+
});
|
|
238
|
+
// Enrich with local gateway info
|
|
239
|
+
const gateways = gatewayDevices.map((device) => {
|
|
240
|
+
const d = device;
|
|
241
|
+
const localInfo = this.gatewayRepository.getGateway(d.id);
|
|
242
|
+
return {
|
|
243
|
+
device: {
|
|
244
|
+
id: d.id,
|
|
245
|
+
name: d.name,
|
|
246
|
+
description: d.description || '',
|
|
247
|
+
type: 'gateway',
|
|
248
|
+
organizationId: d.organizationId,
|
|
249
|
+
createdAt: d.createdAt,
|
|
250
|
+
},
|
|
251
|
+
ec2Instance: localInfo
|
|
252
|
+
? {
|
|
253
|
+
instanceId: localInfo.ec2InstanceId,
|
|
254
|
+
publicIp: localInfo.publicIp,
|
|
255
|
+
privateIp: localInfo.privateIp,
|
|
256
|
+
state: 'running', // Assume running if in config
|
|
257
|
+
region: localInfo.region,
|
|
258
|
+
}
|
|
259
|
+
: undefined,
|
|
260
|
+
applicationCount: 0, // TODO: Calculate from local applications
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
return {
|
|
264
|
+
gateways,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
this.logger.error('Error listing gateways', error);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async deleteGateway(gatewayId, force = false) {
|
|
273
|
+
try {
|
|
274
|
+
// Attempt auto re-login if tokens are missing but credentials are available
|
|
275
|
+
await this.authService.attemptAutoRelogin();
|
|
276
|
+
this.restoreTokensFromApiClient();
|
|
277
|
+
const gatewayInfo = this.gatewayRepository.getGateway(gatewayId);
|
|
278
|
+
if (!gatewayInfo) {
|
|
279
|
+
throw new Error('Gateway not found in local configuration');
|
|
280
|
+
}
|
|
281
|
+
// Check if gateway has active applications (unless forced)
|
|
282
|
+
if (!force) {
|
|
283
|
+
const applications = await this.getGatewayApplications(gatewayId);
|
|
284
|
+
if (applications.length > 0) {
|
|
285
|
+
throw new Error(`Gateway has ${applications.length} active applications. Use --force to delete anyway.`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Terminate EC2 instance
|
|
289
|
+
const awsService = new aws_1.AWSService(this.configRepository.getAWSProfile(), gatewayInfo.region);
|
|
290
|
+
await awsService.terminateInstance(gatewayInfo.ec2InstanceId);
|
|
291
|
+
this.logger.info(`EC2 instance terminated: ${gatewayInfo.ec2InstanceId}`);
|
|
292
|
+
// Delete key pair
|
|
293
|
+
await awsService.deleteKeyPair(gatewayInfo.keyPairName);
|
|
294
|
+
this.logger.info(`Key pair deleted: ${gatewayInfo.keyPairName}`);
|
|
295
|
+
// Delete gateway device via API
|
|
296
|
+
await this.apiClient.deleteDevice(gatewayId);
|
|
297
|
+
// Remove from local repository
|
|
298
|
+
this.gatewayRepository.removeGateway(gatewayId);
|
|
299
|
+
this.logger.info('Gateway deleted successfully');
|
|
300
|
+
return {
|
|
301
|
+
success: true,
|
|
302
|
+
message: 'Gateway deleted successfully',
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
this.logger.error('Error deleting gateway', error);
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async getGatewayApplications(gatewayId) {
|
|
311
|
+
try {
|
|
312
|
+
// Attempt auto re-login if tokens are missing but credentials are available
|
|
313
|
+
await this.authService.attemptAutoRelogin();
|
|
314
|
+
this.restoreTokensFromApiClient();
|
|
315
|
+
const userConfig = this.configRepository.getConfig();
|
|
316
|
+
if (!userConfig.organizationId) {
|
|
317
|
+
throw new Error('No organization ID found. Please login first.');
|
|
318
|
+
}
|
|
319
|
+
// Get all applications from the organization
|
|
320
|
+
const applicationsResponse = await this.apiClient.getOrganizationApplications(userConfig.organizationId);
|
|
321
|
+
// Filter for applications that use this gateway
|
|
322
|
+
const gatewayApplications = applicationsResponse.applications.filter((app) => {
|
|
323
|
+
return app.deviceIds && app.deviceIds.includes(gatewayId);
|
|
324
|
+
});
|
|
325
|
+
return gatewayApplications;
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
this.logger.error('Error getting gateway applications', error);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
exports.GatewayServiceImpl = GatewayServiceImpl;
|
|
334
|
+
//# sourceMappingURL=GatewayService.js.map
|
|
@@ -0,0 +1,146 @@
|
|
|
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.ConfigManager = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const PathResolver_1 = require("../utils/PathResolver");
|
|
39
|
+
class ConfigManager {
|
|
40
|
+
constructor() {
|
|
41
|
+
// Use PathResolver to get the user data directory following XDG/platform conventions
|
|
42
|
+
const userDataPath = PathResolver_1.PathResolver.getUserDataPath();
|
|
43
|
+
this.configPath = PathResolver_1.PathResolver.getCliConfigPath();
|
|
44
|
+
// Ensure config directory exists
|
|
45
|
+
if (!fs.existsSync(userDataPath)) {
|
|
46
|
+
fs.mkdirSync(userDataPath, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
this.config = this.loadConfig();
|
|
49
|
+
}
|
|
50
|
+
loadConfig() {
|
|
51
|
+
try {
|
|
52
|
+
if (fs.existsSync(this.configPath)) {
|
|
53
|
+
const data = fs.readFileSync(this.configPath, 'utf8');
|
|
54
|
+
return JSON.parse(data);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.warn('Failed to load config, using defaults:', error);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
isFirstRun: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
saveConfig() {
|
|
65
|
+
try {
|
|
66
|
+
fs.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2));
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.warn('Failed to save config:', error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
getConfig() {
|
|
73
|
+
return { ...this.config };
|
|
74
|
+
}
|
|
75
|
+
updateConfig(updates) {
|
|
76
|
+
// Filter out undefined values to avoid overwriting existing config
|
|
77
|
+
const filteredUpdates = Object.fromEntries(Object.entries(updates).filter(([_, value]) => value !== undefined));
|
|
78
|
+
this.config = { ...this.config, ...filteredUpdates };
|
|
79
|
+
this.saveConfig();
|
|
80
|
+
}
|
|
81
|
+
isFirstRun() {
|
|
82
|
+
return this.config.isFirstRun;
|
|
83
|
+
}
|
|
84
|
+
setFirstRunComplete() {
|
|
85
|
+
this.updateConfig({ isFirstRun: false });
|
|
86
|
+
}
|
|
87
|
+
setEmail(email) {
|
|
88
|
+
this.updateConfig({ email });
|
|
89
|
+
}
|
|
90
|
+
getEmail() {
|
|
91
|
+
return this.config.email;
|
|
92
|
+
}
|
|
93
|
+
setAccountStatus(exists) {
|
|
94
|
+
this.updateConfig({
|
|
95
|
+
accountExists: exists,
|
|
96
|
+
lastLogin: new Date().toISOString()
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
hasAccount() {
|
|
100
|
+
return this.config.accountExists === true;
|
|
101
|
+
}
|
|
102
|
+
clearConfig() {
|
|
103
|
+
this.config = { isFirstRun: true };
|
|
104
|
+
this.saveConfig();
|
|
105
|
+
}
|
|
106
|
+
// Gateway management methods
|
|
107
|
+
addGateway(gatewayId, gatewayInfo) {
|
|
108
|
+
const gateways = this.config.gateways || {};
|
|
109
|
+
gateways[gatewayId] = {
|
|
110
|
+
...gatewayInfo,
|
|
111
|
+
createdAt: new Date().toISOString()
|
|
112
|
+
};
|
|
113
|
+
this.updateConfig({ gateways });
|
|
114
|
+
}
|
|
115
|
+
getGateway(gatewayId) {
|
|
116
|
+
return this.config.gateways?.[gatewayId];
|
|
117
|
+
}
|
|
118
|
+
getGateways() {
|
|
119
|
+
return this.config.gateways || {};
|
|
120
|
+
}
|
|
121
|
+
removeGateway(gatewayId) {
|
|
122
|
+
const gateways = { ...this.config.gateways };
|
|
123
|
+
delete gateways[gatewayId];
|
|
124
|
+
this.updateConfig({ gateways });
|
|
125
|
+
}
|
|
126
|
+
setAWSProfile(profile) {
|
|
127
|
+
this.updateConfig({ awsProfile: profile });
|
|
128
|
+
}
|
|
129
|
+
getAWSProfile() {
|
|
130
|
+
return this.config.awsProfile;
|
|
131
|
+
}
|
|
132
|
+
setAWSRegion(region) {
|
|
133
|
+
this.updateConfig({ awsRegion: region });
|
|
134
|
+
}
|
|
135
|
+
getAWSRegion() {
|
|
136
|
+
return this.config.awsRegion;
|
|
137
|
+
}
|
|
138
|
+
setDeviceType(deviceType) {
|
|
139
|
+
this.updateConfig({ deviceType });
|
|
140
|
+
}
|
|
141
|
+
getDeviceType() {
|
|
142
|
+
return this.config.deviceType;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.ConfigManager = ConfigManager;
|
|
146
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// AUTO-GENERATED FILE - DO NOT EDIT
|
|
3
|
+
// This file is copied from backend during build. Changes will be overwritten.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.convertAgentV2Status = convertAgentV2Status;
|
|
6
|
+
exports.convertLegacyCliStatus = convertLegacyCliStatus;
|
|
7
|
+
function convertAgentV2Status(input) {
|
|
8
|
+
const base = {
|
|
9
|
+
running: Boolean(input?.running),
|
|
10
|
+
health: input?.health || 'unknown',
|
|
11
|
+
lastPoll: String(input?.lastPoll || new Date().toISOString()),
|
|
12
|
+
applications: Array.isArray(input?.applications) ? input.applications : [],
|
|
13
|
+
deviceId: String(input?.deviceId || ''),
|
|
14
|
+
deviceType: (input?.deviceType === 'gateway' ? 'gateway' : 'serving'),
|
|
15
|
+
pid: typeof input?.pid === 'number' ? input.pid : 0,
|
|
16
|
+
uptime: typeof input?.uptime === 'number' ? input.uptime : 0,
|
|
17
|
+
version: String(input?.version || 'unknown'),
|
|
18
|
+
timestamp: typeof input?.timestamp === 'number' ? input.timestamp : Date.now(),
|
|
19
|
+
apiConnected: Boolean(input?.apiConnected),
|
|
20
|
+
apiAuthenticated: Boolean(input?.apiAuthenticated),
|
|
21
|
+
configurationValid: Boolean(input?.configurationValid)
|
|
22
|
+
};
|
|
23
|
+
if (input?.lastError !== undefined) {
|
|
24
|
+
base.lastError = String(input.lastError);
|
|
25
|
+
}
|
|
26
|
+
if (input?.installed !== undefined) {
|
|
27
|
+
base.installed = Boolean(input.installed);
|
|
28
|
+
}
|
|
29
|
+
return base;
|
|
30
|
+
}
|
|
31
|
+
function convertLegacyCliStatus(input) {
|
|
32
|
+
// Provide a best-effort mapper for legacy CLI status shapes
|
|
33
|
+
const base = {
|
|
34
|
+
running: Boolean(input?.running),
|
|
35
|
+
health: input?.health || 'unknown',
|
|
36
|
+
lastPoll: String(input?.lastPoll || new Date().toISOString()),
|
|
37
|
+
applications: Array.isArray(input?.applications) ? input.applications : [],
|
|
38
|
+
deviceId: String(input?.deviceId || ''),
|
|
39
|
+
deviceType: (input?.deviceType === 'gateway' ? 'gateway' : 'serving'),
|
|
40
|
+
pid: typeof input?.pid === 'number' ? input.pid : 0,
|
|
41
|
+
uptime: typeof input?.uptime === 'number' ? input.uptime : 0,
|
|
42
|
+
version: String(input?.version || 'unknown'),
|
|
43
|
+
timestamp: typeof input?.timestamp === 'number' ? input.timestamp : Date.now(),
|
|
44
|
+
apiConnected: Boolean(input?.apiConnected),
|
|
45
|
+
apiAuthenticated: Boolean(input?.apiAuthenticated),
|
|
46
|
+
configurationValid: Boolean(input?.configurationValid)
|
|
47
|
+
};
|
|
48
|
+
if (input?.lastError !== undefined) {
|
|
49
|
+
base.lastError = String(input.lastError);
|
|
50
|
+
}
|
|
51
|
+
if (input?.installed !== undefined) {
|
|
52
|
+
base.installed = Boolean(input.installed);
|
|
53
|
+
}
|
|
54
|
+
return base;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=UnifiedAgentStatus.js.map
|