featureflagbody.ts•7.7 kB
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
ClientSideAvailabilityPost,
ClientSideAvailabilityPost$inboundSchema,
ClientSideAvailabilityPost$Outbound,
ClientSideAvailabilityPost$outboundSchema,
} from "./clientsideavailabilitypost.js";
import {
CustomProperty,
CustomProperty$inboundSchema,
CustomProperty$Outbound,
CustomProperty$outboundSchema,
} from "./customproperty.js";
import {
Defaults,
Defaults$inboundSchema,
Defaults$Outbound,
Defaults$outboundSchema,
} from "./defaults.js";
import {
FlagPrerequisitePost,
FlagPrerequisitePost$inboundSchema,
FlagPrerequisitePost$Outbound,
FlagPrerequisitePost$outboundSchema,
} from "./flagprerequisitepost.js";
import {
MigrationSettingsPost,
MigrationSettingsPost$inboundSchema,
MigrationSettingsPost$Outbound,
MigrationSettingsPost$outboundSchema,
} from "./migrationsettingspost.js";
import {
Variation,
Variation$inboundSchema,
Variation$Outbound,
Variation$outboundSchema,
} from "./variation.js";
/**
* Purpose of the flag
*/
export const Purpose = {
Migration: "migration",
Holdout: "holdout",
} as const;
/**
* Purpose of the flag
*/
export type Purpose = ClosedEnum<typeof Purpose>;
export type FeatureFlagBody = {
/**
* A human-friendly name for the feature flag
*/
name: string;
/**
* A unique key used to reference the flag in your code
*/
key: string;
/**
* Description of the feature flag. Defaults to an empty string.
*/
description?: string | undefined;
/**
* Deprecated, use <code>clientSideAvailability</code>. Whether this flag should be made available to the client-side JavaScript SDK. Defaults to <code>false</code>.
*
* @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
*/
includeInSnippet?: boolean | undefined;
clientSideAvailability?: ClientSideAvailabilityPost | undefined;
/**
* An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of <code>true</code> and <code>false</code> will be used.
*/
variations?: Array<Variation> | undefined;
/**
* Whether the flag is a temporary flag. Defaults to <code>true</code>.
*/
temporary?: boolean | undefined;
/**
* Tags for the feature flag. Defaults to an empty array.
*/
tags?: Array<string> | undefined;
customProperties?: { [k: string]: CustomProperty } | undefined;
defaults?: Defaults | undefined;
/**
* Purpose of the flag
*/
purpose?: Purpose | undefined;
migrationSettings?: MigrationSettingsPost | undefined;
/**
* The ID of the member who maintains this feature flag
*/
maintainerId?: string | undefined;
/**
* The key of the team that maintains this feature flag
*/
maintainerTeamKey?: string | undefined;
/**
* Initial set of prerequisite flags for all environments
*/
initialPrerequisites?: Array<FlagPrerequisitePost> | undefined;
/**
* Whether to automatically turn the flag on across all environments at creation. Defaults to <code>false</code>.
*/
isFlagOn?: boolean | undefined;
};
/** @internal */
export const Purpose$inboundSchema: z.ZodNativeEnum<typeof Purpose> = z
.nativeEnum(Purpose);
/** @internal */
export const Purpose$outboundSchema: z.ZodNativeEnum<typeof Purpose> =
Purpose$inboundSchema;
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Purpose$ {
/** @deprecated use `Purpose$inboundSchema` instead. */
export const inboundSchema = Purpose$inboundSchema;
/** @deprecated use `Purpose$outboundSchema` instead. */
export const outboundSchema = Purpose$outboundSchema;
}
/** @internal */
export const FeatureFlagBody$inboundSchema: z.ZodType<
FeatureFlagBody,
z.ZodTypeDef,
unknown
> = z.object({
name: z.string(),
key: z.string(),
description: z.string().optional(),
includeInSnippet: z.boolean().optional(),
clientSideAvailability: ClientSideAvailabilityPost$inboundSchema.optional(),
variations: z.array(Variation$inboundSchema).optional(),
temporary: z.boolean().optional(),
tags: z.array(z.string()).optional(),
customProperties: z.record(CustomProperty$inboundSchema).optional(),
defaults: Defaults$inboundSchema.optional(),
purpose: Purpose$inboundSchema.optional(),
migrationSettings: MigrationSettingsPost$inboundSchema.optional(),
maintainerId: z.string().optional(),
maintainerTeamKey: z.string().optional(),
initialPrerequisites: z.array(FlagPrerequisitePost$inboundSchema).optional(),
isFlagOn: z.boolean().optional(),
});
/** @internal */
export type FeatureFlagBody$Outbound = {
name: string;
key: string;
description?: string | undefined;
includeInSnippet?: boolean | undefined;
clientSideAvailability?: ClientSideAvailabilityPost$Outbound | undefined;
variations?: Array<Variation$Outbound> | undefined;
temporary?: boolean | undefined;
tags?: Array<string> | undefined;
customProperties?: { [k: string]: CustomProperty$Outbound } | undefined;
defaults?: Defaults$Outbound | undefined;
purpose?: string | undefined;
migrationSettings?: MigrationSettingsPost$Outbound | undefined;
maintainerId?: string | undefined;
maintainerTeamKey?: string | undefined;
initialPrerequisites?: Array<FlagPrerequisitePost$Outbound> | undefined;
isFlagOn?: boolean | undefined;
};
/** @internal */
export const FeatureFlagBody$outboundSchema: z.ZodType<
FeatureFlagBody$Outbound,
z.ZodTypeDef,
FeatureFlagBody
> = z.object({
name: z.string(),
key: z.string(),
description: z.string().optional(),
includeInSnippet: z.boolean().optional(),
clientSideAvailability: ClientSideAvailabilityPost$outboundSchema.optional(),
variations: z.array(Variation$outboundSchema).optional(),
temporary: z.boolean().optional(),
tags: z.array(z.string()).optional(),
customProperties: z.record(CustomProperty$outboundSchema).optional(),
defaults: Defaults$outboundSchema.optional(),
purpose: Purpose$outboundSchema.optional(),
migrationSettings: MigrationSettingsPost$outboundSchema.optional(),
maintainerId: z.string().optional(),
maintainerTeamKey: z.string().optional(),
initialPrerequisites: z.array(FlagPrerequisitePost$outboundSchema).optional(),
isFlagOn: z.boolean().optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace FeatureFlagBody$ {
/** @deprecated use `FeatureFlagBody$inboundSchema` instead. */
export const inboundSchema = FeatureFlagBody$inboundSchema;
/** @deprecated use `FeatureFlagBody$outboundSchema` instead. */
export const outboundSchema = FeatureFlagBody$outboundSchema;
/** @deprecated use `FeatureFlagBody$Outbound` instead. */
export type Outbound = FeatureFlagBody$Outbound;
}
export function featureFlagBodyToJSON(
featureFlagBody: FeatureFlagBody,
): string {
return JSON.stringify(FeatureFlagBody$outboundSchema.parse(featureFlagBody));
}
export function featureFlagBodyFromJSON(
jsonString: string,
): SafeParseResult<FeatureFlagBody, SDKValidationError> {
return safeParse(
jsonString,
(x) => FeatureFlagBody$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FeatureFlagBody' from JSON`,
);
}