New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vtex/delivery-packages

Package Overview
Dependencies
Maintainers
25
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vtex/delivery-packages

> Small library to separate items in parcels

  • 2.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
426
decreased by-23.93%
Maintainers
25
Weekly downloads
 
Created
Source

delivery-packages

Small library to separate items in parcels

Motivation

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:

  1. Seller
  2. SLAs options
  3. Selected SLA ID
  4. Selected SLA Shipping Estimate
  5. Selected SLA Delivery Channel
  6. Packages already delivered (post purchase scenario)

This module provides a consistent way to handle all those criteria.

Install

$ npm install @vtex/delivery-packages

Usage

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],
//       ...
//     }
//   }
// ]

API

parcelify(order, options)

Returns an array of Parcels.

order

An order shaped like an orderForm.

options.criteria

Type: Object
Default:

{
  slaOptions: false,
  selectedSla: true,
  seller: true,
  shippingEstimate: true,
  deliveryChannel: true
}

This param will be merged with the default options.

Parcel

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]
}
address

The address used for that parcel. If it is a pickup point, the address of the pickup point is returned.

pickupFriendlyName

If the parcel is delivered to a pickup point, this field has its friendly name.

items

The items of the parcel.

seller

The seller of the parcel.

package

The package object from packageAttachment, if it is one.

slas, selectedSla, shippingEstimate, shippingEstimateDate, deliveryChannel, deliveryIds

These properties are taken from the logisticsInfo of the parcel.

Example

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"
//   }
// ]

License

MIT © VTEX

Keywords

FAQs

Package last updated on 07 May 2018

Did you know?

Socket

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.

Install

Related posts

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