mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 16:25:53 +00:00
* Add ordercloud provider * Fix provider errors * Make submit checkout optional * Make submit checkout optional * Remove nullables when creating endpoint type * Update readme * Log checkout error * Log error * Save token to cookie * Update fetch rest * Use token at checkout Co-authored-by: Luis Alvarez <luis@vercel.com>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import type { OperationContext } from '@commerce/api/operations'
|
|
import type { GetAllProductPathsOperation } from '@commerce/types/product'
|
|
|
|
import type { RawProduct } from '../../types/product'
|
|
import type { OrdercloudConfig, Provider } from '../'
|
|
|
|
export type GetAllProductPathsResult = {
|
|
products: Array<{ path: string }>
|
|
}
|
|
|
|
export default function getAllProductPathsOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getAllProductPaths<T extends GetAllProductPathsOperation>({
|
|
config,
|
|
}: {
|
|
config?: Partial<OrdercloudConfig>
|
|
} = {}): Promise<T['data']> {
|
|
// Get fetch from the config
|
|
const { restBuyerFetch } = commerce.getConfig(config)
|
|
|
|
// Get all products
|
|
const rawProducts: RawProduct[] = await restBuyerFetch<{
|
|
Items: RawProduct[]
|
|
}>('GET', '/me/products').then((response) => response.Items)
|
|
|
|
return {
|
|
// Match a path for every product retrieved
|
|
products: rawProducts.map((product) => ({ path: `/${product.ID}` })),
|
|
}
|
|
}
|
|
|
|
return getAllProductPaths
|
|
}
|