import {z} from 'zod' export type StoreCreateBase = {Name?: string | undefined, EmailAddress?: string | undefined, StaffLanguage?: string | undefined, SalesChannelType?: ('Web' | 'App' | 'Kiosk' | 'Pos' | 'None' | 'PhoneAgent' | null) | undefined, PhoneNumber?: string | undefined}; export type CreateApiApiV10PropertiesPropertyIdStoresArgs = {storeGroupId: number, propertyId: string, autoAssignMenu?: boolean | undefined, body: StoreCreateBase}; export type CreateApiApiV10PropertiesPropertyIdStoresOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const coordinates = z.object({Latitude: z.number().optional(), Longitude: z.number().optional()}); export const storeAddress = z.object({AddressId: z.number().int().optional(), Coordinates: coordinates.optional(), Line1: z.string().optional(), Postcode: z.string().optional(), City: z.string().optional(), CountryCode: z.string().max(2).optional(), DisplayForCustomer: z.string().optional(), AddressFields: z.record(z.string(), z.object({})).optional(), SingleLineDisplay: z.string().optional(), TwoLinesDisplay: z.array(z.string()).optional()}); export const deliveryZone = z.object({Id: z.number().int().optional(), FeeChargedToStore: z.number().nullable().optional(), DeliveryFee: z.number().optional(), MinimumDeliveryOrderAmount: z.number().optional(), WellKnownText: z.string().optional(), IsEnabled: z.boolean().optional()}); export const range = z.object({StartTime: z.string().optional(), Period: z.string().optional(), DayOfWeek: z.enum(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]).optional()}); export const businessHoursPeriod = z.object({Early: range.optional(), Late: range.optional(), Ranges: z.array(range).optional(), DayOfWeek: z.enum(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]).optional(), StartTime: z.string().optional(), Period: z.string().optional(), StartTimeEarly: z.string().optional(), PeriodEarly: z.string().optional()}); export const storeNote = z.object({UserId: z.number().int().optional(), CreateTime: z.string().optional(), Note: z.string().optional()}); export const store = z.object({StoreId: z.number().int().optional(), StoreGroupId: z.number().int().optional(), Address: storeAddress.optional(), DeliveryZones: z.array(deliveryZone).optional(), ApmPhoneNumber: z.string().optional(), PickupHours: z.array(businessHoursPeriod).optional(), DeliveryHours: z.array(businessHoursPeriod).optional(), MenuId: z.number().int().optional(), OrderConfirmationMessageOverrideDelivery: z.string().optional(), OrderConfirmationMessageOverridePickup: z.string().optional(), PrintoutLayoutType: z.enum(["Default", "Centra", "SmallChefNotes", "SmallChefNotesAndCentra"]).nullable().optional(), StoreNotes: z.array(storeNote).optional(), MicrosoftTimeZone: z.string().optional(), IanaTimeZone: z.string().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(), PreOrderDeliveryEnabled: z.boolean().optional(), PreOrderPickupEnabled: z.boolean().optional(), LogoUrl: z.string().optional(), FraudPreventionStrategy: z.string().optional(), AppIds: z.array(z.string()).optional(), PropertyId: z.string().optional(), PhoneNumber: z.string().optional(), AlwaysAppearOpen: z.boolean().optional(), PreOrderEnabled: z.boolean().optional(), TakeOutEnabled: z.boolean().optional(), TableServiceEnabled: z.boolean().optional(), DineInEnabled: z.boolean().optional(), AllowPreOrdersAndTableService: z.boolean().optional(), PickupEnabled: z.boolean().optional(), DeliveryEnabled: z.boolean().optional(), CardOrderDeliveryEnabled: z.boolean().optional(), CashOrdersDeliveryEnabled: z.boolean().optional(), CardOrdersPickupEnabled: z.boolean().optional(), CashOrdersPickupEnabled: z.boolean().optional(), TipsEnabled: z.boolean().optional(), AutomaticallyAcceptOrders: z.boolean().optional(), OpenForDelivery: z.boolean().optional(), OpenForPickup: z.boolean().optional(), MinimumPickupOrderAmount: z.number().optional(), RequireCustomerNameForPickup: z.boolean().optional(), GdprCustomerPhoneNumbers: z.boolean().optional(), RequireCustomerNameForDelivery: z.boolean().optional(), AllowChefNotes: z.boolean().optional(), EtaInPickupConfirmationSmsEnabled: z.boolean().optional(), EtaInDeliveryConfirmationSmsEnabled: z.boolean().optional(), IsArchived: z.boolean().optional(), IsPublished: z.boolean().optional(), Name: z.string().optional(), EmailAddress: z.string().max(100).optional(), StaffLanguage: z.string().optional(), SalesChannelTypes: z.array(z.enum(["Web", "App", "Kiosk", "Pos", "None", "PhoneAgent"])).optional(), InheritanceConfigTypes: z.array(z.literal("CollectionSettings")).optional()}); export const restApiResultStore = z.object({Data: store}); 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 }; /** * POST /api/v1.0/properties/{propertyId}/stores */ export const createApiApiV10PropertiesPropertyIdStores = async (args: CreateApiApiV10PropertiesPropertyIdStoresArgs, options?: CreateApiApiV10PropertiesPropertyIdStoresOptions) => { const {baseUrl = "https://api.flipdish.co", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.storeGroupId != null) query.append("storeGroupId", String(args.storeGroupId)) if (args.autoAssignMenu != null) query.append("autoAssignMenu", String(args.autoAssignMenu)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1.0/properties/${encodeURIComponent(String(args.propertyId))}/stores${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(restApiResultStore, await res.json()) };