UNPKG

@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>

564 lines 20.5 kB
/* * 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 MetricType = { Count: "count", Currency: "currency", Percentage: "percentage", }; export const MetricUnit = { Session: "session", User: "user", Visitor: "visitor", }; export const Directionality = { DecreaseIsGood: "decreaseIsGood", IncreaseIsGood: "increaseIsGood", }; export const Device = { Android: "android", Desktop: "desktop", Ios: "ios", Mweb: "mweb", }; export const DurationUnit = { Days: "days", Exposures: "exposures", }; export const AllocationUnit = { CookieId: "cookieId", UserId: "userId", VisitorId: "visitorId", }; export const FlagMetricType = { Count: "count", Currency: "currency", Percentage: "percentage", }; export const FlagMetricUnit = { Session: "session", User: "user", Visitor: "visitor", }; export const FlagDirectionality = { DecreaseIsGood: "decreaseIsGood", IncreaseIsGood: "increaseIsGood", }; export const FlagStatus = { Closed: "closed", Draft: "draft", Paused: "paused", Running: "running", }; export const FlagType = { Variant: "variant", }; export const FlagFallthroughEnvironments3Type = { Entity: "entity", }; export const FlagFallthroughEnvironments2Type = { Entity: "entity", }; export const FlagOutcomeEnvironmentsRules3Type = { Entity: "entity", }; export const FlagOutcomeEnvironmentsRulesType = { 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 MetricType$inboundSchema = z .nativeEnum(MetricType); /** @internal */ export const MetricUnit$inboundSchema = z .nativeEnum(MetricUnit); /** @internal */ export const Directionality$inboundSchema = z.nativeEnum(Directionality); /** @internal */ export const GuardrailMetrics$inboundSchema = 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) { return safeParse(jsonString, (x) => GuardrailMetrics$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GuardrailMetrics' from JSON`); } /** @internal */ export const Device$inboundSchema = z .nativeEnum(Device); /** @internal */ export const DurationUnit$inboundSchema = z.nativeEnum(DurationUnit); /** @internal */ export const AllocationUnit$inboundSchema = z.nativeEnum(AllocationUnit); /** @internal */ export const FlagMetricType$inboundSchema = z.nativeEnum(FlagMetricType); /** @internal */ export const FlagMetricUnit$inboundSchema = z.nativeEnum(FlagMetricUnit); /** @internal */ export const FlagDirectionality$inboundSchema = z.nativeEnum(FlagDirectionality); /** @internal */ export const PrimaryMetrics$inboundSchema = 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) { return safeParse(jsonString, (x) => PrimaryMetrics$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PrimaryMetrics' from JSON`); } /** @internal */ export const FlagStatus$inboundSchema = z .nativeEnum(FlagStatus); /** @internal */ export const Experiment$inboundSchema = 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) { return safeParse(jsonString, (x) => Experiment$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Experiment' from JSON`); } /** @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 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), ]); export function fallthroughFromJSON(jsonString) { return safeParse(jsonString, (x) => Fallthrough$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Fallthrough' 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 FlagOutcomeEnvironmentsRulesType$inboundSchema = z.nativeEnum(FlagOutcomeEnvironmentsRulesType); /** @internal */ export const OutcomeBase$inboundSchema = z.object({ type: FlagOutcomeEnvironmentsRulesType$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 Outcome$inboundSchema = z.union([ z.lazy(() => Outcome1$inboundSchema), z.lazy(() => Outcome2$inboundSchema), z.lazy(() => Outcome3$inboundSchema), ]); export function outcomeFromJSON(jsonString) { return safeParse(jsonString, (x) => Outcome$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Outcome' 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), ]), 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 Environments$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), ]), active: types.boolean(), rules: z.array(z.lazy(() => Rules$inboundSchema)), }); export function environmentsFromJSON(jsonString) { return safeParse(jsonString, (x) => Environments$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Environments' 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()), 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) { return safeParse(jsonString, (x) => Flag$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Flag' from JSON`); } //# sourceMappingURL=flag.js.map