← back to Designer Wallcoverings

audits/designtex-uom-fix/verify-step3.mjs

40 lines

import fs from 'fs'; import os from 'os'; import path from 'path';
const TOK = fs.readFileSync(path.join(os.homedir(),'Projects/secrets-manager/.env'),'utf8').match(/^SHOPIFY_ADMIN_TOKEN=(.+)$/m)[1].trim();
const DOMAIN='designer-laboratory-sandbox.myshopify.com', VER='2024-10';
async function gql(q,v){for(let a=0;a<6;a++){const r=await fetch(`https://${DOMAIN}/admin/api/${VER}/graphql.json`,{method:'POST',headers:{'X-Shopify-Access-Token':TOK,'Content-Type':'application/json'},body:JSON.stringify({query:q,variables:v})});const j=await r.json();if(j.errors&&/throttl/i.test(JSON.stringify(j.errors))){await new Promise(x=>setTimeout(x,3000));continue;}return j;}return{};}
// full sweep: count specs presence + prose residue across all live DWDX
const q=`query($c:String){
  products(first:40, after:$c, query:"vendor:Designtex"){
    pageInfo{ hasNextPage endCursor }
    edges{ node{
      id title descriptionHtml
      gr: metafield(namespace:"global", key:"repeat"){ value }
      gm: metafield(namespace:"global", key:"material"){ value }
      gf: metafield(namespace:"global", key:"FLAMMABILITY"){ value }
      gc: metafield(namespace:"global", key:"Cleaning-Code"){ value }
      sr: metafield(namespace:"specs", key:"fire_rating"){ value }
      sm: metafield(namespace:"specs", key:"material_type"){ value }
      variants(first:4){ edges{ node{ sku } } }
    } }
  }
}`;
let c=null, dwdx=0, hasGlobalContent=0, hasGlobalFire=0, hasGlobalCare=0, hasSpecsFire=0, proseRoll=0; const samples=[];
while(true){
  const j=await gql(q,{c}); const pr=j.data&&j.data.products; if(!pr){console.log('err',JSON.stringify(j).slice(0,200));break;}
  for(const e of pr.edges){const p=e.node;
    const skus=(p.variants?.edges||[]).map(v=>v.node.sku).filter(Boolean);
    if(!skus.some(s=>/^DWDX-/i.test(s))) continue; dwdx++;
    if(p.gm?.value) hasGlobalContent++;
    if(p.gf?.value) hasGlobalFire++;
    if(p.gc?.value) hasGlobalCare++;
    if(p.sr?.value) hasSpecsFire++;
    if(/single\s+roll/i.test(p.descriptionHtml||'')) proseRoll++;
    if(samples.length<4 && p.gm?.value) samples.push({title:p.title, repeat:p.gr?.value||'(solid)', material:(p.gm?.value||'').slice(0,40), fire_global:!!p.gf?.value, care_global:!!p.gc?.value, fire_specs:!!p.sr?.value});
  }
  if(!pr.pageInfo.hasNextPage)break; c=pr.pageInfo.endCursor; await new Promise(x=>setTimeout(x,250));
}
console.log(`live DWDX scanned=${dwdx}`);
console.log(`global.material set=${hasGlobalContent}  global.FLAMMABILITY set=${hasGlobalFire}  global.Cleaning-Code set=${hasGlobalCare}  specs.fire_rating set=${hasSpecsFire}`);
console.log(`prose still 'single roll'=${proseRoll}`);
console.log('SAMPLES:'); samples.forEach(s=>console.log('  ',JSON.stringify(s)));