{"version":3,"file":"rollback.cjs","names":["collectPinnedRemotes","digestOf","verifyChain"],"sources":["../../../src/services/deploy/rollback.ts"],"sourcesContent":["import type { BosConfigInput } from \"../../types\";\nimport { collectPinnedRemotes, digestOf, verifyChain } from \"../verify/chain\";\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\nexport { collectRemoteDescriptors, type RemoteDescriptor } from \"../verify/chain\";\n\nexport async function verifyRollbackSnapshot(\n  config: BosConfigInput,\n  opts?: { fetchImpl?: typeof fetch },\n): Promise<RollbackVerification> {\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 chain = await verifyChain({\n    config,\n    depth: \"pointer\",\n    ...(opts?.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),\n  });\n  const walked = new Map(chain.remotes.map((remote) => [remote.remote, remote]));\n\n  const remotes: RollbackRemoteCheck[] = pinned.map((entry) => {\n    const digest = digestOf(entry.ref)!;\n    const check = walked.get(entry.remote);\n    if (!check) {\n      return {\n        remote: entry.remote,\n        manifest: digest.manifest,\n        ok: false,\n        reason: \"no production URL to fetch the manifest from\",\n      };\n    }\n    return {\n      remote: entry.remote,\n      manifest: check.manifest,\n      ok: check.manifestOk,\n      ...(check.manifestReason !== undefined ? { reason: check.manifestReason } : {}),\n    };\n  });\n  return { verifiable: true, ok: remotes.every((remote) => remote.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":";;;AA6BA,eAAsB,uBACpB,QACA,MAC+B;CAC/B,MAAM,SAASA,mCAAqB,MAAM,CAAC,CAAC,QAAQ,UAAUC,uBAAS,MAAM,GAAG,MAAM,IAAI;CAE1F,IAAI,OAAO,WAAW,GACpB,OAAO;EAAE,YAAY;EAAO,IAAI;EAAO,SAAS,CAAC;CAAE;CAGrD,MAAM,QAAQ,MAAMC,0BAAY;EAC9B;EACA,OAAO;EACP,GAAI,MAAM,cAAc,SAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;CACvE,CAAC;CACD,MAAM,SAAS,IAAI,IAAI,MAAM,QAAQ,KAAK,WAAW,CAAC,OAAO,QAAQ,MAAM,CAAC,CAAC;CAE7E,MAAM,UAAiC,OAAO,KAAK,UAAU;EAC3D,MAAM,SAASD,uBAAS,MAAM,GAAG;EACjC,MAAM,QAAQ,OAAO,IAAI,MAAM,MAAM;EACrC,IAAI,CAAC,OACH,OAAO;GACL,QAAQ,MAAM;GACd,UAAU,OAAO;GACjB,IAAI;GACJ,QAAQ;EACV;EAEF,OAAO;GACL,QAAQ,MAAM;GACd,UAAU,MAAM;GAChB,IAAI,MAAM;GACV,GAAI,MAAM,mBAAmB,SAAY,EAAE,QAAQ,MAAM,eAAe,IAAI,CAAC;EAC/E;CACF,CAAC;CACD,OAAO;EAAE,YAAY;EAAM,IAAI,QAAQ,OAAO,W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