Updated swell-js usage

This commit is contained in:
Luis Alvarez 2021-08-27 18:33:07 -05:00
parent e8f51a4f01
commit 412d6f3b02
4 changed files with 12 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import { swellConfig } from '../..' import swell from '../../swell'
const fetchApi = async (query: string, method: string, variables: [] = []) => { const fetchApi = async (query: string, method: string, variables: [] = []) => {
const { swell } = swellConfig
return swell[query][method](...variables) return swell[query][method](...variables)
} }
export default fetchApi export default fetchApi

View File

@ -1,11 +1,9 @@
import { Fetcher } from '@commerce/utils/types' import { Fetcher } from '@commerce/utils/types'
import { handleFetchResponse } from './utils'
import { swellConfig } from './index'
import { CommerceError } from '@commerce/utils/errors' import { CommerceError } from '@commerce/utils/errors'
import { handleFetchResponse } from './utils'
import swell from './swell'
const fetcher: Fetcher = async ({ method = 'get', variables, query }) => { const fetcher: Fetcher = async ({ method = 'get', variables, query }) => {
const { swell } = swellConfig
async function callSwell() { async function callSwell() {
if (Array.isArray(variables)) { if (Array.isArray(variables)) {
const arg1 = variables[0] const arg1 = variables[0]

View File

@ -1,10 +1,5 @@
import swell from 'swell-js'
import { Provider } from '@commerce' import { Provider } from '@commerce'
import { import { SWELL_CHECKOUT_ID_COOKIE } from './const'
SWELL_CHECKOUT_ID_COOKIE,
SWELL_STORE_ID,
SWELL_PUBLIC_KEY,
} from './const'
import { handler as useCart } from './cart/use-cart' import { handler as useCart } from './cart/use-cart'
import { handler as useAddItem } from './cart/use-add-item' 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 { handler as useSignup } from './auth/use-signup'
import fetcher from './fetcher' import fetcher from './fetcher'
import swell from './swell'
swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY)
export const swellProvider: Provider & { swell: any } = { export const swellProvider: Provider & { swell: any } = {
locale: 'en-us', locale: 'en-us',

6
framework/swell/swell.ts Normal file
View File

@ -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