← back to Designer Wallcoverings
audits/designtex-uom-fix/verify-uom-3-followup.mjs
21 lines
#!/usr/bin/env node
// Read-only verify for the 3 follow-up Designtex SKUs. Expect uom_drift: 0 after the flip.
import fs from 'fs'; import os from 'os'; import path from 'path';
const env = fs.readFileSync(path.join(os.homedir(),'Projects/secrets-manager/.env'),'utf8');
const tok = env.match(/^SHOPIFY_ADMIN_TOKEN=(.+)$/m)[1].trim();
const DOMAIN='designer-laboratory-sandbox.myshopify.com', VER='2024-10';
const gql=(q,v)=>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})}).then(r=>r.json());
const gids=['gid://shopify/Product/7869010870323','gid://shopify/Product/7869010935859','gid://shopify/Product/7869010968627'];
const q=`query($id:ID!){product(id:$id){status uom:metafield(namespace:"global",key:"unit_of_measure"){value} variants(first:5){edges{node{title sku}}} tags}}`;
let yard=0,drift=0,still=[];
for(const id of gids){
const r=await gql(q,{id}); const p=r.data?.product;
const u=(p?.uom?.value||'').toUpperCase();
const ok = u==='YARD' || u.includes('YARD');
if(ok)yard++; else {drift++; still.push({id,uom:p?.uom?.value});}
const prod=p.variants.edges.find(e=>!/sample/i.test(e.node.title));
console.log(`${prod?.node.sku} | ${p.status} | uom='${p.uom?.value}' | rollTag=${p.tags.includes('Priced Per Single Roll')}`);
}
console.log(`\nchecked: ${gids.length} | uom_YARD: ${yard} | uom_drift: ${drift} | stillDrift: ${JSON.stringify(still)}`);
process.exit(drift?1:0);