import { execFileSync } from 'node:child_process'; import { existsSync, mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { verifyCheckout, verifyProductionParity, verificationEnvironment } from './tangled-verify.mjs'; export const requiredWorkflows = ['verify-go.yml', 'verify-appview-image.yml', 'verify-web.yml']; const shaPattern = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/; const failureStates = new Set(['failed', 'timeout', 'cancelled', 'blocked']); const pushType = 'org.tangled.event.push'; const manualType = 'org.tangled.ci.trigger.manual'; const developmentAliasBranch = 'chore/remove-editorial-feeds'; function httpsOrigin(raw) { const url = new URL(raw); if (url.protocol !== 'https:' || url.username || url.password || url.pathname !== '/' || url.search || url.hash) throw new Error('A public HTTPS spindle origin is required.'); return url.origin; } export function deploymentContext(environment) { const branch = environment.TANGLED_REF_NAME; if (!['main', 'dev'].includes(branch) || environment.TANGLED_REF !== `refs/heads/${branch}`) throw new Error('Deployments require an explicit main or dev branch.'); if (environment.TANGLED_PIPELINE_KIND !== 'manual') throw new Error('Only explicit manual runs may deploy.'); if (!shaPattern.test(environment.TANGLED_SHA ?? '')) throw new Error('A full immutable deployment commit is required.'); if (!/^did:[a-z0-9]+:[A-Za-z0-9._:%-]+$/.test(environment.TANGLED_REPO_REPO_DID ?? '')) throw new Error('Repository DID is required.'); if (!/^[A-Za-z0-9._~-]{1,128}$/.test(environment.TANGLED_PIPELINE_ID ?? '')) throw new Error('Pipeline ID is required.'); if (!/^[A-Za-z0-9._~-]{1,128}$/.test(environment.TANGLED_INPUT_VERIFICATION_PIPELINE_ID ?? '')) throw new Error('An explicit verification pipeline ID is required.'); if (environment.TANGLED_PIPELINE_SOURCE && environment.TANGLED_PIPELINE_SOURCE !== environment.TANGLED_REPO_REPO_DID) throw new Error('Fork source cannot deploy.'); const topology = environment.TANGLED_VERCEL_TOPOLOGY; if (!['split', 'consolidated'].includes(topology)) throw new Error('Explicit split or consolidated deployment topology is required.'); return { branch, sha: environment.TANGLED_SHA, repo: environment.TANGLED_REPO_REPO_DID, pipeline: environment.TANGLED_PIPELINE_ID, kind: environment.TANGLED_PIPELINE_KIND, verificationPipeline: environment.TANGLED_INPUT_VERIFICATION_PIPELINE_ID, spindle: httpsOrigin(environment.TANGLED_SPINDLE_URL), topology, appEnv: branch === 'main' ? 'prod' : 'dev', target: branch === 'main' ? 'production' : 'preview', }; } /** Accept only explicitly selected file-based checks on this exact protected revision. */ export function pipelineVerified(pipeline, context) { if (!pipeline || pipeline.id !== context.verificationPipeline || pipeline.repo !== context.repo || pipeline.commit !== context.sha || (pipeline.sourceRepo && pipeline.sourceRepo !== context.repo)) throw new Error('Pipeline identity does not match the deployment.'); const trigger = pipeline.trigger; if (!trigger || trigger.repo !== context.repo || trigger.ref !== `refs/heads/${context.branch}` || ![pushType, manualType].includes(trigger.$type) || (trigger.$type === pushType ? trigger.newSha : trigger.commit) !== context.sha) throw new Error('Pipeline trigger does not match the protected branch revision.'); if (!Array.isArray(pipeline.workflows) || pipeline.workflows.length > 50) throw new Error('Invalid pipeline workflows.'); let complete = true; for (const id of requiredWorkflows) { const matches = pipeline.workflows.filter(workflow => workflow.id === id); if (matches.length !== 1) throw new Error(`Required verification is missing or ambiguous: ${id}`); const workflow = matches[0], source = workflow.definition?.source; if (workflow.definition?.id !== id || source?.repo !== context.repo || source?.commit !== context.sha || source?.path !== `.tangled/workflows/${id}` || source?.$type !== 'org.tangled.ci.defs#fileSource') throw new Error(`Verification provenance is invalid: ${id}`); if (failureStates.has(workflow.status)) throw new Error(`Required verification did not succeed: ${id}`); if (!['pending', 'scheduled', 'running', 'success'].includes(workflow.status)) throw new Error(`Unknown verification status: ${id}`); if (workflow.status !== 'success') complete = false; } return complete; } export async function waitForVerification(context, { request = fetch, sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), attempts = 180, intervalMS = 10_000, } = {}) { if (!Number.isInteger(attempts) || attempts < 1 || attempts > 180 || !Number.isInteger(intervalMS) || intervalMS < 0 || intervalMS > 10_000) throw new Error('Invalid verification wait bounds.'); const url = new URL('/xrpc/org.tangled.ci.getPipeline', context.spindle); url.searchParams.set('repo', context.repo); url.searchParams.set('pipeline', context.verificationPipeline); for (let attempt = 0; attempt < attempts; attempt++) { const response = await request(url, { redirect: 'error', signal: AbortSignal.timeout(15_000), headers: { Accept: 'application/json' } }); if (!response.ok) throw new Error(`Spindle verification query failed (${response.status}).`); const body = await response.text(); if (Buffer.byteLength(body) > 1024 * 1024) throw new Error('Spindle verification response is too large.'); if (pipelineVerified(JSON.parse(body), context)) return; if (attempt + 1 < attempts) await sleep(intervalMS); } throw new Error(attempts === 1 ? 'Selected verification pipeline has not completed all required checks.' : 'Required verification did not finish within the deployment deadline.'); } export function deploymentTargets(context, environment, { exists = existsSync, cwd = process.cwd() } = {}) { const web = environment.VERCEL_WEB_PROJECT_ID, appview = environment.VERCEL_APPVIEW_PROJECT_ID; if (!/^prj_[A-Za-z0-9]+$/.test(web ?? '') || !/^team_[A-Za-z0-9]+$/.test(environment.VERCEL_ORG_ID ?? '')) throw new Error('Verified Vercel team and project IDs are required.'); if (context.topology === 'consolidated') { if (!exists(join(cwd, 'vercel.ts')) || !exists(join(cwd, 'scripts/render-vercel-config.ts'))) throw new Error('Consolidated source configuration is missing.'); return [{ name: 'consolidated', project: web, root: '.', domains: context.branch === 'dev' ? ['testing.thesocialwire.app', 'api.testing.thesocialwire.app'] : [] }]; } if (!/^prj_[A-Za-z0-9]+$/.test(appview ?? '') || appview === web) throw new Error('Split topology requires two distinct existing projects.'); if (!exists(join(cwd, 'apps/web/vercel.json')) || !exists(join(cwd, 'services/appview/scripts/vercel-config.ts'))) throw new Error('Split source configuration is missing; do not activate consolidation implicitly.'); return [ { name: 'appview', project: appview, root: 'services/appview', domains: context.branch === 'dev' ? ['api.testing.thesocialwire.app'] : [] }, { name: 'web', project: web, root: 'apps/web', domains: context.branch === 'dev' ? ['testing.thesocialwire.app'] : [] }, ]; } export function assertCurrentBranch(context, readGit) { const output = readGit(['ls-remote', '--exit-code', 'origin', `refs/heads/${context.branch}`]).trim(); const lines = output.split('\n'); if (lines.length !== 1 || lines[0] !== `${context.sha}\trefs/heads/${context.branch}`) throw new Error('Deployment branch moved; the newer revision must be verified instead.'); } export function deploymentArguments(context, target) { const args = ['deploy', '--yes', '--project', target.project, '--environment', context.target, '--meta', `tangledCommitSha=${context.sha}`, '--meta', `tangledPipelineId=${context.pipeline}`, '--meta', `tangledVerificationPipelineId=${context.verificationPipeline}`]; if (context.target === 'production') args.push('--skip-domain'); // Vercel's GitHub-linked project uses these compatibility keys to attach the // dev Preview variables. Uploaded source and generic Git metadata stay Tangled. if (context.branch === 'dev' && context.target === 'preview') args.push('--meta', 'githubDeployment=1', '--meta', 'githubCommitRef=dev'); for (const [key, value] of Object.entries({ APP_ENV: context.appEnv, VERCEL_GIT_COMMIT_REF: context.branch, DEPLOY_SCHEMA_INITIALIZATION: 'false' })) { args.push('--env', `${key}=${value}`, '--build-env', `${key}=${value}`); } return args; } export function command(command, args, { cwd, environment = process.env, capture = false, timeout = 30 * 60 * 1000 } = {}) { try { const output = execFileSync(command, args, { cwd, env: environment, encoding: 'utf8', timeout, maxBuffer: 2 * 1024 * 1024, stdio: capture ? ['ignore', 'pipe', 'pipe'] : 'inherit' }); return capture ? output.trim() : ''; } catch (error) { const status = Number.isInteger(error.status) ? error.status : 'unknown'; const code = /^[A-Z0-9_]+$/.test(error.code ?? '') ? error.code : 'unavailable'; throw new Error(`${command} ${args[0] ?? ''} failed (exit ${status}, code ${code}); deployment stopped.`); } } export function prepareSourceArchive(cwd, archive, context, clean, execute = command) { execute('git', ['clone', '--local', '--no-hardlinks', '--no-checkout', cwd, archive], { environment: clean }); execute('git', ['checkout', '--detach', context.sha], { cwd: archive, environment: clean }); execute('git', ['update-ref', `refs/heads/${context.branch}`, context.sha], { cwd: archive, environment: clean }); execute('git', ['symbolic-ref', 'HEAD', `refs/heads/${context.branch}`], { cwd: archive, environment: clean }); const remote = execute('git', ['remote', 'get-url', 'origin'], { cwd, environment: clean, capture: true }); execute('git', ['remote', 'set-url', 'origin', remote], { cwd: archive, environment: clean }); } // The frozen compatibility branch keeps stable domains off candidate dev builds. // It is outside the main/dev deploy allowlist; explicit aliases control traffic. export function verifyPreviewDomainStaging(target, context, environment, execute = command, cwd = process.cwd()) { if (context.topology !== 'consolidated' || context.branch !== 'dev' || context.target !== 'preview' || target.name !== 'consolidated') return; const team = environment.VERCEL_ORG_ID; if (!/^team_[A-Za-z0-9]+$/.test(team ?? '') || !/^prj_[A-Za-z0-9]+$/.test(target.project ?? '')) throw new Error('Preview staging requires a verified team and project.'); for (const domain of target.domains) { const configuration = JSON.parse(execute('vercel', ['api', `/v9/projects/${target.project}/domains/${encodeURIComponent(domain)}?teamId=${team}`, '--method', 'GET'], { cwd, environment, capture: true })); if (configuration.name !== domain || configuration.projectId !== target.project || configuration.verified !== true || configuration.gitBranch !== developmentAliasBranch) { throw new Error(`Development domain ${domain} must be verified and bound to ${developmentAliasBranch} before staging.`); } } } function loginBrandingImagePaths(html, origin) { const assets = new Set(); const isBranding = path => /^\/_next\/static\/media\/icon\.[A-Za-z0-9._-]+\.png$/.test(path) || /^\/icons\/social-wire-icon-(?:light|dark)-192\.png$/.test(path); for (const [tag] of html.matchAll(/]*>/gi)) { const src = tag.match(/\ssrc\s*=\s*(["'])(.*?)\1/i)?.[2]; if (!src) continue; let image; try { image = new URL(src.replaceAll('&', '&'), origin); } catch { throw new Error('Login image resource URL is invalid.'); } if (image.origin !== origin || image.username || image.password || image.hash) throw new Error('Login image resources must stay on the candidate origin.'); let original = image; if (image.pathname === '/_next/image') { try { original = new URL(image.searchParams.get('url') ?? '', origin); } catch { throw new Error('Login image resource URL is invalid.'); } } if (original.origin === origin && isBranding(original.pathname)) assets.add(`${image.pathname}${image.search}`); } if (!assets.size) throw new Error('Candidate login page does not render a local branding image.'); return assets; } export function verifyCandidate(candidate, context, execute = command) { const team = candidate.environment.VERCEL_ORG_ID; if (!/^team_[A-Za-z0-9]+$/.test(team ?? '') || !/^prj_[A-Za-z0-9]+$/.test(candidate.project ?? '')) throw new Error('Candidate team or project identity is invalid.'); const options = { cwd: candidate.archive, environment: candidate.environment, capture: true }; const deployment = JSON.parse(execute('vercel', ['api', `/v13/deployments/${new URL(candidate.url).hostname}?teamId=${team}`, '--method', 'GET'], options)); const branch = deployment.gitMetadata?.commitRef ?? deployment.meta?.gitCommitRef; const commit = deployment.gitMetadata?.commitSha ?? deployment.meta?.gitCommitSha; if (!/^dpl_[A-Za-z0-9]+$/.test(deployment.id ?? '') || deployment.projectId !== candidate.project || deployment.readyState !== 'READY' || branch !== context.branch || commit !== context.sha || (context.target === 'production' ? deployment.target !== 'production' : deployment.target != null && deployment.target !== 'preview')) throw new Error('Candidate readiness, deployment identity, target or generic Git branch metadata is invalid.'); if (candidate.name !== 'web') { // READY confirms the build, not that branch-scoped runtime configuration was // attached. Vercel returns only variable names here; never pull their values. const required = ['TURSO_DATABASE_URL', 'TURSO_AUTH_TOKEN', 'SCHEDULING_TURSO_DATABASE_URL', 'SCHEDULING_TURSO_AUTH_TOKEN', 'DATABASE_BACKEND', 'RUNTIME_MODE', 'JOBS_RUNNER_MODE', 'JOBS_SECRET', 'CRON_SECRET', 'PDS_ATTESTATION_RECEIPT_SECRET', 'SOCIAL_DRAFT_STORAGE_KEY', 'SCHEDULING_STORAGE_KEY', 'BLOB_READ_WRITE_TOKEN']; const attached = new Set(Array.isArray(deployment.env) ? deployment.env.filter(key => typeof key === 'string') : []); const missing = required.filter(key => !attached.has(key)); if (missing.length) throw new Error(`Candidate runtime configuration is missing required environment variable names: ${missing.join(', ')}.`); } const curl = (path, image = false) => execute('vercel', ['curl', path, '--deployment', candidate.url, '--', '--fail', '--silent', '--show-error', '--max-time', '20', '--retry', '2', '--retry-all-errors', ...(image ? ['--output', '/dev/null', '--write-out', '%{http_code} %{content_type}'] : [])], options); if (candidate.name !== 'web') curl('/readyz'); if (candidate.name !== 'appview') { curl('/'); const metadata = JSON.parse(curl('/oauth-client-metadata.json')); if (metadata.client_id !== `${candidate.url}/oauth-client-metadata.json` || !metadata.redirect_uris?.includes(`${candidate.url}/callback`)) throw new Error('Candidate Web OAuth metadata is not deployment-local.'); for (const asset of loginBrandingImagePaths(curl('/login'), candidate.url)) { const [status, mime] = curl(asset, true).trim().split(/\s+/); if (status !== '200' || !/^image\//i.test(mime ?? '')) throw new Error('Candidate login branding resource must return HTTP 200 with an image content type.'); } } return deployment.id; } export async function activateCandidate(candidate, context, execute = command, { sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), attempts = 60, intervalMS = 1000, beforeMutation = () => {}, } = {}) { const team = candidate.environment.VERCEL_ORG_ID; if (!/^team_[A-Za-z0-9]+$/.test(team ?? '') || !/^prj_[A-Za-z0-9]+$/.test(candidate.project ?? '') || !/^dpl_[A-Za-z0-9]+$/.test(candidate.id ?? '')) throw new Error('A verified candidate deployment, team and project are required for activation.'); const options = { cwd: candidate.archive, environment: candidate.environment, capture: true }; if (context.target === 'production') { if (!Number.isInteger(attempts) || attempts < 1 || attempts > 60 || !Number.isInteger(intervalMS) || intervalMS < 0 || intervalMS > 1000) throw new Error('Invalid promotion wait bounds.'); const domainPage = JSON.parse(execute('vercel', ['api', `/v9/projects/${candidate.project}/domains?teamId=${team}&limit=100`, '--method', 'GET'], options)); if (!Array.isArray(domainPage.domains) || domainPage.pagination?.next != null) throw new Error('Production domains could not be completely verified.'); const domains = domainPage.domains.filter(domain => domain.gitBranch == null && domain.customEnvironmentId == null); if (!domains.length || domains.some(domain => domain.projectId !== candidate.project || domain.verified !== true || !/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(domain.name))) throw new Error('Production domains do not match the verified project.'); beforeMutation(); execute('vercel', ['api', `/v10/projects/${candidate.project}/promote/${candidate.id}?teamId=${team}`, '--method', 'POST'], options); for (let attempt = 0; attempt < attempts; attempt++) { const project = JSON.parse(execute('vercel', ['api', `/v9/projects/${candidate.project}?teamId=${team}`, '--method', 'GET'], options)); if (project.id !== candidate.project || project.accountId !== team) throw new Error('Promotion project does not match the verified candidate.'); const page = JSON.parse(execute('vercel', ['api', `/v1/projects/${candidate.project}/promote/aliases?teamId=${team}&limit=100`, '--method', 'GET'], options)); if (!Array.isArray(page.aliases) || page.pagination?.next != null || page.aliases.some(alias => !['pending', 'completed', 'failed'].includes(alias.status))) throw new Error('Promotion alias status is invalid or incomplete.'); if (page.aliases.some(alias => alias.status === 'failed')) throw new Error('Candidate promotion did not succeed.'); const production = project.targets?.production; if (production?.id === candidate.id && production.teamId === team && production.target === 'production' && page.aliases.every(alias => alias.status === 'completed') && domains.every(domain => page.aliases.filter(alias => alias.alias === domain.name && alias.status === 'completed').length === 1)) { let mapped = true; for (const domain of domains) { const alias = JSON.parse(execute('vercel', ['api', `/v4/aliases/${domain.name}?teamId=${team}`, '--method', 'GET'], options)); if (alias.alias !== domain.name || alias.deploymentId !== candidate.id || alias.projectId !== candidate.project) mapped = false; } if (mapped) return; } if (attempt + 1 < attempts) await sleep(intervalMS); } throw new Error('Candidate promotion did not complete before the deadline.'); } for (const [index, domain] of candidate.domains.entries()) { if (!/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(domain)) throw new Error('Candidate alias hostname is invalid.'); verifyPreviewDomainStaging({ ...candidate, domains: [domain] }, context, candidate.environment, execute, candidate.archive); const body = join(candidate.archive, '.vercel', `alias-${index}.json`); try { writeFileSync(body, JSON.stringify({ alias: domain }), { mode: 0o600, flag: 'wx' }); let assignmentError; beforeMutation(); try { execute('vercel', ['api', `/v2/deployments/${candidate.id}/aliases?teamId=${team}`, '--method', 'POST', '--input', body], options); } catch (error) { // Assigning an alias already on this deployment can return 409. Only // exact readback, never the status alone, makes that retry successful. assignmentError = error; } const alias = JSON.parse(execute('vercel', ['api', `/v4/aliases/${domain}?teamId=${team}`, '--method', 'GET'], options)); if (alias.alias !== domain || alias.deploymentId !== candidate.id || alias.projectId !== candidate.project) { if (assignmentError) throw assignmentError; throw new Error('Candidate alias does not point to the verified deployment.'); } } finally { rmSync(body, { force: true }); } } } export async function deploy({ cwd = process.cwd(), environment = process.env, execute = command, wait = waitForVerification } = {}) { const context = deploymentContext(environment); verifyCheckout(context.sha, { cwd }); const targets = deploymentTargets(context, environment, { cwd }); for (const target of targets) { const token = target.name === 'appview' ? environment.VERCEL_APPVIEW_TOKEN : environment.VERCEL_WEB_TOKEN; if (!token) throw new Error(`A project-scoped token is required for ${target.name}.`); } const clean = verificationEnvironment(environment); const readGit = args => execute('git', args, { cwd, environment: clean, capture: true, timeout: 60_000 }); assertCurrentBranch(context, readGit); await wait(context, { attempts: 1, intervalMS: 0 }); verifyProductionParity(environment, cwd, (tool, args) => execute(tool, args, { cwd, environment: clean })); assertCurrentBranch(context, readGit); for (const target of targets) { const token = target.name === 'appview' ? environment.VERCEL_APPVIEW_TOKEN : environment.VERCEL_WEB_TOKEN; verifyPreviewDomainStaging(target, context, { ...clean, VERCEL_TOKEN: token, VERCEL_ORG_ID: environment.VERCEL_ORG_ID }, execute, cwd); } const directory = mkdtempSync(join(tmpdir(), 'social-wire-vercel-')); const candidates = []; try { for (const target of targets) { assertCurrentBranch(context, readGit); const archive = join(directory, target.name); // A private clone preserves actual Tangled Git provenance independently of // Vercel's provider compatibility keys, without credentials or caches. prepareSourceArchive(cwd, archive, context, clean, execute); const rendererEnvironment = { ...clean, APP_ENV: context.appEnv, VERCEL_ENV: context.target, VERCEL_GIT_COMMIT_REF: context.branch }; if (target.name !== 'web') { const entrypoint = target.name === 'consolidated' ? 'scripts/render-vercel-config.ts' : undefined; const args = entrypoint ? [entrypoint] : ['--eval', 'import { appViewVercelConfig } from "./services/appview/scripts/vercel-config.ts"; console.log(JSON.stringify(appViewVercelConfig(process.env.APP_ENV, process.env.VERCEL_ENV, process.env.VERCEL_GIT_COMMIT_REF)))']; const rendered = execute('bun', args, { cwd: archive, environment: rendererEnvironment, capture: true }); JSON.parse(rendered); const configRoot = join(archive, target.root); writeFileSync(join(configRoot, 'vercel.json'), rendered, { mode: 0o600 }); rmSync(join(configRoot, 'vercel.ts'), { force: true }); } const link = join(archive, '.vercel'); mkdirSync(link, { recursive: true, mode: 0o700 }); writeFileSync(join(link, 'project.json'), JSON.stringify({ orgId: environment.VERCEL_ORG_ID, projectId: target.project }), { mode: 0o600 }); const token = target.name === 'appview' ? environment.VERCEL_APPVIEW_TOKEN : environment.VERCEL_WEB_TOKEN; const deployEnvironment = { ...clean, VERCEL_TOKEN: token, VERCEL_ORG_ID: environment.VERCEL_ORG_ID, VERCEL_PROJECT_ID: target.project }; const project = JSON.parse(execute('vercel', ['api', `/v9/projects/${target.project}?teamId=${environment.VERCEL_ORG_ID}`, '--method', 'GET'], { cwd: archive, environment: deployEnvironment, capture: true })); const expectedRoot = target.root === '.' ? null : target.root; if (project.id !== target.project || project.accountId !== environment.VERCEL_ORG_ID || (project.rootDirectory ?? null) !== expectedRoot) throw new Error('Vercel project identity or source root differs from the approved topology.'); const output = execute('vercel', deploymentArguments(context, target), { cwd: archive, environment: deployEnvironment, capture: true }); const candidate = output.trim().split(/\s+/).at(-1); const url = new URL(candidate); if (url.protocol !== 'https:' || !url.hostname.endsWith('.vercel.app') || url.pathname !== '/' || url.search || url.hash) throw new Error('Vercel returned an invalid deployment URL.'); candidates.push({ ...target, url: url.origin, environment: deployEnvironment, archive }); } for (const candidate of candidates) candidate.id = verifyCandidate(candidate, context, execute); // Do not assign a stale candidate after a newer push arrived during builds. assertCurrentBranch(context, readGit); for (const candidate of candidates) { assertCurrentBranch(context, readGit); await activateCandidate(candidate, context, execute, { beforeMutation: () => assertCurrentBranch(context, readGit) }); } return { version: 1, commit: context.sha, pipeline: context.pipeline, verificationPipeline: context.verificationPipeline, branch: context.branch, topology: context.topology, deployments: candidates.map(({ name, project, id, url }) => ({ name, project, id, url })) }; } finally { rmSync(directory, { recursive: true, force: true }); } } if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { deploy().then(receipt => console.log(`CI_DEPLOYMENT_RECEIPT ${JSON.stringify(receipt)}`)) .catch(error => { console.error(`Deployment failed: ${error.message}`); process.exitCode = 1; }); }