DomainDig/Models.swift
816 lines · 27455 bytes
1import Foundation
2
3enum ServiceResult<Value> {
4 case success(Value)
5 case empty(String)
6 case error(String)
7}
8
9enum DomainAvailabilityStatus: String, Codable {
10 case available
11 case registered
12 case unknown
13}
14
15struct DomainAvailabilityResult: Codable {
16 let domain: String
17 let status: DomainAvailabilityStatus
18}
19
20struct DomainSuggestionResult: Identifiable, Codable {
21 let id: UUID
22 let domain: String
23 let status: DomainAvailabilityStatus
24
25 init(id: UUID = UUID(), domain: String, status: DomainAvailabilityStatus) {
26 self.id = id
27 self.domain = domain
28 self.status = status
29 }
30}
31
32struct WatchedDomain: Codable, Identifiable {
33 let id: UUID
34 let domain: String
35 let createdAt: Date
36 var lastKnownAvailability: DomainAvailabilityStatus?
37
38 init(
39 id: UUID = UUID(),
40 domain: String,
41 createdAt: Date = Date(),
42 lastKnownAvailability: DomainAvailabilityStatus? = nil
43 ) {
44 self.id = id
45 self.domain = domain
46 self.createdAt = createdAt
47 self.lastKnownAvailability = lastKnownAvailability
48 }
49}
50
51enum ChangeSeverity: Int, Codable, CaseIterable, Comparable {
52 case low
53 case medium
54 case high
55
56 static func < (lhs: ChangeSeverity, rhs: ChangeSeverity) -> Bool {
57 lhs.rawValue < rhs.rawValue
58 }
59
60 var title: String {
61 switch self {
62 case .low:
63 return "Low"
64 case .medium:
65 return "Medium"
66 case .high:
67 return "High"
68 }
69 }
70}
71
72enum CertificateWarningLevel: String, Codable {
73 case none
74 case warning
75 case critical
76
77 var title: String {
78 switch self {
79 case .none:
80 return "Healthy"
81 case .warning:
82 return "Warning"
83 case .critical:
84 return "Critical"
85 }
86 }
87}
88
89struct DomainChangeSummary: Codable, Equatable {
90 let hasChanges: Bool
91 let changedSections: [String]
92 let message: String
93 let severity: ChangeSeverity
94 let generatedAt: Date
95
96 init(
97 hasChanges: Bool,
98 changedSections: [String],
99 message: String,
100 severity: ChangeSeverity,
101 generatedAt: Date
102 ) {
103 self.hasChanges = hasChanges
104 self.changedSections = changedSections
105 self.message = message
106 self.severity = severity
107 self.generatedAt = generatedAt
108 }
109
110 init(from decoder: Decoder) throws {
111 let container = try decoder.container(keyedBy: CodingKeys.self)
112 hasChanges = try container.decodeIfPresent(Bool.self, forKey: .hasChanges) ?? false
113 changedSections = try container.decodeIfPresent([String].self, forKey: .changedSections) ?? []
114 generatedAt = try container.decode(Date.self, forKey: .generatedAt)
115 severity = try container.decodeIfPresent(ChangeSeverity.self, forKey: .severity) ?? (hasChanges ? .medium : .low)
116 message = try container.decodeIfPresent(String.self, forKey: .message)
117 ?? (changedSections.isEmpty ? "No meaningful changes" : changedSections.joined(separator: " • "))
118 }
119}
120
121enum BatchLookupSource: String, Codable {
122 case manual
123 case watchlistRefresh
124}
125
126enum BatchLookupStatus: String, Codable {
127 case pending
128 case running
129 case completed
130 case failed
131}
132
133struct BatchLookupResult: Identifiable, Codable, Equatable {
134 let id: UUID
135 let domain: String
136 let historyEntryID: UUID?
137 let availability: DomainAvailabilityStatus?
138 let primaryIP: String?
139 let quickStatus: String
140 let summaryMessage: String?
141 let changeSeverity: ChangeSeverity?
142 let certificateWarningLevel: CertificateWarningLevel
143 let timestamp: Date
144 let status: BatchLookupStatus
145 let errorMessage: String?
146
147 init(
148 id: UUID = UUID(),
149 domain: String,
150 historyEntryID: UUID?,
151 availability: DomainAvailabilityStatus?,
152 primaryIP: String?,
153 quickStatus: String,
154 summaryMessage: String? = nil,
155 changeSeverity: ChangeSeverity? = nil,
156 certificateWarningLevel: CertificateWarningLevel = .none,
157 timestamp: Date,
158 status: BatchLookupStatus,
159 errorMessage: String? = nil
160 ) {
161 self.id = id
162 self.domain = domain
163 self.historyEntryID = historyEntryID
164 self.availability = availability
165 self.primaryIP = primaryIP
166 self.quickStatus = quickStatus
167 self.summaryMessage = summaryMessage
168 self.changeSeverity = changeSeverity
169 self.certificateWarningLevel = certificateWarningLevel
170 self.timestamp = timestamp
171 self.status = status
172 self.errorMessage = errorMessage
173 }
174}
175
176struct BatchSweepSummary: Identifiable, Equatable {
177 let id = UUID()
178 let source: BatchLookupSource
179 let totalDomains: Int
180 let changedDomains: Int
181 let unchangedDomains: Int
182 let warningDomains: Int
183 let results: [BatchLookupResult]
184 let generatedAt: Date
185}
186
187enum DataCapability: String, Codable {
188 case ownershipHistory
189 case dnsHistory
190 case extendedSubdomains
191 case domainPricing
192}
193
194enum HistoryDateFilter: String, CaseIterable, Identifiable {
195 case today
196 case last7Days
197 case all
198
199 var id: String { rawValue }
200
201 var title: String {
202 switch self {
203 case .today:
204 return "Today"
205 case .last7Days:
206 return "Last 7 Days"
207 case .all:
208 return "All"
209 }
210 }
211}
212
213enum ChangeFilterOption: String, CaseIterable, Identifiable {
214 case all
215 case changed
216 case unchanged
217
218 var id: String { rawValue }
219
220 var title: String {
221 switch self {
222 case .all:
223 return "All"
224 case .changed:
225 return "Changed"
226 case .unchanged:
227 return "Unchanged"
228 }
229 }
230}
231
232enum HistorySortOption: String, CaseIterable, Identifiable {
233 case newest
234 case oldest
235 case domain
236
237 var id: String { rawValue }
238
239 var title: String {
240 switch self {
241 case .newest:
242 return "Newest"
243 case .oldest:
244 return "Oldest"
245 case .domain:
246 return "Domain A-Z"
247 }
248 }
249}
250
251enum WatchlistFilterOption: String, CaseIterable, Identifiable {
252 case all
253 case pinnedOnly
254 case changedOnly
255
256 var id: String { rawValue }
257
258 var title: String {
259 switch self {
260 case .all:
261 return "All"
262 case .pinnedOnly:
263 return "Pinned Only"
264 case .changedOnly:
265 return "Changed Only"
266 }
267 }
268}
269
270enum WatchlistSortOption: String, CaseIterable, Identifiable {
271 case pinned
272 case recentlyUpdated
273 case alphabetical
274
275 var id: String { rawValue }
276
277 var title: String {
278 switch self {
279 case .pinned:
280 return "Pinned"
281 case .recentlyUpdated:
282 return "Recently Updated"
283 case .alphabetical:
284 return "Alphabetical"
285 }
286 }
287}
288
289enum PremiumCapability: String, Codable {
290 case unlimitedTrackedDomains
291 case automatedMonitoring
292 case pushAlerts
293 case batchTracking
294 case advancedExports
295}
296
297struct TrackedDomain: Codable, Identifiable, Equatable {
298 let id: UUID
299 var domain: String
300 var createdAt: Date
301 var updatedAt: Date
302 var note: String?
303 var isPinned: Bool
304 var lastKnownAvailability: DomainAvailabilityStatus?
305 var lastSnapshotID: UUID?
306 var lastChangeSummary: DomainChangeSummary?
307 var lastChangeSeverity: ChangeSeverity?
308 var certificateWarningLevel: CertificateWarningLevel
309 var certificateDaysRemaining: Int?
310
311 init(
312 id: UUID = UUID(),
313 domain: String,
314 createdAt: Date = Date(),
315 updatedAt: Date = Date(),
316 note: String? = nil,
317 isPinned: Bool = false,
318 lastKnownAvailability: DomainAvailabilityStatus? = nil,
319 lastSnapshotID: UUID? = nil,
320 lastChangeSummary: DomainChangeSummary? = nil,
321 lastChangeSeverity: ChangeSeverity? = nil,
322 certificateWarningLevel: CertificateWarningLevel = .none,
323 certificateDaysRemaining: Int? = nil
324 ) {
325 self.id = id
326 self.domain = domain
327 self.createdAt = createdAt
328 self.updatedAt = updatedAt
329 self.note = note
330 self.isPinned = isPinned
331 self.lastKnownAvailability = lastKnownAvailability
332 self.lastSnapshotID = lastSnapshotID
333 self.lastChangeSummary = lastChangeSummary
334 self.lastChangeSeverity = lastChangeSeverity
335 self.certificateWarningLevel = certificateWarningLevel
336 self.certificateDaysRemaining = certificateDaysRemaining
337 }
338
339 init(from decoder: Decoder) throws {
340 let container = try decoder.container(keyedBy: CodingKeys.self)
341 id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
342 domain = try container.decode(String.self, forKey: .domain)
343 createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) ?? Date()
344 updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt) ?? createdAt
345 note = try container.decodeIfPresent(String.self, forKey: .note)
346 isPinned = try container.decodeIfPresent(Bool.self, forKey: .isPinned) ?? false
347 lastKnownAvailability = try container.decodeIfPresent(DomainAvailabilityStatus.self, forKey: .lastKnownAvailability)
348 lastSnapshotID = try container.decodeIfPresent(UUID.self, forKey: .lastSnapshotID)
349 lastChangeSummary = try container.decodeIfPresent(DomainChangeSummary.self, forKey: .lastChangeSummary)
350 lastChangeSeverity = try container.decodeIfPresent(ChangeSeverity.self, forKey: .lastChangeSeverity) ?? lastChangeSummary?.severity
351 certificateWarningLevel = try container.decodeIfPresent(CertificateWarningLevel.self, forKey: .certificateWarningLevel) ?? .none
352 certificateDaysRemaining = try container.decodeIfPresent(Int.self, forKey: .certificateDaysRemaining)
353 }
354}
355
356// MARK: - DNS Models
357
358enum DNSRecordType: String, CaseIterable, Codable {
359 case A
360 case AAAA
361 case MX
362 case NS
363 case TXT
364 case CNAME
365 case SOA
366 case SRV
367 case CAA
368 case DS
369 case PTR
370
371 var queryType: Int {
372 switch self {
373 case .A: return 1
374 case .AAAA: return 28
375 case .MX: return 15
376 case .NS: return 2
377 case .TXT: return 16
378 case .CNAME: return 5
379 case .SOA: return 6
380 case .SRV: return 33
381 case .CAA: return 257
382 case .DS: return 43
383 case .PTR: return 12
384 }
385 }
386
387 var usesRawDataValue: Bool {
388 switch self {
389 case .TXT, .SOA, .DS:
390 return true
391 default:
392 return false
393 }
394 }
395}
396
397struct DNSRecord: Identifiable, Codable {
398 var id = UUID()
399 let value: String
400 let ttl: Int
401}
402
403struct DNSSection: Identifiable, Codable {
404 var id = UUID()
405 let recordType: DNSRecordType
406 var records: [DNSRecord]
407 var wildcardRecords: [DNSRecord] = []
408 var dnssecSigned: Bool?
409 var error: String?
410}
411
412// MARK: - SSL Models
413
414struct SSLCertificateInfo: Codable {
415 struct CertChainEntry: Codable {
416 let subject: String
417 let issuer: String
418 }
419
420 let commonName: String
421 let subjectAltNames: [String]
422 let issuer: String
423 let validFrom: Date
424 let validUntil: Date
425 let daysUntilExpiry: Int
426 let chainDepth: Int
427 let tlsVersion: String?
428 let cipherSuite: String?
429 let chain: [CertChainEntry]
430
431 init(
432 commonName: String,
433 subjectAltNames: [String],
434 issuer: String,
435 validFrom: Date,
436 validUntil: Date,
437 daysUntilExpiry: Int,
438 chainDepth: Int,
439 tlsVersion: String? = nil,
440 cipherSuite: String? = nil,
441 chain: [CertChainEntry] = []
442 ) {
443 self.commonName = commonName
444 self.subjectAltNames = subjectAltNames
445 self.issuer = issuer
446 self.validFrom = validFrom
447 self.validUntil = validUntil
448 self.daysUntilExpiry = daysUntilExpiry
449 self.chainDepth = chainDepth
450 self.tlsVersion = tlsVersion
451 self.cipherSuite = cipherSuite
452 self.chain = chain
453 }
454
455 init(from decoder: Decoder) throws {
456 let container = try decoder.container(keyedBy: CodingKeys.self)
457 commonName = try container.decode(String.self, forKey: .commonName)
458 subjectAltNames = try container.decode([String].self, forKey: .subjectAltNames)
459 issuer = try container.decode(String.self, forKey: .issuer)
460 validFrom = try container.decode(Date.self, forKey: .validFrom)
461 validUntil = try container.decode(Date.self, forKey: .validUntil)
462 daysUntilExpiry = try container.decode(Int.self, forKey: .daysUntilExpiry)
463 chainDepth = try container.decode(Int.self, forKey: .chainDepth)
464 tlsVersion = try container.decodeIfPresent(String.self, forKey: .tlsVersion)
465 cipherSuite = try container.decodeIfPresent(String.self, forKey: .cipherSuite)
466 chain = try container.decodeIfPresent([CertChainEntry].self, forKey: .chain) ?? []
467 }
468}
469
470// MARK: - HTTP Headers Models
471
472struct HTTPHeader: Identifiable, Codable {
473 var id = UUID()
474 let name: String
475 let value: String
476
477 static let securityHeaders: Set<String> = [
478 "strict-transport-security",
479 "x-frame-options",
480 "x-content-type-options",
481 "content-security-policy",
482 "referrer-policy"
483 ]
484
485 var isSecurityHeader: Bool {
486 Self.securityHeaders.contains(name.lowercased())
487 }
488}
489
490// MARK: - Reachability Models
491
492struct PortReachability: Identifiable, Codable {
493 var id = UUID()
494 let port: UInt16
495 let reachable: Bool
496 let latencyMs: Int?
497}
498
499// MARK: - IP Geolocation Models
500
501struct IPGeolocation: Codable {
502 let ip: String
503 let city: String?
504 let region: String?
505 let country_name: String?
506 let org: String?
507 let latitude: Double?
508 let longitude: Double?
509}
510
511// MARK: - Ownership Models
512
513struct DomainOwnership: Codable, Equatable {
514 let registrar: String?
515 let createdDate: Date?
516 let expirationDate: Date?
517 let status: [String]
518 let nameservers: [String]
519 let abuseEmail: String?
520
521 init(
522 registrar: String? = nil,
523 createdDate: Date? = nil,
524 expirationDate: Date? = nil,
525 status: [String] = [],
526 nameservers: [String] = [],
527 abuseEmail: String? = nil
528 ) {
529 self.registrar = registrar
530 self.createdDate = createdDate
531 self.expirationDate = expirationDate
532 self.status = status
533 self.nameservers = nameservers
534 self.abuseEmail = abuseEmail
535 }
536
537 init(from decoder: Decoder) throws {
538 let container = try decoder.container(keyedBy: CodingKeys.self)
539 registrar = try container.decodeIfPresent(String.self, forKey: .registrar)
540 createdDate = try container.decodeIfPresent(Date.self, forKey: .createdDate)
541 expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate)
542 status = try container.decodeIfPresent([String].self, forKey: .status) ?? []
543 nameservers = try container.decodeIfPresent([String].self, forKey: .nameservers) ?? []
544 abuseEmail = try container.decodeIfPresent(String.self, forKey: .abuseEmail)
545 }
546}
547
548struct DiscoveredSubdomain: Codable, Equatable, Hashable, Identifiable {
549 var id: String { hostname }
550 let hostname: String
551}
552
553// MARK: - Email Security Models
554
555struct EmailSecurityResult: Codable {
556 let spf: EmailSecurityRecord
557 let dmarc: EmailSecurityRecord
558 let dkim: EmailSecurityRecord
559 let bimi: EmailSecurityRecord
560 let mtaSts: MTASTSResult?
561
562 init(
563 spf: EmailSecurityRecord,
564 dmarc: EmailSecurityRecord,
565 dkim: EmailSecurityRecord,
566 bimi: EmailSecurityRecord = EmailSecurityRecord(found: false, value: nil),
567 mtaSts: MTASTSResult? = nil
568 ) {
569 self.spf = spf
570 self.dmarc = dmarc
571 self.dkim = dkim
572 self.bimi = bimi
573 self.mtaSts = mtaSts
574 }
575
576 init(from decoder: Decoder) throws {
577 let container = try decoder.container(keyedBy: CodingKeys.self)
578 spf = try container.decode(EmailSecurityRecord.self, forKey: .spf)
579 dmarc = try container.decode(EmailSecurityRecord.self, forKey: .dmarc)
580 dkim = try container.decode(EmailSecurityRecord.self, forKey: .dkim)
581 bimi = try container.decodeIfPresent(EmailSecurityRecord.self, forKey: .bimi)
582 ?? EmailSecurityRecord(found: false, value: nil)
583 mtaSts = try container.decodeIfPresent(MTASTSResult.self, forKey: .mtaSts)
584 }
585}
586
587struct EmailSecurityRecord: Codable {
588 let found: Bool
589 let value: String?
590 let matchedSelector: String?
591
592 init(found: Bool, value: String?, matchedSelector: String? = nil) {
593 self.found = found
594 self.value = value
595 self.matchedSelector = matchedSelector
596 }
597
598 init(from decoder: Decoder) throws {
599 let container = try decoder.container(keyedBy: CodingKeys.self)
600 found = try container.decode(Bool.self, forKey: .found)
601 value = try container.decodeIfPresent(String.self, forKey: .value)
602 matchedSelector = try container.decodeIfPresent(String.self, forKey: .matchedSelector)
603 }
604}
605
606struct MTASTSResult: Codable {
607 let txtFound: Bool
608 let policyMode: String?
609}
610
611// MARK: - Redirect Chain Models
612
613struct RedirectHop: Identifiable, Codable {
614 var id = UUID()
615 let stepNumber: Int
616 let statusCode: Int
617 let url: String
618 let isFinal: Bool
619}
620
621// MARK: - Port Scan Models
622
623enum PortScanKind: String, Codable {
624 case standard
625 case custom
626}
627
628struct PortScanResult: Identifiable, Codable {
629 var id = UUID()
630 let port: UInt16
631 let service: String
632 let open: Bool
633 var banner: String?
634 let kind: PortScanKind
635 let durationMs: Int?
636
637 nonisolated init(
638 port: UInt16,
639 service: String,
640 open: Bool,
641 banner: String? = nil,
642 kind: PortScanKind = .standard,
643 durationMs: Int? = nil
644 ) {
645 self.port = port
646 self.service = service
647 self.open = open
648 self.banner = banner
649 self.kind = kind
650 self.durationMs = durationMs
651 }
652
653 init(from decoder: Decoder) throws {
654 let container = try decoder.container(keyedBy: CodingKeys.self)
655 id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
656 port = try container.decode(UInt16.self, forKey: .port)
657 service = try container.decode(String.self, forKey: .service)
658 open = try container.decode(Bool.self, forKey: .open)
659 banner = try container.decodeIfPresent(String.self, forKey: .banner)
660 kind = try container.decodeIfPresent(PortScanKind.self, forKey: .kind) ?? .standard
661 durationMs = try container.decodeIfPresent(Int.self, forKey: .durationMs)
662 }
663}
664
665// MARK: - History Models
666
667struct HistoryEntry: Identifiable, Codable {
668 var id = UUID()
669 let domain: String
670 let timestamp: Date
671 var trackedDomainID: UUID?
672 let dnsSections: [DNSSection]
673 let sslInfo: SSLCertificateInfo?
674 let httpHeaders: [HTTPHeader]
675 let reachabilityResults: [PortReachability]
676 let ipGeolocation: IPGeolocation?
677 var emailSecurity: EmailSecurityResult?
678 var mtaSts: MTASTSResult?
679 var ownership: DomainOwnership?
680 var ptrRecord: String?
681 var redirectChain: [RedirectHop]
682 var subdomains: [DiscoveredSubdomain]
683 var portScanResults: [PortScanResult]
684 var hstsPreloaded: Bool?
685 var availabilityResult: DomainAvailabilityResult?
686 var suggestions: [DomainSuggestionResult]
687 var resolverDisplayName: String
688 var resolverURLString: String
689 var totalLookupDurationMs: Int?
690 var primaryIP: String?
691 var finalRedirectURL: String?
692 var tlsStatusSummary: String?
693 var emailSecuritySummary: String?
694 var httpGradeSummary: String?
695 var changeSummary: DomainChangeSummary?
696 var sslError: String?
697 var httpHeadersError: String?
698 var reachabilityError: String?
699 var ipGeolocationError: String?
700 var emailSecurityError: String?
701 var ownershipError: String?
702 var ptrError: String?
703 var redirectChainError: String?
704 var subdomainsError: String?
705 var portScanError: String?
706
707 init(domain: String, timestamp: Date, trackedDomainID: UUID? = nil, dnsSections: [DNSSection],
708 sslInfo: SSLCertificateInfo?, httpHeaders: [HTTPHeader],
709 reachabilityResults: [PortReachability], ipGeolocation: IPGeolocation?,
710 emailSecurity: EmailSecurityResult? = nil, mtaSts: MTASTSResult? = nil, ownership: DomainOwnership? = nil,
711 ptrRecord: String? = nil, redirectChain: [RedirectHop] = [], subdomains: [DiscoveredSubdomain] = [],
712 portScanResults: [PortScanResult] = [],
713 hstsPreloaded: Bool? = nil, availabilityResult: DomainAvailabilityResult? = nil,
714 suggestions: [DomainSuggestionResult] = [], resolverDisplayName: String, resolverURLString: String,
715 totalLookupDurationMs: Int? = nil, primaryIP: String? = nil, finalRedirectURL: String? = nil,
716 tlsStatusSummary: String? = nil, emailSecuritySummary: String? = nil, httpGradeSummary: String? = nil,
717 changeSummary: DomainChangeSummary? = nil, sslError: String? = nil, httpHeadersError: String? = nil,
718 reachabilityError: String? = nil, ipGeolocationError: String? = nil,
719 emailSecurityError: String? = nil, ownershipError: String? = nil, ptrError: String? = nil,
720 redirectChainError: String? = nil, subdomainsError: String? = nil, portScanError: String? = nil) {
721 self.domain = domain
722 self.timestamp = timestamp
723 self.trackedDomainID = trackedDomainID
724 self.dnsSections = dnsSections
725 self.sslInfo = sslInfo
726 self.httpHeaders = httpHeaders
727 self.reachabilityResults = reachabilityResults
728 self.ipGeolocation = ipGeolocation
729 self.emailSecurity = emailSecurity
730 self.mtaSts = mtaSts ?? emailSecurity?.mtaSts
731 self.ownership = ownership
732 self.ptrRecord = ptrRecord
733 self.redirectChain = redirectChain
734 self.subdomains = subdomains
735 self.portScanResults = portScanResults
736 self.hstsPreloaded = hstsPreloaded
737 self.availabilityResult = availabilityResult
738 self.suggestions = suggestions
739 self.resolverDisplayName = resolverDisplayName
740 self.resolverURLString = resolverURLString
741 self.totalLookupDurationMs = totalLookupDurationMs
742 self.primaryIP = primaryIP
743 self.finalRedirectURL = finalRedirectURL
744 self.tlsStatusSummary = tlsStatusSummary
745 self.emailSecuritySummary = emailSecuritySummary
746 self.httpGradeSummary = httpGradeSummary
747 self.changeSummary = changeSummary
748 self.sslError = sslError
749 self.httpHeadersError = httpHeadersError
750 self.reachabilityError = reachabilityError
751 self.ipGeolocationError = ipGeolocationError
752 self.emailSecurityError = emailSecurityError
753 self.ownershipError = ownershipError
754 self.ptrError = ptrError
755 self.redirectChainError = redirectChainError
756 self.subdomainsError = subdomainsError
757 self.portScanError = portScanError
758 }
759
760 init(from decoder: Decoder) throws {
761 let container = try decoder.container(keyedBy: CodingKeys.self)
762 id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
763 domain = try container.decode(String.self, forKey: .domain)
764 timestamp = try container.decode(Date.self, forKey: .timestamp)
765 trackedDomainID = try container.decodeIfPresent(UUID.self, forKey: .trackedDomainID)
766 dnsSections = try container.decode([DNSSection].self, forKey: .dnsSections)
767 sslInfo = try container.decodeIfPresent(SSLCertificateInfo.self, forKey: .sslInfo)
768 httpHeaders = try container.decode([HTTPHeader].self, forKey: .httpHeaders)
769 reachabilityResults = try container.decode([PortReachability].self, forKey: .reachabilityResults)
770 ipGeolocation = try container.decodeIfPresent(IPGeolocation.self, forKey: .ipGeolocation)
771 emailSecurity = try container.decodeIfPresent(EmailSecurityResult.self, forKey: .emailSecurity)
772 mtaSts = try container.decodeIfPresent(MTASTSResult.self, forKey: .mtaSts) ?? emailSecurity?.mtaSts
773 ownership = try container.decodeIfPresent(DomainOwnership.self, forKey: .ownership)
774 ptrRecord = try container.decodeIfPresent(String.self, forKey: .ptrRecord)
775 redirectChain = try container.decodeIfPresent([RedirectHop].self, forKey: .redirectChain) ?? []
776 subdomains = try container.decodeIfPresent([DiscoveredSubdomain].self, forKey: .subdomains) ?? []
777 portScanResults = try container.decodeIfPresent([PortScanResult].self, forKey: .portScanResults) ?? []
778 hstsPreloaded = try container.decodeIfPresent(Bool.self, forKey: .hstsPreloaded)
779 availabilityResult = try container.decodeIfPresent(DomainAvailabilityResult.self, forKey: .availabilityResult)
780 suggestions = try container.decodeIfPresent([DomainSuggestionResult].self, forKey: .suggestions) ?? []
781 resolverDisplayName = try container.decodeIfPresent(String.self, forKey: .resolverDisplayName) ?? "Cloudflare"
782 resolverURLString = try container.decodeIfPresent(String.self, forKey: .resolverURLString) ?? DNSResolverOption.defaultURLString
783 totalLookupDurationMs = try container.decodeIfPresent(Int.self, forKey: .totalLookupDurationMs)
784 primaryIP = try container.decodeIfPresent(String.self, forKey: .primaryIP)
785 finalRedirectURL = try container.decodeIfPresent(String.self, forKey: .finalRedirectURL)
786 tlsStatusSummary = try container.decodeIfPresent(String.self, forKey: .tlsStatusSummary)
787 emailSecuritySummary = try container.decodeIfPresent(String.self, forKey: .emailSecuritySummary)
788 httpGradeSummary = try container.decodeIfPresent(String.self, forKey: .httpGradeSummary)
789 changeSummary = try container.decodeIfPresent(DomainChangeSummary.self, forKey: .changeSummary)
790 sslError = try container.decodeIfPresent(String.self, forKey: .sslError)
791 httpHeadersError = try container.decodeIfPresent(String.self, forKey: .httpHeadersError)
792 reachabilityError = try container.decodeIfPresent(String.self, forKey: .reachabilityError)
793 ipGeolocationError = try container.decodeIfPresent(String.self, forKey: .ipGeolocationError)
794 emailSecurityError = try container.decodeIfPresent(String.self, forKey: .emailSecurityError)
795 ownershipError = try container.decodeIfPresent(String.self, forKey: .ownershipError)
796 ptrError = try container.decodeIfPresent(String.self, forKey: .ptrError)
797 redirectChainError = try container.decodeIfPresent(String.self, forKey: .redirectChainError)
798 subdomainsError = try container.decodeIfPresent(String.self, forKey: .subdomainsError)
799 portScanError = try container.decodeIfPresent(String.self, forKey: .portScanError)
800 }
801}
802
803// MARK: - Cloudflare DNS-over-HTTPS Response
804
805struct CloudflareDNSResponse: Decodable {
806 let Status: Int
807 let AD: Bool?
808 let Answer: [CloudflareDNSAnswer]?
809
810 struct CloudflareDNSAnswer: Decodable {
811 let name: String
812 let type: Int
813 let TTL: Int
814 let data: String
815 }
816}