From b4c80856ae65473041be574ef92cba72fdae06a4 Mon Sep 17 00:00:00 2001 From: Vicky Enalen Date: Tue, 4 Apr 2023 15:06:09 -0700 Subject: [PATCH] API version 2.1.0 See https://docs.patch.io/#/changelog for changes (#85) * API version 2.1.0 See https://docs.patch.io/#/changelog for changes * Update expected test results for estimates --- CHANGELOG.md | 12 ++++ package-lock.json | 16 ++--- package.json | 2 +- src/ApiClient.js | 2 +- src/model/CreateOrderLineItemRequest.js | 18 ++++++ src/model/CreateOrderRequest.js | 18 ++++++ .../CreateRoadShippingEstimateRequest.js | 9 +++ src/model/Inventory.js | 43 +++++++++++++- src/model/OrderLineItem.js | 45 +++++++++++++- src/model/UpdateOrderLineItemRequest.js | 18 ++++++ test/integration/estimates.test.js | 2 +- test/integration/orders.test.js | 58 ++++++++++++++++++- test/integration/projects.test.js | 2 + yarn.lock | 6 +- 14 files changed, 230 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ebbfd..88fd32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.0] - 2023-04-04 + +### Added + +- Adds optional `vintage_start_year` and `vintage_end_year` fields to `order` creation +- Adds optional `vintage_start_year` and `vintage_end_year` fields to `order_line_item` create and update +- Adds optional `vintage_start_year` and `vintage_end_year` fields to `inventory` creation +- Adds `vintage_start_year` and `vintage_end_year` fields to `order` response +- Adds `vintage_start_year` and `vintage_end_year` fields to `order_line_item` response +- Adds optional `carrier_scac` field to `patch.estimates.createRoadShippingEstimate` +- Deprecates `createShippingEstimate` in favor of `createEcommerceEstimate` + ## [1.24.2] - 2022-08-10 ### Added diff --git a/package-lock.json b/package-lock.json index b0302d4..15157b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "2.0.1", + "version": "2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "2.0.1", + "version": "2.1.0", "license": "MIT", "dependencies": { "query-string": "^7.0.1", @@ -2178,9 +2178,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001341", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz", - "integrity": "sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==", + "version": "1.0.30001469", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz", + "integrity": "sha512-Rcp7221ScNqQPP3W+lVOYDyjdR6dC+neEQCttoNr5bAyz54AboB4iwpnWgyi8P4YUsPybVzT4LgWiBbI3drL4g==", "dev": true, "funding": [ { @@ -6597,9 +6597,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001341", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz", - "integrity": "sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==", + "version": "1.0.30001469", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz", + "integrity": "sha512-Rcp7221ScNqQPP3W+lVOYDyjdR6dC+neEQCttoNr5bAyz54AboB4iwpnWgyi8P4YUsPybVzT4LgWiBbI3drL4g==", "dev": true }, "chai": { diff --git a/package.json b/package.json index f98fa62..9171d23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "2.0.1", + "version": "2.1.0", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index 651b9bb..ea10ffc 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/2.0.1', + 'User-Agent': 'patch-node/2.1.0', 'Patch-Version': 2 }; diff --git a/src/model/CreateOrderLineItemRequest.js b/src/model/CreateOrderLineItemRequest.js index 3c57fcb..ec1a9af 100644 --- a/src/model/CreateOrderLineItemRequest.js +++ b/src/model/CreateOrderLineItemRequest.js @@ -32,6 +32,20 @@ class CreateOrderLineItemRequest { ); } + if (data.hasOwnProperty('vintage_start_year')) { + obj['vintage_start_year'] = ApiClient.convertToType( + data['vintage_start_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('vintage_end_year')) { + obj['vintage_end_year'] = ApiClient.convertToType( + data['vintage_end_year'], + 'Number' + ); + } + if (data.hasOwnProperty('price')) { obj['price'] = ApiClient.convertToType(data['price'], 'Number'); } @@ -56,6 +70,10 @@ CreateOrderLineItemRequest.prototype['project_id'] = undefined; CreateOrderLineItemRequest.prototype['vintage_year'] = undefined; +CreateOrderLineItemRequest.prototype['vintage_start_year'] = undefined; + +CreateOrderLineItemRequest.prototype['vintage_end_year'] = undefined; + CreateOrderLineItemRequest.prototype['price'] = undefined; CreateOrderLineItemRequest.prototype['currency'] = undefined; diff --git a/src/model/CreateOrderRequest.js b/src/model/CreateOrderRequest.js index 12dd7a3..a365244 100644 --- a/src/model/CreateOrderRequest.js +++ b/src/model/CreateOrderRequest.js @@ -41,6 +41,20 @@ class CreateOrderRequest { ); } + if (data.hasOwnProperty('vintage_start_year')) { + obj['vintage_start_year'] = ApiClient.convertToType( + data['vintage_start_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('vintage_end_year')) { + obj['vintage_end_year'] = ApiClient.convertToType( + data['vintage_end_year'], + 'Number' + ); + } + if (data.hasOwnProperty('total_price')) { obj['total_price'] = ApiClient.convertToType( data['total_price'], @@ -76,6 +90,10 @@ CreateOrderRequest.prototype['state'] = undefined; CreateOrderRequest.prototype['vintage_year'] = undefined; +CreateOrderRequest.prototype['vintage_start_year'] = undefined; + +CreateOrderRequest.prototype['vintage_end_year'] = undefined; + CreateOrderRequest.prototype['total_price'] = undefined; CreateOrderRequest.prototype['currency'] = undefined; diff --git a/src/model/CreateRoadShippingEstimateRequest.js b/src/model/CreateRoadShippingEstimateRequest.js index 5bdd384..d1afea9 100644 --- a/src/model/CreateRoadShippingEstimateRequest.js +++ b/src/model/CreateRoadShippingEstimateRequest.js @@ -106,6 +106,13 @@ class CreateRoadShippingEstimateRequest { ); } + if (data.hasOwnProperty('carrier_scac')) { + obj['carrier_scac'] = ApiClient.convertToType( + data['carrier_scac'], + 'String' + ); + } + if (data.hasOwnProperty('project_id')) { obj['project_id'] = ApiClient.convertToType( data['project_id'], @@ -152,6 +159,8 @@ CreateRoadShippingEstimateRequest.prototype['number_of_containers'] = undefined; CreateRoadShippingEstimateRequest.prototype['truck_weight_t'] = undefined; +CreateRoadShippingEstimateRequest.prototype['carrier_scac'] = undefined; + CreateRoadShippingEstimateRequest.prototype['project_id'] = undefined; CreateRoadShippingEstimateRequest.prototype['create_order'] = false; diff --git a/src/model/Inventory.js b/src/model/Inventory.js index 66f92d0..6e251d2 100644 --- a/src/model/Inventory.js +++ b/src/model/Inventory.js @@ -8,10 +8,20 @@ import ApiClient from '../ApiClient'; class Inventory { - constructor(vintageYear, amountAvailable, price, currency, unit) { + constructor( + vintageYear, + vintageStartYear, + vintageEndYear, + amountAvailable, + price, + currency, + unit + ) { Inventory.initialize( this, vintageYear, + vintageStartYear, + vintageEndYear, amountAvailable, price, currency, @@ -19,8 +29,19 @@ class Inventory { ); } - static initialize(obj, vintageYear, amountAvailable, price, currency, unit) { + static initialize( + obj, + vintageYear, + vintageStartYear, + vintageEndYear, + amountAvailable, + price, + currency, + unit + ) { obj['vintage_year'] = vintageYear; + obj['vintage_start_year'] = vintageStartYear; + obj['vintage_end_year'] = vintageEndYear; obj['amount_available'] = amountAvailable; obj['price'] = price; obj['currency'] = currency; @@ -38,6 +59,20 @@ class Inventory { ); } + if (data.hasOwnProperty('vintage_start_year')) { + obj['vintage_start_year'] = ApiClient.convertToType( + data['vintage_start_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('vintage_end_year')) { + obj['vintage_end_year'] = ApiClient.convertToType( + data['vintage_end_year'], + 'Number' + ); + } + if (data.hasOwnProperty('amount_available')) { obj['amount_available'] = ApiClient.convertToType( data['amount_available'], @@ -63,6 +98,10 @@ class Inventory { Inventory.prototype['vintage_year'] = undefined; +Inventory.prototype['vintage_start_year'] = undefined; + +Inventory.prototype['vintage_end_year'] = undefined; + Inventory.prototype['amount_available'] = undefined; Inventory.prototype['price'] = undefined; diff --git a/src/model/OrderLineItem.js b/src/model/OrderLineItem.js index a5b21c8..f8723b3 100644 --- a/src/model/OrderLineItem.js +++ b/src/model/OrderLineItem.js @@ -9,11 +9,22 @@ import ApiClient from '../ApiClient'; import OrderLineItemProject from './OrderLineItemProject'; class OrderLineItem { - constructor(project, vintageYear, amount, unit, price, currency) { + constructor( + project, + vintageYear, + vintageStartYear, + vintageEndYear, + amount, + unit, + price, + currency + ) { OrderLineItem.initialize( this, project, vintageYear, + vintageStartYear, + vintageEndYear, amount, unit, price, @@ -21,9 +32,21 @@ class OrderLineItem { ); } - static initialize(obj, project, vintageYear, amount, unit, price, currency) { + static initialize( + obj, + project, + vintageYear, + vintageStartYear, + vintageEndYear, + amount, + unit, + price, + currency + ) { obj['project'] = project; obj['vintage_year'] = vintageYear; + obj['vintage_start_year'] = vintageStartYear; + obj['vintage_end_year'] = vintageEndYear; obj['amount'] = amount; obj['unit'] = unit; obj['price'] = price; @@ -52,6 +75,20 @@ class OrderLineItem { ); } + if (data.hasOwnProperty('vintage_start_year')) { + obj['vintage_start_year'] = ApiClient.convertToType( + data['vintage_start_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('vintage_end_year')) { + obj['vintage_end_year'] = ApiClient.convertToType( + data['vintage_end_year'], + 'Number' + ); + } + if (data.hasOwnProperty('amount')) { obj['amount'] = ApiClient.convertToType(data['amount'], 'Number'); } @@ -78,6 +115,10 @@ OrderLineItem.prototype['project'] = undefined; OrderLineItem.prototype['vintage_year'] = undefined; +OrderLineItem.prototype['vintage_start_year'] = undefined; + +OrderLineItem.prototype['vintage_end_year'] = undefined; + OrderLineItem.prototype['amount'] = undefined; OrderLineItem.prototype['unit'] = undefined; diff --git a/src/model/UpdateOrderLineItemRequest.js b/src/model/UpdateOrderLineItemRequest.js index de52e1a..9b74fe3 100644 --- a/src/model/UpdateOrderLineItemRequest.js +++ b/src/model/UpdateOrderLineItemRequest.js @@ -25,6 +25,20 @@ class UpdateOrderLineItemRequest { ); } + if (data.hasOwnProperty('vintage_start_year')) { + obj['vintage_start_year'] = ApiClient.convertToType( + data['vintage_start_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('vintage_end_year')) { + obj['vintage_end_year'] = ApiClient.convertToType( + data['vintage_end_year'], + 'Number' + ); + } + if (data.hasOwnProperty('price')) { obj['price'] = ApiClient.convertToType(data['price'], 'Number'); } @@ -47,6 +61,10 @@ class UpdateOrderLineItemRequest { UpdateOrderLineItemRequest.prototype['vintage_year'] = undefined; +UpdateOrderLineItemRequest.prototype['vintage_start_year'] = undefined; + +UpdateOrderLineItemRequest.prototype['vintage_end_year'] = undefined; + UpdateOrderLineItemRequest.prototype['price'] = undefined; UpdateOrderLineItemRequest.prototype['currency'] = undefined; diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index 2fa4a58..3d55ade 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -46,7 +46,7 @@ describe('Estimates Integration', function () { ); const estimate = createEstimateResponse.data; - expect(estimate.type).to.be.eq('shipping'); + expect(estimate.type).to.be.eq('ecommerce'); expect(estimate.mass_g).to.be.above(0); expect(estimate.production).to.be.eq(false); expect(estimate.order).to.be.eq(null); diff --git a/test/integration/orders.test.js b/test/integration/orders.test.js index f25df47..3cb213d 100644 --- a/test/integration/orders.test.js +++ b/test/integration/orders.test.js @@ -133,6 +133,17 @@ describe('Orders Integration', function () { expect(createOrderResponse.success).to.equal(true); }); + it('supports create orders with vintage start year and vintage end year', async function () { + const createOrderResponse = await patch.orders.createOrder({ + amount: 100, + unit: 'g', + vintage_start_year: 2023, + vintage_end_year: 2025 + }); + + expect(createOrderResponse.success).to.equal(true); + }); + it('supports create orders with an amount and unit', async function () { const createOrderResponse = await patch.orders.createOrder({ amount: 100, @@ -180,7 +191,7 @@ describe('Orders Integration', function () { expect(createLineItemResponse.data.amount).to.equal(0); // Update amount on line item - const lineItemId = createLineItemResponse.data.id; + let lineItemId = createLineItemResponse.data.id; const updateOrderLineItemResponse = await patch.orderlineitems.updateOrderLineItem(orderId, lineItemId, { amount: 100000, @@ -200,8 +211,49 @@ describe('Orders Integration', function () { expect(retrieveOrderResponse.data.line_items[0].amount).to.equal(100000); // Delete line item - const deleteLineItemResponse = - await patch.orderlineitems.deleteOrderLineItem(orderId, lineItemId); + let deleteLineItemResponse = await patch.orderlineitems.deleteOrderLineItem( + orderId, + lineItemId + ); + expect(deleteLineItemResponse.success).to.equal(true); + expect(deleteLineItemResponse.data).to.equal(lineItemId); + + // Add line item via vintage_start_year and vintage_end_year + const createOrderLineItemResponse = + await patch.orderlineitems.createOrderLineItem(orderId, { + project_id: biomass_test_project_id, + amount: 200000, + unit: 'g', + vintage_start_year: 2023, + vintage_end_year: 2025 + }); + + lineItemId = createOrderLineItemResponse.data.id; + expect(createOrderLineItemResponse.success).to.equal(true); + expect(createOrderLineItemResponse.data.id).to.equal(lineItemId); + expect(createOrderLineItemResponse.data.amount).to.equal(200000); + expect(createOrderLineItemResponse.data.price).to.be.greaterThan(0); + expect(createOrderLineItemResponse.data.vintage_start_year).to.equal(2023); + expect(createOrderLineItemResponse.data.vintage_end_year).to.equal(2025); + + // Fetch order and check line item matches + retrieveOrderResponse = await patch.orders.retrieveOrder(orderId); + expect(retrieveOrderResponse.data.id).to.equal(orderId); + expect(retrieveOrderResponse.data.line_items.length).to.equal(1); + expect(retrieveOrderResponse.data.line_items[0].id).to.equal(lineItemId); + expect(retrieveOrderResponse.data.line_items[0].amount).to.equal(200000); + expect( + retrieveOrderResponse.data.line_items[0].vintage_start_year + ).to.equal(2023); + expect(retrieveOrderResponse.data.line_items[0].vintage_end_year).to.equal( + 2025 + ); + + // Delete line item + deleteLineItemResponse = await patch.orderlineitems.deleteOrderLineItem( + orderId, + lineItemId + ); expect(deleteLineItemResponse.success).to.equal(true); expect(deleteLineItemResponse.data).to.equal(lineItemId); diff --git a/test/integration/projects.test.js b/test/integration/projects.test.js index 0c3bc5c..41f0bda 100644 --- a/test/integration/projects.test.js +++ b/test/integration/projects.test.js @@ -41,6 +41,8 @@ describe('Project Integration', function () { const inventory = projectResponse.data.inventory; expect(inventory).to.be.a('array'); expect(inventory[0].vintage_year).to.be.a('number'); + expect(inventory[0].vintage_start_year).to.be.a('number'); + expect(inventory[0].vintage_end_year).to.be.a('number'); expect(inventory[0].amount_available).to.be.a('number'); expect(inventory[0].price).to.be.a('number'); expect(inventory[0].currency).to.be.a('string'); diff --git a/yarn.lock b/yarn.lock index 3355bbc..8ceb73a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1236,9 +1236,9 @@ "version" "6.2.0" "caniuse-lite@^1.0.30001274": - "integrity" "sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==" - "resolved" "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz" - "version" "1.0.30001341" + "integrity" "sha512-Rcp7221ScNqQPP3W+lVOYDyjdR6dC+neEQCttoNr5bAyz54AboB4iwpnWgyi8P4YUsPybVzT4LgWiBbI3drL4g==" + "resolved" "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz" + "version" "1.0.30001469" "chai@^4.3.0": "integrity" "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA=="