docges-api-py 0.1.4__tar.gz → 0.1.6__tar.gz

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.
Files changed (34) hide show
  1. docges_api_py-0.1.6/PKG-INFO +229 -0
  2. docges_api_py-0.1.6/README.md +209 -0
  3. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/pyproject.toml +1 -1
  4. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/client.py +70 -4
  5. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/models/responses.py +3 -0
  6. docges_api_py-0.1.6/src/docges_api_py.egg-info/PKG-INFO +229 -0
  7. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/SOURCES.txt +1 -0
  8. docges_api_py-0.1.6/tests/test_check_dir_struct.py +135 -0
  9. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_examples.py +45 -28
  10. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_models_requests.py +2 -1
  11. docges_api_py-0.1.4/PKG-INFO +0 -161
  12. docges_api_py-0.1.4/README.md +0 -141
  13. docges_api_py-0.1.4/src/docges_api_py.egg-info/PKG-INFO +0 -161
  14. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/LICENSE +0 -0
  15. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/setup.cfg +0 -0
  16. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/__init__.py +0 -0
  17. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/models/__init__.py +0 -0
  18. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/models/auth.py +0 -0
  19. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/models/document.py +0 -0
  20. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py/models/requests.py +0 -0
  21. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/dependency_links.txt +0 -0
  22. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/requires.txt +0 -0
  23. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/top_level.txt +0 -0
  24. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_client_auth.py +0 -0
  25. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_content_methods.py +0 -0
  26. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_endpoints.py +0 -0
  27. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_get_document.py +0 -0
  28. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_initial_cats.py +0 -0
  29. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_models_auth.py +0 -0
  30. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_models_init.py +0 -0
  31. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_models_responses.py +0 -0
  32. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_remaining_methods.py +0 -0
  33. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_retry.py +0 -0
  34. {docges_api_py-0.1.4 → docges_api_py-0.1.6}/tests/test_token_refresh.py +0 -0
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: docges-api-py
3
+ Version: 0.1.6
4
+ Summary: Async, typed Python client for DocGes REST API
5
+ Author-email: "ct.galega" <soporte@ctgalega.com>
6
+ License: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: httpx>=0.27
11
+ Requires-Dist: pydantic>=2.0
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest>=8.0; extra == "dev"
14
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
15
+ Requires-Dist: respx>=0.22; extra == "dev"
16
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
17
+ Requires-Dist: ruff>=0.4; extra == "dev"
18
+ Requires-Dist: mypy>=1.10; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # docges-api-py
22
+
23
+ Async, typed Python client for the DocGes REST API bridge (`docges-ctg-api`).
24
+
25
+ > **Production-ready** — bootstrapped via SDD (Spec-Driven Development).
26
+ > All core endpoints implemented with full test coverage (pytest + respx).
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install docges-api-py
32
+ ```
33
+
34
+ For development with testing tools:
35
+
36
+ ```bash
37
+ pip install -e ".[dev]"
38
+ ```
39
+
40
+ ## Features
41
+
42
+ - ✅ Async HTTP client using `httpx`
43
+ - ✅ Typed request/response models with Pydantic v2
44
+ - ✅ Configurable retries (exponential backoff) and timeouts
45
+ - ✅ Session-based auth: stores `loginResponse` from `/Auth/Login` and auto-injects it
46
+ for all Content endpoints
47
+ - ✅ Full test coverage (pytest + respx)
48
+ - ✅ Complete DocGes API client: categories, documents, search, CRUD operations
49
+
50
+ ## Implemented endpoints
51
+
52
+ ### Auth
53
+ | Method | Endpoint | Description |
54
+ |--------|----------|-------------|
55
+ | `auth()` | `POST /Auth/Login` | Authenticate and store session |
56
+
57
+ ### Content Tree
58
+ | Method | Endpoint | Description |
59
+ |--------|----------|-------------|
60
+ | `get_initial_cats()` | `POST /Content/LoadIniCats` | Load root categories for user's warehouse |
61
+ | `get_cat_info(sid)` | `POST /Content/LoadChilds` | Load subcategories and documents for a given category SID |
62
+
63
+ ### Document Operations
64
+ | Method | Endpoint | Description |
65
+ |--------|----------|-------------|
66
+ | `upload_file(category_sid, file_path)` | `POST /Content/UploadExtended` | Upload a file to a category |
67
+ | `download_content(sid)` | `POST /Content/Download` | Download a document (returns base64 data) |
68
+ | `get_document(sid)` | — | Deprecated wrapper for `download_content()` |
69
+
70
+ ### Search
71
+ | Method | Endpoint | Description |
72
+ |--------|----------|-------------|
73
+ | `search_content(field_values, date_values)` | `POST /Content/SearchContent` | Search documents by field or date criteria |
74
+
75
+ ### Category Management
76
+ | Method | Endpoint | Description |
77
+ |--------|----------|-------------|
78
+ | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
79
+ | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
80
+ | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
81
+ | `check_dir_struct(root_sid, path_names, create_if_not_exist)` | — | Check or create nested directory structure |
82
+
83
+ ### Document Management
84
+ | Method | Endpoint | Description |
85
+ |--------|----------|-------------|
86
+ | `remove_document(sid)` | `POST /Content/RemoveDocument` | Remove a single document |
87
+ | `move_content(content_sid, destination_sid)` | `POST /Content/Move` | Move a document to another category |
88
+ | `update_content(sid, erp_relation, erp_property)` | `POST /Content/Update` | Update document ERP metadata |
89
+
90
+ ## Quick start
91
+
92
+ ```bash
93
+ pip install -e ".[dev]"
94
+ ```
95
+
96
+ ```python
97
+ import asyncio
98
+ import os
99
+ from docges_api_py import AsyncDocGes
100
+
101
+ async def main():
102
+ base_url = os.getenv("DOCGES_API_BASE_URL")
103
+ user = os.getenv("DOCGES_USER")
104
+ pwd = os.getenv("DOCGES_PASSWORD")
105
+ appid = os.getenv("DOCGES_APP_ID")
106
+
107
+ async with AsyncDocGes(base_url, user, pwd, appid) as client:
108
+ auth_resp = await client.auth()
109
+ print(f"User: {auth_resp.user_info['Nombre']}")
110
+
111
+ # Browse root categories
112
+ cats = await client.get_initial_cats()
113
+ for cat in cats.CategoriasHijas or []:
114
+ print(f" {cat.Nombre} [SID: {cat.SID}]")
115
+
116
+ # Search documents
117
+ results = await client.search_content(
118
+ field_values=[{"field": "name", "mode": "contains", "text": "factura"}]
119
+ )
120
+ print(f"Search results: {len(results.results)}")
121
+
122
+ asyncio.run(main())
123
+ ```
124
+
125
+ ### Environment variables
126
+
127
+ | Variable | Description | Example |
128
+ |----------|-------------|---------|
129
+ | `DOCGES_API_BASE_URL` | Bridge base URL | `http://192.168.0.90:49375` |
130
+ | `DOCGES_USER` | Username | `administrador` |
131
+ | `DOCGES_PASSWORD` | Password | `12345` |
132
+ | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
133
+ | `DOCGES_ROOT_SID` | Root category SID for directory operations | `1ddbfd1b-5d33-44af-b392-...` |
134
+
135
+ **Known appIDs:**
136
+ - `local-dev` — local development
137
+ - `pre-dev` — pre-production
138
+ - `pro-*` — production servers
139
+
140
+ ## Examples
141
+
142
+ All examples read credentials from environment variables. Run them with:
143
+
144
+ ```bash
145
+ export DOCGES_API_BASE_URL=http://192.168.0.90:49375
146
+ export DOCGES_USER=administrador
147
+ export DOCGES_PASSWORD=12345
148
+ export DOCGES_APP_ID=local-dev
149
+ python examples/<number>_<name>.py
150
+ ```
151
+
152
+ | # | File | What it does |
153
+ |---|------|-------------|
154
+ | 01 | `examples/01_auth.py` | Login and inspect session context |
155
+ | 02 | `examples/02_initial_cats.py` | Load and list root categories |
156
+ | 03 | `examples/03_browse_category.py` | Browse a category by SID (subcats + docs) |
157
+ | 04 | `examples/04_search.py` | Search documents by name |
158
+ | 05 | `examples/05_upload.py` | Upload a file to a category |
159
+ | 06 | `examples/06_download.py` | Download a document by SID |
160
+ | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
161
+ | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
162
+ | 09 | `examples/09_dir_structure.py` | Check or create nested directory structure |
163
+
164
+ ## Development
165
+
166
+ ```bash
167
+ pip install -e ".[dev]"
168
+ ruff check src/ tests/
169
+ mypy src/
170
+ pytest --cov=docges_api_py
171
+ ```
172
+
173
+ ## Architecture notes
174
+
175
+ - The DocGes REST API is a thin bridge in front of DocGes WCF services. It uses session-based auth: `/Auth/Login` returns a `loginResponse` (containing `userInfo` and `wareHouseInfo`) that must be passed back on every Content request via `requestModel.loginResponse`.
176
+ - Content endpoints expect `contenidoModel`, `fileModel`, etc. as **top-level fields** alongside `requestModel`, not nested inside it. The client builds the correct payload shape automatically.
177
+ - For DocGes Web (bridge) compatibility, the client also includes `loginDocGesData` (username/password/appID) in `requestModel` — this is needed by some bridge deployments that reconstruct the DocGes login model server-side.
178
+ - All file content is base64-encoded in transit (handled automatically by the client).
179
+
180
+ ## Project structure
181
+
182
+ ```
183
+ docges-api-py/
184
+ ├── src/docges_api_py/
185
+ │ ├── __init__.py # Exports AsyncDocGes, models
186
+ │ ├── client.py # AsyncDocGes client (all endpoints)
187
+ │ └── models/
188
+ │ ├── __init__.py # Re-exports all models
189
+ │ ├── auth.py # AuthRequest, AuthResponse
190
+ │ ├── document.py # Document
191
+ │ ├── requests.py # Request models (Pydantic v2)
192
+ │ └── responses.py # Response models (ResCat, ResFileDownload, etc.)
193
+ ├── tests/
194
+ │ ├── conftest.py
195
+ │ ├── test_client_auth.py
196
+ │ ├── test_initial_cats.py
197
+ │ ├── test_content_methods.py
198
+ │ ├── test_remaining_methods.py
199
+ │ ├── test_check_dir_struct.py
200
+ │ ├── test_models_requests.py
201
+ │ ├── test_models_responses.py
202
+ │ ├── test_models_init.py
203
+ │ ├── test_endpoints.py
204
+ │ ├── test_retry.py
205
+ │ ├── test_token_refresh.py
206
+ │ └── test_examples.py
207
+ ├── examples/
208
+ │ ├── 01_auth.py
209
+ │ ├── 02_initial_cats.py
210
+ │ ├── 03_browse_category.py
211
+ │ ├── 04_search.py
212
+ │ ├── 05_upload.py
213
+ │ ├── 06_download.py
214
+ │ ├── 07_category_crud.py
215
+ │ ├── 08_document_operations.py
216
+ │ └── 09_dir_structure.py
217
+ ├── docs/
218
+ │ └── MIGRATION.md
219
+ ├── scripts/
220
+ │ └── docges_debug/ # Debug helpers for payload investigation
221
+ ├── pyproject.toml
222
+ ├── ruff.toml
223
+ ├── mypy.ini
224
+ └── README.md
225
+ ```
226
+
227
+ ## Contributing
228
+
229
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
@@ -0,0 +1,209 @@
1
+ # docges-api-py
2
+
3
+ Async, typed Python client for the DocGes REST API bridge (`docges-ctg-api`).
4
+
5
+ > **Production-ready** — bootstrapped via SDD (Spec-Driven Development).
6
+ > All core endpoints implemented with full test coverage (pytest + respx).
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install docges-api-py
12
+ ```
13
+
14
+ For development with testing tools:
15
+
16
+ ```bash
17
+ pip install -e ".[dev]"
18
+ ```
19
+
20
+ ## Features
21
+
22
+ - ✅ Async HTTP client using `httpx`
23
+ - ✅ Typed request/response models with Pydantic v2
24
+ - ✅ Configurable retries (exponential backoff) and timeouts
25
+ - ✅ Session-based auth: stores `loginResponse` from `/Auth/Login` and auto-injects it
26
+ for all Content endpoints
27
+ - ✅ Full test coverage (pytest + respx)
28
+ - ✅ Complete DocGes API client: categories, documents, search, CRUD operations
29
+
30
+ ## Implemented endpoints
31
+
32
+ ### Auth
33
+ | Method | Endpoint | Description |
34
+ |--------|----------|-------------|
35
+ | `auth()` | `POST /Auth/Login` | Authenticate and store session |
36
+
37
+ ### Content Tree
38
+ | Method | Endpoint | Description |
39
+ |--------|----------|-------------|
40
+ | `get_initial_cats()` | `POST /Content/LoadIniCats` | Load root categories for user's warehouse |
41
+ | `get_cat_info(sid)` | `POST /Content/LoadChilds` | Load subcategories and documents for a given category SID |
42
+
43
+ ### Document Operations
44
+ | Method | Endpoint | Description |
45
+ |--------|----------|-------------|
46
+ | `upload_file(category_sid, file_path)` | `POST /Content/UploadExtended` | Upload a file to a category |
47
+ | `download_content(sid)` | `POST /Content/Download` | Download a document (returns base64 data) |
48
+ | `get_document(sid)` | — | Deprecated wrapper for `download_content()` |
49
+
50
+ ### Search
51
+ | Method | Endpoint | Description |
52
+ |--------|----------|-------------|
53
+ | `search_content(field_values, date_values)` | `POST /Content/SearchContent` | Search documents by field or date criteria |
54
+
55
+ ### Category Management
56
+ | Method | Endpoint | Description |
57
+ |--------|----------|-------------|
58
+ | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
59
+ | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
60
+ | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
61
+ | `check_dir_struct(root_sid, path_names, create_if_not_exist)` | — | Check or create nested directory structure |
62
+
63
+ ### Document Management
64
+ | Method | Endpoint | Description |
65
+ |--------|----------|-------------|
66
+ | `remove_document(sid)` | `POST /Content/RemoveDocument` | Remove a single document |
67
+ | `move_content(content_sid, destination_sid)` | `POST /Content/Move` | Move a document to another category |
68
+ | `update_content(sid, erp_relation, erp_property)` | `POST /Content/Update` | Update document ERP metadata |
69
+
70
+ ## Quick start
71
+
72
+ ```bash
73
+ pip install -e ".[dev]"
74
+ ```
75
+
76
+ ```python
77
+ import asyncio
78
+ import os
79
+ from docges_api_py import AsyncDocGes
80
+
81
+ async def main():
82
+ base_url = os.getenv("DOCGES_API_BASE_URL")
83
+ user = os.getenv("DOCGES_USER")
84
+ pwd = os.getenv("DOCGES_PASSWORD")
85
+ appid = os.getenv("DOCGES_APP_ID")
86
+
87
+ async with AsyncDocGes(base_url, user, pwd, appid) as client:
88
+ auth_resp = await client.auth()
89
+ print(f"User: {auth_resp.user_info['Nombre']}")
90
+
91
+ # Browse root categories
92
+ cats = await client.get_initial_cats()
93
+ for cat in cats.CategoriasHijas or []:
94
+ print(f" {cat.Nombre} [SID: {cat.SID}]")
95
+
96
+ # Search documents
97
+ results = await client.search_content(
98
+ field_values=[{"field": "name", "mode": "contains", "text": "factura"}]
99
+ )
100
+ print(f"Search results: {len(results.results)}")
101
+
102
+ asyncio.run(main())
103
+ ```
104
+
105
+ ### Environment variables
106
+
107
+ | Variable | Description | Example |
108
+ |----------|-------------|---------|
109
+ | `DOCGES_API_BASE_URL` | Bridge base URL | `http://192.168.0.90:49375` |
110
+ | `DOCGES_USER` | Username | `administrador` |
111
+ | `DOCGES_PASSWORD` | Password | `12345` |
112
+ | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
113
+ | `DOCGES_ROOT_SID` | Root category SID for directory operations | `1ddbfd1b-5d33-44af-b392-...` |
114
+
115
+ **Known appIDs:**
116
+ - `local-dev` — local development
117
+ - `pre-dev` — pre-production
118
+ - `pro-*` — production servers
119
+
120
+ ## Examples
121
+
122
+ All examples read credentials from environment variables. Run them with:
123
+
124
+ ```bash
125
+ export DOCGES_API_BASE_URL=http://192.168.0.90:49375
126
+ export DOCGES_USER=administrador
127
+ export DOCGES_PASSWORD=12345
128
+ export DOCGES_APP_ID=local-dev
129
+ python examples/<number>_<name>.py
130
+ ```
131
+
132
+ | # | File | What it does |
133
+ |---|------|-------------|
134
+ | 01 | `examples/01_auth.py` | Login and inspect session context |
135
+ | 02 | `examples/02_initial_cats.py` | Load and list root categories |
136
+ | 03 | `examples/03_browse_category.py` | Browse a category by SID (subcats + docs) |
137
+ | 04 | `examples/04_search.py` | Search documents by name |
138
+ | 05 | `examples/05_upload.py` | Upload a file to a category |
139
+ | 06 | `examples/06_download.py` | Download a document by SID |
140
+ | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
141
+ | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
142
+ | 09 | `examples/09_dir_structure.py` | Check or create nested directory structure |
143
+
144
+ ## Development
145
+
146
+ ```bash
147
+ pip install -e ".[dev]"
148
+ ruff check src/ tests/
149
+ mypy src/
150
+ pytest --cov=docges_api_py
151
+ ```
152
+
153
+ ## Architecture notes
154
+
155
+ - The DocGes REST API is a thin bridge in front of DocGes WCF services. It uses session-based auth: `/Auth/Login` returns a `loginResponse` (containing `userInfo` and `wareHouseInfo`) that must be passed back on every Content request via `requestModel.loginResponse`.
156
+ - Content endpoints expect `contenidoModel`, `fileModel`, etc. as **top-level fields** alongside `requestModel`, not nested inside it. The client builds the correct payload shape automatically.
157
+ - For DocGes Web (bridge) compatibility, the client also includes `loginDocGesData` (username/password/appID) in `requestModel` — this is needed by some bridge deployments that reconstruct the DocGes login model server-side.
158
+ - All file content is base64-encoded in transit (handled automatically by the client).
159
+
160
+ ## Project structure
161
+
162
+ ```
163
+ docges-api-py/
164
+ ├── src/docges_api_py/
165
+ │ ├── __init__.py # Exports AsyncDocGes, models
166
+ │ ├── client.py # AsyncDocGes client (all endpoints)
167
+ │ └── models/
168
+ │ ├── __init__.py # Re-exports all models
169
+ │ ├── auth.py # AuthRequest, AuthResponse
170
+ │ ├── document.py # Document
171
+ │ ├── requests.py # Request models (Pydantic v2)
172
+ │ └── responses.py # Response models (ResCat, ResFileDownload, etc.)
173
+ ├── tests/
174
+ │ ├── conftest.py
175
+ │ ├── test_client_auth.py
176
+ │ ├── test_initial_cats.py
177
+ │ ├── test_content_methods.py
178
+ │ ├── test_remaining_methods.py
179
+ │ ├── test_check_dir_struct.py
180
+ │ ├── test_models_requests.py
181
+ │ ├── test_models_responses.py
182
+ │ ├── test_models_init.py
183
+ │ ├── test_endpoints.py
184
+ │ ├── test_retry.py
185
+ │ ├── test_token_refresh.py
186
+ │ └── test_examples.py
187
+ ├── examples/
188
+ │ ├── 01_auth.py
189
+ │ ├── 02_initial_cats.py
190
+ │ ├── 03_browse_category.py
191
+ │ ├── 04_search.py
192
+ │ ├── 05_upload.py
193
+ │ ├── 06_download.py
194
+ │ ├── 07_category_crud.py
195
+ │ ├── 08_document_operations.py
196
+ │ └── 09_dir_structure.py
197
+ ├── docs/
198
+ │ └── MIGRATION.md
199
+ ├── scripts/
200
+ │ └── docges_debug/ # Debug helpers for payload investigation
201
+ ├── pyproject.toml
202
+ ├── ruff.toml
203
+ ├── mypy.ini
204
+ └── README.md
205
+ ```
206
+
207
+ ## Contributing
208
+
209
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "docges-api-py"
7
- version = "0.1.4"
7
+ version = "0.1.6"
8
8
  description = "Async, typed Python client for DocGes REST API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -142,9 +142,12 @@ class AsyncDocGes:
