@replohq/canopy-sdk 2.6.0 → 3.0.1
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/fonts.mjs +1 -0
- package/_vendor/replo-utils/lib/geometry.mjs +2 -0
- package/_vendor/replo-utils/lib/json.mjs +1 -0
- package/_vendor/replo-utils/lib/misc.mjs +1 -0
- package/_vendor/replo-utils/lib/posthogReplay.mjs +2 -0
- package/_vendor/replo-utils/lib/url.mjs +1 -0
- package/_vendor/replo-utils/react/use-iframe-rpc-channel.mjs +1 -1
- package/_vendor/schemas/designLibrary.mjs +1 -1
- package/_vendor/schemas/generated/consent.d.ts +2 -0
- package/_vendor/schemas/generated/selectModeIframeRpc.d.ts +8 -0
- package/_vendor/schemas/iframeRpcChannel.mjs +2 -1
- package/_vendor/schemas/loaderKeys.d.ts +1 -1
- package/_vendor/schemas/loaderKeys.mjs +103 -23
- package/_vendor/schemas/money.mjs +1860 -3
- package/_vendor/schemas/pageAnnotations.mjs +1 -1
- package/_vendor/schemas/routing/match.mjs +1 -0
- package/_vendor/schemas/routing/rules.mjs +2 -1
- package/_vendor/schemas/selectMode.d.ts +4 -4
- package/_vendor/schemas/selectMode.mjs +1 -0
- package/_vendor/schemas/selectModeIframeRpc.d.ts +25 -5
- package/_vendor/schemas/selectModeIframeRpc.mjs +12 -3
- package/analytics/analytics-provider.d.ts +5 -10
- package/analytics/analytics-provider.js +14 -101
- package/analytics/analytics-provider.js.map +2 -2
- package/analytics/get-analytics-sinks.d.ts +2 -19
- package/analytics/get-analytics-sinks.js +9 -46
- package/analytics/get-analytics-sinks.js.map +2 -2
- package/analytics/hooks/use-product-viewed-analytics.d.ts +2 -6
- package/analytics/hooks/use-product-viewed-analytics.js +6 -28
- package/analytics/hooks/use-product-viewed-analytics.js.map +2 -2
- package/analytics/replo-first-party-pixel.d.ts +3 -12
- package/analytics/replo-first-party-pixel.js +8 -24
- package/analytics/replo-first-party-pixel.js.map +2 -2
- package/analytics/replo-pixel-script.d.ts +4 -10
- package/analytics/replo-pixel-script.js +9 -23
- package/analytics/replo-pixel-script.js.map +2 -2
- package/analytics/sinks/ga4-sink.d.ts +10 -9
- package/analytics/sinks/ga4-sink.js +99 -50
- package/analytics/sinks/ga4-sink.js.map +2 -2
- package/analytics/sinks/meta-sink.d.ts +5 -4
- package/analytics/sinks/meta-sink.js +82 -29
- package/analytics/sinks/meta-sink.js.map +2 -2
- package/analytics/sinks/pinterest-sink.d.ts +7 -6
- package/analytics/sinks/pinterest-sink.js +82 -49
- package/analytics/sinks/pinterest-sink.js.map +2 -2
- package/analytics/sinks/reddit-sink.d.ts +8 -7
- package/analytics/sinks/reddit-sink.js +82 -53
- package/analytics/sinks/reddit-sink.js.map +2 -2
- package/analytics/sinks/replo-sink.d.ts +9 -8
- package/analytics/sinks/replo-sink.js +89 -37
- package/analytics/sinks/replo-sink.js.map +2 -2
- package/analytics/sinks/snapchat-sink.d.ts +6 -5
- package/analytics/sinks/snapchat-sink.js +82 -40
- package/analytics/sinks/snapchat-sink.js.map +2 -2
- package/analytics/sinks/tiktok-sink.d.ts +8 -7
- package/analytics/sinks/tiktok-sink.js +82 -52
- package/analytics/sinks/tiktok-sink.js.map +2 -2
- package/analytics/sinks/window-sink.d.ts +11 -14
- package/analytics/sinks/window-sink.js +101 -28
- package/analytics/sinks/window-sink.js.map +2 -2
- package/analytics/utils/analytics-utils.d.ts +4 -2
- package/analytics/utils/analytics-utils.js +19 -123
- package/analytics/utils/analytics-utils.js.map +2 -2
- package/analytics/utils/navigation-tracker.d.ts +2 -1
- package/analytics/utils/navigation-tracker.js +37 -30
- package/analytics/utils/navigation-tracker.js.map +2 -2
- package/analytics/utils/shopify-funnel-gate.d.ts +2 -7
- package/analytics/utils/shopify-funnel-gate.js +8 -15
- package/analytics/utils/shopify-funnel-gate.js.map +2 -2
- package/cart/buy-now-action.d.ts +2 -9
- package/cart/buy-now-action.js +5 -97
- package/cart/buy-now-action.js.map +2 -2
- package/cart/cart-actions.d.ts +12 -56
- package/cart/cart-actions.js +88 -68
- package/cart/cart-actions.js.map +2 -2
- package/cart/cart-loader.d.ts +3 -9
- package/cart/cart-loader.js +14 -6
- package/cart/cart-loader.js.map +2 -2
- package/cart/cart-provider.d.ts +6 -58
- package/cart/cart-provider.js +13 -359
- package/cart/cart-provider.js.map +3 -3
- package/cart/cart-schema.d.ts +2 -1
- package/cart/cart-schema.js +12 -64
- package/cart/cart-schema.js.map +2 -2
- package/cart/cart-types.d.ts +1 -1
- package/cart/cart-types.js +5 -4
- package/cart/cart-types.js.map +2 -2
- package/cart/gateways/cart-constants.d.ts +1 -0
- package/cart/gateways/cart-constants.js.map +2 -2
- package/cart/gateways/cart-gateway.d.ts +1 -0
- package/cart/gateways/cart-gateway.js +13 -12
- package/cart/gateways/cart-gateway.js.map +2 -2
- package/cart/gateways/cookie-cart-gateway.d.ts +8 -11
- package/cart/gateways/cookie-cart-gateway.js +93 -97
- package/cart/gateways/cookie-cart-gateway.js.map +2 -2
- package/cart/gateways/default-cart-gateway.d.ts +10 -16
- package/cart/gateways/default-cart-gateway.js +13 -23
- package/cart/gateways/default-cart-gateway.js.map +2 -2
- package/cart/gateways/resolver-cart-gateway.d.ts +1 -0
- package/cart/gateways/resolver-cart-gateway.js +13 -102
- package/cart/gateways/resolver-cart-gateway.js.map +2 -2
- package/cart/gateways/stripe-cart-gateway.d.ts +10 -16
- package/cart/gateways/stripe-cart-gateway.js +13 -21
- package/cart/gateways/stripe-cart-gateway.js.map +2 -2
- package/cart/hooks/use-add-to-cart.d.ts +3 -47
- package/cart/hooks/use-add-to-cart.js +10 -115
- package/cart/hooks/use-add-to-cart.js.map +2 -2
- package/cart/hooks/use-buy-now.d.ts +1 -39
- package/cart/hooks/use-buy-now.js +5 -55
- package/cart/hooks/use-buy-now.js.map +2 -2
- package/cart/utils/cart-utils.d.ts +8 -35
- package/cart/utils/cart-utils.js +21 -35
- package/cart/utils/cart-utils.js.map +2 -2
- package/cart/utils/cookie-cart-persistence.d.ts +16 -41
- package/cart/utils/cookie-cart-persistence.js +38 -143
- package/cart/utils/cookie-cart-persistence.js.map +2 -2
- package/cart/utils/variant-to-cart-line.d.ts +12 -42
- package/cart/utils/variant-to-cart-line.js +31 -147
- package/cart/utils/variant-to-cart-line.js.map +2 -2
- package/chunk-UJCSKKID.mjs +27 -0
- package/{chunk-OFU2QEDR.mjs → chunk-ZZPQ3E7S.mjs} +50 -5
- package/consent/consent-action.d.ts +2 -1
- package/consent/consent-action.js +10 -20
- package/consent/consent-action.js.map +2 -2
- package/consent/consent-actions.d.ts +2 -13
- package/consent/consent-actions.js +9 -29
- package/consent/consent-actions.js.map +2 -2
- package/consent/consent-store.d.ts +9 -36
- package/consent/consent-store.js +12 -182
- package/consent/consent-store.js.map +2 -2
- package/consent/cookie.d.ts +9 -12
- package/consent/cookie.js +32 -64
- package/consent/cookie.js.map +2 -2
- package/consent/replo-scripts.d.ts +5 -18
- package/consent/replo-scripts.js +11 -94
- package/consent/replo-scripts.js.map +2 -2
- package/consent/script-registration-store.d.ts +6 -2
- package/consent/script-registration-store.js +33 -47
- package/consent/script-registration-store.js.map +2 -2
- package/consent/script-snippets.d.ts +4 -18
- package/consent/script-snippets.js +19 -127
- package/consent/script-snippets.js.map +2 -2
- package/consent/window-api.d.ts +4 -15
- package/consent/window-api.js +8 -63
- package/consent/window-api.js.map +2 -2
- package/editor/ClientErrorBoundary.d.ts +4 -10
- package/editor/ClientErrorBoundary.js +7 -55
- package/editor/ClientErrorBoundary.js.map +2 -2
- package/editor/DocumentReadyBeacon.d.ts +3 -1
- package/editor/DocumentReadyBeacon.js +6 -3
- package/editor/DocumentReadyBeacon.js.map +2 -2
- package/editor/LinkInterceptor.d.ts +1 -0
- package/editor/LinkInterceptor.js +6 -121
- package/editor/LinkInterceptor.js.map +2 -2
- package/editor/NextErrorReporter.d.ts +1 -0
- package/editor/NextErrorReporter.js +6 -85
- package/editor/NextErrorReporter.js.map +2 -2
- package/editor/annotations/AnnotationLayerMount.d.ts +1 -0
- package/editor/annotations/AnnotationLayerMount.js +6 -6
- package/editor/annotations/AnnotationLayerMount.js.map +2 -2
- package/editor/annotations/annotationController.d.ts +1 -0
- package/editor/annotations/annotationController.js +6 -378
- package/editor/annotations/annotationController.js.map +2 -2
- package/editor/annotations/bridgeGate.d.ts +4 -7
- package/editor/annotations/bridgeGate.js +13 -15
- package/editor/annotations/bridgeGate.js.map +2 -2
- package/editor/design-library-preview/DesignLibraryPreview.d.ts +1 -0
- package/editor/design-library-preview/DesignLibraryPreview.js +6 -86
- package/editor/design-library-preview/DesignLibraryPreview.js.map +2 -2
- package/editor/posthog-relay.d.ts +1 -10
- package/editor/posthog-relay.js +6 -65
- package/editor/posthog-relay.js.map +2 -2
- package/editor/select-mode/EditorSelection.d.ts +1 -23
- package/editor/select-mode/EditorSelection.js +5 -87
- package/editor/select-mode/EditorSelection.js.map +2 -2
- package/editor/select-mode/annotationFrames.d.ts +9 -9
- package/editor/select-mode/annotationFrames.js +22 -103
- package/editor/select-mode/annotationFrames.js.map +2 -2
- package/editor/select-mode/descriptor/elementDescriptor.d.ts +6 -21
- package/editor/select-mode/descriptor/elementDescriptor.js +19 -192
- package/editor/select-mode/descriptor/elementDescriptor.js.map +3 -3
- package/editor/select-mode/descriptor/styleExtraction.d.ts +4 -2
- package/editor/select-mode/descriptor/styleExtraction.js +11 -262
- package/editor/select-mode/descriptor/styleExtraction.js.map +2 -2
- package/editor/select-mode/displayModeStore.d.ts +2 -0
- package/editor/select-mode/displayModeStore.js +14 -39
- package/editor/select-mode/displayModeStore.js.map +2 -2
- package/editor/select-mode/fast-refresh-relay.d.ts +2 -1
- package/editor/select-mode/fast-refresh-relay.js +7 -28
- package/editor/select-mode/fast-refresh-relay.js.map +2 -2
- package/editor/select-mode/fiber.d.ts +14 -7
- package/editor/select-mode/fiber.js +40 -286
- package/editor/select-mode/fiber.js.map +2 -2
- package/editor/select-mode/hooks/useCrosshairCursor.d.ts +2 -9
- package/editor/select-mode/hooks/useCrosshairCursor.js +7 -15
- package/editor/select-mode/hooks/useCrosshairCursor.js.map +2 -2
- package/editor/select-mode/hooks/useEditModeStateMachine.d.ts +5 -3
- package/editor/select-mode/hooks/useEditModeStateMachine.js +13 -228
- package/editor/select-mode/hooks/useEditModeStateMachine.js.map +2 -2
- package/editor/select-mode/hooks/useOptimisticOverrides.d.ts +2 -1
- package/editor/select-mode/hooks/useOptimisticOverrides.js +6 -277
- package/editor/select-mode/hooks/useOptimisticOverrides.js.map +2 -2
- package/editor/select-mode/hooks/useParentMessaging.d.ts +2 -20
- package/editor/select-mode/hooks/useParentMessaging.js +7 -69
- package/editor/select-mode/hooks/useParentMessaging.js.map +2 -2
- package/editor/select-mode/hooks/useSelectModeController.d.ts +2 -1
- package/editor/select-mode/hooks/useSelectModeController.js +6 -40
- package/editor/select-mode/hooks/useSelectModeController.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionHover.d.ts +2 -16
- package/editor/select-mode/hooks/useSelectionHover.js +7 -105
- package/editor/select-mode/hooks/useSelectionHover.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionInteractions.d.ts +2 -26
- package/editor/select-mode/hooks/useSelectionInteractions.js +7 -348
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionScrollSync.d.ts +2 -22
- package/editor/select-mode/hooks/useSelectionScrollSync.js +7 -65
- package/editor/select-mode/hooks/useSelectionScrollSync.js.map +2 -2
- package/editor/select-mode/hooks/useSiblingResolution.d.ts +4 -2
- package/editor/select-mode/hooks/useSiblingResolution.js +13 -52
- package/editor/select-mode/hooks/useSiblingResolution.js.map +2 -2
- package/editor/select-mode/iframeRpcChannel.d.ts +10 -349
- package/editor/select-mode/iframeRpcChannel.js +23 -79
- package/editor/select-mode/iframeRpcChannel.js.map +2 -2
- package/editor/select-mode/inlineTextMarks.d.ts +4 -6
- package/editor/select-mode/inlineTextMarks.js +13 -18
- package/editor/select-mode/inlineTextMarks.js.map +2 -2
- package/editor/select-mode/interactions/selectionGeometry.d.ts +19 -61
- package/editor/select-mode/interactions/selectionGeometry.js +57 -165
- package/editor/select-mode/interactions/selectionGeometry.js.map +2 -2
- package/editor/select-mode/selectModeSession.d.ts +1 -0
- package/editor/select-mode/selectModeSession.js +6 -3
- package/editor/select-mode/selectModeSession.js.map +2 -2
- package/editor/select-mode/selectionFrame.d.ts +9 -60
- package/editor/select-mode/selectionFrame.js +28 -116
- package/editor/select-mode/selectionFrame.js.map +2 -2
- package/editor/select-mode/symbolicate.d.ts +2 -1
- package/editor/select-mode/symbolicate.js +7 -195
- package/editor/select-mode/symbolicate.js.map +2 -2
- package/editor/select-mode/tiptapInlineEditor.d.ts +15 -2
- package/editor/select-mode/tiptapInlineEditor.js +6 -114
- package/editor/select-mode/tiptapInlineEditor.js.map +2 -2
- package/env.d.ts +2 -1
- package/env.js +10 -37
- package/env.js.map +2 -2
- package/gateways/canopy-api.d.ts +15 -12
- package/gateways/canopy-api.js +122 -160
- package/gateways/canopy-api.js.map +2 -2
- package/hooks/use-client-value.d.ts +2 -10
- package/hooks/use-client-value.js +10 -7
- package/hooks/use-client-value.js.map +2 -2
- package/hooks/use-formatted-price.d.ts +1 -14
- package/hooks/use-formatted-price.js +6 -14
- package/hooks/use-formatted-price.js.map +2 -2
- package/lib/canopy-error.d.ts +2 -5
- package/lib/canopy-error.js +10 -14
- package/lib/canopy-error.js.map +2 -2
- package/lib/get-query-client.d.ts +2 -1
- package/lib/get-query-client.js +8 -27
- package/lib/get-query-client.js.map +2 -2
- package/lib/integration-utils.d.ts +1 -0
- package/lib/integration-utils.js +9 -3
- package/lib/integration-utils.js.map +2 -2
- package/lib/shopify-utils.d.ts +2 -10
- package/lib/shopify-utils.js +10 -2
- package/lib/shopify-utils.js.map +2 -2
- package/lib/tombstone.d.ts +21 -0
- package/lib/tombstone.js +99 -0
- package/lib/tombstone.js.map +7 -0
- package/lib/url-utils.d.ts +2 -4
- package/lib/url-utils.js +10 -3
- package/lib/url-utils.js.map +2 -2
- package/loaders/collection-loader.d.ts +3 -2
- package/loaders/collection-loader.js +5 -48
- package/loaders/collection-loader.js.map +2 -2
- package/loaders/collection-products-loader.d.ts +3 -2
- package/loaders/collection-products-loader.js +5 -51
- package/loaders/collection-products-loader.js.map +2 -2
- package/loaders/contentful-entries-loader.d.ts +3 -2
- package/loaders/contentful-entries-loader.js +5 -71
- package/loaders/contentful-entries-loader.js.map +2 -2
- package/loaders/contentful-entry-loader.d.ts +3 -2
- package/loaders/contentful-entry-loader.js +5 -53
- package/loaders/contentful-entry-loader.js.map +2 -2
- package/loaders/invoke-loader-action.d.ts +2 -8
- package/loaders/invoke-loader-action.js +13 -8
- package/loaders/invoke-loader-action.js.map +2 -2
- package/loaders/invoke-loader-server.d.ts +2 -14
- package/loaders/invoke-loader-server.js +12 -34
- package/loaders/invoke-loader-server.js.map +2 -2
- package/loaders/invoke-loader.d.ts +6 -12
- package/loaders/invoke-loader.js +27 -29
- package/loaders/invoke-loader.js.map +2 -2
- package/loaders/levanta-product-loader.d.ts +3 -2
- package/loaders/levanta-product-loader.js +5 -46
- package/loaders/levanta-product-loader.js.map +2 -2
- package/loaders/loader-error-boundary.d.ts +9 -15
- package/loaders/loader-error-boundary.js +50 -13
- package/loaders/loader-error-boundary.js.map +2 -2
- package/loaders/loader-keys.d.ts +4 -12
- package/loaders/loader-keys.js +6 -1
- package/loaders/loader-keys.js.map +2 -2
- package/loaders/loader-schemas.d.ts +142 -61
- package/loaders/loader-schemas.js +253 -90
- package/loaders/loader-schemas.js.map +2 -2
- package/loaders/metaobject-loader.d.ts +3 -2
- package/loaders/metaobject-loader.js +5 -47
- package/loaders/metaobject-loader.js.map +2 -2
- package/loaders/metaobjects-loader.d.ts +3 -2
- package/loaders/metaobjects-loader.js +5 -53
- package/loaders/metaobjects-loader.js.map +2 -2
- package/loaders/okendo-review-aggregate-loader.d.ts +9 -10
- package/loaders/okendo-review-aggregate-loader.js +5 -49
- package/loaders/okendo-review-aggregate-loader.js.map +2 -2
- package/loaders/okendo-reviews-loader.d.ts +8 -16
- package/loaders/okendo-reviews-loader.js +5 -47
- package/loaders/okendo-reviews-loader.js.map +2 -2
- package/loaders/prefetch-loaders.d.ts +4 -26
- package/loaders/prefetch-loaders.js +5 -40
- package/loaders/prefetch-loaders.js.map +2 -2
- package/loaders/preview-placeholder.d.ts +8 -22
- package/loaders/preview-placeholder.js +47 -209
- package/loaders/preview-placeholder.js.map +2 -2
- package/loaders/product-loader-args.d.ts +2 -11
- package/loaders/product-loader-args.js +6 -12
- package/loaders/product-loader-args.js.map +2 -2
- package/loaders/product-loader.d.ts +3 -2
- package/loaders/product-loader.js +5 -45
- package/loaders/product-loader.js.map +2 -2
- package/loaders/rebuy-recommendations-loader.d.ts +8 -157
- package/loaders/rebuy-recommendations-loader.js +5 -50
- package/loaders/rebuy-recommendations-loader.js.map +2 -2
- package/loaders/reviews-io-review-aggregate-loader.d.ts +5 -4
- package/loaders/reviews-io-review-aggregate-loader.js +5 -36
- package/loaders/reviews-io-review-aggregate-loader.js.map +2 -2
- package/loaders/reviews-io-reviews-loader.d.ts +5 -4
- package/loaders/reviews-io-reviews-loader.js +5 -58
- package/loaders/reviews-io-reviews-loader.js.map +2 -2
- package/loaders/smile-earning-rules-loader.d.ts +10 -11
- package/loaders/smile-earning-rules-loader.js +5 -37
- package/loaders/smile-earning-rules-loader.js.map +2 -2
- package/loaders/smile-rewards-loader.d.ts +10 -11
- package/loaders/smile-rewards-loader.js +5 -37
- package/loaders/smile-rewards-loader.js.map +2 -2
- package/loaders/smile-vip-tiers-loader.d.ts +9 -10
- package/loaders/smile-vip-tiers-loader.js +5 -36
- package/loaders/smile-vip-tiers-loader.js.map +2 -2
- package/loaders/statsig-experiment-loader.d.ts +3 -8
- package/loaders/statsig-experiment-loader.js +5 -74
- package/loaders/statsig-experiment-loader.js.map +2 -2
- package/loaders/vendor-loader-keys.d.ts +4 -0
- package/loaders/vendor-loader-keys.js +9 -0
- package/loaders/vendor-loader-keys.js.map +7 -0
- package/loaders/yotpo-review-aggregate-loader.d.ts +5 -4
- package/loaders/yotpo-review-aggregate-loader.js +5 -43
- package/loaders/yotpo-review-aggregate-loader.js.map +2 -2
- package/loaders/yotpo-reviews-loader.d.ts +5 -4
- package/loaders/yotpo-reviews-loader.js +5 -58
- package/loaders/yotpo-reviews-loader.js.map +2 -2
- package/money.d.ts +9 -9
- package/money.js +25 -6
- package/money.js.map +2 -2
- package/next/config.d.ts +3 -1
- package/next/config.js +11 -85
- package/next/config.js.map +2 -2
- package/next/image-loader.d.ts +2 -1
- package/next/image-loader.js +7 -47
- package/next/image-loader.js.map +2 -2
- package/next/open-next.d.ts +4 -2
- package/next/open-next.js +6 -19
- package/next/open-next.js.map +2 -2
- package/orders/order-status-schema.d.ts +28 -13
- package/orders/order-status-schema.js +45 -13
- package/orders/order-status-schema.js.map +2 -2
- package/orders/order-status.d.ts +2 -8
- package/orders/order-status.js +6 -36
- package/orders/order-status.js.map +2 -2
- package/package.json +1 -12
- package/providers/query-provider.d.ts +3 -1
- package/providers/query-provider.js +10 -6
- package/providers/query-provider.js.map +2 -2
- package/providers/replo-provider.d.ts +3 -1
- package/providers/replo-provider.js +6 -37
- package/providers/replo-provider.js.map +2 -2
- package/routing/evaluate.d.ts +3 -3
- package/routing/evaluate.js +5 -40
- package/routing/evaluate.js.map +2 -2
- package/routing/rules.d.ts +3 -11
- package/routing/rules.js +7 -1
- package/routing/rules.js.map +2 -2
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
import {
|
|
3
|
-
import { CookieBasedCartGateway } from "./cookie-cart-gateway";
|
|
4
|
-
function stripeLineMergeFn(existingLines, newLine) {
|
|
5
|
-
return existingLines.findIndex((line) => line.merchandise?.id === newLine.id);
|
|
6
|
-
}
|
|
7
|
-
function stripeLineIdGenerator() {
|
|
8
|
-
return crypto.randomUUID();
|
|
9
|
-
}
|
|
10
|
-
function stripeCartIdGenerator() {
|
|
11
|
-
return crypto.randomUUID();
|
|
12
|
-
}
|
|
13
|
-
class StripeCartGateway extends CookieBasedCartGateway {
|
|
14
|
-
config = {
|
|
15
|
-
cookieName: REPLO_CART_COOKIE_NAME,
|
|
16
|
-
lineMergeFn: stripeLineMergeFn,
|
|
17
|
-
lineIdGenerator: stripeLineIdGenerator,
|
|
18
|
-
cartIdGenerator: stripeCartIdGenerator,
|
|
19
|
-
gatewayName: "Stripe"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
2
|
+
import { canopyTombstoneError } from "../../lib/tombstone";
|
|
22
3
|
async function createStripeCartGateway() {
|
|
23
|
-
|
|
4
|
+
throw canopyTombstoneError({
|
|
5
|
+
symbol: "createStripeCartGateway",
|
|
6
|
+
subpath: "cart/gateways/stripe-cart-gateway",
|
|
7
|
+
replacement: {
|
|
8
|
+
kind: "internal",
|
|
9
|
+
nearestPublicSubpaths: [
|
|
10
|
+
"cart/cart-provider",
|
|
11
|
+
"cart/hooks/use-add-to-cart",
|
|
12
|
+
"cart/hooks/use-buy-now"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
});
|
|
24
16
|
}
|
|
25
17
|
export {
|
|
26
18
|
createStripeCartGateway
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/gateways/stripe-cart-gateway.ts"],
|
|
4
|
-
"sourcesContent": ["\"use server\";\n\nimport type {
|
|
5
|
-
"mappings": ";AAIA,SAAS,
|
|
4
|
+
"sourcesContent": ["\"use server\";\n\nimport type { CartGateway } from \"./cart-gateway\";\n\nimport { canopyTombstoneError } from \"../../lib/tombstone\";\n\ndeclare class StripeCartGateway implements CartGateway {\n protected readonly config: unknown;\n getCart: CartGateway[\"getCart\"];\n createCart: CartGateway[\"createCart\"];\n addToCart: CartGateway[\"addToCart\"];\n updateCartLineItem: CartGateway[\"updateCartLineItem\"];\n removeCartLineItems: CartGateway[\"removeCartLineItems\"];\n updateCartDiscountCodes: CartGateway[\"updateCartDiscountCodes\"];\n}\n\n/** @deprecated Use a supported public @replohq/sdk API for this domain; createStripeCartGateway has no direct replacement. */\nexport async function createStripeCartGateway(): Promise<StripeCartGateway> {\n throw canopyTombstoneError({\n symbol: \"createStripeCartGateway\",\n subpath: \"cart/gateways/stripe-cart-gateway\",\n replacement: {\n kind: \"internal\",\n nearestPublicSubpaths: [\n \"cart/cart-provider\",\n \"cart/hooks/use-add-to-cart\",\n \"cart/hooks/use-buy-now\",\n ],\n },\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,4BAA4B;AAarC,eAAsB,0BAAsD;AAC1E,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,aAAa;AAAA,MACX,MAAM;AAAA,MACN,uBAAuB;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,62 +1,18 @@
|
|
|
1
1
|
import type { QueryClient } from "@tanstack/react-query";
|
|
2
2
|
import type { CartLineAttribute, CartLineMerchandise } from "../cart-types";
|
|
3
|
-
/**
|
|
4
|
-
* Describes a single item to add to the cart. Uses the merchandiseId
|
|
5
|
-
* (e.g. a variant GID) directly from data loader output. Product
|
|
6
|
-
* display data for optimistic UI is resolved automatically from the
|
|
7
|
-
* React Query cache for both single-product loaders (e.g. ProductLoader)
|
|
8
|
-
* and product-list loaders (e.g. CollectionProductsLoader,
|
|
9
|
-
* RebuyRecommendationsLoader). Pass `merchandise` explicitly to bypass
|
|
10
|
-
* the cache lookup when the variant is known but its product was not
|
|
11
|
-
* loaded via a supported loader.
|
|
12
|
-
*/
|
|
13
3
|
export interface AddToCartItem {
|
|
14
|
-
/** The cart-addressable merchandise ID (e.g. `product.variants[N].id` from loader output). */
|
|
15
4
|
merchandiseId: string;
|
|
16
5
|
quantity?: number;
|
|
17
6
|
sellingPlanId?: string | null;
|
|
18
|
-
/** Custom line item properties (appear on the order). */
|
|
19
7
|
properties?: CartLineAttribute[];
|
|
20
8
|
merchandise?: CartLineMerchandise;
|
|
21
9
|
}
|
|
22
|
-
|
|
10
|
+
/** @deprecated Use findMerchandiseInQueryCache from @replohq/sdk/cart/hooks/use-add-to-cart. */
|
|
11
|
+
export declare function findMerchandiseInQueryCache(_options: {
|
|
23
12
|
queryClient: QueryClient;
|
|
24
13
|
merchandiseId: string;
|
|
25
14
|
}): CartLineMerchandise | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Hook for adding items to cart using merchandise IDs from data loader output.
|
|
28
|
-
*
|
|
29
|
-
* This is the primary hook for adding items to cart in the data-loader
|
|
30
|
-
* architecture. It works with the resolver-backed CartGateway so the scaffold
|
|
31
|
-
* never needs direct integration credentials.
|
|
32
|
-
*
|
|
33
|
-
* Merchandise display data (title, price, image) for optimistic cart UI is
|
|
34
|
-
* auto-resolved from the React Query cache for both single-product loaders
|
|
35
|
-
* (e.g. `ProductLoader`) and product-list loaders (e.g.
|
|
36
|
-
* `CollectionProductsLoader`, `RebuyRecommendationsLoader`). Just pass the
|
|
37
|
-
* merchandiseId. Pass `merchandise` explicitly only when the variant is
|
|
38
|
-
* known but its product was not loaded via a supported loader.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```tsx
|
|
42
|
-
* import { useAddToCart } from "canopy-sdk/cart/hooks/use-add-to-cart";
|
|
43
|
-
*
|
|
44
|
-
* function AddToCartButton({ variant }) {
|
|
45
|
-
* const { addToCart, isAdding } = useAddToCart();
|
|
46
|
-
*
|
|
47
|
-
* return (
|
|
48
|
-
* <button
|
|
49
|
-
* disabled={!variant.availableForSale || isAdding}
|
|
50
|
-
* onClick={() => {
|
|
51
|
-
* addToCart([{ merchandiseId: variant.id, quantity: 1 }]);
|
|
52
|
-
* }}
|
|
53
|
-
* >
|
|
54
|
-
* {isAdding ? "Adding..." : "Add to Cart"}
|
|
55
|
-
* </button>
|
|
56
|
-
* );
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
15
|
+
/** @deprecated Use useAddToCart from @replohq/sdk/cart/hooks/use-add-to-cart. */
|
|
60
16
|
export declare function useAddToCart(): {
|
|
61
17
|
addToCart: (items: AddToCartItem[], openCartAfterAdd?: boolean) => Promise<void>;
|
|
62
18
|
isAdding: boolean;
|
|
@@ -1,121 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const PRODUCT_LOADER_KEYS = [
|
|
9
|
-
DATA_LOADER_KEYS.SHOPIFY_PRODUCT,
|
|
10
|
-
DATA_LOADER_KEYS.REPLO_PRODUCT
|
|
11
|
-
];
|
|
12
|
-
const PRODUCT_LIST_LOADER_KEYS = [
|
|
13
|
-
DATA_LOADER_KEYS.SHOPIFY_COLLECTION_PRODUCTS,
|
|
14
|
-
DATA_LOADER_KEYS.REBUY_RECOMMENDATIONS
|
|
15
|
-
];
|
|
16
|
-
function getMerchandiseFromProduct({
|
|
17
|
-
product,
|
|
18
|
-
merchandiseId
|
|
19
|
-
}) {
|
|
20
|
-
if (!product.variants) {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
const matchingVariant = product.variants.find(
|
|
24
|
-
(variant) => variant.id === merchandiseId
|
|
25
|
-
);
|
|
26
|
-
if (!matchingVariant) {
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
const image = matchingVariant.image ?? product.featuredImage ?? null;
|
|
30
|
-
return {
|
|
31
|
-
id: merchandiseId,
|
|
32
|
-
product: {
|
|
33
|
-
id: product.id,
|
|
34
|
-
title: product.title ?? "",
|
|
35
|
-
sellingPlanGroups: product.sellingPlanGroups ?? []
|
|
36
|
-
},
|
|
37
|
-
title: matchingVariant.title ?? "",
|
|
38
|
-
// NOTE (Max, 2026-08-03): loader prices are decimal MoneyV2 strings, but the
|
|
39
|
-
// cart is integer minor units, so convert at this storefront→cart boundary —
|
|
40
|
-
// a raw parseFloat would store "19.99" as 19 minor units (~100× too cheap).
|
|
41
|
-
price: matchingVariant.price ? fromMajorUnitsToMinorUnits(matchingVariant.price) : 0,
|
|
42
|
-
compareAtPrice: matchingVariant.compareAtPrice ? fromMajorUnitsToMinorUnits(matchingVariant.compareAtPrice) : null,
|
|
43
|
-
image: image ? { url: image.url, altText: image.altText } : null,
|
|
44
|
-
selectedOptions: matchingVariant.selectedOptions ?? []
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function findMerchandiseInQueryCache({
|
|
48
|
-
queryClient,
|
|
49
|
-
merchandiseId
|
|
50
|
-
}) {
|
|
51
|
-
for (const loaderKey of PRODUCT_LOADER_KEYS) {
|
|
52
|
-
const productQueries = queryClient.getQueriesData({
|
|
53
|
-
queryKey: [loaderKey]
|
|
54
|
-
});
|
|
55
|
-
for (const [, productData] of productQueries) {
|
|
56
|
-
if (!productData) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const merchandise = getMerchandiseFromProduct({
|
|
60
|
-
product: productData,
|
|
61
|
-
merchandiseId
|
|
62
|
-
});
|
|
63
|
-
if (merchandise) {
|
|
64
|
-
return merchandise;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (const loaderKey of PRODUCT_LIST_LOADER_KEYS) {
|
|
69
|
-
const productListQueries = queryClient.getQueriesData({
|
|
70
|
-
queryKey: [loaderKey]
|
|
71
|
-
});
|
|
72
|
-
for (const [, productListData] of productListQueries) {
|
|
73
|
-
for (const product of productListData?.products ?? []) {
|
|
74
|
-
const merchandise = getMerchandiseFromProduct({
|
|
75
|
-
product,
|
|
76
|
-
merchandiseId
|
|
77
|
-
});
|
|
78
|
-
if (merchandise) {
|
|
79
|
-
return merchandise;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return void 0;
|
|
2
|
+
import { canopyTombstoneError } from "../../lib/tombstone";
|
|
3
|
+
function findMerchandiseInQueryCache(_options) {
|
|
4
|
+
throw canopyTombstoneError({
|
|
5
|
+
symbol: "findMerchandiseInQueryCache",
|
|
6
|
+
subpath: "cart/hooks/use-add-to-cart"
|
|
7
|
+
});
|
|
85
8
|
}
|
|
86
9
|
function useAddToCart() {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
async (items, openCartAfterAdd = true) => {
|
|
92
|
-
setIsAdding(true);
|
|
93
|
-
try {
|
|
94
|
-
const cartLines = items.map((item) => {
|
|
95
|
-
const hasReploAttribution = item.properties?.some(
|
|
96
|
-
(prop) => prop.key === REPLO_ATTRIBUTION_PROPERTY.key
|
|
97
|
-
);
|
|
98
|
-
const properties = hasReploAttribution ? item.properties ?? [] : [REPLO_ATTRIBUTION_PROPERTY, ...item.properties ?? []];
|
|
99
|
-
const merchandise = item.merchandise ?? findMerchandiseInQueryCache({
|
|
100
|
-
queryClient,
|
|
101
|
-
merchandiseId: item.merchandiseId
|
|
102
|
-
});
|
|
103
|
-
return {
|
|
104
|
-
id: item.merchandiseId,
|
|
105
|
-
quantity: item.quantity ?? 1,
|
|
106
|
-
sellingPlanId: item.sellingPlanId ?? void 0,
|
|
107
|
-
properties,
|
|
108
|
-
merchandise
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
await cart.addToCart(cartLines, openCartAfterAdd);
|
|
112
|
-
} finally {
|
|
113
|
-
setIsAdding(false);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
[cart, queryClient]
|
|
117
|
-
);
|
|
118
|
-
return { addToCart, isAdding };
|
|
10
|
+
throw canopyTombstoneError({
|
|
11
|
+
symbol: "useAddToCart",
|
|
12
|
+
subpath: "cart/hooks/use-add-to-cart"
|
|
13
|
+
});
|
|
119
14
|
}
|
|
120
15
|
export {
|
|
121
16
|
findMerchandiseInQueryCache,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/hooks/use-add-to-cart.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { QueryClient } from \"@tanstack/react-query\";\nimport type { CartLineAttribute, CartLineMerchandise } from \"../cart-types\";\n\nimport { canopyTombstoneError } from \"../../lib/tombstone\";\n\nexport interface AddToCartItem {\n merchandiseId: string;\n quantity?: number;\n sellingPlanId?: string | null;\n properties?: CartLineAttribute[];\n merchandise?: CartLineMerchandise;\n}\n\n/** @deprecated Use findMerchandiseInQueryCache from @replohq/sdk/cart/hooks/use-add-to-cart. */\nexport function findMerchandiseInQueryCache(_options: {\n queryClient: QueryClient;\n merchandiseId: string;\n}): CartLineMerchandise | undefined {\n throw canopyTombstoneError({\n symbol: \"findMerchandiseInQueryCache\",\n subpath: \"cart/hooks/use-add-to-cart\",\n });\n}\n\n/** @deprecated Use useAddToCart from @replohq/sdk/cart/hooks/use-add-to-cart. */\nexport function useAddToCart(): {\n addToCart: (\n items: AddToCartItem[],\n openCartAfterAdd?: boolean,\n ) => Promise<void>;\n isAdding: boolean;\n} {\n throw canopyTombstoneError({\n symbol: \"useAddToCart\",\n subpath: \"cart/hooks/use-add-to-cart\",\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAKA,SAAS,4BAA4B;AAW9B,SAAS,4BAA4B,UAGR;AAClC,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;AAGO,SAAS,eAMd;AACA,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,45 +3,7 @@ export interface VariantBuyNowInfo {
|
|
|
3
3
|
quantity?: number;
|
|
4
4
|
sellingPlanId?: string | null;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* React hook that returns a `buyNow` function for express checkout flows.
|
|
8
|
-
* Handles creating the cart/checkout session server-side and redirecting
|
|
9
|
-
* the browser to checkout.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { useBuyNow } from "canopy-sdk/cart/hooks/use-buy-now";
|
|
15
|
-
*
|
|
16
|
-
* function MyComponent({ selectedVariant, selectedSellingPlan, quantity }) {
|
|
17
|
-
* const { buyNow } = useBuyNow();
|
|
18
|
-
*
|
|
19
|
-
* return (
|
|
20
|
-
* <Button
|
|
21
|
-
* disabled={!selectedVariant?.availableForSale}
|
|
22
|
-
* onClick={async () => {
|
|
23
|
-
* if (selectedVariant) {
|
|
24
|
-
* await buyNow(
|
|
25
|
-
* [
|
|
26
|
-
* {
|
|
27
|
-
* variantId: selectedVariant.id,
|
|
28
|
-
* quantity,
|
|
29
|
-
* sellingPlanId: selectedSellingPlan?.id,
|
|
30
|
-
* },
|
|
31
|
-
* ],
|
|
32
|
-
* { discountCodes: ["SUMMER2024"] }
|
|
33
|
-
* );
|
|
34
|
-
* }
|
|
35
|
-
* }}
|
|
36
|
-
* >
|
|
37
|
-
* Shop Now
|
|
38
|
-
* </Button>
|
|
39
|
-
* );
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @returns Object containing the buyNow function
|
|
44
|
-
*/
|
|
6
|
+
/** @deprecated Use useBuyNow from @replohq/sdk/cart/hooks/use-buy-now. */
|
|
45
7
|
export declare function useBuyNow(): {
|
|
46
8
|
buyNow: (variants: VariantBuyNowInfo[], options?: {
|
|
47
9
|
discountCodes?: string[];
|
|
@@ -1,60 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import { useClientValue } from "../../hooks/use-client-value";
|
|
4
|
-
import { CanopyError } from "../../lib/canopy-error";
|
|
5
|
-
import { buyNowAction } from "../buy-now-action";
|
|
6
|
-
const REPLO_LOCAL_STORAGE_SESSION_KEY = "_replo_sid";
|
|
7
|
-
const REPLO_SESSION_ID_KEY = "rsid";
|
|
8
|
-
const REPLO_CLIENT_ID_KEY = "rclid";
|
|
9
|
-
class ProductHasNoVariantsError extends CanopyError {
|
|
10
|
-
}
|
|
2
|
+
import { canopyTombstoneError } from "../../lib/tombstone";
|
|
11
3
|
function useBuyNow() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
);
|
|
16
|
-
const buyNow = React.useCallback(
|
|
17
|
-
async (variants, options) => {
|
|
18
|
-
if (!variants || variants.length === 0) {
|
|
19
|
-
throw new ProductHasNoVariantsError({
|
|
20
|
-
message: "No variants provided"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
const { redirectUrl } = await buyNowAction({
|
|
24
|
-
lineItems: variants.map((variant) => ({
|
|
25
|
-
variantId: variant.variantId,
|
|
26
|
-
quantity: variant.quantity ?? 1,
|
|
27
|
-
sellingPlanId: variant.sellingPlanId ?? null,
|
|
28
|
-
properties: []
|
|
29
|
-
})),
|
|
30
|
-
discountCodes: options?.discountCodes ?? [],
|
|
31
|
-
pageUrl: window.location.href
|
|
32
|
-
});
|
|
33
|
-
const url = new URL(redirectUrl);
|
|
34
|
-
const isStripeCheckout = url.hostname.endsWith("stripe.com");
|
|
35
|
-
if (!isStripeCheckout) {
|
|
36
|
-
const currentParams = new URLSearchParams(window.location.search);
|
|
37
|
-
for (const [key, value] of currentParams.entries()) {
|
|
38
|
-
if (!url.searchParams.has(key)) {
|
|
39
|
-
url.searchParams.set(key, value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (reploSessionString) {
|
|
43
|
-
try {
|
|
44
|
-
const sessionData = JSON.parse(reploSessionString);
|
|
45
|
-
if (sessionData.sessionId && sessionData.reploId) {
|
|
46
|
-
url.searchParams.set(REPLO_SESSION_ID_KEY, sessionData.sessionId);
|
|
47
|
-
url.searchParams.set(REPLO_CLIENT_ID_KEY, sessionData.reploId);
|
|
48
|
-
}
|
|
49
|
-
} catch {
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
window.location.href = url.toString();
|
|
54
|
-
},
|
|
55
|
-
[reploSessionString]
|
|
56
|
-
);
|
|
57
|
-
return { buyNow };
|
|
4
|
+
throw canopyTombstoneError({
|
|
5
|
+
symbol: "useBuyNow",
|
|
6
|
+
subpath: "cart/hooks/use-buy-now"
|
|
7
|
+
});
|
|
58
8
|
}
|
|
59
9
|
export {
|
|
60
10
|
useBuyNow
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/hooks/use-buy-now.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport { canopyTombstoneError } from \"../../lib/tombstone\";\n\nexport interface VariantBuyNowInfo {\n variantId: string;\n quantity?: number;\n sellingPlanId?: string | null;\n}\n\n/** @deprecated Use useBuyNow from @replohq/sdk/cart/hooks/use-buy-now. */\nexport function useBuyNow(): {\n buyNow: (\n variants: VariantBuyNowInfo[],\n options?: { discountCodes?: string[] },\n ) => Promise<void>;\n} {\n throw canopyTombstoneError({\n symbol: \"useBuyNow\",\n subpath: \"cart/hooks/use-buy-now\",\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,4BAA4B;AAS9B,SAAS,YAKd;AACA,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,41 +5,14 @@ export interface CartTotals {
|
|
|
5
5
|
totalSavings: number;
|
|
6
6
|
total: number;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
export declare function calculateLineItemsSubtotal(lineItems: CartLine[]): number;
|
|
14
|
-
/**
|
|
15
|
-
* Calculate cart totals including subtotal, discounts, and final total.
|
|
16
|
-
* When cart cost data is provided (from Shopify), uses the actual totalAmount
|
|
17
|
-
* which includes cart-level discounts from discount codes.
|
|
18
|
-
*
|
|
19
|
-
* @param options - Object containing lineItems and cart
|
|
20
|
-
* @param options.lineItems - Array of cart line items
|
|
21
|
-
* @param options.cart - Optional cart data from Shopify (includes discount codes)
|
|
22
|
-
*/
|
|
23
|
-
export declare function calculateCartTotals({ lineItems, cart, }: {
|
|
8
|
+
/** @deprecated Use calculateLineItemsSubtotal from @replohq/sdk/cart/utils/cart-utils. */
|
|
9
|
+
export declare function calculateLineItemsSubtotal(_lineItems: CartLine[]): number;
|
|
10
|
+
/** @deprecated Use calculateCartTotals from @replohq/sdk/cart/utils/cart-utils. */
|
|
11
|
+
export declare function calculateCartTotals(_options: {
|
|
24
12
|
lineItems: CartLine[];
|
|
25
13
|
cart: Cart | null;
|
|
26
14
|
}): CartTotals;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* force-converged them onto a version where this no longer existed, crashing the
|
|
32
|
-
* cart). It formats INTEGER MINOR UNITS — the units every canopy cart value uses
|
|
33
|
-
* since 1.0.0 (`calculateCartTotals`, `getCartLinePricing`, `CartCost`) — so it
|
|
34
|
-
* is intentionally NOT the pre-1.0.0 decimal formatter: passing 1999 yields
|
|
35
|
-
* "$19.99", not "$1,999.00". New/migrated code should call
|
|
36
|
-
* `formatAmount({ amount, currencyCode })` from `canopy-sdk/money` directly.
|
|
37
|
-
*/
|
|
38
|
-
export declare function formatPrice(price: number, currency?: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Validates and formats a Shopify selling plan ID to ensure it has the correct GID format.
|
|
41
|
-
*
|
|
42
|
-
* @param sellingPlanId - The selling plan ID to validate and format
|
|
43
|
-
* @returns The formatted selling plan ID with GID prefix, or null if no ID provided
|
|
44
|
-
*/
|
|
45
|
-
export declare function formatSellingPlanId(sellingPlanId: string | null | undefined): string | null;
|
|
15
|
+
/** @deprecated Use formatPrice from @replohq/sdk/cart/utils/cart-utils. */
|
|
16
|
+
export declare function formatPrice(_price: number, _currency?: string): string;
|
|
17
|
+
/** @deprecated Use formatSellingPlanId from @replohq/sdk/cart/utils/cart-utils. */
|
|
18
|
+
export declare function formatSellingPlanId(_sellingPlanId: string | null | undefined): string | null;
|
package/cart/utils/cart-utils.js
CHANGED
|
@@ -1,41 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
);
|
|
1
|
+
import { canopyTombstoneError } from "../../lib/tombstone";
|
|
2
|
+
function calculateLineItemsSubtotal(_lineItems) {
|
|
3
|
+
throw canopyTombstoneError({
|
|
4
|
+
symbol: "calculateLineItemsSubtotal",
|
|
5
|
+
subpath: "cart/utils/cart-utils"
|
|
6
|
+
});
|
|
8
7
|
}
|
|
9
|
-
function calculateCartTotals({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const compareAtSubtotal = lineItems.reduce((sum, item) => {
|
|
15
|
-
return sum + getCartLinePricing(item).compareAtPrice * item.quantity;
|
|
16
|
-
}, 0);
|
|
17
|
-
const total = cart?.cost.totalAmount ?? lineItemSubtotal;
|
|
18
|
-
const actualSubtotal = cart?.cost.subtotalAmount ?? lineItemSubtotal;
|
|
19
|
-
const discountAmount = actualSubtotal - total;
|
|
20
|
-
const totalSavings = compareAtSubtotal - total;
|
|
21
|
-
return {
|
|
22
|
-
subtotal: lineItemSubtotal,
|
|
23
|
-
discountAmount,
|
|
24
|
-
totalSavings,
|
|
25
|
-
total
|
|
26
|
-
};
|
|
8
|
+
function calculateCartTotals(_options) {
|
|
9
|
+
throw canopyTombstoneError({
|
|
10
|
+
symbol: "calculateCartTotals",
|
|
11
|
+
subpath: "cart/utils/cart-utils"
|
|
12
|
+
});
|
|
27
13
|
}
|
|
28
|
-
function formatPrice(
|
|
29
|
-
|
|
14
|
+
function formatPrice(_price, _currency = "USD") {
|
|
15
|
+
throw canopyTombstoneError({
|
|
16
|
+
symbol: "formatPrice",
|
|
17
|
+
subpath: "cart/utils/cart-utils"
|
|
18
|
+
});
|
|
30
19
|
}
|
|
31
|
-
function formatSellingPlanId(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return sellingPlanId;
|
|
37
|
-
}
|
|
38
|
-
return `gid://shopify/SellingPlan/${sellingPlanId}`;
|
|
20
|
+
function formatSellingPlanId(_sellingPlanId) {
|
|
21
|
+
throw canopyTombstoneError({
|
|
22
|
+
symbol: "formatSellingPlanId",
|
|
23
|
+
subpath: "cart/utils/cart-utils"
|
|
24
|
+
});
|
|
39
25
|
}
|
|
40
26
|
export {
|
|
41
27
|
calculateCartTotals,
|
|
@@ -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 {
|
|
5
|
-
"mappings": "AAEA,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { Cart, CartLine } from \"../cart-types\";\n\nimport { canopyTombstoneError } from \"../../lib/tombstone\";\n\nexport interface CartTotals {\n subtotal: number;\n discountAmount: number;\n totalSavings: number;\n total: number;\n}\n\n/** @deprecated Use calculateLineItemsSubtotal from @replohq/sdk/cart/utils/cart-utils. */\nexport function calculateLineItemsSubtotal(_lineItems: CartLine[]): number {\n throw canopyTombstoneError({\n symbol: \"calculateLineItemsSubtotal\",\n subpath: \"cart/utils/cart-utils\",\n });\n}\n\n/** @deprecated Use calculateCartTotals from @replohq/sdk/cart/utils/cart-utils. */\nexport function calculateCartTotals(_options: {\n lineItems: CartLine[];\n cart: Cart | null;\n}): CartTotals {\n throw canopyTombstoneError({\n symbol: \"calculateCartTotals\",\n subpath: \"cart/utils/cart-utils\",\n });\n}\n\n/** @deprecated Use formatPrice from @replohq/sdk/cart/utils/cart-utils. */\nexport function formatPrice(_price: number, _currency: string = \"USD\"): string {\n throw canopyTombstoneError({\n symbol: \"formatPrice\",\n subpath: \"cart/utils/cart-utils\",\n });\n}\n\n/** @deprecated Use formatSellingPlanId from @replohq/sdk/cart/utils/cart-utils. */\nexport function formatSellingPlanId(\n _sellingPlanId: string | null | undefined,\n): string | null {\n throw canopyTombstoneError({\n symbol: \"formatSellingPlanId\",\n subpath: \"cart/utils/cart-utils\",\n });\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,4BAA4B;AAU9B,SAAS,2BAA2B,YAAgC;AACzE,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;AAGO,SAAS,oBAAoB,UAGrB;AACb,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;AAGO,SAAS,YAAY,QAAgB,YAAoB,OAAe;AAC7E,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;AAGO,SAAS,oBACd,gBACe;AACf,QAAM,qBAAqB;AAAA,IACzB,QAAQ;AAAA,IACR,SAAS;AAAA,EACX,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|