export function instanceDraftPayload(values, editing = false) { const action = editing ? (values.passwordAction || 'preserve') : (values.passwordAction || (values.password ? 'set' : 'clear')) if (!['preserve', 'set', 'clear'].includes(action)) throw new Error('无效密码操作') if (action === 'set' && !String(values.password || '')) throw new Error('设置密码时必须输入密码') if (action === 'clear' && editing && !values.clearConfirmed) throw new Error('清除密码需要显式确认') const payload = { id: String(values.id || '').trim(), name: String(values.name || '').trim(), url: String(values.url || '').trim(), description: String(values.description || '').trim(), tags: Array.isArray(values.tags) ? values.tags : [], passwordAction: action, } if (action === 'set') payload.password = String(values.password) return payload } export function requestDraft(method, path, body) { const normalizedMethod = String(method || 'GET').toUpperCase() const result = { method: normalizedMethod, path: String(path || '') } if (normalizedMethod !== 'GET' && body !== undefined) result.body = body return result } export const isWriteMethod = method => ['POST', 'PUT', 'PATCH', 'DELETE'].includes(String(method).toUpperCase())