← back to Dw Signup Fulfillment
verification/tk11283/read-live.cjs
42 lines
'use strict';
// Read-only Shopify review; never submits a customer, order, email or theme write.
const fs = require('node:fs');
const path = require('node:path');
const config = require('../../lib/config');
const dir = __dirname;
function envKey(key) {
const source = fs.readFileSync(path.join(require('node:os').homedir(), 'Projects/secrets-manager/.env'), 'utf8');
return source.match(new RegExp('^' + key + '=(.*)$', 'm'))?.[1].replace(/^["']|["']$/g, '').trim();
}
async function main() {
const token = envKey('SHOPIFY_THEME_TOKEN');
if (!token) throw new Error('Theme read credential unavailable');
async function get(endpoint) {
const response = await fetch(`https://${config.SHOP_DOMAIN}/admin/api/2026-07${endpoint}`, {headers:{'X-Shopify-Access-Token':token}});
if (!response.ok) throw new Error(`Theme read HTTP ${response.status}`);
return response.json();
}
const themes = await get('/themes.json');
const main = themes.themes.find(t=>t.role==='main');
if (!main) throw new Error('No main theme');
const keys = ['snippets/dw-signin-modal.liquid', 'snippets/dw-trade-apply.liquid', 'snippets/dw-samples-banner.liquid'];
const assets = [];
for (const key of keys) {
const result = await get(`/themes/${main.id}/assets.json?asset[key]=${encodeURIComponent(key)}`);
const value = result.asset.value;
const filename = `live-${key.replaceAll('/','__')}`;
fs.writeFileSync(path.join(dir, filename), value);
assets.push({key,filename,updated_at:result.asset.updated_at,sha256:require('node:crypto').createHash('sha256').update(value).digest('hex')});
}
const query = `query ReviewSignIn { shop { customerAccountsV2 { customerAccountsVersion url } } discountNodes(first:20,query:"title:DW Free Samples") { nodes { discount { ... on DiscountAutomaticApp { title status appDiscountType { functionId } } } } } webhookSubscriptions(first:50) { nodes { topic uri } } }`;
const response = await fetch(`https://${config.SHOP_DOMAIN}/admin/api/2026-07/graphql.json`, {method:'POST',headers:{'Content-Type':'application/json','X-Shopify-Access-Token':config.SHOPIFY_FULFILLMENT_TOKEN},body:JSON.stringify({query})});
const result = await response.json();
// Do not persist webhook credential-bearing URIs.
const webhooks = result.data?.webhookSubscriptions?.nodes?.map(x=>({topic:x.topic,origin:new URL(x.uri).origin}));
const health = await fetch('https://signup.designerwallcoverings.com/healthz').then(r=>r.json());
const evidence = {timestamp:new Date().toISOString(),theme:{id:main.id,name:main.name,role:main.role},assets,health,account:result.data?.shop,discounts:result.data?.discountNodes?.nodes,webhooks,errors:result.errors?.map(x=>x.message)};
fs.writeFileSync(path.join(dir,'live-read.json'),JSON.stringify(evidence,null,2)+'\n');
console.log(JSON.stringify(evidence,null,2));
}
main().catch(e=>{console.error(e.message);process.exitCode=1;});