← back to Gmc 425 Supplemental Feed

reorder-plan.mjs

29 lines

#!/usr/bin/env node
/** reorder-plan.mjs — DRY-RUN PLAN generator for the SUPP_CANT_HELP source fix. Writes NO changes.
 * For each product (Sample@pos1 → only Sample reaches Google), plan: make Roll position 1, Sample position 2,
 * so Shopify's Google channel submits the Roll offer. Emits the productVariantsBulkReorder payloads
 * (NOT executed) + a re-sync + verify checklist + reversibility. Upload/execute is Steve-gated.
 * Usage: node reorder-plan.mjs [supp-cant-help.json] */
import fs from 'node:fs';
const OUT=new URL('./out/',import.meta.url); fs.mkdirSync(OUT,{recursive:true});
const src=process.argv[2]||new URL('supp-cant-help.json',OUT);
let rows; try{ rows=JSON.parse(fs.readFileSync(src,'utf8')); }catch{ console.error('No SUPP_CANT_HELP list yet at '+src+' — run full-classify.mjs first.'); process.exit(2); }
const plans=rows.map(r=>({
  pid:r.pid, vendor:r.vendor, rollPrice:r.rollPrice,
  mutation:'productVariantsBulkReorder',
  variables:{ productId:`gid://shopify/Product/${r.pid}`,
    positions:[ {id:`gid://shopify/ProductVariant/${r.rollVid}`,position:1},
                {id:`gid://shopify/ProductVariant/${r.sampleVid}`,position:2} ] },
}));
fs.writeFileSync(new URL('reorder-plan.json',OUT),JSON.stringify({
  generated:'DRY-RUN PLAN (not executed)',
  count:plans.length,
  action:'Set Roll variant to position 1 (default) so Shopify Google & YouTube channel submits the Roll offer, not the $4.25 Sample.',
  post_step:'After reorder: force a Google channel re-sync for each product, then RE-VERIFY via classify (Roll offer should appear + $4.25 Sample offer should drop). Note: already-ingested Sample offers are STICKY in Google — allow re-crawl time and confirm.',
  reversibility:'Reorder is fully reversible (swap positions back). No price/variant/inventory mutated.',
  gated:'The productVariantsBulkReorder writes + the channel re-sync are customer-facing Shopify writes — Steve-gated. This file is the plan only.',
  plans,
},null,2));
console.log(`Reorder DRY-RUN plan written for ${plans.length} SUPP_CANT_HELP products → out/reorder-plan.json (NOT executed).`);
if(plans[0]) console.log('Sample payload:',JSON.stringify(plans[0].variables));