matelab-python-sdk 0.1.0a2__py3-none-any.whl → 0.1.0a3__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.
- matelab/__init__.py +0 -68
- matelab/_transport.py +12 -12
- matelab/client.py +17 -24
- matelab/cloud_drive.py +48 -210
- matelab/groups.py +3 -5
- matelab/{literature.py → literature/__init__.py} +64 -233
- matelab/notebooks.py +33 -124
- matelab/{records.py → records/__init__.py} +100 -350
- matelab/streaming.py +3 -3
- matelab/templates.py +62 -188
- matelab/uploads.py +13 -38
- matelab/users.py +3 -6
- {matelab_python_sdk-0.1.0a2.dist-info → matelab_python_sdk-0.1.0a3.dist-info}/METADATA +76 -82
- matelab_python_sdk-0.1.0a3.dist-info/RECORD +22 -0
- matelab_python_sdk-0.1.0a2.dist-info/RECORD +0 -22
- {matelab_python_sdk-0.1.0a2.dist-info → matelab_python_sdk-0.1.0a3.dist-info}/WHEEL +0 -0
- {matelab_python_sdk-0.1.0a2.dist-info → matelab_python_sdk-0.1.0a3.dist-info}/licenses/LICENSE +0 -0
- {matelab_python_sdk-0.1.0a2.dist-info → matelab_python_sdk-0.1.0a3.dist-info}/licenses/NOTICE +0 -0
matelab/__init__.py
CHANGED
|
@@ -8,16 +8,10 @@ from matelab.cloud_drive import (
|
|
|
8
8
|
CloudDriveRootPermissions,
|
|
9
9
|
CloudDriveRootRef,
|
|
10
10
|
CloudFile,
|
|
11
|
-
CloudFileBindResult,
|
|
12
|
-
CloudFileMoveResult,
|
|
13
11
|
CloudFilePage,
|
|
14
|
-
CloudFilePermanentDeleteResult,
|
|
15
12
|
CloudFileRef,
|
|
16
|
-
CloudFileUpdateResult,
|
|
17
13
|
CloudFolder,
|
|
18
|
-
CloudFolderDeleteResult,
|
|
19
14
|
CloudFolderMetadata,
|
|
20
|
-
CloudFolderMoveResult,
|
|
21
15
|
CloudFolderRef,
|
|
22
16
|
CloudFolderSaveResult,
|
|
23
17
|
CloudFolderTree,
|
|
@@ -38,11 +32,8 @@ from matelab.literature import (
|
|
|
38
32
|
ExtractedLiteratureMetadata,
|
|
39
33
|
LiteratureCitation,
|
|
40
34
|
LiteratureComment,
|
|
41
|
-
LiteratureCommentDeleteResult,
|
|
42
35
|
LiteratureCommentDraft,
|
|
43
36
|
LiteratureCommentRef,
|
|
44
|
-
LiteratureCommentSaveResult,
|
|
45
|
-
LiteratureCreateResult,
|
|
46
37
|
LiteratureCreationSchema,
|
|
47
38
|
LiteratureDetail,
|
|
48
39
|
LiteratureField,
|
|
@@ -56,13 +47,8 @@ from matelab.literature import (
|
|
|
56
47
|
LiteratureNestedField,
|
|
57
48
|
LiteraturePage,
|
|
58
49
|
LiteraturePdf,
|
|
59
|
-
LiteraturePdfDeleteResult,
|
|
60
|
-
LiteraturePdfReplaceResult,
|
|
61
|
-
LiteraturePermanentDeleteResult,
|
|
62
|
-
LiteratureShareResult,
|
|
63
50
|
LiteratureSource,
|
|
64
51
|
LiteratureStoredMetadata,
|
|
65
|
-
LiteratureUpdateResult,
|
|
66
52
|
PendingLiteratureShare,
|
|
67
53
|
PendingLiteratureShareComment,
|
|
68
54
|
PendingLiteratureShareRef,
|
|
@@ -75,24 +61,18 @@ from matelab.literature import (
|
|
|
75
61
|
from matelab.models import Identity, Session, Token
|
|
76
62
|
from matelab.notebooks import (
|
|
77
63
|
NotebookCollection,
|
|
78
|
-
NotebookCreateResult,
|
|
79
64
|
NotebookListField,
|
|
80
65
|
NotebookMetadata,
|
|
81
66
|
NotebookRef,
|
|
82
67
|
NotebookShare,
|
|
83
68
|
NotebookSharePermissionGrant,
|
|
84
69
|
NotebookShareRef,
|
|
85
|
-
NotebookShareResult,
|
|
86
70
|
NotebookShares,
|
|
87
|
-
NotebookShareUpdateResult,
|
|
88
71
|
NotebookSummary,
|
|
89
|
-
NotebookUnshareResult,
|
|
90
|
-
NotebookUpdateResult,
|
|
91
72
|
PublicNotebookRef,
|
|
92
73
|
PublicNotebookSummary,
|
|
93
74
|
)
|
|
94
75
|
from matelab.records import (
|
|
95
|
-
BlankRecordCreateResult,
|
|
96
76
|
DeletedRecordPage,
|
|
97
77
|
DeletedRecordRef,
|
|
98
78
|
DeletedRecordSummary,
|
|
@@ -106,11 +86,9 @@ from matelab.records import (
|
|
|
106
86
|
RecordCollection,
|
|
107
87
|
RecordComment,
|
|
108
88
|
RecordCommentAttachmentRef,
|
|
109
|
-
RecordCommentDeleteResult,
|
|
110
89
|
RecordCommentDraft,
|
|
111
90
|
RecordCommentRef,
|
|
112
91
|
RecordComments,
|
|
113
|
-
RecordCommentSaveResult,
|
|
114
92
|
RecordCopyResult,
|
|
115
93
|
RecordDeleteResult,
|
|
116
94
|
RecordExport,
|
|
@@ -132,8 +110,6 @@ from matelab.records import (
|
|
|
132
110
|
RecordPatch,
|
|
133
111
|
RecordRef,
|
|
134
112
|
RecordRelation,
|
|
135
|
-
RecordRelationAddResult,
|
|
136
|
-
RecordRelationDeleteResult,
|
|
137
113
|
RecordRelationRef,
|
|
138
114
|
RecordRelations,
|
|
139
115
|
RecordRestoreResult,
|
|
@@ -159,30 +135,20 @@ from matelab.streaming import ByteRange, DownloadStream
|
|
|
159
135
|
from matelab.templates import (
|
|
160
136
|
TemplateCollection,
|
|
161
137
|
TemplateContent,
|
|
162
|
-
TemplateContentSaveResult,
|
|
163
|
-
TemplateCopyResult,
|
|
164
|
-
TemplateGroupAddResult,
|
|
165
|
-
TemplateGroupRemoveResult,
|
|
166
|
-
TemplateIntroUpdateResult,
|
|
167
138
|
TemplateLibraryEntryRef,
|
|
168
139
|
TemplateLibraryRelationKind,
|
|
169
|
-
TemplateLibraryRemovalResult,
|
|
170
|
-
TemplateMarketAcquireResult,
|
|
171
140
|
TemplateMarketEntry,
|
|
172
141
|
TemplateMarketPage,
|
|
173
|
-
TemplateMarketSubmissionResult,
|
|
174
142
|
TemplateMetadata,
|
|
175
143
|
TemplateMetadataResult,
|
|
176
144
|
TemplateModule,
|
|
177
145
|
TemplateRef,
|
|
178
|
-
TemplateShareResult,
|
|
179
146
|
TemplateSource,
|
|
180
147
|
TemplateSummary,
|
|
181
148
|
)
|
|
182
149
|
from matelab.uploads import (
|
|
183
150
|
StagedFile,
|
|
184
151
|
StagedFileFragment,
|
|
185
|
-
StagedUploadAbortResult,
|
|
186
152
|
StagedUploadSession,
|
|
187
153
|
UploadBindingRef,
|
|
188
154
|
)
|
|
@@ -190,7 +156,6 @@ from matelab.users import UserRef, UserSearchResult, UserSearchScope, UserSummar
|
|
|
190
156
|
|
|
191
157
|
__all__ = [
|
|
192
158
|
"AsyncMatelab",
|
|
193
|
-
"BlankRecordCreateResult",
|
|
194
159
|
"ByteRange",
|
|
195
160
|
"CloudDriveListing",
|
|
196
161
|
"CloudDriveLocation",
|
|
@@ -200,16 +165,10 @@ __all__ = [
|
|
|
200
165
|
"CloudDriveRootPermissions",
|
|
201
166
|
"CloudDriveRootRef",
|
|
202
167
|
"CloudFile",
|
|
203
|
-
"CloudFileBindResult",
|
|
204
|
-
"CloudFileMoveResult",
|
|
205
168
|
"CloudFilePage",
|
|
206
|
-
"CloudFilePermanentDeleteResult",
|
|
207
169
|
"CloudFileRef",
|
|
208
|
-
"CloudFileUpdateResult",
|
|
209
170
|
"CloudFolder",
|
|
210
|
-
"CloudFolderDeleteResult",
|
|
211
171
|
"CloudFolderMetadata",
|
|
212
|
-
"CloudFolderMoveResult",
|
|
213
172
|
"CloudFolderRef",
|
|
214
173
|
"CloudFolderSaveResult",
|
|
215
174
|
"CloudFolderTree",
|
|
@@ -228,11 +187,8 @@ __all__ = [
|
|
|
228
187
|
"Identity",
|
|
229
188
|
"LiteratureCitation",
|
|
230
189
|
"LiteratureComment",
|
|
231
|
-
"LiteratureCommentDeleteResult",
|
|
232
190
|
"LiteratureCommentDraft",
|
|
233
191
|
"LiteratureCommentRef",
|
|
234
|
-
"LiteratureCommentSaveResult",
|
|
235
|
-
"LiteratureCreateResult",
|
|
236
192
|
"LiteratureCreationSchema",
|
|
237
193
|
"LiteratureDetail",
|
|
238
194
|
"LiteratureField",
|
|
@@ -246,13 +202,8 @@ __all__ = [
|
|
|
246
202
|
"LiteratureNestedField",
|
|
247
203
|
"LiteraturePage",
|
|
248
204
|
"LiteraturePdf",
|
|
249
|
-
"LiteraturePdfDeleteResult",
|
|
250
|
-
"LiteraturePdfReplaceResult",
|
|
251
|
-
"LiteraturePermanentDeleteResult",
|
|
252
|
-
"LiteratureShareResult",
|
|
253
205
|
"LiteratureSource",
|
|
254
206
|
"LiteratureStoredMetadata",
|
|
255
|
-
"LiteratureUpdateResult",
|
|
256
207
|
"MatelabAuthenticationError",
|
|
257
208
|
"MatelabError",
|
|
258
209
|
"MatelabProtocolError",
|
|
@@ -261,19 +212,14 @@ __all__ = [
|
|
|
261
212
|
"MatelabUsageError",
|
|
262
213
|
"MatelabVerificationError",
|
|
263
214
|
"NotebookCollection",
|
|
264
|
-
"NotebookCreateResult",
|
|
265
215
|
"NotebookListField",
|
|
266
216
|
"NotebookMetadata",
|
|
267
217
|
"NotebookRef",
|
|
268
218
|
"NotebookShare",
|
|
269
219
|
"NotebookSharePermissionGrant",
|
|
270
220
|
"NotebookShareRef",
|
|
271
|
-
"NotebookShareResult",
|
|
272
|
-
"NotebookShareUpdateResult",
|
|
273
221
|
"NotebookShares",
|
|
274
222
|
"NotebookSummary",
|
|
275
|
-
"NotebookUnshareResult",
|
|
276
|
-
"NotebookUpdateResult",
|
|
277
223
|
"PendingLiteratureShare",
|
|
278
224
|
"PendingLiteratureShareComment",
|
|
279
225
|
"PendingLiteratureShareRef",
|
|
@@ -290,10 +236,8 @@ __all__ = [
|
|
|
290
236
|
"RecordCollection",
|
|
291
237
|
"RecordComment",
|
|
292
238
|
"RecordCommentAttachmentRef",
|
|
293
|
-
"RecordCommentDeleteResult",
|
|
294
239
|
"RecordCommentDraft",
|
|
295
240
|
"RecordCommentRef",
|
|
296
|
-
"RecordCommentSaveResult",
|
|
297
241
|
"RecordComments",
|
|
298
242
|
"RecordCopyResult",
|
|
299
243
|
"RecordDeleteResult",
|
|
@@ -316,8 +260,6 @@ __all__ = [
|
|
|
316
260
|
"RecordPatch",
|
|
317
261
|
"RecordRef",
|
|
318
262
|
"RecordRelation",
|
|
319
|
-
"RecordRelationAddResult",
|
|
320
|
-
"RecordRelationDeleteResult",
|
|
321
263
|
"RecordRelationRef",
|
|
322
264
|
"RecordRelations",
|
|
323
265
|
"RecordRestoreResult",
|
|
@@ -344,27 +286,17 @@ __all__ = [
|
|
|
344
286
|
"StagedPdfMetadataSource",
|
|
345
287
|
"StagedRecordAttachment",
|
|
346
288
|
"StagedRecordCommentAttachment",
|
|
347
|
-
"StagedUploadAbortResult",
|
|
348
289
|
"StagedUploadSession",
|
|
349
290
|
"TemplateCollection",
|
|
350
291
|
"TemplateContent",
|
|
351
|
-
"TemplateContentSaveResult",
|
|
352
|
-
"TemplateCopyResult",
|
|
353
|
-
"TemplateGroupAddResult",
|
|
354
|
-
"TemplateGroupRemoveResult",
|
|
355
|
-
"TemplateIntroUpdateResult",
|
|
356
292
|
"TemplateLibraryEntryRef",
|
|
357
293
|
"TemplateLibraryRelationKind",
|
|
358
|
-
"TemplateLibraryRemovalResult",
|
|
359
|
-
"TemplateMarketAcquireResult",
|
|
360
294
|
"TemplateMarketEntry",
|
|
361
295
|
"TemplateMarketPage",
|
|
362
|
-
"TemplateMarketSubmissionResult",
|
|
363
296
|
"TemplateMetadata",
|
|
364
297
|
"TemplateMetadataResult",
|
|
365
298
|
"TemplateModule",
|
|
366
299
|
"TemplateRef",
|
|
367
|
-
"TemplateShareResult",
|
|
368
300
|
"TemplateSource",
|
|
369
301
|
"TemplateSummary",
|
|
370
302
|
"Token",
|
matelab/_transport.py
CHANGED
|
@@ -7,10 +7,10 @@ from dataclasses import dataclass
|
|
|
7
7
|
from enum import StrEnum
|
|
8
8
|
from typing import IO, Generic, TypeAlias, TypeVar, cast
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import httpx2
|
|
11
11
|
from pydantic import BaseModel, ValidationError
|
|
12
12
|
|
|
13
|
-
from matelab._generated
|
|
13
|
+
from matelab._generated import models as wire_models
|
|
14
14
|
from matelab.errors import (
|
|
15
15
|
MatelabAuthenticationError,
|
|
16
16
|
MatelabProtocolError,
|
|
@@ -152,7 +152,7 @@ _REFRESH_TOKENS = Operation(
|
|
|
152
152
|
method="POST",
|
|
153
153
|
path="/tokens/tokens_refresh",
|
|
154
154
|
encoding=Encoding.FORM,
|
|
155
|
-
response_model=TokenRefreshResponse,
|
|
155
|
+
response_model=wire_models.TokenRefreshResponse,
|
|
156
156
|
success_codes=frozenset({0}),
|
|
157
157
|
authenticated=False,
|
|
158
158
|
authentication_errors=True,
|
|
@@ -160,8 +160,8 @@ _REFRESH_TOKENS = Operation(
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
class SessionTransport:
|
|
163
|
-
def __init__(self, http_client:
|
|
164
|
-
self._http:
|
|
163
|
+
def __init__(self, http_client: httpx2.AsyncClient, *, session: Session | None = None) -> None:
|
|
164
|
+
self._http: httpx2.AsyncClient = http_client
|
|
165
165
|
self.session: Session | None = session
|
|
166
166
|
self._refresh_lock: asyncio.Lock = asyncio.Lock()
|
|
167
167
|
|
|
@@ -200,7 +200,7 @@ class SessionTransport:
|
|
|
200
200
|
if session.refresh.expires_at_ms <= self._now_ms():
|
|
201
201
|
raise MatelabAuthenticationError("Matelab refresh token expired.")
|
|
202
202
|
try:
|
|
203
|
-
request = TokenRefreshRequest(refresh_token=session.refresh.value)
|
|
203
|
+
request = wire_models.TokenRefreshRequest(refresh_token=session.refresh.value)
|
|
204
204
|
except ValidationError:
|
|
205
205
|
raise MatelabAuthenticationError("The Matelab refresh token is invalid.") from None
|
|
206
206
|
response = await self.request(_REFRESH_TOKENS, payload=request.model_dump(mode="json"))
|
|
@@ -307,7 +307,7 @@ class SessionTransport:
|
|
|
307
307
|
response = await self._http.request(operation.method, operation.path, headers=headers)
|
|
308
308
|
else:
|
|
309
309
|
raise MatelabProtocolError(f"Unsupported request encoding: {operation.encoding}.")
|
|
310
|
-
except
|
|
310
|
+
except httpx2.TransportError:
|
|
311
311
|
raise MatelabTransportError("Could not exchange data with the Matelab Provider.") from None
|
|
312
312
|
if not response.is_success:
|
|
313
313
|
raise MatelabTransportError(
|
|
@@ -329,7 +329,7 @@ class SessionTransport:
|
|
|
329
329
|
)
|
|
330
330
|
if code not in operation.success_codes:
|
|
331
331
|
try:
|
|
332
|
-
error_response = ErrorResponse.model_validate(response_payload)
|
|
332
|
+
error_response = wire_models.ErrorResponse.model_validate(response_payload)
|
|
333
333
|
except ValidationError:
|
|
334
334
|
raise MatelabProtocolError(
|
|
335
335
|
"Matelab error response does not match the Integration Contract.", payload=sanitized_payload
|
|
@@ -391,7 +391,7 @@ class SessionTransport:
|
|
|
391
391
|
)
|
|
392
392
|
try:
|
|
393
393
|
response = await self._http.send(request, stream=True)
|
|
394
|
-
except
|
|
394
|
+
except httpx2.TransportError:
|
|
395
395
|
raise MatelabTransportError("Could not exchange data with the Matelab Provider.") from None
|
|
396
396
|
|
|
397
397
|
if response.status_code not in {200, 206}:
|
|
@@ -423,7 +423,7 @@ class SessionTransport:
|
|
|
423
423
|
"Matelab returned a JSON success envelope instead of attachment bytes.", payload=sanitized_payload
|
|
424
424
|
)
|
|
425
425
|
try:
|
|
426
|
-
error_response = ErrorResponse.model_validate(response_payload)
|
|
426
|
+
error_response = wire_models.ErrorResponse.model_validate(response_payload)
|
|
427
427
|
except ValidationError:
|
|
428
428
|
raise MatelabProtocolError(
|
|
429
429
|
"Matelab download error response does not match the Integration Contract.",
|
|
@@ -466,7 +466,7 @@ class SessionTransport:
|
|
|
466
466
|
return DownloadStream(response, content_length=content_length)
|
|
467
467
|
|
|
468
468
|
@staticmethod
|
|
469
|
-
def _parse_content_length(response:
|
|
469
|
+
def _parse_content_length(response: httpx2.Response) -> int | None:
|
|
470
470
|
value = SessionTransport._header(response, "Content-Length")
|
|
471
471
|
if value is None:
|
|
472
472
|
return None
|
|
@@ -477,5 +477,5 @@ class SessionTransport:
|
|
|
477
477
|
return content_length if content_length >= 0 else None
|
|
478
478
|
|
|
479
479
|
@staticmethod
|
|
480
|
-
def _header(response:
|
|
480
|
+
def _header(response: httpx2.Response, name: str) -> str | None:
|
|
481
481
|
return cast(str | None, response.headers.get(name))
|
matelab/client.py
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
from typing import Self
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import httpx2
|
|
4
4
|
from pydantic import SecretStr, ValidationError
|
|
5
5
|
|
|
6
|
-
from matelab._generated
|
|
7
|
-
AppIdentityResponse,
|
|
8
|
-
AuthToken,
|
|
9
|
-
ChatSsoCodeExchangeRequest,
|
|
10
|
-
ChatSsoCodeExchangeResponse,
|
|
11
|
-
TokenLoginRequest,
|
|
12
|
-
TokenLoginResponse,
|
|
13
|
-
TokenRefreshRequest,
|
|
14
|
-
TokenRefreshResponse,
|
|
15
|
-
)
|
|
6
|
+
from matelab._generated import models as wire_models
|
|
16
7
|
from matelab._transport import Encoding, Operation, SessionTransport, multipart_fields
|
|
17
8
|
from matelab.cloud_drive import CloudDrive
|
|
18
9
|
from matelab.errors import MatelabAuthenticationError, MatelabUsageError
|
|
@@ -31,7 +22,7 @@ _LOGIN = Operation(
|
|
|
31
22
|
method="POST",
|
|
32
23
|
path="/tokens/tokens",
|
|
33
24
|
encoding=Encoding.MULTIPART,
|
|
34
|
-
response_model=TokenLoginResponse,
|
|
25
|
+
response_model=wire_models.TokenLoginResponse,
|
|
35
26
|
success_codes=frozenset({0}),
|
|
36
27
|
authenticated=False,
|
|
37
28
|
authentication_errors=True,
|
|
@@ -40,7 +31,7 @@ _EXTERNAL_TOKEN_REFRESH = Operation(
|
|
|
40
31
|
method="POST",
|
|
41
32
|
path="/tokens/tokens_refresh",
|
|
42
33
|
encoding=Encoding.FORM,
|
|
43
|
-
response_model=TokenRefreshResponse,
|
|
34
|
+
response_model=wire_models.TokenRefreshResponse,
|
|
44
35
|
success_codes=frozenset({0}),
|
|
45
36
|
authenticated=False,
|
|
46
37
|
authentication_errors=True,
|
|
@@ -49,7 +40,7 @@ _APP_IDENTITY = Operation(
|
|
|
49
40
|
method="GET",
|
|
50
41
|
path="/actions/app",
|
|
51
42
|
encoding=Encoding.NONE,
|
|
52
|
-
response_model=AppIdentityResponse,
|
|
43
|
+
response_model=wire_models.AppIdentityResponse,
|
|
53
44
|
success_codes=frozenset({0}),
|
|
54
45
|
authentication_errors=True,
|
|
55
46
|
retry_on_access_expired=True,
|
|
@@ -58,7 +49,7 @@ _CHAT_SSO = Operation(
|
|
|
58
49
|
method="POST",
|
|
59
50
|
path="/unlogin_eln/code_check",
|
|
60
51
|
encoding=Encoding.FORM,
|
|
61
|
-
response_model=ChatSsoCodeExchangeResponse,
|
|
52
|
+
response_model=wire_models.ChatSsoCodeExchangeResponse,
|
|
62
53
|
success_codes=frozenset({0}),
|
|
63
54
|
authenticated=False,
|
|
64
55
|
authentication_errors=True,
|
|
@@ -69,7 +60,7 @@ class AsyncMatelab:
|
|
|
69
60
|
"""One-user async client that owns at most one process-local Matelab Session.
|
|
70
61
|
|
|
71
62
|
Do not share one instance across logical user sessions. Separate instances may share an injected
|
|
72
|
-
``
|
|
63
|
+
``httpx2.AsyncClient`` while retaining independent Session state and refresh locks.
|
|
73
64
|
"""
|
|
74
65
|
|
|
75
66
|
def __init__(
|
|
@@ -78,7 +69,7 @@ class AsyncMatelab:
|
|
|
78
69
|
*,
|
|
79
70
|
session: Session | None = None,
|
|
80
71
|
timeout: float = 30.0,
|
|
81
|
-
http_client:
|
|
72
|
+
http_client: httpx2.AsyncClient | None = None,
|
|
82
73
|
) -> None:
|
|
83
74
|
"""Create a client without performing network I/O.
|
|
84
75
|
|
|
@@ -86,10 +77,10 @@ class AsyncMatelab:
|
|
|
86
77
|
the latest value exposed by :attr:`session`.
|
|
87
78
|
"""
|
|
88
79
|
self._owns_http_client: bool = http_client is None
|
|
89
|
-
self._http:
|
|
80
|
+
self._http: httpx2.AsyncClient = (
|
|
90
81
|
http_client
|
|
91
82
|
if http_client is not None
|
|
92
|
-
else
|
|
83
|
+
else httpx2.AsyncClient(base_url=base_url.rstrip("/"), timeout=timeout)
|
|
93
84
|
)
|
|
94
85
|
self._transport: SessionTransport = SessionTransport(self._http, session=session)
|
|
95
86
|
self.cloud_drive: CloudDrive = CloudDrive(self._transport)
|
|
@@ -119,7 +110,7 @@ class AsyncMatelab:
|
|
|
119
110
|
async def authenticate(self, username: str, password: str) -> Session:
|
|
120
111
|
"""Authenticate, install, and return the same latest instance Session."""
|
|
121
112
|
try:
|
|
122
|
-
request = TokenLoginRequest(username=username, password=SecretStr(password))
|
|
113
|
+
request = wire_models.TokenLoginRequest(username=username, password=SecretStr(password))
|
|
123
114
|
except ValidationError:
|
|
124
115
|
raise MatelabUsageError("Matelab username or password does not satisfy the Integration Contract.") from None
|
|
125
116
|
response = await self._transport.request(
|
|
@@ -134,7 +125,7 @@ class AsyncMatelab:
|
|
|
134
125
|
async def exchange_chat_sso_code(self, *, code: str, key: str) -> Session:
|
|
135
126
|
"""Consume one Chat SSO code, install its Session, and return that same Session."""
|
|
136
127
|
try:
|
|
137
|
-
request = ChatSsoCodeExchangeRequest(code=code, key=SecretStr(key))
|
|
128
|
+
request = wire_models.ChatSsoCodeExchangeRequest(code=code, key=SecretStr(key))
|
|
138
129
|
except ValidationError:
|
|
139
130
|
raise MatelabUsageError("Chat SSO credentials do not satisfy the Integration Contract.") from None
|
|
140
131
|
response = await self._transport.request(
|
|
@@ -175,15 +166,17 @@ class AsyncMatelab:
|
|
|
175
166
|
response = await self._transport.request(_APP_IDENTITY, bearer_token=access_token)
|
|
176
167
|
return Identity(userid=response.user.userid, username=response.user.username, email=response.user.email)
|
|
177
168
|
|
|
178
|
-
async def _exchange_external_refresh_token(self, refresh_token: str) -> TokenRefreshResponse:
|
|
169
|
+
async def _exchange_external_refresh_token(self, refresh_token: str) -> wire_models.TokenRefreshResponse:
|
|
179
170
|
try:
|
|
180
|
-
request = TokenRefreshRequest(refresh_token=refresh_token)
|
|
171
|
+
request = wire_models.TokenRefreshRequest(refresh_token=refresh_token)
|
|
181
172
|
except ValidationError:
|
|
182
173
|
raise MatelabAuthenticationError("The Matelab refresh token is invalid.") from None
|
|
183
174
|
return await self._transport.request(_EXTERNAL_TOKEN_REFRESH, payload=request.model_dump(mode="json"))
|
|
184
175
|
|
|
185
176
|
@staticmethod
|
|
186
|
-
def _session_from_wire(
|
|
177
|
+
def _session_from_wire(
|
|
178
|
+
access: wire_models.AuthToken, refresh: wire_models.AuthToken, *, identity: Identity | None
|
|
179
|
+
) -> Session:
|
|
187
180
|
return Session(
|
|
188
181
|
access=Token(value=access.token, expires_at_ms=access.expiredAt),
|
|
189
182
|
refresh=Token(value=refresh.token, expires_at_ms=refresh.expiredAt),
|