UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

1,236 lines (1,235 loc) 64.6 kB
import { RequestInit as FetchRequestInit } from 'node-fetch'; /** * Custom error class for Optimizely API-related errors * @extends Error * @description Provides structured error information for API failures including * HTTP status codes, response bodies, and contextual error messages for debugging */ export declare class OptimizelyAPIError extends Error { /** HTTP status code if the error originated from an HTTP response */ status?: number; /** Response body or additional error details from the API */ response?: string | any; /** * Creates a new OptimizelyAPIError * @param message - Descriptive error message * @param status - HTTP status code (e.g., 404, 401, 500) * @param response - Response body or additional error context * @example * ```typescript * throw new OptimizelyAPIError('Project not found', 404, { project_id: '12345' }); * ``` */ constructor(message: string, status?: number, response?: string | any); } /** * Configuration options for OptimizelyAPIHelper * @description Allows customization of API endpoints, rate limits, and retry behavior */ interface OptimizelyAPIHelperOptions { /** Custom base URL for Optimizely API (default: https://api.optimizely.com/v2) */ baseUrl?: string; /** Custom URL for feature flag configuration endpoints */ flagsUrl?: string; /** Custom rate limit for requests per minute (default: 60) */ requestsPerMinute?: number; /** Custom rate limit for requests per second (default: 10) */ requestsPerSecond?: number; /** Maximum number of retry attempts for failed requests (default: 3) */ retryAttempts?: number; /** Base delay between retries in milliseconds (default: 1000) */ retryDelay?: number; } /** * Options for controlling which data types to include in comprehensive project fetches * @description Used by getProjectData() to selectively include different entity types * and optimize API usage based on specific needs */ interface ProjectDataOptions { /** Whether to include feature flags data (default: true) */ includeFlags?: boolean; /** Whether to include experiments data (default: true) */ includeExperiments?: boolean; /** Whether to include audiences data (default: true) */ includeAudiences?: boolean; /** Whether to include attributes data (default: true) */ includeAttributes?: boolean; /** Whether to include events data (default: true) */ includeEvents?: boolean; } /** * Main API Helper Class for Optimizely REST API interactions * @description Provides comprehensive methods for interacting with Optimizely's REST API * with built-in rate limiting, retry logic, error handling, and data fetching utilities. * Supports both Feature Experimentation and Web Experimentation APIs. * * @example * ```typescript * const apiHelper = new OptimizelyAPIHelper('your-api-token'); * const projects = await apiHelper.listProjects(); * const flags = await apiHelper.listFlags('project-id'); * ``` */ export declare class OptimizelyAPIHelper { /** Optimizely API authentication token */ private token; /** Base URL for Optimizely API endpoints */ private baseUrl; /** URL for feature flag configuration endpoints */ private flagsUrl; /** Rate limiter instance for managing API quotas */ private rateLimiter; /** Maximum number of retry attempts for failed requests */ private retryAttempts; /** Base delay between retries in milliseconds */ private retryDelay; /** * Creates a new OptimizelyAPIHelper instance * @param token - Optimizely Personal Access Token for authentication * @param options - Configuration options for customizing API behavior * @throws {Error} When token is not provided * * @example * ```typescript * // Basic usage with defaults * const api = new OptimizelyAPIHelper('your-token'); * * // Custom configuration * const api = new OptimizelyAPIHelper('your-token', { * requestsPerMinute: 120, * retryAttempts: 5 * }); * ``` */ constructor(token: string, options?: OptimizelyAPIHelperOptions); /** * Core HTTP request method with rate limiting and retry logic * @param url - The complete URL to make the request to * @param options - Fetch request options (method, headers, body, etc.) * @returns Promise resolving to the parsed response data * @throws {OptimizelyAPIError} When the request fails after all retries * * @description This is the foundation method used by all other API methods. * It automatically handles: * - Rate limiting (respects Optimizely's API quotas) * - Authentication (adds Bearer token) * - Retries with exponential backoff * - Error parsing and structured error responses * * @example * ```typescript * // GET request * const data = await api.makeRequest('https://api.optimizely.com/v2/projects'); * * // POST request * const result = await api.makeRequest('https://api.optimizely.com/v2/projects', { * method: 'POST', * body: JSON.stringify({ name: 'New Project' }) * }); * ``` */ makeRequest(url: string, options?: FetchRequestInit): Promise<any>; private isRetryableError; /** * Lists all projects accessible with the current API token * @param filters - Pagination options for the request * @param filters.per_page - Number of projects per page (default: 25, max: 100) * @param filters.page - Page number to retrieve (1-based) * @returns Promise resolving to array of project objects * * @example * ```typescript * // Get all projects (first page) * const projects = await api.listProjects(); * * // Get specific page with custom page size * const page2 = await api.listProjects({ per_page: 50, page: 2 }); * ``` */ listProjects(filters?: { per_page?: number; page?: number; }): Promise<any[]>; /** * Gets detailed information about a specific project * @param projectId - The project ID to retrieve (can be string or number) * @returns Promise resolving to project details including metadata and settings * @throws {OptimizelyAPIError} When project is not found or access is denied * * @example * ```typescript * const project = await api.getProject('12345'); * console.log(project.name, project.status); * ``` */ getProject(projectId: number | string): Promise<any>; /** * Lists all environments within a project * @param projectId - The project ID to get environments for * @returns Promise resolving to array of environment objects with keys, names, and priorities * * @example * ```typescript * const environments = await api.listEnvironments('12345'); * environments.forEach(env => console.log(env.key, env.name)); * ``` */ listEnvironments(projectId: number | string, params?: { per_page?: number; page_token?: string; page_window?: number; archived?: boolean; sort?: string[]; }): Promise<any[]>; /** * Creates a new environment in a Feature Experimentation project * @param projectId - The project ID to create the environment in * @param environmentData - Environment data containing name, key, description, etc. * @returns Promise resolving to the created environment object * * @description Creates a new environment in a Feature Experimentation project. * Only works with projects that have Feature Experimentation enabled. * * @example * ```typescript * const environment = await api.createEnvironment('12345', { * key: 'production', * name: 'Production Environment', * description: 'Production deployment environment' * }); * ``` */ createEnvironment(projectId: number | string, environmentData: any): Promise<any>; /** * Updates an existing environment in a Feature Experimentation project * @param projectId - The project ID containing the environment * @param environmentId - The environment ID to update * @param environmentData - Updated environment data * @returns Promise resolving to the updated environment object * * @description Updates an existing environment in a Feature Experimentation project. * Only works with projects that have Feature Experimentation enabled. * * @example * ```typescript * const environment = await api.updateEnvironment('12345', 'env_123', { * name: 'Updated Production Environment', * description: 'Updated production deployment environment' * }); * ``` */ updateEnvironment(projectId: number | string, environmentId: string, environmentData: any): Promise<any>; /** * Deletes/archives an environment in a Feature Experimentation project * @param projectId - The project ID containing the environment * @param environmentId - The environment ID to delete * @returns Promise resolving to the deleted environment object * * @description Deletes (archives) an environment in a Feature Experimentation project. * Only works with projects that have Feature Experimentation enabled. * Note: In Optimizely, deletion typically means archiving the resource. * * @example * ```typescript * const deletedEnvironment = await api.deleteEnvironment('12345', 'env_123'); * ``` */ deleteEnvironment(projectId: number | string, environmentId: string): Promise<any>; /** * Lists feature flags within a project with optional filtering * @param projectId - The project ID to get flags for * @param filters - Filtering and pagination options * @param filters.per_page - Number of flags per page (default: 25, max: 100) * @param filters.page - Page number to retrieve (1-based) * @param filters.archived - Filter by archived status (client-side filtering) * @returns Promise resolving to array of flag objects * * @description The Optimizely API doesn't support server-side archived filtering, * so this method applies client-side filtering when the archived parameter is provided. * For better performance with large datasets, consider using the CacheManager instead. * * @example * ```typescript * // Get all flags * const flags = await api.listFlags('12345'); * * // Get only active (non-archived) flags * const activeFlags = await api.listFlags('12345', { archived: false }); * ``` */ listFlags(projectId: number | string, filters?: { per_page?: number; page?: number; page_token?: string; archived?: boolean; }): Promise<any>; /** * Gets detailed information about a specific feature flag * @param projectId - The project ID containing the flag * @param flagKey - The unique flag key to retrieve * @returns Promise resolving to flag details including variations, rules, and metadata * @throws {OptimizelyAPIError} When flag is not found or access is denied * * @example * ```typescript * const flag = await api.getFlag('12345', 'feature_rollout'); * console.log(flag.name, flag.variations); * ``` */ getFlag(projectId: number | string, flagKey: string): Promise<any>; /** * Gets entities for a specific flag (for change history tracking) * @param projectId - The project ID containing the flag * @param flagId - The flag ID (integer) to get entities for * @returns Promise resolving to array of entity groups with entity_ids and entity_type * @throws {OptimizelyAPIError} When entities retrieval fails * * @description This endpoint returns the entity parameters needed for calling the change history API * for Feature Experimentation projects. It's part of the two-step process for getting flag changes. * * @example * ```typescript * const entities = await api.getFlagEntities('12345', 45633994); * // Returns: [{ entity_ids: [123, 456], entity_type: "flag" }] * * // Use entities in change history call * for (const entityGroup of entities) { * const changes = await api.getChangeHistory(projectId, { * entity_ids: entityGroup.entity_ids, * entity_type: entityGroup.entity_type, * start_time: since.toISOString() * }); * } * ``` */ getFlagEntities(projectId: number | string, flagId: number | string): Promise<any[]>; /** * Creates a new feature flag in a project * @param projectId - The project ID to create the flag in * @param flagData - The flag configuration data including name, key, variations, etc. * @returns Promise resolving to created flag details * @throws {OptimizelyAPIError} When flag creation fails (e.g., duplicate key, invalid data) * * @example * ```typescript * const newFlag = await api.createFlag('12345', { * key: 'new_feature', * name: 'New Feature Flag', * variable_definitions: [ * { key: 'enabled', type: 'boolean', default_value: 'false' } * ] * }); * ``` */ createFlag(projectId: number | string, flagData: any): Promise<any>; /** * Updates an existing feature flag * @param projectId - The project ID containing the flag * @param flagKey - The flag key to update * @param updates - The updates to apply (partial flag data) * @returns Promise resolving to updated flag details * @throws {OptimizelyAPIError} When update fails (e.g., flag not found, invalid data) * * @example * ```typescript * const updatedFlag = await api.updateFlag('12345', 'feature_key', { * name: 'Updated Feature Name', * description: 'New description' * }); * ``` */ updateFlag(projectId: number | string, flagKey: string, updates: any): Promise<any>; getFlagEnvironmentRuleset(projectId: number | string, flagKey: string, environmentKey: string): Promise<any>; updateFlagEnvironmentRuleset(projectId: number | string, flagKey: string, environmentKey: string, rulesetData: any): Promise<any>; enableFlag(projectId: number | string, flagKey: string, environmentKey: string): Promise<any>; disableFlag(projectId: number | string, flagKey: string, environmentKey: string): Promise<any>; listExperiments(projectId: number | string, filters?: { per_page?: number; page?: number; archived?: boolean; }): Promise<any[]>; getExperiment(experimentId: number | string): Promise<any>; getExperimentResults(experimentId: number | string, filters?: { start_date?: string; end_date?: string; stats_config?: string; }): Promise<any>; listAudiences(projectId: number | string, filters?: { per_page?: number; page?: number; }): Promise<any[]>; getAudience(audienceId: number | string): Promise<any>; listAttributes(projectId: number | string, filters?: { per_page?: number; page?: number; }): Promise<any[]>; getAttribute(attributeId: number | string): Promise<any>; listEvents(projectId: number | string, filters?: { per_page?: number; page?: number; }): Promise<any[]>; getEvent(eventId: number | string): Promise<any>; getChangeHistory(projectId: number | string, filters?: { since?: string; until?: string; per_page?: number; page?: number; target_type?: string; entity_ids?: number[]; entity_type?: string; }): Promise<any[]>; getAllPages(fetchFunction: (page: number, perPage: number) => Promise<any[] | { data?: any[]; results?: any[]; items?: any[]; } | null>, options?: { maxPages?: number; perPage?: number; startPage?: number; delay?: number; retryAttempts?: number; }): Promise<any[]>; getProjectData(projectId: number | string, options?: ProjectDataOptions): Promise<any>; healthCheck(): Promise<any>; /** * Lists campaigns for a Web Experimentation project * @param projectId - Project ID to list campaigns for * @param params - Query parameters for filtering and pagination * @returns Promise resolving to campaign list response * @description Campaigns are groups of experiments that can share traffic allocation * and mutual exclusion rules. Available only for Web Experimentation projects. */ listCampaigns(projectId: string | number, params?: { page?: number; per_page?: number; archived?: boolean; }): Promise<any>; /** * Gets a specific campaign by ID * @param projectId - Project ID (for logging/context, but not used in URL per API docs) * @param campaignId - Campaign ID to retrieve * @returns Promise resolving to campaign details */ getCampaign(projectId: string | number, campaignId: string | number): Promise<any>; /** * Creates a new campaign in a Web Experimentation project * @param projectId - Project ID to create campaign in * @param campaignData - Campaign configuration * @returns Promise resolving to created campaign */ createCampaign(projectId: string | number, campaignData: { name: string; description?: string; holdback?: number; }): Promise<any>; /** * Updates an existing campaign * @param projectId - Project ID (for logging/context, but not used in URL per API docs) * @param campaignId - Campaign ID to update * @param campaignData - Updated campaign configuration * @returns Promise resolving to updated campaign */ updateCampaign(projectId: string | number, campaignId: string | number, campaignData: { name?: string; description?: string; holdback?: number; archived?: boolean; }): Promise<any>; /** * Deletes a campaign * @param projectId - Project ID (for logging/context, but not used in URL per API docs) * @param campaignId - Campaign ID to delete * @returns Promise resolving when deletion is complete */ deleteCampaign(projectId: string | number, campaignId: string | number): Promise<void>; /** * Archives a campaign * @param projectId - Project ID containing the campaign * @param campaignId - Campaign ID to archive * @returns Promise resolving to archived campaign */ archiveCampaign(projectId: string | number, campaignId: string | number): Promise<any>; /** * Gets campaign results/analytics * @param campaignId - Campaign ID to get results for * @param filters - Optional filters for the results * @returns Promise resolving to campaign results * @description Fetches analytics and performance data for a specific campaign. * This endpoint has a specific rate limit of 20 requests per minute. */ getCampaignResults(campaignId: string | number, filters?: { start_date?: string; end_date?: string; stats_config?: string; }): Promise<any>; /** * Lists segments for a Web Experimentation project * @param projectId - Project ID to list segments for * @param params - Query parameters for filtering and pagination * @returns Promise resolving to segment list response * @description Segments are reusable audience definitions that can be shared across experiments */ listSegments(projectId: string | number, params?: { page?: number; per_page?: number; archived?: boolean; }): Promise<any>; /** * Gets a specific segment by ID * @param segmentId - Segment ID to retrieve * @returns Promise resolving to segment details */ getSegment(segmentId: string | number): Promise<any>; /** * Creates a new segment in a Web Experimentation project * @param projectId - Project ID to create segment in * @param segmentData - Segment configuration * @returns Promise resolving to created segment */ createSegment(projectId: string | number, segmentData: { name: string; description?: string; conditions?: any; }): Promise<any>; /** * Updates an existing segment * @param segmentId - Segment ID to update * @param segmentData - Updated segment configuration * @returns Promise resolving to updated segment */ updateSegment(segmentId: string | number, segmentData: { name?: string; description?: string; conditions?: any; archived?: boolean; }): Promise<any>; /** * Deletes a segment * @param segmentId - Segment ID to delete * @returns Promise resolving when deletion is complete */ deleteSegment(segmentId: string | number): Promise<void>; /** * Lists reports for analytics and insights * @param projectId - Optional project ID to filter reports * @param params - Query parameters for filtering and pagination * @returns Promise resolving to report list response * @description Reports provide analytics and insights for experiments and campaigns */ listReports(projectId?: string | number, params?: { page?: number; per_page?: number; report_type?: string; }): Promise<any>; /** * Gets a specific report by ID * @param reportId - Report ID to retrieve * @returns Promise resolving to report details */ getReport(reportId: string | number): Promise<any>; /** * Creates a new report * @param reportData - Report configuration * @returns Promise resolving to created report */ createReport(reportData: { name: string; description?: string; report_type: string; project_id?: number; experiment_ids?: number[]; campaign_ids?: number[]; metrics?: any[]; filters?: any; }): Promise<any>; /** * Updates an existing report * @param reportId - Report ID to update * @param reportData - Updated report configuration * @returns Promise resolving to updated report */ updateReport(reportId: string | number, reportData: { name?: string; description?: string; metrics?: any[]; filters?: any; }): Promise<any>; /** * Deletes a report * @param reportId - Report ID to delete * @returns Promise resolving when deletion is complete */ deleteReport(reportId: string | number): Promise<void>; /** * Lists pages with pagination support * @param projectId - Project ID to filter pages for (required as query parameter) * @param params - Query parameters for pagination and filtering * @returns Promise resolving to page list * @description Pages define URL targeting and activation rules for experiments. * The Pages API supports pagination with per_page, page, and project_id parameters. */ listPages(projectId?: string | number, params?: { page?: number; per_page?: number; archived?: boolean; }): Promise<any>; /** * Gets a specific page by ID * @param pageId - Page ID to retrieve * @returns Promise resolving to page details */ getPage(pageId: string | number): Promise<any>; /** * Creates a new page in a Web Experimentation project * @param projectId - Project ID to create page in * @param pageData - Page configuration * @returns Promise resolving to created page */ createPage(projectId: string | number, pageData: { name: string; edit_url?: string; conditions?: any; activation_type?: string; activation_code?: string; }): Promise<any>; /** * Updates an existing page * @param pageId - Page ID to update * @param pageData - Updated page configuration * @returns Promise resolving to updated page */ updatePage(pageId: string | number, pageData: { name?: string; edit_url?: string; conditions?: any; activation_type?: string; activation_code?: string; archived?: boolean; key?: string; category?: string; page_type?: string; [key: string]: any; }): Promise<any>; /** * Deletes a page * @param pageId - Page ID to delete * @returns Promise resolving when deletion is complete */ deletePage(pageId: string | number): Promise<void>; /** * Archives a page * @param pageId - Page ID to archive * @returns Promise resolving to archived page */ archivePage(pageId: string | number): Promise<any>; /** * Lists rules within a ruleset * @param projectId - Project ID containing the flag * @param flagKey - Flag key to get rules for * @param environmentKey - Environment key to get rules from * @returns Promise resolving to list of rules */ listRules(projectId: string | number, flagKey: string, environmentKey: string): Promise<any[]>; /** * Gets a specific rule by ID * @param projectId - Project ID containing the flag * @param flagKey - Flag key containing the rule * @param environmentKey - Environment key containing the rule * @param ruleId - Rule ID to retrieve * @returns Promise resolving to rule details */ getRule(projectId: string | number, flagKey: string, environmentKey: string, ruleId: string | number): Promise<any>; /** * Deletes a feature flag * @param projectId - The project ID containing the flag * @param flagKey - The flag key to delete * @returns Promise resolving when deletion is complete * @throws {OptimizelyAPIError} When deletion fails */ deleteFlag(projectId: number | string, flagKey: string): Promise<void>; /** * Updates multiple flags in bulk using PATCH format * @param projectId - The project ID containing the flags * @param flagsData - Array of flag update objects or JSON patch operations * @returns Promise resolving to bulk update result * @throws {OptimizelyAPIError} When bulk update fails * @example * ```typescript * const updates = [ * { key: 'flag1', name: 'Updated Flag 1' }, * { key: 'flag2', archived: true } * ]; * const result = await api.updateFlags('12345', updates); * ``` */ updateFlags(projectId: number | string, patchOperations: any[]): Promise<any>; /** * Archives multiple flags in bulk * @param projectId - The project ID containing the flags * @param flagKeys - Array of flag keys to archive * @returns Promise resolving to bulk archive result * @throws {OptimizelyAPIError} When bulk archive fails * @example * ```typescript * const flagKeys = ['flag1', 'flag2', 'flag3']; * const result = await api.archiveFlags('12345', flagKeys); * ``` */ archiveFlags(projectId: number | string, flagKeys: string[]): Promise<any>; /** * Gets environment details for Feature Experimentation * @param projectId - Project ID containing the environment * @param environmentKey - Environment key to retrieve * @returns Promise resolving to environment details * @deprecated This endpoint doesn't exist in the Feature Experimentation API. * Use listEnvironments() and filter by key instead. */ getEnvironment(projectId: string | number, environmentKey: string): Promise<any>; /** * Updates a flag environment ruleset * @param projectId - Project ID containing the flag * @param flagKey - Flag key to update * @param environmentKey - Environment key to update * @param rulesetData - New ruleset configuration * @returns Promise resolving to updated ruleset */ updateRuleset(projectId: string | number, flagKey: string, environmentKey: string, rulesetData: any): Promise<any>; /** * Enables a flag ruleset in an environment * @param projectId - Project ID containing the flag * @param flagKey - Flag key to enable * @param environmentKey - Environment key to enable in * @returns Promise resolving when enabled */ enableRuleset(projectId: string | number, flagKey: string, environmentKey: string): Promise<void>; /** * Disables a flag ruleset in an environment * @param projectId - Project ID containing the flag * @param flagKey - Flag key to disable * @param environmentKey - Environment key to disable in * @returns Promise resolving when disabled */ disableRuleset(projectId: string | number, flagKey: string, environmentKey: string): Promise<void>; /** * Gets the change history for a specific flag * @param projectId - Project ID containing the flag * @param flagKey - Flag key to get history for * @param filters - Optional filters for the history * @returns Promise resolving to array of change records */ getFlagHistory(projectId: string | number, flagKey: string, filters?: { start_time?: string; end_time?: string; page?: number; per_page?: number; }): Promise<any[]>; /** * Gets the change history for a Feature Experimentation project * @param projectId - Project ID to get history for * @param filters - Optional filters for the history * @returns Promise resolving to array of change records */ getProjectHistory(projectId: string | number, filters?: { start_time?: string; end_time?: string; entity_type?: string; page?: number; per_page?: number; }): Promise<any[]>; /** * Lists all features in a project (Feature Experimentation only) * @param projectId - The project ID to list features from * @param filters - Optional filters including pagination * @returns Promise resolving to array of features * @throws {OptimizelyAPIError} When API request fails * @example * ```typescript * // Get all features * const features = await api.listFeatures('12345'); * * // Get features with pagination * const features = await api.listFeatures('12345', { page: 2, per_page: 50 }); * ``` */ listFeatures(projectId: number | string, filters?: { per_page?: number; page?: number; }): Promise<any>; /** * Gets a specific feature by ID * @param featureId - The feature ID to retrieve * @returns Promise resolving to feature details * @throws {OptimizelyAPIError} When feature not found or API request fails * @example * ```typescript * const feature = await api.getFeature('feature_123'); * ``` */ getFeature(featureId: number | string): Promise<any>; /** * Creates a new feature in a project * @param featureData - The feature data including project_id, key, name, etc. * @returns Promise resolving to created feature details * @throws {OptimizelyAPIError} When creation fails * @example * ```typescript * const feature = await api.createFeature({ * project_id: 12345, * key: 'new_feature', * name: 'New Feature', * description: 'A new feature for testing', * variable_definitions: [ * { key: 'enabled', type: 'boolean', default_value: 'false' } * ] * }); * ``` */ createFeature(featureData: any): Promise<any>; /** * Updates an existing feature * @param featureId - The feature ID to update * @param featureData - The updates to apply (partial feature data) * @returns Promise resolving to updated feature details * @throws {OptimizelyAPIError} When update fails * @example * ```typescript * const updated = await api.updateFeature('feature_123', { * name: 'Updated Feature Name', * description: 'Updated description' * }); * ``` */ updateFeature(featureId: number | string, featureData: any): Promise<any>; /** * Deletes a feature from a project * @param featureId - The feature ID to delete * @returns Promise resolving when deletion completes * @throws {OptimizelyAPIError} When deletion fails * @example * ```typescript * await api.deleteFeature('feature_123'); * ``` */ deleteFeature(featureId: number | string): Promise<void>; /** * Creates a new feature variable * @param featureId - The feature ID to add the variable to * @param variableData - The variable configuration data * @returns Promise resolving to created feature variable details * @throws {OptimizelyAPIError} When creation fails * @example * ```typescript * const variable = await api.createFeatureVariable('feature_123', { * key: 'discount_percentage', * type: 'integer', * default_value: '10', * description: 'Default discount percentage' * }); * ``` */ createFeatureVariable(featureId: number | string, variableData: any): Promise<any>; /** * Updates an existing feature variable * @param featureId - The feature ID containing the variable * @param variableId - The variable ID to update * @param variableData - The updates to apply (partial variable data) * @returns Promise resolving to updated feature variable details * @throws {OptimizelyAPIError} When update fails * @example * ```typescript * const updated = await api.updateFeatureVariable('feature_123', 'variable_456', { * default_value: '20', * description: 'Updated discount percentage' * }); * ``` */ updateFeatureVariable(featureId: number | string, variableId: number | string, variableData: any): Promise<any>; /** * Deletes a feature variable * @param featureId - The feature ID containing the variable * @param variableId - The variable ID to delete * @returns Promise resolving when deletion completes * @throws {OptimizelyAPIError} When deletion fails * @example * ```typescript * await api.deleteFeatureVariable('feature_123', 'variable_456'); * ``` */ deleteFeatureVariable(featureId: number | string, variableId: number | string): Promise<void>; /** * Gets a specific rule by key (Feature Experimentation) * @param projectId - Project ID containing the flag * @param flagKey - Flag key containing the rule * @param environmentKey - Environment key containing the rule * @param ruleKey - Rule key to retrieve * @returns Promise resolving to rule details */ getRuleByKey(projectId: string | number, flagKey: string, environmentKey: string, ruleKey: string): Promise<any>; /** * Creates a new rule for a specific flag in an environment * @param projectId - Project ID * @param flagKey - Flag key containing the rule * @param environmentKey - Environment key containing the rule * @param ruleData - Rule configuration data * @returns Promise resolving to created rule details * @description Creates a new rule with targeting conditions and variations for a feature flag. * Rules determine which users see which variations of a feature flag. */ createRule(projectId: string | number, flagKey: string, environmentKey: string, ruleData: any): Promise<any>; /** * Updates an existing rule for a specific flag in an environment * @param projectId - Project ID * @param flagKey - Flag key containing the rule * @param environmentKey - Environment key containing the rule * @param ruleKey - Rule key to update * @param ruleData - Updated rule configuration data * @returns Promise resolving to updated rule details * @description Updates rule targeting conditions, variations, or other configuration. * Changes to rules affect which users see which variations of a feature flag. */ updateRule(projectId: string | number, flagKey: string, environmentKey: string, ruleKey: string, ruleData: any): Promise<any>; /** * Deletes a rule for a specific flag in an environment * @param projectId - Project ID * @param flagKey - Flag key containing the rule * @param environmentKey - Environment key containing the rule * @param ruleKey - Rule key to delete * @returns Promise resolving when deletion is complete * @description Removes a rule from a feature flag environment. * Users previously targeted by this rule will fall through to subsequent rules or default behavior. */ deleteRule(projectId: string | number, flagKey: string, environmentKey: string, ruleKey: string): Promise<void>; /** * Lists variations for a specific flag * @param projectId - Project ID * @param flagKey - Flag key * @returns Promise resolving to array of variations * @description Variations define the different states/values a feature flag can have. * Each variation represents a possible configuration that users can be assigned to. */ listVariations(projectId: string | number, flagKey: string): Promise<any[]>; /** * Creates a new variation for a flag * @param projectId - Project ID * @param flagKey - Flag key * @param variationData - Variation configuration * @returns Promise resolving to created variation * @description Creates a new variation option for a feature flag. * Variations allow different configurations to be tested or rolled out. */ createVariation(projectId: string | number, flagKey: string, variationData: { key: string; name: string; description?: string; variables?: Record<string, any>; variable_values?: Record<string, any>; feature_enabled?: boolean; weight?: number; }): Promise<any>; /** * Updates variations for a flag using JSON patch * @param projectId - Project ID * @param flagKey - Flag key * @param patchData - JSON patch operations * @returns Promise resolving to updated variations * @description Updates one or more variations using JSON patch format. * Allows partial updates to variation configurations. */ updateVariations(projectId: string | number, flagKey: string, patchData: any[]): Promise<any>; /** * Archives variations for a flag * @param projectId - Project ID * @param flagKey - Flag key * @param variationKeys - Array of variation keys to archive * @returns Promise resolving when variations are archived * @description Archives one or more variations, removing them from active use. * Archived variations cannot be assigned to users. */ archiveVariations(projectId: string | number, flagKey: string, variationKeys: string[]): Promise<any>; /** * Gets a specific variation by key * @param projectId - Project ID * @param flagKey - Flag key * @param variationKey - Variation key to retrieve * @returns Promise resolving to variation details * @description Retrieves details for a specific variation by its key. * Includes configuration, variables, and metadata. */ getVariation(projectId: string | number, flagKey: string, variationKey: string): Promise<any>; /** * Deletes a specific variation by key * @param projectId - Project ID * @param flagKey - Flag key * @param variationKey - Variation key to delete * @returns Promise resolving when variation is deleted * @description Permanently deletes a variation from a feature flag. * This operation cannot be undone. */ deleteVariation(projectId: string | number, flagKey: string, variationKey: string): Promise<void>; /** * Lists all variable definitions for a flag * @param projectId - Project ID containing the flag * @param flagKey - Flag key to get variable definitions for * @param params - Optional pagination and filtering parameters * @returns Promise resolving to paginated response with variable definitions */ listVariableDefinitions(projectId: string | number, flagKey: string, params?: { page?: number; per_page?: number; }): Promise<{ count: number; items: Array<{ key: string; type: string; default_value: any; description?: string; revision: number; role: string; }>; total_count: number; total_pages: number; page: number; first_url?: string; last_url?: string; next_url?: string; prev_url?: string[]; }>; /** * Creates a new variable definition for a flag * @param projectId - Project ID containing the flag * @param flagKey - Flag key to create variable definition for * @param variableData - Variable definition data * @returns Promise resolving to created variable definition */ createVariableDefinition(projectId: string | number, flagKey: string, variableData: { key: string; type: string; default_value: any; description?: string; }): Promise<{ key: string; type: string; default_value: any; description?: string; }>; /** * Updates variable definitions using JSON Patch format * @param projectId - Project ID containing the flag * @param flagKey - Flag key to update variable definitions for * @param patchOperations - JSON Patch operations array * @returns Promise resolving to updated variable definitions (paginated response) */ updateVariableDefinitions(projectId: string | number, flagKey: string, patchOperations: Array<{ op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test'; path: string; value?: any; from?: string; }>): Promise<{ count: number; items: Array<{ key: string; type: string; default_value: any; description?: string; revision: number; role: string; }>; total_count: number; total_pages: number; page: number; }>; /** * Gets a specific variable definition by key * @param projectId - Project ID containing the flag * @param flagKey - Flag key containing the variable definition * @param variableDefinitionKey - Variable definition key to retrieve * @returns Promise resolving to variable definition */ getVariableDefinition(projectId: string | number, flagKey: string, variableDefinitionKey: string): Promise<{ key: string; type: string; default_value: any; description?: string; revision: number; role: string; }>; /** * Deletes a variable definition * @param projectId - Project ID containing the flag * @param flagKey - Flag key containing the variable definition * @param variableDefinitionKey - Variable definition key to delete * @returns Promise resolving when deletion is complete */ deleteVariableDefinition(projectId: string | number, flagKey: string, variableDefinitionKey: string): Promise<void>; /** * Uses AI to brainstorm variable definitions for a flag * @param projectId - Project ID containing the flag * @param flagKey - Flag key to brainstorm variable definitions for * @param prompt - Description or prompt for AI brainstorming * @returns Promise resolving to AI brainstorm interactions */ brainstormVariableDefinitions(projectId: string | number, flagKey: string, prompt: string): Promise<{ interactions: Array<any>; }>; /** * Lists all collaborators for a project * @param projectId - Project ID to list collaborators for * @param params - Optional pagination parameters * @returns Promise resolving to array of collaborators */ listCollaborators(projectId: string | number, params?: { page?: number; per_page?: number; }): Promise<any[]>; /** * Adds a collaborator to a project * @param projectId - Project ID to add collaborator to * @param collaboratorData - Collaborator data including email and role * @returns Promise resolving to added collaborator */ addCollaborator(projectId: string | number, collaboratorData: { email: string; role?: string; }): Promise<any>; /** * Gets a specific collaborator from a project * @param projectId - Project ID containing the collaborator * @param userId - User ID of collaborator to retrieve * @returns Promise resolving to collaborator details */ getCollaborator(projectId: string | number, userId: string | number): Promise<any>; /** * Removes a collaborator from a project * @param projectId - Project ID to remove collaborator from * @param userId - User ID of collaborator to remove * @returns Promise resolving when deletion is complete */ removeCollaborator(projectId: string | number, userId: string | number): Promise<void>; /** * Lists all groups * @param params - Optional query parameters * @returns Promise resolving to array of groups */ listGroups(params?: { page?: number; per_page?: number; project_id?: string | number; }): Promise<any[]>; /** * Gets a specific group by ID * @param groupId - Group ID to retrieve * @returns Promise resolving to group object */ getGroup(groupId: string | number): Promise<any>; /** * Creates a new group * @param groupData - Group configuration * @returns Promise resolving to created group */ createGroup(groupData: { project_id: string | number; name: string; description?: string; policy?: string; traffic_allocation?: number; }): Promise<any>; /** * Updates an existing group * @param groupId - Group ID to update * @param groupData - Updated group configuration * @returns Promise resolving to updated group */ updateGroup(groupId: string | number, groupData: { name?: string; description?: string; policy?: string; traffic_allocation?: number; archived?: boolean; }): Promise<any>; /** * Deletes a group * @param groupId - Group ID to delete * @returns Promise resolving when deletion is complete */ deleteGroup(groupId: string | number): Promise<void>; /** * Lists all list attributes * @param projectId - Optional project ID to filter by * @param params - Optional pagination and filtering parameters * @returns Promise resolving to array of list attributes */ listListAttributes(projectId?: string | number, params?: { page?: number; per_page?: number; }): Promise<any[]>; /** * Gets a specific list attribute by ID * @param listAttributeId - List attribute ID to retrieve * @returns Promise resolving to list attribute object */ getListAttribute(listAttributeId: string | number): Promise<any>; /** * Creates a new list attribute * @param listAttributeData - List attribute data * @returns Promise resolving to created list attribute */ createListAttribute(listAttributeData: { name: string; list_type: string; key_field: string; description?: string; list_content?: any; }): Promise<any>; /** * Updates an existing list attribute * @param listAttributeId - List attribute ID to update * @param updateData - Updated list attribute data * @returns Promise resolving to updated list attribute */ updateListAttribute(listAttributeId: string | number, updateData: { name?: string; list_type?: string; key_field?: string; description?: string; list_content?: any; }): Promise<any>; /** * Deletes a list attribute * @param listAttributeId - List attribute ID to delete * @returns Promise resolving when deletion is complete */ deleteListAttribute(listAttributeId: string | number): Promise<void>; /** * Bulk upload items to a list attribute * @param listAttributeId - List attribute ID to upload items to * @param items - Array of items to bulk upload * @returns Promise resolving to upload response */ uploadListItems(listAttributeId: string | number, items: any[]): Promise<any>; /** * List all extensions in a project * @param projectId - The project ID * @param params - Query parameters for pagination * @returns Promise resolving to array of extension objects */ listExtensions(projectId: string | number, params?: { page?: number; per_page?: number; }): Promise<any[]>; /** * Get a specific extension by ID * @param extensionId - The extension ID * @returns Promise resolving to the extension object */ getExtension(extensionId: string | number): Promise<any>; /** * Create a new extension in a project * @param projectId - The project ID * @param extensionData - Extension data including name, implementation, enabled * @returns Promise resolving to the created extension object */ createExtension(projectId: string | number, extensionData: { name: string; implementation: string; enabled: boolean; description?: string;