@scalar/types 0.0.36 → 0.0.39

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 (30) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/api-reference/api-reference-configuration.d.ts +578 -0
  3. package/dist/api-reference/api-reference-configuration.d.ts.map +1 -0
  4. package/dist/api-reference/api-reference-configuration.js +335 -0
  5. package/dist/api-reference/api-reference-configuration.test-d.d.ts +2 -0
  6. package/dist/api-reference/api-reference-configuration.test-d.d.ts.map +1 -0
  7. package/dist/api-reference/helpers/migrate-theme-variables.d.ts +10 -0
  8. package/dist/api-reference/helpers/migrate-theme-variables.d.ts.map +1 -0
  9. package/dist/api-reference/helpers/migrate-theme-variables.js +21 -0
  10. package/dist/api-reference/html-rendering-configuration.d.ts +34 -0
  11. package/dist/api-reference/html-rendering-configuration.d.ts.map +1 -0
  12. package/dist/api-reference/html-rendering-configuration.js +23 -0
  13. package/dist/api-reference/index.d.ts +4 -0
  14. package/dist/api-reference/index.d.ts.map +1 -0
  15. package/dist/api-reference/index.js +3 -0
  16. package/dist/legacy/reference-config.d.ts +51 -44
  17. package/dist/legacy/reference-config.d.ts.map +1 -1
  18. package/dist/snippetz/index.d.ts.map +1 -0
  19. package/dist/snippetz/index.js +1 -0
  20. package/dist/snippetz/snippetz.d.ts +42 -0
  21. package/dist/snippetz/snippetz.d.ts.map +1 -0
  22. package/dist/snippetz/snippetz.js +42 -0
  23. package/dist/snippetz/snippetz.test-d.d.ts +2 -0
  24. package/dist/snippetz/snippetz.test-d.d.ts.map +1 -0
  25. package/package.json +16 -7
  26. package/dist/external/index.d.ts.map +0 -1
  27. package/dist/external/index.js +0 -1
  28. package/dist/external/snippetz.d.ts +0 -2
  29. package/dist/external/snippetz.d.ts.map +0 -1
  30. /package/dist/{external → snippetz}/index.d.ts +0 -0
