import {z} from 'zod' export type CallingPlanProduct = {id?: string | undefined, name?: string | undefined, planMinutes?: number | undefined, unlimitedDisplay?: boolean | undefined, allowOverage?: boolean | undefined, preventForwarding?: boolean | undefined, defaultPlan?: boolean | undefined, callRateFor411?: number | undefined, allow411?: boolean | undefined, rateTypeFor411?: ('PER_CALL' | 'PER_MINUTE') | undefined, callRateForOperator?: number | undefined, allowOperator?: boolean | undefined, rateTypeForOperator?: ('PER_CALL' | 'PER_MINUTE') | undefined, partitionId?: string | undefined, allowUnlimitedLocal?: boolean | undefined, rateIntraPartitionAsFree?: boolean | undefined}; export type PatchApiV2PartitionPartitionIdCallingplanproductCppIdArgs = {cppId: string, partitionId: string, body: CallingPlanProduct}; export type PatchApiV2PartitionPartitionIdCallingplanproductCppIdOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const callingPlanProduct = z.object({id: z.string().optional(), name: z.string().optional(), planMinutes: z.number().int().optional(), unlimitedDisplay: z.boolean().optional(), allowOverage: z.boolean().optional(), preventForwarding: z.boolean().optional(), defaultPlan: z.boolean().optional(), callRateFor411: z.number().optional(), allow411: z.boolean().optional(), rateTypeFor411: z.enum(["PER_CALL", "PER_MINUTE"]).optional(), callRateForOperator: z.number().optional(), allowOperator: z.boolean().optional(), rateTypeForOperator: z.enum(["PER_CALL", "PER_MINUTE"]).optional(), partitionId: z.string().optional(), allowUnlimitedLocal: z.boolean().optional(), rateIntraPartitionAsFree: z.boolean().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 }; /** * Update calling plan product * * PATCH /v2/partition/{partitionId}/callingplanproduct/{cppId} */ export const patchApiV2PartitionPartitionIdCallingplanproductCppId = async (args: PatchApiV2PartitionPartitionIdCallingplanproductCppIdArgs, options?: PatchApiV2PartitionPartitionIdCallingplanproductCppIdOptions) => { 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))}/callingplanproduct/${encodeURIComponent(String(args.cppId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(callingPlanProduct, await res.json()) };