@faststore/api 1.6.16 → 1.6.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/__generated__/schema.d.ts +15 -0
- package/dist/api.cjs.development.js +53 -4
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +53 -4
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/platforms/vtex/clients/commerce/index.d.ts +2 -0
- package/dist/platforms/vtex/clients/commerce/types/Region.d.ts +8 -0
- package/dist/platforms/vtex/clients/index.d.ts +1 -0
- package/dist/platforms/vtex/index.d.ts +3 -2
- package/dist/platforms/vtex/resolvers/mutation.d.ts +1 -0
- package/dist/platforms/vtex/resolvers/updateSession.d.ts +3 -0
- package/dist/platforms/vtex/utils/channel.d.ts +8 -0
- package/dist/typings/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/__generated__/schema.ts +19 -0
- package/src/index.ts +1 -1
- package/src/platforms/vtex/clients/commerce/index.ts +12 -0
- package/src/platforms/vtex/clients/commerce/types/Region.ts +7 -0
- package/src/platforms/vtex/resolvers/mutation.ts +2 -0
- package/src/platforms/vtex/resolvers/updateSession.ts +26 -0
- package/src/platforms/vtex/utils/channel.ts +25 -0
- package/src/typeDefs/mutation.graphql +14 -0
- package/src/typings/index.ts +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Context } from '..'
|
|
2
|
+
import type {
|
|
3
|
+
MutationUpdateSessionArgs,
|
|
4
|
+
StoreSession,
|
|
5
|
+
} from '../../../__generated__/schema'
|
|
6
|
+
import ChannelMarshal from '../utils/channel'
|
|
7
|
+
|
|
8
|
+
export const updateSession = async (
|
|
9
|
+
_: any,
|
|
10
|
+
{ session }: MutationUpdateSessionArgs,
|
|
11
|
+
{ clients }: Context
|
|
12
|
+
): Promise<StoreSession> => {
|
|
13
|
+
const channel = ChannelMarshal.parse(session.channel ?? '')
|
|
14
|
+
const regionData = await clients.commerce.checkout.region({
|
|
15
|
+
postalCode: String(session.postalCode ?? '').replace(/\D/g, ''),
|
|
16
|
+
country: session.country ?? '',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
...session,
|
|
21
|
+
channel: ChannelMarshal.stringify({
|
|
22
|
+
...channel,
|
|
23
|
+
regionId: regionData?.[0]?.id,
|
|
24
|
+
}),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Channel {
|
|
2
|
+
regionId?: string
|
|
3
|
+
salesChannel?: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export default class ChannelMarshal {
|
|
7
|
+
public static parse(channelString: string): Channel {
|
|
8
|
+
try {
|
|
9
|
+
const parsedChannel = JSON.parse(channelString) as Channel
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
regionId: parsedChannel.regionId ?? '',
|
|
13
|
+
salesChannel: parsedChannel.salesChannel ?? '',
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error(error)
|
|
17
|
+
|
|
18
|
+
throw new Error('Malformed channel string')
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static stringify(channel: Channel): string {
|
|
23
|
+
return JSON.stringify(channel)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
type StoreSession {
|
|
2
|
+
channel: String
|
|
3
|
+
country: String
|
|
4
|
+
postalCode: String
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
input IStoreSession {
|
|
8
|
+
channel: String
|
|
9
|
+
country: String
|
|
10
|
+
postalCode: String
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
type Mutation {
|
|
2
14
|
# Returns the order if anything changed with the order. Null if the order is valid
|
|
3
15
|
validateCart(cart: IStoreCart!): StoreCart
|
|
16
|
+
|
|
17
|
+
updateSession(session: IStoreSession!): StoreSession!
|
|
4
18
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Platform = 'vtex'
|