@algolia/requester-browser-xhr
Advanced tools
Comparing version 4.14.1 to 5.0.0-alpha.1
@@ -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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
15259
13
365
1
7
2
1
2
+ Added@algolia/client-common@5.0.0-alpha.1(transitive)
- Removed@algolia/requester-common@4.14.1
- Removed@algolia/requester-common@4.14.1(transitive)