mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 19:21:23 +00:00
merge main (#1)
* Update README.md to include information on how to add a custom provider (#250) * Update README.md * Updated commerce readme Co-authored-by: Luis Alvarez D <luis@vercel.com> * Remove unused provider config (#459) * Updated core types for commerce provider * Updated bigcommerce provider * Added util method for provider creation * Removed unrequired code from saleor * Updated shopify provider * Updated providers and local setup * Updated saleor setup * Updated swell * Updated vendure * Updated swell-js usage * Removed unrequired import from saleor Co-authored-by: Isiko Saidiali <54436062+SaidiAli@users.noreply.github.com> Co-authored-by: Luis Alvarez D <luis@vercel.com>
This commit is contained in:
committed by
GitHub
parent
0e7e7b7d5f
commit
abaf7220dc
@@ -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
|
||||
|
@@ -4,8 +4,6 @@ export const SWELL_CHECKOUT_URL_COOKIE = 'swell_checkoutUrl'
|
||||
|
||||
export const SWELL_CUSTOMER_TOKEN_COOKIE = 'swell_customerToken'
|
||||
|
||||
export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SWELL_STORE_DOMAIN
|
||||
|
||||
export const SWELL_COOKIE_EXPIRE = 30
|
||||
|
||||
export const SWELL_STORE_ID = process.env.NEXT_PUBLIC_SWELL_STORE_ID
|
||||
|
@@ -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]
|
||||
|
@@ -1,47 +1,9 @@
|
||||
import * as React from 'react'
|
||||
import swell from 'swell-js'
|
||||
import { ReactNode } from 'react'
|
||||
|
||||
import {
|
||||
CommerceConfig,
|
||||
CommerceProvider as CoreCommerceProvider,
|
||||
useCommerce as useCoreCommerce,
|
||||
} from '@commerce'
|
||||
|
||||
import { getCommerceProvider, useCommerce as useCoreCommerce } from '@commerce'
|
||||
import { swellProvider, SwellProvider } from './provider'
|
||||
import {
|
||||
SWELL_CHECKOUT_ID_COOKIE,
|
||||
SWELL_STORE_ID,
|
||||
SWELL_PUBLIC_KEY,
|
||||
} from './const'
|
||||
swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY)
|
||||
|
||||
export { swellProvider }
|
||||
export type { SwellProvider }
|
||||
|
||||
export const swellConfig: any = {
|
||||
locale: 'en-us',
|
||||
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
|
||||
swell,
|
||||
}
|
||||
export const CommerceProvider = getCommerceProvider(swellProvider)
|
||||
|
||||
export type SwellConfig = Partial<CommerceConfig>
|
||||
|
||||
export type SwellProps = {
|
||||
children?: ReactNode
|
||||
locale: string
|
||||
} & SwellConfig
|
||||
|
||||
export function CommerceProvider({ children, ...config }: SwellProps) {
|
||||
return (
|
||||
<CoreCommerceProvider
|
||||
// TODO: Fix this type
|
||||
provider={swellProvider as any}
|
||||
config={{ ...swellConfig, ...config }}
|
||||
>
|
||||
{children}
|
||||
</CoreCommerceProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useCommerce = () => useCoreCommerce()
|
||||
export const useCommerce = () => useCoreCommerce<SwellProvider>()
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { Provider } from '@commerce'
|
||||
|
||||
import { SWELL_CHECKOUT_URL_COOKIE, STORE_DOMAIN } 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'
|
||||
@@ -15,11 +14,12 @@ import { handler as useLogout } from './auth/use-logout'
|
||||
import { handler as useSignup } from './auth/use-signup'
|
||||
|
||||
import fetcher from './fetcher'
|
||||
import swell from './swell'
|
||||
|
||||
export const swellProvider: Provider = {
|
||||
export const swellProvider: Provider & { swell: any } = {
|
||||
locale: 'en-us',
|
||||
cartCookie: SWELL_CHECKOUT_URL_COOKIE,
|
||||
// storeDomain: STORE_DOMAIN,
|
||||
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
|
||||
swell,
|
||||
fetcher,
|
||||
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
|
||||
customer: { useCustomer },
|
||||
|
6
framework/swell/swell.ts
Normal file
6
framework/swell/swell.ts
Normal 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
|
Reference in New Issue
Block a user