import type { ServiceResult } from '../models/service-result.js'; import type { UserReadiness } from './UserReadinessService.js'; import type { UserConfig, DeploymentResult, DeploymentStatus, UserConfigurationResult, IUserConfigurationServiceConfig } from './UserConfigurationTypes.js'; export { CONFIGURABLE_PERMISSION_SETS } from './UserConfigurationTypes.js'; export type { UserConfig, DeploymentResult, DeploymentStatus, ConfigurationState, ConfigurationAction, UserConfigurationResult, IUserConfigurationServiceConfig, } from './UserConfigurationTypes.js'; /** * Service for checking and updating user-level Cuneiform configuration. * * Provides methods to query current configuration profiles and trigger * CMT updates via the ISV REST endpoint. Permission set assignment is * handled via REST sObject insert. * * Configure and unconfigure workflows are delegated to {@link ConfigureMode} * and {@link UnconfigureMode} respectively. * * @example * ```typescript * const service = new UserConfigurationService({ * soqlAdapter, * restApiAdapter, * }); * * // Check current config * const config = await service.getCurrentConfig(userId); * if (config.success && !config.data.apiOnlyProfilingEnabled) { * // Enable API-only profiling * const result = await service.enableApiOnlyProfiling('Production'); * if (result.success && result.data.jobId) { * // Check deployment status * const status = await service.getDeploymentStatus(result.data.jobId); * } * } * ``` */ export declare class UserConfigurationService { private readonly soqlAdapter; private readonly restApiAdapter; private readonly userReadinessService?; private readonly logger?; /** Configure mode handler (lazy-initialized when userReadinessService is available) */ private configureMode?; /** Unconfigure mode handler (lazy-initialized when userReadinessService is available) */ private unconfigureMode?; constructor(config: IUserConfigurationServiceConfig); /** * Checks if an error message indicates Cuneiform namespace is not found. * * This typically means the Cuneiform for Salesforce package is not installed in the org. */ private static isCuneiformNamespaceNotFoundError; /** * Creates an empty UserConfig result for error cases. */ private static createEmptyConfig; /** * Retrieves the current Cuneiform configuration for a user. * * Queries the Active Configuration CMT to get the linked Configuration Profile * and its settings. Returns empty config if Cuneiform is not installed. * * @param userId - The Salesforce user ID (for context, not filtered) * @returns ServiceResult containing UserConfig */ getCurrentConfig(userId: string): Promise>; /** * Enables API-only profiling for a configuration profile. * * Triggers a CMT configuration update via the ISV REST endpoint. * Returns the deployment job ID for status tracking. * * @param profileDeveloperName - The developer name of the Configuration Profile to update * @returns ServiceResult containing DeploymentResult with job ID */ enableApiOnlyProfiling(profileDeveloperName: string): Promise>; /** * Retrieves the status of a CMT deployment job. * * Queries the DeployRequest object to check deployment progress. * * @param jobId - The deployment job ID to check * @returns ServiceResult containing DeploymentStatus */ getDeploymentStatus(jobId: string): Promise>; /** * Polls for CMT deployment completion with exponential backoff. * * Waits for a metadata deployment to reach a terminal state (Succeeded, Failed, or Canceled). * Uses exponential backoff starting at 1s, capped at 5s, with a maximum total wait of 30s. * * @param jobId - The deployment job ID to monitor * @returns ServiceResult containing the final DeploymentStatus */ waitForDeploymentCompletion(jobId: string): Promise>; /** * Retrieves the ID of a permission set by name and namespace. * * Queries the PermissionSet object to find the permission set ID. This is * needed before assigning a permission set to a user via PermissionSetAssignment. * * @param name - The permission set API name (e.g., 'Cuneiform_for_CRM_Global_Profiling_Support') * @param namespace - The namespace prefix (e.g., 'pnova') * @returns ServiceResult containing the permission set ID or null if not found */ getPermissionSetId(name: string, namespace: string): Promise>; /** * Orchestrates user configuration for Cuneiform operations. * * Delegates to {@link ConfigureMode} for the full configure workflow. * See ConfigureMode for implementation details. * * @param userId - The Salesforce user ID to configure * @param options - Configuration options * @param options.dryRun - If true, reports planned changes without applying them (default: false) * @param options.readiness - Pre-fetched user readiness snapshot. When provided, configure reuses it instead of issuing its own checkReadiness call — guaranteeing agreement between the caller's display and previousState. Mirrors the cached-data parameter pattern at OrgInfoService.ts:1316-1318. * @returns ServiceResult containing UserConfigurationResult with actions taken/skipped/failed */ configure(userId: string, options?: { dryRun?: boolean; readiness?: UserReadiness; }): Promise>; /** * Orchestrates user unconfiguration — reverses the actions of configure(). * * Delegates to {@link UnconfigureMode} for the full unconfigure workflow. * See UnconfigureMode for implementation details. * * @param userId - The Salesforce user ID to unconfigure * @returns ServiceResult containing UserConfigurationResult with actions taken/skipped/failed */ unconfigure(userId: string): Promise>; /** * Disables API-only profiling for a configuration profile. * * Triggers a CMT configuration update via the ISV REST endpoint to set * Enable_API_Only_Profiling__c to false. Uses the same deployment * pattern as enableApiOnlyProfiling(). * * @param profileDeveloperName - The developer name of the Configuration Profile to update * @returns ServiceResult containing DeploymentResult with job ID */ disableApiOnlyProfiling(profileDeveloperName: string): Promise>; /** * Deploys a CMT configuration update via the ISV REST endpoint and returns * the result including any jobId from the response. * * On 404 (endpoint not available), returns a graceful error explaining that * an ISV upgrade is needed. * * @param profileDeveloperName - The developer name of the Configuration Profile to update * @param enableApiOnlyProfiling - Whether to enable (true) or disable (false) API-only profiling * @returns ServiceResult containing DeploymentResult with job ID */ private deployCmtViaRest; /** * Validates dependencies required for configure()/unconfigure() methods. */ private validateConfigureDependencies; }