|
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,36 @@ 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( |
346 | | - migrationOperation.newEndpoint, |
347 | | - makeMigrationPostOptions(payload), |
348 | | - ); |
349 | | - return LDMigrationSuccess(res.body); |
| 343 | + const res = await fetch(migrationOperation.newEndpoint, makeMigrationPostOptions(payload)); |
| 344 | + if (!res.ok) { throw new Error(`HTTP ${res.status}`); } |
| 345 | + return LDMigrationSuccess(await res.text()); |
350 | 346 | } catch (err: any) { |
351 | 347 | return LDMigrationError(err.message); |
352 | 348 | } |
353 | 349 | }, |
354 | 350 | writeNew: async (payload) => { |
355 | 351 | try { |
356 | | - const res = await got.post( |
357 | | - migrationOperation.newEndpoint, |
358 | | - makeMigrationPostOptions(payload), |
359 | | - ); |
360 | | - return LDMigrationSuccess(res.body); |
| 352 | + const res = await fetch(migrationOperation.newEndpoint, makeMigrationPostOptions(payload)); |
| 353 | + if (!res.ok) { throw new Error(`HTTP ${res.status}`); } |
| 354 | + return LDMigrationSuccess(await res.text()); |
361 | 355 | } catch (err: any) { |
362 | 356 | return LDMigrationError(err.message); |
363 | 357 | } |
364 | 358 | }, |
365 | 359 | readOld: async (payload) => { |
366 | 360 | try { |
367 | | - const res = await got.post( |
368 | | - migrationOperation.oldEndpoint, |
369 | | - makeMigrationPostOptions(payload), |
370 | | - ); |
371 | | - return LDMigrationSuccess(res.body); |
| 361 | + const res = await fetch(migrationOperation.oldEndpoint, makeMigrationPostOptions(payload)); |
| 362 | + if (!res.ok) { throw new Error(`HTTP ${res.status}`); } |
| 363 | + return LDMigrationSuccess(await res.text()); |
372 | 364 | } catch (err: any) { |
373 | 365 | return LDMigrationError(err.message); |
374 | 366 | } |
375 | 367 | }, |
376 | 368 | writeOld: async (payload) => { |
377 | 369 | try { |
378 | | - const res = await got.post( |
379 | | - migrationOperation.oldEndpoint, |
380 | | - makeMigrationPostOptions(payload), |
381 | | - ); |
382 | | - return LDMigrationSuccess(res.body); |
| 370 | + const res = await fetch(migrationOperation.oldEndpoint, makeMigrationPostOptions(payload)); |
| 371 | + if (!res.ok) { throw new Error(`HTTP ${res.status}`); } |
| 372 | + return LDMigrationSuccess(await res.text()); |
383 | 373 | } catch (err: any) { |
384 | 374 | return LDMigrationError(err.message); |
385 | 375 | } |
@@ -423,14 +413,11 @@ export async function newSdkClientEntity(options: CreateInstanceParams): Promise |
423 | 413 | const eventName = 'update'; |
424 | 414 |
|
425 | 415 | 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(() => {}); |
| 416 | + fetch(p.callbackUri, { |
| 417 | + method: 'POST', |
| 418 | + headers: { 'Content-Type': 'application/json' }, |
| 419 | + body: JSON.stringify({ listenerId: p.listenerId, flagKey: eventParams.key }), |
| 420 | + }).catch(() => {}); |
434 | 421 | }; |
435 | 422 |
|
436 | 423 | const existing = listeners.get(p.listenerId); |
|
0 commit comments