← back to Designerwallcoverings
scripts/ai-preamble-leak-sweep/broad-net-bound.mjs
29 lines
import fs from 'fs';
const ENV=fs.readFileSync('/Users/stevestudio2/Projects/secrets-manager/.env','utf8');
const TOK=((ENV.match(/^SHOPIFY_ADMIN_TOKEN=(.+)$/m)||[])[1]||'').replace(/['"\r]/g,'').trim();
const GQL='https://designer-laboratory-sandbox.myshopify.com/admin/api/2024-10/graphql.json';
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(GQL,{method:'POST',headers:{'X-Shopify-Access-Token':TOK,'Content-Type':'application/json'},body:JSON.stringify({query:q,variables:v})});if(r.status===429||r.status>=500){await sleep(2000*(a+1));continue;}const j=await r.json();if(j.errors&&JSON.stringify(j.errors).includes('Throttled')){await sleep(2500*(a+1));continue;}return j;}return null;}
const PJ=/phillip[- ]?jeffries/i;
// BROADER nets to bound the under-count: anywhere in body
const BROAD=[
{k:'product description:', rx:/product description:/i},
{k:'here is/here\'s', rx:/here(?:'s| is)\b/i},
{k:'okay/sure/certainly start', rx:/\b(okay|sure|certainly)[,!:]/i},
{k:'as an ai / language model', rx:/\bas an ai\b|\blanguage model\b/i},
{k:'i hope/let me know/feel free', rx:/\bi hope this\b|\blet me know if\b|\bfeel free to\b/i},
{k:'description for the', rx:/description for the (wallcovering|wallpaper|product|fabric)/i},
];
const strip=h=>(h||'').replace(/<[^>]+>/g,' ').replace(/\s+/g,' ').trim();
const Q=`query($cursor:String){ products(first:60, after:$cursor, query:"status:active"){ pageInfo{hasNextPage endCursor} edges{node{ vendor descriptionHtml }} } }`;
let cursor=null,pages=0,scanned=0; const cnt={}; BROAD.forEach(b=>cnt[b.k]=0); let anyBroad=0; const anyByVendor={};
while(true){ const j=await gql(Q,{cursor}); if(!j?.data)break; const c=j.data.products;
for(const e of c.edges){ const n=e.node; if(PJ.test(n.vendor||''))continue; scanned++; const b=strip(n.descriptionHtml); if(!b)continue;
let hit=false; for(const p of BROAD){ if(p.rx.test(b)){ cnt[p.k]++; hit=true; } }
if(hit){ anyBroad++; anyByVendor[n.vendor]=(anyByVendor[n.vendor]||0)+1; } }
pages++; if(!c.pageInfo.hasNextPage)break; cursor=c.pageInfo.endCursor; const co=j.extensions?.cost?.throttleStatus; if(co&&co.currentlyAvailable<500)await sleep(1500); else await sleep(200); }
console.log(`scanned ${scanned} active bodies`);
console.log(`ANY broad-preamble hit: ${anyBroad}`);
Object.entries(cnt).forEach(([k,v])=>console.log(` [${k}] ${v}`));
console.log(`broad-hit by vendor (top 12):`); Object.entries(anyByVendor).sort((a,b)=>b[1]-a[1]).slice(0,12).forEach(([v,n])=>console.log(` ${v}: ${n}`));