import {z} from 'zod' export type GetApiApiV10SearchRestaurantsArgs = {query: string, countryId: string, includeArchivedStores?: ('NonArchivedOnly' | 'ArchivedOnly' | 'Both') | undefined, searchType?: ('WhiteLabelConfigInfo' | 'WhiteLabelConfigVirtualRestaurantInfo' | 'WhiteLabelConfigPhysicalRestaurantInfo' | 'WhiteLabelConfigPhysicalRestaurantAddressInfo') | undefined, publishedStatus?: ('AllStores' | 'Published' | 'Unpublished') | undefined, page?: number | undefined, limit?: number | undefined}; export type GetApiApiV10SearchRestaurantsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const whiteLabelConfig = z.object({WhiteLabelId: z.number().int().optional(), WhiteLabelName: z.string().optional(), CountryId: z.string().optional(), AppNameId: z.string().optional(), Website: z.string().optional(), PanaceaVanityUrl: z.string().optional()}); export const restaurant = z.object({WhiteLabelConfigs: z.array(whiteLabelConfig).optional(), VirtualRestaurantId: z.number().int().optional(), VirtualRestaurantName: z.string().optional(), VirtualRestaurantUrl: z.string().optional(), PhysicalRestaurantId: z.number().int().optional(), PhysicalRestaurantName: z.string().optional(), PhysicalRestaurantAddress: z.string().optional(), MenuId: z.number().int().optional(), IsArchived: z.boolean().optional(), IsPublished: z.boolean().optional(), FlipdishStripeCustomConnectedAccounts: z.array(z.number().int()).optional()}); export const restApiPaginationResultRestaurant = z.object({Page: z.number().int(), Limit: z.number().int(), TotalRecordCount: z.number().int(), Data: z.array(restaurant)}); 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/search/restaurants */ export const getApiApiV10SearchRestaurants = async (args: GetApiApiV10SearchRestaurantsArgs, options?: GetApiApiV10SearchRestaurantsOptions) => { 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.query != null) query.append("query", String(args.query)) if (args.countryId != null) query.append("countryId", String(args.countryId)) if (args.includeArchivedStores != null) query.append("includeArchivedStores", String(args.includeArchivedStores)) if (args.searchType != null) query.append("searchType", String(args.searchType)) if (args.publishedStatus != null) query.append("publishedStatus", String(args.publishedStatus)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1.0/search/restaurants${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(restApiPaginationResultRestaurant, await res.json()) };