/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. * @generated-id: f5333b124660 */ import * as z from "zod/v4"; import { safeParse } from "../lib/schemas.js"; import { ClosedEnum } from "../types/enums.js"; import { Result as SafeParseResult } from "../types/fp.js"; import { APIKeyDeploymentSetupConfig, APIKeyDeploymentSetupConfig$inboundSchema, } from "./apikeydeploymentsetupconfig.js"; import { SDKValidationError } from "./errors/sdkvalidationerror.js"; export const CreateAPIKeyResponseType = { Workspace: "workspace", Project: "project", Deployment: "deployment", DeploymentGroup: "deployment-group", Manager: "manager", } as const; export type CreateAPIKeyResponseType = ClosedEnum< typeof CreateAPIKeyResponseType >; export type KeyInfo = { /** * Unique identifier for the api key. */ id: string; description: string | null; keyPrefix: string; type: CreateAPIKeyResponseType; role: string; workspaceId: string; projectId: string | null; deploymentId: string | null; deploymentGroupId: string | null; managerId: string | null; enabled: boolean; createdAt: Date; expiresAt: Date | null; lastUsedAt: Date | null; revokedAt: Date | null; deploymentSetupConfig: APIKeyDeploymentSetupConfig | null; }; /** * Response containing the new API key and its metadata */ export type CreateAPIKeyResponse = { /** * The generated API key value (only shown once) */ apiKey: string; keyInfo: KeyInfo; }; /** @internal */ export const CreateAPIKeyResponseType$inboundSchema: z.ZodEnum< typeof CreateAPIKeyResponseType > = z.enum(CreateAPIKeyResponseType); /** @internal */ export const KeyInfo$inboundSchema: z.ZodType = z.object({ id: z.string(), description: z.nullable(z.string()), keyPrefix: z.string(), type: CreateAPIKeyResponseType$inboundSchema, role: z.string(), workspaceId: z.string(), projectId: z.nullable(z.string()), deploymentId: z.nullable(z.string()), deploymentGroupId: z.nullable(z.string()), managerId: z.nullable(z.string()), enabled: z.boolean(), createdAt: z.iso.datetime({ offset: true }).transform(v => new Date(v)), expiresAt: z.nullable( z.iso.datetime({ offset: true }).transform(v => new Date(v)), ), lastUsedAt: z.nullable( z.iso.datetime({ offset: true }).transform(v => new Date(v)), ), revokedAt: z.nullable( z.iso.datetime({ offset: true }).transform(v => new Date(v)), ), deploymentSetupConfig: z.nullable(APIKeyDeploymentSetupConfig$inboundSchema), }); export function keyInfoFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => KeyInfo$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'KeyInfo' from JSON`, ); } /** @internal */ export const CreateAPIKeyResponse$inboundSchema: z.ZodType< CreateAPIKeyResponse, unknown > = z.object({ apiKey: z.string(), keyInfo: z.lazy(() => KeyInfo$inboundSchema), }); export function createAPIKeyResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateAPIKeyResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateAPIKeyResponse' from JSON`, ); }