diff --git a/CHANGELOG.md b/CHANGELOG.md index cf3d756..6cea702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ 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). ## [Unreleased] +### Fixed +- Discard broken order forms ## [0.61.1] - 2021-08-27 diff --git a/node/clients/checkout.ts b/node/clients/checkout.ts index bb7b6bc..00711f6 100644 --- a/node/clients/checkout.ts +++ b/node/clients/checkout.ts @@ -470,3 +470,9 @@ export class Checkout extends JanusClient { } } } + +export class CheckoutNoCookies extends Checkout { + constructor(ctx: IOContext, options?: InstanceOptions) { + super({...ctx, orderFormId: null} as any, { ...options, headers: {} }) + } +} diff --git a/node/clients/index.ts b/node/clients/index.ts index ea6221f..6813614 100644 --- a/node/clients/index.ts +++ b/node/clients/index.ts @@ -1,6 +1,6 @@ import { IOClients } from '@vtex/api' -import { Checkout } from './checkout' +import { Checkout, CheckoutNoCookies } from './checkout' import { SearchGraphQL } from './searchGraphQL' import { Session } from './session' import { CountryDataSettings } from './countryDataSettings' @@ -11,6 +11,10 @@ export class Clients extends IOClients { return this.getOrSet('checkout', Checkout) } + public get checkoutNoCookies() { + return this.getOrSet('checkoutNoCookies', CheckoutNoCookies) + } + public get searchGraphQL() { return this.getOrSet('searchGraphQL', SearchGraphQL) } diff --git a/node/package.json b/node/package.json index d176194..e5caa09 100644 --- a/node/package.json +++ b/node/package.json @@ -23,7 +23,7 @@ "@types/lodash": "^4.14.138", "@types/node": "^12.0.0", "@types/ramda": "types/npm-ramda#dist", - "@vtex/api": "6.45.0", + "@vtex/api": "6.45.3", "@vtex/test-tools": "^3.1.0", "@vtex/tsconfig": "^0.2.0", "typescript": "3.9.7", diff --git a/node/resolvers/orderForm.ts b/node/resolvers/orderForm.ts index cbd2818..333a294 100644 --- a/node/resolvers/orderForm.ts +++ b/node/resolvers/orderForm.ts @@ -188,11 +188,19 @@ export const queries = { cacheControl.noCache = true cacheControl.noStore = true - const { data: newOrderForm, headers } = await clients.checkout.orderFormRaw( + let { data: newOrderForm, headers } = await clients.checkout.orderFormRaw( orderFormId ?? undefined, refreshOutdatedData ?? undefined ) + const hasBrokenCookie = newOrderForm?.clientProfileData?.email?.startsWith('vrn--vtexsphinx--aws-us-east-1') + if (hasBrokenCookie) { + vtex.logger.info({message: "Broken order form", orderFormId}) + const obj = await clients.checkoutNoCookies.orderFormRaw(undefined, true) + newOrderForm = obj.data + headers = obj.headers + } + /** * In case the enableOrderFormOptimization setting is enabled in the store, * this will be the only `orderForm` query performed in the client. So no @@ -202,7 +210,7 @@ export const queries = { const storeSettings: StoreSettings = await clients.apps.getAppSettings( 'vtex.store@2.x' ) - if (storeSettings.enableOrderFormOptimization) { + if (storeSettings.enableOrderFormOptimization || hasBrokenCookie) { forwardCheckoutCookies(headers, ctx) } diff --git a/node/yarn.lock b/node/yarn.lock index 7a356d5..c6884db 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1597,10 +1597,10 @@ resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d" integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg== -"@vtex/api@6.45.0": - version "6.45.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.0.tgz#6f7de4b5e2f2a86cc8251125cc2d77de96611951" - integrity sha512-F5mZLq/x8RrCXl6Qj+gJsqsyM1DGicxggZplitY3NOewn0vGXtz7TR2r/zY3v+9nQp+ksQzax7Vqf9em+78GxA== +"@vtex/api@6.45.3": + version "6.45.3" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.3.tgz#fe7d08adb4eab1fda5e34143cc6302a4c5aa5f52" + integrity sha512-kiD7We1TCKDyBdpYoh2Se3An+jTJRUzXGNpKifoDZylWQ1PyIx+3oL5ZAif9InlY3uJkfEisSAI6nxoKTgvPfw== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3"