From b13e222e030195b4a41f1a35f5674b57788f431a Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Sun, 24 Oct 2021 17:22:03 +0200 Subject: [PATCH] Revert "merge main" --- .env.template | 4 - README.md | 1 - framework/commerce/api/index.ts | 4 +- framework/commerce/config.js | 1 - framework/commerce/types/checkout.ts | 2 +- framework/commerce/types/customer/address.ts | 98 ++++------ framework/commerce/types/customer/card.ts | 72 ++++--- framework/ordercloud/.env.template | 6 - framework/ordercloud/README.md | 3 - .../ordercloud/api/endpoints/cart/add-item.ts | 99 ---------- .../ordercloud/api/endpoints/cart/get-cart.ts | 65 ------- .../ordercloud/api/endpoints/cart/index.ts | 28 --- .../api/endpoints/cart/remove-item.ts | 45 ----- .../api/endpoints/cart/update-item.ts | 63 ------- .../catalog/products/get-products.ts | 37 ---- .../api/endpoints/catalog/products/index.ts | 19 -- .../api/endpoints/checkout/get-checkout.ts | 47 ----- .../api/endpoints/checkout/index.ts | 23 --- .../api/endpoints/checkout/submit-checkout.ts | 32 ---- .../endpoints/customer/address/add-item.ts | 47 ----- .../customer/address/get-addresses.ts | 9 - .../api/endpoints/customer/address/index.ts | 27 --- .../endpoints/customer/address/remove-item.ts | 9 - .../endpoints/customer/address/update-item.ts | 9 - .../api/endpoints/customer/card/add-item.ts | 74 -------- .../api/endpoints/customer/card/get-cards.ts | 9 - .../api/endpoints/customer/card/index.ts | 27 --- .../endpoints/customer/card/remove-item.ts | 9 - .../endpoints/customer/card/update-item.ts | 9 - .../api/endpoints/customer/index.ts | 1 - .../ordercloud/api/endpoints/login/index.ts | 1 - .../ordercloud/api/endpoints/logout/index.ts | 1 - .../ordercloud/api/endpoints/signup/index.ts | 1 - .../api/endpoints/wishlist/index.tsx | 1 - framework/ordercloud/api/index.ts | 71 ------- .../api/operations/get-all-pages.ts | 22 --- .../api/operations/get-all-product-paths.ts | 34 ---- .../api/operations/get-all-products.ts | 35 ---- .../ordercloud/api/operations/get-page.ts | 15 -- .../ordercloud/api/operations/get-product.ts | 60 ------ .../api/operations/get-site-info.ts | 46 ----- framework/ordercloud/api/operations/index.ts | 6 - framework/ordercloud/api/utils/cart.ts | 41 ---- .../ordercloud/api/utils/fetch-graphql.ts | 14 -- framework/ordercloud/api/utils/fetch-rest.ts | 176 ------------------ framework/ordercloud/auth/index.ts | 3 - framework/ordercloud/auth/use-login.tsx | 16 -- framework/ordercloud/auth/use-logout.tsx | 17 -- framework/ordercloud/auth/use-signup.tsx | 19 -- framework/ordercloud/cart/index.ts | 4 - framework/ordercloud/cart/use-add-item.tsx | 48 ----- framework/ordercloud/cart/use-cart.tsx | 33 ---- framework/ordercloud/cart/use-remove-item.tsx | 60 ------ framework/ordercloud/cart/use-update-item.tsx | 93 --------- framework/ordercloud/checkout/index.ts | 2 - .../ordercloud/checkout/use-checkout.tsx | 41 ---- .../checkout/use-submit-checkout.tsx | 36 ---- framework/ordercloud/commerce.config.json | 10 - framework/ordercloud/constants.ts | 6 - .../ordercloud/customer/address/index.ts | 4 - .../customer/address/use-add-item.tsx | 38 ---- .../customer/address/use-addresses.tsx | 35 ---- .../customer/address/use-remove-item.tsx | 62 ------ .../customer/address/use-update-item.tsx | 52 ------ framework/ordercloud/customer/card/index.ts | 4 - .../ordercloud/customer/card/use-add-item.tsx | 38 ---- .../ordercloud/customer/card/use-cards.tsx | 33 ---- .../customer/card/use-remove-item.tsx | 62 ------ .../customer/card/use-update-item.tsx | 52 ------ framework/ordercloud/customer/index.ts | 1 - .../ordercloud/customer/use-customer.tsx | 15 -- framework/ordercloud/fetcher.ts | 17 -- framework/ordercloud/index.tsx | 9 - framework/ordercloud/next.config.js | 8 - framework/ordercloud/product/index.ts | 2 - framework/ordercloud/product/use-price.tsx | 2 - framework/ordercloud/product/use-search.tsx | 40 ---- framework/ordercloud/provider.ts | 62 ------ framework/ordercloud/types/cart.ts | 126 ------------- framework/ordercloud/types/category.ts | 10 - framework/ordercloud/types/checkout.ts | 4 - .../ordercloud/types/customer/address.ts | 31 --- framework/ordercloud/types/customer/card.ts | 16 -- framework/ordercloud/types/node.d.ts | 5 - framework/ordercloud/types/product.ts | 55 ------ framework/ordercloud/utils/product.ts | 47 ----- .../ordercloud/wishlist/use-add-item.tsx | 13 -- .../ordercloud/wishlist/use-remove-item.tsx | 17 -- .../ordercloud/wishlist/use-wishlist.tsx | 43 ----- package.json | 1 - yarn.lock | 20 -- 91 files changed, 76 insertions(+), 2639 deletions(-) delete mode 100644 framework/ordercloud/.env.template delete mode 100644 framework/ordercloud/README.md delete mode 100644 framework/ordercloud/api/endpoints/cart/add-item.ts delete mode 100644 framework/ordercloud/api/endpoints/cart/get-cart.ts delete mode 100644 framework/ordercloud/api/endpoints/cart/index.ts delete mode 100644 framework/ordercloud/api/endpoints/cart/remove-item.ts delete mode 100644 framework/ordercloud/api/endpoints/cart/update-item.ts delete mode 100644 framework/ordercloud/api/endpoints/catalog/products/get-products.ts delete mode 100644 framework/ordercloud/api/endpoints/catalog/products/index.ts delete mode 100644 framework/ordercloud/api/endpoints/checkout/get-checkout.ts delete mode 100644 framework/ordercloud/api/endpoints/checkout/index.ts delete mode 100644 framework/ordercloud/api/endpoints/checkout/submit-checkout.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/address/add-item.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/address/get-addresses.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/address/index.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/address/remove-item.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/address/update-item.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/card/add-item.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/card/get-cards.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/card/index.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/card/remove-item.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/card/update-item.ts delete mode 100644 framework/ordercloud/api/endpoints/customer/index.ts delete mode 100644 framework/ordercloud/api/endpoints/login/index.ts delete mode 100644 framework/ordercloud/api/endpoints/logout/index.ts delete mode 100644 framework/ordercloud/api/endpoints/signup/index.ts delete mode 100644 framework/ordercloud/api/endpoints/wishlist/index.tsx delete mode 100644 framework/ordercloud/api/index.ts delete mode 100644 framework/ordercloud/api/operations/get-all-pages.ts delete mode 100644 framework/ordercloud/api/operations/get-all-product-paths.ts delete mode 100644 framework/ordercloud/api/operations/get-all-products.ts delete mode 100644 framework/ordercloud/api/operations/get-page.ts delete mode 100644 framework/ordercloud/api/operations/get-product.ts delete mode 100644 framework/ordercloud/api/operations/get-site-info.ts delete mode 100644 framework/ordercloud/api/operations/index.ts delete mode 100644 framework/ordercloud/api/utils/cart.ts delete mode 100644 framework/ordercloud/api/utils/fetch-graphql.ts delete mode 100644 framework/ordercloud/api/utils/fetch-rest.ts delete mode 100644 framework/ordercloud/auth/index.ts delete mode 100644 framework/ordercloud/auth/use-login.tsx delete mode 100644 framework/ordercloud/auth/use-logout.tsx delete mode 100644 framework/ordercloud/auth/use-signup.tsx delete mode 100644 framework/ordercloud/cart/index.ts delete mode 100644 framework/ordercloud/cart/use-add-item.tsx delete mode 100644 framework/ordercloud/cart/use-cart.tsx delete mode 100644 framework/ordercloud/cart/use-remove-item.tsx delete mode 100644 framework/ordercloud/cart/use-update-item.tsx delete mode 100644 framework/ordercloud/checkout/index.ts delete mode 100644 framework/ordercloud/checkout/use-checkout.tsx delete mode 100644 framework/ordercloud/checkout/use-submit-checkout.tsx delete mode 100644 framework/ordercloud/commerce.config.json delete mode 100644 framework/ordercloud/constants.ts delete mode 100644 framework/ordercloud/customer/address/index.ts delete mode 100644 framework/ordercloud/customer/address/use-add-item.tsx delete mode 100644 framework/ordercloud/customer/address/use-addresses.tsx delete mode 100644 framework/ordercloud/customer/address/use-remove-item.tsx delete mode 100644 framework/ordercloud/customer/address/use-update-item.tsx delete mode 100644 framework/ordercloud/customer/card/index.ts delete mode 100644 framework/ordercloud/customer/card/use-add-item.tsx delete mode 100644 framework/ordercloud/customer/card/use-cards.tsx delete mode 100644 framework/ordercloud/customer/card/use-remove-item.tsx delete mode 100644 framework/ordercloud/customer/card/use-update-item.tsx delete mode 100644 framework/ordercloud/customer/index.ts delete mode 100644 framework/ordercloud/customer/use-customer.tsx delete mode 100644 framework/ordercloud/fetcher.ts delete mode 100644 framework/ordercloud/index.tsx delete mode 100644 framework/ordercloud/next.config.js delete mode 100644 framework/ordercloud/product/index.ts delete mode 100644 framework/ordercloud/product/use-price.tsx delete mode 100644 framework/ordercloud/product/use-search.tsx delete mode 100644 framework/ordercloud/provider.ts delete mode 100644 framework/ordercloud/types/cart.ts delete mode 100644 framework/ordercloud/types/category.ts delete mode 100644 framework/ordercloud/types/checkout.ts delete mode 100644 framework/ordercloud/types/customer/address.ts delete mode 100644 framework/ordercloud/types/customer/card.ts delete mode 100644 framework/ordercloud/types/node.d.ts delete mode 100644 framework/ordercloud/types/product.ts delete mode 100644 framework/ordercloud/utils/product.ts delete mode 100644 framework/ordercloud/wishlist/use-add-item.tsx delete mode 100644 framework/ordercloud/wishlist/use-remove-item.tsx delete mode 100644 framework/ordercloud/wishlist/use-wishlist.tsx diff --git a/.env.template b/.env.template index a5885494e..b24458b80 100644 --- a/.env.template +++ b/.env.template @@ -23,7 +23,3 @@ NEXT_PUBLIC_SALEOR_CHANNEL= NEXT_PUBLIC_VENDURE_SHOP_API_URL= NEXT_PUBLIC_VENDURE_LOCAL_URL= - -ORDERCLOUD_CLIENT_ID= -ORDERCLOUD_CLIENT_SECRET= -STRIPE_SECRET= diff --git a/README.md b/README.md index 092afa1b1..2eeea375b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ Demo live at: [demo.vercel.store](https://demo.vercel.store/) - BigCommerce Demo: https://bigcommerce.vercel.store/ - Vendure Demo: https://vendure.vercel.store - Saleor Demo: https://saleor.vercel.store/ -- Ordercloud Demo: https://ordercloud.vercel.store/ ## Features diff --git a/framework/commerce/api/index.ts b/framework/commerce/api/index.ts index d7ba37059..716c11ed5 100644 --- a/framework/commerce/api/index.ts +++ b/framework/commerce/api/index.ts @@ -65,8 +65,8 @@ export type EndpointHandlers< [H in keyof E['handlers']]: APIHandler< C, EndpointHandlers, - NonNullable['data'], - NonNullable['body'], + E['handlers'][H]['data'], + E['handlers'][H]['body'], E['options'] > } diff --git a/framework/commerce/config.js b/framework/commerce/config.js index 2aaa80a0b..04248d2f9 100644 --- a/framework/commerce/config.js +++ b/framework/commerce/config.js @@ -15,7 +15,6 @@ const PROVIDERS = [ 'swell', 'vendure', 'medusa', - 'ordercloud', ] function getProviderName() { diff --git a/framework/commerce/types/checkout.ts b/framework/commerce/types/checkout.ts index d75b63902..58b895368 100644 --- a/framework/commerce/types/checkout.ts +++ b/framework/commerce/types/checkout.ts @@ -30,7 +30,7 @@ export type GetCheckoutHook = { } export type CheckoutHooks = { - submitCheckout?: SubmitCheckoutHook + submitCheckout: SubmitCheckoutHook getCheckout: GetCheckoutHook } diff --git a/framework/commerce/types/customer/address.ts b/framework/commerce/types/customer/address.ts index 8dc6ffc0d..5b6ca4b49 100644 --- a/framework/commerce/types/customer/address.ts +++ b/framework/commerce/types/customer/address.ts @@ -1,46 +1,41 @@ export interface Address { - id: string - mask: string + id: string; + mask: string; } export interface AddressFields { - type: string - firstName: string - lastName: string - company: string - streetNumber: string - apartments: string - zipCode: string - city: string - country: string + type: string; + firstName: string; + lastName: string; + company: string; + streetNumber: string; + apartments: string; + zipCode: string; + city: string; + country: string; } export type CustomerAddressTypes = { - address?: Address - fields: AddressFields + address?: Address; + fields: AddressFields; } -export type GetAddressesHook< - T extends CustomerAddressTypes = CustomerAddressTypes -> = { - data: T['address'][] | null +export type GetAddressesHook = { + data: T['address'] | null input: {} fetcherInput: { cartId?: string } swrState: { isEmpty: boolean } } -export type AddItemHook = - { - data: T['address'] - input?: T['fields'] - fetcherInput: T['fields'] - body: { item: T['fields'] } - actionInput: T['fields'] - } +export type AddItemHook = { + data: T['address'] + input?: T['fields'] + fetcherInput: T['fields'] + body: { item: T['fields'] } + actionInput: T['fields'] +} -export type UpdateItemHook< - T extends CustomerAddressTypes = CustomerAddressTypes -> = { +export type UpdateItemHook = { data: T['address'] | null input: { item?: T['fields']; wait?: number } fetcherInput: { itemId: string; item: T['fields'] } @@ -48,62 +43,49 @@ export type UpdateItemHook< actionInput: T['fields'] & { id: string } } -export type RemoveItemHook< - T extends CustomerAddressTypes = CustomerAddressTypes -> = { +export type RemoveItemHook = { data: T['address'] | null - input: { item?: T['address'] } + input: { item?: T['fields'] } fetcherInput: { itemId: string } body: { itemId: string } actionInput: { id: string } } -export type CustomerAddressHooks< - T extends CustomerAddressTypes = CustomerAddressTypes -> = { +export type CustomerAddressHooks = { getAddresses: GetAddressesHook addItem: AddItemHook updateItem: UpdateItemHook removeItem: RemoveItemHook } -export type AddressHandler< - T extends CustomerAddressTypes = CustomerAddressTypes -> = GetAddressesHook & { +export type AddresssHandler = GetAddressesHook & { body: { cartId?: string } } -export type AddItemHandler< - T extends CustomerAddressTypes = CustomerAddressTypes -> = AddItemHook & { +export type AddItemHandler = AddItemHook & { body: { cartId: string } } -export type UpdateItemHandler< - T extends CustomerAddressTypes = CustomerAddressTypes -> = UpdateItemHook & { - data: T['address'] - body: { cartId: string } -} +export type UpdateItemHandler = + UpdateItemHook & { + data: T['address'] + body: { cartId: string } + } -export type RemoveItemHandler< - T extends CustomerAddressTypes = CustomerAddressTypes -> = RemoveItemHook & { - body: { cartId: string } -} +export type RemoveItemHandler = + RemoveItemHook & { + body: { cartId: string } + } -export type CustomerAddressHandlers< - T extends CustomerAddressTypes = CustomerAddressTypes -> = { + +export type CustomerAddressHandlers = { getAddresses: GetAddressesHook addItem: AddItemHandler updateItem: UpdateItemHandler removeItem: RemoveItemHandler } -export type CustomerAddressSchema< - T extends CustomerAddressTypes = CustomerAddressTypes -> = { +export type CustomerAddressSchema = { endpoint: { options: {} handlers: CustomerAddressHandlers diff --git a/framework/commerce/types/customer/card.ts b/framework/commerce/types/customer/card.ts index e9b220dcc..a8731411f 100644 --- a/framework/commerce/types/customer/card.ts +++ b/framework/commerce/types/customer/card.ts @@ -1,30 +1,30 @@ export interface Card { - id: string - mask: string - provider: string + id: string; + mask: string; + provider: string; } export interface CardFields { - cardHolder: string - cardNumber: string - cardExpireDate: string - cardCvc: string - firstName: string - lastName: string - company: string - streetNumber: string - zipCode: string - city: string - country: string + cardHolder: string; + cardNumber: string; + cardExpireDate: string; + cardCvc: string; + firstName: string; + lastName: string; + company: string; + streetNumber: string; + zipCode: string; + city: string; + country: string; } export type CustomerCardTypes = { - card?: Card - fields: CardFields + card?: Card; + fields: CardFields; } export type GetCardsHook = { - data: T['card'][] | null + data: T['card'] | null input: {} fetcherInput: { cartId?: string } swrState: { isEmpty: boolean } @@ -48,29 +48,26 @@ export type UpdateItemHook = { export type RemoveItemHook = { data: T['card'] | null - input: { item?: T['card'] } + input: { item?: T['fields'] } fetcherInput: { itemId: string } body: { itemId: string } actionInput: { id: string } } -export type CustomerCardHooks = - { - getCards: GetCardsHook - addItem: AddItemHook - updateItem: UpdateItemHook - removeItem: RemoveItemHook - } +export type CustomerCardHooks = { + getCards: GetCardsHook + addItem: AddItemHook + updateItem: UpdateItemHook + removeItem: RemoveItemHook +} -export type CardsHandler = - GetCardsHook & { - body: { cartId?: string } - } +export type CardsHandler = GetCardsHook & { + body: { cartId?: string } +} -export type AddItemHandler = - AddItemHook & { - body: { cartId: string } - } +export type AddItemHandler = AddItemHook & { + body: { cartId: string } +} export type UpdateItemHandler = UpdateItemHook & { @@ -83,18 +80,15 @@ export type RemoveItemHandler = body: { cartId: string } } -export type CustomerCardHandlers< - T extends CustomerCardTypes = CustomerCardTypes -> = { + +export type CustomerCardHandlers = { getCards: GetCardsHook addItem: AddItemHandler updateItem: UpdateItemHandler removeItem: RemoveItemHandler } -export type CustomerCardSchema< - T extends CustomerCardTypes = CustomerCardTypes -> = { +export type CustomerCardSchema = { endpoint: { options: {} handlers: CustomerCardHandlers diff --git a/framework/ordercloud/.env.template b/framework/ordercloud/.env.template deleted file mode 100644 index 52406251a..000000000 --- a/framework/ordercloud/.env.template +++ /dev/null @@ -1,6 +0,0 @@ -COMMERCE_PROVIDER=ordercloud - -ORDERCLOUD_BUYER_CLIENT_ID= -ORDERCLOUD_MIDDLEWARE_CLIENT_ID= -ORDERCLOUD_MIDDLEWARE_CLIENT_SECRET= -STRIPE_SECRET= diff --git a/framework/ordercloud/README.md b/framework/ordercloud/README.md deleted file mode 100644 index ca1438eae..000000000 --- a/framework/ordercloud/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Next.js Ordercloud Provider - -Create your own store from [here](https://nextjs.org/commerce) diff --git a/framework/ordercloud/api/endpoints/cart/add-item.ts b/framework/ordercloud/api/endpoints/cart/add-item.ts deleted file mode 100644 index 28d372bd0..000000000 --- a/framework/ordercloud/api/endpoints/cart/add-item.ts +++ /dev/null @@ -1,99 +0,0 @@ -import type { CartEndpoint } from '.' -import type { RawVariant } from '../../../types/product' -import type { OrdercloudLineItem } from '../../../types/cart' - -import { serialize } from 'cookie' - -import { formatCart } from '../../utils/cart' - -const addItem: CartEndpoint['handlers']['addItem'] = async ({ - res, - body: { cartId, item }, - config: { restBuyerFetch, cartCookie, tokenCookie }, -}) => { - // Return an error if no item is present - if (!item) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Missing item' }], - }) - } - - // Store token - let token - - // Set the quantity if not present - if (!item.quantity) item.quantity = 1 - - // Create an order if it doesn't exist - if (!cartId) { - const { ID, meta } = await restBuyerFetch( - 'POST', - `/orders/Outgoing`, - {} - ).then((response: { ID: string; meta: { token: string } }) => response) - - // Set the cart id and token - cartId = ID - token = meta.token - - // Set the cart and token cookie - res.setHeader('Set-Cookie', [ - serialize(tokenCookie, meta.token, { - maxAge: 60 * 60 * 24 * 30, - expires: new Date(Date.now() + 60 * 60 * 24 * 30 * 1000), - secure: process.env.NODE_ENV === 'production', - path: '/', - sameSite: 'lax', - }), - serialize(cartCookie, cartId, { - maxAge: 60 * 60 * 24 * 30, - expires: new Date(Date.now() + 60 * 60 * 24 * 30 * 1000), - secure: process.env.NODE_ENV === 'production', - path: '/', - sameSite: 'lax', - }), - ]) - } - - // Store specs - let specs: RawVariant['Specs'] = [] - - // If a variant is present, fetch its specs - if (item.variantId) { - specs = await restBuyerFetch( - 'GET', - `/me/products/${item.productId}/variants/${item.variantId}`, - null, - { token } - ).then((res: RawVariant) => res.Specs) - } - - // Add the item to the order - await restBuyerFetch( - 'POST', - `/orders/Outgoing/${cartId}/lineitems`, - { - ProductID: item.productId, - Quantity: item.quantity, - Specs: specs, - }, - { token } - ) - - // Get cart - const [cart, lineItems] = await Promise.all([ - restBuyerFetch('GET', `/orders/Outgoing/${cartId}`, null, { token }), - restBuyerFetch('GET', `/orders/Outgoing/${cartId}/lineitems`, null, { - token, - }).then((response: { Items: OrdercloudLineItem[] }) => response.Items), - ]) - - // Format cart - const formattedCart = formatCart(cart, lineItems) - - // Return cart and errors - res.status(200).json({ data: formattedCart, errors: [] }) -} - -export default addItem diff --git a/framework/ordercloud/api/endpoints/cart/get-cart.ts b/framework/ordercloud/api/endpoints/cart/get-cart.ts deleted file mode 100644 index 7ea077b54..000000000 --- a/framework/ordercloud/api/endpoints/cart/get-cart.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { OrdercloudLineItem } from '../../../types/cart' -import type { CartEndpoint } from '.' - -import { serialize } from 'cookie' - -import { formatCart } from '../../utils/cart' - -// Return current cart info -const getCart: CartEndpoint['handlers']['getCart'] = async ({ - req, - res, - body: { cartId }, - config: { restBuyerFetch, cartCookie, tokenCookie }, -}) => { - if (!cartId) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Invalid request' }], - }) - } - - try { - // Get token from cookies - const token = req.cookies[tokenCookie] - - // Get cart - const cart = await restBuyerFetch( - 'GET', - `/orders/Outgoing/${cartId}`, - null, - { token } - ) - - // Get line items - const lineItems = await restBuyerFetch( - 'GET', - `/orders/Outgoing/${cartId}/lineitems`, - null, - { token } - ).then((response: { Items: OrdercloudLineItem[] }) => response.Items) - - // Format cart - const formattedCart = formatCart(cart, lineItems) - - // Return cart and errors - res.status(200).json({ data: formattedCart, errors: [] }) - } catch (error) { - // Reset cart and token cookie - res.setHeader('Set-Cookie', [ - serialize(cartCookie, cartId, { - maxAge: -1, - path: '/', - }), - serialize(tokenCookie, cartId, { - maxAge: -1, - path: '/', - }), - ]) - - // Return empty cart - res.status(200).json({ data: null, errors: [] }) - } -} - -export default getCart diff --git a/framework/ordercloud/api/endpoints/cart/index.ts b/framework/ordercloud/api/endpoints/cart/index.ts deleted file mode 100644 index 756bce9fe..000000000 --- a/framework/ordercloud/api/endpoints/cart/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { CartSchema } from '../../../types/cart' -import type { OrdercloudAPI } from '../..' - -import { GetAPISchema, createEndpoint } from '@commerce/api' -import cartEndpoint from '@commerce/api/endpoints/cart' - -import getCart from './get-cart' -import addItem from './add-item' -import updateItem from './update-item' -import removeItem from './remove-item' - -export type CartAPI = GetAPISchema - -export type CartEndpoint = CartAPI['endpoint'] - -export const handlers: CartEndpoint['handlers'] = { - getCart, - addItem, - updateItem, - removeItem, -} - -const cartApi = createEndpoint({ - handler: cartEndpoint, - handlers, -}) - -export default cartApi diff --git a/framework/ordercloud/api/endpoints/cart/remove-item.ts b/framework/ordercloud/api/endpoints/cart/remove-item.ts deleted file mode 100644 index ea9c46e4c..000000000 --- a/framework/ordercloud/api/endpoints/cart/remove-item.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { CartEndpoint } from '.' - -import { formatCart } from '../../utils/cart' -import { OrdercloudLineItem } from '../../../types/cart' - -const removeItem: CartEndpoint['handlers']['removeItem'] = async ({ - req, - res, - body: { cartId, itemId }, - config: { restBuyerFetch, tokenCookie }, -}) => { - if (!cartId || !itemId) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Invalid request' }], - }) - } - - // Get token from cookies - const token = req.cookies[tokenCookie] - - // Remove the item to the order - await restBuyerFetch( - 'DELETE', - `/orders/Outgoing/${cartId}/lineitems/${itemId}`, - null, - { token } - ) - - // Get cart - const [cart, lineItems] = await Promise.all([ - restBuyerFetch('GET', `/orders/Outgoing/${cartId}`, null, { token }), - restBuyerFetch('GET', `/orders/Outgoing/${cartId}/lineitems`, null, { - token, - }).then((response: { Items: OrdercloudLineItem[] }) => response.Items), - ]) - - // Format cart - const formattedCart = formatCart(cart, lineItems) - - // Return cart and errors - res.status(200).json({ data: formattedCart, errors: [] }) -} - -export default removeItem diff --git a/framework/ordercloud/api/endpoints/cart/update-item.ts b/framework/ordercloud/api/endpoints/cart/update-item.ts deleted file mode 100644 index 20113baee..000000000 --- a/framework/ordercloud/api/endpoints/cart/update-item.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { OrdercloudLineItem } from '../../../types/cart' -import type { RawVariant } from '../../../types/product' -import type { CartEndpoint } from '.' - -import { formatCart } from '../../utils/cart' - -const updateItem: CartEndpoint['handlers']['updateItem'] = async ({ - req, - res, - body: { cartId, itemId, item }, - config: { restBuyerFetch, tokenCookie }, -}) => { - if (!cartId || !itemId || !item) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Invalid request' }], - }) - } - - // Get token from cookies - const token = req.cookies[tokenCookie] - - // Store specs - let specs: RawVariant['Specs'] = [] - - // If a variant is present, fetch its specs - if (item.variantId) { - specs = await restBuyerFetch( - 'GET', - `/me/products/${item.productId}/variants/${item.variantId}`, - null, - { token } - ).then((res: RawVariant) => res.Specs) - } - - // Add the item to the order - await restBuyerFetch( - 'PATCH', - `/orders/Outgoing/${cartId}/lineitems/${itemId}`, - { - ProductID: item.productId, - Quantity: item.quantity, - Specs: specs, - }, - { token } - ) - - // Get cart - const [cart, lineItems] = await Promise.all([ - restBuyerFetch('GET', `/orders/Outgoing/${cartId}`, null, { token }), - restBuyerFetch('GET', `/orders/Outgoing/${cartId}/lineitems`, null, { - token, - }).then((response: { Items: OrdercloudLineItem[] }) => response.Items), - ]) - - // Format cart - const formattedCart = formatCart(cart, lineItems) - - // Return cart and errors - res.status(200).json({ data: formattedCart, errors: [] }) -} - -export default updateItem diff --git a/framework/ordercloud/api/endpoints/catalog/products/get-products.ts b/framework/ordercloud/api/endpoints/catalog/products/get-products.ts deleted file mode 100644 index ad8d391ac..000000000 --- a/framework/ordercloud/api/endpoints/catalog/products/get-products.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { normalize as normalizeProduct } from '../../../../utils/product' -import { ProductsEndpoint } from '.' - -// Get products for the product list page. Search and category filter implemented. Sort and brand filter not implemented. -const getProducts: ProductsEndpoint['handlers']['getProducts'] = async ({ - req, - res, - body: { search, categoryId, brandId, sort }, - config: { restBuyerFetch, cartCookie, tokenCookie }, -}) => { - //Use a dummy base as we only care about the relative path - const url = new URL('/me/products', 'http://a') - - if (search) { - url.searchParams.set('search', search) - } - if (categoryId) { - url.searchParams.set('categoryID', String(categoryId)) - } - - // Get token from cookies - const token = req.cookies[tokenCookie] - - var rawProducts = await restBuyerFetch( - 'GET', - url.pathname + url.search, - null, - { token } - ) - - const products = rawProducts.Items.map(normalizeProduct) - const found = rawProducts?.Items?.length > 0 - - res.status(200).json({ data: { products, found } }) -} - -export default getProducts diff --git a/framework/ordercloud/api/endpoints/catalog/products/index.ts b/framework/ordercloud/api/endpoints/catalog/products/index.ts deleted file mode 100644 index 98727a3d3..000000000 --- a/framework/ordercloud/api/endpoints/catalog/products/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { OrdercloudAPI } from '../../../../api' - -import { createEndpoint, GetAPISchema } from '@commerce/api' -import { ProductsSchema } from '@commerce/types/product' -import getProducts from './get-products' -import productsEndpoint from '@commerce/api/endpoints/catalog/products' - -export type ProductsAPI = GetAPISchema - -export type ProductsEndpoint = ProductsAPI['endpoint'] - -export const handlers: ProductsEndpoint['handlers'] = { getProducts } - -const productsApi = createEndpoint({ - handler: productsEndpoint, - handlers, -}) - -export default productsApi diff --git a/framework/ordercloud/api/endpoints/checkout/get-checkout.ts b/framework/ordercloud/api/endpoints/checkout/get-checkout.ts deleted file mode 100644 index c0ab1a40d..000000000 --- a/framework/ordercloud/api/endpoints/checkout/get-checkout.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { CheckoutEndpoint } from '.' - -const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ - req, - res, - body: { cartId }, - config: { restBuyerFetch, tokenCookie }, -}) => { - // Return an error if no item is present - if (!cartId) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Missing cookie' }], - }) - } - - // Get token from cookies - const token = req.cookies[tokenCookie] - - // Register credit card - const payments = await restBuyerFetch( - 'GET', - `/orders/Outgoing/${cartId}/payments`, - null, - { token } - ).then((response: { Items: unknown[] }) => response.Items) - - const address = await restBuyerFetch( - 'GET', - `/orders/Outgoing/${cartId}`, - null, - { token } - ).then( - (response: { ShippingAddressID: string }) => response.ShippingAddressID - ) - - // Return cart and errors - res.status(200).json({ - data: { - hasPayment: payments.length > 0, - hasShipping: Boolean(address), - }, - errors: [], - }) -} - -export default getCheckout diff --git a/framework/ordercloud/api/endpoints/checkout/index.ts b/framework/ordercloud/api/endpoints/checkout/index.ts deleted file mode 100644 index e1b8a9f1c..000000000 --- a/framework/ordercloud/api/endpoints/checkout/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { CheckoutSchema } from '../../../types/checkout' -import type { OrdercloudAPI } from '../..' - -import { GetAPISchema, createEndpoint } from '@commerce/api' -import checkoutEndpoint from '@commerce/api/endpoints/checkout' - -import getCheckout from './get-checkout' -import submitCheckout from './submit-checkout' - -export type CheckoutAPI = GetAPISchema -export type CheckoutEndpoint = CheckoutAPI['endpoint'] - -export const handlers: CheckoutEndpoint['handlers'] = { - getCheckout, - submitCheckout, -} - -const checkoutApi = createEndpoint({ - handler: checkoutEndpoint, - handlers, -}) - -export default checkoutApi diff --git a/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts b/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts deleted file mode 100644 index 8cd9be5e4..000000000 --- a/framework/ordercloud/api/endpoints/checkout/submit-checkout.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { CheckoutEndpoint } from '.' - -const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({ - req, - res, - body: { cartId }, - config: { restBuyerFetch, tokenCookie }, -}) => { - // Return an error if no item is present - if (!cartId) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Missing item' }], - }) - } - - // Get token from cookies - const token = req.cookies[tokenCookie] - - // Submit order - await restBuyerFetch( - 'POST', - `/orders/Outgoing/${cartId}/submit`, - {}, - { token } - ) - - // Return cart and errors - res.status(200).json({ data: null, errors: [] }) -} - -export default submitCheckout diff --git a/framework/ordercloud/api/endpoints/customer/address/add-item.ts b/framework/ordercloud/api/endpoints/customer/address/add-item.ts deleted file mode 100644 index 434c2400d..000000000 --- a/framework/ordercloud/api/endpoints/customer/address/add-item.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { CustomerAddressEndpoint } from '.' - -const addItem: CustomerAddressEndpoint['handlers']['addItem'] = async ({ - res, - body: { item, cartId }, - config: { restBuyerFetch }, -}) => { - // Return an error if no item is present - if (!item) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Missing item' }], - }) - } - - // Return an error if no item is present - if (!cartId) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Cookie not found' }], - }) - } - - // Register address - const address = await restBuyerFetch('POST', `/me/addresses`, { - AddressName: 'main address', - CompanyName: item.company, - FirstName: item.firstName, - LastName: item.lastName, - Street1: item.streetNumber, - Street2: item.streetNumber, - City: item.city, - State: item.city, - Zip: item.zipCode, - Country: item.country.slice(0, 2).toLowerCase(), - Shipping: true, - }).then((response: { ID: string }) => response.ID) - - // Assign address to order - await restBuyerFetch('PATCH', `/orders/Outgoing/${cartId}`, { - ShippingAddressID: address, - }) - - return res.status(200).json({ data: null, errors: [] }) -} - -export default addItem diff --git a/framework/ordercloud/api/endpoints/customer/address/get-addresses.ts b/framework/ordercloud/api/endpoints/customer/address/get-addresses.ts deleted file mode 100644 index 2e27591c0..000000000 --- a/framework/ordercloud/api/endpoints/customer/address/get-addresses.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CustomerAddressEndpoint } from '.' - -const getCards: CustomerAddressEndpoint['handlers']['getAddresses'] = async ({ - res, -}) => { - return res.status(200).json({ data: null, errors: [] }) -} - -export default getCards diff --git a/framework/ordercloud/api/endpoints/customer/address/index.ts b/framework/ordercloud/api/endpoints/customer/address/index.ts deleted file mode 100644 index 385bc57f1..000000000 --- a/framework/ordercloud/api/endpoints/customer/address/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { CustomerAddressSchema } from '../../../../types/customer/address' -import type { OrdercloudAPI } from '../../..' - -import { GetAPISchema, createEndpoint } from '@commerce/api' -import customerAddressEndpoint from '@commerce/api/endpoints/customer/address' - -import getAddresses from './get-addresses' -import addItem from './add-item' -import updateItem from './update-item' -import removeItem from './remove-item' - -export type CustomerAddressAPI = GetAPISchema -export type CustomerAddressEndpoint = CustomerAddressAPI['endpoint'] - -export const handlers: CustomerAddressEndpoint['handlers'] = { - getAddresses, - addItem, - updateItem, - removeItem, -} - -const customerAddressApi = createEndpoint({ - handler: customerAddressEndpoint, - handlers, -}) - -export default customerAddressApi diff --git a/framework/ordercloud/api/endpoints/customer/address/remove-item.ts b/framework/ordercloud/api/endpoints/customer/address/remove-item.ts deleted file mode 100644 index fba4e1154..000000000 --- a/framework/ordercloud/api/endpoints/customer/address/remove-item.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CustomerAddressEndpoint } from '.' - -const removeItem: CustomerAddressEndpoint['handlers']['removeItem'] = async ({ - res, -}) => { - return res.status(200).json({ data: null, errors: [] }) -} - -export default removeItem diff --git a/framework/ordercloud/api/endpoints/customer/address/update-item.ts b/framework/ordercloud/api/endpoints/customer/address/update-item.ts deleted file mode 100644 index 4c4b4b9ae..000000000 --- a/framework/ordercloud/api/endpoints/customer/address/update-item.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CustomerAddressEndpoint } from '.' - -const updateItem: CustomerAddressEndpoint['handlers']['updateItem'] = async ({ - res, -}) => { - return res.status(200).json({ data: null, errors: [] }) -} - -export default updateItem diff --git a/framework/ordercloud/api/endpoints/customer/card/add-item.ts b/framework/ordercloud/api/endpoints/customer/card/add-item.ts deleted file mode 100644 index ad7dead7c..000000000 --- a/framework/ordercloud/api/endpoints/customer/card/add-item.ts +++ /dev/null @@ -1,74 +0,0 @@ -import type { CustomerCardEndpoint } from '.' -import type { OredercloudCreditCard } from '../../../../types/customer/card' - -import Stripe from 'stripe' - -const stripe = new Stripe(process.env.STRIPE_SECRET as string, { - apiVersion: '2020-08-27', -}) - -const addItem: CustomerCardEndpoint['handlers']['addItem'] = async ({ - res, - body: { item, cartId }, - config: { restBuyerFetch, restMiddlewareFetch }, -}) => { - // Return an error if no item is present - if (!item) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Missing item' }], - }) - } - - // Return an error if no item is present - if (!cartId) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Cookie not found' }], - }) - } - - // Get token - const token = await stripe.tokens - .create({ - card: { - number: item.cardNumber, - exp_month: item.cardExpireDate.split('/')[0], - exp_year: item.cardExpireDate.split('/')[1], - cvc: item.cardCvc, - }, - }) - .then((res: { id: string }) => res.id) - - // Register credit card - const creditCard = await restBuyerFetch('POST', `/me/creditcards`, { - Token: token, - CardType: 'credit', - PartialAccountNumber: item.cardNumber.slice(-4), - CardholderName: item.cardHolder, - ExpirationDate: item.cardExpireDate, - }).then((response: OredercloudCreditCard) => response.ID) - - // Assign payment to order - const payment = await restBuyerFetch( - 'POST', - `/orders/All/${cartId}/payments`, - { - Type: 'CreditCard', - CreditCardID: creditCard, - } - ).then((response: { ID: string }) => response.ID) - - // Accept payment to order - await restMiddlewareFetch( - 'PATCH', - `/orders/All/${cartId}/payments/${payment}`, - { - Accepted: true, - } - ) - - return res.status(200).json({ data: null, errors: [] }) -} - -export default addItem diff --git a/framework/ordercloud/api/endpoints/customer/card/get-cards.ts b/framework/ordercloud/api/endpoints/customer/card/get-cards.ts deleted file mode 100644 index e77520803..000000000 --- a/framework/ordercloud/api/endpoints/customer/card/get-cards.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CustomerCardEndpoint } from '.' - -const getCards: CustomerCardEndpoint['handlers']['getCards'] = async ({ - res, -}) => { - return res.status(200).json({ data: null, errors: [] }) -} - -export default getCards diff --git a/framework/ordercloud/api/endpoints/customer/card/index.ts b/framework/ordercloud/api/endpoints/customer/card/index.ts deleted file mode 100644 index 672939a8b..000000000 --- a/framework/ordercloud/api/endpoints/customer/card/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { CustomerCardSchema } from '../../../../types/customer/card' -import type { OrdercloudAPI } from '../../..' - -import { GetAPISchema, createEndpoint } from '@commerce/api' -import customerCardEndpoint from '@commerce/api/endpoints/customer/card' - -import getCards from './get-cards' -import addItem from './add-item' -import updateItem from './update-item' -import removeItem from './remove-item' - -export type CustomerCardAPI = GetAPISchema -export type CustomerCardEndpoint = CustomerCardAPI['endpoint'] - -export const handlers: CustomerCardEndpoint['handlers'] = { - getCards, - addItem, - updateItem, - removeItem, -} - -const customerCardApi = createEndpoint({ - handler: customerCardEndpoint, - handlers, -}) - -export default customerCardApi diff --git a/framework/ordercloud/api/endpoints/customer/card/remove-item.ts b/framework/ordercloud/api/endpoints/customer/card/remove-item.ts deleted file mode 100644 index 1a81d1cf4..000000000 --- a/framework/ordercloud/api/endpoints/customer/card/remove-item.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CustomerCardEndpoint } from '.' - -const removeItem: CustomerCardEndpoint['handlers']['removeItem'] = async ({ - res, -}) => { - return res.status(200).json({ data: null, errors: [] }) -} - -export default removeItem diff --git a/framework/ordercloud/api/endpoints/customer/card/update-item.ts b/framework/ordercloud/api/endpoints/customer/card/update-item.ts deleted file mode 100644 index 9770644aa..000000000 --- a/framework/ordercloud/api/endpoints/customer/card/update-item.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CustomerCardEndpoint } from '.' - -const updateItem: CustomerCardEndpoint['handlers']['updateItem'] = async ({ - res, -}) => { - return res.status(200).json({ data: null, errors: [] }) -} - -export default updateItem diff --git a/framework/ordercloud/api/endpoints/customer/index.ts b/framework/ordercloud/api/endpoints/customer/index.ts deleted file mode 100644 index 491bf0ac9..000000000 --- a/framework/ordercloud/api/endpoints/customer/index.ts +++ /dev/null @@ -1 +0,0 @@ -export default function noopApi(...args: any[]): void {} diff --git a/framework/ordercloud/api/endpoints/login/index.ts b/framework/ordercloud/api/endpoints/login/index.ts deleted file mode 100644 index 491bf0ac9..000000000 --- a/framework/ordercloud/api/endpoints/login/index.ts +++ /dev/null @@ -1 +0,0 @@ -export default function noopApi(...args: any[]): void {} diff --git a/framework/ordercloud/api/endpoints/logout/index.ts b/framework/ordercloud/api/endpoints/logout/index.ts deleted file mode 100644 index 491bf0ac9..000000000 --- a/framework/ordercloud/api/endpoints/logout/index.ts +++ /dev/null @@ -1 +0,0 @@ -export default function noopApi(...args: any[]): void {} diff --git a/framework/ordercloud/api/endpoints/signup/index.ts b/framework/ordercloud/api/endpoints/signup/index.ts deleted file mode 100644 index 491bf0ac9..000000000 --- a/framework/ordercloud/api/endpoints/signup/index.ts +++ /dev/null @@ -1 +0,0 @@ -export default function noopApi(...args: any[]): void {} diff --git a/framework/ordercloud/api/endpoints/wishlist/index.tsx b/framework/ordercloud/api/endpoints/wishlist/index.tsx deleted file mode 100644 index 491bf0ac9..000000000 --- a/framework/ordercloud/api/endpoints/wishlist/index.tsx +++ /dev/null @@ -1 +0,0 @@ -export default function noopApi(...args: any[]): void {} diff --git a/framework/ordercloud/api/index.ts b/framework/ordercloud/api/index.ts deleted file mode 100644 index df62843ab..000000000 --- a/framework/ordercloud/api/index.ts +++ /dev/null @@ -1,71 +0,0 @@ -import type { CommerceAPI, CommerceAPIConfig } from '@commerce/api' -import { getCommerceApi as commerceApi } from '@commerce/api' -import { createBuyerFetcher, createMiddlewareFetcher } from './utils/fetch-rest' -import createGraphqlFetcher from './utils/fetch-graphql' - -import getAllPages from './operations/get-all-pages' -import getPage from './operations/get-page' -import getSiteInfo from './operations/get-site-info' -import getAllProductPaths from './operations/get-all-product-paths' -import getAllProducts from './operations/get-all-products' -import getProduct from './operations/get-product' - -import { - API_URL, - API_VERSION, - CART_COOKIE, - CUSTOMER_COOKIE, - TOKEN_COOKIE, -} from '../constants' - -export interface OrdercloudConfig extends CommerceAPIConfig { - restBuyerFetch: ( - method: string, - resource: string, - body?: Record, - fetchOptions?: Record - ) => Promise - restMiddlewareFetch: ( - method: string, - resource: string, - body?: Record, - fetchOptions?: Record - ) => Promise - apiVersion: string - tokenCookie: string -} - -const config: OrdercloudConfig = { - commerceUrl: API_URL, - apiToken: '', - apiVersion: API_VERSION, - cartCookie: CART_COOKIE, - customerCookie: CUSTOMER_COOKIE, - tokenCookie: TOKEN_COOKIE, - cartCookieMaxAge: 2592000, - restBuyerFetch: createBuyerFetcher(() => getCommerceApi().getConfig()), - restMiddlewareFetch: createMiddlewareFetcher(() => - getCommerceApi().getConfig() - ), - fetch: createGraphqlFetcher(() => getCommerceApi().getConfig()), -} - -const operations = { - getAllPages, - getPage, - getSiteInfo, - getAllProductPaths, - getAllProducts, - getProduct, -} - -export const provider = { config, operations } - -export type Provider = typeof provider -export type OrdercloudAPI

= CommerceAPI

- -export function getCommerceApi

( - customProvider: P = provider as any -): OrdercloudAPI

{ - return commerceApi(customProvider as any) -} diff --git a/framework/ordercloud/api/operations/get-all-pages.ts b/framework/ordercloud/api/operations/get-all-pages.ts deleted file mode 100644 index 1727532e2..000000000 --- a/framework/ordercloud/api/operations/get-all-pages.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { OrdercloudConfig } from '../' - -import { GetAllPagesOperation } from '@commerce/types/page' - -export type Page = { url: string } -export type GetAllPagesResult = { pages: Page[] } - -export default function getAllPagesOperation() { - async function getAllPages({ - config, - preview, - }: { - url?: string - config?: Partial - preview?: boolean - } = {}): Promise { - return Promise.resolve({ - pages: [], - }) - } - return getAllPages -} diff --git a/framework/ordercloud/api/operations/get-all-product-paths.ts b/framework/ordercloud/api/operations/get-all-product-paths.ts deleted file mode 100644 index 1ac23c033..000000000 --- a/framework/ordercloud/api/operations/get-all-product-paths.ts +++ /dev/null @@ -1,34 +0,0 @@ -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) { - async function getAllProductPaths({ - config, - }: { - config?: Partial - } = {}): Promise { - // 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 -} diff --git a/framework/ordercloud/api/operations/get-all-products.ts b/framework/ordercloud/api/operations/get-all-products.ts deleted file mode 100644 index 6af24d945..000000000 --- a/framework/ordercloud/api/operations/get-all-products.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { GetAllProductsOperation } from '@commerce/types/product' -import type { OperationContext } from '@commerce/api/operations' - -import type { RawProduct } from '../../types/product' -import type { OrdercloudConfig, Provider } from '../index' - -import { normalize as normalizeProduct } from '../../utils/product' - -export default function getAllProductsOperation({ - commerce, -}: OperationContext) { - async function getAllProducts({ - config, - }: { - query?: string - variables?: T['variables'] - config?: Partial - preview?: boolean - } = {}): Promise { - // 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 { - // Normalize products to commerce schema - products: rawProducts.map(normalizeProduct), - } - } - - return getAllProducts -} diff --git a/framework/ordercloud/api/operations/get-page.ts b/framework/ordercloud/api/operations/get-page.ts deleted file mode 100644 index 6b0a86a4d..000000000 --- a/framework/ordercloud/api/operations/get-page.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { GetPageOperation } from "@commerce/types/page" - -export type Page = any -export type GetPageResult = { page?: Page } - -export type PageVariables = { - id: number -} - -export default function getPageOperation() { - async function getPage(): Promise { - return Promise.resolve({}) - } - return getPage -} diff --git a/framework/ordercloud/api/operations/get-product.ts b/framework/ordercloud/api/operations/get-product.ts deleted file mode 100644 index 864f931d4..000000000 --- a/framework/ordercloud/api/operations/get-product.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { OperationContext } from '@commerce/api/operations' -import type { GetProductOperation } from '@commerce/types/product' - -import type { RawProduct, RawSpec, RawVariant } from '../../types/product' -import type { OrdercloudConfig, Provider } from '../index' - -import { normalize as normalizeProduct } from '../../utils/product' - -export default function getProductOperation({ - commerce, -}: OperationContext) { - async function getProduct({ - config, - variables, - }: { - query?: string - variables?: T['variables'] - config?: Partial - preview?: boolean - } = {}): Promise { - // Get fetch from the config - const { restBuyerFetch } = commerce.getConfig(config) - - // Get a single product - const productPromise = restBuyerFetch( - 'GET', - `/me/products/${variables?.slug}` - ) - - // Get product specs - const specsPromise = restBuyerFetch<{ Items: RawSpec[] }>( - 'GET', - `/me/products/${variables?.slug}/specs` - ).then((res) => res.Items) - - // Get product variants - const variantsPromise = restBuyerFetch<{ Items: RawVariant[] }>( - 'GET', - `/me/products/${variables?.slug}/variants` - ).then((res) => res.Items) - - // Execute all promises in parallel - const [product, specs, variants] = await Promise.all([ - productPromise, - specsPromise, - variantsPromise, - ]) - - // Hydrate product - product.xp.Specs = specs - product.xp.Variants = variants - - return { - // Normalize product to commerce schema - product: normalizeProduct(product), - } - } - - return getProduct -} diff --git a/framework/ordercloud/api/operations/get-site-info.ts b/framework/ordercloud/api/operations/get-site-info.ts deleted file mode 100644 index 95188c58e..000000000 --- a/framework/ordercloud/api/operations/get-site-info.ts +++ /dev/null @@ -1,46 +0,0 @@ -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) { - async function getSiteInfo({ - config, - }: { - query?: string - variables?: any - config?: Partial - preview?: boolean - } = {}): Promise { - // 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 -} diff --git a/framework/ordercloud/api/operations/index.ts b/framework/ordercloud/api/operations/index.ts deleted file mode 100644 index 84b04a978..000000000 --- a/framework/ordercloud/api/operations/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { default as getAllPages } from './get-all-pages' -export { default as getPage } from './get-page' -export { default as getSiteInfo } from './get-site-info' -export { default as getProduct } from './get-product' -export { default as getAllProducts } from './get-all-products' -export { default as getAllProductPaths } from './get-all-product-paths' diff --git a/framework/ordercloud/api/utils/cart.ts b/framework/ordercloud/api/utils/cart.ts deleted file mode 100644 index 716f3521e..000000000 --- a/framework/ordercloud/api/utils/cart.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { Cart, OrdercloudCart, OrdercloudLineItem } from '../../types/cart' - -export function formatCart( - cart: OrdercloudCart, - lineItems: OrdercloudLineItem[] -): Cart { - return { - id: cart.ID, - customerId: cart.FromUserID, - email: cart.FromUser.Email, - createdAt: cart.DateCreated, - currency: { - code: cart.FromUser?.xp?.currency ?? 'USD', - }, - taxesIncluded: cart.TaxCost === 0, - lineItems: lineItems.map((lineItem) => ({ - id: lineItem.ID, - variantId: lineItem.Variant ? String(lineItem.Variant.ID) : '', - productId: lineItem.ProductID, - name: lineItem.Product.Name, - quantity: lineItem.Quantity, - discounts: [], - path: lineItem.ProductID, - variant: { - id: lineItem.Variant ? String(lineItem.Variant.ID) : '', - sku: lineItem.ID, - name: lineItem.Product.Name, - image: { - url: lineItem.Product.xp?.Images?.[0]?.url, - }, - requiresShipping: Boolean(lineItem.ShippingAddress), - price: lineItem.UnitPrice, - listPrice: lineItem.UnitPrice, - }, - })), - lineItemsSubtotalPrice: cart.Subtotal, - subtotalPrice: cart.Subtotal, - totalPrice: cart.Total, - discounts: [], - } -} diff --git a/framework/ordercloud/api/utils/fetch-graphql.ts b/framework/ordercloud/api/utils/fetch-graphql.ts deleted file mode 100644 index af72a337c..000000000 --- a/framework/ordercloud/api/utils/fetch-graphql.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { GraphQLFetcher } from '@commerce/api' -import type { OrdercloudConfig } from '../' - -import { FetcherError } from '@commerce/utils/errors' - -const fetchGraphqlApi: (getConfig: () => OrdercloudConfig) => GraphQLFetcher = - () => async () => { - throw new FetcherError({ - errors: [{ message: 'GraphQL fetch is not implemented' }], - status: 500, - }) - } - -export default fetchGraphqlApi diff --git a/framework/ordercloud/api/utils/fetch-rest.ts b/framework/ordercloud/api/utils/fetch-rest.ts deleted file mode 100644 index fd686b958..000000000 --- a/framework/ordercloud/api/utils/fetch-rest.ts +++ /dev/null @@ -1,176 +0,0 @@ -import vercelFetch from '@vercel/fetch' -import { FetcherError } from '@commerce/utils/errors' - -import { OrdercloudConfig } from '../index' - -// Get an instance to vercel fetch -const fetch = vercelFetch() - -// Get token util -async function getToken({ - baseUrl, - clientId, - clientSecret, -}: { - baseUrl: string - clientId: string - clientSecret?: string -}): Promise { - // If not, get a new one and store it - const authResponse = await fetch(`${baseUrl}/oauth/token`, { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - Accept: 'application/json', - }, - body: `client_id=${clientId}&client_secret=${clientSecret}&grant_type=client_credentials`, - }) - - // If something failed getting the auth response - if (!authResponse.ok) { - // Get the body of it - const error = await authResponse.json() - - // And return an error - throw new FetcherError({ - errors: [{ message: error.error_description.Code }], - status: error.error_description.HttpStatus, - }) - } - - // Return the token - return authResponse - .json() - .then((response: { access_token: string }) => response.access_token) -} - -export async function fetchData(opts: { - token: string - path: string - method: string - config: OrdercloudConfig - fetchOptions?: Record - body?: Record -}): Promise { - // Destructure opts - const { path, body, fetchOptions, config, token, method = 'GET' } = opts - - // Do the request with the correct headers - const dataResponse = await fetch( - `${config.commerceUrl}/${config.apiVersion}${path}`, - { - ...fetchOptions, - method, - headers: { - ...fetchOptions?.headers, - 'Content-Type': 'application/json', - accept: 'application/json, text/plain, */*', - authorization: `Bearer ${token}`, - }, - body: body ? JSON.stringify(body) : undefined, - } - ) - - // If something failed getting the data response - if (!dataResponse.ok) { - // Get the body of it - const error = await dataResponse.textConverted() - - // And return an error - throw new FetcherError({ - errors: [{ message: error || dataResponse.statusText }], - status: dataResponse.status, - }) - } - - try { - // Return data response as json - return (await dataResponse.json()) as Promise - } catch (error) { - // If response is empty return it as text - return null as unknown as Promise - } -} - -export const createMiddlewareFetcher: ( - getConfig: () => OrdercloudConfig -) => ( - method: string, - path: string, - body?: Record, - fetchOptions?: Record -) => Promise = - (getConfig) => - async ( - method: string, - path: string, - body?: Record, - fetchOptions?: Record - ) => { - // Get provider config - const config = getConfig() - - // Get a token - const token = await getToken({ - baseUrl: config.commerceUrl, - clientId: process.env.ORDERCLOUD_MIDDLEWARE_CLIENT_ID as string, - clientSecret: process.env.ORDERCLOUD_MIDDLEWARE_CLIENT_SECRET, - }) - - // Return the data and specify the expected type - return fetchData({ - token, - fetchOptions, - method, - config, - path, - body, - }) - } - -export const createBuyerFetcher: ( - getConfig: () => OrdercloudConfig -) => ( - method: string, - path: string, - body?: Record, - fetchOptions?: Record -) => Promise = - (getConfig) => - async ( - method: string, - path: string, - body?: Record, - fetchOptions?: Record - ) => { - // Get provider config - const config = getConfig() - - // If a token was passed, set it on global - if (fetchOptions?.token) { - global.token = fetchOptions.token - } - - // Get a token - if (!global.token) { - global.token = await getToken({ - baseUrl: config.commerceUrl, - clientId: process.env.ORDERCLOUD_BUYER_CLIENT_ID as string, - }) - } - - // Return the data and specify the expected type - const data = await fetchData({ - token: global.token as string, - fetchOptions, - config, - method, - path, - body, - }) - - return { - ...data, - meta: { token: global.token as string }, - } - } diff --git a/framework/ordercloud/auth/index.ts b/framework/ordercloud/auth/index.ts deleted file mode 100644 index 36e757a89..000000000 --- a/framework/ordercloud/auth/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { default as useLogin } from './use-login' -export { default as useLogout } from './use-logout' -export { default as useSignup } from './use-signup' diff --git a/framework/ordercloud/auth/use-login.tsx b/framework/ordercloud/auth/use-login.tsx deleted file mode 100644 index 28351dc7f..000000000 --- a/framework/ordercloud/auth/use-login.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { MutationHook } from '@commerce/utils/types' -import useLogin, { UseLogin } from '@commerce/auth/use-login' - -export default useLogin as UseLogin - -export const handler: MutationHook = { - fetchOptions: { - query: '', - }, - async fetcher() { - return null - }, - useHook: () => () => { - return async function () {} - }, -} diff --git a/framework/ordercloud/auth/use-logout.tsx b/framework/ordercloud/auth/use-logout.tsx deleted file mode 100644 index 9b3fc3e44..000000000 --- a/framework/ordercloud/auth/use-logout.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { MutationHook } from '@commerce/utils/types' -import useLogout, { UseLogout } from '@commerce/auth/use-logout' - -export default useLogout as UseLogout - -export const handler: MutationHook = { - fetchOptions: { - query: '', - }, - async fetcher() { - return null - }, - useHook: - ({ fetch }) => - () => - async () => {}, -} diff --git a/framework/ordercloud/auth/use-signup.tsx b/framework/ordercloud/auth/use-signup.tsx deleted file mode 100644 index e9ad13458..000000000 --- a/framework/ordercloud/auth/use-signup.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { useCallback } from 'react' -import useCustomer from '../customer/use-customer' -import { MutationHook } from '@commerce/utils/types' -import useSignup, { UseSignup } from '@commerce/auth/use-signup' - -export default useSignup as UseSignup - -export const handler: MutationHook = { - fetchOptions: { - query: '', - }, - async fetcher() { - return null - }, - useHook: - ({ fetch }) => - () => - () => {}, -} diff --git a/framework/ordercloud/cart/index.ts b/framework/ordercloud/cart/index.ts deleted file mode 100644 index 3b8ba990e..000000000 --- a/framework/ordercloud/cart/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as useCart } from './use-cart' -export { default as useAddItem } from './use-add-item' -export { default as useRemoveItem } from './use-remove-item' -export { default as useUpdateItem } from './use-update-item' diff --git a/framework/ordercloud/cart/use-add-item.tsx b/framework/ordercloud/cart/use-add-item.tsx deleted file mode 100644 index 4699202c3..000000000 --- a/framework/ordercloud/cart/use-add-item.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import type { AddItemHook } from '@commerce/types/cart' -import type { MutationHook } from '@commerce/utils/types' - -import { useCallback } from 'react' -import { CommerceError } from '@commerce/utils/errors' -import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item' -import useCart from './use-cart' - -export default useAddItem as UseAddItem - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/cart', - method: 'POST', - }, - async fetcher({ input: item, options, fetch }) { - if ( - item.quantity && - (!Number.isInteger(item.quantity) || item.quantity! < 1) - ) { - throw new CommerceError({ - message: 'The item quantity has to be a valid integer greater than 0', - }) - } - - const data = await fetch({ - ...options, - body: { item }, - }) - - return data - }, - useHook: ({ fetch }) => - function useHook() { - const { mutate } = useCart() - - return useCallback( - async function addItem(input) { - const data = await fetch({ input }) - - await mutate(data, false) - - return data - }, - [fetch, mutate] - ) - }, -} diff --git a/framework/ordercloud/cart/use-cart.tsx b/framework/ordercloud/cart/use-cart.tsx deleted file mode 100644 index d194f4097..000000000 --- a/framework/ordercloud/cart/use-cart.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import type { GetCartHook } from '@commerce/types/cart' - -import { useMemo } from 'react' -import { SWRHook } from '@commerce/utils/types' -import useCart, { UseCart } from '@commerce/cart/use-cart' - -export default useCart as UseCart - -export const handler: SWRHook = { - fetchOptions: { - url: '/api/cart', - method: 'GET', - }, - useHook: ({ useData }) => - function useHook(input) { - const response = useData({ - swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, - }) - - return useMemo( - () => - Object.create(response, { - isEmpty: { - get() { - return (response.data?.lineItems?.length ?? 0) <= 0 - }, - enumerable: true, - }, - }), - [response] - ) - }, -} diff --git a/framework/ordercloud/cart/use-remove-item.tsx b/framework/ordercloud/cart/use-remove-item.tsx deleted file mode 100644 index 748ba963d..000000000 --- a/framework/ordercloud/cart/use-remove-item.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import type { - MutationHookContext, - HookFetcherContext, -} from '@commerce/utils/types' -import type { Cart, LineItem, RemoveItemHook } from '@commerce/types/cart' - -import { useCallback } from 'react' - -import { ValidationError } from '@commerce/utils/errors' -import useRemoveItem, { UseRemoveItem } from '@commerce/cart/use-remove-item' - -import useCart from './use-cart' - -export type RemoveItemFn = T extends LineItem - ? (input?: RemoveItemActionInput) => Promise - : (input: RemoveItemActionInput) => Promise - -export type RemoveItemActionInput = T extends LineItem - ? Partial - : RemoveItemHook['actionInput'] - -export default useRemoveItem as UseRemoveItem - -export const handler = { - fetchOptions: { - url: '/api/cart', - method: 'DELETE', - }, - async fetcher({ - input: { itemId }, - options, - fetch, - }: HookFetcherContext) { - return await fetch({ ...options, body: { itemId } }) - }, - useHook: ({ fetch }: MutationHookContext) => - function useHook( - ctx: { item?: T } = {} - ) { - const { item } = ctx - const { mutate } = useCart() - const removeItem: RemoveItemFn = async (input) => { - const itemId = input?.id ?? item?.id - - if (!itemId) { - throw new ValidationError({ - message: 'Invalid input used for this operation', - }) - } - - const data = await fetch({ input: { itemId } }) - - await mutate(data, false) - - return data - } - - return useCallback(removeItem as RemoveItemFn, [fetch, mutate]) - }, -} diff --git a/framework/ordercloud/cart/use-update-item.tsx b/framework/ordercloud/cart/use-update-item.tsx deleted file mode 100644 index cc9d93b03..000000000 --- a/framework/ordercloud/cart/use-update-item.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import type { - HookFetcherContext, - MutationHookContext, -} from '@commerce/utils/types' -import type { UpdateItemHook, LineItem } from '@commerce/types/cart' - -import { useCallback } from 'react' -import debounce from 'lodash.debounce' - -import { MutationHook } from '@commerce/utils/types' -import { ValidationError } from '@commerce/utils/errors' -import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item' - -import { handler as removeItemHandler } from './use-remove-item' -import useCart from './use-cart' - -export type UpdateItemActionInput = T extends LineItem - ? Partial - : UpdateItemHook['actionInput'] - -export default useUpdateItem as UseUpdateItem - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/cart', - method: 'PUT', - }, - async fetcher({ - input: { itemId, item }, - options, - fetch, - }: HookFetcherContext) { - if (Number.isInteger(item.quantity)) { - // Also allow the update hook to remove an item if the quantity is lower than 1 - if (item.quantity! < 1) { - return removeItemHandler.fetcher({ - options: removeItemHandler.fetchOptions, - input: { itemId }, - fetch, - }) - } - } else if (item.quantity) { - throw new ValidationError({ - message: 'The item quantity has to be a valid integer', - }) - } - - return await fetch({ - ...options, - body: { itemId, item }, - }) - }, - useHook: ({ fetch }: MutationHookContext) => - function useHook( - ctx: { - item?: T - wait?: number - } = {} - ) { - const { item } = ctx - const { mutate } = useCart() as any - - return useCallback( - debounce(async (input: UpdateItemActionInput) => { - const itemId = input.id ?? item?.id - const productId = input.productId ?? item?.productId - const variantId = input.productId ?? item?.variantId - - if (!itemId || !productId) { - throw new ValidationError({ - message: 'Invalid input used for this operation', - }) - } - - const data = await fetch({ - input: { - itemId, - item: { - productId, - variantId: variantId || '', - quantity: input.quantity, - }, - }, - }) - - await mutate(data, false) - - return data - }, ctx.wait ?? 500), - [fetch, mutate] - ) - }, -} diff --git a/framework/ordercloud/checkout/index.ts b/framework/ordercloud/checkout/index.ts deleted file mode 100644 index 306621059..000000000 --- a/framework/ordercloud/checkout/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useSubmitCheckout } from './use-submit-checkout' -export { default as useCheckout } from './use-checkout' diff --git a/framework/ordercloud/checkout/use-checkout.tsx b/framework/ordercloud/checkout/use-checkout.tsx deleted file mode 100644 index 6ce13dbb6..000000000 --- a/framework/ordercloud/checkout/use-checkout.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import type { GetCheckoutHook } from '@commerce/types/checkout' - -import { useMemo } from 'react' -import { SWRHook } from '@commerce/utils/types' -import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout' -import useSubmitCheckout from './use-submit-checkout' - -export default useCheckout as UseCheckout - -export const handler: SWRHook = { - fetchOptions: { - url: '/api/checkout', - method: 'GET', - }, - useHook: ({ useData }) => - function useHook(input) { - const submit = useSubmitCheckout(); - const response = useData({ - swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, - }) - - return useMemo( - () => - Object.create(response, { - isEmpty: { - get() { - return (response.data?.lineItems?.length ?? 0) <= 0 - }, - enumerable: true, - }, - submit: { - get() { - return submit - }, - enumerable: true, - }, - }), - [response, submit] - ) - }, -} diff --git a/framework/ordercloud/checkout/use-submit-checkout.tsx b/framework/ordercloud/checkout/use-submit-checkout.tsx deleted file mode 100644 index 47644de8e..000000000 --- a/framework/ordercloud/checkout/use-submit-checkout.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import type { SubmitCheckoutHook } from '@commerce/types/checkout' -import type { MutationHook } from '@commerce/utils/types' - -import { useCallback } from 'react' -import useSubmitCheckout, { UseSubmitCheckout } from '@commerce/checkout/use-submit-checkout' - -export default useSubmitCheckout as UseSubmitCheckout - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/checkout', - method: 'POST', - }, - async fetcher({ input: item, options, fetch }) { - // @TODO: Make form validations in here, import generic error like import { CommerceError } from '@commerce/utils/errors' - // Get payment and delivery information in here - - const data = await fetch({ - ...options, - body: { item }, - }) - - return data - }, - useHook: ({ fetch }) => - function useHook() { - return useCallback( - async function onSubmitCheckout(input) { - const data = await fetch({ input }) - - return data - }, - [fetch] - ) - }, -} diff --git a/framework/ordercloud/commerce.config.json b/framework/ordercloud/commerce.config.json deleted file mode 100644 index e329bd4c1..000000000 --- a/framework/ordercloud/commerce.config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "provider": "ordercloud", - "features": { - "wishlist": false, - "cart": true, - "search": true, - "customerAuth": false, - "customCheckout": true - } -} diff --git a/framework/ordercloud/constants.ts b/framework/ordercloud/constants.ts deleted file mode 100644 index d89b13f64..000000000 --- a/framework/ordercloud/constants.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const CART_COOKIE = 'ordercloud.cart' -export const TOKEN_COOKIE = 'ordercloud.token' -export const CUSTOMER_COOKIE = 'ordercloud.customer' -export const API_URL = 'https://sandboxapi.ordercloud.io' -export const API_VERSION = 'v1' -export const LOCALE = 'en-us' diff --git a/framework/ordercloud/customer/address/index.ts b/framework/ordercloud/customer/address/index.ts deleted file mode 100644 index 02c73e53b..000000000 --- a/framework/ordercloud/customer/address/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as useAddresses } from './use-addresses' -export { default as useAddItem } from './use-add-item' -export { default as useRemoveItem } from './use-remove-item' -export { default as useUpdateItem } from './use-update-item' diff --git a/framework/ordercloud/customer/address/use-add-item.tsx b/framework/ordercloud/customer/address/use-add-item.tsx deleted file mode 100644 index cf3f22c46..000000000 --- a/framework/ordercloud/customer/address/use-add-item.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import type { AddItemHook } from '@commerce/types/customer/address' -import type { MutationHook } from '@commerce/utils/types' - -import { useCallback } from 'react' -import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item' -import useAddresses from './use-addresses' - -export default useAddItem as UseAddItem - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/customer/address', - method: 'POST', - }, - async fetcher({ input: item, options, fetch }) { - const data = await fetch({ - ...options, - body: { item }, - }) - - return data - }, - useHook: ({ fetch }) => - function useHook() { - const { mutate } = useAddresses() - - return useCallback( - async function addItem(input) { - const data = await fetch({ input }) - - await mutate([data], false) - - return data - }, - [fetch, mutate] - ) - }, -} diff --git a/framework/ordercloud/customer/address/use-addresses.tsx b/framework/ordercloud/customer/address/use-addresses.tsx deleted file mode 100644 index e9ddc7001..000000000 --- a/framework/ordercloud/customer/address/use-addresses.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import type { GetAddressesHook } from '@commerce/types/customer/address' - -import { useMemo } from 'react' -import { SWRHook } from '@commerce/utils/types' -import useAddresses, { - UseAddresses, -} from '@commerce/customer/address/use-addresses' - -export default useAddresses as UseAddresses - -export const handler: SWRHook = { - fetchOptions: { - url: '/api/customer/address', - method: 'GET', - }, - useHook: ({ useData }) => - function useHook(input) { - const response = useData({ - swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, - }) - - return useMemo( - () => - Object.create(response, { - isEmpty: { - get() { - return (response.data?.length ?? 0) <= 0 - }, - enumerable: true, - }, - }), - [response] - ) - }, -} diff --git a/framework/ordercloud/customer/address/use-remove-item.tsx b/framework/ordercloud/customer/address/use-remove-item.tsx deleted file mode 100644 index 4e6282c99..000000000 --- a/framework/ordercloud/customer/address/use-remove-item.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import type { - MutationHookContext, - HookFetcherContext, -} from '@commerce/utils/types' -import type { Address, RemoveItemHook } from '@commerce/types/customer/address' - -import { useCallback } from 'react' - -import { ValidationError } from '@commerce/utils/errors' -import useRemoveItem, { - UseRemoveItem, -} from '@commerce/customer/address/use-remove-item' - -import useAddresses from './use-addresses' - -export type RemoveItemFn = T extends Address - ? (input?: RemoveItemActionInput) => Promise

- : (input: RemoveItemActionInput) => Promise
- -export type RemoveItemActionInput = T extends Address - ? Partial - : RemoveItemHook['actionInput'] - -export default useRemoveItem as UseRemoveItem - -export const handler = { - fetchOptions: { - url: '/api/customer/address', - method: 'DELETE', - }, - async fetcher({ - input: { itemId }, - options, - fetch, - }: HookFetcherContext) { - return await fetch({ ...options, body: { itemId } }) - }, - useHook: ({ fetch }: MutationHookContext) => - function useHook( - ctx: { item?: T } = {} - ) { - const { item } = ctx - const { mutate } = useAddresses() - const removeItem: RemoveItemFn
= async (input) => { - const itemId = input?.id ?? item?.id - - if (!itemId) { - throw new ValidationError({ - message: 'Invalid input used for this operation', - }) - } - - const data = await fetch({ input: { itemId } }) - - await mutate([], false) - - return data - } - - return useCallback(removeItem as RemoveItemFn, [fetch, mutate]) - }, -} diff --git a/framework/ordercloud/customer/address/use-update-item.tsx b/framework/ordercloud/customer/address/use-update-item.tsx deleted file mode 100644 index 720a339d8..000000000 --- a/framework/ordercloud/customer/address/use-update-item.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import type { - HookFetcherContext, - MutationHookContext, -} from '@commerce/utils/types' -import type { UpdateItemHook, Address } from '@commerce/types/customer/address' - -import { useCallback } from 'react' - -import { MutationHook } from '@commerce/utils/types' -import useUpdateItem, { - UseUpdateItem, -} from '@commerce/customer/address/use-update-item' - -import useAddresses from './use-addresses' - -export type UpdateItemActionInput = T extends Address - ? Partial - : UpdateItemHook['actionInput'] - -export default useUpdateItem as UseUpdateItem - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/customer/address', - method: 'PUT', - }, - async fetcher({ - input: { itemId, item }, - options, - fetch, - }: HookFetcherContext) { - return await fetch({ - ...options, - body: { itemId, item }, - }) - }, - useHook: ({ fetch }: MutationHookContext) => - function useHook() { - const { mutate } = useAddresses() - - return useCallback( - async function updateItem(input) { - const data = await fetch({ input }) - - await mutate([], false) - - return data - }, - [fetch, mutate] - ) - }, -} diff --git a/framework/ordercloud/customer/card/index.ts b/framework/ordercloud/customer/card/index.ts deleted file mode 100644 index 357d30500..000000000 --- a/framework/ordercloud/customer/card/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as useCards } from './use-cards' -export { default as useAddItem } from './use-add-item' -export { default as useRemoveItem } from './use-remove-item' -export { default as useUpdateItem } from './use-update-item' diff --git a/framework/ordercloud/customer/card/use-add-item.tsx b/framework/ordercloud/customer/card/use-add-item.tsx deleted file mode 100644 index 6c6a6d7fd..000000000 --- a/framework/ordercloud/customer/card/use-add-item.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import type { AddItemHook } from '@commerce/types/customer/card' -import type { MutationHook } from '@commerce/utils/types' - -import { useCallback } from 'react' -import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item' -import useCards from './use-cards' - -export default useAddItem as UseAddItem - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/customer/card', - method: 'POST', - }, - async fetcher({ input: item, options, fetch }) { - const data = await fetch({ - ...options, - body: { item }, - }) - - return data - }, - useHook: ({ fetch }) => - function useHook() { - const { mutate } = useCards() - - return useCallback( - async function addItem(input) { - const data = await fetch({ input }) - - await mutate([data], false) - - return data - }, - [fetch, mutate] - ) - }, -} diff --git a/framework/ordercloud/customer/card/use-cards.tsx b/framework/ordercloud/customer/card/use-cards.tsx deleted file mode 100644 index 92236deb2..000000000 --- a/framework/ordercloud/customer/card/use-cards.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import type { GetCardsHook } from '@commerce/types/customer/card' - -import { useMemo } from 'react' -import { SWRHook } from '@commerce/utils/types' -import useCard, { UseCards } from '@commerce/customer/card/use-cards' - -export default useCard as UseCards - -export const handler: SWRHook = { - fetchOptions: { - url: '/api/customer/card', - method: 'GET', - }, - useHook: ({ useData }) => - function useHook(input) { - const response = useData({ - swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, - }) - - return useMemo( - () => - Object.create(response, { - isEmpty: { - get() { - return (response.data?.length ?? 0) <= 0 - }, - enumerable: true, - }, - }), - [response] - ) - }, -} diff --git a/framework/ordercloud/customer/card/use-remove-item.tsx b/framework/ordercloud/customer/card/use-remove-item.tsx deleted file mode 100644 index dc0781b95..000000000 --- a/framework/ordercloud/customer/card/use-remove-item.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import type { - MutationHookContext, - HookFetcherContext, -} from '@commerce/utils/types' -import type { Card, RemoveItemHook } from '@commerce/types/customer/card' - -import { useCallback } from 'react' - -import { ValidationError } from '@commerce/utils/errors' -import useRemoveItem, { - UseRemoveItem, -} from '@commerce/customer/card/use-remove-item' - -import useCards from './use-cards' - -export type RemoveItemFn = T extends Card - ? (input?: RemoveItemActionInput) => Promise - : (input: RemoveItemActionInput) => Promise - -export type RemoveItemActionInput = T extends Card - ? Partial - : RemoveItemHook['actionInput'] - -export default useRemoveItem as UseRemoveItem - -export const handler = { - fetchOptions: { - url: '/api/customer/card', - method: 'DELETE', - }, - async fetcher({ - input: { itemId }, - options, - fetch, - }: HookFetcherContext) { - return await fetch({ ...options, body: { itemId } }) - }, - useHook: ({ fetch }: MutationHookContext) => - function useHook( - ctx: { item?: T } = {} - ) { - const { item } = ctx - const { mutate } = useCards() - const removeItem: RemoveItemFn = async (input) => { - const itemId = input?.id ?? item?.id - - if (!itemId) { - throw new ValidationError({ - message: 'Invalid input used for this operation', - }) - } - - const data = await fetch({ input: { itemId } }) - - await mutate([], false) - - return data - } - - return useCallback(removeItem as RemoveItemFn, [fetch, mutate]) - }, -} diff --git a/framework/ordercloud/customer/card/use-update-item.tsx b/framework/ordercloud/customer/card/use-update-item.tsx deleted file mode 100644 index 0dfb218d5..000000000 --- a/framework/ordercloud/customer/card/use-update-item.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import type { - HookFetcherContext, - MutationHookContext, -} from '@commerce/utils/types' -import type { UpdateItemHook, Card } from '@commerce/types/customer/card' - -import { useCallback } from 'react' - -import { MutationHook } from '@commerce/utils/types' -import useUpdateItem, { - UseUpdateItem, -} from '@commerce/customer/card/use-update-item' - -import useCards from './use-cards' - -export type UpdateItemActionInput = T extends Card - ? Partial - : UpdateItemHook['actionInput'] - -export default useUpdateItem as UseUpdateItem - -export const handler: MutationHook = { - fetchOptions: { - url: '/api/customer/card', - method: 'PUT', - }, - async fetcher({ - input: { itemId, item }, - options, - fetch, - }: HookFetcherContext) { - return await fetch({ - ...options, - body: { itemId, item }, - }) - }, - useHook: ({ fetch }: MutationHookContext) => - function useHook() { - const { mutate } = useCards() - - return useCallback( - async function updateItem(input) { - const data = await fetch({ input }) - - await mutate([], false) - - return data - }, - [fetch, mutate] - ) - }, -} diff --git a/framework/ordercloud/customer/index.ts b/framework/ordercloud/customer/index.ts deleted file mode 100644 index 6c903ecc5..000000000 --- a/framework/ordercloud/customer/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as useCustomer } from './use-customer' diff --git a/framework/ordercloud/customer/use-customer.tsx b/framework/ordercloud/customer/use-customer.tsx deleted file mode 100644 index 41757cd0d..000000000 --- a/framework/ordercloud/customer/use-customer.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { SWRHook } from '@commerce/utils/types' -import useCustomer, { UseCustomer } from '@commerce/customer/use-customer' - -export default useCustomer as UseCustomer -export const handler: SWRHook = { - fetchOptions: { - query: '', - }, - async fetcher({ input, options, fetch }) {}, - useHook: () => () => { - return async function addItem() { - return {} - } - }, -} diff --git a/framework/ordercloud/fetcher.ts b/framework/ordercloud/fetcher.ts deleted file mode 100644 index 6f314a71e..000000000 --- a/framework/ordercloud/fetcher.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Fetcher } from '@commerce/utils/types' - -const clientFetcher: Fetcher = async ({ method, url, body }) => { - const response = await fetch(url!, { - method, - body: body ? JSON.stringify(body) : undefined, - headers: { - 'Content-Type': 'application/json', - }, - }) - .then((response) => response.json()) - .then((response) => response.data) - - return response -} - -export default clientFetcher diff --git a/framework/ordercloud/index.tsx b/framework/ordercloud/index.tsx deleted file mode 100644 index 6a01c2ee4..000000000 --- a/framework/ordercloud/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { ordercloudProvider, OrdercloudProvider } from './provider' -import { getCommerceProvider, useCommerce as useCoreCommerce } from '@commerce' - -export { ordercloudProvider } -export type { OrdercloudProvider } - -export const CommerceProvider = getCommerceProvider(ordercloudProvider) - -export const useCommerce = () => useCoreCommerce() diff --git a/framework/ordercloud/next.config.js b/framework/ordercloud/next.config.js deleted file mode 100644 index 793a4589f..000000000 --- a/framework/ordercloud/next.config.js +++ /dev/null @@ -1,8 +0,0 @@ -const commerce = require('./commerce.config.json') - -module.exports = { - commerce, - images: { - domains: ['localhost', 'ocdevops.blob.core.windows.net'], - }, -} diff --git a/framework/ordercloud/product/index.ts b/framework/ordercloud/product/index.ts deleted file mode 100644 index 426a3edcd..000000000 --- a/framework/ordercloud/product/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as usePrice } from './use-price' -export { default as useSearch } from './use-search' diff --git a/framework/ordercloud/product/use-price.tsx b/framework/ordercloud/product/use-price.tsx deleted file mode 100644 index 0174faf5e..000000000 --- a/framework/ordercloud/product/use-price.tsx +++ /dev/null @@ -1,2 +0,0 @@ -export * from '@commerce/product/use-price' -export { default } from '@commerce/product/use-price' diff --git a/framework/ordercloud/product/use-search.tsx b/framework/ordercloud/product/use-search.tsx deleted file mode 100644 index 4b39fefb4..000000000 --- a/framework/ordercloud/product/use-search.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { SWRHook } from '@commerce/utils/types' -import useSearch, { UseSearch } from '@commerce/product/use-search' -import { SearchProductsHook } from '@commerce/types/product' -export default useSearch as UseSearch - -export const handler: SWRHook = { - fetchOptions: { - url: '/api/catalog/products', - method: 'GET', - }, - fetcher({ input: { search, categoryId, brandId, sort }, options, fetch }) { - // Use a dummy base as we only care about the relative path - const url = new URL(options.url!, 'http://a') - - - if (search) url.searchParams.set('search', String(search)) - if (categoryId) url.searchParams.set('categoryId', String(categoryId)) - if (brandId) url.searchParams.set('brandId', String(brandId)) - if (sort) url.searchParams.set('sort', String(sort)) - - return fetch({ - url: url.pathname + url.search, - method: options.method, - }) - }, - useHook: ({ useData }) => (input = {}) => { - return useData({ - input: [ - ['search', input.search], - ['categoryId', input.categoryId], - ['brandId', input.brandId], - ['sort', input.sort] - ], - swrOptions: { - revalidateOnFocus: false, - ...input.swrOptions, - }, - }) - }, -} diff --git a/framework/ordercloud/provider.ts b/framework/ordercloud/provider.ts deleted file mode 100644 index 337eed657..000000000 --- a/framework/ordercloud/provider.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { handler as useCart } from './cart/use-cart' -import { handler as useAddCartItem } from './cart/use-add-item' -import { handler as useUpdateCartItem } from './cart/use-update-item' -import { handler as useRemoveCartItem } from './cart/use-remove-item' - -import { handler as useCustomer } from './customer/use-customer' -import { handler as useSearch } from './product/use-search' - -import { handler as useLogin } from './auth/use-login' -import { handler as useLogout } from './auth/use-logout' -import { handler as useSignup } from './auth/use-signup' - -import { handler as useCheckout } from './checkout/use-checkout' -import { handler as useSubmitCheckout } from './checkout/use-submit-checkout' - -import { handler as useCards } from './customer/card/use-cards' -import { handler as useAddCardItem } from './customer/card/use-add-item' -import { handler as useUpdateCardItem } from './customer/card/use-update-item' -import { handler as useRemoveCardItem } from './customer/card/use-remove-item' - -import { handler as useAddresses } from './customer/address/use-addresses' -import { handler as useAddAddressItem } from './customer/address/use-add-item' -import { handler as useUpdateAddressItem } from './customer/address/use-update-item' -import { handler as useRemoveAddressItem } from './customer/address/use-remove-item' - -import { CART_COOKIE, LOCALE } from './constants' -import { default as fetcher } from './fetcher' - -export const ordercloudProvider = { - locale: LOCALE, - cartCookie: CART_COOKIE, - fetcher, - cart: { - useCart, - useAddItem: useAddCartItem, - useUpdateItem: useUpdateCartItem, - useRemoveItem: useRemoveCartItem - }, - checkout: { - useCheckout, - useSubmitCheckout, - }, - customer: { - useCustomer, - card: { - useCards, - useAddItem: useAddCardItem, - useUpdateItem: useUpdateCardItem, - useRemoveItem: useRemoveCardItem - }, - address: { - useAddresses, - useAddItem: useAddAddressItem, - useUpdateItem: useUpdateAddressItem, - useRemoveItem: useRemoveAddressItem - } - }, - products: { useSearch }, - auth: { useLogin, useLogout, useSignup }, -} - -export type OrdercloudProvider = typeof ordercloudProvider diff --git a/framework/ordercloud/types/cart.ts b/framework/ordercloud/types/cart.ts deleted file mode 100644 index 4716c355d..000000000 --- a/framework/ordercloud/types/cart.ts +++ /dev/null @@ -1,126 +0,0 @@ -import * as Core from '@commerce/types/cart' - -export * from '@commerce/types/cart' - -export interface OrdercloudCart { - ID: string - FromUser: { - ID: string - Username: string - Password: null - FirstName: string - LastName: string - Email: string - Phone: null - TermsAccepted: null - Active: true - xp: { - something: string - currency: string - } - AvailableRoles: null - DateCreated: string - PasswordLastSetDate: null - } - FromCompanyID: string - ToCompanyID: string - FromUserID: string - BillingAddressID: null - BillingAddress: null - ShippingAddressID: null - Comments: null - LineItemCount: number - Status: string - DateCreated: string - DateSubmitted: null - DateApproved: null - DateDeclined: null - DateCanceled: null - DateCompleted: null - LastUpdated: string - Subtotal: number - ShippingCost: number - TaxCost: number - PromotionDiscount: number - Total: number - IsSubmitted: false - xp: { - productId: string - variantId: string - quantity: 1 - } -} - -export interface OrdercloudLineItem { - ID: string - ProductID: string - Quantity: 1 - DateAdded: string - QuantityShipped: number - UnitPrice: number - PromotionDiscount: number - LineTotal: number - LineSubtotal: number - CostCenter: null - DateNeeded: null - ShippingAccount: null - ShippingAddressID: null - ShipFromAddressID: null - Product: { - ID: string - Name: string - Description: string - QuantityMultiplier: number - ShipWeight: number - ShipHeight: null - ShipWidth: null - ShipLength: null - xp: { - Images: { - url: string - }[] - } - } - Variant: null | { - ID: string - Name: null - Description: null - ShipWeight: null - ShipHeight: null - ShipWidth: null - ShipLength: null - xp: null - } - ShippingAddress: null - ShipFromAddress: null - SupplierID: null - Specs: [] - xp: null -} - -/** - * Extend core cart types - */ - -export type Cart = Core.Cart & { - lineItems: Core.LineItem[] - url?: string -} - -export type CartTypes = Core.CartTypes - -export type CartHooks = Core.CartHooks - -export type GetCartHook = CartHooks['getCart'] -export type AddItemHook = CartHooks['addItem'] -export type UpdateItemHook = CartHooks['updateItem'] -export type RemoveItemHook = CartHooks['removeItem'] - -export type CartSchema = Core.CartSchema - -export type CartHandlers = Core.CartHandlers - -export type GetCartHandler = CartHandlers['getCart'] -export type AddItemHandler = CartHandlers['addItem'] -export type UpdateItemHandler = CartHandlers['updateItem'] -export type RemoveItemHandler = CartHandlers['removeItem'] diff --git a/framework/ordercloud/types/category.ts b/framework/ordercloud/types/category.ts deleted file mode 100644 index 247844a56..000000000 --- a/framework/ordercloud/types/category.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface RawCategory { - ID: string - Name: string - Description: null | string - ListOrder: number - Active: boolean - ParentID: null - ChildCount: number - xp: null -} diff --git a/framework/ordercloud/types/checkout.ts b/framework/ordercloud/types/checkout.ts deleted file mode 100644 index 17cbf43de..000000000 --- a/framework/ordercloud/types/checkout.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as Core from '@commerce/types/checkout' - -export type CheckoutTypes = Core.CheckoutTypes -export type CheckoutSchema = Core.CheckoutSchema diff --git a/framework/ordercloud/types/customer/address.ts b/framework/ordercloud/types/customer/address.ts deleted file mode 100644 index 3aaddc9a2..000000000 --- a/framework/ordercloud/types/customer/address.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as Core from '@commerce/types/customer/address' - -export type CustomerAddressTypes = Core.CustomerAddressTypes -export type CustomerAddressSchema = Core.CustomerAddressSchema - -export interface OrdercloudAddress { - ID: string; - "FromCompanyID": string; - "ToCompanyID": string; - "FromUserID": string; - "BillingAddressID": null, - "BillingAddress": null, - "ShippingAddressID": null, - "Comments": null, - "LineItemCount": number; - "Status": string; - "DateCreated": string; - "DateSubmitted": null, - "DateApproved": null, - "DateDeclined": null, - "DateCanceled": null, - "DateCompleted": null, - "LastUpdated": string; - "Subtotal": number - "ShippingCost": number - "TaxCost": number - "PromotionDiscount": number - "Total": number - "IsSubmitted": false, - "xp": null -} diff --git a/framework/ordercloud/types/customer/card.ts b/framework/ordercloud/types/customer/card.ts deleted file mode 100644 index eb1abffbb..000000000 --- a/framework/ordercloud/types/customer/card.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as Core from '@commerce/types/customer/card' - -export type CustomerCardTypes = Core.CustomerCardTypes -export type CustomerCardSchema = Core.CustomerCardSchema - -export interface OredercloudCreditCard { - "ID": string; - "Editable": boolean; - "Token": string; - "DateCreated": string; - "CardType": string; - "PartialAccountNumber": string; - "CardholderName": string; - "ExpirationDate": string; - "xp": null -} diff --git a/framework/ordercloud/types/node.d.ts b/framework/ordercloud/types/node.d.ts deleted file mode 100644 index f4e4a21f4..000000000 --- a/framework/ordercloud/types/node.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare module NodeJS { - interface Global { - token: string | null | undefined - } -} diff --git a/framework/ordercloud/types/product.ts b/framework/ordercloud/types/product.ts deleted file mode 100644 index 8ccb778d2..000000000 --- a/framework/ordercloud/types/product.ts +++ /dev/null @@ -1,55 +0,0 @@ -interface RawVariantSpec { - SpecID: string - Name: string - OptionID: string - Value: string - PriceMarkupType: string - PriceMarkup: string | null -} - -export interface RawSpec { - ID: string - Name: string - Options: { - ID: string - Value: string - xp: { - hexColor?: string - } - }[] -} - -export interface RawVariant { - ID: string - Specs: RawVariantSpec[] -} - -export interface RawProduct { - OwnerID: string - DefaultPriceScheduleID: string | null - AutoForward: boolean - ID: string - Name: string - Description: string - QuantityMultiplier: number - ShipWeight: null - ShipHeight: null - ShipWidth: null - ShipLength: null - Active: boolean - SpecCount: number - VariantCount: number - ShipFromAddressID: null - Inventory: null - DefaultSupplierID: null - AllSuppliersCanSell: boolean - xp: { - Price: number - PriceCurrency: string - Images: { - url: string - }[] - Variants?: RawVariant[] - Specs?: RawSpec[] - } -} diff --git a/framework/ordercloud/utils/product.ts b/framework/ordercloud/utils/product.ts deleted file mode 100644 index ee334f175..000000000 --- a/framework/ordercloud/utils/product.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { Product } from '@commerce/types/product' - -import type { RawProduct } from '../types/product' - -export function normalize(product: RawProduct): Product { - return { - id: product.ID, - name: product.Name, - description: product.Description, - slug: product.ID, - images: product.xp.Images, - price: { - value: product.xp.Price, - currencyCode: product.xp.PriceCurrency, - }, - variants: product.xp.Variants?.length - ? product.xp.Variants.map((variant) => ({ - id: variant.ID, - options: variant.Specs.map((spec) => ({ - id: spec.SpecID, - __typename: 'MultipleChoiceOption', - displayName: spec.Name, - values: [ - { - label: spec.Value, - }, - ], - })), - })) - : [ - { - id: '', - options: [], - }, - ], - options: product.xp.Specs?.length - ? product.xp.Specs.map((spec) => ({ - id: spec.ID, - displayName: spec.Name, - values: spec.Options.map((option) => ({ - label: option.Value, - ...(option.xp?.hexColor && { hexColors: [option.xp.hexColor] }), - })), - })) - : [], - } -} diff --git a/framework/ordercloud/wishlist/use-add-item.tsx b/framework/ordercloud/wishlist/use-add-item.tsx deleted file mode 100644 index 75f067c3a..000000000 --- a/framework/ordercloud/wishlist/use-add-item.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { useCallback } from 'react' - -export function emptyHook() { - const useEmptyHook = async (options = {}) => { - return useCallback(async function () { - return Promise.resolve() - }, []) - } - - return useEmptyHook -} - -export default emptyHook diff --git a/framework/ordercloud/wishlist/use-remove-item.tsx b/framework/ordercloud/wishlist/use-remove-item.tsx deleted file mode 100644 index a2d3a8a05..000000000 --- a/framework/ordercloud/wishlist/use-remove-item.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { useCallback } from 'react' - -type Options = { - includeProducts?: boolean -} - -export function emptyHook(options?: Options) { - const useEmptyHook = async ({ id }: { id: string | number }) => { - return useCallback(async function () { - return Promise.resolve() - }, []) - } - - return useEmptyHook -} - -export default emptyHook diff --git a/framework/ordercloud/wishlist/use-wishlist.tsx b/framework/ordercloud/wishlist/use-wishlist.tsx deleted file mode 100644 index 9fe0e758f..000000000 --- a/framework/ordercloud/wishlist/use-wishlist.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { HookFetcher } from '@commerce/utils/types' -import type { Product } from '@commerce/types/product' - -const defaultOpts = {} - -export type Wishlist = { - items: [ - { - product_id: number - variant_id: number - id: number - product: Product - } - ] -} - -export interface UseWishlistOptions { - includeProducts?: boolean -} - -export interface UseWishlistInput extends UseWishlistOptions { - customerId?: number -} - -export const fetcher: HookFetcher = () => { - return null -} - -export function extendHook( - customFetcher: typeof fetcher, - // swrOptions?: SwrOptions - swrOptions?: any -) { - const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => { - return { data: null } - } - - useWishlist.extend = extendHook - - return useWishlist -} - -export default extendHook(fetcher) diff --git a/package.json b/package.json index 95fc52b03..df75d22c5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "react-fast-marquee": "^1.1.4", "react-merge-refs": "^1.1.0", "react-use-measure": "^2.0.4", - "stripe": "^8.176.0", "swell-js": "^4.0.0-next.0", "swr": "^0.5.6", "tabbable": "^5.2.0", diff --git a/yarn.lock b/yarn.lock index 4b0cce00e..d1d2cbf34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1177,11 +1177,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67" integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ== -"@types/node@>=8.1.0": - version "16.9.6" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.6.tgz#040a64d7faf9e5d9e940357125f0963012e66f04" - integrity sha512-YHUZhBOMTM3mjFkXVcK+WwAcYmyhe1wL4lfqNtzI0b3qAy7yuSetnM7QJazgE5PFmgVTNGiLOgRFfJMqW7XpSQ== - "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" @@ -5710,13 +5705,6 @@ qs@6.7.0: resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== -qs@^6.6.0: - version "6.10.1" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.1.tgz#4931482fa8d647a5aab799c5271d2133b981fb6a" - integrity sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg== - dependencies: - side-channel "^1.0.4" - querystring-es3@0.2.1, querystring-es3@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" @@ -6518,14 +6506,6 @@ strip-json-comments@~2.0.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= -stripe@^8.176.0: - version "8.176.0" - resolved "https://registry.yarnpkg.com/stripe/-/stripe-8.176.0.tgz#2f4980ab49acbfe6d67ecaddd54c05e20de9532c" - integrity sha512-0KCDo8TWFgeNWU7cPaqdjO2u2OSth0cmWYZmA7xsuxRCk7/lgWbJ/UbeSphx74cCIjFCmGuzDoNuNxqon9lEbg== - dependencies: - "@types/node" ">=8.1.0" - qs "^6.6.0" - styled-jsx@3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-3.3.2.tgz#2474601a26670a6049fb4d3f94bd91695b3ce018"