import {z} from 'zod' export type CustomCallScreenX = {telephoneNumber?: string | undefined, blockType?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, ringType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined}; export type CallScreeningSettingsX = {anonymousCallScreen?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, anonymousRingType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined, tollFreeCallScreen?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, tollFreeRingType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined, defaultCallScreen?: ('Allow' | 'Block' | 'Voicemail' | 'Forward' | 'VipRing' | 'BlockWithPrompt') | undefined, defaultRingType?: ('StandardRing' | 'Ring1' | 'Ring2' | 'Ring3' | 'Ring4' | 'Ring5' | 'Ring6' | 'Ring7') | undefined, customCallScreenList?: Array | undefined, forwardTn?: string | undefined}; export type CallingPlanX = {id?: string | undefined, referenceId?: string | undefined, referenceType?: ('SIP_TRUNK' | 'END_USER' | 'IVR' | 'ACCOUNT' | 'SPECIALTY_LINE' | 'CONTACT_CENTER') | undefined, callingPlanProductId?: string | undefined, endDate?: string | undefined, startDate?: string | undefined, planMinutes?: number | undefined, secondsRemaining?: number | undefined}; export type Account = {id: string, partitionId: string, accountNumber: string, accountName: string, billingCycleDay: number, customField?: string | undefined, status: 'ACTIVE' | 'DISABLED' | 'DELETED' | 'DELETE_PENDING' | 'SUSPENDED' | 'PENDING', timeZone: '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', languageTag?: string | undefined, deletionDate?: string | undefined, accountType: 'SIMPLE' | 'ADVANCED', platformType?: ('V2_0' | 'V2_1' | 'CPE1' | 'CPE2') | undefined, platformChangeDate?: string | undefined, inboundRatePlanProductId?: string | undefined, extensionLength: number, dialingBehaviorType: 'SEVEN_DIGIT' | 'TEN_DIGIT' | 'OPEN_DIAL_PLAN' | 'DIAL_NINE_SEVEN_DIGIT' | 'DIAL_NINE_TEN_DIGIT' | 'OPEN_DIAL_PLAN_TEN_DIGIT', routePlanId?: string | undefined, callScreeningSettings?: CallScreeningSettingsX | undefined, holdMusicMediaId?: string | undefined, holdTimeoutSeconds?: number | undefined, allowDangerousExtensions?: boolean | undefined, domain?: string | undefined, sendWelcomeEmail?: boolean | undefined, regulatoryType: 'RESIDENTIAL' | 'COMMERCIAL' | 'GOVERNMENT', endUserCount?: number | undefined, customHoldMusicMediaId?: string | undefined, callingPlans?: Array | undefined}; export type CreateApiV2PartitionPartitionIdAccountArgs = {partitionId: string, body: Account}; export type CreateApiV2PartitionPartitionIdAccountOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const customCallScreenX = z.object({telephoneNumber: z.string().optional(), blockType: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), ringType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional()}); export const callScreeningSettingsX = z.object({anonymousCallScreen: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), anonymousRingType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), tollFreeCallScreen: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), tollFreeRingType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), defaultCallScreen: z.enum(["Allow", "Block", "Voicemail", "Forward", "VipRing", "BlockWithPrompt"]).optional(), defaultRingType: z.enum(["StandardRing", "Ring1", "Ring2", "Ring3", "Ring4", "Ring5", "Ring6", "Ring7"]).optional(), customCallScreenList: z.array(customCallScreenX).optional(), forwardTn: z.string().optional()}); export const callingPlanX = z.object({id: z.string().optional(), referenceId: z.string().optional(), referenceType: z.enum(["SIP_TRUNK", "END_USER", "IVR", "ACCOUNT", "SPECIALTY_LINE", "CONTACT_CENTER"]).optional(), callingPlanProductId: z.string().optional(), endDate: z.string().optional(), startDate: z.string().optional(), planMinutes: z.number().int().optional(), secondsRemaining: z.number().int().optional()}); export const account = z.object({id: z.string(), partitionId: z.string(), accountNumber: z.string().min(3).max(256), accountName: z.string().min(3).max(256), billingCycleDay: z.number().int().gte(1).lte(28), customField: z.string().min(3).max(256).optional(), status: z.enum(["ACTIVE", "DISABLED", "DELETED", "DELETE_PENDING", "SUSPENDED", "PENDING"]), timeZone: 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"]), languageTag: z.string().optional(), deletionDate: z.string().optional(), accountType: z.enum(["SIMPLE", "ADVANCED"]), platformType: z.enum(["V2_0", "V2_1", "CPE1", "CPE2"]).optional(), platformChangeDate: z.string().optional(), inboundRatePlanProductId: z.string().optional(), extensionLength: z.number().int().gte(3).lte(6), dialingBehaviorType: z.enum(["SEVEN_DIGIT", "TEN_DIGIT", "OPEN_DIAL_PLAN", "DIAL_NINE_SEVEN_DIGIT", "DIAL_NINE_TEN_DIGIT", "OPEN_DIAL_PLAN_TEN_DIGIT"]), routePlanId: z.string().optional(), callScreeningSettings: callScreeningSettingsX.optional(), holdMusicMediaId: z.string().optional(), holdTimeoutSeconds: z.number().int().gte(30).lte(600).optional(), allowDangerousExtensions: z.boolean().optional(), domain: z.string().optional(), sendWelcomeEmail: z.boolean().optional(), regulatoryType: z.enum(["RESIDENTIAL", "COMMERCIAL", "GOVERNMENT"]), endUserCount: z.number().int().optional(), customHoldMusicMediaId: z.string().optional(), callingPlans: z.array(callingPlanX).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 account within the specified partition. * * POST /v2/partition/{partitionId}/account */ export const createApiV2PartitionPartitionIdAccount = async (args: CreateApiV2PartitionPartitionIdAccountArgs, options?: CreateApiV2PartitionPartitionIdAccountOptions) => { 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${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(account, await res.json()) };