/* * 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 Owner = { Cluster: "cluster", Org: "org", } as const; /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ export type Owner = ClosedEnum; export const Period = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type Period = ClosedEnum; export const Action = { Alert: "alert", Block: "block", } as const; export type Action = ClosedEnum; export type Thresholds = { pct: number; action: Action; }; export type SetOrgBudgetRequestBody = { /** * cluster = operator ceiling (org-admin read-only); org = self-budget */ owner?: Owner | undefined; period: Period; /** * Spend limit in major currency units */ limit: number; thresholds: Array; webhookUrl?: string | null | undefined; webhookSecret?: string | null | undefined; }; export type SetOrgBudgetRequest = { orgId?: string | undefined; requestBody: SetOrgBudgetRequestBody; }; export const Scope = { 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 Scope = ClosedEnum; export const SetOrgBudgetOwner = { Cluster: "cluster", Org: "org", } as const; export type SetOrgBudgetOwner = ClosedEnum; export const SetOrgBudgetPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", } as const; export type SetOrgBudgetPeriod = ClosedEnum; export const SetOrgBudgetAction = { Alert: "alert", Block: "block", } as const; export type SetOrgBudgetAction = ClosedEnum; export type SetOrgBudgetThresholds = { pct: number; action: SetOrgBudgetAction; }; export const SetOrgBudgetStatus = { Ok: "ok", Blocked: "blocked", } as const; export type SetOrgBudgetStatus = ClosedEnum; export type Spend = { /** * 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: SetOrgBudgetStatus; }; /** * OK */ export type SetOrgBudgetResponseBody = { id: string; scope: Scope; scopeId: string; scopeOrgId: string | null; owner: SetOrgBudgetOwner; period: SetOrgBudgetPeriod; limit: number; thresholds: Array; alertWebhookUrl: string | null; spend: Spend; }; /** @internal */ export const Owner$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Owner, ); /** @internal */ export const Owner$outboundSchema: z.ZodNativeEnum = Owner$inboundSchema; /** @internal */ export const Period$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Period); /** @internal */ export const Period$outboundSchema: z.ZodNativeEnum = Period$inboundSchema; /** @internal */ export const Action$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Action); /** @internal */ export const Action$outboundSchema: z.ZodNativeEnum = Action$inboundSchema; /** @internal */ export const Thresholds$inboundSchema: z.ZodType< Thresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: Action$inboundSchema, }); /** @internal */ export type Thresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const Thresholds$outboundSchema: z.ZodType< Thresholds$Outbound, z.ZodTypeDef, Thresholds > = z.object({ pct: z.number().int(), action: Action$outboundSchema, }); export function thresholdsToJSON(thresholds: Thresholds): string { return JSON.stringify(Thresholds$outboundSchema.parse(thresholds)); } export function thresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Thresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Thresholds' from JSON`, ); } /** @internal */ export const SetOrgBudgetRequestBody$inboundSchema: z.ZodType< SetOrgBudgetRequestBody, z.ZodTypeDef, unknown > = z.object({ owner: Owner$inboundSchema.default("org"), period: Period$inboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => Thresholds$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 SetOrgBudgetRequestBody$Outbound = { owner: string; period: string; limit: number; thresholds: Array; webhook_url?: string | null | undefined; webhook_secret?: string | null | undefined; }; /** @internal */ export const SetOrgBudgetRequestBody$outboundSchema: z.ZodType< SetOrgBudgetRequestBody$Outbound, z.ZodTypeDef, SetOrgBudgetRequestBody > = z.object({ owner: Owner$outboundSchema.default("org"), period: Period$outboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => Thresholds$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 setOrgBudgetRequestBodyToJSON( setOrgBudgetRequestBody: SetOrgBudgetRequestBody, ): string { return JSON.stringify( SetOrgBudgetRequestBody$outboundSchema.parse(setOrgBudgetRequestBody), ); } export function setOrgBudgetRequestBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetOrgBudgetRequestBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetOrgBudgetRequestBody' from JSON`, ); } /** @internal */ export const SetOrgBudgetRequest$inboundSchema: z.ZodType< SetOrgBudgetRequest, z.ZodTypeDef, unknown > = z.object({ org_id: z.string().optional(), RequestBody: z.lazy(() => SetOrgBudgetRequestBody$inboundSchema), }).transform((v) => { return remap$(v, { "org_id": "orgId", "RequestBody": "requestBody", }); }); /** @internal */ export type SetOrgBudgetRequest$Outbound = { org_id?: string | undefined; RequestBody: SetOrgBudgetRequestBody$Outbound; }; /** @internal */ export const SetOrgBudgetRequest$outboundSchema: z.ZodType< SetOrgBudgetRequest$Outbound, z.ZodTypeDef, SetOrgBudgetRequest > = z.object({ orgId: z.string().optional(), requestBody: z.lazy(() => SetOrgBudgetRequestBody$outboundSchema), }).transform((v) => { return remap$(v, { orgId: "org_id", requestBody: "RequestBody", }); }); export function setOrgBudgetRequestToJSON( setOrgBudgetRequest: SetOrgBudgetRequest, ): string { return JSON.stringify( SetOrgBudgetRequest$outboundSchema.parse(setOrgBudgetRequest), ); } export function setOrgBudgetRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetOrgBudgetRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetOrgBudgetRequest' from JSON`, ); } /** @internal */ export const Scope$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Scope, ); /** @internal */ export const Scope$outboundSchema: z.ZodNativeEnum = Scope$inboundSchema; /** @internal */ export const SetOrgBudgetOwner$inboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetOwner > = z.nativeEnum(SetOrgBudgetOwner); /** @internal */ export const SetOrgBudgetOwner$outboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetOwner > = SetOrgBudgetOwner$inboundSchema; /** @internal */ export const SetOrgBudgetPeriod$inboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetPeriod > = z.nativeEnum(SetOrgBudgetPeriod); /** @internal */ export const SetOrgBudgetPeriod$outboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetPeriod > = SetOrgBudgetPeriod$inboundSchema; /** @internal */ export const SetOrgBudgetAction$inboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetAction > = z.nativeEnum(SetOrgBudgetAction); /** @internal */ export const SetOrgBudgetAction$outboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetAction > = SetOrgBudgetAction$inboundSchema; /** @internal */ export const SetOrgBudgetThresholds$inboundSchema: z.ZodType< SetOrgBudgetThresholds, z.ZodTypeDef, unknown > = z.object({ pct: z.number().int(), action: SetOrgBudgetAction$inboundSchema, }); /** @internal */ export type SetOrgBudgetThresholds$Outbound = { pct: number; action: string; }; /** @internal */ export const SetOrgBudgetThresholds$outboundSchema: z.ZodType< SetOrgBudgetThresholds$Outbound, z.ZodTypeDef, SetOrgBudgetThresholds > = z.object({ pct: z.number().int(), action: SetOrgBudgetAction$outboundSchema, }); export function setOrgBudgetThresholdsToJSON( setOrgBudgetThresholds: SetOrgBudgetThresholds, ): string { return JSON.stringify( SetOrgBudgetThresholds$outboundSchema.parse(setOrgBudgetThresholds), ); } export function setOrgBudgetThresholdsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetOrgBudgetThresholds$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetOrgBudgetThresholds' from JSON`, ); } /** @internal */ export const SetOrgBudgetStatus$inboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetStatus > = z.nativeEnum(SetOrgBudgetStatus); /** @internal */ export const SetOrgBudgetStatus$outboundSchema: z.ZodNativeEnum< typeof SetOrgBudgetStatus > = SetOrgBudgetStatus$inboundSchema; /** @internal */ export const Spend$inboundSchema: z.ZodType = z .object({ window: z.string(), cost_spent: z.number(), limit: z.number(), pct: z.number().int(), status: SetOrgBudgetStatus$inboundSchema, }).transform((v) => { return remap$(v, { "cost_spent": "costSpent", }); }); /** @internal */ export type Spend$Outbound = { window: string; cost_spent: number; limit: number; pct: number; status: string; }; /** @internal */ export const Spend$outboundSchema: z.ZodType< Spend$Outbound, z.ZodTypeDef, Spend > = z.object({ window: z.string(), costSpent: z.number(), limit: z.number(), pct: z.number().int(), status: SetOrgBudgetStatus$outboundSchema, }).transform((v) => { return remap$(v, { costSpent: "cost_spent", }); }); export function spendToJSON(spend: Spend): string { return JSON.stringify(Spend$outboundSchema.parse(spend)); } export function spendFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Spend$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Spend' from JSON`, ); } /** @internal */ export const SetOrgBudgetResponseBody$inboundSchema: z.ZodType< SetOrgBudgetResponseBody, z.ZodTypeDef, unknown > = z.object({ id: z.string(), scope: Scope$inboundSchema, scope_id: z.string(), scope_org_id: z.nullable(z.string()), owner: SetOrgBudgetOwner$inboundSchema, period: SetOrgBudgetPeriod$inboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => SetOrgBudgetThresholds$inboundSchema)), alert_webhook_url: z.nullable(z.string()), spend: z.lazy(() => Spend$inboundSchema), }).transform((v) => { return remap$(v, { "scope_id": "scopeId", "scope_org_id": "scopeOrgId", "alert_webhook_url": "alertWebhookUrl", }); }); /** @internal */ export type SetOrgBudgetResponseBody$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: Spend$Outbound; }; /** @internal */ export const SetOrgBudgetResponseBody$outboundSchema: z.ZodType< SetOrgBudgetResponseBody$Outbound, z.ZodTypeDef, SetOrgBudgetResponseBody > = z.object({ id: z.string(), scope: Scope$outboundSchema, scopeId: z.string(), scopeOrgId: z.nullable(z.string()), owner: SetOrgBudgetOwner$outboundSchema, period: SetOrgBudgetPeriod$outboundSchema, limit: z.number(), thresholds: z.array(z.lazy(() => SetOrgBudgetThresholds$outboundSchema)), alertWebhookUrl: z.nullable(z.string()), spend: z.lazy(() => Spend$outboundSchema), }).transform((v) => { return remap$(v, { scopeId: "scope_id", scopeOrgId: "scope_org_id", alertWebhookUrl: "alert_webhook_url", }); }); export function setOrgBudgetResponseBodyToJSON( setOrgBudgetResponseBody: SetOrgBudgetResponseBody, ): string { return JSON.stringify( SetOrgBudgetResponseBody$outboundSchema.parse(setOrgBudgetResponseBody), ); } export function setOrgBudgetResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SetOrgBudgetResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SetOrgBudgetResponseBody' from JSON`, ); }