dymo-api 1.0.78 → 1.0.80

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.
@@ -48,8 +48,9 @@ const customError = (code, message) => {
48
48
  return Object.assign(new Error(), { code, message: `[${config_1.default.lib.name}] ${message}` });
49
49
  };
50
50
  const convertTailwindToInlineCss = (htmlContent) => {
51
- return htmlContent.replace(/class="([^"]+)"/g, (match, classList) => {
52
- return match.replace("class", "style").replace(classList, (0, tw_to_css_1.twi)(classList, { minify: true, merge: true }));
51
+ return htmlContent.replace(/class="([^"]+)"( style="([^"]+)")?/g, (match, classList, _, existingStyle) => {
52
+ const compiledStyles = (0, tw_to_css_1.twi)(classList, { minify: true, merge: true });
53
+ return match.replace(/class="[^"]+"/, "").replace(/ style="[^"]+"/, "").concat(` style="${existingStyle ? `${existingStyle.trim().slice(0, -1)}; ${compiledStyles}` : compiledStyles}"`);
53
54
  });
54
55
  };
55
56
  /**
@@ -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
- this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
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 (this.rootApiKey)
103
- tokens.root = `Bearer ${this.rootApiKey}`;
104
- if (this.apiKey)
105
- tokens.api = `Bearer ${this.apiKey}`;
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
- this.tokensResponse = response.data;
115
- this.tokensVerified = true;
108
+ DymoAPI.tokensResponse = response.data;
109
+ DymoAPI.tokensVerified = true;
116
110
  console.log(`[${config_1.default.lib.name}] Tokens initialized successfully.`);
117
- return this.tokensResponse;
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
- await this.getTokens();
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}`);
@@ -9,8 +9,9 @@ const customError = (code, message) => {
9
9
  return Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
10
10
  };
11
11
  const convertTailwindToInlineCss = (htmlContent) => {
12
- return htmlContent.replace(/class="([^"]+)"/g, (match, classList) => {
13
- return match.replace("class", "style").replace(classList, twi(classList, { minify: true, merge: true }));
12
+ return htmlContent.replace(/class="([^"]+)"( style="([^"]+)")?/g, (match, classList, _, existingStyle) => {
13
+ const compiledStyles = twi(classList, { minify: true, merge: true });
14
+ return match.replace(/class="[^"]+"/, "").replace(/ style="[^"]+"/, "").concat(` style="${existingStyle ? `${existingStyle.trim().slice(0, -1)}; ${compiledStyles}` : compiledStyles}"`);
14
15
  });
15
16
  };
16
17
  /**
@@ -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
- this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
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 (this.rootApiKey)
65
- tokens.root = `Bearer ${this.rootApiKey}`;
66
- if (this.apiKey)
67
- tokens.api = `Bearer ${this.apiKey}`;
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
- this.tokensResponse = response.data;
77
- this.tokensVerified = true;
70
+ DymoAPI.tokensResponse = response.data;
71
+ DymoAPI.tokensVerified = true;
78
72
  console.log(`[${config.lib.name}] Tokens initialized successfully.`);
79
- return this.tokensResponse;
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
- await this.getTokens();
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}`);
@@ -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
  *
@@ -36,6 +36,7 @@ export interface SendEmail {
36
36
  options?: {
37
37
  priority?: "high" | "normal" | "low" | undefined;
38
38
  composeTailwindClasses?: boolean;
39
+ compileToCssSafe?: boolean;
39
40
  };
40
41
  attachments?: Attachment[];
41
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dymo-api",
3
- "version": "1.0.78",
3
+ "version": "1.0.80",
4
4
  "description": "Flow system for Dymo API.",
5
5
  "main": "dist/cjs/dymo-api.js",
6
6
  "module": "dist/esm/dymo-api.js",