UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

67 lines (66 loc) 2.78 kB
import type { AddOrUpdateItemError } from '@scayle/storefront-api'; /** * Checks if all basket add/update errors indicate that items were added with reduced quantity. * This function helps determine if a basket operation partially succeeded, meaning some items were added but with a lower quantity than requested. * * @param errors An array of `AddOrUpdateItemError` objects, typically returned from a basket add/update operation. * @returns `true` if all errors indicate reduced quantity, `false` otherwise (including when the `errors` array is empty, null, or undefined). * * @example * ```typescript * const errors: AddOrUpdateItemError[] = [ * { operation: 'add', kind: AddToBasketFailureKind.ITEM_ADDED_WITH_REDUCED_QUANTITY, variantId: 123 }, * { operation: 'update', kind: UpdateBasketItemFailureKind.ITEM_ADDED_WITH_REDUCED_QUANTITY, variantId: 456 }, * ] * * const allReducedQuantity = wasAddedWithReducedQuantity(errors) // true * * const noErrors = wasAddedWithReducedQuantity() // false * * const otherErrors = wasAddedWithReducedQuantity([ * { operation: 'add', kind: AddToBasketFailureKind.ITEM_NOT_FOUND, variantId: 789 }, * ]) // false * ``` */ export declare const wasAddedWithReducedQuantity: (errors?: AddOrUpdateItemError[]) => boolean; /** * Merges the two orderCustomData objects when both RPC and parameter values are provided. * If an attribute exists in both, the parameter value takes precedence. * * @param orderCustomDataRpc The order custom data from the RPC context. * @param orderCustomDataParam The order custom data from the parameter. * * @example * ```typescript * const orderCustomDataRpc = { * orderId: '1', * } * const orderCustomDataParam = { * orderId: '2', * } * const mergedOrderCustomData = mergeOrderCustomData(orderCustomDataRpc, orderCustomDataParam) // { orderId: '2' } * * const orderCustomDataRpc = { * orderId: '1', * } * const orderCustomDataParam = undefined * const mergedOrderCustomData = mergeOrderCustomData(orderCustomDataRpc, orderCustomDataParam) // { orderId: '1' } * * const orderCustomDataRpc = undefined * const orderCustomDataParam = { * orderId: '2', * } * const mergedOrderCustomData = mergeOrderCustomData(orderCustomDataRpc, orderCustomDataParam) // { orderId: '2' } * * const orderCustomDataRpc = { * orderId: '1', * } * const orderCustomDataParam = { * orderName: 'Order 2', * } * const mergedOrderCustomData = mergeOrderCustomData(orderCustomDataRpc, orderCustomDataParam) // { orderId: '1', orderName: 'Order 2' } * ``` * * @returns The merged order custom data. */ export declare const mergeOrderCustomData: (orderCustomDataRpc?: Record<string, unknown>, orderCustomDataParam?: Record<string, unknown>) => Record<string, unknown>;