@n42/cli 0.1.83 → 0.1.88

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.1.83",
3
+ "version": "0.1.88",
4
4
  "description": "Node42 CLI – Command-line interface for Peppol eDelivery path discovery, diagnostics, and tooling",
5
5
  "keywords": [
6
6
  "node42"
package/src/auth.js CHANGED
@@ -1,14 +1,14 @@
1
1
  const fs = require("fs");
2
- const { NODE42_DIR, TOKENS_FILE, API_URL, EP_SIGNIN, EP_REFRESH } = require("./config");
2
+ const { NODE42_DIR, TOKENS_FILE, API_URL, EP_SIGNIN, EP_REFRESH, EP_ME } = require("./config");
3
3
  const { handleError } = require("./errors");
4
- const { getUser } = require("./user");
4
+ const { getUserWithIndex } = require("./user");
5
5
  const { clearScreen, ask, startSpinner } = require("./utils");
6
6
  const db = require("./db");
7
7
 
8
8
 
9
9
  async function login() {
10
10
  clearScreen("Sign in to Node42");
11
- let user = getUser();
11
+ let user = getUserWithIndex(0);
12
12
 
13
13
  const username = await ask("Username", user.userMail ?? "");
14
14
  const password = await ask("Password", null, true);
@@ -54,7 +54,7 @@ async function login() {
54
54
  process.exit(1);
55
55
  }
56
56
 
57
- user = getUser();
57
+ user = getUserWithIndex(0);
58
58
  console.log(
59
59
  `Authenticated as ${user.userName} <${user.userMail}> (${user.role})`
60
60
  );
@@ -81,7 +81,7 @@ async function checkAuth() {
81
81
  return false;
82
82
  }
83
83
 
84
- const res = await fetchWithAuth(`${API_URL}/users/me`, {
84
+ const res = await fetchWithAuth(`${API_URL}/${EP_ME}`, {
85
85
  method: "GET",
86
86
  headers: {
87
87
  "Content-Type": "application/json"
package/src/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { Command } = require("commander");
4
4
  const { login, logout, checkAuth } = require("./auth");
5
- const { getUser, getUserUsage } = require("./user");
5
+ const { getUserWithIndex, getUserUsage } = require("./user");
6
6
  const { runDiscovery } = require("./discover");
7
7
  const { clearScreen, startSpinner, validateEnv, validateId, createAppDirs, getArtefactExt, cleanAppDirs } = require("./utils");
8
8
  const { NODE42_DIR, ARTEFACTS_DIR, DEFAULT_OUTPUT, DEFAULT_FORMAT } = require("./config");
@@ -77,7 +77,7 @@ program
77
77
  process.exit(1);
78
78
  }
79
79
 
80
- const user = getUser();
80
+ const user = getUserWithIndex(0);
81
81
  const currentMonth = new Date().toISOString().slice(0, 7);
82
82
  console.log(`Node42 CLI v${pkg.version}
83
83
  User
@@ -103,7 +103,7 @@ program
103
103
  .description("Returns usage for the authenticated user.")
104
104
  .option("-m, --month <yyyy-mm>", "Show usage for a specific month")
105
105
  .action((service, options) => {
106
- const user = getUser();
106
+ const user = getUserWithIndex(0);
107
107
  const currentMonth = options.month ? options.month : new Date().toISOString().slice(0, 7);
108
108
  let usage = getUserUsage(user.id, service, currentMonth);
109
109
  if (!usage) {
@@ -172,8 +172,6 @@ program
172
172
  for (const item of artefacts) {
173
173
  const d = new Date(item.createdAt);
174
174
  const dt = d.toISOString().slice(0, 19).replace("T", " ");
175
-
176
- const ext = getArtefactExt(item.output, item.format);
177
175
  const file = path.join(ARTEFACTS_DIR, `${item.file}`);
178
176
 
179
177
  let pid = item.participantId;
package/src/config.js CHANGED
@@ -23,6 +23,7 @@ const config = {
23
23
 
24
24
  EP_SIGNIN: "auth/signin",
25
25
  EP_REFRESH: "auth/refresh",
26
+ EP_ME: "users/me",
26
27
  EP_DISCOVER: "discover/peppol"
27
28
  };
28
29
 
package/src/discover.js CHANGED
@@ -5,7 +5,7 @@ const db = require("./db");
5
5
 
6
6
  const { fetchWithAuth } = require("./auth");
7
7
  const { API_URL, EP_DISCOVER, DEFAULT_OUTPUT, DEFAULT_FORMAT, ARTEFACTS_DIR } = require("./config");
8
- const { getUser, setUserUsage } = require("./user");
8
+ const { getUserWithIndex, setUserUsage } = require("./user");
9
9
  const { clearScreen, startSpinner, buildDocLabel, promptForDocument, getShortId, getArtefactExt } = require("./utils");
10
10
  const { handleError } = require("./errors");
11
11
 
@@ -117,7 +117,7 @@ async function runDiscovery(participantId, options) {
117
117
  const encodedDocs = res.headers.get("X-Node42-Documents");
118
118
  const currentMonth = new Date().toISOString().slice(0, 7);
119
119
 
120
- const user = getUser();
120
+ const user = getUserWithIndex(0);
121
121
  setUserUsage(
122
122
  user.id,
123
123
  "discovery",
package/src/user.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const db = require("./db");
2
2
 
3
- function getUser() {
3
+ function getUserWithIndex(index) {
4
4
  const users = db.get("user");
5
- return users.length ? users[0] : {
5
+ return users.length ? users[index] : {
6
6
  "id": "n/a",
7
7
  "userName": "n/a",
8
8
  "userMail": "n/a",
@@ -10,6 +10,21 @@ function getUser() {
10
10
  };
11
11
  }
12
12
 
13
+ function getUserWithId(userId) {
14
+ const database = db.load();
15
+
16
+ const u = database.user.find(x => x.id === userId);
17
+ if (!u) {
18
+ return {
19
+ "id": "n/a",
20
+ "userName": "n/a",
21
+ "userMail": "n/a",
22
+ "role": "n/a"
23
+ }
24
+ }
25
+ return u;
26
+ }
27
+
13
28
  function getUserUsage(userId, service, month) {
14
29
  const database = db.load();
15
30
 
@@ -34,4 +49,4 @@ function setUserUsage(userId, service, month, value) {
34
49
  db.save(database);
35
50
  }
36
51
 
37
- module.exports = { getUser, getUserUsage, setUserUsage };
52
+ module.exports = { getUserWithIndex, getUserWithId, getUserUsage, setUserUsage };
package/test/auth.test.js CHANGED
@@ -36,7 +36,9 @@ describe("auth", () => {
36
36
  .onSecondCall().resolves("secret");
37
37
 
38
38
  sinon.stub(utils, "startSpinner").callsFake(() => () => {});
39
- sinon.stub(user, "getUser").returns({
39
+ sinon.stub(user, "getUserWithIndex")
40
+ .withArgs(0)
41
+ .returns({
40
42
  id: "1",
41
43
  userName: "User",
42
44
  userMail: "user@test.com",