| 91 | // the EVOMAP_HUB_ALLOW_INSECURE escape hatch automatically; we no |
| 92 | // longer need the explicit `enforceHubScheme` guard here. |
| 93 | function _hubPost(pathSuffix, body, timeoutMs) { |
| 94 | const hubUrl = getHubUrl(); |
| 95 | if (!hubUrl) return Promise.resolve({ ok: false, error: 'no_hub_url' }); |
| 96 | const endpoint = hubUrl.replace(/\/+$/, '') + pathSuffix; |
| 97 | const timeout = timeoutMs || require('../config').HTTP_TRANSPORT_TIMEOUT_MS; |
| 98 | const buildHeaders = buildNodeScopedHubHeaders || buildHubHeaders; |
| 99 | return hubFetch(endpoint, { |
| 100 | method: 'POST', |
| 101 | headers: buildHeaders(), |
| 102 | body: JSON.stringify(body), |
| 103 | signal: AbortSignal.timeout(timeout), |
| 104 | }) |
| 105 | .then(function (res) { |
| 106 | if (!res.ok) return res.text().then(function (t) { return { ok: false, status: res.status, error: t.slice(0, 400) }; }); |
| 107 | return res.json().then(function (data) { return { ok: true, data: data }; }); |
| 108 | }) |
| 109 | .catch(function (err) { |
| 110 | // hubFetch throws synchronously (rejected Promise) when the URL |
| 111 | // fails scheme validation in secure mode. Translate to the same |
| 112 | // structured envelope the previous in-line guard produced so the |
| 113 | // caller contract is unchanged. |
| 114 | const msg = (err && err.message) || String(err); |
| 115 | if (msg.indexOf('[hubFetch]') !== -1) { |
| 116 | return { ok: false, error: 'tls_refused: ' + msg }; |
| 117 | } |
| 118 | return { ok: false, error: msg }; |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | function _hubGet(pathSuffix, timeoutMs) { |
| 123 | const hubUrl = getHubUrl(); |