Skip to content
← Public packages

@kentcdodds/raycast

Raycast launcher: stored execute commands via webhooks (canonical; do not use raycast-shortcuts).

src/setup-launcher-token.ts

34 lines · 1.1 KB · TypeScript
import { storeLauncherToken } from './launcher-auth.ts'

function randomToken() {
	const bytes = new Uint8Array(32)
	crypto.getRandomValues(bytes)
	let out = ''
	for (const b of bytes) out += b.toString(16).padStart(2, '0')
	return `kody_raycast_${out}`
}

/**
 * Mint (or rotate) the Raycast launcher bearer token.
 * Stores only a SHA-256 hash in package storage. Returns the plaintext once
 * so an agent can write ~/.config/kody/raycast.json on Kent's Mac — never paste
 * the token into chat.
 *
 * @returns token (once), hint, and hosted API base path
 *
 * @example
 * import setupLauncherToken from 'kody:@kentcdodds/raycast/setup-launcher-token'
 * const { token } = await setupLauncherToken()
 */
export default async function setupLauncherToken(input: { token?: string } = {}) {
	const token = (input.token?.trim() || randomToken()).trim()
	const stored = await storeLauncherToken(token)
	return {
		ok: true as const,
		token,
		hint: stored.hint,
		apiBaseUrl: 'https://kentcdodds.kody.run/packages/raycast',
		configPath: '~/.config/kody/raycast.json',
		note: 'Write token to configPath on the Mac; do not paste token into chat.',
	}
}