@scalar/types 0.1.12 → 0.1.14

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/api-reference/api-reference-configuration.d.ts +9 -9
  3. package/dist/api-reference/api-reference-configuration.d.ts.map +1 -1
  4. package/dist/api-reference/api-reference-configuration.js +271 -289
  5. package/dist/api-reference/api-reference-configuration.js.map +7 -0
  6. package/dist/api-reference/api-reference-configuration.test.js +224 -0
  7. package/dist/api-reference/api-reference-configuration.test.js.map +7 -0
  8. package/dist/api-reference/api-reference-plugin.js +24 -22
  9. package/dist/api-reference/api-reference-plugin.js.map +7 -0
  10. package/dist/api-reference/authentication-configuration.d.ts +2 -2
  11. package/dist/api-reference/authentication-configuration.d.ts.map +1 -1
  12. package/dist/api-reference/authentication-configuration.js +1 -0
  13. package/dist/api-reference/authentication-configuration.js.map +7 -0
  14. package/dist/api-reference/authentication-configuration.test-d.js +45 -0
  15. package/dist/api-reference/authentication-configuration.test-d.js.map +7 -0
  16. package/dist/api-reference/html-api.d.ts +1 -1
  17. package/dist/api-reference/html-api.d.ts.map +1 -1
  18. package/dist/api-reference/html-api.js +1 -0
  19. package/dist/api-reference/html-api.js.map +7 -0
  20. package/dist/api-reference/html-rendering-configuration.d.ts +1 -1
  21. package/dist/api-reference/html-rendering-configuration.d.ts.map +1 -1
  22. package/dist/api-reference/html-rendering-configuration.js +19 -21
  23. package/dist/api-reference/html-rendering-configuration.js.map +7 -0
  24. package/dist/api-reference/index.d.ts +4 -5
  25. package/dist/api-reference/index.d.ts.map +1 -1
  26. package/dist/api-reference/index.js +17 -3
  27. package/dist/api-reference/index.js.map +7 -0
  28. package/dist/entities/index.d.ts +1 -1
  29. package/dist/entities/index.d.ts.map +1 -1
  30. package/dist/entities/index.js +21 -1
  31. package/dist/entities/index.js.map +7 -0
  32. package/dist/entities/security-scheme.d.ts +3 -3
  33. package/dist/entities/security-scheme.js +116 -157
  34. package/dist/entities/security-scheme.js.map +7 -0
  35. package/dist/entities/security-scheme.test.js +311 -0
  36. package/dist/entities/security-scheme.test.js.map +7 -0
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -4
  40. package/dist/index.js.map +7 -0
  41. package/dist/legacy/index.d.ts +1 -1
  42. package/dist/legacy/index.d.ts.map +1 -1
  43. package/dist/legacy/index.js +2 -1
  44. package/dist/legacy/index.js.map +7 -0
  45. package/dist/legacy/reference-config.d.ts +2 -3
  46. package/dist/legacy/reference-config.d.ts.map +1 -1
  47. package/dist/legacy/reference-config.js +10 -8
  48. package/dist/legacy/reference-config.js.map +7 -0
  49. package/dist/snippetz/index.d.ts +1 -1
  50. package/dist/snippetz/index.d.ts.map +1 -1
  51. package/dist/snippetz/index.js +2 -1
  52. package/dist/snippetz/index.js.map +7 -0
  53. package/dist/snippetz/snippetz.js +39 -40
  54. package/dist/snippetz/snippetz.js.map +7 -0
  55. package/dist/snippetz/snippetz.test-d.js +28 -0
  56. package/dist/snippetz/snippetz.test-d.js.map +7 -0
  57. package/dist/utils/index.d.ts +2 -2
  58. package/dist/utils/index.d.ts.map +1 -1
  59. package/dist/utils/index.js +5 -1
  60. package/dist/utils/index.js.map +7 -0
  61. package/dist/utils/nanoid.js +7 -11
  62. package/dist/utils/nanoid.js.map +7 -0
  63. package/dist/utils/nanoid.test.js +29 -0
  64. package/dist/utils/nanoid.test.js.map +7 -0
  65. package/dist/utils/utility-types.js +1 -0
  66. package/dist/utils/utility-types.js.map +7 -0
  67. package/package.json +6 -10
  68. package/dist/api-reference/helpers/migrate-theme-variables.d.ts +0 -10
  69. package/dist/api-reference/helpers/migrate-theme-variables.d.ts.map +0 -1
  70. package/dist/api-reference/helpers/migrate-theme-variables.js +0 -22
