forked from crowetic/commerce
cleanup, add sorting
This commit is contained in:
parent
6a9c6c3bca
commit
a409c373c4
@ -1,5 +1,5 @@
|
||||
SHOPIFY_STORE_DOMAIN=
|
||||
SHOPIFY_STOREFRONT_ACCESS_TOKEN=
|
||||
SWELL_STORE_DOMAIN=
|
||||
SWELL_STOREFRONT_ACCESS_TOKEN=
|
||||
|
||||
NEXT_PUBLIC_SWELL_STORE_ID=
|
||||
NEXT_PUBLIC_SWELL_PUBLIC_KEY=
|
||||
|
@ -36,7 +36,7 @@ yarn install -D @types/shopify-buy
|
||||
```
|
||||
SHOPIFY_STORE_DOMAIN=
|
||||
SHOPIFY_STOREFRONT_ACCESS_TOKEN=
|
||||
NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN=
|
||||
NEXT_PUBLIC_SWELL_STORE_DOMAIN=
|
||||
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=
|
||||
```
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
import createApiHandler, {
|
||||
ShopifyApiHandler,
|
||||
} from '../utils/create-api-handler'
|
||||
import createApiHandler, { SwellApiHandler } from '../utils/create-api-handler'
|
||||
|
||||
import { SWELL_CHECKOUT_URL_COOKIE } from '../../const'
|
||||
|
||||
import { getConfig } from '..'
|
||||
|
||||
const checkoutApi: ShopifyApiHandler<any> = async (req, res, config) => {
|
||||
const checkoutApi: SwellApiHandler<any> = async (req, res, config) => {
|
||||
config = getConfig()
|
||||
|
||||
const { cookies } = req
|
||||
|
@ -1,26 +1,12 @@
|
||||
import type { CommerceAPIConfig } from '@commerce/api'
|
||||
|
||||
import {
|
||||
API_URL,
|
||||
API_TOKEN,
|
||||
SHOPIFY_CHECKOUT_ID_COOKIE,
|
||||
SHOPIFY_CUSTOMER_TOKEN_COOKIE,
|
||||
SHOPIFY_COOKIE_EXPIRE,
|
||||
SWELL_CHECKOUT_ID_COOKIE,
|
||||
SWELL_CUSTOMER_TOKEN_COOKIE,
|
||||
SWELL_COOKIE_EXPIRE,
|
||||
} from '../const'
|
||||
|
||||
if (!API_URL) {
|
||||
throw new Error(
|
||||
`The environment variable NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN is missing and it's required to access your store`
|
||||
)
|
||||
}
|
||||
|
||||
if (!API_TOKEN) {
|
||||
throw new Error(
|
||||
`The environment variable NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN is missing and it's required to access your store`
|
||||
)
|
||||
}
|
||||
|
||||
import fetchGraphqlApi from './utils/fetch-graphql-api'
|
||||
import fetcher from '../fetcher'
|
||||
import fetchSwellApi from './utils/fetch-swell-api'
|
||||
|
||||
export interface SwellConfig extends CommerceAPIConfig {
|
||||
@ -48,13 +34,13 @@ export class Config {
|
||||
|
||||
const config = new Config({
|
||||
locale: 'en-US',
|
||||
commerceUrl: API_URL,
|
||||
apiToken: API_TOKEN!,
|
||||
cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE,
|
||||
cartCookieMaxAge: SHOPIFY_COOKIE_EXPIRE,
|
||||
commerceUrl: '',
|
||||
apiToken: ''!,
|
||||
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
|
||||
cartCookieMaxAge: SWELL_COOKIE_EXPIRE,
|
||||
fetchSwell: fetchSwellApi,
|
||||
fetch: fetchGraphqlApi,
|
||||
customerCookie: SHOPIFY_CUSTOMER_TOKEN_COOKIE,
|
||||
fetch: fetcher,
|
||||
customerCookie: SWELL_CUSTOMER_TOKEN_COOKIE,
|
||||
})
|
||||
|
||||
export function getConfig(userConfig?: Partial<SwellConfig>) {
|
||||
|
@ -1,41 +1,41 @@
|
||||
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
|
||||
import { SwellConfig, getConfig } from '..'
|
||||
|
||||
export type ShopifyApiHandler<
|
||||
export type SwellApiHandler<
|
||||
T = any,
|
||||
H extends ShopifyHandlers = {},
|
||||
H extends SwellHandlers = {},
|
||||
Options extends {} = {}
|
||||
> = (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<ShopifyApiResponse<T>>,
|
||||
res: NextApiResponse<SwellApiResponse<T>>,
|
||||
config: SwellConfig,
|
||||
handlers: H,
|
||||
// Custom configs that may be used by a particular handler
|
||||
options: Options
|
||||
) => void | Promise<void>
|
||||
|
||||
export type ShopifyHandler<T = any, Body = null> = (options: {
|
||||
export type SwellHandler<T = any, Body = null> = (options: {
|
||||
req: NextApiRequest
|
||||
res: NextApiResponse<ShopifyApiResponse<T>>
|
||||
res: NextApiResponse<SwellApiResponse<T>>
|
||||
config: SwellConfig
|
||||
body: Body
|
||||
}) => void | Promise<void>
|
||||
|
||||
export type ShopifyHandlers<T = any> = {
|
||||
[k: string]: ShopifyHandler<T, any>
|
||||
export type SwellHandlers<T = any> = {
|
||||
[k: string]: SwellHandler<T, any>
|
||||
}
|
||||
|
||||
export type ShopifyApiResponse<T> = {
|
||||
export type SwellApiResponse<T> = {
|
||||
data: T | null
|
||||
errors?: { message: string; code?: string }[]
|
||||
}
|
||||
|
||||
export default function createApiHandler<
|
||||
T = any,
|
||||
H extends ShopifyHandlers = {},
|
||||
H extends SwellHandlers = {},
|
||||
Options extends {} = {}
|
||||
>(
|
||||
handler: ShopifyApiHandler<T, H, Options>,
|
||||
handler: SwellApiHandler<T, H, Options>,
|
||||
handlers: H,
|
||||
defaultOptions: Options
|
||||
) {
|
||||
|
@ -4,6 +4,7 @@ import { SwellConfig } from '..'
|
||||
const fetchAllProducts = async ({
|
||||
config,
|
||||
query,
|
||||
method,
|
||||
variables,
|
||||
acc = [],
|
||||
cursor,
|
||||
@ -14,12 +15,13 @@ const fetchAllProducts = async ({
|
||||
variables?: any
|
||||
cursor?: string
|
||||
}): Promise<ProductEdge[]> => {
|
||||
const { data } = await config.fetch(query, {
|
||||
variables: { ...variables, cursor },
|
||||
})
|
||||
// const response = await config.fetch(query, {
|
||||
// variables: { ...variables, cursor },
|
||||
// })
|
||||
const response = await config.fetchSwell('products', 'list', [{ limit: 100 }])
|
||||
|
||||
const edges: ProductEdge[] = data.products?.edges ?? []
|
||||
const hasNextPage = data.products?.pageInfo?.hasNextPage
|
||||
const edges: ProductEdge[] = response.results ?? []
|
||||
const hasNextPage = response.results.length < response.count
|
||||
acc = acc.concat(edges)
|
||||
|
||||
if (hasNextPage) {
|
||||
|
@ -1,34 +0,0 @@
|
||||
import type { GraphQLFetcher } from '@commerce/api'
|
||||
import fetch from './fetch'
|
||||
|
||||
import { API_URL, API_TOKEN } from '../../const'
|
||||
import { getError } from '../../utils/handle-fetch-response'
|
||||
|
||||
const fetchGraphqlApi: GraphQLFetcher = async (
|
||||
query: string,
|
||||
{ variables } = {},
|
||||
fetchOptions
|
||||
) => {
|
||||
const res = await fetch(API_URL, {
|
||||
...fetchOptions,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Shopify-Storefront-Access-Token': API_TOKEN!,
|
||||
...fetchOptions?.headers,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
variables,
|
||||
}),
|
||||
})
|
||||
|
||||
const { data, errors, status } = await res.json()
|
||||
|
||||
if (errors) {
|
||||
throw getError(errors, status)
|
||||
}
|
||||
|
||||
return { data, res }
|
||||
}
|
||||
export default fetchGraphqlApi
|
@ -6,7 +6,6 @@ const fetchSwellApi = async (
|
||||
variables: [] = []
|
||||
) => {
|
||||
const { swell } = swellConfig
|
||||
|
||||
return await swell[query][method](...variables)
|
||||
}
|
||||
export default fetchSwellApi
|
||||
|
@ -2,7 +2,6 @@ import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError, ValidationError } from '@commerce/utils/errors'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import createCustomerAccessTokenMutation from '../utils/mutations/customer-access-token-create'
|
||||
import {
|
||||
CustomerAccessTokenCreateInput,
|
||||
CustomerUserError,
|
||||
|
@ -2,7 +2,6 @@ import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import customerAccessTokenDeleteMutation from '../utils/mutations/customer-access-token-delete'
|
||||
import { getCustomerToken, setCustomerToken } from '../utils/customer-token'
|
||||
|
||||
export default useLogout as UseLogout<typeof handler>
|
||||
|
@ -4,6 +4,7 @@ import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item'
|
||||
import useCart from './use-cart'
|
||||
import { Cart, CartItemBody } from '../types'
|
||||
import { checkoutToCart } from './utils'
|
||||
import { getCheckoutId } from '../utils'
|
||||
import { Mutation, MutationCheckoutLineItemsAddArgs } from '../schema'
|
||||
import { useCallback } from 'react'
|
||||
|
||||
@ -26,12 +27,12 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {
|
||||
const response = await fetch<Mutation, MutationCheckoutLineItemsAddArgs>({
|
||||
...options,
|
||||
variables: {
|
||||
checkoutId: getCheckoutId(),
|
||||
product_id: item.productId,
|
||||
quantity: item.quantity,
|
||||
},
|
||||
})
|
||||
|
||||
// TODO: Fix this Cart type here
|
||||
return checkoutToCart(response) as any
|
||||
},
|
||||
useHook: ({ fetch }) => () => {
|
||||
|
@ -15,7 +15,6 @@ export const handler: SWRHook<Cart | null> = {
|
||||
const cart = await checkoutCreate(fetch)
|
||||
|
||||
return cart ? normalizeCart(cart) : null
|
||||
// return checkoutToCart({ checkout } as any)
|
||||
},
|
||||
useHook: ({ useData }) => (input) => {
|
||||
return useData({
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import { PageEdge } from '../schema'
|
||||
import { getAllPagesQuery } from '../utils/queries'
|
||||
|
||||
type Variables = {
|
||||
first?: number
|
||||
|
@ -1,16 +1,12 @@
|
||||
export const SHOPIFY_CHECKOUT_ID_COOKIE = 'shopify_checkoutId'
|
||||
export const SWELL_CHECKOUT_ID_COOKIE = 'SWELL_checkoutId'
|
||||
|
||||
export const SWELL_CHECKOUT_URL_COOKIE = 'swell_checkoutUrl'
|
||||
|
||||
export const SHOPIFY_CUSTOMER_TOKEN_COOKIE = 'shopify_customerToken'
|
||||
export const SWELL_CUSTOMER_TOKEN_COOKIE = 'swell_customerToken'
|
||||
|
||||
export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN
|
||||
export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SWELL_STORE_DOMAIN
|
||||
|
||||
export const SHOPIFY_COOKIE_EXPIRE = 30
|
||||
|
||||
export const API_URL = `https://${STORE_DOMAIN}/api/2021-01/graphql.json`
|
||||
|
||||
export const API_TOKEN = process.env.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN
|
||||
export const SWELL_COOKIE_EXPIRE = 30
|
||||
|
||||
export const SWELL_STORE_ID = process.env.NEXT_PUBLIC_SWELL_STORE_ID
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import getCustomerIdQuery from '../utils/queries/get-customer-id-query'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
async function getCustomerId({
|
||||
customerToken: customerAccesToken,
|
||||
config,
|
||||
}: {
|
||||
customerToken: string
|
||||
config?: SwellConfig
|
||||
}): Promise<number | undefined> {
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getCustomerIdQuery, {
|
||||
variables: {
|
||||
customerAccesToken:
|
||||
customerAccesToken || Cookies.get(config.customerCookie),
|
||||
},
|
||||
})
|
||||
|
||||
return data.customer?.id
|
||||
}
|
||||
|
||||
export default getCustomerId
|
@ -2,7 +2,6 @@ import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||
import { Customer } from '@commerce/types'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import { normalizeCustomer } from '../utils/normalize'
|
||||
// import { getCustomerQuery, getCustomerToken } from '../utils'
|
||||
|
||||
export default useCustomer as UseCustomer<typeof handler>
|
||||
|
||||
|
@ -8,11 +8,9 @@ const fetcher: Fetcher = async ({ method = 'get', variables, query }) => {
|
||||
if (Array.isArray(variables)) {
|
||||
const arg1 = variables[0]
|
||||
const arg2 = variables[1]
|
||||
// console.log('fetcher', query, method, variables);
|
||||
const response = await swell[query][method](arg1, arg2)
|
||||
return handleFetchResponse(response)
|
||||
} else {
|
||||
// console.log('fetcher', query, method, variables);
|
||||
const response = await swell[query][method](variables)
|
||||
return handleFetchResponse(response)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
|
||||
import { swellProvider, SwellProvider } from './provider'
|
||||
import {
|
||||
SHOPIFY_CHECKOUT_ID_COOKIE,
|
||||
SWELL_CHECKOUT_ID_COOKIE,
|
||||
SWELL_STORE_ID,
|
||||
SWELL_PUBLIC_KEY,
|
||||
} from './const'
|
||||
@ -21,7 +21,7 @@ export type { SwellProvider }
|
||||
|
||||
export const swellConfig: any = {
|
||||
locale: 'en-us',
|
||||
cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE,
|
||||
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
|
||||
swell,
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,16 @@
|
||||
import { CollectionEdge } from '../schema'
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
|
||||
|
||||
const getAllCollections = async (options?: {
|
||||
variables?: any
|
||||
config: SwellConfig
|
||||
preview?: boolean
|
||||
}) => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
let { config, variables = { limit: 25 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllCollectionsQuery, { variables })
|
||||
const edges = data.collections?.edges ?? []
|
||||
const response = await config.fetchSwell('categories', 'list', { variables })
|
||||
const edges = response.results ?? []
|
||||
|
||||
const categories = edges.map(
|
||||
({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
|
||||
|
@ -2,7 +2,6 @@ import { Product } from '@commerce/types'
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
||||
import { ProductEdge } from '../schema'
|
||||
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
|
||||
|
||||
type ProductPath = {
|
||||
path: string
|
||||
@ -21,17 +20,18 @@ const getAllProductPaths = async (options?: {
|
||||
config?: SwellConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
let { config, variables = { limit: 100 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const products = await fetchAllProducts({
|
||||
config,
|
||||
query: getAllProductsPathsQuery,
|
||||
query: 'products',
|
||||
method: 'list',
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
products: products?.map(({ node: { handle } }: ProductEdge) => ({
|
||||
products: products?.map(({ slug: handle }) => ({
|
||||
node: {
|
||||
path: `/${handle}`,
|
||||
},
|
||||
|
@ -1,7 +1,4 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import { ProductEdge } from '../schema'
|
||||
import { getAllProductsQuery } from '../utils/queries'
|
||||
import { normalizeProduct } from '../utils/normalize'
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
|
@ -22,7 +22,6 @@ const getProduct = async (options: {
|
||||
if (product.variants) {
|
||||
product.variants = product.variants?.results
|
||||
}
|
||||
// console.log('product', product)
|
||||
return {
|
||||
product: normalizeProduct(product),
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
|
||||
import { getAllProductsQuery, normalizeProduct } from '../utils'
|
||||
import { normalizeProduct } from '../utils'
|
||||
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
@ -25,14 +25,22 @@ export const handler: SWRHook<
|
||||
SearchProductsInput
|
||||
> = {
|
||||
fetchOptions: {
|
||||
query: getAllProductsQuery,
|
||||
query: 'products', // String(Math.random()),
|
||||
method: 'list',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {
|
||||
const { categoryId, search } = input
|
||||
const sortMap = new Map([
|
||||
['latest-desc', ''],
|
||||
['price-asc', 'price_asc'],
|
||||
['price-desc', 'price_desc'],
|
||||
['trending-desc', 'popularity'],
|
||||
])
|
||||
const { categoryId, search, sort = 'latest-desc' } = input
|
||||
const mappedSort = sortMap.get(sort)
|
||||
const { results, count: found } = await fetch({
|
||||
query: 'products',
|
||||
method: 'list',
|
||||
variables: { category: categoryId, search },
|
||||
variables: { category: categoryId, search, sort: mappedSort },
|
||||
})
|
||||
|
||||
const products = results.map((product) => {
|
||||
|
@ -78,7 +78,7 @@ export interface SwellCustomer extends Core.Customer {
|
||||
last_name: string
|
||||
}
|
||||
|
||||
export type ShopifyCheckout = {
|
||||
export type SwellCheckout = {
|
||||
id: string
|
||||
webUrl: string
|
||||
lineItems: CheckoutLineItem[]
|
||||
|
@ -1,20 +1,20 @@
|
||||
import Cookies, { CookieAttributes } from 'js-cookie'
|
||||
import { SHOPIFY_COOKIE_EXPIRE, SHOPIFY_CUSTOMER_TOKEN_COOKIE } from '../const'
|
||||
import { SWELL_COOKIE_EXPIRE, SWELL_CUSTOMER_TOKEN_COOKIE } from '../const'
|
||||
|
||||
export const getCustomerToken = () => Cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE)
|
||||
export const getCustomerToken = () => Cookies.get(SWELL_CUSTOMER_TOKEN_COOKIE)
|
||||
|
||||
export const setCustomerToken = (
|
||||
token: string | null,
|
||||
options?: CookieAttributes
|
||||
) => {
|
||||
if (!token) {
|
||||
Cookies.remove(SHOPIFY_CUSTOMER_TOKEN_COOKIE)
|
||||
Cookies.remove(SWELL_CUSTOMER_TOKEN_COOKIE)
|
||||
} else {
|
||||
Cookies.set(
|
||||
SHOPIFY_CUSTOMER_TOKEN_COOKIE,
|
||||
SWELL_CUSTOMER_TOKEN_COOKIE,
|
||||
token,
|
||||
options ?? {
|
||||
expires: SHOPIFY_COOKIE_EXPIRE,
|
||||
expires: SWELL_COOKIE_EXPIRE,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import { SHOPIFY_CHECKOUT_ID_COOKIE } from '../const'
|
||||
import { SWELL_CHECKOUT_ID_COOKIE } from '../const'
|
||||
|
||||
const getCheckoutId = (id?: string) => {
|
||||
return id ?? Cookies.get(SHOPIFY_CHECKOUT_ID_COOKIE)
|
||||
return id ?? Cookies.get(SWELL_CHECKOUT_ID_COOKIE)
|
||||
}
|
||||
|
||||
export default getCheckoutId
|
||||
|
@ -1,7 +1,4 @@
|
||||
import { swellConfig } from '@framework'
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
||||
import getAllProductVendors from './queries/get-all-product-vendors-query'
|
||||
import { SwellConfig } from '../api'
|
||||
|
||||
export type BrandNode = {
|
||||
name: string
|
||||
@ -15,8 +12,8 @@ export type BrandEdge = {
|
||||
export type Brands = BrandEdge[]
|
||||
|
||||
const getVendors = async (config: SwellConfig) => {
|
||||
const vendors =
|
||||
(await config.fetchSwell('attributes', 'get', ['brand']).values) ?? []
|
||||
const vendors: [string] =
|
||||
(await config.fetchSwell('attributes', 'get', ['brand'])).values ?? []
|
||||
|
||||
return [...new Set(vendors)].map((v) => ({
|
||||
node: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
|
||||
export function getError(errors: any[], status: number) {
|
||||
errors = errors ?? [{ message: 'Failed to fetch Shopify API' }]
|
||||
errors = errors ?? [{ message: 'Failed to fetch Swell API' }]
|
||||
return new FetcherError({ errors, status })
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ export { default as getSortVariables } from './get-sort-variables'
|
||||
export { default as getVendors } from './get-vendors'
|
||||
export { default as getCategories } from './get-categories'
|
||||
export { default as getCheckoutId } from './get-checkout-id'
|
||||
export * from './queries'
|
||||
export * from './mutations'
|
||||
|
||||
export * from './normalize'
|
||||
export * from './customer-token'
|
||||
|
@ -1,18 +0,0 @@
|
||||
const associateCustomerWithCheckoutMutation = /* GraphQl */ `
|
||||
mutation associateCustomerWithCheckout($checkoutId: ID!, $customerAccessToken: String!) {
|
||||
checkoutCustomerAssociateV2(checkoutId: $checkoutId, customerAccessToken: $customerAccessToken) {
|
||||
checkout {
|
||||
id
|
||||
}
|
||||
checkoutUserErrors {
|
||||
code
|
||||
field
|
||||
message
|
||||
}
|
||||
customer {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default associateCustomerWithCheckoutMutation
|
@ -1,16 +0,0 @@
|
||||
import { checkoutDetailsFragment } from '../queries/get-checkout-query'
|
||||
|
||||
const checkoutCreateMutation = /* GraphQL */ `
|
||||
mutation {
|
||||
checkoutCreate(input: {}) {
|
||||
userErrors {
|
||||
message
|
||||
field
|
||||
}
|
||||
checkout {
|
||||
${checkoutDetailsFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default checkoutCreateMutation
|
@ -1,16 +0,0 @@
|
||||
import { checkoutDetailsFragment } from '../queries/get-checkout-query'
|
||||
|
||||
const checkoutLineItemAddMutation = /* GraphQL */ `
|
||||
mutation($checkoutId: ID!, $lineItems: [CheckoutLineItemInput!]!) {
|
||||
checkoutLineItemsAdd(checkoutId: $checkoutId, lineItems: $lineItems) {
|
||||
userErrors {
|
||||
message
|
||||
field
|
||||
}
|
||||
checkout {
|
||||
${checkoutDetailsFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default checkoutLineItemAddMutation
|
@ -1,19 +0,0 @@
|
||||
import { checkoutDetailsFragment } from '../queries/get-checkout-query'
|
||||
|
||||
const checkoutLineItemRemoveMutation = /* GraphQL */ `
|
||||
mutation($checkoutId: ID!, $lineItemIds: [ID!]!) {
|
||||
checkoutLineItemsRemove(
|
||||
checkoutId: $checkoutId
|
||||
lineItemIds: $lineItemIds
|
||||
) {
|
||||
userErrors {
|
||||
message
|
||||
field
|
||||
}
|
||||
checkout {
|
||||
${checkoutDetailsFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default checkoutLineItemRemoveMutation
|
@ -1,16 +0,0 @@
|
||||
import { checkoutDetailsFragment } from '../queries/get-checkout-query'
|
||||
|
||||
const checkoutLineItemUpdateMutation = /* GraphQL */ `
|
||||
mutation($checkoutId: ID!, $lineItems: [CheckoutLineItemUpdateInput!]!) {
|
||||
checkoutLineItemsUpdate(checkoutId: $checkoutId, lineItems: $lineItems) {
|
||||
userErrors {
|
||||
message
|
||||
field
|
||||
}
|
||||
checkout {
|
||||
${checkoutDetailsFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default checkoutLineItemUpdateMutation
|
@ -1,16 +0,0 @@
|
||||
const customerAccessTokenCreateMutation = /* GraphQL */ `
|
||||
mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) {
|
||||
customerAccessTokenCreate(input: $input) {
|
||||
customerAccessToken {
|
||||
accessToken
|
||||
expiresAt
|
||||
}
|
||||
customerUserErrors {
|
||||
code
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default customerAccessTokenCreateMutation
|
@ -1,14 +0,0 @@
|
||||
const customerAccessTokenDeleteMutation = /* GraphQL */ `
|
||||
mutation customerAccessTokenDelete($customerAccessToken: String!) {
|
||||
customerAccessTokenDelete(customerAccessToken: $customerAccessToken) {
|
||||
deletedAccessToken
|
||||
deletedCustomerAccessTokenId
|
||||
userErrors {
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export default customerAccessTokenDeleteMutation
|
@ -1,15 +0,0 @@
|
||||
const customerCreateMutation = /* GraphQL */ `
|
||||
mutation customerCreate($input: CustomerCreateInput!) {
|
||||
customerCreate(input: $input) {
|
||||
customerUserErrors {
|
||||
code
|
||||
field
|
||||
message
|
||||
}
|
||||
customer {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default customerCreateMutation
|
@ -1,7 +0,0 @@
|
||||
export { default as customerCreateMutation } from './customer-create'
|
||||
export { default as checkoutCreateMutation } from './checkout-create'
|
||||
export { default as checkoutLineItemAddMutation } from './checkout-line-item-add'
|
||||
export { default as checkoutLineItemUpdateMutation } from './checkout-line-item-update'
|
||||
export { default as checkoutLineItemRemoveMutation } from './checkout-line-item-remove'
|
||||
export { default as customerAccessTokenCreateMutation } from './customer-access-token-create'
|
||||
export { default as customerAccessTokenDeleteMutation } from './customer-access-token-delete'
|
@ -36,7 +36,7 @@ type normalizedProductOption = {
|
||||
const normalizeProductOption = ({
|
||||
id,
|
||||
name: displayName = '',
|
||||
values,
|
||||
values = [],
|
||||
}: ProductOption) => {
|
||||
let returnValues = values.map((value) => {
|
||||
let output: any = {
|
||||
|
@ -1,14 +0,0 @@
|
||||
const getSiteCollectionsQuery = /* GraphQL */ `
|
||||
query getSiteCollections($first: Int!) {
|
||||
collections(first: $first) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
handle
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getSiteCollectionsQuery
|
@ -1,14 +0,0 @@
|
||||
export const getAllPagesQuery = /* GraphQL */ `
|
||||
query getAllPages($first: Int = 250) {
|
||||
pages(first: $first) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
handle
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getAllPagesQuery
|
@ -1,17 +0,0 @@
|
||||
const getAllProductVendors = /* GraphQL */ `
|
||||
query getAllProductVendors($first: Int = 250, $cursor: String) {
|
||||
products(first: $first, after: $cursor) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
vendor
|
||||
}
|
||||
cursor
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getAllProductVendors
|
@ -1,17 +0,0 @@
|
||||
const getAllProductsPathsQuery = /* GraphQL */ `
|
||||
query getAllProductPaths($first: Int = 250, $cursor: String) {
|
||||
products(first: $first, after: $cursor) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
handle
|
||||
}
|
||||
cursor
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getAllProductsPathsQuery
|
@ -1,57 +0,0 @@
|
||||
export const productConnection = `
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
vendor
|
||||
handle
|
||||
description
|
||||
priceRange {
|
||||
minVariantPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
images(first: 1) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
originalSrc
|
||||
altText
|
||||
width
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
export const productsFragment = `
|
||||
products(
|
||||
first: $first
|
||||
sortKey: $sortKey
|
||||
reverse: $reverse
|
||||
query: $query
|
||||
) {
|
||||
${productConnection}
|
||||
}
|
||||
`
|
||||
|
||||
const getAllProductsQuery = /* GraphQL */ `
|
||||
query getAllProducts(
|
||||
$first: Int = 250
|
||||
$query: String = ""
|
||||
$sortKey: ProductSortKeys = RELEVANCE
|
||||
$reverse: Boolean = false
|
||||
) {
|
||||
${productsFragment}
|
||||
}
|
||||
`
|
||||
export default getAllProductsQuery
|
@ -1,62 +0,0 @@
|
||||
export const checkoutDetailsFragment = `
|
||||
id
|
||||
webUrl
|
||||
subtotalPriceV2{
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
totalTaxV2 {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
totalPriceV2 {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
completedAt
|
||||
createdAt
|
||||
taxesIncluded
|
||||
lineItems(first: 250) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
variant {
|
||||
id
|
||||
sku
|
||||
title
|
||||
image {
|
||||
originalSrc
|
||||
altText
|
||||
width
|
||||
height
|
||||
}
|
||||
priceV2{
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
compareAtPriceV2{
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const getCheckoutQuery = /* GraphQL */ `
|
||||
query($checkoutId: ID!) {
|
||||
node(id: $checkoutId) {
|
||||
... on Checkout {
|
||||
${checkoutDetailsFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getCheckoutQuery
|
@ -1,24 +0,0 @@
|
||||
import { productConnection } from './get-all-products-query'
|
||||
|
||||
const getCollectionProductsQuery = /* GraphQL */ `
|
||||
query getProductsFromCollection(
|
||||
$categoryId: ID!
|
||||
$first: Int = 250
|
||||
$sortKey: ProductCollectionSortKeys = RELEVANCE
|
||||
$reverse: Boolean = false
|
||||
) {
|
||||
node(id: $categoryId) {
|
||||
id
|
||||
... on Collection {
|
||||
products(
|
||||
first: $first
|
||||
sortKey: $sortKey
|
||||
reverse: $reverse
|
||||
) {
|
||||
${productConnection}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getCollectionProductsQuery
|
@ -1,8 +0,0 @@
|
||||
export const getCustomerQuery = /* GraphQL */ `
|
||||
query getCustomerId($customerAccessToken: String!) {
|
||||
customer(customerAccessToken: $customerAccessToken) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getCustomerQuery
|
@ -1,16 +0,0 @@
|
||||
export const getCustomerQuery = /* GraphQL */ `
|
||||
query getCustomer($customerAccessToken: String!) {
|
||||
customer(customerAccessToken: $customerAccessToken) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
displayName
|
||||
email
|
||||
phone
|
||||
tags
|
||||
acceptsMarketing
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getCustomerQuery
|
@ -1,14 +0,0 @@
|
||||
export const getPageQuery = /* GraphQL */ `
|
||||
query($id: ID!) {
|
||||
node(id: $id) {
|
||||
id
|
||||
... on Page {
|
||||
title
|
||||
handle
|
||||
body
|
||||
bodySummary
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
export default getPageQuery
|
@ -1,69 +0,0 @@
|
||||
const getProductQuery = /* GraphQL */ `
|
||||
query getProductBySlug($slug: String!) {
|
||||
productByHandle(handle: $slug) {
|
||||
id
|
||||
handle
|
||||
title
|
||||
productType
|
||||
vendor
|
||||
description
|
||||
descriptionHtml
|
||||
options {
|
||||
id
|
||||
name
|
||||
values
|
||||
}
|
||||
priceRange {
|
||||
maxVariantPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
minVariantPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
variants(first: 250) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
sku
|
||||
selectedOptions {
|
||||
name
|
||||
value
|
||||
}
|
||||
priceV2 {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
compareAtPriceV2 {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
images(first: 250) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
originalSrc
|
||||
altText
|
||||
width
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export default getProductQuery
|
@ -1,10 +0,0 @@
|
||||
export { default as getSiteCollectionsQuery } from './get-all-collections-query'
|
||||
export { default as getProductQuery } from './get-product-query'
|
||||
export { default as getAllProductsQuery } from './get-all-products-query'
|
||||
export { default as getAllProductsPathtsQuery } from './get-all-products-paths-query'
|
||||
export { default as getAllProductVendors } from './get-all-product-vendors-query'
|
||||
export { default as getCollectionProductsQuery } from './get-collection-products-query'
|
||||
export { default as getCheckoutQuery } from './get-checkout-query'
|
||||
export { default as getAllPagesQuery } from './get-all-pages-query'
|
||||
export { default as getPageQuery } from './get-page-query'
|
||||
export { default as getCustomerQuery } from './get-customer-query'
|
@ -1,5 +1,5 @@
|
||||
// TODO: replace this hook and other wishlist hooks with a handler, or remove them if
|
||||
// Shopify doesn't have a wishlist
|
||||
// Swell doesn't have a wishlist
|
||||
|
||||
import { HookFetcher } from '@commerce/utils/types'
|
||||
import { Product } from '../schema'
|
||||
|
Loading…
x
Reference in New Issue
Block a user