import {z} from 'zod' export type GetApiV2PartitionPartitionIdArgs = {partitionId: string}; export type GetApiV2PartitionPartitionIdOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const dialPlanRuleX = z.object({partitionId: z.string().optional(), mask: z.string().optional(), actionType: z.enum(["TranslateAndReapplyDialPlan", "CallOutboundNumber", "CallCustomerServiceHuntGroup", "Callback", "CallForwardingAlways", "CallForwardingOnBusy", "CallForwardingOnNoAnswer", "CallForwardingOnUnregistered", "CallNonEmergencyServices", "CallPublicServices", "CallCanadaHealthServices", "CallerIdBlockManage", "EnterVoiceMail", "DirectToVoicemail", "CallWaitingEnable", "CallWaitingDisable", "AnonymousCallRejectEnable", "AnonymousCallRejectDisable", "AnonymousCallRejectWithInterceptEnable", "AnonymousCallRejectWithInterceptDisable", "SelectiveCallAcceptEnable", "SelectiveCallAcceptDisable", "SpecificCallerBlock", "SpecificCallerBlockWithIntercept", "SpecificCallerAllow", "SpecificCallerVipRing", "SpecificCallerForwardEnable", "AccountAnonymousCallRejectEnable", "AccountAnonymousCallRejectDisable", "AccountAnonymousCallRejectWithInterceptEnable", "AccountAnonymousCallRejectWithInterceptDisable", "AccountSelectiveCallAcceptEnable", "AccountSelectiveCallAcceptDisable", "AccountSpecificCallerBlock", "AccountSpecificCallerAllow", "AccountSpecificCallerBlockWithIntercept", "DoNotDisturbEnable", "DoNotDisturbDisable", "PickupInDirectory", "CallTrace", "ParkCall", "ParkCallRetrieval", "DirectedCallPickUp", "GroupPickup", "ReservedForHuntGroup", "GroupForwarding", "CallPull", "GroupLoginLogout"]).optional(), callNumber: z.string().optional(), endingMinimumLength: z.number().int().optional(), endingMaximumLength: z.number().int().optional(), translationMacro: z.string().optional(), disableCallerId: z.boolean().optional(), callerIdVisibilityOverride: z.enum(["UseDestinationCallerIdEnabledSetting", "Blocked", "Unblocked"]).optional(), disableCallWaiting: z.boolean().optional(), overwriteCallerIdNumber: z.string().optional(), bypassAuthorization: z.boolean().optional(), outboundNumberFunction: z.enum(["CUSTOMER_SERVICE", "DIRECTORY_ASSISTANCE", "EMERGENCY_SERVICES", "ESSENTIAL_COMMUNITY_SERVICES", "NONURGENT_MUNICIPAL_GOVERNMENT_SERVICES", "NONURGENT_TELEHEALTH_SERVICES", "OPERATOR", "SPEED_DIAL", "TELECOMMUNICATIONS_RELAY_SERVICE", "TRAFFIC_INFORMATION", "UNDERGROUND_PUBLIC_UTILITY_LOCATION"]).optional(), breakTranslation: z.boolean().optional(), id: z.string().optional()}); export const mediaFriendsX = z.object({enabled: z.boolean().optional(), host: z.string().optional(), toNumber: z.string().optional()}); export const partitionX = z.object({id: z.string().optional(), name: z.string().optional(), status: z.enum(["ACTIVE", "ARCHIVED", "HIDDEN"]).optional(), customerServiceNumber: z.string().optional(), parentId: z.string().optional(), useAccountNumberDefault: z.boolean().optional(), bypassVoicemailPINValidationFromDevice: z.boolean().optional(), billingCode: z.string().optional(), country: z.string().optional(), languageTag: z.string().optional(), reorderNotifications: z.array(z.string()).optional(), subPartitionIds: z.array(z.string()).optional(), useOwnCarrier: z.boolean().optional(), availableInboundCarrierId: z.array(z.string()).optional(), defaultRoutePlanId: z.string().optional(), tnDeleteCooldownDays: z.number().int().optional(), defaultTimeZone: 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"]).optional(), tempTnThreshold: z.number().int().optional(), serviceDialPlanRules: z.array(dialPlanRuleX).optional(), mediaFriends: mediaFriendsX.optional(), defaultSimpleDialingBehaviorType: z.enum(["SEVEN_DIGIT", "TEN_DIGIT", "OPEN_DIAL_PLAN", "DIAL_NINE_SEVEN_DIGIT", "DIAL_NINE_TEN_DIGIT", "OPEN_DIAL_PLAN_TEN_DIGIT"]).optional(), defaultAdvancedDialingBehaviorType: z.enum(["SEVEN_DIGIT", "TEN_DIGIT", "OPEN_DIAL_PLAN", "DIAL_NINE_SEVEN_DIGIT", "DIAL_NINE_TEN_DIGIT", "OPEN_DIAL_PLAN_TEN_DIGIT"]).optional(), defaultDirectoryListingType: z.enum(["ERROR", "LIST_PUBLISH", "LIST_NOT_PUBLISH", "NOT_LIST_NOT_PUBLISH", "PORTED", "COMPLEX"]).optional(), portPushDays: z.number().int().optional(), allowedDeviceTypes: z.array(z.string()).optional(), defaultHoldTimeoutSeconds: z.number().int().optional(), allowLoginByAccountNumber: z.boolean().optional(), requiresDeviceInventory: z.boolean().optional(), usesTrammellE911Verification: z.boolean().optional(), showComplexListing: z.boolean().optional(), defaultExtensionLength: z.number().int().optional(), autoAssignCallerId: z.boolean().optional(), byotnCarrierId: z.string().optional(), fraudAlertNotifications: z.array(z.string()).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 }; /** * Get partition data * * GET /v2/partition/{partitionId} */ export const getApiV2PartitionPartitionId = async (args: GetApiV2PartitionPartitionIdArgs, options?: GetApiV2PartitionPartitionIdOptions) => { 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 (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}${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(partitionX, await res.json()) };