dymo-api 1.2.5 → 1.2.6
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/functions/extractWithTextly/index.cjs +33 -0
- package/dist/cjs/branches/private/functions/getRandom/index.cjs +37 -0
- package/dist/cjs/branches/private/functions/isValidData/index.cjs +33 -0
- package/dist/cjs/branches/private/functions/isValidEmail/index.cjs +73 -0
- package/dist/cjs/branches/private/functions/sendEmail/index.cjs +88 -0
- package/dist/cjs/branches/private/index.cjs +21 -0
- package/dist/cjs/branches/public/functions/getPrayerTimes/index.cjs +31 -0
- package/dist/cjs/branches/public/functions/isValidPwd/index.cjs +65 -0
- package/dist/cjs/branches/public/functions/satinize/index.cjs +26 -0
- package/dist/cjs/branches/public/index.cjs +19 -0
- package/dist/cjs/config/index.cjs +0 -21
- package/dist/cjs/dymo-api.cjs +46 -15
- package/dist/cjs/lib/types/interfaces.cjs +0 -1
- package/dist/cjs/lib/types/well-known-bots.cjs +739 -0
- package/dist/cjs/utils/basics.cjs +18 -0
- package/dist/esm/branches/private/functions/extractWithTextly/index.js +29 -0
- package/dist/esm/branches/private/functions/getRandom/index.js +33 -0
- package/dist/esm/branches/private/functions/isValidData/index.js +29 -0
- package/dist/esm/branches/private/functions/isValidEmail/index.js +69 -0
- package/dist/esm/branches/private/functions/sendEmail/index.js +81 -0
- package/dist/esm/branches/private/index.js +5 -0
- package/dist/esm/branches/public/functions/getPrayerTimes/index.js +27 -0
- package/dist/esm/branches/{public.js → public/functions/isValidPwd/index.js} +28 -30
- package/dist/esm/branches/public/functions/satinize/index.js +22 -0
- package/dist/esm/branches/public/index.js +3 -0
- package/dist/esm/config/index.js +0 -15
- package/dist/esm/dymo-api.js +43 -15
- package/dist/esm/lib/types/interfaces.js +0 -1
- package/dist/esm/lib/types/well-known-bots.js +736 -0
- package/dist/esm/utils/basics.js +10 -0
- package/dist/types/branches/private/functions/extractWithTextly/index.d.ts +16 -0
- package/dist/types/branches/private/functions/getRandom/index.d.ts +16 -0
- package/dist/types/branches/private/functions/isValidData/index.d.ts +15 -0
- package/dist/types/branches/private/functions/isValidEmail/index.d.ts +20 -0
- package/dist/types/branches/private/functions/sendEmail/index.d.ts +18 -0
- package/dist/types/branches/private/index.d.ts +5 -0
- package/dist/types/branches/public/functions/getPrayerTimes/index.d.ts +17 -0
- package/dist/types/branches/public/functions/isValidPwd/index.d.ts +28 -0
- package/dist/types/branches/public/functions/satinize/index.d.ts +12 -0
- package/dist/types/branches/public/index.d.ts +3 -0
- package/dist/types/config/index.d.ts +0 -4
- package/dist/types/dymo-api.d.ts +18 -2
- package/dist/types/lib/types/interfaces.d.ts +0 -3
- package/dist/types/lib/types/rules.d.ts +10 -0
- package/dist/types/lib/types/well-known-bots.d.ts +4 -0
- package/dist/types/utils/basics.d.ts +2 -0
- package/package.json +13 -5
- package/dist/cjs/branches/private.cjs +0 -284
- package/dist/cjs/branches/public.cjs +0 -102
- package/dist/esm/branches/private.js +0 -240
- package/dist/types/branches/private.d.ts +0 -76
- package/dist/types/branches/public.d.ts +0 -4
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractWithTextly = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Extracts structured data from a given string using a secure endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @param token - A string or null representing the authentication token. Must not be null.
|
|
9
|
+
* @param data - An object adhering to the ExtractWithTextly interface, containing 'data' and 'format' fields.
|
|
10
|
+
* The 'data' field is the string from which structured data should be extracted.
|
|
11
|
+
* The 'format' field is an object defining the structure of the data to be extracted.
|
|
12
|
+
*
|
|
13
|
+
* @returns A promise that resolves to the response data containing the extracted structured data.
|
|
14
|
+
*
|
|
15
|
+
* @throws Will throw an error if the token is null, if 'data' or 'format' are not defined,
|
|
16
|
+
* or if an error occurs during the request to the extraction endpoint.
|
|
17
|
+
*/
|
|
18
|
+
const extractWithTextly = async (axiosClient, data) => {
|
|
19
|
+
if (!axiosClient.defaults.headers?.Authorization)
|
|
20
|
+
throw (0, basics_1.customError)(3000, "Invalid private token.");
|
|
21
|
+
if (!data.data)
|
|
22
|
+
throw (0, basics_1.customError)(1500, "No data provided.");
|
|
23
|
+
if (!data.format)
|
|
24
|
+
throw (0, basics_1.customError)(1500, "No format provided.");
|
|
25
|
+
try {
|
|
26
|
+
const response = await axiosClient.post("/private/textly/extract", data, { headers: { "Content-Type": "application/json" } });
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw (0, basics_1.customError)(5000, error.response?.data?.message || error.message);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.extractWithTextly = extractWithTextly;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandom = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a random number within a specified range using a secure endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @param token - A string or null representing the authentication token. Must not be null.
|
|
9
|
+
* @param data - An object adhering to the SRNG interface, containing 'min' and 'max' fields,
|
|
10
|
+
* which define the inclusive range within which the random number should be generated.
|
|
11
|
+
*
|
|
12
|
+
* @returns A promise that resolves to the response data containing the random number.
|
|
13
|
+
*
|
|
14
|
+
* @throws Will throw an error if the token is null, if 'min' or 'max' are not defined,
|
|
15
|
+
* if 'min' is not less than 'max', if 'min' or 'max' are out of the allowed range,
|
|
16
|
+
* or if an error occurs during the request to the random number generator endpoint.
|
|
17
|
+
*/
|
|
18
|
+
const getRandom = async (axiosClient, data) => {
|
|
19
|
+
if (!axiosClient.defaults.headers?.Authorization)
|
|
20
|
+
throw (0, basics_1.customError)(3000, "Invalid private token.");
|
|
21
|
+
if (!data.min || !data.max)
|
|
22
|
+
throw (0, basics_1.customError)(1500, "Both 'min' and 'max' parameters must be defined.");
|
|
23
|
+
if (data.min >= data.max)
|
|
24
|
+
throw (0, basics_1.customError)(1500, "'min' must be less than 'max'.");
|
|
25
|
+
if (data.min < -1000000000 || data.min > 1000000000)
|
|
26
|
+
throw (0, basics_1.customError)(1500, "'min' must be an integer in the interval [-1000000000}, 1000000000].");
|
|
27
|
+
if (data.max < -1000000000 || data.max > 1000000000)
|
|
28
|
+
throw (0, basics_1.customError)(1500, "'max' must be an integer in the interval [-1000000000}, 1000000000].");
|
|
29
|
+
try {
|
|
30
|
+
const response = await axiosClient.post("/private/srng", data, { headers: { "Content-Type": "application/json" } });
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw (0, basics_1.customError)(5000, error.response?.data?.message || error.message);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.getRandom = getRandom;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidData = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Validates the provided data using a secure verification endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @param token - A string or null representing the authentication token. Must not be null.
|
|
9
|
+
* @param data - An object adhering to the Validator interface, containing at least one of the following fields:
|
|
10
|
+
* url, email, phone, domain, creditCard, ip, wallet or user agent.
|
|
11
|
+
*
|
|
12
|
+
* @returns A promise that resolves to the response data from the verification endpoint.
|
|
13
|
+
*
|
|
14
|
+
* @throws Will throw an error if the token is null, if none of the required fields are present in the data,
|
|
15
|
+
* or if an error occurs during the verification request.
|
|
16
|
+
*/
|
|
17
|
+
const isValidData = async (axiosClient, data) => {
|
|
18
|
+
if (!axiosClient.defaults.headers?.Authorization)
|
|
19
|
+
throw (0, basics_1.customError)(3000, "Invalid private token.");
|
|
20
|
+
if (!Object.keys(data).some((key) => ["url", "email", "phone", "domain", "creditCard", "ip", "wallet", "userAgent"].includes(key) && data.hasOwnProperty(key)))
|
|
21
|
+
throw (0, basics_1.customError)(1500, "You must provide at least one parameter.");
|
|
22
|
+
try {
|
|
23
|
+
const response = await axiosClient.post("/private/secure/verify", data, { headers: { "Content-Type": "application/json" } });
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const statusCode = error.response?.status || 500;
|
|
28
|
+
const errorMessage = error.response?.data?.message || error.message;
|
|
29
|
+
const errorDetails = JSON.stringify(error.response?.data || {});
|
|
30
|
+
throw (0, basics_1.customError)(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.isValidData = isValidData;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidEmail = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Validates an email using a secure verification endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @param {string | null} token - Authentication token (required).
|
|
9
|
+
* @param {Interfaces.EmailValidator} email - Email to validate.
|
|
10
|
+
* @param {Interfaces.EmailValidatorRules} [rules] - Deny rules. Defaults to ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"].
|
|
11
|
+
*
|
|
12
|
+
* Deny rules (some are premium ⚠️):
|
|
13
|
+
* - "FRAUD", "INVALID", "NO_MX_RECORDS" ⚠️, "PROXIED_EMAIL" ⚠️, "FREE_SUBDOMAIN" ⚠️,
|
|
14
|
+
* "PERSONAL_EMAIL", "CORPORATE_EMAIL", "NO_REPLY_EMAIL", "ROLE_ACCOUNT", "NO_REACHABLE", "HIGH_RISK_SCORE" ⚠️
|
|
15
|
+
*
|
|
16
|
+
* @returns {Promise<boolean>} True if the email passes all deny rules, false otherwise.
|
|
17
|
+
* @throws Error if token is null, rules are empty, or request fails.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const valid = await isValidEmail(apiToken, "user@example.com", { deny: ["FRAUD", "NO_MX_RECORDS"] });
|
|
21
|
+
*/
|
|
22
|
+
const isValidEmail = async (axiosClient, email, rules) => {
|
|
23
|
+
if (!axiosClient.defaults.headers?.Authorization)
|
|
24
|
+
throw (0, basics_1.customError)(3000, "Invalid private token.");
|
|
25
|
+
if (rules.deny.length === 0)
|
|
26
|
+
throw (0, basics_1.customError)(1500, "You must provide at least one deny rule.");
|
|
27
|
+
try {
|
|
28
|
+
const responseEmail = (await axiosClient.post("/private/secure/verify", {
|
|
29
|
+
email,
|
|
30
|
+
plugins: [
|
|
31
|
+
rules.deny.includes("NO_MX_RECORDS") ? "mxRecords" : undefined,
|
|
32
|
+
rules.deny.includes("NO_REACHABLE") ? "reachability" : undefined,
|
|
33
|
+
rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined
|
|
34
|
+
]
|
|
35
|
+
}, { headers: { "Content-Type": "application/json" } })).data.email;
|
|
36
|
+
let reasons = [];
|
|
37
|
+
if (rules.deny.includes("INVALID") && !responseEmail.valid)
|
|
38
|
+
reasons.push("INVALID");
|
|
39
|
+
if (rules.deny.includes("FRAUD") && responseEmail.fraud)
|
|
40
|
+
reasons.push("FRAUD");
|
|
41
|
+
if (rules.deny.includes("PROXIED_EMAIL") && responseEmail.proxiedEmail)
|
|
42
|
+
reasons.push("PROXIED_EMAIL");
|
|
43
|
+
if (rules.deny.includes("FREE_SUBDOMAIN") && responseEmail.freeSubdomain)
|
|
44
|
+
reasons.push("FREE_SUBDOMAIN");
|
|
45
|
+
if (rules.deny.includes("PERSONAL_EMAIL") && !responseEmail.corporate)
|
|
46
|
+
reasons.push("PERSONAL_EMAIL");
|
|
47
|
+
if (rules.deny.includes("CORPORATE_EMAIL") && responseEmail.corporate)
|
|
48
|
+
reasons.push("CORPORATE_EMAIL");
|
|
49
|
+
if (rules.deny.includes("NO_MX_RECORDS") && responseEmail.plugins.mxRecords.length === 0)
|
|
50
|
+
reasons.push("NO_MX_RECORDS");
|
|
51
|
+
if (rules.deny.includes("NO_REPLY_EMAIL") && responseEmail.noReply)
|
|
52
|
+
reasons.push("NO_REPLY_EMAIL");
|
|
53
|
+
if (rules.deny.includes("ROLE_ACCOUNT") && responseEmail.plugins.roleAccount)
|
|
54
|
+
reasons.push("ROLE_ACCOUNT");
|
|
55
|
+
if (rules.deny.includes("NO_REACHABLE") && !responseEmail.plugins.reachable)
|
|
56
|
+
reasons.push("NO_REACHABLE");
|
|
57
|
+
if (rules.deny.includes("HIGH_RISK_SCORE") && responseEmail.plugins.riskScore >= 80)
|
|
58
|
+
reasons.push("HIGH_RISK_SCORE");
|
|
59
|
+
return {
|
|
60
|
+
email: responseEmail.email,
|
|
61
|
+
allow: reasons.length === 0,
|
|
62
|
+
reasons,
|
|
63
|
+
response: responseEmail
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const statusCode = error.response?.status || 500;
|
|
68
|
+
const errorMessage = error.response?.data?.message || error.message;
|
|
69
|
+
const errorDetails = JSON.stringify(error.response?.data || {});
|
|
70
|
+
throw (0, basics_1.customError)(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.isValidEmail = isValidEmail;
|
|
@@ -0,0 +1,88 @@
|
|
|
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.sendEmail = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
const tw_to_css_1 = require("tw-to-css");
|
|
11
|
+
const render_1 = require("@react-email/render");
|
|
12
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
13
|
+
const convertTailwindToInlineCss = (htmlContent) => {
|
|
14
|
+
return htmlContent.replace(/class="([^"]+)"( style="([^"]+)")?/g, (match, classList, _, existingStyle) => {
|
|
15
|
+
const compiledStyles = (0, tw_to_css_1.twi)(classList, { minify: true, merge: true });
|
|
16
|
+
return match.replace(/class="[^"]+"/, "").replace(/ style="[^"]+"/, "").concat(` style="${existingStyle ? `${existingStyle.trim().slice(0, -1)}; ${compiledStyles}` : compiledStyles}"`);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Sends an email using a secure sending endpoint.
|
|
21
|
+
*
|
|
22
|
+
* @param token - A string or null representing the authentication token. Must not be null.
|
|
23
|
+
* @param data - An object adhering to the SendEmail interface, containing the following fields:
|
|
24
|
+
* 'from', 'to', 'subject', 'html' or 'react', and optionally 'attachments', 'options', 'priority', 'waitToResponse', and 'composeTailwindClasses'.
|
|
25
|
+
*
|
|
26
|
+
* @returns A promise that resolves to the response data from the sending endpoint.
|
|
27
|
+
*
|
|
28
|
+
* @throws Will throw an error if the token is null, if any of the required fields are missing,
|
|
29
|
+
* if the 'react' field is not a valid React element, if the 'attachments' field exceeds the maximum allowed size of 40 MB,
|
|
30
|
+
* or if an error occurs during the sending request.
|
|
31
|
+
*/
|
|
32
|
+
const sendEmail = async (axiosClient, data) => {
|
|
33
|
+
if (!axiosClient.defaults.headers?.Authorization)
|
|
34
|
+
throw (0, basics_1.customError)(3000, "Invalid private token.");
|
|
35
|
+
if (!data.from)
|
|
36
|
+
throw (0, basics_1.customError)(1500, "You must provide an email address from which the following will be sent.");
|
|
37
|
+
if (!data.to)
|
|
38
|
+
throw (0, basics_1.customError)(1500, "You must provide an email to be sent to.");
|
|
39
|
+
if (!data.subject)
|
|
40
|
+
throw (0, basics_1.customError)(1500, "You must provide a subject for the email to be sent.");
|
|
41
|
+
if (!data.html && !data.react && !react_1.default.isValidElement(data.react))
|
|
42
|
+
throw (0, basics_1.customError)(1500, "You must provide HTML or a React component.");
|
|
43
|
+
if (data.html && data.react)
|
|
44
|
+
throw (0, basics_1.customError)(1500, "You must provide only HTML or a React component, not both.");
|
|
45
|
+
try {
|
|
46
|
+
if (data.react) {
|
|
47
|
+
//@ts-ignore
|
|
48
|
+
data.html = await (0, render_1.render)(data.react);
|
|
49
|
+
delete data.react;
|
|
50
|
+
}
|
|
51
|
+
if (data.options && data.options.composeTailwindClasses) {
|
|
52
|
+
data.html = convertTailwindToInlineCss(data.html);
|
|
53
|
+
delete data.options.composeTailwindClasses;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw (0, basics_1.customError)(1500, `An error occurred while rendering your React component. Details: ${error}`);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
let totalSize = 0;
|
|
61
|
+
if (data.attachments && Array.isArray(data.attachments)) {
|
|
62
|
+
const processedAttachments = await Promise.all(data.attachments.map(async (attachment) => {
|
|
63
|
+
if ((attachment.path && attachment.content) || (!attachment.path && !attachment.content))
|
|
64
|
+
throw (0, basics_1.customError)(1500, "You must provide either 'path' or 'content', not both.");
|
|
65
|
+
let contentBuffer;
|
|
66
|
+
if (attachment.path)
|
|
67
|
+
contentBuffer = await promises_1.default.readFile(path_1.default.resolve(attachment.path));
|
|
68
|
+
else if (attachment.content)
|
|
69
|
+
contentBuffer = attachment.content instanceof Buffer ? attachment.content : Buffer.from(attachment.content);
|
|
70
|
+
totalSize += Buffer.byteLength(contentBuffer);
|
|
71
|
+
if (totalSize > 40 * 1024 * 1024)
|
|
72
|
+
throw (0, basics_1.customError)(1500, "Attachments exceed the maximum allowed size of 40 MB.");
|
|
73
|
+
return {
|
|
74
|
+
filename: attachment.filename || path_1.default.basename(attachment.path || ""),
|
|
75
|
+
content: contentBuffer,
|
|
76
|
+
cid: attachment.cid || attachment.filename
|
|
77
|
+
};
|
|
78
|
+
}));
|
|
79
|
+
data.attachments = processedAttachments;
|
|
80
|
+
}
|
|
81
|
+
const response = await axiosClient.post("/private/sender/sendEmail", data);
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw (0, basics_1.customError)(5000, error.response?.data?.message || error.message);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
exports.sendEmail = sendEmail;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./functions/extractWithTextly/index.cjs"), exports);
|
|
18
|
+
__exportStar(require("./functions/getRandom/index.cjs"), exports);
|
|
19
|
+
__exportStar(require("./functions/isValidData/index.cjs"), exports);
|
|
20
|
+
__exportStar(require("./functions/isValidEmail/index.cjs"), exports);
|
|
21
|
+
__exportStar(require("./functions/sendEmail/index.cjs"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrayerTimes = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the prayer times for the given location.
|
|
7
|
+
*
|
|
8
|
+
* This method requires a latitude and longitude to be provided in the
|
|
9
|
+
* data object. If either of these are not provided, it will throw an error.
|
|
10
|
+
*
|
|
11
|
+
* @param {Interfaces.PrayerTimesData} data - The data to be sent.
|
|
12
|
+
* @param {number} data.lat - The latitude of the location.
|
|
13
|
+
* @param {number} data.lon - The longitude of the location.
|
|
14
|
+
* @returns {Promise<any>} A promise that resolves to the response from the server.
|
|
15
|
+
* @throws Will throw an error if there is an issue with the prayer times retrieval process.
|
|
16
|
+
*
|
|
17
|
+
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/prayertimes)
|
|
18
|
+
*/
|
|
19
|
+
const getPrayerTimes = async (axiosClient, data) => {
|
|
20
|
+
const { lat, lon } = data;
|
|
21
|
+
if (lat === undefined || lon === undefined)
|
|
22
|
+
throw (0, basics_1.customError)(1000, "You must provide a latitude and longitude.");
|
|
23
|
+
try {
|
|
24
|
+
const response = await axiosClient.get("/public/islam/prayertimes", { params: data });
|
|
25
|
+
return response.data;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw (0, basics_1.customError)(5000, error.response?.data?.message || error.message);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.getPrayerTimes = getPrayerTimes;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidPwd = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Validates a password based on the given parameters.
|
|
7
|
+
*
|
|
8
|
+
* This method requires the password to be provided in the data object.
|
|
9
|
+
* If the password is not provided, it will throw an error. The method
|
|
10
|
+
* will validate the password against the following rules:
|
|
11
|
+
* - The password must be at least 8 characters long.
|
|
12
|
+
* - The password must be at most 32 characters long.
|
|
13
|
+
* - The password must contain at least one uppercase letter.
|
|
14
|
+
* - The password must contain at least one lowercase letter.
|
|
15
|
+
* - The password must contain at least one number.
|
|
16
|
+
* - The password must contain at least one special character.
|
|
17
|
+
* - The password must not contain any of the given banned words.
|
|
18
|
+
*
|
|
19
|
+
* @param {Interfaces.IsValidPwdData} data - The data to be sent.
|
|
20
|
+
* @param {string} [data.email] - Optional email associated with the password.
|
|
21
|
+
* @param {string} data.password - The password to be validated.
|
|
22
|
+
* @param {string | string[]} [data.bannedWords] - The list of banned words that the password must not contain.
|
|
23
|
+
* @param {number} [data.min] - Minimum length of the password. Defaults to 8 if not provided.
|
|
24
|
+
* @param {number} [data.max] - Maximum length of the password. Defaults to 32 if not provided.
|
|
25
|
+
* @returns {Promise<Interfaces.PasswordValidationResult>} A promise that resolves to the response from the server.
|
|
26
|
+
* @throws Will throw an error if there is an issue with the password validation process.
|
|
27
|
+
*
|
|
28
|
+
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/password-validator)
|
|
29
|
+
*/
|
|
30
|
+
const isValidPwd = async (axiosClient, data) => {
|
|
31
|
+
let { email, password, bannedWords, min, max } = data;
|
|
32
|
+
if (password === undefined)
|
|
33
|
+
throw (0, basics_1.customError)(1000, "You must specify at least the password.");
|
|
34
|
+
const params = { password: encodeURIComponent(password) };
|
|
35
|
+
if (email) {
|
|
36
|
+
if (!/^[a-zA-Z0-9._\-+]+@?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email))
|
|
37
|
+
throw (0, basics_1.customError)(1500, "If you provide an email address it must be valid.");
|
|
38
|
+
params.email = encodeURIComponent(email);
|
|
39
|
+
}
|
|
40
|
+
if (bannedWords) {
|
|
41
|
+
if (typeof bannedWords === "string")
|
|
42
|
+
bannedWords = bannedWords.slice(1, -1).trim().split(",").map(item => item.trim());
|
|
43
|
+
if (!Array.isArray(bannedWords) || bannedWords.length > 10)
|
|
44
|
+
throw (0, basics_1.customError)(1500, "If you provide a list of banned words; the list may not exceed 10 words and must be of array type.");
|
|
45
|
+
if (!bannedWords.every(word => typeof word === "string") || new Set(bannedWords).size !== bannedWords.length)
|
|
46
|
+
throw (0, basics_1.customError)(1500, "If you provide a list of banned words; all elements must be non-repeated strings.");
|
|
47
|
+
params.bannedWords = bannedWords;
|
|
48
|
+
}
|
|
49
|
+
if (min !== undefined && (!Number.isInteger(min) || min < 8 || min > 32))
|
|
50
|
+
throw (0, basics_1.customError)(1500, "If you provide a minimum it must be valid.");
|
|
51
|
+
if (max !== undefined && (!Number.isInteger(max) || max < 32 || max > 100))
|
|
52
|
+
throw (0, basics_1.customError)(1500, "If you provide a maximum it must be valid.");
|
|
53
|
+
if (min !== undefined)
|
|
54
|
+
params.min = min;
|
|
55
|
+
if (max !== undefined)
|
|
56
|
+
params.max = max;
|
|
57
|
+
try {
|
|
58
|
+
const response = await axiosClient.get("/public/validPwd", { params });
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw (0, basics_1.customError)(5000, error.response?.data?.message || error.message);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports.isValidPwd = isValidPwd;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.satinize = void 0;
|
|
4
|
+
const basics_1 = require("../../../../utils/basics.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Sanitizes the input, replacing any special characters with their HTML entities.
|
|
7
|
+
*
|
|
8
|
+
* @param {Interfaces.InputSatinizerData} data - The data to be sent.
|
|
9
|
+
* @param {string} data.input - The input to be sanitized.
|
|
10
|
+
* @returns {Promise<any>} A promise that resolves to the response from the server.
|
|
11
|
+
* @throws Will throw an error if there is an issue with the sanitization process.
|
|
12
|
+
*
|
|
13
|
+
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/input-satinizer)
|
|
14
|
+
*/
|
|
15
|
+
const satinize = async (axiosClient, input) => {
|
|
16
|
+
if (input === undefined)
|
|
17
|
+
throw (0, basics_1.customError)(1000, "You must specify at least the input.");
|
|
18
|
+
try {
|
|
19
|
+
const response = await axiosClient.get("/public/inputSatinizer", { params: { input: encodeURIComponent(input) } });
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw (0, basics_1.customError)(5000, error.response?.data?.message || error.message);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.satinize = satinize;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./functions/getPrayerTimes/index.cjs"), exports);
|
|
18
|
+
__exportStar(require("./functions/isValidPwd/index.cjs"), exports);
|
|
19
|
+
__exportStar(require("./functions/satinize/index.cjs"), exports);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.axiosApiUrl = exports.BASE_URL = exports.setBaseUrl = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
3
|
const config = {
|
|
9
4
|
lib: {
|
|
10
5
|
name: "Dymo API",
|
|
@@ -15,19 +10,3 @@ const config = {
|
|
|
15
10
|
}
|
|
16
11
|
};
|
|
17
12
|
exports.default = config;
|
|
18
|
-
let BASE_URL = config.env.baseUrl;
|
|
19
|
-
exports.BASE_URL = BASE_URL;
|
|
20
|
-
const setBaseUrl = (baseUrl) => {
|
|
21
|
-
if (/^(https:\/\/api\.tpeoficial\.com$|http:\/\/(localhost:\d+|dymoapi:\d+))$/.test(baseUrl))
|
|
22
|
-
exports.BASE_URL = BASE_URL = baseUrl;
|
|
23
|
-
else
|
|
24
|
-
throw new Error("[Dymo API] Invalid URL. It must be https://api.tpeoficial.com or start with http://localhost or http://dymoapi followed by a port.");
|
|
25
|
-
};
|
|
26
|
-
exports.setBaseUrl = setBaseUrl;
|
|
27
|
-
const axiosApiUrl = axios_1.default.create({
|
|
28
|
-
baseURL: `${BASE_URL}/v1`,
|
|
29
|
-
headers: {
|
|
30
|
-
"User-Agent": "DymoAPISDK/1.0.0"
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
exports.axiosApiUrl = axiosApiUrl;
|
package/dist/cjs/dymo-api.cjs
CHANGED
|
@@ -32,10 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const config_1 =
|
|
37
|
-
const PublicAPI = __importStar(require("./branches/public.cjs"));
|
|
38
|
-
const PrivateAPI = __importStar(require("./branches/private.cjs"));
|
|
39
|
+
const config_1 = __importDefault(require("./config/index.cjs"));
|
|
40
|
+
const PublicAPI = __importStar(require("./branches/public/index.cjs"));
|
|
41
|
+
const PrivateAPI = __importStar(require("./branches/private/index.cjs"));
|
|
42
|
+
const axios_1 = __importDefault(require("axios"));
|
|
43
|
+
const basics_1 = require("./utils/basics.cjs");
|
|
39
44
|
const customError = (code, message) => {
|
|
40
45
|
return Object.assign(new Error(), { code, message: `[${config_1.default.lib.name}] ${message}` });
|
|
41
46
|
};
|
|
@@ -54,20 +59,30 @@ class DymoAPI {
|
|
|
54
59
|
* @example
|
|
55
60
|
* const dymoApi = new DymoAPI({
|
|
56
61
|
* rootApiKey: "6bfb7675-6b69-4f8d-9f43-5a6f7f02c6c5",
|
|
57
|
-
* apiKey: "
|
|
62
|
+
* apiKey: "dm_4c8b7675-6b69-4f8d-9f43-5a6f7f02c6c5"
|
|
58
63
|
* });
|
|
59
64
|
*/
|
|
60
65
|
constructor({ rootApiKey = null, apiKey = null, baseUrl = "https://api.tpeoficial.com", serverEmailConfig = undefined, rules = {} } = {}) {
|
|
61
66
|
this.rules = {
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
bot: { mode: "LIVE", allow: [] },
|
|
68
|
+
email: { mode: "LIVE", deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"] },
|
|
69
|
+
sensitiveInfo: { mode: "LIVE", deny: ["EMAIL", "PHONE", "CREDIT_CARD"] },
|
|
64
70
|
...rules
|
|
65
71
|
};
|
|
66
72
|
this.rootApiKey = rootApiKey;
|
|
67
73
|
this.apiKey = apiKey;
|
|
68
74
|
this.serverEmailConfig = serverEmailConfig;
|
|
69
75
|
this.baseUrl = baseUrl;
|
|
70
|
-
|
|
76
|
+
// We created the Axios client with the appropriate settings.
|
|
77
|
+
this.axiosClient = axios_1.default.create({
|
|
78
|
+
baseURL: `${(0, basics_1.validBaseURL)(this.baseUrl)}/v1`,
|
|
79
|
+
headers: {
|
|
80
|
+
"User-Agent": "DymoAPISDK/1.0.0"
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// We set the authorization in the Axios client to make requests.
|
|
84
|
+
if (this.rootApiKey || this.apiKey)
|
|
85
|
+
this.axiosClient.defaults.headers.Authorization = `Bearer ${this.rootApiKey || this.apiKey}`;
|
|
71
86
|
}
|
|
72
87
|
;
|
|
73
88
|
// FUNCTIONS / Private.
|
|
@@ -93,7 +108,7 @@ class DymoAPI {
|
|
|
93
108
|
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier)
|
|
94
109
|
*/
|
|
95
110
|
async isValidData(data) {
|
|
96
|
-
return await PrivateAPI.isValidData(this.
|
|
111
|
+
return await PrivateAPI.isValidData(this.axiosClient, data);
|
|
97
112
|
}
|
|
98
113
|
;
|
|
99
114
|
/**
|
|
@@ -115,7 +130,7 @@ class DymoAPI {
|
|
|
115
130
|
* @see [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier)
|
|
116
131
|
*/
|
|
117
132
|
async isValidEmail(email, rules = this.rules.email) {
|
|
118
|
-
return await PrivateAPI.isValidEmail(this.
|
|
133
|
+
return await PrivateAPI.isValidEmail(this.axiosClient, email, rules);
|
|
119
134
|
}
|
|
120
135
|
;
|
|
121
136
|
/**
|
|
@@ -147,7 +162,7 @@ class DymoAPI {
|
|
|
147
162
|
async sendEmail(data) {
|
|
148
163
|
if (!this.serverEmailConfig && !this.rootApiKey)
|
|
149
164
|
console.error(`[${config_1.default.lib.name}] You must configure the email client settings.`);
|
|
150
|
-
return await PrivateAPI.sendEmail(this.
|
|
165
|
+
return await PrivateAPI.sendEmail(this.axiosClient, { serverEmailConfig: this.serverEmailConfig, ...data });
|
|
151
166
|
}
|
|
152
167
|
;
|
|
153
168
|
/**
|
|
@@ -166,7 +181,7 @@ class DymoAPI {
|
|
|
166
181
|
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/secure-random-number-generator)
|
|
167
182
|
*/
|
|
168
183
|
async getRandom(data) {
|
|
169
|
-
return await PrivateAPI.getRandom(this.
|
|
184
|
+
return await PrivateAPI.getRandom(this.axiosClient, data);
|
|
170
185
|
}
|
|
171
186
|
;
|
|
172
187
|
/**
|
|
@@ -182,7 +197,7 @@ class DymoAPI {
|
|
|
182
197
|
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/textly/text-extraction)
|
|
183
198
|
*/
|
|
184
199
|
async extractWithTextly(data) {
|
|
185
|
-
return await PrivateAPI.extractWithTextly(this.
|
|
200
|
+
return await PrivateAPI.extractWithTextly(this.axiosClient, data);
|
|
186
201
|
}
|
|
187
202
|
;
|
|
188
203
|
// FUNCTIONS / Public.
|
|
@@ -201,13 +216,14 @@ class DymoAPI {
|
|
|
201
216
|
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/prayertimes)
|
|
202
217
|
*/
|
|
203
218
|
async getPrayerTimes(data) {
|
|
204
|
-
return await PublicAPI.getPrayerTimes(data);
|
|
219
|
+
return await PublicAPI.getPrayerTimes(this.axiosClient, data);
|
|
205
220
|
}
|
|
206
221
|
;
|
|
207
222
|
/**
|
|
208
223
|
* Satinizes the input, replacing any special characters with their HTML
|
|
209
224
|
* entities.
|
|
210
225
|
*
|
|
226
|
+
* @deprecated Use `satinize` instead. This feature will be removed soon.
|
|
211
227
|
* @param {Object} data - The data to be sent.
|
|
212
228
|
* @param {string} data.input - The input to be satinized.
|
|
213
229
|
* @returns {Promise<Interfaces.SatinizedInputAnalysis>} A promise that resolves to the response from the server.
|
|
@@ -216,7 +232,22 @@ class DymoAPI {
|
|
|
216
232
|
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/input-satinizer)
|
|
217
233
|
*/
|
|
218
234
|
async satinizer(data) {
|
|
219
|
-
return await PublicAPI.
|
|
235
|
+
return await PublicAPI.satinize(this.axiosClient, data.input);
|
|
236
|
+
}
|
|
237
|
+
;
|
|
238
|
+
/**
|
|
239
|
+
* Satinizes the input, replacing any special characters with their HTML
|
|
240
|
+
* entities.
|
|
241
|
+
*
|
|
242
|
+
* @param {Object} data - The data to be sent.
|
|
243
|
+
* @param {string} data.input - The input to be satinized.
|
|
244
|
+
* @returns {Promise<Interfaces.SatinizedInputAnalysis>} A promise that resolves to the response from the server.
|
|
245
|
+
* @throws Will throw an error if there is an issue with the satinization process.
|
|
246
|
+
*
|
|
247
|
+
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/input-satinizer)
|
|
248
|
+
*/
|
|
249
|
+
async satinize(input) {
|
|
250
|
+
return await PublicAPI.satinize(this.axiosClient, input);
|
|
220
251
|
}
|
|
221
252
|
;
|
|
222
253
|
/**
|
|
@@ -245,7 +276,7 @@ class DymoAPI {
|
|
|
245
276
|
* [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/password-validator)
|
|
246
277
|
*/
|
|
247
278
|
async isValidPwd(data) {
|
|
248
|
-
return await PublicAPI.isValidPwd(data);
|
|
279
|
+
return await PublicAPI.isValidPwd(this.axiosClient, data);
|
|
249
280
|
}
|
|
250
281
|
;
|
|
251
282
|
}
|