From 6e31eab187d9dad3a5ba071da0dc5021afa86bc5 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Fri, 13 Sep 2024 09:57:43 -0300 Subject: [PATCH 1/2] fix: geocoordinates --- node/clients/checkout.ts | 25 ++++++++++++++++++++----- node/package.json | 4 ++-- node/resolvers/Routes/index.ts | 5 +++-- node/yarn.lock | 10 +++++----- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/node/clients/checkout.ts b/node/clients/checkout.ts index 23ca5b0..b53e31a 100644 --- a/node/clients/checkout.ts +++ b/node/clients/checkout.ts @@ -296,12 +296,27 @@ export class Checkout extends JanusClient { public getRegionId = ( country: string, - postalCode: string, - salesChannel: string + postalCode: string | null, + salesChannel: string, + geoCoordinates: [number, number] | null ): Promise => { - return this.get( - `/api/checkout/pub/regions?country=${country}&postalCode=${postalCode}&sc=${salesChannel}` - ) + const baseUrl = '/api/checkout/pub/regions' + const params = new URLSearchParams({ + country, + sc: salesChannel, + }) + + if (postalCode) { + params.append('postalCode', postalCode) + } + + if (geoCoordinates) { + params.append('geoCoordinates', geoCoordinates.join(';')) + } + + const url = `${baseUrl}?${params.toString()}` + + return this.get(url) } protected get = (url: string, config: RequestConfig = {}) => { diff --git a/node/package.json b/node/package.json index a229393..97a049e 100644 --- a/node/package.json +++ b/node/package.json @@ -2,7 +2,7 @@ "name": "vtex.checkout-ui-custom", "version": "1.40.4", "dependencies": { - "@vtex/api": "6.46.1", + "@vtex/api": "6.47.0", "atob": "^2.1.2", "co-body": "^6.0.0", "cookie": "^0.3.1", @@ -21,7 +21,7 @@ "@types/jsonwebtoken": "^8.5.0", "@types/node": "^12.0.0", "@types/ramda": "types/npm-ramda#dist", - "@vtex/api": "6.46.1", + "@vtex/api": "6.47.0", "@vtex/prettier-config": "^0.3.1", "tslint": "^5.12.0", "tslint-config-prettier": "^1.18.0", diff --git a/node/resolvers/Routes/index.ts b/node/resolvers/Routes/index.ts index ba55ea3..7e7ec40 100644 --- a/node/resolvers/Routes/index.ts +++ b/node/resolvers/Routes/index.ts @@ -387,7 +387,7 @@ export const Routes = { // Only require CPF if cost center contains an address in Brazil // This is a workaround to avoid setting CPF as documentType for countries other than Brazil if ( - costCenterResponse?.data?.getCostCenterById?.addresses.some( + costCenterResponse?.data?.getCostCenterById?.addresses?.some( (address: { country: string }) => address.country === 'BRA' ) ) { @@ -461,7 +461,8 @@ export const Routes = { const [regionId] = await checkout.getRegionId( address.country, address.postalCode, - salesChannel.toString() + salesChannel.toString(), + address.geoCoordinates ) if (regionId?.id) { diff --git a/node/yarn.lock b/node/yarn.lock index 3a098b1..1a57dcf 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -190,10 +190,10 @@ "@types/mime" "^1" "@types/node" "*" -"@vtex/api@6.46.1": - version "6.46.1" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.46.1.tgz#55a8755ae48f5400e7f1ed1921cd547950bb7a2a" - integrity sha512-geoxVvyWoQpOQ70Zmx3M8SBkRoGOS/bp9Gy26M+iCue63jofVSwmFz1zf66EaHA1PKOJNRgQPFwY+oeDE1U2lQ== +"@vtex/api@6.47.0": + version "6.47.0" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.47.0.tgz#6910455d593d8bb76f1f4f2b7660023853fda35e" + integrity sha512-t9gt7Q89EMbSj3rLhho+49Fv+/lQgiy8EPVRgtmmXFp1J4v8hIAZF7GPjCPie111KVs4eG0gfZFpmhA5dafKNA== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -1428,7 +1428,7 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= -stats-lite@vtex/node-stats-lite#dist: +"stats-lite@github:vtex/node-stats-lite#dist": version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: From a7343dd0c48fc64d22ebdd4eb4ce06fd4fd5f8e5 Mon Sep 17 00:00:00 2001 From: giurigaud Date: Wed, 2 Oct 2024 18:37:34 -0300 Subject: [PATCH 2/2] feat: add changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b73b4b..e11064c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added +- getRegionId now includes geographic coordinates in parameters when available + ## [1.40.4] - 2024-04-29 ### Added