-
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
18 changed files
with
1,695 additions
and
1,133 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.
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
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 }: 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 [regionData, sessionData] = await Promise.all([ | ||
postalCode | ||
? clients.commerce.checkout.region({ postalCode, country }) | ||
: Promise.resolve(null), | ||
clients.commerce.session(), | ||
]) | ||
|
||
const { profile = null, store = null } = sessionData.namespaces | ||
|
||
const newSession = { | ||
...oldSession, | ||
channel: ChannelMarshal.stringify({ | ||
salesChannel: store?.channel?.value ?? channel.salesChannel, | ||
regionId: regionData?.[0]?.id ?? channel.regionId, | ||
}), | ||
person: profile && { | ||
id: profile.id?.value ?? '', | ||
email: profile.email?.value ?? '', | ||
givenName: profile.firstName?.value ?? '', | ||
familyName: profile.lastName?.value ?? '', | ||
}, | ||
} | ||
|
||
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!): 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 |
---|---|---|
|
@@ -190,9 +190,4 @@ type Query { | |
""" | ||
after: String | ||
): StoreCollectionConnection! | ||
|
||
""" | ||
Person query. | ||
""" | ||
person: StorePerson | ||
} |
Oops, something went wrong.