From dd28712e51678faca67703cc9a493b15d1d6bce8 Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Thu, 10 Jun 2021 16:44:34 -0300 Subject: [PATCH] changes --- .../local/api/operations/get-all-pages.ts | 36 +--------- .../api/operations/get-all-product-paths.ts | 47 ++------------ .../api/operations/get-customer-wishlist.ts | 21 +----- framework/local/api/operations/get-page.ts | 39 +---------- framework/local/api/operations/get-product.ts | 65 +------------------ framework/local/api/operations/login.ts | 60 ----------------- framework/local/provider.ts | 2 +- tsconfig.json | 6 ++ 8 files changed, 21 insertions(+), 255 deletions(-) delete mode 100644 framework/local/api/operations/login.ts diff --git a/framework/local/api/operations/get-all-pages.ts b/framework/local/api/operations/get-all-pages.ts index 43170cda8..22156a4a2 100644 --- a/framework/local/api/operations/get-all-pages.ts +++ b/framework/local/api/operations/get-all-pages.ts @@ -1,41 +1,11 @@ -import { VendureConfig } from '../' -import { OperationContext } from '@commerce/api/operations' -import { Provider } from '../../../bigcommerce/api' - export type Page = any +export type GetAllPagesResult = { pages: Page[] } -export type GetAllPagesResult< - T extends { pages: any[] } = { pages: Page[] } -> = T - -export default function getAllPagesOperation({ - commerce, -}: OperationContext) { - async function getAllPages(opts?: { - config?: Partial - preview?: boolean - }): Promise - - async function getAllPages(opts: { - url: string - config?: Partial - preview?: boolean - }): Promise> - - async function getAllPages({ - config: cfg, - preview, - }: { - url?: string - config?: Partial - preview?: boolean - } = {}): Promise { - const config = commerce.getConfig(cfg) - +export default function getAllPagesOperation() { + function getAllPages(): GetAllPagesResult { return { pages: [], } } - return getAllPages } diff --git a/framework/local/api/operations/get-all-product-paths.ts b/framework/local/api/operations/get-all-product-paths.ts index 54ca3b136..ac753a59c 100644 --- a/framework/local/api/operations/get-all-product-paths.ts +++ b/framework/local/api/operations/get-all-product-paths.ts @@ -1,50 +1,11 @@ -import { OperationContext, OperationOptions } from '@commerce/api/operations' -import type { GetAllProductPathsQuery } from '../../schema' -import { Provider } from '../index' -import { getAllProductPathsQuery } from '../../utils/queries/get-all-product-paths-query' -import { GetAllProductPathsOperation } from '@commerce/types/product' -import { BigcommerceConfig } from '../../../bigcommerce/api' - export type GetAllProductPathsResult = { - products: Array<{ node: { path: string } }> + products: Array<{ path: string }> } -export default function getAllProductPathsOperation({ - commerce, -}: OperationContext) { - async function getAllProductPaths< - T extends GetAllProductPathsOperation - >(opts?: { - variables?: T['variables'] - config?: BigcommerceConfig - }): Promise - - async function getAllProductPaths( - opts: { - variables?: T['variables'] - config?: BigcommerceConfig - } & OperationOptions - ): Promise - - async function getAllProductPaths({ - query = getAllProductPathsQuery, - variables, - config: cfg, - }: { - query?: string - variables?: T['variables'] - config?: BigcommerceConfig - } = {}): Promise { - const config = commerce.getConfig(cfg) - // RecursivePartial forces the method to check for every prop in the data, which is - // required in case there's a custom `query` - const { data } = await config.fetch(query, { - variables, - }) - const products = data.products.items - +export default function getAllProductPathsOperation() { + function getAllProductPaths(): GetAllProductPathsResult { return { - products: products.map((p) => ({ path: `/${p.slug}` })), + products: [].map((p) => ({ path: `/hello` })), } } diff --git a/framework/local/api/operations/get-customer-wishlist.ts b/framework/local/api/operations/get-customer-wishlist.ts index 0040ef36d..8c34b9e87 100644 --- a/framework/local/api/operations/get-customer-wishlist.ts +++ b/framework/local/api/operations/get-customer-wishlist.ts @@ -1,23 +1,6 @@ -import { OperationContext } from '@commerce/api/operations' -import { Provider, VendureConfig } from '../' - -export default function getCustomerWishlistOperation({ - commerce, -}: OperationContext) { - async function getCustomerWishlist({ - config: cfg, - variables, - includeProducts, - }: { - url?: string - variables: any - config?: Partial - includeProducts?: boolean - }): Promise { - // Not implemented as Vendure does not ship with wishlist functionality at present - const config = commerce.getConfig(cfg) +export default function getCustomerWishlistOperation() { + function getCustomerWishlist(): any { return { wishlist: {} } } - return getCustomerWishlist } diff --git a/framework/local/api/operations/get-page.ts b/framework/local/api/operations/get-page.ts index 59717dc84..7bb33dfcf 100644 --- a/framework/local/api/operations/get-page.ts +++ b/framework/local/api/operations/get-page.ts @@ -1,45 +1,12 @@ -import { VendureConfig, Provider } from '../' -import { OperationContext } from '@commerce/api/operations' - export type Page = any - -export type GetPageResult = T - +export type GetPageResult = { page?: Page } export type PageVariables = { id: number } -export default function getPageOperation({ - commerce, -}: OperationContext) { - async function getPage(opts: { - url?: string - variables: PageVariables - config?: Partial - preview?: boolean - }): Promise - - async function getPage(opts: { - url: string - variables: V - config?: Partial - preview?: boolean - }): Promise> - - async function getPage({ - url, - variables, - config: cfg, - preview, - }: { - url?: string - variables: PageVariables - config?: Partial - preview?: boolean - }): Promise { - const config = commerce.getConfig(cfg) +export default function getPageOperation() { + function getPage(): GetPageResult { return {} } - return getPage } diff --git a/framework/local/api/operations/get-product.ts b/framework/local/api/operations/get-product.ts index 4ab9ed2d9..67385cabc 100644 --- a/framework/local/api/operations/get-product.ts +++ b/framework/local/api/operations/get-product.ts @@ -1,69 +1,8 @@ import { Product } from '@commerce/types/product' -import { OperationContext } from '@commerce/api/operations' -import { Provider, VendureConfig } from '../' -import { GetProductQuery } from '../../schema' -import { getProductQuery } from '../../utils/queries/get-product-query' - -export default function getProductOperation({ - commerce, -}: OperationContext) { - async function getProduct({ - query = getProductQuery, - variables, - config: cfg, - }: { - query?: string - variables: { slug: string } - config?: Partial - preview?: boolean - }): Promise { - const config = commerce.getConfig(cfg) - - const locale = config.locale - const { data } = await config.fetch(query, { variables }) - const product = data.product - - if (product) { - const getOptionGroupName = (id: string): string => { - return product.optionGroups.find((og) => og.id === id)!.name - } - return { - product: { - id: product.id, - name: product.name, - description: product.description, - slug: product.slug, - images: product.assets.map((a) => ({ - url: a.preview, - alt: a.name, - })), - variants: product.variants.map((v) => ({ - id: v.id, - options: v.options.map((o) => ({ - // This __typename property is required in order for the correct - // variant selection to work, see `components/product/helpers.ts` - // `getVariant()` function. - __typename: 'MultipleChoiceOption', - id: o.id, - displayName: getOptionGroupName(o.groupId), - values: [{ label: o.name }], - })), - })), - price: { - value: product.variants[0].priceWithTax / 100, - currencyCode: product.variants[0].currencyCode, - }, - options: product.optionGroups.map((og) => ({ - id: og.id, - displayName: og.name, - values: og.options.map((o) => ({ label: o.name })), - })), - } as Product, - } - } +export default function getProductOperation() { + async function getProduct(): Promise { return {} } - return getProduct } diff --git a/framework/local/api/operations/login.ts b/framework/local/api/operations/login.ts deleted file mode 100644 index 4ad408e0a..000000000 --- a/framework/local/api/operations/login.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { ServerResponse } from 'http' -import type { - OperationContext, - OperationOptions, -} from '@commerce/api/operations' -import { ValidationError } from '@commerce/utils/errors' -import type { LoginOperation } from '../../types/login' -import type { LoginMutation } from '../../schema' -import { Provider, VendureConfig } from '..' -import { loginMutation } from '../../utils/mutations/log-in-mutation' - -export default function loginOperation({ - commerce, -}: OperationContext) { - async function login(opts: { - variables: T['variables'] - config?: Partial - res: ServerResponse - }): Promise - - async function login( - opts: { - variables: T['variables'] - config?: Partial - res: ServerResponse - } & OperationOptions - ): Promise - - async function login({ - query = loginMutation, - variables, - res: response, - config: cfg, - }: { - query?: string - variables: T['variables'] - res: ServerResponse - config?: Partial - }): Promise { - const config = commerce.getConfig(cfg) - - const { data, res } = await config.fetch(query, { - variables, - }) - switch (data.login.__typename) { - case 'NativeAuthStrategyError': - case 'InvalidCredentialsError': - case 'NotVerifiedError': - throw new ValidationError({ - code: data.login.errorCode, - message: data.login.message, - }) - } - return { - result: data.login.id, - } - } - - return login -} diff --git a/framework/local/provider.ts b/framework/local/provider.ts index e100c277b..f24f4be18 100644 --- a/framework/local/provider.ts +++ b/framework/local/provider.ts @@ -13,7 +13,7 @@ import { fetcher } from './fetcher' export const vendureProvider: Provider = { locale: 'en-us', cartCookie: 'session', - fetcher, + fetcher: (e) => e, cart: { useCart, useAddItem, useUpdateItem, useRemoveItem }, customer: { useCustomer }, products: { useSearch }, diff --git a/tsconfig.json b/tsconfig.json index 9c444e661..64477b3c6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -42,6 +42,12 @@ "components/wishlist", "components/cart", "components/auth", + "components/wishlist", + "components/cart", + "components/auth", + "components/wishlist", + "components/cart", + "components/auth", "components/wishlist" ] }