mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
WIP OrderCloud provider
This commit is contained in:
19
framework/ordercloud/api/operations/get-all-pages.ts
Normal file
19
framework/ordercloud/api/operations/get-all-pages.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export type Page = { url: string }
|
||||
export type GetAllPagesResult = { pages: Page[] }
|
||||
import type { OrdercloudConfig } from '../index'
|
||||
|
||||
export default function getAllPagesOperation() {
|
||||
function getAllPages({
|
||||
config,
|
||||
preview,
|
||||
}: {
|
||||
url?: string
|
||||
config?: Partial<OrdercloudConfig>
|
||||
preview?: boolean
|
||||
}): Promise<GetAllPagesResult> {
|
||||
return Promise.resolve({
|
||||
pages: [],
|
||||
})
|
||||
}
|
||||
return getAllPages
|
||||
}
|
16
framework/ordercloud/api/operations/get-all-product-paths.ts
Normal file
16
framework/ordercloud/api/operations/get-all-product-paths.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import data from '../../data.json'
|
||||
|
||||
export type GetAllProductPathsResult = {
|
||||
products: Array<{ path: string }>
|
||||
}
|
||||
|
||||
export default function getAllProductPathsOperation() {
|
||||
function getAllProductPaths(): Promise<GetAllProductPathsResult> {
|
||||
return Promise.resolve({
|
||||
products: []
|
||||
// products: data.products.map(({ path }) => ({ path })),
|
||||
})
|
||||
}
|
||||
|
||||
return getAllProductPaths
|
||||
}
|
44
framework/ordercloud/api/operations/get-all-products.ts
Normal file
44
framework/ordercloud/api/operations/get-all-products.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { GetAllProductsOperation } from '@commerce/types/product'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { OrdercloudConfig, Provider } from '../index'
|
||||
import {
|
||||
PriceSchedule,
|
||||
RawProduct,
|
||||
RawProductWithPrice,
|
||||
} from '@framework/types/product'
|
||||
import { normalize as normalizeProduct } from '@framework/utils/product'
|
||||
|
||||
export default function getAllProductsOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function getAllProducts<T extends GetAllProductsOperation>({
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: T['variables']
|
||||
config?: Partial<OrdercloudConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ products: Product[] }> {
|
||||
const { fetch } = commerce.getConfig(config)
|
||||
|
||||
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
||||
'GET',
|
||||
'/products'
|
||||
).then((response) => response.Items)
|
||||
const rawProductsWithPrice: RawProductWithPrice[] = await Promise.all(
|
||||
rawProducts.map(async (product) => ({
|
||||
...product,
|
||||
priceSchedule: await fetch<PriceSchedule>(
|
||||
'GET',
|
||||
`/priceschedules/${product.ID}`
|
||||
),
|
||||
}))
|
||||
)
|
||||
|
||||
return {
|
||||
products: rawProductsWithPrice.map(normalizeProduct),
|
||||
}
|
||||
}
|
||||
return getAllProducts
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
export default function getCustomerWishlistOperation() {
|
||||
function getCustomerWishlist(): any {
|
||||
return { wishlist: {} }
|
||||
}
|
||||
return getCustomerWishlist
|
||||
}
|
13
framework/ordercloud/api/operations/get-page.ts
Normal file
13
framework/ordercloud/api/operations/get-page.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export type Page = any
|
||||
export type GetPageResult = { page?: Page }
|
||||
|
||||
export type PageVariables = {
|
||||
id: number
|
||||
}
|
||||
|
||||
export default function getPageOperation() {
|
||||
function getPage(): Promise<GetPageResult> {
|
||||
return Promise.resolve({})
|
||||
}
|
||||
return getPage
|
||||
}
|
26
framework/ordercloud/api/operations/get-product.ts
Normal file
26
framework/ordercloud/api/operations/get-product.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { OrdercloudConfig } from '../index'
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { GetProductOperation } from '@commerce/types/product'
|
||||
import data from '../../data.json'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
|
||||
export default function getProductOperation({
|
||||
commerce,
|
||||
}: OperationContext<any>) {
|
||||
async function getProduct<T extends GetProductOperation>({
|
||||
query = '',
|
||||
variables,
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: T['variables']
|
||||
config?: Partial<OrdercloudConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<Product | {} | any> {
|
||||
return {
|
||||
product: null // data.products.find(({ slug }) => slug === variables!.slug),
|
||||
}
|
||||
}
|
||||
|
||||
return getProduct
|
||||
}
|
43
framework/ordercloud/api/operations/get-site-info.ts
Normal file
43
framework/ordercloud/api/operations/get-site-info.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Category } from '@commerce/types/site'
|
||||
import { OrdercloudConfig } from '../index'
|
||||
|
||||
export type GetSiteInfoResult<
|
||||
T extends { categories: any[]; brands: any[] } = {
|
||||
categories: Category[]
|
||||
brands: any[]
|
||||
}
|
||||
> = T
|
||||
|
||||
export default function getSiteInfoOperation({}: OperationContext<any>) {
|
||||
function getSiteInfo({
|
||||
query,
|
||||
variables,
|
||||
config: cfg,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: any
|
||||
config?: Partial<OrdercloudConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetSiteInfoResult> {
|
||||
return Promise.resolve({
|
||||
categories: [
|
||||
{
|
||||
id: 'new-arrivals',
|
||||
name: 'New Arrivals',
|
||||
slug: 'new-arrivals',
|
||||
path: '/new-arrivals',
|
||||
},
|
||||
{
|
||||
id: 'featured',
|
||||
name: 'Featured',
|
||||
slug: 'featured',
|
||||
path: '/featured',
|
||||
},
|
||||
],
|
||||
brands: [],
|
||||
})
|
||||
}
|
||||
|
||||
return getSiteInfo
|
||||
}
|
6
framework/ordercloud/api/operations/index.ts
Normal file
6
framework/ordercloud/api/operations/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export { default as getPage } from './get-page'
|
||||
export { default as getSiteInfo } from './get-site-info'
|
||||
export { default as getAllPages } from './get-all-pages'
|
||||
export { default as getProduct } from './get-product'
|
||||
export { default as getAllProducts } from './get-all-products'
|
||||
export { default as getAllProductPaths } from './get-all-product-paths'
|
Reference in New Issue
Block a user