MCPcopy Index your code
hub / github.com/simstudioai/sim / clearCredentialInValue

Function clearCredentialInValue

apps/sim/lib/credentials/deletion.ts:244–282  ·  view source on GitHub ↗
(input: unknown, credentialId: string)

Source from the content-addressed store, hash-verified

242 * Returns the original reference when nothing matched so callers can skip writes.
243 */
244export function clearCredentialInValue(input: unknown, credentialId: string): ClearResult {
245 if (Array.isArray(input)) {
246 let changed = false
247 const next = input.map((item) => {
248 const result = clearCredentialInValue(item, credentialId)
249 if (result.changed) changed = true
250 return result.value
251 })
252 return changed ? { value: next, changed: true } : { value: input, changed: false }
253 }
254
255 if (input !== null && typeof input === 'object') {
256 const obj = input as Record<string, unknown>
257 const id = typeof obj.id === 'string' ? obj.id : null
258 const isCredentialSubBlock = id !== null && CREDENTIAL_SUBBLOCK_IDS.has(id)
259 let changed = false
260 const next: Record<string, unknown> = {}
261
262 for (const [key, value] of Object.entries(obj)) {
263 if (isCredentialSubBlock && key === 'value' && value === credentialId) {
264 next[key] = ''
265 changed = true
266 continue
267 }
268 if (key === 'credential' && value === credentialId) {
269 next[key] = ''
270 changed = true
271 continue
272 }
273 const result = clearCredentialInValue(value, credentialId)
274 next[key] = result.value
275 if (result.changed) changed = true
276 }
277
278 return changed ? { value: next, changed: true } : { value: input, changed: false }
279 }
280
281 return { value: input, changed: false }
282}

Callers 5

deletion.test.tsFile · 0.90
clearInWorkflowBlocksFunction · 0.85
clearInPausedExecutionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected