| 402 | |
| 403 | /** Normalize a full SDK Item to match Connect API FullItem shape. */ |
| 404 | export function normalizeSdkItem(item: Item): NormalizedItem { |
| 405 | return { |
| 406 | id: item.id, |
| 407 | title: item.title, |
| 408 | vault: { id: item.vaultId }, |
| 409 | category: SDK_TO_CONNECT_CATEGORY[item.category] ?? 'CUSTOM', |
| 410 | urls: (item.websites ?? []).map((w: Website) => ({ |
| 411 | href: w.url, |
| 412 | label: w.label ?? null, |
| 413 | primary: false, |
| 414 | })), |
| 415 | favorite: false, |
| 416 | tags: item.tags ?? [], |
| 417 | version: item.version ?? 0, |
| 418 | state: null, |
| 419 | fields: (item.fields ?? []).map((field: ItemField) => ({ |
| 420 | id: field.id, |
| 421 | label: field.title, |
| 422 | type: SDK_TO_CONNECT_FIELD_TYPE[field.fieldType] ?? 'STRING', |
| 423 | purpose: '', |
| 424 | value: field.value ?? null, |
| 425 | section: field.sectionId ? { id: field.sectionId } : null, |
| 426 | generate: false, |
| 427 | recipe: null, |
| 428 | entropy: null, |
| 429 | })), |
| 430 | sections: (item.sections ?? []).map((section: ItemSection) => ({ |
| 431 | id: section.id, |
| 432 | label: section.title, |
| 433 | })), |
| 434 | createdAt: |
| 435 | item.createdAt instanceof Date ? item.createdAt.toISOString() : (item.createdAt ?? null), |
| 436 | updatedAt: |
| 437 | item.updatedAt instanceof Date ? item.updatedAt.toISOString() : (item.updatedAt ?? null), |
| 438 | lastEditedBy: null, |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /** Convert a Connect-style category string to the SDK category string. */ |
| 443 | export function toSdkCategory(category: string): `${ItemCategory}` { |