Skip to content

Commit

Permalink
add cart
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Oct 1, 2021
1 parent 0f63589 commit 8e69713
Show file tree
Hide file tree
Showing 28 changed files with 814 additions and 91 deletions.
6 changes: 5 additions & 1 deletion packages/store-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"dependencies": {
"@graphql-tools/schema": "^8.2.0",
"graphql": "^15.5.3",
"dataloader": "^2.0.0",
"fast-deep-equal": "^3.1.3",
"isomorphic-unfetch": "^3.1.0",
"rollup-plugin-graphql": "^0.1.0",
"slugify": "^1.6.0"
Expand All @@ -36,5 +37,8 @@
"tsdx": "^0.14.1",
"tslib": "^2.3.1",
"typescript": "^4.4.2"
},
"peerDependencies": {
"graphql": "^15.6.0"
}
}
68 changes: 68 additions & 0 deletions packages/store-api/src/__generated__/schema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 56 additions & 9 deletions packages/store-api/src/platforms/vtex/clients/commerce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@ import type {
Simulation,
SimulationArgs,
SimulationOptions,
} from './types/Checkout'
} from './types/Simulation'
import type { CategoryTree } from './types/CategoryTree'
import type { Options } from '../..'
import type { Brand } from './types/Brand'
import type { OrderForm, OrderFormInputItem } from './types/OrderForm'

const BASE_INIT = {
method: 'POST',
headers: {
'content-type': 'application/json',
},
}

const getBase = ({ account, environment }: Options) =>
`http://${account}.${environment}.com.br`

export const VtexCommerce = (opts: Options) => {
const base = getBase(opts)
export const VtexCommerce = (options: Options) => {
const { channel } = options
const base = getBase(options)

return {
catalog: {
Expand All @@ -28,18 +37,56 @@ export const VtexCommerce = (opts: Options) => {
checkout: {
simulation: (
args: SimulationArgs,
options: SimulationOptions = { sc: '1' }
simulationOptions: SimulationOptions = { sc: channel }
): Promise<Simulation> => {
const params = new URLSearchParams({ ...options })
const params = new URLSearchParams({ ...simulationOptions })

return fetchAPI(
`${base}/api/checkout/pub/orderForms/simulation?${params.toString()}`,
{
method: 'POST',
...BASE_INIT,
body: JSON.stringify(args),
headers: {
'content-type': 'application/json',
},
}
)
},
orderForm: ({
id,
refreshOutdatedData = true,
sc = channel,
}: {
id: string
refreshOutdatedData?: boolean
sc?: string
}): Promise<OrderForm> => {
const params = new URLSearchParams({
refreshOutdatedData: refreshOutdatedData.toString(),
sc,
})

return fetchAPI(
`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`,
BASE_INIT
)
},
updateOrderFormItems: ({
id,
orderItems,
allowOutdatedData = 'paymentData',
sc = channel,
}: {
id: string
orderItems: OrderFormInputItem[]
allowOutdatedData?: 'paymentData'
sc?: string
}): Promise<OrderForm> => {
const params = new URLSearchParams({ allowOutdatedData, sc })

return fetchAPI(
`${base}/api/checkout/pub/orderForm/${id}/items?${params}`,
{
...BASE_INIT,
body: JSON.stringify({ orderItems }),
method: 'PATCH',
}
)
},
Expand Down
Loading

0 comments on commit 8e69713

Please sign in to comment.