diff --git a/framework/swell/.env.template b/framework/swell/.env.template index b5f38e883..43c931f45 100644 --- a/framework/swell/.env.template +++ b/framework/swell/.env.template @@ -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= diff --git a/framework/swell/README.md b/framework/swell/README.md index fc6a70ce3..f47a7a028 100644 --- a/framework/swell/README.md +++ b/framework/swell/README.md @@ -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= ``` diff --git a/framework/swell/api/checkout/index.ts b/framework/swell/api/checkout/index.ts index 03f166a1a..0759e2abc 100644 --- a/framework/swell/api/checkout/index.ts +++ b/framework/swell/api/checkout/index.ts @@ -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 = async (req, res, config) => { +const checkoutApi: SwellApiHandler = async (req, res, config) => { config = getConfig() const { cookies } = req diff --git a/framework/swell/api/index.ts b/framework/swell/api/index.ts index 9c41b18ae..1e328062b 100644 --- a/framework/swell/api/index.ts +++ b/framework/swell/api/index.ts @@ -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) { diff --git a/framework/swell/api/utils/create-api-handler.ts b/framework/swell/api/utils/create-api-handler.ts index 7ceb7d423..bd40a7ee4 100644 --- a/framework/swell/api/utils/create-api-handler.ts +++ b/framework/swell/api/utils/create-api-handler.ts @@ -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>, + res: NextApiResponse>, config: SwellConfig, handlers: H, // Custom configs that may be used by a particular handler options: Options ) => void | Promise -export type ShopifyHandler = (options: { +export type SwellHandler = (options: { req: NextApiRequest - res: NextApiResponse> + res: NextApiResponse> config: SwellConfig body: Body }) => void | Promise -export type ShopifyHandlers = { - [k: string]: ShopifyHandler +export type SwellHandlers = { + [k: string]: SwellHandler } -export type ShopifyApiResponse = { +export type SwellApiResponse = { data: T | null errors?: { message: string; code?: string }[] } export default function createApiHandler< T = any, - H extends ShopifyHandlers = {}, + H extends SwellHandlers = {}, Options extends {} = {} >( - handler: ShopifyApiHandler, + handler: SwellApiHandler, handlers: H, defaultOptions: Options ) { diff --git a/framework/swell/api/utils/fetch-all-products.ts b/framework/swell/api/utils/fetch-all-products.ts index 7ad308b04..859ec0212 100644 --- a/framework/swell/api/utils/fetch-all-products.ts +++ b/framework/swell/api/utils/fetch-all-products.ts @@ -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 => { - 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) { diff --git a/framework/swell/api/utils/fetch-graphql-api.ts b/framework/swell/api/utils/fetch-graphql-api.ts deleted file mode 100644 index 321cba2aa..000000000 --- a/framework/swell/api/utils/fetch-graphql-api.ts +++ /dev/null @@ -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 diff --git a/framework/swell/api/utils/fetch-swell-api.ts b/framework/swell/api/utils/fetch-swell-api.ts index c8707230d..e070483ae 100644 --- a/framework/swell/api/utils/fetch-swell-api.ts +++ b/framework/swell/api/utils/fetch-swell-api.ts @@ -6,7 +6,6 @@ const fetchSwellApi = async ( variables: [] = [] ) => { const { swell } = swellConfig - return await swell[query][method](...variables) } export default fetchSwellApi diff --git a/framework/swell/auth/use-login.tsx b/framework/swell/auth/use-login.tsx index cdaf6151b..57c3ce921 100644 --- a/framework/swell/auth/use-login.tsx +++ b/framework/swell/auth/use-login.tsx @@ -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, diff --git a/framework/swell/auth/use-logout.tsx b/framework/swell/auth/use-logout.tsx index 6eebd997f..ae17ba74e 100644 --- a/framework/swell/auth/use-logout.tsx +++ b/framework/swell/auth/use-logout.tsx @@ -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 diff --git a/framework/swell/cart/use-add-item.tsx b/framework/swell/cart/use-add-item.tsx index ff6c7143f..346c6c955 100644 --- a/framework/swell/cart/use-add-item.tsx +++ b/framework/swell/cart/use-add-item.tsx @@ -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 = { const response = await fetch({ ...options, variables: { + checkoutId: getCheckoutId(), product_id: item.productId, quantity: item.quantity, }, }) - // TODO: Fix this Cart type here return checkoutToCart(response) as any }, useHook: ({ fetch }) => () => { diff --git a/framework/swell/cart/use-cart.tsx b/framework/swell/cart/use-cart.tsx index 04d07914d..354b4f947 100644 --- a/framework/swell/cart/use-cart.tsx +++ b/framework/swell/cart/use-cart.tsx @@ -15,7 +15,6 @@ export const handler: SWRHook = { const cart = await checkoutCreate(fetch) return cart ? normalizeCart(cart) : null - // return checkoutToCart({ checkout } as any) }, useHook: ({ useData }) => (input) => { return useData({ diff --git a/framework/swell/common/get-all-pages.ts b/framework/swell/common/get-all-pages.ts index 1088a472c..489af339c 100644 --- a/framework/swell/common/get-all-pages.ts +++ b/framework/swell/common/get-all-pages.ts @@ -1,6 +1,4 @@ import { getConfig, SwellConfig } from '../api' -import { PageEdge } from '../schema' -import { getAllPagesQuery } from '../utils/queries' type Variables = { first?: number diff --git a/framework/swell/const.ts b/framework/swell/const.ts index 7226b19cb..669194298 100644 --- a/framework/swell/const.ts +++ b/framework/swell/const.ts @@ -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 diff --git a/framework/swell/customer/get-customer-id.ts b/framework/swell/customer/get-customer-id.ts deleted file mode 100644 index c3a1b8d2f..000000000 --- a/framework/swell/customer/get-customer-id.ts +++ /dev/null @@ -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 { - config = getConfig(config) - - const { data } = await config.fetch(getCustomerIdQuery, { - variables: { - customerAccesToken: - customerAccesToken || Cookies.get(config.customerCookie), - }, - }) - - return data.customer?.id -} - -export default getCustomerId diff --git a/framework/swell/customer/use-customer.tsx b/framework/swell/customer/use-customer.tsx index 7b84795aa..632065d5a 100644 --- a/framework/swell/customer/use-customer.tsx +++ b/framework/swell/customer/use-customer.tsx @@ -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 diff --git a/framework/swell/fetcher.ts b/framework/swell/fetcher.ts index 4c65b91d2..e52d8fd54 100644 --- a/framework/swell/fetcher.ts +++ b/framework/swell/fetcher.ts @@ -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) } diff --git a/framework/swell/index.tsx b/framework/swell/index.tsx index db8cd3e1f..28f60b394 100644 --- a/framework/swell/index.tsx +++ b/framework/swell/index.tsx @@ -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, } diff --git a/framework/swell/product/get-all-collections.ts b/framework/swell/product/get-all-collections.ts index b3832316c..e6da3ade4 100644 --- a/framework/swell/product/get-all-collections.ts +++ b/framework/swell/product/get-all-collections.ts @@ -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) => ({ diff --git a/framework/swell/product/get-all-product-paths.ts b/framework/swell/product/get-all-product-paths.ts index 4f3dec29a..fad11f8c2 100644 --- a/framework/swell/product/get-all-product-paths.ts +++ b/framework/swell/product/get-all-product-paths.ts @@ -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 => { - 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}`, }, diff --git a/framework/swell/product/get-all-products.ts b/framework/swell/product/get-all-products.ts index 1f4f4152c..dff5bf067 100644 --- a/framework/swell/product/get-all-products.ts +++ b/framework/swell/product/get-all-products.ts @@ -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' diff --git a/framework/swell/product/get-product.ts b/framework/swell/product/get-product.ts index 49bc5b67f..1923fc75a 100644 --- a/framework/swell/product/get-product.ts +++ b/framework/swell/product/get-product.ts @@ -22,7 +22,6 @@ const getProduct = async (options: { if (product.variants) { product.variants = product.variants?.results } - // console.log('product', product) return { product: normalizeProduct(product), } diff --git a/framework/swell/product/use-search.tsx b/framework/swell/product/use-search.tsx index 14b966319..b93a5598f 100644 --- a/framework/swell/product/use-search.tsx +++ b/framework/swell/product/use-search.tsx @@ -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) => { diff --git a/framework/swell/types.ts b/framework/swell/types.ts index a4ce4afa8..248ea3158 100644 --- a/framework/swell/types.ts +++ b/framework/swell/types.ts @@ -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[] diff --git a/framework/swell/utils/customer-token.ts b/framework/swell/utils/customer-token.ts index 85454cb83..63bd51bc0 100644 --- a/framework/swell/utils/customer-token.ts +++ b/framework/swell/utils/customer-token.ts @@ -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, } ) } diff --git a/framework/swell/utils/get-checkout-id.ts b/framework/swell/utils/get-checkout-id.ts index 11e3802d9..07643f475 100644 --- a/framework/swell/utils/get-checkout-id.ts +++ b/framework/swell/utils/get-checkout-id.ts @@ -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 diff --git a/framework/swell/utils/get-vendors.ts b/framework/swell/utils/get-vendors.ts index d80854f6d..a96d9dccd 100644 --- a/framework/swell/utils/get-vendors.ts +++ b/framework/swell/utils/get-vendors.ts @@ -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: { diff --git a/framework/swell/utils/handle-fetch-response.ts b/framework/swell/utils/handle-fetch-response.ts index 79aba8bd3..96ceb2469 100644 --- a/framework/swell/utils/handle-fetch-response.ts +++ b/framework/swell/utils/handle-fetch-response.ts @@ -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 }) } diff --git a/framework/swell/utils/index.ts b/framework/swell/utils/index.ts index 2d59aa506..9ec81bfb8 100644 --- a/framework/swell/utils/index.ts +++ b/framework/swell/utils/index.ts @@ -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' diff --git a/framework/swell/utils/mutations/associate-customer-with-checkout.ts b/framework/swell/utils/mutations/associate-customer-with-checkout.ts deleted file mode 100644 index 6b1350e05..000000000 --- a/framework/swell/utils/mutations/associate-customer-with-checkout.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/mutations/checkout-create.ts b/framework/swell/utils/mutations/checkout-create.ts deleted file mode 100644 index 912e1cbd2..000000000 --- a/framework/swell/utils/mutations/checkout-create.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/mutations/checkout-line-item-add.ts b/framework/swell/utils/mutations/checkout-line-item-add.ts deleted file mode 100644 index 67b9cf250..000000000 --- a/framework/swell/utils/mutations/checkout-line-item-add.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/mutations/checkout-line-item-remove.ts b/framework/swell/utils/mutations/checkout-line-item-remove.ts deleted file mode 100644 index d967a5168..000000000 --- a/framework/swell/utils/mutations/checkout-line-item-remove.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/mutations/checkout-line-item-update.ts b/framework/swell/utils/mutations/checkout-line-item-update.ts deleted file mode 100644 index 8edf17587..000000000 --- a/framework/swell/utils/mutations/checkout-line-item-update.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/mutations/customer-access-token-create.ts b/framework/swell/utils/mutations/customer-access-token-create.ts deleted file mode 100644 index 7a45c3f49..000000000 --- a/framework/swell/utils/mutations/customer-access-token-create.ts +++ /dev/null @@ -1,16 +0,0 @@ -const customerAccessTokenCreateMutation = /* GraphQL */ ` - mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) { - customerAccessTokenCreate(input: $input) { - customerAccessToken { - accessToken - expiresAt - } - customerUserErrors { - code - field - message - } - } - } -` -export default customerAccessTokenCreateMutation diff --git a/framework/swell/utils/mutations/customer-access-token-delete.ts b/framework/swell/utils/mutations/customer-access-token-delete.ts deleted file mode 100644 index c46eff1e5..000000000 --- a/framework/swell/utils/mutations/customer-access-token-delete.ts +++ /dev/null @@ -1,14 +0,0 @@ -const customerAccessTokenDeleteMutation = /* GraphQL */ ` - mutation customerAccessTokenDelete($customerAccessToken: String!) { - customerAccessTokenDelete(customerAccessToken: $customerAccessToken) { - deletedAccessToken - deletedCustomerAccessTokenId - userErrors { - field - message - } - } - } -` - -export default customerAccessTokenDeleteMutation diff --git a/framework/swell/utils/mutations/customer-create.ts b/framework/swell/utils/mutations/customer-create.ts deleted file mode 100644 index 05c728a25..000000000 --- a/framework/swell/utils/mutations/customer-create.ts +++ /dev/null @@ -1,15 +0,0 @@ -const customerCreateMutation = /* GraphQL */ ` - mutation customerCreate($input: CustomerCreateInput!) { - customerCreate(input: $input) { - customerUserErrors { - code - field - message - } - customer { - id - } - } - } -` -export default customerCreateMutation diff --git a/framework/swell/utils/mutations/index.ts b/framework/swell/utils/mutations/index.ts deleted file mode 100644 index 3a16d7cec..000000000 --- a/framework/swell/utils/mutations/index.ts +++ /dev/null @@ -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' diff --git a/framework/swell/utils/normalize.ts b/framework/swell/utils/normalize.ts index 63b63feb0..9f69f702e 100644 --- a/framework/swell/utils/normalize.ts +++ b/framework/swell/utils/normalize.ts @@ -36,7 +36,7 @@ type normalizedProductOption = { const normalizeProductOption = ({ id, name: displayName = '', - values, + values = [], }: ProductOption) => { let returnValues = values.map((value) => { let output: any = { diff --git a/framework/swell/utils/queries/get-all-collections-query.ts b/framework/swell/utils/queries/get-all-collections-query.ts deleted file mode 100644 index 2abf374d6..000000000 --- a/framework/swell/utils/queries/get-all-collections-query.ts +++ /dev/null @@ -1,14 +0,0 @@ -const getSiteCollectionsQuery = /* GraphQL */ ` - query getSiteCollections($first: Int!) { - collections(first: $first) { - edges { - node { - id - title - handle - } - } - } - } -` -export default getSiteCollectionsQuery diff --git a/framework/swell/utils/queries/get-all-pages-query.ts b/framework/swell/utils/queries/get-all-pages-query.ts deleted file mode 100644 index e3aee1f10..000000000 --- a/framework/swell/utils/queries/get-all-pages-query.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const getAllPagesQuery = /* GraphQL */ ` - query getAllPages($first: Int = 250) { - pages(first: $first) { - edges { - node { - id - title - handle - } - } - } - } -` -export default getAllPagesQuery diff --git a/framework/swell/utils/queries/get-all-product-vendors-query.ts b/framework/swell/utils/queries/get-all-product-vendors-query.ts deleted file mode 100644 index be08b8ec6..000000000 --- a/framework/swell/utils/queries/get-all-product-vendors-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/get-all-products-paths-query.ts b/framework/swell/utils/queries/get-all-products-paths-query.ts deleted file mode 100644 index 56298c204..000000000 --- a/framework/swell/utils/queries/get-all-products-paths-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/get-all-products-query.ts b/framework/swell/utils/queries/get-all-products-query.ts deleted file mode 100644 index 5eb44c7a7..000000000 --- a/framework/swell/utils/queries/get-all-products-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/get-checkout-query.ts b/framework/swell/utils/queries/get-checkout-query.ts deleted file mode 100644 index 194e1619a..000000000 --- a/framework/swell/utils/queries/get-checkout-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/get-collection-products-query.ts b/framework/swell/utils/queries/get-collection-products-query.ts deleted file mode 100644 index 04766caa4..000000000 --- a/framework/swell/utils/queries/get-collection-products-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/get-customer-id-query.ts b/framework/swell/utils/queries/get-customer-id-query.ts deleted file mode 100644 index 076ceb10b..000000000 --- a/framework/swell/utils/queries/get-customer-id-query.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const getCustomerQuery = /* GraphQL */ ` - query getCustomerId($customerAccessToken: String!) { - customer(customerAccessToken: $customerAccessToken) { - id - } - } -` -export default getCustomerQuery diff --git a/framework/swell/utils/queries/get-customer-query.ts b/framework/swell/utils/queries/get-customer-query.ts deleted file mode 100644 index 87e37e68d..000000000 --- a/framework/swell/utils/queries/get-customer-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/get-page-query.ts b/framework/swell/utils/queries/get-page-query.ts deleted file mode 100644 index 2ca79abd4..000000000 --- a/framework/swell/utils/queries/get-page-query.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const getPageQuery = /* GraphQL */ ` - query($id: ID!) { - node(id: $id) { - id - ... on Page { - title - handle - body - bodySummary - } - } - } -` -export default getPageQuery diff --git a/framework/swell/utils/queries/get-product-query.ts b/framework/swell/utils/queries/get-product-query.ts deleted file mode 100644 index 5c109901b..000000000 --- a/framework/swell/utils/queries/get-product-query.ts +++ /dev/null @@ -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 diff --git a/framework/swell/utils/queries/index.ts b/framework/swell/utils/queries/index.ts deleted file mode 100644 index e19be9c8c..000000000 --- a/framework/swell/utils/queries/index.ts +++ /dev/null @@ -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' diff --git a/framework/swell/wishlist/use-wishlist.tsx b/framework/swell/wishlist/use-wishlist.tsx index d2ce9db5b..cd1bfa0ad 100644 --- a/framework/swell/wishlist/use-wishlist.tsx +++ b/framework/swell/wishlist/use-wishlist.tsx @@ -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'