@eleva-io/erp-sdk
Version:
SDK oficial para el ERP de Eleva
56 lines • 2.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERPClient = void 0;
const http_1 = require("./utils/http");
const horizontal_1 = require("./modules/horizontal");
const ticketing_1 = require("./modules/ticketing");
const api_1 = require("./modules/contacts/api");
const api_2 = require("./modules/global/api");
const api_3 = require("./modules/domain/api");
const pino_1 = __importDefault(require("pino"));
class ERPClient {
_baseUrl = '/api/v1';
_httpClient;
constructor(config) {
if (!config.baseURL) {
throw new Error('Missing required baseURL configuration');
}
if ('token' in config) {
if (!config.token) {
throw new Error('Token is required when using token authentication');
}
}
else {
if (!config.apiKey || !config.apiSecret) {
throw new Error('API key and secret are required when using API key authentication');
}
}
let logger = config.logger?.instance;
if (!logger) {
logger = (0, pino_1.default)();
logger.level = config.logger?.level || 'info';
}
logger = logger.child({ client: 'eleva-erp' });
this._httpClient = new http_1.HTTPClient(config, logger);
}
domain() {
return new api_3.DomainAPI(this._httpClient, this._baseUrl); // TODO: auth http client
}
global() {
return new api_2.GlobalAPI(this._httpClient, this._baseUrl);
}
contacts() {
return new api_1.ContactsAPI(this._httpClient, this._baseUrl);
}
horizontal() {
return new horizontal_1.HorizontalAPI(this._httpClient, this._baseUrl);
}
ticketing() {
return new ticketing_1.TicketingAPI(this._httpClient, this._baseUrl);
}
}
exports.ERPClient = ERPClient;
//# sourceMappingURL=erp.js.map