@algolia/requester-node-http
Advanced tools
Comparing version 5.3.2 to 5.4.0
@@ -1,7 +0,5 @@ | ||
import { Requester } from '@algolia/client-common'; | ||
import http from 'http'; | ||
import https from 'https'; | ||
import { Requester } from '@algolia/client-common'; | ||
declare function echoRequester(status?: number): Requester; | ||
type CreateHttpRequesterOptions = Partial<{ | ||
@@ -18,2 +16,2 @@ agent: http.Agent | https.Agent; | ||
export { type CreateHttpRequesterOptions, createHttpRequester, echoRequester }; | ||
export { type CreateHttpRequesterOptions, createHttpRequester }; |
@@ -1,12 +0,5 @@ | ||
// src/echoRequester.ts | ||
import { URL } from "url"; | ||
import { createEchoRequester } from "@algolia/client-common"; | ||
function echoRequester(status = 200) { | ||
return createEchoRequester({ getURL: (url) => new URL(url), status }); | ||
} | ||
// src/createHttpRequester.ts | ||
import http from "http"; | ||
import https from "https"; | ||
import { URL as URL2 } from "url"; | ||
import { URL } from "url"; | ||
var agentOptions = { keepAlive: true }; | ||
@@ -27,3 +20,3 @@ var defaultHttpAgent = new http.Agent(agentOptions); | ||
let connectTimeout; | ||
const url = new URL2(request.url); | ||
const url = new URL(request.url); | ||
const path = url.search === null ? url.pathname : `${url.pathname}${url.search}`; | ||
@@ -88,5 +81,4 @@ const options = { | ||
export { | ||
createHttpRequester, | ||
echoRequester | ||
createHttpRequester | ||
}; | ||
//# sourceMappingURL=requester.http.js.map |
@@ -1,2 +0,1 @@ | ||
export * from './src/echoRequester'; | ||
export * from './src/createHttpRequester'; |
{ | ||
"name": "@algolia/requester-node-http", | ||
"version": "5.3.2", | ||
"version": "5.4.0", | ||
"description": "Promise-based request library for node using the native http module.", | ||
@@ -33,20 +33,16 @@ "repository": { | ||
"clean": "rm -rf ./dist || true", | ||
"test": "jest", | ||
"test": "vitest --run", | ||
"test:bundle": "publint . && attw --pack ." | ||
}, | ||
"dependencies": { | ||
"@algolia/client-common": "5.3.2" | ||
"@algolia/client-common": "5.4.0" | ||
}, | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "0.16.1", | ||
"@babel/preset-env": "7.25.4", | ||
"@babel/preset-typescript": "7.24.7", | ||
"@types/jest": "29.5.12", | ||
"@types/node": "22.5.1", | ||
"jest": "29.7.0", | ||
"nock": "13.5.5", | ||
"publint": "0.2.10", | ||
"ts-jest": "29.2.5", | ||
"tsup": "8.2.4", | ||
"typescript": "5.5.4" | ||
"typescript": "5.5.4", | ||
"vitest": "2.0.5" | ||
}, | ||
@@ -53,0 +49,0 @@ "engines": { |
@@ -7,2 +7,3 @@ import http from 'http'; | ||
import nock from 'nock'; | ||
import { vi, describe, test, beforeAll, afterAll, expect } from 'vitest'; | ||
@@ -27,7 +28,7 @@ import { createHttpRequester } from '../..'; | ||
const mockedRequestResponse = { | ||
destroy: jest.fn(), | ||
on: jest.fn(), | ||
once: jest.fn(), | ||
write: jest.fn(), | ||
end: jest.fn(), | ||
destroy: vi.fn(), | ||
on: vi.fn(), | ||
once: vi.fn(), | ||
write: vi.fn(), | ||
end: vi.fn(), | ||
}; | ||
@@ -37,3 +38,3 @@ | ||
// @ts-expect-error we don't care about the response for those tests | ||
https.request = jest.fn(() => mockedRequestResponse); | ||
https.request = vi.fn(() => mockedRequestResponse); | ||
}); | ||
@@ -44,14 +45,14 @@ | ||
http.request = httpBaseRequest; | ||
jest.resetAllMocks(); | ||
jest.clearAllMocks(); | ||
vi.resetAllMocks(); | ||
vi.clearAllMocks(); | ||
}); | ||
it('allow init without parameters', () => { | ||
test('allow init without parameters', () => { | ||
expect(() => createHttpRequester()).not.toThrow(); | ||
}); | ||
it('allow providing custom agent', async () => { | ||
test('allow providing custom agent', async () => { | ||
const agent = new http.Agent(); | ||
// @ts-expect-error we don't care about the response for those tests | ||
http.request = jest.fn(() => mockedRequestResponse); | ||
http.request = vi.fn(() => mockedRequestResponse); | ||
const tmpRequester = createHttpRequester({ | ||
@@ -69,3 +70,3 @@ agent, | ||
it('allow overriding default options', async () => { | ||
test('allow overriding default options', async () => { | ||
const tmpRequester = createHttpRequester({ | ||
@@ -93,3 +94,3 @@ requesterOptions: { | ||
describe('status code handling', () => { | ||
it('sends requests', async () => { | ||
test('sends requests', async () => { | ||
const body = getStringifiedBody(); | ||
@@ -104,3 +105,3 @@ | ||
it('resolves status 200', async () => { | ||
test('resolves status 200', async () => { | ||
const body = getStringifiedBody(); | ||
@@ -117,3 +118,3 @@ | ||
it('resolves status 300', async () => { | ||
test('resolves status 300', async () => { | ||
const reason = 'Multiple Choices'; | ||
@@ -130,3 +131,3 @@ | ||
it('resolves status 400', async () => { | ||
test('resolves status 400', async () => { | ||
const body = getStringifiedBody({ | ||
@@ -145,3 +146,3 @@ message: 'Invalid Application-Id or API-Key', | ||
it('handles chunked responses inside unicode character boundaries', async () => { | ||
test('handles chunked responses inside unicode character boundaries', async () => { | ||
const data = Buffer.from('äöü'); | ||
@@ -175,7 +176,10 @@ | ||
afterAll((done) => { | ||
server.close(() => done()); | ||
}); | ||
afterAll( | ||
() => | ||
new Promise((done) => { | ||
done(); | ||
}), | ||
); | ||
it('timeouts with the given 1 seconds connection timeout', async () => { | ||
test('timeouts with the given 1 seconds connection timeout', async () => { | ||
const before = Date.now(); | ||
@@ -195,3 +199,3 @@ const response = await requester.send({ | ||
it('connection timeouts with the given 2 seconds connection timeout', async () => { | ||
test('connection timeouts with the given 2 seconds connection timeout', async () => { | ||
const before = Date.now(); | ||
@@ -211,3 +215,3 @@ const response = await requester.send({ | ||
it("socket timeouts if response don't appears before the timeout with 2 seconds timeout", async () => { | ||
test("socket timeouts if response don't appears before the timeout with 2 seconds timeout", async () => { | ||
const before = Date.now(); | ||
@@ -228,3 +232,3 @@ | ||
it("socket timeouts if response don't appears before the timeout with 3 seconds timeout", async () => { | ||
test("socket timeouts if response don't appears before the timeout with 3 seconds timeout", async () => { | ||
const before = Date.now(); | ||
@@ -244,3 +248,3 @@ const response = await requester.send({ | ||
it('do not timeouts if response appears before the timeout', async () => { | ||
test('do not timeouts if response appears before the timeout', async () => { | ||
const before = Date.now(); | ||
@@ -264,3 +268,3 @@ const response = await requester.send({ | ||
describe('error handling', (): void => { | ||
it('resolves dns not found', async () => { | ||
test('resolves dns not found', async () => { | ||
const request: EndRequest = { | ||
@@ -282,3 +286,3 @@ url: 'https://this-dont-exist.algolia.com', | ||
it('resolves general network errors', async () => { | ||
test('resolves general network errors', async () => { | ||
nock(testQueryBaseUrl, { reqheaders: headers }) | ||
@@ -285,0 +289,0 @@ .post('/foo') |
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
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
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
7
31822
10
522
+ Added@algolia/client-common@5.4.0(transitive)
- Removed@algolia/client-common@5.3.2(transitive)
Updated@algolia/client-common@5.4.0