/* * 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"; /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ export const SetUserBudgetOwner = { Cluster: "cluster", Org: "org", } as const; /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ export type SetUserBudgetOwner = ClosedEnum; export const SetUserBudgetPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type SetUserBudgetPeriod = ClosedEnum; export const SetUserBudgetAction = { Alert: "alert", Block: "block", } as const; export type SetUserBudgetAction = ClosedEnum; export type SetUserBudgetThresholds = { pct: number; action: SetUserBudgetAction; }; export type SetUserBudgetRequestBody = { /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ owner?: SetUserBudgetOwner | undefined; period: SetUserBudgetPeriod; /** * Spend limit in major currency units */ limit: number; thresholds: Array; webhookUrl?: string | null | undefined; webhookSecret?: string | null | undefined; }; export type SetUserBudgetRequest = { id: string; orgId?: string | undefined; requestBody: SetUserBudgetRequestBody; }; export const SetUserBudgetScope = { 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 SetUserBudgetScope = ClosedEnum; export const SetUserBudgetBudgetsOwner = { Cluster: "cluster", Org: "org", } as const; export type SetUserBudgetBudgetsOwner = ClosedEnum< typeof SetUserBudgetBudgetsOwner >; export const SetUserBudgetBudgetsPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type SetUserBudgetBudgetsPeriod = ClosedEnum< typeof SetUserBudgetBudgetsPeriod >; export const SetUserBudgetBudgetsAction = { Alert: "alert", Block: "block", } as const; export type SetUserBudgetBudgetsAction = ClosedEnum< typeof SetUserBudgetBudgetsAction >; export type SetUserBudgetBudgetsThresholds = { pct: number; action: SetUserBudgetBudgetsAction; }; export const SetUserBudgetStatus = { Ok: "ok", Blocked: "blocked", } as const; export type SetUserBudgetStatus = ClosedEnum; export type SetUserBudgetSpend = { /** * 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: SetUserBudgetStatus; }; /** * OK */ export type SetUserBudgetResponseBody = { id: string; scope: SetUserBudgetScope; scopeId: string; scopeOrgId: string | null; owner: SetUserBudgetBudgetsOwner; period: SetUserBudgetBudgetsPeriod; limit: number; thresholds: Array; alertWebhookUrl: string | null; spend: SetUserBudgetSpend; }; /** @internal */ export const SetUserBudgetOwner$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetOwner > = z.nativeEnum(SetUserBudgetOwner); /** @internal */ export const SetUserBudgetOwner$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetOwner > = SetUserBudgetOwner$inboundSchema; /** @internal */ export const SetUserBudgetPeriod$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetPeriod > = z.nativeEnum(SetUserBudgetPeriod); /** @internal */ export const SetUserBudgetPeriod$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetPeriod > = SetUserBudgetPeriod$inboundSchema; /** @internal */ export const SetUserBudgetAction$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetAction > = z.nativeEnum(SetUserBudgetAction); /** @internal */ export const SetUserBudgetAction$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetAction > = SetUserBudgetAction$inboundSchema; /** @internal */ export const SetUserBudgetThresholds$inboundSchema: z.ZodType< SetUserBudgetThresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: SetUserBudgetAction$inboundSchema, }); /** @internal */ export type SetUserBudgetThresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const SetUserBudgetThresholds$outboundSchema: z.ZodType< SetUserBudgetThresholds$Outbound, z.ZodTypeDef, SetUserBudgetThresholds > = z.object({ pct: z.number().int(), action: SetUserBudgetAction$outboundSchema, }); export function setUserBudgetThresholdsToJSON( setUserBudgetThresholds: SetUserBudgetThresholds, ): string { return JSON.stringify( SetUserBudgetThresholds$outboundSchema.parse(setUserBudgetThresholds), ); } export function setUserBudgetThresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetUserBudgetThresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetUserBudgetThresholds' from JSON`, ); } /** @internal */ export const SetUserBudgetRequestBody$inboundSchema: z.ZodType< SetUserBudgetRequestBody, z.ZodTypeDef, unknown > = z.object({ owner: SetUserBudgetOwner$inboundSchema.default("org"), period: SetUserBudgetPeriod$inboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => SetUserBudgetThresholds$inboundSchema)), webhook_url: z.nullable(z.string()).optional(), webhook_secret: z.nullable(z.string()).optional(), }).transform((v) => { return remap$(v, { "webhook_url": "webhookUrl", "webhook_secret": "webhookSecret", }); }); /** @internal */ export type SetUserBudgetRequestBody$Outbound = { owner: string; period: string; limit: number; thresholds: Array; webhook_url?: string | null | undefined; webhook_secret?: string | null | undefined; }; /** @internal */ export const SetUserBudgetRequestBody$outboundSchema: z.ZodType< SetUserBudgetRequestBody$Outbound, z.ZodTypeDef, SetUserBudgetRequestBody > = z.object({ owner: SetUserBudgetOwner$outboundSchema.default("org"), period: SetUserBudgetPeriod$outboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => SetUserBudgetThresholds$outboundSchema)), webhookUrl: z.nullable(z.string()).optional(), webhookSecret: z.nullable(z.string()).optional(), }).transform((v) => { return remap$(v, { webhookUrl: "webhook_url", webhookSecret: "webhook_secret", }); }); export function setUserBudgetRequestBodyToJSON( setUserBudgetRequestBody: SetUserBudgetRequestBody, ): string { return JSON.stringify( SetUserBudgetRequestBody$outboundSchema.parse(setUserBudgetRequestBody), ); } export function setUserBudgetRequestBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetUserBudgetRequestBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetUserBudgetRequestBody' from JSON`, ); } /** @internal */ export const SetUserBudgetRequest$inboundSchema: z.ZodType< SetUserBudgetRequest, z.ZodTypeDef, unknown > = z.object({ id: z.string(), org_id: z.string().optional(), RequestBody: z.lazy(() => SetUserBudgetRequestBody$inboundSchema), }).transform((v) => { return remap$(v, { "org_id": "orgId", "RequestBody": "requestBody", }); }); /** @internal */ export type SetUserBudgetRequest$Outbound = { id: string; org_id?: string | undefined; RequestBody: SetUserBudgetRequestBody$Outbound; }; /** @internal */ export const SetUserBudgetRequest$outboundSchema: z.ZodType< SetUserBudgetRequest$Outbound, z.ZodTypeDef, SetUserBudgetRequest > = z.object({ id: z.string(), orgId: z.string().optional(), requestBody: z.lazy(() => SetUserBudgetRequestBody$outboundSchema), }).transform((v) => { return remap$(v, { orgId: "org_id", requestBody: "RequestBody", }); }); export function setUserBudgetRequestToJSON( setUserBudgetRequest: SetUserBudgetRequest, ): string { return JSON.stringify( SetUserBudgetRequest$outboundSchema.parse(setUserBudgetRequest), ); } export function setUserBudgetRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetUserBudgetRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetUserBudgetRequest' from JSON`, ); } /** @internal */ export const SetUserBudgetScope$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetScope > = z.nativeEnum(SetUserBudgetScope); /** @internal */ export const SetUserBudgetScope$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetScope > = SetUserBudgetScope$inboundSchema; /** @internal */ export const SetUserBudgetBudgetsOwner$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetBudgetsOwner > = z.nativeEnum(SetUserBudgetBudgetsOwner); /** @internal */ export const SetUserBudgetBudgetsOwner$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetBudgetsOwner > = SetUserBudgetBudgetsOwner$inboundSchema; /** @internal */ export const SetUserBudgetBudgetsPeriod$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetBudgetsPeriod > = z.nativeEnum(SetUserBudgetBudgetsPeriod); /** @internal */ export const SetUserBudgetBudgetsPeriod$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetBudgetsPeriod > = SetUserBudgetBudgetsPeriod$inboundSchema; /** @internal */ export const SetUserBudgetBudgetsAction$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetBudgetsAction > = z.nativeEnum(SetUserBudgetBudgetsAction); /** @internal */ export const SetUserBudgetBudgetsAction$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetBudgetsAction > = SetUserBudgetBudgetsAction$inboundSchema; /** @internal */ export const SetUserBudgetBudgetsThresholds$inboundSchema: z.ZodType< SetUserBudgetBudgetsThresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: SetUserBudgetBudgetsAction$inboundSchema, }); /** @internal */ export type SetUserBudgetBudgetsThresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const SetUserBudgetBudgetsThresholds$outboundSchema: z.ZodType< SetUserBudgetBudgetsThresholds$Outbound, z.ZodTypeDef, SetUserBudgetBudgetsThresholds > = z.object({ pct: z.number().int(), action: SetUserBudgetBudgetsAction$outboundSchema, }); export function setUserBudgetBudgetsThresholdsToJSON( setUserBudgetBudgetsThresholds: SetUserBudgetBudgetsThresholds, ): string { return JSON.stringify( SetUserBudgetBudgetsThresholds$outboundSchema.parse( setUserBudgetBudgetsThresholds, ), ); } export function setUserBudgetBudgetsThresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetUserBudgetBudgetsThresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetUserBudgetBudgetsThresholds' from JSON`, ); } /** @internal */ export const SetUserBudgetStatus$inboundSchema: z.ZodNativeEnum< typeof SetUserBudgetStatus > = z.nativeEnum(SetUserBudgetStatus); /** @internal */ export const SetUserBudgetStatus$outboundSchema: z.ZodNativeEnum< typeof SetUserBudgetStatus > = SetUserBudgetStatus$inboundSchema; /** @internal */ export const SetUserBudgetSpend$inboundSchema: z.ZodType< SetUserBudgetSpend, z.ZodTypeDef, unknown > = z.object({ window: z.string(), cost_spent: z.number(), limit: z.number(), pct: z.number().int(), status: SetUserBudgetStatus$inboundSchema, }).transform((v) => { return remap$(v, { "cost_spent": "costSpent", }); }); /** @internal */ export type SetUserBudgetSpend$Outbound = { window: string; cost_spent: number; limit: number; pct: number; status: string; }; /** @internal */ export const SetUserBudgetSpend$outboundSchema: z.ZodType< SetUserBudgetSpend$Outbound, z.ZodTypeDef, SetUserBudgetSpend > = z.object({ window: z.string(), costSpent: z.number(), limit: z.number(), pct: z.number().int(), status: SetUserBudgetStatus$outboundSchema, }).transform((v) => { return remap$(v, { costSpent: "cost_spent", }); }); export function setUserBudgetSpendToJSON( setUserBudgetSpend: SetUserBudgetSpend, ): string { return JSON.stringify( SetUserBudgetSpend$outboundSchema.parse(setUserBudgetSpend), ); } export function setUserBudgetSpendFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetUserBudgetSpend$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetUserBudgetSpend' from JSON`, ); } /** @internal */ export const SetUserBudgetResponseBody$inboundSchema: z.ZodType< SetUserBudgetResponseBody, z.ZodTypeDef, unknown > = z.object({ id: z.string(), scope: SetUserBudgetScope$inboundSchema, scope_id: z.string(), scope_org_id: z.nullable(z.string()), owner: SetUserBudgetBudgetsOwner$inboundSchema, period: SetUserBudgetBudgetsPeriod$inboundSchema, limit: z.number(), thresholds: z.array( z.lazy(() => SetUserBudgetBudgetsThresholds$inboundSchema), ), alert_webhook_url: z.nullable(z.string()), spend: z.lazy(() => SetUserBudgetSpend$inboundSchema), }).transform((v) => { return remap$(v, { "scope_id": "scopeId", "scope_org_id": "scopeOrgId", "alert_webhook_url": "alertWebhookUrl", }); }); /** @internal */ export type SetUserBudgetResponseBody$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: SetUserBudgetSpend$Outbound; }; /** @internal */ export const SetUserBudgetResponseBody$outboundSchema: z.ZodType< SetUserBudgetResponseBody$Outbound, z.ZodTypeDef, SetUserBudgetResponseBody > = z.object({ id: z.string(), scope: SetUserBudgetScope$outboundSchema, scopeId: z.string(), scopeOrgId: z.nullable(z.string()), owner: SetUserBudgetBudgetsOwner$outboundSchema, period: SetUserBudgetBudgetsPeriod$outboundSchema, limit: z.number(), thresholds: z.array( z.lazy(() => SetUserBudgetBudgetsThresholds$outboundSchema), ), alertWebhookUrl: z.nullable(z.string()), spend: z.lazy(() => SetUserBudgetSpend$outboundSchema), }).transform((v) => { return remap$(v, { scopeId: "scope_id", scopeOrgId: "scope_org_id", alertWebhookUrl: "alert_webhook_url", }); }); export function setUserBudgetResponseBodyToJSON( setUserBudgetResponseBody: SetUserBudgetResponseBody, ): string { return JSON.stringify( SetUserBudgetResponseBody$outboundSchema.parse(setUserBudgetResponseBody), ); } export function setUserBudgetResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetUserBudgetResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetUserBudgetResponseBody' from JSON`, ); }