-
Notifications
You must be signed in to change notification settings - Fork 532
feat(nango): add integration.rs with list/get/create/update/delete endpoints #3712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+168
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| use crate::client::{NangoClient, append_query, check_response, parse_response}; | ||
| use crate::common_derives; | ||
| use crate::connect_session::DataWrapper; | ||
|
|
||
| common_derives! { | ||
| pub struct Integration { | ||
| pub unique_key: String, | ||
| pub display_name: String, | ||
| pub provider: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub logo: Option<String>, | ||
| pub created_at: String, | ||
| pub updated_at: String, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| pub struct IntegrationFull { | ||
| pub unique_key: String, | ||
| pub display_name: String, | ||
| pub provider: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub logo: Option<String>, | ||
| pub created_at: String, | ||
| pub updated_at: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub webhook_url: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub credentials: Option<IntegrationCredentials>, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| #[serde(tag = "type")] | ||
| pub enum IntegrationCredentials { | ||
| #[serde(rename = "OAUTH1")] | ||
| OAuth1 { | ||
| client_id: String, | ||
| client_secret: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| scopes: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| webhook_secret: Option<String>, | ||
| }, | ||
| #[serde(rename = "OAUTH2")] | ||
| OAuth2 { | ||
| client_id: String, | ||
| client_secret: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| scopes: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| webhook_secret: Option<String>, | ||
| }, | ||
| #[serde(rename = "TBA")] | ||
| Tba { | ||
| client_id: String, | ||
| client_secret: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| scopes: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| webhook_secret: Option<String>, | ||
| }, | ||
| #[serde(rename = "APP")] | ||
| App { | ||
| app_id: String, | ||
| app_link: String, | ||
| private_key: String, | ||
| }, | ||
| #[serde(rename = "CUSTOM")] | ||
| Custom { | ||
| client_id: String, | ||
| client_secret: String, | ||
| app_id: String, | ||
| app_link: String, | ||
| private_key: String, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| pub struct CreateIntegrationRequest { | ||
| pub unique_key: String, | ||
| pub provider: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub display_name: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub credentials: Option<IntegrationCredentials>, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| #[derive(Default)] | ||
| pub struct UpdateIntegrationRequest { | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub unique_key: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub display_name: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub credentials: Option<IntegrationCredentials>, | ||
| } | ||
| } | ||
|
|
||
| impl NangoClient { | ||
| pub async fn list_integrations(&self) -> Result<Vec<Integration>, crate::Error> { | ||
| let mut url = self.api_base.clone(); | ||
| url.set_path("/integrations"); | ||
|
|
||
| let response = self.client.get(url).send().await?; | ||
| let wrapper: DataWrapper<Vec<Integration>> = parse_response(response).await?; | ||
| Ok(wrapper.data) | ||
| } | ||
|
|
||
| pub async fn get_integration( | ||
| &self, | ||
| unique_key: impl std::fmt::Display, | ||
| include: &[&str], | ||
| ) -> Result<IntegrationFull, crate::Error> { | ||
| let mut url = self.api_base.clone(); | ||
| url.set_path(&format!("/integrations/{}", unique_key)); | ||
|
|
||
| for item in include { | ||
| append_query(&mut url, "include", item); | ||
| } | ||
|
|
||
| let response = self.client.get(url).send().await?; | ||
| let wrapper: DataWrapper<IntegrationFull> = parse_response(response).await?; | ||
| Ok(wrapper.data) | ||
| } | ||
|
|
||
| pub async fn create_integration( | ||
| &self, | ||
| req: CreateIntegrationRequest, | ||
| ) -> Result<Vec<Integration>, crate::Error> { | ||
| let mut url = self.api_base.clone(); | ||
| url.set_path("/integrations"); | ||
|
|
||
| let response = self.client.post(url).json(&req).send().await?; | ||
| let wrapper: DataWrapper<Vec<Integration>> = parse_response(response).await?; | ||
| Ok(wrapper.data) | ||
| } | ||
|
|
||
| pub async fn update_integration( | ||
| &self, | ||
| unique_key: impl std::fmt::Display, | ||
| req: UpdateIntegrationRequest, | ||
| ) -> Result<Integration, crate::Error> { | ||
| let mut url = self.api_base.clone(); | ||
| url.set_path(&format!("/integrations/{}", unique_key)); | ||
|
|
||
| let response = self.client.patch(url).json(&req).send().await?; | ||
| let wrapper: DataWrapper<Integration> = parse_response(response).await?; | ||
| Ok(wrapper.data) | ||
| } | ||
|
|
||
| pub async fn delete_integration( | ||
| &self, | ||
| unique_key: impl std::fmt::Display, | ||
| ) -> Result<(), crate::Error> { | ||
| let mut url = self.api_base.clone(); | ||
| url.set_path(&format!("/integrations/{}", unique_key)); | ||
|
|
||
| let response = self.client.delete(url).send().await?; | ||
| check_response(response).await?; | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴
create_integrationdeserializes response asVec<Integration>but API returns a single objectThe
create_integrationmethod at line 138 deserializes the response asDataWrapper<Vec<Integration>>, expecting thedatafield to be an array. However, the NangoPOST /integrationsAPI endpoint returns a single integration object in thedatafield ({ data: { ... } }), not an array.Root Cause
All other create/mutate endpoints in this crate return a single object wrapped in
DataWrapper<T>— for example,create_connect_sessionatcrates/nango/src/connect_session.rs:84usesDataWrapper<ConnectSession>, andupdate_integrationat line 151 of the same file usesDataWrapper<Integration>. The Nango API consistently returns{ data: <single_object> }for create operations.Using
DataWrapper<Vec<Integration>>will causeserdedeserialization to fail at runtime with a type mismatch error (expecting array, got object), makingcreate_integrationcompletely non-functional.Impact: Every call to
create_integrationwill fail with a deserialization error, even when the API request itself succeeds.Was this helpful? React with 👍 or 👎 to provide feedback.