import {z} from 'zod' export type GetApiAccountV2UsersUserUuidProfileArgs = {userUuid: string}; export type GetApiAccountV2UsersUserUuidProfileOptions = {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 }; /** * Read user profile * * GET /account/v2/users/{userUuid}/profile */ export const getApiAccountV2UsersUserUuidProfile = async (args: GetApiAccountV2UsersUserUuidProfileArgs, options?: GetApiAccountV2UsersUserUuidProfileOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/account/v2/users/${encodeURIComponent(String(args.userUuid))}/profile${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(userProfileAccountV2, await res.json()) };