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

(EAI-206): Custom fetch options + add authorized user to staging conversation custom data #308

Merged
merged 17 commits into from
Feb 21, 2024

Conversation

mongodben
Copy link
Collaborator

@mongodben mongodben commented Jan 24, 2024

Jira: https://jira.mongodb.org/browse/EAI-206

Changes

  • In UI library:

    • Configure custom fetch options (so can pass cookies/custom headers, etc.)
  • In server library:

    • when streaming make so inherits "Access-Control-Allow-Origin" header from CORs/app rather than from the data streamer.
  • On server implementation:

    • Add ability to get authorized user from the cookie that CorpSecure sets in lower level envs.
    • Explicitly add requireRequestOrigin() and requireValidIpAddress() middleware and logic to add these to the conversation custom data b/c the new functionality to get the auth user overrides the defaults which used these.

Todos:

  • Test to make sure adding authUser from cookie works

Notes

@mongodben mongodben changed the title (EAI-206): Add authorized user to conversation custom data if env != prod && authorized user cookie exists (EAI-206): Custom fetch options + add authorized user to staging conversation custom data Jan 30, 2024
@mongodben mongodben marked this pull request as ready for review February 1, 2024 15:11
@mongodben mongodben linked an issue Feb 2, 2024 that may be closed by this pull request
};

export class ConversationService {
private serverUrl: string;
private fetchOptions?: ConversationFetchOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We define this.fetchOptions in the class constructor so it should always be defined right?

Maybe an opportunity for cleanup in other spots in the class where we currently assume fetchOptions may be undefined and use nullish coalescing (i.e. ??)

@@ -222,12 +254,11 @@ export class ConversationService {
};

await fetchEventSource(this.getUrl(path, { stream: "true" }), {
...this.fetchOptions,
// Need to convert Headers to plain object for fetchEventSource
headers: Object.fromEntries(this.fetchOptions?.headers ?? new Headers()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this.fetchOptions and this.fetchOptions.headers always be defined since we assign it in the constructor?

Copy link
Collaborator

@nlarew nlarew left a comment

Choose a reason for hiding this comment

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

Couple of small changes in the frontend code but then I think this should be good to go! Tests seems to indicate the the overrides work well. Let's double check in staging after the merge to make sure and then we can cut new releases.

@mongodben mongodben merged commit 09c3bf5 into main Feb 21, 2024
1 check passed
@mongodben mongodben deleted the EAI-206 branch February 21, 2024 15:00
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.

how to pass parameters from <Chatbot>?
2 participants