import { ShopifyStoreConnector, type ConnectorMeta, type RawRecordLike } from '@rareindex/connectors'; import type { NormalizedRecord } from '@rareindex/shared'; /** * Mattel Creations (creations.mattel.com) — Mattel's official collector shop (Hot Wheels Collectors / Red Line * Club, Matchbox Collectors, Barbie Signature, Masters of the Universe, WWE) on Shopify. Read through the shared * Shopify adapter; this subclass copies the store's "Brand: X" / "Category: Y" tags into brand/metadata and flags * membership-exclusive (RLC) items. Prices are Mattel's own MSRP → every listing also carries originalMsrp. */ export class MattelCreationsConnector extends ShopifyStoreConnector { override async normalize(raw: RawRecordLike): Promise { const out = await super.normalize(raw); for (const r of out) { if (r.kind !== 'listing') continue; const tags = Array.isArray(r.attributes.metadata.tags) ? (r.attributes.metadata.tags as string[]) : []; const tag = (prefix: string) => tags.find((t) => new RegExp(`^${prefix}\\s*:`, 'i').test(t))?.split(':').slice(1).join(':').trim() ?? null; const brand = tag('Brand'); if (brand) r.attributes.brand = brand; r.attributes.metadata.mattel_category = tag('Category'); r.attributes.metadata.age_grade = tag('Filter-AgeGrade'); r.attributes.metadata.members_only = tags.some((t) => /^(RLC|BSM|brand_RLC|brand_BSM|MC_Exclusive)$/i.test(t)); const yearTag = tags.find((t) => /^(19|20)\d{2}$/.test(t)); if (yearTag && r.attributes.year === null) r.attributes.year = Number(yearTag); if (r.price !== null && r.attributes.originalMsrp === null) { r.attributes.originalMsrp = r.price; r.attributes.originalMsrpCurrency = 'USD'; } r.condition = { condition: null, conditionRaw: 'new', completeness: 'sealed' }; } return out; } } export default (meta: ConnectorMeta) => new MattelCreationsConnector(meta);