import type { ISoqlQueryAdapter } from '../adapters/soql/soql-query-adapter.js'; import type { IRestApiAdapter } from '../adapters/rest/rest-api-adapter.js'; import type { ServiceResult } from '../models/service-result.js'; import type { IProfileRequest, ProfileRequestListOptions, ProfileRequestCancelOptions, ProfileRequestCancelResult, ProfileRequestDeleteOptions, ProfileRequestDeleteResult } from '../models/profile-request-types.js'; /** * Configuration for ProfileRequestService. */ export type IProfileRequestServiceConfig = { /** SOQL query adapter for reading request records */ soqlAdapter: ISoqlQueryAdapter; /** REST API adapter for updating request records */ restAdapter: IRestApiAdapter; /** Optional logger for debug output */ logger?: Console; }; /** * Service for managing profiling request records (pnova__Profiling_Request__c). * * Provides operations to list profiling requests with filtering and pagination, * and to cancel queued or in-progress requests. All methods return ServiceResult * with duration metadata. * * @design * **Query Pattern**: Uses CuneiformQueryBuilder for type-safe SOQL construction * with status filtering and pagination support. * * @design * **Cancel Strategy**: Cancellation updates each request's status to 'Canceled' * via the REST adapter. Partial failures are tracked and reported with E4905. * * @example * ```typescript * const service = new ProfileRequestService({ soqlAdapter, restAdapter }); * const listResult = await service.listRequests({ status: 'Queued', limit: 10 }); * const cancelResult = await service.cancelRequests({ all: true, dryRun: true }); * ``` */ export declare class ProfileRequestService { private readonly soqlAdapter; private readonly restAdapter; private readonly logger?; constructor(config: IProfileRequestServiceConfig); /** * Maps a raw Salesforce record to the IProfileRequest domain type. * * @param record - Raw SOQL query result record * @returns Mapped IProfileRequest */ private static mapRecord; /** * Builds a SOQL query for profiling requests with optional status filter and pagination. * * @param options - Filtering and pagination options * @returns SOQL query string */ private static buildListQuery; /** * Builds a SOQL query to find cancellable requests, optionally filtered by IDs. * * @param requestIds - Optional specific IDs to filter by * @returns SOQL query string */ private static buildCancellableQuery; /** * Creates an empty cancel result for error/validation responses. * * @param dryRun - Whether this was a dry run * @returns Empty ProfileRequestCancelResult */ private static emptyCancelResult; /** * Validates cancel request options for mutual exclusivity and ID format. * * @param options - The cancel options to validate * @param emptyResult - Empty result for failure responses * @param startTime - Operation start time for duration tracking * @returns Failure ServiceResult if invalid, undefined if valid */ private static validateCancelOptions; /** * Builds a SOQL query to find deletable requests, optionally filtered by IDs. * * Deletable requests are those in 'Canceled' or 'Rejected' status. * These never produced a summary and are safe to delete. * * @param requestIds - Optional specific IDs to filter by * @returns SOQL query string */ private static buildDeletableQuery; /** * Creates an empty delete result for error/validation responses. * * @param dryRun - Whether this was a dry run * @returns Empty ProfileRequestDeleteResult */ private static emptyDeleteResult; /** * Validates delete request options for mutual exclusivity and ID format. * * @param options - The delete options to validate * @param emptyResult - Empty result for failure responses * @param startTime - Operation start time for duration tracking * @returns Failure ServiceResult if invalid, undefined if valid */ private static validateDeleteOptions; /** * List profiling requests with optional filtering and pagination. * * Queries pnova__Profiling_Request__c records via SOQL with support for * status filtering (single or multiple values) and pagination controls. * * @param options - Optional filtering and pagination settings * @returns ServiceResult containing an array of IProfileRequest */ listRequests(options?: ProfileRequestListOptions): Promise>; /** * Cancel profiling requests by IDs or all cancellable requests. * * Supports three modes: * 1. `all: true` - Cancel all requests in Queued status * 2. `requestIds: [...]` - Cancel specific requests (must be in cancellable status) * 3. `dryRun: true` - Preview what would be cancelled without making changes * * @param options - Cancel options specifying which requests to cancel * @returns ServiceResult containing the cancel operation results */ cancelRequests(options: ProfileRequestCancelOptions): Promise>; /** * Delete profiling requests by IDs or all deletable requests. * * Supports three modes: * 1. `all: true` - Delete all requests in Canceled/Rejected status * 2. `requestIds: [...]` - Delete specific requests (must be in Canceled/Rejected status) * 3. `dryRun: true` - Preview what would be deleted without making changes * * Uses the ISV bulk REST endpoint (`DELETE /v1/profiling/requests?ids=...`) for * the actual deletion. IDs are passed via query params because jsforce strips * the body from DELETE requests (RFC 7231 defines no semantics for DELETE payloads). * * This is an irreversible operation. * * @param options - Delete options specifying which requests to delete * @returns ServiceResult containing the delete operation results */ deleteRequests(options: ProfileRequestDeleteOptions): Promise>; /** * Executes cancellation via the Cuneiform REST API cancel-requests action. * Direct DML is blocked by a trigger guard on Profiling_Request__c; * cancellation must go through GlobalProfilingService.cancelProfilingRequests(). * * @param requests - The mapped requests to cancel * @returns Object with cancelled and failed arrays */ private executeCancellations; /** * Builds the final cancel result based on update outcomes. * * @param cancelled - Successfully cancelled requests * @param failed - Requests that failed to cancel * @param totalCancellable - Total number of cancellable requests found * @param duration - Operation duration in milliseconds * @returns ServiceResult with appropriate error code for partial/total failure */ private buildCancelResult; /** * Calls the ISV REST endpoint to delete profiling requests in bulk. * * IDs are passed via query params instead of request body because RFC 7231 * defines no semantics for DELETE payloads, and jsforce's transport layer * strips the body for DELETE requests — causing the call to hang indefinitely. * * @param requestIds - Array of request IDs to delete (max 200, ISV backend limit) * @returns ServiceResult containing the raw ISV API response */ private executeIsvDelete; /** * Builds the final delete result by correlating ISV API response items * with the queried IProfileRequest objects. * * @param apiResponse - Raw ISV API response * @param queriedRequests - Full IProfileRequest objects from SOQL * @param duration - Operation duration in milliseconds * @returns ServiceResult with rich delete result */ private buildDeleteResult; }