import {z} from 'zod' export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsNameArgs = {mesh: string, name: string}; export type GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsNameOptions = {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 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 MeshRateLimit entity * * GET /v1/mesh/control-planes/{cpId}/api/meshes/{mesh}/meshratelimits/{name} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsName = async (args: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsNameArgs, options?: GetApiV1MeshControlPlanesCpIdApiMeshesMeshMeshratelimitsNameOptions) => { 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 (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/${encodeURIComponent(String(args.name))}${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(meshRateLimitItem, await res.json()) };