@scalar/import 0.1.2 → 0.2.2

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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # @scalar/import
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [9b4f85d]
8
+ - @scalar/oas-utils@0.2.84
9
+
10
+ ## 0.2.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [f524411]
15
+ - Updated dependencies [10c9016]
16
+ - Updated dependencies [b11294c]
17
+ - @scalar/oas-utils@0.2.83
18
+
19
+ ## 0.2.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 6389557: feat: use X-Forwarded-Host header (if available)
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [6389557]
28
+ - @scalar/oas-utils@0.2.82
29
+
3
30
  ## 0.1.2
4
31
 
5
32
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE;IACR;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,GACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,CAmHnD"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE;IACR;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,GACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,CAoHnD"}
package/dist/resolve.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { makeUrlAbsolute } from '@scalar/oas-utils/helpers';
1
2
  import { parse } from 'yaml';
2
3
 
3
4
  /**
@@ -41,6 +42,7 @@ async function resolve(value, options) {
41
42
  }
42
43
  if (result.ok) {
43
44
  const content = await result.text();
45
+ const forwardedHost = result.headers.get('X-Forwarded-Host');
44
46
  // Check if content is directly JSON/YAML
45
47
  try {
46
48
  // Try parsing as JSON
@@ -88,7 +90,7 @@ async function resolve(value, options) {
88
90
  }
89
91
  // Relative or absolute URL
90
92
  if (urlOrPathOrDocument) {
91
- return makeRelativeUrlsAbsolute(value, urlOrPathOrDocument);
93
+ return makeUrlAbsolute(urlOrPathOrDocument, forwardedHost || value);
92
94
  }
93
95
  // Check for embedded OpenAPI document
94
96
  const embeddedSpec = parseEmbeddedOpenApi(content);
@@ -187,25 +189,6 @@ function parseScriptContent(html) {
187
189
  }
188
190
  return undefined;
189
191
  }
190
- /**
191
- * URLs can be relative, but we need absolute URLs eventually.
192
- */
193
- function makeRelativeUrlsAbsolute(baseUrl, path) {
194
- // Check whether the path is already absolute
195
- if (path.startsWith('http://') || path.startsWith('https://')) {
196
- return path;
197
- }
198
- // Combine the URL and the relative path
199
- try {
200
- const { href } = new URL(path, baseUrl);
201
- return href;
202
- }
203
- catch (error) {
204
- // Return original path if URL creation fails
205
- console.error('[makeRelativeUrlsAbsolute] Error combining URLs:', error);
206
- return path;
207
- }
208
- }
209
192
  /**
210
193
  * Parse embedded OpenAPI document from HTML
211
194
  */
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "postman",
17
17
  "scalar"
18
18
  ],
19
- "version": "0.1.2",
19
+ "version": "0.2.2",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -36,6 +36,7 @@
36
36
  "module": "dist/index.js",
37
37
  "dependencies": {
38
38
  "yaml": "^2.4.5",
39
+ "@scalar/oas-utils": "0.2.84",
39
40
  "@scalar/openapi-parser": "0.8.10"
40
41
  },
41
42
  "devDependencies": {