import { parseAuth } from './auth.ts'
import { zendeskRequest } from './client.ts'
import { mapMe } from './models.ts'
import type { ZendeskAuthInput, ZendeskMe } from './types.ts'
import { requireRecord } from './types.ts'
/**
* Return the connected Zendesk agent without email.
* @example
* import getMe from 'kody:@kody/zendesk/me'
* const me = await getMe({ subdomain: 'acme' })
*/
export async function getMe(input: ZendeskAuthInput = {}): Promise<ZendeskMe> {
const result = await zendeskRequest<unknown>({
...input,
operation: 'me.read',
path: '/users/me',
})
if ('dryRun' in result) {
throw new Error('GET /users/me does not support dryRun.')
}
return mapMe(result.data)
}
/**
* Return the connected Zendesk agent without email.
* @example
* import getMe from 'kody:@kody/zendesk/me'
* const me = await getMe({ integrationName: 'zendesk-work' })
*/
export default async function meEntrypoint(
params: ZendeskAuthInput & Record<string, unknown> = {},
) {
return getMe(parseAuth(requireRecord(params, 'me')))
}