import {z} from 'zod' export type GetApiAccountsAidCustomersUsersArgs = {aid: unknown, token_value?: string | undefined, token_type?: string | undefined, email?: string | undefined, phone_number?: string | undefined, type?: ('customer' | 'company' | 'contact' | 'employee' | 'other' | 'any') | undefined, search?: string | undefined, tag_id?: string | undefined, include_deleted?: boolean | undefined, attributes_keys?: Array | undefined, attributes_values?: Array | undefined, since_datetime?: string | undefined, limit?: number | undefined, starting_after?: string | undefined, total?: boolean | undefined}; export type GetApiAccountsAidCustomersUsersOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const userConsent = z.object({consent: z.boolean().optional(), updated_at: z.string().optional()}); export const customerAddress = z.object({address_line: z.string(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string(), country: z.string(), latitude: z.number().optional(), longitude: z.number().optional(), type: z.enum(["custom", "home", "other", "work"]).optional(), custom_type: z.string().optional(), comment: z.string().optional()}); export const customerTerm = z.object({id: z.string().optional(), accepted_at: z.string().optional()}); export const customerResponse = z.object({metadata: z.object({}).optional(), id: z.string().optional(), created_at: z.string().optional(), created_by: z.string().optional(), updated_at: z.string().optional(), deleted_by: z.string().optional(), deleted_at: z.string().optional(), first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), attributes: z.object({}).optional(), status: z.string().nullable().optional(), favorite_store: z.string().nullable().optional(), enrolled_by: z.object({type: z.string().optional(), value: z.string().nullable()}).optional(), marketing_consent: z.object({sms: userConsent.optional(), email: userConsent.optional()}).and(z.record(z.string(), userConsent)).optional(), type: z.enum(["customer", "company", "contact", "employee", "other"]), addresses: z.array(customerAddress).optional(), term: customerTerm.optional(), company: z.object({organization_number: z.string().optional(), bussiness_name: z.string(), department: z.string().optional(), industry: z.string().optional(), website: z.string().optional(), number_of_employees: z.string().optional()}).optional(), gender: z.string().nullable().optional(), date_of_birth: z.string().nullable().optional(), contact_for: z.array(z.object({customer_id: z.string()})).optional(), customer_id: z.string().max(255)}); export const getApiAccountsAidCustomersUsersResponse = z.array(customerResponse); 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 }; /** * aid_customers_get * * GET /accounts/{aid}/customers/users */ export const getApiAccountsAidCustomersUsers = async (args: GetApiAccountsAidCustomersUsersArgs, options?: GetApiAccountsAidCustomersUsersOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.token_value != null) query.append("token_value", String(args.token_value)) if (args.token_type != null) query.append("token_type", String(args.token_type)) if (args.email != null) query.append("email", String(args.email)) if (args.phone_number != null) query.append("phone_number", String(args.phone_number)) if (args.type != null) query.append("type", String(args.type)) if (args.search != null) query.append("search", String(args.search)) if (args.tag_id != null) query.append("tag_id", String(args.tag_id)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.attributes_keys != null) query.append("attributes_keys", args.attributes_keys.join(',')) if (args.attributes_values != null) query.append("attributes_values", args.attributes_values.join(',')) if (args.since_datetime != null) query.append("since_datetime", String(args.since_datetime)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.total != null) query.append("total", String(args.total)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/customers/users${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(getApiAccountsAidCustomersUsersResponse, await res.json()) };