Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/intercom

src/me.ts

35 lines · 1.0 KB · TypeScript
import { parseAuth } from './auth.ts'
import { intercomRequest } from './client.ts'
import { mapMe } from './models.ts'
import type { IntercomAuthInput, IntercomMe } from './types.ts'
import { requireRecord } from './types.ts'

/**
 * Return the connected Intercom admin without email or workspace name.
 * @example
 * import getMe from 'kody:@kody/intercom/me'
 * const me = await getMe()
 */
export async function getMe(input: IntercomAuthInput = {}): Promise<IntercomMe> {
	const result = await intercomRequest<unknown>({
		...input,
		operation: 'me.read',
		path: '/me',
	})
	if ('dryRun' in result) {
		throw new Error('GET /me does not support dryRun.')
	}
	return mapMe(result.data)
}

/**
 * Return the connected Intercom admin without email or workspace name.
 * @example
 * import getMe from 'kody:@kody/intercom/me'
 * const me = await getMe({ integrationName: 'intercom-work' })
 */
export default async function meEntrypoint(
	params: IntercomAuthInput & Record<string, unknown> = {},
) {
	return getMe(parseAuth(requireRecord(params, 'me')))
}