← back to All Designerwallcoverings
scripts/adapters/index.js
38 lines
// scripts/adapters/index.js — the generalized per-vendor LIVE-STOCK adapter registry.
//
// Each adapter is a module exporting `async run(ctx)` where ctx = { sku, pool, newSession,
// romoLogin, catalogTable, log }. It owns its own login (creds read from the DB — never a
// hardcoded/echoed secret), resolves the SKU's vendor product page, reads stock/availability,
// and returns a PUBLIC-SAFE result:
//
// success: { available:true, session_opened, vendor, in_stock, lead_time, price, raw_stock_label, as_of, source }
// failure: { available:false, session_opened, reason }
//
// PUBLIC-SAFE CONTRACT (enforced by every adapter): only availability + our-RETAIL price ever
// leave here. `price` is emitted ONLY when the adapter can produce our retail (WallQuest transforms
// its cost→retail); portal net/trade prices and vendor DTC prices are NEVER emitted (price:null).
const ADAPTERS = {
wallquest: require('./wallquest'),
romo: require('./romo'),
thibaut: require('./thibaut'), // trade portal — creds referenced in place from the dw-price-stock vault
'shopify-public': require('./shopify-public'),
'woo-public': require('./woo-public'),
'schema-public': require('./schema-public'), // login-free schema.org/Magento availability
koroseal: require('./koroseal'), // login-free Available/Discontinued liveness (spec/sample line — no inventory count)
designtex: require('./designtex'), // login-free schema.org availability (WIRED; parked — grid rows carry no SKU key to route)
schumacher: require('./schumacher'), // vault-portal (WIRED; parked/dim — quote-only line, portal exposes no live stock signal)
fabricut: require('./fabricut'), // vault-portal (WIRED; parked/dim — price-oriented, no stock field; catalog too small)
contrado: require('./contrado'), // made-to-order (WIRED; parked/dim — print-on-demand, no live stock signal exists)
'kravet-db': require('./kravet-db'), // $0 DB read — Kravet-family authoritative MAP price file (no Browserbase session)
};
function get(key) { return ADAPTERS[key] || null; }
async function run(key, ctx) {
const a = get(key);
if (!a) return { available: false, session_opened: false, reason: `no adapter '${key}'` };
return a.run(ctx);
}
module.exports = { run, get, keys: () => Object.keys(ADAPTERS) };