@scalar/import 0.2.24 → 0.2.26
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 +19 -0
- package/dist/index.js +1 -1
- package/dist/resolve.d.ts +12 -0
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +55 -12
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @scalar/import
|
|
2
2
|
|
|
3
|
+
## 0.2.26
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [ed92564]
|
|
8
|
+
- @scalar/oas-utils@0.2.106
|
|
9
|
+
|
|
10
|
+
## 0.2.25
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 54fdfcb: chore: remove spec wording
|
|
15
|
+
- fa6afe8: chore: code formatting
|
|
16
|
+
- 4d30a35: fix: can’t parse HTML attributes with HTML tags inside
|
|
17
|
+
- Updated dependencies [54fdfcb]
|
|
18
|
+
- Updated dependencies [1223c1f]
|
|
19
|
+
- @scalar/oas-utils@0.2.105
|
|
20
|
+
- @scalar/openapi-parser@0.10.7
|
|
21
|
+
|
|
3
22
|
## 0.2.24
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { resolve } from './resolve.js';
|
|
1
|
+
export { getConfigurationAttribute, getContentOfScriptTag, resolve } from './resolve.js';
|
package/dist/resolve.d.ts
CHANGED
|
@@ -8,4 +8,16 @@ export declare function resolve(value?: string | null, options?: {
|
|
|
8
8
|
*/
|
|
9
9
|
fetch?: (url: string) => Promise<Response>;
|
|
10
10
|
}): Promise<string | Record<string, any> | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the content between the script tags
|
|
13
|
+
*
|
|
14
|
+
* @example <script id="api-reference">console.log("Hello, world!");</script>
|
|
15
|
+
*/
|
|
16
|
+
export declare function getContentOfScriptTag(html: string): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Get the configuration attribute from the script tag
|
|
19
|
+
*
|
|
20
|
+
* @example <script id="api-reference" data-configuration="{"spec":{"content":"foo"}}"></script>
|
|
21
|
+
*/
|
|
22
|
+
export declare function getConfigurationAttribute(html: string): string | undefined;
|
|
11
23
|
//# 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,CA+GnD;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,CAiB1E"}
|
package/dist/resolve.js
CHANGED
|
@@ -18,8 +18,7 @@ async function resolve(value, options) {
|
|
|
18
18
|
return value;
|
|
19
19
|
}
|
|
20
20
|
// https://*.yaml
|
|
21
|
-
if (value?.toLowerCase().endsWith('.yaml') ||
|
|
22
|
-
value?.toLowerCase().endsWith('.yml')) {
|
|
21
|
+
if (value?.toLowerCase().endsWith('.yaml') || value?.toLowerCase().endsWith('.yml')) {
|
|
23
22
|
return value;
|
|
24
23
|
}
|
|
25
24
|
// https://sandbox.scalar.com
|
|
@@ -166,21 +165,46 @@ function parseHtml(html) {
|
|
|
166
165
|
}
|
|
167
166
|
return undefined;
|
|
168
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Get the content between the script tags
|
|
170
|
+
*
|
|
171
|
+
* @example <script id="api-reference">console.log("Hello, world!");</script>
|
|
172
|
+
*/
|
|
173
|
+
function getContentOfScriptTag(html) {
|
|
174
|
+
const patterns = [
|
|
175
|
+
// Double quotes
|
|
176
|
+
/<script[^>]*id="api-reference[\s\S]*?">([\s\S]*?)<\/script>/i,
|
|
177
|
+
// Single quotes
|
|
178
|
+
/<script[^>]*id='api-reference[\s\S]*?'>([\s\S]*?)<\/script>/i,
|
|
179
|
+
];
|
|
180
|
+
for (const pattern of patterns) {
|
|
181
|
+
const match = html.match(pattern);
|
|
182
|
+
if (match?.[1])
|
|
183
|
+
return match[1].trim();
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
169
187
|
/**
|
|
170
188
|
* Parse OpenAPI document directly from script tag content
|
|
171
189
|
*/
|
|
172
190
|
function parseScriptContent(html) {
|
|
173
|
-
const
|
|
174
|
-
if (!match?.[1])
|
|
175
|
-
return undefined;
|
|
191
|
+
const content = getContentOfScriptTag(html);
|
|
176
192
|
try {
|
|
177
|
-
const content = match[1].trim();
|
|
178
193
|
if (content) {
|
|
179
194
|
try {
|
|
195
|
+
// JSON
|
|
180
196
|
return JSON.parse(content);
|
|
181
197
|
}
|
|
182
198
|
catch {
|
|
183
|
-
|
|
199
|
+
try {
|
|
200
|
+
// JSON with escaped whitespace
|
|
201
|
+
const sanitizedContent = content.replace(/\\s/g, '\\\\s');
|
|
202
|
+
return JSON.parse(sanitizedContent);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// YAML
|
|
206
|
+
return parse(content);
|
|
207
|
+
}
|
|
184
208
|
}
|
|
185
209
|
}
|
|
186
210
|
}
|
|
@@ -189,16 +213,35 @@ function parseScriptContent(html) {
|
|
|
189
213
|
}
|
|
190
214
|
return undefined;
|
|
191
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Get the configuration attribute from the script tag
|
|
218
|
+
*
|
|
219
|
+
* @example <script id="api-reference" data-configuration="{"spec":{"content":"foo"}}"></script>
|
|
220
|
+
*/
|
|
221
|
+
function getConfigurationAttribute(html) {
|
|
222
|
+
const patterns = [
|
|
223
|
+
// Double quotes
|
|
224
|
+
/<script[^>]*id="api-reference"[^>]*data-configuration=["]([^"]+)["][^>]*>(.*?)<\/script>/s,
|
|
225
|
+
// Single quotes
|
|
226
|
+
/<script[^>]*id='api-reference'[^>]*data-configuration=[']([^']+)['][^>]*>(.*?)<\/script>/s,
|
|
227
|
+
];
|
|
228
|
+
for (const pattern of patterns) {
|
|
229
|
+
const match = html.match(pattern);
|
|
230
|
+
if (match?.[1]) {
|
|
231
|
+
return match[1];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
192
236
|
/**
|
|
193
237
|
* Parse embedded OpenAPI document from HTML
|
|
194
238
|
*/
|
|
195
239
|
function parseEmbeddedOpenApi(html) {
|
|
196
|
-
const
|
|
197
|
-
if (!
|
|
240
|
+
const configString = getConfigurationAttribute(html);
|
|
241
|
+
if (!configString)
|
|
198
242
|
return undefined;
|
|
199
243
|
try {
|
|
200
|
-
const
|
|
201
|
-
const config = JSON.parse(configString);
|
|
244
|
+
const config = JSON.parse(decodeHtmlEntities(configString));
|
|
202
245
|
// Handle both direct JSON content and YAML content
|
|
203
246
|
if (config.spec?.content) {
|
|
204
247
|
// If content is a string, assume it's YAML
|
|
@@ -248,4 +291,4 @@ function transformGitHubUrl(url) {
|
|
|
248
291
|
return undefined;
|
|
249
292
|
}
|
|
250
293
|
|
|
251
|
-
export { resolve };
|
|
294
|
+
export { getConfigurationAttribute, getContentOfScriptTag, resolve };
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"postman",
|
|
17
17
|
"scalar"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.26",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -36,16 +36,18 @@
|
|
|
36
36
|
"module": "dist/index.js",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"yaml": "^2.4.5",
|
|
39
|
-
"@scalar/oas-utils": "0.2.
|
|
40
|
-
"@scalar/openapi-parser": "0.10.
|
|
39
|
+
"@scalar/oas-utils": "0.2.106",
|
|
40
|
+
"@scalar/openapi-parser": "0.10.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"vite": "^5.4.10",
|
|
44
|
-
"@scalar/build-tooling": "0.1.
|
|
44
|
+
"@scalar/build-tooling": "0.1.13"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "scalar-build-rollup",
|
|
48
48
|
"dev": "nodemon --exec \"vite-node playground/index.ts\" --ext ts --quiet",
|
|
49
|
+
"format": "scalar-format",
|
|
50
|
+
"format:check": "scalar-format-check",
|
|
49
51
|
"lint:check": "eslint .",
|
|
50
52
|
"lint:fix": "eslint . --fix",
|
|
51
53
|
"test": "vitest",
|