konecty_sdk_python 2.1.1__py3-none-any.whl → 2.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,12 +31,15 @@ logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR)
31
31
 
32
32
  logger = logging.getLogger(__name__)
33
33
 
34
+ # `_updatedBy` is NOT stripped: the backend accepts it on update as an explicit
35
+ # authorship override for admin callers (automations crediting a write to the user
36
+ # it acted on behalf of). Non-admin callers have it ignored server-side, so letting
37
+ # it through costs nothing. See "Autoria da escrita" in docs/pt-BR/api.md (konecty/Konecty).
34
38
  KONECTY_UPDATE_IGNORE_FIELDS = [
35
39
  "_id",
36
40
  "code",
37
41
  "_updatedAt",
38
42
  "_createdAt",
39
- "_updatedBy",
40
43
  "_createdBy",
41
44
  ]
42
45
  KONECTY_CREATE_IGNORE_FIELDS = ["_updatedAt", "_createdAt", "_updatedBy", "_createdBy"]
@@ -13,6 +13,22 @@ class KonectyAPIError(KonectyError):
13
13
  pass
14
14
 
15
15
 
16
+ class KonectyGoogleSessionError(KonectyAPIError):
17
+ """
18
+ Raised by exchange_google_code. Carries the machine-readable ``code`` from
19
+ ``errors[0].code`` so callers can branch or translate without parsing the
20
+ message; ``failed`` covers unreadable or unrecognised bodies.
21
+
22
+ Subclasses KonectyAPIError so existing ``except KonectyAPIError`` keeps working.
23
+
24
+ Mirrors KonectyGoogleSessionError in the TypeScript SDK — keep both in sync.
25
+ """
26
+
27
+ def __init__(self, code: str, message: str) -> None:
28
+ super().__init__(message)
29
+ self.code = code
30
+
31
+
16
32
  class KonectyValidationError(KonectyError):
17
33
  """Raised for validation errors."""
18
34
 
@@ -3,7 +3,7 @@
3
3
  from typing import Any, Dict, Optional, Union
4
4
  from urllib.parse import quote, urlencode
5
5
 
6
- from ..exceptions import KonectyAPIError
6
+ from ..exceptions import KonectyAPIError, KonectyGoogleSessionError
7
7
  from .base import BaseService
8
8
 
9
9
  GOOGLE_START_PATH = "/api/auth/google/start"
@@ -15,6 +15,29 @@ GOOGLE_SESSION_PATH = "/api/auth/google/session"
15
15
  LOGIN_OPTIONS_PATH = "/api/auth/login-options"
16
16
 
17
17
 
18
+ _GOOGLE_SESSION_ERROR_CODES = (
19
+ "invalid_code",
20
+ "expired_code",
21
+ "user_not_found",
22
+ "user_inactive",
23
+ )
24
+
25
+
26
+ def _first_error_code(error: KonectyAPIError) -> str:
27
+ """
28
+ Extract the first recognised ``errors[].code``; ``failed`` when there is none.
29
+
30
+ Same set and same fallback as the TypeScript SDK, so both raise the same code
31
+ for the same response.
32
+ """
33
+ errors = error.args[0] if error.args else None
34
+ if isinstance(errors, list):
35
+ for item in errors:
36
+ if isinstance(item, dict) and item.get("code") in _GOOGLE_SESSION_ERROR_CODES:
37
+ return str(item["code"])
38
+ return "failed"
39
+
40
+
18
41
  def _first_error_message(error: KonectyAPIError) -> str:
19
42
  """Extract errors[0].message from a KonectyAPIError raised by the HTTP layer."""
20
43
  errors = error.args[0] if error.args else None
@@ -74,8 +97,10 @@ class AuthService(BaseService):
74
97
  POST /api/auth/google/session. Exchanges the single-use code (TTL 60s) for a session.
75
98
 
76
99
  On success the returned authId is adopted by the client, so following requests