@@ -1,2 +1,2 @@
1
- export { type Oauth2Flow, type Oauth2FlowPayload, type SecuritySchemaHttp, type SecuritySchemaOpenId, type SecurityScheme, type SecuritySchemeApiKey, type SecuritySchemeOauth2, type SecuritySchemeOauth2Payload, type SecuritySchemePayload, oasSecurityRequirementSchema, oasSecuritySchemeSchema, pkceOptions, securityApiKeySchema, securityHttpSchema, securityOauthSchema, securityOpenIdSchema, securitySchemeSchema, } from './security-scheme.ts';
1
+ export { type Oauth2Flow, type Oauth2FlowPayload, type SecuritySchemaHttp, type SecuritySchemaOpenId, type SecurityScheme, type SecuritySchemeApiKey, type SecuritySchemeOauth2, type SecuritySchemeOauth2Payload, type SecuritySchemePayload, oasSecurityRequirementSchema, oasSecuritySchemeSchema, pkceOptions, securityApiKeySchema, securityHttpSchema, securityOauthSchema, securityOpenIdSchema, securitySchemeSchema, } from './security-scheme.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,mBAAmB,CAAA"}
@@ -1 +1,21 @@
1
- export { oasSecurityRequirementSchema, oasSecuritySchemeSchema, pkceOptions, securityApiKeySchema, securityHttpSchema, securityOauthSchema, securityOpenIdSchema, securitySchemeSchema } from './security-scheme.js';
1
+ import {
2
+ oasSecurityRequirementSchema,
3
+ oasSecuritySchemeSchema,
4
+ pkceOptions,
5
+ securityApiKeySchema,
6
+ securityHttpSchema,
7
+ securityOauthSchema,
8
+ securityOpenIdSchema,
9
+ securitySchemeSchema
10
+ } from "./security-scheme.js";
11
+ export {
12
+ oasSecurityRequirementSchema,
13
+ oasSecuritySchemeSchema,
14
+ pkceOptions,
15
+ securityApiKeySchema,
16
+ securityHttpSchema,
17
+ securityOauthSchema,
18
+ securityOpenIdSchema,
19
+ securitySchemeSchema
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/entities/index.ts"],
4
+ "sourcesContent": ["export {\n type Oauth2Flow,\n type Oauth2FlowPayload,\n type SecuritySchemaHttp,\n type SecuritySchemaOpenId,\n type SecurityScheme,\n type SecuritySchemeApiKey,\n type SecuritySchemeOauth2,\n type SecuritySchemeOauth2Payload,\n type SecuritySchemePayload,\n oasSecurityRequirementSchema,\n oasSecuritySchemeSchema,\n pkceOptions,\n securityApiKeySchema,\n securityHttpSchema,\n securityOauthSchema,\n securityOpenIdSchema,\n securitySchemeSchema,\n} from './security-scheme'\n"],
5
+ "mappings": "AAAA;AAAA,EAUE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
6
+ "names": []
7
+ }
@@ -16,8 +16,8 @@ export declare const securityApiKeySchema: z.ZodObject<z.objectUtil.extendShape<
16
16
  value: z.ZodDefault<z.ZodString>;
17
17
  }>, "strip", z.ZodTypeAny, {
18
18
  name: string;
19
- type: "apiKey";
20
19
  value: string;
20
+ type: "apiKey";
21
21
  uid: string & z.BRAND<"securityScheme">;
22
22
  nameKey: string;
23
23
  in: "cookie" | "query" | "header";
@@ -958,8 +958,8 @@ export declare const securitySchemeSchema: z.ZodEffects<z.ZodDiscriminatedUnion<
958
958
  value: z.ZodDefault<z.ZodString>;
959
959
  }>, "strip", z.ZodTypeAny, {
960
960
  name: string;
961
- type: "apiKey";
962
961
  value: string;
962
+ type: "apiKey";
963
963
  uid: string & z.BRAND<"securityScheme">;
964
964
  nameKey: string;
965
965
  in: "cookie" | "query" | "header";
@@ -1424,8 +1424,8 @@ export declare const securitySchemeSchema: z.ZodEffects<z.ZodDiscriminatedUnion<
1424
1424
  } | undefined;
