@commercelayer/react-components 4.15.3-beta.1 → 4.15.3-beta.3

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.
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutLink=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),getApplicationLink_1=require("../../utils/getApplicationLink"),getDomain_1=require("../../utils/getDomain"),organization_1=require("../../utils/organization");function CheckoutLink(props){var _a;const{label,hostedCheckout=!0,children,onClick}=props,p=tslib_1.__rest(props,["label","hostedCheckout","children","onClick"]),{order}=(0,react_1.useContext)(OrderContext_1.default),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=(0,getDomain_1.getDomain)(endpoint),href=hostedCheckout&&order?.id?(0,getApplicationLink_1.getApplicationLink)({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):(_a=order?.checkout_url)!==null&&_a!==void 0?_a:"",parentProps=Object.assign({checkoutUrl:order?.checkout_url,hostedCheckout,label,href},p);function handleClick(e){accessToken&&endpoint&&(0,organization_1.getOrganizationConfig)({accessToken,endpoint,params:{accessToken}}).then(config=>{var _a2;!((_a2=config?.links)===null||_a2===void 0)&&_a2.checkout&&(e.preventDefault(),location.href=config.links.checkout)})}return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("a",Object.assign({href,onClick:handleClick},p,{children:label}))}exports.CheckoutLink=CheckoutLink,exports.default=CheckoutLink;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutLink=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),getApplicationLink_1=require("../../utils/getApplicationLink"),getDomain_1=require("../../utils/getDomain"),organization_1=require("../../utils/organization");function CheckoutLink(props){var _a;const{label,hostedCheckout=!0,children,onClick}=props,p=tslib_1.__rest(props,["label","hostedCheckout","children","onClick"]),{order}=(0,react_1.useContext)(OrderContext_1.default),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=(0,getDomain_1.getDomain)(endpoint),href=hostedCheckout&&order?.id?(0,getApplicationLink_1.getApplicationLink)({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):(_a=order?.checkout_url)!==null&&_a!==void 0?_a:"",parentProps=Object.assign({checkoutUrl:order?.checkout_url,hostedCheckout,label,href},p);function handleClick(e){e.preventDefault(),e.stopPropagation(),console.log("e.currentTarget.href",e.currentTarget.href);const currentHref=e.currentTarget.href;accessToken&&endpoint&&order?.id?(0,organization_1.getOrganizationConfig)({accessToken,endpoint,params:{accessToken,orderId:order?.id}}).then(config=>{var _a2;!((_a2=config?.links)===null||_a2===void 0)&&_a2.checkout?location.href=config.links.checkout:location.href=currentHref}):location.href=currentHref}return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("a",Object.assign({href,onClick:handleClick},p,{children:label}))}exports.CheckoutLink=CheckoutLink,exports.default=CheckoutLink;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{getOrganizationConfig}from"../../utils/organization";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,onClick,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=hostedCheckout&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):order?.checkout_url??"",parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};function handleClick(e){accessToken&&endpoint&&getOrganizationConfig({accessToken,endpoint,params:{accessToken}}).then(config=>{config?.links?.checkout&&(e.preventDefault(),location.href=config.links.checkout)})}return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,onClick:handleClick,...p,children:label})}export default CheckoutLink;
2
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{getOrganizationConfig}from"../../utils/organization";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,onClick,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=hostedCheckout&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):order?.checkout_url??"",parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};function handleClick(e){e.preventDefault(),e.stopPropagation(),console.log("e.currentTarget.href",e.currentTarget.href);const currentHref=e.currentTarget.href;accessToken&&endpoint&&order?.id?getOrganizationConfig({accessToken,endpoint,params:{accessToken,orderId:order?.id}}).then(config=>{config?.links?.checkout?location.href=config.links.checkout:location.href=currentHref}):location.href=currentHref}return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,onClick:handleClick,...p,children:label})}export default CheckoutLink;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "4.15.3-beta.1",
3
+ "version": "4.15.3-beta.3",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",