(providerConfig: unknown)
| 98 | * Returns null when the config has no recognizable event type. |
| 99 | */ |
| 100 | export function parseSubscriptionConfig(providerConfig: unknown): SimSubscriptionConfig | null { |
| 101 | const config = |
| 102 | providerConfig && typeof providerConfig === 'object' && !Array.isArray(providerConfig) |
| 103 | ? (providerConfig as Record<string, unknown>) |
| 104 | : {} |
| 105 | |
| 106 | const eventType = config.eventType |
| 107 | if ( |
| 108 | typeof eventType !== 'string' || |
| 109 | !(SIM_EVENT_TYPES as readonly string[]).includes(eventType) |
| 110 | ) { |
| 111 | return null |
| 112 | } |
| 113 | |
| 114 | return { |
| 115 | eventType: eventType as SimEventType, |
| 116 | workflowIds: parseStringArray(config.workflowIds), |
| 117 | consecutiveFailures: parseBoundedNumber( |
| 118 | config.consecutiveFailures, |
| 119 | SIM_RULE_DEFAULTS.consecutiveFailures, |
| 120 | SIM_RULE_BOUNDS.consecutiveFailures |
| 121 | ), |
| 122 | failureRatePercent: parseBoundedNumber( |
| 123 | config.failureRatePercent, |
| 124 | SIM_RULE_DEFAULTS.failureRatePercent, |
| 125 | SIM_RULE_BOUNDS.failureRatePercent |
| 126 | ), |
| 127 | windowHours: parseBoundedNumber( |
| 128 | config.windowHours, |
| 129 | SIM_RULE_DEFAULTS.windowHours, |
| 130 | SIM_RULE_BOUNDS.windowHours |
| 131 | ), |
| 132 | durationThresholdMs: parseBoundedNumber( |
| 133 | config.durationThresholdMs, |
| 134 | SIM_RULE_DEFAULTS.durationThresholdMs, |
| 135 | SIM_RULE_BOUNDS.durationThresholdMs |
| 136 | ), |
| 137 | latencySpikePercent: parseBoundedNumber( |
| 138 | config.latencySpikePercent, |
| 139 | SIM_RULE_DEFAULTS.latencySpikePercent, |
| 140 | SIM_RULE_BOUNDS.latencySpikePercent |
| 141 | ), |
| 142 | costThresholdCredits: parseBoundedNumber( |
| 143 | config.costThresholdCredits, |
| 144 | SIM_RULE_DEFAULTS.costThresholdCredits, |
| 145 | SIM_RULE_BOUNDS.costThresholdCredits |
| 146 | ), |
| 147 | errorCountThreshold: parseBoundedNumber( |
| 148 | config.errorCountThreshold, |
| 149 | SIM_RULE_DEFAULTS.errorCountThreshold, |
| 150 | SIM_RULE_BOUNDS.errorCountThreshold |
| 151 | ), |
| 152 | inactivityHours: parseBoundedNumber( |
| 153 | config.inactivityHours, |
| 154 | SIM_RULE_DEFAULTS.inactivityHours, |
| 155 | SIM_RULE_BOUNDS.inactivityHours |
| 156 | ), |
| 157 | } |
no test coverage detected