mirror of
https://github.com/vercel/commerce.git
synced 2025-07-28 12:41:22 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
saleor
shopify
api
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
index.ts
login.ts
utils
index.ts
auth
cart
customer
product
types
utils
wishlist
.env.template
README.md
codegen.json
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
swell
vendure
lib
pages
public
.editorconfig
.env.template
.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.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import type {
|
|
OperationContext,
|
|
OperationOptions,
|
|
} from '@commerce/api/operations'
|
|
import { normalizePage } from '../../utils'
|
|
import type { ShopifyConfig, Provider } from '..'
|
|
import {
|
|
GetPageQuery,
|
|
GetPageQueryVariables,
|
|
Page as ShopifyPage,
|
|
} from '../../schema'
|
|
import { GetPageOperation } from '../../types/page'
|
|
import getPageQuery from '../../utils/queries/get-page-query'
|
|
|
|
export default function getPageOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getPage<T extends GetPageOperation>(opts: {
|
|
variables: T['variables']
|
|
config?: Partial<ShopifyConfig>
|
|
preview?: boolean
|
|
}): Promise<T['data']>
|
|
|
|
async function getPage<T extends GetPageOperation>(
|
|
opts: {
|
|
variables: T['variables']
|
|
config?: Partial<ShopifyConfig>
|
|
preview?: boolean
|
|
} & OperationOptions
|
|
): Promise<T['data']>
|
|
|
|
async function getPage<T extends GetPageOperation>({
|
|
query = getPageQuery,
|
|
variables,
|
|
config,
|
|
}: {
|
|
query?: string
|
|
variables: T['variables']
|
|
config?: Partial<ShopifyConfig>
|
|
preview?: boolean
|
|
}): Promise<T['data']> {
|
|
const { fetch, locale } = commerce.getConfig(config)
|
|
|
|
const {
|
|
data: { node: page },
|
|
} = await fetch<GetPageQuery, GetPageQueryVariables>(
|
|
query,
|
|
{
|
|
variables,
|
|
},
|
|
{
|
|
...(locale && {
|
|
headers: {
|
|
'Accept-Language': locale,
|
|
},
|
|
}),
|
|
}
|
|
)
|
|
|
|
return page ? { page: normalizePage(page as ShopifyPage, locale) } : {}
|
|
}
|
|
|
|
return getPage
|
|
}
|