import {z} from 'zod' export type GetApiV2CesDeviceGraphMacaddressArgs = {limited?: boolean | undefined, macaddress: string}; export type GetApiV2CesDeviceGraphMacaddressOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const deviceGraphLimited = z.object({deviceTypeId: z.string().optional(), accountId: z.string().optional(), partitionId: z.string().optional(), macAddress: z.string().optional(), deviceName: z.string().optional(), emergencyNumber: z.string().optional(), faxEnabled: z.boolean().optional(), lineNumber: z.number().int().optional(), userId: z.string().optional(), sipUsername: z.string().optional(), linetype: z.string().optional(), telephoneNumbers: z.array(z.string())}); 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 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 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 telephoneNumberAccountV2X = 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(), accountId: z.string().optional(), partitionId: z.string().optional(), customerServiceRecord: customerServiceRecordX.optional(), carrierStatus: 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(), orderVersion: z.string().optional(), e911Address: e911AddressX.optional(), temporaryNumber: z.string().optional(), directoryListing: directoryListingX.optional(), assignAsCallerId: z.boolean().optional(), byotnCarrierId: z.string().optional(), ringType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), carrierId: z.string().optional(), tollFree: z.boolean().optional(), id: z.string().optional(), tags: z.array(z.string()).optional()}); export const deviceGraphUnlimited = z.object({deviceTypeId: z.string().optional(), accountId: z.string().optional(), partitionId: z.string().optional(), macAddress: z.string().optional(), deviceName: z.string().optional(), emergencyNumber: z.string().optional(), faxEnabled: z.boolean().optional(), lineNumber: z.number().int().optional(), userId: z.string().optional(), sipUsername: z.string().optional(), linetype: z.string().optional(), tnas: z.array(telephoneNumberAccountV2X)}); export const getApiV2CesDeviceGraphMacaddressResponse = z.union([deviceGraphLimited, deviceGraphUnlimited]); 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 }; /** * Device Graph * * GET /v2/ces/deviceGraph/{macaddress} */ export const getApiV2CesDeviceGraphMacaddress = async (args: GetApiV2CesDeviceGraphMacaddressArgs, options?: GetApiV2CesDeviceGraphMacaddressOptions) => { 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.limited != null) query.append("limited", String(args.limited)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/ces/deviceGraph/${encodeURIComponent(String(args.macaddress))}${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(getApiV2CesDeviceGraphMacaddressResponse, await res.json()) };