@n42/cli 0.1.33 → 0.1.38

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/auth.js +12 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n42/cli",
3
- "version": "0.1.33",
3
+ "version": "0.1.38",
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
@@ -57,7 +57,7 @@ async function refreshSession() {
57
57
  }
58
58
 
59
59
  const payload = {
60
- refreshToken,
60
+ token: refreshToken,
61
61
  };
62
62
 
63
63
  const res = await fetch(`${API_URL}/${EP_REFRESH}`, {
@@ -86,17 +86,14 @@ async function refreshSession() {
86
86
  idToken: data.idToken
87
87
  })
88
88
  );
89
- //console.log("Token refreshed");
90
89
  }
91
90
 
92
91
  return true;
93
92
  }
94
93
 
95
94
  async function fetchWithAuth(url, options = {}) {
96
- const { accessToken } = loadAuth();
97
- if (!accessToken) { // N42E-9032
98
- //console.log("Token missing...");
99
-
95
+ let { accessToken } = loadAuth();
96
+ if (!accessToken) {
100
97
  handleError({ code: "N42E-9032" });
101
98
  return;
102
99
  }
@@ -115,9 +112,17 @@ async function fetchWithAuth(url, options = {}) {
115
112
 
116
113
  const refreshed = await refreshSession();
117
114
  if (!refreshed) { // N42E-9033
118
- //console.log("Token expired...");
119
115
  return res;
120
116
  }
117
+
118
+ accessToken = loadAuth().accessToken;
119
+ return fetch(url, {
120
+ ...options,
121
+ headers: {
122
+ ...(options.headers || {}),
123
+ Authorization: `Bearer ${accessToken}`
124
+ }
125
+ });
121
126
  }
122
127
 
123
128
  module.exports = { loadAuth, checkAuth, fetchWithAuth };