Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@elastic/transport

Package Overview
Dependencies
Maintainers
77
Versions
39
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.6 to 0.0.7

7

lib/connection/BaseConnection.d.ts

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

import { Readable as ReadableStream } from 'stream';
import AbortController from 'node-abort-controller';
import Diagnostic from '../Diagnostic';

@@ -29,7 +28,4 @@ import { ApiKeyAuth, BasicAuth, BearerAuth, HttpAgentOptions, UndiciAgentOptions, agentFn } from '../types';

headers?: http.IncomingHttpHeaders;
asStream?: boolean;
body?: string | Buffer | ReadableStream | null;
querystring?: string;
abortController?: AbortController;
timeout?: number;
}

@@ -42,2 +38,5 @@ export interface ConnectionRequestOptions {

maxCompressedResponseSize?: number;
asStream?: boolean;
signal?: AbortSignal;
timeout?: number;
}

@@ -44,0 +43,0 @@ export interface ConnectionRequestResponse {

@@ -12,3 +12,3 @@ /// <reference types="node" />

close(): Promise<void>;
buildRequestObject(params: ConnectionRequestParams): http.ClientRequestArgs;
buildRequestObject(params: ConnectionRequestParams, options: ConnectionRequestOptions): http.ClientRequestArgs;
}

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

const maxCompressedResponseSize = (_b = options.maxCompressedResponseSize) !== null && _b !== void 0 ? _b : MAX_BUFFER_LENGTH;
const requestParams = this.buildRequestObject(params);
const requestParams = this.buildRequestObject(params, options);
// https://github.com/nodejs/node/commit/b961d9fd83

