← back to Dw Signup Fulfillment
verification/tk10836/verify-functions-recheck.js
52 lines
#!/usr/bin/env node
// TK-11366: my earlier shopifyFunctions/deliveryCustomizations query returned EMPTY, but a
// "DW Free Samples" discount FUNCTION demonstrably exists (TK-11361). So that empty result may
// have been a silent failure -> my "no rate-hiding customization" conclusion is UNVERIFIED.
// Re-check with a positive control: if I cannot see the discount function I KNOW exists,
// I cannot trust an empty deliveryCustomizations result either.
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, API='2024-10';
async function gql(q,token,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();
return {data:j.data, errors:j.errors};
}
const TOKENS={FULL:process.env.SHOPIFY_FULL_ACCESS_TOKEN, FULFILLMENT:process.env.SHOPIFY_FULFILLMENT_TOKEN};
(async()=>{
for(const [name,tok] of Object.entries(TOKENS)){
if(!tok) continue;
console.log(`\n================ TOKEN ${name} (…${tok.slice(-4)}) ================`);
// POSITIVE CONTROL: automatic app discounts (we KNOW >=1 function-backed discount exists)
let r=await gql(`query{ automaticDiscountNodes(first:25){ nodes{ id automaticDiscount{
__typename
... on DiscountAutomaticApp{ title status appDiscountType{ functionId title } }
... on DiscountAutomaticBasic{ title status } } } } }`,tok);
if(r.errors) console.log(' automaticDiscountNodes ERRORS:', JSON.stringify(r.errors).slice(0,300));
const nodes=r.data?.automaticDiscountNodes?.nodes||[];
console.log(` CONTROL automaticDiscountNodes: ${nodes.length} node(s)`);
for(const n of nodes){
const a=n.automaticDiscount;
console.log(` - [${a.__typename}] "${a.title}" status=${a.status} fn=${a.appDiscountType?.functionId||'-'} id=${n.id.split('/').pop()}`);
}
for(const [label,q] of [
['deliveryCustomizations',`query{ deliveryCustomizations(first:25){ nodes{ id title enabled functionId } } }`],
['shopifyFunctions',`query{ shopifyFunctions(first:50){ nodes{ id title apiType app{ title } } } }`],
['cartTransforms',`query{ cartTransforms(first:10){ nodes{ id functionId } } }`],
]){
r=await gql(q,tok);
if(r.errors){ console.log(` ${label}: ERROR -> ${JSON.stringify(r.errors).slice(0,220)}`); continue; }
const key=Object.keys(r.data||{})[0];
const ns=r.data?.[key]?.nodes||[];
console.log(` ${label}: ${ns.length} node(s)`);
for(const n of ns) console.log(` - ${JSON.stringify(n).slice(0,200)}`);
}
}
})();