@magicpixel/rn-mp-client-sdk 0.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.
- package/LICENSE +20 -0
- package/README.md +29 -0
- package/lib/commonjs/common/app-types.js +6 -0
- package/lib/commonjs/common/app-types.js.map +1 -0
- package/lib/commonjs/common/constants.js +51 -0
- package/lib/commonjs/common/constants.js.map +1 -0
- package/lib/commonjs/common/data-store.js +361 -0
- package/lib/commonjs/common/data-store.js.map +1 -0
- package/lib/commonjs/common/event-bus.js +42 -0
- package/lib/commonjs/common/event-bus.js.map +1 -0
- package/lib/commonjs/common/logger.js +30 -0
- package/lib/commonjs/common/logger.js.map +1 -0
- package/lib/commonjs/common/network-service.js +90 -0
- package/lib/commonjs/common/network-service.js.map +1 -0
- package/lib/commonjs/common/reporter.js +107 -0
- package/lib/commonjs/common/reporter.js.map +1 -0
- package/lib/commonjs/common/utils.js +276 -0
- package/lib/commonjs/common/utils.js.map +1 -0
- package/lib/commonjs/coverage/clover.xml +6 -0
- package/lib/commonjs/coverage/coverage-final.json +1 -0
- package/lib/commonjs/coverage/lcov-report/base.css +224 -0
- package/lib/commonjs/coverage/lcov-report/block-navigation.js +83 -0
- package/lib/commonjs/coverage/lcov-report/block-navigation.js.map +1 -0
- package/lib/commonjs/coverage/lcov-report/favicon.png +0 -0
- package/lib/commonjs/coverage/lcov-report/index.html +101 -0
- package/lib/commonjs/coverage/lcov-report/prettify.css +1 -0
- package/lib/commonjs/coverage/lcov-report/prettify.js +995 -0
- package/lib/commonjs/coverage/lcov-report/prettify.js.map +1 -0
- package/lib/commonjs/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/lib/commonjs/coverage/lcov-report/sorter.js +212 -0
- package/lib/commonjs/coverage/lcov-report/sorter.js.map +1 -0
- package/lib/commonjs/coverage/lcov.info +0 -0
- package/lib/commonjs/eedl/eedl.js +262 -0
- package/lib/commonjs/eedl/eedl.js.map +1 -0
- package/lib/commonjs/index.js +214 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/models/mp-client-sdk.js +33 -0
- package/lib/commonjs/models/mp-client-sdk.js.map +1 -0
- package/lib/commonjs/processors/data-element.processor.js +191 -0
- package/lib/commonjs/processors/data-element.processor.js.map +1 -0
- package/lib/commonjs/processors/qc.processor.js +111 -0
- package/lib/commonjs/processors/qc.processor.js.map +1 -0
- package/lib/commonjs/processors/tag.processor.js +432 -0
- package/lib/commonjs/processors/tag.processor.js.map +1 -0
- package/lib/commonjs/processors/trans-function.processor.js +91 -0
- package/lib/commonjs/processors/trans-function.processor.js.map +1 -0
- package/lib/commonjs/processors/visit-id.processor.js +172 -0
- package/lib/commonjs/processors/visit-id.processor.js.map +1 -0
- package/lib/module/common/app-types.js +2 -0
- package/lib/module/common/app-types.js.map +1 -0
- package/lib/module/common/constants.js +41 -0
- package/lib/module/common/constants.js.map +1 -0
- package/lib/module/common/data-store.js +346 -0
- package/lib/module/common/data-store.js.map +1 -0
- package/lib/module/common/event-bus.js +31 -0
- package/lib/module/common/event-bus.js.map +1 -0
- package/lib/module/common/logger.js +21 -0
- package/lib/module/common/logger.js.map +1 -0
- package/lib/module/common/network-service.js +73 -0
- package/lib/module/common/network-service.js.map +1 -0
- package/lib/module/common/reporter.js +88 -0
- package/lib/module/common/reporter.js.map +1 -0
- package/lib/module/common/utils.js +263 -0
- package/lib/module/common/utils.js.map +1 -0
- package/lib/module/coverage/clover.xml +6 -0
- package/lib/module/coverage/coverage-final.json +1 -0
- package/lib/module/coverage/lcov-report/base.css +224 -0
- package/lib/module/coverage/lcov-report/block-navigation.js +81 -0
- package/lib/module/coverage/lcov-report/block-navigation.js.map +1 -0
- package/lib/module/coverage/lcov-report/favicon.png +0 -0
- package/lib/module/coverage/lcov-report/index.html +101 -0
- package/lib/module/coverage/lcov-report/prettify.css +1 -0
- package/lib/module/coverage/lcov-report/prettify.js +993 -0
- package/lib/module/coverage/lcov-report/prettify.js.map +1 -0
- package/lib/module/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/lib/module/coverage/lcov-report/sorter.js +210 -0
- package/lib/module/coverage/lcov-report/sorter.js.map +1 -0
- package/lib/module/coverage/lcov.info +0 -0
- package/lib/module/eedl/eedl.js +246 -0
- package/lib/module/eedl/eedl.js.map +1 -0
- package/lib/module/index.js +176 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/models/mp-client-sdk.js +24 -0
- package/lib/module/models/mp-client-sdk.js.map +1 -0
- package/lib/module/processors/data-element.processor.js +176 -0
- package/lib/module/processors/data-element.processor.js.map +1 -0
- package/lib/module/processors/qc.processor.js +90 -0
- package/lib/module/processors/qc.processor.js.map +1 -0
- package/lib/module/processors/tag.processor.js +396 -0
- package/lib/module/processors/tag.processor.js.map +1 -0
- package/lib/module/processors/trans-function.processor.js +73 -0
- package/lib/module/processors/trans-function.processor.js.map +1 -0
- package/lib/module/processors/visit-id.processor.js +144 -0
- package/lib/module/processors/visit-id.processor.js.map +1 -0
- package/lib/typescript/common/app-types.d.ts +101 -0
- package/lib/typescript/common/constants.d.ts +21 -0
- package/lib/typescript/common/data-store.d.ts +81 -0
- package/lib/typescript/common/event-bus.d.ts +6 -0
- package/lib/typescript/common/logger.d.ts +5 -0
- package/lib/typescript/common/network-service.d.ts +8 -0
- package/lib/typescript/common/reporter.d.ts +12 -0
- package/lib/typescript/common/utils.d.ts +38 -0
- package/lib/typescript/eedl/eedl.d.ts +46 -0
- package/lib/typescript/index.d.ts +18 -0
- package/lib/typescript/models/mp-client-sdk.d.ts +157 -0
- package/lib/typescript/processors/data-element.processor.d.ts +12 -0
- package/lib/typescript/processors/qc.processor.d.ts +4 -0
- package/lib/typescript/processors/tag.processor.d.ts +27 -0
- package/lib/typescript/processors/trans-function.processor.d.ts +12 -0
- package/lib/typescript/processors/visit-id.processor.d.ts +7 -0
- package/package.json +170 -0
- package/src/common/app-types.ts +128 -0
- package/src/common/constants.ts +43 -0
- package/src/common/data-store.ts +333 -0
- package/src/common/event-bus.ts +35 -0
- package/src/common/logger.ts +19 -0
- package/src/common/network-service.ts +85 -0
- package/src/common/reporter.ts +110 -0
- package/src/common/utils.ts +281 -0
- package/src/coverage/clover.xml +6 -0
- package/src/coverage/coverage-final.json +1 -0
- package/src/coverage/lcov-report/base.css +224 -0
- package/src/coverage/lcov-report/block-navigation.js +87 -0
- package/src/coverage/lcov-report/favicon.png +0 -0
- package/src/coverage/lcov-report/index.html +101 -0
- package/src/coverage/lcov-report/prettify.css +1 -0
- package/src/coverage/lcov-report/prettify.js +2 -0
- package/src/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/src/coverage/lcov-report/sorter.js +196 -0
- package/src/coverage/lcov.info +0 -0
- package/src/eedl/eedl.ts +233 -0
- package/src/index.tsx +258 -0
- package/src/models/mp-client-sdk.ts +174 -0
- package/src/processors/data-element.processor.ts +249 -0
- package/src/processors/qc.processor.ts +115 -0
- package/src/processors/tag.processor.ts +527 -0
- package/src/processors/trans-function.processor.ts +85 -0
- package/src/processors/visit-id.processor.ts +164 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds all the applicable tags based on the true qualification criteria. Method does not return anything
|
|
3
|
+
* because it uses pass by memory reference. The last 2 paramters (allTagInfo and applicableTagInfo) are
|
|
4
|
+
* return variables
|
|
5
|
+
* @param sdkTags
|
|
6
|
+
* @param sdkProviders
|
|
7
|
+
* @param validQcList
|
|
8
|
+
* @param allTagInfo
|
|
9
|
+
* @param applicableTagInfo
|
|
10
|
+
*/
|
|
11
|
+
import { Logger } from '../common/logger';
|
|
12
|
+
import { DataStore } from '../common/data-store';
|
|
13
|
+
import { Reporter } from '../common/reporter';
|
|
14
|
+
import { Constants } from '../common/constants';
|
|
15
|
+
import { Utils } from '../common/utils';
|
|
16
|
+
export class TagProcessor {
|
|
17
|
+
static findApplicableTags(sdkTags, sdkProviders, validQcList, allTagInfo, applicableTagInfo) {
|
|
18
|
+
const applicableTags = [];
|
|
19
|
+
const tagKeys = Object.keys(sdkTags);
|
|
20
|
+
const currentEpochSeconds = Math.round(new Date().getTime() / 1000);
|
|
21
|
+
Logger.logDbg('Total Tag Length: ', tagKeys.length);
|
|
22
|
+
|
|
23
|
+
for (const tagId of tagKeys) {
|
|
24
|
+
const tag = sdkTags[tagId];
|
|
25
|
+
|
|
26
|
+
if (tag) {
|
|
27
|
+
let isQualified = true;
|
|
28
|
+
|
|
29
|
+
for (const qc of tag.qc) {
|
|
30
|
+
if (validQcList.indexOf(qc) === -1) {
|
|
31
|
+
var _sdkProviders$tag$p;
|
|
32
|
+
|
|
33
|
+
isQualified = false;
|
|
34
|
+
allTagInfo.push({
|
|
35
|
+
id: tagId,
|
|
36
|
+
nm: tag.nm,
|
|
37
|
+
status: false,
|
|
38
|
+
qc,
|
|
39
|
+
pr: tag.p,
|
|
40
|
+
prNm: ((_sdkProviders$tag$p = sdkProviders[tag.p]) === null || _sdkProviders$tag$p === void 0 ? void 0 : _sdkProviders$tag$p.nm) || ''
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (isQualified && applicableTags.indexOf(tagId) === -1) {
|
|
47
|
+
if (this.checkTagDateValidity(currentEpochSeconds, tag.st, tag.ex)) {
|
|
48
|
+
var _sdkProviders$tag$p2, _sdkProviders$tag$p3;
|
|
49
|
+
|
|
50
|
+
applicableTags.push(tagId);
|
|
51
|
+
allTagInfo.push({
|
|
52
|
+
id: tagId,
|
|
53
|
+
nm: tag.nm,
|
|
54
|
+
status: true,
|
|
55
|
+
qc: tag.qc,
|
|
56
|
+
pr: tag.p,
|
|
57
|
+
prNm: ((_sdkProviders$tag$p2 = sdkProviders[tag.p]) === null || _sdkProviders$tag$p2 === void 0 ? void 0 : _sdkProviders$tag$p2.nm) || ''
|
|
58
|
+
});
|
|
59
|
+
applicableTagInfo.push({
|
|
60
|
+
id: tagId,
|
|
61
|
+
nm: tag.nm,
|
|
62
|
+
status: true,
|
|
63
|
+
qc: tag.qc,
|
|
64
|
+
pr: tag.p,
|
|
65
|
+
prNm: ((_sdkProviders$tag$p3 = sdkProviders[tag.p]) === null || _sdkProviders$tag$p3 === void 0 ? void 0 : _sdkProviders$tag$p3.nm) || ''
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
var _sdkProviders$tag$p4;
|
|
69
|
+
|
|
70
|
+
allTagInfo.push({
|
|
71
|
+
id: tagId,
|
|
72
|
+
nm: tag.nm,
|
|
73
|
+
status: false,
|
|
74
|
+
qc: tag.qc,
|
|
75
|
+
pr: tag.p,
|
|
76
|
+
prNm: ((_sdkProviders$tag$p4 = sdkProviders[tag.p]) === null || _sdkProviders$tag$p4 === void 0 ? void 0 : _sdkProviders$tag$p4.nm) || ''
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Core function which actually puts the tag on page based on the tag type (JS or Image)
|
|
85
|
+
* @param eventName
|
|
86
|
+
* @param evtId
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
static async processTags(eventName, evtId) {
|
|
91
|
+
try {
|
|
92
|
+
Logger.logDbg('Processing tags for event: ', eventName, ' with id: ', evtId);
|
|
93
|
+
const allTagInfo = [];
|
|
94
|
+
const applicableTagInfo = [];
|
|
95
|
+
const prStatus = DataStore.getPrivacyCompliance();
|
|
96
|
+
const dataElements = DataStore.getDataElements();
|
|
97
|
+
const transFunctions = DataStore.getTransFunctions();
|
|
98
|
+
const sdkTags = DataStore.getSdkTags();
|
|
99
|
+
const sdkProviders = DataStore.getSdkProviders();
|
|
100
|
+
const validQcList = DataStore.getValidQcList(); // Find applicable tags
|
|
101
|
+
|
|
102
|
+
this.findApplicableTags(sdkTags, sdkProviders, validQcList, allTagInfo, applicableTagInfo); // set expected tag count, so that the reporter knows when all tags are finished and can report asynchronously
|
|
103
|
+
|
|
104
|
+
Reporter.setExpectedTagCount(applicableTagInfo.length, evtId);
|
|
105
|
+
Logger.logDbg('Applicable Tags: ', applicableTagInfo); // process tags one by one
|
|
106
|
+
|
|
107
|
+
for (const tagInfo of applicableTagInfo) {
|
|
108
|
+
try {
|
|
109
|
+
Logger.logDbg(`Processing Tag: ${tagInfo.nm} [${tagInfo.id}]`);
|
|
110
|
+
const tag = sdkTags[tagInfo.id];
|
|
111
|
+
|
|
112
|
+
if (!tag) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const provider = sdkProviders[tag.p];
|
|
117
|
+
|
|
118
|
+
if (!provider) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const result = this.hydrateTag(tagInfo, tag, provider, prStatus, dataElements, transFunctions);
|
|
123
|
+
|
|
124
|
+
if (result.isInError) {
|
|
125
|
+
Logger.logDbg(`Tag ${tagInfo.nm} not processed because of error code: ${result.errCd}`);
|
|
126
|
+
|
|
127
|
+
if (result.errCd === 'NP') {
|
|
128
|
+
Reporter.reportItem({
|
|
129
|
+
st: Constants.ST_PR_EXC,
|
|
130
|
+
t: tagInfo.id,
|
|
131
|
+
p: tagInfo.pr,
|
|
132
|
+
tNm: tagInfo.nm,
|
|
133
|
+
req: result.errMsg
|
|
134
|
+
}, evtId);
|
|
135
|
+
} else if (result.errCd === 'PRB') {
|
|
136
|
+
Reporter.reportItem({
|
|
137
|
+
st: Constants.ST_PR_BL,
|
|
138
|
+
t: tagInfo.id,
|
|
139
|
+
p: tagInfo.pr,
|
|
140
|
+
tNm: tagInfo.nm,
|
|
141
|
+
req: result.errMsg
|
|
142
|
+
}, evtId);
|
|
143
|
+
} else if (result.errCd === 'REF') {
|
|
144
|
+
Reporter.reportItem({
|
|
145
|
+
st: Constants.ST_VAL_FAIL,
|
|
146
|
+
t: tagInfo.id,
|
|
147
|
+
p: tagInfo.pr,
|
|
148
|
+
tNm: tagInfo.nm,
|
|
149
|
+
req: result.errMsg
|
|
150
|
+
}, evtId);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const finalUrl = result.content;
|
|
157
|
+
Logger.logDbg('Final Url :: ', finalUrl);
|
|
158
|
+
|
|
159
|
+
if (provider.typ === Constants.PR_TYP_APP) {
|
|
160
|
+
if (provider.sTyp === Constants.PR_S_TYP_R) {
|
|
161
|
+
// process and fire app event
|
|
162
|
+
try {
|
|
163
|
+
const parsedData = JSON.parse(result.content);
|
|
164
|
+
Utils.triggerEvent(parsedData.event_bus_name, parsedData.event_bus_payload);
|
|
165
|
+
Reporter.reportItem({
|
|
166
|
+
st: Constants.ST_OK,
|
|
167
|
+
t: tagInfo.id,
|
|
168
|
+
p: tagInfo.pr,
|
|
169
|
+
tNm: tagInfo.nm,
|
|
170
|
+
req: parsedData
|
|
171
|
+
}, evtId);
|
|
172
|
+
} catch (err) {
|
|
173
|
+
Logger.logError(err);
|
|
174
|
+
Reporter.reportItem({
|
|
175
|
+
st: Constants.ST_ERR,
|
|
176
|
+
t: tagInfo.id,
|
|
177
|
+
p: tagInfo.pr,
|
|
178
|
+
tNm: tagInfo.nm,
|
|
179
|
+
req: result.content
|
|
180
|
+
}, evtId);
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
Logger.logError('Unsupported provider type: ' + provider.sTyp);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
Logger.logError('Failed loading tag: ', tagInfo.id, ': Name: ', tagInfo.nm, 'with error ', err);
|
|
188
|
+
Reporter.reportItem({
|
|
189
|
+
st: Constants.ST_ERR,
|
|
190
|
+
t: tagInfo.id,
|
|
191
|
+
p: tagInfo.pr,
|
|
192
|
+
tNm: tagInfo.nm,
|
|
193
|
+
req: err === null || err === void 0 ? void 0 : err.stack
|
|
194
|
+
}, evtId);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
} catch (err) {
|
|
198
|
+
Logger.logError('Error processing tags: ', err); // TODO: Report as metric to client
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Takes all the placeholders in a tag and replaces them with actual values from data elements or
|
|
203
|
+
* actual static values. Method returns an object with errCd and replaced content and a boolean identifier
|
|
204
|
+
* to denote if this process failed or not
|
|
205
|
+
* @param tagInfo
|
|
206
|
+
* @param tag
|
|
207
|
+
* @param provider
|
|
208
|
+
* @param prStatus
|
|
209
|
+
* @param dataElements
|
|
210
|
+
* @param transFunctions
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
static hydrateTag(tagInfo, tag, provider, prStatus, dataElements, transFunctions) {
|
|
215
|
+
Logger.logDbg(`Hydrating Tag: ${tagInfo.nm} [${tagInfo.id}]`);
|
|
216
|
+
|
|
217
|
+
if (!provider) {
|
|
218
|
+
// serious issue. tag is in build sdk but not the appropriate provider
|
|
219
|
+
Logger.logError(`Not hydrating tag: ${tagInfo.nm} [${tagInfo.id}] because appropriate provider was not found`);
|
|
220
|
+
return {
|
|
221
|
+
isInError: true,
|
|
222
|
+
content: null,
|
|
223
|
+
errCd: 'NP',
|
|
224
|
+
errMsg: `Not hydrating tag: ${tagInfo.nm} [${tagInfo.id}] because appropriate provider was not found`
|
|
225
|
+
}; // No Provider
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (provider.pr === 'B' && !prStatus) {
|
|
229
|
+
Logger.logDbg(`Not hydrating provider: ${provider.nm} [${tag.p}] because it is blacklisted`);
|
|
230
|
+
return {
|
|
231
|
+
isInError: true,
|
|
232
|
+
content: null,
|
|
233
|
+
errCd: 'PRB',
|
|
234
|
+
errMsg: `Not hydrating provider: ${provider.nm} [${tag.p}] because it is blacklisted`
|
|
235
|
+
}; // Privacy Blocked
|
|
236
|
+
} // merge both provider and client tag params into one - tag param overwrites provider params
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
const params = Utils.mergeMaps(undefined, provider.rParams, tag.rParams);
|
|
240
|
+
|
|
241
|
+
if (provider.typ === 'app' && provider.sTyp === 'r') {
|
|
242
|
+
// this is o app type provider. no need to find place-holders, just convert params to an object and prepare the json object
|
|
243
|
+
return this.resourceParamsToActualValues(Object.values(params), dataElements, transFunctions);
|
|
244
|
+
} else {
|
|
245
|
+
// make tag url
|
|
246
|
+
const preReplaceUrl = provider.url + (tag.url ? tag.url : '');
|
|
247
|
+
const finalUrl = provider.url + (tag.url ? tag.url : ''); // find placeholder values
|
|
248
|
+
|
|
249
|
+
const placeHolders = this.findPlaceHolders(preReplaceUrl); // process tag attributes
|
|
250
|
+
|
|
251
|
+
return this.replacePlaceHolders(finalUrl, placeHolders, dataElements, transFunctions, params, provider.chld || tag.chld, 'rph');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
static findPlaceHolders(content) {
|
|
256
|
+
const placeHolders = [];
|
|
257
|
+
let match = Constants.PLACEHOLDER_REGEX.exec(content);
|
|
258
|
+
|
|
259
|
+
while (match !== null) {
|
|
260
|
+
placeHolders.push(match[2]);
|
|
261
|
+
match = Constants.PLACEHOLDER_REGEX.exec(content);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return placeHolders;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
static resourceParamsToActualValues(params, deItems, transFunctions) {
|
|
268
|
+
// resolve all param values and convert them into a temporary structure
|
|
269
|
+
const paramValueArray = {};
|
|
270
|
+
|
|
271
|
+
for (const param of params) {
|
|
272
|
+
if (param.val_src !== 'CHILDREN') {
|
|
273
|
+
const deVal = this.parseParamValue(param, deItems, transFunctions);
|
|
274
|
+
|
|
275
|
+
if (param.rqd && typeof deVal === 'undefined') {
|
|
276
|
+
return {
|
|
277
|
+
isInError: true,
|
|
278
|
+
content: '',
|
|
279
|
+
errCd: 'REF',
|
|
280
|
+
errMsg: `Tag validation failed. Parameter ${param.nm} is marked as mandatory, but no value was found in source.`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
paramValueArray[param.fKey] = deVal;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const op = Utils.unflattenObject(paramValueArray);
|
|
289
|
+
return {
|
|
290
|
+
isInError: false,
|
|
291
|
+
content: JSON.stringify(op),
|
|
292
|
+
errCd: null,
|
|
293
|
+
errMsg: null
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static parseParamValue(paramItem, deItems, transFunctions) {
|
|
298
|
+
let paramValue = undefined;
|
|
299
|
+
|
|
300
|
+
if (paramItem.sv || paramItem.de || paramItem.tfId) {
|
|
301
|
+
if (paramItem.sv) {
|
|
302
|
+
paramValue = paramItem.sv;
|
|
303
|
+
} else if (paramItem.de) {
|
|
304
|
+
paramValue = deItems[paramItem.de];
|
|
305
|
+
} else if (paramItem.tfId) {
|
|
306
|
+
paramValue = transFunctions[paramItem.tfId];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
paramValue = Utils.applyTransformationResourceParam(paramValue, paramItem.tf);
|
|
310
|
+
return paramValue;
|
|
311
|
+
} else {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
static replacePlaceHolders(content, placeHolders, deItems, transFunctions, params, hasChildren, replaceMode) {
|
|
317
|
+
let isInError = false;
|
|
318
|
+
let errMsg;
|
|
319
|
+
|
|
320
|
+
if (!params) {
|
|
321
|
+
return {
|
|
322
|
+
isInError: false,
|
|
323
|
+
content,
|
|
324
|
+
errCd: null,
|
|
325
|
+
errMsg: 'No parameters where found to process in this tag'
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (hasChildren) {
|
|
330
|
+
// convert the flattened parameters to parent - child format. this is inside a condition
|
|
331
|
+
// because we may not have a lot of JSON type parameters and we can save some processing time by limiting
|
|
332
|
+
// when this is done
|
|
333
|
+
params = Utils.unFlattenResourceParams(Object.values(params));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
for (const ph of placeHolders) {
|
|
337
|
+
try {
|
|
338
|
+
const tagParam = params[ph];
|
|
339
|
+
|
|
340
|
+
if (tagParam) {
|
|
341
|
+
if (tagParam.children && tagParam.children.length > 0) {
|
|
342
|
+
const paramValue = {};
|
|
343
|
+
|
|
344
|
+
for (const childParam of tagParam.children) {
|
|
345
|
+
paramValue[childParam.nm] = this.parseParamValue(childParam, deItems, transFunctions);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
content = this.replaceValues(ph, content, JSON.stringify(paramValue), replaceMode);
|
|
349
|
+
} else {
|
|
350
|
+
const paramValue = this.parseParamValue(tagParam, deItems, transFunctions);
|
|
351
|
+
|
|
352
|
+
if (typeof paramValue === 'object') {
|
|
353
|
+
content = this.replaceValues(ph, content, JSON.stringify(paramValue), replaceMode);
|
|
354
|
+
} else {
|
|
355
|
+
content = this.replaceValues(ph, content, paramValue, replaceMode);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
// TODO: Report
|
|
360
|
+
// place holder was found but the corresponding item was not found in tag resource params
|
|
361
|
+
Logger.logDbg('place holder:', ph, ', was found but the corresponding item was not found in tag resource params');
|
|
362
|
+
}
|
|
363
|
+
} catch (err) {
|
|
364
|
+
isInError = true;
|
|
365
|
+
errMsg = err === null || err === void 0 ? void 0 : err.stack;
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return {
|
|
371
|
+
isInError,
|
|
372
|
+
content,
|
|
373
|
+
errCd: isInError ? 'REF' : null,
|
|
374
|
+
errMsg: errMsg
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
static checkTagDateValidity(currentEpochSeconds, tagStart, tagEnd) {
|
|
379
|
+
return currentEpochSeconds >= tagStart && currentEpochSeconds <= tagEnd;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
static replaceValues(placeHolder, content, val, replaceMode) {
|
|
383
|
+
let replaceVal;
|
|
384
|
+
|
|
385
|
+
if (replaceMode === 'kph') {
|
|
386
|
+
replaceVal = val && val !== '' ? val : `{{${placeHolder}}`;
|
|
387
|
+
} else if (replaceMode === 'rph') {
|
|
388
|
+
replaceVal = val && val !== '' ? val : '';
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
content = content.split(`{{${placeHolder}}}`).join(replaceVal);
|
|
392
|
+
return content;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
}
|
|
396
|
+
//# sourceMappingURL=tag.processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Logger","DataStore","Reporter","Constants","Utils","TagProcessor","findApplicableTags","sdkTags","sdkProviders","validQcList","allTagInfo","applicableTagInfo","applicableTags","tagKeys","Object","keys","currentEpochSeconds","Math","round","Date","getTime","logDbg","length","tagId","tag","isQualified","qc","indexOf","push","id","nm","status","pr","p","prNm","checkTagDateValidity","st","ex","processTags","eventName","evtId","prStatus","getPrivacyCompliance","dataElements","getDataElements","transFunctions","getTransFunctions","getSdkTags","getSdkProviders","getValidQcList","setExpectedTagCount","tagInfo","provider","result","hydrateTag","isInError","errCd","reportItem","ST_PR_EXC","t","tNm","req","errMsg","ST_PR_BL","ST_VAL_FAIL","finalUrl","content","typ","PR_TYP_APP","sTyp","PR_S_TYP_R","parsedData","JSON","parse","triggerEvent","event_bus_name","event_bus_payload","ST_OK","err","logError","ST_ERR","stack","params","mergeMaps","undefined","rParams","resourceParamsToActualValues","values","preReplaceUrl","url","placeHolders","findPlaceHolders","replacePlaceHolders","chld","match","PLACEHOLDER_REGEX","exec","deItems","paramValueArray","param","val_src","deVal","parseParamValue","rqd","fKey","op","unflattenObject","stringify","paramItem","paramValue","sv","de","tfId","applyTransformationResourceParam","tf","hasChildren","replaceMode","unFlattenResourceParams","ph","tagParam","children","childParam","replaceValues","tagStart","tagEnd","placeHolder","val","replaceVal","split","join"],"sources":["tag.processor.ts"],"sourcesContent":["/**\n * Finds all the applicable tags based on the true qualification criteria. Method does not return anything\n * because it uses pass by memory reference. The last 2 paramters (allTagInfo and applicableTagInfo) are\n * return variables\n * @param sdkTags\n * @param sdkProviders\n * @param validQcList\n * @param allTagInfo\n * @param applicableTagInfo\n */\nimport type {\n HydrateTagInfo,\n MapLike,\n ReplaceMode,\n TagInfoItem,\n} from '../common/app-types';\nimport type {\n ClientSdkParamItem,\n ClientSdkPrItem,\n ClientSdkTagItem,\n} from '../models/mp-client-sdk';\nimport { Logger } from '../common/logger';\nimport { DataStore } from '../common/data-store';\nimport { Reporter } from '../common/reporter';\nimport { Constants } from '../common/constants';\nimport { Utils } from '../common/utils';\n\nexport class TagProcessor {\n private static findApplicableTags(\n sdkTags: MapLike<ClientSdkTagItem>,\n sdkProviders: MapLike<ClientSdkPrItem>,\n validQcList: string[],\n allTagInfo: TagInfoItem[],\n applicableTagInfo: TagInfoItem[]\n ): void {\n const applicableTags: string[] = [];\n const tagKeys = Object.keys(sdkTags);\n const currentEpochSeconds = Math.round(new Date().getTime() / 1000);\n Logger.logDbg('Total Tag Length: ', tagKeys.length);\n for (const tagId of tagKeys) {\n const tag: ClientSdkTagItem | undefined = sdkTags[tagId];\n if (tag) {\n let isQualified = true;\n for (const qc of tag.qc) {\n if (validQcList.indexOf(qc) === -1) {\n isQualified = false;\n allTagInfo.push({\n id: tagId,\n nm: tag.nm,\n status: false,\n qc,\n pr: tag.p,\n prNm: sdkProviders[tag.p]?.nm || '',\n });\n break;\n }\n }\n if (isQualified && applicableTags.indexOf(tagId) === -1) {\n if (this.checkTagDateValidity(currentEpochSeconds, tag.st, tag.ex)) {\n applicableTags.push(tagId);\n allTagInfo.push({\n id: tagId,\n nm: tag.nm,\n status: true,\n qc: tag.qc,\n pr: tag.p,\n prNm: sdkProviders[tag.p]?.nm || '',\n });\n applicableTagInfo.push({\n id: tagId,\n nm: tag.nm,\n status: true,\n qc: tag.qc,\n pr: tag.p,\n prNm: sdkProviders[tag.p]?.nm || '',\n });\n } else {\n allTagInfo.push({\n id: tagId,\n nm: tag.nm,\n status: false,\n qc: tag.qc,\n pr: tag.p,\n prNm: sdkProviders[tag.p]?.nm || '',\n });\n }\n }\n }\n }\n }\n\n /**\n * Core function which actually puts the tag on page based on the tag type (JS or Image)\n * @param eventName\n * @param evtId\n */\n static async processTags(eventName: string, evtId: string): Promise<void> {\n try {\n Logger.logDbg(\n 'Processing tags for event: ',\n eventName,\n ' with id: ',\n evtId\n );\n const allTagInfo: Array<TagInfoItem> = [];\n const applicableTagInfo: Array<TagInfoItem> = [];\n const prStatus = DataStore.getPrivacyCompliance();\n const dataElements = DataStore.getDataElements();\n const transFunctions = DataStore.getTransFunctions();\n const sdkTags = DataStore.getSdkTags();\n const sdkProviders = DataStore.getSdkProviders();\n const validQcList = DataStore.getValidQcList();\n\n // Find applicable tags\n this.findApplicableTags(\n sdkTags,\n sdkProviders,\n validQcList,\n allTagInfo,\n applicableTagInfo\n );\n\n // set expected tag count, so that the reporter knows when all tags are finished and can report asynchronously\n Reporter.setExpectedTagCount(applicableTagInfo.length, evtId);\n\n Logger.logDbg('Applicable Tags: ', applicableTagInfo);\n\n // process tags one by one\n for (const tagInfo of applicableTagInfo) {\n try {\n Logger.logDbg(`Processing Tag: ${tagInfo.nm} [${tagInfo.id}]`);\n\n const tag: ClientSdkTagItem | undefined = sdkTags[tagInfo.id];\n\n if (!tag) {\n continue;\n }\n\n const provider: ClientSdkPrItem | undefined = sdkProviders[tag.p];\n\n if (!provider) {\n continue;\n }\n\n const result = this.hydrateTag(\n tagInfo,\n tag,\n provider,\n prStatus,\n dataElements,\n transFunctions\n );\n\n if (result.isInError) {\n Logger.logDbg(\n `Tag ${tagInfo.nm} not processed because of error code: ${result.errCd}`\n );\n if (result.errCd === 'NP') {\n Reporter.reportItem(\n {\n st: Constants.ST_PR_EXC,\n t: tagInfo.id,\n p: tagInfo.pr,\n tNm: tagInfo.nm,\n req: result.errMsg,\n },\n evtId\n );\n } else if (result.errCd === 'PRB') {\n Reporter.reportItem(\n {\n st: Constants.ST_PR_BL,\n t: tagInfo.id,\n p: tagInfo.pr,\n tNm: tagInfo.nm,\n req: result.errMsg,\n },\n evtId\n );\n } else if (result.errCd === 'REF') {\n Reporter.reportItem(\n {\n st: Constants.ST_VAL_FAIL,\n t: tagInfo.id,\n p: tagInfo.pr,\n tNm: tagInfo.nm,\n req: result.errMsg,\n },\n evtId\n );\n }\n continue;\n }\n\n const finalUrl = result.content;\n Logger.logDbg('Final Url :: ', finalUrl);\n\n if (provider.typ === Constants.PR_TYP_APP) {\n if (provider.sTyp === Constants.PR_S_TYP_R) {\n // process and fire app event\n try {\n const parsedData = JSON.parse(result.content as string);\n Utils.triggerEvent(\n parsedData.event_bus_name,\n parsedData.event_bus_payload\n );\n Reporter.reportItem(\n {\n st: Constants.ST_OK,\n t: tagInfo.id,\n p: tagInfo.pr,\n tNm: tagInfo.nm,\n req: parsedData,\n },\n evtId\n );\n } catch (err) {\n Logger.logError(err);\n Reporter.reportItem(\n {\n st: Constants.ST_ERR,\n t: tagInfo.id,\n p: tagInfo.pr,\n tNm: tagInfo.nm,\n req: result.content,\n },\n evtId\n );\n }\n } else {\n Logger.logError('Unsupported provider type: ' + provider.sTyp);\n }\n }\n } catch (err) {\n Logger.logError(\n 'Failed loading tag: ',\n tagInfo.id,\n ': Name: ',\n tagInfo.nm,\n 'with error ',\n err\n );\n Reporter.reportItem(\n {\n st: Constants.ST_ERR,\n t: tagInfo.id,\n p: tagInfo.pr,\n tNm: tagInfo.nm,\n req: (err as any)?.stack,\n },\n evtId\n );\n }\n }\n } catch (err) {\n Logger.logError('Error processing tags: ', err);\n // TODO: Report as metric to client\n }\n }\n\n /**\n * Takes all the placeholders in a tag and replaces them with actual values from data elements or\n * actual static values. Method returns an object with errCd and replaced content and a boolean identifier\n * to denote if this process failed or not\n * @param tagInfo\n * @param tag\n * @param provider\n * @param prStatus\n * @param dataElements\n * @param transFunctions\n */\n private static hydrateTag(\n tagInfo: TagInfoItem,\n tag: ClientSdkTagItem,\n provider: ClientSdkPrItem,\n prStatus: boolean,\n dataElements: MapLike<any>,\n transFunctions: MapLike<any>\n ): HydrateTagInfo {\n Logger.logDbg(`Hydrating Tag: ${tagInfo.nm} [${tagInfo.id}]`);\n if (!provider) {\n // serious issue. tag is in build sdk but not the appropriate provider\n Logger.logError(\n `Not hydrating tag: ${tagInfo.nm} [${tagInfo.id}] because appropriate provider was not found`\n );\n return {\n isInError: true,\n content: null,\n errCd: 'NP',\n errMsg: `Not hydrating tag: ${tagInfo.nm} [${tagInfo.id}] because appropriate provider was not found`,\n }; // No Provider\n }\n\n if (provider.pr === 'B' && !prStatus) {\n Logger.logDbg(\n `Not hydrating provider: ${provider.nm} [${tag.p}] because it is blacklisted`\n );\n return {\n isInError: true,\n content: null,\n errCd: 'PRB',\n errMsg: `Not hydrating provider: ${provider.nm} [${tag.p}] because it is blacklisted`,\n }; // Privacy Blocked\n }\n\n // merge both provider and client tag params into one - tag param overwrites provider params\n const params: MapLike<ClientSdkParamItem | undefined> =\n Utils.mergeMaps<ClientSdkParamItem>(\n undefined,\n provider.rParams,\n tag.rParams\n );\n\n if (provider.typ === 'app' && provider.sTyp === 'r') {\n // this is o app type provider. no need to find place-holders, just convert params to an object and prepare the json object\n return this.resourceParamsToActualValues(\n Object.values(params),\n dataElements,\n transFunctions\n );\n } else {\n // make tag url\n const preReplaceUrl: string = provider.url + (tag.url ? tag.url : '');\n const finalUrl: string = provider.url + (tag.url ? tag.url : '');\n\n // find placeholder values\n const placeHolders: string[] = this.findPlaceHolders(preReplaceUrl);\n // process tag attributes\n return this.replacePlaceHolders(\n finalUrl,\n placeHolders,\n dataElements,\n transFunctions,\n params,\n provider.chld || tag.chld,\n 'rph'\n );\n }\n }\n\n private static findPlaceHolders(content: string): string[] {\n const placeHolders: string[] = [];\n let match = Constants.PLACEHOLDER_REGEX.exec(content);\n while (match !== null) {\n placeHolders.push(match[2]);\n match = Constants.PLACEHOLDER_REGEX.exec(content);\n }\n return placeHolders;\n }\n\n private static resourceParamsToActualValues(\n params: ClientSdkParamItem[],\n deItems: MapLike,\n transFunctions: MapLike\n ): HydrateTagInfo {\n // resolve all param values and convert them into a temporary structure\n const paramValueArray: MapLike = {};\n\n for (const param of params) {\n if (param.val_src !== 'CHILDREN') {\n const deVal = this.parseParamValue(param, deItems, transFunctions);\n\n if (param.rqd && typeof deVal === 'undefined') {\n return {\n isInError: true,\n content: '',\n errCd: 'REF',\n errMsg: `Tag validation failed. Parameter ${param.nm} is marked as mandatory, but no value was found in source.`,\n };\n }\n\n paramValueArray[param.fKey] = deVal;\n }\n }\n\n const op = Utils.unflattenObject(paramValueArray);\n\n return {\n isInError: false,\n content: JSON.stringify(op),\n errCd: null,\n errMsg: null,\n };\n }\n\n private static parseParamValue(\n paramItem: ClientSdkParamItem,\n deItems: MapLike<any>,\n transFunctions: MapLike<any>\n ): any {\n let paramValue = undefined;\n if (paramItem.sv || paramItem.de || paramItem.tfId) {\n if (paramItem.sv) {\n paramValue = paramItem.sv;\n } else if (paramItem.de) {\n paramValue = deItems[paramItem.de];\n } else if (paramItem.tfId) {\n paramValue = transFunctions[paramItem.tfId];\n }\n\n paramValue = Utils.applyTransformationResourceParam(\n paramValue,\n paramItem.tf\n );\n return paramValue;\n } else {\n return undefined;\n }\n }\n\n private static replacePlaceHolders(\n content: string,\n placeHolders: string[],\n deItems: MapLike<any>,\n transFunctions: MapLike<any>,\n params: MapLike<ClientSdkParamItem>,\n hasChildren: boolean,\n replaceMode: ReplaceMode\n ): HydrateTagInfo {\n let isInError = false;\n let errMsg;\n\n if (!params) {\n return {\n isInError: false,\n content,\n errCd: null,\n errMsg: 'No parameters where found to process in this tag',\n };\n }\n\n if (hasChildren) {\n // convert the flattened parameters to parent - child format. this is inside a condition\n // because we may not have a lot of JSON type parameters and we can save some processing time by limiting\n // when this is done\n params = Utils.unFlattenResourceParams(Object.values(params));\n }\n\n for (const ph of placeHolders) {\n try {\n const tagParam: ClientSdkParamItem = params[ph];\n if (tagParam) {\n if (tagParam.children && tagParam.children.length > 0) {\n const paramValue: MapLike<any> = {};\n for (const childParam of tagParam.children) {\n paramValue[childParam.nm] = this.parseParamValue(\n childParam,\n deItems,\n transFunctions\n );\n }\n content = this.replaceValues(\n ph,\n content,\n JSON.stringify(paramValue),\n replaceMode\n );\n } else {\n const paramValue = this.parseParamValue(\n tagParam,\n deItems,\n transFunctions\n );\n if (typeof paramValue === 'object') {\n content = this.replaceValues(\n ph,\n content,\n JSON.stringify(paramValue),\n replaceMode\n );\n } else {\n content = this.replaceValues(\n ph,\n content,\n paramValue,\n replaceMode\n );\n }\n }\n } else {\n // TODO: Report\n // place holder was found but the corresponding item was not found in tag resource params\n Logger.logDbg(\n 'place holder:',\n ph,\n ', was found but the corresponding item was not found in tag resource params'\n );\n }\n } catch (err) {\n isInError = true;\n errMsg = (err as any)?.stack;\n break;\n }\n }\n\n return {\n isInError,\n content,\n errCd: isInError ? 'REF' : null,\n errMsg: errMsg,\n };\n }\n\n private static checkTagDateValidity(\n currentEpochSeconds: number,\n tagStart: number,\n tagEnd: number\n ): boolean {\n return currentEpochSeconds >= tagStart && currentEpochSeconds <= tagEnd;\n }\n\n private static replaceValues(\n placeHolder: string,\n content: string,\n val: any,\n replaceMode: ReplaceMode\n ): string {\n let replaceVal: string;\n if (replaceMode === 'kph') {\n replaceVal = val && val !== '' ? val : `{{${placeHolder}}`;\n } else if (replaceMode === 'rph') {\n replaceVal = val && val !== '' ? val : '';\n }\n content = content.split(`{{${placeHolder}}}`).join(replaceVal);\n return content;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAYA,SAASA,MAAT,QAAuB,kBAAvB;AACA,SAASC,SAAT,QAA0B,sBAA1B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA,OAAO,MAAMC,YAAN,CAAmB;EACS,OA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A2B,KAAID,WAAY,GAAxD;IACD,CAFD,MAEO,IAAIT,WAAW,KAAK,KAApB,EAA2B;MAChCW,UAAU,GAAGD,GAAG,IAAIA,GAAG,KAAK,EAAf,GAAoBA,GAApB,GAA0B,EAAvC;IACD;;IACD5D,OAAO,GAAGA,OAAO,CAAC8D,KAAR,CAAe,KAAIH,WAAY,IAA/B,EAAoCI,IAApC,CAAyCF,UAAzC,CAAV;IACA,OAAO7D,OAAP;EACD;;AAlfuB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process all the data elements at once, or if a set of keys are specified, processes only
|
|
3
|
+
* those keys and updates the dataElements object in global-fns file
|
|
4
|
+
* @param dataElements
|
|
5
|
+
* @param sdkTransFunctions
|
|
6
|
+
* @param optTfnKeys
|
|
7
|
+
*/
|
|
8
|
+
import { DataStore } from '../common/data-store';
|
|
9
|
+
import { Logger } from '../common/logger';
|
|
10
|
+
import { Utils } from '../common/utils';
|
|
11
|
+
import { Reporter } from '../common/reporter';
|
|
12
|
+
export class TransFunctionProcessor {
|
|
13
|
+
static processTransformationFunctions(dataElements, sdkTransFunctions, optTfnKeys) {
|
|
14
|
+
const tfn = DataStore.getTransFunctions();
|
|
15
|
+
const tfnKeys = optTfnKeys && optTfnKeys.length > 0 ? optTfnKeys : Object.keys(sdkTransFunctions);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
for (const key of tfnKeys) {
|
|
19
|
+
try {
|
|
20
|
+
const tfnItem = sdkTransFunctions[key];
|
|
21
|
+
/**
|
|
22
|
+
* How to process transformation functions
|
|
23
|
+
* 1) Find all the data elements in the resource params of trans function
|
|
24
|
+
* 2) make them into an object (key value) where key is the resourceKey and value is the value of data elements
|
|
25
|
+
* 3) Invoke the tfn and get the value and store it against the tfn key
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
if (tfnItem) {
|
|
29
|
+
if (tfnItem.rParams) {
|
|
30
|
+
const tfnFnInput = {};
|
|
31
|
+
|
|
32
|
+
for (const paramKey of Object.keys(tfnItem.rParams)) {
|
|
33
|
+
// tfn can have only data elements as of now.
|
|
34
|
+
const rParam = tfnItem.rParams[paramKey];
|
|
35
|
+
const deId = rParam === null || rParam === void 0 ? void 0 : rParam.de;
|
|
36
|
+
|
|
37
|
+
if (deId) {
|
|
38
|
+
let paramValue = dataElements[deId] || '';
|
|
39
|
+
|
|
40
|
+
if (rParam.rqd && !paramValue) {
|
|
41
|
+
Logger.logDbg(`Value required for: ${paramKey}, in transformation function. But not found`);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (rParam.tf) {
|
|
46
|
+
paramValue = Utils.applyTransformationResourceParam(paramValue, rParam.tf);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
tfnFnInput[paramKey] = paramValue;
|
|
50
|
+
}
|
|
51
|
+
} // invoke the function and get the value
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
tfn[key] = tfnItem.fn(tfnFnInput);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
tfn[key] = '';
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
Logger.logError('Error processing transformation function: ', key, ' with error: ', err); // TODO: Report as metric to client
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
Logger.logError('Error processing transformation functions: ', err);
|
|
65
|
+
Reporter.reportError('m::processTransformationFunctions', err);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
DataStore.setTransFunctions(tfn);
|
|
69
|
+
return tfn;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=trans-function.processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DataStore","Logger","Utils","Reporter","TransFunctionProcessor","processTransformationFunctions","dataElements","sdkTransFunctions","optTfnKeys","tfn","getTransFunctions","tfnKeys","length","Object","keys","key","tfnItem","rParams","tfnFnInput","paramKey","rParam","deId","de","paramValue","rqd","logDbg","tf","applyTransformationResourceParam","fn","err","logError","reportError","setTransFunctions"],"sources":["trans-function.processor.ts"],"sourcesContent":["/**\n * Process all the data elements at once, or if a set of keys are specified, processes only\n * those keys and updates the dataElements object in global-fns file\n * @param dataElements\n * @param sdkTransFunctions\n * @param optTfnKeys\n */\nimport type { MapLike } from '../common/app-types';\nimport type { ClientSdkTfnItem } from '../models/mp-client-sdk';\nimport { DataStore } from '../common/data-store';\nimport { Logger } from '../common/logger';\nimport { Utils } from '../common/utils';\nimport { Reporter } from '../common/reporter';\n\nexport class TransFunctionProcessor {\n static processTransformationFunctions(\n dataElements: MapLike<any>,\n sdkTransFunctions: MapLike<ClientSdkTfnItem>,\n optTfnKeys?: string[]\n ): MapLike<any> {\n const tfn = DataStore.getTransFunctions();\n const tfnKeys =\n optTfnKeys && optTfnKeys.length > 0\n ? optTfnKeys\n : Object.keys(sdkTransFunctions);\n try {\n for (const key of tfnKeys) {\n try {\n const tfnItem = sdkTransFunctions[key];\n /**\n * How to process transformation functions\n * 1) Find all the data elements in the resource params of trans function\n * 2) make them into an object (key value) where key is the resourceKey and value is the value of data elements\n * 3) Invoke the tfn and get the value and store it against the tfn key\n */\n\n if (tfnItem) {\n if (tfnItem.rParams) {\n const tfnFnInput: any = {};\n for (const paramKey of Object.keys(tfnItem.rParams)) {\n // tfn can have only data elements as of now.\n const rParam = tfnItem.rParams[paramKey];\n const deId = rParam?.de;\n if (deId) {\n let paramValue = dataElements[deId] || '';\n if (rParam.rqd && !paramValue) {\n Logger.logDbg(\n `Value required for: ${paramKey}, in transformation function. But not found`\n );\n break;\n }\n if (rParam.tf) {\n paramValue = Utils.applyTransformationResourceParam(\n paramValue,\n rParam.tf\n );\n }\n tfnFnInput[paramKey] = paramValue;\n }\n }\n // invoke the function and get the value\n tfn[key] = tfnItem.fn(tfnFnInput);\n }\n } else {\n tfn[key] = '';\n }\n } catch (err) {\n Logger.logError(\n 'Error processing transformation function: ',\n key,\n ' with error: ',\n err\n );\n // TODO: Report as metric to client\n }\n }\n } catch (err) {\n Logger.logError('Error processing transformation functions: ', err);\n Reporter.reportError('m::processTransformationFunctions', err);\n }\n\n DataStore.setTransFunctions(tfn);\n return tfn;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,SAASA,SAAT,QAA0B,sBAA1B;AACA,SAASC,MAAT,QAAuB,kBAAvB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA,OAAO,MAAMC,sBAAN,CAA6B;EACG,OAA9BC,8BAA8B,CACnCC,YADmC,EAEnCC,iBAFmC,EAGnCC,UAHmC,EAIrB;IACd,MAAMC,GAAG,GAAGT,SAAS,CAACU,iBAAV,EAAZ;IACA,MAAMC,OAAO,GACXH,UAAU,IAAIA,UAAU,CAACI,MAAX,GAAoB,CAAlC,GACIJ,UADJ,GAEIK,MAAM,CAACC,IAAP,CAAYP,iBAAZ,CAHN;;IAIA,IAAI;MACF,KAAK,MAAMQ,GAAX,IAAkBJ,OAAlB,EAA2B;QACzB,IAAI;UACF,MAAMK,OAAO,GAAGT,iBAAiB,CAACQ,GAAD,CAAjC;UACA;AACV;AACA;AACA;AACA;AACA;;UAEU,IAAIC,OAAJ,EAAa;YACX,IAAIA,OAAO,CAACC,OAAZ,EAAqB;cACnB,MAAMC,UAAe,GAAG,EAAxB;;cACA,KAAK,MAAMC,QAAX,IAAuBN,MAAM,CAACC,IAAP,CAAYE,OAAO,CAACC,OAApB,CAAvB,EAAqD;gBACnD;gBACA,MAAMG,MAAM,GAAGJ,OAAO,CAACC,OAAR,CAAgBE,QAAhB,CAAf;gBACA,MAAME,IAAI,GAAGD,MAAH,aAAGA,MAAH,uBAAGA,MAAM,CAAEE,EAArB;;gBACA,IAAID,IAAJ,EAAU;kBACR,IAAIE,UAAU,GAAGjB,YAAY,CAACe,IAAD,CAAZ,IAAsB,EAAvC;;kBACA,I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