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

Fix handling of apiEndpoint in constructor #34

Merged
merged 4 commits into from
Jan 31, 2025

Conversation

greenberga
Copy link
Contributor

We need to keep track of whether an apiEndpoint was passed to the FriendlyCaptchaSDK constructor. And then check it when creating widgets. The order of priority for determining a widget's apiEndpoint should be

  1. CreateWidgetOptions
  2. data-api-endpoint
  3. FriendlyCaptchaSDKOptions
  4. getSDKAPIEndpoint()

We need to keep track of whether an `apiEndpoint` was passed to the
`FriendlyCaptchaSDK` constructor. And then check it when creating
widgets. The order of priority for determining a widget's `apiEndpoint`
should be

1. `CreateWidgetOptions`
2. `data-api-endpoint`
3. `FriendlyCaptchaSDKOptions`
4. `getSDKAPIEndpoint()`
@greenberga greenberga requested a review from gzuidhof January 31, 2025 10:53
@greenberga greenberga self-assigned this Jan 31, 2025
Copy link
Contributor

@gzuidhof gzuidhof left a comment

Choose a reason for hiding this comment

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

LGTM, thank you 👍

// Returns true if a widget iframe (corresponding to the passed widget id)
// exists and has the given endpoint in its `src` attribute.
function widgetIFrameHasCorrectSrc(id: string, endpoint: string) {
const iframe = document.querySelector(`[data--frc-frame-id="${id}"]`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const iframe = document.querySelector(`[data--frc-frame-id="${id}"]`);
const iframe = document.querySelector(`[data--frc-frame-id="${id}"]`);

Surprised there's the double dash 🤔 - I suppose it works :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I pulled that from the Elements panel of the Developer Tools 🤷

@greenberga greenberga merged commit 8cf9638 into main Jan 31, 2025
2 checks passed
@greenberga greenberga deleted the fix-constructor-api-endpoint branch January 31, 2025 14:01
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.

2 participants