finatic-server-python 1.0.7__py3-none-any.whl → 1.0.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: finatic-server-python
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary: Python SDK for Finatic Server API
5
5
  Project-URL: Homepage, https://github.com/FinaticORG/FinaticServerSDK-Python
6
6
  Project-URL: Documentation, https://docs.finatic.com/python
@@ -82,7 +82,7 @@ async def main() -> None:
82
82
  # After account.grant.created, start a session for that portal user, then read.
83
83
  portal_user_id = "user-from-connect-onSuccess"
84
84
  authed = await finatic.v1.start_session(user_id=portal_user_id)
85
- if not authed.get("session_id"):
85
+ if not authed.get("authenticated"):
86
86
  raise RuntimeError(authed.get("error") or "Authenticated session start failed")
87
87
  accounts = await finatic.v1.list_accounts(include_sync_status=True)
88
88
  if accounts.get("errors"):
@@ -111,6 +111,13 @@ Connect UI lives in **FinaticConnect**. This SDK does not open an iframe.
111
111
 
112
112
  Wait for HTTPS webhook `account.grant.created` (or poll `list_accounts` on an ACTIVE session) before account-scoped reads.
113
113
 
114
+ `start_session()` reports transport/session-start completion in `success` and
115
+ account readiness separately in `authenticated`. Account reads require
116
+ `authenticated=true`, which is returned only for an `active` session carrying
117
+ the server-authoritative `user_id`. The result also exposes `status`,
118
+ `provided_user_id_rejected`, and `portal_connection_management_pending` for
119
+ portal-flow handling.
120
+
114
121
  ## Trading
115
122
 
116
123
  Fetch the broker schema, then send an idempotent command:
@@ -2,13 +2,13 @@ finatic_server/__init__.py,sha256=4kk4SVN6YPa8g371MGc7jWoypOAn9YGwBDvJqLvQeqM,95
2
2
  finatic_server_python/__init__.py,sha256=LB4GcHvm7rEvldM1iqzVqYrJ4WDSQR5-AEd5Kj3uDLw,1082
3
3
  src/.openapi-generator-ignore,sha256=43VbPbcl7Kuqn8_Q0-Yt8syPgWNXrnOzS7qiFkxJw8Y,677
4
4
  src/FinaticServer.py,sha256=5FqaZEm21BNZeos-QMCTPDv3rWq4XWr9DGUU7K7M53k,238
5
- src/FinaticServerCore.py,sha256=hsunqG9ligZGEdqnkma1mki7TwHiEY7JRaQ0qJCwtaI,2704
6
- src/__init__.py,sha256=JjSrGrR3toIfaKHY2vrCO1uVP5ovh82dT4x4r9-dlAQ,980
5
+ src/FinaticServerCore.py,sha256=ecah0NDKHeO1d0sobe5Gpc8LZXjUz4p7ry5_L_3Q1os,2939
6
+ src/__init__.py,sha256=BS5vPhm0su2ol_CIzfLL6VhvbReGY6OIt_AYaDZJzPc,1205
7
7
  src/config.py,sha256=X10rF_jr-VlwiTAaHNIJZJ97q4932PoRKZW-P90j44M,2412
8
8
  src/finatic_fdx_typed_dicts.py,sha256=qI--a06hO53Lm0TMlHaLckMynhCcbaXh77hslyx1gd8,6383
9
9
  src/finatic_fdx_types.py,sha256=GXZi1ALPsn3p4XgRYb1wf_cIjjux_GzjQPNAXkZ9mRU,1865
10
10
  src/types.py,sha256=qYKqx95w5CjiXzMLk-GnojxQ8qsKxrMaY_XKiO7l49Q,712
11
- src/v1.py,sha256=VOto5gwBHwymbOYi3MlDSQC_Avp4nTm-yWyh5WxEMkI,28220
11
+ src/v1.py,sha256=C24MnPABmWFFHbi3f__62T5Dmj-NHkKBOxwZQjIXFlc,30336
12
12
  src/internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  src/openapi/.openapi-generator-ignore,sha256=43VbPbcl7Kuqn8_Q0-Yt8syPgWNXrnOzS7qiFkxJw8Y,677
14
14
  src/openapi/path_bootstrap.py,sha256=ywVDEDRhAEs9aqmchRETHPOONaGg5lV4U05CDsaMyxY,622
@@ -444,7 +444,7 @@ src/utils/request_id.py,sha256=R_Gcyc5rih7_keAruJHW0bg0Y0MCqQNsUgkZ4C_9sRc,200
444
444
  src/utils/url_utils.py,sha256=dtxaFEF6Li_lQ7ft0BEDsbyYUDcNXUN4WO_yVAG5MJ8,5051
445
445
  src/utils/validation.py,sha256=ODt5raui4KVH1Iz_-Tt8-VKEw-yUzIZg6o93iWLwRj0,1263
