← back to Dw Signup Fulfillment

verification/tk10836/verify-profile-leak.js

61 lines

#!/usr/bin/env node
// TK-10836 (post-red-team): WHY did comped sample carts stop getting the $0.00 rate after ~Aug 18?
// The Samples profile's Domestic zone offers ONLY: Free Shipping (No Tracking) $0.00 + Priority
// Sample Only $24.95.  "UPS(R) Ground" is NOT one of them -- it lives in the General profile.
// So a sample-only order that shipped UPS Ground proves its variants were NOT in the Samples profile.
// TEST: for recent PAID comped sample orders vs recent FREE ones, resolve each line item's
// delivery profile. Read-only.
const fs=require('fs'),os=require('os');
for (const line of fs.readFileSync(os.homedir()+'/Projects/secrets-manager/.env','utf8').split('\n')) {
  const m=line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)$/); if(!m) continue;
  let v=m[2].trim().replace(/^['"]|['"]$/g,''); if(!process.env[m[1]]) process.env[m[1]]=v;
}
const STORE=process.env.SHOPIFY_STORE_DOMAIN||'designer-laboratory-sandbox.myshopify.com';
const TOKEN=process.env.SHOPIFY_FULL_ACCESS_TOKEN, API='2024-10';
async function gql(q,v={}){const r=await fetch(`https://${STORE}/admin/api/${API}/graphql.json`,{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.errors)console.error('ERR',JSON.stringify(j.errors).slice(0,400)); return j.data;}

// 1) FULL untruncated dump of the Samples profile Domestic zone
// resolve the Samples profile id off one of Kelly's own variants, then dump it whole
const FINDPROF=`query{ productVariants(first:1, query:"sku:DWCC-600006-Sample"){ nodes{ sku deliveryProfile{ id name } } } }`;
const DUMP=`query($id:ID!){ node(id:$id){ ... on DeliveryProfile { name
  profileLocationGroups{ locationGroupZones(first:8){ nodes{ zone{name}
    methodDefinitions(first:40){ nodes{ name active
      rateProvider{ __typename ... on DeliveryRateDefinition{ price{amount} } ... on DeliveryParticipant{ carrierService{formattedName} } } } } } } } } } }`;

const ORDER=`query($q:String!){ orders(first:12, query:$q, sortKey:CREATED_AT, reverse:true){ nodes{
  name createdAt totalShippingPriceSet{shopMoney{amount}} shippingLine{title}
  shippingAddress{provinceCode}
  lineItems(first:10){ nodes{ title quantity
    variant{ sku createdAt deliveryProfile{ name } product{ createdAt vendor } } } } } } }`;

(async()=>{
  const fp=await gql(FINDPROF);
  const prof=fp?.productVariants?.nodes?.[0]?.deliveryProfile;
  console.log(`### FULL dump of Kelly's variant profile: "${prof?.name}" (untruncated) ###`);
  const dp=await gql(DUMP,{id:prof.id});
  for(const lg of dp.node.profileLocationGroups) for(const z of lg.locationGroupZones.nodes){
    console.log(`  zone=${z.zone.name}`);
    for(const m of z.methodDefinitions.nodes){
      const rp=m.rateProvider;
      console.log(`     - "${m.name}" active=${m.active} ${rp.price?`FLAT $${rp.price.amount}`:(rp.carrierService?`CARRIER ${rp.carrierService.formattedName}`:rp.__typename)}`);
    }
  }
  for(const [label,q] of [
    ['RECENT PAID comped sample orders','created_at:>2026-08-25 shipping_line:"UPS® Ground"'],
    ['RECENT FREE comped sample orders','created_at:>2026-08-25 shipping_line:"Free Shipping (No Tracking)"']]){
    console.log(`\n### ${label} — line-item delivery profiles ###`);
    const d=await gql(ORDER,{q});
    for(const o of (d?.orders?.nodes||[])){
      const lis=o.lineItems.nodes;
      if(!lis.every(li=>/(^|-)sample/i.test(li.variant?.sku||''))) continue;
      const profs=[...new Set(lis.map(li=>li.variant?.deliveryProfile?.name||'(unknown)'))];
      const newest=lis.map(li=>li.variant?.product?.createdAt||'').sort().pop();
      console.log(`  ${o.name} ${o.createdAt.slice(0,10)} ${o.shippingAddress?.provinceCode} $${o.totalShippingPriceSet.shopMoney.amount} "${o.shippingLine?.title}"`);
      console.log(`     profiles: ${profs.join(' | ')}   newest product createdAt: ${newest.slice(0,10)}`);
      for(const li of lis) console.log(`       · ${li.variant?.sku} -> "${li.variant?.deliveryProfile?.name}" (product created ${li.variant?.product?.createdAt?.slice(0,10)}, vendor ${li.variant?.product?.vendor})`);
    }
  }
})();