import {z} from 'zod' export type PatchApiPersonasPersonaIdArgs = {personaId: string, accountId: string, body: {emailAddress?: (string | null) | undefined, employeeNumber?: (string | null) | undefined, workNumber?: (string | null) | undefined, jobTitle?: (string | null) | undefined, status?: ('active' | 'deactivated') | undefined, transactionalEmailPreference?: (boolean | null) | undefined, marketingEmailsPreference?: (boolean | null) | undefined, securityNotificationsPreference?: (boolean | null) | undefined, cardTransactionPushNotificationPreference?: boolean | undefined}}; export type PatchApiPersonasPersonaIdOptions = {baseUrl?: string | undefined, CommonAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiPersonasPersonaIdResponse = z.object({id: z.string(), accountId: z.string(), emailAddress: z.string().max(256).nullable(), employeeNumber: z.string().max(256).nullable(), workNumber: z.string().max(50).nullable(), jobTitle: z.string().max(256).nullable(), status: z.enum(["active", "deactivated", "created", "invited", "inviteExpired"]).nullable(), addresses: z.array(z.object({id: z.string(), type: z.string(), nickName: z.string().max(256).nullable().optional(), addressLine1: z.string().min(1).max(256), addressLine2: z.string().max(256).nullable().optional(), addressLine3: z.string().max(256).nullable().optional(), addressContact: z.string().max(256).nullable().optional(), city: z.string().max(256), postcode: z.string().max(50), country: z.string().max(256), countryCode: z.string().max(2).nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()})).optional(), createdBy: z.record(z.string(), z.unknown()).nullable().optional(), createdByPersonaId: z.string().max(36).nullable(), primaryOwnerOf: z.record(z.string(), z.unknown()).nullable().optional(), teams: z.array(z.object({id: z.string(), accountId: z.string().optional(), name: z.string().max(256).nullable(), description: z.string().max(256).nullable(), enabled: z.boolean(), createdAt: z.string(), updatedAt: z.string()})).optional(), transactionalEmailPreference: z.boolean().nullable().optional(), cardTransactionPushNotificationPreference: z.boolean().optional(), inviteSentDate: z.string().nullable().optional(), marketingEmails: z.boolean(), securityNotifications: z.boolean(), createdAt: z.string().optional(), updatedAt: z.string().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 }; /** * Update a persona * * PATCH /personas/{personaId} */ export const patchApiPersonasPersonaId = async (args: PatchApiPersonasPersonaIdArgs, options?: PatchApiPersonasPersonaIdOptions) => { const {baseUrl = "https://api.equalsmoney.com/v2", fetch: fetchFn = fetch, CommonAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (CommonAuth !== undefined) headers.set("Authorization", CommonAuth) const url = `${baseUrl.replace(/\/+$/, '')}/personas/${encodeURIComponent(String(args.personaId))}${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(patchApiPersonasPersonaIdResponse, await res.json()) };