// Generated, do not edit. sha256:5e5e2f16e143c15a74105363f7c477f9e5d2936d0860e2793eadda36b591c7e6 import { CONFIG } from '../../shared/config.js'; import { t } from '../i18n/index.js'; import { serverFoutTekst } from '../data/_rpc.js'; async function api(path, { method = 'GET', body = null } = {}) { const ctl = new AbortController(); const timer = setTimeout(() => ctl.abort(), CONFIG.NWC.CLIENT_TIMEOUT_MS); try { const res = await fetch(path, { method, signal: ctl.signal, ...(body ? { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}), }); const json = await res.json().catch(() => null); if (!res.ok) throw new Error(serverFoutTekst(json) || `HTTP ${res.status}`); return json; } catch (e) { if (e.name === 'AbortError') throw new Error(t('common.backendSilent', { s: CONFIG.NWC.CLIENT_TIMEOUT_MS / 1000 })); throw e; } finally { clearTimeout(timer); } } export const validateUri = uri => api('/api/nwc/validate', { method: 'POST', body: { uri } }); export const status = sourceId => api(`/api/nwc/status?source=${encodeURIComponent(sourceId)}`); export const setUri = (sourceId, uri) => api('/api/nwc/config', { method: 'POST', body: { source: sourceId, uri } }); export const purgeUri = sourceId => api('/api/nwc/delete', { method: 'POST', body: { source: sourceId } }); export const call = (sourceId, method, params = {}) => api('/api/nwc/call', { method: 'POST', body: { source: sourceId, method, params } }); export const getInfo = sourceId => call(sourceId, 'get_info'); export const getBalance = sourceId => call(sourceId, 'get_balance'); export const listTransactions = (sourceId, params = {}) => call(sourceId, 'list_transactions', params); export const testNwc = sourceId => api('/api/nwc/test', { method: 'POST', body: { source: sourceId } });