Skip to content
← Public packages

@kentcdodds/fly

Manage Fly.io apps, Machines, logs, and metrics.

src/smoke-test.ts

30 lines · 1.2 KB · TypeScript
import { listApps } from './apps.ts'
import { listOrganizations } from './organizations.ts'
import machineCount from './machine-count.ts'
import type { FlySmokeTestInput } from './types.ts'

/**
 * Run a read-only Fly.io auth smoke test (GraphQL orgs + Machines REST apps/machines).
 * @returns Organization sample, apps sample, and optional machine count breakdown.
 * @example
 * import smokeTest from 'kody:@kentcdodds/fly/smoke-test'
 * const result = await smokeTest()
 * // => { ok: true, organizationCount: 1, appCount: 12, machineCount: 55, ... }
 */
export default async function smokeTest(params: FlySmokeTestInput = {}) {
	const organizations = await listOrganizations({ first: 10 })
	const apps = await listApps({ organizationSlug: 'personal' })
	const machines =
		params.includeMachines === false
			? null
			: await machineCount({ organizationSlug: 'personal', maxPages: 1 })
	return {
		ok: true,
		organizationCount: organizations.organizations.length,
		organizations: organizations.organizations,
		appCount: apps.count,
		appsSample: apps.apps.slice(0, 5).map((app) => ({ name: app.name, status: app.status })),
		machineCount: machines?.count ?? null,
		byState: machines?.byState ?? null,
	}
}