import {z} from 'zod' export type GetApiV2PartitionPartitionIdAccountAccounthistorysearchArgs = {accountHistoryType?: (Array<'PHONE_NUMBER' | 'PROVISIONING' | 'CALL_FORWARDING' | 'CALL_SCREENING' | 'ADDRESS' | 'ADDRESS_CSR' | 'ADDRESS_E911' | 'ADDRESS_DIRECTORY_LISTING' | 'ACCOUNT_STATUS' | 'VOICEMAIL' | 'CALLING_PLAN' | 'INBOUND_CALLING_PLAN' | 'IVR' | 'SIP_TRUNK' | 'SIP_TRUNK_FORWARD' | 'SIP_TRUNK_GROUP' | 'DEVICE' | 'DEVICE_METADATA' | 'USER' | 'USER_API_AUTH' | 'LINE_HUNTGROUP' | 'ACCOUNT' | 'LINE_APPEARANCE' | 'LINE_HARDWARE' | 'VFAX' | 'PAGING_GROUP' | 'PICKUP_GROUP' | 'GROUP_OF_REFERENCES' | 'CALL_PARKING_SPOT' | 'ACCOUNT_USER' | 'SIP_CREDENTIALS' | 'BUSINESS_LINE' | 'BUSINESS_LINE_HUNT_GROUP' | 'CALL_GROUP' | 'CALL_QUEUE' | 'USER_DEVICE_LINE' | 'EMERGENCY_NOTIFICATION' | 'DYNAMIC_RESERVATION' | 'SPECIALTY_LINE' | 'AUTHORITY' | 'AUTO_ATTENDANT' | 'CONTACT' | 'CONTACT_CENTER' | 'CALL_RECORDING' | 'ACCOUNT_CODE' | 'SHORT_CODE' | 'MEDIA_MANAGEMENT' | 'SOUNDS' | 'USER_GROUP'>) | undefined, accountNumber: string, endDate?: string | undefined, firstResultIndex?: number | undefined, maxResult?: number | undefined, partitionId: string, startDate?: string | undefined}; export type GetApiV2PartitionPartitionIdAccountAccounthistorysearchOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const accountHistoryX = z.object({id: z.string().optional(), accountId: z.string().optional(), accountNumber: z.string().optional(), oldValue: z.string().optional(), newValue: z.string().optional(), userName: z.string().optional(), userId: z.string().optional(), userType: z.enum(["AccountUser", "EndUser", "ManagementUser", "AlianzaUser", "BusinessLines"]).optional(), partitionName: z.string().optional(), accountHistoryType: z.enum(["PHONE_NUMBER", "PROVISIONING", "CALL_FORWARDING", "CALL_SCREENING", "ADDRESS", "ADDRESS_CSR", "ADDRESS_E911", "ADDRESS_DIRECTORY_LISTING", "ACCOUNT_STATUS", "VOICEMAIL", "CALLING_PLAN", "INBOUND_CALLING_PLAN", "IVR", "SIP_TRUNK", "SIP_TRUNK_FORWARD", "SIP_TRUNK_GROUP", "DEVICE", "DEVICE_METADATA", "USER", "USER_API_AUTH", "LINE_HUNTGROUP", "ACCOUNT", "LINE_APPEARANCE", "LINE_HARDWARE", "VFAX", "PAGING_GROUP", "PICKUP_GROUP", "GROUP_OF_REFERENCES", "CALL_PARKING_SPOT", "ACCOUNT_USER", "SIP_CREDENTIALS", "BUSINESS_LINE", "BUSINESS_LINE_HUNT_GROUP", "CALL_GROUP", "CALL_QUEUE", "USER_DEVICE_LINE", "EMERGENCY_NOTIFICATION", "DYNAMIC_RESERVATION", "SPECIALTY_LINE", "AUTHORITY", "AUTO_ATTENDANT", "CONTACT", "CONTACT_CENTER", "CALL_RECORDING", "ACCOUNT_CODE", "SHORT_CODE", "MEDIA_MANAGEMENT", "SOUNDS", "USER_GROUP"]).optional(), loggedDate: z.string().optional(), referenceType: z.enum(["Account", "LineAppearance", "LineHuntGroup", "SipTrunk", "SipTrunkForward", "Device", "Telephone", "IVR", "EndUser", "VFax", "VoicemailBox", "PagingGroup", "GroupOfReferences", "PickupGroup", "CallParkingSpot", "AccountUser", "SIP_CREDENTIALS", "BUSINESS_LINE", "BUSINESS_LINE_HUNT_GROUP", "CALL_GROUP", "CALL_QUEUE", "USER_DEVICE_LINE", "SIP_TRUNK", "SIP_TRUNK_GROUP", "EMERGENCY_NOTIFICATION_COMPLIANCE", "DYNAMIC_RESERVATION", "SPECIALTY_LINE", "AUTHORITY_ROLE", "AUTO_ATTENDANT", "END_USER_CONTACT", "CUSTOM_CONTACT", "CONTACT_CENTER", "CALL_RECORDING", "ACCOUNT_CODE", "SHORT_CODE", "MEDIA_MANAGEMENT", "SOUNDS", "USER_GROUP", "USER_API_AUTH"]).optional(), referenceId: z.string().optional(), referenceName: z.string().optional(), action: z.enum(["CREATE", "UPDATE", "PROVISION_REQUEST", "DELETE"]).optional()}); export const accountHistorySearchResponseX = z.object({totalRecords: z.number().int().optional(), accountCreatedDate: z.string().optional(), accountLastUpdatedDate: z.string().optional(), results: z.array(accountHistoryX).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 }; /** * Account history record search * * GET /v2/partition/{partitionId}/account/accounthistorysearch */ export const getApiV2PartitionPartitionIdAccountAccounthistorysearch = async (args: GetApiV2PartitionPartitionIdAccountAccounthistorysearchArgs, options?: GetApiV2PartitionPartitionIdAccountAccounthistorysearchOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.accountHistoryType ?? []) query.append("accountHistoryType", String(item)) if (args.accountNumber != null) query.append("accountNumber", String(args.accountNumber)) if (args.endDate != null) query.append("endDate", String(args.endDate)) 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)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/account/accounthistorysearch${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(accountHistorySearchResponseX, await res.json()) };