@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>
1,296 lines (1,141 loc) • 32.5 kB
text/typescript
/*
* 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 { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
export const MetricType = {
Count: "count",
Currency: "currency",
Percentage: "percentage",
} as const;
export type MetricType = ClosedEnum<typeof MetricType>;
export const MetricUnit = {
Session: "session",
User: "user",
Visitor: "visitor",
} as const;
export type MetricUnit = ClosedEnum<typeof MetricUnit>;
export const Directionality = {
DecreaseIsGood: "decreaseIsGood",
IncreaseIsGood: "increaseIsGood",
} as const;
export type Directionality = ClosedEnum<typeof Directionality>;
export type GuardrailMetrics = {
description?: string | undefined;
metricFormula?: string | undefined;
name: string;
metricType: MetricType;
metricUnit: MetricUnit;
directionality: Directionality;
};
export const Device = {
Android: "android",
Desktop: "desktop",
Ios: "ios",
Mweb: "mweb",
} as const;
export type Device = ClosedEnum<typeof Device>;
export const DurationUnit = {
Days: "days",
Exposures: "exposures",
} as const;
export type DurationUnit = ClosedEnum<typeof DurationUnit>;
export const AllocationUnit = {
CookieId: "cookieId",
UserId: "userId",
VisitorId: "visitorId",
} as const;
export type AllocationUnit = ClosedEnum<typeof AllocationUnit>;
export const FlagMetricType = {
Count: "count",
Currency: "currency",
Percentage: "percentage",
} as const;
export type FlagMetricType = ClosedEnum<typeof FlagMetricType>;
export const FlagMetricUnit = {
Session: "session",
User: "user",
Visitor: "visitor",
} as const;
export type FlagMetricUnit = ClosedEnum<typeof FlagMetricUnit>;
export const FlagDirectionality = {
DecreaseIsGood: "decreaseIsGood",
IncreaseIsGood: "increaseIsGood",
} as const;
export type FlagDirectionality = ClosedEnum<typeof FlagDirectionality>;
export type PrimaryMetrics = {
description?: string | undefined;
metricFormula?: string | undefined;
name: string;
metricType: FlagMetricType;
metricUnit: FlagMetricUnit;
directionality: FlagDirectionality;
};
export const FlagStatus = {
Closed: "closed",
Draft: "draft",
Paused: "paused",
Running: "running",
} as const;
export type FlagStatus = ClosedEnum<typeof FlagStatus>;
export type Experiment = {
id?: string | undefined;
name?: string | undefined;
numVariants?: number | undefined;
surfaceArea?: string | undefined;
stickyRequirement?: boolean | undefined;
layer?: string | undefined;
guardrailMetrics?: Array<GuardrailMetrics> | undefined;
hypothesis?: string | undefined;
device?: Device | undefined;
controlVariantId?: string | undefined;
startedAt?: number | undefined;
endedAt?: number | undefined;
decision?: string | undefined;
decisionReason?: string | undefined;
duration?: number | undefined;
durationUnit?: DurationUnit | undefined;
allocationPercent?: number | undefined;
allocationUnit: AllocationUnit;
primaryMetrics: Array<PrimaryMetrics>;
status: FlagStatus;
};
export type Variants = {};
export type Reuse = {
active: boolean;
environment: string;
};
export type Targets = {
note?: string | undefined;
value: string;
};
export const FlagType = {
Variant: "variant",
} as const;
export type FlagType = ClosedEnum<typeof FlagType>;
export type PausedOutcome = {
type: FlagType;
variantId: string;
};
export const FlagFallthroughEnvironments3Type = {
Entity: "entity",
} as const;
export type FlagFallthroughEnvironments3Type = ClosedEnum<
typeof FlagFallthroughEnvironments3Type
>;
export type FallthroughBase = {
type: FlagFallthroughEnvironments3Type;
kind: string;
attribute: string;
};
export type Slots = {
promille: number;
durationMs: number;
};
export type Fallthrough3 = {
type: "rollout";
base: FallthroughBase;
defaultVariantId: string;
startTimestamp: number;
rollFromVariantId: string;
rollToVariantId: string;
slots: Array<Slots>;
};
export const FlagFallthroughEnvironments2Type = {
Entity: "entity",
} as const;
export type FlagFallthroughEnvironments2Type = ClosedEnum<
typeof FlagFallthroughEnvironments2Type
>;
export type Base = {
type: FlagFallthroughEnvironments2Type;
kind: string;
attribute: string;
};
export type Fallthrough2 = {
type: "split";
base: Base;
weights: { [k: string]: number };
defaultVariantId: string;
};
export type Fallthrough1 = {
type: "variant";
variantId: string;
};
export type Fallthrough = Fallthrough1 | Fallthrough2 | Fallthrough3;
export const FlagOutcomeEnvironmentsRules3Type = {
Entity: "entity",
} as const;
export type FlagOutcomeEnvironmentsRules3Type = ClosedEnum<
typeof FlagOutcomeEnvironmentsRules3Type
>;
export type FlagOutcomeBase = {
type: FlagOutcomeEnvironmentsRules3Type;
kind: string;
attribute: string;
};
export type OutcomeSlots = {
promille: number;
durationMs: number;
};
export type Outcome3 = {
type: "rollout";
base: FlagOutcomeBase;
defaultVariantId: string;
startTimestamp: number;
rollFromVariantId: string;
rollToVariantId: string;
slots: Array<OutcomeSlots>;
};
export const FlagOutcomeEnvironmentsRulesType = {
Entity: "entity",
} as const;
export type FlagOutcomeEnvironmentsRulesType = ClosedEnum<
typeof FlagOutcomeEnvironmentsRulesType
>;
export type OutcomeBase = {
type: FlagOutcomeEnvironmentsRulesType;
kind: string;
attribute: string;
};
export type Outcome2 = {
type: "split";
base: OutcomeBase;
weights: { [k: string]: number };
defaultVariantId: string;
};
export type Outcome1 = {
type: "variant";
variantId: string;
};
export type Outcome = Outcome1 | Outcome2 | Outcome3;
export const FlagRhsType = {
Regex: "regex",
} as const;
export type FlagRhsType = ClosedEnum<typeof FlagRhsType>;
export type Rhs4 = {
type: FlagRhsType;
pattern: string;
flags: string;
};
export const RhsType = {
List: "list",
ListInline: "list/inline",
} as const;
export type RhsType = ClosedEnum<typeof RhsType>;
export type Items2 = {
label?: string | undefined;
note?: string | undefined;
value: string;
};
export type Items1 = {
label?: string | undefined;
note?: string | undefined;
value: number;
};
export type RhsItems = Items1 | Items2;
export type Rhs3 = {
type: RhsType;
items: Array<Items1 | Items2>;
};
export type Rhs = Rhs4 | Rhs3 | string | number | boolean;
export type CmpOptions = {
ignoreCase?: boolean | undefined;
};
export type Lhs2 = {
type: "entity";
kind: string;
attribute: string;
};
export type Lhs1 = {
type: "segment";
};
export type Lhs = Lhs1 | Lhs2;
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",
} as const;
export type Cmp = ClosedEnum<typeof Cmp>;
export type Conditions = {
rhs?: Rhs4 | Rhs3 | string | number | boolean | undefined;
cmpOptions?: CmpOptions | undefined;
lhs: Lhs1 | Lhs2;
cmp: Cmp;
};
export type Rules = {
id: string;
outcome: Outcome1 | Outcome2 | Outcome3;
conditions: Array<Conditions>;
};
export type Environments = {
reuse?: Reuse | undefined;
targets?:
| { [k: string]: { [k: string]: { [k: string]: Array<Targets> } } }
| undefined;
revision?: number | undefined;
pausedOutcome: PausedOutcome;
fallthrough: Fallthrough1 | Fallthrough2 | Fallthrough3;
active: boolean;
rules: Array<Rules>;
};
export const Kind = {
Boolean: "boolean",
Json: "json",
Number: "number",
String: "string",
} as const;
export type Kind = ClosedEnum<typeof Kind>;
export const State = {
Active: "active",
Archived: "archived",
} as const;
export type State = ClosedEnum<typeof State>;
export const TypeName = {
Flag: "flag",
} as const;
export type TypeName = ClosedEnum<typeof TypeName>;
export type Creator = {
id: string;
name: string;
};
export type Metadata = {
creator?: Creator | undefined;
};
export type Flag = {
description?: string | undefined;
maintainerIds?: Array<string> | undefined;
permanent?: boolean | undefined;
tags?: Array<string> | undefined;
experiment?: Experiment | undefined;
variants: Array<Variants>;
id: string;
environments: { [k: string]: Environments };
kind: Kind;
revision: number;
seed: number;
state: State;
slug: string;
createdAt: number;
updatedAt: number;
createdBy: string;
ownerId: string;
projectId: string;
typeName: TypeName;
metadata?: Metadata | undefined;
};
/** @internal */
export const MetricType$inboundSchema: z.ZodNativeEnum<typeof MetricType> = z
.nativeEnum(MetricType);
/** @internal */
export const MetricUnit$inboundSchema: z.ZodNativeEnum<typeof MetricUnit> = z
.nativeEnum(MetricUnit);
/** @internal */
export const Directionality$inboundSchema: z.ZodNativeEnum<
typeof Directionality
> = z.nativeEnum(Directionality);
/** @internal */
export const GuardrailMetrics$inboundSchema: z.ZodType<
GuardrailMetrics,
z.ZodTypeDef,
unknown
> = z.object({
description: types.optional(types.string()),
metricFormula: types.optional(types.string()),
name: types.string(),
metricType: MetricType$inboundSchema,
metricUnit: MetricUnit$inboundSchema,
directionality: Directionality$inboundSchema,
});
export function guardrailMetricsFromJSON(
jsonString: string,
): SafeParseResult<GuardrailMetrics, SDKValidationError> {
return safeParse(
jsonString,
(x) => GuardrailMetrics$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'GuardrailMetrics' from JSON`,
);
}
/** @internal */
export const Device$inboundSchema: z.ZodNativeEnum<typeof Device> = z
.nativeEnum(Device);
/** @internal */
export const DurationUnit$inboundSchema: z.ZodNativeEnum<typeof DurationUnit> =
z.nativeEnum(DurationUnit);
/** @internal */
export const AllocationUnit$inboundSchema: z.ZodNativeEnum<
typeof AllocationUnit
> = z.nativeEnum(AllocationUnit);
/** @internal */
export const FlagMetricType$inboundSchema: z.ZodNativeEnum<
typeof FlagMetricType
> = z.nativeEnum(FlagMetricType);
/** @internal */
export const FlagMetricUnit$inboundSchema: z.ZodNativeEnum<
typeof FlagMetricUnit
> = z.nativeEnum(FlagMetricUnit);
/** @internal */
export const FlagDirectionality$inboundSchema: z.ZodNativeEnum<
typeof FlagDirectionality
> = z.nativeEnum(FlagDirectionality);
/** @internal */
export const PrimaryMetrics$inboundSchema: z.ZodType<
PrimaryMetrics,
z.ZodTypeDef,
unknown
> = z.object({
description: types.optional(types.string()),
metricFormula: types.optional(types.string()),
name: types.string(),
metricType: FlagMetricType$inboundSchema,
metricUnit: FlagMetricUnit$inboundSchema,
directionality: FlagDirectionality$inboundSchema,
});
export function primaryMetricsFromJSON(
jsonString: string,
): SafeParseResult<PrimaryMetrics, SDKValidationError> {
return safeParse(
jsonString,
(x) => PrimaryMetrics$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'PrimaryMetrics' from JSON`,
);
}
/** @internal */
export const FlagStatus$inboundSchema: z.ZodNativeEnum<typeof FlagStatus> = z
.nativeEnum(FlagStatus);
/** @internal */
export const Experiment$inboundSchema: z.ZodType<
Experiment,
z.ZodTypeDef,
unknown
> = z.object({
id: types.optional(types.string()),
name: types.optional(types.string()),
numVariants: types.optional(types.number()),
surfaceArea: types.optional(types.string()),
stickyRequirement: types.optional(types.boolean()),
layer: types.optional(types.string()),
guardrailMetrics: types.optional(
z.array(z.lazy(() => GuardrailMetrics$inboundSchema)),
),
hypothesis: types.optional(types.string()),
device: types.optional(Device$inboundSchema),
controlVariantId: types.optional(types.string()),
startedAt: types.optional(types.number()),
endedAt: types.optional(types.number()),
decision: types.optional(types.string()),
decisionReason: types.optional(types.string()),
duration: types.optional(types.number()),
durationUnit: types.optional(DurationUnit$inboundSchema),
allocationPercent: types.optional(types.number()),
allocationUnit: AllocationUnit$inboundSchema,
primaryMetrics: z.array(z.lazy(() => PrimaryMetrics$inboundSchema)),
status: FlagStatus$inboundSchema,
});
export function experimentFromJSON(
jsonString: string,
): SafeParseResult<Experiment, SDKValidationError> {
return safeParse(
jsonString,
(x) => Experiment$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Experiment' from JSON`,
);
}
/** @internal */
export const Variants$inboundSchema: z.ZodType<
Variants,
z.ZodTypeDef,
unknown
> = z.object({});
export function variantsFromJSON(
jsonString: string,
): SafeParseResult<Variants, SDKValidationError> {
return safeParse(
jsonString,
(x) => Variants$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Variants' from JSON`,
);
}
/** @internal */
export const Reuse$inboundSchema: z.ZodType<Reuse, z.ZodTypeDef, unknown> = z
.object({
active: types.boolean(),
environment: types.string(),
});
export function reuseFromJSON(
jsonString: string,
): SafeParseResult<Reuse, SDKValidationError> {
return safeParse(
jsonString,
(x) => Reuse$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Reuse' from JSON`,
);
}
/** @internal */
export const Targets$inboundSchema: z.ZodType<Targets, z.ZodTypeDef, unknown> =
z.object({
note: types.optional(types.string()),
value: types.string(),
});
export function targetsFromJSON(
jsonString: string,
): SafeParseResult<Targets, SDKValidationError> {
return safeParse(
jsonString,
(x) => Targets$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Targets' from JSON`,
);
}
/** @internal */
export const FlagType$inboundSchema: z.ZodNativeEnum<typeof FlagType> = z
.nativeEnum(FlagType);
/** @internal */
export const PausedOutcome$inboundSchema: z.ZodType<
PausedOutcome,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagType$inboundSchema,
variantId: types.string(),
});
export function pausedOutcomeFromJSON(
jsonString: string,
): SafeParseResult<PausedOutcome, SDKValidationError> {
return safeParse(
jsonString,
(x) => PausedOutcome$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'PausedOutcome' from JSON`,
);
}
/** @internal */
export const FlagFallthroughEnvironments3Type$inboundSchema: z.ZodNativeEnum<
typeof FlagFallthroughEnvironments3Type
> = z.nativeEnum(FlagFallthroughEnvironments3Type);
/** @internal */
export const FallthroughBase$inboundSchema: z.ZodType<
FallthroughBase,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagFallthroughEnvironments3Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function fallthroughBaseFromJSON(
jsonString: string,
): SafeParseResult<FallthroughBase, SDKValidationError> {
return safeParse(
jsonString,
(x) => FallthroughBase$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FallthroughBase' from JSON`,
);
}
/** @internal */
export const Slots$inboundSchema: z.ZodType<Slots, z.ZodTypeDef, unknown> = z
.object({
promille: types.number(),
durationMs: types.number(),
});
export function slotsFromJSON(
jsonString: string,
): SafeParseResult<Slots, SDKValidationError> {
return safeParse(
jsonString,
(x) => Slots$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Slots' from JSON`,
);
}
/** @internal */
export const Fallthrough3$inboundSchema: z.ZodType<
Fallthrough3,
z.ZodTypeDef,
unknown
> = 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: string,
): SafeParseResult<Fallthrough3, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough3' from JSON`,
);
}
/** @internal */
export const FlagFallthroughEnvironments2Type$inboundSchema: z.ZodNativeEnum<
typeof FlagFallthroughEnvironments2Type
> = z.nativeEnum(FlagFallthroughEnvironments2Type);
/** @internal */
export const Base$inboundSchema: z.ZodType<Base, z.ZodTypeDef, unknown> = z
.object({
type: FlagFallthroughEnvironments2Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function baseFromJSON(
jsonString: string,
): SafeParseResult<Base, SDKValidationError> {
return safeParse(
jsonString,
(x) => Base$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Base' from JSON`,
);
}
/** @internal */
export const Fallthrough2$inboundSchema: z.ZodType<
Fallthrough2,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("split"),
base: z.lazy(() => Base$inboundSchema),
weights: z.record(types.number()),
defaultVariantId: types.string(),
});
export function fallthrough2FromJSON(
jsonString: string,
): SafeParseResult<Fallthrough2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough2' from JSON`,
);
}
/** @internal */
export const Fallthrough1$inboundSchema: z.ZodType<
Fallthrough1,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("variant"),
variantId: types.string(),
});
export function fallthrough1FromJSON(
jsonString: string,
): SafeParseResult<Fallthrough1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough1' from JSON`,
);
}
/** @internal */
export const Fallthrough$inboundSchema: z.ZodType<
Fallthrough,
z.ZodTypeDef,
unknown
> = z.union([
z.lazy(() => Fallthrough1$inboundSchema),
z.lazy(() => Fallthrough2$inboundSchema),
z.lazy(() => Fallthrough3$inboundSchema),
]);
export function fallthroughFromJSON(
jsonString: string,
): SafeParseResult<Fallthrough, SDKValidationError> {
return safeParse(
jsonString,
(x) => Fallthrough$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Fallthrough' from JSON`,
);
}
/** @internal */
export const FlagOutcomeEnvironmentsRules3Type$inboundSchema: z.ZodNativeEnum<
typeof FlagOutcomeEnvironmentsRules3Type
> = z.nativeEnum(FlagOutcomeEnvironmentsRules3Type);
/** @internal */
export const FlagOutcomeBase$inboundSchema: z.ZodType<
FlagOutcomeBase,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagOutcomeEnvironmentsRules3Type$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function flagOutcomeBaseFromJSON(
jsonString: string,
): SafeParseResult<FlagOutcomeBase, SDKValidationError> {
return safeParse(
jsonString,
(x) => FlagOutcomeBase$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FlagOutcomeBase' from JSON`,
);
}
/** @internal */
export const OutcomeSlots$inboundSchema: z.ZodType<
OutcomeSlots,
z.ZodTypeDef,
unknown
> = z.object({
promille: types.number(),
durationMs: types.number(),
});
export function outcomeSlotsFromJSON(
jsonString: string,
): SafeParseResult<OutcomeSlots, SDKValidationError> {
return safeParse(
jsonString,
(x) => OutcomeSlots$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'OutcomeSlots' from JSON`,
);
}
/** @internal */
export const Outcome3$inboundSchema: z.ZodType<
Outcome3,
z.ZodTypeDef,
unknown
> = 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: string,
): SafeParseResult<Outcome3, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome3' from JSON`,
);
}
/** @internal */
export const FlagOutcomeEnvironmentsRulesType$inboundSchema: z.ZodNativeEnum<
typeof FlagOutcomeEnvironmentsRulesType
> = z.nativeEnum(FlagOutcomeEnvironmentsRulesType);
/** @internal */
export const OutcomeBase$inboundSchema: z.ZodType<
OutcomeBase,
z.ZodTypeDef,
unknown
> = z.object({
type: FlagOutcomeEnvironmentsRulesType$inboundSchema,
kind: types.string(),
attribute: types.string(),
});
export function outcomeBaseFromJSON(
jsonString: string,
): SafeParseResult<OutcomeBase, SDKValidationError> {
return safeParse(
jsonString,
(x) => OutcomeBase$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'OutcomeBase' from JSON`,
);
}
/** @internal */
export const Outcome2$inboundSchema: z.ZodType<
Outcome2,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("split"),
base: z.lazy(() => OutcomeBase$inboundSchema),
weights: z.record(types.number()),
defaultVariantId: types.string(),
});
export function outcome2FromJSON(
jsonString: string,
): SafeParseResult<Outcome2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome2' from JSON`,
);
}
/** @internal */
export const Outcome1$inboundSchema: z.ZodType<
Outcome1,
z.ZodTypeDef,
unknown
> = z.object({
type: types.literal("variant"),
variantId: types.string(),
});
export function outcome1FromJSON(
jsonString: string,
): SafeParseResult<Outcome1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome1' from JSON`,
);
}
/** @internal */
export const Outcome$inboundSchema: z.ZodType<Outcome, z.ZodTypeDef, unknown> =
z.union([
z.lazy(() => Outcome1$inboundSchema),
z.lazy(() => Outcome2$inboundSchema),
z.lazy(() => Outcome3$inboundSchema),
]);
export function outcomeFromJSON(
jsonString: string,
): SafeParseResult<Outcome, SDKValidationError> {
return safeParse(
jsonString,
(x) => Outcome$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Outcome' from JSON`,
);
}
/** @internal */
export const FlagRhsType$inboundSchema: z.ZodNativeEnum<typeof FlagRhsType> = z
.nativeEnum(FlagRhsType);
/** @internal */
export const Rhs4$inboundSchema: z.ZodType<Rhs4, z.ZodTypeDef, unknown> = z
.object({
type: FlagRhsType$inboundSchema,
pattern: types.string(),
flags: types.string(),
});
export function rhs4FromJSON(
jsonString: string,
): SafeParseResult<Rhs4, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rhs4$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rhs4' from JSON`,
);
}
/** @internal */
export const RhsType$inboundSchema: z.ZodNativeEnum<typeof RhsType> = z
.nativeEnum(RhsType);
/** @internal */
export const Items2$inboundSchema: z.ZodType<Items2, z.ZodTypeDef, unknown> = z
.object({
label: types.optional(types.string()),
note: types.optional(types.string()),
value: types.string(),
});
export function items2FromJSON(
jsonString: string,
): SafeParseResult<Items2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Items2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Items2' from JSON`,
);
}
/** @internal */
export const Items1$inboundSchema: z.ZodType<Items1, z.ZodTypeDef, unknown> = z
.object({
label: types.optional(types.string()),
note: types.optional(types.string()),
value: types.number(),
});
export function items1FromJSON(
jsonString: string,
): SafeParseResult<Items1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Items1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Items1' from JSON`,
);
}
/** @internal */
export const RhsItems$inboundSchema: z.ZodType<
RhsItems,
z.ZodTypeDef,
unknown
> = smartUnion([
z.lazy(() => Items1$inboundSchema),
z.lazy(() => Items2$inboundSchema),
]);
export function rhsItemsFromJSON(
jsonString: string,
): SafeParseResult<RhsItems, SDKValidationError> {
return safeParse(
jsonString,
(x) => RhsItems$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'RhsItems' from JSON`,
);
}
/** @internal */
export const Rhs3$inboundSchema: z.ZodType<Rhs3, z.ZodTypeDef, unknown> = z
.object({
type: RhsType$inboundSchema,
items: z.array(
smartUnion([
z.lazy(() => Items1$inboundSchema),
z.lazy(() => Items2$inboundSchema),
]),
),
});
export function rhs3FromJSON(
jsonString: string,
): SafeParseResult<Rhs3, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rhs3$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rhs3' from JSON`,
);
}
/** @internal */
export const Rhs$inboundSchema: z.ZodType<Rhs, z.ZodTypeDef, unknown> =
smartUnion([
z.lazy(() => Rhs4$inboundSchema),
z.lazy(() => Rhs3$inboundSchema),
types.string(),
types.number(),
types.boolean(),
]);
export function rhsFromJSON(
jsonString: string,
): SafeParseResult<Rhs, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rhs$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rhs' from JSON`,
);
}
/** @internal */
export const CmpOptions$inboundSchema: z.ZodType<
CmpOptions,
z.ZodTypeDef,
unknown
> = z.object({
ignoreCase: types.optional(types.boolean()),
});
export function cmpOptionsFromJSON(
jsonString: string,
): SafeParseResult<CmpOptions, SDKValidationError> {
return safeParse(
jsonString,
(x) => CmpOptions$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'CmpOptions' from JSON`,
);
}
/** @internal */
export const Lhs2$inboundSchema: z.ZodType<Lhs2, z.ZodTypeDef, unknown> = z
.object({
type: types.literal("entity"),
kind: types.string(),
attribute: types.string(),
});
export function lhs2FromJSON(
jsonString: string,
): SafeParseResult<Lhs2, SDKValidationError> {
return safeParse(
jsonString,
(x) => Lhs2$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Lhs2' from JSON`,
);
}
/** @internal */
export const Lhs1$inboundSchema: z.ZodType<Lhs1, z.ZodTypeDef, unknown> = z
.object({
type: types.literal("segment"),
});
export function lhs1FromJSON(
jsonString: string,
): SafeParseResult<Lhs1, SDKValidationError> {
return safeParse(
jsonString,
(x) => Lhs1$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Lhs1' from JSON`,
);
}
/** @internal */
export const Lhs$inboundSchema: z.ZodType<Lhs, z.ZodTypeDef, unknown> = z.union(
[z.lazy(() => Lhs1$inboundSchema), z.lazy(() => Lhs2$inboundSchema)],
);
export function lhsFromJSON(
jsonString: string,
): SafeParseResult<Lhs, SDKValidationError> {
return safeParse(
jsonString,
(x) => Lhs$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Lhs' from JSON`,
);
}
/** @internal */
export const Cmp$inboundSchema: z.ZodNativeEnum<typeof Cmp> = z.nativeEnum(Cmp);
/** @internal */
export const Conditions$inboundSchema: z.ZodType<
Conditions,
z.ZodTypeDef,
unknown
> = 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: string,
): SafeParseResult<Conditions, SDKValidationError> {
return safeParse(
jsonString,
(x) => Conditions$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Conditions' from JSON`,
);
}
/** @internal */
export const Rules$inboundSchema: z.ZodType<Rules, z.ZodTypeDef, unknown> = z
.object({
id: types.string(),
outcome: z.union([
z.lazy(() => Outcome1$inboundSchema),
z.lazy(() => Outcome2$inboundSchema),
z.lazy(() => Outcome3$inboundSchema),
]),
conditions: z.array(z.lazy(() => Conditions$inboundSchema)),
});
export function rulesFromJSON(
jsonString: string,
): SafeParseResult<Rules, SDKValidationError> {
return safeParse(
jsonString,
(x) => Rules$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Rules' from JSON`,
);
}
/** @internal */
export const Environments$inboundSchema: z.ZodType<
Environments,
z.ZodTypeDef,
unknown
> = 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),
]),
active: types.boolean(),
rules: z.array(z.lazy(() => Rules$inboundSchema)),
});
export function environmentsFromJSON(
jsonString: string,
): SafeParseResult<Environments, SDKValidationError> {
return safeParse(
jsonString,
(x) => Environments$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Environments' from JSON`,
);
}
/** @internal */
export const Kind$inboundSchema: z.ZodNativeEnum<typeof Kind> = z.nativeEnum(
Kind,
);
/** @internal */
export const State$inboundSchema: z.ZodNativeEnum<typeof State> = z.nativeEnum(
State,
);
/** @internal */
export const TypeName$inboundSchema: z.ZodNativeEnum<typeof TypeName> = z
.nativeEnum(TypeName);
/** @internal */
export const Creator$inboundSchema: z.ZodType<Creator, z.ZodTypeDef, unknown> =
z.object({
id: types.string(),
name: types.string(),
});
export function creatorFromJSON(
jsonString: string,
): SafeParseResult<Creator, SDKValidationError> {
return safeParse(
jsonString,
(x) => Creator$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Creator' from JSON`,
);
}
/** @internal */
export const Metadata$inboundSchema: z.ZodType<
Metadata,
z.ZodTypeDef,
unknown
> = z.object({
creator: types.optional(z.lazy(() => Creator$inboundSchema)),
});
export function metadataFromJSON(
jsonString: string,
): SafeParseResult<Metadata, SDKValidationError> {
return safeParse(
jsonString,
(x) => Metadata$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Metadata' from JSON`,
);
}
/** @internal */
export const Flag$inboundSchema: z.ZodType<Flag, z.ZodTypeDef, unknown> = z
.object({
description: types.optional(types.string()),
maintainerIds: types.optional(z.array(types.string())),
permanent: types.optional(types.boolean()),
tags: types.optional(z.array(types.string())),
experiment: types.optional(z.lazy(() => Experiment$inboundSchema)),
variants: z.array(z.lazy(() => Variants$inboundSchema)),
id: types.string(),
environments: z.record(z.lazy(() => Environments$inboundSchema)),
kind: Kind$inboundSchema,
revision: types.number(),
seed: types.number(),
state: State$inboundSchema,
slug: types.string(),
createdAt: types.number(),
updatedAt: types.number(),
createdBy: types.string(),
ownerId: types.string(),
projectId: types.string(),
typeName: TypeName$inboundSchema,
metadata: types.optional(z.lazy(() => Metadata$inboundSchema)),
});
export function flagFromJSON(
jsonString: string,
): SafeParseResult<Flag, SDKValidationError> {
return safeParse(
jsonString,
(x) => Flag$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Flag' from JSON`,
);
}