@dainprotocol/cli 1.2.30 → 1.2.33
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/commands/build.js +1 -1
- package/dist/commands/deploy.js +5 -11
- package/dist/commands/dev.js +17 -6
- package/dist/commands/logs.js +13 -30
- package/dist/commands/status.js +6 -20
- package/dist/commands/undeploy.js +4 -19
- package/dist/index.js +0 -0
- package/dist/utils.js +100 -12
- package/package.json +10 -11
package/dist/commands/build.js
CHANGED
|
@@ -165,7 +165,7 @@ function copyWasmDependencies(bundlePath, nodeModulesPath, outDir) {
|
|
|
165
165
|
case 7: return [3 /*break*/, 9];
|
|
166
166
|
case 8:
|
|
167
167
|
error_1 = _a.sent();
|
|
168
|
-
|
|
168
|
+
(0, utils_1.logInfo)("Warning: Could not process WASM dependencies: ".concat(error_1));
|
|
169
169
|
return [3 /*break*/, 9];
|
|
170
170
|
case 9: return [2 /*return*/, copiedFiles];
|
|
171
171
|
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -77,7 +77,8 @@ function deploy(options) {
|
|
|
77
77
|
spinner.fail("No project found on platform linked to this repository.");
|
|
78
78
|
_d.label = 4;
|
|
79
79
|
case 4:
|
|
80
|
-
_d.trys.push([4,
|
|
80
|
+
_d.trys.push([4, 16, , 17]);
|
|
81
|
+
result = void 0;
|
|
81
82
|
if (!(projectId && repoName && branchName)) return [3 /*break*/, 7];
|
|
82
83
|
spinner.info("Deploying project using github repository...").start();
|
|
83
84
|
return [4 /*yield*/, (0, utils_1.fetchWithTimeout)((0, utils_1.joinUrl)(basePath, "/api/app/codegen/data/projects/".concat(projectId, "/start-deploy")), {
|
|
@@ -114,26 +115,19 @@ function deploy(options) {
|
|
|
114
115
|
case 13:
|
|
115
116
|
_c = _d.sent();
|
|
116
117
|
return [3 /*break*/, 14];
|
|
117
|
-
case 14:
|
|
118
|
-
if (!result) return [3 /*break*/, 16];
|
|
119
|
-
return [4 /*yield*/, updateDainJson(result)];
|
|
118
|
+
case 14: return [4 /*yield*/, updateDainJson(result)];
|
|
120
119
|
case 15:
|
|
121
120
|
_d.sent();
|
|
122
121
|
printDeploymentResult(result, spinner);
|
|
123
122
|
process.exit(0);
|
|
124
123
|
return [3 /*break*/, 17];
|
|
125
124
|
case 16:
|
|
126
|
-
spinner.fail("Deployment failed.");
|
|
127
|
-
process.exit(1);
|
|
128
|
-
_d.label = 17;
|
|
129
|
-
case 17: return [3 /*break*/, 19];
|
|
130
|
-
case 18:
|
|
131
125
|
error_1 = _d.sent();
|
|
132
126
|
spinner.fail("Deployment failed.");
|
|
133
127
|
(0, utils_1.logError)("Error during deployment: ", error_1);
|
|
134
128
|
process.exit(1);
|
|
135
|
-
return [3 /*break*/,
|
|
136
|
-
case
|
|
129
|
+
return [3 /*break*/, 17];
|
|
130
|
+
case 17: return [2 /*return*/];
|
|
137
131
|
}
|
|
138
132
|
});
|
|
139
133
|
});
|
package/dist/commands/dev.js
CHANGED
|
@@ -67,6 +67,7 @@ var tunnelUrl = null;
|
|
|
67
67
|
var isFirstStart = true;
|
|
68
68
|
var proxyServer = null;
|
|
69
69
|
var isCleaningUp = false;
|
|
70
|
+
var debounceTimer = null;
|
|
70
71
|
function isPortAvailable(port) {
|
|
71
72
|
return new Promise(function (resolve) {
|
|
72
73
|
var server = (0, net_1.createServer)()
|
|
@@ -78,6 +79,10 @@ function cleanup() {
|
|
|
78
79
|
if (isCleaningUp)
|
|
79
80
|
return;
|
|
80
81
|
isCleaningUp = true;
|
|
82
|
+
if (debounceTimer) {
|
|
83
|
+
clearTimeout(debounceTimer);
|
|
84
|
+
debounceTimer = null;
|
|
85
|
+
}
|
|
81
86
|
if (childProcess) {
|
|
82
87
|
childProcess.kill('SIGTERM');
|
|
83
88
|
childProcess = null;
|
|
@@ -172,7 +177,7 @@ function startProcess(mainFile, envVars, isRestart) {
|
|
|
172
177
|
}
|
|
173
178
|
function dev(options) {
|
|
174
179
|
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
-
var config, port, portNumber, runtime, mainFile, resolvedMain, envVars, proxySetup, watchPaths, dainDir, outFile, MFconfig_1,
|
|
180
|
+
var config, port, portNumber, runtime, mainFile, resolvedMain, envVars, proxySetup, watchPaths, dainDir, outFile, MFconfig_1, error_1;
|
|
176
181
|
return __generator(this, function (_a) {
|
|
177
182
|
switch (_a.label) {
|
|
178
183
|
case 0:
|
|
@@ -228,7 +233,14 @@ function dev(options) {
|
|
|
228
233
|
config['static-dir'] ? path_1.default.join(process.cwd(), config['static-dir']) : (0, utils_1.getStaticFilesPath)(),
|
|
229
234
|
].filter(function (p) { return fs_extra_1.default.existsSync(p); });
|
|
230
235
|
watcher = chokidar_1.default.watch(watchPaths, { ignored: /(^|[\/\\])\./, persistent: true, ignoreInitial: true });
|
|
231
|
-
watcher.on('change', function (changedPath) {
|
|
236
|
+
watcher.on('change', function (changedPath) {
|
|
237
|
+
if (debounceTimer)
|
|
238
|
+
clearTimeout(debounceTimer);
|
|
239
|
+
debounceTimer = setTimeout(function () {
|
|
240
|
+
(0, utils_1.logInfo)("File ".concat(changedPath, " changed. Restarting..."));
|
|
241
|
+
startProcess(mainFile, envVars, true);
|
|
242
|
+
}, 300);
|
|
243
|
+
});
|
|
232
244
|
(0, utils_1.logInfo)('Watching for file changes...');
|
|
233
245
|
return [3 /*break*/, 8];
|
|
234
246
|
case 5:
|
|
@@ -241,11 +253,10 @@ function dev(options) {
|
|
|
241
253
|
MFconfig_1 = { scriptPath: outFile, modules: true, port: parseInt(port, 10), log: new miniflare_1.Log(miniflare_1.LogLevel.DEBUG), liveReload: true };
|
|
242
254
|
mf = new miniflare_1.Miniflare(MFconfig_1);
|
|
243
255
|
(0, utils_1.logSuccess)("Miniflare server started on port ".concat(port));
|
|
244
|
-
debounceTimer_1 = null;
|
|
245
256
|
fs_extra_1.default.watch(dainDir, { recursive: true }, function (_eventType, filename) {
|
|
246
|
-
if (
|
|
247
|
-
clearTimeout(
|
|
248
|
-
|
|
257
|
+
if (debounceTimer)
|
|
258
|
+
clearTimeout(debounceTimer);
|
|
259
|
+
debounceTimer = setTimeout(function () { if (mf) {
|
|
249
260
|
mf.setOptions(MFconfig_1);
|
|
250
261
|
(0, utils_1.logInfo)("Build updated (".concat(filename, ")"));
|
|
251
262
|
} }, 300);
|
package/dist/commands/logs.js
CHANGED
|
@@ -56,6 +56,8 @@ var utils_1 = require("../utils");
|
|
|
56
56
|
var watchInterval = null;
|
|
57
57
|
var isShuttingDown = false;
|
|
58
58
|
function cleanup() {
|
|
59
|
+
if (isShuttingDown)
|
|
60
|
+
return;
|
|
59
61
|
isShuttingDown = true;
|
|
60
62
|
if (watchInterval) {
|
|
61
63
|
clearInterval(watchInterval);
|
|
@@ -64,40 +66,24 @@ function cleanup() {
|
|
|
64
66
|
}
|
|
65
67
|
function logs(options) {
|
|
66
68
|
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var config,
|
|
69
|
+
var config, ctx, spinner, result, error_1;
|
|
68
70
|
var _this = this;
|
|
69
71
|
return __generator(this, function (_a) {
|
|
70
72
|
switch (_a.label) {
|
|
71
73
|
case 0:
|
|
72
74
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
73
|
-
|
|
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.");
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
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
|
-
}
|
|
75
|
+
ctx = (0, utils_1.validatePlatformConfig)(config);
|
|
89
76
|
process.once("SIGINT", function () { cleanup(); process.exit(0); });
|
|
90
77
|
process.once("SIGTERM", function () { cleanup(); process.exit(0); });
|
|
91
|
-
logsUrl = (0, utils_1.buildPlatformUrl)(config, orgId, "logs");
|
|
92
78
|
spinner = (0, ora_1.default)("Fetching logs for project ".concat(config["project-id"], "...")).start();
|
|
93
79
|
_a.label = 1;
|
|
94
80
|
case 1:
|
|
95
81
|
_a.trys.push([1, 3, , 4]);
|
|
96
|
-
return [4 /*yield*/, fetchLogs(
|
|
82
|
+
return [4 /*yield*/, fetchLogs(ctx)];
|
|
97
83
|
case 2:
|
|
98
84
|
result = _a.sent();
|
|
99
85
|
spinner.stop();
|
|
100
|
-
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(result, deploymentId)));
|
|
86
|
+
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(result, ctx.deploymentId)));
|
|
101
87
|
if (options.watch) {
|
|
102
88
|
(0, utils_1.logInfo)("Watching for log updates (Ctrl+C to stop)...");
|
|
103
89
|
watchInterval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -110,11 +96,11 @@ function logs(options) {
|
|
|
110
96
|
_a.label = 1;
|
|
111
97
|
case 1:
|
|
112
98
|
_a.trys.push([1, 3, , 4]);
|
|
113
|
-
return [4 /*yield*/, fetchLogs(
|
|
99
|
+
return [4 /*yield*/, fetchLogs(ctx)];
|
|
114
100
|
case 2:
|
|
115
101
|
newResult = _a.sent();
|
|
116
102
|
process.stdout.write("\x1Bc");
|
|
117
|
-
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(newResult, deploymentId)));
|
|
103
|
+
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(newResult, ctx.deploymentId)));
|
|
118
104
|
return [3 /*break*/, 4];
|
|
119
105
|
case 3:
|
|
120
106
|
error_2 = _a.sent();
|
|
@@ -140,15 +126,12 @@ function logs(options) {
|
|
|
140
126
|
});
|
|
141
127
|
});
|
|
142
128
|
}
|
|
143
|
-
function fetchLogs(
|
|
129
|
+
function fetchLogs(ctx) {
|
|
144
130
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
131
|
var response;
|
|
146
132
|
return __generator(this, function (_a) {
|
|
147
133
|
switch (_a.label) {
|
|
148
|
-
case 0: return [4 /*yield*/, (0, utils_1.
|
|
149
|
-
method: "GET",
|
|
150
|
-
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(apiKey) },
|
|
151
|
-
})];
|
|
134
|
+
case 0: return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "logs")];
|
|
152
135
|
case 1:
|
|
153
136
|
response = _a.sent();
|
|
154
137
|
if (!response.ok) {
|
|
@@ -164,10 +147,10 @@ function formatProjectLogs(projectLogs, deploymentId) {
|
|
|
164
147
|
var _a = projectLogs.logs, logs_1 = _a === void 0 ? "" : _a, metadata = __rest(projectLogs, ["logs"]);
|
|
165
148
|
var formattedMetadata = Object.entries(metadata)
|
|
166
149
|
.map(function (_a) {
|
|
167
|
-
var _b;
|
|
168
150
|
var key = _a[0], value = _a[1];
|
|
169
|
-
var
|
|
170
|
-
|
|
151
|
+
var stringValue = String(value);
|
|
152
|
+
var formattedValue = stringValue.includes("T")
|
|
153
|
+
? new Date(stringValue).toLocaleString()
|
|
171
154
|
: value;
|
|
172
155
|
return "\u001B[36m".concat(key.replace(/([A-Z])/g, " $1").toLowerCase(), ":\u001B[0m ").concat(formattedValue);
|
|
173
156
|
})
|
package/dist/commands/status.js
CHANGED
|
@@ -44,35 +44,21 @@ var ora_1 = __importDefault(require("ora"));
|
|
|
44
44
|
var utils_1 = require("../utils");
|
|
45
45
|
function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var config,
|
|
47
|
+
var config, ctx, spinner, response, result, error_1;
|
|
48
48
|
return __generator(this, function (_a) {
|
|
49
49
|
switch (_a.label) {
|
|
50
50
|
case 0:
|
|
51
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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.");
|
|
58
|
-
process.exit(1);
|
|
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,
|
|
52
|
+
ctx = (0, utils_1.validatePlatformConfig)(config, {
|
|
53
|
+
deploymentId: preDefinedDeploymentId,
|
|
54
|
+
serviceId: preDefinedServiceId,
|
|
68
55
|
});
|
|
69
56
|
spinner = (0, ora_1.default)("Checking status for project ".concat(config["project-id"], "...")).start();
|
|
70
57
|
_a.label = 1;
|
|
71
58
|
case 1:
|
|
72
59
|
_a.trys.push([1, 4, , 5]);
|
|
73
|
-
return [4 /*yield*/, (0, utils_1.
|
|
74
|
-
|
|
75
|
-
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(apiKey) },
|
|
60
|
+
return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "status", "GET", {
|
|
61
|
+
environment: preDefinedEnvironmentName,
|
|
76
62
|
})];
|
|
77
63
|
case 2:
|
|
78
64
|
response = _a.sent();
|
|
@@ -44,32 +44,17 @@ var ora_1 = __importDefault(require("ora"));
|
|
|
44
44
|
var utils_1 = require("../utils");
|
|
45
45
|
function undeploy(options) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var config,
|
|
47
|
+
var config, ctx, spinner, response, error_1;
|
|
48
48
|
return __generator(this, function (_a) {
|
|
49
49
|
switch (_a.label) {
|
|
50
50
|
case 0:
|
|
51
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
-
|
|
53
|
-
|
|
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.");
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
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");
|
|
52
|
+
ctx = (0, utils_1.validatePlatformConfig)(config);
|
|
53
|
+
spinner = (0, ora_1.default)("Undeploying deployment ".concat(ctx.deploymentId, "...")).start();
|
|
66
54
|
_a.label = 1;
|
|
67
55
|
case 1:
|
|
68
56
|
_a.trys.push([1, 3, , 4]);
|
|
69
|
-
return [4 /*yield*/, (0, utils_1.
|
|
70
|
-
method: "DELETE",
|
|
71
|
-
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(apiKey) },
|
|
72
|
-
})];
|
|
57
|
+
return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "undeploy", "DELETE")];
|
|
73
58
|
case 2:
|
|
74
59
|
response = _a.sent();
|
|
75
60
|
if (!response.ok) {
|
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/utils.js
CHANGED
|
@@ -65,6 +65,9 @@ exports.extractOrgId = extractOrgId;
|
|
|
65
65
|
exports.resolveOrgId = resolveOrgId;
|
|
66
66
|
exports.fetchWithTimeout = fetchWithTimeout;
|
|
67
67
|
exports.buildPlatformUrl = buildPlatformUrl;
|
|
68
|
+
exports.validatePlatformConfig = validatePlatformConfig;
|
|
69
|
+
exports.platformRequest = platformRequest;
|
|
70
|
+
exports.createIdempotentCleanup = createIdempotentCleanup;
|
|
68
71
|
var fs_1 = __importDefault(require("fs"));
|
|
69
72
|
var path_1 = __importDefault(require("path"));
|
|
70
73
|
var client_1 = require("@dainprotocol/tunnel/client");
|
|
@@ -102,21 +105,32 @@ function parseDainApiKey(apiKey) {
|
|
|
102
105
|
var parts = apiKey.split("_");
|
|
103
106
|
if (parts.length < 5)
|
|
104
107
|
return null;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
var isOrgFormat = parts[2] === "org";
|
|
109
|
+
if (isOrgFormat) {
|
|
110
|
+
var orgId_1 = parts[3];
|
|
111
|
+
var isAgentKeyword = parts[4] === "agent";
|
|
112
|
+
var agentId_1 = parts[5];
|
|
108
113
|
var secret_1 = parts.slice(6).join("_");
|
|
109
|
-
|
|
114
|
+
if (!orgId_1 || !isAgentKeyword || !agentId_1 || !secret_1)
|
|
115
|
+
return null;
|
|
116
|
+
return { agentId: agentId_1, orgId: orgId_1, secret: secret_1 };
|
|
110
117
|
}
|
|
118
|
+
var agentId = parts[2];
|
|
119
|
+
var orgId = parts[3];
|
|
111
120
|
var secret = parts.slice(4).join("_");
|
|
112
|
-
|
|
121
|
+
if (!agentId || !orgId || !secret)
|
|
122
|
+
return null;
|
|
123
|
+
return { agentId: agentId, orgId: orgId, secret: secret };
|
|
113
124
|
}
|
|
114
125
|
function loadEnvFiles() {
|
|
115
|
-
[".env.local", ".env", ".env.development", ".env.production"]
|
|
126
|
+
var envFiles = [".env.local", ".env", ".env.development", ".env.production"];
|
|
127
|
+
for (var _i = 0, envFiles_1 = envFiles; _i < envFiles_1.length; _i++) {
|
|
128
|
+
var file = envFiles_1[_i];
|
|
116
129
|
var envPath = path_1.default.join(process.cwd(), file);
|
|
117
|
-
if (fs_1.default.existsSync(envPath))
|
|
130
|
+
if (fs_1.default.existsSync(envPath)) {
|
|
118
131
|
dotenv_1.default.config({ path: envPath });
|
|
119
|
-
|
|
132
|
+
}
|
|
133
|
+
}
|
|
120
134
|
}
|
|
121
135
|
function getDainConfig(configFile) {
|
|
122
136
|
loadEnvFiles();
|
|
@@ -154,7 +168,7 @@ function displayTunnelUrl(tunnelUrl) {
|
|
|
154
168
|
}
|
|
155
169
|
function setupProxy(port, apiKey, config) {
|
|
156
170
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
var spinner,
|
|
171
|
+
var spinner, client_2, tunnelUrl, error_1;
|
|
158
172
|
return __generator(this, function (_a) {
|
|
159
173
|
switch (_a.label) {
|
|
160
174
|
case 0:
|
|
@@ -162,12 +176,41 @@ function setupProxy(port, apiKey, config) {
|
|
|
162
176
|
_a.label = 1;
|
|
163
177
|
case 1:
|
|
164
178
|
_a.trys.push([1, 3, , 4]);
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
client_2 = new client_1.DainTunnel(config["tunnel-base-url"] || exports.DEFAULT_TUNNEL_BASE_URL, apiKey);
|
|
180
|
+
// Handle tunnel lifecycle events
|
|
181
|
+
client_2.on("disconnected", function () {
|
|
182
|
+
console.log(chalk_1.default.yellow("\n⚠ Tunnel disconnected. Attempting to reconnect..."));
|
|
183
|
+
});
|
|
184
|
+
client_2.on("reconnecting", function (_a) {
|
|
185
|
+
var attempt = _a.attempt, delay = _a.delay;
|
|
186
|
+
console.log(chalk_1.default.yellow(" Reconnection attempt ".concat(attempt, "/10 in ").concat(Math.round(delay / 1000), "s...")));
|
|
187
|
+
});
|
|
188
|
+
client_2.on("reconnected", function () {
|
|
189
|
+
console.log(chalk_1.default.green("✓ Tunnel reconnected successfully"));
|
|
190
|
+
});
|
|
191
|
+
client_2.on("error", function (error) {
|
|
192
|
+
console.error(chalk_1.default.red("\n\u2717 Tunnel error: ".concat(error.message)));
|
|
193
|
+
});
|
|
194
|
+
client_2.on("max_reconnect_attempts", function () {
|
|
195
|
+
console.error(chalk_1.default.red("\n✗ Tunnel failed to reconnect after 10 attempts."));
|
|
196
|
+
console.log(chalk_1.default.yellow(" Resetting and trying again..."));
|
|
197
|
+
// Reset and try one more time (resetReconnection added in tunnel 1.1.31)
|
|
198
|
+
if (typeof client_2.resetReconnection === "function") {
|
|
199
|
+
client_2.resetReconnection();
|
|
200
|
+
client_2.start(parseInt(port)).catch(function (err) {
|
|
201
|
+
console.error(chalk_1.default.red("\n\u2717 Unable to restore tunnel connection: ".concat(err.message)));
|
|
202
|
+
console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
return [4 /*yield*/, client_2.start(parseInt(port))];
|
|
167
210
|
case 2:
|
|
168
211
|
tunnelUrl = _a.sent();
|
|
169
212
|
spinner.succeed("Proxy setup complete");
|
|
170
|
-
return [2 /*return*/, { client:
|
|
213
|
+
return [2 /*return*/, { client: client_2, tunnelUrl: tunnelUrl }];
|
|
171
214
|
case 3:
|
|
172
215
|
error_1 = _a.sent();
|
|
173
216
|
spinner.fail(chalk_1.default.red("Error setting up proxy"));
|
|
@@ -228,3 +271,48 @@ function buildPlatformUrl(config, orgId, endpoint, overrides) {
|
|
|
228
271
|
var serviceId = (overrides === null || overrides === void 0 ? void 0 : overrides.serviceId) || config["service-id"];
|
|
229
272
|
return joinUrl(baseUrl, "/codegen-deploy/".concat(endpoint, "/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment));
|
|
230
273
|
}
|
|
274
|
+
function validatePlatformConfig(config, overrides) {
|
|
275
|
+
var orgId = resolveOrgId(config);
|
|
276
|
+
var apiKey = config["api-key"];
|
|
277
|
+
var deploymentId = (overrides === null || overrides === void 0 ? void 0 : overrides.deploymentId) || config["deployment-id"];
|
|
278
|
+
var serviceId = (overrides === null || overrides === void 0 ? void 0 : overrides.serviceId) || config["service-id"];
|
|
279
|
+
if (!orgId) {
|
|
280
|
+
logError("Org ID not found. Ensure your API key or DAIN_ORG_ID is set.");
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
if (!deploymentId || !serviceId) {
|
|
284
|
+
logError("Deployment ID or service ID not found");
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
if (!apiKey) {
|
|
288
|
+
logError("API key not found");
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
return { config: config, orgId: orgId, apiKey: apiKey, deploymentId: deploymentId, serviceId: serviceId };
|
|
292
|
+
}
|
|
293
|
+
function platformRequest(ctx_1, endpoint_1) {
|
|
294
|
+
return __awaiter(this, arguments, void 0, function (ctx, endpoint, method, overrides) {
|
|
295
|
+
var url;
|
|
296
|
+
if (method === void 0) { method = "GET"; }
|
|
297
|
+
return __generator(this, function (_a) {
|
|
298
|
+
url = buildPlatformUrl(ctx.config, ctx.orgId, endpoint, {
|
|
299
|
+
deploymentId: ctx.deploymentId,
|
|
300
|
+
serviceId: ctx.serviceId,
|
|
301
|
+
environment: overrides === null || overrides === void 0 ? void 0 : overrides.environment,
|
|
302
|
+
});
|
|
303
|
+
return [2 /*return*/, fetchWithTimeout(url, {
|
|
304
|
+
method: method,
|
|
305
|
+
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(ctx.apiKey) },
|
|
306
|
+
})];
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function createIdempotentCleanup(cleanupFn) {
|
|
311
|
+
var hasRun = false;
|
|
312
|
+
return function idempotentCleanup() {
|
|
313
|
+
if (hasRun)
|
|
314
|
+
return;
|
|
315
|
+
hasRun = true;
|
|
316
|
+
cleanupFn();
|
|
317
|
+
};
|
|
318
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dainprotocol/cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.33",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,21 +10,14 @@
|
|
|
10
10
|
"bin": {
|
|
11
11
|
"dain": "./dist/index.js"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc && cp -r templates dist/",
|
|
15
|
-
"test": "jest",
|
|
16
|
-
"test:watch": "jest --watch",
|
|
17
|
-
"test:coverage": "jest --coverage",
|
|
18
|
-
"prepublishOnly": "pnpm run build && pnpm test"
|
|
19
|
-
},
|
|
20
13
|
"files": [
|
|
21
14
|
"dist",
|
|
22
15
|
"README.md"
|
|
23
16
|
],
|
|
24
17
|
"dependencies": {
|
|
25
18
|
"@ai-sdk/anthropic": "^0.0.50",
|
|
26
|
-
"@dainprotocol/service-sdk": "
|
|
27
|
-
"@dainprotocol/tunnel": "
|
|
19
|
+
"@dainprotocol/service-sdk": "2.0.80",
|
|
20
|
+
"@dainprotocol/tunnel": "1.1.33",
|
|
28
21
|
"@types/fs-extra": "^11.0.4",
|
|
29
22
|
"@types/localtunnel": "^2.0.4",
|
|
30
23
|
"ai": "^3.3.41",
|
|
@@ -47,5 +40,11 @@
|
|
|
47
40
|
"ts-jest": "^29.4.6",
|
|
48
41
|
"ts-node": "^10.9.2",
|
|
49
42
|
"typescript": "^5.9.3"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc && cp -r templates dist/",
|
|
46
|
+
"test": "jest",
|
|
47
|
+
"test:watch": "jest --watch",
|
|
48
|
+
"test:coverage": "jest --coverage"
|
|
50
49
|
}
|
|
51
|
-
}
|
|
50
|
+
}
|