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