import {z} from 'zod' export type GetApiPhoneBulkV1BatchesBatchIdResultsArgs = {'Reference-Id'?: string | undefined, batch_id: string, 'Add-Metadata'?: boolean | undefined}; export type GetApiPhoneBulkV1BatchesBatchIdResultsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const responseError = z.object({type: z.string().nullable().optional(), title: z.string().nullable().optional(), detail: z.string().nullable().optional(), instance: z.string().nullable().optional()}); export const bulkPhoneV1GetBatchResultsResponseStatistic = z.object({name: z.string().nullable().optional(), value: z.number().int().optional()}); export const bulkPhoneV1GetBatchResultsResponsePhoneMetadata = z.object({original_operator_name: z.string().nullable().optional(), original_network_status: z.string().nullable().optional(), original_home_network_identity: z.string().nullable().optional(), original_country_prefix: z.string().nullable().optional(), original_country_name: z.string().nullable().optional(), original_country_iso: z.string().nullable().optional(), operator_name: z.string().nullable().optional(), network_status: z.string().nullable().optional(), home_network_identity: z.string().nullable().optional(), country_prefix: z.string().nullable().optional(), country_name: z.string().nullable().optional(), country_iso: z.string().nullable().optional(), is_ported: z.string().nullable().optional(), email_to_sms_address: z.string().nullable().optional(), email_to_mms_address: z.string().nullable().optional()}); export const bulkPhoneV1GetBatchResultsResponsePhone = z.object({number: z.string().nullable().optional(), validated_phone_number: z.string().nullable().optional(), formatted_phone_number: z.string().nullable().optional(), phone_type: z.string().nullable().optional(), confidence: z.string().nullable().optional(), ported_date: z.string().nullable().optional(), disposable_number: z.string().nullable().optional(), metadata: bulkPhoneV1GetBatchResultsResponsePhoneMetadata.optional()}); export const bulkPhoneV1GetBatchResultsResult = z.object({batch_id: z.string().nullable().optional(), batch_reference_id: z.string().nullable().optional(), credits_charged: z.number().int().optional(), status: z.string().nullable().optional(), reason: z.string().nullable().optional(), statistics: z.array(bulkPhoneV1GetBatchResultsResponseStatistic).nullable().optional(), phones: z.array(bulkPhoneV1GetBatchResultsResponsePhone).nullable().optional()}); export const bulkPhoneV1GetBatchResultsResponse = z.object({error: responseError.optional(), result: bulkPhoneV1GetBatchResultsResult.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 }; /** * Gets the validation result of a batch of phone numbers. * * GET /phone/bulk/v1/batches/{batch_id}/results * * Also accepts auth: Auth-Token */ export const getApiPhoneBulkV1BatchesBatchIdResults = async (args: GetApiPhoneBulkV1BatchesBatchIdResultsArgs, options?: GetApiPhoneBulkV1BatchesBatchIdResultsOptions) => { const {baseUrl = "https://api.experianaperture.io", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Reference-Id'] != null) headers.set("Reference-Id", String(args['Reference-Id'])) if (args['Add-Metadata'] != null) headers.set("Add-Metadata", String(args['Add-Metadata'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/phone/bulk/v1/batches/${encodeURIComponent(String(args.batch_id))}/results${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(bulkPhoneV1GetBatchResultsResponse, await res.json()) };