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/negotiator url #148

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions packages/lib/src/services/bbmriNegotiate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { queryStore } from "../stores/query";

import { lensOptions } from "../stores/options";
import { v4 as uuidv4 } from "uuid";
import type { QueryItem, SendableQuery } from "../types/queryData";
import type {
LensOptions,
NegotiateOptions,
Expand Down Expand Up @@ -60,20 +56,10 @@ export const getCollections = (
* @param sitesToNegotiate the sites to negotiate with
*/
export const negotiate = async (sitesToNegotiate: string[]): Promise<void> => {
let sendableQuery!: SendableQuery;
queryStore.subscribe((value: QueryItem[][]) => {
const uuid = uuidv4();
sendableQuery = {
query: value,
id: `${uuid}__search__${uuid}`,
};
});

const humanReadable: string = getHumanReadableQuery();
const collections: NegotiateOptionsSiteMapping[] =
getCollections(sitesToNegotiate);
const negotiatorResponse = await sendRequestToNegotiator(
sendableQuery,
humanReadable,
collections,
);
Expand Down Expand Up @@ -119,22 +105,18 @@ interface BbmriCollectionResource {

/**
*
* @param sendableQuery the query to be sent to the negotiator
* @param humanReadable a human readable query string to view in the negotiator project
* @param collections the collections to negotiate with
* @returns the redirect uri from the negotiator
*/
async function sendRequestToNegotiator(
sendableQuery: SendableQuery,
humanReadable: string,
collections: NegotiateOptionsSiteMapping[],
): Promise<NegotiatorResponse> {
const base64Query: string = btoa(JSON.stringify(sendableQuery.query));

/**
* handle redirect to negotiator url
*/
const returnURL: string = `${window.location.protocol}//${window.location.host}/?nToken=${sendableQuery.id}&query=${base64Query}`;
const returnURL: string = `${window.location.protocol}//${window.location.host}`;

let response!: Response;

Expand Down
Loading