import {z} from 'zod' export type GetApiV2PartitionPartitionIdTelephonenumberExportstatussearch2Args = {accountId?: string | undefined, dateType?: ('FOCDate' | 'UpdatedDate' | 'CreatedDate') | undefined, endDate?: string | undefined, eventType?: Array | undefined, includeSubTns?: boolean | undefined, partitionId: string, startDate?: string | undefined, statusType?: Array | undefined, telephoneNumber?: string | undefined}; export type GetApiV2PartitionPartitionIdTelephonenumberExportstatussearch2Options = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const jobError = z.object({error: z.string().optional(), lineNumber: z.number().int().optional(), column: z.string().optional(), input: z.string().optional()}); export const job = z.object({id: z.string().optional(), name: z.string().optional(), userId: z.string().optional(), status: z.enum(["PENDING", "IN_PROGRESS", "DONE", "FAILED"]).optional(), errors: z.array(jobError).optional(), inputKey: z.string().optional(), outputKey: z.string().optional(), start: z.string().optional(), lastUpdated: z.string().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 }; /** * Export as CSV telephone number status search * * GET /v2/partition/{partitionId}/telephonenumber/exportstatussearch_2 */ export const getApiV2PartitionPartitionIdTelephonenumberExportstatussearch2 = async (args: GetApiV2PartitionPartitionIdTelephonenumberExportstatussearch2Args, options?: GetApiV2PartitionPartitionIdTelephonenumberExportstatussearch2Options) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.dateType != null) query.append("dateType", String(args.dateType)) if (args.endDate != null) query.append("endDate", String(args.endDate)) for (const item of args.eventType ?? []) query.append("eventType", String(item)) if (args.includeSubTns != null) query.append("includeSubTns", String(args.includeSubTns)) if (args.startDate != null) query.append("startDate", String(args.startDate)) for (const item of args.statusType ?? []) query.append("statusType", String(item)) if (args.telephoneNumber != null) query.append("telephoneNumber", String(args.telephoneNumber)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/telephonenumber/exportstatussearch_2${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(job, await res.json()) };