(endpointPath, message, deps)
| 591 | } |
| 592 | |
| 593 | async function postEnvelope(endpointPath, message, deps) { |
| 594 | const hubUrl = getHubUrl(deps); |
| 595 | if (!hubUrl) throw new ContractError('auth_required', 'Hub URL is required'); |
| 596 | const a2a = deps.a2a || require('./a2aProtocol'); |
| 597 | const headers = buildEnvelopeHeaders(endpointPath, deps, a2a); |
| 598 | if (!hasAuthorizationHeader(headers)) throw new ContractError('auth_required', 'Hub authentication required'); |
| 599 | const fetchImpl = deps.hubFetch || require('./hubFetch').hubFetch; |
| 600 | const timeoutMs = deps.timeoutMs || 30000; |
| 601 | const endpoint = hubUrl.replace(/\/+$/, '') + endpointPath; |
| 602 | try { |
| 603 | const res = await fetchImpl(endpoint, { |
| 604 | method: 'POST', |
| 605 | headers, |
| 606 | body: JSON.stringify(message), |
| 607 | signal: AbortSignal.timeout(timeoutMs), |
| 608 | }); |
| 609 | const body = await safeJson(res); |
| 610 | return { ok: Boolean(res && res.ok), status: res && res.status || 0, body }; |
| 611 | } catch (e) { |
| 612 | return { ok: false, status: 0, body: { error: 'network_error' } }; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | async function safeJson(res) { |
| 617 | if (!res) return {}; |
no test coverage detected