leadconduit-trustedform 2.2.2 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
- node-version: [16.x, 18.x, latest]
8
+ node-version: [18.x, 20.x, latest]
9
9
  env:
10
10
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
11
11
  steps:
package/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org)
4
4
 
5
+ ## [2.3.1] - 2024-01-10
6
+ ### Fixed
7
+ - v4 `validate` function will properly handle missing `insights` vars ([sc-65226](https://app.shortcut.com/active-prospect/story/65226/trustedform-v4-insights-add-on-with-no-field-mappings-errors-in-validation))
8
+
9
+ ## [2.3.0] - 2023-11-20
10
+ ### Fixed
11
+ - Re-add fixed TrustedForm v4 Verify Add-On ([#105](https://github.com/activeprospect/leadconduit-integration-trustedform/pull/105), [sc-63442](https://app.shortcut.com/active-prospect/story/63442/trustedform-v4-add-verify-to-add-on))
12
+
13
+ ## [2.2.2] - 2023-11-17
14
+ ### Fixed
15
+ - Revert [#102](https://github.com/activeprospect/leadconduit-integration-trustedform/pull/102)
16
+
17
+ ## [2.2.1] - 2023-11-17
18
+ ### Fixed
19
+ - Page scan variables are now typed as arrays ([#103](https://github.com/activeprospect/leadconduit-integration-trustedform/pull/103))
20
+
21
+ ## [2.2.0] - 2023-11-15
22
+ ### Added
23
+ - TrustedForm v4 Verify Add-On ([sc-63442](https://app.shortcut.com/active-prospect/story/63442/trustedform-v4-add-verify-to-add-on))
24
+
25
+ ## [2.1.1] - 2023-07-14
26
+ ### Fixed
27
+ - Updated "Age" and "Age in Seconds" description for TF Inisights and TF Consent + Insights ([sc-48650](https://app.shortcut.com/active-prospect/story/48650/incorrect-description-for-age-in-the-trustedform-enhancements))
28
+
29
+ ## [2.1.0] - 2023-06-20
30
+ ### Added
31
+ - TrustedForm v4 Integration ([sc-50245](https://app.shortcut.com/active-prospect/story/50245/trustedform-v4-new-integration-trustedform))
32
+
5
33
  ## [2.0.3] - 2023-02-21
6
34
  ### Fixed
7
35
  - `domain` data is now appended if returned as part of insights data
package/lib/claim.js CHANGED
@@ -34,6 +34,7 @@ const requestVariables = () => [
34
34
  { name: 'lead.phone_3', type: 'string', required: false, description: 'Lead phone 3 that will be fingerprinted, defaults to the lead\'s "Phone 3" field' }
35
35
  ];
36
36
 
37
+ // eslint-disable-next-line complexity
37
38
  const parseResponse = (res, body, vars) => {
38
39
  let appended = {};
39
40
  const event = body;
package/lib/consent.js CHANGED
@@ -64,6 +64,7 @@ const parseCertData = (cert) => {
64
64
  };
65
65
  };
66
66
 
67
+ // eslint-disable-next-line complexity
67
68
  const parseResponse = (statusCode, body, vars) => {
68
69
  let appended = {};
69
70
  const event = body;
package/lib/helpers.js CHANGED
@@ -79,14 +79,21 @@ const tfFacebookRegex = /^https?:\/\/cert.trustedform.com\/0\./;
79
79
  const tfStagingRegex = /^https?:\/\/cert.staging.trustedform.com\/([-_a-zA-Z0-9]{40}|[-_a-zA-Z0-9]{80})$/;
80
80
  const tfStagingFacebook = /^https?:\/\/cert.staging.trustedform.com\/0\./;
81
81
 
82
+ // same as above, for development
83
+ const tfDevelopmentRegex = /^https?:\/\/cert.trustedform-dev.com\/([-_a-zA-Z0-9]{40}|[-_a-zA-Z0-9]{80})$/;
84
+ const tfDevelopmentFacebook = /^https?:\/\/cert.trustedform-dev.com\/0\./;
85
+
82
86
  const validate = (vars) => {
83
87
  const certUrl = _.get(vars.lead, 'trustedform_cert_url');
84
88
  if (!certUrl) return 'TrustedForm cert URL must not be blank';
89
+ const productionValid = (tfRegex.test(getUrlString(certUrl)) || tfFacebookRegex.test(getUrlString(certUrl)));
90
+ const developmentValid = (process.env.NODE_ENV === 'development' && (tfDevelopmentRegex.test(getUrlString(certUrl)) || tfDevelopmentFacebook.test(getUrlString(certUrl))));
91
+ const stagingValid = (!['production', 'development'].includes(process.env.NODE_ENV) && (tfStagingRegex.test(getUrlString(certUrl)) || tfStagingFacebook.test(getUrlString(certUrl))));
92
+ if (!productionValid && !stagingValid && !developmentValid) return 'TrustedForm cert URL must be valid';
93
+ };
85
94
 
86
- const productionValid = (tfRegex.test(certUrl) || tfFacebookRegex.test(certUrl));
87
- const stagingValid = (process.env.NODE_ENV !== 'production' && (tfStagingRegex.test(certUrl) || tfStagingFacebook.test(certUrl)));
88
-
89
- if (!productionValid && !stagingValid) return 'TrustedForm cert URL must be valid';
95
+ const getUrlString = (url) => {
96
+ return typeof url === 'object' ? url.raw : url;
90
97
  };
91
98
 
92
99
  const getLeadConduitUrl = (env = process.env.NODE_ENV) => {
@@ -94,6 +101,7 @@ const getLeadConduitUrl = (env = process.env.NODE_ENV) => {
94
101
  case 'localhost': return 'http://leadconduit.localhost';
95
102
  case 'development': return 'https://app.leadconduit-development.com';
96
103
  case 'staging': return 'https://app.leadconduit-staging.com';
104
+ case 'test': return 'https://app.leadconduit-staging.com';
97
105
  case 'production': return 'https://app.leadconduit.com';
98
106
  default: return 'https://app.leadconduit.com';
99
107
  }
@@ -19,7 +19,7 @@ const request = (vars) => {
19
19
  if (trustedform.insights.valueOf()) {
20
20
  body.insights = {
21
21
  properties: formatProperties(insights)
22
- }
22
+ };
23
23
  if (insights.page_scan?.valueOf()) {
24
24
  body.insights.scans = {
25
25
  required: trustedform.scan_required_text,
@@ -28,6 +28,9 @@ const request = (vars) => {
28
28
  };
29
29
  }
30
30
  }
31
+ if (trustedform.verify?.valueOf()) {
32
+ body.verify = {};
33
+ }
31
34
 
32
35
  return {
33
36
  method: 'POST',
@@ -38,7 +41,7 @@ const request = (vars) => {
38
41
  'api-version': '4.0',
39
42
  Authorization: `Basic ${Buffer.from(`X:${vars.activeprospect.api_key}`).toString('base64')}`
40
43
  }
41
- }
44
+ };
42
45
  };
43
46
 
44
47
  const formatProperties = (insights) => {
@@ -64,7 +67,7 @@ const formatProperties = (insights) => {
64
67
  ];
65
68
 
66
69
  let selectedProps = insightsProps.map((field) => {
67
- if (insights[field.mapping]?.valueOf()) return field.value;
70
+ if (insights?.[field.mapping]?.valueOf()) return field.value;
68
71
  });
69
72
 
70
73
  return compact(selectedProps);
@@ -101,16 +104,26 @@ request.variables = () => [
101
104
  { name: 'insights.page_scan', type: 'boolean', required: false, description: 'Request TrustedForm Insights page scan data?' },
102
105
  { name: 'trustedform.scan_required_text', type: 'array', required: false, description: 'A list of required text to scan for. TrustedForm will then perform a case and whitespace insensitive search for the string.' },
103
106
  { 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.' },
104
- { name: 'trustedform.scan_delimiter', type: 'string', required: false, description: 'Use this parameter to designate a delimiter when wrapping wildcards or template variables; defaults to |.' }
107
+ { name: 'trustedform.scan_delimiter', type: 'string', required: false, description: 'Use this parameter to designate a delimiter when wrapping wildcards or template variables; defaults to |.' },
108
+
109
+ { name: 'trustedform.verify', type: 'boolean', required: true, description: 'If true, a request to the Verify product will be made'}
105
110
  ];
106
111
 
107
112
  const validate = (vars) => {
108
- const certError = helpers.validate(vars)
113
+ const certError = helpers.validate(vars);
109
114
  if (certError) return certError;
110
- if (!vars.trustedform?.retain?.valueOf() && !vars.trustedform?.insights.valueOf()) return 'a TrustedForm product must be selected';
111
- if (!vars.trustedform?.insights?.valueOf() && !(vars.lead.email || vars.lead.phone_1)) return 'an email address or phone number is required to use TrustedForm Retain'
112
- if (!vars.trustedform?.retain?.valueOf() && formatProperties(vars.insights).length === 0 && !vars.insights.page_scan?.valueOf()) return 'no properties selected for TrustedForm Insights';
113
- }
115
+ if (!hasTrustedFormProduct(vars)) return 'a TrustedForm product must be selected';
116
+ if (retainEnabled(vars) && !hasRequiredRetainProps(vars)) return 'an email address or phone number is required to use TrustedForm Retain';
117
+ if (insightsEnabled(vars) && !hasAtLeastOneInsightsProp(vars)) return 'no properties selected for TrustedForm Insights';
118
+ };
119
+
120
+ const hasTrustedFormProduct = (vars) => retainEnabled(vars) || insightsEnabled(vars) || verifyEnabled(vars);
121
+ const retainEnabled = (vars) => vars.trustedform?.retain?.valueOf();
122
+ const insightsEnabled = (vars) => vars.trustedform?.insights?.valueOf();
123
+ const verifyEnabled = (vars) => vars.trustedform?.verify?.valueOf();
124
+ const hasRequiredRetainProps = (vars) => !!(vars.lead.email || vars.lead.phone_1);
125
+ const hasAtLeastOneInsightsProp = (vars) => formatProperties(vars.insights).length > 0 || vars.insights?.page_scan?.valueOf();
126
+
114
127
 
115
128
  const response = (vars, req, res) => {
116
129
  if (res.status < 500) {
@@ -162,8 +175,12 @@ const response = (vars, req, res) => {
162
175
  is_mobile: parsed.insights?.properties?.os?.is_mobile,
163
176
  os_name: parsed.insights?.properties?.os?.name,
164
177
  page_url: parsed.insights?.properties?.page_url,
165
- parent_page_url: parsed.insights?.properties?.parent_page_url
166
- }, (v) => { return !isUndefined(v) });
178
+ parent_page_url: parsed.insights?.properties?.parent_page_url,
179
+
180
+ languages: parsed.insights?.properties?.languages,
181
+ language_approved: parsed.insights?.properties?.language_approved,
182
+ success: parsed.verify?.result?.success,
183
+ }, (v) => { return !isUndefined(v); });
167
184
  } else {
168
185
  return {
169
186
  outcome: parsed.outcome,
@@ -226,11 +243,14 @@ response.variables = () => [
226
243
  { name: 'is_mobile', type: 'boolean', description: 'A boolean indicating that the form was filled out on a mobile device or tablet, based on user-agent' },
227
244
  { name: 'os_name', type: 'string', description: 'Operating system name' },
228
245
  { name: 'page_url', type: 'string', description: 'The URL of the page hosting TrustedForm Certify.' },
229
- { name: 'parent_page_url', type: 'string', description: 'The parent URL of the page hosting TrustedForm Certify, if framed.' }
246
+ { name: 'parent_page_url', type: 'string', description: 'The parent URL of the page hosting TrustedForm Certify, if framed.' },
247
+ { name: 'verify.languages', type: 'array', description: 'A list of the consent languages detected within the certificate' },
248
+ { name: 'verify.language_approved', type: 'string', description: 'A boolean indicating if any of the consent languages found have been approved in your account\'s consent language manager.' },
249
+ { name: 'verify.success', type: 'boolean', description: 'A boolean indicating if any of the consent languages found meet the success criteria defined for your account.' },
230
250
  ];
231
251
 
232
252
  module.exports = {
233
253
  request,
234
254
  response,
235
255
  validate
236
- }
256
+ };
@@ -5,7 +5,14 @@ module.exports = (req, res) => {
5
5
  const { apiKey } = req.query;
6
6
  if (!apiKey) return res.status(422).send({ error: 'missing required field: apiKey' });
7
7
 
8
- const url = get(process, 'env.NODE_ENV') === 'production' ? 'https://app.trustedform.com/account' : 'https://app.staging.trustedform.com/account';
8
+ const trustedFormUrl = {
9
+ 'production': 'https://app.trustedform.com/account',
10
+ 'staging': 'https://app.staging.trustedform.com/account',
11
+ 'test': 'https://app.staging.trustedform.com/account',
12
+ 'development': 'https://app.trustedform-dev.com/account',
13
+ };
14
+ const environment = get(process, 'env.NODE_ENV') || 'development';
15
+ const url = trustedFormUrl[environment];
9
16
 
10
17
  const options = {
11
18
  url,
@@ -5,4 +5,4 @@ const account = require('./account');
5
5
  module.exports =
6
6
  express.Router()
7
7
  .use(json())
8
- .use('/account', account)
8
+ .use('/account', account);
@@ -16,6 +16,10 @@
16
16
  <input type="checkbox" :disabled="!products.insights.enabled" v-model="products.insights.selected"><span> Insights</span>
17
17
  <p class="help-text">TrustedForm Insights helps buyers identify the leads that are most likely to convert and effectively manage returns and rejections.</p>
18
18
  </li>
19
+ <li>
20
+ <input type="checkbox" :disabled="!products.verify.enabled" v-model="products.verify.selected"><span> Verify</span>
21
+ <p class="help-text">Confirm that your leads were shown consent language that meets your compliance requirements.</p>
22
+ </li>
19
23
  </ul>
20
24
  </form>
21
25
  </section>
@@ -23,12 +27,12 @@
23
27
  :showPrevious="false"
24
28
  :onNext="!showFinish ? next : undefined"
25
29
  :onFinish="showFinish ? finish : undefined"
26
- :disableNext="!products.retain.selected && !products.insights.selected"
30
+ :disableNext="!products.retain.selected && !products.insights.selected && !products.verify.selected"
27
31
  />
28
32
  </div>
29
33
  </template>
30
34
  <script>
31
- import { Navigation } from '@activeprospect/integration-components'
35
+ import { Navigation } from '@activeprospect/integration-components';
32
36
 
33
37
  export default {
34
38
  data () {
@@ -42,7 +46,7 @@ export default {
42
46
  },
43
47
  computed: {
44
48
  showFinish () {
45
- return this.products.retain.selected && !this.products.insights.selected;
49
+ return (this.products.retain.selected ||this.products.verify.selected ) && !this.products.insights.selected;
46
50
  }
47
51
  },
48
52
  methods: {
@@ -56,7 +60,7 @@ export default {
56
60
  }
57
61
  },
58
62
  created () {
59
- this.$store.dispatch('getProducts')
63
+ this.$store.dispatch('getProducts');
60
64
  }
61
65
  };
62
66
  </script>
@@ -16,8 +16,10 @@ const initStore = (config, ui) => new Vuex.Store({
16
16
  errors: undefined,
17
17
  products: {
18
18
  retain: { enabled: false, selected: false },
19
- insights: { enabled: false, selected: false }
20
- }
19
+ insights: { enabled: false, selected: false },
20
+ verify: { enabled: false, selected: false }
21
+ },
22
+ filters: []
21
23
  },
22
24
  mutations: {
23
25
  setErrors (state, errors) {
@@ -25,6 +27,9 @@ const initStore = (config, ui) => new Vuex.Store({
25
27
  },
26
28
  setProduct (state, { product, value }) {
27
29
  state.products[product] = value;
30
+ },
31
+ setFilters(state, filters) {
32
+ state.filters = filters;
28
33
  }
29
34
  },
30
35
  getters: {
@@ -45,9 +50,10 @@ const initStore = (config, ui) => new Vuex.Store({
45
50
  .then(function (response) {
46
51
  const availableProducts = [
47
52
  'retain',
48
- 'insights'
49
- ]
50
- const products = get(response, 'data.product_components');
53
+ 'insights',
54
+ 'verify'
55
+ ];
56
+ const products = get(response, 'data.product_components');
51
57
  availableProducts.forEach(function (product) {
52
58
  context.commit('setProduct', { product, value: {
53
59
  enabled: products.includes(product),
@@ -63,7 +69,25 @@ const initStore = (config, ui) => new Vuex.Store({
63
69
  }
64
70
  });
65
71
  },
66
- finish (context) {
72
+ createFilter(context, filterConfig) {
73
+ const filter = {
74
+ type: 'filter',
75
+ reason: filterConfig.reason,
76
+ outcome: filterConfig.outcome,
77
+ rule_set: {
78
+ op: 'and',
79
+ rules: [{
80
+ op: filterConfig.rulesOp,
81
+ lhv: filterConfig.lhv,
82
+ rhv: filterConfig.rhv
83
+ }]
84
+ },
85
+ description: filterConfig.description,
86
+ enabled: true
87
+ };
88
+ context.commit('setFilters', [...context.state.filters, filter]);
89
+ },
90
+ async finish (context) {
67
91
  const { products, v4Fields } = context.state;
68
92
  const flow = {
69
93
  steps: [{
@@ -76,8 +100,9 @@ const initStore = (config, ui) => new Vuex.Store({
76
100
  module_id: config.integration,
77
101
  mappings: []
78
102
  }
79
- }]
103
+ }],
80
104
  };
105
+
81
106
  if (config.integration === 'leadconduit-trustedform.outbound.trustedform') {
82
107
  Object.keys(products).forEach((product) => {
83
108
  flow.steps[0].integration.mappings.push({
@@ -91,9 +116,24 @@ const initStore = (config, ui) => new Vuex.Store({
91
116
  flow.steps[0].integration.mappings.push({
92
117
  property: `insights.${field}`,
93
118
  value: v4Fields[field].selected ? 'true' : 'false'
94
- })
119
+ });
95
120
  });
96
121
  }
122
+
123
+ if (products.verify.selected) {
124
+ const filterConfig = {
125
+ reason: '{{trustedform.reason}}',
126
+ rulesOp: 'is not equal to',
127
+ lhv: 'trustedform.outcome',
128
+ rhv: 'success',
129
+ outcome: 'failure',
130
+ description: 'Filter leads that fail on Trustedform Verify check'
131
+ };
132
+ await context.dispatch('createFilter', filterConfig);
133
+ }
134
+ context.state.filters.forEach(filter => {
135
+ flow.steps.push(filter);
136
+ });
97
137
  }
98
138
  context.state.ui.create({ flow });
99
139
  }
@@ -93,5 +93,5 @@ module.exports = {
93
93
  name: 'Time On Page',
94
94
  description: 'The amount of time, in seconds, that the consumer spent on the page during the lead event.',
95
95
  enabled: false
96
- }
97
- }
96
+ },
97
+ };