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:
46
framework/ordercloud/api/operations/get-site-info.ts
Normal file
46
framework/ordercloud/api/operations/get-site-info.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { Category, GetSiteInfoOperation } from '@commerce/types/site'
|
||||
|
||||
import type { RawCategory } from '../../types/category'
|
||||
import type { OrdercloudConfig, Provider } from '../index'
|
||||
|
||||
export type GetSiteInfoResult<
|
||||
T extends { categories: any[]; brands: any[] } = {
|
||||
categories: Category[]
|
||||
brands: any[]
|
||||
}
|
||||
> = T
|
||||
|
||||
export default function getSiteInfoOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function getSiteInfo<T extends GetSiteInfoOperation>({
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: any
|
||||
config?: Partial<OrdercloudConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<T['data']> {
|
||||
// Get fetch from the config
|
||||
const { restBuyerFetch } = commerce.getConfig(config)
|
||||
|
||||
// Get list of categories
|
||||
const rawCategories: RawCategory[] = await restBuyerFetch<{
|
||||
Items: RawCategory[]
|
||||
}>('GET', `/me/categories`).then((response) => response.Items)
|
||||
|
||||
return {
|
||||
// Normalize categories
|
||||
categories: rawCategories.map((category) => ({
|
||||
id: category.ID,
|
||||
name: category.Name,
|
||||
slug: category.ID,
|
||||
path: `/${category.ID}`,
|
||||
})),
|
||||
brands: [],
|
||||
}
|
||||
}
|
||||
|
||||
return getSiteInfo
|
||||
}
|
Reference in New Issue
Block a user