UNPKG

dymo-api

Version:
288 lines 16.8 kB
import * as Interfaces from "./lib/types/interfaces"; declare class DymoAPI { private rootApiKey; private apiKey; private serverEmailConfig?; private rules; private baseUrl; private axiosClient; private resilienceManager; /** * @param {Object} options - Options to create the DymoAPI instance. * @param {string} [options.rootApiKey] - The root API key. * @param {string} [options.apiKey] - The API key. * @param {string} [options.baseUrl] - Whether to use a local server instead of the cloud server. * @param {Object} [options.serverEmailConfig] - The server email config. * @param {Object} [options.rules] - The rules. * @param {Object} [options.resilience] - The resilience config. * @description * This is the main class to interact with the Dymo API. It should be * instantiated with the root API key and the API key. The root API key is * used to fetch the tokens and the API key is used to authenticate the * requests. Requests are retried once by default with exponential backoff. * @example * const dymoApi = new DymoAPI({ * rootApiKey: "6bfb7675-6b69-4f8d-9f43-5a6f7f02c6c5", * apiKey: "dm_4c8b7675-6b69-4f8d-9f43-5a6f7f02c6c5" * }); */ constructor({ rootApiKey, apiKey, baseUrl, serverEmailConfig, rules, resilience }?: { rootApiKey?: string | null; apiKey?: string | null; baseUrl?: string; serverEmailConfig?: Interfaces.ServerEmailConfig; rules?: Interfaces.Rules; resilience?: Interfaces.ResilienceConfig; }); /** * Validates the given data against the configured validation settings. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @deprecated Use `isValidDataRaw` instead. This feature will be modified soon. * @param {Object} data - The data to be validated. * @param {string} [data.url] - Optional URL to be validated. * @param {string} [data.email] - Optional email address to be validated. * @param {Interfaces.PhoneData} [data.phone] - Optional phone number data to be validated. * @param {string} [data.domain] - Optional domain name to be validated. * @param {string|Interfaces.CreditCardData} [data.creditCard] - Optional credit card number or data to be validated. * @param {string} [data.ip] - Optional IP address to be validated. * @param {string} [data.wallet] - Optional wallet address to be validated. * @param {string} [data.userAgent] - Optional user agent string to be validated. * @param {string} [data.iban] - Optional IBAN to be validated. * @param {Interfaces.VerifyPlugins[]} [data.plugins] - Optional array of verification plugins to be used. * @returns {Promise<Interfaces.DataValidationAnalysis>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the validation process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) */ isValidData(data: Interfaces.Validator): Promise<Interfaces.DataValidationAnalysis>; /** * Validates the given data against the configured validation settings. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {Object} data - The data to be validated. * @param {string} [data.url] - Optional URL to be validated. * @param {string} [data.email] - Optional email address to be validated. * @param {Interfaces.PhoneData} [data.phone] - Optional phone number data to be validated. * @param {string} [data.domain] - Optional domain name to be validated. * @param {string|Interfaces.CreditCardData} [data.creditCard] - Optional credit card number or data to be validated. * @param {string} [data.ip] - Optional IP address to be validated. * @param {string} [data.wallet] - Optional wallet address to be validated. * @param {string} [data.userAgent] - Optional user agent string to be validated. * @param {string} [data.iban] - Optional IBAN to be validated. * @param {Interfaces.VerifyPlugins[]} [data.plugins] - Optional array of verification plugins to be used. * @returns {Promise<Interfaces.DataValidationAnalysis>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the validation process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) */ isValidDataRaw(data: Interfaces.Validator): Promise<Interfaces.DataValidationAnalysis>; /** * Validates the given email against the configured rules. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {string} [email] - Email address to validate. * @param {NegativeEmailRules[]} [rules] - Optional rules for validation. Some rules are premium features. * @important * **⚠️ NO_MX_RECORDS, HIGH_RISK_SCORE and NO_REACHABLE are [PREMIUM](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) features.** * @returns {Promise<Interfaces.EmailValidatorResponse>} Resolves with the validation response. * @throws Will throw an error if validation cannot be performed. * * @example * const valid = await dymoClient.isValidEmail("user@example.com", { deny: ["FRAUD", "NO_MX_RECORDS"] }); * * @see [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/email-validation) */ isValidEmail(email: Interfaces.EmailValidator, rules?: Interfaces.EmailValidatorRules): Promise<Interfaces.EmailValidatorResponse>; /** * Validates the given IP against the configured rules. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {string} [ip] - IP address to validate. * @param {NegativeIPRules[]} [rules] - Optional rules for validation. Some rules are premium features. * @important * **⚠️ TOR_NETWORK and HIGH_RISK_SCORE are [PREMIUM](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) features.** * @returns {Promise<Interfaces.IPValidatorResponse>} Resolves with the validation response. * @throws Will throw an error if validation cannot be performed. * * @example * const valid = await isValidIP("52.94.236.248", { deny: ["FRAUD", "TOR_NETWORK", "COUNTRY:RU"] }); * * @see [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/ip-validation) */ isValidIP(ip: Interfaces.IPValidator, rules?: Interfaces.IPValidatorRules): Promise<Interfaces.IPValidatorResponse>; /** * Validates the given phone against the configured rules. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {string} [phone] - Phone number to validate. * @param {NegativePhoneRules[]} [rules] - Optional rules for validation. Some rules are premium features. * @important * **⚠️ HIGH_RISK_SCORE is a [PREMIUM](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) feature.** * @returns {Promise<Interfaces.PhoneValidatorResponse>} Resolves with the validation response. * @throws Will throw an error if validation cannot be performed. * * @example * const valid = await dymoClient.isValidPhone("+34617509462", { deny: ["FRAUD", "INVALID"] }); * * @see [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/phone-validation) */ isValidPhone(phone: Interfaces.PhoneValidator, rules?: Interfaces.PhoneValidatorRules): Promise<Interfaces.PhoneValidatorResponse>; /** * Protects the given request against the configured rules. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {Object} req - The request object to be protected. * @param {Interfaces.WafRules} [rules] - Optional rules for protection. Some rules are premium features. * @returns {Promise<Interfaces.HTTPRequest>} Resolves with the protected request. * @important * **⚠️ This is a [PREMIUM](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) and BETA feature.** * @throws Will throw an error if protection cannot be performed. * * @example * const protectedReq = await dymoClient.protectReq(req); * * @see [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/data-verifier) */ protectReq(req: Interfaces.HTTPRequest, rules?: Interfaces.WafRules): Promise<any>; /** * Sends an email using the configured email client settings. * * This method requires either the root API key or the server email config to be set. * If neither is set, it will throw an error. * * @param {Object} data - The email data to be sent. * @param {string} data.from - The email address from which the email will be sent. * @param {string} data.to - The email address to which the email will be sent. * @param {string} data.subject - The subject of the email. * @param {string} [data.html] - The HTML content of the email. * @param {React.ReactElement} [data.react] - The React component to be rendered as the email content. * @param {Object} [data.options] - Content configuration options. * @param {"high" | "normal" | "low" | undefined} [data.options.priority="normal"] - Email priority (default: normal). * @param {boolean} [data.options.waitToResponse=true] - Wait until the email is sent (default: true). * @param {boolean} [data.options.composeTailwindClasses] - Whether to compose tailwind classes. * @param {Attachment[]} [data.attachments] - An array of attachments to be included in the email. * @param {string} data.attachments[].filename - The name of the attached file. * @param {string} [data.attachments[].path] - The path or URL of the attached file. Either this or `content` must be provided. * @param {Buffer} [data.attachments[].content] - The content of the attached file as a Buffer. Either this or `path` must be provided. * @param {string} [data.attachments[].cid] - The CID (Content-ID) of the attached file, used for inline images. * @returns {Promise<Interfaces.EmailStatus>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the email sending process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/sender-send-email/getting-started) */ sendEmail(data: Interfaces.SendEmail): Promise<Interfaces.EmailStatus>; /** * Generates a random number between the provided min and max values. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {Interfaces.SRNG} data - The data to be sent. * @param {number} data.min - The minimum value of the range. * @param {number} data.max - The maximum value of the range. * @param {number} [data.quantity] - The number of random values to generate. Defaults to 1 if not provided. * @returns {Promise<Interfaces.SRNSummary>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the random number generation process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/secure-random-number-generator) */ getRandom(data: Interfaces.SRNG): Promise<Interfaces.SRNSummary>; /** * Extracts structured data from a given string using Textly. * * This method requires either the root API key or the API key to be set. * If neither is set, it will throw an error. * * @param {Interfaces.ExtractWithTextly} data - The data to be sent, containing the string to be processed and the format schema. * @returns {Promise<any>} A promise that resolves to the extracted structured data. * @throws Will throw an error if there is an issue with the extraction process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/textly/text-extraction) */ extractWithTextly(data: Interfaces.ExtractWithTextly): Promise<any>; /** * Retrieves the prayer times for the given location. * * This method requires a latitude and longitude to be provided in the * data object. If either of these are not provided, it will throw an error. * * @param {Object} data - The data to be sent. * @param {number} data.lat - The latitude of the location. * @param {number} data.lon - The longitude of the location. * @returns {Promise<Interfaces.CountryPrayerTimes | { error: string }>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the prayer times retrieval process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/prayertimes) */ getPrayerTimes(data: Interfaces.PrayerTimesData): Promise<Interfaces.CountryPrayerTimes | { error: string; }>; /** * Satinizes the input, replacing any special characters with their HTML * entities. * * @deprecated Use `satinize` instead. This feature will be removed soon. * @param {Object} data - The data to be sent. * @param {string} data.input - The input to be satinized. * @returns {Promise<Interfaces.SatinizedInputAnalysis>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the satinization process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/input-satinizer) */ satinizer(data: { input: string; }): Promise<Interfaces.SatinizedInputAnalysis>; /** * Satinizes the input, replacing any special characters with their HTML * entities. * * @param {string} input - The input to be satinized. * @returns {Promise<Interfaces.SatinizedInputAnalysis>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the satinization process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/input-satinizer) */ satinize(input: string): Promise<Interfaces.SatinizedInputAnalysis>; /** * Validates a password based on the given parameters. * * This method requires the password to be provided in the data object. * If the password is not provided, it will throw an error. The method * will validate the password against the following rules: * - The password must be at least 8 characters long. * - The password must be at most 32 characters long. * - The password must contain at least one uppercase letter. * - The password must contain at least one lowercase letter. * - The password must contain at least one number. * - The password must contain at least one special character. * - The password must not contain any of the given banned words. * * @param {Object} data - The data to be sent. * @param {number} [data.min] - Minimum length of the password. Defaults to 8 if not provided. * @param {number} [data.max] - Maximum length of the password. Defaults to 32 if not provided. * @param {string} [data.email] - Optional email associated with the password. * @param {string} data.password - The password to be validated. * @param {string | string[]} [data.bannedWords] - The list of banned words that the password must not contain. * @returns {Promise<Interfaces.PasswordValidationResult>} A promise that resolves to the response from the server. * @throws Will throw an error if there is an issue with the password validation process. * * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/public/password-validator) */ isValidPwd(data: Interfaces.IsValidPwdData): Promise<Interfaces.PasswordValidationResult>; } export default DymoAPI; export type { EmailValidatorRules, NegativeEmailRules, DataEmailValidationAnalysis, IPValidatorRules, NegativeIPRules, DataIPValidationAnalysis, PhoneValidatorRules, NegativePhoneRules, DataPhoneValidationAnalysis, WafRules, SensitiveInfoRules, ResilienceConfig } from './lib/types/interfaces'; //# sourceMappingURL=dymo-api.d.ts.map