From 62e03f518cff8ecce8da7b750f740c22f6d458c6 Mon Sep 17 00:00:00 2001 From: GunaTrika Date: Mon, 19 Jul 2021 18:09:07 +0530 Subject: [PATCH] Adding supported files for new provider --- .../elasticpath/api/endpoints/cart/index.ts | 1 + .../api/endpoints/catalog/index.ts | 1 + .../api/endpoints/catalog/products.ts | 1 + .../api/endpoints/checkout/index.ts | 1 + .../api/endpoints/customer/index.ts | 1 + .../elasticpath/api/endpoints/logout/index.ts | 1 + .../elasticpath/api/endpoints/signup/index.ts | 1 + .../api/endpoints/wishlist/index.tsx | 1 + framework/elasticpath/api/index.ts | 22 ++++++++-- .../api/operations/get-all-pages.ts | 19 ++++++++ .../api/operations/get-all-product-paths.ts | 15 +++++++ .../api/operations/get-all-products.ts | 25 +++++++++++ .../api/operations/get-customer-wishlist.ts | 6 +++ .../elasticpath/api/operations/get-page.ts | 13 ++++++ .../elasticpath/api/operations/get-product.ts | 26 +++++++++++ .../api/operations/get-site-info.ts | 43 +++++++++++++++++++ framework/elasticpath/next.config.js | 8 ++++ 17 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 framework/elasticpath/api/endpoints/cart/index.ts create mode 100644 framework/elasticpath/api/endpoints/catalog/index.ts create mode 100644 framework/elasticpath/api/endpoints/catalog/products.ts create mode 100644 framework/elasticpath/api/endpoints/checkout/index.ts create mode 100644 framework/elasticpath/api/endpoints/customer/index.ts create mode 100644 framework/elasticpath/api/endpoints/logout/index.ts create mode 100644 framework/elasticpath/api/endpoints/signup/index.ts create mode 100644 framework/elasticpath/api/endpoints/wishlist/index.tsx create mode 100644 framework/elasticpath/api/operations/get-all-pages.ts create mode 100644 framework/elasticpath/api/operations/get-all-product-paths.ts create mode 100644 framework/elasticpath/api/operations/get-all-products.ts create mode 100644 framework/elasticpath/api/operations/get-customer-wishlist.ts create mode 100644 framework/elasticpath/api/operations/get-page.ts create mode 100644 framework/elasticpath/api/operations/get-product.ts create mode 100644 framework/elasticpath/api/operations/get-site-info.ts diff --git a/framework/elasticpath/api/endpoints/cart/index.ts b/framework/elasticpath/api/endpoints/cart/index.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/cart/index.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/catalog/index.ts b/framework/elasticpath/api/endpoints/catalog/index.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/catalog/index.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/catalog/products.ts b/framework/elasticpath/api/endpoints/catalog/products.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/catalog/products.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/checkout/index.ts b/framework/elasticpath/api/endpoints/checkout/index.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/checkout/index.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/customer/index.ts b/framework/elasticpath/api/endpoints/customer/index.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/customer/index.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/logout/index.ts b/framework/elasticpath/api/endpoints/logout/index.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/logout/index.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/signup/index.ts b/framework/elasticpath/api/endpoints/signup/index.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/signup/index.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/endpoints/wishlist/index.tsx b/framework/elasticpath/api/endpoints/wishlist/index.tsx new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/elasticpath/api/endpoints/wishlist/index.tsx @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/elasticpath/api/index.ts b/framework/elasticpath/api/index.ts index 8680d90ab..2a47a8d6a 100644 --- a/framework/elasticpath/api/index.ts +++ b/framework/elasticpath/api/index.ts @@ -7,7 +7,15 @@ import { import createFetcher from './utils/fetch-local' import type { LoginAPI } from './endpoints/login' + import login from './operations/login' +import getAllPages from './operations/get-all-pages' +import getPage from './operations/get-page' +import getSiteInfo from './operations/get-site-info' +import getCustomerWishlist from './operations/get-customer-wishlist' +import getAllProductPaths from './operations/get-all-product-paths' +import getAllProducts from './operations/get-all-products' +import getProduct from './operations/get-product' const API_URL = process.env.NEXT_PUBLIC_ELASTICPATH_BASE const STOREID = process.env.NEXT_PUBLIC_ELASTICPATH_STOREID @@ -36,7 +44,15 @@ const config: any = { } const operations = { - login + login, + + getAllPages, + getPage, + getSiteInfo, + getCustomerWishlist, + getAllProductPaths, + getAllProducts, + getProduct } export interface ElasticpathConfig extends CommerceAPIConfig { @@ -50,10 +66,10 @@ export type Provider = typeof provider export type APIs = | LoginAPI -export type ElasticpathAPI

= CommerceAPI

+export type ElasticpathAPI

= CommerceAPI

export function getCommerceApi

( customProvider: P = provider as any ): ElasticpathAPI

{ - return commerceApi(customProvider) + return commerceApi(customProvider as any) } diff --git a/framework/elasticpath/api/operations/get-all-pages.ts b/framework/elasticpath/api/operations/get-all-pages.ts new file mode 100644 index 000000000..e80bf92b1 --- /dev/null +++ b/framework/elasticpath/api/operations/get-all-pages.ts @@ -0,0 +1,19 @@ +export type Page = { url: string } +export type GetAllPagesResult = { pages: Page[] } +import type { ElasticpathConfig } from '../index' + +export default function getAllPagesOperation() { + function getAllPages({ + config, + preview, + }: { + url?: string + config?: Partial + preview?: boolean + }): Promise { + return Promise.resolve({ + pages: [], + }) + } + return getAllPages +} diff --git a/framework/elasticpath/api/operations/get-all-product-paths.ts b/framework/elasticpath/api/operations/get-all-product-paths.ts new file mode 100644 index 000000000..fff24e791 --- /dev/null +++ b/framework/elasticpath/api/operations/get-all-product-paths.ts @@ -0,0 +1,15 @@ +import data from '../../data.json' + +export type GetAllProductPathsResult = { + products: Array<{ path: string }> +} + +export default function getAllProductPathsOperation() { + function getAllProductPaths(): Promise { + return Promise.resolve({ + products: data.products.map(({ path }) => ({ path })), + }) + } + + return getAllProductPaths +} diff --git a/framework/elasticpath/api/operations/get-all-products.ts b/framework/elasticpath/api/operations/get-all-products.ts new file mode 100644 index 000000000..76b1fa036 --- /dev/null +++ b/framework/elasticpath/api/operations/get-all-products.ts @@ -0,0 +1,25 @@ +import { Product } from '@commerce/types/product' +import { GetAllProductsOperation } from '@commerce/types/product' +import type { OperationContext } from '@commerce/api/operations' +import type { ElasticpathConfig, Provider } from '../index' +import data from '../../data.json' + +export default function getAllProductsOperation({ + commerce, +}: OperationContext) { + async function getAllProducts({ + query = '', + variables, + config, + }: { + query?: string + variables?: T['variables'] + config?: Partial + preview?: boolean + } = {}): Promise<{ products: Product[] | any[] }> { + return { + products: data.products, + } + } + return getAllProducts +} diff --git a/framework/elasticpath/api/operations/get-customer-wishlist.ts b/framework/elasticpath/api/operations/get-customer-wishlist.ts new file mode 100644 index 000000000..8c34b9e87 --- /dev/null +++ b/framework/elasticpath/api/operations/get-customer-wishlist.ts @@ -0,0 +1,6 @@ +export default function getCustomerWishlistOperation() { + function getCustomerWishlist(): any { + return { wishlist: {} } + } + return getCustomerWishlist +} diff --git a/framework/elasticpath/api/operations/get-page.ts b/framework/elasticpath/api/operations/get-page.ts new file mode 100644 index 000000000..b0cfdf58f --- /dev/null +++ b/framework/elasticpath/api/operations/get-page.ts @@ -0,0 +1,13 @@ +export type Page = any +export type GetPageResult = { page?: Page } + +export type PageVariables = { + id: number +} + +export default function getPageOperation() { + function getPage(): Promise { + return Promise.resolve({}) + } + return getPage +} diff --git a/framework/elasticpath/api/operations/get-product.ts b/framework/elasticpath/api/operations/get-product.ts new file mode 100644 index 000000000..ba3411bae --- /dev/null +++ b/framework/elasticpath/api/operations/get-product.ts @@ -0,0 +1,26 @@ +import type { ElasticpathConfig } from '../index' +import { Product } from '@commerce/types/product' +import { GetProductOperation } from '@commerce/types/product' +import data from '../../data.json' +import type { OperationContext } from '@commerce/api/operations' + +export default function getProductOperation({ + commerce, +}: OperationContext) { + async function getProduct({ + query = '', + variables, + config, + }: { + query?: string + variables?: T['variables'] + config?: Partial + preview?: boolean + } = {}): Promise { + return { + product: data.products.find(({ slug }) => slug === variables!.slug), + } + } + + return getProduct +} diff --git a/framework/elasticpath/api/operations/get-site-info.ts b/framework/elasticpath/api/operations/get-site-info.ts new file mode 100644 index 000000000..6e9c9fb91 --- /dev/null +++ b/framework/elasticpath/api/operations/get-site-info.ts @@ -0,0 +1,43 @@ +import { OperationContext } from '@commerce/api/operations' +import { Category } from '@commerce/types/site' +import { ElasticpathConfig } from '../index' + +export type GetSiteInfoResult< + T extends { categories: any[]; brands: any[] } = { + categories: Category[] + brands: any[] + } +> = T + +export default function getSiteInfoOperation({}: OperationContext) { + function getSiteInfo({ + query, + variables, + config: cfg, + }: { + query?: string + variables?: any + config?: Partial + preview?: boolean + } = {}): Promise { + return Promise.resolve({ + categories: [ + { + id: 'new-arrivals', + name: 'New Arrivals', + slug: 'new-arrivals', + path: '/new-arrivals', + }, + { + id: 'featured', + name: 'Featured', + slug: 'featured', + path: '/featured', + }, + ], + brands: [], + }) + } + + return getSiteInfo +} diff --git a/framework/elasticpath/next.config.js b/framework/elasticpath/next.config.js index e69de29bb..ce46b706f 100644 --- a/framework/elasticpath/next.config.js +++ b/framework/elasticpath/next.config.js @@ -0,0 +1,8 @@ +const commerce = require('./commerce.config.json') + +module.exports = { + commerce, + images: { + domains: ['localhost'], + }, +}