@scalar/import 0.0.6 → 0.1.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @scalar/import
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c98a99c: feat: use X-Forwarded-Host header (if available)
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [4bcaa75]
12
+ - Updated dependencies [9eb6650]
13
+ - Updated dependencies [c98a99c]
14
+ - @scalar/oas-utils@0.2.72
15
+
3
16
  ## 0.0.6
4
17
 
5
18
  ### 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,CAuHnD"}
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,8 @@ 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');
46
+ console.log('ASAS', forwardedHost);
44
47
  // Check if content is directly JSON/YAML
45
48
  try {
46
49
  // Try parsing as JSON
@@ -88,7 +91,8 @@ async function resolve(value, options) {
88
91
  }
89
92
  // Relative or absolute URL
90
93
  if (urlOrPathOrDocument) {
91
- return makeRelativeUrlsAbsolute(value, urlOrPathOrDocument);
94
+ console.log('make absolute', forwardedHost, urlOrPathOrDocument);
95
+ return makeUrlAbsolute(urlOrPathOrDocument, forwardedHost || value);
92
96
  }
93
97
  // Check for embedded OpenAPI document
94
98
  const embeddedSpec = parseEmbeddedOpenApi(content);
@@ -187,25 +191,6 @@ function parseScriptContent(html) {
187
191
  }
188
192
  return undefined;
189
193
  }
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
194
  /**
210
195
  * Parse embedded OpenAPI document from HTML
211
196
  */
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "postman",
17
17
  "scalar"
18
18
  ],
19
- "version": "0.0.6",
19
+ "version": "0.1.0",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -36,7 +36,8 @@
36
36
  "module": "dist/index.js",
37
37
  "dependencies": {
38
38
  "yaml": "^2.4.5",
39
- "@scalar/openapi-parser": "0.8.9"
39
+ "@scalar/openapi-parser": "0.8.9",
40
+ "@scalar/oas-utils": "0.2.72"
40
41
  },
41
42
  "devDependencies": {
42
43
  "vite": "^5.4.9",