← back to Dw Image Dup Audit
sweep1-fix.js
35 lines
#!/usr/bin/env node
// /5x sweep-1 fix: draft the two ACTIVE peel-and-stick strays on the main store
// (P&S line policy = apartmentwallpaper.com only). Ledgered, reversible.
const https = require("https");
const fs = require("fs");
const TOKEN = process.env.SHOPIFY_ADMIN_TOKEN;
const HOST = "designer-laboratory-sandbox.myshopify.com";
const API = "/admin/api/2024-10";
const LEDGER = __dirname + "/fix-ledger.jsonl";
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
function req(method, path, body) {
return new Promise((res, rej) => {
const data = body ? JSON.stringify(body) : null;
const r = https.request({ host: HOST, path, method, headers: { "X-Shopify-Access-Token": TOKEN, "Content-Type": "application/json", ...(data ? { "Content-Length": Buffer.byteLength(data) } : {}) } },
(resp) => { let d = ""; resp.on("data", (c) => (d += c)); resp.on("end", () => res({ status: resp.statusCode, body: d })); });
r.on("error", rej); if (data) r.write(data); r.end();
});
}
const HANDLES = [
"peel-and-stick-wallcovering-jeffrey-stevens-4",
"peel-and-stick-wallcovering-grey-blythe-jeffrey-stevens",
];
(async () => {
for (const handle of HANDLES) {
const g = await req("GET", `${API}/products.json?handle=${handle}&fields=id,status,title`);
const p = (JSON.parse(g.body).products || [])[0];
await sleep(600);
if (!p || p.status !== "active") { console.log("skip", handle); continue; }
const r = await req("PUT", `${API}/products/${p.id}.json`, { product: { id: p.id, status: "draft" } });
await sleep(600);
fs.appendFileSync(LEDGER, JSON.stringify({ ts: new Date().toISOString(), act: "5x-sweep1-draft", handle, id: p.id, title: p.title, ok: r.status === 200 }) + "\n");
console.log(r.status === 200 ? "drafted" : "FAIL", handle);
}
})();