Skip to content

src/smoke-test.ts

71 lines · 1.9 KB · TypeScript
Raw
import {
	DEFAULT_ZOOM_CLIENT_ID_SECRET,
	DEFAULT_ZOOM_S2S_CLIENT_SECRET,
	ZOOM_CLIENT_ID_SETUP_URL,
	ZOOM_OAUTH_CONNECT_URL,
	ZOOM_S2S_CLIENT_SECRET_SETUP_URL,
	getCurrentUser,
	pickAuthInput,
	resolveZoomAuth,
} from './core.ts'
import { buildMeetingBody } from './shape.ts'

/**
 * Local helper checks plus an optional live `/users/me` read.
 *
 * Without credentials this returns `{ ok: true, live: false }` and the
 * prefilled connect / secret URLs. After OAuth or S2S secrets exist it
 * reads the current user and returns `{ live: true }` without tokens.
 *
 * @example
 * import smokeTest from 'kody:@kody/zoom/smoke-test'
 * export default async function main() {
 *   return await smokeTest()
 * }
 */
export default async function smokeTest(params: Record<string, unknown> = {}) {
	const authInput = pickAuthInput(params)
	const resolved = resolveZoomAuth(authInput)
	const createPreview = buildMeetingBody({
		topic: 'Example meeting',
		type: 2,
		start_time: '2030-01-15T17:00:00',
		duration: 30,
		timezone: 'UTC',
	})

	const setup = {
		oauthConnectUrl: ZOOM_OAUTH_CONNECT_URL,
		clientIdSetupUrl: ZOOM_CLIENT_ID_SETUP_URL,
		clientSecretSetupUrl: ZOOM_S2S_CLIENT_SECRET_SETUP_URL,
		s2sAccountId:
			'Pass accountId (the plain Zoom account ID, not a secret) with auth: "s2s".',
		s2sSecrets: {
			clientId: DEFAULT_ZOOM_CLIENT_ID_SECRET,
			clientSecret: DEFAULT_ZOOM_S2S_CLIENT_SECRET,
		},
	}

	if (params.live !== true) {
		return {
			ok: true,
			live: false,
			auth: resolved,
			createPreview,
			setup,
			hint: 'Pass live: true after connecting OAuth (or saving S2S secrets and passing accountId) to read /users/me. Never create a live meeting from this smoke test.',
		}
	}

	const user = await getCurrentUser(authInput)
	return {
		ok: true,
		live: true,
		auth: user.auth,
		hasUserId: Boolean(user.id),
		hasEmail: Boolean(user.email),
		displayName: user.displayName,
		createPreview,
		setup,
	}
}