@n42/cli 0.1.21 → 0.1.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/README.md CHANGED
@@ -67,11 +67,11 @@ n42 discover peppol <environment> <participantId>
67
67
 
68
68
  ------------------------------------------------------------------------
69
69
 
70
- ## Artifacts
70
+ ## Artefacts
71
71
 
72
- Artifacts are stored under:
72
+ Artefacts are stored under:
73
73
 
74
- ~/.node42/artifacts/
74
+ ~/.node42/artefacts/
75
75
 
76
76
  ------------------------------------------------------------------------
77
77
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@n42/cli",
3
- "version": "0.1.21",
4
- "description": "Node42 CLI – Command-line interface for eDelivery path discovery, diagnostics, and tooling",
3
+ "version": "0.1.33",
4
+ "description": "Node42 CLI – Command-line interface for Peppol eDelivery path discovery, diagnostics, and tooling",
5
5
  "keywords": [
6
6
  "node42"
7
7
  ],
package/src/config.js CHANGED
@@ -9,11 +9,15 @@ const config = {
9
9
  API_TIMEOUT_MS: 30000,
10
10
 
11
11
  NODE42_DIR: path.join(os.homedir(), ".node42"),
12
+
12
13
  ARTEFACTS_DIR: null,
13
- USAGE_FILE: null, // filled below
14
- USER_FILE: null, // filled below
15
- TOKENS_FILE: null, // filled below
16
- CONFIG_FILE: null, // filled below
14
+ TRANSACTIONS_DIR: null,
15
+ VALIDATION_DIR: null,
16
+
17
+ USAGE_FILE: null,
18
+ USER_FILE: null,
19
+ TOKENS_FILE: null,
20
+ CONFIG_FILE: null,
17
21
 
18
22
  DEFAULT_OUTPUT: "json",
19
23
  DEFAULT_FORMAT: "svg",
@@ -24,6 +28,9 @@ const config = {
24
28
  };
25
29
 
26
30
  config.ARTEFACTS_DIR = path.join(config.NODE42_DIR, "artefacts", "discovery");
31
+ config.TRANSACTIONS_DIR = path.join(config.NODE42_DIR, "artefacts", "transactions");
32
+ config.VALIDATION_DIR = path.join(config.NODE42_DIR, "artefacts", "validation");
33
+
27
34
  config.USER_FILE = path.join(config.NODE42_DIR, "user.json");
28
35
  config.USAGE_FILE = path.join(config.NODE42_DIR, "usage.json");
29
36
  config.TOKENS_FILE = path.join(config.NODE42_DIR, "tokens.json");
@@ -31,14 +38,15 @@ config.CONFIG_FILE = path.join(config.NODE42_DIR, "config.json");
31
38
 
32
39
  function createAppDirs() {
33
40
  fs.mkdirSync(config.NODE42_DIR, { recursive: true });
41
+
34
42
  fs.mkdirSync(config.ARTEFACTS_DIR, { recursive: true });
43
+ fs.mkdirSync(config.TRANSACTIONS_DIR, { recursive: true });
44
+ fs.mkdirSync(config.VALIDATION_DIR, { recursive: true });
35
45
 
36
- //if (!fs.existsSync(config.CONFIG_FILE)) {
37
- fs.writeFileSync(
38
- config.CONFIG_FILE,
39
- JSON.stringify(config, null, 2)
40
- );
41
- //}
46
+ fs.writeFileSync(
47
+ config.CONFIG_FILE,
48
+ JSON.stringify(config, null, 2)
49
+ );
42
50
  }
43
51
 
44
52
  createAppDirs();
package/src/discover.js CHANGED
@@ -33,6 +33,29 @@ const DEFAULT_DISCOVERY_INPUT = {
33
33
  const discoveryInput = DEFAULT_DISCOVERY_INPUT;
34
34
  let docSelected = false;
35
35
 
36
+ async function processSupportedDocuments(encodedDocs, environment, participantId, options) {
37
+ if (encodedDocs && !docSelected) {
38
+ const docs = JSON.parse(Buffer.from(encodedDocs, "base64").toString("utf8"))
39
+ .map(d => ({ ...d, label: buildDocLabel(d) }));
40
+
41
+ if (docs.length) {
42
+ console.log(`Discovery completed`);
43
+ console.log(`Found ${docs.length} supported document type(s)\n`);
44
+
45
+ docSelected = await promptForDocument(docs);
46
+
47
+ if (docSelected.scheme) {
48
+ discoveryInput.document.scheme = docSelected.scheme;
49
+ }
50
+
51
+ if (docSelected.value) {
52
+ discoveryInput.document.value = docSelected.value;
53
+ }
54
+
55
+ runDiscovery(environment, participantId, options);
56
+ }
57
+ }
58
+ }
36
59
 
37
60
  async function runDiscovery(environment, participantId, options) {
38
61
  const {
@@ -54,7 +77,7 @@ async function runDiscovery(environment, participantId, options) {
54
77
  output,
55
78
  format,
56
79
  forceHttps,
57
- rejectUnauthorized: insecure,
80
+ insecure,
58
81
  fetchBusinessCard,
59
82
  reverseLookup,
60
83
  probeEndpoints
@@ -84,6 +107,17 @@ async function runDiscovery(environment, participantId, options) {
84
107
  process.exit(1);
85
108
  }
86
109
 
110
+ const refId = res.headers.get("X-Node42-RefId");
111
+ const serviceUsage = res.headers.get("X-Node42-ServiceUsage");
112
+ const rateLimit = res.headers.get("X-Node42-RateLimit");
113
+ const encodedDocs = res.headers.get("X-Node42-Documents");
114
+
115
+ const userUsage = getUserUsage();
116
+ const currentMonth = new Date().toISOString().slice(0, 7);
117
+ userUsage.serviceUsage.discovery[currentMonth] = serviceUsage;
118
+
119
+ updateUserUsage(userUsage);
120
+
87
121
  if (output === "plantuml" && format === "svg") {
88
122
  const svg = await res.text();
89
123
  stopSpinner();
@@ -93,59 +127,44 @@ async function runDiscovery(environment, participantId, options) {
93
127
  process.exit(1);
94
128
  }
95
129
 
96
- const refId = res.headers.get("X-Node42-RefId");
97
- const serviceUsage = res.headers.get("X-Node42-ServiceUsage");
98
- const rateLimit = res.headers.get("X-Node42-RateLimit");
99
-
100
- const userUsage = getUserUsage();
101
- const currentMonth = new Date().toISOString().slice(0, 7);
102
- userUsage.serviceUsage.discovery[currentMonth] = serviceUsage;
103
-
104
- updateUserUsage(userUsage);
105
-
106
- const encodedDocs = res.headers.get("X-Node42-Documents");
107
- if (encodedDocs && !docSelected) {
108
- const docs = JSON.parse(Buffer.from(encodedDocs, "base64").toString("utf8"))
109
- .map(d => ({ ...d, label: buildDocLabel(d) }));
110
-
111
- if (docs.length) {
112
- console.log(`Discovery completed`);
113
- console.log(`Found ${docs.length} supported document type(s)\n`);
114
-
115
- docSelected = await promptForDocument(docs);
116
-
117
- if (docSelected.scheme) {
118
- discoveryInput.document.scheme = docSelected.scheme;
119
- }
120
-
121
- if (docSelected.value) {
122
- discoveryInput.document.value = docSelected.value;
123
- }
124
-
125
- runDiscovery(environment, participantId, options);
126
- }
127
- }
130
+ await processSupportedDocuments(encodedDocs, environment, participantId, options);
128
131
 
129
132
  const file = path.join(ARTEFACTS_DIR, `${refId}.svg`);
130
133
  fs.writeFileSync(file, svg);
131
134
 
132
135
  console.log(`Discovery completed`);
133
136
  console.log(`Usage : ${serviceUsage} / ${rateLimit}`);
134
- console.log(`Artifact : ${file}\n`);
135
-
136
- stopSpinner();
137
+ console.log(`Artefact : ${file}\n`);
137
138
  return;
138
139
  }
139
140
 
140
- if (output === "plantuml" && output === "text") {
141
+ if (output === "plantuml" && format === "text") {
141
142
  const text = await res.text();
142
- console.log(text);
143
+ stopSpinner();
144
+
145
+ await processSupportedDocuments(encodedDocs, environment, participantId, options);
146
+
147
+ const file = path.join(ARTEFACTS_DIR, `${refId}.puml`);
148
+ fs.writeFileSync(file, text);
149
+
150
+ console.log(`Discovery completed`);
151
+ console.log(`Usage : ${serviceUsage} / ${rateLimit}`);
152
+ console.log(`Artefact : ${file}\n`);
143
153
  return;
144
154
  }
145
155
 
146
156
  // default: json
147
157
  const json = await res.json();
148
- console.log(JSON.stringify(json, null, 2));
158
+ stopSpinner();
159
+
160
+ await processSupportedDocuments(encodedDocs, environment, participantId, options);
161
+
162
+ const file = path.join(ARTEFACTS_DIR, `${refId}.json`);
163
+ fs.writeFileSync(file, JSON.stringify(json, null, 2));
164
+
165
+ console.log(`Discovery completed`);
166
+ console.log(`Usage : ${serviceUsage} / ${rateLimit}`);
167
+ console.log(`Artefact : ${file}\n`);
149
168
  }
150
169
 
151
170
  module.exports = { runDiscovery };