import {z} from 'zod' export type GetApiRecipesRecentviewsArgs = {pg?: number | undefined, rpp?: number | undefined}; export type GetApiRecipesRecentviewsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; 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 bigOvenModelRecipeInfoDateTuple2 = z.object({recipeInfo: bigOvenModelAPI2RecipeInfox.optional(), date: z.string().optional()}); export const getApiRecipesRecentviewsResponse = z.array(bigOvenModelRecipeInfoDateTuple2); 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 a list of recipes that the authenticated user has most recently viewed * * GET /recipes/recentviews */ export const getApiRecipesRecentviews = async (args: GetApiRecipesRecentviewsArgs, options?: GetApiRecipesRecentviewsOptions) => { const {baseUrl = "https://api2.bigoven.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pg != null) query.append("pg", String(args.pg)) if (args.rpp != null) query.append("rpp", String(args.rpp)) const url = `${baseUrl.replace(/\/+$/, '')}/recipes/recentviews${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(getApiRecipesRecentviewsResponse, await res.json()) };