create-packer 1.25.32 → 1.26.0
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 +4 -4
- package/template/docusaurus/package.json +1 -1
- package/template/lib/react/package.json +4 -4
- package/template/lib/ts/package.json +3 -3
- package/template/nest/package.json +3 -3
- package/template/web-app/next/package.json +1 -1
- package/template/web-app/react/package.json +4 -4
- package/template/web-app/react-webpack/package.json +4 -4
- package/template/web-app/solid/package.json +1 -1
- package/template/web-app/svelte/package.json +3 -3
- package/template/web-app/vue/package.json +4 -4
- package/template/web-extension/.env +1 -1
- package/template/web-extension/.env.development +1 -1
- package/template/web-extension/package.json +5 -3
- package/template/web-extension/shared/service/request.ts +4 -83
- package/template/web-extension/shared/service/tools.ts +126 -0
- package/template/web-extension/shared/service/types.ts +22 -0
- package/template/web-extension/tsconfig.json +1 -0
- package/template/web-extension/popup/popup.spec.tsx +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-packer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": "https://github.com/kevily/create-packer",
|
|
6
6
|
"author": "1k <bug_zero@163.com>",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"@types/fs-extra": "9.0.12",
|
|
28
28
|
"@types/inquirer": "7.3.3",
|
|
29
29
|
"@types/node": "16.4.7",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "
|
|
31
|
-
"@typescript-eslint/parser": "
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
31
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
32
32
|
"commitizen": "4.3.0",
|
|
33
33
|
"eslint": "7.32.0",
|
|
34
34
|
"rimraf": "3.0.2",
|
|
35
|
-
"typescript": "5.
|
|
35
|
+
"typescript": "5.3.3"
|
|
36
36
|
},
|
|
37
37
|
"config": {
|
|
38
38
|
"commitizen": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build-storybook": "storybook build"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
|
|
13
|
+
"dist"
|
|
14
14
|
],
|
|
15
15
|
"keywords": [],
|
|
16
16
|
"author": "",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@storybook/testing-library": "0.0.14-next.2",
|
|
30
30
|
"@types/react": "18.2.14",
|
|
31
31
|
"@types/react-dom": "18.2.6",
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "
|
|
33
|
-
"@typescript-eslint/parser": "
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
33
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
34
34
|
"eslint": "8.43.0",
|
|
35
35
|
"eslint-import-resolver-typescript": "3.5.5",
|
|
36
36
|
"eslint-plugin-import": "2.27.5",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"storybook": "7.1.0",
|
|
46
46
|
"stylelint": "15.9.0",
|
|
47
47
|
"stylelint-config-standard": "33.0.0",
|
|
48
|
-
"typescript": "5.
|
|
48
|
+
"typescript": "5.3.3",
|
|
49
49
|
"vite-plugin-svgr": "3.2.0"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "
|
|
18
|
-
"@typescript-eslint/parser": "
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
18
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
19
19
|
"eslint": "8.43.0",
|
|
20
20
|
"eslint-import-resolver-typescript": "3.5.5",
|
|
21
21
|
"eslint-plugin-import": "2.27.5",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"prettier": "2.8.8",
|
|
24
24
|
"stylelint": "15.9.0",
|
|
25
25
|
"stylelint-config-standard": "33.0.0",
|
|
26
|
-
"typescript": "5.
|
|
26
|
+
"typescript": "5.3.3",
|
|
27
27
|
"vitest": "0.34.2"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"@types/jest": "29.4.0",
|
|
42
42
|
"@types/node": "18.13.0",
|
|
43
43
|
"@types/supertest": "2.0.12",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "
|
|
45
|
-
"@typescript-eslint/parser": "
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
45
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
46
46
|
"commitizen": "4.3.0",
|
|
47
47
|
"cz-adapter-eslint": "0.3.0",
|
|
48
48
|
"eslint": "8.34.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ts-loader": "9.4.2",
|
|
58
58
|
"ts-node": "10.9.1",
|
|
59
59
|
"tsconfig-paths": "4.1.2",
|
|
60
|
-
"typescript": "
|
|
60
|
+
"typescript": "5.3.3"
|
|
61
61
|
},
|
|
62
62
|
"jest": {
|
|
63
63
|
"moduleFileExtensions": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"commit": "git add . && npm run cz"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"1k-types": "1.
|
|
21
|
+
"1k-types": "1.1.2",
|
|
22
22
|
"axios": "1.3.6",
|
|
23
23
|
"define-zustand": "2.0.1",
|
|
24
24
|
"immer": "10.0.1",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@types/qs": "6.9.7",
|
|
41
41
|
"@types/react": "18.0.38",
|
|
42
42
|
"@types/react-dom": "18.0.11",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "
|
|
44
|
-
"@typescript-eslint/parser": "
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
44
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
45
45
|
"@vitejs/plugin-react": "4.2.0",
|
|
46
46
|
"autoprefixer": "10.4.14",
|
|
47
47
|
"commitizen": "4.3.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"stylelint": "15.7.0",
|
|
64
64
|
"stylelint-config-standard": "33.0.0",
|
|
65
65
|
"tailwindcss": "3.3.1",
|
|
66
|
-
"typescript": "5.
|
|
66
|
+
"typescript": "5.3.3",
|
|
67
67
|
"vite": "4.3.1",
|
|
68
68
|
"vite-plugin-checker": "0.6.2",
|
|
69
69
|
"vite-plugin-mock-dev-server": "1.2.1",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"commit": "git add . && npm run cz"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"1k-types": "1.
|
|
22
|
+
"1k-types": "1.1.2",
|
|
23
23
|
"axios": "1.5.0",
|
|
24
24
|
"define-zustand": "2.0.1",
|
|
25
25
|
"immer": "10.0.2",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@types/react-redux": "7.1.26",
|
|
45
45
|
"@types/react-router-config": "5.0.7",
|
|
46
46
|
"@types/react-router-dom": "5.3.3",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
48
|
-
"@typescript-eslint/parser": "6.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
48
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
49
49
|
"autoprefixer": "10.4.15",
|
|
50
50
|
"commitizen": "4.3.0",
|
|
51
51
|
"css-loader": "6.8.1",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"stylelint": "15.10.3",
|
|
75
75
|
"stylelint-config-standard": "34.0.0",
|
|
76
76
|
"stylelint-webpack-plugin": "4.1.1",
|
|
77
|
-
"typescript": "5.
|
|
77
|
+
"typescript": "5.3.3",
|
|
78
78
|
"webpack": "5.88.2",
|
|
79
79
|
"webpack-bundle-analyzer": "4.9.1",
|
|
80
80
|
"webpack-cli": "5.1.4",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@sveltejs/adapter-auto": "2.1.0",
|
|
26
26
|
"@sveltejs/kit": "1.25.0",
|
|
27
27
|
"@types/lodash-es": "4.17.9",
|
|
28
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
29
|
-
"@typescript-eslint/parser": "6.
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
29
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
30
30
|
"commitizen": "4.3.0",
|
|
31
31
|
"cssnano": "6.0.1",
|
|
32
32
|
"eslint": "8.50.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"rollup-plugin-visualizer": "5.9.2",
|
|
42
42
|
"svelte-check": "3.5.2",
|
|
43
43
|
"tslib": "2.6.2",
|
|
44
|
-
"typescript": "5.
|
|
44
|
+
"typescript": "5.3.3",
|
|
45
45
|
"vite": "4.4.9"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"commit": "git add . && npm run cz"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"1k-types": "1.
|
|
20
|
+
"1k-types": "1.1.2",
|
|
21
21
|
"axios": "1.3.6",
|
|
22
22
|
"lodash-es": "4.17.21",
|
|
23
23
|
"pinia": "2.0.35",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@commitlint/cz-commitlint": "17.5.0",
|
|
31
31
|
"@types/lodash-es": "4.17.7",
|
|
32
32
|
"@types/mockjs": "1.0.7",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "
|
|
34
|
-
"@typescript-eslint/parser": "
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
34
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
35
35
|
"@vitejs/plugin-vue": "4.2.3",
|
|
36
36
|
"@vitejs/plugin-vue-jsx": "3.0.1",
|
|
37
37
|
"autoprefixer": "10.4.14",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"stylelint": "15.7.0",
|
|
54
54
|
"stylelint-config-standard": "33.0.0",
|
|
55
55
|
"tailwindcss": "3.3.1",
|
|
56
|
-
"typescript": "5.
|
|
56
|
+
"typescript": "5.3.3",
|
|
57
57
|
"vite": "4.3.8",
|
|
58
58
|
"vite-plugin-checker": "0.6.1",
|
|
59
59
|
"vite-plugin-mock-dev-server": "1.2.1",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
VITE_API_HOST
|
|
1
|
+
VITE_API_HOST=/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
VITE_API_HOST
|
|
1
|
+
VITE_API_HOST=/
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"define-zustand": "2.0.1",
|
|
21
21
|
"immer": "10.0.1",
|
|
22
|
+
"ky": "1.1.3",
|
|
22
23
|
"lodash-es": "4.17.21",
|
|
23
24
|
"qs": "6.11.2",
|
|
24
25
|
"react": "18.2.0",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"zustand": "4.4.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
30
|
+
"1k-types": "1.1.2",
|
|
29
31
|
"@commitlint/cli": "17.6.1",
|
|
30
32
|
"@commitlint/config-conventional": "17.6.1",
|
|
31
33
|
"@commitlint/cz-commitlint": "17.5.0",
|
|
@@ -36,8 +38,8 @@
|
|
|
36
38
|
"@types/qs": "6.9.7",
|
|
37
39
|
"@types/react": "18.0.38",
|
|
38
40
|
"@types/react-dom": "18.0.11",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "
|
|
40
|
-
"@typescript-eslint/parser": "
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "6.17.0",
|
|
42
|
+
"@typescript-eslint/parser": "6.17.0",
|
|
41
43
|
"@vitejs/plugin-react": "4.0.0",
|
|
42
44
|
"autoprefixer": "10.4.14",
|
|
43
45
|
"commitizen": "4.3.0",
|
|
@@ -57,7 +59,7 @@
|
|
|
57
59
|
"stylelint": "15.7.0",
|
|
58
60
|
"stylelint-config-standard": "33.0.0",
|
|
59
61
|
"tailwindcss": "3.3.1",
|
|
60
|
-
"typescript": "5.
|
|
62
|
+
"typescript": "5.3.3",
|
|
61
63
|
"vite": "4.3.1",
|
|
62
64
|
"vite-plugin-checker": "0.6.1"
|
|
63
65
|
},
|
|
@@ -1,84 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { stringify } from 'qs'
|
|
1
|
+
import { createService } from './tools'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
baseURL: string
|
|
8
|
-
headers?: {
|
|
9
|
-
'Content-Type'?: string
|
|
10
|
-
[key: string]: string | undefined
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
type onErrorType = (e: Response) => void
|
|
14
|
-
|
|
15
|
-
async function resFormatter(response: Response) {
|
|
16
|
-
const contentType = response.headers.get('Content-Type')
|
|
17
|
-
|
|
18
|
-
if (contentType?.startsWith('application/json')) {
|
|
19
|
-
return await response.json()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (contentType?.startsWith('text/html')) {
|
|
23
|
-
return await response.text()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return response
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class Request {
|
|
30
|
-
config: configType
|
|
31
|
-
interceptors: {
|
|
32
|
-
error: onErrorType[]
|
|
33
|
-
}
|
|
34
|
-
constructor(config: configType) {
|
|
35
|
-
this.config = {
|
|
36
|
-
...config,
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type': 'application/json',
|
|
39
|
-
...config.headers
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
this.interceptors = {
|
|
43
|
-
error: []
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
onError(callback: onErrorType) {
|
|
47
|
-
this.interceptors.error.push(callback)
|
|
48
|
-
}
|
|
49
|
-
async request(url: string, config?: fetchConfigType) {
|
|
50
|
-
try {
|
|
51
|
-
const response = await fetch(this.config.baseURL + url, {
|
|
52
|
-
headers: this.config.headers as never,
|
|
53
|
-
redirect: 'manual',
|
|
54
|
-
...config
|
|
55
|
-
})
|
|
56
|
-
if (response.status !== 200) {
|
|
57
|
-
const errMsg = `服务器错误状态:${response.status}`
|
|
58
|
-
forEach(this.interceptors.error, onError => {
|
|
59
|
-
onError(response)
|
|
60
|
-
})
|
|
61
|
-
throw new Error(errMsg)
|
|
62
|
-
}
|
|
63
|
-
return resFormatter(response)
|
|
64
|
-
} catch (error: any) {
|
|
65
|
-
throw new Error(error.message)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
get(url: string, data?: Record<string, any> | any[]) {
|
|
69
|
-
const query = size(data) > 0 ? `?${stringify(data)}` : ''
|
|
70
|
-
return this.request(url + query, {
|
|
71
|
-
method: 'GET'
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
post(url: string, body?: any) {
|
|
75
|
-
return this.request(url, {
|
|
76
|
-
method: 'POST',
|
|
77
|
-
body: JSON.stringify(body)
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function create(config: configType) {
|
|
83
|
-
return new Request(config)
|
|
84
|
-
}
|
|
3
|
+
export const request = createService({
|
|
4
|
+
prefixUrl: import.meta.env.VITE_API_HOST
|
|
5
|
+
})
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import ky, { Hooks, KyInstance, Options } from 'ky'
|
|
2
|
+
import { Input } from 'ky/distribution/types/options'
|
|
3
|
+
import { assign, includes, isArray, isObject, omit } from 'lodash-es'
|
|
4
|
+
import { parse, stringify } from 'qs'
|
|
5
|
+
import { ArrayValues } from '1k-types'
|
|
6
|
+
import { configType, requestOptionsType, serviceHooksType } from './types'
|
|
7
|
+
|
|
8
|
+
function createServiceHooks() {
|
|
9
|
+
const serviceHooks: serviceHooksType = {
|
|
10
|
+
beforeError: [],
|
|
11
|
+
beforeRequest: []
|
|
12
|
+
}
|
|
13
|
+
const kyHooks: Hooks = {
|
|
14
|
+
beforeError: [
|
|
15
|
+
async error => {
|
|
16
|
+
await foreachHooks('beforeError', error)
|
|
17
|
+
return error
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
beforeRequest: [
|
|
21
|
+
async req => {
|
|
22
|
+
// eslint-disable-next-line prefer-const
|
|
23
|
+
let [url, searchParams] = req.url.split('?')
|
|
24
|
+
const reqBody =
|
|
25
|
+
!includes(['GET', 'HEAD'], req.method) && req.body ? await req.json() : void 0
|
|
26
|
+
const parsedSearchParams = parse(searchParams)
|
|
27
|
+
const reqConfig = {
|
|
28
|
+
searchParams: parsedSearchParams,
|
|
29
|
+
body: reqBody,
|
|
30
|
+
headers: req.headers,
|
|
31
|
+
method: req.method
|
|
32
|
+
}
|
|
33
|
+
await foreachHooks('beforeRequest', reqConfig)
|
|
34
|
+
url = url + stringify(reqConfig.searchParams, { addQueryPrefix: true })
|
|
35
|
+
return new Request(url, {
|
|
36
|
+
...omit(req, 'url'),
|
|
37
|
+
headers: reqConfig.headers,
|
|
38
|
+
body: reqBody ? JSON.stringify(reqConfig.body) : void 0
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
function addHooks<K extends keyof serviceHooksType>(
|
|
44
|
+
key: K,
|
|
45
|
+
callback: ArrayValues<serviceHooksType[K]>
|
|
46
|
+
) {
|
|
47
|
+
serviceHooks[key].push(callback as any)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function foreachHooks<K extends keyof serviceHooksType>(
|
|
51
|
+
name: K,
|
|
52
|
+
arg: Parameters<ArrayValues<serviceHooksType[K]>>[0]
|
|
53
|
+
) {
|
|
54
|
+
for (let i = 0; i < serviceHooks[name].length; i++) {
|
|
55
|
+
const fn = serviceHooks[name][i]
|
|
56
|
+
await fn(arg as never)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
kyHooks,
|
|
62
|
+
serviceHooks,
|
|
63
|
+
addHooks
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createRequestActions(request: KyInstance) {
|
|
68
|
+
function creator(method: Required<Options>['method']) {
|
|
69
|
+
return function <DATA = any>(url: Input, option?: requestOptionsType): Promise<DATA> {
|
|
70
|
+
return request[method](url, omit(option, 'responseType'))[
|
|
71
|
+
option?.responseType || 'json'
|
|
72
|
+
]()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
get: creator('get'),
|
|
78
|
+
post: creator('post'),
|
|
79
|
+
put: creator('put'),
|
|
80
|
+
patch: creator('patch'),
|
|
81
|
+
head: creator('head'),
|
|
82
|
+
delete: creator('delete')
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export type requestActionsType = ReturnType<typeof createRequestActions>
|
|
86
|
+
|
|
87
|
+
export function createService(config: configType) {
|
|
88
|
+
const { kyHooks, addHooks } = createServiceHooks()
|
|
89
|
+
const globalParams: configType['globalParams'] = assign({}, config.globalParams)
|
|
90
|
+
const globalSearchParams: configType['globalSearchParams'] = assign(
|
|
91
|
+
{},
|
|
92
|
+
config.globalSearchParams
|
|
93
|
+
)
|
|
94
|
+
const request = ky.create({
|
|
95
|
+
prefixUrl: config.prefixUrl,
|
|
96
|
+
headers: config.headers,
|
|
97
|
+
hooks: kyHooks
|
|
98
|
+
})
|
|
99
|
+
const requestActions = createRequestActions(request)
|
|
100
|
+
|
|
101
|
+
function setGlobalParams(params: configType['globalParams']) {
|
|
102
|
+
assign(globalParams, params)
|
|
103
|
+
}
|
|
104
|
+
function setGlobalSearchParams(params: configType['globalSearchParams']) {
|
|
105
|
+
assign(globalSearchParams, params)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 初始化
|
|
109
|
+
// ------------------------------------------------------------------------
|
|
110
|
+
addHooks('beforeRequest', async req => {
|
|
111
|
+
const { searchParams, body } = req
|
|
112
|
+
req.searchParams = { ...globalSearchParams, ...searchParams }
|
|
113
|
+
|
|
114
|
+
if (!isArray(body) && isObject(body)) {
|
|
115
|
+
req.body = { ...globalParams, ...body }
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
instance: request,
|
|
121
|
+
...requestActions,
|
|
122
|
+
addHooks,
|
|
123
|
+
setGlobalParams,
|
|
124
|
+
setGlobalSearchParams
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Options, HTTPError } from 'ky'
|
|
2
|
+
import { Nullable } from '1k-types'
|
|
3
|
+
|
|
4
|
+
export interface configType extends Pick<Options, 'prefixUrl' | 'headers'> {
|
|
5
|
+
globalParams?: Record<string, any>
|
|
6
|
+
globalSearchParams?: Record<string, any>
|
|
7
|
+
}
|
|
8
|
+
export interface requestOptionsType extends Options {
|
|
9
|
+
responseType?: 'json' | 'text' | 'blob'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type beforeRequestType = (req: {
|
|
13
|
+
searchParams: Record<string, any>
|
|
14
|
+
body: Nullable<Record<string, any>>
|
|
15
|
+
headers: Headers
|
|
16
|
+
method: Options['method']
|
|
17
|
+
}) => Promise<void> | void
|
|
18
|
+
export type beforeErrorType = (error: HTTPError) => Promise<void> | void
|
|
19
|
+
export interface serviceHooksType {
|
|
20
|
+
beforeError: beforeErrorType[]
|
|
21
|
+
beforeRequest: beforeRequestType[]
|
|
22
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react'
|
|
2
|
-
import Popup from './popup.container'
|
|
3
|
-
|
|
4
|
-
describe('HelloWorld', () => {
|
|
5
|
-
it('should renders a msg', () => {
|
|
6
|
-
// arrange
|
|
7
|
-
render(<Popup />)
|
|
8
|
-
|
|
9
|
-
// act
|
|
10
|
-
const title = screen.getByTestId('title')
|
|
11
|
-
|
|
12
|
-
// assert
|
|
13
|
-
expect(title).toHaveTextContent(/Hello React!/i)
|
|
14
|
-
})
|
|
15
|
-
})
|