vastlint-client 0.4.20 → 0.4.21
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/resolved.js +22 -43
- package/dist/tracking.js +22 -1
- package/package.json +2 -2
package/dist/resolved.js
CHANGED
|
@@ -20,8 +20,29 @@ function decodeXmlEntities(value) {
|
|
|
20
20
|
return `&${entity};`;
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
function stripCdataSections(value) {
|
|
24
|
+
let output = "";
|
|
25
|
+
let cursor = 0;
|
|
26
|
+
while (cursor < value.length) {
|
|
27
|
+
const start = value.indexOf("<![CDATA[", cursor);
|
|
28
|
+
if (start === -1) {
|
|
29
|
+
output += value.slice(cursor);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
output += value.slice(cursor, start);
|
|
33
|
+
const contentStart = start + "<![CDATA[".length;
|
|
34
|
+
const end = value.indexOf("]]>", contentStart);
|
|
35
|
+
if (end === -1) {
|
|
36
|
+
output += value.slice(start);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
output += value.slice(contentStart, end);
|
|
40
|
+
cursor = end + 3;
|
|
41
|
+
}
|
|
42
|
+
return output;
|
|
43
|
+
}
|
|
23
44
|
function cleanXmlText(value) {
|
|
24
|
-
const withoutCdata = value
|
|
45
|
+
const withoutCdata = stripCdataSections(value);
|
|
25
46
|
return decodeXmlEntities(withoutCdata).trim();
|
|
26
47
|
}
|
|
27
48
|
function extractAttribute(rawAttributes, attributeName) {
|
|
@@ -56,16 +77,6 @@ function cloneMediaFiles(mediaFiles) {
|
|
|
56
77
|
function uniqueValues(values) {
|
|
57
78
|
return [...new Set(values.filter((value) => value.length > 0))];
|
|
58
79
|
}
|
|
59
|
-
function mergeTrackingEventMaps(...eventMaps) {
|
|
60
|
-
const grouped = {};
|
|
61
|
-
for (const eventMap of eventMaps) {
|
|
62
|
-
for (const [event, urls] of Object.entries(eventMap)) {
|
|
63
|
-
grouped[event] ??= [];
|
|
64
|
-
grouped[event].push(...urls);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return Object.fromEntries(Object.entries(grouped).map(([event, urls]) => [event, uniqueValues(urls)]));
|
|
68
|
-
}
|
|
69
80
|
function collectTagTexts(xml, tagName) {
|
|
70
81
|
const values = [];
|
|
71
82
|
const pattern = new RegExp(`<${tagName}\\b[^>]*>([\\s\\S]*?)<\\/${tagName}>`, "gi");
|
|
@@ -127,38 +138,6 @@ function extractMediaFiles(xml) {
|
|
|
127
138
|
}
|
|
128
139
|
return mediaFiles;
|
|
129
140
|
}
|
|
130
|
-
function extractTrackingSurface(xml) {
|
|
131
|
-
const trackingEvents = collectTrackingEventMap(xml);
|
|
132
|
-
const viewable = collectTagTexts(xml, "Viewable");
|
|
133
|
-
const notViewable = collectTagTexts(xml, "NotViewable");
|
|
134
|
-
const viewUndetermined = collectTagTexts(xml, "ViewUndetermined");
|
|
135
|
-
return {
|
|
136
|
-
impressionUrls: uniqueValues(collectTagTexts(xml, "Impression")),
|
|
137
|
-
errorUrls: uniqueValues(collectTagTexts(xml, "Error")),
|
|
138
|
-
clickTrackingUrls: uniqueValues([
|
|
139
|
-
...collectTagTexts(xml, "ClickTracking"),
|
|
140
|
-
...collectTagTexts(xml, "CompanionClickTracking"),
|
|
141
|
-
...collectTagTexts(xml, "IconClickTracking"),
|
|
142
|
-
...collectTagTexts(xml, "NonLinearClickTracking"),
|
|
143
|
-
]),
|
|
144
|
-
clickThroughUrls: uniqueValues([
|
|
145
|
-
...collectTagTexts(xml, "ClickThrough"),
|
|
146
|
-
...collectTagTexts(xml, "CompanionClickThrough"),
|
|
147
|
-
...collectTagTexts(xml, "IconClickThrough"),
|
|
148
|
-
...collectTagTexts(xml, "NonLinearClickThrough"),
|
|
149
|
-
]),
|
|
150
|
-
trackingEvents: mergeTrackingEventMaps(trackingEvents, viewable.length ? { viewable } : {}, notViewable.length ? { notViewable } : {}, viewUndetermined.length ? { viewUndetermined } : {}),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function mergeTrackingSurfaces(...surfaces) {
|
|
154
|
-
return {
|
|
155
|
-
impressionUrls: uniqueValues(surfaces.flatMap((surface) => surface.impressionUrls)),
|
|
156
|
-
errorUrls: uniqueValues(surfaces.flatMap((surface) => surface.errorUrls)),
|
|
157
|
-
clickTrackingUrls: uniqueValues(surfaces.flatMap((surface) => surface.clickTrackingUrls)),
|
|
158
|
-
clickThroughUrls: uniqueValues(surfaces.flatMap((surface) => surface.clickThroughUrls)),
|
|
159
|
-
trackingEvents: mergeTrackingEventMaps(...surfaces.map((surface) => surface.trackingEvents)),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
141
|
function extractAdType(xml) {
|
|
163
142
|
if (/<Wrapper\b/i.test(xml)) {
|
|
164
143
|
return "Wrapper";
|
package/dist/tracking.js
CHANGED
|
@@ -48,8 +48,29 @@ function decodeXmlEntities(value) {
|
|
|
48
48
|
return `&${entity};`;
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
+
function stripCdataSections(value) {
|
|
52
|
+
let output = "";
|
|
53
|
+
let cursor = 0;
|
|
54
|
+
while (cursor < value.length) {
|
|
55
|
+
const start = value.indexOf("<![CDATA[", cursor);
|
|
56
|
+
if (start === -1) {
|
|
57
|
+
output += value.slice(cursor);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
output += value.slice(cursor, start);
|
|
61
|
+
const contentStart = start + "<![CDATA[".length;
|
|
62
|
+
const end = value.indexOf("]]>", contentStart);
|
|
63
|
+
if (end === -1) {
|
|
64
|
+
output += value.slice(start);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
output += value.slice(contentStart, end);
|
|
68
|
+
cursor = end + 3;
|
|
69
|
+
}
|
|
70
|
+
return output;
|
|
71
|
+
}
|
|
51
72
|
function cleanXmlText(value, collapseWhitespace = false) {
|
|
52
|
-
const withoutCdata = value
|
|
73
|
+
const withoutCdata = stripCdataSections(value);
|
|
53
74
|
const decoded = decodeXmlEntities(withoutCdata);
|
|
54
75
|
return collapseWhitespace ? normalizeWhitespace(decoded) : decoded.trim();
|
|
55
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vastlint-client",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.21",
|
|
4
4
|
"description": "Headless VAST session/runtime package built on top of vastlint.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Alex Sekowski <alex@vastlint.org>",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"vastlint": "^0.4.
|
|
52
|
+
"vastlint": "^0.4.21"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"typescript": "^5.9.3"
|