@scalar/workspace-store 0.42.0 → 0.43.0
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 +15 -0
- package/dist/events/definitions/operation.d.ts +6 -1
- package/dist/events/definitions/operation.d.ts.map +1 -1
- package/dist/events/definitions/server.d.ts +5 -1
- package/dist/events/definitions/server.d.ts.map +1 -1
- package/dist/events/definitions/ui.d.ts +5 -3
- package/dist/events/definitions/ui.d.ts.map +1 -1
- package/dist/helpers/get-resolved-ref-deep.d.ts +27 -0
- package/dist/helpers/get-resolved-ref-deep.d.ts.map +1 -0
- package/dist/helpers/get-resolved-ref-deep.js +49 -0
- package/dist/mutators/operation/operation.d.ts +1 -1
- package/dist/mutators/operation/operation.d.ts.map +1 -1
- package/dist/mutators/operation/operation.js +4 -4
- package/dist/mutators/server.d.ts +1 -1
- package/dist/mutators/server.d.ts.map +1 -1
- package/dist/mutators/server.js +5 -2
- package/dist/navigation/helpers/traverse-description.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-description.js +19 -21
- package/dist/navigation/helpers/utils.js +2 -2
- package/dist/request-example/builder/body/build-request-body.d.ts +42 -0
- package/dist/request-example/builder/body/build-request-body.d.ts.map +1 -0
- package/dist/request-example/builder/body/build-request-body.js +134 -0
- package/dist/request-example/builder/body/get-request-body-example.d.ts +6 -0
- package/dist/request-example/builder/body/get-request-body-example.d.ts.map +1 -0
- package/dist/request-example/builder/body/get-request-body-example.js +31 -0
- package/dist/request-example/builder/body/get-selected-body-content-type.d.ts +10 -0
- package/dist/request-example/builder/body/get-selected-body-content-type.d.ts.map +1 -0
- package/dist/request-example/builder/body/get-selected-body-content-type.js +10 -0
- package/dist/request-example/builder/build-request.d.ts +9 -0
- package/dist/request-example/builder/build-request.d.ts.map +1 -0
- package/dist/request-example/builder/build-request.js +135 -0
- package/dist/request-example/builder/header/build-request-cookie-header.d.ts +25 -0
- package/dist/request-example/builder/header/build-request-cookie-header.d.ts.map +1 -0
- package/dist/request-example/builder/header/build-request-cookie-header.js +39 -0
- package/dist/request-example/builder/header/build-request-parameters.d.ts +24 -0
- package/dist/request-example/builder/header/build-request-parameters.d.ts.map +1 -0
- package/dist/request-example/builder/header/build-request-parameters.js +215 -0
- package/dist/request-example/builder/header/de-serialize-parameter.d.ts +4 -0
- package/dist/request-example/builder/header/de-serialize-parameter.d.ts.map +1 -0
- package/dist/request-example/builder/header/de-serialize-parameter.js +49 -0
- package/dist/request-example/builder/header/filter-global-cookies.d.ts +14 -0
- package/dist/request-example/builder/header/filter-global-cookies.d.ts.map +1 -0
- package/dist/request-example/builder/header/filter-global-cookies.js +26 -0
- package/dist/request-example/builder/header/is-param-disabled.d.ts +13 -0
- package/dist/request-example/builder/header/is-param-disabled.d.ts.map +1 -0
- package/dist/request-example/builder/header/is-param-disabled.js +19 -0
- package/dist/request-example/builder/header/matches-domain.d.ts +9 -0
- package/dist/request-example/builder/header/matches-domain.d.ts.map +1 -0
- package/dist/request-example/builder/header/matches-domain.js +27 -0
- package/dist/request-example/builder/header/serialize-parameter.d.ts +96 -0
- package/dist/request-example/builder/header/serialize-parameter.d.ts.map +1 -0
- package/dist/request-example/builder/header/serialize-parameter.js +222 -0
- package/dist/request-example/builder/helpers/apply-allow-reserved-to-url.d.ts +6 -0
- package/dist/request-example/builder/helpers/apply-allow-reserved-to-url.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/apply-allow-reserved-to-url.js +69 -0
- package/dist/request-example/builder/helpers/get-environment-variables.d.ts +9 -0
- package/dist/request-example/builder/helpers/get-environment-variables.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/get-environment-variables.js +12 -0
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts +40 -0
- package/dist/request-example/builder/helpers/get-example-from-schema.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/get-example-from-schema.js +568 -0
- package/dist/request-example/builder/helpers/get-example.d.ts +10 -0
- package/dist/request-example/builder/helpers/get-example.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/get-example.js +66 -0
- package/dist/request-example/builder/helpers/get-resolved-url.d.ts +20 -0
- package/dist/request-example/builder/helpers/get-resolved-url.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/get-resolved-url.js +19 -0
- package/dist/request-example/builder/helpers/get-server-variables.d.ts +10 -0
- package/dist/request-example/builder/helpers/get-server-variables.d.ts.map +1 -0
- package/dist/request-example/builder/helpers/get-server-variables.js +19 -0
- package/dist/request-example/builder/index.d.ts +15 -0
- package/dist/request-example/builder/index.d.ts.map +1 -0
- package/dist/request-example/builder/index.js +13 -0
- package/dist/request-example/builder/request-factory.d.ts +60 -0
- package/dist/request-example/builder/request-factory.d.ts.map +1 -0
- package/dist/request-example/builder/request-factory.js +78 -0
- package/dist/request-example/builder/security/build-request-security.d.ts +24 -0
- package/dist/request-example/builder/security/build-request-security.d.ts.map +1 -0
- package/dist/request-example/builder/security/build-request-security.js +79 -0
- package/dist/request-example/builder/security/secret-types.d.ts +25 -0
- package/dist/request-example/builder/security/secret-types.d.ts.map +1 -0
- package/dist/request-example/builder/security/secret-types.js +1 -0
- package/dist/request-example/context/environment.d.ts +21 -0
- package/dist/request-example/context/environment.d.ts.map +1 -0
- package/dist/request-example/context/environment.js +49 -0
- package/dist/request-example/context/get-request-example-context.d.ts +57 -0
- package/dist/request-example/context/get-request-example-context.d.ts.map +1 -0
- package/dist/request-example/context/get-request-example-context.js +115 -0
- package/dist/request-example/context/headers.d.ts +33 -0
- package/dist/request-example/context/headers.d.ts.map +1 -0
- package/dist/request-example/context/headers.js +54 -0
- package/dist/request-example/context/helpers/combine-params.d.ts +4 -0
- package/dist/request-example/context/helpers/combine-params.d.ts.map +1 -0
- package/dist/request-example/context/helpers/combine-params.js +21 -0
- package/dist/request-example/context/index.d.ts +12 -0
- package/dist/request-example/context/index.d.ts.map +1 -0
- package/dist/request-example/context/index.js +10 -0
- package/dist/request-example/context/proxy.d.ts +18 -0
- package/dist/request-example/context/proxy.d.ts.map +1 -0
- package/dist/request-example/context/proxy.js +26 -0
- package/dist/request-example/context/security/extract-security-scheme-secrets.d.ts +10 -0
- package/dist/request-example/context/security/extract-security-scheme-secrets.d.ts.map +1 -0
- package/dist/request-example/context/security/extract-security-scheme-secrets.js +167 -0
- package/dist/request-example/context/security/get-security-requirements.d.ts +12 -0
- package/dist/request-example/context/security/get-security-requirements.d.ts.map +1 -0
- package/dist/request-example/context/security/get-security-requirements.js +16 -0
- package/dist/request-example/context/security/get-security-schemes.d.ts +9 -0
- package/dist/request-example/context/security/get-security-schemes.d.ts.map +1 -0
- package/dist/request-example/context/security/get-security-schemes.js +13 -0
- package/dist/request-example/context/security/get-selected-security.d.ts +15 -0
- package/dist/request-example/context/security/get-selected-security.d.ts.map +1 -0
- package/dist/request-example/context/security/get-selected-security.js +49 -0
- package/dist/request-example/context/security/is-auth-optional.d.ts +4 -0
- package/dist/request-example/context/security/is-auth-optional.d.ts.map +1 -0
- package/dist/request-example/context/security/is-auth-optional.js +6 -0
- package/dist/request-example/context/security/merge-security.d.ts +9 -0
- package/dist/request-example/context/security/merge-security.d.ts.map +1 -0
- package/dist/request-example/context/security/merge-security.js +29 -0
- package/dist/request-example/context/servers.d.ts +26 -0
- package/dist/request-example/context/servers.d.ts.map +1 -0
- package/dist/request-example/context/servers.js +89 -0
- package/dist/request-example/index.d.ts +5 -0
- package/dist/request-example/index.d.ts.map +1 -0
- package/dist/request-example/index.js +2 -0
- package/dist/request-example/types.d.ts +14 -0
- package/dist/request-example/types.d.ts.map +1 -0
- package/dist/request-example/types.js +1 -0
- package/dist/schemas/extensions/operation/index.d.ts +2 -1
- package/dist/schemas/extensions/operation/index.d.ts.map +1 -1
- package/dist/schemas/extensions/operation/index.js +1 -0
- package/dist/schemas/extensions/tag/x-tag-groups.d.ts +8 -8
- package/dist/schemas/extensions/tag/x-tag-groups.d.ts.map +1 -1
- package/dist/schemas/v3.1/openapi/index.d.ts +110 -1
- package/dist/schemas/v3.1/openapi/index.d.ts.map +1 -1
- package/dist/schemas/v3.1/openapi/index.js +50 -66
- package/package.json +15 -10
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the selected body content type for the given request body and exampleKey.
|
|
3
|
+
* Priority:
|
|
4
|
+
* 1. requestBody?.['x-scalar-selected-content-type']?.[exampleKey] (if set)
|
|
5
|
+
* 2. First key in requestBody?.content (if available)
|
|
6
|
+
* 3. null (if none available)
|
|
7
|
+
*/
|
|
8
|
+
export const getSelectedBodyContentType = (requestBody, exampleKey = 'default') => {
|
|
9
|
+
return (requestBody?.['x-scalar-selected-content-type']?.[exampleKey] ?? Object.keys(requestBody?.content ?? {})[0] ?? null);
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RequestFactory } from '../../request-example/builder/request-factory.js';
|
|
2
|
+
export declare const buildRequest: (request: RequestFactory, options: {
|
|
3
|
+
envVariables: Record<string, string>;
|
|
4
|
+
}) => {
|
|
5
|
+
request: Request;
|
|
6
|
+
controller: AbortController;
|
|
7
|
+
isUsingProxy: boolean;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=build-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-request.d.ts","sourceRoot":"","sources":["../../../src/request-example/builder/build-request.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAA;AAG/E,eAAO,MAAM,YAAY,GACvB,SAAS,cAAc,EACvB,SAAS;IACP,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC;;;;CAwKF,CAAA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { replaceEnvVariables, replacePathVariables } from '@scalar/helpers/regex/replace-variables';
|
|
2
|
+
import { mergeUrls } from '@scalar/helpers/url/merge-urls';
|
|
3
|
+
import { redirectToProxy, shouldUseProxy } from '@scalar/helpers/url/redirect-to-proxy';
|
|
4
|
+
import { encode as encodeBase64 } from 'js-base64';
|
|
5
|
+
import { buildRequestCookieHeader } from '../../request-example/builder/header/build-request-cookie-header.js';
|
|
6
|
+
import { applyAllowReservedToUrl } from '../../request-example/builder/helpers/apply-allow-reserved-to-url.js';
|
|
7
|
+
export const buildRequest = (request, options) => {
|
|
8
|
+
const controller = new AbortController();
|
|
9
|
+
const headers = (() => {
|
|
10
|
+
const variables = options.envVariables;
|
|
11
|
+
const headers = new Headers();
|
|
12
|
+
request.headers.forEach((value, key) => {
|
|
13
|
+
headers.set(replaceEnvVariables(key, variables), replaceEnvVariables(value, variables));
|
|
14
|
+
});
|
|
15
|
+
return headers;
|
|
16
|
+
})();
|
|
17
|
+
const body = (() => {
|
|
18
|
+
const variables = options.envVariables;
|
|
19
|
+
if (request.body?.mode === 'raw') {
|
|
20
|
+
if (typeof request.body.value === 'string') {
|
|
21
|
+
return replaceEnvVariables(request.body.value, variables);
|
|
22
|
+
}
|
|
23
|
+
return request.body.value;
|
|
24
|
+
}
|
|
25
|
+
if (request.body?.mode === 'formdata') {
|
|
26
|
+
const form = new FormData();
|
|
27
|
+
request.body.value.forEach((item) => {
|
|
28
|
+
if (item.type === 'text') {
|
|
29
|
+
form.append(replaceEnvVariables(item.key, variables), replaceEnvVariables(item.value, variables));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
form.append(replaceEnvVariables(item.key, variables), item.value);
|
|
33
|
+
});
|
|
34
|
+
return form;
|
|
35
|
+
}
|
|
36
|
+
if (request.body?.mode === 'urlencoded') {
|
|
37
|
+
return new URLSearchParams(request.body.value.map((item) => [
|
|
38
|
+
replaceEnvVariables(item.key, variables),
|
|
39
|
+
replaceEnvVariables(item.value, variables),
|
|
40
|
+
]));
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
})();
|
|
44
|
+
const securityQueryParams = new URLSearchParams();
|
|
45
|
+
const securityCookies = [];
|
|
46
|
+
// Build the request security
|
|
47
|
+
request.security.forEach((security) => {
|
|
48
|
+
const name = replaceEnvVariables(security.name, options.envVariables);
|
|
49
|
+
const securityValue = replaceEnvVariables(security.value, options.envVariables);
|
|
50
|
+
if (security.in === 'header') {
|
|
51
|
+
// Build the value for the header
|
|
52
|
+
const buildValue = (() => {
|
|
53
|
+
if (security.type === 'basic') {
|
|
54
|
+
return `Basic ${encodeBase64(securityValue)}`;
|
|
55
|
+
}
|
|
56
|
+
if (security.type === 'bearer') {
|
|
57
|
+
return `Bearer ${securityValue}`;
|
|
58
|
+
}
|
|
59
|
+
return securityValue;
|
|
60
|
+
})();
|
|
61
|
+
// Set the header (use replaced header name so {{ env }} placeholders work)
|
|
62
|
+
headers.set(name, buildValue);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (security.in === 'query') {
|
|
66
|
+
securityQueryParams.set(name, securityValue);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (security.in === 'cookie') {
|
|
70
|
+
securityCookies.push({
|
|
71
|
+
name: name,
|
|
72
|
+
value: securityValue,
|
|
73
|
+
isDisabled: false,
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const requestUrl = (() => {
|
|
79
|
+
// construct replaced path variables
|
|
80
|
+
const pathVariables = Object.fromEntries(Object.entries(request.path.variables).map(([key, value]) => [
|
|
81
|
+
key,
|
|
82
|
+
encodeURIComponent(replaceEnvVariables(value, options.envVariables)),
|
|
83
|
+
]));
|
|
84
|
+
const baseUrl = replaceEnvVariables(request.baseUrl, options.envVariables);
|
|
85
|
+
const path = replacePathVariables(request.path.raw, pathVariables);
|
|
86
|
+
const mergedUrl = mergeUrls(baseUrl, path);
|
|
87
|
+
const urlBase = globalThis.window?.location?.origin ?? 'http://localhost:3000';
|
|
88
|
+
// Replace the path variables with the environment variables and server variables
|
|
89
|
+
const url = new URL(mergedUrl, urlBase);
|
|
90
|
+
// Merge security query params
|
|
91
|
+
for (const [key, value] of securityQueryParams.entries()) {
|
|
92
|
+
url.searchParams.set(replaceEnvVariables(key, options.envVariables), replaceEnvVariables(value, options.envVariables));
|
|
93
|
+
}
|
|
94
|
+
// Replace the query params with the environment variables
|
|
95
|
+
for (const [key, value] of request.query.params.entries()) {
|
|
96
|
+
url.searchParams.set(replaceEnvVariables(key, options.envVariables), replaceEnvVariables(value, options.envVariables));
|
|
97
|
+
}
|
|
98
|
+
return url.toString();
|
|
99
|
+
})();
|
|
100
|
+
const isUsingProxy = shouldUseProxy(request.proxy.proxyUrl, requestUrl);
|
|
101
|
+
const cookies = [...request.cookies.list, ...securityCookies].map((c) => ({
|
|
102
|
+
...c,
|
|
103
|
+
name: replaceEnvVariables(c.name, options.envVariables),
|
|
104
|
+
value: replaceEnvVariables(c.value, options.envVariables),
|
|
105
|
+
}));
|
|
106
|
+
const cookieHeader = buildRequestCookieHeader({
|
|
107
|
+
cookies,
|
|
108
|
+
originalCookieHeader: headers.get('cookie'),
|
|
109
|
+
url: requestUrl,
|
|
110
|
+
useCustomCookieHeader: (isUsingProxy || request.options?.isElectron) ?? false,
|
|
111
|
+
});
|
|
112
|
+
// Add the cookie header to the headers
|
|
113
|
+
if (cookieHeader) {
|
|
114
|
+
headers.set(cookieHeader.name, cookieHeader.value);
|
|
115
|
+
}
|
|
116
|
+
// final url
|
|
117
|
+
const encodedUrl = applyAllowReservedToUrl(requestUrl, request.allowedReservedQueryParameters ?? new Set());
|
|
118
|
+
const finalUrl = isUsingProxy ? redirectToProxy(request.proxy.proxyUrl, encodedUrl) : encodedUrl;
|
|
119
|
+
return {
|
|
120
|
+
request: new Request(finalUrl, {
|
|
121
|
+
/**
|
|
122
|
+
* Ensure that all methods are uppercased (though only needed for patch)
|
|
123
|
+
*
|
|
124
|
+
* @see https://github.com/whatwg/fetch/issues/50
|
|
125
|
+
*/
|
|
126
|
+
method: request.method.toUpperCase(),
|
|
127
|
+
headers,
|
|
128
|
+
body,
|
|
129
|
+
cache: request.cache,
|
|
130
|
+
signal: controller.signal,
|
|
131
|
+
}),
|
|
132
|
+
controller,
|
|
133
|
+
isUsingProxy,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a cookie header from the cookie params
|
|
4
|
+
*/
|
|
5
|
+
export declare const getCookieHeader: (cookieParams: XScalarCookie[], originalCookieHeader: string | undefined) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Build out the cookies header taking in global, param and security scheme cookies
|
|
8
|
+
*/
|
|
9
|
+
export declare const buildRequestCookieHeader: ({ cookies, originalCookieHeader, url, useCustomCookieHeader, }: {
|
|
10
|
+
/** Parsed/replaced cookies from the parameters and security schemes */
|
|
11
|
+
cookies: XScalarCookie[];
|
|
12
|
+
/** Cookie header that previously exists from the spec OR from the user */
|
|
13
|
+
originalCookieHeader: string | undefined | null;
|
|
14
|
+
/** The url of the request used to filter global cookies by domain */
|
|
15
|
+
url: string;
|
|
16
|
+
/**
|
|
17
|
+
* If we are running in Electron or using the proxy, we need to add a custom header
|
|
18
|
+
* that's then forwarded as a `Cookie` header.
|
|
19
|
+
*/
|
|
20
|
+
useCustomCookieHeader: boolean;
|
|
21
|
+
}) => null | {
|
|
22
|
+
name: string;
|
|
23
|
+
value: string;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=build-request-cookie-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-request-cookie-header.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/header/build-request-cookie-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AAYxG;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,cAAc,aAAa,EAAE,EAAE,sBAAsB,MAAM,GAAG,SAAS,KAAG,MAWzG,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,gEAKtC;IACD,uEAAuE;IACvE,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB,0EAA0E;IAC1E,oBAAoB,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IAC/C,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,qBAAqB,EAAE,OAAO,CAAA;CAC/B,KAAG,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAsBvC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { filterGlobalCookie } from './filter-global-cookies.js';
|
|
2
|
+
const CUSTOM_COOKIE_HEADER_WARNING = "We're using a `X-Scalar-Cookie` custom header to the request. The proxy will forward this as a `Cookie` header. We do this to avoid the browser omitting the `Cookie` header for cross-origin requests for security reasons.";
|
|
3
|
+
const COOKIE_HEADER_WARNING = `We're trying to add a Cookie header, but browsers often omit them for cross-origin requests for various security reasons. If it's not working, that's probably why. Here are the requirements for it to work:
|
|
4
|
+
|
|
5
|
+
- The browser URL must be on the same domain as the server URL.
|
|
6
|
+
- The connection must be made over HTTPS.
|
|
7
|
+
`;
|
|
8
|
+
/**
|
|
9
|
+
* Generate a cookie header from the cookie params
|
|
10
|
+
*/
|
|
11
|
+
export const getCookieHeader = (cookieParams, originalCookieHeader) => {
|
|
12
|
+
// Generate the cookie header from the cookie params
|
|
13
|
+
const cookieHeader = cookieParams.map((c) => `${c.name}=${c.value}`).join('; ');
|
|
14
|
+
// Merge with the original cookie header
|
|
15
|
+
if (originalCookieHeader && cookieHeader) {
|
|
16
|
+
return `${originalCookieHeader}; ${cookieHeader}`;
|
|
17
|
+
}
|
|
18
|
+
// Return whichever one exists, or empty string if both are empty
|
|
19
|
+
return originalCookieHeader || cookieHeader || '';
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Build out the cookies header taking in global, param and security scheme cookies
|
|
23
|
+
*/
|
|
24
|
+
export const buildRequestCookieHeader = ({ cookies, originalCookieHeader, url, useCustomCookieHeader, }) => {
|
|
25
|
+
/** Filter the global cookies by domain + parse */
|
|
26
|
+
/** Generate the cookie header */
|
|
27
|
+
const cookieHeader = getCookieHeader(cookies.filter((cookie) => filterGlobalCookie({ url, cookie, disabledGlobalCookies: {} })), originalCookieHeader ?? undefined);
|
|
28
|
+
if (cookieHeader) {
|
|
29
|
+
// Add a custom header for the proxy (that's then forwarded as `Cookie`)
|
|
30
|
+
if (useCustomCookieHeader) {
|
|
31
|
+
console.warn(CUSTOM_COOKIE_HEADER_WARNING);
|
|
32
|
+
return { name: 'X-Scalar-Cookie', value: cookieHeader };
|
|
33
|
+
}
|
|
34
|
+
// or stick to the original header (which might be removed by the browser)
|
|
35
|
+
console.warn(COOKIE_HEADER_WARNING);
|
|
36
|
+
return { name: 'Cookie', value: cookieHeader };
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
|
|
2
|
+
import type { ParameterObject, ReferenceType } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the parameters into a set of headers, cookies and url params while
|
|
5
|
+
* replacing environment variables and extracting example values. Also builds up a record of the path
|
|
6
|
+
* parameters which can then be used to replace variables in the path.
|
|
7
|
+
* Also handles both content based and schema based parameters.
|
|
8
|
+
*
|
|
9
|
+
* @param parameters - Unfiltered parameters
|
|
10
|
+
* @param exampleName - The key of the current example
|
|
11
|
+
* @returns A set of headers, cookies and url params
|
|
12
|
+
*/
|
|
13
|
+
export declare const buildRequestParameters: (
|
|
14
|
+
/** All parameters */
|
|
15
|
+
parameters?: ReferenceType<ParameterObject>[],
|
|
16
|
+
/** The key of the current example */
|
|
17
|
+
exampleName?: string) => {
|
|
18
|
+
cookies: XScalarCookie[];
|
|
19
|
+
headers: Record<string, string>;
|
|
20
|
+
pathVariables: Record<string, string>;
|
|
21
|
+
allowReservedQueryParameters: Set<string>;
|
|
22
|
+
urlParams: URLSearchParams;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=build-request-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-request-parameters.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/header/build-request-parameters.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,qEAAqE,CAAA;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,8DAA8D,CAAA;AAoBlH;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB;AACjC,qBAAqB;AACrB,aAAY,aAAa,CAAC,eAAe,CAAC,EAAO;AACjD,qCAAqC;AACrC,cAAa,MAAkB,KAC9B;IACD,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,4BAA4B,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACzC,SAAS,EAAE,eAAe,CAAA;CAwF3B,CAAA"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { isDefined } from '@scalar/helpers/array/is-defined';
|
|
2
|
+
import { isObject } from '@scalar/helpers/object/is-object';
|
|
3
|
+
import { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref';
|
|
4
|
+
import { xScalarCookieSchema, } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
|
|
5
|
+
import { coerceValue } from '@scalar/workspace-store/schemas/typebox-coerce';
|
|
6
|
+
import { deSerializeParameter } from '../../../request-example/builder/header/de-serialize-parameter.js';
|
|
7
|
+
import { getExample } from '../helpers/get-example.js';
|
|
8
|
+
import { isParamDisabled } from './is-param-disabled.js';
|
|
9
|
+
import { serializeContentValue, serializeDeepObjectStyle, serializeFormStyle, serializeFormStyleForCookies, serializePipeDelimitedStyle, serializeSimpleStyle, serializeSpaceDelimitedStyle, } from './serialize-parameter.js';
|
|
10
|
+
/** Helper to get explode value with default */
|
|
11
|
+
const getExplode = (param, defaultValue) => 'explode' in param && param.explode !== undefined ? param.explode : defaultValue;
|
|
12
|
+
/**
|
|
13
|
+
* Converts the parameters into a set of headers, cookies and url params while
|
|
14
|
+
* replacing environment variables and extracting example values. Also builds up a record of the path
|
|
15
|
+
* parameters which can then be used to replace variables in the path.
|
|
16
|
+
* Also handles both content based and schema based parameters.
|
|
17
|
+
*
|
|
18
|
+
* @param parameters - Unfiltered parameters
|
|
19
|
+
* @param exampleName - The key of the current example
|
|
20
|
+
* @returns A set of headers, cookies and url params
|
|
21
|
+
*/
|
|
22
|
+
export const buildRequestParameters = (
|
|
23
|
+
/** All parameters */
|
|
24
|
+
parameters = [],
|
|
25
|
+
/** The key of the current example */
|
|
26
|
+
exampleName = 'default') => {
|
|
27
|
+
const result = {
|
|
28
|
+
cookies: [],
|
|
29
|
+
headers: {},
|
|
30
|
+
pathVariables: {},
|
|
31
|
+
allowReservedQueryParameters: new Set(),
|
|
32
|
+
urlParams: new URLSearchParams(),
|
|
33
|
+
};
|
|
34
|
+
// Early return for empty parameters
|
|
35
|
+
if (parameters.length === 0) {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
// Second pass: process all parameters
|
|
39
|
+
for (const referencedParam of parameters) {
|
|
40
|
+
const param = getResolvedRef(referencedParam);
|
|
41
|
+
const example = getExample(param, exampleName, undefined);
|
|
42
|
+
// Skip disabled examples
|
|
43
|
+
if (!example || isParamDisabled(param, example)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
/** Replace environment variables in the key and value */
|
|
47
|
+
const value = example.value;
|
|
48
|
+
/** De-serialize the example value if it is a string and matches the schema type */
|
|
49
|
+
const deSerializedValue = deSerializeParameter(value, param);
|
|
50
|
+
const paramName = param.name;
|
|
51
|
+
// Handle by parameter location
|
|
52
|
+
switch (param.in) {
|
|
53
|
+
case 'header': {
|
|
54
|
+
// Filter out Content-Type header when it is multipart/form-data
|
|
55
|
+
// The browser will automatically set this header with the proper boundary
|
|
56
|
+
const lowerParamName = paramName.toLowerCase();
|
|
57
|
+
if (lowerParamName === 'content-type' && deSerializedValue === 'multipart/form-data') {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
/** Headers only support simple style according to OpenAPI 3.1.1 */
|
|
61
|
+
const serialized = serializeSimpleStyle(deSerializedValue, getExplode(param, false));
|
|
62
|
+
// Remove undefined/null headers
|
|
63
|
+
if (!isDefined(serialized)) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
/** Headers can only be strings so we can cast numbers etc */
|
|
67
|
+
const serializedString = String(serialized);
|
|
68
|
+
// If the header already exists, append with comma
|
|
69
|
+
if (result.headers[paramName]) {
|
|
70
|
+
result.headers[paramName] = `${result.headers[paramName]},${serializedString}`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
result.headers[paramName] = serializedString;
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'path': {
|
|
78
|
+
// Path parameters use simple style by default
|
|
79
|
+
const serialized = serializeSimpleStyle(deSerializedValue, getExplode(param, false));
|
|
80
|
+
result.pathVariables[paramName] = String(serialized);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'query': {
|
|
84
|
+
processQueryParameter(param, paramName, deSerializedValue, result.urlParams, result.allowReservedQueryParameters);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'cookie': {
|
|
88
|
+
processCookieParameter(paramName, deSerializedValue, getExplode(param, true), result.cookies);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
/** Ensure we only apply the correcet style to the correct types */
|
|
96
|
+
const getStyle = (param, replacedValue) => {
|
|
97
|
+
if (!('style' in param) || !param.style) {
|
|
98
|
+
return 'form';
|
|
99
|
+
}
|
|
100
|
+
// DeepObject can only apply to objects
|
|
101
|
+
if (param.style === 'deepObject') {
|
|
102
|
+
if (isObject(replacedValue)) {
|
|
103
|
+
return 'deepObject';
|
|
104
|
+
}
|
|
105
|
+
return 'form';
|
|
106
|
+
}
|
|
107
|
+
return param.style;
|
|
108
|
+
};
|
|
109
|
+
/** Whether the parameter allows reserved characters (from param or schema). */
|
|
110
|
+
const isAllowReserved = (param) => {
|
|
111
|
+
if ('allowReserved' in param && param.allowReserved !== undefined) {
|
|
112
|
+
return param.allowReserved;
|
|
113
|
+
}
|
|
114
|
+
if ('schema' in param && param.schema && typeof param.schema === 'object' && 'allowReserved' in param.schema) {
|
|
115
|
+
return param.schema.allowReserved === true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
};
|
|
119
|
+
/** When allowReserved is true, add keys to the set so reserved chars stay unescaped in the URL. */
|
|
120
|
+
const trackReservedKeys = (allowReservedQueryParameters, allowReserved, ...keys) => {
|
|
121
|
+
if (allowReserved) {
|
|
122
|
+
for (const key of keys) {
|
|
123
|
+
allowReservedQueryParameters.add(key);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Helper function to process query parameters.
|
|
129
|
+
* Extracted to reduce complexity in main function.
|
|
130
|
+
*/
|
|
131
|
+
const processQueryParameter = (param, paramName, replacedValue, urlParams, allowReservedQueryParameters) => {
|
|
132
|
+
/** If the parameter should be exploded, defaults to true for form style */
|
|
133
|
+
const explodeParam = 'explode' in param && param.explode !== undefined ? param.explode : true;
|
|
134
|
+
/** Whether the parameter allows reserved characters (from param or schema). */
|
|
135
|
+
const allowReserved = isAllowReserved(param);
|
|
136
|
+
/** Style of the parameter, defaults to form */
|
|
137
|
+
const style = getStyle(param, replacedValue);
|
|
138
|
+
// Content type parameters should be serialized according to the parameter's own content type
|
|
139
|
+
if ('content' in param && param.content) {
|
|
140
|
+
// We grab the first for now but eventually we should support selecting the content type per parameter
|
|
141
|
+
const paramContentType = Object.keys(param.content)[0] ?? 'application/json';
|
|
142
|
+
const serializedValue = serializeContentValue(replacedValue, paramContentType);
|
|
143
|
+
urlParams.set(paramName, serializedValue);
|
|
144
|
+
trackReservedKeys(allowReservedQueryParameters, allowReserved, paramName);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Handle deepObject style
|
|
148
|
+
if (style === 'deepObject' && explodeParam) {
|
|
149
|
+
const entries = serializeDeepObjectStyle(paramName, replacedValue);
|
|
150
|
+
for (const entry of entries) {
|
|
151
|
+
urlParams.append(entry.key, entry.value);
|
|
152
|
+
trackReservedKeys(allowReservedQueryParameters, allowReserved, paramName);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// Handle spaceDelimited style
|
|
157
|
+
if (style === 'spaceDelimited') {
|
|
158
|
+
const serialized = serializeSpaceDelimitedStyle(replacedValue);
|
|
159
|
+
const existingValue = urlParams.get(paramName);
|
|
160
|
+
urlParams.set(paramName, existingValue ? `${existingValue} ${serialized}` : serialized);
|
|
161
|
+
trackReservedKeys(allowReservedQueryParameters, allowReserved, paramName);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Handle pipeDelimited style
|
|
165
|
+
if (style === 'pipeDelimited') {
|
|
166
|
+
const serialized = serializePipeDelimitedStyle(replacedValue);
|
|
167
|
+
const existingValue = urlParams.get(paramName);
|
|
168
|
+
urlParams.set(paramName, existingValue ? `${existingValue}|${serialized}` : serialized);
|
|
169
|
+
trackReservedKeys(allowReservedQueryParameters, allowReserved, paramName);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Handle form style (default)
|
|
173
|
+
const serialized = serializeFormStyle(replacedValue, explodeParam);
|
|
174
|
+
// If serialized is an array of key-value pairs (exploded object or array)
|
|
175
|
+
if (Array.isArray(serialized)) {
|
|
176
|
+
for (const entry of serialized) {
|
|
177
|
+
// If key is empty, use paramName (for arrays)
|
|
178
|
+
const key = entry.key || paramName;
|
|
179
|
+
urlParams.append(key, String(entry.value));
|
|
180
|
+
trackReservedKeys(allowReservedQueryParameters, allowReserved, paramName);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Otherwise, convert to string for URLSearchParams
|
|
185
|
+
urlParams.append(paramName, String(serialized));
|
|
186
|
+
trackReservedKeys(allowReservedQueryParameters, allowReserved, paramName);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Helper function to process cookie parameters.
|
|
191
|
+
* Extracted to reduce complexity in main function.
|
|
192
|
+
*/
|
|
193
|
+
const processCookieParameter = (paramName, replacedValue, explode, cookies) => {
|
|
194
|
+
// Cookies only support form style according to OpenAPI 3.1.1
|
|
195
|
+
const serialized = serializeFormStyleForCookies(replacedValue, explode);
|
|
196
|
+
// If serialized is an array of key-value pairs (exploded object or array)
|
|
197
|
+
if (Array.isArray(serialized)) {
|
|
198
|
+
for (const entry of serialized) {
|
|
199
|
+
const key = entry.key || paramName;
|
|
200
|
+
cookies.push(coerceValue(xScalarCookieSchema, {
|
|
201
|
+
name: key,
|
|
202
|
+
value: String(entry.value),
|
|
203
|
+
path: '/',
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// Otherwise, convert to string for cookie value
|
|
209
|
+
cookies.push(coerceValue(xScalarCookieSchema, {
|
|
210
|
+
name: paramName,
|
|
211
|
+
value: String(serialized),
|
|
212
|
+
path: '/',
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ParameterObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
2
|
+
/** Helper that de-serializes the example value based on the parameter type */
|
|
3
|
+
export declare const deSerializeParameter: (example: unknown, param: ParameterObject) => any;
|
|
4
|
+
//# sourceMappingURL=de-serialize-parameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de-serialize-parameter.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/header/de-serialize-parameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,8DAA8D,CAAA;AAErE,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,GAAI,SAAS,OAAO,EAAE,OAAO,eAAe,QAS5E,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref';
|
|
2
|
+
/** Helper that de-serializes the example value based on the parameter type */
|
|
3
|
+
export const deSerializeParameter = (example, param) => {
|
|
4
|
+
if ('content' in param) {
|
|
5
|
+
return deSerializeContentExample(example, Object.keys(param.content ?? {})[0] ?? '');
|
|
6
|
+
}
|
|
7
|
+
if ('schema' in param) {
|
|
8
|
+
return deSerializeSchemaExample(example, param.schema);
|
|
9
|
+
}
|
|
10
|
+
return example;
|
|
11
|
+
};
|
|
12
|
+
/** De-serialize the example value based on the content type */
|
|
13
|
+
const deSerializeContentExample = (example, contentType) => {
|
|
14
|
+
if (typeof example === 'string' && contentType.includes('json')) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(example);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Ignore the error and return the original example
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return example;
|
|
23
|
+
};
|
|
24
|
+
/** Create a set of all the types we wish to parse as JSON */
|
|
25
|
+
const parseableTypesSet = new Set(['array', 'object', 'boolean', 'number', 'integer', 'null']);
|
|
26
|
+
/** De-serialize the example value based on the schema type */
|
|
27
|
+
const deSerializeSchemaExample = (example, schema) => {
|
|
28
|
+
const resolvedSchema = getResolvedRef(schema);
|
|
29
|
+
if (typeof example === 'string' && resolvedSchema && 'type' in resolvedSchema) {
|
|
30
|
+
const type = Array.isArray(resolvedSchema.type) ? resolvedSchema.type[0] : resolvedSchema.type;
|
|
31
|
+
if (type && parseableTypesSet.has(type)) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(example);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// For array types, fall back to splitting comma-separated values.
|
|
37
|
+
// Users commonly enter array values as "foo,bar" or "foo, bar" in the UI
|
|
38
|
+
// text field, which is not valid JSON. Per the OpenAPI spec, the default
|
|
39
|
+
// serialization for query array parameters is style=form + explode=true,
|
|
40
|
+
// meaning each value should be sent as a separate query parameter.
|
|
41
|
+
if (type === 'array') {
|
|
42
|
+
return example.split(/,\s?/).filter((v) => v !== '');
|
|
43
|
+
}
|
|
44
|
+
// Ignore the error and return the original example for other types
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return example;
|
|
49
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
|
|
2
|
+
/**
|
|
3
|
+
* Filter a global cookie to determine if it should be included with a request to the given URL.
|
|
4
|
+
* - Returns false if the cookie is disabled, in the disabledGlobalCookies map, or missing a name.
|
|
5
|
+
* - Returns false if the domain does not match.
|
|
6
|
+
* - Returns false if the path is specified and does not match the URL pathname.
|
|
7
|
+
* - Returns true otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare const filterGlobalCookie: ({ cookie, url, disabledGlobalCookies, }: {
|
|
10
|
+
cookie: XScalarCookie;
|
|
11
|
+
url: string;
|
|
12
|
+
disabledGlobalCookies: Record<string, boolean>;
|
|
13
|
+
}) => boolean;
|
|
14
|
+
//# sourceMappingURL=filter-global-cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-global-cookies.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/header/filter-global-cookies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AAIxG;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,yCAIhC;IACD,MAAM,EAAE,aAAa,CAAA;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/C,KAAG,OAqBH,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { matchesDomain } from './matches-domain.js';
|
|
2
|
+
/**
|
|
3
|
+
* Filter a global cookie to determine if it should be included with a request to the given URL.
|
|
4
|
+
* - Returns false if the cookie is disabled, in the disabledGlobalCookies map, or missing a name.
|
|
5
|
+
* - Returns false if the domain does not match.
|
|
6
|
+
* - Returns false if the path is specified and does not match the URL pathname.
|
|
7
|
+
* - Returns true otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export const filterGlobalCookie = ({ cookie, url, disabledGlobalCookies, }) => {
|
|
10
|
+
// Filter out disabled cookies, those disabled globally, or those missing a name.
|
|
11
|
+
if (cookie.isDisabled || disabledGlobalCookies[cookie.name.toLowerCase()] === true || !cookie.name) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
// Parse the URL to extract the pathname for path matching.
|
|
15
|
+
const urlObject = new URL(url, 'https://example.com');
|
|
16
|
+
// If a domain restriction exists, ensure the cookie is only sent for matching domains.
|
|
17
|
+
if (cookie.domain && !matchesDomain(url, cookie.domain)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// If a path restriction exists, ensure the cookie is only sent for URLs with a matching prefix.
|
|
21
|
+
if (cookie.path && !urlObject.pathname.startsWith(cookie.path)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
// Cookie passed all checks; include it in the request.
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExampleObject, ParameterObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a parameter is disabled
|
|
4
|
+
*
|
|
5
|
+
* First we explicitly check if its been disabled via the `x-disabled` extension.
|
|
6
|
+
* Then we check if its an optional parameter and not a path parameter.
|
|
7
|
+
*
|
|
8
|
+
* @param param - The parameter to check.
|
|
9
|
+
* @param example - The example to check.
|
|
10
|
+
* @returns true if the parameter is disabled, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isParamDisabled: (param: ParameterObject, example: ExampleObject | undefined) => boolean;
|
|
13
|
+
//# sourceMappingURL=is-param-disabled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-param-disabled.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/header/is-param-disabled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AAElH;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,eAAe,EAAE,SAAS,aAAa,GAAG,SAAS,YAUzF,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a parameter is disabled
|
|
3
|
+
*
|
|
4
|
+
* First we explicitly check if its been disabled via the `x-disabled` extension.
|
|
5
|
+
* Then we check if its an optional parameter and not a path parameter.
|
|
6
|
+
*
|
|
7
|
+
* @param param - The parameter to check.
|
|
8
|
+
* @param example - The example to check.
|
|
9
|
+
* @returns true if the parameter is disabled, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export const isParamDisabled = (param, example) => {
|
|
12
|
+
const xDisabled = example?.['x-disabled'];
|
|
13
|
+
// If x-disabled is explicitly set (true or false), use that value
|
|
14
|
+
if (typeof xDisabled === 'boolean') {
|
|
15
|
+
return xDisabled;
|
|
16
|
+
}
|
|
17
|
+
// Otherwise, disable optional parameters (except path parameters which are always required)
|
|
18
|
+
return !param.required && param.in !== 'path';
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches, when:
|
|
3
|
+
* - Isn't scoped to a domain, or
|
|
4
|
+
* - matches the current host, or
|
|
5
|
+
* - or ends with the current host, or
|
|
6
|
+
* - matches the current host with a wildcard.
|
|
7
|
+
*/
|
|
8
|
+
export declare const matchesDomain: (givenUrl?: string, configuredHostname?: string) => boolean;
|
|
9
|
+
//# sourceMappingURL=matches-domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches-domain.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/header/matches-domain.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,EAAE,qBAAqB,MAAM,KAAG,OAsB9E,CAAA"}
|