← back to Dw Signup Fulfillment

verification/tk10836/verify-kelly-orders.js

43 lines

'use strict';
const config = require('../../lib/config');
const shop = config.SHOP_DOMAIN, token = config.SHOPIFY_FULFILLMENT_TOKEN;
async function gql(query, variables) {
  const r = await fetch(`https://${shop}/admin/api/2024-10/graphql.json`, {
    method: 'POST', headers: { 'X-Shopify-Access-Token': token, 'Content-Type': 'application/json' },
    body: JSON.stringify({ query, variables }) });
  const j = await r.json();
  if (j.errors) console.error('ERRORS', JSON.stringify(j.errors).slice(0,500));
  return j.data;
}
(async () => {
  const d = await gql(`
  query($id: ID!) {
    customer(id: $id) {
      email numberOfOrders amountSpent { amount }
      orders(first: 10) { nodes { name createdAt discountCodes totalPriceSet { shopMoney { amount } } totalShippingPriceSet { shopMoney { amount } } } }
    }
  }`, { id: 'gid://shopify/Customer/8388564123699' });
  console.log('=== KELLY ORDERS ===');
  console.log(JSON.stringify(d, null, 2));

  const fs = await gql(`
  {
    codeDiscountNodes(first: 30) {
      nodes {
        codeDiscount {
          __typename
          ... on DiscountCodeFreeShipping {
            title status endsAt appliesOncePerCustomer
            combinesWith { orderDiscounts productDiscounts shippingDiscounts }
            minimumRequirement { __typename ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount } } }
            codes(first: 3) { nodes { code } }
          }
        }
      }
    }
  }`);
  console.log('\n=== FREE SHIPPING CODES ===');
  const nodes = (fs && fs.codeDiscountNodes.nodes || []).filter(n => n.codeDiscount.__typename === 'DiscountCodeFreeShipping');
  console.log(JSON.stringify(nodes, null, 2));
})().catch(e => { console.error('ERR', e.message); process.exit(1); });