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

Added API Key to Fire Function #89

Conversation

honeycomb-cheesecake
Copy link
Contributor

@honeycomb-cheesecake honeycomb-cheesecake commented Sep 18, 2023

Allows for authenticated requests.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #50473: Decision SDK Fire Function Not Working.

@honeycomb-cheesecake honeycomb-cheesecake changed the title Added API Key to Fire unction. Added API Key to Fire Function Sep 18, 2023
vkurup
vkurup previously approved these changes Sep 19, 2023
Copy link
Contributor

@vkurup vkurup left a comment

Choose a reason for hiding this comment

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

There are some tests, but I'm not familiar with them, If it's easy to add coverage there for this feature, it might be helpful

src/client.ts Outdated
@@ -335,7 +341,7 @@ class PixelClient {
method: 'GET',
headers: {
'X-Adzerk-Sdk-Version': this._versionString,
'X-Kevel-ApiKey': additionalOpts?.apiKey,
'X-Kevel-ApiKey': additionalOpts?.apiKey ?? this._options?.apiKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not very familiar with the Decision API. The only thing I worry about here is that for the Decision client, we only include the header if it is present, but here, we are including the header in every request, with a null value if it is not present. I'm wondering if it might be safer to only include the header if the apikey is found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a comment from Ash to help the user experience. I'll roll it back to original functionality for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I like the fallback from additionalOpts to this._options. I'm just afraid of sending X-Kevel-ApiKey: null rather than not sending the header at all if apikey is not set.

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 diverges against establshed behaviour, we could roll this, but we'd have to announce it.

Choose a reason for hiding this comment

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

How about something like:

if (additionalOpts?.apiKey) {
    opts.headers['X-Kevel-ApiKey'] = additionalOpts.apiKey;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't actually the topic, but good suggestion as fetch actually still sends something even if set to undefined and null. Have updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

That was actually what I was trying to suggest, but Akira is a better communicator than me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhhhh, I get it now. Sorry @vkurup that's clearly my misread.

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, no worries! It's a 2 way street and both of ours have had heavy traffic on them recently

@honeycomb-cheesecake honeycomb-cheesecake merged commit 8c5cde3 into master Sep 28, 2023
5 checks passed
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.

3 participants