| 15 | } |
| 16 | |
| 17 | function parseStringArray(value: unknown): string[] | undefined { |
| 18 | if (Array.isArray(value)) { |
| 19 | const items = value |
| 20 | .flatMap((item) => (typeof item === 'string' ? [item.trim()] : [])) |
| 21 | .filter((item) => item.length > 0) |
| 22 | |
| 23 | return items.length > 0 ? items : undefined |
| 24 | } |
| 25 | |
| 26 | if (typeof value !== 'string') { |
| 27 | return undefined |
| 28 | } |
| 29 | |
| 30 | const trimmed = value.trim() |
| 31 | if (trimmed.length === 0) { |
| 32 | return undefined |
| 33 | } |
| 34 | |
| 35 | if (trimmed.startsWith('[')) { |
| 36 | try { |
| 37 | const parsed = JSON.parse(trimmed) |
| 38 | return parseStringArray(parsed) |
| 39 | } catch { |
| 40 | return undefined |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | const items = trimmed |
| 45 | .split(',') |
| 46 | .map((item) => item.trim()) |
| 47 | .filter((item) => item.length > 0) |
| 48 | return items.length > 0 ? items : undefined |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Trello uses a custom token flow and non-UUID credential IDs, so the block keeps |