@scalar/oas-utils 0.6.22 → 0.6.24
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 +18 -0
- package/dist/helpers/fetch-document.d.ts.map +1 -1
- package/dist/helpers/fetch-document.js +1 -1
- package/dist/helpers/fetch-document.js.map +2 -2
- package/dist/helpers/fetch-with-proxy-fallback.js +1 -1
- package/dist/helpers/fetch-with-proxy-fallback.js.map +1 -1
- package/dist/helpers/index.d.ts +57 -55
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +46 -47
- package/dist/helpers/index.js.map +2 -2
- package/package.json +5 -5
- package/dist/helpers/redirect-to-proxy.d.ts +0 -13
- package/dist/helpers/redirect-to-proxy.d.ts.map +0 -1
- package/dist/helpers/redirect-to-proxy.js +0 -44
- package/dist/helpers/redirect-to-proxy.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.6.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
#### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- **@scalar/workspace-store@0.25.3**
|
|
10
|
+
- [#7850](https://github.com/scalar/scalar/pull/7850): fix: remove unused workspace config
|
|
11
|
+
- [#7868](https://github.com/scalar/scalar/pull/7868): fix: updating path with a variable in it
|
|
12
|
+
|
|
13
|
+
## 0.6.23
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
#### Updated Dependencies
|
|
18
|
+
|
|
19
|
+
- **@scalar/workspace-store@0.25.2**
|
|
20
|
+
|
|
3
21
|
## 0.6.22
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-document.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-document.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-document.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-document.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EAC7F,WAAW,UAAO,GACjB,OAAO,CAAC,MAAM,CAAC,CA4BjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { redirectToProxy } from "@scalar/helpers/url/redirect-to-proxy";
|
|
1
2
|
import { formatJsonOrYamlString } from "./parse.js";
|
|
2
|
-
import { redirectToProxy } from "./redirect-to-proxy.js";
|
|
3
3
|
const OLD_PROXY_URL = "https://api.scalar.com/request-proxy";
|
|
4
4
|
const NEW_PROXY_URL = "https://proxy.scalar.com";
|
|
5
5
|
async function fetchDocument(url, proxyUrl, fetcher, prettyPrint = true) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/fetch-document.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { redirectToProxy } from '@scalar/helpers/url/redirect-to-proxy'\n\nimport { formatJsonOrYamlString } from './parse'\n\n// Doesn't work\nconst OLD_PROXY_URL = 'https://api.scalar.com/request-proxy'\n// Does work\nconst NEW_PROXY_URL = 'https://proxy.scalar.com'\n\n/**\n * Fetches an OpenAPI/Swagger document from a given URL\n *\n * @throws an error if the fetch fails\n */\nexport async function fetchDocument(\n url: string,\n proxyUrl?: string,\n fetcher?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>,\n prettyPrint = true,\n): Promise<string> {\n // This replaces the OLD_PROXY_URL with the NEW_PROXY_URL on the fly.\n if (proxyUrl === OLD_PROXY_URL) {\n // biome-ignore lint/style/noParameterAssign: It's ok, let's make an exception here.\n proxyUrl = NEW_PROXY_URL\n }\n\n const response = await (fetcher ? fetcher(url, undefined) : fetch(redirectToProxy(proxyUrl, url)))\n\n // Looks like the request failed\n if (response.status !== 200) {\n console.error(`[fetchDocument] Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`)\n\n if (!proxyUrl) {\n console.warn(\n `[fetchDocument] Tried to fetch the OpenAPI document from ${url} without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`,\n )\n }\n\n throw new Error(`Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`)\n }\n\n // If it's JSON, make it pretty\n if (prettyPrint) {\n return formatJsonOrYamlString(await response.text())\n }\n\n return await response.text()\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAEhC,SAAS,8BAA8B;AAGvC,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAOtB,eAAsB,cACpB,KACA,UACA,SACA,cAAc,MACG;AAEjB,MAAI,aAAa,eAAe;AAE9B,eAAW;AAAA,EACb;AAEA,QAAM,WAAW,OAAO,UAAU,QAAQ,KAAK,MAAS,IAAI,MAAM,gBAAgB,UAAU,GAAG,CAAC;AAGhG,MAAI,SAAS,WAAW,KAAK;AAC3B,YAAQ,MAAM,6DAA6D,GAAG,aAAa,SAAS,MAAM,GAAG;AAE7G,QAAI,CAAC,UAAU;AACb,cAAQ;AAAA,QACN,4DAA4D,GAAG;AAAA,MACjE;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,6CAA6C,GAAG,aAAa,SAAS,MAAM,GAAG;AAAA,EACjG;AAGA,MAAI,aAAa;AACf,WAAO,uBAAuB,MAAM,SAAS,KAAK,CAAC;AAAA,EACrD;AAEA,SAAO,MAAM,SAAS,KAAK;AAC7B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { redirectToProxy, shouldUseProxy } from "
|
|
1
|
+
import { redirectToProxy, shouldUseProxy } from "@scalar/helpers/url/redirect-to-proxy";
|
|
2
2
|
async function fetchWithProxyFallback(url, { proxyUrl, cache }) {
|
|
3
3
|
const fetchOptions = {
|
|
4
4
|
cache: cache || "default"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/fetch-with-proxy-fallback.ts"],
|
|
4
|
-
"sourcesContent": ["import { redirectToProxy, shouldUseProxy } from '
|
|
4
|
+
"sourcesContent": ["import { redirectToProxy, shouldUseProxy } from '@scalar/helpers/url/redirect-to-proxy'\n\nexport type FetchWithProxyFallbackOptions = {\n proxyUrl: string | undefined\n /**\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache\n */\n cache?: RequestInit['cache']\n}\n\n/**\n * Fetches an OpenAPI document with a proxyUrl fallback mechanism.\n *\n * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.\n * If the proxy fetch fails or is not used, it will fall back to a direct fetch.\n */\nexport async function fetchWithProxyFallback(url: string, { proxyUrl, cache }: FetchWithProxyFallbackOptions) {\n const fetchOptions = {\n cache: cache || 'default',\n }\n const shouldTryProxy = shouldUseProxy(proxyUrl, url)\n const initialUrl = shouldTryProxy ? redirectToProxy(proxyUrl, url) : url\n\n try {\n const result = await fetch(initialUrl, fetchOptions)\n\n if (result.ok || !shouldTryProxy) {\n return result\n }\n\n // Retry without proxyUrl if the initial request failed\n return await fetch(url, fetchOptions)\n } catch (error) {\n if (shouldTryProxy) {\n // If proxyUrl failed, try without it\n return await fetch(url, fetchOptions)\n }\n throw error\n }\n}\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,iBAAiB,sBAAsB;AAgBhD,eAAsB,uBAAuB,KAAa,EAAE,UAAU,MAAM,GAAkC;AAC5G,QAAM,eAAe;AAAA,IACnB,OAAO,SAAS;AAAA,EAClB;AACA,QAAM,iBAAiB,eAAe,UAAU,GAAG;AACnD,QAAM,aAAa,iBAAiB,gBAAgB,UAAU,GAAG,IAAI;AAErE,MAAI;AACF,UAAM,SAAS,MAAM,MAAM,YAAY,YAAY;AAEnD,QAAI,OAAO,MAAM,CAAC,gBAAgB;AAChC,aAAO;AAAA,IACT;AAGA,WAAO,MAAM,MAAM,KAAK,YAAY;AAAA,EACtC,SAAS,OAAO;AACd,QAAI,gBAAgB;AAElB,aAAO,MAAM,MAAM,KAAK,YAAY;AAAA,IACtC;AACA,UAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,64 +1,18 @@
|
|
|
1
|
-
export { fetchDocument } from './fetch-document.js';
|
|
2
|
-
export { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback.js';
|
|
3
|
-
export { normalizeMimeType } from './normalize-mime-type.js';
|
|
4
|
-
export { normalizeMimeTypeObject } from './normalize-mime-type-object.js';
|
|
5
|
-
export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse.js';
|
|
6
|
-
export { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json.js';
|
|
7
|
-
export { shouldUseProxy, redirectToProxy } from './redirect-to-proxy.js';
|
|
8
|
-
export { schemaModel } from './schema-model.js';
|
|
9
|
-
export { shouldIgnoreEntity } from './should-ignore-entity.js';
|
|
10
|
-
export { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from './operation-stability.js';
|
|
11
|
-
export { getServersFromDocument } from './servers.js';
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated These helpers are being phased out. Please import directly from @scalar/helpers instead.
|
|
14
|
-
* For example: import { createHash } from '/@scalar/helpers/string/create-hash'
|
|
15
|
-
*/
|
|
16
|
-
export {
|
|
17
|
-
/** @deprecated Please use createHash from \@scalar/helpers/string/create-hash instead */
|
|
18
|
-
createHash, } from '@scalar/helpers/string/create-hash';
|
|
19
1
|
export {
|
|
20
2
|
/** @deprecated Please use isDefined from \@scalar/helpers/array/is-defined instead */
|
|
21
3
|
isDefined, } from '@scalar/helpers/array/is-defined';
|
|
22
4
|
export {
|
|
23
|
-
/** @deprecated Please use isHttpMethod from \@scalar/helpers/http/is-http-method instead */
|
|
24
|
-
isHttpMethod, } from '@scalar/helpers/http/is-http-method';
|
|
25
|
-
export {
|
|
26
|
-
/** @deprecated Please use combineUrlAndPath from \@scalar/helpers/url/merge-urls instead */
|
|
27
|
-
combineUrlAndPath, } from '@scalar/helpers/url/merge-urls';
|
|
28
|
-
export {
|
|
29
5
|
/** @deprecated Please use json2xml from \@scalar/helpers/file/json2xml instead */
|
|
30
6
|
json2xml, } from '@scalar/helpers/file/json2xml';
|
|
31
7
|
export {
|
|
32
|
-
/** @deprecated Please use capitalize from \@scalar/helpers/string/capitalize instead */
|
|
33
|
-
capitalize, } from '@scalar/helpers/string/capitalize';
|
|
34
|
-
export {
|
|
35
|
-
/** @deprecated Please use camelToTitleWords from \@scalar/helpers/string/camel-to-title instead */
|
|
36
|
-
camelToTitleWords, } from '@scalar/helpers/string/camel-to-title';
|
|
37
|
-
export {
|
|
38
|
-
/** @deprecated Please use REGEX from \@scalar/helpers/regex/regex-helpers instead */
|
|
39
|
-
REGEX, } from '@scalar/helpers/regex/regex-helpers';
|
|
40
|
-
export {
|
|
41
|
-
/** @deprecated Please use isLocalUrl from \@scalar/helpers/url/is-local-url instead */
|
|
42
|
-
isLocalUrl, } from '@scalar/helpers/url/is-local-url';
|
|
43
|
-
export {
|
|
44
|
-
/** @deprecated Please use isRelativePath from \@scalar/helpers/url/is-relative-path instead */
|
|
45
|
-
isRelativePath, } from '@scalar/helpers/url/is-relative-path';
|
|
46
|
-
export {
|
|
47
|
-
/** @deprecated Please use ensureProtocol from \@scalar/helpers/url/ensure-protocol instead */
|
|
48
|
-
ensureProtocol, } from '@scalar/helpers/url/ensure-protocol';
|
|
49
|
-
export {
|
|
50
|
-
/** @deprecated Please use findVariables from \@scalar/helpers/regex/find-variables instead */
|
|
51
|
-
findVariables, } from '@scalar/helpers/regex/find-variables';
|
|
52
|
-
export {
|
|
53
8
|
/** @deprecated Please use canMethodHaveBody from \@scalar/helpers/http/can-method-have-body instead */
|
|
54
9
|
canMethodHaveBody, } from '@scalar/helpers/http/can-method-have-body';
|
|
55
10
|
export {
|
|
11
|
+
/** @deprecated Please use REQUEST_METHODS from \@scalar/helpers/http/http-methods instead */
|
|
12
|
+
REQUEST_METHODS,
|
|
56
13
|
/** @deprecated Please use getHttpMethodInfo from \@scalar/helpers/http/http-info instead */
|
|
57
14
|
getHttpMethodInfo, } from '@scalar/helpers/http/http-info';
|
|
58
15
|
export {
|
|
59
|
-
/** @deprecated Please use REQUEST_METHODS from \@scalar/helpers/http/http-methods instead */
|
|
60
|
-
REQUEST_METHODS, } from '@scalar/helpers/http/http-info';
|
|
61
|
-
export {
|
|
62
16
|
/** @deprecated Please use HttpStatusCode from \@scalar/helpers/http/http-status-codes instead */
|
|
63
17
|
type HttpStatusCode,
|
|
64
18
|
/** @deprecated Please use HttpStatusCodes from \@scalar/helpers/http/http-status-codes instead */
|
|
@@ -66,23 +20,71 @@ type HttpStatusCodes,
|
|
|
66
20
|
/** @deprecated Please use httpStatusCodes from \@scalar/helpers/http/http-status-codes instead */
|
|
67
21
|
httpStatusCodes, } from '@scalar/helpers/http/http-status-codes';
|
|
68
22
|
export {
|
|
69
|
-
/** @deprecated Please use
|
|
70
|
-
|
|
23
|
+
/** @deprecated Please use isHttpMethod from \@scalar/helpers/http/is-http-method instead */
|
|
24
|
+
isHttpMethod, } from '@scalar/helpers/http/is-http-method';
|
|
25
|
+
export {
|
|
26
|
+
/** @deprecated Please use objectKeys from \@scalar/helpers/object/object-keys instead */
|
|
27
|
+
objectKeys as getObjectKeys, } from '@scalar/helpers/object/object-keys';
|
|
28
|
+
export {
|
|
29
|
+
/** @deprecated Please use findVariables from \@scalar/helpers/regex/find-variables instead */
|
|
30
|
+
findVariables, } from '@scalar/helpers/regex/find-variables';
|
|
31
|
+
export {
|
|
32
|
+
/** @deprecated Please use REGEX from \@scalar/helpers/regex/regex-helpers instead */
|
|
33
|
+
REGEX, } from '@scalar/helpers/regex/regex-helpers';
|
|
34
|
+
export {
|
|
35
|
+
/** @deprecated Please use replaceVariables from \@scalar/helpers/regex/replace-variables instead */
|
|
36
|
+
replaceVariables, } from '@scalar/helpers/regex/replace-variables';
|
|
37
|
+
export {
|
|
38
|
+
/** @deprecated Please use camelToTitleWords from \@scalar/helpers/string/camel-to-title instead */
|
|
39
|
+
camelToTitleWords, } from '@scalar/helpers/string/camel-to-title';
|
|
40
|
+
export {
|
|
41
|
+
/** @deprecated Please use capitalize from \@scalar/helpers/string/capitalize instead */
|
|
42
|
+
capitalize, } from '@scalar/helpers/string/capitalize';
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated These helpers are being phased out. Please import directly from @scalar/helpers instead.
|
|
45
|
+
* For example: import { createHash } from '/@scalar/helpers/string/create-hash'
|
|
46
|
+
*/
|
|
47
|
+
export {
|
|
48
|
+
/** @deprecated Please use createHash from \@scalar/helpers/string/create-hash instead */
|
|
49
|
+
createHash, } from '@scalar/helpers/string/create-hash';
|
|
71
50
|
export {
|
|
72
51
|
/** @deprecated Please use iterateTitle from \@scalar/helpers/string/iterate-title instead */
|
|
73
52
|
iterateTitle, } from '@scalar/helpers/string/iterate-title';
|
|
74
53
|
export {
|
|
54
|
+
/** @deprecated Please use ensureProtocol from \@scalar/helpers/url/ensure-protocol instead */
|
|
55
|
+
ensureProtocol, } from '@scalar/helpers/url/ensure-protocol';
|
|
56
|
+
export {
|
|
57
|
+
/** @deprecated Please use isLocalUrl from \@scalar/helpers/url/is-local-url instead */
|
|
58
|
+
isLocalUrl, } from '@scalar/helpers/url/is-local-url';
|
|
59
|
+
export {
|
|
60
|
+
/** @deprecated Please use isRelativePath from \@scalar/helpers/url/is-relative-path instead */
|
|
61
|
+
isRelativePath, } from '@scalar/helpers/url/is-relative-path';
|
|
62
|
+
export {
|
|
63
|
+
/** @deprecated Please use isValidUrl from \@scalar/helpers/url/is-valid-url instead */
|
|
64
|
+
isValidUrl, } from '@scalar/helpers/url/is-valid-url';
|
|
65
|
+
export {
|
|
75
66
|
/** @deprecated Please use makeUrlAbsolute from \@scalar/helpers/url/make-url-absolute instead */
|
|
76
67
|
makeUrlAbsolute, } from '@scalar/helpers/url/make-url-absolute';
|
|
77
68
|
export {
|
|
69
|
+
/** @deprecated Please use combineUrlAndPath from \@scalar/helpers/url/merge-urls instead */
|
|
70
|
+
combineUrlAndPath,
|
|
78
71
|
/** @deprecated Please use mergeSearchParams from \@scalar/helpers/url/merge-urls instead */
|
|
79
72
|
mergeSearchParams,
|
|
80
73
|
/** @deprecated Please use mergeUrls from \@scalar/helpers/url/merge-urls instead */
|
|
81
74
|
mergeUrls, } from '@scalar/helpers/url/merge-urls';
|
|
82
75
|
export {
|
|
83
|
-
/** @deprecated Please use
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
/** @deprecated Please use redirectToProxy from \@scalar/helpers/url/redirect-to-proxy instead */
|
|
77
|
+
redirectToProxy,
|
|
78
|
+
/** @deprecated Please use shouldUseProxy from \@scalar/helpers/url/redirect-to-proxy instead */
|
|
79
|
+
shouldUseProxy, } from '@scalar/helpers/url/redirect-to-proxy';
|
|
80
|
+
export { fetchDocument } from './fetch-document.js';
|
|
81
|
+
export { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback.js';
|
|
82
|
+
export { normalizeMimeType } from './normalize-mime-type.js';
|
|
83
|
+
export { normalizeMimeTypeObject } from './normalize-mime-type-object.js';
|
|
84
|
+
export { getOperationStability, getOperationStabilityColor, isOperationDeprecated } from './operation-stability.js';
|
|
85
|
+
export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse.js';
|
|
86
|
+
export { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json.js';
|
|
87
|
+
export { schemaModel } from './schema-model.js';
|
|
88
|
+
export { getServersFromDocument } from './servers.js';
|
|
89
|
+
export { shouldIgnoreEntity } from './should-ignore-entity.js';
|
|
88
90
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACL,sFAAsF;AACtF,SAAS,GACV,MAAM,kCAAkC,CAAA;AACzC,OAAO;AACL,kFAAkF;AAClF,QAAQ,GACT,MAAM,+BAA+B,CAAA;AACtC,OAAO;AACL,uGAAuG;AACvG,iBAAiB,GAClB,MAAM,2CAA2C,CAAA;AAClD,OAAO;AACL,6FAA6F;AAC7F,eAAe;AACf,4FAA4F;AAC5F,iBAAiB,GAClB,MAAM,gCAAgC,CAAA;AACvC,OAAO;AACL,iGAAiG;AACjG,KAAK,cAAc;AACnB,kGAAkG;AAClG,KAAK,eAAe;AACpB,kGAAkG;AAClG,eAAe,GAChB,MAAM,wCAAwC,CAAA;AAC/C,OAAO;AACL,4FAA4F;AAC5F,YAAY,GACb,MAAM,qCAAqC,CAAA;AAC5C,OAAO;AACL,yFAAyF;AACzF,UAAU,IAAI,aAAa,GAC5B,MAAM,oCAAoC,CAAA;AAC3C,OAAO;AACL,8FAA8F;AAC9F,aAAa,GACd,MAAM,sCAAsC,CAAA;AAC7C,OAAO;AACL,qFAAqF;AACrF,KAAK,GACN,MAAM,qCAAqC,CAAA;AAC5C,OAAO;AACL,oGAAoG;AACpG,gBAAgB,GACjB,MAAM,yCAAyC,CAAA;AAChD,OAAO;AACL,mGAAmG;AACnG,iBAAiB,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO;AACL,wFAAwF;AACxF,UAAU,GACX,MAAM,mCAAmC,CAAA;AAC1C;;;GAGG;AACH,OAAO;AACL,yFAAyF;AACzF,UAAU,GACX,MAAM,oCAAoC,CAAA;AAC3C,OAAO;AACL,6FAA6F;AAC7F,YAAY,GACb,MAAM,sCAAsC,CAAA;AAC7C,OAAO;AACL,8FAA8F;AAC9F,cAAc,GACf,MAAM,qCAAqC,CAAA;AAC5C,OAAO;AACL,uFAAuF;AACvF,UAAU,GACX,MAAM,kCAAkC,CAAA;AACzC,OAAO;AACL,+FAA+F;AAC/F,cAAc,GACf,MAAM,sCAAsC,CAAA;AAC7C,OAAO;AACL,uFAAuF;AACvF,UAAU,GACX,MAAM,kCAAkC,CAAA;AACzC,OAAO;AACL,iGAAiG;AACjG,eAAe,GAChB,MAAM,uCAAuC,CAAA;AAC9C,OAAO;AACL,4FAA4F;AAC5F,iBAAiB;AACjB,4FAA4F;AAC5F,iBAAiB;AACjB,oFAAoF;AACpF,SAAS,GACV,MAAM,gCAAgC,CAAA;AACvC,OAAO;AACL,iGAAiG;AACjG,eAAe;AACf,gGAAgG;AAChG,cAAc,GACf,MAAM,uCAAuC,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,KAAK,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAChH,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC5G,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,81 +1,80 @@
|
|
|
1
|
-
import { fetchDocument } from "./fetch-document.js";
|
|
2
|
-
import { fetchWithProxyFallback } from "./fetch-with-proxy-fallback.js";
|
|
3
|
-
import { normalizeMimeType } from "./normalize-mime-type.js";
|
|
4
|
-
import { normalizeMimeTypeObject } from "./normalize-mime-type-object.js";
|
|
5
|
-
import { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from "./parse.js";
|
|
6
|
-
import { prettyPrintJson, replaceCircularDependencies } from "./pretty-print-json.js";
|
|
7
|
-
import { shouldUseProxy, redirectToProxy } from "./redirect-to-proxy.js";
|
|
8
|
-
import { schemaModel } from "./schema-model.js";
|
|
9
|
-
import { shouldIgnoreEntity } from "./should-ignore-entity.js";
|
|
10
|
-
import { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from "./operation-stability.js";
|
|
11
|
-
import { getServersFromDocument } from "./servers.js";
|
|
12
|
-
import {
|
|
13
|
-
createHash
|
|
14
|
-
} from "@scalar/helpers/string/create-hash";
|
|
15
1
|
import {
|
|
16
2
|
isDefined
|
|
17
3
|
} from "@scalar/helpers/array/is-defined";
|
|
4
|
+
import {
|
|
5
|
+
json2xml
|
|
6
|
+
} from "@scalar/helpers/file/json2xml";
|
|
7
|
+
import {
|
|
8
|
+
canMethodHaveBody
|
|
9
|
+
} from "@scalar/helpers/http/can-method-have-body";
|
|
10
|
+
import {
|
|
11
|
+
REQUEST_METHODS,
|
|
12
|
+
getHttpMethodInfo
|
|
13
|
+
} from "@scalar/helpers/http/http-info";
|
|
14
|
+
import {
|
|
15
|
+
httpStatusCodes
|
|
16
|
+
} from "@scalar/helpers/http/http-status-codes";
|
|
18
17
|
import {
|
|
19
18
|
isHttpMethod
|
|
20
19
|
} from "@scalar/helpers/http/is-http-method";
|
|
21
20
|
import {
|
|
22
|
-
|
|
23
|
-
} from "@scalar/helpers/
|
|
21
|
+
objectKeys
|
|
22
|
+
} from "@scalar/helpers/object/object-keys";
|
|
24
23
|
import {
|
|
25
|
-
|
|
26
|
-
} from "@scalar/helpers/
|
|
24
|
+
findVariables
|
|
25
|
+
} from "@scalar/helpers/regex/find-variables";
|
|
27
26
|
import {
|
|
28
|
-
|
|
29
|
-
} from "@scalar/helpers/
|
|
27
|
+
REGEX
|
|
28
|
+
} from "@scalar/helpers/regex/regex-helpers";
|
|
29
|
+
import {
|
|
30
|
+
replaceVariables
|
|
31
|
+
} from "@scalar/helpers/regex/replace-variables";
|
|
30
32
|
import {
|
|
31
33
|
camelToTitleWords
|
|
32
34
|
} from "@scalar/helpers/string/camel-to-title";
|
|
33
35
|
import {
|
|
34
|
-
|
|
35
|
-
} from "@scalar/helpers/
|
|
36
|
+
capitalize
|
|
37
|
+
} from "@scalar/helpers/string/capitalize";
|
|
36
38
|
import {
|
|
37
|
-
|
|
38
|
-
} from "@scalar/helpers/
|
|
39
|
+
createHash
|
|
40
|
+
} from "@scalar/helpers/string/create-hash";
|
|
39
41
|
import {
|
|
40
|
-
|
|
41
|
-
} from "@scalar/helpers/
|
|
42
|
+
iterateTitle
|
|
43
|
+
} from "@scalar/helpers/string/iterate-title";
|
|
42
44
|
import {
|
|
43
45
|
ensureProtocol
|
|
44
46
|
} from "@scalar/helpers/url/ensure-protocol";
|
|
45
47
|
import {
|
|
46
|
-
|
|
47
|
-
} from "@scalar/helpers/
|
|
48
|
-
import {
|
|
49
|
-
canMethodHaveBody
|
|
50
|
-
} from "@scalar/helpers/http/can-method-have-body";
|
|
51
|
-
import {
|
|
52
|
-
getHttpMethodInfo
|
|
53
|
-
} from "@scalar/helpers/http/http-info";
|
|
54
|
-
import {
|
|
55
|
-
REQUEST_METHODS
|
|
56
|
-
} from "@scalar/helpers/http/http-info";
|
|
48
|
+
isLocalUrl
|
|
49
|
+
} from "@scalar/helpers/url/is-local-url";
|
|
57
50
|
import {
|
|
58
|
-
|
|
59
|
-
} from "@scalar/helpers/
|
|
51
|
+
isRelativePath
|
|
52
|
+
} from "@scalar/helpers/url/is-relative-path";
|
|
60
53
|
import {
|
|
61
54
|
isValidUrl
|
|
62
55
|
} from "@scalar/helpers/url/is-valid-url";
|
|
63
|
-
import {
|
|
64
|
-
iterateTitle
|
|
65
|
-
} from "@scalar/helpers/string/iterate-title";
|
|
66
56
|
import {
|
|
67
57
|
makeUrlAbsolute
|
|
68
58
|
} from "@scalar/helpers/url/make-url-absolute";
|
|
69
59
|
import {
|
|
60
|
+
combineUrlAndPath,
|
|
70
61
|
mergeSearchParams,
|
|
71
62
|
mergeUrls
|
|
72
63
|
} from "@scalar/helpers/url/merge-urls";
|
|
73
64
|
import {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} from "
|
|
65
|
+
redirectToProxy,
|
|
66
|
+
shouldUseProxy
|
|
67
|
+
} from "@scalar/helpers/url/redirect-to-proxy";
|
|
68
|
+
import { fetchDocument } from "./fetch-document.js";
|
|
69
|
+
import { fetchWithProxyFallback } from "./fetch-with-proxy-fallback.js";
|
|
70
|
+
import { normalizeMimeType } from "./normalize-mime-type.js";
|
|
71
|
+
import { normalizeMimeTypeObject } from "./normalize-mime-type-object.js";
|
|
72
|
+
import { getOperationStability, getOperationStabilityColor, isOperationDeprecated } from "./operation-stability.js";
|
|
73
|
+
import { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from "./parse.js";
|
|
74
|
+
import { prettyPrintJson, replaceCircularDependencies } from "./pretty-print-json.js";
|
|
75
|
+
import { schemaModel } from "./schema-model.js";
|
|
76
|
+
import { getServersFromDocument } from "./servers.js";
|
|
77
|
+
import { shouldIgnoreEntity } from "./should-ignore-entity.js";
|
|
79
78
|
export {
|
|
80
79
|
REGEX,
|
|
81
80
|
REQUEST_METHODS,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/index.ts"],
|
|
4
|
-
"sourcesContent": ["export {
|
|
5
|
-
"mappings": "AAAA
|
|
4
|
+
"sourcesContent": ["export {\n /** @deprecated Please use isDefined from \\@scalar/helpers/array/is-defined instead */\n isDefined,\n} from '@scalar/helpers/array/is-defined'\nexport {\n /** @deprecated Please use json2xml from \\@scalar/helpers/file/json2xml instead */\n json2xml,\n} from '@scalar/helpers/file/json2xml'\nexport {\n /** @deprecated Please use canMethodHaveBody from \\@scalar/helpers/http/can-method-have-body instead */\n canMethodHaveBody,\n} from '@scalar/helpers/http/can-method-have-body'\nexport {\n /** @deprecated Please use REQUEST_METHODS from \\@scalar/helpers/http/http-methods instead */\n REQUEST_METHODS,\n /** @deprecated Please use getHttpMethodInfo from \\@scalar/helpers/http/http-info instead */\n getHttpMethodInfo,\n} from '@scalar/helpers/http/http-info'\nexport {\n /** @deprecated Please use HttpStatusCode from \\@scalar/helpers/http/http-status-codes instead */\n type HttpStatusCode,\n /** @deprecated Please use HttpStatusCodes from \\@scalar/helpers/http/http-status-codes instead */\n type HttpStatusCodes,\n /** @deprecated Please use httpStatusCodes from \\@scalar/helpers/http/http-status-codes instead */\n httpStatusCodes,\n} from '@scalar/helpers/http/http-status-codes'\nexport {\n /** @deprecated Please use isHttpMethod from \\@scalar/helpers/http/is-http-method instead */\n isHttpMethod,\n} from '@scalar/helpers/http/is-http-method'\nexport {\n /** @deprecated Please use objectKeys from \\@scalar/helpers/object/object-keys instead */\n objectKeys as getObjectKeys,\n} from '@scalar/helpers/object/object-keys'\nexport {\n /** @deprecated Please use findVariables from \\@scalar/helpers/regex/find-variables instead */\n findVariables,\n} from '@scalar/helpers/regex/find-variables'\nexport {\n /** @deprecated Please use REGEX from \\@scalar/helpers/regex/regex-helpers instead */\n REGEX,\n} from '@scalar/helpers/regex/regex-helpers'\nexport {\n /** @deprecated Please use replaceVariables from \\@scalar/helpers/regex/replace-variables instead */\n replaceVariables,\n} from '@scalar/helpers/regex/replace-variables'\nexport {\n /** @deprecated Please use camelToTitleWords from \\@scalar/helpers/string/camel-to-title instead */\n camelToTitleWords,\n} from '@scalar/helpers/string/camel-to-title'\nexport {\n /** @deprecated Please use capitalize from \\@scalar/helpers/string/capitalize instead */\n capitalize,\n} from '@scalar/helpers/string/capitalize'\n/**\n * @deprecated These helpers are being phased out. Please import directly from @scalar/helpers instead.\n * For example: import { createHash } from '\\@scalar/helpers/string/create-hash'\n */\nexport {\n /** @deprecated Please use createHash from \\@scalar/helpers/string/create-hash instead */\n createHash,\n} from '@scalar/helpers/string/create-hash'\nexport {\n /** @deprecated Please use iterateTitle from \\@scalar/helpers/string/iterate-title instead */\n iterateTitle,\n} from '@scalar/helpers/string/iterate-title'\nexport {\n /** @deprecated Please use ensureProtocol from \\@scalar/helpers/url/ensure-protocol instead */\n ensureProtocol,\n} from '@scalar/helpers/url/ensure-protocol'\nexport {\n /** @deprecated Please use isLocalUrl from \\@scalar/helpers/url/is-local-url instead */\n isLocalUrl,\n} from '@scalar/helpers/url/is-local-url'\nexport {\n /** @deprecated Please use isRelativePath from \\@scalar/helpers/url/is-relative-path instead */\n isRelativePath,\n} from '@scalar/helpers/url/is-relative-path'\nexport {\n /** @deprecated Please use isValidUrl from \\@scalar/helpers/url/is-valid-url instead */\n isValidUrl,\n} from '@scalar/helpers/url/is-valid-url'\nexport {\n /** @deprecated Please use makeUrlAbsolute from \\@scalar/helpers/url/make-url-absolute instead */\n makeUrlAbsolute,\n} from '@scalar/helpers/url/make-url-absolute'\nexport {\n /** @deprecated Please use combineUrlAndPath from \\@scalar/helpers/url/merge-urls instead */\n combineUrlAndPath,\n /** @deprecated Please use mergeSearchParams from \\@scalar/helpers/url/merge-urls instead */\n mergeSearchParams,\n /** @deprecated Please use mergeUrls from \\@scalar/helpers/url/merge-urls instead */\n mergeUrls,\n} from '@scalar/helpers/url/merge-urls'\nexport {\n /** @deprecated Please use redirectToProxy from \\@scalar/helpers/url/redirect-to-proxy instead */\n redirectToProxy,\n /** @deprecated Please use shouldUseProxy from \\@scalar/helpers/url/redirect-to-proxy instead */\n shouldUseProxy,\n} from '@scalar/helpers/url/redirect-to-proxy'\n\nexport { fetchDocument } from './fetch-document'\nexport { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback'\nexport { normalizeMimeType } from './normalize-mime-type'\nexport { normalizeMimeTypeObject } from './normalize-mime-type-object'\nexport { getOperationStability, getOperationStabilityColor, isOperationDeprecated } from './operation-stability'\nexport { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse'\nexport { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json'\nexport { schemaModel } from './schema-model'\nexport { getServersFromDocument } from './servers'\nexport { shouldIgnoreEntity } from './should-ignore-entity'\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAME;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEgB;AAAA,OACT;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AAKP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,qBAAqB;AAC9B,SAA6C,8BAA8B;AAC3E,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AACxC,SAAS,uBAAuB,4BAA4B,6BAA6B;AACzF,SAAS,wBAAwB,cAAc,MAAM,iBAAiB,iBAAiB,YAAY;AACnG,SAAS,iBAAiB,mCAAmC;AAC7D,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.6.
|
|
19
|
+
"version": "0.6.24",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -89,13 +89,13 @@
|
|
|
89
89
|
"type-fest": "^5.3.1",
|
|
90
90
|
"yaml": "^2.8.0",
|
|
91
91
|
"zod": "^4.3.5",
|
|
92
|
+
"@scalar/helpers": "0.2.8",
|
|
92
93
|
"@scalar/json-magic": "0.9.2",
|
|
93
94
|
"@scalar/object-utils": "1.2.22",
|
|
94
|
-
"@scalar/helpers": "0.2.8",
|
|
95
|
-
"@scalar/openapi-types": "0.5.3",
|
|
96
95
|
"@scalar/themes": "0.13.26",
|
|
97
96
|
"@scalar/types": "0.5.8",
|
|
98
|
-
"@scalar/
|
|
97
|
+
"@scalar/openapi-types": "0.5.3",
|
|
98
|
+
"@scalar/workspace-store": "0.25.3"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@types/node": "^22.19.3",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"vitest": "4.0.16",
|
|
104
104
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
105
105
|
"@scalar/build-tooling": "0.4.1",
|
|
106
|
-
"@scalar/openapi-parser": "0.24.
|
|
106
|
+
"@scalar/openapi-parser": "0.24.3",
|
|
107
107
|
"@scalar/openapi-types": "0.5.3"
|
|
108
108
|
},
|
|
109
109
|
"scripts": {
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redirects the request to a proxy server with a given URL. But not for:
|
|
3
|
-
*
|
|
4
|
-
* - Relative URLs
|
|
5
|
-
* - URLs that seem to point to a local IP (except the proxy is on the same domain)
|
|
6
|
-
* - URLs that don't look like a domain
|
|
7
|
-
**/
|
|
8
|
-
export declare function redirectToProxy(proxyUrl?: string, url?: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* Returns false for requests to localhost, relative URLs, if no proxy is defined …
|
|
11
|
-
**/
|
|
12
|
-
export declare function shouldUseProxy(proxyUrl?: string, url?: string): url is string;
|
|
13
|
-
//# sourceMappingURL=redirect-to-proxy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redirect-to-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirect-to-proxy.ts"],"names":[],"mappings":"AAGA;;;;;;IAMI;AACJ,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAkCvE;AAED;;IAEI;AACJ,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,IAAI,MAAM,CAkC7E"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { isLocalUrl } from "@scalar/helpers/url/is-local-url";
|
|
2
|
-
import { isRelativePath } from "@scalar/helpers/url/is-relative-path";
|
|
3
|
-
function redirectToProxy(proxyUrl, url) {
|
|
4
|
-
try {
|
|
5
|
-
if (!shouldUseProxy(proxyUrl, url)) {
|
|
6
|
-
return url ?? "";
|
|
7
|
-
}
|
|
8
|
-
const newUrl = new URL(url);
|
|
9
|
-
const temporaryProxyUrl = isRelativePath(proxyUrl) ? `http://localhost${proxyUrl}` : proxyUrl;
|
|
10
|
-
newUrl.href = temporaryProxyUrl;
|
|
11
|
-
newUrl.searchParams.append("scalar_url", url);
|
|
12
|
-
const result = isRelativePath(proxyUrl) ? newUrl.toString().replace(/^http:\/\/localhost/, "") : newUrl.toString();
|
|
13
|
-
return result;
|
|
14
|
-
} catch {
|
|
15
|
-
return url ?? "";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function shouldUseProxy(proxyUrl, url) {
|
|
19
|
-
try {
|
|
20
|
-
if (!proxyUrl || !url) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (isRelativePath(url)) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (isRelativePath(proxyUrl)) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
if (isLocalUrl(proxyUrl)) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
if (isLocalUrl(url)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export {
|
|
41
|
-
redirectToProxy,
|
|
42
|
-
shouldUseProxy
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=redirect-to-proxy.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/redirect-to-proxy.ts"],
|
|
4
|
-
"sourcesContent": ["import { isLocalUrl } from '@scalar/helpers/url/is-local-url'\nimport { isRelativePath } from '@scalar/helpers/url/is-relative-path'\n\n/**\n * Redirects the request to a proxy server with a given URL. But not for:\n *\n * - Relative URLs\n * - URLs that seem to point to a local IP (except the proxy is on the same domain)\n * - URLs that don't look like a domain\n **/\nexport function redirectToProxy(proxyUrl?: string, url?: string): string {\n try {\n if (!shouldUseProxy(proxyUrl, url)) {\n return url ?? ''\n }\n\n // Create new URL object from url\n const newUrl = new URL(url)\n\n // Add temporary domain for relative proxy URLs\n //\n // Q: Why isn't proxyUrl type guarded?\n // A: Type guarding works for one parameter only (as of now).\n //\n // Q: Why do we need to add http://localhost to relative proxy URLs?\n // A: Because the `new URL()` would otherwise fail.\n //\n const temporaryProxyUrl = isRelativePath(proxyUrl as string) ? `http://localhost${proxyUrl}` : (proxyUrl as string)\n\n // Rewrite the URL with the proxy\n newUrl.href = temporaryProxyUrl\n\n // Add the original URL as a query parameter\n newUrl.searchParams.append('scalar_url', url)\n\n // Remove the temporary domain if we added it, but only from the start of the URL\n const result = isRelativePath(proxyUrl as string)\n ? newUrl.toString().replace(/^http:\\/\\/localhost/, '')\n : newUrl.toString()\n\n return result\n } catch {\n return url ?? ''\n }\n}\n\n/**\n * Returns false for requests to localhost, relative URLs, if no proxy is defined \u2026\n **/\nexport function shouldUseProxy(proxyUrl?: string, url?: string): url is string {\n try {\n // \u274C We don't have a proxy URL or the URL\n if (!proxyUrl || !url) {\n return false\n }\n\n // \u274C Request to relative URLs (won't be blocked by CORS anyway)\n if (isRelativePath(url)) {\n return false\n }\n\n // \u2705 Proxy URL is on the same domain (e.g. /proxy)\n // It's more likely (not guaranteed, though) that the proxy has access to local domains.\n if (isRelativePath(proxyUrl)) {\n return true\n }\n\n // \u2705 Proxy URL is local\n if (isLocalUrl(proxyUrl)) {\n return true\n }\n\n // \u274C Requests to localhost\n // We won't reach them from a (likely remote) proxy.\n if (isLocalUrl(url)) {\n return false\n }\n\n // \u2705 Seems fine (e.g. remote proxy + remote URL)\n return true\n } catch {\n return false\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AASxB,SAAS,gBAAgB,UAAmB,KAAsB;AACvE,MAAI;AACF,QAAI,CAAC,eAAe,UAAU,GAAG,GAAG;AAClC,aAAO,OAAO;AAAA,IAChB;AAGA,UAAM,SAAS,IAAI,IAAI,GAAG;AAU1B,UAAM,oBAAoB,eAAe,QAAkB,IAAI,mBAAmB,QAAQ,KAAM;AAGhG,WAAO,OAAO;AAGd,WAAO,aAAa,OAAO,cAAc,GAAG;AAG5C,UAAM,SAAS,eAAe,QAAkB,IAC5C,OAAO,SAAS,EAAE,QAAQ,uBAAuB,EAAE,IACnD,OAAO,SAAS;AAEpB,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,OAAO;AAAA,EAChB;AACF;AAKO,SAAS,eAAe,UAAmB,KAA6B;AAC7E,MAAI;AAEF,QAAI,CAAC,YAAY,CAAC,KAAK;AACrB,aAAO;AAAA,IACT;AAGA,QAAI,eAAe,GAAG,GAAG;AACvB,aAAO;AAAA,IACT;AAIA,QAAI,eAAe,QAAQ,GAAG;AAC5B,aAAO;AAAA,IACT;AAGA,QAAI,WAAW,QAAQ,GAAG;AACxB,aAAO;AAAA,IACT;AAIA,QAAI,WAAW,GAAG,GAAG;AACnB,aAAO;AAAA,IACT;AAGA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|