import {z} from 'zod' export type UpdateUser = {status: 'ACTIVE' | 'DEACTIVE' | 'CLOSED', created_on?: unknown | undefined, internal_user_id: string, address1: string, address2?: string | undefined, city: string, state_province: string, postal_code: string, country: string, first_name: string, middle_name?: string | undefined, last_name: string, email: string, language?: string | undefined, mobile_number?: string | undefined, business_name?: string | undefined, date_of_birth?: string | undefined, metadata?: Record | undefined}; export type UpdateApiPayoutUserUserTokenArgs = {user_token: string, 'Idempotency-Key'?: string | undefined, body: UpdateUser}; export type UpdateApiPayoutUserUserTokenOptions = {baseUrl?: string | undefined, AUTHORIZERNAME?: string | undefined, fetch?: typeof fetch | undefined}; export const storedUser = z.object({user_token: z.string(), status: z.enum(["ACTIVE", "LOCKED", "DEACTIVE", "CLOSED"]), created_on: z.string(), internal_user_id: z.string(), address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), state_province: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), first_name: z.string(), middle_name: z.string().optional(), last_name: z.string(), email: z.string(), language: z.string().optional(), mobile_number: z.string().optional(), business_name: z.string().optional(), timezone: z.string(), date_of_birth: z.string().optional(), metadata: z.object({}).optional(), activation_url: 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 }; /** * Updated user * * PUT /payout/user/{user_token} * * Also accepts auth: api_key */ export const updateApiPayoutUserUserToken = async (args: UpdateApiPayoutUserUserTokenArgs, options?: UpdateApiPayoutUserUserTokenOptions) => { const {baseUrl = "https://api.masspay.io/v1.0.0", fetch: fetchFn = fetch, AUTHORIZERNAME} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (AUTHORIZERNAME !== undefined) headers.set("Authorization", AUTHORIZERNAME) const url = `${baseUrl.replace(/\/+$/, '')}/payout/user/${encodeURIComponent(String(args.user_token))}${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(storedUser, await res.json()) };