@scalar/api-client 0.5.1 → 0.5.2

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
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "graphql",
10
10
  "postman alternative"
11
11
  ],
12
- "version": "0.5.1",
12
+ "version": "0.5.2",
13
13
  "author": "Scalar (https://github.com/scalar)",
14
14
  "homepage": "https://github.com/scalar/scalar",
15
15
  "repository": {
@@ -26,13 +26,11 @@
26
26
  },
27
27
  "type": "module",
28
28
  "files": [
29
- "src",
30
29
  "dist"
31
30
  ],
32
31
  "main": "./dist/index.js",
33
32
  "module": "./dist/index.js",
34
33
  "exports": {
35
- "development": "./src/index.ts",
36
34
  "import": "./dist/index.js"
37
35
  },
38
36
  "types": "dist/index.d.ts",
@@ -46,17 +44,18 @@
46
44
  "pretty-ms": "8.0.0",
47
45
  "tippy.js": "6.3.7",
48
46
  "@scalar/default-theme": "0.2.1",
49
- "@scalar/use-keyboard-event": "0.4.1",
50
- "@scalar/use-codemirror": "0.5.0"
47
+ "@scalar/use-codemirror": "0.5.1",
48
+ "@scalar/use-keyboard-event": "0.4.2"
51
49
  },
52
50
  "devDependencies": {
53
51
  "@vitejs/plugin-vue": "4.2.3",
52
+ "vitest": "0.34.1",
53
+ "@vitest/coverage-v8": "^0.34.4",
54
54
  "tsc-alias": "1.8.6",
55
55
  "vite": "4.4.8",
56
56
  "vite-plugin-css-injected-by-js": "^3.3.0",
57
- "vitest": "0.34.1",
58
57
  "vue-tsc": "1.8.8",
59
- "@scalar/echo-server": "0.4.1"
58
+ "@scalar/echo-server": "0.4.2"
60
59
  },
