feat: changes for woocommerce (WIP)

This commit is contained in:
Reza Babaei
2021-09-04 16:32:16 +03:00
committed by Reza Babaei
parent 2a904b7bb4
commit 28c1c04964
24 changed files with 590 additions and 18270 deletions

View File

@@ -18,7 +18,7 @@ import LoginView from '@components/auth/LoginView'
import s from './Layout.module.css' import s from './Layout.module.css'
const Loading = () => ( const Loading = () => (
<div className="w-80 h-80 flex items-center text-center justify-center p-3"> <div className="flex items-center justify-center p-3 text-center w-80 h-80">
<LoadingDots /> <LoadingDots />
</div> </div>
) )
@@ -104,7 +104,7 @@ const Layout: FC<Props> = ({
return ( return (
<CommerceProvider locale={locale}> <CommerceProvider locale={locale}>
<div className={cn(s.root)}> <div className={cn(s.root)}>
<Navbar links={navBarlinks} /> {/* <Navbar links={navBarlinks} /> */}
<main className="fit">{children}</main> <main className="fit">{children}</main>
<Footer pages={pageProps.pages} /> <Footer pages={pageProps.pages} />
<ModalUI /> <ModalUI />

View File

@@ -18,19 +18,24 @@ interface Props {
const countItem = (count: number, item: LineItem) => count + item.quantity const countItem = (count: number, item: LineItem) => count + item.quantity
const UserNav: FC<Props> = ({ className }) => { const UserNav: FC<Props> = ({ className }) => {
const { data } = useCart() // const { data } = useCart()
const { data: customer } = useCustomer() const { data: customer } = useCustomer()
const { toggleSidebar, closeSidebarIfPresent, openModal } = useUI() const { toggleSidebar, closeSidebarIfPresent, openModal } = useUI()
const itemsCount = data?.lineItems.reduce(countItem, 0) ?? 0 // const itemsCount = data?.lineItems.reduce(countItem, 0) ?? 0
return ( return (
<nav className={cn(s.root, className)}> <nav className={cn(s.root, className)}>
<ul className={s.list}> <ul className={s.list}>
{process.env.COMMERCE_CART_ENABLED && ( {process.env.COMMERCE_CART_ENABLED && (
<li className={s.item}> <li className={s.item}>
<Button className={s.item} variant="naked" onClick={toggleSidebar} aria-label="Cart"> <Button
className={s.item}
variant="naked"
onClick={toggleSidebar}
aria-label="Cart"
>
<Bag /> <Bag />
{itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>} {/* {itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>} */}
</Button> </Button>
</li> </li>
)} )}

View File

@@ -6,9 +6,8 @@ import {
import { import {
API_URL, API_URL,
API_TOKEN, WOOCOMMERCE_CUSTOMER_TOKEN_COOKIE,
SHOPIFY_CUSTOMER_TOKEN_COOKIE, WOOCOMMERCE_CHECKOUT_ID_COOKIE,
SHOPIFY_CHECKOUT_ID_COOKIE,
} from '../const' } from '../const'
import fetchGraphqlApi from './utils/fetch-graphql-api' import fetchGraphqlApi from './utils/fetch-graphql-api'
@@ -17,24 +16,20 @@ import * as operations from './operations'
if (!API_URL) { if (!API_URL) {
throw new Error( throw new Error(
`The environment variable NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN is missing and it's required to access your store` `The environment variable NEXT_PUBLIC_WOOCOMMERCE_STORE_DOMAIN is missing and it's required to access your store`
) )
} }
if (!API_TOKEN) { export interface WooCommerceConfig extends CommerceAPIConfig {}
throw new Error(
`The environment variable NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN is missing and it's required to access your store`
)
}
export interface ShopifyConfig extends CommerceAPIConfig {}
const ONE_DAY = 60 * 60 * 24 const ONE_DAY = 60 * 60 * 24
const config: ShopifyConfig = { //TODO we don't have a apiToken here
const config: WooCommerceConfig = {
commerceUrl: API_URL, commerceUrl: API_URL,
apiToken: API_TOKEN, apiToken: '',
customerCookie: SHOPIFY_CUSTOMER_TOKEN_COOKIE, customerCookie: WOOCOMMERCE_CUSTOMER_TOKEN_COOKIE,
cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE, cartCookie: WOOCOMMERCE_CHECKOUT_ID_COOKIE,
cartCookieMaxAge: ONE_DAY * 30, cartCookieMaxAge: ONE_DAY * 30,
fetch: fetchGraphqlApi, fetch: fetchGraphqlApi,
} }
@@ -46,10 +41,10 @@ export const provider = {
export type Provider = typeof provider export type Provider = typeof provider
export type ShopifyAPI<P extends Provider = Provider> = CommerceAPI<P> export type WOOCOMMERCEAPI<P extends Provider = Provider> = CommerceAPI<P>
export function getCommerceApi<P extends Provider>( export function getCommerceApi<P extends Provider>(
customProvider: P = provider as any customProvider: P = provider as any
): ShopifyAPI<P> { ): WOOCOMMERCEAPI<P> {
return commerceApi(customProvider) return commerceApi(customProvider)
} }

View File

@@ -6,9 +6,9 @@ import { GetAllProductsOperation } from '../../types/product'
import { import {
GetAllProductsQuery, GetAllProductsQuery,
GetAllProductsQueryVariables, GetAllProductsQueryVariables,
Product as ShopifyProduct, Product as WooCommerceProduct,
} from '../../schema' } from '../../schema'
import type { ShopifyConfig, Provider } from '..' import type { WooCommerceConfig, Provider } from '..'
import getAllProductsQuery from '../../utils/queries/get-all-products-query' import getAllProductsQuery from '../../utils/queries/get-all-products-query'
import { normalizeProduct } from '../../utils' import { normalizeProduct } from '../../utils'
@@ -17,14 +17,14 @@ export default function getAllProductsOperation({
}: OperationContext<Provider>) { }: OperationContext<Provider>) {
async function getAllProducts<T extends GetAllProductsOperation>(opts?: { async function getAllProducts<T extends GetAllProductsOperation>(opts?: {
variables?: T['variables'] variables?: T['variables']
config?: Partial<ShopifyConfig> config?: Partial<WooCommerceConfig>
preview?: boolean preview?: boolean
}): Promise<T['data']> }): Promise<T['data']>
async function getAllProducts<T extends GetAllProductsOperation>( async function getAllProducts<T extends GetAllProductsOperation>(
opts: { opts: {
variables?: T['variables'] variables?: T['variables']
config?: Partial<ShopifyConfig> config?: Partial<WooCommerceConfig>
preview?: boolean preview?: boolean
} & OperationOptions } & OperationOptions
): Promise<T['data']> ): Promise<T['data']>
@@ -36,7 +36,7 @@ export default function getAllProductsOperation({
}: { }: {
query?: string query?: string
variables?: T['variables'] variables?: T['variables']
config?: Partial<ShopifyConfig> config?: Partial<WooCommerceConfig>
preview?: boolean preview?: boolean
} = {}): Promise<T['data']> { } = {}): Promise<T['data']> {
const { fetch, locale } = commerce.getConfig(config) const { fetch, locale } = commerce.getConfig(config)
@@ -58,7 +58,7 @@ export default function getAllProductsOperation({
return { return {
products: data.products.edges.map(({ node }) => products: data.products.edges.map(({ node }) =>
normalizeProduct(node as ShopifyProduct) normalizeProduct(node as WooCommerceProduct)
), ),
} }
} }

View File

@@ -3,7 +3,7 @@ import type {
OperationOptions, OperationOptions,
} from '@commerce/api/operations' } from '@commerce/api/operations'
import { GetSiteInfoQueryVariables } from '../../schema' import { GetSiteInfoQueryVariables } from '../../schema'
import type { ShopifyConfig, Provider } from '..' import type { WooCommerceConfig, Provider } from '..'
import { GetSiteInfoOperation } from '../../types/site' import { GetSiteInfoOperation } from '../../types/site'
import { getCategories, getBrands, getSiteInfoQuery } from '../../utils' import { getCategories, getBrands, getSiteInfoQuery } from '../../utils'
@@ -12,13 +12,13 @@ export default function getSiteInfoOperation({
commerce, commerce,
}: OperationContext<Provider>) { }: OperationContext<Provider>) {
async function getSiteInfo<T extends GetSiteInfoOperation>(opts?: { async function getSiteInfo<T extends GetSiteInfoOperation>(opts?: {
config?: Partial<ShopifyConfig> config?: Partial<WooCommerceConfig>
preview?: boolean preview?: boolean
}): Promise<T['data']> }): Promise<T['data']>
async function getSiteInfo<T extends GetSiteInfoOperation>( async function getSiteInfo<T extends GetSiteInfoOperation>(
opts: { opts: {
config?: Partial<ShopifyConfig> config?: Partial<WooCommerceConfig>
preview?: boolean preview?: boolean
} & OperationOptions } & OperationOptions
): Promise<T['data']> ): Promise<T['data']>
@@ -29,14 +29,14 @@ export default function getSiteInfoOperation({
variables, variables,
}: { }: {
query?: string query?: string
config?: Partial<ShopifyConfig> config?: Partial<WooCommerceConfig>
preview?: boolean preview?: boolean
variables?: GetSiteInfoQueryVariables variables?: GetSiteInfoQueryVariables
} = {}): Promise<T['data']> { } = {}): Promise<T['data']> {
const cfg = commerce.getConfig(config) const cfg = commerce.getConfig(config)
console.log(cfg)
const categoriesPromise = getCategories(cfg) // const categoriesPromise = getCategories(cfg)
const brandsPromise = getBrands(cfg) // const brandsPromise = getBrands(cfg)
/* /*
const { fetch, locale } = cfg const { fetch, locale } = cfg
const { data } = await fetch<GetSiteInfoQuery, GetSiteInfoQueryVariables>( const { data } = await fetch<GetSiteInfoQuery, GetSiteInfoQueryVariables>(
@@ -53,8 +53,8 @@ export default function getSiteInfoOperation({
*/ */
return { return {
categories: await categoriesPromise, // categories: await categoriesPromise,
brands: await brandsPromise, // brands: await brandsPromise,
} }
} }

View File

@@ -1,7 +1,7 @@
export { default as getAllPages } from './get-all-pages' // export { default as getAllPages } from './get-all-pages'
export { default as getPage } from './get-page' // export { default as getPage } from './get-page'
export { default as getAllProducts } from './get-all-products' export { default as getAllProducts } from './get-all-products'
export { default as getAllProductPaths } from './get-all-product-paths' // export { default as getAllProductPaths } from './get-all-product-paths'
export { default as getProduct } from './get-product' // export { default as getProduct } from './get-product'
export { default as getSiteInfo } from './get-site-info' export { default as getSiteInfo } from './get-site-info'
export { default as login } from './login' // export { default as login } from './login'

View File

@@ -1,7 +1,7 @@
import type { GraphQLFetcher } from '@commerce/api' import type { GraphQLFetcher } from '@commerce/api'
import fetch from './fetch' import fetch from './fetch'
import { API_URL, API_TOKEN } from '../../const' import { API_URL } from '../../const'
import { getError } from '../../utils/handle-fetch-response' import { getError } from '../../utils/handle-fetch-response'
const fetchGraphqlApi: GraphQLFetcher = async ( const fetchGraphqlApi: GraphQLFetcher = async (
@@ -14,7 +14,6 @@ const fetchGraphqlApi: GraphQLFetcher = async (
...fetchOptions, ...fetchOptions,
method: 'POST', method: 'POST',
headers: { headers: {
'X-Shopify-Storefront-Access-Token': API_TOKEN!,
...fetchOptions?.headers, ...fetchOptions?.headers,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },

View File

@@ -37,21 +37,23 @@ export const handler: SWRHook<GetCartHook> = {
return checkoutToCart({ checkout }) return checkoutToCart({ checkout })
}, },
useHook: ({ useData }) => (input) => { useHook:
const response = useData({ ({ useData }) =>
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, (input) => {
}) const response = useData({
return useMemo( swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
() => })
Object.create(response, { return useMemo(
isEmpty: { () =>
get() { Object.create(response, {
return (response.data?.lineItems.length ?? 0) <= 0 isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
},
enumerable: true,
}, },
enumerable: true, }),
}, [response]
}), )
[response] },
)
},
} }

View File

@@ -21,12 +21,14 @@ export const handler: SWRHook<CustomerHook> = {
} }
return null return null
}, },
useHook: ({ useData }) => (input) => { useHook:
return useData({ ({ useData }) =>
swrOptions: { (input) => {
revalidateOnFocus: false, return useData({
...input?.swrOptions, swrOptions: {
}, revalidateOnFocus: false,
}) ...input?.swrOptions,
}, },
})
},
} }

View File

@@ -1,10 +1,16 @@
import { WOOCOMMERCE_CHECKOUT_ID_COOKIE } from './const' import { WOOCOMMERCE_CHECKOUT_ID_COOKIE } from './const'
import { handler as useCart } from './cart/use-cart'
import { handler as useAddItem } from './cart/use-add-item'
import { handler as useUpdateItem } from './cart/use-update-item'
import { handler as useRemoveItem } from './cart/use-remove-item'
import fetcher from './fetcher' import fetcher from './fetcher'
export const wooCommerceProvider = { export const wooCommerceProvider = {
locale: 'en-us', locale: 'en-us',
fetcher, fetcher,
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
cartCookie: WOOCOMMERCE_CHECKOUT_ID_COOKIE, cartCookie: WOOCOMMERCE_CHECKOUT_ID_COOKIE,
} }

View File

@@ -2775,8 +2775,12 @@ export type CreateUserInput = {
nickname?: Maybe<Scalars['String']> nickname?: Maybe<Scalars['String']>
/** A string that contains the plain text password for the user. */ /** A string that contains the plain text password for the user. */
password?: Maybe<Scalars['String']> password?: Maybe<Scalars['String']>
/** If true, this will refresh the users JWT secret. */
refreshJwtUserSecret?: Maybe<Scalars['Boolean']>
/** The date the user registered. Format is Y-m-d H:i:s. */ /** The date the user registered. Format is Y-m-d H:i:s. */
registered?: Maybe<Scalars['String']> registered?: Maybe<Scalars['String']>
/** If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets. */
revokeJwtUserSecret?: Maybe<Scalars['Boolean']>
/** A string for whether to enable the rich editor or not. False if not empty. */ /** A string for whether to enable the rich editor or not. False if not empty. */
richEditing?: Maybe<Scalars['String']> richEditing?: Maybe<Scalars['String']>
/** An array of roles to be assigned to the user. */ /** An array of roles to be assigned to the user. */
@@ -2844,10 +2848,20 @@ export type Customer = Node & {
hasCalculatedShipping?: Maybe<Scalars['Boolean']> hasCalculatedShipping?: Maybe<Scalars['Boolean']>
/** The globally unique identifier for the customer */ /** The globally unique identifier for the customer */
id: Scalars['ID'] id: Scalars['ID']
/** Whether the JWT User secret has been revoked. If the secret has been revoked, auth tokens will not be issued until an admin, or user with proper capabilities re-issues a secret for the user. */
isJwtAuthSecretRevoked: Scalars['Boolean']
/** Return the date customer was last updated */ /** Return the date customer was last updated */
isPayingCustomer?: Maybe<Scalars['Boolean']> isPayingCustomer?: Maybe<Scalars['Boolean']>
/** Is customer VAT exempt? */ /** Is customer VAT exempt? */
isVatExempt?: Maybe<Scalars['Boolean']> isVatExempt?: Maybe<Scalars['Boolean']>
/** The expiration for the JWT Token for the user. If not set custom for the user, it will use the default sitewide expiration setting */
jwtAuthExpiration?: Maybe<Scalars['String']>
/** A JWT token that can be used in future requests for authentication/authorization */
jwtAuthToken?: Maybe<Scalars['String']>
/** A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers. */
jwtRefreshToken?: Maybe<Scalars['String']>
/** A unique secret tied to the users JWT token that can be revoked or refreshed. Revoking the secret prevents JWT tokens from being issued to the user. Refreshing the token invalidates previously issued tokens, but allows new tokens to be issued. */
jwtUserSecret?: Maybe<Scalars['String']>
/** Return the customer&#039;s last name. */ /** Return the customer&#039;s last name. */
lastName?: Maybe<Scalars['String']> lastName?: Maybe<Scalars['String']>
/** Gets the customers last order. */ /** Gets the customers last order. */
@@ -4916,6 +4930,33 @@ export type LocalProductAttribute = ProductAttribute & {
visible: Scalars['Boolean'] visible: Scalars['Boolean']
} }
/** Input for the login mutation */
export type LoginInput = {
/** This is an ID that can be passed to a mutation by the client to track the progress of mutations and catch possible duplicate mutation submissions. */
clientMutationId?: Maybe<Scalars['String']>
/** The plain-text password for the user logging in. */
password: Scalars['String']
/** The username used for login. Typically a unique or email address depending on specific configuration */
username: Scalars['String']
}
/** The payload for the login mutation */
export type LoginPayload = {
__typename?: 'LoginPayload'
/** JWT Token that can be used in future requests for Authentication */
authToken?: Maybe<Scalars['String']>
/** If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. */
clientMutationId?: Maybe<Scalars['String']>
/** Customer object of authenticated user. */
customer?: Maybe<Customer>
/** A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers. */
refreshToken?: Maybe<Scalars['String']>
/** A JWT token that can be used in future requests to for WooCommerce session identification */
sessionToken?: Maybe<Scalars['String']>
/** The user that was logged in */
user?: Maybe<User>
}
/** Product manage stock enumeration */ /** Product manage stock enumeration */
export enum ManageStockEnum { export enum ManageStockEnum {
False = 'FALSE', False = 'FALSE',
@@ -11200,6 +11241,23 @@ export type ReadingSettings = {
postsPerPage?: Maybe<Scalars['Int']> postsPerPage?: Maybe<Scalars['Int']>
} }
/** Input for the refreshJwtAuthToken mutation */
export type RefreshJwtAuthTokenInput = {
/** This is an ID that can be passed to a mutation by the client to track the progress of mutations and catch possible duplicate mutation submissions. */
clientMutationId?: Maybe<Scalars['String']>
/** A valid, previously issued JWT refresh token. If valid a new Auth token will be provided. If invalid, expired, revoked or otherwise invalid, a new AuthToken will not be provided. */
jwtRefreshToken: Scalars['String']
}
/** The payload for the refreshJwtAuthToken mutation */
export type RefreshJwtAuthTokenPayload = {
__typename?: 'RefreshJwtAuthTokenPayload'
/** JWT Token that can be used in future requests for Authentication */
authToken?: Maybe<Scalars['String']>
/** If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. */
clientMutationId?: Maybe<Scalars['String']>
}
/** A refund object */ /** A refund object */
export type Refund = Node & { export type Refund = Node & {
__typename?: 'Refund' __typename?: 'Refund'
@@ -11315,9 +11373,13 @@ export type RegisterCustomerInput = {
/** The payload for the registerCustomer mutation */ /** The payload for the registerCustomer mutation */
export type RegisterCustomerPayload = { export type RegisterCustomerPayload = {
__typename?: 'RegisterCustomerPayload' __typename?: 'RegisterCustomerPayload'
/** JWT Token that can be used in future requests for Authentication */
authToken?: Maybe<Scalars['String']>
/** If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. */ /** If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. */
clientMutationId?: Maybe<Scalars['String']> clientMutationId?: Maybe<Scalars['String']>
customer?: Maybe<Customer> customer?: Maybe<Customer>
/** A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers. */
refreshToken?: Maybe<Scalars['String']>
viewer?: Maybe<User> viewer?: Maybe<User>
} }
@@ -11347,8 +11409,12 @@ export type RegisterUserInput = {
nickname?: Maybe<Scalars['String']> nickname?: Maybe<Scalars['String']>
/** A string that contains the plain text password for the user. */ /** A string that contains the plain text password for the user. */
password?: Maybe<Scalars['String']> password?: Maybe<Scalars['String']>
/** If true, this will refresh the users JWT secret. */
refreshJwtUserSecret?: Maybe<Scalars['Boolean']>
/** The date the user registered. Format is Y-m-d H:i:s. */ /** The date the user registered. Format is Y-m-d H:i:s. */
registered?: Maybe<Scalars['String']> registered?: Maybe<Scalars['String']>
/** If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets. */
revokeJwtUserSecret?: Maybe<Scalars['Boolean']>
/** A string for whether to enable the rich editor or not. False if not empty. */ /** A string for whether to enable the rich editor or not. False if not empty. */
richEditing?: Maybe<Scalars['String']> richEditing?: Maybe<Scalars['String']>
/** A string that contains the user's username. */ /** A string that contains the user's username. */
@@ -11580,6 +11646,10 @@ export type RootMutation = {
fillCart?: Maybe<FillCartPayload> fillCart?: Maybe<FillCartPayload>
/** Increase the count. */ /** Increase the count. */
increaseCount?: Maybe<Scalars['Int']> increaseCount?: Maybe<Scalars['Int']>
/** The payload for the login mutation */
login?: Maybe<LoginPayload>
/** The payload for the refreshJwtAuthToken mutation */
refreshJwtAuthToken?: Maybe<RefreshJwtAuthTokenPayload>
/** The payload for the registerCustomer mutation */ /** The payload for the registerCustomer mutation */
registerCustomer?: Maybe<RegisterCustomerPayload> registerCustomer?: Maybe<RegisterCustomerPayload>
/** The payload for the registerUser mutation */ /** The payload for the registerUser mutation */
@@ -11866,6 +11936,16 @@ export type RootMutationIncreaseCountArgs = {
count?: Maybe<Scalars['Int']> count?: Maybe<Scalars['Int']>
} }
/** The root mutation */
export type RootMutationLoginArgs = {
input: LoginInput
}
/** The root mutation */
export type RootMutationRefreshJwtAuthTokenArgs = {
input: RefreshJwtAuthTokenInput
}
/** The root mutation */ /** The root mutation */
export type RootMutationRegisterCustomerArgs = { export type RootMutationRegisterCustomerArgs = {
input: RegisterCustomerInput input: RegisterCustomerInput
@@ -16095,9 +16175,13 @@ export type UpdateCustomerInput = {
/** The payload for the updateCustomer mutation */ /** The payload for the updateCustomer mutation */
export type UpdateCustomerPayload = { export type UpdateCustomerPayload = {
__typename?: 'UpdateCustomerPayload' __typename?: 'UpdateCustomerPayload'
/** JWT Token that can be used in future requests for Authentication */
authToken?: Maybe<Scalars['String']>
/** If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. */ /** If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. */
clientMutationId?: Maybe<Scalars['String']> clientMutationId?: Maybe<Scalars['String']>
customer?: Maybe<Customer> customer?: Maybe<Customer>
/** A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers. */
refreshToken?: Maybe<Scalars['String']>
} }
/** Input for the updateItemQuantities mutation */ /** Input for the updateItemQuantities mutation */
@@ -16635,8 +16719,12 @@ export type UpdateUserInput = {
nickname?: Maybe<Scalars['String']> nickname?: Maybe<Scalars['String']>
/** A string that contains the plain text password for the user. */ /** A string that contains the plain text password for the user. */
password?: Maybe<Scalars['String']> password?: Maybe<Scalars['String']>
/** If true, this will refresh the users JWT secret. */
refreshJwtUserSecret?: Maybe<Scalars['Boolean']>
/** The date the user registered. Format is Y-m-d H:i:s. */ /** The date the user registered. Format is Y-m-d H:i:s. */
registered?: Maybe<Scalars['String']> registered?: Maybe<Scalars['String']>
/** If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets. */
revokeJwtUserSecret?: Maybe<Scalars['Boolean']>
/** A string for whether to enable the rich editor or not. False if not empty. */ /** A string for whether to enable the rich editor or not. False if not empty. */
richEditing?: Maybe<Scalars['String']> richEditing?: Maybe<Scalars['String']>
/** An array of roles to be assigned to the user. */ /** An array of roles to be assigned to the user. */
@@ -16713,10 +16801,20 @@ export type User = Node &
id: Scalars['ID'] id: Scalars['ID']
/** Whether the node is a Content Node */ /** Whether the node is a Content Node */
isContentNode: Scalars['Boolean'] isContentNode: Scalars['Boolean']
/** Whether the JWT User secret has been revoked. If the secret has been revoked, auth tokens will not be issued until an admin, or user with proper capabilities re-issues a secret for the user. */
isJwtAuthSecretRevoked: Scalars['Boolean']
/** Whether the object is restricted from the current viewer */ /** Whether the object is restricted from the current viewer */
isRestricted?: Maybe<Scalars['Boolean']> isRestricted?: Maybe<Scalars['Boolean']>
/** Whether the node is a Term */ /** Whether the node is a Term */
isTermNode: Scalars['Boolean'] isTermNode: Scalars['Boolean']
/** The expiration for the JWT Token for the user. If not set custom for the user, it will use the default sitewide expiration setting */
jwtAuthExpiration?: Maybe<Scalars['String']>
/** A JWT token that can be used in future requests for authentication/authorization */
jwtAuthToken?: Maybe<Scalars['String']>
/** A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers. */
jwtRefreshToken?: Maybe<Scalars['String']>
/** A unique secret tied to the users JWT token that can be revoked or refreshed. Revoking the secret prevents JWT tokens from being issued to the user. Refreshing the token invalidates previously issued tokens, but allows new tokens to be issued. */
jwtUserSecret?: Maybe<Scalars['String']>
/** Last name of the user. This is equivalent to the WP_User-&gt;user_last_name property. */ /** Last name of the user. This is equivalent to the WP_User-&gt;user_last_name property. */
lastName?: Maybe<Scalars['String']> lastName?: Maybe<Scalars['String']>
/** The preferred language locale set for the user. Value derived from get_user_locale(). */ /** The preferred language locale set for the user. Value derived from get_user_locale(). */
@@ -18173,6 +18271,23 @@ export type WritingSettings = {
useSmilies?: Maybe<Scalars['Boolean']> useSmilies?: Maybe<Scalars['Boolean']>
} }
export type GetCustomerIdQueryVariables = Exact<{ [key: string]: never }>
export type GetCustomerIdQuery = { __typename?: 'RootQuery' } & {
customer?: Maybe<{ __typename?: 'Customer' } & Pick<Customer, 'id'>>
}
export type GetCustomerQueryVariables = Exact<{ [key: string]: never }>
export type GetCustomerQuery = { __typename?: 'RootQuery' } & {
customer?: Maybe<
{ __typename?: 'Customer' } & Pick<
Customer,
'id' | 'firstName' | 'lastName' | 'displayName' | 'email'
>
>
}
export type SettingQueryVariables = Exact<{ [key: string]: never }> export type SettingQueryVariables = Exact<{ [key: string]: never }>
export type SettingQuery = { __typename?: 'RootQuery' } & { export type SettingQuery = { __typename?: 'RootQuery' } & {

View File

@@ -5601,11 +5601,21 @@ input CreateUserInput {
""" """
password: String password: String
"""
If true, this will refresh the users JWT secret.
"""
refreshJwtUserSecret: Boolean
""" """
The date the user registered. Format is Y-m-d H:i:s. The date the user registered. Format is Y-m-d H:i:s.
""" """
registered: String registered: String
"""
If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets.
"""
revokeJwtUserSecret: Boolean
""" """
A string for whether to enable the rich editor or not. False if not empty. A string for whether to enable the rich editor or not. False if not empty.
""" """
@@ -5771,6 +5781,11 @@ type Customer implements Node {
""" """
id: ID! id: ID!
"""
Whether the JWT User secret has been revoked. If the secret has been revoked, auth tokens will not be issued until an admin, or user with proper capabilities re-issues a secret for the user.
"""
isJwtAuthSecretRevoked: Boolean!
""" """
Return the date customer was last updated Return the date customer was last updated
""" """
@@ -5781,6 +5796,26 @@ type Customer implements Node {
""" """
isVatExempt: Boolean isVatExempt: Boolean
"""
The expiration for the JWT Token for the user. If not set custom for the user, it will use the default sitewide expiration setting
"""
jwtAuthExpiration: String
"""
A JWT token that can be used in future requests for authentication/authorization
"""
jwtAuthToken: String
"""
A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.
"""
jwtRefreshToken: String
"""
A unique secret tied to the users JWT token that can be revoked or refreshed. Revoking the secret prevents JWT tokens from being issued to the user. Refreshing the token invalidates previously issued tokens, but allows new tokens to be issued.
"""
jwtUserSecret: String
""" """
Return the customer&#039;s last name. Return the customer&#039;s last name.
""" """
@@ -10272,6 +10307,61 @@ type LocalProductAttribute implements ProductAttribute {
visible: Boolean! visible: Boolean!
} }
"""
Input for the login mutation
"""
input LoginInput {
"""
This is an ID that can be passed to a mutation by the client to track the progress of mutations and catch possible duplicate mutation submissions.
"""
clientMutationId: String
"""
The plain-text password for the user logging in.
"""
password: String!
"""
The username used for login. Typically a unique or email address depending on specific configuration
"""
username: String!
}
"""
The payload for the login mutation
"""
type LoginPayload {
"""
JWT Token that can be used in future requests for Authentication
"""
authToken: String
"""
If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions.
"""
clientMutationId: String
"""
Customer object of authenticated user.
"""
customer: Customer
"""
A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.
"""
refreshToken: String
"""
A JWT token that can be used in future requests to for WooCommerce session identification
"""
sessionToken: String
"""
The user that was logged in
"""
user: User
}
""" """
Product manage stock enumeration Product manage stock enumeration
""" """
@@ -24021,6 +24111,36 @@ type ReadingSettings {
postsPerPage: Int postsPerPage: Int
} }
"""
Input for the refreshJwtAuthToken mutation
"""
input RefreshJwtAuthTokenInput {
"""
This is an ID that can be passed to a mutation by the client to track the progress of mutations and catch possible duplicate mutation submissions.
"""
clientMutationId: String
"""
A valid, previously issued JWT refresh token. If valid a new Auth token will be provided. If invalid, expired, revoked or otherwise invalid, a new AuthToken will not be provided.
"""
jwtRefreshToken: String!
}
"""
The payload for the refreshJwtAuthToken mutation
"""
type RefreshJwtAuthTokenPayload {
"""
JWT Token that can be used in future requests for Authentication
"""
authToken: String
"""
If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions.
"""
clientMutationId: String
}
""" """
A refund object A refund object
""" """
@@ -24270,11 +24390,21 @@ input RegisterCustomerInput {
The payload for the registerCustomer mutation The payload for the registerCustomer mutation
""" """
type RegisterCustomerPayload { type RegisterCustomerPayload {
"""
JWT Token that can be used in future requests for Authentication
"""
authToken: String
""" """
If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions.
""" """
clientMutationId: String clientMutationId: String
customer: Customer customer: Customer
"""
A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.
"""
refreshToken: String
viewer: User viewer: User
} }
@@ -24342,11 +24472,21 @@ input RegisterUserInput {
""" """
password: String password: String
"""
If true, this will refresh the users JWT secret.
"""
refreshJwtUserSecret: Boolean
""" """
The date the user registered. Format is Y-m-d H:i:s. The date the user registered. Format is Y-m-d H:i:s.
""" """
registered: String registered: String
"""
If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets.
"""
revokeJwtUserSecret: Boolean
""" """
A string for whether to enable the rich editor or not. False if not empty. A string for whether to enable the rich editor or not. False if not empty.
""" """
@@ -25045,6 +25185,26 @@ type RootMutation {
count: Int count: Int
): Int ): Int
"""
The payload for the login mutation
"""
login(
"""
Input for the login mutation
"""
input: LoginInput!
): LoginPayload
"""
The payload for the refreshJwtAuthToken mutation
"""
refreshJwtAuthToken(
"""
Input for the refreshJwtAuthToken mutation
"""
input: RefreshJwtAuthTokenInput!
): RefreshJwtAuthTokenPayload
""" """
The payload for the registerCustomer mutation The payload for the registerCustomer mutation
""" """
@@ -34240,11 +34400,21 @@ input UpdateCustomerInput {
The payload for the updateCustomer mutation The payload for the updateCustomer mutation
""" """
type UpdateCustomerPayload { type UpdateCustomerPayload {
"""
JWT Token that can be used in future requests for Authentication
"""
authToken: String
""" """
If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions. If a &#039;clientMutationId&#039; input is provided to the mutation, it will be returned as output on the mutation. This ID can be used by the client to track the progress of mutations and catch possible duplicate mutation submissions.
""" """
clientMutationId: String clientMutationId: String
customer: Customer customer: Customer
"""
A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.
"""
refreshToken: String
} }
""" """
@@ -35375,11 +35545,21 @@ input UpdateUserInput {
""" """
password: String password: String
"""
If true, this will refresh the users JWT secret.
"""
refreshJwtUserSecret: Boolean
""" """
The date the user registered. Format is Y-m-d H:i:s. The date the user registered. Format is Y-m-d H:i:s.
""" """
registered: String registered: String
"""
If true, this will revoke the users JWT secret. If false, this will unrevoke the JWT secret AND issue a new one. To revoke, the user must have proper capabilities to edit users JWT secrets.
"""
revokeJwtUserSecret: Boolean
""" """
A string for whether to enable the rich editor or not. False if not empty. A string for whether to enable the rich editor or not. False if not empty.
""" """
@@ -35615,6 +35795,11 @@ type User implements Node & UniformResourceIdentifiable & Commenter & DatabaseId
""" """
isContentNode: Boolean! isContentNode: Boolean!
"""
Whether the JWT User secret has been revoked. If the secret has been revoked, auth tokens will not be issued until an admin, or user with proper capabilities re-issues a secret for the user.
"""
isJwtAuthSecretRevoked: Boolean!
""" """
Whether the object is restricted from the current viewer Whether the object is restricted from the current viewer
""" """
@@ -35625,6 +35810,26 @@ type User implements Node & UniformResourceIdentifiable & Commenter & DatabaseId
""" """
isTermNode: Boolean! isTermNode: Boolean!
"""
The expiration for the JWT Token for the user. If not set custom for the user, it will use the default sitewide expiration setting
"""
jwtAuthExpiration: String
"""
A JWT token that can be used in future requests for authentication/authorization
"""
jwtAuthToken: String
"""
A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.
"""
jwtRefreshToken: String
"""
A unique secret tied to the users JWT token that can be revoked or refreshed. Revoking the secret prevents JWT tokens from being issued to the user. Refreshing the token invalidates previously issued tokens, but allows new tokens to be issued.
"""
jwtUserSecret: String
""" """
Last name of the user. This is equivalent to the WP_User-&gt;user_last_name property. Last name of the user. This is equivalent to the WP_User-&gt;user_last_name property.
""" """

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
export const getAllPagesQuery = /* GraphQL */ `
query getAllPages($first: Int = 250) {
pages(first: $first) {
edges {
node {
id
title
handle
}
}
}
}
`
export default getAllPagesQuery

View File

@@ -0,0 +1,34 @@
export const productConnectionFragment = /* GraphQL */ `
fragment productConnection on ProductConnection {
edges {
node {
id
name
image {
uri
altText
}
}
}
}
}
`
const getAllProductsQuery = /* GraphQL */ `
products(first: $first) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
node {
id
name
...productConnection
}
}
}
${productConnectionFragment}
`
export default getAllProductsQuery

View File

@@ -0,0 +1,8 @@
export const getCustomerQuery = /* GraphQL */ `
query getCustomerId {
customer {
id
}
}
`
export default getCustomerQuery

View File

@@ -0,0 +1,12 @@
export const getCustomerQuery = /* GraphQL */ `
query getCustomer {
customer {
id
firstName
lastName
displayName
email
}
}
`
export default getCustomerQuery

View File

@@ -0,0 +1,14 @@
export const getPageQuery = /* GraphQL */ `
query getPage($id: ID!) {
node(id: $id) {
id
... on Page {
title
handle
body
bodySummary
}
}
}
`
export default getPageQuery

View File

@@ -0,0 +1,12 @@
export const getPageQuery = /* GraphQL */ `
query allPosts {
posts {
nodes {
id
title
date
}
}
}
`
export default getPageQuery

View File

@@ -0,0 +1,72 @@
const getProductQuery = /* GraphQL */ `
query getProductBySlug($slug: String!) {
productByHandle(handle: $slug) {
id
handle
availableForSale
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
availableForSale
requiresShipping
selectedOptions {
name
value
}
priceV2 {
amount
currencyCode
}
compareAtPriceV2 {
amount
currencyCode
}
}
}
}
images(first: 250) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
node {
originalSrc
altText
width
height
}
}
}
}
}
`
export default getProductQuery

View File

@@ -3,4 +3,15 @@
// export { default as getAllPagesQuery } from './get-all-pages-query' // export { default as getAllPagesQuery } from './get-all-pages-query'
// export { default as getPostsQuery } from './get-posts-query' // export { default as getPostsQuery } from './get-posts-query'
// export { default as getPageQuery } from './get-page-query' // export { default as getPageQuery } from './get-page-query'
// 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'
export { default as getSiteInfoQuery } from './get-site-info-query' export { default as getSiteInfoQuery } from './get-site-info-query'

View File

@@ -11,7 +11,7 @@
"find:unused": "npx next-unused", "find:unused": "npx next-unused",
"generate": "graphql-codegen", "generate": "graphql-codegen",
"generate:shopify": "DOTENV_CONFIG_PATH=./.env.local graphql-codegen -r dotenv/config --config framework/shopify/codegen.json", "generate:shopify": "DOTENV_CONFIG_PATH=./.env.local graphql-codegen -r dotenv/config --config framework/shopify/codegen.json",
"generate:wpc": "DOTENV_CONFIG_PATH=./.env.local graphql-codegen -r dotenv/config --config framework/woocommerce/codegen.json", "generate:wpc": "NODE_TLS_REJECT_UNAUTHORIZED=0 DOTENV_CONFIG_PATH=./.env.local graphql-codegen -r dotenv/config --config framework/woocommerce/codegen.json",
"generate:vendure": "graphql-codegen --config framework/vendure/codegen.json", "generate:vendure": "graphql-codegen --config framework/vendure/codegen.json",
"generate:definitions": "node framework/bigcommerce/scripts/generate-definitions.js" "generate:definitions": "node framework/bigcommerce/scripts/generate-definitions.js"
}, },

View File

@@ -18,19 +18,19 @@ export async function getStaticProps({
// Saleor provider only // Saleor provider only
...({ featured: true } as any), ...({ featured: true } as any),
}) })
const pagesPromise = commerce.getAllPages({ config, preview }) // const pagesPromise = commerce.getAllPages({ config, preview })
const siteInfoPromise = commerce.getSiteInfo({ config, preview }) // const siteInfoPromise = commerce.getSiteInfo({ config, preview })
const { products } = await productsPromise // const { products } = await productsPromise
const { pages } = await pagesPromise // const { pages } = await pagesPromise
const { categories, brands } = await siteInfoPromise // const { categories, brands } = await siteInfoPromise
return { return {
props: { // props: {
products, // products,
categories, // categories,
brands, // brands,
pages, // pages,
}, // },
revalidate: 60, revalidate: 60,
} }
} }
@@ -40,7 +40,7 @@ export default function Home({
}: InferGetStaticPropsType<typeof getStaticProps>) { }: InferGetStaticPropsType<typeof getStaticProps>) {
return ( return (
<> <>
<Grid variant="filled"> {/* <Grid variant="filled">
{products.slice(0, 3).map((product: any, i: number) => ( {products.slice(0, 3).map((product: any, i: number) => (
<ProductCard <ProductCard
key={product.id} key={product.id}
@@ -77,7 +77,7 @@ export default function Home({
{products.slice(3).map((product: any, i: number) => ( {products.slice(3).map((product: any, i: number) => (
<ProductCard key={product.id} product={product} variant="slim" /> <ProductCard key={product.id} product={product} variant="slim" />
))} ))}
</Marquee> </Marquee> */}
{/* <HomeAllProductsGrid {/* <HomeAllProductsGrid
newestProducts={products} newestProducts={products}
categories={categories} categories={categories}

View File

@@ -23,8 +23,8 @@
"@components/*": ["components/*"], "@components/*": ["components/*"],
"@commerce": ["framework/commerce"], "@commerce": ["framework/commerce"],
"@commerce/*": ["framework/commerce/*"], "@commerce/*": ["framework/commerce/*"],
"@framework": ["framework/local"], "@framework": ["framework/woocommerce"],
"@framework/*": ["framework/local/*"] "@framework/*": ["framework/woocommerce/*"]
} }
}, },
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"], "include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],