UNPKG

sfdx-hardis

Version:

Swiss-army-knife Toolbox for Salesforce. Allows you to define a complete CD/CD Pipeline. Orchestrate base commands and assist users with interactive wizards

104 lines (103 loc) 7.01 kB
import { SfCommand } from '@salesforce/sf-plugins-core'; export default class ProfilesExtract extends SfCommand<void> { static readonly description = "\n## Command Behavior\n\n**Guides administrators through extracting Salesforce profiles, personas, and related metadata into structured CSV/XLSX deliverables.**\n\nThe command inventories SObjects that contain data, lets the user pick the ones to document, and then produces persona-centric spreadsheets that cover users, personas, relationships, record types, apps, permissions, tabs, fields, and permission sets. The output consolidates everything into both CSV files and a single Excel workbook, making it easy to audit access models or prepare remediation plans.\n\nKey capabilities:\n\n- **Interactive object discovery:** Lists queryable objects with records and allows multi-selection.\n- **Persona modeling:** Lets users define the number of personas and generates cross-object matrices that leverage Excel formulas for faster updates.\n- **Comprehensive metadata export:** Captures users, record types, apps, permissions, tabs, fields, and permission sets with persona/profile visibility indicators.\n- **Profile field access coverage:** Retrieves FieldPermissions to surface read/edit status per profile and field.\n- **Consolidated reporting:** Produces standalone CSVs plus an aggregated XLSX stored in the report directory.\n\n<details markdown=\"1\">\n<summary>Technical explanations</summary>\n\n- **Salesforce connectivity:** Uses the requested target org connection from `Flags.requiredOrg` to fetch metadata and records.\n- **Bulk/REST queries:** Relies on `bulkQuery` and standard SOQL to evaluate record counts and pull FieldPermissions, Users, RecordTypes, Applications, Tabs, and PermissionSets.\n- **Describe calls:** Invokes `describeGlobal` and `describeSObject` to enumerate objects and field-level metadata, including picklists and formulas.\n- **Prompt-driven input:** Utilizes the shared `prompts` utility to collect object selections and persona counts, ensuring consistent CLI UX.\n- **Reporting pipeline:** Writes intermediate CSV files via `generateCsvFile`, stores them under the report directory from `getReportDirectory`, and finally merges them using `createXlsxFromCsvFiles`.\n- **Logging & diagnostics:** Uses `uxLog` with chalk coloring for progress, warnings, and debug output, integrating with the project-wide logging style.\n\n</details>\n"; static readonly examples: string[]; static readonly flags: { 'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>; debug: import("@oclif/core/interfaces").BooleanFlag<boolean>; websocket: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>; skipauth: import("@oclif/core/interfaces").BooleanFlag<boolean>; }; protected csvFiles: string[]; protected outputFile: string; protected activeProfileNames: Set<string>; /** * Main entry point for the command. Orchestrates the extraction process: * - Prompts user to select objects * - Extracts users, personas, relations, record types, apps, permissions, tabs, and object fields * - Generates CSV and XLSX reports */ run(): Promise<void>; /** * Extracts field-level access for profiles using FieldPermissions object. * Generates a CSV report of profile-field access. * @param conn Salesforce connection */ getProfileFieldAccessData(conn: any, selectedObjects: string[]): Promise<{ Profile: string; SObjectType: string; Field: string; PermissionsRead: string; PermissionsEdit: string; }[]>; /** * Prompts the user to select Salesforce objects (SObjects) that have records in the org. * Generates a CSV report of the selected objects. * @param conn Salesforce connection * @returns Array of selected object API names */ private generateObjectsList; /** * Extracts active users from the org, including their username, role, and profile. * Generates a CSV report of users. * @param conn Salesforce connection */ generateUsersExtract(conn: any): Promise<void>; /** * Prompts the user for the number of personas to create. * Generates a CSV report listing the personas. * @returns The number of personas */ private generatePersonaExtract; /** * Generates a CSV mapping each selected object to persona permissions (Read, Create, Edit, Delete). * @param selectedObjects Array of object API names * @param numberOfPersonas Number of personas */ generateRelationExtract(selectedObjects: string[], numberOfPersonas: number): Promise<void>; /** * Extracts record types for each selected object and maps persona access (Active, Default). * Generates a CSV report of record types per object. * @param conn Salesforce connection * @param selectedObjects Array of object API names * @param numberOfPersonas Number of personas */ generateRTExtract(conn: any, selectedObjects: string[], numberOfPersonas: number): Promise<void>; /** * Extracts custom applications (AppDefinition) and maps persona access (Active, Default). * Generates a CSV report of applications. * @param conn Salesforce connection * @param numberOfPersonas Number of personas */ generateAppsExtract(conn: any, numberOfPersonas: number): Promise<void>; /** * Extracts all boolean permission fields from PermissionSet object. * Generates a CSV report mapping each permission to personas. * @param conn Salesforce connection * @param numberOfPersonas Number of personas */ generatePermissionsExtract(conn: any, numberOfPersonas: number): Promise<void>; /** * Extracts custom tabs and maps persona access. * Generates a CSV report of tabs. * @param conn Salesforce connection * @param numberOfPersonas Number of personas */ generateTabsExtract(conn: any, numberOfPersonas: number): Promise<void>; /** * For each selected object, extracts all fields and their metadata (label, type, picklist values, etc.). * Maps persona visibility and read-only status for each field. * Generates a CSV report per object. * @param conn Salesforce connection * @param selectedObjects Array of object API names * @param numberOfPersonas Number of personas */ generateObjectFieldsExtract(conn: any, selectedObjects: string[], numberOfPersonas: number, profileNames?: string[], profileFieldAccess?: any[]): Promise<void>; /** * Extracts all Permission Sets in the org. * Generates a CSV report mapping each permission set to personas. * @param conn * @param numberOfPersonas */ generatePermissionSetsExtract(conn: any, numberOfPersonas: number): Promise<void>; }