From fdb05403d267c74a19bb4d7527805c7ea85362b0 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 20 Aug 2019 15:36:57 +0200 Subject: [PATCH] Use utils from common --- packages/auth/src/utils.js | 58 ------------------------------ packages/auth/src/vars.js | 35 ------------------ packages/auth/src/vpu-auth-demo.js | 3 +- packages/auth/src/vpu-auth.js | 3 +- packages/auth/vendor/common | 2 +- 5 files changed, 3 insertions(+), 98 deletions(-) delete mode 100644 packages/auth/src/utils.js delete mode 100644 packages/auth/src/vars.js diff --git a/packages/auth/src/utils.js b/packages/auth/src/utils.js deleted file mode 100644 index 7e96c124..00000000 --- a/packages/auth/src/utils.js +++ /dev/null @@ -1,58 +0,0 @@ -import vars from './vars.js'; - -export default { - getAPiUrl: function(path = "", withPrefix = true) { - return vars.apiBaseUrl + (withPrefix ? vars.apiUrlPrefix : "") + path; - }, - - /** - * Parses a link header - * - * The node module parse-link-header didn't work, so https://gist.github.com/niallo/3109252 became handy - * - * @param header - */ - parseLinkHeader: (header) => { - if (header.length === 0) { - throw new Error("input must not be of zero length"); - } - - // Split parts by comma - const parts = header.split(','); - const links = {}; - - // Parse each part into a named link - for(let i=0; i<parts.length; i++) { - const section = parts[i].split(';'); - if (section.length !== 2) { - throw new Error("section could not be split on ';'"); - } - const url = section[0].replace(/<(.*)>/, '$1').trim(); - const name = section[1].replace(/rel="(.*)"/, '$1').trim(); - links[name] = url; - } - - return links; - }, - - /** - * Parses the base url from an url - * - * @param url - * @returns {string} - */ - parseBaseUrl: (url) => { - const pathArray = url.split('/'); - const protocol = pathArray[0]; - const host = pathArray[2]; - return protocol + '//' + host; - }, - - /** - * Reads a setting - * - * @param key - * @returns {*} - */ - setting: (key) => vars[key] -}; diff --git a/packages/auth/src/vars.js b/packages/auth/src/vars.js deleted file mode 100644 index 741b34e2..00000000 --- a/packages/auth/src/vars.js +++ /dev/null @@ -1,35 +0,0 @@ -var config = undefined; - -switch(process.env.BUILD) { - case "development": - config = { - apiBaseUrl: 'https://mw-dev.tugraz.at', - apiUrlPrefix: '', - keyCloakClientId: 'auth-dev-mw-frontend', - }; - - break; - case "production": - config = { - apiBaseUrl: 'https://mw.tugraz.at', - apiUrlPrefix: '', - keyCloakClientId: 'auth-prod-mw-frontend', - }; - break; - case "demo": - config = { - apiBaseUrl: 'https://api-demo.tugraz.at', - apiUrlPrefix: '', - keyCloakClientId: 'auth-dev-mw-frontend', - }; - break; - case "local": - default: - config = { - apiBaseUrl: 'http://127.0.0.1:8000', - apiUrlPrefix: '', - keyCloakClientId: 'auth-dev-mw-frontend-local', - }; -} - -export default config; diff --git a/packages/auth/src/vpu-auth-demo.js b/packages/auth/src/vpu-auth-demo.js index 55f67106..49553319 100644 --- a/packages/auth/src/vpu-auth-demo.js +++ b/packages/auth/src/vpu-auth-demo.js @@ -1,4 +1,3 @@ -import utils from './utils.js'; import {i18n} from './i18n.js'; import {html, LitElement} from 'lit-element'; import './vpu-auth'; @@ -37,7 +36,7 @@ class AuthDemo extends LitElement { <h1 class="title">Auth-Demo</h1> </div> <div class="container"> - <vpu-auth lang="${this.lang}" client-id="${utils.setting('keyCloakClientId')}" load-person></vpu-auth> + <vpu-auth lang="${this.lang}" client-id="${commonUtils.setting('keyCloakClientId')}" load-person></vpu-auth> </div> </section> `; diff --git a/packages/auth/src/vpu-auth.js b/packages/auth/src/vpu-auth.js index b1198740..e2bdb65e 100644 --- a/packages/auth/src/vpu-auth.js +++ b/packages/auth/src/vpu-auth.js @@ -1,7 +1,6 @@ import {i18n} from './i18n.js'; import {html, LitElement} from 'lit-element'; import JSONLD from 'vpu-common/jsonld' -import utils from "./utils"; import commonUtils from 'vpu-common/utils'; /** @@ -94,7 +93,7 @@ class VPUAuth extends LitElement { that.dispatchInitEvent(); if (that.loadPerson) { - JSONLD.initialize(utils.getAPiUrl(), (jsonld) => { + JSONLD.initialize(commonUtils.getAPiUrl(), (jsonld) => { // find the correct api url for the current person // we are fetching the logged-in person directly to respect the REST philosophy // see: https://github.com/api-platform/api-platform/issues/337 diff --git a/packages/auth/vendor/common b/packages/auth/vendor/common index 378256b0..fdcb4c14 160000 --- a/packages/auth/vendor/common +++ b/packages/auth/vendor/common @@ -1 +1 @@ -Subproject commit 378256b0ae92712fd5b8feed3a987cd014617c0b +Subproject commit fdcb4c14ef0375b5dc61d48ca4f59bd6c2561708 -- GitLab