From 412d6f3b02b179d80f93c1e131a653a1b2e4583a Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Fri, 27 Aug 2021 18:33:07 -0500 Subject: [PATCH] Updated swell-js usage --- framework/swell/api/utils/fetch-swell-api.ts | 4 ++-- framework/swell/fetcher.ts | 6 ++---- framework/swell/provider.ts | 10 ++-------- framework/swell/swell.ts | 6 ++++++ 4 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 framework/swell/swell.ts diff --git a/framework/swell/api/utils/fetch-swell-api.ts b/framework/swell/api/utils/fetch-swell-api.ts index 65caed763..83055c5c0 100644 --- a/framework/swell/api/utils/fetch-swell-api.ts +++ b/framework/swell/api/utils/fetch-swell-api.ts @@ -1,7 +1,7 @@ -import { swellConfig } from '../..' +import swell from '../../swell' const fetchApi = async (query: string, method: string, variables: [] = []) => { - const { swell } = swellConfig return swell[query][method](...variables) } + export default fetchApi diff --git a/framework/swell/fetcher.ts b/framework/swell/fetcher.ts index f18dcf667..655e4da25 100644 --- a/framework/swell/fetcher.ts +++ b/framework/swell/fetcher.ts @@ -1,11 +1,9 @@ import { Fetcher } from '@commerce/utils/types' -import { handleFetchResponse } from './utils' -import { swellConfig } from './index' import { CommerceError } from '@commerce/utils/errors' +import { handleFetchResponse } from './utils' +import swell from './swell' const fetcher: Fetcher = async ({ method = 'get', variables, query }) => { - const { swell } = swellConfig - async function callSwell() { if (Array.isArray(variables)) { const arg1 = variables[0] diff --git a/framework/swell/provider.ts b/framework/swell/provider.ts index 1b221c05f..062f1c32c 100644 --- a/framework/swell/provider.ts +++ b/framework/swell/provider.ts @@ -1,10 +1,5 @@ -import swell from 'swell-js' import { Provider } from '@commerce' -import { - SWELL_CHECKOUT_ID_COOKIE, - SWELL_STORE_ID, - SWELL_PUBLIC_KEY, -} from './const' +import { SWELL_CHECKOUT_ID_COOKIE } from './const' import { handler as useCart } from './cart/use-cart' import { handler as useAddItem } from './cart/use-add-item' @@ -19,8 +14,7 @@ import { handler as useLogout } from './auth/use-logout' import { handler as useSignup } from './auth/use-signup' import fetcher from './fetcher' - -swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY) +import swell from './swell' export const swellProvider: Provider & { swell: any } = { locale: 'en-us', diff --git a/framework/swell/swell.ts b/framework/swell/swell.ts new file mode 100644 index 000000000..d73bceb72 --- /dev/null +++ b/framework/swell/swell.ts @@ -0,0 +1,6 @@ +import swell from 'swell-js' +import { SWELL_STORE_ID, SWELL_PUBLIC_KEY } from './const' + +swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY) + +export default swell