(
block: BlockState,
triggerId: string,
triggerDef: { subBlocks: SubBlockConfig[] }
)
| 262 | * deploy API. |
| 263 | */ |
| 264 | export function buildProviderConfig( |
| 265 | block: BlockState, |
| 266 | triggerId: string, |
| 267 | triggerDef: { subBlocks: SubBlockConfig[] } |
| 268 | ): { |
| 269 | providerConfig: Record<string, unknown> |
| 270 | missingFields: string[] |
| 271 | credentialId?: string |
| 272 | credentialSetId?: string |
| 273 | triggerPath: string |
| 274 | } { |
| 275 | const triggerConfigValue = getSubBlockValue(block, 'triggerConfig') |
| 276 | const baseConfig = |
| 277 | triggerConfigValue && typeof triggerConfigValue === 'object' |
| 278 | ? (triggerConfigValue as Record<string, unknown>) |
| 279 | : {} |
| 280 | |
| 281 | const providerConfig: Record<string, unknown> = { ...baseConfig } |
| 282 | const missingFields: string[] = [] |
| 283 | const subBlockValues = Object.fromEntries( |
| 284 | Object.entries(block.subBlocks || {}).map(([key, value]) => [key, { value: value.value }]) |
| 285 | ) |
| 286 | |
| 287 | const canonicalIndex = buildCanonicalIndex(triggerDef.subBlocks) |
| 288 | const satisfiedCanonicalIds = new Set<string>() |
| 289 | const filledSubBlockIds = new Set<string>() |
| 290 | |
| 291 | const relevantSubBlocks = triggerDef.subBlocks.filter( |
| 292 | (subBlock) => |
| 293 | (subBlock.mode === 'trigger' || subBlock.mode === 'trigger-advanced') && |
| 294 | !SYSTEM_SUBBLOCK_IDS.includes(subBlock.id) |
| 295 | ) |
| 296 | |
| 297 | // First pass: populate providerConfig, clear stale baseConfig entries, and track which |
| 298 | // subblocks and canonical groups have a value. |
| 299 | for (const subBlock of relevantSubBlocks) { |
| 300 | const valueToUse = getConfigValue(block, subBlock) |
| 301 | if (valueToUse !== null && valueToUse !== undefined && valueToUse !== '') { |
| 302 | providerConfig[subBlock.id] = valueToUse |
| 303 | filledSubBlockIds.add(subBlock.id) |
| 304 | const canonicalId = canonicalIndex.canonicalIdBySubBlockId[subBlock.id] |
| 305 | if (canonicalId) satisfiedCanonicalIds.add(canonicalId) |
| 306 | } else { |
| 307 | delete providerConfig[subBlock.id] |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // Second pass: validate required fields. Skip subblocks that are filled or whose canonical |
| 312 | // group is satisfied by another member. |
| 313 | for (const subBlock of relevantSubBlocks) { |
| 314 | if (filledSubBlockIds.has(subBlock.id)) continue |
| 315 | const canonicalId = canonicalIndex.canonicalIdBySubBlockId[subBlock.id] |
| 316 | if (canonicalId && satisfiedCanonicalIds.has(canonicalId)) continue |
| 317 | if (isFieldRequired(subBlock, subBlockValues)) { |
| 318 | missingFields.push(subBlock.title || subBlock.id) |
| 319 | } |
| 320 | } |
| 321 |
no test coverage detected