import {z} from 'zod' export type DeleteApiV1AddressesIdArgs = {id: string}; export type DeleteApiV1AddressesIdOptions = {baseUrl: string, TokenBasic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const addressValidation = z.object({success: z.boolean(), meta: z.record(z.string(), z.unknown()).nullable().optional()}); export const address = z.object({id: z.string().optional(), postal_code: z.string().max(10).nullable().optional(), city: z.string().max(30).nullable().optional(), federal_tax_id: z.string().max(20).nullable().optional(), state_tax_id: z.string().max(20).nullable().optional(), person_name: z.string().max(50).nullable().optional(), company_name: z.string().max(50).nullable().optional(), country_code: z.enum(["AC", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GT", "GU", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "IC", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KV", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PR", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SY", "SZ", "TC", "TD", "TG", "TH", "TJ", "TL", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WS", "XB", "XC", "XE", "XM", "XN", "XS", "XY", "YE", "YT", "ZA", "ZM", "ZW", "EH", "IM", "BL", "MF", "SX"]), email: z.string().nullable().optional(), phone_number: z.string().max(20).nullable().optional(), state_code: z.string().max(20).nullable().optional(), residential: z.boolean().nullable().optional(), street_number: z.string().max(20).nullable().optional(), address_line1: z.string().max(50).nullable().optional(), address_line2: z.string().max(50).nullable().optional(), validate_location: z.boolean().nullable().optional(), object_type: z.string().optional(), validation: addressValidation.nullable().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 }; /** * Discard an address * * DELETE /v1/addresses/{id} * * Also accepts auth: Token, OAuth2, JWT */ export const deleteApiV1AddressesId = async (args: DeleteApiV1AddressesIdArgs, options: DeleteApiV1AddressesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, TokenBasic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (TokenBasic !== undefined) headers.set('authorization', `Basic ${btoa(`${TokenBasic.username}:${TokenBasic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/addresses/${encodeURIComponent(String(args.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(address, await res.json()) };