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