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

Function extractOAuthServiceId

scripts/generate-docs.ts:607–631  ·  view source on GitHub ↗

* Extract the OAuth service id from the block's `oauth-input` credential * subBlock. Scoped to that subBlock's object literal so `serviceId` fields on * other subBlocks (e.g. file selectors) are never picked up. Brace matching * runs on a blanked copy of the content so string literals and comment

(blockContent: string)

Source from the content-addressed store, hash-verified

605 * containing braces cannot skew it.
606 */
607function extractOAuthServiceId(blockContent: string): string | undefined {
608 const typeMatch = /type\s*:\s*['"]oauth-input['"]/.exec(blockContent)
609 if (!typeMatch) return undefined
610
611 const scannable = blankStringsAndComments(blockContent)
612 let depth = 0
613 let objectStart = -1
614 for (let i = typeMatch.index; i >= 0; i--) {
615 const char = scannable[i]
616 if (char === '}') depth++
617 else if (char === '{') {
618 if (depth === 0) {
619 objectStart = i
620 break
621 }
622 depth--
623 }
624 }
625 if (objectStart === -1) return undefined
626
627 const objectEnd = findMatchingClose(scannable, objectStart)
628 if (objectEnd === -1) return undefined
629 const subBlockContent = blockContent.substring(objectStart, objectEnd)
630 return /serviceId\s*:\s*['"]([^'"]+)['"]/.exec(subBlockContent)?.[1]
631}
632
633/**
634 * Extract the list of trigger IDs from the block's `triggers.available` array.

Callers 1

writeIntegrationsJsonFunction · 0.85

Calls 2

blankStringsAndCommentsFunction · 0.85
findMatchingCloseFunction · 0.85

Tested by

no test coverage detected