@scalar/api-reference 1.50.0 → 1.51.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 +10 -0
- package/dist/browser/standalone.js +208 -208
- package/dist/browser/webpack-stats.json +1 -1
- package/dist/components/ApiReference.vue.d.ts.map +1 -1
- package/dist/components/ApiReference.vue.js +1 -1
- package/dist/components/ApiReference.vue.js.map +1 -1
- package/dist/components/ApiReference.vue.script.js +46 -11
- package/dist/components/ApiReference.vue.script.js.map +1 -1
- package/dist/components/Content/Auth/Auth.vue.d.ts.map +1 -1
- package/dist/components/Content/Auth/Auth.vue.js.map +1 -1
- package/dist/components/Content/Auth/Auth.vue.script.js +2 -13
- package/dist/components/Content/Auth/Auth.vue.script.js.map +1 -1
- package/dist/components/Content/Content.vue.d.ts +1 -0
- package/dist/components/Content/Content.vue.d.ts.map +1 -1
- package/dist/components/Content/Content.vue.js.map +1 -1
- package/dist/components/Content/Content.vue.script.js +6 -5
- package/dist/components/Content/Content.vue.script.js.map +1 -1
- package/dist/features/Operation/layouts/ModernLayout.vue.script.js.map +1 -1
- package/dist/helpers/safe-deep-clone.d.ts +17 -0
- package/dist/helpers/safe-deep-clone.d.ts.map +1 -0
- package/dist/helpers/safe-deep-clone.js +25 -0
- package/dist/helpers/safe-deep-clone.js.map +1 -0
- package/dist/helpers/storage.d.ts +5 -5
- package/dist/style.css +16 -16
- package/package.json +11 -11
- package/dist/components/Content/Auth/helpers/get-default-security.d.ts +0 -18
- package/dist/components/Content/Auth/helpers/get-default-security.d.ts.map +0 -1
- package/dist/components/Content/Auth/helpers/get-default-security.js +0 -64
- package/dist/components/Content/Auth/helpers/get-default-security.js.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-clones plain data for use where mutation must not affect the source.
|
|
3
|
+
*
|
|
4
|
+
* In the browser we use `structuredClone`, which preserves `Date`, `Map`, `Set`,
|
|
5
|
+
* typed arrays, and other structured types. During SSR there is no `window`, so
|
|
6
|
+
* we fall back to `JSON.parse(JSON.stringify(...))`, which only supports JSON
|
|
7
|
+
* values (functions, `undefined` in objects, symbols, etc. are dropped or altered).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const copy = safeDeepClone(spec)
|
|
12
|
+
* copy.info.title = 'Draft'
|
|
13
|
+
* // original spec is unchanged
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const safeDeepClone: <T>(value: T) => T;
|
|
17
|
+
//# sourceMappingURL=safe-deep-clone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-deep-clone.d.ts","sourceRoot":"","sources":["../../src/helpers/safe-deep-clone.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,CAK3C,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { deepClone } from "@scalar/workspace-store/helpers/deep-clone";
|
|
2
|
+
//#region src/helpers/safe-deep-clone.ts
|
|
3
|
+
/**
|
|
4
|
+
* Deep-clones plain data for use where mutation must not affect the source.
|
|
5
|
+
*
|
|
6
|
+
* In the browser we use `structuredClone`, which preserves `Date`, `Map`, `Set`,
|
|
7
|
+
* typed arrays, and other structured types. During SSR there is no `window`, so
|
|
8
|
+
* we fall back to `JSON.parse(JSON.stringify(...))`, which only supports JSON
|
|
9
|
+
* values (functions, `undefined` in objects, symbols, etc. are dropped or altered).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const copy = safeDeepClone(spec)
|
|
14
|
+
* copy.info.title = 'Draft'
|
|
15
|
+
* // original spec is unchanged
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var safeDeepClone = (value) => {
|
|
19
|
+
if (typeof window === "undefined") return deepClone(value);
|
|
20
|
+
return window.structuredClone(value);
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { safeDeepClone };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=safe-deep-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-deep-clone.js","names":[],"sources":["../../src/helpers/safe-deep-clone.ts"],"sourcesContent":["import { deepClone } from '@scalar/workspace-store/helpers/deep-clone'\n\n/**\n * Deep-clones plain data for use where mutation must not affect the source.\n *\n * In the browser we use `structuredClone`, which preserves `Date`, `Map`, `Set`,\n * typed arrays, and other structured types. During SSR there is no `window`, so\n * we fall back to `JSON.parse(JSON.stringify(...))`, which only supports JSON\n * values (functions, `undefined` in objects, symbols, etc. are dropped or altered).\n *\n * @example\n * ```ts\n * const copy = safeDeepClone(spec)\n * copy.info.title = 'Draft'\n * // original spec is unchanged\n * ```\n */\nexport const safeDeepClone = <T>(value: T): T => {\n if (typeof window === 'undefined') {\n return deepClone(value)\n }\n return window.structuredClone(value) as T\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,IAAa,iBAAoB,UAAgB;AAC/C,KAAI,OAAO,WAAW,YACpB,QAAO,UAAU,MAAM;AAEzB,QAAO,OAAO,gBAAgB,MAAM"}
|
|
@@ -88,10 +88,10 @@ export declare const authStorage: () => {
|
|
|
88
88
|
}) | undefined;
|
|
89
89
|
}) | {
|
|
90
90
|
implicit?: ({
|
|
91
|
+
refreshUrl: string;
|
|
91
92
|
scopes: {
|
|
92
93
|
[x: string]: string;
|
|
93
94
|
};
|
|
94
|
-
refreshUrl: string;
|
|
95
95
|
} & {
|
|
96
96
|
'x-scalar-security-query'?: {
|
|
97
97
|
[x: string]: string;
|
|
@@ -118,10 +118,10 @@ export declare const authStorage: () => {
|
|
|
118
118
|
'x-scalar-secret-redirect-uri': string;
|
|
119
119
|
}) | undefined;
|
|
120
120
|
password?: ({
|
|
121
|
+
refreshUrl: string;
|
|
121
122
|
scopes: {
|
|
122
123
|
[x: string]: string;
|
|
123
124
|
};
|
|
124
|
-
refreshUrl: string;
|
|
125
125
|
} & {
|
|
126
126
|
'x-scalar-security-query'?: {
|
|
127
127
|
[x: string]: string;
|
|
@@ -155,10 +155,10 @@ export declare const authStorage: () => {
|
|
|
155
155
|
'x-scalar-credentials-location'?: "body" | "header" | undefined;
|
|
156
156
|
}) | undefined;
|
|
157
157
|
clientCredentials?: ({
|
|
158
|
+
refreshUrl: string;
|
|
158
159
|
scopes: {
|
|
159
160
|
[x: string]: string;
|
|
160
161
|
};
|
|
161
|
-
refreshUrl: string;
|
|
162
162
|
} & {
|
|
163
163
|
'x-scalar-security-query'?: {
|
|
164
164
|
[x: string]: string;
|
|
@@ -189,10 +189,10 @@ export declare const authStorage: () => {
|
|
|
189
189
|
'x-scalar-credentials-location'?: "body" | "header" | undefined;
|
|
190
190
|
}) | undefined;
|
|
191
191
|
authorizationCode?: ({
|
|
192
|
+
refreshUrl: string;
|
|
192
193
|
scopes: {
|
|
193
194
|
[x: string]: string;
|
|
194
195
|
};
|
|
195
|
-
refreshUrl: string;
|
|
196
196
|
} & {
|
|
197
197
|
'x-scalar-security-query'?: {
|
|
198
198
|
[x: string]: string;
|
|
@@ -208,8 +208,8 @@ export declare const authStorage: () => {
|
|
|
208
208
|
} & {
|
|
209
209
|
'x-scalar-secret-token-url'?: string | undefined;
|
|
210
210
|
} & {
|
|
211
|
-
tokenUrl: string;
|
|
212
211
|
authorizationUrl: string;
|
|
212
|
+
tokenUrl: string;
|
|
213
213
|
} & {
|
|
214
214
|
'x-usePkce': "SHA-256" | "plain" | "no";
|
|
215
215
|
} & {
|
package/dist/style.css
CHANGED
|
@@ -13469,7 +13469,7 @@ div + .userMessage[data-v-8e43ed7a] {
|
|
|
13469
13469
|
|
|
13470
13470
|
/* Configurable Layout Variables */
|
|
13471
13471
|
@layer scalar-config {
|
|
13472
|
-
.scalar-api-reference[data-v-
|
|
13472
|
+
.scalar-api-reference[data-v-0d40a3ce] {
|
|
13473
13473
|
/* The header height */
|
|
13474
13474
|
--refs-header-height: calc(
|
|
13475
13475
|
var(--scalar-custom-header-height, 0px) + var(--scalar-header-height, 0px)
|
|
@@ -13491,20 +13491,20 @@ div + .userMessage[data-v-8e43ed7a] {
|
|
|
13491
13491
|
/* The maximum width of the content column */
|
|
13492
13492
|
--refs-content-max-width: var(--scalar-content-max-width, 1540px);
|
|
13493
13493
|
}
|
|
13494
|
-
.scalar-api-reference.references-classic[data-v-
|
|
13494
|
+
.scalar-api-reference.references-classic[data-v-0d40a3ce] {
|
|
13495
13495
|
/* Classic layout is wider */
|
|
13496
13496
|
--refs-content-max-width: var(--scalar-content-max-width, 1420px);
|
|
13497
13497
|
min-height: 100dvh;
|
|
13498
13498
|
--refs-sidebar-width: 0;
|
|
13499
13499
|
}
|
|
13500
13500
|
}
|
|
13501
|
-
.t-doc__sidebar[data-v-
|
|
13501
|
+
.t-doc__sidebar[data-v-0d40a3ce] {
|
|
13502
13502
|
z-index: 10;
|
|
13503
13503
|
}
|
|
13504
13504
|
|
|
13505
13505
|
/* ----------------------------------------------------- */
|
|
13506
13506
|
/* References Layout */
|
|
13507
|
-
.references-layout[data-v-
|
|
13507
|
+
.references-layout[data-v-0d40a3ce] {
|
|
13508
13508
|
/* Try to fill the container */
|
|
13509
13509
|
min-height: 100dvh;
|
|
13510
13510
|
min-width: 100%;
|
|
@@ -13528,44 +13528,44 @@ div + .userMessage[data-v-8e43ed7a] {
|
|
|
13528
13528
|
|
|
13529
13529
|
background: var(--scalar-background-1);
|
|
13530
13530
|
}
|
|
13531
|
-
.references-editor[data-v-
|
|
13531
|
+
.references-editor[data-v-0d40a3ce] {
|
|
13532
13532
|
grid-area: editor;
|
|
13533
13533
|
display: flex;
|
|
13534
13534
|
min-width: 0;
|
|
13535
13535
|
background: var(--scalar-background-1);
|
|
13536
13536
|
}
|
|
13537
|
-
.references-rendered[data-v-
|
|
13537
|
+
.references-rendered[data-v-0d40a3ce] {
|
|
13538
13538
|
position: relative;
|
|
13539
13539
|
grid-area: rendered;
|
|
13540
13540
|
min-width: 0;
|
|
13541
13541
|
background: var(--scalar-background-1);
|
|
13542
13542
|
}
|
|
13543
|
-
.scalar-api-reference.references-classic[data-v-
|
|
13544
|
-
.references-classic .references-rendered[data-v-
|
|
13543
|
+
.scalar-api-reference.references-classic[data-v-0d40a3ce],
|
|
13544
|
+
.references-classic .references-rendered[data-v-0d40a3ce] {
|
|
13545
13545
|
height: initial !important;
|
|
13546
13546
|
max-height: initial !important;
|
|
13547
13547
|
}
|
|
13548
13548
|
@layer scalar-config {
|
|
13549
|
-
.references-sidebar[data-v-
|
|
13549
|
+
.references-sidebar[data-v-0d40a3ce] {
|
|
13550
13550
|
/* Set a default width if references are enabled */
|
|
13551
13551
|
--refs-sidebar-width: var(--scalar-sidebar-width, 288px);
|
|
13552
13552
|
}
|
|
13553
13553
|
}
|
|
13554
13554
|
|
|
13555
13555
|
/* Footer */
|
|
13556
|
-
.references-footer[data-v-
|
|
13556
|
+
.references-footer[data-v-0d40a3ce] {
|
|
13557
13557
|
grid-area: footer;
|
|
13558
13558
|
}
|
|
13559
13559
|
/* ----------------------------------------------------- */
|
|
13560
13560
|
/* Responsive / Mobile Layout */
|
|
13561
13561
|
@media (max-width: 1000px) {
|
|
13562
13562
|
/* Keep toolbar hidden on mobile without forcing desktop display mode. */
|
|
13563
|
-
.references-developer-tools[data-v-
|
|
13563
|
+
.references-developer-tools[data-v-0d40a3ce] {
|
|
13564
13564
|
display: none;
|
|
13565
13565
|
}
|
|
13566
13566
|
|
|
13567
13567
|
/* Stack view on mobile */
|
|
13568
|
-
.references-layout[data-v-
|
|
13568
|
+
.references-layout[data-v-0d40a3ce] {
|
|
13569
13569
|
/* Adjust the sidebar height to the viewport height minus the header height */
|
|
13570
13570
|
--refs-sidebar-height: calc(
|
|
13571
13571
|
var(--full-height, 100dvh) - var(--scalar-custom-header-height, 0px)
|
|
@@ -13580,13 +13580,13 @@ div + .userMessage[data-v-8e43ed7a] {
|
|
|
13580
13580
|
'rendered'
|
|
13581
13581
|
'footer';
|
|
13582
13582
|
}
|
|
13583
|
-
.references-editable[data-v-
|
|
13583
|
+
.references-editable[data-v-0d40a3ce] {
|
|
13584
13584
|
grid-template-areas:
|
|
13585
13585
|
'header'
|
|
13586
13586
|
'navigation'
|
|
13587
13587
|
'editor';
|
|
13588
13588
|
}
|
|
13589
|
-
.references-rendered[data-v-
|
|
13589
|
+
.references-rendered[data-v-0d40a3ce] {
|
|
13590
13590
|
position: static;
|
|
13591
13591
|
}
|
|
13592
13592
|
}
|
|
@@ -13597,12 +13597,12 @@ div + .userMessage[data-v-8e43ed7a] {
|
|
|
13597
13597
|
* when the new elements are available
|
|
13598
13598
|
*/
|
|
13599
13599
|
@media (max-width: 1000px) {
|
|
13600
|
-
.scalar-api-references-standalone-mobile[data-v-
|
|
13600
|
+
.scalar-api-references-standalone-mobile[data-v-0d40a3ce]:not(.references-classic) {
|
|
13601
13601
|
--scalar-header-height: 50px;
|
|
13602
13602
|
}
|
|
13603
13603
|
}
|
|
13604
13604
|
|
|
13605
|
-
.darklight-reference[data-v-
|
|
13605
|
+
.darklight-reference[data-v-0d40a3ce] {
|
|
13606
13606
|
width: 100%;
|
|
13607
13607
|
margin-top: auto;
|
|
13608
13608
|
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"vue",
|
|
21
21
|
"vue3"
|
|
22
22
|
],
|
|
23
|
-
"version": "1.
|
|
23
|
+
"version": "1.51.0",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
@@ -91,20 +91,20 @@
|
|
|
91
91
|
"nanoid": "^5.1.6",
|
|
92
92
|
"vue": "^3.5.30",
|
|
93
93
|
"yaml": "^2.8.0",
|
|
94
|
-
"@scalar/agent-chat": "0.10.
|
|
95
|
-
"@scalar/api-client": "2.
|
|
94
|
+
"@scalar/agent-chat": "0.10.1",
|
|
95
|
+
"@scalar/api-client": "2.41.0",
|
|
96
96
|
"@scalar/code-highlight": "0.3.2",
|
|
97
|
-
"@scalar/components": "0.21.3",
|
|
98
|
-
"@scalar/icons": "0.7.2",
|
|
99
|
-
"@scalar/oas-utils": "0.10.15",
|
|
100
97
|
"@scalar/helpers": "0.4.3",
|
|
101
|
-
"@scalar/
|
|
98
|
+
"@scalar/oas-utils": "0.10.16",
|
|
99
|
+
"@scalar/icons": "0.7.2",
|
|
100
|
+
"@scalar/sidebar": "0.8.18",
|
|
101
|
+
"@scalar/components": "0.21.3",
|
|
102
102
|
"@scalar/snippetz": "0.7.8",
|
|
103
103
|
"@scalar/themes": "0.15.2",
|
|
104
104
|
"@scalar/use-hooks": "0.4.2",
|
|
105
|
+
"@scalar/workspace-store": "0.43.1",
|
|
105
106
|
"@scalar/use-toasts": "0.10.1",
|
|
106
|
-
"@scalar/types": "0.7.6"
|
|
107
|
-
"@scalar/workspace-store": "0.43.0"
|
|
107
|
+
"@scalar/types": "0.7.6"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@hono/node-server": "^1.19.10",
|
|
@@ -121,8 +121,8 @@
|
|
|
121
121
|
"vite-plugin-banner": "^0.8.1",
|
|
122
122
|
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
123
123
|
"vitest": "4.1.0",
|
|
124
|
-
"@scalar/
|
|
125
|
-
"@scalar/
|
|
124
|
+
"@scalar/galaxy": "0.6.2",
|
|
125
|
+
"@scalar/core": "0.4.6"
|
|
126
126
|
},
|
|
127
127
|
"scripts": {
|
|
128
128
|
"build": "pnpm build:default && pnpm build:standalone && vue-tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AuthenticationConfiguration } from '@scalar/types/api-reference';
|
|
2
|
-
import type { MergedSecuritySchemes } from '@scalar/workspace-store/request-example';
|
|
3
|
-
import type { SecurityRequirementObject, SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
4
|
-
/**
|
|
5
|
-
* Extracts the default scopes for a security scheme.
|
|
6
|
-
* Only OAuth2 schemes can have default scopes via the x-default-scopes extension.
|
|
7
|
-
*/
|
|
8
|
-
export declare const getDefaultScopes: (scheme: SecuritySchemeObject | undefined) => string[];
|
|
9
|
-
/**
|
|
10
|
-
* Determines the default security scheme to use for an operation.
|
|
11
|
-
*
|
|
12
|
-
* Priority order:
|
|
13
|
-
* 1. User-configured preferred security scheme (if provided)
|
|
14
|
-
* 2. First security requirement from the OpenAPI spec
|
|
15
|
-
* 3. null (no security required)
|
|
16
|
-
*/
|
|
17
|
-
export declare const getDefaultSecurity: (securityRequirements: SecurityRequirementObject[], preferredSecurityScheme: AuthenticationConfiguration["preferredSecurityScheme"], securitySchemes: MergedSecuritySchemes) => SecurityRequirementObject | null;
|
|
18
|
-
//# sourceMappingURL=get-default-security.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-default-security.d.ts","sourceRoot":"","sources":["../../../../../src/components/Content/Auth/helpers/get-default-security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAG9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAA;AACpF,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,8DAA8D,CAAA;AAErE;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,GAAG,SAAS,KAAG,MAAM,EAMjF,CAAA;AAkED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC7B,sBAAsB,yBAAyB,EAAE,EACjD,yBAAyB,2BAA2B,CAAC,yBAAyB,CAAC,EAC/E,iBAAiB,qBAAqB,KACrC,yBAAyB,GAAG,IAW9B,CAAA"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
|
-
import { unpackProxyObject } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
3
|
-
//#region src/components/Content/Auth/helpers/get-default-security.ts
|
|
4
|
-
/**
|
|
5
|
-
* Extracts the default scopes for a security scheme.
|
|
6
|
-
* Only OAuth2 schemes can have default scopes via the x-default-scopes extension.
|
|
7
|
-
*/
|
|
8
|
-
var getDefaultScopes = (scheme) => {
|
|
9
|
-
if (!scheme || scheme.type !== "oauth2") return [];
|
|
10
|
-
return scheme["x-default-scopes"] ?? [];
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Hydrates an existing security requirement with configured default scopes.
|
|
14
|
-
* Explicit scopes from the OpenAPI requirement take precedence over x-default-scopes.
|
|
15
|
-
*/
|
|
16
|
-
var hydrateSecurityRequirement = (requirement, securitySchemes) => {
|
|
17
|
-
const hydratedRequirement = {};
|
|
18
|
-
for (const [schemeName, scopes] of Object.entries(unpackProxyObject(requirement, { depth: 1 }) ?? requirement)) {
|
|
19
|
-
if (Array.isArray(scopes) && scopes.length > 0) {
|
|
20
|
-
hydratedRequirement[schemeName] = scopes;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
hydratedRequirement[schemeName] = getDefaultScopes(getResolvedRef(securitySchemes[schemeName]));
|
|
24
|
-
}
|
|
25
|
-
return hydratedRequirement;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Processes a single scheme name and adds it to the accumulator with its default scopes.
|
|
29
|
-
*/
|
|
30
|
-
var addSchemeToRequirement = (acc, schemeName, securitySchemes) => {
|
|
31
|
-
acc[schemeName] = getDefaultScopes(getResolvedRef(securitySchemes[schemeName]));
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Converts the preferred security scheme configuration into a SecurityRequirementObject.
|
|
35
|
-
* Handles both flat arrays and nested arrays (for complex auth scenarios).
|
|
36
|
-
*/
|
|
37
|
-
var buildSecurityRequirementFromPreferred = (preferredSecurityScheme, securitySchemes) => {
|
|
38
|
-
if (!Array.isArray(preferredSecurityScheme)) {
|
|
39
|
-
const scheme = getResolvedRef(securitySchemes[preferredSecurityScheme]);
|
|
40
|
-
return { [preferredSecurityScheme]: getDefaultScopes(scheme) };
|
|
41
|
-
}
|
|
42
|
-
const requirement = {};
|
|
43
|
-
for (const item of preferredSecurityScheme) if (Array.isArray(item)) for (const schemeName of item) addSchemeToRequirement(requirement, schemeName, securitySchemes);
|
|
44
|
-
else addSchemeToRequirement(requirement, item, securitySchemes);
|
|
45
|
-
return requirement;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Determines the default security scheme to use for an operation.
|
|
49
|
-
*
|
|
50
|
-
* Priority order:
|
|
51
|
-
* 1. User-configured preferred security scheme (if provided)
|
|
52
|
-
* 2. First security requirement from the OpenAPI spec
|
|
53
|
-
* 3. null (no security required)
|
|
54
|
-
*/
|
|
55
|
-
var getDefaultSecurity = (securityRequirements, preferredSecurityScheme, securitySchemes) => {
|
|
56
|
-
if (preferredSecurityScheme) return buildSecurityRequirementFromPreferred(preferredSecurityScheme, securitySchemes);
|
|
57
|
-
const firstRequirement = securityRequirements[0];
|
|
58
|
-
if (firstRequirement) return hydrateSecurityRequirement(firstRequirement, securitySchemes);
|
|
59
|
-
return null;
|
|
60
|
-
};
|
|
61
|
-
//#endregion
|
|
62
|
-
export { getDefaultSecurity };
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=get-default-security.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-default-security.js","names":[],"sources":["../../../../../src/components/Content/Auth/helpers/get-default-security.ts"],"sourcesContent":["import type { AuthenticationConfiguration } from '@scalar/types/api-reference'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport type { MergedSecuritySchemes } from '@scalar/workspace-store/request-example'\nimport type {\n SecurityRequirementObject,\n SecuritySchemeObject,\n} from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\n\n/**\n * Extracts the default scopes for a security scheme.\n * Only OAuth2 schemes can have default scopes via the x-default-scopes extension.\n */\nexport const getDefaultScopes = (scheme: SecuritySchemeObject | undefined): string[] => {\n if (!scheme || scheme.type !== 'oauth2') {\n return []\n }\n\n return scheme['x-default-scopes'] ?? []\n}\n\n/**\n * Hydrates an existing security requirement with configured default scopes.\n * Explicit scopes from the OpenAPI requirement take precedence over x-default-scopes.\n */\nconst hydrateSecurityRequirement = (\n requirement: SecurityRequirementObject,\n securitySchemes: MergedSecuritySchemes,\n): SecurityRequirementObject => {\n const hydratedRequirement: SecurityRequirementObject = {}\n\n for (const [schemeName, scopes] of Object.entries(unpackProxyObject(requirement, { depth: 1 }) ?? requirement)) {\n if (Array.isArray(scopes) && scopes.length > 0) {\n hydratedRequirement[schemeName] = scopes\n continue\n }\n\n const scheme = getResolvedRef(securitySchemes[schemeName])\n hydratedRequirement[schemeName] = getDefaultScopes(scheme)\n }\n\n return hydratedRequirement\n}\n\n/**\n * Processes a single scheme name and adds it to the accumulator with its default scopes.\n */\nconst addSchemeToRequirement = (\n acc: SecurityRequirementObject,\n schemeName: string,\n securitySchemes: MergedSecuritySchemes,\n): void => {\n const scheme = getResolvedRef(securitySchemes[schemeName])\n acc[schemeName] = getDefaultScopes(scheme)\n}\n\n/**\n * Converts the preferred security scheme configuration into a SecurityRequirementObject.\n * Handles both flat arrays and nested arrays (for complex auth scenarios).\n */\nconst buildSecurityRequirementFromPreferred = (\n preferredSecurityScheme: string | (string | string[])[],\n securitySchemes: MergedSecuritySchemes,\n): SecurityRequirementObject => {\n if (!Array.isArray(preferredSecurityScheme)) {\n const scheme = getResolvedRef(securitySchemes[preferredSecurityScheme])\n return { [preferredSecurityScheme]: getDefaultScopes(scheme) }\n }\n\n const requirement: SecurityRequirementObject = {}\n\n for (const item of preferredSecurityScheme) {\n if (Array.isArray(item)) {\n // Handle nested arrays for complex auth (e.g., [['oauth2', 'apiKey'], 'basic'])\n for (const schemeName of item) {\n addSchemeToRequirement(requirement, schemeName, securitySchemes)\n }\n } else {\n addSchemeToRequirement(requirement, item, securitySchemes)\n }\n }\n\n return requirement\n}\n\n/**\n * Determines the default security scheme to use for an operation.\n *\n * Priority order:\n * 1. User-configured preferred security scheme (if provided)\n * 2. First security requirement from the OpenAPI spec\n * 3. null (no security required)\n */\nexport const getDefaultSecurity = (\n securityRequirements: SecurityRequirementObject[],\n preferredSecurityScheme: AuthenticationConfiguration['preferredSecurityScheme'],\n securitySchemes: MergedSecuritySchemes,\n): SecurityRequirementObject | null => {\n if (preferredSecurityScheme) {\n return buildSecurityRequirementFromPreferred(preferredSecurityScheme, securitySchemes)\n }\n\n const firstRequirement = securityRequirements[0]\n if (firstRequirement) {\n return hydrateSecurityRequirement(firstRequirement, securitySchemes)\n }\n\n return null\n}\n"],"mappings":";;;;;;;AAaA,IAAa,oBAAoB,WAAuD;AACtF,KAAI,CAAC,UAAU,OAAO,SAAS,SAC7B,QAAO,EAAE;AAGX,QAAO,OAAO,uBAAuB,EAAE;;;;;;AAOzC,IAAM,8BACJ,aACA,oBAC8B;CAC9B,MAAM,sBAAiD,EAAE;AAEzD,MAAK,MAAM,CAAC,YAAY,WAAW,OAAO,QAAQ,kBAAkB,aAAa,EAAE,OAAO,GAAG,CAAC,IAAI,YAAY,EAAE;AAC9G,MAAI,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,GAAG;AAC9C,uBAAoB,cAAc;AAClC;;AAIF,sBAAoB,cAAc,iBADnB,eAAe,gBAAgB,YAAY,CACA;;AAG5D,QAAO;;;;;AAMT,IAAM,0BACJ,KACA,YACA,oBACS;AAET,KAAI,cAAc,iBADH,eAAe,gBAAgB,YAAY,CAChB;;;;;;AAO5C,IAAM,yCACJ,yBACA,oBAC8B;AAC9B,KAAI,CAAC,MAAM,QAAQ,wBAAwB,EAAE;EAC3C,MAAM,SAAS,eAAe,gBAAgB,yBAAyB;AACvE,SAAO,GAAG,0BAA0B,iBAAiB,OAAO,EAAE;;CAGhE,MAAM,cAAyC,EAAE;AAEjD,MAAK,MAAM,QAAQ,wBACjB,KAAI,MAAM,QAAQ,KAAK,CAErB,MAAK,MAAM,cAAc,KACvB,wBAAuB,aAAa,YAAY,gBAAgB;KAGlE,wBAAuB,aAAa,MAAM,gBAAgB;AAI9D,QAAO;;;;;;;;;;AAWT,IAAa,sBACX,sBACA,yBACA,oBACqC;AACrC,KAAI,wBACF,QAAO,sCAAsC,yBAAyB,gBAAgB;CAGxF,MAAM,mBAAmB,qBAAqB;AAC9C,KAAI,iBACF,QAAO,2BAA2B,kBAAkB,gBAAgB;AAGtE,QAAO"}
|