@scalar/types 0.0.1

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 ADDED
@@ -0,0 +1,9 @@
1
+ # @scalar/types
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 78db8f5: feat: use new @scalar/types package
8
+ - Updated dependencies [78db8f5]
9
+ - @scalar/themes@0.9.25
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Scalar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@scalar/types",
3
+ "description": "Types to work with Scalar packages",
4
+ "license": "MIT",
5
+ "author": "Scalar (https://github.com/scalar)",
6
+ "homepage": "https://github.com/scalar/scalar",
7
+ "bugs": "https://github.com/scalar/scalar/issues/new/choose",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/scalar/scalar.git",
11
+ "directory": "packages/types"
12
+ },
13
+ "keywords": [
14
+ "typescript",
15
+ "types",
16
+ "scalar",
17
+ "references"
18
+ ],
19
+ "version": "0.0.1",
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "type": "module",
24
+ "exports": {
25
+ "./legacy": "./src/legacy/index.ts",
26
+ "./utils": "./src/utils/index.ts"
27
+ },
28
+ "files": [
29
+ "src",
30
+ "CHANGELOG.md"
31
+ ],
32
+ "dependencies": {
33
+ "@unhead/schema": "^1.9.5",
34
+ "@scalar/openapi-types": "0.0.1",
35
+ "@scalar/themes": "0.9.25"
36
+ },
37
+ "scripts": {
38
+ "lint:check": "eslint .",
39
+ "lint:fix": "eslint . --fix",
40
+ "types:check": "tsc --noEmit --skipLibCheck --composite false"
41
+ }
42
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * These types are copied from httpsnippet-lite to reduce depenedencies
3
+ */
4
+
5
+ export type Param = {
6
+ /** name of a posted parameter. */
7
+ name: string
8
+ /** value of a posted parameter or content of a posted file */
9
+ value?: string | undefined
10
+ /** name of a posted file. */
11
+ fileName?: string | undefined
12
+ /** content type of a posted file. */
13
+ contentType?: string | undefined
14
+ /** A comment provided by the user or the application */
15
+ comment?: string | undefined
16
+ }
17
+
18
+ export type PostDataCommon = {
19
+ /** Mime type of posted data. */
20
+ mimeType: string
21
+ /** A comment provided by the user or the application */
22
+ comment?: string | undefined
23
+ }
24
+
25
+ type PostDataBase = PostDataCommon & {
26
+ text?: string
27
+ params?: Param[]
28
+ }
29
+
30
+ export type Cookie = {
31
+ /** The name of the cookie. */
32
+ name: string
33
+ /** The cookie value. */
34
+ value: string
35
+ /** The path pertaining to the cookie. */
36
+ path?: string | undefined
37
+ /** The host of the cookie. */
38
+ domain?: string | undefined
39
+ /**
40
+ * Cookie expiration time.
41
+ * (ISO 8601 - `YYYY-MM-DDThh:mm:ss.sTZD`,
42
+ * e.g. `2009-07-24T19:20:30.123+02:00`).
43
+ */
44
+ expires?: string | undefined
45
+ /** Set to true if the cookie is HTTP only, false otherwise. */
46
+ httpOnly?: boolean | undefined
47
+ /** True if the cookie was transmitted over ssl, false otherwise. */
48
+ secure?: boolean | undefined
49
+ /** A comment provided by the user or the application */
50
+ comment?: string | undefined
51
+ }
52
+
53
+ /**
54
+ * This object represents a headers (used in `request` and `response` objects).
55
+ *
56
+ * http://www.softwareishard.com/blog/har-12-spec/#headers
57
+ */
58
+ export type Header = {
59
+ name: string
60
+ value: string
61
+ /** A comment provided by the user or the application */
62
+ comment?: string | undefined
63
+ }
64
+ /**
65
+ * This object represents a parameter & value parsed from a query string,
66
+ * if any (embedded in `request` object).
67
+ *
68
+ * http://www.softwareishard.com/blog/har-12-spec/#queryString
69
+ */
70
+ export type QueryString = {
71
+ name: string
72
+ value: string
73
+ /** A comment provided by the user or the application */
74
+ comment?: string | undefined
75
+ }
76
+
77
+ /**
78
+ * Post data with `params` specified.
79
+ */
80
+ export type PostDataParams = {
81
+ /**
82
+ * List of posted parameters (in case of URL encoded parameters).
83
+ */
84
+ params: Param[]
85
+
86
+ /**
87
+ * _`params` and `text` fields are mutually exclusive._
88
+ */
89
+ text?: never | undefined
90
+ }
91
+
92
+ /**
93
+ * Post data with `text` specified.
94
+ */
95
+ export type PostDataText = {
96
+ /**
97
+ * Plain text posted data
98
+ */
99
+ text: string
100
+
101
+ /**
102
+ * _`params` and `text` fields are mutually exclusive._
103
+ */
104
+ params?: never | undefined
105
+ }
106
+
107
+ /**
108
+ * This object describes posted data, if any (embedded in `request` object).
109
+ *
110
+ * http://www.softwareishard.com/blog/har-12-spec/#postData
111
+ */
112
+ export type PostData = PostDataCommon & (PostDataParams | PostDataText)
113
+
114
+ export type Request = {
115
+ /** Request method (`GET`, `POST`, ...). */
116
+ method: string
117
+ /** Absolute URL of the request (fragments are not included). */
118
+ url: string
119
+ /** Request HTTP Version. */
120
+ httpVersion: string
121
+ /** List of cookie objects. */
122
+ cookies: Cookie[]
123
+ /** List of header objects. */
124
+ headers: Header[]
125
+ /** List of query parameter objects. */
126
+ queryString: QueryString[]
127
+ /** Posted data info. */
128
+ postData?: PostData | undefined
129
+ /**
130
+ * Total number of bytes from the start of the HTTP request message until
131
+ * (and including) the double CRLF before the body.
132
+ *
133
+ * Set to `-1` if the info is not available.
134
+ */
135
+ headersSize: number
136
+ /**
137
+ * Size of the request body (POST data payload) in bytes.
138
+ *
139
+ * Set to `-1` if the info is not available.
140
+ */
141
+ bodySize: number
142
+ /** A comment provided by the user or the application */
143
+ comment?: string | undefined
144
+ }
145
+
146
+ export type HarRequest = Omit<Request, 'postData'> & {
147
+ postData?: PostDataBase
148
+ }
149
+
150
+ export type TargetId =
151
+ | 'c'
152
+ | 'clojure'
153
+ | 'csharp'
154
+ | 'go'
155
+ | 'http'
156
+ | 'java'
157
+ | 'javascript'
158
+ | 'kotlin'
159
+ | 'node'
160
+ | 'objc'
161
+ | 'ocaml'
162
+ | 'php'
163
+ | 'powershell'
164
+ | 'python'
165
+ | 'r'
166
+ | 'ruby'
167
+ | 'shell'
168
+ | 'swift'
@@ -0,0 +1 @@
1
+ export * from './httpsnippet-lite'
@@ -0,0 +1 @@
1
+ export * from './reference-config'
@@ -0,0 +1,417 @@
1
+ import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'
2
+ import type { ThemeId } from '@scalar/themes'
3
+ import type { UseSeoMetaInput } from '@unhead/schema'
4
+
5
+ import type { HarRequest, TargetId } from '../external'
6
+
7
+ /**
8
+ * This re-export is needed due to a typescript issue
9
+ * @see https://github.com/microsoft/TypeScript/issues/42873
10
+ */
11
+ export type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'
12
+
13
+ export type ClientInfo = {
14
+ key: string
15
+ title: string
16
+ link: string
17
+ description: string
18
+ }
19
+
20
+ export type TargetInfo = {
21
+ key: TargetId
22
+ title: string
23
+ extname: `.${string}` | null
24
+ default: string
25
+ }
26
+
27
+ export type HiddenClients =
28
+ // Just hide all
29
+ | true
30
+ // Exclude whole targets or just specific clients
31
+ | Partial<Record<TargetInfo['key'], boolean | ClientInfo['key'][]>>
32
+ // Backwards compatibility with the previous behavior ['fetch', 'xhr']
33
+ | ClientInfo['key'][]
34
+
35
+ type HttpClientState = { targetKey: TargetId; clientKey: string }
36
+
37
+ export type PathRouting = {
38
+ basePath: string
39
+ }
40
+
41
+ export type ReferenceConfiguration = {
42
+ /** A string to use one of the color presets */
43
+ theme?: ThemeId
44
+ /** The layout to use for the references */
45
+ layout?: 'modern' | 'classic'
46
+ /** The Swagger/OpenAPI spec to render */
47
+ spec?: SpecConfiguration
48
+ /** URL to a request proxy for the API client */
49
+ proxy?: string
50
+ /** Whether the spec input should show */
51
+ isEditable?: boolean
52
+ /** Whether to show the sidebar */
53
+ showSidebar?: boolean
54
+ /**
55
+ * Whether to show models in the sidebar, search, and content.
56
+ *
57
+ * @default false
58
+ */
59
+ hideModels?: boolean
60
+ /**
61
+ * Whether to show the "Download OpenAPI Specification" button
62
+ *
63
+ * @default false
64
+ */
65
+ hideDownloadButton?: boolean
66
+ /** Whether dark mode is on or off initially (light mode) */
67
+ darkMode?: boolean
68
+ /** forceDarkModeState makes it always this state no matter what*/
69
+ forceDarkModeState?: 'dark' | 'light'
70
+ /** Whether to show the dark mode toggle */
71
+ hideDarkModeToggle?: boolean
72
+ /** Key used with CTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k) */
73
+ searchHotKey?:
74
+ | 'a'
75
+ | 'b'
76
+ | 'c'
77
+ | 'd'
78
+ | 'e'
79
+ | 'f'
80
+ | 'g'
81
+ | 'h'
82
+ | 'i'
83
+ | 'j'
84
+ | 'k'
85
+ | 'l'
86
+ | 'm'
87
+ | 'n'
88
+ | 'o'
89
+ | 'p'
90
+ | 'q'
91
+ | 'r'
92
+ | 's'
93
+ | 't'
94
+ | 'u'
95
+ | 'v'
96
+ | 'w'
97
+ | 'x'
98
+ | 'y'
99
+ | 'z'
100
+ /**
101
+ * If used, passed data will be added to the HTML header
102
+ * @see https://unhead.unjs.io/usage/composables/use-seo-meta
103
+ */
104
+ metaData?: UseSeoMetaInput
105
+ /**
106
+ * List of httpsnippet clients to hide from the clients menu
107
+ * By default hides Unirest, pass `[]` to show all clients
108
+ */
109
+ hiddenClients?: HiddenClients
110
+ /** Determine the HTTP client that’s selected by default */
111
+ defaultHttpClient?: HttpClientState
112
+ /** Custom CSS to be added to the page */
113
+ customCss?: string
114
+ /** onSpecUpdate is fired on spec/swagger content change */
115
+ onSpecUpdate?: (spec: string) => void
116
+ /** Prefill authentication */
117
+ authentication?: Partial<AuthenticationState>
118
+ /**
119
+ * Route using paths instead of hashes, your server MUST support this
120
+ * for example vue router needs a catch all so any subpaths are included
121
+ *
122
+ * @example
123
+ * '/standalone-api-reference/:custom(.*)?'
124
+ *
125
+ * @experimental
126
+ * @default undefined
127
+ */
128
+ pathRouting?: PathRouting
129
+ /**
130
+ * The baseServerURL is used when the spec servers are relative paths and we are using SSR.
131
+ * On the client we can grab the window.location.origin but on the server we need
132
+ * to use this prop.
133
+ *
134
+ * @default undefined
135
+ * @example 'http://localhost:3000'
136
+ */
137
+ baseServerURL?: string
138
+ /**
139
+ * List of servers to override the openapi spec servers
140
+ *
141
+ * @default undefined
142
+ * @example [{ url: 'https://api.scalar.com', description: 'Production server' }]
143
+ */
144
+ servers?: Server[]
145
+ /**
146
+ * We’re using Inter and JetBrains Mono as the default fonts. If you want to use your own fonts, set this to false.
147
+ *
148
+ * @default true
149
+ */
150
+ withDefaultFonts?: boolean
151
+ /**
152
+ * By default we only open the relevant tag based on the url, however if you want all the tags open by default then set this configuration option :)
153
+ *
154
+ * @default false
155
+ */
156
+ defaultOpenAllTags?: boolean
157
+ /**
158
+ * Sort tags alphabetically or with a custom sort function
159
+ */
160
+ tagsSorter?: 'alpha' | ((a: Tag, b: Tag) => number)
161
+ }
162
+
163
+ export type Server = OpenAPIV3.ServerObject | OpenAPIV3_1.ServerObject
164
+
165
+ export type BaseParameter = {
166
+ name: string
167
+ description?: string | null
168
+ value: string | number | Record<string, any>
169
+ required?: boolean
170
+ enabled: boolean
171
+ }
172
+
173
+ type OptionalCharset = string | null
174
+
175
+ export type ContentType =
176
+ | `application/json${OptionalCharset}`
177
+ | `application/xml${OptionalCharset}`
178
+ | `text/plain${OptionalCharset}`
179
+ | `text/html${OptionalCharset}`
180
+ | `application/octet-stream${OptionalCharset}`
181
+ | `application/x-www-form-urlencoded${OptionalCharset}`
182
+ | `multipart/form-data${OptionalCharset}`
183
+
184
+ export type Cookie = {
185
+ name: string
186
+ value: string
187
+ }
188
+
189
+ export type CustomRequestExample = {
190
+ lang: string
191
+ label: string
192
+ source: string
193
+ }
194
+
195
+ export type HarRequestWithPath = HarRequest & {
196
+ path: string
197
+ }
198
+
199
+ export type Header = {
200
+ name: string
201
+ value: string
202
+ }
203
+
204
+ export type Information = {
205
+ 'description'?: string
206
+ 'operationId'?: string | number
207
+ 'parameters'?: Parameters[]
208
+ 'responses'?: Record<string, ScalarResponse>
209
+ 'security'?: OpenAPIV3.SecurityRequirementObject[]
210
+ 'requestBody'?: RequestBody
211
+ 'summary'?: string
212
+ 'tags'?: string[]
213
+ 'deprecated'?: boolean
214
+ /**
215
+ * Scalar
216
+ */
217
+ 'x-custom-examples'?: CustomRequestExample[]
218
+ /**
219
+ * Redocly, current
220
+ */
221
+ 'x-codeSamples'?: CustomRequestExample[]
222
+ /**
223
+ * Redocly, deprecated
224
+ */
225
+ 'x-code-samples'?: CustomRequestExample[]
226
+ }
227
+
228
+ export type Operation = {
229
+ httpVerb:
230
+ | 'GET'
231
+ | 'HEAD'
232
+ | 'PATCH'
233
+ | 'POST'
234
+ | 'PUT'
235
+ | 'TRACE'
236
+ | 'CONNECT'
237
+ | 'DELETE'
238
+ | 'OPTIONS'
239
+ path: string
240
+ operationId?: string
241
+ name?: string
242
+ description?: string
243
+ information?: Information
244
+ }
245
+ export type Parameters = {
246
+ // Fixed Fields
247
+ name: string
248
+ in?: string
249
+ description?: string
250
+ required?: boolean
251
+ deprecated?: boolean
252
+ allowEmptyValue?: boolean
253
+ // Other
254
+ style?: 'form' | 'simple'
255
+ explode?: boolean
256
+ allowReserved?: boolean
257
+ schema?: Schema
258
+ example?: any
259
+ examples?: Map<string, any>
260
+ content?: RequestBodyMimeTypes
261
+ }
262
+
263
+ export type Query = {
264
+ name: string
265
+ value: string
266
+ }
267
+
268
+ // Create a mapped type to ensure keys are a subset of ContentType
269
+ export type RequestBodyMimeTypes = {
270
+ [K in ContentType]?: {
271
+ schema?: any
272
+ example?: any
273
+ examples?: any
274
+ }
275
+ }
276
+
277
+ export type ScalarResponse = {
278
+ description: string
279
+ content: any
280
+ }
281
+
282
+ export type RequestBody = {
283
+ description?: string
284
+ required?: boolean
285
+ content?: RequestBodyMimeTypes
286
+ }
287
+
288
+ /** For providing a OAS spec object or url to be fetched */
289
+ export type SpecConfiguration = {
290
+ /** URL to a Swagger/OpenAPI file */
291
+ url?: string
292
+ /** Swagger/Open API spec */
293
+ content?: string | Record<string, any> | (() => Record<string, any>)
294
+ }
295
+
296
+ export type Schema = {
297
+ type: string
298
+ name?: string
299
+ example?: any
300
+ default?: any
301
+ format?: string
302
+ description?: string
303
+ properties?: Record<string, Schema>
304
+ }
305
+
306
+ export type TransformedOperation = Operation & {
307
+ pathParameters?: Parameters[]
308
+ }
309
+
310
+ export type CollapsedSidebarItems = Record<string, boolean>
311
+
312
+ export type AuthenticationState = {
313
+ customSecurity: boolean
314
+ preferredSecurityScheme: string | null
315
+ securitySchemes?:
316
+ | OpenAPIV2.SecurityDefinitionsObject
317
+ | OpenAPIV3.ComponentsObject['securitySchemes']
318
+ | OpenAPIV3_1.ComponentsObject['securitySchemes']
319
+ http: {
320
+ basic: {
321
+ username: string
322
+ password: string
323
+ }
324
+ bearer: {
325
+ token: string
326
+ }
327
+ }
328
+ apiKey: {
329
+ token: string
330
+ }
331
+ oAuth2: {
332
+ clientId: string
333
+ scopes: string[]
334
+ accessToken: string
335
+ state: string
336
+ username: string
337
+ password: string
338
+ }
339
+ }
340
+
341
+ export type Heading = {
342
+ depth: number
343
+ value: string
344
+ slug?: string
345
+ }
346
+
347
+ export type CodeBlockSSRKey = `components-scalar-code-block${number}`
348
+ export type DescriptionSectionSSRKey =
349
+ `components-Content-Introduction-Description-sections${number}`
350
+ export type ExampleRequestSSRKey =
351
+ `components-Content-Operation-Example-Request${number}`
352
+
353
+ export type ScalarState = {
354
+ 'hash'?: string
355
+ 'useGlobalStore-authentication'?: AuthenticationState
356
+ 'useSidebarContent-collapsedSidebarItems'?: CollapsedSidebarItems
357
+ [key: CodeBlockSSRKey]: string
358
+ [key: DescriptionSectionSSRKey]: {
359
+ heading: Heading
360
+ content: string
361
+ }[]
362
+ [key: ExampleRequestSSRKey]: string
363
+ }
364
+
365
+ export type SSRState = {
366
+ payload: {
367
+ data: ScalarState
368
+ }
369
+ url: string
370
+ }
371
+
372
+ export type Tag = {
373
+ 'name': string
374
+ 'description': string
375
+ 'operations': TransformedOperation[]
376
+ 'x-displayName'?: string
377
+ }
378
+
379
+ export type TagGroup = {
380
+ name: string
381
+ tags: string[]
382
+ }
383
+
384
+ export type Definitions = OpenAPIV2.DefinitionsObject
385
+
386
+ export type Webhooks = Record<
387
+ string,
388
+ Record<
389
+ OpenAPIV3_1.HttpMethods,
390
+ TransformedOperation & {
391
+ 'x-internal'?: boolean
392
+ }
393
+ >
394
+ >
395
+
396
+ export type Spec = {
397
+ 'tags'?: Tag[]
398
+ 'info':
399
+ | Partial<OpenAPIV2.Document['info']>
400
+ | Partial<OpenAPIV3.Document['info']>
401
+ | Partial<OpenAPIV3_1.Document['info']>
402
+ 'host'?: OpenAPIV2.Document['host']
403
+ 'basePath'?: OpenAPIV2.Document['basePath']
404
+ 'schemes'?: OpenAPIV2.Document['schemes']
405
+ 'externalDocs'?: {
406
+ url: string
407
+ description?: string
408
+ }
409
+ 'servers'?: OpenAPIV3.Document['servers'] | OpenAPIV3_1.Document['servers']
410
+ 'components'?: OpenAPIV3.ComponentsObject | OpenAPIV3_1.ComponentsObject
411
+ 'webhooks'?: Webhooks
412
+ 'definitions'?: Definitions
413
+ 'swagger'?: OpenAPIV2.Document['swagger']
414
+ 'openapi'?: OpenAPIV3.Document['openapi'] | OpenAPIV3_1.Document['openapi']
415
+ 'x-tagGroups'?: TagGroup[]
416
+ 'security'?: OpenAPIV3.SecurityRequirementObject[]
417
+ }
@@ -0,0 +1 @@
1
+ export * from './utility-types'
@@ -0,0 +1,4 @@
1
+ /**
2
+ * When the object values are unknown
3
+ */
4
+ export type UnknownObject = Record<string, unknown>