← back to Dwjs Consolidation 2026 04 23

hollywood_archived_audit.js

69 lines

// Pull ALL archived Hollywood Wallcoverings → score reactivation eligibility.
const fs=require('fs');
const TOKEN=(process.env.SHOPIFY_ADMIN_TOKEN || '');
const SHOP='designer-laboratory-sandbox.myshopify.com';
const API=`https://${SHOP}/admin/api/2024-10/graphql.json`;

async function gql(q,vars){
  const r=await fetch(API,{method:'POST',headers:{'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'},body:JSON.stringify({query:q,variables:vars})});
  return r.json();
}

(async()=>{
  console.log('Fetching archived Hollywood Wallcoverings...');
  const all=[];
  let cursor=null;
  while(true){
    const q=`query($c:String){
      products(first:100, after:$c, query:"vendor:'Hollywood Wallcoverings' status:archived"){
        pageInfo{hasNextPage endCursor}
        nodes{
          id title status totalInventory createdAt updatedAt bodyHtml
          variants(first:5){nodes{sku price compareAtPrice inventoryQuantity inventoryItem{tracked}}}
          images(first:1){nodes{url}}
          mfr:metafield(namespace:"custom",key:"manufacturer_sku"){value}
        }
      }
    }`;
    const j=await gql(q,{c:cursor});
    if(!j.data){console.log('err',JSON.stringify(j).slice(0,300));break;}
    all.push(...j.data.products.nodes);
    if(!j.data.products.pageInfo.hasNextPage)break;
    cursor=j.data.products.pageInfo.endCursor;
    process.stdout.write(`  ${all.length}\r`);
  }
  console.log(`\n${all.length} archived total\n`);

  const eligible=[], skipNoImg=[], skipNoBolt=[], skipNoSample=[], skipNoBody=[], skipNoPrice=[];
  for(const p of all){
    const variants=p.variants.nodes;
    const bolt=variants.find(v=>!/-sample$/i.test(v.sku||''));
    const sample=variants.find(v=>/-sample$/i.test(v.sku||''));
    const hasImg=p.images.nodes.length>0;
    const hasBody=(p.bodyHtml||'').replace(/<[^>]+>/g,'').trim().length>20;
    const boltPriced=bolt && parseFloat(bolt.price)>0;
    const samplePriced=sample && parseFloat(sample.price)>0;

    if(!hasImg){skipNoImg.push(p);continue;}
    if(!bolt){skipNoBolt.push(p);continue;}
    if(!sample){skipNoSample.push(p);continue;}
    if(!boltPriced||!samplePriced){skipNoPrice.push(p);continue;}
    if(!hasBody){skipNoBody.push(p);continue;}
    eligible.push(p);
  }

  console.log('Reactivation eligibility:');
  console.log(`  ELIGIBLE (all gates pass): ${eligible.length}`);
  console.log(`  skip — no image:           ${skipNoImg.length}`);
  console.log(`  skip — no bolt variant:    ${skipNoBolt.length}`);
  console.log(`  skip — no sample variant:  ${skipNoSample.length}`);
  console.log(`  skip — bolt or sample $0:  ${skipNoPrice.length}`);
  console.log(`  skip — no body:            ${skipNoBody.length}`);

  fs.writeFileSync('/Users/macstudio3/Projects/dwjs-consolidation-2026-04-23/hollywood_eligible.json',
    JSON.stringify(eligible.map(p=>({id:p.id,title:p.title,sku:p.variants.nodes[0]?.sku})),null,2));
  fs.writeFileSync('/Users/macstudio3/Projects/dwjs-consolidation-2026-04-23/hollywood_archived_skips.json',
    JSON.stringify({skipNoImg:skipNoImg.length,skipNoBolt:skipNoBolt.length,skipNoSample:skipNoSample.length,skipNoPrice:skipNoPrice.length,skipNoBody:skipNoBody.length},null,2));
  console.log(`\nWrote ${eligible.length} eligible IDs to hollywood_eligible.json`);
})();