import {z} from 'zod' export type Link = {href?: string | undefined, rel?: string | undefined} | null; export type AttributeType = 'TEXT' | 'MULTISELECT'; export type CustomAttributeAccountV2 = {attributeType?: AttributeType | undefined, hint?: string | undefined, label?: string | undefined, name?: string | undefined, value?: string | undefined, valueKeys?: Array | undefined}; export type EducationAccountV2 = {current?: boolean | undefined, degree?: string | undefined, endYear?: number | undefined, field?: string | undefined, school?: string | undefined, startYear?: number | undefined}; export type EmailAddressType = 'PERSONAL' | 'WORK'; export type EmailAddressAccountV2 = {address?: string | undefined, type?: EmailAddressType | undefined, verified?: boolean | undefined}; export type IMType = 'YAHOO' | 'MSN' | 'GOOGLE_TALK' | 'JABBER' | 'AIM' | 'SKYPE' | 'ICQ' | 'COMUNICATOR' | 'OTHER'; export type IM = {account?: string | undefined, type?: IMType | undefined}; export type WorkExperienceAccountV2 = {current?: boolean | undefined, description?: string | undefined, employer?: string | undefined, endYear?: number | undefined, position?: string | undefined, startYear?: number | undefined}; export type UserProfileAccountV2 = {links?: Array | undefined, birthday?: string | undefined, currentCity?: string | undefined, customAttributes?: Array | undefined, educations?: Array | undefined, emailAddresses?: Array | undefined, homePhone?: string | undefined, hometown?: string | undefined, ims?: Array | undefined, mobilePhone?: string | undefined, twitter?: string | undefined, twoFactorAuthenticationMethod?: string | undefined, workExperiences?: Array | undefined, workPhone?: string | undefined} | null; export type PatchApiAccountV2UsersUserUuidProfileArgs = {userUuid: string, removeUnspecifiedCustomAttributes?: boolean | undefined, body: UserProfileAccountV2}; export type PatchApiAccountV2UsersUserUuidProfileOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({href: z.string().optional(), rel: z.string().optional()}).nullable(); export const attributeType = z.enum(["TEXT", "MULTISELECT"]); export const customAttributeAccountV2 = z.object({attributeType: attributeType.optional(), hint: z.string().optional(), label: z.string().optional(), name: z.string().optional(), value: z.string().optional(), valueKeys: z.array(z.string()).optional()}); export const educationAccountV2 = z.object({current: z.boolean().optional(), degree: z.string().optional(), endYear: z.number().optional(), field: z.string().optional(), school: z.string().optional(), startYear: z.number().optional()}); export const emailAddressType = z.enum(["PERSONAL", "WORK"]); export const emailAddressAccountV2 = z.object({address: z.string().optional(), type: emailAddressType.optional(), verified: z.boolean().optional()}); export const iMType = z.enum(["YAHOO", "MSN", "GOOGLE_TALK", "JABBER", "AIM", "SKYPE", "ICQ", "COMUNICATOR", "OTHER"]); export const iM = z.object({account: z.string().optional(), type: iMType.optional()}); export const workExperienceAccountV2 = z.object({current: z.boolean().optional(), description: z.string().optional(), employer: z.string().optional(), endYear: z.number().optional(), position: z.string().optional(), startYear: z.number().optional()}); export const userProfileAccountV2 = z.object({links: z.array(link).optional(), birthday: z.string().optional(), currentCity: z.string().optional(), customAttributes: z.array(customAttributeAccountV2).optional(), educations: z.array(educationAccountV2).optional(), emailAddresses: z.array(emailAddressAccountV2).optional(), homePhone: z.string().optional(), hometown: z.string().optional(), ims: z.array(iM).optional(), mobilePhone: z.string().optional(), twitter: z.string().optional(), twoFactorAuthenticationMethod: z.string().optional(), workExperiences: z.array(workExperienceAccountV2).optional(), workPhone: z.string().optional()}).nullable(); 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 }; /** * Patch user profile * * PATCH /account/v2/users/{userUuid}/profile */ export const patchApiAccountV2UsersUserUuidProfile = async (args: PatchApiAccountV2UsersUserUuidProfileArgs, options?: PatchApiAccountV2UsersUserUuidProfileOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.removeUnspecifiedCustomAttributes != null) query.append("removeUnspecifiedCustomAttributes", String(args.removeUnspecifiedCustomAttributes)) const url = `${baseUrl.replace(/\/+$/, '')}/account/v2/users/${encodeURIComponent(String(args.userUuid))}/profile${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(userProfileAccountV2, await res.json()) };