import {z} from 'zod' export type DeleteApiAccountsAidCustomersUsersCustomerIdArgs = {aid: unknown, customer_id: string, delete_tokens?: boolean | undefined}; export type DeleteApiAccountsAidCustomersUsersCustomerIdOptions = {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 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_cid_delete * * DELETE /accounts/{aid}/customers/users/{customer_id} */ export const deleteApiAccountsAidCustomersUsersCustomerId = async (args: DeleteApiAccountsAidCustomersUsersCustomerIdArgs, options?: DeleteApiAccountsAidCustomersUsersCustomerIdOptions) => { 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.delete_tokens != null) query.append("delete_tokens", String(args.delete_tokens)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/customers/users/${encodeURIComponent(String(args.customer_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(customerResponse, await res.json()) };