Socket
Socket
Sign inDemoInstall

@elastic/transport

Package Overview
Dependencies
Maintainers
68
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 8.2.0 to 8.3.1

6

lib/connection/BaseConnection.d.ts
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { inspect } from 'util';

@@ -3,0 +9,0 @@ import * as http from 'http';

1

lib/connection/HttpConnection.d.ts
/// <reference types="node" />
/// <reference types="node" />
import hpagent from 'hpagent';

@@ -3,0 +4,0 @@ import http from 'http';

@@ -142,5 +142,28 @@ "use strict";

let payload = isCompressed || isVectorTile ? new Array() : '';
const onData = isCompressed || isVectorTile
? (chunk) => { payload.push(chunk); }
: (chunk) => { payload = `${payload}${chunk}`; };
const onData = isCompressed || isVectorTile ? onDataAsBuffer : onDataAsString;
let currentLength = 0;
function onDataAsBuffer(chunk) {
currentLength += Buffer.byteLength(chunk);
if (currentLength > maxCompressedResponseSize) {
// TODO: hacky solution, refactor to avoid using the deprecated aborted event
response.removeListener('aborted', onAbort);
response.destroy();
onEnd(new errors_1.RequestAbortedError(`The content length (${currentLength}) is bigger than the maximum allowed buffer (${maxCompressedResponseSize})`));
}
else {
payload.push(chunk);
}
}
function onDataAsString(chunk) {
currentLength += Buffer.byteLength(chunk);
if (currentLength > maxResponseSize) {
// TODO: hacky solution, refactor to avoid using the deprecated aborted event
response.removeListener('aborted', onAbort);
response.destroy();
onEnd(new errors_1.RequestAbortedError(`The content length (${currentLength}) is bigger than the maximum allowed string (${maxResponseSize})`));
}
else {
payload = `${payload}${chunk}`;
}
}
const onEnd = (err) => {

@@ -152,2 +175,5 @@ response.removeListener('data', onData);

if (err != null) {
if (err.name === 'RequestAbortedError') {
return reject(err);
}
return reject(new errors_1.ConnectionError(err.message));

@@ -154,0 +180,0 @@ }

2

lib/connection/index.d.ts
import BaseConnection from './BaseConnection';
import HttpConnection from './HttpConnection';
import UndiciConnection from './UndiciConnection';
export declare type Connection = BaseConnection | HttpConnection | UndiciConnection;
export type Connection = BaseConnection | HttpConnection | UndiciConnection;
export type { ConnectionOptions, ConnectionRequestParams, ConnectionRequestOptions, ConnectionRequestOptionsAsStream, ConnectionRequestResponse, ConnectionRequestResponseAsStream } from './BaseConnection';
export { BaseConnection, HttpConnection, UndiciConnection };

@@ -186,13 +186,34 @@ "use strict";

if (isCompressed || isVectorTile) { // eslint-disable-line
let currentLength = 0;
const payload = [];
for await (const chunk of response.body) {
currentLength += Buffer.byteLength(chunk);
if (currentLength > maxCompressedResponseSize) {
response.body.destroy();
throw new errors_1.RequestAbortedError(`The content length (${currentLength}) is bigger than the maximum allowed buffer (${maxCompressedResponseSize})`);
}
payload.push(chunk);
}
return {
statusCode: response.statusCode,
headers: response.headers,
body: Buffer.from(await response.body.arrayBuffer())
body: Buffer.concat(payload)
};
}
else {
let payload = '';
let currentLength = 0;
response.body.setEncoding('utf8');
for await (const chunk of response.body) {
currentLength += Buffer.byteLength(chunk);
if (currentLength > maxResponseSize) {
response.body.destroy();
throw new errors_1.RequestAbortedError(`The content length (${currentLength}) is bigger than the maximum allowed string (${maxResponseSize})`);
}
payload += chunk;
}
return {
statusCode: response.statusCode,
headers: response.headers,
body: await response.body.text()
body: payload
};

@@ -202,2 +223,5 @@ }

catch (err) {
if (err.name === 'RequestAbortedError') {
throw err;
}
throw new errors_1.ConnectionError(err.message);

@@ -204,0 +228,0 @@ }

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

import { DiagnosticResult, DiagnosticResultResponse } from './types';
export declare type DiagnosticListener = (err: ElasticsearchClientError | null, meta: any | null) => void;
export declare type DiagnosticListenerFull = (err: ElasticsearchClientError | null, meta: DiagnosticResult | null) => void;
export declare type DiagnosticListenerFullResponse = (err: ElasticsearchClientError | null, meta: DiagnosticResultResponse | null) => void;
export declare type DiagnosticListenerLight = (err: ElasticsearchClientError | null, meta: ConnectionRequestOptions | null) => void;
export declare type DiagnosticListenerResurrect = (err: ElasticsearchClientError | null, meta: ResurrectEvent | null) => void;
export type DiagnosticListener = (err: ElasticsearchClientError | null, meta: any | null) => void;
export type DiagnosticListenerFull = (err: ElasticsearchClientError | null, meta: DiagnosticResult | null) => void;
export type DiagnosticListenerFullResponse = (err: ElasticsearchClientError | null, meta: DiagnosticResultResponse | null) => void;
export type DiagnosticListenerLight = (err: ElasticsearchClientError | null, meta: ConnectionRequestOptions | null) => void;
export type DiagnosticListenerResurrect = (err: ElasticsearchClientError | null, meta: ResurrectEvent | null) => void;
export declare enum events {

@@ -14,0 +14,0 @@ RESPONSE = "response",

@@ -132,8 +132,18 @@ "use strict";

if (isObject(meta.body) && meta.body.error != null && meta.body.error.type != null) {
if (Array.isArray(meta.body.error.root_cause)) {
this.message = meta.body.error.type + ': ';
this.message += meta.body.error.root_cause.map((entry) => `[${entry.type}] Reason: ${entry.reason}`).join('; ');
this.message = meta.body.error.type;
if (isObject(meta.body.error.caused_by)) {
const { type, reason } = meta.body.error.caused_by;
const causedBy = [
'\tCaused by:',
`\t\t${type}: ${reason}`
].join('\n');
this.message += `\n${causedBy}`;
}
else {
this.message = meta.body.error.type;
if (Array.isArray(meta.body.error.root_cause) && meta.body.error.root_cause.length !== 0) {
const formatRootCause = (entry) => `\t\t${entry.type}: ${entry.reason}`;
const rootCauses = [
'\tRoot causes:',
...meta.body.error.root_cause.map(formatRootCause)
].join('\n');
this.message += `\n${rootCauses}`;
}

@@ -140,0 +150,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
import { URL } from 'url';

@@ -8,3 +9,3 @@ import { ConnectionOptions as TlsConnectionOptions } from 'tls';

import { HttpAgentOptions, UndiciAgentOptions, agentFn, ApiKeyAuth, BasicAuth, BearerAuth, nodeFilterFn, nodeSelectorFn } from '../types';
declare type AddConnectionOptions = string | ConnectionOptions;
type AddConnectionOptions = string | ConnectionOptions;
export interface ConnectionPoolOptions {

@@ -11,0 +12,0 @@ tls?: TlsConnectionOptions;

/// <reference types="node" />
/// <reference types="node" />
import * as http from 'http';

@@ -3,0 +4,0 @@ import { Connection } from './connection';

@@ -425,3 +425,6 @@ "use strict";

if (this[symbols_1.kProductCheck] != null && headers['x-elastic-product'] !== this[symbols_1.kProductCheck] && statusCode >= 200 && statusCode < 300) {
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
// @ts-ignore
throw new errors_1.ProductNotSupportedError(this[symbols_1.kProductCheck], result);
/* eslint-enable @typescript-eslint/prefer-ts-expect-error */
}

@@ -428,0 +431,0 @@ if (options.asStream === true) {

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Readable as ReadableStream } from 'stream';

@@ -7,5 +10,5 @@ import { URL } from 'url';

import { TransportRequestParams, TransportRequestOptions } from './Transport';
export declare type Context = Record<string, unknown> | null;
export declare type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream;
export declare type RequestNDBody<T = Array<Record<string, any>>> = T | string | string[] | Buffer | ReadableStream;
export type Context = Record<string, unknown> | null;
export type RequestBody<T = Record<string, any>> = T | string | Buffer | ReadableStream;
export type RequestNDBody<T = Array<Record<string, any>>> = T | string | string[] | Buffer | ReadableStream;
export interface DiagnosticResult<TResponse = unknown, TContext = unknown> {

@@ -33,3 +36,3 @@ body?: TResponse;

}
export declare type DiagnosticResultResponse<TResponse = unknown, TContext = unknown> = Required<DiagnosticResult<TResponse, TContext>>;
export type DiagnosticResultResponse<TResponse = unknown, TContext = unknown> = Required<DiagnosticResult<TResponse, TContext>>;
export interface TransportResult<TResponse = unknown, TContext = unknown> extends DiagnosticResult<TResponse, TContext> {

@@ -70,4 +73,4 @@ body: TResponse;

}
export declare type nodeSelectorFn = (connections: Connection[]) => Connection;
export declare type nodeFilterFn = (connection: Connection) => boolean;
export declare type generateRequestIdFn = (params: TransportRequestParams, options: TransportRequestOptions) => any;
export type nodeSelectorFn = (connections: Connection[]) => Connection;
export type nodeFilterFn = (connection: Connection) => boolean;
export type generateRequestIdFn = (params: TransportRequestParams, options: TransportRequestOptions) => any;
{
"name": "@elastic/transport",
"version": "8.2.0",
"version": "8.3.1",
"description": "Transport classes and utilities shared among Node.js Elastic client libraries",

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

"tslib": "^2.4.0",
"undici": "^5.1.1"
"undici": "^5.5.1"
},

@@ -68,0 +68,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

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