dymo-api 1.0.55 → 1.0.57
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/branches/private.js +2 -2
- package/dist/cjs/dymo-api.js +1 -0
- package/dist/esm/branches/private.js +18 -50
- package/dist/esm/branches/public.js +11 -44
- package/dist/esm/config/index.js +4 -8
- package/dist/esm/dymo-api.js +12 -39
- package/dist/esm/lib/interfaces.js +1 -2
- package/dist/esm/services/autoupdate.js +5 -11
- package/dist/types/dymo-api.d.ts +188 -1
- package/package.json +1 -1
|
@@ -31,7 +31,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
31
31
|
const axios_1 = __importDefault(require("axios"));
|
|
32
32
|
const react_1 = __importDefault(require("react"));
|
|
33
33
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
34
|
-
const
|
|
34
|
+
const tw_to_css_1 = require("tw-to-css");
|
|
35
35
|
const config_1 = __importStar(require("../config"));
|
|
36
36
|
const render_1 = require("@react-email/render");
|
|
37
37
|
const customError = (code, message) => {
|
|
@@ -39,7 +39,7 @@ const customError = (code, message) => {
|
|
|
39
39
|
};
|
|
40
40
|
const convertTailwindToInlineCss = (htmlContent) => {
|
|
41
41
|
return htmlContent.replace(/class="([^"]+)"/g, (match, classList) => {
|
|
42
|
-
return match.replace("class", "style").replace(classList, twi(classList, { minify: true, merge: true }));
|
|
42
|
+
return match.replace("class", "style").replace(classList, (0, tw_to_css_1.twi)(classList, { minify: true, merge: true }));
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
/**
|
package/dist/cjs/dymo-api.js
CHANGED
|
@@ -1,41 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getRandom = exports.sendEmail = exports.isValidData = void 0;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const axios_1 = __importDefault(require("axios"));
|
|
32
|
-
const react_1 = __importDefault(require("react"));
|
|
33
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
34
|
-
const { twi } = require("tw-to-css");
|
|
35
|
-
const config_1 = __importStar(require("../config"));
|
|
36
|
-
const render_1 = require("@react-email/render");
|
|
1
|
+
import path from "path";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
import { twi } from "tw-to-css";
|
|
6
|
+
import config, { BASE_URL } from "../config";
|
|
7
|
+
import { render } from "@react-email/render";
|
|
37
8
|
const customError = (code, message) => {
|
|
38
|
-
return Object.assign(new Error(), { code, message: `[${
|
|
9
|
+
return Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
|
|
39
10
|
};
|
|
40
11
|
const convertTailwindToInlineCss = (htmlContent) => {
|
|
41
12
|
return htmlContent.replace(/class="([^"]+)"/g, (match, classList) => {
|
|
@@ -54,20 +25,19 @@ const convertTailwindToInlineCss = (htmlContent) => {
|
|
|
54
25
|
* @throws Will throw an error if the token is null, if none of the required fields are present in the data,
|
|
55
26
|
* or if an error occurs during the verification request.
|
|
56
27
|
*/
|
|
57
|
-
const isValidData = async (token, data) => {
|
|
28
|
+
export const isValidData = async (token, data) => {
|
|
58
29
|
if (token === null)
|
|
59
30
|
throw customError(3000, "Invalid private token.");
|
|
60
31
|
if (!Object.keys(data).some((key) => ["email", "phone", "domain", "creditCard", "ip", "wallet"].includes(key) && data.hasOwnProperty(key)))
|
|
61
32
|
throw customError(1500, "You must provide at least one parameter.");
|
|
62
33
|
try {
|
|
63
|
-
const response = await
|
|
34
|
+
const response = await axios.post(`${BASE_URL}/v1/private/secure/verify`, data, { headers: { "Authorization": token } });
|
|
64
35
|
return response.data;
|
|
65
36
|
}
|
|
66
37
|
catch (error) {
|
|
67
38
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
68
39
|
}
|
|
69
40
|
};
|
|
70
|
-
exports.isValidData = isValidData;
|
|
71
41
|
/**
|
|
72
42
|
* Sends an email using a secure sending endpoint.
|
|
73
43
|
*
|
|
@@ -81,7 +51,7 @@ exports.isValidData = isValidData;
|
|
|
81
51
|
* if the 'react' field is not a valid React element, if the 'attachments' field exceeds the maximum allowed size of 40 MB,
|
|
82
52
|
* or if an error occurs during the sending request.
|
|
83
53
|
*/
|
|
84
|
-
const sendEmail = async (token, data) => {
|
|
54
|
+
export const sendEmail = async (token, data) => {
|
|
85
55
|
if (token === null)
|
|
86
56
|
throw customError(3000, "Invalid private token.");
|
|
87
57
|
if (!data.from)
|
|
@@ -90,14 +60,14 @@ const sendEmail = async (token, data) => {
|
|
|
90
60
|
throw customError(1500, "You must provide an email to be sent to.");
|
|
91
61
|
if (!data.subject)
|
|
92
62
|
throw customError(1500, "You must provide a subject for the email to be sent.");
|
|
93
|
-
if (!data.html && !data.react && !
|
|
63
|
+
if (!data.html && !data.react && !React.isValidElement(data.react))
|
|
94
64
|
throw customError(1500, "You must provide HTML or a React component.");
|
|
95
65
|
if (data.html && data.react)
|
|
96
66
|
throw customError(1500, "You must provide only HTML or a React component, not both.");
|
|
97
67
|
try {
|
|
98
68
|
if (data.react) {
|
|
99
69
|
//@ts-ignore
|
|
100
|
-
data.html = await
|
|
70
|
+
data.html = await render(data.react);
|
|
101
71
|
delete data.react;
|
|
102
72
|
}
|
|
103
73
|
if (data.options && data.options.composeTailwindClasses) {
|
|
@@ -116,28 +86,27 @@ const sendEmail = async (token, data) => {
|
|
|
116
86
|
throw customError(1500, "You must provide either 'path' or 'content', not both.");
|
|
117
87
|
let contentBuffer;
|
|
118
88
|
if (attachment.path)
|
|
119
|
-
contentBuffer = await
|
|
89
|
+
contentBuffer = await fs.readFile(path.resolve(attachment.path));
|
|
120
90
|
else if (attachment.content)
|
|
121
91
|
contentBuffer = attachment.content instanceof Buffer ? attachment.content : Buffer.from(attachment.content);
|
|
122
92
|
totalSize += Buffer.byteLength(contentBuffer);
|
|
123
93
|
if (totalSize > 40 * 1024 * 1024)
|
|
124
94
|
throw customError(1500, "Attachments exceed the maximum allowed size of 40 MB.");
|
|
125
95
|
return {
|
|
126
|
-
filename: attachment.filename ||
|
|
96
|
+
filename: attachment.filename || path.basename(attachment.path || ""),
|
|
127
97
|
content: contentBuffer,
|
|
128
98
|
cid: attachment.cid || attachment.filename
|
|
129
99
|
};
|
|
130
100
|
}));
|
|
131
101
|
data.attachments = processedAttachments;
|
|
132
102
|
}
|
|
133
|
-
const response = await
|
|
103
|
+
const response = await axios.post(`${BASE_URL}/v1/private/sender/sendEmail`, data, { headers: { "Authorization": token } });
|
|
134
104
|
return response.data;
|
|
135
105
|
}
|
|
136
106
|
catch (error) {
|
|
137
107
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
138
108
|
}
|
|
139
109
|
};
|
|
140
|
-
exports.sendEmail = sendEmail;
|
|
141
110
|
/**
|
|
142
111
|
* Retrieves a random number within a specified range using a secure endpoint.
|
|
143
112
|
*
|
|
@@ -151,7 +120,7 @@ exports.sendEmail = sendEmail;
|
|
|
151
120
|
* if 'min' is not less than 'max', if 'min' or 'max' are out of the allowed range,
|
|
152
121
|
* or if an error occurs during the request to the random number generator endpoint.
|
|
153
122
|
*/
|
|
154
|
-
const getRandom = async (token, data) => {
|
|
123
|
+
export const getRandom = async (token, data) => {
|
|
155
124
|
if (token === null)
|
|
156
125
|
throw customError(3000, "Invalid private token.");
|
|
157
126
|
if (!data.min || !data.max)
|
|
@@ -163,11 +132,10 @@ const getRandom = async (token, data) => {
|
|
|
163
132
|
if (data.max < -1000000000 || data.max > 1000000000)
|
|
164
133
|
throw customError(1500, "'max' must be an integer in the interval [-1000000000}, 1000000000].");
|
|
165
134
|
try {
|
|
166
|
-
const response = await
|
|
135
|
+
const response = await axios.post(`${BASE_URL}/v1/private/srng`, data, { headers: { "Authorization": token } });
|
|
167
136
|
return response.data;
|
|
168
137
|
}
|
|
169
138
|
catch (error) {
|
|
170
139
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
171
140
|
}
|
|
172
141
|
};
|
|
173
|
-
exports.getRandom = getRandom;
|
|
@@ -1,68 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.newURLEncrypt = exports.isValidPwd = exports.satinizer = exports.getPrayerTimes = void 0;
|
|
30
|
-
const axios_1 = __importDefault(require("axios"));
|
|
31
|
-
const config_1 = __importStar(require("../config"));
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import config, { BASE_URL } from "../config";
|
|
32
3
|
const customError = (code, message) => {
|
|
33
|
-
return Object.assign(new Error(), { code, message: `[${
|
|
4
|
+
return Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
|
|
34
5
|
};
|
|
35
6
|
;
|
|
36
7
|
;
|
|
37
8
|
;
|
|
38
9
|
;
|
|
39
|
-
const getPrayerTimes = async (data) => {
|
|
10
|
+
export const getPrayerTimes = async (data) => {
|
|
40
11
|
const { lat, lon } = data;
|
|
41
12
|
if (lat === undefined || lon === undefined)
|
|
42
13
|
throw customError(1000, "You must provide a latitude and longitude.");
|
|
43
14
|
try {
|
|
44
|
-
const response = await
|
|
15
|
+
const response = await axios.get(`${BASE_URL}/v1/public/islam/prayertimes`, { params: data });
|
|
45
16
|
return response.data;
|
|
46
17
|
}
|
|
47
18
|
catch (error) {
|
|
48
19
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
49
20
|
}
|
|
50
21
|
};
|
|
51
|
-
|
|
52
|
-
const satinizer = async (data) => {
|
|
22
|
+
export const satinizer = async (data) => {
|
|
53
23
|
const { input } = data;
|
|
54
24
|
if (input === undefined)
|
|
55
25
|
throw customError(1000, "You must specify at least the input.");
|
|
56
26
|
try {
|
|
57
|
-
const response = await
|
|
27
|
+
const response = await axios.get(`${BASE_URL}/v1/public/inputSatinizer`, { params: { input: encodeURIComponent(input) } });
|
|
58
28
|
return response.data;
|
|
59
29
|
}
|
|
60
30
|
catch (error) {
|
|
61
31
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
62
32
|
}
|
|
63
33
|
};
|
|
64
|
-
|
|
65
|
-
const isValidPwd = async (data) => {
|
|
34
|
+
export const isValidPwd = async (data) => {
|
|
66
35
|
let { email, password, bannedWords, min, max } = data;
|
|
67
36
|
if (password === undefined)
|
|
68
37
|
throw customError(1000, "You must specify at least the password.");
|
|
@@ -90,24 +59,22 @@ const isValidPwd = async (data) => {
|
|
|
90
59
|
if (max !== undefined)
|
|
91
60
|
params.max = max;
|
|
92
61
|
try {
|
|
93
|
-
const response = await
|
|
62
|
+
const response = await axios.get(`${BASE_URL}/v1/public/validPwd`, { params });
|
|
94
63
|
return response.data;
|
|
95
64
|
}
|
|
96
65
|
catch (error) {
|
|
97
66
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
98
67
|
}
|
|
99
68
|
};
|
|
100
|
-
|
|
101
|
-
const newURLEncrypt = async (data) => {
|
|
69
|
+
export const newURLEncrypt = async (data) => {
|
|
102
70
|
const { url } = data;
|
|
103
71
|
if (url === undefined || (!url.startsWith("https://") && !url.startsWith("http://")))
|
|
104
72
|
throw customError(1500, "You must provide a valid url.");
|
|
105
73
|
try {
|
|
106
|
-
const response = await
|
|
74
|
+
const response = await axios.get(`${BASE_URL}/v1/public/url-encrypt`, { params: data });
|
|
107
75
|
return response.data;
|
|
108
76
|
}
|
|
109
77
|
catch (error) {
|
|
110
78
|
throw customError(5000, error.response?.data?.message || error.message);
|
|
111
79
|
}
|
|
112
80
|
};
|
|
113
|
-
exports.newURLEncrypt = newURLEncrypt;
|
package/dist/esm/config/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BASE_URL = exports.setBaseUrl = void 0;
|
|
4
1
|
const config = {
|
|
5
2
|
lib: {
|
|
6
3
|
name: "Dymo API",
|
|
@@ -10,10 +7,9 @@ const config = {
|
|
|
10
7
|
baseUrl: "https://api.tpeoficial.com"
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
export default config;
|
|
14
11
|
let BASE_URL = config.env.baseUrl;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.BASE_URL = BASE_URL = isLocal ? "http://localhost:3050" : config.env.baseUrl;
|
|
12
|
+
export const setBaseUrl = (isLocal) => {
|
|
13
|
+
BASE_URL = isLocal ? "http://localhost:3050" : config.env.baseUrl;
|
|
18
14
|
};
|
|
19
|
-
|
|
15
|
+
export { BASE_URL };
|
package/dist/esm/dymo-api.js
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const axios_1 = __importDefault(require("axios"));
|
|
30
|
-
const PublicAPI = __importStar(require("./branches/public"));
|
|
31
|
-
const PrivateAPI = __importStar(require("./branches/private"));
|
|
32
|
-
const config_1 = __importStar(require("./config"));
|
|
33
|
-
const autoupdate_1 = require("./services/autoupdate");
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import * as PublicAPI from "./branches/public";
|
|
3
|
+
import * as PrivateAPI from "./branches/private";
|
|
4
|
+
import config, { BASE_URL, setBaseUrl } from "./config";
|
|
5
|
+
import { checkForUpdates } from "./services/autoupdate";
|
|
34
6
|
const customError = (code, message) => {
|
|
35
|
-
return Object.assign(new Error(), { code, message: `[${
|
|
7
|
+
return Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
|
|
36
8
|
};
|
|
37
9
|
;
|
|
38
10
|
;
|
|
@@ -63,7 +35,7 @@ class DymoAPI {
|
|
|
63
35
|
this.lastFetchTime = null;
|
|
64
36
|
this.serverEmailConfig = serverEmailConfig;
|
|
65
37
|
this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
|
|
66
|
-
|
|
38
|
+
setBaseUrl(this.local);
|
|
67
39
|
this.autoupdate();
|
|
68
40
|
this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
|
|
69
41
|
}
|
|
@@ -85,7 +57,7 @@ class DymoAPI {
|
|
|
85
57
|
async getTokens() {
|
|
86
58
|
const currentTime = new Date();
|
|
87
59
|
if (this.tokensResponse && this.lastFetchTime && (currentTime.getTime() - this.lastFetchTime.getTime()) < 5 * 60 * 1000) {
|
|
88
|
-
console.log(`[${
|
|
60
|
+
console.log(`[${config.lib.name}] Using cached tokens response.`);
|
|
89
61
|
return this.tokensResponse;
|
|
90
62
|
}
|
|
91
63
|
;
|
|
@@ -97,14 +69,14 @@ class DymoAPI {
|
|
|
97
69
|
try {
|
|
98
70
|
if (Object.keys(tokens).length === 0)
|
|
99
71
|
return;
|
|
100
|
-
const response = await
|
|
72
|
+
const response = await axios.post(`${BASE_URL}/v1/dvr/tokens`, { tokens });
|
|
101
73
|
if (tokens.root && response.data.root === false)
|
|
102
74
|
throw customError(3000, "Invalid root token.");
|
|
103
75
|
if (tokens.api && response.data.api === false)
|
|
104
76
|
throw customError(3000, "Invalid API token.");
|
|
105
77
|
this.tokensResponse = response.data;
|
|
106
78
|
this.lastFetchTime = currentTime;
|
|
107
|
-
console.log(`[${
|
|
79
|
+
console.log(`[${config.lib.name}] Tokens initialized successfully.`);
|
|
108
80
|
return this.tokensResponse;
|
|
109
81
|
}
|
|
110
82
|
catch (error) {
|
|
@@ -139,7 +111,7 @@ class DymoAPI {
|
|
|
139
111
|
*/
|
|
140
112
|
async autoupdate() {
|
|
141
113
|
try {
|
|
142
|
-
await
|
|
114
|
+
await checkForUpdates();
|
|
143
115
|
}
|
|
144
116
|
catch (error) {
|
|
145
117
|
throw customError(5000, `Error checking the latest version in npmjs: ${error.message}`);
|
|
@@ -269,3 +241,4 @@ class DymoAPI {
|
|
|
269
241
|
return await PublicAPI.newURLEncrypt(data);
|
|
270
242
|
}
|
|
271
243
|
}
|
|
244
|
+
export default DymoAPI;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
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"));
|
|
1
|
+
import axios from "axios";
|
|
8
2
|
//@ts-ignore
|
|
9
|
-
|
|
10
|
-
const localVersion =
|
|
11
|
-
async function checkForUpdates() {
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
const localVersion = execSync("npm list dymo-api --depth=0").toString().match(new RegExp("dymo-api@(\\d+\\.\\d+\\.\\d+)"))?.[1] || "0.0.0";
|
|
5
|
+
export async function checkForUpdates() {
|
|
12
6
|
try {
|
|
13
|
-
const response = await
|
|
7
|
+
const response = await axios.get("https://registry.npmjs.org/dymo-api/latest");
|
|
14
8
|
const latestVersion = response.data.version;
|
|
15
9
|
if (localVersion !== latestVersion)
|
|
16
10
|
console.log(`[Dymo API] A new version of dymo-api is available: ${latestVersion}. You are using ${localVersion}. Consider updating.`);
|
package/dist/types/dymo-api.d.ts
CHANGED
|
@@ -1 +1,188 @@
|
|
|
1
|
-
|
|
1
|
+
interface ServerEmailConfig {
|
|
2
|
+
host: string;
|
|
3
|
+
port: number;
|
|
4
|
+
secure: boolean;
|
|
5
|
+
auth: {
|
|
6
|
+
user: string;
|
|
7
|
+
pass: string;
|
|
8
|
+
};
|
|
9
|
+
dkim?: {
|
|
10
|
+
domainName: string;
|
|
11
|
+
keySelector: string;
|
|
12
|
+
privateKey: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
declare class DymoAPI {
|
|
16
|
+
private rootApiKey;
|
|
17
|
+
private apiKey;
|
|
18
|
+
private tokensResponse;
|
|
19
|
+
private lastFetchTime;
|
|
20
|
+
private serverEmailConfig?;
|
|
21
|
+
private local;
|
|
22
|
+
/**
|
|
23
|
+
* @param {Object} options - Options to create the DymoAPI instance.
|
|
24
|
+
* @param {string} [options.rootApiKey] - The root API key.
|
|
25
|
+
* @param {string} [options.apiKey] - The API key.
|
|
26
|
+
* @param {boolean} [options.local] - Whether to use a local server instead of the cloud server.
|
|
27
|
+
* @param {Object} [options.serverEmailConfig] - The server email config.
|
|
28
|
+
* @description
|
|
29
|
+
* This is the main class to interact with the Dymo API. It should be
|
|
30
|
+
* instantiated with the root API key and the API key. The root API key is
|
|
31
|
+
* used to fetch the tokens and the API key is used to authenticate the
|
|
32
|
+
* requests.
|
|
33
|
+
* @example
|
|
34
|
+
* const dymoApi = new DymoAPI({
|
|
35
|
+
* rootApiKey: "6bfb7675-6b69-4f8d-9f43-5a6f7f02c6c5",
|
|
36
|
+
* apiKey: "4c8b7675-6b69-4f8d-9f43-5a6f7f02c6c5",
|
|
37
|
+
* local: true
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
constructor({ rootApiKey, apiKey, local, serverEmailConfig }: {
|
|
41
|
+
rootApiKey?: string | null;
|
|
42
|
+
apiKey?: string | null;
|
|
43
|
+
local?: boolean;
|
|
44
|
+
serverEmailConfig?: ServerEmailConfig;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves and caches authentication tokens.
|
|
48
|
+
*
|
|
49
|
+
* This method checks if cached tokens are available and valid. If so, it returns
|
|
50
|
+
* the cached tokens. Otherwise, it generates new tokens using the provided API keys
|
|
51
|
+
* and caches them. The tokens are fetched from the server using a POST request.
|
|
52
|
+
*
|
|
53
|
+
* The method also handles validation of root and API tokens, throwing errors if
|
|
54
|
+
* any of the tokens are invalid. Cached tokens are considered valid for 5 minutes.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Promise<Object|undefined>} A promise that resolves to the tokens response
|
|
57
|
+
* if successful, or undefined if no tokens are available.
|
|
58
|
+
* @throws Will throw an error if token validation fails, or if there is an issue
|
|
59
|
+
* with the token retrieval process.
|
|
60
|
+
*/
|
|
61
|
+
private getTokens;
|
|
62
|
+
/**
|
|
63
|
+
* Initializes the tokens response by calling getTokens().
|
|
64
|
+
*
|
|
65
|
+
* This method is called in the constructor and will throw an error if the
|
|
66
|
+
* initialization process fails.
|
|
67
|
+
*
|
|
68
|
+
* @throws Will throw an error if there is an issue with the token retrieval
|
|
69
|
+
* process.
|
|
70
|
+
*/
|
|
71
|
+
private initializeTokens;
|
|
72
|
+
/**
|
|
73
|
+
* Checks for updates and logs a message if a new version is available.
|
|
74
|
+
*
|
|
75
|
+
* This method is called in the constructor and will throw an error if the
|
|
76
|
+
* update check fails.
|
|
77
|
+
*
|
|
78
|
+
* @throws Will throw an error if there is an issue with the update check
|
|
79
|
+
* process.
|
|
80
|
+
*/
|
|
81
|
+
private autoupdate;
|
|
82
|
+
/**
|
|
83
|
+
* Validates the given data against the configured validation settings.
|
|
84
|
+
*
|
|
85
|
+
* This method requires either the root API key or the API key to be set.
|
|
86
|
+
* If neither is set, it will throw an error.
|
|
87
|
+
*
|
|
88
|
+
* @param {Object} data - The data to be validated.
|
|
89
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
90
|
+
* @throws Will throw an error if there is an issue with the validation process.
|
|
91
|
+
*/
|
|
92
|
+
isValidData(data: any): Promise<any>;
|
|
93
|
+
/**
|
|
94
|
+
* Sends an email using the configured email client settings.
|
|
95
|
+
*
|
|
96
|
+
* This method requires either the root API key or the server email config to be set.
|
|
97
|
+
* If neither is set, it will throw an error.
|
|
98
|
+
*
|
|
99
|
+
* @param {Object} data - The email data to be sent.
|
|
100
|
+
* @param {string} data.from - The email address from which the email will be sent.
|
|
101
|
+
* @param {string} data.to - The email address to which the email will be sent.
|
|
102
|
+
* @param {string} data.subject - The subject of the email.
|
|
103
|
+
* @param {string} [data.html] - The HTML content of the email.
|
|
104
|
+
* @param {React.ReactElement} [data.react] - The React component to be rendered as the email content.
|
|
105
|
+
* @param {Object} [data.options] - Content configuration options.
|
|
106
|
+
* @param {"high" | "normal" | "low" | undefined} [data.options.priority="normal"] - Email priority (default: normal).
|
|
107
|
+
* @param {boolean} [data.options.waitToResponse=true] - Wait until the email is sent (default: true).
|
|
108
|
+
* @param {boolean} [data.options.composeTailwindClasses] - Whether to compose tailwind classes.
|
|
109
|
+
* @param {Attachment[]} [data.attachments] - An array of attachments to be included in the email.
|
|
110
|
+
* @param {string} data.attachments[].filename - The name of the attached file.
|
|
111
|
+
* @param {string} [data.attachments[].path] - The path or URL of the attached file. Either this or `content` must be provided.
|
|
112
|
+
* @param {Buffer} [data.attachments[].content] - The content of the attached file as a Buffer. Either this or `path` must be provided.
|
|
113
|
+
* @param {string} [data.attachments[].cid] - The CID (Content-ID) of the attached file, used for inline images.
|
|
114
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
115
|
+
* @throws Will throw an error if there is an issue with the email sending process.
|
|
116
|
+
*/
|
|
117
|
+
sendEmail(data: any): Promise<any>;
|
|
118
|
+
/**
|
|
119
|
+
* Generates a random number between the provided min and max values.
|
|
120
|
+
*
|
|
121
|
+
* This method requires either the root API key or the API key to be set.
|
|
122
|
+
* If neither is set, it will throw an error.
|
|
123
|
+
*
|
|
124
|
+
* @param {Object} data - The data to be sent.
|
|
125
|
+
* @param {number} data.min - The minimum value of the range.
|
|
126
|
+
* @param {number} data.max - The maximum value of the range.
|
|
127
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
128
|
+
* @throws Will throw an error if there is an issue with the random number generation process.
|
|
129
|
+
*/
|
|
130
|
+
getRandom(data: any): Promise<any>;
|
|
131
|
+
/**
|
|
132
|
+
* Retrieves the prayer times for the given location.
|
|
133
|
+
*
|
|
134
|
+
* This method requires a latitude and longitude to be provided in the
|
|
135
|
+
* data object. If either of these are not provided, it will throw an error.
|
|
136
|
+
*
|
|
137
|
+
* @param {Object} data - The data to be sent.
|
|
138
|
+
* @param {number} data.lat - The latitude of the location.
|
|
139
|
+
* @param {number} data.lon - The longitude of the location.
|
|
140
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
141
|
+
* @throws Will throw an error if there is an issue with the prayer times retrieval process.
|
|
142
|
+
*/
|
|
143
|
+
getPrayerTimes(data: any): Promise<any>;
|
|
144
|
+
/**
|
|
145
|
+
* Satinizes the input, replacing any special characters with their HTML
|
|
146
|
+
* entities.
|
|
147
|
+
*
|
|
148
|
+
* @param {Object} data - The data to be sent.
|
|
149
|
+
* @param {string} data.input - The input to be satinized.
|
|
150
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
151
|
+
* @throws Will throw an error if there is an issue with the satinization process.
|
|
152
|
+
*/
|
|
153
|
+
satinizer(data: any): Promise<any>;
|
|
154
|
+
/**
|
|
155
|
+
* Validates a password based on the given parameters.
|
|
156
|
+
*
|
|
157
|
+
* This method requires the password to be provided in the data object.
|
|
158
|
+
* If the password is not provided, it will throw an error. The method
|
|
159
|
+
* will validate the password against the following rules:
|
|
160
|
+
* - The password must be at least 8 characters long.
|
|
161
|
+
* - The password must be at most 32 characters long.
|
|
162
|
+
* - The password must contain at least one uppercase letter.
|
|
163
|
+
* - The password must contain at least one lowercase letter.
|
|
164
|
+
* - The password must contain at least one number.
|
|
165
|
+
* - The password must contain at least one special character.
|
|
166
|
+
* - The password must not contain any of the given banned words.
|
|
167
|
+
*
|
|
168
|
+
* @param {Object} data - The data to be sent.
|
|
169
|
+
* @param {string} data.password - The password to be validated.
|
|
170
|
+
* @param {string[]} [data.bannedWords] - The list of banned words that the password must not contain.
|
|
171
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
172
|
+
* @throws Will throw an error if there is an issue with the password validation process.
|
|
173
|
+
*/
|
|
174
|
+
isValidPwd(data: any): Promise<any>;
|
|
175
|
+
/**
|
|
176
|
+
* Encrypts a URL using the configured encryption settings.
|
|
177
|
+
*
|
|
178
|
+
* This method requires the URL to be provided in the data object.
|
|
179
|
+
* If the URL is not provided, it will throw an error.
|
|
180
|
+
*
|
|
181
|
+
* @param {Object} data - The data to be sent.
|
|
182
|
+
* @param {string} data.url - The URL to be encrypted.
|
|
183
|
+
* @returns {Promise<Object>} A promise that resolves to the response from the server.
|
|
184
|
+
* @throws Will throw an error if there is an issue with the URL encryption process.
|
|
185
|
+
*/
|
|
186
|
+
newURLEncrypt(data: any): Promise<any>;
|
|
187
|
+
}
|
|
188
|
+
export default DymoAPI;
|