leadconduit-trustedform 2.1.0 → 2.2.0

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.
@@ -23,7 +23,7 @@ jobs:
23
23
  - name: Install Node.js
24
24
  uses: actions/setup-node@v3
25
25
  with:
26
- node-version: ${{ secrets.NODE_VERSION || 12 }}
26
+ node-version: 18
27
27
  - name: Install packages
28
28
  run: npm install
29
29
  env:
@@ -5,7 +5,7 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
- node-version: [14.x, 16.x, latest]
8
+ node-version: [16.x, 18.x, latest]
9
9
  env:
10
10
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
11
11
  steps:
@@ -17,7 +17,3 @@ jobs:
17
17
  - run: npm install
18
18
  - name: Run tests
19
19
  run: npx nyc@latest --reporter=lcov npm test
20
- - name: Coveralls
21
- uses: coverallsapp/github-action@master
22
- with:
23
- github-token: ${{ secrets.github_token }}
@@ -7,7 +7,7 @@ const handle = (vars, callback) => {
7
7
 
8
8
  const responseVariables = () => {
9
9
  return consent.responseVariables().concat([
10
- { name: 'age_in_seconds', type: 'number', description: 'Number of seconds since the certificate was created' },
10
+ { name: 'age_in_seconds', type: 'number', description: 'Number of seconds since the last user interaction with the certificate' },
11
11
  { name: 'city', type: 'string', description: 'City name based on IP address' },
12
12
  { name: 'country_code', type: 'string', description: 'Country based on IP address' },
13
13
  { name: 'latitude', type: 'number', description: 'Latitude based on IP address' },
package/lib/helpers.js CHANGED
@@ -79,14 +79,22 @@ 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 = (process.env.NODE_ENV === 'staging' && (tfStagingRegex.test(getUrlString(certUrl)) || tfStagingFacebook.test(getUrlString(certUrl))));
85
92
 
86
- const productionValid = (tfRegex.test(certUrl) || tfFacebookRegex.test(certUrl));
87
- const stagingValid = (process.env.NODE_ENV !== 'production' && (tfStagingRegex.test(certUrl) || tfStagingFacebook.test(certUrl)));
93
+ if (!productionValid && !stagingValid && !developmentValid) return 'TrustedForm cert URL must be valid';
94
+ };
88
95
 
89
- if (!productionValid && !stagingValid) return 'TrustedForm cert URL must be valid';
96
+ const getUrlString = (url) => {
97
+ return typeof url === 'object' ? url.raw : url;
90
98
  };
91
99
 
92
100
  const getLeadConduitUrl = (env = process.env.NODE_ENV) => {
package/lib/insights.js CHANGED
@@ -127,7 +127,7 @@ response.variables = () => [
127
127
  { name: 'outcome', type: 'string', description: 'Integration outcome (success, failure, or error)' },
128
128
  { name: 'reason', type: 'string', description: 'in case of failure, the reason for failure' },
129
129
  { name: 'billable', type: 'number', description: 'If the event is billable, the billable count for the event, else 0' },
130
- { name: 'age', type: 'number', description: 'Number of seconds since the certificate was created' },
130
+ { name: 'age', type: 'number', description: 'Number of seconds since the last user interaction with the certificate' },
131
131
  { name: 'browser', type: 'string', description: 'Human friendly version of user-agent' },
132
132
  { name: 'consented_at', type: 'time', description: 'Time the user checked the consent language checkbox, in UTC ISO8601 format' },
133
133
  { name: 'created_at', type: 'time', description: 'Time the user loaded the form, in UTC ISO8601 format' },
@@ -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) => {
@@ -101,17 +104,22 @@ 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: 'string', 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: 'string', 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 (!vars.trustedform?.insights?.valueOf() && !(vars.lead.email || vars.lead.phone_1)) return 'an email address or phone number is required to use TrustedForm Retain';
117
+ if (!vars.trustedform?.retain?.valueOf() && !vars.trustedform?.verify?.valueOf() && formatProperties(vars.insights).length === 0 && !vars.insights.page_scan?.valueOf()) return 'no properties selected for TrustedForm Insights';
118
+ };
114
119
 
120
+ const hasTrustedFormProduct = (vars) => {
121
+ return vars.trustedform?.retain?.valueOf() || vars.trustedform?.insights?.valueOf() || vars.trustedform?.verify?.valueOf();
122
+ };
115
123
  const response = (vars, req, res) => {
116
124
  if (res.status < 500) {
117
125
  try {
@@ -162,8 +170,12 @@ const response = (vars, req, res) => {
162
170
  is_mobile: parsed.insights?.properties?.os?.is_mobile,
163
171
  os_name: parsed.insights?.properties?.os?.name,
164
172
  page_url: parsed.insights?.properties?.page_url,
165
- parent_page_url: parsed.insights?.properties?.parent_page_url
166
- }, (v) => { return !isUndefined(v) });
173
+ parent_page_url: parsed.insights?.properties?.parent_page_url,
174
+
175
+ languages: parsed.insights?.properties?.languages,
176
+ language_approved: parsed.insights?.properties?.language_approved,
177
+ success: parsed.verify?.results?.success,
178
+ }, (v) => { return !isUndefined(v); });
167
179
  } else {
168
180
  return {
169
181
  outcome: parsed.outcome,
@@ -226,11 +238,14 @@ response.variables = () => [
226
238
  { 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
239
  { name: 'os_name', type: 'string', description: 'Operating system name' },
228
240
  { 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.' }
241
+ { name: 'parent_page_url', type: 'string', description: 'The parent URL of the page hosting TrustedForm Certify, if framed.' },
242
+ { name: 'verify.languages', type: 'array', description: 'A list of the consent languages detected within the certificate' },
243
+ { 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.' },
244
+ { 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
245
  ];
231
246
 
232
247
  module.exports = {
233
248
  request,
234
249
  response,
235
250
  validate
236
- }
251
+ };
@@ -5,7 +5,13 @@ 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
+ 'development': 'https://app.trustedform-dev.com/account',
12
+ };
13
+ const environment = get(process, 'env.NODE_ENV') || 'development';
14
+ const url = trustedFormUrl[environment];
9
15
 
10
16
  const options = {
11
17
  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
+ };