[object Object]

← back to Gmc Titlefix

verify-link: check authoritative primary rule (reverse-pointer lags) — confirms weight DS linked

f57f894477b8452b3e12a1dfc75272add2f937b8 · 2026-07-09 09:02:11 -0700 · steve

Files touched

Diff

commit f57f894477b8452b3e12a1dfc75272add2f937b8
Author: steve <steve@designerwallcoverings.com>
Date:   Thu Jul 9 09:02:11 2026 -0700

    verify-link: check authoritative primary rule (reverse-pointer lags) — confirms weight DS linked
---
 gmc-weight-override.js | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/gmc-weight-override.js b/gmc-weight-override.js
index 8885244..f582953 100644
--- a/gmc-weight-override.js
+++ b/gmc-weight-override.js
@@ -58,11 +58,16 @@ async function createDataSource() {
 // Verify the supplemental datasource is LINKED to a primary feed — else inserts 200 but do nothing.
 async function verifyLink(ds) {
   const tok = await token();
-  const name = ds.startsWith('accounts/') ? ds : `accounts/${MERCHANT}/dataSources/${ds}`;
-  const r = await (await fetch(`https://merchantapi.googleapis.com/datasources/v1/${name}`, { headers: { Authorization: 'Bearer ' + tok } })).json();
-  console.log('datasource:', JSON.stringify(r, null, 2).slice(0, 800));
-  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.');
+  const suppId = (ds.match(/(\d+)$/) || [])[1];
+  // AUTHORITATIVE: check every primary's defaultRule.takeFromDataSources for this supplemental
+  // (the supplemental's own referencingPrimaryDataSources reverse-pointer lags / only reflects UI links).
+  const all = await (await fetch(`https://merchantapi.googleapis.com/datasources/v1/accounts/${MERCHANT}/dataSources?pageSize=100`, { headers: { Authorization: 'Bearer ' + tok } })).json();
+  const linkedTo = [];
+  for (const d of (all.dataSources || [])) {
+    const tf = d.primaryProductDataSource?.defaultRule?.takeFromDataSources || [];
+    if (tf.some(x => (x.supplementalDataSourceName || '').includes(suppId))) linkedTo.push(d.name);
+  }
+  console.log(linkedTo.length ? `✓ LINKED — referenced by primary rule(s): ${linkedTo.join(', ')}` : '⚠️ NOT LINKED — no primary rule references it; inserts would 200 but NOT propagate.');
 }
 // 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.

← 1e92087 add --link mode: append weight supplemental to primary 18069  ·  back to Gmc Titlefix  ·  add --samples-only mode: fix ONLY $4.25 samples @ 0.35lb, le 327c4ba →