77
- are authenticated. On error raises KonectyAPIError with errors[0].message and
78
- leaves the client authentication state untouched.
100
+ are authenticated. On error raises KonectyGoogleSessionError — errors[0].message
101
+ as the message plus the machine-readable ``code`` — and leaves the client
102
+ authentication state untouched. The error subclasses KonectyAPIError, so callers
103
+ catching that keep working.
79
104
  """
80
105
  payload: Dict[str, Any] = {"code": code}
81
106
  if geolocation is not None:
@@ -90,11 +115,15 @@ class AuthService(BaseService):
90
115
  try:
91
116
  response = await self._post(GOOGLE_SESSION_PATH, json=payload)
92
117
  except KonectyAPIError as error:
93
- raise KonectyAPIError(_first_error_message(error)) from error
118
+ raise KonectyGoogleSessionError(
119
+ _first_error_code(error), _first_error_message(error)
120
+ ) from error
94
121
 
95
122
  auth_id = response.get("authId") if isinstance(response, dict) else None
96
123
  if not isinstance(auth_id, str) or not auth_id:
97
- raise KonectyAPIError("Google session response has no authId")
124
+ raise KonectyGoogleSessionError(
125
+ "failed", "Google session response has no authId"
126
+ )
98
127
 
99
128
  self._client.set_auth_id(auth_id)
100
129
  return response
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: konecty_sdk_python
3
- Version: 2.1.1
3
+ Version: 2.1.3
4
4
  Summary: Konecty SDK Python
5
5
  Author-email: Leonardo Leal <leonardo.leal@konecty.com>, Derotino Silveira <derotino.silveira@konecty.com>
6
6
  License: MIT
@@ -4,8 +4,8 @@ KonectySdkPython/cli/apply.py,sha256=LyPoNcsU3oz9P_eTAi4BdtJHWkbp-sNK_SP9W8Xua04
4
4
  KonectySdkPython/cli/backup.py,sha256=rcla3EWfPsy-vWgmDK844EaM5u3h7JF-u7-b2HUBMgA,4785
5
5
  KonectySdkPython/cli/pull.py,sha256=n4gIkKtuEpPKULb3zcYu5tZlBLbt_4oNQDeu2l6tHxU,9529
6
6
  KonectySdkPython/lib/__init__.py,sha256=Du8jLNfFG1bQuHX5u7pAhbyV9TjC7Ie9K1Xo1KSUqqc,995
7
- KonectySdkPython/lib/client.py,sha256=i-7goKqsH-jvwxZfGeipTRFByOBAOhMHkuhjjdEN3kE,34034
8
- KonectySdkPython/lib/exceptions.py,sha256=HR48cd-cptFPoObr37NcvDrdkb-RtxKRteQoG-tuPkk,529
7
+ KonectySdkPython/lib/client.py,sha256=xq89t3y79IB2nl407tWUYyNqiu4I0zCWpm5ew_wuMtA,34356
8
+ KonectySdkPython/lib/exceptions.py,sha256=RQ6H_zgbF8yeII1F75wCIEJ1LfO4lWfY5hnK30cwETY,1107
9
9
  KonectySdkPython/lib/file_manager.py,sha256=CLpOJWdA1tb2iq0qOIeRyEEIuACRq9tIo7Rls1YT2ig,9986
10
10
  KonectySdkPython/lib/filters.py,sha256=PsFaUFCEyKgxgzD566LdTLvuMJevoF_i9U1WnpJZzPQ,4482
11
11
  KonectySdkPython/lib/http.py,sha256=atwyuKSFniulvAspi_VhinUhtPJGNyZYkIkaEgqfIqo,3377
@@ -19,7 +19,7 @@ KonectySdkPython/lib/feature_types/kpi.py,sha256=67RpwwwnzU8piIPRyFb6Kn0hqSRpT9R
19
19
  KonectySdkPython/lib/feature_types/query_json.py,sha256=yZgMPmkMdiBLm-dIrmU1AeZe5G9zQLwLtKUPMb7IOhU,8139
20
20
  KonectySdkPython/lib/services/__init__.py,sha256=fluQuxs6LnIZwcjYTuKNeXCFTKuNF3At3X19fIB68p8,121
21
21
  KonectySdkPython/lib/services/aggregation.py,sha256=igK1mleMFU2_rDQCAU1yKyvDoOjhTO1SO0Nn4T_DokA,5610
22
- KonectySdkPython/lib/services/auth.py,sha256=JFiOvk0cqwRucvDQCN93jmKvSITxGtFYW1ME0gdEkMk,4226
22
+ KonectySdkPython/lib/services/auth.py,sha256=seb2QgdeWT_ALcVLR8bDMgO1ycI9dz75OhuIjahzy7o,5173
23
23
  KonectySdkPython/lib/services/base.py,sha256=tdVyWb7Y77cBhVc8Mz2BQMN6kAyZIohoxBxdwDnRsYs,1820
24
24
  KonectySdkPython/lib/services/change_user.py,sha256=ce6mcDYMP6eWxW0bEtzlVf7wbppGHCkGwdgo2jJFJOQ,2548
25
25
  KonectySdkPython/lib/services/comments.py,sha256=RNevCg4de2FWNk7mD60-pk3r8f2sJ1NLoolD2iNMidg,3033
@@ -29,7 +29,7 @@ KonectySdkPython/lib/services/notifications.py,sha256=7AtCBbBl-YAz_RBIW6bzoKvuws
29
29
  KonectySdkPython/lib/services/query.py,sha256=vCqbf0QdV8Blh8Hfsvq6Ne1-YFuC5siw1gVa7ZBGs_k,6605
30
30
  KonectySdkPython/lib/services/stream.py,sha256=1DMVxcg9Ymk2NgX0Qfvpjrr6vZJo5iFovPFT1NA3_CY,4737
31
31
  KonectySdkPython/lib/services/subscriptions.py,sha256=_Jq8jW7YkL_hwLNte1bWgrr4D2EMZUUSOXUgnRoGGK4,1022
32
- konecty_sdk_python-2.1.1.dist-info/METADATA,sha256=zK3rmKw6vnfQNOLXQWJSjqj5pKmGxOOfmlABHsMeDcs,5442
33
- konecty_sdk_python-2.1.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
34
- konecty_sdk_python-2.1.1.dist-info/entry_points.txt,sha256=awf962DamFgy791G3PsJ354edBMLJg16Dqi-2Y1tb9s,58
35
- konecty_sdk_python-2.1.1.dist-info/RECORD,,
32
+ konecty_sdk_python-2.1.3.dist-info/METADATA,sha256=-X2txZP8kfSzfXxRnPTECpKiMof6-GGfmIkDVktyxi4,5442
33
+ konecty_sdk_python-2.1.3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
34
+ konecty_sdk_python-2.1.3.dist-info/entry_points.txt,sha256=awf962DamFgy791G3PsJ354edBMLJg16Dqi-2Y1tb9s,58
35
+ konecty_sdk_python-2.1.3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.31.0
2
+ Generator: hatchling 1.32.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any