1
0
mirror of https://github.com/vercel/commerce.git synced 2025-07-25 19:21:23 +00:00
Files
.vscode
assets
components
config
framework
bigcommerce
api
cart
catalog
customers
definitions
fragments
utils
concat-cookie.ts
create-api-handler.ts
errors.ts
fetch-graphql-api.ts
fetch-store-api.ts
fetch.ts
filter-edges.ts
get-cart-cookie.ts
is-allowed-method.ts
parse-item.ts
set-product-locale-meta.ts
types.ts
wishlist
checkout.ts
index.ts
auth
cart
common
customer
lib
product
scripts
wishlist
.env.template
README.md
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
commerce
shopify
swell
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
commerce/framework/bigcommerce/api/utils/get-cart-cookie.ts
2020-12-29 19:14:49 -05:00

21 lines
526 B
TypeScript

import { serialize, CookieSerializeOptions } from 'cookie'
export default function getCartCookie(
name: string,
cartId?: string,
maxAge?: number
) {
const options: CookieSerializeOptions =
cartId && maxAge
? {
maxAge,
expires: new Date(Date.now() + maxAge * 1000),
secure: process.env.NODE_ENV === 'production',
path: '/',
sameSite: 'lax',
}
: { maxAge: -1, path: '/' } // Removes the cookie
return serialize(name, cartId || '', options)
}