[object Object]

← back to Gmc Titlefix

add --link mode: append weight supplemental to primary 180695450 rule (dry-run default, --yes to apply)

1e920874ee0c035cd440051521b6b8bf1295e57f · 2026-07-09 09:00:20 -0700 · steve

Files touched

Diff

commit 1e920874ee0c035cd440051521b6b8bf1295e57f
Author: steve <steve@designerwallcoverings.com>
Date:   Thu Jul 9 09:00:20 2026 -0700

    add --link mode: append weight supplemental to primary 180695450 rule (dry-run default, --yes to apply)
---
 gmc-weight-override.js | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/gmc-weight-override.js b/gmc-weight-override.js
index 07a34cc..8885244 100644
--- a/gmc-weight-override.js
+++ b/gmc-weight-override.js
@@ -64,6 +64,27 @@ async function verifyLink(ds) {
   const ref = r.supplementalProductDataSource?.referencingPrimaryDataSources || r.referencedPrimaryDataSourceId || null;
   console.log(ref ? `✓ LINKED to primary: ${JSON.stringify(ref)}` : '⚠️ NOT LINKED — inserts will 200 but NOT propagate. Link it (MC UI: Feeds → supplemental → Link to primary) before pushing.');
 }
+// Link our supplemental into the primary feed's takeFromDataSources (before {self:true}).
+// DRY-RUN by default; add --yes to PATCH the primary. This is a PRIMARY-FEED config write.
+async function linkSupplemental() {
+  const PRIMARY = '180695450';
+  const SUPP = 'accounts/146735262/dataSources/10683334493';
+  const tok = await token();
+  const base = `https://merchantapi.googleapis.com/datasources/v1/accounts/${MERCHANT}/dataSources/${PRIMARY}`;
+  const cur = await (await fetch(base, { headers: { Authorization: 'Bearer ' + tok } })).json();
+  const pds = cur.primaryProductDataSource;
+  const tf = (pds.defaultRule && pds.defaultRule.takeFromDataSources) || [{ self: true }];
+  if (tf.some(x => x.supplementalDataSourceName === SUPP)) { console.log('✓ already linked — nothing to do'); return; }
+  const idx = tf.findIndex(x => x.self);
+  const newTf = [...tf]; newTf.splice(idx < 0 ? tf.length : idx, 0, { supplementalDataSourceName: SUPP });
+  const newPds = { ...pds, defaultRule: { ...pds.defaultRule, takeFromDataSources: newTf } };
+  console.log('CURRENT takeFromDataSources:', JSON.stringify(tf));
+  console.log('NEW     takeFromDataSources:', JSON.stringify(newTf));
+  if (!args.includes('--yes')) { console.log('\nDRY-RUN — re-run with --yes to apply the link (PATCHes the primary feed).'); return; }
+  const r = await fetch(base + '?updateMask=primaryProductDataSource', { method: 'PATCH', headers: { Authorization: 'Bearer ' + tok, 'Content-Type': 'application/json' }, body: JSON.stringify({ primaryProductDataSource: newPds }) });
+  const txt = await r.text();
+  console.log(r.ok ? '✓ LINKED (HTTP ' + r.status + ')' : '⚠️ PATCH failed ' + r.status + ' ' + txt.slice(0, 300));
+}
 async function listDs() {
   const tok = await token();
   const r = await (await fetch(`https://merchantapi.googleapis.com/datasources/v1/accounts/${MERCHANT}/dataSources?pageSize=100`, { headers: { Authorization: 'Bearer ' + tok } })).json();
@@ -99,6 +120,7 @@ async function apply(ds) {
 
 (async () => {
   if (LIST_DS) return listDs();
+  if (args.includes('--link')) return linkSupplemental();
   if (VERIFY_LINK) { if (!VL_DS) { console.error('need datasource: --verify-link <DS>'); process.exit(1); } return verifyLink(VL_DS); }
   if (CREATE_DS) return createDataSource();
   if (APPLY) { if (!DS) { console.error('need datasource: --apply <DS>'); process.exit(1); } return apply(DS); }

← 766c063 weight-override FIX-FIRST (contrarian): +verify-link/list-ds  ·  back to Gmc Titlefix  ·  verify-link: check authoritative primary rule (reverse-point f57f894 →