// Generated, do not edit. sha256:f749bbb8aa6d30896aca521c750c1da8d88aef00151138c594cf54a5f6889b26 import { listProviders, getProvider } from './data/providers.js'; import { listAssets } from './data/assets.js'; import { getBaseCurrency } from './data/portfolio.js'; export const INTEGRATIONS_FORMAT = 'atreides-assets/integrations'; export const INTEGRATIONS_VERSION = 1; const byKeys = (...keys) => (a, b) => { for (const k of keys) { const x = a[k] ?? ''; const y = b[k] ?? ''; if (x < y) return -1; if (x > y) return 1; } return 0; }; export function integrationsJson(providers, assets, baseCurrency) { const kindOf = new Map(assets.map(a => [a.symbol, a.kind])); return { format: INTEGRATIONS_FORMAT, version: INTEGRATIONS_VERSION, baseCurrency, providers: providers.filter(p => !p.isSystem).sort(byKeys('key')).map(p => ({ key: p.key, name: p.name, baseUrl: p.baseUrl, isActive: p.isActive === 1, callsPerMonth: p.callsPerMonth ?? null, auth: { kind: p.authenticationKind, required: p.authenticationRequired === 1, headerName: p.authenticationHeaderName ?? null, parameterName: p.authenticationParameterName ?? null, hmac: p.hmac ? { messageParts: p.hmac.messageParts, keyHeader: p.hmac.keyHeader, signatureHeader: p.hmac.signatureHeader, timestampHeader: p.hmac.timestampHeader, windowHeader: p.hmac.windowHeader ?? null, windowMs: p.hmac.windowMs ?? null, hashAlgorithm: p.hmac.hashAlgorithm, encoding: p.hmac.encoding, } : null, }, endpoints: [...p.endpoints].sort(byKeys('capability')).map(e => ({ capability: e.capability, method: e.method, pathTemplate: e.pathTemplate, queryTemplate: e.queryTemplate ?? null, quote: e.quoteCurrency ?? baseCurrency, minIntervalSeconds: e.minIntervalSeconds ?? null, })), inputMap: [...p.symbols].sort(byKeys('isCatchAll', 'symbol')).map(s => ({ symbol: s.symbol ?? null, externalId: s.externalId, quoteUnit: s.quoteUnit ?? null, isCatchAll: s.isCatchAll === 1, })), outputs: [...p.outputs].sort(byKeys('capability', 'internalField')).map(o => ({ capability: o.capability, internalField: o.internalField, jsonPath: o.jsonPath, transform: o.transform, })), coverage: [...p.coverage].sort().map(symbol => ({ symbol, kind: kindOf.get(symbol) ?? null })), })), }; } function fileName() { const d = new Date(); const p = n => String(n).padStart(2, '0'); return `integraties-${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}.json`; } export function exportIntegrations(res) { const providers = listProviders().map(p => getProvider(p.key)); const body = Buffer.from(JSON.stringify(integrationsJson(providers, listAssets(), getBaseCurrency()), null, 2) + '\n', 'utf-8'); res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Content-Disposition': `attachment; filename="${fileName()}"`, 'Content-Length': body.length, 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', }); res.end(body); }