@replohq/canopy-sdk 0.20.2 → 1.0.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.
- package/_vendor/replo-utils/lib/crypto.d.ts +30 -0
- package/_vendor/replo-utils/lib/errors.d.ts +83 -0
- package/_vendor/replo-utils/lib/json.mjs +1 -1
- package/_vendor/replo-utils/lib/misc.mjs +2 -2
- package/_vendor/schemas/errors.d.ts +438 -0
- package/_vendor/schemas/generated/errors.d.ts +61 -0
- package/_vendor/schemas/money.d.ts +55 -0
- package/_vendor/schemas/money.mjs +193 -0
- package/_vendor/schemas/selectMode.mjs +2 -2
- package/analytics/analytics-sink.d.ts +6 -0
- package/cart/cart-provider.js +18 -4
- package/cart/cart-provider.js.map +2 -2
- package/cart/cart-types.d.ts +2 -0
- package/cart/cart-types.js.map +2 -2
- package/cart/gateways/cart-constants.d.ts +1 -1
- package/cart/gateways/cart-constants.js +1 -1
- package/cart/gateways/cart-constants.js.map +2 -2
- package/cart/gateways/default-cart-gateway.js +1 -1
- package/cart/gateways/default-cart-gateway.js.map +2 -2
- package/cart/hooks/use-add-to-cart.js +6 -2
- package/cart/hooks/use-add-to-cart.js.map +2 -2
- package/cart/utils/cart-utils.d.ts +0 -4
- package/cart/utils/cart-utils.js +0 -8
- package/cart/utils/cart-utils.js.map +2 -2
- package/cart/utils/variant-to-cart-line.js +22 -5
- package/cart/utils/variant-to-cart-line.js.map +2 -2
- package/{chunk-ME5W2TJM.mjs → chunk-UWHM3FKU.mjs} +1 -1
- package/hooks/use-formatted-price.d.ts +1 -1
- package/hooks/use-formatted-price.js +7 -6
- package/hooks/use-formatted-price.js.map +2 -2
- package/money.d.ts +9 -0
- package/money.js +13 -0
- package/money.js.map +7 -0
- package/package.json +2 -1
- package/{chunk-NCKKAFF7.mjs → chunk-ILGEM42C.mjs} +7 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/utils/cart-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Cart, CartLine } from \"../cart-types\";\n\nimport { getCartLinePricing } from \"./variant-to-cart-line\";\n\nexport interface CartTotals {\n subtotal: number;\n discountAmount: number;\n totalSavings: number;\n total: number;\n}\n\n/**\n * Sum the final (post selling-plan) price of every line item in the cart.\n * This is the authoritative subtotal for cookie-based carts, which have no\n * server-computed cost to rely on.\n */\nexport function calculateLineItemsSubtotal(lineItems: CartLine[]): number {\n return lineItems.reduce(\n (sum, item) => sum + getCartLinePricing(item).finalPrice * item.quantity,\n 0,\n );\n}\n\n/**\n * Calculate cart totals including subtotal, discounts, and final total.\n * When cart cost data is provided (from Shopify), uses the actual totalAmount\n * which includes cart-level discounts from discount codes.\n *\n * @param options - Object containing lineItems and cart\n * @param options.lineItems - Array of cart line items\n * @param options.cart - Optional cart data from Shopify (includes discount codes)\n */\nexport function calculateCartTotals({\n lineItems,\n cart,\n}: {\n lineItems: CartLine[];\n cart: Cart | null;\n}): CartTotals {\n const lineItemSubtotal = calculateLineItemsSubtotal(lineItems);\n const compareAtSubtotal = lineItems.reduce((sum, item) => {\n return sum + getCartLinePricing(item).compareAtPrice * item.quantity;\n }, 0);\n\n // NOTE (Jasmine, 2026-07-22): Trust the provider's authoritative cost when\n // present. For Shopify this is the server-computed cart cost (including a\n // legitimate $0 when items aren't purchasable), which we must not\n // second-guess; cookie carts keep their cost truthful via\n // cookie-cart-persistence.ts.\n const total = cart?.cost.totalAmount ?? lineItemSubtotal;\n\n // If we have provider cost data, use subtotalAmount which doesn't include discounts\n const actualSubtotal = cart?.cost.subtotalAmount ?? lineItemSubtotal;\n const discountAmount = actualSubtotal - total;\n\n const totalSavings = compareAtSubtotal - total;\n\n return {\n subtotal: lineItemSubtotal,\n discountAmount,\n totalSavings,\n total,\n };\n}\n\n/**\n *
|
|
5
|
-
"mappings": "AAEA,SAAS,0BAA0B;AAc5B,SAAS,2BAA2B,WAA+B;AACxE,SAAO,UAAU;AAAA,IACf,CAAC,KAAK,SAAS,MAAM,mBAAmB,IAAI,EAAE,aAAa,KAAK;AAAA,IAChE;AAAA,EACF;AACF;AAWO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGe;AACb,QAAM,mBAAmB,2BAA2B,SAAS;AAC7D,QAAM,oBAAoB,UAAU,OAAO,CAAC,KAAK,SAAS;AACxD,WAAO,MAAM,mBAAmB,IAAI,EAAE,iBAAiB,KAAK;AAAA,EAC9D,GAAG,CAAC;AAOJ,QAAM,QAAQ,MAAM,KAAK,eAAe;AAGxC,QAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,QAAM,iBAAiB,iBAAiB;AAExC,QAAM,eAAe,oBAAoB;AAEzC,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;
|
|
4
|
+
"sourcesContent": ["import type { Cart, CartLine } from \"../cart-types\";\n\nimport { getCartLinePricing } from \"./variant-to-cart-line\";\n\nexport interface CartTotals {\n subtotal: number;\n discountAmount: number;\n totalSavings: number;\n total: number;\n}\n\n/**\n * Sum the final (post selling-plan) price of every line item in the cart.\n * This is the authoritative subtotal for cookie-based carts, which have no\n * server-computed cost to rely on.\n */\nexport function calculateLineItemsSubtotal(lineItems: CartLine[]): number {\n return lineItems.reduce(\n (sum, item) => sum + getCartLinePricing(item).finalPrice * item.quantity,\n 0,\n );\n}\n\n/**\n * Calculate cart totals including subtotal, discounts, and final total.\n * When cart cost data is provided (from Shopify), uses the actual totalAmount\n * which includes cart-level discounts from discount codes.\n *\n * @param options - Object containing lineItems and cart\n * @param options.lineItems - Array of cart line items\n * @param options.cart - Optional cart data from Shopify (includes discount codes)\n */\nexport function calculateCartTotals({\n lineItems,\n cart,\n}: {\n lineItems: CartLine[];\n cart: Cart | null;\n}): CartTotals {\n const lineItemSubtotal = calculateLineItemsSubtotal(lineItems);\n const compareAtSubtotal = lineItems.reduce((sum, item) => {\n return sum + getCartLinePricing(item).compareAtPrice * item.quantity;\n }, 0);\n\n // NOTE (Jasmine, 2026-07-22): Trust the provider's authoritative cost when\n // present. For Shopify this is the server-computed cart cost (including a\n // legitimate $0 when items aren't purchasable), which we must not\n // second-guess; cookie carts keep their cost truthful via\n // cookie-cart-persistence.ts.\n const total = cart?.cost.totalAmount ?? lineItemSubtotal;\n\n // If we have provider cost data, use subtotalAmount which doesn't include discounts\n const actualSubtotal = cart?.cost.subtotalAmount ?? lineItemSubtotal;\n const discountAmount = actualSubtotal - total;\n\n const totalSavings = compareAtSubtotal - total;\n\n return {\n subtotal: lineItemSubtotal,\n discountAmount,\n totalSavings,\n total,\n };\n}\n\n/**\n * Validates and formats a Shopify selling plan ID to ensure it has the correct GID format.\n *\n * @param sellingPlanId - The selling plan ID to validate and format\n * @returns The formatted selling plan ID with GID prefix, or null if no ID provided\n */\nexport function formatSellingPlanId(\n sellingPlanId: string | null | undefined,\n): string | null {\n if (!sellingPlanId) {\n return null;\n }\n\n // Check if it already has the gid format\n if (sellingPlanId.startsWith(\"gid://shopify/SellingPlan/\")) {\n return sellingPlanId;\n }\n\n // If it doesn't have the gid format, prepend it\n return `gid://shopify/SellingPlan/${sellingPlanId}`;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,0BAA0B;AAc5B,SAAS,2BAA2B,WAA+B;AACxE,SAAO,UAAU;AAAA,IACf,CAAC,KAAK,SAAS,MAAM,mBAAmB,IAAI,EAAE,aAAa,KAAK;AAAA,IAChE;AAAA,EACF;AACF;AAWO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGe;AACb,QAAM,mBAAmB,2BAA2B,SAAS;AAC7D,QAAM,oBAAoB,UAAU,OAAO,CAAC,KAAK,SAAS;AACxD,WAAO,MAAM,mBAAmB,IAAI,EAAE,iBAAiB,KAAK;AAAA,EAC9D,GAAG,CAAC;AAOJ,QAAM,QAAQ,MAAM,KAAK,eAAe;AAGxC,QAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,QAAM,iBAAiB,iBAAiB;AAExC,QAAM,eAAe,oBAAoB;AAEzC,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQO,SAAS,oBACd,eACe;AACf,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,cAAc,WAAW,4BAA4B,GAAG;AAC1D,WAAO;AAAA,EACT;AAGA,SAAO,6BAA6B,aAAa;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
import { fromMajorUnitsToMinorUnits } from "../../_vendor/schemas/money.mjs";
|
|
1
2
|
import { convertLegacyResourceIdToGraphQLId } from "../../lib/shopify-utils";
|
|
2
3
|
import { formatSellingPlanId } from "./cart-utils";
|
|
3
|
-
function applyPriceAdjustment(variantPrice, adjustment) {
|
|
4
|
+
function applyPriceAdjustment(variantPrice, adjustment, currencyCode) {
|
|
4
5
|
switch (adjustment.valueType) {
|
|
6
|
+
// NOTE (Max, 2026-08-03): variantPrice is integer minor units, but the
|
|
7
|
+
// loader emits money-typed adjustments as decimal major units (its
|
|
8
|
+
// storefront contract), so the price/fixedAmount arms convert here at the
|
|
9
|
+
// cart boundary. Percentage is unitless and needs no conversion.
|
|
5
10
|
case "price":
|
|
6
|
-
return
|
|
11
|
+
return fromMajorUnitsToMinorUnits({
|
|
12
|
+
amount: adjustment.value,
|
|
13
|
+
currencyCode
|
|
14
|
+
});
|
|
7
15
|
case "percentage":
|
|
8
|
-
return Math.max(
|
|
16
|
+
return Math.max(
|
|
17
|
+
0,
|
|
18
|
+
Math.round(variantPrice * (1 - adjustment.value / 100))
|
|
19
|
+
);
|
|
9
20
|
case "fixedAmount":
|
|
10
|
-
return Math.max(
|
|
21
|
+
return Math.max(
|
|
22
|
+
0,
|
|
23
|
+
variantPrice - fromMajorUnitsToMinorUnits({
|
|
24
|
+
amount: adjustment.value,
|
|
25
|
+
currencyCode
|
|
26
|
+
})
|
|
27
|
+
);
|
|
11
28
|
}
|
|
12
29
|
}
|
|
13
30
|
function variantToCartLine(variant, options) {
|
|
@@ -160,7 +177,7 @@ function createOptimisticSellingPlanAllocation({
|
|
|
160
177
|
description: sellingPlan.description
|
|
161
178
|
},
|
|
162
179
|
priceAdjustments: sellingPlan.priceAdjustments.map((adj) => {
|
|
163
|
-
const adjustedPrice = variantPrice !== void 0 ? applyPriceAdjustment(variantPrice, adj) : 0;
|
|
180
|
+
const adjustedPrice = variantPrice !== void 0 ? applyPriceAdjustment(variantPrice, adj, currencyCode) : 0;
|
|
164
181
|
return {
|
|
165
182
|
compareAtPrice: {
|
|
166
183
|
amount: variantPrice ?? 0,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/utils/variant-to-cart-line.ts"],
|
|
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
|
-
"mappings": "AASA,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AAoBpC,SAAS,qBACP,cACA,
|
|
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 { fromMajorUnitsToMinorUnits } from \"schemas/money\";\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 currencyCode: string,\n): number {\n switch (adjustment.valueType) {\n // NOTE (Max, 2026-08-03): variantPrice is integer minor units, but the\n // loader emits money-typed adjustments as decimal major units (its\n // storefront contract), so the price/fixedAmount arms convert here at the\n // cart boundary. Percentage is unitless and needs no conversion.\n case \"price\":\n return fromMajorUnitsToMinorUnits({\n amount: adjustment.value,\n currencyCode,\n });\n case \"percentage\":\n return Math.max(\n 0,\n Math.round(variantPrice * (1 - adjustment.value / 100)),\n );\n case \"fixedAmount\":\n return Math.max(\n 0,\n variantPrice -\n fromMajorUnitsToMinorUnits({\n amount: adjustment.value,\n currencyCode,\n }),\n );\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, currencyCode)\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
|
+
"mappings": "AASA,SAAS,kCAAkC;AAE3C,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AAoBpC,SAAS,qBACP,cACA,YAIA,cACQ;AACR,UAAQ,WAAW,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,IAK5B,KAAK;AACH,aAAO,2BAA2B;AAAA,QAChC,QAAQ,WAAW;AAAA,Q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AA,QAC3B;AAAA,QACA,kBAAkB,YAAY,iBAAiB,IAAI,CAAC,QAAQ;AAC1D,gBAAM,gBACJ,iBAAiB,SACb,qBAAqB,cAAc,KAAK,YAAY,IACpD;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-
|
|
1
|
+
import { isObject_default } from './chunk-ILGEM42C.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
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ```tsx
|
|
7
7
|
* import { useFormattedPrice } from "canopy-sdk/hooks/use-formatted-price";
|
|
8
8
|
*
|
|
9
|
-
* const originalPrice =
|
|
9
|
+
* const originalPrice = 1999; // integer minor units
|
|
10
10
|
* const originalPriceFormatted = useFormattedPrice(originalPrice, "USD");
|
|
11
11
|
* // Display the formatted price
|
|
12
12
|
* <p>{originalPriceFormatted}</p>;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { formatAmount } from "../_vendor/schemas/money.mjs";
|
|
1
2
|
import { useClientValue } from "./use-client-value";
|
|
2
3
|
const useFormattedPrice = (price, currency) => {
|
|
3
4
|
const navigatorLanguage = useClientValue(
|
|
4
5
|
() => window.navigator.language,
|
|
5
6
|
"en-US"
|
|
6
7
|
);
|
|
7
|
-
if (
|
|
8
|
+
if (price === null) {
|
|
8
9
|
return null;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
return formatAmount({
|
|
12
|
+
amount: price,
|
|
13
|
+
currencyCode: currency ?? "USD",
|
|
14
|
+
locale: navigatorLanguage
|
|
15
|
+
});
|
|
15
16
|
};
|
|
16
17
|
export {
|
|
17
18
|
useFormattedPrice
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/use-formatted-price.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Use useFormattedPrice() hook to display prices with proper currency symbols and formatting. Pass in a price
|
|
5
|
-
"mappings": "AAIA,SAAS,sBAAsB;AAgBxB,MAAM,oBAAoB,CAC/B,OACA,aACG;AACH,QAAM,oBAAoB;AAAA,IACxB,MAAM,OAAO,UAAU;AAAA,IACvB;AAAA,EACF;
|
|
4
|
+
"sourcesContent": ["/**\n * Use useFormattedPrice() hook to display prices with proper currency symbols and formatting. Pass in a price in integer minor units (Stripe convention) and a currency code (e.g., 1999 and \"USD\") and it returns a formatted string like \"$19.99\".\n * @module\n */\nimport { formatAmount } from \"schemas/money\";\n\nimport { useClientValue } from \"./use-client-value\";\n\n/**\n * Use `useFormattedPrice` to format prices with proper currency and locale.\n * @returns A formatted price string based on the price and currency code. It\n * already takes into account the user's locale/browser.\n * @example\n * ```tsx\n * import { useFormattedPrice } from \"canopy-sdk/hooks/use-formatted-price\";\n *\n * const originalPrice = 1999; // integer minor units\n * const originalPriceFormatted = useFormattedPrice(originalPrice, \"USD\");\n * // Display the formatted price\n * <p>{originalPriceFormatted}</p>;\n * ```\n */\nexport const useFormattedPrice = (\n price: number | null,\n currency: string | null,\n) => {\n const navigatorLanguage = useClientValue(\n () => window.navigator.language,\n \"en-US\",\n );\n\n // NOTE (Max, 2026-08-03): guard on null, not falsiness \u2014 0 is a real amount\n // (a free item), so `if (!price)` would render no price at all for it.\n if (price === null) {\n return null;\n }\n\n return formatAmount({\n amount: price,\n currencyCode: currency ?? \"USD\",\n locale: navigatorLanguage,\n });\n};\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,oBAAoB;AAE7B,SAAS,sBAAsB;AAgBxB,MAAM,oBAAoB,CAC/B,OACA,aACG;AACH,QAAM,oBAAoB;AAAA,IACxB,MAAM,OAAO,UAAU;AAAA,IACvB;AAAA,EACF;AAIA,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,SAAO,aAAa;AAAA,IAClB,QAAQ;AAAA,IACR,cAAc,YAAY;AAAA,IAC1B,QAAQ;AAAA,EACV,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/money.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money helpers for storefronts. All commerce amounts in canopy (variant
|
|
3
|
+
* prices, cart costs) are integer minor units, Stripe convention: 1999 =
|
|
4
|
+
* $19.99 USD, 1999 = ¥1999 JPY. Use formatAmount/useFormattedPrice for
|
|
5
|
+
* display and fromMinorUnitsToMajorUnits when handing amounts to analytics or third-party
|
|
6
|
+
* APIs that speak decimal money.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export { formatAmount, fromMinorUnitsToMajorUnits, fromMinorUnitsToMajorUnitsString, fromMajorUnitsToMinorUnits, } from "./_vendor/schemas/money";
|
package/money.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatAmount,
|
|
3
|
+
fromMinorUnitsToMajorUnits,
|
|
4
|
+
fromMinorUnitsToMajorUnitsString,
|
|
5
|
+
fromMajorUnitsToMinorUnits
|
|
6
|
+
} from "./_vendor/schemas/money.mjs";
|
|
7
|
+
export {
|
|
8
|
+
formatAmount,
|
|
9
|
+
fromMajorUnitsToMinorUnits,
|
|
10
|
+
fromMinorUnitsToMajorUnits,
|
|
11
|
+
fromMinorUnitsToMajorUnitsString
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=money.js.map
|
package/money.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../money.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Money helpers for storefronts. All commerce amounts in canopy (variant\n * prices, cart costs) are integer minor units, Stripe convention: 1999 =\n * $19.99 USD, 1999 = \u00A51999 JPY. Use formatAmount/useFormattedPrice for\n * display and fromMinorUnitsToMajorUnits when handing amounts to analytics or third-party\n * APIs that speak decimal money.\n * @module\n */\n// eslint-disable-next-line barrel-files/avoid-barrel-files, replo/no-export-from -- public SDK entrypoint: scaffolded sites cannot import workspace `schemas`, so this module is their only path to the money helpers.\nexport {\n formatAmount,\n fromMinorUnitsToMajorUnits,\n fromMinorUnitsToMajorUnitsString,\n fromMajorUnitsToMinorUnits,\n} from \"schemas/money\";\n"],
|
|
5
|
+
"mappings": "AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replohq/canopy-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Replo Canopy SDK — cart, analytics, data loaders, and editor runtime for agent-built Next.js sites.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"@tiptap/extension-text": "^2.25.0",
|
|
14
14
|
"@tiptap/extension-underline": "^2.25.0",
|
|
15
15
|
"@tiptap/pm": "^2.25.0",
|
|
16
|
+
"currency-codes": "^2.2.0",
|
|
16
17
|
"tiny-jsonc": "^1.0.2",
|
|
17
18
|
"uuid": "^11.1.0",
|
|
18
19
|
"zod": "^4.3.6"
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { isObjectLike_default, baseGetTag_default, isArray_default } from './chunk-FNTGY7I5.mjs';
|
|
2
2
|
|
|
3
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNumber.js
|
|
4
|
-
var numberTag = "[object Number]";
|
|
5
|
-
function isNumber(value) {
|
|
6
|
-
return typeof value == "number" || isObjectLike_default(value) && baseGetTag_default(value) == numberTag;
|
|
7
|
-
}
|
|
8
|
-
var isNumber_default = isNumber;
|
|
9
|
-
|
|
10
3
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
11
4
|
function isObject(value) {
|
|
12
5
|
var type = typeof value;
|
|
@@ -14,6 +7,13 @@ function isObject(value) {
|
|
|
14
7
|
}
|
|
15
8
|
var isObject_default = isObject;
|
|
16
9
|
|
|
10
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNumber.js
|
|
11
|
+
var numberTag = "[object Number]";
|
|
12
|
+
function isNumber(value) {
|
|
13
|
+
return typeof value == "number" || isObjectLike_default(value) && baseGetTag_default(value) == numberTag;
|
|
14
|
+
}
|
|
15
|
+
var isNumber_default = isNumber;
|
|
16
|
+
|
|
17
17
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isString.js
|
|
18
18
|
var stringTag = "[object String]";
|
|
19
19
|
function isString(value) {
|