"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 produceAgreement({ data, shortName, role, archive }) { const cfg = getConfig(); const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey }; return (await axios.post(_getUrl('/api/v1/data/agreement/produce'), { data, shortName, role, archive: archive || defaultArchive, }, { headers: _headers() })).data; } async function processAgreement({ agreementId, shortName, role, archive }) { const cfg = getConfig(); const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey }; return (await axios.post(_getUrl('/api/v1/data/agreement/process'), { agreementId: agreementId || getDefault('agreementId'), shortName, role, archive: archive || defaultArchive, }, { headers: _headers() })).data; } async function getAgreement({ agreementId, includeSignatures }) { return (await axios.post(_getUrl('/api/v1/data/agreement/get'), { agreementId: agreementId || getDefault('agreementId'), includeSignatures }, { headers: _headers() })).data; } module.exports = { produceAgreement, processAgreement, getAgreement };