@adisuper94/orcid
Version:
ORCID API client
73 lines (72 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEmployment = getEmployment;
exports.getEducation = getEducation;
const types_js_1 = require("./types.js");
/**
* @module
* This module provides functions to fetch `Education` and `Employment` details of an ORCID ID from
* ORCID's public API.
*/
/**
* Fetches `Employment` details of `orcidId` from orcid's public API
*
* @example
* ```typescript
* const orcidId = "0000-0000-0000-0000";
* const [edu, err] = await getEmployment(orcidId);
* if (err){
* //handle err
* }
*
* ```
*
* @param orcidId
* @returns tuple containing `Education` summary array and `Error`
*/
async function getEmployment(orcidId) {
const [response, err] = await (0, types_js_1.tryCatch)(fetch(`https://pub.orcid.org/v3.0/${orcidId}/employments`, {
method: "GET",
headers: { Accept: "application/json" },
}));
if (err != undefined) {
return [undefined, err];
}
const [data, jsonErr] = await (0, types_js_1.tryCatch)(response.json());
if (jsonErr != undefined) {
return [undefined, jsonErr];
}
const empRecordsResult = (0, types_js_1.parseEmploymentResp)(data);
return empRecordsResult;
}
/**
* Fetches `Education` details of `orcidId` from orcid's public API
*
* @example
* ```typescript
* const orcidId = "0000-0000-0000-0000";
* const [edu, err] = await getEducation(orcidId);
* if (err){
* //handle err
* }
*
* ```
*
* @param orcidId
* @returns tuple containing `Education` summary array and `Error`
*/
async function getEducation(orcidId) {
const [response, err] = await (0, types_js_1.tryCatch)(fetch(`https://pub.orcid.org/v3.0/${orcidId}/educations`, {
method: "GET",
headers: { Accept: "application/json" },
}));
if (err != undefined) {
return [undefined, err];
}
const [data, jsonErr] = await (0, types_js_1.tryCatch)(response.json());
if (jsonErr != undefined) {
return [undefined, jsonErr];
}
const eduRecordsResult = (0, types_js_1.parseEducationResp)(data);
return eduRecordsResult;
}