import {z} from 'zod' export type API2ModelsLocation = {City?: string | undefined, Country?: string | undefined, DMA?: number | undefined}; export type API2ModelsPersonal = {Email?: string | undefined, Location?: API2ModelsLocation | undefined}; export type API2ModelsAccounting = {MemberSince?: string | undefined, CreditBalance?: number | undefined, PremiumExpiryDate?: string | undefined, UserLevel?: string | undefined}; export type API2ModelsPreference = {EatingStyle?: string | undefined}; export type API2ModelsCounts = {FollowingCount?: number | undefined, AddedCount?: number | undefined, FollowersCount?: number | undefined, PublicRecipeCount?: number | undefined, PrivateRecipeCount?: number | undefined, TotalRecipes?: number | undefined}; export type API2ModelsProfile = {FullName?: string | undefined, Counts?: API2ModelsCounts | undefined, AboutMe?: string | undefined, FirstName?: string | undefined, LastName?: string | undefined, UserID?: number | undefined, HomeUrl?: string | undefined, PhotoUrl?: string | undefined, UserName?: string | undefined, BackgroundUrl?: string | undefined}; export type API2ModelsBigOvenUser = {BOAuthToken?: string | undefined, Personal?: API2ModelsPersonal | undefined, Accounting?: API2ModelsAccounting | undefined, LastChangeLogID?: string | undefined, Preferences?: API2ModelsPreference | undefined, Profile?: API2ModelsProfile | undefined}; export type UpdateApiMeArgs = {body: API2ModelsBigOvenUser}; export type UpdateApiMeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const aPI2ModelsLocation = z.object({City: z.string().optional(), Country: z.string().optional(), DMA: z.number().int().optional()}); export const aPI2ModelsPersonal = z.object({Email: z.string().optional(), Location: aPI2ModelsLocation.optional()}); export const aPI2ModelsAccounting = z.object({MemberSince: z.string().optional(), CreditBalance: z.number().int().optional(), PremiumExpiryDate: z.string().optional(), UserLevel: z.string().optional()}); export const aPI2ModelsPreference = z.object({EatingStyle: z.string().optional()}); export const aPI2ModelsCounts = z.object({FollowingCount: z.number().int().optional(), AddedCount: z.number().int().optional(), FollowersCount: z.number().int().optional(), PublicRecipeCount: z.number().int().optional(), PrivateRecipeCount: z.number().int().optional(), TotalRecipes: z.number().int().optional()}); export const aPI2ModelsProfile = z.object({FullName: z.string().optional(), Counts: aPI2ModelsCounts.optional(), AboutMe: z.string().optional(), FirstName: z.string().optional(), LastName: z.string().optional(), UserID: z.number().int().optional(), HomeUrl: z.string().optional(), PhotoUrl: z.string().optional(), UserName: z.string().optional(), BackgroundUrl: z.string().optional()}); export const aPI2ModelsBigOvenUser = z.object({BOAuthToken: z.string().optional(), Personal: aPI2ModelsPersonal.optional(), Accounting: aPI2ModelsAccounting.optional(), LastChangeLogID: z.string().optional(), Preferences: aPI2ModelsPreference.optional(), Profile: aPI2ModelsProfile.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 }; /** * Puts me. * * PUT /me */ export const updateApiMe = async (args: UpdateApiMeArgs, options?: UpdateApiMeOptions) => { 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(/\/+$/, '')}/me${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(aPI2ModelsBigOvenUser, await res.json()) };