
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
salesforce-webhooks
Advanced tools
Provides an interface to create webhooks in Salesforce for different SObject events
The purpose of this package is to provide a convenient interface to the Salesforce API in order to create or delete webhooks in the Salesforce platform. It offers a simple interface to create basic webhooks for "created", "updated" or "deleted" events on any SObject type (although such types must be triggerable, as specified by an SObject's metadata)
Please note that this is a Node.js package and hasn't been tested in a browser-like environment.
Nothing special here: just a regular NPM/Yarn Node.js package.
npm install --save salesforce-webhooks
yarn add salesforce-webhooks
This package can be used to either create or delete a webhook from Salesforce. It just serves as an interface and convenience tool to do all the required wiring, customization and interaction with Salesforce under the hood. It does not however keep track of created webhooks, it's purpose is not to manage those webhooks beyond creation or deletion of its low-level components.
The interface is exposed through the SalesforceClient
class. To start, create
a new instance of this class by providing the following information about your
Salesforce organization:
50.0
by
default, and this is the target version for which this package was developed.The above parameter names are authToken
, instance
and apiVersion
,
respectively. So, to create a new instance of SalesforceClient
execute the
following code:
const { SalesforceClient } = require("salesforce-webhooks");
const authToken = "a secret API token"; // This is supposed to be secret!
const instance = "na139"; // This is just an example instance.
const client = new SalesforceClient({
authToken,
instance,
apiVersion: "50.0",
});
console.log(client);
// SalesforceClient {
// authToken: 'a secret token',
// metadataApiUrl: 'https://na139.salesforce.com/services/Soap/m/50.0',
// soapApiUrl: 'https://na139.salesforce.com/services/Soap/s/50.0'
//}
Note that the *ApiUrl
properties contain information about the instance and
the API version.
The client parameters can also be extracted from environment variables if they are not provided to the constructor:
export SALESFORCE_API_VERSION='50.0'
export SALESFORCE_AUTH_TOKEN='a secret API token'
export SALESFORCE_INSTANCE='na139'
The constructor will resort to the environment variables above if no valid arguments were provided to it:
const { SalesforceClient } = require("salesforce-webhooks");
const client = new SalesforceClient();
console.log(client);
// SalesforceClient {
// authToken: 'a secret token',
// metadataApiUrl: 'https://na139.salesforce.com/services/Soap/m/50.0',
// soapApiUrl: 'https://na139.salesforce.com/services/Soap/s/50.0'
//}
Every webhook creation interface requires users to provide at least the following arguments:
endpointUrl
: the URL of the endpoint that the webhook should call
whenever it gets triggeredsObjectType
: the type of SObject that this webhook will react toThe following interfaces serve the purpose of creating webhooks:
createWebhookNew
: creates a webhook that gets triggers when a new object
is createdcreateWebhookUpdated
: creates a webhook that gets triggers when an
object is updatedcreateWebhookDeleted
: creates a webhook that gets triggers when an
object is deletedcreateWebhook
: it takes an additional argument event
whose values can
be either new
, updated
or deleted
, and it creates a webhook that gets
triggers when an event of type event
happens to an objectAn optional parameter called secretToken
can be provided in order to verify
the authenticity of the HTTP calls at the target endpoint. Whenever the endpoint
receives an HTTP call, it can verify that the X-Webhook-Token
header matches
the secret token provided through the secretToken
argument.
To create a webhook that will make an HTTP POST call to http://example.com whenever a new account is created, run the following code:
const client = new SalesforceClient(...); // See the Instantiation section above.
const webhookOpts = {
endpointUrl: 'http://example.com',
sObjectType: 'Account',
secretToken: 'some secret arbitrary string',
};
const webhookData = await client.createWebhookNew(webhookOpts);
console.log(webhookData);
// {
// remoteSiteName: 'SW_Endpoint_9c680f2bb526a0fbdc34a2aef7e5',
// classNames: [
// 'SW_SObjectFactory_3452ca73469dc9c2094f01',
// 'SW_Callout_ae23bd24aa8c2abbc0c78db11e7f',
// 'SW_CalloutMock_6a18a2dfa993157c6574bd7c',
// 'SW_Test_85d9edee3617e831a7fbfe43cb30e084'
// ],
// triggerNames: [ 'SW_Trigger_b868fb7dbbcdea44930014e7a585' ]
// }
If you don't know the type of event at compile time, you can use the more
flexible interface createWebhook
which allows you to specify the type of event
at runtime. The output of the following code is equivalent to the one in the
code above:
const client = new SalesforceClient(...); // See the Instantiation section above.
const webhookOpts = {
endpointUrl: 'http://example.com',
sObjectType: 'Account',
secretToken: 'some secret arbitrary string',
event: 'new'
};
const webhookData = await client.createWebhook(webhookOpts);
console.log(webhookData);
// {
// remoteSiteName: 'SW_Endpoint_9c680f2bb526a0fbdc34a2aef7e5',
// classNames: [
// 'SW_SObjectFactory_3452ca73469dc9c2094f01',
// 'SW_Callout_ae23bd24aa8c2abbc0c78db11e7f',
// 'SW_CalloutMock_6a18a2dfa993157c6574bd7c',
// 'SW_Test_85d9edee3617e831a7fbfe43cb30e084'
// ],
// triggerNames: [ 'SW_Trigger_b868fb7dbbcdea44930014e7a585' ]
// }
The information returned by these methods is required whenever you wish to delete the resources created by them.
As mentioned in the previous section, after creating a webhook the call returns useful data that can be used to delete all the resources created before.
So after creating a webhook, we can do this to delete it:
await client.deleteWebhook(webhookData);
The concept of webhooks in Salesforce is a bit blurry: they do not exist explicitly, but the platform provides enough building blocks for developers to implement them.
This section briefly describes the Lightning Platform aspects that this package leverages to implement webhooks in Salesforce. In a nutshell:
Under the hood, this package performs the following actions when creating a webhook:
Upon successful creation of a webhook, the package returns an object with
information relative to all the entities created above. This information must be
stored for future use whenever users which to clean-up those resources. The
package itself does not keep track of those resources after the call to
createWebhook*
completes.
For deletion, the same steps described above is performed in reverse order, except that instead of creating those resources, they are removed.
FAQs
Provides an interface to create webhooks in Salesforce for different SObject events
The npm package salesforce-webhooks receives a total of 607 weekly downloads. As such, salesforce-webhooks popularity was classified as not popular.
We found that salesforce-webhooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.