@replohq/canopy-sdk 0.14.1 → 0.15.0

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 (81) hide show
  1. package/_vendor/replo-utils/lib/fonts.mjs +40 -2
  2. package/_vendor/replo-utils/lib/json.mjs +1 -1
  3. package/_vendor/replo-utils/lib/misc.mjs +2 -2
  4. package/_vendor/schemas/loaderKeys.mjs +1 -1
  5. package/_vendor/schemas/selectMode.mjs +2 -2
  6. package/cart/buy-now-action.js +3 -3
  7. package/cart/buy-now-action.js.map +2 -2
  8. package/cart/cart-provider.js +2 -2
  9. package/cart/cart-provider.js.map +2 -2
  10. package/{_vendor/schemas/cart.mjs → cart/cart-schema.js} +26 -17
  11. package/cart/cart-schema.js.map +7 -0
  12. package/cart/cart-types.d.ts +1 -2
  13. package/cart/cart-types.js.map +2 -2
  14. package/cart/hooks/use-add-to-cart.js +1 -1
  15. package/cart/hooks/use-add-to-cart.js.map +2 -2
  16. package/cart/hooks/use-buy-now.js +2 -2
  17. package/cart/hooks/use-buy-now.js.map +2 -2
  18. package/cart/utils/variant-to-cart-line.d.ts +2 -1
  19. package/cart/utils/variant-to-cart-line.js.map +1 -1
  20. package/{chunk-OCB5XQYL.mjs → chunk-ME5W2TJM.mjs} +2 -2
  21. package/gateways/canopy-api.d.ts +3 -3
  22. package/gateways/canopy-api.js +3 -3
  23. package/gateways/canopy-api.js.map +2 -2
  24. package/lib/canopy-error.d.ts +25 -0
  25. package/lib/canopy-error.js +24 -0
  26. package/lib/canopy-error.js.map +7 -0
  27. package/loaders/collection-loader.d.ts +1 -1
  28. package/loaders/collection-loader.js +1 -1
  29. package/loaders/collection-loader.js.map +2 -2
  30. package/loaders/collection-products-loader.d.ts +1 -1
  31. package/loaders/collection-products-loader.js +1 -1
  32. package/loaders/collection-products-loader.js.map +2 -2
  33. package/loaders/invoke-loader.d.ts +2 -2
  34. package/loaders/invoke-loader.js +2 -2
  35. package/loaders/invoke-loader.js.map +2 -2
  36. package/loaders/levanta-product-loader.d.ts +1 -1
  37. package/loaders/levanta-product-loader.js +1 -1
  38. package/loaders/levanta-product-loader.js.map +2 -2
  39. package/{_vendor/schemas/loaderKeys.d.ts → loaders/loader-keys.d.ts} +4 -4
  40. package/loaders/loader-keys.js +22 -0
  41. package/loaders/loader-keys.js.map +7 -0
  42. package/loaders/loader-schemas.d.ts +755 -0
  43. package/loaders/loader-schemas.js +257 -0
  44. package/loaders/loader-schemas.js.map +7 -0
  45. package/loaders/okendo-reviews-loader.js +1 -1
  46. package/loaders/okendo-reviews-loader.js.map +2 -2
  47. package/loaders/prefetch-loaders.d.ts +1 -1
  48. package/loaders/prefetch-loaders.js.map +1 -1
  49. package/loaders/product-loader.d.ts +1 -1
  50. package/loaders/product-loader.js +1 -1
  51. package/loaders/product-loader.js.map +2 -2
  52. package/loaders/rebuy-recommendations-loader.js +1 -1
  53. package/loaders/rebuy-recommendations-loader.js.map +2 -2
  54. package/loaders/yotpo-review-aggregate-loader.d.ts +1 -1
  55. package/loaders/yotpo-review-aggregate-loader.js +1 -1
  56. package/loaders/yotpo-review-aggregate-loader.js.map +2 -2
  57. package/loaders/yotpo-reviews-loader.d.ts +1 -1
  58. package/loaders/yotpo-reviews-loader.js +1 -1
  59. package/loaders/yotpo-reviews-loader.js.map +2 -2
  60. package/package.json +1 -1
  61. package/_vendor/replo-utils/lib/errors.d.ts +0 -83
  62. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +0 -49
  63. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +0 -36
  64. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +0 -340
  65. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +0 -51
  66. package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.d.ts +0 -37
  67. package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.mjs +0 -37
  68. package/_vendor/schemas/errors.d.ts +0 -438
  69. package/_vendor/schemas/errors.mjs +0 -932
  70. package/_vendor/schemas/generated/errors.d.ts +0 -61
  71. package/_vendor/schemas/objectType.d.ts +0 -1038
  72. package/_vendor/schemas/objectType.mjs +0 -2
  73. package/_vendor/schemas/registry.d.ts +0 -539
  74. package/_vendor/schemas/sandboxFiles.d.ts +0 -36
  75. package/_vendor/schemas/sellingPlan.d.ts +0 -60
  76. package/_vendor/schemas/sellingPlan.mjs +0 -1
  77. package/chunk-4XLTENDR.mjs +0 -33
  78. package/chunk-A7EUNWRQ.mjs +0 -765
  79. package/chunk-QFYIXADC.mjs +0 -42
  80. package/{_vendor/schemas/cart.d.ts → cart/cart-schema.d.ts} +0 -0
  81. package/{chunk-ILGEM42C.mjs → chunk-NCKKAFF7.mjs} +7 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../cart/utils/variant-to-cart-line.ts"],
4
- "sourcesContent": ["import type {\n CartLine,\n CartLineAttribute,\n CartLineMerchandise,\n CartLinePayload,\n SellingPlanAllocation,\n SellingPlanGroup,\n} from \"../cart-types\";\n\nimport { convertLegacyResourceIdToGraphQLId } from \"../../lib/shopify-utils\";\nimport { formatSellingPlanId } from \"./cart-utils\";\n\n// TODO: Temporary \u2014 minimal local type after removing features/product. Replace with loader/canonical variant type when data loaders are in place.\ninterface ProductVariant {\n id: string;\n externalId?: string;\n title: string;\n price: number;\n originalPrice: number | null;\n optionValues?: {\n id: string;\n value: string;\n color: string | null;\n image: string | null;\n imageUrls: string[];\n referenceType: \"SHOPIFY\" | \"REPLO\";\n }[];\n}\n\n// TODO: Temporary \u2014 inlined from removed features/product/utils/pricing-utils. Keep until cart uses canonical product/loader types.\nfunction applyPriceAdjustment(\n variantPrice: number,\n adjustment: {\n value: number;\n valueType: \"percentage\" | \"fixedAmount\" | \"price\";\n },\n): number {\n switch (adjustment.valueType) {\n case \"price\":\n return adjustment.value;\n case \"percentage\":\n return Math.max(0, variantPrice * (1 - adjustment.value / 100));\n case \"fixedAmount\":\n return Math.max(0, variantPrice - adjustment.value);\n }\n}\n\n// === Variant to Cart Line Conversion ===\n\nexport interface VariantToCartLineProduct {\n id: string;\n title: string;\n featuredMedia?: {\n type: string;\n url: string;\n alt?: string;\n } | null;\n sellingPlanGroups?: SellingPlanGroup[];\n}\n\ninterface VariantToCartLineOptions {\n quantity?: number;\n properties?: CartLineAttribute[];\n sellingPlanId?: string | null;\n pricing?: {\n compareAtPrice: number;\n discountPercentage: number;\n };\n bundle?: {\n bundleId: string;\n bundleDiscount: number;\n };\n includeMerchandise?: boolean;\n product?: VariantToCartLineProduct;\n}\n\n/**\n * Converts a product variant to a cart line payload.\n * This is the primary function for creating cart lines from variants.\n *\n * When a ProductVariant has both `price` and `originalPrice`, the function will\n * automatically calculate and include pricing attributes (compareAtPrice and discountPercentage)\n * unless explicitly overridden in the options.\n */\nexport function variantToCartLine(\n variant: ProductVariant,\n options?: VariantToCartLineOptions,\n): CartLinePayload {\n const quantity = options?.quantity ?? 1;\n const baseProperties = options?.properties ?? [];\n const sellingPlanId = formatSellingPlanId(options?.sellingPlanId ?? null);\n\n // Create additional properties based on options\n const additionalProperties: CartLineAttribute[] = [];\n\n if (options?.bundle) {\n additionalProperties.push(\n ...createBundleAttributes(\n options.bundle.bundleId,\n options.bundle.bundleDiscount,\n ),\n );\n }\n\n const allProperties = [...baseProperties, ...additionalProperties];\n\n const cartLine: CartLinePayload = {\n id: variant.externalId\n ? convertLegacyResourceIdToGraphQLId(variant.externalId, \"ProductVariant\")\n : variant.id,\n quantity,\n properties: allProperties,\n sellingPlanId,\n };\n\n // Add merchandise if requested and we have product data\n if (options?.includeMerchandise && options.product) {\n const { product } = options;\n\n cartLine.merchandise = {\n id: variant.externalId\n ? convertLegacyResourceIdToGraphQLId(\n variant.externalId,\n \"ProductVariant\",\n )\n : variant.id,\n product: {\n id: product.id,\n title: product.title,\n sellingPlanGroups: product.sellingPlanGroups,\n },\n title: variant.title ?? `${product.title} - ${variant.id}`,\n price: variant.price ?? 0,\n compareAtPrice: variant.originalPrice,\n image:\n product.featuredMedia?.type === \"image\"\n ? {\n url: product.featuredMedia.url,\n altText: product.featuredMedia.alt ?? product.title,\n }\n : null,\n selectedOptions:\n variant.optionValues?.map((opt) => ({\n name: opt.value,\n value: opt.value,\n })) ?? [],\n };\n }\n\n return cartLine;\n}\n\n// === Cart Attributes Functions ===\n\n/**\n * Creates cart line attributes for bundle items.\n *\n * @param bundleId - The ID of the bundle\n * @param bundleDiscount - The discount amount for the bundle\n * @returns Array of cart line attributes for bundle metadata\n */\nfunction createBundleAttributes(\n bundleId: string,\n bundleDiscount: number,\n): CartLineAttribute[] {\n return [\n { key: \"bundleId\", value: bundleId },\n { key: \"bundleDiscount\", value: bundleDiscount },\n { key: \"isBundleItem\", value: true },\n ];\n}\n\n// === Cart Line Utilities ===\n\n/**\n * Gets a specific attribute value from a cart line.\n *\n * @param cartLine - The cart line to get the attribute from\n * @param key - The attribute key to retrieve\n * @returns The attribute value, or undefined if not found\n */\nexport function getCartLineAttribute(\n cartLine: CartLine,\n key: string,\n): string | number | boolean | undefined {\n return cartLine.attributes.find((attr: CartLineAttribute) => attr.key === key)\n ?.value;\n}\n\n/**\n * Calculates pricing information for a cart line, including discounts and\n * selling plan adjustments.\n *\n * @param cartLine - The cart line to calculate pricing for\n * @returns Object containing compareAtPrice, discountPercentage, hasDiscount, sellingPlanAdjustedPrice, and finalPrice\n */\nexport function getCartLinePricing(cartLine: CartLine) {\n if (!cartLine.merchandise) {\n return {\n compareAtPrice: 0,\n discountPercentage: 0,\n hasDiscount: false,\n sellingPlanAdjustedPrice: 0,\n finalPrice: 0,\n };\n }\n\n const compareAtPrice = cartLine.merchandise.compareAtPrice ?? 0;\n const currentPrice = cartLine.merchandise.price;\n const discountPercentage =\n compareAtPrice > currentPrice\n ? ((compareAtPrice - currentPrice) / compareAtPrice) * 100\n : 0;\n const hasDiscount = compareAtPrice > currentPrice;\n\n let sellingPlanAdjustedPrice = cartLine.merchandise.price;\n if (\n cartLine.sellingPlanAllocation &&\n cartLine.sellingPlanAllocation.priceAdjustments.length > 0 &&\n cartLine.sellingPlanAllocation.priceAdjustments[0]?.price\n ) {\n // Use the price from the first price adjustment, which represents the selling plan price\n sellingPlanAdjustedPrice =\n cartLine.sellingPlanAllocation.priceAdjustments[0]!.price.amount;\n }\n\n return {\n compareAtPrice,\n discountPercentage,\n hasDiscount: hasDiscount,\n sellingPlanAdjustedPrice,\n finalPrice: sellingPlanAdjustedPrice,\n };\n}\n\n/**\n * Extracts bundle information from cart line attributes.\n *\n * @param cartLine - The cart line to get bundle info from\n * @returns Object containing bundle ID, discount, and whether it's a bundle item\n */\nexport function getCartLineBundleInfo(cartLine: CartLine) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const bundleId = getCartLineAttribute(cartLine, \"bundleId\") as string;\n const bundleDiscount = Number(\n getCartLineAttribute(cartLine, \"bundleDiscount\") ?? 0,\n );\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const isBundleItem = getCartLineAttribute(\n cartLine,\n \"isBundleItem\",\n ) as boolean;\n\n return {\n bundleId: bundleId ?? null,\n bundleDiscount,\n isBundleItem: isBundleItem ?? false,\n };\n}\n\n/**\n * Extracts special item information from cart line attributes.\n *\n * @param cartLine - The cart line to get special info from\n * @returns Object containing whether it's a special item and any special instructions\n */\nexport function getCartLineSpecialInfo(cartLine: CartLine) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const isSpecialItem = getCartLineAttribute(\n cartLine,\n \"isSpecialItem\",\n ) as boolean;\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const specialInstructions = getCartLineAttribute(\n cartLine,\n \"specialInstructions\",\n ) as string;\n\n return {\n isSpecialItem: isSpecialItem ?? false,\n specialInstructions: specialInstructions\n ? specialInstructions.split(\"|\")\n : [],\n };\n}\n\n/**\n * Extracts subscription (selling plan) information from a cart line.\n *\n * @param cartLine - The cart line to get subscription info from\n * @returns Object containing isSubscription, frequency, discount, and sellingPlan\n */\nexport function getCartLineSubscriptionInfo(cartLine: CartLine) {\n if (cartLine.sellingPlanAllocation) {\n return {\n isSubscription: true,\n frequency: cartLine.sellingPlanAllocation.sellingPlan.name,\n discount: 0, // Shopify calculates this from price adjustments when available\n sellingPlan: cartLine.sellingPlanAllocation.sellingPlan,\n };\n }\n\n // No subscription if no sellingPlanAllocation\n return {\n isSubscription: false,\n frequency: null,\n discount: 0,\n sellingPlan: null,\n };\n}\n\n/**\n * Creates an optimistic selling plan allocation using product data.\n * This matches the exact structure that Shopify returns so the UI doesn't need conditional logic.\n */\nexport function createOptimisticSellingPlanAllocation({\n merchandise,\n sellingPlanId,\n currencyCode = \"USD\",\n}: {\n merchandise: CartLineMerchandise;\n sellingPlanId: string | null;\n currencyCode?: string;\n}): SellingPlanAllocation | null {\n const { product, price: variantPrice } = merchandise;\n\n if (!sellingPlanId || !product.sellingPlanGroups) {\n return null;\n }\n\n // Find the selling plan in the product's selling plan groups\n for (const group of product.sellingPlanGroups) {\n const sellingPlan = group.sellingPlans.find(\n (sp) => sp.id === sellingPlanId,\n );\n if (sellingPlan) {\n return {\n sellingPlan: {\n id: sellingPlan.id,\n name: sellingPlan.name,\n description: sellingPlan.description,\n },\n priceAdjustments: sellingPlan.priceAdjustments.map((adj) => {\n const adjustedPrice =\n variantPrice !== undefined\n ? applyPriceAdjustment(variantPrice, adj)\n : 0;\n\n return {\n compareAtPrice: {\n amount: variantPrice ?? 0,\n currencyCode,\n },\n perDeliveryPrice: {\n amount: adjustedPrice,\n currencyCode,\n },\n price: {\n amount: adjustedPrice,\n currencyCode,\n },\n unitPrice: null,\n };\n }),\n checkoutChargeAmount: {\n amount: 0,\n currencyCode,\n },\n remainingBalanceChargeAmount: {\n amount: 0,\n currencyCode,\n },\n };\n }\n }\n\n return null;\n}\n"],
4
+ "sourcesContent": ["import type { SellingPlanGroup } from \"../../loaders/loader-schemas\";\nimport type {\n CartLine,\n CartLineAttribute,\n CartLineMerchandise,\n CartLinePayload,\n SellingPlanAllocation,\n} from \"../cart-types\";\n\nimport { convertLegacyResourceIdToGraphQLId } from \"../../lib/shopify-utils\";\nimport { formatSellingPlanId } from \"./cart-utils\";\n\n// TODO: Temporary \u2014 minimal local type after removing features/product. Replace with loader/canonical variant type when data loaders are in place.\ninterface ProductVariant {\n id: string;\n externalId?: string;\n title: string;\n price: number;\n originalPrice: number | null;\n optionValues?: {\n id: string;\n value: string;\n color: string | null;\n image: string | null;\n imageUrls: string[];\n referenceType: \"SHOPIFY\" | \"REPLO\";\n }[];\n}\n\n// TODO: Temporary \u2014 inlined from removed features/product/utils/pricing-utils. Keep until cart uses canonical product/loader types.\nfunction applyPriceAdjustment(\n variantPrice: number,\n adjustment: {\n value: number;\n valueType: \"percentage\" | \"fixedAmount\" | \"price\";\n },\n): number {\n switch (adjustment.valueType) {\n case \"price\":\n return adjustment.value;\n case \"percentage\":\n return Math.max(0, variantPrice * (1 - adjustment.value / 100));\n case \"fixedAmount\":\n return Math.max(0, variantPrice - adjustment.value);\n }\n}\n\n// === Variant to Cart Line Conversion ===\n\nexport interface VariantToCartLineProduct {\n id: string;\n title: string;\n featuredMedia?: {\n type: string;\n url: string;\n alt?: string;\n } | null;\n sellingPlanGroups?: SellingPlanGroup[];\n}\n\ninterface VariantToCartLineOptions {\n quantity?: number;\n properties?: CartLineAttribute[];\n sellingPlanId?: string | null;\n pricing?: {\n compareAtPrice: number;\n discountPercentage: number;\n };\n bundle?: {\n bundleId: string;\n bundleDiscount: number;\n };\n includeMerchandise?: boolean;\n product?: VariantToCartLineProduct;\n}\n\n/**\n * Converts a product variant to a cart line payload.\n * This is the primary function for creating cart lines from variants.\n *\n * When a ProductVariant has both `price` and `originalPrice`, the function will\n * automatically calculate and include pricing attributes (compareAtPrice and discountPercentage)\n * unless explicitly overridden in the options.\n */\nexport function variantToCartLine(\n variant: ProductVariant,\n options?: VariantToCartLineOptions,\n): CartLinePayload {\n const quantity = options?.quantity ?? 1;\n const baseProperties = options?.properties ?? [];\n const sellingPlanId = formatSellingPlanId(options?.sellingPlanId ?? null);\n\n // Create additional properties based on options\n const additionalProperties: CartLineAttribute[] = [];\n\n if (options?.bundle) {\n additionalProperties.push(\n ...createBundleAttributes(\n options.bundle.bundleId,\n options.bundle.bundleDiscount,\n ),\n );\n }\n\n const allProperties = [...baseProperties, ...additionalProperties];\n\n const cartLine: CartLinePayload = {\n id: variant.externalId\n ? convertLegacyResourceIdToGraphQLId(variant.externalId, \"ProductVariant\")\n : variant.id,\n quantity,\n properties: allProperties,\n sellingPlanId,\n };\n\n // Add merchandise if requested and we have product data\n if (options?.includeMerchandise && options.product) {\n const { product } = options;\n\n cartLine.merchandise = {\n id: variant.externalId\n ? convertLegacyResourceIdToGraphQLId(\n variant.externalId,\n \"ProductVariant\",\n )\n : variant.id,\n product: {\n id: product.id,\n title: product.title,\n sellingPlanGroups: product.sellingPlanGroups,\n },\n title: variant.title ?? `${product.title} - ${variant.id}`,\n price: variant.price ?? 0,\n compareAtPrice: variant.originalPrice,\n image:\n product.featuredMedia?.type === \"image\"\n ? {\n url: product.featuredMedia.url,\n altText: product.featuredMedia.alt ?? product.title,\n }\n : null,\n selectedOptions:\n variant.optionValues?.map((opt) => ({\n name: opt.value,\n value: opt.value,\n })) ?? [],\n };\n }\n\n return cartLine;\n}\n\n// === Cart Attributes Functions ===\n\n/**\n * Creates cart line attributes for bundle items.\n *\n * @param bundleId - The ID of the bundle\n * @param bundleDiscount - The discount amount for the bundle\n * @returns Array of cart line attributes for bundle metadata\n */\nfunction createBundleAttributes(\n bundleId: string,\n bundleDiscount: number,\n): CartLineAttribute[] {\n return [\n { key: \"bundleId\", value: bundleId },\n { key: \"bundleDiscount\", value: bundleDiscount },\n { key: \"isBundleItem\", value: true },\n ];\n}\n\n// === Cart Line Utilities ===\n\n/**\n * Gets a specific attribute value from a cart line.\n *\n * @param cartLine - The cart line to get the attribute from\n * @param key - The attribute key to retrieve\n * @returns The attribute value, or undefined if not found\n */\nexport function getCartLineAttribute(\n cartLine: CartLine,\n key: string,\n): string | number | boolean | undefined {\n return cartLine.attributes.find((attr: CartLineAttribute) => attr.key === key)\n ?.value;\n}\n\n/**\n * Calculates pricing information for a cart line, including discounts and\n * selling plan adjustments.\n *\n * @param cartLine - The cart line to calculate pricing for\n * @returns Object containing compareAtPrice, discountPercentage, hasDiscount, sellingPlanAdjustedPrice, and finalPrice\n */\nexport function getCartLinePricing(cartLine: CartLine) {\n if (!cartLine.merchandise) {\n return {\n compareAtPrice: 0,\n discountPercentage: 0,\n hasDiscount: false,\n sellingPlanAdjustedPrice: 0,\n finalPrice: 0,\n };\n }\n\n const compareAtPrice = cartLine.merchandise.compareAtPrice ?? 0;\n const currentPrice = cartLine.merchandise.price;\n const discountPercentage =\n compareAtPrice > currentPrice\n ? ((compareAtPrice - currentPrice) / compareAtPrice) * 100\n : 0;\n const hasDiscount = compareAtPrice > currentPrice;\n\n let sellingPlanAdjustedPrice = cartLine.merchandise.price;\n if (\n cartLine.sellingPlanAllocation &&\n cartLine.sellingPlanAllocation.priceAdjustments.length > 0 &&\n cartLine.sellingPlanAllocation.priceAdjustments[0]?.price\n ) {\n // Use the price from the first price adjustment, which represents the selling plan price\n sellingPlanAdjustedPrice =\n cartLine.sellingPlanAllocation.priceAdjustments[0]!.price.amount;\n }\n\n return {\n compareAtPrice,\n discountPercentage,\n hasDiscount: hasDiscount,\n sellingPlanAdjustedPrice,\n finalPrice: sellingPlanAdjustedPrice,\n };\n}\n\n/**\n * Extracts bundle information from cart line attributes.\n *\n * @param cartLine - The cart line to get bundle info from\n * @returns Object containing bundle ID, discount, and whether it's a bundle item\n */\nexport function getCartLineBundleInfo(cartLine: CartLine) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const bundleId = getCartLineAttribute(cartLine, \"bundleId\") as string;\n const bundleDiscount = Number(\n getCartLineAttribute(cartLine, \"bundleDiscount\") ?? 0,\n );\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const isBundleItem = getCartLineAttribute(\n cartLine,\n \"isBundleItem\",\n ) as boolean;\n\n return {\n bundleId: bundleId ?? null,\n bundleDiscount,\n isBundleItem: isBundleItem ?? false,\n };\n}\n\n/**\n * Extracts special item information from cart line attributes.\n *\n * @param cartLine - The cart line to get special info from\n * @returns Object containing whether it's a special item and any special instructions\n */\nexport function getCartLineSpecialInfo(cartLine: CartLine) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const isSpecialItem = getCartLineAttribute(\n cartLine,\n \"isSpecialItem\",\n ) as boolean;\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const specialInstructions = getCartLineAttribute(\n cartLine,\n \"specialInstructions\",\n ) as string;\n\n return {\n isSpecialItem: isSpecialItem ?? false,\n specialInstructions: specialInstructions\n ? specialInstructions.split(\"|\")\n : [],\n };\n}\n\n/**\n * Extracts subscription (selling plan) information from a cart line.\n *\n * @param cartLine - The cart line to get subscription info from\n * @returns Object containing isSubscription, frequency, discount, and sellingPlan\n */\nexport function getCartLineSubscriptionInfo(cartLine: CartLine) {\n if (cartLine.sellingPlanAllocation) {\n return {\n isSubscription: true,\n frequency: cartLine.sellingPlanAllocation.sellingPlan.name,\n discount: 0, // Shopify calculates this from price adjustments when available\n sellingPlan: cartLine.sellingPlanAllocation.sellingPlan,\n };\n }\n\n // No subscription if no sellingPlanAllocation\n return {\n isSubscription: false,\n frequency: null,\n discount: 0,\n sellingPlan: null,\n };\n}\n\n/**\n * Creates an optimistic selling plan allocation using product data.\n * This matches the exact structure that Shopify returns so the UI doesn't need conditional logic.\n */\nexport function createOptimisticSellingPlanAllocation({\n merchandise,\n sellingPlanId,\n currencyCode = \"USD\",\n}: {\n merchandise: CartLineMerchandise;\n sellingPlanId: string | null;\n currencyCode?: string;\n}): SellingPlanAllocation | null {\n const { product, price: variantPrice } = merchandise;\n\n if (!sellingPlanId || !product.sellingPlanGroups) {\n return null;\n }\n\n // Find the selling plan in the product's selling plan groups\n for (const group of product.sellingPlanGroups) {\n const sellingPlan = group.sellingPlans.find(\n (sp) => sp.id === sellingPlanId,\n );\n if (sellingPlan) {\n return {\n sellingPlan: {\n id: sellingPlan.id,\n name: sellingPlan.name,\n description: sellingPlan.description,\n },\n priceAdjustments: sellingPlan.priceAdjustments.map((adj) => {\n const adjustedPrice =\n variantPrice !== undefined\n ? applyPriceAdjustment(variantPrice, adj)\n : 0;\n\n return {\n compareAtPrice: {\n amount: variantPrice ?? 0,\n currencyCode,\n },\n perDeliveryPrice: {\n amount: adjustedPrice,\n currencyCode,\n },\n price: {\n amount: adjustedPrice,\n currencyCode,\n },\n unitPrice: null,\n };\n }),\n checkoutChargeAmount: {\n amount: 0,\n currencyCode,\n },\n remainingBalanceChargeAmount: {\n amount: 0,\n currencyCode,\n },\n };\n }\n }\n\n return null;\n}\n"],
5
5
  "mappings": "AASA,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AAoBpC,SAAS,qBACP,cACA,YAIQ;AACR,UAAQ,WAAW,WAAW;AAAA,IAC5B,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO,KAAK,IAAI,GAAG,gBAAgB,IAAI,WAAW,QAAQ,IAAI;AAAA,IAChE,KAAK;AACH,aAAO,KAAK,IAAI,GAAG,eAAe,WAAW,KAAK;AAAA,EACtD;AACF;AAuCO,SAAS,kBACd,SACA,SACiB;AACjB,QAAM,WAAW,SAAS,YAAY;AACtC,QAAM,iBAAiB,SAAS,cAAc,CAAC;AAC/C,QAAM,gBAAgB,oBAAoB,SAAS,iBAAiB,IAAI;AAGxE,QAAM,uBAA4C,CAAC;AAEnD,MAAI,SAAS,QAAQ;AACnB,yBAAqB;AAAA,MACnB,GAAG;AAAA,QACD,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAgB,CAAC,GAA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;AAAA,MACtD,UAAU;AAAA;AAAA,MACV,aAAa,SAAS,sBAAsB;AAAA,IAC9C;AAAA,EACF;AAGA,SAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,WAAW;AAAA,IACX,UAAU;AAAA,IACV,aAAa;AAAA,EACf;AACF;AAMO,SAAS,sCAAsC;AAAA,EACpD;AAAA,EACA;AAAA,EACA,eAAe;AACjB,GAIiC;AAC/B,QAAM,EAAE,SAAS,OAAO,aAAa,IAAI;AAEzC,MAAI,CAAC,iBAAiB,CAAC,QAAQ,mBAAmB;AAChD,WAAO;AAAA,EACT;AAGA,aAAW,SAAS,QAAQ,mBAAmB;AAC7C,UAAM,cAAc,MAAM,aAAa;AAAA,MACrC,CAAC,OAAO,GAAG,OAAO;AAAA,IACpB;AACA,QAAI,aAAa;AACf,aAAO;AAAA,QACL,aAAa;AAAA,UACX,IAAI,YAAY;AAAA,UAChB,MAAM,YAAY;AAAA,UAClB,aAAa,YAAY;AAAA,QAC3B;AAAA,QACA,kBAAkB,YAAY,iBAAiB,IAAI,CAAC,QAAQ;AAC1D,gBAAM,gBACJ,iBAAiB,SACb,qBAAqB,cAAc,GAAG,IACtC;AAEN,iBAAO;AAAA,YACL,gBAAgB;AAAA,cACd,QAAQ,gBAAgB;AAAA,cACxB;AAAA,YACF;AAAA,YACA,kBAAkB;AAAA,cAChB,QAAQ;AAAA,cACR;AAAA,YACF;AAAA,YACA,OAAO;AAAA,cACL,QAAQ;AAAA,cACR;AAAA,YACF;AAAA,YACA,WAAW;AAAA,UACb;AAAA,QACF,CAAC;AAAA,QACD,sBAAsB;AAAA,UACpB,QAAQ;AAAA,UACR;AAAA,QACF;AAAA,QACA,8BAA8B;AAAA,UAC5B,QAAQ;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { isObject_default } from './chunk-ILGEM42C.mjs';
