@mintlify/scraping 4.0.155 → 4.0.156

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/scraping",
3
- "version": "4.0.155",
3
+ "version": "4.0.156",
4
4
  "description": "Scrape documentation frameworks to Mintlify docs",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -38,7 +38,7 @@
38
38
  "format:check": "prettier . --check"
39
39
  },
40
40
  "dependencies": {
41
- "@mintlify/common": "1.0.306",
41
+ "@mintlify/common": "1.0.307",
42
42
  "@mintlify/openapi-parser": "^0.0.7",
43
43
  "fs-extra": "^11.1.1",
44
44
  "hast-util-to-mdast": "^10.1.0",
@@ -78,5 +78,5 @@
78
78
  "typescript": "^5.5.3",
79
79
  "vitest": "^2.0.4"
80
80
  },
81
- "gitHead": "29edb9ff3597e617bc8e950720ad9b34e55467bf"
81
+ "gitHead": "68bb960973656dafb657d93f1909bdcbe04115e8"
82
82
  }
@@ -0,0 +1,35 @@
1
+ import { AsyncAPISchema } from '@mintlify/common/asyncapi';
2
+ import * as fs from 'fs/promises';
3
+ import yaml from 'js-yaml';
4
+ import * as path from 'path';
5
+
6
+ import { fetchAsyncApi } from '../utils/network.js';
7
+
8
+ export const getAsyncApiDefinition = async (
9
+ pathOrDocumentOrUrl: string | AsyncAPISchema | URL
10
+ ): Promise<{ document: AsyncAPISchema; isUrl: boolean }> => {
11
+ if (typeof pathOrDocumentOrUrl === 'string') {
12
+ if (pathOrDocumentOrUrl.startsWith('http://')) {
13
+ // This is an invalid location either for a file or a URL
14
+ throw new Error('Only HTTPS URLs are supported. Please provide an HTTPS URL');
15
+ } else {
16
+ try {
17
+ const url = new URL(pathOrDocumentOrUrl);
18
+ pathOrDocumentOrUrl = url;
19
+ } catch {
20
+ const pathname = path.join(process.cwd(), pathOrDocumentOrUrl.toString());
21
+ const file = await fs.readFile(pathname, 'utf-8');
22
+ pathOrDocumentOrUrl = yaml.load(file) as AsyncAPISchema;
23
+ }
24
+ }
25
+ }
26
+ const isUrl = pathOrDocumentOrUrl instanceof URL;
27
+ if (pathOrDocumentOrUrl instanceof URL) {
28
+ if (pathOrDocumentOrUrl.protocol !== 'https:') {
29
+ throw new Error('Only HTTPS URLs are supported. Please provide an HTTPS URL');
30
+ }
31
+ pathOrDocumentOrUrl = await fetchAsyncApi(pathOrDocumentOrUrl);
32
+ }
33
+
34
+ return { document: pathOrDocumentOrUrl, isUrl };
35
+ };