Skip to content

Commit

Permalink
Merge pull request #150 from vtex-apps/fix/broken-order-form
Browse files Browse the repository at this point in the history
Fix broken order forms
  • Loading branch information
Athos authored Sep 1, 2021
2 parents 7de006c + d04d90c commit 3af2a32
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions node/clients/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} })
}
}
6 changes: 5 additions & 1 deletion node/clients/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions node/resolvers/orderForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -202,7 +210,7 @@ export const queries = {
const storeSettings: StoreSettings = await clients.apps.getAppSettings(
'[email protected]'
)
if (storeSettings.enableOrderFormOptimization) {
if (storeSettings.enableOrderFormOptimization || hasBrokenCookie) {
forwardCheckoutCookies(headers, ctx)
}

Expand Down
8 changes: 4 additions & 4 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1597,10 +1597,10 @@
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d"
integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==

"@vtex/[email protected].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/[email protected].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"
Expand Down

0 comments on commit 3af2a32

Please sign in to comment.