dymo-api 1.0.78 → 1.0.79
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/cjs/dymo-api.cjs +14 -17
- package/dist/esm/dymo-api.js +14 -17
- package/dist/types/dymo-api.d.ts +3 -3
- package/package.json +1 -1
package/dist/cjs/dymo-api.cjs
CHANGED
|
@@ -69,13 +69,12 @@ class DymoAPI {
|
|
|
69
69
|
constructor({ rootApiKey = null, apiKey = null, local = false, serverEmailConfig = undefined } = {}) {
|
|
70
70
|
this.rootApiKey = rootApiKey;
|
|
71
71
|
this.apiKey = apiKey;
|
|
72
|
-
this.tokensResponse = null;
|
|
73
|
-
this.tokensVerified = false;
|
|
74
72
|
this.serverEmailConfig = serverEmailConfig;
|
|
75
73
|
this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
|
|
76
74
|
(0, config_1.setBaseUrl)(this.local);
|
|
77
75
|
this.autoupdate();
|
|
78
|
-
|
|
76
|
+
if (!DymoAPI.tokensVerified)
|
|
77
|
+
this.initializeTokens();
|
|
79
78
|
}
|
|
80
79
|
/**
|
|
81
80
|
* Retrieves and caches authentication tokens.
|
|
@@ -92,17 +91,12 @@ class DymoAPI {
|
|
|
92
91
|
* @throws Will throw an error if token validation fails, or if there is an issue
|
|
93
92
|
* with the token retrieval process.
|
|
94
93
|
*/
|
|
95
|
-
async getTokens() {
|
|
96
|
-
if (this.tokensResponse && this.tokensVerified) {
|
|
97
|
-
console.log(`[${config_1.default.lib.name}] Using cached tokens response.`);
|
|
98
|
-
return this.tokensResponse;
|
|
99
|
-
}
|
|
100
|
-
;
|
|
94
|
+
static async getTokens(rootApiKey, apiKey) {
|
|
101
95
|
const tokens = {};
|
|
102
|
-
if (
|
|
103
|
-
tokens.root = `Bearer ${
|
|
104
|
-
if (
|
|
105
|
-
tokens.api = `Bearer ${
|
|
96
|
+
if (rootApiKey)
|
|
97
|
+
tokens.root = `Bearer ${rootApiKey}`;
|
|
98
|
+
if (apiKey)
|
|
99
|
+
tokens.api = `Bearer ${apiKey}`;
|
|
106
100
|
try {
|
|
107
101
|
if (Object.keys(tokens).length === 0)
|
|
108
102
|
return;
|
|
@@ -111,10 +105,10 @@ class DymoAPI {
|
|
|
111
105
|
throw customError(3000, "Invalid root token.");
|
|
112
106
|
if (tokens.api && response.data.api === false)
|
|
113
107
|
throw customError(3000, "Invalid API token.");
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
DymoAPI.tokensResponse = response.data;
|
|
109
|
+
DymoAPI.tokensVerified = true;
|
|
116
110
|
console.log(`[${config_1.default.lib.name}] Tokens initialized successfully.`);
|
|
117
|
-
return
|
|
111
|
+
return DymoAPI.tokensResponse;
|
|
118
112
|
}
|
|
119
113
|
catch (error) {
|
|
120
114
|
throw customError(5000, error.message);
|
|
@@ -131,7 +125,10 @@ class DymoAPI {
|
|
|
131
125
|
*/
|
|
132
126
|
async initializeTokens() {
|
|
133
127
|
try {
|
|
134
|
-
|
|
128
|
+
if (!DymoAPI.tokensVerified)
|
|
129
|
+
await DymoAPI.getTokens(this.rootApiKey, this.apiKey);
|
|
130
|
+
else
|
|
131
|
+
console.log(`[${config_1.default.lib.name}] Tokens already verified.`);
|
|
135
132
|
}
|
|
136
133
|
catch (error) {
|
|
137
134
|
throw customError(5000, `Error initializing tokens: ${error.message}`);
|
package/dist/esm/dymo-api.js
CHANGED
|
@@ -31,13 +31,12 @@ class DymoAPI {
|
|
|
31
31
|
constructor({ rootApiKey = null, apiKey = null, local = false, serverEmailConfig = undefined } = {}) {
|
|
32
32
|
this.rootApiKey = rootApiKey;
|
|
33
33
|
this.apiKey = apiKey;
|
|
34
|
-
this.tokensResponse = null;
|
|
35
|
-
this.tokensVerified = false;
|
|
36
34
|
this.serverEmailConfig = serverEmailConfig;
|
|
37
35
|
this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
|
|
38
36
|
setBaseUrl(this.local);
|
|
39
37
|
this.autoupdate();
|
|
40
|
-
|
|
38
|
+
if (!DymoAPI.tokensVerified)
|
|
39
|
+
this.initializeTokens();
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Retrieves and caches authentication tokens.
|
|
@@ -54,17 +53,12 @@ class DymoAPI {
|
|
|
54
53
|
* @throws Will throw an error if token validation fails, or if there is an issue
|
|
55
54
|
* with the token retrieval process.
|
|
56
55
|
*/
|
|
57
|
-
async getTokens() {
|
|
58
|
-
if (this.tokensResponse && this.tokensVerified) {
|
|
59
|
-
console.log(`[${config.lib.name}] Using cached tokens response.`);
|
|
60
|
-
return this.tokensResponse;
|
|
61
|
-
}
|
|
62
|
-
;
|
|
56
|
+
static async getTokens(rootApiKey, apiKey) {
|
|
63
57
|
const tokens = {};
|
|
64
|
-
if (
|
|
65
|
-
tokens.root = `Bearer ${
|
|
66
|
-
if (
|
|
67
|
-
tokens.api = `Bearer ${
|
|
58
|
+
if (rootApiKey)
|
|
59
|
+
tokens.root = `Bearer ${rootApiKey}`;
|
|
60
|
+
if (apiKey)
|
|
61
|
+
tokens.api = `Bearer ${apiKey}`;
|
|
68
62
|
try {
|
|
69
63
|
if (Object.keys(tokens).length === 0)
|
|
70
64
|
return;
|
|
@@ -73,10 +67,10 @@ class DymoAPI {
|
|
|
73
67
|
throw customError(3000, "Invalid root token.");
|
|
74
68
|
if (tokens.api && response.data.api === false)
|
|
75
69
|
throw customError(3000, "Invalid API token.");
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
DymoAPI.tokensResponse = response.data;
|
|
71
|
+
DymoAPI.tokensVerified = true;
|
|
78
72
|
console.log(`[${config.lib.name}] Tokens initialized successfully.`);
|
|
79
|
-
return
|
|
73
|
+
return DymoAPI.tokensResponse;
|
|
80
74
|
}
|
|
81
75
|
catch (error) {
|
|
82
76
|
throw customError(5000, error.message);
|
|
@@ -93,7 +87,10 @@ class DymoAPI {
|
|
|
93
87
|
*/
|
|
94
88
|
async initializeTokens() {
|
|
95
89
|
try {
|
|
96
|
-
|
|
90
|
+
if (!DymoAPI.tokensVerified)
|
|
91
|
+
await DymoAPI.getTokens(this.rootApiKey, this.apiKey);
|
|
92
|
+
else
|
|
93
|
+
console.log(`[${config.lib.name}] Tokens already verified.`);
|
|
97
94
|
}
|
|
98
95
|
catch (error) {
|
|
99
96
|
throw customError(5000, `Error initializing tokens: ${error.message}`);
|
package/dist/types/dymo-api.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ interface ServerEmailConfig {
|
|
|
15
15
|
declare class DymoAPI {
|
|
16
16
|
private rootApiKey;
|
|
17
17
|
private apiKey;
|
|
18
|
-
private tokensResponse;
|
|
19
|
-
private tokensVerified;
|
|
18
|
+
private static tokensResponse;
|
|
19
|
+
private static tokensVerified;
|
|
20
20
|
private serverEmailConfig?;
|
|
21
21
|
private local;
|
|
22
22
|
/**
|
|
@@ -58,7 +58,7 @@ declare class DymoAPI {
|
|
|
58
58
|
* @throws Will throw an error if token validation fails, or if there is an issue
|
|
59
59
|
* with the token retrieval process.
|
|
60
60
|
*/
|
|
61
|
-
private getTokens;
|
|
61
|
+
private static getTokens;
|
|
62
62
|
/**
|
|
63
63
|
* Initializes the tokens response by calling getTokens().
|
|
64
64
|
*
|