import {z} from 'zod' export type GetApiV2PartitionPartitionIdTelephonenumberTnArgs = {partitionId: string, tn: string}; export type GetApiV2PartitionPartitionIdTelephonenumberTnOptions = {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 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 }; /** * Retrieve telephone number * * GET /v2/partition/{partitionId}/telephonenumber/{tn} */ export const getApiV2PartitionPartitionIdTelephonenumberTn = async (args: GetApiV2PartitionPartitionIdTelephonenumberTnArgs, options?: GetApiV2PartitionPartitionIdTelephonenumberTnOptions) => { 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 (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/telephonenumber/${encodeURIComponent(String(args.tn))}${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(telephoneNumberViewX, await res.json()) };