mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
normalizations & missing files
This commit is contained in:
1
framework/shopify/api/cart/index.ts
Normal file
1
framework/shopify/api/cart/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function () {}
|
1
framework/shopify/api/catalog/index.ts
Normal file
1
framework/shopify/api/catalog/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function () {}
|
1
framework/shopify/api/catalog/products.ts
Normal file
1
framework/shopify/api/catalog/products.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function () {}
|
103
framework/shopify/api/checkout/index.ts
Normal file
103
framework/shopify/api/checkout/index.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { CommerceAPIFetchOptions } from '@commerce/api'
|
||||
import {
|
||||
CheckoutCreateInput,
|
||||
CheckoutCreatePayload,
|
||||
Maybe,
|
||||
} from '@framework/schema'
|
||||
import { getProductQuery } from 'framework/bigcommerce/product/get-product'
|
||||
import Cookies from 'js-cookie'
|
||||
import { getConfig, ShopifyConfig } from '..'
|
||||
|
||||
const createCheckoutMutation = `
|
||||
mutation($input) {
|
||||
checkoutCreate(input: $input) {
|
||||
checkout {
|
||||
id
|
||||
webUrl
|
||||
lineItems(first: 100) {
|
||||
edges {
|
||||
node {
|
||||
title
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const getCheckoutQuery = `
|
||||
query {
|
||||
shop {
|
||||
name
|
||||
currencyCode
|
||||
checkout {
|
||||
id
|
||||
webUrl
|
||||
lineItems(first: 100) {
|
||||
edges {
|
||||
node {
|
||||
title
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const createCheckout = async (fetcher: any, input: CheckoutCreateInput) => {
|
||||
return await fetcher(createCheckoutMutation, {
|
||||
variables: {
|
||||
input,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const getCheckout = async (req: any, res: any, config: any): Promise<any> => {
|
||||
console.log(config)
|
||||
|
||||
return
|
||||
config = getConfig(config)
|
||||
|
||||
const { data: shop } = await config.fetch(getProductQuery)
|
||||
|
||||
const checkout = shop?.checkout
|
||||
const completedAt = checkout.completedAt
|
||||
|
||||
const checkoutId = Cookies.get('nextjs-commerce-shopify-token')
|
||||
|
||||
const checkoutCreateInput = {
|
||||
presentmentCurrencyCode: shop?.currencyCode,
|
||||
}
|
||||
|
||||
// we could have a cart id stored in session storage
|
||||
// user could be refreshing or navigating back and forthlet checkoutResource
|
||||
let checkoutCreatePayload: Maybe<CheckoutCreatePayload>
|
||||
|
||||
if (checkoutId) {
|
||||
checkoutCreatePayload = await createCheckout(
|
||||
config.fetch,
|
||||
checkoutCreateInput
|
||||
)
|
||||
const existingCheckout = checkoutCreatePayload?.checkout
|
||||
const completedAt = existingCheckout?.completedAt
|
||||
if (completedAt) {
|
||||
checkoutCreatePayload = await createCheckout(
|
||||
config.fetch,
|
||||
checkoutCreateInput
|
||||
)
|
||||
}
|
||||
} else {
|
||||
checkoutCreatePayload = await createCheckout(
|
||||
config.fetch,
|
||||
checkoutCreateInput
|
||||
)
|
||||
}
|
||||
|
||||
console.log(checkout)
|
||||
}
|
||||
|
||||
export default getCheckout
|
1
framework/shopify/api/customer.ts
Normal file
1
framework/shopify/api/customer.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function () {}
|
@@ -1,38 +0,0 @@
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import type { LoginHandlers } from '../login'
|
||||
|
||||
const loginHandler: LoginHandlers['login'] = async ({
|
||||
res,
|
||||
body: { email, password },
|
||||
config,
|
||||
}) => {
|
||||
if (!(email && password)) {
|
||||
return res.status(400).json({
|
||||
data: null,
|
||||
errors: [{ message: 'Invalid request' }],
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
} catch (error) {
|
||||
// Check if the email and password didn't match an existing account
|
||||
if (error instanceof FetcherError) {
|
||||
return res.status(401).json({
|
||||
data: null,
|
||||
errors: [
|
||||
{
|
||||
message:
|
||||
'Cannot find an account that matches the provided credentials',
|
||||
code: 'invalid_credentials',
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
res.status(200).json({ data: null })
|
||||
}
|
||||
|
||||
export default loginHandler
|
Reference in New Issue
Block a user