@dainprotocol/cli 1.1.27 → 1.1.28

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.
@@ -47,62 +47,63 @@ var path_1 = __importDefault(require("path"));
47
47
  var archiver_1 = __importDefault(require("archiver"));
48
48
  var build_1 = __importDefault(require("./build"));
49
49
  var status_1 = __importDefault(require("./status"));
50
- var START_DEPLOY_URI = '/api/app/data/deployments/start-deploy';
50
+ var START_DEPLOY_URI = "/api/app/data/deployments/start-deploy";
51
51
  function deploy(options) {
52
52
  return __awaiter(this, void 0, void 0, function () {
53
- var config, spinner, basePath, deployPath, envArray, result, deploymentId, dainJson, dainJsonObject, error_1;
53
+ var config, spinner, basePath, deployPath, isProduction, environmentName, envArray, result, deploymentId, serviceId, dainJson, dainJsonObject, error_1;
54
54
  return __generator(this, function (_a) {
55
55
  switch (_a.label) {
56
56
  case 0:
57
57
  config = (0, utils_1.getDainConfig)(options.config);
58
- spinner = (0, ora_1.default)('Deploying project...').start();
59
- basePath = config['api-base-url'] || 'https://dain-platform-ochre.vercel.app';
58
+ spinner = (0, ora_1.default)("Deploying project...").start();
59
+ basePath = config["api-base-url"] || "https://dain-platform-ochre.vercel.app";
60
60
  deployPath = "".concat(basePath).concat(START_DEPLOY_URI);
61
+ isProduction = config["environment"] === "production";
62
+ environmentName = config["environment"] || "production";
61
63
  _a.label = 1;
62
64
  case 1:
63
- _a.trys.push([1, 9, , 10]);
65
+ _a.trys.push([1, 8, , 9]);
64
66
  return [4 /*yield*/, loadAndValidateEnvVariables()];
65
67
  case 2:
66
68
  envArray = _a.sent();
67
69
  return [4 /*yield*/, (0, build_1.default)({ config: options.config, deploy: true })];
68
70
  case 3:
69
71
  _a.sent();
70
- return [4 /*yield*/, deployAndPushFiles(deployPath, envArray)];
72
+ return [4 /*yield*/, deployAndPushFiles(deployPath, envArray, isProduction, environmentName)];
71
73
  case 4:
72
74
  result = _a.sent();
73
- deploymentId = result.deploymentId.replace('codegen-', '');
74
- return [4 /*yield*/, recursiveStatusUntilRunning(JSON.stringify(config), deploymentId)];
75
+ deploymentId = result.deploymentId;
76
+ serviceId = result.serviceId;
77
+ return [4 /*yield*/, fs_extra_1.default.readFile("./dain.json", "utf-8")];
75
78
  case 5:
76
- _a.sent();
77
- return [4 /*yield*/, fs_extra_1.default.readFile('./dain.json', 'utf-8')];
78
- case 6:
79
79
  dainJson = _a.sent();
80
80
  dainJsonObject = JSON.parse(dainJson);
81
- dainJsonObject['deployment-id'] = deploymentId;
82
- return [4 /*yield*/, fs_extra_1.default.writeFile('./dain.json', JSON.stringify(dainJsonObject, null, 2))];
83
- case 7:
81
+ dainJsonObject["deployment-id"] = deploymentId;
82
+ dainJsonObject["service-id"] = serviceId;
83
+ return [4 /*yield*/, fs_extra_1.default.writeFile("./dain.json", JSON.stringify(dainJsonObject, null, 2))];
84
+ case 6:
84
85
  _a.sent();
85
- console.log('\n-----------------------');
86
+ console.log("\n-----------------------");
86
87
  spinner.succeed("Deployment URL: ".concat(result.service.url));
87
88
  spinner.succeed("Deployment ID: ".concat(result.deploymentId));
88
- spinner.succeed('Deployment completed at: ' + new Date().toISOString());
89
- spinner.succeed('Deployment completed successfully.');
90
- spinner.info('You can access logs using `dain logs -w` command.');
91
- console.log('-----------------------');
89
+ spinner.succeed("Deployment completed at: " + new Date().toISOString());
90
+ spinner.succeed("Deployment completed successfully.");
91
+ spinner.info("You can access logs using `dain logs -w` command.");
92
+ console.log("-----------------------");
92
93
  return [4 /*yield*/, fetch(result.service.url, {
93
- method: 'GET',
94
+ method: "GET",
94
95
  })];
95
- case 8:
96
+ case 7:
96
97
  _a.sent();
97
98
  process.exit(0);
98
- return [3 /*break*/, 10];
99
- case 9:
99
+ return [3 /*break*/, 9];
100
+ case 8:
100
101
  error_1 = _a.sent();
101
- spinner.fail('Deployment failed.');
102
- (0, utils_1.logError)('Error during deployment: ', error_1);
102
+ spinner.fail("Deployment failed.");
103
+ (0, utils_1.logError)("Error during deployment: ", error_1);
103
104
  process.exit(1);
104
- return [3 /*break*/, 10];
105
- case 10: return [2 /*return*/];
105
+ return [3 /*break*/, 9];
106
+ case 9: return [2 /*return*/];
106
107
  }
107
108
  });
108
109
  });
@@ -117,11 +118,11 @@ function loadAndValidateEnvVariables() {
117
118
  case 1:
118
119
  envArray = _a.sent();
119
120
  if (envArray.length === 0) {
120
- (0, utils_1.logError)('No environment variables found. Please ensure your .env file is correctly set up.');
121
+ (0, utils_1.logError)("No environment variables found. Please ensure your .env file is correctly set up.");
121
122
  process.exit(1);
122
123
  }
123
- if (!envArray.some(function (env) { return env.name === 'DAIN_API_KEY'; })) {
124
- (0, utils_1.logError)('DAIN_API_KEY not found in environment variables. Please check your .env file.');
124
+ if (!envArray.some(function (env) { return env.name === "DAIN_API_KEY"; })) {
125
+ (0, utils_1.logError)("DAIN_API_KEY not found in environment variables. Please check your .env file.");
125
126
  process.exit(1);
126
127
  }
127
128
  return [2 /*return*/, envArray];
@@ -130,25 +131,27 @@ function loadAndValidateEnvVariables() {
130
131
  });
131
132
  }
132
133
  // Deploys and pushes files to the platform
133
- function deployAndPushFiles(startDeployUrl, envArray) {
134
+ function deployAndPushFiles(startDeployUrl, envArray, isProduction, environmentName) {
134
135
  return __awaiter(this, void 0, void 0, function () {
135
136
  var projectZip, projectZipBuffer, formData, response, errorText, result, error_2;
136
137
  return __generator(this, function (_a) {
137
138
  switch (_a.label) {
138
- case 0: return [4 /*yield*/, zipDirectory('./', 'project.zip')];
139
+ case 0: return [4 /*yield*/, zipDirectory("./", "project.zip")];
139
140
  case 1:
140
141
  projectZip = _a.sent();
141
142
  return [4 /*yield*/, fs_extra_1.default.readFile(projectZip)];
142
143
  case 2:
143
144
  projectZipBuffer = _a.sent();
144
145
  formData = new FormData();
145
- formData.append('array', JSON.stringify(envArray));
146
- formData.append('file', new Blob([projectZipBuffer]), 'project.zip');
146
+ formData.append("array", JSON.stringify(envArray));
147
+ formData.append("file", new Blob([projectZipBuffer]), "project.zip");
148
+ formData.append("isProduction", isProduction.toString());
149
+ formData.append("environment", environmentName);
147
150
  _a.label = 3;
148
151
  case 3:
149
152
  _a.trys.push([3, 8, , 9]);
150
153
  return [4 /*yield*/, fetch(startDeployUrl, {
151
- method: 'POST',
154
+ method: "POST",
152
155
  body: formData,
153
156
  })];
154
157
  case 4:
@@ -164,8 +167,8 @@ function deployAndPushFiles(startDeployUrl, envArray) {
164
167
  return [2 /*return*/, result];
165
168
  case 8:
166
169
  error_2 = _a.sent();
167
- (0, utils_1.logError)('Error during deployment and push files: ', error_2.stack);
168
- console.error('Detailed error:', error_2);
170
+ (0, utils_1.logError)("Error during deployment and push files: ", error_2.stack);
171
+ console.error("Detailed error:", error_2);
169
172
  process.exit(1);
170
173
  return [3 /*break*/, 9];
171
174
  case 9: return [2 /*return*/];
@@ -179,21 +182,21 @@ function loadEnvVariables() {
179
182
  var files, envFile, envContent;
180
183
  return __generator(this, function (_a) {
181
184
  switch (_a.label) {
182
- case 0: return [4 /*yield*/, fs_extra_1.default.readdir('./')];
185
+ case 0: return [4 /*yield*/, fs_extra_1.default.readdir("./")];
183
186
  case 1:
184
187
  files = _a.sent();
185
- envFile = files.find(function (file) { return file === '.env'; });
188
+ envFile = files.find(function (file) { return file === ".env"; });
186
189
  if (!envFile) {
187
- (0, utils_1.logError)('Environment file not found. Please create a .env file in the build directory.');
190
+ (0, utils_1.logError)("Environment file not found. Please create a .env file in the build directory.");
188
191
  process.exit(1);
189
192
  }
190
- return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join('./', envFile), 'utf-8')];
193
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join("./", envFile), "utf-8")];
191
194
  case 2:
192
195
  envContent = _a.sent();
193
196
  return [2 /*return*/, envContent
194
- .split('\n')
197
+ .split("\n")
195
198
  .map(function (line) {
196
- var _a = line.split('='), name = _a[0], value = _a[1];
199
+ var _a = line.split("="), name = _a[0], value = _a[1];
197
200
  return { name: name, value: value };
198
201
  })
199
202
  .filter(function (env) { return env.name && env.value; })];
@@ -207,33 +210,33 @@ function zipDirectory(sourceDir, outputZip) {
207
210
  return __generator(this, function (_a) {
208
211
  return [2 /*return*/, new Promise(function (resolve, reject) {
209
212
  var output = fs_extra_1.default.createWriteStream(outputZip);
210
- var archive = (0, archiver_1.default)('zip', { zlib: { level: 9 } });
211
- output.on('close', function () { return resolve(outputZip); });
212
- archive.on('error', function (err) {
213
- (0, utils_1.logError)('Error during zipping the directory: ', err);
213
+ var archive = (0, archiver_1.default)("zip", { zlib: { level: 9 } });
214
+ output.on("close", function () { return resolve(outputZip); });
215
+ archive.on("error", function (err) {
216
+ (0, utils_1.logError)("Error during zipping the directory: ", err);
214
217
  reject(err);
215
218
  });
216
219
  archive.pipe(output);
217
- archive.glob('**/*', { ignore: ['node_modules/**', 'project.zip'] });
220
+ archive.glob("**/*", { ignore: ["node_modules/**", "project.zip"] });
218
221
  archive.finalize();
219
222
  })];
220
223
  });
221
224
  });
222
225
  }
223
- var recursiveStatusUntilRunning = function (config, deploymentId) { return __awaiter(void 0, void 0, void 0, function () {
226
+ var recursiveStatusUntilRunning = function (config, deploymentId, environmentName, serviceId) { return __awaiter(void 0, void 0, void 0, function () {
224
227
  var statusResult;
225
228
  return __generator(this, function (_a) {
226
229
  switch (_a.label) {
227
- case 0: return [4 /*yield*/, (0, status_1.default)({}, deploymentId)];
230
+ case 0: return [4 /*yield*/, (0, status_1.default)({}, deploymentId, environmentName, serviceId)];
228
231
  case 1:
229
232
  statusResult = _a.sent();
230
- if (statusResult.status === 'RUNNING') {
233
+ if (statusResult.status === "RUNNING") {
231
234
  return [2 /*return*/];
232
235
  }
233
236
  return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 15000); })];
234
237
  case 2:
235
238
  _a.sent();
236
- return [4 /*yield*/, recursiveStatusUntilRunning(config, deploymentId)];
239
+ return [4 /*yield*/, recursiveStatusUntilRunning(config, deploymentId, environmentName, serviceId)];
237
240
  case 3:
238
241
  _a.sent();
239
242
  return [2 /*return*/];
@@ -61,13 +61,13 @@ function logs(options_1) {
61
61
  switch (_b.label) {
62
62
  case 0:
63
63
  config = (0, utils_1.getDainConfig)(options.config);
64
- orgId = 'hackathon';
64
+ orgId = "hackathon";
65
65
  _a = initializeConfig(config, orgId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, logsUrl = _a.logsUrl;
66
66
  if (!orgId || !deploymentId) {
67
- (0, utils_1.logError)('Org ID or deployment ID not found');
67
+ (0, utils_1.logError)("Org ID or deployment ID not found");
68
68
  return [2 /*return*/];
69
69
  }
70
- spinner = (0, ora_1.default)("Fetching logs for project ".concat(config['project-id'], "...")).start();
70
+ spinner = (0, ora_1.default)("Fetching logs for project ".concat(config["project-id"], "...")).start();
71
71
  _b.label = 1;
72
72
  case 1:
73
73
  _b.trys.push([1, 3, 4, 5]);
@@ -78,7 +78,7 @@ function logs(options_1) {
78
78
  formatLogs = formatProjectLogs(result, deploymentId);
79
79
  if (isWatching) {
80
80
  // clear terminal before printing logs when watching
81
- process.stdout.write('\x1Bc');
81
+ process.stdout.write("\x1Bc");
82
82
  }
83
83
  (0, utils_1.logInfo)("Project logs: ".concat(formatLogs));
84
84
  if (options.watch) {
@@ -101,10 +101,12 @@ function logs(options_1) {
101
101
  });
102
102
  }
103
103
  var initializeConfig = function (config, orgId) {
104
- var baseUrl = config['platform-base-url'] || 'https://codegen-deploy-service.dainapp.com/';
105
- var apiKey = config['api-key'];
106
- var deploymentId = config['deployment-id'];
107
- var logsUrl = "".concat(baseUrl, "/codegen-deploy/logs/").concat(orgId, "/").concat(deploymentId);
104
+ var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
105
+ var apiKey = config["api-key"];
106
+ var deploymentId = config["deployment-id"];
107
+ var environment = config["environment"];
108
+ var serviceId = config["service-id"];
109
+ var logsUrl = "".concat(baseUrl, "/codegen-deploy/logs/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
108
110
  return { baseUrl: baseUrl, apiKey: apiKey, orgId: orgId, deploymentId: deploymentId, logsUrl: logsUrl };
109
111
  };
110
112
  var fetchLogs = function (logsUrl, apiKey) { return __awaiter(void 0, void 0, void 0, function () {
@@ -112,11 +114,11 @@ var fetchLogs = function (logsUrl, apiKey) { return __awaiter(void 0, void 0, vo
112
114
  return __generator(this, function (_a) {
113
115
  switch (_a.label) {
114
116
  case 0: return [4 /*yield*/, fetch(logsUrl, {
115
- method: 'GET',
117
+ method: "GET",
116
118
  headers: {
117
- 'Content-Type': 'application/json',
118
- 'X-DAIN-SIGNATORY-ADDRESS': 'TODO: X-DAIN-SIGNATORY-ADDRESS',
119
- 'X-DAIN-SIGNATURE': 'TODO: X-DAIN-SIGNATORY-SIGNATURE',
119
+ "Content-Type": "application/json",
120
+ "X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
121
+ "X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
120
122
  Authorization: "Bearer ".concat(apiKey),
121
123
  },
122
124
  })];
@@ -131,12 +133,12 @@ var fetchLogs = function (logsUrl, apiKey) { return __awaiter(void 0, void 0, vo
131
133
  });
132
134
  }); };
133
135
  var handleError = function (spinner, error) {
134
- spinner.fail('Failed to retrieve project logs.');
135
- (0, utils_1.logError)('Error during log fetch', error);
136
+ spinner.fail("Failed to retrieve project logs.");
137
+ (0, utils_1.logError)("Error during log fetch", error);
136
138
  };
137
139
  var formatProjectLogs = function (projectLogs, deploymentId) {
138
140
  try {
139
- var _a = projectLogs.logs, logs_1 = _a === void 0 ? '' : _a, metadata = __rest(projectLogs, ["logs"]);
141
+ var _a = projectLogs.logs, logs_1 = _a === void 0 ? "" : _a, metadata = __rest(projectLogs, ["logs"]);
140
142
  var formatDate_1 = function (dateString) {
141
143
  try {
142
144
  return new Date(dateString).toLocaleString();
@@ -149,23 +151,23 @@ var formatProjectLogs = function (projectLogs, deploymentId) {
149
151
  .map(function (_a) {
150
152
  var _b;
151
153
  var key = _a[0], value = _a[1];
152
- var formattedValue = ((_b = value === null || value === void 0 ? void 0 : value.includes) === null || _b === void 0 ? void 0 : _b.call(value, 'T'))
154
+ var formattedValue = ((_b = value === null || value === void 0 ? void 0 : value.includes) === null || _b === void 0 ? void 0 : _b.call(value, "T"))
153
155
  ? formatDate_1(value)
154
156
  : value;
155
- var formattedKey = key.replace(/([A-Z])/g, ' $1').toLowerCase();
157
+ var formattedKey = key.replace(/([A-Z])/g, " $1").toLowerCase();
156
158
  return "\u001B[36m".concat(formattedKey, ":\u001B[0m ").concat(formattedValue);
157
159
  })
158
- .join('\n');
159
- var projectUrl = "\nurl: https://".concat(deploymentId.replace('codegen-', ''), "-agent.dainapp.com");
160
+ .join("\n");
161
+ var projectUrl = "\nurl: https://".concat(deploymentId.replace("codegen-", ""), "-agent.dainapp.com");
160
162
  var output = [
161
- '\n',
162
- '\x1b[1m=== Project ===\x1b[0m',
163
+ "\n",
164
+ "\x1b[1m=== Project ===\x1b[0m",
163
165
  formattedMetadata,
164
166
  projectUrl,
165
- '\n\x1b[1m=== Logs ===\x1b[0m',
167
+ "\n\x1b[1m=== Logs ===\x1b[0m",
166
168
  logs_1,
167
169
  ];
168
- return output.join('\n');
170
+ return output.join("\n");
169
171
  }
170
172
  catch (error) {
171
173
  return "Error formatting logs: ".concat(error.message);
@@ -42,29 +42,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.default = status;
43
43
  var ora_1 = __importDefault(require("ora"));
44
44
  var utils_1 = require("../utils");
45
- function status(options, preDefinedDeploymentId) {
45
+ function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
46
46
  return __awaiter(this, void 0, void 0, function () {
47
47
  var config, orgId, _a, apiKey, deploymentId, statusUrl, spinner, response, result, error_1;
48
48
  return __generator(this, function (_b) {
49
49
  switch (_b.label) {
50
50
  case 0:
51
51
  config = (0, utils_1.getDainConfig)(options.config);
52
- orgId = 'hackathon';
53
- _a = initializeConfig(config, orgId, preDefinedDeploymentId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, statusUrl = _a.statusUrl;
52
+ orgId = "hackathon";
53
+ _a = initializeConfig(config, orgId, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, statusUrl = _a.statusUrl;
54
54
  if (!orgId || !deploymentId) {
55
- (0, utils_1.logError)('Org ID or deployment ID not found');
55
+ (0, utils_1.logError)("Org ID or deployment ID not found");
56
56
  return [2 /*return*/];
57
57
  }
58
- spinner = (0, ora_1.default)("Checking status for project ".concat(config['project-id'], "...")).start();
58
+ spinner = (0, ora_1.default)("Checking status for project ".concat(config["project-id"], "...")).start();
59
59
  _b.label = 1;
60
60
  case 1:
61
61
  _b.trys.push([1, 4, , 5]);
62
62
  return [4 /*yield*/, fetch(statusUrl, {
63
- method: 'GET',
63
+ method: "GET",
64
64
  headers: {
65
- 'Content-Type': 'application/json',
66
- 'X-DAIN-SIGNATORY-ADDRESS': 'TODO: X-DAIN-SIGNATORY-ADDRESS',
67
- 'X-DAIN-SIGNATURE': 'TODO: X-DAIN-SIGNATORY-SIGNATURE',
65
+ "Content-Type": "application/json",
66
+ "X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
67
+ "X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
68
68
  Authorization: "Bearer ".concat(apiKey),
69
69
  },
70
70
  })];
@@ -76,15 +76,15 @@ function status(options, preDefinedDeploymentId) {
76
76
  return [4 /*yield*/, response.json()];
77
77
  case 3:
78
78
  result = _b.sent();
79
- spinner.info('Status: ' + result.message);
79
+ spinner.info("Status: " + result.message);
80
80
  if (!preDefinedDeploymentId) {
81
81
  process.exit(0);
82
82
  }
83
83
  return [2 /*return*/, result];
84
84
  case 4:
85
85
  error_1 = _b.sent();
86
- spinner.fail('Failed to retrieve project status.');
87
- (0, utils_1.logError)('Error during status check', error_1);
86
+ spinner.fail("Failed to retrieve project status.");
87
+ (0, utils_1.logError)("Error during status check", error_1);
88
88
  process.exit(1);
89
89
  return [3 /*break*/, 5];
90
90
  case 5: return [2 /*return*/];
@@ -92,11 +92,13 @@ function status(options, preDefinedDeploymentId) {
92
92
  });
93
93
  });
94
94
  }
95
- var initializeConfig = function (config, orgId, preDefinedDeploymentId) {
96
- var baseUrl = config['platform-base-url'] || 'https://codegen-deploy-service.dainapp.com/';
97
- var apiKey = config['api-key'];
95
+ var initializeConfig = function (config, orgId, preDefinedDeploymentId, preDefinedEnvironment, preDefinedServiceId) {
96
+ var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
97
+ var apiKey = config["api-key"];
98
98
  var orgIdToBeUsed = orgId || (0, utils_1.extractOrgId)(apiKey);
99
- var deploymentId = preDefinedDeploymentId || config['deployment-id'];
100
- var statusUrl = "".concat(baseUrl, "/codegen-deploy/status/").concat(orgIdToBeUsed, "/").concat(deploymentId);
99
+ var deploymentId = preDefinedDeploymentId || config["deployment-id"];
100
+ var environment = preDefinedEnvironment || config["environment"];
101
+ var serviceId = preDefinedServiceId || config["service-id"];
102
+ var statusUrl = "".concat(baseUrl, "/codegen-deploy/status/").concat(orgIdToBeUsed, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
101
103
  return { baseUrl: baseUrl, apiKey: apiKey, orgIdToBeUsed: orgIdToBeUsed, deploymentId: deploymentId, statusUrl: statusUrl };
102
104
  };
@@ -49,22 +49,22 @@ function undeploy(options) {
49
49
  switch (_b.label) {
50
50
  case 0:
51
51
  config = (0, utils_1.getDainConfig)(options.config);
52
- spinner = (0, ora_1.default)("Undeploying deployment ".concat(config['deployment-id'], "...")).start();
52
+ spinner = (0, ora_1.default)("Undeploying deployment ".concat(config["deployment-id"], "...")).start();
53
53
  _b.label = 1;
54
54
  case 1:
55
55
  _b.trys.push([1, 3, 4, 5]);
56
- orgId = 'hackathon';
56
+ orgId = "hackathon";
57
57
  _a = initializeConfig(config, orgId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, undeployUrl = _a.undeployUrl;
58
58
  if (!orgId || !deploymentId) {
59
- (0, utils_1.logError)('Org ID or deployment ID not found');
59
+ (0, utils_1.logError)("Org ID or deployment ID not found");
60
60
  return [2 /*return*/];
61
61
  }
62
62
  return [4 /*yield*/, fetch(undeployUrl, {
63
- method: 'DELETE',
63
+ method: "DELETE",
64
64
  headers: {
65
- 'Content-Type': 'application/json',
66
- 'X-DAIN-SIGNATORY-ADDRESS': 'TODO: X-DAIN-SIGNATORY-ADDRESS',
67
- 'X-DAIN-SIGNATURE': 'TODO: X-DAIN-SIGNATORY-SIGNATURE',
65
+ "Content-Type": "application/json",
66
+ "X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
67
+ "X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
68
68
  Authorization: "Bearer ".concat(apiKey),
69
69
  },
70
70
  })];
@@ -73,13 +73,13 @@ function undeploy(options) {
73
73
  if (!response.ok) {
74
74
  throw new Error("Undeployment failed: ".concat(response.statusText));
75
75
  }
76
- spinner.succeed('Undeployment completed successfully.');
76
+ spinner.succeed("Undeployment completed successfully.");
77
77
  spinner.info("Undeployment completed with status code: ".concat(response.status));
78
78
  return [3 /*break*/, 5];
79
79
  case 3:
80
80
  error_1 = _b.sent();
81
- spinner.fail('Failed to undeploy project.');
82
- (0, utils_1.logError)('Error during undeployment', error_1);
81
+ spinner.fail("Failed to undeploy project.");
82
+ (0, utils_1.logError)("Error during undeployment", error_1);
83
83
  process.exit(1);
84
84
  return [3 /*break*/, 5];
85
85
  case 4:
@@ -92,10 +92,12 @@ function undeploy(options) {
92
92
  });
93
93
  }
94
94
  var initializeConfig = function (config, orgId) {
95
- var baseUrl = config['platform-base-url'] || 'https://codegen-deploy-service.dainapp.com/';
96
- var apiKey = config['api-key'];
95
+ var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
96
+ var apiKey = config["api-key"];
97
97
  var orgIdToBeUsed = orgId || (0, utils_1.extractOrgId)(apiKey);
98
- var deploymentId = config['deployment-id'];
99
- var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgIdToBeUsed, "/").concat(deploymentId);
98
+ var deploymentId = config["deployment-id"];
99
+ var environment = config["environment"];
100
+ var serviceId = config["service-id"];
101
+ var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgIdToBeUsed, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
100
102
  return { baseUrl: baseUrl, apiKey: apiKey, orgIdToBeUsed: orgIdToBeUsed, deploymentId: deploymentId, undeployUrl: undeployUrl };
101
103
  };
@@ -7,5 +7,6 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///tunnel.dain-local.com",
10
- "deployment-id": ""
10
+ "deployment-id": "",
11
+ "service-id": ""
11
12
  }
package/dist/utils.js CHANGED
@@ -54,7 +54,7 @@ var ora_1 = __importDefault(require("ora"));
54
54
  var chalk_1 = __importDefault(require("chalk"));
55
55
  var dotenv_1 = __importDefault(require("dotenv"));
56
56
  function loadEnvFiles() {
57
- var envFiles = ['.env.local', '.env', '.env.development', '.env.production'];
57
+ var envFiles = [".env.local", ".env", ".env.development", ".env.production"];
58
58
  envFiles.forEach(function (file) {
59
59
  var envPath = path_1.default.join(process.cwd(), file);
60
60
  if (fs_1.default.existsSync(envPath)) {
@@ -64,37 +64,34 @@ function loadEnvFiles() {
64
64
  }
65
65
  function getDainConfig(configFile) {
66
66
  loadEnvFiles(); // Loads all env files first
67
- var defaultConfigPath = path_1.default.join(process.cwd(), 'dain.json');
68
- var configPath = configFile
69
- ? path_1.default.join(process.cwd(), configFile)
70
- : defaultConfigPath;
71
- console.log('Config path: ', configPath);
67
+ var defaultConfigPath = path_1.default.join(process.cwd(), "dain.json");
68
+ var configPath = configFile ? path_1.default.join(process.cwd(), configFile) : defaultConfigPath;
69
+ console.log("Config path: ", configPath);
72
70
  if (!fs_1.default.existsSync(configPath)) {
73
71
  logError("Configuration file not found: ".concat(configPath));
74
72
  process.exit(1);
75
73
  }
76
74
  try {
77
- var configData = fs_1.default.readFileSync(configPath, 'utf8');
75
+ var configData = fs_1.default.readFileSync(configPath, "utf8");
78
76
  var config = JSON.parse(configData);
79
77
  // Validate required fields
80
- if (!config['main-file']) {
78
+ if (!config["main-file"]) {
81
79
  throw new Error("Configuration must include 'main-file'");
82
80
  }
83
81
  // Set default values for optional fields
84
- config['environment'] = config['environment'] || 'development';
85
- config['version'] = config['version'] || '1.0.0';
86
- config['out-dir'] = config['out-dir'] || 'dist'; // Default to 'dist' if not specified
87
- config['tunnel-base-url'] =
88
- config['tunnel-base-url'] || 'wss:///tunnel.dain-local.com'; // Default value if not specified
89
- config['runtime'] = config['runtime'] || 'node'; // Add this line
82
+ config["environment"] = config["environment"] || "development";
83
+ config["version"] = config["version"] || "1.0.0";
84
+ config["out-dir"] = config["out-dir"] || "dist"; // Default to 'dist' if not specified
85
+ config["tunnel-base-url"] = config["tunnel-base-url"] || "wss:///tunnel.dain-local.com"; // Default value if not specified
86
+ config["runtime"] = config["runtime"] || "node"; // Add this line
90
87
  // Handle API key
91
- if (!config['api-key'] ||
92
- config['api-key'] === 'env' ||
93
- config['api-key'] === 'MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY') {
94
- config['api-key'] = process.env.DAIN_API_KEY;
88
+ if (!config["api-key"] ||
89
+ config["api-key"] === "env" ||
90
+ config["api-key"] === "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY") {
91
+ config["api-key"] = process.env.DAIN_API_KEY;
95
92
  }
96
- if (!config['api-key']) {
97
- throw new Error('API key is not set in config or DAIN_API_KEY environment variable');
93
+ if (!config["api-key"]) {
94
+ throw new Error("API key is not set in config or DAIN_API_KEY environment variable");
98
95
  }
99
96
  return config;
100
97
  }
@@ -103,12 +100,12 @@ function getDainConfig(configFile) {
103
100
  }
104
101
  }
105
102
  function displayTunnelUrl(tunnelUrl) {
106
- var divider = chalk_1.default.green('------------------------------------------------------------');
107
- var header = chalk_1.default.green('Your service is available publicly at:');
103
+ var divider = chalk_1.default.green("------------------------------------------------------------");
104
+ var header = chalk_1.default.green("Your service is available publicly at:");
108
105
  var url = chalk_1.default.cyan.underline(tunnelUrl);
109
- var info = chalk_1.default.yellow('This service URL can be connected to by a DAIN client or assistant');
110
- var subInfo = chalk_1.default.yellow('(such as butterfly in development mode)');
111
- var warning = chalk_1.default.red('You should not visit this URL directly');
106
+ var info = chalk_1.default.yellow("This service URL can be connected to by a DAIN client or assistant");
107
+ var subInfo = chalk_1.default.yellow("(such as butterfly in development mode)");
108
+ var warning = chalk_1.default.red("You should not visit this URL directly");
112
109
  console.log("\n".concat(divider, "\n").concat(header, "\n").concat(url, "\n\n").concat(info, "\n").concat(subInfo, "\n\n").concat(warning, "\n").concat(divider, "\n"));
113
110
  }
114
111
  function setupProxy(port, apiKey, config) {
@@ -117,20 +114,20 @@ function setupProxy(port, apiKey, config) {
117
114
  return __generator(this, function (_a) {
118
115
  switch (_a.label) {
119
116
  case 0:
120
- spinner = (0, ora_1.default)('Setting up proxy...').start();
117
+ spinner = (0, ora_1.default)("Setting up proxy...").start();
121
118
  _a.label = 1;
122
119
  case 1:
123
120
  _a.trys.push([1, 3, , 4]);
124
- client = new client_1.DainTunnel(config['tunnel-base-url'] || 'wss:///tunnel.dain-local.com', apiKey);
121
+ client = new client_1.DainTunnel(config["tunnel-base-url"] || "wss:///tunnel.dain-local.com", apiKey);
125
122
  return [4 /*yield*/, client.start(parseInt(port))];
126
123
  case 2:
127
124
  tunnelUrl = _a.sent();
128
- spinner.succeed('Proxy setup complete');
125
+ spinner.succeed("Proxy setup complete");
129
126
  displayTunnelUrl(tunnelUrl);
130
127
  return [2 /*return*/, { client: client, tunnelUrl: tunnelUrl }];
131
128
  case 3:
132
129
  error_1 = _a.sent();
133
- spinner.fail(chalk_1.default.red('Error setting up proxy'));
130
+ spinner.fail(chalk_1.default.red("Error setting up proxy"));
134
131
  console.error(chalk_1.default.red(error_1));
135
132
  throw error_1;
136
133
  case 4: return [2 /*return*/];
@@ -151,9 +148,9 @@ function logInfo(message) {
151
148
  console.log(chalk_1.default.blue("\nInfo: ".concat(message)));
152
149
  }
153
150
  function getStaticFilesPath() {
154
- return path_1.default.join(process.cwd(), 'static');
151
+ return path_1.default.join(process.cwd(), "static");
155
152
  }
156
153
  function extractOrgId(apiKey) {
157
- var apiKeySplit = apiKey === null || apiKey === void 0 ? void 0 : apiKey.split('_');
158
- return apiKeySplit ? apiKeySplit[2] : '';
154
+ var apiKeySplit = apiKey === null || apiKey === void 0 ? void 0 : apiKey.split("_");
155
+ return apiKeySplit ? apiKeySplit[2] : "";
159
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.1.27",
3
+ "version": "1.1.28",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -7,5 +7,6 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///tunnel.dain-local.com",
10
- "deployment-id": ""
10
+ "deployment-id": "",
11
+ "service-id": ""
11
12
  }