@vanakaru/ekilex-api-client
Version:
A node api client for the Ekilex API
93 lines • 3.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EkilexClient = void 0;
const http_client_1 = require("./http/http-client");
const endpoints_1 = require("./resources/endpoints");
const words_1 = require("./resources/words");
const datasets_1 = require("./resources/datasets");
const classifiers_1 = require("./resources/classifiers");
const domains_1 = require("./resources/domains");
const paradigms_1 = require("./resources/paradigms");
const meanings_1 = require("./resources/meanings");
const sources_1 = require("./resources/sources");
const public_words_1 = require("./resources/public-words");
const basePaths = {
test: 'https://ekitest.tripledev.ee/ekilex/api/',
prod: 'https://ekilex.ee/api/',
};
function isConfigValid(config) {
const regex = /^[0-9a-fA-F]{32}$/;
const isValidApiKey = regex.test(String(config.apiKey));
const isValidTestEnvironment = ['test', 'prod', undefined].includes(config.environment);
return isValidApiKey && isValidTestEnvironment;
}
class EkilexClient {
constructor(config) {
if (!isConfigValid(config)) {
throw new Error('Invalid config');
}
this.config = config;
const basePath = this.config.environment ? basePaths[this.config.environment] : basePaths.prod;
this.httpClient = new http_client_1.HttpClient(config.apiKey, basePath);
this.init();
}
init() {
this._endpoints = undefined;
}
get endpoints() {
if (!this._endpoints) {
this._endpoints = new endpoints_1.Endpoints(this.httpClient);
}
return this._endpoints;
}
get words() {
if (!this._words) {
this._words = new words_1.Words(this.httpClient);
}
return this._words;
}
get datasets() {
if (!this._datasets) {
this._datasets = new datasets_1.Datasets(this.httpClient);
}
return this._datasets;
}
get classifiers() {
if (!this._classifiers) {
this._classifiers = new classifiers_1.Classifiers(this.httpClient);
}
return this._classifiers;
}
get domains() {
if (!this._domains) {
this._domains = new domains_1.Domains(this.httpClient);
}
return this._domains;
}
get paradigms() {
if (!this._paradigms) {
this._paradigms = new paradigms_1.Paradigms(this.httpClient);
}
return this._paradigms;
}
get meanings() {
if (!this._meanings) {
this._meanings = new meanings_1.Meanings(this.httpClient);
}
return this._meanings;
}
get sources() {
if (!this._sources) {
this._sources = new sources_1.Sources(this.httpClient);
}
return this._sources;
}
get publiWords() {
if (!this._publicWords) {
this._publicWords = new public_words_1.PublicWords(this.httpClient);
}
return this._publicWords;
}
}
exports.EkilexClient = EkilexClient;
//# sourceMappingURL=client.js.map