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

@vtex/lean-shipping-calculator

Package Overview
Dependencies
Maintainers
53
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vtex/lean-shipping-calculator

> Utilities library to for VTEX lean shipping options

  • 0.2.15
  • npm
  • Socket score

Version published
Weekly downloads
20
Maintainers
53
Weekly downloads
 
Created
Source

lean-shipping-calculator

Utilities library to for VTEX lean shipping options

Documentation

Install

$ npm install @vtex/lean-shipping-calculator -S

API

getLeanShippingOptions({ logisticsInfo, activeChannel, isScheduledDeliveryActive })

Returns lean shipping options (cheapest, fastest and combined)

logisticsInfo

Type: Array

Logistics info for each item

activeChannel

Type: String
Default: delivery

Active channel

isScheduledDeliveryActive

Type: boolean
Default: false


getOptionsDetails(delivery)

Get more details about each lean option

delivery

Type: Object

Lean shipping options


getSelectedDeliveryOption

Get lean shipping option that is current selected

delivery

Type: Object

Object with lean shipping options


Usage

getLeanShippingOptions

Return all options are only returned if they are worthy according to the calculation.

const leanShippingCalculator = require('@vtex/lean-shipping-calculator')

const options = leanShippingCalculator.getLeanShippingOptions({
  logisticsInfo,
  activeChannel,
})

console.log(options)
// {
//   cheapest: [{item1}, {item2}],
//   fastest:  [{item1}, {item2}],
//   combined: [{item1}, {item2}]
// }

An example of the function returning only cheapest option:

console.log(options)
// {
//   cheapest: [{item1}, {item2}]
// }

getOptionsDetails

Returns more details about each lean shipping option

const leanShippingCalculator = require('@vtex/lean-shipping-calculator')

const optionDetails = leanShippingCalculator.getOptionsDetails({
  [CHEAPEST]: cheapestOption,
  [COMBINED]: combinedOption,
  [FASTEST]: fastestOption,
})

console.log(optionDetails)
// [
//   {
//     averageEstimatePerItem: 520200,
//     id: 'CHEAPEST',
//     packagesLength: 2,
//     price: 1000,
//     shippingEstimate: '8bd',
//   },
//   {
//     averageEstimatePerItem: 220200,
//     id: 'COMBINED',
//     packagesLength: 2,
//     price: 3000,
//     shippingEstimate: '2bd',
//   },
//   {
//     averageEstimatePerItem: 300200,
//     id: 'FASTEST',
//     packagesLength: 2,
//     price: 1500,
//     shippingEstimate: '5bd',
//   }
// ]

getSelectedDeliveryOption

Returns the selected lean options

const leanShippingCalculator = require('@vtex/lean-shipping-calculator')

const optionToBeSelected = leanShippingCalculator.getSelectedDeliveryOption({
  optionsDetails = null,
  newCombined,
  newFastest,
  newCheapest,
  activeDeliveryOption,
})

console.log(optionToBeSelected) // CHEAPEST

FAQs

Package last updated on 05 Jul 2022

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