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

@pnpm/network.agent

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnpm/network.agent - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

dist/preview-1707304045348.js

137

agent.spec.ts

@@ -92,1 +92,138 @@ import { getAgent } from './agent'

test('should return the correct client certificates', () => {
const agent = getAgent('https://foo.com/bar', {
clientCertificates: {
'//foo.com/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
})
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
})
})
test('should not return client certificates for a different host', () => {
const agent = getAgent('https://foo.com/bar', {
clientCertificates: {
'//bar.com/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
})
expect(agent).toEqual({
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
})
})
test('scoped certificates override global certificates', () => {
const agent = getAgent('https://foo.com/bar', {
ca: 'global-ca',
key: 'global-key',
cert: 'global-cert',
clientCertificates: {
'//foo.com/': {
ca: 'scoped-ca',
cert: 'scoped-cert',
key: 'scoped-key',
},
},
})
expect(agent).toEqual({
ca: 'scoped-ca',
cert: 'scoped-cert',
key: 'scoped-key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
})
})
test('select correct client certificates when host has a port', () => {
const agent = getAgent('https://foo.com:1234/bar', {
clientCertificates: {
'//foo.com:1234/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
})
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
})
})
test('select correct client certificates when host has a path', () => {
const agent = getAgent('https://foo.com/bar/baz', {
clientCertificates: {
'//foo.com/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
})
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
})
})
test('select correct client certificates when host has a path and the cert contains a path', () => {
const agent = getAgent('https://foo.com/bar/baz', {
clientCertificates: {
'//foo.com/bar/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
})
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
})
})

55

agent.ts

@@ -5,2 +5,3 @@ import { URL } from 'url'

import { getProxyAgent, ProxyAgentOptions } from '@pnpm/network.proxy-agent'
import { pickSettingByUrl } from '@pnpm/network.config';

@@ -29,2 +30,7 @@ const HttpsAgent = HttpAgent.HttpsAgent

const { ca, cert, key: certKey } = {
...opts,
...pickSettingByUrl(opts.clientCertificates, uri)
}
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */

@@ -34,6 +40,8 @@ const key = [

`local-address:${opts.localAddress ?? '>no-local-address<'}`,
`strict-ssl:${isHttps ? Boolean(opts.strictSsl).toString() : '>no-strict-ssl<'}`,
`ca:${(isHttps && opts.ca?.toString()) || '>no-ca<'}`,
`cert:${(isHttps && opts.cert?.toString()) || '>no-cert<'}`,
`key:${(isHttps && opts.key) || '>no-key<'}`,
`strict-ssl:${
isHttps ? Boolean(opts.strictSsl).toString() : '>no-strict-ssl<'
}`,
`ca:${isHttps && (ca?.toString()) || '>no-ca<'}`,
`cert:${isHttps && (cert?.toString()) || '>no-cert<'}`,
`key:${isHttps && (certKey?.toString()) || '>no-key<'}`,
].join(':')

@@ -51,3 +59,6 @@ /* eslint-enable @typescript-eslint/prefer-nullish-coalescing */

// consistent errors.
const agentTimeout = typeof opts.timeout !== 'number' || opts.timeout === 0 ? 0 : opts.timeout + 1
const agentTimeout =
typeof opts.timeout !== 'number' || opts.timeout === 0
? 0
: opts.timeout + 1

@@ -62,15 +73,15 @@ // NOTE: localAddress is passed to the agent here even though it is an

