// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as ItemsAPI from '../rules/lists/items'; import { APIPromise } from '../../core/api-promise'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class BaseEnvironments extends APIResource { static override readonly _key: readonly ['zones', 'environments'] = Object.freeze([ 'zones', 'environments', ] as const); /** * Creates environments for a zone. * * @example * ```ts * const environment = await client.zones.environments.create({ * zone_id: 'zone_id', * environments: [ * { * expression: 'expression', * locked_on_deployment: true, * name: 'name', * position: {}, * ref: 'ref', * version: 0, * }, * ], * }); * ``` */ create(params: EnvironmentCreateParams, options?: RequestOptions): APIPromise { const { zone_id, ...body } = params; return ( this._client.post(path`/zones/${zone_id}/environments`, { body, ...options }) as APIPromise<{ result: EnvironmentCreateResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Replaces the full environment configuration for a zone. * * @example * ```ts * const environment = await client.zones.environments.update({ * zone_id: 'zone_id', * environments: [ * { * expression: 'expression', * locked_on_deployment: true, * name: 'name', * position: {}, * ref: 'ref', * version: 0, * }, * ], * }); * ``` */ update(params: EnvironmentUpdateParams, options?: RequestOptions): APIPromise { const { zone_id, ...body } = params; return ( this._client.put(path`/zones/${zone_id}/environments`, { body, ...options }) as APIPromise<{ result: EnvironmentUpdateResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Lists configured environments for a zone. * * @example * ```ts * const environments = await client.zones.environments.list({ * zone_id: 'zone_id', * }); * ``` */ list(params: EnvironmentListParams, options?: RequestOptions): APIPromise { const { zone_id } = params; return ( this._client.get(path`/zones/${zone_id}/environments`, options) as APIPromise<{ result: EnvironmentListResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Deletes a zone environment by reference identifier. * * @example * ```ts * const environment = await client.zones.environments.delete( * 'environment_id', * { zone_id: 'zone_id' }, * ); * ``` */ delete( environmentID: string, params: EnvironmentDeleteParams, options?: RequestOptions, ): APIPromise { const { zone_id } = params; return ( this._client.delete(path`/zones/${zone_id}/environments/${environmentID}`, options) as APIPromise<{ result: EnvironmentDeleteResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Applies partial updates to zone environments. * * @example * ```ts * const response = await client.zones.environments.edit({ * zone_id: 'zone_id', * environments: [ * { * expression: 'expression', * locked_on_deployment: true, * name: 'name', * position: {}, * ref: 'ref', * version: 0, * }, * ], * }); * ``` */ edit(params: EnvironmentEditParams, options?: RequestOptions): APIPromise { const { zone_id, ...body } = params; return ( this._client.patch(path`/zones/${zone_id}/environments`, { body, ...options }) as APIPromise<{ result: EnvironmentEditResponse; }> )._thenUnwrap((obj) => obj.result); } /** * Rolls a zone environment back to its previous version. * * @example * ```ts * const response = await client.zones.environments.rollback( * 'environment_id', * { zone_id: 'zone_id' }, * ); * ``` */ rollback( environmentID: string, params: EnvironmentRollbackParams, options?: RequestOptions, ): APIPromise { const { zone_id } = params; return ( this._client.post( path`/zones/${zone_id}/environments/${environmentID}/rollback`, options, ) as APIPromise<{ result: EnvironmentRollbackResponse }> )._thenUnwrap((obj) => obj.result); } } export class Environments extends BaseEnvironments {} export interface EnvironmentCreateResponse { environments: Array; } export namespace EnvironmentCreateResponse { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursor; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentUpdateResponse { environments: Array; } export namespace EnvironmentUpdateResponse { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursor; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentListResponse { environments: Array; } export namespace EnvironmentListResponse { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursor; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentDeleteResponse { environments: Array; } export namespace EnvironmentDeleteResponse { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursor; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentEditResponse { environments: Array; } export namespace EnvironmentEditResponse { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursor; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentRollbackResponse { environments: Array; } export namespace EnvironmentRollbackResponse { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursor; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentCreateParams { /** * Path param: Identifier of the zone. */ zone_id: string; /** * Body param */ environments: Array; } export namespace EnvironmentCreateParams { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursorParam; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentUpdateParams { /** * Path param: Identifier of the zone. */ zone_id: string; /** * Body param */ environments: Array; } export namespace EnvironmentUpdateParams { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursorParam; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentListParams { /** * Identifier of the zone. */ zone_id: string; } export interface EnvironmentDeleteParams { /** * Identifier of the zone. */ zone_id: string; } export interface EnvironmentEditParams { /** * Path param: Identifier of the zone. */ zone_id: string; /** * Body param */ environments: Array; } export namespace EnvironmentEditParams { export interface Environment { expression: string; locked_on_deployment: boolean | null; name: string; position: ItemsAPI.ListCursorParam; ref: string; version: number | null; http_application_id?: string | null; } } export interface EnvironmentRollbackParams { /** * Identifier of the zone. */ zone_id: string; } export declare namespace Environments { export { type EnvironmentCreateResponse as EnvironmentCreateResponse, type EnvironmentUpdateResponse as EnvironmentUpdateResponse, type EnvironmentListResponse as EnvironmentListResponse, type EnvironmentDeleteResponse as EnvironmentDeleteResponse, type EnvironmentEditResponse as EnvironmentEditResponse, type EnvironmentRollbackResponse as EnvironmentRollbackResponse, type EnvironmentCreateParams as EnvironmentCreateParams, type EnvironmentUpdateParams as EnvironmentUpdateParams, type EnvironmentListParams as EnvironmentListParams, type EnvironmentDeleteParams as EnvironmentDeleteParams, type EnvironmentEditParams as EnvironmentEditParams, type EnvironmentRollbackParams as EnvironmentRollbackParams, }; }