@n42/cli 0.3.68 → 0.3.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n42/cli",
3
- "version": "0.3.68",
3
+ "version": "0.3.73",
4
4
  "description": "Node42 CLI – Command-line interface for Peppol eDelivery path discovery, diagnostics, and tooling",
5
5
  "keywords": [
6
6
  "node42",
@@ -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.65"
198
+ pkgVersion: "0.3.69"
183
199
  });
184
200
 
185
201
  addSvgClickListener();
@@ -1,7 +1,7 @@
1
1
  class Terminal {
2
2
  constructor(opts = {}) {
3
3
  this.opts = {
4
- title: "Request",
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 = `Terminal [CMD]: ${input.command}`;
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();
@@ -127,11 +133,11 @@ class Terminal {
127
133
 
128
134
  async httpRequest(req) {
129
135
  const normalized = this._normalizeReq(req);
130
- this._resetTerminal();
131
136
 
132
137
  const cmd = `$ request ${this._getReqArgs(normalized)}`;
133
138
  this._addHistory(cmd)
134
139
 
140
+ this._printLine("");
135
141
  this._printColoredLine(cmd, this.colorBlue);
136
142
  this._printLine("");
137
143
 
@@ -175,14 +181,14 @@ class Terminal {
175
181
  if (normalized.body) this._printLine(`> (body ${this._byteLen(normalized.body)} bytes)`);
176
182
  this._printLine("");
177
183
 
178
- this.title.textContent = `Terminal [${normalized.method}]: request`;
184
+ //this.title.textContent = `Request: ${normalized.method}`;
179
185
 
180
186
  const res = await fetch(normalized.url, fetchInit);
181
187
 
182
188
  const dt = (performance.now() - t0);
183
- this._printLine(`< HTTP ${res.status} ${res.statusText} (${dt.toFixed(0)} ms)`);
189
+ this._printColoredLine(`< HTTP ${res.status} ${res.statusText} (${dt.toFixed(0)} ms)`, this.colorBrown);
184
190
 
185
- res.headers.forEach((v, k) => this._printLine(`< ${k}: ${v}`));
191
+ res.headers.forEach((v, k) => this._printColoredLine(`< ${k}: ${v}`, this.colorBrown));
186
192
  this._printLine("");
187
193
 
188
194
  const { text, truncated, bytesRead } = await this._readTextWithLimit(res, normalized.maxBytes);
@@ -193,15 +199,22 @@ class Terminal {
193
199
  this._printRaw(text);
194
200
 
195
201
  this._printLine("");
196
- this._printLine(`[done]`);
202
+ this._printColoredLine(`[done]`, this.colorGreen);
203
+
197
204
  this._setBusy(false);
205
+
198
206
  return { status: res.status, headers: res.headers, body: text, truncated };
199
207
  }
200
208
  catch (err) {
201
- const name = err?.name || "Error";
209
+ //console.log(err);
210
+
211
+ //const name = err?.name || "error";
202
212
  const msg = err?.message || String(err);
203
213
 
204
- this._printLine(`[${name}] ${msg}`);
214
+ this._printColoredLine(`[error]: ${msg}`, this.colorRed);
215
+ this._printLine("");
216
+ this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
217
+
205
218
  this._setBusy(false);
206
219
 
207
220
  return { status: 0, headers: new Headers(), body: "", error: msg };
@@ -297,18 +310,53 @@ class Terminal {
297
310
  this._printHelp();
298
311
  return;
299
312
  }
313
+
314
+ if (cmd.startsWith("parse ")) {
315
+ const cmdParts = cmd.trim().split(/\s+/);
316
+ if (cmdParts.length < 2) {
317
+ this._printLine("");
318
+ this._printColoredLine("[error]: Unknown item.", this.colorRed);
319
+ return;
320
+ }
321
+
322
+ const item = cmdParts[1].trim();
323
+ if (item) {
324
+ switch(item) {
325
+ case "naptr": {
326
+ const parts = this._argument.split(".");
327
+ const hash = parts[0];
328
+ const scheme = parts[1];
329
+ const env = parts[2];
330
+ const smlDomain = parts.slice(3).join(".");
331
+
332
+ this._printLine("");
333
+ this._printColoredLine("$ parse NAPTR domain", this.colorBlue);
334
+ this._printLine("");
335
+
336
+ this._printColoredLine(`Environment : ${env === "acc" ? "TEST" : "PROD"}`, this.colorPink);
337
+ this._printLine(`Participant scheme : ${scheme}`);
338
+ this._printLine(`Identifier hash : ${hash}`);
339
+ this._printLine(`${env === "acc" ? "SMK" : "SML"} domain : ${smlDomain}`);
340
+ break;
341
+ }
342
+ }
343
+ }
344
+ return;
345
+ }
300
346
 
301
347
  if (cmd.startsWith("request ")) {
302
348
  if (this.runningFromFile) {
303
349
  this._addHistory(cmd);
304
350
 
351
+ this._printLine("");
305
352
  this._printColoredLine(`$ ${cmd}`, this.colorBlue);
306
353
 
307
354
  this._printLine("");
308
355
  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
356
  this._printLine("");
311
357
 
358
+ this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
359
+
312
360
  return;
313
361
  }
314
362
  // Parse: request [METHOD] <url>
@@ -327,9 +375,13 @@ class Terminal {
327
375
  this._addHistory(cmd);
328
376
 
329
377
  if (discoveryTrace) {
330
- this._resetTerminal();
331
- this._printHtml(this._jsonHighlight(discoveryTrace));
332
- } else {
378
+ this._printLine("");
379
+ this._printColoredLine("$ trace", this.colorBlue);
380
+ this._printLine("");
381
+
382
+ this._printLine(this._jsonHighlight(discoveryTrace));
383
+ }
384
+ else {
333
385
  this._printColoredLine("[error]: Discovery trace missing", this.colorRed);
334
386
  }
335
387
  return;
@@ -584,8 +636,16 @@ class Terminal {
584
636
  }
585
637
 
586
638
  _openUrl() {
587
- const url = this.input.value.replace(/^.*?(?=https?:\/\/)/, "")
588
- window.open(url, '_blank');
639
+ if (this.input.value && this.input.value.length > 0) {
640
+ const url = this.input.value.replace(/^.*?(?=https?:\/\/)/, "")
641
+ window.open(url, '_blank');
642
+ }
643
+ else {
644
+ this._printLine("");
645
+ this._printColoredLine(`[error]: No URL selected`, this.colorRed);
646
+ this._printLine("");
647
+ this._printLine("Use the arrow keys to reselect the URL, then click the top-right button to open it in a browser tab instead.");
648
+ }
589
649
  }
590
650
 
591
651
  _resetTerminal() {
@@ -603,10 +663,10 @@ class Terminal {
603
663
  this._printLine("");
604
664
 
605
665
  this._printLine("Available commands:");
606
- this._printLine(" request [-X METHOD] <url> – send HTTP request to a URL");
607
- this._printLine(" trace – output discovery trace");
608
- this._printLine(" clear – clear terminal output");
609
- this._printLine(" help – show this help text");
666
+ this._printLine(" request [-X METHOD] &lturl&gt – send HTTP request to a URL");
667
+ this._printLine(" trace – output discovery trace");
668
+ this._printLine(" clear – clear terminal output");
669
+ this._printLine(" help – show this help text");
610
670
  this._printLine("");
611
671
 
612
672
  this._printLine("Keyboard support:");
@@ -624,7 +684,6 @@ class Terminal {
624
684
  this._printLine("Examples:");
625
685
  this._printLine(" request https://api.node42.dev/health");
626
686
  this._printLine(" request -X POST https://api.node42.dev/health");
627
- this._printLine("");
628
687
  }
629
688
 
630
689
  _printLine(s) {
@@ -635,9 +694,7 @@ class Terminal {
635
694
 
636
695
  _printColoredLine(s, color="#111827") {
637
696
  const html = this.term.innerHTML;
638
- this.term.innerHTML =
639
- `${html}<span style="color:${color};">${s}</span><br>`;
640
-
697
+ this.term.innerHTML = `${html}<span style="color:${color};">${s}</span><br>`;
641
698
  this._scrollToBottom();
642
699
  }
643
700
 
@@ -647,8 +704,24 @@ class Terminal {
647
704
  }
648
705
 
649
706
  _printRaw(s) {
650
- const html = s.replace(/\r?\n/g, "<br>");
651
- this.term.innerHTML += html;
707
+ // Detect if this is HTML content
708
+ const isHtml = /^\s*</.test(s);
709
+
710
+ let output;
711
+
712
+ if (isHtml) {
713
+ // Escape HTML so it is shown as text
714
+ output = s
715
+ .replace(/&/g, "&amp;")
716
+ .replace(/</g, "&lt;")
717
+ .replace(/>/g, "&gt;")
718
+ .replace(/\r?\n/g, "<br>");
719
+ } else {
720
+ // Normal text handling
721
+ output = s.replace(/\r?\n/g, "<br>");
722
+ }
723
+
724
+ this.term.innerHTML += output;
652
725
 
653
726
  if (!s.endsWith("\n")) {
654
727
  this.term.innerHTML += "<br>";