UNPKG

@vercel/sdk

Version:

<p align="center"> <a href="https://vercel.com"> <img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96"> <h3 align="center">Vercel</h3> </a> <p align="center">Develop. Preview. Ship.</p> </p>

461 lines (410 loc) 12.4 kB
/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { safeParse } from "../lib/schemas.js"; import { ClosedEnum } from "../types/enums.js"; import { Result as SafeParseResult } from "../types/fp.js"; import * as types from "../types/primitives.js"; import { APIKey, APIKey$inboundSchema } from "./apikey.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; import { VercelError } from "./vercelerror.js"; /** * How often the quota refreshes. */ export const CreateApiKeysRefreshPeriod = { Daily: "daily", Weekly: "weekly", Monthly: "monthly", None: "none", } as const; /** * How often the quota refreshes. */ export type CreateApiKeysRefreshPeriod = ClosedEnum< typeof CreateApiKeysRefreshPeriod >; /** * Optional AI Gateway quota configuration for the API key. */ export type AiGatewayQuota = { /** * The quota limit amount. */ limitAmount: number; /** * Whether to include BYOK (Bring Your Own Key) usage in the quota. */ includeByokInQuota?: boolean | undefined; /** * How often the quota refreshes. */ refreshPeriod?: CreateApiKeysRefreshPeriod | undefined; /** * Spend percentages (a subset of [50, 75, 100]) at which to send a spend alert. */ alertThresholds?: Array<number> | undefined; }; export type CreateApiKeysRequestBody = { /** * The API key's purpose, which restricts how it can be used. */ purpose: string; /** * An optional project to restrict the API key to. */ projectId?: string | undefined; /** * An optional name for the API key. */ name?: string | undefined; /** * The API key's expiration, expressed as a UNIX timestamp in milliseconds. */ expiresAt?: number | undefined; /** * Optional AI Gateway quota configuration for the API key. */ aiGatewayQuota?: AiGatewayQuota | undefined; /** * Optional generic metadata for the API key. The accepted shape depends on the key's `purpose` and is validated on creation; for `ai-gateway` keys this accepts `environment`. */ metadata?: { [k: string]: any } | undefined; }; export type CreateApiKeysResponse500Error = { code: string; message: string; }; export type CreateApiKeysResponse500ResponseBodyData = { error: CreateApiKeysResponse500Error; }; export class CreateApiKeysResponse500ResponseBody extends VercelError { error: CreateApiKeysResponse500Error; /** The original data that was passed to this error instance. */ data$: CreateApiKeysResponse500ResponseBodyData; constructor( err: CreateApiKeysResponse500ResponseBodyData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.error?.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.error = err.error; this.name = "CreateApiKeysResponse500ResponseBody"; } } export type CreateApiKeysResponse429Error = { code: string; name: string; message: string; limit: number; }; export type CreateApiKeysResponse429ResponseBodyData = { error: CreateApiKeysResponse429Error; }; export class CreateApiKeysResponse429ResponseBody extends VercelError { error: CreateApiKeysResponse429Error; /** The original data that was passed to this error instance. */ data$: CreateApiKeysResponse429ResponseBodyData; constructor( err: CreateApiKeysResponse429ResponseBodyData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.error?.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.error = err.error; this.name = "CreateApiKeysResponse429ResponseBody"; } } export type CreateApiKeysResponseError = { code: string; message: string; }; /** * You do not have permission to access this resource. */ export type CreateApiKeysResponse403ResponseBodyData = { error: CreateApiKeysResponseError; }; /** * You do not have permission to access this resource. */ export class CreateApiKeysResponse403ResponseBody extends VercelError { error: CreateApiKeysResponseError; /** The original data that was passed to this error instance. */ data$: CreateApiKeysResponse403ResponseBodyData; constructor( err: CreateApiKeysResponse403ResponseBodyData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.error?.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.error = err.error; this.name = "CreateApiKeysResponse403ResponseBody"; } } export type CreateApiKeysError = { code: string; message: string; }; /** * The request is not authorized. */ export type CreateApiKeysResponseResponseBodyData = { error: CreateApiKeysError; }; /** * The request is not authorized. */ export class CreateApiKeysResponseResponseBody extends VercelError { error: CreateApiKeysError; /** The original data that was passed to this error instance. */ data$: CreateApiKeysResponseResponseBodyData; constructor( err: CreateApiKeysResponseResponseBodyData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.error?.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.error = err.error; this.name = "CreateApiKeysResponseResponseBody"; } } /** * Successfully created an API key. */ export type CreateApiKeysResponseBody = { /** * The API key's actual value. This value is only provided in this response, and can never be retrieved again in the future. Be sure to save it somewhere safe! */ apiKeyString: string; /** * Information about the newly created API key. */ apiKey: APIKey; }; /** @internal */ export const CreateApiKeysRefreshPeriod$outboundSchema: z.ZodNativeEnum< typeof CreateApiKeysRefreshPeriod > = z.nativeEnum(CreateApiKeysRefreshPeriod); /** @internal */ export type AiGatewayQuota$Outbound = { limitAmount: number; includeByokInQuota: boolean; refreshPeriod: string; alertThresholds?: Array<number> | undefined; }; /** @internal */ export const AiGatewayQuota$outboundSchema: z.ZodType< AiGatewayQuota$Outbound, z.ZodTypeDef, AiGatewayQuota > = z.object({ limitAmount: z.number(), includeByokInQuota: z.boolean().default(false), refreshPeriod: CreateApiKeysRefreshPeriod$outboundSchema.default("none"), alertThresholds: z.array(z.number()).optional(), }); export function aiGatewayQuotaToJSON(aiGatewayQuota: AiGatewayQuota): string { return JSON.stringify(AiGatewayQuota$outboundSchema.parse(aiGatewayQuota)); } /** @internal */ export type CreateApiKeysRequestBody$Outbound = { purpose: string; projectId?: string | undefined; name?: string | undefined; expiresAt?: number | undefined; aiGatewayQuota?: AiGatewayQuota$Outbound | undefined; metadata?: { [k: string]: any } | undefined; }; /** @internal */ export const CreateApiKeysRequestBody$outboundSchema: z.ZodType< CreateApiKeysRequestBody$Outbound, z.ZodTypeDef, CreateApiKeysRequestBody > = z.object({ purpose: z.string(), projectId: z.string().optional(), name: z.string().optional(), expiresAt: z.number().optional(), aiGatewayQuota: z.lazy(() => AiGatewayQuota$outboundSchema).optional(), metadata: z.record(z.any()).optional(), }); export function createApiKeysRequestBodyToJSON( createApiKeysRequestBody: CreateApiKeysRequestBody, ): string { return JSON.stringify( CreateApiKeysRequestBody$outboundSchema.parse(createApiKeysRequestBody), ); } /** @internal */ export const CreateApiKeysResponse500Error$inboundSchema: z.ZodType< CreateApiKeysResponse500Error, z.ZodTypeDef, unknown > = z.object({ code: types.string(), message: types.string(), }); export function createApiKeysResponse500ErrorFromJSON( jsonString: string, ): SafeParseResult<CreateApiKeysResponse500Error, SDKValidationError> { return safeParse( jsonString, (x) => CreateApiKeysResponse500Error$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateApiKeysResponse500Error' from JSON`, ); } /** @internal */ export const CreateApiKeysResponse500ResponseBody$inboundSchema: z.ZodType< CreateApiKeysResponse500ResponseBody, z.ZodTypeDef, unknown > = z.object({ error: z.lazy(() => CreateApiKeysResponse500Error$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new CreateApiKeysResponse500ResponseBody(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export const CreateApiKeysResponse429Error$inboundSchema: z.ZodType< CreateApiKeysResponse429Error, z.ZodTypeDef, unknown > = z.object({ code: types.string(), name: types.string(), message: types.string(), limit: types.number(), }); export function createApiKeysResponse429ErrorFromJSON( jsonString: string, ): SafeParseResult<CreateApiKeysResponse429Error, SDKValidationError> { return safeParse( jsonString, (x) => CreateApiKeysResponse429Error$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateApiKeysResponse429Error' from JSON`, ); } /** @internal */ export const CreateApiKeysResponse429ResponseBody$inboundSchema: z.ZodType< CreateApiKeysResponse429ResponseBody, z.ZodTypeDef, unknown > = z.object({ error: z.lazy(() => CreateApiKeysResponse429Error$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new CreateApiKeysResponse429ResponseBody(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export const CreateApiKeysResponseError$inboundSchema: z.ZodType< CreateApiKeysResponseError, z.ZodTypeDef, unknown > = z.object({ code: types.string(), message: types.string(), }); export function createApiKeysResponseErrorFromJSON( jsonString: string, ): SafeParseResult<CreateApiKeysResponseError, SDKValidationError> { return safeParse( jsonString, (x) => CreateApiKeysResponseError$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateApiKeysResponseError' from JSON`, ); } /** @internal */ export const CreateApiKeysResponse403ResponseBody$inboundSchema: z.ZodType< CreateApiKeysResponse403ResponseBody, z.ZodTypeDef, unknown > = z.object({ error: z.lazy(() => CreateApiKeysResponseError$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new CreateApiKeysResponse403ResponseBody(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export const CreateApiKeysError$inboundSchema: z.ZodType< CreateApiKeysError, z.ZodTypeDef, unknown > = z.object({ code: types.string(), message: types.string(), }); export function createApiKeysErrorFromJSON( jsonString: string, ): SafeParseResult<CreateApiKeysError, SDKValidationError> { return safeParse( jsonString, (x) => CreateApiKeysError$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateApiKeysError' from JSON`, ); } /** @internal */ export const CreateApiKeysResponseResponseBody$inboundSchema: z.ZodType< CreateApiKeysResponseResponseBody, z.ZodTypeDef, unknown > = z.object({ error: z.lazy(() => CreateApiKeysError$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new CreateApiKeysResponseResponseBody(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export const CreateApiKeysResponseBody$inboundSchema: z.ZodType< CreateApiKeysResponseBody, z.ZodTypeDef, unknown > = z.object({ apiKeyString: types.string(), apiKey: APIKey$inboundSchema, }); export function createApiKeysResponseBodyFromJSON( jsonString: string, ): SafeParseResult<CreateApiKeysResponseBody, SDKValidationError> { return safeParse( jsonString, (x) => CreateApiKeysResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateApiKeysResponseBody' from JSON`, ); }