openalex-client
Version:
TypeScript SDK for OpenAlex academic database API
162 lines • 4.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InstitutionsService = void 0;
const base_1 = require("./base");
class InstitutionsService extends base_1.BaseService {
constructor() {
super(...arguments);
this.endpoint = "institutions";
}
/**
* Get works from a specific institution
*/
async getWorks(institutionId, params) {
const cleanId = this.cleanId(institutionId);
const response = await this.client.get(`/institutions/${cleanId}/works`, this.buildParams(params));
return response.data;
}
/**
* Get authors from a specific institution
*/
async getAuthors(institutionId, params) {
const cleanId = this.cleanId(institutionId);
const response = await this.client.get(`/institutions/${cleanId}/authors`, this.buildParams(params));
return response.data;
}
/**
* Get institution by ROR ID
*/
async getByRor(ror, params) {
// Clean ROR - remove URL prefix if present
const cleanRor = ror.replace(/^https?:\/\/ror\.org\//, "");
return this.get(`https://ror.org/${cleanRor}`, params);
}
/**
* Search institutions by multiple RORs
*/
async getByRors(rors, params) {
const cleanRors = rors.map((ror) => ror.replace(/^https?:\/\/ror\.org\//, ""));
const filterParams = {
...params,
filter: {
...params?.filter,
ror: cleanRors,
},
};
return this.list(filterParams);
}
/**
* Get institutions by country
*/
async getByCountry(countryCode, params) {
const filterParams = {
...params,
filter: {
...params?.filter,
country_code: countryCode.toUpperCase(),
},
};
return this.list(filterParams);
}
/**
* Get institutions by type
*/
async getByType(type, params) {
const filterParams = {
...params,
filter: {
...params?.filter,
type: type,
},
};
return this.list(filterParams);
}
/**
* Get top institutions by works count
*/
async getTopByWorks(params) {
return this.list({
...params,
sort: "works_count:desc",
});
}
/**
* Get top institutions by citations
*/
async getTopByCitations(params) {
return this.list({
...params,
sort: "cited_by_count:desc",
});
}
/**
* Get institutions in a specific geographic area
*/
async getByLocation(latitude, longitude, radiusKm = 50, params) {
// Note: This would require a custom filter implementation
// For now, we'll return institutions by country as an approximation
console.warn("Geographic radius search not directly supported by OpenAlex API. Consider filtering by country or region instead.");
return this.list(params);
}
/**
* Get university-type institutions
*/
async getUniversities(params) {
return this.getByType("education", params);
}
/**
* Get government institutions
*/
async getGovernmentInstitutions(params) {
return this.getByType("government", params);
}
/**
* Get healthcare institutions
*/
async getHealthcareInstitutions(params) {
return this.getByType("healthcare", params);
}
/**
* Get company/corporate institutions
*/
async getCompanies(params) {
return this.getByType("company", params);
}
/**
* Get associated institutions
*/
async getAssociated(institutionId, params) {
const institution = await this.get(institutionId);
if (institution.associated_institutions.length === 0) {
return {
results: [],
meta: { count: 0, db_response_time_ms: 0, page: 1, per_page: 0 },
};
}
const associatedIds = institution.associated_institutions.map((assoc) => assoc.id);
const filterParams = {
...params,
filter: {
...params?.filter,
id: associatedIds,
},
};
return this.list(filterParams);
}
/**
* Get institutions 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);
}
}
exports.InstitutionsService = InstitutionsService;
//# sourceMappingURL=institutions.js.map