Skip to content
← Public packages

@kentcdodds/devin

Start, monitor, and manage Devin sessions, knowledge, playbooks, and schedules via the Devin v3 API

src/request.ts

50 lines · 1.2 KB · TypeScript
import {
	type DevinQuery,
	devinRequestRaw,
	resolveOrgId,
} from './lib/client.ts'

export {
	DevinApiError,
	DEVIN_BASE_URL,
	DEVIN_ORG_VALUE_NAME,
	DEVIN_SECRET_NAME,
	resolveOrgId,
	type DevinQuery,
} from './lib/client.ts'

export type DevinRequestParams = {
	/** Path on api.devin.ai. `{org_id}` is replaced with the resolved org id. */
	path: string
	method?: string
	query?: DevinQuery
	body?: unknown
	headers?: Record<string, string>
	orgId?: string
	accept?: string
}

/**
 * Unwrapped api.devin.ai escape hatch for endpoints this package doesn't wrap
 * (enterprise admin, code scans, snapshot blueprints, repo indexing, secrets).
 * Non-2xx responses are returned rather than thrown.
 */
export async function devinRequest(params: DevinRequestParams) {
	let path = params.path
	if (path.includes('{org_id}')) {
		const org = await resolveOrgId(params.orgId)
		path = path.replaceAll('{org_id}', encodeURIComponent(org))
	}

	const result = await devinRequestRaw({
		path,
		method: params.method,
		query: params.query,
		body: params.body,
		headers: params.headers,
		accept: params.accept,
	})
	return { status: result.status, body: result.body }
}

export default devinRequest