mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
feat: disable Wishlist
chore: setup commerce & next config fix: replace all call to bigcommerce from aquilacms provider feat add validation to input in signup
This commit is contained in:
@@ -1,71 +1,90 @@
|
||||
import type {
|
||||
GetAllProductPathsQuery,
|
||||
GetAllProductPathsQueryVariables,
|
||||
} from '../schema'
|
||||
import type { RecursivePartial, RecursiveRequired } from '../api/utils/types'
|
||||
import filterEdges from '../api/utils/filter-edges'
|
||||
import { AquilacmsConfig, getConfig } from '../api'
|
||||
|
||||
export const getAllProductPathsQuery = /* GraphQL */ `
|
||||
query getAllProductPaths($first: Int = 100) {
|
||||
site {
|
||||
products(first: $first) {
|
||||
edges {
|
||||
node {
|
||||
path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export type GetAllProductsResultAquila = {
|
||||
datas: any[]
|
||||
count: number
|
||||
min: {
|
||||
et: number
|
||||
ati: number
|
||||
}
|
||||
`
|
||||
|
||||
export type ProductPath = NonNullable<
|
||||
NonNullable<GetAllProductPathsQuery['site']['products']['edges']>[0]
|
||||
>
|
||||
|
||||
export type ProductPaths = ProductPath[]
|
||||
|
||||
export type { GetAllProductPathsQueryVariables }
|
||||
|
||||
export type GetAllProductPathsResult<
|
||||
T extends { products: any[] } = { products: ProductPaths }
|
||||
> = T
|
||||
|
||||
async function getAllProductPaths(opts?: {
|
||||
variables?: GetAllProductPathsQueryVariables
|
||||
config?: AquilacmsConfig
|
||||
}): Promise<GetAllProductPathsResult>
|
||||
|
||||
async function getAllProductPaths<
|
||||
T extends { products: any[] },
|
||||
V = any
|
||||
>(opts: {
|
||||
query: string
|
||||
variables?: V
|
||||
config?: AquilacmsConfig
|
||||
}): Promise<GetAllProductPathsResult<T>>
|
||||
|
||||
async function getAllProductPaths({
|
||||
query = getAllProductPathsQuery,
|
||||
variables,
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: GetAllProductPathsQueryVariables
|
||||
config?: AquilacmsConfig
|
||||
} = {}): Promise<GetAllProductPathsResult> {
|
||||
config = getConfig(config)
|
||||
// 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<
|
||||
RecursivePartial<GetAllProductPathsQuery>
|
||||
>(query, { variables })
|
||||
const products = data.site?.products?.edges
|
||||
|
||||
return {
|
||||
products: filterEdges(products as RecursiveRequired<typeof products>),
|
||||
max: {
|
||||
et: number
|
||||
ati: number
|
||||
}
|
||||
specialPriceMin: {
|
||||
et: number
|
||||
ati: number
|
||||
}
|
||||
specialPriceMax: {
|
||||
et: number
|
||||
ati: number
|
||||
}
|
||||
}
|
||||
|
||||
type ProductPath = {
|
||||
node: {
|
||||
path: string
|
||||
}
|
||||
}
|
||||
|
||||
type ProductPaths = ProductPath[]
|
||||
|
||||
type GetAllProductPathsResult<
|
||||
T extends { products: any[] } = { products: ProductPaths }
|
||||
> = T
|
||||
|
||||
async function getAllProductPaths({
|
||||
variables,
|
||||
config,
|
||||
}: {
|
||||
variables?: {
|
||||
locales?: string[] | undefined
|
||||
}
|
||||
config?: AquilacmsConfig
|
||||
} = {}): Promise<GetAllProductPathsResult> {
|
||||
config = getConfig(config)
|
||||
let data: any = {
|
||||
paths: [],
|
||||
products: [],
|
||||
}
|
||||
try {
|
||||
const result: GetAllProductsResultAquila = await config.storeApiFetch(
|
||||
'/v2/products',
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
PostBody: {
|
||||
structure: {
|
||||
translation: 1,
|
||||
},
|
||||
limit: 200,
|
||||
page: 1,
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
// if (variables?.locales) {
|
||||
// for (const locale of variables?.locales) {
|
||||
// for (const p of result.datas) {
|
||||
// const loc = locale.split('-')[0]
|
||||
// if (p.slug[loc]) data.paths.push(`/${locale}/product/${p.slug[loc]}/`)
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
return {
|
||||
products: result.datas.map((p) => {
|
||||
return {
|
||||
node: {
|
||||
path: `/${p.slug['en']}/`,
|
||||
},
|
||||
}
|
||||
}),
|
||||
}
|
||||
// }
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export default getAllProductPaths
|
||||
|
@@ -1,57 +1,7 @@
|
||||
import type {
|
||||
GetAllProductsQuery,
|
||||
GetAllProductsQueryVariables,
|
||||
} from '../schema'
|
||||
import type { Product } from '@commerce/types'
|
||||
import type { RecursivePartial, RecursiveRequired } from '../api/utils/types'
|
||||
import filterEdges from '../api/utils/filter-edges'
|
||||
import setProductLocaleMeta from '../api/utils/set-product-locale-meta'
|
||||
import { productConnectionFragment } from '../api/fragments/product'
|
||||
import { AquilacmsConfig, getConfig } from '../api'
|
||||
import { normalizeProduct } from '../lib/normalize'
|
||||
|
||||
export const getAllProductsQuery = /* GraphQL */ `
|
||||
query getAllProducts(
|
||||
$hasLocale: Boolean = false
|
||||
$locale: String = "null"
|
||||
$entityIds: [Int!]
|
||||
$first: Int = 10
|
||||
$products: Boolean = false
|
||||
$featuredProducts: Boolean = false
|
||||
$bestSellingProducts: Boolean = false
|
||||
$newestProducts: Boolean = false
|
||||
) {
|
||||
site {
|
||||
products(first: $first, entityIds: $entityIds) @include(if: $products) {
|
||||
...productConnnection
|
||||
}
|
||||
featuredProducts(first: $first) @include(if: $featuredProducts) {
|
||||
...productConnnection
|
||||
}
|
||||
bestSellingProducts(first: $first) @include(if: $bestSellingProducts) {
|
||||
...productConnnection
|
||||
}
|
||||
newestProducts(first: $first) @include(if: $newestProducts) {
|
||||
...productConnnection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
${productConnectionFragment}
|
||||
`
|
||||
|
||||
export type ProductEdge = NonNullable<
|
||||
NonNullable<GetAllProductsQuery['site']['products']['edges']>[0]
|
||||
>
|
||||
|
||||
export type ProductNode = ProductEdge['node']
|
||||
|
||||
export type GetAllProductsResult<
|
||||
T extends Record<keyof GetAllProductsResult, any[]> = {
|
||||
products: ProductEdge[]
|
||||
}
|
||||
> = T
|
||||
|
||||
const FIELDS = [
|
||||
'products',
|
||||
'featuredProducts',
|
||||
@@ -65,29 +15,12 @@ export type ProductTypes =
|
||||
| 'bestSellingProducts'
|
||||
| 'newestProducts'
|
||||
|
||||
export type ProductVariables = { field?: ProductTypes } & Omit<
|
||||
GetAllProductsQueryVariables,
|
||||
ProductTypes | 'hasLocale'
|
||||
>
|
||||
|
||||
async function getAllProducts(opts?: {
|
||||
variables?: ProductVariables
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
}): Promise<{ products: Product[] }>
|
||||
|
||||
async function getAllProducts<
|
||||
T extends Record<keyof GetAllProductsResult, any[]>,
|
||||
V = any
|
||||
>(opts: {
|
||||
query: string
|
||||
variables?: V
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetAllProductsResult<T>>
|
||||
export type ProductVariables = { field?: ProductTypes; first?: number } & {
|
||||
locale?: string
|
||||
hasLocale?: boolean
|
||||
}
|
||||
|
||||
async function getAllProducts({
|
||||
query = getAllProductsQuery,
|
||||
variables: { field = 'products', ...vars } = {},
|
||||
config,
|
||||
}: {
|
||||
@@ -95,12 +28,11 @@ async function getAllProducts({
|
||||
variables?: ProductVariables
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
// TODO: fix the product type here
|
||||
} = {}): Promise<{ products: Product[] | any[] }> {
|
||||
config = getConfig(config)
|
||||
|
||||
const locale = vars.locale || config.locale
|
||||
const variables: GetAllProductsQueryVariables = {
|
||||
const locale = (vars.locale || config.locale)?.split('-')[0]
|
||||
const variables = {
|
||||
...vars,
|
||||
locale,
|
||||
hasLocale: !!locale,
|
||||
@@ -112,24 +44,31 @@ async function getAllProducts({
|
||||
)
|
||||
}
|
||||
|
||||
variables[field] = true
|
||||
|
||||
// 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<RecursivePartial<GetAllProductsQuery>>(
|
||||
query,
|
||||
{ variables }
|
||||
)
|
||||
const edges = data.site?.[field]?.edges
|
||||
const products = filterEdges(edges as RecursiveRequired<typeof edges>)
|
||||
let { datas } = await config.storeApiFetch('/v2/products', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
lang: locale,
|
||||
PostBody: {
|
||||
structure: {
|
||||
code: 1,
|
||||
id: 1,
|
||||
translation: 1,
|
||||
attributes: 1,
|
||||
pictos: 1,
|
||||
canonical: 1,
|
||||
images: 1,
|
||||
},
|
||||
page: 1,
|
||||
limit: variables.first,
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
if (locale && config.applyLocale) {
|
||||
products.forEach((product: RecursivePartial<ProductEdge>) => {
|
||||
if (product.node) setProductLocaleMeta(product.node)
|
||||
})
|
||||
}
|
||||
const products = datas.map(normalizeProduct)
|
||||
|
||||
return { products: products.map(({ node }) => normalizeProduct(node as any)) }
|
||||
return { products }
|
||||
}
|
||||
|
||||
export default getAllProducts
|
||||
|
@@ -1,92 +1,18 @@
|
||||
import type { GetProductQuery, GetProductQueryVariables } from '../schema'
|
||||
import setProductLocaleMeta from '../api/utils/set-product-locale-meta'
|
||||
import { productInfoFragment } from '../api/fragments/product'
|
||||
import { AquilacmsConfig, getConfig } from '../api'
|
||||
import { normalizeProduct } from '../lib/normalize'
|
||||
import type { Product } from '@commerce/types'
|
||||
|
||||
export const getProductQuery = /* GraphQL */ `
|
||||
query getProduct(
|
||||
$hasLocale: Boolean = false
|
||||
$locale: String = "null"
|
||||
$path: String!
|
||||
) {
|
||||
site {
|
||||
route(path: $path) {
|
||||
node {
|
||||
__typename
|
||||
... on Product {
|
||||
...productInfo
|
||||
variants {
|
||||
edges {
|
||||
node {
|
||||
entityId
|
||||
defaultImage {
|
||||
urlOriginal
|
||||
altText
|
||||
isDefault
|
||||
}
|
||||
prices {
|
||||
...productPrices
|
||||
}
|
||||
inventory {
|
||||
aggregated {
|
||||
availableToSell
|
||||
warningLevel
|
||||
}
|
||||
isInStock
|
||||
}
|
||||
productOptions {
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
entityId
|
||||
displayName
|
||||
...multipleChoiceOption
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
${productInfoFragment}
|
||||
`
|
||||
|
||||
export type ProductNode = Extract<
|
||||
GetProductQuery['site']['route']['node'],
|
||||
{ __typename: 'Product' }
|
||||
>
|
||||
|
||||
export type GetProductResult<
|
||||
T extends { product?: any } = { product?: ProductNode }
|
||||
> = T
|
||||
import { AquilacmsProduct } from '../types'
|
||||
|
||||
export type ProductVariables = { locale?: string } & (
|
||||
| { path: string; slug?: never }
|
||||
| { path?: never; slug: string }
|
||||
)
|
||||
|
||||
async function getProduct(opts: {
|
||||
variables: ProductVariables
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetProductResult>
|
||||
|
||||
async function getProduct<T extends { product?: any }, V = any>(opts: {
|
||||
query: string
|
||||
variables: V
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetProductResult<T>>
|
||||
export type GetProductResult<
|
||||
T extends { product?: any } = { product?: Product }
|
||||
> = T
|
||||
|
||||
async function getProduct({
|
||||
query = getProductQuery,
|
||||
variables: { slug, ...vars },
|
||||
config,
|
||||
}: {
|
||||
@@ -94,28 +20,32 @@ async function getProduct({
|
||||
variables: ProductVariables
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
}): Promise<Product | {} | any> {
|
||||
}): Promise<Product | any> {
|
||||
config = getConfig(config)
|
||||
|
||||
const locale = vars.locale || config.locale
|
||||
const variables: GetProductQueryVariables = {
|
||||
...vars,
|
||||
locale,
|
||||
hasLocale: !!locale,
|
||||
path: slug ? `/${slug}/` : vars.path!,
|
||||
}
|
||||
const { data } = await config.fetch<GetProductQuery>(query, { variables })
|
||||
const product = data.site?.route?.node
|
||||
|
||||
if (product?.__typename === 'Product') {
|
||||
if (locale && config.applyLocale) {
|
||||
setProductLocaleMeta(product)
|
||||
}
|
||||
|
||||
return { product: normalizeProduct(product as any) }
|
||||
}
|
||||
|
||||
return {}
|
||||
const locale = (vars.locale || config.locale)?.split('-')[0]
|
||||
const data: AquilacmsProduct = await config.storeApiFetch('/v2/product', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
lang: locale,
|
||||
countviews: true,
|
||||
withFilters: false,
|
||||
PostBody: {
|
||||
filter: {
|
||||
[`translation.${locale}.slug`]: slug,
|
||||
},
|
||||
structure: {
|
||||
code: 1,
|
||||
id: 1,
|
||||
translation: 1,
|
||||
attributes: 1,
|
||||
pictos: 1,
|
||||
canonical: 1,
|
||||
images: 1,
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
return { product: normalizeProduct(data) }
|
||||
}
|
||||
|
||||
export default getProduct
|
||||
|
@@ -25,8 +25,7 @@ export const handler: SWRHook<
|
||||
const url = new URL(options.url!, 'http://a')
|
||||
|
||||
if (search) url.searchParams.set('search', search)
|
||||
if (Number.isInteger(categoryId))
|
||||
url.searchParams.set('category', String(categoryId))
|
||||
if (categoryId) url.searchParams.set('category', String(categoryId))
|
||||
if (Number.isInteger(brandId))
|
||||
url.searchParams.set('brand', String(brandId))
|
||||
if (sort) url.searchParams.set('sort', sort)
|
||||
|
Reference in New Issue
Block a user