Skip to content

Commit e91b25e

Browse files
jfrench9claude
andauthored
Add native accounting operations and enhance API error handling (#89)
## Summary This PR introduces a comprehensive set of native accounting (RoboLedger) CRUD operations and significantly enhances error handling and response parsing across all RoboInvestor and GraphQL API operations in the `robosystems_client`. ## Key Accomplishments ### New RoboLedger Operations (16 new endpoint modules) - **Elements**: Create, update, and delete accounting elements with full support for balance types, classifications, element types, period types, and source enums - **Journal Entries**: Create, update, delete, and reverse journal entries with line item support - **Associations**: Bulk create, update, and delete associations (including bulk association items with typed association types) - **Schedules**: Delete, update, and manage schedules (including truncation) - **Structures**: Delete and update organizational structures - **Taxonomies**: Delete and update taxonomy definitions ### New Models (30+ new model files) - Request models for all new operations (`CreateElementRequest`, `CreateJournalEntryRequest`, `BulkCreateAssociationsRequest`, etc.) - Supporting enum models for typed fields (`CreateElementRequestBalanceType`, `CreateJournalEntryRequestType`, `UpdateElementRequestClassificationType0`, etc.) - `JournalEntryLineItemInput` for structured journal entry line items - `OperationError` and `OperationErrorDetailType1` for standardized error representation - `OperationEnvelope` updates to support the new error structure ### Enhanced Error Handling & Response Parsing - **All existing RoboInvestor operations** (9 modules: create/update/delete for portfolio, position, security) updated with improved error handling and richer response parsing - **All existing RoboLedger operations** (20+ modules) updated with consistent error handling patterns - **GraphQL operations** (GET and POST handlers) enhanced with better response parsing - **Ledger client** (`ledger_client.py`) updated to integrate with new operations ## Breaking Changes - **`OperationEnvelope` model** has been updated — consumers relying on the previous error field structure should update to use the new `OperationError` model - New operations may introduce additional required dependencies or import paths in the `models/__init__.py` module ## Testing Notes - Verify all new CRUD operations for elements, journal entries, associations, schedules, structures, and taxonomies against the API - Test error scenarios to validate the enhanced error handling produces correctly structured `OperationError` responses across all modules - Confirm backward compatibility of existing RoboInvestor and GraphQL operations after the error handling refactor - Validate enum models serialize/deserialize correctly for all typed request fields (balance types, classifications, period types, etc.) - Test the reverse journal entry flow end-to-end as it represents a new business operation ## Infrastructure Considerations - The significant number of new model and operation files (85 files changed) suggests this was likely generated or scaffolded from an updated API specification — ensure the code generation tooling and API spec are version-tracked accordingly - The `models/__init__.py` module has been updated to export all new models; downstream consumers pulling from this package will pick up the new types automatically - No new external dependencies appear to be introduced; changes are additive within the existing client architecture --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `feature/native-accounting-ops` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents 8a46e56 + 76fa0b9 commit e91b25e

90 files changed

Lines changed: 10854 additions & 365 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎robosystems_client/api/extensions_graph_ql/handle_http_get_extensions_graph_id_graphql_get.py‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def _parse_response(
3030
response_200 = response.json()
3131
return response_200
3232

33+
if response.status_code == 401:
34+
response_401 = cast(Any, None)
35+
return response_401
36+
37+
if response.status_code == 403:
38+
response_403 = cast(Any, None)
39+
return response_403
40+
3341
if response.status_code == 404:
3442
response_404 = cast(Any, None)
3543
return response_404
@@ -39,6 +47,10 @@ def _parse_response(
3947

4048
return response_422
4149

50+
if response.status_code == 429:
51+
response_429 = cast(Any, None)
52+
return response_429
53+
4254
if client.raise_on_unexpected_status:
4355
raise errors.UnexpectedStatus(response.status_code, response.content)
4456
else:
@@ -63,6 +75,15 @@ def sync_detailed(
6375
) -> Response[Any | HTTPValidationError]:
6476
"""Handle Http Get
6577
78+
79+
80+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
81+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
82+
`UNAUTHENTICATED`.
83+
84+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
85+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
86+
6687
Args:
6788
graph_id (str):
6889
@@ -92,6 +113,15 @@ def sync(
92113
) -> Any | HTTPValidationError | None:
93114
"""Handle Http Get
94115
116+
117+
118+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
119+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
120+
`UNAUTHENTICATED`.
121+
122+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
123+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
124+
95125
Args:
96126
graph_id (str):
97127
@@ -116,6 +146,15 @@ async def asyncio_detailed(
116146
) -> Response[Any | HTTPValidationError]:
117147
"""Handle Http Get
118148
149+
150+
151+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
152+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
153+
`UNAUTHENTICATED`.
154+
155+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
156+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
157+
119158
Args:
120159
graph_id (str):
121160
@@ -143,6 +182,15 @@ async def asyncio(
143182
) -> Any | HTTPValidationError | None:
144183
"""Handle Http Get
145184
185+
186+
187+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
188+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
189+
`UNAUTHENTICATED`.
190+
191+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
192+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
193+
146194
Args:
147195
graph_id (str):
148196

‎robosystems_client/api/extensions_graph_ql/handle_http_post_extensions_graph_id_graphql_post.py‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any
2+
from typing import Any, cast
33
from urllib.parse import quote
44

55
import httpx
@@ -30,11 +30,23 @@ def _parse_response(
3030
response_200 = response.json()
3131
return response_200
3232

33+
if response.status_code == 401:
34+
response_401 = cast(Any, None)
35+
return response_401
36+
37+
if response.status_code == 403:
38+
response_403 = cast(Any, None)
39+
return response_403
40+
3341
if response.status_code == 422:
3442
response_422 = HTTPValidationError.from_dict(response.json())
3543

3644
return response_422
3745

46+
if response.status_code == 429:
47+
response_429 = cast(Any, None)
48+
return response_429
49+
3850
if client.raise_on_unexpected_status:
3951
raise errors.UnexpectedStatus(response.status_code, response.content)
4052
else:
@@ -59,6 +71,15 @@ def sync_detailed(
5971
) -> Response[Any | HTTPValidationError]:
6072
"""Handle Http Post
6173
74+
75+
76+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
77+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
78+
`UNAUTHENTICATED`.
79+
80+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
81+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
82+
6283
Args:
6384
graph_id (str):
6485
@@ -88,6 +109,15 @@ def sync(
88109
) -> Any | HTTPValidationError | None:
89110
"""Handle Http Post
90111
112+
113+
114+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
115+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
116+
`UNAUTHENTICATED`.
117+
118+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
119+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
120+
91121
Args:
92122
graph_id (str):
93123
@@ -112,6 +142,15 @@ async def asyncio_detailed(
112142
) -> Response[Any | HTTPValidationError]:
113143
"""Handle Http Post
114144
145+
146+
147+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
148+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
149+
`UNAUTHENTICATED`.
150+
151+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
152+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
153+
115154
Args:
116155
graph_id (str):
117156
@@ -139,6 +178,15 @@ async def asyncio(
139178
) -> Any | HTTPValidationError | None:
140179
"""Handle Http Post
141180
181+
182+
183+
**Auth**: pass `X-API-Key` (or a JWT `Authorization: Bearer` header). Unauthenticated introspection
184+
queries are deliberately allowed for SDK codegen; data queries require credentials and raise
185+
`UNAUTHENTICATED`.
186+
187+
**Error codes**: `LEDGER_NOT_INITIALIZED`, `INVESTOR_NOT_INITIALIZED`, and `UNAUTHENTICATED` surface
188+
in the GraphQL `errors[].extensions.code` field — see `graphql/README.md` for the full vocabulary.
189+
142190
Args:
143191
graph_id (str):
144192

‎robosystems_client/api/extensions_robo_investor/op_create_portfolio.py‎

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any
2+
from typing import Any, cast
33
from urllib.parse import quote
44

55
import httpx
@@ -9,6 +9,7 @@
99
from ...models.create_portfolio_request import CreatePortfolioRequest
1010
from ...models.http_validation_error import HTTPValidationError
1111
from ...models.operation_envelope import OperationEnvelope
12+
from ...models.operation_error import OperationError
1213
from ...types import UNSET, Response, Unset
1314

1415

@@ -39,17 +40,48 @@ def _get_kwargs(
3940

4041
def _parse_response(
4142
*, client: AuthenticatedClient | Client, response: httpx.Response
42-
) -> HTTPValidationError | OperationEnvelope | None:
43+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
4344
if response.status_code == 200:
4445
response_200 = OperationEnvelope.from_dict(response.json())
4546

4647
return response_200
4748

49+
if response.status_code == 400:
50+
response_400 = OperationError.from_dict(response.json())
51+
52+
return response_400
53+
54+
if response.status_code == 401:
55+
response_401 = cast(Any, None)
56+
return response_401
57+
58+
if response.status_code == 403:
59+
response_403 = cast(Any, None)
60+
return response_403
61+
62+
if response.status_code == 404:
63+
response_404 = OperationError.from_dict(response.json())
64+
65+
return response_404
66+
67+
if response.status_code == 409:
68+
response_409 = OperationError.from_dict(response.json())
69+
70+
return response_409
71+
4872
if response.status_code == 422:
4973
response_422 = HTTPValidationError.from_dict(response.json())
5074

5175
return response_422
5276

77+
if response.status_code == 429:
78+
response_429 = cast(Any, None)
79+
return response_429
80+
81+
if response.status_code == 500:
82+
response_500 = cast(Any, None)
83+
return response_500
84+
5385
if client.raise_on_unexpected_status:
5486
raise errors.UnexpectedStatus(response.status_code, response.content)
5587
else:
@@ -58,7 +90,7 @@ def _parse_response(
5890

5991
def _build_response(
6092
*, client: AuthenticatedClient | Client, response: httpx.Response
61-
) -> Response[HTTPValidationError | OperationEnvelope]:
93+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
6294
return Response(
6395
status_code=HTTPStatus(response.status_code),
6496
content=response.content,
@@ -73,9 +105,14 @@ def sync_detailed(
73105
client: AuthenticatedClient,
74106
body: CreatePortfolioRequest,
75107
idempotency_key: None | str | Unset = UNSET,
76-
) -> Response[HTTPValidationError | OperationEnvelope]:
108+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
77109
"""Create Portfolio
78110
111+
112+
113+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
114+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
115+
79116
Args:
80117
graph_id (str):
81118
idempotency_key (None | str | Unset):
@@ -86,7 +123,7 @@ def sync_detailed(
86123
httpx.TimeoutException: If the request takes longer than Client.timeout.
87124
88125
Returns:
89-
Response[HTTPValidationError | OperationEnvelope]
126+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
90127
"""
91128

92129
kwargs = _get_kwargs(
@@ -108,9 +145,14 @@ def sync(
108145
client: AuthenticatedClient,
109146
body: CreatePortfolioRequest,
110147
idempotency_key: None | str | Unset = UNSET,
111-
) -> HTTPValidationError | OperationEnvelope | None:
148+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
112149
"""Create Portfolio
113150
151+
152+
153+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
154+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
155+
114156
Args:
115157
graph_id (str):
116158
idempotency_key (None | str | Unset):
@@ -121,7 +163,7 @@ def sync(
121163
httpx.TimeoutException: If the request takes longer than Client.timeout.
122164
123165
Returns:
124-
HTTPValidationError | OperationEnvelope
166+
Any | HTTPValidationError | OperationEnvelope | OperationError
125167
"""
126168

127169
return sync_detailed(
@@ -138,9 +180,14 @@ async def asyncio_detailed(
138180
client: AuthenticatedClient,
139181
body: CreatePortfolioRequest,
140182
idempotency_key: None | str | Unset = UNSET,
141-
) -> Response[HTTPValidationError | OperationEnvelope]:
183+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
142184
"""Create Portfolio
143185
186+
187+
188+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
189+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
190+
144191
Args:
145192
graph_id (str):
146193
idempotency_key (None | str | Unset):
@@ -151,7 +198,7 @@ async def asyncio_detailed(
151198
httpx.TimeoutException: If the request takes longer than Client.timeout.
152199
153200
Returns:
154-
Response[HTTPValidationError | OperationEnvelope]
201+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
155202
"""
156203

157204
kwargs = _get_kwargs(
@@ -171,9 +218,14 @@ async def asyncio(
171218
client: AuthenticatedClient,
172219
body: CreatePortfolioRequest,
173220
idempotency_key: None | str | Unset = UNSET,
174-
) -> HTTPValidationError | OperationEnvelope | None:
221+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
175222
"""Create Portfolio
176223
224+
225+
226+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
227+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
228+
177229
Args:
178230
graph_id (str):
179231
idempotency_key (None | str | Unset):
@@ -184,7 +236,7 @@ async def asyncio(
184236
httpx.TimeoutException: If the request takes longer than Client.timeout.
185237
186238
Returns:
187-
HTTPValidationError | OperationEnvelope
239+
Any | HTTPValidationError | OperationEnvelope | OperationError
188240
"""
189241

190242
return (

0 commit comments

Comments
 (0)