/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
ApprovalSettings,
ApprovalSettings$inboundSchema,
ApprovalSettings$Outbound,
ApprovalSettings$outboundSchema,
} from "./approvalsettings.js";
import {
Link,
Link$inboundSchema,
Link$Outbound,
Link$outboundSchema,
} from "./link.js";
export type Environment = {
/**
* The location and content type of related resources
*/
links: { [k: string]: Link };
/**
* The ID for the environment. Use this as the client-side ID for authorization in some client-side SDKs, and to associate LaunchDarkly environments with CDN integrations in edge SDKs.
*/
id: string;
/**
* A project-unique key for the new environment
*/
key: string;
/**
* A human-friendly name for the new environment
*/
name: string;
/**
* The SDK key for the environment. Use this for authorization in server-side SDKs.
*/
apiKey: string;
/**
* The mobile key for the environment. Use this for authorization in mobile SDKs.
*/
mobileKey: string;
/**
* The color used to indicate this environment in the UI
*/
color: string;
/**
* The default time (in minutes) that the PHP SDK can cache feature flag rules locally
*/
defaultTtl: number;
/**
* Ensures that one end user of the client-side SDK cannot inspect the variations for another end user
*/
secureMode: boolean;
/**
* Enables tracking detailed information for new flags by default
*/
defaultTrackEvents: boolean;
/**
* Whether members who modify flags and segments through the LaunchDarkly user interface are required to add a comment
*/
requireComments: boolean;
/**
* Whether members who modify flags and segments through the LaunchDarkly user interface are required to confirm those changes
*/
confirmChanges: boolean;
/**
* A list of tags for this environment
*/
tags: Array<string>;
approvalSettings?: ApprovalSettings | undefined;
/**
* Details on the approval settings for this environment for each resource kind
*/
resourceApprovalSettings?: { [k: string]: ApprovalSettings } | undefined;
/**
* Whether the environment is critical
*/
critical: boolean;
};
/** @internal */
export const Environment$inboundSchema: z.ZodType<
Environment,
z.ZodTypeDef,
unknown
> = z.object({
_links: z.record(Link$inboundSchema),
_id: z.string(),
key: z.string(),
name: z.string(),
apiKey: z.string(),
mobileKey: z.string(),
color: z.string(),
defaultTtl: z.number().int(),
secureMode: z.boolean(),
defaultTrackEvents: z.boolean(),
requireComments: z.boolean(),
confirmChanges: z.boolean(),
tags: z.array(z.string()),
approvalSettings: ApprovalSettings$inboundSchema.optional(),
resourceApprovalSettings: z.record(ApprovalSettings$inboundSchema).optional(),
critical: z.boolean(),
}).transform((v) => {
return remap$(v, {
"_links": "links",
"_id": "id",
});
});
/** @internal */
export type Environment$Outbound = {
_links: { [k: string]: Link$Outbound };
_id: string;
key: string;
name: string;
apiKey: string;
mobileKey: string;
color: string;
defaultTtl: number;
secureMode: boolean;
defaultTrackEvents: boolean;
requireComments: boolean;
confirmChanges: boolean;
tags: Array<string>;
approvalSettings?: ApprovalSettings$Outbound | undefined;
resourceApprovalSettings?:
| { [k: string]: ApprovalSettings$Outbound }
| undefined;
critical: boolean;
};
/** @internal */
export const Environment$outboundSchema: z.ZodType<
Environment$Outbound,
z.ZodTypeDef,
Environment
> = z.object({
links: z.record(Link$outboundSchema),
id: z.string(),
key: z.string(),
name: z.string(),
apiKey: z.string(),
mobileKey: z.string(),
color: z.string(),
defaultTtl: z.number().int(),
secureMode: z.boolean(),
defaultTrackEvents: z.boolean(),
requireComments: z.boolean(),
confirmChanges: z.boolean(),
tags: z.array(z.string()),
approvalSettings: ApprovalSettings$outboundSchema.optional(),
resourceApprovalSettings: z.record(ApprovalSettings$outboundSchema)
.optional(),
critical: z.boolean(),
}).transform((v) => {
return remap$(v, {
links: "_links",
id: "_id",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Environment$ {
/** @deprecated use `Environment$inboundSchema` instead. */
export const inboundSchema = Environment$inboundSchema;
/** @deprecated use `Environment$outboundSchema` instead. */
export const outboundSchema = Environment$outboundSchema;
/** @deprecated use `Environment$Outbound` instead. */
export type Outbound = Environment$Outbound;
}
export function environmentToJSON(environment: Environment): string {
return JSON.stringify(Environment$outboundSchema.parse(environment));
}
export function environmentFromJSON(
jsonString: string,
): SafeParseResult<Environment, SDKValidationError> {
return safeParse(
jsonString,
(x) => Environment$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Environment' from JSON`,
);
}