UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

103 lines (101 loc) • 2.79 kB
const require_manifest_verify = require('./manifest-verify.cjs'); const require_config_slots = require('../config-slots.cjs'); //#region src/services/deploy/rollback.ts function collectPinnedSlots(config) { const slots = []; require_config_slots.walkConfigSlots(config, ({ slot, entry }) => { if (entry && typeof entry === "object") slots.push({ slot, ref: entry }); }); return slots; } function pinOf(ref) { const manifest = typeof ref.pin?.manifest === "string" ? ref.pin.manifest : void 0; const integrity = typeof ref.pin?.integrity === "string" ? ref.pin.integrity : void 0; return manifest && integrity ? { manifest, integrity } : null; } /** Every pinned slot with both a production base and a verifiable pin. */ function collectSlotPinRefs(config) { return collectPinnedSlots(config).map(({ slot, ref }) => { const pin = pinOf(ref); const base = typeof ref.production === "string" ? ref.production : void 0; return pin && base ? { slot, base, pin } : null; }).filter((entry) => entry !== null); } async function verifySlot(slot, ref, fetchImpl) { const base = typeof ref.production === "string" ? ref.production : void 0; const pin = pinOf(ref); if (!pin) return { slot, ok: true }; const { manifest, integrity } = pin; if (!base) return { slot, manifest, ok: false, reason: "no production URL to fetch the manifest from" }; const verified = await require_manifest_verify.fetchVerifiedManifest({ base, pin: { manifest, integrity }, fetchImpl }); if (!verified.ok) return { slot, manifest, ok: false, reason: verified.reason }; return { slot, manifest, ok: true }; } async function verifyRollbackSnapshot(config, opts) { const fetchImpl = opts?.fetchImpl ?? fetch; const pinned = collectPinnedSlots(config).filter((entry) => pinOf(entry.ref) !== null); if (pinned.length === 0) return { verifiable: false, ok: false, slots: [] }; const slots = await Promise.all(pinned.map((entry) => verifySlot(entry.slot, entry.ref, fetchImpl))); return { verifiable: true, ok: slots.every((check) => check.ok), slots }; } function summarizeSlotPins(config) { const pinned = collectPinnedSlots(config).map((entry) => { const pin = pinOf(entry.ref); return pin ? `${entry.slot}=${pin.manifest}` : null; }).filter(Boolean); return pinned.length > 0 ? pinned.join(" ") : "no version pins (pre-pin snapshot)"; } function buildRollbackPayload(targetConfig, rolledBackFrom) { return { ...targetConfig, rolledBackFrom }; } //#endregion exports.buildRollbackPayload = buildRollbackPayload; exports.collectSlotPinRefs = collectSlotPinRefs; exports.summarizeSlotPins = summarizeSlotPins; exports.verifyRollbackSnapshot = verifyRollbackSnapshot; //# sourceMappingURL=rollback.cjs.map