@replohq/canopy-sdk 0.1.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 (241) hide show
  1. package/_vendor/replo-utils/lib/errors.d.ts +83 -0
  2. package/_vendor/replo-utils/lib/json.d.ts +6 -0
  3. package/_vendor/replo-utils/lib/misc.d.ts +128 -0
  4. package/_vendor/replo-utils/lib/misc.mjs +1 -0
  5. package/_vendor/replo-utils/lib/object.d.ts +31 -0
  6. package/_vendor/replo-utils/lib/parse.d.ts +15 -0
  7. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +49 -0
  8. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +36 -0
  9. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +334 -0
  10. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +50 -0
  11. package/_vendor/schemas/cart.d.ts +198 -0
  12. package/_vendor/schemas/cart.mjs +83 -0
  13. package/_vendor/schemas/errors.d.ts +428 -0
  14. package/_vendor/schemas/errors.mjs +955 -0
  15. package/_vendor/schemas/generated/errors.d.ts +61 -0
  16. package/_vendor/schemas/generated/selectMode.d.ts +95 -0
  17. package/_vendor/schemas/generated/selectMode.mjs +1 -0
  18. package/_vendor/schemas/loaderKeys.d.ts +39 -0
  19. package/_vendor/schemas/loaderKeys.mjs +23 -0
  20. package/_vendor/schemas/objectType.d.ts +895 -0
  21. package/_vendor/schemas/objectType.mjs +2 -0
  22. package/_vendor/schemas/registry.d.ts +243 -0
  23. package/_vendor/schemas/sandboxFiles.d.ts +35 -0
  24. package/_vendor/schemas/selectMode.d.ts +507 -0
  25. package/_vendor/schemas/selectMode.mjs +194 -0
  26. package/_vendor/schemas/sellingPlan.d.ts +60 -0
  27. package/_vendor/schemas/sellingPlan.mjs +1 -0
  28. package/analytics/analytics-provider.d.ts +13 -0
  29. package/analytics/analytics-provider.js +104 -0
  30. package/analytics/analytics-provider.js.map +7 -0
  31. package/analytics/analytics-sink.d.ts +20 -0
  32. package/analytics/analytics-sink.js +1 -0
  33. package/analytics/analytics-sink.js.map +7 -0
  34. package/analytics/hooks/use-product-viewed-analytics.d.ts +23 -0
  35. package/analytics/hooks/use-product-viewed-analytics.js +34 -0
  36. package/analytics/hooks/use-product-viewed-analytics.js.map +7 -0
  37. package/analytics/sinks/ga4-sink.d.ts +15 -0
  38. package/analytics/sinks/ga4-sink.js +52 -0
  39. package/analytics/sinks/ga4-sink.js.map +7 -0
  40. package/analytics/sinks/meta-sink.d.ts +14 -0
  41. package/analytics/sinks/meta-sink.js +44 -0
  42. package/analytics/sinks/meta-sink.js.map +7 -0
  43. package/analytics/sinks/pinterest-sink.d.ts +14 -0
  44. package/analytics/sinks/pinterest-sink.js +76 -0
  45. package/analytics/sinks/pinterest-sink.js.map +7 -0
  46. package/analytics/sinks/reddit-sink.d.ts +14 -0
  47. package/analytics/sinks/reddit-sink.js +80 -0
  48. package/analytics/sinks/reddit-sink.js.map +7 -0
  49. package/analytics/sinks/replo-sink.d.ts +14 -0
  50. package/analytics/sinks/replo-sink.js +57 -0
  51. package/analytics/sinks/replo-sink.js.map +7 -0
  52. package/analytics/sinks/snapchat-sink.d.ts +14 -0
  53. package/analytics/sinks/snapchat-sink.js +67 -0
  54. package/analytics/sinks/snapchat-sink.js.map +7 -0
  55. package/analytics/sinks/tiktok-sink.d.ts +14 -0
  56. package/analytics/sinks/tiktok-sink.js +79 -0
  57. package/analytics/sinks/tiktok-sink.js.map +7 -0
  58. package/analytics/sinks/window-sink.d.ts +18 -0
  59. package/analytics/sinks/window-sink.js +46 -0
  60. package/analytics/sinks/window-sink.js.map +7 -0
  61. package/analytics/utils/analytics-utils.d.ts +7 -0
  62. package/analytics/utils/analytics-utils.js +130 -0
  63. package/analytics/utils/analytics-utils.js.map +7 -0
  64. package/analytics/utils/navigation-tracker.d.ts +16 -0
  65. package/analytics/utils/navigation-tracker.js +44 -0
  66. package/analytics/utils/navigation-tracker.js.map +7 -0
  67. package/cart/buy-now-action.d.ts +21 -0
  68. package/cart/buy-now-action.js +104 -0
  69. package/cart/buy-now-action.js.map +7 -0
  70. package/cart/cart-actions.d.ts +63 -0
  71. package/cart/cart-actions.js +90 -0
  72. package/cart/cart-actions.js.map +7 -0
  73. package/cart/cart-loader.d.ts +9 -0
  74. package/cart/cart-loader.js +11 -0
  75. package/cart/cart-loader.js.map +7 -0
  76. package/cart/cart-provider.d.ts +85 -0
  77. package/cart/cart-provider.js +358 -0
  78. package/cart/cart-provider.js.map +7 -0
  79. package/cart/cart-types.d.ts +154 -0
  80. package/cart/cart-types.js +16 -0
  81. package/cart/cart-types.js.map +7 -0
  82. package/cart/gateways/cart-gateway.d.ts +10 -0
  83. package/cart/gateways/cart-gateway.js +19 -0
  84. package/cart/gateways/cart-gateway.js.map +7 -0
  85. package/cart/gateways/cookie-cart-gateway.d.ts +28 -0
  86. package/cart/gateways/cookie-cart-gateway.js +109 -0
  87. package/cart/gateways/cookie-cart-gateway.js.map +7 -0
  88. package/cart/gateways/default-cart-gateway.d.ts +19 -0
  89. package/cart/gateways/default-cart-gateway.js +30 -0
  90. package/cart/gateways/default-cart-gateway.js.map +7 -0
  91. package/cart/gateways/resolver-cart-gateway.d.ts +2 -0
  92. package/cart/gateways/resolver-cart-gateway.js +106 -0
  93. package/cart/gateways/resolver-cart-gateway.js.map +7 -0
  94. package/cart/gateways/stripe-cart-gateway.d.ts +19 -0
  95. package/cart/gateways/stripe-cart-gateway.js +28 -0
  96. package/cart/gateways/stripe-cart-gateway.js.map +7 -0
  97. package/cart/gateways/stripe-constants.d.ts +1 -0
  98. package/cart/gateways/stripe-constants.js +5 -0
  99. package/cart/gateways/stripe-constants.js.map +7 -0
  100. package/cart/hooks/use-add-to-cart.d.ts +63 -0
  101. package/cart/hooks/use-add-to-cart.js +120 -0
  102. package/cart/hooks/use-add-to-cart.js.map +7 -0
  103. package/cart/hooks/use-buy-now.d.ts +49 -0
  104. package/cart/hooks/use-buy-now.js +62 -0
  105. package/cart/hooks/use-buy-now.js.map +7 -0
  106. package/cart/utils/cart-utils.d.ts +31 -0
  107. package/cart/utils/cart-utils.js +48 -0
  108. package/cart/utils/cart-utils.js.map +7 -0
  109. package/cart/utils/cookie-cart-persistence.d.ts +55 -0
  110. package/cart/utils/cookie-cart-persistence.js +153 -0
  111. package/cart/utils/cookie-cart-persistence.js.map +7 -0
  112. package/cart/utils/variant-to-cart-line.d.ts +124 -0
  113. package/cart/utils/variant-to-cart-line.js +202 -0
  114. package/cart/utils/variant-to-cart-line.js.map +7 -0
  115. package/chunk-46YU2W6T.mjs +538 -0
  116. package/chunk-4TZVNC3W.mjs +33 -0
  117. package/chunk-INHK6MYI.mjs +1598 -0
  118. package/editor/ClientErrorBoundary.d.ts +7 -0
  119. package/editor/ClientErrorBoundary.js +48 -0
  120. package/editor/ClientErrorBoundary.js.map +7 -0
  121. package/editor/LinkInterceptor.d.ts +1 -0
  122. package/editor/LinkInterceptor.js +124 -0
  123. package/editor/LinkInterceptor.js.map +7 -0
  124. package/editor/posthog-relay.d.ts +10 -0
  125. package/editor/posthog-relay.js +60 -0
  126. package/editor/posthog-relay.js.map +7 -0
  127. package/editor/select-mode/EditorSelection.d.ts +24 -0
  128. package/editor/select-mode/EditorSelection.js +34 -0
  129. package/editor/select-mode/EditorSelection.js.map +7 -0
  130. package/editor/select-mode/descriptor/elementDescriptor.d.ts +15 -0
  131. package/editor/select-mode/descriptor/elementDescriptor.js +213 -0
  132. package/editor/select-mode/descriptor/elementDescriptor.js.map +7 -0
  133. package/editor/select-mode/fiber.d.ts +52 -0
  134. package/editor/select-mode/fiber.js +269 -0
  135. package/editor/select-mode/fiber.js.map +7 -0
  136. package/editor/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
  137. package/editor/select-mode/hooks/useCrosshairCursor.js +20 -0
  138. package/editor/select-mode/hooks/useCrosshairCursor.js.map +7 -0
  139. package/editor/select-mode/hooks/useParentMessaging.d.ts +24 -0
  140. package/editor/select-mode/hooks/useParentMessaging.js +33 -0
  141. package/editor/select-mode/hooks/useParentMessaging.js.map +7 -0
  142. package/editor/select-mode/hooks/useSelectModeController.d.ts +8 -0
  143. package/editor/select-mode/hooks/useSelectModeController.js +49 -0
  144. package/editor/select-mode/hooks/useSelectModeController.js.map +7 -0
  145. package/editor/select-mode/hooks/useSelectionHover.d.ts +22 -0
  146. package/editor/select-mode/hooks/useSelectionHover.js +98 -0
  147. package/editor/select-mode/hooks/useSelectionHover.js.map +7 -0
  148. package/editor/select-mode/hooks/useSelectionInteractions.d.ts +32 -0
  149. package/editor/select-mode/hooks/useSelectionInteractions.js +293 -0
  150. package/editor/select-mode/hooks/useSelectionInteractions.js.map +7 -0
  151. package/editor/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
  152. package/editor/select-mode/hooks/useSelectionScrollSync.js +77 -0
  153. package/editor/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
  154. package/editor/select-mode/interactions/selectionGeometry.d.ts +80 -0
  155. package/editor/select-mode/interactions/selectionGeometry.js +160 -0
  156. package/editor/select-mode/interactions/selectionGeometry.js.map +7 -0
  157. package/editor/select-mode/selectModeSession.d.ts +21 -0
  158. package/editor/select-mode/selectModeSession.js +7 -0
  159. package/editor/select-mode/selectModeSession.js.map +7 -0
  160. package/editor/select-mode/selectionFrame.d.ts +48 -0
  161. package/editor/select-mode/selectionFrame.js +74 -0
  162. package/editor/select-mode/selectionFrame.js.map +7 -0
  163. package/editor/select-mode/symbolicate.d.ts +3 -0
  164. package/editor/select-mode/symbolicate.js +139 -0
  165. package/editor/select-mode/symbolicate.js.map +7 -0
  166. package/env.d.ts +13 -0
  167. package/env.js +20 -0
  168. package/env.js.map +7 -0
  169. package/gateways/canopy-api.d.ts +84 -0
  170. package/gateways/canopy-api.js +203 -0
  171. package/gateways/canopy-api.js.map +7 -0
  172. package/hooks/use-client-value.d.ts +10 -0
  173. package/hooks/use-client-value.js +12 -0
  174. package/hooks/use-client-value.js.map +7 -0
  175. package/hooks/use-formatted-price.d.ts +15 -0
  176. package/hooks/use-formatted-price.js +19 -0
  177. package/hooks/use-formatted-price.js.map +7 -0
  178. package/lib/get-query-client.d.ts +2 -0
  179. package/lib/get-query-client.js +34 -0
  180. package/lib/get-query-client.js.map +7 -0
  181. package/lib/integration-utils.d.ts +2 -0
  182. package/lib/integration-utils.js +9 -0
  183. package/lib/integration-utils.js.map +7 -0
  184. package/lib/shopify-utils.d.ts +16 -0
  185. package/lib/shopify-utils.js +11 -0
  186. package/lib/shopify-utils.js.map +7 -0
  187. package/lib/url-utils.d.ts +4 -0
  188. package/lib/url-utils.js +8 -0
  189. package/lib/url-utils.js.map +7 -0
  190. package/loaders/collection-loader.d.ts +11 -0
  191. package/loaders/collection-loader.js +53 -0
  192. package/loaders/collection-loader.js.map +7 -0
  193. package/loaders/collection-products-loader.d.ts +12 -0
  194. package/loaders/collection-products-loader.js +56 -0
  195. package/loaders/collection-products-loader.js.map +7 -0
  196. package/loaders/invoke-loader-action.d.ts +11 -0
  197. package/loaders/invoke-loader-action.js +14 -0
  198. package/loaders/invoke-loader-action.js.map +7 -0
  199. package/loaders/invoke-loader-server.d.ts +18 -0
  200. package/loaders/invoke-loader-server.js +35 -0
  201. package/loaders/invoke-loader-server.js.map +7 -0
  202. package/loaders/invoke-loader.d.ts +14 -0
  203. package/loaders/invoke-loader.js +36 -0
  204. package/loaders/invoke-loader.js.map +7 -0
  205. package/loaders/levanta-product-loader.d.ts +11 -0
  206. package/loaders/levanta-product-loader.js +53 -0
  207. package/loaders/levanta-product-loader.js.map +7 -0
  208. package/loaders/loader-error-boundary.d.ts +25 -0
  209. package/loaders/loader-error-boundary.js +24 -0
  210. package/loaders/loader-error-boundary.js.map +7 -0
  211. package/loaders/okendo-review-aggregate-loader.d.ts +17 -0
  212. package/loaders/okendo-review-aggregate-loader.js +56 -0
  213. package/loaders/okendo-review-aggregate-loader.js.map +7 -0
  214. package/loaders/okendo-reviews-loader.d.ts +23 -0
  215. package/loaders/okendo-reviews-loader.js +54 -0
  216. package/loaders/okendo-reviews-loader.js.map +7 -0
  217. package/loaders/prefetch-loaders.d.ts +33 -0
  218. package/loaders/prefetch-loaders.js +46 -0
  219. package/loaders/prefetch-loaders.js.map +7 -0
  220. package/loaders/product-loader.d.ts +11 -0
  221. package/loaders/product-loader.js +53 -0
  222. package/loaders/product-loader.js.map +7 -0
  223. package/loaders/rebuy-recommendations-loader.d.ts +159 -0
  224. package/loaders/rebuy-recommendations-loader.js +57 -0
  225. package/loaders/rebuy-recommendations-loader.js.map +7 -0
  226. package/loaders/smile-earning-rules-loader.d.ts +19 -0
  227. package/loaders/smile-earning-rules-loader.js +44 -0
  228. package/loaders/smile-earning-rules-loader.js.map +7 -0
  229. package/loaders/smile-rewards-loader.d.ts +19 -0
  230. package/loaders/smile-rewards-loader.js +44 -0
  231. package/loaders/smile-rewards-loader.js.map +7 -0
  232. package/loaders/smile-vip-tiers-loader.d.ts +18 -0
  233. package/loaders/smile-vip-tiers-loader.js +43 -0
  234. package/loaders/smile-vip-tiers-loader.js.map +7 -0
  235. package/package.json +29 -0
  236. package/providers/query-provider.d.ts +1 -0
  237. package/providers/query-provider.js +12 -0
  238. package/providers/query-provider.js.map +7 -0
  239. package/providers/replo-provider.d.ts +1 -0
  240. package/providers/replo-provider.js +20 -0
  241. package/providers/replo-provider.js.map +7 -0
