@simplysf/simply-permissions-core
v0.11.1
Published
Permission set generation, permission set XML, and permissions report rendering — the library layer behind @simplysf/simply-permissions, published separately for direct consumption (e.g. editor tooling, CI scripts) without the CLI framework
Readme
@simplysf/simply-permissions-core
Permission set generation from source metadata, permission set XML, and permissions report rendering. This is not a Salesforce CLI plugin — it's the library layer behind @simplysf/simply-permissions's permission set build/report commands, published separately so it can be imported directly by anything that wants the same rendering (an editor extension, a CI job, a script) without pulling in the CLI framework.
Install
npm install @simplysf/simply-permissions-coreRequires Node.js >=22 and either "type": "module" or a dynamic import() — this package ships ESM only.
API
Everything below is exported from the package root. Removing or renaming an export is a breaking change; see src/index.ts.
| Export | Description |
| -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| buildPermissionSetXml(data) | Pure function: renders a complete PermissionSet metadata XML document from typed template data. |
| buildPermissionsReportHtml(options) | Pure function: renders a self-contained HTML report of permission sets/groups, grouped by package. |
| ObjectPermission, FieldPermission, TabSetting, RecordTypeVisibility, UserPermission, PermissionSetTemplateData | Types for buildPermissionSetXml's input. |
| ObjectPermissionEntry, FieldPermissionEntry, PermissionSetReportEntry, PermissionSetGroupReportEntry, GroupedPermissionsData | Types for buildPermissionsReportHtml's input. |
import { buildPermissionSetXml, type PermissionSetTemplateData } from '@simplysf/simply-permissions-core';
const data: PermissionSetTemplateData = {
label: 'My Permission Set',
hasActivationRequired: false,
objectPermissions: [
{
object: 'Account',
allowCreate: true,
allowDelete: false,
allowEdit: true,
allowRead: true,
modifyAllRecords: false,
viewAllRecords: true,
viewAllFields: false,
},
],
fieldPermissions: [],
tabSettings: [],
recordTypeVisibilities: [],
userPermissions: [],
};
const xml = buildPermissionSetXml(data);
// write xml to a `.permissionset-meta.xml` fileimport { buildPermissionsReportHtml } from '@simplysf/simply-permissions-core';
const html = buildPermissionsReportHtml({
username: '[email protected]',
reportDate: new Date().toISOString(),
groupedData: new Map([['', { permissionSets: [], permissionSetGroups: [] }]]),
});
// write html to a report fileIssues
Please report any issues at https://github.com/SimplySF/simply-plugins-core/issues
Contributing
This package is part of the @simplysf/simply monorepo. See CONTRIBUTING.md for what's specific to this package, and the repo's root CONTRIBUTING.md for repo structure, setup, commit conventions, and how to submit a pull request. Please also read our Code of Conduct.
License
Licensed under the Apache-2.0 license.
| scanPermissionSetSource(directory) | Scans a source directory for custom objects, permissionable fields, tabs, and record types, recording the file each object and field came from and the fields left out as required or master-detail. Like sf project deploy start, it honors .forceignore but not .gitignore. |
| compilePermissionSet(scan, options) | Pure function: applies a type baseline (read-only/view-all/modify-all) and overrides to a scan, returning PermissionSetTemplateData. |
| writePermissionSet(data, name, output) | Renders and writes <output>/<name>.permissionset-meta.xml. |
| loadPermissionSetBuildConfig(filePath) | Loads and validates an overrides file (PermissionSetBuildConfigSchema). |
| loadPermissionSetBuildFile(filePath) | Loads and validates a permission set build file (PermissionSetBuildFileSchema), which defines one permission set, into a PermissionSetSpec: a referenced overrides file loaded, the source directory checked. A file in the pre-0.7 permissionSets list format is rejected with legacy-format. |
| assertUniquePermissionSetNames(entries) | Throws duplicate-name if two { file, spec } entries declare the same permission set name, naming both files. |
| findPermissionSetBuildFiles() | Every *.psbuild.json file under the current directory, as sorted /-separated relative paths. Doesn't descend into node_modules, .git, .sf, or .sfdx, or follow symbolic links. |
| generatePermissionSets(specs, onPermissionSet?, onExplanation?) | Builds and writes each spec, scanning each distinct source directory once. With onExplanation, also passes each spec's PermissionSetExplanation to it, at the cost of a git lookup per source directory. |
| checkPermissionSets(specs, onPermissionSet?, onExplanation?) | Builds each spec as generatePermissionSets does but writes nothing: compares it with the file at its output path and reports up-to-date, drifted, or missing. Formatting differences (indentation, line endings, comments) aren't drift. onExplanation as for generatePermissionSets. |
| explainPermissionSets(specs, onPermissionSet?) | Builds each spec as generatePermissionSets does but writes nothing: returns, per spec, one ObjectAccessDecision per object saying whether its fields are granted by viewAllFields, by field permissions, or not at all; why (baseline, no-object-metadata, config-override, config-only); and which source files decided it, with each file's git status (tracked, untracked, ignored, unknown). |
| findUntrackedSources(explanation) | The deciding files in an explanation that git doesn't track (untracked or ignored): usually metadata left behind by sf project retrieve start, which changes the generated permission set but isn't in anyone else's checkout. |
| PermissionSetBuildError | Thrown by the above with a structural code (scan-failed, invalid-config, config-not-found, directory-not-found, legacy-format, duplicate-name) and args. |
| PermissionSetBuildConfigSchema, PermissionSetBuildFileSchema | zod schemas for the overrides file and the permission set build file. |
| PERMISSION_SET_BUILD_FILE_SUFFIX | '.psbuild.json', the suffix that marks a permission set build file, which findPermissionSetBuildFiles (and so sf simply cicd build check-permission-sets and a flagless sf simply permissions build) discovers files by. loadPermissionSetBuildFile accepts any name. |
| PermissionSetExplanation, ObjectAccessDecision, FieldAccess, FieldAccessReason, SourceFile, GitFileStatus, OmittedField, UntrackedSource | Types for explainPermissionSets and findUntrackedSources. |
| PermissionSetType, PermissionSetSourceScan, PermissionSetBuildOptions, PermissionSetSpec, PermissionSetBuildResult, PermissionSetCheckResult, PermissionSetCheckStatus, PermissionSetBuildErrorCode, PermissionSetBuildConfig, PermissionSetBuildFile | Types for the permission set build functions. |
