@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>
498 lines (438 loc) • 13.4 kB
text/typescript
/*
* 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 * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
export type PathCondition = {
value?: string | undefined;
syntax?: string | undefined;
};
export type GenerateRouteConditions = {
field?: string | undefined;
operator?: string | undefined;
key?: string | undefined;
value?: string | undefined;
missing?: boolean | undefined;
};
export type GenerateRouteHeaders = {
key?: string | undefined;
value?: string | undefined;
op?: string | undefined;
};
export type Actions = {
type?: string | undefined;
subType?: string | undefined;
dest?: string | undefined;
status?: number | undefined;
headers?: Array<GenerateRouteHeaders> | undefined;
};
export type CurrentRoute = {
name?: string | undefined;
description?: string | undefined;
pathCondition: PathCondition;
conditions?: Array<GenerateRouteConditions> | undefined;
actions: Array<Actions>;
};
export type GenerateRouteRequestBody = {
prompt: string;
currentRoute?: CurrentRoute | undefined;
};
export type GenerateRouteRequest = {
projectId: string;
/**
* The Team identifier to perform the request on behalf of.
*/
teamId?: string | undefined;
/**
* The Team slug to perform the request on behalf of.
*/
slug?: string | undefined;
requestBody?: GenerateRouteRequestBody | undefined;
};
export const Syntax = {
Equals: "equals",
PathToRegexp: "path-to-regexp",
Regex: "regex",
} as const;
export type Syntax = ClosedEnum<typeof Syntax>;
export type GenerateRoutePathCondition = {
value: string;
syntax: Syntax;
};
export const GenerateRouteField = {
Cookie: "cookie",
Header: "header",
Host: "host",
Query: "query",
} as const;
export type GenerateRouteField = ClosedEnum<typeof GenerateRouteField>;
export const Operator = {
Contains: "contains",
Eq: "eq",
Exists: "exists",
Re: "re",
} as const;
export type Operator = ClosedEnum<typeof Operator>;
export type GenerateRouteProjectRoutesConditions = {
field: GenerateRouteField;
operator: Operator;
key?: string | undefined;
value?: string | undefined;
missing: boolean;
};
export const GenerateRouteType = {
Modify: "modify",
Redirect: "redirect",
Rewrite: "rewrite",
SetStatus: "set-status",
} as const;
export type GenerateRouteType = ClosedEnum<typeof GenerateRouteType>;
export const SubType = {
ResponseHeaders: "response-headers",
TransformRequestHeader: "transform-request-header",
TransformRequestQuery: "transform-request-query",
} as const;
export type SubType = ClosedEnum<typeof SubType>;
export const GenerateRouteOp = {
Append: "append",
Delete: "delete",
Set: "set",
} as const;
export type GenerateRouteOp = ClosedEnum<typeof GenerateRouteOp>;
export type GenerateRouteProjectRoutesHeaders = {
key: string;
value?: string | undefined;
op: GenerateRouteOp;
};
export type GenerateRouteActions = {
type: GenerateRouteType;
subType?: SubType | undefined;
dest?: string | undefined;
status?: number | undefined;
headers?: Array<GenerateRouteProjectRoutesHeaders> | undefined;
};
export type GenerateRouteRoute = {
name: string;
description: string;
pathCondition: GenerateRoutePathCondition;
conditions?: Array<GenerateRouteProjectRoutesConditions> | undefined;
actions: Array<GenerateRouteActions>;
};
export type GenerateRouteResponseBody = {
route?: GenerateRouteRoute | undefined;
error?: string | undefined;
};
/** @internal */
export type PathCondition$Outbound = {
value?: string | undefined;
syntax?: string | undefined;
};
/** @internal */
export const PathCondition$outboundSchema: z.ZodType<
PathCondition$Outbound,
z.ZodTypeDef,
PathCondition
> = z.object({
value: z.string().optional(),
syntax: z.string().optional(),
});
export function pathConditionToJSON(pathCondition: PathCondition): string {
return JSON.stringify(PathCondition$outboundSchema.parse(pathCondition));
}
/** @internal */
export type GenerateRouteConditions$Outbound = {
field?: string | undefined;
operator?: string | undefined;
key?: string | undefined;
value?: string | undefined;
missing?: boolean | undefined;
};
/** @internal */
export const GenerateRouteConditions$outboundSchema: z.ZodType<
GenerateRouteConditions$Outbound,
z.ZodTypeDef,
GenerateRouteConditions
> = z.object({
field: z.string().optional(),
operator: z.string().optional(),
key: z.string().optional(),
value: z.string().optional(),
missing: z.boolean().optional(),
});
export function generateRouteConditionsToJSON(
generateRouteConditions: GenerateRouteConditions,
): string {
return JSON.stringify(
GenerateRouteConditions$outboundSchema.parse(generateRouteConditions),
);
}
/** @internal */
export type GenerateRouteHeaders$Outbound = {
key?: string | undefined;
value?: string | undefined;
op?: string | undefined;
};
/** @internal */
export const GenerateRouteHeaders$outboundSchema: z.ZodType<
GenerateRouteHeaders$Outbound,
z.ZodTypeDef,
GenerateRouteHeaders
> = z.object({
key: z.string().optional(),
value: z.string().optional(),
op: z.string().optional(),
});
export function generateRouteHeadersToJSON(
generateRouteHeaders: GenerateRouteHeaders,
): string {
return JSON.stringify(
GenerateRouteHeaders$outboundSchema.parse(generateRouteHeaders),
);
}
/** @internal */
export type Actions$Outbound = {
type?: string | undefined;
subType?: string | undefined;
dest?: string | undefined;
status?: number | undefined;
headers?: Array<GenerateRouteHeaders$Outbound> | undefined;
};
/** @internal */
export const Actions$outboundSchema: z.ZodType<
Actions$Outbound,
z.ZodTypeDef,
Actions
> = z.object({
type: z.string().optional(),
subType: z.string().optional(),
dest: z.string().optional(),
status: z.number().int().optional(),
headers: z.array(z.lazy(() => GenerateRouteHeaders$outboundSchema))
.optional(),
});
export function actionsToJSON(actions: Actions): string {
return JSON.stringify(Actions$outboundSchema.parse(actions));
}
/** @internal */
export type CurrentRoute$Outbound = {
name?: string | undefined;
description?: string | undefined;
pathCondition: PathCondition$Outbound;
conditions?: Array<GenerateRouteConditions$Outbound> | undefined;
actions: Array<Actions$Outbound>;
};
/** @internal */
export const CurrentRoute$outboundSchema: z.ZodType<
CurrentRoute$Outbound,
z.ZodTypeDef,
CurrentRoute
> = z.object({
name: z.string().optional(),
description: z.string().optional(),
pathCondition: z.lazy(() => PathCondition$outboundSchema),
conditions: z.array(z.lazy(() => GenerateRouteConditions$outboundSchema))
.optional(),
actions: z.array(z.lazy(() => Actions$outboundSchema)),
});
export function currentRouteToJSON(currentRoute: CurrentRoute): string {
return JSON.stringify(CurrentRoute$outboundSchema.parse(currentRoute));
}
/** @internal */
export type GenerateRouteRequestBody$Outbound = {
prompt: string;
currentRoute?: CurrentRoute$Outbound | undefined;
};
/** @internal */
export const GenerateRouteRequestBody$outboundSchema: z.ZodType<
GenerateRouteRequestBody$Outbound,
z.ZodTypeDef,
GenerateRouteRequestBody
> = z.object({
prompt: z.string(),
currentRoute: z.lazy(() => CurrentRoute$outboundSchema).optional(),
});
export function generateRouteRequestBodyToJSON(
generateRouteRequestBody: GenerateRouteRequestBody,
): string {
return JSON.stringify(
GenerateRouteRequestBody$outboundSchema.parse(generateRouteRequestBody),
);
}
/** @internal */
export type GenerateRouteRequest$Outbound = {
projectId: string;
teamId?: string | undefined;
slug?: string | undefined;
RequestBody?: GenerateRouteRequestBody$Outbound | undefined;
};
/** @internal */
export const GenerateRouteRequest$outboundSchema: z.ZodType<
GenerateRouteRequest$Outbound,
z.ZodTypeDef,
GenerateRouteRequest
> = z.object({
projectId: z.string(),
teamId: z.string().optional(),
slug: z.string().optional(),
requestBody: z.lazy(() => GenerateRouteRequestBody$outboundSchema).optional(),
}).transform((v) => {
return remap$(v, {
requestBody: "RequestBody",
});
});
export function generateRouteRequestToJSON(
generateRouteRequest: GenerateRouteRequest,
): string {
return JSON.stringify(
GenerateRouteRequest$outboundSchema.parse(generateRouteRequest),
);
}
/** @internal */
export const Syntax$inboundSchema: z.ZodNativeEnum<typeof Syntax> = z
.nativeEnum(Syntax);
/** @internal */
export const GenerateRoutePathCondition$inboundSchema: z.ZodType<
GenerateRoutePathCondition,
z.ZodTypeDef,
unknown
> = z.object({
value: types.string(),
syntax: Syntax$inboundSchema,
});
export function generateRoutePathConditionFromJSON(
jsonString: string,
): SafeParseResult<GenerateRoutePathCondition, SDKValidationError> {
return safeParse(
jsonString,
(x) => GenerateRoutePathCondition$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GenerateRoutePathCondition' from JSON`,
);
}
/** @internal */
export const GenerateRouteField$inboundSchema: z.ZodNativeEnum<
typeof GenerateRouteField
> = z.nativeEnum(GenerateRouteField);
/** @internal */
export const Operator$inboundSchema: z.ZodNativeEnum<typeof Operator> = z
.nativeEnum(Operator);
/** @internal */
export const GenerateRouteProjectRoutesConditions$inboundSchema: z.ZodType<
GenerateRouteProjectRoutesConditions,
z.ZodTypeDef,
unknown
> = z.object({
field: GenerateRouteField$inboundSchema,
operator: Operator$inboundSchema,
key: types.optional(types.string()),
value: types.optional(types.string()),
missing: types.boolean(),
});
export function generateRouteProjectRoutesConditionsFromJSON(
jsonString: string,
): SafeParseResult<GenerateRouteProjectRoutesConditions, SDKValidationError> {
return safeParse(
jsonString,
(x) =>
GenerateRouteProjectRoutesConditions$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GenerateRouteProjectRoutesConditions' from JSON`,
);
}
/** @internal */
export const GenerateRouteType$inboundSchema: z.ZodNativeEnum<
typeof GenerateRouteType
> = z.nativeEnum(GenerateRouteType);
/** @internal */
export const SubType$inboundSchema: z.ZodNativeEnum<typeof SubType> = z
.nativeEnum(SubType);
/** @internal */
export const GenerateRouteOp$inboundSchema: z.ZodNativeEnum<
typeof GenerateRouteOp
> = z.nativeEnum(GenerateRouteOp);
/** @internal */
export const GenerateRouteProjectRoutesHeaders$inboundSchema: z.ZodType<
GenerateRouteProjectRoutesHeaders,
z.ZodTypeDef,
unknown
> = z.object({
key: types.string(),
value: types.optional(types.string()),
op: GenerateRouteOp$inboundSchema,
});
export function generateRouteProjectRoutesHeadersFromJSON(
jsonString: string,
): SafeParseResult<GenerateRouteProjectRoutesHeaders, SDKValidationError> {
return safeParse(
jsonString,
(x) => GenerateRouteProjectRoutesHeaders$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GenerateRouteProjectRoutesHeaders' from JSON`,
);
}
/** @internal */
export const GenerateRouteActions$inboundSchema: z.ZodType<
GenerateRouteActions,
z.ZodTypeDef,
unknown
> = z.object({
type: GenerateRouteType$inboundSchema,
subType: types.optional(SubType$inboundSchema),
dest: types.optional(types.string()),
status: types.optional(types.number()),
headers: types.optional(
z.array(z.lazy(() => GenerateRouteProjectRoutesHeaders$inboundSchema)),
),
});
export function generateRouteActionsFromJSON(
jsonString: string,
): SafeParseResult<GenerateRouteActions, SDKValidationError> {
return safeParse(
jsonString,
(x) => GenerateRouteActions$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GenerateRouteActions' from JSON`,
);
}
/** @internal */
export const GenerateRouteRoute$inboundSchema: z.ZodType<
GenerateRouteRoute,
z.ZodTypeDef,
unknown
> = z.object({
name: types.string(),
description: types.string(),
pathCondition: z.lazy(() => GenerateRoutePathCondition$inboundSchema),
conditions: types.optional(
z.array(z.lazy(() => GenerateRouteProjectRoutesConditions$inboundSchema)),
),
actions: z.array(z.lazy(() => GenerateRouteActions$inboundSchema)),
});
export function generateRouteRouteFromJSON(
jsonString: string,
): SafeParseResult<GenerateRouteRoute, SDKValidationError> {
return safeParse(
jsonString,
(x) => GenerateRouteRoute$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GenerateRouteRoute' from JSON`,
);
}
/** @internal */
export const GenerateRouteResponseBody$inboundSchema: z.ZodType<
GenerateRouteResponseBody,
z.ZodTypeDef,
unknown
> = z.object({
route: types.optional(z.lazy(() => GenerateRouteRoute$inboundSchema)),
error: types.optional(types.string()),
});
export function generateRouteResponseBodyFromJSON(
jsonString: string,
): SafeParseResult<GenerateRouteResponseBody, SDKValidationError> {
return safeParse(
jsonString,
(x) => GenerateRouteResponseBody$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GenerateRouteResponseBody' from JSON`,
);
}