446
446
  src/wrappers/__init__.py,sha256=8puRg8uOrUR42gCwCtW5zkOtCDbgyMpZSMi2iz2bPcU,123
447
- finatic_server_python-1.0.7.dist-info/METADATA,sha256=GIcI0ZxwpViIuefxxxK90iUGT9SuMehZj4lBBn2J_5c,7725
448
- finatic_server_python-1.0.7.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
449
- finatic_server_python-1.0.7.dist-info/licenses/LICENSE,sha256=hE35tOCe7uZCeYglYc-sjRSjad4jPyB3i53-QW1YfLk,3590
450
- finatic_server_python-1.0.7.dist-info/RECORD,,
447
+ finatic_server_python-1.0.8.dist-info/METADATA,sha256=iKF00nhRfksr5nN_kfRarJZzSxrUVP_pj5uEGDY-u1A,8124
448
+ finatic_server_python-1.0.8.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
449
+ finatic_server_python-1.0.8.dist-info/licenses/LICENSE,sha256=hE35tOCe7uZCeYglYc-sjRSjad4jPyB3i53-QW1YfLk,3590
450
+ finatic_server_python-1.0.8.dist-info/RECORD,,
src/FinaticServerCore.py CHANGED
@@ -74,6 +74,11 @@ class FinaticServer:
74
74
  "/api/v1/session/init + /start responses."
75
75
  )
76
76
  raise ValueError(str(error_message))
77
+ if user_id is not None and not session_result.get("authenticated"):
78
+ raise ValueError(
79
+ "Session initialization failed: requested user identity was not "
80
+ "authenticated."
81
+ )
77
82
  if not instance.v1.get_session_id():
78
83
  raise ValueError("Session initialization failed: missing session_id.")
79
84
  return instance
src/__init__.py CHANGED
@@ -7,11 +7,6 @@ try:
7
7
  except ModuleNotFoundError:
8
8
  pass
9
9
 
10
- try:
11
- from .v1 import AccountOrderCommand, V1Client
12
- except ModuleNotFoundError:
13
- pass
14
-
15
10
  try:
