@dainprotocol/cli 1.2.34 → 1.2.36
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__/utils.test.js +11 -0
- package/dist/utils.js +19 -7
- package/package.json +3 -3
|
@@ -92,6 +92,17 @@ describe('joinUrl', function () {
|
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
|
+
describe('normalizeTunnelPublicUrl', function () {
|
|
96
|
+
test('keeps valid https tunnel URL unchanged', function () {
|
|
97
|
+
expect((0, utils_1.normalizeTunnelPublicUrl)('https://tunnel.dain-local.com/0_229')).toBe('https://tunnel.dain-local.com/0_229');
|
|
98
|
+
});
|
|
99
|
+
test('adds https protocol when tunnel URL is missing scheme', function () {
|
|
100
|
+
expect((0, utils_1.normalizeTunnelPublicUrl)('tunnel.dain-local.com/0_229')).toBe('https://tunnel.dain-local.com/0_229');
|
|
101
|
+
});
|
|
102
|
+
test('uses http for localhost tunnel URL without scheme', function () {
|
|
103
|
+
expect((0, utils_1.normalizeTunnelPublicUrl)('localhost:3001/0_229')).toBe('http://localhost:3001/0_229');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
95
106
|
describe('parseEnvContent', function () {
|
|
96
107
|
describe('basic parsing', function () {
|
|
97
108
|
test('parses simple key=value pairs', function () {
|
package/dist/utils.js
CHANGED
|
@@ -53,6 +53,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
53
53
|
exports.DEFAULT_API_BASE_URL = exports.DEFAULT_PLATFORM_BASE_URL = exports.DEFAULT_TUNNEL_BASE_URL = void 0;
|
|
54
54
|
exports.normalizeBaseUrl = normalizeBaseUrl;
|
|
55
55
|
exports.joinUrl = joinUrl;
|
|
56
|
+
exports.normalizeTunnelPublicUrl = normalizeTunnelPublicUrl;
|
|
56
57
|
exports.parseEnvContent = parseEnvContent;
|
|
57
58
|
exports.getDainConfig = getDainConfig;
|
|
58
59
|
exports.displayTunnelUrl = displayTunnelUrl;
|
|
@@ -91,6 +92,16 @@ function normalizeBaseUrl(value) {
|
|
|
91
92
|
function joinUrl(baseUrl, pathname) {
|
|
92
93
|
return "".concat(normalizeBaseUrl(baseUrl), "/").concat(pathname.replace(/^\/+/, ""));
|
|
93
94
|
}
|
|
95
|
+
function normalizeTunnelPublicUrl(tunnelUrl) {
|
|
96
|
+
var trimmed = tunnelUrl.trim();
|
|
97
|
+
if (!trimmed)
|
|
98
|
+
return trimmed;
|
|
99
|
+
if (/^https?:\/\//i.test(trimmed))
|
|
100
|
+
return normalizeBaseUrl(trimmed);
|
|
101
|
+
var likelyLocalhost = /^localhost[:/]|^127\./i.test(trimmed);
|
|
102
|
+
var protocol = likelyLocalhost ? "http://" : "https://";
|
|
103
|
+
return normalizeBaseUrl("".concat(protocol).concat(trimmed.replace(/^\/+/, "")));
|
|
104
|
+
}
|
|
94
105
|
function parseEnvContent(envContent) {
|
|
95
106
|
return Object.entries(dotenv_1.default.parse(envContent))
|
|
96
107
|
.map(function (_a) {
|
|
@@ -168,14 +179,14 @@ function displayTunnelUrl(tunnelUrl) {
|
|
|
168
179
|
}
|
|
169
180
|
function setupProxy(port, apiKey, config) {
|
|
170
181
|
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
-
var spinner, client_2, tunnelUrl, error_1;
|
|
172
|
-
return __generator(this, function (
|
|
173
|
-
switch (
|
|
182
|
+
var spinner, client_2, tunnelUrl, _a, error_1;
|
|
183
|
+
return __generator(this, function (_b) {
|
|
184
|
+
switch (_b.label) {
|
|
174
185
|
case 0:
|
|
175
186
|
spinner = (0, ora_1.default)("Setting up proxy...").start();
|
|
176
|
-
|
|
187
|
+
_b.label = 1;
|
|
177
188
|
case 1:
|
|
178
|
-
|
|
189
|
+
_b.trys.push([1, 3, , 4]);
|
|
179
190
|
client_2 = new client_1.DainTunnel(config["tunnel-base-url"] || exports.DEFAULT_TUNNEL_BASE_URL, apiKey);
|
|
180
191
|
// Handle tunnel lifecycle events
|
|
181
192
|
client_2.on("disconnected", function () {
|
|
@@ -206,13 +217,14 @@ function setupProxy(port, apiKey, config) {
|
|
|
206
217
|
console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
|
|
207
218
|
}
|
|
208
219
|
});
|
|
220
|
+
_a = normalizeTunnelPublicUrl;
|
|
209
221
|
return [4 /*yield*/, client_2.start(parseInt(port))];
|
|
210
222
|
case 2:
|
|
211
|
-
tunnelUrl = _a.sent();
|
|
223
|
+
tunnelUrl = _a.apply(void 0, [_b.sent()]);
|
|
212
224
|
spinner.succeed("Proxy setup complete");
|
|
213
225
|
return [2 /*return*/, { client: client_2, tunnelUrl: tunnelUrl }];
|
|
214
226
|
case 3:
|
|
215
|
-
error_1 =
|
|
227
|
+
error_1 = _b.sent();
|
|
216
228
|
spinner.fail(chalk_1.default.red("Error setting up proxy"));
|
|
217
229
|
console.error(chalk_1.default.red(error_1));
|
|
218
230
|
throw error_1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dainprotocol/cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.36",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ai-sdk/anthropic": "^0.0.50",
|
|
26
|
-
"@dainprotocol/service-sdk": "2.0.
|
|
27
|
-
"@dainprotocol/tunnel": "1.1.
|
|
26
|
+
"@dainprotocol/service-sdk": "2.0.82",
|
|
27
|
+
"@dainprotocol/tunnel": "1.1.35",
|
|
28
28
|
"@types/fs-extra": "^11.0.4",
|
|
29
29
|
"@types/localtunnel": "^2.0.4",
|
|
30
30
|
"ai": "^3.3.41",
|