← back to Filemaker Mcp
add fuzzy-sku-check.mjs: reusable WALLPAPER SKU existence probe (strips -Sample; combo sku/comboskuwithdash/mfr pattern number/Mfr Pattern; exit 0/1 + JSON)
941cf7aa292f3ac81cc486682ee8c5cccd998801 · 2026-07-01 15:54:01 -0700 · Steve Abrams
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Files touched
A scripts/fuzzy-sku-check.mjs
Diff
commit 941cf7aa292f3ac81cc486682ee8c5cccd998801
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Wed Jul 1 15:54:01 2026 -0700
add fuzzy-sku-check.mjs: reusable WALLPAPER SKU existence probe (strips -Sample; combo sku/comboskuwithdash/mfr pattern number/Mfr Pattern; exit 0/1 + JSON)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---
scripts/fuzzy-sku-check.mjs | 72 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/scripts/fuzzy-sku-check.mjs b/scripts/fuzzy-sku-check.mjs
new file mode 100644
index 0000000..81d054f
--- /dev/null
+++ b/scripts/fuzzy-sku-check.mjs
@@ -0,0 +1,72 @@
+// fuzzy-sku-check — reusable existence check for a DW SKU in the WALLPAPER db.
+// Strips a trailing -Sample, then queries across the fields a SKU can live in:
+// "combo sku" (dashless calc, e.g. DWTT73433), "comboskuwithdash" (DWTT-73433),
+// "mfr pattern number", "Mfr Pattern".
+// Prints JSON { sku, normalized, exists, matches: [{ field, recordId, comboSku, name }] }.
+// Exit 0 = exists, 1 = not found, 2 = usage/error.
+// Usage: node scripts/fuzzy-sku-check.mjs DWTT-73433[-Sample]
+// Intended consumer: the invoice-import pipeline (wire-up owned by that pipeline, not here).
+
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+const __dir = dirname(fileURLToPath(import.meta.url));
+for (const line of readFileSync(join(__dir, '..', '.env'), 'utf8').split('\n')) {
+ const m = line.match(/^([A-Z_]+)=(.*)$/);
+ if (m && !process.env[m[1]]) process.env[m[1]] = m[2];
+}
+
+const { findRecords } = await import('../src/fm-client.js');
+
+const DB = 'WALLPAPER';
+const LAYOUT = '*List Wallpapers - Shopify Detail Database';
+
+const raw = process.argv[2];
+if (!raw) {
+ console.error('Usage: node scripts/fuzzy-sku-check.mjs <SKU> (e.g. DWTT-73433-Sample)');
+ process.exit(2);
+}
+
+// normalize: trim, strip trailing -Sample (any case), collapse whitespace
+const normalized = raw.trim().replace(/[-_ ]?sample$/i, '');
+const dashless = normalized.replace(/-/g, '');
+
+// field -> query value. combo sku is stored dashless; comboskuwithdash keeps the dash.
+const probes = [
+ ['combo sku', dashless],
+ ['comboskuwithdash', normalized.includes('-') ? normalized : dashless],
+ ['mfr pattern number', normalized],
+ ['Mfr Pattern', normalized],
+];
+
+const matches = [];
+const seen = new Set();
+for (const [field, value] of probes) {
+ if (!value) continue;
+ try {
+ const { records } = await findRecords(DB, LAYOUT, { [field]: `==${value}` }, { limit: 10 });
+ for (const r of records) {
+ const key = `${field}:${r.recordId}`;
+ if (seen.has(key)) continue;
+ seen.add(key);
+ matches.push({
+ field,
+ value,
+ recordId: r.recordId,
+ comboSku: r.fieldData['combo sku'],
+ comboSkuWithDash: r.fieldData['comboskuwithdash'],
+ mfrPattern: r.fieldData['Mfr Pattern'],
+ name: r.fieldData['Name of Pattern'],
+ });
+ }
+ } catch (e) {
+ if (e.fmCode === '401') continue; // no records match — not an error
+ console.error(`ERROR probing "${field}": ${e.message}`);
+ process.exit(2);
+ }
+}
+
+const out = { sku: raw, normalized, exists: matches.length > 0, matches };
+console.log(JSON.stringify(out, null, 1));
+process.exit(out.exists ? 0 : 1);
← 10f7a19 invoice 102374 repair script: split Otto's collapsed 4-sampl
·
back to Filemaker Mcp
·
chore: v0.1.1 (session close — Baxter records, invoice 10237 bcf5e67 →