commerce/packages/bigcommerce/api/utils/get-customer-id.ts
2022-01-13 17:19:27 -05:00

33 lines
643 B
TypeScript

import type { GetCustomerIdQuery } from '../../schema'
import type { BigcommerceConfig } from '../'
export const getCustomerIdQuery = /* GraphQL */ `
query getCustomerId {
customer {
entityId
}
}
`
async function getCustomerId({
customerToken,
config,
}: {
customerToken: string
config: BigcommerceConfig
}): Promise<string | undefined> {
const { data } = await config.fetch<GetCustomerIdQuery>(
getCustomerIdQuery,
undefined,
{
headers: {
cookie: `${config.customerCookie}=${customerToken}`,
},
}
)
return String(data?.customer?.entityId)
}
export default getCustomerId