Skip to content

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

Package listing

@kentcdodds/cursor

src/request.ts

36 lines · 1.1 KB · TypeScript
import { cursorRequestRaw } from './lib/client.ts'

export type CursorRequestParams = {
	path: string
	method?: string
	query?: Record<string, string | number | boolean | undefined | null>
	body?: unknown
	headers?: Record<string, string>
}

/**
 * Send a raw request to any api.cursor.com path (escape hatch for unwrapped APIs).
 *
 * @param params.path - API path (e.g. `/v1/models` or `/v0/private-workers`).
 * @param params.method - HTTP method; defaults to GET.
 * @returns Parsed JSON or text body plus HTTP status.
 * @example
 * import { cursorRequest } from 'kody:@kentcdodds/cursor/request'
 * const result = await cursorRequest({ path: '/v1/models' })
 * // => { status: 200, body: { items: [...] } }
 *
 * @see https://cursor.com/docs/api
 */
export async function cursorRequest(params: CursorRequestParams) {
	const result = await cursorRequestRaw({
		path: params.path,
		method: params.method,
		query: params.query,
		body: params.body,
		headers: params.headers,
	})
	return { status: result.status, body: result.body }
}

/** Default export: raw request escape hatch. */
export default cursorRequest