mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 12:11:23 +00:00
Add ordercloud provider (#500)
* 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>
This commit is contained in:
34
framework/ordercloud/api/operations/get-all-product-paths.ts
Normal file
34
framework/ordercloud/api/operations/get-all-product-paths.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user