Skip to content

Commit

Permalink
Merge pull request #189 from CanDIG/bugfix/deprecated-api
Browse files Browse the repository at this point in the history
Remove unused API calls, add more documentation
  • Loading branch information
OrdiNeu authored Nov 14, 2024
2 parents b3bd79d + 46f1c6f commit 05c0121
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 1,169 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
ARG alpine_version
ARG katsu_api_target_url

FROM node:21.7.0-alpine${alpine_version} as build

LABEL Maintainer="CanDIG Project"
LABEL "candigv2"="candig-data-portal"

ENV TYK_KATSU_API_TARGET=$katsu_api_target_url

RUN apk update && apk add gettext

RUN apk add --no-cache git curl vim bash
Expand Down
445 changes: 202 additions & 243 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"ag-grid-community": "^31.3.4",
"ag-grid-react": "^31.3.4",
"apexcharts": "^3.45.1",
"babel-loader": "^9.1.3",
"clsx": "^2.1.0",
Expand All @@ -49,6 +47,7 @@
"react-router": "^6.21.1",
"react-router-dom": "^6.21.1",
"redux": "^5.0.1",
"resolve-url-loader": "^5.0.0",
"yup": "^1.3.3"
},
"scripts": {
Expand Down Expand Up @@ -94,5 +93,9 @@
"react-scripts": "^5.0.1",
"sass": "^1.69.7",
"webpack-cli": "^5.1.4"
},
"overrides": {
"nth-check": "2.1.1",
"postcss": "8.4.49"
}
}
205 changes: 39 additions & 166 deletions src/store/api.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,23 @@
// API Server constant
/* eslint-disable camelcase */
export const katsu = process.env.REACT_APP_KATSU_API_SERVER;
export const federation = `${process.env.REACT_APP_FEDERATION_API_SERVER}/v1`;
export const BASE_URL = process.env.REACT_APP_CANDIG_SERVER;
export const htsget = process.env.REACT_APP_HTSGET_SERVER;
export const TYK_URL = process.env.REACT_APP_TYK_SERVER;
export const INGEST_URL = process.env.REACT_APP_INGEST_SERVER;

// API Calls
/*
Fetch katsu calls
*/
export function fetchKatsu(URL) {
return fetch(`${katsu}/moh/v1/discovery/overview/${URL}`)
.then((response) => {
if (response.ok) {
return response.json();
}
console.log(`Katsu: ${response}`);
throw new Error(`Katsu: ${response}`);
})
.catch((error) => {
console.log(`Error: ${error}`);
return 'error';
});
}

/*
Fetch htsget calls
*/
export function fetchHtsget() {
return fetch(`${federation}/fanout`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
method: 'GET',
path: `ga4gh/drs/v1/objects`,
payload: {},
service: 'htsget'
})
})
.then((response) => {
if (response.ok) {
return response.json();
}
return [];
})
.catch((error) => {
console.log(`Error: ${error}`);
return 'error';
});
export function fetchOrRelogin(...args) {
return fetch(...args).catch((error) => {
if (error.status === 403) {
// The user's token has expired, and they need to refresh the page
window.location.replace('/auth/logout');
} else {
// Wasn't a permission denied -- re-throw the error
throw error;
}
});
}