142
142
 
143
143
  # Normalize: copy SIDraiz to SID in wareHouseInfo for bridge compatibility
144
144
  # The bridge C# code expects wareHouseInfo.SID, but the API returns SIDraiz
145
- if "wareHouseInfo" in resp and "SIDraiz" in resp["wareHouseInfo"]:
146
- if "SID" not in resp["wareHouseInfo"]:
147
- resp["wareHouseInfo"]["SID"] = resp["wareHouseInfo"]["SIDraiz"]
145
+ if (
146
+ "wareHouseInfo" in resp
147
+ and "SIDraiz" in resp["wareHouseInfo"]
148
+ and "SID" not in resp["wareHouseInfo"]
149
+ ):
150
+ resp["wareHouseInfo"]["SID"] = resp["wareHouseInfo"]["SIDraiz"]
148
151
 
149
152
  # Store the normalized dict for injection into every subsequent /Content/* request
150
153
  self._login_response = resp
@@ -206,7 +209,7 @@ class AsyncDocGes:
206
209
  # Build final payload: extra data fields (contenidoModel, fileModel, etc.)
207
210
  # go at TOP LEVEL alongside requestModel — NOT nested inside requestModel.
208
211
  # This matches the server's RequestContentModel: { contenidoModel, requestModel }.
