1
0
mirror of https://github.com/vercel/commerce.git synced 2025-07-24 02:31:24 +00:00
Files
.vscode
assets
components
config
framework
bigcommerce
api
cart
catalog
customers
handlers
index.ts
login.ts
logout.ts
signup.ts
definitions
fragments
utils
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/customers/index.ts
2020-12-29 19:14:49 -05:00

47 lines
1.1 KiB
TypeScript

import createApiHandler, {
BigcommerceApiHandler,
BigcommerceHandler,
} from '../utils/create-api-handler'
import isAllowedMethod from '../utils/is-allowed-method'
import { BigcommerceApiError } from '../utils/errors'
import getLoggedInCustomer, {
Customer,
} from './handlers/get-logged-in-customer'
export type { Customer }
export type CustomerData = {
customer: Customer
}
export type CustomersHandlers = {
getLoggedInCustomer: BigcommerceHandler<CustomerData>
}
const METHODS = ['GET']
const customersApi: BigcommerceApiHandler<
CustomerData,
CustomersHandlers
> = async (req, res, config, handlers) => {
if (!isAllowedMethod(req, res, METHODS)) return
try {
const body = null
return await handlers['getLoggedInCustomer']({ req, res, config, body })
} catch (error) {
console.error(error)
const message =
error instanceof BigcommerceApiError
? 'An unexpected error ocurred with the Bigcommerce API'
: 'An unexpected error ocurred'
res.status(500).json({ data: null, errors: [{ message }] })
}
}
const handlers = { getLoggedInCustomer }
export default createApiHandler(customersApi, handlers, {})