({ pipe, account }: { pipe: Pipe; account: Account })
| 242 | } |
| 243 | |
| 244 | async function upsertPipe({ pipe, account }: { pipe: Pipe; account: Account }) { |
| 245 | const { createUrl } = getApiUrls(pipe.name); |
| 246 | |
| 247 | try { |
| 248 | const createResponse = await fetch(createUrl, { |
| 249 | method: 'POST', |
| 250 | headers: { |
| 251 | 'Content-Type': 'application/json', |
| 252 | Authorization: `Bearer ${account.apiKey}` |
| 253 | }, |
| 254 | body: JSON.stringify({ |
| 255 | ...pipe, |
| 256 | upsert: true |
| 257 | }) |
| 258 | }); |
| 259 | |
| 260 | if (createResponse.ok) { |
| 261 | return (await createResponse.json()) as any; |
| 262 | } |
| 263 | |
| 264 | const errorData = (await createResponse.json()) as ErrorResponse; |
| 265 | |
| 266 | throw new Error( |
| 267 | `HTTP error! status: ${createResponse.status}, message: ${errorData.error?.message}` |
| 268 | ); |
| 269 | } catch (error) { |
| 270 | console.error('Error in createNewPipe:', error); |
| 271 | throw error; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | async function updateExistingPipe({ |
| 276 | updateUrl, |
no test coverage detected