@scalar/import 0.2.35 → 0.3.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 +27 -0
- package/dist/index.js +1 -1
- package/dist/resolve.d.ts +2 -0
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +24 -5
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @scalar/import
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5f9a8a2: feat!: remove the spec prefix, make content and url top-level attributes
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 14c5d22: fix: getting configuration for galaxy example
|
|
12
|
+
- @scalar/oas-utils@0.2.118
|
|
13
|
+
- @scalar/openapi-parser@0.10.10
|
|
14
|
+
|
|
15
|
+
## 0.2.37
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- @scalar/oas-utils@0.2.117
|
|
20
|
+
- @scalar/openapi-parser@0.10.10
|
|
21
|
+
|
|
22
|
+
## 0.2.36
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [ab98841]
|
|
27
|
+
- Updated dependencies [db9ebbc]
|
|
28
|
+
- @scalar/oas-utils@0.2.116
|
|
29
|
+
|
|
3
30
|
## 0.2.35
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getConfigurationAttribute, getContentOfScriptTag, resolve } from './resolve.js';
|
|
1
|
+
export { getConfigurationAttribute, getConfigurationAttributeUrl, getContentOfScriptTag, resolve } from './resolve.js';
|
package/dist/resolve.d.ts
CHANGED
|
@@ -20,4 +20,6 @@ export declare function getContentOfScriptTag(html: string): string | undefined;
|
|
|
20
20
|
* @example <script id="api-reference" data-configuration="{"spec":{"content":"foo"}}"></script>
|
|
21
21
|
*/
|
|
22
22
|
export declare function getConfigurationAttribute(html: string): string | undefined;
|
|
23
|
+
/** Grab the URL from the configuration data attribute */
|
|
24
|
+
export declare const getConfigurationAttributeUrl: (html: string) => string | undefined;
|
|
23
25
|
//# sourceMappingURL=resolve.d.ts.map
|
package/dist/resolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAqHnD;AA6ED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAetE;AAgCD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAqB1E;AAED,yDAAyD;AACzD,eAAO,MAAM,4BAA4B,SAAU,MAAM,KAAG,MAAM,GAAG,SAMpE,CAAA"}
|
package/dist/resolve.js
CHANGED
|
@@ -91,6 +91,11 @@ async function resolve(value, options) {
|
|
|
91
91
|
if (urlOrPathOrDocument) {
|
|
92
92
|
return makeUrlAbsolute(urlOrPathOrDocument, forwardedHost || value);
|
|
93
93
|
}
|
|
94
|
+
// Check for configuration attribute URL
|
|
95
|
+
const configUrl = getConfigurationAttributeUrl(content);
|
|
96
|
+
if (configUrl) {
|
|
97
|
+
return makeUrlAbsolute(configUrl, forwardedHost || value);
|
|
98
|
+
}
|
|
94
99
|
// Check for embedded OpenAPI document
|
|
95
100
|
const embeddedSpec = parseEmbeddedOpenApi(content);
|
|
96
101
|
if (embeddedSpec) {
|
|
@@ -224,6 +229,10 @@ function getConfigurationAttribute(html) {
|
|
|
224
229
|
/<script[^>]*id="api-reference"[^>]*data-configuration=["]([^"]+)["][^>]*>(.*?)<\/script>/s,
|
|
225
230
|
// Single quotes
|
|
226
231
|
/<script[^>]*id='api-reference'[^>]*data-configuration=[']([^']+)['][^>]*>(.*?)<\/script>/s,
|
|
232
|
+
// Mix quote single first
|
|
233
|
+
/<script[^>]*id='api-reference'[^>]*data-configuration=["]([^"]+)["][^>]*>(.*?)<\/script>/s,
|
|
234
|
+
// Mix quote double first
|
|
235
|
+
/<script[^>]*id="api-reference"[^>]*data-configuration=[']([^']+)['][^>]*>(.*?)<\/script>/s,
|
|
227
236
|
];
|
|
228
237
|
for (const pattern of patterns) {
|
|
229
238
|
const match = html.match(pattern);
|
|
@@ -233,6 +242,14 @@ function getConfigurationAttribute(html) {
|
|
|
233
242
|
}
|
|
234
243
|
return undefined;
|
|
235
244
|
}
|
|
245
|
+
/** Grab the URL from the configuration data attribute */
|
|
246
|
+
const getConfigurationAttributeUrl = (html) => {
|
|
247
|
+
const configString = getConfigurationAttribute(html);
|
|
248
|
+
if (!configString)
|
|
249
|
+
return undefined;
|
|
250
|
+
const config = JSON.parse(decodeHtmlEntities(configString));
|
|
251
|
+
return config.url || config.spec?.url;
|
|
252
|
+
};
|
|
236
253
|
/**
|
|
237
254
|
* Parse embedded OpenAPI document from HTML
|
|
238
255
|
*/
|
|
@@ -242,14 +259,16 @@ function parseEmbeddedOpenApi(html) {
|
|
|
242
259
|
return undefined;
|
|
243
260
|
try {
|
|
244
261
|
const config = JSON.parse(decodeHtmlEntities(configString));
|
|
262
|
+
// Handle the old spec format while we transition to the new one
|
|
263
|
+
const content = config.content || config.spec?.content;
|
|
245
264
|
// Handle both direct JSON content and YAML content
|
|
246
|
-
if (
|
|
265
|
+
if (content) {
|
|
247
266
|
// If content is a string, assume it's YAML
|
|
248
|
-
if (typeof
|
|
249
|
-
return parse(
|
|
267
|
+
if (typeof content === 'string') {
|
|
268
|
+
return parse(content);
|
|
250
269
|
}
|
|
251
270
|
// If content is an object, return it directly
|
|
252
|
-
return
|
|
271
|
+
return content;
|
|
253
272
|
}
|
|
254
273
|
}
|
|
255
274
|
catch (error) {
|
|
@@ -291,4 +310,4 @@ function transformGitHubUrl(url) {
|
|
|
291
310
|
return undefined;
|
|
292
311
|
}
|
|
293
312
|
|
|
294
|
-
export { getConfigurationAttribute, getContentOfScriptTag, resolve };
|
|
313
|
+
export { getConfigurationAttribute, getConfigurationAttributeUrl, getContentOfScriptTag, resolve };
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"postman",
|
|
17
17
|
"scalar"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.3.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"module": "dist/index.js",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"yaml": "^2.4.5",
|
|
39
|
-
"@scalar/
|
|
40
|
-
"@scalar/
|
|
39
|
+
"@scalar/openapi-parser": "0.10.10",
|
|
40
|
+
"@scalar/oas-utils": "0.2.118"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"vite": "^5.4.10",
|