Skip to content

Commit

Permalink
Change get to native code
Browse files Browse the repository at this point in the history
  • Loading branch information
ksvirkou-hubspot committed Feb 25, 2025
1 parent 1b553a5 commit 34f74df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/services/http/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class Auth {
public static chooseAuth(opts: IHttpOptions = {}, config: IConfiguration = {}): string | undefined {
let type
if (opts.authType) {
if (opts.authType !== 'none' && get(config, opts.authType)) {
if (opts.authType !== 'none' && opts.authType in config) {
type = opts.authType
}
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/services/http/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export class Request {
protected applyAuth() {
const authType = Auth.chooseAuth(this.opts, this.config)

if (authType) {
const method = get(AuthTypes, authType)
if (authType && authType in AuthTypes) {
const type = authType as keyof typeof AuthTypes

const method: keyof typeof AuthMethods = AuthTypes[type]
const value = get(this.config, authType)
if (method === AuthMethods.hapikey) {
this.url.searchParams.set('hapikey', value)
Expand All @@ -65,7 +67,7 @@ export class Request {
}

protected initHeaders() {
if (get(this.opts, 'defaultJson', true)) {
if (this.opts?.defaultJson ?? true) {
this.headers = { 'Content-Type': 'application/json' }
}

Expand All @@ -91,7 +93,7 @@ export class Request {
protected setBody() {
if (this.opts.body) {
this.body = this.opts.body
if (get(this.headers, 'Content-Type') === 'application/json' && get(this.opts, 'defaultJson', true)) {
if (this.opts?.defaultJson ?? true) {
this.body = JSON.stringify(this.body)
}
}
Expand Down

0 comments on commit 34f74df

Please sign in to comment.