leadconduit-trustedform 2.0.3 → 2.1.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.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: TrustedForm Decision Service Ping
3
3
  tag: Data Insights
4
- integration_type: enhancement marketplace
4
+ integration_type: marketplace enhancement
5
5
  link: https://activeprospect.com/products/trustedform/
6
6
  ---
7
7
  TrustedForm Decision Service helps buyers identify the leads that are most likely to convert and effectively manage returns and rejections.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: TrustedForm Decision Service Post
3
3
  tag: Data Insights
4
- integration_type: enhancement marketplace
4
+ integration_type: marketplace enhancement
5
5
  link: https://activeprospect.com/products/trustedform/
6
6
  ---
7
7
  TrustedForm Decision Service helps buyers identify the leads that are most likely to convert and effectively manage returns and rejections.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: TrustedForm Insights
3
3
  tag: Data Insights
4
- integration_type: enhancement marketplace
4
+ integration_type: marketplace enhancement
5
5
  link: https://activeprospect.com/products/trustedform/
6
6
  ---
7
7
  TrustedForm Insights helps buyers identify the leads that are most likely to convert and effectively manage returns and rejections.
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: TrustedForm
3
+ tag: TCPA
4
+ integration_type: marketplace enhancement
5
+ link: https://activeprospect.com/trustedform/
6
+ ---
7
+ TrustedForm provides unbiased third-party documentation of consent and real-time actionable insights about the leads you’re acquiring.
package/index.js CHANGED
@@ -6,6 +6,7 @@ module.exports = {
6
6
  consent_plus_data: require('./lib/consent_plus_data'),
7
7
  decision_service_ping: require('./lib/insights'),
8
8
  decision_service_post: require('./lib/insights'),
9
- insights: require('./lib/insights')
9
+ insights: require('./lib/insights'),
10
+ trustedform: require('./lib/trustedform')
10
11
  }
11
12
  };
package/lib/helpers.js CHANGED
@@ -121,6 +121,7 @@ module.exports = {
121
121
  countRequiredMatched,
122
122
  evalFingerprint,
123
123
  formatUrl,
124
+ getLeadConduitUrl,
124
125
  configureClaimOptions,
125
126
  validate
126
127
  };
