Skip to content

Commit

Permalink
fix: always parse Ads as array
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunkers committed Feb 5, 2025
1 parent 4826cb1 commit ae93410
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/vast/vastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ export interface AdApiOptions {
setupNotification?: (asset: ManifestAsset) => void;
}

const alwaysArray = ['VAST.Ad'];

const isArray = (
name: string,
jpath: string,
isLeafNode: boolean,

Check warning on line 51 in src/vast/vastApi.ts

View workflow job for this annotation

GitHub Actions / lint

'isLeafNode' is defined but never used
isAttribute: boolean

Check warning on line 52 in src/vast/vastApi.ts

View workflow job for this annotation

GitHub Actions / lint

'isAttribute' is defined but never used
): boolean => {
return alwaysArray.includes(jpath);
};

export const vastApi: FastifyPluginCallback<AdApiOptions> = (
fastify,
opts,
Expand Down Expand Up @@ -276,7 +287,7 @@ const getCreatives = async (vastXml: any): Promise<ManifestAsset[]> => {

const replaceMediaFiles = (vastXml: string, assets: ManifestAsset[]) => {
try {
const parser = new XMLParser({ ignoreAttributes: false });
const parser = new XMLParser({ ignoreAttributes: false, isArray: isArray });
const parsedVAST = parser.parse(vastXml);
if (parsedVAST.VAST.Ad) {
parsedVAST.VAST.Ad = parsedVAST.VAST.Ad.reduce((acc: any[], ad: any) => {
Expand Down Expand Up @@ -305,7 +316,7 @@ const replaceMediaFiles = (vastXml: string, assets: ManifestAsset[]) => {

const parseVast = (vastXml: string) => {
try {
const parser = new XMLParser({ ignoreAttributes: false });
const parser = new XMLParser({ ignoreAttributes: false, isArray: isArray });
const parsedVAST = parser.parse(vastXml);
return parsedVAST;
} catch (error) {
Expand All @@ -317,7 +328,7 @@ const parseVast = (vastXml: string) => {
const createAssetList = (vastXml: string, assets: ManifestAsset[]) => {
let assetDescriptions = [];
try {
const parser = new XMLParser({ ignoreAttributes: false });
const parser = new XMLParser({ ignoreAttributes: false, isArray: isArray });
const parsedVAST = parser.parse(vastXml);
if (parsedVAST.VAST.Ad) {
assetDescriptions = parsedVAST.VAST.Ad.map((ad: any) => {
Expand Down

0 comments on commit ae93410

Please sign in to comment.