everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
1 lines • 2.48 kB
Source Map (JSON)
{"version":3,"file":"manifest-verify.mjs","names":[],"sources":["../../../src/services/deploy/manifest-verify.ts"],"sourcesContent":["import { asDigest, computeSri, fetchVerified, isVerifyError } from \"../verify/engine\";\n\nexport interface ManifestPin {\n /** versioned manifest filename, relative to the remote's production base */\n manifest: string;\n /** the manifest document's own SRI */\n integrity: string;\n}\n\nexport type VerifiedManifest = { ok: true; text: string } | { ok: false; reason: string };\n\nexport function manifestDocumentUrl(base: string, manifest: string): string {\n return `${base.replace(/\\/$/, \"\")}/${manifest.replace(/^\\//, \"\")}`;\n}\n\nexport function computeManifestSri(text: string): string {\n return computeSri(text);\n}\n\nexport function reasonOf(error: unknown): string {\n if (!isVerifyError(error)) {\n return error instanceof Error ? error.message : String(error);\n }\n if (error._tag === \"IntegrityMismatch\") {\n return `integrity mismatch for ${error.url} (expected ${error.expected}, computed ${error.actual})`;\n }\n if (error._tag === \"ProvenanceUnknown\") {\n if (error.status !== undefined) {\n return `manifest fetch failed: ${error.status}`;\n }\n return `manifest fetch failed: ${error.cause instanceof Error ? error.cause.message : String(error.cause)}`;\n }\n return `signature invalid for ${error.url}: ${error.reason}`;\n}\n\nexport async function fetchVerifiedManifest(input: {\n base: string;\n digest: ManifestPin;\n fetchImpl?: typeof fetch;\n}): Promise<VerifiedManifest> {\n const manifestUrl = manifestDocumentUrl(input.base, input.digest.manifest);\n try {\n const bytes = await fetchVerified({\n url: manifestUrl,\n expected: asDigest(input.digest.integrity),\n fetchImpl: input.fetchImpl,\n cache: false,\n });\n return { ok: true, text: new TextDecoder().decode(bytes) };\n } catch (error) {\n return { ok: false, reason: reasonOf(error) };\n }\n}\n"],"mappings":";;;AAWA,SAAgB,oBAAoB,MAAc,UAA0B;CAC1E,OAAO,GAAG,KAAK,QAAQ,OAAO,EAAE,EAAE,GAAG,SAAS,QAAQ,OAAO,EAAE;AACjE;AAMA,SAAgB,SAAS,OAAwB;CAC/C,IAAI,CAAC,cAAc,KAAK,GACtB,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAE9D,IAAI,MAAM,SAAS,qBACjB,OAAO,0BAA0B,MAAM,IAAI,aAAa,MAAM,SAAS,aAAa,MAAM,OAAO;CAEnG,IAAI,MAAM,SAAS,qBAAqB;EACtC,IAAI,MAAM,WAAW,QACnB,OAAO,0BAA0B,MAAM;EAEzC,OAAO,0BAA0B,MAAM,iBAAiB,QAAQ,MAAM,MAAM,UAAU,OAAO,MAAM,KAAK;CAC1G;CACA,OAAO,yBAAyB,MAAM,IAAI,IAAI,MAAM;AACtD"}