@@ -0,0 +1,236 @@
1
+ const helpers = require('./helpers');
2
+ const { compact, pickBy, isUndefined } = require('lodash');
3
+
4
+ const request = (vars) => {
5
+ const { lead, trustedform, insights } = vars;
6
+ const body = {};
7
+
8
+ if (trustedform.retain.valueOf() && (lead.email || lead.phone_1)) {
9
+ body.match_lead = {
10
+ email: lead.email,
11
+ phone: lead.phone_1
12
+ };
13
+ body.retain = {
14
+ reference: trustedform.custom_reference || `${helpers.getLeadConduitUrl()}/events/${lead.id}`,
15
+ vendor: trustedform.vendor || vars.source.name
16
+ };
17
+ }
18
+
19
+ if (trustedform.insights.valueOf()) {
20
+ body.insights = {
21
+ properties: formatProperties(insights)
22
+ }
23
+ if (insights.page_scan?.valueOf()) {
24
+ body.insights.scans = {
25
+ required: trustedform.scan_required_text,
26
+ forbidden: trustedform.scan_forbidden_text,
27
+ delimiter: trustedform.scan_delimiter
28
+ };
29
+ }
30
+ }
31
+
32
+ return {
33
+ method: 'POST',
34
+ url: lead.trustedform_cert_url.toString(),
35
+ body: JSON.stringify(body),
36
+ headers: {
37
+ 'Content-Type': 'application/json',
38
+ 'api-version': '4.0',
39
+ Authorization: `Basic ${Buffer.from(`X:${vars.activeprospect.api_key}`).toString('base64')}`
40
+ }
41
+ }
42
+ };
43
+
44
+ const formatProperties = (insights) => {
45
+ const insightsProps = [
46
+ { mapping: 'age', value: 'age_seconds' },
47
+ { mapping: 'location', value: 'approx_ip_geo' },
48
+ { mapping: 'browser', value: 'browser' },
49
+ { mapping: 'created_timestamp', value: 'created_at' },
50
+ { mapping: 'domain', value: 'domain' },
51
+ { mapping: 'expiration_timestamp', value: 'expires_at' },
52
+ { mapping: 'form_input_kpm', value: 'form_input_kpm' },
53
+ { mapping: 'form_input_method', value: 'form_input_method' },
54
+ { mapping: 'form_input_wpm', value: 'form_input_wpm' },
55
+ { mapping: 'ip_address', value: 'ip' },
56
+ { mapping: 'framed', value: 'is_framed' },
57
+ { mapping: 'masked', value: 'is_masked' },
58
+ { mapping: 'sensitive_content', value: 'num_sensitive_content_elements' },
59
+ { mapping: 'sensitive_form_fields', value: 'num_sensitive_form_elements' },
60
+ { mapping: 'operating_system', value: 'os' },
61
+ { mapping: 'page_url', value: 'page_url' },
62
+ { mapping: 'parent_page_url', value: 'parent_page_url' },
63
+ { mapping: 'time_on_page', value: 'seconds_on_page' }
64
+ ];
65
+
66
+ let selectedProps = insightsProps.map((field) => {
67
+ if (insights[field.mapping]?.valueOf()) return field.value;
68
+ });
69
+
70
+ return compact(selectedProps);
71
+ };
72
+
73
+ request.variables = () => [
74
+ { name: 'lead.trustedform_cert_url', type: 'trustedform_url', required: true, description: 'TrustedForm Certificate URL' },
75
+ { name: 'lead.email', type: 'string', required: false, description: `The email of the consumer you believe was recorded in the certificate; defaults to the lead's "Email" field.` },
76
+ { name: 'lead.phone_1', type: 'string', required: false, description: `The phone number of the consumer you believe was recorded in the certificate; defaults to the lead's "Phone 1" field.`},
77
+
78
+ { name: 'trustedform.retain', type: 'boolean', required: true, description: 'If true, a request to the Retain product will be made' },
79
+ { name: 'trustedform.custom_reference', type: 'string', required: false, description: `Any text that may help you identify the lead associated with the certificate, such as a unique lead identifier or URL pointing to the lead in another system; defaults to the lead's url.` },
80
+ { name: 'trustedform.vendor', type: 'string', required: false, description: `The name of the company that provided the lead associated with the certificate; defaults to the lead source's name.` },
81
+
82
+ { name: 'trustedform.insights', type: 'boolean', required: true, description: 'If true, a request to the Insights product will be made' },
83
+ { name: 'insights.age', type: 'boolean', required: false, description: 'Request TrustedForm Insights age data?' },
84
+ { name: 'insights.browser', type: 'boolean', required: false, description: 'Request TrustedForm Insights browser data?' },
85
+ { name: 'insights.created_timestamp', type: 'boolean', required: false, description: 'Request TrustedForm Insights created timestamp data?' },
86
+ { name: 'insights.domain', type: 'boolean', required: false, description: 'Request TrustedForm Insights domain data?' },
87
+ { name: 'insights.expiration_timestamp', type: 'boolean', required: false, description: 'Request TrustedForm Insights expiration timestamp data?' },
88
+ { name: 'insights.framed', type: 'boolean', required: false, description: 'Request TrustedForm Insights framed data?' },
89
+ { name: 'insights.form_input_method', type: 'boolean', required: false, description: 'Request TrustedForm Insights form input method data?' },
90
+ { name: 'insights.form_input_kpm', type: 'boolean', required: false, description: 'Request TrustedForm Insights form input KPM data?' },
91
+ { name: 'insights.form_input_wpm', type: 'boolean', required: false, description: 'Request TrustedForm Insights form input WPM data?' },
92
+ { name: 'insights.ip_address', type: 'boolean', required: false, description: 'Request TrustedForm Insights IP address data?' },
93
+ { name: 'insights.location', type: 'boolean', required: false, description: 'Request TrustedForm Insights location data?' },
94
+ { name: 'insights.masked', type: 'boolean', required: false, description: 'Request TrustedForm Insights masked data?' },
95
+ { name: 'insights.sensitive_content', type: 'boolean', required: false, description: 'Request TrustedForm Insights sensitive content data?' },
96
+ { name: 'insights.sensitive_form_fields', type: 'boolean', required: false, description: 'Request TrustedForm Insights sensitive form fields data?' },
97
+ { name: 'insights.operating_system', type: 'boolean', required: false, description: 'Request TrustedForm Insights operating system data?' },
98
+ { name: 'insights.parent_page_url', type: 'boolean', required: false, description: 'Request TrustedForm Insights parent page URL data?' },
99
+ { name: 'insights.time_on_page', type: 'boolean', required: false, description: 'Request TrustedForm Insights time on page data?' },
100
+ { name: 'insights.page_url', type: 'boolean', required: false, description: 'Request TrustedForm Insights page URL data?' },
101
+ { name: 'insights.page_scan', type: 'boolean', required: false, description: 'Request TrustedForm Insights page scan data?' },
102
+ { 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
+ { 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 |.' }
105
+ ];
106
+
107
+ const validate = (vars) => {
108
+ const certError = helpers.validate(vars)
109
+ 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
+ }
114
+
115
+ const response = (vars, req, res) => {
116
+ if (res.status < 500) {
117
+ try {
118
+ const parsed = JSON.parse(res.body);
119
+ if (res.status === 200) {
120
+ return pickBy({
121
+ outcome: parsed.outcome,
122
+ reason: parsed.reason,
123
+
124
+ matched_email: parsed.match_lead?.email,
125
+ matched_phone: parsed.match_lead?.phone,
126
+ successful_match: parsed.match_lead?.result?.success,
127
+ email_fingerprint_matched: parsed.match_lead?.result?.email_match,
128
+ phone_fingerprint_matched: parsed.match_lead?.result?.phone_match,
129
+ reference_code: parsed.retain?.reference,
130
+ vendor: parsed.retain?.vendor,
131
+
132
+ previously_retained: parsed.retain?.results?.previously_retained,
133
+ expires_at: parsed.retain?.results?.expires_at || parsed.insights?.properties?.expires_at,
134
+
135
+ scans_result: parsed.insights?.scans?.result?.success,
136
+ required_scans_found: parsed.insights?.scans?.result?.required?.found,
137
+ required_scans_not_found: parsed.insights?.scans?.result?.required?.not_found,
138
+ forbidden_scans_found: parsed.insights?.scans?.result?.forbidden?.found,
139
+ forbidden_scans_not_found: parsed.insights?.scans?.result?.forbidden?.not_found,
140
+ age_in_seconds: parsed.insights?.properties?.age_seconds,
141
+ city: parsed.insights?.properties?.approx_ip_geo?.city,
142
+ country_code: parsed.insights?.properties?.approx_ip_geo?.country_code,
143
+ latitude: parsed.insights?.properties?.approx_ip_geo?.lat,
144
+ longitude: parsed.insights?.properties?.approx_ip_geo?.lon,
145
+ postal_code: parsed.insights?.properties?.approx_ip_geo?.postal_code,
146
+ state: parsed.insights?.properties?.approx_ip_geo?.state,
147
+ time_zone: parsed.insights?.properties?.approx_ip_geo?.time_zone,
148
+ browser_full: parsed.insights?.properties?.browser?.full,
149
+ user_agent: parsed.insights?.properties?.browser?.user_agent,
150
+ created_at: parsed.insights?.properties?.created_at,
151
+ domain: parsed.insights?.properties?.domain,
152
+ time_on_page_in_seconds: parsed.insights?.properties?.seconds_on_page,
153
+ kpm: parsed.insights?.properties?.form_input_kpm,
154
+ form_input_method: parsed.insights?.properties?.form_input_method,
155
+ wpm: parsed.insights?.properties?.form_input_wpm,
156
+ ip: parsed.insights?.properties?.ip,
157
+ is_framed: parsed.insights?.properties?.is_framed,
158
+ is_masked: parsed.insights?.properties?.is_masked,
159
+ sensitive_hidden_content_elements: parsed.insights?.properties?.num_sensitive_content_elements,
160
+ sensitive_hidden_form_elements: parsed.insights?.properties?.num_sensitive_form_elements,
161
+ os_full: parsed.insights?.properties?.os?.full,
162
+ is_mobile: parsed.insights?.properties?.os?.is_mobile,
163
+ os_name: parsed.insights?.properties?.os?.name,
164
+ page_url: parsed.insights?.properties?.page_url,
165
+ parent_page_url: parsed.insights?.properties?.parent_page_url
166
+ }, (v) => { return !isUndefined(v) });
167
+ } else {
168
+ return {
169
+ outcome: parsed.outcome,
170
+ reason: parsed.reason
171
+ };
172
+ }
173
+ } catch (e) {
174
+ return {
175
+ outcome: 'error',
176
+ reason: 'unable to parse response'
177
+ };
178
+ }
179
+ } else {
180
+ return {
181
+ outcome: 'error',
182
+ reason: 'unable to parse response'
183
+ };
184
+ }
185
+ };
186
+
187
+ response.variables = () => [
188
+ { name: 'outcome', type: 'string', description: 'The outcome of the request. Indicates whether the call succeeded, failed, or resulted in an error. The value of the outcome is determined by the result of each operation specified by the caller. "success" is returned if all results resulted in success. "failure" is returned if any result is unsuccessful. If an error occurs during any operation, the outcome is an "error".' },
189
+ { name: 'reason', type: 'string', description: 'Provides an explanation for failure or error.' },
190
+ { name: 'matched_email', type: 'string', description: 'The email or hashed value provided in the request, believed to be that of the consumer recorded in the certificate.' },
191
+ { name: 'matched_phone', type: 'string', description: 'The phone number or hashed value provided in the request, believed to be that of the consumer recorded in the certificate.' },
192
+ { name: 'successful_match', type: 'boolean', description: 'A boolean indicating if any matches were found during the lead matching operation. A null value indicates that lead matching was not performed.' },
193
+ { name: 'email_fingerprint_matched', type: 'boolean', description: 'A boolean indicating if any email matches were found during the lead matching operation. A null value indicates that no emails were provided.' },
194
+ { name: 'phone_fingerprint_matched', type: 'boolean', description: 'A boolean indicating if any phone matches were found during the lead matching operation. A null value indicates that no phone numbers were provided.' },
195
+ { name: 'reference_code', type: 'string', description: 'The parameter provided in the request, intended to be a reference to help you identify the lead associated with the certificate.' },
196
+ { name: 'vendor', type: 'string', description: 'The parameter provided in the request, intended to be the name of the company that provided the lead associated with the certificate.' },
197
+ { name: 'previously_retained', type: 'boolean', description: 'A boolean indicating whether your account had already retained this certificate.' },
198
+ { name: 'expires_at', type: 'time', description: 'The UTC ISO8601 formatted date and time when this certificate will no longer be available for API requests.' },
199
+ { name: 'scans_result', type: 'boolean', description: 'A boolean indicating if all required text was found and none of the forbidden text was found.' },
200
+ { name: 'required_scans_found', type: 'array', description: 'A list of required scan terms that were found in the recorded content.' },
201
+ { name: 'required_scans_not_found', type: 'array', description: 'A list of required scan terms that were not found in the recorded content.' },
202
+ { name: 'forbidden_scans_found', type: 'array', description: 'A list of forbidden scan terms that were found in the recorded content.' },
203
+ { name: 'forbidden_scans_not_found', type: 'array', description: 'A list of forbidden scan terms that were not found in the recorded content.' },
204
+ { name: 'age_in_seconds', type: 'number', description: 'Number of seconds since the last user interaction with the certificate.' },
205
+ { name: 'city', type: 'string', description: 'City name based on consumer\'s public IP address' },
206
+ { name: 'country_code', type: 'string', description: 'Country code based on consumer\'s public IP address' },
207
+ { name: 'latitude', type: 'number', description: 'Latitude based on consumer\'s public IP address' },
208
+ { name: 'longitude', type: 'number', description: 'Longitude based on consumer\'s public IP address' },
209
+ { name: 'postal_code', type: 'postal_code', description: 'Mailing address postal code based on consumer\'s public IP address' },
210
+ { name: 'state', type: 'state', description: 'State/Province or Political Subdivision abbreviation based on consumer\'s public IP address' },
211
+ { name: 'time_zone', type: 'string', description: 'Timezone name based on consumer\'s public IP address' },
212
+ { name: 'browser_full', type: 'string', description: 'A human-friendly version of the browser parsed from the user-agent' },
213
+ { name: 'user_agent', type: 'string', description: 'The consumer\'s browser user-agent' },
214
+ { name: 'created_at', type: 'time', description: 'The UTC ISO8601 formatted date and time when the TrustedForm script was loaded' },
215
+ { name: 'domain', type: 'string', description: 'The domain displayed to the consumer during the page visit' },
216
+ { name: 'time_on_page_in_seconds', type: 'number', description: 'The time in seconds between when the script was loaded and when the most recent event was received' },
217
+ { name: 'kpm', type: 'number', description: 'The average number of keystrokes per minute based on the consumer’s rate of form input.' },
218
+ { name: 'form_input_method', type: 'array', description: 'The detected input method(s) the consumer used to fill out the form, such as "autofill" if the form was filled out using browser autofill; "paste" if the form was filled out pasting text; and "typing" if the form was filled out by typing.' },
219
+ { name: 'wpm', type: 'number', description: 'The approximate number of words per minute calculated by using the form_input_kpm and assuming five characters represent a word.' },
220
+ { name: 'ip', type: 'string', description: 'The consumer\'s public IP address' },
221
+ { name: 'is_framed', type: 'boolean', description: 'A boolean indicating if the form was displayed within an iframe' },
222
+ { name: 'is_masked', type: 'boolean', description: 'A boolean indicating if the certificate is masked and does not show source information nor a session replay' },
223
+ { name: 'sensitive_hidden_content_elements', type: 'number', description: 'Count of how many content elements (e.g. img, div) are marked sensitive and hidden from the session replay' },
224
+ { name: 'sensitive_hidden_form_elements', type: 'number', description: 'Count of how many form elements (e.g. input, textarea) are marked sensitive and hidden from the session replay' },
225
+ { name: 'os_full', type: 'string', description: 'A human-friendly version of the operating system information parsed from the user-agent' },
226
+ { 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
+ { name: 'os_name', type: 'string', description: 'Operating system name' },
228
+ { 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.' }
230
+ ];
231
+
232
+ module.exports = {
233
+ request,
234
+ response,
235
+ validate
236
+ }
@@ -0,0 +1,35 @@
1
+ const { get } = require('lodash');
2
+ const request = require('request');
3
+
4
+ module.exports = (req, res) => {
5
+ const { apiKey } = req.query;
6
+ if (!apiKey) return res.status(422).send({ error: 'missing required field: apiKey' });
7
+
8
+ const url = get(process, 'env.NODE_ENV') === 'production' ? 'https://app.trustedform.com/account' : 'https://app.staging.trustedform.com/account';
9
+
10
+ const options = {
11
+ url,
12
+ method: 'GET',
13
+ headers: {
14
+ accept: 'application/json',
15
+ authorization: `Basic ${Buffer.from(`X:${apiKey}`).toString('base64')}`
16
+ },
17
+ };
18
+
19
+ request(options, (err, response, body) => {
20
+ if (err) return res.status(422).send({ error: err.message });
21
+ if (response.statusCode !== 200) {
22
+ let message = '';
23
+ try {
24
+ message = JSON.parse(body).error;
25
+ }
26
+ catch (e) {
27
+ message = `Error (${response.statusCode}); unable to parse response from TrustedForm`;
28
+ }
29
+ return res.status(response.statusCode).send({ error: message });
30
+ }
31
+ else {
32
+ res.status(200).send(body);
33
+ }
34
+ });
35
+ };
@@ -0,0 +1,8 @@
1
+ const express = require('express');
2
+ const { json } = require('body-parser');
3
+ const account = require('./account');
4
+
5
+ module.exports =
6
+ express.Router()
7
+ .use(json())
8
+ .use('/account', account)
package/lib/ui/index.js CHANGED
@@ -1,7 +1,16 @@
1
1
  const express = require('express');
2
2
  const path = require('path');
3
+ const { existsSync } = require('fs');
3
4
 
4
5
  const router = express.Router()
5
- .use(express.static(path.join(__dirname, '/public')));
6
+ .use(express.static(path.join(__dirname, 'public')));
7
+
8
+ if (existsSync(path.join(__dirname, 'oauth'))) {
9
+ router.use('/oauth', require(path.join(__dirname, 'oauth')));
10
+ }
11
+
12
+ if (existsSync(path.join(__dirname, 'api'))) {
13
+ router.use(require(path.join(__dirname, 'api')));
14
+ }
6
15
 
7
16
  module.exports = router;
@@ -59,6 +59,7 @@ export default {
59
59
  },
60
60
  mounted () {
61
61
  const { integration } = this.$store.state.config;
62
+ if (integration.includes('outbound.trustedform')) this.$router.push('/4');
62
63
  if (!integration.includes('insights')) {
63
64
  this.isDataService = false;
64
65
  }
@@ -0,0 +1,62 @@
1
+ <template>
2
+ <div>
3
+ <header>
4
+ Add TrustedForm Add-On
5
+ </header>
6
+ <section>
7
+ <form>
8
+ <h3>Select the TrustedForm products to add to your flow.</h3>
9
+ <p>You may select all products that you would like to add to your flow. Each product will be charged depending on your contract. {{errors}}</p>
10
+ <ul>
11
+ <li>
12
+ <input type="checkbox" :disabled="!products.retain.enabled" v-model="products.retain.selected"><span> Retain</span>
13
+ <p class="help-text">Store consent in TrustedForm certificates for legal (TCPA) compliance.</p>
14
+ </li>
15
+ <li>
16
+ <input type="checkbox" :disabled="!products.insights.enabled" v-model="products.insights.selected"><span> Insights</span>
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
+ </li>
19
+ </ul>
20
+ </form>
21
+ </section>
22
+ <Navigation
23
+ :showPrevious="false"
24
+ :onNext="!showFinish ? next : undefined"
25
+ :onFinish="showFinish ? finish : undefined"
26
+ :disableNext="!products.retain.selected && !products.insights.selected"
27
+ />
28
+ </div>
29
+ </template>
30
+ <script>
31
+ import { Navigation } from '@activeprospect/integration-components'
32
+
33
+ export default {
34
+ data () {
35
+ return {
36
+ products: this.$store.getters.getProducts,
37
+ errors: this.$store.getters.getErrors
38
+ };
39
+ },
40
+ components: {
41
+ Navigation
42
+ },
43
+ computed: {
44
+ showFinish () {
45
+ return this.products.retain.selected && !this.products.insights.selected;
46
+ }
47
+ },
48
+ methods: {
49
+ next () {
50
+ this.$store.state.products = this.products;
51
+ this.$router.push('/5');
52
+ },
53
+ finish () {
54
+ this.$store.state.products = this.products;
55
+ this.$store.dispatch('finish');
56
+ }
57
+ },
58
+ created () {
59
+ this.$store.dispatch('getProducts')
60
+ }
61
+ };
62
+ </script>
@@ -0,0 +1,80 @@
1
+ <template>
2
+ <div>
3
+ <header>
4
+ TrustedForm Insights Configuration
5
+ </header>
6
+ <section>
7
+ <form>
8
+ <h3>Select Data Points</h3>
9
+ <p>TrustedForm Insights provides the following data related to the lead that filled out the form. Each selection of data points will be charged individually.</p>
10
+ <table>
11
+ <thead>
12
+ <tr>
13
+ <th><input type="checkbox" v-model="header" :indeterminate.prop="selected === 'some'" @click="toggleAll"></th>
14
+ <th>Select All</th>
15
+ <th></th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <tr v-for="field in Object.keys(fields)" :key="fields[field].name">
20
+ <td><input type="checkbox" v-model="fields[field].selected" @change="updateHeader"></td>
21
+ <td>{{fields[field].name}}</td>
22
+ <td v-html="fields[field].description"></td>
23
+ </tr>
24
+ </tbody>
25
+ </table>
26
+ </form>
27
+ </section>
28
+ <Navigation
29
+ :onFinish="finish"
30
+ :disableFinish="selected === 'none'"
31
+ />
32
+ </div>
33
+ </template>
34
+ <script>
35
+ import { Navigation } from '@activeprospect/integration-components'
36
+ import { filter } from 'lodash';
37
+
38
+ export default {
39
+ data () {
40
+ return {
41
+ fields: this.$store.state.v4Fields,
42
+ header: false,
43
+ selected: 'none'
44
+ };
45
+ },
46
+ components: {
47
+ Navigation
48
+ },
49
+ methods: {
50
+ amountSelected () {
51
+ // 'some', 'all', or 'none'
52
+ const totalFields = Object.keys(this.fields).length;
53
+ const selectedFields = filter(this.fields, function (field) { return field.selected; }).length;
54
+ if (selectedFields === 0) return 'none';
55
+ if (totalFields === selectedFields) return 'all';
56
+ return 'some';
57
+ },
58
+ toggleAll () {
59
+ // set to false when 'all' are selected, otherwise set to true
60
+ const bool = this.amountSelected() !== 'all';
61
+ for (const field in this.fields) {
62
+ this.fields[field].selected = bool;
63
+ }
64
+ this.updateHeader();
65
+ },
66
+ updateHeader () {
67
+ this.selected = this.amountSelected();
68
+ this.header = this.selected === 'all';
69
+ },
70
+ finish () {
71
+ this.$store.state.v4Fields = this.fields;
72
+ this.$store.dispatch('finish');
73
+ }
74
+ },
75
+ mounted () {
76
+ // ensure header is set correctly when returning to this page with some props selected
77
+ this.updateHeader();
78
+ }
79
+ }
80
+ </script>
@@ -4,6 +4,8 @@ import Config from './config/Config.vue';
4
4
  import PageOne from './config/Page1.vue';
5
5
  import PageTwo from './config/Page2.vue';
6
6
  import PageThree from './config/Page3.vue';
7
+ import PageFour from './config/Page4.vue';
8
+ import PageFive from './config/Page5.vue';
7
9
 
8
10
  Vue.use(Router);
9
11
 
@@ -29,6 +31,16 @@ export default new Router({
29
31
  path: '3',
30
32
  name: 'PageThree',
31
33
  component: PageThree
34
+ },
35
+ {
36
+ path: '4',
37
+ name: 'PageFour',
38
+ component: PageFour
39
+ },
40
+ {
41
+ path: '5',
42
+ name: 'PageFive',
43
+ component: PageFive
32
44
  }
33
45
  ]
34
46
  }
@@ -1,20 +1,70 @@
1
1
  import Vuex from 'vuex';
2
2
  import fieldData from './fieldData';
3
+ import v4Fields from './v4fields';
4
+ import axios from 'axios';
5
+ import { get } from 'lodash';
3
6
 
4
7
  const initStore = (config, ui) => new Vuex.Store({
5
8
  state: {
6
9
  // field descriptions
7
10
  fieldData,
11
+ v4Fields,
8
12
 
9
13
  // integration state
10
14
  ui,
11
- config
15
+ config,
16
+ errors: undefined,
17
+ products: {
18
+ retain: { enabled: false, selected: false },
19
+ insights: { enabled: false, selected: false }
20
+ }
21
+ },
22
+ mutations: {
23
+ setErrors (state, errors) {
24
+ state.errors = errors;
25
+ },
26
+ setProduct (state, { product, value }) {
27
+ state.products[product] = value;
28
+ }
29
+ },
30
+ getters: {
31
+ getProducts: (state) => {
32
+ return state.products;
33
+ },
34
+ getErrors: (state) => {
35
+ return state.errors;
36
+ }
12
37
  },
13
38
  actions: {
14
39
  cancel (context) {
15
40
  context.state.ui.cancel();
16
41
  },
42
+ getProducts (context) {
43
+ axios
44
+ .get(`account?apiKey=${config.credential.token}`)
45
+ .then(function (response) {
46
+ const availableProducts = [
47
+ 'retain',
48
+ 'insights'
49
+ ]
50
+ const products = get(response, 'data.product_components');
51
+ availableProducts.forEach(function (product) {
52
+ context.commit('setProduct', { product, value: {
53
+ enabled: products.includes(product),
54
+ selected: false
55
+ }});
56
+ });
57
+ })
58
+ .catch(function (error) {
59
+ if (get(error, 'response.status') === 401) {
60
+ context.commit('setErrors', 'no TrustedForm account found for this API key');
61
+ } else {
62
+ context.commit('setErrors', get(error, 'response.data') || error.message);
63
+ }
64
+ });
65
+ },
17
66
  finish (context) {
67
+ const { products, v4Fields } = context.state;
18
68
  const flow = {
19
69
  steps: [{
20
70
  type: 'recipient',
@@ -28,6 +78,23 @@ const initStore = (config, ui) => new Vuex.Store({
28
78
  }
29
79
  }]
30
80
  };
81
+ if (config.integration === 'leadconduit-trustedform.outbound.trustedform') {
82
+ Object.keys(products).forEach((product) => {
83
+ flow.steps[0].integration.mappings.push({
84
+ property: `trustedform.${product}`,
85
+ value: products[product].selected ? 'true' : 'false'
86
+ });
87
+ });
88
+
89
+ if (products.insights.selected) {
90
+ Object.keys(v4Fields).forEach((field) => {
91
+ flow.steps[0].integration.mappings.push({
92
+ property: `insights.${field}`,
93
+ value: v4Fields[field].selected ? 'true' : 'false'
94
+ })
95
+ });
96
+ }
97
+ }
31
98
  context.state.ui.create({ flow });
32
99
  }
33
100
  }