import {z} from 'zod' export type GetApiCustomerV1GetAllCustomersArgs = {activeFlag?: boolean | undefined, authenticationtoken: string, customerAccountNumber?: string | undefined, customerCode?: string | undefined, locationCode?: string | undefined, password: string, sitename: string, userid: string, 'X-B3-TraceId'?: string | undefined, includeNull?: boolean | undefined}; export type GetApiCustomerV1GetAllCustomersOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const customerDetailsDtoRes = z.object({activeFlag: z.string().optional(), address1: z.string(), address2: z.string().optional(), city: z.string(), country: z.string(), customerAccountNumber: z.string().optional(), customerCode: z.string(), customerName: z.string(), exportCode: z.string().optional(), importCode: z.string().optional(), locationCode: z.string(), retailPricing: z.string().optional(), state: z.string().optional(), supplyPricing: z.string(), zipcode: z.string().optional()}); export const customerDetailsRes = z.object({customerDetailDetails: z.array(customerDetailsDtoRes).optional()}); export const getApiCustomerV1GetAllCustomersResponse = z.array(customerDetailsRes); 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 }; /** * getAllCustomers * * GET /customer/v1/getAllCustomers */ export const getApiCustomerV1GetAllCustomers = async (args: GetApiCustomerV1GetAllCustomersArgs, options: GetApiCustomerV1GetAllCustomersOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.activeFlag != null) query.append("activeFlag", String(args.activeFlag)) if (args.authenticationtoken != null) headers.set("authenticationtoken", String(args.authenticationtoken)) if (args.customerAccountNumber != null) query.append("customerAccountNumber", String(args.customerAccountNumber)) if (args.customerCode != null) query.append("customerCode", String(args.customerCode)) if (args.locationCode != null) query.append("locationCode", String(args.locationCode)) if (args.password != null) headers.set("password", String(args.password)) if (args.sitename != null) headers.set("sitename", String(args.sitename)) if (args.userid != null) headers.set("userid", String(args.userid)) if (args['X-B3-TraceId'] != null) headers.set("X-B3-TraceId", String(args['X-B3-TraceId'])) if (args.includeNull != null) query.append("includeNull", String(args.includeNull)) const url = `${baseUrl.replace(/\/+$/, '')}/customer/v1/getAllCustomers${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(getApiCustomerV1GetAllCustomersResponse, await res.json()) };