import {z} from 'zod' export type CreateApiCompatV2RecipesUpdateRecipeArgs = {body: {id: string, title: string, description: string, yield: string, activeTime: string, totalTime: string, source: string, url: string, notes: string, ingredients: string, instructions: string, rating: number | null, folder: 'main' | 'inbox', labelIds: Array, imageIds: Array, lastMadeAt?: (string | null) | undefined, linkedRecipeIds?: Array | undefined, nutritionServingSize?: (string | null) | undefined, nutritionCalories?: (number | null) | undefined, nutritionTotalFat?: (number | null) | undefined, nutritionSaturatedFat?: (number | null) | undefined, nutritionTransFat?: (number | null) | undefined, nutritionPolyunsaturatedFat?: (number | null) | undefined, nutritionMonounsaturatedFat?: (number | null) | undefined, nutritionCholesterol?: (number | null) | undefined, nutritionSodium?: (number | null) | undefined, nutritionTotalCarbs?: (number | null) | undefined, nutritionDietaryFiber?: (number | null) | undefined, nutritionTotalSugars?: (number | null) | undefined, nutritionAddedSugars?: (number | null) | undefined, nutritionProtein?: (number | null) | undefined, nutritionVitaminD?: (number | null) | undefined, nutritionCalcium?: (number | null) | undefined, nutritionIron?: (number | null) | undefined, nutritionPotassium?: (number | null) | undefined, nutritionOtherDetails?: (string | null) | undefined}}; export type CreateApiCompatV2RecipesUpdateRecipeOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiCompatV2RecipesUpdateRecipeResponse = z.object({id: z.string()}); 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 }; /** * Update a recipe * * POST /compat/v2/recipes/updateRecipe */ export const createApiCompatV2RecipesUpdateRecipe = async (args: CreateApiCompatV2RecipesUpdateRecipeArgs, options?: CreateApiCompatV2RecipesUpdateRecipeOptions) => { const {baseUrl = "https://api.recipesage.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/compat/v2/recipes/updateRecipe${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(createApiCompatV2RecipesUpdateRecipeResponse, await res.json()) };