mirror of
https://github.com/vercel/commerce.git
synced 2025-08-09 02:11:24 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
local
ordercloud
saleor
shopify
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>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { SwellProduct } from '../../types'
|
|
import { SwellConfig, Provider } from '..'
|
|
import { OperationContext, OperationOptions } from '@commerce/api/operations'
|
|
import { GetAllProductPathsOperation } from '@commerce/types/product'
|
|
|
|
export default function getAllProductPathsOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getAllProductPaths<
|
|
T extends GetAllProductPathsOperation
|
|
>(opts?: {
|
|
variables?: T['variables']
|
|
config?: SwellConfig
|
|
}): Promise<T['data']>
|
|
|
|
async function getAllProductPaths<T extends GetAllProductPathsOperation>(
|
|
opts: {
|
|
variables?: T['variables']
|
|
config?: SwellConfig
|
|
} & OperationOptions
|
|
): Promise<T['data']>
|
|
|
|
async function getAllProductPaths<T extends GetAllProductPathsOperation>({
|
|
variables,
|
|
config: cfg,
|
|
}: {
|
|
query?: string
|
|
variables?: T['variables']
|
|
config?: SwellConfig
|
|
} = {}): Promise<T['data']> {
|
|
const config = commerce.getConfig(cfg)
|
|
// RecursivePartial forces the method to check for every prop in the data, which is
|
|
// required in case there's a custom `query`
|
|
const { results } = await config.fetch('products', 'list', [
|
|
{
|
|
limit: variables?.first,
|
|
},
|
|
])
|
|
|
|
return {
|
|
products: results?.map(({ slug: handle }: SwellProduct) => ({
|
|
path: `/${handle}`,
|
|
})),
|
|
}
|
|
}
|
|
|
|
return getAllProductPaths
|
|
}
|