209
- payload: dict[str, Any] = {"requestModel": request_model}
212
+ payload = {"requestModel": request_model}
210
213
  if data is not None:
211
214
  extra = data.model_dump(exclude_none=True)
212
215
  # If data itself has a requestModel key, merge it into the top-level one
@@ -359,6 +362,69 @@ class AsyncDocGes:
359
362
  resp = await self.do_request(Endpoints.content_delete_category, data)
360
363
  return bool(resp.get("result"))
361
364
 
365
+ async def check_dir_struct(
366
+ self,
367
+ root_sid: str,
368
+ path_names: list[str],
369
+ create_if_not_exist: bool = False,
370
+ ) -> list[dict] | None:
371
+ """
372
+ Check or create a directory structure under a given root SID.
373
+
374
+ Traverses the hierarchy level by level. For each level:
375
+ 1. Gets child categories via get_cat_info()
376
+ 2. Searches for a matching category by name
377
+ 3. If not found and create_if_not_exist=True, creates it
378
+
379
+ Args:
380
+ root_sid: The root SID to start from
381
+ path_names: List of category names to traverse/create (e.g., ["2025", "PM-001"])
382
+ create_if_not_exist: If True, create missing categories
383
+
384
+ Returns:
385
+ List of dicts with keys: sid, parent_sid, name (one per level)
386
+ None on error
387
+ """
388
+ results: list[dict] = []
389
+ current_sid = root_sid
390
+
391
+ try:
392
+ for name in path_names:
393
+ cat_info = await self.get_cat_info(current_sid)
394
+
395
+ found_sid = None
396
+ if cat_info and cat_info.CategoriasHijas:
397
+ for child in cat_info.CategoriasHijas:
398
+ if child.get("Nombre") == name:
399
+ found_sid = child.get("SID")
400
+ break
401
+
402
+ if found_sid:
403
+ results.append({
404
+ "sid": found_sid,
405
+ "parent_sid": current_sid,
406
+ "name": name,
407
+ })
408
+ current_sid = found_sid
409
+ elif create_if_not_exist:
410
+ new_sid = await self.create_category(current_sid, name)
411
+ if new_sid:
412
+ results.append({
413
+ "sid": new_sid,
414
+ "parent_sid": current_sid,
415
+ "name": name,
416
+ })
417
+ current_sid = new_sid
418
+ else:
419
+ return None
420
+ else:
421
+ return None
422
+
423
+ return results
424
+
425
+ except Exception:
426
+ return None
427
+
362
428
  async def remove_document(self, sid: str) -> bool:
363
429
  """Remove a single document. Returns True on success."""
364
430
  await self._ensure_session()
@@ -21,6 +21,9 @@ class ResCatItem(DocGesResponseModel):
21
21
 
22
22
  class ResCat(DocGesResponseModel):
23
23
  """Response from /Content/LoadIniCats and /Content/LoadChilds."""
24
+ Nombre: str | None = None
25
+ SID: str | None = None
26
+ CategoriaMadre: dict | None = None
24
27
  CategoriasHijas: list[dict] | None = None
25
28
  Documentos: list[dict] | None = None
26
29