export function fetchFederationStat(endpoint) {
return fetch(`${federation}/fanout`, {
return fetchOrRelogin(`${federation}/fanout`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand All @@ -79,7 +43,7 @@ export function fetchFederationStat(endpoint) {
Generic querying for federation
*/
export function fetchFederation(path, service) {
return fetch(`${federation}/fanout`, {
return fetchOrRelogin(`${federation}/fanout`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
Expand All @@ -102,125 +66,18 @@ export function fetchFederation(path, service) {
}

/*
Fetch the federation service for clinical search data
*/
/* export function fetchFederationClinicalData() {
// Until I can debug the Tyk error
return new Promise((resolve) => resolve({}));
return fetch(`${federation}/fanout`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
method: 'GET',
path: 'api/mcodepackets',
payload: {},
service: 'katsu'
})
})
.then((response) => {
if (response.ok) {
return response.json();
}
return {};
})
.catch((error) => {
console.log('Error:', error);
return 'error';
});
} */

/*
Fetch peer federation stats from CanDIG federation service
*/
export function fetchSummaryStats(URL) {
return federation !== '' ? fetchFederationStat() : fetchKatsu(URL);
}

/*
Fetch variant for a specific Dataset Id; start; and reference name; and returns a promise
* @param {number}... Start
* @param {number}... End
* @param {string}... Reference name
*/
export function searchVariant(chromosome, start, end, assemblyId = 'hg37') {
const payload = {
query: {
requestParameters: {
referenceName: chromosome,
assemblyId,
start: [parseInt(start, 10) || 0],
end: [parseInt(end, 10) || 100000]
}
},
meta: {
apiVersion: 'v2'
}
};
return fetch(`${federation}/fanout`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
method: 'POST',
path: 'beacon/v2/g_variants',
payload,
service: 'htsget'
})
})
.then((response) => {
if (response.ok) {
return response.json();
}
return [];
})
.catch((error) => {
console.log('Error:', error);
return 'error';
});
}

/*
Fetch variant for a gene name; and returns a promise that contains the results from HTSGet through Federation
* @param {string}... Name of a gene
Query the Query microservice for a page of results
* @param {parameters} passed onto Query as URL parameters
* @param {abort} Abort Controller used to cancel the query
* @param {path} Query API path used to send the request to, assumed to be /query but
* can be used for e.g. /genomic_completeness if need be
*/
export function searchVariantByGene(geneName) {
const payload = {
query: {
requestParameters: {
gene_id: geneName
}
},
meta: {
apiVersion: 'v2'
}
};
return fetch(`${federation}/fanout`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
method: 'POST',
path: 'beacon/v2/g_variants',
payload,
service: 'htsget'
})
})
.then((response) => {
if (response.ok) {
return response.json();
}
return [];
})
.catch((error) => {
console.log('Error:', error);
return 'error';
});
}

export function query(parameters, abort, path = 'query') {
const payload = {
...parameters
};

return fetch(`${federation}/fanout`, {
return fetchOrRelogin(`${federation}/fanout`, {
method: 'post',
signal: abort,
headers: { 'Content-Type': 'application/json' },
Expand Down Expand Up @@ -248,12 +105,15 @@ export function query(parameters, abort, path = 'query') {
});
}

/* The following two functions are both used for the ingest page,
which at this time is unimplemented.
*/

/*
Post a clinical data JSON to Katsu
* @param {string}... Name of a gene
*/
export function ingestClinicalData(data) {
return fetch(`${INGEST_URL}/ingest/clinical_donors`, {
return fetchOrRelogin(`${INGEST_URL}/ingest/clinical_donors`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: data
Expand All @@ -264,9 +124,11 @@ export function ingestClinicalData(data) {
return error;
});
}

/*
Post a clinical data JSON to Katsu
*/
export function ingestGenomicData(data, program_id) {
return fetch(`${INGEST_URL}/ingest/moh_variants/${program_id}`, {
return fetchOrRelogin(`${INGEST_URL}/ingest/moh_variants/${program_id}`, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: data
Expand All @@ -278,6 +140,10 @@ export function ingestGenomicData(data, program_id) {
});
}

/*
* Fetch the genomic completeness stats from Query, returning the results
* as a dictionary of {site: {program (type)} = #}
*/
export function fetchGenomicCompleteness() {
return fetchFederation('genomic_completeness', 'query').then((data) => {
const numCompleteGenomic = {};
Expand All @@ -293,6 +159,10 @@ export function fetchGenomicCompleteness() {
});
}

/*
* Fetch the clinical completeness stats from Query, returning a dictionary
* with: numNodes, numErrorNodes, numDonors, numCompleteDonors, numClinicalComplete, data
*/
export function fetchClinicalCompleteness() {
return fetchFederation('discovery/programs', 'query').then((data) => {
// Step 1: Determine the number of provinces
Expand Down Expand Up @@ -331,8 +201,11 @@ export function fetchClinicalCompleteness() {
});
}

/*
* Directly query Query for the /get-tokene endpoint, which reflects our refresh token.
*/
export function fetchRefreshToken() {
return fetch(`${INGEST_URL}/get-token`)
return fetchOrRelogin(`${INGEST_URL}/get-token`)
.then((response) => response.json())
.catch((error) => {
console.log('Error:', error);
Expand Down
Loading

0 comments on commit 05c0121

Please sign in to comment.