@n42/cli 0.3.67 → 0.3.72
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/assets/discover.js +23 -7
- package/dist/assets/terminal.js +98 -24
- package/dist/n42 +1 -1
- package/package.json +1 -1
- package/src/assets/discover.js +23 -7
- package/src/assets/terminal.js +98 -24
package/package.json
CHANGED
package/src/assets/discover.js
CHANGED
|
@@ -51,6 +51,7 @@ function addDownloadLinkListener() {
|
|
|
51
51
|
function addSvgClickListener() {
|
|
52
52
|
const bubble = document.getElementById("bubble");
|
|
53
53
|
const svgEl = bubble.querySelector("svg");
|
|
54
|
+
const refId = bubble.dataset.uuid;
|
|
54
55
|
|
|
55
56
|
svgEl.addEventListener("click", function (e) {
|
|
56
57
|
const link = e.target.closest("a");
|
|
@@ -65,7 +66,8 @@ function addSvgClickListener() {
|
|
|
65
66
|
if (!url.startsWith("#")) {
|
|
66
67
|
terminal.open({
|
|
67
68
|
url: url,
|
|
68
|
-
method: "GET"
|
|
69
|
+
method: "GET",
|
|
70
|
+
refId
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
else {
|
|
@@ -79,7 +81,8 @@ function addSvgClickListener() {
|
|
|
79
81
|
|
|
80
82
|
terminal.show({
|
|
81
83
|
command: "trace",
|
|
82
|
-
run: true
|
|
84
|
+
run: true,
|
|
85
|
+
refId
|
|
83
86
|
});
|
|
84
87
|
break;
|
|
85
88
|
}
|
|
@@ -89,14 +92,26 @@ function addSvgClickListener() {
|
|
|
89
92
|
break;
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
case "BCARD": {
|
|
93
|
-
itemUrl = link.getAttribute("data-bcard-url");
|
|
95
|
+
case "BCARD-DIR": {
|
|
96
|
+
itemUrl = link.getAttribute("data-bcard-dir-url");
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case "BCARD-SMP": {
|
|
101
|
+
itemUrl = link.getAttribute("data-bcard-smp-url");
|
|
94
102
|
break;
|
|
95
103
|
}
|
|
96
104
|
|
|
97
105
|
case "NAPTR": {
|
|
98
106
|
const naptrUrl = link.getAttribute("data-naptr-url");
|
|
99
|
-
console.log("naptr: " + naptrUrl);
|
|
107
|
+
//console.log("naptr: " + naptrUrl);
|
|
108
|
+
|
|
109
|
+
terminal.show({
|
|
110
|
+
command: "parse naptr",
|
|
111
|
+
argument: naptrUrl,
|
|
112
|
+
run: true,
|
|
113
|
+
refId
|
|
114
|
+
});
|
|
100
115
|
break;
|
|
101
116
|
}
|
|
102
117
|
|
|
@@ -138,7 +153,8 @@ function addSvgClickListener() {
|
|
|
138
153
|
if (itemUrl && itemUrl.length) {
|
|
139
154
|
terminal.open({
|
|
140
155
|
url: itemUrl,
|
|
141
|
-
method: "GET"
|
|
156
|
+
method: "GET",
|
|
157
|
+
refId
|
|
142
158
|
});
|
|
143
159
|
}
|
|
144
160
|
}
|
|
@@ -179,7 +195,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
179
195
|
terminal = new Terminal({
|
|
180
196
|
title: "Terminal",
|
|
181
197
|
theme: "light",
|
|
182
|
-
pkgVersion: "0.3.
|
|
198
|
+
pkgVersion: "0.3.69"
|
|
183
199
|
});
|
|
184
200
|
|
|
185
201
|
addSvgClickListener();
|
package/src/assets/terminal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Terminal {
|
|
2
2
|
constructor(opts = {}) {
|
|
3
3
|
this.opts = {
|
|
4
|
-
title: "
|
|
4
|
+
title: "Terminal",
|
|
5
5
|
...opts,
|
|
6
6
|
};
|
|
7
7
|
|
|
@@ -9,6 +9,8 @@ class Terminal {
|
|
|
9
9
|
this._controller = null;
|
|
10
10
|
this._lastFocused = null;
|
|
11
11
|
|
|
12
|
+
this._argument = null;
|
|
13
|
+
|
|
12
14
|
this._history = [];
|
|
13
15
|
this._historyIndex = -1;
|
|
14
16
|
|
|
@@ -64,6 +66,8 @@ class Terminal {
|
|
|
64
66
|
this.overlay.classList.remove("hidden");
|
|
65
67
|
this.dialog.classList.remove("hidden");
|
|
66
68
|
|
|
69
|
+
this.title.textContent = `Discovery: ${req.refId}`;
|
|
70
|
+
|
|
67
71
|
this.input.value = `request -X ${req.method} ${req.url}`;
|
|
68
72
|
this.input.focus();
|
|
69
73
|
|
|
@@ -86,7 +90,9 @@ class Terminal {
|
|
|
86
90
|
this.overlay.classList.remove("hidden");
|
|
87
91
|
this.dialog.classList.remove("hidden");
|
|
88
92
|
|
|
89
|
-
this.title.textContent = `
|
|
93
|
+
this.title.textContent = `Discovery: ${input.refId}`;
|
|
94
|
+
|
|
95
|
+
this._argument = input.argument;
|
|
90
96
|
|
|
91
97
|
this.input.value = `${input.command}`;
|
|
92
98
|
this.input.focus();
|
|
@@ -132,6 +138,7 @@ class Terminal {
|
|
|
132
138
|
const cmd = `$ request ${this._getReqArgs(normalized)}`;
|
|
133
139
|
this._addHistory(cmd)
|
|
134
140
|
|
|
141
|
+
this._printLine("");
|
|
135
142
|
this._printColoredLine(cmd, this.colorBlue);
|
|
136
143
|
this._printLine("");
|
|
137
144
|
|
|
@@ -175,14 +182,14 @@ class Terminal {
|
|
|
175
182
|
if (normalized.body) this._printLine(`> (body ${this._byteLen(normalized.body)} bytes)`);
|
|
176
183
|
this._printLine("");
|
|
177
184
|
|
|
178
|
-
this.title.textContent = `
|
|
185
|
+
//this.title.textContent = `Request: ${normalized.method}`;
|
|
179
186
|
|
|
180
187
|
const res = await fetch(normalized.url, fetchInit);
|
|
181
188
|
|
|
182
189
|
const dt = (performance.now() - t0);
|
|
183
|
-
this.
|
|
190
|
+
this._printColoredLine(`< HTTP ${res.status} ${res.statusText} (${dt.toFixed(0)} ms)`, this.colorBrown);
|
|
184
191
|
|
|
185
|
-
res.headers.forEach((v, k) => this.
|
|
192
|
+
res.headers.forEach((v, k) => this._printColoredLine(`< ${k}: ${v}`, this.colorBrown));
|
|
186
193
|
this._printLine("");
|
|
187
194
|
|
|
188
195
|
const { text, truncated, bytesRead } = await this._readTextWithLimit(res, normalized.maxBytes);
|
|
@@ -193,15 +200,22 @@ class Terminal {
|
|
|
193
200
|
this._printRaw(text);
|
|
194
201
|
|
|
195
202
|
this._printLine("");
|
|
196
|
-
this.
|
|
203
|
+
this._printColoredLine(`[done]`, this.colorGreen);
|
|
204
|
+
|
|
197
205
|
this._setBusy(false);
|
|
206
|
+
|
|
198
207
|
return { status: res.status, headers: res.headers, body: text, truncated };
|
|
199
208
|
}
|
|
200
209
|
catch (err) {
|
|
201
|
-
|
|
210
|
+
//console.log(err);
|
|
211
|
+
|
|
212
|
+
//const name = err?.name || "error";
|
|
202
213
|
const msg = err?.message || String(err);
|
|
203
214
|
|
|
204
|
-
this.
|
|
215
|
+
this._printColoredLine(`[error]: ${msg}`, this.colorRed);
|
|
216
|
+
this._printLine("");
|
|
217
|
+
this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
|
|
218
|
+
|
|
205
219
|
this._setBusy(false);
|
|
206
220
|
|
|
207
221
|
return { status: 0, headers: new Headers(), body: "", error: msg };
|
|
@@ -297,18 +311,53 @@ class Terminal {
|
|
|
297
311
|
this._printHelp();
|
|
298
312
|
return;
|
|
299
313
|
}
|
|
314
|
+
|
|
315
|
+
if (cmd.startsWith("parse ")) {
|
|
316
|
+
const cmdParts = cmd.trim().split(/\s+/);
|
|
317
|
+
if (cmdParts.length < 2) {
|
|
318
|
+
this._printLine("");
|
|
319
|
+
this._printColoredLine("[error]: Unknown item.", this.colorRed);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const item = cmdParts[1].trim();
|
|
324
|
+
if (item) {
|
|
325
|
+
switch(item) {
|
|
326
|
+
case "naptr": {
|
|
327
|
+
const parts = this._argument.split(".");
|
|
328
|
+
const hash = parts[0];
|
|
329
|
+
const scheme = parts[1];
|
|
330
|
+
const env = parts[2];
|
|
331
|
+
const smlDomain = parts.slice(3).join(".");
|
|
332
|
+
|
|
333
|
+
this._printLine("");
|
|
334
|
+
this._printColoredLine("$ parse NAPTR domain", this.colorBlue);
|
|
335
|
+
this._printLine("");
|
|
336
|
+
|
|
337
|
+
this._printColoredLine(`Environment : ${env === "acc" ? "TEST" : "PROD"}`, this.colorPink);
|
|
338
|
+
this._printLine(`Participant scheme : ${scheme}`);
|
|
339
|
+
this._printLine(`Identifier hash : ${hash}`);
|
|
340
|
+
this._printLine(`${env === "acc" ? "SMK" : "SML"} domain : ${smlDomain}`);
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
300
347
|
|
|
301
348
|
if (cmd.startsWith("request ")) {
|
|
302
349
|
if (this.runningFromFile) {
|
|
303
350
|
this._addHistory(cmd);
|
|
304
351
|
|
|
352
|
+
this._printLine("");
|
|
305
353
|
this._printColoredLine(`$ ${cmd}`, this.colorBlue);
|
|
306
354
|
|
|
307
355
|
this._printLine("");
|
|
308
356
|
this._printColoredLine("[error]: CORS has blocked this request (the script is running from file://).", this.colorRed);
|
|
309
|
-
this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
|
|
310
357
|
this._printLine("");
|
|
311
358
|
|
|
359
|
+
this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
|
|
360
|
+
|
|
312
361
|
return;
|
|
313
362
|
}
|
|
314
363
|
// Parse: request [METHOD] <url>
|
|
@@ -327,9 +376,13 @@ class Terminal {
|
|
|
327
376
|
this._addHistory(cmd);
|
|
328
377
|
|
|
329
378
|
if (discoveryTrace) {
|
|
330
|
-
this.
|
|
331
|
-
this.
|
|
332
|
-
|
|
379
|
+
this._printLine("");
|
|
380
|
+
this._printColoredLine("$ trace", this.colorBlue);
|
|
381
|
+
this._printLine("");
|
|
382
|
+
|
|
383
|
+
this._printLine(this._jsonHighlight(discoveryTrace));
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
333
386
|
this._printColoredLine("[error]: Discovery trace missing", this.colorRed);
|
|
334
387
|
}
|
|
335
388
|
return;
|
|
@@ -584,8 +637,16 @@ class Terminal {
|
|
|
584
637
|
}
|
|
585
638
|
|
|
586
639
|
_openUrl() {
|
|
587
|
-
|
|
588
|
-
|
|
640
|
+
if (input.value && this.input.value.length > 0) {
|
|
641
|
+
const url = this.input.value.replace(/^.*?(?=https?:\/\/)/, "")
|
|
642
|
+
window.open(url, '_blank');
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
this._printLine("");
|
|
646
|
+
this._printColoredLine(`[error]: No URL selected`, this.colorRed);
|
|
647
|
+
this._printLine("");
|
|
648
|
+
this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
|
|
649
|
+
}
|
|
589
650
|
}
|
|
590
651
|
|
|
591
652
|
_resetTerminal() {
|
|
@@ -603,10 +664,10 @@ class Terminal {
|
|
|
603
664
|
this._printLine("");
|
|
604
665
|
|
|
605
666
|
this._printLine("Available commands:");
|
|
606
|
-
this._printLine(" request [-X METHOD]
|
|
607
|
-
this._printLine(" trace
|
|
608
|
-
this._printLine(" clear
|
|
609
|
-
this._printLine(" help
|
|
667
|
+
this._printLine(" request [-X METHOD] <url> – send HTTP request to a URL");
|
|
668
|
+
this._printLine(" trace – output discovery trace");
|
|
669
|
+
this._printLine(" clear – clear terminal output");
|
|
670
|
+
this._printLine(" help – show this help text");
|
|
610
671
|
this._printLine("");
|
|
611
672
|
|
|
612
673
|
this._printLine("Keyboard support:");
|
|
@@ -624,7 +685,6 @@ class Terminal {
|
|
|
624
685
|
this._printLine("Examples:");
|
|
625
686
|
this._printLine(" request https://api.node42.dev/health");
|
|
626
687
|
this._printLine(" request -X POST https://api.node42.dev/health");
|
|
627
|
-
this._printLine("");
|
|
628
688
|
}
|
|
629
689
|
|
|
630
690
|
_printLine(s) {
|
|
@@ -635,9 +695,7 @@ class Terminal {
|
|
|
635
695
|
|
|
636
696
|
_printColoredLine(s, color="#111827") {
|
|
637
697
|
const html = this.term.innerHTML;
|
|
638
|
-
this.term.innerHTML =
|
|
639
|
-
`${html}<span style="color:${color};">${s}</span><br>`;
|
|
640
|
-
|
|
698
|
+
this.term.innerHTML = `${html}<span style="color:${color};">${s}</span><br>`;
|
|
641
699
|
this._scrollToBottom();
|
|
642
700
|
}
|
|
643
701
|
|
|
@@ -647,8 +705,24 @@ class Terminal {
|
|
|
647
705
|
}
|
|
648
706
|
|
|
649
707
|
_printRaw(s) {
|
|
650
|
-
|
|
651
|
-
|
|
708
|
+
// Detect if this is HTML content
|
|
709
|
+
const isHtml = /^\s*</.test(s);
|
|
710
|
+
|
|
711
|
+
let output;
|
|
712
|
+
|
|
713
|
+
if (isHtml) {
|
|
714
|
+
// Escape HTML so it is shown as text
|
|
715
|
+
output = s
|
|
716
|
+
.replace(/&/g, "&")
|
|
717
|
+
.replace(/</g, "<")
|
|
718
|
+
.replace(/>/g, ">")
|
|
719
|
+
.replace(/\r?\n/g, "<br>");
|
|
720
|
+
} else {
|
|
721
|
+
// Normal text handling
|
|
722
|
+
output = s.replace(/\r?\n/g, "<br>");
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
this.term.innerHTML += output;
|
|
652
726
|
|
|
653
727
|
if (!s.endsWith("\n")) {
|
|
654
728
|
this.term.innerHTML += "<br>";
|