← back to Filemaker Mcp
scripts/tk-10083-cleanup.mjs
53 lines
// TK-10083 remediation: delete the TWO empty duplicate WALLPAPER masters minted
// 7/31/2026 by the old buggy parser (Series=DWC, wrong split), preserving the
// genuine 2019 master 240939. Steve-approved (2026-08-03).
//
// HARD INTERLOCK: re-reads each record live and DELETES ONLY IF it is still the
// empty DWC mis-mint — Series must be exactly 'DWC', combo sku exactly
// 'DWCOP-ART-DECO-WAVES', and every price/cost field blank. Any deviation (data
// appeared, or it's the real master) ABORTS that record. This makes it
// structurally impossible to delete 240939 (Series 'OP-ART') or a record that
// gained content since the approval.
import * as fm from '../src/fm-client.js';
const DB = 'WALLPAPER';
const LAYOUT = 'Basic List of Fields'; // read/guard layout
// The read layout has related-table portals -> FM [110] on DELETE. Delete through a
// leaner layout instead (the ones onboarding already writes through work).
const DELETE_LAYOUTS = ['Add wallcovering', '*List Wallpapers - Full View', 'Basic List of Fields'];
const TARGETS = ['538697', '538698'];
const NEVER = new Set(['240939']); // the genuine master — explicit tripwire
const PRICE_FIELDS = ['Retail Price', 'Cost', 'Net Price', 'Repeat', 'Width', 'Supplier', 'Internal Description', 'Client Notes'];
function guardOk(fd) {
const reasons = [];
if (String(fd.Series || '') !== 'DWC') reasons.push(`Series is "${fd.Series}" (expected DWC)`);
if (String(fd['combo sku'] || '') !== 'DWCOP-ART-DECO-WAVES') reasons.push(`combo sku is "${fd['combo sku']}" (expected DWCOP-ART-DECO-WAVES)`);
for (const f of PRICE_FIELDS) if (String(fd[f] || '').trim()) reasons.push(`${f} is non-empty ("${fd[f]}")`);
return reasons;
}
const del = process.argv.includes('--commit');
console.log(del ? '=== COMMIT MODE — will delete on guard pass ===' : '=== DRY RUN (add --commit to delete) ===');
for (const id of TARGETS) {
if (NEVER.has(id)) { console.log(`ABORT ${id}: on the never-delete list`); continue; }
let rec;
try { rec = await fm.getRecord(DB, LAYOUT, id); }
catch (e) { console.log(`ABORT ${id}: could not re-read (${e.message})`); continue; }
if (!rec) { console.log(`SKIP ${id}: already gone (not found)`); continue; }
const fd = rec.fieldData || {};
const bad = guardOk(fd);
if (bad.length) { console.log(`ABORT ${id}: guard failed — ${bad.join('; ')}`); continue; }
console.log(`GUARD PASS ${id}: empty DWC mis-mint (Series=${fd.Series}, combo sku=${fd['combo sku']})`);
if (!del) { console.log(` would delete ${id}`); continue; }
let done = false;
for (const lay of DELETE_LAYOUTS) {
try { const r = await fm.deleteRecord(DB, lay, id); console.log(` DELETED ${id} via "${lay}": ${JSON.stringify(r)}`); done = true; break; }
catch (e) { console.log(` delete via "${lay}" failed: ${e.message}`); }
}
if (!done) console.log(` DELETE FAILED ${id}: all candidate layouts rejected`);
}
console.log('=== done ===');