Skip to content

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

Package listing

@kody/zendesk

src/scheduled-account-health.ts

27 lines · 937 B · TypeScript
import { getMe } from './me.ts'
import { listArticles } from './articles.ts'
import { listTickets } from './tickets.ts'
import { listUsers } from './users.ts'

/**
 * No-argument scheduled wrapper. Reads `/users/me` plus first-page counts
 * only — no writes. The `account-health` job is **disabled** by default.
 * @example
 * import scheduledAccountHealth from 'kody:@kody/zendesk/scheduled-account-health'
 * const snapshot = await scheduledAccountHealth()
 */
export default async function scheduledAccountHealth() {
	const [me, tickets, users, articles] = await Promise.all([
		getMe(),
		listTickets({ perPage: 5 }),
		listUsers({ perPage: 5 }),
		listArticles({ perPage: 5 }),
	])
	return {
		hasUserId: Boolean(me.id),
		role: me.role,
		ticketCount: tickets.pageInfo.count ?? tickets.items.length,
		userCount: users.pageInfo.count ?? users.items.length,
		articleCount: articles.pageInfo.count ?? articles.items.length,
	}
}