@serenity-js/rest 3.32.5 → 3.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/lib/io/AxiosRequestConfigDefaults.d.ts +1 -0
- package/lib/io/AxiosRequestConfigDefaults.d.ts.map +1 -1
- package/lib/io/EnvironmentVariables.d.ts +9 -0
- package/lib/io/EnvironmentVariables.d.ts.map +1 -0
- package/lib/io/EnvironmentVariables.js +39 -0
- package/lib/io/EnvironmentVariables.js.map +1 -0
- package/lib/io/ProxyAgent.d.ts +1 -3
- package/lib/io/ProxyAgent.d.ts.map +1 -1
- package/lib/io/ProxyAgent.js +1 -2
- package/lib/io/ProxyAgent.js.map +1 -1
- package/lib/io/ProxyBypass.d.ts +6 -0
- package/lib/io/ProxyBypass.d.ts.map +1 -0
- package/lib/io/ProxyBypass.js +70 -0
- package/lib/io/ProxyBypass.js.map +1 -0
- package/lib/io/createAxios.d.ts.map +1 -1
- package/lib/io/createAxios.js +2 -2
- package/lib/io/createAxios.js.map +1 -1
- package/lib/io/proxy.d.ts +14 -0
- package/lib/io/proxy.d.ts.map +1 -0
- package/lib/io/proxy.js +104 -0
- package/lib/io/proxy.js.map +1 -0
- package/lib/screenplay/abilities/CallAnApi.d.ts +59 -15
- package/lib/screenplay/abilities/CallAnApi.d.ts.map +1 -1
- package/lib/screenplay/abilities/CallAnApi.js +74 -28
- package/lib/screenplay/abilities/CallAnApi.js.map +1 -1
- package/package.json +5 -6
- package/src/io/AxiosRequestConfigDefaults.ts +1 -0
- package/src/io/EnvironmentVariables.ts +39 -0
- package/src/io/ProxyAgent.ts +2 -5
- package/src/io/ProxyBypass.ts +83 -0
- package/src/io/createAxios.ts +1 -1
- package/src/io/proxy.ts +91 -0
- package/src/screenplay/abilities/CallAnApi.ts +74 -30
- package/lib/io/axiosProxyOverridesFor.d.ts +0 -11
- package/lib/io/axiosProxyOverridesFor.d.ts.map +0 -1
- package/lib/io/axiosProxyOverridesFor.js +0 -34
- package/lib/io/axiosProxyOverridesFor.js.map +0 -1
- package/lib/screenplay/abilities/proxy/ProxyAgent.d.ts +0 -54
- package/lib/screenplay/abilities/proxy/ProxyAgent.d.ts.map +0 -1
- package/lib/screenplay/abilities/proxy/ProxyAgent.js +0 -121
- package/lib/screenplay/abilities/proxy/ProxyAgent.js.map +0 -1
- package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.d.ts +0 -11
- package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.d.ts.map +0 -1
- package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.js +0 -34
- package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.js.map +0 -1
- package/lib/screenplay/abilities/proxy/createUrl.d.ts +0 -9
- package/lib/screenplay/abilities/proxy/createUrl.d.ts.map +0 -1
- package/lib/screenplay/abilities/proxy/createUrl.js +0 -29
- package/lib/screenplay/abilities/proxy/createUrl.js.map +0 -1
- package/lib/screenplay/abilities/proxy/index.d.ts +0 -2
- package/lib/screenplay/abilities/proxy/index.d.ts.map +0 -1
- package/lib/screenplay/abilities/proxy/index.js +0 -18
- package/lib/screenplay/abilities/proxy/index.js.map +0 -1
- package/src/io/axiosProxyOverridesFor.ts +0 -39
- package/src/screenplay/abilities/proxy/ProxyAgent.ts +0 -129
- package/src/screenplay/abilities/proxy/axiosProxyOverridesFor.ts +0 -39
- package/src/screenplay/abilities/proxy/createUrl.ts +0 -39
- package/src/screenplay/abilities/proxy/index.ts +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axiosProxyOverridesFor.d.ts","sourceRoot":"","sources":["../../src/io/axiosProxyOverridesFor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAI/E;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,GAAG,GAAG,EAAE,OAAO,EAAE,0BAA0B,CAAC,IAAI,CAAC,GAAG;IAC3F,KAAK,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAA;CAC9D,CA0BA"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.axiosProxyOverridesFor = axiosProxyOverridesFor;
|
|
4
|
-
const tiny_types_1 = require("tiny-types");
|
|
5
|
-
const createUrl_1 = require("./createUrl");
|
|
6
|
-
const ProxyAgent_1 = require("./ProxyAgent");
|
|
7
|
-
/**
|
|
8
|
-
* @param options
|
|
9
|
-
*/
|
|
10
|
-
function axiosProxyOverridesFor(options) {
|
|
11
|
-
const envProxyOverride = options.proxy
|
|
12
|
-
&& (0, createUrl_1.createUrl)({
|
|
13
|
-
username: options.proxy?.auth?.username,
|
|
14
|
-
password: options.proxy?.auth?.password,
|
|
15
|
-
protocol: options.proxy?.protocol,
|
|
16
|
-
hostname: (0, tiny_types_1.ensure)('proxy.host', options.proxy?.host, (0, tiny_types_1.isDefined)()),
|
|
17
|
-
port: options.proxy?.port ? Number(options.proxy?.port) : undefined,
|
|
18
|
-
}).toString();
|
|
19
|
-
const agent = new ProxyAgent_1.ProxyAgent({
|
|
20
|
-
httpAgent: options.httpAgent,
|
|
21
|
-
httpsAgent: options.httpsAgent,
|
|
22
|
-
// if there's a specific proxy override configured, use it
|
|
23
|
-
// if not - detect proxy automatically based on env variables
|
|
24
|
-
getProxyForUrl: envProxyOverride
|
|
25
|
-
? (url_) => envProxyOverride
|
|
26
|
-
: undefined,
|
|
27
|
-
});
|
|
28
|
-
return {
|
|
29
|
-
proxy: false,
|
|
30
|
-
httpAgent: agent,
|
|
31
|
-
httpsAgent: agent,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=axiosProxyOverridesFor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axiosProxyOverridesFor.js","sourceRoot":"","sources":["../../src/io/axiosProxyOverridesFor.ts"],"names":[],"mappings":";;AAUA,wDA4BC;AArCD,2CAA+C;AAG/C,2CAAwC;AACxC,6CAA0C;AAE1C;;GAEG;AACH,SAAgB,sBAAsB,CAAa,OAAyC;IAGxF,MAAM,gBAAgB,GAAmB,OAAO,CAAC,KAAK;WAC/C,IAAA,qBAAS,EAAC;YACT,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ;YACjC,QAAQ,EAAE,IAAA,mBAAM,EAAC,YAAY,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAA,sBAAS,GAAE,CAAC;YAChE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SACtE,CAAC,CAAC,QAAQ,EAAE,CAAC;IAElB,MAAM,KAAK,GAAG,IAAI,uBAAU,CAAC;QACzB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;QAE9B,0DAA0D;QAC1D,6DAA6D;QAC7D,cAAc,EAAE,gBAAgB;YAC5B,CAAC,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,gBAAgB;YACpC,CAAC,CAAC,SAAS;KAClB,CAAC,CAAC;IAEH,OAAO;QACH,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,KAAK;KACpB,CAAC;AACN,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { AgentConnectOpts } from 'agent-base';
|
|
2
|
-
import { Agent } from 'agent-base';
|
|
3
|
-
import * as http from 'http';
|
|
4
|
-
import { type HttpProxyAgentOptions } from 'http-proxy-agent';
|
|
5
|
-
import { type HttpsProxyAgentOptions } from 'https-proxy-agent';
|
|
6
|
-
type GetProxyForUrlCallback = (url: string) => string;
|
|
7
|
-
export type ProxyAgentOptions = HttpProxyAgentOptions<''> & HttpsProxyAgentOptions<''> & {
|
|
8
|
-
/**
|
|
9
|
-
* Default `http.Agent` instance to use when no proxy is
|
|
10
|
-
* configured for a request. Defaults to a new `http.Agent()`
|
|
11
|
-
* instance with the proxy agent options passed in.
|
|
12
|
-
*/
|
|
13
|
-
httpAgent?: http.Agent;
|
|
14
|
-
/**
|
|
15
|
-
* Default `http.Agent` instance to use when no proxy is
|
|
16
|
-
* configured for a request. Defaults to a new `https.Agent()`
|
|
17
|
-
* instance with the proxy agent options passed in.
|
|
18
|
-
*/
|
|
19
|
-
httpsAgent?: http.Agent;
|
|
20
|
-
/**
|
|
21
|
-
* A callback for dynamic provision of proxy for url.
|
|
22
|
-
* Defaults to standard proxy environment variables,
|
|
23
|
-
* see https://www.npmjs.com/package/proxy-from-env for details
|
|
24
|
-
*/
|
|
25
|
-
getProxyForUrl?: GetProxyForUrlCallback;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* A simplified version of the original
|
|
29
|
-
* [`ProxyAgent`](https://github.com/TooTallNate/proxy-agents/blob/5923589c2e5206504772c250ac4f20fc31122d3b/packages/proxy-agent/src/index.ts)
|
|
30
|
-
* with fewer dependencies.
|
|
31
|
-
*
|
|
32
|
-
* Delegates requests to the appropriate `Agent` subclass based on the "proxy"
|
|
33
|
-
* environment variables, or the provided `agentOptions.getProxyForUrl` callback.
|
|
34
|
-
*
|
|
35
|
-
* Uses an LRU cache to prevent unnecessary creation of proxy `http.Agent` instances.
|
|
36
|
-
*/
|
|
37
|
-
export declare class ProxyAgent extends Agent {
|
|
38
|
-
private readonly agentOptions;
|
|
39
|
-
private static proxyAgents;
|
|
40
|
-
/**
|
|
41
|
-
* Cache for `Agent` instances.
|
|
42
|
-
*/
|
|
43
|
-
private readonly cache;
|
|
44
|
-
private readonly httpAgent;
|
|
45
|
-
private readonly httpsAgent;
|
|
46
|
-
private readonly getProxyForUrl;
|
|
47
|
-
constructor(agentOptions: ProxyAgentOptions);
|
|
48
|
-
connect(request: http.ClientRequest, options: AgentConnectOpts): Promise<http.Agent>;
|
|
49
|
-
private createAgent;
|
|
50
|
-
private isValidProtocol;
|
|
51
|
-
destroy(): void;
|
|
52
|
-
}
|
|
53
|
-
export {};
|
|
54
|
-
//# sourceMappingURL=ProxyAgent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyAgent.d.ts","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/ProxyAgent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAYjF,KAAK,sBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GACzB,qBAAqB,CAAC,EAAE,CAAC,GACzB,sBAAsB,CAAC,EAAE,CAAC,GAAG;IACzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;IACvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;IACxB;;;;OAIG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;CAC3C,CAAC;AAEN;;;;;;;;;GASG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAmBrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAjBzC,OAAO,CAAC,MAAM,CAAC,WAAW,CAGxB;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGnB;IAEH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;gBAE3B,YAAY,EAAE,iBAAiB;IAO7C,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;IA4BnG,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,eAAe;IAId,OAAO,IAAI,IAAI;CAI3B"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ProxyAgent = void 0;
|
|
37
|
-
const core_1 = require("@serenity-js/core");
|
|
38
|
-
const agent_base_1 = require("agent-base");
|
|
39
|
-
const http = __importStar(require("http"));
|
|
40
|
-
const http_proxy_agent_1 = require("http-proxy-agent");
|
|
41
|
-
const https = __importStar(require("https"));
|
|
42
|
-
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
43
|
-
const lru_cache_1 = require("lru-cache");
|
|
44
|
-
const proxy_from_env_1 = require("proxy-from-env");
|
|
45
|
-
const protocols = [
|
|
46
|
-
...http_proxy_agent_1.HttpProxyAgent.protocols,
|
|
47
|
-
];
|
|
48
|
-
/**
|
|
49
|
-
* A simplified version of the original
|
|
50
|
-
* [`ProxyAgent`](https://github.com/TooTallNate/proxy-agents/blob/5923589c2e5206504772c250ac4f20fc31122d3b/packages/proxy-agent/src/index.ts)
|
|
51
|
-
* with fewer dependencies.
|
|
52
|
-
*
|
|
53
|
-
* Delegates requests to the appropriate `Agent` subclass based on the "proxy"
|
|
54
|
-
* environment variables, or the provided `agentOptions.getProxyForUrl` callback.
|
|
55
|
-
*
|
|
56
|
-
* Uses an LRU cache to prevent unnecessary creation of proxy `http.Agent` instances.
|
|
57
|
-
*/
|
|
58
|
-
class ProxyAgent extends agent_base_1.Agent {
|
|
59
|
-
agentOptions;
|
|
60
|
-
static proxyAgents = {
|
|
61
|
-
http: [http_proxy_agent_1.HttpProxyAgent, https_proxy_agent_1.HttpsProxyAgent],
|
|
62
|
-
https: [http_proxy_agent_1.HttpProxyAgent, https_proxy_agent_1.HttpsProxyAgent],
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Cache for `Agent` instances.
|
|
66
|
-
*/
|
|
67
|
-
cache = new lru_cache_1.LRUCache({
|
|
68
|
-
max: 20,
|
|
69
|
-
dispose: (value, key) => value.destroy(),
|
|
70
|
-
});
|
|
71
|
-
httpAgent;
|
|
72
|
-
httpsAgent;
|
|
73
|
-
getProxyForUrl;
|
|
74
|
-
constructor(agentOptions) {
|
|
75
|
-
super(agentOptions);
|
|
76
|
-
this.agentOptions = agentOptions;
|
|
77
|
-
this.httpAgent = agentOptions?.httpAgent || new http.Agent(agentOptions);
|
|
78
|
-
this.httpsAgent = agentOptions?.httpsAgent || new https.Agent(agentOptions);
|
|
79
|
-
this.getProxyForUrl = agentOptions?.getProxyForUrl || proxy_from_env_1.getProxyForUrl;
|
|
80
|
-
}
|
|
81
|
-
async connect(request, options) {
|
|
82
|
-
const { secureEndpoint } = options;
|
|
83
|
-
const isWebSocket = request.getHeader('upgrade') === 'websocket';
|
|
84
|
-
const protocol = secureEndpoint
|
|
85
|
-
? (isWebSocket ? 'wss:' : 'https:')
|
|
86
|
-
: (isWebSocket ? 'ws:' : 'http:');
|
|
87
|
-
const host = request.getHeader('host');
|
|
88
|
-
const url = new URL(request.path, `${protocol}//${host}`).href;
|
|
89
|
-
const proxy = this.getProxyForUrl(url);
|
|
90
|
-
if (!proxy) {
|
|
91
|
-
return secureEndpoint
|
|
92
|
-
? this.httpsAgent
|
|
93
|
-
: this.httpAgent;
|
|
94
|
-
}
|
|
95
|
-
// attempt to get a cached `http.Agent` instance first
|
|
96
|
-
const cacheKey = `${protocol}+${proxy}`;
|
|
97
|
-
let agent = this.cache.get(cacheKey);
|
|
98
|
-
if (!agent) {
|
|
99
|
-
agent = this.createAgent(new URL(proxy), secureEndpoint || isWebSocket);
|
|
100
|
-
this.cache.set(cacheKey, agent);
|
|
101
|
-
}
|
|
102
|
-
return agent;
|
|
103
|
-
}
|
|
104
|
-
createAgent(proxyUrl, requiresTls) {
|
|
105
|
-
const protocol = proxyUrl.protocol.replace(':', '');
|
|
106
|
-
if (!this.isValidProtocol(protocol)) {
|
|
107
|
-
throw new core_1.ConfigurationError(`Unsupported protocol for proxy URL: ${proxyUrl}`);
|
|
108
|
-
}
|
|
109
|
-
const ctor = ProxyAgent.proxyAgents[protocol][requiresTls ? 1 : 0];
|
|
110
|
-
return new ctor(proxyUrl, this.agentOptions);
|
|
111
|
-
}
|
|
112
|
-
isValidProtocol(v) {
|
|
113
|
-
return protocols.includes(v);
|
|
114
|
-
}
|
|
115
|
-
destroy() {
|
|
116
|
-
this.cache.clear();
|
|
117
|
-
super.destroy();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.ProxyAgent = ProxyAgent;
|
|
121
|
-
//# sourceMappingURL=ProxyAgent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyAgent.js","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/ProxyAgent.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type * as http from 'http';
|
|
2
|
-
import type { AxiosRequestConfigDefaults } from '../AxiosRequestConfigDefaults';
|
|
3
|
-
/**
|
|
4
|
-
* @param options
|
|
5
|
-
*/
|
|
6
|
-
export declare function axiosProxyOverridesFor<Data = any>(options: AxiosRequestConfigDefaults<Data>): {
|
|
7
|
-
proxy: false;
|
|
8
|
-
httpAgent: http.Agent;
|
|
9
|
-
httpsAgent: http.Agent;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=axiosProxyOverridesFor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axiosProxyOverridesFor.d.ts","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/axiosProxyOverridesFor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAIhF;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,GAAG,GAAG,EAAE,OAAO,EAAE,0BAA0B,CAAC,IAAI,CAAC,GAAG;IAC3F,KAAK,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC;IAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAA;CAC9D,CA0BA"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.axiosProxyOverridesFor = axiosProxyOverridesFor;
|
|
4
|
-
const tiny_types_1 = require("tiny-types");
|
|
5
|
-
const createUrl_1 = require("./createUrl");
|
|
6
|
-
const ProxyAgent_1 = require("./ProxyAgent");
|
|
7
|
-
/**
|
|
8
|
-
* @param options
|
|
9
|
-
*/
|
|
10
|
-
function axiosProxyOverridesFor(options) {
|
|
11
|
-
const envProxyOverride = options.proxy
|
|
12
|
-
&& (0, createUrl_1.createUrl)({
|
|
13
|
-
username: options.proxy?.auth?.username,
|
|
14
|
-
password: options.proxy?.auth?.password,
|
|
15
|
-
protocol: options.proxy?.protocol,
|
|
16
|
-
hostname: (0, tiny_types_1.ensure)('proxy.host', options.proxy?.host, (0, tiny_types_1.isDefined)()),
|
|
17
|
-
port: options.proxy?.port
|
|
18
|
-
}).toString();
|
|
19
|
-
const agent = new ProxyAgent_1.ProxyAgent({
|
|
20
|
-
httpAgent: options.httpAgent,
|
|
21
|
-
httpsAgent: options.httpsAgent,
|
|
22
|
-
// if there's a specific proxy override configured, use it
|
|
23
|
-
// if not - detect proxy automatically based on env variables
|
|
24
|
-
getProxyForUrl: envProxyOverride
|
|
25
|
-
? (url_) => envProxyOverride
|
|
26
|
-
: undefined,
|
|
27
|
-
});
|
|
28
|
-
return {
|
|
29
|
-
proxy: false,
|
|
30
|
-
httpAgent: agent,
|
|
31
|
-
httpsAgent: agent,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=axiosProxyOverridesFor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axiosProxyOverridesFor.js","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/axiosProxyOverridesFor.ts"],"names":[],"mappings":";;AAUA,wDA4BC;AArCD,2CAA+C;AAG/C,2CAAwC;AACxC,6CAA0C;AAE1C;;GAEG;AACH,SAAgB,sBAAsB,CAAa,OAAyC;IAGxF,MAAM,gBAAgB,GAAmB,OAAO,CAAC,KAAK;WAC/C,IAAA,qBAAS,EAAC;YACT,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ;YACvC,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ;YACjC,QAAQ,EAAE,IAAA,mBAAM,EAAC,YAAY,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAA,sBAAS,GAAE,CAAC;YAChE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI;SAC5B,CAAC,CAAC,QAAQ,EAAE,CAAC;IAElB,MAAM,KAAK,GAAG,IAAI,uBAAU,CAAC;QACzB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;QAE9B,0DAA0D;QAC1D,6DAA6D;QAC7D,cAAc,EAAE,gBAAgB;YAC5B,CAAC,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,gBAAgB;YACpC,CAAC,CAAC,SAAS;KAClB,CAAC,CAAC;IAEH,OAAO;QACH,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,KAAK;KACpB,CAAC;AACN,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUrl.d.ts","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/createUrl.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,GAAG,CAYxD"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createUrl = createUrl;
|
|
4
|
-
const tiny_types_1 = require("tiny-types");
|
|
5
|
-
function createUrl(options) {
|
|
6
|
-
const hostname = (0, tiny_types_1.ensure)('hostname', options?.hostname, (0, tiny_types_1.isString)(), (0, tiny_types_1.isNotBlank)()).trim();
|
|
7
|
-
const port = options?.port
|
|
8
|
-
? ':' + options?.port
|
|
9
|
-
: (options?.protocol ? undefined : ':80');
|
|
10
|
-
return new URL([
|
|
11
|
-
options?.protocol && protocolFrom(options?.protocol),
|
|
12
|
-
(options?.username || options?.password) && credentialsFrom(options.username, options.password),
|
|
13
|
-
hostname,
|
|
14
|
-
port,
|
|
15
|
-
].filter(Boolean).join(''));
|
|
16
|
-
}
|
|
17
|
-
function protocolFrom(protocol) {
|
|
18
|
-
const protocolName = protocol.match(/([A-Za-z]+)[/:]*/)[1];
|
|
19
|
-
(0, tiny_types_1.ensure)('hostname', protocolName, (0, tiny_types_1.isDefined)());
|
|
20
|
-
return protocolName + '://';
|
|
21
|
-
}
|
|
22
|
-
function credentialsFrom(username, password) {
|
|
23
|
-
return [
|
|
24
|
-
username && encodeURIComponent(username),
|
|
25
|
-
password && ':' + encodeURIComponent(password),
|
|
26
|
-
'@'
|
|
27
|
-
].filter(Boolean).join('');
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=createUrl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUrl.js","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/createUrl.ts"],"names":[],"mappings":";;AAUA,8BAYC;AAtBD,2CAAqE;AAUrE,SAAgB,SAAS,CAAC,OAAyB;IAC/C,MAAM,QAAQ,GAAI,IAAA,mBAAM,EAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAA,qBAAQ,GAAE,EAAE,IAAA,uBAAU,GAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzF,MAAM,IAAI,GAAQ,OAAO,EAAE,IAAI;QAC3B,CAAC,CAAC,GAAG,GAAG,OAAO,EAAE,IAAI;QACrB,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAE9C,OAAO,IAAI,GAAG,CAAC;QACX,OAAO,EAAE,QAAQ,IAAI,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC;QACpD,CAAC,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC;QAC/F,QAAQ;QACR,IAAI;KACP,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,YAAY,CAAC,QAAiB;IACnC,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3D,IAAA,mBAAM,EAAC,UAAU,EAAE,YAAY,EAAE,IAAA,sBAAS,GAAE,CAAC,CAAC;IAE9C,OAAO,YAAY,GAAG,KAAK,CAAC;AAChC,CAAC;AAED,SAAS,eAAe,CAAC,QAAiB,EAAE,QAAiB;IACzD,OAAO;QACH,QAAQ,IAAI,kBAAkB,CAAC,QAAQ,CAAC;QACxC,QAAQ,IAAI,GAAG,GAAG,kBAAkB,CAAC,QAAQ,CAAC;QAC9C,GAAG;KACN,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./axiosProxyOverridesFor"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type * as http from 'http';
|
|
2
|
-
import { ensure, isDefined } from 'tiny-types';
|
|
3
|
-
|
|
4
|
-
import type { AxiosRequestConfigDefaults } from './AxiosRequestConfigDefaults';
|
|
5
|
-
import { createUrl } from './createUrl';
|
|
6
|
-
import { ProxyAgent } from './ProxyAgent';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
|
-
export function axiosProxyOverridesFor<Data = any>(options: AxiosRequestConfigDefaults<Data>): {
|
|
12
|
-
proxy: false, httpAgent: http.Agent, httpsAgent: http.Agent
|
|
13
|
-
} {
|
|
14
|
-
const envProxyOverride: string | false = options.proxy
|
|
15
|
-
&& createUrl({
|
|
16
|
-
username: options.proxy?.auth?.username,
|
|
17
|
-
password: options.proxy?.auth?.password,
|
|
18
|
-
protocol: options.proxy?.protocol,
|
|
19
|
-
hostname: ensure('proxy.host', options.proxy?.host, isDefined()),
|
|
20
|
-
port: options.proxy?.port ? Number(options.proxy?.port) : undefined,
|
|
21
|
-
}).toString();
|
|
22
|
-
|
|
23
|
-
const agent = new ProxyAgent({
|
|
24
|
-
httpAgent: options.httpAgent,
|
|
25
|
-
httpsAgent: options.httpsAgent,
|
|
26
|
-
|
|
27
|
-
// if there's a specific proxy override configured, use it
|
|
28
|
-
// if not - detect proxy automatically based on env variables
|
|
29
|
-
getProxyForUrl: envProxyOverride
|
|
30
|
-
? (url_: string) => envProxyOverride
|
|
31
|
-
: undefined,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
proxy: false,
|
|
36
|
-
httpAgent: agent,
|
|
37
|
-
httpsAgent: agent,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { ConfigurationError } from '@serenity-js/core';
|
|
2
|
-
import type { AgentConnectOpts } from 'agent-base';
|
|
3
|
-
import { Agent } from 'agent-base';
|
|
4
|
-
import * as http from 'http';
|
|
5
|
-
import { HttpProxyAgent, type HttpProxyAgentOptions } from 'http-proxy-agent';
|
|
6
|
-
import * as https from 'https';
|
|
7
|
-
import { HttpsProxyAgent, type HttpsProxyAgentOptions } from 'https-proxy-agent';
|
|
8
|
-
import { LRUCache } from 'lru-cache';
|
|
9
|
-
import { getProxyForUrl as envGetProxyForUrl } from 'proxy-from-env';
|
|
10
|
-
|
|
11
|
-
const protocols = [
|
|
12
|
-
...HttpProxyAgent.protocols,
|
|
13
|
-
] as const;
|
|
14
|
-
|
|
15
|
-
type AgentConstructor = new (proxy: URL | string, options?: ProxyAgentOptions) => Agent;
|
|
16
|
-
|
|
17
|
-
type ValidProtocol = (typeof protocols)[number];
|
|
18
|
-
|
|
19
|
-
type GetProxyForUrlCallback = (url: string) => string;
|
|
20
|
-
|
|
21
|
-
export type ProxyAgentOptions =
|
|
22
|
-
HttpProxyAgentOptions<''> &
|
|
23
|
-
HttpsProxyAgentOptions<''> & {
|
|
24
|
-
/**
|
|
25
|
-
* Default `http.Agent` instance to use when no proxy is
|
|
26
|
-
* configured for a request. Defaults to a new `http.Agent()`
|
|
27
|
-
* instance with the proxy agent options passed in.
|
|
28
|
-
*/
|
|
29
|
-
httpAgent?: http.Agent;
|
|
30
|
-
/**
|
|
31
|
-
* Default `http.Agent` instance to use when no proxy is
|
|
32
|
-
* configured for a request. Defaults to a new `https.Agent()`
|
|
33
|
-
* instance with the proxy agent options passed in.
|
|
34
|
-
*/
|
|
35
|
-
httpsAgent?: http.Agent;
|
|
36
|
-
/**
|
|
37
|
-
* A callback for dynamic provision of proxy for url.
|
|
38
|
-
* Defaults to standard proxy environment variables,
|
|
39
|
-
* see https://www.npmjs.com/package/proxy-from-env for details
|
|
40
|
-
*/
|
|
41
|
-
getProxyForUrl?: GetProxyForUrlCallback;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A simplified version of the original
|
|
46
|
-
* [`ProxyAgent`](https://github.com/TooTallNate/proxy-agents/blob/5923589c2e5206504772c250ac4f20fc31122d3b/packages/proxy-agent/src/index.ts)
|
|
47
|
-
* with fewer dependencies.
|
|
48
|
-
*
|
|
49
|
-
* Delegates requests to the appropriate `Agent` subclass based on the "proxy"
|
|
50
|
-
* environment variables, or the provided `agentOptions.getProxyForUrl` callback.
|
|
51
|
-
*
|
|
52
|
-
* Uses an LRU cache to prevent unnecessary creation of proxy `http.Agent` instances.
|
|
53
|
-
*/
|
|
54
|
-
export class ProxyAgent extends Agent {
|
|
55
|
-
|
|
56
|
-
private static proxyAgents: { [P in ValidProtocol]: [ AgentConstructor, AgentConstructor ] } = {
|
|
57
|
-
http: [ HttpProxyAgent, HttpsProxyAgent ],
|
|
58
|
-
https: [ HttpProxyAgent, HttpsProxyAgent ],
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Cache for `Agent` instances.
|
|
63
|
-
*/
|
|
64
|
-
private readonly cache = new LRUCache<string, Agent>({
|
|
65
|
-
max: 20,
|
|
66
|
-
dispose: (value: Agent, key: string) => value.destroy(),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
private readonly httpAgent: http.Agent;
|
|
70
|
-
private readonly httpsAgent: http.Agent;
|
|
71
|
-
private readonly getProxyForUrl: GetProxyForUrlCallback;
|
|
72
|
-
|
|
73
|
-
constructor(private readonly agentOptions: ProxyAgentOptions) {
|
|
74
|
-
super(agentOptions);
|
|
75
|
-
this.httpAgent = agentOptions?.httpAgent || new http.Agent(agentOptions);
|
|
76
|
-
this.httpsAgent = agentOptions?.httpsAgent || new https.Agent(agentOptions as https.AgentOptions);
|
|
77
|
-
this.getProxyForUrl = agentOptions?.getProxyForUrl || envGetProxyForUrl;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
override async connect(request: http.ClientRequest, options: AgentConnectOpts): Promise<http.Agent> {
|
|
81
|
-
const { secureEndpoint } = options;
|
|
82
|
-
const isWebSocket = request.getHeader('upgrade') === 'websocket';
|
|
83
|
-
const protocol = secureEndpoint
|
|
84
|
-
? (isWebSocket ? 'wss:' : 'https:')
|
|
85
|
-
: (isWebSocket ? 'ws:' : 'http:');
|
|
86
|
-
const host = request.getHeader('host');
|
|
87
|
-
const url = new URL(request.path, `${protocol}//${host}`).href;
|
|
88
|
-
const proxy = this.getProxyForUrl(url);
|
|
89
|
-
|
|
90
|
-
if (! proxy) {
|
|
91
|
-
return secureEndpoint
|
|
92
|
-
? this.httpsAgent
|
|
93
|
-
: this.httpAgent;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// attempt to get a cached `http.Agent` instance first
|
|
97
|
-
const cacheKey = `${ protocol }+${ proxy }`;
|
|
98
|
-
let agent = this.cache.get(cacheKey);
|
|
99
|
-
if (! agent) {
|
|
100
|
-
agent = this.createAgent(new URL(proxy), secureEndpoint || isWebSocket);
|
|
101
|
-
|
|
102
|
-
this.cache.set(cacheKey, agent);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return agent;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private createAgent(proxyUrl: URL, requiresTls: boolean): Agent {
|
|
109
|
-
|
|
110
|
-
const protocol = proxyUrl.protocol.replace(':', '');
|
|
111
|
-
|
|
112
|
-
if (! this.isValidProtocol(protocol)) {
|
|
113
|
-
throw new ConfigurationError(`Unsupported protocol for proxy URL: ${ proxyUrl }`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const ctor = ProxyAgent.proxyAgents[protocol][requiresTls ? 1 : 0];
|
|
117
|
-
|
|
118
|
-
return new ctor(proxyUrl, this.agentOptions);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private isValidProtocol(v: string): v is ValidProtocol {
|
|
122
|
-
return (protocols as readonly string[]).includes(v);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
override destroy(): void {
|
|
126
|
-
this.cache.clear();
|
|
127
|
-
super.destroy();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type * as http from 'http';
|
|
2
|
-
import { ensure, isDefined } from 'tiny-types';
|
|
3
|
-
|
|
4
|
-
import type { AxiosRequestConfigDefaults } from '../AxiosRequestConfigDefaults';
|
|
5
|
-
import { createUrl } from './createUrl';
|
|
6
|
-
import { ProxyAgent } from './ProxyAgent';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
|
-
export function axiosProxyOverridesFor<Data = any>(options: AxiosRequestConfigDefaults<Data>): {
|
|
12
|
-
proxy: false, httpAgent: http.Agent, httpsAgent: http.Agent
|
|
13
|
-
} {
|
|
14
|
-
const envProxyOverride: string | false = options.proxy
|
|
15
|
-
&& createUrl({
|
|
16
|
-
username: options.proxy?.auth?.username,
|
|
17
|
-
password: options.proxy?.auth?.password,
|
|
18
|
-
protocol: options.proxy?.protocol,
|
|
19
|
-
hostname: ensure('proxy.host', options.proxy?.host, isDefined()),
|
|
20
|
-
port: options.proxy?.port
|
|
21
|
-
}).toString();
|
|
22
|
-
|
|
23
|
-
const agent = new ProxyAgent({
|
|
24
|
-
httpAgent: options.httpAgent,
|
|
25
|
-
httpsAgent: options.httpsAgent,
|
|
26
|
-
|
|
27
|
-
// if there's a specific proxy override configured, use it
|
|
28
|
-
// if not - detect proxy automatically based on env variables
|
|
29
|
-
getProxyForUrl: envProxyOverride
|
|
30
|
-
? (url_: string) => envProxyOverride
|
|
31
|
-
: undefined,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
proxy: false,
|
|
36
|
-
httpAgent: agent,
|
|
37
|
-
httpsAgent: agent,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ensure, isDefined, isNotBlank, isString } from 'tiny-types';
|
|
2
|
-
|
|
3
|
-
export interface CreateUrlOptions {
|
|
4
|
-
protocol?: string;
|
|
5
|
-
hostname: string;
|
|
6
|
-
port?: string | number;
|
|
7
|
-
username?: string;
|
|
8
|
-
password?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function createUrl(options: CreateUrlOptions): URL {
|
|
12
|
-
const hostname = ensure('hostname', options?.hostname, isString(), isNotBlank()).trim();
|
|
13
|
-
const port = options?.port
|
|
14
|
-
? ':' + options?.port
|
|
15
|
-
: (options?.protocol ? undefined : ':80');
|
|
16
|
-
|
|
17
|
-
return new URL([
|
|
18
|
-
options?.protocol && protocolFrom(options?.protocol),
|
|
19
|
-
(options?.username || options?.password) && credentialsFrom(options.username, options.password),
|
|
20
|
-
hostname,
|
|
21
|
-
port,
|
|
22
|
-
].filter(Boolean).join(''));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function protocolFrom(protocol?: string): string {
|
|
26
|
-
const protocolName = protocol.match(/([A-Za-z]+)[/:]*/)[1];
|
|
27
|
-
|
|
28
|
-
ensure('hostname', protocolName, isDefined());
|
|
29
|
-
|
|
30
|
-
return protocolName + '://';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function credentialsFrom(username?: string, password?: string): string {
|
|
34
|
-
return [
|
|
35
|
-
username && encodeURIComponent(username),
|
|
36
|
-
password && ':' + encodeURIComponent(password),
|
|
37
|
-
'@'
|
|
38
|
-
].filter(Boolean).join('');
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './axiosProxyOverridesFor';
|