Created
November 2, 2018 08:10
-
-
Save hfreire/f04fb34d3d457ffaed152e6759e8c516 to your computer and use it in GitHub Desktop.
π Hack π€ to consent βοΈ e-mail and data processing for π€·πΌββοΈ contact persons in π Lime Go CRM https://www.lime-go.se
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BASE_URL = 'https://go.lime-go.com' | |
const ACCOUNT_ID = process.env.LIMEGO_ACCOUNT_ID | |
const REQUEST_COOKIE = process.env.LIMEGO_REQUEST_COOKIE | |
const REQUEST_VERIFICATION_TOKEN = process.env.LIMEGO_REQUEST_VERIFICATION_TOKEN | |
const REQUEST_SENDER_ID = process.env.LIMEGO_REQUEST_SENDER_ID | |
const _ = require('lodash') | |
const Logger = require('modern-logger') | |
const Request = require('request-on-steroids') | |
const request = new Request({ | |
request: { | |
headers: { | |
cookie: REQUEST_COOKIE, | |
origin: BASE_URL, | |
referer: `${BASE_URL}/${ACCOUNT_ID}/`, | |
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8', | |
'accept-encoding': 'gzip, deflate, br', | |
'content-type': 'application/json; charset=UTF-8', | |
'accept': 'application/json, text/javascript, */*; q=0.01', | |
'authority': 'go.lime-go.com', | |
'__requestverificationtoken': REQUEST_VERIFICATION_TOKEN, | |
senderid: REQUEST_SENDER_ID, | |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36', | |
'x-requested-with': 'XMLHttpRequest' | |
} | |
} | |
}) | |
const doSearchRequest = async (endpoint = `/${ACCOUNT_ID}/personquery/search`) => { | |
Logger.info(`POST ${BASE_URL}${endpoint}`) | |
const options = { | |
url: `${BASE_URL}${endpoint}`, | |
json: true, | |
body: { size: 100, filters: [ { name: 'employer_relation', values: [ '1', '2' ], option: 'or' } ] } | |
} | |
const { body } = await request.post(options).delay(700) | |
return body | |
} | |
const doConsentRequest = async (endpoint) => { | |
if (!endpoint) { | |
throw new Error('No consent endpoint') | |
} | |
Logger.info(`POST ${BASE_URL}${endpoint}`) | |
const options = { | |
url: `${BASE_URL}${endpoint}`, | |
json: true, | |
body: { 'processingConsent': true, 'mailConsent': true } | |
} | |
const { body } = await request.post(options).delay(500) | |
return body | |
} | |
(async () => { | |
let numberOfConsents = 0 | |
let next = false | |
let objects = [] | |
do { | |
({ next, objects }) = await doSearchRequest(searchEndpoint) | |
_.forEach(objects, async (object) => { | |
const consentEndpoint = _.get(object, 'actions.setConsents') | |
const hasMailConsent = _.get(object, 'data.integrity.hasMailConsent', false) | |
const hasProcessingConsent = _.get(object, 'data.integrity.hasProcessingConsent', false) | |
if (!hasMailConsent || !hasProcessingConsent) { | |
Logger.info(`Consenting e-mail usage and data processing for ${object.heading} ${object.subHeading}`) | |
try { | |
await doConsentRequest(consentEndpoint) | |
numberOfConsents++ | |
} catch (error) { | |
Logger.error(error) | |
} | |
} | |
}) | |
} while (next) | |
Logger.info(`Consented e-mail usage and data processing for ${numberOfConsents} person(s)`) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment