Socket
Socket
Sign inDemoInstall

@vtex/order-items

Package Overview
Dependencies
Maintainers
67
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vtex/order-items - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

src/.npmignore

12

CHANGELOG.md

@@ -10,2 +10,14 @@ # Changelog

## [0.6.0] - 2021-04-26
### Added
- `addItems` function with options argument to allow outdated data on the
orderForm.
### Changed
- Added options argument to `updateQuantity` and `removeItem` functions to
allow outdated data on the orderForm.
### Deprecated
- Function `addItem` in favor of `addItems`.
## [0.5.2] - 2021-04-21

@@ -12,0 +24,0 @@ ### Changed

52

dist/index.esm.js
/*!
* @vtex/order-items v0.5.2
* @vtex/order-items v0.6.0
* (c) VTEX

@@ -14,2 +14,3 @@ * Released under the MIT License.

addItem: noop,
addItems: noop,
updateQuantity: noop,

@@ -83,2 +84,9 @@ removeItem: noop,

const isSameSeller = input.seller === item.seller;
/**
* If item is a gift, it should not be considered as the same item of the added one,
* otherwise buyer will not see two different products in the cart (the gift and the paid one)
*/
if (item.isGift) {
return false;
}
// input has no options

@@ -137,2 +145,3 @@ if (input.options == null) {

priceTags: [],
isGift: false,
};

@@ -148,3 +157,3 @@ };

