@scalar/oas-utils 0.4.0 → 0.4.2
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 +13 -0
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +3 -1
- package/dist/helpers/index.js.map +2 -2
- package/dist/helpers/local-storage.d.ts +13 -0
- package/dist/helpers/local-storage.d.ts.map +1 -1
- package/dist/helpers/local-storage.js +11 -1
- package/dist/helpers/local-storage.js.map +2 -2
- package/dist/helpers/redirect-to-proxy.d.ts.map +1 -1
- package/dist/helpers/redirect-to-proxy.js +0 -1
- package/dist/helpers/redirect-to-proxy.js.map +2 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7ca47ab: fix: add ssr safe alias for local storage
|
|
8
|
+
|
|
9
|
+
## 0.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [85877aa]
|
|
14
|
+
- @scalar/themes@0.13.1
|
|
15
|
+
|
|
3
16
|
## 0.4.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { isLocalUrl } from './is-local-url.js';
|
|
|
10
10
|
export { isValidUrl } from './is-valid-url.js';
|
|
11
11
|
export { iterateTitle } from './iterate-title.js';
|
|
12
12
|
export { json2xml } from './json2xml.js';
|
|
13
|
-
export { LS_KEYS } from './local-storage.js';
|
|
13
|
+
export { LS_KEYS, REFERENCE_LS_KEYS, safeLocalStorage } from './local-storage.js';
|
|
14
14
|
export { makeUrlAbsolute } from './make-url-absolute.js';
|
|
15
15
|
export { combineUrlAndPath, mergeSearchParams, mergeUrls } from './merge-urls.js';
|
|
16
16
|
export { normalizeMimeType } from './normalize-mime-type.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,KAAK,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACpG,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,KAAK,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACpG,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACrD,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,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isLocalUrl } from "./is-local-url.js";
|
|
|
10
10
|
import { isValidUrl } from "./is-valid-url.js";
|
|
11
11
|
import { iterateTitle } from "./iterate-title.js";
|
|
12
12
|
import { json2xml } from "./json2xml.js";
|
|
13
|
-
import { LS_KEYS } from "./local-storage.js";
|
|
13
|
+
import { LS_KEYS, REFERENCE_LS_KEYS, safeLocalStorage } from "./local-storage.js";
|
|
14
14
|
import { makeUrlAbsolute } from "./make-url-absolute.js";
|
|
15
15
|
import { combineUrlAndPath, mergeSearchParams, mergeUrls } from "./merge-urls.js";
|
|
16
16
|
import { normalizeMimeType } from "./normalize-mime-type.js";
|
|
@@ -27,6 +27,7 @@ import { defaultStateFactory, ssrState } from "./ssr-state.js";
|
|
|
27
27
|
import { camelToTitleWords, capitalize } from "./string.js";
|
|
28
28
|
export {
|
|
29
29
|
LS_KEYS,
|
|
30
|
+
REFERENCE_LS_KEYS,
|
|
30
31
|
REGEX,
|
|
31
32
|
REQUEST_METHODS,
|
|
32
33
|
camelToTitleWords,
|
|
@@ -63,6 +64,7 @@ export {
|
|
|
63
64
|
redirectToProxy,
|
|
64
65
|
replaceCircularDependencies,
|
|
65
66
|
replaceVariables,
|
|
67
|
+
safeLocalStorage,
|
|
66
68
|
schemaModel,
|
|
67
69
|
shouldIgnoreEntity,
|
|
68
70
|
shouldUseProxy,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { createHash } from './create-hash'\nexport { ensureProtocol } from './ensure-protocol'\nexport { fetchDocument } from './fetch-document'\nexport { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback'\nexport { findVariables } from './find-variables'\nexport { canMethodHaveBody, getHttpMethodInfo, isHttpMethod, REQUEST_METHODS } from './http-methods'\nexport { type HttpStatusCode, type HttpStatusCodes, httpStatusCodes } from './http-status-codes'\nexport { isDefined } from './is-defined'\nexport { isLocalUrl } from './is-local-url'\nexport { isValidUrl } from './is-valid-url'\nexport { iterateTitle } from './iterate-title'\nexport { json2xml } from './json2xml'\nexport { LS_KEYS } from './local-storage'\nexport { makeUrlAbsolute } from './make-url-absolute'\nexport { combineUrlAndPath, mergeSearchParams, mergeUrls } from './merge-urls'\nexport { normalizeMimeType } from './normalize-mime-type'\nexport { normalizeMimeTypeObject } from './normalize-mime-type-object'\nexport { objectMerge, getObjectKeys } from './object'\nexport { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse'\nexport { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json'\nexport { redirectToProxy, isRelativePath, shouldUseProxy } from './redirect-to-proxy'\nexport { REGEX } from './regex-helpers'\nexport { replaceVariables } from './replace-variables'\nexport { schemaModel } from './schema-model'\nexport { shouldIgnoreEntity } from './should-ignore-entity'\nexport { defaultStateFactory, ssrState } from './ssr-state'\nexport { camelToTitleWords, capitalize } from './string'\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAA6C,8BAA8B;AAC3E,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB,mBAAmB,cAAc,uBAAuB;AACpF,SAAoD,uBAAuB;AAC3E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,
|
|
4
|
+
"sourcesContent": ["export { createHash } from './create-hash'\nexport { ensureProtocol } from './ensure-protocol'\nexport { fetchDocument } from './fetch-document'\nexport { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback'\nexport { findVariables } from './find-variables'\nexport { canMethodHaveBody, getHttpMethodInfo, isHttpMethod, REQUEST_METHODS } from './http-methods'\nexport { type HttpStatusCode, type HttpStatusCodes, httpStatusCodes } from './http-status-codes'\nexport { isDefined } from './is-defined'\nexport { isLocalUrl } from './is-local-url'\nexport { isValidUrl } from './is-valid-url'\nexport { iterateTitle } from './iterate-title'\nexport { json2xml } from './json2xml'\nexport { LS_KEYS, REFERENCE_LS_KEYS, safeLocalStorage } from './local-storage'\nexport { makeUrlAbsolute } from './make-url-absolute'\nexport { combineUrlAndPath, mergeSearchParams, mergeUrls } from './merge-urls'\nexport { normalizeMimeType } from './normalize-mime-type'\nexport { normalizeMimeTypeObject } from './normalize-mime-type-object'\nexport { objectMerge, getObjectKeys } from './object'\nexport { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse'\nexport { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json'\nexport { redirectToProxy, isRelativePath, shouldUseProxy } from './redirect-to-proxy'\nexport { REGEX } from './regex-helpers'\nexport { replaceVariables } from './replace-variables'\nexport { schemaModel } from './schema-model'\nexport { shouldIgnoreEntity } from './should-ignore-entity'\nexport { defaultStateFactory, ssrState } from './ssr-state'\nexport { camelToTitleWords, capitalize } from './string'\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAA6C,8BAA8B;AAC3E,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB,mBAAmB,cAAc,uBAAuB;AACpF,SAAoD,uBAAuB;AAC3E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,SAAS,mBAAmB,wBAAwB;AAC7D,SAAS,uBAAuB;AAChC,SAAS,mBAAmB,mBAAmB,iBAAiB;AAChE,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AACxC,SAAS,aAAa,qBAAqB;AAC3C,SAAS,wBAAwB,cAAc,MAAM,iBAAiB,iBAAiB,YAAY;AACnG,SAAS,iBAAiB,mCAAmC;AAC7D,SAAS,iBAAiB,gBAAgB,sBAAsB;AAChE,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,mBAAmB,kBAAkB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,4 +13,17 @@ export declare const LS_KEYS: {
|
|
|
13
13
|
readonly TAG: "tag";
|
|
14
14
|
readonly WORKSPACE: "workspace";
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* localStorage keys for all reference resources
|
|
18
|
+
* to ensure we do not have any conflicts
|
|
19
|
+
*/
|
|
20
|
+
export declare const REFERENCE_LS_KEYS: {
|
|
21
|
+
readonly SELECTED_CLIENT: "scalar-reference-selected-client";
|
|
22
|
+
};
|
|
23
|
+
/** SSR safe alias for localStorage */
|
|
24
|
+
export declare const safeLocalStorage: Storage | {
|
|
25
|
+
getItem: () => null;
|
|
26
|
+
setItem: () => null;
|
|
27
|
+
removeItem: () => null;
|
|
28
|
+
};
|
|
16
29
|
//# sourceMappingURL=local-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/helpers/local-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;CAUV,CAAA"}
|
|
1
|
+
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/helpers/local-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;CAUV,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;CAEpB,CAAA;AAEV,sCAAsC;AACtC,eAAO,MAAM,gBAAgB;;;;CAOX,CAAA"}
|
|
@@ -9,7 +9,17 @@ const LS_KEYS = {
|
|
|
9
9
|
TAG: "tag",
|
|
10
10
|
WORKSPACE: "workspace"
|
|
11
11
|
};
|
|
12
|
+
const REFERENCE_LS_KEYS = {
|
|
13
|
+
SELECTED_CLIENT: "scalar-reference-selected-client"
|
|
14
|
+
};
|
|
15
|
+
const safeLocalStorage = typeof window === "undefined" ? {
|
|
16
|
+
getItem: () => null,
|
|
17
|
+
setItem: () => null,
|
|
18
|
+
removeItem: () => null
|
|
19
|
+
} : localStorage;
|
|
12
20
|
export {
|
|
13
|
-
LS_KEYS
|
|
21
|
+
LS_KEYS,
|
|
22
|
+
REFERENCE_LS_KEYS,
|
|
23
|
+
safeLocalStorage
|
|
14
24
|
};
|
|
15
25
|
//# sourceMappingURL=local-storage.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/local-storage.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * localStorage keys for resources\n * DO NOT CHANGE THESE AS IT WILL BREAK THE MIGRATION\n */\nexport const LS_KEYS = {\n COLLECTION: 'collection',\n COOKIE: 'cookie',\n ENVIRONMENT: 'environment',\n REQUEST: 'request',\n REQUEST_EXAMPLE: 'requestExample',\n SECURITY_SCHEME: 'securityScheme',\n SERVER: 'server',\n TAG: 'tag',\n WORKSPACE: 'workspace',\n} as const\n"],
|
|
5
|
-
"mappings": "AAIO,MAAM,UAAU;AAAA,EACrB,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,WAAW;AACb;",
|
|
4
|
+
"sourcesContent": ["/**\n * localStorage keys for resources\n * DO NOT CHANGE THESE AS IT WILL BREAK THE MIGRATION\n */\nexport const LS_KEYS = {\n COLLECTION: 'collection',\n COOKIE: 'cookie',\n ENVIRONMENT: 'environment',\n REQUEST: 'request',\n REQUEST_EXAMPLE: 'requestExample',\n SECURITY_SCHEME: 'securityScheme',\n SERVER: 'server',\n TAG: 'tag',\n WORKSPACE: 'workspace',\n} as const\n\n/**\n * localStorage keys for all reference resources\n * to ensure we do not have any conflicts\n */\nexport const REFERENCE_LS_KEYS = {\n SELECTED_CLIENT: 'scalar-reference-selected-client',\n} as const\n\n/** SSR safe alias for localStorage */\nexport const safeLocalStorage =\n typeof window === 'undefined'\n ? {\n getItem: () => null,\n setItem: () => null,\n removeItem: () => null,\n }\n : localStorage\n"],
|
|
5
|
+
"mappings": "AAIO,MAAM,UAAU;AAAA,EACrB,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,WAAW;AACb;AAMO,MAAM,oBAAoB;AAAA,EAC/B,iBAAiB;AACnB;AAGO,MAAM,mBACX,OAAO,WAAW,cACd;AAAA,EACE,SAAS,MAAM;AAAA,EACf,SAAS,MAAM;AAAA,EACf,YAAY,MAAM;AACpB,IACA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED;;IAEI;AACJ,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,IAAI,MAAM,CAkC7E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/redirect-to-proxy.ts"],
|
|
4
|
-
"sourcesContent": ["import { isLocalUrl } from './is-local-url'\nimport { REGEX } from './regex-helpers'\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\u2019t look like a domain\n **/\nexport function redirectToProxy(proxyUrl?: string, url?: string): string {\n try {\n if (!shouldUseProxy(proxyUrl, url)) {\n
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AASf,SAAS,gBAAgB,UAAmB,KAAsB;AACvE,MAAI;AACF,QAAI,CAAC,eAAe,UAAU,GAAG,GAAG;AAClC,
|
|
4
|
+
"sourcesContent": ["import { isLocalUrl } from './is-local-url'\nimport { REGEX } from './regex-helpers'\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\u2019t 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\u2019t 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 * Check if the URL is relative or if it's a domain without protocol\n **/\nexport const isRelativePath = (url: string) => {\n // Allow http:// https:// and other protocols such as file://\n if (REGEX.PROTOCOL.test(url)) {\n return false\n }\n\n // Check if it looks like a domain (contains dots and no spaces)\n // This catches cases like \"galaxy.scalar.com/planets\"\n if (/^[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+(\\/|$)/.test(url)) {\n return false\n }\n\n return true\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\u2019t have a proxy URL or the URL\n if (!proxyUrl || !url) {\n return false\n }\n\n // \u274C Request to relative URLs (won\u2019t 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\u2019s 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\u2019t 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,aAAa;AASf,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,MAAM,iBAAiB,CAAC,QAAgB;AAE7C,MAAI,MAAM,SAAS,KAAK,GAAG,GAAG;AAC5B,WAAO;AAAA,EACT;AAIA,MAAI,uCAAuC,KAAK,GAAG,GAAG;AACpD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;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
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.4.
|
|
19
|
+
"version": "0.4.2",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"type-fest": "^4.20.0",
|
|
94
94
|
"yaml": "^2.4.5",
|
|
95
95
|
"zod": "3.24.1",
|
|
96
|
-
"@scalar/object-utils": "1.2.1",
|
|
97
96
|
"@scalar/openapi-types": "0.3.1",
|
|
98
|
-
"@scalar/themes": "0.13.
|
|
99
|
-
"@scalar/types": "0.2.1"
|
|
97
|
+
"@scalar/themes": "0.13.1",
|
|
98
|
+
"@scalar/types": "0.2.1",
|
|
99
|
+
"@scalar/object-utils": "1.2.1"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@types/node": "^20.17.10",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"vite": "5.4.19",
|
|
105
105
|
"vitest": "^1.6.0",
|
|
106
106
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
107
|
-
"@scalar/openapi-parser": "0.
|
|
107
|
+
"@scalar/openapi-parser": "0.14.0",
|
|
108
108
|
"@scalar/build-tooling": "0.2.1",
|
|
109
109
|
"@scalar/openapi-types": "0.3.1"
|
|
110
110
|
},
|