1
+ import { isObject_default } from './chunk-NCKKAFF7.mjs';
2
2
  import { root_default, isObjectLike_default, freeGlobal_default, baseGetTag_default, Symbol_default, isArray_default } from './chunk-FNTGY7I5.mjs';
3
3
 
4
4
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_listCacheClear.js
@@ -1512,4 +1512,4 @@ function errorMessage(error) {
1512
1512
  return String(error);
1513
1513
  }
1514
1514
 
1515
- export { MapCache_default, Stack_default, Uint8Array_default, baseAssignValue_default, baseFor_default, coerceNumberToString, deepCloneAndMergeReplacingArrays, eq_default, errorMessage, exhaustiveSwitch, formatFileSize, getAllKeys_default, getFromRecordOrNull, getTag_default, hasOwnProperty12 as hasOwnProperty, identity_default, invariant, isArguments_default, isBuffer_default, isEmpty2 as isEmpty, isFunction_default, isIndex_default, isLength_default, isNotNullish, isNullish, isPrimitive, isTypedArray_default, keys_default, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, warning };
1515
+ export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty12 as hasOwnProperty, invariant, isEmpty2 as isEmpty, isFunction_default, isNotNullish, isNullish, isPrimitive, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, warning };
@@ -1,12 +1,12 @@
1
- import type { Cart } from "../_vendor/schemas/cart";
2
- import { ReploError } from "../_vendor/schemas/errors";
1
+ import type { Cart } from "../cart/cart-schema";
2
+ import { CanopyError } from "../lib/canopy-error";
3
3
  type CanopyApiGatewayErrorConfig = {
4
4
  message: string;
5
5
  statusCode?: number;
6
6
  cause?: unknown;
7
7
  additionalData?: Record<string, unknown>;
8
8
  };
