commerce/packages/kibocommerce/api/utils/get-customer-id.ts
2022-01-14 13:33:59 -05:00

27 lines
673 B
TypeScript

import type { KiboCommerceConfig } from '..'
import { getCustomerAccountQuery } from '../queries/get-customer-account-query'
async function getCustomerId({
customerToken,
config,
}: {
customerToken: string
config: KiboCommerceConfig
}): Promise<string | undefined> {
const token = customerToken ? Buffer.from(customerToken, 'base64').toString('ascii'): null;
const accessToken = token ? JSON.parse(token).accessToken : null;
const { data } = await config.fetch(
getCustomerAccountQuery,
undefined,
{
headers: {
'x-vol-user-claims': accessToken,
},
}
)
return data?.customerAccount?.id
}
export default getCustomerId