) {
- return config.setConfig(newConfig)
+export const provider = {
+ config,
+ operations,
+}
+
+export type Provider = typeof provider
+
+export type ShopifyAPI = CommerceAPI
+
+export function getCommerceApi
(
+ customProvider: P = provider as any
+): ShopifyAPI
{
+ return commerceApi(customProvider)
}
diff --git a/framework/shopify/api/operations/get-all-pages.ts b/framework/shopify/api/operations/get-all-pages.ts
new file mode 100644
index 000000000..ab0af9ff7
--- /dev/null
+++ b/framework/shopify/api/operations/get-all-pages.ts
@@ -0,0 +1,67 @@
+import type {
+ OperationContext,
+ OperationOptions,
+} from '@commerce/api/operations'
+import {
+ GetAllPagesQuery,
+ GetAllPagesQueryVariables,
+ PageEdge,
+} from '../../schema'
+import { normalizePages } from '../../utils'
+import type { ShopifyConfig, Provider } from '..'
+import type { GetAllPagesOperation, Page } from '../../types/page'
+import getAllPagesQuery from '../../utils/queries/get-all-pages-query'
+
+export default function getAllPagesOperation({
+ commerce,
+}: OperationContext) {
+ async function getAllPages(opts?: {
+ config?: Partial
+ preview?: boolean
+ }): Promise
+
+ async function getAllPages(
+ opts: {
+ config?: Partial
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+
+ async function getAllPages({
+ query = getAllPagesQuery,
+ config,
+ variables,
+ }: {
+ url?: string
+ config?: Partial
+ variables?: GetAllPagesQueryVariables
+ preview?: boolean
+ query?: string
+ } = {}): Promise {
+ const { fetch, locale, locales = ['en-US'] } = commerce.getConfig(config)
+
+ const { data } = await fetch(
+ query,
+ {
+ variables,
+ },
+ {
+ ...(locale && {
+ headers: {
+ 'Accept-Language': locale,
+ },
+ }),
+ }
+ )
+
+ return {
+ pages: locales.reduce(
+ (arr, locale) =>
+ arr.concat(normalizePages(data.pages.edges as PageEdge[], locale)),
+ []
+ ),
+ }
+ }
+
+ return getAllPages
+}
diff --git a/framework/shopify/api/operations/get-all-product-paths.ts b/framework/shopify/api/operations/get-all-product-paths.ts
new file mode 100644
index 000000000..c84f8c90a
--- /dev/null
+++ b/framework/shopify/api/operations/get-all-product-paths.ts
@@ -0,0 +1,55 @@
+import type {
+ OperationContext,
+ OperationOptions,
+} from '@commerce/api/operations'
+import { GetAllProductPathsOperation } from '../../types/product'
+import {
+ GetAllProductPathsQuery,
+ GetAllProductPathsQueryVariables,
+ ProductEdge,
+} from '../../schema'
+import type { ShopifyConfig, Provider } from '..'
+import { getAllProductsQuery } from '../../utils'
+
+export default function getAllProductPathsOperation({
+ commerce,
+}: OperationContext) {
+ async function getAllProductPaths<
+ T extends GetAllProductPathsOperation
+ >(opts?: {
+ variables?: T['variables']
+ config?: ShopifyConfig
+ }): Promise
+
+ async function getAllProductPaths(
+ opts: {
+ variables?: T['variables']
+ config?: ShopifyConfig
+ } & OperationOptions
+ ): Promise
+
+ async function getAllProductPaths({
+ query = getAllProductsQuery,
+ config,
+ variables,
+ }: {
+ query?: string
+ config?: ShopifyConfig
+ variables?: T['variables']
+ } = {}): Promise {
+ config = commerce.getConfig(config)
+
+ const { data } = await config.fetch<
+ GetAllProductPathsQuery,
+ GetAllProductPathsQueryVariables
+ >(query, { variables })
+
+ return {
+ products: data.products.edges.map(({ node: { handle } }) => ({
+ path: `/${handle}`,
+ })),
+ }
+ }
+
+ return getAllProductPaths
+}
diff --git a/framework/shopify/api/operations/get-all-products.ts b/framework/shopify/api/operations/get-all-products.ts
new file mode 100644
index 000000000..08d781d5c
--- /dev/null
+++ b/framework/shopify/api/operations/get-all-products.ts
@@ -0,0 +1,67 @@
+import type {
+ OperationContext,
+ OperationOptions,
+} from '@commerce/api/operations'
+import { GetAllProductsOperation } from '../../types/product'
+import {
+ GetAllProductsQuery,
+ GetAllProductsQueryVariables,
+ Product as ShopifyProduct,
+} from '../../schema'
+import type { ShopifyConfig, Provider } from '..'
+import getAllProductsQuery from '../../utils/queries/get-all-products-query'
+import { normalizeProduct } from '../../utils'
+
+export default function getAllProductsOperation({
+ commerce,
+}: OperationContext) {
+ async function getAllProducts(opts?: {
+ variables?: T['variables']
+ config?: Partial
+ preview?: boolean
+ }): Promise
+
+ async function getAllProducts(
+ opts: {
+ variables?: T['variables']
+ config?: Partial
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+
+ async function getAllProducts({
+ query = getAllProductsQuery,
+ variables,
+ config,
+ }: {
+ query?: string
+ variables?: T['variables']
+ config?: Partial
+ preview?: boolean
+ } = {}): Promise {
+ const { fetch, locale } = commerce.getConfig(config)
+
+ const { data } = await fetch<
+ GetAllProductsQuery,
+ GetAllProductsQueryVariables
+ >(
+ query,
+ { variables },
+ {
+ ...(locale && {
+ headers: {
+ 'Accept-Language': locale,
+ },
+ }),
+ }
+ )
+
+ return {
+ products: data.products.edges.map(({ node }) =>
+ normalizeProduct(node as ShopifyProduct)
+ ),
+ }
+ }
+
+ return getAllProducts
+}
diff --git a/framework/shopify/api/operations/get-page.ts b/framework/shopify/api/operations/get-page.ts
new file mode 100644
index 000000000..67e135ebe
--- /dev/null
+++ b/framework/shopify/api/operations/get-page.ts
@@ -0,0 +1,64 @@
+import type {
+ OperationContext,
+ OperationOptions,
+} from '@commerce/api/operations'
+import { normalizePage } from '../../utils'
+import type { ShopifyConfig, Provider } from '..'
+import {
+ GetPageQuery,
+ GetPageQueryVariables,
+ Page as ShopifyPage,
+} from '../../schema'
+import { GetPageOperation } from '../../types/page'
+import getPageQuery from '../../utils/queries/get-page-query'
+
+export default function getPageOperation({
+ commerce,
+}: OperationContext) {
+ async function getPage(opts: {
+ variables: T['variables']
+ config?: Partial
+ preview?: boolean
+ }): Promise
+
+ async function getPage(
+ opts: {
+ variables: T['variables']
+ config?: Partial
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+
+ async function getPage({
+ query = getPageQuery,
+ variables,
+ config,
+ }: {
+ query?: string
+ variables: T['variables']
+ config?: Partial
+ preview?: boolean
+ }): Promise {
+ const { fetch, locale = 'en-US' } = commerce.getConfig(config)
+
+ const {
+ data: { node: page },
+ } = await fetch(
+ query,
+ {
+ variables,
+ },
+ {
+ ...(locale && {
+ headers: {
+ 'Accept-Language': locale,
+ },
+ }),
+ }
+ )
+
+ return page ? { page: normalizePage(page as ShopifyPage, locale) } : {}
+ }
+
+ return getPage
+}
diff --git a/framework/shopify/api/operations/get-product.ts b/framework/shopify/api/operations/get-product.ts
new file mode 100644
index 000000000..447b5c792
--- /dev/null
+++ b/framework/shopify/api/operations/get-product.ts
@@ -0,0 +1,63 @@
+import type {
+ OperationContext,
+ OperationOptions,
+} from '@commerce/api/operations'
+import { GetProductOperation } from '../../types/product'
+import { normalizeProduct, getProductQuery } from '../../utils'
+import type { ShopifyConfig, Provider } from '..'
+import { GetProductBySlugQuery, Product as ShopifyProduct } from '../../schema'
+
+export default function getProductOperation({
+ commerce,
+}: OperationContext) {
+ async function getProduct(opts: {
+ variables: T['variables']
+ config?: Partial
+ preview?: boolean
+ }): Promise
+
+ async function getProduct(
+ opts: {
+ variables: T['variables']
+ config?: Partial
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+
+ async function getProduct({
+ query = getProductQuery,
+ variables,
+ config: cfg,
+ }: {
+ query?: string
+ variables: T['variables']
+ config?: Partial
+ preview?: boolean
+ }): Promise {
+ const { fetch, locale } = commerce.getConfig(cfg)
+
+ const {
+ data: { productByHandle },
+ } = await fetch(
+ query,
+ {
+ variables,
+ },
+ {
+ ...(locale && {
+ headers: {
+ 'Accept-Language': locale,
+ },
+ }),
+ }
+ )
+
+ return {
+ ...(productByHandle && {
+ product: normalizeProduct(productByHandle as ShopifyProduct),
+ }),
+ }
+ }
+
+ return getProduct
+}
diff --git a/framework/shopify/api/operations/get-site-info.ts b/framework/shopify/api/operations/get-site-info.ts
new file mode 100644
index 000000000..27b63b0f9
--- /dev/null
+++ b/framework/shopify/api/operations/get-site-info.ts
@@ -0,0 +1,62 @@
+import type {
+ OperationContext,
+ OperationOptions,
+} from '@commerce/api/operations'
+import { GetSiteInfoQueryVariables } from '../../schema'
+import type { ShopifyConfig, Provider } from '..'
+import { GetSiteInfoOperation } from '../../types/site'
+
+import { getCategories, getBrands, getSiteInfoQuery } from '../../utils'
+
+export default function getSiteInfoOperation({
+ commerce,
+}: OperationContext) {
+ async function getSiteInfo(opts?: {
+ config?: Partial
+ preview?: boolean
+ }): Promise
+
+ async function getSiteInfo(
+ opts: {
+ config?: Partial
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+
+ async function getSiteInfo({
+ query = getSiteInfoQuery,
+ config,
+ variables,
+ }: {
+ query?: string
+ config?: Partial
+ preview?: boolean
+ variables?: GetSiteInfoQueryVariables
+ } = {}): Promise {
+ const cfg = commerce.getConfig(config)
+
+ const categories = await getCategories(cfg)
+ const brands = await getBrands(cfg)
+ /*
+ const { fetch, locale } = cfg
+ const { data } = await fetch(
+ query,
+ { variables },
+ {
+ ...(locale && {
+ headers: {
+ 'Accept-Language': locale,
+ },
+ }),
+ }
+ )
+ */
+
+ return {
+ categories,
+ brands,
+ }
+ }
+
+ return getSiteInfo
+}
diff --git a/framework/shopify/api/operations/index.ts b/framework/shopify/api/operations/index.ts
new file mode 100644
index 000000000..7872a20b6
--- /dev/null
+++ b/framework/shopify/api/operations/index.ts
@@ -0,0 +1,7 @@
+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 getSiteInfo } from './get-site-info'
+export { default as login } from './login'
diff --git a/framework/shopify/api/operations/login.ts b/framework/shopify/api/operations/login.ts
new file mode 100644
index 000000000..41e837a3f
--- /dev/null
+++ b/framework/shopify/api/operations/login.ts
@@ -0,0 +1,48 @@
+import type { ServerResponse } from 'http'
+import type { OperationContext } from '@commerce/api/operations'
+import type { LoginOperation } from '../../types/login'
+import type { ShopifyConfig, Provider } from '..'
+import {
+ customerAccessTokenCreateMutation,
+ setCustomerToken,
+ throwUserErrors,
+} from '../../utils'
+import { CustomerAccessTokenCreateMutation } from '../../schema'
+
+export default function loginOperation({
+ commerce,
+}: OperationContext) {
+ async function login({
+ query = customerAccessTokenCreateMutation,
+ variables,
+ config,
+ }: {
+ query?: string
+ variables: T['variables']
+ res: ServerResponse
+ config?: ShopifyConfig
+ }): Promise {
+ config = commerce.getConfig(config)
+
+ const {
+ data: { customerAccessTokenCreate },
+ } = await config.fetch(query, {
+ variables,
+ })
+
+ throwUserErrors(customerAccessTokenCreate?.customerUserErrors)
+
+ const customerAccessToken = customerAccessTokenCreate?.customerAccessToken
+ const accessToken = customerAccessToken?.accessToken
+
+ if (accessToken) {
+ setCustomerToken(accessToken)
+ }
+
+ return {
+ result: customerAccessToken?.accessToken,
+ }
+ }
+
+ return login
+}
diff --git a/framework/shopify/api/utils/create-api-handler.ts b/framework/shopify/api/utils/create-api-handler.ts
deleted file mode 100644
index 8820aeabc..000000000
--- a/framework/shopify/api/utils/create-api-handler.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
-import { ShopifyConfig, getConfig } from '..'
-
-export type ShopifyApiHandler<
- T = any,
- H extends ShopifyHandlers = {},
- Options extends {} = {}
-> = (
- req: NextApiRequest,
- res: NextApiResponse>,
- config: ShopifyConfig,
- handlers: H,
- // Custom configs that may be used by a particular handler
- options: Options
-) => void | Promise
-
-export type ShopifyHandler = (options: {
- req: NextApiRequest
- res: NextApiResponse>
- config: ShopifyConfig
- body: Body
-}) => void | Promise
-
-export type ShopifyHandlers = {
- [k: string]: ShopifyHandler
-}
-
-export type ShopifyApiResponse = {
- data: T | null
- errors?: { message: string; code?: string }[]
-}
-
-export default function createApiHandler<
- T = any,
- H extends ShopifyHandlers = {},
- Options extends {} = {}
->(
- handler: ShopifyApiHandler,
- handlers: H,
- defaultOptions: Options
-) {
- return function getApiHandler({
- config,
- operations,
- options,
- }: {
- config?: ShopifyConfig
- operations?: Partial
- options?: Options extends {} ? Partial : never
- } = {}): NextApiHandler {
- const ops = { ...operations, ...handlers }
- const opts = { ...defaultOptions, ...options }
-
- return function apiHandler(req, res) {
- return handler(req, res, getConfig(config), ops, opts)
- }
- }
-}
diff --git a/framework/shopify/api/utils/fetch-all-products.ts b/framework/shopify/api/utils/fetch-all-products.ts
deleted file mode 100644
index 9fa70a5ee..000000000
--- a/framework/shopify/api/utils/fetch-all-products.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { ProductEdge } from '../../schema'
-import { ShopifyConfig } from '..'
-
-const fetchAllProducts = async ({
- config,
- query,
- variables,
- acc = [],
- cursor,
-}: {
- config: ShopifyConfig
- query: string
- acc?: ProductEdge[]
- variables?: any
- cursor?: string
-}): Promise => {
- const { data } = await config.fetch(query, {
- variables: { ...variables, cursor },
- })
-
- const edges: ProductEdge[] = data.products?.edges ?? []
- const hasNextPage = data.products?.pageInfo?.hasNextPage
- acc = acc.concat(edges)
-
- if (hasNextPage) {
- const cursor = edges.pop()?.cursor
- if (cursor) {
- return fetchAllProducts({
- config,
- query,
- variables,
- acc,
- cursor,
- })
- }
- }
-
- return acc
-}
-
-export default fetchAllProducts
diff --git a/framework/shopify/api/utils/is-allowed-method.ts b/framework/shopify/api/utils/is-allowed-method.ts
deleted file mode 100644
index 78bbba568..000000000
--- a/framework/shopify/api/utils/is-allowed-method.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import type { NextApiRequest, NextApiResponse } from 'next'
-
-export default function isAllowedMethod(
- req: NextApiRequest,
- res: NextApiResponse,
- allowedMethods: string[]
-) {
- const methods = allowedMethods.includes('OPTIONS')
- ? allowedMethods
- : [...allowedMethods, 'OPTIONS']
-
- if (!req.method || !methods.includes(req.method)) {
- res.status(405)
- res.setHeader('Allow', methods.join(', '))
- res.end()
- return false
- }
-
- if (req.method === 'OPTIONS') {
- res.status(200)
- res.setHeader('Allow', methods.join(', '))
- res.setHeader('Content-Length', '0')
- res.end()
- return false
- }
-
- return true
-}
diff --git a/framework/shopify/api/wishlist/index.tsx b/framework/shopify/api/wishlist/index.tsx
deleted file mode 100644
index a72856673..000000000
--- a/framework/shopify/api/wishlist/index.tsx
+++ /dev/null
@@ -1,2 +0,0 @@
-export type WishlistItem = { product: any; id: number }
-export default function () {}
diff --git a/framework/shopify/auth/use-login.tsx b/framework/shopify/auth/use-login.tsx
index 7993822cd..d4369b7c2 100644
--- a/framework/shopify/auth/use-login.tsx
+++ b/framework/shopify/auth/use-login.tsx
@@ -1,31 +1,22 @@
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,
- Mutation,
- MutationCheckoutCreateArgs,
-} from '../schema'
+import { CommerceError } from '@commerce/utils/errors'
import useLogin, { UseLogin } from '@commerce/auth/use-login'
-import { setCustomerToken, throwUserErrors } from '../utils'
+import type { LoginHook } from '../types/login'
+import useCustomer from '../customer/use-customer'
+
+import {
+ setCustomerToken,
+ throwUserErrors,
+ customerAccessTokenCreateMutation,
+} from '../utils'
+import { Mutation, MutationCustomerAccessTokenCreateArgs } from '../schema'
export default useLogin as UseLogin
-const getErrorMessage = ({ code, message }: CustomerUserError) => {
- switch (code) {
- case 'UNIDENTIFIED_CUSTOMER':
- message = 'Cannot find an account that matches the provided credentials'
- break
- }
- return message
-}
-
-export const handler: MutationHook = {
+export const handler: MutationHook = {
fetchOptions: {
- query: createCustomerAccessTokenMutation,
+ query: customerAccessTokenCreateMutation,
},
async fetcher({ input: { email, password }, options, fetch }) {
if (!(email && password)) {
@@ -37,7 +28,7 @@ export const handler: MutationHook = {
const { customerAccessTokenCreate } = await fetch<
Mutation,
- MutationCheckoutCreateArgs
+ MutationCustomerAccessTokenCreateArgs
>({
...options,
variables: {
diff --git a/framework/shopify/auth/use-logout.tsx b/framework/shopify/auth/use-logout.tsx
index 81a3b8cdd..30074b8d5 100644
--- a/framework/shopify/auth/use-logout.tsx
+++ b/framework/shopify/auth/use-logout.tsx
@@ -1,13 +1,14 @@
import { useCallback } from 'react'
import type { MutationHook } from '@commerce/utils/types'
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
+import type { LogoutHook } from '../types/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
-export const handler: MutationHook = {
+export const handler: MutationHook = {
fetchOptions: {
query: customerAccessTokenDeleteMutation,
},
diff --git a/framework/shopify/auth/use-signup.tsx b/framework/shopify/auth/use-signup.tsx
index 9ca5c682f..29557e960 100644
--- a/framework/shopify/auth/use-signup.tsx
+++ b/framework/shopify/auth/use-signup.tsx
@@ -1,25 +1,20 @@
import { useCallback } from 'react'
import type { MutationHook } from '@commerce/utils/types'
-import { CommerceError, ValidationError } from '@commerce/utils/errors'
+import { CommerceError } from '@commerce/utils/errors'
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
+import type { SignupHook } from '../types/signup'
import useCustomer from '../customer/use-customer'
-import {
- CustomerCreateInput,
- Mutation,
- MutationCustomerCreateArgs,
-} from '../schema'
+import { Mutation, MutationCustomerCreateArgs } from '../schema'
-import { customerCreateMutation } from '../utils/mutations'
-import { handleAutomaticLogin, throwUserErrors } from '../utils'
+import {
+ handleAutomaticLogin,
+ throwUserErrors,
+ customerCreateMutation,
+} from '../utils'
export default useSignup as UseSignup
-export const handler: MutationHook<
- null,
- {},
- CustomerCreateInput,
- CustomerCreateInput
-> = {
+export const handler: MutationHook = {
fetchOptions: {
query: customerCreateMutation,
},
diff --git a/framework/shopify/cart/use-add-item.tsx b/framework/shopify/cart/use-add-item.tsx
index cce0950e9..5f0809d01 100644
--- a/framework/shopify/cart/use-add-item.tsx
+++ b/framework/shopify/cart/use-add-item.tsx
@@ -2,18 +2,19 @@ import { useCallback } from 'react'
import type { MutationHook } from '@commerce/utils/types'
import { CommerceError } from '@commerce/utils/errors'
import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item'
+import type { AddItemHook } from '../types/cart'
import useCart from './use-cart'
+
import {
checkoutLineItemAddMutation,
getCheckoutId,
checkoutToCart,
} from '../utils'
-import { Cart, CartItemBody } from '../types'
import { Mutation, MutationCheckoutLineItemsAddArgs } from '../schema'
export default useAddItem as UseAddItem
-export const handler: MutationHook = {
+export const handler: MutationHook = {
fetchOptions: {
query: checkoutLineItemAddMutation,
},
diff --git a/framework/shopify/cart/use-cart.tsx b/framework/shopify/cart/use-cart.tsx
index 5f77360bb..d920d058a 100644
--- a/framework/shopify/cart/use-cart.tsx
+++ b/framework/shopify/cart/use-cart.tsx
@@ -1,22 +1,20 @@
import { useMemo } from 'react'
-import useCommerceCart, {
- FetchCartInput,
- UseCart,
-} from '@commerce/cart/use-cart'
+import useCommerceCart, { UseCart } from '@commerce/cart/use-cart'
-import { Cart } from '../types'
import { SWRHook } from '@commerce/utils/types'
import { checkoutCreate, checkoutToCart } from '../utils'
import getCheckoutQuery from '../utils/queries/get-checkout-query'
+import { GetCartHook } from '../types/cart'
+
+import {
+ GetCheckoutQuery,
+ GetCheckoutQueryVariables,
+ CheckoutDetailsFragment,
+} from '../schema'
export default useCommerceCart as UseCart
-export const handler: SWRHook<
- Cart | null,
- {},
- FetchCartInput,
- { isEmpty?: boolean }
-> = {
+export const handler: SWRHook = {
fetchOptions: {
query: getCheckoutQuery,
},
diff --git a/framework/shopify/cart/use-remove-item.tsx b/framework/shopify/cart/use-remove-item.tsx
index 8db38eac2..bf9fb2d95 100644
--- a/framework/shopify/cart/use-remove-item.tsx
+++ b/framework/shopify/cart/use-remove-item.tsx
@@ -3,31 +3,29 @@ import type {
MutationHookContext,
HookFetcherContext,
} from '@commerce/utils/types'
-import { RemoveCartItemBody } from '@commerce/types'
import { ValidationError } from '@commerce/utils/errors'
-import useRemoveItem, {
- RemoveItemInput as RemoveItemInputBase,
- UseRemoveItem,
-} from '@commerce/cart/use-remove-item'
+import useRemoveItem, { UseRemoveItem } from '@commerce/cart/use-remove-item'
+import type { Cart, LineItem, RemoveItemHook } from '../types/cart'
import useCart from './use-cart'
+
+export type RemoveItemFn = T extends LineItem
+ ? (input?: RemoveItemActionInput) => Promise
+ : (input: RemoveItemActionInput) => Promise
+
+export type RemoveItemActionInput = T extends LineItem
+ ? Partial
+ : RemoveItemHook['actionInput']
+
+export default useRemoveItem as UseRemoveItem
+
import {
checkoutLineItemRemoveMutation,
getCheckoutId,
checkoutToCart,
} from '../utils'
-import { Cart, LineItem } from '../types'
+
import { Mutation, MutationCheckoutLineItemsRemoveArgs } from '../schema'
-export type RemoveItemFn = T extends LineItem
- ? (input?: RemoveItemInput) => Promise
- : (input: RemoveItemInput) => Promise
-
-export type RemoveItemInput = T extends LineItem
- ? Partial
- : RemoveItemInputBase
-
-export default useRemoveItem as UseRemoveItem
-
export const handler = {
fetchOptions: {
query: checkoutLineItemRemoveMutation,
@@ -36,16 +34,14 @@ export const handler = {
input: { itemId },
options,
fetch,
- }: HookFetcherContext) {
+ }: HookFetcherContext) {
const data = await fetch({
...options,
variables: { checkoutId: getCheckoutId(), lineItemIds: [itemId] },
})
return checkoutToCart(data.checkoutLineItemsRemove)
},
- useHook: ({
- fetch,
- }: MutationHookContext) => <
+ useHook: ({ fetch }: MutationHookContext) => <
T extends LineItem | undefined = undefined
>(
ctx: { item?: T } = {}
diff --git a/framework/shopify/cart/use-update-item.tsx b/framework/shopify/cart/use-update-item.tsx
index 49dd6be14..3f1cf4315 100644
--- a/framework/shopify/cart/use-update-item.tsx
+++ b/framework/shopify/cart/use-update-item.tsx
@@ -5,21 +5,21 @@ import type {
MutationHookContext,
} from '@commerce/utils/types'
import { ValidationError } from '@commerce/utils/errors'
-import useUpdateItem, {
- UpdateItemInput as UpdateItemInputBase,
- UseUpdateItem,
-} from '@commerce/cart/use-update-item'
+import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item'
import useCart from './use-cart'
import { handler as removeItemHandler } from './use-remove-item'
-import type { Cart, LineItem, UpdateCartItemBody } from '../types'
-import { checkoutToCart } from '../utils'
-import { getCheckoutId, checkoutLineItemUpdateMutation } from '../utils'
+import type { UpdateItemHook, LineItem } from '../types/cart'
+import {
+ getCheckoutId,
+ checkoutLineItemUpdateMutation,
+ checkoutToCart,
+} from '../utils'
import { Mutation, MutationCheckoutLineItemsUpdateArgs } from '../schema'
-export type UpdateItemInput = T extends LineItem
- ? Partial>
- : UpdateItemInputBase
+export type UpdateItemActionInput = T extends LineItem
+ ? Partial
+ : UpdateItemHook['actionInput']
export default useUpdateItem as UseUpdateItem
@@ -31,7 +31,7 @@ export const handler = {
input: { itemId, item },
options,
fetch,
- }: HookFetcherContext) {
+ }: HookFetcherContext) {
if (Number.isInteger(item.quantity)) {
// Also allow the update hook to remove an item if the quantity is lower than 1
if (item.quantity! < 1) {
@@ -64,9 +64,7 @@ export const handler = {
return checkoutToCart(checkoutLineItemsUpdate)
},
- useHook: ({
- fetch,
- }: MutationHookContext) => <
+ useHook: ({ fetch }: MutationHookContext) => <
T extends LineItem | undefined = undefined
>(
ctx: {
@@ -78,7 +76,7 @@ export const handler = {
const { mutate } = useCart() as any
return useCallback(
- debounce(async (input: UpdateItemInput) => {
+ debounce(async (input: UpdateItemActionInput) => {
const itemId = input.id ?? item?.id
const productId = input.productId ?? item?.productId
const variantId = input.productId ?? item?.variantId
diff --git a/framework/shopify/codegen.json b/framework/shopify/codegen.json
new file mode 100644
index 000000000..f0a757142
--- /dev/null
+++ b/framework/shopify/codegen.json
@@ -0,0 +1,32 @@
+{
+ "schema": {
+ "https://${NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN}/api/2021-01/graphql.json": {
+ "headers": {
+ "X-Shopify-Storefront-Access-Token": "${NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN}"
+ }
+ }
+ },
+ "documents": [
+ {
+ "./framework/shopify/**/*.{ts,tsx}": {
+ "noRequire": true
+ }
+ }
+ ],
+ "generates": {
+ "./framework/shopify/schema.d.ts": {
+ "plugins": ["typescript", "typescript-operations"],
+ "config": {
+ "scalars": {
+ "ID": "string"
+ }
+ }
+ },
+ "./framework/shopify/schema.graphql": {
+ "plugins": ["schema-ast"]
+ }
+ },
+ "hooks": {
+ "afterAllFileWrite": ["prettier --write"]
+ }
+}
diff --git a/framework/shopify/common/get-all-pages.ts b/framework/shopify/common/get-all-pages.ts
deleted file mode 100644
index 54231ed03..000000000
--- a/framework/shopify/common/get-all-pages.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { getConfig, ShopifyConfig } from '../api'
-import { PageEdge } from '../schema'
-import { getAllPagesQuery } from '../utils/queries'
-
-type Variables = {
- first?: number
-}
-
-type ReturnType = {
- pages: Page[]
-}
-
-export type Page = {
- id: string
- name: string
- url: string
- sort_order?: number
- body: string
-}
-
-const getAllPages = async (options?: {
- variables?: Variables
- config: ShopifyConfig
- preview?: boolean
-}): Promise => {
- let { config, variables = { first: 250 } } = options ?? {}
- config = getConfig(config)
- const { locale } = config
- const { data } = await config.fetch(getAllPagesQuery, { variables })
-
- const pages = data.pages?.edges?.map(
- ({ node: { title: name, handle, ...node } }: PageEdge) => ({
- ...node,
- url: `/${locale}/${handle}`,
- name,
- })
- )
-
- return { pages }
-}
-
-export default getAllPages
diff --git a/framework/shopify/common/get-page.ts b/framework/shopify/common/get-page.ts
deleted file mode 100644
index be934aa42..000000000
--- a/framework/shopify/common/get-page.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { getConfig, ShopifyConfig } from '../api'
-import getPageQuery from '../utils/queries/get-page-query'
-import { Page } from './get-all-pages'
-
-type Variables = {
- id: string
-}
-
-export type GetPageResult = T
-
-const getPage = async (options: {
- variables: Variables
- config: ShopifyConfig
- preview?: boolean
-}): Promise => {
- let { config, variables } = options ?? {}
-
- config = getConfig(config)
- const { locale } = config
-
- const { data } = await config.fetch(getPageQuery, {
- variables,
- })
- const page = data.node
-
- return {
- page: page
- ? {
- ...page,
- name: page.title,
- url: `/${locale}/${page.handle}`,
- }
- : null,
- }
-}
-
-export default getPage
diff --git a/framework/shopify/common/get-site-info.ts b/framework/shopify/common/get-site-info.ts
deleted file mode 100644
index cbbacf5b6..000000000
--- a/framework/shopify/common/get-site-info.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import getCategories, { Category } from '../utils/get-categories'
-import getVendors, { Brands } from '../utils/get-vendors'
-
-import { getConfig, ShopifyConfig } from '../api'
-
-export type GetSiteInfoResult<
- T extends { categories: any[]; brands: any[] } = {
- categories: Category[]
- brands: Brands
- }
-> = T
-
-const getSiteInfo = async (options?: {
- variables?: any
- config: ShopifyConfig
- preview?: boolean
-}): Promise => {
- let { config } = options ?? {}
-
- config = getConfig(config)
-
- const categories = await getCategories(config)
- const brands = await getVendors(config)
-
- return {
- categories,
- brands,
- }
-}
-
-export default getSiteInfo
diff --git a/framework/shopify/customer/get-customer-id.ts b/framework/shopify/customer/get-customer-id.ts
deleted file mode 100644
index ca096645a..000000000
--- a/framework/shopify/customer/get-customer-id.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { getConfig, ShopifyConfig } 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?: ShopifyConfig
-}): 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/shopify/customer/use-customer.tsx b/framework/shopify/customer/use-customer.tsx
index 7b600838e..be097fe80 100644
--- a/framework/shopify/customer/use-customer.tsx
+++ b/framework/shopify/customer/use-customer.tsx
@@ -1,18 +1,19 @@
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
-import { Customer } from '@commerce/types'
+import type { CustomerHook } from '../types/customer'
import { SWRHook } from '@commerce/utils/types'
import { getCustomerQuery, getCustomerToken } from '../utils'
+import { GetCustomerQuery, GetCustomerQueryVariables } from '../schema'
export default useCustomer as UseCustomer
-export const handler: SWRHook = {
+export const handler: SWRHook = {
fetchOptions: {
query: getCustomerQuery,
},
async fetcher({ options, fetch }) {
const customerAccessToken = getCustomerToken()
if (customerAccessToken) {
- const data = await fetch({
+ const data = await fetch({
...options,
variables: { customerAccessToken: getCustomerToken() },
})
diff --git a/framework/shopify/fetcher.ts b/framework/shopify/fetcher.ts
index a69150503..9a8d2d8d5 100644
--- a/framework/shopify/fetcher.ts
+++ b/framework/shopify/fetcher.ts
@@ -8,13 +8,17 @@ const fetcher: Fetcher = async ({
variables,
query,
}) => {
+ const { locale, ...vars } = variables ?? {}
return handleFetchResponse(
await fetch(url, {
method,
- body: JSON.stringify({ query, variables }),
+ body: JSON.stringify({ query, variables: vars }),
headers: {
'X-Shopify-Storefront-Access-Token': API_TOKEN!,
'Content-Type': 'application/json',
+ ...(locale && {
+ 'Accept-Language': locale,
+ }),
},
})
)
diff --git a/framework/shopify/index.tsx b/framework/shopify/index.tsx
index 5b25d6b21..13ff9d1f8 100644
--- a/framework/shopify/index.tsx
+++ b/framework/shopify/index.tsx
@@ -36,4 +36,4 @@ export function CommerceProvider({ children, ...config }: ShopifyProps) {
)
}
-export const useCommerce = () => useCoreCommerce()
+export const useCommerce = () => useCoreCommerce()
diff --git a/framework/shopify/product/get-all-collections.ts b/framework/shopify/product/get-all-collections.ts
deleted file mode 100644
index 15c4bc51a..000000000
--- a/framework/shopify/product/get-all-collections.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { CollectionEdge } from '../schema'
-import { getConfig, ShopifyConfig } from '../api'
-import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
-
-const getAllCollections = async (options?: {
- variables?: any
- config: ShopifyConfig
- preview?: boolean
-}) => {
- let { config, variables = { first: 250 } } = options ?? {}
- config = getConfig(config)
-
- const { data } = await config.fetch(getAllCollectionsQuery, { variables })
- const edges = data.collections?.edges ?? []
-
- const categories = edges.map(
- ({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
- entityId,
- name,
- path: `/${handle}`,
- })
- )
-
- return {
- categories,
- }
-}
-
-export default getAllCollections
diff --git a/framework/shopify/product/get-all-product-paths.ts b/framework/shopify/product/get-all-product-paths.ts
deleted file mode 100644
index e8ee04065..000000000
--- a/framework/shopify/product/get-all-product-paths.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { getConfig, ShopifyConfig } from '../api'
-import { ProductEdge } from '../schema'
-import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
-
-type ProductPath = {
- path: string
-}
-
-export type ProductPathNode = {
- node: ProductPath
-}
-
-type ReturnType = {
- products: ProductPathNode[]
-}
-
-const getAllProductPaths = async (options?: {
- variables?: any
- config?: ShopifyConfig
- preview?: boolean
-}): Promise => {
- let { config, variables = { first: 100, sortKey: 'BEST_SELLING' } } =
- options ?? {}
- config = getConfig(config)
-
- const { data } = await config.fetch(getAllProductsPathsQuery, {
- variables,
- })
-
- return {
- products: data.products?.edges?.map(
- ({ node: { handle } }: ProductEdge) => ({
- node: {
- path: `/${handle}`,
- },
- })
- ),
- }
-}
-
-export default getAllProductPaths
diff --git a/framework/shopify/product/get-all-products.ts b/framework/shopify/product/get-all-products.ts
deleted file mode 100644
index 3915abebf..000000000
--- a/framework/shopify/product/get-all-products.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { GraphQLFetcherResult } from '@commerce/api'
-import { getConfig, ShopifyConfig } from '../api'
-import { ProductEdge } from '../schema'
-import { getAllProductsQuery } from '../utils/queries'
-import { normalizeProduct } from '../utils/normalize'
-import { Product } from '@commerce/types'
-
-type Variables = {
- first?: number
- field?: string
-}
-
-type ReturnType = {
- products: Product[]
-}
-
-const getAllProducts = async (options: {
- variables?: Variables
- config?: ShopifyConfig
- preview?: boolean
-}): Promise => {
- let { config, variables = { first: 250 } } = options ?? {}
- config = getConfig(config)
-
- const { data }: GraphQLFetcherResult = await config.fetch(
- getAllProductsQuery,
- { variables }
- )
-
- const products = data.products?.edges?.map(({ node: p }: ProductEdge) =>
- normalizeProduct(p)
- )
-
- return {
- products,
- }
-}
-
-export default getAllProducts
diff --git a/framework/shopify/product/get-product.ts b/framework/shopify/product/get-product.ts
deleted file mode 100644
index 1d861e1a1..000000000
--- a/framework/shopify/product/get-product.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { GraphQLFetcherResult } from '@commerce/api'
-import { getConfig, ShopifyConfig } from '../api'
-import { normalizeProduct, getProductQuery } from '../utils'
-
-type Variables = {
- slug: string
-}
-
-type ReturnType = {
- product: any
-}
-
-const getProduct = async (options: {
- variables: Variables
- config: ShopifyConfig
- preview?: boolean
-}): Promise => {
- let { config, variables } = options ?? {}
- config = getConfig(config)
-
- const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, {
- variables,
- })
- const { productByHandle } = data
-
- return {
- product: productByHandle ? normalizeProduct(productByHandle) : null,
- }
-}
-
-export default getProduct
diff --git a/framework/shopify/product/use-search.tsx b/framework/shopify/product/use-search.tsx
index bf812af3d..9588b65a2 100644
--- a/framework/shopify/product/use-search.tsx
+++ b/framework/shopify/product/use-search.tsx
@@ -1,7 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useSearch, { UseSearch } from '@commerce/product/use-search'
-import { ProductEdge } from '../schema'
+import {
+ CollectionEdge,
+ GetAllProductsQuery,
+ GetProductsFromCollectionQueryVariables,
+ Product as ShopifyProduct,
+ ProductEdge,
+} from '../schema'
+
import {
getAllProductsQuery,
getCollectionProductsQuery,
@@ -9,56 +16,59 @@ import {
normalizeProduct,
} from '../utils'
-import { Product } from '@commerce/types'
-
-export default useSearch as UseSearch
+import type { SearchProductsHook } from '../types/product'
export type SearchProductsInput = {
search?: string
- categoryId?: string
- brandId?: string
+ categoryId?: number
+ brandId?: number
sort?: string
+ locale?: string
}
-export type SearchProductsData = {
- products: Product[]
- found: boolean
-}
+export default useSearch as UseSearch
-export const handler: SWRHook<
- SearchProductsData,
- SearchProductsInput,
- SearchProductsInput
-> = {
+export const handler: SWRHook = {
fetchOptions: {
query: getAllProductsQuery,
},
async fetcher({ input, options, fetch }) {
const { categoryId, brandId } = input
+ const method = options?.method
+ const variables = getSearchVariables(input)
+ let products
- const data = await fetch({
- query: categoryId ? getCollectionProductsQuery : options.query,
- method: options?.method,
- variables: getSearchVariables(input),
- })
-
- let edges
-
+ // change the query to getCollectionProductsQuery when categoryId is set
if (categoryId) {
- edges = data.node?.products?.edges ?? []
- if (brandId) {
- edges = edges.filter(
- ({ node: { vendor } }: ProductEdge) =>
- vendor.replace(/\s+/g, '-').toLowerCase() === brandId
- )
- }
+ const data = await fetch<
+ CollectionEdge,
+ GetProductsFromCollectionQueryVariables
+ >({
+ query: getCollectionProductsQuery,
+ method,
+ variables,
+ })
+ // filter on client when brandId & categoryId are set since is not available on collection product query
+ products = brandId
+ ? data.node.products.edges.filter(
+ ({ node: { vendor } }: ProductEdge) =>
+ vendor.replace(/\s+/g, '-').toLowerCase() === brandId
+ )
+ : data.node.products.edges
} else {
- edges = data.products?.edges ?? []
+ const data = await fetch({
+ query: options.query,
+ method,
+ variables,
+ })
+ products = data.products.edges
}
return {
- products: edges.map(({ node }: ProductEdge) => normalizeProduct(node)),
- found: !!edges.length,
+ products: products?.map(({ node }) =>
+ normalizeProduct(node as ShopifyProduct)
+ ),
+ found: !!products?.length,
}
},
useHook: ({ useData }) => (input = {}) => {
@@ -68,6 +78,7 @@ export const handler: SWRHook<
['categoryId', input.categoryId],
['brandId', input.brandId],
['sort', input.sort],
+ ['locale', input.locale],
],
swrOptions: {
revalidateOnFocus: false,
diff --git a/framework/shopify/schema.d.ts b/framework/shopify/schema.d.ts
index b1b23a3e5..328f0ff1b 100644
--- a/framework/shopify/schema.d.ts
+++ b/framework/shopify/schema.d.ts
@@ -37,7 +37,7 @@ export type ApiVersion = {
displayName: Scalars['String']
/** The unique identifier of an ApiVersion. All supported API versions have a date-based (YYYY-MM) or `unstable` handle. */
handle: Scalars['String']
- /** Whether the version is supported by Shopify. */
+ /** Whether the version is actively supported by Shopify. Supported API versions are guaranteed to be stable. Unsupported API versions include unstable, release candidate, and end-of-life versions that are marked as unsupported. For more information, refer to [Versioning](https://shopify.dev/concepts/about-apis/versioning). */
supported: Scalars['Boolean']
}
@@ -306,17 +306,17 @@ export enum BlogSortKeys {
/** Card brand, such as Visa or Mastercard, which can be used for payments. */
export enum CardBrand {
- /** Visa */
+ /** Visa. */
Visa = 'VISA',
- /** Mastercard */
+ /** Mastercard. */
Mastercard = 'MASTERCARD',
- /** Discover */
+ /** Discover. */
Discover = 'DISCOVER',
- /** American Express */
+ /** American Express. */
AmericanExpress = 'AMERICAN_EXPRESS',
- /** Diners Club */
+ /** Diners Club. */
DinersClub = 'DINERS_CLUB',
- /** JCB */
+ /** JCB. */
Jcb = 'JCB',
}
@@ -1195,6 +1195,8 @@ export enum CountryCode {
Am = 'AM',
/** Aruba. */
Aw = 'AW',
+ /** Ascension Island. */
+ Ac = 'AC',
/** Australia. */
Au = 'AU',
/** Austria. */
@@ -1613,6 +1615,8 @@ export enum CountryCode {
To = 'TO',
/** Trinidad & Tobago. */
Tt = 'TT',
+ /** Tristan da Cunha. */
+ Ta = 'TA',
/** Tunisia. */
Tn = 'TN',
/** Turkey. */
@@ -1687,7 +1691,7 @@ export type CreditCard = {
export type CreditCardPaymentInput = {
/** The amount of the payment. */
amount: Scalars['Money']
- /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. */
+ /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. For more information, refer to [Idempotent requests](https://shopify.dev/concepts/about-apis/idempotent-requests). */
idempotencyKey: Scalars['String']
/** The billing address for the payment. */
billingAddress: MailingAddressInput
@@ -1704,7 +1708,7 @@ export type CreditCardPaymentInput = {
export type CreditCardPaymentInputV2 = {
/** The amount and currency of the payment. */
paymentAmount: MoneyInput
- /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. */
+ /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. For more information, refer to [Idempotent requests](https://shopify.dev/concepts/about-apis/idempotent-requests). */
idempotencyKey: Scalars['String']
/** The billing address for the payment. */
billingAddress: MailingAddressInput
@@ -1766,10 +1770,6 @@ export enum CurrencyCode {
Bhd = 'BHD',
/** Burundian Franc (BIF). */
Bif = 'BIF',
- /** Belarusian Ruble (BYN). */
- Byn = 'BYN',
- /** Belarusian Ruble (BYR). */
- Byr = 'BYR',
/** Belize Dollar (BZD). */
Bzd = 'BZD',
/** Bermudian Dollar (BMD). */
@@ -1816,26 +1816,18 @@ export enum CurrencyCode {
Czk = 'CZK',
/** Danish Kroner (DKK). */
Dkk = 'DKK',
- /** Djiboutian Franc (DJF). */
- Djf = 'DJF',
/** Dominican Peso (DOP). */
Dop = 'DOP',
/** East Caribbean Dollar (XCD). */
Xcd = 'XCD',
/** Egyptian Pound (EGP). */
Egp = 'EGP',
- /** Eritrean Nakfa (ERN). */
- Ern = 'ERN',
/** Ethiopian Birr (ETB). */
Etb = 'ETB',
- /** Falkland Islands Pounds (FKP). */
- Fkp = 'FKP',
/** CFP Franc (XPF). */
Xpf = 'XPF',
/** Fijian Dollars (FJD). */
Fjd = 'FJD',
- /** Gibraltar Pounds (GIP). */
- Gip = 'GIP',
/** Gambian Dalasi (GMD). */
Gmd = 'GMD',
/** Ghanaian Cedi (GHS). */
@@ -1846,8 +1838,6 @@ export enum CurrencyCode {
Gyd = 'GYD',
/** Georgian Lari (GEL). */
Gel = 'GEL',
- /** Guinean Franc (GNF). */
- Gnf = 'GNF',
/** Haitian Gourde (HTG). */
Htg = 'HTG',
/** Honduran Lempira (HNL). */
@@ -1864,8 +1854,6 @@ export enum CurrencyCode {
Idr = 'IDR',
/** Israeli New Shekel (NIS). */
Ils = 'ILS',
- /** Iranian Rial (IRR). */
- Irr = 'IRR',
/** Iraqi Dinar (IQD). */
Iqd = 'IQD',
/** Jamaican Dollars (JMD). */
@@ -1880,8 +1868,6 @@ export enum CurrencyCode {
Kzt = 'KZT',
/** Kenyan Shilling (KES). */
Kes = 'KES',
- /** Kiribati Dollar (KID). */
- Kid = 'KID',
/** Kuwaiti Dinar (KWD). */
Kwd = 'KWD',
/** Kyrgyzstani Som (KGS). */
@@ -1896,8 +1882,6 @@ export enum CurrencyCode {
Lsl = 'LSL',
/** Liberian Dollar (LRD). */
Lrd = 'LRD',
- /** Libyan Dinar (LYD). */
- Lyd = 'LYD',
/** Lithuanian Litai (LTL). */
Ltl = 'LTL',
/** Malagasy Ariary (MGA). */
@@ -1910,8 +1894,6 @@ export enum CurrencyCode {
Mwk = 'MWK',
/** Maldivian Rufiyaa (MVR). */
Mvr = 'MVR',
- /** Mauritanian Ouguiya (MRU). */
- Mru = 'MRU',
/** Mexican Pesos (MXN). */
Mxn = 'MXN',
/** Malaysian Ringgits (MYR). */
@@ -1966,8 +1948,6 @@ export enum CurrencyCode {
Rwf = 'RWF',
/** Samoan Tala (WST). */
Wst = 'WST',
- /** Saint Helena Pounds (SHP). */
- Shp = 'SHP',
/** Saudi Riyal (SAR). */
Sar = 'SAR',
/** Sao Tome And Principe Dobra (STD). */
@@ -1976,14 +1956,10 @@ export enum CurrencyCode {
Rsd = 'RSD',
/** Seychellois Rupee (SCR). */
Scr = 'SCR',
- /** Sierra Leonean Leone (SLL). */
- Sll = 'SLL',
/** Singapore Dollars (SGD). */
Sgd = 'SGD',
/** Sudanese Pound (SDG). */
Sdg = 'SDG',
- /** Somali Shilling (SOS). */
- Sos = 'SOS',
/** Syrian Pound (SYP). */
Syp = 'SYP',
/** South African Rand (ZAR). */
@@ -2008,12 +1984,8 @@ export enum CurrencyCode {
Twd = 'TWD',
/** Thai baht (THB). */
Thb = 'THB',
- /** Tajikistani Somoni (TJS). */
- Tjs = 'TJS',
/** Tanzanian Shilling (TZS). */
Tzs = 'TZS',
- /** Tongan Pa'anga (TOP). */
- Top = 'TOP',
/** Trinidad and Tobago Dollars (TTD). */
Ttd = 'TTD',
/** Tunisian Dinar (TND). */
@@ -2034,10 +2006,6 @@ export enum CurrencyCode {
Uzs = 'UZS',
/** Vanuatu Vatu (VUV). */
Vuv = 'VUV',
- /** Venezuelan Bolivares (VEF). */
- Vef = 'VEF',
- /** Venezuelan Bolivares (VES). */
- Ves = 'VES',
/** Vietnamese đồng (VND). */
Vnd = 'VND',
/** West African CFA franc (XOF). */
@@ -2046,6 +2014,42 @@ export enum CurrencyCode {
Yer = 'YER',
/** Zambian Kwacha (ZMW). */
Zmw = 'ZMW',
+ /** Belarusian Ruble (BYN). */
+ Byn = 'BYN',
+ /** Belarusian Ruble (BYR). */
+ Byr = 'BYR',
+ /** Djiboutian Franc (DJF). */
+ Djf = 'DJF',
+ /** Eritrean Nakfa (ERN). */
+ Ern = 'ERN',
+ /** Falkland Islands Pounds (FKP). */
+ Fkp = 'FKP',
+ /** Gibraltar Pounds (GIP). */
+ Gip = 'GIP',
+ /** Guinean Franc (GNF). */
+ Gnf = 'GNF',
+ /** Iranian Rial (IRR). */
+ Irr = 'IRR',
+ /** Kiribati Dollar (KID). */
+ Kid = 'KID',
+ /** Libyan Dinar (LYD). */
+ Lyd = 'LYD',
+ /** Mauritanian Ouguiya (MRU). */
+ Mru = 'MRU',
+ /** Sierra Leonean Leone (SLL). */
+ Sll = 'SLL',
+ /** Saint Helena Pounds (SHP). */
+ Shp = 'SHP',
+ /** Somali Shilling (SOS). */
+ Sos = 'SOS',
+ /** Tajikistani Somoni (TJS). */
+ Tjs = 'TJS',
+ /** Tongan Pa'anga (TOP). */
+ Top = 'TOP',
+ /** Venezuelan Bolivares (VEF). */
+ Vef = 'VEF',
+ /** Venezuelan Bolivares (VES). */
+ Ves = 'VES',
}
/** A customer represents a customer account with the shop. Customer accounts store contact information for the customer, saving logged-in customers the trouble of having to provide it at every checkout. */
@@ -3817,7 +3821,11 @@ export type Payment = Node & {
errorMessage?: Maybe
/** Globally unique identifier. */
id: Scalars['ID']
- /** A client-side generated token to identify a payment and perform idempotent operations. */
+ /**
+ * A client-side generated token to identify a payment and perform idempotent operations.
+ * For more information, refer to
+ * [Idempotent requests](https://shopify.dev/concepts/about-apis/idempotent-requests).
+ */
idempotencyKey?: Maybe
/** The URL where the customer needs to be redirected so they can complete the 3D Secure payment flow. */
nextActionUrl?: Maybe
@@ -4386,7 +4394,9 @@ export type QueryRoot = {
collections: CollectionConnection
/** Find a customer by its access token. */
customer?: Maybe
+ /** Returns a specific node by ID. */
node?: Maybe
+ /** Returns the list of nodes with the given IDs. */
nodes: Array>
/** Find a page by its handle. */
pageByHandle?: Maybe
@@ -4768,7 +4778,7 @@ export type StringEdge = {
export type TokenizedPaymentInput = {
/** The amount of the payment. */
amount: Scalars['Money']
- /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. */
+ /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. For more information, refer to [Idempotent requests](https://shopify.dev/concepts/about-apis/idempotent-requests). */
idempotencyKey: Scalars['String']
/** The billing address for the payment. */
billingAddress: MailingAddressInput
@@ -4789,7 +4799,7 @@ export type TokenizedPaymentInput = {
export type TokenizedPaymentInputV2 = {
/** The amount and currency of the payment. */
paymentAmount: MoneyInput
- /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. */
+ /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. For more information, refer to [Idempotent requests](https://shopify.dev/concepts/about-apis/idempotent-requests). */
idempotencyKey: Scalars['String']
/** The billing address for the payment. */
billingAddress: MailingAddressInput
@@ -4810,7 +4820,7 @@ export type TokenizedPaymentInputV2 = {
export type TokenizedPaymentInputV3 = {
/** The amount and currency of the payment. */
paymentAmount: MoneyInput
- /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. */
+ /** A unique client generated key used to avoid duplicate charges. When a duplicate payment is found, the original is returned instead of creating a new one. For more information, refer to [Idempotent requests](https://shopify.dev/concepts/about-apis/idempotent-requests). */
idempotencyKey: Scalars['String']
/** The billing address for the payment. */
billingAddress: MailingAddressInput
@@ -4847,18 +4857,32 @@ export type Transaction = {
test: Scalars['Boolean']
}
+/** The different kinds of order transactions. */
export enum TransactionKind {
+ /** An authorization and capture performed together in a single step. */
Sale = 'SALE',
+ /** A transfer of the money that was reserved during the authorization stage. */
Capture = 'CAPTURE',
+ /**
+ * An amount reserved against the cardholder's funding source.
+ * Money does not change hands until the authorization is captured.
+ */
Authorization = 'AUTHORIZATION',
+ /** An authorization for a payment taken with an EMV credit card reader. */
EmvAuthorization = 'EMV_AUTHORIZATION',
+ /** Money returned to the customer when they have paid too much. */
Change = 'CHANGE',
}
+/** Transaction statuses describe the status of a transaction. */
export enum TransactionStatus {
+ /** The transaction is pending. */
Pending = 'PENDING',
+ /** The transaction succeeded. */
Success = 'SUCCESS',
+ /** The transaction failed. */
Failure = 'FAILURE',
+ /** There was an error while processing the transaction. */
Error = 'ERROR',
}
@@ -4967,19 +4991,596 @@ export enum WeightUnit {
Ounces = 'OUNCES',
}
-export type Unnamed_1_QueryVariables = Exact<{
+export type AssociateCustomerWithCheckoutMutationVariables = Exact<{
+ checkoutId: Scalars['ID']
+ customerAccessToken: Scalars['String']
+}>
+
+export type AssociateCustomerWithCheckoutMutation = {
+ __typename?: 'Mutation'
+} & {
+ checkoutCustomerAssociateV2?: Maybe<
+ { __typename?: 'CheckoutCustomerAssociateV2Payload' } & {
+ checkout?: Maybe<{ __typename?: 'Checkout' } & Pick>
+ checkoutUserErrors: Array<
+ { __typename?: 'CheckoutUserError' } & Pick<
+ CheckoutUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ customer?: Maybe<{ __typename?: 'Customer' } & Pick>
+ }
+ >
+}
+
+export type CheckoutCreateMutationVariables = Exact<{
+ input?: Maybe
+}>
+
+export type CheckoutCreateMutation = { __typename?: 'Mutation' } & {
+ checkoutCreate?: Maybe<
+ { __typename?: 'CheckoutCreatePayload' } & {
+ checkoutUserErrors: Array<
+ { __typename?: 'CheckoutUserError' } & Pick<
+ CheckoutUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ checkout?: Maybe<{ __typename?: 'Checkout' } & CheckoutDetailsFragment>
+ }
+ >
+}
+
+export type CheckoutLineItemAddMutationVariables = Exact<{
+ checkoutId: Scalars['ID']
+ lineItems: Array | CheckoutLineItemInput
+}>
+
+export type CheckoutLineItemAddMutation = { __typename?: 'Mutation' } & {
+ checkoutLineItemsAdd?: Maybe<
+ { __typename?: 'CheckoutLineItemsAddPayload' } & {
+ checkoutUserErrors: Array<
+ { __typename?: 'CheckoutUserError' } & Pick<
+ CheckoutUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ checkout?: Maybe<{ __typename?: 'Checkout' } & CheckoutDetailsFragment>
+ }
+ >
+}
+
+export type CheckoutLineItemRemoveMutationVariables = Exact<{
+ checkoutId: Scalars['ID']
+ lineItemIds: Array | Scalars['ID']
+}>
+
+export type CheckoutLineItemRemoveMutation = { __typename?: 'Mutation' } & {
+ checkoutLineItemsRemove?: Maybe<
+ { __typename?: 'CheckoutLineItemsRemovePayload' } & {
+ checkoutUserErrors: Array<
+ { __typename?: 'CheckoutUserError' } & Pick<
+ CheckoutUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ checkout?: Maybe<{ __typename?: 'Checkout' } & CheckoutDetailsFragment>
+ }
+ >
+}
+
+export type CheckoutLineItemUpdateMutationVariables = Exact<{
+ checkoutId: Scalars['ID']
+ lineItems: Array | CheckoutLineItemUpdateInput
+}>
+
+export type CheckoutLineItemUpdateMutation = { __typename?: 'Mutation' } & {
+ checkoutLineItemsUpdate?: Maybe<
+ { __typename?: 'CheckoutLineItemsUpdatePayload' } & {
+ checkoutUserErrors: Array<
+ { __typename?: 'CheckoutUserError' } & Pick<
+ CheckoutUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ checkout?: Maybe<{ __typename?: 'Checkout' } & CheckoutDetailsFragment>
+ }
+ >
+}
+
+export type CustomerAccessTokenCreateMutationVariables = Exact<{
+ input: CustomerAccessTokenCreateInput
+}>
+
+export type CustomerAccessTokenCreateMutation = { __typename?: 'Mutation' } & {
+ customerAccessTokenCreate?: Maybe<
+ { __typename?: 'CustomerAccessTokenCreatePayload' } & {
+ customerAccessToken?: Maybe<
+ { __typename?: 'CustomerAccessToken' } & Pick<
+ CustomerAccessToken,
+ 'accessToken' | 'expiresAt'
+ >
+ >
+ customerUserErrors: Array<
+ { __typename?: 'CustomerUserError' } & Pick<
+ CustomerUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ }
+ >
+}
+
+export type CustomerAccessTokenDeleteMutationVariables = Exact<{
+ customerAccessToken: Scalars['String']
+}>
+
+export type CustomerAccessTokenDeleteMutation = { __typename?: 'Mutation' } & {
+ customerAccessTokenDelete?: Maybe<
+ { __typename?: 'CustomerAccessTokenDeletePayload' } & Pick<
+ CustomerAccessTokenDeletePayload,
+ 'deletedAccessToken' | 'deletedCustomerAccessTokenId'
+ > & {
+ userErrors: Array<
+ { __typename?: 'UserError' } & Pick
+ >
+ }
+ >
+}
+
+export type CustomerActivateByUrlMutationVariables = Exact<{
+ activationUrl: Scalars['URL']
+ password: Scalars['String']
+}>
+
+export type CustomerActivateByUrlMutation = { __typename?: 'Mutation' } & {
+ customerActivateByUrl?: Maybe<
+ { __typename?: 'CustomerActivateByUrlPayload' } & {
+ customer?: Maybe<{ __typename?: 'Customer' } & Pick>
+ customerAccessToken?: Maybe<
+ { __typename?: 'CustomerAccessToken' } & Pick<
+ CustomerAccessToken,
+ 'accessToken' | 'expiresAt'
+ >
+ >
+ customerUserErrors: Array<
+ { __typename?: 'CustomerUserError' } & Pick<
+ CustomerUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ }
+ >
+}
+
+export type CustomerActivateMutationVariables = Exact<{
+ id: Scalars['ID']
+ input: CustomerActivateInput
+}>
+
+export type CustomerActivateMutation = { __typename?: 'Mutation' } & {
+ customerActivate?: Maybe<
+ { __typename?: 'CustomerActivatePayload' } & {
+ customer?: Maybe<{ __typename?: 'Customer' } & Pick>
+ customerAccessToken?: Maybe<
+ { __typename?: 'CustomerAccessToken' } & Pick<
+ CustomerAccessToken,
+ 'accessToken' | 'expiresAt'
+ >
+ >
+ customerUserErrors: Array<
+ { __typename?: 'CustomerUserError' } & Pick<
+ CustomerUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ }
+ >
+}
+
+export type CustomerCreateMutationVariables = Exact<{
+ input: CustomerCreateInput
+}>
+
+export type CustomerCreateMutation = { __typename?: 'Mutation' } & {
+ customerCreate?: Maybe<
+ { __typename?: 'CustomerCreatePayload' } & {
+ customerUserErrors: Array<
+ { __typename?: 'CustomerUserError' } & Pick<
+ CustomerUserError,
+ 'code' | 'field' | 'message'
+ >
+ >
+ customer?: Maybe<{ __typename?: 'Customer' } & Pick>
+ }
+ >
+}
+
+export type GetSiteCollectionsQueryVariables = Exact<{
first: Scalars['Int']
}>
-export type Unnamed_1_Query = { __typename?: 'QueryRoot' } & {
- pages: { __typename?: 'PageConnection' } & {
+export type GetSiteCollectionsQuery = { __typename?: 'QueryRoot' } & {
+ collections: { __typename?: 'CollectionConnection' } & {
edges: Array<
- { __typename?: 'PageEdge' } & {
- node: { __typename?: 'Page' } & Pick<
- Page,
- 'id' | 'title' | 'handle' | 'body' | 'bodySummary' | 'url'
+ { __typename?: 'CollectionEdge' } & {
+ node: { __typename?: 'Collection' } & Pick<
+ Collection,
+ 'id' | 'title' | 'handle'
>
}
>
}
}
+
+export type GetAllPagesQueryVariables = Exact<{
+ first?: Maybe
+}>
+
+export type GetAllPagesQuery = { __typename?: 'QueryRoot' } & {
+ pages: { __typename?: 'PageConnection' } & {
+ edges: Array<
+ { __typename?: 'PageEdge' } & {
+ node: { __typename?: 'Page' } & Pick
+ }
+ >
+ }
+}
+
+export type GetAllProductVendorsQueryVariables = Exact<{
+ first?: Maybe
+ cursor?: Maybe
+}>
+
+export type GetAllProductVendorsQuery = { __typename?: 'QueryRoot' } & {
+ products: { __typename?: 'ProductConnection' } & {
+ pageInfo: { __typename?: 'PageInfo' } & Pick<
+ PageInfo,
+ 'hasNextPage' | 'hasPreviousPage'
+ >
+ edges: Array<
+ { __typename?: 'ProductEdge' } & Pick & {
+ node: { __typename?: 'Product' } & Pick
+ }
+ >
+ }
+}
+
+export type GetAllProductPathsQueryVariables = Exact<{
+ first?: Maybe
+ cursor?: Maybe
+}>
+
+export type GetAllProductPathsQuery = { __typename?: 'QueryRoot' } & {
+ products: { __typename?: 'ProductConnection' } & {
+ pageInfo: { __typename?: 'PageInfo' } & Pick<
+ PageInfo,
+ 'hasNextPage' | 'hasPreviousPage'
+ >
+ edges: Array<
+ { __typename?: 'ProductEdge' } & Pick & {
+ node: { __typename?: 'Product' } & Pick
+ }
+ >
+ }
+}
+
+export type ProductConnectionFragment = { __typename?: 'ProductConnection' } & {
+ pageInfo: { __typename?: 'PageInfo' } & Pick<
+ PageInfo,
+ 'hasNextPage' | 'hasPreviousPage'
+ >
+ edges: Array<
+ { __typename?: 'ProductEdge' } & {
+ node: { __typename?: 'Product' } & Pick<
+ Product,
+ 'id' | 'title' | 'vendor' | 'handle'
+ > & {
+ priceRange: { __typename?: 'ProductPriceRange' } & {
+ minVariantPrice: { __typename?: 'MoneyV2' } & Pick<
+ MoneyV2,
+ 'amount' | 'currencyCode'
+ >
+ }
+ images: { __typename?: 'ImageConnection' } & {
+ pageInfo: { __typename?: 'PageInfo' } & Pick<
+ PageInfo,
+ 'hasNextPage' | 'hasPreviousPage'
+ >
+ edges: Array<
+ { __typename?: 'ImageEdge' } & {
+ node: { __typename?: 'Image' } & Pick<
+ Image,
+ 'originalSrc' | 'altText' | 'width' | 'height'
+ >
+ }
+ >
+ }
+ }
+ }
+ >
+}
+
+export type GetAllProductsQueryVariables = Exact<{
+ first?: Maybe
+ query?: Maybe
+ sortKey?: Maybe
+ reverse?: Maybe
+}>
+
+export type GetAllProductsQuery = { __typename?: 'QueryRoot' } & {
+ products: { __typename?: 'ProductConnection' } & ProductConnectionFragment
+}
+
+export type CheckoutDetailsFragment = { __typename?: 'Checkout' } & Pick<
+ Checkout,
+ 'id' | 'webUrl' | 'completedAt' | 'createdAt' | 'taxesIncluded'
+> & {
+ subtotalPriceV2: { __typename?: 'MoneyV2' } & Pick<
+ MoneyV2,
+ 'amount' | 'currencyCode'
+ >
+ totalTaxV2: { __typename?: 'MoneyV2' } & Pick<
+ MoneyV2,
+ 'amount' | 'currencyCode'
+ >
+ totalPriceV2: { __typename?: 'MoneyV2' } & Pick<
+ MoneyV2,
+ 'amount' | 'currencyCode'
+ >
+ lineItems: { __typename?: 'CheckoutLineItemConnection' } & {
+ pageInfo: { __typename?: 'PageInfo' } & Pick<
+ PageInfo,
+ 'hasNextPage' | 'hasPreviousPage'
+ >
+ edges: Array<
+ { __typename?: 'CheckoutLineItemEdge' } & {
+ node: { __typename?: 'CheckoutLineItem' } & Pick<
+ CheckoutLineItem,
+ 'id' | 'title' | 'quantity'
+ > & {
+ variant?: Maybe<
+ { __typename?: 'ProductVariant' } & Pick<
+ ProductVariant,
+ 'id' | 'sku' | 'title'
+ > & {
+ image?: Maybe<
+ { __typename?: 'Image' } & Pick<
+ Image,
+ 'originalSrc' | 'altText' | 'width' | 'height'
+ >
+ >
+ priceV2: { __typename?: 'MoneyV2' } & Pick<
+ MoneyV2,
+ 'amount' | 'currencyCode'
+ >
+ compareAtPriceV2?: Maybe<
+ { __typename?: 'MoneyV2' } & Pick<
+ MoneyV2,
+ 'amount' | 'currencyCode'
+ >
+ >
+ product: { __typename?: 'Product' } & Pick<
+ Product,
+ 'handle'
+ >
+ }
+ >
+ }
+ }
+ >
+ }
+ }
+
+export type GetCheckoutQueryVariables = Exact<{
+ checkoutId: Scalars['ID']
+}>
+
+export type GetCheckoutQuery = { __typename?: 'QueryRoot' } & {
+ node?: Maybe<
+ | { __typename?: 'AppliedGiftCard' }
+ | { __typename?: 'Article' }
+ | { __typename?: 'Blog' }
+ | ({ __typename?: 'Checkout' } & CheckoutDetailsFragment)
+ | { __typename?: 'CheckoutLineItem' }
+ | { __typename?: 'Collection' }
+ | { __typename?: 'Comment' }
+ | { __typename?: 'ExternalVideo' }
+ | { __typename?: 'MailingAddress' }
+ | { __typename?: 'MediaImage' }
+ | { __typename?: 'Metafield' }
+ | { __typename?: 'Model3d' }
+ | { __typename?: 'Order' }
+ | { __typename?: 'Page' }
+ | { __typename?: 'Payment' }
+ | { __typename?: 'Product' }
+ | { __typename?: 'ProductOption' }
+ | { __typename?: 'ProductVariant' }
+ | { __typename?: 'ShopPolicy' }
+ | { __typename?: 'Video' }
+ >
+}
+
+export type GetProductsFromCollectionQueryVariables = Exact<{
+ categoryId: Scalars['ID']
+ first?: Maybe
+ sortKey?: Maybe
+ reverse?: Maybe
+}>
+
+export type GetProductsFromCollectionQuery = { __typename?: 'QueryRoot' } & {
+ node?: Maybe<
+ | ({ __typename?: 'AppliedGiftCard' } & Pick)
+ | ({ __typename?: 'Article' } & Pick)
+ | ({ __typename?: 'Blog' } & Pick)
+ | ({ __typename?: 'Checkout' } & Pick)
+ | ({ __typename?: 'CheckoutLineItem' } & Pick)
+ | ({ __typename?: 'Collection' } & Pick & {
+ products: {
+ __typename?: 'ProductConnection'
+ } & ProductConnectionFragment
+ })
+ | ({ __typename?: 'Comment' } & Pick)
+ | ({ __typename?: 'ExternalVideo' } & Pick)
+ | ({ __typename?: 'MailingAddress' } & Pick)
+ | ({ __typename?: 'MediaImage' } & Pick)
+ | ({ __typename?: 'Metafield' } & Pick)
+ | ({ __typename?: 'Model3d' } & Pick)
+ | ({ __typename?: 'Order' } & Pick)
+ | ({ __typename?: 'Page' } & Pick)
+ | ({ __typename?: 'Payment' } & Pick)
+ | ({ __typename?: 'Product' } & Pick)
+ | ({ __typename?: 'ProductOption' } & Pick)
+ | ({ __typename?: 'ProductVariant' } & Pick)
+ | ({ __typename?: 'ShopPolicy' } & Pick)
+ | ({ __typename?: 'Video' } & Pick