commerce/framework/aquilacms/customer/get-customer-id.ts
Gérard Le Cloerec 94861a922a (feat): create aquilacms provider
(style): replace all bigcommerce name by aquilacms
2021-04-07 08:45:24 +02:00

35 lines
663 B
TypeScript

import { GetCustomerIdQuery } from '../schema'
import { AquilacmsConfig, getConfig } from '../api'
export const getCustomerIdQuery = /* GraphQL */ `
query getCustomerId {
customer {
entityId
}
}
`
async function getCustomerId({
customerToken,
config,
}: {
customerToken: string
config?: AquilacmsConfig
}): 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