@mhubcloud/tms_core 2.0.0-beta.0 → 2.0.0-beta.2
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.
- package/dist/index.js +624 -0
- package/package.json +2 -2
- package/src/index.ts +2 -1
- package/src/utils/testUtils.ts +18 -0
- package/tests/AffiliatePort.js +1 -1
- package/tests/CJ.js +1 -1
- package/tests/Facebook.js +1 -1
- package/tests/GoogleAnalytics4.js +1 -1
- package/tests/Piano.js +1 -1
- package/tests/UniversalAnalytics.js +1 -1
- package/js/lib/defaultPublisher.js +0 -116
- package/js/lib/utils.js +0 -349
- package/js/publishers/AffiliatePort.js +0 -78
- package/js/publishers/CJ.js +0 -68
- package/js/publishers/Facebook.js +0 -64
- package/js/publishers/GoogleAnalytics4.js +0 -76
- package/js/publishers/HttpPublisher.js +0 -64
- package/js/publishers/Piano.js +0 -68
- package/js/publishers/UniversalAnalytics.js +0 -75
- package/tests/testUtils.js +0 -7
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const fetch = require('node-fetch');
|
|
2
|
-
const utils = require("../lib/utils");
|
|
3
|
-
const SOURCE = "f_Facebook";
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
/**
|
|
7
|
-
* Processed data comming from EventHub to data for further processing
|
|
8
|
-
* @param {Object} data The data comming from EventHub
|
|
9
|
-
* @param {FunctionContext} test Azure Function context.test
|
|
10
|
-
* @returns {Object} Data for further processing
|
|
11
|
-
*/
|
|
12
|
-
parse: function parse(data, test) {
|
|
13
|
-
//ConsumerBase.cs:ConsumeOneEventAsync
|
|
14
|
-
data.enqueuedAt = test ? 1600000000000 : Date.now();
|
|
15
|
-
return data;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Publishes data to Facebook
|
|
20
|
-
* @param {FunctionContext} log Azure Function context.log.warn
|
|
21
|
-
* @param {{id: string, access_token: string}} config Publisher configuration
|
|
22
|
-
* @param {Object} data Data in publisher-friendly format to be published
|
|
23
|
-
* @param {string} event for which is it triggered
|
|
24
|
-
*/
|
|
25
|
-
publish: async function publish(log, config, data, event) {
|
|
26
|
-
data = utils.removeUndefined(data);
|
|
27
|
-
const reqOpts = {
|
|
28
|
-
method: "post",
|
|
29
|
-
body: JSON.stringify({ data: [data] }),
|
|
30
|
-
headers: {
|
|
31
|
-
'Content-Type': 'application/json'
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
//https://graph.facebook.com/v11.0/<id>/events
|
|
35
|
-
const baseUrl = "https://graph.facebook.com/v11.0/" + encodeURIComponent(config.id) + "/events";
|
|
36
|
-
const query = "?access_token=" + encodeURI(config.access_token);
|
|
37
|
-
const url = baseUrl + query;
|
|
38
|
-
const resp = await fetch(url, reqOpts);
|
|
39
|
-
|
|
40
|
-
if (process.env.PUBLISHER_TESTURL) {
|
|
41
|
-
try {
|
|
42
|
-
utils.prepareTestRequestHeaders(reqOpts.headers, url, reqOpts, resp);
|
|
43
|
-
await fetch(process.env.PUBLISHER_TESTURL + query, reqOpts);
|
|
44
|
-
} catch { }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await utils.handleResponse(resp, event);
|
|
48
|
-
|
|
49
|
-
log(`Facebook - ${event} - sent`);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Validates an object against given schema
|
|
54
|
-
* @param {Object} data An object to validate.
|
|
55
|
-
* @param {string} schema Name of the schema. That's name of a file with `.schema.json` extension in `customizable/schemas` subfolder of current publisher folder
|
|
56
|
-
* @returns {boolean} Validation result, true if successful, false if unsuccessfull (in which case more info is written to console)
|
|
57
|
-
*/
|
|
58
|
-
validate: function validate(data, schema) {
|
|
59
|
-
if (!schema) throw new Error("Schema parameters not provided");
|
|
60
|
-
if (schema.indexOf("/") >= 0) throw new Error("Schema must be provided as schema name, not schema path");
|
|
61
|
-
//More validation done by utils.validate
|
|
62
|
-
return utils.validate(data, SOURCE, schema);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const fetch = require('node-fetch');
|
|
2
|
-
const utils = require("../lib/utils");
|
|
3
|
-
const SOURCE = "f_GoogleAnalytics4";
|
|
4
|
-
|
|
5
|
-
//https://cloud.google.com/appengine/docs/standard/php7/integrating-with-analytics#server-side_analytics_collection
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
/**
|
|
9
|
-
* Processed data comming from EventHub to data for further processing
|
|
10
|
-
* @param {Object} data The data comming from EventHub
|
|
11
|
-
* @param {FunctionContext} test Azure Function context.test
|
|
12
|
-
* @returns {Object} Data for further processing
|
|
13
|
-
*/
|
|
14
|
-
parse: function parse(data, test) {
|
|
15
|
-
//ConsumerBase.cs:ConsumeOneEventAsync
|
|
16
|
-
data.enqueuedAt = test ? 1600000000000 : Date.now();
|
|
17
|
-
return data;
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Publishes data to Google Analytics
|
|
22
|
-
* @param {FunctionContext} log Azure Function context.log.warn
|
|
23
|
-
* @param {{tid: string}} config Publisher configuration
|
|
24
|
-
* @param {{action: string, ti: string, [key:string]: string|number|boolean}} data Data in publisher-friendly format to be published
|
|
25
|
-
*/
|
|
26
|
-
publish: async function publish(log, config, data, event) {
|
|
27
|
-
data = utils.removeUndefined(data);
|
|
28
|
-
data.v = 2;
|
|
29
|
-
data.seg = 1;
|
|
30
|
-
data.gcs = 111;
|
|
31
|
-
data.tid = config.trackingId;
|
|
32
|
-
|
|
33
|
-
let payload = "";
|
|
34
|
-
|
|
35
|
-
for (const prp in data) {
|
|
36
|
-
if (data.hasOwnProperty(prp)) {
|
|
37
|
-
if (payload) payload += "&";
|
|
38
|
-
payload += encodeURI(prp) + "=" + encodeURI(data[prp]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var reqOpts = {
|
|
43
|
-
hostname: 'www.google-analytics.com',
|
|
44
|
-
port: 443,
|
|
45
|
-
path: '/g/collect?' + payload,
|
|
46
|
-
method: 'POST'
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
await utils.httpRequest(reqOpts);
|
|
50
|
-
|
|
51
|
-
if (process.env.PUBLISHER_TESTURL) {
|
|
52
|
-
try {
|
|
53
|
-
reqOpts.headers = {};
|
|
54
|
-
utils.prepareTestRequestHeaders(reqOpts.headers, reqOpts.hostname + reqOpts.path , reqOpts);
|
|
55
|
-
await fetch(process.env.PUBLISHER_TESTURL, reqOpts);
|
|
56
|
-
} catch(exception) {
|
|
57
|
-
warn(exception);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
log(`GoogleAnalytics4 - ${event} - sent`);
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Validates an object against given schema
|
|
66
|
-
* @param {Object} data An object to validate.
|
|
67
|
-
* @param {string} schema Name of the schema. That's name of a file with `.schema.json` extension in `customizable/schemas` subfolder of current publisher folder
|
|
68
|
-
* @returns {boolean} Validation result, true if successful, false if unsuccessfull (in which case more info is written to console)
|
|
69
|
-
*/
|
|
70
|
-
validate: function validate(data, schema) {
|
|
71
|
-
if (!schema) throw new Error("Schema parameters not provided");
|
|
72
|
-
if (schema.indexOf("/") >= 0) throw new Error("Schema must be provided as schema name, not schema path");
|
|
73
|
-
//More validation done by utils.validate
|
|
74
|
-
return utils.validate(data, SOURCE, schema);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const fetch = require('node-fetch');
|
|
2
|
-
const utils = require("../lib/utils");
|
|
3
|
-
const SOURCE = "f_HttpPublisher";
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
/**
|
|
7
|
-
* Processed data comming from EventHub to data for further processing
|
|
8
|
-
* @param {Object} data The data comming from EventHub
|
|
9
|
-
* @param {FunctionContext} test Azure Function context.test
|
|
10
|
-
* @returns {Object} Data for further processing
|
|
11
|
-
*/
|
|
12
|
-
parse: function parse(data, test) {
|
|
13
|
-
//ConsumerBase.cs:ConsumeOneEventAsync
|
|
14
|
-
data.enqueuedAt = test ? 1600000000000 : Date.now();
|
|
15
|
-
return data;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Publishes data to provided URL
|
|
20
|
-
* @param {FunctionContext} log Azure Function context.log.warn
|
|
21
|
-
* @param {string} event Required: event for which is it triggered
|
|
22
|
-
* @param {string} url Required: Request URL with query parameters
|
|
23
|
-
* @param {string} platform Required: Name of the plaform to which request is sent
|
|
24
|
-
* @param {string} method Required: Request method - GET|POST|PUT...
|
|
25
|
-
* @param {Object} headers Optional: Object of request headers
|
|
26
|
-
* @param {Object} body Optional: Non-strigifed request body object
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
publish: async function publish(log, event, platform, url, method, headers = {}, body = {}) {
|
|
30
|
-
const reqOpts = {
|
|
31
|
-
method: method,
|
|
32
|
-
headers: headers
|
|
33
|
-
};
|
|
34
|
-
if(method == "POST"){
|
|
35
|
-
reqOpts.body = JSON.stringify(body);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const resp = await fetch(url, reqOpts);
|
|
39
|
-
|
|
40
|
-
if (process.env.PUBLISHER_TESTURL) {
|
|
41
|
-
try {
|
|
42
|
-
utils.prepareTestRequestHeaders(reqOpts.headers, url, reqOpts, resp);
|
|
43
|
-
await fetch(process.env.PUBLISHER_TESTURL, reqOpts);
|
|
44
|
-
} catch { }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await utils.handleResponse(resp, event);
|
|
48
|
-
|
|
49
|
-
log(`${platform} - ${event} - sent`);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Validates an object against given schema
|
|
54
|
-
* @param {Object} data An object to validate.
|
|
55
|
-
* @param {string} schema Name of the schema. That's name of a file with `.schema.json` extension in `customizable/schemas` subfolder of current publisher folder
|
|
56
|
-
* @returns {boolean} Validation result, true if successful, false if unsuccessfull (in which case more info is written to console)
|
|
57
|
-
*/
|
|
58
|
-
validate: function validate(data, schema) {
|
|
59
|
-
if (!schema) throw new Error("Schema parameters not provided");
|
|
60
|
-
if (schema.indexOf("/") >= 0) throw new Error("Schema must be provided as schema name, not schema path");
|
|
61
|
-
//More validation done by utils.validate
|
|
62
|
-
return utils.validate(data, SOURCE, schema);
|
|
63
|
-
}
|
|
64
|
-
};
|
package/js/publishers/Piano.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const utils = require("../lib/utils");
|
|
2
|
-
const fetch = require('node-fetch');
|
|
3
|
-
const SOURCE = "f_Piano";
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
/**
|
|
7
|
-
* Processed data comming from EventHub to data for further processing
|
|
8
|
-
* @param {Object} data The data comming from EventHub
|
|
9
|
-
* @param {FunctionContext} test Azure Function context.test
|
|
10
|
-
* @returns {Object} Data for further processing
|
|
11
|
-
*/
|
|
12
|
-
parse: function parse(data, test) {
|
|
13
|
-
//ConsumerBase.cs:ConsumeOneEventAsync
|
|
14
|
-
data.enqueuedAt = test ? 1600000000000 : Date.now();
|
|
15
|
-
return data;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Publishes data to Piano
|
|
20
|
-
* @param {FunctionContext} log Azure Function context.log.warn
|
|
21
|
-
* @param {{collectionDomain: string, siteId: string|number}} config Publisher configuration
|
|
22
|
-
* @param {{pianoData: {events: {name: string, data: {[key: string]: any}}[]}, aux: {visitorId: string, ref: string, userAgent?: string, referer?: string, forwardedFor?: string}}} data Data in publisher-friendly format to be published
|
|
23
|
-
* @returns {*} Data returned by platform, if possible JSON-deserialized (otherwise as string)
|
|
24
|
-
* @param {string} event for which is it triggered
|
|
25
|
-
*/
|
|
26
|
-
publish: async function publish(log, config, data, event) {
|
|
27
|
-
data = utils.removeUndefined(data);
|
|
28
|
-
let dt = "";
|
|
29
|
-
//https://developers.atinternet-solutions.com/piano-analytics-tagging-en/event-tagging-piano-analytics-en/events-pattern-en/#post-request_5
|
|
30
|
-
//https://<collection-domain>/<path>?s=<site-id>&idclient=<visitor-id>&ref=<previous-url>
|
|
31
|
-
dt = "?s=" + encodeURI(config.siteId);
|
|
32
|
-
dt += "&idclient=" + encodeURI(data.aux.visitorId);
|
|
33
|
-
dt += "&ref=" + encodeURI(data.aux.ref);
|
|
34
|
-
|
|
35
|
-
const reqOpts = { method: "post", headers: {} /*Needed by test call*/, body: JSON.stringify(data.pianoData) };
|
|
36
|
-
if (data.aux.userAgent)
|
|
37
|
-
reqOpts.headers["User-Agent"] = data.aux.userAgent;
|
|
38
|
-
if (data.aux.referer)
|
|
39
|
-
reqOpts.headers["Referer"] = data.aux.referer;
|
|
40
|
-
if (data.aux.forwardedFor)
|
|
41
|
-
reqOpts.headers["X-Forwarded-For"] = data.aux.forwardedFor;
|
|
42
|
-
const resp = await fetch("https://" + config.collectionDomain + "/" + dt, reqOpts);
|
|
43
|
-
|
|
44
|
-
if (process.env.PUBLISHER_TESTURL) {
|
|
45
|
-
try {
|
|
46
|
-
utils.prepareTestRequestHeaders(reqOpts.headers, config.collectionDomain + dt, reqOpts, resp);
|
|
47
|
-
await fetch(process.env.PUBLISHER_TESTURL + dt, reqOpts);
|
|
48
|
-
} catch { }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
await utils.handleResponse(resp, event);
|
|
52
|
-
|
|
53
|
-
log(`Piano Analytics - ${event} - sent`);
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Validates an object against given schema
|
|
58
|
-
* @param {Object} data An object to validate.
|
|
59
|
-
* @param {string} schema Name of the schema. That's name of a file with `.schema.json` extension in `customizable/schemas` subfolder of current publisher folder
|
|
60
|
-
* @returns {boolean} Validation result, true if successful, false if unsuccessfull (in which case more info is written to console)
|
|
61
|
-
*/
|
|
62
|
-
validate: function validate(data, schema) {
|
|
63
|
-
if (!schema) throw new Error("Schema parameters not provided");
|
|
64
|
-
if (schema.indexOf("/") >= 0) throw new Error("Schema must be provided as schema name, not schema path");
|
|
65
|
-
//More validation done by utils.validate
|
|
66
|
-
return utils.validate(data, SOURCE, schema);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
const fetch = require('node-fetch');
|
|
2
|
-
const utils = require("../lib/utils");
|
|
3
|
-
const SOURCE = "f_UniversalAnalytics";
|
|
4
|
-
|
|
5
|
-
//https://cloud.google.com/appengine/docs/standard/php7/integrating-with-analytics#server-side_analytics_collection
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
/**
|
|
9
|
-
* Processed data comming from EventHub to data for further processing
|
|
10
|
-
* @param {Object} data The data comming from EventHub
|
|
11
|
-
* @param {FunctionContext} test Azure Function context.test
|
|
12
|
-
* @returns {Object} Data for further processing
|
|
13
|
-
*/
|
|
14
|
-
parse: function parse(data, test) {
|
|
15
|
-
//ConsumerBase.cs:ConsumeOneEventAsync
|
|
16
|
-
data.enqueuedAt = test ? 1600000000000 : Date.now();
|
|
17
|
-
return data;
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Publishes data to Google Analytics
|
|
22
|
-
* @param {FunctionContext} log Azure Function context.log.warn
|
|
23
|
-
* @param {{tid: string}} config Publisher configuration
|
|
24
|
-
* @param {{action: string, ti: string, [key:string]: string|number|boolean}} data Data in publisher-friendly format to be published
|
|
25
|
-
*/
|
|
26
|
-
publish: async function publish(log, config, data, event) {
|
|
27
|
-
data = utils.removeUndefined(data);
|
|
28
|
-
//https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
|
|
29
|
-
const url = "https://www.google-analytics.com/collect";
|
|
30
|
-
data.v = 1;
|
|
31
|
-
data.tid = config.trackingId;
|
|
32
|
-
let payload = "";
|
|
33
|
-
|
|
34
|
-
for (const prp in data) {
|
|
35
|
-
if (data.hasOwnProperty(prp)) {
|
|
36
|
-
if (payload) payload += "&";
|
|
37
|
-
payload += encodeURI(prp) + "=" + encodeURI(data[prp]);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const reqOpts = {
|
|
42
|
-
method: "post",
|
|
43
|
-
body: payload,
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const resp = await fetch(url, reqOpts);
|
|
50
|
-
|
|
51
|
-
if (process.env.PUBLISHER_TESTURL) {
|
|
52
|
-
try {
|
|
53
|
-
utils.prepareTestRequestHeaders(reqOpts.headers, url, reqOpts, resp);
|
|
54
|
-
await fetch(process.env.PUBLISHER_TESTURL, reqOpts);
|
|
55
|
-
} catch { }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
await utils.handleResponse(resp);
|
|
59
|
-
|
|
60
|
-
log(`Universal Analytics - ${event} - sent`);
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Validates an object against given schema
|
|
65
|
-
* @param {Object} data An object to validate.
|
|
66
|
-
* @param {string} schema Name of the schema. That's name of a file with `.schema.json` extension in `customizable/schemas` subfolder of current publisher folder
|
|
67
|
-
* @returns {boolean} Validation result, true if successful, false if unsuccessfull (in which case more info is written to console)
|
|
68
|
-
*/
|
|
69
|
-
validate: function validate(data, schema) {
|
|
70
|
-
if (!schema) throw new Error("Schema parameters not provided");
|
|
71
|
-
if (schema.indexOf("/") >= 0) throw new Error("Schema must be provided as schema name, not schema path");
|
|
72
|
-
//More validation done by utils.validate
|
|
73
|
-
return utils.validate(data, SOURCE, schema);
|
|
74
|
-
}
|
|
75
|
-
};
|