UNPKG

openalex-client

Version:

TypeScript SDK for OpenAlex academic database API

149 lines 4.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthorsService = void 0; const base_1 = require("./base"); class AuthorsService extends base_1.BaseService { constructor() { super(...arguments); this.endpoint = "authors"; } /** * Get works by a specific author */ async getWorks(authorId, params) { const cleanId = this.cleanId(authorId); const response = await this.client.get(`/authors/${cleanId}/works`, this.buildParams(params)); return response.data; } /** * Get author by ORCID */ async getByOrcid(orcid, params) { // Clean ORCID - remove URL prefix if present const cleanOrcid = orcid.replace(/^https?:\/\/(www\.)?orcid\.org\//, ""); return this.get(`https://orcid.org/${cleanOrcid}`, params); } /** * Search authors by multiple ORCIDs */ async getByOrcids(orcids, params) { const cleanOrcids = orcids.map((orcid) => orcid.replace(/^https?:\/\/(www\.)?orcid\.org\//, "")); const filterParams = { ...params, filter: { ...params?.filter, orcid: cleanOrcids, }, }; return this.list(filterParams); } /** * Get authors by institution */ async getByInstitution(institutionId, params) { const cleanId = this.cleanId(institutionId); const filterParams = { ...params, filter: { ...params?.filter, "last_known_institution.id": cleanId, }, }; return this.list(filterParams); } /** * Get authors by concept (research area) */ async getByConcept(conceptId, params) { const cleanId = this.cleanId(conceptId); const filterParams = { ...params, filter: { ...params?.filter, "x_concepts.id": cleanId, }, }; return this.list(filterParams); } /** * Get highly cited authors */ async getHighlyCited(params) { return this.list({ ...params, sort: "cited_by_count:desc", }); } /** * Get authors with high h-index */ async getByHIndex(minHIndex, params) { const filterParams = { ...params, filter: { ...params?.filter, "summary_stats.h_index": `>${minHIndex}`, }, }; return this.list(filterParams); } /** * Get prolific authors (by works count) */ async getProlific(minWorksCount = 100, params) { const filterParams = { ...params, filter: { ...params?.filter, works_count: `>${minWorksCount}`, }, }; return this.list(filterParams); } /** * Search for co-authors of a specific author */ async getCoAuthors(authorId, params) { // First get the author's works const works = await this.getWorks(authorId, { per_page: 200 }); // Extract all co-author IDs const coAuthorIds = new Set(); works.results.forEach((work) => { work.authorships.forEach((authorship) => { if (authorship.author.id !== authorId) { coAuthorIds.add(authorship.author.id); } }); }); if (coAuthorIds.size === 0) { return { results: [], meta: { count: 0, db_response_time_ms: 0, page: 1, per_page: 0 }, }; } // Get author details for co-authors const filterParams = { ...params, filter: { ...params?.filter, id: Array.from(coAuthorIds).slice(0, 50), // Limit to avoid URL length issues }, }; return this.list(filterParams); } /** * Get authors from a specific country */ async getByCountry(countryCode, params) { const filterParams = { ...params, filter: { ...params?.filter, "last_known_institution.country_code": countryCode.toUpperCase(), }, }; return this.list(filterParams); } } exports.AuthorsService = AuthorsService; //# sourceMappingURL=authors.js.map