← back to Shopify Sample Shipping
theme-inspect.mjs
26 lines
import {TOKEN, SHOP} from '../designerwallcoverings/scripts/lib/shopify.mjs';
const base=`https://${SHOP}/admin/api/2026-07`;
const H={'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'};
const get=async p=>{const r=await fetch(base+p,{headers:H});return {status:r.status,json:await r.json().catch(()=>null)};};
// 1) themes
const t=await get('/themes.json');
const themes=(t.json?.themes)||[];
const main=themes.find(x=>x.role==='main');
console.log('themes:',themes.map(x=>`${x.id} "${x.name}" [${x.role}]`).join(' | '));
if(!main){console.log('no main theme / status',t.status);process.exit(0);}
console.log('\nMAIN theme id=',main.id,'name=',main.name);
// 2) list cart-related assets
const a=await get(`/themes/${main.id}/assets.json`);
const keys=(a.json?.assets||[]).map(x=>x.key);
const cartKeys=keys.filter(k=>/cart/i.test(k));
console.log('\ncart-related assets:');
cartKeys.forEach(k=>console.log(' '+k));
// 3) peek at the cart template JSON (OS 2.0) if present
for(const key of ['templates/cart.json','templates/cart.liquid']){
if(!keys.includes(key))continue;
const as=await get(`/themes/${main.id}/assets.json?asset[key]=${encodeURIComponent(key)}`);
const val=as.json?.asset?.value||'';
console.log(`\n--- ${key} (first 800 chars) ---`);
console.log(val.slice(0,800));
}