const mutate = useMutateAddItems();
const addItemTask = useCallback(({ mutationInputItems, mutationInputMarketingData, orderFormItems, salesChannel, }) => ({
const addItemTask = useCallback(({ mutationInputItems, mutationInputMarketingData, orderFormItems, salesChannel, allowedOutdatedData, }) => ({
execute: async () => {

@@ -156,2 +165,3 @@ var _a;

salesChannel,
allowedOutdatedData,
});

@@ -250,3 +260,3 @@ if (!updatedOrderForm || ((_a = errors === null || errors === void 0 ? void 0 : errors.length) !== null && _a !== void 0 ? _a : 0) > 0) {

const mutate = useMutateUpdateQuantity();
const updateItemTask = useCallback(({ items, orderFormItems, id, }) => {
const updateItemTask = useCallback(({ items, orderFormItems, id, allowedOutdatedData, }) => {
return {

@@ -272,2 +282,3 @@ id,

}),
allowedOutdatedData,
};

@@ -453,4 +464,4 @@ const { data, errors } = await mutate(mutationVariables);

}, [orderForm.items]);
const updateQuantity = useCallback((input) => {
var _a, _b, _c;
const updateQuantity = useCallback((input, options) => {
var _a, _b;
let index;

@@ -470,3 +481,3 @@ let uniqueId = '';

if (index < 0 || index >= currentOrderFormItems.length) {
throw new Error(`Item ${(_b = input.id) !== null && _b !== void 0 ? _b : input.uniqueId} not found`);
throw new Error(`Item ${input.id || input.uniqueId} not found`);
}

@@ -476,3 +487,3 @@ if (!uniqueId) {

}
const quantity = (_c = input.quantity) !== null && _c !== void 0 ? _c : 1;
const quantity = (_b = input.quantity) !== null && _b !== void 0 ? _b : 1;
setOrderForm((prevOrderForm) => {

@@ -546,2 +557,3 @@ const updatedItems = prevOrderForm.items.slice();

mutationVariables = {
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
orderItems: itemIndexInPreviousTask > -1

@@ -555,3 +567,6 @@ ? previousTaskItems.map((prevInput, prevInputIndex) => prevInputIndex === itemIndexInPreviousTask

else {
mutationVariables = { orderItems: [{ uniqueId, quantity }] };
mutationVariables = {
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
orderItems: [{ uniqueId, quantity }],
};
}

@@ -568,2 +583,3 @@ pushLocalOrderQueue({

id,
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
}));

@@ -575,3 +591,4 @@ }, [enqueueTask, setOrderForm, updateItemsTask]);

*/
const addItem = useCallback((items, marketingData, salesChannel) => {
const addItems = useCallback((items, options) => {
const { salesChannel, marketingData, allowedOutdatedData } = options !== null && options !== void 0 ? options : {};
const { newItems, updatedItems } = items.reduce((acc, item) => {

@@ -597,3 +614,3 @@ var _a;

if (updatedItems.length) {
updatedItems.forEach((item) => updateQuantity(item));
updatedItems.forEach((item) => updateQuantity(item, { allowedOutdatedData }));
}

@@ -609,3 +626,3 @@ if (newItems.length === 0) {

...prevOrderForm,
items: [].concat(orderFormItemsRef.current, orderFormItems),
items: [...orderFormItemsRef.current, ...orderFormItems],
totalizers: orderFormItems.reduce((totalizers, item) => {

@@ -626,2 +643,3 @@ return updateTotalizersAndValue({ totalizers, newItem: item })

salesChannel,
allowedOutdatedData,
},

@@ -635,4 +653,8 @@ orderFormItems,

salesChannel,
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
}));
}, [addItemsTask, enqueueTask, setOrderForm, updateQuantity]);
const addItem = useCallback((items, marketingData, salesChannel) => {
return addItems(items, { marketingData, salesChannel });
}, [addItems]);
const setManualPrice = useCallback((price, itemIndex) => {

@@ -644,4 +666,4 @@ const task = setManualPriceTask(price, itemIndex);

}, [enqueueTask, setManualPriceTask]);
const removeItem = useCallback((input) => updateQuantity({ ...input, quantity: 0 }), [updateQuantity]);
const value = useMemo(() => ({ addItem, updateQuantity, removeItem, setManualPrice }), [addItem, updateQuantity, removeItem, setManualPrice]);
const removeItem = useCallback((input, options) => updateQuantity({ ...input, quantity: 0 }, options), [updateQuantity]);
const value = useMemo(() => ({ addItem, addItems, updateQuantity, removeItem, setManualPrice }), [addItem, addItems, updateQuantity, removeItem, setManualPrice]);
useEffect(() => {

@@ -656,2 +678,3 @@ const localOrderQueue = getLocalOrderQueue();

salesChannel: task.variables.salesChannel,
allowedOutdatedData: task.variables.allowedOutdatedData,
}));

@@ -663,2 +686,3 @@ }

orderFormItems: task.orderFormItems,
allowedOutdatedData: task.variables.allowedOutdatedData,
id: task.id,

@@ -686,3 +710,3 @@ }));

export { createOrderItemsProvider, useOrderItems };
export { AVAILABLE, adjustForItemInput, createOrderItemsProvider, filterUndefined, isSameItem, mapToOrderFormItem, useOrderItems };
//# sourceMappingURL=index.esm.js.map
/*!
* @vtex/order-items v0.5.2
* @vtex/order-items v0.6.0
* (c) VTEX

@@ -43,2 +43,3 @@ * Released under the MIT License.

addItem: noop,
addItems: noop,
updateQuantity: noop,

@@ -112,2 +113,9 @@ removeItem: noop,

const isSameSeller = input.seller === item.seller;
/**
* If item is a gift, it should not be considered as the same item of the added one,
* otherwise buyer will not see two different products in the cart (the gift and the paid one)
*/
if (item.isGift) {
return false;
}
// input has no options

@@ -166,2 +174,3 @@ if (input.options == null) {

priceTags: [],
isGift: false,
};

@@ -177,3 +186,3 @@ };

const mutate = useMutateAddItems();
const addItemTask = React.useCallback(({ mutationInputItems, mutationInputMarketingData, orderFormItems, salesChannel, }) => ({
const addItemTask = React.useCallback(({ mutationInputItems, mutationInputMarketingData, orderFormItems, salesChannel, allowedOutdatedData, }) => ({
execute: async () => {

@@ -185,2 +194,3 @@ var _a;

salesChannel,
allowedOutdatedData,
});

@@ -279,3 +289,3 @@ if (!updatedOrderForm || ((_a = errors === null || errors === void 0 ? void 0 : errors.length) !== null && _a !== void 0 ? _a : 0) > 0) {

const mutate = useMutateUpdateQuantity();
const updateItemTask = React.useCallback(({ items, orderFormItems, id, }) => {
const updateItemTask = React.useCallback(({ items, orderFormItems, id, allowedOutdatedData, }) => {
return {

@@ -301,2 +311,3 @@ id,

}),
allowedOutdatedData,
};

@@ -482,4 +493,4 @@ const { data, errors } = await mutate(mutationVariables);

}, [orderForm.items]);
const updateQuantity = React.useCallback((input) => {
var _a, _b, _c;
const updateQuantity = React.useCallback((input, options) => {
var _a, _b;
let index;

@@ -499,3 +510,3 @@ let uniqueId = '';

if (index < 0 || index >= currentOrderFormItems.length) {
throw new Error(`Item ${(_b = input.id) !== null && _b !== void 0 ? _b : input.uniqueId} not found`);
throw new Error(`Item ${input.id || input.uniqueId} not found`);
}

@@ -505,3 +516,3 @@ if (!uniqueId) {

}
const quantity = (_c = input.quantity) !== null && _c !== void 0 ? _c : 1;
const quantity = (_b = input.quantity) !== null && _b !== void 0 ? _b : 1;
setOrderForm((prevOrderForm) => {

@@ -575,2 +586,3 @@ const updatedItems = prevOrderForm.items.slice();

mutationVariables = {
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
orderItems: itemIndexInPreviousTask > -1

@@ -584,3 +596,6 @@ ? previousTaskItems.map((prevInput, prevInputIndex) => prevInputIndex === itemIndexInPreviousTask

else {
mutationVariables = { orderItems: [{ uniqueId, quantity }] };
mutationVariables = {
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
orderItems: [{ uniqueId, quantity }],
};
}

@@ -597,2 +612,3 @@ pushLocalOrderQueue({

id,
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
}));

@@ -604,3 +620,4 @@ }, [enqueueTask, setOrderForm, updateItemsTask]);

*/
const addItem = React.useCallback((items, marketingData, salesChannel) => {
const addItems = React.useCallback((items, options) => {
const { salesChannel, marketingData, allowedOutdatedData } = options !== null && options !== void 0 ? options : {};
const { newItems, updatedItems } = items.reduce((acc, item) => {

@@ -626,3 +643,3 @@ var _a;

if (updatedItems.length) {
updatedItems.forEach((item) => updateQuantity(item));
updatedItems.forEach((item) => updateQuantity(item, { allowedOutdatedData }));
}

@@ -638,3 +655,3 @@ if (newItems.length === 0) {

...prevOrderForm,
items: [].concat(orderFormItemsRef.current, orderFormItems),
items: [...orderFormItemsRef.current, ...orderFormItems],
totalizers: orderFormItems.reduce((totalizers, item) => {

@@ -655,2 +672,3 @@ return updateTotalizersAndValue({ totalizers, newItem: item })

salesChannel,
allowedOutdatedData,
},

@@ -664,4 +682,8 @@ orderFormItems,

salesChannel,
allowedOutdatedData: options === null || options === void 0 ? void 0 : options.allowedOutdatedData,
}));
}, [addItemsTask, enqueueTask, setOrderForm, updateQuantity]);
const addItem = React.useCallback((items, marketingData, salesChannel) => {
return addItems(items, { marketingData, salesChannel });
}, [addItems]);
const setManualPrice = React.useCallback((price, itemIndex) => {

@@ -673,4 +695,4 @@ const task = setManualPriceTask(price, itemIndex);

}, [enqueueTask, setManualPriceTask]);
const removeItem = React.useCallback((input) => updateQuantity({ ...input, quantity: 0 }), [updateQuantity]);
const value = React.useMemo(() => ({ addItem, updateQuantity, removeItem, setManualPrice }), [addItem, updateQuantity, removeItem, setManualPrice]);
const removeItem = React.useCallback((input, options) => updateQuantity({ ...input, quantity: 0 }, options), [updateQuantity]);
const value = React.useMemo(() => ({ addItem, addItems, updateQuantity, removeItem, setManualPrice }), [addItem, addItems, updateQuantity, removeItem, setManualPrice]);
React.useEffect(() => {

@@ -685,2 +707,3 @@ const localOrderQueue = getLocalOrderQueue();

salesChannel: task.variables.salesChannel,
allowedOutdatedData: task.variables.allowedOutdatedData,
}));

@@ -692,2 +715,3 @@ }

orderFormItems: task.orderFormItems,
allowedOutdatedData: task.variables.allowedOutdatedData,
id: task.id,

@@ -715,4 +739,9 @@ }));

exports.AVAILABLE = AVAILABLE;
exports.adjustForItemInput = adjustForItemInput;
exports.createOrderItemsProvider = createOrderItemsProvider;
exports.filterUndefined = filterUndefined;
exports.isSameItem = isSameItem;
exports.mapToOrderFormItem = mapToOrderFormItem;
exports.useOrderItems = useOrderItems;
//# sourceMappingURL=index.js.map
{
"name": "@vtex/order-items",
"version": "0.5.2",
"version": "0.6.0",
"description": "",

@@ -5,0 +5,0 @@ "cdn": "dist/index.umd.js",

@@ -11,2 +11,3 @@ import type { Item, OrderFormItemInput, MarketingData } from '../typings'

orderItems: UpdateQuantityInput[]
allowedOutdatedData?: string[]
}

@@ -18,2 +19,3 @@

salesChannel?: string
allowedOutdatedData?: string[]
}

@@ -20,0 +22,0 @@

@@ -54,2 +54,3 @@ import type { OrderForm as BaseOrderForm } from '@vtex/order-manager'

index?: number
isGift: boolean
}

@@ -140,2 +141,3 @@

orderItems: UpdateQuantityInput[]
allowedOutdatedData?: string[]
}

@@ -142,0 +144,0 @@

@@ -22,2 +22,10 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

/**
* If item is a gift, it should not be considered as the same item of the added one,
* otherwise buyer will not see two different products in the cart (the gift and the paid one)
*/
if (item.isGift) {
return false
}
// input has no options

@@ -90,2 +98,3 @@ if (input.options == null) {

priceTags: [],
isGift: false,
}

@@ -92,0 +101,0 @@ }

export { createOrderItemsProvider } from './createOrderItems';
export { useOrderItems } from './modules/OrderItemsContext';
export { AVAILABLE, isSameItem, filterUndefined, adjustForItemInput, mapToOrderFormItem, } from './utils';
//# sourceMappingURL=index.d.ts.map

@@ -13,3 +13,3 @@ import type { OrderFormContext } from '@vtex/order-manager';

}
export declare function createUseAddItems<O extends OrderForm>({ useMutateAddItems, useOrderForm, }: CreateAddItemsParams<O>): (fakeUniqueIdMapRef: React.MutableRefObject<FakeUniqueIdMap>) => ({ mutationInputItems, mutationInputMarketingData, orderFormItems, salesChannel, }: {
export declare function createUseAddItems<O extends OrderForm>({ useMutateAddItems, useOrderForm, }: CreateAddItemsParams<O>): (fakeUniqueIdMapRef: React.MutableRefObject<FakeUniqueIdMap>) => ({ mutationInputItems, mutationInputMarketingData, orderFormItems, salesChannel, allowedOutdatedData, }: {
mutationInputItems: OrderFormItemInput[];

@@ -19,2 +19,3 @@ mutationInputMarketingData?: Partial<MarketingData> | undefined;

salesChannel?: string | undefined;
allowedOutdatedData?: string[] | undefined;
}) => {

@@ -21,0 +22,0 @@ execute: () => Promise<O>;

@@ -14,6 +14,7 @@ import type { OrderFormContext } from '@vtex/order-manager';

}
export declare function createUseUpdateQuantity<O extends OrderForm>({ useMutateUpdateQuantity, useOrderForm, }: CreateUseUpdateQuantityParams<O>): (fakeUniqueIdMapRef: React.MutableRefObject<FakeUniqueIdMap>) => ({ items, orderFormItems, id, }: {
export declare function createUseUpdateQuantity<O extends OrderForm>({ useMutateUpdateQuantity, useOrderForm, }: CreateUseUpdateQuantityParams<O>): (fakeUniqueIdMapRef: React.MutableRefObject<FakeUniqueIdMap>) => ({ items, orderFormItems, id, allowedOutdatedData, }: {
items: UpdateQuantityInput[];
orderFormItems: Item[];
id: string;
allowedOutdatedData?: string[] | undefined;
}) => {

@@ -20,0 +21,0 @@ id: string;

@@ -12,2 +12,3 @@ import type { Item, OrderFormItemInput, MarketingData } from '../typings';

orderItems: UpdateQuantityInput[];
allowedOutdatedData?: string[];
}

@@ -18,2 +19,3 @@ export interface AddItemsMutationVariables {

salesChannel?: string;
allowedOutdatedData?: string[];
}

@@ -20,0 +22,0 @@ declare type LocalOrderTask = {

/// <reference types="react" />
import type { AssemblyOptionInput, ItemAdditionalInfo, MarketingData, SKUSpecification } from '../typings';
export interface Context {
/**
* @deprecated Use `addItems` instead
*/
addItem: AddItemFn;
addItems: AddItemsFn;
updateQuantity: UpdateQuantityFn;

@@ -31,2 +35,8 @@ removeItem: RemoveItemFn;

};
export declare type AddItemsOptions = {
marketingData?: Partial<MarketingData>;
salesChannel?: string;
allowedOutdatedData?: string[];
};
export declare type AddItemsFn = (items: AddItemItemParam[], options?: AddItemsOptions) => void;
export declare type AddItemFn = (items: AddItemItemParam[], marketingData?: Partial<MarketingData>, salesChannel?: string) => void;

@@ -53,7 +63,10 @@ interface ItemIdentificationById {

} & ItemIdentification;
export declare type UpdateQuantityFn = (item: UpdateQuantityItemParam) => void;
export declare type UpdateQuantityOptions = {
allowedOutdatedData?: string[];
};
export declare type UpdateQuantityFn = (item: UpdateQuantityItemParam, options?: UpdateQuantityOptions) => void;
declare type RemoveItemParam = {
seller: string;
} & ItemIdentification;
export declare type RemoveItemFn = (input: RemoveItemParam) => void;
export declare type RemoveItemFn = (input: RemoveItemParam, options?: UpdateQuantityOptions) => void;
export declare type SetManualPriceFn = (price: number, itemIndex: number) => void;

@@ -60,0 +73,0 @@ export declare const OrderItemsContext: import("react").Context<Context>;

@@ -49,2 +49,3 @@ import type { OrderForm as BaseOrderForm } from '@vtex/order-manager';

index?: number;
isGift: boolean;
}

@@ -128,2 +129,3 @@ export interface MarketingData {

orderItems: UpdateQuantityInput[];
allowedOutdatedData?: string[];
}

@@ -130,0 +132,0 @@ export interface FakeUniqueIdMap {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc