@scalar/api-client 0.5.1 → 0.5.3

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 (59) hide show
  1. package/package.json +6 -7
  2. package/src/components/ApiClient/AddressBar.vue +0 -462
  3. package/src/components/ApiClient/ApiClient.vue +0 -266
  4. package/src/components/ApiClient/Request/Request.vue +0 -271
  5. package/src/components/ApiClient/Request/RequestAuth.vue +0 -221
  6. package/src/components/ApiClient/Request/RequestBody.vue +0 -40
  7. package/src/components/ApiClient/Request/RequestHeaders.vue +0 -24
  8. package/src/components/ApiClient/Request/RequestQuery.vue +0 -25
  9. package/src/components/ApiClient/Request/RequestVariables.vue +0 -25
  10. package/src/components/ApiClient/Request/index.ts +0 -1
  11. package/src/components/ApiClient/RequestHistory.vue +0 -114
  12. package/src/components/ApiClient/RequestHistoryItem.vue +0 -59
  13. package/src/components/ApiClient/Response/Copilot.vue.bak +0 -385
  14. package/src/components/ApiClient/Response/Response.vue +0 -120
  15. package/src/components/ApiClient/Response/ResponseBody.vue +0 -24
  16. package/src/components/ApiClient/Response/ResponseHeaders.vue +0 -52
  17. package/src/components/ApiClient/Response/ResponseMetaInformation.vue +0 -58
  18. package/src/components/ApiClient/Response/index.ts +0 -1
  19. package/src/components/ApiClient/index.ts +0 -1
  20. package/src/components/CollapsibleSection/CollapsibleSection.vue +0 -149
  21. package/src/components/CollapsibleSection/index.ts +0 -1
  22. package/src/components/FlowModal.vue +0 -133
  23. package/src/components/Grid/Grid.vue +0 -511
  24. package/src/components/Grid/SimpleGrid.vue +0 -33
  25. package/src/components/Grid/index.ts +0 -2
  26. package/src/components/HelpfulLink.vue +0 -19
  27. package/src/components/SimpleTable/SimpleCell.vue +0 -47
  28. package/src/components/SimpleTable/SimpleHeader.vue +0 -17
  29. package/src/components/SimpleTable/SimpleRow.vue +0 -14
  30. package/src/components/SimpleTable/SimpleTable.vue +0 -13
  31. package/src/components/SimpleTable/index.ts +0 -4
  32. package/src/fixtures/httpHeaders.ts +0 -530
  33. package/src/fixtures/httpStatusCodes.ts +0 -259
  34. package/src/fixtures/index.ts +0 -6
  35. package/src/helpers/concatenateUrlAndPath.test.ts +0 -27
  36. package/src/helpers/concatenateUrlAndPath.ts +0 -13
  37. package/src/helpers/createPlaceholderRequest.ts +0 -16
  38. package/src/helpers/generateParameters.ts +0 -19
  39. package/src/helpers/generateRequest.ts +0 -26
  40. package/src/helpers/index.ts +0 -10
  41. package/src/helpers/mapFromArray.ts +0 -16
  42. package/src/helpers/normalizePath.test.ts +0 -17
  43. package/src/helpers/normalizePath.ts +0 -16
  44. package/src/helpers/normalizeRequestMethod.test.ts +0 -29
  45. package/src/helpers/normalizeRequestMethod.ts +0 -43
  46. package/src/helpers/normalizeUrl.test.ts +0 -25
  47. package/src/helpers/normalizeUrl.ts +0 -24
  48. package/src/helpers/replaceVariables.test.ts +0 -13
  49. package/src/helpers/replaceVariables.ts +0 -11
  50. package/src/helpers/sendRequest.test.ts +0 -50
  51. package/src/helpers/sendRequest.ts +0 -105
  52. package/src/hooks/index.ts +0 -2
  53. package/src/hooks/useCopilot.ts +0 -64
  54. package/src/hooks/useOperation.ts +0 -43
  55. package/src/index.ts +0 -8
  56. package/src/stores/apiClientRequestStore.ts +0 -103
  57. package/src/stores/apiClientStore.ts +0 -57
  58. package/src/stores/index.ts +0 -5
  59. package/src/types.ts +0 -185
