← back to Novasuede Min Fix
recheck.mjs
18 lines
import fs from 'fs';
const env=fs.readFileSync(process.env.HOME+'/Projects/secrets-manager/.env','utf8');
const get=k=>(env.match(new RegExp('^'+k+'=(.*)$','m'))||[])[1];
const TOKEN=get('SHOPIFY_ADMIN_TOKEN');
const API='https://designer-laboratory-sandbox.myshopify.com/admin/api/2024-10/graphql.json';
async function gql(q,v={}){for(let a=0;a<5;a++){const r=await fetch(API,{method:'POST',headers:{'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'},body:JSON.stringify({query:q,variables:v})});const j=await r.json();if(j.data&&j.data.products)return j;await new Promise(x=>setTimeout(x,2000));}throw new Error('fail');}
// use direct metafield lookup by identifier instead of paging metafields
let cursor=null, all=[], notFive=[];
do{
const j=await gql(`query($c:String){products(first:40,after:$c,query:"vendor:Novasuede status:active"){pageInfo{hasNextPage endCursor} nodes{id title
mf: metafield(namespace:"global", key:"v_prods_quantity_order_min"){value}}}}`,{c:cursor});
const d=j.data; all.push(...d.products.nodes); cursor=d.products.pageInfo.hasNextPage?d.products.pageInfo.endCursor:null;
}while(cursor);
let five=0;
for(const p of all){ if(p.mf&&p.mf.value==='5')five++; else notFive.push({title:p.title,val:p.mf?p.mf.value:'(null)'}); }
console.log('TOTAL:',all.length,' product-level min=5:',five,' NOT 5:',notFive.length);
console.log(notFive.slice(0,10));