← back to Filemaker Mcp

scripts/create-dwkk-120156.mjs

86 lines

// One-off: create the missing WALLPAPER master for DWKK-120156 (Shopify order #32513,
// FM invoice 102387). Gaston Y Daniela "Albuquerque", Verde Agua Multi — Gaston Uptown,
// stripes upholstery weave FABRIC sold per yard. Mfr# GDT5151.003.0 (Shopify
// global.manufacturer_sku). Kravet-family pricing: retail 308.70 IS MAP => whls = MAP/1.5
// = 205.80 (universal 1.5x rule; SKU absent from kravet_master_price — fabric line).
// Width: 55" per the selling variant title ("Sold Per Yard - 55In Wide"); the stale
// global.width metafield says 36" — variant title wins, it's what the customer bought.
// Repeat/Content left blank — not in any source; never invent specs.
// Conventions from DWKK siblings (recordId 480584+): vid=KRA, Series=DWKK, JS Pattern
// numeric, Mfr Pattern dotted Kravet number. CALC FIELDS omitted (combo sku,
// comboskuwithdash, comboskuplussample, Dw Retail Price) — verified post-create.
// Usage: node scripts/create-dwkk-120156.mjs [--commit]   (default = dry-run)

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, createRecord } = await import('../src/fm-client.js');

const DB = 'WALLPAPER';
const LAYOUT = '*List Wallpapers - Shopify Detail Database';
const commit = process.argv.includes('--commit');
const SKU = 'DWKK120156'; // expected value of the "combo sku" calc — guard/verify only

const fieldData = {
  'Series': 'DWKK',
  'vid': 'KRA',
  'JS Pattern': '120156',
  'Mfr Pattern': 'GDT5151.003.0',
  'mfr pattern number': 'GDT5151.003.0',
  'Name of Pattern': 'Albuquerque',
  'Mfr Name of Pattern': 'Albuquerque',
  'Color of Pattern': 'Verde Agua Multi',
  'Mfr Color of Pattern': 'Verde Agua Multi',
  'Collection': 'GASTON UPTOWN',
  'Width': '55"',
  'Record Type': 'Master',
  'Date Line Put Up:': '7/2/2026',
  'Net Price': 205.80,
  'MFR MAP PRICE': 308.70,
};

// fail-closed duplicate guard — probe dashless calc AND dashed variant (standing rule)
for (const [field, value] of [['combo sku', SKU], ['comboskuwithdash', 'DWKK-120156']]) {
  try {
    const { records } = await findRecords(DB, LAYOUT, { [field]: `==${value}` }, { limit: 1 });
    if (records.length) {
      console.log(`SKIP: already exists via ${field}=${value} as recordId ${records[0].recordId}`);
      process.exit(0);
    }
  } catch (e) {
    if (e.fmCode !== '401') throw e; // 401 = no records match = safe to create
  }
}

const res = await createRecord(DB, LAYOUT, fieldData, { dryRun: !commit });
console.log(commit ? `CREATED ${SKU}:` : `DRY RUN ${SKU}:`, JSON.stringify(res, null, 1));

if (commit) {
  const { records } = await findRecords(DB, LAYOUT, { 'combo sku': `==${SKU}` }, { limit: 2 });
  const f = records[0]?.fieldData || {};
  console.log(`VERIFY ${SKU}:`, JSON.stringify({
    recordId: records[0]?.recordId,
    'combo sku': f['combo sku'],
    'comboskuwithdash': f['comboskuwithdash'],
    'comboskuplussample': f['comboskuplussample'],
    'vid': f['vid'],
    'Mfr Pattern': f['Mfr Pattern'],
    'mfr pattern number': f['mfr pattern number'],
    'Name of Pattern': f['Name of Pattern'],
    'Color of Pattern': f['Color of Pattern'],
    'Collection': f['Collection'],
    'Width': f['Width'],
    'Net Price': f['Net Price'],
    'MFR MAP PRICE': f['MFR MAP PRICE'],
    'Dw Retail Price': f['Dw Retail Price'],
    'Record Type': f['Record Type'],
  }, null, 1));
}