{"id":21835783,"url":"https://github.com/vtex/lean-shipping-calculator","last_synced_at":"2025-04-14T09:15:46.179Z","repository":{"id":33845332,"uuid":"137247210","full_name":"vtex/lean-shipping-calculator","owner":"vtex","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-20T13:25:27.000Z","size":701,"stargazers_count":5,"open_issues_count":8,"forks_count":1,"subscribers_count":143,"default_branch":"main","last_synced_at":"2025-04-14T09:15:26.546Z","etag":null,"topics":["srv-checkout-ui","xp-shopping"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vtex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-13T17:10:16.000Z","updated_at":"2025-02-27T18:18:40.000Z","dependencies_parsed_at":"2024-05-16T16:28:45.977Z","dependency_job_id":"8fc0bdac-d02e-4ec4-884d-1bcdef073164","html_url":"https://github.com/vtex/lean-shipping-calculator","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Flean-shipping-calculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Flean-shipping-calculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Flean-shipping-calculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vtex%2Flean-shipping-calculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vtex","download_url":"https://codeload.github.com/vtex/lean-shipping-calculator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852185,"owners_count":21171843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["srv-checkout-ui","xp-shopping"],"created_at":"2024-11-27T20:24:41.662Z","updated_at":"2025-04-14T09:15:46.159Z","avatar_url":"https://github.com/vtex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lean-shipping-calculator\n\n\u003e Utilities library to for VTEX lean shipping options\n\n[Documentation](https://docs.google.com/document/d/1tDhV1ZOhHhwRYXRGcYmsLvNjsc2pzfQGHKePV68BEKg)\n\n## Install\n\n```sh\n$ npm install @vtex/lean-shipping-calculator -S\n```\n\n---\n\n## API\n\n### getLeanShippingOptions({ logisticsInfo, activeChannel, isScheduledDeliveryActive })\n\nReturns lean shipping options (cheapest, fastest and combined)\n\n#### logisticsInfo\n\nType: `Array`\n\nLogistics info for each item\n\n#### activeChannel\n\nType: `String` \u003cbr/\u003e\nDefault: `delivery`\n\nActive channel\n\n#### isScheduledDeliveryActive\n\nType: `boolean` \u003cbr/\u003e\nDefault: `false`\n\n---\n\n### getOptionsDetails(delivery)\n\nGet more details about each lean option\n\n#### delivery\n\nType: `Object`\n\nLean shipping options\n\n---\n\n### getSelectedDeliveryOption\n\nGet lean shipping option that is current selected\n\n#### delivery\n\nType: `Object`\n\nObject with lean shipping options\n\n---\n\n## Usage\n\n### getLeanShippingOptions\n\nReturn all options are only returned if they are worthy according to the calculation.\n\n```js\nconst leanShippingCalculator = require('@vtex/lean-shipping-calculator')\n\nconst options = leanShippingCalculator.getLeanShippingOptions({\n  logisticsInfo,\n  activeChannel,\n})\n\nconsole.log(options)\n// {\n//   cheapest: [{item1}, {item2}],\n//   fastest:  [{item1}, {item2}],\n//   combined: [{item1}, {item2}]\n// }\n```\n\nAn example of the function returning only cheapest option:\n\n```js\nconsole.log(options)\n// {\n//   cheapest: [{item1}, {item2}]\n// }\n```\n\n### getOptionsDetails\n\nReturns more details about each lean shipping option\n\n```js\nconst leanShippingCalculator = require('@vtex/lean-shipping-calculator')\n\nconst optionDetails = leanShippingCalculator.getOptionsDetails({\n  [CHEAPEST]: cheapestOption,\n  [COMBINED]: combinedOption,\n  [FASTEST]: fastestOption,\n})\n\nconsole.log(optionDetails)\n// [\n//   {\n//     averageEstimatePerItem: 520200,\n//     id: 'CHEAPEST',\n//     packagesLength: 2,\n//     price: 1000,\n//     shippingEstimate: '8bd',\n//   },\n//   {\n//     averageEstimatePerItem: 220200,\n//     id: 'COMBINED',\n//     packagesLength: 2,\n//     price: 3000,\n//     shippingEstimate: '2bd',\n//   },\n//   {\n//     averageEstimatePerItem: 300200,\n//     id: 'FASTEST',\n//     packagesLength: 2,\n//     price: 1500,\n//     shippingEstimate: '5bd',\n//   }\n// ]\n```\n\n### getSelectedDeliveryOption\n\nReturns the selected lean options\n\n```js\nconst leanShippingCalculator = require('@vtex/lean-shipping-calculator')\n\nconst optionToBeSelected = leanShippingCalculator.getSelectedDeliveryOption({\n  optionsDetails = null,\n  newCombined,\n  newFastest,\n  newCheapest,\n  activeDeliveryOption,\n})\n\nconsole.log(optionToBeSelected) // CHEAPEST\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtex%2Flean-shipping-calculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvtex%2Flean-shipping-calculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvtex%2Flean-shipping-calculator/lists"}