mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +00:00
33 lines
643 B
TypeScript
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
|