Skip to content

Commit

Permalink
Sc 77184/trustedform v4 verify add 1 1 consent check (#121)
Browse files Browse the repository at this point in the history
* Add 1:1 consent filter and advertiser name request field
  • Loading branch information
henriquelakiap authored Sep 26, 2024
1 parent 703b4a6 commit f10a6b8
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 34 deletions.
27 changes: 16 additions & 11 deletions lib/trustedform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { get } = require('lodash');
const helpers = require('./helpers');
const { compact, pickBy, isUndefined } = require('lodash');
const { compact, get, pickBy, isUndefined } = require('lodash');

const request = (vars) => {
const { lead, trustedform, insights } = vars;
Expand Down Expand Up @@ -29,8 +28,10 @@ const request = (vars) => {
};
}
}

if (trustedform.verify?.valueOf()) {
body.verify = {};
const advertiserName = trustedform?.advertiser_name;
body.verify = pickBy({ advertiser_name: advertiserName }, (v) => { return !isUndefined(v); });
}

return {
Expand Down Expand Up @@ -108,7 +109,8 @@ request.variables = () => [
{ name: 'trustedform.scan_forbidden_text', type: 'array', required: false, description: 'A list of forbidden text to scan for. TrustedForm will then perform a case and whitespace insensitive search for the string.' },
{ name: 'trustedform.scan_delimiter', type: 'string', required: false, description: 'Use this parameter to designate a delimiter when wrapping wildcards or template variables; defaults to |.' },

{ name: 'trustedform.verify', type: 'boolean', required: true, description: 'If true, a request to the Verify product will be made'}
{ name: 'trustedform.verify', type: 'boolean', required: true, description: 'If true, a request to the Verify product will be made'},
{ name: 'trustedform.advertiser_name', type: 'string', required: false, description: 'The name of the legal entity for an advertiser that will be used to determine if they were given consent in a one to one manner. This value will be normalized to be case insensitive, ignore redundant white space and omit non ascii characters. Both \'Acme Inc.\' and \'acme inc\' would result in the same processed value.' }
];

const validate = (vars) => {
Expand All @@ -126,20 +128,21 @@ const verifyEnabled = (vars) => vars.trustedform?.verify?.valueOf();
const hasRequiredRetainProps = (vars) => !!(vars.lead.email || vars.lead.phone_1);
const hasAtLeastOneInsightsProp = (vars) => formatProperties(vars.insights).length > 0 || vars.insights?.page_scan?.valueOf();
const hasVerifyData = (data) => {
return data.verify?.languages || data.verify?.result?.language_approved || data.verify?.result?.success;
return data.verify?.languages || data.verify?.result?.language_approved || data.verify?.result?.success || data.verify?.result?.one_to_one;
};

const response = (vars, req, res) => {
if (res.status < 500) {
try {
const parsed = JSON.parse(res.body);
if (res.status === 200) {
const verify = hasVerifyData(parsed) ?
{
languages: parsed.verify.languages.map(lang => lang.text),
language_approved: parsed.verify.result.language_approved,
success: parsed.verify.result.success
} : undefined;
const verify = hasVerifyData(parsed)
? pickBy({
languages: parsed.verify.languages.map(lang => lang.text),
language_approved: parsed.verify.result.language_approved,
success: parsed.verify.result.success,
}, (v) => !isUndefined(v))
: undefined;

const appended = pickBy({
outcome: parsed.outcome,
Expand Down Expand Up @@ -188,6 +191,7 @@ const response = (vars, req, res) => {
os_name: parsed.insights?.properties?.os?.name,
page_url: parsed.insights?.properties?.page_url,
parent_page_url: parsed.insights?.properties?.parent_page_url,
one_to_one: parsed.verify?.result?.one_to_one,
verify
}, (v) => { return !isUndefined(v); });
// only include this property if page scan was selected
Expand Down Expand Up @@ -262,6 +266,7 @@ response.variables = () => [
{ name: 'os_name', type: 'string', description: 'Operating system name' },
{ name: 'page_url', type: 'string', description: 'The URL of the page hosting TrustedForm Certify.' },
{ name: 'parent_page_url', type: 'string', description: 'The parent URL of the page hosting TrustedForm Certify, if framed.' },
{ name: 'one_to_one', type: 'boolean', description: 'A boolean indicating if the cert structure satisfied the requirements for 1:1 consent.' },
{ name: 'verify.languages', type: 'array', description: 'A list of the consent languages detected within the certificate' },
{ name: 'verify.language_approved', type: 'boolean', description: 'A boolean indicating if any of the consent languages found have been approved in your account\'s consent language manager.' },
{ name: 'verify.success', type: 'boolean', description: 'A boolean indicating if any of the consent languages found meet the success criteria defined for your account.' },
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/public/app/config/Page1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default {
},
mounted () {
const { integration } = this.$store.state.config;
if (integration.includes('outbound.trustedform')) this.$router.push('/4');
if (integration.includes('outbound.trustedform')) {
this.$router.push('/4');
}
else if (!integration.includes('insights')) {
this.isDataService = false;
}
Expand Down
14 changes: 12 additions & 2 deletions lib/ui/public/app/config/Page4.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
:showPrevious="false"
:onConfirm="confirm"
:disableConfirm="!products.retain.selected && !products.insights.selected && !products.verify.selected"
:navHistory="navHistory"
/>
</div>
</template>
Expand All @@ -54,7 +55,8 @@ export default {
return {
loading: true,
products: this.$store.getters.getProducts,
errors: this.$store.getters.getErrors
errors: this.$store.getters.getErrors,
navHistory: this.$store.getters.getNavHistory
};
},
components: {
Expand All @@ -67,9 +69,17 @@ export default {
},
methods: {
confirm () {
this.$store.commit('resetNavHistory');
this.$store.commit('setNavHistory', '/4');
this.$store.state.products = this.products;
if (this.products.insights.selected) {
if (this.products.insights.selected && this.products.verify.selected) {
this.$router.push('/5');
this.$store.commit('setShouldConfigVerify', true);
} else if (this.products.insights.selected) {
this.$store.commit('setShouldConfigVerify', false);
this.$router.push('/5');
} else if (this.products.verify.selected) {
this.$router.push('/7');
} else {
this.$store.dispatch('confirm');
}
Expand Down
13 changes: 10 additions & 3 deletions lib/ui/public/app/config/Page5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Navigation
:onConfirm="confirm"
:disableConfirm="selected === 'none'"
:navHistory="navHistory"
/>
</div>
</template>
Expand All @@ -46,7 +47,8 @@ export default {
return {
fields: this.$store.state.v4Fields,
header: false,
selected: 'none'
selected: 'none',
navHistory: this.$store.getters.getNavHistory
};
},
components: {
Expand Down Expand Up @@ -74,10 +76,15 @@ export default {
this.header = this.selected === 'all';
},
confirm () {
this.$store.commit('setNavHistory', '/5');
const shouldConfigVerify = this.$store.getters.getShouldConfigVerify;
this.$store.state.v4Fields = this.fields;
if (this.fields.page_scan?.selected) {
this.$router.push('/6')
return
this.$router.push('/6');
return;
} else if (shouldConfigVerify) {
this.$router.push('/7');
return;
}
this.$store.dispatch('confirm');
}
Expand Down
14 changes: 11 additions & 3 deletions lib/ui/public/app/config/Page6.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Navigation
:onConfirm="confirm"
:disableConfirm="false"
:navHistory="navHistory"
/>
</div>
</template>
Expand All @@ -59,7 +60,9 @@ export default {
forbiddenTags: [],
/** @type {string[]} */
forbiddenOptions: [],
}
/** @type {string[]} */
navHistory: this.$store.getters.getNavHistory
};
},
methods: {
handleRequiredTag(tag) {
Expand All @@ -71,14 +74,19 @@ export default {
this.forbiddenOptions.push(tag);
},
confirm() {
this.$store.commit('setNavHistory', '/6')
this.$store.commit('setPageScan', {
required: this.requiredTags,
forbidden: this.forbiddenTags
});
this.$store.dispatch('confirm');
if (this.$store.getters.getShouldConfigVerify) {
this.$router.push('/7');
} else {
this.$store.dispatch('confirm');
}
},
}
}
};
</script>

<style scoped>
Expand Down
62 changes: 62 additions & 0 deletions lib/ui/public/app/config/Page7.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<template>
<div>
<header>
Configure TrustedForm Verify
</header>
<section>
<p>
Enter the name of the legal entity for an advertiser that will be used to determine if they
were given consent in a one to one manner.
</p>
<Form :actions="false">
<input
v-model="advertiserName"
type="text"
placeholder="(optional) keep empty if you don't need to check one-to-one consent"
></input>
</Form>
</section>
<Navigation
:onConfirm="confirm"
:disableConfirm="false"
:navHistory="navHistory"
/>
</div>
</template>

<script>
import { Navigation } from '@activeprospect/integration-components';
import { TextField, Form } from '@activeprospect/ui-components';
export default {
components: {
Navigation,
TextField,
Form
},
data() {
return {
/** @type {string} */
advertiserName: "",
/** @type {string[]} */
navHistory: this.$store.getters.getNavHistory
};
},
methods: {
confirm() {
this.$store.commit('setAdvertiserName', {
advertiserName: this.advertiserName
});
this.$store.dispatch('confirm');
},
}
};
</script>

<style scoped>
input {
width: 65%;
}
</style>
6 changes: 6 additions & 0 deletions lib/ui/public/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PageThree from './config/Page3.vue';
import PageFour from './config/Page4.vue';
import PageFive from './config/Page5.vue';
import PageSix from './config/Page6.vue';
import PageSeven from './config/Page7.vue';

export default createRouter({
history: createMemoryHistory(),
Expand Down Expand Up @@ -45,6 +46,11 @@ export default createRouter({
path: '6',
name: 'PageSix',
component: PageSix
},
{
path: '7',
name: 'PageSeven',
component: PageSeven
}
]
}
Expand Down
Loading

0 comments on commit f10a6b8

Please sign in to comment.