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

39 lines
1.4 KiB
JavaScript

"use strict";
const axios = require('axios');
const { getConfig, getDefault } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function produceEvent({ type, senderShortName, recipientShortName, agreementId, meta, data, archive }) {
const cfg = getConfig();
const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey };
return (await axios.post(_getUrl('/api/v1/data/event/produce'), {
type,
senderShortName,
recipientShortName,
agreementId: agreementId || getDefault('agreementId'),
meta,
data,
archive: archive || defaultArchive,
}, { headers: _headers() })).data;
}
async function getEvent({ eventId, meta }) {
return (await axios.post(_getUrl('/api/v1/data/event/get'), { eventId, meta }, { headers: _headers() })).data;
}
async function processEvent({ eventId, shortName, archive }) {
const cfg = getConfig();
const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey };
return (await axios.post(_getUrl('/api/v1/data/event/process'), {
eventId,
shortName,
archive: archive || defaultArchive,
}, { headers: _headers() })).data;
}
module.exports = { produceEvent, getEvent, processEvent };