import {z} from 'zod' export type BigOvenModelAPIGroceryItem = {ItemID?: number | undefined, GUID?: string | undefined, RecipeID?: number | undefined, Name?: string | undefined, Notes?: string | undefined, DisplayQuantity?: string | undefined, Department?: string | undefined, CreationDate?: string | undefined, IsChecked?: boolean | undefined, LocalStatus?: string | undefined, LastModified?: string | undefined, BigOvenObject?: string | undefined, ThirdPartyURL?: string | undefined}; export type BigOvenModelAPIUserInfo = {UserID?: number | undefined, UserName?: string | undefined, ImageUrl48?: string | undefined, PhotoUrl48?: string | undefined, PhotoUrl?: string | undefined, WebUrl?: string | undefined, IsPremium?: boolean | undefined, IsKitchenHelper?: boolean | undefined, PremiumExpiryDate?: string | undefined, MemberSince?: string | undefined, IsUsingRecurly?: boolean | undefined, FirstName?: string | undefined, LastName?: string | undefined}; export type BigOvenModelAPIRecipeInfo = {RecipeID?: number | undefined, Title?: string | undefined, Cuisine?: string | undefined, Category?: string | undefined, Subcategory?: string | undefined, Microcategory?: string | undefined, StarRating?: number | undefined, StarRatingIMG?: string | undefined, WebURL?: string | undefined, ImageURL?: string | undefined, ImageURL120?: string | undefined, ReviewCount?: number | undefined, Poster?: BigOvenModelAPIUserInfo | undefined, IsPrivate?: boolean | undefined, HideFromPublicSearch?: boolean | undefined, IsBookmark?: boolean | undefined, BookmarkURL?: string | undefined, YieldNumber?: number | undefined, QualityScore?: number | undefined, CreationDate?: string | undefined, MaxImageSquare?: number | undefined, TotalTries?: number | undefined, HeroPhotoUrl?: string | undefined, HasVideos?: boolean | undefined}; export type BigOvenModelAPIGroceryGroceryList = {Items?: Array | undefined, Recipes?: Array | undefined, LastModified?: string | undefined, VersionGuid?: string | undefined}; export type API2ControllersWebAPIGroceryListControllerPostGroceryListSyncRequest = {list?: BigOvenModelAPIGroceryGroceryList | undefined, since?: string | undefined}; export type CreateApiGrocerylistSyncArgs = {body: API2ControllersWebAPIGroceryListControllerPostGroceryListSyncRequest}; export type CreateApiGrocerylistSyncOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const systemObject = z.object({}); 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 }; /** * Synchronize the grocery list. Call this with a POST to /grocerylist/sync * * POST /grocerylist/sync */ export const createApiGrocerylistSync = async (args: CreateApiGrocerylistSyncArgs, options?: CreateApiGrocerylistSyncOptions) => { const {baseUrl = "https://api2.bigoven.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/grocerylist/sync${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(systemObject, await res.json()) };