11use crate :: apis:: api_key_service_api:: { ApiKeyError , ApiKeyQueryParams , CreateApiKeyParams , UpdateApiKeyParams , ValidateApiKeyParams } ;
22use crate :: apis:: configuration:: Configuration ;
33use crate :: models:: { CreateApiKeyResponse , FetchApiKeyResponse , FetchApiKeysPagedResponse , ValidateApiKeyResponse } ;
4+ use crate :: models:: validate_api_key_response:: { ValidateOrgApiKeyResponse , ValidatePersonalApiKeyResponse } ;
45use crate :: propelauth:: helpers:: map_autogenerated_error;
56
67pub struct ApiKeyService < ' a > {
@@ -22,7 +23,7 @@ impl ApiKeyService<'_> {
2223 bad_request,
2324 ) ) ,
2425 ) => ApiKeyError :: BadRequest ( bad_request) ,
25- ( 401 , _) => ApiKeyError :: InvalidAPIKey ,
26+ ( 401 , _) => ApiKeyError :: InvalidIntegrationAPIKey ,
2627 ( 404 , _) => ApiKeyError :: NotFound ,
2728 _ => ApiKeyError :: UnexpectedExceptionWithSDK ,
2829 } ,
@@ -44,7 +45,7 @@ impl ApiKeyService<'_> {
4445 bad_request,
4546 ) ) ,
4647 ) => ApiKeyError :: BadRequest ( bad_request) ,
47- ( 401 , _) => ApiKeyError :: InvalidAPIKey ,
48+ ( 401 , _) => ApiKeyError :: InvalidIntegrationAPIKey ,
4849 ( 404 , _) => ApiKeyError :: NotFound ,
4950 _ => ApiKeyError :: UnknownError ,
5051 } ,
@@ -60,8 +61,8 @@ impl ApiKeyService<'_> {
6061 err,
6162 ApiKeyError :: UnexpectedExceptionWithSDK ,
6263 |status_code, _| match status_code. as_u16 ( ) {
63- 401 => ApiKeyError :: InvalidAPIKey ,
64- 404 => ApiKeyError :: InvalidEndUserAPIKey ,
64+ 401 => ApiKeyError :: InvalidIntegrationAPIKey ,
65+ 404 => ApiKeyError :: InvalidAPIKey ,
6566 _ => ApiKeyError :: UnknownError ,
6667 } ,
6768 )
@@ -76,7 +77,7 @@ impl ApiKeyService<'_> {
7677 err,
7778 ApiKeyError :: UnexpectedExceptionWithSDK ,
7879 |status_code, _| match status_code. as_u16 ( ) {
79- 401 => ApiKeyError :: InvalidAPIKey ,
80+ 401 => ApiKeyError :: InvalidIntegrationAPIKey ,
8081 404 => ApiKeyError :: NotFound ,
8182 _ => ApiKeyError :: UnknownError ,
8283 } ,
@@ -92,8 +93,8 @@ impl ApiKeyService<'_> {
9293 err,
9394 ApiKeyError :: UnexpectedExceptionWithSDK ,
9495 |status_code, _| match status_code. as_u16 ( ) {
95- 401 => ApiKeyError :: InvalidAPIKey ,
96- 404 => ApiKeyError :: InvalidEndUserAPIKey ,
96+ 401 => ApiKeyError :: InvalidIntegrationAPIKey ,
97+ 404 => ApiKeyError :: InvalidAPIKey ,
9798 _ => ApiKeyError :: UnknownError ,
9899 } ,
99100 )
@@ -110,8 +111,8 @@ impl ApiKeyService<'_> {
110111 err,
111112 ApiKeyError :: UnexpectedExceptionWithSDK ,
112113 |status_code, _| match status_code. as_u16 ( ) {
113- 401 => ApiKeyError :: InvalidAPIKey ,
114- 404 => ApiKeyError :: InvalidEndUserAPIKey ,
114+ 401 => ApiKeyError :: InvalidIntegrationAPIKey ,
115+ 404 => ApiKeyError :: InvalidAPIKey ,
115116 _ => ApiKeyError :: UnknownError ,
116117 } ,
117118 )
@@ -128,11 +129,37 @@ impl ApiKeyService<'_> {
128129 err,
129130 ApiKeyError :: UnexpectedExceptionWithSDK ,
130131 |status_code, _| match status_code. as_u16 ( ) {
131- 401 => ApiKeyError :: InvalidAPIKey ,
132+ 401 => ApiKeyError :: InvalidIntegrationAPIKey ,
132133 404 => ApiKeyError :: NotFound ,
133134 _ => ApiKeyError :: UnknownError ,
134135 } ,
135136 )
136137 } )
137138 }
139+
140+ pub async fn validate_personal_api_key ( & self , params : ValidateApiKeyParams ) -> Result < ValidatePersonalApiKeyResponse , ApiKeyError > {
141+ let resp = self . validate_api_key ( params) . await ?;
142+ if resp. user_metadata . is_none ( ) || resp. org_metadata . is_some ( ) {
143+ return Err ( ApiKeyError :: InvalidPersonalAPIKey ) ;
144+ }
145+
146+ Ok ( ValidatePersonalApiKeyResponse {
147+ metadata : resp. metadata ,
148+ user_metadata : resp. user_metadata . unwrap ( ) ,
149+ } )
150+ }
151+
152+ pub async fn validate_org_api_key ( & self , params : ValidateApiKeyParams ) -> Result < ValidateOrgApiKeyResponse , ApiKeyError > {
153+ let resp = self . validate_api_key ( params) . await ?;
154+ if resp. org_metadata . is_none ( ) {
155+ return Err ( ApiKeyError :: InvalidOrgAPIKey ) ;
156+ }
157+
158+ Ok ( ValidateOrgApiKeyResponse {
159+ metadata : resp. metadata ,
160+ user_metadata : resp. user_metadata ,
161+ org_metadata : resp. org_metadata . unwrap ( ) ,
162+ user_role_in_org : resp. user_role_in_org ,
163+ } )
164+ }
138165}
0 commit comments