Skip to main content

egs_api/facade/
account.rs

1use crate::EpicGames;
2use crate::api::error::EpicAPIError;
3use crate::api::types::account::{AccountData, AccountInfo, ExternalAuth};
4use crate::api::types::asset_info::GameToken;
5use crate::api::types::entitlement::Entitlement;
6use crate::api::types::epic_asset::EpicAsset;
7use crate::api::types::friends::Friend;
8use crate::api::types::library::Library;
9
10impl EpicGames {
11    /// Like [`account_details`](Self::account_details), but returns a `Result` instead of swallowing errors.
12    pub async fn try_account_details(&mut self) -> Result<AccountData, EpicAPIError> {
13        self.egs.account_details().await
14    }
15
16    /// Fetch account details (email, display name, country, 2FA status).
17    ///
18    /// Returns `None` on API errors.
19    pub async fn account_details(&mut self) -> Option<AccountData> {
20        self.try_account_details().await.ok()
21    }
22
23    /// Like [`account_ids_details`](Self::account_ids_details), but returns a `Result` instead of swallowing errors.
24    pub async fn try_account_ids_details(
25        &mut self,
26        ids: Vec<String>,
27    ) -> Result<Vec<AccountInfo>, EpicAPIError> {
28        self.egs.account_ids_details(ids).await
29    }
30
31    /// Bulk lookup of account IDs to display names.
32    ///
33    /// Returns `None` on API errors.
34    pub async fn account_ids_details(&mut self, ids: Vec<String>) -> Option<Vec<AccountInfo>> {
35        self.try_account_ids_details(ids).await.ok()
36    }
37
38    /// Like [`account_friends`](Self::account_friends), but returns a `Result` instead of swallowing errors.
39    pub async fn try_account_friends(
40        &mut self,
41        include_pending: bool,
42    ) -> Result<Vec<Friend>, EpicAPIError> {
43        self.egs.account_friends(include_pending).await
44    }
45
46    /// Fetch friends list (including pending requests if `include_pending` is true).
47    ///
48    /// Returns `None` on API errors.
49    pub async fn account_friends(&mut self, include_pending: bool) -> Option<Vec<Friend>> {
50        self.try_account_friends(include_pending).await.ok()
51    }
52
53    /// Like [`external_auths`](Self::external_auths), but returns a `Result` instead of swallowing errors.
54    pub async fn try_external_auths(
55        &self,
56        account_id: &str,
57    ) -> Result<Vec<ExternalAuth>, EpicAPIError> {
58        self.egs.external_auths(account_id).await
59    }
60
61    /// Fetch external auth connections linked to an account.
62    ///
63    /// Returns linked platform accounts (Steam, PSN, Xbox, Nintendo, etc.)
64    /// with external display names and account IDs. Requires a valid user session.
65    ///
66    /// Returns `None` on API errors.
67    pub async fn external_auths(&self, account_id: &str) -> Option<Vec<ExternalAuth>> {
68        self.try_external_auths(account_id).await.ok()
69    }
70
71    /// Like [`sso_domains`](Self::sso_domains), but returns a `Result` instead of swallowing errors.
72    pub async fn try_sso_domains(&self) -> Result<Vec<String>, EpicAPIError> {
73        self.egs.sso_domains().await
74    }
75
76    /// Fetch the list of SSO (Single Sign-On) domains.
77    ///
78    /// Returns domain strings that support Epic's SSO flow. Used by the
79    /// launcher to determine which domains can share authentication cookies.
80    ///
81    /// Returns `None` on API errors.
82    pub async fn sso_domains(&self) -> Option<Vec<String>> {
83        self.try_sso_domains().await.ok()
84    }
85
86    /// Like [`game_token`](Self::game_token), but returns a `Result` instead of swallowing errors.
87    pub async fn try_game_token(&mut self) -> Result<GameToken, EpicAPIError> {
88        self.egs.game_token().await
89    }
90
91    /// Fetch a short-lived exchange code for game launches.
92    ///
93    /// Returns `None` on API errors.
94    pub async fn game_token(&mut self) -> Option<GameToken> {
95        self.try_game_token().await.ok()
96    }
97
98    /// Like [`ownership_token`](Self::ownership_token), but returns a `Result` instead of swallowing errors.
99    pub async fn try_ownership_token(&mut self, asset: &EpicAsset) -> Result<String, EpicAPIError> {
100        self.egs.ownership_token(asset).await.map(|a| a.token)
101    }
102
103    /// Fetch a JWT proving ownership of an asset.
104    ///
105    /// Returns `None` on API errors.
106    pub async fn ownership_token(&mut self, asset: &EpicAsset) -> Option<String> {
107        self.try_ownership_token(asset).await.ok()
108    }
109
110    /// Like [`user_entitlements`](Self::user_entitlements), but returns a `Result` instead of swallowing errors.
111    pub async fn try_user_entitlements(&mut self) -> Result<Vec<Entitlement>, EpicAPIError> {
112        self.egs.user_entitlements().await
113    }
114
115    /// Fetch all user entitlements (games, DLC, subscriptions).
116    ///
117    /// Returns empty `Vec` on API errors.
118    pub async fn user_entitlements(&mut self) -> Vec<Entitlement> {
119        self.try_user_entitlements()
120            .await
121            .unwrap_or_else(|_| Vec::new())
122    }
123
124    /// Like [`library_items`](Self::library_items), but returns a `Result` instead of swallowing errors.
125    pub async fn try_library_items(
126        &mut self,
127        include_metadata: bool,
128    ) -> Result<Library, EpicAPIError> {
129        self.egs.library_items(include_metadata).await
130    }
131
132    /// Fetch the user library with optional metadata.
133    ///
134    /// Paginates internally and returns all records at once. Returns `None` on API errors.
135    pub async fn library_items(&mut self, include_metadata: bool) -> Option<Library> {
136        self.try_library_items(include_metadata).await.ok()
137    }
138}