61
60
  "peerDependencies": {
62
61
  "vue": "3.3.4"
@@ -1,462 +0,0 @@
1
- <script setup lang="ts">
2
- import { CodeMirror } from '@scalar/use-codemirror'
3
- import { useKeyboardEvent } from '@scalar/use-keyboard-event'
4
- import { useMediaQuery } from '@vueuse/core'
5
- import TimeAgo from 'javascript-time-ago'
6
- import en from 'javascript-time-ago/locale/en'
7
- import { computed, ref } from 'vue'
8
-
9
- import { sendRequest } from '../../helpers/sendRequest'
10
- import { useApiClientRequestStore } from '../../stores/apiClientRequestStore'
11
- import FlowModal, { useModalState } from '../FlowModal.vue'
12
- import RequestHistory from './RequestHistory.vue'
13
-
14
- const props = defineProps<{
15
- proxyUrl: string
16
- }>()
17
-
18
- const emits = defineEmits<{
19
- (event: 'onSend'): void
20
- }>()
21
-
22
- TimeAgo.addLocale(en)
23
- const timeAgo = new TimeAgo('en-US')
24
-
25
- const showHistory = ref(false)
26
- const loading = ref(false)
27
-
28
- const {
29
- activeRequest,
30
- addRequestToHistory,
31
- requestHistory,
32
- requestHistoryOrder,
33
- readOnly,
34
- setActiveRequest,
35
- } = useApiClientRequestStore()
36
-
37
- const historyModal = useModalState()
38
-
39
- // https://petstore3.swagger.io/api/v3
40
- const url = computed(() => activeRequest.url)
41
- // GET, POST …
42
- const requestType = computed(() => activeRequest.type)
43
- // /pet/{petId}
44
- const requestPath = computed(() => activeRequest.path)
45
- // true|false
46
- const isSmallScreen = useMediaQuery('(max-width: 820px)')
47
-
48
- // https://petstore3.swagger.io/api/v3/pet/{petId} -> /api/v3/pet/{petId}
49
- function getShortUrl(longURL: string): string {
50
- try {
51
- const urlObject = new URL(longURL)
52
- const { pathname } = urlObject
53
-
54
- return pathname
55
- } catch {
56
- return longURL
57
- }
58
- }
59
-
60
- const formattedUrl = computed(() => {
61
- const fullUrl = `${url.value}${requestPath.value}`
62
-
63
- return isSmallScreen.value ? `...${getShortUrl(fullUrl)}` : fullUrl
64
- })
65
-
66
- async function send() {
67
- loading.value = true
68
- emits('onSend')
69
- const result = await sendRequest(activeRequest, props.proxyUrl)
70
-
71
- if (result) {
72
- addRequestToHistory(result)
73
- }
74
- loading.value = false
75
- }
76
-
77
- const lastRequestTimestamp = computed(() => {
78
- const lastRequestKey = requestHistoryOrder.value[0]
79
- return requestHistory[lastRequestKey]
80
- ? timeAgo.format(requestHistory[lastRequestKey].sentTime)
81
- : 'History'
82
- })
83
-
84
- useKeyboardEvent({
85
- keyList: ['enter'],
86
- withCtrlCmd: true,
87
- handler: send,
88
- })
89
-
90
- const onChange = (value: string) => {
91
- if (activeRequest.url + activeRequest.path === value) {
92
- return
93
- }
94
-
95
- setActiveRequest({ ...activeRequest, url: value })
96
- }
97
- </script>
98
-
99
- <template>
100
- <div
101
- class="scalar-api-client__address-bar"
102
- :class="{ 'scalar-api-client__address-bar__on': showHistory }">
103
- <div class="scalar-api-client__url-form">
104
- <div class="scalar-api-client__field">
105
- <div class="scalar-api-client__request-type">
106
- <i :class="requestType.toLowerCase()" />
107
- <span>{{ requestType }}</span>
108
- </div>
109
- <CodeMirror
110
- class="scalar-api-client__url-input"
111
- :content="formattedUrl"
112
- :disableEnter="true"
113
- :readOnly="readOnly"
114
- :withVariables="true"
115
- :withoutTheme="true"
116
- @change="onChange" />
117
- </div>
118
- <button
119
- class="scalar-api-client__send-request-button"
120
- :class="[
121
- { 'scalar-api-client__send-request-button--loading': loading },
122
- ]"
123
- type="submit"
124
- @click="send">
125
- <svg
126
- fill="none"
127
- height="48"
128
- viewBox="0 0 14 14"
129
- width="48"
130
- xmlns="http://www.w3.org/2000/svg">
131
- <g id="send-email--mail-send-email-paper-airplane">
132
- <path
133
- id="Subtract"
134
- clip-rule="evenodd"
135
- d="M11.8215 0.0977331C12.1097 -0.0075178 12.422 -0.0287134 12.7219 0.0367172C13.0248 0.102803 13.3024 0.254481 13.5216 0.473719C13.7409 0.692957 13.8926 0.970537 13.9586 1.27346C14.0241 1.57338 14.0029 1.88566 13.8976 2.17389L10.3236 12.8859L10.3234 12.8866C10.2363 13.15 10.083 13.3867 9.87813 13.5739C9.67383 13.7606 9.42512 13.8917 9.15575 13.9549C8.88633 14.0206 8.60444 14.015 8.33777 13.9388C8.07134 13.8627 7.82929 13.7187 7.63532 13.5209L5.71798 11.6123L3.70392 12.6538C3.54687 12.735 3.3586 12.7272 3.20877 12.6333C3.05895 12.5395 2.96984 12.3734 2.97443 12.1967L3.057 9.01294L10.102 3.89553C10.3812 3.69267 10.4432 3.30182 10.2403 3.02255C10.0375 2.74327 9.64662 2.68133 9.36734 2.88419L2.20286 8.0884L0.473156 6.35869L0.473098 6.35864L0.472971 6.35851C0.285648 6.17132 0.147746 5.94054 0.0716498 5.68688C-0.00390565 5.43503 -0.016181 5.16847 0.0358684 4.91079C0.087985 4.62928 0.213827 4.36658 0.400607 4.14951C0.588668 3.93095 0.831681 3.76658 1.10453 3.67339L1.1079 3.67224L1.1079 3.67225L11.8215 0.0977331Z"
136
- fill="currentColor"
137
- fill-rule="evenodd"></path>
138
- </g>
139
- </svg>
140
- <span>Send Request</span>
141
- </button>
142
- </div>
143
- <div
144
- class="scalar-api-client__address-bar__close"
145
- @click="showHistory = false" />
146
- <div class="scalar-api-client__address-bar__content">
147
- <FlowModal
148
- :state="historyModal"
149
- title="Request History"
150
- variant="large">
151
- <RequestHistory
152
- :showHistory="showHistory"
153
- @toggle="showHistory = !showHistory" />
154
- </FlowModal>
155
- </div>
156
-
157
- <div
158
- v-if="requestHistoryOrder.length"
159
- class="scalar-api-client__history">
160
- <div
161
- class="scalar-api-client__history-toggle"
162
- @click="historyModal.show()">
163
- <svg
164
- fill="none"
165
- height="48"
166
- viewBox="0 0 14 14"
167
- width="48"
168
- xmlns="http://www.w3.org/2000/svg">
169
- <g id="rewind-clock--back-return-clock-timer-countdown">
170
- <path
171
- id="Vector 1561 (Stroke)"
172
- clip-rule="evenodd"
173
- d="M6.99999 2.75C7.4142 2.75 7.74999 3.08579 7.74999 3.5V7.5C7.74999 7.76345 7.61177 8.00758 7.38586 8.14312L4.88586 9.64312C4.53068 9.85623 4.06998 9.74106 3.85687 9.38587C3.64376 9.03069 3.75893 8.56999 4.11412 8.35688L6.24999 7.07536V3.5C6.24999 3.08579 6.58578 2.75 6.99999 2.75Z"
174
- fill="currentColor"
175
- fill-rule="evenodd"></path>
176
- <path
177
- id="Union"
178
- clip-rule="evenodd"
179
- d="M12.5 7C12.5 3.96243 10.0376 1.5 7 1.5C5.24916 1.5 3.68853 2.31796 2.68066 3.59456L3.64645 4.56034C3.96143 4.87533 3.73835 5.4139 3.29289 5.4139H0.5C0.223857 5.4139 0 5.19004 0 4.9139V2.121C0 1.67555 0.53857 1.45247 0.853553 1.76745L1.61439 2.52829C2.89781 0.984301 4.83356 0 7 0C10.866 0 14 3.13401 14 7C14 10.866 10.866 14 7 14C3.68902 14 0.916591 11.702 0.187329 8.61473C0.0921059 8.21161 0.341704 7.80762 0.744824 7.7124C1.14794 7.61717 1.55193 7.86677 1.64715 8.26989C2.22013 10.6955 4.40025 12.5 7 12.5C10.0376 12.5 12.5 10.0376 12.5 7Z"
180
- fill="currentColor"
181
- fill-rule="evenodd"></path>
182
- </g>
183
- </svg>
184
- <span>{{ lastRequestTimestamp }}</span>
185
- </div>
186
- </div>
187
- </div>
188
- </template>
189
- <style>
190
- .scalar-api-client__address-bar {
191
- width: 100%;
192
- padding: 12px 12px 10px 12px;
193
- display: flex;
194
- align-items: center;
195
- position: relative;
196
- background: var(--theme-background-1);
197
- }
198
- .scalar-api-client__url-form {
199
- display: flex;
200
- width: 100%;
201
- align-items: stretch;
202
- border-radius: var(--theme-radius-lg);
203
- }
204
- .scalar-api-client__field {
205
- border: 1px solid var(--theme-border-color);
206
- border-right: 0;
207
- border-radius: var(--theme-radius-lg) 0 0 var(--theme-radius-lg);
208
- display: flex;
209
- align-items: stretch;
210
- width: 100%;
211
- }
212
- .scalar-api-client__address-bar-data {
213
- width: 100%;
214
- }
215
- .scalar-api-client__address-bar-data-meta {
216
- display: flex;
217
- margin-top: 5px;
218
- }
219
- .scalar-api-client__request-type {
220
- display: flex;
221
- align-items: center;
222
- background: var(--theme-background-2);
223
- color: var(--theme-color-disabled);
224
- appearance: none;
225
- -webkit-appearance: none;
226
- padding: 0 12px;
227
- border-right: 1px solid var(--theme-border-color);
228
- border-radius: var(--theme-radius-lg) 0 0 var(--theme-radius-lg);
229
- position: relative;
230
- }
231
- .scalar-api-client__request-type span {
232
- font-family: var(--theme-font-code);
233
- font-size: 500;
234
- font-size: 12px;
235
- text-transform: uppercase;
236
- }
237
- .scalar-api-client__request-type svg {
238
- margin-left: 6px;
239
- width: 8px;
240
- }
241
- .scalar-api-client__request-type i {
242
- width: 10px;
243
- height: 10px;
244
- border-radius: 50%;
245
- margin-right: 6px;
246
- text-align: center;
247
- line-height: 18px;
248
- font-style: normal;
249
- flex-shrink: 0;
250
- display: inline-block;
251
- color: var(--theme-color-disabled);
252
- background: var(--scalar-api-client-color);
253
- }
254
- .meta-request-break {
255
- margin: 0 5px;
256
- }
257
- .scalar-api-client__history {
258
- appearance: none;
259
- -webkit-appearance: none;
260
- background: transparent;
261
- color: var(--theme-color-2);
262
- display: flex;
263
- align-items: center;
264
- border-radius: var(--theme-radius-lg);
265
- height: 100%;
266
- }
267
- .scalar-api-client__send-request-button[type='submit'] {
268
- font-size: var(--theme-mini);
269
- letter-spacing: 0.25px;
270
- line-height: 30px;
271
- font-weight: var(--theme-semibold);
272
- color: white;
273
- border: none;
274
- white-space: nowrap;
275
- padding: 0 10px;
276
- text-transform: uppercase;
277
- cursor: pointer;
278
- outline: none;
279
- border-radius: 0 var(--theme-radius-lg) var(--theme-radius-lg) 0;
280
- background: var(--scalar-api-client-color);
281
- /** #087f5b */
282
- display: flex;
283
- align-items: center;
284
- }
285
- .scalar-api-client__send-request-button svg {
286
- width: 12px;
287
- height: 12px;
288
- margin-right: 6px;
289
- }
290
- .scalar-api-client__send-request-button--loading {
291
- font-size: 0;
292
- display: flex;
293
- align-items: center;
294
- justify-content: center;
295
- min-width: 127px;
296
- }
297
- .scalar-api-client__send-request-button--loading svg {
298
- display: none;
299
- }
300
- .scalar-api-client__send-request-button--loading:before {
301
- content: '';
302
- border: 1px solid rgba(0, 0, 0, 0.1);
303
- border-top: 1px solid white;
304
- animation: urlloader 0.45s linear infinite;
305
- background: transparent;
306
- width: 14px;
307
- height: 14px;
308
- margin-left: 0;
309
- margin-right: 9px;
310
- border-radius: 50%;
311
- }
312
- .scalar-api-client__send-request-button--loading:after {
313
- content: 'Loading';
314
- font-size: 12px;
315
- }
316
- @keyframes urlloader {
317
- 0% {
318
- transform: rotate(0deg);
319
- }
320
- to {
321
- transform: rotate(1turn);
322
- }
323
- }
324
- .scalar-api-client__history-toggle {
325
- padding: 0 9px;
326
- line-height: 30px;
327
- color: var(--theme-color-disabled);
328
- font-size: var(--theme-mini);
329
- letter-spacing: 0.125px;
330
- font-weight: var(--theme-semibold);
331
- text-transform: uppercase;
332
- height: 100%;
333
- display: flex;
334
- align-items: center;
335
- cursor: pointer;
336
- white-space: nowrap;
337
- border: 1px solid var(--theme-border-color);
338
- margin-left: 12px;
339
- border-radius: var(--theme-radius-lg);
340
- }
341
- .scalar-api-client__history-toggle:hover {
342
- background: var(--theme-background-2);
343
- }
344
- .scalar-api-client__history-toggle svg {
345
- height: 13px;
346
- width: 13px;
347
- margin-right: 6px;
348
- color: var(--theme-color-disabled);
349
- }
350
- .scalar-api-client__address-bar-close {
351
- fill: var(--theme-color-disabled);
352
- margin-left: 12px;
353
- height: 24px;
354
- }
355
- .scalar-api-client__address-bar-close:hover {
356
- cursor: pointer;
357
- fill: var(--theme-color-1);
358
- }
359
- .scalar-api-client__address-bar__content {
360
- width: 640px;
361
- height: 100%;
362
- background: var(--theme-background-1);
363
- position: fixed;
364
- top: 0;
365
- right: 0;
366
- z-index: 1000;
367
- transform: translate3d(640px, 0, 0);
368
- opacity: 0;
369
- transition: transform 0.5s cubic-bezier(0.77, 0, 0.175, 1),
370
- opacity 0.01s ease-in-out 0.5s;
371
- pointer-events: none;
372
- }
373
- .scalar-api-client__address-bar-content-item {
374
- height: 100vh;
375
- max-height: 100vh;
376
- overflow: auto;
377
- }
378
- .scalar-api-client__address-bar__on {
379
- z-index: 100000;
380
- }
381
- .scalar-api-client__address-bar__on .scalar-api-client__address-bar__content {
382
- transform: translate3d(0, 0, 0);
383
- opacity: 1;
384
- pointer-events: all;
385
- transition: transform 0.5s cubic-bezier(0.77, 0, 0.175, 1);
386
- }
387
- .scalar-api-client__address-bar__on .scalar-api-client__address-bar__close {
388
- opacity: 1;
389
- pointer-events: all;
390
- cursor: pointer;
391
- }
392
- .scalar-api-client__address-bar .navtable-item__active {
393
- background: var(--theme-background-2);
394
- cursor: default;
395
- }
396
- .scalar-api-client__address-bar .navtable-item__active .radio:before {
397
- display: none;
398
- }
399
- .navigation-back {
400
- stroke: var(--theme-color-2);
401
- cursor: pointer;
402
- }
403
- .navigation-back:hover {
404
- stroke: var(--theme-color-1);
405
- }
406
- .scalar-api-client__address-bar__close {
407
- width: 100%;
408
- height: 100%;
409
- position: fixed;
410
- top: 0;
411
- left: 0;
412
- /* background: rgba(0,0,0,.55);
413
- */
414
- pointer-events: none;
415
- opacity: 0;
416
- transition: all 0.1s ease-in-out;
417
- z-index: 1000;
418
- }
419
- .navtable-item-request span {
420
- padding: 8px 9px 8px 0;
421
- border: none;
422
- outline: none;
423
- font-size: 12px;
424
- color: var(--theme-color-1);
425
- width: 100%;
426
- display: block;
427
- overflow: hidden;
428
- white-space: nowrap;
429
- text-overflow: ellipsis;
430
- }
431
- .navtable-item-request span em {
432
- text-transform: uppercase;
433
- font-style: normal;
434
- font-family: var(--theme-font-code);
435
- font-size: 11px;
436
- margin-right: 6px;
437
- font-weight: var(--theme-bold);
438
- color: var(--theme-color-disabled);
439
- }
440
- .navtable-item-time {
441
- font-size: 12px;
442
- color: var(--theme-color-1);
443
- text-transform: capitalize;
444
- padding: 0 9px;
445
- }
446
- @media screen and (max-width: 720px) {
447
- .scalar-api-client__history-toggle span,
448
- .scalar-api-client__send-request-button span {
449
- display: none;
450
- }
451
- .scalar-api-client__history-toggle svg,
452
- .scalar-api-client__send-request-button svg {
453
- margin-right: 0;
454
- }
455
- .scalar-api-client__history-toggle,
456
- .scalar-api-client__send-request-button {
457
- height: 31.5px;
458
- width: 31.5px;
459
- }
460
- }
461
- </style>
462
- ../../../../use-keyboard-event/src