@scalar/api-client 0.4.0 → 0.5.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/README.md +62 -0
- package/dist/components/ApiClient/Request/RequestBody.vue.d.ts.map +1 -1
- package/dist/components/ApiClient/Request/RequestHeaders.vue.d.ts +0 -2
- package/dist/components/ApiClient/Request/RequestHeaders.vue.d.ts.map +1 -1
- package/dist/components/ApiClient/Request/RequestQuery.vue.d.ts +0 -2
- package/dist/components/ApiClient/Request/RequestQuery.vue.d.ts.map +1 -1
- package/dist/components/ApiClient/Request/RequestVariables.vue.d.ts +2 -4
- package/dist/components/ApiClient/Request/RequestVariables.vue.d.ts.map +1 -1
- package/dist/components/ApiClient/Response/ResponseBody.vue.d.ts.map +1 -1
- package/dist/helpers/concatenateUrlAndPath.d.ts +5 -0
- package/dist/helpers/concatenateUrlAndPath.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +6 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/normalizePath.d.ts +5 -0
- package/dist/helpers/normalizePath.d.ts.map +1 -0
- package/dist/helpers/normalizeRequestMethod.d.ts +5 -0
- package/dist/helpers/normalizeRequestMethod.d.ts.map +1 -0
- package/dist/helpers/normalizeUrl.d.ts +5 -0
- package/dist/helpers/normalizeUrl.d.ts.map +1 -0
- package/dist/helpers/replaceVariables.d.ts +5 -0
- package/dist/helpers/replaceVariables.d.ts.map +1 -0
- package/dist/helpers/sendRequest.d.ts +2 -2
- package/dist/helpers/sendRequest.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +374 -4181
- package/dist/stores/apiClientRequestStore.d.ts +8 -8
- package/dist/types.d.ts +7 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +26 -21
- package/src/components/ApiClient/AddressBar.vue +1 -1
- package/src/components/ApiClient/Request/Request.vue +1 -1
- package/src/components/ApiClient/Request/RequestBody.vue +3 -2
- package/src/components/ApiClient/Request/RequestHeaders.vue +2 -2
- package/src/components/ApiClient/Request/RequestQuery.vue +2 -2
- package/src/components/ApiClient/Request/RequestVariables.vue +3 -3
- package/src/components/ApiClient/Response/ResponseBody.vue +3 -2
- package/src/helpers/concatenateUrlAndPath.test.ts +27 -0
- package/src/helpers/concatenateUrlAndPath.ts +13 -0
- package/src/helpers/index.ts +6 -1
- package/src/helpers/normalizePath.test.ts +17 -0
- package/src/helpers/normalizePath.ts +16 -0
- package/src/helpers/normalizeRequestMethod.test.ts +29 -0
- package/src/helpers/normalizeRequestMethod.ts +43 -0
- package/src/helpers/normalizeUrl.test.ts +25 -0
- package/src/helpers/normalizeUrl.ts +24 -0
- package/src/helpers/replaceVariables.test.ts +13 -0
- package/src/helpers/replaceVariables.ts +11 -0
- package/src/helpers/sendRequest.test.ts +50 -0
- package/src/helpers/sendRequest.ts +43 -32
- package/src/index.ts +0 -1
- package/src/types.ts +9 -5
- package/dist/components/CodeMirror/CodeMirror.vue.d.ts +0 -56
- package/dist/components/CodeMirror/CodeMirror.vue.d.ts.map +0 -1
- package/dist/components/CodeMirror/extensions/variables.d.ts +0 -6
- package/dist/components/CodeMirror/extensions/variables.d.ts.map +0 -1
- package/dist/components/CodeMirror/index.d.ts +0 -2
- package/dist/components/CodeMirror/index.d.ts.map +0 -1
- package/src/components/CodeMirror/CodeMirror.vue +0 -232
- package/src/components/CodeMirror/extensions/variables.ts +0 -41
- package/src/components/CodeMirror/index.ts +0 -1
- package/src/hooks/useOperation.test.ts +0 -7
|
@@ -32,26 +32,26 @@ export declare const useApiClientRequestStore: () => {
|
|
|
32
32
|
readOnly: import("vue").Ref<boolean>;
|
|
33
33
|
activeRequest: {
|
|
34
34
|
id?: string | undefined;
|
|
35
|
-
name
|
|
35
|
+
name?: string | undefined;
|
|
36
36
|
url: string;
|
|
37
37
|
type: string;
|
|
38
38
|
path: string;
|
|
39
|
-
parameters
|
|
39
|
+
parameters?: {
|
|
40
40
|
name: string;
|
|
41
41
|
value: string | number;
|
|
42
42
|
customClass?: string | undefined;
|
|
43
|
-
}[];
|
|
44
|
-
query
|
|
43
|
+
}[] | undefined;
|
|
44
|
+
query?: {
|
|
45
45
|
name: string;
|
|
46
46
|
value: string | number;
|
|
47
47
|
customClass?: string | undefined;
|
|
48
|
-
}[];
|
|
49
|
-
headers
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
headers?: {
|
|
50
50
|
name: string;
|
|
51
51
|
value: string | number;
|
|
52
52
|
customClass?: string | undefined;
|
|
53
|
-
}[];
|
|
54
|
-
body
|
|
53
|
+
}[] | undefined;
|
|
54
|
+
body?: string | undefined;
|
|
55
55
|
formData?: {
|
|
56
56
|
name: string;
|
|
57
57
|
value: string | number;
|
package/dist/types.d.ts
CHANGED
|
@@ -41,20 +41,21 @@ export type FormDataItem = BaseParameter;
|
|
|
41
41
|
/** Complete request state for a client request */
|
|
42
42
|
export type ClientRequestConfig = {
|
|
43
43
|
id?: string;
|
|
44
|
-
name
|
|
44
|
+
name?: string;
|
|
45
45
|
url: string;
|
|
46
46
|
/** HTTP Request Method */
|
|
47
47
|
type: string;
|
|
48
48
|
/** Request path */
|
|
49
49
|
path: string;
|
|
50
|
+
/** TODO: Rename to variables? */
|
|
50
51
|
/** Path parameters */
|
|
51
|
-
parameters
|
|
52
|
+
parameters?: BaseParameter[];
|
|
52
53
|
/** Query parameters */
|
|
53
|
-
query
|
|
54
|
+
query?: Query[];
|
|
54
55
|
/** Request headers */
|
|
55
|
-
headers
|
|
56
|
+
headers?: Header[];
|
|
56
57
|
/** Content type matched body */
|
|
57
|
-
body
|
|
58
|
+
body?: string;
|
|
58
59
|
/** Optional form data body */
|
|
59
60
|
formData?: FormDataItem[];
|
|
60
61
|
};
|
|
@@ -76,6 +77,7 @@ export type ClientResponse = {
|
|
|
76
77
|
data: string;
|
|
77
78
|
duration: number;
|
|
78
79
|
};
|
|
80
|
+
export type SendRequestConfig = Partial<ClientRequestConfig> & Required<Pick<ClientRequestConfig, 'url'>>;
|
|
79
81
|
export type RequestResult = {
|
|
80
82
|
request: ClientRequestConfig;
|
|
81
83
|
response: ClientResponse;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE1E,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,GAAG,M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AA;CACZ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalar/api-client",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"description": "the open source API testing client",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"api",
|
|
6
|
+
"client",
|
|
7
|
+
"testing",
|
|
8
|
+
"rest",
|
|
9
|
+
"graphql",
|
|
10
|
+
"postman alternative"
|
|
11
|
+
],
|
|
12
|
+
"version": "0.5.1",
|
|
13
|
+
"author": "Scalar (https://github.com/scalar)",
|
|
14
|
+
"homepage": "https://github.com/scalar/scalar",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/scalar/scalar.git",
|
|
18
|
+
"directory": "packages/api-client"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/scalar/scalar/issues/new"
|
|
22
|
+
},
|
|
5
23
|
"license": "MIT",
|
|
6
24
|
"engines": {
|
|
7
25
|
"node": ">=18"
|
|
@@ -19,30 +37,17 @@
|
|
|
19
37
|
},
|
|
20
38
|
"types": "dist/index.d.ts",
|
|
21
39
|
"dependencies": {
|
|
22
|
-
"@codemirror/lang-java": "^6.0.1",
|
|
23
|
-
"@codemirror/lang-javascript": "6.1.9",
|
|
24
|
-
"@codemirror/lang-json": "6.0.1",
|
|
25
|
-
"@codemirror/lang-python": "6.1.3",
|
|
26
|
-
"@codemirror/language": "6.8.0",
|
|
27
|
-
"@codemirror/legacy-modes": "6.3.3",
|
|
28
|
-
"@codemirror/state": "6.2.1",
|
|
29
|
-
"@codemirror/view": "6.16.0",
|
|
30
40
|
"@headlessui/vue": "1.7.14",
|
|
31
|
-
"@lezer/highlight": "1.1.6",
|
|
32
|
-
"@uiw/codemirror-theme-duotone": "4.21.3",
|
|
33
|
-
"@uiw/codemirror-themes": "4.21.3",
|
|
34
41
|
"@vueuse/core": "10.1.2",
|
|
35
42
|
"axios": "1.4.0",
|
|
36
|
-
"codemirror": "6.0.1",
|
|
37
43
|
"javascript-time-ago": "2.5.9",
|
|
38
44
|
"nanoid": "4.0.2",
|
|
39
|
-
"nunjucks": "3.2.3",
|
|
40
45
|
"pretty-bytes": "6.1.0",
|
|
41
46
|
"pretty-ms": "8.0.0",
|
|
42
47
|
"tippy.js": "6.3.7",
|
|
43
|
-
"@scalar/default-theme": "0.2.
|
|
44
|
-
"@scalar/use-
|
|
45
|
-
"@scalar/use-
|
|
48
|
+
"@scalar/default-theme": "0.2.1",
|
|
49
|
+
"@scalar/use-keyboard-event": "0.4.1",
|
|
50
|
+
"@scalar/use-codemirror": "0.5.0"
|
|
46
51
|
},
|
|
47
52
|
"devDependencies": {
|
|
48
53
|
"@vitejs/plugin-vue": "4.2.3",
|
|
@@ -50,11 +55,11 @@
|
|
|
50
55
|
"vite": "4.4.8",
|
|
51
56
|
"vite-plugin-css-injected-by-js": "^3.3.0",
|
|
52
57
|
"vitest": "0.34.1",
|
|
53
|
-
"vue-tsc": "1.8.8"
|
|
58
|
+
"vue-tsc": "1.8.8",
|
|
59
|
+
"@scalar/echo-server": "0.4.1"
|
|
54
60
|
},
|
|
55
61
|
"peerDependencies": {
|
|
56
|
-
"vue": "3.3.4"
|
|
57
|
-
"@types/nunjucks": "3.2.3"
|
|
62
|
+
"vue": "3.3.4"
|
|
58
63
|
},
|
|
59
64
|
"scripts": {
|
|
60
65
|
"build": "vite build && pnpm types:build && tsc-alias -p tsconfig.build.json",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { CodeMirror } from '@scalar/use-codemirror'
|
|
2
3
|
import { useKeyboardEvent } from '@scalar/use-keyboard-event'
|
|
3
4
|
import { useMediaQuery } from '@vueuse/core'
|
|
4
5
|
import TimeAgo from 'javascript-time-ago'
|
|
@@ -7,7 +8,6 @@ import { computed, ref } from 'vue'
|
|
|
7
8
|
|
|
8
9
|
import { sendRequest } from '../../helpers/sendRequest'
|
|
9
10
|
import { useApiClientRequestStore } from '../../stores/apiClientRequestStore'
|
|
10
|
-
import { CodeMirror } from '../CodeMirror'
|
|
11
11
|
import FlowModal, { useModalState } from '../FlowModal.vue'
|
|
12
12
|
import RequestHistory from './RequestHistory.vue'
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ const { activeRequest, readOnly } = useApiClientRequestStore()
|
|
|
25
25
|
</div>
|
|
26
26
|
<div>
|
|
27
27
|
<RequestAuth />
|
|
28
|
-
<RequestVariables :
|
|
28
|
+
<RequestVariables :variables="activeRequest.parameters" />
|
|
29
29
|
<RequestQuery :queries="activeRequest.query" />
|
|
30
30
|
<RequestHeaders :headers="activeRequest.headers" />
|
|
31
31
|
<RequestBody
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { CodeMirror } from '@scalar/use-codemirror'
|
|
3
|
+
|
|
2
4
|
import { useApiClientRequestStore } from '../../../stores/apiClientRequestStore'
|
|
3
|
-
import { CodeMirror } from '../../CodeMirror'
|
|
4
5
|
import { CollapsibleSection } from '../../CollapsibleSection'
|
|
5
6
|
import { Grid } from '../../Grid'
|
|
6
7
|
|
|
@@ -33,7 +34,7 @@ const updateActiveRequest = (value: string) => {
|
|
|
33
34
|
v-else
|
|
34
35
|
:content="activeRequest.body"
|
|
35
36
|
:languages="['json']"
|
|
36
|
-
|
|
37
|
+
lineNumbers
|
|
37
38
|
@change="updateActiveRequest" />
|
|
38
39
|
</CollapsibleSection>
|
|
39
40
|
</template>
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { CollapsibleSection } from '../../CollapsibleSection'
|
|
3
3
|
import { Grid } from '../../Grid'
|
|
4
4
|
|
|
5
|
-
defineProps<{ headers
|
|
5
|
+
defineProps<{ headers?: any[] }>()
|
|
6
6
|
</script>
|
|
7
7
|
<template>
|
|
8
8
|
<CollapsibleSection title="Headers">
|
|
9
|
-
<template v-if="headers.length === 0">
|
|
9
|
+
<template v-if="!headers || headers.length === 0">
|
|
10
10
|
<div class="scalar-api-client__empty-state">No Headers</div>
|
|
11
11
|
</template>
|
|
12
12
|
<template v-else>
|
|
@@ -3,11 +3,11 @@ import type { Query } from '../../../types'
|
|
|
3
3
|
import { CollapsibleSection } from '../../CollapsibleSection'
|
|
4
4
|
import { Grid } from '../../Grid'
|
|
5
5
|
|
|
6
|
-
defineProps<{ queries
|
|
6
|
+
defineProps<{ queries?: Query[] }>()
|
|
7
7
|
</script>
|
|
8
8
|
<template>
|
|
9
9
|
<CollapsibleSection title="Query Parameters">
|
|
10
|
-
<template v-if="queries.length === 0">
|
|
10
|
+
<template v-if="!queries || queries.length === 0">
|
|
11
11
|
<div class="scalar-api-client__empty-state">No Query Parameters</div>
|
|
12
12
|
</template>
|
|
13
13
|
<template v-else>
|
|
@@ -3,15 +3,15 @@ import type { BaseParameter } from '../../../types'
|
|
|
3
3
|
import { CollapsibleSection } from '../../CollapsibleSection'
|
|
4
4
|
import { Grid } from '../../Grid'
|
|
5
5
|
|
|
6
|
-
defineProps<{
|
|
6
|
+
defineProps<{ variables?: BaseParameter[] }>()
|
|
7
7
|
</script>
|
|
8
8
|
<template>
|
|
9
9
|
<CollapsibleSection title="Variables">
|
|
10
|
-
<template v-if="
|
|
10
|
+
<template v-if="!variables || variables.length === 0">
|
|
11
11
|
<div class="scalar-api-client__empty-state">No variables</div>
|
|
12
12
|
</template>
|
|
13
13
|
<template v-else>
|
|
14
|
-
<Grid :items="
|
|
14
|
+
<Grid :items="variables" />
|
|
15
15
|
<!-- @addAnother="addQuery"
|
|
16
16
|
@deleteItem="deleteQuery"
|
|
17
17
|
@toggleDescription="toggleDescription"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { CodeMirror } from '
|
|
2
|
+
import { CodeMirror } from '@scalar/use-codemirror'
|
|
3
|
+
|
|
3
4
|
import { CollapsibleSection } from '../../CollapsibleSection'
|
|
4
5
|
|
|
5
6
|
withDefaults(defineProps<{ active: boolean; data: any }>(), {
|
|
@@ -13,7 +14,7 @@ withDefaults(defineProps<{ active: boolean; data: any }>(), {
|
|
|
13
14
|
v-if="active"
|
|
14
15
|
:content="data"
|
|
15
16
|
:languages="['json']"
|
|
16
|
-
|
|
17
|
+
readOnly />
|
|
17
18
|
<div
|
|
18
19
|
v-else
|
|
19
20
|
class="scalar-api-client__empty-state">
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
package/src/helpers/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
export { concatenateUrlAndPath } from './concatenateUrlAndPath'
|
|
1
2
|
export { createPlaceholderRequest } from './createPlaceholderRequest'
|
|
2
|
-
export { generateRequest } from './generateRequest'
|
|
3
3
|
export { generateParameters } from './generateParameters'
|
|
4
|
+
export { generateRequest } from './generateRequest'
|
|
4
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'
|
|
5
10
|
export { sendRequest } from './sendRequest'
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
})
|