4
0
forked from crowetic/commerce
commerce/lib/bigcommerce/api/operations/get-customer-id.ts
2020-10-26 15:23:19 -05:00

35 lines
677 B
TypeScript

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