/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type GetApiKeyBudgetsRequest = { apiKeyId: string; }; export const GetApiKeyBudgetsScope = { Org: "org", Apikey: "apikey", User: "user", Team: "team", ExternalUser: "external_user", UserDefault: "user_default", TeamDefault: "team_default", ExternalUserDefault: "external_user_default", } as const; export type GetApiKeyBudgetsScope = ClosedEnum; export const GetApiKeyBudgetsOwner = { Cluster: "cluster", Org: "org", } as const; export type GetApiKeyBudgetsOwner = ClosedEnum; export const GetApiKeyBudgetsPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type GetApiKeyBudgetsPeriod = ClosedEnum; export const GetApiKeyBudgetsAction = { Alert: "alert", Block: "block", } as const; export type GetApiKeyBudgetsAction = ClosedEnum; export type GetApiKeyBudgetsThresholds = { pct: number; action: GetApiKeyBudgetsAction; }; export const GetApiKeyBudgetsStatus = { Ok: "ok", Blocked: "blocked", } as const; export type GetApiKeyBudgetsStatus = ClosedEnum; export type GetApiKeyBudgetsSpend = { /** * Current period bucket, e.g. 2026-07 / 2026-W28 / 2026-07-07 */ window: string; /** * Live spend this window, major currency units */ costSpent: number; limit: number; pct: number; status: GetApiKeyBudgetsStatus; }; export type GetApiKeyBudgetsData = { id: string; scope: GetApiKeyBudgetsScope; scopeId: string; scopeOrgId: string | null; owner: GetApiKeyBudgetsOwner; period: GetApiKeyBudgetsPeriod; limit: number; thresholds: Array; alertWebhookUrl: string | null; spend: GetApiKeyBudgetsSpend; }; /** * OK */ export type GetApiKeyBudgetsResponseBody = { object: "list"; data: Array; }; /** @internal */ export const GetApiKeyBudgetsRequest$inboundSchema: z.ZodType< GetApiKeyBudgetsRequest, z.ZodTypeDef, unknown > = z.object({ apiKeyId: z.string(), }); /** @internal */ export type GetApiKeyBudgetsRequest$Outbound = { apiKeyId: string; }; /** @internal */ export const GetApiKeyBudgetsRequest$outboundSchema: z.ZodType< GetApiKeyBudgetsRequest$Outbound, z.ZodTypeDef, GetApiKeyBudgetsRequest > = z.object({ apiKeyId: z.string(), }); export function getApiKeyBudgetsRequestToJSON( getApiKeyBudgetsRequest: GetApiKeyBudgetsRequest, ): string { return JSON.stringify( GetApiKeyBudgetsRequest$outboundSchema.parse(getApiKeyBudgetsRequest), ); } export function getApiKeyBudgetsRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetApiKeyBudgetsRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetApiKeyBudgetsRequest' from JSON`, ); } /** @internal */ export const GetApiKeyBudgetsScope$inboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsScope > = z.nativeEnum(GetApiKeyBudgetsScope); /** @internal */ export const GetApiKeyBudgetsScope$outboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsScope > = GetApiKeyBudgetsScope$inboundSchema; /** @internal */ export const GetApiKeyBudgetsOwner$inboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsOwner > = z.nativeEnum(GetApiKeyBudgetsOwner); /** @internal */ export const GetApiKeyBudgetsOwner$outboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsOwner > = GetApiKeyBudgetsOwner$inboundSchema; /** @internal */ export const GetApiKeyBudgetsPeriod$inboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsPeriod > = z.nativeEnum(GetApiKeyBudgetsPeriod); /** @internal */ export const GetApiKeyBudgetsPeriod$outboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsPeriod > = GetApiKeyBudgetsPeriod$inboundSchema; /** @internal */ export const GetApiKeyBudgetsAction$inboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsAction > = z.nativeEnum(GetApiKeyBudgetsAction); /** @internal */ export const GetApiKeyBudgetsAction$outboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsAction > = GetApiKeyBudgetsAction$inboundSchema; /** @internal */ export const GetApiKeyBudgetsThresholds$inboundSchema: z.ZodType< GetApiKeyBudgetsThresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: GetApiKeyBudgetsAction$inboundSchema, }); /** @internal */ export type GetApiKeyBudgetsThresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const GetApiKeyBudgetsThresholds$outboundSchema: z.ZodType< GetApiKeyBudgetsThresholds$Outbound, z.ZodTypeDef, GetApiKeyBudgetsThresholds > = z.object({ pct: z.number().int(), action: GetApiKeyBudgetsAction$outboundSchema, }); export function getApiKeyBudgetsThresholdsToJSON( getApiKeyBudgetsThresholds: GetApiKeyBudgetsThresholds, ): string { return JSON.stringify( GetApiKeyBudgetsThresholds$outboundSchema.parse(getApiKeyBudgetsThresholds), ); } export function getApiKeyBudgetsThresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetApiKeyBudgetsThresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetApiKeyBudgetsThresholds' from JSON`, ); } /** @internal */ export const GetApiKeyBudgetsStatus$inboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsStatus > = z.nativeEnum(GetApiKeyBudgetsStatus); /** @internal */ export const GetApiKeyBudgetsStatus$outboundSchema: z.ZodNativeEnum< typeof GetApiKeyBudgetsStatus > = GetApiKeyBudgetsStatus$inboundSchema; /** @internal */ export const GetApiKeyBudgetsSpend$inboundSchema: z.ZodType< GetApiKeyBudgetsSpend, z.ZodTypeDef, unknown > = z.object({ window: z.string(), cost_spent: z.number(), limit: z.number(), pct: z.number().int(), status: GetApiKeyBudgetsStatus$inboundSchema, }).transform((v) => { return remap$(v, { "cost_spent": "costSpent", }); }); /** @internal */ export type GetApiKeyBudgetsSpend$Outbound = { window: string; cost_spent: number; limit: number; pct: number; status: string; }; /** @internal */ export const GetApiKeyBudgetsSpend$outboundSchema: z.ZodType< GetApiKeyBudgetsSpend$Outbound, z.ZodTypeDef, GetApiKeyBudgetsSpend > = z.object({ window: z.string(), costSpent: z.number(), limit: z.number(), pct: z.number().int(), status: GetApiKeyBudgetsStatus$outboundSchema, }).transform((v) => { return remap$(v, { costSpent: "cost_spent", }); }); export function getApiKeyBudgetsSpendToJSON( getApiKeyBudgetsSpend: GetApiKeyBudgetsSpend, ): string { return JSON.stringify( GetApiKeyBudgetsSpend$outboundSchema.parse(getApiKeyBudgetsSpend), ); } export function getApiKeyBudgetsSpendFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetApiKeyBudgetsSpend$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetApiKeyBudgetsSpend' from JSON`, ); } /** @internal */ export const GetApiKeyBudgetsData$inboundSchema: z.ZodType< GetApiKeyBudgetsData, z.ZodTypeDef, unknown > = z.object({ id: z.string(), scope: GetApiKeyBudgetsScope$inboundSchema, scope_id: z.string(), scope_org_id: z.nullable(z.string()), owner: GetApiKeyBudgetsOwner$inboundSchema, period: GetApiKeyBudgetsPeriod$inboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => GetApiKeyBudgetsThresholds$inboundSchema)), alert_webhook_url: z.nullable(z.string()), spend: z.lazy(() => GetApiKeyBudgetsSpend$inboundSchema), }).transform((v) => { return remap$(v, { "scope_id": "scopeId", "scope_org_id": "scopeOrgId", "alert_webhook_url": "alertWebhookUrl", }); }); /** @internal */ export type GetApiKeyBudgetsData$Outbound = { id: string; scope: string; scope_id: string; scope_org_id: string | null; owner: string; period: string; limit: number; thresholds: Array; alert_webhook_url: string | null; spend: GetApiKeyBudgetsSpend$Outbound; }; /** @internal */ export const GetApiKeyBudgetsData$outboundSchema: z.ZodType< GetApiKeyBudgetsData$Outbound, z.ZodTypeDef, GetApiKeyBudgetsData > = z.object({ id: z.string(), scope: GetApiKeyBudgetsScope$outboundSchema, scopeId: z.string(), scopeOrgId: z.nullable(z.string()), owner: GetApiKeyBudgetsOwner$outboundSchema, period: GetApiKeyBudgetsPeriod$outboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => GetApiKeyBudgetsThresholds$outboundSchema)), alertWebhookUrl: z.nullable(z.string()), spend: z.lazy(() => GetApiKeyBudgetsSpend$outboundSchema), }).transform((v) => { return remap$(v, { scopeId: "scope_id", scopeOrgId: "scope_org_id", alertWebhookUrl: "alert_webhook_url", }); }); export function getApiKeyBudgetsDataToJSON( getApiKeyBudgetsData: GetApiKeyBudgetsData, ): string { return JSON.stringify( GetApiKeyBudgetsData$outboundSchema.parse(getApiKeyBudgetsData), ); } export function getApiKeyBudgetsDataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetApiKeyBudgetsData$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetApiKeyBudgetsData' from JSON`, ); } /** @internal */ export const GetApiKeyBudgetsResponseBody$inboundSchema: z.ZodType< GetApiKeyBudgetsResponseBody, z.ZodTypeDef, unknown > = z.object({ object: z.literal("list"), data: z.array(z.lazy(() => GetApiKeyBudgetsData$inboundSchema)), }); /** @internal */ export type GetApiKeyBudgetsResponseBody$Outbound = { object: "list"; data: Array; }; /** @internal */ export const GetApiKeyBudgetsResponseBody$outboundSchema: z.ZodType< GetApiKeyBudgetsResponseBody$Outbound, z.ZodTypeDef, GetApiKeyBudgetsResponseBody > = z.object({ object: z.literal("list"), data: z.array(z.lazy(() => GetApiKeyBudgetsData$outboundSchema)), }); export function getApiKeyBudgetsResponseBodyToJSON( getApiKeyBudgetsResponseBody: GetApiKeyBudgetsResponseBody, ): string { return JSON.stringify( GetApiKeyBudgetsResponseBody$outboundSchema.parse( getApiKeyBudgetsResponseBody, ), ); } export function getApiKeyBudgetsResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetApiKeyBudgetsResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetApiKeyBudgetsResponseBody' from JSON`, ); }