"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 };