@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.
- package/package.json +6 -7
- package/src/components/ApiClient/AddressBar.vue +0 -462
- package/src/components/ApiClient/ApiClient.vue +0 -266
- package/src/components/ApiClient/Request/Request.vue +0 -271
- package/src/components/ApiClient/Request/RequestAuth.vue +0 -221
- package/src/components/ApiClient/Request/RequestBody.vue +0 -40
- package/src/components/ApiClient/Request/RequestHeaders.vue +0 -24
- package/src/components/ApiClient/Request/RequestQuery.vue +0 -25
- package/src/components/ApiClient/Request/RequestVariables.vue +0 -25
- package/src/components/ApiClient/Request/index.ts +0 -1
- package/src/components/ApiClient/RequestHistory.vue +0 -114
- package/src/components/ApiClient/RequestHistoryItem.vue +0 -59
- package/src/components/ApiClient/Response/Copilot.vue.bak +0 -385
- package/src/components/ApiClient/Response/Response.vue +0 -120
- package/src/components/ApiClient/Response/ResponseBody.vue +0 -24
- package/src/components/ApiClient/Response/ResponseHeaders.vue +0 -52
- package/src/components/ApiClient/Response/ResponseMetaInformation.vue +0 -58
- package/src/components/ApiClient/Response/index.ts +0 -1
- package/src/components/ApiClient/index.ts +0 -1
- package/src/components/CollapsibleSection/CollapsibleSection.vue +0 -149
- package/src/components/CollapsibleSection/index.ts +0 -1
- package/src/components/FlowModal.vue +0 -133
- package/src/components/Grid/Grid.vue +0 -511
- package/src/components/Grid/SimpleGrid.vue +0 -33
- package/src/components/Grid/index.ts +0 -2
- package/src/components/HelpfulLink.vue +0 -19
- package/src/components/SimpleTable/SimpleCell.vue +0 -47
- package/src/components/SimpleTable/SimpleHeader.vue +0 -17
- package/src/components/SimpleTable/SimpleRow.vue +0 -14
- package/src/components/SimpleTable/SimpleTable.vue +0 -13
- package/src/components/SimpleTable/index.ts +0 -4
- package/src/fixtures/httpHeaders.ts +0 -530
- package/src/fixtures/httpStatusCodes.ts +0 -259
- package/src/fixtures/index.ts +0 -6
- package/src/helpers/concatenateUrlAndPath.test.ts +0 -27
- package/src/helpers/concatenateUrlAndPath.ts +0 -13
- package/src/helpers/createPlaceholderRequest.ts +0 -16
- package/src/helpers/generateParameters.ts +0 -19
- package/src/helpers/generateRequest.ts +0 -26
- package/src/helpers/index.ts +0 -10
- package/src/helpers/mapFromArray.ts +0 -16
- package/src/helpers/normalizePath.test.ts +0 -17
- package/src/helpers/normalizePath.ts +0 -16
- package/src/helpers/normalizeRequestMethod.test.ts +0 -29
- package/src/helpers/normalizeRequestMethod.ts +0 -43
- package/src/helpers/normalizeUrl.test.ts +0 -25
- package/src/helpers/normalizeUrl.ts +0 -24
- package/src/helpers/replaceVariables.test.ts +0 -13
- package/src/helpers/replaceVariables.ts +0 -11
- package/src/helpers/sendRequest.test.ts +0 -50
- package/src/helpers/sendRequest.ts +0 -105
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useCopilot.ts +0 -64
- package/src/hooks/useOperation.ts +0 -43
- package/src/index.ts +0 -8
- package/src/stores/apiClientRequestStore.ts +0 -103
- package/src/stores/apiClientStore.ts +0 -57
- package/src/stores/index.ts +0 -5
- package/src/types.ts +0 -185
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
export type HttpStatusCode = {
|
|
2
|
-
name: string
|
|
3
|
-
url: string
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type HttpStatusCodes = Record<string, HttpStatusCode>
|
|
7
|
-
|
|
8
|
-
export const httpStatusCodes: HttpStatusCodes = {
|
|
9
|
-
100: {
|
|
10
|
-
name: 'Continue',
|
|
11
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/100',
|
|
12
|
-
},
|
|
13
|
-
101: {
|
|
14
|
-
name: 'Switching Protocols',
|
|
15
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/101',
|
|
16
|
-
},
|
|
17
|
-
102: {
|
|
18
|
-
name: 'Processing',
|
|
19
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/102',
|
|
20
|
-
},
|
|
21
|
-
103: {
|
|
22
|
-
name: 'Early Hints',
|
|
23
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103',
|
|
24
|
-
},
|
|
25
|
-
200: {
|
|
26
|
-
name: 'OK',
|
|
27
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200',
|
|
28
|
-
},
|
|
29
|
-
201: {
|
|
30
|
-
name: 'Created',
|
|
31
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201',
|
|
32
|
-
},
|
|
33
|
-
202: {
|
|
34
|
-
name: 'Accepted',
|
|
35
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/202',
|
|
36
|
-
},
|
|
37
|
-
203: {
|
|
38
|
-
name: 'Non-Authoritative Information',
|
|
39
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/203',
|
|
40
|
-
},
|
|
41
|
-
204: {
|
|
42
|
-
name: 'No Content',
|
|
43
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204',
|
|
44
|
-
},
|
|
45
|
-
205: {
|
|
46
|
-
name: 'Reset Content',
|
|
47
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/205',
|
|
48
|
-
},
|
|
49
|
-
206: {
|
|
50
|
-
name: 'Partial Content',
|
|
51
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206',
|
|
52
|
-
},
|
|
53
|
-
207: {
|
|
54
|
-
name: 'Multi-Status',
|
|
55
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/207',
|
|
56
|
-
},
|
|
57
|
-
208: {
|
|
58
|
-
name: 'Already Reported',
|
|
59
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/208',
|
|
60
|
-
},
|
|
61
|
-
226: {
|
|
62
|
-
name: 'IM Used',
|
|
63
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/226',
|
|
64
|
-
},
|
|
65
|
-
300: {
|
|
66
|
-
name: 'Multiple Choices',
|
|
67
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/300',
|
|
68
|
-
},
|
|
69
|
-
301: {
|
|
70
|
-
name: 'Moved Permanently',
|
|
71
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301',
|
|
72
|
-
},
|
|
73
|
-
302: {
|
|
74
|
-
name: 'Found',
|
|
75
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302',
|
|
76
|
-
},
|
|
77
|
-
303: {
|
|
78
|
-
name: 'See Other',
|
|
79
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303',
|
|
80
|
-
},
|
|
81
|
-
304: {
|
|
82
|
-
name: 'Not Modified',
|
|
83
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304',
|
|
84
|
-
},
|
|
85
|
-
305: {
|
|
86
|
-
name: 'Use Proxy',
|
|
87
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/305',
|
|
88
|
-
},
|
|
89
|
-
306: {
|
|
90
|
-
name: '(Unused)',
|
|
91
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/306',
|
|
92
|
-
},
|
|
93
|
-
307: {
|
|
94
|
-
name: 'Temporary Redirect',
|
|
95
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307',
|
|
96
|
-
},
|
|
97
|
-
308: {
|
|
98
|
-
name: 'Permanent Redirect',
|
|
99
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308',
|
|
100
|
-
},
|
|
101
|
-
400: {
|
|
102
|
-
name: 'Bad Request',
|
|
103
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400',
|
|
104
|
-
},
|
|
105
|
-
401: {
|
|
106
|
-
name: 'Unauthorized',
|
|
107
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401',
|
|
108
|
-
},
|
|
109
|
-
402: {
|
|
110
|
-
name: 'Payment Required',
|
|
111
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/402',
|
|
112
|
-
},
|
|
113
|
-
403: {
|
|
114
|
-
name: 'Forbidden',
|
|
115
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403',
|
|
116
|
-
},
|
|
117
|
-
404: {
|
|
118
|
-
name: 'Not Found',
|
|
119
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404',
|
|
120
|
-
},
|
|
121
|
-
405: {
|
|
122
|
-
name: 'Method Not Allowed',
|
|
123
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405',
|
|
124
|
-
},
|
|
125
|
-
406: {
|
|
126
|
-
name: 'Not Acceptable',
|
|
127
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406',
|
|
128
|
-
},
|
|
129
|
-
407: {
|
|
130
|
-
name: 'Proxy Authentication Required',
|
|
131
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407',
|
|
132
|
-
},
|
|
133
|
-
408: {
|
|
134
|
-
name: 'Request Timeout',
|
|
135
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408',
|
|
136
|
-
},
|
|
137
|
-
409: {
|
|
138
|
-
name: 'Conflict',
|
|
139
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409',
|
|
140
|
-
},
|
|
141
|
-
410: {
|
|
142
|
-
name: 'Gone',
|
|
143
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/410',
|
|
144
|
-
},
|
|
145
|
-
411: {
|
|
146
|
-
name: 'Length Required',
|
|
147
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/411',
|
|
148
|
-
},
|
|
149
|
-
412: {
|
|
150
|
-
name: 'Precondition Failed',
|
|
151
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/412',
|
|
152
|
-
},
|
|
153
|
-
413: {
|
|
154
|
-
name: 'Content Too Large',
|
|
155
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413',
|
|
156
|
-
},
|
|
157
|
-
414: {
|
|
158
|
-
name: 'URI Too Long',
|
|
159
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/414',
|
|
160
|
-
},
|
|
161
|
-
415: {
|
|
162
|
-
name: 'Unsupported Media Type',
|
|
163
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415',
|
|
164
|
-
},
|
|
165
|
-
416: {
|
|
166
|
-
name: 'Range Not Satisfiable',
|
|
167
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416',
|
|
168
|
-
},
|
|
169
|
-
417: {
|
|
170
|
-
name: 'Expectation Failed',
|
|
171
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/417',
|
|
172
|
-
},
|
|
173
|
-
421: {
|
|
174
|
-
name: 'Misdirected Request',
|
|
175
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/421',
|
|
176
|
-
},
|
|
177
|
-
422: {
|
|
178
|
-
name: 'Unprocessable Content',
|
|
179
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422',
|
|
180
|
-
},
|
|
181
|
-
423: {
|
|
182
|
-
name: 'Locked',
|
|
183
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/423',
|
|
184
|
-
},
|
|
185
|
-
424: {
|
|
186
|
-
name: 'Failed Dependency',
|
|
187
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/424',
|
|
188
|
-
},
|
|
189
|
-
425: {
|
|
190
|
-
name: 'Too Early',
|
|
191
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/425',
|
|
192
|
-
},
|
|
193
|
-
426: {
|
|
194
|
-
name: 'Upgrade Required',
|
|
195
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/426',
|
|
196
|
-
},
|
|
197
|
-
428: {
|
|
198
|
-
name: 'Precondition Required',
|
|
199
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/428',
|
|
200
|
-
},
|
|
201
|
-
429: {
|
|
202
|
-
name: 'Too Many Requests',
|
|
203
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429',
|
|
204
|
-
},
|
|
205
|
-
431: {
|
|
206
|
-
name: 'Request Header Fields Too Large',
|
|
207
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/431',
|
|
208
|
-
},
|
|
209
|
-
451: {
|
|
210
|
-
name: 'Unavailable For Legal Reasons',
|
|
211
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/451',
|
|
212
|
-
},
|
|
213
|
-
500: {
|
|
214
|
-
name: 'Internal Server Error',
|
|
215
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500',
|
|
216
|
-
},
|
|
217
|
-
501: {
|
|
218
|
-
name: 'Not Implemented',
|
|
219
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501',
|
|
220
|
-
},
|
|
221
|
-
502: {
|
|
222
|
-
name: 'Bad Gateway',
|
|
223
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502',
|
|
224
|
-
},
|
|
225
|
-
503: {
|
|
226
|
-
name: 'Service Unavailable',
|
|
227
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503',
|
|
228
|
-
},
|
|
229
|
-
504: {
|
|
230
|
-
name: 'Gateway Timeout',
|
|
231
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504',
|
|
232
|
-
},
|
|
233
|
-
505: {
|
|
234
|
-
name: 'HTTP Version Not Supported',
|
|
235
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/505',
|
|
236
|
-
},
|
|
237
|
-
506: {
|
|
238
|
-
name: 'Variant Also Negotiates',
|
|
239
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/506',
|
|
240
|
-
},
|
|
241
|
-
507: {
|
|
242
|
-
name: 'Insufficient Storage',
|
|
243
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/507',
|
|
244
|
-
},
|
|
245
|
-
508: {
|
|
246
|
-
name: 'Loop Detected',
|
|
247
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/508',
|
|
248
|
-
},
|
|
249
|
-
510: {
|
|
250
|
-
name: 'Not Extended',
|
|
251
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/510',
|
|
252
|
-
},
|
|
253
|
-
511: {
|
|
254
|
-
name: 'Network Authentication Required',
|
|
255
|
-
url: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/511',
|
|
256
|
-
},
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export default httpStatusCodes
|
package/src/fixtures/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { concatenateUrlAndPath } from './'
|
|
4
|
-
|
|
5
|
-
describe('concatenateUrlAndPath', () => {
|
|
6
|
-
it('trims a slash from the URL', async () => {
|
|
7
|
-
expect(concatenateUrlAndPath('http://127.0.0.1/', 'foobar')).toBe(
|
|
8
|
-
'http://127.0.0.1/foobar',
|
|
9
|
-
)
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('adds a slash between url and path', async () => {
|
|
13
|
-
expect(concatenateUrlAndPath('http://127.0.0.1', 'foobar')).toBe(
|
|
14
|
-
'http://127.0.0.1/foobar',
|
|
15
|
-
)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('trims a slash from the path', async () => {
|
|
19
|
-
expect(concatenateUrlAndPath('http://127.0.0.1', '/foobar')).toBe(
|
|
20
|
-
'http://127.0.0.1/foobar',
|
|
21
|
-
)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('works without a path', async () => {
|
|
25
|
-
expect(concatenateUrlAndPath('http://127.0.0.1')).toBe('http://127.0.0.1')
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Make sure the URL and path are concatenated correctly.
|
|
3
|
-
*/
|
|
4
|
-
export const concatenateUrlAndPath = (url: string, path?: string) => {
|
|
5
|
-
if (typeof path !== 'string' || !path.length) {
|
|
6
|
-
return url
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const urlWithSlash = url.endsWith('/') ? url : `${url}/`
|
|
10
|
-
const pathWithoutSlash = path.startsWith('/') ? path.slice(1) : path
|
|
11
|
-
|
|
12
|
-
return [urlWithSlash, pathWithoutSlash].join('')
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ClientRequestConfig } from '../types'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate a new placeholder request
|
|
5
|
-
*/
|
|
6
|
-
export const createPlaceholderRequest = (): ClientRequestConfig => ({
|
|
7
|
-
name: '',
|
|
8
|
-
url: '',
|
|
9
|
-
type: 'GET',
|
|
10
|
-
path: '',
|
|
11
|
-
parameters: [],
|
|
12
|
-
headers: [],
|
|
13
|
-
query: [],
|
|
14
|
-
body: '',
|
|
15
|
-
formData: [],
|
|
16
|
-
})
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { BaseParameter, Parameters } from '../types'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate parameters for the request from the parameters in the swagger file
|
|
5
|
-
*/
|
|
6
|
-
export function generateParameters(parameters: Parameters[]) {
|
|
7
|
-
const params: BaseParameter[] = []
|
|
8
|
-
parameters.forEach((parameter: Parameters) => {
|
|
9
|
-
const param: BaseParameter = {
|
|
10
|
-
name: parameter.name,
|
|
11
|
-
value: '',
|
|
12
|
-
customClass: parameter.required ? 'required-parameter' : '',
|
|
13
|
-
}
|
|
14
|
-
param.value = ''
|
|
15
|
-
params.push(param)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return params
|
|
19
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type ParamMap } from '../hooks/useOperation'
|
|
2
|
-
import type { ClientRequestConfig, Operation, Server } from '../types'
|
|
3
|
-
import { generateParameters } from './generateParameters'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate parameters for the request
|
|
7
|
-
*/
|
|
8
|
-
export function generateRequest(
|
|
9
|
-
operation: Operation,
|
|
10
|
-
parameterMap: ParamMap,
|
|
11
|
-
server: Server,
|
|
12
|
-
): ClientRequestConfig {
|
|
13
|
-
const item = {
|
|
14
|
-
id: operation.operationId,
|
|
15
|
-
name: operation.name,
|
|
16
|
-
type: operation.httpVerb,
|
|
17
|
-
path: operation.path,
|
|
18
|
-
parameters: generateParameters(parameterMap.path),
|
|
19
|
-
query: generateParameters(parameterMap.query),
|
|
20
|
-
headers: generateParameters(parameterMap.header),
|
|
21
|
-
url: server.url,
|
|
22
|
-
body: '',
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return item
|
|
26
|
-
}
|
package/src/helpers/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { concatenateUrlAndPath } from './concatenateUrlAndPath'
|
|
2
|
-
export { createPlaceholderRequest } from './createPlaceholderRequest'
|
|
3
|
-
export { generateParameters } from './generateParameters'
|
|
4
|
-
export { generateRequest } from './generateRequest'
|
|
5
|
-
export { mapFromArray } from './mapFromArray'
|
|
6
|
-
export { normalizePath } from './normalizePath'
|
|
7
|
-
export { normalizeRequestMethod } from './normalizeRequestMethod'
|
|
8
|
-
export { normalizeUrl } from './normalizeUrl'
|
|
9
|
-
export { replaceVariables } from './replaceVariables'
|
|
10
|
-
export { sendRequest } from './sendRequest'
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A utility function to convert an array of objects to an object of objects.
|
|
3
|
-
*/
|
|
4
|
-
export function mapFromArray<
|
|
5
|
-
T extends Record<string, unknown>,
|
|
6
|
-
K extends keyof T & string,
|
|
7
|
-
V extends keyof T & string,
|
|
8
|
-
>(arr: T[], key: K, valueKey: V) {
|
|
9
|
-
const obj: Record<string, T[V]> = {}
|
|
10
|
-
|
|
11
|
-
arr.forEach((entry) => {
|
|
12
|
-
obj[entry[key] as string] = entry[valueKey]
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
return obj
|
|
16
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { normalizePath } from './'
|
|
4
|
-
|
|
5
|
-
describe('normalizePath', () => {
|
|
6
|
-
it('keeps a path as is', async () => {
|
|
7
|
-
expect(normalizePath('foobar')).toBe('foobar')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('removes slash', async () => {
|
|
11
|
-
expect(normalizePath('/foobar')).toBe('foobar')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('trims whitespace', async () => {
|
|
15
|
-
expect(normalizePath('foobar ')).toBe('foobar')
|
|
16
|
-
})
|
|
17
|
-
})
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes a path by removing leading slashes.
|
|
3
|
-
*/
|
|
4
|
-
export const normalizePath = (path?: string) => {
|
|
5
|
-
if (typeof path !== 'string') {
|
|
6
|
-
return ''
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
let normalizedPath = path.trim()
|
|
10
|
-
|
|
11
|
-
if (normalizedPath.startsWith('/')) {
|
|
12
|
-
normalizedPath = normalizedPath.slice(1)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return normalizedPath
|
|
16
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { normalizeRequestMethod } from './'
|
|
4
|
-
|
|
5
|
-
describe('normalizeRequestMethod', () => {
|
|
6
|
-
it('returns a valid request method', async () => {
|
|
7
|
-
expect(normalizeRequestMethod('GET')).toBe('GET')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('makes method uppercase', async () => {
|
|
11
|
-
expect(normalizeRequestMethod('get')).toBe('GET')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('return uppercase POST', async () => {
|
|
15
|
-
expect(normalizeRequestMethod('post')).toBe('POST')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('trims whitespace', async () => {
|
|
19
|
-
expect(normalizeRequestMethod('post ')).toBe('POST')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('uses GET as the default', async () => {
|
|
23
|
-
expect(normalizeRequestMethod()).toBe('GET')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('ignores invalid request methods', async () => {
|
|
27
|
-
expect(normalizeRequestMethod('fantasy')).toBe('GET')
|
|
28
|
-
})
|
|
29
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const defaultRequestMethod = 'GET'
|
|
2
|
-
|
|
3
|
-
const validRequestMethods = [
|
|
4
|
-
'GET',
|
|
5
|
-
'POST',
|
|
6
|
-
'PUT',
|
|
7
|
-
'HEAD',
|
|
8
|
-
'DELETE',
|
|
9
|
-
'PATCH',
|
|
10
|
-
'OPTIONS',
|
|
11
|
-
'CONNECT',
|
|
12
|
-
'TRACE',
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get a normalized request method (e.g. GET, POST, etc.)
|
|
17
|
-
*/
|
|
18
|
-
export const normalizeRequestMethod = (method?: string) => {
|
|
19
|
-
// Make sure it’s a string
|
|
20
|
-
if (typeof method !== 'string') {
|
|
21
|
-
console.warn(
|
|
22
|
-
`[sendRequest] Request method is not a string. Using ${defaultRequestMethod} as the default.`,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
return defaultRequestMethod
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Normalize the string
|
|
29
|
-
const normalizedMethod = method.trim().toUpperCase()
|
|
30
|
-
|
|
31
|
-
// Make sure it’s a valid request method
|
|
32
|
-
const isValidRequestMethod = validRequestMethods.includes(normalizedMethod)
|
|
33
|
-
|
|
34
|
-
if (!isValidRequestMethod) {
|
|
35
|
-
console.warn(
|
|
36
|
-
`[sendRequest] ${method} is not a valid request method. Using ${defaultRequestMethod} as the default.`,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
return defaultRequestMethod
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return normalizedMethod
|
|
43
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { normalizeUrl } from './'
|
|
4
|
-
|
|
5
|
-
describe('normalizeUrl', () => {
|
|
6
|
-
it('keeps URLs as is', async () => {
|
|
7
|
-
expect(normalizeUrl('http://127.0.0.1')).toBe('http://127.0.0.1')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('keeps slashes', async () => {
|
|
11
|
-
expect(normalizeUrl('http://127.0.0.1/')).toBe('http://127.0.0.1/')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('makes URLs lowercase', async () => {
|
|
15
|
-
expect(normalizeUrl('http://EXAMPLE.COM')).toBe('http://example.com')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('adds http://', async () => {
|
|
19
|
-
expect(normalizeUrl('example.com')).toBe('http://example.com')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('trims whitespace', async () => {
|
|
23
|
-
expect(normalizeUrl('http://example.com ')).toBe('http://example.com')
|
|
24
|
-
})
|
|
25
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes a URL by trimming it and adding http:// as the default prefix.
|
|
3
|
-
*/
|
|
4
|
-
export const normalizeUrl = (url?: string) => {
|
|
5
|
-
if (typeof url !== 'string') {
|
|
6
|
-
console.warn(
|
|
7
|
-
`[sendRequest] URL is not a string. Using an empty string as the default.`,
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
return ''
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let normalizedUrl = url.trim().toLowerCase()
|
|
14
|
-
|
|
15
|
-
if (!normalizedUrl.startsWith('http')) {
|
|
16
|
-
console.warn(
|
|
17
|
-
`[sendRequest] URL does not start with http. Adding http:// as the default prefix.`,
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
normalizedUrl = `http://${normalizedUrl}`
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return normalizedUrl
|
|
24
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { replaceVariables } from './'
|
|
4
|
-
|
|
5
|
-
describe('replaceVariables', () => {
|
|
6
|
-
it('replaces variables', async () => {
|
|
7
|
-
expect(
|
|
8
|
-
replaceVariables('http://{baseUrl}/foobar', {
|
|
9
|
-
baseUrl: 'example.com',
|
|
10
|
-
}),
|
|
11
|
-
).toBe('http://example.com/foobar')
|
|
12
|
-
})
|
|
13
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Replaces variables in a url with the values provided.
|
|
3
|
-
*/
|
|
4
|
-
export const replaceVariables = (
|
|
5
|
-
url: string,
|
|
6
|
-
variables: Record<string, string | number>,
|
|
7
|
-
) => {
|
|
8
|
-
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
9
|
-
return acc.replace(`{${key}}`, value.toString())
|
|
10
|
-
}, url)
|
|
11
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { createEchoServer } from '@scalar/echo-server'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { sendRequest } from './sendRequest'
|
|
5
|
-
|
|
6
|
-
const createEchoServerOnAnyPort = (): { address: string; port: number } => {
|
|
7
|
-
const { listen } = createEchoServer()
|
|
8
|
-
const instance = listen(0)
|
|
9
|
-
|
|
10
|
-
return instance.address()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('sendRequest', () => {
|
|
14
|
-
it('sends requests', async () => {
|
|
15
|
-
const { port } = createEchoServerOnAnyPort()
|
|
16
|
-
|
|
17
|
-
const request = {
|
|
18
|
-
url: `http://127.0.0.1:${port}`,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const result = await sendRequest(request)
|
|
22
|
-
|
|
23
|
-
expect(result?.response).toContain({
|
|
24
|
-
method: 'GET',
|
|
25
|
-
path: '/',
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('replaces variables', async () => {
|
|
30
|
-
const { port } = createEchoServerOnAnyPort()
|
|
31
|
-
|
|
32
|
-
const request = {
|
|
33
|
-
url: `http://127.0.0.1:${port}`,
|
|
34
|
-
path: '{path}',
|
|
35
|
-
parameters: [
|
|
36
|
-
{
|
|
37
|
-
name: 'path',
|
|
38
|
-
value: 'example',
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const result = await sendRequest(request)
|
|
44
|
-
|
|
45
|
-
expect(result?.response).toContain({
|
|
46
|
-
method: 'GET',
|
|
47
|
-
path: '/example',
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
})
|