1pub struct IdentityService<'a> {
2 client: &'a crate::core::ImClient,
3}
4
5impl<'a> IdentityService<'a> {
6 pub(crate) fn new(client: &'a crate::core::ImClient) -> Self {
7 Self { client }
8 }
9
10 pub fn profile(&self) -> crate::ImResult<super::Profile> {
11 self.profile_with_runtime(
12 crate::internal::auth::session::FileSessionProvider::new(self.client),
13 crate::internal::transport::CoreHttpTransport::new(self.client),
14 )
15 .map(|result| result.profile)
16 }
17
18 pub async fn profile_async(&self) -> crate::ImResult<super::Profile> {
19 self.profile_with_runtime_async(
20 crate::internal::auth::session::FileSessionProvider::new(self.client),
21 crate::internal::transport::CoreHttpTransport::new(self.client),
22 )
23 .await
24 .map(|result| result.profile)
25 }
26
27 pub(crate) fn profile_with_runtime<P, T>(
28 &self,
29 session_provider: P,
30 transport: T,
31 ) -> crate::ImResult<crate::internal::profile_runtime::ProfileReadResult>
32 where
33 P: crate::internal::auth::session::SessionProvider,
34 T: crate::internal::transport::AuthenticatedRpcTransport,
35 {
36 crate::internal::profile_runtime::ProfileReader::new(
37 self.client,
38 session_provider,
39 transport,
40 )
41 .profile()
42 }
43
44 pub(crate) async fn profile_with_runtime_async<P, T>(
45 &self,
46 session_provider: P,
47 transport: T,
48 ) -> crate::ImResult<crate::internal::profile_runtime::ProfileReadResult>
49 where
50 P: crate::internal::auth::session::AsyncSessionProvider,
51 T: crate::internal::transport::AsyncAuthenticatedRpcTransport,
52 {
53 crate::internal::profile_runtime::ProfileReader::new(
54 self.client,
55 session_provider,
56 transport,
57 )
58 .profile_async()
59 .await
60 }
61
62 pub fn update_profile(&self, patch: super::ProfilePatch) -> crate::ImResult<super::Profile> {
63 super::profile::validate_profile_patch(&patch)?;
64 self.update_profile_with_runtime(
65 patch,
66 crate::internal::auth::session::FileSessionProvider::new(self.client),
67 crate::internal::transport::CoreHttpTransport::new(self.client),
68 )
69 .map(|result| result.profile)
70 }
71
72 pub async fn update_profile_async(
73 &self,
74 patch: super::ProfilePatch,
75 ) -> crate::ImResult<super::Profile> {
76 super::profile::validate_profile_patch(&patch)?;
77 self.update_profile_with_runtime_async(
78 patch,
79 crate::internal::auth::session::FileSessionProvider::new(self.client),
80 crate::internal::transport::CoreHttpTransport::new(self.client),
81 )
82 .await
83 .map(|result| result.profile)
84 }
85
86 pub(crate) fn update_profile_with_runtime<P, T>(
87 &self,
88 patch: super::ProfilePatch,
89 session_provider: P,
90 transport: T,
91 ) -> crate::ImResult<crate::internal::profile_runtime::ProfileUpdateResult>
92 where
93 P: crate::internal::auth::session::SessionProvider,
94 T: crate::internal::transport::AuthenticatedRpcTransport,
95 {
96 super::profile::validate_profile_patch(&patch)?;
97 crate::internal::profile_runtime::ProfileReader::new(
98 self.client,
99 session_provider,
100 transport,
101 )
102 .update_profile(patch)
103 }
104
105 pub(crate) async fn update_profile_with_runtime_async<P, T>(
106 &self,
107 patch: super::ProfilePatch,
108 session_provider: P,
109 transport: T,
110 ) -> crate::ImResult<crate::internal::profile_runtime::ProfileUpdateResult>
111 where
112 P: crate::internal::auth::session::AsyncSessionProvider,
113 T: crate::internal::transport::AsyncAuthenticatedRpcTransport,
114 {
115 super::profile::validate_profile_patch(&patch)?;
116 crate::internal::profile_runtime::ProfileReader::new(
117 self.client,
118 session_provider,
119 transport,
120 )
121 .update_profile_async(patch)
122 .await
123 }
124
125 pub fn bind_contact(
126 &self,
127 request: super::ContactBindingRequest,
128 ) -> crate::ImResult<super::ContactBindingResult> {
129 crate::internal::identity_bind_runtime::validate_request(&request)?;
130 self.bind_contact_with_runtime(
131 request,
132 crate::internal::auth::session::FileSessionProvider::new(self.client),
133 crate::internal::transport::CoreHttpTransport::new(self.client),
134 )
135 .map(|result| result.sdk_result)
136 }
137
138 pub async fn bind_contact_async(
139 &self,
140 request: super::ContactBindingRequest,
141 ) -> crate::ImResult<super::ContactBindingResult> {
142 crate::internal::identity_bind_runtime::validate_request(&request)?;
143 self.bind_contact_with_runtime_async(
144 request,
145 crate::internal::auth::session::FileSessionProvider::new(self.client),
146 crate::internal::transport::CoreHttpTransport::new(self.client),
147 )
148 .await
149 .map(|result| result.sdk_result)
150 }
151
152 pub fn bind_email_status(&self, email: String) -> crate::ImResult<super::ContactBindingResult> {
153 self.bind_email_status_with_runtime(
154 email,
155 crate::internal::auth::session::FileSessionProvider::new(self.client),
156 crate::internal::transport::CoreHttpTransport::new(self.client),
157 )
158 .map(|result| result.sdk_result)
159 }
160
161 pub async fn bind_email_status_async(
162 &self,
163 email: String,
164 ) -> crate::ImResult<super::ContactBindingResult> {
165 self.bind_email_status_with_runtime_async(
166 email,
167 crate::internal::auth::session::FileSessionProvider::new(self.client),
168 crate::internal::transport::CoreHttpTransport::new(self.client),
169 )
170 .await
171 .map(|result| result.sdk_result)
172 }
173
174 pub(crate) fn bind_contact_with_runtime<P, T>(
175 &self,
176 request: super::ContactBindingRequest,
177 session_provider: P,
178 transport: T,
179 ) -> crate::ImResult<crate::internal::identity_bind_runtime::ContactBindingRuntimeResult>
180 where
181 P: crate::internal::auth::session::SessionProvider,
182 T: crate::internal::transport::AuthenticatedRestTransport,
183 {
184 crate::internal::identity_bind_runtime::ContactBindingRuntime::new(
185 self.client,
186 session_provider,
187 transport,
188 )
189 .bind_contact(request)
190 }
191
192 pub(crate) async fn bind_contact_with_runtime_async<P, T>(
193 &self,
194 request: super::ContactBindingRequest,
195 session_provider: P,
196 transport: T,
197 ) -> crate::ImResult<crate::internal::identity_bind_runtime::ContactBindingRuntimeResult>
198 where
199 P: crate::internal::auth::session::AsyncSessionProvider,
200 T: crate::internal::transport::AsyncAuthenticatedRestTransport,
201 {
202 crate::internal::identity_bind_runtime::ContactBindingRuntime::new(
203 self.client,
204 session_provider,
205 transport,
206 )
207 .bind_contact_async(request)
208 .await
209 }
210
211 pub(crate) fn bind_email_status_with_runtime<P, T>(
212 &self,
213 email: String,
214 session_provider: P,
215 transport: T,
216 ) -> crate::ImResult<crate::internal::identity_bind_runtime::ContactBindingRuntimeResult>
217 where
218 P: crate::internal::auth::session::SessionProvider,
219 T: crate::internal::transport::AuthenticatedRestTransport,
220 {
221 crate::internal::identity_bind_runtime::ContactBindingRuntime::new(
222 self.client,
223 session_provider,
224 transport,
225 )
226 .email_status(email)
227 }
228
229 pub(crate) async fn bind_email_status_with_runtime_async<P, T>(
230 &self,
231 email: String,
232 session_provider: P,
233 transport: T,
234 ) -> crate::ImResult<crate::internal::identity_bind_runtime::ContactBindingRuntimeResult>
235 where
236 P: crate::internal::auth::session::AsyncSessionProvider,
237 T: crate::internal::transport::AsyncAuthenticatedRestTransport,
238 {
239 crate::internal::identity_bind_runtime::ContactBindingRuntime::new(
240 self.client,
241 session_provider,
242 transport,
243 )
244 .email_status_async(email)
245 .await
246 }
247
248 pub fn replace_did_plan(
249 &self,
250 request: super::ReplaceDidPlanRequest,
251 ) -> crate::ImResult<super::ReplaceDidPlan> {
252 crate::internal::identity_replace_did_plan::plan_replace_did_for_client(
253 self.client,
254 request,
255 )
256 }
257
258 pub async fn replace_did_plan_async(
259 &self,
260 request: super::ReplaceDidPlanRequest,
261 ) -> crate::ImResult<super::ReplaceDidPlan> {
262 let client = self.client.clone();
263 crate::internal::runtime::worker::run_blocking(move || {
264 crate::internal::identity_replace_did_plan::plan_replace_did_for_client(
265 &client, request,
266 )
267 })
268 .await
269 .map_err(|err| crate::ImError::Internal {
270 message: err.to_string(),
271 })?
272 }
273
274 pub(crate) fn replace_did_with_runtime<B>(
275 &self,
276 request: super::ReplaceDidExecutionRequest,
277 bridge: B,
278 ) -> crate::ImResult<super::ReplaceDidExecutionResult>
279 where
280 B: crate::internal::identity_replace_did_execution::ReplaceDidExecutionBridge,
281 {
282 crate::internal::identity_replace_did_execution::ReplaceDidExecutionRuntime::new(
283 self.client,
284 bridge,
285 )
286 .execute(request)
287 }
288}