← Public packages
@kody/doordash
Order food on DoorDash as a customer through the consumer MCP used by dd-cli.
src/promo.ts
42 lines · 1.4 KB · TypeScriptimport { callMcpTool, TOOLS, type DoorDashMcpAuthInput } from './mcp.ts'
const ACTIONS = ['list', 'apply', 'remove'] as const
export type PromoAction = (typeof ACTIONS)[number]
export type PromoInput = DoorDashMcpAuthInput & {
action?: PromoAction
storeId?: string | number
cartUuid?: string
promoCode?: string
addressId?: string
confirm?: boolean
dryRun?: boolean
}
function shouldDryRun(input: PromoInput, mutating: boolean) {
if (input.dryRun === true) return true
if (mutating && input.confirm !== true && input.dryRun !== false) return true
return false
}
export default async function promo(input: PromoInput = {}) {
const action = (input.action ?? 'list') as PromoAction
if (action === 'list') {
const storeId = String(input.storeId ?? '').trim()
if (!storeId) throw new Error('storeId is required for promo list.')
const args: Record<string, unknown> = { store_id: storeId }
if (input.addressId) args.address_id = String(input.addressId)
return callMcpTool({ ...input, name: TOOLS.listPromos, arguments: args })
}
const cartUuid = String(input.cartUuid ?? '').trim()
const promoCode = String(input.promoCode ?? '').trim()
if (!cartUuid || !promoCode) {
throw new Error('cartUuid and promoCode are required for apply/remove.')
}
return callMcpTool({
...input,
name: action === 'apply' ? TOOLS.applyPromo : TOOLS.removePromo,
arguments: { cart_uuid: cartUuid, promo_code: promoCode },
dryRun: shouldDryRun(input, true),
})
}