@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>
459 lines • 17 kB
JavaScript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
export const FlagType = {
Variant: "variant",
};
export const FlagFallthroughEnvironments3Type = {
Entity: "entity",
};
export const FlagFallthroughEnvironments2Type = {
Entity: "entity",
};
export const FlagOutcomeEnvironmentsRules3Type = {
Entity: "entity",
};
export const FlagOutcomeEnvironmentsRules2Type = {
Entity: "entity",
};
export const FlagRhsType = {
Regex: "regex",
};
export const RhsType = {
List: "list",
ListInline: "list/inline",
};
export const Cmp = {
NotContains: "!contains",
NotEndsWith: "!endsWith",
NotEq: "!eq",
NotEx: "!ex",
NotOneOf: "!oneOf",
NotRegex: "!regex",
NotStartsWith: "!startsWith",
After: "after",
Before: "before",
Contains: "contains",
ContainsAllOf: "containsAllOf",
ContainsAnyOf: "containsAnyOf",
ContainsNoneOf: "containsNoneOf",
EndsWith: "endsWith",
Eq: "eq",
Ex: "ex",
Gt: "gt",
Gte: "gte",
Lt: "lt",
Lte: "lte",
OneOf: "oneOf",
Regex: "regex",
StartsWith: "startsWith",
};
export const Kind = {
Boolean: "boolean",
Json: "json",
Number: "number",
String: "string",
};
export const State = {
Active: "active",
Archived: "archived",
};
export const TypeName = {
Flag: "flag",
};
/** @internal */
export const Variants$inboundSchema = z.object({});
export function variantsFromJSON(jsonString) {
return safeParse(jsonString, (x) => Variants$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Variants' from JSON`);
}
/** @internal */
export const Reuse$inboundSchema = z
.object({
active: types.boolean(),
environment: types.string(),
});
export function reuseFromJSON(jsonString) {
return safeParse(jsonString, (x) => Reuse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Reuse' from JSON`);
}
/** @internal */
export const Targets$inboundSchema = z.object({
note: types.optional(types.string()),
value: types.string(),
});
export function targetsFromJSON(jsonString) {
return safeParse(jsonString, (x) => Targets$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Targets' from JSON`);
}
/** @internal */
export const FlagType$inboundSchema = z
.nativeEnum(FlagType);
/** @internal */
export const PausedOutcome$inboundSchema = z.object({
type: FlagType$inboundSchema,
variantId: types.string(),
});
export function pausedOutcomeFromJSON(jsonString) {
return safeParse(jsonString, (x) => PausedOutcome$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PausedOutcome' from JSON`);
}
/** @internal */
export const Fallthrough4$inboundSchema = z.object({
type: types.literal("experiment"),
});
export function fallthrough4FromJSON(jsonString) {
return safeParse(jsonString, (x) => Fallthrough4$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Fallthrough4' from JSON`);
}
/** @internal */
export const FlagFallthroughEnvironments3Type$inboundSchema = z.nativeEnum(FlagFallthroughEnvironments3Type);
/** @internal */
export const FallthroughBase$inboundSchema = z.object({
type: FlagFallthroughEnvironments3Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function fallthroughBaseFromJSON(jsonString) {
return safeParse(jsonString, (x) => FallthroughBase$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FallthroughBase' from JSON`);
}
/** @internal */
export const Slots$inboundSchema = z
.object({
promille: types.number(),
durationMs: types.number(),
});
export function slotsFromJSON(jsonString) {
return safeParse(jsonString, (x) => Slots$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Slots' from JSON`);
}
/** @internal */
export const Fallthrough3$inboundSchema = z.object({
type: types.literal("rollout"),
base: z.lazy(() => FallthroughBase$inboundSchema),
defaultVariantId: types.string(),
startTimestamp: types.number(),
rollFromVariantId: types.string(),
rollToVariantId: types.string(),
slots: z.array(z.lazy(() => Slots$inboundSchema)),
});
export function fallthrough3FromJSON(jsonString) {
return safeParse(jsonString, (x) => Fallthrough3$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Fallthrough3' from JSON`);
}
/** @internal */
export const FlagFallthroughEnvironments2Type$inboundSchema = z.nativeEnum(FlagFallthroughEnvironments2Type);
/** @internal */
export const Base$inboundSchema = z
.object({
type: FlagFallthroughEnvironments2Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function baseFromJSON(jsonString) {
return safeParse(jsonString, (x) => Base$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Base' from JSON`);
}
/** @internal */
export const Fallthrough2$inboundSchema = z.object({
type: types.literal("split"),
base: z.lazy(() => Base$inboundSchema),
weights: z.record(types.number()),
defaultVariantId: types.string(),
});
export function fallthrough2FromJSON(jsonString) {
return safeParse(jsonString, (x) => Fallthrough2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Fallthrough2' from JSON`);
}
/** @internal */
export const Fallthrough1$inboundSchema = z.object({
type: types.literal("variant"),
variantId: types.string(),
});
export function fallthrough1FromJSON(jsonString) {
return safeParse(jsonString, (x) => Fallthrough1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Fallthrough1' from JSON`);
}
/** @internal */
export const Fallthrough$inboundSchema = z.union([
z.lazy(() => Fallthrough1$inboundSchema),
z.lazy(() => Fallthrough2$inboundSchema),
z.lazy(() => Fallthrough3$inboundSchema),
z.lazy(() => Fallthrough4$inboundSchema),
]);
export function fallthroughFromJSON(jsonString) {
return safeParse(jsonString, (x) => Fallthrough$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Fallthrough' from JSON`);
}
/** @internal */
export const Outcome4$inboundSchema = z.object({
type: types.literal("experiment"),
});
export function outcome4FromJSON(jsonString) {
return safeParse(jsonString, (x) => Outcome4$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Outcome4' from JSON`);
}
/** @internal */
export const FlagOutcomeEnvironmentsRules3Type$inboundSchema = z.nativeEnum(FlagOutcomeEnvironmentsRules3Type);
/** @internal */
export const FlagOutcomeBase$inboundSchema = z.object({
type: FlagOutcomeEnvironmentsRules3Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function flagOutcomeBaseFromJSON(jsonString) {
return safeParse(jsonString, (x) => FlagOutcomeBase$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FlagOutcomeBase' from JSON`);
}
/** @internal */
export const OutcomeSlots$inboundSchema = z.object({
promille: types.number(),
durationMs: types.number(),
});
export function outcomeSlotsFromJSON(jsonString) {
return safeParse(jsonString, (x) => OutcomeSlots$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OutcomeSlots' from JSON`);
}
/** @internal */
export const Outcome3$inboundSchema = z.object({
type: types.literal("rollout"),
base: z.lazy(() => FlagOutcomeBase$inboundSchema),
defaultVariantId: types.string(),
startTimestamp: types.number(),
rollFromVariantId: types.string(),
rollToVariantId: types.string(),
slots: z.array(z.lazy(() => OutcomeSlots$inboundSchema)),
});
export function outcome3FromJSON(jsonString) {
return safeParse(jsonString, (x) => Outcome3$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Outcome3' from JSON`);
}
/** @internal */
export const FlagOutcomeEnvironmentsRules2Type$inboundSchema = z.nativeEnum(FlagOutcomeEnvironmentsRules2Type);
/** @internal */
export const OutcomeBase$inboundSchema = z.object({
type: FlagOutcomeEnvironmentsRules2Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function outcomeBaseFromJSON(jsonString) {
return safeParse(jsonString, (x) => OutcomeBase$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OutcomeBase' from JSON`);
}
/** @internal */
export const Outcome2$inboundSchema = z.object({
type: types.literal("split"),
base: z.lazy(() => OutcomeBase$inboundSchema),
weights: z.record(types.number()),
defaultVariantId: types.string(),
});
export function outcome2FromJSON(jsonString) {
return safeParse(jsonString, (x) => Outcome2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Outcome2' from JSON`);
}
/** @internal */
export const Outcome1$inboundSchema = z.object({
type: types.literal("variant"),
variantId: types.string(),
});
export function outcome1FromJSON(jsonString) {
return safeParse(jsonString, (x) => Outcome1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Outcome1' from JSON`);
}
/** @internal */
export const FlagOutcome$inboundSchema = z.union([
z.lazy(() => Outcome1$inboundSchema),
z.lazy(() => Outcome2$inboundSchema),
z.lazy(() => Outcome3$inboundSchema),
z.lazy(() => Outcome4$inboundSchema),
]);
export function flagOutcomeFromJSON(jsonString) {
return safeParse(jsonString, (x) => FlagOutcome$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FlagOutcome' from JSON`);
}
/** @internal */
export const FlagRhsType$inboundSchema = z
.nativeEnum(FlagRhsType);
/** @internal */
export const Rhs4$inboundSchema = z
.object({
type: FlagRhsType$inboundSchema,
pattern: types.string(),
flags: types.string(),
});
export function rhs4FromJSON(jsonString) {
return safeParse(jsonString, (x) => Rhs4$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Rhs4' from JSON`);
}
/** @internal */
export const RhsType$inboundSchema = z
.nativeEnum(RhsType);
/** @internal */
export const Items2$inboundSchema = z
.object({
label: types.optional(types.string()),
note: types.optional(types.string()),
value: types.string(),
});
export function items2FromJSON(jsonString) {
return safeParse(jsonString, (x) => Items2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Items2' from JSON`);
}
/** @internal */
export const Items1$inboundSchema = z
.object({
label: types.optional(types.string()),
note: types.optional(types.string()),
value: types.number(),
});
export function items1FromJSON(jsonString) {
return safeParse(jsonString, (x) => Items1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Items1' from JSON`);
}
/** @internal */
export const RhsItems$inboundSchema = smartUnion([
z.lazy(() => Items1$inboundSchema),
z.lazy(() => Items2$inboundSchema),
]);
export function rhsItemsFromJSON(jsonString) {
return safeParse(jsonString, (x) => RhsItems$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RhsItems' from JSON`);
}
/** @internal */
export const Rhs3$inboundSchema = z
.object({
type: RhsType$inboundSchema,
items: z.array(smartUnion([
z.lazy(() => Items1$inboundSchema),
z.lazy(() => Items2$inboundSchema),
])),
});
export function rhs3FromJSON(jsonString) {
return safeParse(jsonString, (x) => Rhs3$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Rhs3' from JSON`);
}
/** @internal */
export const Rhs$inboundSchema = smartUnion([
z.lazy(() => Rhs4$inboundSchema),
z.lazy(() => Rhs3$inboundSchema),
types.string(),
types.number(),
types.boolean(),
]);
export function rhsFromJSON(jsonString) {
return safeParse(jsonString, (x) => Rhs$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Rhs' from JSON`);
}
/** @internal */
export const CmpOptions$inboundSchema = z.object({
ignoreCase: types.optional(types.boolean()),
});
export function cmpOptionsFromJSON(jsonString) {
return safeParse(jsonString, (x) => CmpOptions$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CmpOptions' from JSON`);
}
/** @internal */
export const Lhs2$inboundSchema = z
.object({
type: types.literal("entity"),
kind: types.string(),
attribute: types.string(),
});
export function lhs2FromJSON(jsonString) {
return safeParse(jsonString, (x) => Lhs2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Lhs2' from JSON`);
}
/** @internal */
export const Lhs1$inboundSchema = z
.object({
type: types.literal("segment"),
});
export function lhs1FromJSON(jsonString) {
return safeParse(jsonString, (x) => Lhs1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Lhs1' from JSON`);
}
/** @internal */
export const Lhs$inboundSchema = z.union([z.lazy(() => Lhs1$inboundSchema), z.lazy(() => Lhs2$inboundSchema)]);
export function lhsFromJSON(jsonString) {
return safeParse(jsonString, (x) => Lhs$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Lhs' from JSON`);
}
/** @internal */
export const Cmp$inboundSchema = z.nativeEnum(Cmp);
/** @internal */
export const Conditions$inboundSchema = z.object({
rhs: types.optional(smartUnion([
z.lazy(() => Rhs4$inboundSchema),
z.lazy(() => Rhs3$inboundSchema),
types.string(),
types.number(),
types.boolean(),
])),
cmpOptions: types.optional(z.lazy(() => CmpOptions$inboundSchema)),
lhs: z.union([
z.lazy(() => Lhs1$inboundSchema),
z.lazy(() => Lhs2$inboundSchema),
]),
cmp: Cmp$inboundSchema,
});
export function conditionsFromJSON(jsonString) {
return safeParse(jsonString, (x) => Conditions$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Conditions' from JSON`);
}
/** @internal */
export const Rules$inboundSchema = z
.object({
id: types.string(),
outcome: z.union([
z.lazy(() => Outcome1$inboundSchema),
z.lazy(() => Outcome2$inboundSchema),
z.lazy(() => Outcome3$inboundSchema),
z.lazy(() => Outcome4$inboundSchema),
]),
conditions: z.array(z.lazy(() => Conditions$inboundSchema)),
});
export function rulesFromJSON(jsonString) {
return safeParse(jsonString, (x) => Rules$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Rules' from JSON`);
}
/** @internal */
export const FlagEnvironments$inboundSchema = z.object({
reuse: types.optional(z.lazy(() => Reuse$inboundSchema)),
targets: types.optional(z.record(z.record(z.record(z.array(z.lazy(() => Targets$inboundSchema)))))),
revision: types.optional(types.number()),
pausedOutcome: z.lazy(() => PausedOutcome$inboundSchema),
fallthrough: z.union([
z.lazy(() => Fallthrough1$inboundSchema),
z.lazy(() => Fallthrough2$inboundSchema),
z.lazy(() => Fallthrough3$inboundSchema),
z.lazy(() => Fallthrough4$inboundSchema),
]),
active: types.boolean(),
rules: z.array(z.lazy(() => Rules$inboundSchema)),
});
export function flagEnvironmentsFromJSON(jsonString) {
return safeParse(jsonString, (x) => FlagEnvironments$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'FlagEnvironments' from JSON`);
}
/** @internal */
export const Kind$inboundSchema = z.nativeEnum(Kind);
/** @internal */
export const State$inboundSchema = z.nativeEnum(State);
/** @internal */
export const TypeName$inboundSchema = z
.nativeEnum(TypeName);
/** @internal */
export const Creator$inboundSchema = z.object({
id: types.string(),
name: types.string(),
});
export function creatorFromJSON(jsonString) {
return safeParse(jsonString, (x) => Creator$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Creator' from JSON`);
}
/** @internal */
export const Metadata$inboundSchema = z.object({
creator: types.optional(z.lazy(() => Creator$inboundSchema)),
});
export function metadataFromJSON(jsonString) {
return safeParse(jsonString, (x) => Metadata$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Metadata' from JSON`);
}
/** @internal */
export const Flag$inboundSchema = z
.object({
description: types.optional(types.string()),
variants: z.array(z.lazy(() => Variants$inboundSchema)),
id: types.string(),
environments: z.record(z.lazy(() => FlagEnvironments$inboundSchema)),
kind: Kind$inboundSchema,
revision: types.number(),
seed: types.number(),
state: State$inboundSchema,
maintainerIds: types.optional(z.array(types.string())),
permanent: types.optional(types.boolean()),
tags: types.optional(z.array(types.string())),
slug: types.string(),
createdAt: types.number(),
updatedAt: types.number(),
updatedBy: types.optional(types.string()),
createdBy: types.string(),
ownerId: types.string(),
projectId: types.string(),
typeName: TypeName$inboundSchema,
metadata: types.optional(z.lazy(() => Metadata$inboundSchema)),
});
export function flagFromJSON(jsonString) {
return safeParse(jsonString, (x) => Flag$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Flag' from JSON`);
}
//# sourceMappingURL=flag.js.map