Skip to content

Commit

Permalink
feat(transport): Upgrade transport to 8.4.0 (#40)
Browse files Browse the repository at this point in the history
Includes support for [new redaction features](elastic/elastic-transport-js#76).
  • Loading branch information
JoshMock committed Dec 14, 2023
1 parent 2156cc1 commit 9858727
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"zx": "^7.2.2"
},
"dependencies": {
"@elastic/transport": "^8.3.2",
"@elastic/transport": "^8.4.0",
"tslib": "^2.5.0"
},
"tap": {
Expand Down
11 changes: 9 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
BearerAuth,
Context
} from '@elastic/transport/lib/types'
import { RedactionOptions } from '@elastic/transport/lib/Transport'
import BaseConnection, { prepareHeaders } from '@elastic/transport/lib/connection/BaseConnection'
import Helpers from './helpers'
import API from './api'
Expand Down Expand Up @@ -104,6 +105,7 @@ export interface ClientOptions {
caFingerprint?: string
maxResponseSize?: number
maxCompressedResponseSize?: number
redaction?: RedactionOptions
}

export default class Client extends API {
Expand Down Expand Up @@ -173,7 +175,11 @@ export default class Client extends API {
proxy: null,
enableMetaHeader: true,
maxResponseSize: null,
maxCompressedResponseSize: null
maxCompressedResponseSize: null,
redaction: {
type: 'replace',
additionalKeys: []
}
}, opts)

if (options.caFingerprint != null && isHttpConnection(opts.node ?? opts.nodes)) {
Expand Down Expand Up @@ -241,7 +247,8 @@ export default class Client extends API {
context: options.context,
productCheck: 'Elasticsearch',
maxResponseSize: options.maxResponseSize,
maxCompressedResponseSize: options.maxCompressedResponseSize
maxCompressedResponseSize: options.maxCompressedResponseSize,
redaction: options.redaction
})

this.helpers = new Helpers({
Expand Down
12 changes: 9 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,11 @@ export default class Helpers {
await sleep(wait)
}
assert(response !== undefined, 'The response is undefined, please file a bug report')

const { redaction = { type: 'replace' } } = options
const errorOptions = { redaction }
if (response.statusCode === 429) {
throw new ResponseError(response)
throw new ResponseError(response, errorOptions)
}

let scroll_id = response.body._scroll_id
Expand Down Expand Up @@ -234,7 +237,7 @@ export default class Helpers {
await sleep(wait)
}
if (response.statusCode === 429) {
throw new ResponseError(response)
throw new ResponseError(response, errorOptions)
}
}

Expand Down Expand Up @@ -286,6 +289,9 @@ export default class Helpers {
} = options
reqOptions.meta = true

const { redaction = { type: 'replace' } } = reqOptions
const errorOptions = { redaction }

let stopReading = false
let stopError: Error | null = null
let timeoutRef = null
Expand Down Expand Up @@ -499,7 +505,7 @@ export default class Helpers {
// @ts-expect-error
addDocumentsGetter(result)
if (response.status != null && response.status >= 400) {
callbacks[i](new ResponseError(result), result)
callbacks[i](new ResponseError(result, errorOptions), result)
} else {
callbacks[i](null, result)
}
Expand Down

0 comments on commit 9858727

Please sign in to comment.