@@ -0,0 +1,335 @@
1
+ import { z } from 'zod';
2
+ import { migrateThemeVariables } from './helpers/migrate-theme-variables.js';
3
+
4
+ /** Available theme presets for the API reference */
5
+ const themeIdEnum = z.enum([
6
+ 'alternate',
7
+ 'default',
8
+ 'moon',
9
+ 'purple',
10
+ 'solarized',
11
+ 'bluePlanet',
12
+ 'deepSpace',
13
+ 'saturn',
14
+ 'kepler',
15
+ 'elysiajs',
16
+ 'fastify',
17
+ 'mars',
18
+ 'none',
19
+ ]);
20
+ /** Valid keys that can be used with CTRL/CMD to open the search modal */
21
+ const searchHotKeyEnum = z.enum([
22
+ 'a',
23
+ 'b',
24
+ 'c',
25
+ 'd',
26
+ 'e',
27
+ 'f',
28
+ 'g',
29
+ 'h',
30
+ 'i',
31
+ 'j',
32
+ 'k',
33
+ 'l',
34
+ 'm',
35
+ 'n',
36
+ 'o',
37
+ 'p',
38
+ 'q',
39
+ 'r',
40
+ 's',
41
+ 't',
42
+ 'u',
43
+ 'v',
44
+ 'w',
45
+ 'x',
46
+ 'y',
47
+ 'z',
48
+ ]);
49
+ /** Supported integration types */
50
+ const integrationEnum = z
51
+ .enum([
52
+ 'adonisjs',
53
+ 'docusaurus',
54
+ 'dotnet',
55
+ 'elysiajs',
56
+ 'express',
57
+ 'fastapi',
58
+ 'fastify',
59
+ 'go',
60
+ 'hono',
61
+ 'html',
62
+ 'laravel',
63
+ 'litestar',
64
+ 'nestjs',
65
+ 'nextjs',
66
+ 'nitro',
67
+ 'nuxt',
68
+ 'platformatic',
69
+ 'react',
70
+ 'rust',
71
+ 'vue',
72
+ ])
73
+ .nullable();
74
+ /** Configuration for the OpenAPI/Swagger specification */
75
+ const specConfigurationSchema = z.object({
76
+ /** URL to an OpenAPI/Swagger document */
77
+ url: z.string().optional(),
78
+ /**
79
+ * Directly embed the OpenAPI document.
80
+ * Can be a string, object, function returning an object, or null.
81
+ * @remarks It's recommended to pass a URL instead of content.
82
+ */
83
+ content: z.union([z.string(), z.record(z.any()), z.function().returns(z.record(z.any())), z.null()]).optional(),
84
+ });
85
+ /** Configuration for path-based routing */
86
+ const pathRoutingSchema = z.object({
87
+ /** Base path for the API reference */
88
+ basePath: z.string(),
89
+ });
90
+ /** Configuration for the Api Client */
91
+ const apiClientConfigurationSchema = z.object({
92
+ /** Prefill authentication */
93
+ authentication: z.any().optional(), // Temp until we bring in the new auth
94
+ /** Base URL for the API server */
95
+ baseServerURL: z.string().optional(),
96
+ /**
97
+ * Whether to hide the client button
98
+ * @default false
99
+ */
100
+ hideClientButton: z.boolean().optional().default(false).catch(false),
101
+ /** URL to a request proxy for the API client */
102
+ proxyUrl: z.string().optional(),
103
+ /** Key used with CTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k) */
104
+ searchHotKey: searchHotKeyEnum.optional(),
105
+ /** List of OpenAPI server objects */
106
+ servers: z.array(z.any()).optional(), // Using any for OpenAPIV3_1.ServerObject
107
+ /**
108
+ * Whether to show the sidebar
109
+ * @default true
110
+ */
111
+ showSidebar: z.boolean().optional().default(true).catch(true),
112
+ /** The Swagger/OpenAPI spec to render */
113
+ spec: specConfigurationSchema.optional(),
114
+ /** A string to use one of the color presets */
115
+ theme: themeIdEnum.optional().default('default').catch('default'),
116
+ /** Integration type identifier */
117
+ _integration: integrationEnum.optional(),
118
+ });
119
+ const OLD_PROXY_URL = 'https://api.scalar.com/request-proxy';
120
+ const NEW_PROXY_URL = 'https://proxy.scalar.com';
121
+ /** Configuration for the Api Reference */
122
+ const apiReferenceConfigurationSchema = apiClientConfigurationSchema
123
+ .merge(z.object({
124
+ /**
125
+ * The layout to use for the references
126
+ * @default 'modern'
127
+ */
128
+ layout: z.enum(['modern', 'classic']).optional().default('modern').catch('modern'),
129
+ /**
130
+ * URL to a request proxy for the API client
131
+ * @deprecated Use proxyUrl instead
132
+ */
133
+ proxy: z.string().optional(),
134
+ /**
135
+ * Whether the spec input should show
136
+ * @default false
137
+ */
138
+ isEditable: z.boolean().optional().default(false).catch(false),
139
+ /**
140
+ * Whether to show models in the sidebar, search, and content.
141
+ * @default false
142
+ */
143
+ hideModels: z.boolean().optional().default(false).catch(false),
144
+ /**
145
+ * Whether to show the "Download OpenAPI Document" button
146
+ * @default false
147
+ */
148
+ hideDownloadButton: z.boolean().optional().default(false).catch(false),
149
+ /**
150
+ * Whether to show the "Test Request" button
151
+ * @default false
152
+ */
153
+ hideTestRequestButton: z.boolean().optional().default(false).catch(false),
154
+ /**
155
+ * Whether to show the sidebar search bar
156
+ * @default false
157
+ */
158
+ hideSearch: z.boolean().optional().default(false).catch(false),
159
+ /** Whether dark mode is on or off initially (light mode) */
160
+ darkMode: z.boolean().optional(),
161
+ /** forceDarkModeState makes it always this state no matter what */
162
+ forceDarkModeState: z.enum(['dark', 'light']).optional(),
163
+ /**
164
+ * Whether to show the dark mode toggle
165
+ * @default false
166
+ */
167
+ hideDarkModeToggle: z.boolean().optional().default(false).catch(false),
168
+ /**
169
+ * If used, passed data will be added to the HTML header
170
+ * @see https://unhead.unjs.io/usage/composables/use-seo-meta
171
+ */
172
+ metaData: z.any().optional(), // Using any for UseSeoMetaInput since it's an external type
173
+ /**
174
+ * Path to a favicon image
175
+ * @default undefined
176
+ * @example '/favicon.svg'
177
+ */
178
+ favicon: z.string().optional(),
179
+ /**
180
+ * List of httpsnippet clients to hide from the clients menu
181
+ * By default hides Unirest, pass `[]` to show all clients
182
+ */
183
+ hiddenClients: z
184
+ .union([z.record(z.union([z.boolean(), z.array(z.string())])), z.array(z.string()), z.literal(true)])
185
+ .optional(),
186
+ /** Determine the HTTP client that's selected by default */
187
+ defaultHttpClient: z
188
+ .object({
189
+ targetKey: z.custom(),
190
+ clientKey: z.string(),
191
+ })
192
+ .optional(),
193
+ /** Custom CSS to be added to the page */
194
+ customCss: z.string().optional(),
195
+ /** onSpecUpdate is fired on spec/swagger content change */
196
+ onSpecUpdate: z.function().args(z.string()).returns(z.void()).optional(),
197
+ /** onServerChange is fired on selected server change */
198
+ onServerChange: z.function().args(z.string()).returns(z.void()).optional(),
199
+ /**
200
+ * Route using paths instead of hashes, your server MUST support this
201
+ * @example '/standalone-api-reference/:custom(.*)?'
202
+ * @experimental
203
+ * @default undefined
204
+ */
205
+ pathRouting: pathRoutingSchema.optional(),
206
+ /**
207
+ * Customize the heading portion of the hash
208
+ * @param heading - The heading object
209
+ * @returns A string ID used to generate the URL hash
210
+ * @default (heading) => `#description/${heading.slug}`
211
+ */
212
+ generateHeadingSlug: z
213
+ .function()
214
+ .args(z.object({ slug: z.string().default('headingSlug') }))
215
+ .returns(z.string())
216
+ .optional(),
217
+ /**
218
+ * Customize the model portion of the hash
219
+ * @param model - The model object with a name property
220
+ * @returns A string ID used to generate the URL hash
221
+ * @default (model) => slug(model.name)
222
+ */
223
+ generateModelSlug: z
224
+ .function()
225
+ .args(z.object({ name: z.string().default('modelName') }))
226
+ .returns(z.string())
227
+ .optional(),
228
+ /**
229
+ * Customize the tag portion of the hash
230
+ * @param tag - The tag object
231
+ * @returns A string ID used to generate the URL hash
232
+ * @default (tag) => slug(tag.name)
233
+ */
234
+ generateTagSlug: z
235
+ .function()
236
+ .args(z.object({ name: z.string().default('tagName') }))
237
+ .returns(z.string())
238
+ .optional(),
239
+ /**
240
+ * Customize the operation portion of the hash
241
+ * @param operation - The operation object
242
+ * @returns A string ID used to generate the URL hash
243
+ * @default (operation) => `${operation.method}${operation.path}`
244
+ */
245
+ generateOperationSlug: z
246
+ .function()
247
+ .args(z.object({
248
+ path: z.string(),
249
+ operationId: z.string().optional(),
250
+ method: z.string(),
251
+ summary: z.string().optional(),
252
+ }))
253
+ .returns(z.string())
254
+ .optional(),
255
+ /**
256
+ * Customize the webhook portion of the hash
257
+ * @param webhook - The webhook object
258
+ * @returns A string ID used to generate the URL hash
259
+ * @default (webhook) => slug(webhook.name)
260
+ */
261
+ generateWebhookSlug: z
262
+ .function()
263
+ .args(z.object({
264
+ name: z.string(),
265
+ method: z.string().optional(),
266
+ }))
267
+ .returns(z.string())
268
+ .optional(),
269
+ /** Callback fired when the reference is fully loaded */
270
+ onLoaded: z.union([z.function().returns(z.void()), z.undefined()]).optional(),
271
+ /**
272
+ * To handle redirects, pass a function that will recieve:
273
+ * - The current path with hash if pathRouting is enabled
274
+ * - The current hash if hashRouting (default)
275
+ * And then passes that to history.replaceState
276
+ *
277
+ * @example hashRouting (default)
278
+ * ```ts
279
+ * redirect: (hash: string) => hash.replace('#v1/old-path', '#v2/new-path')
280
+ * ```
281
+ * @example pathRouting
282
+ * ```ts
283
+ * redirect: (pathWithHash: string) => {
284
+ * if (pathWithHash.includes('#')) {
285
+ * return pathWithHash.replace('/v1/tags/user#operation/get-user', '/v1/tags/user/operation/get-user')
286
+ * }
287
+ * return null
288
+ * }
289
+ * ```
290
+ */
291
+ redirect: z.function().args(z.string()).returns(z.string().nullable().optional()).optional(),
292
+ /**
293
+ * Whether to include default fonts
294
+ * @default true
295
+ */
296
+ withDefaultFonts: z.boolean().optional().default(true).catch(true),
297
+ /** Whether to expand all tags by default */
298
+ defaultOpenAllTags: z.boolean().optional(),
299
+ /**
300
+ * Function to sort tags
301
+ * @default 'alpha' for alphabetical sorting
302
+ */
303
+ tagsSorter: z.union([z.literal('alpha'), z.function().args(z.any(), z.any()).returns(z.number())]).optional(),
304
+ /**
305
+ * Function to sort operations
306
+ * @default 'alpha' for alphabetical sorting
307
+ */
308
+ operationsSorter: z
309
+ .union([z.literal('alpha'), z.literal('method'), z.function().args(z.any(), z.any()).returns(z.number())])
310
+ .optional(),
311
+ }))
312
+ .transform((_configuration) => {
313
+ const configuration = { ..._configuration };
314
+ // Migrate legacy theme variables
315
+ if (configuration.customCss) {
316
+ configuration.customCss = migrateThemeVariables(configuration.customCss);
317
+ }
318
+ // Migrate proxy URL
319
+ if (configuration.proxy) {
320
+ console.warn(`[DEPRECATED] You’re using the deprecated 'proxy' attribute, rename it to 'proxyUrl' or update the package.`);
321
+ if (!configuration.proxyUrl) {
322
+ configuration.proxyUrl = configuration.proxy;
323
+ }
324
+ delete configuration.proxy;
325
+ }
326
+ if (configuration.proxyUrl === OLD_PROXY_URL) {
327
+ console.warn(`[DEPRECATED] Warning: configuration.proxyUrl points to our old proxy (${OLD_PROXY_URL}).`);
328
+ console.warn(`[DEPRECATED] We are overwriting the value and use the new proxy URL (${NEW_PROXY_URL}) instead.`);
329
+ console.warn(`[DEPRECATED] Action Required: You should manually update your configuration to use the new URL (${NEW_PROXY_URL}). Read more: https://github.com/scalar/scalar`);
330
+ configuration.proxyUrl = NEW_PROXY_URL;
331
+ }
332
+ return configuration;
333
+ });
334
+
335
+ export { apiClientConfigurationSchema, apiReferenceConfigurationSchema };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api-reference-configuration.test-d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-reference-configuration.test-d.d.ts","sourceRoot":"","sources":["../../src/api-reference/api-reference-configuration.test-d.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ /** The legacy -> updated CSS variable prefix pairs */
2
+ export declare const PREFIX_MIGRATIONS: readonly [readonly ["--theme-", "--scalar-"], readonly ["--sidebar-", "--scalar-sidebar-"]];
3
+ export declare const LEGACY_PREFIXES: ("--theme-" | "--sidebar-")[];
4
+ /**
5
+ * Checks a style string for legacy theme variables and updated them to the new theme variables
6
+ *
7
+ * @param styles the style string to be checked for legacy theme variables and updated
8
+ */
9
+ export declare function migrateThemeVariables(styles: string): string;
10
+ //# sourceMappingURL=migrate-theme-variables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-theme-variables.d.ts","sourceRoot":"","sources":["../../../src/api-reference/helpers/migrate-theme-variables.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,eAAO,MAAM,iBAAiB,6FAGpB,CAAA;AAEV,eAAO,MAAM,eAAe,+BAA8C,CAAA;AAE1E;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D"}
@@ -0,0 +1,21 @@
1
+ /** The legacy -> updated CSS variable prefix pairs */
2
+ const PREFIX_MIGRATIONS = [
3
+ ['--theme-', '--scalar-'],
4
+ ['--sidebar-', '--scalar-sidebar-'],
5
+ ];
6
+ const LEGACY_PREFIXES = PREFIX_MIGRATIONS.map(([legacy]) => legacy);
7
+ /**
8
+ * Checks a style string for legacy theme variables and updated them to the new theme variables
9
+ *
10
+ * @param styles the style string to be checked for legacy theme variables and updated
11
+ */
12
+ function migrateThemeVariables(styles) {
13
+ const hasLegacyPrefixes = LEGACY_PREFIXES.some((p) => styles.includes(p));
14
+ if (!hasLegacyPrefixes)
15
+ return styles;
16
+ console.warn(`DEPRECATION WARNING: It looks like you're using legacy CSS variables in your custom CSS string. Please migrate them to use the updated prefixes. See https://github.com/scalar/scalar/blob/main/documentation/themes.md#theme-prefix-changes`);
17
+ // Replaces each old variable in the prefix migrations
18
+ return PREFIX_MIGRATIONS.reduce((s, [o, n]) => s.replaceAll(o, n), styles);
19
+ }
20
+
21
+ export { LEGACY_PREFIXES, PREFIX_MIGRATIONS, migrateThemeVariables };
@@ -0,0 +1,34 @@
1
+ import type { ApiReferenceConfiguration } from '../api-reference/api-reference-configuration.ts';
2
+ import { z } from 'zod';
3
+ /**
4
+ * Zod schema for HTML rendering configuration
5
+ */
6
+ export declare const htmlRenderingConfigurationSchema: z.ZodObject<{
7
+ /**
8
+ * The URL to the Scalar API Reference JS CDN.
9
+ *
10
+ * Use this to pin a specific version of the Scalar API Reference.
11
+ *
12
+ * @default https://cdn.jsdelivr.net/npm/@scalar/api-reference
13
+ *
14
+ * @example https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.122
15
+ */
16
+ cdn: z.ZodDefault<z.ZodOptional<z.ZodString>>;
17
+ /**
18
+ * The title of the page.
19
+ */
20
+ pageTitle: z.ZodDefault<z.ZodOptional<z.ZodString>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ cdn: string;
23
+ pageTitle: string;
24
+ }, {
25
+ cdn?: string | undefined;
26
+ pageTitle?: string | undefined;
27
+ }>;
28
+ /**
29
+ * The configuration for the static HTML rendering using the CDN.
30
+ *
31
+ * It’s the ApiReferenceConfiguration, but extended with the `pageTitle` and `cdn` options.
32
+ */
33
+ export type HtmlRenderingConfiguration = ApiReferenceConfiguration & z.infer<typeof htmlRenderingConfigurationSchema>;
34
+ //# sourceMappingURL=html-rendering-configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-rendering-configuration.d.ts","sourceRoot":"","sources":["../../src/api-reference/html-rendering-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC/F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,gCAAgC;IAC3C;;;;;;;;OAQG;;IAEH;;OAEG;;;;;;;;EAEH,CAAA;AAEF;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA"}
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Zod schema for HTML rendering configuration
5
+ */
6
+ const htmlRenderingConfigurationSchema = z.object({
7
+ /**
8
+ * The URL to the Scalar API Reference JS CDN.
9
+ *
10
+ * Use this to pin a specific version of the Scalar API Reference.
11
+ *
12
+ * @default https://cdn.jsdelivr.net/npm/@scalar/api-reference
13
+ *
14
+ * @example https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.122
15
+ */
16
+ cdn: z.string().optional().default('https://cdn.jsdelivr.net/npm/@scalar/api-reference'),
17
+ /**
18
+ * The title of the page.
19
+ */
20
+ pageTitle: z.string().optional().default('Scalar API Reference'),
21
+ });
22
+
23
+ export { htmlRenderingConfigurationSchema };
@@ -0,0 +1,4 @@
1
+ export * from './api-reference-configuration.ts';
2
+ export * from './html-rendering-configuration.ts';
3
+ export { migrateThemeVariables } from './helpers/migrate-theme-variables.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api-reference/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { apiClientConfigurationSchema, apiReferenceConfigurationSchema } from './api-reference-configuration.js';
2
+ export { htmlRenderingConfigurationSchema } from './html-rendering-configuration.js';
3
+ export { migrateThemeVariables } from './helpers/migrate-theme-variables.js';