|
1 | | -import got from 'got'; |
2 | | - |
3 | 1 | import { |
4 | 2 | CommandParams, |
5 | 3 | CreateInstanceParams, |
@@ -184,11 +182,11 @@ function getExecution(order: string) { |
184 | 182 | } |
185 | 183 | } |
186 | 184 |
|
187 | | -function makeMigrationPostOptions(payload: any) { |
| 185 | +function makeMigrationPostOptions(payload: any): RequestInit { |
188 | 186 | if (payload) { |
189 | | - return { body: payload }; |
| 187 | + return { method: 'POST', body: payload }; |
190 | 188 | } |
191 | | - return {}; |
| 189 | + return { method: 'POST' }; |
192 | 190 | } |
193 | 191 |
|
194 | 192 | function contextOrUser( |
@@ -342,44 +340,56 @@ export async function newSdkClientEntity(options: CreateInstanceParams): Promise |
342 | 340 | check: migrationOperation.trackConsistency ? (a, b) => a === b : undefined, |
343 | 341 | readNew: async (payload) => { |
344 | 342 | try { |
345 | | - const res = await got.post( |
| 343 | + const res = await fetch( |
346 | 344 | migrationOperation.newEndpoint, |
347 | 345 | makeMigrationPostOptions(payload), |
348 | 346 | ); |
349 | | - return LDMigrationSuccess(res.body); |
| 347 | + if (!res.ok) { |
| 348 | + throw new Error(`HTTP ${res.status}`); |
| 349 | + } |
| 350 | + return LDMigrationSuccess(await res.text()); |
350 | 351 | } catch (err: any) { |
351 | 352 | return LDMigrationError(err.message); |
352 | 353 | } |
353 | 354 | }, |
354 | 355 | writeNew: async (payload) => { |
355 | 356 | try { |
356 | | - const res = await got.post( |
| 357 | + const res = await fetch( |
357 | 358 | migrationOperation.newEndpoint, |
358 | 359 | makeMigrationPostOptions(payload), |
359 | 360 | ); |
360 | | - return LDMigrationSuccess(res.body); |
| 361 | + if (!res.ok) { |
| 362 | + throw new Error(`HTTP ${res.status}`); |
| 363 | + } |
| 364 | + return LDMigrationSuccess(await res.text()); |
361 | 365 | } catch (err: any) { |
362 | 366 | return LDMigrationError(err.message); |
363 | 367 | } |
364 | 368 | }, |
365 | 369 | readOld: async (payload) => { |
366 | 370 | try { |
367 | | - const res = await got.post( |
| 371 | + const res = await fetch( |
368 | 372 | migrationOperation.oldEndpoint, |
369 | 373 | makeMigrationPostOptions(payload), |
370 | 374 | ); |
371 | | - return LDMigrationSuccess(res.body); |
| 375 | + if (!res.ok) { |
| 376 | + throw new Error(`HTTP ${res.status}`); |
| 377 | + } |
| 378 | + return LDMigrationSuccess(await res.text()); |
372 | 379 | } catch (err: any) { |
373 | 380 | return LDMigrationError(err.message); |
374 | 381 | } |
375 | 382 | }, |
376 | 383 | writeOld: async (payload) => { |
377 | 384 | try { |
378 | | - const res = await got.post( |
| 385 | + const res = await fetch( |
379 | 386 | migrationOperation.oldEndpoint, |
380 | 387 | makeMigrationPostOptions(payload), |
381 | 388 | ); |
382 | | - return LDMigrationSuccess(res.body); |
| 389 | + if (!res.ok) { |
| 390 | + throw new Error(`HTTP ${res.status}`); |
| 391 | + } |
| 392 | + return LDMigrationSuccess(await res.text()); |
383 | 393 | } catch (err: any) { |
384 | 394 | return LDMigrationError(err.message); |
385 | 395 | } |
@@ -423,14 +433,11 @@ export async function newSdkClientEntity(options: CreateInstanceParams): Promise |
423 | 433 | const eventName = 'update'; |
424 | 434 |
|
425 | 435 | const handler = (eventParams: { key: string }) => { |
426 | | - got |
427 | | - .post(p.callbackUri, { |
428 | | - json: { |
429 | | - listenerId: p.listenerId, |
430 | | - flagKey: eventParams.key, |
431 | | - }, |
432 | | - }) |
433 | | - .catch(() => {}); |
| 436 | + fetch(p.callbackUri, { |
| 437 | + method: 'POST', |
| 438 | + headers: { 'Content-Type': 'application/json' }, |
| 439 | + body: JSON.stringify({ listenerId: p.listenerId, flagKey: eventParams.key }), |
| 440 | + }).catch(() => {}); |
434 | 441 | }; |
435 | 442 |
|
436 | 443 | const existing = listeners.get(p.listenerId); |
|
0 commit comments