diff --git a/demo/vue/app/config/test.json b/demo/vue/app/config/test.json index c1a26a59..a9e42a98 100644 --- a/demo/vue/app/config/test.json +++ b/demo/vue/app/config/test.json @@ -12,11 +12,5 @@ "clientSecret": "password" }, "logLevel": "silent" - }, - "serviceClient": { - "customService": { - "username": "username", - "password": "password" - } } -} \ No newline at end of file +} diff --git a/demo/vue/app/src/components/cdogsService.js b/demo/vue/app/src/components/cdogsService.js deleted file mode 100644 index 9d047286..00000000 --- a/demo/vue/app/src/components/cdogsService.js +++ /dev/null @@ -1,144 +0,0 @@ -const config = require('config'); -const crypto = require('crypto'); -const FormData = require('form-data'); -const fs = require('fs-extra'); - -const ClientConnection = require('./clientConnection'); -const errorToProblem = require('./errorToProblem'); -const log = require('./log')(module.filename); - -const SERVICE = 'CDOGS'; - -class CdogsService { - constructor({ tokenUrl, clientId, clientSecret, apiUrl }) { - log.verbose(`Constructed with ${tokenUrl}, ${clientId}, clientSecret, ${apiUrl}`, { function: 'constructor' }); - if (!tokenUrl || !clientId || !clientSecret || !apiUrl) { - log.error('Invalid configuration.', { function: 'constructor' }); - throw new Error('CdogsService is not configured. Check configuration.'); - } - this.connection = new ClientConnection({ tokenUrl, clientId, clientSecret }); - this.axios = this.connection.axios; - this.apiUrl = apiUrl; - this.apiV2 = `${this.apiUrl}/v2`; - } - - async health() { - try { - const url = `${this.apiV2}/health`; - log.debug(`GET to ${url}`, { function: 'health' }); - - const { data, status } = await this.axios.get(url, { - headers: { - 'Content-Type': 'application/json' - } - }); - - return { data, status }; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async templateUploadAndRender(body) { - try { - const url = `${this.apiV2}/template/render`; - log.debug(`POST to ${url}`, { function: 'templateUploadAndRender' }); - - const { data, headers, status } = await this.axios.post(url, body, { - responseType: 'arraybuffer' // Needed for binaries unless you want pain - }); - - return { data, headers, status }; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async templateRender(templateId, body) { - try { - const url = `${this.apiV2}/template/${templateId}/render`; - log.debug(`POST to ${url}`, { function: 'templateRender' }); - - const { data, headers, status } = await this.axios.post(url, body, { - headers: { - 'content-type': 'application/json' - }, - responseType: 'arraybuffer' - }); - - return { data, headers, status }; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async getTemplate(templateId) { - try { - const url = `${this.apiV2}/template/${templateId}`; - log.debug(`GET to ${url}`, { function: 'getTemplate' }); - - const { data, status } = await this.axios.get(url, { - headers: { - 'Content-Type': 'application/json' - } - }); - - return { data, status }; - } catch (e) { - if (e.response && e.response.status === 404) { - return { data: 'Not Found', status: 404 }; - } - errorToProblem(SERVICE, e); - } - } - - async uploadTemplate(path) { - try { - const form = new FormData(); - form.append('template', fs.createReadStream(path)); - - const url = `${this.apiV2}/template`; - log.debug(`POST to ${url}`, { function: 'uploadTemplate' }); - - const { data, headers, status } = await this.axios( - { - method: 'post', - url: url, - data: form, - headers: { - 'content-type': `multipart/form-data; boundary=${form._boundary}`, - }, - } - ); - - return { data, headers, status }; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async getHash(file) { - const hash = crypto.createHash('sha256'); - const stream = fs.createReadStream(file); - return new Promise((resolve, reject) => { - stream.on('readable', () => { - let chunk; - while (null !== (chunk = stream.read())) { - hash.update(chunk); - } - }); - stream.on('end', () => resolve(hash.digest('hex'))); - stream.on('error', error => reject(error)); - }); - } - - -} - -const endpoint = config.get('serviceClient.commonServices.cdogs.endpoint'); -const tokenEndpoint = config.get('serviceClient.commonServices.tokenEndpoint'); -const username = config.get('serviceClient.commonServices.username'); -const password = config.get('serviceClient.commonServices.password'); - -let cdogsService = new CdogsService({tokenUrl: tokenEndpoint, clientId: username, clientSecret: password, apiUrl: endpoint}); -module.exports = cdogsService; diff --git a/demo/vue/app/src/components/chesService.js b/demo/vue/app/src/components/chesService.js deleted file mode 100644 index a7b5d932..00000000 --- a/demo/vue/app/src/components/chesService.js +++ /dev/null @@ -1,154 +0,0 @@ -const config = require('config'); - -const ClientConnection = require('./clientConnection'); -const errorToProblem = require('./errorToProblem'); -const log = require('./log')(module.filename); - -const SERVICE = 'CHES'; - -class ChesService { - constructor({tokenUrl, clientId, clientSecret, apiUrl}) { - log.verbose(`Constructed with ${tokenUrl}, ${clientId}, clientSecret, ${apiUrl}`, { function: 'constructor' }); - if (!tokenUrl || !clientId || !clientSecret || !apiUrl) { - log.error('Invalid configuration.', { function: 'constructor' }); - throw new Error('ChesService is not configured. Check configuration.'); - } - this.connection = new ClientConnection({ tokenUrl, clientId, clientSecret }); - this.axios = this.connection.axios; - this.apiUrl = apiUrl; - this.apiV1 = `${this.apiUrl}/v1`; - } - - async health() { - try { - const response = await this.axios.get( - `${this.apiV1}/health`, - { - headers: { - 'Content-Type': 'application/json' - } - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async statusQuery(params) { - try { - const response = await this.axios.get( - `${this.apiV1}/status`, - { - params: params, - headers: { - 'Content-Type': 'application/json' - } - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async cancelMsg(msgId) { - try { - const response = await this.axios.delete( - `${this.apiV1}/cancel/${msgId}`, - { - headers: { - 'Content-Type': 'application/json' - } - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async cancelQuery(params) { - try { - const response = await this.axios.delete( - `${this.apiV1}/cancel`, - { - params: params, - headers: { - 'Content-Type': 'application/json' - } - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async send(email) { - try { - const response = await this.axios.post( - `${this.apiV1}/email`, - email, - { - headers: { - 'Content-Type': 'application/json' - }, - maxContentLength: Infinity, - maxBodyLength: Infinity - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - - async merge(data) { - try { - const response = await this.axios.post( - `${this.apiV1}/emailMerge`, - data, - { - headers: { - 'Content-Type': 'application/json' - }, - maxContentLength: Infinity, - maxBodyLength: Infinity - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - - async preview(data) { - try { - const response = await this.axios.post( - `${this.apiV1}/emailMerge/preview`, - data, - { - headers: { - 'Content-Type': 'application/json' - }, - maxContentLength: Infinity, - maxBodyLength: Infinity - } - ); - return response.data; - } catch (e) { - errorToProblem(SERVICE, e); - } - } - -} - -const endpoint = config.get('serviceClient.commonServices.ches.endpoint'); -const tokenEndpoint = config.get('serviceClient.commonServices.tokenEndpoint'); -const username = config.get('serviceClient.commonServices.username'); -const password = config.get('serviceClient.commonServices.password'); - -let chesService = new ChesService({tokenUrl: tokenEndpoint, clientId: username, clientSecret: password, apiUrl: endpoint}); -module.exports = chesService;