import {z} from 'zod' export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsArgs = {offset?: number | undefined, size?: number | undefined, filter?: ({key?: string | undefined, value?: string | undefined}) | undefined, mesh: string}; export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const meshRateLimitItem = z.object({type: z.literal("MeshRateLimit"), mesh: z.string().optional(), kri: z.string().optional(), name: z.string(), labels: z.record(z.string(), z.string()).optional(), spec: z.object({from: z.array(z.object({default: z.object({local: z.object({http: z.object({disabled: z.boolean().optional(), onRateLimit: z.object({headers: z.object({add: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional(), set: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional()}).optional(), status: z.number().int().optional()}).optional(), requestRate: z.object({interval: z.string(), num: z.number().int()}).optional()}).optional(), tcp: z.object({connectionRate: z.object({interval: z.string(), num: z.number().int()}).optional(), disabled: z.boolean().optional()}).optional()}).optional()}).optional(), targetRef: z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional()})})).optional(), rules: z.array(z.object({default: z.object({local: z.object({http: z.object({disabled: z.boolean().optional(), onRateLimit: z.object({headers: z.object({add: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional(), set: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional()}).optional(), status: z.number().int().optional()}).optional(), requestRate: z.object({interval: z.string(), num: z.number().int()}).optional()}).optional(), tcp: z.object({connectionRate: z.object({interval: z.string(), num: z.number().int()}).optional(), disabled: z.boolean().optional()}).optional()}).optional()}).optional(), matches: z.array(z.object({sni: z.object({type: z.literal("Exact"), value: z.string()}).optional(), spiffeID: z.object({type: z.enum(["Exact", "Prefix"]), value: z.string()}).optional()})).optional()})).optional(), targetRef: z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional()}).optional(), to: z.array(z.object({default: z.object({local: z.object({http: z.object({disabled: z.boolean().optional(), onRateLimit: z.object({headers: z.object({add: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional(), set: z.array(z.object({name: z.string().min(1).max(256), value: z.string()})).optional()}).optional(), status: z.number().int().optional()}).optional(), requestRate: z.object({interval: z.string(), num: z.number().int()}).optional()}).optional(), tcp: z.object({connectionRate: z.object({interval: z.string(), num: z.number().int()}).optional(), disabled: z.boolean().optional()}).optional()}).optional()}).optional(), targetRef: z.object({kind: z.enum(["Mesh", "MeshSubset", "MeshGateway", "MeshService", "MeshExternalService", "MeshMultiZoneService", "MeshServiceSubset", "MeshHTTPRoute", "Dataplane"]), labels: z.record(z.string(), z.string()).optional(), mesh: z.string().optional(), name: z.string().optional(), namespace: z.string().optional(), proxyTypes: z.array(z.enum(["Sidecar", "Gateway"])).optional(), sectionName: z.string().optional(), tags: z.record(z.string(), z.string()).optional()})})).optional()}), creationTime: z.string().optional(), modificationTime: z.string().optional()}); export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsResponse = z.object({items: z.array(meshRateLimitItem).optional(), total: z.number().optional(), next: 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 }; /** * Returns a list of MeshRateLimit in the mesh. * * GET /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshratelimits * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimits = async (args: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsArgs, options?: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.size != null) query.append("size", String(args.size)) if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/mesh/control-planes/${encodeURIComponent(String(args.cpId))}/api/meshes/${encodeURIComponent(String(args.mesh))}/meshratelimits${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(getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsResponse, await res.json()) };