@elastic/transport
Advanced tools
Comparing version 8.3.4 to 8.4.0
@@ -128,3 +128,4 @@ "use strict"; | ||
if (options.signal != null) { | ||
options.signal.dispatchEvent('abort'); | ||
// @ts-expect-error Event is a Node.js global | ||
options.signal.dispatchEvent(new Event('abort')); | ||
} | ||
@@ -131,0 +132,0 @@ else { |
/// <reference types="node" /> | ||
import * as http from 'http'; | ||
import { DiagnosticResult } from './types'; | ||
import { RedactionOptions } from './Transport'; | ||
export interface ErrorOptions { | ||
redaction: RedactionOptions; | ||
} | ||
export declare class ElasticsearchClientError extends Error { | ||
constructor(message: string); | ||
options: ErrorOptions; | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
export declare class TimeoutError extends ElasticsearchClientError { | ||
meta?: DiagnosticResult; | ||
constructor(message: string, meta?: DiagnosticResult); | ||
constructor(message: string, meta?: DiagnosticResult, options?: ErrorOptions); | ||
} | ||
export declare class ConnectionError extends ElasticsearchClientError { | ||
meta?: DiagnosticResult; | ||
constructor(message: string, meta?: DiagnosticResult); | ||
constructor(message: string, meta?: DiagnosticResult, options?: ErrorOptions); | ||
} | ||
export declare class NoLivingConnectionsError extends ElasticsearchClientError { | ||
meta: DiagnosticResult; | ||
constructor(message: string, meta: DiagnosticResult); | ||
constructor(message: string, meta: DiagnosticResult, options?: ErrorOptions); | ||
} | ||
@@ -32,3 +37,3 @@ export declare class SerializationError extends ElasticsearchClientError { | ||
meta: DiagnosticResult; | ||
constructor(meta: DiagnosticResult); | ||
constructor(meta: DiagnosticResult, options?: ErrorOptions); | ||
get body(): any | undefined; | ||
@@ -40,7 +45,7 @@ get statusCode(): number | undefined; | ||
meta?: DiagnosticResult; | ||
constructor(message: string, meta?: DiagnosticResult); | ||
constructor(message: string, meta?: DiagnosticResult, options?: ErrorOptions); | ||
} | ||
export declare class ProductNotSupportedError extends ElasticsearchClientError { | ||
meta?: DiagnosticResult; | ||
constructor(product: string, meta?: DiagnosticResult); | ||
constructor(product: string, meta?: DiagnosticResult, options?: ErrorOptions); | ||
} |
@@ -22,6 +22,22 @@ "use strict"; | ||
exports.ProductNotSupportedError = exports.RequestAbortedError = exports.ResponseError = exports.ConfigurationError = exports.DeserializationError = exports.SerializationError = exports.NoLivingConnectionsError = exports.ConnectionError = exports.TimeoutError = exports.ElasticsearchClientError = void 0; | ||
const security_1 = require("./security"); | ||
class ElasticsearchClientError extends Error { | ||
constructor(message) { | ||
constructor(message, options) { | ||
super(message); | ||
Object.defineProperty(this, "options", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.name = 'ElasticsearchClientError'; | ||
this.options = { | ||
redaction: { | ||
type: 'replace', | ||
additionalKeys: [] | ||
} | ||
}; | ||
if (isObject(options)) { | ||
this.options.redaction = { ...this.options.redaction, ...options.redaction }; | ||
} | ||
} | ||
@@ -31,4 +47,4 @@ } | ||
class TimeoutError extends ElasticsearchClientError { | ||
constructor(message, meta) { | ||
super(message); | ||
constructor(message, meta, options) { | ||
super(message, options); | ||
Object.defineProperty(this, "meta", { | ||
@@ -43,2 +59,4 @@ enumerable: true, | ||
this.message = message !== null && message !== void 0 ? message : 'Timeout Error'; | ||
if (isObject(meta)) | ||
meta = (0, security_1.redactDiagnostic)(meta, this.options.redaction); | ||
this.meta = meta; | ||
@@ -49,4 +67,4 @@ } | ||
class ConnectionError extends ElasticsearchClientError { | ||
constructor(message, meta) { | ||
super(message); | ||
constructor(message, meta, options) { | ||
super(message, options); | ||
Object.defineProperty(this, "meta", { | ||
@@ -61,2 +79,4 @@ enumerable: true, | ||
this.message = message !== null && message !== void 0 ? message : 'Connection Error'; | ||
if (isObject(meta)) | ||
meta = (0, security_1.redactDiagnostic)(meta, this.options.redaction); | ||
this.meta = meta; | ||
@@ -67,4 +87,4 @@ } | ||
class NoLivingConnectionsError extends ElasticsearchClientError { | ||
constructor(message, meta) { | ||
super(message); | ||
constructor(message, meta, options) { | ||
super(message, options); | ||
Object.defineProperty(this, "meta", { | ||
@@ -79,3 +99,3 @@ enumerable: true, | ||
this.message = message !== null && message !== void 0 ? message : 'Given the configuration, the ConnectionPool was not able to find a usable Connection for this request.'; | ||
this.meta = meta; | ||
this.meta = (0, security_1.redactDiagnostic)(meta, this.options.redaction); | ||
} | ||
@@ -126,5 +146,5 @@ } | ||
class ResponseError extends ElasticsearchClientError { | ||
constructor(meta) { | ||
constructor(meta, options) { | ||
var _a; | ||
super('Response Error'); | ||
super('Response Error', options); | ||
Object.defineProperty(this, "meta", { | ||
@@ -164,3 +184,3 @@ enumerable: true, | ||
} | ||
this.meta = meta; | ||
this.meta = (0, security_1.redactDiagnostic)(meta, this.options.redaction); | ||
} | ||
@@ -182,4 +202,4 @@ get body() { | ||
class RequestAbortedError extends ElasticsearchClientError { | ||
constructor(message, meta) { | ||
super(message); | ||
constructor(message, meta, options) { | ||
super(message, options); | ||
Object.defineProperty(this, "meta", { | ||
@@ -194,2 +214,4 @@ enumerable: true, | ||
this.message = message !== null && message !== void 0 ? message : 'Request aborted'; | ||
if (isObject(meta)) | ||
meta = (0, security_1.redactDiagnostic)(meta, this.options.redaction); | ||
this.meta = meta; | ||
@@ -200,4 +222,4 @@ } | ||
class ProductNotSupportedError extends ElasticsearchClientError { | ||
constructor(product, meta) { | ||
super('Product Not Supported Error'); | ||
constructor(product, meta, options) { | ||
super('Product Not Supported Error', options); | ||
Object.defineProperty(this, "meta", { | ||
@@ -212,2 +234,4 @@ enumerable: true, | ||
this.message = `The client noticed that the server is not ${product} and we do not support this unknown product.`; | ||
if (isObject(meta)) | ||
meta = (0, security_1.redactDiagnostic)(meta, this.options.redaction); | ||
this.meta = meta; | ||
@@ -218,4 +242,4 @@ } | ||
function isObject(obj) { | ||
return typeof obj === 'object'; | ||
return typeof obj === 'object' && obj !== null; | ||
} | ||
//# sourceMappingURL=errors.js.map |
@@ -30,1 +30,2 @@ export declare const kSniffEnabled: unique symbol; | ||
export declare const kAcceptHeader: unique symbol; | ||
export declare const kRedaction: unique symbol; |
@@ -21,3 +21,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.kAcceptHeader = exports.kNdjsonContentType = exports.kJsonContentType = exports.kMaxCompressedResponseSize = exports.kMaxResponseSize = exports.kCaFingerprint = exports.kProductCheck = exports.kEmitter = exports.kStatus = exports.kJsonOptions = exports.kNodeSelector = exports.kNodeFilter = exports.kHeaders = exports.kDiagnostic = exports.kSerializer = exports.kConnectionPool = exports.kContext = exports.kGenerateRequestId = exports.kOpaqueIdPrefix = exports.kName = exports.kMaxRetries = exports.kCompression = exports.kRequestTimeout = exports.kSniffEndpoint = exports.kSniffOnConnectionFault = exports.kSniffInterval = exports.kIsSniffing = exports.kNextSniff = exports.kSniffEnabled = void 0; | ||
exports.kRedaction = exports.kAcceptHeader = exports.kNdjsonContentType = exports.kJsonContentType = exports.kMaxCompressedResponseSize = exports.kMaxResponseSize = exports.kCaFingerprint = exports.kProductCheck = exports.kEmitter = exports.kStatus = exports.kJsonOptions = exports.kNodeSelector = exports.kNodeFilter = exports.kHeaders = exports.kDiagnostic = exports.kSerializer = exports.kConnectionPool = exports.kContext = exports.kGenerateRequestId = exports.kOpaqueIdPrefix = exports.kName = exports.kMaxRetries = exports.kCompression = exports.kRequestTimeout = exports.kSniffEndpoint = exports.kSniffOnConnectionFault = exports.kSniffInterval = exports.kIsSniffing = exports.kNextSniff = exports.kSniffEnabled = void 0; | ||
exports.kSniffEnabled = Symbol('sniff enabled'); | ||
@@ -52,2 +52,3 @@ exports.kNextSniff = Symbol('next sniff'); | ||
exports.kAcceptHeader = Symbol('accept header'); | ||
exports.kRedaction = Symbol('redaction'); | ||
//# sourceMappingURL=symbols.js.map |
@@ -9,3 +9,3 @@ /// <reference types="node" /> | ||
import { nodeFilterFn, nodeSelectorFn, generateRequestIdFn, RequestBody, RequestNDBody, TransportResult, Context } from './types'; | ||
import { kSniffEnabled, kNextSniff, kIsSniffing, kSniffInterval, kSniffOnConnectionFault, kSniffEndpoint, kRequestTimeout, kCompression, kMaxRetries, kName, kOpaqueIdPrefix, kGenerateRequestId, kContext, kConnectionPool, kSerializer, kDiagnostic, kHeaders, kNodeFilter, kNodeSelector, kProductCheck, kMaxResponseSize, kMaxCompressedResponseSize, kJsonContentType, kNdjsonContentType, kAcceptHeader } from './symbols'; | ||
import { kSniffEnabled, kNextSniff, kIsSniffing, kSniffInterval, kSniffOnConnectionFault, kSniffEndpoint, kRequestTimeout, kCompression, kMaxRetries, kName, kOpaqueIdPrefix, kGenerateRequestId, kContext, kConnectionPool, kSerializer, kDiagnostic, kHeaders, kNodeFilter, kNodeSelector, kProductCheck, kMaxResponseSize, kMaxCompressedResponseSize, kJsonContentType, kNdjsonContentType, kAcceptHeader, kRedaction } from './symbols'; | ||
export interface TransportOptions { | ||
@@ -37,2 +37,3 @@ diagnostic?: Diagnostic; | ||
}; | ||
redaction?: RedactionOptions; | ||
} | ||
@@ -82,2 +83,3 @@ export interface TransportRequestParams { | ||
meta?: boolean; | ||
redaction?: RedactionOptions; | ||
} | ||
@@ -99,2 +101,6 @@ export interface TransportRequestOptionsWithMeta extends TransportRequestOptions { | ||
} | ||
export interface RedactionOptions { | ||
type: 'off' | 'replace' | 'remove'; | ||
additionalKeys?: string[]; | ||
} | ||
export default class Transport { | ||
@@ -126,2 +132,3 @@ [kNodeFilter]: nodeFilterFn; | ||
[kAcceptHeader]: string; | ||
[kRedaction]: RedactionOptions; | ||
static sniffReasons: { | ||
@@ -128,0 +135,0 @@ SNIFF_ON_START: string; |
@@ -20,3 +20,3 @@ "use strict"; | ||
*/ | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -43,3 +43,3 @@ exports.lowerCaseHeaders = exports.generateRequestId = void 0; | ||
constructor(opts) { | ||
var _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20; | ||
var _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22; | ||
Object.defineProperty(this, _a, { | ||
@@ -195,2 +195,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(this, _1, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
if (opts.connectionPool == null) { | ||
@@ -212,27 +218,28 @@ throw new errors_1.ConfigurationError('The Connection Pool option is not defined'); | ||
} | ||
this[symbols_1.kNodeFilter] = (_1 = opts.nodeFilter) !== null && _1 !== void 0 ? _1 : defaultNodeFilter; | ||
this[symbols_1.kNodeSelector] = (_2 = opts.nodeSelector) !== null && _2 !== void 0 ? _2 : roundRobinSelector(); | ||
this[symbols_1.kNodeFilter] = (_2 = opts.nodeFilter) !== null && _2 !== void 0 ? _2 : defaultNodeFilter; | ||
this[symbols_1.kNodeSelector] = (_3 = opts.nodeSelector) !== null && _3 !== void 0 ? _3 : roundRobinSelector(); | ||
this[symbols_1.kHeaders] = Object.assign({}, { 'user-agent': userAgent }, opts.compression === true ? { 'accept-encoding': 'gzip,deflate' } : null, lowerCaseHeaders(opts.headers)); | ||
this[symbols_1.kDiagnostic] = (_3 = opts.diagnostic) !== null && _3 !== void 0 ? _3 : new Diagnostic_1.default(); | ||
this[symbols_1.kDiagnostic] = (_4 = opts.diagnostic) !== null && _4 !== void 0 ? _4 : new Diagnostic_1.default(); | ||
this[symbols_1.kConnectionPool] = opts.connectionPool; | ||
this[symbols_1.kSerializer] = (_4 = opts.serializer) !== null && _4 !== void 0 ? _4 : new Serializer_1.default(); | ||
this[symbols_1.kContext] = (_5 = opts.context) !== null && _5 !== void 0 ? _5 : null; | ||
this[symbols_1.kGenerateRequestId] = (_6 = opts.generateRequestId) !== null && _6 !== void 0 ? _6 : generateRequestId(); | ||
this[symbols_1.kOpaqueIdPrefix] = (_7 = opts.opaqueIdPrefix) !== null && _7 !== void 0 ? _7 : null; | ||
this[symbols_1.kName] = (_8 = opts.name) !== null && _8 !== void 0 ? _8 : 'elastic-transport-js'; | ||
this[symbols_1.kSerializer] = (_5 = opts.serializer) !== null && _5 !== void 0 ? _5 : new Serializer_1.default(); | ||
this[symbols_1.kContext] = (_6 = opts.context) !== null && _6 !== void 0 ? _6 : null; | ||
this[symbols_1.kGenerateRequestId] = (_7 = opts.generateRequestId) !== null && _7 !== void 0 ? _7 : generateRequestId(); | ||
this[symbols_1.kOpaqueIdPrefix] = (_8 = opts.opaqueIdPrefix) !== null && _8 !== void 0 ? _8 : null; | ||
this[symbols_1.kName] = (_9 = opts.name) !== null && _9 !== void 0 ? _9 : 'elastic-transport-js'; | ||
this[symbols_1.kMaxRetries] = typeof opts.maxRetries === 'number' ? opts.maxRetries : 3; | ||
this[symbols_1.kCompression] = opts.compression === true; | ||
this[symbols_1.kRequestTimeout] = opts.requestTimeout != null ? toMs(opts.requestTimeout) : 30000; | ||
this[symbols_1.kSniffInterval] = (_9 = opts.sniffInterval) !== null && _9 !== void 0 ? _9 : false; | ||
this[symbols_1.kSniffInterval] = (_10 = opts.sniffInterval) !== null && _10 !== void 0 ? _10 : false; | ||
this[symbols_1.kSniffEnabled] = typeof this[symbols_1.kSniffInterval] === 'number'; | ||
this[symbols_1.kNextSniff] = this[symbols_1.kSniffEnabled] ? (Date.now() + this[symbols_1.kSniffInterval]) : 0; | ||
this[symbols_1.kIsSniffing] = false; | ||
this[symbols_1.kSniffOnConnectionFault] = (_10 = opts.sniffOnConnectionFault) !== null && _10 !== void 0 ? _10 : false; | ||
this[symbols_1.kSniffEndpoint] = (_11 = opts.sniffEndpoint) !== null && _11 !== void 0 ? _11 : null; | ||
this[symbols_1.kProductCheck] = (_12 = opts.productCheck) !== null && _12 !== void 0 ? _12 : null; | ||
this[symbols_1.kMaxResponseSize] = (_13 = opts.maxResponseSize) !== null && _13 !== void 0 ? _13 : buffer_1.default.constants.MAX_STRING_LENGTH; | ||
this[symbols_1.kMaxCompressedResponseSize] = (_14 = opts.maxCompressedResponseSize) !== null && _14 !== void 0 ? _14 : buffer_1.default.constants.MAX_LENGTH; | ||
this[symbols_1.kJsonContentType] = (_16 = (_15 = opts.vendoredHeaders) === null || _15 === void 0 ? void 0 : _15.jsonContentType) !== null && _16 !== void 0 ? _16 : 'application/json'; | ||
this[symbols_1.kNdjsonContentType] = (_18 = (_17 = opts.vendoredHeaders) === null || _17 === void 0 ? void 0 : _17.ndjsonContentType) !== null && _18 !== void 0 ? _18 : 'application/x-ndjson'; | ||
this[symbols_1.kAcceptHeader] = (_20 = (_19 = opts.vendoredHeaders) === null || _19 === void 0 ? void 0 : _19.accept) !== null && _20 !== void 0 ? _20 : 'application/json, text/plain'; | ||
this[symbols_1.kSniffOnConnectionFault] = (_11 = opts.sniffOnConnectionFault) !== null && _11 !== void 0 ? _11 : false; | ||
this[symbols_1.kSniffEndpoint] = (_12 = opts.sniffEndpoint) !== null && _12 !== void 0 ? _12 : null; | ||
this[symbols_1.kProductCheck] = (_13 = opts.productCheck) !== null && _13 !== void 0 ? _13 : null; | ||
this[symbols_1.kMaxResponseSize] = (_14 = opts.maxResponseSize) !== null && _14 !== void 0 ? _14 : buffer_1.default.constants.MAX_STRING_LENGTH; | ||
this[symbols_1.kMaxCompressedResponseSize] = (_15 = opts.maxCompressedResponseSize) !== null && _15 !== void 0 ? _15 : buffer_1.default.constants.MAX_LENGTH; | ||
this[symbols_1.kJsonContentType] = (_17 = (_16 = opts.vendoredHeaders) === null || _16 === void 0 ? void 0 : _16.jsonContentType) !== null && _17 !== void 0 ? _17 : 'application/json'; | ||
this[symbols_1.kNdjsonContentType] = (_19 = (_18 = opts.vendoredHeaders) === null || _18 === void 0 ? void 0 : _18.ndjsonContentType) !== null && _19 !== void 0 ? _19 : 'application/x-ndjson'; | ||
this[symbols_1.kAcceptHeader] = (_21 = (_20 = opts.vendoredHeaders) === null || _20 === void 0 ? void 0 : _20.accept) !== null && _21 !== void 0 ? _21 : 'application/json, text/plain'; | ||
this[symbols_1.kRedaction] = (_22 = opts.redaction) !== null && _22 !== void 0 ? _22 : { type: 'replace', additionalKeys: [] }; | ||
if (opts.sniffOnStart === true) { | ||
@@ -271,3 +278,3 @@ this.sniff({ | ||
async request(params, options = {}) { | ||
var _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16; | ||
var _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17; | ||
const connectionParams = { | ||
@@ -282,3 +289,3 @@ method: params.method, | ||
options: options, | ||
id: (_1 = options.id) !== null && _1 !== void 0 ? _1 : this[symbols_1.kGenerateRequestId](params, options) | ||
id: (_2 = options.id) !== null && _2 !== void 0 ? _2 : this[symbols_1.kGenerateRequestId](params, options) | ||
}, | ||
@@ -290,3 +297,3 @@ name: this[symbols_1.kName], | ||
}; | ||
const returnMeta = (_2 = options.meta) !== null && _2 !== void 0 ? _2 : false; | ||
const returnMeta = (_3 = options.meta) !== null && _3 !== void 0 ? _3 : false; | ||
if (this[symbols_1.kContext] != null && options.context != null) { | ||
@@ -309,6 +316,9 @@ meta.context = Object.assign({}, this[symbols_1.kContext], options.context); | ||
get warnings() { | ||
var _1; | ||
return ((_1 = this.headers) === null || _1 === void 0 ? void 0 : _1.warning) != null | ||
? this.headers.warning.split(/(?!\B"[^"]*),(?![^"]*"\B)/) | ||
: null; | ||
var _2; | ||
if (((_2 = this.headers) === null || _2 === void 0 ? void 0 : _2.warning) == null) { | ||
return null; | ||
} | ||
return this.headers.warning | ||
.split(/(?!\B"[^"]*),(?![^"]*"\B)/) | ||
.filter((warning) => warning.match(/^\d\d\d Elasticsearch-/)); | ||
} | ||
@@ -319,8 +329,11 @@ }; | ||
// the size of the stream, we risk to take too much memory. | ||
// Furthermore, copying everytime the stream is very a expensive operation. | ||
const maxRetries = isStream((_3 = params.body) !== null && _3 !== void 0 ? _3 : params.bulkBody) ? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this[symbols_1.kMaxRetries]); | ||
// Furthermore, copying every time the stream is very a expensive operation. | ||
const maxRetries = isStream((_4 = params.body) !== null && _4 !== void 0 ? _4 : params.bulkBody) ? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this[symbols_1.kMaxRetries]); | ||
const compression = typeof options.compression === 'boolean' ? options.compression : this[symbols_1.kCompression]; | ||
const signal = options.signal; | ||
const maxResponseSize = (_4 = options.maxResponseSize) !== null && _4 !== void 0 ? _4 : this[symbols_1.kMaxResponseSize]; | ||
const maxCompressedResponseSize = (_5 = options.maxCompressedResponseSize) !== null && _5 !== void 0 ? _5 : this[symbols_1.kMaxCompressedResponseSize]; | ||
const maxResponseSize = (_5 = options.maxResponseSize) !== null && _5 !== void 0 ? _5 : this[symbols_1.kMaxResponseSize]; | ||
const maxCompressedResponseSize = (_6 = options.maxCompressedResponseSize) !== null && _6 !== void 0 ? _6 : this[symbols_1.kMaxCompressedResponseSize]; | ||
const errorOptions = { | ||
redaction: typeof options.redaction === 'object' ? options.redaction : this[symbols_1.kRedaction] | ||
}; | ||
this[symbols_1.kDiagnostic].emit('serialization', null, result); | ||
@@ -343,9 +356,9 @@ const headers = Object.assign({}, this[symbols_1.kHeaders], lowerCaseHeaders(options.headers)); | ||
} | ||
headers['content-type'] = (_6 = headers['content-type']) !== null && _6 !== void 0 ? _6 : this[symbols_1.kJsonContentType]; | ||
headers.accept = (_7 = headers.accept) !== null && _7 !== void 0 ? _7 : this[symbols_1.kJsonContentType]; | ||
headers['content-type'] = (_7 = headers['content-type']) !== null && _7 !== void 0 ? _7 : this[symbols_1.kJsonContentType]; | ||
headers.accept = (_8 = headers.accept) !== null && _8 !== void 0 ? _8 : this[symbols_1.kJsonContentType]; | ||
} | ||
else { | ||
if (params.body !== '') { | ||
headers['content-type'] = (_8 = headers['content-type']) !== null && _8 !== void 0 ? _8 : 'text/plain'; | ||
headers.accept = (_9 = headers.accept) !== null && _9 !== void 0 ? _9 : this[symbols_1.kAcceptHeader]; | ||
headers['content-type'] = (_9 = headers['content-type']) !== null && _9 !== void 0 ? _9 : 'text/plain'; | ||
headers.accept = (_10 = headers.accept) !== null && _10 !== void 0 ? _10 : this[symbols_1.kAcceptHeader]; | ||
} | ||
@@ -370,4 +383,4 @@ connectionParams.body = params.body; | ||
if (connectionParams.body !== '') { | ||
headers['content-type'] = (_10 = headers['content-type']) !== null && _10 !== void 0 ? _10 : this[symbols_1.kNdjsonContentType]; | ||
headers.accept = (_11 = headers.accept) !== null && _11 !== void 0 ? _11 : this[symbols_1.kJsonContentType]; | ||
headers['content-type'] = (_11 = headers['content-type']) !== null && _11 !== void 0 ? _11 : this[symbols_1.kNdjsonContentType]; | ||
headers.accept = (_12 = headers.accept) !== null && _12 !== void 0 ? _12 : this[symbols_1.kJsonContentType]; | ||
} | ||
@@ -407,3 +420,3 @@ } | ||
} | ||
headers.accept = (_12 = headers.accept) !== null && _12 !== void 0 ? _12 : this[symbols_1.kAcceptHeader]; | ||
headers.accept = (_13 = headers.accept) !== null && _13 !== void 0 ? _13 : this[symbols_1.kAcceptHeader]; | ||
connectionParams.headers = headers; | ||
@@ -413,3 +426,3 @@ while (meta.attempts <= maxRetries) { | ||
if (signal === null || signal === void 0 ? void 0 : signal.aborted) { // eslint-disable-line | ||
throw new errors_1.RequestAbortedError('Request has been aborted by the user', result); | ||
throw new errors_1.RequestAbortedError('Request has been aborted by the user', result, errorOptions); | ||
} | ||
@@ -421,3 +434,3 @@ meta.connection = this.getConnection({ | ||
if (meta.connection === null) { | ||
throw new errors_1.NoLivingConnectionsError('There are no living connections', result); | ||
throw new errors_1.NoLivingConnectionsError('There are no living connections', result, errorOptions); | ||
} | ||
@@ -441,3 +454,3 @@ this[symbols_1.kDiagnostic].emit('request', null, result); | ||
// @ts-ignore | ||
throw new errors_1.ProductNotSupportedError(this[symbols_1.kProductCheck], result); | ||
throw new errors_1.ProductNotSupportedError(this[symbols_1.kProductCheck], result, errorOptions); | ||
/* eslint-enable @typescript-eslint/prefer-ts-expect-error */ | ||
@@ -450,7 +463,7 @@ } | ||
} | ||
const contentEncoding = ((_13 = headers['content-encoding']) !== null && _13 !== void 0 ? _13 : '').toLowerCase(); | ||
const contentEncoding = ((_14 = headers['content-encoding']) !== null && _14 !== void 0 ? _14 : '').toLowerCase(); | ||
if (contentEncoding.includes('gzip') || contentEncoding.includes('deflate')) { | ||
body = await unzip(body); | ||
} | ||
const isVectorTile = ((_14 = headers['content-type']) !== null && _14 !== void 0 ? _14 : '').includes('application/vnd.mapbox-vector-tile'); | ||
const isVectorTile = ((_15 = headers['content-type']) !== null && _15 !== void 0 ? _15 : '').includes('application/vnd.mapbox-vector-tile'); | ||
if (Buffer.isBuffer(body) && !isVectorTile) { | ||
@@ -465,4 +478,4 @@ body = body.toString(); | ||
if (headers['content-type'] !== undefined && | ||
(((_15 = headers['content-type']) === null || _15 === void 0 ? void 0 : _15.includes('application/json')) || | ||
((_16 = headers['content-type']) === null || _16 === void 0 ? void 0 : _16.includes('application/vnd.elasticsearch+json'))) && | ||
(((_16 = headers['content-type']) === null || _16 === void 0 ? void 0 : _16.includes('application/json')) || | ||
((_17 = headers['content-type']) === null || _17 === void 0 ? void 0 : _17.includes('application/vnd.elasticsearch+json'))) && | ||
!isHead && body !== '') { // eslint-disable-line | ||
@@ -496,3 +509,3 @@ result.body = this[symbols_1.kSerializer].deserialize(body); | ||
if (!ignoreStatusCode && statusCode >= 400) { | ||
throw new errors_1.ResponseError(result); | ||
throw new errors_1.ResponseError(result, errorOptions); | ||
} | ||
@@ -520,3 +533,3 @@ else { | ||
// Wrap the error to get a clean stack trace | ||
const wrappedError = new errors_1.RequestAbortedError(error.message, result); | ||
const wrappedError = new errors_1.RequestAbortedError(error.message, result, errorOptions); | ||
this[symbols_1.kDiagnostic].emit('response', wrappedError, result); | ||
@@ -546,4 +559,4 @@ throw wrappedError; | ||
const wrappedError = error.name === 'TimeoutError' | ||
? new errors_1.TimeoutError(error.message, result) | ||
: new errors_1.ConnectionError(error.message, result); | ||
? new errors_1.TimeoutError(error.message, result, errorOptions) | ||
: new errors_1.ConnectionError(error.message, result, errorOptions); | ||
this[symbols_1.kDiagnostic].emit('response', wrappedError, result); | ||
@@ -584,3 +597,3 @@ throw wrappedError; | ||
exports.default = Transport; | ||
_a = symbols_1.kNodeFilter, _b = symbols_1.kNodeSelector, _c = symbols_1.kHeaders, _d = symbols_1.kDiagnostic, _e = symbols_1.kConnectionPool, _f = symbols_1.kSerializer, _g = symbols_1.kContext, _h = symbols_1.kGenerateRequestId, _j = symbols_1.kOpaqueIdPrefix, _k = symbols_1.kName, _l = symbols_1.kMaxRetries, _m = symbols_1.kCompression, _o = symbols_1.kRequestTimeout, _p = symbols_1.kSniffEnabled, _q = symbols_1.kNextSniff, _r = symbols_1.kIsSniffing, _s = symbols_1.kSniffInterval, _t = symbols_1.kSniffOnConnectionFault, _u = symbols_1.kSniffEndpoint, _v = symbols_1.kProductCheck, _w = symbols_1.kMaxResponseSize, _x = symbols_1.kMaxCompressedResponseSize, _y = symbols_1.kJsonContentType, _z = symbols_1.kNdjsonContentType, _0 = symbols_1.kAcceptHeader; | ||
_a = symbols_1.kNodeFilter, _b = symbols_1.kNodeSelector, _c = symbols_1.kHeaders, _d = symbols_1.kDiagnostic, _e = symbols_1.kConnectionPool, _f = symbols_1.kSerializer, _g = symbols_1.kContext, _h = symbols_1.kGenerateRequestId, _j = symbols_1.kOpaqueIdPrefix, _k = symbols_1.kName, _l = symbols_1.kMaxRetries, _m = symbols_1.kCompression, _o = symbols_1.kRequestTimeout, _p = symbols_1.kSniffEnabled, _q = symbols_1.kNextSniff, _r = symbols_1.kIsSniffing, _s = symbols_1.kSniffInterval, _t = symbols_1.kSniffOnConnectionFault, _u = symbols_1.kSniffEndpoint, _v = symbols_1.kProductCheck, _w = symbols_1.kMaxResponseSize, _x = symbols_1.kMaxCompressedResponseSize, _y = symbols_1.kJsonContentType, _z = symbols_1.kNdjsonContentType, _0 = symbols_1.kAcceptHeader, _1 = symbols_1.kRedaction; | ||
Object.defineProperty(Transport, "sniffReasons", { | ||
@@ -587,0 +600,0 @@ enumerable: true, |
{ | ||
"name": "@elastic/transport", | ||
"version": "8.3.4", | ||
"version": "8.4.0", | ||
"description": "Transport classes and utilities shared among Node.js Elastic client libraries", | ||
@@ -37,3 +37,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=14" | ||
"node": ">=16" | ||
}, | ||
@@ -48,2 +48,4 @@ "devDependencies": { | ||
"@types/tap": "^15.0.7", | ||
"@types/ungap__structured-clone": "^0.3.3", | ||
"@ungap/structured-clone": "^1.2.0", | ||
"into-stream": "^6.0.0", | ||
@@ -50,0 +52,0 @@ "license-checker": "^25.0.1", |
@@ -17,3 +17,3 @@ <img align="right" width="auto" height="auto" src="https://www.elastic.co/static-res/images/elastic-logo-200.png"> | ||
NOTE: The minimum supported version of Node.js is `v14`. | ||
NOTE: The minimum supported version of Node.js is `v16`. | ||
@@ -27,5 +27,3 @@ The client versioning follows the Elastc Stack versioning, this means that | ||
Typically, as soon as a Node.js version goes into EOL, the client will continue | ||
to support that version for at least another minor release. If you are using the client | ||
with a version of Node.js that will be unsupported soon, you will see a warning | ||
in your logs (the client will start logging the warning with two minors in advance). | ||
to support that version for at least another minor release. | ||
@@ -32,0 +30,0 @@ Unless you are **always** using a supported version of Node.js, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
245509
56
3794
20
48