dymo-api 1.0.28 → 1.0.30
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/branches/private.js +1 -1
- package/dist/dymo-api.js +11 -1
- package/dist/dymo-api.mjs +11 -1
- package/dist/services/autoupdate.js +28 -0
- package/dist/types/dymo-api.d.ts +6 -0
- package/dist/types/lib/interfaces.d.ts +1 -0
- package/dist/types/services/autoupdate.d.ts +1 -0
- package/package.json +1 -1
package/dist/branches/private.js
CHANGED
|
@@ -38,7 +38,7 @@ const isValidData = async (token, data) => {
|
|
|
38
38
|
throw customError(3000, "Invalid private token.");
|
|
39
39
|
let i = false;
|
|
40
40
|
for (const key in data) {
|
|
41
|
-
if (data.hasOwnProperty(key) && (key === "email" || key === "phone" || key === "domain" || key === "creditCard" || key === "ip")) {
|
|
41
|
+
if (data.hasOwnProperty(key) && (key === "email" || key === "phone" || key === "domain" || key === "creditCard" || key === "ip" || key === "wallet")) {
|
|
42
42
|
i = true;
|
|
43
43
|
break;
|
|
44
44
|
}
|
package/dist/dymo-api.js
CHANGED
|
@@ -30,6 +30,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
30
30
|
const PublicAPI = __importStar(require("./branches/public"));
|
|
31
31
|
const PrivateAPI = __importStar(require("./branches/private"));
|
|
32
32
|
const config_1 = __importStar(require("./config"));
|
|
33
|
+
const autoupdate_1 = require("./services/autoupdate");
|
|
33
34
|
const customError = (code, message) => {
|
|
34
35
|
return Object.assign(new Error(), { code, message: `[${config_1.default.lib.name}] ${message}` });
|
|
35
36
|
};
|
|
@@ -45,6 +46,7 @@ class DymoAPI {
|
|
|
45
46
|
this.serverEmailConfig = serverEmailConfig;
|
|
46
47
|
this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
|
|
47
48
|
(0, config_1.setBaseUrl)(this.local);
|
|
49
|
+
this.autoupdate();
|
|
48
50
|
this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
|
|
49
51
|
}
|
|
50
52
|
getBaseUrl() {
|
|
@@ -87,12 +89,20 @@ class DymoAPI {
|
|
|
87
89
|
throw customError(5000, `Error initializing tokens: ${error.message}`);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
92
|
+
async autoupdate() {
|
|
93
|
+
try {
|
|
94
|
+
await (0, autoupdate_1.checkForUpdates)();
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw customError(5000, `Error checking the latest version in npmjs: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
90
100
|
// FUNCTIONS / Private.
|
|
91
101
|
async isValidData(data) {
|
|
92
102
|
return await PrivateAPI.isValidData(this.apiKey, data);
|
|
93
103
|
}
|
|
94
104
|
async sendEmail(data) {
|
|
95
|
-
if (this.serverEmailConfig)
|
|
105
|
+
if (!this.serverEmailConfig)
|
|
96
106
|
throw customError(5000, `You must configure the email client settings.`);
|
|
97
107
|
return await PrivateAPI.sendEmail(this.apiKey, { serverEmailConfig: this.serverEmailConfig, ...data });
|
|
98
108
|
}
|
package/dist/dymo-api.mjs
CHANGED
|
@@ -30,6 +30,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
30
30
|
const PublicAPI = __importStar(require("./branches/public"));
|
|
31
31
|
const PrivateAPI = __importStar(require("./branches/private"));
|
|
32
32
|
const config_1 = __importStar(require("./config"));
|
|
33
|
+
const autoupdate_1 = require("./services/autoupdate");
|
|
33
34
|
const customError = (code, message) => {
|
|
34
35
|
return Object.assign(new Error(), { code, message: `[${config_1.default.lib.name}] ${message}` });
|
|
35
36
|
};
|
|
@@ -45,6 +46,7 @@ class DymoAPI {
|
|
|
45
46
|
this.serverEmailConfig = serverEmailConfig;
|
|
46
47
|
this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
|
|
47
48
|
(0, config_1.setBaseUrl)(this.local);
|
|
49
|
+
this.autoupdate();
|
|
48
50
|
this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
|
|
49
51
|
}
|
|
50
52
|
getBaseUrl() {
|
|
@@ -87,12 +89,20 @@ class DymoAPI {
|
|
|
87
89
|
throw customError(5000, `Error initializing tokens: ${error.message}`);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
92
|
+
async autoupdate() {
|
|
93
|
+
try {
|
|
94
|
+
await (0, autoupdate_1.checkForUpdates)();
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw customError(5000, `Error checking the latest version in npmjs: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
90
100
|
// FUNCTIONS / Private.
|
|
91
101
|
async isValidData(data) {
|
|
92
102
|
return await PrivateAPI.isValidData(this.apiKey, data);
|
|
93
103
|
}
|
|
94
104
|
async sendEmail(data) {
|
|
95
|
-
if (this.serverEmailConfig)
|
|
105
|
+
if (!this.serverEmailConfig)
|
|
96
106
|
throw customError(5000, `You must configure the email client settings.`);
|
|
97
107
|
return await PrivateAPI.sendEmail(this.apiKey, { serverEmailConfig: this.serverEmailConfig, ...data });
|
|
98
108
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkForUpdates = checkForUpdates;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const localVersion = (0, child_process_1.execSync)(`npm list dymo-api --depth=0`).toString().match(new RegExp(`dymo-api@(\\d+\\.\\d+\\.\\d+)`))?.[1] || "0.0.0";
|
|
10
|
+
async function checkForUpdates() {
|
|
11
|
+
try {
|
|
12
|
+
const response = await axios_1.default.get(`https://registry.npmjs.org/dymo-api/latest`);
|
|
13
|
+
const latestVersion = response.data.version;
|
|
14
|
+
if (localVersion !== latestVersion)
|
|
15
|
+
console.log(`A new version of dymo-api is available: ${latestVersion}. You are using ${localVersion}. Consider updating.`);
|
|
16
|
+
else
|
|
17
|
+
console.log(`You are using the latest version of dymo-api: ${localVersion}.`);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error.response)
|
|
21
|
+
console.error("Error fetching the latest version:", error.response.data);
|
|
22
|
+
else if (error.request)
|
|
23
|
+
console.error("No response received from the server:", error.request);
|
|
24
|
+
else
|
|
25
|
+
console.error("An unknown error occurred:", error.message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
;
|
package/dist/types/dymo-api.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ interface ServerEmailConfig {
|
|
|
6
6
|
user: string;
|
|
7
7
|
pass: string;
|
|
8
8
|
};
|
|
9
|
+
dkim?: {
|
|
10
|
+
domainName: string;
|
|
11
|
+
keySelector: string;
|
|
12
|
+
privateKey: string;
|
|
13
|
+
};
|
|
9
14
|
}
|
|
10
15
|
declare class DymoAPI {
|
|
11
16
|
private rootApiKey;
|
|
@@ -23,6 +28,7 @@ declare class DymoAPI {
|
|
|
23
28
|
private getBaseUrl;
|
|
24
29
|
private getTokens;
|
|
25
30
|
private initializeTokens;
|
|
31
|
+
private autoupdate;
|
|
26
32
|
isValidData(data: any): Promise<any>;
|
|
27
33
|
sendEmail(data: any): Promise<any>;
|
|
28
34
|
getRandom(data: any): Promise<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkForUpdates(): Promise<void>;
|