Skip to content

chore(intercom): Add request to the update server to determine if Intercom integration is allowed COMPASS-9371 #6982

New issue

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

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

Already on GitHub? # to your account

Merged
merged 10 commits into from
Jun 18, 2025

Conversation

kraenhansen
Copy link
Contributor

@kraenhansen kraenhansen commented Jun 3, 2025

Description

Combined with https://github.com/10gen/compass-mongodb-com/pull/133, merging this will introduce a preflight request to the update server to determine if Compass is allowed to setup the Intercom integration.

TODO: We might want to send the Compass version and OS / arch to that endpoint, in order to be able to selectively respond based on those parameters. But is that a thing that we will reasonably be using?

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@kraenhansen kraenhansen self-assigned this Jun 3, 2025
@kraenhansen kraenhansen added the no release notes Fix or feature not for release notes label Jun 3, 2025
@@ -25,6 +25,11 @@ export async function setupIntercom(
return;
}

if (!(await isIntercomAllowed())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: We shouldn't send a request networkTraffic is disabled.

Copy link
Member

@Anemy Anemy Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also want to prevent a request if the enableFeedbackPanel preference is false, or we're on web right? I'm guessing the web part is something we get from only accessing this from the compass electron side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enableFeedbackPanel depens on network traffic already, so checking just one should be enough. We might want to just move this check higher in this method maybe

Copy link
Contributor Author

@kraenhansen kraenhansen Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way to shuffle stuff around. I am checking networkTraffic explicitly to increase cohesion and avoid relying on an implicit fact (the enableFeedbackPanel depending on networkTraffic - as I could observe that, but personally failed to establish the reason for that as I was writing this).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have a strong preference for us not to do that, deriveNetworkTrafficOptionState is a mechanism we specifically added so that feature flags for some features (like feedback panel) don't need to explicitly check for network traffic. I'm happy to discuss how to make it more visible if just looking at the preferences descriptions that use deriveNetworkTrafficOptionState is not enough, but introducing a different pattern just makes it more obscure. Looking at the code it's now not clear whether or not networkTraffic needs to be checked even if deriveNetworkTrafficOptionState is applied to the preference. If I look here, it needs to be, if I look at some other preferences it doesn't, and there's no explanation for why this is happening

Copy link
Contributor Author

@kraenhansen kraenhansen Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rely on enableFeedbackPanel directly then 👍 I seached for deriveNetworkTrafficOptionState and I don't know why I wasn't able to find that before.

Another alternative would be for the DeriveValueFunction to be async and call the endpoint from there, as to completely disable the feature based on a response from the update server. But that might be more involved 🤔

@kraenhansen kraenhansen force-pushed the kh/intercom-integration-switch branch from 28e787c to 938d4e3 Compare June 6, 2025 13:18
@kraenhansen
Copy link
Contributor Author

I'm seeing some pretty consistent failures of the e2e tests related to dynamically changing the proxy preference, but I have no idea why 😬 I can reproduce it locally and it doesn't reproduce off main locally either.

https://parsley.mongodb.com/test/10gen_compass_main_test_packaged_app_rhel_test_packaged_app_1_patch_1fd78e7d7f2c6c69213ea58b921c82f1f660fa22_6842eb5c66fdd10007816d59_25_06_06_13_21_35/0/0bbe998191287f5102298f00bf09d948?bookmarks=0,15&shareLine=0

@kraenhansen
Copy link
Contributor Author

Turns out the preflight request opened a connection which made the proxy tests fail when they requests afterwards.

@kraenhansen kraenhansen marked this pull request as ready for review June 10, 2025 11:55
@kraenhansen kraenhansen added feature flagged PRs labeled with this label will not be included in the release notes of the next release and removed feature flagged PRs labeled with this label will not be included in the release notes of the next release labels Jun 10, 2025
@kraenhansen kraenhansen force-pushed the kh/intercom-integration-switch branch from 0f5f80d to 6ab3c4d Compare June 10, 2025 12:39
// NOTE: we use 301 since intercom will redirects
// to the actual location of the widget script
fetchMock.resolves({ status: 301 } as Response);
fetchMock = sinon.stub(globalThis, 'fetch');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this makes it possible to restore afterwards.

@@ -89,7 +89,7 @@ export function injectCSP() {
extraAllowed.push('ws://localhost:*');
// Used by proxy tests, since Chrome does not like proxying localhost
// (this does not result in actual outgoing HTTP requests)
extraAllowed.push('http://compass.mongodb.com/');
extraAllowed.push('http://proxy-test-compass.mongodb.com/');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm changing this to avoid conflicts with the actual compass update server URL called when setting up intercom.

await toggleEnableFeedbackPanel(shouldLoad);
} catch (error) {
debug('initial toggle failed', {
error: error instanceof Error && error.message,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just

Suggested change
error: error instanceof Error && error.message,
error

?

(error) => {
debug(
'Failed to fetch intercom integration status, defaulting to false',
{ error: error instanceof Error && error.message }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Suggested change
{ error: error instanceof Error && error.message }
{ error }

}
);
}

function isIntercomAllowed(allowNetworkTraffic = true): Promise<boolean> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I think we'd want to avoid the default argument here but we'll want to change this so we don't interact with allowNetworkTraffic here directly anyway, so it doesn't really matter)

@kraenhansen kraenhansen requested a review from a team as a code owner June 15, 2025 20:49
@kraenhansen kraenhansen force-pushed the kh/intercom-integration-switch branch from cc710c2 to 6441053 Compare June 17, 2025 13:40
Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have one note / nit comment, but otherwise looks good!


toggleEnableFeedbackPanel(!!enableFeedbackPanel);
try {
await toggleEnableFeedbackPanel(shouldLoad);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have a good suggestion from the top of my head, but I did find it a bit mind bending that shouldLoad here already takes awaited isIntercomAllowed into account, but then toggleEnableFeedbackPanel immediately fetches it again. I understand the purpose of this, but kinda wish this was maybe somehow less tangled. I don't think it's that big of a deal, but wanted to highlight

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a valid concern and I had the response cached in a previous commit. I reverted it because it felt a bit premature, but thinking more about it, I do think it makes sense - this is going to be fetched by every render process and we might as well do it once instead of twice.

@kraenhansen kraenhansen force-pushed the kh/intercom-integration-switch branch from 6441053 to 1e07960 Compare June 18, 2025 06:53
@kraenhansen kraenhansen merged commit d5cce0d into main Jun 18, 2025
103 of 105 checks passed
@kraenhansen kraenhansen deleted the kh/intercom-integration-switch branch June 18, 2025 11:52
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants