Files
jlinc-sdk-node/dist/entity.js
T
2026-10-23 18:49:11 +00:00

31 lines
1.0 KiB
JavaScript

"use strict";
const axios = require('axios');
const { getConfig } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function getDomains({ fedidUrl, auth: authPayload }) {
const cfg = getConfig();
return (await axios.post(_getUrl('/api/v1/data/entity/domains/get'), {
fedidUrl: fedidUrl || cfg.fedidUrl,
auth: authPayload,
}, { headers: _headers() })).data;
}
async function createEntity({ fedidUrl, shortName }) {
const cfg = getConfig();
return (await axios.post(_getUrl('/api/v1/data/entity/create'), {
fedidUrl: fedidUrl || cfg.fedidUrl,
shortName,
}, { headers: _headers() })).data;
}
async function getEntity({ shortName }) {
return (await axios.post(_getUrl('/api/v1/data/entity/get'), { shortName }, { headers: _headers() }));
}
module.exports = { getDomains, getEntity, createEntity };