import {z} from 'zod' export type GetApiV1UsagePlanRatesIdArgs = {id: number}; export type GetApiV1UsagePlanRatesIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revAppComponentsLink = z.object({rel: z.string().optional(), href: z.string().optional()}); export const revWebAPIModelsGetOrSearchOfRevAppModelsUsagePlanRate = z.object({ok: z.boolean().optional(), usage_plan_rate_id: z.number().int().optional(), plan_id: z.number().int().gte(1).lte(2147483647), description: z.string().max(255), rate: z.number().gte(0).optional(), surcharge: z.number().gte(0).optional(), initial: z.number().int().gte(0).lte(2147483647).optional(), increment: z.number().int().gte(0).lte(2147483647).optional(), country: z.string().optional(), state: z.string().optional(), area: z.string().optional(), lata: z.string().max(20).optional(), ocn: z.string().max(20).optional(), product_type_id: z.number().int().optional(), line_type: z.string().optional(), direction: z.enum(["OUTBOUND", "INBOUND", "BOTH"]).optional(), carrier_code: z.string().optional(), source_type: z.string().optional(), start_date: z.string().optional(), end_date: z.string().optional(), rounding_digits: z.number().int().optional(), minimum_charge: z.number().gte(0).optional(), zone: z.number().int().optional(), links: z.array(revAppComponentsLink).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 }; /** * View usage plan rate * * GET /v1/UsagePlanRates/{id} */ export const getApiV1UsagePlanRatesId = async (args: GetApiV1UsagePlanRatesIdArgs, options?: GetApiV1UsagePlanRatesIdOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/UsagePlanRates/${encodeURIComponent(String(args.id))}${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(revWebAPIModelsGetOrSearchOfRevAppModelsUsagePlanRate, await res.json()) };