diff --git a/.tsc-baseline.json b/.tsc-baseline.json index 6f28c286e..a2e8cd559 100644 --- a/.tsc-baseline.json +++ b/.tsc-baseline.json @@ -1,6 +1,6 @@ { - "generatedAt": "2026-05-09T23:55:23.566Z", - "totalErrors": 960, + "generatedAt": "2026-05-10T00:32:16.986Z", + "totalErrors": 924, "counts": { "src/components/admin/DiscountApprovalQueue.tsx": { "TS18048": 1 @@ -695,12 +695,6 @@ "TS2322": 1, "TS2353": 3 }, - "src/lib/external-db/products.ts": { - "TS2345": 13, - "TS2322": 20, - "TS2339": 2, - "TS7053": 1 - }, "src/lib/external-db/techniques.ts": { "TS2322": 19 }, diff --git a/src/lib/external-db/products.ts b/src/lib/external-db/products.ts index 53e3deb24..23ae82082 100644 --- a/src/lib/external-db/products.ts +++ b/src/lib/external-db/products.ts @@ -1,4 +1,3 @@ -import { type ExternalProduct } from "@/types/external-db"; /** * Fetch products with full enrichment (colors, images, variants, suppliers). */ @@ -12,6 +11,24 @@ import { shouldFallbackSelect, } from './product-types'; +// Row shapes for external_db_bridge results (untyped at runtime; assertions below). +type VariantRow = { + id: string; product_id: string; sku?: string | null; + color_id?: string | null; color_name?: string | null; color_code?: string | null; + color_hex?: string | null; stock_quantity?: number | null; + selected_thumbnail?: string | null; images?: string[] | null; +}; +type ImageRow = { + product_id: string; variant_id: string | null; + url_cdn: string; url_original: string | null; filename: string | null; + image_type: string; is_primary: boolean; is_og_image: boolean | null; + applies_to_color: boolean | null; display_order: number; + supplier_code: string | null; alt_text: string | null; title_text: string | null; +}; +type SupplierRow = { id: string; name: string; code: string }; +type ColorVariationRow = { id: string; name: string; slug: string; group_id: string }; +type ColorGroupRow = { id: string; name: string; slug: string }; + export async function fetchPromobrindProducts(options?: { search?: string; limit?: number; @@ -231,31 +248,31 @@ async function enrichProducts( } // Extract results - const variantsRecords: Record[] = []; + const variantsRecords: VariantRow[] = []; for (const idx of queryMap.variants) { const r = batchResults[idx]; - if (r?.success && r.data?.records) variantsRecords.push(...r.data.records); + if (r?.success && r.data?.records) variantsRecords.push(...(r.data.records as VariantRow[])); } - const imagesRecords: Record[] = []; + const imagesRecords: ImageRow[] = []; for (const idx of queryMap.images) { const r = batchResults[idx]; - if (r?.success && r.data?.records) imagesRecords.push(...r.data.records); + if (r?.success && r.data?.records) imagesRecords.push(...(r.data.records as ImageRow[])); } - const suppliersRecords: { id: string; name: string; code: string }[] = []; + const suppliersRecords: SupplierRow[] = []; for (const idx of queryMap.suppliers) { const r = batchResults[idx]; - if (r?.success && r.data?.records) suppliersRecords.push(...(r.data.records as ExternalProduct[])); + if (r?.success && r.data?.records) suppliersRecords.push(...(r.data.records as SupplierRow[])); } - let colorVariationsRecords: Record[] = []; + let colorVariationsRecords: ColorVariationRow[] = []; for (const idx of queryMap.colorVariations) { const r = batchResults[idx]; - if (r?.success && r.data?.records) colorVariationsRecords = r.data.records as unknown[]; + if (r?.success && r.data?.records) colorVariationsRecords = r.data.records as ColorVariationRow[]; } - let colorGroupsRecords: Record[] = []; + let colorGroupsRecords: ColorGroupRow[] = []; for (const idx of queryMap.colorGroups) { const r = batchResults[idx]; - if (r?.success && r.data?.records) colorGroupsRecords = r.data.records as unknown[]; + if (r?.success && r.data?.records) colorGroupsRecords = r.data.records as ColorGroupRow[]; } const suppliersMap = new Map(suppliersRecords.map(s => [s.id, s.name])); @@ -266,8 +283,8 @@ async function enrichProducts( if (s?.id && s?.name) putInCacheSafe('suppliers', { id: s.id, name: s.name, code: s.code }); } } catch { /* cache populate is best-effort */ } - const colorVariationMap = new Map(colorVariationsRecords.map((v) => [v.id as string, { name: v.name as string, slug: v.slug as string, group_id: v.group_id as string }])); - const colorGroupMap = new Map(colorGroupsRecords.map((g) => [g.id as string, { name: g.name as string, slug: g.slug as string }])); + const colorVariationMap = new Map(colorVariationsRecords.map((v) => [v.id, { name: v.name, slug: v.slug, group_id: v.group_id }])); + const colorGroupMap = new Map(colorGroupsRecords.map((g) => [g.id, { name: g.name, slug: g.slug }])); // Build image map const productIdSet = new Set(productIds);