@@ -103,4 +103,5 @@ if (INVALID_PATH_REGEX.test(requestParams.path)) {

const request = this.makeRequest(requestParams);
if (params.abortController != null) {
params.abortController.signal.addEventListener('abort', () => request.abort(), { once: true });
if (options.signal != null) {
// @ts-expect-error
options.signal.addEventListener('abort', () => request.abort(), { once: true });
}

@@ -249,3 +250,4 @@ const onResponse = (response) => {

}
buildRequestObject(params) {
buildRequestObject(params, options) {
var _a;
const url = this.url;

@@ -267,3 +269,3 @@ const request = {

agent: this.agent,
timeout: this.timeout
timeout: (_a = options.timeout) !== null && _a !== void 0 ? _a : this.timeout
};

@@ -270,0 +272,0 @@ const paramsKeys = Object.keys(params);

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

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

@@ -112,3 +112,3 @@ const maxCompressedResponseSize = (_c = options.maxCompressedResponseSize) !== null && _c !== void 0 ? _c : MAX_BUFFER_LENGTH;

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

@@ -122,8 +122,8 @@ // undici does not support per-request timeouts,

let timeoutId;
if (params.timeout != null && params.timeout !== this.timeout) {
if (options.timeout != null && options.timeout !== this.timeout) {
timeoutId = setTimeout(() => {
var _b;
timedout = true;
if (((_b = params.abortController) === null || _b === void 0 ? void 0 : _b.signal) != null) {
params.abortController.abort();
if (options.signal != null) {
// @ts-expect-error
options.signal.dispatchEvent('abort');
}

@@ -133,3 +133,3 @@ else {

}
}, params.timeout);
}, options.timeout);
}

@@ -157,3 +157,3 @@ // https://github.com/nodejs/node/commit/b961d9fd83

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
throw new errors_1.ConnectionError(`${err.message} - Local: ${(_f = (_e = err.socket) === null || _e === void 0 ? void 0 : _e.localAddress) !== null && _f !== void 0 ? _f : 'unknown'}:${(_h = (_g = err.socket) === null || _g === void 0 ? void 0 : _g.localPort) !== null && _h !== void 0 ? _h : 'unknown'}, Remote: ${(_k = (_j = err.socket) === null || _j === void 0 ? void 0 : _j.remoteAddress) !== null && _k !== void 0 ? _k : 'unknown'}:${(_m = (_l = err.socket) === null || _l === void 0 ? void 0 : _l.remotePort) !== null && _m !== void 0 ? _m : 'unknown'}`); // eslint-disable-line
default:

@@ -163,5 +163,5 @@ throw new errors_1.ConnectionError(err.message);

}
const contentEncoding = ((_p = response.headers['content-encoding']) !== null && _p !== void 0 ? _p : '').toLowerCase();
const contentEncoding = ((_o = response.headers['content-encoding']) !== null && _o !== void 0 ? _o : '').toLowerCase();
const isCompressed = contentEncoding.includes('gzip') || contentEncoding.includes('deflate');
const isVectorTile = ((_q = response.headers['content-type']) !== null && _q !== void 0 ? _q : '').includes('application/vnd.mapbox-vector-tile');
const isVectorTile = ((_p = response.headers['content-type']) !== null && _p !== void 0 ? _p : '').includes('application/vnd.mapbox-vector-tile');
/* istanbul ignore else */

@@ -168,0 +168,0 @@ if (response.headers['content-length'] !== undefined) {

@@ -20,15 +20,15 @@ /// <reference types="node" />

export default class Diagnostic extends EventEmitter {
on(event: events.REQUEST, listener: DiagnosticListenerFull): this;
on(event: events.RESPONSE, listener: DiagnosticListenerFull): this;
on(event: events.SERIALIZATION, listener: DiagnosticListenerFull): this;
on(event: events.SNIFF, listener: DiagnosticListenerFull): this;
on(event: events.DESERIALIZATION, listener: DiagnosticListenerLight): this;
on(event: events.RESURRECT, listener: DiagnosticListenerResurrect): this;
once(event: events.REQUEST, listener: DiagnosticListenerFull): this;
once(event: events.RESPONSE, listener: DiagnosticListenerFull): this;
once(event: events.SERIALIZATION, listener: DiagnosticListenerFull): this;
once(event: events.SNIFF, listener: DiagnosticListenerFull): this;
once(event: events.DESERIALIZATION, listener: DiagnosticListenerLight): this;
once(event: events.RESURRECT, listener: DiagnosticListenerResurrect): this;
on(event: 'request', listener: DiagnosticListenerFull): this;
on(event: 'response', listener: DiagnosticListenerFull): this;
on(event: 'serialization', listener: DiagnosticListenerFull): this;
on(event: 'sniff', listener: DiagnosticListenerFull): this;
on(event: 'deserialization', listener: DiagnosticListenerLight): this;
on(event: 'resurrect', listener: DiagnosticListenerResurrect): this;
once(event: 'request', listener: DiagnosticListenerFull): this;
once(event: 'response', listener: DiagnosticListenerFull): this;
once(event: 'serialization', listener: DiagnosticListenerFull): this;
once(event: 'sniff', listener: DiagnosticListenerFull): this;
once(event: 'deserialization', listener: DiagnosticListenerLight): this;
once(event: 'resurrect', listener: DiagnosticListenerResurrect): this;
off(event: string, listener: DiagnosticListener): this;
}

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

if (this.resurrectStrategy === 1) {
connection.request({ method: 'HEAD', path: '/', timeout: this.pingTimeout }, { requestId: opts.requestId, name: opts.name, context: opts.context })
connection.request({ method: 'HEAD', path: '/' }, { timeout: this.pingTimeout, requestId: opts.requestId, name: opts.name, context: opts.context })
.then(({ statusCode }) => {

@@ -151,0 +151,0 @@ let isAlive = true;

@@ -6,3 +6,2 @@ /// <reference types="node" />

import Serializer from './Serializer';
import AbortController from 'node-abort-controller';
import { BaseConnectionPool } from './pool';

@@ -52,3 +51,3 @@ import { nodeFilterFn, nodeSelectorFn, generateRequestIdFn, RequestBody, RequestNDBody, TransportResult, Context } from './types';

opaqueId?: string;
abortController?: AbortController;
signal?: AbortSignal;
maxResponseSize?: number;

@@ -55,0 +54,0 @@ maxCompressedResponseSize?: number;

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

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

@@ -294,5 +294,5 @@ context: null,

const compression = typeof options.compression === 'boolean' ? options.compression : this[symbols_1.kCompression];
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];
const signal = options.signal;
const maxResponseSize = (_1 = options.maxResponseSize) !== null && _1 !== void 0 ? _1 : this[symbols_1.kMaxResponseSize];
const maxCompressedResponseSize = (_2 = options.maxCompressedResponseSize) !== null && _2 !== void 0 ? _2 : this[symbols_1.kMaxCompressedResponseSize];
this[symbols_1.kDiagnostic].emit('serialization', null, result);

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

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

@@ -340,3 +340,3 @@ }

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

@@ -353,4 +353,2 @@ }

}
// handles request timeout
connectionParams.timeout = toMs(options.requestTimeout != null ? options.requestTimeout : this[symbols_1.kRequestTimeout]);
// TODO: fixme

@@ -387,3 +385,3 @@ // if (options.asStream === true) params.asStream = true

try {
if (abortController === null || abortController === void 0 ? void 0 : abortController.signal.aborted) { // eslint-disable-line
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);

@@ -405,3 +403,5 @@ }

maxResponseSize,
maxCompressedResponseSize
maxCompressedResponseSize,
signal,
timeout: toMs(options.requestTimeout != null ? options.requestTimeout : this[symbols_1.kRequestTimeout])
});

@@ -413,7 +413,7 @@ result.statusCode = statusCode;

}
const contentEncoding = ((_6 = headers['content-encoding']) !== null && _6 !== void 0 ? _6 : '').toLowerCase();
const contentEncoding = ((_5 = headers['content-encoding']) !== null && _5 !== void 0 ? _5 : '').toLowerCase();
if (contentEncoding.includes('gzip') || contentEncoding.includes('deflate')) {
body = await unzip(body);
}
const isVectorTile = ((_7 = headers['content-type']) !== null && _7 !== void 0 ? _7 : '').includes('application/vnd.mapbox-vector-tile');
const isVectorTile = ((_6 = headers['content-type']) !== null && _6 !== void 0 ? _6 : '').includes('application/vnd.mapbox-vector-tile');
if (Buffer.isBuffer(body) && !isVectorTile) {

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

if (headers['content-type'] !== undefined &&
(((_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'))) &&
(((_7 = headers['content-type']) === null || _7 === void 0 ? void 0 : _7.includes('application/json')) ||
((_8 = headers['content-type']) === null || _8 === void 0 ? void 0 : _8.includes('application/vnd.elasticsearch+json'))) &&
!isHead && body !== '') { // eslint-disable-line

@@ -438,0 +438,0 @@ result.body = this[symbols_1.kSerializer].deserialize(body);

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

@@ -5,0 +5,0 @@ "main": "index.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

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