Skip to content

Commit 9858727

Browse files
authored
feat(transport): Upgrade transport to 8.4.0 (#40)
Includes support for [new redaction features](elastic/elastic-transport-js#76).
1 parent 2156cc1 commit 9858727

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"zx": "^7.2.2"
7878
},
7979
"dependencies": {
80-
"@elastic/transport": "^8.3.2",
80+
"@elastic/transport": "^8.4.0",
8181
"tslib": "^2.5.0"
8282
},
8383
"tap": {

src/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
BearerAuth,
4141
Context
4242
} from '@elastic/transport/lib/types'
43+
import { RedactionOptions } from '@elastic/transport/lib/Transport'
4344
import BaseConnection, { prepareHeaders } from '@elastic/transport/lib/connection/BaseConnection'
4445
import Helpers from './helpers'
4546
import API from './api'
@@ -104,6 +105,7 @@ export interface ClientOptions {
104105
caFingerprint?: string
105106
maxResponseSize?: number
106107
maxCompressedResponseSize?: number
108+
redaction?: RedactionOptions
107109
}
108110

109111
export default class Client extends API {
@@ -173,7 +175,11 @@ export default class Client extends API {
173175
proxy: null,
174176
enableMetaHeader: true,
175177
maxResponseSize: null,
176-
maxCompressedResponseSize: null
178+
maxCompressedResponseSize: null,
179+
redaction: {
180+
type: 'replace',
181+
additionalKeys: []
182+
}
177183
}, opts)
178184

179185
if (options.caFingerprint != null && isHttpConnection(opts.node ?? opts.nodes)) {
@@ -241,7 +247,8 @@ export default class Client extends API {
241247
context: options.context,
242248
productCheck: 'Elasticsearch',
243249
maxResponseSize: options.maxResponseSize,
244-
maxCompressedResponseSize: options.maxCompressedResponseSize
250+
maxCompressedResponseSize: options.maxCompressedResponseSize,
251+
redaction: options.redaction
245252
})
246253

247254
this.helpers = new Helpers({

src/helpers.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ export default class Helpers {
193193
await sleep(wait)
194194
}
195195
assert(response !== undefined, 'The response is undefined, please file a bug report')
196+
197+
const { redaction = { type: 'replace' } } = options
198+
const errorOptions = { redaction }
196199
if (response.statusCode === 429) {
197-
throw new ResponseError(response)
200+
throw new ResponseError(response, errorOptions)
198201
}
199202

200203
let scroll_id = response.body._scroll_id
@@ -234,7 +237,7 @@ export default class Helpers {
234237
await sleep(wait)
235238
}
236239
if (response.statusCode === 429) {
237-
throw new ResponseError(response)
240+
throw new ResponseError(response, errorOptions)
238241
}
239242
}
240243

@@ -286,6 +289,9 @@ export default class Helpers {
286289
} = options
287290
reqOptions.meta = true
288291

292+
const { redaction = { type: 'replace' } } = reqOptions
293+
const errorOptions = { redaction }
294+
289295
let stopReading = false
290296
let stopError: Error | null = null
291297
let timeoutRef = null
@@ -499,7 +505,7 @@ export default class Helpers {
499505
// @ts-expect-error
500506
addDocumentsGetter(result)
501507
if (response.status != null && response.status >= 400) {
502-
callbacks[i](new ResponseError(result), result)
508+
callbacks[i](new ResponseError(result, errorOptions), result)
503509
} else {
504510
callbacks[i](null, result)
505511
}

0 commit comments

Comments
 (0)