@commercelayer/react-components 2.49.1 → 2.49.5
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/lib/cjs/components/AdyenPayment.js +1 -1
- package/lib/cjs/components/BillingAddressContainer.js +1 -1
- package/lib/cjs/components/BillingAddressForm.js +1 -1
- package/lib/cjs/components/CustomerContainer.js +1 -1
- package/lib/cjs/components/LineItemsContainer.js +1 -1
- package/lib/cjs/components/OrderContainer.js +1 -1
- package/lib/cjs/components/PaymentMethodsContainer.js +1 -1
- package/lib/cjs/components/PaymentSource.js +1 -1
- package/lib/cjs/components/PlaceOrderContainer.js +1 -1
- package/lib/cjs/components/ShipmentsContainer.js +1 -1
- package/lib/cjs/components/ShippingAddressForm.js +1 -1
- package/lib/cjs/components/gateways/AdyenGateway.js +1 -1
- package/lib/cjs/reducers/AddressReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.d.ts +9 -5
- package/lib/cjs/reducers/OrderReducer.js +1 -1
- package/lib/cjs/reducers/PlaceOrderReducer.js +1 -1
- package/lib/cjs/utils/localStorage.d.ts +1 -2
- package/lib/esm/components/AdyenPayment.js +1 -1
- package/lib/esm/components/BillingAddressContainer.js +1 -1
- package/lib/esm/components/BillingAddressForm.js +1 -1
- package/lib/esm/components/CustomerContainer.js +1 -1
- package/lib/esm/components/LineItemsContainer.js +1 -1
- package/lib/esm/components/OrderContainer.js +1 -1
- package/lib/esm/components/PaymentMethodsContainer.js +1 -1
- package/lib/esm/components/PaymentSource.js +1 -1
- package/lib/esm/components/PlaceOrderContainer.js +1 -1
- package/lib/esm/components/ShipmentsContainer.js +1 -1
- package/lib/esm/components/ShippingAddressForm.js +1 -1
- package/lib/esm/components/gateways/AdyenGateway.js +1 -1
- package/lib/esm/reducers/AddressReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.d.ts +9 -5
- package/lib/esm/reducers/OrderReducer.js +1 -1
- package/lib/esm/reducers/PlaceOrderReducer.js +1 -1
- package/lib/esm/utils/localStorage.d.ts +1 -2
- package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";export const addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"];export const addressInitialState={errors:[]};export const setAddressErrors=({errors:s,dispatch:e,currentErrors:d=[],resource:i})=>{const r=i==="billing_address"?s.filter((s=>s.resource===i)):d.filter((s=>s.resource==="billing_address"));const t=i==="shipping_address"?s.filter((s=>s.resource===i)):d.filter((s=>s.resource==="shipping_address"));const o=[...r,...t];e&&e({type:"setErrors",payload:{errors:o}})};export const setAddress=({values:s,resource:e,dispatch:d})=>{d&&d({type:"setAddress",payload:{[`${e}`]:s}})};export const setCloneAddress=(s,e,d)=>{d({type:"setCloneAddress",payload:{[`${camelCase(e)}Id`]:s}})};export const saveAddresses=async({config:s,updateOrder:e,order:d,state:i
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";export const addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"];export const addressInitialState={errors:[]};export const setAddressErrors=({errors:s,dispatch:e,currentErrors:d=[],resource:i})=>{const r=i==="billing_address"?s.filter((s=>s.resource===i)):d.filter((s=>s.resource==="billing_address"));const t=i==="shipping_address"?s.filter((s=>s.resource===i)):d.filter((s=>s.resource==="shipping_address"));const o=[...r,...t];e&&e({type:"setErrors",payload:{errors:o}})};export const setAddress=({values:s,resource:e,dispatch:d})=>{d&&d({type:"setAddress",payload:{[`${e}`]:s}})};export const setCloneAddress=(s,e,d)=>{d({type:"setCloneAddress",payload:{[`${camelCase(e)}Id`]:s}})};export const saveAddresses=async({config:s,updateOrder:e,order:d,state:i})=>{var r,t,o;const{shipToDifferentAddress:a,billing_address:l,shipping_address:n,billingAddressId:p,shippingAddressId:_}=i;try{const i=getSdk(s);if(d){const s=(r=d===null||d===void 0?void 0:d.billing_address)===null||r===void 0?void 0:r.reference;const c={id:d===null||d===void 0?void 0:d.id,_billing_address_clone_id:p,_shipping_address_clone_id:p};if(s===p){c._billing_address_clone_id=(t=d===null||d===void 0?void 0:d.billing_address)===null||t===void 0?void 0:t.id;c._shipping_address_clone_id=(o=d===null||d===void 0?void 0:d.shipping_address)===null||o===void 0?void 0:o.id}if(!isEmpty(l)&&l){delete c._billing_address_clone_id;delete c._shipping_address_clone_id;c._shipping_address_same_as_billing=true;const s=await i.addresses.create(l);c.billing_address=i.addresses.relationship(s.id)}if(a){delete c._shipping_address_same_as_billing;if(_)c._shipping_address_clone_id=_;if(!isEmpty(n)&&n){delete c._shipping_address_clone_id;const s=await i.addresses.create(n);c.shipping_address=i.addresses.relationship(s.id)}}if(!isEmpty(c)&&e){await e({id:d.id,attributes:c})}}}catch(s){console.error(s)}};const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"];const addressReducer=(s,e)=>baseReducer(s,e,type);export default addressReducer;
|
|
@@ -53,13 +53,15 @@ export interface AddToCartImport {
|
|
|
53
53
|
export interface UnsetOrderState {
|
|
54
54
|
(dispatch: Dispatch<OrderActions>): void;
|
|
55
55
|
}
|
|
56
|
-
declare type
|
|
56
|
+
export declare type ResourceIncluded = 'billing_address' | 'shipping_address' | 'line_items.line_item_options.sku_option' | 'available_customer_payment_sources.payment_source' | 'shipments.available_shipping_methods' | 'shipments.stock_transfers' | 'shipments.shipment_line_items.line_item' | 'shipments.shipping_method' | 'shipments.stock_location' | 'payment_source' | 'available_payment_methods' | 'payment_method';
|
|
57
|
+
declare type ResourceIncludedLoaded = Partial<Record<ResourceIncluded, boolean>>;
|
|
57
58
|
export interface OrderPayload {
|
|
58
59
|
loading?: boolean;
|
|
59
60
|
orderId?: string;
|
|
60
61
|
order?: Order;
|
|
61
62
|
errors?: BaseError[];
|
|
62
|
-
include?:
|
|
63
|
+
include?: ResourceIncluded[];
|
|
64
|
+
includeLoaded?: ResourceIncludedLoaded;
|
|
63
65
|
}
|
|
64
66
|
export declare type AddToCartValues = Pick<AddToCartParams, 'bundleCode' | 'lineItem' | 'quantity' | 'skuCode' | 'skuId' | 'option'>;
|
|
65
67
|
export declare type AddToCartImportValues = Pick<AddToCartImportParams, 'lineItems'>;
|
|
@@ -82,11 +84,13 @@ export declare type UpdateOrderArgs = {
|
|
|
82
84
|
export declare function updateOrder({ id, attributes, dispatch, config, include, }: UpdateOrderArgs): Promise<void>;
|
|
83
85
|
export declare const setOrder: (order: Order, dispatch?: Dispatch<OrderActions> | undefined) => void;
|
|
84
86
|
export declare type AddResourceToInclude = {
|
|
85
|
-
resourcesIncluded?:
|
|
87
|
+
resourcesIncluded?: ResourceIncluded[];
|
|
86
88
|
dispatch?: Dispatch<OrderActions>;
|
|
87
|
-
newResource
|
|
89
|
+
newResource?: ResourceIncluded | ResourceIncluded[];
|
|
90
|
+
resourceIncludedLoaded?: ResourceIncludedLoaded;
|
|
91
|
+
newResourceLoaded?: ResourceIncludedLoaded;
|
|
88
92
|
};
|
|
89
|
-
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, }: AddResourceToInclude): void;
|
|
93
|
+
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, newResourceLoaded, resourceIncludedLoaded, }: AddResourceToInclude): void;
|
|
90
94
|
export declare const addToCart: AddToCart;
|
|
91
95
|
export declare const unsetOrderState: UnsetOrderState;
|
|
92
96
|
declare type OrderErrors = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import{isEmpty,size,map}from"lodash";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async
|
|
1
|
+
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import{isEmpty,size,map}from"lodash";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async e=>{if(e){const{persistKey:r,state:t,dispatch:s,config:o,orderMetadata:d,orderAttributes:c={},setLocalOrder:n}=e;if(t===null||t===void 0?void 0:t.orderId)return t.orderId;const a=getSdk(o);try{const e=await(a===null||a===void 0?void 0:a.orders.create(Object.assign({metadata:d},c)));s&&s({type:"setOrderId",payload:{orderId:e===null||e===void 0?void 0:e.id}});r&&n&&n(r,e.id);return e.id}catch(e){const r=getErrors(e,"orders");console.error("Create order",r);if(s)setErrors({currentErrors:t===null||t===void 0?void 0:t.errors,newErrors:r,dispatch:s})}}return""};export const getApiOrder=async e=>{const{id:r,dispatch:t,config:s,clearWhenPlaced:o,persistKey:d,deleteLocalOrder:c,state:n}=e;const a=getSdk(s);try{const e={};if((n===null||n===void 0?void 0:n.include)&&n.include.length>0){e.include=n.include}const s=await a.orders.retrieve(r,e);if(o&&s.status==="placed"||s.status==="approved"||s.status==="cancelled"){d&&c&&c(d);t&&t({type:"setOrder",payload:{order:undefined,orderId:""}})}else{t&&t({type:"setOrder",payload:{order:s,orderId:s.id}})}return s}catch(e){const r=getErrors(e,"orders");console.error("Retrieve order",r);if(t)setErrors({currentErrors:n===null||n===void 0?void 0:n.errors,newErrors:r,dispatch:t});return}};export async function updateOrder({id:e,attributes:r,dispatch:t,config:s,include:o}){const d=getSdk(s);try{const s=Object.assign(Object.assign({},r),{id:e});const c=await d.orders.update(s,{include:o});t&&t({type:"setOrder",payload:{order:c}})}catch(e){const r=getErrors(e,"orders");if(t){setOrderErrors({errors:r,dispatch:t});t({type:"setErrors",payload:{errors:r}})}}}export const setOrder=(e,r)=>{r&&r({type:"setOrder",payload:{order:e}})};export function addResourceToInclude({resourcesIncluded:e=[],dispatch:r,newResource:t,newResourceLoaded:s,resourceIncludedLoaded:o}){const d={include:undefined,includeLoaded:undefined};if(t){d.include=[...e,...typeof t==="string"?[t]:t]}else{delete d.include}d.includeLoaded=Object.assign(Object.assign({},o),s);r&&r({type:"setIncludesResource",payload:d})}export const addToCart=async e=>{const{skuCode:r,bundleCode:t,skuId:s,quantity:o,option:d,config:c,dispatch:n,lineItem:a,state:i,errors:u=[]}=e;try{const p=getSdk(c);const l=await createOrder(e);if(l){const c=p.orders.relationship(l);const y=a===null||a===void 0?void 0:a.name;const f=a===null||a===void 0?void 0:a.imageUrl;const g={order:c,sku_code:r,name:y,image_url:f,quantity:o||1,_update_quantity:true,bundle_code:t};if(s){g["item"]=p.skus.relationship(s)}const m=await p.line_items.create(g);if(!isEmpty(d)){let r=0;map(d,(async t=>{const{options:s,skuOptionId:o}=t;const c=p.sku_options.relationship(o);const n=p.line_items.relationship(m.id);const a={quantity:1,options:s,sku_option:c,line_item:n};await p.line_item_options.create(a);r+=1;if(r===size(d)){await getApiOrder(Object.assign({id:l},e))}}))}else{await getApiOrder(Object.assign(Object.assign({id:l},e),{state:i}))}if(!isEmpty(u)&&n){n({type:"setErrors",payload:{errors:[]}})}return{success:true}}return{success:false}}catch(e){const r=getErrors(e,"orders");console.error("Add to cart",r);if(n)setErrors({currentErrors:i===null||i===void 0?void 0:i.errors,newErrors:r,dispatch:n});return{success:false}}};export const unsetOrderState=e=>{e({type:"setOrderId",payload:{orderId:""}});e({type:"setOrder",payload:{order:undefined}})};export function setOrderErrors({dispatch:e,errors:r}){e&&e({type:"setErrors",payload:{errors:r}});return{success:false}}export const saveAddressToCustomerAddressBook=({type:e,value:r,dispatch:t})=>{const s=`_save_${e}_to_customer_address_book`;const o=`${r}`;setCustomerOrderParam(s,o);t&&t({type:"setSaveAddressToCustomerAddressBook",payload:{[s]:o}})};export const setGiftCardOrCouponCode=async({code:e,dispatch:r,config:t,order:s})=>{try{if(t&&s&&e&&r){const o=getSdk(t);const d={id:s.id,gift_card_or_coupon_code:e};const c=await o.orders.update(d);r({type:"setErrors",payload:{errors:[],order:c}});return{success:true}}return{success:false}}catch(e){const t=getErrors(e,"gift_card_or_coupon_code");r&&setOrderErrors({errors:t,dispatch:r});return{success:false}}};export const removeGiftCardOrCouponCode=async({codeType:e,dispatch:r,config:t,order:s})=>{try{if(t&&s&&r){const o=getSdk(t);const d={id:s.id,[e]:""};const c=await o.orders.update(d);r({type:"setErrors",payload:{errors:[],order:c}});return{success:true}}return{success:false}}catch(e){const t=getErrors(e,"gift_card_or_coupon_code");console.error("Remove gift card o coupon code",t);r&&setOrderErrors({errors:t,dispatch:r});return{success:false}}};export const orderInitialState={loading:false,orderId:"",order:undefined,errors:[]};const orderReducer=(e,r)=>baseReducer(e,r,actionType);export default orderReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:false};export const setPlaceOrderErrors=(e,t)=>{t&&t({type:"setErrors",payload:{errors:e}})};export const placeOrderPermitted=async({config:e,order:t,dispatch:r,options:s})=>{var a;if(t&&e){let e=true;if(t.privacy_url&&t.terms_url){e=localStorage.getItem("privacy-terms")==="true"}const i=t.billing_address;if(isEmpty(i))e=false;const o=t.shipping_address;if(isEmpty(o))e=false;const d=t.shipments;const p=d&&shipmentsFilled(d);if(!isEmpty(d)&&!p)e=false;const l=t.payment_method;const n=t.payment_source;if(t.total_amount_with_taxes_cents!==0&&isEmpty(l===null||l===void 0?void 0:l.id))e=false;r({type:"setPlaceOrderPermitted",payload:{isPermitted:e,paymentType:l===null||l===void 0?void 0:l.payment_source_type,paymentSecret:n===null||n===void 0?void 0:n.client_secret,paymentId:(a=n===null||n===void 0?void 0:n.options)===null||a===void 0?void 0:a.id,paymentSource:n,options:s}})}};export const setPlaceOrder=async({state:e,order:t,config:r,setOrderErrors:s,paymentSource:a})=>{const i={placed:false};try{
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:false};export const setPlaceOrderErrors=(e,t)=>{t&&t({type:"setErrors",payload:{errors:e}})};export const placeOrderPermitted=async({config:e,order:t,dispatch:r,options:s})=>{var a;if(t&&e){let e=true;if(t.privacy_url&&t.terms_url){e=localStorage.getItem("privacy-terms")==="true"}const i=t.billing_address;if(isEmpty(i))e=false;const o=t.shipping_address;if(isEmpty(o))e=false;const d=t.shipments;const p=d&&shipmentsFilled(d);if(!isEmpty(d)&&!p)e=false;const l=t.payment_method;const n=t.payment_source;if(t.total_amount_with_taxes_cents!==0&&isEmpty(l===null||l===void 0?void 0:l.id))e=false;r({type:"setPlaceOrderPermitted",payload:{isPermitted:e,paymentType:l===null||l===void 0?void 0:l.payment_source_type,paymentSecret:n===null||n===void 0?void 0:n.client_secret,paymentId:(a=n===null||n===void 0?void 0:n.options)===null||a===void 0?void 0:a.id,paymentSource:n,options:s}})}};export const setPlaceOrder=async({state:e,order:t,config:r,setOrderErrors:s,paymentSource:a})=>{const i={placed:false};try{if(e&&t&&r&&a){const o=getSdk(r);const{options:d,paymentType:p}=e;if(p==="paypal_payments"){if(!(d===null||d===void 0?void 0:d.paypalPayerId)&&(a===null||a===void 0?void 0:a.approval_url)){window.location.href=a===null||a===void 0?void 0:a.approval_url;return i}await o.paypal_payments.update({id:a.id,paypal_payer_id:d===null||d===void 0?void 0:d.paypalPayerId})}const l={id:t.id,_place:true};if(saveBillingAddress()){await o.orders.update({id:t.id,_save_billing_address_to_customer_address_book:true})}if(saveShippingAddress()){await o.orders.update({id:t.id,_save_shipping_address_to_customer_address_book:true})}switch(p){case"braintree_payments":if(saveToWallet()){await o.orders.update({id:t.id,_save_payment_source_to_customer_wallet:true})}await o.orders.update(l);s&&s([]);return{placed:true};default:if(saveToWallet()){await o.orders.update({id:t.id,_save_payment_source_to_customer_wallet:true})}await o.orders.update(l);s&&s([]);return{placed:true}}}return i}catch(e){const t=getErrors(e,"orders");s&&s(t);return Object.assign(Object.assign({},i),{errors:t})}};const type=["setErrors","setPlaceOrderPermitted"];const placeOrderReducer=(e,t)=>baseReducer(e,t,type);export default placeOrderReducer;
|
|
@@ -13,6 +13,5 @@ export declare const deleteLocalOrder: DeleteLocalOrder;
|
|
|
13
13
|
export declare const getSavePaymentSourceToCustomerWallet: () => boolean;
|
|
14
14
|
export declare const getSaveBillingAddressToAddressBook: () => boolean;
|
|
15
15
|
export declare const getSaveShippingAddressToAddressBook: () => boolean;
|
|
16
|
-
declare type CustomerOrderParams = '_save_payment_source_to_customer_wallet' | '_save_billing_address_to_customer_address_book' | '_save_shipping_address_to_customer_address_book';
|
|
16
|
+
export declare type CustomerOrderParams = '_save_payment_source_to_customer_wallet' | '_save_billing_address_to_customer_address_book' | '_save_shipping_address_to_customer_address_book';
|
|
17
17
|
export declare function setCustomerOrderParam<T extends CustomerOrderParams>(key: T, value: string): void;
|
|
18
|
-
export {};
|