| 1 | package bitwarden |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | // ItemType represents the type of a vault item. |
| 9 | type ItemType int |
| 10 | |
| 11 | const ( |
| 12 | ItemTypeLogin ItemType = 1 |
| 13 | ItemTypeSecureNote ItemType = 2 |
| 14 | ItemTypeCard ItemType = 3 |
| 15 | ItemTypeIdentity ItemType = 4 |
| 16 | ItemTypeSSHKey ItemType = 5 |
| 17 | ) |
| 18 | |
| 19 | // SendType represents the type of a Send. |
| 20 | type SendType int |
| 21 | |
| 22 | const ( |
| 23 | SendTypeText SendType = 0 |
| 24 | SendTypeFile SendType = 1 |
| 25 | ) |
| 26 | |
| 27 | // FieldType represents the type of a custom field. |
| 28 | type FieldType int |
| 29 | |
| 30 | const ( |
| 31 | FieldTypeText FieldType = 0 |
| 32 | FieldTypeHidden FieldType = 1 |
| 33 | FieldTypeBoolean FieldType = 2 |
| 34 | FieldTypeLinked FieldType = 3 |
| 35 | ) |
| 36 | |
| 37 | // URIMatchType represents the URI match detection type. |
| 38 | type URIMatchType int |
| 39 | |
| 40 | const ( |
| 41 | URIMatchBaseDomain URIMatchType = 0 |
| 42 | URIMatchHost URIMatchType = 1 |
| 43 | URIMatchStartsWith URIMatchType = 2 |
| 44 | URIMatchRegex URIMatchType = 3 |
| 45 | URIMatchExact URIMatchType = 4 |
| 46 | URIMatchNever URIMatchType = 5 |
| 47 | ) |
| 48 | |
| 49 | // Status represents the response from /status. |
| 50 | type Status struct { |
| 51 | ServerURL string `json:"serverUrl"` |
| 52 | LastSync string `json:"lastSync"` |
| 53 | UserEmail string `json:"userEmail"` |
| 54 | UserID string `json:"userId"` |
| 55 | Status string `json:"status"` |
| 56 | } |
| 57 | |
| 58 | // StatusResponse wraps the status endpoint response. |
| 59 | type StatusResponse struct { |
| 60 | Success bool `json:"success"` |
| 61 | Data json.RawMessage `json:"data"` |
| 62 | } |
| 63 | |
| 64 | // SyncResponse wraps the sync endpoint response. |
| 65 | type SyncResponse struct { |
| 66 | Success bool `json:"success"` |
| 67 | Data struct { |
| 68 | Title string `json:"title"` |
| 69 | Message string `json:"message"` |
| 70 | } `json:"data"` |
| 71 | } |
| 72 | |
| 73 | // UnlockRequest is the body for POST /unlock. |
| 74 | type UnlockRequest struct { |
| 75 | Password string `json:"password"` |
| 76 | } |
| 77 | |
| 78 | // MessageResponse is a generic message response from the API. |
| 79 | type MessageResponse struct { |
| 80 | Success bool `json:"success"` |
| 81 | Data struct { |
| 82 | Title string `json:"title"` |
| 83 | Message string `json:"message"` |
| 84 | Raw string `json:"raw"` |
| 85 | } `json:"data"` |
| 86 | } |
| 87 | |
| 88 | // LoginURI represents a URI attached to a login item. |
| 89 | type LoginURI struct { |
| 90 | Match *URIMatchType `json:"match,omitempty"` |
| 91 | URI string `json:"uri"` |
| 92 | } |
| 93 | |
| 94 | // Login represents login-specific fields of a vault item. |
| 95 | type Login struct { |
| 96 | URIs []LoginURI `json:"uris,omitempty"` |
| 97 | Username string `json:"username,omitempty"` |
| 98 | Password string `json:"password,omitempty"` |
| 99 | TOTP string `json:"totp,omitempty"` |
| 100 | } |
| 101 | |
| 102 | // Card represents card-specific fields of a vault item. |
| 103 | type Card struct { |
| 104 | CardholderName string `json:"cardholderName,omitempty"` |
| 105 | Brand string `json:"brand,omitempty"` |
| 106 | Number string `json:"number,omitempty"` |
| 107 | ExpMonth string `json:"expMonth,omitempty"` |
| 108 | ExpYear string `json:"expYear,omitempty"` |
| 109 | Code string `json:"code,omitempty"` |
| 110 | } |
| 111 | |
| 112 | // Identity represents identity-specific fields of a vault item. |
| 113 | type Identity struct { |
| 114 | Title string `json:"title,omitempty"` |
| 115 | FirstName string `json:"firstName,omitempty"` |
| 116 | MiddleName string `json:"middleName,omitempty"` |
| 117 | LastName string `json:"lastName,omitempty"` |
| 118 | Address1 string `json:"address1,omitempty"` |
| 119 | Address2 string `json:"address2,omitempty"` |
| 120 | Address3 string `json:"address3,omitempty"` |
| 121 | City string `json:"city,omitempty"` |
| 122 | State string `json:"state,omitempty"` |
| 123 | PostalCode string `json:"postalCode,omitempty"` |
| 124 | Country string `json:"country,omitempty"` |
| 125 | Company string `json:"company,omitempty"` |
| 126 | Email string `json:"email,omitempty"` |
| 127 | Phone string `json:"phone,omitempty"` |
| 128 | SSN string `json:"ssn,omitempty"` |
| 129 | Username string `json:"username,omitempty"` |
| 130 | PassportNumber string `json:"passportNumber,omitempty"` |
| 131 | LicenseNumber string `json:"licenseNumber,omitempty"` |
| 132 | } |
| 133 | |
| 134 | // SecureNote represents secure note-specific fields. |
| 135 | type SecureNote struct { |
| 136 | Type int `json:"type"` |
| 137 | } |
| 138 | |
| 139 | // Field represents a custom field on a vault item. |
| 140 | type Field struct { |
| 141 | Name string `json:"name"` |
| 142 | Value string `json:"value"` |
| 143 | Type FieldType `json:"type"` |
| 144 | LinkedID *int `json:"linkedId,omitempty"` |
| 145 | } |
| 146 | |
| 147 | // PasswordHistory represents a password history entry. |
| 148 | type PasswordHistory struct { |
| 149 | LastUsedDate string `json:"lastUsedDate"` |
| 150 | Password string `json:"password"` |
| 151 | } |
| 152 | |
| 153 | // Item represents a vault item (cipher). |
| 154 | type Item struct { |
| 155 | Object string `json:"object,omitempty"` |
| 156 | ID string `json:"id,omitempty"` |
| 157 | OrganizationID string `json:"organizationId,omitempty"` |
| 158 | FolderID *string `json:"folderId,omitempty"` |
| 159 | Type ItemType `json:"type"` |
| 160 | Reprompt int `json:"reprompt"` |
| 161 | Name string `json:"name"` |
| 162 | Notes string `json:"notes,omitempty"` |
| 163 | Favorite bool `json:"favorite"` |
| 164 | Login *Login `json:"login,omitempty"` |
| 165 | Card *Card `json:"card,omitempty"` |
| 166 | Identity *Identity `json:"identity,omitempty"` |
| 167 | SecureNote *SecureNote `json:"secureNote,omitempty"` |
| 168 | Fields []Field `json:"fields,omitempty"` |
| 169 | PasswordHistory []PasswordHistory `json:"passwordHistory,omitempty"` |
| 170 | Attachments []Attachment `json:"attachments,omitempty"` |
| 171 | CollectionIDs []string `json:"collectionIds,omitempty"` |
| 172 | RevisionDate string `json:"revisionDate,omitempty"` |
| 173 | CreationDate string `json:"creationDate,omitempty"` |
| 174 | DeletedDate *string `json:"deletedDate,omitempty"` |
| 175 | } |
| 176 | |
| 177 | // Folder represents a vault folder. |
| 178 | type Folder struct { |
| 179 | Object string `json:"object,omitempty"` |
| 180 | ID string `json:"id,omitempty"` |
| 181 | Name string `json:"name"` |
| 182 | } |
| 183 | |
| 184 | // Collection represents a vault collection. |
| 185 | type Collection struct { |
| 186 | Object string `json:"object,omitempty"` |
| 187 | ID string `json:"id,omitempty"` |
| 188 | OrganizationID string `json:"organizationId,omitempty"` |
| 189 | Name string `json:"name"` |
| 190 | ExternalID string `json:"externalId,omitempty"` |
| 191 | } |
| 192 | |
| 193 | // OrgCollection represents an organization collection with additional details. |
| 194 | type OrgCollection struct { |
| 195 | Object string `json:"object,omitempty"` |
| 196 | ID string `json:"id,omitempty"` |
| 197 | OrganizationID string `json:"organizationId,omitempty"` |
| 198 | Name string `json:"name"` |
| 199 | ExternalID string `json:"externalId,omitempty"` |
| 200 | Groups []string `json:"groups,omitempty"` |
| 201 | } |
| 202 | |
| 203 | // Organization represents an organization. |
| 204 | type Organization struct { |
| 205 | Object string `json:"object,omitempty"` |
| 206 | ID string `json:"id,omitempty"` |
| 207 | Name string `json:"name"` |
| 208 | Status int `json:"status"` |
| 209 | Type int `json:"type"` |
| 210 | Enabled bool `json:"enabled"` |
| 211 | } |
| 212 | |
| 213 | // OrgMember represents an organization member. |
| 214 | type OrgMember struct { |
| 215 | Object string `json:"object,omitempty"` |
| 216 | ID string `json:"id,omitempty"` |
| 217 | Name string `json:"name"` |
| 218 | Email string `json:"email"` |
| 219 | Status int `json:"status"` |
| 220 | Type int `json:"type"` |
| 221 | TwoStep bool `json:"twoFactorEnabled"` |
| 222 | } |
| 223 | |
| 224 | // Send represents a Bitwarden Send object. |
| 225 | type Send struct { |
| 226 | Object string `json:"object,omitempty"` |
| 227 | ID string `json:"id,omitempty"` |
| 228 | AccessID string `json:"accessId,omitempty"` |
| 229 | Type SendType `json:"type"` |
| 230 | Name string `json:"name"` |
| 231 | Notes string `json:"notes,omitempty"` |
| 232 | File *SendFile `json:"file,omitempty"` |
| 233 | Text *SendText `json:"text,omitempty"` |
| 234 | Key string `json:"key,omitempty"` |
| 235 | MaxAccessCount *int `json:"maxAccessCount,omitempty"` |
| 236 | AccessCount int `json:"accessCount,omitempty"` |
| 237 | Password string `json:"password,omitempty"` |
| 238 | Disabled bool `json:"disabled"` |
| 239 | RevisionDate string `json:"revisionDate,omitempty"` |
| 240 | DeletionDate string `json:"deletionDate"` |
| 241 | ExpirationDate *string `json:"expirationDate,omitempty"` |
| 242 | HideEmail bool `json:"hideEmail"` |
| 243 | } |
| 244 | |
| 245 | // SendFile represents file details in a Send. |
| 246 | type SendFile struct { |
| 247 | ID string `json:"id,omitempty"` |
| 248 | FileName string `json:"fileName"` |
| 249 | Size string `json:"size,omitempty"` |
| 250 | SizeName string `json:"sizeName,omitempty"` |
| 251 | } |
| 252 | |
| 253 | // SendText represents text details in a Send. |
| 254 | type SendText struct { |
| 255 | Text string `json:"text"` |
| 256 | Hidden bool `json:"hidden"` |
| 257 | } |
| 258 | |
| 259 | // Attachment represents a file attachment on a vault item. |
| 260 | type Attachment struct { |
| 261 | ID string `json:"id"` |
| 262 | FileName string `json:"fileName"` |
| 263 | Size string `json:"size"` |
| 264 | SizeName string `json:"sizeName"` |
| 265 | URL string `json:"url"` |
| 266 | } |
| 267 | |
| 268 | // GenerateOptions holds password/passphrase generation options. |
| 269 | type GenerateOptions struct { |
| 270 | Lowercase *bool `json:"lowercase,omitempty"` |
| 271 | Uppercase *bool `json:"uppercase,omitempty"` |
| 272 | Number *bool `json:"number,omitempty"` |
| 273 | Special *bool `json:"special,omitempty"` |
| 274 | Length *int `json:"length,omitempty"` |
| 275 | Passphrase *bool `json:"passphrase,omitempty"` |
| 276 | Words *int `json:"words,omitempty"` |
| 277 | Separator *string `json:"separator,omitempty"` |
| 278 | Capitalize *bool `json:"capitalize,omitempty"` |
| 279 | IncludeNumber *bool `json:"includeNumber,omitempty"` |
| 280 | } |
| 281 | |
| 282 | // GenerateResponse wraps the /generate endpoint response. |
| 283 | type GenerateResponse struct { |
| 284 | Success bool `json:"success"` |
| 285 | Data struct { |
| 286 | Object string `json:"object"` |
| 287 | Data string `json:"data"` |
| 288 | } `json:"data"` |
| 289 | } |
| 290 | |
| 291 | // ListResponse is a generic list response wrapper. |
| 292 | type ListResponse[T any] struct { |
| 293 | Success bool `json:"success"` |
| 294 | Data struct { |
| 295 | Object string `json:"object"` |
| 296 | Data []T `json:"data"` |
| 297 | } `json:"data"` |
| 298 | } |
| 299 | |
| 300 | // ObjectResponse is a generic single-object response wrapper. |
| 301 | type ObjectResponse[T any] struct { |
| 302 | Success bool `json:"success"` |
| 303 | Data T `json:"data"` |
| 304 | } |
| 305 | |
| 306 | // ListFilter holds common filter parameters for list operations. |
| 307 | type ListFilter struct { |
| 308 | Search string |
| 309 | OrganizationID string |
| 310 | CollectionID string |
| 311 | FolderID string |
| 312 | URL string |
| 313 | Trash bool |
| 314 | } |
| 315 | |
| 316 | // ConfirmRequest is the body for POST /confirm/org-member/:id. |
| 317 | type ConfirmRequest struct { |
| 318 | OrganizationID string `json:"organizationId"` |
| 319 | } |
| 320 | |
| 321 | // MoveRequest is the body for POST /move/:id/:organizationId. |
| 322 | type MoveRequest struct { |
| 323 | CollectionIDs []string `json:"collectionIds"` |
| 324 | } |
| 325 | |
| 326 | // TemplateType represents the type of template to retrieve. |
| 327 | type TemplateType string |
| 328 | |
| 329 | const ( |
| 330 | TemplateItem TemplateType = "item" |
| 331 | TemplateItemField TemplateType = "item.field" |
| 332 | TemplateItemLogin TemplateType = "item.login" |
| 333 | TemplateItemCard TemplateType = "item.card" |
| 334 | TemplateItemIdentity TemplateType = "item.identity" |
| 335 | TemplateItemSecureNote TemplateType = "item.securenote" |
| 336 | TemplateFolder TemplateType = "folder" |
| 337 | TemplateCollection TemplateType = "collection" |
| 338 | TemplateSend TemplateType = "send" |
| 339 | TemplateSendText TemplateType = "send.text" |
| 340 | TemplateSendFile TemplateType = "send.file" |
| 341 | ) |
| 342 | |
| 343 | // Duration alias for convenience. |
| 344 | type Duration = time.Duration |
| 345 | |