import { Page } from '../../schema' import { SwellConfig, Provider } from '..' import { OperationContext, OperationOptions } from '@commerce/api/operations' import { GetPageOperation } from '../../types/page' export type GetPageResult = T export type PageVariables = { id: number } export default function getPageOperation({ commerce, }: OperationContext) { async function getPage(opts: { variables: T['variables'] config?: Partial preview?: boolean }): Promise async function getPage( opts: { variables: T['variables'] config?: Partial preview?: boolean } & OperationOptions ): Promise async function getPage({ variables, config, }: { query?: string variables: T['variables'] config?: Partial preview?: boolean }): Promise { 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 }