/** * Environment operations for Managed Runtime. * * Handles creating and managing MRT environments (targets). * * @module operations/mrt/env */ import type { AuthStrategy } from '../../auth/types.js'; import type { components } from '../../clients/mrt.js'; /** * MRT environment (target) type from API. */ export type MrtEnvironment = components['schemas']['APITargetV2Create']; /** * Environment state from the MRT API. */ export type MrtEnvironmentState = components['schemas']['StateEnum']; type SsrRegion = components['schemas']['SsrRegionEnum']; type LogLevel = components['schemas']['LogLevelEnum']; /** * Options for creating an MRT environment. */ export interface CreateEnvOptions { /** * The project slug to create the environment in. */ projectSlug: string; /** * Environment slug/identifier (e.g., staging, production). */ slug: string; /** * Display name for the environment. */ name: string; /** * AWS region for SSR deployment. */ region?: SsrRegion; /** * Mark as a production environment. */ isProduction?: boolean; /** * Hostname pattern for V8 Tag loading. */ hostname?: string; /** * Full external hostname (e.g., www.example.com). */ externalHostname?: string; /** * External domain for Universal PWA SSR (e.g., example.com). */ externalDomain?: string; /** * Forward HTTP cookies to origin. */ allowCookies?: boolean; /** * Enable source map support in the environment. */ enableSourceMaps?: boolean; /** * Minimum log level for the environment. */ logLevel?: LogLevel; /** * IP whitelist (CIDR blocks, space-separated). */ whitelistedIps?: string; /** * Proxy configurations for SSR. * Each proxy maps a path prefix to a backend host. */ proxyConfigs?: Array<{ /** The path prefix to proxy (e.g., 'api', 'ocapi', 'einstein'). */ path: string; /** The backend host to proxy to (e.g., 'api.example.com'). */ host: string; }>; /** * MRT API origin URL. * @default "https://cloud.mobify.com" */ origin?: string; } /** * Creates a new environment (target) in an MRT project. * * @param options - Environment creation options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns The full environment object from the API * @throws Error if creation fails * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { createEnv } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * const env = await createEnv({ * projectSlug: 'my-storefront', * slug: 'staging', * name: 'Staging Environment', * region: 'us-east-1', * isProduction: false * }, auth); * * console.log(`Environment ${env.slug} created`); * ``` */ export declare function createEnv(options: CreateEnvOptions, auth: AuthStrategy): Promise; /** * Options for deleting an MRT environment. */ export interface DeleteEnvOptions { /** * The project slug containing the environment. */ projectSlug: string; /** * Environment slug/identifier to delete. */ slug: string; /** * MRT API origin URL. * @default "https://cloud.mobify.com" */ origin?: string; } /** * Deletes an environment (target) from an MRT project. * * @param options - Environment deletion options * @param auth - Authentication strategy (ApiKeyStrategy) * @throws Error if deletion fails * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { deleteEnv } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * await deleteEnv({ * projectSlug: 'my-storefront', * slug: 'feature-test' * }, auth); * * console.log('Environment deleted'); * ``` */ export declare function deleteEnv(options: DeleteEnvOptions, auth: AuthStrategy): Promise; /** * Options for getting an MRT environment. */ export interface GetEnvOptions { /** * The project slug containing the environment. */ projectSlug: string; /** * Environment slug/identifier to retrieve. */ slug: string; /** * MRT API origin URL. * @default "https://cloud.mobify.com" */ origin?: string; } /** * Gets an environment (target) from an MRT project. * * @param options - Environment retrieval options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns The environment object from the API * @throws Error if retrieval fails * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { getEnv } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * const env = await getEnv({ * projectSlug: 'my-storefront', * slug: 'staging' * }, auth); * * console.log(`Environment state: ${env.state}`); * ``` */ export declare function getEnv(options: GetEnvOptions, auth: AuthStrategy): Promise; /** * Poll info passed to the onPoll callback during environment waiting. */ export interface WaitForEnvPollInfo { /** Environment slug. */ slug: string; /** Seconds elapsed since waiting started. */ elapsedSeconds: number; /** Current environment state (e.g., 'PUBLISH_IN_PROGRESS', 'ACTIVE'). */ state: string; } /** * Options for waiting for an MRT environment to be ready. */ export interface WaitForEnvOptions extends GetEnvOptions { /** * Polling interval in seconds. * @default 10 */ pollIntervalSeconds?: number; /** * Maximum time to wait in seconds (0 for no timeout). * @default 2700 (45 minutes) */ timeoutSeconds?: number; /** * Optional callback invoked on each poll with current status. */ onPoll?: (info: WaitForEnvPollInfo) => void; /** * Custom sleep function for testing. */ sleep?: (ms: number) => Promise; /** * Custom clock for testing. Defaults to Date.now. */ now?: () => number; } /** * Waits for an environment to reach a terminal state (ACTIVE or failed). * * Polls the environment status until it reaches ACTIVE, CREATE_FAILED, * or PUBLISH_FAILED state, or until the timeout is reached. * * @param options - Wait options including polling interval and timeout * @param auth - Authentication strategy (ApiKeyStrategy) * @returns The environment in its terminal state * @throws Error if timeout is reached or environment fails * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { createEnv, waitForEnv } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * // Create environment * const env = await createEnv({ * projectSlug: 'my-storefront', * slug: 'staging', * name: 'Staging' * }, auth); * * // Wait for it to be ready * const readyEnv = await waitForEnv({ * projectSlug: 'my-storefront', * slug: 'staging', * timeoutSeconds: 60, * onPoll: (info) => console.log(`[${info.elapsedSeconds}s] State: ${info.state}`) * }, auth); * * if (readyEnv.state === 'ACTIVE') { * console.log('Environment is ready!'); * } * ``` */ export declare function waitForEnv(options: WaitForEnvOptions, auth: AuthStrategy): Promise; /** * MRT environment type for updates. */ export type MrtEnvironmentUpdate = components['schemas']['APITargetV2Update']; /** * Options for cloning an MRT environment. */ export interface CloneEnvOptions { /** * The project slug containing the source and new environment. */ projectSlug: string; /** * Slug for the new environment created by the clone. */ slug: string; /** * Slug of the source environment to clone from. */ fromSlug: string; /** * Full external hostname (e.g., www.example.com). * Required when not using an MRT-managed certificate. */ externalHostname?: string | null; /** * External domain for Universal PWA SSR (e.g., example.com). */ externalDomain?: string | null; /** * ID of the certificate to associate with the new environment. * Required when using a custom domain. */ certificateId?: number | null; /** * Clone redirects from the source environment. * @default false */ cloneRedirects?: boolean; /** * Clone environment variables from the source environment. * @default false */ cloneEnvironmentVariables?: boolean; /** * Clone B2C target info from the source environment. * @default false */ cloneB2cTargetInfo?: boolean; /** * MRT API origin URL. * @default "https://cloud.mobify.com" */ origin?: string; } /** * Clones an environment (target) from an existing source environment. * * The new environment receives the source's configuration (excluding proxies and * production flag) and is automatically deployed with the same bundle as the * source target's current deployment (if any). * * @param options - Clone options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns The newly created environment * @throws Error if the clone fails * * @example * ```typescript * const env = await cloneEnv({ * projectSlug: 'my-storefront', * slug: 'staging-copy', * fromSlug: 'staging', * cloneRedirects: true, * cloneEnvironmentVariables: true * }, auth); * ``` */ export declare function cloneEnv(options: CloneEnvOptions, auth: AuthStrategy): Promise; /** * Patched environment for partial updates. */ export type PatchedMrtEnvironment = components['schemas']['PatchedAPITargetV2Update']; /** * Options for listing MRT environments. */ export interface ListEnvsOptions { /** * The project slug to list environments for. */ projectSlug: string; /** * MRT API origin URL. * @default "https://cloud.mobify.com" */ origin?: string; } /** * Result of listing environments. */ export interface ListEnvsResult { /** * Array of environments. */ environments: MrtEnvironment[]; } /** * Lists environments (targets) for an MRT project. * * @param options - List options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns List of environments * @throws Error if request fails * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { listEnvs } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * const result = await listEnvs({ projectSlug: 'my-storefront' }, auth); * for (const env of result.environments) { * console.log(`- ${env.name} (${env.slug}): ${env.state}`); * } * ``` */ export declare function listEnvs(options: ListEnvsOptions, auth: AuthStrategy): Promise; /** * Options for updating an MRT environment. */ export interface UpdateEnvOptions { /** * The project slug containing the environment. */ projectSlug: string; /** * Environment slug/identifier to update. */ slug: string; /** * New display name for the environment. */ name?: string; /** * Mark as a production environment. */ isProduction?: boolean; /** * Hostname pattern for V8 Tag loading. */ hostname?: string | null; /** * Full external hostname (e.g., www.example.com). */ externalHostname?: string | null; /** * External domain for Universal PWA SSR (e.g., example.com). */ externalDomain?: string | null; /** * Forward HTTP cookies to origin. */ allowCookies?: boolean | null; /** * Enable source map support in the environment. */ enableSourceMaps?: boolean | null; /** * Minimum log level for the environment. */ logLevel?: LogLevel | null; /** * IP whitelist (CIDR blocks, space-separated). */ whitelistedIps?: string | null; /** * Proxy configurations for SSR. */ proxyConfigs?: Array<{ path: string; host: string; }> | null; /** * MRT API origin URL. * @default "https://cloud.mobify.com" */ origin?: string; } /** * Updates an environment (target) in an MRT project. * * Important: This endpoint automatically re-deploys the current bundle * if any of the SSR-related properties are changed. * * @param options - Environment update options * @param auth - Authentication strategy (ApiKeyStrategy) * @returns The updated environment * @throws Error if update fails * * @example * ```typescript * import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth'; * import { updateEnv } from '@salesforce/b2c-tooling-sdk/operations/mrt'; * * const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization'); * * const updated = await updateEnv({ * projectSlug: 'my-storefront', * slug: 'staging', * name: 'Staging v2', * enableSourceMaps: true * }, auth); * ``` */ export declare function updateEnv(options: UpdateEnvOptions, auth: AuthStrategy): Promise; export {};