← back to Shopify Sample Shipping
list-designer-segments.mjs
20 lines
// READ-ONLY: discover the customer segments + tag vocabulary used for designers/trade.
import {query} from './query.mjs';
// 1) Customer segments (their `query` strings reveal which customer_tags define "designer")
const segs=(await query(`{segments(first:100){nodes{id name query creationDate}}}`)).segments.nodes;
console.log('=== CUSTOMER SEGMENTS ('+segs.length+') ===');
for(const s of segs) console.log(`• ${s.name}\n query: ${s.query}`);
// 2) Existing free-shipping DISCOUNTS (code + automatic) so we don't duplicate
try{
const codes=(await query(`{codeDiscountNodes(first:50){nodes{codeDiscount{__typename ... on DiscountCodeFreeShipping{title status customerSelection{__typename} customerGets{items{__typename}}}}}}}`)).codeDiscountNodes.nodes;
const fs=codes.filter(n=>n.codeDiscount?.__typename==='DiscountCodeFreeShipping');
console.log('\n=== FREE-SHIPPING CODE DISCOUNTS ('+fs.length+') ===');
for(const n of fs) console.log(`• ${n.codeDiscount.title} [${n.codeDiscount.status}] customerSelection=${n.codeDiscount.customerSelection?.__typename}`);
}catch(e){console.log('code discounts read err:',e.message);}
try{
const autos=(await query(`{automaticDiscountNodes(first:50){nodes{automaticDiscount{__typename ... on DiscountAutomaticFreeShipping{title status}}}}}`)).automaticDiscountNodes.nodes;
const af=autos.filter(n=>n.automaticDiscount?.__typename==='DiscountAutomaticFreeShipping');
console.log('\n=== AUTOMATIC FREE-SHIPPING DISCOUNTS ('+af.length+') ===');
for(const n of af) console.log(`• ${n.automaticDiscount.title} [${n.automaticDiscount.status}]`);
}catch(e){console.log('auto discounts read err:',e.message);}