mirror of
https://github.com/vercel/commerce.git
synced 2025-08-06 08:51:25 +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
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { Provider, SwellConfig } from '..'
|
|
import type { OperationContext } from '@commerce/api/operations'
|
|
import type { Page } from '../../types/page'
|
|
|
|
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> =
|
|
T
|
|
|
|
export default function getAllPagesOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getAllPages(opts?: {
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
}): Promise<GetAllPagesResult>
|
|
|
|
async function getAllPages<T extends { pages: any[] }>(opts: {
|
|
url: string
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
}): Promise<GetAllPagesResult<T>>
|
|
|
|
async function getAllPages({
|
|
config: cfg,
|
|
preview,
|
|
}: {
|
|
url?: string
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
} = {}): Promise<GetAllPagesResult> {
|
|
const config = commerce.getConfig(cfg)
|
|
const { locale, fetch } = config
|
|
const data = await fetch('content', 'list', ['pages'])
|
|
const pages =
|
|
data?.results?.map(({ slug, ...rest }: { slug: string }) => ({
|
|
url: `/${locale}/${slug}`,
|
|
...rest,
|
|
})) ?? []
|
|
return {
|
|
pages,
|
|
}
|
|
}
|
|
|
|
return getAllPages
|
|
}
|