jordy 0.14.7 → 0.14.8
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/{esm5 → esm6}/adaptive-render/AdaptiveRender.js +3 -4
- package/{esm5 → esm6}/adaptive-render/DeviceDetectContext.js +15 -17
- package/{esm5 → esm6}/adaptive-render/adaptive-render.type.js +0 -0
- package/{esm5 → esm6}/adaptive-render/device.type.js +0 -0
- package/{esm5 → esm6}/adaptive-render/index.js +0 -0
- package/{esm5 → esm6}/adaptive-render/withAdaptiveRender.js +7 -8
- package/{esm5 → esm6}/hooks/index.js +0 -0
- package/esm6/hooks/useDebounce.js +24 -0
- package/{esm5 → esm6}/hooks/useNavigate.js +6 -9
- package/esm6/hooks/useQueryParams.js +18 -0
- package/esm6/hooks/useThrottle.js +16 -0
- package/esm6/http-api/BaseInterceptorHttpApi.js +45 -0
- package/esm6/http-api/BasicHttpApi.js +126 -0
- package/esm6/http-api/BasicHttpUploadApi.js +47 -0
- package/esm6/http-api/ErrorParser.decorator.js +54 -0
- package/esm6/http-api/axios/AxiosHttpNetworkProvider.js +54 -0
- package/esm6/http-api/axios/AxiosHttpUploadProvider.js +45 -0
- package/{esm5 → esm6}/http-api/axios/axios.util.js +0 -0
- package/{esm5 → esm6}/http-api/axios/index.js +0 -0
- package/{esm5 → esm6}/http-api/axios/throwableAxiosErrorParser.js +2 -2
- package/{esm5 → esm6}/http-api/createHttpApi.factory.js +1 -4
- package/esm6/http-api/createHttpHeaderPipe.js +20 -0
- package/{esm5 → esm6}/http-api/createHttpUploadApi.factory.js +1 -4
- package/{esm5 → esm6}/http-api/httpHeaderOperator.js +5 -5
- package/{esm5 → esm6}/http-api/index.js +0 -0
- package/{esm5 → esm6}/http-api/network.type.js +0 -0
- package/{esm5 → esm6}/http-api/network.util.js +3 -5
- package/{esm5 → esm6}/index.js +0 -0
- package/esm6/proxies/cache.proxy.js +28 -0
- package/{esm5 → esm6}/proxies/index.js +0 -0
- package/esm6/queries/buildMutationCreator.js +75 -0
- package/esm6/queries/buildQueryCreator.js +112 -0
- package/{esm5 → esm6}/queries/index.js +0 -0
- package/{esm5 → esm6}/queries/useMakeDeps.js +3 -3
- package/{esm5 → esm6}/queries/utils/clearCacheByKeyword.js +10 -13
- package/{esm5 → esm6}/queries/utils/createCacheKey.js +4 -4
- package/{esm5 → esm6}/queries/utils/index.js +0 -0
- package/{esm5 → esm6}/route-system/index.js +0 -0
- package/{esm5 → esm6}/route-system/useRouteSystem.fixture.js +8 -11
- package/{esm5 → esm6}/route-system/useRouteSystem.js +15 -16
- package/{esm5 → esm6}/route-system/useRouteSystem.model.js +0 -0
- package/esm6/storage/CookieStorageAdapter.js +17 -0
- package/esm6/storage/ExpiableStorageAdapter.js +40 -0
- package/esm6/storage/MemorySimpleStorage.js +16 -0
- package/esm6/storage/RefreshableJWTProvider.js +87 -0
- package/esm6/storage/SimpleStorageAdapter.js +16 -0
- package/esm6/storage/StorageTokenProvider.js +14 -0
- package/{esm5 → esm6}/storage/cookie.js +11 -12
- package/{esm5 → esm6}/storage/createJWTProvider.factory.js +0 -0
- package/{esm5 → esm6}/storage/createStorage.factory.js +2 -5
- package/{esm5 → esm6}/storage/createTokenProvider.factory.js +0 -0
- package/{esm5 → esm6}/storage/index.js +0 -0
- package/esm6/storage/memoryStorage.js +30 -0
- package/{esm5 → esm6}/storage/storage.type.js +0 -0
- package/{esm5 → esm6}/storage/storage.util.js +1 -1
- package/esm6/types/HttpRestError.js +116 -0
- package/{esm5 → esm6}/types/component.type.js +0 -0
- package/{esm5 → esm6}/types/etc.type.js +0 -0
- package/{esm5 → esm6}/types/index.js +0 -0
- package/{esm5 → esm6}/types/marshalling.type.js +0 -0
- package/esm6/util/AsyncQueue.js +51 -0
- package/{esm5 → esm6}/util/collection.js +4 -5
- package/{esm5 → esm6}/util/envCheck.js +13 -13
- package/{esm5 → esm6}/util/etc.js +3 -3
- package/{esm5 → esm6}/util/filter.js +2 -4
- package/{esm5 → esm6}/util/format.js +1 -2
- package/{esm5 → esm6}/util/index.js +1 -1
- package/{esm5 → esm6}/util/josa.js +4 -4
- package/{esm5 → esm6}/util/json.js +0 -0
- package/esm6/util/libLoader.js +25 -0
- package/{esm5 → esm6}/util/path.js +1 -2
- package/esm6/util/queryString.js +58 -0
- package/{esm5 → esm6}/util/redux.js +1 -2
- package/{esm5 → esm6}/util/template.js +14 -14
- package/{esm5 → esm6}/util/typeCheck.js +0 -0
- package/{esm5 → esm6}/validate/fn.js +17 -19
- package/{esm5 → esm6}/validate/index.js +1 -1
- package/{esm5 → esm6}/validate/mergeValidates.js +4 -9
- package/{esm5 → esm6}/validate/validate.js +5 -5
- package/{esm5 → esm6}/validate/validate.type.js +0 -0
- package/{esm5 → esm6}/validate/validateSubUtils.js +14 -15
- package/package.json +7 -6
- package/esm5/hooks/useDebounce.js +0 -26
- package/esm5/hooks/useQueryParams.js +0 -20
- package/esm5/hooks/useThrottle.js +0 -18
- package/esm5/http-api/BaseInterceptorHttpApi.js +0 -53
- package/esm5/http-api/BasicHttpApi.js +0 -191
- package/esm5/http-api/BasicHttpUploadApi.js +0 -72
- package/esm5/http-api/ErrorParser.decorator.js +0 -88
- package/esm5/http-api/axios/AxiosHttpNetworkProvider.js +0 -57
- package/esm5/http-api/axios/AxiosHttpUploadProvider.js +0 -52
- package/esm5/http-api/createHttpHeaderPipe.js +0 -34
- package/esm5/proxies/cache.proxy.js +0 -40
- package/esm5/queries/buildMutationCreator.js +0 -87
- package/esm5/queries/buildQueryCreator.js +0 -124
- package/esm5/storage/CookieStorageAdapter.js +0 -20
- package/esm5/storage/ExpiableStorageAdapter.js +0 -47
- package/esm5/storage/MemorySimpleStorage.js +0 -18
- package/esm5/storage/RefreshableJWTProvider.js +0 -124
- package/esm5/storage/SimpleStorageAdapter.js +0 -18
- package/esm5/storage/StorageTokenProvider.js +0 -16
- package/esm5/storage/memoryStorage.js +0 -35
- package/esm5/types/HttpRestError.js +0 -138
- package/esm5/util/AsyncQueue.js +0 -53
- package/esm5/util/libLoader.js +0 -27
- package/esm5/util/queryString.js +0 -63
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIsMobile, useIsTablet } from './DeviceDetectContext';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var isTablet = useIsTablet();
|
|
3
|
+
export const AdaptiveRender = ({ mobile, notTablet, children, }) => {
|
|
4
|
+
const isMobile = useIsMobile();
|
|
5
|
+
const isTablet = useIsTablet();
|
|
7
6
|
if (notTablet && isTablet) {
|
|
8
7
|
return null;
|
|
9
8
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read } from "tslib";
|
|
2
1
|
import React, { createContext, useContext, useEffect, useMemo, useState, } from 'react';
|
|
3
2
|
import { isMobile as isMobileCheck, isNativeApp as isNativeAppCheck, isServer, isTablet as isTabletCheck, } from '../util/envCheck';
|
|
4
3
|
import { DeviceSizeEnum } from './device.type';
|
|
@@ -26,38 +25,37 @@ function getIsTablet() {
|
|
|
26
25
|
(window.innerWidth >= DeviceSizeEnum.TABLET &&
|
|
27
26
|
window.innerWidth <= DeviceSizeEnum.DESKTOP_SM - 1));
|
|
28
27
|
}
|
|
29
|
-
export
|
|
28
|
+
export const DeviceDetectContext = createContext([
|
|
30
29
|
getIsMobile(),
|
|
31
30
|
getIsTablet(),
|
|
32
31
|
isNativeAppCheck(),
|
|
33
32
|
]);
|
|
34
|
-
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
useEffect(function () {
|
|
33
|
+
const { Provider: DeviceDetectContextProvider } = DeviceDetectContext;
|
|
34
|
+
export const DeviceDetectProvider = ({ children, }) => {
|
|
35
|
+
const [isMobile, setIsMobile] = useState(getIsMobile());
|
|
36
|
+
const [isTablet, setIsTablet] = useState(getIsTablet());
|
|
37
|
+
const isNative = useMemo(isNativeAppCheck, []);
|
|
38
|
+
useEffect(() => {
|
|
41
39
|
if (isServer() || !window || typeof window.matchMedia !== 'function') {
|
|
42
40
|
return undefined;
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const mqMobile = window.matchMedia(`screen and (max-width: ${DeviceSizeEnum.TABLET - 1}px)`);
|
|
43
|
+
const mqTablet = window.matchMedia(`screen and (min-width: ${DeviceSizeEnum.TABLET}px) and (max-width: ${DeviceSizeEnum.DESKTOP_SM - 1}px)`);
|
|
44
|
+
const handleResizeForMobile = (e) => {
|
|
47
45
|
setIsMobile(e.matches);
|
|
48
46
|
};
|
|
49
|
-
|
|
47
|
+
const handleResizeForTablet = (e) => {
|
|
50
48
|
setIsTablet(e.matches);
|
|
51
49
|
};
|
|
52
50
|
mqMobile.addEventListener('change', handleResizeForMobile);
|
|
53
51
|
mqTablet.addEventListener('change', handleResizeForTablet);
|
|
54
|
-
return
|
|
52
|
+
return () => {
|
|
55
53
|
mqMobile.removeEventListener('change', handleResizeForMobile);
|
|
56
54
|
mqTablet.removeEventListener('change', handleResizeForTablet);
|
|
57
55
|
};
|
|
58
56
|
}, []);
|
|
59
57
|
return (React.createElement(DeviceDetectContextProvider, { value: [isMobile, isTablet, isNative] }, children));
|
|
60
58
|
};
|
|
61
|
-
export
|
|
62
|
-
export
|
|
63
|
-
export
|
|
59
|
+
export const useIsMobile = () => useContext(DeviceDetectContext)[0];
|
|
60
|
+
export const useIsTablet = () => useContext(DeviceDetectContext)[1];
|
|
61
|
+
export const useIsNative = () => useContext(DeviceDetectContext)[2];
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { useIsMobile, useIsTablet, useIsNative } from './DeviceDetectContext';
|
|
4
3
|
export function withAdaptiveRender(settings) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const FnComp = (props) => {
|
|
5
|
+
const isMobile = useIsMobile();
|
|
6
|
+
const isTablet = useIsTablet();
|
|
7
|
+
const isNative = useIsNative();
|
|
8
|
+
const { desktop: DesktopComp, tablet: TabletComp, mobile: MobileComp, native: NativeAppComp, } = settings;
|
|
9
|
+
let Comp;
|
|
11
10
|
if (isNative && NativeAppComp) {
|
|
12
11
|
Comp = NativeAppComp;
|
|
13
12
|
}
|
|
@@ -23,7 +22,7 @@ export function withAdaptiveRender(settings) {
|
|
|
23
22
|
else {
|
|
24
23
|
return null;
|
|
25
24
|
}
|
|
26
|
-
return React.createElement(Comp,
|
|
25
|
+
return React.createElement(Comp, Object.assign({}, props));
|
|
27
26
|
};
|
|
28
27
|
return FnComp;
|
|
29
28
|
}
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
export function useDebounce(fn, time = 300, deps = []) {
|
|
4
|
+
const timerRef = useRef(0);
|
|
5
|
+
const memoizeFn = useCallback(fn, deps);
|
|
6
|
+
useEffect(() => () => clearTimeout(timerRef.current), [memoizeFn]);
|
|
7
|
+
const callback = useMemo(() => {
|
|
8
|
+
const result = ((args) => {
|
|
9
|
+
if (timerRef.current) {
|
|
10
|
+
clearTimeout(timerRef.current);
|
|
11
|
+
}
|
|
12
|
+
timerRef.current = setTimeout(() => {
|
|
13
|
+
memoizeFn(args);
|
|
14
|
+
}, time);
|
|
15
|
+
});
|
|
16
|
+
result.stop = () => {
|
|
17
|
+
if (timerRef.current) {
|
|
18
|
+
clearTimeout(timerRef.current);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return result;
|
|
22
|
+
}, [memoizeFn]);
|
|
23
|
+
return callback;
|
|
24
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign, __read, __spreadArray } from "tslib";
|
|
2
1
|
import { useCallback } from 'react';
|
|
3
2
|
import { useNavigate as useRcNavigate, useSearchParams, } from 'react-router-dom';
|
|
4
3
|
import { isNullable, isObject, isUndefined } from '../util';
|
|
@@ -12,8 +11,7 @@ function isMergeQueries(option) {
|
|
|
12
11
|
return isUndefined(option) || (option && option['merge'] === true);
|
|
13
12
|
}
|
|
14
13
|
function refineQueries(queries) {
|
|
15
|
-
return Object.entries(queries).reduce(
|
|
16
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
14
|
+
return Object.entries(queries).reduce((acc, [key, value]) => {
|
|
17
15
|
if (!isNullable(value) && value !== '') {
|
|
18
16
|
acc[key] = value;
|
|
19
17
|
}
|
|
@@ -21,9 +19,9 @@ function refineQueries(queries) {
|
|
|
21
19
|
}, {});
|
|
22
20
|
}
|
|
23
21
|
export function useNavigate() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const [currentSearchParams, setSearchParams] = useSearchParams();
|
|
23
|
+
const navigate = useRcNavigate();
|
|
24
|
+
const navigation = useCallback((to, option) => {
|
|
27
25
|
if (typeof to === 'number') {
|
|
28
26
|
return navigate(to);
|
|
29
27
|
}
|
|
@@ -35,12 +33,11 @@ export function useNavigate() {
|
|
|
35
33
|
}
|
|
36
34
|
if (instanceOfSearchParams(to)) {
|
|
37
35
|
if (isMergeQueries(option)) {
|
|
38
|
-
|
|
39
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
36
|
+
const currentQueries = [...currentSearchParams].reduce((acc, [key, value]) => {
|
|
40
37
|
acc[key] = value;
|
|
41
38
|
return acc;
|
|
42
39
|
}, {});
|
|
43
|
-
|
|
40
|
+
const mergeQueries = Object.assign(Object.assign({}, currentQueries), to);
|
|
44
41
|
return setSearchParams(refineQueries(mergeQueries), option);
|
|
45
42
|
}
|
|
46
43
|
return setSearchParams(refineQueries(to), option);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useLocation, useParams } from 'react-router-dom';
|
|
3
|
+
import { qs } from '../util/queryString';
|
|
4
|
+
const defSelector = (params) => {
|
|
5
|
+
return params;
|
|
6
|
+
};
|
|
7
|
+
export function useQueryParams(selector = defSelector) {
|
|
8
|
+
const selConverter = useCallback(selector, []);
|
|
9
|
+
const location = useLocation();
|
|
10
|
+
const params = useParams();
|
|
11
|
+
const searchString = location.search;
|
|
12
|
+
const result = useMemo(() => {
|
|
13
|
+
const query = qs.parse(searchString);
|
|
14
|
+
const innerResult = Object.assign(Object.assign({}, query), params);
|
|
15
|
+
return selConverter(innerResult);
|
|
16
|
+
}, [searchString, params, selConverter]);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
export function useThrottle(fn, time = 300, deps = []) {
|
|
3
|
+
const timerRef = useRef(0);
|
|
4
|
+
const memoizeFn = useCallback(fn, deps);
|
|
5
|
+
useEffect(() => () => clearTimeout(timerRef.current), [memoizeFn]);
|
|
6
|
+
const callback = useCallback((args) => {
|
|
7
|
+
if (timerRef.current) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
timerRef.current = setTimeout(() => {
|
|
11
|
+
timerRef.current = 0;
|
|
12
|
+
}, time);
|
|
13
|
+
memoizeFn(args);
|
|
14
|
+
}, [memoizeFn]);
|
|
15
|
+
return callback;
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class BaseInterceptorHttpApi {
|
|
2
|
+
constructor(paramsSerializer) {
|
|
3
|
+
this.paramsSerializer = paramsSerializer;
|
|
4
|
+
this._interceptor = {};
|
|
5
|
+
this.mergeParams = (method, url, paramsOriginal) => {
|
|
6
|
+
if (this._interceptor.params) {
|
|
7
|
+
const paramsAdditional = this._interceptor.params(method, url, paramsOriginal);
|
|
8
|
+
if (paramsAdditional) {
|
|
9
|
+
if (paramsOriginal) {
|
|
10
|
+
return Object.assign(Object.assign({}, paramsOriginal), paramsAdditional);
|
|
11
|
+
}
|
|
12
|
+
return paramsAdditional;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return paramsOriginal;
|
|
16
|
+
};
|
|
17
|
+
this.mergeQueries = (method, url, paramsOriginal) => {
|
|
18
|
+
if (this._interceptor.params) {
|
|
19
|
+
const paramsAdditional = this._interceptor.params(method, url, paramsOriginal);
|
|
20
|
+
if (!paramsAdditional) {
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
return (url +
|
|
24
|
+
(url.includes('?') ? '&' : '?') +
|
|
25
|
+
this.paramsSerializer(paramsAdditional));
|
|
26
|
+
}
|
|
27
|
+
return url;
|
|
28
|
+
};
|
|
29
|
+
this.throwWithInterceptor = (err) => {
|
|
30
|
+
if (this._interceptor.error) {
|
|
31
|
+
const nextError = this._interceptor.error(err);
|
|
32
|
+
if (nextError) {
|
|
33
|
+
throw nextError;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw err;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
get interceptor() {
|
|
40
|
+
return this._interceptor;
|
|
41
|
+
}
|
|
42
|
+
set interceptor(value) {
|
|
43
|
+
this._interceptor = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { getFileName } from '../util';
|
|
3
|
+
import { BaseInterceptorHttpApi } from './BaseInterceptorHttpApi';
|
|
4
|
+
export class BasicHttpApi extends BaseInterceptorHttpApi {
|
|
5
|
+
constructor(provider, baseUrl, headersCreator, paramsSerializer, withCredentials = true) {
|
|
6
|
+
super(paramsSerializer);
|
|
7
|
+
this.provider = provider;
|
|
8
|
+
this.baseUrl = baseUrl;
|
|
9
|
+
this.headersCreator = headersCreator;
|
|
10
|
+
this.withCredentials = withCredentials;
|
|
11
|
+
}
|
|
12
|
+
get(url, params, timeout) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
const headers = yield this.headersCreator();
|
|
16
|
+
return yield this.provider.get({
|
|
17
|
+
url: `${this.baseUrl}${url}`,
|
|
18
|
+
headers,
|
|
19
|
+
withCredentials: this.withCredentials,
|
|
20
|
+
paramsSerializer: this.paramsSerializer,
|
|
21
|
+
params: this.mergeParams('get', url, params),
|
|
22
|
+
timeout,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
this.throwWithInterceptor(error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
post(url, body, timeout) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
const headers = yield this.headersCreator();
|
|
34
|
+
return yield this.provider.post({
|
|
35
|
+
url: `${this.baseUrl}${this.mergeQueries('post', url, body)}`,
|
|
36
|
+
headers,
|
|
37
|
+
withCredentials: this.withCredentials,
|
|
38
|
+
paramsSerializer: this.paramsSerializer,
|
|
39
|
+
params: body,
|
|
40
|
+
timeout,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.throwWithInterceptor(error);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
put(url, body, timeout) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const headers = yield this.headersCreator();
|
|
52
|
+
return yield this.provider.put({
|
|
53
|
+
url: `${this.baseUrl}${this.mergeQueries('put', url, body)}`,
|
|
54
|
+
headers,
|
|
55
|
+
withCredentials: this.withCredentials,
|
|
56
|
+
paramsSerializer: this.paramsSerializer,
|
|
57
|
+
params: body,
|
|
58
|
+
timeout,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
this.throwWithInterceptor(error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
patch(url, body, timeout) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
try {
|
|
69
|
+
const headers = yield this.headersCreator();
|
|
70
|
+
return yield this.provider.patch({
|
|
71
|
+
url: `${this.baseUrl}${this.mergeQueries('patch', url, body)}`,
|
|
72
|
+
headers,
|
|
73
|
+
withCredentials: this.withCredentials,
|
|
74
|
+
paramsSerializer: this.paramsSerializer,
|
|
75
|
+
params: body,
|
|
76
|
+
timeout,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this.throwWithInterceptor(error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
delete(url, body, timeout) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
try {
|
|
87
|
+
const headers = yield this.headersCreator();
|
|
88
|
+
return yield this.provider.delete({
|
|
89
|
+
url: `${this.baseUrl}${this.mergeQueries('delete', url, body)}`,
|
|
90
|
+
headers,
|
|
91
|
+
withCredentials: this.withCredentials,
|
|
92
|
+
paramsSerializer: this.paramsSerializer,
|
|
93
|
+
params: body,
|
|
94
|
+
timeout,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
this.throwWithInterceptor(error);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getFile(url, params, filename) {
|
|
103
|
+
return this.getBlob(url, params)
|
|
104
|
+
.then((blob) => {
|
|
105
|
+
return new File([blob], filename || getFileName(url));
|
|
106
|
+
})
|
|
107
|
+
.catch(this.throwWithInterceptor);
|
|
108
|
+
}
|
|
109
|
+
getBlob(url, params) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
try {
|
|
112
|
+
const headers = yield this.headersCreator();
|
|
113
|
+
return yield this.provider.getBlob({
|
|
114
|
+
url: `${this.baseUrl}${url}`,
|
|
115
|
+
headers,
|
|
116
|
+
withCredentials: this.withCredentials,
|
|
117
|
+
paramsSerializer: this.paramsSerializer,
|
|
118
|
+
params: this.mergeParams('get', url, params),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.throwWithInterceptor(error);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { BaseInterceptorHttpApi } from './BaseInterceptorHttpApi';
|
|
3
|
+
export class BasicHttpUploadApi extends BaseInterceptorHttpApi {
|
|
4
|
+
constructor(provider, baseUrl, headersCreator, paramsSerializer, withCredentials = true) {
|
|
5
|
+
super(paramsSerializer);
|
|
6
|
+
this.provider = provider;
|
|
7
|
+
this.baseUrl = baseUrl;
|
|
8
|
+
this.headersCreator = headersCreator;
|
|
9
|
+
this.withCredentials = withCredentials;
|
|
10
|
+
}
|
|
11
|
+
postUpload(url, data, progressCallback, timeout) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
try {
|
|
14
|
+
const headers = yield this.headersCreator();
|
|
15
|
+
return yield this.provider.post({
|
|
16
|
+
url: `${this.baseUrl}${this.mergeQueries('post', url, data)}`,
|
|
17
|
+
headers,
|
|
18
|
+
withCredentials: this.withCredentials,
|
|
19
|
+
data,
|
|
20
|
+
timeout,
|
|
21
|
+
onProgress: progressCallback,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
this.throwWithInterceptor(error);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
putUpload(url, data, progressCallback, timeout) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
try {
|
|
32
|
+
const headers = yield this.headersCreator();
|
|
33
|
+
return yield this.provider.put({
|
|
34
|
+
url: `${this.baseUrl}${this.mergeQueries('put', url, data)}`,
|
|
35
|
+
headers,
|
|
36
|
+
withCredentials: this.withCredentials,
|
|
37
|
+
data,
|
|
38
|
+
timeout,
|
|
39
|
+
onProgress: progressCallback,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
this.throwWithInterceptor(error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { throwHttpRestError } from './network.util';
|
|
3
|
+
function isConstructor(val) {
|
|
4
|
+
return typeof val === 'function';
|
|
5
|
+
}
|
|
6
|
+
export function ErrorParser(throwableParser) {
|
|
7
|
+
return function (ClassConstructor) {
|
|
8
|
+
if (isConstructor(ClassConstructor) === false) {
|
|
9
|
+
throw new Error('ErrorParser: argument is not function.');
|
|
10
|
+
}
|
|
11
|
+
return class ErrorParserDecoratedUnionHttpNetworkProvider {
|
|
12
|
+
constructor(...args) {
|
|
13
|
+
this.parse = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const nextError = throwableParser(error);
|
|
15
|
+
if (nextError) {
|
|
16
|
+
throw nextError;
|
|
17
|
+
}
|
|
18
|
+
throwHttpRestError(error);
|
|
19
|
+
});
|
|
20
|
+
this.network = new ClassConstructor(args[0], args[1], args[2]);
|
|
21
|
+
}
|
|
22
|
+
get(...args) {
|
|
23
|
+
return this.network.get
|
|
24
|
+
.apply(this.network, [...args])
|
|
25
|
+
.catch(this.parse);
|
|
26
|
+
}
|
|
27
|
+
post(...args) {
|
|
28
|
+
return this.network.post
|
|
29
|
+
.apply(this.network, [...args])
|
|
30
|
+
.catch(this.parse);
|
|
31
|
+
}
|
|
32
|
+
put(...args) {
|
|
33
|
+
return this.network.put
|
|
34
|
+
.apply(this.network, [...args])
|
|
35
|
+
.catch(this.parse);
|
|
36
|
+
}
|
|
37
|
+
patch(...args) {
|
|
38
|
+
return this.network.patch
|
|
39
|
+
.apply(this.network, [...args])
|
|
40
|
+
.catch(this.parse);
|
|
41
|
+
}
|
|
42
|
+
delete(...args) {
|
|
43
|
+
return this.network.delete
|
|
44
|
+
.apply(this.network, [...args])
|
|
45
|
+
.catch(this.parse);
|
|
46
|
+
}
|
|
47
|
+
getBlob(...args) {
|
|
48
|
+
return this.network.getBlob
|
|
49
|
+
.apply(this.network, [...args])
|
|
50
|
+
.catch(this.parse);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { __decorate, __rest } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { ErrorParser } from '../ErrorParser.decorator';
|
|
4
|
+
import { throwableAxiosErrorParser } from './throwableAxiosErrorParser';
|
|
5
|
+
let AxiosHttpNetworkProvider = class AxiosHttpNetworkProvider {
|
|
6
|
+
extractData(axiosRes) {
|
|
7
|
+
return axiosRes.data;
|
|
8
|
+
}
|
|
9
|
+
makeAxiosHeaders(headers) {
|
|
10
|
+
return {
|
|
11
|
+
common: headers,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
get(_a) {
|
|
15
|
+
var { url, headers } = _a, config = __rest(_a, ["url", "headers"]);
|
|
16
|
+
return axios
|
|
17
|
+
.get(url, Object.assign(Object.assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
18
|
+
.then(this.extractData);
|
|
19
|
+
}
|
|
20
|
+
post(_a) {
|
|
21
|
+
var { url, headers, params: data } = _a, config = __rest(_a, ["url", "headers", "params"]);
|
|
22
|
+
return axios
|
|
23
|
+
.post(url, data, Object.assign(Object.assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
24
|
+
.then(this.extractData);
|
|
25
|
+
}
|
|
26
|
+
put(_a) {
|
|
27
|
+
var { url, headers, params: data } = _a, config = __rest(_a, ["url", "headers", "params"]);
|
|
28
|
+
return axios
|
|
29
|
+
.put(url, data, Object.assign(Object.assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
30
|
+
.then(this.extractData);
|
|
31
|
+
}
|
|
32
|
+
patch(_a) {
|
|
33
|
+
var { url, headers, params: data } = _a, config = __rest(_a, ["url", "headers", "params"]);
|
|
34
|
+
return axios
|
|
35
|
+
.patch(url, data, Object.assign(Object.assign({}, config), { headers: this.makeAxiosHeaders(headers) }))
|
|
36
|
+
.then(this.extractData);
|
|
37
|
+
}
|
|
38
|
+
delete(_a) {
|
|
39
|
+
var { url, headers, params: data } = _a, config = __rest(_a, ["url", "headers", "params"]);
|
|
40
|
+
return axios
|
|
41
|
+
.delete(url, Object.assign(Object.assign({}, config), { data, headers: this.makeAxiosHeaders(headers) }))
|
|
42
|
+
.then(this.extractData);
|
|
43
|
+
}
|
|
44
|
+
getBlob(_a) {
|
|
45
|
+
var { url, headers } = _a, config = __rest(_a, ["url", "headers"]);
|
|
46
|
+
return axios
|
|
47
|
+
.get(url, Object.assign(Object.assign({}, config), { headers: this.makeAxiosHeaders(headers), responseType: 'blob' }))
|
|
48
|
+
.then(this.extractData);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
AxiosHttpNetworkProvider = __decorate([
|
|
52
|
+
ErrorParser(throwableAxiosErrorParser)
|
|
53
|
+
], AxiosHttpNetworkProvider);
|
|
54
|
+
export { AxiosHttpNetworkProvider };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { ErrorParser } from '../ErrorParser.decorator';
|
|
4
|
+
import { convertToFormData } from '../network.util';
|
|
5
|
+
import { throwableAxiosErrorParser } from './throwableAxiosErrorParser';
|
|
6
|
+
let AxiosHttpUploadProvider = class AxiosHttpUploadProvider {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.handleDownloadProgressCurried = (onProgress) => ({ loaded, total }) => onProgress({
|
|
9
|
+
completed: loaded >= total,
|
|
10
|
+
loaded,
|
|
11
|
+
progress: Math.floor((loaded * 1000) / total) / 10,
|
|
12
|
+
total,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
extractData(axiosRes) {
|
|
16
|
+
return axiosRes.data;
|
|
17
|
+
}
|
|
18
|
+
makeAxiosHeaders(headers) {
|
|
19
|
+
return {
|
|
20
|
+
common: headers,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
upload(method, { url, data, headers, withCredentials, timeout, onProgress, }) {
|
|
24
|
+
return axios(url, {
|
|
25
|
+
method,
|
|
26
|
+
data: convertToFormData(data),
|
|
27
|
+
headers: this.makeAxiosHeaders(headers),
|
|
28
|
+
withCredentials,
|
|
29
|
+
timeout,
|
|
30
|
+
onDownloadProgress: onProgress
|
|
31
|
+
? this.handleDownloadProgressCurried(onProgress)
|
|
32
|
+
: undefined,
|
|
33
|
+
}).then(this.extractData);
|
|
34
|
+
}
|
|
35
|
+
post(config) {
|
|
36
|
+
return this.upload('POST', config);
|
|
37
|
+
}
|
|
38
|
+
put(config) {
|
|
39
|
+
return this.upload('PUT', config);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
AxiosHttpUploadProvider = __decorate([
|
|
43
|
+
ErrorParser(throwableAxiosErrorParser)
|
|
44
|
+
], AxiosHttpUploadProvider);
|
|
45
|
+
export { AxiosHttpUploadProvider };
|
|
File without changes
|
|
File without changes
|
|
@@ -11,8 +11,8 @@ function tryGetMethod(method) {
|
|
|
11
11
|
export function throwableAxiosErrorParser(error) {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
if (isAxiosError(error)) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
15
|
+
const meta = {
|
|
16
16
|
url: error.config.url || '',
|
|
17
17
|
method: tryGetMethod(error.config.method),
|
|
18
18
|
status: Number(((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || 0),
|
|
@@ -2,9 +2,6 @@ import { qs } from '../util';
|
|
|
2
2
|
import { AxiosHttpNetworkProvider } from './axios';
|
|
3
3
|
import { BasicHttpApi } from './BasicHttpApi';
|
|
4
4
|
import { defaultHeaderCreator } from './network.util';
|
|
5
|
-
export function createHttpApi(baseUrl, headerCreator, paramsSerializer, withCredentials) {
|
|
6
|
-
if (headerCreator === void 0) { headerCreator = defaultHeaderCreator; }
|
|
7
|
-
if (paramsSerializer === void 0) { paramsSerializer = qs.serialize; }
|
|
8
|
-
if (withCredentials === void 0) { withCredentials = true; }
|
|
5
|
+
export function createHttpApi(baseUrl, headerCreator = defaultHeaderCreator, paramsSerializer = qs.serialize, withCredentials = true) {
|
|
9
6
|
return new BasicHttpApi(new AxiosHttpNetworkProvider(), baseUrl, headerCreator, paramsSerializer, withCredentials);
|
|
10
7
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { isServer } from '../util/envCheck';
|
|
3
|
+
function makeHeaders(pipes, token = '') {
|
|
4
|
+
const rawMap = pipes.reduce((prev, fn) => fn(prev, token), new Map());
|
|
5
|
+
return Object.fromEntries(rawMap);
|
|
6
|
+
}
|
|
7
|
+
export const createHttpHeaderPipe = (provider, loginRequiredMessage = '로그인 상태가 만료 되었습니다.\n다시 로그인 하여 주시기 바랍니다.') => {
|
|
8
|
+
return function headerPipe(...pipes) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
let token = '';
|
|
11
|
+
if (provider) {
|
|
12
|
+
token = yield provider.get();
|
|
13
|
+
if (!token && !isServer()) {
|
|
14
|
+
throw new Error(loginRequiredMessage);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return makeHeaders(pipes, token);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -2,9 +2,6 @@ import { qs } from '../util';
|
|
|
2
2
|
import { AxiosHttpUploadProvider } from './axios';
|
|
3
3
|
import { BasicHttpUploadApi } from './BasicHttpUploadApi';
|
|
4
4
|
import { defaultHeaderCreator } from './network.util';
|
|
5
|
-
export function createHttpUploadApi(baseUrl, headerCreator, paramsSerializer, withCredentials) {
|
|
6
|
-
if (headerCreator === void 0) { headerCreator = defaultHeaderCreator; }
|
|
7
|
-
if (paramsSerializer === void 0) { paramsSerializer = qs.serialize; }
|
|
8
|
-
if (withCredentials === void 0) { withCredentials = true; }
|
|
5
|
+
export function createHttpUploadApi(baseUrl, headerCreator = defaultHeaderCreator, paramsSerializer = qs.serialize, withCredentials = true) {
|
|
9
6
|
return new BasicHttpUploadApi(new AxiosHttpUploadProvider(), baseUrl, headerCreator, paramsSerializer, withCredentials);
|
|
10
7
|
}
|