Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hyperforce China Support #141

Merged
merged 4 commits into from
Dec 22, 2023

Conversation

yaacov9
Copy link
Contributor

@yaacov9 yaacov9 commented Aug 21, 2023

Hi, we have some clients that are now using a new Salesforce product called Hyperforce.
For China clients, Hyperforce are available only from new url.

So I implemented a way to retrieve the sessionCookie, the recordId, the hostname etc, and it's now works on differents clients that are using Hyperforce China.

My code supports both Classic and Lightning

@yaacov9
Copy link
Contributor Author

yaacov9 commented Aug 28, 2023

Hi, I reopened a PR, with all the requested changes.
Waiting for your review

@stenebenau
Copy link

Hi, please approve and merge this request asap. We are working on China/Alibaba developments and need this functionality as well. Thanks!

@tprouvot
Copy link
Owner

Hi @yaacov9 @stenebenau ,

Could one of you create me an account on a scratch org hosted on AlibabaCloud to be able to do some tests ?

@stenebenau
Copy link

HI @tprouvot, I understand your request. However this is not really allowed just yet. Can i test a beta package somehow?

@yaacov9
Copy link
Contributor Author

yaacov9 commented Nov 10, 2023

@tprouvot sorry I can't provide you a sandbox @stenebenau you already can download my version since it's open source
Go to my fork, download it and install it as package, as mentioned in the readme file
https://github.com/yaacov9/Salesforce-Inspector-reloaded/tree/releaseCandidate

@stenebenau
Copy link

Hi @tprouvot, i did some testing and ran the unit-tests. That worked until the export test, it tries to do something with an unknown field.

Salesforce_Inspector_Unit_Test

@tprouvot
Copy link
Owner

Hi Guys,
I'm not very comfortable with releasing something I haven't tested.
Same need happened when I had to add the support for military orgs, and I still have the access to make sure there's no regression.

I understand the issue with providing access to a sandbox which may include some metadata / data but with an empty scratch org it should be ok.
If you're in contact with people from Salesforce professional services on your project (not the support) you can tell them to reach me on our internal message system.

@yaacov9 the number of domains to check is increasing, could you refactor a little bit ie on background.js ?
Could you also resolve the conflicts on the branch ?
Thanks

"use strict";
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  // Perform cookie operations in the background page, because not all foreground pages have access to the cookie API.
  // Firefox does not support incognito split mode, so we use sender.tab.cookieStoreId to select the right cookie store.
  // Chrome does not support sender.tab.cookieStoreId, which means it is undefined, and we end up using the default cookie store according to incognito split mode.
  if (request.message == "getSfHost") {
    // When on a *.visual.force.com page, the session in the cookie does not have API access,
    // so we read the corresponding session from *.salesforce.com page.
    // The first part of the session cookie is the OrgID,
    // which we use as key to support being logged in to multiple orgs at once.
    // http://salesforce.stackexchange.com/questions/23277/different-session-ids-in-different-contexts
    // There is no straight forward way to unambiguously understand if the user authenticated against salesforce.com or cloudforce.com
    // (and thereby the domain of the relevant cookie) cookie domains are therefore tried in sequence.
    chrome.cookies.get({url: request.url, name: "sid", storeId: sender.tab.cookieStoreId}, cookie => {
      if (!cookie) {
        sendResponse(null);
        return;
      }
      let [orgId] = cookie.value.split("!");
      let orderedDomains = ["salesforce.com", "cloudforce.com", "salesforce.mil", "cloudforce.mil", "sfcrmproducts.cn"];

      orderedDomains.forEach(currentDomain => {
        chrome.cookies.getAll({name: "sid", domain: currentDomain, secure: true, storeId: sender.tab.cookieStoreId}, cookies => {
          let sessionCookie = cookies.find(c => c.value.startsWith(orgId + "!"));
          if (sessionCookie) {
            sendResponse(sessionCookie.domain);
          } else if (orderedDomains[orderedDomains.length] === currentDomain){
            sendResponse(null);
          }
        });
      });
    });
    return true; // Tell Chrome that we want to call sendResponse asynchronously.
  }
  if (request.message == "getSession") {
    chrome.cookies.get({url: "https://" + request.sfHost, name: "sid", storeId: sender.tab.cookieStoreId}, sessionCookie => {
      if (!sessionCookie) {
        sendResponse(null);
        return;
      }
      let session = {key: sessionCookie.value, hostname: sessionCookie.domain};
      sendResponse(session);
    });
    return true; // Tell Chrome that we want to call sendResponse asynchronously.
  }
  return false;
});

@tprouvot
Copy link
Owner

Hi @stenebenau,
My internal contact (Adam) is asking me what is your customer, maybe you can have a chat with him to clarify this point ?

@tprouvot tprouvot mentioned this pull request Dec 19, 2023
@tprouvot tprouvot merged commit 39b6aff into tprouvot:releaseCandidate Dec 22, 2023
AntoineLeleu-Salesforce pushed a commit to AntoineLeleu-Salesforce/Salesforce-Inspector-reloaded that referenced this pull request Jan 4, 2024
Hi, we have some clients that are now using a new Salesforce product
called Hyperforce.
For China clients, Hyperforce are available only from new url.

So I implemented a way to retrieve the sessionCookie, the recordId, the
hostname etc, and it's now works on differents clients that are using
Hyperforce China.

My code supports both Classic and Lightning

---------

Co-authored-by: Thomas Prouvot <prouvot.t@gmail.com>
AntoineLeleu-Salesforce pushed a commit to AntoineLeleu-Salesforce/Salesforce-Inspector-reloaded that referenced this pull request Jan 4, 2024
Hi, we have some clients that are now using a new Salesforce product
called Hyperforce.
For China clients, Hyperforce are available only from new url.

So I implemented a way to retrieve the sessionCookie, the recordId, the
hostname etc, and it's now works on differents clients that are using
Hyperforce China.

My code supports both Classic and Lightning

---------

Co-authored-by: Thomas Prouvot <prouvot.t@gmail.com>
@mehdicherf mehdicherf mentioned this pull request Jan 15, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants