@vtex/delivery-packages
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -181,2 +181,6 @@ if (!Array.prototype.find) { | ||
return logisticsInfo.map(function (li) { | ||
if (!li) { | ||
return li; | ||
} | ||
var selectedSlaId = action.selectedSla || action.slaOption; | ||
@@ -183,0 +187,0 @@ var deliveryWindow = action.deliveryWindow; |
@@ -185,2 +185,6 @@ 'use strict'; | ||
return logisticsInfo.map(function (li) { | ||
if (!li) { | ||
return li; | ||
} | ||
var selectedSlaId = action.selectedSla || action.slaOption; | ||
@@ -187,0 +191,0 @@ var deliveryWindow = action.deliveryWindow; |
@@ -74,2 +74,16 @@ if (!Array.prototype.find) { | ||
function getSelectedSlaIfMatchSlaId(item, slaId) { | ||
if (!item || !item.slas || item.slas.length === 0 || !slaId) { | ||
return null; | ||
} | ||
return item.slas.find(function (sla) { | ||
return sla.id === slaId && sla.id === item.selectedSla; | ||
}) || null; | ||
} | ||
function getSlaAsId(sla) { | ||
return sla && sla.id ? sla.id : sla; | ||
} | ||
function hasDeliveryWindows(slas) { | ||
@@ -149,2 +163,8 @@ if (!slas) { | ||
function checkIfHasDeliveryWindow(selectedSla, actionDeliveryWindow) { | ||
return selectedSla && selectedSla.availableDeliveryWindows.find(function (deliveryWindow) { | ||
return actionDeliveryWindow && areDeliveryWindowsEquals(deliveryWindow, actionDeliveryWindow); | ||
}); | ||
} | ||
function filterSlaByAvailableDeliveryWindows(sla, availableDeliveryWindows) { | ||
@@ -189,2 +209,35 @@ if (!availableDeliveryWindows) { | ||
/* action = {selectedSla, deliveryWindow} */ | ||
function selectDeliveryWindow(logisticsInfo, action) { | ||
if (!logisticsInfo || logisticsInfo.length === 0 || !action || !action.slaOption && !action.selectedSla || !action.deliveryWindow) { | ||
return null; | ||
} | ||
return logisticsInfo.map(function (li) { | ||
if (!li) { | ||
return li; | ||
} | ||
var selectedSlaId = action.selectedSla || action.slaOption; | ||
var deliveryWindow = action.deliveryWindow; | ||
var selectedSlaObj = getSelectedSlaIfMatchSlaId(li, selectedSlaId); | ||
var hasDeliveryWindow = checkIfHasDeliveryWindow(selectedSlaObj, deliveryWindow); | ||
if (selectedSlaObj && hasDeliveryWindow) { | ||
return _extends({}, li, { | ||
slas: li.slas.map(function (sla) { | ||
return _extends({}, sla, { | ||
deliveryWindow: sla.id === selectedSlaObj.id ? deliveryWindow : null | ||
}); | ||
}), | ||
deliveryWindow: deliveryWindow | ||
}); | ||
} | ||
return li; | ||
}); | ||
} | ||
function getFirstScheduledDelivery(logisticsInfo) { | ||
@@ -302,3 +355,3 @@ var availableDeliveryWindows = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
selectedSla = selectedSla && selectedSla.id ? selectedSla.id : selectedSla; | ||
selectedSla = getSlaAsId(selectedSla); | ||
@@ -310,2 +363,6 @@ if (!selectedSla || !logisticsInfo || logisticsInfo.length === 0) { | ||
return logisticsInfo.map(function (li) { | ||
if (!li) { | ||
return li; | ||
} | ||
var selectedSlaObj = getSelectedSla({ | ||
@@ -355,3 +412,31 @@ logisticsInfo: logisticsInfo, | ||
export { getLogisticsInfoData, hydratePackageWithLogisticsExtraInfo, getNewLogisticsInfo, getNewLogisticsInfoWithSelectedScheduled }; | ||
function getNewLogisticsInfoWithScheduledDeliveryChoice(logisticsInfo, scheduledDeliveryChoice) { | ||
var scheduledDeliveryItems = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
if (!logisticsInfo || logisticsInfo.length === 0 || !scheduledDeliveryChoice || !scheduledDeliveryChoice.deliveryWindow || !scheduledDeliveryChoice.selectedSla) { | ||
return null; | ||
} | ||
var deliveryWindow = scheduledDeliveryChoice.deliveryWindow; | ||
var selectedSla = getSlaAsId(scheduledDeliveryChoice.selectedSla); | ||
var indexes = scheduledDeliveryItems ? scheduledDeliveryItems.map(function (item) { | ||
return typeof item.itemIndex !== 'undefined' ? item.itemIndex : item.index; | ||
}) : null; | ||
var itemsLogisticsInfo = indexes ? logisticsInfo.map(function (li) { | ||
return indexes.indexOf(li.itemIndex) !== -1 ? li : null; | ||
}) : logisticsInfo; | ||
var newItemsLogisticsInfo = getNewLogisticsInfo(itemsLogisticsInfo, selectedSla); | ||
var newItemsLogisticsInfoWithDeliveryWindow = selectDeliveryWindow(newItemsLogisticsInfo, { selectedSla: selectedSla, deliveryWindow: deliveryWindow }); | ||
return indexes ? logisticsInfo.map(function (li) { | ||
return newItemsLogisticsInfoWithDeliveryWindow[li.itemIndex] ? newItemsLogisticsInfoWithDeliveryWindow[li.itemIndex] : li; | ||
}) : newItemsLogisticsInfoWithDeliveryWindow; | ||
} | ||
export { getLogisticsInfoData, hydratePackageWithLogisticsExtraInfo, getNewLogisticsInfo, getNewLogisticsInfoWithSelectedScheduled, getNewLogisticsInfoWithScheduledDeliveryChoice }; | ||
//# sourceMappingURL=shipping.esm.js.map |
@@ -78,2 +78,16 @@ 'use strict'; | ||
function getSelectedSlaIfMatchSlaId(item, slaId) { | ||
if (!item || !item.slas || item.slas.length === 0 || !slaId) { | ||
return null; | ||
} | ||
return item.slas.find(function (sla) { | ||
return sla.id === slaId && sla.id === item.selectedSla; | ||
}) || null; | ||
} | ||
function getSlaAsId(sla) { | ||
return sla && sla.id ? sla.id : sla; | ||
} | ||
function hasDeliveryWindows(slas) { | ||
@@ -153,2 +167,8 @@ if (!slas) { | ||
function checkIfHasDeliveryWindow(selectedSla, actionDeliveryWindow) { | ||
return selectedSla && selectedSla.availableDeliveryWindows.find(function (deliveryWindow) { | ||
return actionDeliveryWindow && areDeliveryWindowsEquals(deliveryWindow, actionDeliveryWindow); | ||
}); | ||
} | ||
function filterSlaByAvailableDeliveryWindows(sla, availableDeliveryWindows) { | ||
@@ -193,2 +213,35 @@ if (!availableDeliveryWindows) { | ||
/* action = {selectedSla, deliveryWindow} */ | ||
function selectDeliveryWindow(logisticsInfo, action) { | ||
if (!logisticsInfo || logisticsInfo.length === 0 || !action || !action.slaOption && !action.selectedSla || !action.deliveryWindow) { | ||
return null; | ||
} | ||
return logisticsInfo.map(function (li) { | ||
if (!li) { | ||
return li; | ||
} | ||
var selectedSlaId = action.selectedSla || action.slaOption; | ||
var deliveryWindow = action.deliveryWindow; | ||
var selectedSlaObj = getSelectedSlaIfMatchSlaId(li, selectedSlaId); | ||
var hasDeliveryWindow = checkIfHasDeliveryWindow(selectedSlaObj, deliveryWindow); | ||
if (selectedSlaObj && hasDeliveryWindow) { | ||
return _extends({}, li, { | ||
slas: li.slas.map(function (sla) { | ||
return _extends({}, sla, { | ||
deliveryWindow: sla.id === selectedSlaObj.id ? deliveryWindow : null | ||
}); | ||
}), | ||
deliveryWindow: deliveryWindow | ||
}); | ||
} | ||
return li; | ||
}); | ||
} | ||
function getFirstScheduledDelivery(logisticsInfo) { | ||
@@ -306,3 +359,3 @@ var availableDeliveryWindows = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
selectedSla = selectedSla && selectedSla.id ? selectedSla.id : selectedSla; | ||
selectedSla = getSlaAsId(selectedSla); | ||
@@ -314,2 +367,6 @@ if (!selectedSla || !logisticsInfo || logisticsInfo.length === 0) { | ||
return logisticsInfo.map(function (li) { | ||
if (!li) { | ||
return li; | ||
} | ||
var selectedSlaObj = getSelectedSla({ | ||
@@ -359,2 +416,30 @@ logisticsInfo: logisticsInfo, | ||
function getNewLogisticsInfoWithScheduledDeliveryChoice(logisticsInfo, scheduledDeliveryChoice) { | ||
var scheduledDeliveryItems = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
if (!logisticsInfo || logisticsInfo.length === 0 || !scheduledDeliveryChoice || !scheduledDeliveryChoice.deliveryWindow || !scheduledDeliveryChoice.selectedSla) { | ||
return null; | ||
} | ||
var deliveryWindow = scheduledDeliveryChoice.deliveryWindow; | ||
var selectedSla = getSlaAsId(scheduledDeliveryChoice.selectedSla); | ||
var indexes = scheduledDeliveryItems ? scheduledDeliveryItems.map(function (item) { | ||
return typeof item.itemIndex !== 'undefined' ? item.itemIndex : item.index; | ||
}) : null; | ||
var itemsLogisticsInfo = indexes ? logisticsInfo.map(function (li) { | ||
return indexes.indexOf(li.itemIndex) !== -1 ? li : null; | ||
}) : logisticsInfo; | ||
var newItemsLogisticsInfo = getNewLogisticsInfo(itemsLogisticsInfo, selectedSla); | ||
var newItemsLogisticsInfoWithDeliveryWindow = selectDeliveryWindow(newItemsLogisticsInfo, { selectedSla: selectedSla, deliveryWindow: deliveryWindow }); | ||
return indexes ? logisticsInfo.map(function (li) { | ||
return newItemsLogisticsInfoWithDeliveryWindow[li.itemIndex] ? newItemsLogisticsInfoWithDeliveryWindow[li.itemIndex] : li; | ||
}) : newItemsLogisticsInfoWithDeliveryWindow; | ||
} | ||
exports.getLogisticsInfoData = getLogisticsInfoData; | ||
@@ -364,2 +449,3 @@ exports.hydratePackageWithLogisticsExtraInfo = hydratePackageWithLogisticsExtraInfo; | ||
exports.getNewLogisticsInfoWithSelectedScheduled = getNewLogisticsInfoWithSelectedScheduled; | ||
exports.getNewLogisticsInfoWithScheduledDeliveryChoice = getNewLogisticsInfoWithScheduledDeliveryChoice; | ||
//# sourceMappingURL=shipping.js.map |
@@ -87,2 +87,6 @@ if (!Array.prototype.find) { | ||
function getSlaAsId(sla) { | ||
return sla && sla.id ? sla.id : sla; | ||
} | ||
/** PUBLIC **/ | ||
@@ -149,3 +153,13 @@ | ||
export { getSelectedSlaInSlas, getSelectedSlaIfMatchSlaId, findSlaWithChannel, hasSLAs, hasDeliveryWindows, getSelectedSla, getSlaObj }; | ||
function excludePickupTypeFromSlas(slas) { | ||
if (!slas || slas.length === 0) { | ||
return []; | ||
} | ||
return slas.filter(function (sla) { | ||
return !sla.pickupStoreInfo || !sla.pickupStoreInfo.isPickupStore; | ||
}); | ||
} | ||
export { getSelectedSlaInSlas, getSelectedSlaIfMatchSlaId, findSlaWithChannel, getSlaAsId, hasSLAs, hasDeliveryWindows, getSelectedSla, getSlaObj, excludePickupTypeFromSlas }; | ||
//# sourceMappingURL=sla.esm.js.map |
@@ -91,2 +91,6 @@ 'use strict'; | ||
function getSlaAsId(sla) { | ||
return sla && sla.id ? sla.id : sla; | ||
} | ||
/** PUBLIC **/ | ||
@@ -153,5 +157,16 @@ | ||
function excludePickupTypeFromSlas(slas) { | ||
if (!slas || slas.length === 0) { | ||
return []; | ||
} | ||
return slas.filter(function (sla) { | ||
return !sla.pickupStoreInfo || !sla.pickupStoreInfo.isPickupStore; | ||
}); | ||
} | ||
exports.getSelectedSlaInSlas = getSelectedSlaInSlas; | ||
exports.getSelectedSlaIfMatchSlaId = getSelectedSlaIfMatchSlaId; | ||
exports.findSlaWithChannel = findSlaWithChannel; | ||
exports.getSlaAsId = getSlaAsId; | ||
exports.hasSLAs = hasSLAs; | ||
@@ -161,2 +176,3 @@ exports.hasDeliveryWindows = hasDeliveryWindows; | ||
exports.getSlaObj = getSlaObj; | ||
exports.excludePickupTypeFromSlas = excludePickupTypeFromSlas; | ||
//# sourceMappingURL=sla.js.map |
{ | ||
"name": "@vtex/delivery-packages", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
170
README.md
@@ -1095,2 +1095,147 @@ # delivery-packages | ||
### getNewLogisticsInfoWithScheduledDeliveryChoice (logisticsInfo, scheduledDeliveryChoice, scheduledDeliveryItems = null) | ||
Get new logisticInfo selecting the sla and delivery window passed and optionally filtering by a logistics items array. | ||
##### Usage | ||
```js | ||
const { getNewLogisticsInfoWithScheduledDeliveryChoice } = require('@vtex/delivery-packages/dist/shipping') | ||
const logisticsInfo = [ | ||
{ | ||
// You can pass all the properties of the logisticInfo | ||
"addressId": "-4556418741084", | ||
"selectedSla": null, | ||
"selectedDeliveryChannel": null, | ||
"shippingEstimate": "5bd", | ||
"shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00", | ||
"deliveryChannel": "delivery", | ||
"itemIndex": 0, | ||
"slas": [ | ||
// You can pass all the properties of the sla | ||
{ | ||
"id": "Agendada", | ||
"deliveryChannel": "delivery", | ||
"availableDeliveryWindows": [ | ||
{ | ||
startDateUtc: '2018-05-26T09:00:00+00:00', | ||
endDateUtc: '2018-05-26T21:00:00+00:00', | ||
price: 500, | ||
lisPrice: 500, | ||
tax: 0, | ||
}, | ||
{ | ||
startDateUtc: '2018-05-26T12:00:00+00:00', | ||
endDateUtc: '2018-05-26T13:00:00+00:00', | ||
price: 500, | ||
lisPrice: 500, | ||
tax: 0, | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"addressId": "-4556418741084", | ||
"selectedSla": null, | ||
"selectedDeliveryChannel": null, | ||
"shippingEstimate": "6bd", | ||
"shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00", | ||
"deliveryChannel": "delivery", | ||
"itemIndex": 1, | ||
"slas": [ | ||
{ "id": "Normal", "deliveryChannel": "delivery" } | ||
] | ||
} | ||
] | ||
const deliveryWindow = { | ||
startDateUtc: '2018-05-26T12:00:00+00:00', | ||
endDateUtc: '2018-05-26T13:00:00+00:00', | ||
price: 500, | ||
lisPrice: 500, | ||
tax: 0, | ||
} | ||
getNewLogisticsInfoWithScheduledDeliveryChoice(logisticsInfo, { selectedSla: 'Agendada', deliveryWindow }, [{ itemIndex: 0 }]) | ||
// -> [ | ||
// { | ||
// // You can pass all the properties of the logisticInfo | ||
// "addressId": "-4556418741084", | ||
// "selectedSla": 'Agendada', | ||
// "selectedDeliveryChannel": 'delivery', | ||
// "shippingEstimate": "5bd", | ||
// "shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00", | ||
// "deliveryChannel": "delivery", | ||
// "itemIndex": 0, | ||
// "deliveryWindow": { | ||
// startDateUtc: '2018-05-26T12:00:00+00:00', | ||
// endDateUtc: '2018-05-26T13:00:00+00:00', | ||
// price: 500, | ||
// lisPrice: 500, | ||
// tax: 0, | ||
// }, | ||
// "slas": [ | ||
// // You can pass all the properties of the sla | ||
// { | ||
// "id": "Agendada", | ||
// "deliveryChannel": "delivery", | ||
// "deliveryWindow": { | ||
// startDateUtc: '2018-05-26T12:00:00+00:00', | ||
// endDateUtc: '2018-05-26T13:00:00+00:00', | ||
// price: 500, | ||
// lisPrice: 500, | ||
// tax: 0, | ||
// }, | ||
// "availableDeliveryWindows": [ | ||
// { | ||
// startDateUtc: '2018-05-26T09:00:00+00:00', | ||
// endDateUtc: '2018-05-26T21:00:00+00:00', | ||
// price: 500, | ||
// lisPrice: 500, | ||
// tax: 0, | ||
// }, | ||
// { | ||
// startDateUtc: '2018-05-26T12:00:00+00:00', | ||
// endDateUtc: '2018-05-26T13:00:00+00:00', | ||
// price: 500, | ||
// lisPrice: 500, | ||
// tax: 0, | ||
// } | ||
// ] | ||
// } | ||
// ] | ||
// }, | ||
// { | ||
// "addressId": "-4556418741084", | ||
// "selectedSla": null, | ||
// "selectedDeliveryChannel": null, | ||
// "shippingEstimate": "6bd", | ||
// "shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00", | ||
// "deliveryChannel": "delivery", | ||
// "itemIndex": 1, | ||
// "slas": [ | ||
// { "id": "Normal", "deliveryChannel": "delivery" } | ||
// ] | ||
// } | ||
// ] | ||
``` | ||
**params:** | ||
- **logisticsInfo** | ||
Type: `Array<object>` | ||
The logisticInfo like the one inside `orderForm` with `selectedSla` and `slas` | ||
- **scheduledDeliveryChoice** | ||
Type: `object` | ||
An object like `{ selectedSla, deliveryWindow }` saying what sla and deliveryWindow to choose the delivery | ||
- **scheduledDeliveryItems** | ||
Type: `Array<object>` | ||
An array of objects, each like `{ itemIndex: number }` or `{ index: number }` so that you can filter what items should change their selected sla and delivery window | ||
**returns:** | ||
- **new logisticInfo** | ||
Type: `Array<object>` | ||
New logisticInfo with selectedSla, selectedDeliveryChannel and deliveryWindow filled correctly according to the params | ||
## SLA | ||
@@ -1188,2 +1333,27 @@ > @vtex/delivery-packages/dist/sla | ||
### excludePickupTypeFromSlas (slas) | ||
Return only delivery slas from a list of slas passed. | ||
##### Usage | ||
```js | ||
const { excludePickupTypeFromSlas } = require('@vtex/delivery-packages/dist/sla') | ||
excludePickupTypeFromSlas([ | ||
{ "id": "Normal", "deliveryChannel": "delivery" }, | ||
{ "id": "Pickup", "deliveryChannel": "delivery", pickupStoreInfo: { isPickupStore: true, friendlyName: 'Shopping da Gávea' }, } | ||
]) | ||
// -> [ { "id": "Normal", "deliveryChannel": "delivery" } ] | ||
``` | ||
**params:** | ||
- **slas** | ||
Type: `Array<object>` | ||
An array of slas | ||
**returns:** | ||
- **delivery slas** | ||
Type: `Array<object>` | ||
An array with only the delivery slas (no pickup point sla) | ||
### getSlaObj (slas, slaId) | ||
@@ -1190,0 +1360,0 @@ |
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
1544216
15473
1455