Skip to content

Commit

Permalink
Ensure access_token props are always passed through to request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ozsivanov committed Nov 4, 2021
1 parent d69ec0d commit 44d855a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 30 deletions.
2 changes: 2 additions & 0 deletions commons/src/connections/neural.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const fetchCleanConversations = (
`${getMiddlewareApiUrl(query.component_id)}/neural/conversation`,
getFetchConfig({
method: "PUT",
access_token: query.access_token,
component_id: query.component_id,
body: { message_id: query.message_id },
}),
Expand All @@ -38,6 +39,7 @@ export const sendCleanConversationFeedback = (
`${getMiddlewareApiUrl(query.component_id)}/neural/conversation/feedback`,
getFetchConfig({
method: "POST",
access_token: query.access_token,
component_id: query.component_id,
body: { message_id: query.message_id },
}),
Expand Down
13 changes: 6 additions & 7 deletions commons/src/types/Availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type {
SelectionStatus,
AvailabilityStatus,
} from "@commons/enums/Availability";
import type { Manifest as NylasManifest } from "@commons/types/Nylas";
import type {
CommonQuery,
Manifest as NylasManifest,
} from "@commons/types/Nylas";
export interface Manifest extends NylasManifest {
allow_booking: boolean;
allow_date_change: boolean;
Expand Down Expand Up @@ -75,14 +78,12 @@ export interface SelectableSlot extends TimeSlot {
hovering?: boolean;
}

export interface AvailabilityQuery {
export interface AvailabilityQuery extends CommonQuery {
body: {
emails: string[];
start_time: number;
end_time: number;
};
component_id: string;
access_token?: string;
forceReload?: boolean;
}

Expand All @@ -95,12 +96,10 @@ export interface AvailabilityResponse {
email: string;
}

export interface EventQuery {
export interface EventQuery extends CommonQuery {
participants?: EventParticipant[];
title?: string;
location?: string;
access_token?: string;
component_id?: string;
}

export interface EventParticipant {
Expand Down
11 changes: 3 additions & 8 deletions commons/src/types/Contacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WebPage } from "@commons/types/Nylas";
import type { CommonQuery, WebPage } from "@commons/types/Nylas";

export interface Contact {
account_id: string;
Expand Down Expand Up @@ -56,15 +56,10 @@ export interface ContactPhoneNumber {
type: string;
}

export interface ContactsQuery {
component_id: string;
access_token?: string;
}
export interface ContactsQuery extends CommonQuery {}

export interface ContactSearchQuery {
component_id: string;
export interface ContactSearchQuery extends CommonQuery {
query: string;
access_token?: string;
}

export interface StoredContacts {
Expand Down
19 changes: 6 additions & 13 deletions commons/src/types/Nylas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
EmailUnreadStatus,
MailboxActions,
} from "@commons/enums/Nylas";

export interface CommonQuery {
component_id: string;
access_token?: string;
Expand All @@ -18,10 +19,7 @@ export interface MailboxQuery extends CommonQuery {
query: ThreadsQuery;
}

export interface AccountQuery {
component_id: string;
access_token?: string;
}
export interface AccountQuery extends CommonQuery {}

export interface ThreadsQuery {
limit?: number;
Expand All @@ -44,9 +42,7 @@ export interface ThreadsQuery {
not_in?: string;
}

export interface SearchResultThreadsQuery {
component_id: string;
access_token?: string;
export interface SearchResultThreadsQuery extends CommonQuery {
keyword_to_search: string;
}

Expand All @@ -55,13 +51,11 @@ export interface MessagesQuery extends CommonQuery {
received_after?: number;
}

export interface CleanConversationQuery {
component_id: string;
export interface CleanConversationQuery extends CommonQuery {
message_id: string[]; // Note: singular name but expects array
}

export interface CleanConversationFeedbackQuery {
component_id: string;
export interface CleanConversationFeedbackQuery extends CommonQuery {
message_id: string;
}

Expand All @@ -80,8 +74,7 @@ export interface StoredMessage {
data: Message;
}

export interface SingularEmail {
component_id: string;
export interface SingularEmail extends CommonQuery {
message_id: string;
}

Expand Down
2 changes: 2 additions & 0 deletions components/conversation/src/Conversation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
let query: ConversationQuery;
$: query = {
access_token,
component_id: id,
thread_id: thread_id,
};
Expand Down Expand Up @@ -240,6 +241,7 @@
//#region Clean Conversation
function cleanConversation() {
fetchCleanConversations({
access_token,
component_id: id,
message_id: conversationMessages
.slice(-CONVERSATION_ENDPOINT_MAX_MESSAGES)
Expand Down
6 changes: 4 additions & 2 deletions components/email/src/Email.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@
}
let query: ConversationQuery;
$: query = {
access_token,
component_id: id,
thread_id: thread_id,
thread_id,
};
let queryKey: string;
Expand Down Expand Up @@ -282,6 +283,7 @@
function cleanConversation() {
if (activeThread) {
fetchCleanConversations({
access_token,
component_id: id,
message_id: activeThread.messages
.slice(-CONVERSATION_ENDPOINT_MAX_MESSAGES)
Expand Down Expand Up @@ -516,7 +518,7 @@
// For cases when someone wants to show just a single email message, rather than the full thread.
function fetchOneMessage() {
fetchEmail({ component_id: id, message_id: message_id }).then((json) => {
fetchEmail({ access_token, component_id: id, message_id }).then((json) => {
message = json;
messageLoadStatus[0] = "loaded";
});
Expand Down
1 change: 1 addition & 0 deletions components/mailbox/src/Mailbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
async function updateThreadStatus(updatedThread: any) {
if (id && updatedThread && updatedThread.id) {
const threadQuery = {
access_token,
component_id: id,
thread_id: updatedThread.id,
};
Expand Down

0 comments on commit 44d855a

Please sign in to comment.