npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

psforce

v1.2.0

Published

Interact with Salesforce permissions in JavaScript.

Downloads

51

Readme

OrgPermssioner

Easily interact with Salesforce permissions via Node.js

OrgPermssioner in a javascript module that makes interacting with Salesforce org permissions a breeze.

It can be used by Salesforce ISVs and DevOps vendors for multiple use cases such as:

Find out why a user has access to a given permission

Salesforce users can be granted a specific permission, such as ViewAllData via Profiles, Permission Sets and Permission Set Groups (and a combination of all of them).

The getUsersWithAccess function retrives all the active users that have specific permissions enabled, and gives a breakdown of how the permissions are granted.

Here's how to use it

const conn = new jsforce.Connection();
await conn.login(...);

let permissionsToCheck = [perm1,perm2];

const result = await getUsersWithAccess({
    jsforceConnection: conn,
    permissionsToCheck
});

console.log(result);

The response provides a list of users who have access to ALL the permissions in the permissionsToCheck array. For each permission, the sources array list all the reasons that user has that permissions.

[
  {
    "username": "[email protected]",
    "name": "pablo gonzalez",
    "id": "005Wy000000uRLhIAM",
    "permissions": [
      {
        "name": "PermissionsExportReport",
        "sources": [
          {
            "type": "Profile",
            "name": "X00ex00000018ozq_128_09_04_12_10",
            "id": "00eWy0000008yPTIAY"
          },
          {
            "type": "PermissionSetGroup",
            "name": "AuthorApexAndExportData",
            "id": "0PGWy0000004JFNOA2",
            "sources": [
              {
                "type": "PermissionSet",
                "name": "ExportReportPermSetB",
                "id": "0PSWy000000TGNxOAO"
              }
            ]
          },
          {
            "type": "PermissionSet",
            "name": "ExportReportPermSetB",
            "id": "0PSWy000000TGNxOAO"
          },
          {
            "type": "PermissionSet",
            "name": "ExportReportPermSetA",
            "id": "0PSWy000000TGMLOA4"
          }
        ]
      },
      {
        "name": "PermissionsAuthorApex",
        "sources": [
          {
            "type": "PermissionSetGroup",
            "name": "AuthorApexAndExportData",
            "id": "0PGWy0000004JFNOA2",
            "sources": [
              {
                "type": "PermissionSet",
                "name": "ExportReportPermSetB",
                "id": "0PSWy000000TGNxOAO"
              }
            ]
          },
          {
            "type": "PermissionSet",
            "name": "AuthorApexPermSetB",
            "id": "0PSWy000000TGKjOAO"
          },
          {
            "type": "PermissionSet",
            "name": "AuthorApexPermSetA",
            "id": "0PSWy000000TGHVOA4"
          }
        ]
      }
    ]
  },
  {
    "username": "[email protected]",
    "name": "Pablo Gonzalez",
    "id": "005Wy000000AcgjIAC",
    "permissions": [
      {
        "name": "PermissionsExportReport",
        "sources": [
          {
            "type": "PermissionSet",
            "name": "ExportReportPermSetB",
            "id": "0PSWy000000TGNxOAO"
          },
          {
            "type": "PermissionSet",
            "name": "ExportReportPermSetA",
            "id": "0PSWy000000TGMLOA4"
          },
          {
            "type": "Profile",
            "name": "X00ex00000018ozh_128_09_04_12_1",
            "id": "00eWy0000008yOpIAI"
          }
        ]
      },
      {
        "name": "PermissionsAuthorApex",
        "sources": [
          {
            "type": "PermissionSet",
            "name": "AuthorApexPermSetB",
            "id": "0PSWy000000TGKjOAO"
          },
          {
            "type": "PermissionSet",
            "name": "AuthorApexPermSetA",
            "id": "0PSWy000000TGHVOA4"
          },
          {
            "type": "Profile",
            "name": "X00ex00000018ozh_128_09_04_12_1",
            "id": "00eWy0000008yOpIAI"
          }
        ]
      }
    ]
  }
]

How it works

You must pass a jsforce connection object. How that object is created and how the authentication is established is your responsibility.

The permissionsToCheck is a String[] where each permission name corresponds to the permission-related fields in the PermissionSet object. For each permission that exists in the org, a corresponding Permissions[Name] field exists in the PermissionSet object.

For example, the ViewAllData and ExportReport permissions are represented as PermissionsViewAllData and PermissionsExportReport respectively.

To view the entire list of fields that are permissions, use the jsforce describe operation

const metadata = await conn.sobject('PermissionSet').describe()
    
metadata.fields.forEach(field => {
    if(field.name.startsWith('Permissions')){
        console.log(field.name);
    }
});