{"size": 678, "ext": "js", "max_stars_repo_path": "get-salesforce-identity.js", "max_stars_repo_name": "heroku/jsforce-connection", "max_stars_repo_stars_event_min_datetime": "2016-07-20T23:12:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T22:29:21.000Z", "max_issues_repo_path": "get-salesforce-identity.js", "max_issues_repo_name": "heroku/jsforce-connection", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "get-salesforce-identity.js", "max_forks_repo_name": "heroku/jsforce-connection", "max_forks_repo_forks_event_min_datetime": "2019-10-07T17:54:50.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-07T17:54:50.000Z"}
{"max_stars_count": 6, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 30.8181818182, "max_line_length": 85, "alphanum_fraction": 0.598820059}
const fetch = require('node-fetch');

module.exports = function getSalesforceIdentity(accessToken, idUrl, logger) {
  logger('-----> Get Salesforce identity');
  return fetch(idUrl, {
      headers: {
        'Authorization': `Bearer ${accessToken}`,
        'Content-Type': 'application/json'
      }
    })
    .then( response => {
      const status = response.status;
      if (status >= 300) { throw new Error(`Request status ${status} for ${idUrl}`) }
      //logger('       response status', status);
      return response.json();
    })
    .then( salesforceIdentity => {
      //logger('       Identity', salesforceIdentity);
      return salesforceIdentity;
    });
}
