← back to Flock Fix Viewer
fix-mfr-8004.mjs
41 lines
// TK-11122 — write the REAL mfr# onto FLOCK-8004 (Retro Velvet Hot Pink Fuscia).
// Confirmed Osborne & Little W5725-04 (FileMaker flock8004 + visual fans-pattern match).
// Replaces the placeholder mfr metafield (currently = the DW SKU "FLOCK-8004").
// Value written = bare code "W5725-04" (no vendor name → no private-label leak).
// Reversible: snapshots old values + ledgers undo. Dry-run default; --apply writes.
import fs from 'fs'; import os from 'os'; import path from 'path';
const SHOP='designer-laboratory-sandbox.myshopify.com';
const TOKEN=fs.readFileSync(new URL('./.token',import.meta.url),'utf8').trim();
const LEDGER=path.join(os.homedir(),'.claude/yolo-queue/executed-reversible/ledger.jsonl');
const SNAP=new URL('./mfr-8004-snapshot.json',import.meta.url);
const DRY=!process.argv.includes('--apply');
const API=`https://${SHOP}/admin/api/2024-10`;
const H={'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'};
const PRODUCT_ID=1494878388336; // FLOCK-8004 product (8003=1494878158960 is a paisley, NOT W5725 — excluded)
const NEW='W5725-04';
const TARGET=[['custom','manufacturer_sku'],['dwc','manufacturer_sku']];
const r=await (await fetch(`${API}/products/${PRODUCT_ID}/metafields.json`,{headers:H})).json();
const mfs=r.metafields||[];
const hits=TARGET.map(([ns,key])=>mfs.find(m=>m.namespace===ns&&m.key===key)).filter(Boolean);
console.log(`FLOCK-8004 (product ${PRODUCT_ID}) — write mfr# -> "${NEW}" APPLY=${!DRY}`);
const snap=[];
for(const m of hits){
console.log(` ${m.namespace}.${m.key}: "${m.value}" -> "${NEW}"`);
snap.push({id:m.id,namespace:m.namespace,key:m.key,oldValue:m.value});
}
if(hits.length===0){console.log(' (no manufacturer_sku metafields found — nothing to do)');}
if(DRY){console.log('\nDRY RUN — nothing written. Re-run with --apply.');process.exit(0);}
for(const m of hits){
const res=await (await fetch(`${API}/metafields/${m.id}.json`,{method:'PUT',headers:H,
body:JSON.stringify({metafield:{id:m.id,value:NEW,type:'single_line_text_field'}})})).json();
if(res?.metafield?.value===NEW){console.log(` ✓ ${m.namespace}.${m.key} = ${NEW}`);}
else{console.log(' FAIL',m.namespace+'.'+m.key,JSON.stringify(res).slice(0,200));}
}
fs.writeFileSync(SNAP,JSON.stringify(snap,null,1));
fs.appendFileSync(LEDGER,JSON.stringify({ts:new Date().toISOString(),agent:'vp-dw-commerce',ticket:'TK-11122',
action:`FLOCK-8004: set real mfr# manufacturer_sku -> W5725-04 (Osborne & Little), was placeholder FLOCK-8004`,
blast_radius:1,undo_cmd:`restore mfr-8004-snapshot.json: PUT each metafield id back to oldValue (FLOCK-8004)`,
verify:'GET product 1494878388336 metafields -> custom.manufacturer_sku==W5725-04'})+'\n');
console.log('\nDONE — snapshot: mfr-8004-snapshot.json, ledgered.');