adstxt-validator 1.2.6 → 1.2.7
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/index.js +20 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -601,6 +601,8 @@ async function validateWithOptimizedProvider(publisherDomain, records, provider,
|
|
|
601
601
|
// Batch fetch sellers for all domains
|
|
602
602
|
const domainSellersMap = new Map();
|
|
603
603
|
const domainMetadataMap = new Map();
|
|
604
|
+
// Track which domains actually have sellers.json (separate from whether matching sellers were found)
|
|
605
|
+
const domainHasSellersJsonMap = new Map();
|
|
604
606
|
for (const [domain, sellerIds] of domainToSellerIds) {
|
|
605
607
|
try {
|
|
606
608
|
logger.info(`Fetching ${sellerIds.length} sellers for domain: ${domain}`);
|
|
@@ -610,8 +612,11 @@ async function validateWithOptimizedProvider(publisherDomain, records, provider,
|
|
|
610
612
|
logger.info(`No sellers.json found for domain: ${domain}`);
|
|
611
613
|
domainSellersMap.set(domain, new Map());
|
|
612
614
|
domainMetadataMap.set(domain, {});
|
|
615
|
+
domainHasSellersJsonMap.set(domain, false);
|
|
613
616
|
continue;
|
|
614
617
|
}
|
|
618
|
+
// Domain has sellers.json - record this explicitly before fetching matching sellers
|
|
619
|
+
domainHasSellersJsonMap.set(domain, true);
|
|
615
620
|
// Batch fetch sellers
|
|
616
621
|
const batchResult = await provider.batchGetSellers(domain, sellerIds);
|
|
617
622
|
// Convert to Map for efficient lookup
|
|
@@ -629,6 +634,10 @@ async function validateWithOptimizedProvider(publisherDomain, records, provider,
|
|
|
629
634
|
logger.error(`Error fetching sellers for domain ${domain}:`, error);
|
|
630
635
|
domainSellersMap.set(domain, new Map());
|
|
631
636
|
domainMetadataMap.set(domain, {});
|
|
637
|
+
// On error, we can't confirm sellers.json exists
|
|
638
|
+
if (!domainHasSellersJsonMap.has(domain)) {
|
|
639
|
+
domainHasSellersJsonMap.set(domain, false);
|
|
640
|
+
}
|
|
632
641
|
}
|
|
633
642
|
}
|
|
634
643
|
// Validate each record using the fetched data
|
|
@@ -640,7 +649,10 @@ async function validateWithOptimizedProvider(publisherDomain, records, provider,
|
|
|
640
649
|
const domain = record.domain.toLowerCase().trim();
|
|
641
650
|
const sellersMap = domainSellersMap.get(domain) || new Map();
|
|
642
651
|
const metadata = domainMetadataMap.get(domain) || {};
|
|
643
|
-
|
|
652
|
+
// Use explicit sellers.json existence flag to avoid false "noSellersJson" when
|
|
653
|
+
// sellers.json exists but no matching seller IDs were found
|
|
654
|
+
const hasSellersJson = domainHasSellersJsonMap.get(domain) ?? (sellersMap.size > 0 || Object.keys(metadata).length > 0);
|
|
655
|
+
return await validateSingleRecordOptimized(record, publisherDomain, sellersMap, metadata, allEntries, hasSellersJson);
|
|
644
656
|
}));
|
|
645
657
|
logger.info(`After optimized sellers.json validation: ${validatedRecords.length} records, ${validatedRecords.filter((r) => r.has_warning).length} with warnings`);
|
|
646
658
|
return validatedRecords;
|
|
@@ -648,11 +660,15 @@ async function validateWithOptimizedProvider(publisherDomain, records, provider,
|
|
|
648
660
|
/**
|
|
649
661
|
* Validate a single record using optimized data structures
|
|
650
662
|
*/
|
|
651
|
-
async function validateSingleRecordOptimized(record, publisherDomain, sellersMap, metadata, allEntries) {
|
|
663
|
+
async function validateSingleRecordOptimized(record, publisherDomain, sellersMap, metadata, allEntries, hasSellersJson) {
|
|
652
664
|
// Initialize validation result
|
|
653
665
|
const validationResult = createInitialValidationResult();
|
|
654
|
-
// Check if sellers.json exists for this domain
|
|
655
|
-
|
|
666
|
+
// Check if sellers.json exists for this domain.
|
|
667
|
+
// Use the explicit hasSellersJson flag when provided to correctly handle the case where
|
|
668
|
+
// sellers.json exists but no matching seller IDs were found (which produces an empty sellersMap).
|
|
669
|
+
validationResult.hasSellerJson = hasSellersJson !== undefined
|
|
670
|
+
? hasSellersJson
|
|
671
|
+
: (sellersMap.size > 0 || Object.keys(metadata).length > 0);
|
|
656
672
|
if (!validationResult.hasSellerJson) {
|
|
657
673
|
return createWarningRecord(record, exports.VALIDATION_KEYS.NO_SELLERS_JSON, { domain: record.domain }, Severity.WARNING, { validation_results: validationResult });
|
|
658
674
|
}
|