Skip to content

Commit e78839e

Browse files
committed
fix(onepassword): preserve field metadata and empty-title fallback
connectItemToSdkItem rebuilt every field as a bare object, dropping SDK-only metadata (e.g. password-generation details) that a raw patch/replace previously left untouched. Now merges onto the existing SDK field by id before applying the translated properties, and only starts fields bare when they're genuinely new. Also restored the || (not ??) fallback on title to match replace_item's prior behavior of treating an explicitly empty title as "not provided".
1 parent 53ef085 commit e78839e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • apps/sim/app/api/tools/onepassword

apps/sim/app/api/tools/onepassword/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,21 @@ export function findItemFileAttributes(item: Item, fileId: string): FileAttribut
497497
*/
498498
// eslint-disable-next-line @typescript-eslint/no-explicit-any
499499
export function connectItemToSdkItem(connectItem: Record<string, any>, existing: Item): Item {
500+
const existingFieldsById = new Map((existing.fields ?? []).map((f) => [f.id, f]))
501+
const existingSectionsById = new Map((existing.sections ?? []).map((s) => [s.id, s]))
502+
500503
return {
501504
...existing,
502505
id: existing.id,
503506
vaultId: existing.vaultId,
504-
title: connectItem.title ?? existing.title,
507+
title: connectItem.title || existing.title,
505508
category: connectItem.category ? toSdkCategory(connectItem.category) : existing.category,
506509
fields: Array.isArray(connectItem.fields)
507510
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
508511
connectItem.fields.map((f: Record<string, any>) => ({
512+
// Preserve any SDK-only metadata (e.g. password-generation `details`)
513+
// on fields that already existed — only brand-new fields start bare.
514+
...(f.id ? existingFieldsById.get(f.id) : undefined),
509515
id: f.id || generateId().slice(0, 8),
510516
title: f.label || f.title || '',
511517
fieldType: toSdkFieldType(f.type || 'STRING'),
@@ -516,6 +522,7 @@ export function connectItemToSdkItem(connectItem: Record<string, any>, existing:
516522
sections: Array.isArray(connectItem.sections)
517523
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
518524
connectItem.sections.map((s: Record<string, any>) => ({
525+
...(s.id ? existingSectionsById.get(s.id) : undefined),
519526
id: s.id || '',
520527
title: s.label || s.title || '',
521528
}))

0 commit comments

Comments
 (0)