adstxt-validator 1.2.3

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.
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Utility to validate and parse Ads.txt data
3
+ */
4
+ export declare enum Severity {
5
+ ERROR = "error",
6
+ WARNING = "warning",
7
+ INFO = "info"
8
+ }
9
+ export declare const VALIDATION_KEYS: {
10
+ MISSING_FIELDS: string;
11
+ INVALID_FORMAT: string;
12
+ INVALID_RELATIONSHIP: string;
13
+ INVALID_DOMAIN: string;
14
+ EMPTY_ACCOUNT_ID: string;
15
+ IMPLIMENTED: string;
16
+ NO_SELLERS_JSON: string;
17
+ DIRECT_ACCOUNT_ID_NOT_IN_SELLERS_JSON: string;
18
+ RESELLER_ACCOUNT_ID_NOT_IN_SELLERS_JSON: string;
19
+ DOMAIN_MISMATCH: string;
20
+ DIRECT_NOT_PUBLISHER: string;
21
+ SELLER_ID_NOT_UNIQUE: string;
22
+ RESELLER_NOT_INTERMEDIARY: string;
23
+ SELLERS_JSON_VALIDATION_ERROR: string;
24
+ EMPTY_FILE: string;
25
+ INVALID_CHARACTERS: string;
26
+ };
27
+ export declare const ERROR_KEYS: {
28
+ MISSING_FIELDS: string;
29
+ INVALID_FORMAT: string;
30
+ INVALID_RELATIONSHIP: string;
31
+ INVALID_DOMAIN: string;
32
+ EMPTY_ACCOUNT_ID: string;
33
+ IMPLIMENTED: string;
34
+ NO_SELLERS_JSON: string;
35
+ DIRECT_ACCOUNT_ID_NOT_IN_SELLERS_JSON: string;
36
+ RESELLER_ACCOUNT_ID_NOT_IN_SELLERS_JSON: string;
37
+ DOMAIN_MISMATCH: string;
38
+ DIRECT_NOT_PUBLISHER: string;
39
+ SELLER_ID_NOT_UNIQUE: string;
40
+ RESELLER_NOT_INTERMEDIARY: string;
41
+ SELLERS_JSON_VALIDATION_ERROR: string;
42
+ EMPTY_FILE: string;
43
+ INVALID_CHARACTERS: string;
44
+ };
45
+ export { ValidationMessage, MessageData, MessageProvider, MessageConfig, DefaultMessageProvider, SupportedLocale, setMessageProvider, getMessageProvider, createValidationMessage, configureMessages, isSupportedLocale, getSupportedLocales, } from './messages';
46
+ export interface SellersJsonProvider {
47
+ /**
48
+ * Get specific sellers by seller IDs for a domain
49
+ * @param domain - The domain to fetch sellers for
50
+ * @param sellerIds - Array of seller IDs to fetch
51
+ * @returns Promise resolving to batch sellers result
52
+ */
53
+ batchGetSellers(domain: string, sellerIds: string[]): Promise<BatchSellersResult>;
54
+ /**
55
+ * Get metadata for a domain's sellers.json
56
+ * @param domain - The domain to fetch metadata for
57
+ * @returns Promise resolving to sellers.json metadata
58
+ */
59
+ getMetadata(domain: string): Promise<SellersJsonMetadata>;
60
+ /**
61
+ * Check if a domain has a sellers.json file
62
+ * @param domain - The domain to check
63
+ * @returns Promise resolving to boolean indicating existence
64
+ */
65
+ hasSellerJson(domain: string): Promise<boolean>;
66
+ /**
67
+ * Get cache information for a domain
68
+ * @param domain - The domain to get cache info for
69
+ * @returns Promise resolving to cache information
70
+ */
71
+ getCacheInfo(domain: string): Promise<CacheInfo>;
72
+ }
73
+ export interface BatchSellersResult {
74
+ domain: string;
75
+ requested_count: number;
76
+ found_count: number;
77
+ results: SellerResult[];
78
+ metadata: SellersJsonMetadata;
79
+ cache: CacheInfo;
80
+ }
81
+ export interface SellerResult {
82
+ sellerId: string;
83
+ seller: Seller | null;
84
+ found: boolean;
85
+ source: 'cache' | 'fresh';
86
+ error?: string;
87
+ }
88
+ export interface Seller {
89
+ seller_id: string;
90
+ name?: string;
91
+ domain?: string;
92
+ seller_type?: 'PUBLISHER' | 'INTERMEDIARY' | 'BOTH';
93
+ is_confidential?: 0 | 1;
94
+ [key: string]: any;
95
+ }
96
+ export interface SellersJsonMetadata {
97
+ version?: string;
98
+ contact_email?: string;
99
+ contact_address?: string;
100
+ seller_count?: number;
101
+ identifiers?: any[];
102
+ }
103
+ export interface CacheInfo {
104
+ is_cached: boolean;
105
+ last_updated?: string;
106
+ status: 'success' | 'error' | 'stale';
107
+ expires_at?: string;
108
+ }
109
+ export interface ParsedAdsTxtEntryBase {
110
+ line_number: number;
111
+ raw_line: string;
112
+ is_valid: boolean;
113
+ error?: string;
114
+ has_warning?: boolean;
115
+ warning?: string;
116
+ validation_key?: string;
117
+ severity?: Severity;
118
+ warning_params?: Record<string, any>;
119
+ all_warnings?: Array<{
120
+ key: string;
121
+ params?: Record<string, any>;
122
+ severity?: Severity;
123
+ }>;
124
+ validation_error?: string;
125
+ }
126
+ export interface ParsedAdsTxtVariable extends ParsedAdsTxtEntryBase {
127
+ variable_type: 'CONTACT' | 'SUBDOMAIN' | 'INVENTORYPARTNERDOMAIN' | 'OWNERDOMAIN' | 'MANAGERDOMAIN';
128
+ value: string;
129
+ is_variable: true;
130
+ }
131
+ export type ParsedAdsTxtEntry = ParsedAdsTxtRecord | ParsedAdsTxtVariable;
132
+ /**
133
+ * Type guard to check if an entry is a record
134
+ */
135
+ export declare function isAdsTxtRecord(entry: ParsedAdsTxtEntry): entry is ParsedAdsTxtRecord;
136
+ /**
137
+ * Type guard to check if an entry is a variable
138
+ */
139
+ export declare function isAdsTxtVariable(entry: ParsedAdsTxtEntry): entry is ParsedAdsTxtVariable;
140
+ export interface ParsedAdsTxtRecord extends ParsedAdsTxtEntryBase {
141
+ domain: string;
142
+ account_id: string;
143
+ account_type: string;
144
+ certification_authority_id?: string;
145
+ relationship: 'DIRECT' | 'RESELLER';
146
+ is_variable?: false;
147
+ duplicate_domain?: string;
148
+ validation_results?: CrossCheckValidationResult;
149
+ }
150
+ /**
151
+ * Parse an ads.txt variable line
152
+ * @param line - The raw line from the file
153
+ * @param lineNumber - The line number in the file (for error reporting)
154
+ * @returns A parsed variable if recognized, null otherwise
155
+ */
156
+ export declare function parseAdsTxtVariable(line: string, lineNumber: number): ParsedAdsTxtVariable | null;
157
+ /**
158
+ * Parse and validate a line from an Ads.txt file
159
+ * @param line - The raw line from the file
160
+ * @param lineNumber - The line number in the file (for error reporting)
161
+ * @returns A parsed record or variable, or null for comments and empty lines
162
+ */
163
+ export declare function parseAdsTxtLine(line: string, lineNumber: number): ParsedAdsTxtEntry | null;
164
+ /**
165
+ * Parse and validate a complete Ads.txt file
166
+ * @param content - The full content of the Ads.txt file
167
+ * @param publisherDomain - Optional publisher domain for creating default OWNERDOMAIN if missing
168
+ * @returns Array of parsed records and variables with validation status
169
+ */
170
+ export declare function parseAdsTxtContent(content: string, publisherDomain?: string): ParsedAdsTxtEntry[];
171
+ /**
172
+ * Logger helper to standardize logging
173
+ */
174
+ export type Logger = {
175
+ info: (message: string, ...args: any[]) => void;
176
+ error: (message: string, ...args: any[]) => void;
177
+ debug: (message: string, ...args: any[]) => void;
178
+ };
179
+ /**
180
+ * Interface for sellers.json seller record
181
+ */
182
+ export interface SellersJsonSellerRecord {
183
+ seller_id: string;
184
+ name?: string;
185
+ domain?: string;
186
+ seller_type?: 'PUBLISHER' | 'INTERMEDIARY' | 'BOTH';
187
+ is_confidential?: 0 | 1;
188
+ [key: string]: any;
189
+ }
190
+ /**
191
+ * Validation results for cross-checking ads.txt with sellers.json
192
+ */
193
+ export interface CrossCheckValidationResult {
194
+ hasSellerJson: boolean;
195
+ directAccountIdInSellersJson: boolean;
196
+ directDomainMatchesSellerJsonEntry: boolean | null;
197
+ directEntryHasPublisherType: boolean | null;
198
+ directSellerIdIsUnique: boolean | null;
199
+ resellerAccountIdInSellersJson: boolean | null;
200
+ resellerDomainMatchesSellerJsonEntry: boolean | null;
201
+ resellerEntryHasIntermediaryType: boolean | null;
202
+ resellerSellerIdIsUnique: boolean | null;
203
+ sellerData?: SellersJsonSellerRecord | null;
204
+ error?: string;
205
+ }
206
+ /**
207
+ * Optimized cross-check function using SellersJsonProvider
208
+ * This is the new preferred method for performance-critical applications
209
+ */
210
+ export declare function crossCheckAdsTxtRecords(publisherDomain: string | undefined, parsedEntries: ParsedAdsTxtEntry[], cachedAdsTxtContent: string | null, sellersJsonProvider: SellersJsonProvider): Promise<ParsedAdsTxtEntry[]>;
211
+ /**
212
+ * Legacy cross-check function for backward compatibility
213
+ * @deprecated Use the SellersJsonProvider version for better performance
214
+ */
215
+ export declare function crossCheckAdsTxtRecords(publisherDomain: string | undefined, parsedEntries: ParsedAdsTxtEntry[], cachedAdsTxtContent: string | null, getSellersJson: (domain: string) => Promise<any | null>): Promise<ParsedAdsTxtEntry[]>;
216
+ /**
217
+ * Check for duplicates in existing ads.txt records
218
+ */
219
+ export declare function checkForDuplicates(publisherDomain: string, parsedRecords: ParsedAdsTxtRecord[], // Note: This expects only record entries, not variables
220
+ cachedAdsTxtContent: string | null, logger: Logger): Promise<ParsedAdsTxtRecord[]>;
221
+ /**
222
+ * Ads.txt Level 1 Optimization
223
+ * Optimizes ads.txt content by:
224
+ * 1. Removing duplicates
225
+ * 2. Standardizing format
226
+ * 3. Preserving comments and variables
227
+ *
228
+ * @param content - The original ads.txt content
229
+ * @param publisherDomain - Optional publisher domain for OWNERDOMAIN default
230
+ * @returns Optimized ads.txt content as a string
231
+ */
232
+ export declare function optimizeAdsTxt(content: string, publisherDomain?: string): string;
233
+ /**
234
+ * Check if an email address is valid
235
+ * @param email - The email address to validate
236
+ * @returns Boolean indicating if the email is valid
237
+ */
238
+ export declare function isValidEmail(email: string): boolean;