-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
509 additions
and
229 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { validateCart } from './validateCart' | ||
import { updateSession } from './updateSession' | ||
import { validateSession } from './validateSession' | ||
|
||
export const Mutation = { | ||
validateCart, | ||
updateSession, | ||
validateSession, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
packages/api/src/platforms/vtex/resolvers/updateSession.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
packages/api/src/platforms/vtex/resolvers/validateSession.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import deepEquals from 'fast-deep-equal' | ||
|
||
import ChannelMarshal from '../utils/channel' | ||
import type { Context } from '..' | ||
import type { | ||
MutationValidateSessionArgs, | ||
StoreSession, | ||
} from '../../../__generated__/schema' | ||
|
||
export const validateSession = async ( | ||
_: any, | ||
{ session: oldSession, search }: MutationValidateSessionArgs, | ||
{ clients }: Context | ||
): Promise<StoreSession | null> => { | ||
const channel = ChannelMarshal.parse(oldSession.channel ?? '') | ||
const postalCode = String(oldSession.postalCode ?? '').replace(/\D/g, '') | ||
const country = oldSession.country ?? '' | ||
|
||
const params = new URLSearchParams(search) | ||
|
||
params.set('sc', params.get('sc') ?? channel.salesChannel) | ||
|
||
const [regionData, sessionData] = await Promise.all([ | ||
postalCode | ||
? clients.commerce.checkout.region({ postalCode, country }) | ||
: Promise.resolve(null), | ||
clients.commerce.session(params.toString()).catch(() => null), | ||
]) | ||
|
||
const profile = sessionData?.namespaces.profile ?? null | ||
const store = sessionData?.namespaces.store ?? null | ||
|
||
const newSession = { | ||
...oldSession, | ||
currency: { | ||
code: store?.currencyCode.value ?? oldSession.currency.code, | ||
symbol: store?.currencySymbol.value ?? oldSession.currency.symbol, | ||
}, | ||
country: store?.countryCode.value ?? oldSession.country, | ||
channel: ChannelMarshal.stringify({ | ||
salesChannel: store?.channel?.value ?? channel.salesChannel, | ||
regionId: regionData?.[0]?.id ?? channel.regionId, | ||
}), | ||
person: profile?.id | ||
? { | ||
id: profile.id?.value ?? '', | ||
email: profile.email?.value ?? '', | ||
givenName: profile.firstName?.value ?? '', | ||
familyName: profile.lastName?.value ?? '', | ||
} | ||
: null, | ||
} | ||
|
||
if (deepEquals(oldSession, newSession)) { | ||
return null | ||
} | ||
|
||
return newSession | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,10 @@ | ||
""" | ||
Session information. | ||
""" | ||
type StoreSession { | ||
""" | ||
Session channel. | ||
""" | ||
channel: String | ||
""" | ||
Session country. | ||
""" | ||
country: String | ||
""" | ||
Session postal code. | ||
""" | ||
postalCode: String | ||
} | ||
|
||
""" | ||
Session input. | ||
""" | ||
input IStoreSession { | ||
""" | ||
Session input channel. | ||
""" | ||
channel: String | ||
""" | ||
Session input country. | ||
""" | ||
country: String | ||
""" | ||
Session input postal code. | ||
""" | ||
postalCode: String | ||
} | ||
|
||
type Mutation { | ||
""" | ||
Returns the order if anything has changed in it, or `null` if the order is valid. | ||
""" | ||
validateCart(cart: IStoreCart!): StoreCart | ||
""" | ||
Update session information. | ||
Validate session information. | ||
""" | ||
updateSession(session: IStoreSession!): StoreSession! | ||
validateSession(session: IStoreSession!, search: String!): StoreSession | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,9 +204,4 @@ type Query { | |
""" | ||
after: String | ||
): StoreCollectionConnection! | ||
|
||
""" | ||
Person query. | ||
""" | ||
person: StorePerson | ||
} |
Oops, something went wrong.