UNPKG

greip-node

Version:

Official Node.js library for Greip API

404 lines 20.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("./common"); class Greip { /** * Creates GreipWrapper object to send requests to the [Greip](https://greip.io/) API. * * @param token Token string (Greip API Key). */ constructor(token) { this.Lookup = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const ip1 = options.ip || ""; const params = options.params || []; const format1 = options.format || "JSON"; let lang1 = options.lang || "EN"; const mode1 = options.mode || "live"; lang1 = lang1.toUpperCase(); // Validate the ip variable if (ip1.length < 3) { reject(new Error("You should pass the `ip` parameter.")); } // Validate the params variable items params.forEach((perParam) => { if (perParam.length > 0) { if (!common_1.availableGeoIPParams.includes(perParam)) { reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } } }); // Validate the format variable if (!common_1.availableFormats.includes(format1)) { reject(new Error('The `format` option value "' + format1 + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } // Validate the lang variable if (!common_1.availableLanguages.includes(lang1)) { reject(new Error('The `lang` option value "' + lang1 + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } (0, common_1.makeHttpRquest)("IPLookup", { ip: ip1, params: params.join(","), format: format1, lang: lang1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.Threats = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const ip1 = options.ip || ""; const format1 = options.format || "JSON"; const mode1 = options.mode || "live"; // Validate the ip variable if (ip1.length < 3) { reject(new Error("You should pass the `ip` parameter.")); } // Validate the format variable if (!common_1.availableFormats.includes(format1)) { reject(new Error('The `format` option value "' + format1 + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } (0, common_1.makeHttpRquest)("threats", { ip: ip1, format: format1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.BulkLookup = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { let ips1 = options.ips || []; const params = options.params || []; const format1 = options.format || "JSON"; let lang1 = options.lang || "EN"; const mode1 = options.mode || "live"; lang1 = lang1.toUpperCase(); if (typeof ips1 !== "object") ips1 = []; // Validate the ip variable if (ips1.length < 1) { reject(new Error("You should pass the `ips` parameter.")); } ips1.forEach((perParam) => { if (perParam.length < 7) { reject(new Error("You should pass a valid IP Addresses in the `ips` parameter.")); } }); // Validate the params variable items params.forEach((perParam) => { if (perParam.length > 0) { if (!common_1.availableGeoIPParams.includes(perParam)) { reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } } }); // Validate the format variable if (!common_1.availableFormats.includes(format1)) { reject(new Error('The `format` option value "' + format1 + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } // Validate the lang variable if (!common_1.availableLanguages.includes(lang1)) { reject(new Error('The `lang` option value "' + lang1 + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup')); } (0, common_1.makeHttpRquest)("BulkLookup", { ips: ips1, params: params.join(","), format: format1, lang: lang1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.Country = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { let countryCode = options.countryCode || ""; const params = options.params || []; const format1 = options.format || "JSON"; let lang1 = options.lang || "EN"; const mode1 = options.mode || "live"; countryCode = countryCode.toUpperCase(); lang1 = lang1.toUpperCase(); // Validate the countryCode variable if (countryCode.length !== 2) { reject(new Error("You should pass the `countryCode` parameter. Also, it should be a `ISO 3166-1 alpha-2` format.\nRead more at: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2")); } // Validate the params variable items params.forEach((perParam) => { if (perParam.length > 0) { if (!common_1.availableCountryParams.includes(perParam)) { reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `language`, `flag`, `currency` and/or `timezone`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/country-data')); } } }); // Validate the format variable if (!common_1.availableFormats.includes(format1)) { reject(new Error('The `format` option value "' + format1 + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/country-data')); } // Validate the lang variable if (!common_1.availableLanguages.includes(lang1)) { reject(new Error('The `lang` option value "' + lang1 + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/country-data')); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/country-data')); } (0, common_1.makeHttpRquest)("Country", { CountryCode: countryCode, params: params.join(","), format: format1, lang: lang1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.Profanity = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const text1 = options.text || ""; const params = options.params || []; const format1 = options.format || "JSON"; let lang1 = options.lang || "EN"; const mode1 = options.mode || "live"; lang1 = lang1.toUpperCase(); // Validate the text variable if (text1.length < 1) { reject(new Error("You should pass the `text` parameter.")); } // Validate the format variable if (!common_1.availableFormats.includes(format1)) { reject(new Error('The `format` option value "' + format1 + '" you specified is unknown.\nYou can use: `JSON`, `XML` or `CSV`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/profanity-detection')); } // Validate the lang variable if (!common_1.availableLanguages.includes(lang1)) { reject(new Error('The `lang` option value "' + lang1 + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/profanity-detection')); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/other-services/profanity-detection')); } (0, common_1.makeHttpRquest)("badWords", { text: text1, params: params.join(","), format: format1, lang: lang1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.ASN = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const asn1 = options.asn || ""; const mode1 = options.mode || "live"; // Validate the text variable if (asn1.length < 1) { reject(new Error("You should pass the `asn` parameter.")); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/ip-geolocation/asn-lookup')); } (0, common_1.makeHttpRquest)("ASNLookup", { asn: asn1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.EmailValidation = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const email1 = options.email || ""; const mode1 = options.mode || "live"; // Validate the text variable if (email1.length < 1) { reject(new Error("You should pass the `email` parameter.")); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/data-validation/email-lookup')); } (0, common_1.makeHttpRquest)("validateEmail", { email: email1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.PaymentFraud = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const data1 = options.data || []; const mode1 = options.mode || "live"; // Validate the text variable if (typeof data1 !== "object" || Array.isArray(data1)) { reject(new Error("You should pass the `data` parameter.")); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/payment-fraud/payment-fraud-prevention')); } (0, common_1.makePostRquest)("paymentFraud", { data: data1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.PhoneValidation = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const phone1 = options.phone || ""; const countryCode1 = options.countryCode || ""; const mode1 = options.mode || "live"; // Validate the text variable if (phone1.length < 1 || countryCode1.length < 1) { reject(new Error("You should pass both `phone` and `countryCode` parameters.")); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/data-validation/phone-lookup')); } (0, common_1.makeHttpRquest)("validatePhone", { phone: phone1, countryCode: countryCode1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; this.IBANValidation = (options) => { if (typeof options !== "object") options = {}; return new Promise((resolve, reject) => { const iban1 = options.iban || ""; const mode1 = options.mode || "live"; // Validate the text variable if (iban1.length < 1) { reject(new Error("You should pass the `iban` parameter.")); } // Validate the mode variable if (mode1 !== "live" && mode1 !== "test") { reject(new Error('The `mode` option value "' + mode1 + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://docs.greip.io/api-reference/endpoint/payment-fraud/iban-validation')); } (0, common_1.makeHttpRquest)("validateIBAN", { iban: iban1, mode: mode1 }, (res) => { if (typeof res !== "object") res = JSON.parse(res); resolve(res); }, this.token); }); }; // Check if the token is provided. if (!token) { throw new Error("Token is required"); } this.token = token; } } // export { Greip }; exports.default = Greip; //# sourceMappingURL=index.mjs.js.map