From 21bfdf2264a255e779fbbe85f97cf00266ec4545 Mon Sep 17 00:00:00 2001 From: Arthur Bond Date: Mon, 29 Jan 2024 15:35:36 -0500 Subject: [PATCH 1/2] New mutation to remove/add B2B session data --- CHANGELOG.md | 26 +++++++++++++------------- graphql/schema.graphql | 4 ++++ node/resolvers/Mutations/Users.ts | 29 +++++++++++++++++++++++++++++ node/resolvers/Routes/index.ts | 9 +++++++++ node/resolvers/index.ts | 2 ++ node/yarn.lock | 2 +- vtex.session/configuration.json | 2 +- 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d9eb8..f8a7a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- New `ignoreB2BSessionData` mutation to allow a user to leave/resume the B2B context + ## [1.38.0] - 2023-12-14 ### Added @@ -52,16 +56,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.35.2] - 2023-07-13 ### Changed + - Edited README.md file ## [1.35.1] - 2023-06-29 -### Fixed +### Fixed - Removing the document on orderform in case of business/corporate profile data - Removing all the non digits from the business document to prevent checkout errors - ## [1.35.0] - 2023-05-31 ### Added @@ -89,11 +93,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.33.3] - 2023-05-08 ### Fixed + - Fixed issue where `documentType` is always set to cpf ## [1.33.2] - 2023-05-03 ### Fixed + - geoCoordinates empty ## [1.33.1] - 2023-04-21 @@ -106,8 +112,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed -- Fix on impersonation user - +- Fix on impersonation user ## [1.32.0] - 2023-04-19 @@ -115,15 +120,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added the x-b2b-senderapp header to fix problems with the new B2B API - ## [1.31.5] - 2023-04-11 ### Fixed -- Fixed clear call async calls - +- Fixed clear call async calls ### Removed + - [ENGINEERS-1247] - Disable cypress tests in PR level ### Changed @@ -137,7 +141,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed the `setProfile` to clear the cart properly - Improved calls on set profile in order to get faster response - ## [1.31.3] - 2023-03-01 ### Fixed @@ -147,6 +150,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.31.2] - 2023-02-27 ### Fixed + - `setProfile` adding sku 1 to the cart to set sales channel when the cart is empty - `setProfile` losing item attachments after login @@ -162,7 +166,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a feature when the user logs in or changes the current organization. - ## [1.30.0] - 2023-02-09 ### Added @@ -226,7 +229,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - getOrganizationsByEmail is returning all users instead of only first 50 records - ## [1.29.2] - 2022-11-28 ### Fixed @@ -245,7 +247,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [1.29.0] - 2022-11-08 - ### Added - Added the functionality to the storefront permissions to change the sales channel according to the Organization @@ -262,7 +263,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Force the business document and state registration on setProfile method - ## [1.27.0] - 2022-10-19 ### Changed @@ -299,7 +299,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - - Changed the validation of the add user +- Changed the validation of the add user ### Added diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 1d91f1a..5d1f676 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -161,6 +161,10 @@ type Mutation { @withSession @cacheControl(scope: PRIVATE) @withSender + + ignoreB2BSessionData(enabled: Boolean!): MutationResponse + @withSession + @cacheControl(scope: PRIVATE) } type UserImpersonation { diff --git a/node/resolvers/Mutations/Users.ts b/node/resolvers/Mutations/Users.ts index 9d5420c..32074f4 100644 --- a/node/resolvers/Mutations/Users.ts +++ b/node/resolvers/Mutations/Users.ts @@ -639,3 +639,32 @@ export const setCurrentOrganization = async ( return { status: 'error', message: error } } } + +export const ignoreB2BSessionData = async ( + _: void, + { enabled }: { enabled: boolean }, + ctx: Context +) => { + const { + cookies, + request, + vtex: { logger }, + clients: { session }, + } = ctx + + const sessionCookie = + cookies.get('vtex_session') ?? request.header?.sessiontoken + + try { + await session.updateSession('removeB2B', enabled, [], sessionCookie) + + return { status: 'success', message: '' } + } catch (error) { + logger.error({ + error, + message: 'removeB2BSessionData.error', + }) + + return { status: 'error', message: error } + } +} diff --git a/node/resolvers/Routes/index.ts b/node/resolvers/Routes/index.ts index 27a9d58..6561079 100644 --- a/node/resolvers/Routes/index.ts +++ b/node/resolvers/Routes/index.ts @@ -162,6 +162,15 @@ export const Routes = { let stateRegistration = null let user = null + const ignoreB2B = body?.public?.removeB2B?.value + + if (ignoreB2B) { + ctx.response.body = response + ctx.response.status = 200 + + return + } + if (b2bImpersonate) { try { user = (await getUser({ diff --git a/node/resolvers/index.ts b/node/resolvers/index.ts index 6e005d1..383002c 100644 --- a/node/resolvers/index.ts +++ b/node/resolvers/index.ts @@ -8,6 +8,7 @@ import { addOrganizationToUser, addUser, deleteUser, + ignoreB2BSessionData, impersonateUser, saveUser, setActiveUserByOrganization, @@ -40,6 +41,7 @@ export const resolvers = { addUser, deleteRole, deleteUser, + ignoreB2BSessionData, impersonateUser, saveRole, saveUser, diff --git a/node/yarn.lock b/node/yarn.lock index 8dd924f..197ca86 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -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@github:vtex/node-stats-lite#dist": +stats-lite@vtex/node-stats-lite#dist: version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: diff --git a/vtex.session/configuration.json b/vtex.session/configuration.json index a8a729d..7913ee8 100644 --- a/vtex.session/configuration.json +++ b/vtex.session/configuration.json @@ -4,7 +4,7 @@ "authentication": ["storeUserEmail"], "checkout": ["orderFormId"], "impersonate": ["storeUserEmail", "storeUserId"], - "public": ["impersonate"] + "public": ["impersonate", "removeB2B"] }, "output": { "public": ["facets", "sc", "regionId"], From 70da66f1e89aeb27ba0af699b1cd6d67f9db49ea Mon Sep 17 00:00:00 2001 From: Arthur Bond Date: Wed, 31 Jan 2024 11:23:33 -0500 Subject: [PATCH 2/2] Update quality engineering workflow version --- .github/workflows/qe-dispatch.yml | 2 +- .github/workflows/qe-pull-request-target.yml | 2 +- .github/workflows/qe-pull-request.yml | 2 +- .github/workflows/qe-push.yml | 2 +- .github/workflows/qe-schedule.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/qe-dispatch.yml b/.github/workflows/qe-dispatch.yml index ef043b3..7ce9cc0 100644 --- a/.github/workflows/qe-dispatch.yml +++ b/.github/workflows/qe-dispatch.yml @@ -13,7 +13,7 @@ on: jobs: quality-engineering: name: QE - uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2 + uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2.1.14 with: cypress: true cyRunnerBranch: ${{ github.event.inputs.cyRunnerBranch }} diff --git a/.github/workflows/qe-pull-request-target.yml b/.github/workflows/qe-pull-request-target.yml index 24e10f7..c9cb1cd 100644 --- a/.github/workflows/qe-pull-request-target.yml +++ b/.github/workflows/qe-pull-request-target.yml @@ -11,7 +11,7 @@ on: jobs: quality-engineering: name: QE - uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2 + uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2.1.14 with: danger: true dangerRequireChangelog: false diff --git a/.github/workflows/qe-pull-request.yml b/.github/workflows/qe-pull-request.yml index 1361646..82611c3 100644 --- a/.github/workflows/qe-pull-request.yml +++ b/.github/workflows/qe-pull-request.yml @@ -14,7 +14,7 @@ on: jobs: quality-engineering: name: QE - uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2 + uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2.1.14 with: danger: true dangerRequireChangelog: false diff --git a/.github/workflows/qe-push.yml b/.github/workflows/qe-push.yml index abd7145..054d76e 100644 --- a/.github/workflows/qe-push.yml +++ b/.github/workflows/qe-push.yml @@ -9,7 +9,7 @@ on: jobs: quality-engineering: name: QE - uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2 + uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2.1.14 with: nodeLint: true nodeTest: false diff --git a/.github/workflows/qe-schedule.yml b/.github/workflows/qe-schedule.yml index 85881d9..e6cf15f 100644 --- a/.github/workflows/qe-schedule.yml +++ b/.github/workflows/qe-schedule.yml @@ -6,7 +6,7 @@ on: jobs: quality-engineering: name: QE - uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2 + uses: vtex-apps/usqa/.github/workflows/quality-engineering.yml@v2.1.14 with: cypress: true cyRunnerTimeOut: 45