UNPKG

neverbounce

Version:

An API wrapper for the NeverBounce API

162 lines (161 loc) 4.79 kB
import HttpsClient from './HttpsClient.js'; /** * Jobs API endpoints */ class Jobs extends HttpsClient { /** * Search for jobs * @param query Search query parameters * @returns Promise with search results */ async search(query) { return this.request({ method: 'GET', path: 'jobs/search' }, query || {}); } /** * Creates a job * @param input Input data (array of emails or remote URL) * @param inputlocation Input location type ('remote_url' or 'supplied') * @param filename Filename for the job * @param runsample Whether to run a sample * @param autoparse Whether to automatically parse * @param autostart Whether to automatically start * @param historicalData Whether to leverage historical data * @param allowManualReview Whether to allow manual review * @param callbackUrl URL to call when job completes * @param callbackHeaders Headers to include in callback request * @returns Promise with job creation response */ async create(input, inputlocation, filename, runsample, autoparse, autostart, historicalData, allowManualReview, callbackUrl, callbackHeaders) { const data = { input: Array.isArray(input) ? input : [input], input_location: inputlocation, filename, run_sample: runsample || null, auto_start: autostart || null, auto_parse: autoparse || null, allow_manual_review: allowManualReview || null, callback_url: callbackUrl || null, callback_headers: callbackHeaders || null }; if (historicalData !== undefined) { data.request_meta_data = { leverage_historical_data: historicalData ? 1 : 0 }; } return this.request({ method: 'POST', path: 'jobs/create' }, data); } /** * Starts parsing job after creation * @param jobid Job ID * @param autostart Whether to automatically start * @returns Promise with parse response */ async parse(jobid, autostart) { return this.request({ method: 'POST', path: 'jobs/parse' }, { job_id: jobid, auto_start: autostart || undefined }); } /** * Starts job waiting to be started * @param jobid Job ID * @param runsample Whether to run a sample * @param allowManualReview Whether to allow manual review * @returns Promise with start response */ async start(jobid, runsample, allowManualReview) { return this.request({ method: 'POST', path: 'jobs/start' }, { job_id: jobid, run_sample: runsample || undefined, allow_manual_review: allowManualReview || undefined }); } /** * Gets job status * @param jobid Job ID * @returns Promise with job status */ async status(jobid) { return this.request({ method: 'GET', path: 'jobs/status' }, { job_id: jobid }); } /** * Retrieves job results * @param jobid Job ID * @param query Additional query parameters * @returns Promise with job results */ async results(jobid, query) { return this.request({ method: 'GET', path: 'jobs/results' }, Object.assign({ job_id: jobid }, query || {})); } /** * Downloads results as CSV * @param jobid Job ID * @param query Additional query parameters * @returns Promise with CSV data */ async download(jobid, query) { return this.request({ acceptedType: 'application/octet-stream', method: 'GET', path: 'jobs/download' }, Object.assign({ job_id: jobid }, query || {})); } /** * Deletes a job * @param jobid Job ID * @returns Promise with delete response */ async delete(jobid) { return this.request({ method: 'POST', path: 'jobs/delete' }, { job_id: jobid }); } } /** * Job input type constants */ Jobs.remote = 'remote_url'; Jobs.supplied = 'supplied'; /** * Helper object for job types and statuses * @since 4.1.4 */ Jobs.helpers = { inputType: { remote: Jobs.remote, supplied: Jobs.supplied }, status: { under_review: 'under_review', queued: 'queued', failed: 'failed', complete: 'complete', running: 'running', parsing: 'parsing', waiting: 'waiting', waiting_analyzed: 'waiting_analyzed', uploading: 'uploading' } }; export default Jobs;