mirror of
https://github.com/vercel/commerce.git
synced 2025-08-15 05:11:22 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
commercejs
commercelayer
kibocommerce
local
ordercloud
saleor
shopify
spree
swell
api
cart
catalog
customers
endpoints
operations
get-all-pages.ts
get-all-product-paths.ts
get-all-products.ts
get-page.ts
get-product.ts
get-site-info.ts
login.ts
utils
wishlist
customer.ts
index.ts
auth
cart
checkout
customer
product
types
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
swell.ts
types.ts
vendure
lib
pages
public
.editorconfig
.env.template
.eslintrc
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package-lock.json
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
* fix update cart item * update types * update checkout * update get-page, cleanup types * revert change to incorrect file * cleanup Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { Page } from '../../schema'
|
|
import { SwellConfig, Provider } from '..'
|
|
import { OperationContext, OperationOptions } from '@commerce/api/operations'
|
|
import { GetPageOperation } from '../../types/page'
|
|
|
|
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
|
|
|
export type PageVariables = {
|
|
id: number
|
|
}
|
|
|
|
export default function getPageOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getPage<T extends GetPageOperation>(opts: {
|
|
variables: T['variables']
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
}): Promise<T['data']>
|
|
|
|
async function getPage<T extends GetPageOperation>(
|
|
opts: {
|
|
variables: T['variables']
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
} & OperationOptions
|
|
): Promise<T['data']>
|
|
|
|
async function getPage<T extends GetPageOperation>({
|
|
variables,
|
|
config,
|
|
}: {
|
|
query?: string
|
|
variables: T['variables']
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
}): Promise<T['data']> {
|
|
const { fetch, locale = 'en-US' } = commerce.getConfig(config)
|
|
const id = variables.id
|
|
const result = await fetch('content', 'get', ['pages', id])
|
|
const page = result
|
|
|
|
return {
|
|
page: page
|
|
? {
|
|
...page,
|
|
url: `/${locale}/${page.slug}`,
|
|
}
|
|
: null,
|
|
}
|
|
}
|
|
|
|
return getPage
|
|
}
|