@mhubcloud/tms_core 1.6.0 → 1.7.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.
@@ -13,19 +13,18 @@ const utils = require("./utils");
13
13
  module.exports = async function DefaultPublisher(context, eventHubMessages, source, publisher, trigger) {
14
14
  context.log(`JavaScript eventhub trigger function called for message array [${eventHubMessages.length}]`);
15
15
  global.console.log = context.log.warn || context.log;
16
-
17
- let ret = context.test ? [] : undefined;
18
16
  let mi = 0;
17
+
18
+ let processMessagePromises = [];
19
19
  for (const message of eventHubMessages) {
20
- try{
21
- var res = await processMessage(message, context, source, publisher, trigger, mi++);
22
- if (context.test && res instanceof Array) ret.push(...res);
23
- }catch(exception){
24
- utils.logException(exception);
20
+ processMessagePromises.push(processMessage(message, context, source, publisher, trigger, mi++));
21
+ }
22
+ let results = await Promise.allSettled(processMessagePromises);
23
+ for (const result of results) {
24
+ if(result.status === "rejected"){
25
+ utils.logException(result.reason);
25
26
  }
26
27
  }
27
-
28
- if (context.test) return utils.removeUndefined(ret);
29
28
  }
30
29
 
31
30
  /**
@@ -46,14 +45,8 @@ async function processMessage(message, context, source, platfromPublisher, trigg
46
45
  const data = platfromPublisher.parse(message, context);
47
46
  const logProp = {
48
47
  source: source,
49
- raw_message: JSON.stringify(message)
48
+ data: JSON.stringify(data)
50
49
  };
51
- if (!data) {
52
- utils.log2(context, 3, "Message completelly invalid", logProp);
53
- return false;
54
- }
55
- delete logProp.raw_message;
56
- logProp.data = JSON.stringify(data);
57
50
 
58
51
  /** @type {EventPublisher[]} */
59
52
  const publishers = trigger(data);
@@ -79,7 +72,7 @@ async function processMessage(message, context, source, platfromPublisher, trigg
79
72
 
80
73
  prevPublisher = eventPublisher;
81
74
 
82
- const res = await publishMessage(mapped, eventPublisher.config, logProp, context, platfromPublisher, message.event.code + (message.event.name ? "/"+ message.event.name : ""));
75
+ const res = await publishMessage(mapped, eventPublisher.config, context, platfromPublisher, message.event.code + (message.event.name ? "/"+ message.event.name : ""));
83
76
  if (res) published = true;
84
77
  if (context.test && res instanceof Array) ret.push(...res);
85
78
  if (res && !context.test) ret = true;
@@ -101,13 +94,12 @@ async function processMessage(message, context, source, platfromPublisher, trigg
101
94
  * Publishes a message to configured publisher
102
95
  * @param {Object} mapped Mapped message data
103
96
  * @param {Object} config Platform-specific platform publisher configuration
104
- * @param {{[key: string]: string}} logProp Dictionary of additional data for Application Insights logging
105
97
  * @param {FunctionContext} context Azure Function context
106
98
  * @param {PlatformPublisher} platfromPublisher Publisher implementation instance (from <publisher>/publisher.js)
107
99
  * @param {string} event for which logic was triggered
108
100
  * @returns {Promise<boolean|ReqResTestData[]>} In normal mode returns true/false indicating if the message has been successfully published to any platform. In (unit) test mode returns array of publication requests (or even results if it's not unit test), fulse just in case the were no publishers configured.
109
101
  */
110
- async function publishMessage(mapped, config, logProp, context, platfromPublisher, event) {
102
+ async function publishMessage(mapped, config, context, platfromPublisher, event) {
111
103
  let ret = context.test ? [] : true;
112
104
  if (context.test)
113
105
  ret.push({ req: mapped, config: config });
package/lib/utils.js CHANGED
@@ -6,7 +6,10 @@ const https = require('https');
6
6
  let aiClient;
7
7
  if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
8
8
  const appInsights = require("applicationinsights");
9
- appInsights.setup().start(); //Set einvironmet variable APPINSIGHTS_INSTRUMENTATIONKEY, so setup() can be called w/o parameters
9
+ appInsights
10
+ .setup() //Set einvironmet variable APPINSIGHTS_INSTRUMENTATIONKEY, so setup() can be called w/o parameters
11
+ .setUseDiskRetryCaching(false)
12
+ .start();
10
13
  aiClient = appInsights.defaultClient;
11
14
  }
12
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhubcloud/tms_core",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "description": "Core function for mHub Cloud TMS publishers",
5
5
  "homepage": "https://mhubcloud.com/",
6
6
  "license": "Apache 2.0",
package/publishers/CJ.js CHANGED
@@ -24,7 +24,7 @@ module.exports = {
24
24
  publish: async function publish(config, data, event) {
25
25
  if(!data.cjevent){
26
26
  console.log(`CJ - ${event} - skipped because CJEVENT is missing`);
27
- return;
27
+ return false;
28
28
  }
29
29
 
30
30
  data = utils.removeUndefined(data);
package/tests/CJ.js CHANGED
@@ -42,6 +42,123 @@ describe('test CJ publisher', function () {
42
42
  ],
43
43
  "enqueuedAt": 1657003409370,
44
44
  "ads": [{"adPlatform":"cjaffiliate","adCodes":{"cjevent":"816f5670dbf52c3dc27a7e849903c327d705ef643993fbab3"},"visitAt":1658392668000}]
45
+ },
46
+ {
47
+ "currencyCode": "CZK",
48
+ "event": {
49
+ "region": "MAIN",
50
+ "id": "115169112-4870.1657003407533",
51
+ "code": "purchase"
52
+ },
53
+ "session": {
54
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
55
+ "ip": "89.177.126.237",
56
+ "referrer": "https://crossmasters.com/"
57
+ },
58
+ "referrer": "https://crossmasters.com/",
59
+ "permissions": [],
60
+ "identity": {
61
+ "piano": {
62
+ "id": "1657003393413.319297501"
63
+ }
64
+ },
65
+ "publisher": {
66
+ "code": "mhubcloud.com",
67
+ "tm": "GTM-N7K9L4X",
68
+ "tmv": "494"
69
+ },
70
+ "$schema": "/mhub/purchase",
71
+ "id": "20162351",
72
+ "revenue": 440,
73
+ "products": [
74
+ {
75
+ "id": "Car",
76
+ "price": 440,
77
+ "quantity": 1
78
+ }
79
+ ],
80
+ "enqueuedAt": 1657003409370,
81
+ "ads": [{"adPlatform":"cjaffiliate","adCodes":{"cjevent":"816f5670dbf52c3dc27a7e849903c327d705ef643993fbab3"},"visitAt":1658392668000}]
82
+ }
83
+ ];
84
+ await test(eventHubMessages);
85
+ });
86
+
87
+ it('purchase', async function () {
88
+ var eventHubMessages = [
89
+ {
90
+ "currencyCode": "CZK",
91
+ "event": {
92
+ "region": "MAIN",
93
+ "id": "115169112-4870.1657003407533",
94
+ "code": "purchase"
95
+ },
96
+ "session": {
97
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
98
+ "ip": "89.177.126.237",
99
+ "referrer": "https://crossmasters.com/"
100
+ },
101
+ "referrer": "https://crossmasters.com/",
102
+ "permissions": [],
103
+ "identity": {
104
+ "piano": {
105
+ "id": "1657003393413.319297501"
106
+ }
107
+ },
108
+ "publisher": {
109
+ "code": "mhubcloud.com",
110
+ "tm": "GTM-N7K9L4X",
111
+ "tmv": "494"
112
+ },
113
+ "$schema": "/mhub/purchase",
114
+ "id": "20162351",
115
+ "revenue": 440,
116
+ "products": [
117
+ {
118
+ "id": "Car",
119
+ "price": 440,
120
+ "quantity": 1
121
+ }
122
+ ],
123
+ "enqueuedAt": 1657003409370,
124
+ "ads": [{"adPlatform":"cjaffiliate","adCodes":{"cjevent":"816f5670dbf52c3dc27a7e849903c327d705ef643993fbab3"},"visitAt":1658392668000}]
125
+ },
126
+ {
127
+ "currencyCode": "CZK",
128
+ "event": {
129
+ "region": "MAIN",
130
+ "id": "115169112-4870.1657003407533",
131
+ "code": "purchase"
132
+ },
133
+ "session": {
134
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
135
+ "ip": "89.177.126.237",
136
+ "referrer": "https://crossmasters.com/"
137
+ },
138
+ "referrer": "https://crossmasters.com/",
139
+ "permissions": [],
140
+ "identity": {
141
+ "piano": {
142
+ "id": "1657003393413.319297501"
143
+ }
144
+ },
145
+ "publisher": {
146
+ "code": "mhubcloud.com",
147
+ "tm": "GTM-N7K9L4X",
148
+ "tmv": "494"
149
+ },
150
+ "$schema": "/mhub/purchase",
151
+ "id": "20162351",
152
+ "revenue": 440,
153
+ "products": [
154
+ {
155
+ "id": "Car",
156
+ "price": 440,
157
+ "quantity": 1
158
+ }
159
+ ],
160
+ "enqueuedAt": 1657003409370,
161
+ "ads": [{"adPlatform":"cjaffiliate","adCodes":{"cjevent":"816f5670dbf52c3dc27a7e849903c327d705ef643993fbab3"},"visitAt":1658392668000}]
45
162
  }
46
163
  ];
47
164
  await test(eventHubMessages);