@@ -1,105 +0,0 @@
1
- import axios from 'axios'
2
- import { nanoid } from 'nanoid'
3
-
4
- import type {
5
- ClientRequestConfig,
6
- ClientResponse,
7
- RequestResult,
8
- SendRequestConfig,
9
- } from '../types'
10
- import {
11
- concatenateUrlAndPath,
12
- mapFromArray,
13
- normalizePath,
14
- normalizeRequestMethod,
15
- normalizeUrl,
16
- replaceVariables,
17
- } from './'
18
-
19
- const defaultHeaders = {
20
- 'User-Agent': 'Scalar API Client',
21
- }
22
-
23
- /**
24
- * Send a request via the proxy
25
- */
26
- export async function sendRequest(
27
- request: SendRequestConfig,
28
- proxyUrl?: string,
29
- ): Promise<RequestResult | null> {
30
- const method = normalizeRequestMethod(request.type)
31
- const headers: Record<string, string | number> = {
32
- ...defaultHeaders,
33
- ...mapFromArray(request.headers ?? [], 'name', 'value'),
34
- }
35
- const url = normalizeUrl(request.url)
36
- const path = normalizePath(request.path)
37
- const urlWithPath = concatenateUrlAndPath(url, path)
38
- const renderedURL = replaceVariables(
39
- urlWithPath,
40
- mapFromArray(request.parameters ?? [], 'name', 'value'),
41
- )
42
-
43
- /** TODO: Make dynamic */
44
- const auth = {
45
- type: 'none',
46
- }
47
-
48
- const startTime = Date.now()
49
-
50
- const requestOptions = {
51
- method,
52
- url: renderedURL,
53
- auth,
54
- headers,
55
- data: request.body,
56
- }
57
-
58
- const config = proxyUrl
59
- ? {
60
- method: 'POST',
61
- url: proxyUrl,
62
- data: requestOptions,
63
- }
64
- : {
65
- method: requestOptions.method,
66
- url: requestOptions.url,
67
- headers: requestOptions.headers,
68
- data: requestOptions.data,
69
- }
70
-
71
- console.info(`${requestOptions.method} ${requestOptions.url}`)
72
-
73
- const response: (ClientResponse & { error: false }) | { error: true } =
74
- // @ts-ignore
75
- await axios(config)
76
- .then((res) => {
77
- return {
78
- ...res.data,
79
- error: false,
80
- }
81
- })
82
- .catch((err) => {
83
- return {
84
- error: true,
85
- ...err?.response,
86
- }
87
- })
88
-
89
- return response.error
90
- ? null
91
- : {
92
- sentTime: Date.now(),
93
- request: {
94
- ...request,
95
- type: method,
96
- url,
97
- path,
98
- },
99
- response: {
100
- ...response,
101
- duration: Date.now() - startTime,
102
- },
103
- responseId: nanoid(),
104
- }
105
- }
@@ -1,2 +0,0 @@
1
- // export { useCopilot } from './useCopilot'
2
- export { useOperation, type ParamMap } from './useOperation'
@@ -1,64 +0,0 @@
1
- import { useWebSocket } from '@vueuse/core'
2
- import { reactive, readonly } from 'vue'
3
-
4
- export enum CopilotLoadingStates {
5
- Inactive = 'Inactive',
6
- Fix = 'Fix',
7
- Loading = 'Loading',
8
- Working = 'Working',
9
- Success = 'Success',
10
- }
11
-
12
- export type RequestData = {
13
- id: string
14
- request: string
15
- }
16
- export type RecommendationHandler = (recommendation: string) => void
17
-
18
- const recommendationHandler: Set<RecommendationHandler> = new Set([])
19
-
20
- function onMessage(_ws: WebSocket, event: MessageEvent) {
21
- const jsonData = JSON.parse(event.data)
22
- const recommendation = jsonData['response']
23
- recommendationHandler.forEach((handler) => handler(recommendation))
24
- }
25
-
26
- const { send } = useWebSocket(import.meta.env.VITE_COPILOT_WS_URL, {
27
- onMessage,
28
- autoReconnect: true,
29
- })
30
-
31
- function sendCopilot(requestData: RequestData) {
32
- setLoadingState(CopilotLoadingStates.Loading)
33
- const jsonString = JSON.stringify(requestData)
34
- send(jsonString)
35
- }
36
-
37
- const serverHandler = () => ({
38
- uuid: '',
39
- curlRequest:
40
- "curl -X 'GET' 'https://petstore.swagger.io/v2/pet/findByStatus?status=SOld' -H 'accept: application/json'",
41
- })
42
-
43
- const serverHandlerState = reactive(serverHandler())
44
-
45
- const state = reactive({
46
- loadingState: CopilotLoadingStates.Inactive,
47
- })
48
-
49
- function setLoadingState(loadingState: CopilotLoadingStates) {
50
- state.loadingState = loadingState
51
- }
52
-
53
- /**
54
- * This hook is used to send requests to the copilot server and receive recommendations.
55
- */
56
- export const useCopilot = () => ({
57
- sendCopilot,
58
- state: readonly(state),
59
- onRecommendation: (handler: RecommendationHandler) => {
60
- recommendationHandler.add(handler)
61
- },
62
- serverHandlerState,
63
- setLoadingState,
64
- })
@@ -1,43 +0,0 @@
1
- import { computed } from 'vue'
2
-
3
- import type { Operation, Parameters } from '../types'
4
-
5
- export type ParamMap = {
6
- path: Parameters[]
7
- query: Parameters[]
8
- header: Parameters[]
9
- }
10
-
11
- export type OperationProps = {
12
- operation: Operation
13
- }
14
-
15
- /**
16
- * This hook is used to generate the parameters for the request from the parameters in the swagger file
17
- */
18
- export function useOperation(props: OperationProps) {
19
- const parameterMap = computed(() => {
20
- const { parameters } = props.operation.information
21
- const map: ParamMap = {
22
- path: [],
23
- query: [],
24
- header: [],
25
- }
26
- if (parameters) {
27
- parameters.forEach((parameter: Parameters) => {
28
- if (parameter.in === 'path') {
29
- map.path.push(parameter)
30
- } else if (parameter.in === 'query') {
31
- map.query.push(parameter)
32
- } else if (parameter.in === 'header') {
33
- map.header.push(parameter)
34
- }
35
- })
36
- }
37
- return map
38
- })
39
-
40
- return {
41
- parameterMap,
42
- }
43
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export { ApiClient } from './components/ApiClient'
2
-
3
- export * from './helpers'
4
- export * from './hooks'
5
- export * from './stores/apiClientStore'
6
- export * from './stores/apiClientRequestStore'
7
- export * from './types'
8
- export * from './fixtures'
@@ -1,103 +0,0 @@
1
- import { computed, reactive, ref } from 'vue'
2
-
3
- import { createPlaceholderRequest } from '../helpers/createPlaceholderRequest'
4
- import type { AuthState, ClientRequestConfig, RequestResult } from '../types'
5
-
6
- // Auth state template
7
- export const createEmptyAuthState = (): AuthState => ({
8
- type: 'none',
9
- basic: {
10
- userName: '',
11
- password: '',
12
- active: true,
13
- },
14
- oauthTwo: {
15
- generatedToken: '',
16
- discoveryURL: '',
17
- authURL: '',
18
- accessTokenURL: '',
19
- clientID: '',
20
- clientSecret: '',
21
- scope: '',
22
- active: true,
23
- },
24
- bearer: {
25
- token: '',
26
- active: true,
27
- },
28
- digest: {
29
- userName: '',
30
- password: '',
31
- active: true,
32
- },
33
- })
34
-
35
- /**
36
- * Request state
37
- */
38
- type RequestHistoryOrder = string[]
39
- type RequestHistoryEntry = RequestResult
40
-
41
- // Request Authorization State
42
- const authState = reactive(createEmptyAuthState())
43
-
44
- // Log of all requests made
45
- const requestHistory: Record<string, RequestHistoryEntry> = reactive({})
46
-
47
- // Request list order
48
- const requestHistoryOrder = ref<RequestHistoryOrder>([])
49
-
50
- // Id of the currently viewed request
51
- const activeRequestId = ref('')
52
-
53
- // Active request object
54
- const activeRequest = reactive(createPlaceholderRequest())
55
-
56
- /**
57
- * Mutators
58
- */
59
-
60
- // Add a new request to the history log and make it active
61
- const addRequestToHistory = (value: RequestHistoryEntry) => {
62
- requestHistory[value.responseId] = value
63
- activeRequestId.value = value.responseId
64
- requestHistoryOrder.value.unshift(value.responseId)
65
- }
66
-
67
- // Set a response by key to currently active
68
- const setActiveResponse = (historyID: string) => {
69
- activeRequestId.value = historyID
70
- const { request }: { request: ClientRequestConfig } =
71
- requestHistory[historyID]
72
- Object.assign(activeRequest, request)
73
- }
74
-
75
- // Get the currently active response
76
- const activeResponse = computed(() =>
77
- activeRequestId.value ? requestHistory[activeRequestId.value].response : null,
78
- )
79
-
80
- // Set the active request object
81
- const setActiveRequest = (request: ClientRequestConfig) => {
82
- Object.assign(activeRequest, request)
83
- }
84
-
85
- /**
86
- * View state
87
- */
88
-
89
- // Whether the request is in read mode or edit mode
90
- const readOnly = ref(true)
91
-
92
- export const useApiClientRequestStore = () => ({
93
- authState,
94
- readOnly,
95
- activeRequest,
96
- activeResponse,
97
- requestHistory,
98
- requestHistoryOrder,
99
- activeRequestId,
100
- setActiveResponse,
101
- addRequestToHistory,
102
- setActiveRequest,
103
- })
@@ -1,57 +0,0 @@
1
- import { reactive, readonly } from 'vue'
2
-
3
- type State = {
4
- showApiClient: boolean
5
- activeApiClientEndpointId: string
6
- activeItem: any
7
- snippetType: string
8
- activeSidebar: string
9
- }
10
-
11
- function defaultState(): State {
12
- return {
13
- showApiClient: false,
14
- activeApiClientEndpointId: '',
15
- activeItem: {},
16
- snippetType: 'javascript',
17
- activeSidebar: '',
18
- }
19
- }
20
-
21
- const state = reactive<State>(defaultState())
22
-
23
- function toggleApiClient(item?: any, forceShow = false) {
24
- if (forceShow) {
25
- state.showApiClient = true
26
- } else {
27
- state.showApiClient = !state.showApiClient
28
- }
29
- if (item) {
30
- state.activeItem = item
31
- }
32
- }
33
-
34
- function hideApiClient() {
35
- state.showApiClient = false
36
- }
37
-
38
- function setActiveApiClientEndpointId(id: string) {
39
- state.activeApiClientEndpointId = id
40
- }
41
-
42
- function setSnippetType(type: string) {
43
- state.snippetType = type
44
- }
45
-
46
- function setActiveSidebar(item: string) {
47
- state.activeSidebar = item
48
- }
49
-
50
- export const useApiClientStore = () => ({
51
- state: readonly(state),
52
- toggleApiClient,
53
- setActiveApiClientEndpointId,
54
- setSnippetType,
55
- setActiveSidebar,
56
- hideApiClient,
57
- })
@@ -1,5 +0,0 @@
1
- export { useApiClientStore } from './apiClientStore'
2
- export {
3
- useApiClientRequestStore,
4
- createEmptyAuthState,
5
- } from './apiClientRequestStore'
package/src/types.ts DELETED
@@ -1,185 +0,0 @@
1
- export type BasicAuth = {
2
- userName: string
3
- password: string
4
- active: boolean
5
- }
6
-
7
- export type OAuthTwo = {
8
- generatedToken: string
9
- discoveryURL: string
10
- authURL: string
11
- accessTokenURL: string
12
- clientID: string
13
- clientSecret: string
14
- scope: string
15
- active: boolean
16
- }
17
-
18
- export type Bearer = {
19
- token: string
20
- active: boolean
21
- }
22
-
23
- export type Digest = {
24
- userName: string
25
- password: string
26
- active: boolean
27
- }
28
-
29
- export type AuthType = 'basic' | 'oauthTwo' | 'bearer' | 'digest' | 'none'
30
-
31
- export type AuthState = {
32
- type: AuthType
33
- basic: BasicAuth
34
- oauthTwo: OAuthTwo
35
- bearer: Bearer
36
- digest: Digest
37
- }
38
-
39
- export type BaseParameter = {
40
- name: string
41
- value: string | number
42
- customClass?: string
43
- }
44
-
45
- export type Header = BaseParameter
46
-
47
- export type Query = BaseParameter
48
-
49
- export type FormDataItem = BaseParameter
50
-
51
- /** Complete request state for a client request */
52
- export type ClientRequestConfig = {
53
- id?: string
54
- name?: string
55
- url: string
56
- /** HTTP Request Method */
57
- type: string
58
- /** Request path */
59
- path: string
60
- /** TODO: Rename to variables? */
61
- /** Path parameters */
62
- parameters?: BaseParameter[]
63
- /** Query parameters */
64
- query?: Query[]
65
- /** Request headers */
66
- headers?: Header[]
67
- /** Content type matched body */
68
- body?: string
69
- /** Optional form data body */
70
- formData?: FormDataItem[]
71
- }
72
-
73
- /** Formatted request for the proxy server */
74
- export type ProxyPayload = {
75
- method: string
76
- url: string
77
- body: string
78
- headers: Header[]
79
- auth: Record<string, string>
80
- grpc: boolean
81
- }
82
-
83
- /** Client response from the proxy */
84
- export type ClientResponse = {
85
- cookies: Record<string, string>
86
- headers: Record<string, string>
87
- statusCode: number
88
- statusText: string
89
- data: string
90
- duration: number
91
- }
92
-
93
- export type SendRequestConfig = Partial<ClientRequestConfig> &
94
- Required<Pick<ClientRequestConfig, 'url'>>
95
-
96
- export type RequestResult = {
97
- request: ClientRequestConfig
98
- response: ClientResponse
99
- responseId: string
100
- sentTime: number
101
- }
102
-
103
- export type Schema = {
104
- format: string
105
- type: string
106
- }
107
-
108
- export type Parameters = {
109
- description?: string
110
- in?: string
111
- name: string
112
- required?: boolean
113
- schema?: Schema
114
- }
115
-
116
- export type Security = {
117
- api_key?: any[]
118
- petstore_auth?: string[]
119
- }
120
-
121
- export type ContentProperties = {
122
- [key: string]: {
123
- type: string
124
- format: string
125
- example: string
126
- required: string[]
127
- description?: string
128
- properties?: ContentProperties
129
- }
130
- }
131
-
132
- export type ContentSchema = {
133
- schema: {
134
- type: string
135
- required: string[]
136
- properties: ContentProperties
137
- }
138
- }
139
-
140
- export type ContentType =
141
- | 'application/json'
142
- | 'application/xml'
143
- | 'text/plain'
144
- | 'text/html'
145
- | 'application/x-www-form-urlencoded'
146
- | 'multipart/form-data'
147
-
148
- export type Content = {
149
- [key in ContentType]: ContentSchema
150
- }
151
-
152
- export type RequestBody = {
153
- description: string
154
- content: Content
155
- required: boolean
156
- }
157
-
158
- export type Response = {
159
- description: string
160
- content: any
161
- }
162
-
163
- export type Information = {
164
- description: string
165
- operationId: string
166
- parameters: Parameters[]
167
- responses: Record<string, Response>
168
- security: Security[]
169
- requestBody: RequestBody
170
- summary: string
171
- tags: string[]
172
- }
173
-
174
- export type Operation = {
175
- httpVerb: string
176
- path: string
177
- operationId: string
178
- name: string
179
- description: string
180
- information: Information
181
- }
182
-
183
- export type Server = {
184
- url: string
185
- }