UNPKG

neverbounce

Version:

An API wrapper for the NeverBounce API

126 lines (125 loc) 3.45 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Import resource classes const Account_js_1 = __importDefault(require("./Account.js")); const Jobs_js_1 = __importDefault(require("./Jobs.js")); const POE_js_1 = __importDefault(require("./POE.js")); const Single_js_1 = __importDefault(require("./Single.js")); const VerificationObject_js_1 = __importDefault(require("./VerificationObject.js")); const Errors_js_1 = __importDefault(require("./Errors.js")); /** * Main NeverBounce API client class */ class NeverBounce { /** * Initializes NeverBounce object * @param config Configuration options */ constructor(config = {}) { // Create config by merging defaults with user config this.config = { ...structuredClone(NeverBounce.defaultConfig), ...config, opts: { ...NeverBounce.defaultConfig.opts, ...(config.opts || {}), headers: { ...NeverBounce.defaultConfig.opts.headers, ...(config.opts?.headers || {}) } } }; // Initialize resources this.account = new Account_js_1.default(this); this.jobs = new Jobs_js_1.default(this); this.poe = new POE_js_1.default(this); this.single = new Single_js_1.default(this); } /** * Returns config */ getConfig() { return this.config; } /** * Make request options */ getRequestOpts(opts = {}) { return { ...this.config.opts, ...opts, headers: { ...this.config.opts.headers, ...(opts.headers || {}) } }; } /** * Update configuration */ updateConfig(config) { if (config.apiKey) this.config.apiKey = config.apiKey; if (config.apiVersion) this.config.apiVersion = config.apiVersion; if (config.timeout) this.config.timeout = config.timeout; if (config.opts) { this.config.opts = { ...this.config.opts, ...config.opts, headers: { ...this.config.opts.headers, ...(config.opts.headers || {}) } }; } } /** * Set api key (convenience method) * @param key API key */ setApiKey(key) { this.config.apiKey = key; } /** * Set api host (convenience method) * @param host API host */ setHost(host) { this.config.opts.host = host; } } /** * Default config values */ NeverBounce.defaultConfig = { apiVersion: 'v4.2', apiKey: null, timeout: 30000, opts: { acceptedType: 'application/json', host: 'api.neverbounce.com', port: 443, headers: { 'Content-Type': 'application/json', 'User-Agent': 'NeverBounce-Node/5.0.0' } } }; /** * Verification result helpers */ NeverBounce.result = VerificationObject_js_1.default.helpers; /** * Job helpers */ NeverBounce.job = Jobs_js_1.default.helpers; /** * Error types */ NeverBounce.errors = Errors_js_1.default; exports.default = NeverBounce;