@dainprotocol/cli 1.2.28 → 1.2.30
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/dist/__tests__/build.test.js +289 -0
- package/dist/__tests__/deploy.test.js +10 -27
- package/dist/__tests__/dev.test.js +189 -0
- package/dist/__tests__/init.test.js +290 -0
- package/dist/__tests__/integration.test.js +5 -22
- package/dist/__tests__/testchat.test.js +214 -0
- package/dist/__tests__/utils.test.js +324 -0
- package/dist/commands/build.js +28 -61
- package/dist/commands/deploy.js +91 -156
- package/dist/commands/dev.js +22 -83
- package/dist/commands/init.js +2 -9
- package/dist/commands/logs.js +46 -111
- package/dist/commands/start.js +15 -4
- package/dist/commands/status.js +25 -62
- package/dist/commands/undeploy.js +23 -64
- package/dist/index.js +0 -7
- package/dist/templates/default/dain.json +1 -1
- package/dist/utils.js +112 -37
- package/package.json +1 -1
package/dist/commands/logs.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -64,7 +53,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
64
53
|
exports.default = logs;
|
|
65
54
|
var ora_1 = __importDefault(require("ora"));
|
|
66
55
|
var utils_1 = require("../utils");
|
|
67
|
-
// Module state for cleanup
|
|
68
56
|
var watchInterval = null;
|
|
69
57
|
var isShuttingDown = false;
|
|
70
58
|
function cleanup() {
|
|
@@ -76,41 +64,44 @@ function cleanup() {
|
|
|
76
64
|
}
|
|
77
65
|
function logs(options) {
|
|
78
66
|
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
var config, orgId,
|
|
67
|
+
var config, orgId, apiKey, deploymentId, serviceId, logsUrl, spinner, result, error_1;
|
|
80
68
|
var _this = this;
|
|
81
|
-
return __generator(this, function (
|
|
82
|
-
switch (
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
83
71
|
case 0:
|
|
84
72
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
85
|
-
orgId =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
73
|
+
orgId = (0, utils_1.resolveOrgId)(config);
|
|
74
|
+
apiKey = config["api-key"];
|
|
75
|
+
deploymentId = config["deployment-id"];
|
|
76
|
+
serviceId = config["service-id"];
|
|
77
|
+
if (!orgId) {
|
|
78
|
+
(0, utils_1.logError)("Org ID not found. Ensure your API key or DAIN_ORG_ID is set.");
|
|
89
79
|
process.exit(1);
|
|
90
80
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
81
|
+
if (!deploymentId || !serviceId) {
|
|
82
|
+
(0, utils_1.logError)("Deployment ID or service ID not found");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
if (!apiKey) {
|
|
86
|
+
(0, utils_1.logError)("API key not found");
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
process.once("SIGINT", function () { cleanup(); process.exit(0); });
|
|
90
|
+
process.once("SIGTERM", function () { cleanup(); process.exit(0); });
|
|
91
|
+
logsUrl = (0, utils_1.buildPlatformUrl)(config, orgId, "logs");
|
|
100
92
|
spinner = (0, ora_1.default)("Fetching logs for project ".concat(config["project-id"], "...")).start();
|
|
101
|
-
|
|
93
|
+
_a.label = 1;
|
|
102
94
|
case 1:
|
|
103
|
-
|
|
95
|
+
_a.trys.push([1, 3, , 4]);
|
|
104
96
|
return [4 /*yield*/, fetchLogs(logsUrl, apiKey)];
|
|
105
97
|
case 2:
|
|
106
|
-
result =
|
|
98
|
+
result = _a.sent();
|
|
107
99
|
spinner.stop();
|
|
108
|
-
|
|
109
|
-
(0, utils_1.logInfo)("Project logs: ".concat(formattedLogs));
|
|
100
|
+
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(result, deploymentId)));
|
|
110
101
|
if (options.watch) {
|
|
111
102
|
(0, utils_1.logInfo)("Watching for log updates (Ctrl+C to stop)...");
|
|
112
103
|
watchInterval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
113
|
-
var newResult,
|
|
104
|
+
var newResult, error_2;
|
|
114
105
|
return __generator(this, function (_a) {
|
|
115
106
|
switch (_a.label) {
|
|
116
107
|
case 0:
|
|
@@ -122,9 +113,8 @@ function logs(options) {
|
|
|
122
113
|
return [4 /*yield*/, fetchLogs(logsUrl, apiKey)];
|
|
123
114
|
case 2:
|
|
124
115
|
newResult = _a.sent();
|
|
125
|
-
process.stdout.write("\x1Bc");
|
|
126
|
-
|
|
127
|
-
(0, utils_1.logInfo)("Project logs: ".concat(newFormattedLogs));
|
|
116
|
+
process.stdout.write("\x1Bc");
|
|
117
|
+
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(newResult, deploymentId)));
|
|
128
118
|
return [3 /*break*/, 4];
|
|
129
119
|
case 3:
|
|
130
120
|
error_2 = _a.sent();
|
|
@@ -140,8 +130,9 @@ function logs(options) {
|
|
|
140
130
|
}
|
|
141
131
|
return [3 /*break*/, 4];
|
|
142
132
|
case 3:
|
|
143
|
-
error_1 =
|
|
144
|
-
|
|
133
|
+
error_1 = _a.sent();
|
|
134
|
+
spinner.fail("Failed to retrieve project logs.");
|
|
135
|
+
(0, utils_1.logError)("Error during log fetch", error_1);
|
|
145
136
|
process.exit(1);
|
|
146
137
|
return [3 /*break*/, 4];
|
|
147
138
|
case 4: return [2 /*return*/];
|
|
@@ -149,98 +140,42 @@ function logs(options) {
|
|
|
149
140
|
});
|
|
150
141
|
});
|
|
151
142
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
var deploymentId = config["deployment-id"];
|
|
156
|
-
var environment = config["environment"];
|
|
157
|
-
var serviceId = config["service-id"];
|
|
158
|
-
var logsUrl = "".concat(baseUrl, "/codegen-deploy/logs/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
159
|
-
return { apiKey: apiKey, deploymentId: deploymentId, logsUrl: logsUrl };
|
|
160
|
-
};
|
|
161
|
-
var FETCH_TIMEOUT_MS = 30000;
|
|
162
|
-
function fetchWithTimeout(url_1, options_1) {
|
|
163
|
-
return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
|
|
164
|
-
var controller, timeoutId, response;
|
|
165
|
-
if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
|
|
143
|
+
function fetchLogs(url, apiKey) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var response;
|
|
166
146
|
return __generator(this, function (_a) {
|
|
167
147
|
switch (_a.label) {
|
|
168
|
-
case 0:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
148
|
+
case 0: return [4 /*yield*/, (0, utils_1.fetchWithTimeout)(url, {
|
|
149
|
+
method: "GET",
|
|
150
|
+
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(apiKey) },
|
|
151
|
+
})];
|
|
172
152
|
case 1:
|
|
173
|
-
_a.trys.push([1, , 3, 4]);
|
|
174
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
175
|
-
case 2:
|
|
176
153
|
response = _a.sent();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return [
|
|
181
|
-
case 4: return [2 /*return*/];
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
throw new Error("Log fetch failed: ".concat(response.status, " ").concat(response.statusText));
|
|
156
|
+
}
|
|
157
|
+
return [2 /*return*/, response.json()];
|
|
182
158
|
}
|
|
183
159
|
});
|
|
184
160
|
});
|
|
185
161
|
}
|
|
186
|
-
|
|
187
|
-
var response;
|
|
188
|
-
return __generator(this, function (_a) {
|
|
189
|
-
switch (_a.label) {
|
|
190
|
-
case 0: return [4 /*yield*/, fetchWithTimeout(logsUrl, {
|
|
191
|
-
method: "GET",
|
|
192
|
-
headers: {
|
|
193
|
-
"Content-Type": "application/json",
|
|
194
|
-
Authorization: "Bearer ".concat(apiKey),
|
|
195
|
-
},
|
|
196
|
-
})];
|
|
197
|
-
case 1:
|
|
198
|
-
response = _a.sent();
|
|
199
|
-
if (!response.ok) {
|
|
200
|
-
throw new Error("Log fetch failed: ".concat(response.status, " ").concat(response.statusText));
|
|
201
|
-
}
|
|
202
|
-
return [2 /*return*/, response.json()];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}); };
|
|
206
|
-
var handleError = function (spinner, error) {
|
|
207
|
-
spinner.fail("Failed to retrieve project logs.");
|
|
208
|
-
(0, utils_1.logError)("Error during log fetch", error);
|
|
209
|
-
};
|
|
210
|
-
var formatProjectLogs = function (projectLogs, deploymentId) {
|
|
162
|
+
function formatProjectLogs(projectLogs, deploymentId) {
|
|
211
163
|
try {
|
|
212
164
|
var _a = projectLogs.logs, logs_1 = _a === void 0 ? "" : _a, metadata = __rest(projectLogs, ["logs"]);
|
|
213
|
-
var formatDate_1 = function (dateString) {
|
|
214
|
-
try {
|
|
215
|
-
return new Date(dateString).toLocaleString();
|
|
216
|
-
}
|
|
217
|
-
catch (_a) {
|
|
218
|
-
return dateString;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
165
|
var formattedMetadata = Object.entries(metadata)
|
|
222
166
|
.map(function (_a) {
|
|
223
167
|
var _b;
|
|
224
168
|
var key = _a[0], value = _a[1];
|
|
225
169
|
var formattedValue = ((_b = value === null || value === void 0 ? void 0 : value.includes) === null || _b === void 0 ? void 0 : _b.call(value, "T"))
|
|
226
|
-
?
|
|
170
|
+
? new Date(value).toLocaleString()
|
|
227
171
|
: value;
|
|
228
|
-
|
|
229
|
-
return "\u001B[36m".concat(formattedKey, ":\u001B[0m ").concat(formattedValue);
|
|
172
|
+
return "\u001B[36m".concat(key.replace(/([A-Z])/g, " $1").toLowerCase(), ":\u001B[0m ").concat(formattedValue);
|
|
230
173
|
})
|
|
231
174
|
.join("\n");
|
|
232
175
|
var projectUrl = "\nurl: https://".concat(deploymentId.replace("codegen-", ""), "-agent.dainapp.com");
|
|
233
|
-
|
|
234
|
-
"\n",
|
|
235
|
-
"\x1b[1m=== Project ===\x1b[0m",
|
|
236
|
-
formattedMetadata,
|
|
237
|
-
projectUrl,
|
|
238
|
-
"\n\x1b[1m=== Logs ===\x1b[0m",
|
|
239
|
-
logs_1,
|
|
240
|
-
];
|
|
241
|
-
return output.join("\n");
|
|
176
|
+
return ["\n", "\x1b[1m=== Project ===\x1b[0m", formattedMetadata, projectUrl, "\n\x1b[1m=== Logs ===\x1b[0m", logs_1].join("\n");
|
|
242
177
|
}
|
|
243
178
|
catch (error) {
|
|
244
179
|
return "Error formatting logs: ".concat(error.message);
|
|
245
180
|
}
|
|
246
|
-
}
|
|
181
|
+
}
|
package/dist/commands/start.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.default = start;
|
|
4
7
|
var child_process_1 = require("child_process");
|
|
8
|
+
var fs_1 = __importDefault(require("fs"));
|
|
9
|
+
var path_1 = __importDefault(require("path"));
|
|
5
10
|
var utils_1 = require("../utils");
|
|
6
11
|
function start(options) {
|
|
12
|
+
var config = (0, utils_1.getDainConfig)();
|
|
7
13
|
process.env.PORT = options.port;
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
var mainFile = config['main-file'];
|
|
15
|
+
var outDir = config['out-dir'] || 'dist';
|
|
16
|
+
var outputFile = path_1.default.join(process.cwd(), outDir, "".concat(path_1.default.basename(mainFile, path_1.default.extname(mainFile)), ".js"));
|
|
17
|
+
var entryFile = fs_1.default.existsSync(outputFile) ? outputFile : mainFile;
|
|
18
|
+
if (entryFile === mainFile && mainFile.endsWith('.ts')) {
|
|
19
|
+
(0, utils_1.logError)("Build output not found: ".concat(outputFile, ". Run \"dain build\" first."));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
var child = (0, child_process_1.spawn)('node', [entryFile], { stdio: 'inherit' });
|
|
12
23
|
child.on('error', function (error) {
|
|
13
24
|
console.error("Error: ".concat(error.message));
|
|
14
25
|
process.exit(1);
|
package/dist/commands/status.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -53,70 +42,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
53
42
|
exports.default = status;
|
|
54
43
|
var ora_1 = __importDefault(require("ora"));
|
|
55
44
|
var utils_1 = require("../utils");
|
|
56
|
-
var FETCH_TIMEOUT_MS = 30000;
|
|
57
|
-
function fetchWithTimeout(url_1, options_1) {
|
|
58
|
-
return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
|
|
59
|
-
var controller, timeoutId, response;
|
|
60
|
-
if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
controller = new AbortController();
|
|
65
|
-
timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
|
|
66
|
-
_a.label = 1;
|
|
67
|
-
case 1:
|
|
68
|
-
_a.trys.push([1, , 3, 4]);
|
|
69
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
70
|
-
case 2:
|
|
71
|
-
response = _a.sent();
|
|
72
|
-
return [2 /*return*/, response];
|
|
73
|
-
case 3:
|
|
74
|
-
clearTimeout(timeoutId);
|
|
75
|
-
return [7 /*endfinally*/];
|
|
76
|
-
case 4: return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
45
|
function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
|
|
82
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var config, orgId,
|
|
84
|
-
return __generator(this, function (
|
|
85
|
-
switch (
|
|
47
|
+
var config, orgId, apiKey, deploymentId, serviceId, statusUrl, spinner, response, result, error_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
86
50
|
case 0:
|
|
87
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
88
|
-
orgId =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
orgId = (0, utils_1.resolveOrgId)(config);
|
|
53
|
+
apiKey = config["api-key"];
|
|
54
|
+
deploymentId = preDefinedDeploymentId || config["deployment-id"];
|
|
55
|
+
serviceId = preDefinedServiceId || config["service-id"];
|
|
56
|
+
if (!orgId) {
|
|
57
|
+
(0, utils_1.logError)("Org ID not found. Ensure your API key or DAIN_ORG_ID is set.");
|
|
92
58
|
process.exit(1);
|
|
93
59
|
}
|
|
60
|
+
if (!deploymentId || !serviceId) {
|
|
61
|
+
(0, utils_1.logError)("Deployment ID or service ID not found");
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
statusUrl = (0, utils_1.buildPlatformUrl)(config, orgId, "status", {
|
|
65
|
+
deploymentId: deploymentId,
|
|
66
|
+
environment: preDefinedEnvironmentName,
|
|
67
|
+
serviceId: serviceId,
|
|
68
|
+
});
|
|
94
69
|
spinner = (0, ora_1.default)("Checking status for project ".concat(config["project-id"], "...")).start();
|
|
95
|
-
|
|
70
|
+
_a.label = 1;
|
|
96
71
|
case 1:
|
|
97
|
-
|
|
98
|
-
return [4 /*yield*/, fetchWithTimeout(statusUrl, {
|
|
72
|
+
_a.trys.push([1, 4, , 5]);
|
|
73
|
+
return [4 /*yield*/, (0, utils_1.fetchWithTimeout)(statusUrl, {
|
|
99
74
|
method: "GET",
|
|
100
|
-
headers: {
|
|
101
|
-
"Content-Type": "application/json",
|
|
102
|
-
Authorization: "Bearer ".concat(apiKey),
|
|
103
|
-
},
|
|
75
|
+
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(apiKey) },
|
|
104
76
|
})];
|
|
105
77
|
case 2:
|
|
106
|
-
response =
|
|
78
|
+
response = _a.sent();
|
|
107
79
|
if (!response.ok) {
|
|
108
80
|
throw new Error("Status check failed: ".concat(response.status, " ").concat(response.statusText));
|
|
109
81
|
}
|
|
110
82
|
return [4 /*yield*/, response.json()];
|
|
111
83
|
case 3:
|
|
112
|
-
result =
|
|
84
|
+
result = _a.sent();
|
|
113
85
|
spinner.info("Status: " + result.message);
|
|
114
86
|
if (!preDefinedDeploymentId) {
|
|
115
87
|
process.exit(0);
|
|
116
88
|
}
|
|
117
89
|
return [2 /*return*/, result];
|
|
118
90
|
case 4:
|
|
119
|
-
error_1 =
|
|
91
|
+
error_1 = _a.sent();
|
|
120
92
|
spinner.fail("Failed to retrieve project status.");
|
|
121
93
|
(0, utils_1.logError)("Error during status check", error_1);
|
|
122
94
|
process.exit(1);
|
|
@@ -126,12 +98,3 @@ function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preD
|
|
|
126
98
|
});
|
|
127
99
|
});
|
|
128
100
|
}
|
|
129
|
-
var initializeConfig = function (config, orgId, preDefinedDeploymentId, preDefinedEnvironment, preDefinedServiceId) {
|
|
130
|
-
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
131
|
-
var apiKey = config["api-key"];
|
|
132
|
-
var deploymentId = preDefinedDeploymentId || config["deployment-id"];
|
|
133
|
-
var environment = preDefinedEnvironment || config["environment"];
|
|
134
|
-
var serviceId = preDefinedServiceId || config["service-id"];
|
|
135
|
-
var statusUrl = "".concat(baseUrl, "/codegen-deploy/status/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
136
|
-
return { apiKey: apiKey, deploymentId: deploymentId, statusUrl: statusUrl };
|
|
137
|
-
};
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -51,59 +40,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
40
|
};
|
|
52
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
42
|
exports.default = undeploy;
|
|
54
|
-
var utils_1 = require("../utils");
|
|
55
43
|
var ora_1 = __importDefault(require("ora"));
|
|
56
|
-
var
|
|
57
|
-
function fetchWithTimeout(url_1, options_1) {
|
|
58
|
-
return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
|
|
59
|
-
var controller, timeoutId, response;
|
|
60
|
-
if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
controller = new AbortController();
|
|
65
|
-
timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
|
|
66
|
-
_a.label = 1;
|
|
67
|
-
case 1:
|
|
68
|
-
_a.trys.push([1, , 3, 4]);
|
|
69
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
70
|
-
case 2:
|
|
71
|
-
response = _a.sent();
|
|
72
|
-
return [2 /*return*/, response];
|
|
73
|
-
case 3:
|
|
74
|
-
clearTimeout(timeoutId);
|
|
75
|
-
return [7 /*endfinally*/];
|
|
76
|
-
case 4: return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
44
|
+
var utils_1 = require("../utils");
|
|
81
45
|
function undeploy(options) {
|
|
82
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var config,
|
|
84
|
-
return __generator(this, function (
|
|
85
|
-
switch (
|
|
47
|
+
var config, orgId, apiKey, deploymentId, serviceId, spinner, undeployUrl, response, error_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
86
50
|
case 0:
|
|
87
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
(0, utils_1.logError)("Deployment ID not found");
|
|
52
|
+
orgId = (0, utils_1.resolveOrgId)(config);
|
|
53
|
+
apiKey = config["api-key"];
|
|
54
|
+
deploymentId = config["deployment-id"];
|
|
55
|
+
serviceId = config["service-id"];
|
|
56
|
+
spinner = (0, ora_1.default)("Undeploying deployment ".concat(deploymentId, "...")).start();
|
|
57
|
+
if (!orgId) {
|
|
58
|
+
(0, utils_1.logError)("Org ID not found. Ensure your API key or DAIN_ORG_ID is set.");
|
|
96
59
|
process.exit(1);
|
|
97
60
|
}
|
|
98
|
-
|
|
61
|
+
if (!deploymentId || !serviceId) {
|
|
62
|
+
(0, utils_1.logError)("Deployment ID or service ID not found");
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
undeployUrl = (0, utils_1.buildPlatformUrl)(config, orgId, "undeploy");
|
|
66
|
+
_a.label = 1;
|
|
67
|
+
case 1:
|
|
68
|
+
_a.trys.push([1, 3, , 4]);
|
|
69
|
+
return [4 /*yield*/, (0, utils_1.fetchWithTimeout)(undeployUrl, {
|
|
99
70
|
method: "DELETE",
|
|
100
|
-
headers: {
|
|
101
|
-
"Content-Type": "application/json",
|
|
102
|
-
Authorization: "Bearer ".concat(apiKey),
|
|
103
|
-
},
|
|
71
|
+
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(apiKey) },
|
|
104
72
|
})];
|
|
105
73
|
case 2:
|
|
106
|
-
response =
|
|
74
|
+
response = _a.sent();
|
|
107
75
|
if (!response.ok) {
|
|
108
76
|
throw new Error("Undeployment failed: ".concat(response.status, " ").concat(response.statusText));
|
|
109
77
|
}
|
|
@@ -111,7 +79,7 @@ function undeploy(options) {
|
|
|
111
79
|
process.exit(0);
|
|
112
80
|
return [3 /*break*/, 4];
|
|
113
81
|
case 3:
|
|
114
|
-
error_1 =
|
|
82
|
+
error_1 = _a.sent();
|
|
115
83
|
spinner.fail("Failed to undeploy project.");
|
|
116
84
|
(0, utils_1.logError)("Error during undeployment", error_1);
|
|
117
85
|
process.exit(1);
|
|
@@ -121,12 +89,3 @@ function undeploy(options) {
|
|
|
121
89
|
});
|
|
122
90
|
});
|
|
123
91
|
}
|
|
124
|
-
var initializeConfig = function (config, orgId) {
|
|
125
|
-
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
126
|
-
var apiKey = config["api-key"];
|
|
127
|
-
var deploymentId = config["deployment-id"];
|
|
128
|
-
var environment = config["environment"];
|
|
129
|
-
var serviceId = config["service-id"];
|
|
130
|
-
var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
131
|
-
return { apiKey: apiKey, deploymentId: deploymentId, undeployUrl: undeployUrl };
|
|
132
|
-
};
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var testchat_1 = __importDefault(require("./commands/testchat"));
|
|
|
14
14
|
var status_1 = __importDefault(require("./commands/status"));
|
|
15
15
|
var undeploy_1 = __importDefault(require("./commands/undeploy"));
|
|
16
16
|
var logs_1 = __importDefault(require("./commands/logs"));
|
|
17
|
-
var help_1 = __importDefault(require("./commands/help"));
|
|
18
17
|
var program = new commander_1.Command();
|
|
19
18
|
program
|
|
20
19
|
.name('dain')
|
|
@@ -91,12 +90,6 @@ program
|
|
|
91
90
|
.action(function (options) {
|
|
92
91
|
(0, logs_1.default)(options);
|
|
93
92
|
});
|
|
94
|
-
program
|
|
95
|
-
.command('help')
|
|
96
|
-
.description('Show the help')
|
|
97
|
-
.action(function () {
|
|
98
|
-
(0, help_1.default)();
|
|
99
|
-
});
|
|
100
93
|
program.parse(process.argv);
|
|
101
94
|
// Add a catch-all command for unknown commands
|
|
102
95
|
program.on('command:*', function () {
|