UNPKG

everything-dev

Version:

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

1 lines • 6.37 kB
{"version":3,"file":"rollback.cjs","names":["fetchVerifiedManifest"],"sources":["../../../src/services/deploy/rollback.ts"],"sourcesContent":["import type { BosConfigInput } from \"../../types\";\nimport { walkRemotes } from \"../remotes\";\nimport { fetchVerifiedManifest } from \"./manifest-verify\";\n\n/**\n * Rollback safety gate (atomic-deploys 11): before republishing a historical\n * snapshot, every pinned remote's version manifest must still serve and match\n * its SRI — Phase A made bytes additive and retention is keep-everything, so\n * a verify failure means the pointer is broken, never publishable. Snapshots\n * from before the pin existed cannot be verified this way; they are allowed\n * only with an explicit force (their bytes were overwritten in place), with\n * the caller expected to warn loudly.\n */\n\nexport interface RollbackRemoteCheck {\n remote: string;\n manifest?: string;\n ok: boolean;\n reason?: string;\n}\n\nexport interface RollbackVerification {\n /** false = pre-pin snapshot with no verifiable pins (force required) */\n verifiable: boolean;\n ok: boolean;\n remotes: RollbackRemoteCheck[];\n}\n\ninterface PinnedRemoteRef {\n production?: unknown;\n digest?: { manifest?: unknown; integrity?: unknown };\n}\n\nfunction collectPinnedRemotes(\n config: BosConfigInput,\n): Array<{ remote: string; ref: PinnedRemoteRef }> {\n const remotes: Array<{ remote: string; ref: PinnedRemoteRef }> = [];\n walkRemotes(config as unknown as Record<string, unknown>, ({ remote, entry }) => {\n if (entry && typeof entry === \"object\") remotes.push({ remote, ref: entry as PinnedRemoteRef });\n });\n return remotes;\n}\n\nfunction digestOf(ref: PinnedRemoteRef): { manifest: string; integrity: string } | null {\n const manifest = typeof ref.digest?.manifest === \"string\" ? ref.digest.manifest : undefined;\n const integrity = typeof ref.digest?.integrity === \"string\" ? ref.digest.integrity : undefined;\n return manifest && integrity ? { manifest, integrity } : null;\n}\n\nexport interface RemoteDescriptor {\n remote: string;\n /** the remote's production base URL (…/bundles/<account>/<gateway>/<workspace>/) */\n base: string;\n digest: { manifest: string; integrity: string };\n}\n\n/** Every pinned remote with both a production base and a verifiable pin. */\nexport function collectRemoteDescriptors(config: BosConfigInput): RemoteDescriptor[] {\n return collectPinnedRemotes(config)\n .map(({ remote, ref }) => {\n const digest = digestOf(ref);\n const base = typeof ref.production === \"string\" ? ref.production : undefined;\n return digest && base ? { remote, base, digest } : null;\n })\n .filter((entry): entry is RemoteDescriptor => entry !== null);\n}\n\nasync function verifyRemote(\n remote: string,\n ref: PinnedRemoteRef,\n fetchImpl: typeof fetch,\n): Promise<RollbackRemoteCheck> {\n const base = typeof ref.production === \"string\" ? ref.production : undefined;\n const digest = digestOf(ref);\n if (!digest) return { remote, ok: true };\n const { manifest, integrity } = digest;\n\n if (!base)\n return { remote, manifest, ok: false, reason: \"no production URL to fetch the manifest from\" };\n\n const verified = await fetchVerifiedManifest({\n base,\n digest: { manifest, integrity },\n fetchImpl,\n });\n if (!verified.ok) {\n return { remote, manifest, ok: false, reason: verified.reason };\n }\n return { remote, manifest, ok: true };\n}\n\nexport async function verifyRollbackSnapshot(\n config: BosConfigInput,\n opts?: { fetchImpl?: typeof fetch },\n): Promise<RollbackVerification> {\n const fetchImpl = opts?.fetchImpl ?? fetch;\n const pinned = collectPinnedRemotes(config).filter((entry) => digestOf(entry.ref) !== null);\n\n if (pinned.length === 0) {\n return { verifiable: false, ok: false, remotes: [] };\n }\n\n const remotes = await Promise.all(\n pinned.map((entry) => verifyRemote(entry.remote, entry.ref, fetchImpl)),\n );\n return { verifiable: true, ok: remotes.every((check) => check.ok), remotes };\n}\n\nexport function summarizeRemoteDigests(config: BosConfigInput): string {\n const pinned = collectPinnedRemotes(config)\n .map((entry) => {\n const digest = digestOf(entry.ref);\n return digest ? `${entry.remote}=${digest.manifest}` : null;\n })\n .filter(Boolean) as string[];\n return pinned.length > 0 ? pinned.join(\" \") : \"no version pins (pre-pin snapshot)\";\n}\n\nexport function buildRollbackPayload<T extends object>(\n targetConfig: T,\n rolledBackFrom: string,\n): T & { rolledBackFrom: string } {\n return { ...targetConfig, rolledBackFrom };\n}\n"],"mappings":";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