← back to Dw Yolo Loop

scripts/gmc-verify/gmc-verify.mjs

28 lines

import fs from 'fs';
const T=(fs.readFileSync(process.env.HOME+'/Projects/secrets-manager/.env','utf8').match(/^SHOPIFY_ADMIN_TOKEN=(.+)$/m)||[])[1];
const API='https://designer-laboratory-sandbox.myshopify.com/admin/api/2024-10/graphql.json';
const GOOG='gid://shopify/Publication/29646651457';
const sleep=ms=>new Promise(r=>setTimeout(r,ms));
async function gql(q,v){for(let a=0;a<6;a++){const r=await fetch(API,{method:'POST',headers:{'X-Shopify-Access-Token':T,'Content-Type':'application/json'},body:JSON.stringify({query:q,variables:v||{}})});if(r.status===429){await sleep(2000);continue;}const j=await r.json();if(j.errors&&JSON.stringify(j.errors).match(/THROTTLED/)){await sleep(2000);continue;}return j;}throw new Error('throttled');}
// 1) sample 20 ACTIVE products whose min-variant <=4.25 → should now be OFF Google
let j=await gql(`{products(first:60,query:"status:active"){nodes{handle onGoogle:publishedOnPublication(publicationId:"${GOOG}") variants(first:60){nodes{price}}}}}`);
let sample425=[], sampleReal=[];
for(const p of j.data.products.nodes){
  const mn=Math.min(...p.variants.nodes.map(v=>parseFloat(v.price)).filter(x=>!isNaN(x)));
  if(mn<=4.25 && sample425.length<20) sample425.push(p);
  else if(mn>4.25 && sampleReal.length<15) sampleReal.push(p);
}
const offGoogle425=sample425.filter(p=>!p.onGoogle).length;
const stillOnReal=sampleReal.filter(p=>p.onGoogle).length;
console.log(`=== GMC exclusion verification (live) ===`);
console.log(`$4.25 sample (n=${sample425.length}): OFF Google = ${offGoogle425}/${sample425.length}  ${offGoogle425===sample425.length?'✅ all excluded':'⚠️ some still on'}`);
console.log(`real-priced sample (n=${sampleReal.length}): STILL on Google = ${stillOnReal}/${sampleReal.length}  ${stillOnReal===sampleReal.length?'✅ all retained':'⚠️ some dropped'}`);
// 2) catalog-wide count: how many $4.25 still on Google (should be ~0)
let cur=null,on425=0,scanned=0,pages=0;
do{ const d=await gql(`query($c:String){products(first:150,after:$c,query:"status:active"){pageInfo{hasNextPage endCursor} nodes{onGoogle:publishedOnPublication(publicationId:"${GOOG}") variants(first:60){nodes{price}}}}}`,{c:cur});
  for(const p of d.products?.nodes||d.data.products.nodes){ scanned++; const mn=Math.min(...p.variants.nodes.map(v=>parseFloat(v.price)).filter(x=>!isNaN(x))); if(mn<=4.25 && p.onGoogle) on425++; }
  pages++; const pg=d.data?d.data.products:d.products; cur=pg.pageInfo.hasNextPage?pg.pageInfo.endCursor:null; if(pages%80===0)process.stderr.write(`  ...${scanned} scanned, still-on=${on425}\n`);
}while(cur);
console.log(`\ncatalog-wide: ${scanned} active scanned | $4.25-still-on-Google = ${on425} (target ~0)`);
fs.writeFileSync(process.env.HOME+'/.claude/yolo-queue/gmc-verify-2026-06-16.json',JSON.stringify({sample425:sample425.length,offGoogle425,sampleReal:sampleReal.length,stillOnReal,scanned,still_on_425:on425},null,2));