feat: changes for woocommerce (WIP)

This commit is contained in:
Reza Babaei 2021-09-04 16:32:16 +03:00
parent 3c93eb980d
commit c71c3d1ae6
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'
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 />
</div>
)
@ -104,7 +104,7 @@ const Layout: FC<Props> = ({
return (
<CommerceProvider locale={locale}>
<div className={cn(s.root)}>
<Navbar links={navBarlinks} />
{/* <Navbar links={navBarlinks} /> */}
<main className="fit">{children}</main>
<Footer pages={pageProps.pages} />
<ModalUI />

View File

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

View File

@ -6,9 +6,8 @@ import {
import {
API_URL,
API_TOKEN,
SHOPIFY_CUSTOMER_TOKEN_COOKIE,
SHOPIFY_CHECKOUT_ID_COOKIE,
WOOCOMMERCE_CUSTOMER_TOKEN_COOKIE,
WOOCOMMERCE_CHECKOUT_ID_COOKIE,
} from '../const'
import fetchGraphqlApi from './utils/fetch-graphql-api'
@ -17,24 +16,20 @@ import * as operations from './operations'
if (!API_URL) {
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) {
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 {}
export interface WooCommerceConfig extends CommerceAPIConfig {}
const ONE_DAY = 60 * 60 * 24
const config: ShopifyConfig = {
//TODO we don't have a apiToken here
const config: WooCommerceConfig = {
commerceUrl: API_URL,
apiToken: API_TOKEN,
customerCookie: SHOPIFY_CUSTOMER_TOKEN_COOKIE,
cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE,
apiToken: '',
customerCookie: WOOCOMMERCE_CUSTOMER_TOKEN_COOKIE,
cartCookie: WOOCOMMERCE_CHECKOUT_ID_COOKIE,
cartCookieMaxAge: ONE_DAY * 30,
fetch: fetchGraphqlApi,
}
@ -46,10 +41,10 @@ export const 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>(
customProvider: P = provider as any
): ShopifyAPI<P> {
): WOOCOMMERCEAPI<P> {
return commerceApi(customProvider)
}

View File

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

View File

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

View File

@ -1,7 +1,7 @@
export { default as getAllPages } from './get-all-pages'
export { default as getPage } from './get-page'
// export { default as getAllPages } from './get-all-pages'
// export { default as getPage } from './get-page'
export { default as getAllProducts } from './get-all-products'
export { default as getAllProductPaths } from './get-all-product-paths'
export { default as getProduct } from './get-product'
// export { default as getAllProductPaths } from './get-all-product-paths'
// export { default as getProduct } from './get-product'
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 fetch from './fetch'
import { API_URL, API_TOKEN } from '../../const'
import { API_URL } from '../../const'
import { getError } from '../../utils/handle-fetch-response'
const fetchGraphqlApi: GraphQLFetcher = async (
@ -14,7 +14,6 @@ const fetchGraphqlApi: GraphQLFetcher = async (
...fetchOptions,
method: 'POST',
headers: {
'X-Shopify-Storefront-Access-Token': API_TOKEN!,
...fetchOptions?.headers,
'Content-Type': 'application/json',
},

View File

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

View File

@ -1,10 +1,16 @@
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'
export const wooCommerceProvider = {
locale: 'en-us',
fetcher,
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
cartCookie: WOOCOMMERCE_CHECKOUT_ID_COOKIE,
}

View File

@ -2775,8 +2775,12 @@ export type CreateUserInput = {
nickname?: Maybe<Scalars['String']>
/** A string that contains the plain text password for the user. */
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. */
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. */
richEditing?: Maybe<Scalars['String']>
/** An array of roles to be assigned to the user. */
@ -2844,10 +2848,20 @@ export type Customer = Node & {
hasCalculatedShipping?: Maybe<Scalars['Boolean']>
/** The globally unique identifier for the customer */
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 */
isPayingCustomer?: Maybe<Scalars['Boolean']>
/** Is customer VAT exempt? */
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. */
lastName?: Maybe<Scalars['String']>
/** Gets the customers last order. */
@ -4916,6 +4930,33 @@ export type LocalProductAttribute = ProductAttribute & {
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 */
export enum ManageStockEnum {
False = 'FALSE',
@ -11200,6 +11241,23 @@ export type ReadingSettings = {
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 */
export type Refund = Node & {
__typename?: 'Refund'
@ -11315,9 +11373,13 @@ export type RegisterCustomerInput = {
/** The payload for the registerCustomer mutation */
export type 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. */
clientMutationId?: Maybe<Scalars['String']>
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>
}
@ -11347,8 +11409,12 @@ export type RegisterUserInput = {
nickname?: Maybe<Scalars['String']>
/** A string that contains the plain text password for the user. */
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. */
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. */
richEditing?: Maybe<Scalars['String']>
/** A string that contains the user's username. */
@ -11580,6 +11646,10 @@ export type RootMutation = {
fillCart?: Maybe<FillCartPayload>
/** Increase the count. */
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 */
registerCustomer?: Maybe<RegisterCustomerPayload>
/** The payload for the registerUser mutation */
@ -11866,6 +11936,16 @@ export type RootMutationIncreaseCountArgs = {
count?: Maybe<Scalars['Int']>
}
/** The root mutation */
export type RootMutationLoginArgs = {
input: LoginInput
}
/** The root mutation */
export type RootMutationRefreshJwtAuthTokenArgs = {
input: RefreshJwtAuthTokenInput
}
/** The root mutation */
export type RootMutationRegisterCustomerArgs = {
input: RegisterCustomerInput
@ -16095,9 +16175,13 @@ export type UpdateCustomerInput = {
/** The payload for the updateCustomer mutation */
export type 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. */
clientMutationId?: Maybe<Scalars['String']>
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 */
@ -16635,8 +16719,12 @@ export type UpdateUserInput = {
nickname?: Maybe<Scalars['String']>
/** A string that contains the plain text password for the user. */
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. */
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. */
richEditing?: Maybe<Scalars['String']>
/** An array of roles to be assigned to the user. */
@ -16713,10 +16801,20 @@ export type User = Node &
id: Scalars['ID']
/** Whether the node is a Content Node */
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 */
isRestricted?: Maybe<Scalars['Boolean']>
/** Whether the node is a Term */
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. */
lastName?: Maybe<Scalars['String']>
/** 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']>
}
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 SettingQuery = { __typename?: 'RootQuery' } & {

View File

@ -5601,11 +5601,21 @@ input CreateUserInput {
"""
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.
"""
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.
"""
@ -5771,6 +5781,11 @@ type Customer implements Node {
"""
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
"""
@ -5781,6 +5796,26 @@ type Customer implements Node {
"""
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.
"""
@ -10272,6 +10307,61 @@ type LocalProductAttribute implements ProductAttribute {
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
"""
@ -24021,6 +24111,36 @@ type ReadingSettings {
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
"""
@ -24270,11 +24390,21 @@ input RegisterCustomerInput {
The payload for the registerCustomer mutation
"""
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.
"""
clientMutationId: String
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
}
@ -24342,11 +24472,21 @@ input RegisterUserInput {
"""
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.
"""
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.
"""
@ -25045,6 +25185,26 @@ type RootMutation {
count: 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
"""
@ -34240,11 +34400,21 @@ input UpdateCustomerInput {
The payload for the updateCustomer mutation
"""
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.
"""
clientMutationId: String
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
"""
If true, this will refresh the users JWT secret.
"""
refreshJwtUserSecret: Boolean
"""
The date the user registered. Format is Y-m-d H:i:s.
"""
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.
"""
@ -35615,6 +35795,11 @@ type User implements Node & UniformResourceIdentifiable & Commenter & DatabaseId
"""
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
"""
@ -35625,6 +35810,26 @@ type User implements Node & UniformResourceIdentifiable & Commenter & DatabaseId
"""
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.
"""

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 getPostsQuery } from './get-posts-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'

View File

@ -11,7 +11,7 @@
"find:unused": "npx next-unused",
"generate": "graphql-codegen",
"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:definitions": "node framework/bigcommerce/scripts/generate-definitions.js"
},

View File

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

View File

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