import {z} from 'zod' export type CustomerServiceRecordX = {id?: string | undefined, firstName?: string | undefined, middleInitial?: string | undefined, lastName?: string | undefined, businessName?: string | undefined, streetNumber?: string | undefined, streetNumberSuffix?: string | undefined, preDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, streetName?: string | undefined, streetSuffix?: string | undefined, postDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postalCode?: string | undefined, secondaryLocationDescription?: ('' | 'APARTMENT' | 'BUILDING' | 'BASEMENT' | 'DEPARTMENT' | 'FLOOR' | 'FRONT' | 'HANGER' | 'KEY' | 'LOBBY' | 'LOT' | 'LOWER' | 'OFFICE' | 'PENTHOUSE' | 'PIER' | 'REAR' | 'ROOM' | 'SIDE' | 'SLIP' | 'SPACE' | 'SUITE' | 'STOP' | 'TRAILER' | 'UNIT' | 'UPPER') | undefined, unit?: string | undefined, customerType?: ('BUSINESS' | 'RESIDENTIAL') | undefined, firstNameSecondary?: string | undefined, blockCustomerName?: boolean | undefined, customerName?: string | undefined}; export type TnData = {tn?: string | undefined, rateCenter?: string | undefined, wireless?: boolean | undefined}; export type TelecomSettingsX = {notes?: string | undefined, currentCarrier?: string | undefined, currentCarrierName?: string | undefined, localReseller?: string | undefined, loaDate?: string | undefined, disconnectInternetService?: boolean | undefined, disconnectTelevisionService?: boolean | undefined, tnData?: {[key: string]: TnData} | undefined}; export type FileDataBase64X = {contentType?: string | undefined, name?: string | undefined, contentBase64?: string | undefined}; export type SmsActionX = 'CHANGE_CAMPAIGN' | 'DISABLE' | 'ENABLE' | 'PORT_COMPLETED'; export type SmsSettingsX = {smsLoaDocumentVersionId?: string | undefined, updatedAt?: string | undefined, campaignId?: string | undefined, smsLoa?: FileDataBase64X | undefined, enableSMS?: boolean | undefined, createdAt?: string | undefined, authorizingPerson?: string | undefined, smsAction?: SmsActionX | undefined, smsCarrierId?: string | undefined, campaignName?: string | undefined, remoteCampaignId?: string | undefined}; export type PortX = {id?: string | undefined, partitionId?: string | undefined, accountId?: string | undefined, telephoneNumbers?: Array | undefined, status?: ('ACTIVE' | 'ACTIVATION_ON_HOLD' | 'ACTIVATION_PENDING' | 'PORT_PENDING' | 'CANCEL_PORT' | 'CANCEL_PORT_EXPIDITED' | 'DELETE_PENDING' | 'DELETED' | 'CANCEL_PORT_COMPLETE' | 'PORT_REJECTED' | 'INVENTORY' | 'INVENTORY_CLAIMED' | 'COOLDOWN' | 'RECOVERED') | undefined, sendLoa?: boolean | undefined, loaSaved?: boolean | undefined, carrierId?: string | undefined, carrierType?: ('LEVEL_3' | 'NO_API' | 'E911' | 'TELUS' | 'TELUS_API' | 'TELUS_ONEVOICE' | 'PROVTEL' | 'VERIZON_CARIANZA' | 'ONVOY_CARIANZA' | 'LEVEL3_CARIANZA' | 'BANDWIDTH' | 'LUMEN_IMS' | 'LUMEN_VOICE_LI_ELS' | 'SINCH' | 'SERVICE_PROVIDER_CARRIER') | undefined, customerServiceRecord?: CustomerServiceRecordX | undefined, crdDate?: string | undefined, billingTelephoneNumber?: string | undefined, portingWireType?: ('Wireless' | 'Wireline') | undefined, portingAuthorizedName?: string | undefined, wirelessAccountNumber?: string | undefined, wirelessPin?: string | undefined, focDate?: string | undefined, focDateTimeZone?: ('US/Samoa' | 'US/Hawaii' | 'US/Alaska' | 'US/Pacific' | 'US/Arizona' | 'US/Mountain' | 'US/Central' | 'US/Eastern' | 'America/St_Thomas' | 'Canada/Pacific' | 'Canada/Mountain' | 'Canada/Central' | 'Canada/Eastern' | 'Canada/Atlantic' | 'Canada/Newfoundland') | undefined, createdDate?: string | undefined, completedDate?: string | undefined, cancelType?: ('NORMAL' | 'EXPIDITED' | 'BY_CARRIER') | undefined, telecomSettings?: TelecomSettingsX | undefined, hotCutPortId?: string | undefined, portNow?: boolean | undefined, canAcceptSMS?: boolean | undefined, smsCallbackUrl?: string | undefined, smsSettings?: SmsSettingsX | undefined, tags?: Array | undefined}; export type L3SettingsX = {servicePackage?: ('Usage' | 'PrimaryLocalFlatRate' | 'PrimaryLocalAndDomesticLDFlatRate' | 'SecondaryLocalFlatRate' | 'SecondaryLocalAndDomesticLDFlatRate') | undefined, availableServicePackages?: (Array<'Usage' | 'PrimaryLocalFlatRate' | 'PrimaryLocalAndDomesticLDFlatRate' | 'SecondaryLocalFlatRate' | 'SecondaryLocalAndDomesticLDFlatRate'>) | undefined, seasonalSuspendServicePackage?: ('Usage' | 'PrimaryLocalFlatRate' | 'PrimaryLocalAndDomesticLDFlatRate' | 'SecondaryLocalFlatRate' | 'SecondaryLocalAndDomesticLDFlatRate') | undefined, b2BPartnerID?: string | undefined, customerServiceName?: string | undefined, bizOrg?: string | undefined, parentBizOrg?: string | undefined}; export type AddressX = {id?: string | undefined, firstName?: string | undefined, middleInitial?: string | undefined, lastName?: string | undefined, businessName?: string | undefined, streetNumber?: string | undefined, streetNumberSuffix?: string | undefined, preDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, streetName?: string | undefined, streetSuffix?: string | undefined, postDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postalCode?: string | undefined, secondaryLocationDescription?: ('' | 'APARTMENT' | 'BUILDING' | 'BASEMENT' | 'DEPARTMENT' | 'FLOOR' | 'FRONT' | 'HANGER' | 'KEY' | 'LOBBY' | 'LOT' | 'LOWER' | 'OFFICE' | 'PENTHOUSE' | 'PIER' | 'REAR' | 'ROOM' | 'SIDE' | 'SLIP' | 'SPACE' | 'SUITE' | 'STOP' | 'TRAILER' | 'UNIT' | 'UPPER') | undefined, unit?: string | undefined}; export type DirectoryListingX = {listed?: boolean | undefined, type?: ('ERROR' | 'LIST_PUBLISH' | 'LIST_NOT_PUBLISH' | 'NOT_LIST_NOT_PUBLISH' | 'PORTED' | 'COMPLEX') | undefined, address?: AddressX | undefined}; export type E911AddressX = {id?: string | undefined, firstName?: string | undefined, middleInitial?: string | undefined, lastName?: string | undefined, businessName?: string | undefined, streetNumber?: string | undefined, streetNumberSuffix?: string | undefined, preDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, streetName?: string | undefined, streetSuffix?: string | undefined, postDirectional?: ('' | 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW') | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined, postalCode?: string | undefined, secondaryLocationDescription?: ('' | 'APARTMENT' | 'BUILDING' | 'BASEMENT' | 'DEPARTMENT' | 'FLOOR' | 'FRONT' | 'HANGER' | 'KEY' | 'LOBBY' | 'LOT' | 'LOWER' | 'OFFICE' | 'PENTHOUSE' | 'PIER' | 'REAR' | 'ROOM' | 'SIDE' | 'SLIP' | 'SPACE' | 'SUITE' | 'STOP' | 'TRAILER' | 'UNIT' | 'UPPER') | undefined, unit?: string | undefined, customerType?: ('BUSINESS' | 'RESIDENTIAL') | undefined, latitude?: string | undefined, longitude?: string | undefined, language?: string | undefined}; export type TelephoneNumberAccountBareX = {phoneNumber?: string | undefined, referenceType?: ('SIP_TRUNK' | 'END_USER' | 'IVR' | 'LINE_APPEARANCE' | 'LINE_HUNTGROUP' | 'TELEPHONE' | 'VFAX' | 'BUSINESS_LINE' | 'BUSINESS_LINE_HUNT_GROUP' | 'CALL_GROUP' | 'CALL_QUEUE' | 'AUTO_ATTENDANT' | 'SPECIALTY_LINE' | 'CONTACT_CENTER') | undefined, referenceId?: string | undefined, functionType?: ('ELS' | 'TollFree' | 'TemporaryNumber' | 'SPTN') | undefined, canAcceptSMS?: boolean | undefined, operationalStatus?: ('ACTIVE' | 'STAGED') | undefined, portId?: string | undefined, servicePackageType?: ('Usage' | 'PrimaryLocalFlatRate' | 'PrimaryLocalAndDomesticLDFlatRate' | 'SecondaryLocalFlatRate' | 'SecondaryLocalAndDomesticLDFlatRate') | undefined, tollFree?: boolean | undefined, id?: string | undefined, tags?: Array | undefined}; export type TelephoneNumberActivationsV2X = {partitionId?: string | undefined, accountId?: string | undefined, port?: PortX | undefined, l3Settings?: L3SettingsX | undefined, customerServiceRecord?: CustomerServiceRecordX | undefined, directoryListing?: DirectoryListingX | undefined, e911Address?: E911AddressX | undefined, holdActivation?: boolean | undefined, telephoneNumbers?: Array | undefined, byotnCarrierId?: string | undefined, smsSettings?: SmsSettingsX | undefined, id?: string | undefined}; export type CreateApiV2PartitionPartitionIdAccountPrevalidateArgs = {partitionId: string, body: TelephoneNumberActivationsV2X}; export type CreateApiV2PartitionPartitionIdAccountPrevalidateOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const customerServiceRecordX = z.object({id: z.string().optional(), firstName: z.string().min(1).max(256).optional(), middleInitial: z.string().max(256).optional(), lastName: z.string().max(256).optional(), businessName: z.string().max(256).optional(), streetNumber: z.string().optional(), streetNumberSuffix: z.string().optional(), preDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), streetName: z.string().max(256).optional(), streetSuffix: z.string().optional(), postDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), city: z.string().max(256).optional(), state: z.string().optional(), country: z.string().optional(), postalCode: z.string().optional(), secondaryLocationDescription: z.enum(["", "APARTMENT", "BUILDING", "BASEMENT", "DEPARTMENT", "FLOOR", "FRONT", "HANGER", "KEY", "LOBBY", "LOT", "LOWER", "OFFICE", "PENTHOUSE", "PIER", "REAR", "ROOM", "SIDE", "SLIP", "SPACE", "SUITE", "STOP", "TRAILER", "UNIT", "UPPER"]).optional(), unit: z.string().max(10).optional(), customerType: z.enum(["BUSINESS", "RESIDENTIAL"]).optional(), firstNameSecondary: z.string().optional(), blockCustomerName: z.boolean().optional(), customerName: z.string().optional()}); export const tnData = z.object({tn: z.string().optional(), rateCenter: z.string().optional(), wireless: z.boolean().optional()}); export const telecomSettingsX = z.object({notes: z.string().optional(), currentCarrier: z.string().optional(), currentCarrierName: z.string().optional(), localReseller: z.string().optional(), loaDate: z.string().optional(), disconnectInternetService: z.boolean().optional(), disconnectTelevisionService: z.boolean().optional(), tnData: z.record(z.string(), tnData).optional()}); export const fileDataBase64X = z.object({contentType: z.string().optional(), name: z.string().optional(), contentBase64: z.string().optional()}); export const smsActionX = z.enum(["CHANGE_CAMPAIGN", "DISABLE", "ENABLE", "PORT_COMPLETED"]); export const smsSettingsX = z.object({smsLoaDocumentVersionId: z.string().optional(), updatedAt: z.string().optional(), campaignId: z.string().optional(), smsLoa: fileDataBase64X.optional(), enableSMS: z.boolean().optional(), createdAt: z.string().optional(), authorizingPerson: z.string().optional(), smsAction: smsActionX.optional(), smsCarrierId: z.string().optional(), campaignName: z.string().optional(), remoteCampaignId: z.string().optional()}); export const portX = z.object({id: z.string().optional(), partitionId: z.string().optional(), accountId: z.string().optional(), telephoneNumbers: z.array(z.string()).optional(), status: z.enum(["ACTIVE", "ACTIVATION_ON_HOLD", "ACTIVATION_PENDING", "PORT_PENDING", "CANCEL_PORT", "CANCEL_PORT_EXPIDITED", "DELETE_PENDING", "DELETED", "CANCEL_PORT_COMPLETE", "PORT_REJECTED", "INVENTORY", "INVENTORY_CLAIMED", "COOLDOWN", "RECOVERED"]).optional(), sendLoa: z.boolean().optional(), loaSaved: z.boolean().optional(), carrierId: z.string().optional(), carrierType: z.enum(["LEVEL_3", "NO_API", "E911", "TELUS", "TELUS_API", "TELUS_ONEVOICE", "PROVTEL", "VERIZON_CARIANZA", "ONVOY_CARIANZA", "LEVEL3_CARIANZA", "BANDWIDTH", "LUMEN_IMS", "LUMEN_VOICE_LI_ELS", "SINCH", "SERVICE_PROVIDER_CARRIER"]).optional(), customerServiceRecord: customerServiceRecordX.optional(), crdDate: z.string().optional(), billingTelephoneNumber: z.string().optional(), portingWireType: z.enum(["Wireless", "Wireline"]).optional(), portingAuthorizedName: z.string().optional(), wirelessAccountNumber: z.string().optional(), wirelessPin: z.string().max(15).optional(), focDate: z.string().optional(), focDateTimeZone: z.enum(["US/Samoa", "US/Hawaii", "US/Alaska", "US/Pacific", "US/Arizona", "US/Mountain", "US/Central", "US/Eastern", "America/St_Thomas", "Canada/Pacific", "Canada/Mountain", "Canada/Central", "Canada/Eastern", "Canada/Atlantic", "Canada/Newfoundland"]).optional(), createdDate: z.string().optional(), completedDate: z.string().optional(), cancelType: z.enum(["NORMAL", "EXPIDITED", "BY_CARRIER"]).optional(), telecomSettings: telecomSettingsX.optional(), hotCutPortId: z.string().optional(), portNow: z.boolean().optional(), canAcceptSMS: z.boolean().optional(), smsCallbackUrl: z.string().optional(), smsSettings: smsSettingsX.optional(), tags: z.array(z.string()).optional()}); export const l3SettingsX = z.object({servicePackage: z.enum(["Usage", "PrimaryLocalFlatRate", "PrimaryLocalAndDomesticLDFlatRate", "SecondaryLocalFlatRate", "SecondaryLocalAndDomesticLDFlatRate"]).optional(), availableServicePackages: z.array(z.enum(["Usage", "PrimaryLocalFlatRate", "PrimaryLocalAndDomesticLDFlatRate", "SecondaryLocalFlatRate", "SecondaryLocalAndDomesticLDFlatRate"])).optional(), seasonalSuspendServicePackage: z.enum(["Usage", "PrimaryLocalFlatRate", "PrimaryLocalAndDomesticLDFlatRate", "SecondaryLocalFlatRate", "SecondaryLocalAndDomesticLDFlatRate"]).optional(), b2BPartnerID: z.string().optional(), customerServiceName: z.string().optional(), bizOrg: z.string().optional(), parentBizOrg: z.string().optional()}); export const addressX = z.object({id: z.string().optional(), firstName: z.string().min(1).max(256).optional(), middleInitial: z.string().max(256).optional(), lastName: z.string().max(256).optional(), businessName: z.string().max(256).optional(), streetNumber: z.string().optional(), streetNumberSuffix: z.string().optional(), preDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), streetName: z.string().max(256).optional(), streetSuffix: z.string().optional(), postDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), city: z.string().max(256).optional(), state: z.string().optional(), country: z.string().optional(), postalCode: z.string().optional(), secondaryLocationDescription: z.enum(["", "APARTMENT", "BUILDING", "BASEMENT", "DEPARTMENT", "FLOOR", "FRONT", "HANGER", "KEY", "LOBBY", "LOT", "LOWER", "OFFICE", "PENTHOUSE", "PIER", "REAR", "ROOM", "SIDE", "SLIP", "SPACE", "SUITE", "STOP", "TRAILER", "UNIT", "UPPER"]).optional(), unit: z.string().max(10).optional()}); export const directoryListingX = z.object({listed: z.boolean().optional(), type: z.enum(["ERROR", "LIST_PUBLISH", "LIST_NOT_PUBLISH", "NOT_LIST_NOT_PUBLISH", "PORTED", "COMPLEX"]).optional(), address: addressX.optional()}); export const e911AddressX = z.object({id: z.string().optional(), firstName: z.string().optional(), middleInitial: z.string().optional(), lastName: z.string().optional(), businessName: z.string().optional(), streetNumber: z.string().optional(), streetNumberSuffix: z.string().optional(), preDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), streetName: z.string().optional(), streetSuffix: z.string().optional(), postDirectional: z.enum(["", "N", "NE", "E", "SE", "S", "SW", "W", "NW"]).optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), postalCode: z.string().optional(), secondaryLocationDescription: z.enum(["", "APARTMENT", "BUILDING", "BASEMENT", "DEPARTMENT", "FLOOR", "FRONT", "HANGER", "KEY", "LOBBY", "LOT", "LOWER", "OFFICE", "PENTHOUSE", "PIER", "REAR", "ROOM", "SIDE", "SLIP", "SPACE", "SUITE", "STOP", "TRAILER", "UNIT", "UPPER"]).optional(), unit: z.string().optional(), customerType: z.enum(["BUSINESS", "RESIDENTIAL"]).optional(), latitude: z.string().optional(), longitude: z.string().optional(), language: z.string().optional()}); export const telephoneNumberAccountBareX = z.object({phoneNumber: z.string().optional(), referenceType: z.enum(["SIP_TRUNK", "END_USER", "IVR", "LINE_APPEARANCE", "LINE_HUNTGROUP", "TELEPHONE", "VFAX", "BUSINESS_LINE", "BUSINESS_LINE_HUNT_GROUP", "CALL_GROUP", "CALL_QUEUE", "AUTO_ATTENDANT", "SPECIALTY_LINE", "CONTACT_CENTER"]).optional(), referenceId: z.string().optional(), functionType: z.enum(["ELS", "TollFree", "TemporaryNumber", "SPTN"]).optional(), canAcceptSMS: z.boolean().optional(), operationalStatus: z.enum(["ACTIVE", "STAGED"]).optional(), portId: z.string().optional(), servicePackageType: z.enum(["Usage", "PrimaryLocalFlatRate", "PrimaryLocalAndDomesticLDFlatRate", "SecondaryLocalFlatRate", "SecondaryLocalAndDomesticLDFlatRate"]).optional(), tollFree: z.boolean().optional(), id: z.string().optional(), tags: z.array(z.string()).optional()}); export const telephoneNumberActivationsV2X = z.object({partitionId: z.string().optional(), accountId: z.string().optional(), port: portX.optional(), l3Settings: l3SettingsX.optional(), customerServiceRecord: customerServiceRecordX.optional(), directoryListing: directoryListingX.optional(), e911Address: e911AddressX.optional(), holdActivation: z.boolean().optional(), telephoneNumbers: z.array(telephoneNumberAccountBareX).optional(), byotnCarrierId: z.string().optional(), smsSettings: smsSettingsX.optional(), id: z.string().optional()}); export const portAvailabilityResponseV2X = z.object({id: z.string().optional(), businessPartnerTicketID: z.string().optional(), carrierTicketId: z.string().optional(), requestedActivation: telephoneNumberActivationsV2X.optional(), serviceAvailable: z.boolean().optional(), carrierType: z.enum(["LEVEL_3", "NO_API", "E911", "TELUS", "TELUS_API", "TELUS_ONEVOICE", "PROVTEL", "VERIZON_CARIANZA", "ONVOY_CARIANZA", "LEVEL3_CARIANZA", "BANDWIDTH", "LUMEN_IMS", "LUMEN_VOICE_LI_ELS", "SINCH", "SERVICE_PROVIDER_CARRIER"]).optional(), earliestCRD: z.string().optional(), latestCRD: z.string().optional(), availabilityList: z.array(z.string()).optional(), resultCSRs: z.array(customerServiceRecordX).optional(), exception: z.string().optional(), thirdPartyResultCode: z.string().optional(), thirdPartyResultContext: z.string().optional(), thirdPartyResultMessage: z.string().optional(), directoryListingAllowed: z.boolean().optional(), lnp: z.boolean().optional(), wirelessPort: z.boolean().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 }; /** * Prevalidate a phone number * * POST /v2/partition/{partitionId}/account/prevalidate */ export const createApiV2PartitionPartitionIdAccountPrevalidate = async (args: CreateApiV2PartitionPartitionIdAccountPrevalidateArgs, options?: CreateApiV2PartitionPartitionIdAccountPrevalidateOptions) => { 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))}/account/prevalidate${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(portAvailabilityResponseV2X, await res.json()) };