(
dataConfig: NonNullable<ContinueConfig["data"]>[number],
event: DevDataLogEvent,
)
| 160 | } |
| 161 | |
| 162 | async logToOneDestination( |
| 163 | dataConfig: NonNullable<ContinueConfig["data"]>[number], |
| 164 | event: DevDataLogEvent, |
| 165 | ) { |
| 166 | try { |
| 167 | if (!dataConfig) { |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | // First extract the data schema based on the version and level |
| 172 | const { schema } = dataConfig; |
| 173 | const level = dataConfig.level ?? DEFAULT_DEV_DATA_LEVEL; |
| 174 | |
| 175 | // Skip event if `events` is specified and does not include the event |
| 176 | const events = dataConfig.events ?? allDevEventNames; |
| 177 | if (!events.includes(event.name)) { |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | // Parse the event data, throwing if it fails |
| 182 | const parsed = await this.parseEventData(event, schema, level); |
| 183 | |
| 184 | const uriComponents = URI.parse(dataConfig.destination); |
| 185 | |
| 186 | // Send to remote server |
| 187 | if (uriComponents.scheme === "https" || uriComponents.scheme === "http") { |
| 188 | const headers: Record<string, string> = { |
| 189 | "Content-Type": "application/json", |
| 190 | }; |
| 191 | |
| 192 | if (dataConfig.apiKey) { |
| 193 | headers["Authorization"] = `Bearer ${dataConfig.apiKey}`; |
| 194 | } |
| 195 | |
| 196 | const profileId = |
| 197 | this.core?.configHandler.currentProfile?.profileDescription.id ?? ""; |
| 198 | const response = await fetchwithRequestOptions( |
| 199 | dataConfig.destination, |
| 200 | { |
| 201 | method: "POST", |
| 202 | headers, |
| 203 | body: JSON.stringify({ |
| 204 | name: event.name, |
| 205 | data: parsed, |
| 206 | schema, |
| 207 | level, |
| 208 | profileId, |
| 209 | }), |
| 210 | }, |
| 211 | dataConfig.requestOptions, |
| 212 | ); |
| 213 | if (!response.ok) { |
| 214 | throw new Error( |
| 215 | `Post request failed. ${response.status}: ${response.statusText}`, |
| 216 | ); |
| 217 | } |
| 218 | } else if (uriComponents.scheme === "file") { |
| 219 | // Write to jsonc file for local file URIs |
no test coverage detected