import {z} from 'zod' export type RevAppModelsServiceFieldBuiltinFieldModel = {field: 'Account_Group_ID' | 'Activated_Date' | 'AddressA_ID' | 'AddressZ_ID' | 'AddressZWeight' | 'AltBtnId' | 'Bounty_Eligible_Flag' | 'CallPlanID' | 'Carrier_Account_ID' | 'Carrier_Account_Number' | 'Carrier_ID' | 'Channels' | 'Channels_Data' | 'Channels_Voice' | 'Circuit_Completion_Date' | 'Circuit_FOC_Date' | 'Circuit_Number' | 'Circuit_Number2' | 'Circuit_Order_Date' | 'Circular_Hunt' | 'CLLI_Code' | 'Close_Reason_ID' | 'Contract_End' | 'Contract_Start' | 'Customer_ID' | 'd_Channel' | 'Description' | 'Digits_Outpulsed' | 'Disconnect_Date' | 'DNIS' | 'Hunt_Group' | 'Hunt_Identifier' | 'Hunt_Sequence' | 'International_Access' | 'IPIC' | 'IsCircuit' | 'isDataOnly' | 'IsPorting' | 'Line_ID' | 'Line_Type_ID' | 'LineOCN' | 'LPIC' | 'MAC' | 'Notes' | 'Override_Class' | 'Override_Class_Flag' | 'Package_ID' | 'Pair' | 'PBX_Make' | 'PBX_Model' | 'PIC' | 'Port' | 'Program_ID' | 'Protocol' | 'Rate_Center' | 'RDT_Equipment' | 'Router_DHCP' | 'Router_IP' | 'Router_Password' | 'Router_Protocol' | 'Router_Subnet' | 'Shelf' | 'Slot' | 'Switch' | 'TN' | 'TN_800' | 'TN_LD_Access' | 'TN_Reservation' | 'TN_VoiceMail' | 'WanRouter_DHCP' | 'WanRouter_IP' | 'WanRouter_Password' | 'WanRouter_Protocol' | 'WanRouter_Subnet' | 'Wireless_Device_ID' | 'Wireless_Device_Type' | 'Exchange_Key' | 'UNEL_Cut_Date' | 'Circuit_Reference' | 'Relay_Rack' | 'Transferred_From_Line_ID'}; export type RevAppModelsServiceFieldCustomFieldModel = {type: 'TEXTBOX' | 'TEXTAREA' | 'DROPDOWNLIST' | 'RADIOBUTTONLIST' | 'CHECKBOX' | 'DATE' | 'REGEX', required?: boolean | undefined, options?: Array | undefined, default_value?: string | undefined, regex?: string | undefined, regex_validation_message?: string | undefined}; export type RevAppComponentsLink = {rel?: string | undefined, href?: string | undefined}; export type RevAppModelsServiceFieldModel = {display_name: string, field_id?: number | undefined, description?: string | undefined, tab_name?: string | undefined, builtin_field?: RevAppModelsServiceFieldBuiltinFieldModel | undefined, custom_field?: RevAppModelsServiceFieldCustomFieldModel | undefined, links?: Array | undefined}; export type RevAppModelsServiceType = {service_type_id?: number | undefined, active?: boolean | undefined, description: string, service_code: string, fields?: Array | undefined, links?: Array | undefined}; export type CreateApiV1ServiceTypesArgs = {body: RevAppModelsServiceType}; export type CreateApiV1ServiceTypesOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revWebAPIModelsCreate = z.object({ok: z.boolean().optional(), id: z.number().int().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 service type * * POST /v1/ServiceTypes */ export const createApiV1ServiceTypes = async (args: CreateApiV1ServiceTypesArgs, options?: CreateApiV1ServiceTypesOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ServiceTypes${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(revWebAPIModelsCreate, await res.json()) };