Skip to content

Commit

Permalink
chore(sdk-auth): remove lodash.defaultsdeep dependency from sdk-auth …
Browse files Browse the repository at this point in the history
…package
  • Loading branch information
ajimae committed Jan 16, 2023
1 parent 16d951f commit 811c73e
Show file tree
Hide file tree
Showing 3 changed files with 391 additions and 624 deletions.
1 change: 0 additions & 1 deletion packages/sdk-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"dependencies": {
"@commercetools/sdk-middleware-http": "^7.0.0",
"lodash.defaultsdeep": "^4.6.1",
"qss": "2.0.3"
},
"devDependencies": {
Expand Down
17 changes: 2 additions & 15 deletions packages/sdk-auth/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,8 @@ export default class SdkAuth {
}

_getRequestConfig(config: CustomAuthOptions = {}): AuthOptions {

// It is important to note the difference between plain old javascript Object.assign()
// and the lodash _.defaultsDeep() functions especially how they are both used here

// _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }) // { a: { b: 2, c: 3 } }
// Object.assign({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }) // { a: { b: 1, c: 3 } }

// handle scopes array - Object.assign would merge arrays together
// instead of taking its first occurrence
// const mergedConfig = defaultsDeep({}, config, this.config)

const mergedConfig = typeof window === 'undefined' ?
// eslint-disable-next-line global-require, prefer-object-spread
require('lodash.defaultsdeep')({}, config, this.config) : Object.assign({}, this.config, config)

// eslint-disable-next-line prefer-object-spread
const mergedConfig = Object.assign({}, this.config, config)
if (config.scopes) mergedConfig.scopes = config.scopes

return mergedConfig
Expand Down
Loading

0 comments on commit 811c73e

Please sign in to comment.