@fumadocs/api-docs 0.0.3 → 0.0.4
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/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +2 -2
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +1 -1
- package/dist/ref-parser/bundle.d.ts +10 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/bundle.js +76 -6
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/normalize-args.js +1 -1
- package/dist/ref-parser/options.d.ts +28 -0
- package/dist/ref-parser/options.js +27 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/parse.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/parsers/json.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/parsers/yaml.js +6 -12
- package/dist/ref-parser/pointer.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/pointer.js +16 -54
- package/dist/ref-parser/ref.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/ref.js +6 -48
- package/dist/ref-parser/refs.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/refs.js +4 -41
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/resolve-external.js +3 -3
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/resolvers/file.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/types/index.d.ts +8 -40
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/convert-path-to-posix.js +1 -1
- package/dist/ref-parser/util/errors.d.ts +1 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/errors.js +16 -34
- package/dist/ref-parser/util/is-windows.js +5 -0
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/maybe.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/next.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/plugins.js +1 -1
- package/dist/{node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib → ref-parser}/util/schema-resources.js +1 -1
- package/dist/ref-parser/util/url.js +206 -0
- package/dist/schema/bundle.d.ts +1 -1
- package/dist/schema/bundle.js +1 -1
- package/dist/schema/ref.d.ts +3 -1
- package/dist/schema/ref.js +1 -1
- package/dist/schema/sample.js +5 -7
- package/dist/utils/cn.js +1 -1
- package/dist/utils/deep-merge.js +8 -0
- package/package.json +8 -10
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/dereference.js +0 -187
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/index.d.ts +0 -157
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/index.js +0 -136
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/options.d.ts +0 -166
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/options.js +0 -124
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/binary.js +0 -30
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/parsers/text.js +0 -36
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/pointer.d.ts +0 -96
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/ref.d.ts +0 -190
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/refs.d.ts +0 -134
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js +0 -121
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/errors.d.ts +0 -34
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/is-windows.js +0 -5
- package/dist/node_modules/.pnpm/@apidevtools_json-schema-ref-parser@15.3.6_@types_json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/url.js +0 -381
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { isHttp, isUnsafeUrl, parse, resolve } from "../util/url.js";
|
|
2
|
-
import { ResolverError } from "../util/errors.js";
|
|
3
|
-
//#region ../../node_modules/.pnpm/@apidevtools+json-schema-ref-parser@15.3.6_@types+json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js
|
|
4
|
-
var http_default = {
|
|
5
|
-
/**
|
|
6
|
-
* The order that this resolver will run, in relation to other resolvers.
|
|
7
|
-
*/
|
|
8
|
-
order: 200,
|
|
9
|
-
/**
|
|
10
|
-
* HTTP headers to send when downloading files.
|
|
11
|
-
*
|
|
12
|
-
* @example:
|
|
13
|
-
* {
|
|
14
|
-
* "User-Agent": "JSON Schema $Ref Parser",
|
|
15
|
-
* Accept: "application/json"
|
|
16
|
-
* }
|
|
17
|
-
*/
|
|
18
|
-
headers: null,
|
|
19
|
-
/**
|
|
20
|
-
* HTTP request timeout (in milliseconds).
|
|
21
|
-
*/
|
|
22
|
-
timeout: 6e4,
|
|
23
|
-
/**
|
|
24
|
-
* The maximum number of HTTP redirects to follow.
|
|
25
|
-
* To disable automatic following of redirects, set this to zero.
|
|
26
|
-
*/
|
|
27
|
-
redirects: 5,
|
|
28
|
-
/**
|
|
29
|
-
* The `withCredentials` option of XMLHttpRequest.
|
|
30
|
-
* Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
|
|
31
|
-
*/
|
|
32
|
-
withCredentials: false,
|
|
33
|
-
/**
|
|
34
|
-
* Set this to `false` if you want to allow unsafe URLs (e.g., `127.0.0.1`, localhost, and other internal URLs).
|
|
35
|
-
*/
|
|
36
|
-
safeUrlResolver: true,
|
|
37
|
-
/**
|
|
38
|
-
* Determines whether this resolver can read a given file reference.
|
|
39
|
-
* Resolvers that return true will be tried in order, until one successfully resolves the file.
|
|
40
|
-
* Resolvers that return false will not be given a chance to resolve the file.
|
|
41
|
-
*/
|
|
42
|
-
canRead(file) {
|
|
43
|
-
return isHttp(file.url) && (!this.safeUrlResolver || !isUnsafeUrl(file.url));
|
|
44
|
-
},
|
|
45
|
-
/**
|
|
46
|
-
* Reads the given URL and returns its raw contents as a Buffer.
|
|
47
|
-
*/
|
|
48
|
-
read(file) {
|
|
49
|
-
const u = parse(file.url);
|
|
50
|
-
if (typeof window !== "undefined" && !u.protocol) u.protocol = parse(location.href).protocol;
|
|
51
|
-
return download(u, this);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Downloads the given file.
|
|
56
|
-
* @returns
|
|
57
|
-
* The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.
|
|
58
|
-
*/
|
|
59
|
-
async function download(u, httpOptions, _redirects) {
|
|
60
|
-
u = parse(u);
|
|
61
|
-
const redirects = _redirects || [];
|
|
62
|
-
redirects.push(u.href);
|
|
63
|
-
try {
|
|
64
|
-
if (httpOptions.safeUrlResolver && isUnsafeUrl(u.href)) throw new Error(`Unsafe URL blocked by safeUrlResolver: ${u.href}`);
|
|
65
|
-
const res = await get(u, httpOptions);
|
|
66
|
-
if (res.status >= 400) {
|
|
67
|
-
const error = /* @__PURE__ */ new Error(`HTTP ERROR ${res.status}`);
|
|
68
|
-
error.status = res.status;
|
|
69
|
-
throw error;
|
|
70
|
-
} else if (res.status >= 300) if (!Number.isNaN(httpOptions.redirects) && redirects.length > httpOptions.redirects) {
|
|
71
|
-
const error = /* @__PURE__ */ new Error(`Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`);
|
|
72
|
-
error.status = res.status;
|
|
73
|
-
throw new ResolverError(error);
|
|
74
|
-
} else {
|
|
75
|
-
const location = getHeader(res, "location");
|
|
76
|
-
if (!location) {
|
|
77
|
-
const error = /* @__PURE__ */ new Error(`HTTP ${res.status} redirect with no location header`);
|
|
78
|
-
error.status = res.status;
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
return download(resolve(u.href, location), httpOptions, redirects);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
if (res.body) {
|
|
85
|
-
const buf = await res.arrayBuffer();
|
|
86
|
-
return Buffer.from(buf);
|
|
87
|
-
}
|
|
88
|
-
return Buffer.alloc(0);
|
|
89
|
-
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
const e = err;
|
|
92
|
-
e.message = `Error downloading ${u.href}: ${e.message}`;
|
|
93
|
-
throw new ResolverError(e, u.href);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Sends an HTTP GET request.
|
|
98
|
-
* The promise resolves with the HTTP Response object.
|
|
99
|
-
*/
|
|
100
|
-
async function get(u, httpOptions) {
|
|
101
|
-
let controller;
|
|
102
|
-
let timeoutId;
|
|
103
|
-
if (httpOptions.timeout && typeof AbortController !== "undefined") {
|
|
104
|
-
controller = new AbortController();
|
|
105
|
-
timeoutId = setTimeout(() => controller.abort(), httpOptions.timeout);
|
|
106
|
-
}
|
|
107
|
-
const response = await fetch(u, {
|
|
108
|
-
method: "GET",
|
|
109
|
-
headers: httpOptions.headers || {},
|
|
110
|
-
credentials: httpOptions.withCredentials ? "include" : "same-origin",
|
|
111
|
-
redirect: "manual",
|
|
112
|
-
signal: controller ? controller.signal : null
|
|
113
|
-
});
|
|
114
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
115
|
-
return response;
|
|
116
|
-
}
|
|
117
|
-
function getHeader(response, name) {
|
|
118
|
-
return response.headers.get(name);
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { http_default as default };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@apidevtools+json-schema-ref-parser@15.3.6_@types+json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/errors.d.ts
|
|
2
|
-
type JSONParserErrorType = "EUNKNOWN" | "EPARSER" | "EUNMATCHEDPARSER" | "ETIMEOUT" | "ERESOLVER" | "EUNMATCHEDRESOLVER" | "EMISSINGPOINTER" | "EINVALIDPOINTER";
|
|
3
|
-
declare class JSONParserError extends Error {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
readonly message: string;
|
|
6
|
-
source: string | undefined;
|
|
7
|
-
path: Array<string | number> | null;
|
|
8
|
-
readonly code: JSONParserErrorType;
|
|
9
|
-
constructor(message: string, source?: string);
|
|
10
|
-
toJSON: () => Error;
|
|
11
|
-
get footprint(): string;
|
|
12
|
-
}
|
|
13
|
-
declare class ParserError extends JSONParserError {
|
|
14
|
-
code: JSONParserErrorType;
|
|
15
|
-
name: string;
|
|
16
|
-
constructor(message: any, source: any);
|
|
17
|
-
}
|
|
18
|
-
declare class ResolverError extends JSONParserError {
|
|
19
|
-
code: JSONParserErrorType;
|
|
20
|
-
name: string;
|
|
21
|
-
ioErrorCode?: string;
|
|
22
|
-
constructor(ex: Error | any, source?: string);
|
|
23
|
-
}
|
|
24
|
-
declare class MissingPointerError extends JSONParserError {
|
|
25
|
-
code: JSONParserErrorType;
|
|
26
|
-
name: string;
|
|
27
|
-
targetToken: any;
|
|
28
|
-
targetRef: string;
|
|
29
|
-
targetFound: string;
|
|
30
|
-
parentPath: string;
|
|
31
|
-
constructor(token: any, path: any, targetRef: any, targetFound: any, parentPath: any);
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
export { JSONParserError, MissingPointerError, ParserError, ResolverError };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@apidevtools+json-schema-ref-parser@15.3.6_@types+json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/is-windows.js
|
|
2
|
-
const isWindowsConst = /^win/.test(globalThis.process ? globalThis.process.platform : "");
|
|
3
|
-
const isWindows = () => isWindowsConst;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { isWindows };
|
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import convertPathToPosix from "./convert-path-to-posix.js";
|
|
2
|
-
import { isWindows } from "./is-windows.js";
|
|
3
|
-
//#region ../../node_modules/.pnpm/@apidevtools+json-schema-ref-parser@15.3.6_@types+json-schema@7.0.15/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/util/url.js
|
|
4
|
-
const forwardSlashPattern = /\//g;
|
|
5
|
-
const protocolPattern = /^(\w{2,}):\/\//i;
|
|
6
|
-
const jsonPointerSlash = /~1/g;
|
|
7
|
-
const jsonPointerTilde = /~0/g;
|
|
8
|
-
const isAbsoluteWin32Path = /^[a-zA-Z]:[\\/]/;
|
|
9
|
-
const urlEncodePatterns = [[/\?/g, "%3F"], [/#/g, "%23"]];
|
|
10
|
-
const urlDecodePatterns = [
|
|
11
|
-
/%23/g,
|
|
12
|
-
"#",
|
|
13
|
-
/%24/g,
|
|
14
|
-
"$",
|
|
15
|
-
/%26/g,
|
|
16
|
-
"&",
|
|
17
|
-
/%2C/g,
|
|
18
|
-
",",
|
|
19
|
-
/%40/g,
|
|
20
|
-
"@"
|
|
21
|
-
];
|
|
22
|
-
const unsafeDomainSuffixes = [
|
|
23
|
-
".localhost",
|
|
24
|
-
".local",
|
|
25
|
-
".internal",
|
|
26
|
-
".intranet",
|
|
27
|
-
".corp",
|
|
28
|
-
".home",
|
|
29
|
-
".lan"
|
|
30
|
-
];
|
|
31
|
-
const parse = (u) => new URL(u);
|
|
32
|
-
/**
|
|
33
|
-
* Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
|
|
34
|
-
*
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
function resolve(from, to) {
|
|
38
|
-
const fromUrl = new URL(convertPathToPosix(from), "https://aaa.nonexistanturl.com");
|
|
39
|
-
const resolvedUrl = new URL(convertPathToPosix(to), fromUrl);
|
|
40
|
-
const endSpaces = to.match(/(\s*)$/)?.[1] || "";
|
|
41
|
-
if (resolvedUrl.hostname === "aaa.nonexistanturl.com") {
|
|
42
|
-
const { pathname, search, hash } = resolvedUrl;
|
|
43
|
-
return pathname + search + decodeURIComponent(hash) + endSpaces;
|
|
44
|
-
}
|
|
45
|
-
const resolved = resolvedUrl.toString() + endSpaces;
|
|
46
|
-
if (resolved.includes("#")) {
|
|
47
|
-
const [base, hash] = resolved.split("#", 2);
|
|
48
|
-
return base + "#" + decodeURIComponent(hash || "");
|
|
49
|
-
}
|
|
50
|
-
return resolved;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns the current working directory (in Node) or the current page URL (in browsers).
|
|
54
|
-
*
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
function cwd() {
|
|
58
|
-
if (typeof window !== "undefined" && window.location && window.location.href) {
|
|
59
|
-
const href = window.location.href;
|
|
60
|
-
if (!href || !href.startsWith("http")) try {
|
|
61
|
-
new URL(href);
|
|
62
|
-
return href;
|
|
63
|
-
} catch {
|
|
64
|
-
return "/";
|
|
65
|
-
}
|
|
66
|
-
return href;
|
|
67
|
-
}
|
|
68
|
-
if (typeof process !== "undefined" && process.cwd) {
|
|
69
|
-
const path = process.cwd();
|
|
70
|
-
const lastChar = path.slice(-1);
|
|
71
|
-
if (lastChar === "/" || lastChar === "\\") return path;
|
|
72
|
-
else return path + "/";
|
|
73
|
-
}
|
|
74
|
-
return "/";
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns the protocol of the given URL, or `undefined` if it has no protocol.
|
|
78
|
-
*
|
|
79
|
-
* @param path
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
function getProtocol(path) {
|
|
83
|
-
const match = protocolPattern.exec(path || "");
|
|
84
|
-
if (match) return match[1].toLowerCase();
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns the lowercased file extension of the given URL,
|
|
88
|
-
* or an empty string if it has no extension.
|
|
89
|
-
*
|
|
90
|
-
* @param path
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
function getExtension(path) {
|
|
94
|
-
const lastDot = path.lastIndexOf(".");
|
|
95
|
-
if (lastDot >= 0) return stripQuery(path.substring(lastDot).toLowerCase());
|
|
96
|
-
return "";
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Removes the query, if any, from the given path.
|
|
100
|
-
*
|
|
101
|
-
* @param path
|
|
102
|
-
* @returns
|
|
103
|
-
*/
|
|
104
|
-
function stripQuery(path) {
|
|
105
|
-
const queryIndex = path.indexOf("?");
|
|
106
|
-
if (queryIndex >= 0) path = path.substring(0, queryIndex);
|
|
107
|
-
return path;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Returns the hash (URL fragment), of the given path.
|
|
111
|
-
* If there is no hash, then the root hash ("#") is returned.
|
|
112
|
-
*
|
|
113
|
-
* @param path
|
|
114
|
-
* @returns
|
|
115
|
-
*/
|
|
116
|
-
function getHash(path) {
|
|
117
|
-
if (!path) return "#";
|
|
118
|
-
const hashIndex = path.indexOf("#");
|
|
119
|
-
if (hashIndex >= 0) return path.substring(hashIndex);
|
|
120
|
-
return "#";
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Removes the hash (URL fragment), if any, from the given path.
|
|
124
|
-
*
|
|
125
|
-
* @param path
|
|
126
|
-
* @returns
|
|
127
|
-
*/
|
|
128
|
-
function stripHash(path) {
|
|
129
|
-
if (!path) return "";
|
|
130
|
-
const hashIndex = path.indexOf("#");
|
|
131
|
-
if (hashIndex >= 0) path = path.substring(0, hashIndex);
|
|
132
|
-
return path;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Determines whether the given path is an HTTP(S) URL.
|
|
136
|
-
*
|
|
137
|
-
* @param path
|
|
138
|
-
* @returns
|
|
139
|
-
*/
|
|
140
|
-
function isHttp(path) {
|
|
141
|
-
const protocol = getProtocol(path);
|
|
142
|
-
if (protocol === "http" || protocol === "https") return true;
|
|
143
|
-
else if (protocol === void 0) return typeof window !== "undefined";
|
|
144
|
-
else return false;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Determines whether the given url is an unsafe or internal url.
|
|
148
|
-
*
|
|
149
|
-
* @param path - The URL or path to check
|
|
150
|
-
* @returns true if the URL is unsafe/internal, false otherwise
|
|
151
|
-
*/
|
|
152
|
-
function isUnsafeUrl(path) {
|
|
153
|
-
if (!path || typeof path !== "string") return true;
|
|
154
|
-
const normalizedPath = path.trim().toLowerCase();
|
|
155
|
-
if (!normalizedPath) return true;
|
|
156
|
-
if (normalizedPath.startsWith("javascript:") || normalizedPath.startsWith("vbscript:") || normalizedPath.startsWith("data:")) return true;
|
|
157
|
-
if (normalizedPath.startsWith("file:")) return true;
|
|
158
|
-
if (typeof window !== "undefined" && window.location && window.location.href) return false;
|
|
159
|
-
try {
|
|
160
|
-
const url = new URL(normalizedPath.startsWith("//") ? "http:" + normalizedPath : normalizedPath);
|
|
161
|
-
if (isUnsafeHostname(url.hostname)) return true;
|
|
162
|
-
const port = url.port;
|
|
163
|
-
if (port && isInternalPort(parseInt(port))) return true;
|
|
164
|
-
} catch {
|
|
165
|
-
if (normalizedPath.startsWith("/") && !normalizedPath.startsWith("//")) return false;
|
|
166
|
-
if (containsUnsafeHostname(normalizedPath)) return true;
|
|
167
|
-
}
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Helper function to check if a hostname is local or resolves to a non-public literal address.
|
|
172
|
-
*/
|
|
173
|
-
function isUnsafeHostname(hostname) {
|
|
174
|
-
const normalizedHostname = normalizeHostname(hostname);
|
|
175
|
-
if (!normalizedHostname) return true;
|
|
176
|
-
if (normalizedHostname === "localhost" || unsafeDomainSuffixes.some((suffix) => normalizedHostname.endsWith(suffix))) return true;
|
|
177
|
-
const ipv4 = parseIPv4Address(normalizedHostname);
|
|
178
|
-
if (ipv4) return isUnsafeIPv4Address(ipv4);
|
|
179
|
-
const ipv6 = parseIPv6Address(normalizedHostname);
|
|
180
|
-
if (ipv6) return isUnsafeIPv6Address(ipv6);
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
function normalizeHostname(hostname) {
|
|
184
|
-
let normalizedHostname = hostname.trim().toLowerCase();
|
|
185
|
-
if (normalizedHostname.startsWith("[") && normalizedHostname.endsWith("]")) normalizedHostname = normalizedHostname.slice(1, -1);
|
|
186
|
-
while (normalizedHostname.endsWith(".")) normalizedHostname = normalizedHostname.slice(0, -1);
|
|
187
|
-
return normalizedHostname;
|
|
188
|
-
}
|
|
189
|
-
function parseIPv4Address(ip) {
|
|
190
|
-
const parts = ip.split(".");
|
|
191
|
-
if (parts.length !== 4) return;
|
|
192
|
-
const octets = parts.map((part) => {
|
|
193
|
-
if (!/^\d+$/.test(part)) return NaN;
|
|
194
|
-
return Number(part);
|
|
195
|
-
});
|
|
196
|
-
if (octets.some((octet) => !Number.isInteger(octet) || octet < 0 || octet > 255)) return;
|
|
197
|
-
return octets;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Helper function to check if an IPv4 address is in a non-public range.
|
|
201
|
-
*/
|
|
202
|
-
function isUnsafeIPv4Address([a, b, c, d]) {
|
|
203
|
-
return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 0 && c === 0 || a === 192 && b === 168 || a === 198 && (b === 18 || b === 19) || a >= 224 || a === 255 && b === 255 && c === 255 && d === 255;
|
|
204
|
-
}
|
|
205
|
-
function parseIPv6Address(ip) {
|
|
206
|
-
if (!ip.includes(":")) return;
|
|
207
|
-
let normalizedIP = ip;
|
|
208
|
-
const lastSeparator = normalizedIP.lastIndexOf(":");
|
|
209
|
-
const possibleIPv4 = normalizedIP.slice(lastSeparator + 1);
|
|
210
|
-
if (possibleIPv4.includes(".")) {
|
|
211
|
-
const ipv4 = parseIPv4Address(possibleIPv4);
|
|
212
|
-
if (!ipv4) return;
|
|
213
|
-
const firstGroup = ipv4[0] * 256 + ipv4[1];
|
|
214
|
-
const secondGroup = ipv4[2] * 256 + ipv4[3];
|
|
215
|
-
normalizedIP = `${normalizedIP.slice(0, lastSeparator + 1)}${firstGroup.toString(16)}:${secondGroup.toString(16)}`;
|
|
216
|
-
}
|
|
217
|
-
const halves = normalizedIP.split("::");
|
|
218
|
-
if (halves.length > 2) return;
|
|
219
|
-
const head = parseIPv6Groups(halves[0]);
|
|
220
|
-
const tail = halves.length === 2 ? parseIPv6Groups(halves[1]) : [];
|
|
221
|
-
if (!head || !tail) return;
|
|
222
|
-
if (halves.length === 1) return head.length === 8 ? head : void 0;
|
|
223
|
-
const missingGroups = 8 - head.length - tail.length;
|
|
224
|
-
if (missingGroups < 1) return;
|
|
225
|
-
return [
|
|
226
|
-
...head,
|
|
227
|
-
...Array(missingGroups).fill(0),
|
|
228
|
-
...tail
|
|
229
|
-
];
|
|
230
|
-
}
|
|
231
|
-
function parseIPv6Groups(groups) {
|
|
232
|
-
if (!groups) return [];
|
|
233
|
-
const parsedGroups = groups.split(":").map((group) => {
|
|
234
|
-
if (!/^[\da-f]{1,4}$/i.test(group)) return NaN;
|
|
235
|
-
return Number.parseInt(group, 16);
|
|
236
|
-
});
|
|
237
|
-
if (parsedGroups.some((group) => !Number.isInteger(group) || group < 0 || group > 65535)) return;
|
|
238
|
-
return parsedGroups;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Helper function to check if an IPv6 address is in a non-public range.
|
|
242
|
-
*/
|
|
243
|
-
function isUnsafeIPv6Address(groups) {
|
|
244
|
-
if (groups.length !== 8) return false;
|
|
245
|
-
const isUnspecified = groups.every((group) => group === 0);
|
|
246
|
-
const isLoopback = groups.slice(0, 7).every((group) => group === 0) && groups[7] === 1;
|
|
247
|
-
const isUniqueLocal = (groups[0] & 65024) === 64512;
|
|
248
|
-
const isLinkLocal = (groups[0] & 65472) === 65152;
|
|
249
|
-
const isMulticast = (groups[0] & 65280) === 65280;
|
|
250
|
-
if (isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isMulticast) return true;
|
|
251
|
-
const mappedIPv4 = getMappedIPv4Address(groups);
|
|
252
|
-
return mappedIPv4 ? isUnsafeIPv4Address(mappedIPv4) : false;
|
|
253
|
-
}
|
|
254
|
-
function getMappedIPv4Address(groups) {
|
|
255
|
-
const firstFiveGroupsAreZero = groups.slice(0, 5).every((group) => group === 0);
|
|
256
|
-
const firstSixGroupsAreZero = firstFiveGroupsAreZero && groups[5] === 0;
|
|
257
|
-
const isIPv4Mapped = firstFiveGroupsAreZero && groups[5] === 65535;
|
|
258
|
-
if (!firstSixGroupsAreZero && !isIPv4Mapped) return;
|
|
259
|
-
return [
|
|
260
|
-
Math.floor(groups[6] / 256),
|
|
261
|
-
groups[6] % 256,
|
|
262
|
-
Math.floor(groups[7] / 256),
|
|
263
|
-
groups[7] % 256
|
|
264
|
-
];
|
|
265
|
-
}
|
|
266
|
-
function containsUnsafeHostname(value) {
|
|
267
|
-
return value.split(/[\s/?#]+/).map((candidate) => candidate.replace(/^[a-z][\d+.a-z-]*:\/\//i, "").replace(/:\d+$/, "")).filter(Boolean).some((candidate) => isUnsafeHostname(candidate));
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Helper function to check if a port is typically used for internal services
|
|
271
|
-
*/
|
|
272
|
-
function isInternalPort(port) {
|
|
273
|
-
return [
|
|
274
|
-
22,
|
|
275
|
-
23,
|
|
276
|
-
25,
|
|
277
|
-
53,
|
|
278
|
-
135,
|
|
279
|
-
139,
|
|
280
|
-
445,
|
|
281
|
-
993,
|
|
282
|
-
995,
|
|
283
|
-
1433,
|
|
284
|
-
1521,
|
|
285
|
-
3306,
|
|
286
|
-
3389,
|
|
287
|
-
5432,
|
|
288
|
-
5900,
|
|
289
|
-
6379,
|
|
290
|
-
8080,
|
|
291
|
-
8443,
|
|
292
|
-
9200,
|
|
293
|
-
27017
|
|
294
|
-
].includes(port);
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Determines whether the given path is a filesystem path.
|
|
298
|
-
* This includes "file://" URLs.
|
|
299
|
-
*
|
|
300
|
-
* @param path
|
|
301
|
-
* @returns
|
|
302
|
-
*/
|
|
303
|
-
function isFileSystemPath(path) {
|
|
304
|
-
if (typeof window !== "undefined" || typeof process !== "undefined" && process.browser) return false;
|
|
305
|
-
const protocol = getProtocol(path);
|
|
306
|
-
return protocol === void 0 || protocol === "file";
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Converts a filesystem path to a properly-encoded URL.
|
|
310
|
-
*
|
|
311
|
-
* This is intended to handle situations where JSON Schema $Ref Parser is called
|
|
312
|
-
* with a filesystem path that contains characters which are not allowed in URLs.
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* The following filesystem paths would be converted to the following URLs:
|
|
316
|
-
*
|
|
317
|
-
* <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
|
|
318
|
-
* C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
|
|
319
|
-
* file://Project #42/file.json ==> file://Project%20%2342/file.json
|
|
320
|
-
*
|
|
321
|
-
* @param path
|
|
322
|
-
* @returns
|
|
323
|
-
*/
|
|
324
|
-
function fromFileSystemPath(path) {
|
|
325
|
-
if (isWindows()) {
|
|
326
|
-
const projectDir = cwd();
|
|
327
|
-
const upperPath = path.toUpperCase();
|
|
328
|
-
const posixUpper = convertPathToPosix(projectDir).toUpperCase();
|
|
329
|
-
const hasProjectDir = upperPath.includes(posixUpper);
|
|
330
|
-
const hasProjectUri = upperPath.includes(posixUpper);
|
|
331
|
-
const isAbsolutePath = isAbsoluteWin32Path.test(path) || path.startsWith("http://") || path.startsWith("https://") || path.startsWith("file://");
|
|
332
|
-
if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
|
|
333
|
-
const join = (a, b) => {
|
|
334
|
-
if (a.endsWith("/") || a.endsWith("\\")) return a + b;
|
|
335
|
-
else return a + "/" + b;
|
|
336
|
-
};
|
|
337
|
-
path = join(projectDir, path);
|
|
338
|
-
}
|
|
339
|
-
path = convertPathToPosix(path);
|
|
340
|
-
}
|
|
341
|
-
path = encodeURI(path);
|
|
342
|
-
for (const pattern of urlEncodePatterns) path = path.replace(pattern[0], pattern[1]);
|
|
343
|
-
return path;
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Converts a URL to a local filesystem path.
|
|
347
|
-
*/
|
|
348
|
-
function toFileSystemPath(path, keepFileProtocol) {
|
|
349
|
-
path = path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25");
|
|
350
|
-
path = decodeURI(path);
|
|
351
|
-
for (let i = 0; i < urlDecodePatterns.length; i += 2) path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
|
|
352
|
-
let isFileUrl = path.toLowerCase().startsWith("file://");
|
|
353
|
-
if (isFileUrl) {
|
|
354
|
-
path = path.replace(/^file:\/\//, "").replace(/^\//, "");
|
|
355
|
-
if (isWindows() && path[1] === "/") path = `${path[0]}:${path.substring(1)}`;
|
|
356
|
-
if (keepFileProtocol) path = "file:///" + path;
|
|
357
|
-
else {
|
|
358
|
-
isFileUrl = false;
|
|
359
|
-
path = isWindows() ? path : "/" + path;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (isWindows() && !isFileUrl) {
|
|
363
|
-
path = path.replace(forwardSlashPattern, "\\");
|
|
364
|
-
if (path.match(/^[a-z]:\\/i)) path = path[0].toUpperCase() + path.substring(1);
|
|
365
|
-
}
|
|
366
|
-
return path;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Converts a $ref pointer to a valid JSON Path.
|
|
370
|
-
*
|
|
371
|
-
* @param pointer
|
|
372
|
-
* @returns
|
|
373
|
-
*/
|
|
374
|
-
function safePointerToPath(pointer) {
|
|
375
|
-
if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") return [];
|
|
376
|
-
return pointer.slice(2).split("/").map((value) => {
|
|
377
|
-
return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
//#endregion
|
|
381
|
-
export { cwd, fromFileSystemPath, getExtension, getHash, isFileSystemPath, isHttp, isUnsafeUrl, parse, resolve, safePointerToPath, stripHash, toFileSystemPath };
|