← back to Filemaker Mcp
pull-wallpaper-combosku.mjs
36 lines
// One-off: page ALL live WALLPAPER combo skus → /tmp/fm_wallpaper_combosku.txt
// Reuses the MCP's fm-client (Claris ID auth). Read-only. TK-10483 audit.
import fs from 'fs';
const env = JSON.parse(fs.readFileSync('/tmp/fmenv.json','utf8'));
for (const [k,v] of Object.entries(env)) process.env[k] = v;
const fm = await import('./src/fm-client.js');
const DB = 'WALLPAPER', LAYOUT = 'Basic List of Fields', PAGE = 1000;
const norm = s => (s||'').toUpperCase().replace(/[^A-Z0-9]/g,'');
const set = new Set();
let offset = 1, total = null, pages = 0;
const t0 = Date.now();
while (true) {
let res, tries = 0;
while (true) {
try { res = await fm.listRecords(DB, LAYOUT, { limit: PAGE, offset }); break; }
catch (e) {
if (++tries >= 4) throw e;
await new Promise(r => setTimeout(r, 1500 * tries));
}
}
total = res?.dataInfo?.totalRecordCount ?? total;
const recs = res?.records || [];
if (!recs.length) break;
for (const r of recs) { const c = norm(r.fieldData?.['combo sku']); if (c) set.add(c); }
pages++;
offset += PAGE;
if (pages % 20 === 0) console.error(` page ${pages} offset ${offset-1}/${total} distinct=${set.size} ${((Date.now()-t0)/1000|0)}s`);
if (total && offset > total) break;
}
fs.writeFileSync('/tmp/fm_wallpaper_combosku.txt', [...set].join('\n') + '\n');
console.error(`DONE pages=${pages} total_records=${total} distinct_combosku=${set.size} elapsed=${((Date.now()-t0)/1000|0)}s`);
console.log(JSON.stringify({ pages, total, distinct: set.size }));