@openfn/language-http 3.1.12 → 3.2.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/lib/Utils.js +13 -0
- package/package.json +1 -1
package/lib/Utils.js
CHANGED
|
@@ -19,10 +19,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
19
|
|
|
20
20
|
function setUrl(configuration, path) {
|
|
21
21
|
const baseUrl = configuration === null || configuration === void 0 ? void 0 : configuration.baseUrl;
|
|
22
|
+
if (isValidHttpUrl(path)) return path;
|
|
22
23
|
if (baseUrl) return `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\/+/g, '')}`;
|
|
23
24
|
return path;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
function isValidHttpUrl(string) {
|
|
28
|
+
let url;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
url = new URL(string);
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
function setAuth(configuration, manualAuth) {
|
|
27
40
|
if (manualAuth) return manualAuth;else if (configuration && configuration.username) return {
|
|
28
41
|
username: configuration.username,
|