whale-code 6.5.7 → 6.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +14 -2
  2. package/dist/cli/services/agent-loop.js +26 -2
  3. package/dist/cli/services/agent-loop.js.map +1 -1
  4. package/dist/cli/services/hooks.js +2 -1
  5. package/dist/cli/services/hooks.js.map +1 -1
  6. package/dist/cli/services/telemetry-spans.js +1 -0
  7. package/dist/cli/services/telemetry-spans.js.map +1 -1
  8. package/dist/cli/services/telemetry.d.ts +23 -0
  9. package/dist/cli/services/telemetry.js +45 -1
  10. package/dist/cli/services/telemetry.js.map +1 -1
  11. package/dist/server/handlers/__test-utils__/test-db.d.ts +17 -3
  12. package/dist/server/handlers/__test-utils__/test-db.js +113 -14
  13. package/dist/server/handlers/__test-utils__/test-db.js.map +1 -1
  14. package/dist/server/handlers/affiliates.d.ts +9 -0
  15. package/dist/server/handlers/affiliates.js +197 -0
  16. package/dist/server/handlers/affiliates.js.map +1 -0
  17. package/dist/server/handlers/api-docs.d.ts +4 -2
  18. package/dist/server/handlers/api-docs.js +204 -1681
  19. package/dist/server/handlers/api-docs.js.map +1 -1
  20. package/dist/server/handlers/campaigns.d.ts +9 -0
  21. package/dist/server/handlers/campaigns.js +237 -0
  22. package/dist/server/handlers/campaigns.js.map +1 -0
  23. package/dist/server/handlers/catalog-schemas.js +9 -9
  24. package/dist/server/handlers/catalog-schemas.js.map +1 -1
  25. package/dist/server/handlers/catalog.js +1 -1
  26. package/dist/server/handlers/catalog.js.map +1 -1
  27. package/dist/server/handlers/comms-documents.js +28 -2
  28. package/dist/server/handlers/comms-documents.js.map +1 -1
  29. package/dist/server/handlers/comms-pdf-generation.js +25 -3
  30. package/dist/server/handlers/comms-pdf-generation.js.map +1 -1
  31. package/dist/server/handlers/comms-pdf-helpers.js +4 -4
  32. package/dist/server/handlers/comms-pdf-helpers.js.map +1 -1
  33. package/dist/server/handlers/comms.d.ts +100 -0
  34. package/dist/server/handlers/comms.js +146 -12
  35. package/dist/server/handlers/comms.js.map +1 -1
  36. package/dist/server/handlers/coupons.d.ts +9 -0
  37. package/dist/server/handlers/coupons.js +220 -0
  38. package/dist/server/handlers/coupons.js.map +1 -0
  39. package/dist/server/handlers/embeddings.js +1 -1
  40. package/dist/server/handlers/embeddings.js.map +1 -1
  41. package/dist/server/handlers/enrichment.js +2 -622
  42. package/dist/server/handlers/enrichment.js.map +1 -1
  43. package/dist/server/handlers/fulfillment.d.ts +9 -0
  44. package/dist/server/handlers/fulfillment.js +209 -0
  45. package/dist/server/handlers/fulfillment.js.map +1 -0
  46. package/dist/server/handlers/google-ads.d.ts +24 -0
  47. package/dist/server/handlers/google-ads.js +2199 -0
  48. package/dist/server/handlers/google-ads.js.map +1 -0
  49. package/dist/server/handlers/invoices.d.ts +9 -0
  50. package/dist/server/handlers/invoices.js +252 -0
  51. package/dist/server/handlers/invoices.js.map +1 -0
  52. package/dist/server/handlers/loyalty.d.ts +9 -0
  53. package/dist/server/handlers/loyalty.js +197 -0
  54. package/dist/server/handlers/loyalty.js.map +1 -0
  55. package/dist/server/handlers/meta-ads-graph-api.js +18 -3
  56. package/dist/server/handlers/meta-ads-graph-api.js.map +1 -1
  57. package/dist/server/handlers/phone.d.ts +9 -0
  58. package/dist/server/handlers/phone.js +197 -0
  59. package/dist/server/handlers/phone.js.map +1 -0
  60. package/dist/server/handlers/pipeline.d.ts +9 -0
  61. package/dist/server/handlers/pipeline.js +277 -0
  62. package/dist/server/handlers/pipeline.js.map +1 -0
  63. package/dist/server/handlers/qr-codes.d.ts +9 -0
  64. package/dist/server/handlers/qr-codes.js +198 -0
  65. package/dist/server/handlers/qr-codes.js.map +1 -0
  66. package/dist/server/handlers/reviews.d.ts +9 -0
  67. package/dist/server/handlers/reviews.js +171 -0
  68. package/dist/server/handlers/reviews.js.map +1 -0
  69. package/dist/server/handlers/segments.d.ts +9 -0
  70. package/dist/server/handlers/segments.js +229 -0
  71. package/dist/server/handlers/segments.js.map +1 -0
  72. package/dist/server/handlers/social.d.ts +9 -0
  73. package/dist/server/handlers/social.js +81 -0
  74. package/dist/server/handlers/social.js.map +1 -0
  75. package/dist/server/handlers/tax.d.ts +9 -0
  76. package/dist/server/handlers/tax.js +182 -0
  77. package/dist/server/handlers/tax.js.map +1 -0
  78. package/dist/server/handlers/wallet.d.ts +9 -0
  79. package/dist/server/handlers/wallet.js +203 -0
  80. package/dist/server/handlers/wallet.js.map +1 -0
  81. package/dist/server/handlers/webhooks-mgmt.d.ts +9 -0
  82. package/dist/server/handlers/webhooks-mgmt.js +181 -0
  83. package/dist/server/handlers/webhooks-mgmt.js.map +1 -0
  84. package/dist/server/handlers/wholesale.d.ts +9 -0
  85. package/dist/server/handlers/wholesale.js +219 -0
  86. package/dist/server/handlers/wholesale.js.map +1 -0
  87. package/dist/server/index.js +20 -9
  88. package/dist/server/index.js.map +1 -1
  89. package/dist/server/lib/clickhouse-buffer.js +1 -0
  90. package/dist/server/lib/clickhouse-buffer.js.map +1 -1
  91. package/dist/server/lib/coa-renderer.d.ts +1 -1
  92. package/dist/server/lib/coa-renderer.js +32 -10
  93. package/dist/server/lib/coa-renderer.js.map +1 -1
  94. package/dist/server/server-worker.d.ts +1 -0
  95. package/dist/server/server-worker.js +464 -3
  96. package/dist/server/server-worker.js.map +1 -1
  97. package/dist/server/tool-router.js +118 -4
  98. package/dist/server/tool-router.js.map +1 -1
  99. package/package.json +28 -4
  100. package/vendor/ink/package.json +0 -2
  101. package/whale-logo.png +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.js","names":["sanitizeFilterValue","handleProducts","sb","args","storeId","sid","action","data","cats","error","catErr","from","select","eq","order","ascending","success","message","count","activeCount","head","neq","archivedCount","categories","product_status_summary","active","archived","tip","offset","q","limit","range","query","sq","String","or","category","category_id","catInput","catVal","matchedCatId","test","ilike","length","id","children","catIds","map","c","in","catalog_id","status","include_archived","featured","undefined","totalCount","flattened","row","rest","category_name","name","total","pid","product_id","product","pErr","single","fieldSchemas","pricingSchemas","inventory","field_schemas","fs","field_schema","pricing_schemas","ps","pricing_schema","insert","store_id","sku","description","short_description","type","cost_price","wholesale_price","stock_quantity","manage_stock","weight","tax_status","tax_class","pricing_data","featured_image","image_gallery","is_wholesale","wholesale_only","minimum_wholesale_quantity","catArg","primary_category_id","pricing_schema_id","field_schema_ids","Array","isArray","rows","fsId","field_schema_id","pricing_schema_ids","psId","productUpdates","inherited","categoryId","cat","upsert","onConflict","fields","schemaKeys","Set","fieldValues","f","key","add","default","agentValues","custom_fields","k","v","Object","entries","has","push","catFieldSchemas","cat2","filter","r","tiers","keys","update","full","updates","agentFV","pfs","fsDef","existing","base","filtered","Boolean","updateCatArg","hard","delete","deleted","parent_id","active_only","catId","fieldAssigns","pricingAssigns","a","sort_order","subcategories","slug","toLowerCase","replace","icon","display_order","i","is_active","public_only","schema_id","assignments","assigned_categories","catalogId","defaultCatalog","is_public","deleted_at","Date","toISOString","quality_tier","store","owner_user_id","vertical","is_default","settings","target","schemaType","schema_type","targetId","target_id","schemaId","targetTable","ownerCheck","ownerErr","schemaTable","schemaCheck","schemaErr","table","fkCol","schemaCol","schema","rebuilt","removed","all","allErr","nameMap","Map","p","normalized","trim","set","get","duplicates","_","products","normalizedName","normalized_name","created_at","skuMap","skuDupes","totalNameDupes","reduce","s","d","totalSkuDupes","lines","group","slice","join","primaryId","primary_product_id","secondaryId","secondary_product_id","primary","secondary","reassignResults","secInv","quantity","priRow","location_id","maybeSingle","updated_at","oiErr","oiCount","order_items","ciErr","ciCount","cart_items","poiErr","poiCount","purchase_order_items","prErr","prCount","product_reviews","fillFields","fills","field","merged","field_fills","merged_product","archived_product","reassign_results","handleCollections","sn"],"sources":["../../../src/server/handlers/catalog.ts"],"sourcesContent":["import type { SupabaseClient } from \"@supabase/supabase-js\";\nimport { sanitizeFilterValue } from \"../lib/utils.js\";\n\n// ============================================================================\n// PRODUCTS — Full product catalog management\n// Products, categories, field schemas, pricing schemas, catalogs, assignments\n// ============================================================================\n\nexport async function handleProducts(sb: SupabaseClient, args: Record<string, unknown>, storeId?: string) {\n const sid = storeId as string;\n switch (args.action) {\n\n // ======================== PRODUCTS ========================\n\n case \"browse\": {\n // Category summary with product counts, price ranges, stock status\n const { data: cats, error: catErr } = await sb.from(\"categories\")\n .select(\"id, name, slug, parent_id, display_order, product_count, catalog_id\")\n .eq(\"store_id\", sid)\n .eq(\"is_active\", true)\n .order(\"display_order\", { ascending: true });\n if (catErr) return { success: false, error: catErr.message };\n\n // Status distribution via count queries\n const { count: activeCount } = await sb.from(\"products\").select(\"id\", { count: \"exact\", head: true }).eq(\"store_id\", sid).neq(\"status\", \"archived\");\n const { count: archivedCount } = await sb.from(\"products\").select(\"id\", { count: \"exact\", head: true }).eq(\"store_id\", sid).eq(\"status\", \"archived\");\n\n return {\n success: true,\n data: {\n categories: cats,\n product_status_summary: { active: activeCount || 0, archived: archivedCount || 0 },\n tip: \"Use products.find with category or status filters to drill into a specific set. Use products.get for full product detail.\"\n }\n };\n }\n\n case \"find\": {\n const offset = args.offset as number || 0;\n let q = sb.from(\"products\")\n .select(\"id, name, sku, status, type, stock_quantity, category:categories!primary_category_id(name)\", { count: \"exact\" })\n .eq(\"store_id\", sid)\n .order(\"created_at\", { ascending: false });\n if (args.limit) {\n q = q.range(offset, offset + (args.limit as number) - 1);\n } else if (offset > 0) {\n q = q.range(offset, offset + 999);\n }\n if (args.query) { const sq = sanitizeFilterValue(String(args.query)); q = q.or(`name.ilike.%${sq}%,sku.ilike.%${sq}%,description.ilike.%${sq}%`); }\n if (args.category || args.category_id) {\n // Accept both category (name or UUID) and category_id (UUID)\n const catInput = (args.category_id || args.category) as string;\n const catVal = sanitizeFilterValue(catInput);\n let matchedCatId: string | null = null;\n if (/^[0-9a-f]{8}-/.test(catVal)) {\n matchedCatId = catVal;\n } else {\n const { data: cats } = await sb.from(\"categories\").select(\"id\").ilike(\"name\", `%${catVal}%`).eq(\"store_id\", sid).limit(1);\n if (cats?.length) matchedCatId = cats[0].id;\n }\n if (matchedCatId) {\n // Include sub-categories (children of the matched category)\n const { data: children } = await sb.from(\"categories\").select(\"id\").eq(\"parent_id\", matchedCatId).eq(\"store_id\", sid);\n const catIds = [matchedCatId, ...(children || []).map(c => c.id)];\n q = q.in(\"primary_category_id\", catIds);\n } else {\n // Category not found — return empty result\n q = q.eq(\"primary_category_id\", \"00000000-0000-0000-0000-000000000000\");\n }\n }\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.status) q = q.eq(\"status\", args.status as string);\n // Exclude archived unless explicitly requested or filtering by status\n if (!args.status && !args.include_archived) {\n q = q.neq(\"status\", \"archived\");\n }\n if (args.featured !== undefined) q = q.eq(\"featured\", args.featured as boolean);\n const { data, error, count: totalCount } = await q;\n if (error) return { success: false, error: error.message };\n // Flatten nested category for display\n const flattened = (data || []).map((row: any) => {\n const { category, ...rest } = row;\n return { ...rest, category_name: category?.name || null };\n });\n return { success: true, total: totalCount, count: flattened.length, offset, ...(args.limit ? { limit: args.limit } : {}), data: flattened };\n }\n\n case \"get\": {\n const pid = args.product_id as string;\n const { data: product, error: pErr } = await sb.from(\"products\")\n .select(\"*, category:categories!primary_category_id(id, name, slug)\")\n .eq(\"id\", pid).eq(\"store_id\", sid).single();\n if (pErr) return { success: false, error: pErr.message };\n\n const { data: fieldSchemas } = await sb.from(\"product_field_schemas\")\n .select(\"field_schema_id, field_schema:field_schemas!field_schema_id(id, name, fields, icon)\")\n .eq(\"product_id\", pid);\n\n const { data: pricingSchemas } = await sb.from(\"product_pricing_schemas\")\n .select(\"pricing_schema_id, pricing_schema:pricing_schemas!pricing_schema_id(id, name, tiers, quality_tier)\")\n .eq(\"product_id\", pid);\n\n const { data: inventory } = await sb.from(\"inventory\")\n .select(\"id, quantity, location:locations!location_id(id, name)\")\n .eq(\"product_id\", pid).eq(\"store_id\", sid);\n\n return {\n success: true,\n data: {\n ...product,\n field_schemas: fieldSchemas?.map(fs => fs.field_schema) || [],\n pricing_schemas: pricingSchemas?.map(ps => ps.pricing_schema) || [],\n inventory: inventory || []\n }\n };\n }\n\n case \"create\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n const insert: Record<string, unknown> = { store_id: sid, name };\n if (args.sku) insert.sku = args.sku;\n if (args.description) insert.description = args.description;\n if (args.short_description) insert.short_description = args.short_description;\n if (args.type) insert.type = args.type;\n if (args.status) insert.status = args.status;\n if (args.cost_price !== undefined) insert.cost_price = args.cost_price;\n if (args.wholesale_price !== undefined) insert.wholesale_price = args.wholesale_price;\n if (args.featured !== undefined) insert.featured = args.featured;\n if (args.stock_quantity !== undefined) insert.stock_quantity = args.stock_quantity;\n if (args.manage_stock !== undefined) insert.manage_stock = args.manage_stock;\n if (args.weight !== undefined) insert.weight = args.weight;\n if (args.tax_status) insert.tax_status = args.tax_status;\n if (args.tax_class) insert.tax_class = args.tax_class;\n if (args.catalog_id) insert.catalog_id = args.catalog_id;\n if (args.pricing_data) insert.pricing_data = args.pricing_data;\n // custom_fields NOT inserted directly — schema is the source of truth\n // Agent-provided custom_fields are filtered against schema keys post-insert\n if (args.featured_image !== undefined) insert.featured_image = args.featured_image;\n if (args.image_gallery !== undefined) insert.image_gallery = args.image_gallery;\n if (args.is_wholesale !== undefined) insert.is_wholesale = args.is_wholesale;\n if (args.wholesale_only !== undefined) insert.wholesale_only = args.wholesale_only;\n if (args.minimum_wholesale_quantity !== undefined) insert.minimum_wholesale_quantity = args.minimum_wholesale_quantity;\n const catArg = (args.category || args.primary_category_id || args.category_id) as string | undefined;\n if (catArg) {\n if (/^[0-9a-f]{8}-/.test(catArg)) {\n insert.primary_category_id = catArg;\n } else {\n const { data: cats } = await sb.from(\"categories\").select(\"id\").ilike(\"name\", `%${catArg}%`).eq(\"store_id\", sid).limit(1);\n if (cats?.length) insert.primary_category_id = cats[0].id;\n }\n }\n if (args.pricing_schema_id) insert.pricing_schema_id = args.pricing_schema_id;\n\n const { data, error } = await sb.from(\"products\").insert(insert).select(\"id, name, sku, slug, status, primary_category_id, pricing_schema_id, created_at\").single();\n if (error) return { success: false, error: error.message };\n\n // Explicit schema assignments from args\n if (args.field_schema_ids && Array.isArray(args.field_schema_ids)) {\n const rows = (args.field_schema_ids as string[]).map(fsId => ({ product_id: data.id, field_schema_id: fsId }));\n await sb.from(\"product_field_schemas\").insert(rows);\n }\n if (args.pricing_schema_ids && Array.isArray(args.pricing_schema_ids)) {\n const rows = (args.pricing_schema_ids as string[]).map(psId => ({ product_id: data.id, pricing_schema_id: psId }));\n await sb.from(\"product_pricing_schemas\").insert(rows);\n }\n\n const productUpdates: Record<string, unknown> = {};\n const inherited: string[] = [];\n\n // Auto-inherit field schema from category — ALWAYS merge with schema template\n const categoryId = insert.primary_category_id as string | undefined;\n if (categoryId && !args.field_schema_ids) {\n const { data: cat } = await sb.from(\"categories\").select(\"field_schema_id\").eq(\"id\", categoryId).single();\n if (cat?.field_schema_id) {\n await sb.from(\"product_field_schemas\").upsert(\n { product_id: data.id, field_schema_id: cat.field_schema_id },\n { onConflict: \"product_id,field_schema_id\" }\n );\n // Schema is source of truth — only schema keys allowed\n const { data: fs } = await sb.from(\"field_schemas\").select(\"fields\").eq(\"id\", cat.field_schema_id).single();\n if (fs?.fields && Array.isArray(fs.fields)) {\n const schemaKeys = new Set<string>();\n const fieldValues: Record<string, unknown> = {};\n for (const f of fs.fields) {\n const key = (f as any).key;\n if (key) { schemaKeys.add(key); fieldValues[key] = (f as any).default ?? null; }\n }\n // Only accept agent values for keys that exist in the schema\n const agentValues = (args.custom_fields as Record<string, unknown>) || {};\n for (const [k, v] of Object.entries(agentValues)) {\n if (schemaKeys.has(k)) fieldValues[k] = v;\n }\n productUpdates.custom_fields = fieldValues;\n }\n inherited.push(`field_schema:${cat.field_schema_id}`);\n }\n // Also check junction table for additional schemas\n const { data: catFieldSchemas } = await sb.from(\"category_field_schemas\").select(\"field_schema_id\").eq(\"category_id\", categoryId);\n if (catFieldSchemas?.length) {\n const cat2 = await sb.from(\"categories\").select(\"field_schema_id\").eq(\"id\", categoryId).single();\n const rows = catFieldSchemas.filter(r => r.field_schema_id !== cat2?.data?.field_schema_id).map(r => ({ product_id: data.id, field_schema_id: r.field_schema_id }));\n if (rows.length) await sb.from(\"product_field_schemas\").insert(rows);\n }\n }\n\n // If pricing_schema_id provided, hydrate pricing_data from schema\n if (insert.pricing_schema_id && !args.pricing_data) {\n const { data: ps } = await sb.from(\"pricing_schemas\").select(\"tiers\").eq(\"id\", insert.pricing_schema_id as string).single();\n if (ps?.tiers) productUpdates.pricing_data = ps.tiers;\n }\n\n // Apply any post-insert updates\n if (Object.keys(productUpdates).length > 0) {\n await sb.from(\"products\").update(productUpdates).eq(\"id\", data.id);\n }\n\n // Re-read the full product for response\n const { data: full } = await sb.from(\"products\")\n .select(\"id, name, sku, slug, status, primary_category_id, pricing_schema_id, custom_fields, pricing_data, created_at\")\n .eq(\"id\", data.id).single();\n if (inherited.length && full) (full as any).inherited = inherited;\n\n return { success: true, data: full || data };\n }\n\n case \"update\": {\n const pid = args.product_id as string;\n if (!pid) return { success: false, error: \"product_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.sku !== undefined) updates.sku = args.sku;\n if (args.description !== undefined) updates.description = args.description;\n if (args.short_description !== undefined) updates.short_description = args.short_description;\n if (args.type !== undefined) updates.type = args.type;\n if (args.status !== undefined) updates.status = args.status;\n if (args.cost_price !== undefined) updates.cost_price = args.cost_price;\n if (args.wholesale_price !== undefined) updates.wholesale_price = args.wholesale_price;\n if (args.featured !== undefined) updates.featured = args.featured;\n if (args.stock_quantity !== undefined) updates.stock_quantity = args.stock_quantity;\n if (args.manage_stock !== undefined) updates.manage_stock = args.manage_stock;\n if (args.weight !== undefined) updates.weight = args.weight;\n if (args.tax_status !== undefined) updates.tax_status = args.tax_status;\n if (args.tax_class !== undefined) updates.tax_class = args.tax_class;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n if (args.pricing_schema_id !== undefined) updates.pricing_schema_id = args.pricing_schema_id;\n if (args.pricing_data !== undefined) updates.pricing_data = args.pricing_data;\n // custom_fields filtered to schema keys only (schema = source of truth)\n if (args.custom_fields !== undefined) {\n const agentFV = args.custom_fields as Record<string, unknown>;\n // Look up product's linked field schema to get allowed keys\n const { data: pfs } = await sb.from(\"product_field_schemas\").select(\"field_schema_id\").eq(\"product_id\", pid).limit(1);\n if (pfs?.length) {\n const { data: fsDef } = await sb.from(\"field_schemas\").select(\"fields\").eq(\"id\", pfs[0].field_schema_id).single();\n if (fsDef?.fields && Array.isArray(fsDef.fields)) {\n const { data: existing } = await sb.from(\"products\").select(\"custom_fields\").eq(\"id\", pid).single();\n const base = (existing?.custom_fields as Record<string, unknown>) || {};\n const filtered: Record<string, unknown> = { ...base };\n const schemaKeys = new Set(fsDef.fields.map((f: any) => f.key).filter(Boolean));\n for (const [k, v] of Object.entries(agentFV)) {\n if (schemaKeys.has(k)) filtered[k] = v;\n }\n updates.custom_fields = filtered;\n } else {\n updates.custom_fields = agentFV; // no schema definition found, pass through\n }\n } else {\n updates.custom_fields = agentFV; // no schema linked, pass through\n }\n }\n if (args.is_wholesale !== undefined) updates.is_wholesale = args.is_wholesale;\n if (args.wholesale_only !== undefined) updates.wholesale_only = args.wholesale_only;\n if (args.minimum_wholesale_quantity !== undefined) updates.minimum_wholesale_quantity = args.minimum_wholesale_quantity;\n if (args.featured_image !== undefined) updates.featured_image = args.featured_image;\n if (args.image_gallery !== undefined) updates.image_gallery = args.image_gallery;\n const updateCatArg = (args.category ?? args.primary_category_id ?? args.category_id) as string | undefined;\n if (updateCatArg !== undefined) {\n if (!updateCatArg) { updates.primary_category_id = null; }\n else if (/^[0-9a-f]{8}-/.test(updateCatArg)) { updates.primary_category_id = updateCatArg; }\n else {\n const { data: cats } = await sb.from(\"categories\").select(\"id\").ilike(\"name\", `%${updateCatArg}%`).eq(\"store_id\", sid).limit(1);\n if (cats?.length) updates.primary_category_id = cats[0].id;\n }\n }\n\n const { data, error } = await sb.from(\"products\")\n .update(updates).eq(\"id\", pid).eq(\"store_id\", sid)\n .select(\"id, name, sku, slug, status, cost_price, pricing_schema_id, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete\": {\n const pid = args.product_id as string;\n if (!pid) return { success: false, error: \"product_id is required\" };\n if (args.hard === true) {\n const { error } = await sb.from(\"products\").delete().eq(\"id\", pid).eq(\"store_id\", sid);\n return error ? { success: false, error: error.message } : { success: true, data: { id: pid, deleted: true } };\n }\n const { data, error } = await sb.from(\"products\")\n .update({ status: \"archived\" }).eq(\"id\", pid).eq(\"store_id\", sid)\n .select(\"id, name, status\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== CATEGORIES ========================\n\n case \"list_categories\": {\n let q = sb.from(\"categories\")\n .select(\"id, name, slug, description, icon, parent_id, display_order, is_active, featured, product_count, catalog_id, field_schema_id, created_at\")\n .eq(\"store_id\", sid)\n .order(\"display_order\", { ascending: true });\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.parent_id) q = q.eq(\"parent_id\", args.parent_id as string);\n if (args.active_only !== false) q = q.eq(\"is_active\", true);\n const { data, error } = await q.limit(args.limit as number || 100);\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"get_category\": {\n const catId = args.category_id as string;\n const { data: cat, error: catErr } = await sb.from(\"categories\")\n .select(\"*\").eq(\"id\", catId).eq(\"store_id\", sid).single();\n if (catErr) return { success: false, error: catErr.message };\n\n const { data: fieldAssigns } = await sb.from(\"category_field_schemas\")\n .select(\"sort_order, is_active, field_schema:field_schemas!field_schema_id(id, name, fields, icon)\")\n .eq(\"category_id\", catId).eq(\"is_active\", true).order(\"sort_order\");\n\n const { data: pricingAssigns } = await sb.from(\"category_pricing_schemas\")\n .select(\"sort_order, is_active, pricing_schema:pricing_schemas!pricing_schema_id(id, name, tiers, quality_tier)\")\n .eq(\"category_id\", catId).eq(\"is_active\", true).order(\"sort_order\");\n\n const { data: children } = await sb.from(\"categories\")\n .select(\"id, name, slug, display_order, is_active, product_count\")\n .eq(\"parent_id\", catId).order(\"display_order\");\n\n return {\n success: true,\n data: {\n ...cat,\n field_schemas: fieldAssigns?.map(a => ({ ...a.field_schema, sort_order: a.sort_order })) || [],\n pricing_schemas: pricingAssigns?.map(a => ({ ...a.pricing_schema, sort_order: a.sort_order })) || [],\n subcategories: children || []\n }\n };\n }\n\n case \"create_category\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n const insert: Record<string, unknown> = { store_id: sid, name, slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\") };\n if (args.description) insert.description = args.description;\n if (args.icon) insert.icon = args.icon;\n if (args.parent_id) insert.parent_id = args.parent_id;\n if (args.catalog_id) insert.catalog_id = args.catalog_id;\n if (args.display_order !== undefined) insert.display_order = args.display_order;\n if (args.field_schema_id) insert.field_schema_id = args.field_schema_id;\n\n const { data, error } = await sb.from(\"categories\").insert(insert)\n .select(\"id, name, slug, parent_id, catalog_id, display_order, created_at\").single();\n if (error) return { success: false, error: error.message };\n\n if (args.field_schema_ids && Array.isArray(args.field_schema_ids)) {\n const rows = (args.field_schema_ids as string[]).map((fsId, i) => ({ category_id: data.id, field_schema_id: fsId, sort_order: i + 1 }));\n await sb.from(\"category_field_schemas\").insert(rows);\n }\n if (args.pricing_schema_ids && Array.isArray(args.pricing_schema_ids)) {\n const rows = (args.pricing_schema_ids as string[]).map((psId, i) => ({ category_id: data.id, pricing_schema_id: psId, sort_order: i + 1 }));\n await sb.from(\"category_pricing_schemas\").insert(rows);\n }\n\n return { success: true, data };\n }\n\n case \"update_category\": {\n const catId = args.category_id as string;\n if (!catId) return { success: false, error: \"category_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.icon !== undefined) updates.icon = args.icon;\n if (args.parent_id !== undefined) updates.parent_id = args.parent_id;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n if (args.display_order !== undefined) updates.display_order = args.display_order;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.featured !== undefined) updates.featured = args.featured;\n if (args.field_schema_id !== undefined) updates.field_schema_id = args.field_schema_id;\n\n const { data, error } = await sb.from(\"categories\")\n .update(updates).eq(\"id\", catId).eq(\"store_id\", sid)\n .select(\"id, name, slug, is_active, display_order, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete_category\": {\n const catId = args.category_id as string;\n if (!catId) return { success: false, error: \"category_id is required\" };\n if (args.hard === true) {\n const { error } = await sb.from(\"categories\").delete().eq(\"id\", catId).eq(\"store_id\", sid);\n return error ? { success: false, error: error.message } : { success: true, data: { id: catId, deleted: true } };\n }\n const { data, error } = await sb.from(\"categories\")\n .update({ is_active: false }).eq(\"id\", catId).eq(\"store_id\", sid)\n .select(\"id, name, is_active\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== FIELD SCHEMAS ========================\n\n case \"list_field_schemas\": {\n let q = sb.from(\"field_schemas\")\n .select(\"id, name, slug, description, icon, fields, is_public, is_active, catalog_id, store_id, install_count, created_at\")\n .eq(\"is_active\", true);\n // Show store-owned schemas AND public schemas (prevent IDOR)\n if (args.public_only === true) {\n q = q.eq(\"is_public\", true);\n } else {\n q = q.or(`store_id.eq.${sid},is_public.eq.true`);\n }\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.limit) q = q.limit(args.limit as number);\n const { data, error } = await q.order(\"name\");\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"get_field_schema\": {\n const fsId = (args.field_schema_id || args.schema_id) as string;\n if (!fsId) return { success: false, error: \"field_schema_id is required\" };\n // Allow access to own schemas OR public schemas (prevent IDOR)\n const { data, error } = await sb.from(\"field_schemas\").select(\"*\").eq(\"id\", fsId)\n .or(`store_id.eq.${sid},is_public.eq.true`).single();\n if (error) return { success: false, error: error.message };\n\n const { data: assignments } = await sb.from(\"category_field_schemas\")\n .select(\"category:categories!category_id(id, name)\").eq(\"field_schema_id\", fsId).eq(\"is_active\", true);\n\n return { success: true, data: { ...data, assigned_categories: assignments?.map(a => a.category) || [] } };\n }\n\n case \"create_field_schema\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n if (!args.fields || !Array.isArray(args.fields)) return { success: false, error: \"fields array is required\" };\n\n // Auto-resolve catalog_id: use provided value, or fall back to store's default catalog\n let catalogId = args.catalog_id as string | undefined;\n if (!catalogId) {\n const { data: defaultCatalog } = await sb.from(\"catalogs\")\n .select(\"id\").eq(\"store_id\", sid).eq(\"is_default\", true).single();\n if (defaultCatalog) catalogId = defaultCatalog.id;\n }\n\n const insert: Record<string, unknown> = {\n store_id: sid,\n name,\n slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\"),\n fields: args.fields\n };\n if (args.description) insert.description = args.description;\n if (args.icon) insert.icon = args.icon;\n if (catalogId) insert.catalog_id = catalogId;\n if (args.is_public !== undefined) insert.is_public = args.is_public;\n\n const { data, error } = await sb.from(\"field_schemas\").insert(insert)\n .select(\"id, name, slug, fields, icon, is_active, catalog_id, created_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"update_field_schema\": {\n const fsId = (args.field_schema_id || args.schema_id) as string;\n if (!fsId) return { success: false, error: \"field_schema_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.icon !== undefined) updates.icon = args.icon;\n if (args.fields !== undefined) updates.fields = args.fields;\n if (args.is_public !== undefined) updates.is_public = args.is_public;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n\n // Only allow modification of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"field_schemas\")\n .update(updates).eq(\"id\", fsId).eq(\"store_id\", sid)\n .select(\"id, name, slug, fields, icon, is_active, catalog_id, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete_field_schema\": {\n const fsId = (args.field_schema_id || args.schema_id) as string;\n if (!fsId) return { success: false, error: \"field_schema_id is required\" };\n // Only allow deletion of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"field_schemas\")\n .update({ is_active: false, deleted_at: new Date().toISOString() }).eq(\"id\", fsId).eq(\"store_id\", sid)\n .select(\"id, name, is_active\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== PRICING SCHEMAS ========================\n\n case \"list_pricing_schemas\": {\n let q = sb.from(\"pricing_schemas\")\n .select(\"id, name, slug, description, tiers, quality_tier, is_public, is_active, catalog_id, store_id, install_count, created_at\")\n .eq(\"is_active\", true);\n // Show store-owned schemas AND public schemas (prevent IDOR)\n if (args.public_only === true) {\n q = q.eq(\"is_public\", true);\n } else {\n q = q.or(`store_id.eq.${sid},is_public.eq.true`);\n }\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.limit) q = q.limit(args.limit as number);\n const { data, error } = await q.order(\"name\");\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"get_pricing_schema\": {\n const psId = (args.pricing_schema_id || args.schema_id) as string;\n if (!psId) return { success: false, error: \"pricing_schema_id is required\" };\n // Allow access to own schemas OR public schemas (prevent IDOR)\n const { data, error } = await sb.from(\"pricing_schemas\").select(\"*\").eq(\"id\", psId)\n .or(`store_id.eq.${sid},is_public.eq.true`).single();\n if (error) return { success: false, error: error.message };\n\n const { data: assignments } = await sb.from(\"category_pricing_schemas\")\n .select(\"category:categories!category_id(id, name)\").eq(\"pricing_schema_id\", psId).eq(\"is_active\", true);\n\n return { success: true, data: { ...data, assigned_categories: assignments?.map(a => a.category) || [] } };\n }\n\n case \"create_pricing_schema\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n if (!args.tiers || !Array.isArray(args.tiers)) return { success: false, error: \"tiers array is required\" };\n\n // Auto-resolve catalog_id: use provided value, or fall back to store's default catalog\n let catalogId = args.catalog_id as string | undefined;\n if (!catalogId) {\n const { data: defaultCatalog } = await sb.from(\"catalogs\")\n .select(\"id\").eq(\"store_id\", sid).eq(\"is_default\", true).single();\n if (defaultCatalog) catalogId = defaultCatalog.id;\n }\n\n const insert: Record<string, unknown> = {\n store_id: sid,\n name,\n slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\"),\n tiers: args.tiers\n };\n if (args.description) insert.description = args.description;\n if (args.quality_tier) insert.quality_tier = args.quality_tier;\n if (catalogId) insert.catalog_id = catalogId;\n if (args.is_public !== undefined) insert.is_public = args.is_public;\n\n const { data, error } = await sb.from(\"pricing_schemas\").insert(insert)\n .select(\"id, name, slug, tiers, quality_tier, is_active, catalog_id, created_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"update_pricing_schema\": {\n const psId = (args.pricing_schema_id || args.schema_id) as string;\n if (!psId) return { success: false, error: \"pricing_schema_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.tiers !== undefined) updates.tiers = args.tiers;\n if (args.quality_tier !== undefined) updates.quality_tier = args.quality_tier;\n if (args.is_public !== undefined) updates.is_public = args.is_public;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n\n // Only allow modification of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"pricing_schemas\")\n .update(updates).eq(\"id\", psId).eq(\"store_id\", sid)\n .select(\"id, name, slug, tiers, quality_tier, is_active, catalog_id, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete_pricing_schema\": {\n const psId = (args.pricing_schema_id || args.schema_id) as string;\n if (!psId) return { success: false, error: \"pricing_schema_id is required\" };\n // Only allow deletion of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"pricing_schemas\")\n .update({ is_active: false, deleted_at: new Date().toISOString() }).eq(\"id\", psId).eq(\"store_id\", sid)\n .select(\"id, name, is_active\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== CATALOGS ========================\n\n case \"list_catalogs\": {\n const { data, error } = await sb.from(\"catalogs\")\n .select(\"id, name, slug, description, vertical, is_active, is_default, display_order, created_at\")\n .eq(\"store_id\", sid).order(\"display_order\");\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"create_catalog\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n // Resolve owner_user_id from store\n const { data: store } = await sb.from(\"stores\").select(\"owner_user_id\").eq(\"id\", sid).single();\n const insert: Record<string, unknown> = {\n store_id: sid, name,\n slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\"),\n owner_user_id: store?.owner_user_id\n };\n if (args.description) insert.description = args.description;\n if (args.vertical) insert.vertical = args.vertical;\n if (args.is_default !== undefined) insert.is_default = args.is_default;\n if (args.settings) insert.settings = args.settings;\n\n const { data, error } = await sb.from(\"catalogs\").insert(insert)\n .select(\"id, name, slug, vertical, is_default, created_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"update_catalog\": {\n const catId = args.catalog_id as string;\n if (!catId) return { success: false, error: \"catalog_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.vertical !== undefined) updates.vertical = args.vertical;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.is_default !== undefined) updates.is_default = args.is_default;\n if (args.settings !== undefined) updates.settings = args.settings;\n if (args.display_order !== undefined) updates.display_order = args.display_order;\n\n const { data, error } = await sb.from(\"catalogs\")\n .update(updates).eq(\"id\", catId).eq(\"store_id\", sid)\n .select(\"id, name, slug, vertical, is_active, is_default, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== SCHEMA ASSIGNMENTS ========================\n\n case \"assign_schema\": {\n const target = args.target as string; // \"category\" or \"product\"\n const schemaType = args.schema_type as string; // \"field\" or \"pricing\"\n const targetId = args.target_id as string;\n const schemaId = args.schema_id as string;\n if (!target || !schemaType || !targetId || !schemaId) {\n return { success: false, error: \"target (category|product), schema_type (field|pricing), target_id, and schema_id are required\" };\n }\n\n // Verify target product/category belongs to this store (prevent IDOR)\n const targetTable = target === \"product\" ? \"products\" : \"categories\";\n const { data: ownerCheck, error: ownerErr } = await sb.from(targetTable)\n .select(\"id\").eq(\"id\", targetId).eq(\"store_id\", sid).single();\n if (ownerErr || !ownerCheck) {\n return { success: false, error: `${target} not found or does not belong to this store` };\n }\n\n // Verify schema is accessible (own schema or public)\n const schemaTable = schemaType === \"field\" ? \"field_schemas\" : \"pricing_schemas\";\n const { data: schemaCheck, error: schemaErr } = await sb.from(schemaTable)\n .select(\"id\").eq(\"id\", schemaId).or(`store_id.eq.${sid},is_public.eq.true`).single();\n if (schemaErr || !schemaCheck) {\n return { success: false, error: `${schemaType} schema not found or not accessible` };\n }\n\n const table = target === \"product\"\n ? (schemaType === \"field\" ? \"product_field_schemas\" : \"product_pricing_schemas\")\n : (schemaType === \"field\" ? \"category_field_schemas\" : \"category_pricing_schemas\");\n const fkCol = target === \"product\" ? \"product_id\" : \"category_id\";\n const schemaCol = schemaType === \"field\" ? \"field_schema_id\" : \"pricing_schema_id\";\n\n const row: Record<string, unknown> = { [fkCol]: targetId, [schemaCol]: schemaId };\n if (args.sort_order !== undefined) row.sort_order = args.sort_order;\n\n const { data, error } = await sb.from(table).upsert(row, { onConflict: `${fkCol},${schemaCol}` }).select().single();\n if (error) return { success: false, error: error.message };\n\n // Hydrate product with schema data\n if (target === \"product\") {\n const productUpdates: Record<string, unknown> = {};\n if (schemaType === \"pricing\") {\n const { data: schema } = await sb.from(\"pricing_schemas\").select(\"tiers, quality_tier\").eq(\"id\", schemaId).single();\n productUpdates.pricing_schema_id = schemaId;\n if (schema?.tiers) productUpdates.pricing_data = schema.tiers;\n }\n if (schemaType === \"field\") {\n // Schema is source of truth — rebuild custom_fields from schema keys only\n const { data: schema } = await sb.from(\"field_schemas\").select(\"fields\").eq(\"id\", schemaId).single();\n if (schema?.fields && Array.isArray(schema.fields)) {\n const { data: product } = await sb.from(\"products\").select(\"custom_fields\").eq(\"id\", targetId).eq(\"store_id\", sid).single();\n const existing = (product?.custom_fields as Record<string, unknown>) || {};\n const rebuilt: Record<string, unknown> = {};\n for (const f of schema.fields) {\n const key = (f as any).key;\n if (key) rebuilt[key] = (key in existing) ? existing[key] : ((f as any).default ?? null);\n }\n productUpdates.custom_fields = rebuilt;\n }\n }\n if (Object.keys(productUpdates).length > 0) {\n await sb.from(\"products\").update(productUpdates).eq(\"id\", targetId).eq(\"store_id\", sid);\n }\n }\n\n return { success: true, data };\n }\n\n case \"unassign_schema\": {\n const target = args.target as string;\n const schemaType = args.schema_type as string;\n const targetId = args.target_id as string;\n const schemaId = args.schema_id as string;\n if (!target || !schemaType || !targetId || !schemaId) {\n return { success: false, error: \"target (category|product), schema_type (field|pricing), target_id, and schema_id are required\" };\n }\n\n // Verify target product/category belongs to this store (prevent IDOR)\n const targetTable = target === \"product\" ? \"products\" : \"categories\";\n const { data: ownerCheck, error: ownerErr } = await sb.from(targetTable)\n .select(\"id\").eq(\"id\", targetId).eq(\"store_id\", sid).single();\n if (ownerErr || !ownerCheck) {\n return { success: false, error: `${target} not found or does not belong to this store` };\n }\n\n const table = target === \"product\"\n ? (schemaType === \"field\" ? \"product_field_schemas\" : \"product_pricing_schemas\")\n : (schemaType === \"field\" ? \"category_field_schemas\" : \"category_pricing_schemas\");\n const fkCol = target === \"product\" ? \"product_id\" : \"category_id\";\n const schemaCol = schemaType === \"field\" ? \"field_schema_id\" : \"pricing_schema_id\";\n\n const { error } = await sb.from(table).delete().eq(fkCol, targetId).eq(schemaCol, schemaId);\n return error ? { success: false, error: error.message } : { success: true, data: { removed: true, target, schema_type: schemaType, target_id: targetId, schema_id: schemaId } };\n }\n\n // ======================== PRODUCT DEDUP / MERGE ========================\n\n case \"find_duplicates\": {\n // Find products with similar names (potential duplicates)\n const { data: all, error: allErr } = await sb.from(\"products\")\n .select(\"id, name, sku, status, stock_quantity, cost_price, created_at\")\n .eq(\"store_id\", sid).neq(\"status\", \"archived\")\n .order(\"name\");\n if (allErr) return { success: false, error: allErr.message };\n\n // Group by normalized name (lowercase, trim, strip common suffixes like \"(TEMP)\", \"(OLD)\", \"(COPY)\")\n const nameMap = new Map<string, typeof all>();\n for (const p of all || []) {\n const normalized = (p.name || \"\").toLowerCase().trim()\n .replace(/\\s*\\((temp|old|copy|duplicate|dup|new|v2)\\)\\s*/gi, \"\")\n .replace(/\\s+/g, \" \");\n if (!normalized) continue;\n if (!nameMap.has(normalized)) nameMap.set(normalized, []);\n nameMap.get(normalized)!.push(p);\n }\n\n const duplicates = Array.from(nameMap.entries())\n .filter(([_, products]) => products.length > 1)\n .map(([normalizedName, products]) => ({\n normalized_name: normalizedName,\n count: products.length,\n products: products.map(p => ({\n id: p.id, name: p.name, sku: p.sku, status: p.status,\n stock_quantity: p.stock_quantity, cost_price: p.cost_price, created_at: p.created_at,\n })),\n }));\n\n // Also check by exact SKU match\n const skuMap = new Map<string, typeof all>();\n for (const p of all || []) {\n if (!p.sku) continue;\n const key = p.sku.toLowerCase().trim();\n if (!skuMap.has(key)) skuMap.set(key, []);\n skuMap.get(key)!.push(p);\n }\n const skuDupes = Array.from(skuMap.entries())\n .filter(([_, products]) => products.length > 1)\n .map(([sku, products]) => ({ sku, count: products.length, products }));\n\n // Pre-format as markdown — formatter drops nested products arrays\n const totalNameDupes = duplicates.reduce((s, d) => s + d.count, 0);\n const totalSkuDupes = skuDupes.reduce((s, d) => s + d.count, 0);\n const lines: string[] = [\n `## Duplicate Products`,\n `**By Name**: ${duplicates.length} groups (${totalNameDupes} products) | **By SKU**: ${skuDupes.length} groups (${totalSkuDupes} products)\\n`,\n ];\n if (duplicates.length > 0) {\n lines.push(\"### Name Duplicates\");\n for (const group of duplicates.slice(0, 20)) {\n lines.push(`\\n**\"${group.normalized_name}\"** (${group.count} products):`);\n lines.push(\"| Name | SKU | Status | Stock | Created |\");\n lines.push(\"| --- | --- | --- | ---: | --- |\");\n for (const p of group.products) {\n lines.push(`| ${p.name} | ${p.sku || \"—\"} | ${p.status} | ${p.stock_quantity ?? \"—\"} | ${p.created_at?.slice(0, 10) || \"—\"} |`);\n }\n }\n }\n if (skuDupes.length > 0) {\n lines.push(\"\\n### SKU Duplicates\");\n for (const group of skuDupes.slice(0, 20)) {\n lines.push(`\\n**SKU \"${group.sku}\"** (${group.count} products):`);\n lines.push(\"| Name | SKU | Status | Stock | Created |\");\n lines.push(\"| --- | --- | --- | ---: | --- |\");\n for (const p of group.products) {\n lines.push(`| ${(p as any).name} | ${(p as any).sku || \"—\"} | ${(p as any).status} | ${(p as any).stock_quantity ?? \"—\"} | ${(p as any).created_at?.slice(0, 10) || \"—\"} |`);\n }\n }\n }\n if (duplicates.length === 0 && skuDupes.length === 0) {\n lines.push(\"\\nNo duplicates found.\");\n }\n return { success: true, data: lines.join(\"\\n\") };\n }\n\n case \"merge\": {\n const primaryId = args.primary_product_id as string;\n const secondaryId = args.secondary_product_id as string;\n if (!primaryId || !secondaryId) return { success: false, error: \"primary_product_id and secondary_product_id required\" };\n if (primaryId === secondaryId) return { success: false, error: \"Cannot merge a product with itself\" };\n\n // Verify both exist and belong to this store\n const { data: primary } = await sb.from(\"products\").select(\"*\").eq(\"id\", primaryId).eq(\"store_id\", sid).single();\n const { data: secondary } = await sb.from(\"products\").select(\"*\").eq(\"id\", secondaryId).eq(\"store_id\", sid).single();\n if (!primary) return { success: false, error: `Primary product ${primaryId} not found` };\n if (!secondary) return { success: false, error: `Secondary product ${secondaryId} not found` };\n\n const reassignResults: Record<string, string> = {};\n\n // 1. Consolidate inventory — sum quantities per location\n const { data: secInv } = await sb.from(\"inventory\")\n .select(\"product_id, location_id, quantity\")\n .eq(\"product_id\", secondaryId).eq(\"store_id\", sid);\n if (secInv?.length) {\n for (const row of secInv) {\n if (!row.quantity || row.quantity <= 0) continue;\n // Try to add to existing primary inventory at same location\n const { data: priRow } = await sb.from(\"inventory\")\n .select(\"id, quantity\")\n .eq(\"product_id\", primaryId).eq(\"location_id\", row.location_id).eq(\"store_id\", sid)\n .maybeSingle();\n if (priRow) {\n await sb.from(\"inventory\").update({ quantity: (priRow.quantity || 0) + row.quantity, updated_at: new Date().toISOString() }).eq(\"id\", priRow.id);\n } else {\n await sb.from(\"inventory\").insert({ store_id: sid, product_id: primaryId, location_id: row.location_id, quantity: row.quantity });\n }\n }\n // Zero out secondary inventory\n await sb.from(\"inventory\").update({ quantity: 0 }).eq(\"product_id\", secondaryId).eq(\"store_id\", sid);\n reassignResults.inventory = `consolidated ${secInv.length} location(s)`;\n } else {\n reassignResults.inventory = \"no inventory to consolidate\";\n }\n\n // 2. Reassign order_items\n const { error: oiErr, count: oiCount } = await sb.from(\"order_items\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.order_items = oiErr ? `error: ${oiErr.message}` : `moved ${oiCount ?? 0} rows`;\n\n // 3. Reassign cart_items\n const { error: ciErr, count: ciCount } = await sb.from(\"cart_items\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.cart_items = ciErr ? `error: ${ciErr.message}` : `moved ${ciCount ?? 0} rows`;\n\n // 4. Reassign purchase_order_items\n const { error: poiErr, count: poiCount } = await sb.from(\"purchase_order_items\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.purchase_order_items = poiErr ? `error: ${poiErr.message}` : `moved ${poiCount ?? 0} rows`;\n\n // 5. Reassign product_reviews\n const { error: prErr, count: prCount } = await sb.from(\"product_reviews\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.product_reviews = prErr ? `error: ${prErr.message}` : `moved ${prCount ?? 0} rows`;\n\n // 6. Fill in missing fields on primary from secondary\n const fillFields = [\"description\", \"short_description\", \"cost_price\", \"wholesale_price\", \"weight\", \"featured_image\", \"image_gallery\"] as const;\n const fills: Record<string, unknown> = {};\n for (const field of fillFields) {\n if (!primary[field] && secondary[field]) fills[field] = secondary[field];\n }\n // Merge custom_fields (secondary fills gaps)\n if (secondary.custom_fields && typeof secondary.custom_fields === \"object\") {\n const merged = { ...(secondary.custom_fields as Record<string, unknown>), ...(primary.custom_fields as Record<string, unknown> || {}) };\n fills.custom_fields = merged;\n }\n if (Object.keys(fills).length > 0) {\n await sb.from(\"products\").update(fills).eq(\"id\", primaryId).eq(\"store_id\", sid);\n reassignResults.field_fills = Object.keys(fills).join(\", \");\n }\n\n // 7. Archive the secondary product\n await sb.from(\"products\").update({\n status: \"archived\",\n name: `[MERGED] ${secondary.name}`,\n }).eq(\"id\", secondaryId).eq(\"store_id\", sid);\n\n // Re-read primary\n const { data: merged } = await sb.from(\"products\")\n .select(\"id, name, sku, status, stock_quantity, cost_price, created_at, updated_at\")\n .eq(\"id\", primaryId).single();\n\n return {\n success: true,\n data: {\n merged_product: merged,\n archived_product: { id: secondaryId, name: secondary.name },\n reassign_results: reassignResults,\n }\n };\n }\n\n default:\n return { success: false, error: `Unknown products action: ${args.action}. Valid: browse, find, get, create, update, delete, find_duplicates, merge, list_categories, get_category, create_category, update_category, delete_category, list_field_schemas, get_field_schema, create_field_schema, update_field_schema, delete_field_schema, list_pricing_schemas, get_pricing_schema, create_pricing_schema, update_pricing_schema, delete_pricing_schema, list_catalogs, create_catalog, update_catalog, assign_schema, unassign_schema` };\n }\n}\n\nexport async function handleCollections(sb: SupabaseClient, args: Record<string, unknown>, storeId?: string) {\n const sid = storeId as string;\n switch (args.action) {\n case \"find\": {\n let q = sb.from(\"creation_collections\").select(\"*\").eq(\"store_id\", sid);\n if (args.name) { const sn = sanitizeFilterValue(args.name as string); q = q.ilike(\"name\", `%${sn}%`); }\n const { data, error } = await q.limit(100);\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n case \"create\": {\n const slug = (args.slug as string) || (args.name as string || \"\").toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\");\n const { data, error } = await sb.from(\"creation_collections\")\n .insert({ store_id: sid, name: args.name, slug }).select().single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n default:\n return { success: false, error: `Unknown collections action: ${args.action}` };\n }\n}\n"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,iBAAiB;;AAErD;AACA;AACA;AACA;;AAEA,OAAO,eAAeC,cAAcA,CAACC,EAAkB,EAAEC,IAA6B,EAAEC,OAAgB,EAAE;EACxG,MAAMC,GAAG,GAAGD,OAAiB;EAC7B,QAAQD,IAAI,CAACG,MAAM;IAEjB;;IAEA,KAAK,QAAQ;MAAE;QACb;QACA,MAAM;UAAEC,IAAI,EAAEC,IAAI;UAAEC,KAAK,EAAEC;QAAO,CAAC,GAAG,MAAMR,EAAE,CAACS,IAAI,CAAC,YAAY,CAAC,CAC9DC,MAAM,CAAC,qEAAqE,CAAC,CAC7EC,EAAE,CAAC,UAAU,EAAER,GAAG,CAAC,CACnBQ,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,CACrBC,KAAK,CAAC,eAAe,EAAE;UAAEC,SAAS,EAAE;QAAK,CAAC,CAAC;QAC9C,IAAIL,MAAM,EAAE,OAAO;UAAEM,OAAO,EAAE,KAAK;UAAEP,KAAK,EAAEC,MAAM,CAACO;QAAQ,CAAC;;QAE5D;QACA,MAAM;UAAEC,KAAK,EAAEC;QAAY,CAAC,GAAG,MAAMjB,EAAE,CAACS,IAAI,CAAC,UAAU,CAAC,CAACC,MAAM,CAAC,IAAI,EAAE;UAAEM,KAAK,EAAE,OAAO;UAAEE,IAAI,EAAE;QAAK,CAAC,CAAC,CAACP,EAAE,CAAC,UAAU,EAAER,GAAG,CAA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IACA;MACE,OAAO;QAAES,OAAO,EAAE,KAAK;QAAEP,KAAK,EAAE,+BAA+BN,IAAI,CAACG,MAAM;MAAG,CAAC;EAClF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"catalog.js","names":["sanitizeFilterValue","handleProducts","sb","args","storeId","sid","action","data","cats","error","catErr","from","select","eq","order","ascending","success","message","count","activeCount","head","neq","archivedCount","categories","product_status_summary","active","archived","tip","offset","q","limit","range","query","sq","String","or","category","category_id","catInput","catVal","matchedCatId","test","ilike","length","id","children","catIds","map","c","in","catalog_id","status","include_archived","featured","undefined","totalCount","flattened","row","rest","category_name","name","total","pid","product_id","product","pErr","single","fieldSchemas","pricingSchemas","inventory","field_schemas","fs","field_schema","pricing_schemas","ps","pricing_schema","insert","store_id","sku","description","short_description","type","cost_price","wholesale_price","stock_quantity","manage_stock","weight","tax_status","tax_class","pricing_data","featured_image","image_gallery","is_wholesale","wholesale_only","minimum_wholesale_quantity","catArg","primary_category_id","pricing_schema_id","field_schema_ids","Array","isArray","rows","fsId","field_schema_id","pricing_schema_ids","psId","productUpdates","inherited","categoryId","cat","upsert","onConflict","fields","schemaKeys","Set","fieldValues","f","key","add","default","agentValues","custom_fields","k","v","Object","entries","has","push","catFieldSchemas","cat2","filter","r","tiers","keys","update","full","updates","agentFV","pfs","fsDef","existing","base","filtered","Boolean","updateCatArg","hard","delete","deleted","parent_id","active_only","catId","fieldAssigns","pricingAssigns","a","sort_order","subcategories","slug","toLowerCase","replace","icon","display_order","i","is_active","public_only","schema_id","assignments","assigned_categories","catalogId","defaultCatalog","is_public","deleted_at","Date","toISOString","quality_tier","store","owner_user_id","vertical","is_default","settings","target","schemaType","schema_type","targetId","target_id","schemaId","targetTable","ownerCheck","ownerErr","schemaTable","schemaCheck","schemaErr","table","fkCol","schemaCol","schema","rebuilt","removed","all","allErr","nameMap","Map","p","normalized","trim","set","get","duplicates","_","products","normalizedName","normalized_name","created_at","skuMap","skuDupes","totalNameDupes","reduce","s","d","totalSkuDupes","lines","group","slice","join","primaryId","primary_product_id","secondaryId","secondary_product_id","primary","secondary","reassignResults","secInv","quantity","priRow","location_id","maybeSingle","updated_at","oiErr","oiCount","order_items","ciErr","ciCount","cart_items","poiErr","poiCount","purchase_order_items","prErr","prCount","product_reviews","fillFields","fills","field","merged","field_fills","merged_product","archived_product","reassign_results","handleCollections","sn"],"sources":["../../../src/server/handlers/catalog.ts"],"sourcesContent":["import type { SupabaseClient } from \"@supabase/supabase-js\";\nimport { sanitizeFilterValue } from \"../lib/utils.js\";\n\n// ============================================================================\n// PRODUCTS — Full product catalog management\n// Products, categories, field schemas, pricing schemas, catalogs, assignments\n// ============================================================================\n\nexport async function handleProducts(sb: SupabaseClient, args: Record<string, unknown>, storeId?: string) {\n const sid = storeId as string;\n switch (args.action) {\n\n // ======================== PRODUCTS ========================\n\n case \"browse\": {\n // Category summary with product counts, price ranges, stock status\n const { data: cats, error: catErr } = await sb.from(\"categories\")\n .select(\"id, name, slug, parent_id, display_order, product_count, catalog_id\")\n .eq(\"store_id\", sid)\n .eq(\"is_active\", true)\n .order(\"display_order\", { ascending: true });\n if (catErr) return { success: false, error: catErr.message };\n\n // Status distribution via count queries\n const { count: activeCount } = await sb.from(\"products\").select(\"id\", { count: \"exact\", head: true }).eq(\"store_id\", sid).neq(\"status\", \"archived\");\n const { count: archivedCount } = await sb.from(\"products\").select(\"id\", { count: \"exact\", head: true }).eq(\"store_id\", sid).eq(\"status\", \"archived\");\n\n return {\n success: true,\n data: {\n categories: cats,\n product_status_summary: { active: activeCount || 0, archived: archivedCount || 0 },\n tip: \"Use products.find with category or status filters to drill into a specific set. Use products.get for full product detail.\"\n }\n };\n }\n\n case \"find\": {\n const offset = args.offset as number || 0;\n let q = sb.from(\"products\")\n .select(\"id, name, sku, status, type, stock_quantity, category:categories!primary_category_id(name)\", { count: \"exact\" })\n .eq(\"store_id\", sid)\n .order(\"created_at\", { ascending: false });\n if (args.limit) {\n q = q.range(offset, offset + (args.limit as number) - 1);\n } else if (offset > 0) {\n q = q.range(offset, offset + 999);\n }\n if (args.query) { const sq = sanitizeFilterValue(String(args.query)); q = q.or(`name.ilike.%${sq}%,sku.ilike.%${sq}%,description.ilike.%${sq}%`); }\n if (args.category || args.category_id) {\n // Accept both category (name or UUID) and category_id (UUID)\n const catInput = (args.category_id || args.category) as string;\n const catVal = sanitizeFilterValue(catInput);\n let matchedCatId: string | null = null;\n if (/^[0-9a-f]{8}-/.test(catVal)) {\n matchedCatId = catVal;\n } else {\n const { data: cats } = await sb.from(\"categories\").select(\"id\").ilike(\"name\", `%${catVal}%`).eq(\"store_id\", sid).limit(1);\n if (cats?.length) matchedCatId = cats[0].id;\n }\n if (matchedCatId) {\n // Include sub-categories (children of the matched category)\n const { data: children } = await sb.from(\"categories\").select(\"id\").eq(\"parent_id\", matchedCatId).eq(\"store_id\", sid);\n const catIds = [matchedCatId, ...(children || []).map(c => c.id)];\n q = q.in(\"primary_category_id\", catIds);\n } else {\n // Category not found — return empty result\n q = q.eq(\"primary_category_id\", \"00000000-0000-0000-0000-000000000000\");\n }\n }\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.status) q = q.eq(\"status\", args.status as string);\n // Exclude archived unless explicitly requested or filtering by status\n if (!args.status && !args.include_archived) {\n q = q.neq(\"status\", \"archived\");\n }\n if (args.featured !== undefined) q = q.eq(\"featured\", args.featured as boolean);\n const { data, error, count: totalCount } = await q;\n if (error) return { success: false, error: error.message };\n // Flatten nested category for display\n const flattened = (data || []).map((row: any) => {\n const { category, ...rest } = row;\n return { ...rest, category_name: category?.name || null };\n });\n return { success: true, total: totalCount, count: flattened.length, offset, ...(args.limit ? { limit: args.limit } : {}), data: flattened };\n }\n\n case \"get\": {\n const pid = args.product_id as string;\n const { data: product, error: pErr } = await sb.from(\"products\")\n .select(\"*, category:categories!primary_category_id(id, name, slug)\")\n .eq(\"id\", pid).eq(\"store_id\", sid).neq(\"status\", \"archived\").single();\n if (pErr) return { success: false, error: pErr.message };\n\n const { data: fieldSchemas } = await sb.from(\"product_field_schemas\")\n .select(\"field_schema_id, field_schema:field_schemas!field_schema_id(id, name, fields, icon)\")\n .eq(\"product_id\", pid);\n\n const { data: pricingSchemas } = await sb.from(\"product_pricing_schemas\")\n .select(\"pricing_schema_id, pricing_schema:pricing_schemas!pricing_schema_id(id, name, tiers, quality_tier)\")\n .eq(\"product_id\", pid);\n\n const { data: inventory } = await sb.from(\"inventory\")\n .select(\"id, quantity, location:locations!location_id(id, name)\")\n .eq(\"product_id\", pid).eq(\"store_id\", sid);\n\n return {\n success: true,\n data: {\n ...product,\n field_schemas: fieldSchemas?.map(fs => fs.field_schema) || [],\n pricing_schemas: pricingSchemas?.map(ps => ps.pricing_schema) || [],\n inventory: inventory || []\n }\n };\n }\n\n case \"create\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n const insert: Record<string, unknown> = { store_id: sid, name };\n if (args.sku) insert.sku = args.sku;\n if (args.description) insert.description = args.description;\n if (args.short_description) insert.short_description = args.short_description;\n if (args.type) insert.type = args.type;\n if (args.status) insert.status = args.status;\n if (args.cost_price !== undefined) insert.cost_price = args.cost_price;\n if (args.wholesale_price !== undefined) insert.wholesale_price = args.wholesale_price;\n if (args.featured !== undefined) insert.featured = args.featured;\n if (args.stock_quantity !== undefined) insert.stock_quantity = args.stock_quantity;\n if (args.manage_stock !== undefined) insert.manage_stock = args.manage_stock;\n if (args.weight !== undefined) insert.weight = args.weight;\n if (args.tax_status) insert.tax_status = args.tax_status;\n if (args.tax_class) insert.tax_class = args.tax_class;\n if (args.catalog_id) insert.catalog_id = args.catalog_id;\n if (args.pricing_data) insert.pricing_data = args.pricing_data;\n // custom_fields NOT inserted directly — schema is the source of truth\n // Agent-provided custom_fields are filtered against schema keys post-insert\n if (args.featured_image !== undefined) insert.featured_image = args.featured_image;\n if (args.image_gallery !== undefined) insert.image_gallery = args.image_gallery;\n if (args.is_wholesale !== undefined) insert.is_wholesale = args.is_wholesale;\n if (args.wholesale_only !== undefined) insert.wholesale_only = args.wholesale_only;\n if (args.minimum_wholesale_quantity !== undefined) insert.minimum_wholesale_quantity = args.minimum_wholesale_quantity;\n const catArg = (args.category || args.primary_category_id || args.category_id) as string | undefined;\n if (catArg) {\n if (/^[0-9a-f]{8}-/.test(catArg)) {\n insert.primary_category_id = catArg;\n } else {\n const { data: cats } = await sb.from(\"categories\").select(\"id\").ilike(\"name\", `%${catArg}%`).eq(\"store_id\", sid).limit(1);\n if (cats?.length) insert.primary_category_id = cats[0].id;\n }\n }\n if (args.pricing_schema_id) insert.pricing_schema_id = args.pricing_schema_id;\n\n const { data, error } = await sb.from(\"products\").insert(insert).select(\"id, name, sku, slug, status, primary_category_id, pricing_schema_id, created_at\").single();\n if (error) return { success: false, error: error.message };\n\n // Explicit schema assignments from args\n if (args.field_schema_ids && Array.isArray(args.field_schema_ids)) {\n const rows = (args.field_schema_ids as string[]).map(fsId => ({ product_id: data.id, field_schema_id: fsId }));\n await sb.from(\"product_field_schemas\").insert(rows);\n }\n if (args.pricing_schema_ids && Array.isArray(args.pricing_schema_ids)) {\n const rows = (args.pricing_schema_ids as string[]).map(psId => ({ product_id: data.id, pricing_schema_id: psId }));\n await sb.from(\"product_pricing_schemas\").insert(rows);\n }\n\n const productUpdates: Record<string, unknown> = {};\n const inherited: string[] = [];\n\n // Auto-inherit field schema from category — ALWAYS merge with schema template\n const categoryId = insert.primary_category_id as string | undefined;\n if (categoryId && !args.field_schema_ids) {\n const { data: cat } = await sb.from(\"categories\").select(\"field_schema_id\").eq(\"id\", categoryId).single();\n if (cat?.field_schema_id) {\n await sb.from(\"product_field_schemas\").upsert(\n { product_id: data.id, field_schema_id: cat.field_schema_id },\n { onConflict: \"product_id,field_schema_id\" }\n );\n // Schema is source of truth — only schema keys allowed\n const { data: fs } = await sb.from(\"field_schemas\").select(\"fields\").eq(\"id\", cat.field_schema_id).single();\n if (fs?.fields && Array.isArray(fs.fields)) {\n const schemaKeys = new Set<string>();\n const fieldValues: Record<string, unknown> = {};\n for (const f of fs.fields) {\n const key = (f as any).key;\n if (key) { schemaKeys.add(key); fieldValues[key] = (f as any).default ?? null; }\n }\n // Only accept agent values for keys that exist in the schema\n const agentValues = (args.custom_fields as Record<string, unknown>) || {};\n for (const [k, v] of Object.entries(agentValues)) {\n if (schemaKeys.has(k)) fieldValues[k] = v;\n }\n productUpdates.custom_fields = fieldValues;\n }\n inherited.push(`field_schema:${cat.field_schema_id}`);\n }\n // Also check junction table for additional schemas\n const { data: catFieldSchemas } = await sb.from(\"category_field_schemas\").select(\"field_schema_id\").eq(\"category_id\", categoryId);\n if (catFieldSchemas?.length) {\n const cat2 = await sb.from(\"categories\").select(\"field_schema_id\").eq(\"id\", categoryId).single();\n const rows = catFieldSchemas.filter(r => r.field_schema_id !== cat2?.data?.field_schema_id).map(r => ({ product_id: data.id, field_schema_id: r.field_schema_id }));\n if (rows.length) await sb.from(\"product_field_schemas\").insert(rows);\n }\n }\n\n // If pricing_schema_id provided, hydrate pricing_data from schema\n if (insert.pricing_schema_id && !args.pricing_data) {\n const { data: ps } = await sb.from(\"pricing_schemas\").select(\"tiers\").eq(\"id\", insert.pricing_schema_id as string).single();\n if (ps?.tiers) productUpdates.pricing_data = ps.tiers;\n }\n\n // Apply any post-insert updates\n if (Object.keys(productUpdates).length > 0) {\n await sb.from(\"products\").update(productUpdates).eq(\"id\", data.id);\n }\n\n // Re-read the full product for response\n const { data: full } = await sb.from(\"products\")\n .select(\"id, name, sku, slug, status, primary_category_id, pricing_schema_id, custom_fields, pricing_data, created_at\")\n .eq(\"id\", data.id).single();\n if (inherited.length && full) (full as any).inherited = inherited;\n\n return { success: true, data: full || data };\n }\n\n case \"update\": {\n const pid = args.product_id as string;\n if (!pid) return { success: false, error: \"product_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.sku !== undefined) updates.sku = args.sku;\n if (args.description !== undefined) updates.description = args.description;\n if (args.short_description !== undefined) updates.short_description = args.short_description;\n if (args.type !== undefined) updates.type = args.type;\n if (args.status !== undefined) updates.status = args.status;\n if (args.cost_price !== undefined) updates.cost_price = args.cost_price;\n if (args.wholesale_price !== undefined) updates.wholesale_price = args.wholesale_price;\n if (args.featured !== undefined) updates.featured = args.featured;\n if (args.stock_quantity !== undefined) updates.stock_quantity = args.stock_quantity;\n if (args.manage_stock !== undefined) updates.manage_stock = args.manage_stock;\n if (args.weight !== undefined) updates.weight = args.weight;\n if (args.tax_status !== undefined) updates.tax_status = args.tax_status;\n if (args.tax_class !== undefined) updates.tax_class = args.tax_class;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n if (args.pricing_schema_id !== undefined) updates.pricing_schema_id = args.pricing_schema_id;\n if (args.pricing_data !== undefined) updates.pricing_data = args.pricing_data;\n // custom_fields filtered to schema keys only (schema = source of truth)\n if (args.custom_fields !== undefined) {\n const agentFV = args.custom_fields as Record<string, unknown>;\n // Look up product's linked field schema to get allowed keys\n const { data: pfs } = await sb.from(\"product_field_schemas\").select(\"field_schema_id\").eq(\"product_id\", pid).limit(1);\n if (pfs?.length) {\n const { data: fsDef } = await sb.from(\"field_schemas\").select(\"fields\").eq(\"id\", pfs[0].field_schema_id).single();\n if (fsDef?.fields && Array.isArray(fsDef.fields)) {\n const { data: existing } = await sb.from(\"products\").select(\"custom_fields\").eq(\"id\", pid).single();\n const base = (existing?.custom_fields as Record<string, unknown>) || {};\n const filtered: Record<string, unknown> = { ...base };\n const schemaKeys = new Set(fsDef.fields.map((f: any) => f.key).filter(Boolean));\n for (const [k, v] of Object.entries(agentFV)) {\n if (schemaKeys.has(k)) filtered[k] = v;\n }\n updates.custom_fields = filtered;\n } else {\n updates.custom_fields = agentFV; // no schema definition found, pass through\n }\n } else {\n updates.custom_fields = agentFV; // no schema linked, pass through\n }\n }\n if (args.is_wholesale !== undefined) updates.is_wholesale = args.is_wholesale;\n if (args.wholesale_only !== undefined) updates.wholesale_only = args.wholesale_only;\n if (args.minimum_wholesale_quantity !== undefined) updates.minimum_wholesale_quantity = args.minimum_wholesale_quantity;\n if (args.featured_image !== undefined) updates.featured_image = args.featured_image;\n if (args.image_gallery !== undefined) updates.image_gallery = args.image_gallery;\n const updateCatArg = (args.category ?? args.primary_category_id ?? args.category_id) as string | undefined;\n if (updateCatArg !== undefined) {\n if (!updateCatArg) { updates.primary_category_id = null; }\n else if (/^[0-9a-f]{8}-/.test(updateCatArg)) { updates.primary_category_id = updateCatArg; }\n else {\n const { data: cats } = await sb.from(\"categories\").select(\"id\").ilike(\"name\", `%${updateCatArg}%`).eq(\"store_id\", sid).limit(1);\n if (cats?.length) updates.primary_category_id = cats[0].id;\n }\n }\n\n const { data, error } = await sb.from(\"products\")\n .update(updates).eq(\"id\", pid).eq(\"store_id\", sid)\n .select(\"id, name, sku, slug, status, cost_price, pricing_schema_id, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete\": {\n const pid = args.product_id as string;\n if (!pid) return { success: false, error: \"product_id is required\" };\n if (args.hard === true) {\n const { error } = await sb.from(\"products\").delete().eq(\"id\", pid).eq(\"store_id\", sid);\n return error ? { success: false, error: error.message } : { success: true, data: { id: pid, deleted: true } };\n }\n const { data, error } = await sb.from(\"products\")\n .update({ status: \"archived\" }).eq(\"id\", pid).eq(\"store_id\", sid)\n .select(\"id, name, status\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== CATEGORIES ========================\n\n case \"list_categories\": {\n let q = sb.from(\"categories\")\n .select(\"id, name, slug, description, icon, parent_id, display_order, is_active, featured, product_count, catalog_id, field_schema_id, created_at\")\n .eq(\"store_id\", sid)\n .order(\"display_order\", { ascending: true });\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.parent_id) q = q.eq(\"parent_id\", args.parent_id as string);\n if (args.active_only !== false) q = q.eq(\"is_active\", true);\n const { data, error } = await q.limit(args.limit as number || 100);\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"get_category\": {\n const catId = args.category_id as string;\n const { data: cat, error: catErr } = await sb.from(\"categories\")\n .select(\"*\").eq(\"id\", catId).eq(\"store_id\", sid).single();\n if (catErr) return { success: false, error: catErr.message };\n\n const { data: fieldAssigns } = await sb.from(\"category_field_schemas\")\n .select(\"sort_order, is_active, field_schema:field_schemas!field_schema_id(id, name, fields, icon)\")\n .eq(\"category_id\", catId).eq(\"is_active\", true).order(\"sort_order\");\n\n const { data: pricingAssigns } = await sb.from(\"category_pricing_schemas\")\n .select(\"sort_order, is_active, pricing_schema:pricing_schemas!pricing_schema_id(id, name, tiers, quality_tier)\")\n .eq(\"category_id\", catId).eq(\"is_active\", true).order(\"sort_order\");\n\n const { data: children } = await sb.from(\"categories\")\n .select(\"id, name, slug, display_order, is_active, product_count\")\n .eq(\"parent_id\", catId).order(\"display_order\");\n\n return {\n success: true,\n data: {\n ...cat,\n field_schemas: fieldAssigns?.map(a => ({ ...a.field_schema, sort_order: a.sort_order })) || [],\n pricing_schemas: pricingAssigns?.map(a => ({ ...a.pricing_schema, sort_order: a.sort_order })) || [],\n subcategories: children || []\n }\n };\n }\n\n case \"create_category\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n const insert: Record<string, unknown> = { store_id: sid, name, slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\") };\n if (args.description) insert.description = args.description;\n if (args.icon) insert.icon = args.icon;\n if (args.parent_id) insert.parent_id = args.parent_id;\n if (args.catalog_id) insert.catalog_id = args.catalog_id;\n if (args.display_order !== undefined) insert.display_order = args.display_order;\n if (args.field_schema_id) insert.field_schema_id = args.field_schema_id;\n\n const { data, error } = await sb.from(\"categories\").insert(insert)\n .select(\"id, name, slug, parent_id, catalog_id, display_order, created_at\").single();\n if (error) return { success: false, error: error.message };\n\n if (args.field_schema_ids && Array.isArray(args.field_schema_ids)) {\n const rows = (args.field_schema_ids as string[]).map((fsId, i) => ({ category_id: data.id, field_schema_id: fsId, sort_order: i + 1 }));\n await sb.from(\"category_field_schemas\").insert(rows);\n }\n if (args.pricing_schema_ids && Array.isArray(args.pricing_schema_ids)) {\n const rows = (args.pricing_schema_ids as string[]).map((psId, i) => ({ category_id: data.id, pricing_schema_id: psId, sort_order: i + 1 }));\n await sb.from(\"category_pricing_schemas\").insert(rows);\n }\n\n return { success: true, data };\n }\n\n case \"update_category\": {\n const catId = args.category_id as string;\n if (!catId) return { success: false, error: \"category_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.icon !== undefined) updates.icon = args.icon;\n if (args.parent_id !== undefined) updates.parent_id = args.parent_id;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n if (args.display_order !== undefined) updates.display_order = args.display_order;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.featured !== undefined) updates.featured = args.featured;\n if (args.field_schema_id !== undefined) updates.field_schema_id = args.field_schema_id;\n\n const { data, error } = await sb.from(\"categories\")\n .update(updates).eq(\"id\", catId).eq(\"store_id\", sid)\n .select(\"id, name, slug, is_active, display_order, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete_category\": {\n const catId = args.category_id as string;\n if (!catId) return { success: false, error: \"category_id is required\" };\n if (args.hard === true) {\n const { error } = await sb.from(\"categories\").delete().eq(\"id\", catId).eq(\"store_id\", sid);\n return error ? { success: false, error: error.message } : { success: true, data: { id: catId, deleted: true } };\n }\n const { data, error } = await sb.from(\"categories\")\n .update({ is_active: false }).eq(\"id\", catId).eq(\"store_id\", sid)\n .select(\"id, name, is_active\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== FIELD SCHEMAS ========================\n\n case \"list_field_schemas\": {\n let q = sb.from(\"field_schemas\")\n .select(\"id, name, slug, description, icon, fields, is_public, is_active, catalog_id, store_id, install_count, created_at\")\n .eq(\"is_active\", true);\n // Show store-owned schemas AND public schemas (prevent IDOR)\n if (args.public_only === true) {\n q = q.eq(\"is_public\", true);\n } else {\n q = q.or(`store_id.eq.${sid},is_public.eq.true`);\n }\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.limit) q = q.limit(args.limit as number);\n const { data, error } = await q.order(\"name\");\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"get_field_schema\": {\n const fsId = (args.field_schema_id || args.schema_id) as string;\n if (!fsId) return { success: false, error: \"field_schema_id is required\" };\n // Allow access to own schemas OR public schemas (prevent IDOR)\n const { data, error } = await sb.from(\"field_schemas\").select(\"*\").eq(\"id\", fsId)\n .or(`store_id.eq.${sid},is_public.eq.true`).single();\n if (error) return { success: false, error: error.message };\n\n const { data: assignments } = await sb.from(\"category_field_schemas\")\n .select(\"category:categories!category_id(id, name)\").eq(\"field_schema_id\", fsId).eq(\"is_active\", true);\n\n return { success: true, data: { ...data, assigned_categories: assignments?.map(a => a.category) || [] } };\n }\n\n case \"create_field_schema\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n if (!args.fields || !Array.isArray(args.fields)) return { success: false, error: \"fields array is required\" };\n\n // Auto-resolve catalog_id: use provided value, or fall back to store's default catalog\n let catalogId = args.catalog_id as string | undefined;\n if (!catalogId) {\n const { data: defaultCatalog } = await sb.from(\"catalogs\")\n .select(\"id\").eq(\"store_id\", sid).eq(\"is_default\", true).single();\n if (defaultCatalog) catalogId = defaultCatalog.id;\n }\n\n const insert: Record<string, unknown> = {\n store_id: sid,\n name,\n slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\"),\n fields: args.fields\n };\n if (args.description) insert.description = args.description;\n if (args.icon) insert.icon = args.icon;\n if (catalogId) insert.catalog_id = catalogId;\n if (args.is_public !== undefined) insert.is_public = args.is_public;\n\n const { data, error } = await sb.from(\"field_schemas\").insert(insert)\n .select(\"id, name, slug, fields, icon, is_active, catalog_id, created_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"update_field_schema\": {\n const fsId = (args.field_schema_id || args.schema_id) as string;\n if (!fsId) return { success: false, error: \"field_schema_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.icon !== undefined) updates.icon = args.icon;\n if (args.fields !== undefined) updates.fields = args.fields;\n if (args.is_public !== undefined) updates.is_public = args.is_public;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n\n // Only allow modification of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"field_schemas\")\n .update(updates).eq(\"id\", fsId).eq(\"store_id\", sid)\n .select(\"id, name, slug, fields, icon, is_active, catalog_id, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete_field_schema\": {\n const fsId = (args.field_schema_id || args.schema_id) as string;\n if (!fsId) return { success: false, error: \"field_schema_id is required\" };\n // Only allow deletion of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"field_schemas\")\n .update({ is_active: false, deleted_at: new Date().toISOString() }).eq(\"id\", fsId).eq(\"store_id\", sid)\n .select(\"id, name, is_active\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== PRICING SCHEMAS ========================\n\n case \"list_pricing_schemas\": {\n let q = sb.from(\"pricing_schemas\")\n .select(\"id, name, slug, description, tiers, quality_tier, is_public, is_active, catalog_id, store_id, install_count, created_at\")\n .eq(\"is_active\", true);\n // Show store-owned schemas AND public schemas (prevent IDOR)\n if (args.public_only === true) {\n q = q.eq(\"is_public\", true);\n } else {\n q = q.or(`store_id.eq.${sid},is_public.eq.true`);\n }\n if (args.catalog_id) q = q.eq(\"catalog_id\", args.catalog_id as string);\n if (args.limit) q = q.limit(args.limit as number);\n const { data, error } = await q.order(\"name\");\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"get_pricing_schema\": {\n const psId = (args.pricing_schema_id || args.schema_id) as string;\n if (!psId) return { success: false, error: \"pricing_schema_id is required\" };\n // Allow access to own schemas OR public schemas (prevent IDOR)\n const { data, error } = await sb.from(\"pricing_schemas\").select(\"*\").eq(\"id\", psId)\n .or(`store_id.eq.${sid},is_public.eq.true`).single();\n if (error) return { success: false, error: error.message };\n\n const { data: assignments } = await sb.from(\"category_pricing_schemas\")\n .select(\"category:categories!category_id(id, name)\").eq(\"pricing_schema_id\", psId).eq(\"is_active\", true);\n\n return { success: true, data: { ...data, assigned_categories: assignments?.map(a => a.category) || [] } };\n }\n\n case \"create_pricing_schema\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n if (!args.tiers || !Array.isArray(args.tiers)) return { success: false, error: \"tiers array is required\" };\n\n // Auto-resolve catalog_id: use provided value, or fall back to store's default catalog\n let catalogId = args.catalog_id as string | undefined;\n if (!catalogId) {\n const { data: defaultCatalog } = await sb.from(\"catalogs\")\n .select(\"id\").eq(\"store_id\", sid).eq(\"is_default\", true).single();\n if (defaultCatalog) catalogId = defaultCatalog.id;\n }\n\n const insert: Record<string, unknown> = {\n store_id: sid,\n name,\n slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\"),\n tiers: args.tiers\n };\n if (args.description) insert.description = args.description;\n if (args.quality_tier) insert.quality_tier = args.quality_tier;\n if (catalogId) insert.catalog_id = catalogId;\n if (args.is_public !== undefined) insert.is_public = args.is_public;\n\n const { data, error } = await sb.from(\"pricing_schemas\").insert(insert)\n .select(\"id, name, slug, tiers, quality_tier, is_active, catalog_id, created_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"update_pricing_schema\": {\n const psId = (args.pricing_schema_id || args.schema_id) as string;\n if (!psId) return { success: false, error: \"pricing_schema_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.tiers !== undefined) updates.tiers = args.tiers;\n if (args.quality_tier !== undefined) updates.quality_tier = args.quality_tier;\n if (args.is_public !== undefined) updates.is_public = args.is_public;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.catalog_id !== undefined) updates.catalog_id = args.catalog_id;\n\n // Only allow modification of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"pricing_schemas\")\n .update(updates).eq(\"id\", psId).eq(\"store_id\", sid)\n .select(\"id, name, slug, tiers, quality_tier, is_active, catalog_id, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"delete_pricing_schema\": {\n const psId = (args.pricing_schema_id || args.schema_id) as string;\n if (!psId) return { success: false, error: \"pricing_schema_id is required\" };\n // Only allow deletion of own schemas (prevent IDOR)\n const { data, error } = await sb.from(\"pricing_schemas\")\n .update({ is_active: false, deleted_at: new Date().toISOString() }).eq(\"id\", psId).eq(\"store_id\", sid)\n .select(\"id, name, is_active\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== CATALOGS ========================\n\n case \"list_catalogs\": {\n const { data, error } = await sb.from(\"catalogs\")\n .select(\"id, name, slug, description, vertical, is_active, is_default, display_order, created_at\")\n .eq(\"store_id\", sid).order(\"display_order\");\n return error ? { success: false, error: error.message } : { success: true, count: data?.length, data };\n }\n\n case \"create_catalog\": {\n const name = args.name as string;\n if (!name) return { success: false, error: \"name is required\" };\n // Resolve owner_user_id from store\n const { data: store } = await sb.from(\"stores\").select(\"owner_user_id\").eq(\"id\", sid).single();\n const insert: Record<string, unknown> = {\n store_id: sid, name,\n slug: name.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\"),\n owner_user_id: store?.owner_user_id\n };\n if (args.description) insert.description = args.description;\n if (args.vertical) insert.vertical = args.vertical;\n if (args.is_default !== undefined) insert.is_default = args.is_default;\n if (args.settings) insert.settings = args.settings;\n\n const { data, error } = await sb.from(\"catalogs\").insert(insert)\n .select(\"id, name, slug, vertical, is_default, created_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n case \"update_catalog\": {\n const catId = args.catalog_id as string;\n if (!catId) return { success: false, error: \"catalog_id is required\" };\n const updates: Record<string, unknown> = {};\n if (args.name !== undefined) updates.name = args.name;\n if (args.description !== undefined) updates.description = args.description;\n if (args.vertical !== undefined) updates.vertical = args.vertical;\n if (args.is_active !== undefined) updates.is_active = args.is_active;\n if (args.is_default !== undefined) updates.is_default = args.is_default;\n if (args.settings !== undefined) updates.settings = args.settings;\n if (args.display_order !== undefined) updates.display_order = args.display_order;\n\n const { data, error } = await sb.from(\"catalogs\")\n .update(updates).eq(\"id\", catId).eq(\"store_id\", sid)\n .select(\"id, name, slug, vertical, is_active, is_default, updated_at\").single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n\n // ======================== SCHEMA ASSIGNMENTS ========================\n\n case \"assign_schema\": {\n const target = args.target as string; // \"category\" or \"product\"\n const schemaType = args.schema_type as string; // \"field\" or \"pricing\"\n const targetId = args.target_id as string;\n const schemaId = args.schema_id as string;\n if (!target || !schemaType || !targetId || !schemaId) {\n return { success: false, error: \"target (category|product), schema_type (field|pricing), target_id, and schema_id are required\" };\n }\n\n // Verify target product/category belongs to this store (prevent IDOR)\n const targetTable = target === \"product\" ? \"products\" : \"categories\";\n const { data: ownerCheck, error: ownerErr } = await sb.from(targetTable)\n .select(\"id\").eq(\"id\", targetId).eq(\"store_id\", sid).single();\n if (ownerErr || !ownerCheck) {\n return { success: false, error: `${target} not found or does not belong to this store` };\n }\n\n // Verify schema is accessible (own schema or public)\n const schemaTable = schemaType === \"field\" ? \"field_schemas\" : \"pricing_schemas\";\n const { data: schemaCheck, error: schemaErr } = await sb.from(schemaTable)\n .select(\"id\").eq(\"id\", schemaId).or(`store_id.eq.${sid},is_public.eq.true`).single();\n if (schemaErr || !schemaCheck) {\n return { success: false, error: `${schemaType} schema not found or not accessible` };\n }\n\n const table = target === \"product\"\n ? (schemaType === \"field\" ? \"product_field_schemas\" : \"product_pricing_schemas\")\n : (schemaType === \"field\" ? \"category_field_schemas\" : \"category_pricing_schemas\");\n const fkCol = target === \"product\" ? \"product_id\" : \"category_id\";\n const schemaCol = schemaType === \"field\" ? \"field_schema_id\" : \"pricing_schema_id\";\n\n const row: Record<string, unknown> = { [fkCol]: targetId, [schemaCol]: schemaId };\n if (args.sort_order !== undefined) row.sort_order = args.sort_order;\n\n const { data, error } = await sb.from(table).upsert(row, { onConflict: `${fkCol},${schemaCol}` }).select().single();\n if (error) return { success: false, error: error.message };\n\n // Hydrate product with schema data\n if (target === \"product\") {\n const productUpdates: Record<string, unknown> = {};\n if (schemaType === \"pricing\") {\n const { data: schema } = await sb.from(\"pricing_schemas\").select(\"tiers, quality_tier\").eq(\"id\", schemaId).single();\n productUpdates.pricing_schema_id = schemaId;\n if (schema?.tiers) productUpdates.pricing_data = schema.tiers;\n }\n if (schemaType === \"field\") {\n // Schema is source of truth — rebuild custom_fields from schema keys only\n const { data: schema } = await sb.from(\"field_schemas\").select(\"fields\").eq(\"id\", schemaId).single();\n if (schema?.fields && Array.isArray(schema.fields)) {\n const { data: product } = await sb.from(\"products\").select(\"custom_fields\").eq(\"id\", targetId).eq(\"store_id\", sid).single();\n const existing = (product?.custom_fields as Record<string, unknown>) || {};\n const rebuilt: Record<string, unknown> = {};\n for (const f of schema.fields) {\n const key = (f as any).key;\n if (key) rebuilt[key] = (key in existing) ? existing[key] : ((f as any).default ?? null);\n }\n productUpdates.custom_fields = rebuilt;\n }\n }\n if (Object.keys(productUpdates).length > 0) {\n await sb.from(\"products\").update(productUpdates).eq(\"id\", targetId).eq(\"store_id\", sid);\n }\n }\n\n return { success: true, data };\n }\n\n case \"unassign_schema\": {\n const target = args.target as string;\n const schemaType = args.schema_type as string;\n const targetId = args.target_id as string;\n const schemaId = args.schema_id as string;\n if (!target || !schemaType || !targetId || !schemaId) {\n return { success: false, error: \"target (category|product), schema_type (field|pricing), target_id, and schema_id are required\" };\n }\n\n // Verify target product/category belongs to this store (prevent IDOR)\n const targetTable = target === \"product\" ? \"products\" : \"categories\";\n const { data: ownerCheck, error: ownerErr } = await sb.from(targetTable)\n .select(\"id\").eq(\"id\", targetId).eq(\"store_id\", sid).single();\n if (ownerErr || !ownerCheck) {\n return { success: false, error: `${target} not found or does not belong to this store` };\n }\n\n const table = target === \"product\"\n ? (schemaType === \"field\" ? \"product_field_schemas\" : \"product_pricing_schemas\")\n : (schemaType === \"field\" ? \"category_field_schemas\" : \"category_pricing_schemas\");\n const fkCol = target === \"product\" ? \"product_id\" : \"category_id\";\n const schemaCol = schemaType === \"field\" ? \"field_schema_id\" : \"pricing_schema_id\";\n\n const { error } = await sb.from(table).delete().eq(fkCol, targetId).eq(schemaCol, schemaId);\n return error ? { success: false, error: error.message } : { success: true, data: { removed: true, target, schema_type: schemaType, target_id: targetId, schema_id: schemaId } };\n }\n\n // ======================== PRODUCT DEDUP / MERGE ========================\n\n case \"find_duplicates\": {\n // Find products with similar names (potential duplicates)\n const { data: all, error: allErr } = await sb.from(\"products\")\n .select(\"id, name, sku, status, stock_quantity, cost_price, created_at\")\n .eq(\"store_id\", sid).neq(\"status\", \"archived\")\n .order(\"name\");\n if (allErr) return { success: false, error: allErr.message };\n\n // Group by normalized name (lowercase, trim, strip common suffixes like \"(TEMP)\", \"(OLD)\", \"(COPY)\")\n const nameMap = new Map<string, typeof all>();\n for (const p of all || []) {\n const normalized = (p.name || \"\").toLowerCase().trim()\n .replace(/\\s*\\((temp|old|copy|duplicate|dup|new|v2)\\)\\s*/gi, \"\")\n .replace(/\\s+/g, \" \");\n if (!normalized) continue;\n if (!nameMap.has(normalized)) nameMap.set(normalized, []);\n nameMap.get(normalized)!.push(p);\n }\n\n const duplicates = Array.from(nameMap.entries())\n .filter(([_, products]) => products.length > 1)\n .map(([normalizedName, products]) => ({\n normalized_name: normalizedName,\n count: products.length,\n products: products.map(p => ({\n id: p.id, name: p.name, sku: p.sku, status: p.status,\n stock_quantity: p.stock_quantity, cost_price: p.cost_price, created_at: p.created_at,\n })),\n }));\n\n // Also check by exact SKU match\n const skuMap = new Map<string, typeof all>();\n for (const p of all || []) {\n if (!p.sku) continue;\n const key = p.sku.toLowerCase().trim();\n if (!skuMap.has(key)) skuMap.set(key, []);\n skuMap.get(key)!.push(p);\n }\n const skuDupes = Array.from(skuMap.entries())\n .filter(([_, products]) => products.length > 1)\n .map(([sku, products]) => ({ sku, count: products.length, products }));\n\n // Pre-format as markdown — formatter drops nested products arrays\n const totalNameDupes = duplicates.reduce((s, d) => s + d.count, 0);\n const totalSkuDupes = skuDupes.reduce((s, d) => s + d.count, 0);\n const lines: string[] = [\n `## Duplicate Products`,\n `**By Name**: ${duplicates.length} groups (${totalNameDupes} products) | **By SKU**: ${skuDupes.length} groups (${totalSkuDupes} products)\\n`,\n ];\n if (duplicates.length > 0) {\n lines.push(\"### Name Duplicates\");\n for (const group of duplicates.slice(0, 20)) {\n lines.push(`\\n**\"${group.normalized_name}\"** (${group.count} products):`);\n lines.push(\"| Name | SKU | Status | Stock | Created |\");\n lines.push(\"| --- | --- | --- | ---: | --- |\");\n for (const p of group.products) {\n lines.push(`| ${p.name} | ${p.sku || \"—\"} | ${p.status} | ${p.stock_quantity ?? \"—\"} | ${p.created_at?.slice(0, 10) || \"—\"} |`);\n }\n }\n }\n if (skuDupes.length > 0) {\n lines.push(\"\\n### SKU Duplicates\");\n for (const group of skuDupes.slice(0, 20)) {\n lines.push(`\\n**SKU \"${group.sku}\"** (${group.count} products):`);\n lines.push(\"| Name | SKU | Status | Stock | Created |\");\n lines.push(\"| --- | --- | --- | ---: | --- |\");\n for (const p of group.products) {\n lines.push(`| ${(p as any).name} | ${(p as any).sku || \"—\"} | ${(p as any).status} | ${(p as any).stock_quantity ?? \"—\"} | ${(p as any).created_at?.slice(0, 10) || \"—\"} |`);\n }\n }\n }\n if (duplicates.length === 0 && skuDupes.length === 0) {\n lines.push(\"\\nNo duplicates found.\");\n }\n return { success: true, data: lines.join(\"\\n\") };\n }\n\n case \"merge\": {\n const primaryId = args.primary_product_id as string;\n const secondaryId = args.secondary_product_id as string;\n if (!primaryId || !secondaryId) return { success: false, error: \"primary_product_id and secondary_product_id required\" };\n if (primaryId === secondaryId) return { success: false, error: \"Cannot merge a product with itself\" };\n\n // Verify both exist and belong to this store\n const { data: primary } = await sb.from(\"products\").select(\"*\").eq(\"id\", primaryId).eq(\"store_id\", sid).single();\n const { data: secondary } = await sb.from(\"products\").select(\"*\").eq(\"id\", secondaryId).eq(\"store_id\", sid).single();\n if (!primary) return { success: false, error: `Primary product ${primaryId} not found` };\n if (!secondary) return { success: false, error: `Secondary product ${secondaryId} not found` };\n\n const reassignResults: Record<string, string> = {};\n\n // 1. Consolidate inventory — sum quantities per location\n const { data: secInv } = await sb.from(\"inventory\")\n .select(\"product_id, location_id, quantity\")\n .eq(\"product_id\", secondaryId).eq(\"store_id\", sid);\n if (secInv?.length) {\n for (const row of secInv) {\n if (!row.quantity || row.quantity <= 0) continue;\n // Try to add to existing primary inventory at same location\n const { data: priRow } = await sb.from(\"inventory\")\n .select(\"id, quantity\")\n .eq(\"product_id\", primaryId).eq(\"location_id\", row.location_id).eq(\"store_id\", sid)\n .maybeSingle();\n if (priRow) {\n await sb.from(\"inventory\").update({ quantity: (priRow.quantity || 0) + row.quantity, updated_at: new Date().toISOString() }).eq(\"id\", priRow.id);\n } else {\n await sb.from(\"inventory\").insert({ store_id: sid, product_id: primaryId, location_id: row.location_id, quantity: row.quantity });\n }\n }\n // Zero out secondary inventory\n await sb.from(\"inventory\").update({ quantity: 0 }).eq(\"product_id\", secondaryId).eq(\"store_id\", sid);\n reassignResults.inventory = `consolidated ${secInv.length} location(s)`;\n } else {\n reassignResults.inventory = \"no inventory to consolidate\";\n }\n\n // 2. Reassign order_items\n const { error: oiErr, count: oiCount } = await sb.from(\"order_items\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.order_items = oiErr ? `error: ${oiErr.message}` : `moved ${oiCount ?? 0} rows`;\n\n // 3. Reassign cart_items\n const { error: ciErr, count: ciCount } = await sb.from(\"cart_items\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.cart_items = ciErr ? `error: ${ciErr.message}` : `moved ${ciCount ?? 0} rows`;\n\n // 4. Reassign purchase_order_items\n const { error: poiErr, count: poiCount } = await sb.from(\"purchase_order_items\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.purchase_order_items = poiErr ? `error: ${poiErr.message}` : `moved ${poiCount ?? 0} rows`;\n\n // 5. Reassign product_reviews\n const { error: prErr, count: prCount } = await sb.from(\"product_reviews\")\n .update({ product_id: primaryId }).eq(\"product_id\", secondaryId);\n reassignResults.product_reviews = prErr ? `error: ${prErr.message}` : `moved ${prCount ?? 0} rows`;\n\n // 6. Fill in missing fields on primary from secondary\n const fillFields = [\"description\", \"short_description\", \"cost_price\", \"wholesale_price\", \"weight\", \"featured_image\", \"image_gallery\"] as const;\n const fills: Record<string, unknown> = {};\n for (const field of fillFields) {\n if (!primary[field] && secondary[field]) fills[field] = secondary[field];\n }\n // Merge custom_fields (secondary fills gaps)\n if (secondary.custom_fields && typeof secondary.custom_fields === \"object\") {\n const merged = { ...(secondary.custom_fields as Record<string, unknown>), ...(primary.custom_fields as Record<string, unknown> || {}) };\n fills.custom_fields = merged;\n }\n if (Object.keys(fills).length > 0) {\n await sb.from(\"products\").update(fills).eq(\"id\", primaryId).eq(\"store_id\", sid);\n reassignResults.field_fills = Object.keys(fills).join(\", \");\n }\n\n // 7. Archive the secondary product\n await sb.from(\"products\").update({\n status: \"archived\",\n name: `[MERGED] ${secondary.name}`,\n }).eq(\"id\", secondaryId).eq(\"store_id\", sid);\n\n // Re-read primary\n const { data: merged } = await sb.from(\"products\")\n .select(\"id, name, sku, status, stock_quantity, cost_price, created_at, updated_at\")\n .eq(\"id\", primaryId).single();\n\n return {\n success: true,\n data: {\n merged_product: merged,\n archived_product: { id: secondaryId, name: secondary.name },\n reassign_results: reassignResults,\n }\n };\n }\n\n default:\n return { success: false, error: `Unknown products action: ${args.action}. Valid: browse, find, get, create, update, delete, find_duplicates, merge, list_categories, get_category, create_category, update_category, delete_category, list_field_schemas, get_field_schema, create_field_schema, update_field_schema, delete_field_schema, list_pricing_schemas, get_pricing_schema, create_pricing_schema, update_pricing_schema, delete_pricing_schema, list_catalogs, create_catalog, update_catalog, assign_schema, unassign_schema` };\n }\n}\n\nexport async function handleCollections(sb: SupabaseClient, args: Record<string, unknown>, storeId?: string) {\n const sid = storeId as string;\n switch (args.action) {\n case \"find\": {\n let q = sb.from(\"creation_collections\").select(\"*\").eq(\"store_id\", sid);\n if (args.name) { const sn = sanitizeFilterValue(args.name as string); q = q.ilike(\"name\", `%${sn}%`); }\n const { data, error } = await q.limit(100);\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n case \"create\": {\n const slug = (args.slug as string) || (args.name as string || \"\").toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\");\n const { data, error } = await sb.from(\"creation_collections\")\n .insert({ store_id: sid, name: args.name, slug }).select().single();\n return error ? { success: false, error: error.message } : { success: true, data };\n }\n default:\n return { success: false, error: `Unknown collections action: ${args.action}` };\n }\n}\n"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,iBAAiB;;AAErD;AACA;AACA;AACA;;AAEA,OAAO,eAAeC,cAAcA,CAACC,EAAkB,EAAEC,IAA6B,EAAEC,OAAgB,EAAE;EACxG,MAAMC,GAAG,GAAGD,OAAiB;EAC7B,QAAQD,IAAI,CAACG,MAAM;IAEjB;;IAEA,KAAK,QAAQ;MAAE;QACb;QACA,MAAM;UAAEC,IAAI,EAAEC,IAAI;UAAEC,KAAK,EAAEC;QAAO,CAAC,GAAG,MAAMR,EAAE,CAACS,IAAI,CAAC,YAAY,CAAC,CAC9DC,MAAM,CAAC,qEAAqE,CAAC,CAC7EC,EAAE,CAAC,UAAU,EAAER,GAAG,CAAC,CACnBQ,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,CACr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QAAQ,EAAE,EAAE,CAAC;QACjI,MAAM;UAAEvJ,IAAI;UAAEE;QAAM,CAAC,GAAG,MAAMP,EAAE,CAACS,IAAI,CAAC,sBAAsB,CAAC,CAC1DiE,MAAM,CAAC;UAAEC,QAAQ,EAAExE,GAAG;UAAEuD,IAAI,EAAEzD,IAAI,CAACyD,IAAI;UAAEgG;QAAK,CAAC,CAAC,CAAChJ,MAAM,CAAC,CAAC,CAACsD,MAAM,CAAC,CAAC;QACrE,OAAOzD,KAAK,GAAG;UAAEO,OAAO,EAAE,KAAK;UAAEP,KAAK,EAAEA,KAAK,CAACQ;QAAQ,CAAC,GAAG;UAAED,OAAO,EAAE,IAAI;UAAET;QAAK,CAAC;MACnF;IACA;MACE,OAAO;QAAES,OAAO,EAAE,KAAK;QAAEP,KAAK,EAAE,+BAA+BN,IAAI,CAACG,MAAM;MAAG,CAAC;EAClF;AACF","ignoreList":[]}
@@ -173,10 +173,36 @@ handleDocuments) {
173
173
  }
174
174
  case "delete":
175
175
  {
176
- if (!args.confirm) return {
176
+ if (!args.force && !args.confirm) return {
177
177
  success: false,
178
- error: "Set confirm: true to delete"
178
+ error: "Set force: true to confirm deletion"
179
179
  };
180
+
181
+ // Single document delete by ID (preferred)
182
+ if (args.query) {
183
+ const docId = args.query;
184
+ const {
185
+ data,
186
+ error
187
+ } = await sb.from("store_documents").delete().eq("id", docId).eq("store_id", sid).select("id");
188
+ if (error) return {
189
+ success: false,
190
+ error: error.message
191
+ };
192
+ if (!data?.length) return {
193
+ success: false,
194
+ error: "Document not found or does not belong to this store"
195
+ };
196
+ return {
197
+ success: true,
198
+ data: {
199
+ deleted: 1,
200
+ id: docId
201
+ }
202
+ };
203
+ }
204
+
205
+ // Bulk delete by filters
180
206
  let query = sb.from("store_documents").delete().eq("store_id", sid);
181
207
  if (args.document_type) query = query.eq("document_type", args.document_type);
182
208
  if (args.name) {