55from __future__ import annotations
66
77from enum import Enum
8- from pydantic import BaseModel , ConfigDict , Field
9- from typing import List , Literal , Optional , Union
8+ from pydantic import BaseModel , BeforeValidator , ConfigDict , Field , PlainSerializer
9+ from typing import Annotated , List , Literal , Optional , Union
10+
11+
12+ def serialize_binary_data (value : bytes ) -> list [int ]:
13+ return list (value )
14+
15+
16+ def deserialize_binary_data (value ):
17+ if isinstance (value , list ):
18+ if all (isinstance (x , int ) and 0 <= x <= 255 for x in value ):
19+ return bytes (value )
20+ raise ValueError ("All elements must be integers in the range 0-255 (u8)." )
21+ elif isinstance (value , bytes ):
22+ return value
23+ raise TypeError ("Content must be a list of integers (0-255) or bytes." )
24+
25+
26+ class DocumentCreateParams (BaseModel ):
27+ name : str
28+ """
29+ the name of the file
30+ """
31+ content : Annotated [
32+ bytes ,
33+ BeforeValidator (deserialize_binary_data ),
34+ PlainSerializer (serialize_binary_data ),
35+ ]
36+ """
37+ the content of the file
38+ """
39+
40+
41+ class FileAttributes (BaseModel ):
42+ name : str
43+ """
44+ The name of the file
45+ """
46+ id : str
47+ """
48+ The ID of the file retrieved from the server
49+ """
50+ size : int
51+ """
52+ The size of the file in bytes
53+ """
54+
55+
56+ class FileCreateParams (BaseModel ):
57+ model_config = ConfigDict (populate_by_name = True )
58+
59+ name : str
60+ """
61+ the name of the file
62+ """
63+ content : Annotated [
64+ bytes ,
65+ BeforeValidator (deserialize_binary_data ),
66+ PlainSerializer (serialize_binary_data ),
67+ ]
68+ """
69+ the content of the file
70+ """
71+ section_id : str = Field (alias = "sectionId" )
72+ """
73+ the section id where the file should be stored
74+ """
75+ field_id : str = Field (alias = "fieldId" )
76+ """
77+ the field id where the file should be stored
78+ """
1079
1180
1281class GeneratePasswordResponse (BaseModel ):
@@ -58,11 +127,14 @@ class ItemFieldType(str, Enum):
58127 TOTP = "Totp"
59128 EMAIL = "Email"
60129 REFERENCE = "Reference"
130+ SSHKEY = "SshKey"
131+ MENU = "Menu"
61132 UNSUPPORTED = "Unsupported"
62133
63134
64135class ItemFieldDetailsTypes (str , Enum ):
65136 OTP = "Otp"
137+ SSH_KEY = "SshKey"
66138
67139
68140class ItemFieldDetailsOtp (BaseModel ):
@@ -74,8 +146,17 @@ class ItemFieldDetailsOtp(BaseModel):
74146 content : OtpFieldDetails
75147
76148
149+ class ItemFieldDetailsSshKey (BaseModel ):
150+ """
151+ Computed SSH Key attributes
152+ """
153+
154+ type : Literal [ItemFieldDetailsTypes .SSH_KEY ] = ItemFieldDetailsTypes .SSH_KEY
155+ content : Optional [SshKeyAttributes ]
156+
157+
77158# Field type-specific attributes.
78- ItemFieldDetails = ItemFieldDetailsOtp
159+ ItemFieldDetails = Union [ ItemFieldDetailsOtp , ItemFieldDetailsSshKey ]
79160
80161
81162class ItemField (BaseModel ):
@@ -167,6 +248,23 @@ class Website(BaseModel):
167248 """
168249
169250
251+ class ItemFile (BaseModel ):
252+ model_config = ConfigDict (populate_by_name = True )
253+
254+ attributes : FileAttributes
255+ """
256+ the attributes of the file
257+ """
258+ section_id : str = Field (alias = "sectionId" )
259+ """
260+ the section id where the file should be stored
261+ """
262+ field_id : str = Field (alias = "fieldId" )
263+ """
264+ the field id where the file should be stored
265+ """
266+
267+
170268class Item (BaseModel ):
171269 """
172270 Represents a 1Password item.
@@ -214,6 +312,14 @@ class Item(BaseModel):
214312 """
215313 The item's version
216314 """
315+ files : List [ItemFile ]
316+ """
317+ The item's file fields
318+ """
319+ document : Optional [FileAttributes ] = Field (default = None )
320+ """
321+ The document file for the Document item category
322+ """
217323
218324
219325class ItemCreateParams (BaseModel ):
@@ -251,6 +357,14 @@ class ItemCreateParams(BaseModel):
251357 """
252358 The websites used for autofilling for items of the Login and Password categories.
253359 """
360+ files : Optional [List [FileCreateParams ]] = Field (default = None )
361+ """
362+ The item's files stored as fields
363+ """
364+ document : Optional [DocumentCreateParams ] = Field (default = None )
365+ """
366+ The document file for the Document item category
367+ """
254368
255369
256370class ItemOverview (BaseModel ):
@@ -453,6 +567,23 @@ class OtpFieldDetails(BaseModel):
453567 """
454568
455569
570+ class SshKeyAttributes (BaseModel ):
571+ model_config = ConfigDict (populate_by_name = True )
572+
573+ public_key : str = Field (alias = "publicKey" )
574+ """
575+ The public part of the SSH Key
576+ """
577+ fingerprint : str
578+ """
579+ The fingerprint of the SSH Key
580+ """
581+ key_type : str = Field (alias = "keyType" )
582+ """
583+ The key type ("Ed25519" or "RSA, {length}-bit")
584+ """
585+
586+
456587class VaultOverview (BaseModel ):
457588 """
458589 Represents a decrypted 1Password vault.
0 commit comments