From c2c9179448bf96d8a0ce9a20f6e7d669f8b0ef01 Mon Sep 17 00:00:00 2001 From: Chris Grayson Date: Fri, 15 Mar 2024 15:33:03 -0500 Subject: [PATCH] reworked UI for token credential --- index.js | 2 +- lib/authjson.js | 2 +- lib/ui/public/app/auth/Auth.vue | 88 ++++++++++++++++++++++++--------- lib/ui/public/app/store.js | 10 ++-- lib/ui/public/index.html | 1 - test/authjson-spec.js | 9 ++-- test/json-spec.js | 3 +- 7 files changed, 79 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 9bbe00b..086912a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ module.exports = { outbound: { - authenticated_json: require('./lib/authjson'), + token_authenticated: require('./lib/authjson'), json: require('./lib/json') }, ui: require('./lib/ui') diff --git a/lib/authjson.js b/lib/authjson.js index 3b3b58c..406e460 100644 --- a/lib/authjson.js +++ b/lib/authjson.js @@ -8,7 +8,7 @@ const validate = (vars) => { if (baseValidation) { return baseValidation; } - if (!vars.credential_id) return 'credential ID is required'; + if (!vars.credential_id || vars.credential?.type !== 'token') return 'ID of token credential is required'; if (!vars.authentication_url) return 'authentication URL is required'; }; diff --git a/lib/ui/public/app/auth/Auth.vue b/lib/ui/public/app/auth/Auth.vue index 29c95e7..d68fa94 100644 --- a/lib/ui/public/app/auth/Auth.vue +++ b/lib/ui/public/app/auth/Auth.vue @@ -1,49 +1,91 @@ + + diff --git a/lib/ui/public/app/store.js b/lib/ui/public/app/store.js index 684c787..1b0b1bb 100644 --- a/lib/ui/public/app/store.js +++ b/lib/ui/public/app/store.js @@ -21,7 +21,7 @@ const initStore = (config, ui) => new Vuex.Store({ Vue.set(state, 'parsedFields', fields); }, setJson (state, json) { - Vue.set(state, 'rawJson', json) + Vue.set(state, 'rawJson', json); }, setResponseOpts (state, { outcomePath, outcomeTerm, reasonPath }) { Vue.set(state, 'outcomePath', outcomePath); @@ -33,7 +33,7 @@ const initStore = (config, ui) => new Vuex.Store({ } }, getters: { - getCredential: (state, getters) => { + getCredential: () => { return config.credential; } }, @@ -41,7 +41,7 @@ const initStore = (config, ui) => new Vuex.Store({ cancel (context) { context.state.ui.cancel(); }, - createCredential(context, credential) { + saveCredential(context, credential) { if (!credential.id) credential.id = new ObjectID().toHexString(); context.state.ui.create({ credential }); }, @@ -58,7 +58,7 @@ const initStore = (config, ui) => new Vuex.Store({ id: config.entity.id }, integration: { - module_id: config.integration, + module_id: config.credential?.type === 'token' ? 'leadconduit-json.outbound.token_authenticated' : 'leadconduit-json.outbound.json', mappings: [{ property: 'credential_id', value: (config.credential) ? config.credential.id : undefined @@ -74,7 +74,7 @@ const initStore = (config, ui) => new Vuex.Store({ }, { property: 'reason_path', value: context.state.reasonPath - }].filter((mapping) => { return mapping.value }) + }].filter((mapping) => { return mapping.value; }) } }] }; diff --git a/lib/ui/public/index.html b/lib/ui/public/index.html index ffb965c..fd295f6 100644 --- a/lib/ui/public/index.html +++ b/lib/ui/public/index.html @@ -1,7 +1,6 @@ Leadconduit Integration -
diff --git a/test/authjson-spec.js b/test/authjson-spec.js index b3e171a..3d9928e 100644 --- a/test/authjson-spec.js +++ b/test/authjson-spec.js @@ -1,7 +1,7 @@ const { assert } = require('chai'); const { requestVariables, validate } = require('../lib/authjson'); -describe('Authenticated JSON', function () { +describe('Token Authenticated', function () { describe('Request variables', function () { it('makes credential_id required', function () { @@ -18,7 +18,10 @@ describe('Authenticated JSON', function () { vars = { url: 'https://example.com/deliver', credential_id: 'abc123', - authentication_url: 'https://example.com/authenticate' + authentication_url: 'https://example.com/authenticate', + credential: { + type: 'token' + } }; }); @@ -33,7 +36,7 @@ describe('Authenticated JSON', function () { it('fails when missing credential ID', function () { delete vars.credential_id; - assert.equal(validate(vars), 'credential ID is required'); + assert.equal(validate(vars), 'ID of token credential is required'); }); it('fails when missing auth URL', function () { diff --git a/test/json-spec.js b/test/json-spec.js index f09cadb..d25cafc 100644 --- a/test/json-spec.js +++ b/test/json-spec.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.10.0 (function() { var assert, integration, types; @@ -217,7 +216,7 @@ return assert.equal(integration.validate({ url: 'http://foo.com', method: 'HEAD' - }), 'Unsupported HTTP method - use POST, PUT, DELETE'); + }), 'Unsupported HTTP method - use POST, PUT, DELETE, PATCH'); }); it('should require valid search outcome', function() { return assert.equal(integration.validate({