import { DataStore } from '../common/data-store'; import { Logger } from '../common/logger'; import { Utils } from '../common/utils'; import type { ClientSdkQcItem } from '../models/mp-client-sdk'; import { Constants } from '../common/constants'; import { Reporter } from '../common/reporter'; export class QcProcessor { static processQc( sdkQc: ClientSdkQcItem[], eventName: string, evtId: string ): string[] { const validQcList: string[] = []; const validQcInfo: Array<{ nm: string; id: string; st: boolean }> = []; try { Logger.logDbg('Processing qc lists for eventId:: ', evtId); for (const qc of sdkQc) { let notMatching = true; Logger.logDbg('Processing QC: ', qc.nm); for (const qcCondition of qc.c) { let deVal: string | number | boolean; if ( qcCondition.param === Constants.CUST_EVT || qcCondition.param === Constants.MP_DL_EVT ) { if (!eventName) { // this qc has an event condition but no eventName was supplied. so it is not going to match notMatching = true; break; } else { deVal = eventName; } } else { deVal = DataStore.getDataElementValue(qcCondition.param); } if (typeof deVal === 'undefined' || deVal === null || deVal === '') { Logger.logDbg( 'DE ', qcCondition.param, 'was used, but has no value. QC will not qualify' ); notMatching = true; continue; } // check exclude conditions first if (qcCondition.e && qcCondition.e.length > 0) { if ( Utils.isMatch( deVal.toString(), qcCondition.e, !qcCondition.e_cs, qcCondition.e_ect ) ) { Logger.logDbg( 'QC:Exc: ', qcCondition.param, ' did not qualify. QC: ', qc.nm ); notMatching = true; continue; } else { notMatching = false; } } if (qcCondition.i && qcCondition.i.length > 0) { if ( !Utils.isMatch( deVal.toString(), qcCondition.i, !qcCondition.i_cs, qcCondition.i_ect ) ) { Logger.logDbg( 'QC:Inc: ', qcCondition.param, ' did not qualify. QC: ', qc.nm ); notMatching = true; break; } else { notMatching = false; } } else { // if there is no qc, auto include notMatching = false; } } if (!notMatching) { validQcList.push(qc.id); validQcInfo.push({ id: qc.id, nm: qc.nm, st: true }); } else { validQcInfo.push({ id: qc.id, nm: qc.nm, st: false }); } } } catch (err) { Logger.logDbg('Error processing qc criteria: ', err); Reporter.reportError('m:processQC', err); } Logger.logDbg('QC Status: ', validQcInfo); DataStore.setValidQc(validQcList, validQcInfo); return validQcList; } }