import {z} from 'zod' export type GetApiV2PartitionPartitionIdAccountAccountIdArgs = {accountId: string, accountIdType?: ('Id' | 'AccountNumber' | 'PhoneNumber' | 'MacAddress') | undefined, partitionId: string}; export type GetApiV2PartitionPartitionIdAccountAccountIdOptions = {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 }; /** * Retrieve account by an ID. * * GET /v2/partition/{partitionId}/account/{accountId} */ export const getApiV2PartitionPartitionIdAccountAccountId = async (args: GetApiV2PartitionPartitionIdAccountAccountIdArgs, options?: GetApiV2PartitionPartitionIdAccountAccountIdOptions) => { 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.accountIdType != null) query.append("accountIdType", String(args.accountIdType)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/account/${encodeURIComponent(String(args.accountId))}${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(account, await res.json()) };