import {z} from 'zod' export type GetApiV1UsagePlanGroupPlansArgs = {'search.usage_plan_group_plan_id'?: Array | undefined, 'search.usage_plan_group_id'?: Array | undefined, 'search.plan_id'?: Array | undefined, 'search.page_size'?: number | undefined, 'search.page'?: number | undefined, 'search.sort'?: string | undefined}; export type GetApiV1UsagePlanGroupPlansOptions = {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 revAppModelsUsagePlanGroupPlan = z.object({usage_plan_group_plan_id: z.number().int().optional(), usage_plan_group_id: z.number().int().gte(1).lte(2147483647), plan_id: z.number().int().gte(1).lte(2147483647), retail: z.boolean().optional(), wholesale: z.boolean().optional(), links: z.array(revAppComponentsLink).optional()}); export const revWebAPIModelsGetOrSearchOfRevAppSearchModelsResponseOfRevAppModelsUsagePlanGroupPlan = z.object({ok: z.boolean().optional(), has_more: z.boolean().optional(), record_count: z.number().int().optional(), records: z.array(revAppModelsUsagePlanGroupPlan).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 }; /** * Search usage plan group plans * * GET /v1/UsagePlanGroupPlans */ export const getApiV1UsagePlanGroupPlans = async (args: GetApiV1UsagePlanGroupPlansArgs, options?: GetApiV1UsagePlanGroupPlansOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args['search.usage_plan_group_plan_id'] ?? []) query.append("search.usage_plan_group_plan_id", String(item)) for (const item of args['search.usage_plan_group_id'] ?? []) query.append("search.usage_plan_group_id", String(item)) for (const item of args['search.plan_id'] ?? []) query.append("search.plan_id", String(item)) if (args['search.page_size'] != null) query.append("search.page_size", String(args['search.page_size'])) if (args['search.page'] != null) query.append("search.page", String(args['search.page'])) if (args['search.sort'] != null) query.append("search.sort", String(args['search.sort'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/UsagePlanGroupPlans${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(revWebAPIModelsGetOrSearchOfRevAppSearchModelsResponseOfRevAppModelsUsagePlanGroupPlan, await res.json()) };