@@ -0,0 +1,202 @@
1
+ import { convertLegacyResourceIdToGraphQLId } from "../../lib/shopify-utils";
2
+ import { formatSellingPlanId } from "./cart-utils";
3
+ function applyPriceAdjustment(variantPrice, adjustment) {
4
+ switch (adjustment.valueType) {
5
+ case "price":
6
+ return adjustment.value;
7
+ case "percentage":
8
+ return Math.max(0, variantPrice * (1 - adjustment.value / 100));
9
+ case "fixedAmount":
10
+ return Math.max(0, variantPrice - adjustment.value);
11
+ }
12
+ }
13
+ function variantToCartLine(variant, options) {
14
+ const quantity = options?.quantity ?? 1;
15
+ const baseProperties = options?.properties ?? [];
16
+ const sellingPlanId = formatSellingPlanId(options?.sellingPlanId ?? null);
17
+ const additionalProperties = [];
18
+ if (options?.bundle) {
19
+ additionalProperties.push(
20
+ ...createBundleAttributes(
21
+ options.bundle.bundleId,
22
+ options.bundle.bundleDiscount
23
+ )
24
+ );
25
+ }
26
+ const allProperties = [...baseProperties, ...additionalProperties];
27
+ const cartLine = {
28
+ id: variant.externalId ? convertLegacyResourceIdToGraphQLId(variant.externalId, "ProductVariant") : variant.id,
29
+ quantity,
30
+ properties: allProperties,
31
+ sellingPlanId
32
+ };
33
+ if (options?.includeMerchandise && options.product) {
34
+ const { product } = options;
35
+ cartLine.merchandise = {
36
+ id: variant.externalId ? convertLegacyResourceIdToGraphQLId(
37
+ variant.externalId,
38
+ "ProductVariant"
39
+ ) : variant.id,
40
+ product: {
41
+ id: product.id,
42
+ title: product.title,
43
+ sellingPlanGroups: product.sellingPlanGroups
44
+ },
45
+ title: variant.title ?? `${product.title} - ${variant.id}`,
46
+ price: variant.price ?? 0,
47
+ compareAtPrice: variant.originalPrice,
48
+ image: product.featuredMedia?.type === "image" ? {
49
+ url: product.featuredMedia.url,
50
+ altText: product.featuredMedia.alt ?? product.title
51
+ } : null,
52
+ selectedOptions: variant.optionValues?.map((opt) => ({
53
+ name: opt.value,
54
+ value: opt.value
55
+ })) ?? []
56
+ };
57
+ }
58
+ return cartLine;
59
+ }
60
+ function createBundleAttributes(bundleId, bundleDiscount) {
61
+ return [
62
+ { key: "bundleId", value: bundleId },
63
+ { key: "bundleDiscount", value: bundleDiscount },
64
+ { key: "isBundleItem", value: true }
65
+ ];
66
+ }
67
+ function getCartLineAttribute(cartLine, key) {
68
+ return cartLine.attributes.find((attr) => attr.key === key)?.value;
69
+ }
70
+ function getCartLinePricing(cartLine) {
71
+ if (!cartLine.merchandise) {
72
+ return {
73
+ compareAtPrice: 0,
74
+ discountPercentage: 0,
75
+ hasDiscount: false,
76
+ sellingPlanAdjustedPrice: 0,
77
+ finalPrice: 0
78
+ };
79
+ }
80
+ const compareAtPrice = cartLine.merchandise.compareAtPrice ?? 0;
81
+ const currentPrice = cartLine.merchandise.price;
82
+ const discountPercentage = compareAtPrice > currentPrice ? (compareAtPrice - currentPrice) / compareAtPrice * 100 : 0;
83
+ const hasDiscount = compareAtPrice > currentPrice;
84
+ let sellingPlanAdjustedPrice = cartLine.merchandise.price;
85
+ if (cartLine.sellingPlanAllocation && cartLine.sellingPlanAllocation.priceAdjustments.length > 0 && cartLine.sellingPlanAllocation.priceAdjustments[0]?.price) {
86
+ sellingPlanAdjustedPrice = cartLine.sellingPlanAllocation.priceAdjustments[0].price.amount;
87
+ }
88
+ return {
89
+ compareAtPrice,
90
+ discountPercentage,
91
+ hasDiscount,
92
+ sellingPlanAdjustedPrice,
93
+ finalPrice: sellingPlanAdjustedPrice
94
+ };
95
+ }
96
+ function getCartLineBundleInfo(cartLine) {
97
+ const bundleId = getCartLineAttribute(cartLine, "bundleId");
98
+ const bundleDiscount = Number(
99
+ getCartLineAttribute(cartLine, "bundleDiscount") ?? 0
100
+ );
101
+ const isBundleItem = getCartLineAttribute(
102
+ cartLine,
103
+ "isBundleItem"
104
+ );
105
+ return {
106
+ bundleId: bundleId ?? null,
107
+ bundleDiscount,
108
+ isBundleItem: isBundleItem ?? false
109
+ };
110
+ }
111
+ function getCartLineSpecialInfo(cartLine) {
112
+ const isSpecialItem = getCartLineAttribute(
113
+ cartLine,
114
+ "isSpecialItem"
115
+ );
116
+ const specialInstructions = getCartLineAttribute(
117
+ cartLine,
118
+ "specialInstructions"
119
+ );
120
+ return {
121
+ isSpecialItem: isSpecialItem ?? false,
122
+ specialInstructions: specialInstructions ? specialInstructions.split("|") : []
123
+ };
124
+ }
125
+ function getCartLineSubscriptionInfo(cartLine) {
126
+ if (cartLine.sellingPlanAllocation) {
127
+ return {
128
+ isSubscription: true,
129
+ frequency: cartLine.sellingPlanAllocation.sellingPlan.name,
130
+ discount: 0,
131
+ // Shopify calculates this from price adjustments when available
132
+ sellingPlan: cartLine.sellingPlanAllocation.sellingPlan
133
+ };
134
+ }
135
+ return {
136
+ isSubscription: false,
137
+ frequency: null,
138
+ discount: 0,
139
+ sellingPlan: null
140
+ };
141
+ }
142
+ function createOptimisticSellingPlanAllocation({
143
+ merchandise,
144
+ sellingPlanId,
145
+ currencyCode = "USD"
146
+ }) {
147
+ const { product, price: variantPrice } = merchandise;
148
+ if (!sellingPlanId || !product.sellingPlanGroups) {
149
+ return null;
150
+ }
151
+ for (const group of product.sellingPlanGroups) {
152
+ const sellingPlan = group.sellingPlans.find(
153
+ (sp) => sp.id === sellingPlanId
154
+ );
155
+ if (sellingPlan) {
156
+ return {
157
+ sellingPlan: {
158
+ id: sellingPlan.id,
159
+ name: sellingPlan.name,
160
+ description: sellingPlan.description
161
+ },
162
+ priceAdjustments: sellingPlan.priceAdjustments.map((adj) => {
163
+ const adjustedPrice = variantPrice !== void 0 ? applyPriceAdjustment(variantPrice, adj) : 0;
164
+ return {
165
+ compareAtPrice: {
166
+ amount: variantPrice ?? 0,
167
+ currencyCode
168
+ },
169
+ perDeliveryPrice: {
170
+ amount: adjustedPrice,
171
+ currencyCode
172
+ },
173
+ price: {
174
+ amount: adjustedPrice,
175
+ currencyCode
176
+ },
177
+ unitPrice: null
178
+ };
179
+ }),
180
+ checkoutChargeAmount: {
181
+ amount: 0,
182
+ currencyCode
183
+ },
184
+ remainingBalanceChargeAmount: {
185
+ amount: 0,
186
+ currencyCode
187
+ }
188
+ };
189
+ }
190
+ }
191
+ return null;
192
+ }
193
+ export {
194
+ createOptimisticSellingPlanAllocation,
195
+ getCartLineAttribute,
196
+ getCartLineBundleInfo,
197
+ getCartLinePricing,
198
+ getCartLineSpecialInfo,
199
+ getCartLineSubscriptionInfo,
200
+ variantToCartLine
201
+ };
202
+ //# sourceMappingURL=variant-to-cart-line.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
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,GAAG,gBAAgB,GAA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