@@ -35,11 +35,7 @@ export async function POST(request: NextRequest) {
3535 const body = await request . json ( )
3636 const params = UpdateItemSchema . parse ( body )
3737 const creds = resolveCredentials ( params )
38- const ops = JSON . parse ( params . operations ) as Array < {
39- op : string
40- path : string
41- value ?: unknown
42- } >
38+ const ops = JSON . parse ( params . operations ) as JsonPatchOperation [ ]
4339
4440 logger . info (
4541 `[${ requestId } ] Updating item ${ params . itemId } in vault ${ params . vaultId } (${ creds . mode } mode)`
@@ -48,7 +44,6 @@ export async function POST(request: NextRequest) {
4844 if ( creds . mode === 'service_account' ) {
4945 const client = await createOnePasswordClient ( creds . serviceAccountToken ! )
5046
51- // SDK doesn't support PATCH — fetch, apply patches, then put
5247 const item = await client . items . get ( params . vaultId , params . itemId )
5348
5449 for ( const op of ops ) {
@@ -89,8 +84,15 @@ export async function POST(request: NextRequest) {
8984 }
9085}
9186
92- /** Apply a single RFC6902 JSON Patch operation to a mutable SDK Item. */
93- function applyPatch ( item : Record < string , any > , op : { op : string ; path : string ; value ?: unknown } ) {
87+ interface JsonPatchOperation {
88+ op : 'add' | 'remove' | 'replace'
89+ path : string
90+ value ?: unknown
91+ }
92+
93+ /** Apply a single RFC6902 JSON Patch operation to a mutable object. */
94+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95+ function applyPatch ( item : Record < string , any > , op : JsonPatchOperation ) {
9496 const segments = op . path . split ( '/' ) . filter ( Boolean )
9597
9698 if ( segments . length === 1 ) {
@@ -103,7 +105,6 @@ function applyPatch(item: Record<string, any>, op: { op: string; path: string; v
103105 return
104106 }
105107
106- // Navigate to parent of target
107108 let target = item
108109 for ( let i = 0 ; i < segments . length - 1 ; i ++ ) {
109110 const seg = segments [ i ]
0 commit comments