delivery-packages
Small library to separate items in packages
Motivation
The UX of displaying to the user how their items are going to be delivered can be tricky to be expressed and developed.
That are many criterias to split items in different packages. They are:
- Seller
- SLAs options
- Selected SLA ID
- Selected SLA Shipping Estimate
- Selected SLA Delivery Channel
- Packages already delivered (post purchase scenario)
This module provides a consistent way to handle all those criterias.
Install
$ npm install @vtex/delivery-packages
Usage
const packagify = require('@vtex/delivery-packages')
packagify({
items,
selectedAddresses,
logisticsInfo
})
API
packagify({ items, selectedAddresses, logisticsInfo, packages })
Returns an array of Packages.
items
The items
array from the order.
selectedAddresses
The selectedAddress
array from the order's shippingData
.
logisticsInfo
The logisticsInfo
array from the order's shippingData
.
packages (optional)
The packages
array from the order's packageAttachment
. This property is only available using OMS API.
Package
A Package object shape
{
address: Object,
pickupFriendlyName: String,
seller: String,
package: Object,
selectedSla: String,
slas: [Object],
shippingEstimate: String,
shippingEstimateDate: String,
deliveryChannel: String,
}
address
The address
used for that package. If it is a pickup point, the address of the pickup point is returned.
pickupFriendlyName
If the package is delivered to a pickup point, this field has its friendly name.
seller
The seller of the package.
package
The package
object from packageAttachment
, if it is one.
slas, selectedSla, shippingEstimate, shippingEstimateDate, deliveryChannel
These properties are taken from the logisticsInfo
of the package.
Example
const items = [
{ "id": 0, "quantity": 1, "seller": "1" },
{ "id": 1, "quantity": 1, "seller": "1" }
]
const selectedAddresses = [
{
"addressId": "-4556418741084",
"addressType": "residential",
"receiverName": "John Doe",
"street": "Rua Barão",
"number": "2",
"complement": null,
"neighborhood": "Botafogo",
"postalCode": "22231-100",
"city": "Rio de Janeiro",
"state": "RJ",
"country": "BRA",
"reference": null,
"geoCoordinates": []
}
]
const logisticsInfo = [
{
"addressId": "-4556418741084",
"selectedSla": "Expressa",
"shippingEstimate": "5bd",
"shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00",
"deliveryChannel": "delivery",
"itemIndex": 0,
"slas": [
{ "id": "Expressa", "deliveryChannel": "delivery" }
]
},
{
"addressId": "-4556418741084",
"selectedSla": "Normal",
"shippingEstimate": "6bd",
"shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
"deliveryChannel": "delivery",
"itemIndex": 1,
"slas": [
{ "id": "Normal", "deliveryChannel": "delivery" }
]
}
]
const packages = [
{
"courierStatus": { "finished": false },
"trackingNumber": "123",
"trackingUrl": "",
"invoiceNumber": "456",
"items": [
{ "itemIndex": 0, "quantity": 1 }
]
}
]
packagify({items, selectedAddresses, logisticsInfo, packages})
License
MIT © VTEX