groupon / gofer

A general purpose service client library for node.js
BSD 3-Clause "New" or "Revised" License
82 stars 18 forks source link

fix: merge URLSearchParams qs arguments #134

Closed dbushong closed 2 years ago

dbushong commented 2 years ago
const client = new Gofer({ c: { qs: { id: 'x' } } }, 'c');
// both of these now work and request /go?id=x&other=y
await client.get('/go', { qs: { other: 'y' } });
// fixed
await client.get('/go', { qs: new URLSearchParams({ other: 'y' }) });

NOTE: values for a given key replace all values for existing key (don't think this rises to the level of breaking):

const config = { c: { qs: { a: '1', b: '3' } } };
const client = new Gofer(config, 'c');
console.log(client.getMergedOptions(
  {},
  { qs: new URLSearchParams([['a', '2'], ['a', '4']]) }
));

// before:
// new URLSearchParams([['a', '1'], ['b', '3'], ['a', '2'], ['a', '4']])

// now: (note existing a: 1 has been removed)
// new URLSearchParams([['a', '2'], ['b', '3'], ['a', '4']])

This PR was started by: git wf pr