import {z} from 'zod' export type GetApiV2PartitionPartitionIdTelephonenumberSearchArgs = {carrierId?: string | undefined, functiontype?: ('ELS' | 'TollFree' | 'TemporaryNumber' | 'SPTN') | undefined, lat?: number | undefined, long?: number | undefined, maxResults?: number | undefined, partitionId: string, q?: string | undefined, type?: ('POSTALCODE_OR_TN' | 'TN' | 'POSTALCODE' | 'LAT_LONG' | 'RATECENTER' | 'RATECENTER_CARRIER') | undefined}; export type GetApiV2PartitionPartitionIdTelephonenumberSearchOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const telephoneNumberViewX = z.object({partitionId: z.string().optional(), phoneNumber: z.string().optional(), rateCenter: z.string().optional(), rateCenterReorderName: z.string().optional(), state: z.string().optional(), country: z.string().optional(), prefix: z.string().optional(), accountId: z.string().optional(), carrierId: z.string().optional(), cooldownExpireDate: z.string().optional(), cooldownRecoveredDate: z.string().optional(), functionType: z.enum(["ELS", "TollFree", "TemporaryNumber", "SPTN"]).optional(), claimTicketId: z.string().optional(), matchesZip: z.boolean().optional(), distance: z.number().optional(), byotn: z.boolean().optional(), activationDate: z.number().int().optional(), isInInventory: z.boolean().optional(), operationalStatus: z.enum(["ACTIVE", "STAGED"]).optional(), id: z.string().optional(), port: z.boolean().optional(), tags: z.array(z.string()).optional()}); export const getApiV2PartitionPartitionIdTelephonenumberSearchResponse = z.array(telephoneNumberViewX); 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 }; /** * Telephone number search * * GET /v2/partition/{partitionId}/telephonenumber/search */ export const getApiV2PartitionPartitionIdTelephonenumberSearch = async (args: GetApiV2PartitionPartitionIdTelephonenumberSearchArgs, options?: GetApiV2PartitionPartitionIdTelephonenumberSearchOptions) => { 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.carrierId != null) query.append("carrierId", String(args.carrierId)) if (args.functiontype != null) query.append("functiontype", String(args.functiontype)) if (args.lat != null) query.append("lat", String(args.lat)) if (args.long != null) query.append("long", String(args.long)) if (args.maxResults != null) query.append("maxResults", String(args.maxResults)) if (args.q != null) query.append("q", String(args.q)) if (args.type != null) query.append("type", String(args.type)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/telephonenumber/search${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(getApiV2PartitionPartitionIdTelephonenumberSearchResponse, await res.json()) };