mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
changes
This commit is contained in:
parent
dd9b913f6d
commit
dd28712e51
@ -1,41 +1,11 @@
|
|||||||
import { VendureConfig } from '../'
|
|
||||||
import { OperationContext } from '@commerce/api/operations'
|
|
||||||
import { Provider } from '../../../bigcommerce/api'
|
|
||||||
|
|
||||||
export type Page = any
|
export type Page = any
|
||||||
|
export type GetAllPagesResult = { pages: Page[] }
|
||||||
|
|
||||||
export type GetAllPagesResult<
|
export default function getAllPagesOperation() {
|
||||||
T extends { pages: any[] } = { pages: Page[] }
|
function getAllPages(): GetAllPagesResult {
|
||||||
> = T
|
|
||||||
|
|
||||||
export default function getAllPagesOperation({
|
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function getAllPages(opts?: {
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<GetAllPagesResult>
|
|
||||||
|
|
||||||
async function getAllPages<T extends { pages: any[] }>(opts: {
|
|
||||||
url: string
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<GetAllPagesResult<T>>
|
|
||||||
|
|
||||||
async function getAllPages({
|
|
||||||
config: cfg,
|
|
||||||
preview,
|
|
||||||
}: {
|
|
||||||
url?: string
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
} = {}): Promise<GetAllPagesResult> {
|
|
||||||
const config = commerce.getConfig(cfg)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pages: [],
|
pages: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAllPages
|
return getAllPages
|
||||||
}
|
}
|
||||||
|
@ -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 = {
|
export type GetAllProductPathsResult = {
|
||||||
products: Array<{ node: { path: string } }>
|
products: Array<{ path: string }>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function getAllProductPathsOperation({
|
export default function getAllProductPathsOperation() {
|
||||||
commerce,
|
function getAllProductPaths(): GetAllProductPathsResult {
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function getAllProductPaths<
|
|
||||||
T extends GetAllProductPathsOperation
|
|
||||||
>(opts?: {
|
|
||||||
variables?: T['variables']
|
|
||||||
config?: BigcommerceConfig
|
|
||||||
}): Promise<T['data']>
|
|
||||||
|
|
||||||
async function getAllProductPaths<T extends GetAllProductPathsOperation>(
|
|
||||||
opts: {
|
|
||||||
variables?: T['variables']
|
|
||||||
config?: BigcommerceConfig
|
|
||||||
} & OperationOptions
|
|
||||||
): Promise<T['data']>
|
|
||||||
|
|
||||||
async function getAllProductPaths<T extends GetAllProductPathsOperation>({
|
|
||||||
query = getAllProductPathsQuery,
|
|
||||||
variables,
|
|
||||||
config: cfg,
|
|
||||||
}: {
|
|
||||||
query?: string
|
|
||||||
variables?: T['variables']
|
|
||||||
config?: BigcommerceConfig
|
|
||||||
} = {}): Promise<T['data']> {
|
|
||||||
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<GetAllProductPathsQuery>(query, {
|
|
||||||
variables,
|
|
||||||
})
|
|
||||||
const products = data.products.items
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
products: products.map((p) => ({ path: `/${p.slug}` })),
|
products: [].map((p) => ({ path: `/hello` })),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,6 @@
|
|||||||
import { OperationContext } from '@commerce/api/operations'
|
export default function getCustomerWishlistOperation() {
|
||||||
import { Provider, VendureConfig } from '../'
|
function getCustomerWishlist(): any {
|
||||||
|
|
||||||
export default function getCustomerWishlistOperation({
|
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function getCustomerWishlist({
|
|
||||||
config: cfg,
|
|
||||||
variables,
|
|
||||||
includeProducts,
|
|
||||||
}: {
|
|
||||||
url?: string
|
|
||||||
variables: any
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
includeProducts?: boolean
|
|
||||||
}): Promise<any> {
|
|
||||||
// Not implemented as Vendure does not ship with wishlist functionality at present
|
|
||||||
const config = commerce.getConfig(cfg)
|
|
||||||
return { wishlist: {} }
|
return { wishlist: {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
return getCustomerWishlist
|
return getCustomerWishlist
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,12 @@
|
|||||||
import { VendureConfig, Provider } from '../'
|
|
||||||
import { OperationContext } from '@commerce/api/operations'
|
|
||||||
|
|
||||||
export type Page = any
|
export type Page = any
|
||||||
|
export type GetPageResult = { page?: Page }
|
||||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
|
||||||
|
|
||||||
export type PageVariables = {
|
export type PageVariables = {
|
||||||
id: number
|
id: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function getPageOperation({
|
export default function getPageOperation() {
|
||||||
commerce,
|
function getPage(): GetPageResult {
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function getPage(opts: {
|
|
||||||
url?: string
|
|
||||||
variables: PageVariables
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<GetPageResult>
|
|
||||||
|
|
||||||
async function getPage<T extends { page?: any }, V = any>(opts: {
|
|
||||||
url: string
|
|
||||||
variables: V
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<GetPageResult<T>>
|
|
||||||
|
|
||||||
async function getPage({
|
|
||||||
url,
|
|
||||||
variables,
|
|
||||||
config: cfg,
|
|
||||||
preview,
|
|
||||||
}: {
|
|
||||||
url?: string
|
|
||||||
variables: PageVariables
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<GetPageResult> {
|
|
||||||
const config = commerce.getConfig(cfg)
|
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return getPage
|
return getPage
|
||||||
}
|
}
|
||||||
|
@ -1,69 +1,8 @@
|
|||||||
import { Product } from '@commerce/types/product'
|
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<Provider>) {
|
|
||||||
async function getProduct({
|
|
||||||
query = getProductQuery,
|
|
||||||
variables,
|
|
||||||
config: cfg,
|
|
||||||
}: {
|
|
||||||
query?: string
|
|
||||||
variables: { slug: string }
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<Product | {} | any> {
|
|
||||||
const config = commerce.getConfig(cfg)
|
|
||||||
|
|
||||||
const locale = config.locale
|
|
||||||
const { data } = await config.fetch<GetProductQuery>(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<Product | {} | any> {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return getProduct
|
return getProduct
|
||||||
}
|
}
|
||||||
|
@ -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<Provider>) {
|
|
||||||
async function login<T extends LoginOperation>(opts: {
|
|
||||||
variables: T['variables']
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
res: ServerResponse
|
|
||||||
}): Promise<T['data']>
|
|
||||||
|
|
||||||
async function login<T extends LoginOperation>(
|
|
||||||
opts: {
|
|
||||||
variables: T['variables']
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
res: ServerResponse
|
|
||||||
} & OperationOptions
|
|
||||||
): Promise<T['data']>
|
|
||||||
|
|
||||||
async function login<T extends LoginOperation>({
|
|
||||||
query = loginMutation,
|
|
||||||
variables,
|
|
||||||
res: response,
|
|
||||||
config: cfg,
|
|
||||||
}: {
|
|
||||||
query?: string
|
|
||||||
variables: T['variables']
|
|
||||||
res: ServerResponse
|
|
||||||
config?: Partial<VendureConfig>
|
|
||||||
}): Promise<T['data']> {
|
|
||||||
const config = commerce.getConfig(cfg)
|
|
||||||
|
|
||||||
const { data, res } = await config.fetch<LoginMutation>(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
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ import { fetcher } from './fetcher'
|
|||||||
export const vendureProvider: Provider = {
|
export const vendureProvider: Provider = {
|
||||||
locale: 'en-us',
|
locale: 'en-us',
|
||||||
cartCookie: 'session',
|
cartCookie: 'session',
|
||||||
fetcher,
|
fetcher: (e) => e,
|
||||||
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
|
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
|
||||||
customer: { useCustomer },
|
customer: { useCustomer },
|
||||||
products: { useSearch },
|
products: { useSearch },
|
||||||
|
@ -42,6 +42,12 @@
|
|||||||
"components/wishlist",
|
"components/wishlist",
|
||||||
"components/cart",
|
"components/cart",
|
||||||
"components/auth",
|
"components/auth",
|
||||||
|
"components/wishlist",
|
||||||
|
"components/cart",
|
||||||
|
"components/auth",
|
||||||
|
"components/wishlist",
|
||||||
|
"components/cart",
|
||||||
|
"components/auth",
|
||||||
"components/wishlist"
|
"components/wishlist"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user