Skip to content
← Public packages

@kody/doordash-driver

Request DoorDash Drive (Dasher) deliveries with JWT auth from Developer Portal access keys.

src/accept-quote.ts

37 lines · 1.0 KB · TypeScript
/**
 * Accept a DoorDash Drive quote (`POST /drive/v2/quotes/{external_delivery_id}/accept`).
 * Dry-run by default — pass `confirm: true` to accept live.
 *
 * ```ts
 * import { acceptQuote } from 'kody:@kody/doordash-driver/accept-quote'
 * await acceptQuote({ externalDeliveryId: 'order-123', confirm: true })
 * ```
 */

import { doorDashRequest, type DoorDashAuthInput, type DoorDashObject } from './core.ts'

export type AcceptQuoteInput = DoorDashAuthInput & {
	externalDeliveryId?: string
	quoteId?: string
	id?: string
	body?: DoorDashObject
	dryRun?: boolean
	confirm?: boolean
}

export async function acceptQuote(input: AcceptQuoteInput = {}) {
	const externalId = String(
		input.externalDeliveryId ?? input.quoteId ?? input.id ?? '',
	).trim()
	if (!externalId) {
		throw new Error('Pass externalDeliveryId (same id used when creating the quote).')
	}
	return doorDashRequest({
		...input,
		method: 'POST',
		path: '/drive/v2/quotes/' + encodeURIComponent(externalId) + '/accept',
		body: input.body ?? {},
	})
}

export default acceptQuote