wflow-api 0.1.0__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.
- wflow_api/__init__.py +20 -0
- wflow_api/auth.py +85 -0
- wflow_api/client.py +130 -0
- wflow_api/errors.py +13 -0
- wflow_api/guards.py +132 -0
- wflow_api/models/__init__.py +128 -0
- wflow_api/models/account.py +127 -0
- wflow_api/models/admin.py +98 -0
- wflow_api/models/common.py +117 -0
- wflow_api/models/documents.py +514 -0
- wflow_api/models/registers.py +165 -0
- wflow_api/models/requests.py +341 -0
- wflow_api/models/storage.py +38 -0
- wflow_api/operation.py +50 -0
- wflow_api/operations/__init__.py +21 -0
- wflow_api/operations/account.py +46 -0
- wflow_api/operations/admin.py +307 -0
- wflow_api/operations/approvals.py +235 -0
- wflow_api/operations/document_files.py +145 -0
- wflow_api/operations/document_properties.py +204 -0
- wflow_api/operations/document_tags.py +60 -0
- wflow_api/operations/documents.py +603 -0
- wflow_api/operations/integrations.py +63 -0
- wflow_api/operations/organization.py +51 -0
- wflow_api/operations/registers.py +2273 -0
- wflow_api/operations/storage_files.py +477 -0
- wflow_api/operations/storage_folders.py +132 -0
- wflow_api/operations/webhooks.py +67 -0
- wflow_api/py.typed +0 -0
- wflow_api-0.1.0.dist-info/METADATA +48 -0
- wflow_api-0.1.0.dist-info/RECORD +33 -0
- wflow_api-0.1.0.dist-info/WHEEL +4 -0
- wflow_api-0.1.0.dist-info/licenses/LICENSE +202 -0
wflow_api/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from importlib.metadata import version
|
|
2
|
+
|
|
3
|
+
from wflow_api.auth import ENVIRONMENTS, ClientCredentials
|
|
4
|
+
from wflow_api.client import WflowClient
|
|
5
|
+
from wflow_api.errors import WflowApiError, WflowError
|
|
6
|
+
from wflow_api.models.common import FileContent
|
|
7
|
+
from wflow_api.operation import operation
|
|
8
|
+
|
|
9
|
+
__version__ = version("wflow-api")
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"ENVIRONMENTS",
|
|
13
|
+
"ClientCredentials",
|
|
14
|
+
"FileContent",
|
|
15
|
+
"WflowApiError",
|
|
16
|
+
"WflowClient",
|
|
17
|
+
"WflowError",
|
|
18
|
+
"__version__",
|
|
19
|
+
"operation",
|
|
20
|
+
]
|
wflow_api/auth.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Machine-to-machine sign-in: a client_credentials token, fetched once and reused until it nears expiry."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import time
|
|
5
|
+
from urllib.parse import urlsplit
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from wflow_api.errors import WflowApiError, WflowError
|
|
10
|
+
|
|
11
|
+
ENVIRONMENTS = {
|
|
12
|
+
"prod": ("https://api.wflow.com", "https://account.wflow.com"),
|
|
13
|
+
"test": ("https://apitest.wflow.com", "https://account.wflow.com"),
|
|
14
|
+
}
|
|
15
|
+
TOKEN_PATH = "/connect/token"
|
|
16
|
+
REFRESH_MARGIN_SECONDS = 60
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _oauth_error(response: httpx.Response) -> str:
|
|
20
|
+
try:
|
|
21
|
+
body = response.json()
|
|
22
|
+
except ValueError:
|
|
23
|
+
return ""
|
|
24
|
+
if not isinstance(body, dict) or not body.get("error"):
|
|
25
|
+
return ""
|
|
26
|
+
described = f": {body['error_description']}" if body.get("error_description") else ""
|
|
27
|
+
return f"{body['error']}{described}"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ClientCredentials:
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
client_id: str,
|
|
34
|
+
client_secret: str,
|
|
35
|
+
account_base: str,
|
|
36
|
+
scope: str = "uccl_common_api",
|
|
37
|
+
*,
|
|
38
|
+
transport: httpx.AsyncBaseTransport | None = None,
|
|
39
|
+
) -> None:
|
|
40
|
+
self._form = {
|
|
41
|
+
"client_id": client_id,
|
|
42
|
+
"client_secret": client_secret,
|
|
43
|
+
"grant_type": "client_credentials",
|
|
44
|
+
"scope": scope,
|
|
45
|
+
}
|
|
46
|
+
self._account_base = account_base.rstrip("/")
|
|
47
|
+
self._host = urlsplit(self._account_base).netloc or self._account_base
|
|
48
|
+
self._transport = transport
|
|
49
|
+
self._token: str | None = None
|
|
50
|
+
self._expires_at = 0.0
|
|
51
|
+
self._lock = asyncio.Lock()
|
|
52
|
+
|
|
53
|
+
async def __call__(self) -> str:
|
|
54
|
+
async with self._lock:
|
|
55
|
+
if self._token is None or time.monotonic() >= self._expires_at:
|
|
56
|
+
self._token, self._expires_at = await self._fetch()
|
|
57
|
+
return self._token
|
|
58
|
+
|
|
59
|
+
async def _fetch(self) -> tuple[str, float]:
|
|
60
|
+
try:
|
|
61
|
+
async with httpx.AsyncClient(base_url=self._account_base, transport=self._transport, timeout=30) as client:
|
|
62
|
+
response = await client.post(TOKEN_PATH, data=self._form)
|
|
63
|
+
except (httpx.HTTPError, httpx.InvalidURL) as error:
|
|
64
|
+
reason = f"{type(error).__name__}{f': {error}' if str(error) else ''}"
|
|
65
|
+
raise WflowError(f"wflow {self._host} POST {TOKEN_PATH} could not be reached: {reason}.") from error
|
|
66
|
+
if response.is_error:
|
|
67
|
+
detail = _oauth_error(response)
|
|
68
|
+
described = f" ({detail})" if detail else ""
|
|
69
|
+
raise WflowApiError(
|
|
70
|
+
f"wflow {self._host} POST {TOKEN_PATH} returned {response.status_code}{described}.",
|
|
71
|
+
status=response.status_code,
|
|
72
|
+
method="POST",
|
|
73
|
+
path=TOKEN_PATH,
|
|
74
|
+
detail=detail,
|
|
75
|
+
)
|
|
76
|
+
missing = f"wflow {self._host} POST {TOKEN_PATH} answered without an access_token."
|
|
77
|
+
try:
|
|
78
|
+
body = response.json()
|
|
79
|
+
token = body["access_token"]
|
|
80
|
+
expires_in = float(body.get("expires_in") or 0)
|
|
81
|
+
except (ValueError, KeyError, TypeError) as error:
|
|
82
|
+
raise WflowError(missing) from error
|
|
83
|
+
if not isinstance(token, str) or not token:
|
|
84
|
+
raise WflowError(missing)
|
|
85
|
+
return token, time.monotonic() + max(expires_in - REFRESH_MARGIN_SECONDS, 0)
|
wflow_api/client.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Calls to the wflow public API, signed with the caller's token."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Awaitable, Callable, Mapping
|
|
4
|
+
from typing import Any
|
|
5
|
+
from urllib.parse import urlsplit
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from wflow_api.errors import WflowApiError, WflowError
|
|
10
|
+
from wflow_api.guards import filename_from_disposition, problem_detail
|
|
11
|
+
from wflow_api.models.common import FileContent
|
|
12
|
+
|
|
13
|
+
Token = Callable[[], Awaitable[str]]
|
|
14
|
+
|
|
15
|
+
UPLOAD_TIMEOUT = 120
|
|
16
|
+
DOWNLOAD_TIMEOUT = 60
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class WflowClient:
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
token: Token,
|
|
23
|
+
*,
|
|
24
|
+
api_base: str,
|
|
25
|
+
headers: Mapping[str, str],
|
|
26
|
+
timeout: float = 30,
|
|
27
|
+
transport: httpx.AsyncBaseTransport | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
self.api_base = api_base
|
|
30
|
+
self._token = token
|
|
31
|
+
self._headers = dict(headers)
|
|
32
|
+
self._timeout = timeout
|
|
33
|
+
self._transport = transport
|
|
34
|
+
self._host = urlsplit(api_base).netloc or api_base
|
|
35
|
+
|
|
36
|
+
def _http(self, timeout: float) -> httpx.AsyncClient:
|
|
37
|
+
return httpx.AsyncClient(base_url=self.api_base, timeout=timeout, transport=self._transport)
|
|
38
|
+
|
|
39
|
+
async def _signed(self) -> dict[str, str]:
|
|
40
|
+
return {**self._headers, "Authorization": f"Bearer {await self._token()}"}
|
|
41
|
+
|
|
42
|
+
def _failure(self, response: httpx.Response, method: str, path: str) -> WflowApiError:
|
|
43
|
+
detail = problem_detail(response)
|
|
44
|
+
return WflowApiError(
|
|
45
|
+
f"wflow {self._host} {method} {path} returned {response.status_code}.{detail}",
|
|
46
|
+
status=response.status_code,
|
|
47
|
+
method=method,
|
|
48
|
+
path=path,
|
|
49
|
+
detail=detail.strip(),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def _transport_failure(self, error: httpx.HTTPError | httpx.InvalidURL, method: str, path: str) -> WflowError:
|
|
53
|
+
return WflowError(
|
|
54
|
+
f"wflow {self._host} {method} {path} failed: {type(error).__name__}{f': {error}' if str(error) else ''}."
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
async def request(self, method: str, path: str, *, timeout: float | None = None, **kwargs: Any) -> Any:
|
|
58
|
+
headers = {**await self._signed(), "Accept": "application/json"}
|
|
59
|
+
try:
|
|
60
|
+
async with self._http(self._timeout if timeout is None else timeout) as http:
|
|
61
|
+
response = await http.request(method, path, headers=headers, **kwargs)
|
|
62
|
+
except (httpx.HTTPError, httpx.InvalidURL) as error:
|
|
63
|
+
raise self._transport_failure(error, method, path) from error
|
|
64
|
+
if not response.is_success:
|
|
65
|
+
raise self._failure(response, method, path)
|
|
66
|
+
if not response.content:
|
|
67
|
+
return None
|
|
68
|
+
try:
|
|
69
|
+
return response.json()
|
|
70
|
+
except ValueError as error:
|
|
71
|
+
raise WflowError(
|
|
72
|
+
f"wflow {self._host} {method} {path} returned a {response.status_code} that was not JSON."
|
|
73
|
+
) from error
|
|
74
|
+
|
|
75
|
+
async def upload(
|
|
76
|
+
self,
|
|
77
|
+
method: str,
|
|
78
|
+
path: str,
|
|
79
|
+
filename: str,
|
|
80
|
+
content: bytes,
|
|
81
|
+
params: dict[str, object] | None = None,
|
|
82
|
+
field: str = "file",
|
|
83
|
+
) -> Any:
|
|
84
|
+
return await self.request(
|
|
85
|
+
method, path, params=params or {}, files={field: (filename, content)}, timeout=UPLOAD_TIMEOUT
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
async def download(
|
|
89
|
+
self, path: str, method: str = "GET", json: Any = None, max_bytes: int | None = None
|
|
90
|
+
) -> FileContent:
|
|
91
|
+
headers = await self._signed()
|
|
92
|
+
try:
|
|
93
|
+
async with (
|
|
94
|
+
self._http(DOWNLOAD_TIMEOUT) as http,
|
|
95
|
+
http.stream(method, path, headers=headers, json=json) as response,
|
|
96
|
+
):
|
|
97
|
+
if response.is_error:
|
|
98
|
+
await response.aread()
|
|
99
|
+
raise self._failure(response, method, path)
|
|
100
|
+
if response.status_code != 200:
|
|
101
|
+
await response.aread()
|
|
102
|
+
if response.status_code == 204:
|
|
103
|
+
raise WflowError(
|
|
104
|
+
f"wflow {self._host} {method} {path} returned 204: wflow holds no content for that file."
|
|
105
|
+
)
|
|
106
|
+
raise WflowError(f"wflow {self._host} {method} {path} returned {response.status_code}, not 200.")
|
|
107
|
+
try:
|
|
108
|
+
declared = int(response.headers.get("content-length") or 0)
|
|
109
|
+
except ValueError:
|
|
110
|
+
raise WflowError(f"wflow {self._host} {method} {path} sent a non-numeric Content-Length.") from None
|
|
111
|
+
if max_bytes is not None and declared > max_bytes:
|
|
112
|
+
raise WflowError(
|
|
113
|
+
f"The file at {path} is {declared} bytes, over the {max_bytes}-byte limit set for this download."
|
|
114
|
+
)
|
|
115
|
+
chunks: list[bytes] = []
|
|
116
|
+
size = 0
|
|
117
|
+
async for chunk in response.aiter_bytes():
|
|
118
|
+
size += len(chunk)
|
|
119
|
+
if max_bytes is not None and size > max_bytes:
|
|
120
|
+
raise WflowError(
|
|
121
|
+
f"The file at {path} is over the {max_bytes}-byte limit set for this download."
|
|
122
|
+
)
|
|
123
|
+
chunks.append(chunk)
|
|
124
|
+
return FileContent(
|
|
125
|
+
filename=filename_from_disposition(response.headers.get("content-disposition", "")),
|
|
126
|
+
content_type=response.headers.get("content-type"),
|
|
127
|
+
content=b"".join(chunks),
|
|
128
|
+
)
|
|
129
|
+
except (httpx.HTTPError, httpx.InvalidURL) as error:
|
|
130
|
+
raise self._transport_failure(error, method, path) from error
|
wflow_api/errors.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class WflowError(Exception):
|
|
2
|
+
"""A wflow call that could not be made or did not succeed."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class WflowApiError(WflowError):
|
|
6
|
+
"""wflow answered with an error status."""
|
|
7
|
+
|
|
8
|
+
def __init__(self, message: str, *, status: int, method: str, path: str, detail: str) -> None:
|
|
9
|
+
super().__init__(message)
|
|
10
|
+
self.status = status
|
|
11
|
+
self.method = method
|
|
12
|
+
self.path = path
|
|
13
|
+
self.detail = detail
|
wflow_api/guards.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Checks every operation relies on: arguments, write bodies, and what wflow sends back."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from email.message import Message
|
|
5
|
+
from typing import TYPE_CHECKING, Any
|
|
6
|
+
from urllib.parse import quote
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from wflow_api.errors import WflowError
|
|
11
|
+
from wflow_api.models.account import Account
|
|
12
|
+
from wflow_api.models.common import WflowModel
|
|
13
|
+
from wflow_api.models.documents import Property
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from wflow_api.client import WflowClient
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def query_params(**kwargs: object) -> dict[str, object]:
|
|
20
|
+
return {name: value for name, value in kwargs.items() if value is not None}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def path_segment(value: str) -> str:
|
|
24
|
+
if value and not value.strip("."):
|
|
25
|
+
raise WflowError(
|
|
26
|
+
f"{value!r} is not a usable path segment: a run of dots is resolved away before the request "
|
|
27
|
+
"leaves, so the call would land on the parent record and report success against it. Pass the "
|
|
28
|
+
"identifier the paired read hands back."
|
|
29
|
+
)
|
|
30
|
+
return quote(value, safe="")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _unknown_fields(item: WflowModel, path: str) -> list[str]:
|
|
34
|
+
unknown = [f"{path}{name}" for name in item.model_extra or {}]
|
|
35
|
+
for name in type(item).model_fields:
|
|
36
|
+
value = getattr(item, name)
|
|
37
|
+
for index, nested in enumerate(value if isinstance(value, list) else [value]):
|
|
38
|
+
if isinstance(nested, WflowModel):
|
|
39
|
+
position = f"[{index}]" if isinstance(value, list) else ""
|
|
40
|
+
unknown += _unknown_fields(nested, f"{path}{name}{position}.")
|
|
41
|
+
return unknown
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _refuse_unknown(unknown: list[str]) -> None:
|
|
45
|
+
if unknown:
|
|
46
|
+
raise WflowError(
|
|
47
|
+
f"Unknown field(s) in the payload: {', '.join(unknown)}. wflow ignores JSON members it does "
|
|
48
|
+
"not recognise, so the write would report success while those values never arrive — and on a "
|
|
49
|
+
"whole-record write any field one of them was meant to set is cleared instead. Correct the "
|
|
50
|
+
"spelling, or drop the field: only the fields the model declares can be written."
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _indexed_unknown(items: Sequence[WflowModel]) -> list[str]:
|
|
55
|
+
return [name for index, item in enumerate(items) for name in _unknown_fields(item, f"[{index}].")]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def write_body(items: Sequence[WflowModel]) -> list[dict[str, Any]]:
|
|
59
|
+
if not items:
|
|
60
|
+
raise WflowError(
|
|
61
|
+
"Refusing to send an empty list of records: it can neither add nor update anything, and on "
|
|
62
|
+
"an update_register_* call it would mark every record in the register invalid. To retire "
|
|
63
|
+
"records deliberately, send them to the matching patch_register_* operation with isValid: false "
|
|
64
|
+
"— and keep that field in every later payload naming them, because it defaults to true and a "
|
|
65
|
+
"write that omits it revives the record."
|
|
66
|
+
)
|
|
67
|
+
_refuse_unknown(_indexed_unknown(items))
|
|
68
|
+
return [item.model_dump(exclude_none=True) for item in items]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def write_json(item: WflowModel) -> dict[str, Any]:
|
|
72
|
+
_refuse_unknown(_unknown_fields(item, ""))
|
|
73
|
+
return item.model_dump(mode="json", exclude_none=True)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def write_json_list(items: Sequence[WflowModel], *, allow_empty: bool = False) -> list[dict[str, Any]]:
|
|
77
|
+
if not items and not allow_empty:
|
|
78
|
+
raise WflowError(
|
|
79
|
+
"Refusing to send an empty list: this endpoint replaces the whole set, so it would clear "
|
|
80
|
+
"everything currently held rather than change nothing, and wflow keeps no version history to "
|
|
81
|
+
"restore it from. An empty list is also what payload construction yields when it yields nothing "
|
|
82
|
+
"— a read that came back empty, a filter that matched no rows. Send the records you mean to "
|
|
83
|
+
"keep; to remove one deliberately, use the matching delete_* operation where the endpoint has one."
|
|
84
|
+
)
|
|
85
|
+
_refuse_unknown(_indexed_unknown(items))
|
|
86
|
+
return [item.model_dump(mode="json", exclude_none=True) for item in items]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def write_definitions_json(properties: Sequence[Property], *, values_operation: str) -> list[dict[str, Any]]:
|
|
90
|
+
undefined = [f"[{index}]" for index, item in enumerate(properties) if not item.carries_definition()]
|
|
91
|
+
if undefined:
|
|
92
|
+
raise WflowError(
|
|
93
|
+
f"Entries {', '.join(undefined)} carry no `name` and `type`. wflow refuses the whole list over "
|
|
94
|
+
f"such an entry, so nothing was sent. Give every entry its `name` and `type`, or set values on "
|
|
95
|
+
f"already-defined properties with {values_operation}."
|
|
96
|
+
)
|
|
97
|
+
return write_json_list(properties)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def ensure_list(path: str, payload: Any) -> list[Any]:
|
|
101
|
+
if not isinstance(payload, list):
|
|
102
|
+
raise WflowError(f"wflow GET {path} returned {payload!r}, not an array.")
|
|
103
|
+
return payload
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def problem_detail(response: httpx.Response) -> str:
|
|
107
|
+
try:
|
|
108
|
+
body = response.json()
|
|
109
|
+
except ValueError:
|
|
110
|
+
return ""
|
|
111
|
+
if not isinstance(body, dict):
|
|
112
|
+
return ""
|
|
113
|
+
parts = [str(body[key]) for key in ("title", "detail") if body.get(key)]
|
|
114
|
+
return f" {' — '.join(parts)}" if parts else ""
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def filename_from_disposition(header: str) -> str | None:
|
|
118
|
+
message = Message()
|
|
119
|
+
message["content-disposition"] = header
|
|
120
|
+
return message.get_filename() or None
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
async def current_account(client: "WflowClient", organization: str) -> Account:
|
|
124
|
+
payload = await client.request("GET", f"/api/{organization}/account")
|
|
125
|
+
if payload is None:
|
|
126
|
+
raise WflowError(
|
|
127
|
+
f"wflow returned an empty account for organization '{organization}' "
|
|
128
|
+
"(HTTP 200, body `null`). This endpoint reports the *current user*, so the "
|
|
129
|
+
"signed-in identity has no account in that workspace. Use list_organizations "
|
|
130
|
+
"to see which slugs are visible."
|
|
131
|
+
)
|
|
132
|
+
return Account.model_validate(payload)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Typed responses, mirroring the schemas in the wflow OpenAPI spec."""
|
|
2
|
+
|
|
3
|
+
from wflow_api.models.account import (
|
|
4
|
+
Account,
|
|
5
|
+
DocumentTypeBase,
|
|
6
|
+
Identity,
|
|
7
|
+
Organization,
|
|
8
|
+
OrganizationDomain,
|
|
9
|
+
OrganizationSettings,
|
|
10
|
+
RoleBase,
|
|
11
|
+
TeamBase,
|
|
12
|
+
TypePermission,
|
|
13
|
+
UserFull,
|
|
14
|
+
)
|
|
15
|
+
from wflow_api.models.admin import (
|
|
16
|
+
ApprovalsTemplate,
|
|
17
|
+
ApprovalsTemplateFull,
|
|
18
|
+
ApprovalsTemplatesTeam,
|
|
19
|
+
Role,
|
|
20
|
+
Team,
|
|
21
|
+
User,
|
|
22
|
+
WebHookRegistration,
|
|
23
|
+
)
|
|
24
|
+
from wflow_api.models.common import (
|
|
25
|
+
FileContent,
|
|
26
|
+
OrgSlug,
|
|
27
|
+
Page,
|
|
28
|
+
Paged,
|
|
29
|
+
PageSize,
|
|
30
|
+
Query,
|
|
31
|
+
Search,
|
|
32
|
+
Sort,
|
|
33
|
+
WflowModel,
|
|
34
|
+
WriteResult,
|
|
35
|
+
)
|
|
36
|
+
from wflow_api.models.registers import (
|
|
37
|
+
AddressType,
|
|
38
|
+
BusinessItemUpdateC,
|
|
39
|
+
KindRegister,
|
|
40
|
+
Location,
|
|
41
|
+
NoCodeRegisterBase,
|
|
42
|
+
OrganizationPerson,
|
|
43
|
+
PartnerAccount,
|
|
44
|
+
PartnerFull,
|
|
45
|
+
PartnerPeppolId,
|
|
46
|
+
PartnerPersonUpdateC,
|
|
47
|
+
PaymentMethods,
|
|
48
|
+
Register,
|
|
49
|
+
RegisterBase,
|
|
50
|
+
RegisterId,
|
|
51
|
+
Serie,
|
|
52
|
+
VATReturnLine,
|
|
53
|
+
)
|
|
54
|
+
from wflow_api.models.requests import (
|
|
55
|
+
ApiClientResult,
|
|
56
|
+
ApprovalsTemplateTeams,
|
|
57
|
+
ApprovalsTemplateUpdate,
|
|
58
|
+
DocumentUpdate,
|
|
59
|
+
IdType,
|
|
60
|
+
PaymentCreate,
|
|
61
|
+
PropertyUpdate,
|
|
62
|
+
RoleUpdate,
|
|
63
|
+
StorageFolderUpdate,
|
|
64
|
+
StructuredFilter,
|
|
65
|
+
TeamUpdate,
|
|
66
|
+
UserUpdate,
|
|
67
|
+
)
|
|
68
|
+
from wflow_api.models.storage import StorageFile, StorageFolder
|
|
69
|
+
|
|
70
|
+
__all__ = [
|
|
71
|
+
"Account", # alias of UserFull, kept for the existing get_me annotation
|
|
72
|
+
"AddressType",
|
|
73
|
+
"ApiClientResult",
|
|
74
|
+
"ApprovalsTemplate",
|
|
75
|
+
"ApprovalsTemplateFull",
|
|
76
|
+
"ApprovalsTemplateTeams",
|
|
77
|
+
"ApprovalsTemplateUpdate",
|
|
78
|
+
"ApprovalsTemplatesTeam",
|
|
79
|
+
"BusinessItemUpdateC",
|
|
80
|
+
"DocumentTypeBase",
|
|
81
|
+
"DocumentUpdate",
|
|
82
|
+
"FileContent",
|
|
83
|
+
"IdType",
|
|
84
|
+
"Identity",
|
|
85
|
+
"KindRegister",
|
|
86
|
+
"Location",
|
|
87
|
+
"NoCodeRegisterBase",
|
|
88
|
+
"OrgSlug",
|
|
89
|
+
"Organization",
|
|
90
|
+
"OrganizationDomain",
|
|
91
|
+
"OrganizationPerson",
|
|
92
|
+
"OrganizationSettings",
|
|
93
|
+
"Page",
|
|
94
|
+
"PageSize",
|
|
95
|
+
"Paged",
|
|
96
|
+
"PartnerAccount",
|
|
97
|
+
"PartnerFull",
|
|
98
|
+
"PartnerPeppolId",
|
|
99
|
+
"PartnerPersonUpdateC",
|
|
100
|
+
"PaymentCreate",
|
|
101
|
+
"PaymentMethods",
|
|
102
|
+
"PropertyUpdate",
|
|
103
|
+
"Query",
|
|
104
|
+
"Register",
|
|
105
|
+
"RegisterBase",
|
|
106
|
+
"RegisterId",
|
|
107
|
+
"Role",
|
|
108
|
+
"RoleBase",
|
|
109
|
+
"RoleUpdate",
|
|
110
|
+
"Search",
|
|
111
|
+
"Serie",
|
|
112
|
+
"Sort",
|
|
113
|
+
"StorageFile",
|
|
114
|
+
"StorageFolder",
|
|
115
|
+
"StorageFolderUpdate",
|
|
116
|
+
"StructuredFilter",
|
|
117
|
+
"Team",
|
|
118
|
+
"TeamBase",
|
|
119
|
+
"TeamUpdate",
|
|
120
|
+
"TypePermission",
|
|
121
|
+
"User",
|
|
122
|
+
"UserFull",
|
|
123
|
+
"UserUpdate",
|
|
124
|
+
"VATReturnLine",
|
|
125
|
+
"WebHookRegistration",
|
|
126
|
+
"WflowModel",
|
|
127
|
+
"WriteResult",
|
|
128
|
+
]
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Account and organization models, mirroring the schemas in the wflow OpenAPI spec."""
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
5
|
+
from wflow_api.models.common import WflowModel, WflowTimestamp
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OrganizationDomain(WflowModel):
|
|
9
|
+
"""A workspace the signed-in user has access to, as listed by list_organizations.
|
|
10
|
+
|
|
11
|
+
Distinct from Organization, which is one workspace's own detail.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
name: str | None = None
|
|
15
|
+
baseURL: str | None = Field(default=None, description='Host, e.g. "nonameorg.wflow.com"')
|
|
16
|
+
subdomain: str | None = Field(default=None, description="Workspace slug; pass as `organization`")
|
|
17
|
+
trialExpiration: WflowTimestamp | None = Field(default=None, description="Null when not on a trial")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Identity(WflowModel):
|
|
21
|
+
id: str | None = None
|
|
22
|
+
login: str | None = None
|
|
23
|
+
firstName: str | None = None
|
|
24
|
+
lastName: str | None = None
|
|
25
|
+
fullName: str | None = None
|
|
26
|
+
language: str | None = Field(default=None, description="ISO 639-1 code")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class RoleBase(WflowModel):
|
|
30
|
+
id: str | None = None
|
|
31
|
+
name: str | None = None
|
|
32
|
+
description: str | None = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TeamBase(WflowModel):
|
|
36
|
+
id: str | None = None
|
|
37
|
+
name: str | None = None
|
|
38
|
+
description: str | None = None
|
|
39
|
+
system: bool | None = Field(default=None, description="Built-in, not organization-created")
|
|
40
|
+
# get_document_rights sends this; declared so its read-then-PUT-back round-trip is not refused.
|
|
41
|
+
fromApprovalTemplate: bool | None = Field(
|
|
42
|
+
default=None, description="Access came from an approval template rather than being set directly"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class DocumentTypeBase(WflowModel):
|
|
47
|
+
id: str | None = None
|
|
48
|
+
name: str | None = None
|
|
49
|
+
kind: str | None = Field(default=None, description="e.g. IncomingInvoice, Contract")
|
|
50
|
+
default: bool | None = None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class TypePermission(WflowModel):
|
|
54
|
+
documentType: DocumentTypeBase | None = None
|
|
55
|
+
permission: str | None = Field(default=None, description="All, OnlyAssigned or FullAccess")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class UserFull(WflowModel):
|
|
59
|
+
"""The profile of the authenticated user within one organization."""
|
|
60
|
+
|
|
61
|
+
id: str | None = None
|
|
62
|
+
identity: Identity | None = None
|
|
63
|
+
created: WflowTimestamp | None = None
|
|
64
|
+
hasFullAccess: bool | None = None
|
|
65
|
+
roles: list[RoleBase] | None = None
|
|
66
|
+
teams: list[TeamBase] | None = None
|
|
67
|
+
documentTypes: list[TypePermission] | None = Field(default=None, description="Per document type access")
|
|
68
|
+
rights: list[str] | None = Field(default=None, description="e.g. CanApprove, CanCreateDocument")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Account = UserFull
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Organization(WflowModel):
|
|
75
|
+
"""The workspace's own identity, as returned by get_organization."""
|
|
76
|
+
|
|
77
|
+
id: str | None = Field(default=None, description="Id")
|
|
78
|
+
name: str | None = Field(default=None, description="Name")
|
|
79
|
+
created: WflowTimestamp | None = Field(default=None, description="Creation date (yyyy-mm-ddThh:mm:ss.ffffff)")
|
|
80
|
+
organizationUrlPart: str | None = Field(default=None, description="Organization part in URL")
|
|
81
|
+
customerUrlPart: str | None = Field(default=None, description="Customer part in URL")
|
|
82
|
+
vatCountry: str | None = Field(default=None, description="VAT registration country ISO code (fixed length 3 chars)")
|
|
83
|
+
vatNonPayer: bool | None = None
|
|
84
|
+
seriesOnDocument: bool | None = None
|
|
85
|
+
acceptDateAsCreatedDate: bool | None = None
|
|
86
|
+
allowSupportAccess: bool | None = None
|
|
87
|
+
trialExpiration: WflowTimestamp | None = None
|
|
88
|
+
authenticationPolicy: str | None = Field(
|
|
89
|
+
default=None, description="One of: MultiFactor, MicrosoftSingleSign, GoogleSingleSign"
|
|
90
|
+
)
|
|
91
|
+
biDashboardStatus: str | None = Field(default=None, description="One of: None, InPreparation, Active")
|
|
92
|
+
biDashboardTrialExpires: WflowTimestamp | None = Field(
|
|
93
|
+
default=None, description="Gets or sets the bi dashboard trial expires."
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class OrganizationSettings(WflowModel):
|
|
98
|
+
"""How the workspace processes documents, as returned by get_organization_settings."""
|
|
99
|
+
|
|
100
|
+
name: str | None = None
|
|
101
|
+
vatCountry: str | None = None
|
|
102
|
+
vatNonPayer: bool | None = None
|
|
103
|
+
seriesOnDocument: bool | None = None
|
|
104
|
+
acceptDateAsCreatedDate: bool | None = None
|
|
105
|
+
defaultLanguage: str | None = None
|
|
106
|
+
allowSupportAccess: bool | None = None
|
|
107
|
+
autoCloneLastDocumentAccounting: bool | None = None
|
|
108
|
+
settings: str | None = None
|
|
109
|
+
autoLinkIISD: bool | None = None
|
|
110
|
+
autoLinkTakeLinesIISD: bool | None = None
|
|
111
|
+
autoLinkTakeAccountingIISD: bool | None = None
|
|
112
|
+
shareApproveIISD: bool | None = None
|
|
113
|
+
shareApproveIISDTolerance: float | None = None
|
|
114
|
+
numberOnlyIISD: bool | None = None
|
|
115
|
+
autoLinkIISDToleranceRate: int | None = None
|
|
116
|
+
processIsdoc: bool | None = None
|
|
117
|
+
processIsdocLines: bool | None = None
|
|
118
|
+
processIsdocDescription: bool | None = None
|
|
119
|
+
processEKasa: bool | None = None
|
|
120
|
+
processEKasaLines: bool | None = None
|
|
121
|
+
sortDocumentsByIc: bool | None = None
|
|
122
|
+
enableLinesApproval: bool | None = None
|
|
123
|
+
autoLinkPartner: bool | None = None
|
|
124
|
+
autoGenerateMissingPDFForISDOC: bool | None = None
|
|
125
|
+
vatInclusiveBudgets: bool | None = None
|
|
126
|
+
trialExpiration: WflowTimestamp | None = Field(default=None, description="Gets or sets the trial expiration date.")
|
|
127
|
+
fiscalYearStart: int | None = None
|