dymo-api 1.2.32 → 1.2.33

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 (97) hide show
  1. package/dist/cjs/dymo-api.cjs +1123 -393
  2. package/dist/esm/dymo-api.js +1125 -356
  3. package/dist/types/branches/private/functions/extractWithTextly/index.d.ts +3 -2
  4. package/dist/types/branches/private/functions/extractWithTextly/index.d.ts.map +1 -0
  5. package/dist/types/branches/private/functions/getRandom/index.d.ts +3 -2
  6. package/dist/types/branches/private/functions/getRandom/index.d.ts.map +1 -0
  7. package/dist/types/branches/private/functions/isValidDataRaw/index.d.ts +3 -2
  8. package/dist/types/branches/private/functions/isValidDataRaw/index.d.ts.map +1 -0
  9. package/dist/types/branches/private/functions/isValidEmail/index.d.ts +3 -2
  10. package/dist/types/branches/private/functions/isValidEmail/index.d.ts.map +1 -0
  11. package/dist/types/branches/private/functions/isValidIP/index.d.ts +3 -2
  12. package/dist/types/branches/private/functions/isValidIP/index.d.ts.map +1 -0
  13. package/dist/types/branches/private/functions/isValidPhone/index.d.ts +3 -2
  14. package/dist/types/branches/private/functions/isValidPhone/index.d.ts.map +1 -0
  15. package/dist/types/branches/private/functions/protectReq/index.d.ts +3 -2
  16. package/dist/types/branches/private/functions/protectReq/index.d.ts.map +1 -0
  17. package/dist/types/branches/private/functions/protectReq/requestHandler.d.ts +1 -0
  18. package/dist/types/branches/private/functions/protectReq/requestHandler.d.ts.map +1 -0
  19. package/dist/types/branches/private/functions/sendEmail/index.d.ts +3 -2
  20. package/dist/types/branches/private/functions/sendEmail/index.d.ts.map +1 -0
  21. package/dist/types/branches/private/index.d.ts +9 -8
  22. package/dist/types/branches/private/index.d.ts.map +1 -0
  23. package/dist/types/branches/public/functions/getPrayerTimes/index.d.ts +3 -2
  24. package/dist/types/branches/public/functions/getPrayerTimes/index.d.ts.map +1 -0
  25. package/dist/types/branches/public/functions/isValidPwd/index.d.ts +3 -2
  26. package/dist/types/branches/public/functions/isValidPwd/index.d.ts.map +1 -0
  27. package/dist/types/branches/public/functions/satinize/index.d.ts +2 -1
  28. package/dist/types/branches/public/functions/satinize/index.d.ts.map +1 -0
  29. package/dist/types/branches/public/index.d.ts +4 -3
  30. package/dist/types/branches/public/index.d.ts.map +1 -0
  31. package/dist/types/config/index.d.ts +1 -0
  32. package/dist/types/config/index.d.ts.map +1 -0
  33. package/dist/types/dymo-api.d.ts +2 -1
  34. package/dist/types/dymo-api.d.ts.map +1 -0
  35. package/dist/types/lib/resilience/fallback.d.ts +1 -0
  36. package/dist/types/lib/resilience/fallback.d.ts.map +1 -0
  37. package/dist/types/lib/resilience/index.d.ts +3 -2
  38. package/dist/types/lib/resilience/index.d.ts.map +1 -0
  39. package/dist/types/lib/types/data-verifier.d.ts +3 -2
  40. package/dist/types/lib/types/data-verifier.d.ts.map +1 -0
  41. package/dist/types/lib/types/interfaces.d.ts +5 -4
  42. package/dist/types/lib/types/interfaces.d.ts.map +1 -0
  43. package/dist/types/lib/types/primitives.d.ts +1 -0
  44. package/dist/types/lib/types/primitives.d.ts.map +1 -0
  45. package/dist/types/lib/types/rules.d.ts +2 -1
  46. package/dist/types/lib/types/rules.d.ts.map +1 -0
  47. package/dist/types/lib/types/well-known-bots.d.ts +1 -0
  48. package/dist/types/lib/types/well-known-bots.d.ts.map +1 -0
  49. package/dist/types/utils/basics.d.ts +1 -0
  50. package/dist/types/utils/basics.d.ts.map +1 -0
  51. package/package.json +8 -9
  52. package/dist/cjs/branches/private/functions/extractWithTextly/index.cjs +0 -33
  53. package/dist/cjs/branches/private/functions/getRandom/index.cjs +0 -37
  54. package/dist/cjs/branches/private/functions/isValidDataRaw/index.cjs +0 -33
  55. package/dist/cjs/branches/private/functions/isValidEmail/index.cjs +0 -91
  56. package/dist/cjs/branches/private/functions/isValidIP/index.cjs +0 -80
  57. package/dist/cjs/branches/private/functions/isValidPhone/index.cjs +0 -77
  58. package/dist/cjs/branches/private/functions/protectReq/index.cjs +0 -74
  59. package/dist/cjs/branches/private/functions/protectReq/requestHandler.cjs +0 -22
  60. package/dist/cjs/branches/private/functions/sendEmail/index.cjs +0 -88
  61. package/dist/cjs/branches/private/index.cjs +0 -24
  62. package/dist/cjs/branches/public/functions/getPrayerTimes/index.cjs +0 -31
  63. package/dist/cjs/branches/public/functions/isValidPwd/index.cjs +0 -65
  64. package/dist/cjs/branches/public/functions/satinize/index.cjs +0 -26
  65. package/dist/cjs/branches/public/index.cjs +0 -19
  66. package/dist/cjs/config/index.cjs +0 -12
  67. package/dist/cjs/lib/resilience/fallback.cjs +0 -427
  68. package/dist/cjs/lib/resilience/index.cjs +0 -135
  69. package/dist/cjs/lib/types/data-verifier.cjs +0 -2
  70. package/dist/cjs/lib/types/interfaces.cjs +0 -24
  71. package/dist/cjs/lib/types/primitives.cjs +0 -2
  72. package/dist/cjs/lib/types/rules.cjs +0 -2
  73. package/dist/cjs/lib/types/well-known-bots.cjs +0 -739
  74. package/dist/cjs/utils/basics.cjs +0 -18
  75. package/dist/esm/branches/private/functions/extractWithTextly/index.js +0 -29
  76. package/dist/esm/branches/private/functions/getRandom/index.js +0 -33
  77. package/dist/esm/branches/private/functions/isValidDataRaw/index.js +0 -29
  78. package/dist/esm/branches/private/functions/isValidEmail/index.js +0 -87
  79. package/dist/esm/branches/private/functions/isValidIP/index.js +0 -76
  80. package/dist/esm/branches/private/functions/isValidPhone/index.js +0 -73
  81. package/dist/esm/branches/private/functions/protectReq/index.js +0 -37
  82. package/dist/esm/branches/private/functions/protectReq/requestHandler.js +0 -18
  83. package/dist/esm/branches/private/functions/sendEmail/index.js +0 -81
  84. package/dist/esm/branches/private/index.js +0 -8
  85. package/dist/esm/branches/public/functions/getPrayerTimes/index.js +0 -27
  86. package/dist/esm/branches/public/functions/isValidPwd/index.js +0 -61
  87. package/dist/esm/branches/public/functions/satinize/index.js +0 -22
  88. package/dist/esm/branches/public/index.js +0 -3
  89. package/dist/esm/config/index.js +0 -10
  90. package/dist/esm/lib/resilience/fallback.js +0 -423
  91. package/dist/esm/lib/resilience/index.js +0 -131
  92. package/dist/esm/lib/types/data-verifier.js +0 -1
  93. package/dist/esm/lib/types/interfaces.js +0 -8
  94. package/dist/esm/lib/types/primitives.js +0 -1
  95. package/dist/esm/lib/types/rules.js +0 -1
  96. package/dist/esm/lib/types/well-known-bots.js +0 -736
  97. package/dist/esm/utils/basics.js +0 -10