16
11
  from .finatic_fdx_types import (
17
12
  AccountOrderPayload,
@@ -39,3 +34,15 @@ try:
39
34
  from finatic_server import * # type: ignore[F401,F403]
40
35
  except ModuleNotFoundError:
41
36
  pass
37
+
38
+ # Bind the hand-written facade exports after the generated wildcard import so
39
+ # generated model names cannot replace the public v1 contract aliases.
40
+ try:
41
+ from .v1 import (
42
+ AccountOrderCommand,
43
+ SessionStartResult,
44
+ SessionStatus,
45
+ V1Client,
46
+ )
47
+ except ModuleNotFoundError:
48
+ pass
src/v1.py CHANGED
@@ -10,7 +10,7 @@ import inspect
10
10
  import json
11
11
  from collections.abc import Mapping
12
12
  from dataclasses import dataclass
13
- from typing import Any, Literal, cast
13
+ from typing import Any, Literal, TypedDict, cast
14
14
  from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
15
15
 
16
16
  from finatic_server.api_client import ApiClient
@@ -34,6 +34,36 @@ from .utils.url_utils import (
34
34
  )
35
35
 
36
36
  Environment = str
37
+ SessionStatus = Literal[
38
+ "pending",
39
+ "authenticating",
40
+ "active",
41
+ "completed",
42
+ "expired",
43
+ ]
44
+ _SESSION_STATUSES: set[str] = {
45
+ "pending",
46
+ "authenticating",
47
+ "active",
48
+ "completed",
49
+ "expired",
50
+ }
51
+
52
+
53
+ class SessionStartResult(TypedDict):
54
+ """Normalized result for every public session-start attempt."""
55
+
56
+ success: bool
57
+ session_id: str | None
58
+ company_id: str | None
59
+ error: str | None
60
+ status: SessionStatus | None
61
+ user_id: str | None
62
+ provided_user_id_rejected: bool
63
+ portal_connection_management_pending: bool
64
+ authenticated: bool
65
+
66
+
37
67
  _ERROR_CODE_BY_STATUS = {
38
68
  400: "VALIDATION",
39
69
  401: "AUTHENTICATION",
@@ -73,6 +103,39 @@ def _read_session_field(data: dict[str, Any] | None, keys: tuple[str, ...]) -> s
73
103
  return ""
74
104
 
75
105
 
106
+ def _read_session_status(
107
+ data: dict[str, Any] | None, keys: tuple[str, ...]
108
+ ) -> SessionStatus | None:
109
+ value = _read_session_field(data, keys)
110
+ if value not in _SESSION_STATUSES:
111
+ return None
112
+ return cast(SessionStatus, value)
113
+
114
+
115
+ def _read_session_bool(data: dict[str, Any] | None, keys: tuple[str, ...]) -> bool:
116
+ if not data:
117
+ return False
118
+ for key in keys:
119
+ if key in data:
120
+ value = data[key]
121
+ return value if type(value) is bool else False
122
+ return False
123
+
124
+
125
+ def _failed_session_start(error: str) -> SessionStartResult:
126
+ return {
127
+ "success": False,
128
+ "session_id": None,
129
+ "company_id": None,
130
+ "error": error,
131
+ "status": None,
132
+ "user_id": None,
133
+ "provided_user_id_rejected": False,
134
+ "portal_connection_management_pending": False,
135
+ "authenticated": False,
136
+ }
137
+
138
+
76
139
  def _append_query_param(url: str, name: str, value: str) -> str:
77
140
  parsed = urlparse(url)
78
141
  query_params = parse_qs(parsed.query)
@@ -100,6 +163,8 @@ class V1Client:
100
163
  self.authorization: str | None = None
101
164
  self.csrf_token: str | None = None
102
165
  self.user_id: str | None = None
166
+ self.session_status: SessionStatus | None = None
167
+ self.authenticated = False
103
168
 
104
169
  def set_environment(self, environment: Environment) -> None:
105
170
  """Set the public v1 environment for subsequent requests."""
@@ -129,7 +194,7 @@ class V1Client:
129
194
  return self.user_id
130
195
 
131
196
  def is_authed(self) -> bool:
132
- return bool(self.user_id)
197
+ return self.authenticated
133
198
 
134
199
  async def init_session(self, api_key: str | None = None) -> FinaticResponse:
135
200
  return await self._request(
@@ -170,38 +235,24 @@ class V1Client:
170
235
  *,
171
236
  one_time_token: str | None = None,
172
237
  user_id: str | None = None,
173
- ) -> dict[str, Any]:
238
+ ) -> SessionStartResult:
174
239
  if not one_time_token:
175
240
  if not self.api_key:
176
- return {
177
- "success": False,
178
- "session_id": None,
179
- "company_id": None,
180
- "error": "API key is required in the constructor.",
181
- }
241
+ return _failed_session_start("API key is required in the constructor.")
182
242
  try:
183
- token = await self.get_token()
184
- started = await self._start_session_with_token(token, user_id)
185
- return {
186
- "success": True,
187
- "session_id": started["session_id"],
188
- "company_id": started["company_id"],
189
- "error": None,
190
- }
243
+ one_time_token = await self.get_token()
191
244
  except Exception as error:
192
- return {
193
- "success": False,
194
- "session_id": None,
195
- "company_id": None,
196
- "error": str(error),
197
- }
198
- return await self._start_session_with_token(one_time_token, user_id)
245
+ return _failed_session_start(str(error))
246
+ try:
247
+ return await self._start_session_with_token(one_time_token, user_id)
248
+ except Exception as error:
249
+ return _failed_session_start(str(error))
199
250
 
200
251
  async def _start_session_with_token(
201
252
  self,
202
253
  one_time_token: str,
203
254
  user_id: str | None = None,
204
- ) -> dict[str, str]:
255
+ ) -> SessionStartResult:
205
256
  body = {"user_id": user_id} if user_id else None
206
257
  response = await self._request(
207
258
  "POST",
@@ -220,15 +271,40 @@ class V1Client:
220
271
  company_id = _read_session_field(session_data_dict, ("company_id", "companyId"))
221
272
  csrf_token = _read_session_field(session_data_dict, ("csrf_token", "csrfToken"))
222
273
  response_user_id = _read_session_field(session_data_dict, ("user_id", "userId"))
274
+ status = _read_session_status(session_data_dict, ("status",))
275
+ provided_user_id_rejected = _read_session_bool(
276
+ session_data_dict,
277
+ ("provided_user_id_rejected", "providedUserIdRejected"),
278
+ )
279
+ portal_connection_management_pending = _read_session_bool(
280
+ session_data_dict,
281
+ (
282
+ "portal_connection_management_pending",
283
+ "portalConnectionManagementPending",
284
+ ),
285
+ )
286
+ authenticated = status == "active" and bool(response_user_id)
223
287
 
224
288
  if session_id and company_id:
225
289
  self.set_session_context(session_id, company_id, csrf_token=csrf_token)
226
290
 
227
- final_user_id = response_user_id or user_id
228
- if final_user_id:
229
- self.user_id = final_user_id
291
+ self.session_status = status
292
+ self.authenticated = authenticated
293
+ self.user_id = response_user_id if authenticated else None
230
294
 
231
- return {"session_id": session_id, "company_id": company_id}
295
+ return {
296
+ "success": True,
297
+ "session_id": session_id or None,
298
+ "company_id": company_id or None,
299
+ "error": None,
300
+ "status": status,
301
+ "user_id": response_user_id or None,
302
+ "provided_user_id_rejected": provided_user_id_rejected,
303
+ "portal_connection_management_pending": (
304
+ portal_connection_management_pending
305
+ ),
306
+ "authenticated": authenticated,
307
+ }
232
308
 
233
309
  async def get_portal_url(
234
310
  self,