UNPKG

@cgignite/ignite-salesforce

Version:

A set of Node-RED nodes to interact with Salesforce and Force.com.

218 lines (212 loc) 9.81 kB
<script type="text/javascript"> const API_VERSION = 'v45.0'; RED.nodes.registerType('connection-config', { category: 'config', defaults: { name: { value: '', required: true }, poturl: { value: '', required: false }, consumerKey: { value: '', required: false }, consumerSecret: { value: '', required: false }, callbackUrl: { required: true }, environment: { value: 'production', required: true }, credentialType: { value: 'oauth', required: 'true' }, useEnvCredentials: { value: true }, allowMsgCredentials: { value: false }, userName: { value: '', required: false }, passWord: { value: '', required: false }, apiversion: { value: API_VERSION, required: true } }, label: function() { return this.name || this.username + ' connection'; }, oneditprepare: function() { setTimeout(function() { var jqCurDialog = $("[aria-describedby='node-config-dialog']:visible"); var dialogWidth = $(window).width() - 100; if (dialogWidth > 700) { dialogWidth = 700; } jqCurDialog.css('width', dialogWidth); jqCurDialog.css('left', ($(window).width() - dialogWidth) / 2); // jqCurDialog.css('min-height', '580px'); // increase for form field size $('.form-row label').width('150px'); }, 0); $('#node-config-input-useEnvCredentials').change(function() { $('#credentials').toggle(!this.checked); }); $('#node-config-input-environment').change(function() { var curEnv = $('#node-config-input-environment'); if (curEnv.val() && curEnv.val().substring(0, 6) == 'custom') { $('#node-config-rown-poturl').show(); } else { $('#node-config-rown-poturl').hide(); } }); }, // reset the form label size oneditsave: function() { if (this.useEnvCredentials) { delete this.userName; delete this.passWord; delete this.consumerKey; delete this.consumerSecret; } //$(".form-row label").width('100px'); }, // reset the form label size oneditcancel: function() { //$(".form-row label").width('100px'); }, oneditdelete: function() { //$(".form-row label").width('100px'); } }); </script> <script type="text/x-red" data-template-name="connection-config"> <div class="form-row"> <label for="node-config-input-name"><i class="icon-bookmark"></i> Name</label> <input type="text" id="node-config-input-name" /> </div> <div class="form-row" style="white-space:nowrap"> <label for="node-config-input-callbackUrl"><i class="fa fa-history"></i> Callback URL</label> <input type="text" id="node-config-input-callbackUrl" placeholder="http://localhost:3000/oauth/_callback" /> <!-- TODO: add button for current host --> </div> <div class="form-row"> <label for="node-config-input-environment"><i class="fa fa-tasks"></i> Environment</label> <select id="node-config-input-environment"> <option value="production">Production</option> <option value="sandbox">Sandbox</option> <option value="customproduction">Production (Custom)</option> <option value="customsandbox">Sandbox (Custom)</option> <option value="environment">Environment variable</option> <option value="custommarketing">Marketing Cloud</option> <!-- <option value="customcommerce">Commerce Cloud (Custom)</option> --> </select> </div> <div class="form-row" id="node-config-rown-apiversion"> <label for="node-config-input-apiversion"><i class="fa fa-fire-extinguisher"></i> API Version</label> <input type="text" id="node-config-input-apiversion" placeholder="v45.0"/> </div> <div class="form-row" id="node-config-rown-poturl"> <label for="node-config-input-poturl"><i class="icon-bookmark"></i> Instance URL</label> <input type="text" id="node-config-input-poturl" /> </div> <div class="form-row"> <label for="node-config-input-credentialType"><i class="fa fa-lock"></i> Credential Type</label> <select id="node-config-input-credentialType"> <option value="oauth">oAuth (default)</option> <!-- <option value="userpwd">Username/Password</option> <option value="jwt">JWT Token</option> <option value="bearer">Bearer Token (Session)</option> --> </select> </div> <div class="form-row"> <input type="checkbox" id="node-config-input-allowMsgCredentials" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-config-input-allowMsgCredentials" style="width: auto; white-space:nowrap;">Allow credentials in msg object</label> </div> <div class="form-row"> <input type="checkbox" id="node-config-input-useEnvCredentials" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-config-input-useEnvCredentials" style="width: auto; white-space:nowrap;">Use environment variables for credentials</label> </div> <div id="credentials"> <div class="form-row credentials" style="white-space:nowrap"> <label for="node-config-input-consumerKey"><i class="fa fa-key"></i> Consumer Key</label> <input type="text" id="node-config-input-consumerKey" /> </div> <div class="form-row credentials" style="white-space:nowrap"> <label for="node-config-input-consumerSecret"><i class="fa fa-user-secret"></i> Consumer Secret</label> <input type="password" id="node-config-input-consumerSecret" /> </div> <div class="form-row credentials"> <label for="node-config-input-userName"><i class="fa fa-user"></i> Username</label> <input type="text" id="node-config-input-userName" /> </div> <div class="form-row credentials"> <label for="node-config-input-passWord"><i class="fa fa-lock"></i> Password</label> <input type="password" id="node-config-input-passWord" /> </div> </div> </script> <script type="text/x-red" data-help-name="connection-config"> <h3>Setting up a config node</h3> <ul> <li><b>Name</b>: NodeRED internal name of the connection. When you use environment credentials: prefix of the credential variables (see below) </li> <li><b>Callback URL</b>: needs to match the setting in the connected app. use <code>&lt;NodeRedURL&gt;/oauth/_callback</code> as default </li> <li><b>Environment</b>: Production or Sandbox. DevEditions are Production. When you pick the "custom" option, you can specify the URL of your specific instance. This avoids potential "connection" error that sometimes occurs with oauth. <br /> <b>NEW</b> Environment variable: Read the environment from an environemtn variable if this node is called <code>SFTest</code> it will read <code>SFTest_Environment</code> which must be <code>production</code> or <code>sandbox</code> </li> <li><b>Instance URL</b> (only shows for Environment "custom"): URL to your Salesforce instance (optional). Use it when you get "invalid client id" errors when connecting to Salesforce or when you use a ScratchOrg </li> <li><b>Credential Type</b>: What type of credentials to expect: <ul> <li><b>oAuth</b>: ClientId, ClientSecret and username/password are required. Use environment parameters or message paramenters</li> <li><b>Username/Password</b>: -not recommended in production- </li> <li><b>JWT</b>: requires access to JWT secret and setup of a connected app. Can impersonate any user! Handle with care!!!</li> <li><b>Bearer</b>: Use the <code>msg.bearer</code> property for authentication. Usefull for "calling back as the same user"</li> </ul> </li> <li><b>Allow credentials in msg object</b>: With this option enabled the configuration is checking for the <code>sf</code> property in the msg object and retrieves username, password, ConsumerKey and ConsumerSecret from it. (Thx to benariss for the idea/code) </li> <li><b>Use environment credentials</b>: Ignores the credential entries below and tries to read environment variables (e.g from a Heroku deployment). The variables are the name of this node and _ConsumerKey, _ConsumerSecret, _UserName and _Password. So if this Node is called <code>SFTest</code>, it will look for: <ul> <li>Consumer Key: <code>SFTest_ConsumerKey</code></li> <li>Consumer Secret: <code>SFTest_ConsumerSecret</code></li> <li>User Name: <code>SFTest_UserName</code></li> <li>Password: <code>SFTest_PassWord</code></li> </ul> Typically user name used here is the integration user </li> <li>Environment credentials <b>unchecked</b>: Fill in the values (will get updated in future) <ul> <li><b>Consumer Key</b>: Values from the Connected App setting in your instance </li> <li><b>Consumer Secret</b>: Values from the Connected App setting in your instance </li> <li><b>Username</b>: Credentials to get an Oauth token. Typically integration user. Not recommended, use environment instead </li> <li><b>Username/Password</b>: Credentials to get an Oauth token. Typically integration user. Not recommended, use environment instead </li> </ul> </li> </ul> </script>