← Public packages
@kody/doordash-driver
Request DoorDash Drive (Dasher) deliveries with JWT auth from Developer Portal access keys.
src/create-quote.ts
59 lines · 1.5 KB · TypeScript/**
* Create a DoorDash Drive delivery quote (`POST /drive/v2/quotes`).
* Dry-run by default — pass `confirm: true` to request a live quote.
*
* ```ts
* import { createQuote } from 'kody:@kody/doordash-driver/create-quote'
* await createQuote({
* external_delivery_id: 'order-123',
* pickup_address: '901 Market Street, San Francisco, CA 94103',
* dropoff_address: '901 Market Street, San Francisco, CA 94103',
* order_value: 1999,
* confirm: true,
* })
* ```
*/
import { doorDashRequest, type DoorDashAuthInput, type DoorDashObject } from './core.ts'
export type CreateQuoteInput = DoorDashAuthInput & {
body?: DoorDashObject
external_delivery_id?: string
pickup_address?: string
pickup_phone_number?: string
dropoff_address?: string
dropoff_phone_number?: string
order_value?: number
currency?: string
dryRun?: boolean
confirm?: boolean
}
function buildBody(input: CreateQuoteInput): DoorDashObject {
if (input.body && typeof input.body === 'object') return { ...input.body }
const body: DoorDashObject = {}
for (const key of [
'external_delivery_id',
'pickup_address',
'pickup_phone_number',
'dropoff_address',
'dropoff_phone_number',
'order_value',
'currency',
] as const) {
const value = input[key]
if (value !== undefined) body[key] = value
}
return body
}
export async function createQuote(input: CreateQuoteInput = {}) {
return doorDashRequest({
...input,
method: 'POST',
path: '/drive/v2/quotes',
body: buildBody(input),
})
}
export default createQuote