@scalar/oas-utils 0.2.137 → 0.2.138
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 +6 -0
- package/dist/helpers/security/get-schemes.d.ts +82 -0
- package/dist/helpers/security/get-schemes.d.ts.map +1 -0
- package/dist/helpers/security/get-schemes.js +11 -0
- package/dist/helpers/security/has-token.d.ts +4 -0
- package/dist/helpers/security/has-token.d.ts.map +1 -0
- package/dist/helpers/security/has-token.js +21 -0
- package/dist/helpers/security/index.d.ts +3 -0
- package/dist/helpers/security/index.d.ts.map +1 -0
- package/dist/helpers/security/index.js +2 -0
- package/package.json +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { SecurityScheme } from '@scalar/types/entities';
|
|
2
|
+
import type { Operation } from '../../entities/spec/operation.ts';
|
|
3
|
+
/** Parses a list of selected security scheme uids which may be an array or single uid and returns a flattened array of security schemes */
|
|
4
|
+
export declare const getSchemes: (selectedSecuritySchemes: Operation["selectedSecuritySchemeUids"], securitySchemes: Record<SecurityScheme["uid"], SecurityScheme>) => NonNullable<{
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
type: "apiKey";
|
|
8
|
+
uid: string & import("zod").BRAND<"securityScheme">;
|
|
9
|
+
nameKey: string;
|
|
10
|
+
in: "cookie" | "query" | "header";
|
|
11
|
+
description?: string | undefined;
|
|
12
|
+
} | {
|
|
13
|
+
type: "http";
|
|
14
|
+
uid: string & import("zod").BRAND<"securityScheme">;
|
|
15
|
+
nameKey: string;
|
|
16
|
+
scheme: "basic" | "bearer";
|
|
17
|
+
bearerFormat: string;
|
|
18
|
+
username: string;
|
|
19
|
+
password: string;
|
|
20
|
+
token: string;
|
|
21
|
+
description?: string | undefined;
|
|
22
|
+
} | {
|
|
23
|
+
type: "openIdConnect";
|
|
24
|
+
uid: string & import("zod").BRAND<"securityScheme">;
|
|
25
|
+
nameKey: string;
|
|
26
|
+
openIdConnectUrl: string;
|
|
27
|
+
description?: string | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
type: "oauth2";
|
|
30
|
+
uid: string & import("zod").BRAND<"securityScheme">;
|
|
31
|
+
nameKey: string;
|
|
32
|
+
flows: {
|
|
33
|
+
password?: {
|
|
34
|
+
type: "password";
|
|
35
|
+
username: string;
|
|
36
|
+
password: string;
|
|
37
|
+
token: string;
|
|
38
|
+
refreshUrl: string;
|
|
39
|
+
scopes: Record<string, string>;
|
|
40
|
+
selectedScopes: string[];
|
|
41
|
+
"x-scalar-client-id": string;
|
|
42
|
+
tokenUrl: string;
|
|
43
|
+
clientSecret: string;
|
|
44
|
+
} | undefined;
|
|
45
|
+
implicit?: {
|
|
46
|
+
type: "implicit";
|
|
47
|
+
token: string;
|
|
48
|
+
refreshUrl: string;
|
|
49
|
+
scopes: Record<string, string>;
|
|
50
|
+
selectedScopes: string[];
|
|
51
|
+
"x-scalar-client-id": string;
|
|
52
|
+
authorizationUrl: string;
|
|
53
|
+
"x-scalar-redirect-uri": string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
clientCredentials?: {
|
|
56
|
+
type: "clientCredentials";
|
|
57
|
+
token: string;
|
|
58
|
+
refreshUrl: string;
|
|
59
|
+
scopes: Record<string, string>;
|
|
60
|
+
selectedScopes: string[];
|
|
61
|
+
"x-scalar-client-id": string;
|
|
62
|
+
tokenUrl: string;
|
|
63
|
+
clientSecret: string;
|
|
64
|
+
} | undefined;
|
|
65
|
+
authorizationCode?: {
|
|
66
|
+
type: "authorizationCode";
|
|
67
|
+
token: string;
|
|
68
|
+
refreshUrl: string;
|
|
69
|
+
scopes: Record<string, string>;
|
|
70
|
+
selectedScopes: string[];
|
|
71
|
+
"x-scalar-client-id": string;
|
|
72
|
+
authorizationUrl: string;
|
|
73
|
+
"x-scalar-redirect-uri": string;
|
|
74
|
+
tokenUrl: string;
|
|
75
|
+
clientSecret: string;
|
|
76
|
+
"x-usePkce": "SHA-256" | "plain" | "no";
|
|
77
|
+
} | undefined;
|
|
78
|
+
};
|
|
79
|
+
description?: string | undefined;
|
|
80
|
+
'x-default-scopes'?: string | string[] | undefined;
|
|
81
|
+
}>[];
|
|
82
|
+
//# sourceMappingURL=get-schemes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-schemes.d.ts","sourceRoot":"","sources":["../../../src/helpers/security/get-schemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAG7D,2IAA2I;AAC3I,eAAO,MAAM,UAAU,4BACI,SAAS,CAAC,4BAA4B,CAAC,mBAC/C,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAOyr3D,CAAC;;;;;;;;;;;;gBAA4X,CAAC;;;;;;;;;;yBAA4V,CAAC;;;;;;;;;;yBAAkV,CAAC;;;;;;;;;;;;;;;;IADty5D,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isDefined } from '../is-defined.js';
|
|
2
|
+
|
|
3
|
+
/** Parses a list of selected security scheme uids which may be an array or single uid and returns a flattened array of security schemes */
|
|
4
|
+
const getSchemes = (selectedSecuritySchemes, securitySchemes) => {
|
|
5
|
+
const uids = new Set(selectedSecuritySchemes.flat());
|
|
6
|
+
return Array.from(uids)
|
|
7
|
+
.map((uid) => securitySchemes[uid])
|
|
8
|
+
.filter(isDefined);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { getSchemes };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SecurityScheme } from '@scalar/types/entities';
|
|
2
|
+
/** Pass in a security scheme and it will return true if it has a token or value depending on the scheme type */
|
|
3
|
+
export declare const hasToken: (scheme: SecurityScheme) => Boolean;
|
|
4
|
+
//# sourceMappingURL=has-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-token.d.ts","sourceRoot":"","sources":["../../../src/helpers/security/has-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,gHAAgH;AAChH,eAAO,MAAM,QAAQ,WAAY,cAAc,KAAG,OAwBjD,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Pass in a security scheme and it will return true if it has a token or value depending on the scheme type */
|
|
2
|
+
const hasToken = (scheme) => {
|
|
3
|
+
// ApiKey
|
|
4
|
+
if (scheme.type === 'apiKey') {
|
|
5
|
+
return Boolean(scheme.value);
|
|
6
|
+
}
|
|
7
|
+
// Http
|
|
8
|
+
if (scheme.type === 'http') {
|
|
9
|
+
return Boolean((scheme.scheme === 'bearer' && scheme.token) || (scheme.scheme === 'basic' && scheme.username && scheme.password));
|
|
10
|
+
}
|
|
11
|
+
// OAuth2 just check for A token
|
|
12
|
+
if (scheme.type === 'oauth2') {
|
|
13
|
+
return Boolean(scheme.flows.authorizationCode?.token ||
|
|
14
|
+
scheme.flows.clientCredentials?.token ||
|
|
15
|
+
scheme.flows.password?.token ||
|
|
16
|
+
scheme.flows.implicit?.token);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { hasToken };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.138",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -58,6 +58,11 @@
|
|
|
58
58
|
"types": "./dist/helpers/index.d.ts",
|
|
59
59
|
"default": "./dist/helpers/index.js"
|
|
60
60
|
},
|
|
61
|
+
"./helpers/security": {
|
|
62
|
+
"import": "./dist/helpers/security/index.js",
|
|
63
|
+
"types": "./dist/helpers/security/index.d.ts",
|
|
64
|
+
"default": "./dist/helpers/security/index.js"
|
|
65
|
+
},
|
|
61
66
|
"./migrations": {
|
|
62
67
|
"import": "./dist/migrations/index.js",
|
|
63
68
|
"types": "./dist/migrations/index.d.ts",
|
|
@@ -86,11 +91,11 @@
|
|
|
86
91
|
"nanoid": "^5.1.5",
|
|
87
92
|
"type-fest": "^4.20.0",
|
|
88
93
|
"yaml": "^2.4.5",
|
|
89
|
-
"zod": "
|
|
94
|
+
"zod": "3.24.1",
|
|
95
|
+
"@scalar/object-utils": "1.1.13",
|
|
90
96
|
"@scalar/openapi-types": "0.2.1",
|
|
91
|
-
"@scalar/types": "0.1.12",
|
|
92
97
|
"@scalar/themes": "0.10.4",
|
|
93
|
-
"@scalar/
|
|
98
|
+
"@scalar/types": "0.1.12"
|
|
94
99
|
},
|
|
95
100
|
"devDependencies": {
|
|
96
101
|
"@types/node": "^20.17.10",
|
|
@@ -98,9 +103,9 @@
|
|
|
98
103
|
"vite": "^5.4.10",
|
|
99
104
|
"vitest": "^1.6.0",
|
|
100
105
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
106
|
+
"@scalar/openapi-types": "0.2.1",
|
|
101
107
|
"@scalar/build-tooling": "0.1.18",
|
|
102
|
-
"@scalar/openapi-parser": "0.10.16"
|
|
103
|
-
"@scalar/openapi-types": "0.2.1"
|
|
108
|
+
"@scalar/openapi-parser": "0.10.16"
|
|
104
109
|
},
|
|
105
110
|
"scripts": {
|
|
106
111
|
"build": "scalar-build-rollup",
|