? new HttpsAgent({
ca: opts.ca,
cert: opts.cert,
key: opts.key,
localAddress: opts.localAddress,
maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS,
rejectUnauthorized: opts.strictSsl,
timeout: agentTimeout,
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
ca,
cert,
key: certKey,
localAddress: opts.localAddress,
maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS,
rejectUnauthorized: opts.strictSsl,
timeout: agentTimeout,
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
: new HttpAgent({
localAddress: opts.localAddress,
maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS,
timeout: agentTimeout,
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
localAddress: opts.localAddress,
maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS,
timeout: agentTimeout,
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
AGENT_CACHE.set(key, agent)

@@ -81,7 +92,13 @@ return agent

function checkNoProxy (uri: string, opts: { noProxy?: boolean | string }) {
const host = new URL(uri).hostname.split('.').filter(x => x).reverse()
const host = new URL(uri).hostname
.split('.')
.filter(x => x)
.reverse()
if (typeof opts.noProxy === 'string') {
const noproxyArr = opts.noProxy.split(/\s*,\s*/g)
return noproxyArr.some(no => {
const noParts = no.split('.').filter(x => x).reverse()
const noParts = no
.split('.')
.filter(x => x)
.reverse()
if (noParts.length === 0) {

@@ -88,0 +105,0 @@ return false

import { ProxyAgentOptions } from '@pnpm/network.proxy-agent';
export declare type AgentOptions = ProxyAgentOptions & {
export type AgentOptions = ProxyAgentOptions & {
noProxy?: boolean | string;
};
export declare function getAgent(uri: string, opts: AgentOptions): unknown;

@@ -11,2 +11,3 @@ "use strict";

const network_proxy_agent_1 = require("@pnpm/network.proxy-agent");
const network_config_1 = require("@pnpm/network.config");
const HttpsAgent = agentkeepalive_1.default.HttpsAgent;

@@ -25,13 +26,16 @@ const DEFAULT_MAX_SOCKETS = 50;

function getNonProxyAgent(uri, opts) {
var _a, _b, _c, _d, _e;
const parsedUri = new url_1.URL(uri);
const isHttps = parsedUri.protocol === 'https:';
const { ca, cert, key: certKey } = {
...opts,
...(0, network_config_1.pickSettingByUrl)(opts.clientCertificates, uri)
};
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
const key = [
`https:${isHttps.toString()}`,
`local-address:${(_a = opts.localAddress) !== null && _a !== void 0 ? _a : '>no-local-address<'}`,
`local-address:${opts.localAddress ?? '>no-local-address<'}`,
`strict-ssl:${isHttps ? Boolean(opts.strictSsl).toString() : '>no-strict-ssl<'}`,
`ca:${(isHttps && ((_b = opts.ca) === null || _b === void 0 ? void 0 : _b.toString())) || '>no-ca<'}`,
`cert:${(isHttps && ((_c = opts.cert) === null || _c === void 0 ? void 0 : _c.toString())) || '>no-cert<'}`,
`key:${(isHttps && opts.key) || '>no-key<'}`,
`ca:${isHttps && (ca?.toString()) || '>no-ca<'}`,
`cert:${isHttps && (cert?.toString()) || '>no-cert<'}`,
`key:${isHttps && (certKey?.toString()) || '>no-key<'}`,
].join(':');

@@ -47,3 +51,5 @@ /* eslint-enable @typescript-eslint/prefer-nullish-coalescing */

// consistent errors.
const agentTimeout = typeof opts.timeout !== 'number' || opts.timeout === 0 ? 0 : opts.timeout + 1;
const agentTimeout = typeof opts.timeout !== 'number' || opts.timeout === 0
? 0
: opts.timeout + 1;
// NOTE: localAddress is passed to the agent here even though it is an

@@ -57,7 +63,7 @@ // undocumented option of the agent's constructor.

? new HttpsAgent({
ca: opts.ca,
cert: opts.cert,
key: opts.key,
ca,
cert,
key: certKey,
localAddress: opts.localAddress,
maxSockets: (_d = opts.maxSockets) !== null && _d !== void 0 ? _d : DEFAULT_MAX_SOCKETS,
maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS,
rejectUnauthorized: opts.strictSsl,

@@ -68,3 +74,3 @@ timeout: agentTimeout,

localAddress: opts.localAddress,
maxSockets: (_e = opts.maxSockets) !== null && _e !== void 0 ? _e : DEFAULT_MAX_SOCKETS,
maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS,
timeout: agentTimeout,

@@ -76,7 +82,13 @@ }); // eslint-disable-line @typescript-eslint/no-explicit-any

function checkNoProxy(uri, opts) {
const host = new url_1.URL(uri).hostname.split('.').filter(x => x).reverse();
const host = new url_1.URL(uri).hostname
.split('.')
.filter(x => x)
.reverse();
if (typeof opts.noProxy === 'string') {
const noproxyArr = opts.noProxy.split(/\s*,\s*/g);
return noproxyArr.some(no => {
const noParts = no.split('.').filter(x => x).reverse();
const noParts = no
.split('.')
.filter(x => x)
.reverse();
if (noParts.length === 0) {

@@ -83,0 +95,0 @@ return false;

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

return function Agent(opts) {
return Object.assign(Object.assign({}, opts), { __type: type });
return {
...opts,
__type: type,
};
};

@@ -47,3 +50,7 @@ }

test('all expected options passed down to proxy agent', () => {
const opts = Object.assign({ httpsProxy: 'https://user:pass@my.proxy:1234/foo', noProxy: 'qar.com, bar.com' }, OPTS);
const opts = {
httpsProxy: 'https://user:pass@my.proxy:1234/foo',
noProxy: 'qar.com, bar.com',
...OPTS,
};
expect((0, agent_1.getAgent)('https://foo.com/bar', opts).proxy).toEqual({

@@ -65,3 +72,7 @@ ALPNProtocols: ['http 1.1'],

test("don't use a proxy when the URL is in noProxy", () => {
const opts = Object.assign({ httpsProxy: 'https://user:pass@my.proxy:1234/foo', noProxy: 'foo.com, bar.com' }, OPTS);
const opts = {
httpsProxy: 'https://user:pass@my.proxy:1234/foo',
noProxy: 'foo.com, bar.com',
...OPTS,
};
expect((0, agent_1.getAgent)('https://foo.com/bar', opts)).toEqual({

@@ -78,2 +89,128 @@ __type: 'https',

});
test('should return the correct client certificates', () => {
const agent = (0, agent_1.getAgent)('https://foo.com/bar', {
clientCertificates: {
'//foo.com/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
});
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
});
});
test('should not return client certificates for a different host', () => {
const agent = (0, agent_1.getAgent)('https://foo.com/bar', {
clientCertificates: {
'//bar.com/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
});
expect(agent).toEqual({
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
});
});
test('scoped certificates override global certificates', () => {
const agent = (0, agent_1.getAgent)('https://foo.com/bar', {
ca: 'global-ca',
key: 'global-key',
cert: 'global-cert',
clientCertificates: {
'//foo.com/': {
ca: 'scoped-ca',
cert: 'scoped-cert',
key: 'scoped-key',
},
},
});
expect(agent).toEqual({
ca: 'scoped-ca',
cert: 'scoped-cert',
key: 'scoped-key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
});
});
test('select correct client certificates when host has a port', () => {
const agent = (0, agent_1.getAgent)('https://foo.com:1234/bar', {
clientCertificates: {
'//foo.com:1234/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
});
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
});
});
test('select correct client certificates when host has a path', () => {
const agent = (0, agent_1.getAgent)('https://foo.com/bar/baz', {
clientCertificates: {
'//foo.com/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
});
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
});
});
test('select correct client certificates when host has a path and the cert contains a path', () => {
const agent = (0, agent_1.getAgent)('https://foo.com/bar/baz', {
clientCertificates: {
'//foo.com/bar/': {
ca: 'ca',
cert: 'cert',
key: 'key',
},
},
});
expect(agent).toEqual({
ca: 'ca',
cert: 'cert',
key: 'key',
localAddress: undefined,
maxSockets: 50,
rejectUnauthorized: undefined,
timeout: 0,
__type: 'https',
});
});
//# sourceMappingURL=agent.spec.js.map
{
"name": "@pnpm/network.agent",
"version": "0.1.0",
"homepage": "https://bit.dev/pnpm/network/agent",
"version": "1.0.0",
"homepage": "https://bit.cloud/pnpm/network/agent",
"main": "dist/index.js",

@@ -9,3 +9,3 @@ "componentId": {

"name": "agent",
"version": "0.1.0"
"version": "1.0.0"
},

@@ -15,11 +15,17 @@ "dependencies": {

"lru-cache": "7.10.1",
"@pnpm/network.proxy-agent": "0.1.0"
"@pnpm/network.config": "1.0.0",
"@pnpm/network.proxy-agent": "1.0.0"
},
"devDependencies": {
"@types/jest": "26.0.20",
"@types/node": "12.20.4",
"@babel/runtime": "7.20.0"
"@types/node": "^18.11.9",
"@types/jest": "^29.2.2",
"@pnpm/tsconfig": "^2.0.0",
"@pnpm/eslint-config": "^1.1.0",
"@pnpm/env.envs.pnpm-env": "1.0.0"
},
"peerDependencies": {},
"license": "MIT",
"optionalDependencies": {},
"peerDependenciesMeta": {},
"type": "module",
"private": false,

@@ -37,2 +43,2 @@ "engines": {

}
}
}
{
"compilerOptions": {
"lib": [
"es2019",
"DOM",
"ES6",
"DOM.Iterable"
],
"target": "es2015",
"module": "CommonJS",
"jsx": "react",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"composite": true,
"declaration": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"preserveConstEnums": true,
"removeComments": false,
"sourceMap": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"outDir": "dist",
"moduleResolution": "node",
"esModuleInterop": true,
"rootDir": ".",
"resolveJsonModule": true
"strict": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es2020",
"ignoreDeprecations": "5.0",
"outDir": "dist"
},
"atom": {
"rewriteTsconfig": true
},
"exclude": [
"artifacts",
"public",
"dist",
"package.json"
"node_modules",
"package.json",
"**/*.cjs"
],
"include": [
"**/*",
"**/*.json"
"**/*.json",
".mocharc.js",
".mocharc.js"
]
}

@@ -0,1 +1,5 @@

/**
* this file is copied into your components' build output.
*/
declare module '*.png' {

@@ -8,8 +12,8 @@ const value: any;

export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
export const ReactComponent: FunctionComponent<
SVGProps<SVGSVGElement> & { title?: string }
>;
const src: string;
export default src;
}
// @TODO Gilad
declare module '*.jpg' {

@@ -16,0 +20,0 @@ const value: any;

@@ -1,42 +0,47 @@

declare module '*.module.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.scss' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.sass' {
const classes: { readonly [key: string]: string };
export default classes;
}
/**
* this file is copied into your components' build output.
*/
declare module '*.module.less' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.less' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.sass' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.scss' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.mdx' {
const component: any;
export default component;
}
declare module '*.module.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.scss' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.sass' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.module.less' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.less' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.sass' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.scss' {
const classes: { readonly [key: string]: string };
export default classes;
}
declare module '*.mdx' {
const component: any;
export default component;
}

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