← back to All Designerwallcoverings

scripts/adapters/contrado.js

74 lines

// adapters/contrado.js — Contrado live-stock adapter (PUBLIC-SAFE, SESSION-FREE — MADE-TO-ORDER).
//
// HONEST VERDICT (mined from the contrado-scraper-manager skill + the Import scrapers
// lib/scrapers/contrado-new-products-scraper.ts / contrado-general-scraper.ts, 2026-07-07):
//
//   Contrado (contrado.com) is a CUSTOM PRINT-ON-DEMAND platform — NOT a stocked storefront.
//   Every product is a blank that is manufactured to order at purchase time. There is NO Shopify/Woo
//   `.js` stock feed, no schema.org Offer `availability`, and no visible inventory/stock markup on the
//   anonymous product page: the server-rendered PDP carries only `<title>`, `og:image`, and a "From $X"
//   price. In other words there is NO live-stock signal to read — the item is *always* orderable
//   (made to order), which is categorically different from "in stock" (real on-hand inventory).
//
// Consequences for this adapter (deliberate, honest design):
//   • It does NOT open a metered Browserbase session — there is nothing stock-shaped to scrape, so a
//     paid session would only ever return "unknown". Cost is $0 (no session opened).
//   • It never fakes `in_stock:true`. It returns `in_stock:null` with `availability:'made to order'`,
//     so the grid honestly reflects "made to order — no live stock signal" instead of a green dot.
//   • No login is used or needed. Contrado trade creds DO exist in the dw-price-stock vault
//     (prefix CONTRADO), but the login gates checkout/pricing, not any stock signal — so they are not
//     read here. (Referencing them would still not surface inventory, because none is published.)
//
// PUBLIC-SAFE CONTRACT: availability only. `price` is ALWAYS null — Contrado's public "From $X" is a
// custom-print DTC price, not our retail, so it is never surfaced (same rule as schema-public /
// shopify-public / woo-public).
//
// HONEST-DIM RECOMMENDATION (for build-coverage.js — NOT changed by this file):
//   Contrado should be classified live_capable:false with reason "made to order — no stock signal".
//   It currently sits in build-coverage's SCHEMA_PUBLIC set but fails the resolvability gate (0%), so
//   it already falls through to a dim NO_STOCK tier. The precise, honest home is a SCHEMA_PARSE_PENDING
//   (or equivalent) entry, e.g.:
//     ['contrado', 'Contrado is a custom print-on-demand platform — every product is made to order;
//                   the anonymous PDP publishes no stock feed / schema.org availability, so there is
//                   no live-stock signal to read (sold made-to-order)']
//   That renders the vendor dim with an accurate reason instead of an empty/unknown live check.
const { resolveCatalogUrl } = require('./resolve');

async function run({ sku, pool, catalogTable, log }) {
  const as_of = new Date().toISOString();

  // Opportunistic resolve — attach the product_url when the SKU aligns with the catalog, purely for
  // context. It NEVER gates the verdict: Contrado is made-to-order regardless of which SKU, and (per
  // the 2026-07-07 audit) the grid's "Contrado" display SKUs are print-on-demand apparel/accessory
  // blanks that don't intersect contrado_catalog's wallcovering slugs, so this usually won't resolve.
  let product_url = null;
  try {
    const r = await resolveCatalogUrl(pool, catalogTable || 'contrado_catalog', sku);
    if (r && r.product_url) product_url = r.product_url;
  } catch { /* resolution is optional — the made-to-order verdict does not depend on it */ }

  if (log) log('contrado made-to-order (no session opened, $0)', product_url || '(sku unresolved)');

  // No Browserbase session is opened → session_opened:false, cost $0. `available:true` = the adapter
  // produced a definitive PUBLIC-SAFE result (the made-to-order verdict), not that stock was found.
  return {
    available: true,
    session_opened: false,
    vendor: 'Contrado',
    in_stock: null,                 // no inventory concept — never fake a stock state
    availability: 'made to order',  // print-on-demand: always orderable, manufactured at purchase
    made_to_order: true,
    lead_time: 'made to order (print on demand)',
    price: null,                    // public "From $X" is custom-print DTC, NOT our retail → never emitted
    raw_stock_label: 'made to order — no live stock signal',
    product_url,
    as_of,
    source: 'contrado-live',
    // Surfaced so the grid / coverage layer can dim honestly rather than showing an unknown check.
    dim_recommended: true,
    dim_reason: 'made to order — no stock signal',
  };
}

module.exports = { run };