import {z} from 'zod' export type CreateApiGrocerylistClearcheckedlinesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bigOvenModelAPIGroceryItem = z.object({ItemID: z.number().int().optional(), GUID: z.string().optional(), RecipeID: z.number().int().optional(), Name: z.string().optional(), Notes: z.string().optional(), DisplayQuantity: z.string().optional(), Department: z.string().optional(), CreationDate: z.string().optional(), IsChecked: z.boolean().optional(), LocalStatus: z.string().optional(), LastModified: z.string().optional(), BigOvenObject: z.string().optional(), ThirdPartyURL: z.string().optional()}); export const bigOvenModelAPI2UserInfoTinyx = z.object({UserName: z.string().optional(), UserID: z.number().int().optional(), FirstName: z.string().optional(), LastName: z.string().optional(), PhotoUrl: z.string().optional()}); export const bigOvenModelAPI2RecipeInfox = z.object({RecipeID: z.number().int().optional(), Title: z.string().optional(), Cuisine: z.string().optional(), Category: z.string().optional(), Subcategory: z.string().optional(), Microcategory: z.string().optional(), StarRating: z.number().optional(), WebURL: z.string().optional(), ReviewCount: z.number().int().optional(), Poster: bigOvenModelAPI2UserInfoTinyx.optional(), IsPrivate: z.boolean().optional(), Servings: z.number().optional(), CreationDate: z.string().optional(), IsRecipeScan: z.boolean().optional(), IsBookmark: z.boolean().optional(), TotalTries: z.number().int().optional(), PhotoUrl: z.string().optional(), HasVideos: z.boolean().optional()}); export const bigOvenModelAPI2GroceryList = z.object({Items: z.array(bigOvenModelAPIGroceryItem).optional(), Recipes: z.array(bigOvenModelAPI2RecipeInfox).optional(), LastModified: z.string().optional(), VersionGuid: z.string().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 }; /** * Clears the checked lines. * * POST /grocerylist/clearcheckedlines */ export const createApiGrocerylistClearcheckedlines = async (options?: CreateApiGrocerylistClearcheckedlinesOptions) => { const {baseUrl = "https://api2.bigoven.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/grocerylist/clearcheckedlines${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(bigOvenModelAPI2GroceryList, await res.json()) };