@techsio/storefront-data
Version:
Medusa-first storefront data layer built on TanStack Query.
24 lines (23 loc) • 1.2 kB
JavaScript
const resolveCheckoutCartInput = ({ cartId, cart })=>{
const resolvedCartId = cartId ?? ("string" == typeof cart?.id ? cart.id : void 0);
if (cart && resolvedCartId && cart.id && cart.id !== resolvedCartId) return {
resolvedCartId
};
return {
resolvedCartId,
normalizedCart: cart
};
};
const resolveEffectiveCheckoutCart = ({ cartId, cart, getCachedCart })=>cart ?? getCachedCart(cartId);
const resolveSelectedPaymentSession = (cart)=>{
const paymentSessions = cart?.payment_collection?.payment_sessions;
if (!paymentSessions?.length) return;
return paymentSessions.find((session)=>true === session.is_selected) ?? paymentSessions[0];
};
const resolveSelectedPaymentProviderId = (cart)=>resolveSelectedPaymentSession(cart)?.provider_id;
const resolveExistingPaymentCollection = (cart, paymentProviderId)=>{
const paymentCollection = cart?.payment_collection;
if (!paymentCollection) return null;
return resolveSelectedPaymentProviderId(cart) === paymentProviderId ? paymentCollection : null;
};
export { resolveCheckoutCartInput, resolveEffectiveCheckoutCart, resolveExistingPaymentCollection, resolveSelectedPaymentProviderId };