← back to Tk 10965 Zero Price Analysis
evidence/tk10965_probe.mjs
23 lines
import fs from 'node:fs';
const env=fs.readFileSync('/Users/macstudio3/Projects/secrets-manager/.env','utf8');
const val=k=>(env.match(new RegExp('^'+k+'=(.*)$','m'))||[])[1]?.trim();
const DOM=val('SHOPIFY_STORE_DOMAIN'), TOK=val('SHOPIFY_ADMIN_TOKEN');
const API=`https://${DOM}/admin/api/2024-10/graphql.json`;
async function gql(q,v){for(let a=0;a<6;a++){const r=await fetch(API,{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){if(JSON.stringify(j.errors).includes('THROTTLED')){await new Promise(s=>setTimeout(s,1500*(a+1)));continue;}throw new Error(JSON.stringify(j.errors));}return j.data;}throw new Error('retries');}
const Q=`query($id:ID!){product(id:$id){title vendor tags totalInventory tracksInventory variants(first:20){nodes{title price availableForSale inventoryPolicy inventoryQuantity inventoryItem{tracked}}}}}`;
async function show(label,gid){
const d=await gql(Q,{id:gid});
const p=d.product; if(!p){console.log(`\n### ${label}: NOT FOUND ${gid}`);return;}
console.log(`\n### ${label}: ${p.title} [${p.vendor}]`);
console.log(` tags: ${p.tags.join(', ')}`);
for(const v of p.variants.nodes){
console.log(` - "${v.title}" price=${v.price} afs=${v.availableForSale} policy=${v.inventoryPolicy} qty=${v.inventoryQuantity} tracked=${v.inventoryItem?.tracked}`);
}
}
const g=id=>`gid://shopify/Product/${id}`;
await show('PR-FLAGGED', g('7896453414963')); // Vienna It's Electric Twist & Shout
await show('FENTUCCI-$0ROLL', g('7896848072755')); // Fasano
// live-fetch a De Gournay quote-only reference
const s=await gql(`query{products(first:1,query:"status:active AND vendor:'De Gournay'"){nodes{id title}}}`,{});
if(s.products.nodes[0]) await show('DEGOURNAY-REF', s.products.nodes[0].id);