diff --git a/framework/ordercloud/api/endpoints/cart/add-item.ts b/framework/ordercloud/api/endpoints/cart/add-item.ts index 8925a5c09..d292a3157 100644 --- a/framework/ordercloud/api/endpoints/cart/add-item.ts +++ b/framework/ordercloud/api/endpoints/cart/add-item.ts @@ -9,7 +9,7 @@ import { formatCart } from '../../utils/cart' const addItem: CartEndpoint['handlers']['addItem'] = async ({ res, body: { cartId, item }, - config: { storeRestFetch, cartCookie }, + config: { restFetch, cartCookie }, }) => { // Return an error if no item is present if (!item) { @@ -24,7 +24,7 @@ const addItem: CartEndpoint['handlers']['addItem'] = async ({ // Create an order if it doesn't exist if (!cartId) { - cartId = await storeRestFetch('POST', `/orders/Outgoing`).then( + cartId = await restFetch('POST', `/orders/Outgoing`).then( (response: { ID: string }) => response.ID ) } @@ -46,14 +46,14 @@ const addItem: CartEndpoint['handlers']['addItem'] = async ({ // If a variant is present, fetch its specs if (item.variantId) { - specs = await storeRestFetch( + specs = await restFetch( 'GET', `/me/products/${item.productId}/variants/${item.variantId}` ).then((res: RawVariant) => res.Specs) } // Add the item to the order - await storeRestFetch('POST', `/orders/Outgoing/${cartId}/lineitems`, { + await restFetch('POST', `/orders/Outgoing/${cartId}/lineitems`, { ProductID: item.productId, Quantity: item.quantity, Specs: specs, @@ -61,8 +61,8 @@ const addItem: CartEndpoint['handlers']['addItem'] = async ({ // Get cart const [cart, lineItems] = await Promise.all([ - storeRestFetch('GET', `/orders/Outgoing/${cartId}`), - storeRestFetch('GET', `/orders/Outgoing/${cartId}/lineitems`).then( + restFetch('GET', `/orders/Outgoing/${cartId}`), + restFetch('GET', `/orders/Outgoing/${cartId}/lineitems`).then( (response: { Items: OrdercloudLineItem[] }) => response.Items ), ]) diff --git a/framework/ordercloud/api/endpoints/cart/get-cart.ts b/framework/ordercloud/api/endpoints/cart/get-cart.ts index d7bf698fa..0340600e0 100644 --- a/framework/ordercloud/api/endpoints/cart/get-cart.ts +++ b/framework/ordercloud/api/endpoints/cart/get-cart.ts @@ -9,7 +9,7 @@ import { formatCart } from '../../utils/cart' const getCart: CartEndpoint['handlers']['getCart'] = async ({ res, body: { cartId }, - config: { storeRestFetch, cartCookie }, + config: { restFetch, cartCookie }, }) => { if (!cartId) { return res.status(400).json({ @@ -20,10 +20,10 @@ const getCart: CartEndpoint['handlers']['getCart'] = async ({ try { // Get cart - const cart = await storeRestFetch('GET', `/orders/Outgoing/${cartId}`) + const cart = await restFetch('GET', `/orders/Outgoing/${cartId}`) // Get line items - const lineItems = await storeRestFetch( + const lineItems = await restFetch( 'GET', `/orders/Outgoing/${cartId}/lineitems` ).then((response: { Items: OrdercloudLineItem[] }) => response.Items) diff --git a/framework/ordercloud/api/endpoints/cart/remove-item.ts b/framework/ordercloud/api/endpoints/cart/remove-item.ts index f31e63809..40a39aa3a 100644 --- a/framework/ordercloud/api/endpoints/cart/remove-item.ts +++ b/framework/ordercloud/api/endpoints/cart/remove-item.ts @@ -6,7 +6,7 @@ import { OrdercloudLineItem } from '../../../types/cart' const removeItem: CartEndpoint['handlers']['removeItem'] = async ({ res, body: { cartId, itemId }, - config: { storeRestFetch }, + config: { restFetch }, }) => { if (!cartId || !itemId) { return res.status(400).json({ @@ -16,15 +16,15 @@ const removeItem: CartEndpoint['handlers']['removeItem'] = async ({ } // Remove the item to the order - await storeRestFetch( + await restFetch( 'DELETE', `/orders/Outgoing/${cartId}/lineitems/${itemId}` ) // Get cart const [cart, lineItems] = await Promise.all([ - storeRestFetch('GET', `/orders/Outgoing/${cartId}`), - storeRestFetch('GET', `/orders/Outgoing/${cartId}/lineitems`).then( + restFetch('GET', `/orders/Outgoing/${cartId}`), + restFetch('GET', `/orders/Outgoing/${cartId}/lineitems`).then( (response: { Items: OrdercloudLineItem[] }) => response.Items ), ]) diff --git a/framework/ordercloud/api/endpoints/cart/update-item.ts b/framework/ordercloud/api/endpoints/cart/update-item.ts index 74356bf7b..e10ccc0ad 100644 --- a/framework/ordercloud/api/endpoints/cart/update-item.ts +++ b/framework/ordercloud/api/endpoints/cart/update-item.ts @@ -7,7 +7,7 @@ import { formatCart } from '../../utils/cart' const updateItem: CartEndpoint['handlers']['updateItem'] = async ({ res, body: { cartId, itemId, item }, - config: { storeRestFetch }, + config: { restFetch }, }) => { if (!cartId || !itemId || !item) { return res.status(400).json({ @@ -21,14 +21,14 @@ const updateItem: CartEndpoint['handlers']['updateItem'] = async ({ // If a variant is present, fetch its specs if (item.variantId) { - specs = await storeRestFetch( + specs = await restFetch( 'GET', `/me/products/${item.productId}/variants/${item.variantId}` ).then((res: RawVariant) => res.Specs) } // Add the item to the order - await storeRestFetch( + await restFetch( 'PATCH', `/orders/Outgoing/${cartId}/lineitems/${itemId}`, { @@ -40,8 +40,8 @@ const updateItem: CartEndpoint['handlers']['updateItem'] = async ({ // Get cart const [cart, lineItems] = await Promise.all([ - storeRestFetch('GET', `/orders/Outgoing/${cartId}`), - storeRestFetch('GET', `/orders/Outgoing/${cartId}/lineitems`).then( + restFetch('GET', `/orders/Outgoing/${cartId}`), + restFetch('GET', `/orders/Outgoing/${cartId}/lineitems`).then( (response: { Items: OrdercloudLineItem[] }) => response.Items ), ]) diff --git a/framework/ordercloud/api/index.ts b/framework/ordercloud/api/index.ts index 4dc1c2ba6..ad81811d2 100644 --- a/framework/ordercloud/api/index.ts +++ b/framework/ordercloud/api/index.ts @@ -10,7 +10,7 @@ import getProduct from './operations/get-product' import { API_URL, CART_COOKIE, CUSTOMER_COOKIE } from '../constants' export interface OrdercloudConfig extends CommerceAPIConfig { - storeRestFetch: ( + restFetch: ( method: string, resource: string, body?: Record, @@ -24,7 +24,7 @@ const config: OrdercloudConfig = { cartCookie: CART_COOKIE, customerCookie: CUSTOMER_COOKIE, cartCookieMaxAge: 2592000, - storeRestFetch: createRestFetcher(() => getCommerceApi().getConfig()), + restFetch: createRestFetcher(() => getCommerceApi().getConfig()), fetch: createGraphqlFetcher(() => getCommerceApi().getConfig()), } diff --git a/framework/ordercloud/api/operations/get-all-product-paths.ts b/framework/ordercloud/api/operations/get-all-product-paths.ts index b97d1ce52..e8966539c 100644 --- a/framework/ordercloud/api/operations/get-all-product-paths.ts +++ b/framework/ordercloud/api/operations/get-all-product-paths.ts @@ -17,10 +17,10 @@ export default function getAllProductPathsOperation({ config?: Partial } = {}): Promise { // Get fetch from the config - const { storeRestFetch } = commerce.getConfig(config) + const { restFetch } = commerce.getConfig(config) // Get all products - const rawProducts: RawProduct[] = await storeRestFetch<{ + const rawProducts: RawProduct[] = await restFetch<{ Items: RawProduct[] }>('GET', '/me/products').then((response) => response.Items) diff --git a/framework/ordercloud/api/operations/get-all-products.ts b/framework/ordercloud/api/operations/get-all-products.ts index 5930ee83c..6e1020e5d 100644 --- a/framework/ordercloud/api/operations/get-all-products.ts +++ b/framework/ordercloud/api/operations/get-all-products.ts @@ -18,10 +18,10 @@ export default function getAllProductsOperation({ preview?: boolean } = {}): Promise { // Get fetch from the config - const { storeRestFetch } = commerce.getConfig(config) + const { restFetch } = commerce.getConfig(config) // Get all products - const rawProducts: RawProduct[] = await storeRestFetch<{ + const rawProducts: RawProduct[] = await restFetch<{ Items: RawProduct[] }>('GET', '/me/products').then((response) => response.Items) diff --git a/framework/ordercloud/api/operations/get-product.ts b/framework/ordercloud/api/operations/get-product.ts index 7cb265171..9fba59b3a 100644 --- a/framework/ordercloud/api/operations/get-product.ts +++ b/framework/ordercloud/api/operations/get-product.ts @@ -19,22 +19,22 @@ export default function getProductOperation({ preview?: boolean } = {}): Promise { // Get fetch from the config - const { storeRestFetch } = commerce.getConfig(config) + const { restFetch } = commerce.getConfig(config) // Get a single product - const productPromise = storeRestFetch( + const productPromise = restFetch( 'GET', `/me/products/${variables?.slug}` ) // Get product specs - const specsPromise = storeRestFetch<{ Items: RawSpec[] }>( + const specsPromise = restFetch<{ Items: RawSpec[] }>( 'GET', `/me/products/${variables?.slug}/specs` ).then((res) => res.Items) // Get product variants - const variantsPromise = storeRestFetch<{ Items: RawVariant[] }>( + const variantsPromise = restFetch<{ Items: RawVariant[] }>( 'GET', `/me/products/${variables?.slug}/variants` ).then((res) => res.Items) diff --git a/framework/ordercloud/api/operations/get-site-info.ts b/framework/ordercloud/api/operations/get-site-info.ts index 2ed4e210e..247b2aa07 100644 --- a/framework/ordercloud/api/operations/get-site-info.ts +++ b/framework/ordercloud/api/operations/get-site-info.ts @@ -23,10 +23,10 @@ export default function getSiteInfoOperation({ preview?: boolean } = {}): Promise { // Get fetch from the config - const { storeRestFetch } = commerce.getConfig(config) + const { restFetch } = commerce.getConfig(config) // Get list of categories - const rawCategories: RawCategory[] = await storeRestFetch<{ + const rawCategories: RawCategory[] = await restFetch<{ Items: RawCategory[] }>('GET', `/me/categories`).then((response) => response.Items)