Socket
Socket
Sign inDemoInstall

@elastic/transport

Package Overview
Dependencies
Maintainers
74
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elastic/transport - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

lib/connection/BaseConnection.d.ts

@@ -38,2 +38,4 @@ /// <reference types="node" />

context: any;
maxResponseSize?: number;
maxCompressedResponseSize?: number;
}

@@ -40,0 +42,0 @@ export interface ConnectionRequestResponse {

2

lib/connection/BaseConnection.js

@@ -25,3 +25,3 @@ "use strict";

const util_1 = require("util");
const Diagnostic_1 = tslib_1.__importDefault(require("../Diagnostic"));
const Diagnostic_1 = (0, tslib_1.__importDefault)(require("../Diagnostic"));
const errors_1 = require("../errors");

@@ -28,0 +28,0 @@ const symbols_1 = require("../symbols");

@@ -22,14 +22,14 @@ "use strict";

const tslib_1 = require("tslib");
const hpagent_1 = tslib_1.__importDefault(require("hpagent"));
const http_1 = tslib_1.__importDefault(require("http"));
const https_1 = tslib_1.__importDefault(require("https"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const buffer_1 = tslib_1.__importDefault(require("buffer"));
const hpagent_1 = (0, tslib_1.__importDefault)(require("hpagent"));
const http_1 = (0, tslib_1.__importDefault)(require("http"));
const https_1 = (0, tslib_1.__importDefault)(require("https"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const buffer_1 = (0, tslib_1.__importDefault)(require("buffer"));
const util_1 = require("util");
const BaseConnection_1 = tslib_1.__importStar(require("./BaseConnection"));
const BaseConnection_1 = (0, tslib_1.__importStar)(require("./BaseConnection"));
const symbols_1 = require("../symbols");
const stream_1 = require("stream");
const errors_1 = require("../errors");
const sleep = util_1.promisify(setTimeout);
const debug = debug_1.default('elasticsearch');
const sleep = (0, util_1.promisify)(setTimeout);
const debug = (0, debug_1.default)('elasticsearch');
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;

@@ -91,4 +91,7 @@ const MAX_BUFFER_LENGTH = buffer_1.default.constants.MAX_LENGTH;

return await new Promise((resolve, reject) => {
var _a, _b;
this._openRequests++;
let cleanedListeners = false;
const maxResponseSize = (_a = options.maxResponseSize) !== null && _a !== void 0 ? _a : MAX_STRING_LENGTH;
const maxCompressedResponseSize = (_b = options.maxCompressedResponseSize) !== null && _b !== void 0 ? _b : MAX_BUFFER_LENGTH;
const requestParams = this.buildRequestObject(params);

@@ -114,9 +117,9 @@ // https://github.com/nodejs/node/commit/b961d9fd83

const contentLength = Number(response.headers['content-length']);
if (isCompressed && contentLength > MAX_BUFFER_LENGTH) {
if (isCompressed && contentLength > maxCompressedResponseSize) {
response.destroy();
return reject(new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed buffer (${MAX_BUFFER_LENGTH})`));
return reject(new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed buffer (${maxCompressedResponseSize})`));
}
else if (contentLength > MAX_STRING_LENGTH) {
else if (contentLength > maxResponseSize) {
response.destroy();
return reject(new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed string (${MAX_STRING_LENGTH})`));
return reject(new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed string (${maxResponseSize})`));
}

@@ -165,5 +168,11 @@ }

const onError = (err) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
cleanListeners();
this._openRequests--;
reject(new errors_1.ConnectionError(err.message));
let message = err.message;
// @ts-expect-error
if (err.code === 'ECONNRESET') {
message += ` - Local: ${(_b = (_a = request.socket) === null || _a === void 0 ? void 0 : _a.localAddress) !== null && _b !== void 0 ? _b : 'unknown'}:${(_d = (_c = request.socket) === null || _c === void 0 ? void 0 : _c.localPort) !== null && _d !== void 0 ? _d : 'unknown'}, Remote: ${(_f = (_e = request.socket) === null || _e === void 0 ? void 0 : _e.remoteAddress) !== null && _f !== void 0 ? _f : 'unknown'}:${(_h = (_g = request.socket) === null || _g === void 0 ? void 0 : _g.remotePort) !== null && _h !== void 0 ? _h : 'unknown'}`;
}
reject(new errors_1.ConnectionError(message));
};

@@ -181,3 +190,3 @@ const onAbort = () => {

socket.once('secureConnect', () => {
const issuerCertificate = BaseConnection_1.getIssuerCertificate(socket);
const issuerCertificate = (0, BaseConnection_1.getIssuerCertificate)(socket);
/* istanbul ignore next */

@@ -210,3 +219,3 @@ if (issuerCertificate == null) {

if (isStream(params.body)) {
stream_1.pipeline(params.body, request, err => {
(0, stream_1.pipeline)(params.body, request, err => {
/* istanbul ignore if */

@@ -213,0 +222,0 @@ if (err != null && !cleanedListeners) {

@@ -23,8 +23,8 @@ "use strict";

const tslib_1 = require("tslib");
const BaseConnection_1 = tslib_1.__importDefault(require("./BaseConnection"));
const BaseConnection_1 = (0, tslib_1.__importDefault)(require("./BaseConnection"));
exports.BaseConnection = BaseConnection_1.default;
const HttpConnection_1 = tslib_1.__importDefault(require("./HttpConnection"));
const HttpConnection_1 = (0, tslib_1.__importDefault)(require("./HttpConnection"));
exports.HttpConnection = HttpConnection_1.default;
const UndiciConnection_1 = tslib_1.__importDefault(require("./UndiciConnection"));
const UndiciConnection_1 = (0, tslib_1.__importDefault)(require("./UndiciConnection"));
exports.UndiciConnection = UndiciConnection_1.default;
//# sourceMappingURL=index.js.map

@@ -24,9 +24,9 @@ "use strict";

const events_1 = require("events");
const debug_1 = tslib_1.__importDefault(require("debug"));
const buffer_1 = tslib_1.__importDefault(require("buffer"));
const BaseConnection_1 = tslib_1.__importStar(require("./BaseConnection"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const buffer_1 = (0, tslib_1.__importDefault)(require("buffer"));
const BaseConnection_1 = (0, tslib_1.__importStar)(require("./BaseConnection"));
const undici_1 = require("undici");
const errors_1 = require("../errors");
const symbols_1 = require("../symbols");
const debug = debug_1.default('elasticsearch');
const debug = (0, debug_1.default)('elasticsearch');
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;

@@ -74,3 +74,3 @@ const MAX_BUFFER_LENGTH = buffer_1.default.constants.MAX_LENGTH;

const caFingerprint = this[symbols_1.kCaFingerprint];
const connector = undici_1.buildConnector(((_b = this.ssl) !== null && _b !== void 0 ? _b : {}));
const connector = (0, undici_1.buildConnector)(((_b = this.ssl) !== null && _b !== void 0 ? _b : {}));
undiciOptions.connect = function (opts, cb) {

@@ -82,3 +82,3 @@ connector(opts, (err, socket) => {

if (caFingerprint !== null && isTlsSocket(opts, socket)) {
const issuerCertificate = BaseConnection_1.getIssuerCertificate(socket);
const issuerCertificate = (0, BaseConnection_1.getIssuerCertificate)(socket);
/* istanbul ignore next */

@@ -106,3 +106,5 @@ if (issuerCertificate == null) {

async request(params, options) {
var _b, _c, _d, _e;
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
const maxResponseSize = (_b = options.maxResponseSize) !== null && _b !== void 0 ? _b : MAX_STRING_LENGTH;
const maxCompressedResponseSize = (_c = options.maxCompressedResponseSize) !== null && _c !== void 0 ? _c : MAX_BUFFER_LENGTH;
const requestParams = {

@@ -113,3 +115,3 @@ method: params.method,

body: params.body,
signal: (_c = (_b = params.abortController) === null || _b === void 0 ? void 0 : _b.signal) !== null && _c !== void 0 ? _c : this[symbols_1.kEmitter]
signal: (_e = (_d = params.abortController) === null || _d === void 0 ? void 0 : _d.signal) !== null && _e !== void 0 ? _e : this[symbols_1.kEmitter]
};

@@ -142,2 +144,3 @@ // undici does not support per-request timeouts,

try {
// @ts-expect-error method it's fine as string
response = await this.pool.request(requestParams);

@@ -155,2 +158,4 @@ if (timeoutId != null)

throw new errors_1.TimeoutError('Request timed out');
case 'UND_ERR_SOCKET':
throw new errors_1.ConnectionError(`${err.message} - Local: ${(_g = (_f = err.socket) === null || _f === void 0 ? void 0 : _f.localAddress) !== null && _g !== void 0 ? _g : 'unknown'}:${(_j = (_h = err.socket) === null || _h === void 0 ? void 0 : _h.localPort) !== null && _j !== void 0 ? _j : 'unknown'}, Remote: ${(_l = (_k = err.socket) === null || _k === void 0 ? void 0 : _k.remoteAddress) !== null && _l !== void 0 ? _l : 'unknown'}:${(_o = (_m = err.socket) === null || _m === void 0 ? void 0 : _m.remotePort) !== null && _o !== void 0 ? _o : 'unknown'}`); // eslint-disable-line
default:

@@ -160,15 +165,15 @@ throw new errors_1.ConnectionError(err.message);

}
const contentEncoding = ((_d = response.headers['content-encoding']) !== null && _d !== void 0 ? _d : '').toLowerCase();
const contentEncoding = ((_p = response.headers['content-encoding']) !== null && _p !== void 0 ? _p : '').toLowerCase();
const isCompressed = contentEncoding.includes('gzip') || contentEncoding.includes('deflate');
const isVectorTile = ((_e = response.headers['content-type']) !== null && _e !== void 0 ? _e : '').includes('application/vnd.mapbox-vector-tile');
const isVectorTile = ((_q = response.headers['content-type']) !== null && _q !== void 0 ? _q : '').includes('application/vnd.mapbox-vector-tile');
/* istanbul ignore else */
if (response.headers['content-length'] !== undefined) {
const contentLength = Number(response.headers['content-length']);
if (isCompressed && contentLength > MAX_BUFFER_LENGTH) {
if (isCompressed && contentLength > maxCompressedResponseSize) {
response.body.destroy();
throw new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed buffer (${MAX_BUFFER_LENGTH})`);
throw new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed buffer (${maxCompressedResponseSize})`);
}
else if (contentLength > MAX_STRING_LENGTH) {
else if (contentLength > maxResponseSize) {
response.body.destroy();
throw new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed string (${MAX_STRING_LENGTH})`);
throw new errors_1.RequestAbortedError(`The content length (${contentLength}) is bigger than the maximum allowed string (${maxResponseSize})`);
}

@@ -175,0 +180,0 @@ }

@@ -24,8 +24,8 @@ "use strict";

const url_1 = require("url");
const debug_1 = tslib_1.__importDefault(require("debug"));
const Diagnostic_1 = tslib_1.__importDefault(require("../Diagnostic"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const Diagnostic_1 = (0, tslib_1.__importDefault)(require("../Diagnostic"));
const symbols_1 = require("../symbols");
const connection_1 = require("../connection");
const errors_1 = require("../errors");
const debug = debug_1.default('elasticsearch');
const debug = (0, debug_1.default)('elasticsearch');
class BaseConnectionPool {

@@ -32,0 +32,0 @@ constructor(opts) {

@@ -22,3 +22,3 @@ "use strict";

const tslib_1 = require("tslib");
const BaseConnectionPool_1 = tslib_1.__importDefault(require("./BaseConnectionPool"));
const BaseConnectionPool_1 = (0, tslib_1.__importDefault)(require("./BaseConnectionPool"));
class CloudConnectionPool extends BaseConnectionPool_1.default {

@@ -25,0 +25,0 @@ constructor(opts) {

@@ -22,7 +22,7 @@ "use strict";

const tslib_1 = require("tslib");
const BaseConnectionPool_1 = tslib_1.__importDefault(require("./BaseConnectionPool"));
const assert_1 = tslib_1.__importDefault(require("assert"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const BaseConnectionPool_1 = (0, tslib_1.__importDefault)(require("./BaseConnectionPool"));
const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const connection_1 = require("../connection");
const debug = debug_1.default('elasticsearch');
const debug = (0, debug_1.default)('elasticsearch');
class ClusterConnectionPool extends BaseConnectionPool_1.default {

@@ -71,3 +71,3 @@ constructor(opts) {

this.resurrectStrategy = ClusterConnectionPool.resurrectStrategies[resurrectStrategy];
assert_1.default(this.resurrectStrategy != null, `Invalid resurrection strategy: '${resurrectStrategy}'`);
(0, assert_1.default)(this.resurrectStrategy != null, `Invalid resurrection strategy: '${resurrectStrategy}'`);
}

@@ -74,0 +74,0 @@ /**

@@ -23,10 +23,10 @@ "use strict";

const tslib_1 = require("tslib");
const BaseConnectionPool_1 = tslib_1.__importDefault(require("./BaseConnectionPool"));
const BaseConnectionPool_1 = (0, tslib_1.__importDefault)(require("./BaseConnectionPool"));
exports.BaseConnectionPool = BaseConnectionPool_1.default;
const WeightedConnectionPool_1 = tslib_1.__importDefault(require("./WeightedConnectionPool"));
const WeightedConnectionPool_1 = (0, tslib_1.__importDefault)(require("./WeightedConnectionPool"));
exports.WeightedConnectionPool = WeightedConnectionPool_1.default;
const ClusterConnectionPool_1 = tslib_1.__importDefault(require("./ClusterConnectionPool"));
const ClusterConnectionPool_1 = (0, tslib_1.__importDefault)(require("./ClusterConnectionPool"));
exports.ClusterConnectionPool = ClusterConnectionPool_1.default;
const CloudConnectionPool_1 = tslib_1.__importDefault(require("./CloudConnectionPool"));
const CloudConnectionPool_1 = (0, tslib_1.__importDefault)(require("./CloudConnectionPool"));
exports.CloudConnectionPool = CloudConnectionPool_1.default;
//# sourceMappingURL=index.js.map

@@ -23,3 +23,3 @@ "use strict";

const connection_1 = require("../connection");
const BaseConnectionPool_1 = tslib_1.__importDefault(require("./BaseConnectionPool"));
const BaseConnectionPool_1 = (0, tslib_1.__importDefault)(require("./BaseConnectionPool"));
const noFilter = () => true;

@@ -26,0 +26,0 @@ class WeightedConnectionPool extends BaseConnectionPool_1.default {

@@ -24,7 +24,7 @@ "use strict";

const querystring_1 = require("querystring");
const debug_1 = tslib_1.__importDefault(require("debug"));
const secure_json_parse_1 = tslib_1.__importDefault(require("secure-json-parse"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const secure_json_parse_1 = (0, tslib_1.__importDefault)(require("secure-json-parse"));
const errors_1 = require("./errors");
const symbols_1 = require("./symbols");
const debug = debug_1.default('elasticsearch');
const debug = (0, debug_1.default)('elasticsearch');
class Serializer {

@@ -103,3 +103,3 @@ constructor(opts = {}) {

}
return querystring_1.stringify(object);
return (0, querystring_1.stringify)(object);
}

@@ -106,0 +106,0 @@ }

@@ -25,1 +25,3 @@ export declare const kSniffEnabled: unique symbol;

export declare const kCaFingerprint: unique symbol;
export declare const kMaxResponseSize: unique symbol;
export declare const kMaxCompressedResponseSize: unique symbol;

@@ -21,3 +21,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
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.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');

@@ -47,2 +47,4 @@ exports.kNextSniff = Symbol('next sniff');

exports.kCaFingerprint = Symbol('ca fingerprint');
exports.kMaxResponseSize = Symbol('max response size');
exports.kMaxCompressedResponseSize = Symbol('max compressed response size');
//# sourceMappingURL=symbols.js.map

@@ -7,8 +7,8 @@ /// <reference types="node" />

import AbortController from 'node-abort-controller';
import { ClusterConnectionPool, CloudConnectionPool, WeightedConnectionPool, BaseConnectionPool } from './pool';
import { BaseConnectionPool } from './pool';
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 } 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 } from './symbols';
export interface TransportOptions {
diagnostic?: Diagnostic;
connectionPool: ClusterConnectionPool | CloudConnectionPool | WeightedConnectionPool;
connectionPool: BaseConnectionPool;
serializer?: Serializer;

@@ -30,2 +30,4 @@ maxRetries?: number;

productCheck?: string;
maxResponseSize?: number;
maxCompressedResponseSize?: number;
}

@@ -52,2 +54,4 @@ export interface TransportRequestParams {

abortController?: AbortController;
maxResponseSize?: number;
maxCompressedResponseSize?: number;
/**

@@ -95,3 +99,3 @@ * Warning: If you set meta to true the result will no longer be

[kDiagnostic]: Diagnostic;
[kConnectionPool]: ClusterConnectionPool | CloudConnectionPool | WeightedConnectionPool;
[kConnectionPool]: BaseConnectionPool;
[kSerializer]: Serializer;

@@ -112,2 +116,4 @@ [kContext]: Context;

[kProductCheck]: string | null;
[kMaxResponseSize]: number;
[kMaxCompressedResponseSize]: number;
static sniffReasons: {

@@ -114,0 +120,0 @@ SNIFF_ON_START: string;

@@ -20,19 +20,20 @@ "use strict";

*/
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
Object.defineProperty(exports, "__esModule", { value: true });
exports.lowerCaseHeaders = exports.generateRequestId = void 0;
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const os_1 = tslib_1.__importDefault(require("os"));
const zlib_1 = tslib_1.__importDefault(require("zlib"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const os_1 = (0, tslib_1.__importDefault)(require("os"));
const zlib_1 = (0, tslib_1.__importDefault)(require("zlib"));
const buffer_1 = (0, tslib_1.__importDefault)(require("buffer"));
const util_1 = require("util");
const ms_1 = tslib_1.__importDefault(require("ms"));
const ms_1 = (0, tslib_1.__importDefault)(require("ms"));
const errors_1 = require("./errors");
const Diagnostic_1 = tslib_1.__importDefault(require("./Diagnostic"));
const Serializer_1 = tslib_1.__importDefault(require("./Serializer"));
const Diagnostic_1 = (0, tslib_1.__importDefault)(require("./Diagnostic"));
const Serializer_1 = (0, tslib_1.__importDefault)(require("./Serializer"));
const symbols_1 = require("./symbols");
const { version: clientVersion } = require('../package.json'); // eslint-disable-line
const debug = debug_1.default('elasticsearch');
const gzip = util_1.promisify(zlib_1.default.gzip);
const unzip = util_1.promisify(zlib_1.default.unzip);
const debug = (0, debug_1.default)('elasticsearch');
const gzip = (0, util_1.promisify)(zlib_1.default.gzip);
const unzip = (0, util_1.promisify)(zlib_1.default.unzip);
const { createGzip } = zlib_1.default;

@@ -42,3 +43,3 @@ const userAgent = `elastic-transport-js/${clientVersion} (${os_1.default.platform()} ${os_1.default.release()}-${os_1.default.arch()}; Node.js ${process.version})`; // eslint-disable-line

constructor(opts) {
var _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
var _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
Object.defineProperty(this, _a, {

@@ -164,2 +165,14 @@ enumerable: true,

});
Object.defineProperty(this, _w, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, _x, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
if (opts.connectionPool == null) {

@@ -175,22 +188,30 @@ throw new errors_1.ConfigurationError('The Connection Pool option is not defined');

}
this[symbols_1.kNodeFilter] = (_w = opts.nodeFilter) !== null && _w !== void 0 ? _w : defaultNodeFilter;
this[symbols_1.kNodeSelector] = (_x = opts.nodeSelector) !== null && _x !== void 0 ? _x : roundRobinSelector();
if (opts.maxResponseSize != null && opts.maxResponseSize > buffer_1.default.constants.MAX_STRING_LENGTH) {
throw new errors_1.ConfigurationError(`The maxResponseSize cannot be bigger than ${buffer_1.default.constants.MAX_STRING_LENGTH}`);
}
if (opts.maxCompressedResponseSize != null && opts.maxCompressedResponseSize > buffer_1.default.constants.MAX_LENGTH) {
throw new errors_1.ConfigurationError(`The maxCompressedResponseSize cannot be bigger than ${buffer_1.default.constants.MAX_LENGTH}`);
}
this[symbols_1.kNodeFilter] = (_y = opts.nodeFilter) !== null && _y !== void 0 ? _y : defaultNodeFilter;
this[symbols_1.kNodeSelector] = (_z = opts.nodeSelector) !== null && _z !== void 0 ? _z : roundRobinSelector();
this[symbols_1.kHeaders] = Object.assign({}, { 'user-agent': userAgent, accept: 'application/vnd.elasticsearch+json; compatible-with=8' }, opts.compression === true ? { 'accept-encoding': 'gzip,deflate' } : null, lowerCaseHeaders(opts.headers));
this[symbols_1.kDiagnostic] = (_y = opts.diagnostic) !== null && _y !== void 0 ? _y : new Diagnostic_1.default();
this[symbols_1.kDiagnostic] = (_0 = opts.diagnostic) !== null && _0 !== void 0 ? _0 : new Diagnostic_1.default();
this[symbols_1.kConnectionPool] = opts.connectionPool;
this[symbols_1.kSerializer] = (_z = opts.serializer) !== null && _z !== void 0 ? _z : new Serializer_1.default();
this[symbols_1.kContext] = (_0 = opts.context) !== null && _0 !== void 0 ? _0 : null;
this[symbols_1.kGenerateRequestId] = (_1 = opts.generateRequestId) !== null && _1 !== void 0 ? _1 : generateRequestId();
this[symbols_1.kOpaqueIdPrefix] = (_2 = opts.opaqueIdPrefix) !== null && _2 !== void 0 ? _2 : null;
this[symbols_1.kName] = (_3 = opts.name) !== null && _3 !== void 0 ? _3 : 'elastic-transport-js';
this[symbols_1.kSerializer] = (_1 = opts.serializer) !== null && _1 !== void 0 ? _1 : new Serializer_1.default();
this[symbols_1.kContext] = (_2 = opts.context) !== null && _2 !== void 0 ? _2 : null;
this[symbols_1.kGenerateRequestId] = (_3 = opts.generateRequestId) !== null && _3 !== void 0 ? _3 : generateRequestId();
this[symbols_1.kOpaqueIdPrefix] = (_4 = opts.opaqueIdPrefix) !== null && _4 !== void 0 ? _4 : null;
this[symbols_1.kName] = (_5 = opts.name) !== null && _5 !== void 0 ? _5 : '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] = (_4 = opts.sniffInterval) !== null && _4 !== void 0 ? _4 : false;
this[symbols_1.kSniffInterval] = (_6 = opts.sniffInterval) !== null && _6 !== void 0 ? _6 : 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] = (_5 = opts.sniffOnConnectionFault) !== null && _5 !== void 0 ? _5 : false;
this[symbols_1.kSniffEndpoint] = (_6 = opts.sniffEndpoint) !== null && _6 !== void 0 ? _6 : null;
this[symbols_1.kProductCheck] = (_7 = opts.productCheck) !== null && _7 !== void 0 ? _7 : null;
this[symbols_1.kSniffOnConnectionFault] = (_7 = opts.sniffOnConnectionFault) !== null && _7 !== void 0 ? _7 : false;
this[symbols_1.kSniffEndpoint] = (_8 = opts.sniffEndpoint) !== null && _8 !== void 0 ? _8 : null;
this[symbols_1.kProductCheck] = (_9 = opts.productCheck) !== null && _9 !== void 0 ? _9 : null;
this[symbols_1.kMaxResponseSize] = (_10 = opts.maxResponseSize) !== null && _10 !== void 0 ? _10 : buffer_1.default.constants.MAX_STRING_LENGTH;
this[symbols_1.kMaxCompressedResponseSize] = (_11 = opts.maxCompressedResponseSize) !== null && _11 !== void 0 ? _11 : buffer_1.default.constants.MAX_LENGTH;
if (opts.sniffOnStart === true) {

@@ -229,3 +250,3 @@ this.sniff({

async request(params, options = {}) {
var _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
var _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
const meta = {

@@ -236,3 +257,3 @@ context: null,

options: options,
id: (_w = options.id) !== null && _w !== void 0 ? _w : this[symbols_1.kGenerateRequestId](params, options)
id: (_y = options.id) !== null && _y !== void 0 ? _y : this[symbols_1.kGenerateRequestId](params, options)
},

@@ -244,3 +265,3 @@ name: this[symbols_1.kName],

};
const returnMeta = (_x = options.meta) !== null && _x !== void 0 ? _x : false;
const returnMeta = (_z = options.meta) !== null && _z !== void 0 ? _z : false;
if (this[symbols_1.kContext] != null && options.context != null) {

@@ -263,4 +284,4 @@ meta.context = Object.assign({}, this[symbols_1.kContext], options.context);

get warnings() {
var _w;
return ((_w = this.headers) === null || _w === void 0 ? void 0 : _w.warning) != null
var _y;
return ((_y = this.headers) === null || _y === void 0 ? void 0 : _y.warning) != null
? this.headers.warning.split(/(?!\B"[^"]*),(?![^"]*"\B)/)

@@ -278,5 +299,7 @@ : null;

// Furthermore, copying everytime the stream is very a expensive operation.
const maxRetries = isStream((_y = params.body) !== null && _y !== void 0 ? _y : params.bulkBody) ? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this[symbols_1.kMaxRetries]);
const maxRetries = isStream((_0 = params.body) !== null && _0 !== void 0 ? _0 : 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 abortController = (_z = options.abortController) !== null && _z !== void 0 ? _z : null;
const abortController = (_1 = options.abortController) !== null && _1 !== void 0 ? _1 : null;
const maxResponseSize = (_2 = options.maxResponseSize) !== null && _2 !== void 0 ? _2 : this[symbols_1.kMaxResponseSize];
const maxCompressedResponseSize = (_3 = options.maxCompressedResponseSize) !== null && _3 !== void 0 ? _3 : this[symbols_1.kMaxCompressedResponseSize];
this[symbols_1.kDiagnostic].emit('serialization', null, result);

@@ -304,3 +327,3 @@ const headers = Object.assign({}, this[symbols_1.kHeaders], lowerCaseHeaders(options.headers));

if (params.body !== '') {
headers['content-type'] = (_0 = headers['content-type']) !== null && _0 !== void 0 ? _0 : 'application/vnd.elasticsearch+json; compatible-with=8';
headers['content-type'] = (_4 = headers['content-type']) !== null && _4 !== void 0 ? _4 : 'application/vnd.elasticsearch+json; compatible-with=8';
}

@@ -323,3 +346,3 @@ // handle ndjson body

if (connectionParams.body !== '') {
headers['content-type'] = (_1 = headers['content-type']) !== null && _1 !== void 0 ? _1 : 'application/vnd.elasticsearch+x-ndjson; compatible-with=8';
headers['content-type'] = (_5 = headers['content-type']) !== null && _5 !== void 0 ? _5 : 'application/vnd.elasticsearch+x-ndjson; compatible-with=8';
}

@@ -383,14 +406,16 @@ }

name: this[symbols_1.kName],
context: meta.context
context: meta.context,
maxResponseSize,
maxCompressedResponseSize
});
result.statusCode = statusCode;
result.headers = headers;
if (this[symbols_1.kProductCheck] != null && headers['x-elastic-product'] !== this[symbols_1.kProductCheck]) {
if (this[symbols_1.kProductCheck] != null && headers['x-elastic-product'] !== this[symbols_1.kProductCheck] && statusCode !== 401 && statusCode !== 403) {
throw new errors_1.ProductNotSupportedError(this[symbols_1.kProductCheck], result);
}
const contentEncoding = ((_2 = headers['content-encoding']) !== null && _2 !== void 0 ? _2 : '').toLowerCase();
const contentEncoding = ((_6 = headers['content-encoding']) !== null && _6 !== void 0 ? _6 : '').toLowerCase();
if (contentEncoding.includes('gzip') || contentEncoding.includes('deflate')) {
body = await unzip(body);
}
const isVectorTile = ((_3 = headers['content-type']) !== null && _3 !== void 0 ? _3 : '').includes('application/vnd.mapbox-vector-tile');
const isVectorTile = ((_7 = headers['content-type']) !== null && _7 !== void 0 ? _7 : '').includes('application/vnd.mapbox-vector-tile');
if (Buffer.isBuffer(body) && !isVectorTile) {

@@ -411,4 +436,4 @@ body = body.toString();

if (headers['content-type'] !== undefined &&
(((_4 = headers['content-type']) === null || _4 === void 0 ? void 0 : _4.includes('application/json')) ||
((_5 = headers['content-type']) === null || _5 === void 0 ? void 0 : _5.includes('application/vnd.elasticsearch+json'))) &&
(((_8 = headers['content-type']) === null || _8 === void 0 ? void 0 : _8.includes('application/json')) ||
((_9 = headers['content-type']) === null || _9 === void 0 ? void 0 : _9.includes('application/vnd.elasticsearch+json'))) &&
!isHead && body !== '') { // eslint-disable-line

@@ -527,3 +552,3 @@ result.body = this[symbols_1.kSerializer].deserialize(body);

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;
_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;
Object.defineProperty(Transport, "sniffReasons", {

@@ -542,3 +567,3 @@ enumerable: true,

if (typeof time === 'string') {
return ms_1.default(time);
return (0, ms_1.default)(time);
}

@@ -545,0 +570,0 @@ return time;

{
"name": "@elastic/transport",
"version": "0.0.3",
"version": "0.0.4",
"description": "Transport classes and utilities shared among Node.js Elastic client libraries",

@@ -66,3 +66,3 @@ "main": "index.js",

"tslib": "^2.3.0",
"undici": "^4.3.1"
"undici": "^4.7.0"
},

@@ -69,0 +69,0 @@ "tap": {

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc