@smart-cloud/publisher-exporter 1.1.45 → 1.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- import w from'fs/promises';import ee from'http';import te from'https';import y from'path';import {CloudFrontClient,waitUntilInvalidationCompleted,CreateInvalidationCommand}from'@aws-sdk/client-cloudfront';import {createHash}from'crypto';function j(r){let e=r.trim();return e==="."?".":e.replace(/\/$/,"")}function re(r){let e=String(r??"").trim();if(!e)return "";let t=e;if(/^https?:\/\//i.test(t))try{t=new URL(t).pathname;}catch{return ""}if(t=t.split(/[?#]/,1)[0]?.replace(/\\/g,"/").trim()??"",!t)return "";let n=t.endsWith("/"),i=t.replace(/^\/+/,"").split("/").map(o=>o.replace(/[^A-Za-z0-9._-]/g,"")).filter(o=>o.length>0&&o!=="."&&o!=="..");if(i.length===0)return "";let s=`/${i.join("/")}`;return n&&y.extname(s)===""&&(s+="/"),s==="/"?"":s}function k(r){return !r||typeof r!="object"?{}:Object.fromEntries(Object.entries(r).map(([e,t])=>[e.trim(),String(t??"")]).filter(([e])=>e.length>0))}function ie(r){if(!r||typeof r!="object")return {};let e={};for(let[t,n]of Object.entries(r)){let i=t.trim();if(!i||!n||typeof n!="object")continue;let s=n,o={};if(typeof s.targetOrigin=="string"){let a=j(s.targetOrigin);a&&(o.targetOrigin=a);}let u=k(s.extraReplacements);if(Object.keys(u).length>0&&(o.extraReplacements=u),s.s3&&typeof s.s3=="object"){let a={},l=s.s3;typeof l.bucket=="string"&&(a.bucket=l.bucket.trim()),typeof l.prefix=="string"&&(a.prefix=l.prefix.trim()),typeof l.region=="string"&&(a.region=l.region.trim()),typeof l.htmlCacheControl=="string"&&(a.htmlCacheControl=l.htmlCacheControl.trim()),typeof l.assetCacheControl=="string"&&(a.assetCacheControl=l.assetCacheControl.trim()),Object.keys(a).length>0&&(o.s3=a);}if(s.cloudFront&&typeof s.cloudFront=="object"){let a={},l=s.cloudFront;typeof l.distributionId=="string"&&(a.distributionId=l.distributionId.trim()),Array.isArray(l.invalidationPaths)&&(a.invalidationPaths=l.invalidationPaths.map(c=>String(c??"").trim()).filter(c=>c.length>0)),Object.keys(a).length>0&&(o.cloudFront=a);}e[i]=o;}return e}function L(r){return r==="PROFESSIONAL"||r==="AGENCY"?r:void 0}function ne(r,e){if(!r||typeof r!="object")return null;let t=r,n=t.command;if(n!=="publish"&&n!=="crawl"&&n!=="deploy"&&n!=="invalidate"&&n!=="retry-timeouts"&&n!=="url"&&n!=="content-sync")return null;let i=Number.parseInt(String(t.intervalMinutes??"0"),10);if(!Number.isFinite(i)||i<1)return null;let s=String(t.id??`${n}-${e+1}`).trim();if(!s)return null;let o=String(t.deploymentProfile??"").trim(),u=String(t.url??"").trim(),a=Array.isArray(t.postTypes)?[...new Set(t.postTypes.map(c=>String(c??"").trim().toLowerCase().replace(/[^a-z0-9_-]/g,"")).filter(Boolean))]:[],l=Array.isArray(t.listingPaths)?[...new Set(t.listingPaths.map(c=>String(c??"").trim()).filter(Boolean))]:[];return n==="content-sync"&&a.length===0?null:{id:s,enabled:t.enabled!==false,command:n,intervalMinutes:i,...n==="publish"||n==="crawl"?{crawlMode:t.crawlMode==="incremental"?"incremental":"full"}:{},...(n==="publish"||n==="deploy"||n==="invalidate"||n==="content-sync")&&o?{deploymentProfile:o}:{},...u?{url:u}:{},...a.length>0?{postTypes:a}:{},...l.length>0?{listingPaths:l}:{},...typeof t.includeSubsites=="boolean"?{includeSubsites:t.includeSubsites}:{},...typeof t.includePostTypeArchives=="boolean"?{includePostTypeArchives:t.includePostTypeArchives}:{},...typeof t.includeTaxonomyArchives=="boolean"?{includeTaxonomyArchives:t.includeTaxonomyArchives}:{},...typeof t.includeAuthorArchives=="boolean"?{includeAuthorArchives:t.includeAuthorArchives}:{},...typeof t.includeDateArchives=="boolean"?{includeDateArchives:t.includeDateArchives}:{},...typeof t.includePostsPage=="boolean"?{includePostsPage:t.includePostsPage}:{},...typeof t.includeSitemapChain=="boolean"?{includeSitemapChain:t.includeSitemapChain}:{}}}function U(r){let e=r&&typeof r=="object"?r:{},t=Array.isArray(e.rules)?e.rules.map((n,i)=>ne(n,i)).filter(n=>!!n):[];return {enabled:e.enabled===true,timezone:typeof e.timezone=="string"&&e.timezone.trim()!==""?e.timezone.trim():"UTC",rules:t}}function se(r){if(!r||typeof r!="object")return;let e=r,t={};for(let i of ["accountId","siteId"]){let s=e[i];typeof s=="string"&&s.trim()!==""&&(t[i]=s.trim());}let n=Number(e.lastUpdate??0);return Number.isFinite(n)&&n>0&&(t.lastUpdate=Math.floor(n)),e.subscriber===true&&(t.subscriber=true),Object.keys(t).length>0?t:void 0}function x(r){let e=r&&typeof r=="object"?r:{},t=String(e.accountId??"").trim(),n=String(e.siteId??"").trim(),i=e.subscriber===true,s=se(e.siteSettings),o={...s??{},...t?{accountId:s?.accountId??t}:{},...n?{siteId:s?.siteId??n}:{},...s?.subscriber===true||i?{subscriber:true}:{}},u={},a=String(e.apiBase??"").trim();a&&(u.apiBase=a);let l=String(e.runtimeToken??e.nonce??"").trim();l&&(u.runtimeToken=l);let c=String(e.virtualAssetBaseUrl??e.uploadUrl??"").trim();c&&(u.virtualAssetBaseUrl=c),Object.keys(o).length>0&&(u.siteSettings=o);let d=L(e.subscriptionType);return d&&(u.subscriptionType=d),u}function oe(r){try{let e=new URL(r);globalThis.location=e;}catch{}}function $(r){return typeof r=="string"?r:r instanceof URL?r.toString():r.url}function ae(r,e){let t=new Headers(r instanceof Request?r.headers:void 0);if(e?.headers)for(let[n,i]of new Headers(e.headers).entries())t.set(n,i);return t}async function _(r,e,t=5){let n=new URL($(r)),i=String(e?.method??(r instanceof Request?r.method:"GET")).toUpperCase(),s=n.protocol==="http:"?ee:te,o=ae(r,e);return await new Promise((u,a)=>{let l=s.request(n,{method:i,headers:Object.fromEntries(o.entries()),...n.protocol==="https:"?{rejectUnauthorized:false}:{}},c=>{let d=[];c.on("data",g=>{d.push(Buffer.isBuffer(g)?g:Buffer.from(g));}),c.on("error",a),c.on("end",()=>{let g=c.statusCode??0,m=c.headers.location;if(t>0&&m&&[301,302,303,307,308].includes(g)){u(_(new URL(m,n),{method:g===303?"GET":i},t-1));return}let p=new Headers;for(let[f,h]of Object.entries(c.headers))Array.isArray(h)?p.set(f,h.join(", ")):typeof h=="string"&&p.set(f,h);u(new Response(Buffer.concat(d),{status:g,statusText:c.statusMessage??"",headers:p}));});});l.on("error",a),l.end();})}function le(r){let e=x(r.wpsuite),t={...e.siteSettings??{},...e.siteSettings?.subscriber===true||e.subscriptionType==="PROFESSIONAL"||e.subscriptionType==="AGENCY"?{subscriber:true}:{}},n=String(t.accountId??"").trim(),i=String(t.siteId??"").trim(),s=String(e.virtualAssetBaseUrl??e.uploadUrl??"").trim();if(r.wpsuite={...e.apiBase?{apiBase:e.apiBase}:{},...e.runtimeToken?{runtimeToken:e.runtimeToken}:{},...s?{virtualAssetBaseUrl:s}:{},...Object.keys(t).length>0?{siteSettings:t}:{},...e.subscriptionType?{subscriptionType:e.subscriptionType}:{}},!n||!i||!s)return false;oe(r.sourceOrigin);let o=globalThis,a={...o.WpSuite??{},siteSettings:t,uploadUrl:s};return e.apiBase&&(a.apiBase=e.apiBase),o.WpSuite=a,true}async function ue(r){let e=String(r.wpsuite?.virtualAssetBaseUrl??r.wpsuite?.uploadUrl??"").trim();if(!le(r)){let i=r.wpsuite?.siteSettings,s=[String(i?.accountId??"").trim()?"":"accountId",String(i?.siteId??"").trim()?"":"siteId",e?"":"virtualAssetBaseUrl"].filter(Boolean);return {remote:null,diagnostic:{status:"invalid-runtime",virtualAssetBaseUrl:e,subscriptionType:null,error:`Missing WP Suite runtime field(s): ${s.join(", ")}.`,requests:[]}}}let t=globalThis.fetch,n=[];try{typeof t=="function"&&/^https?:\/\//i.test(e)&&(globalThis.fetch=(async(a,l)=>{let c=$(a);if(c.startsWith(e)){let d=(()=>{try{return new URL(c).pathname}catch{return c}})();try{let g=r.ignoreHttpsErrors&&c.startsWith("https://")?await _(a,l):await t(a,l);return n.push({path:d,status:g.status,ok:g.ok,error:null}),g}catch(g){throw n.push({path:d,status:null,ok:!1,error:g instanceof Error?g.message:String(g)}),g}}return t(a,l)}));let{getConfig:i}=await import('@smart-cloud/wpsuite-core'),s=await i("publisher"),o=s&&typeof s=="object"?s:null,u=L(o?.subscriptionType);return {remote:o,diagnostic:{status:o?"loaded":"unavailable",virtualAssetBaseUrl:e,subscriptionType:u??null,error:o?null:"WP Suite publisher config loader returned no configuration.",requests:n}}}catch(i){return {remote:null,diagnostic:{status:"unavailable",virtualAssetBaseUrl:e,subscriptionType:null,error:i instanceof Error?i.message:String(i),requests:n}}}finally{typeof t=="function"&&(globalThis.fetch=t);}}function ce(r,e){let t=ie(e?.deploymentProfiles),n=String(e?.defaultDeploymentProfile??"").trim(),i=t[n]?n:"",s=L(e?.subscriptionType),o=x(r.wpsuite);return {...r,scheduler:U(e?.scheduler),deploymentProfiles:t,defaultDeploymentProfile:i,...s?{subscriptionType:s}:{},wpsuite:{...o,...o.siteSettings||s?{siteSettings:{...o.siteSettings??{},...o.siteSettings?.subscriber===true||s==="PROFESSIONAL"||s==="AGENCY"?{subscriber:true}:{}}}:{},...s?{subscriptionType:s}:{}}}}function E(r,e){let n=String(r||"").replace(/\\/g,"/").trim().replace(/^\/+|\/+$/g,"");if(!n)return e;let i=n.split("/").map(s=>s.trim()).filter(s=>s.length>0&&s!=="."&&s!=="..");return i.length>0?i.join("/"):e}function pe(){let r=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";return r.trim()?y.resolve(r):""}function N(r,e,t){let n=String(e||"").trim();return n&&y.isAbsolute(n)?y.resolve(n):y.resolve(r,E(n,t))}async function D(r,e={}){let t=String("").trim()||process.env.PUBLISHER_CONFIG||"publisher.config.json",n=await w.readFile(t,"utf8"),i=JSON.parse(n);i.sourceOrigin=i.sourceOrigin.replace(/\/$/,""),i.targetOrigin=j(i.targetOrigin),i.ignoreHttpsErrors??=false,i.outputDir=String(i.outputDir||"export").trim()||"export",i.urlRewriteMode||=i.targetOrigin==="."?"relative":"absolute",i.noJavaScriptRenderPathPrefixes||=[],i.seedPaths||=[],i.generated404RequestPath=re(i.generated404RequestPath),i.sitemapPaths||=["/sitemap_index.xml","/sitemap.xml"],i.allowedAssetHosts||=[],i.assetPathPrefixes||=["/wp-content/","/wp-includes/","/static/","/assets/","/build/","/_next/","/docs/","/sitemap","/robots.txt","/llms.txt"],i.blockedPathPrefixes||=[],i.blockedSearchFragments||=[],i.concurrency||=1,i.maxPages||=0,i.extraReplacements=k(i.extraReplacements),i.postCrawlCopyMap=k(i.postCrawlCopyMap),i.logDir=String(i.logDir||"logs").trim()||"logs",i.verbose??=false,i.logLevel||=i.verbose?"debug":"info",i.s3SyncMode||="sdk-upload-delete",i.readiness||={waitForSelector:null,waitForFunction:null,timeoutMs:1500,fallbackWaitMs:1500},i.readiness.timeoutMs??=1500,i.readiness.fallbackWaitMs??=1500,i.viewport||={width:1440,height:1200},i.navigationTimeoutMs||=3e4,i.assetDownloadConcurrency=Number(i.assetDownloadConcurrency)>0?Number(i.assetDownloadConcurrency):i.concurrency,i.rewriteConcurrency=Number(i.rewriteConcurrency)>0?Number(i.rewriteConcurrency):i.assetDownloadConcurrency,i.wpsuite=x(i.wpsuite),i.scheduler=U(void 0),i.deploymentProfiles={},i.defaultDeploymentProfile="",i.deploymentTargetOverride=String(i.deploymentTargetOverride??"").trim();let s=await ue(i);e.onRemotePublisherConfigDiagnostic?.(s.diagnostic);let o=ce(i,s.remote),u=pe(),a=u?y.resolve(u,".."):"";return a?(o.outputDir=N(a,o.outputDir,"export"),o.logDir=N(a,o.logDir,"logs")):(y.isAbsolute(o.outputDir)||(o.outputDir=E(o.outputDir,"export")),y.isAbsolute(o.logDir)||(o.logDir=E(o.logDir,"logs"))),o}function ge(r){let e=r/6e4;if(Number.isInteger(e)&&e>=1)return `${e} minute${"s"}`;let t=Math.ceil(r/1e3);return `${t} second${t===1?"":"s"}`}async function M(r,e,t){let n=new AbortController,i=globalThis.setTimeout(()=>{n.abort(new Error(`${r} timed out after ${ge(e)}.`));},e);try{return await t({abortController:n,httpOptions:{abortSignal:n.signal,requestTimeout:e}})}finally{globalThis.clearTimeout(i);}}function me(r){let e=r;return e.endsWith("/")?e+="index.html":y.posix.basename(e).includes(".")||(e+="/index.html"),e}function q(r,e){let t=new Set;for(let n of r){let i=new URL(n,"https://content-sync.invalid");if(i.origin!=="https://content-sync.invalid")continue;let s=`${i.pathname}${i.search}`;t.add(s),t.add(`${me(i.pathname)}${i.search}`);}return [...t].sort()}var fe=".deploy-plan.json",ye="deploy-plan.json";function Pe(){let r=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";return r.trim()?y.resolve(r):""}function be(r){let e=String(r||"").replace(/\\/g,"/").replace(/^\/+/,"").trim(),t=y.posix.normalize(e);return !e||!t||t==="."||/^[a-zA-Z]:/.test(t)||t.startsWith("../")||t===".."?null:t}function we(r){let e=String(r||"").trim();if(!e.startsWith("/")||e.startsWith("//")||e.includes("*")||e.includes("#"))return null;try{let t=new URL(e,"https://content-sync.invalid");return t.origin!=="https://content-sync.invalid"?null:`${y.posix.normalize(t.pathname)}${t.search}`}catch{return null}}function b(r){return [...new Set(r.map(be).filter(e=>e!==null))]}function Se(r,e){let t={generatedAt:String(e.generatedAt||new Date().toISOString()),outputDir:y.resolve(r.outputDir),runMode:e.runMode,crawlMode:e.crawlMode,fullSyncRequired:!!e.fullSyncRequired,changedFiles:b(e.changedFiles||[]),deletedFiles:b(e.deletedFiles||[]),rewriteTargets:b(e.rewriteTargets||[])};return e.schemaVersion===2?{...t,schemaVersion:2,runMode:"content-sync",crawlMode:"incremental",fullSyncRequired:false,consumerId:String(e.consumerId||"").trim(),fromSequence:Math.max(0,Number(e.fromSequence)||0),toSequence:Math.max(0,Number(e.toSequence)||0),impactHash:String(e.impactHash||"").trim(),uploadGroups:{assets:b(e.uploadGroups?.assets||[]),content:b(e.uploadGroups?.content||[]),listings:b(e.uploadGroups?.listings||[]),sitemapLeaves:b(e.uploadGroups?.sitemapLeaves||[]),sitemapIndexes:b(e.uploadGroups?.sitemapIndexes||[])},invalidationPaths:[...new Set((e.invalidationPaths||[]).map(we).filter(n=>n!==null))].sort()}:{schemaVersion:1,...t,runMode:e.runMode}}function ve(r){if(!r||typeof r!="object")return false;let e=r;if(e.schemaVersion===2){let t=e;return t.runMode==="content-sync"&&t.crawlMode==="incremental"&&t.fullSyncRequired===false&&typeof t.generatedAt=="string"&&typeof t.outputDir=="string"&&typeof t.consumerId=="string"&&t.consumerId.trim()!==""&&Number.isSafeInteger(t.fromSequence)&&Number.isSafeInteger(t.toSequence)&&Number(t.toSequence)>=Number(t.fromSequence)&&typeof t.impactHash=="string"&&/^[a-f0-9]{64}$/.test(t.impactHash)&&Array.isArray(t.changedFiles)&&Array.isArray(t.deletedFiles)&&Array.isArray(t.rewriteTargets)&&!!t.uploadGroups&&Array.isArray(t.uploadGroups.assets)&&Array.isArray(t.uploadGroups.content)&&Array.isArray(t.uploadGroups.listings)&&Array.isArray(t.uploadGroups.sitemapLeaves)&&Array.isArray(t.uploadGroups.sitemapIndexes)&&Array.isArray(t.invalidationPaths)}return e.schemaVersion===1&&typeof e.generatedAt=="string"&&typeof e.outputDir=="string"&&(e.runMode==="full"||e.runMode==="retry-timeouts"||e.runMode==="single-url")&&(e.crawlMode==="full"||e.crawlMode==="incremental")&&typeof e.fullSyncRequired=="boolean"&&Array.isArray(e.changedFiles)&&Array.isArray(e.deletedFiles)&&Array.isArray(e.rewriteTargets)}function Ie(r){let e=y.join(y.resolve(r.outputDir),fe),t=Pe();return t?[y.join(t,ye),e]:[e]}async function W(r){let e=y.resolve(r.outputDir);for(let t of Ie(r))try{let n=await w.readFile(t,"utf8"),i=JSON.parse(n);if(!ve(i)||y.resolve(i.outputDir)!==e)continue;return Se(r,i)}catch{}return null}function Ce(r){return typeof r.subscriptionType=="string"&&r.subscriptionType.trim()!==""}function B(r){let e="";for(let n=0;n<r.length;n++){let i=r[n];if(i==="--profile"){let s=(r[n+1]||"").trim();if(!s)throw new Error("Missing value for --profile.");e=s,n+=1;}else if(i.startsWith("--profile=")){let s=i.slice(10).trim();if(!s)throw new Error("Missing value for --profile.");e=s;}}let t=String(process.env.PUBLISHER_DEPLOY_PROFILE||process.env.PUBLISHER_DEPLOYMENT_PROFILE||"").trim();return e||t||null}function De(r,e){return {...r,...e??{}}}function Te(r,e){return {...r,...e??{},invalidationPaths:[...(e?.invalidationPaths??r.invalidationPaths)||[]]}}function H(r,e){let t=String(e??r.deploymentTargetOverride??"").trim();if(!Ce(r)){if(t)throw new Error(`Deployment target "${t}" requires an active WPSuite subscription and remote publisher config.`);return {name:null,profile:null,config:r}}let n=String(t||r.defaultDeploymentProfile||"").trim();if(!n)return {name:null,profile:null,config:r};let i=r.deploymentProfiles?.[n];if(!i)throw new Error(`Unknown deployment profile "${n}". Check the linked WPSuite publisher configuration.`);return {name:n,profile:i,config:{...r,targetOrigin:i.targetOrigin??r.targetOrigin,s3:De(r.s3,i.s3),cloudFront:Te(r.cloudFront,i.cloudFront)}}}var z={error:0,warn:1,info:2,debug:3},Re=/^(?:authorization|proxyAuthorization|runtimeToken|siteKey|nonce|accessToken|refreshToken|accessKeyId|secretAccessKey|sessionToken|xStaticPublisherToken|xApiKey)$/i;function C(r){return r.replace(/((?:x-static-publisher-token|authorization|proxy-authorization|x-api-key|aws-access-key-id|aws-secret-access-key|aws-session-token)\s*:\s*)[^\r\n]+/gi,"$1[REDACTED]").replace(/\b(Basic|Bearer)\s+[^\s]+/gi,"$1 [REDACTED]").replace(/([?&](?:token|access_token|refresh_token|api_key|key|nonce)=)[^&\s]+/gi,"$1[REDACTED]").replace(/((?:"|')?(?:runtimeToken|siteKey|nonce|accessToken|refreshToken|accessKeyId|secretAccessKey|sessionToken)(?:"|')?\s*[:=]\s*(?:"|'))[^"']+/gi,"$1[REDACTED]")}function R(r){return typeof r=="string"?C(r):Array.isArray(r)?r.map(e=>R(e)):r instanceof Error?{name:r.name,message:C(r.message),...r.stack?{stack:C(r.stack)}:{}}:r&&typeof r=="object"?Object.fromEntries(Object.entries(r).map(([e,t])=>[e,Re.test(e)?"[REDACTED]":R(t)])):r}function Q(r){return r?R(r):void 0}var J=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"",T=J?y.join(J,"current-progress.json"):"",G=Promise.resolve();function V(r){return r.includes("crawl")?"crawl":r.includes("deploy")?"deploy":r.includes("invalidate")?"invalidate":r}function Ae(r,e){let t={...r},n=new Set(["pagesQueued","pagesRendered","assetsQueued","sitemapsQueued","pagesDiscovered","assetsDiscovered","sitemapsDiscovered","pagesSaved","assetsSaved","donePages","doneAssets","doneSitemaps","changedTextFiles","uploaded","failed","index","totalFiles","pageQueue","assetQueue","sitemapQueue"]);for(let[i,s]of Object.entries(e)){let o=t[i];if(typeof o=="number"&&typeof s=="number"&&n.has(i)){t[i]=Math.max(o,s);continue}t[i]=s;}return t}function ke(r,e,t){T&&(G=G.then(async()=>{let n=new Date,i=n.toISOString();await w.mkdir(y.dirname(T),{recursive:true});let s=await w.readFile(T,"utf8").then(I=>JSON.parse(I)).catch(()=>null),o=s&&typeof s.details=="object"&&s.details?s.details:{},u=V(r),a=s?.currentStep||V(s?.source||""),l=s?.startedAt||i,c={...s?.stepDurationsSec??{}},d=s?.stepStartedAt||i;if(a&&a!==u&&s?.stepStartedAt){let I=Math.max(0,Math.round((n.getTime()-new Date(s.stepStartedAt).getTime())/1e3));c[a]=(c[a]??0)+I,d=i;}let g=Math.max(0,Math.round((n.getTime()-new Date(d).getTime())/1e3)),m=Math.max(0,Math.round((n.getTime()-new Date(l).getTime())/1e3)),p=C(e),f=Q(t)??{},h={checkedAt:i,source:r,message:p,details:Ae(o,f),startedAt:l,currentStep:u,stepStartedAt:d,stepElapsedSec:g,totalElapsedSec:m,stepDurationsSec:c};await w.writeFile(T,JSON.stringify(h,null,2),"utf8");}).catch(()=>{}));}async function Ee(r,e){await w.mkdir(y.dirname(r),{recursive:true}),await w.appendFile(r,`${JSON.stringify(R(e))}
1
+ import w from'fs/promises';import ee from'http';import te from'https';import y from'path';import {CloudFrontClient,waitUntilInvalidationCompleted,CreateInvalidationCommand}from'@aws-sdk/client-cloudfront';import {createHash}from'crypto';function $(r){let e=r.trim();return e==="."?".":e.replace(/\/$/,"")}function re(r){let e=String(r??"").trim();if(!e)return "";let t=e;if(/^https?:\/\//i.test(t))try{t=new URL(t).pathname;}catch{return ""}if(t=t.split(/[?#]/,1)[0]?.replace(/\\/g,"/").trim()??"",!t)return "";let n=t.endsWith("/"),i=t.replace(/^\/+/,"").split("/").map(o=>o.replace(/[^A-Za-z0-9._-]/g,"")).filter(o=>o.length>0&&o!=="."&&o!=="..");if(i.length===0)return "";let s=`/${i.join("/")}`;return n&&y.extname(s)===""&&(s+="/"),s==="/"?"":s}function k(r){return !r||typeof r!="object"?{}:Object.fromEntries(Object.entries(r).map(([e,t])=>[e.trim(),String(t??"")]).filter(([e])=>e.length>0))}function ie(r){if(!r||typeof r!="object")return {};let e={};for(let[t,n]of Object.entries(r)){let i=t.trim();if(!i||!n||typeof n!="object")continue;let s=n,o={};if(typeof s.targetOrigin=="string"){let a=$(s.targetOrigin);a&&(o.targetOrigin=a);}let l=k(s.extraReplacements);if(Object.keys(l).length>0&&(o.extraReplacements=l),s.s3&&typeof s.s3=="object"){let a={},u=s.s3;typeof u.bucket=="string"&&(a.bucket=u.bucket.trim()),typeof u.prefix=="string"&&(a.prefix=u.prefix.trim()),typeof u.region=="string"&&(a.region=u.region.trim()),typeof u.htmlCacheControl=="string"&&(a.htmlCacheControl=u.htmlCacheControl.trim()),typeof u.assetCacheControl=="string"&&(a.assetCacheControl=u.assetCacheControl.trim()),Object.keys(a).length>0&&(o.s3=a);}if(s.cloudFront&&typeof s.cloudFront=="object"){let a={},u=s.cloudFront;typeof u.distributionId=="string"&&(a.distributionId=u.distributionId.trim()),Array.isArray(u.invalidationPaths)&&(a.invalidationPaths=u.invalidationPaths.map(c=>String(c??"").trim()).filter(c=>c.length>0)),Object.keys(a).length>0&&(o.cloudFront=a);}e[i]=o;}return e}function L(r){return r==="PROFESSIONAL"||r==="AGENCY"?r:void 0}function ne(r,e){if(!r||typeof r!="object")return null;let t=r,n=t.command;if(n!=="publish"&&n!=="crawl"&&n!=="deploy"&&n!=="invalidate"&&n!=="retry-timeouts"&&n!=="url"&&n!=="content-sync")return null;let i=Number.parseInt(String(t.intervalMinutes??"0"),10);if(!Number.isFinite(i)||i<1)return null;let s=String(t.id??`${n}-${e+1}`).trim();if(!s)return null;let o=String(t.deploymentProfile??"").trim(),l=String(t.url??"").trim(),a=Array.isArray(t.postTypes)?[...new Set(t.postTypes.map(c=>String(c??"").trim().toLowerCase().replace(/[^a-z0-9_-]/g,"")).filter(Boolean))]:[],u=Array.isArray(t.listingPaths)?[...new Set(t.listingPaths.map(c=>String(c??"").trim()).filter(Boolean))]:[];return n==="content-sync"&&a.length===0?null:{id:s,enabled:t.enabled!==false,command:n,intervalMinutes:i,...n==="publish"||n==="crawl"?{crawlMode:t.crawlMode==="incremental"?"incremental":"full"}:{},...(n==="publish"||n==="deploy"||n==="invalidate"||n==="content-sync")&&o?{deploymentProfile:o}:{},...l?{url:l}:{},...a.length>0?{postTypes:a}:{},...u.length>0?{listingPaths:u}:{},...typeof t.includeSubsites=="boolean"?{includeSubsites:t.includeSubsites}:{},...typeof t.includePostTypeArchives=="boolean"?{includePostTypeArchives:t.includePostTypeArchives}:{},...typeof t.includeTaxonomyArchives=="boolean"?{includeTaxonomyArchives:t.includeTaxonomyArchives}:{},...typeof t.includeAuthorArchives=="boolean"?{includeAuthorArchives:t.includeAuthorArchives}:{},...typeof t.includeDateArchives=="boolean"?{includeDateArchives:t.includeDateArchives}:{},...typeof t.includePostsPage=="boolean"?{includePostsPage:t.includePostsPage}:{},...typeof t.includeSitemapChain=="boolean"?{includeSitemapChain:t.includeSitemapChain}:{}}}function j(r){let e=r&&typeof r=="object"?r:{},t=Array.isArray(e.rules)?e.rules.map((n,i)=>ne(n,i)).filter(n=>!!n):[];return {enabled:e.enabled===true,timezone:typeof e.timezone=="string"&&e.timezone.trim()!==""?e.timezone.trim():"UTC",rules:t}}function se(r){if(!r||typeof r!="object")return;let e=r,t={};for(let i of ["accountId","siteId"]){let s=e[i];typeof s=="string"&&s.trim()!==""&&(t[i]=s.trim());}let n=Number(e.lastUpdate??0);return Number.isFinite(n)&&n>0&&(t.lastUpdate=Math.floor(n)),e.subscriber===true&&(t.subscriber=true),Object.keys(t).length>0?t:void 0}function x(r){let e=r&&typeof r=="object"?r:{},t=String(e.accountId??"").trim(),n=String(e.siteId??"").trim(),i=e.subscriber===true,s=se(e.siteSettings),o={...s??{},...t?{accountId:s?.accountId??t}:{},...n?{siteId:s?.siteId??n}:{},...s?.subscriber===true||i?{subscriber:true}:{}},l={},a=String(e.apiBase??"").trim();a&&(l.apiBase=a);let u=String(e.runtimeToken??e.nonce??"").trim();u&&(l.runtimeToken=u);let c=String(e.virtualAssetBaseUrl??e.uploadUrl??"").trim();c&&(l.virtualAssetBaseUrl=c),Object.keys(o).length>0&&(l.siteSettings=o);let d=L(e.subscriptionType);return d&&(l.subscriptionType=d),l}function oe(r){try{let e=new URL(r);globalThis.location=e;}catch{}}function U(r){return typeof r=="string"?r:r instanceof URL?r.toString():r.url}function ae(r,e){let t=new Headers(r instanceof Request?r.headers:void 0);if(e?.headers)for(let[n,i]of new Headers(e.headers).entries())t.set(n,i);return t}async function _(r,e,t=5){let n=new URL(U(r)),i=String(e?.method??(r instanceof Request?r.method:"GET")).toUpperCase(),s=n.protocol==="http:"?ee:te,o=ae(r,e);return await new Promise((l,a)=>{let u=s.request(n,{method:i,headers:Object.fromEntries(o.entries()),...n.protocol==="https:"?{rejectUnauthorized:false}:{}},c=>{let d=[];c.on("data",p=>{d.push(Buffer.isBuffer(p)?p:Buffer.from(p));}),c.on("error",a),c.on("end",()=>{let p=c.statusCode??0,m=c.headers.location;if(t>0&&m&&[301,302,303,307,308].includes(p)){l(_(new URL(m,n),{method:p===303?"GET":i},t-1));return}let g=new Headers;for(let[f,h]of Object.entries(c.headers))Array.isArray(h)?g.set(f,h.join(", ")):typeof h=="string"&&g.set(f,h);l(new Response(Buffer.concat(d),{status:p,statusText:c.statusMessage??"",headers:g}));});});u.on("error",a),u.end();})}function le(r){let e=x(r.wpsuite),t={...e.siteSettings??{},...e.siteSettings?.subscriber===true||e.subscriptionType==="PROFESSIONAL"||e.subscriptionType==="AGENCY"?{subscriber:true}:{}},n=String(t.accountId??"").trim(),i=String(t.siteId??"").trim(),s=String(e.virtualAssetBaseUrl??e.uploadUrl??"").trim();if(r.wpsuite={...e.apiBase?{apiBase:e.apiBase}:{},...e.runtimeToken?{runtimeToken:e.runtimeToken}:{},...s?{virtualAssetBaseUrl:s}:{},...Object.keys(t).length>0?{siteSettings:t}:{},...e.subscriptionType?{subscriptionType:e.subscriptionType}:{}},!n||!i||!s)return false;oe(r.sourceOrigin);let o=globalThis,a={...o.WpSuite??{},siteSettings:t,uploadUrl:s};return e.apiBase&&(a.apiBase=e.apiBase),o.WpSuite=a,true}async function ue(r){let e=String(r.wpsuite?.virtualAssetBaseUrl??r.wpsuite?.uploadUrl??"").trim();if(!le(r)){let i=r.wpsuite?.siteSettings,s=[String(i?.accountId??"").trim()?"":"accountId",String(i?.siteId??"").trim()?"":"siteId",e?"":"virtualAssetBaseUrl"].filter(Boolean);return {remote:null,diagnostic:{status:"invalid-runtime",virtualAssetBaseUrl:e,subscriptionType:null,error:`Missing WP Suite runtime field(s): ${s.join(", ")}.`,requests:[]}}}let t=globalThis.fetch,n=[];try{typeof t=="function"&&/^https?:\/\//i.test(e)&&(globalThis.fetch=(async(a,u)=>{let c=U(a);if(c.startsWith(e)){let d=(()=>{try{return new URL(c).pathname}catch{return c}})();try{let p=r.ignoreHttpsErrors&&c.startsWith("https://")?await _(a,u):await t(a,u);return n.push({path:d,status:p.status,ok:p.ok,error:null}),p}catch(p){throw n.push({path:d,status:null,ok:!1,error:p instanceof Error?p.message:String(p)}),p}}return t(a,u)}));let{getConfig:i}=await import('@smart-cloud/wpsuite-core'),s=await i("publisher"),o=s&&typeof s=="object"?s:null,l=L(o?.subscriptionType);return {remote:o,diagnostic:{status:o?"loaded":"unavailable",virtualAssetBaseUrl:e,subscriptionType:l??null,error:o?null:"WP Suite publisher config loader returned no configuration.",requests:n}}}catch(i){return {remote:null,diagnostic:{status:"unavailable",virtualAssetBaseUrl:e,subscriptionType:null,error:i instanceof Error?i.message:String(i),requests:n}}}finally{typeof t=="function"&&(globalThis.fetch=t);}}function ce(r,e){let t=ie(e?.deploymentProfiles),n=String(e?.defaultDeploymentProfile??"").trim(),i=t[n]?n:"",s=L(e?.subscriptionType),o=x(r.wpsuite);return {...r,scheduler:j(e?.scheduler),deploymentProfiles:t,defaultDeploymentProfile:i,...s?{subscriptionType:s}:{},wpsuite:{...o,...o.siteSettings||s?{siteSettings:{...o.siteSettings??{},...o.siteSettings?.subscriber===true||s==="PROFESSIONAL"||s==="AGENCY"?{subscriber:true}:{}}}:{},...s?{subscriptionType:s}:{}}}}function E(r,e){let n=String(r||"").replace(/\\/g,"/").trim().replace(/^\/+|\/+$/g,"");if(!n)return e;let i=n.split("/").map(s=>s.trim()).filter(s=>s.length>0&&s!=="."&&s!=="..");return i.length>0?i.join("/"):e}function ge(){let r=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";return r.trim()?y.resolve(r):""}function N(r,e,t){let n=String(e||"").trim();return n&&y.isAbsolute(n)?y.resolve(n):y.resolve(r,E(n,t))}async function D(r,e={}){let t=String("").trim()||process.env.PUBLISHER_CONFIG||"publisher.config.json",n=await w.readFile(t,"utf8"),i=JSON.parse(n);i.sourceOrigin=i.sourceOrigin.replace(/\/$/,""),i.targetOrigin=$(i.targetOrigin),i.ignoreHttpsErrors??=false,i.outputDir=String(i.outputDir||"export").trim()||"export",i.urlRewriteMode||=i.targetOrigin==="."?"relative":"absolute",i.noJavaScriptRenderPathPrefixes||=[],i.seedPaths||=[],i.generated404RequestPath=re(i.generated404RequestPath),i.sitemapPaths||=["/sitemap_index.xml","/sitemap.xml"],i.allowedAssetHosts||=[],i.assetPathPrefixes||=["/wp-content/","/wp-includes/","/static/","/assets/","/build/","/_next/","/docs/","/sitemap","/robots.txt","/llms.txt"],i.blockedPathPrefixes||=[],i.blockedSearchFragments||=[],i.concurrency||=1,i.maxPages||=0,i.extraReplacements=k(i.extraReplacements),i.postCrawlCopyMap=k(i.postCrawlCopyMap),i.logDir=String(i.logDir||"logs").trim()||"logs",i.verbose??=false,i.logLevel||=i.verbose?"debug":"info",i.s3SyncMode||="sdk-upload-delete",i.readiness||={waitForSelector:null,waitForFunction:null,timeoutMs:1500,fallbackWaitMs:1500},i.readiness.timeoutMs??=1500,i.readiness.fallbackWaitMs??=1500,i.viewport||={width:1440,height:1200},i.navigationTimeoutMs||=3e4,i.assetDownloadConcurrency=Number(i.assetDownloadConcurrency)>0?Number(i.assetDownloadConcurrency):i.concurrency,i.rewriteConcurrency=Number(i.rewriteConcurrency)>0?Number(i.rewriteConcurrency):i.assetDownloadConcurrency,i.wpsuite=x(i.wpsuite),i.scheduler=j(void 0),i.deploymentProfiles={},i.defaultDeploymentProfile="",i.deploymentTargetOverride=String(i.deploymentTargetOverride??"").trim();let s=await ue(i);e.onRemotePublisherConfigDiagnostic?.(s.diagnostic);let o=ce(i,s.remote),l=ge(),a=l?y.resolve(l,".."):"";return a?(o.outputDir=N(a,o.outputDir,"export"),o.logDir=N(a,o.logDir,"logs")):(y.isAbsolute(o.outputDir)||(o.outputDir=E(o.outputDir,"export")),y.isAbsolute(o.logDir)||(o.logDir=E(o.logDir,"logs"))),o}function pe(r){let e=r/6e4;if(Number.isInteger(e)&&e>=1)return `${e} minute${"s"}`;let t=Math.ceil(r/1e3);return `${t} second${t===1?"":"s"}`}async function M(r,e,t){let n=new AbortController,i=globalThis.setTimeout(()=>{n.abort(new Error(`${r} timed out after ${pe(e)}.`));},e);try{return await t({abortController:n,httpOptions:{abortSignal:n.signal,requestTimeout:e}})}finally{globalThis.clearTimeout(i);}}function me(r){let e=r;return e.endsWith("/")?e+="index.html":y.posix.basename(e).includes(".")||(e+="/index.html"),e}function he(r,e){let t=e.trim().replace(/^\/+|\/+$/g,"");if(!t)return null;let n=`/${t}`;return r===n||r.startsWith(`${n}/`)?r:`${n}${r.startsWith("/")?r:`/${r}`}`}function q(r,e){let t=new Set;for(let n of r){let i=new URL(n,"https://content-sync.invalid");if(i.origin!=="https://content-sync.invalid")continue;let s=`${i.pathname}${i.search}`,o=me(i.pathname);t.add(s),t.add(`${o}${i.search}`);let l=he(o,e);l&&t.add(`${l}${i.search}`);}return [...t].sort()}var ye=".deploy-plan.json",Pe="deploy-plan.json";function be(){let r=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";return r.trim()?y.resolve(r):""}function we(r){let e=String(r||"").replace(/\\/g,"/").replace(/^\/+/,"").trim(),t=y.posix.normalize(e);return !e||!t||t==="."||/^[a-zA-Z]:/.test(t)||t.startsWith("../")||t===".."?null:t}function Se(r){let e=String(r||"").trim();if(!e.startsWith("/")||e.startsWith("//")||e.includes("*")||e.includes("#"))return null;try{let t=new URL(e,"https://content-sync.invalid");return t.origin!=="https://content-sync.invalid"?null:`${y.posix.normalize(t.pathname)}${t.search}`}catch{return null}}function b(r){return [...new Set(r.map(we).filter(e=>e!==null))]}function ve(r,e){let t={generatedAt:String(e.generatedAt||new Date().toISOString()),outputDir:y.resolve(r.outputDir),runMode:e.runMode,crawlMode:e.crawlMode,fullSyncRequired:!!e.fullSyncRequired,changedFiles:b(e.changedFiles||[]),deletedFiles:b(e.deletedFiles||[]),rewriteTargets:b(e.rewriteTargets||[])};return e.schemaVersion===2?{...t,schemaVersion:2,runMode:"content-sync",crawlMode:"incremental",fullSyncRequired:false,consumerId:String(e.consumerId||"").trim(),fromSequence:Math.max(0,Number(e.fromSequence)||0),toSequence:Math.max(0,Number(e.toSequence)||0),impactHash:String(e.impactHash||"").trim(),uploadGroups:{assets:b(e.uploadGroups?.assets||[]),content:b(e.uploadGroups?.content||[]),listings:b(e.uploadGroups?.listings||[]),sitemapLeaves:b(e.uploadGroups?.sitemapLeaves||[]),sitemapIndexes:b(e.uploadGroups?.sitemapIndexes||[])},invalidationPaths:[...new Set((e.invalidationPaths||[]).map(Se).filter(n=>n!==null))].sort()}:{schemaVersion:1,...t,runMode:e.runMode}}function Ie(r){if(!r||typeof r!="object")return false;let e=r;if(e.schemaVersion===2){let t=e;return t.runMode==="content-sync"&&t.crawlMode==="incremental"&&t.fullSyncRequired===false&&typeof t.generatedAt=="string"&&typeof t.outputDir=="string"&&typeof t.consumerId=="string"&&t.consumerId.trim()!==""&&Number.isSafeInteger(t.fromSequence)&&Number.isSafeInteger(t.toSequence)&&Number(t.toSequence)>=Number(t.fromSequence)&&typeof t.impactHash=="string"&&/^[a-f0-9]{64}$/.test(t.impactHash)&&Array.isArray(t.changedFiles)&&Array.isArray(t.deletedFiles)&&Array.isArray(t.rewriteTargets)&&!!t.uploadGroups&&Array.isArray(t.uploadGroups.assets)&&Array.isArray(t.uploadGroups.content)&&Array.isArray(t.uploadGroups.listings)&&Array.isArray(t.uploadGroups.sitemapLeaves)&&Array.isArray(t.uploadGroups.sitemapIndexes)&&Array.isArray(t.invalidationPaths)}return e.schemaVersion===1&&typeof e.generatedAt=="string"&&typeof e.outputDir=="string"&&(e.runMode==="full"||e.runMode==="retry-timeouts"||e.runMode==="single-url")&&(e.crawlMode==="full"||e.crawlMode==="incremental")&&typeof e.fullSyncRequired=="boolean"&&Array.isArray(e.changedFiles)&&Array.isArray(e.deletedFiles)&&Array.isArray(e.rewriteTargets)}function Ce(r){let e=y.join(y.resolve(r.outputDir),ye),t=be();return t?[y.join(t,Pe),e]:[e]}async function W(r){let e=y.resolve(r.outputDir);for(let t of Ce(r))try{let n=await w.readFile(t,"utf8"),i=JSON.parse(n);if(!Ie(i)||y.resolve(i.outputDir)!==e)continue;return ve(r,i)}catch{}return null}function De(r){return typeof r.subscriptionType=="string"&&r.subscriptionType.trim()!==""}function B(r){let e="";for(let n=0;n<r.length;n++){let i=r[n];if(i==="--profile"){let s=(r[n+1]||"").trim();if(!s)throw new Error("Missing value for --profile.");e=s,n+=1;}else if(i.startsWith("--profile=")){let s=i.slice(10).trim();if(!s)throw new Error("Missing value for --profile.");e=s;}}let t=String(process.env.PUBLISHER_DEPLOY_PROFILE||process.env.PUBLISHER_DEPLOYMENT_PROFILE||"").trim();return e||t||null}function Te(r,e){return {...r,...e??{}}}function Re(r,e){return {...r,...e??{},invalidationPaths:[...(e?.invalidationPaths??r.invalidationPaths)||[]]}}function H(r,e){let t=String(e??r.deploymentTargetOverride??"").trim();if(!De(r)){if(t)throw new Error(`Deployment target "${t}" requires an active WPSuite subscription and remote publisher config.`);return {name:null,profile:null,config:r}}let n=String(t||r.defaultDeploymentProfile||"").trim();if(!n)return {name:null,profile:null,config:r};let i=r.deploymentProfiles?.[n];if(!i)throw new Error(`Unknown deployment profile "${n}". Check the linked WPSuite publisher configuration.`);return {name:n,profile:i,config:{...r,targetOrigin:i.targetOrigin??r.targetOrigin,s3:Te(r.s3,i.s3),cloudFront:Re(r.cloudFront,i.cloudFront)}}}var z={error:0,warn:1,info:2,debug:3},Ae=/^(?:authorization|proxyAuthorization|runtimeToken|siteKey|nonce|accessToken|refreshToken|accessKeyId|secretAccessKey|sessionToken|xStaticPublisherToken|xApiKey)$/i;function C(r){return r.replace(/((?:x-static-publisher-token|authorization|proxy-authorization|x-api-key|aws-access-key-id|aws-secret-access-key|aws-session-token)\s*:\s*)[^\r\n]+/gi,"$1[REDACTED]").replace(/\b(Basic|Bearer)\s+[^\s]+/gi,"$1 [REDACTED]").replace(/([?&](?:token|access_token|refresh_token|api_key|key|nonce)=)[^&\s]+/gi,"$1[REDACTED]").replace(/((?:"|')?(?:runtimeToken|siteKey|nonce|accessToken|refreshToken|accessKeyId|secretAccessKey|sessionToken)(?:"|')?\s*[:=]\s*(?:"|'))[^"']+/gi,"$1[REDACTED]")}function R(r){return typeof r=="string"?C(r):Array.isArray(r)?r.map(e=>R(e)):r instanceof Error?{name:r.name,message:C(r.message),...r.stack?{stack:C(r.stack)}:{}}:r&&typeof r=="object"?Object.fromEntries(Object.entries(r).map(([e,t])=>[e,Ae.test(e)?"[REDACTED]":R(t)])):r}function Q(r){return r?R(r):void 0}var J=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"",T=J?y.join(J,"current-progress.json"):"",G=Promise.resolve();function V(r){return r.includes("crawl")?"crawl":r.includes("deploy")?"deploy":r.includes("invalidate")?"invalidate":r}function ke(r,e){let t={...r},n=new Set(["pagesQueued","pagesRendered","assetsQueued","sitemapsQueued","pagesDiscovered","assetsDiscovered","sitemapsDiscovered","pagesSaved","assetsSaved","donePages","doneAssets","doneSitemaps","changedTextFiles","uploaded","failed","index","totalFiles","pageQueue","assetQueue","sitemapQueue"]);for(let[i,s]of Object.entries(e)){let o=t[i];if(typeof o=="number"&&typeof s=="number"&&n.has(i)){t[i]=Math.max(o,s);continue}t[i]=s;}return t}function Ee(r,e,t){T&&(G=G.then(async()=>{let n=new Date,i=n.toISOString();await w.mkdir(y.dirname(T),{recursive:true});let s=await w.readFile(T,"utf8").then(I=>JSON.parse(I)).catch(()=>null),o=s&&typeof s.details=="object"&&s.details?s.details:{},l=V(r),a=s?.currentStep||V(s?.source||""),u=s?.startedAt||i,c={...s?.stepDurationsSec??{}},d=s?.stepStartedAt||i;if(a&&a!==l&&s?.stepStartedAt){let I=Math.max(0,Math.round((n.getTime()-new Date(s.stepStartedAt).getTime())/1e3));c[a]=(c[a]??0)+I,d=i;}let p=Math.max(0,Math.round((n.getTime()-new Date(d).getTime())/1e3)),m=Math.max(0,Math.round((n.getTime()-new Date(u).getTime())/1e3)),g=C(e),f=Q(t)??{},h={checkedAt:i,source:r,message:g,details:ke(o,f),startedAt:u,currentStep:l,stepStartedAt:d,stepElapsedSec:p,totalElapsedSec:m,stepDurationsSec:c};await w.writeFile(T,JSON.stringify(h,null,2),"utf8");}).catch(()=>{}));}async function Le(r,e){await w.mkdir(y.dirname(r),{recursive:true}),await w.appendFile(r,`${JSON.stringify(R(e))}
2
2
  `,"utf8");}var v=class{constructor(e,t,n="info"){this.logDir=e;this.logFile=t;this.level=n;this.ensureLogFileReady();}logDir;logFile;level;startedAt=Date.now();marks=new Map;initPromise=null;writeQueue=Promise.resolve();writeError=null;get logPath(){return y.join(this.logDir,this.logFile)}artifactPath(e){return this.logFile.endsWith(".log.jsonl")?y.join(this.logDir,this.logFile.replace(/\.log\.jsonl$/u,`${e}.jsonl`)):y.join(this.logDir,`${this.logFile}${e}.jsonl`)}get errorsPath(){return this.artifactPath(".errors")}get rejectedPath(){return this.artifactPath(".rejected")}ensureLogFileReady(){return this.initPromise||(this.initPromise=(async()=>{await w.mkdir(this.logDir,{recursive:true}),await w.writeFile(this.logPath,"","utf8");})()),this.initPromise}enqueueTask(e){this.writeQueue=this.writeQueue.then(e).catch(t=>{this.writeError=t instanceof Error?t:new Error(String(t));});}enqueueLine(e){this.enqueueTask(async()=>{await this.ensureLogFileReady(),await w.appendFile(this.logPath,`${e}
3
- `,"utf8");});}enqueueJsonLine(e,t){this.enqueueTask(()=>Ee(e,t));}accepts(e){return z[e]<=z[this.level]}push(e,t,n){if(!this.accepts(e))return;let i=C(t),s=Q(n),o=JSON.stringify({time:new Date().toISOString(),level:e,message:i,...s||{}});this.enqueueLine(o),e==="error"?console.error(`[ERROR] ${i}`,s?JSON.stringify(s):""):e==="warn"?console.warn(`[WARN] ${i}`,s?JSON.stringify(s):""):console.log(`[${e.toUpperCase().padEnd(5)}] ${i}`);}info(e,t){this.push("info",e,t);}progress(e,t){ke(this.logFile,e,t);}debug(e,t){this.push("debug",e,t);}warn(e,t){this.push("warn",e,t);}reject(e,t,n,i,s){let o={kind:e,url:t,reason:n,...i?{source:i}:{},...s||{}};this.enqueueJsonLine(this.rejectedPath,o),this.accepts("debug")&&this.push("debug",`Rejected ${e} ${t}: ${n}`,o);}error(e,t){this.enqueueJsonLine(this.errorsPath,{message:e,...t||{}}),this.push("error",e,t);}mark(e){this.marks.set(e,Date.now());}endMark(e,t){let n=this.marks.get(e);if(!n)return;let i=Date.now()-n,s=Number((i/1e3).toFixed(2));this.push("info",`Timing ${e}: ${s}s`,{name:e,ms:i,seconds:s,...t||{}});}async flush(){let e=Date.now()-this.startedAt,t=Number((e/1e3).toFixed(2));if(this.push("info",`Total time: ${t}s`,{name:"total",ms:e,seconds:t}),await this.writeQueue,this.writeError)throw this.writeError}};function Fe(){let r=String(process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"").trim();return r?y.join(y.resolve(r),"content-sync-invalidation.json"):""}async function F(r,e){if(!r)return;await w.mkdir(y.dirname(r),{recursive:true});let t=`${r}.${process.pid}.${Date.now()}.tmp`;await w.writeFile(t,JSON.stringify({...e,updatedAt:new Date().toISOString()},null,2),"utf8"),await w.rename(t,r);}async function Oe(r,e,t,n){if(!r)return null;try{let i=JSON.parse(await w.readFile(r,"utf8"));if(i.schemaVersion!==1||i.distributionId!==e||i.impactHash!==t||!Array.isArray(i.batches))throw new Error("Content-sync invalidation state does not match the deploy plan.");let s=i.batches.flatMap(o=>o.paths);return s.length!==n.length||s.some((o,u)=>o!==n[u])?null:i}catch(i){if(i.code==="ENOENT")return null;throw i}}function Ne(r,e=3e3){let t=[];for(let n=0;n<r.length;n+=e)t.push(r.slice(n,n+e));return t}async function Z(r=process.argv.slice(2)){let e=await D(),t=B(r),n=H(e,t),i=n.config,s=new v(i.logDir||"logs","invalidate.log.jsonl",i.logLevel??"info"),o=r.includes("--content-sync"),u=await W(e);if(o&&u?.schemaVersion!==2)throw new Error("Content-sync invalidation requires a valid schema-2 targeted deploy plan.");if(n.name&&s.info(`Using deployment profile: ${n.name}`),!i.cloudFront.distributionId){s.info("No CloudFront distributionId configured; skipping invalidation."),await s.flush();return}let a=u?.schemaVersion===2?u.invalidationPaths:i.cloudFront.invalidationPaths.length>0?i.cloudFront.invalidationPaths:["/*"],l=u?.schemaVersion===2?q(a,i.s3.prefix||""):a;if(u?.schemaVersion===2&&l.some(p=>p==="/*"))throw new Error("Content-sync cannot use a whole-distribution invalidation.");if(l.length===0){s.info("The targeted deploy plan has no CloudFront paths to invalidate."),await s.flush();return}let c=i.cloudFront.distributionId,d=new CloudFrontClient({region:"us-east-1",maxAttempts:5});if(s.mark("invalidate"),u?.schemaVersion!==2){let p=`smartcloud-static-publisher-${Date.now()}`;await M(`CloudFront invalidation for distribution ${c}`,3e5,({httpOptions:f})=>d.send(new CreateInvalidationCommand({DistributionId:c,InvalidationBatch:{CallerReference:p,Paths:{Quantity:l.length,Items:l}}}),f)),s.endMark("invalidate"),await s.flush();return}let g=Fe(),m=await Oe(g,c,u.impactHash,l);if(!m){let p=createHash("sha256").update(JSON.stringify(l)).digest("hex");m={schemaVersion:1,distributionId:c,impactHash:u.impactHash,updatedAt:new Date().toISOString(),batches:Ne(l).map((f,h)=>({index:h,callerReference:`wpsuite-content-sync-${u.impactHash.slice(0,24)}-${p.slice(0,24)}-${h}`,paths:f,invalidationId:null,status:"pending"}))},await F(g,m);}for(let p of m.batches){if(!p.invalidationId){let f=await M(`CloudFront targeted invalidation batch ${p.index+1}`,3e5,({httpOptions:I})=>d.send(new CreateInvalidationCommand({DistributionId:c,InvalidationBatch:{CallerReference:p.callerReference,Paths:{Quantity:p.paths.length,Items:p.paths}}}),I)),h=String(f.Invalidation?.Id||"").trim();if(!h)throw new Error("CloudFront did not return an invalidation ID.");p.invalidationId=h,p.status="created",await F(g,m);}await waitUntilInvalidationCompleted({client:d,maxWaitTime:900,minDelay:2,maxDelay:15},{DistributionId:c,Id:p.invalidationId}),p.status="completed",await F(g,m),s.info(`CloudFront invalidation batch ${p.index+1}/${m.batches.length} completed.`,{invalidationId:p.invalidationId,pathCount:p.paths.length});}s.endMark("invalidate"),await s.flush();}Z().catch(async r=>{console.error(r);try{let e=await D().catch(()=>null),t=new v(e?.logDir??"logs","invalidate.log.jsonl","debug");t.error(`Unhandled error: ${r instanceof Error?r.message:String(r)}`,r instanceof Error?{stack:r.stack}:void 0),await t.flush();}catch{}process.exit(1);});
3
+ `,"utf8");});}enqueueJsonLine(e,t){this.enqueueTask(()=>Le(e,t));}accepts(e){return z[e]<=z[this.level]}push(e,t,n){if(!this.accepts(e))return;let i=C(t),s=Q(n),o=JSON.stringify({time:new Date().toISOString(),level:e,message:i,...s||{}});this.enqueueLine(o),e==="error"?console.error(`[ERROR] ${i}`,s?JSON.stringify(s):""):e==="warn"?console.warn(`[WARN] ${i}`,s?JSON.stringify(s):""):console.log(`[${e.toUpperCase().padEnd(5)}] ${i}`);}info(e,t){this.push("info",e,t);}progress(e,t){Ee(this.logFile,e,t);}debug(e,t){this.push("debug",e,t);}warn(e,t){this.push("warn",e,t);}reject(e,t,n,i,s){let o={kind:e,url:t,reason:n,...i?{source:i}:{},...s||{}};this.enqueueJsonLine(this.rejectedPath,o),this.accepts("debug")&&this.push("debug",`Rejected ${e} ${t}: ${n}`,o);}error(e,t){this.enqueueJsonLine(this.errorsPath,{message:e,...t||{}}),this.push("error",e,t);}mark(e){this.marks.set(e,Date.now());}endMark(e,t){let n=this.marks.get(e);if(!n)return;let i=Date.now()-n,s=Number((i/1e3).toFixed(2));this.push("info",`Timing ${e}: ${s}s`,{name:e,ms:i,seconds:s,...t||{}});}async flush(){let e=Date.now()-this.startedAt,t=Number((e/1e3).toFixed(2));if(this.push("info",`Total time: ${t}s`,{name:"total",ms:e,seconds:t}),await this.writeQueue,this.writeError)throw this.writeError}};function Oe(){let r=String(process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"").trim();return r?y.join(y.resolve(r),"content-sync-invalidation.json"):""}async function F(r,e){if(!r)return;await w.mkdir(y.dirname(r),{recursive:true});let t=`${r}.${process.pid}.${Date.now()}.tmp`;await w.writeFile(t,JSON.stringify({...e,updatedAt:new Date().toISOString()},null,2),"utf8"),await w.rename(t,r);}async function Ne(r,e,t,n){if(!r)return null;try{let i=JSON.parse(await w.readFile(r,"utf8"));if(i.schemaVersion!==1||i.distributionId!==e||i.impactHash!==t||!Array.isArray(i.batches))throw new Error("Content-sync invalidation state does not match the deploy plan.");let s=i.batches.flatMap(o=>o.paths);return s.length!==n.length||s.some((o,l)=>o!==n[l])?null:i}catch(i){if(i.code==="ENOENT")return null;throw i}}function $e(r,e=3e3){let t=[];for(let n=0;n<r.length;n+=e)t.push(r.slice(n,n+e));return t}async function Z(r=process.argv.slice(2)){let e=await D(),t=B(r),n=H(e,t),i=n.config,s=new v(i.logDir||"logs","invalidate.log.jsonl",i.logLevel??"info"),o=r.includes("--content-sync"),l=await W(e);if(o&&l?.schemaVersion!==2)throw new Error("Content-sync invalidation requires a valid schema-2 targeted deploy plan.");if(n.name&&s.info(`Using deployment profile: ${n.name}`),!i.cloudFront.distributionId){s.info("No CloudFront distributionId configured; skipping invalidation."),await s.flush();return}let a=l?.schemaVersion===2?l.invalidationPaths:i.cloudFront.invalidationPaths.length>0?i.cloudFront.invalidationPaths:["/*"],u=l?.schemaVersion===2?q(a,i.s3.prefix||""):a;if(l?.schemaVersion===2&&u.some(g=>g==="/*"))throw new Error("Content-sync cannot use a whole-distribution invalidation.");if(u.length===0){s.info("The targeted deploy plan has no CloudFront paths to invalidate."),await s.flush();return}let c=i.cloudFront.distributionId,d=new CloudFrontClient({region:"us-east-1",maxAttempts:5});if(s.mark("invalidate"),l?.schemaVersion!==2){let g=`smartcloud-static-publisher-${Date.now()}`;await M(`CloudFront invalidation for distribution ${c}`,3e5,({httpOptions:f})=>d.send(new CreateInvalidationCommand({DistributionId:c,InvalidationBatch:{CallerReference:g,Paths:{Quantity:u.length,Items:u}}}),f)),s.endMark("invalidate"),await s.flush();return}let p=Oe(),m=await Ne(p,c,l.impactHash,u);if(!m){let g=createHash("sha256").update(JSON.stringify(u)).digest("hex");m={schemaVersion:1,distributionId:c,impactHash:l.impactHash,updatedAt:new Date().toISOString(),batches:$e(u).map((f,h)=>({index:h,callerReference:`wpsuite-content-sync-${l.impactHash.slice(0,24)}-${g.slice(0,24)}-${h}`,paths:f,invalidationId:null,status:"pending"}))},await F(p,m);}for(let g of m.batches){if(!g.invalidationId){let f=await M(`CloudFront targeted invalidation batch ${g.index+1}`,3e5,({httpOptions:I})=>d.send(new CreateInvalidationCommand({DistributionId:c,InvalidationBatch:{CallerReference:g.callerReference,Paths:{Quantity:g.paths.length,Items:g.paths}}}),I)),h=String(f.Invalidation?.Id||"").trim();if(!h)throw new Error("CloudFront did not return an invalidation ID.");g.invalidationId=h,g.status="created",await F(p,m);}await waitUntilInvalidationCompleted({client:d,maxWaitTime:900,minDelay:2,maxDelay:15},{DistributionId:c,Id:g.invalidationId}),g.status="completed",await F(p,m),s.info(`CloudFront invalidation batch ${g.index+1}/${m.batches.length} completed.`,{invalidationId:g.invalidationId,pathCount:g.paths.length});}s.endMark("invalidate"),await s.flush();}Z().catch(async r=>{console.error(r);try{let e=await D().catch(()=>null),t=new v(e?.logDir??"logs","invalidate.log.jsonl","debug");t.error(`Unhandled error: ${r instanceof Error?r.message:String(r)}`,r instanceof Error?{stack:r.stack}:void 0),await t.flush();}catch{}process.exit(1);});
@@ -1,3 +1,3 @@
1
- import {pathToFileURL}from'url';import P from'fs/promises';import {existsSync,createReadStream,createWriteStream}from'fs';import m from'path';import {spawn}from'child_process';import {randomUUID,createHash}from'crypto';import Je from'http';import me from'https';import {pipeline}from'stream/promises';import {createGzip}from'zlib';function le(e){return [...new Set(e.map(t=>t.trim()).filter(Boolean))].sort()}function N(e){return Array.isArray(e)?e.map(N):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,N(n)])):e}function Ee(e){return JSON.stringify(N(e))}function J(e){return createHash("sha256").update(Ee(e)).digest("hex")}function de(e){return J({schemaVersion:1,wordpressFingerprint:e.wordpressFingerprint,targetFingerprint:e.targetFingerprint,sourceOrigin:e.sourceOrigin,sitemapPaths:[...e.sitemapPaths].sort(),blockedPathPrefixes:[...e.blockedPathPrefixes].sort(),assetPathPrefixes:[...e.assetPathPrefixes].sort(),noJavaScriptRenderPathPrefixes:[...e.noJavaScriptRenderPathPrefixes].sort(),urlRewriteMode:e.urlRewriteMode})}function Fe(e){let t=new URL(e);if(t.protocol!=="http:"&&t.protocol!=="https:")throw new Error(`Unsupported source origin protocol: ${t.protocol}`);return t.hash="",t.search="",t.pathname=t.pathname.replace(/\/+$/,""),t.toString().replace(/\/$/,"")}function M(e){let t=le((e.postTypes??[]).map(r=>String(r).toLowerCase().replace(/[^a-z0-9_-]/g,"")));if(t.length===0)throw new Error("Content-sync requires at least one public post type.");let n=le((e.listingPaths??[]).map(r=>{let i=String(r).trim();if(!i)return "";let a=new URL(i,"https://content-sync.invalid/");if(a.origin!=="https://content-sync.invalid"&&/^https?:\/\//i.test(i))throw new Error("Content-sync listing routes must be same-site paths.");let s=`/${a.pathname.replace(/^\/+|\/+$/g,"")}`;return s==="/"?"/":`${s}/`}));return {postTypes:t,listingPaths:n,includeSubsites:e.includeSubsites===true,includePostTypeArchives:e.includePostTypeArchives!==false,includeTaxonomyArchives:e.includeTaxonomyArchives!==false,includeAuthorArchives:e.includeAuthorArchives===true,includeDateArchives:e.includeDateArchives===true,includePostsPage:e.includePostsPage!==false,includeSitemapChain:e.includeSitemapChain!==false}}function _(e,t,n){return J({schemaVersion:1,sourceOrigin:Fe(e),ruleId:t.trim(),scope:M(n)})}function K(e){return J({schemaVersion:1,...e})}function pe(e){return e.replace(/((?:x-static-publisher-token|authorization|proxy-authorization|x-api-key|aws-access-key-id|aws-secret-access-key|aws-session-token)\s*:\s*)[^\r\n]+/gi,"$1[REDACTED]").replace(/\b(Basic|Bearer)\s+[^\s]+/gi,"$1 [REDACTED]").replace(/([?&](?:token|access_token|refresh_token|api_key|key|nonce)=)[^&\s]+/gi,"$1[REDACTED]").replace(/((?:"|')?(?:runtimeToken|siteKey|nonce|accessToken|refreshToken|accessKeyId|secretAccessKey|sessionToken)(?:"|')?\s*[:=]\s*(?:"|'))[^"']+/gi,"$1[REDACTED]")}var ge=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";ge?m.join(ge,"current-progress.json"):"";Promise.resolve();var Oe="wp-json/smartcloud-static-publisher/v1/content-sync/",Le=25*1024*1024,k=class extends Error{status;code;constructor(t,n,r){super(r),this.name="ContentSyncApiError",this.status=t,this.code=n;}},U=class{options;constructor(t){if(!t.runtimeToken.trim())throw new Error("Content-sync requires a WordPress runtime token.");this.options={...t,timeoutMs:t.timeoutMs??6e4};}endpoint(t){let n=this.options.sourceOrigin.replace(/\/+$/,"")+"/";return new URL(`${Oe}${t}`,n)}async post(t,n){let r=this.endpoint(t),i=Buffer.from(JSON.stringify(n),"utf8"),a=r.protocol==="https:"?me:Je,s=r.protocol==="https:"?new me.Agent({rejectUnauthorized:!this.options.ignoreHttpsErrors}):void 0;return new Promise((o,u)=>{let c=a.request(r,{method:"POST",agent:s,headers:{"content-type":"application/json","content-length":String(i.byteLength),"x-static-publisher-token":this.options.runtimeToken},timeout:this.options.timeoutMs},d=>{let g=[],p=0;d.on("data",h=>{if(p+=h.byteLength,p>Le){d.destroy(new Error("Content-sync API response exceeded the size limit."));return}g.push(h);}),d.on("error",u),d.on("end",()=>{let h=Buffer.concat(g).toString("utf8"),y;try{y=h?JSON.parse(h):{};}catch{u(new k(d.statusCode??500,"invalid-json","Content-sync API returned invalid JSON."));return}let l=d.statusCode??500;if(l<200||l>=300){u(new k(l,String(y.code??"request-failed"),String(y.message??`Content-sync API request failed (${l}).`)));return}o(y);});});c.on("timeout",()=>c.destroy(new Error(`Content-sync API request timed out: ${t}`))),c.on("error",u),c.end(i);})}async head(t){return this.post("head",t)}async unboundHead(t,n){return this.post("head",{postTypes:t,includeSubsites:n})}async events(t){let n=[],r=t.afterSequence,i=new Set(t.postTypes);for(;r<t.throughSequence;){let a=await this.post("events",{...t,afterSequence:r,limit:250});if(a.fromSequence!==r||a.throughSequence!==t.throughSequence||a.nextSequence<r||a.nextSequence>t.throughSequence)throw new Error("Content-sync API returned an inconsistent event page.");if(!Array.isArray(a.items))throw new Error("Content-sync API returned a malformed event page.");let s=r;for(let o of a.items){if(!Number.isSafeInteger(o.sequence)||o.sequence<=s||o.sequence>t.throughSequence||!Number.isSafeInteger(o.postId)||o.postId<=0||!Number.isSafeInteger(o.blogId)||o.blogId<=0||!i.has(o.postType)||typeof o.operation!="string"||!o.operation)throw new Error("Content-sync API returned an invalid or out-of-scope journal event.");s=o.sequence;}if(a.items.length>0&&a.nextSequence!==s)throw new Error("Content-sync API event cursor does not match the final returned event.");if(n.push(...a.items),!a.hasMore)break;if(a.nextSequence===r)throw new Error("Content-sync API event pagination did not advance.");r=a.nextSequence;}if(t.throughSequence>t.afterSequence&&n.at(-1)?.sequence!==t.throughSequence)throw new Error("Content-sync API omitted the claimed journal high-water event.");return n}async resolveImpactFamilies(t,n){let r=await this.post("impact",{families:t,includeSubsites:n});return Array.isArray(r.families)?r.families:[]}async releaseFingerprint(t=false){let n=await this.post("fingerprint",{includeSubsites:t}),r=String(n.fingerprint||"").trim();if(!/^[a-f0-9]{64}$/.test(r))throw new Error("WordPress returned an invalid release fingerprint.");return r}async establishBaseline(t){return this.post("baseline",t)}async acknowledge(t){return this.post("ack",t)}};function Be(e){return typeof e.subscriptionType=="string"&&e.subscriptionType.trim()!==""}function Me(e,t){return {...e,...t??{}}}function Ue(e,t){return {...e,...t??{},invalidationPaths:[...(t?.invalidationPaths??e.invalidationPaths)||[]]}}function z(e,t){let n=String(t??e.deploymentTargetOverride??"").trim();if(!Be(e)){if(n)throw new Error(`Deployment target "${n}" requires an active WPSuite subscription and remote publisher config.`);return {name:null,profile:null,config:e}}let r=String(n||e.defaultDeploymentProfile||"").trim();if(!r)return {name:null,profile:null,config:e};let i=e.deploymentProfiles?.[r];if(!i)throw new Error(`Unknown deployment profile "${r}". Check the linked WPSuite publisher configuration.`);return {name:r,profile:i,config:{...e,targetOrigin:i.targetOrigin??e.targetOrigin,s3:Me(e.s3,i.s3),cloudFront:Ue(e.cloudFront,i.cloudFront)}}}function fe(e){let t=e.trim();return t==="."?".":t.replace(/\/$/,"")}function Ne(e){let t=String(e??"").trim();if(!t)return "";let n=t;if(/^https?:\/\//i.test(n))try{n=new URL(n).pathname;}catch{return ""}if(n=n.split(/[?#]/,1)[0]?.replace(/\\/g,"/").trim()??"",!n)return "";let r=n.endsWith("/"),i=n.replace(/^\/+/,"").split("/").map(s=>s.replace(/[^A-Za-z0-9._-]/g,"")).filter(s=>s.length>0&&s!=="."&&s!=="..");if(i.length===0)return "";let a=`/${i.join("/")}`;return r&&m.extname(a)===""&&(a+="/"),a==="/"?"":a}function H(e){return !e||typeof e!="object"?{}:Object.fromEntries(Object.entries(e).map(([t,n])=>[t.trim(),String(n??"")]).filter(([t])=>t.length>0))}function _e(e){if(!e||typeof e!="object")return {};let t={};for(let[n,r]of Object.entries(e)){let i=n.trim();if(!i||!r||typeof r!="object")continue;let a=r,s={};if(typeof a.targetOrigin=="string"){let u=fe(a.targetOrigin);u&&(s.targetOrigin=u);}let o=H(a.extraReplacements);if(Object.keys(o).length>0&&(s.extraReplacements=o),a.s3&&typeof a.s3=="object"){let u={},c=a.s3;typeof c.bucket=="string"&&(u.bucket=c.bucket.trim()),typeof c.prefix=="string"&&(u.prefix=c.prefix.trim()),typeof c.region=="string"&&(u.region=c.region.trim()),typeof c.htmlCacheControl=="string"&&(u.htmlCacheControl=c.htmlCacheControl.trim()),typeof c.assetCacheControl=="string"&&(u.assetCacheControl=c.assetCacheControl.trim()),Object.keys(u).length>0&&(s.s3=u);}if(a.cloudFront&&typeof a.cloudFront=="object"){let u={},c=a.cloudFront;typeof c.distributionId=="string"&&(u.distributionId=c.distributionId.trim()),Array.isArray(c.invalidationPaths)&&(u.invalidationPaths=c.invalidationPaths.map(d=>String(d??"").trim()).filter(d=>d.length>0)),Object.keys(u).length>0&&(s.cloudFront=u);}t[i]=s;}return t}function V(e){return e==="PROFESSIONAL"||e==="AGENCY"?e:void 0}function Ke(e,t){if(!e||typeof e!="object")return null;let n=e,r=n.command;if(r!=="publish"&&r!=="crawl"&&r!=="deploy"&&r!=="invalidate"&&r!=="retry-timeouts"&&r!=="url"&&r!=="content-sync")return null;let i=Number.parseInt(String(n.intervalMinutes??"0"),10);if(!Number.isFinite(i)||i<1)return null;let a=String(n.id??`${r}-${t+1}`).trim();if(!a)return null;let s=String(n.deploymentProfile??"").trim(),o=String(n.url??"").trim(),u=Array.isArray(n.postTypes)?[...new Set(n.postTypes.map(d=>String(d??"").trim().toLowerCase().replace(/[^a-z0-9_-]/g,"")).filter(Boolean))]:[],c=Array.isArray(n.listingPaths)?[...new Set(n.listingPaths.map(d=>String(d??"").trim()).filter(Boolean))]:[];return r==="content-sync"&&u.length===0?null:{id:a,enabled:n.enabled!==false,command:r,intervalMinutes:i,...r==="publish"||r==="crawl"?{crawlMode:n.crawlMode==="incremental"?"incremental":"full"}:{},...(r==="publish"||r==="deploy"||r==="invalidate"||r==="content-sync")&&s?{deploymentProfile:s}:{},...o?{url:o}:{},...u.length>0?{postTypes:u}:{},...c.length>0?{listingPaths:c}:{},...typeof n.includeSubsites=="boolean"?{includeSubsites:n.includeSubsites}:{},...typeof n.includePostTypeArchives=="boolean"?{includePostTypeArchives:n.includePostTypeArchives}:{},...typeof n.includeTaxonomyArchives=="boolean"?{includeTaxonomyArchives:n.includeTaxonomyArchives}:{},...typeof n.includeAuthorArchives=="boolean"?{includeAuthorArchives:n.includeAuthorArchives}:{},...typeof n.includeDateArchives=="boolean"?{includeDateArchives:n.includeDateArchives}:{},...typeof n.includePostsPage=="boolean"?{includePostsPage:n.includePostsPage}:{},...typeof n.includeSitemapChain=="boolean"?{includeSitemapChain:n.includeSitemapChain}:{}}}function ye(e){let t=e&&typeof e=="object"?e:{},n=Array.isArray(t.rules)?t.rules.map((r,i)=>Ke(r,i)).filter(r=>!!r):[];return {enabled:t.enabled===true,timezone:typeof t.timezone=="string"&&t.timezone.trim()!==""?t.timezone.trim():"UTC",rules:n}}function ze(e){if(!e||typeof e!="object")return;let t=e,n={};for(let i of ["accountId","siteId"]){let a=t[i];typeof a=="string"&&a.trim()!==""&&(n[i]=a.trim());}let r=Number(t.lastUpdate??0);return Number.isFinite(r)&&r>0&&(n.lastUpdate=Math.floor(r)),t.subscriber===true&&(n.subscriber=true),Object.keys(n).length>0?n:void 0}function Y(e){let t=e&&typeof e=="object"?e:{},n=String(t.accountId??"").trim(),r=String(t.siteId??"").trim(),i=t.subscriber===true,a=ze(t.siteSettings),s={...a??{},...n?{accountId:a?.accountId??n}:{},...r?{siteId:a?.siteId??r}:{},...a?.subscriber===true||i?{subscriber:true}:{}},o={},u=String(t.apiBase??"").trim();u&&(o.apiBase=u);let c=String(t.runtimeToken??t.nonce??"").trim();c&&(o.runtimeToken=c);let d=String(t.virtualAssetBaseUrl??t.uploadUrl??"").trim();d&&(o.virtualAssetBaseUrl=d),Object.keys(s).length>0&&(o.siteSettings=s);let g=V(t.subscriptionType);return g&&(o.subscriptionType=g),o}function He(e){try{let t=new URL(e);globalThis.location=t;}catch{}}function be(e){return typeof e=="string"?e:e instanceof URL?e.toString():e.url}function Ge(e,t){let n=new Headers(e instanceof Request?e.headers:void 0);if(t?.headers)for(let[r,i]of new Headers(t.headers).entries())n.set(r,i);return n}async function Se(e,t,n=5){let r=new URL(be(e)),i=String(t?.method??(e instanceof Request?e.method:"GET")).toUpperCase(),a=r.protocol==="http:"?Je:me,s=Ge(e,t);return await new Promise((o,u)=>{let c=a.request(r,{method:i,headers:Object.fromEntries(s.entries()),...r.protocol==="https:"?{rejectUnauthorized:false}:{}},d=>{let g=[];d.on("data",p=>{g.push(Buffer.isBuffer(p)?p:Buffer.from(p));}),d.on("error",u),d.on("end",()=>{let p=d.statusCode??0,h=d.headers.location;if(n>0&&h&&[301,302,303,307,308].includes(p)){o(Se(new URL(h,r),{method:p===303?"GET":i},n-1));return}let y=new Headers;for(let[l,b]of Object.entries(d.headers))Array.isArray(b)?y.set(l,b.join(", ")):typeof b=="string"&&y.set(l,b);o(new Response(Buffer.concat(g),{status:p,statusText:d.statusMessage??"",headers:y}));});});c.on("error",u),c.end();})}function Ve(e){let t=Y(e.wpsuite),n={...t.siteSettings??{},...t.siteSettings?.subscriber===true||t.subscriptionType==="PROFESSIONAL"||t.subscriptionType==="AGENCY"?{subscriber:true}:{}},r=String(n.accountId??"").trim(),i=String(n.siteId??"").trim(),a=String(t.virtualAssetBaseUrl??t.uploadUrl??"").trim();if(e.wpsuite={...t.apiBase?{apiBase:t.apiBase}:{},...t.runtimeToken?{runtimeToken:t.runtimeToken}:{},...a?{virtualAssetBaseUrl:a}:{},...Object.keys(n).length>0?{siteSettings:n}:{},...t.subscriptionType?{subscriptionType:t.subscriptionType}:{}},!r||!i||!a)return false;He(e.sourceOrigin);let s=globalThis,u={...s.WpSuite??{},siteSettings:n,uploadUrl:a};return t.apiBase&&(u.apiBase=t.apiBase),s.WpSuite=u,true}async function Ye(e){let t=String(e.wpsuite?.virtualAssetBaseUrl??e.wpsuite?.uploadUrl??"").trim();if(!Ve(e)){let i=e.wpsuite?.siteSettings,a=[String(i?.accountId??"").trim()?"":"accountId",String(i?.siteId??"").trim()?"":"siteId",t?"":"virtualAssetBaseUrl"].filter(Boolean);return {remote:null,diagnostic:{status:"invalid-runtime",virtualAssetBaseUrl:t,subscriptionType:null,error:`Missing WP Suite runtime field(s): ${a.join(", ")}.`,requests:[]}}}let n=globalThis.fetch,r=[];try{typeof n=="function"&&/^https?:\/\//i.test(t)&&(globalThis.fetch=(async(u,c)=>{let d=be(u);if(d.startsWith(t)){let g=(()=>{try{return new URL(d).pathname}catch{return d}})();try{let p=e.ignoreHttpsErrors&&d.startsWith("https://")?await Se(u,c):await n(u,c);return r.push({path:g,status:p.status,ok:p.ok,error:null}),p}catch(p){throw r.push({path:g,status:null,ok:!1,error:p instanceof Error?p.message:String(p)}),p}}return n(u,c)}));let{getConfig:i}=await import('@smart-cloud/wpsuite-core'),a=await i("publisher"),s=a&&typeof a=="object"?a:null,o=V(s?.subscriptionType);return {remote:s,diagnostic:{status:s?"loaded":"unavailable",virtualAssetBaseUrl:t,subscriptionType:o??null,error:s?null:"WP Suite publisher config loader returned no configuration.",requests:r}}}catch(i){return {remote:null,diagnostic:{status:"unavailable",virtualAssetBaseUrl:t,subscriptionType:null,error:i instanceof Error?i.message:String(i),requests:r}}}finally{typeof n=="function"&&(globalThis.fetch=n);}}function Ze(e,t){let n=_e(t?.deploymentProfiles),r=String(t?.defaultDeploymentProfile??"").trim(),i=n[r]?r:"",a=V(t?.subscriptionType),s=Y(e.wpsuite);return {...e,scheduler:ye(t?.scheduler),deploymentProfiles:n,defaultDeploymentProfile:i,...a?{subscriptionType:a}:{},wpsuite:{...s,...s.siteSettings||a?{siteSettings:{...s.siteSettings??{},...s.siteSettings?.subscriber===true||a==="PROFESSIONAL"||a==="AGENCY"?{subscriber:true}:{}}}:{},...a?{subscriptionType:a}:{}}}}function G(e,t){let r=String(e||"").replace(/\\/g,"/").trim().replace(/^\/+|\/+$/g,"");if(!r)return t;let i=r.split("/").map(a=>a.trim()).filter(a=>a.length>0&&a!=="."&&a!=="..");return i.length>0?i.join("/"):t}function Xe(){let e=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";return e.trim()?m.resolve(e):""}function he(e,t,n){let r=String(t||"").trim();return r&&m.isAbsolute(r)?m.resolve(r):m.resolve(e,G(r,n))}async function Z(e,t={}){let n=String(e??"").trim()||process.env.PUBLISHER_CONFIG||"publisher.config.json",r=await P.readFile(n,"utf8"),i=JSON.parse(r);i.sourceOrigin=i.sourceOrigin.replace(/\/$/,""),i.targetOrigin=fe(i.targetOrigin),i.ignoreHttpsErrors??=false,i.outputDir=String(i.outputDir||"export").trim()||"export",i.urlRewriteMode||=i.targetOrigin==="."?"relative":"absolute",i.noJavaScriptRenderPathPrefixes||=[],i.seedPaths||=[],i.generated404RequestPath=Ne(i.generated404RequestPath),i.sitemapPaths||=["/sitemap_index.xml","/sitemap.xml"],i.allowedAssetHosts||=[],i.assetPathPrefixes||=["/wp-content/","/wp-includes/","/static/","/assets/","/build/","/_next/","/docs/","/sitemap","/robots.txt","/llms.txt"],i.blockedPathPrefixes||=[],i.blockedSearchFragments||=[],i.concurrency||=1,i.maxPages||=0,i.extraReplacements=H(i.extraReplacements),i.postCrawlCopyMap=H(i.postCrawlCopyMap),i.logDir=String(i.logDir||"logs").trim()||"logs",i.verbose??=false,i.logLevel||=i.verbose?"debug":"info",i.s3SyncMode||="sdk-upload-delete",i.readiness||={waitForSelector:null,waitForFunction:null,timeoutMs:1500,fallbackWaitMs:1500},i.readiness.timeoutMs??=1500,i.readiness.fallbackWaitMs??=1500,i.viewport||={width:1440,height:1200},i.navigationTimeoutMs||=3e4,i.assetDownloadConcurrency=Number(i.assetDownloadConcurrency)>0?Number(i.assetDownloadConcurrency):i.concurrency,i.rewriteConcurrency=Number(i.rewriteConcurrency)>0?Number(i.rewriteConcurrency):i.assetDownloadConcurrency,i.wpsuite=Y(i.wpsuite),i.scheduler=ye(void 0),i.deploymentProfiles={},i.defaultDeploymentProfile="",i.deploymentTargetOverride=String(i.deploymentTargetOverride??"").trim();let a=await Ye(i);t.onRemotePublisherConfigDiagnostic?.(a.diagnostic);let s=Ze(i,a.remote),o=Xe(),u=o?m.resolve(o,".."):"";return u?(s.outputDir=he(u,s.outputDir,"export"),s.logDir=he(u,s.logDir,"logs")):(m.isAbsolute(s.outputDir)||(s.outputDir=G(s.outputDir,"export")),m.isAbsolute(s.logDir)||(s.logDir=G(s.logDir,"logs"))),s}function Ce(e){let t=String(e.command??"").trim();return (t==="publish"||t==="crawl")&&e.crawlMode==="incremental"||t==="content-sync"}var X=new Map;async function we(e){let t=m.resolve(e),n=X.get(t);if(n!==void 0)return n;try{let r=JSON.parse(await P.readFile(t,"utf8")),i=String(r.version??"").trim();return X.set(t,i),i}catch{return X.set(t,""),""}}var B=class extends Error{request;step;constructor(t,n){super(`Stop requested during ${n}.`),this.name="StopRequestedError",this.request=t,this.step=n;}},st="queue-mutation.lock",ot=5e3,at=3e4;function ut(e){let t=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"",n=process.env.STATIC_PUBLISHER_EXPORTER_DIR||process.cwd(),r=process.env.PUBLISHER_CONFIG||"",i=1;for(let o=0;o<e.length;o++){let u=e[o];u==="--runtime-dir"?t=e[++o]||"":u.startsWith("--runtime-dir=")?t=u.slice(14):u==="--exporter-dir"?n=e[++o]||n:u.startsWith("--exporter-dir=")?n=u.slice(15):u==="--config"?r=e[++o]||"":u.startsWith("--config=")?r=u.slice(9):u==="--max-jobs"?i=Number.parseInt(e[++o]||"1",10):u.startsWith("--max-jobs=")&&(i=Number.parseInt(u.slice(11),10));}if(!t)throw new Error("Missing runtime dir. Use --runtime-dir or STATIC_PUBLISHER_RUNTIME_DIR.");let a=m.resolve(t),s=r?m.resolve(r):m.join(a,"config.json");return {runtimeDir:a,exporterDir:m.resolve(n),configPath:s,maxJobs:Number.isFinite(i)&&i>0?i:1}}async function v(e,t){try{let n=await P.readFile(e,"utf8");return JSON.parse(n)}catch(n){if((n&&typeof n=="object"&&"code"in n?String(n.code||""):"")!=="ENOENT"){let i=n instanceof Error?n.message:String(n);console.warn(`[queue-runner] failed to read JSON ${e}: ${i}`);}return t}}async function w(e,t){await P.mkdir(m.dirname(e),{recursive:true}),await P.writeFile(e,JSON.stringify(t,null,2),"utf8");}function Ae(e){return m.join(e,st)}async function ct(e){await new Promise(t=>setTimeout(t,e));}async function lt(e){let t=Ae(e),n=Date.now()+ot;for(;;)try{await P.mkdir(m.dirname(t),{recursive:!0}),await P.writeFile(t,JSON.stringify({pid:process.pid,createdAt:new Date().toISOString()},null,2),{encoding:"utf8",flag:"wx"});return}catch(r){if((r&&typeof r=="object"&&"code"in r?String(r.code||""):"")!=="EEXIST")throw r;let a=await P.stat(t).catch(()=>null);if(a&&Date.now()-a.mtimeMs>at){await P.unlink(t).catch(()=>{});continue}if(Date.now()>=n)throw new Error("Timed out acquiring queue mutation lock.",{cause:r});await ct(50);}}async function dt(e){await P.unlink(Ae(e)).catch(()=>{});}async function E(e,t){await lt(e);try{return await t()}finally{await dt(e);}}function Ie(e){return m.join(e,"queue-runner-heartbeat.json")}function ae(e){return m.join(e,"current-progress.json")}function ee(e){return m.join(e,"scheduler-state.json")}function gt(e,t){let r=String(e||"").replace(/\\/g,"/").trim().replace(/^\/+|\/+$/g,"");if(!r)return t;let i=r.split("/").map(a=>a.trim()).filter(a=>a.length>0&&a!=="."&&a!=="..");return i.length>0?i.join("/"):t}async function Re(e){let t=await v(e.configPath||"",null),n=m.resolve(e.runtimeDir,".."),i=(typeof t?.logDir=="string"?t.logDir:"").trim();return i&&m.isAbsolute(i)?m.resolve(i):m.resolve(n,gt(i,"logs"))}function te(e,t){return String(e||"").trim().replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||t}function pt(e){let t=e?new Date(e):new Date;return (Number.isNaN(t.getTime())?new Date:t).toISOString().replace(/[-:]/g,"").replace(/\.\d{3}Z$/,"Z")}function mt(e){return [pt(e.endedAt||e.startedAt),te(e.command||"job","job"),te(e.id||"job","job"),te(e.status||"finished","finished")].join("-")}function ht(e){return e.endsWith(".log.jsonl")||e.endsWith(".errors.jsonl")||e.endsWith(".rejected.jsonl")?true:["current-crawl-event.json","rejected.jsonl","ignored.jsonl","skipped-http.jsonl","errors.jsonl","timings.jsonl","rejected.json","ignored.json","skipped-http.json","errors.json","timings.json"].includes(e)}function ft(e){return e==="errors.json"||e==="errors.jsonl"||e.endsWith(".errors.jsonl")?"errors":e==="ignored.json"||e==="ignored.jsonl"?"ignored":e==="rejected.json"||e==="rejected.jsonl"||e.endsWith(".rejected.jsonl")?"rejected":e==="skipped-http.json"||e==="skipped-http.jsonl"?"skipped-http":e==="timings.json"||e==="timings.jsonl"?"timings":e==="current-progress.json"?"current-progress":e==="current-crawl-event.json"?"current-crawl-event":e.endsWith(".log.jsonl")?e.replace(/\.log\.jsonl$/i,"-log"):e.replace(/\.[^.]+$/u,"")||"artifact"}function yt(e){return e.endsWith(".gz")?"application/gzip":e.endsWith(".jsonl")?"application/x-ndjson":e.endsWith(".json")?"application/json":"text/plain"}async function ne(e,t,n){let r=`${n}.gz`,i=m.join(t,r);await pipeline(createReadStream(e),createGzip({level:9}),createWriteStream(i));let[a,s]=await Promise.all([P.stat(e),P.stat(i)]);return {role:ft(n),originalFileName:n,storedFileName:r,compressed:true,compression:"gzip",contentType:yt(r),originalSize:a.size,storedSize:s.size}}async function $(e,t){let n=await Re(t),r=new Date().toISOString(),i=mt(e),a=m.join(n,"archive",i),s=[],o=[];await P.mkdir(a,{recursive:true});try{let d=await P.readdir(n,{withFileTypes:!0});for(let g of d){if(!g.isFile()||!ht(g.name))continue;let p=await ne(m.join(n,g.name),a,g.name);o.push(p),s.push(p.storedFileName);}}catch(d){if((d&&typeof d=="object"&&"code"in d?String(d.code||""):"")!=="ENOENT")throw d}let u=ae(t.runtimeDir);if(existsSync(u)){let d=await ne(u,a,"current-progress.json");o.push(d),s.push(d.storedFileName);}if(e.command==="content-sync")for(let d of ["content-sync-current.json","content-sync-impact-plan.json","content-sync-checkpoint.json","content-sync-state.json","content-sync-invalidation.json","deploy-plan.json"]){let g=m.join(t.runtimeDir,d);if(!existsSync(g))continue;let p=await ne(g,a,d);o.push(p),s.push(p.storedFileName);}let c=[...s,"job.json"];return await w(m.join(a,"job.json"),{manifestVersion:1,archivedAt:r,archiveKey:i,archiveDir:a,logDir:n,runtimeDir:t.runtimeDir,exporterDir:t.exporterDir,configPath:t.configPath||"",archivedFiles:c,artifacts:o,job:e}),{archiveKey:i,archiveDir:a,archiveCreatedAt:r,archivedFiles:c,artifacts:o}}function bt(e){return m.join(e,"audit-events.jsonl")}function se(e){return m.join(e,"stop-request.json")}async function qe(e){try{let t=await P.readFile(se(e),"utf8"),n=JSON.parse(t);return n&&typeof n=="object"?n:null}catch{return null}}async function ve(e,t){let n=await qe(e);if(!n)return null;let r=String(n.targetJobId||"").trim();return r&&r!==t?null:n}async function O(e,t){if(!t){await P.unlink(se(e)).catch(()=>{});return}let n=await qe(e);if(!n)return;let r=String(n.targetJobId||"").trim();(!r||r===t)&&await P.unlink(se(e)).catch(()=>{});}async function I(e,t){try{let n={occurredAt:t.occurredAt||new Date().toISOString(),status:t.status||"info",actorSource:t.actorSource||"queue-runner",...t};await P.mkdir(e,{recursive:!0}),await P.appendFile(bt(e),`${JSON.stringify(n)}
2
- `,"utf8");}catch{}}async function C(e,t,n){let[r,i]=await Promise.all([we(m.join(e.exporterDir,"package.json")),we(m.join(e.exporterDir,"node_modules","@smart-cloud","wpsuite-core","package.json"))]),a={checkedAt:new Date().toISOString(),status:t,pid:process.pid,nodePath:process.execPath,nodeVersion:process.version,exporterVersion:r,wpsuiteCoreVersion:i,runtimeDir:e.runtimeDir,exporterDir:e.exporterDir,...n??{}};try{await w(Ie(e.runtimeDir),a);}catch{}}async function L(e){try{await P.unlink(ae(e));}catch{}}function St(e,t){let n=e.command;if(n!=="publish"&&n!=="crawl"&&n!=="deploy"&&n!=="invalidate"&&n!=="retry-timeouts"&&n!=="url"&&n!=="content-sync")return null;let r=Number.parseInt(String(e.intervalMinutes??"0"),10);if(!Number.isFinite(r)||r<1)return null;let i=(e.id||`${n}-${t+1}`).trim();if(!i)return null;let a=e.enabled!==false,s=typeof e.url=="string"?e.url.trim():"",o=typeof e.deploymentProfile=="string"?e.deploymentProfile.trim():"",u=Array.isArray(e.postTypes)?[...new Set(e.postTypes.map(g=>String(g).trim()).filter(Boolean))]:[],c=Array.isArray(e.listingPaths)?[...new Set(e.listingPaths.map(g=>String(g).trim()).filter(Boolean))]:[],d=(n==="publish"||n==="crawl")&&e.crawlMode==="incremental"?"incremental":"full";return n==="url"&&!s||n==="content-sync"&&u.length===0?null:{id:i,enabled:a,command:n,intervalMinutes:r,...n==="publish"||n==="crawl"?{crawlMode:d}:{},...(n==="publish"||n==="deploy"||n==="invalidate"||n==="content-sync")&&o?{deploymentProfile:o}:{},...s?{url:s}:{},...u.length>0?{postTypes:u}:{},...c.length>0?{listingPaths:c}:{},...typeof e.includeSubsites=="boolean"?{includeSubsites:e.includeSubsites}:{},...typeof e.includePostTypeArchives=="boolean"?{includePostTypeArchives:e.includePostTypeArchives}:{},...typeof e.includeTaxonomyArchives=="boolean"?{includeTaxonomyArchives:e.includeTaxonomyArchives}:{},...typeof e.includeAuthorArchives=="boolean"?{includeAuthorArchives:e.includeAuthorArchives}:{},...typeof e.includeDateArchives=="boolean"?{includeDateArchives:e.includeDateArchives}:{},...typeof e.includePostsPage=="boolean"?{includePostsPage:e.includePostsPage}:{},...typeof e.includeSitemapChain=="boolean"?{includeSitemapChain:e.includeSitemapChain}:{}}}async function wt(e){let t=await Z(e.configPath).catch(()=>null),n=t?.scheduler,r=Array.isArray(n?.rules)?n.rules.map((i,a)=>St(i,a)).filter(i=>!!i):[];return {enabled:!!n?.enabled,timezone:typeof n?.timezone=="string"&&n.timezone.trim()?n.timezone.trim():"UTC",rules:r,wpsuite:t?.wpsuite,publisherConfig:t}}function re(e,t){if(!t)throw new Error("Content-sync scheduler requires a valid publisher config.");let n=M({postTypes:e.postTypes??[],listingPaths:e.listingPaths??[],includeSubsites:e.includeSubsites,includePostTypeArchives:e.includePostTypeArchives,includeTaxonomyArchives:e.includeTaxonomyArchives,includeAuthorArchives:e.includeAuthorArchives,includeDateArchives:e.includeDateArchives,includePostsPage:e.includePostsPage,includeSitemapChain:e.includeSitemapChain}),r=_(t.sourceOrigin,e.id,n),i=z(t,e.deploymentProfile),a=K({sourceOrigin:t.sourceOrigin,targetOrigin:i.config.targetOrigin,deploymentProfile:i.name||"",s3Bucket:i.config.s3.bucket,s3Prefix:i.config.s3.prefix,cloudFrontDistributionId:i.config.cloudFront.distributionId,urlRewriteMode:i.config.urlRewriteMode,extraReplacements:i.profile?.extraReplacements??{}});return `content-sync:${e.id}:${J({scopeFingerprint:r,targetFingerprint:a}).slice(0,32)}`}async function vt(e,t,n,r,i){let s=(await v(m.join(e.runtimeDir,"content-sync-baseline.json"),{})).entries?.[r];if(!s?.consumerId||!s.scopeFingerprint||!s.baselineId)return {status:"baseline-required",reason:"No verified normal-release baseline exists for this rule scope."};try{let o=t.publisherConfig;if(!o)throw new Error("Publisher configuration is unavailable.");let u=M({postTypes:n.postTypes??[],listingPaths:n.listingPaths??[],includeSubsites:n.includeSubsites,includePostTypeArchives:n.includePostTypeArchives,includeTaxonomyArchives:n.includeTaxonomyArchives,includeAuthorArchives:n.includeAuthorArchives,includeDateArchives:n.includeDateArchives,includePostsPage:n.includePostsPage,includeSitemapChain:n.includeSitemapChain}),c=_(o.sourceOrigin,n.id,u),d=z(o,n.deploymentProfile),g=K({sourceOrigin:o.sourceOrigin,targetOrigin:d.config.targetOrigin,deploymentProfile:d.name||"",s3Bucket:d.config.s3.bucket,s3Prefix:d.config.s3.prefix,cloudFrontDistributionId:d.config.cloudFront.distributionId,urlRewriteMode:d.config.urlRewriteMode,extraReplacements:d.profile?.extraReplacements??{}});if(s.scopeFingerprint!==c||s.targetFingerprint!==g||!s.releaseFingerprint)return {status:"baseline-required",reason:"The verified content-sync baseline does not match the active scope or deployment target. Run a successful full or incremental publish to establish a new baseline."};let p=new U({sourceOrigin:o.sourceOrigin,runtimeToken:String(o.wpsuite?.runtimeToken||""),ignoreHttpsErrors:o.ignoreHttpsErrors}),h=await p.releaseFingerprint(u.includeSubsites),y=de({wordpressFingerprint:h,targetFingerprint:g,sourceOrigin:o.sourceOrigin,sitemapPaths:o.sitemapPaths,blockedPathPrefixes:o.blockedPathPrefixes,assetPathPrefixes:o.assetPathPrefixes,noJavaScriptRenderPathPrefixes:o.noJavaScriptRenderPathPrefixes,urlRewriteMode:o.urlRewriteMode});if(s.releaseFingerprint!==y)return {status:"baseline-required",reason:"The installed WordPress release changed after the last verified content-sync baseline. Run a successful full or incremental publish to establish a new baseline."};let l=await p.head({consumerId:s.consumerId,scopeFingerprint:s.scopeFingerprint,baselineId:s.baselineId,postTypes:u.postTypes,includeSubsites:u.includeSubsites}),b=l.committedSequence;if(i?.command==="content-sync"&&i.coalesceKey===r){let S=await v(m.join(e.runtimeDir,"content-sync-current.json"),null);S?.coalesceKey===r&&Number.isSafeInteger(S.toSequence)&&(b=Math.max(b,Number(S.toSequence)));}return {status:l.headSequence>b?"pending":"current",headSequence:l.headSequence,committedSequence:l.committedSequence}}catch(o){return o instanceof k&&o.code==="baseline-required"?{status:"baseline-required",reason:o.message}:{status:"unavailable",reason:o instanceof Error?o.message:String(o)}}}async function De(e,t,n,r,i,a){let s=m.join(e.runtimeDir,"content-sync-state.json"),u=(await v(s,{})).rules??{},c=u[n]??{};u[n]={...c,ruleId:t,coalesceKey:n,...Number.isSafeInteger(i)?{observedHeadSequence:i}:{},...Number.isSafeInteger(a)?{committedSequence:a}:{},retryAttempt:0,nextRetryAt:null,lastError:r,baselineStatus:"required",baselineReason:r,trailingWorkDetected:Number.isSafeInteger(i)&&Number.isSafeInteger(a)?Number(i)>Number(a):!!c.trailingWorkDetected},await w(s,{schemaVersion:1,updatedAt:new Date().toISOString(),rules:u});}function oe(e,t){let n=(t.url||"").trim(),r=t.crawlMode||"full",i=(t.deploymentProfile||"").trim(),a=(t.coalesceKey||"").trim();return e.some(s=>s.command===t.command&&(t.command!=="content-sync"||(s.coalesceKey||"").trim()===a)&&(s.url||"").trim()===n&&(s.crawlMode||"full")===r&&(s.deploymentProfile||"").trim()===i&&(s.status===void 0||s.status==="queued"||s.status==="retry-wait"||s.status==="running"))}async function Pt(e,t,n){if(!t.allowSchedulerAutoEnqueue)return 0;let r=await wt(e);if(!r.enabled||r.rules.length===0)return 0;if(t.assertActiveSubscriptionForIdentity)try{await t.assertActiveSubscriptionForIdentity(r.wpsuite??null);}catch(l){let b=l instanceof Error?l.message:String(l);return console.warn(`[queue-runner] scheduler auto-enqueue skipped: ${b}`),0}let i=m.join(e.runtimeDir,"queue.json"),a=m.join(e.runtimeDir,"current-run.json"),s=Date.now(),o=0,u=[],c=[],d=[],g=new Map,[p,h,y]=await Promise.all([v(i,[]),v(a,null),v(ee(e.runtimeDir),{lastEnqueuedBucketByRuleId:{},lastEvaluatedBucketByRuleId:{},lastCreatedBucketByRuleId:{},coalescedCountByRuleId:{}})]);for(let l of r.rules){if(!l.enabled||l.command!=="content-sync")continue;let b=Math.floor(s/(l.intervalMinutes*60*1e3)),S=y.lastEvaluatedBucketByRuleId?.[l.id]??y.lastEnqueuedBucketByRuleId?.[l.id]??-1;if(b<=S)continue;let D=re(l,r.publisherConfig);oe(p,{command:l.command,deploymentProfile:l.deploymentProfile,coalesceKey:D})||g.set(l.id,await vt(e,r,l,D,h));}await E(e.runtimeDir,async()=>{let l=await v(i,[]),b=await v(a,null),S=await v(ee(e.runtimeDir),{lastEnqueuedBucketByRuleId:{},lastEvaluatedBucketByRuleId:{},lastCreatedBucketByRuleId:{},coalescedCountByRuleId:{}});S.lastEnqueuedBucketByRuleId??={},S.lastEvaluatedBucketByRuleId??={...S.lastEnqueuedBucketByRuleId},S.lastCreatedBucketByRuleId??={...S.lastEnqueuedBucketByRuleId},S.coalescedCountByRuleId??={};let D=[...l];b&&b.status==="running"&&D.unshift(b);for(let f of r.rules){if(!f.enabled)continue;let A=f.intervalMinutes*60*1e3,q=Math.floor(s/A),F=S.lastEvaluatedBucketByRuleId[f.id]??S.lastEnqueuedBucketByRuleId[f.id]??-1;if(q<=F)continue;let j=f.command==="content-sync"?re(f,r.publisherConfig):"";S.lastEvaluatedBucketByRuleId[f.id]=q;let T=f.command==="content-sync"?l:D;if(oe(T,{command:f.command,url:f.url,crawlMode:f.crawlMode,deploymentProfile:f.deploymentProfile,coalesceKey:j})){S.coalescedCountByRuleId[f.id]=(S.coalescedCountByRuleId[f.id]??0)+1,c.push(f);continue}if(f.command==="content-sync"){let W=g.get(f.id);if(!W||W.status!=="pending"){let ce=W??{status:"unavailable",reason:"Content-sync demand was not checked."};ce.status!=="current"&&d.push({rule:f,check:ce});continue}}let Q={id:randomUUID(),command:f.command,...f.command==="content-sync"?{ruleId:f.id,coalesceKey:j,attempt:0}:{},...(f.command==="publish"||f.command==="crawl")&&f.crawlMode?{crawlMode:f.crawlMode}:{},...(f.command==="publish"||f.command==="deploy"||f.command==="invalidate"||f.command==="content-sync")&&f.deploymentProfile?{deploymentProfile:f.deploymentProfile}:{},...f.url?{url:f.url}:{},enqueueSource:"scheduler",...r.wpsuite?{wpsuite:r.wpsuite}:{},status:"queued",createdAt:new Date().toISOString(),createdBy:0};l.push(Q),D.push(Q),u.push({job:Q,rule:f}),S.lastEnqueuedBucketByRuleId[f.id]=q,S.lastCreatedBucketByRuleId[f.id]=q,o+=1;}o>0&&await w(i,l),await w(ee(e.runtimeDir),S);});for(let l of u){if(l.rule.command==="content-sync"){let b=g.get(l.rule.id);await I(e.runtimeDir,{eventType:"content-sync-demand-detected",status:"queued",actorSource:"queue-runner-scheduler",jobId:l.job.id,command:l.job.command,message:"Pending journal changes require a content-sync job.",details:{ruleId:l.rule.id,headSequence:b?.headSequence??0,committedSequence:b?.committedSequence??0}});}await I(e.runtimeDir,{eventType:"job-created",status:"queued",actorSource:"queue-runner-scheduler",jobId:l.job.id,command:l.job.command,message:"Scheduler auto-enqueued a job.",details:{ruleId:l.rule.id,intervalMinutes:l.rule.intervalMinutes,timezone:r.timezone,deploymentProfile:l.rule.deploymentProfile||"",url:l.rule.url||""}});}for(let l of c)await I(e.runtimeDir,{eventType:"content-sync-coalesced",status:"queued",actorSource:"queue-runner-scheduler",command:l.command,message:"Scheduler demand was coalesced into an existing content-sync job.",details:{ruleId:l.id}});for(let l of d){if(l.check.status==="baseline-required"){let b=re(l.rule,r.publisherConfig);await De(e,l.rule.id,b,l.check.reason||"A successful full or incremental publish must establish a new content-sync baseline.",l.check.headSequence,l.check.committedSequence);}await I(e.runtimeDir,{eventType:l.check.status==="baseline-required"?"content-sync-baseline-required":"content-sync-demand-check-failed",status:l.check.status==="unavailable"?"failed":"info",actorSource:"queue-runner-scheduler",command:"content-sync",message:l.check.reason||"The content-sync consumer is already at the current journal head.",details:{ruleId:l.rule.id,headSequence:l.check.headSequence??0,committedSequence:l.check.committedSequence??0}});}return o}async function Ct(e){let t={pid:process.pid,startedAt:new Date().toISOString()};await P.writeFile(e,JSON.stringify(t,null,2),{encoding:"utf8",flag:"wx"});}async function At(e){try{await P.unlink(e);}catch{}}function It(e,t){let n=[m.join(e,"dist",`${t}.js`),m.join(e,`${t}.js`)];for(let r of n)if(existsSync(r))return r;throw new Error(`Cannot find ${t}.js in ${m.join(e,"dist")} or ${e}`)}async function R(e,t,n,r,i,a,s){if(s){let c=await ve(t,s);if(c)throw new B(c,n)}let o=It(e,n),u={...process.env,...a??{}};return u.STATIC_PUBLISHER_RUNTIME_DIR=t,i&&(u.PUBLISHER_CONFIG=i),await new Promise((c,d)=>{let g=null,p=null,h=null,y=null,l=false,b="",S=spawn(process.execPath,[o,...r],{cwd:e,env:u,stdio:["inherit","inherit","pipe"]});S.stderr?.on("data",A=>{b+=A.toString("utf8");});let D=()=>{p&&clearInterval(p),h&&clearInterval(h),y&&clearTimeout(y);},f=async()=>{if(!(!s||g||l)){l=true;try{let A=await ve(t,s);if(!A)return;g=A,S.kill("SIGTERM"),y=setTimeout(()=>{S.kill("SIGKILL");},1e4);}finally{l=false;}}};s&&(p=setInterval(()=>{f();},1e3),h=setInterval(()=>{(async()=>{let A=Ie(t),q=await v(A,{});await w(A,{...q,checkedAt:new Date().toISOString(),status:"running",currentJobId:s||q.currentJobId||"",currentStep:n});})().catch(()=>{});},15e3)),S.on("error",A=>{D(),d(A);}),S.on("close",(A,q)=>{D();let F=pe(b).trim();if(F&&process.stderr.write(`${F}
3
- `),g){d(new B(g,n));return}if(A===0)c();else {let j=F.split(/\r?\n/).map(T=>T.trim()).find(T=>T&&!T.startsWith("at "));d(new Error(`${n} exited with code ${A??-1}${q?` (signal ${q})`:""}${j?`: ${j}`:""}`));}});}),0}function Rt(e){let t=e.awsTempCreds;if(!t)return {};let n={};return typeof t.accessKeyId=="string"&&t.accessKeyId.trim()!==""&&(n.AWS_ACCESS_KEY_ID=t.accessKeyId.trim()),typeof t.secretAccessKey=="string"&&t.secretAccessKey.trim()!==""&&(n.AWS_SECRET_ACCESS_KEY=t.secretAccessKey.trim()),typeof t.sessionToken=="string"&&t.sessionToken.trim()!==""&&(n.AWS_SESSION_TOKEN=t.sessionToken.trim()),n}async function qt(e,t){let n=s=>{if(!s||typeof s!="object")return null;let o=s,u={...o.siteSettings??{},...String(o.accountId??"").trim()&&!o.siteSettings?.accountId?{accountId:String(o.accountId).trim()}:{},...String(o.siteId??"").trim()&&!o.siteSettings?.siteId?{siteId:String(o.siteId).trim()}:{},...o.siteSettings?.subscriber===true||o.subscriber===true?{subscriber:true}:{}},c={...String(o.apiBase??"").trim()?{apiBase:String(o.apiBase).trim()}:{},...String(o.runtimeToken??o.nonce??"").trim()?{runtimeToken:String(o.runtimeToken??o.nonce).trim()}:{},...String(o.virtualAssetBaseUrl??o.uploadUrl??"").trim()?{virtualAssetBaseUrl:String(o.virtualAssetBaseUrl??o.uploadUrl).trim()}:{},...Object.keys(u).length>0?{siteSettings:u}:{},...o.subscriptionType?{subscriptionType:o.subscriptionType}:{}};return Object.keys(c).length>0?c:null},r=await Z(t.configPath).catch(()=>null),i=n(r?.wpsuite);if(i)return i;let a=n(e.wpsuite);return a||null}async function Dt(e,t){return await qt(e,t)}function ue(e){let t={...e,status:"queued"};return delete t.startedAt,delete t.endedAt,delete t.exitCode,delete t.error,delete t.stopRequestedAt,delete t.stopRequestedByUserId,delete t.stopRequestedByLogin,delete t.stopMode,delete t.stoppedStep,t}async function xt(e,t){let n=await v(ae(e.runtimeDir),null),r=n&&n.details&&typeof n.details.phase=="string"?n.details.phase.trim():"";if(r)return r;let i=n&&typeof n.currentStep=="string"?n.currentStep.trim():"";if(i)return i;let a=await Re(e).catch(()=>"");if(a){let s=await v(m.join(a,"current-crawl-event.json"),null),o=s&&typeof s.currentStep=="string"?s.currentStep.trim():"";if(o)return o}return t}function Tt(e,t){if((e.command==="publish"||e.command==="crawl")&&t==="rewrite-text")return "rewrite-text"}async function kt(e){let t=m.join(e.runtimeDir,"queue.json"),n=m.join(e.runtimeDir,"current-run.json"),r=await E(e.runtimeDir,async()=>{let i=await v(n,null);if(!i||i.status!=="running"&&i.status!=="queued")return null;let a=await v(t,[]),s=Array.isArray(a)?a.filter(u=>u?.id!==i.id):[],o=ue(i);return await w(t,[o,...s]),await w(n,null),o});r&&(await O(e.runtimeDir,r.id),await I(e.runtimeDir,{eventType:"job-recovered",status:"queued",actorSource:"queue-runner",jobId:r.id,command:r.command,message:"Recovered stale current-run entry back into queue."}));}async function Et(e,t,n){try{if((n.shouldEnforceSubscriptionOnJobExecution?.(e)??n.enforceSubscriptionOnJobExecution)&&n.assertActiveSubscriptionForIdentity){let o=await Dt(e,t);await n.assertActiveSubscriptionForIdentity(o);}let i=Rt(e),a=e.resumeFromStep==="rewrite-text"?["--resume-rewrite"]:e.crawlMode==="incremental"?["--crawl-mode","incremental"]:[],s=e.deploymentProfile?["--profile",e.deploymentProfile]:[];if(e.command==="publish")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"content-sync-release-cutoff"}),await R(t.exporterDir,t.runtimeDir,"content-sync",["--capture-baseline-cutoffs",e.id],t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:e.resumeFromStep==="rewrite-text"?"rewrite-text":"crawl"}),await R(t.exporterDir,t.runtimeDir,"crawl",a,t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"deploy"}),await R(t.exporterDir,t.runtimeDir,"deploy",s,t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"invalidate"}),await R(t.exporterDir,t.runtimeDir,"invalidate",s,t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"content-sync-baseline"}),await R(t.exporterDir,t.runtimeDir,"content-sync",["--establish-baselines",e.id],t.configPath,i,e.id),{exitCode:0};if(e.command==="crawl")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:e.resumeFromStep==="rewrite-text"?"rewrite-text":"crawl"}),await R(t.exporterDir,t.runtimeDir,"crawl",a,t.configPath,i,e.id),{exitCode:0};if(e.command==="deploy")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"deploy"}),await R(t.exporterDir,t.runtimeDir,"deploy",s,t.configPath,i,e.id),{exitCode:0};if(e.command==="invalidate")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"invalidate"}),await R(t.exporterDir,t.runtimeDir,"invalidate",s,t.configPath,i,e.id),{exitCode:0};if(e.command==="retry-timeouts")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"retry-timeouts"}),await R(t.exporterDir,t.runtimeDir,"crawl",["--retry-timeouts"],t.configPath,i,e.id),{exitCode:0};if(e.command==="url"){let o=(e.url||"").trim();return o?(await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"url"}),await R(t.exporterDir,t.runtimeDir,"crawl",["--url",o],t.configPath,i,e.id),{exitCode:0}):{exitCode:2,error:"Missing url for command 'url'"}}return e.command==="content-sync"?!e.ruleId||!e.coalesceKey?{exitCode:2,error:"Content-sync queue jobs require ruleId and coalesceKey."}:(await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"content-sync"}),await R(t.exporterDir,t.runtimeDir,"content-sync",["--job-id",e.id],t.configPath,i,e.id),{exitCode:0}):{exitCode:2,error:`Unsupported command: ${e.command}`}}catch(r){return r instanceof B?{exitCode:130,error:"Job stop requested.",stopped:true,stopRequest:r.request,stoppedStep:r.step}:{exitCode:1,error:r instanceof Error?r.message:String(r)}}}function xe(e){return async function(n=process.argv.slice(2)){let r=ut(n),i=m.join(r.runtimeDir,"export.lock"),a=m.join(r.runtimeDir,"last-run.json");await L(r.runtimeDir),await C(r,"starting",{message:"queue-runner starting"});try{await Ct(i);}catch(s){if((s&&typeof s=="object"&&"code"in s?String(s.code||""):"")!=="EEXIST")throw s;console.log("[queue-runner] lock active, skipping"),await C(r,"lock-active",{message:"lock active, skipped this cron tick"});return}try{await kt(r);let s=await Pt(r,e),o=0;for(let u=0;u<r.maxJobs;u++){let c=await Ot(r,e);if(c==="none"||(o+=1,c==="stopped"))break}if(o===0)await L(r.runtimeDir),await C(r,"idle",{processedJobs:o,schedulerEnqueued:s,message:"no queued jobs"});else {await L(r.runtimeDir);let u=await v(a,null),c=String(u?.status||"").trim();await C(r,c==="success"?"job-success":c==="stopped"?"job-stopped":"job-failed",{processedJobs:o,schedulerEnqueued:s,lastJobId:u?.id,lastJobCommand:u?.command,lastJobStatus:u?.status,lastJobExitCode:u?.exitCode,lastJobError:u?.error,...c==="stopped"?{currentStep:u?.stoppedStep,stopRequestedAt:u?.stopRequestedAt,stopRequestedByLogin:u?.stopRequestedByLogin,stopRequestedMode:u?.stopMode,lastStoppedStep:u?.stoppedStep,message:u?.stopMode==="requeue"?`Job stopped during ${u?.stoppedStep||u?.command||"active step"} and requeued.`:`Job stopped during ${u?.stoppedStep||u?.command||"active step"} and left out of queue.`}:{}});}}catch(s){let o=s instanceof Error?s.message:String(s);throw await C(r,"error",{message:o}),await I(r.runtimeDir,{eventType:"queue-runner-error",status:"failed",actorSource:"queue-runner",message:"Unhandled queue-runner error.",details:{error:o}}),s}finally{await At(i);}}}async function Ft(e,t,n){let r=m.join(e.runtimeDir,"queue.json"),i=m.join(e.runtimeDir,"current-run.json");await E(e.runtimeDir,async()=>{let a=await v(r,[]),s=Array.isArray(a)?a.filter(c=>c?.id!==t.id):[],o=ue(t),u=Tt(t,n);u?o.resumeFromStep=u:delete o.resumeFromStep,await w(r,[o,...s]),await w(i,null);});}async function jt(e,t,n){let r=Math.max(0,t.attempt??0)+1,i=Math.min(3600*1e3,6e4*2**(r-1)),a=Math.floor(i*.2*Math.random()),s=new Date(Date.now()+i+a).toISOString(),o={...ue(t),status:"retry-wait",attempt:r,nextAttemptAt:s,error:n};if(await E(e.runtimeDir,async()=>{let u=m.join(e.runtimeDir,"queue.json"),c=m.join(e.runtimeDir,"current-run.json"),g=(await v(u,[])).filter(p=>p.id!==t.id);await w(u,[o,...g]),await w(c,null);}),t.coalesceKey){let u=m.join(e.runtimeDir,"content-sync-state.json"),d=(await v(u,{})).rules??{};d[t.coalesceKey]={...d[t.coalesceKey]??{},ruleId:t.ruleId||"",coalesceKey:t.coalesceKey,retryAttempt:r,nextRetryAt:s,lastError:n,trailingWorkDetected:true},await w(u,{schemaVersion:1,updatedAt:new Date().toISOString(),rules:d});}return o}async function Jt(e,t){if(!t.coalesceKey||!t.ruleId||!(await v(m.join(e.runtimeDir,"content-sync-state.json"),null))?.rules?.[t.coalesceKey]?.trailingWorkDetected)return null;let r=null;await E(e.runtimeDir,async()=>{let a=m.join(e.runtimeDir,"queue.json"),s=await v(a,[]);oe(s,{command:"content-sync",coalesceKey:t.coalesceKey,deploymentProfile:t.deploymentProfile})||(r={id:randomUUID(),command:"content-sync",ruleId:t.ruleId,coalesceKey:t.coalesceKey,deploymentProfile:t.deploymentProfile,enqueueSource:"scheduler",wpsuite:t.wpsuite,status:"queued",attempt:0,createdAt:new Date().toISOString(),createdBy:0},await w(a,[...s,r]));});let i=r;return i&&await I(e.runtimeDir,{eventType:"content-sync-trailing-job-created",status:"queued",actorSource:"queue-runner",jobId:i.id,command:i.command,message:"Content changes after the stable cutoff created one trailing job.",details:{predecessorJobId:t.id,ruleId:t.ruleId,coalesceKey:t.coalesceKey}}),i}async function Ot(e,t){let n=m.join(e.runtimeDir,"queue.json"),r=m.join(e.runtimeDir,"current-run.json"),i=m.join(e.runtimeDir,"last-run.json"),a=new Date().toISOString(),s=await E(e.runtimeDir,async()=>{let g=await v(n,[]);if(!Array.isArray(g)||g.length===0)return null;let p=Date.parse(String(g[0]?.nextAttemptAt||""));if(Number.isFinite(p)&&p>Date.now())return null;let h={...g[0],status:"running",startedAt:a};return delete h.nextAttemptAt,await w(n,g.slice(1)),await w(r,h),h});if(!s)return "none";await L(e.runtimeDir),await I(e.runtimeDir,{eventType:"job-run-started",status:"running",actorSource:"queue-runner",jobId:s.id,command:s.command,message:"Job execution started.",details:{createdAt:s.createdAt||"",startedAt:a,createdBy:s.createdBy??null,deploymentProfile:s.deploymentProfile||"",queuedWithTempAwsCreds:!!s.awsTempCreds}}),await C(e,"running",{currentJobId:s.id,currentJobCommand:s.command,currentStep:s.command});let o=await Et(s,e,t),u=new Date().toISOString();if(o.stopped){let g=await xt(e,o.stoppedStep||s.command),p=o.stopRequest?.mode==="requeue"?"requeue":"stop",h={...s,status:"stopped",endedAt:u,exitCode:o.exitCode,...o.error?{error:o.error}:{},stopRequestedAt:o.stopRequest?.requestedAt||"",stopRequestedByUserId:typeof o.stopRequest?.requestedByUserId=="number"?o.stopRequest.requestedByUserId:null,stopRequestedByLogin:o.stopRequest?.requestedByLogin||"",stopMode:p,stoppedStep:g};p==="requeue"?await Ft(e,s,g):await w(r,null);try{let y=await $(h,e);h.logArchiveDir=y.archiveDir,h.logArchiveCreatedAt=y.archiveCreatedAt,h.logArchiveFileCount=y.archivedFiles.length;}catch(y){h.logArchiveError=y instanceof Error?y.message:String(y);}return await w(i,h),await O(e.runtimeDir,s.id),await L(e.runtimeDir),await I(e.runtimeDir,{eventType:"job-run-stopped",status:"stopped",actorSource:"queue-runner",jobId:s.id,command:s.command,message:p==="requeue"?"Job stop requested and requeued.":"Job stop requested and removed from active execution without requeue.",details:{startedAt:s.startedAt||"",endedAt:u,deploymentProfile:s.deploymentProfile||"",stopMode:p,stopRequestedAt:o.stopRequest?.requestedAt||"",stopRequestedByLogin:o.stopRequest?.requestedByLogin||"",stopRequestedByUserId:typeof o.stopRequest?.requestedByUserId=="number"?o.stopRequest.requestedByUserId:null,stoppedStep:g,logArchiveKey:h.logArchiveError||!h.logArchiveDir?"":m.basename(h.logArchiveDir),logArchiveDir:h.logArchiveDir||"",logArchiveCreatedAt:h.logArchiveCreatedAt||"",logArchiveFileCount:h.logArchiveFileCount??0,logArchiveError:h.logArchiveError||""}}),"stopped"}if(s.command==="content-sync"&&o.exitCode!==0){if(/baseline (?:is missing or stale|required)|verified content-sync baseline|new baseline/i.test(o.error||"")){let y="The installed release no longer matches the verified content-sync baseline. Run a successful full or incremental publish to establish a new baseline.";s.ruleId&&s.coalesceKey&&await De(e,s.ruleId,s.coalesceKey,y);let l={...s,status:"failed",endedAt:u,exitCode:o.exitCode,error:y};try{let b=await $(l,e);l.logArchiveDir=b.archiveDir,l.logArchiveCreatedAt=b.archiveCreatedAt,l.logArchiveFileCount=b.archivedFiles.length;}catch(b){l.logArchiveError=b instanceof Error?b.message:String(b);}return await w(i,l),await O(e.runtimeDir,s.id),await I(e.runtimeDir,{eventType:"content-sync-baseline-required",status:"failed",actorSource:"queue-runner",jobId:s.id,command:s.command,message:y,details:{ruleId:s.ruleId||"",retryScheduled:false}}),"processed"}await I(e.runtimeDir,{eventType:"content-sync-failed",status:"failed",actorSource:"queue-runner",jobId:s.id,command:s.command,message:"Content-sync execution failed before cursor acknowledgement.",details:{attempt:s.attempt??0,error:o.error||"Content-sync execution failed."}});let p=await jt(e,s,o.error||"Content-sync execution failed."),h={...s,status:"retry-wait",endedAt:u,exitCode:o.exitCode,error:p.error,attempt:p.attempt,nextAttemptAt:p.nextAttemptAt};try{let y=await $(h,e);h.logArchiveDir=y.archiveDir,h.logArchiveCreatedAt=y.archiveCreatedAt,h.logArchiveFileCount=y.archivedFiles.length;}catch(y){h.logArchiveError=y instanceof Error?y.message:String(y);}return await w(i,h),await O(e.runtimeDir,s.id),await I(e.runtimeDir,{eventType:"content-sync-retry-scheduled",status:"retry-wait",actorSource:"queue-runner",jobId:s.id,command:s.command,message:"Content-sync retry was scheduled with bounded backoff.",details:{attempt:p.attempt??0,nextAttemptAt:p.nextAttemptAt||"",error:p.error||""}}),"processed"}let c={...s,status:o.exitCode===0?"success":"failed",endedAt:u,exitCode:o.exitCode,...o.error?{error:o.error}:{}};await w(r,null),c.status==="success"&&c.command==="content-sync"&&await Jt(e,c),await O(e.runtimeDir,s.id);try{let g=await $(c,e);c.logArchiveDir=g.archiveDir,c.logArchiveCreatedAt=g.archiveCreatedAt,c.logArchiveFileCount=g.archivedFiles.length;}catch(g){c.logArchiveError=g instanceof Error?g.message:String(g);}await w(i,c);let d=s.startedAt&&c.endedAt?Math.max(0,Math.round((new Date(c.endedAt).getTime()-new Date(s.startedAt).getTime())/1e3)):void 0;return await I(e.runtimeDir,{eventType:"job-run-finished",status:c.status==="success"?"success":"failed",actorSource:"queue-runner",jobId:c.id,command:c.command,message:c.status==="success"?"Job execution finished successfully.":"Job execution finished with failure.",details:{startedAt:s.startedAt||"",endedAt:c.endedAt||"",durationSec:d,deploymentProfile:c.deploymentProfile||"",exitCode:c.exitCode??null,error:c.error||"",logArchiveKey:c.logArchiveError||!c.logArchiveDir?"":m.basename(c.logArchiveDir),logArchiveDir:c.logArchiveDir||"",logArchiveCreatedAt:c.logArchiveCreatedAt||"",logArchiveFileCount:c.logArchiveFileCount??0,logArchiveError:c.logArchiveError||""}}),"processed"}async function Bt(e){if(!e)throw new Error("Missing remote WPSuite publisher state. Refresh the runtime config before running subscription-gated jobs.");if(e.subscriptionType!=="PROFESSIONAL"&&e.subscriptionType!=="AGENCY")throw new Error("This job requires an active WPSuite publisher subscription in the remote site configuration.")}var Mt={allowSchedulerAutoEnqueue:true,enforceSubscriptionOnJobExecution:false,shouldEnforceSubscriptionOnJobExecution:e=>Ce(e)||e.enqueueSource==="scheduler"||e.createdBy===0,assertActiveSubscriptionForIdentity:Bt},Te=xe(Mt),Ut=Te,wn=Te;process.argv[1]&&import.meta.url===pathToFileURL(process.argv[1]).href&&Ut().catch(e=>{console.error(e),process.exit(1);});export{wn as default,Ut as main,Te as runQueueRunner};
1
+ import {pathToFileURL}from'url';import P from'fs/promises';import {existsSync,createReadStream,createWriteStream}from'fs';import m from'path';import {spawn}from'child_process';import {randomUUID,createHash}from'crypto';import Je from'http';import me from'https';import {pipeline}from'stream/promises';import {createGzip}from'zlib';function le(e){return [...new Set(e.map(t=>t.trim()).filter(Boolean))].sort()}function N(e){return Array.isArray(e)?e.map(N):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,N(n)])):e}function Ee(e){return JSON.stringify(N(e))}function J(e){return createHash("sha256").update(Ee(e)).digest("hex")}function de(e){return J({schemaVersion:1,wordpressFingerprint:e.wordpressFingerprint,targetFingerprint:e.targetFingerprint,sourceOrigin:e.sourceOrigin,sitemapPaths:[...e.sitemapPaths].sort(),blockedPathPrefixes:[...e.blockedPathPrefixes].sort(),assetPathPrefixes:[...e.assetPathPrefixes].sort(),noJavaScriptRenderPathPrefixes:[...e.noJavaScriptRenderPathPrefixes].sort(),urlRewriteMode:e.urlRewriteMode})}function Fe(e){let t=new URL(e);if(t.protocol!=="http:"&&t.protocol!=="https:")throw new Error(`Unsupported source origin protocol: ${t.protocol}`);return t.hash="",t.search="",t.pathname=t.pathname.replace(/\/+$/,""),t.toString().replace(/\/$/,"")}function M(e){let t=le((e.postTypes??[]).map(r=>String(r).toLowerCase().replace(/[^a-z0-9_-]/g,"")));if(t.length===0)throw new Error("Content-sync requires at least one public post type.");let n=le((e.listingPaths??[]).map(r=>{let i=String(r).trim();if(!i)return "";let a=new URL(i,"https://content-sync.invalid/");if(a.origin!=="https://content-sync.invalid"&&/^https?:\/\//i.test(i))throw new Error("Content-sync listing routes must be same-site paths.");let s=`/${a.pathname.replace(/^\/+|\/+$/g,"")}`;return s==="/"?"/":`${s}/`}));return {postTypes:t,listingPaths:n,includeSubsites:e.includeSubsites===true,includePostTypeArchives:e.includePostTypeArchives!==false,includeTaxonomyArchives:e.includeTaxonomyArchives!==false,includeAuthorArchives:e.includeAuthorArchives===true,includeDateArchives:e.includeDateArchives===true,includePostsPage:e.includePostsPage!==false,includeSitemapChain:e.includeSitemapChain!==false}}function _(e,t,n){return J({schemaVersion:1,sourceOrigin:Fe(e),ruleId:t.trim(),scope:M(n)})}function K(e){return J({schemaVersion:1,...e})}function pe(e){return e.replace(/((?:x-static-publisher-token|authorization|proxy-authorization|x-api-key|aws-access-key-id|aws-secret-access-key|aws-session-token)\s*:\s*)[^\r\n]+/gi,"$1[REDACTED]").replace(/\b(Basic|Bearer)\s+[^\s]+/gi,"$1 [REDACTED]").replace(/([?&](?:token|access_token|refresh_token|api_key|key|nonce)=)[^&\s]+/gi,"$1[REDACTED]").replace(/((?:"|')?(?:runtimeToken|siteKey|nonce|accessToken|refreshToken|accessKeyId|secretAccessKey|sessionToken)(?:"|')?\s*[:=]\s*(?:"|'))[^"']+/gi,"$1[REDACTED]")}var ge=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";ge?m.join(ge,"current-progress.json"):"";Promise.resolve();var Le="wp-json/smartcloud-static-publisher/v1/content-sync/",Oe=25*1024*1024,k=class extends Error{status;code;constructor(t,n,r){super(r),this.name="ContentSyncApiError",this.status=t,this.code=n;}},U=class{options;constructor(t){if(!t.runtimeToken.trim())throw new Error("Content-sync requires a WordPress runtime token.");this.options={...t,timeoutMs:t.timeoutMs??6e4};}endpoint(t){let n=this.options.sourceOrigin.replace(/\/+$/,"")+"/";return new URL(`${Le}${t}`,n)}async post(t,n){let r=this.endpoint(t),i=Buffer.from(JSON.stringify(n),"utf8"),a=r.protocol==="https:"?me:Je,s=r.protocol==="https:"?new me.Agent({rejectUnauthorized:!this.options.ignoreHttpsErrors}):void 0;return new Promise((o,u)=>{let c=a.request(r,{method:"POST",agent:s,headers:{"content-type":"application/json","content-length":String(i.byteLength),"x-static-publisher-token":this.options.runtimeToken},timeout:this.options.timeoutMs},d=>{let g=[],p=0;d.on("data",h=>{if(p+=h.byteLength,p>Oe){d.destroy(new Error("Content-sync API response exceeded the size limit."));return}g.push(h);}),d.on("error",u),d.on("end",()=>{let h=Buffer.concat(g).toString("utf8"),y;try{y=h?JSON.parse(h):{};}catch{u(new k(d.statusCode??500,"invalid-json","Content-sync API returned invalid JSON."));return}let l=d.statusCode??500;if(l<200||l>=300){u(new k(l,String(y.code??"request-failed"),String(y.message??`Content-sync API request failed (${l}).`)));return}o(y);});});c.on("timeout",()=>c.destroy(new Error(`Content-sync API request timed out: ${t}`))),c.on("error",u),c.end(i);})}async head(t){return this.post("head",t)}async unboundHead(t,n){return this.post("head",{postTypes:t,includeSubsites:n})}async events(t){let n=[],r=t.afterSequence,i=new Set(t.postTypes);for(;r<t.throughSequence;){let a=await this.post("events",{...t,afterSequence:r,limit:250});if(a.fromSequence!==r||a.throughSequence!==t.throughSequence||a.nextSequence<r||a.nextSequence>t.throughSequence)throw new Error("Content-sync API returned an inconsistent event page.");if(!Array.isArray(a.items))throw new Error("Content-sync API returned a malformed event page.");let s=r;for(let o of a.items){if(!Number.isSafeInteger(o.sequence)||o.sequence<=s||o.sequence>t.throughSequence||!Number.isSafeInteger(o.postId)||o.postId<=0||!Number.isSafeInteger(o.blogId)||o.blogId<=0||!i.has(o.postType)||typeof o.operation!="string"||!o.operation)throw new Error("Content-sync API returned an invalid or out-of-scope journal event.");s=o.sequence;}if(a.items.length>0&&a.nextSequence!==s)throw new Error("Content-sync API event cursor does not match the final returned event.");if(n.push(...a.items),!a.hasMore)break;if(a.nextSequence===r)throw new Error("Content-sync API event pagination did not advance.");r=a.nextSequence;}if(t.throughSequence>t.afterSequence&&n.at(-1)?.sequence!==t.throughSequence)throw new Error("Content-sync API omitted the claimed journal high-water event.");return n}async resolveImpactFamilies(t,n){let r=await this.post("impact",{families:t,includeSubsites:n});return Array.isArray(r.families)?r.families:[]}async releaseFingerprint(t=false){let n=await this.post("fingerprint",{includeSubsites:t}),r=String(n.fingerprint||"").trim();if(!/^[a-f0-9]{64}$/.test(r))throw new Error("WordPress returned an invalid release fingerprint.");return r}async establishBaseline(t){return this.post("baseline",t)}async acknowledge(t){return this.post("ack",t)}};function Be(e){return typeof e.subscriptionType=="string"&&e.subscriptionType.trim()!==""}function Me(e,t){return {...e,...t??{}}}function Ue(e,t){return {...e,...t??{},invalidationPaths:[...(t?.invalidationPaths??e.invalidationPaths)||[]]}}function z(e,t){let n=String(t??e.deploymentTargetOverride??"").trim();if(!Be(e)){if(n)throw new Error(`Deployment target "${n}" requires an active WPSuite subscription and remote publisher config.`);return {name:null,profile:null,config:e}}let r=String(n||e.defaultDeploymentProfile||"").trim();if(!r)return {name:null,profile:null,config:e};let i=e.deploymentProfiles?.[r];if(!i)throw new Error(`Unknown deployment profile "${r}". Check the linked WPSuite publisher configuration.`);return {name:r,profile:i,config:{...e,targetOrigin:i.targetOrigin??e.targetOrigin,s3:Me(e.s3,i.s3),cloudFront:Ue(e.cloudFront,i.cloudFront)}}}function fe(e){let t=e.trim();return t==="."?".":t.replace(/\/$/,"")}function Ne(e){let t=String(e??"").trim();if(!t)return "";let n=t;if(/^https?:\/\//i.test(n))try{n=new URL(n).pathname;}catch{return ""}if(n=n.split(/[?#]/,1)[0]?.replace(/\\/g,"/").trim()??"",!n)return "";let r=n.endsWith("/"),i=n.replace(/^\/+/,"").split("/").map(s=>s.replace(/[^A-Za-z0-9._-]/g,"")).filter(s=>s.length>0&&s!=="."&&s!=="..");if(i.length===0)return "";let a=`/${i.join("/")}`;return r&&m.extname(a)===""&&(a+="/"),a==="/"?"":a}function H(e){return !e||typeof e!="object"?{}:Object.fromEntries(Object.entries(e).map(([t,n])=>[t.trim(),String(n??"")]).filter(([t])=>t.length>0))}function _e(e){if(!e||typeof e!="object")return {};let t={};for(let[n,r]of Object.entries(e)){let i=n.trim();if(!i||!r||typeof r!="object")continue;let a=r,s={};if(typeof a.targetOrigin=="string"){let u=fe(a.targetOrigin);u&&(s.targetOrigin=u);}let o=H(a.extraReplacements);if(Object.keys(o).length>0&&(s.extraReplacements=o),a.s3&&typeof a.s3=="object"){let u={},c=a.s3;typeof c.bucket=="string"&&(u.bucket=c.bucket.trim()),typeof c.prefix=="string"&&(u.prefix=c.prefix.trim()),typeof c.region=="string"&&(u.region=c.region.trim()),typeof c.htmlCacheControl=="string"&&(u.htmlCacheControl=c.htmlCacheControl.trim()),typeof c.assetCacheControl=="string"&&(u.assetCacheControl=c.assetCacheControl.trim()),Object.keys(u).length>0&&(s.s3=u);}if(a.cloudFront&&typeof a.cloudFront=="object"){let u={},c=a.cloudFront;typeof c.distributionId=="string"&&(u.distributionId=c.distributionId.trim()),Array.isArray(c.invalidationPaths)&&(u.invalidationPaths=c.invalidationPaths.map(d=>String(d??"").trim()).filter(d=>d.length>0)),Object.keys(u).length>0&&(s.cloudFront=u);}t[i]=s;}return t}function V(e){return e==="PROFESSIONAL"||e==="AGENCY"?e:void 0}function Ke(e,t){if(!e||typeof e!="object")return null;let n=e,r=n.command;if(r!=="publish"&&r!=="crawl"&&r!=="deploy"&&r!=="invalidate"&&r!=="retry-timeouts"&&r!=="url"&&r!=="content-sync")return null;let i=Number.parseInt(String(n.intervalMinutes??"0"),10);if(!Number.isFinite(i)||i<1)return null;let a=String(n.id??`${r}-${t+1}`).trim();if(!a)return null;let s=String(n.deploymentProfile??"").trim(),o=String(n.url??"").trim(),u=Array.isArray(n.postTypes)?[...new Set(n.postTypes.map(d=>String(d??"").trim().toLowerCase().replace(/[^a-z0-9_-]/g,"")).filter(Boolean))]:[],c=Array.isArray(n.listingPaths)?[...new Set(n.listingPaths.map(d=>String(d??"").trim()).filter(Boolean))]:[];return r==="content-sync"&&u.length===0?null:{id:a,enabled:n.enabled!==false,command:r,intervalMinutes:i,...r==="publish"||r==="crawl"?{crawlMode:n.crawlMode==="incremental"?"incremental":"full"}:{},...(r==="publish"||r==="deploy"||r==="invalidate"||r==="content-sync")&&s?{deploymentProfile:s}:{},...o?{url:o}:{},...u.length>0?{postTypes:u}:{},...c.length>0?{listingPaths:c}:{},...typeof n.includeSubsites=="boolean"?{includeSubsites:n.includeSubsites}:{},...typeof n.includePostTypeArchives=="boolean"?{includePostTypeArchives:n.includePostTypeArchives}:{},...typeof n.includeTaxonomyArchives=="boolean"?{includeTaxonomyArchives:n.includeTaxonomyArchives}:{},...typeof n.includeAuthorArchives=="boolean"?{includeAuthorArchives:n.includeAuthorArchives}:{},...typeof n.includeDateArchives=="boolean"?{includeDateArchives:n.includeDateArchives}:{},...typeof n.includePostsPage=="boolean"?{includePostsPage:n.includePostsPage}:{},...typeof n.includeSitemapChain=="boolean"?{includeSitemapChain:n.includeSitemapChain}:{}}}function ye(e){let t=e&&typeof e=="object"?e:{},n=Array.isArray(t.rules)?t.rules.map((r,i)=>Ke(r,i)).filter(r=>!!r):[];return {enabled:t.enabled===true,timezone:typeof t.timezone=="string"&&t.timezone.trim()!==""?t.timezone.trim():"UTC",rules:n}}function ze(e){if(!e||typeof e!="object")return;let t=e,n={};for(let i of ["accountId","siteId"]){let a=t[i];typeof a=="string"&&a.trim()!==""&&(n[i]=a.trim());}let r=Number(t.lastUpdate??0);return Number.isFinite(r)&&r>0&&(n.lastUpdate=Math.floor(r)),t.subscriber===true&&(n.subscriber=true),Object.keys(n).length>0?n:void 0}function Y(e){let t=e&&typeof e=="object"?e:{},n=String(t.accountId??"").trim(),r=String(t.siteId??"").trim(),i=t.subscriber===true,a=ze(t.siteSettings),s={...a??{},...n?{accountId:a?.accountId??n}:{},...r?{siteId:a?.siteId??r}:{},...a?.subscriber===true||i?{subscriber:true}:{}},o={},u=String(t.apiBase??"").trim();u&&(o.apiBase=u);let c=String(t.runtimeToken??t.nonce??"").trim();c&&(o.runtimeToken=c);let d=String(t.virtualAssetBaseUrl??t.uploadUrl??"").trim();d&&(o.virtualAssetBaseUrl=d),Object.keys(s).length>0&&(o.siteSettings=s);let g=V(t.subscriptionType);return g&&(o.subscriptionType=g),o}function He(e){try{let t=new URL(e);globalThis.location=t;}catch{}}function be(e){return typeof e=="string"?e:e instanceof URL?e.toString():e.url}function Ge(e,t){let n=new Headers(e instanceof Request?e.headers:void 0);if(t?.headers)for(let[r,i]of new Headers(t.headers).entries())n.set(r,i);return n}async function Se(e,t,n=5){let r=new URL(be(e)),i=String(t?.method??(e instanceof Request?e.method:"GET")).toUpperCase(),a=r.protocol==="http:"?Je:me,s=Ge(e,t);return await new Promise((o,u)=>{let c=a.request(r,{method:i,headers:Object.fromEntries(s.entries()),...r.protocol==="https:"?{rejectUnauthorized:false}:{}},d=>{let g=[];d.on("data",p=>{g.push(Buffer.isBuffer(p)?p:Buffer.from(p));}),d.on("error",u),d.on("end",()=>{let p=d.statusCode??0,h=d.headers.location;if(n>0&&h&&[301,302,303,307,308].includes(p)){o(Se(new URL(h,r),{method:p===303?"GET":i},n-1));return}let y=new Headers;for(let[l,b]of Object.entries(d.headers))Array.isArray(b)?y.set(l,b.join(", ")):typeof b=="string"&&y.set(l,b);o(new Response(Buffer.concat(g),{status:p,statusText:d.statusMessage??"",headers:y}));});});c.on("error",u),c.end();})}function Ve(e){let t=Y(e.wpsuite),n={...t.siteSettings??{},...t.siteSettings?.subscriber===true||t.subscriptionType==="PROFESSIONAL"||t.subscriptionType==="AGENCY"?{subscriber:true}:{}},r=String(n.accountId??"").trim(),i=String(n.siteId??"").trim(),a=String(t.virtualAssetBaseUrl??t.uploadUrl??"").trim();if(e.wpsuite={...t.apiBase?{apiBase:t.apiBase}:{},...t.runtimeToken?{runtimeToken:t.runtimeToken}:{},...a?{virtualAssetBaseUrl:a}:{},...Object.keys(n).length>0?{siteSettings:n}:{},...t.subscriptionType?{subscriptionType:t.subscriptionType}:{}},!r||!i||!a)return false;He(e.sourceOrigin);let s=globalThis,u={...s.WpSuite??{},siteSettings:n,uploadUrl:a};return t.apiBase&&(u.apiBase=t.apiBase),s.WpSuite=u,true}async function Ye(e){let t=String(e.wpsuite?.virtualAssetBaseUrl??e.wpsuite?.uploadUrl??"").trim();if(!Ve(e)){let i=e.wpsuite?.siteSettings,a=[String(i?.accountId??"").trim()?"":"accountId",String(i?.siteId??"").trim()?"":"siteId",t?"":"virtualAssetBaseUrl"].filter(Boolean);return {remote:null,diagnostic:{status:"invalid-runtime",virtualAssetBaseUrl:t,subscriptionType:null,error:`Missing WP Suite runtime field(s): ${a.join(", ")}.`,requests:[]}}}let n=globalThis.fetch,r=[];try{typeof n=="function"&&/^https?:\/\//i.test(t)&&(globalThis.fetch=(async(u,c)=>{let d=be(u);if(d.startsWith(t)){let g=(()=>{try{return new URL(d).pathname}catch{return d}})();try{let p=e.ignoreHttpsErrors&&d.startsWith("https://")?await Se(u,c):await n(u,c);return r.push({path:g,status:p.status,ok:p.ok,error:null}),p}catch(p){throw r.push({path:g,status:null,ok:!1,error:p instanceof Error?p.message:String(p)}),p}}return n(u,c)}));let{getConfig:i}=await import('@smart-cloud/wpsuite-core'),a=await i("publisher"),s=a&&typeof a=="object"?a:null,o=V(s?.subscriptionType);return {remote:s,diagnostic:{status:s?"loaded":"unavailable",virtualAssetBaseUrl:t,subscriptionType:o??null,error:s?null:"WP Suite publisher config loader returned no configuration.",requests:r}}}catch(i){return {remote:null,diagnostic:{status:"unavailable",virtualAssetBaseUrl:t,subscriptionType:null,error:i instanceof Error?i.message:String(i),requests:r}}}finally{typeof n=="function"&&(globalThis.fetch=n);}}function Ze(e,t){let n=_e(t?.deploymentProfiles),r=String(t?.defaultDeploymentProfile??"").trim(),i=n[r]?r:"",a=V(t?.subscriptionType),s=Y(e.wpsuite);return {...e,scheduler:ye(t?.scheduler),deploymentProfiles:n,defaultDeploymentProfile:i,...a?{subscriptionType:a}:{},wpsuite:{...s,...s.siteSettings||a?{siteSettings:{...s.siteSettings??{},...s.siteSettings?.subscriber===true||a==="PROFESSIONAL"||a==="AGENCY"?{subscriber:true}:{}}}:{},...a?{subscriptionType:a}:{}}}}function G(e,t){let r=String(e||"").replace(/\\/g,"/").trim().replace(/^\/+|\/+$/g,"");if(!r)return t;let i=r.split("/").map(a=>a.trim()).filter(a=>a.length>0&&a!=="."&&a!=="..");return i.length>0?i.join("/"):t}function Xe(){let e=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"";return e.trim()?m.resolve(e):""}function he(e,t,n){let r=String(t||"").trim();return r&&m.isAbsolute(r)?m.resolve(r):m.resolve(e,G(r,n))}async function Z(e,t={}){let n=String(e??"").trim()||process.env.PUBLISHER_CONFIG||"publisher.config.json",r=await P.readFile(n,"utf8"),i=JSON.parse(r);i.sourceOrigin=i.sourceOrigin.replace(/\/$/,""),i.targetOrigin=fe(i.targetOrigin),i.ignoreHttpsErrors??=false,i.outputDir=String(i.outputDir||"export").trim()||"export",i.urlRewriteMode||=i.targetOrigin==="."?"relative":"absolute",i.noJavaScriptRenderPathPrefixes||=[],i.seedPaths||=[],i.generated404RequestPath=Ne(i.generated404RequestPath),i.sitemapPaths||=["/sitemap_index.xml","/sitemap.xml"],i.allowedAssetHosts||=[],i.assetPathPrefixes||=["/wp-content/","/wp-includes/","/static/","/assets/","/build/","/_next/","/docs/","/sitemap","/robots.txt","/llms.txt"],i.blockedPathPrefixes||=[],i.blockedSearchFragments||=[],i.concurrency||=1,i.maxPages||=0,i.extraReplacements=H(i.extraReplacements),i.postCrawlCopyMap=H(i.postCrawlCopyMap),i.logDir=String(i.logDir||"logs").trim()||"logs",i.verbose??=false,i.logLevel||=i.verbose?"debug":"info",i.s3SyncMode||="sdk-upload-delete",i.readiness||={waitForSelector:null,waitForFunction:null,timeoutMs:1500,fallbackWaitMs:1500},i.readiness.timeoutMs??=1500,i.readiness.fallbackWaitMs??=1500,i.viewport||={width:1440,height:1200},i.navigationTimeoutMs||=3e4,i.assetDownloadConcurrency=Number(i.assetDownloadConcurrency)>0?Number(i.assetDownloadConcurrency):i.concurrency,i.rewriteConcurrency=Number(i.rewriteConcurrency)>0?Number(i.rewriteConcurrency):i.assetDownloadConcurrency,i.wpsuite=Y(i.wpsuite),i.scheduler=ye(void 0),i.deploymentProfiles={},i.defaultDeploymentProfile="",i.deploymentTargetOverride=String(i.deploymentTargetOverride??"").trim();let a=await Ye(i);t.onRemotePublisherConfigDiagnostic?.(a.diagnostic);let s=Ze(i,a.remote),o=Xe(),u=o?m.resolve(o,".."):"";return u?(s.outputDir=he(u,s.outputDir,"export"),s.logDir=he(u,s.logDir,"logs")):(m.isAbsolute(s.outputDir)||(s.outputDir=G(s.outputDir,"export")),m.isAbsolute(s.logDir)||(s.logDir=G(s.logDir,"logs"))),s}function Ce(e){let t=String(e.command??"").trim();return (t==="publish"||t==="crawl")&&e.crawlMode==="incremental"||t==="content-sync"}var X=new Map;async function we(e){let t=m.resolve(e),n=X.get(t);if(n!==void 0)return n;try{let r=JSON.parse(await P.readFile(t,"utf8")),i=String(r.version??"").trim();return X.set(t,i),i}catch{return X.set(t,""),""}}var B=class extends Error{request;step;constructor(t,n){super(`Stop requested during ${n}.`),this.name="StopRequestedError",this.request=t,this.step=n;}},st="queue-mutation.lock",ot=5e3,at=3e4;function ut(e){let t=process.env.STATIC_PUBLISHER_RUNTIME_DIR||process.env.WPSUITE_STATIC_PUBLISHER_RUNTIME_DIR||"",n=process.env.STATIC_PUBLISHER_EXPORTER_DIR||process.cwd(),r=process.env.PUBLISHER_CONFIG||"",i=1;for(let o=0;o<e.length;o++){let u=e[o];u==="--runtime-dir"?t=e[++o]||"":u.startsWith("--runtime-dir=")?t=u.slice(14):u==="--exporter-dir"?n=e[++o]||n:u.startsWith("--exporter-dir=")?n=u.slice(15):u==="--config"?r=e[++o]||"":u.startsWith("--config=")?r=u.slice(9):u==="--max-jobs"?i=Number.parseInt(e[++o]||"1",10):u.startsWith("--max-jobs=")&&(i=Number.parseInt(u.slice(11),10));}if(!t)throw new Error("Missing runtime dir. Use --runtime-dir or STATIC_PUBLISHER_RUNTIME_DIR.");let a=m.resolve(t),s=r?m.resolve(r):m.join(a,"config.json");return {runtimeDir:a,exporterDir:m.resolve(n),configPath:s,maxJobs:Number.isFinite(i)&&i>0?i:1}}async function v(e,t){try{let n=await P.readFile(e,"utf8");return JSON.parse(n)}catch(n){if((n&&typeof n=="object"&&"code"in n?String(n.code||""):"")!=="ENOENT"){let i=n instanceof Error?n.message:String(n);console.warn(`[queue-runner] failed to read JSON ${e}: ${i}`);}return t}}async function w(e,t){await P.mkdir(m.dirname(e),{recursive:true}),await P.writeFile(e,JSON.stringify(t,null,2),"utf8");}function Ae(e){return m.join(e,st)}async function ct(e){await new Promise(t=>setTimeout(t,e));}async function lt(e){let t=Ae(e),n=Date.now()+ot;for(;;)try{await P.mkdir(m.dirname(t),{recursive:!0}),await P.writeFile(t,JSON.stringify({pid:process.pid,createdAt:new Date().toISOString()},null,2),{encoding:"utf8",flag:"wx"});return}catch(r){if((r&&typeof r=="object"&&"code"in r?String(r.code||""):"")!=="EEXIST")throw r;let a=await P.stat(t).catch(()=>null);if(a&&Date.now()-a.mtimeMs>at){await P.unlink(t).catch(()=>{});continue}if(Date.now()>=n)throw new Error("Timed out acquiring queue mutation lock.",{cause:r});await ct(50);}}async function dt(e){await P.unlink(Ae(e)).catch(()=>{});}async function E(e,t){await lt(e);try{return await t()}finally{await dt(e);}}function Ie(e){return m.join(e,"queue-runner-heartbeat.json")}function ae(e){return m.join(e,"current-progress.json")}function ee(e){return m.join(e,"scheduler-state.json")}function gt(e,t){let r=String(e||"").replace(/\\/g,"/").trim().replace(/^\/+|\/+$/g,"");if(!r)return t;let i=r.split("/").map(a=>a.trim()).filter(a=>a.length>0&&a!=="."&&a!=="..");return i.length>0?i.join("/"):t}async function Re(e){let t=await v(e.configPath||"",null),n=m.resolve(e.runtimeDir,".."),i=(typeof t?.logDir=="string"?t.logDir:"").trim();return i&&m.isAbsolute(i)?m.resolve(i):m.resolve(n,gt(i,"logs"))}function te(e,t){return String(e||"").trim().replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||t}function pt(e){let t=e?new Date(e):new Date;return (Number.isNaN(t.getTime())?new Date:t).toISOString().replace(/[-:]/g,"").replace(/\.\d{3}Z$/,"Z")}function mt(e){return [pt(e.endedAt||e.startedAt),te(e.command||"job","job"),te(e.id||"job","job"),te(e.status||"finished","finished")].join("-")}function ht(e){return e.endsWith(".log.jsonl")||e.endsWith(".errors.jsonl")||e.endsWith(".rejected.jsonl")?true:["current-crawl-event.json","rejected.jsonl","ignored.jsonl","skipped-http.jsonl","errors.jsonl","timings.jsonl","rejected.json","ignored.json","skipped-http.json","errors.json","timings.json"].includes(e)}function ft(e){return e==="errors.json"||e==="errors.jsonl"||e.endsWith(".errors.jsonl")?"errors":e==="ignored.json"||e==="ignored.jsonl"?"ignored":e==="rejected.json"||e==="rejected.jsonl"||e.endsWith(".rejected.jsonl")?"rejected":e==="skipped-http.json"||e==="skipped-http.jsonl"?"skipped-http":e==="timings.json"||e==="timings.jsonl"?"timings":e==="current-progress.json"?"current-progress":e==="current-crawl-event.json"?"current-crawl-event":e.endsWith(".log.jsonl")?e.replace(/\.log\.jsonl$/i,"-log"):e.replace(/\.[^.]+$/u,"")||"artifact"}function yt(e){return e.endsWith(".gz")?"application/gzip":e.endsWith(".jsonl")?"application/x-ndjson":e.endsWith(".json")?"application/json":"text/plain"}async function ne(e,t,n){let r=`${n}.gz`,i=m.join(t,r);await pipeline(createReadStream(e),createGzip({level:9}),createWriteStream(i));let[a,s]=await Promise.all([P.stat(e),P.stat(i)]);return {role:ft(n),originalFileName:n,storedFileName:r,compressed:true,compression:"gzip",contentType:yt(r),originalSize:a.size,storedSize:s.size}}async function $(e,t){let n=await Re(t),r=new Date().toISOString(),i=mt(e),a=m.join(n,"archive",i),s=[],o=[];await P.mkdir(a,{recursive:true});try{let d=await P.readdir(n,{withFileTypes:!0});for(let g of d){if(!g.isFile()||!ht(g.name))continue;let p=await ne(m.join(n,g.name),a,g.name);o.push(p),s.push(p.storedFileName);}}catch(d){if((d&&typeof d=="object"&&"code"in d?String(d.code||""):"")!=="ENOENT")throw d}let u=ae(t.runtimeDir);if(existsSync(u)){let d=await ne(u,a,"current-progress.json");o.push(d),s.push(d.storedFileName);}if(e.command==="content-sync")for(let d of ["content-sync-current.json","content-sync-impact-plan.json","content-sync-checkpoint.json","content-sync-state.json","content-sync-invalidation.json","deploy-plan.json"]){let g=m.join(t.runtimeDir,d);if(!existsSync(g))continue;let p=await ne(g,a,d);o.push(p),s.push(p.storedFileName);}let c=[...s,"job.json"];return await w(m.join(a,"job.json"),{manifestVersion:1,archivedAt:r,archiveKey:i,archiveDir:a,logDir:n,runtimeDir:t.runtimeDir,exporterDir:t.exporterDir,configPath:t.configPath||"",archivedFiles:c,artifacts:o,job:e}),{archiveKey:i,archiveDir:a,archiveCreatedAt:r,archivedFiles:c,artifacts:o}}function bt(e){return m.join(e,"audit-events.jsonl")}function se(e){return m.join(e,"stop-request.json")}async function qe(e){try{let t=await P.readFile(se(e),"utf8"),n=JSON.parse(t);return n&&typeof n=="object"?n:null}catch{return null}}async function ve(e,t){let n=await qe(e);if(!n)return null;let r=String(n.targetJobId||"").trim();return r&&r!==t?null:n}async function L(e,t){if(!t){await P.unlink(se(e)).catch(()=>{});return}let n=await qe(e);if(!n)return;let r=String(n.targetJobId||"").trim();(!r||r===t)&&await P.unlink(se(e)).catch(()=>{});}async function I(e,t){try{let n={occurredAt:t.occurredAt||new Date().toISOString(),status:t.status||"info",actorSource:t.actorSource||"queue-runner",...t};await P.mkdir(e,{recursive:!0}),await P.appendFile(bt(e),`${JSON.stringify(n)}
2
+ `,"utf8");}catch{}}async function C(e,t,n){let[r,i]=await Promise.all([we(m.join(e.exporterDir,"package.json")),we(m.join(e.exporterDir,"node_modules","@smart-cloud","wpsuite-core","package.json"))]),a={checkedAt:new Date().toISOString(),status:t,pid:process.pid,nodePath:process.execPath,nodeVersion:process.version,exporterVersion:r,wpsuiteCoreVersion:i,runtimeDir:e.runtimeDir,exporterDir:e.exporterDir,...n??{}};try{await w(Ie(e.runtimeDir),a);}catch{}}async function O(e){try{await P.unlink(ae(e));}catch{}}function St(e,t){let n=e.command;if(n!=="publish"&&n!=="crawl"&&n!=="deploy"&&n!=="invalidate"&&n!=="retry-timeouts"&&n!=="url"&&n!=="content-sync")return null;let r=Number.parseInt(String(e.intervalMinutes??"0"),10);if(!Number.isFinite(r)||r<1)return null;let i=(e.id||`${n}-${t+1}`).trim();if(!i)return null;let a=e.enabled!==false,s=typeof e.url=="string"?e.url.trim():"",o=typeof e.deploymentProfile=="string"?e.deploymentProfile.trim():"",u=Array.isArray(e.postTypes)?[...new Set(e.postTypes.map(g=>String(g).trim()).filter(Boolean))]:[],c=Array.isArray(e.listingPaths)?[...new Set(e.listingPaths.map(g=>String(g).trim()).filter(Boolean))]:[],d=(n==="publish"||n==="crawl")&&e.crawlMode==="incremental"?"incremental":"full";return n==="url"&&!s||n==="content-sync"&&u.length===0?null:{id:i,enabled:a,command:n,intervalMinutes:r,...n==="publish"||n==="crawl"?{crawlMode:d}:{},...(n==="publish"||n==="deploy"||n==="invalidate"||n==="content-sync")&&o?{deploymentProfile:o}:{},...s?{url:s}:{},...u.length>0?{postTypes:u}:{},...c.length>0?{listingPaths:c}:{},...typeof e.includeSubsites=="boolean"?{includeSubsites:e.includeSubsites}:{},...typeof e.includePostTypeArchives=="boolean"?{includePostTypeArchives:e.includePostTypeArchives}:{},...typeof e.includeTaxonomyArchives=="boolean"?{includeTaxonomyArchives:e.includeTaxonomyArchives}:{},...typeof e.includeAuthorArchives=="boolean"?{includeAuthorArchives:e.includeAuthorArchives}:{},...typeof e.includeDateArchives=="boolean"?{includeDateArchives:e.includeDateArchives}:{},...typeof e.includePostsPage=="boolean"?{includePostsPage:e.includePostsPage}:{},...typeof e.includeSitemapChain=="boolean"?{includeSitemapChain:e.includeSitemapChain}:{}}}async function wt(e){let t=await Z(e.configPath).catch(()=>null),n=t?.scheduler,r=Array.isArray(n?.rules)?n.rules.map((i,a)=>St(i,a)).filter(i=>!!i):[];return {enabled:!!n?.enabled,timezone:typeof n?.timezone=="string"&&n.timezone.trim()?n.timezone.trim():"UTC",rules:r,wpsuite:t?.wpsuite,publisherConfig:t}}function re(e,t){if(!t)throw new Error("Content-sync scheduler requires a valid publisher config.");let n=M({postTypes:e.postTypes??[],listingPaths:e.listingPaths??[],includeSubsites:e.includeSubsites,includePostTypeArchives:e.includePostTypeArchives,includeTaxonomyArchives:e.includeTaxonomyArchives,includeAuthorArchives:e.includeAuthorArchives,includeDateArchives:e.includeDateArchives,includePostsPage:e.includePostsPage,includeSitemapChain:e.includeSitemapChain}),r=_(t.sourceOrigin,e.id,n),i=z(t,e.deploymentProfile),a=K({sourceOrigin:t.sourceOrigin,targetOrigin:i.config.targetOrigin,deploymentProfile:i.name||"",s3Bucket:i.config.s3.bucket,s3Prefix:i.config.s3.prefix,cloudFrontDistributionId:i.config.cloudFront.distributionId,urlRewriteMode:i.config.urlRewriteMode,extraReplacements:i.profile?.extraReplacements??{}});return `content-sync:${e.id}:${J({scopeFingerprint:r,targetFingerprint:a}).slice(0,32)}`}async function vt(e,t,n,r,i){let s=(await v(m.join(e.runtimeDir,"content-sync-baseline.json"),{})).entries?.[r];if(!s?.consumerId||!s.scopeFingerprint||!s.baselineId)return {status:"baseline-required",reason:"No verified normal-release baseline exists for this rule scope."};try{let o=t.publisherConfig;if(!o)throw new Error("Publisher configuration is unavailable.");let u=M({postTypes:n.postTypes??[],listingPaths:n.listingPaths??[],includeSubsites:n.includeSubsites,includePostTypeArchives:n.includePostTypeArchives,includeTaxonomyArchives:n.includeTaxonomyArchives,includeAuthorArchives:n.includeAuthorArchives,includeDateArchives:n.includeDateArchives,includePostsPage:n.includePostsPage,includeSitemapChain:n.includeSitemapChain}),c=_(o.sourceOrigin,n.id,u),d=z(o,n.deploymentProfile),g=K({sourceOrigin:o.sourceOrigin,targetOrigin:d.config.targetOrigin,deploymentProfile:d.name||"",s3Bucket:d.config.s3.bucket,s3Prefix:d.config.s3.prefix,cloudFrontDistributionId:d.config.cloudFront.distributionId,urlRewriteMode:d.config.urlRewriteMode,extraReplacements:d.profile?.extraReplacements??{}});if(s.scopeFingerprint!==c||s.targetFingerprint!==g||!s.releaseFingerprint)return {status:"baseline-required",reason:"The verified content-sync baseline does not match the active scope or deployment target. Run a successful full or incremental publish to establish a new baseline."};let p=new U({sourceOrigin:o.sourceOrigin,runtimeToken:String(o.wpsuite?.runtimeToken||""),ignoreHttpsErrors:o.ignoreHttpsErrors}),h=await p.releaseFingerprint(u.includeSubsites),y=de({wordpressFingerprint:h,targetFingerprint:g,sourceOrigin:o.sourceOrigin,sitemapPaths:o.sitemapPaths,blockedPathPrefixes:o.blockedPathPrefixes,assetPathPrefixes:o.assetPathPrefixes,noJavaScriptRenderPathPrefixes:o.noJavaScriptRenderPathPrefixes,urlRewriteMode:o.urlRewriteMode});if(s.releaseFingerprint!==y)return {status:"baseline-required",reason:"The installed WordPress release changed after the last verified content-sync baseline. Run a successful full or incremental publish to establish a new baseline."};let l=await p.head({consumerId:s.consumerId,scopeFingerprint:s.scopeFingerprint,baselineId:s.baselineId,postTypes:u.postTypes,includeSubsites:u.includeSubsites}),b=l.committedSequence;if(i?.command==="content-sync"&&i.coalesceKey===r){let S=await v(m.join(e.runtimeDir,"content-sync-current.json"),null);S?.coalesceKey===r&&Number.isSafeInteger(S.toSequence)&&(b=Math.max(b,Number(S.toSequence)));}return {status:l.headSequence>b?"pending":"current",headSequence:l.headSequence,committedSequence:l.committedSequence}}catch(o){return o instanceof k&&o.code==="baseline-required"?{status:"baseline-required",reason:o.message}:{status:"unavailable",reason:o instanceof Error?o.message:String(o)}}}async function De(e,t,n,r,i,a){let s=m.join(e.runtimeDir,"content-sync-state.json"),u=(await v(s,{})).rules??{},c=u[n]??{};u[n]={...c,ruleId:t,coalesceKey:n,...Number.isSafeInteger(i)?{observedHeadSequence:i}:{},...Number.isSafeInteger(a)?{committedSequence:a}:{},retryAttempt:0,nextRetryAt:null,lastError:r,baselineStatus:"required",baselineReason:r,trailingWorkDetected:Number.isSafeInteger(i)&&Number.isSafeInteger(a)?Number(i)>Number(a):!!c.trailingWorkDetected},await w(s,{schemaVersion:1,updatedAt:new Date().toISOString(),rules:u});}function oe(e,t){let n=(t.url||"").trim(),r=t.crawlMode||"full",i=(t.deploymentProfile||"").trim(),a=(t.coalesceKey||"").trim();return e.some(s=>s.command===t.command&&(t.command!=="content-sync"||(s.coalesceKey||"").trim()===a)&&(s.url||"").trim()===n&&(s.crawlMode||"full")===r&&(s.deploymentProfile||"").trim()===i&&(s.status===void 0||s.status==="queued"||s.status==="retry-wait"||s.status==="running"))}async function Pt(e,t,n){if(!t.allowSchedulerAutoEnqueue)return 0;let r=await wt(e);if(!r.enabled||r.rules.length===0)return 0;if(t.assertActiveSubscriptionForIdentity)try{await t.assertActiveSubscriptionForIdentity(r.wpsuite??null);}catch(l){let b=l instanceof Error?l.message:String(l);return console.warn(`[queue-runner] scheduler auto-enqueue skipped: ${b}`),0}let i=m.join(e.runtimeDir,"queue.json"),a=m.join(e.runtimeDir,"current-run.json"),s=Date.now(),o=0,u=[],c=[],d=[],g=new Map,[p,h,y]=await Promise.all([v(i,[]),v(a,null),v(ee(e.runtimeDir),{lastEnqueuedBucketByRuleId:{},lastEvaluatedBucketByRuleId:{},lastCreatedBucketByRuleId:{},coalescedCountByRuleId:{}})]);for(let l of r.rules){if(!l.enabled||l.command!=="content-sync")continue;let b=Math.floor(s/(l.intervalMinutes*60*1e3)),S=y.lastEvaluatedBucketByRuleId?.[l.id]??y.lastEnqueuedBucketByRuleId?.[l.id]??-1;if(b<=S)continue;let D=re(l,r.publisherConfig);oe(p,{command:l.command,deploymentProfile:l.deploymentProfile,coalesceKey:D})||g.set(l.id,await vt(e,r,l,D,h));}await E(e.runtimeDir,async()=>{let l=await v(i,[]),b=await v(a,null),S=await v(ee(e.runtimeDir),{lastEnqueuedBucketByRuleId:{},lastEvaluatedBucketByRuleId:{},lastCreatedBucketByRuleId:{},coalescedCountByRuleId:{}});S.lastEnqueuedBucketByRuleId??={},S.lastEvaluatedBucketByRuleId??={...S.lastEnqueuedBucketByRuleId},S.lastCreatedBucketByRuleId??={...S.lastEnqueuedBucketByRuleId},S.coalescedCountByRuleId??={};let D=[...l];b&&b.status==="running"&&D.unshift(b);for(let f of r.rules){if(!f.enabled)continue;let A=f.intervalMinutes*60*1e3,q=Math.floor(s/A),F=S.lastEvaluatedBucketByRuleId[f.id]??S.lastEnqueuedBucketByRuleId[f.id]??-1;if(q<=F)continue;let j=f.command==="content-sync"?re(f,r.publisherConfig):"";S.lastEvaluatedBucketByRuleId[f.id]=q;let T=f.command==="content-sync"?l:D;if(oe(T,{command:f.command,url:f.url,crawlMode:f.crawlMode,deploymentProfile:f.deploymentProfile,coalesceKey:j})){S.coalescedCountByRuleId[f.id]=(S.coalescedCountByRuleId[f.id]??0)+1,c.push(f);continue}if(f.command==="content-sync"){let W=g.get(f.id);if(!W||W.status!=="pending"){let ce=W??{status:"unavailable",reason:"Content-sync demand was not checked."};ce.status!=="current"&&d.push({rule:f,check:ce});continue}}let Q={id:randomUUID(),command:f.command,...f.command==="content-sync"?{ruleId:f.id,coalesceKey:j,attempt:0}:{},...(f.command==="publish"||f.command==="crawl")&&f.crawlMode?{crawlMode:f.crawlMode}:{},...(f.command==="publish"||f.command==="deploy"||f.command==="invalidate"||f.command==="content-sync")&&f.deploymentProfile?{deploymentProfile:f.deploymentProfile}:{},...f.url?{url:f.url}:{},enqueueSource:"scheduler",...r.wpsuite?{wpsuite:r.wpsuite}:{},status:"queued",createdAt:new Date().toISOString(),createdBy:0};l.push(Q),D.push(Q),u.push({job:Q,rule:f}),S.lastEnqueuedBucketByRuleId[f.id]=q,S.lastCreatedBucketByRuleId[f.id]=q,o+=1;}o>0&&await w(i,l),await w(ee(e.runtimeDir),S);});for(let l of u){if(l.rule.command==="content-sync"){let b=g.get(l.rule.id);await I(e.runtimeDir,{eventType:"content-sync-demand-detected",status:"queued",actorSource:"queue-runner-scheduler",jobId:l.job.id,command:l.job.command,message:"Pending journal changes require a content-sync job.",details:{ruleId:l.rule.id,headSequence:b?.headSequence??0,committedSequence:b?.committedSequence??0}});}await I(e.runtimeDir,{eventType:"job-created",status:"queued",actorSource:"queue-runner-scheduler",jobId:l.job.id,command:l.job.command,message:"Scheduler auto-enqueued a job.",details:{ruleId:l.rule.id,intervalMinutes:l.rule.intervalMinutes,timezone:r.timezone,deploymentProfile:l.rule.deploymentProfile||"",url:l.rule.url||""}});}for(let l of c)await I(e.runtimeDir,{eventType:"content-sync-coalesced",status:"queued",actorSource:"queue-runner-scheduler",command:l.command,message:"Scheduler demand was coalesced into an existing content-sync job.",details:{ruleId:l.id}});for(let l of d){if(l.check.status==="baseline-required"){let b=re(l.rule,r.publisherConfig);await De(e,l.rule.id,b,l.check.reason||"A successful full or incremental publish must establish a new content-sync baseline.",l.check.headSequence,l.check.committedSequence);}await I(e.runtimeDir,{eventType:l.check.status==="baseline-required"?"content-sync-baseline-required":"content-sync-demand-check-failed",status:l.check.status==="unavailable"?"failed":"info",actorSource:"queue-runner-scheduler",command:"content-sync",message:l.check.reason||"The content-sync consumer is already at the current journal head.",details:{ruleId:l.rule.id,headSequence:l.check.headSequence??0,committedSequence:l.check.committedSequence??0}});}return o}async function Ct(e){let t={pid:process.pid,startedAt:new Date().toISOString()};await P.writeFile(e,JSON.stringify(t,null,2),{encoding:"utf8",flag:"wx"});}async function At(e){try{await P.unlink(e);}catch{}}function It(e,t){let n=[m.join(e,"dist",`${t}.js`),m.join(e,`${t}.js`)];for(let r of n)if(existsSync(r))return r;throw new Error(`Cannot find ${t}.js in ${m.join(e,"dist")} or ${e}`)}async function R(e,t,n,r,i,a,s){if(s){let c=await ve(t,s);if(c)throw new B(c,n)}let o=It(e,n),u={...process.env,...a??{}};return u.STATIC_PUBLISHER_RUNTIME_DIR=t,i&&(u.PUBLISHER_CONFIG=i),await new Promise((c,d)=>{let g=null,p=null,h=null,y=null,l=false,b="",S=spawn(process.execPath,[o,...r],{cwd:e,env:u,stdio:["inherit","inherit","pipe"]});S.stderr?.on("data",A=>{b+=A.toString("utf8");});let D=()=>{p&&clearInterval(p),h&&clearInterval(h),y&&clearTimeout(y);},f=async()=>{if(!(!s||g||l)){l=true;try{let A=await ve(t,s);if(!A)return;g=A,S.kill("SIGTERM"),y=setTimeout(()=>{S.kill("SIGKILL");},1e4);}finally{l=false;}}};s&&(p=setInterval(()=>{f();},1e3),h=setInterval(()=>{(async()=>{let A=Ie(t),q=await v(A,{});await w(A,{...q,checkedAt:new Date().toISOString(),status:"running",currentJobId:s||q.currentJobId||"",currentStep:n});})().catch(()=>{});},15e3)),S.on("error",A=>{D(),d(A);}),S.on("close",(A,q)=>{D();let F=pe(b).trim();if(F&&process.stderr.write(`${F}
3
+ `),g){d(new B(g,n));return}if(A===0)c();else {let j=F.split(/\r?\n/).map(T=>T.trim()).find(T=>T&&!T.startsWith("at "));d(new Error(`${n} exited with code ${A??-1}${q?` (signal ${q})`:""}${j?`: ${j}`:""}`));}});}),0}function Rt(e){let t=e.awsTempCreds;if(!t)return {};let n={};return typeof t.accessKeyId=="string"&&t.accessKeyId.trim()!==""&&(n.AWS_ACCESS_KEY_ID=t.accessKeyId.trim()),typeof t.secretAccessKey=="string"&&t.secretAccessKey.trim()!==""&&(n.AWS_SECRET_ACCESS_KEY=t.secretAccessKey.trim()),typeof t.sessionToken=="string"&&t.sessionToken.trim()!==""&&(n.AWS_SESSION_TOKEN=t.sessionToken.trim()),n}async function qt(e,t){let n=s=>{if(!s||typeof s!="object")return null;let o=s,u={...o.siteSettings??{},...String(o.accountId??"").trim()&&!o.siteSettings?.accountId?{accountId:String(o.accountId).trim()}:{},...String(o.siteId??"").trim()&&!o.siteSettings?.siteId?{siteId:String(o.siteId).trim()}:{},...o.siteSettings?.subscriber===true||o.subscriber===true?{subscriber:true}:{}},c={...String(o.apiBase??"").trim()?{apiBase:String(o.apiBase).trim()}:{},...String(o.runtimeToken??o.nonce??"").trim()?{runtimeToken:String(o.runtimeToken??o.nonce).trim()}:{},...String(o.virtualAssetBaseUrl??o.uploadUrl??"").trim()?{virtualAssetBaseUrl:String(o.virtualAssetBaseUrl??o.uploadUrl).trim()}:{},...Object.keys(u).length>0?{siteSettings:u}:{},...o.subscriptionType?{subscriptionType:o.subscriptionType}:{}};return Object.keys(c).length>0?c:null},r=await Z(t.configPath).catch(()=>null),i=n(r?.wpsuite);if(i)return i;let a=n(e.wpsuite);return a||null}async function Dt(e,t){return await qt(e,t)}function ue(e){let t={...e,status:"queued"};return delete t.startedAt,delete t.endedAt,delete t.exitCode,delete t.error,delete t.stopRequestedAt,delete t.stopRequestedByUserId,delete t.stopRequestedByLogin,delete t.stopMode,delete t.stoppedStep,t}async function xt(e,t){let n=await v(ae(e.runtimeDir),null),r=n&&n.details&&typeof n.details.phase=="string"?n.details.phase.trim():"";if(r)return r;let i=n&&typeof n.currentStep=="string"?n.currentStep.trim():"";if(i)return i;let a=await Re(e).catch(()=>"");if(a){let s=await v(m.join(a,"current-crawl-event.json"),null),o=s&&typeof s.currentStep=="string"?s.currentStep.trim():"";if(o)return o}return t}function Tt(e,t){if((e.command==="publish"||e.command==="crawl")&&t==="rewrite-text")return "rewrite-text"}async function kt(e){let t=m.join(e.runtimeDir,"queue.json"),n=m.join(e.runtimeDir,"current-run.json"),r=await E(e.runtimeDir,async()=>{let i=await v(n,null);if(!i||i.status!=="running"&&i.status!=="queued")return null;let a=await v(t,[]),s=Array.isArray(a)?a.filter(u=>u?.id!==i.id):[],o=ue(i);return await w(t,[o,...s]),await w(n,null),o});r&&(await L(e.runtimeDir,r.id),await I(e.runtimeDir,{eventType:"job-recovered",status:"queued",actorSource:"queue-runner",jobId:r.id,command:r.command,message:"Recovered stale current-run entry back into queue."}));}async function Et(e,t,n){try{if((n.shouldEnforceSubscriptionOnJobExecution?.(e)??n.enforceSubscriptionOnJobExecution)&&n.assertActiveSubscriptionForIdentity){let o=await Dt(e,t);await n.assertActiveSubscriptionForIdentity(o);}let i=Rt(e),a=e.resumeFromStep==="rewrite-text"?["--resume-rewrite"]:e.crawlMode==="incremental"?["--crawl-mode","incremental"]:[],s=e.deploymentProfile?["--profile",e.deploymentProfile]:[];if(e.command==="publish")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"content-sync-release-cutoff"}),await R(t.exporterDir,t.runtimeDir,"content-sync",["--capture-baseline-cutoffs",e.id],t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:e.resumeFromStep==="rewrite-text"?"rewrite-text":"crawl"}),await R(t.exporterDir,t.runtimeDir,"crawl",a,t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"deploy"}),await R(t.exporterDir,t.runtimeDir,"deploy",s,t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"invalidate"}),await R(t.exporterDir,t.runtimeDir,"invalidate",s,t.configPath,i,e.id),await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"content-sync-baseline"}),await R(t.exporterDir,t.runtimeDir,"content-sync",["--establish-baselines",e.id],t.configPath,i,e.id),{exitCode:0};if(e.command==="crawl")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:e.resumeFromStep==="rewrite-text"?"rewrite-text":"crawl"}),await R(t.exporterDir,t.runtimeDir,"crawl",a,t.configPath,i,e.id),{exitCode:0};if(e.command==="deploy")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"deploy"}),await R(t.exporterDir,t.runtimeDir,"deploy",s,t.configPath,i,e.id),{exitCode:0};if(e.command==="invalidate")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"invalidate"}),await R(t.exporterDir,t.runtimeDir,"invalidate",s,t.configPath,i,e.id),{exitCode:0};if(e.command==="retry-timeouts")return await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"retry-timeouts"}),await R(t.exporterDir,t.runtimeDir,"crawl",["--retry-timeouts"],t.configPath,i,e.id),{exitCode:0};if(e.command==="url"){let o=(e.url||"").trim();return o?(await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"url"}),await R(t.exporterDir,t.runtimeDir,"crawl",["--url",o],t.configPath,i,e.id),{exitCode:0}):{exitCode:2,error:"Missing url for command 'url'"}}return e.command==="content-sync"?!e.ruleId||!e.coalesceKey?{exitCode:2,error:"Content-sync queue jobs require ruleId and coalesceKey."}:(await C(t,"running",{currentJobId:e.id,currentJobCommand:e.command,currentStep:"content-sync"}),await R(t.exporterDir,t.runtimeDir,"content-sync",["--job-id",e.id],t.configPath,i,e.id),{exitCode:0}):{exitCode:2,error:`Unsupported command: ${e.command}`}}catch(r){return r instanceof B?{exitCode:130,error:"Job stop requested.",stopped:true,stopRequest:r.request,stoppedStep:r.step}:{exitCode:1,error:r instanceof Error?r.message:String(r)}}}function xe(e){return async function(n=process.argv.slice(2)){let r=ut(n),i=m.join(r.runtimeDir,"export.lock"),a=m.join(r.runtimeDir,"last-run.json");await O(r.runtimeDir),await C(r,"starting",{message:"queue-runner starting"});try{await Ct(i);}catch(s){if((s&&typeof s=="object"&&"code"in s?String(s.code||""):"")!=="EEXIST")throw s;console.log("[queue-runner] lock active, skipping"),await C(r,"lock-active",{message:"lock active, skipped this cron tick"});return}try{await kt(r);let s=await Pt(r,e),o=0;for(let u=0;u<r.maxJobs;u++){let c=await Lt(r,e);if(c==="none"||(o+=1,c==="stopped"))break}if(o===0)await O(r.runtimeDir),await C(r,"idle",{processedJobs:o,schedulerEnqueued:s,message:"no queued jobs"});else {await O(r.runtimeDir);let u=await v(a,null),c=String(u?.status||"").trim();await C(r,c==="success"?"job-success":c==="stopped"?"job-stopped":"job-failed",{processedJobs:o,schedulerEnqueued:s,lastJobId:u?.id,lastJobCommand:u?.command,lastJobStatus:u?.status,lastJobExitCode:u?.exitCode,lastJobError:u?.error,...c==="stopped"?{currentStep:u?.stoppedStep,stopRequestedAt:u?.stopRequestedAt,stopRequestedByLogin:u?.stopRequestedByLogin,stopRequestedMode:u?.stopMode,lastStoppedStep:u?.stoppedStep,message:u?.stopMode==="requeue"?`Job stopped during ${u?.stoppedStep||u?.command||"active step"} and requeued.`:`Job stopped during ${u?.stoppedStep||u?.command||"active step"} and left out of queue.`}:{}});}}catch(s){let o=s instanceof Error?s.message:String(s);throw await C(r,"error",{message:o}),await I(r.runtimeDir,{eventType:"queue-runner-error",status:"failed",actorSource:"queue-runner",message:"Unhandled queue-runner error.",details:{error:o}}),s}finally{await At(i);}}}async function Ft(e,t,n){let r=m.join(e.runtimeDir,"queue.json"),i=m.join(e.runtimeDir,"current-run.json");await E(e.runtimeDir,async()=>{let a=await v(r,[]),s=Array.isArray(a)?a.filter(c=>c?.id!==t.id):[],o=ue(t),u=Tt(t,n);u?o.resumeFromStep=u:delete o.resumeFromStep,await w(r,[o,...s]),await w(i,null);});}async function jt(e,t,n){let r=Math.max(0,t.attempt??0)+1,i=Math.min(3600*1e3,6e4*2**(r-1)),a=Math.floor(i*.2*Math.random()),s=new Date(Date.now()+i+a).toISOString(),o={...ue(t),status:"retry-wait",attempt:r,nextAttemptAt:s,error:n};if(await E(e.runtimeDir,async()=>{let u=m.join(e.runtimeDir,"queue.json"),c=m.join(e.runtimeDir,"current-run.json"),g=(await v(u,[])).filter(p=>p.id!==t.id);await w(u,[o,...g]),await w(c,null);}),t.coalesceKey){let u=m.join(e.runtimeDir,"content-sync-state.json"),d=(await v(u,{})).rules??{};d[t.coalesceKey]={...d[t.coalesceKey]??{},ruleId:t.ruleId||"",coalesceKey:t.coalesceKey,retryAttempt:r,nextRetryAt:s,lastError:n,trailingWorkDetected:true},await w(u,{schemaVersion:1,updatedAt:new Date().toISOString(),rules:d});}return o}async function Jt(e,t){if(!t.coalesceKey||!t.ruleId||!(await v(m.join(e.runtimeDir,"content-sync-state.json"),null))?.rules?.[t.coalesceKey]?.trailingWorkDetected)return null;let r=null;await E(e.runtimeDir,async()=>{let a=m.join(e.runtimeDir,"queue.json"),s=await v(a,[]);oe(s,{command:"content-sync",coalesceKey:t.coalesceKey,deploymentProfile:t.deploymentProfile})||(r={id:randomUUID(),command:"content-sync",ruleId:t.ruleId,coalesceKey:t.coalesceKey,deploymentProfile:t.deploymentProfile,enqueueSource:"scheduler",wpsuite:t.wpsuite,status:"queued",attempt:0,createdAt:new Date().toISOString(),createdBy:0},await w(a,[...s,r]));});let i=r;return i&&await I(e.runtimeDir,{eventType:"content-sync-trailing-job-created",status:"queued",actorSource:"queue-runner",jobId:i.id,command:i.command,message:"Content changes after the stable cutoff created one trailing job.",details:{predecessorJobId:t.id,ruleId:t.ruleId,coalesceKey:t.coalesceKey}}),i}async function Lt(e,t){let n=m.join(e.runtimeDir,"queue.json"),r=m.join(e.runtimeDir,"current-run.json"),i=m.join(e.runtimeDir,"last-run.json"),a=new Date().toISOString(),s=await E(e.runtimeDir,async()=>{let g=await v(n,[]);if(!Array.isArray(g)||g.length===0)return null;let p=Date.parse(String(g[0]?.nextAttemptAt||""));if(Number.isFinite(p)&&p>Date.now())return null;let h={...g[0],status:"running",startedAt:a};return delete h.nextAttemptAt,await w(n,g.slice(1)),await w(r,h),h});if(!s)return "none";await O(e.runtimeDir),await I(e.runtimeDir,{eventType:"job-run-started",status:"running",actorSource:"queue-runner",jobId:s.id,command:s.command,message:"Job execution started.",details:{createdAt:s.createdAt||"",startedAt:a,createdBy:s.createdBy??null,deploymentProfile:s.deploymentProfile||"",queuedWithTempAwsCreds:!!s.awsTempCreds}}),await C(e,"running",{currentJobId:s.id,currentJobCommand:s.command,currentStep:s.command});let o=await Et(s,e,t),u=new Date().toISOString();if(o.stopped){let g=await xt(e,o.stoppedStep||s.command),p=o.stopRequest?.mode==="requeue"?"requeue":"stop",h={...s,status:"stopped",endedAt:u,exitCode:o.exitCode,...o.error?{error:o.error}:{},stopRequestedAt:o.stopRequest?.requestedAt||"",stopRequestedByUserId:typeof o.stopRequest?.requestedByUserId=="number"?o.stopRequest.requestedByUserId:null,stopRequestedByLogin:o.stopRequest?.requestedByLogin||"",stopMode:p,stoppedStep:g};p==="requeue"?await Ft(e,s,g):await w(r,null);try{let y=await $(h,e);h.logArchiveDir=y.archiveDir,h.logArchiveCreatedAt=y.archiveCreatedAt,h.logArchiveFileCount=y.archivedFiles.length;}catch(y){h.logArchiveError=y instanceof Error?y.message:String(y);}return await w(i,h),await L(e.runtimeDir,s.id),await O(e.runtimeDir),await I(e.runtimeDir,{eventType:"job-run-stopped",status:"stopped",actorSource:"queue-runner",jobId:s.id,command:s.command,message:p==="requeue"?"Job stop requested and requeued.":"Job stop requested and removed from active execution without requeue.",details:{startedAt:s.startedAt||"",endedAt:u,deploymentProfile:s.deploymentProfile||"",stopMode:p,stopRequestedAt:o.stopRequest?.requestedAt||"",stopRequestedByLogin:o.stopRequest?.requestedByLogin||"",stopRequestedByUserId:typeof o.stopRequest?.requestedByUserId=="number"?o.stopRequest.requestedByUserId:null,stoppedStep:g,logArchiveKey:h.logArchiveError||!h.logArchiveDir?"":m.basename(h.logArchiveDir),logArchiveDir:h.logArchiveDir||"",logArchiveCreatedAt:h.logArchiveCreatedAt||"",logArchiveFileCount:h.logArchiveFileCount??0,logArchiveError:h.logArchiveError||""}}),"stopped"}if(s.command==="content-sync"&&o.exitCode!==0){if(/baseline (?:is missing or stale|required)|verified content-sync baseline|new baseline/i.test(o.error||"")){let y="The installed release no longer matches the verified content-sync baseline. Run a successful full or incremental publish to establish a new baseline.";s.ruleId&&s.coalesceKey&&await De(e,s.ruleId,s.coalesceKey,y);let l={...s,status:"failed",endedAt:u,exitCode:o.exitCode,error:y};try{let b=await $(l,e);l.logArchiveDir=b.archiveDir,l.logArchiveCreatedAt=b.archiveCreatedAt,l.logArchiveFileCount=b.archivedFiles.length;}catch(b){l.logArchiveError=b instanceof Error?b.message:String(b);}return await w(i,l),await L(e.runtimeDir,s.id),await I(e.runtimeDir,{eventType:"content-sync-baseline-required",status:"failed",actorSource:"queue-runner",jobId:s.id,command:s.command,message:y,details:{ruleId:s.ruleId||"",retryScheduled:false}}),"processed"}await I(e.runtimeDir,{eventType:"content-sync-failed",status:"failed",actorSource:"queue-runner",jobId:s.id,command:s.command,message:"Content-sync execution failed before cursor acknowledgement.",details:{attempt:s.attempt??0,error:o.error||"Content-sync execution failed."}});let p=await jt(e,s,o.error||"Content-sync execution failed."),h={...s,status:"retry-wait",endedAt:u,exitCode:o.exitCode,error:p.error,attempt:p.attempt,nextAttemptAt:p.nextAttemptAt};try{let y=await $(h,e);h.logArchiveDir=y.archiveDir,h.logArchiveCreatedAt=y.archiveCreatedAt,h.logArchiveFileCount=y.archivedFiles.length;}catch(y){h.logArchiveError=y instanceof Error?y.message:String(y);}return await w(i,h),await L(e.runtimeDir,s.id),await I(e.runtimeDir,{eventType:"content-sync-retry-scheduled",status:"retry-wait",actorSource:"queue-runner",jobId:s.id,command:s.command,message:"Content-sync retry was scheduled with bounded backoff.",details:{attempt:p.attempt??0,nextAttemptAt:p.nextAttemptAt||"",error:p.error||""}}),"processed"}let c={...s,status:o.exitCode===0?"success":"failed",endedAt:u,exitCode:o.exitCode,...o.error?{error:o.error}:{}};await w(r,null),c.status==="success"&&c.command==="content-sync"&&await Jt(e,c),await L(e.runtimeDir,s.id);try{let g=await $(c,e);c.logArchiveDir=g.archiveDir,c.logArchiveCreatedAt=g.archiveCreatedAt,c.logArchiveFileCount=g.archivedFiles.length;}catch(g){c.logArchiveError=g instanceof Error?g.message:String(g);}await w(i,c);let d=s.startedAt&&c.endedAt?Math.max(0,Math.round((new Date(c.endedAt).getTime()-new Date(s.startedAt).getTime())/1e3)):void 0;return await I(e.runtimeDir,{eventType:"job-run-finished",status:c.status==="success"?"success":"failed",actorSource:"queue-runner",jobId:c.id,command:c.command,message:c.status==="success"?"Job execution finished successfully.":"Job execution finished with failure.",details:{startedAt:s.startedAt||"",endedAt:c.endedAt||"",durationSec:d,deploymentProfile:c.deploymentProfile||"",exitCode:c.exitCode??null,error:c.error||"",logArchiveKey:c.logArchiveError||!c.logArchiveDir?"":m.basename(c.logArchiveDir),logArchiveDir:c.logArchiveDir||"",logArchiveCreatedAt:c.logArchiveCreatedAt||"",logArchiveFileCount:c.logArchiveFileCount??0,logArchiveError:c.logArchiveError||""}}),"processed"}async function Bt(){throw new Error("Incremental and content-sync jobs require the premium Publisher runtime with an active Professional or Agency subscription.")}var Mt={allowSchedulerAutoEnqueue:false,enforceSubscriptionOnJobExecution:false,shouldEnforceSubscriptionOnJobExecution:e=>Ce(e),assertActiveSubscriptionForIdentity:Bt},Te=xe(Mt),Ut=Te,wn=Te;process.argv[1]&&import.meta.url===pathToFileURL(process.argv[1]).href&&Ut().catch(e=>{console.error(e),process.exit(1);});export{wn as default,Ut as main,Te as runQueueRunner};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/publisher-exporter",
3
- "version": "1.1.45",
3
+ "version": "1.1.46",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Headless Playwright static publisher for WordPress/Elementor sites with sitemap-only page discovery, strict asset capture, escaped URL rewrite, structured logs, and targeted retry modes.",