import {z} from 'zod' export type TelephoneNumberSearchEventType = Array<'ACTIVATION' | 'BYOTN_REQUEST' | 'CSR_CHANGE_REQUEST' | 'DISCONNECT' | 'DYNAMIC_RESERVATION' | 'NINE_ONE_ONE_ADDRESS' | 'PORT_REQUEST' | 'SERVICE_PROVIDER_TN'>; export type TelephoneNumberSearchStatusType = Array<'PENDING' | 'IN_PROGRESS' | 'REJECTED' | 'FOC_RECEIVED' | 'FOC_REMOVED' | 'CANCELLED' | 'CANCEL_PENDING' | 'CARRIER_CANCELLED' | 'DELETE_PENDING' | 'DELETE_SCHEDULED' | 'COMPLETED' | 'CORRECTED_COMPLETED' | 'COOLDOWN' | 'HOT_CUT_PORT' | 'ON_HOLD' | 'RESELLER_PENDING'>; export type GetApiV2PartitionPartitionIdTelephonenumberStatussearchArgs = {accountId?: string | undefined, dateType?: ('FOCDate' | 'UpdatedDate' | 'CreatedDate') | undefined, endDate?: string | undefined, eventType?: TelephoneNumberSearchEventType | undefined, firstResultIndex?: number | undefined, maxResult?: number | undefined, partitionId: string, startDate?: string | undefined, statusType?: TelephoneNumberSearchStatusType | undefined, telephoneNumber?: string | undefined}; export type GetApiV2PartitionPartitionIdTelephonenumberStatussearchOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceActivationEventLogX = z.object({status: z.enum(["PENDING", "IN_PROGRESS", "REJECTED", "FOC_RECEIVED", "FOC_REMOVED", "CANCELLED", "CANCEL_PENDING", "CARRIER_CANCELLED", "DELETE_PENDING", "DELETE_SCHEDULED", "COMPLETED", "CORRECTED_COMPLETED", "COOLDOWN", "HOT_CUT_PORT", "ON_HOLD", "RESELLER_PENDING"]).optional(), actionDate: z.string().optional(), code: z.string().optional(), message: z.string().optional(), creationDate: z.string().optional(), generatedTicketId: z.string().optional()}); export const serviceActivationEventX = z.object({id: z.string().optional(), partitionId: z.string().optional(), accountId: z.string().optional(), serviceType: z.enum(["PORT_REQUEST", "CSR_CHANGE_REQUEST", "ACTIVATION", "NINE_ONE_ONE_ADDRESS", "DISCONNECT", "DYNAMIC_RESERVATION", "BYOTN_REQUEST", "SERVICE_PROVIDER_TN"]).optional(), referenceType: z.enum(["TELEPHONE", "PORT", "DYNAMIC_INVENTORY", "BYOTN", "BYOTN_PORT"]).optional(), referenceId: z.string().optional(), activationStatusType: z.enum(["PENDING", "IN_PROGRESS", "REJECTED", "FOC_RECEIVED", "FOC_REMOVED", "CANCELLED", "CANCEL_PENDING", "CARRIER_CANCELLED", "DELETE_PENDING", "DELETE_SCHEDULED", "COMPLETED", "CORRECTED_COMPLETED", "COOLDOWN", "HOT_CUT_PORT", "ON_HOLD", "RESELLER_PENDING"]).optional(), createdDate: z.string().optional(), lastUpdatedDate: z.string().optional(), focDate: z.string().optional(), crdDate: z.string().optional(), city: z.string().optional(), mainTelephoneNumber: z.string().optional(), subTelephoneNumbers: z.array(z.string()).optional(), firstName: z.string().optional(), lastName: z.string().optional(), companyName: z.string().optional(), state: z.string().optional(), l3Reaction: z.enum(["IGNORE", "RESUBMIT", "CANCEL", "SEND_EMAIL"]).optional(), parentOrderId: z.string().optional(), editableFieldTypes: z.array(z.enum(["crdDate", "wirelessAccountNumber", "wirelessPin", "name"])).optional(), losingCarrier: z.string().optional(), inboundCarrierType: 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(), logs: z.array(serviceActivationEventLogX).optional()}); export const serviceActivationEventResponseX = z.object({totalRecords: z.number().int().optional(), results: z.array(serviceActivationEventX).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 }; /** * Telephone number status search * * GET /v2/partition/{partitionId}/telephonenumber/statussearch */ export const getApiV2PartitionPartitionIdTelephonenumberStatussearch = async (args: GetApiV2PartitionPartitionIdTelephonenumberStatussearchArgs, options?: GetApiV2PartitionPartitionIdTelephonenumberStatussearchOptions) => { 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.accountId != null) query.append("accountId", String(args.accountId)) if (args.dateType != null) query.append("dateType", String(args.dateType)) if (args.endDate != null) query.append("endDate", String(args.endDate)) for (const item of args.eventType ?? []) query.append("eventType", String(item)) if (args.firstResultIndex != null) query.append("firstResultIndex", String(args.firstResultIndex)) if (args.maxResult != null) query.append("maxResult", String(args.maxResult)) if (args.startDate != null) query.append("startDate", String(args.startDate)) for (const item of args.statusType ?? []) query.append("statusType", String(item)) if (args.telephoneNumber != null) query.append("telephoneNumber", String(args.telephoneNumber)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/telephonenumber/statussearch${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(serviceActivationEventResponseX, await res.json()) };