← back to Designer Wallcoverings
nav script: handle auth-error string + last-wins env loader
0eadbd60f2f121c3090ec791f7b8abbc89c340e5 · 2026-07-30 11:09:03 -0700 · Steve Abrams
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files touched
M scripts/menu-nest-trim-under-fabrics.mjs
Diff
commit 0eadbd60f2f121c3090ec791f7b8abbc89c340e5
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Jul 30 11:09:03 2026 -0700
nav script: handle auth-error string + last-wins env loader
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
scripts/menu-nest-trim-under-fabrics.mjs | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/scripts/menu-nest-trim-under-fabrics.mjs b/scripts/menu-nest-trim-under-fabrics.mjs
index 046e1801..f3a3b80e 100644
--- a/scripts/menu-nest-trim-under-fabrics.mjs
+++ b/scripts/menu-nest-trim-under-fabrics.mjs
@@ -40,7 +40,9 @@ function loadEnv(file) {
if (!m) continue;
const k = m[1];
let v = m[2].replace(/^["']|["']$/g, '').replace(/\s+#.*$/, '').trim();
- if (v && process.env[k] === undefined) process.env[k] = v;
+ // last-wins: a later line/file overrides an earlier value (so a real
+ // token appended after a placeholder takes effect with no cleanup).
+ if (v) process.env[k] = v;
}
} catch { /* file may not exist */ }
}
@@ -84,7 +86,17 @@ async function gql(query, variables) {
});
const json = await res.json();
if (json.errors) {
- const msg = json.errors.map((e) => e.message).join('; ');
+ // Shopify returns errors as an array (GraphQL) OR a bare string (auth 401s).
+ const msg = Array.isArray(json.errors)
+ ? json.errors.map((e) => e.message).join('; ')
+ : String(json.errors);
+ if (/invalid api key or access token|unrecognized login|401/i.test(msg)) {
+ console.error(
+ `✗ Invalid/placeholder token (${msg}).\n` +
+ ' SHOPIFY_NAV_TOKEN is not a real shpat_ value — set the actual token and re-run.'
+ );
+ process.exit(2);
+ }
if (/Access denied for menus field/i.test(msg)) {
console.error(
`✗ Token lacks the online-store-navigation scope (${msg}).\n` +
← 281f46f7 TK-10055: free-promote hero script + gated plan (DTD-B; scan
·
back to Designer Wallcoverings
·
auto-save: 2026-07-30T11:17:19 (12 files) — shopify/scripts/ d5d01e09 →