9
- export declare class CanopyApiGatewayError extends ReploError {
9
+ export declare class CanopyApiGatewayError extends CanopyError {
10
10
  statusCode: number;
11
11
  constructor(config: CanopyApiGatewayErrorConfig);
12
12
  }
@@ -1,9 +1,9 @@
1
- import { cartSchema } from "../_vendor/schemas/cart.mjs";
2
- import { ReploError } from "../_vendor/schemas/errors.mjs";
3
1
  import { z } from "zod";
2
+ import { cartSchema } from "../cart/cart-schema";
4
3
  import { getEnv } from "../env";
4
+ import { CanopyError } from "../lib/canopy-error";
5
5
  import { buildBaseUrl } from "../lib/url-utils";
6
- class CanopyApiGatewayError extends ReploError {
6
+ class CanopyApiGatewayError extends CanopyError {
7
7
  statusCode;
8
8
  constructor(config) {
9
9
  const resolvedStatusCode = config.statusCode ?? 500;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../gateways/canopy-api.ts"],
4
- "sourcesContent": ["import type { Cart } from \"schemas/cart\";\n\nimport { cartSchema } from \"schemas/cart\";\nimport { ReploError } from \"schemas/errors\";\nimport { z } from \"zod\";\n\nimport { getEnv } from \"../env\";\nimport { buildBaseUrl } from \"../lib/url-utils\";\n\ntype CanopyApiGatewayErrorConfig = {\n message: string;\n statusCode?: number;\n cause?: unknown;\n additionalData?: Record<string, unknown>;\n};\n\nexport class CanopyApiGatewayError extends ReploError {\n statusCode: number;\n\n constructor(config: CanopyApiGatewayErrorConfig) {\n const resolvedStatusCode = config.statusCode ?? 500;\n super({\n message: config.message,\n cause: config.cause,\n additionalData: {\n ...config.additionalData,\n statusCode: resolvedStatusCode,\n },\n });\n this.statusCode = resolvedStatusCode;\n }\n}\n\nexport function isCanopyApiGatewayError(\n error: unknown,\n): error is CanopyApiGatewayError {\n return error instanceof CanopyApiGatewayError;\n}\n\nclass UnknownCanopyApiError extends CanopyApiGatewayError {\n constructor(config: Omit<CanopyApiGatewayErrorConfig, \"statusCode\">) {\n super({ ...config, statusCode: 502 });\n }\n}\n\nconst loaderInvokeResponseSchema = z.object({\n data: z.unknown(),\n meta: z\n .object({\n cache: z.object({\n hit: z.boolean(),\n ttlSeconds: z.number(),\n }),\n })\n .optional(),\n});\n\nclass CanopyApiGateway {\n private apiHost: string;\n private baseUrl: string;\n constructor(apiHost: string) {\n this.apiHost = apiHost;\n this.baseUrl = buildBaseUrl(apiHost);\n }\n\n private static readonly REQUEST_TIMEOUT_MILLISECONDS = 10_000;\n\n static async setup() {\n const env = await getEnv();\n\n return new CanopyApiGateway(env.CANOPY_API_HOST);\n }\n\n private async _post(url: string, body: unknown) {\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n try {\n return await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n signal: abortController.signal,\n });\n } catch (error) {\n let message = `Failed to POST to canopy-api at ${url}: ${error}`;\n if (process.env.NODE_ENV !== \"production\") {\n message += `\\n\\napiHost: ${this.apiHost}\\nIf you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;\n }\n throw new UnknownCanopyApiError({ message, cause: error });\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n private async _get(url: string) {\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n try {\n return await fetch(url, { signal: abortController.signal });\n } catch (error) {\n let message = `Failed to GET from canopy-api at ${url}: ${error}`;\n if (process.env.NODE_ENV !== \"production\") {\n message += `\\n\\napiHost: ${this.apiHost}\\nIf you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;\n }\n throw new UnknownCanopyApiError({ message, cause: error });\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n async invokeLoader({\n loaderKey,\n args,\n }: {\n loaderKey: string;\n args: Record<string, unknown>;\n }) {\n const env = await getEnv();\n const response = await this._post(`${this.baseUrl}/api/v1/loaders/invoke`, {\n projectId: env.PROJECT_ID,\n loaderKey,\n args,\n });\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => \"\");\n throw new CanopyApiGatewayError({\n message: `Failed to invoke loader ${loaderKey}: ${response.status} ${response.statusText}${errorBody ? ` \u2014 ${errorBody}` : \"\"}`,\n statusCode: response.status,\n });\n }\n\n return loaderInvokeResponseSchema.parse(await response.json());\n }\n\n // ---------------------------------------------------------------------------\n // Cart operations (canopy-api-backed ExternalCart)\n // ---------------------------------------------------------------------------\n\n private async _cartPost(\n path: string,\n body: Record<string, unknown>,\n ): Promise<Cart> {\n const env = await getEnv();\n const authSecret = env.CART_AUTH_SECRET;\n const url = `${this.baseUrl}/api/v1/cart${path}`;\n\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(authSecret ? { \"X-Replo-Resolver-Auth\": authSecret } : {}),\n },\n body: JSON.stringify({ ...body, projectId: env.PROJECT_ID }),\n signal: abortController.signal,\n });\n } catch (error) {\n throw new UnknownCanopyApiError({\n message: `Failed to POST cart operation to ${url}: ${error}`,\n cause: error,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n throw new CanopyApiGatewayError({\n message: `Cart operation ${path} failed: ${response.status} ${response.statusText} \u2014 ${text}`,\n statusCode: response.status,\n });\n }\n\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const json = (await response.json()) as { data: unknown };\n return cartSchema.parse(json.data);\n }\n\n async cartGet({ cartId }: { cartId: string }): Promise<Cart | null> {\n try {\n return await this._cartPost(\"/get\", { cartId });\n } catch (error) {\n if (error instanceof CanopyApiGatewayError && error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n async cartCreate(options?: {\n lines?: {\n merchandiseId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n discountCodes?: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/create\", {\n lines: options?.lines,\n discountCodes: options?.discountCodes,\n });\n }\n\n async cartAddLines({\n cartId,\n lines,\n }: {\n cartId: string;\n lines: {\n merchandiseId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n }): Promise<Cart> {\n return this._cartPost(\"/add-lines\", { cartId, lines });\n }\n\n async cartUpdateLines({\n cartId,\n lines,\n }: {\n cartId: string;\n lines: {\n lineId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n }): Promise<Cart> {\n return this._cartPost(\"/update-lines\", { cartId, lines });\n }\n\n async cartRemoveLines({\n cartId,\n lineIds,\n }: {\n cartId: string;\n lineIds: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/remove-lines\", { cartId, lineIds });\n }\n\n async cartUpdateDiscountCodes({\n cartId,\n discountCodes,\n }: {\n cartId: string;\n discountCodes: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/update-discount-codes\", { cartId, discountCodes });\n }\n}\n\nexport async function getCanopyApiGateway() {\n return CanopyApiGateway.setup();\n}\n"],
5
- "mappings": "AAEA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,SAAS;AAElB,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAStB,MAAM,8BAA8B,WAAW;AAAA,EACpD;AAAA,EAEA,YAAY,QAAqC;AAC/C,UAAM,qBAAqB,OAAO,cAAc;AAChD,UAAM;AAAA,MACJ,SAAS,OAAO;AAAA,MAChB,OAAO,OAAO;AAAA,MACd,gBAAgB;AAAA,QACd,GAAG,OAAO;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,wBACd,OACgC;AAChC,SAAO,iBAAiB;AAC1B;AAEA,MAAM,8BAA8B,sBAAsB;AAAA,EACxD,YAAY,QAAyD;AACnE,UAAM,EAAE,GAAG,QAAQ,YAAY,IAAI,CAAC;AAAA,EACtC;AACF;AAEA,MAAM,6BAA6B,EAAE,OAAO;AAAA,EAC1C,MAAM,EAAE,QAAQ;AAAA,E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Q,MAAM,CAAC;AAAA,EACvD;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAQkB;AAChB,WAAO,KAAK,UAAU,iBAAiB,EAAE,QAAQ,MAAM,CAAC;AAAA,EAC1D;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAGkB;AAChB,WAAO,KAAK,UAAU,iBAAiB,EAAE,QAAQ,QAAQ,CAAC;AAAA,EAC5D;AAAA,EAEA,MAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GAGkB;AAChB,WAAO,KAAK,UAAU,0BAA0B,EAAE,QAAQ,cAAc,CAAC;AAAA,EAC3E;AACF;AAEA,eAAsB,sBAAsB;AAC1C,SAAO,iBAAiB,MAAM;AAChC;",
4
+ "sourcesContent": ["import type { Cart } from \"../cart/cart-schema\";\n\nimport { z } from \"zod\";\n\nimport { cartSchema } from \"../cart/cart-schema\";\nimport { getEnv } from \"../env\";\nimport { CanopyError } from \"../lib/canopy-error\";\nimport { buildBaseUrl } from \"../lib/url-utils\";\n\ntype CanopyApiGatewayErrorConfig = {\n message: string;\n statusCode?: number;\n cause?: unknown;\n additionalData?: Record<string, unknown>;\n};\n\nexport class CanopyApiGatewayError extends CanopyError {\n statusCode: number;\n\n constructor(config: CanopyApiGatewayErrorConfig) {\n const resolvedStatusCode = config.statusCode ?? 500;\n super({\n message: config.message,\n cause: config.cause,\n additionalData: {\n ...config.additionalData,\n statusCode: resolvedStatusCode,\n },\n });\n this.statusCode = resolvedStatusCode;\n }\n}\n\nexport function isCanopyApiGatewayError(\n error: unknown,\n): error is CanopyApiGatewayError {\n return error instanceof CanopyApiGatewayError;\n}\n\nclass UnknownCanopyApiError extends CanopyApiGatewayError {\n constructor(config: Omit<CanopyApiGatewayErrorConfig, \"statusCode\">) {\n super({ ...config, statusCode: 502 });\n }\n}\n\nconst loaderInvokeResponseSchema = z.object({\n data: z.unknown(),\n meta: z\n .object({\n cache: z.object({\n hit: z.boolean(),\n ttlSeconds: z.number(),\n }),\n })\n .optional(),\n});\n\nclass CanopyApiGateway {\n private apiHost: string;\n private baseUrl: string;\n constructor(apiHost: string) {\n this.apiHost = apiHost;\n this.baseUrl = buildBaseUrl(apiHost);\n }\n\n private static readonly REQUEST_TIMEOUT_MILLISECONDS = 10_000;\n\n static async setup() {\n const env = await getEnv();\n\n return new CanopyApiGateway(env.CANOPY_API_HOST);\n }\n\n private async _post(url: string, body: unknown) {\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n try {\n return await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n signal: abortController.signal,\n });\n } catch (error) {\n let message = `Failed to POST to canopy-api at ${url}: ${error}`;\n if (process.env.NODE_ENV !== \"production\") {\n message += `\\n\\napiHost: ${this.apiHost}\\nIf you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;\n }\n throw new UnknownCanopyApiError({ message, cause: error });\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n private async _get(url: string) {\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n try {\n return await fetch(url, { signal: abortController.signal });\n } catch (error) {\n let message = `Failed to GET from canopy-api at ${url}: ${error}`;\n if (process.env.NODE_ENV !== \"production\") {\n message += `\\n\\napiHost: ${this.apiHost}\\nIf you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;\n }\n throw new UnknownCanopyApiError({ message, cause: error });\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n async invokeLoader({\n loaderKey,\n args,\n }: {\n loaderKey: string;\n args: Record<string, unknown>;\n }) {\n const env = await getEnv();\n const response = await this._post(`${this.baseUrl}/api/v1/loaders/invoke`, {\n projectId: env.PROJECT_ID,\n loaderKey,\n args,\n });\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => \"\");\n throw new CanopyApiGatewayError({\n message: `Failed to invoke loader ${loaderKey}: ${response.status} ${response.statusText}${errorBody ? ` \u2014 ${errorBody}` : \"\"}`,\n statusCode: response.status,\n });\n }\n\n return loaderInvokeResponseSchema.parse(await response.json());\n }\n\n // ---------------------------------------------------------------------------\n // Cart operations (canopy-api-backed ExternalCart)\n // ---------------------------------------------------------------------------\n\n private async _cartPost(\n path: string,\n body: Record<string, unknown>,\n ): Promise<Cart> {\n const env = await getEnv();\n const authSecret = env.CART_AUTH_SECRET;\n const url = `${this.baseUrl}/api/v1/cart${path}`;\n\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(authSecret ? { \"X-Replo-Resolver-Auth\": authSecret } : {}),\n },\n body: JSON.stringify({ ...body, projectId: env.PROJECT_ID }),\n signal: abortController.signal,\n });\n } catch (error) {\n throw new UnknownCanopyApiError({\n message: `Failed to POST cart operation to ${url}: ${error}`,\n cause: error,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n throw new CanopyApiGatewayError({\n message: `Cart operation ${path} failed: ${response.status} ${response.statusText} \u2014 ${text}`,\n statusCode: response.status,\n });\n }\n\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const json = (await response.json()) as { data: unknown };\n return cartSchema.parse(json.data);\n }\n\n async cartGet({ cartId }: { cartId: string }): Promise<Cart | null> {\n try {\n return await this._cartPost(\"/get\", { cartId });\n } catch (error) {\n if (error instanceof CanopyApiGatewayError && error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n async cartCreate(options?: {\n lines?: {\n merchandiseId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n discountCodes?: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/create\", {\n lines: options?.lines,\n discountCodes: options?.discountCodes,\n });\n }\n\n async cartAddLines({\n cartId,\n lines,\n }: {\n cartId: string;\n lines: {\n merchandiseId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n }): Promise<Cart> {\n return this._cartPost(\"/add-lines\", { cartId, lines });\n }\n\n async cartUpdateLines({\n cartId,\n lines,\n }: {\n cartId: string;\n lines: {\n lineId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n }): Promise<Cart> {\n return this._cartPost(\"/update-lines\", { cartId, lines });\n }\n\n async cartRemoveLines({\n cartId,\n lineIds,\n }: {\n cartId: string;\n lineIds: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/remove-lines\", { cartId, lineIds });\n }\n\n async cartUpdateDiscountCodes({\n cartId,\n discountCodes,\n }: {\n cartId: string;\n discountCodes: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/update-discount-codes\", { cartId, discountCodes });\n }\n}\n\nexport async function getCanopyApiGateway() {\n return CanopyApiGateway.setup();\n}\n"],
5
+ "mappings": "AAEA,SAAS,SAAS;AAElB,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAStB,MAAM,8BAA8B,YAAY;AAAA,EACrD;AAAA,EAEA,YAAY,QAAqC;AAC/C,UAAM,qBAAqB,OAAO,cAAc;AAChD,UAAM;AAAA,MACJ,SAAS,OAAO;AAAA,MAChB,OAAO,OAAO;AAAA,MACd,gBAAgB;AAAA,QACd,GAAG,OAAO;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,wBACd,OACgC;AAChC,SAAO,iBAAiB;AAC1B;AAEA,MAAM,8BAA8B,sBAAs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,SAAS;AAAA,MAChB,eAAe,SAAS;AAAA,IAC1B,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,EACF,GAQkB;AAChB,WAAO,KAAK,UAAU,cAAc,EAAE,QAAQ,MAAM,CAAC;AAAA,EACvD;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAQkB;AAChB,WAAO,KAAK,UAAU,iBAAiB,EAAE,QAAQ,MAAM,CAAC;AAAA,EAC1D;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAGkB;AAChB,WAAO,KAAK,UAAU,iBAAiB,EAAE,QAAQ,QAAQ,CAAC;AAAA,EAC5D;AAAA,EAEA,MAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GAGkB;AAChB,WAAO,KAAK,UAAU,0BAA0B,EAAE,QAAQ,cAAc,CAAC;AAAA,EAC3E;AACF;AAEA,eAAsB,sBAAsB;AAC1C,SAAO,iBAAiB,MAAM;AAChC;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,25 @@
1
+ export type CanopyErrorConfig = {
2
+ /**
3
+ * Message of the error. If not provided, defaults to the error's class name.
4
+ */
5
+ message?: string;
6
+ /**
7
+ * Additional context about the error (ids, contextual variables, etc.),
8
+ * surfaced when the error is logged.
9
+ */
10
+ additionalData?: Record<string, unknown>;
11
+ /**
12
+ * Original cause of the error, useful when catching and re-throwing with more
13
+ * context.
14
+ */
15
+ cause?: unknown;
16
+ };
17
+ /**
18
+ * Base error that all canopy-sdk errors inherit from. Deliberately minimal and
19
+ * self-contained; it does not depend on the `schemas` workspace package.
20
+ */
21
+ export declare abstract class CanopyError extends Error {
22
+ config: CanopyErrorConfig;
23
+ id: string;
24
+ constructor(config: CanopyErrorConfig);
25
+ }
@@ -0,0 +1,24 @@
1
+ class CanopyError extends Error {
2
+ config;
3
+ id;
4
+ constructor(config) {
5
+ super(config.message);
6
+ this.message = config.message ?? this.constructor.name;
7
+ this.config = config;
8
+ this.id = crypto.randomUUID();
9
+ const { cause } = config;
10
+ if (cause) {
11
+ this.cause = cause;
12
+ if (cause instanceof CanopyError) {
13
+ this.config.additionalData = {
14
+ ...this.config.additionalData,
15
+ ...cause.config.additionalData
16
+ };
17
+ }
18
+ }
19
+ }
20
+ }
21
+ export {
22
+ CanopyError
23
+ };
24
+ //# sourceMappingURL=canopy-error.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../lib/canopy-error.ts"],
4
+ "sourcesContent": ["// NOTE (Ryan, 2026-07-23, REPL-27611): Local error base for canopy-sdk's\n// published-page code. Mirrors the minimal surface of `schemas`' `ReploError`\n// (a `config` bag, a stable `id`, and cause chaining) that canopy's scoped\n// error classes actually use, so nothing shipped to a generated site imports\n// from `schemas`.\n\nexport type CanopyErrorConfig = {\n /**\n * Message of the error. If not provided, defaults to the error's class name.\n */\n message?: string;\n /**\n * Additional context about the error (ids, contextual variables, etc.),\n * surfaced when the error is logged.\n */\n additionalData?: Record<string, unknown>;\n /**\n * Original cause of the error, useful when catching and re-throwing with more\n * context.\n */\n cause?: unknown;\n};\n\n/**\n * Base error that all canopy-sdk errors inherit from. Deliberately minimal and\n * self-contained; it does not depend on the `schemas` workspace package.\n */\nexport abstract class CanopyError extends Error {\n config: CanopyErrorConfig;\n id: string;\n\n constructor(config: CanopyErrorConfig) {\n super(config.message);\n this.message = config.message ?? this.constructor.name;\n this.config = config;\n // crypto.randomUUID is natively available in browsers, Node, and the\n // Cloudflare Workers runtime \u2014 the three environments canopy-sdk runs in.\n this.id = crypto.randomUUID();\n\n const { cause } = config;\n if (cause) {\n this.cause = cause;\n if (cause instanceof CanopyError) {\n this.config.additionalData = {\n ...this.config.additionalData,\n ...cause.config.additionalData,\n };\n }\n }\n }\n}\n"],
5
+ "mappings": "AA2BO,MAAe,oBAAoB,MAAM;AAAA,EAC9C;AAAA,EACA;AAAA,EAEA,YAAY,QAA2B;AACrC,UAAM,OAAO,OAAO;AACpB,SAAK,UAAU,OAAO,WAAW,KAAK,YAAY;AAClD,SAAK,SAAS;AAGd,SAAK,KAAK,OAAO,WAAW;AAE5B,UAAM,EAAE,MAAM,IAAI;AAClB,QAAI,OAAO;AACT,WAAK,QAAQ;AACb,UAAI,iBAAiB,aAAa;AAChC,aAAK,OAAO,iBAAiB;AAAA,UAC3B,GAAG,KAAK,OAAO;AAAA,UACf,GAAG,MAAM,OAAO;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
- import type { FullCollection } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product";
2
+ import type { FullCollection } from "./loader-schemas";
3
3
  type CollectionLoaderProps = {
4
4
  loaderKey: string;
5
5
  handle?: string;
@@ -2,9 +2,9 @@
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { Suspense } from "react";
4
4
  import { useSuspenseQuery } from "@tanstack/react-query";
5
- import { fullCollectionSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs";
6
5
  import { invokeLoader } from "./invoke-loader";
7
6
  import { LoaderErrorBoundary } from "./loader-error-boundary";
7
+ import { fullCollectionSchema } from "./loader-schemas";
8
8
  function CollectionLoaderInner({
9
9
  loaderKey,
10
10
  handle,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../loaders/collection-loader.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { FullCollection } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { fullCollectionSchema } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype CollectionLoaderProps = {\n loaderKey: string;\n handle?: string;\n collectionGid?: string;\n children: (data: FullCollection) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction CollectionLoaderInner({\n loaderKey,\n handle,\n collectionGid,\n children,\n}: Omit<CollectionLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { handle, collectionGid }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { handle, collectionGid },\n });\n return fullCollectionSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function CollectionLoader({\n loaderKey,\n handle,\n collectionGid,\n children,\n fallback,\n}: CollectionLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${handle ?? \"\"}:${collectionGid ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <CollectionLoaderInner\n loaderKey={loaderKey}\n handle={handle}\n collectionGid={collectionGid}\n >\n {children}\n </CollectionLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
- "mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AAErC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAUpC,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4C;AAC1C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,QAAQ,cAAc,CAAC;AAAA,IAC/C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,QAAQ,cAAc;AAAA,MAChC,CAAC;AACD,aAAO,qBAAqB,MAAM,UAAU;AAAA,IAC9C;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,UAAU,EAAE,IAAI,iBAAiB,EAAE;AAAA,MAE7D,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
4
+ "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { FullCollection } from \"./loader-schemas\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\nimport { fullCollectionSchema } from \"./loader-schemas\";\n\ntype CollectionLoaderProps = {\n loaderKey: string;\n handle?: string;\n collectionGid?: string;\n children: (data: FullCollection) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction CollectionLoaderInner({\n loaderKey,\n handle,\n collectionGid,\n children,\n}: Omit<CollectionLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { handle, collectionGid }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { handle, collectionGid },\n });\n return fullCollectionSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function CollectionLoader({\n loaderKey,\n handle,\n collectionGid,\n children,\n fallback,\n}: CollectionLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${handle ?? \"\"}:${collectionGid ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <CollectionLoaderInner\n loaderKey={loaderKey}\n handle={handle}\n collectionGid={collectionGid}\n >\n {children}\n </CollectionLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
+ "mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AAUrC,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4C;AAC1C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,QAAQ,cAAc,CAAC;AAAA,IAC/C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,QAAQ,cAAc;AAAA,MAChC,CAAC;AACD,aAAO,qBAAqB,MAAM,UAAU;AAAA,IAC9C;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,UAAU,EAAE,IAAI,iBAAiB,EAAE;AAAA,MAE7D,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
- import type { PaginatedProducts } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product";
2
+ import type { PaginatedProducts } from "./loader-schemas";
3
3
  type CollectionProductsLoaderProps = {
4
4
  loaderKey: string;
5
5
  collectionGid: string;
@@ -2,9 +2,9 @@
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { Suspense } from "react";
4
4
  import { useSuspenseQuery } from "@tanstack/react-query";
5
- import { paginatedProductsSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs";
6
5
  import { invokeLoader } from "./invoke-loader";
7
6
  import { LoaderErrorBoundary } from "./loader-error-boundary";
7
+ import { paginatedProductsSchema } from "./loader-schemas";
8
8
  function CollectionProductsLoaderInner({
9
9
  loaderKey,
10
10
  collectionGid,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../loaders/collection-products-loader.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { PaginatedProducts } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { paginatedProductsSchema } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype CollectionProductsLoaderProps = {\n loaderKey: string;\n collectionGid: string;\n first?: number;\n after?: string;\n children: (data: PaginatedProducts) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction CollectionProductsLoaderInner({\n loaderKey,\n collectionGid,\n first,\n after,\n children,\n}: Omit<CollectionProductsLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { collectionGid, first, after }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { collectionGid, first, after },\n });\n return paginatedProductsSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function CollectionProductsLoader({\n loaderKey,\n collectionGid,\n first,\n after,\n children,\n fallback,\n}: CollectionProductsLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${collectionGid}:${first ?? \"\"}:${after ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <CollectionProductsLoaderInner\n loaderKey={loaderKey}\n collectionGid={collectionGid}\n first={first}\n after={after}\n >\n {children}\n </CollectionProductsLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
- "mappings": ";AAwCS;AAnCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAExC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAWpC,SAAS,8BAA8B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoD;AAClD,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,eAAe,OAAO,MAAM,CAAC;AAAA,IACrD,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,eAAe,OAAO,MAAM;AAAA,MACtC,CAAC;AACD,aAAO,wBAAwB,MAAM,UAAU;AAAA,IACjD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAkC;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,aAAa,IAAI,SAAS,EAAE,IAAI,SAAS,EAAE;AAAA,MAErE,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
4
+ "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { PaginatedProducts } from \"./loader-schemas\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\nimport { paginatedProductsSchema } from \"./loader-schemas\";\n\ntype CollectionProductsLoaderProps = {\n loaderKey: string;\n collectionGid: string;\n first?: number;\n after?: string;\n children: (data: PaginatedProducts) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction CollectionProductsLoaderInner({\n loaderKey,\n collectionGid,\n first,\n after,\n children,\n}: Omit<CollectionProductsLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { collectionGid, first, after }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { collectionGid, first, after },\n });\n return paginatedProductsSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function CollectionProductsLoader({\n loaderKey,\n collectionGid,\n first,\n after,\n children,\n fallback,\n}: CollectionProductsLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${collectionGid}:${first ?? \"\"}:${after ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <CollectionProductsLoaderInner\n loaderKey={loaderKey}\n collectionGid={collectionGid}\n first={first}\n after={after}\n >\n {children}\n </CollectionProductsLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
+ "mappings": ";AAwCS;AAnCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAWxC,SAAS,8BAA8B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoD;AAClD,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,eAAe,OAAO,MAAM,CAAC;AAAA,IACrD,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,eAAe,OAAO,MAAM;AAAA,MACtC,CAAC;AACD,aAAO,wBAAwB,MAAM,UAAU;AAAA,IACjD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAkC;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,aAAa,IAAI,SAAS,EAAE,IAAI,SAAS,EAAE;AAAA,MAErE,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
- import { ReploError } from "../_vendor/schemas/errors";
1
+ import { CanopyError } from "../lib/canopy-error";
2
2
  /** Scoped error for loader invocation failures. */
3
- export declare class LoaderInvokeError extends ReploError {
3
+ export declare class LoaderInvokeError extends CanopyError {
4
4
  }
5
5
  export declare function isLoaderInvokeError(error: unknown): error is LoaderInvokeError;
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { ReploError } from "../_vendor/schemas/errors.mjs";
2
- class LoaderInvokeError extends ReploError {
1
+ import { CanopyError } from "../lib/canopy-error";
2
+ class LoaderInvokeError extends CanopyError {
3
3
  }
4
4
  function isLoaderInvokeError(error) {
5
5
  return error instanceof LoaderInvokeError;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../loaders/invoke-loader.ts"],
4
- "sourcesContent": ["import { ReploError } from \"schemas/errors\";\n\n/** Scoped error for loader invocation failures. */\nexport class LoaderInvokeError extends ReploError {}\n\nexport function isLoaderInvokeError(\n error: unknown,\n): error is LoaderInvokeError {\n return error instanceof LoaderInvokeError;\n}\n\n/**\n * Invokes a data loader. During SSR, calls the canopy-api gateway directly.\n * In the browser, dynamically imports a server action so React 19 never sees\n * the \"use server\" reference during render.\n */\nexport async function invokeLoader({\n loaderKey,\n args,\n}: {\n loaderKey: string;\n args: Record<string, unknown>;\n}) {\n try {\n if (typeof window === \"undefined\") {\n const { getCanopyApiGateway } = await import(\"../gateways/canopy-api\");\n const gateway = await getCanopyApiGateway();\n const response = await gateway.invokeLoader({ loaderKey, args });\n return response.data;\n }\n\n const { invokeLoaderAction } = await import(\"./invoke-loader-action\");\n return await invokeLoaderAction({ loaderKey, args });\n } catch (error) {\n if (error instanceof LoaderInvokeError) {\n throw error;\n }\n throw new LoaderInvokeError({\n message: `Loader ${loaderKey} failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n additionalData: { loaderKey },\n });\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,kBAAkB;AAGpB,MAAM,0BAA0B,WAAW;AAAC;AAE5C,SAAS,oBACd,OAC4B;AAC5B,SAAO,iBAAiB;AAC1B;AAOA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AACF,GAGG;AACD,MAAI;AACF,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,EAAE,oBAAoB,IAAI,MAAM,OAAO,wBAAwB;AACrE,YAAM,UAAU,MAAM,oBAAoB;AAC1C,YAAM,WAAW,MAAM,QAAQ,aAAa,EAAE,WAAW,KAAK,CAAC;AAC/D,aAAO,SAAS;AAAA,IAClB;AAEA,UAAM,EAAE,mBAAmB,IAAI,MAAM,OAAO,wBAAwB;AACpE,WAAO,MAAM,mBAAmB,EAAE,WAAW,KAAK,CAAC;AAAA,EACrD,SAAS,OAAO;AACd,QAAI,iBAAiB,mBAAmB;AACtC,YAAM;AAAA,IACR;AACA,UAAM,IAAI,kBAAkB;AAAA,MAC1B,SAAS,UAAU,SAAS,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MAC9F,OAAO;AAAA,MACP,gBAAgB,EAAE,UAAU;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;",
4
+ "sourcesContent": ["import { CanopyError } from \"../lib/canopy-error\";\n\n/** Scoped error for loader invocation failures. */\nexport class LoaderInvokeError extends CanopyError {}\n\nexport function isLoaderInvokeError(\n error: unknown,\n): error is LoaderInvokeError {\n return error instanceof LoaderInvokeError;\n}\n\n/**\n * Invokes a data loader. During SSR, calls the canopy-api gateway directly.\n * In the browser, dynamically imports a server action so React 19 never sees\n * the \"use server\" reference during render.\n */\nexport async function invokeLoader({\n loaderKey,\n args,\n}: {\n loaderKey: string;\n args: Record<string, unknown>;\n}) {\n try {\n if (typeof window === \"undefined\") {\n const { getCanopyApiGateway } = await import(\"../gateways/canopy-api\");\n const gateway = await getCanopyApiGateway();\n const response = await gateway.invokeLoader({ loaderKey, args });\n return response.data;\n }\n\n const { invokeLoaderAction } = await import(\"./invoke-loader-action\");\n return await invokeLoaderAction({ loaderKey, args });\n } catch (error) {\n if (error instanceof LoaderInvokeError) {\n throw error;\n }\n throw new LoaderInvokeError({\n message: `Loader ${loaderKey} failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n additionalData: { loaderKey },\n });\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAGrB,MAAM,0BAA0B,YAAY;AAAC;AAE7C,SAAS,oBACd,OAC4B;AAC5B,SAAO,iBAAiB;AAC1B;AAOA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AACF,GAGG;AACD,MAAI;AACF,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,EAAE,oBAAoB,IAAI,MAAM,OAAO,wBAAwB;AACrE,YAAM,UAAU,MAAM,oBAAoB;AAC1C,YAAM,WAAW,MAAM,QAAQ,aAAa,EAAE,WAAW,KAAK,CAAC;AAC/D,aAAO,SAAS;AAAA,IAClB;AAEA,UAAM,EAAE,mBAAmB,IAAI,MAAM,OAAO,wBAAwB;AACpE,WAAO,MAAM,mBAAmB,EAAE,WAAW,KAAK,CAAC;AAAA,EACrD,SAAS,OAAO;AACd,QAAI,iBAAiB,mBAAmB;AACtC,YAAM;AAAA,IACR;AACA,UAAM,IAAI,kBAAkB;AAAA,MAC1B,SAAS,UAAU,SAAS,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MAC9F,OAAO;AAAA,MACP,gBAAgB,EAAE,UAAU;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
- import type { LevantaProductFull } from "../_vendor/schemas/agentTools/customIntegrations/loaders/levanta";
2
+ import type { LevantaProductFull } from "./loader-schemas";
3
3
  type LevantaProductLoaderProps = {
4
4
  loaderKey: string;
5
5
  asin: string;
@@ -2,9 +2,9 @@
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { Suspense } from "react";
4
4
  import { useSuspenseQuery } from "@tanstack/react-query";
5
- import { levantaProductFullSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs";
6
5
  import { invokeLoader } from "./invoke-loader";
7
6
  import { LoaderErrorBoundary } from "./loader-error-boundary";
7
+ import { levantaProductFullSchema } from "./loader-schemas";
8
8
  function LevantaProductLoaderInner({
9
9
  loaderKey,
10
10
  asin,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../loaders/levanta-product-loader.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { LevantaProductFull } from \"schemas/agentTools/customIntegrations/loaders/levanta\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { levantaProductFullSchema } from \"schemas/agentTools/customIntegrations/loaders/levanta\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype LevantaProductLoaderProps = {\n loaderKey: string;\n asin: string;\n marketplace?: string;\n children: (data: LevantaProductFull) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction LevantaProductLoaderInner({\n loaderKey,\n asin,\n marketplace,\n children,\n}: Omit<LevantaProductLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { asin, marketplace }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { asin, marketplace },\n });\n return levantaProductFullSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function LevantaProductLoader({\n loaderKey,\n asin,\n marketplace,\n children,\n fallback,\n}: LevantaProductLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${asin}:${marketplace ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <LevantaProductLoaderInner\n loaderKey={loaderKey}\n asin={asin}\n marketplace={marketplace}\n >\n {children}\n </LevantaProductLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
- "mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AAEzC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAUpC,SAAS,0BAA0B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAgD;AAC9C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,MAAM,YAAY,CAAC;AAAA,IAC3C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,MAAM,YAAY;AAAA,MAC5B,CAAC;AACD,aAAO,yBAAyB,MAAM,UAAU;AAAA,IAClD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,IAAI,IAAI,eAAe,EAAE;AAAA,MAEnD,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
4
+ "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { LevantaProductFull } from \"./loader-schemas\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\nimport { levantaProductFullSchema } from \"./loader-schemas\";\n\ntype LevantaProductLoaderProps = {\n loaderKey: string;\n asin: string;\n marketplace?: string;\n children: (data: LevantaProductFull) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction LevantaProductLoaderInner({\n loaderKey,\n asin,\n marketplace,\n children,\n}: Omit<LevantaProductLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { asin, marketplace }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { asin, marketplace },\n });\n return levantaProductFullSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function LevantaProductLoader({\n loaderKey,\n asin,\n marketplace,\n children,\n fallback,\n}: LevantaProductLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${asin}:${marketplace ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <LevantaProductLoaderInner\n loaderKey={loaderKey}\n asin={asin}\n marketplace={marketplace}\n >\n {children}\n </LevantaProductLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
+ "mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AAUzC,SAAS,0BAA0B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAgD;AAC9C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,MAAM,YAAY,CAAC;AAAA,IAC3C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,MAAM,YAAY;AAAA,MAC5B,CAAC;AACD,aAAO,yBAAyB,MAAM,UAAU;AAAA,IAClD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,IAAI,IAAI,eAAe,EAAE;AAAA,MAEnD,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,11 @@
1
1
  import { z } from "zod";
2
2
  /**
3
- * Shared data-loader key constants. Both the integration registry and the
4
- * dependency resolver import from here so the strings are never duplicated.
3
+ * Shared data-loader key constants. Loader components and prefetch queries
4
+ * import from here so the strings are never duplicated across a generated site.
5
5
  *
6
6
  * These keys serve double duty: they identify which backend loader to invoke
7
- * AND are used as React Query cache key prefixes. Loader components
8
- * internally construct queryKey as `[loaderKey, args]`.
7
+ * AND are used as React Query cache key prefixes. Loader components internally
8
+ * construct queryKey as `[loaderKey, args]`.
9
9
  *
10
10
  * Naming convention: `<integration>.<objectType>` or
11
11
  * `<integration>.<objectType>_<qualifier>`.
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ const DATA_LOADER_KEYS = {
3
+ SHOPIFY_PRODUCT: "shopify_storefront.product",
4
+ SHOPIFY_COLLECTION: "shopify_storefront.collection",
5
+ SHOPIFY_COLLECTION_PRODUCTS: "shopify_storefront.collection_products",
6
+ REPLO_PRODUCT: "replo_products.product",
7
+ OKENDO_PRODUCT_REVIEWS: "okendo.product_reviews",
8
+ OKENDO_PRODUCT_REVIEW_AGGREGATE: "okendo.product_review_aggregate",
9
+ REBUY_RECOMMENDATIONS: "rebuy.recommendations",
10
+ LEVANTA_PRODUCT: "levanta_products.product",
11
+ SMILE_IO_VIP_TIERS: "smile_io.vip_tiers",
12
+ SMILE_IO_EARNING_RULES: "smile_io.earning_rules",
13
+ SMILE_IO_REWARDS: "smile_io.rewards",
14
+ YOTPO_PRODUCT_REVIEWS: "yotpo.product_reviews",
15
+ YOTPO_PRODUCT_REVIEW_AGGREGATE: "yotpo.product_review_aggregate"
16
+ };
17
+ const dataLoaderKeySchema = z.enum(Object.values(DATA_LOADER_KEYS));
18
+ export {
19
+ DATA_LOADER_KEYS,
20
+ dataLoaderKeySchema
21
+ };
22
+ //# sourceMappingURL=loader-keys.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../loaders/loader-keys.ts"],
4
+ "sourcesContent": ["import { z } from \"zod\";\n\n// NOTE (Ryan, 2026-07-23, REPL-27611): Canonical loader-key constants for the\n// published-page surface. canopy-sdk owns this copy so nothing shipped to a\n// generated site imports from `schemas`. The backend keeps its own copy in\n// `schemas/loaderKeys.ts` (consumed by the integration registry + tool\n// metadata, which cannot depend on canopy-sdk without a cycle); the two are\n// kept in lockstep by the drift guard in `loader-keys.spec.ts`.\n\n/**\n * Shared data-loader key constants. Loader components and prefetch queries\n * import from here so the strings are never duplicated across a generated site.\n *\n * These keys serve double duty: they identify which backend loader to invoke\n * AND are used as React Query cache key prefixes. Loader components internally\n * construct queryKey as `[loaderKey, args]`.\n *\n * Naming convention: `<integration>.<objectType>` or\n * `<integration>.<objectType>_<qualifier>`.\n */\nexport const DATA_LOADER_KEYS = {\n SHOPIFY_PRODUCT: \"shopify_storefront.product\",\n SHOPIFY_COLLECTION: \"shopify_storefront.collection\",\n SHOPIFY_COLLECTION_PRODUCTS: \"shopify_storefront.collection_products\",\n REPLO_PRODUCT: \"replo_products.product\",\n OKENDO_PRODUCT_REVIEWS: \"okendo.product_reviews\",\n OKENDO_PRODUCT_REVIEW_AGGREGATE: \"okendo.product_review_aggregate\",\n REBUY_RECOMMENDATIONS: \"rebuy.recommendations\",\n LEVANTA_PRODUCT: \"levanta_products.product\",\n SMILE_IO_VIP_TIERS: \"smile_io.vip_tiers\",\n SMILE_IO_EARNING_RULES: \"smile_io.earning_rules\",\n SMILE_IO_REWARDS: \"smile_io.rewards\",\n YOTPO_PRODUCT_REVIEWS: \"yotpo.product_reviews\",\n YOTPO_PRODUCT_REVIEW_AGGREGATE: \"yotpo.product_review_aggregate\",\n} as const;\n\nexport type DataLoaderKey =\n (typeof DATA_LOADER_KEYS)[keyof typeof DATA_LOADER_KEYS];\n\nexport const dataLoaderKeySchema = z.enum(Object.values(DATA_LOADER_KEYS));\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAoBX,MAAM,mBAAmB;AAAA,EAC9B,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,6BAA6B;AAAA,EAC7B,eAAe;AAAA,EACf,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACjC,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,wBAAwB;AAAA,EACxB,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,gCAAgC;AAClC;AAKO,MAAM,sBAAsB,EAAE,KAAK,OAAO,OAAO,gBAAgB,CAAC;",
6
+ "names": []
7
+ }