* 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)
| 605 | * containing braces cannot skew it. |
| 606 | */ |
| 607 | function 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. |
no test coverage detected