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

@algolia/transporter

Package Overview
Dependencies
Maintainers
58
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/transporter - npm Package Compare versions

Comparing version 4.0.0-beta.4 to 4.0.0-beta.5

20

dist/transporter.cjs.js

@@ -5,7 +5,9 @@ 'use strict';

function createHost(url, accept) {
const ttl = 300 * 1000;
// If an host is down, it will remain down for 5 mins.
const DOWNTIME = 5 * 60 * 1000;
function createHost(options) {
const host = {
url,
accept,
protocol: options.protocol || 'https',
url: options.url,
accept: options.accept,
downDate: 0,

@@ -20,3 +22,3 @@ up: true,

isUp() {
if (!host.up && Date.now() - host.downDate > ttl) {
if (!host.up && Date.now() - host.downDate > DOWNTIME) {
// eslint-disable-next-line functional/immutable-data

@@ -83,2 +85,3 @@ host.up = true;

}
const timeoutAdjuster = timeoutRetries + 1;
const payload = {

@@ -93,3 +96,4 @@ data,

}),
timeout: (timeoutRetries + 1) * (requestOptions.timeout ? requestOptions.timeout : 0),
connectTimeout: timeoutAdjuster * transporter.timeouts.connect,
socketTimeout: timeoutAdjuster * (requestOptions.timeout || 0),
};

@@ -152,3 +156,3 @@ const decisions = {

// eslint-disable-next-line functional/immutable-data
transporter.hosts = values.map(host => createHost(host.url, host.accept));
transporter.hosts = values.map(hostOptions => createHost(hostOptions));
},

@@ -266,3 +270,3 @@ read(request, requestOptions) {

// eslint-disable-next-line functional/no-let
let url = `https://${host.url}/${path}`;
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
if (queryParametersAsString.length) {

@@ -269,0 +273,0 @@ url += `?${queryParametersAsString}`;

15

dist/transporter.d.ts

@@ -22,3 +22,3 @@ import { Cache } from '@algolia/cache-common';

export declare function createHost(url: string, accept: CallType): Host;
export declare function createHost(options: HostOptions): Host;

@@ -46,2 +46,3 @@ export declare function createRetryError(stackTrace: readonly StackFrame[]): RetryError;

up: boolean;
readonly protocol: string;
readonly url: string;

@@ -53,2 +54,8 @@ readonly accept: CallType;

export declare type HostOptions = {
readonly url: string;
readonly accept: CallType;
readonly protocol?: string;
};
export declare type MappedRequestOptions = {

@@ -131,2 +138,3 @@ readonly cacheable: boolean | undefined;

export declare type Timeouts = {
readonly connect: number;
readonly read: number;

@@ -152,6 +160,3 @@ readonly write: number;

readonly addQueryParameters: (queryParameters: QueryParameters) => void;
readonly setHosts: (values: ReadonlyArray<{
readonly url: string;
readonly accept: CallType;
}>) => void;
readonly setHosts: (values: readonly HostOptions[]) => void;
readonly read: <TResponse>(request: Request, requestOptions?: RequestOptions) => Readonly<Promise<TResponse>>;

@@ -158,0 +163,0 @@ readonly write: <TResponse>(request: Request, requestOptions?: RequestOptions) => Readonly<Promise<TResponse>>;

@@ -1,6 +0,8 @@

function createHost(url, accept) {
const ttl = 300 * 1000;
// If an host is down, it will remain down for 5 mins.
const DOWNTIME = 5 * 60 * 1000;
function createHost(options) {
const host = {
url,
accept,
protocol: options.protocol || 'https',
url: options.url,
accept: options.accept,
downDate: 0,

@@ -15,3 +17,3 @@ up: true,

isUp() {
if (!host.up && Date.now() - host.downDate > ttl) {
if (!host.up && Date.now() - host.downDate > DOWNTIME) {
// eslint-disable-next-line functional/immutable-data

@@ -78,2 +80,3 @@ host.up = true;

}
const timeoutAdjuster = timeoutRetries + 1;
const payload = {

@@ -88,3 +91,4 @@ data,

}),
timeout: (timeoutRetries + 1) * (requestOptions.timeout ? requestOptions.timeout : 0),
connectTimeout: timeoutAdjuster * transporter.timeouts.connect,
socketTimeout: timeoutAdjuster * (requestOptions.timeout || 0),
};

@@ -147,3 +151,3 @@ const decisions = {

// eslint-disable-next-line functional/immutable-data
transporter.hosts = values.map(host => createHost(host.url, host.accept));
transporter.hosts = values.map(hostOptions => createHost(hostOptions));
},

@@ -261,3 +265,3 @@ read(request, requestOptions) {

// eslint-disable-next-line functional/no-let
let url = `https://${host.url}/${path}`;
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
if (queryParametersAsString.length) {

@@ -264,0 +268,0 @@ url += `?${queryParametersAsString}`;

{
"name": "@algolia/transporter",
"version": "4.0.0-beta.4",
"version": "4.0.0-beta.5",
"private": false,

@@ -11,2 +11,3 @@ "description": "Promise-based transporter layer with embedded retry strategy.",

],
"sideEffects": false,
"main": "index.js",

@@ -16,6 +17,6 @@ "module": "dist/transporter.esm.js",

"dependencies": {
"@algolia/cache-common": "4.0.0-beta.4",
"@algolia/logger-common": "4.0.0-beta.4",
"@algolia/requester-common": "4.0.0-beta.4"
"@algolia/cache-common": "4.0.0-beta.5",
"@algolia/logger-common": "4.0.0-beta.5",
"@algolia/requester-common": "4.0.0-beta.5"
}
}
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