UNPKG

@buildit/job-listings

Version:

Small JS library for fetching Buildit job listings data from SmartRecruiter's API

58 lines (50 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getJobAdUrl = getJobAdUrl; exports.getJobPostingsData = getJobPostingsData; var _crossFetch = _interopRequireDefault(require("cross-fetch")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Constructs the full URL for SmartRecruiters' Posting API * endpoint. * * @see https://dev.smartrecruiters.com/customer-api/posting-api/endpoints/postings/ * * @param {String} companyId The company ID (e.g. "WiproDigital") */ function getPostingEndpointUrl(companyId) { return `https://api.smartrecruiters.com/v1/companies/${companyId}/postings`; } /** * Constructs the full URL for a job ad page on SmartRecruiters. * * @param {String} companyId The company ID (e.g. "WiproDigital") * @param {String} jobUuid The job's UUID * @param {String} trId Optional tracking ID * * @return {String} Full job ad URL */ function getJobAdUrl(companyId, jobUuid, trId) { const queryString = trId ? `?trid=${trId}` : ''; return `https://jobs.smartrecruiters.com/ni/${companyId}/${jobUuid}${queryString}`; } /** * Fetches job posting data from SmartRecruiters' Posting API. * * @see https://dev.smartrecruiters.com/customer-api/posting-api/endpoints/postings/ * * @param {String} companyId The company ID (e.g. "WiproDigital") * @param {String} customFieldId Optional custom field ID to filter results on * @param {String} customFieldValueId Optional custom field value to use with the field ID * * @return {Promise<Array>} Promise that resolves to an array of job posting data. */ async function getJobPostingsData(companyId, customFieldId, customFieldValueId) { const queryString = customFieldId ? `?custom_field.${customFieldId}=${customFieldValueId}` : ''; const url = getPostingEndpointUrl(companyId) + queryString; const response = await (0, _crossFetch.default)(url); const json = await response.json(); return json.content; // actual jobs array }