import {z} from 'zod' export type ResourceId = string; export type ServerTimestamp = string; export type Link = {href: string, rel: 'draft' | 'events' | 'order' | 'receipt' | 'self' | 'session' | 'session-checkout' | 'transaction'}; export type ApiEvent = {event_type: 'api-event', id?: ResourceId | undefined, created_at?: ServerTimestamp | undefined, created_by?: ResourceId | undefined, version?: number | undefined, request?: ({path?: string | undefined, method?: string | undefined, body?: string | undefined}) | undefined, draft_id?: string | undefined}; export type BillingPayoutRuleDestinationNested = {type: 'percentage' | 'flat_amount' | 'remaining_amount', value?: unknown | undefined, destination?: string | undefined, destinations?: Array> | undefined, amount?: number | undefined}; export type BillingPayoutRuleDestination = {type: 'percentage' | 'flat_amount' | 'remaining_amount', value?: unknown | undefined, destination?: string | undefined, destinations?: Array | undefined, amount?: number | undefined}; export type BillingPayoutRule = {account_id?: unknown | undefined, rule_type: string, rule_id: string, rule_version?: number | undefined, destinations: Array, metadata?: Record | undefined}; export type UserConsent = {consent?: boolean | undefined, updated_at?: string | undefined}; export type CustomerAddress = {address_line: string, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place: string, country: unknown, latitude?: number | undefined, longitude?: number | undefined, type?: ('custom' | 'home' | 'other' | 'work') | undefined, custom_type?: string | undefined, comment?: string | undefined}; export type CustomerTerm = {id?: string | undefined, accepted_at?: string | undefined}; export type Customer = {metadata?: Record | undefined, id?: string | undefined, created_at?: string | undefined, created_by?: string | undefined, updated_at?: string | undefined, deleted_by?: string | undefined, deleted_at?: string | undefined, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, email?: (string | null) | undefined, phone_number?: (unknown | null) | undefined, attributes?: Record | undefined, status?: (string | null) | undefined, favorite_store?: (string | null) | undefined, enrolled_by?: ({type?: string | undefined, value: string | null}) | undefined, marketing_consent?: ({sms?: UserConsent | undefined, email?: UserConsent | undefined} | {[key: string]: UserConsent}) | undefined, type: 'customer' | 'company' | 'contact' | 'employee' | 'other', addresses?: Array | undefined, term?: CustomerTerm | undefined, company?: ({organization_number?: string | undefined, bussiness_name: string, department?: string | undefined, industry?: string | undefined, website?: string | undefined, number_of_employees?: string | undefined}) | undefined, gender?: (string | null) | undefined, date_of_birth?: (string | null) | undefined, contact_for?: Array<{customer_id: string}> | undefined}; export type GrossAmount = number; export type NetAmount = number; export type ContactObject = {address_line: string, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place: string, country: unknown, first_name?: string | undefined, last_name?: string | undefined, comment?: string | undefined}; export type OrderItineraryAddress = {id?: string | undefined, name?: string | undefined, address_line?: string | undefined, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place?: string | undefined, latitude?: number | undefined, longitude?: number | undefined, country?: unknown | undefined, external_ids?: (Array<{id: string, source: string, description?: string | undefined}>) | undefined}; export type ItineraryTravelMode = 'BUS' | 'CAR' | 'FERRY' | 'METRO' | 'TAXI' | 'TRAIN' | 'TRAM' | 'WALK' | 'WAIT' | 'CUSTOM'; export type OrderTravelItinerary = {id?: string | undefined, operator?: string | undefined, arrival_address?: OrderItineraryAddress | undefined, arrival_at?: unknown | undefined, departure_address?: OrderItineraryAddress | undefined, departure_at?: unknown | undefined, travel_mode?: ItineraryTravelMode | undefined, route_id?: string | undefined, vehicle_id?: string | undefined, summary?: string | undefined, distance?: {value: number} | undefined, duration?: {value: number} | undefined, tickets?: (Array<{class?: string | undefined, line?: string | undefined, seat?: string | undefined, zone?: string | undefined, passenger_id?: Array | undefined}>) | undefined, line_ids?: Array | undefined, waypoints?: (Array<{display_name?: string | undefined, latitude: number, longitude: number, arrival_schedule_at?: unknown | undefined, departure_schedule_at?: unknown | undefined}>) | undefined}; export type OrderExternalId = {id: string, source: string, description?: string | undefined}; export type TaxItem = {amount?: number | undefined, amount_dwh?: string | undefined, exempt?: boolean | undefined, included_in_price?: boolean | undefined, percentage?: number | undefined, tax_basis?: number | undefined, tax_basis_dwh?: string | undefined, tax_code?: string | undefined, tax_group?: string | undefined}; export type Dimension = {color?: string | undefined, size?: string | undefined, style?: string | undefined, config?: string | undefined, variant?: string | undefined}; export type DiscountType = 'customer' | 'periodic' | 'manual' | 'loyalty' | 'total' | 'employee' | 'external'; export type DiscountItem = {amount?: number | undefined, percentage?: number | undefined, discount_type?: DiscountType | undefined, discount_id?: string | undefined, description?: string | undefined, line_id?: number | undefined}; export type Amount = number; export type SplitPayout = {account_id?: unknown | undefined, rule_type: string, rule_id: string, rule_version?: number | undefined, destinations: Array, metadata?: Record | undefined}; export type OrderExternalLink = {text: string, href: string, public?: boolean | undefined}; export type Address = {address_line: string, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place: string, country: unknown}; export type LineItemIsuranceAttachment = {insurance_company?: string | undefined, insurance_type?: string | undefined}; export type LineItemReservationAttachment = {booking_id?: string | undefined, line_ids?: Array | undefined, passengers?: (Array<{id?: string | undefined, title?: string | undefined, first_name?: string | undefined, last_name?: string | undefined}>) | undefined, itinerary?: (Array<{departure_address?: Address | undefined, departure_at?: string | undefined, arrival_address?: Address | undefined, arrival_at?: string | undefined, operator?: string | undefined, class?: string | undefined, line?: string | undefined, seat?: string | undefined, zone?: string | undefined, expires_at?: string | undefined, activates_at?: string | undefined, passenger_id?: Array | undefined}>) | undefined, insurance?: Array | undefined}; export type LineItemReservationCarAttachment = {booking_id?: string | undefined, line_ids?: Array | undefined, itinerary?: (Array<{rental_company?: string | undefined, drivers_id?: Array | undefined, pick_up_address?: Address | undefined, pick_up_at?: string | undefined, drop_off_address?: Address | undefined, drop_off_at?: string | undefined, class?: string | undefined}>) | undefined, drivers?: Array | undefined, insurance?: Array | undefined}; export type DraftOrder = {id?: ResourceId | undefined, created_at?: ServerTimestamp | undefined, created_by?: ResourceId | undefined, updated_at?: ServerTimestamp | undefined, deleted_by?: ResourceId | undefined, deleted_at?: ServerTimestamp | undefined, status?: ('open' | 'completed' | 'deleted') | undefined, _links?: Array | undefined, version?: number | undefined, events?: Array | undefined, options?: ({order_time_to_live?: number | undefined, generate_order_id?: ('UUID' | 'ALPHANUMERIC_9' | 'ALPHANUMERIC_9_RESERVE') | undefined, order_id?: string | undefined, replace?: 'order' | undefined, payout?: ({rules?: Array | undefined, resolve_rule_id: 'order.items.store.id', resolve_rule_type: string}) | undefined, split_draft?: boolean | undefined, serial_order_number_suffix?: boolean | undefined, multiple_authorizations?: boolean | undefined}) | undefined, order: {customer?: Customer | undefined, gross_amount?: GrossAmount | undefined, net_amount?: NetAmount | undefined, total_discount?: number | undefined, total_manual_discount_amount?: number | undefined, shipping_address?: ContactObject | undefined, billing_address?: ContactObject | undefined, metadata?: Record | undefined, comment?: string | undefined, salesperson_id?: string | undefined, salesperson_name?: string | undefined, delivery_at?: string | undefined, pickup_at?: string | undefined, courier_id?: string | undefined, pre_order?: boolean | undefined, time_to_live?: number | undefined, itinerary?: Array | undefined, external_ids?: Array | undefined, items?: (Array<{status?: string | undefined, id?: string | undefined, metadata?: Record | undefined, groups?: (Array<{id: string, name?: string | undefined}>) | undefined, line_id?: number | undefined, quantity?: number | undefined, gross_amount: GrossAmount, net_amount?: NetAmount | undefined, tax_lines: Array, description?: string | undefined, description_alias?: string | undefined, is_changed?: boolean | undefined, eligible_for_discount?: boolean | undefined, dimension?: Dimension | undefined, discount_lines?: Array | undefined, additions?: (Array<{id?: string | undefined, description?: string | undefined, quantity?: number | undefined, gross_amount?: Amount | undefined, groups?: (Array<{id: string, name?: string | undefined}>) | undefined}>) | undefined, store?: ({id: string, organization_number?: string | undefined, name?: string | undefined, business_name?: string | undefined, comment?: string | undefined}) | undefined, external_id?: string | undefined, related_item?: ({line_id: number, type: 'required' | 'optional' | 'reversed'}) | undefined, salesperson_id?: string | undefined, salesperson_name?: string | undefined, comment?: string | undefined, version?: number | undefined, reversed_reason?: string | undefined, dynamic_payout?: {rule_type: string, rule_id: string} | undefined, payout?: SplitPayout | undefined, original_currency?: unknown | undefined, original_gross_amount?: number | undefined, conversion_rate_ppm?: number | undefined, conversion_rate_timestamp?: string | undefined, conversion_rate_source?: string | undefined}>) | undefined, version?: number | undefined, type?: string | undefined, order_number?: string | undefined, currency: unknown, order_id?: string | undefined, time_to_live_expires_at?: unknown | undefined, multiple_authorizations?: boolean | undefined, discounts?: (Array<{id?: string | undefined, refs?: (Array<{id?: string | undefined, amount?: number | undefined, statistics?: ({amount?: number | undefined, stamp?: number | undefined, usage?: number | undefined}) | undefined, stamp?: number | undefined, usages?: number | undefined, items?: (Array<{line_id?: number | undefined, amount?: number | undefined}>) | undefined}>) | undefined}>) | undefined, store?: ({id: string, organization_number?: string | undefined, name?: string | undefined, business_name?: string | undefined, comments?: Array | undefined}) | undefined, external_links?: Array | undefined, attachments?: (Array<{id?: string | undefined, bus_reservation?: LineItemReservationAttachment | undefined, car_reservation?: LineItemReservationCarAttachment | undefined, ferry_reservation?: LineItemReservationAttachment | undefined, metro_reservation?: LineItemReservationAttachment | undefined, taxi_reservation?: LineItemReservationAttachment | undefined, train_reservation?: LineItemReservationAttachment | undefined, tram_reservation?: LineItemReservationAttachment | undefined}>) | undefined, stores?: (Array<{id: string, organization_number?: string | undefined, name?: string | undefined, business_name?: string | undefined, comments?: Array | undefined}>) | undefined}}; export type CreateApiAccountsAidShoppingDraftOrdersArgs = {aid: unknown, apply_discounts?: boolean | undefined, body: DraftOrder}; export type CreateApiAccountsAidShoppingDraftOrdersOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceId = z.string().max(40); export const serverTimestamp = z.string(); export const link = z.object({href: z.string(), rel: z.enum(["draft", "events", "order", "receipt", "self", "session", "session-checkout", "transaction"])}); export const apiEvent = z.object({event_type: z.literal("api-event"), id: resourceId.optional(), created_at: serverTimestamp.optional(), created_by: resourceId.optional(), version: z.number().optional(), request: z.object({path: z.string().optional(), method: z.string().optional(), body: z.string().optional()}).optional(), draft_id: z.string().optional()}); export const billingPayoutRuleDestinationNested = z.object({type: z.enum(["percentage", "flat_amount", "remaining_amount"]), value: z.string().optional(), destination: z.string().optional(), destinations: z.array(z.object({})).optional(), amount: z.number().int().optional()}); export const billingPayoutRuleDestination = z.object({type: z.enum(["percentage", "flat_amount", "remaining_amount"]), value: z.string().optional(), destination: z.string().optional(), destinations: z.array(billingPayoutRuleDestinationNested).optional(), amount: z.number().int().optional()}); export const billingPayoutRule = z.object({account_id: z.string().optional(), rule_type: z.string(), rule_id: z.string(), rule_version: z.number().optional(), destinations: z.array(billingPayoutRuleDestination), metadata: z.object({}).optional()}); export const userConsent = z.object({consent: z.boolean().optional(), updated_at: z.string().optional()}); export const customerAddress = z.object({address_line: z.string(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string(), country: z.string(), latitude: z.number().optional(), longitude: z.number().optional(), type: z.enum(["custom", "home", "other", "work"]).optional(), custom_type: z.string().optional(), comment: z.string().optional()}); export const customerTerm = z.object({id: z.string().optional(), accepted_at: z.string().optional()}); export const customer = z.object({metadata: z.object({}).optional(), id: z.string().optional(), created_at: z.string().optional(), created_by: z.string().optional(), updated_at: z.string().optional(), deleted_by: z.string().optional(), deleted_at: z.string().optional(), first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), attributes: z.object({}).optional(), status: z.string().nullable().optional(), favorite_store: z.string().nullable().optional(), enrolled_by: z.object({type: z.string().optional(), value: z.string().nullable()}).optional(), marketing_consent: z.object({sms: userConsent.optional(), email: userConsent.optional()}).and(z.record(z.string(), userConsent)).optional(), type: z.enum(["customer", "company", "contact", "employee", "other"]), addresses: z.array(customerAddress).optional(), term: customerTerm.optional(), company: z.object({organization_number: z.string().optional(), bussiness_name: z.string(), department: z.string().optional(), industry: z.string().optional(), website: z.string().optional(), number_of_employees: z.string().optional()}).optional(), gender: z.string().nullable().optional(), date_of_birth: z.string().nullable().optional(), contact_for: z.array(z.object({customer_id: z.string()})).optional()}); export const grossAmount = z.number().int(); export const netAmount = z.number().int(); export const contactObject = z.object({address_line: z.string(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string(), country: z.string(), first_name: z.string().optional(), last_name: z.string().optional(), comment: z.string().optional()}); export const orderItineraryAddress = z.object({id: z.string().optional(), name: z.string().optional(), address_line: z.string().optional(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), country: z.string().optional(), external_ids: z.array(z.object({id: z.string(), source: z.string(), description: z.string().optional()})).optional()}); export const itineraryTravelMode = z.enum(["BUS", "CAR", "FERRY", "METRO", "TAXI", "TRAIN", "TRAM", "WALK", "WAIT", "CUSTOM"]); export const orderTravelItinerary = z.object({id: z.string().optional(), operator: z.string().optional(), arrival_address: orderItineraryAddress.optional(), arrival_at: z.string().optional(), departure_address: orderItineraryAddress.optional(), departure_at: z.string().optional(), travel_mode: itineraryTravelMode.optional(), route_id: z.string().optional(), vehicle_id: z.string().optional(), summary: z.string().optional(), distance: z.object({value: z.number().int()}).optional(), duration: z.object({value: z.number().int()}).optional(), tickets: z.array(z.object({class: z.string().optional(), line: z.string().optional(), seat: z.string().optional(), zone: z.string().optional(), passenger_id: z.array(z.string()).optional()})).optional(), line_ids: z.array(z.number().int()).optional(), waypoints: z.array(z.object({display_name: z.string().optional(), latitude: z.number(), longitude: z.number(), arrival_schedule_at: z.string().optional(), departure_schedule_at: z.string().optional()})).optional()}); export const orderExternalId = z.object({id: z.string(), source: z.string(), description: z.string().optional()}); export const taxItem = z.object({amount: z.number().int().optional(), amount_dwh: z.string().optional(), exempt: z.boolean().optional(), included_in_price: z.boolean().optional(), percentage: z.number().optional(), tax_basis: z.number().int().optional(), tax_basis_dwh: z.string().optional(), tax_code: z.string().optional(), tax_group: z.string().optional()}); export const dimension = z.object({color: z.string().optional(), size: z.string().optional(), style: z.string().optional(), config: z.string().optional(), variant: z.string().optional()}); export const discountType = z.enum(["customer", "periodic", "manual", "loyalty", "total", "employee", "external"]); export const discountItem = z.object({amount: z.number().int().optional(), percentage: z.number().optional(), discount_type: discountType.optional(), discount_id: z.string().optional(), description: z.string().optional(), line_id: z.number().int().optional()}); export const amount = z.number().int(); export const splitPayout = z.object({account_id: z.string().optional(), rule_type: z.string(), rule_id: z.string(), rule_version: z.number().optional(), destinations: z.array(billingPayoutRuleDestination), metadata: z.object({}).optional()}); export const orderExternalLink = z.object({text: z.string(), href: z.string(), public: z.boolean().optional()}); export const address = z.object({address_line: z.string(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string(), country: z.string()}); export const lineItemIsuranceAttachment = z.object({insurance_company: z.string().optional(), insurance_type: z.string().optional()}); export const lineItemReservationAttachment = z.object({booking_id: z.string().optional(), line_ids: z.array(z.number().int()).optional(), passengers: z.array(z.object({id: z.string().optional(), title: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional()})).optional(), itinerary: z.array(z.object({departure_address: address.optional(), departure_at: z.string().optional(), arrival_address: address.optional(), arrival_at: z.string().optional(), operator: z.string().optional(), class: z.string().optional(), line: z.string().optional(), seat: z.string().optional(), zone: z.string().optional(), expires_at: z.string().optional(), activates_at: z.string().optional(), passenger_id: z.array(z.string()).optional()})).optional(), insurance: z.array(lineItemIsuranceAttachment).optional()}); export const lineItemReservationCarAttachment = z.object({booking_id: z.string().optional(), line_ids: z.array(z.number().int()).optional(), itinerary: z.array(z.object({rental_company: z.string().optional(), drivers_id: z.array(z.string()).optional(), pick_up_address: address.optional(), pick_up_at: z.string().optional(), drop_off_address: address.optional(), drop_off_at: z.string().optional(), class: z.string().optional()})).optional(), drivers: z.array(z.string()).optional(), insurance: z.array(lineItemIsuranceAttachment).optional()}); export const draftOrder = z.object({id: resourceId.optional(), created_at: serverTimestamp.optional(), created_by: resourceId.optional(), updated_at: serverTimestamp.optional(), deleted_by: resourceId.optional(), deleted_at: serverTimestamp.optional(), status: z.enum(["open", "completed", "deleted"]).optional(), _links: z.array(link).optional(), version: z.number().int().optional(), events: z.array(apiEvent).optional(), options: z.object({order_time_to_live: z.number().int().gte(86400).optional(), generate_order_id: z.enum(["UUID", "ALPHANUMERIC_9", "ALPHANUMERIC_9_RESERVE"]).optional(), order_id: z.string().optional(), replace: z.literal("order").optional(), payout: z.object({rules: z.array(billingPayoutRule).optional(), resolve_rule_id: z.literal("order.items.store.id"), resolve_rule_type: z.string()}).optional(), split_draft: z.boolean().optional(), serial_order_number_suffix: z.boolean().optional(), multiple_authorizations: z.boolean().optional()}).optional(), order: z.object({customer: customer.optional(), gross_amount: grossAmount.optional(), net_amount: netAmount.optional(), total_discount: z.number().int().gte(0).optional(), total_manual_discount_amount: z.number().int().gte(0).optional(), shipping_address: contactObject.optional(), billing_address: contactObject.optional(), metadata: z.object({}).optional(), comment: z.string().max(255).optional(), salesperson_id: z.string().optional(), salesperson_name: z.string().optional(), delivery_at: z.string().optional(), pickup_at: z.string().optional(), courier_id: z.string().optional(), pre_order: z.boolean().optional(), time_to_live: z.number().int().gte(86400).optional(), itinerary: z.array(orderTravelItinerary).optional(), external_ids: z.array(orderExternalId).optional(), items: z.array(z.object({status: z.string().optional(), id: z.string().optional(), metadata: z.object({}).optional(), groups: z.array(z.object({id: z.string(), name: z.string().optional()})).optional(), line_id: z.number().int().optional(), quantity: z.number().optional(), gross_amount: grossAmount, net_amount: netAmount.optional(), tax_lines: z.array(taxItem), description: z.string().optional(), description_alias: z.string().optional(), is_changed: z.boolean().optional(), eligible_for_discount: z.boolean().optional(), dimension: dimension.optional(), discount_lines: z.array(discountItem).optional(), additions: z.array(z.object({id: z.string().optional(), description: z.string().optional(), quantity: z.number().optional(), gross_amount: amount.optional(), groups: z.array(z.object({id: z.string(), name: z.string().optional()})).optional()})).optional(), store: z.object({id: z.string(), organization_number: z.string().optional(), name: z.string().optional(), business_name: z.string().optional(), comment: z.string().max(255).optional()}).optional(), external_id: z.string().optional(), related_item: z.object({line_id: z.number().int(), type: z.enum(["required", "optional", "reversed"])}).optional(), salesperson_id: z.string().optional(), salesperson_name: z.string().optional(), comment: z.string().max(255).optional(), version: z.number().optional(), reversed_reason: z.string().optional(), dynamic_payout: z.object({rule_type: z.string(), rule_id: z.string()}).optional(), payout: splitPayout.optional(), original_currency: z.string().max(3).optional(), original_gross_amount: z.number().int().optional(), conversion_rate_ppm: z.number().int().optional(), conversion_rate_timestamp: z.string().optional(), conversion_rate_source: z.string().optional()})).optional(), version: z.number().int().optional(), type: z.string().optional(), order_number: z.string().optional(), currency: z.string().max(3), order_id: z.string().min(1).max(255).optional(), time_to_live_expires_at: z.string().optional(), multiple_authorizations: z.boolean().optional(), discounts: z.array(z.object({id: z.string().optional(), refs: z.array(z.object({id: z.string().optional(), amount: z.number().optional(), statistics: z.object({amount: z.number().optional(), stamp: z.number().optional(), usage: z.number().optional()}).optional(), stamp: z.number().optional(), usages: z.number().optional(), items: z.array(z.object({line_id: z.number().optional(), amount: z.number().optional()})).optional()})).optional()})).optional(), store: z.object({id: z.string(), organization_number: z.string().optional(), name: z.string().optional(), business_name: z.string().optional(), comments: z.array(z.string().max(255)).optional()}).optional(), external_links: z.array(orderExternalLink).optional(), attachments: z.array(z.object({id: z.string().optional(), bus_reservation: lineItemReservationAttachment.optional(), car_reservation: lineItemReservationCarAttachment.optional(), ferry_reservation: lineItemReservationAttachment.optional(), metro_reservation: lineItemReservationAttachment.optional(), taxi_reservation: lineItemReservationAttachment.optional(), train_reservation: lineItemReservationAttachment.optional(), tram_reservation: lineItemReservationAttachment.optional()})).optional(), stores: z.array(z.object({id: z.string(), organization_number: z.string().optional(), name: z.string().optional(), business_name: z.string().optional(), comments: z.array(z.string().max(255)).optional()})).optional()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * aid_draft_orders_post * * POST /accounts/{aid}/shopping/draft_orders */ export const createApiAccountsAidShoppingDraftOrders = async (args: CreateApiAccountsAidShoppingDraftOrdersArgs, options?: CreateApiAccountsAidShoppingDraftOrdersOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.apply_discounts != null) query.append("apply_discounts", String(args.apply_discounts)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/shopping/draft_orders${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(draftOrder, await res.json()) };