← back to Fentucci Theme Note
revert-quote-note.mjs
21 lines
#!/usr/bin/env node
// TK-10311 — revert the quote-note theme write by re-PUTting the exact backup taken before it.
// Usage: node revert-quote-note.mjs <path-to-backup.liquid.bak>
import fs from 'node:fs';
const SECRETS = '/Users/macstudio3/Projects/secrets-manager/.env';
const STORE = 'designer-laboratory-sandbox.myshopify.com';
const TOKEN = fs.readFileSync(SECRETS, 'utf8').match(/^SHOPIFY_FULL_ACCESS_TOKEN=(.+)$/m)[1].trim();
const REST = `https://${STORE}/admin/api/2024-10`;
const H = { 'X-Shopify-Access-Token': TOKEN, 'Content-Type': 'application/json' };
const KEY = 'snippets/product-description-meta.liquid';
const bak = process.argv[2];
if (!bak || !fs.existsSync(bak)) { console.error('need an existing backup file path'); process.exit(1); }
const value = fs.readFileSync(bak, 'utf8');
(async () => {
const tr = await fetch(`${REST}/themes.json?fields=id,role`, { headers: H });
const MAIN = (await tr.json()).themes.find(t => t.role === 'main').id;
const r = await fetch(`${REST}/themes/${MAIN}/assets.json`, { method: 'PUT', headers: H, body: JSON.stringify({ asset: { key: KEY, value } }) });
const j = await r.json();
console.log(r.ok ? `REVERTED ${KEY} on theme ${MAIN} @ ${j.asset?.updated_at}` : `FAIL ${r.status} ${JSON.stringify(j).slice(0,200)}`);
})();