@modelriver/cli 1.2.0 → 1.2.1
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/package.json
CHANGED
package/src/utils/url-helpers.js
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
function normalizeWebhookUrl(url) {
|
|
11
11
|
if (!url) return url;
|
|
12
12
|
|
|
13
|
+
// Ensure protocol
|
|
14
|
+
if (!url.match(/^https?:\/\//)) {
|
|
15
|
+
url = 'http://' + url;
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
try {
|
|
14
19
|
const urlObj = new URL(url);
|
|
15
20
|
let pathname = urlObj.pathname;
|
|
@@ -98,6 +103,12 @@ function isValidApiKeyFormat(apiKey) {
|
|
|
98
103
|
*/
|
|
99
104
|
function parseForwardUrl(url) {
|
|
100
105
|
if (!url) return null;
|
|
106
|
+
|
|
107
|
+
// Ensure protocol
|
|
108
|
+
if (!url.match(/^https?:\/\//)) {
|
|
109
|
+
url = 'http://' + url;
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
try {
|
|
102
113
|
const urlObj = new URL(url);
|
|
103
114
|
return {
|
|
@@ -126,9 +126,19 @@ describe('URL Helpers', () => {
|
|
|
126
126
|
expect(parseForwardUrl(undefined)).toBeNull();
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
it('should handle URLs without protocol by defaulting to http', () => {
|
|
130
|
+
const result = parseForwardUrl('myserver:4000/webhook/modelriver');
|
|
131
|
+
expect(result).toEqual({
|
|
132
|
+
hostname: 'myserver',
|
|
133
|
+
port: 4000,
|
|
134
|
+
path: '/webhook/modelriver',
|
|
135
|
+
protocol: 'http'
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
129
139
|
it('should return null for invalid URLs', () => {
|
|
130
|
-
expect(parseForwardUrl('
|
|
131
|
-
expect(parseForwardUrl('just
|
|
140
|
+
expect(parseForwardUrl('http://invalid url with spaces')).toBeNull();
|
|
141
|
+
expect(parseForwardUrl('just text with spaces')).toBeNull();
|
|
132
142
|
});
|
|
133
143
|
});
|
|
134
144
|
});
|