import {z} from 'zod' export type TelephoneNumberViewX = {partitionId?: string | undefined, phoneNumber?: string | undefined, rateCenter?: string | undefined, rateCenterReorderName?: string | undefined, state?: string | undefined, country?: string | undefined, prefix?: string | undefined, accountId?: string | undefined, carrierId?: string | undefined, cooldownExpireDate?: string | undefined, cooldownRecoveredDate?: string | undefined, functionType?: ('ELS' | 'TollFree' | 'TemporaryNumber' | 'SPTN') | undefined, claimTicketId?: string | undefined, matchesZip?: boolean | undefined, distance?: number | undefined, byotn?: boolean | undefined, activationDate?: number | undefined, isInInventory?: boolean | undefined, operationalStatus?: ('ACTIVE' | 'STAGED') | undefined, id?: string | undefined, port?: boolean | undefined, tags?: Array | undefined}; export type CreateApiV2PartitionPartitionIdTelephonenumberArgs = {partitionId: string, body: TelephoneNumberViewX}; export type CreateApiV2PartitionPartitionIdTelephonenumberOptions = {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 }; /** * Create telephone number in inventory * * POST /v2/partition/{partitionId}/telephonenumber */ export const createApiV2PartitionPartitionIdTelephonenumber = async (args: CreateApiV2PartitionPartitionIdTelephonenumberArgs, options?: CreateApiV2PartitionPartitionIdTelephonenumberOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) 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()) };