import {z} from 'zod' export type CreateApiCompatV2UsersUpdatePreferencesArgs = {body: {preferencesVersion?: number | undefined, 'global.enableSplitPane'?: boolean | undefined, 'global.language'?: ('en-us' | 'it-it' | 'de-de' | 'uk-ua' | 'he' | 'es-es' | 'fr-fr' | 'ru-ru' | 'hu-hu' | 'da-dk' | 'zh-cn' | 'pt-pt' | 'pt-br' | 'nl' | 'pl' | 'ja' | 'lt' | 'eu' | 'el' | 'fi' | 'sv' | 'ro' | 'cs' | 'ar-sa' | 'hi' | 'es-mx' | 'ko' | 'nb-no' | 'tr' | 'zh-hant' | null) | undefined, 'global.fontSize'?: ('1rem' | '14px' | '16px' | '18px' | '20px' | '22px' | '24px') | undefined, 'global.theme'?: ('default' | 'light' | 'dark' | 'black' | 'midnight') | undefined, 'global.preferencesSync'?: ('enabled' | 'disabled') | undefined, 'global.startPage'?: ('myRecipes' | 'manageLabels' | 'mealPlans' | 'shoppingLists') | undefined, 'global.offlineModePrompt'?: ('ask' | 'never') | undefined, 'myRecipes.enableLabelIntersection'?: boolean | undefined, 'myRecipes.showLabels'?: boolean | undefined, 'myRecipes.showLabelChips'?: boolean | undefined, 'myRecipes.showImages'?: boolean | undefined, 'myRecipes.showSource'?: boolean | undefined, 'myRecipes.showRecipeDescription'?: boolean | undefined, 'myRecipes.showRating'?: boolean | undefined, 'myRecipes.viewType'?: ('tiles' | 'list' | 'compact') | undefined, 'myRecipes.sortBy'?: ('title' | '-createdAt' | 'createdAt' | '-updatedAt' | 'updatedAt' | '-lastMadeAt' | 'lastMadeAt') | undefined, 'myRecipes.includeFriends'?: ('yes' | 'no' | 'search' | 'browse') | undefined, 'recipeDetails.enableWakeLock'?: boolean | undefined, 'recipeDetails.autoExpandNutrition'?: boolean | undefined, 'recipeDetails.layout'?: ('automatic' | 'stacked' | 'sideBySide' | 'sideBySideEqualWidth' | 'tabs') | undefined, 'cookMode.fontSize'?: ('1rem' | '14px' | '16px' | '18px' | '20px' | '22px' | '24px') | undefined, 'manageLabels.showCreatedAt'?: boolean | undefined, 'measurementConverter.enabledUnits'?: Array | undefined, 'MealPlan.showAddedBy'?: boolean | undefined, 'MealPlan.showAddedOn'?: boolean | undefined, 'MealPlan.startOfWeek'?: ('monday' | 'sunday') | undefined, 'MealPlan.viewType'?: ('calendar' | 'list') | undefined, 'ShoppingList.sortBy'?: ('title' | '-title' | 'createdAt' | '-createdAt') | undefined, 'ShoppingList.showAddedBy'?: boolean | undefined, 'ShoppingList.showAddedOn'?: boolean | undefined, 'ShoppingList.showRecipeTitle'?: boolean | undefined, 'ShoppingList.preferDelete'?: boolean | undefined, 'ShoppingList.groupSimilar'?: boolean | undefined, 'ShoppingList.groupCategories'?: boolean | undefined, 'ShoppingList.ignoreItemTitles'?: string | undefined}}; export type CreateApiCompatV2UsersUpdatePreferencesOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiCompatV2UsersUpdatePreferencesResponse = 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 the caller's stored app preferences * * POST /compat/v2/users/updatePreferences */ export const createApiCompatV2UsersUpdatePreferences = async (args: CreateApiCompatV2UsersUpdatePreferencesArgs, options?: CreateApiCompatV2UsersUpdatePreferencesOptions) => { 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/users/updatePreferences${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(createApiCompatV2UsersUpdatePreferencesResponse, await res.json()) };