1425
1425
  }>]>, {
1426
1426
  name: string;
1427
- type: "apiKey";
1428
1427
  value: string;
1428
+ type: "apiKey";
1429
1429
  uid: string & z.BRAND<"securityScheme">;
1430
1430
  nameKey: string;
1431
1431
  in: "cookie" | "query" | "header";
@@ -1,184 +1,143 @@
1
- import { z } from 'zod';
2
- import { nanoidSchema } from '../utils/nanoid.js';
3
-
4
- // ---------------------------------------------------------------------------
5
- // COMMON PROPS FOR ALL SECURITY SCHEMES
6
- /** Some common properties used in all security schemes */
1
+ import { z } from "zod";
2
+ import { nanoidSchema } from "../utils/nanoid.js";
7
3
  const commonProps = z.object({
8
- /* A description for security scheme. CommonMark syntax MAY be used for rich text representation. */
9
- description: z.string().optional(),
4
+ /* A description for security scheme. CommonMark syntax MAY be used for rich text representation. */
5
+ description: z.string().optional()
10
6
  });
11
7
  const extendedSecuritySchema = z.object({
12
- uid: nanoidSchema.brand(),
13
- /** The name key that links a security requirement to a security object */
14
- nameKey: z.string().optional().default(''),
8
+ uid: nanoidSchema.brand(),
9
+ /** The name key that links a security requirement to a security object */
10
+ nameKey: z.string().optional().default("")
15
11
  });
16
- // ---------------------------------------------------------------------------
17
- // API KEY
18
- const securitySchemeApiKeyIn = ['query', 'header', 'cookie'];
12
+ const securitySchemeApiKeyIn = ["query", "header", "cookie"];
19
13
  const oasSecuritySchemeApiKey = commonProps.extend({
20
- type: z.literal('apiKey'),
21
- /** REQUIRED. The name of the header, query or cookie parameter to be used. */
22
- name: z.string().optional().default(''),
23
- /** REQUIRED. The location of the API key. Valid values are "query", "header" or "cookie". */
24
- in: z.enum(securitySchemeApiKeyIn).optional().default('header').catch('header'),
14
+ type: z.literal("apiKey"),
15
+ /** REQUIRED. The name of the header, query or cookie parameter to be used. */
16
+ name: z.string().optional().default(""),
17
+ /** REQUIRED. The location of the API key. Valid values are "query", "header" or "cookie". */
18
+ in: z.enum(securitySchemeApiKeyIn).optional().default("header").catch("header")
25
19
  });
26
20
  const apiKeyValueSchema = z.object({
27
- value: z.string().default(''),
21
+ value: z.string().default("")
28
22
  });
29
23
  const securityApiKeySchema = oasSecuritySchemeApiKey.merge(extendedSecuritySchema).merge(apiKeyValueSchema);
30
- // ---------------------------------------------------------------------------
31
- // HTTP
32
24
  const oasSecuritySchemeHttp = commonProps.extend({
33
- type: z.literal('http'),
34
- /**
35
- * REQUIRED. The name of the HTTP Authorization scheme to be used in the Authorization header as defined in
36
- * [RFC7235]. The values used SHOULD be registered in the IANA Authentication Scheme registry.
37
- */
38
- scheme: z
39
- .string()
40
- .toLowerCase()
41
- .pipe(z.enum(['basic', 'bearer']))
42
- .optional()
43
- .default('basic'),
44
- /**
45
- * A hint to the client to identify how the bearer token is formatted.
46
- * Bearer tokens are usually generated by an authorization server, so
47
- * this information is primarily for documentation purposes.
48
- */
49
- bearerFormat: z
50
- .union([z.literal('JWT'), z.string()])
51
- .optional()
52
- .default('JWT'),
25
+ type: z.literal("http"),
26
+ /**
27
+ * REQUIRED. The name of the HTTP Authorization scheme to be used in the Authorization header as defined in
28
+ * [RFC7235]. The values used SHOULD be registered in the IANA Authentication Scheme registry.
29
+ */
30
+ scheme: z.string().toLowerCase().pipe(z.enum(["basic", "bearer"])).optional().default("basic"),
31
+ /**
32
+ * A hint to the client to identify how the bearer token is formatted.
33
+ * Bearer tokens are usually generated by an authorization server, so
34
+ * this information is primarily for documentation purposes.
35
+ */
36
+ bearerFormat: z.union([z.literal("JWT"), z.string()]).optional().default("JWT")
53
37
  });
54
38
  const httpValueSchema = z.object({
55
- username: z.string().default(''),
56
- password: z.string().default(''),
57
- token: z.string().default(''),
39
+ username: z.string().default(""),
40
+ password: z.string().default(""),
41
+ token: z.string().default("")
58
42
  });
59
43
  const securityHttpSchema = oasSecuritySchemeHttp.merge(extendedSecuritySchema).merge(httpValueSchema);
60
- // ---------------------------------------------------------------------------
61
- // OPENID CONNECT
62
44
  const oasSecuritySchemeOpenId = commonProps.extend({
63
- type: z.literal('openIdConnect'),
64
- /**
65
- * REQUIRED. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the
66
- * form of a URL. The OpenID Connect standard requires the use of TLS.
67
- */
68
- openIdConnectUrl: z.string().optional().default(''),
45
+ type: z.literal("openIdConnect"),
46
+ /**
47
+ * REQUIRED. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the
48
+ * form of a URL. The OpenID Connect standard requires the use of TLS.
49
+ */
50
+ openIdConnectUrl: z.string().optional().default("")
69
51
  });
70
52
  const securityOpenIdSchema = oasSecuritySchemeOpenId.merge(extendedSecuritySchema);
71
- // ---------------------------------------------------------------------------
72
- /**
73
- * REQUIRED. The authorization URL to be used for this flow. This MUST be in
74
- * the form of a URL. The OAuth2 standard requires the use of TLS.
75
- */
76
- const authorizationUrl = z.string().default('');
77
- /**
78
- * REQUIRED. The token URL to be used for this flow. This MUST be in the
79
- * form of a URL. The OAuth2 standard requires the use of TLS.
80
- */
81
- const tokenUrl = z.string().default('');
82
- /** Common properties used across all oauth2 flows */
53
+ const authorizationUrl = z.string().default("");
54
+ const tokenUrl = z.string().default("");
83
55
  const flowsCommon = z.object({
84
- /**
85
- * The URL to be used for obtaining refresh tokens. This MUST be in the form of a
86
- * URL. The OAuth2 standard requires the use of TLS.
87
- */
88
- 'refreshUrl': z.string().optional().default(''),
89
- /**
90
- * REQUIRED. The available scopes for the OAuth2 security scheme. A map
91
- * between the scope name and a short description for it. The map MAY be empty.
92
- */
93
- 'scopes': z.record(z.string(), z.string().optional().default('')).optional().default({}).catch({}),
94
- 'selectedScopes': z.array(z.string()).optional().default([]),
95
- /** Extension to save the client Id associated with an oauth flow */
96
- 'x-scalar-client-id': z.string().optional().default(''),
97
- /** The auth token */
98
- 'token': z.string().default(''),
56
+ /**
57
+ * The URL to be used for obtaining refresh tokens. This MUST be in the form of a
58
+ * URL. The OAuth2 standard requires the use of TLS.
59
+ */
60
+ "refreshUrl": z.string().optional().default(""),
61
+ /**
62
+ * REQUIRED. The available scopes for the OAuth2 security scheme. A map
63
+ * between the scope name and a short description for it. The map MAY be empty.
64
+ */
65
+ "scopes": z.record(z.string(), z.string().optional().default("")).optional().default({}).catch({}),
66
+ "selectedScopes": z.array(z.string()).optional().default([]),
67
+ /** Extension to save the client Id associated with an oauth flow */
68
+ "x-scalar-client-id": z.string().optional().default(""),
69
+ /** The auth token */
70
+ "token": z.string().default("")
99
71
  });
100
- /** Setup a default redirect uri if we can */
101
- const defaultRedirectUri = typeof window !== 'undefined' ? window.location.origin + window.location.pathname : '';
102
- /** Options for the x-usePkce extension */
103
- const pkceOptions = ['SHA-256', 'plain', 'no'];
104
- /** Oauth2 security scheme */
72
+ const defaultRedirectUri = typeof window !== "undefined" ? window.location.origin + window.location.pathname : "";
73
+ const pkceOptions = ["SHA-256", "plain", "no"];
105
74
  const oasSecuritySchemeOauth2 = commonProps.extend({
106
- type: z.literal('oauth2'),
107
- /** The default scopes for the oauth flow */
108
- 'x-default-scopes': z.string().or(z.array(z.string())).optional(),
109
- /** REQUIRED. An object containing configuration information for the flow types supported. */
110
- flows: z
111
- .object({
112
- /** Configuration for the OAuth Implicit flow */
113
- implicit: flowsCommon.extend({
114
- 'type': z.literal('implicit').default('implicit'),
115
- authorizationUrl,
116
- 'x-scalar-redirect-uri': z.string().optional().default(defaultRedirectUri),
117
- }),
118
- /** Configuration for the OAuth Resource Owner Password flow */
119
- password: flowsCommon.extend({
120
- type: z.literal('password').default('password'),
121
- tokenUrl,
122
- clientSecret: z.string().default(''),
123
- username: z.string().default(''),
124
- password: z.string().default(''),
125
- }),
126
- /** Configuration for the OAuth Client Credentials flow. Previously called application in OpenAPI 2.0. */
127
- clientCredentials: flowsCommon.extend({
128
- type: z.literal('clientCredentials').default('clientCredentials'),
129
- tokenUrl,
130
- clientSecret: z.string().default(''),
131
- }),
132
- /** Configuration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.*/
133
- authorizationCode: flowsCommon.extend({
134
- 'type': z.literal('authorizationCode').default('authorizationCode'),
135
- authorizationUrl,
136
- 'x-usePkce': z.enum(pkceOptions).optional().default('no'),
137
- 'x-scalar-redirect-uri': z.string().optional().default(defaultRedirectUri),
138
- tokenUrl,
139
- 'clientSecret': z.string().default(''),
140
- }),
141
- })
142
- .partial()
143
- .default({
144
- implicit: { type: 'implicit', authorizationUrl: 'http://localhost:8080' },
75
+ type: z.literal("oauth2"),
76
+ /** The default scopes for the oauth flow */
77
+ "x-default-scopes": z.string().or(z.array(z.string())).optional(),
78
+ /** REQUIRED. An object containing configuration information for the flow types supported. */
79
+ flows: z.object({
80
+ /** Configuration for the OAuth Implicit flow */
81
+ implicit: flowsCommon.extend({
82
+ "type": z.literal("implicit").default("implicit"),
83
+ authorizationUrl,
84
+ "x-scalar-redirect-uri": z.string().optional().default(defaultRedirectUri)
85
+ }),
86
+ /** Configuration for the OAuth Resource Owner Password flow */
87
+ password: flowsCommon.extend({
88
+ type: z.literal("password").default("password"),
89
+ tokenUrl,
90
+ clientSecret: z.string().default(""),
91
+ username: z.string().default(""),
92
+ password: z.string().default("")
145
93
  }),
94
+ /** Configuration for the OAuth Client Credentials flow. Previously called application in OpenAPI 2.0. */
95
+ clientCredentials: flowsCommon.extend({
96
+ type: z.literal("clientCredentials").default("clientCredentials"),
97
+ tokenUrl,
98
+ clientSecret: z.string().default("")
99
+ }),
100
+ /** Configuration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.*/
101
+ authorizationCode: flowsCommon.extend({
102
+ "type": z.literal("authorizationCode").default("authorizationCode"),
103
+ authorizationUrl,
104
+ "x-usePkce": z.enum(pkceOptions).optional().default("no"),
105
+ "x-scalar-redirect-uri": z.string().optional().default(defaultRedirectUri),
106
+ tokenUrl,
107
+ "clientSecret": z.string().default("")
108
+ })
109
+ }).partial().default({
110
+ implicit: { type: "implicit", authorizationUrl: "http://localhost:8080" }
111
+ })
146
112
  });
147
113
  const securityOauthSchema = oasSecuritySchemeOauth2.merge(extendedSecuritySchema);
148
- // ---------------------------------------------------------------------------
149
- // Final Types
150
- /**
151
- * Security Requirement
152
- * Lists the required security schemes to execute this operation OR the whole collection/spec.
153
- * The name used for each property MUST correspond to a security scheme declared in the Security
154
- * Schemes under the Components Object.
155
- *
156
- * The key (name) here will be matched to the key of the securityScheme for linking
157
- *
158
- * @see https://spec.openapis.org/oas/latest.html#security-requirement-object
159
- */
160
114
  const oasSecurityRequirementSchema = z.record(z.string(), z.array(z.string()).optional().default([]));
161
- /** OAS Compliant security schemes */
162
115
  const oasSecuritySchemeSchema = z.union([
163
- oasSecuritySchemeApiKey,
164
- oasSecuritySchemeHttp,
165
- oasSecuritySchemeOauth2,
166
- oasSecuritySchemeOpenId,
116
+ oasSecuritySchemeApiKey,
117
+ oasSecuritySchemeHttp,
118
+ oasSecuritySchemeOauth2,
119
+ oasSecuritySchemeOpenId
167
120
  ]);
168
- /** Extended security schemes for workspace usage */
169
- const securitySchemeSchema = z
170
- .discriminatedUnion('type', [securityApiKeySchema, securityHttpSchema, securityOpenIdSchema, securityOauthSchema])
171
- .transform((data) => {
172
- // Set selected scopes from x-default-scopes
173
- if (data.type === 'oauth2' && data['x-default-scopes']?.length) {
174
- const keys = Object.keys(data.flows);
175
- keys.forEach((key) => {
176
- if (data.flows[key]?.selectedScopes && data['x-default-scopes']) {
177
- data.flows[key].selectedScopes = [data['x-default-scopes']].flat();
178
- }
179
- });
180
- }
181
- return data;
121
+ const securitySchemeSchema = z.discriminatedUnion("type", [securityApiKeySchema, securityHttpSchema, securityOpenIdSchema, securityOauthSchema]).transform((data) => {
122
+ if (data.type === "oauth2" && data["x-default-scopes"]?.length) {
123
+ const keys = Object.keys(data.flows);
124
+ keys.forEach((key) => {
125
+ if (data.flows[key]?.selectedScopes && data["x-default-scopes"]) {
126
+ data.flows[key].selectedScopes = [data["x-default-scopes"]].flat();
127
+ }
128
+ });
129
+ }
130
+ return data;
182
131
  });
183
-
184
- export { oasSecurityRequirementSchema, oasSecuritySchemeSchema, pkceOptions, securityApiKeySchema, securityHttpSchema, securityOauthSchema, securityOpenIdSchema, securitySchemeApiKeyIn, securitySchemeSchema };
132
+ export {
133
+ oasSecurityRequirementSchema,
134
+ oasSecuritySchemeSchema,
135
+ pkceOptions,
136
+ securityApiKeySchema,
137
+ securityHttpSchema,
138
+ securityOauthSchema,
139
+ securityOpenIdSchema,
140
+ securitySchemeApiKeyIn,
141
+ securitySchemeSchema
142
+ };
143
+ //# sourceMappingURL=security-scheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/entities/security-scheme.ts"],
4
+ "sourcesContent": ["import { z } from 'zod'\n\nimport { type ENTITY_BRANDS, nanoidSchema } from '../utils/nanoid'\n\n// ---------------------------------------------------------------------------\n// COMMON PROPS FOR ALL SECURITY SCHEMES\n\n/** Some common properties used in all security schemes */\nconst commonProps = z.object({\n /* A description for security scheme. CommonMark syntax MAY be used for rich text representation. */\n description: z.string().optional(),\n})\n\nconst extendedSecuritySchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['SECURITY_SCHEME']>(),\n /** The name key that links a security requirement to a security object */\n nameKey: z.string().optional().default(''),\n})\n\n// ---------------------------------------------------------------------------\n// API KEY\n\nexport const securitySchemeApiKeyIn = ['query', 'header', 'cookie'] as const\n\nconst oasSecuritySchemeApiKey = commonProps.extend({\n type: z.literal('apiKey'),\n /** REQUIRED. The name of the header, query or cookie parameter to be used. */\n name: z.string().optional().default(''),\n /** REQUIRED. The location of the API key. Valid values are \"query\", \"header\" or \"cookie\". */\n in: z.enum(securitySchemeApiKeyIn).optional().default('header').catch('header'),\n})\n\nconst apiKeyValueSchema = z.object({\n value: z.string().default(''),\n})\n\nexport const securityApiKeySchema = oasSecuritySchemeApiKey.merge(extendedSecuritySchema).merge(apiKeyValueSchema)\nexport type SecuritySchemeApiKey = z.infer<typeof securityApiKeySchema>\n\n// ---------------------------------------------------------------------------\n// HTTP\n\nconst oasSecuritySchemeHttp = commonProps.extend({\n type: z.literal('http'),\n /**\n * REQUIRED. The name of the HTTP Authorization scheme to be used in the Authorization header as defined in\n * [RFC7235]. The values used SHOULD be registered in the IANA Authentication Scheme registry.\n */\n scheme: z\n .string()\n .toLowerCase()\n .pipe(z.enum(['basic', 'bearer']))\n .optional()\n .default('basic'),\n /**\n * A hint to the client to identify how the bearer token is formatted.\n * Bearer tokens are usually generated by an authorization server, so\n * this information is primarily for documentation purposes.\n */\n bearerFormat: z\n .union([z.literal('JWT'), z.string()])\n .optional()\n .default('JWT'),\n})\n\nconst httpValueSchema = z.object({\n username: z.string().default(''),\n password: z.string().default(''),\n token: z.string().default(''),\n})\n\nexport const securityHttpSchema = oasSecuritySchemeHttp.merge(extendedSecuritySchema).merge(httpValueSchema)\nexport type SecuritySchemaHttp = z.infer<typeof securityHttpSchema>\n\n// ---------------------------------------------------------------------------\n// OPENID CONNECT\nconst oasSecuritySchemeOpenId = commonProps.extend({\n type: z.literal('openIdConnect'),\n /**\n * REQUIRED. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the\n * form of a URL. The OpenID Connect standard requires the use of TLS.\n */\n openIdConnectUrl: z.string().optional().default(''),\n})\n\nexport const securityOpenIdSchema = oasSecuritySchemeOpenId.merge(extendedSecuritySchema)\nexport type SecuritySchemaOpenId = z.infer<typeof securityOpenIdSchema>\n\n// ---------------------------------------------------------------------------\n\n/**\n * REQUIRED. The authorization URL to be used for this flow. This MUST be in\n * the form of a URL. The OAuth2 standard requires the use of TLS.\n */\nconst authorizationUrl = z.string().default('')\n\n/**\n * REQUIRED. The token URL to be used for this flow. This MUST be in the\n * form of a URL. The OAuth2 standard requires the use of TLS.\n */\nconst tokenUrl = z.string().default('')\n\n/** Common properties used across all oauth2 flows */\nconst flowsCommon = z.object({\n /**\n * The URL to be used for obtaining refresh tokens. This MUST be in the form of a\n * URL. The OAuth2 standard requires the use of TLS.\n */\n 'refreshUrl': z.string().optional().default(''),\n /**\n * REQUIRED. The available scopes for the OAuth2 security scheme. A map\n * between the scope name and a short description for it. The map MAY be empty.\n */\n 'scopes': z.record(z.string(), z.string().optional().default('')).optional().default({}).catch({}),\n 'selectedScopes': z.array(z.string()).optional().default([]),\n /** Extension to save the client Id associated with an oauth flow */\n 'x-scalar-client-id': z.string().optional().default(''),\n /** The auth token */\n 'token': z.string().default(''),\n})\n\n/** Setup a default redirect uri if we can */\nconst defaultRedirectUri = typeof window !== 'undefined' ? window.location.origin + window.location.pathname : ''\n\n/** Options for the x-usePkce extension */\nexport const pkceOptions = ['SHA-256', 'plain', 'no'] as const\n\n/** Oauth2 security scheme */\nconst oasSecuritySchemeOauth2 = commonProps.extend({\n type: z.literal('oauth2'),\n /** The default scopes for the oauth flow */\n 'x-default-scopes': z.string().or(z.array(z.string())).optional(),\n /** REQUIRED. An object containing configuration information for the flow types supported. */\n flows: z\n .object({\n /** Configuration for the OAuth Implicit flow */\n implicit: flowsCommon.extend({\n 'type': z.literal('implicit').default('implicit'),\n authorizationUrl,\n 'x-scalar-redirect-uri': z.string().optional().default(defaultRedirectUri),\n }),\n /** Configuration for the OAuth Resource Owner Password flow */\n password: flowsCommon.extend({\n type: z.literal('password').default('password'),\n tokenUrl,\n clientSecret: z.string().default(''),\n username: z.string().default(''),\n password: z.string().default(''),\n }),\n /** Configuration for the OAuth Client Credentials flow. Previously called application in OpenAPI 2.0. */\n clientCredentials: flowsCommon.extend({\n type: z.literal('clientCredentials').default('clientCredentials'),\n tokenUrl,\n clientSecret: z.string().default(''),\n }),\n /** Configuration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.*/\n authorizationCode: flowsCommon.extend({\n 'type': z.literal('authorizationCode').default('authorizationCode'),\n authorizationUrl,\n 'x-usePkce': z.enum(pkceOptions).optional().default('no'),\n 'x-scalar-redirect-uri': z.string().optional().default(defaultRedirectUri),\n tokenUrl,\n 'clientSecret': z.string().default(''),\n }),\n })\n .partial()\n .default({\n implicit: { type: 'implicit', authorizationUrl: 'http://localhost:8080' },\n }),\n})\n\nexport const securityOauthSchema = oasSecuritySchemeOauth2.merge(extendedSecuritySchema)\n\nexport type SecuritySchemeOauth2 = z.infer<typeof securityOauthSchema>\nexport type SecuritySchemeOauth2Payload = z.input<typeof securityOauthSchema>\nexport type Oauth2Flow = NonNullable<\n SecuritySchemeOauth2['flows']['authorizationCode' | 'clientCredentials' | 'implicit' | 'password']\n>\n/** Payload for the oauth 2 flows + extensions */\nexport type Oauth2FlowPayload = NonNullable<SecuritySchemeOauth2Payload['flows']>[\n | 'authorizationCode'\n | 'clientCredentials'\n | 'implicit'\n | 'password'] &\n Record<`x-${string}`, string>\n\n// ---------------------------------------------------------------------------\n// Final Types\n\n/**\n * Security Requirement\n * Lists the required security schemes to execute this operation OR the whole collection/spec.\n * The name used for each property MUST correspond to a security scheme declared in the Security\n * Schemes under the Components Object.\n *\n * The key (name) here will be matched to the key of the securityScheme for linking\n *\n * @see https://spec.openapis.org/oas/latest.html#security-requirement-object\n */\nexport const oasSecurityRequirementSchema = z.record(z.string(), z.array(z.string()).optional().default([]))\n\n/** OAS Compliant security schemes */\nexport const oasSecuritySchemeSchema = z.union([\n oasSecuritySchemeApiKey,\n oasSecuritySchemeHttp,\n oasSecuritySchemeOauth2,\n oasSecuritySchemeOpenId,\n])\n\n/** Extended security schemes for workspace usage */\nexport const securitySchemeSchema = z\n .discriminatedUnion('type', [securityApiKeySchema, securityHttpSchema, securityOpenIdSchema, securityOauthSchema])\n .transform((data) => {\n // Set selected scopes from x-default-scopes\n if (data.type === 'oauth2' && data['x-default-scopes']?.length) {\n const keys = Object.keys(data.flows) as Array<keyof typeof data.flows>\n keys.forEach((key) => {\n if (data.flows[key]?.selectedScopes && data['x-default-scopes']) {\n data.flows[key].selectedScopes = [data['x-default-scopes']].flat()\n }\n })\n }\n return data\n })\n\n/**\n * Security Scheme Object\n *\n * @see https://spec.openapis.org/oas/latest.html#security-scheme-object\n */\nexport type SecurityScheme = z.infer<typeof securitySchemeSchema>\nexport type SecuritySchemePayload = z.input<typeof securitySchemeSchema>\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAElB,SAA6B,oBAAoB;AAMjD,MAAM,cAAc,EAAE,OAAO;AAAA;AAAA,EAE3B,aAAa,EAAE,OAAO,EAAE,SAAS;AACnC,CAAC;AAED,MAAM,yBAAyB,EAAE,OAAO;AAAA,EACtC,KAAK,aAAa,MAAwC;AAAA;AAAA,EAE1D,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE;AAC3C,CAAC;AAKM,MAAM,yBAAyB,CAAC,SAAS,UAAU,QAAQ;AAElE,MAAM,0BAA0B,YAAY,OAAO;AAAA,EACjD,MAAM,EAAE,QAAQ,QAAQ;AAAA;AAAA,EAExB,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE;AAAA;AAAA,EAEtC,IAAI,EAAE,KAAK,sBAAsB,EAAE,SAAS,EAAE,QAAQ,QAAQ,EAAE,MAAM,QAAQ;AAChF,CAAC;AAED,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACjC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE;AAC9B,CAAC;AAEM,MAAM,uBAAuB,wBAAwB,MAAM,sBAAsB,EAAE,MAAM,iBAAiB;AAMjH,MAAM,wBAAwB,YAAY,OAAO;AAAA,EAC/C,MAAM,EAAE,QAAQ,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA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