Skip to content

Commit

Permalink
fix: retire lodash omitby to fix vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
yukun-han committed Feb 3, 2024
1 parent dd9218b commit fedcc2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"lodash.isnil": "4.0.0",
"lodash.isundefined": "3.0.1",
"lodash.omit": "^4.5.0",
"lodash.omitby": "4.6.0",
"pkginfo": "^0.4.1",
"ramda": "^0.28.0",
"randexp": "^0.5.3"
Expand Down
22 changes: 10 additions & 12 deletions src/dsl/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*
* @module GraphQL
*/
import { isNil, extend, omitBy, isUndefined } from 'lodash';
import { isNil, extend, isUndefined } from 'lodash';
import { reject } from 'ramda';
import gql from 'graphql-tag';
import { Interaction, InteractionStateComplete } from './interaction';
import { regex } from './matchers';
Expand Down Expand Up @@ -106,17 +107,14 @@ export class GraphQLInteraction extends Interaction {

this.state.request = extend(
{
body: omitBy(
{
operationName: this.operation,
query: regex({
generate: this.query,
matcher: escapeGraphQlQuery(this.query),
}),
variables: this.variables,
},
isUndefined
),
body: reject(isUndefined, {
operationName: this.operation,
query: regex({
generate: this.query,
matcher: escapeGraphQlQuery(this.query),
}),
variables: this.variables,
}),
headers: { 'Content-Type': 'application/json' },
method: 'POST',
},
Expand Down
18 changes: 8 additions & 10 deletions src/dsl/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @module Interaction
*/

import { isNil, keys, omitBy } from 'lodash';
import { isNil, keys } from 'lodash';
import { reject } from 'ramda';
import { HTTPMethods, HTTPMethod } from '../common/request';
import { Matcher, isMatcher, AnyTemplate } from './matchers';
import ConfigurationError from '../errors/configurationError';
Expand Down Expand Up @@ -131,7 +132,7 @@ export class Interaction {
throwIfQueryObjectInvalid(requestOpts.query);
}

this.state.request = omitBy(requestOpts, isNil) as RequestOptions;
this.state.request = reject(isNil, requestOpts) as RequestOptions;

return this;
}
Expand All @@ -152,14 +153,11 @@ export class Interaction {
throw new ConfigurationError('You must provide a status code.');
}

this.state.response = omitBy(
{
body: responseOpts.body,
headers: responseOpts.headers || undefined,
status: responseOpts.status,
},
isNil
) as ResponseOptions;
this.state.response = reject(isNil, {
body: responseOpts.body,
headers: responseOpts.headers || undefined,
status: responseOpts.status,
}) as ResponseOptions;
return this;
}

Expand Down

0 comments on commit fedcc2e

Please sign in to comment.