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

@algolia/requester-browser-xhr

Package Overview
Dependencies
Maintainers
3
Versions
237
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/requester-browser-xhr - npm Package Compare versions

Comparing version 4.14.1 to 5.0.0-alpha.1

dist/index.d.ts

101

dist/requester-browser-xhr.cjs.js

@@ -5,58 +5,61 @@ 'use strict';

function createBrowserXhrRequester() {
return {
send(request) {
return new Promise((resolve) => {
const baseRequester = new XMLHttpRequest();
baseRequester.open(request.method, request.url, true);
Object.keys(request.headers).forEach(key => baseRequester.setRequestHeader(key, request.headers[key]));
const createTimeout = (timeout, content) => {
return setTimeout(() => {
baseRequester.abort();
resolve({
status: 0,
content,
isTimedOut: true,
});
}, timeout * 1000);
};
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
// eslint-disable-next-line functional/no-let
let responseTimeout;
// eslint-disable-next-line functional/immutable-data
baseRequester.onreadystatechange = () => {
if (baseRequester.readyState > baseRequester.OPENED && responseTimeout === undefined) {
clearTimeout(connectTimeout);
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
}
};
// eslint-disable-next-line functional/immutable-data
baseRequester.onerror = () => {
// istanbul ignore next
if (baseRequester.status === 0) {
clearTimeout(connectTimeout);
clearTimeout(responseTimeout);
resolve({
content: baseRequester.responseText || 'Network request failed',
status: baseRequester.status,
isTimedOut: false,
});
}
};
// eslint-disable-next-line functional/immutable-data
baseRequester.onload = () => {
var clientCommon = require('@algolia/client-common');
function createXhrRequester() {
function send(request) {
return new Promise((resolve) => {
const baseRequester = new XMLHttpRequest();
baseRequester.open(request.method, request.url, true);
Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
const createTimeout = (timeout, content) => {
return setTimeout(() => {
baseRequester.abort();
resolve({
status: 0,
content,
isTimedOut: true,
});
}, timeout);
};
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
let responseTimeout;
baseRequester.onreadystatechange = () => {
if (baseRequester.readyState > baseRequester.OPENED &&
responseTimeout === undefined) {
clearTimeout(connectTimeout);
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
}
};
baseRequester.onerror = () => {
// istanbul ignore next
if (baseRequester.status === 0) {
clearTimeout(connectTimeout);
clearTimeout(responseTimeout);
resolve({
content: baseRequester.responseText,
content: baseRequester.responseText || 'Network request failed',
status: baseRequester.status,
isTimedOut: false,
});
};
baseRequester.send(request.data);
});
},
};
}
};
baseRequester.onload = () => {
clearTimeout(connectTimeout);
clearTimeout(responseTimeout);
resolve({
content: baseRequester.responseText,
status: baseRequester.status,
isTimedOut: false,
});
};
baseRequester.send(request.data);
});
}
return { send };
}
exports.createBrowserXhrRequester = createBrowserXhrRequester;
function echoRequester(status = 200) {
return clientCommon.createEchoRequester({ getURL: (url) => new URL(url), status });
}
exports.createXhrRequester = createXhrRequester;
exports.echoRequester = echoRequester;
{
"name": "@algolia/requester-browser-xhr",
"version": "4.14.1",
"private": false,
"version": "5.0.0-alpha.1",
"description": "Promise-based request library for browser using xhr.",
"repository": {
"type": "git",
"url": "git://github.com/algolia/algoliasearch-client-javascript.git"
},
"repository": "algolia/algoliasearch-client-javascript",
"license": "MIT",
"sideEffects": false,
"main": "index.js",
"module": "dist/requester-browser-xhr.esm.js",
"types": "dist/requester-browser-xhr.d.ts",
"author": "Algolia",
"main": "dist/requester-browser-xhr.cjs.js",
"module": "dist/requester-browser-xhr.esm.node.js",
"types": "dist/index.d.ts",
"files": [
"index.js",
"dist"
"dist",
"src",
"index.ts"
],
"scripts": {
"clean": "rm -rf dist/",
"test": "jest"
},
"dependencies": {
"@algolia/requester-common": "4.14.1"
"@algolia/client-common": "5.0.0-alpha.1"
},
"devDependencies": {
"@types/jest": "28.1.6",
"@types/node": "16.11.45",
"jest": "28.1.3",
"jest-environment-jsdom": "28.1.3",
"ts-jest": "28.0.5",
"typescript": "4.7.4",
"xhr-mock": "2.5.1"
},
"engines": {
"node": ">= 14.0.0"
}
}
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