MCPcopy Create free account
hub / github.com/EvoMap/evolver / postEnvelope

Function postEnvelope

src/gep/cliContracts.js:593–614  ·  view source on GitHub ↗
(endpointPath, message, deps)

Source from the content-addressed store, hash-verified

591}
592
593async 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
616async function safeJson(res) {
617 if (!res) return {};

Callers 3

fetchAssetByIdFunction · 0.85
postValidateFunction · 0.85
postPublishFunction · 0.85

Calls 5

getHubUrlFunction · 0.85
buildEnvelopeHeadersFunction · 0.85
hasAuthorizationHeaderFunction · 0.85
fetchImplFunction · 0.85
safeJsonFunction · 0.85

Tested by

no test coverage detected