Skip to content

Commit

Permalink
Add 1:1 consent filter and advertiser name request field
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquelakiap committed Sep 25, 2024
1 parent b382768 commit 91fbffa
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
23 changes: 13 additions & 10 deletions lib/trustedform.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,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 +110,7 @@ request.variables = () => [
{ 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: 'verify.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.' }
{ 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 @@ -134,13 +136,13 @@ const response = (vars, req, res) => {
try {
const parsed = JSON.parse(res.body);
if (res.status === 200) {
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,
one_to_one: parsed.verify.result.one_to_one
}, (v) => { return !isUndefined(v); }) : 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 @@ -189,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 @@ -263,10 +266,10 @@ 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., and is available to use in filters' },
{ 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.' },
{ name: 'verify.one_to_one', type: 'boolean', description: 'A boolean indicating if the consent was given in a one to one manner.' }
];

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/public/app/config/Page4.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default {
this.$store.state.products = this.products;
if (this.products.insights.selected && this.products.verify.selected) {
this.$router.push('/5');
this.$store.dispatch('setShouldConfigVerify', true);
this.$store.commit('setShouldConfigVerify', true);
} else if (this.products.insights.selected) {
this.$router.push('/5');
} else if (this.products.verify.selected) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/public/app/config/Page5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default {
this.header = this.selected === 'all';
},
confirm () {
const shouldConfigVerify = this.$store.dispatch('getShouldConfigVerify');
const shouldConfigVerify = this.$store.getters.getShouldConfigVerify;
this.$store.state.v4Fields = this.fields;
if (this.fields.page_scan?.selected) {
this.$router.push('/6');
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/public/app/config/Page6.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
forbidden: this.forbiddenTags
});
const shouldConfigVerify = this.$store.dispatch('getShouldConfigVerify');
const shouldConfigVerify = this.$store.getters.getShouldConfigVerify;
if (shouldConfigVerify) {
this.$router.push('/7');
} else {
Expand Down
35 changes: 12 additions & 23 deletions lib/ui/public/app/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createStore } from 'vuex';
import fieldData from './fieldData';
import v4Fields from './v4fields';
import axios from 'axios';
import { assign, castArray, get, isArray, set } from 'lodash';
import { castArray, get, set } from 'lodash';
import { toRaw } from 'vue';

const initStore = (config, ui) => createStore({
Expand Down Expand Up @@ -42,14 +42,20 @@ const initStore = (config, ui) => createStore({
},
setAdvertiserName(state, {advertiserName}) {
state.advertiserName = advertiserName;
}
},
setShouldConfigVerify(state, shouldConfigVerify) {
state.shouldConfigVerify = shouldConfigVerify;
},
},
getters: {
getProducts: (state) => {
return state.products;
},
getErrors: (state) => {
return state.errors;
},
getShouldConfigVerify: (state) => {
return state.shouldConfigVerify;
}
},
actions: {
Expand Down Expand Up @@ -82,24 +88,13 @@ const initStore = (config, ui) => createStore({
});
},
createFilter(context, filterConfig) {
let rules;
if (isArray(filterConfig.rules)) {
rules = filterConfig.rules.map(rule => {
const rules = filterConfig.rules.map(rule => {
return {
op: rule.rulesOp,
lhv: rule.lhv,
rhv: rule.rhv
};
});
} else {
rules = {
rules: [{
op: filterConfig.rulesOp,
lhv: filterConfig.lhv,
rhv: filterConfig.rhv
}]
};
}

const filter = {
type: 'filter',
Expand Down Expand Up @@ -165,7 +160,7 @@ const initStore = (config, ui) => createStore({

if(advertiserName) {
flow.steps[0].integration.mappings.push({
property: 'verify.advertiser_name',
property: 'trustedform.advertiser_name',
value: advertiserName
});
}
Expand All @@ -180,7 +175,7 @@ const initStore = (config, ui) => createStore({
{ ...verifyRules },
{
rulesOp: 'is false',
lhv: 'trustedform.verify.one_to_one',
lhv: 'trustedform.one_to_one',
}
];

Expand All @@ -192,7 +187,7 @@ const initStore = (config, ui) => createStore({
description: 'Filter leads that fail on Trustedform Verify check',

};
isArray(rules) ? set(filterConfig, 'rules', rules) : assign(filterConfig, rules);
set(filterConfig, 'rules', rules);
await context.dispatch('createFilter', filterConfig);
}
context.state.filters.forEach(filter => {
Expand All @@ -203,12 +198,6 @@ const initStore = (config, ui) => createStore({
}
context.state.ui.create({ flow });
},
setShouldConfigVerify(context, shouldConfigVerify) {
context.state.shouldConfigVerify = shouldConfigVerify;
},
getShouldConfigVerify(context) {
return context.state.shouldConfigVerify;
}
}
});

Expand Down
27 changes: 23 additions & 4 deletions test/trustedform_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ describe('v4', () => {
'seconds_on_page'
]
},
verify: {}
verify: {
advertiser_name: 'test'
}
}),
headers: {
'Content-Type': 'application/json',
Expand All @@ -162,7 +164,8 @@ describe('v4', () => {
page_url: 'true',
parent_page_url: 'true',
time_on_page: 'true'
}
},
trustedform: { advertiser_name: 'test' }
});
assert.deepEqual(integration.request(vars), expected);
});
Expand Down Expand Up @@ -333,6 +336,22 @@ describe('v4', () => {
});
assert.deepEqual(integration.request(vars).body, expected);
});
it('should correctly format a verify only request with 1:1 consent check', () => {
const expected = JSON.stringify({
verify: {
advertiser_name: 'test'
}
});
const vars = baseVars({
trustedform: {
retain: 'false',
insights: 'false',
advertiser_name: 'test'
},
verify: {}
});
assert.deepEqual(integration.request(vars).body, expected);
});
});

it('should use a custom api key when present', () => {
Expand Down Expand Up @@ -491,11 +510,11 @@ describe('v4', () => {
time_on_page_in_seconds: 8374,
time_zone: 'America/Chicago',
vendor: 'Inbound Verbose',
one_to_one: true,
verify: {
languages: ['I understand that the TrustedForm certificate is sent to the email address I provided above and I will receive product updates as they are released.'],
language_approved: true,
success: true,
one_to_one: true
success: true
}
};
assert.deepEqual(integration.response({ insights: { page_scan: true }}, {}, res), expected);
Expand Down

0 comments on commit 91fbffa

Please sign in to comment.