xing-api-client
Version:
A client library for interacting with the Xing API
221 lines (209 loc) • 8.35 kB
JavaScript
import { sendRequest } from './chunk-MLMXFCXW.mjs';
// src/e-recruitung/types/EXingOrderStatus.ts
var EXingOrderStatus = /* @__PURE__ */ ((EXingOrderStatus2) => {
EXingOrderStatus2["ACTIVE"] = "active";
EXingOrderStatus2["UNSTARTED"] = "unstarted";
EXingOrderStatus2["EXPIRED"] = "expired";
return EXingOrderStatus2;
})(EXingOrderStatus || {});
// src/e-recruitung/types/EXingJobState.ts
var EXingJobState = /* @__PURE__ */ ((EXingJobState2) => {
EXingJobState2["CREATED"] = "created";
EXingJobState2["ACTIVE"] = "active";
EXingJobState2["DEACTIVATED"] = "deactivated";
EXingJobState2["ARCHIVED"] = "archived";
EXingJobState2["DELETED"] = "deleted";
return EXingJobState2;
})(EXingJobState || {});
// src/e-recruitung/types/EXingCurrency.ts
var EXingCurrency = /* @__PURE__ */ ((EXingCurrency2) => {
EXingCurrency2["EUR"] = "EUR";
EXingCurrency2["USD"] = "USD";
EXingCurrency2["GBP"] = "GBP";
EXingCurrency2["CHF"] = "CHF";
return EXingCurrency2;
})(EXingCurrency || {});
// src/e-recruitung/types/EXingJobType.ts
var EXingJobType = /* @__PURE__ */ ((EXingJobType2) => {
EXingJobType2["FULL_TIME"] = "FULL_TIME";
EXingJobType2["PART_TIME"] = "PART_TIME";
EXingJobType2["INTERNSHIP"] = "INTERNSHIP";
EXingJobType2["FREELANCE"] = "FREELANCE";
EXingJobType2["TEMPORARY"] = "TEMPORARY";
EXingJobType2["TRAINING"] = "TRAINING";
return EXingJobType2;
})(EXingJobType || {});
// src/e-recruitung/types/EXingJobLevel.ts
var EXingJobLevel = /* @__PURE__ */ ((EXingJobLevel2) => {
EXingJobLevel2["STUDENT"] = "JOBLEVEL_1";
EXingJobLevel2["ENTRY"] = "JOBLEVEL_2";
EXingJobLevel2["PROFESSIONAL"] = "JOBLEVEL_3";
EXingJobLevel2["MANAGER"] = "JOBLEVEL_4";
EXingJobLevel2["EXECUTIVE"] = "JOBLEVEL_5";
EXingJobLevel2["SENIOR_EXECUTIVE"] = "JOBLEVEL_6";
return EXingJobLevel2;
})(EXingJobLevel || {});
// src/e-recruitung/types/EXingJobPointOfContactType.ts
var EXingJobPointOfContactType = /* @__PURE__ */ ((EXingJobPointOfContactType2) => {
EXingJobPointOfContactType2["COMPANY"] = "company";
EXingJobPointOfContactType2["USER"] = "user";
EXingJobPointOfContactType2["NONE"] = "none";
return EXingJobPointOfContactType2;
})(EXingJobPointOfContactType || {});
// src/e-recruitung/types/EXingReplySetting.ts
var EXingReplySetting = /* @__PURE__ */ ((EXingReplySetting2) => {
EXingReplySetting2["XING_MESSAGING"] = "xing_messaging";
EXingReplySetting2["EMAIL"] = "email";
EXingReplySetting2["URL"] = "url";
EXingReplySetting2["XING_APPLY"] = "xing_apply";
return EXingReplySetting2;
})(EXingReplySetting || {});
// src/e-recruitung/types/EXingJobUserRole.ts
var EXingJobUserRole = /* @__PURE__ */ ((EXingJobUserRole2) => {
EXingJobUserRole2["HR_CONSULTANT"] = "HR_CONSULTANT";
EXingJobUserRole2["HR_DEPARTMENT"] = "HR_DEPARTMENT";
EXingJobUserRole2["MANAGER"] = "MANAGER";
EXingJobUserRole2["EXTERNAL_RECRUITER"] = "EXTERNAL_RECRUITER";
EXingJobUserRole2["EMPLOYEE"] = "EMPLOYEE";
return EXingJobUserRole2;
})(EXingJobUserRole || {});
// src/common/XingBaseApiClient.ts
var XingBaseApiClient = class {
/**
* Access token.
*/
accessToken;
/**
* Constructor for initializing an instance with the given access token.
*
* @param {string} accessToken - The access token used for authentication or API requests.
*/
constructor(accessToken) {
this.accessToken = accessToken;
}
/**
* Sends an authorized HTTP request to the specified API endpoint with the given parameters,
* method, and optional request body. It handles authorization headers and request formatting.
*
* @param {string} path - The path for the API endpoint.
* @param {Record<string, string>} [params={}] - The query parameters to include in the request URL.
* @param {'GET' | 'POST' | 'PUT' | 'DELETE'} [method='GET'] - The HTTP method to use for the request.
* @param {unknown} [body] - The payload to include in the request body (used for POST or PUT methods).
*
* @return {Promise<T>} - A promise that resolves to the parsed response body as the generic type T,
* or a boolean for PUT or DELETE methods with no content.
*/
async sendAuthorizedRequest(path, params = {}, method = "GET", body) {
const url = `https://api.xing.com${path}?${new URLSearchParams(params).toString()}`;
const requestInit = {
method,
headers: {
Authorization: `Bearer ${this.accessToken}`,
"Content-Type": "application/json"
}
};
if ((method === "POST" || method === "PUT") && body) {
requestInit.body = JSON.stringify(body);
}
const response = await sendRequest(url, requestInit);
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
if ((method === "PUT" || method === "DELETE") && response.status === 204) {
return true;
}
return response.json();
}
};
// src/e-recruitung/XingERecruitingApiClient.ts
var XingERecruitingApiClient = class extends XingBaseApiClient {
getPostingId(jobPosting) {
if (typeof jobPosting === "number") return jobPosting;
return jobPosting.id;
}
/**
* Get a paginated list of all orders for which the current oAuth user created postings.
*
* @param {XingGetOrdersParameters} [parameters]
*/
async getOrders({
ids,
status,
page
} = {}) {
const params = {};
if (ids && ids.length > 0) params.ids = ids.join(",");
if (status) params.status = status.toString();
if (page) params.page = page.toString();
return this.sendAuthorizedRequest("/vendor/jobs/orders", params);
}
/**
* Get a paginated list of all postings created by the current oAuth user.
*
* @param {XingGetPostingsParameters} [parameters]
*/
async getPostings({
page,
ids
} = {}) {
const params = {};
if (ids) params.ids = ids.join(",");
if (page) params.page = page.toString();
return this.sendAuthorizedRequest("/vendor/jobs/postings", params);
}
/**
* Creates a job posting on the Xing platform.
*
* @param {XingCreatePostingRequest} jobPosting Object containing the details of the job posting to be created.
* @return {Promise<XingCreatePostingResponse>} Response object for the created job posting.
*/
async createJobPosting(jobPosting) {
return this.sendAuthorizedRequest("/vendor/jobs/postings", {}, "POST", jobPosting);
}
/**
* Updates an existing job posting on the Xing platform.
*
* @param {number} jobPostingId The job posting id.
* @param{Partial<XingCreatePostingRequest>} jobPosting Payload containing the new data.
* @returns A promise resolving to void if the update is successful.
*/
async updateJobPosting(jobPostingId, jobPosting) {
return this.sendAuthorizedRequest(`/vendor/jobs/postings/${jobPostingId}`, {}, "PUT", jobPosting);
}
/**
* Activates a job posting on the Xing platform.
*
* @param {number | XingPosting} jobPosting Job posting id to activate.
*/
async activatePosting(jobPosting) {
const jobPostingId = this.getPostingId(jobPosting);
return this.sendAuthorizedRequest(`/vendor/jobs/postings/${jobPostingId}/activate`, {}, "PUT");
}
/**
* Archives a job posting on the Xing platform.
*
* @param {number | XingPosting} jobPosting Job posting id to archive.
*/
async archivePosting(jobPosting) {
const jobPostingId = this.getPostingId(jobPosting);
return this.sendAuthorizedRequest(`/vendor/jobs/postings/${jobPostingId}/archive`, {}, "PUT");
}
/**
* Deactivates a job posting on the Xing platform.
*
* @param {number | XingPosting} jobPosting Job posting to deactivate.
*/
async deactivatePosting(jobPosting) {
const jobPostingId = this.getPostingId(jobPosting);
return this.sendAuthorizedRequest(`/vendor/jobs/postings/${jobPostingId}/deactivate`, {}, "PUT");
}
/**
* Deletes a job posting on the Xing platform.
*
* @param {number | XingPosting} jobPosting Job posting to be deleted.
*/
async deletePosting(jobPosting) {
return this.sendAuthorizedRequest(`/vendor/jobs/postings/${this.getPostingId(jobPosting)}`, {}, "DELETE");
}
};
export { EXingCurrency, EXingJobLevel, EXingJobPointOfContactType, EXingJobState, EXingJobType, EXingJobUserRole, EXingOrderStatus, EXingReplySetting, XingERecruitingApiClient };