import {z} from 'zod' export type GetApiApiV10AppIdOrdersSummariesNewArgs = {appId: string, searchQuery?: string | undefined, physicalRestaurantId?: Array | undefined, state?: (Array<'Created' | 'PlacedCanBeCancelled' | 'ReadyToProcess' | 'AcceptedByRestaurant' | 'Dispatched' | 'Delivered' | 'Cancelled' | 'ManualReview' | 'RejectedByStore' | 'RejectedByFlipdish' | 'RejectedAutomatically' | 'RejectedAfterBeingAccepted' | 'AcceptedAndRefunded' | 'PendingPayment'>) | undefined, page?: number | undefined, limit?: number | undefined, orderByRequestedForTime?: boolean | undefined, channels?: (Array<'Unknown' | 'Ios' | 'Android' | 'Web' | 'Kiosk' | 'Pos' | 'TelephoneCall' | 'Sms' | 'PwaAndroid' | 'PwaIos' | 'Google' | 'Photon'>) | undefined, orderIds?: Array | undefined, from?: string | undefined, to?: string | undefined, logSql?: boolean | undefined}; export type GetApiApiV10AppIdOrdersSummariesNewOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const channel = z.object({ChannelId: z.number().int().optional(), TranslationKey: z.string().optional(), Source: z.enum(["Internal", "External"]).optional(), LogoUri: z.string().optional(), Available: z.boolean().optional(), MaintainedExternally: z.boolean().optional()}); export const orderDropOffLocation = z.object({OrderId: z.number().int().optional(), LocationName: z.string().optional(), LocationAreaName: z.string().optional(), LocationId: z.number().int().optional(), LocationAreaId: z.number().int().optional(), ExternalLocationId: z.string().optional()}); export const orderBatchSummary = z.object({Id: z.number().int().optional(), DisplayCode: z.string().optional(), CreateTime: z.string().optional(), IsPublished: z.boolean().optional()}); export const coordinates = z.object({Latitude: z.number().optional(), Longitude: z.number().optional()}); export const deliveryLocation = z.object({Coordinates: coordinates.optional(), Building: z.string().optional(), Street: z.string().optional(), Town: z.string().optional(), PostCode: z.string().optional(), DeliveryInstructions: z.string().optional(), PrettyAddressString: z.string().optional()}); export const orderSummary = z.object({OrderId: z.number().int().optional(), DeliveryType: z.enum(["Delivery", "Pickup"]).optional(), PickupLocationType: z.enum(["TakeOut", "TableService", "DineIn"]).optional(), TableServiceCatagory: z.enum(["Generic", "Villa", "House", "Room", "Area", "Table", "ParkingBay", "Gate", "DriveThrough", "Team"]).nullable().optional(), OrderState: z.enum(["Created", "PlacedCanBeCancelled", "ReadyToProcess", "AcceptedByRestaurant", "Dispatched", "Delivered", "Cancelled", "ManualReview", "RejectedByStore", "RejectedByFlipdish", "RejectedAutomatically", "RejectedAfterBeingAccepted", "AcceptedAndRefunded", "PendingPayment"]).optional(), RequestedForTime: z.string().optional(), StoreName: z.string().optional(), StoreIanaTimeZone: z.string().optional(), CustomerName: z.string().optional(), CustomerPhoneNumber: z.string().optional(), Amount: z.number().optional(), RefundedAmount: z.number().optional(), PaymentAccountType: z.enum(["Card", "Cash", "Ideal", "Bancontact", "Giropay", "Eps", "Emv", "PayPal", "PayGreen", "GoogleWalletToken"]).optional(), PaymentStatus: z.enum(["Paid", "Unpaid", "Refunded", "PartiallyRefunded", "Disputed"]).optional(), Currency: z.enum(["EUR", "USD", "GBP", "CAD", "AUD", "DJF", "ZAR", "ETB", "AED", "BHD", "DZD", "EGP", "IQD", "JOD", "KWD", "LBP", "LYD", "MAD", "OMR", "QAR", "SAR", "SYP", "TND", "YER", "CLP", "INR", "AZN", "RUB", "BYN", "BGN", "NGN", "BDT", "CNY", "BAM", "CZK", "DKK", "CHF", "MVR", "BTN", "XCD", "BZD", "HKD", "IDR", "JMD", "MYR", "NZD", "PHP", "SGD", "TTD", "XDR", "ARS", "BOB", "COP", "CRC", "CUP", "DOP", "GTQ", "HNL", "MXN", "NIO", "PAB", "PEN", "PYG", "UYU", "VEF", "IRR", "XOF", "CDF", "XAF", "HTG", "ILS", "HRK", "HUF", "AMD", "ISK", "JPY", "GEL", "KZT", "KHR", "KRW", "KGS", "LAK", "MKD", "MNT", "BND", "MMK", "NOK", "NPR", "PKR", "PLN", "AFN", "BRL", "MDL", "RON", "RWF", "SEK", "LKR", "SOS", "ALL", "RSD", "KES", "TJS", "THB", "ERN", "TMT", "BWP", "TRY", "UAH", "UZS", "VND", "MOP", "TWD", "BMD"]).optional(), AppType: z.enum(["Unknown", "Ios", "Android", "Web", "Kiosk", "Pos", "TelephoneCall", "Sms", "PwaAndroid", "PwaIos", "Google"]).optional(), LocalOrderId: z.string().optional(), DropOffLocationId: z.number().int().nullable().optional(), DropOffLocation: z.string().optional(), AcceptedFor: z.string().nullable().optional(), Channel: channel.optional(), InFraudZone: z.boolean().optional(), UnusualHighValueOrder: z.boolean().optional(), ChannelOrderId: z.string().optional(), ChannelOrderDisplayId: z.string().optional(), OrderDropOffLocation: orderDropOffLocation.optional(), OrderBatchInfo: orderBatchSummary.optional(), DeliveryLocation: deliveryLocation.optional()}); export const restApiPaginationResultOrderSummary = z.object({Page: z.number().int(), Limit: z.number().int(), TotalRecordCount: z.number().int(), Data: z.array(orderSummary)}); 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 }; /** * GET /api/v1.0/{appId}/orders/summariesNew */ export const getApiApiV10AppIdOrdersSummariesNew = async (args: GetApiApiV10AppIdOrdersSummariesNewArgs, options?: GetApiApiV10AppIdOrdersSummariesNewOptions) => { const {baseUrl = "https://api.flipdish.co", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.searchQuery != null) query.append("searchQuery", String(args.searchQuery)) for (const item of args.physicalRestaurantId ?? []) query.append("physicalRestaurantId", String(item)) for (const item of args.state ?? []) query.append("state", String(item)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.orderByRequestedForTime != null) query.append("orderByRequestedForTime", String(args.orderByRequestedForTime)) for (const item of args.channels ?? []) query.append("channels", String(item)) for (const item of args.orderIds ?? []) query.append("orderIds", String(item)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.logSql != null) query.append("logSql", String(args.logSql)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1.0/${encodeURIComponent(String(args.appId))}/orders/summariesNew${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(restApiPaginationResultOrderSummary, await res.json()) };