commerce/providers/bigcommerce/api/utils/get-customer-id.ts
Loui Nissen-Petersen 03dcf96fb1 rename folder
2021-07-16 16:58:03 +02: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