mirror of
https://github.com/vercel/commerce.git
synced 2025-05-16 22:46:58 +00:00
Update cookies & packages to Next 13
This commit is contained in:
parent
5ca9ebb3cd
commit
0d553fe52f
@ -58,7 +58,7 @@
|
||||
"uuidv4": "^6.2.13"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -73,7 +73,7 @@
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"@types/react": "^18.0.14",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -8,8 +8,8 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
config,
|
||||
}) => {
|
||||
const { cookies } = req
|
||||
const cartId = cookies.get(config.cartCookie)
|
||||
const customerToken = cookies.get(config.customerCookie)
|
||||
const cartId = cookies.get(config.cartCookie)?.value
|
||||
const customerToken = cookies.get(config.customerCookie)?.value
|
||||
|
||||
if (!cartId) {
|
||||
return { redirectTo: '/cart' }
|
||||
|
@ -27,7 +27,7 @@ export type Customer = NonNullable<GetLoggedInCustomerQuery['customer']>
|
||||
|
||||
const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] =
|
||||
async ({ req, config }) => {
|
||||
const token = req.cookies.get(config.customerCookie)
|
||||
const token = req.cookies.get(config.customerCookie)?.value
|
||||
|
||||
if (token) {
|
||||
const { data } = await config.fetch<GetLoggedInCustomerQuery>(
|
||||
|
@ -55,7 +55,7 @@
|
||||
"zod": "^3.19.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -68,7 +68,7 @@
|
||||
"@types/node-fetch": "2.6.2",
|
||||
"@types/react": "^18.0.14",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -29,7 +29,7 @@ const cartEndpoint: GetAPISchema<
|
||||
|
||||
let output
|
||||
const { cookies } = req
|
||||
const cartId = cookies.get(config.cartCookie)
|
||||
const cartId = cookies.get(config.cartCookie)?.value
|
||||
|
||||
// Return current cart info
|
||||
if (req.method === 'GET') {
|
||||
|
@ -22,7 +22,7 @@ const checkoutEndpoint: GetAPISchema<
|
||||
})
|
||||
|
||||
const { cookies } = req
|
||||
const cartId = cookies.get(config.cartCookie)!
|
||||
const cartId = cookies.get(config.cartCookie)?.value
|
||||
const input = await getInput(req)
|
||||
|
||||
// Get checkout
|
||||
|
@ -33,7 +33,7 @@ const customerShippingEndpoint: GetAPISchema<
|
||||
const { cookies } = req
|
||||
|
||||
// Cart id might be usefull for anonymous shopping
|
||||
const cartId = cookies.get(config.cartCookie)
|
||||
const cartId = cookies.get(config.cartCookie)?.value
|
||||
|
||||
// Return customer addresses
|
||||
if (req.method === 'GET') {
|
||||
|
@ -31,7 +31,7 @@ const customerCardEndpoint: GetAPISchema<
|
||||
const { cookies } = req
|
||||
|
||||
// Cart id might be usefull for anonymous shopping
|
||||
const cartId = cookies.get(config.cartCookie)
|
||||
const cartId = cookies.get(config.cartCookie)?.value
|
||||
|
||||
// Create or add a card
|
||||
if (req.method === 'GET') {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { CustomerSchema } from '../../../types/customer'
|
||||
import type { GetAPISchema } from '../..'
|
||||
|
||||
import { z } from 'zod'
|
||||
import { parse } from '../../utils'
|
||||
import validateHandlers from '../../utils/validate-handlers'
|
||||
|
||||
@ -19,7 +19,14 @@ const customerEndpoint: GetAPISchema<
|
||||
const body = null
|
||||
const output = await handlers['getLoggedInCustomer']({ ...ctx, body })
|
||||
|
||||
return output ? parse(output, customerSchema) : { status: 204 }
|
||||
return output
|
||||
? parse(
|
||||
output,
|
||||
z.object({
|
||||
customer: customerSchema,
|
||||
})
|
||||
)
|
||||
: { status: 204 }
|
||||
}
|
||||
|
||||
export default customerEndpoint
|
||||
|
@ -18,7 +18,7 @@ const signupEndpoint: GetAPISchema<
|
||||
|
||||
const input = await getInput(req)
|
||||
const { cookies } = req
|
||||
const cartId = cookies.get(config.cartCookie)
|
||||
const cartId = cookies.get(config.cartCookie)?.value
|
||||
|
||||
const body = signupBodySchema.parse({ ...input, cartId })
|
||||
return handlers['signup']({ ...ctx, body })
|
||||
|
@ -28,7 +28,7 @@ const wishlistEndpoint: GetAPISchema<
|
||||
const { cookies } = req
|
||||
const input = await getInput(req)
|
||||
|
||||
const customerToken = cookies.get(config.customerCookie)
|
||||
const customerToken = cookies.get(config.customerCookie)?.value
|
||||
const products = new URL(req.url).searchParams.get('products')
|
||||
|
||||
// Return current wishlist info
|
||||
|
@ -55,7 +55,7 @@
|
||||
"lodash.debounce": "^4.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -71,7 +71,7 @@
|
||||
"@types/node": "^17.0.8",
|
||||
"@types/react": "^18.0.14",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -53,11 +53,12 @@
|
||||
"lodash.debounce": "^4.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.5",
|
||||
"@graphql-codegen/cli": "^2.7.0",
|
||||
"@graphql-codegen/schema-ast": "^2.4.1",
|
||||
"@graphql-codegen/typescript": "^2.4.2",
|
||||
@ -71,7 +72,7 @@
|
||||
"@types/react": "^18.0.14",
|
||||
"graphql": "^16.0.0",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -8,7 +8,8 @@ const removeItem: CartEndpoint['handlers']['removeItem'] = async ({
|
||||
body: { itemId },
|
||||
config,
|
||||
}) => {
|
||||
const encodedToken = req.cookies.get(config.customerCookie)
|
||||
const encodedToken = req.cookies.get(config.customerCookie)?.value
|
||||
|
||||
const token = encodedToken
|
||||
? Buffer.from(encodedToken, 'base64').toString('ascii')
|
||||
: null
|
||||
|
@ -8,7 +8,7 @@ const updateItem: CartEndpoint['handlers']['updateItem'] = async ({
|
||||
body: { itemId, item },
|
||||
config,
|
||||
}) => {
|
||||
const encodedToken = req.cookies.get(config.cartCookie)
|
||||
const encodedToken = req.cookies.get(config.cartCookie)?.value
|
||||
const token = encodedToken
|
||||
? Buffer.from(encodedToken, 'base64').toString('ascii')
|
||||
: null
|
||||
|
@ -19,7 +19,7 @@ export default class CookieHandler {
|
||||
this.config = config
|
||||
this.request = req
|
||||
|
||||
const encodedToken = req.cookies.get(config.customerCookie)
|
||||
const encodedToken = req.cookies.get(config.customerCookie)?.value
|
||||
const token = parseCookie(encodedToken)
|
||||
this.accessToken = token ? token.accessToken : null
|
||||
}
|
||||
@ -36,7 +36,7 @@ export default class CookieHandler {
|
||||
}
|
||||
isShopperCookieAnonymous() {
|
||||
const customerCookieKey = this.config.customerCookie
|
||||
const shopperCookie = this.request.cookies.get(customerCookieKey)
|
||||
const shopperCookie = this.request.cookies.get(customerCookieKey)?.value
|
||||
const shopperSession = parseCookie(shopperCookie)
|
||||
const isAnonymous = shopperSession?.customerAccount ? false : true
|
||||
return isAnonymous
|
||||
|
@ -50,7 +50,7 @@
|
||||
"@vercel/commerce": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -62,7 +62,7 @@
|
||||
"@types/react": "^18.0.14",
|
||||
"@types/node-fetch": "2.6.2",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -52,7 +52,7 @@
|
||||
"cookie": "^0.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -66,7 +66,7 @@
|
||||
"@types/cookie": "^0.4.1",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -10,7 +10,7 @@ const addItem: CartEndpoint['handlers']['addItem'] = async ({
|
||||
config: { restBuyerFetch, cartCookie, tokenCookie },
|
||||
}) => {
|
||||
// Get token
|
||||
let token = req.cookies.get(tokenCookie)
|
||||
let token = req.cookies.get(tokenCookie)?.value
|
||||
let headers: any = {}
|
||||
|
||||
// Create an order if it doesn't exist
|
||||
|
@ -16,7 +16,7 @@ const getCart: CartEndpoint['handlers']['getCart'] = async ({
|
||||
|
||||
try {
|
||||
// Get token
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
// Get cart & line items
|
||||
const [cart, { Items }] = await Promise.all([
|
||||
|
@ -7,7 +7,7 @@ const removeItem: CartEndpoint['handlers']['removeItem'] = async ({
|
||||
body: { cartId, itemId },
|
||||
config: { restBuyerFetch, tokenCookie },
|
||||
}) => {
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
// Remove the item to the order
|
||||
await restBuyerFetch(
|
||||
|
@ -9,7 +9,7 @@ const updateItem: CartEndpoint['handlers']['updateItem'] = async ({
|
||||
body: { cartId, itemId, item },
|
||||
config: { restBuyerFetch, tokenCookie },
|
||||
}) => {
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
// Store specs
|
||||
let specs: RawVariant['Specs'] = []
|
||||
|
@ -7,7 +7,7 @@ const getProducts: ProductsEndpoint['handlers']['getProducts'] = async ({
|
||||
body: { search, categoryId },
|
||||
config: { restBuyerFetch, tokenCookie },
|
||||
}) => {
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
//Use a dummy base as we only care about the relative path
|
||||
const url = new URL('/me/products', 'http://a')
|
||||
|
@ -5,7 +5,7 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
body: { cartId },
|
||||
config: { restBuyerFetch },
|
||||
}) => {
|
||||
const token = req.cookies.get('token')
|
||||
const token = req.cookies.get('token')?.value
|
||||
|
||||
// Register credit card
|
||||
const payments = await restBuyerFetch(
|
||||
|
@ -5,7 +5,7 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
|
||||
body: { cartId },
|
||||
config: { restBuyerFetch, tokenCookie },
|
||||
}) => {
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
// Submit order
|
||||
await restBuyerFetch('POST', `/orders/Outgoing/${cartId}/submit`, null, {
|
||||
|
@ -5,7 +5,7 @@ const addItem: CustomerAddressEndpoint['handlers']['addItem'] = async ({
|
||||
body: { item, cartId },
|
||||
config: { restBuyerFetch, tokenCookie },
|
||||
}) => {
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
// Register address
|
||||
const address = await restBuyerFetch('POST', `/me/addresses`, {
|
||||
|
@ -7,7 +7,7 @@ const addItem: CustomerCardEndpoint['handlers']['addItem'] = async ({
|
||||
config: { restBuyerFetch, tokenCookie },
|
||||
}) => {
|
||||
// Get token
|
||||
const token = req.cookies.get(tokenCookie)
|
||||
const token = req.cookies.get(tokenCookie)?.value
|
||||
|
||||
const [exp_month, exp_year] = item.cardExpireDate.split('/')
|
||||
const stripeToken = await fetch('https://api.stripe.com/v1/tokens', {
|
||||
|
@ -54,11 +54,12 @@
|
||||
"lodash.debounce": "^4.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.5",
|
||||
"@graphql-codegen/cli": "^2.7.0",
|
||||
"@graphql-codegen/schema-ast": "^2.4.1",
|
||||
"@graphql-codegen/typescript": "^2.4.2",
|
||||
@ -73,7 +74,7 @@
|
||||
"@types/react": "^18.0.14",
|
||||
"graphql": "^16.0.0",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -51,7 +51,7 @@
|
||||
"commerce-sdk": "^2.7.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -63,7 +63,7 @@
|
||||
"@types/react": "^18.0.14",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -54,11 +54,12 @@
|
||||
"lodash.debounce": "^4.0.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.5",
|
||||
"@graphql-codegen/cli": "2.7.0",
|
||||
"@graphql-codegen/schema-ast": "^2.4.1",
|
||||
"@graphql-codegen/typescript": "^2.6.0",
|
||||
@ -69,10 +70,10 @@
|
||||
"@types/js-cookie": "3.0.2",
|
||||
"@types/lodash.debounce": "^4.0.7",
|
||||
"@types/node": "^18.0.3",
|
||||
"@types/react": "^18.0.14",
|
||||
"@types/node-fetch": "2.6.2",
|
||||
"graphql": "^16.0.0",
|
||||
"@types/react": "^18.0.14",
|
||||
"dotenv": "^16.0.1",
|
||||
"graphql": "^16.0.0",
|
||||
"lint-staged": "^13.0.3",
|
||||
"next": "^12.2.1",
|
||||
"prettier": "^2.7.1",
|
||||
|
@ -11,15 +11,16 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
config,
|
||||
}) => {
|
||||
const { cookies } = req
|
||||
const checkoutUrl = cookies.get(SHOPIFY_CHECKOUT_URL_COOKIE)
|
||||
const customerCookie = cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE)
|
||||
const checkoutUrl = cookies.get(SHOPIFY_CHECKOUT_URL_COOKIE)?.value
|
||||
const customerCookie = cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE)?.value
|
||||
|
||||
if (customerCookie) {
|
||||
try {
|
||||
await config.fetch(associateCustomerWithCheckoutMutation, {
|
||||
variables: {
|
||||
checkoutId: cookies.get(SHOPIFY_CHECKOUT_ID_COOKIE),
|
||||
customerAccessToken: cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE),
|
||||
checkoutId: cookies.get(SHOPIFY_CHECKOUT_ID_COOKIE)?.value,
|
||||
customerAccessToken: cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE)
|
||||
?.value,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
|
@ -54,7 +54,7 @@
|
||||
"swr": "^1.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -68,7 +68,7 @@
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"@types/react": "^18.0.14",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -54,7 +54,7 @@
|
||||
"swell-js": "^4.0.0-next.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
@ -68,7 +68,7 @@
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"@types/react": "^18.0.14",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
@ -7,7 +7,7 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
req,
|
||||
}) => {
|
||||
const { cookies } = req
|
||||
const checkoutUrl = cookies.get(SWELL_CHECKOUT_URL_COOKIE)
|
||||
const checkoutUrl = cookies.get(SWELL_CHECKOUT_URL_COOKIE)?.value
|
||||
|
||||
if (checkoutUrl) {
|
||||
return { redirectTo: checkoutUrl }
|
||||
|
@ -52,11 +52,12 @@
|
||||
"@vercel/commerce": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12",
|
||||
"next": "^13",
|
||||
"react": "^18",
|
||||
"react-dom": "^18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.5",
|
||||
"@graphql-codegen/cli": "2.7.0",
|
||||
"@graphql-codegen/schema-ast": "^2.4.1",
|
||||
"@graphql-codegen/typescript": "^2.4.2",
|
||||
@ -69,7 +70,7 @@
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"graphql": "^16.0.0",
|
||||
"lint-staged": "^12.1.7",
|
||||
"next": "^12.0.8",
|
||||
"next": "^13.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
662
pnpm-lock.yaml
generated
662
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -59,7 +59,7 @@ const UserNav: React.FC<{
|
||||
)}
|
||||
{process.env.COMMERCE_WISHLIST_ENABLED && (
|
||||
<li className={s.item}>
|
||||
<Link href="/wishlist">
|
||||
<Link href="/wishlist" legacyBehavior>
|
||||
<a onClick={closeSidebarIfPresent} aria-label="Wishlist">
|
||||
<Heart />
|
||||
</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user