Skip to main content

ipscanner/types/
edge.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::AgentCheck;
6
7/// Body of `POST /v1/edge/check`.
8#[derive(Debug, Clone, Default, PartialEq, Serialize)]
9pub struct EdgeCheckRequest {
10    pub ip: String,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub site: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub user_agent: Option<String>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub ja4: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub headers: Option<HashMap<String, String>>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub headless_flags: Option<HashMap<String, bool>>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub request_id: Option<String>,
23}
24
25impl EdgeCheckRequest {
26    pub fn new(ip: impl Into<String>) -> Self {
27        EdgeCheckRequest {
28            ip: ip.into(),
29            ..Default::default()
30        }
31    }
32}
33
34/// Response of `POST /v1/edge/check`.
35#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36#[serde(default, rename_all = "camelCase")]
37pub struct EdgeCheck {
38    /// Traffic class, such as `human`, `verified_bot`, `ai_agent`, `vpn` or `relay`.
39    pub class: String,
40    /// Null when the Agentscan half did not answer.
41    pub agent: Option<AgentCheck>,
42    /// Null when the network half did not answer.
43    pub network: Option<EdgeNetwork>,
44    /// Null when no site was given, or it is unknown or another account's.
45    pub site: Option<EdgeSite>,
46    /// `agent` and/or `network` when that half is missing.
47    pub degraded: Vec<String>,
48    pub locked: Vec<String>,
49    pub plan_required: Option<String>,
50}
51
52/// The network half of an edge check.
53#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
54#[serde(default, rename_all = "camelCase")]
55pub struct EdgeNetwork {
56    pub network_class: String,
57    pub anonymized: bool,
58    pub risk_score: i64,
59    /// The network owner. Null on the Free plan.
60    pub provider: Option<String>,
61    /// The VPN brand when known. Null on the Free plan.
62    pub vpn_provider: Option<String>,
63    pub evidence: Vec<String>,
64    pub country: Option<String>,
65    pub asn: Option<i64>,
66    pub asn_name: Option<String>,
67}
68
69/// The site an edge check was attributed to.
70#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
71#[serde(default, rename_all = "camelCase")]
72pub struct EdgeSite {
73    pub id: String,
74    /// `monitor` or `enforce`.
75    pub mode: String,
76    pub policy_version: i64,
77}