dymo-api 1.2.31 → 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 +9 -10
  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,91 +0,0 @@
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", "NO_GRAVATAR" "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
- if (rules.mode === "DRY_RUN") {
28
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
29
- return {
30
- email,
31
- allow: true,
32
- reasons: [],
33
- response: "CHANGE TO LIVE MODE"
34
- };
35
- }
36
- try {
37
- const responseEmail = (await axiosClient.post("/private/secure/verify", {
38
- email,
39
- plugins: [
40
- rules.deny.includes("NO_MX_RECORDS") ? "mxRecords" : undefined,
41
- rules.deny.includes("NO_REACHABLE") ? "reachable" : undefined,
42
- rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined,
43
- rules.deny.includes("NO_GRAVATAR") ? "gravatar" : undefined
44
- ].filter(Boolean)
45
- }, { headers: { "Content-Type": "application/json" } })).data.email;
46
- let reasons = [];
47
- if (rules.deny.includes("INVALID") && !responseEmail.valid) {
48
- return {
49
- email: responseEmail.email,
50
- allow: false,
51
- reasons: ["INVALID"],
52
- response: responseEmail
53
- };
54
- }
55
- if (rules.deny.includes("FRAUD") && responseEmail.fraud)
56
- reasons.push("FRAUD");
57
- if (rules.deny.includes("PROXIED_EMAIL") && responseEmail.proxiedEmail)
58
- reasons.push("PROXIED_EMAIL");
59
- if (rules.deny.includes("FREE_SUBDOMAIN") && responseEmail.freeSubdomain)
60
- reasons.push("FREE_SUBDOMAIN");
61
- if (rules.deny.includes("PERSONAL_EMAIL") && !responseEmail.corporate)
62
- reasons.push("PERSONAL_EMAIL");
63
- if (rules.deny.includes("CORPORATE_EMAIL") && responseEmail.corporate)
64
- reasons.push("CORPORATE_EMAIL");
65
- if (rules.deny.includes("NO_MX_RECORDS") && responseEmail.plugins.mxRecords.length === 0)
66
- reasons.push("NO_MX_RECORDS");
67
- if (rules.deny.includes("NO_REPLY_EMAIL") && responseEmail.noReply)
68
- reasons.push("NO_REPLY_EMAIL");
69
- if (rules.deny.includes("ROLE_ACCOUNT") && responseEmail.plugins.roleAccount)
70
- reasons.push("ROLE_ACCOUNT");
71
- if (rules.deny.includes("NO_REACHABLE") && !responseEmail.plugins.reachable)
72
- reasons.push("NO_REACHABLE");
73
- if (rules.deny.includes("HIGH_RISK_SCORE") && responseEmail.plugins.riskScore >= 80)
74
- reasons.push("HIGH_RISK_SCORE");
75
- if (rules.deny.includes("NO_GRAVATAR") && !responseEmail.plugins.gravatar)
76
- reasons.push("NO_GRAVATAR");
77
- return {
78
- email: responseEmail.email,
79
- allow: reasons.length === 0,
80
- reasons,
81
- response: responseEmail
82
- };
83
- }
84
- catch (error) {
85
- const statusCode = error.response?.status || 500;
86
- const errorMessage = error.response?.data?.message || error.message;
87
- const errorDetails = JSON.stringify(error.response?.data || {});
88
- throw (0, basics_1.customError)(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
89
- }
90
- };
91
- exports.isValidEmail = isValidEmail;
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidIP = void 0;
4
- const basics_1 = require("../../../../utils/basics.cjs");
5
- /**
6
- * Validates an ip using a secure verification endpoint.
7
- *
8
- * @param {string | null} token - Authentication token (required).
9
- * @param {Interfaces.IPValidator} ip - IP to validate.
10
- * @param {Interfaces.IPValidatorRules} [rules] - Deny rules. Defaults to ["FRAUD", "INVALID", "TOR_NETWORK"].
11
- *
12
- * Deny rules (some are premium ⚠️):
13
- * - "FRAUD", "INVALID", "TOR_NETWORK" ⚠️, "HIGH_RISK_SCORE" ⚠️
14
- *
15
- * @returns {Promise<boolean>} True if the IP passes all deny rules, false otherwise.
16
- * @throws Error if token is null, rules are empty, or request fails.
17
- *
18
- * @example
19
- * const valid = await isValidIP(apiToken, "52.94.236.248", { deny: ["FRAUD", "TOR_NETWORK", "COUNTRY:RU"] });
20
- */
21
- const isValidIP = async (axiosClient, ip, rules) => {
22
- if (!axiosClient.defaults.headers?.Authorization)
23
- throw (0, basics_1.customError)(3000, "Invalid private token.");
24
- if (rules.deny.length === 0)
25
- throw (0, basics_1.customError)(1500, "You must provide at least one deny rule.");
26
- if (rules.mode === "DRY_RUN") {
27
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
28
- return {
29
- ip,
30
- allow: true,
31
- reasons: [],
32
- response: "CHANGE TO LIVE MODE"
33
- };
34
- }
35
- try {
36
- const responseIP = (await axiosClient.post("/private/secure/verify", {
37
- ip,
38
- plugins: [
39
- rules.deny.includes("TOR_NETWORK") ? "torNetwork" : undefined,
40
- rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined
41
- ].filter(Boolean)
42
- }, { headers: { "Content-Type": "application/json" } })).data.ip;
43
- let reasons = [];
44
- if (rules.deny.includes("INVALID") && !responseIP.valid) {
45
- return {
46
- ip: responseIP.ip,
47
- allow: false,
48
- reasons: ["INVALID"],
49
- response: responseIP
50
- };
51
- }
52
- if (rules.deny.includes("FRAUD") && responseIP.fraud)
53
- reasons.push("FRAUD");
54
- if (rules.deny.includes("TOR_NETWORK") && responseIP.plugins.torNetwork)
55
- reasons.push("TOR_NETWORK");
56
- if (rules.deny.includes("HIGH_RISK_SCORE") && responseIP.plugins.riskScore >= 80)
57
- reasons.push("HIGH_RISK_SCORE");
58
- // Country block rules.
59
- for (const rule of rules.deny) {
60
- if (rule.startsWith("COUNTRY:")) {
61
- const block = rule.split(":")[1]; // Extract country code.
62
- if (responseIP.countryCode === block)
63
- reasons.push(`COUNTRY:${block}`);
64
- }
65
- }
66
- return {
67
- ip: responseIP.ip,
68
- allow: reasons.length === 0,
69
- reasons,
70
- response: responseIP
71
- };
72
- }
73
- catch (error) {
74
- const statusCode = error.response?.status || 500;
75
- const errorMessage = error.response?.data?.message || error.message;
76
- const errorDetails = JSON.stringify(error.response?.data || {});
77
- throw (0, basics_1.customError)(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
78
- }
79
- };
80
- exports.isValidIP = isValidIP;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidPhone = void 0;
4
- const basics_1 = require("../../../../utils/basics.cjs");
5
- /**
6
- * Validates an phone using a secure verification endpoint.
7
- *
8
- * @param {string | null} token - Authentication token (required).
9
- * @param {Interfaces.PhoneValidator} phone - Phone to validate.
10
- * @param {Interfaces.PhoneValidatorRules} [rules] - Deny rules. Defaults to ["FRAUD", "INVALID"].
11
- *
12
- * Deny rules (some are premium ⚠️):
13
- * - "FRAUD", "INVALID", "HIGH_RISK_SCORE" ⚠️
14
- *
15
- * @returns {Promise<boolean>} True if the phone passes all deny rules, false otherwise.
16
- * @throws Error if token is null, rules are empty, or request fails.
17
- *
18
- * @example
19
- * const valid = await isValidPhone(apiToken, "+34617509462", { deny: ["FRAUD", "INVALID" });
20
- */
21
- const isValidPhone = async (axiosClient, phone, rules) => {
22
- if (!axiosClient.defaults.headers?.Authorization)
23
- throw (0, basics_1.customError)(3000, "Invalid private token.");
24
- if (rules.deny.length === 0)
25
- throw (0, basics_1.customError)(1500, "You must provide at least one deny rule.");
26
- if (rules.mode === "DRY_RUN") {
27
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
28
- return {
29
- phone,
30
- allow: true,
31
- reasons: [],
32
- response: "CHANGE TO LIVE MODE"
33
- };
34
- }
35
- try {
36
- const responsePhone = (await axiosClient.post("/private/secure/verify", {
37
- phone,
38
- plugins: [
39
- rules.deny.includes("HIGH_RISK_SCORE") ? "riskScore" : undefined
40
- ].filter(Boolean)
41
- }, { headers: { "Content-Type": "application/json" } })).data.phone;
42
- let reasons = [];
43
- if (rules.deny.includes("INVALID") && !responsePhone.valid) {
44
- return {
45
- phone: responsePhone.phone,
46
- allow: false,
47
- reasons: ["INVALID"],
48
- response: responsePhone
49
- };
50
- }
51
- if (rules.deny.includes("FRAUD") && responsePhone.fraud)
52
- reasons.push("FRAUD");
53
- if (rules.deny.includes("HIGH_RISK_SCORE") && responsePhone.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 (responsePhone.countryCode === block)
60
- reasons.push(`COUNTRY:${block}`);
61
- }
62
- }
63
- return {
64
- phone: responsePhone.phone,
65
- allow: reasons.length === 0,
66
- reasons,
67
- response: responsePhone
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 (0, basics_1.customError)(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
75
- }
76
- };
77
- exports.isValidPhone = isValidPhone;
@@ -1,74 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.protectReq = void 0;
37
- const basics_1 = require("../../../../utils/basics.cjs");
38
- const requestHandler_1 = require("./requestHandler.cjs");
39
- const Interfaces = __importStar(require("../../../../lib/types/interfaces.cjs"));
40
- const isWellKnownBot = (ua) => {
41
- return Object.values(Interfaces.categories).flat().includes(ua);
42
- };
43
- const protectReq = async (axiosClient, req, rules) => {
44
- if (!axiosClient.defaults.headers?.Authorization)
45
- throw (0, basics_1.customError)(3000, "Invalid private token.");
46
- const reqData = (0, requestHandler_1.handleRequest)(req);
47
- if (!reqData.userAgent || !reqData.ip)
48
- throw (0, basics_1.customError)(1500, "You must provide user agent and ip.");
49
- if (rules.mode === "DRY_RUN") {
50
- console.warn("[Dymo API] DRY_RUN mode is enabled. No requests with real data will be processed until you switch to LIVE mode.");
51
- return {
52
- ip: reqData.ip,
53
- userAgent: reqData.userAgent,
54
- allow: true,
55
- reasons: []
56
- };
57
- }
58
- try {
59
- const response = await axiosClient.post("/private/waf/verifyRequest", {
60
- ip: reqData.ip,
61
- userAgent: reqData.userAgent,
62
- allowBots: rules.allowBots,
63
- deny: rules.deny
64
- }, { headers: { "Content-Type": "application/json" } });
65
- return response.data;
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 (0, basics_1.customError)(5000, `Error ${statusCode}: ${errorMessage}. Details: ${errorDetails}`);
72
- }
73
- };
74
- exports.protectReq = protectReq;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleRequest = void 0;
4
- // Helpers.
5
- const getUserAgent = (req) => {
6
- return req.headers?.["user-agent"] || req.headers?.["User-Agent"];
7
- };
8
- const getIp = (req) => {
9
- return (req.ip ||
10
- req.headers?.["x-forwarded-for"] ||
11
- req.connection?.remoteAddress ||
12
- req.socket?.remoteAddress ||
13
- req.req?.socket?.remoteAddress);
14
- };
15
- const handleRequest = (req) => {
16
- return {
17
- body: req.body,
18
- userAgent: getUserAgent(req),
19
- ip: getIp(req)
20
- };
21
- };
22
- exports.handleRequest = handleRequest;
@@ -1,88 +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.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;
@@ -1,24 +0,0 @@
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/isValidDataRaw/index.cjs"), exports);
20
- __exportStar(require("./functions/isValidEmail/index.cjs"), exports);
21
- __exportStar(require("./functions/isValidIP/index.cjs"), exports);
22
- __exportStar(require("./functions/isValidPhone/index.cjs"), exports);
23
- __exportStar(require("./functions/protectReq/index.cjs"), exports);
24
- __exportStar(require("./functions/sendEmail/index.cjs"), exports);
@@ -1,31 +0,0 @@
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;
@@ -1,65 +0,0 @@
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;
@@ -1,26 +0,0 @@
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;
@@ -1,19 +0,0 @@
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,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {
4
- lib: {
5
- name: "Dymo API",
6
- dir: "dymo-api"
7
- },
8
- env: {
9
- baseUrl: "https://api.tpeoficial.com"
10
- }
11
- };
12
- exports.default = config;