clerk_fapi_rs/models/
client_session.rs

1/*
2 * Clerk Frontend API
3 *
4 * The Clerk REST Frontend API, meant to be accessed from a browser or native environment.  This is a Form Based API and all the data must be sent and formatted according to the `application/x-www-form-urlencoded` content type.  ### Versions  When the API changes in a way that isn't compatible with older versions, a new version is released. Each version is identified by its release date, e.g. `2021-02-05`. For more information, please see [Clerk API Versions](https://clerk.com/docs/backend-requests/versioning/overview).  ### Using the Try It Console  The `Try It` feature of the docs only works for **Development Instances** when using the `DevBrowser` security scheme. To use it, first generate a dev instance token from the `/v1/dev_browser` endpoint.  Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct ClientSession {
16    #[serde(rename = "id")]
17    pub id: String,
18    /// String representing the object's type. Objects of the same type share the same value.
19    #[serde(rename = "object")]
20    pub object: Object,
21    #[serde(rename = "status")]
22    pub status: Status,
23    #[serde(rename = "expire_at")]
24    pub expire_at: i64,
25    #[serde(rename = "abandon_at")]
26    pub abandon_at: i64,
27    #[serde(rename = "last_active_at")]
28    pub last_active_at: i64,
29    #[serde(
30        rename = "last_active_token",
31        default,
32        with = "::serde_with::rust::double_option",
33        skip_serializing_if = "Option::is_none"
34    )]
35    pub last_active_token: Option<Option<Box<models::Token>>>,
36    #[serde(
37        rename = "actor",
38        default,
39        with = "::serde_with::rust::double_option",
40        skip_serializing_if = "Option::is_none"
41    )]
42    pub actor: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
43    #[serde(
44        rename = "tasks",
45        default,
46        with = "::serde_with::rust::double_option",
47        skip_serializing_if = "Option::is_none"
48    )]
49    pub tasks: Option<Option<Vec<models::ClientSessionTask>>>,
50    #[serde(
51        rename = "last_active_organization_id",
52        deserialize_with = "Option::deserialize"
53    )]
54    pub last_active_organization_id: Option<String>,
55    #[serde(rename = "user", skip_serializing_if = "Option::is_none")]
56    pub user: Option<Box<models::ClientUser>>,
57    #[serde(rename = "public_user_data", deserialize_with = "Option::deserialize")]
58    pub public_user_data: Option<serde_json::Value>,
59    /// Each item represents the minutes that have passed since the last time a first or second factor were verified.
60    #[serde(rename = "factor_verification_age")]
61    pub factor_verification_age: Vec<i64>,
62    /// Unix timestamp of creation.
63    #[serde(rename = "created_at")]
64    pub created_at: i64,
65    /// Unix timestamp of last update.
66    #[serde(rename = "updated_at")]
67    pub updated_at: i64,
68}
69
70impl ClientSession {
71    pub fn new(
72        id: String,
73        object: Object,
74        status: Status,
75        expire_at: i64,
76        abandon_at: i64,
77        last_active_at: i64,
78        last_active_organization_id: Option<String>,
79        public_user_data: Option<serde_json::Value>,
80        factor_verification_age: Vec<i64>,
81        created_at: i64,
82        updated_at: i64,
83    ) -> ClientSession {
84        ClientSession {
85            id,
86            object,
87            status,
88            expire_at,
89            abandon_at,
90            last_active_at,
91            last_active_token: None,
92            actor: None,
93            tasks: None,
94            last_active_organization_id,
95            user: None,
96            public_user_data,
97            factor_verification_age,
98            created_at,
99            updated_at,
100        }
101    }
102}
103
104impl From<models::schemas_client_session::SchemasClientSession> for ClientSession {
105    fn from(schemas_client_session: models::schemas_client_session::SchemasClientSession) -> Self {
106        ClientSession::new(
107            schemas_client_session.id,
108            Object::from(schemas_client_session.object),
109            Status::from(schemas_client_session.status),
110            schemas_client_session.expire_at,
111            schemas_client_session.abandon_at,
112            schemas_client_session.last_active_at,
113            schemas_client_session.last_active_organization_id,
114            schemas_client_session.public_user_data,
115            schemas_client_session.factor_verification_age,
116            schemas_client_session.created_at,
117            schemas_client_session.updated_at,
118        )
119    }
120}
121
122/// String representing the object's type. Objects of the same type share the same value.
123#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
124pub enum Object {
125    #[serde(rename = "session")]
126    Session,
127}
128
129impl From<models::schemas_client_session::Object> for Object {
130    fn from(object: models::schemas_client_session::Object) -> Self {
131        match object {
132            models::schemas_client_session::Object::Session => Object::Session,
133        }
134    }
135}
136
137impl Default for Object {
138    fn default() -> Object {
139        Self::Session
140    }
141}
142
143#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
144pub enum Status {
145    #[serde(rename = "active")]
146    Active,
147    #[serde(rename = "revoked")]
148    Revoked,
149    #[serde(rename = "ended")]
150    Ended,
151    #[serde(rename = "expired")]
152    Expired,
153    #[serde(rename = "removed")]
154    Removed,
155    #[serde(rename = "abandoned")]
156    Abandoned,
157    #[serde(rename = "pending")]
158    Pending,
159}
160
161impl From<models::schemas_client_session::Status> for Status {
162    fn from(status: models::schemas_client_session::Status) -> Self {
163        match status {
164            models::schemas_client_session::Status::Active => Status::Active,
165            models::schemas_client_session::Status::Revoked => Status::Revoked,
166            models::schemas_client_session::Status::Ended => Status::Ended,
167            models::schemas_client_session::Status::Expired => Status::Expired,
168            models::schemas_client_session::Status::Removed => Status::Removed,
169            models::schemas_client_session::Status::Abandoned => Status::Abandoned,
170        }
171    }
172}
173
174impl Default for Status {
175    fn default() -> Status {
176        Self::Active
177    }
178}