@@ -1,18 +0,0 @@
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;
@@ -1,29 +0,0 @@
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
- };
@@ -1,33 +0,0 @@
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
- };
@@ -1,29 +0,0 @@
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, user agent or iban.
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 isValidDataRaw = 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", "iban"].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
- };
@@ -1,87 +0,0 @@
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", "NO_GRAVATAR" "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
- if (rules.mode === "DRY_RUN") {
25
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
26
- return {
27
- email,
28
- allow: true,
29
- reasons: [],
30
- response: "CHANGE TO LIVE MODE"
31
- };
32
- }
33
- try {
34
- const responseEmail = (await axiosClient.post("/private/secure/verify", {
35
- email,
36
- plugins: [
37
- rules.deny.includes("NO_MX_RECORDS") ? "mxRecords" : undefined,
38
- rules.deny.includes("NO_REACHABLE") ? "reachable" : undefined,
39
- rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined,
40
- rules.deny.includes("NO_GRAVATAR") ? "gravatar" : undefined
41
- ].filter(Boolean)
42
- }, { headers: { "Content-Type": "application/json" } })).data.email;
43
- let reasons = [];
44
- if (rules.deny.includes("INVALID") && !responseEmail.valid) {
45
- return {
46
- email: responseEmail.email,
47
- allow: false,
48
- reasons: ["INVALID"],
49
- response: responseEmail
50
- };
51
- }
52
- if (rules.deny.includes("FRAUD") && responseEmail.fraud)
53
- reasons.push("FRAUD");
54
- if (rules.deny.includes("PROXIED_EMAIL") && responseEmail.proxiedEmail)
55
- reasons.push("PROXIED_EMAIL");
56
- if (rules.deny.includes("FREE_SUBDOMAIN") && responseEmail.freeSubdomain)
57
- reasons.push("FREE_SUBDOMAIN");
58
- if (rules.deny.includes("PERSONAL_EMAIL") && !responseEmail.corporate)
59
- reasons.push("PERSONAL_EMAIL");
60
- if (rules.deny.includes("CORPORATE_EMAIL") && responseEmail.corporate)
61
- reasons.push("CORPORATE_EMAIL");
62
- if (rules.deny.includes("NO_MX_RECORDS") && responseEmail.plugins.mxRecords.length === 0)
63
- reasons.push("NO_MX_RECORDS");
64
- if (rules.deny.includes("NO_REPLY_EMAIL") && responseEmail.noReply)
65
- reasons.push("NO_REPLY_EMAIL");
66
- if (rules.deny.includes("ROLE_ACCOUNT") && responseEmail.plugins.roleAccount)
67
- reasons.push("ROLE_ACCOUNT");
68
- if (rules.deny.includes("NO_REACHABLE") && !responseEmail.plugins.reachable)
69
- reasons.push("NO_REACHABLE");
70
- if (rules.deny.includes("HIGH_RISK_SCORE") && responseEmail.plugins.riskScore >= 80)
71
- reasons.push("HIGH_RISK_SCORE");
72
- if (rules.deny.includes("NO_GRAVATAR") && !responseEmail.plugins.gravatar)
73
- reasons.push("NO_GRAVATAR");
74
- return {
75
- email: responseEmail.email,
76
- allow: reasons.length === 0,
77
- reasons,
78
- response: responseEmail
79
- };
80
- }
81
- catch (error) {
82
- const statusCode = error.response?.status || 500;
83
- const errorMessage = error.response?.data?.message || error.message;
84
- const errorDetails = JSON.stringify(error.response?.data || {});
85
- throw customError(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
86
- }
87
- };
@@ -1,76 +0,0 @@
1
- import { customError } from "../../../../utils/basics.js";
2
- /**
3
- * Validates an ip using a secure verification endpoint.
4
- *
5
- * @param {string | null} token - Authentication token (required).
6
- * @param {Interfaces.IPValidator} ip - IP to validate.
7
- * @param {Interfaces.IPValidatorRules} [rules] - Deny rules. Defaults to ["FRAUD", "INVALID", "TOR_NETWORK"].
8
- *
9
- * Deny rules (some are premium ⚠️):
10
- * - "FRAUD", "INVALID", "TOR_NETWORK" ⚠️, "HIGH_RISK_SCORE" ⚠️
11
- *
12
- * @returns {Promise<boolean>} True if the IP passes all deny rules, false otherwise.
13
- * @throws Error if token is null, rules are empty, or request fails.
14
- *
15
- * @example
16
- * const valid = await isValidIP(apiToken, "52.94.236.248", { deny: ["FRAUD", "TOR_NETWORK", "COUNTRY:RU"] });
17
- */
18
- export const isValidIP = async (axiosClient, ip, rules) => {
19
- if (!axiosClient.defaults.headers?.Authorization)
20
- throw customError(3000, "Invalid private token.");
21
- if (rules.deny.length === 0)
22
- throw customError(1500, "You must provide at least one deny rule.");
23
- if (rules.mode === "DRY_RUN") {
24
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
25
- return {
26
- ip,
27
- allow: true,
28
- reasons: [],
29
- response: "CHANGE TO LIVE MODE"
30
- };
31
- }
32
- try {
33
- const responseIP = (await axiosClient.post("/private/secure/verify", {
34
- ip,
35
- plugins: [
36
- rules.deny.includes("TOR_NETWORK") ? "torNetwork" : undefined,
37
- rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined
38
- ].filter(Boolean)
39
- }, { headers: { "Content-Type": "application/json" } })).data.ip;
40
- let reasons = [];
41
- if (rules.deny.includes("INVALID") && !responseIP.valid) {
42
- return {
43
- ip: responseIP.ip,
44
- allow: false,
45
- reasons: ["INVALID"],
46
- response: responseIP
47
- };
48
- }
49
- if (rules.deny.includes("FRAUD") && responseIP.fraud)
50
- reasons.push("FRAUD");
51
- if (rules.deny.includes("TOR_NETWORK") && responseIP.plugins.torNetwork)
52
- reasons.push("TOR_NETWORK");
53
- if (rules.deny.includes("HIGH_RISK_SCORE") && responseIP.plugins.riskScore >= 80)
54
- reasons.push("HIGH_RISK_SCORE");
55
- // Country block rules.
56
- for (const rule of rules.deny) {
57
- if (rule.startsWith("COUNTRY:")) {
58
- const block = rule.split(":")[1]; // Extract country code.
59
- if (responseIP.countryCode === block)
60
- reasons.push(`COUNTRY:${block}`);
61
- }
62
- }
63
- return {
64
- ip: responseIP.ip,
65
- allow: reasons.length === 0,
66
- reasons,
67
- response: responseIP
68
- };
69
- }
70
- catch (error) {
71
- const statusCode = error.response?.status || 500;
72
- const errorMessage = error.response?.data?.message || error.message;
73
- const errorDetails = JSON.stringify(error.response?.data || {});
74
- throw customError(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
75
- }
76
- };
@@ -1,73 +0,0 @@
1
- import { customError } from "../../../../utils/basics.js";
2
- /**
3
- * Validates an phone using a secure verification endpoint.
4
- *
5
- * @param {string | null} token - Authentication token (required).
6
- * @param {Interfaces.PhoneValidator} phone - Phone to validate.
7
- * @param {Interfaces.PhoneValidatorRules} [rules] - Deny rules. Defaults to ["FRAUD", "INVALID"].
8
- *
9
- * Deny rules (some are premium ⚠️):
10
- * - "FRAUD", "INVALID", "HIGH_RISK_SCORE" ⚠️
11
- *
12
- * @returns {Promise<boolean>} True if the phone passes all deny rules, false otherwise.
13
- * @throws Error if token is null, rules are empty, or request fails.
14
- *
15
- * @example
16
- * const valid = await isValidPhone(apiToken, "+34617509462", { deny: ["FRAUD", "INVALID" });
17
- */
18
- export const isValidPhone = async (axiosClient, phone, rules) => {
19
- if (!axiosClient.defaults.headers?.Authorization)
20
- throw customError(3000, "Invalid private token.");
21
- if (rules.deny.length === 0)
22
- throw customError(1500, "You must provide at least one deny rule.");
23
- if (rules.mode === "DRY_RUN") {
24
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
25
- return {
26
- phone,
27
- allow: true,
28
- reasons: [],
29
- response: "CHANGE TO LIVE MODE"
30
- };
31
- }
32
- try {
33
- const responsePhone = (await axiosClient.post("/private/secure/verify", {
34
- phone,
35
- plugins: [
36
- rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined
37
- ].filter(Boolean)
38
- }, { headers: { "Content-Type": "application/json" } })).data.phone;
39
- let reasons = [];
40
- if (rules.deny.includes("INVALID") && !responsePhone.valid) {
41
- return {
42
- phone: responsePhone.phone,
43
- allow: false,
44
- reasons: ["INVALID"],
45
- response: responsePhone
46
- };
47
- }
48
- if (rules.deny.includes("FRAUD") && responsePhone.fraud)
49
- reasons.push("FRAUD");
50
- if (rules.deny.includes("HIGH_RISK_SCORE") && responsePhone.plugins.riskScore >= 80)
51
- reasons.push("HIGH_RISK_SCORE");
52
- // Country block rules.
53
- for (const rule of rules.deny) {
54
- if (rule.startsWith("COUNTRY:")) {
55
- const block = rule.split(":")[1]; // Extract country code.
56
- if (responsePhone.countryCode === block)
57
- reasons.push(`COUNTRY:${block}`);
58
- }
59
- }
60
- return {
61
- phone: responsePhone.phone,
62
- allow: reasons.length === 0,
63
- reasons,
64
- response: responsePhone
65
- };
66
- }
67
- catch (error) {
68
- const statusCode = error.response?.status || 500;
69
- const errorMessage = error.response?.data?.message || error.message;
70
- const errorDetails = JSON.stringify(error.response?.data || {});
71
- throw customError(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
72
- }
73
- };
@@ -1,37 +0,0 @@
1
- import { customError } from "../../../../utils/basics.js";
2
- import { handleRequest } from "./requestHandler.js";
3
- import * as Interfaces from "../../../../lib/types/interfaces.js";
4
- const isWellKnownBot = (ua) => {
5
- return Object.values(Interfaces.categories).flat().includes(ua);
6
- };
7
- export const protectReq = async (axiosClient, req, rules) => {
8
- if (!axiosClient.defaults.headers?.Authorization)
9
- throw customError(3000, "Invalid private token.");
10
- const reqData = handleRequest(req);
11
- if (!reqData.userAgent || !reqData.ip)
12
- throw customError(1500, "You must provide user agent and ip.");
13
- if (rules.mode === "DRY_RUN") {
14
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
15
- return {
16
- ip: reqData.ip,
17
- userAgent: reqData.userAgent,
18
- allow: true,
19
- reasons: []
20
- };
21
- }
22
- try {
23
- const response = await axiosClient.post("/private/waf/verifyRequest", {
24
- ip: reqData.ip,
25
- userAgent: reqData.userAgent,
26
- allowBots: rules.allowBots,
27
- deny: rules.deny
28
- }, { headers: { "Content-Type": "application/json" } });
29
- return response.data;
30
- }
31
- catch (error) {
32
- const statusCode = error.response?.status || 500;
33
- const errorMessage = error.response?.data?.message || error.message;
34
- const errorDetails = JSON.stringify(error.response?.data || {});
35
- throw customError(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
36
- }
37
- };
@@ -1,18 +0,0 @@
1
- // Helpers.
2
- const getUserAgent = (req) => {
3
- return req.headers?.["user-agent"] || req.headers?.["User-Agent"];
4
- };
5
- const getIp = (req) => {
6
- return (req.ip ||
7
- req.headers?.["x-forwarded-for"] ||
8
- req.connection?.remoteAddress ||
9
- req.socket?.remoteAddress ||
10
- req.req?.socket?.remoteAddress);
11
- };
12
- export const handleRequest = (req) => {
13
- return {
14
- body: req.body,
15
- userAgent: getUserAgent(req),
16
- ip: getIp(req)
17
- };
18
- };
@@ -1,81 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
1
- export * from "./functions/extractWithTextly";
2
- export * from "./functions/getRandom";
3
- export * from "./functions/isValidDataRaw";
4
- export * from "./functions/isValidEmail";
5
- export * from "./functions/isValidIP";
6
- export * from "./functions/isValidPhone";
7
- export * from "./functions/protectReq";
8
- export * from "./functions/sendEmail";
@@ -1,27 +0,0 @@
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,61 +0,0 @@
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) => {
28
- let { email, password, bannedWords, min, max } = data;
29
- if (password === undefined)
30
- throw customError(1000, "You must specify at least the password.");
31
- const params = { password: encodeURIComponent(password) };
32
- if (email) {
33
- if (!/^[a-zA-Z0-9._\-+]+@?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email))
34
- throw customError(1500, "If you provide an email address it must be valid.");
35
- params.email = encodeURIComponent(email);
36
- }
37
- if (bannedWords) {
38
- if (typeof bannedWords === "string")
39
- bannedWords = bannedWords.slice(1, -1).trim().split(",").map(item => item.trim());
40
- if (!Array.isArray(bannedWords) || bannedWords.length > 10)
41
- throw customError(1500, "If you provide a list of banned words; the list may not exceed 10 words and must be of array type.");
42
- if (!bannedWords.every(word => typeof word === "string") || new Set(bannedWords).size !== bannedWords.length)
43
- throw customError(1500, "If you provide a list of banned words; all elements must be non-repeated strings.");
44
- params.bannedWords = bannedWords;
45
- }
46
- if (min !== undefined && (!Number.isInteger(min) || min < 8 || min > 32))
47
- throw customError(1500, "If you provide a minimum it must be valid.");
48
- if (max !== undefined && (!Number.isInteger(max) || max < 32 || max > 100))
49
- throw customError(1500, "If you provide a maximum it must be valid.");
50
- if (min !== undefined)
51
- params.min = min;
52
- if (max !== undefined)
53
- params.max = max;
54
- try {
55
- const response = await axiosClient.get("/public/validPwd", { params });
56
- return response.data;
57
- }
58
- catch (error) {
59
- throw customError(5000, error.response?.data?.message || error.message);
60
- }
61
- };
@@ -1,22 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- export * from "./functions/getPrayerTimes";
2
- export * from "./functions/isValidPwd";
3
- export * from "./functions/satinize";
@@ -1,10 +0,0 @@
1
- const config = {
2
- lib: {
3
- name: "Dymo API",
4
- dir: "dymo-api"
5
- },
6
- env: {
7
- baseUrl: "https://api.tpeoficial.com"
8
- }
9
- };
10
- export default config;