← back to Designer Wallcoverings
Make inventory-stamp-guard.mjs shim portable (TK-11786 review): resolve shared master via DW_SHARED_GUARDS/homedir, not hardcoded /Users/macstudio3
48ea8a9ccb80a4926bbf6f7fd19b1b63ea9a801e · 2026-09-22 12:54:46 -0700 · Steve
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3ChReG53fwpNgUESv4SY7
Files touched
M shopify/scripts/lib/inventory-stamp-guard.mjs
Diff
commit 48ea8a9ccb80a4926bbf6f7fd19b1b63ea9a801e
Author: Steve <steve@designerwallcoverings.com>
Date: Tue Sep 22 12:54:46 2026 -0700
Make inventory-stamp-guard.mjs shim portable (TK-11786 review): resolve shared master via DW_SHARED_GUARDS/homedir, not hardcoded /Users/macstudio3
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3ChReG53fwpNgUESv4SY7
---
shopify/scripts/lib/inventory-stamp-guard.mjs | 91 ++++++---------------------
1 file changed, 19 insertions(+), 72 deletions(-)
diff --git a/shopify/scripts/lib/inventory-stamp-guard.mjs b/shopify/scripts/lib/inventory-stamp-guard.mjs
index 9cc16799..4459da32 100644
--- a/shopify/scripts/lib/inventory-stamp-guard.mjs
+++ b/shopify/scripts/lib/inventory-stamp-guard.mjs
@@ -1,75 +1,22 @@
-// TK-10965 — Fix B (prevention): the inventory-stamp invariant, as a pure guard.
+// inventory-stamp-guard.mjs — RE-EXPORT SHIM -> canonical master (2026-09-22 Option-B decouple).
+// Executable code verified IDENTICAL to the master (comment-only diff) + predicate-proof GREEN.
+// The $0-orderable guard (TK-11357) has ONE source of truth: ~/Projects/_shared/dw-guards/.
+// Original preserved as inventory-stamp-guard.mjs.pre-shared-lift.
//
-// ROOT CAUSE (see ../FINDINGS.md): importers stamp a positive "cap-free" stock
-// number (the year literal 2026) on the SELLABLE non-Sample variant of every
-// activated product — both in the product-create payload (`inventory_quantity: 2026`)
-// and on reconcile (`setInventory2026()`). When that sellable variant is ALSO
-// priced $0 (quote-only / contact-for-price lines like Phillipe Romano, Fentucci
-// Naturals), positive stock makes it `availableForSale` → checkout-orderable for $0.
-//
-// THE INVARIANT this module enforces (one place, both call sites):
-// A sellable variant that is priced $0 OR belongs to a quote-only / price-
-// suppressed line must NEVER receive positive inventory. It gets 0 → not orderable.
-// (The $4.25 Sample variant is unaffected — it is not the sellable variant and is
-// already qty=0/non-orderable by design.)
-//
-// PURE + dependency-free on purpose: no network, no env, no Shopify client, so it
-// unit-tests offline and drops into any importer runtime unchanged. $0 (local).
-
-// Tag family that means "this line has no public retail price" — a superset of the
-// single `quote-only` tag the standing canary keyed on (which is why Fentucci, tagged
-// `quotes`/`Needs-Price`, was the canary's 462-product blind spot).
-export const PRICE_SUPPRESSED_TAGS = new Set([
- 'quote-only', 'quote only', 'quote_only',
- 'quotes', 'contact-for-price', 'contact for price', 'needs-price', 'needs price',
-]);
-
-const norm = t => String(t).trim().toLowerCase();
-
-/**
- * Is this product a quote-only / price-suppressed line?
- * @param {{tags?: string[]|string, vendor?: string}} product
- */
-export function isPriceSuppressed(product = {}) {
- const tags = Array.isArray(product.tags)
- ? product.tags
- : String(product.tags || '').split(',');
- if (tags.some(t => PRICE_SUPPRESSED_TAGS.has(norm(t)))) return true;
- // Vendor fallback for untagged cohorts (Fentucci Naturals ships quote-only with
- // zero quote-only tags). Extend as new price-on-request lines are onboarded.
- return norm(product.vendor) === 'fentucci naturals';
-}
-
-/**
- * A variant is the "sellable" one iff it is NOT the Sample variant.
- * (Importers create exactly two variants: `Sample` @ $4.25 and the real unit @ price.)
- * @param {{title?: string, option1?: string}} variant
- */
-export function isSellableVariant(variant = {}) {
- const label = variant.title ?? variant.option1 ?? '';
- return !/sample/i.test(label);
-}
+// PORTABLE resolution (TK-11786 review fix): resolve the master via DW_SHARED_GUARDS or the
+// per-user home dir, NOT a hardcoded /Users/macstudio3 path — mirrors validate-before-activate.js
+// and internal-guard.js so this works on Kamatera (/root), Mac1, and any other home.
+// `export * from` requires a string literal, so we re-export explicitly from a dynamic import
+// (top-level await is valid in an ESM .mjs and resolves before any importer evaluates).
+import os from 'node:os';
+import path from 'node:path';
+import { pathToFileURL } from 'node:url';
-/**
- * Would giving this sellable variant positive stock make it a $0-orderable defect?
- * True iff it's the sellable variant AND (price is 0 OR the line is price-suppressed).
- * @param {object} variant the variant about to be stamped
- * @param {object} product its parent (for tags/vendor)
- */
-export function isZeroPriceOrderableRisk(variant = {}, product = {}) {
- if (!isSellableVariant(variant)) return false;
- const price = Number(variant.price);
- return price === 0 || Number.isNaN(price) || isPriceSuppressed(product);
-}
+const base = process.env.DW_SHARED_GUARDS || path.join(os.homedir(), 'Projects', '_shared', 'dw-guards');
+const _m = await import(pathToFileURL(path.join(base, 'inventory-stamp-guard.mjs')).href);
-/**
- * THE GUARD. Return the inventory quantity that is SAFE to stamp on this variant.
- * Drop-in replacement for the literal `2026` at both call sites:
- * - create payload: inventory_quantity: safeStampQuantity(variant, product)
- * - setInventory2026: quantity: safeStampQuantity(variant, product)
- * Returns `desired` (2026) for normal priced variants; 0 for the defect class.
- * @returns {number} 0 for a zero-price-orderable risk, else `desired`
- */
-export function safeStampQuantity(variant, product, desired = 2026) {
- return isZeroPriceOrderableRisk(variant, product) ? 0 : desired;
-}
+export const PRICE_SUPPRESSED_TAGS = _m.PRICE_SUPPRESSED_TAGS;
+export const isPriceSuppressed = _m.isPriceSuppressed;
+export const isSellableVariant = _m.isSellableVariant;
+export const isZeroPriceOrderableRisk = _m.isZeroPriceOrderableRisk;
+export const safeStampQuantity = _m.safeStampQuantity;
← e495042c auto-data-snapshot: 2026-09-22T12:49:04 (5 data files) — sho
·
back to Designer Wallcoverings
·
auto-data-snapshot: 2026-09-22T13:21:57 (2 data files) — sho 3bccb9b2 →