Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from odpi/react
Browse files Browse the repository at this point in the history
Merge #react with #main
  • Loading branch information
sarbull authored Sep 23, 2022
2 parents 5509991 + 0d2992a commit b450064
Show file tree
Hide file tree
Showing 62 changed files with 1,065 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
52 changes: 52 additions & 0 deletions dist/esm/api/data/glossaries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { apiUrl } from '../';
import { authHeader, handleResponse } from '../../auth';
export const glossaries = {
getAll,
getGlossaryCategories,
getGlossaryTerms
};
/**
*
* HTTP API request for retrieving all the asset types.
*
* @since 0.1.0
* @access public
*
*
* @return {Promise} Returns a promise with the request.
*
*/
function getAll() {
const requestOptions = { method: 'GET', headers: authHeader() };
return fetch(`${apiUrl()}/api/glossaries`, requestOptions).then(handleResponse);
}
/**
*
* HTTP API request for retrieving all the glossary categories.
*
* @since 0.1.0
* @access public
*
*
* @return {Promise} Returns a promise with the request.
*
*/
function getGlossaryCategories() {
const requestOptions = { method: 'GET', headers: authHeader() };
return fetch(`${apiUrl()}/api/glossaries/categories`, requestOptions).then(handleResponse);
}
/**
*
* HTTP API request for retrieving all the glossary terms.
*
* @since 0.1.0
* @access public
*
*
* @return {Promise} Returns a promise with the request.
*
*/
function getGlossaryTerms() {
const requestOptions = { method: 'GET', headers: authHeader() };
return fetch(`${apiUrl()}/api/glossaries/terms`, requestOptions).then(handleResponse);
}
22 changes: 22 additions & 0 deletions dist/esm/api/data/lineage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { authHeader, handleResponse } from '../../auth';
import { apiUrl } from '../';
function getLineageTypes() {
const requestOptions = { method: 'GET', headers: authHeader() };
return fetch(`${apiUrl()}/api/lineage/types`, requestOptions).then(handleResponse);
}
function getNameSuggestions(name, type) {
const requestOptions = { method: 'GET', headers: authHeader() };
let url = `${apiUrl()}/api/lineage/nodes`;
if (type) {
url = `${url}?type=${type.trim()}`;
if (name) {
url = `${url}&name=${name.trim()}`;
}
url = `${url}&limit=10`;
}
return fetch(url, requestOptions).then(handleResponse);
}
export const lineage = {
getLineageTypes,
getNameSuggestions
};
20 changes: 20 additions & 0 deletions dist/esm/api/data/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { apiUrl } from '../';
import { authHeader, handleResponse } from '../../auth';
export const types = {
getAll
};
/**
*
* HTTP API request for retrieving all the asset types.
*
* @since 0.1.0
* @access public
*
*
* @return {Promise} Returns a promise with the request.
*
*/
function getAll() {
const requestOptions = { method: 'GET', headers: authHeader() };
return fetch(`${apiUrl()}/api/assets/types`, requestOptions).then(handleResponse);
}
7 changes: 7 additions & 0 deletions dist/esm/api/egeria-fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { handleResponse } from '../auth';
const egeriaFetch = (endpoint, method, headers, options) => {
const requestOptions = Object.assign({ method: method, headers: headers }, options);
const apiUrl = process.env.REACT_APP_API_URL || '';
return fetch(`${apiUrl}${endpoint}`, requestOptions).then(handleResponse);
};
export { egeriaFetch };
13 changes: 13 additions & 0 deletions dist/esm/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { glossaries } from './data/glossaries';
import { lineage } from './data/lineage';
import { types } from './data/types';
import { egeriaFetch } from './egeria-fetch';
const apiUrl = () => {
return `${process.env.REACT_APP_API_URL}`;
};
function goHome() {
console.log('WENT HOME');
window.location.href = '/';
}
;
export { apiUrl, egeriaFetch, glossaries, goHome, lineage, types };
23 changes: 23 additions & 0 deletions dist/esm/auth/auth-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { currentJwt } from "./current-jwt";
export function authHeader() {
const _currentJwt = currentJwt();
if (_currentJwt) {
return { "x-auth-token": _currentJwt };
}
else {
return {};
}
}
export function authHeaderWithContentType() {
const _currentJwt = currentJwt();
if (_currentJwt) {
return {
"x-auth-token": _currentJwt,
"Content-Type": "application/json",
"accept": "application/json"
};
}
else {
return {};
}
}
3 changes: 3 additions & 0 deletions dist/esm/auth/current-jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function currentJwt() {
return localStorage.getItem('currentJwt');
}
10 changes: 10 additions & 0 deletions dist/esm/auth/handle-response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { logout } from './logout';
export function handleResponse(response) {
if (!response.ok) {
if ([401, 403].indexOf(response.status) !== -1) {
logout();
}
return Promise.reject();
}
return response;
}
8 changes: 8 additions & 0 deletions dist/esm/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { authHeader, authHeaderWithContentType } from './auth-header';
import { currentJwt } from './current-jwt';
import { login } from './login';
import { logout } from './logout';
import { parseJwt } from './parse-jwt';
import { setToken } from './set-token';
import { handleResponse } from './handle-response';
export { authHeader, authHeaderWithContentType, currentJwt, handleResponse, login, logout, parseJwt, setToken };
16 changes: 16 additions & 0 deletions dist/esm/auth/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { setToken } from './set-token';
export function login(username, password, apiUrl) {
const requestOptions = {
method: 'POST',
body: new URLSearchParams(`username=${username}&password=${password}`)
};
return fetch(`${apiUrl}`, requestOptions)
.then((response) => {
if (response.ok) {
const token = response.headers.get('x-auth-token');
setToken(token);
console.log("LOGGED IN");
}
return response;
});
}
7 changes: 7 additions & 0 deletions dist/esm/auth/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const logout = (logoutCallback) => {
localStorage.removeItem('currentJwt');
console.log('LOGGED OUT');
if (logoutCallback) {
logoutCallback();
}
};
10 changes: 10 additions & 0 deletions dist/esm/auth/parse-jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function parseJwt(token) {
if (token !== "") {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
}
}
5 changes: 5 additions & 0 deletions dist/esm/auth/set-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function setToken(token) {
const _token = token || '';
localStorage.setItem('currentJwt', _token);
console.log('TOKEN SAVED');
}
4 changes: 4 additions & 0 deletions dist/esm/capitalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function capitalize(s) {
return s && s[0].toUpperCase() + s.slice(1);
}
export { capitalize };
4 changes: 4 additions & 0 deletions dist/esm/get-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const getComponent = (id) => {
return document.querySelector(id);
};
export { getComponent };
Loading

0 comments on commit b450064

Please sign in to comment.