![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@vtex/delivery-packages
Advanced tools
> Library of functions that help to separate items in parcels and select delivery items on UIs
Library of functions that help to separate items in parcels and select delivery items on UIs
The UX of displaying to the user how their items are going to be delivered can be tricky to be expressed and developed.
There are many criteria to split items in different parcels. They are:
This module provides a consistent way to handle all those criteria.
And provide also helper functions for other use cases.
$ npm install @vtex/delivery-packages
const parcelify = require('@vtex/delivery-packages')
parcelify(order)
// [
// {
// "seller": "1",
// "pickupFriendlyName": null,
// "selectedSla": "Normal",
// "slas": [
// {
// "id": "Normal",
// "deliveryChannel": "delivery",
// ...
// }
// ],
// "shippingEstimate": "6bd",
// "shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
// "deliveryChannel": "delivery",
// "items": [
// {
// "index": 0,
// "id": 0,
// "quantity": 1,
// "seller": "1",
// ...
// }
// ],
// "address": {
// "addressId": "-4556418741084",
// "addressType": "residential",
// "receiverName": "John Doe",
// ...
// }
// },
// {
// "seller": "2",
// "pickupFriendlyName": "Shopping da Gávea",
// "selectedSla": "Retirada na loja (17c6a89)",
// "slas": [
// {
// "id": "Retirada na loja (17c6a89)",
// "deliveryChannel": "pickup-in-point",
// ...
// }
// ],
// "shippingEstimate": "5h",
// "shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00",
// "deliveryChannel": "pickup-in-point",
// "items": [
// {
// "id": 1,
// "quantity": 1,
// "seller": "2",
// "index": 1
// }
// ],
// "address": {
// "addressId": "141125d",
// "addressType": "pickup",
// "geoCoordinates": [-43.18080139160156, -22.96540069580078],
// ...
// }
// }
// ]
Returns an array of Parcels.
An order shaped like an orderForm.
Type: Object
Default:
{
groupByAvailableDeliveryWindows: false,
slaOptions: false,
selectedSla: true,
seller: true,
shippingEstimate: true,
deliveryChannel: true
}
This param will be merged with the default options.
A Parcel object shape
{
address: Object,
pickupFriendlyName: String,
seller: String,
items: [Object],
package: Object,
selectedSla: String,
slas: [Object],
shippingEstimate: String,
shippingEstimateDate: String,
deliveryChannel: String,
deliveryIds: [Object]
}
The address
used for that parcel. If it is a pickup point, the address of the pickup point is returned.
If the parcel is delivered to a pickup point, this field has its friendly name.
The items of the parcel.
The seller of the parcel.
The package
object from packageAttachment
, if it is one.
These properties are taken from the logisticsInfo
of the parcel.
const order = {
items: [
// You can pass all the properties of the item. That's simplified.
{ "id": 0, "quantity": 1, "seller": "1" },
{ "id": 1, "quantity": 1, "seller": "1" }
],
shippingData: {
selectedAddresses: [
{ "addressId": "-4556418741084", "street": "Rua Barão" }
],
logisticsInfo: [
{
// You can pass all the properties of the logisticInfo
"addressId": "-4556418741084",
"selectedSla": "Expressa",
"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": "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" }
]
}
]
},
packageAttachment: {
packages: [
{
// You can pass all the properties of tha package.
"courierStatus": { "finished": false },
"trackingNumber": "123",
"trackingUrl": "",
"invoiceNumber": "456",
"items": [
{ "itemIndex": 0, "quantity": 1 }
]
}
]
}
}
parcelify(order, { criteria: { seller: false } })
// [
// {
// "package": {
// "courierStatus": { "finished": false },
// "trackingNumber": "123",
// "trackingUrl": "",
// "invoiceNumber": "456",
// "items": [
// { "itemIndex": 0, "quantity": 1 }
// ],
// "index": 0
// },
// "address": { "addressId": "-4556418741084", "street": "Rua Barão" },
// "pickupFriendlyName": null,
// "selectedSla": "Expressa",
// "slas": [{ "id": "Expressa", "deliveryChannel": "delivery" }],
// "shippingEstimate": "5bd",
// "shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00",
// "deliveryChannel": "delivery",
// "items": [
// { "id": 0, "quantity": 1, "seller": "1", "index": 0 }
// ],
// "seller": "1"
// },
// {
// "address": { "addressId": "-4556418741084", "street": "Rua Barão" },
// "pickupFriendlyName": null,
// "selectedSla": "Normal",
// "slas": [{ "id": "Normal", "deliveryChannel": "delivery" }],
// "shippingEstimate": "6bd",
// "shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
// "deliveryChannel": "delivery",
// "items": [
// { "id": 1, "quantity": 1, "seller": "1", "index": 1 }
// ],
// "seller": "1"
// }
// ]
This module provide a lot of helper functions besides parcelify, that are worth checking below.
@vtex/delivery-packages/delivery-channel
Get the delivery channel string of a delivery channel source.
const { getDeliveryChannel } = require('@vtex/delivery-packages/delivery-channel')
getDeliveryChannel({ id: 'pickup-in-point'})
// -> 'pickup-in-point'
params:
object
or string
An object containing a deliveryChannel string or the string itselfreturns:
string
The deliveryChannel string (generally 'pickup-in-point' or 'delivery')Check if the delivery channel source is a pickup point.
const { isPickup } = require('@vtex/delivery-packages/delivery-channel')
isPickup({ id: 'pickup-in-point'})
// -> true
isPickup({ selectedDeliveryChannel: 'pickup-in-point' })
// true
isPickup({ deliveryChannel: 'pickup-in-point' })
// true
isPickup({ id: 'delivery'})
// -> false
params:
object
or string
An object containing a deliveryChannel string or the string itselfreturns:
boolean
true or falseCheck if the delivery channel source is a delivery.
const { isDelivery } = require('@vtex/delivery-packages/delivery-channel')
isDelivery({ id: 'pickup-in-point'})
// -> false
isDelivery({ selectedDeliveryChannel: 'delivery' })
// true
isDelivery({ deliveryChannel: 'delivery' })
// true
isDelivery({ id: 'delivery'})
// -> true
params:
object
or string
An object containing a deliveryChannel string or the string itselfreturns:
boolean
true or falseSearch for a delivery channel object from an object container a list of delivery channel objects (usually it will be a logisticInfo item).
const { findChannelById } = require('@vtex/delivery-packages/delivery-channel')
findChannelById({ deliveryChannels: [{ id: 'delivery' }] }, 'pickup-in-point')
// -> null
findChannelById({ deliveryChannels: [{ id: 'delivery' }, { id: 'pickup-in-point' }] }, 'delivery')
// -> { id: 'delivery' }
params:
object
An object containing a deliveryChannels arrayobject
or string
An object containing a deliveryChannel string or the string itselfreturns:
object
Object like { id: 'delivery' }
or { id: 'pickup-in-point' }
@vtex/delivery-packages/items
Get new items based on the ones passed and an array of changes.
const { getNewItems } = require('@vtex/delivery-packages/items')
const items = [
{ id: 10, quantity: 1, seller: '1' },
{ id: 11, quantity: 1, seller: '1' },
]
const changes = [
{ itemsAdded: [{ id: 12, quantity: 1, seller: '1' }] },
{ itemsRemoved: [{ id: 11, quantity: 1, seller: '1' }] },
]
getNewItems(items, changes)
// -> [{ id: 10, quantity: 1, seller: '1' }, { id: 12, quantity: 1, seller: '1'}]
params:
items
Type: Array<object>
Array of items (like the ones in an orderForm)
changes
Type: Array<object>
Array of changes, each change on the format { itemsAdded: Array<item>, itemsRemoved: Array<item> }
returns:
Array<object>
New array of items with the changes appliedMerge items with packages and organize them based if they were already delivered or will be delivered.
const { getDeliveredItems } = require('@vtex/delivery-packages/items')
const items = [
{ id: 10, quantity: 1, seller: '1', index: 0 },
{ id: 11, quantity: 1, seller: '1', index: 1 },
]
const packages = [
{
courierStatus: { finished: false },
index: 0,
invoiceNumber: '456',
items: [
{ itemIndex: 0, quantity: 1 },
{ itemIndex: 1, quantity: 1 },
],
trackingNumber: '123',
trackingUrl: '',
},
]
getDeliveredItems({ items, packages })
// -> {
// delivered: [
// {
// item: { id: '10', index: 0, quantity: 1, seller: '1' },
// package: {
// courierStatus: { finished: false },
// index: 0,
// invoiceNumber: '456',
// items: [{ itemIndex: 0, quantity: 1 }, { itemIndex: 1, quantity: 1 }],
// trackingNumber: '123',
// trackingUrl: '',
// },
// },
// ],
// toBeDelivered: [{ item: { id: '1', index: 1, quantity: 1, seller: '1' } }],
// }
params:
object
Object on the format { items, packages }
containing the items and packages of an order, with the index of each item and packagereturns:
object
Object contained the keys delivered and toBeDelivered containing the right items and packages@vtex/delivery-packages/scheduled-delivery
Check if two available delivery windows are equal.
const { areAvailableDeliveryWindowsEquals } = require('@vtex/delivery-packages/scheduled-delivery')
const availableDeliveryWindows1 = [
{
startDateUtc: '2018-05-26T09:00:00+00:00',
endDateUtc: '2018-05-26T21:00:00+00:00',
price: 500,
lisPrice: 500,
tax: 0,
}
]
const availableDeliveryWindows2 = [
{
startDateUtc: '2018-05-26T09:00:00+00:00',
endDateUtc: '2018-05-26T21:00:00+00:00',
price: 500,
lisPrice: 500,
tax: 0,
}
]
const availableDeliveryWindows3 = [
{
startDateUtc: '2018-06-20T09:00:00+00:00',
endDateUtc: '2018-06-20T21:00:00+00:00',
price: 500,
lisPrice: 500,
tax: 0,
}
]
areAvailableDeliveryWindowsEquals(availableDeliveryWindows1, availableDeliveryWindows2)
// -> true
areAvailableDeliveryWindowsEquals(availableDeliveryWindows1, availableDeliveryWindows3)
// -> false
params:
availableDeliveryWindows1
Type: Array<object>
Array of objects, each object with startDateUtc
, endDateUtc
, price
, lisPrice
and tax
properties (like inside logisticInfo[i].slas that have scheduled deliveries)
availableDeliveryWindows2
Type: Array<object>
Array of objects, each object with startDateUtc
, endDateUtc
, price
, lisPrice
and tax
properties (like inside logisticInfo[i].slas that have scheduled deliveries)
returns:
boolean
true or falseGet new logisticInfo with the deliveryWindow of the selectedSla inserted.
const { selectDeliveryWindow } = require('@vtex/delivery-packages/scheduled-delivery')
const logisticsInfo = [
{
// You can pass all the properties of the logisticInfo
"addressId": "-4556418741084",
"selectedSla": "Agendada",
"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": "Normal",
"shippingEstimate": "6bd",
"shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
"deliveryChannel": "delivery",
"itemIndex": 1,
"slas": [
{ "id": "Normal", "deliveryChannel": "delivery" }
]
}
]
selectDeliveryWindow(logisticsInfo, {
selectedSla: 'Agendada',
deliveryWindow: {
startDateUtc: '2018-05-26T09:00:00+00:00',
endDateUtc: '2018-05-26T21:00:00+00:00',
price: 500,
lisPrice: 500,
tax: 0,
},
})
// -> [
// {
// // You can pass all the properties of the logisticInfo
// "addressId": "-4556418741084",
// "selectedSla": "Agendada",
// "shippingEstimate": "5bd",
// "shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00",
// "deliveryChannel": "delivery",
// "itemIndex": 0,
// "deliveryWindow": {
// startDateUtc: '2018-05-26T09:00:00+00:00',
// endDateUtc: '2018-05-26T21: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-26T09:00:00+00:00',
// endDateUtc: '2018-05-26T21: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": "Normal",
// "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
action
Type: object
Object on the format { selectedSla, deliveryWindow }
, selectedSla being a string with the id of the selectedSla of each logisticInfo item and deliveryWindow being an object of the availableDeliveryWindows on these items
returns:
Array<object>
The new logisticInfo with the deliveryWindow selected on the matching items that have the selectedSla passedGet the first sla with scheduled delivery matching the availableDeliveryWindows passed.
const { getFirstScheduledDelivery } = require('@vtex/delivery-packages/scheduled-delivery')
const logisticsInfo = [
{
// You can pass all the properties of the logisticInfo
"addressId": "-4556418741084",
"selectedSla": "Agendada",
"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": "Normal",
"shippingEstimate": "6bd",
"shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
"deliveryChannel": "delivery",
"itemIndex": 1,
"slas": [
{ "id": "Normal", "deliveryChannel": "delivery" }
]
}
]
getFirstScheduledDelivery(logisticsInfo, [
{
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,
}
])
// ->
// {
// "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,
// }
// ]
// }
params:
logisticsInfo
Type: Array<object>
The logisticInfo like the one inside orderForm
with selectedSla
and slas
availableDeliveryWindows1
Type: Array<object>
Array of objects, each object with startDateUtc
, endDateUtc
, price
, lisPrice
and tax
properties (like inside logisticInfo[i].slas that have scheduled deliveries). The default value for this parameter is null
returns:
object
If availableDeliveryWindows is passed, return the first sla with scheduled delivery matching the availableDeliveryWindows. If availableDeliveryWindows is not passed, return the first scheduled delivery sla that exists@vtex/delivery-packages/shipping
Get new logisticInfo with the selectedSla on all items that can receive it as selected.
const { getNewLogisticsInfo } = require('@vtex/delivery-packages/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" }
]
}
]
getNewLogisticsInfo(logisticsInfo, 'Normal')
// -> [
// {
// // 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": "Normal",
// "selectedDeliveryChannel": "delivery",
// "shippingEstimate": "6bd",
// "shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
// "deliveryChannel": "delivery",
// "itemIndex": 1,
// "slas": [
// { "id": "Normal", "deliveryChannel": "delivery" }
// ]
// }
// ]
getNewLogisticsInfo(logisticsInfo, 'Agendada', [
{
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,
}
])
// -> [
// {
// // 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,
// "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" }
// ]
// }
// ]
params:
logisticsInfo
Type: Array<object>
The logisticInfo like the one inside orderForm
with selectedSla
and slas
selectedSla
Type: string
The id of the selected sla on logisticInfo items
availableDeliveryWindows
Type: Array<object>
Array of objects, each object with startDateUtc
, endDateUtc
, price
, lisPrice
and tax
properties (like inside logisticInfo[i].slas that have scheduled deliveries). The default value for this parameter is null
returns:
Array<object>
New logisticInfo with selectedSla and selectedDeliveryChannel filled correctly on each item with slas that can be selected. Optionally the availableDeliveryWindows can be passed to filter the scheduled delivery slasGet new logisticInfo selecting first sla that has availableDeliveryWindows on each item that can be scheduled delivered.
const { getNewLogisticsInfoWithSelectedScheduled } = require('@vtex/delivery-packages/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" }
]
}
]
getNewLogisticsInfoWithSelectedScheduled(logisticsInfo)
// -> [
// {
// // 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,
// "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" }
// ]
// }
// ]
params:
Array<object>
The logisticInfo like the one inside orderForm
with selectedSla
and slas
returns:
Array<object>
New logisticInfo with selectedSla and selectedDeliveryChannel filled correctly on each item with slas that has availableDeliveryWindows@vtex/delivery-packages/sla
Check if the object or array passed have one or more slas
const { hasSLAs } = require('@vtex/delivery-packages/sla')
hasSLAs({
slas: [{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }],
})
// -> true
hasSLAs([{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }],)
// -> true
hasSLAs({ slas: [] })
// -> false
params:
object
or Array<object>
Object with slas key or array of objectsreturns:
boolean
true or falseCheck if the object or array passed have at least of sla that can be scheduled delivered.
const { hasDeliveryWindows } = require('@vtex/delivery-packages/sla')
hasDeliveryWindows([
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
])
// -> false
hasDeliveryWindows([
{
"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,
}
]
},
{ "id": "Expressa", "deliveryChannel": "delivery" }
])
// -> true
hasDeliveryWindows({
"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,
}
]
})
// -> true
params:
object
or Array<object>
Object with a single sla or an array of slasreturns:
boolean
true or falseGet the sla object on slas that match the slaId passed.
const { getSlaObj } = require('@vtex/delivery-packages/sla')
getSlaObj([
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
], 'Normal')
// -> { "id": "Normal", "deliveryChannel": "delivery" }
getSlaObj([
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
], 'Agendada')
// -> null
params:
slas
Type: Array<object>
An array of slas
slaId
Type: string
The id of a sla of the list passed
returns:
object
the sla object on the array that match the slaId passed or null if it doesn't find itGet the select sla object on logisticInfo at the itemIndex position and optionally passing another selectedSla as reference.
const { getSelectedSla } = require('@vtex/delivery-packages/sla')
getSelectedSla({
logisticInfo: [
{
// other logisticInfo properties can be passed also
selectedSla: 'Normal',
slas: [
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
]
},
{
// other logisticInfo properties can be passed also
selectedSla: 'Expressa',
slas: [
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
]
}
],
itemIndex: 0,
})
// -> { "id": "Normal", "deliveryChannel": "delivery" }
getSelectedSla({
logisticInfo: [
{
// other logisticInfo properties can be passed also
selectedSla: 'Normal',
slas: [
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
]
},
{
// other logisticInfo properties can be passed also
selectedSla: 'Expressa',
slas: [
{ "id": "Normal", "deliveryChannel": "delivery" }, { "id": "Expressa", "deliveryChannel": "delivery" }
]
}
],
itemIndex: 1,
selectedSla: 'Normal',
})
// -> { "id": "Normal", "deliveryChannel": "delivery" }
params:
object
Object on the format {logisticsInfo, itemIndex, selectedSla}
with logisticsInfo being an object like the one inside an orderForm, itemIndex a number referring the position of a logisticInfo item and selectedSla an optional string with the id of the wanted slareturns:
object
the selectedSla object on the logisticsInfo item that itemIndex refer and optionally using another selectedSla then the one on logisticsInfo itemMIT © VTEX
FAQs
> Library of functions that help to separate items in parcels and select delivery items on UIs
The npm package @vtex/delivery-packages receives a total of 418 weekly downloads. As such, @vtex/delivery-packages popularity was classified as not popular.
We found that @vtex/delivery-packages demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 81 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.