@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>
471 lines (428 loc) • 13.3 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 { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
export const QueryParam2 = {
Only: "only",
} as const;
export type QueryParam2 = ClosedEnum<typeof QueryParam2>;
export type Diff = boolean | QueryParam2;
export const SortBy = {
Source: "source",
Destination: "destination",
StatusCode: "statusCode",
} as const;
export type SortBy = ClosedEnum<typeof SortBy>;
export const SortOrder = {
Asc: "asc",
Desc: "desc",
} as const;
export type SortOrder = ClosedEnum<typeof SortOrder>;
export type GetRedirectsRequest = {
projectId: string;
versionId?: string | undefined;
q?: string | undefined;
diff?: boolean | QueryParam2 | undefined;
page?: number | undefined;
perPage?: number | undefined;
sortBy?: SortBy | undefined;
sortOrder?: SortOrder | undefined;
/**
* 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;
};
export type GetRedirectsResponseBodyRedirects = {
statusCode?: number | undefined;
permanent?: boolean | undefined;
sensitive?: boolean | undefined;
caseSensitive?: boolean | undefined;
query?: boolean | undefined;
preserveQueryParams?: boolean | undefined;
destination: string;
source: string;
};
export type GetRedirectsResponseBodyVersion = {
/**
* The unique identifier for the version.
*/
id: string;
/**
* The key of the version. The key may be duplicated across versions if the contents are the same as a different version.
*/
key: string;
lastModified: number;
createdBy: string;
/**
* Optional name for the version. If not provided, defaults to an ISO timestamp string.
*/
name?: string | undefined;
/**
* Whether this version has not been promoted to production yet and is not serving end users.
*/
isStaging?: boolean | undefined;
/**
* Whether this version is currently live in production.
*/
isLive?: boolean | undefined;
/**
* The number of redirects in this version.
*/
redirectCount?: number | undefined;
/**
* The staging link for previewing redirects in this version.
*/
alias?: string | undefined;
};
export type GetRedirectsResponseBodyBulkRedirectsPagination = {
page: number;
perPage: number;
numPages: number;
};
export type ResponseBody3 = {
redirects: Array<GetRedirectsResponseBodyRedirects>;
version?: GetRedirectsResponseBodyVersion | undefined;
pagination: GetRedirectsResponseBodyBulkRedirectsPagination;
};
export type ResponseBodyVersion = {
/**
* The unique identifier for the version.
*/
id: string;
/**
* The key of the version. The key may be duplicated across versions if the contents are the same as a different version.
*/
key: string;
lastModified: number;
createdBy: string;
/**
* Optional name for the version. If not provided, defaults to an ISO timestamp string.
*/
name?: string | undefined;
/**
* Whether this version has not been promoted to production yet and is not serving end users.
*/
isStaging?: boolean | undefined;
/**
* Whether this version is currently live in production.
*/
isLive?: boolean | undefined;
/**
* The number of redirects in this version.
*/
redirectCount?: number | undefined;
/**
* The staging link for previewing redirects in this version.
*/
alias?: string | undefined;
};
export type ResponseBodyRedirects = {
statusCode?: number | undefined;
permanent?: boolean | undefined;
sensitive?: boolean | undefined;
caseSensitive?: boolean | undefined;
query?: boolean | undefined;
preserveQueryParams?: boolean | undefined;
destination: string;
source: string;
};
export type GetRedirectsResponseBodyPagination = {
page: number;
perPage: number;
numPages: number;
};
export type GetRedirectsResponseBody2 = {
version: ResponseBodyVersion;
redirects: Array<ResponseBodyRedirects>;
pagination: GetRedirectsResponseBodyPagination;
};
export type GetRedirectsResponseBody =
| GetRedirectsResponseBody2
| ResponseBody3
| { [k: string]: any };
/** @internal */
export const QueryParam2$outboundSchema: z.ZodNativeEnum<typeof QueryParam2> = z
.nativeEnum(QueryParam2);
/** @internal */
export type Diff$Outbound = boolean | string;
/** @internal */
export const Diff$outboundSchema: z.ZodType<Diff$Outbound, z.ZodTypeDef, Diff> =
smartUnion([z.boolean(), QueryParam2$outboundSchema]);
export function diffToJSON(diff: Diff): string {
return JSON.stringify(Diff$outboundSchema.parse(diff));
}
/** @internal */
export const SortBy$outboundSchema: z.ZodNativeEnum<typeof SortBy> = z
.nativeEnum(SortBy);
/** @internal */
export const SortOrder$outboundSchema: z.ZodNativeEnum<typeof SortOrder> = z
.nativeEnum(SortOrder);
/** @internal */
export type GetRedirectsRequest$Outbound = {
projectId: string;
versionId?: string | undefined;
q?: string | undefined;
diff?: boolean | string | undefined;
page?: number | undefined;
per_page?: number | undefined;
sort_by?: string | undefined;
sort_order?: string | undefined;
teamId?: string | undefined;
slug?: string | undefined;
};
/** @internal */
export const GetRedirectsRequest$outboundSchema: z.ZodType<
GetRedirectsRequest$Outbound,
z.ZodTypeDef,
GetRedirectsRequest
> = z.object({
projectId: z.string(),
versionId: z.string().optional(),
q: z.string().optional(),
diff: smartUnion([z.boolean(), QueryParam2$outboundSchema]).optional(),
page: z.number().int().optional(),
perPage: z.number().int().optional(),
sortBy: SortBy$outboundSchema.optional(),
sortOrder: SortOrder$outboundSchema.optional(),
teamId: z.string().optional(),
slug: z.string().optional(),
}).transform((v) => {
return remap$(v, {
perPage: "per_page",
sortBy: "sort_by",
sortOrder: "sort_order",
});
});
export function getRedirectsRequestToJSON(
getRedirectsRequest: GetRedirectsRequest,
): string {
return JSON.stringify(
GetRedirectsRequest$outboundSchema.parse(getRedirectsRequest),
);
}
/** @internal */
export const GetRedirectsResponseBodyRedirects$inboundSchema: z.ZodType<
GetRedirectsResponseBodyRedirects,
z.ZodTypeDef,
unknown
> = z.object({
statusCode: types.optional(types.number()),
permanent: types.optional(types.boolean()),
sensitive: types.optional(types.boolean()),
caseSensitive: types.optional(types.boolean()),
query: types.optional(types.boolean()),
preserveQueryParams: types.optional(types.boolean()),
destination: types.string(),
source: types.string(),
});
export function getRedirectsResponseBodyRedirectsFromJSON(
jsonString: string,
): SafeParseResult<GetRedirectsResponseBodyRedirects, SDKValidationError> {
return safeParse(
jsonString,
(x) => GetRedirectsResponseBodyRedirects$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetRedirectsResponseBodyRedirects' from JSON`,
);
}
/** @internal */
export const GetRedirectsResponseBodyVersion$inboundSchema: z.ZodType<
GetRedirectsResponseBodyVersion,
z.ZodTypeDef,
unknown
> = z.object({
id: types.string(),
key: types.string(),
lastModified: types.number(),
createdBy: types.string(),
name: types.optional(types.string()),
isStaging: types.optional(types.boolean()),
isLive: types.optional(types.boolean()),
redirectCount: types.optional(types.number()),
alias: types.optional(types.string()),
});
export function getRedirectsResponseBodyVersionFromJSON(
jsonString: string,
): SafeParseResult<GetRedirectsResponseBodyVersion, SDKValidationError> {
return safeParse(
jsonString,
(x) => GetRedirectsResponseBodyVersion$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetRedirectsResponseBodyVersion' from JSON`,
);
}
/** @internal */
export const GetRedirectsResponseBodyBulkRedirectsPagination$inboundSchema:
z.ZodType<
GetRedirectsResponseBodyBulkRedirectsPagination,
z.ZodTypeDef,
unknown
> = z.object({
page: types.number(),
per_page: types.number(),
numPages: types.number(),
}).transform((v) => {
return remap$(v, {
"per_page": "perPage",
});
});
export function getRedirectsResponseBodyBulkRedirectsPaginationFromJSON(
jsonString: string,
): SafeParseResult<
GetRedirectsResponseBodyBulkRedirectsPagination,
SDKValidationError
> {
return safeParse(
jsonString,
(x) =>
GetRedirectsResponseBodyBulkRedirectsPagination$inboundSchema.parse(
JSON.parse(x),
),
`Failed to parse 'GetRedirectsResponseBodyBulkRedirectsPagination' from JSON`,
);
}
/** @internal */
export const ResponseBody3$inboundSchema: z.ZodType<
ResponseBody3,
z.ZodTypeDef,
unknown
> = z.object({
redirects: z.array(
z.lazy(() => GetRedirectsResponseBodyRedirects$inboundSchema),
),
version: types.optional(
z.lazy(() => GetRedirectsResponseBodyVersion$inboundSchema),
),
pagination: z.lazy(() =>
GetRedirectsResponseBodyBulkRedirectsPagination$inboundSchema
),
});
export function responseBody3FromJSON(
jsonString: string,
): SafeParseResult<ResponseBody3, SDKValidationError> {
return safeParse(
jsonString,
(x) => ResponseBody3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ResponseBody3' from JSON`,
);
}
/** @internal */
export const ResponseBodyVersion$inboundSchema: z.ZodType<
ResponseBodyVersion,
z.ZodTypeDef,
unknown
> = z.object({
id: types.string(),
key: types.string(),
lastModified: types.number(),
createdBy: types.string(),
name: types.optional(types.string()),
isStaging: types.optional(types.boolean()),
isLive: types.optional(types.boolean()),
redirectCount: types.optional(types.number()),
alias: types.optional(types.string()),
});
export function responseBodyVersionFromJSON(
jsonString: string,
): SafeParseResult<ResponseBodyVersion, SDKValidationError> {
return safeParse(
jsonString,
(x) => ResponseBodyVersion$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ResponseBodyVersion' from JSON`,
);
}
/** @internal */
export const ResponseBodyRedirects$inboundSchema: z.ZodType<
ResponseBodyRedirects,
z.ZodTypeDef,
unknown
> = z.object({
statusCode: types.optional(types.number()),
permanent: types.optional(types.boolean()),
sensitive: types.optional(types.boolean()),
caseSensitive: types.optional(types.boolean()),
query: types.optional(types.boolean()),
preserveQueryParams: types.optional(types.boolean()),
destination: types.string(),
source: types.string(),
});
export function responseBodyRedirectsFromJSON(
jsonString: string,
): SafeParseResult<ResponseBodyRedirects, SDKValidationError> {
return safeParse(
jsonString,
(x) => ResponseBodyRedirects$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ResponseBodyRedirects' from JSON`,
);
}
/** @internal */
export const GetRedirectsResponseBodyPagination$inboundSchema: z.ZodType<
GetRedirectsResponseBodyPagination,
z.ZodTypeDef,
unknown
> = z.object({
page: types.number(),
per_page: types.number(),
numPages: types.number(),
}).transform((v) => {
return remap$(v, {
"per_page": "perPage",
});
});
export function getRedirectsResponseBodyPaginationFromJSON(
jsonString: string,
): SafeParseResult<GetRedirectsResponseBodyPagination, SDKValidationError> {
return safeParse(
jsonString,
(x) =>
GetRedirectsResponseBodyPagination$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetRedirectsResponseBodyPagination' from JSON`,
);
}
/** @internal */
export const GetRedirectsResponseBody2$inboundSchema: z.ZodType<
GetRedirectsResponseBody2,
z.ZodTypeDef,
unknown
> = z.object({
version: z.lazy(() => ResponseBodyVersion$inboundSchema),
redirects: z.array(z.lazy(() => ResponseBodyRedirects$inboundSchema)),
pagination: z.lazy(() => GetRedirectsResponseBodyPagination$inboundSchema),
});
export function getRedirectsResponseBody2FromJSON(
jsonString: string,
): SafeParseResult<GetRedirectsResponseBody2, SDKValidationError> {
return safeParse(
jsonString,
(x) => GetRedirectsResponseBody2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetRedirectsResponseBody2' from JSON`,
);
}
/** @internal */
export const GetRedirectsResponseBody$inboundSchema: z.ZodType<
GetRedirectsResponseBody,
z.ZodTypeDef,
unknown
> = smartUnion([
z.lazy(() => GetRedirectsResponseBody2$inboundSchema),
z.lazy(() => ResponseBody3$inboundSchema),
z.record(z.any()),
]);
export function getRedirectsResponseBodyFromJSON(
jsonString: string,
): SafeParseResult<GetRedirectsResponseBody, SDKValidationError> {
return safeParse(
jsonString,
(x) => GetRedirectsResponseBody$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GetRedirectsResponseBody' from JSON`,
);
}