diff --git a/CHANGELOG.md b/CHANGELOG.md index 73fde8b..cc91d8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ nylas-python Changelog ====================== +Unreleased +---------- +* UAS multi-credential update v6.14.2 ---------- diff --git a/nylas/models/auth.py b/nylas/models/auth.py index 9146796..2246478 100644 --- a/nylas/models/auth.py +++ b/nylas/models/auth.py @@ -47,6 +47,7 @@ class URLForAuthenticationConfig(TypedDict): include_grant_scopes: NotRequired[bool] state: NotRequired[str] login_hint: NotRequired[str] + credential_id: NotRequired[str] class URLForAdminConsentConfig(URLForAuthenticationConfig): diff --git a/nylas/models/connectors.py b/nylas/models/connectors.py index 6ffd5ef..65eb330 100644 --- a/nylas/models/connectors.py +++ b/nylas/models/connectors.py @@ -34,6 +34,7 @@ class BaseCreateConnectorRequest(TypedDict): """ provider: Provider + active_credential_id: NotRequired[str] class GoogleCreateConnectorSettings(TypedDict): @@ -141,6 +142,7 @@ class UpdateConnectorRequest(TypedDict): name: NotRequired[str] settings: NotRequired[Dict[str, Any]] scope: NotRequired[List[str]] + active_credential_id: NotRequired[str] class ListConnectorQueryParams(ListQueryParams): diff --git a/nylas/models/grants.py b/nylas/models/grants.py index 61db3d6..4cae4c1 100644 --- a/nylas/models/grants.py +++ b/nylas/models/grants.py @@ -42,6 +42,7 @@ class Grant: updated_at: Optional[int] = None provider_user_id: Optional[str] = None settings: Optional[Dict[str, Any]] = None + credential_id: Optional[str] = None class CreateGrantRequest(TypedDict): diff --git a/tests/resources/test_auth.py b/tests/resources/test_auth.py index db88ca5..f592de8 100644 --- a/tests/resources/test_auth.py +++ b/tests/resources/test_auth.py @@ -137,6 +137,25 @@ def test_url_for_oauth2(self, http_client): == "https://test.nylas.com/v3/connect/auth?client_id=abc-123&redirect_uri=https%3A//example.com/oauth/callback&scope=email.read_only%20calendar%20contacts&login_hint=test%40gmail.com&provider=google&prompt=select_provider%2Cdetect&state=abc-123-state&response_type=code&access_type=online" ) + def test_url_for_oauth2_with_credential_id(self, http_client): + auth = Auth(http_client) + config = { + "client_id": "abc-123", + "redirect_uri": "https://example.com/oauth/callback", + "scope": ["Mail.Read", "User.Read"], + "login_hint": "test@outlook.com", + "provider": "microsoft", + "state": "abc-123-state", + "credential_id": "cred-abc-123", + } + + url = auth.url_for_oauth2(config) + + assert ( + url + == "https://test.nylas.com/v3/connect/auth?client_id=abc-123&redirect_uri=https%3A//example.com/oauth/callback&scope=Mail.Read%20User.Read&login_hint=test%40outlook.com&provider=microsoft&state=abc-123-state&credential_id=cred-abc-123&response_type=code&access_type=online" + ) + def test_exchange_code_for_token(self, http_client_token_exchange): auth = Auth(http_client_token_exchange) config = { diff --git a/tests/resources/test_connectors.py b/tests/resources/test_connectors.py index fc5c202..b43e362 100644 --- a/tests/resources/test_connectors.py +++ b/tests/resources/test_connectors.py @@ -66,6 +66,28 @@ def test_create_connector(self, http_client_response): "POST", "/v3/connectors", None, None, request_body, overrides=None ) + def test_create_connector_with_active_credential_id(self, http_client_response): + connectors = Connectors(http_client_response) + request_body = { + "provider": "microsoft", + "settings": { + "client_id": "string", + "client_secret": "string", + "tenant": "common", + }, + "scope": [ + "Mail.Read", + "User.Read", + ], + "active_credential_id": "cred-abc-123", + } + + connectors.create(request_body=request_body) + + http_client_response._execute.assert_called_once_with( + "POST", "/v3/connectors", None, None, request_body, overrides=None + ) + def test_update_connector(self, http_client_response): connectors = Connectors(http_client_response) request_body = { @@ -89,6 +111,29 @@ def test_update_connector(self, http_client_response): "PATCH", "/v3/connectors/google", None, None, request_body, overrides=None ) + def test_update_connector_with_active_credential_id(self, http_client_response): + connectors = Connectors(http_client_response) + request_body = { + "settings": { + "client_id": "string", + "client_secret": "string", + }, + "scope": [ + "Mail.Read", + "User.Read", + ], + "active_credential_id": "cred-xyz-789", + } + + connectors.update( + provider="microsoft", + request_body=request_body, + ) + + http_client_response._execute.assert_called_once_with( + "PATCH", "/v3/connectors/microsoft", None, None, request_body, overrides=None + ) + def test_destroy_connector(self, http_client_delete_response): connectors = Connectors(http_client_delete_response) diff --git a/tests/resources/test_grants.py b/tests/resources/test_grants.py index e7d61d3..bcb6e88 100644 --- a/tests/resources/test_grants.py +++ b/tests/resources/test_grants.py @@ -30,6 +30,35 @@ def test_grant_deserialization(self, http_client): assert grant.created_at == 1617817109 assert grant.updated_at == 1617817109 + def test_grant_deserialization_with_credential_id(self, http_client): + grant_json = { + "id": "e19f8e1a-eb1c-41c0-b6a6-d2e59daf7f47", + "provider": "microsoft", + "grant_status": "valid", + "email": "email@example.com", + "scope": ["Mail.Read", "User.Read", "offline_access"], + "user_agent": "string", + "ip": "string", + "state": "my-state", + "created_at": 1617817109, + "updated_at": 1617817109, + "credential_id": "cred-abc-123", + } + + grant = Grant.from_dict(grant_json) + + assert grant.id == "e19f8e1a-eb1c-41c0-b6a6-d2e59daf7f47" + assert grant.provider == "microsoft" + assert grant.grant_status == "valid" + assert grant.email == "email@example.com" + assert grant.scope == ["Mail.Read", "User.Read", "offline_access"] + assert grant.user_agent == "string" + assert grant.ip == "string" + assert grant.state == "my-state" + assert grant.created_at == 1617817109 + assert grant.updated_at == 1617817109 + assert grant.credential_id == "cred-abc-123" + def test_list_grants(self, http_client_list_response): grants = Grants(http_client_list_response)