mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
setup custom fetcher and auth hooks
This commit is contained in:
@@ -22,23 +22,23 @@ if (!API_TOKEN) {
|
||||
|
||||
import fetchGraphqlApi from './utils/fetch-graphql-api'
|
||||
|
||||
export interface ShopifyConfig extends CommerceAPIConfig {}
|
||||
export interface SwellConfig extends CommerceAPIConfig {}
|
||||
|
||||
export class Config {
|
||||
private config: ShopifyConfig
|
||||
private config: SwellConfig
|
||||
|
||||
constructor(config: ShopifyConfig) {
|
||||
constructor(config: SwellConfig) {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
getConfig(userConfig: Partial<ShopifyConfig> = {}) {
|
||||
return Object.entries(userConfig).reduce<ShopifyConfig>(
|
||||
getConfig(userConfig: Partial<SwellConfig> = {}) {
|
||||
return Object.entries(userConfig).reduce<SwellConfig>(
|
||||
(cfg, [key, value]) => Object.assign(cfg, { [key]: value }),
|
||||
{ ...this.config }
|
||||
)
|
||||
}
|
||||
|
||||
setConfig(newConfig: Partial<ShopifyConfig>) {
|
||||
setConfig(newConfig: Partial<SwellConfig>) {
|
||||
Object.assign(this.config, newConfig)
|
||||
}
|
||||
}
|
||||
@@ -53,10 +53,10 @@ const config = new Config({
|
||||
customerCookie: SHOPIFY_CUSTOMER_TOKEN_COOKIE,
|
||||
})
|
||||
|
||||
export function getConfig(userConfig?: Partial<ShopifyConfig>) {
|
||||
export function getConfig(userConfig?: Partial<SwellConfig>) {
|
||||
return config.getConfig(userConfig)
|
||||
}
|
||||
|
||||
export function setConfig(newConfig: Partial<ShopifyConfig>) {
|
||||
export function setConfig(newConfig: Partial<SwellConfig>) {
|
||||
return config.setConfig(newConfig)
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import Client from 'shopify-buy'
|
||||
import { ShopifyConfig } from '../index'
|
||||
import { SwellConfig } from '../index'
|
||||
|
||||
type Options = {
|
||||
config: ShopifyConfig
|
||||
config: SwellConfig
|
||||
}
|
||||
|
||||
const getAllCollections = async (options: Options) => {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Page } from '../../schema'
|
||||
import { ShopifyConfig, getConfig } from '..'
|
||||
import { SwellConfig, getConfig } from '..'
|
||||
|
||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||
|
||||
@@ -15,7 +15,7 @@ async function getPage({
|
||||
}: {
|
||||
url?: string
|
||||
variables: PageVariables
|
||||
config?: ShopifyConfig
|
||||
config?: SwellConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetPageResult> {
|
||||
config = getConfig(config)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
|
||||
import { ShopifyConfig, getConfig } from '..'
|
||||
import { SwellConfig, getConfig } from '..'
|
||||
|
||||
export type ShopifyApiHandler<
|
||||
T = any,
|
||||
@@ -8,7 +8,7 @@ export type ShopifyApiHandler<
|
||||
> = (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<ShopifyApiResponse<T>>,
|
||||
config: ShopifyConfig,
|
||||
config: SwellConfig,
|
||||
handlers: H,
|
||||
// Custom configs that may be used by a particular handler
|
||||
options: Options
|
||||
@@ -17,7 +17,7 @@ export type ShopifyApiHandler<
|
||||
export type ShopifyHandler<T = any, Body = null> = (options: {
|
||||
req: NextApiRequest
|
||||
res: NextApiResponse<ShopifyApiResponse<T>>
|
||||
config: ShopifyConfig
|
||||
config: SwellConfig
|
||||
body: Body
|
||||
}) => void | Promise<void>
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function createApiHandler<
|
||||
operations,
|
||||
options,
|
||||
}: {
|
||||
config?: ShopifyConfig
|
||||
config?: SwellConfig
|
||||
operations?: Partial<H>
|
||||
options?: Options extends {} ? Partial<Options> : never
|
||||
} = {}): NextApiHandler {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ProductEdge } from '../../schema'
|
||||
import { ShopifyConfig } from '..'
|
||||
import { SwellConfig } from '..'
|
||||
|
||||
const fetchAllProducts = async ({
|
||||
config,
|
||||
@@ -8,7 +8,7 @@ const fetchAllProducts = async ({
|
||||
acc = [],
|
||||
cursor,
|
||||
}: {
|
||||
config: ShopifyConfig
|
||||
config: SwellConfig
|
||||
query: string
|
||||
acc?: ProductEdge[]
|
||||
variables?: any
|
||||
|
Reference in New Issue
Block a user