mirror of
https://github.com/vercel/commerce.git
synced 2025-08-16 05:41:24 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
shopify
swell
api
auth
cart
common
customer
product
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
swell-js.d.ts
types.ts
vendure
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.json
yarn.lock
48 lines
1.0 KiB
TypeScript
48 lines
1.0 KiB
TypeScript
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 { 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 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()
|