/* * 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 OnBehalfOf = { userType: "service-account"; serviceAccountId: string; }; export type CreateScopedApiKeyRequestBody = { name: string; teamId: string; scopes: Array; expiresIn?: number | undefined; rateLimitEnabled?: boolean | undefined; rateLimitTimeWindow?: number | undefined; rateLimitMax?: number | undefined; onBehalfOf?: OnBehalfOf | undefined; }; export type CreateScopedApiKeyRequest = { /** * Optional external end-user identifier forwarded by the API gateway. */ xOnBehalfOf?: string | undefined; requestBody?: CreateScopedApiKeyRequestBody | undefined; }; export const UserType = { User: "user", ServiceAccount: "service-account", } as const; export type UserType = ClosedEnum; /** * Key minted (plaintext returned once) */ export type CreateScopedApiKeyResponseBody = { id: string; name?: string | null | undefined; key?: string | undefined; prefix?: string | null | undefined; start?: string | null | undefined; userId: string; userType: UserType; orgId: string | null; teamId: string | null; scopes: Array; expiresAt?: string | null | undefined; }; /** @internal */ export const OnBehalfOf$inboundSchema: z.ZodType< OnBehalfOf, z.ZodTypeDef, unknown > = z.object({ userType: z.literal("service-account"), serviceAccountId: z.string(), }); /** @internal */ export type OnBehalfOf$Outbound = { userType: "service-account"; serviceAccountId: string; }; /** @internal */ export const OnBehalfOf$outboundSchema: z.ZodType< OnBehalfOf$Outbound, z.ZodTypeDef, OnBehalfOf > = z.object({ userType: z.literal("service-account"), serviceAccountId: z.string(), }); export function onBehalfOfToJSON(onBehalfOf: OnBehalfOf): string { return JSON.stringify(OnBehalfOf$outboundSchema.parse(onBehalfOf)); } export function onBehalfOfFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OnBehalfOf$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OnBehalfOf' from JSON`, ); } /** @internal */ export const CreateScopedApiKeyRequestBody$inboundSchema: z.ZodType< CreateScopedApiKeyRequestBody, z.ZodTypeDef, unknown > = z.object({ name: z.string(), teamId: z.string(), scopes: z.array(z.string()), expiresIn: z.number().int().optional(), rateLimitEnabled: z.boolean().default(false), rateLimitTimeWindow: z.number().optional(), rateLimitMax: z.number().optional(), onBehalfOf: z.lazy(() => OnBehalfOf$inboundSchema).optional(), }); /** @internal */ export type CreateScopedApiKeyRequestBody$Outbound = { name: string; teamId: string; scopes: Array; expiresIn?: number | undefined; rateLimitEnabled: boolean; rateLimitTimeWindow?: number | undefined; rateLimitMax?: number | undefined; onBehalfOf?: OnBehalfOf$Outbound | undefined; }; /** @internal */ export const CreateScopedApiKeyRequestBody$outboundSchema: z.ZodType< CreateScopedApiKeyRequestBody$Outbound, z.ZodTypeDef, CreateScopedApiKeyRequestBody > = z.object({ name: z.string(), teamId: z.string(), scopes: z.array(z.string()), expiresIn: z.number().int().optional(), rateLimitEnabled: z.boolean().default(false), rateLimitTimeWindow: z.number().optional(), rateLimitMax: z.number().optional(), onBehalfOf: z.lazy(() => OnBehalfOf$outboundSchema).optional(), }); export function createScopedApiKeyRequestBodyToJSON( createScopedApiKeyRequestBody: CreateScopedApiKeyRequestBody, ): string { return JSON.stringify( CreateScopedApiKeyRequestBody$outboundSchema.parse( createScopedApiKeyRequestBody, ), ); } export function createScopedApiKeyRequestBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateScopedApiKeyRequestBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateScopedApiKeyRequestBody' from JSON`, ); } /** @internal */ export const CreateScopedApiKeyRequest$inboundSchema: z.ZodType< CreateScopedApiKeyRequest, z.ZodTypeDef, unknown > = z.object({ "X-On-Behalf-Of": z.string().optional(), RequestBody: z.lazy(() => CreateScopedApiKeyRequestBody$inboundSchema) .optional(), }).transform((v) => { return remap$(v, { "X-On-Behalf-Of": "xOnBehalfOf", "RequestBody": "requestBody", }); }); /** @internal */ export type CreateScopedApiKeyRequest$Outbound = { "X-On-Behalf-Of"?: string | undefined; RequestBody?: CreateScopedApiKeyRequestBody$Outbound | undefined; }; /** @internal */ export const CreateScopedApiKeyRequest$outboundSchema: z.ZodType< CreateScopedApiKeyRequest$Outbound, z.ZodTypeDef, CreateScopedApiKeyRequest > = z.object({ xOnBehalfOf: z.string().optional(), requestBody: z.lazy(() => CreateScopedApiKeyRequestBody$outboundSchema) .optional(), }).transform((v) => { return remap$(v, { xOnBehalfOf: "X-On-Behalf-Of", requestBody: "RequestBody", }); }); export function createScopedApiKeyRequestToJSON( createScopedApiKeyRequest: CreateScopedApiKeyRequest, ): string { return JSON.stringify( CreateScopedApiKeyRequest$outboundSchema.parse(createScopedApiKeyRequest), ); } export function createScopedApiKeyRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateScopedApiKeyRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateScopedApiKeyRequest' from JSON`, ); } /** @internal */ export const UserType$inboundSchema: z.ZodNativeEnum = z .nativeEnum(UserType); /** @internal */ export const UserType$outboundSchema: z.ZodNativeEnum = UserType$inboundSchema; /** @internal */ export const CreateScopedApiKeyResponseBody$inboundSchema: z.ZodType< CreateScopedApiKeyResponseBody, z.ZodTypeDef, unknown > = z.object({ id: z.string(), name: z.nullable(z.string()).optional(), key: z.string().optional(), prefix: z.nullable(z.string()).optional(), start: z.nullable(z.string()).optional(), userId: z.string(), userType: UserType$inboundSchema, orgId: z.nullable(z.string()), teamId: z.nullable(z.string()), scopes: z.array(z.string()), expiresAt: z.nullable(z.string()).optional(), }); /** @internal */ export type CreateScopedApiKeyResponseBody$Outbound = { id: string; name?: string | null | undefined; key?: string | undefined; prefix?: string | null | undefined; start?: string | null | undefined; userId: string; userType: string; orgId: string | null; teamId: string | null; scopes: Array; expiresAt?: string | null | undefined; }; /** @internal */ export const CreateScopedApiKeyResponseBody$outboundSchema: z.ZodType< CreateScopedApiKeyResponseBody$Outbound, z.ZodTypeDef, CreateScopedApiKeyResponseBody > = z.object({ id: z.string(), name: z.nullable(z.string()).optional(), key: z.string().optional(), prefix: z.nullable(z.string()).optional(), start: z.nullable(z.string()).optional(), userId: z.string(), userType: UserType$outboundSchema, orgId: z.nullable(z.string()), teamId: z.nullable(z.string()), scopes: z.array(z.string()), expiresAt: z.nullable(z.string()).optional(), }); export function createScopedApiKeyResponseBodyToJSON( createScopedApiKeyResponseBody: CreateScopedApiKeyResponseBody, ): string { return JSON.stringify( CreateScopedApiKeyResponseBody$outboundSchema.parse( createScopedApiKeyResponseBody, ), ); } export function createScopedApiKeyResponseBodyFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateScopedApiKeyResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateScopedApiKeyResponseBody' from JSON`, ); }