@hidrografico/request 1.0.1 → 1.0.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.
- package/README.md +4 -0
- package/dist/api/api.d.ts +8 -0
- package/dist/api/api.d.ts.map +1 -0
- package/dist/api/api.js +35 -0
- package/dist/component/auth.d.ts +8 -0
- package/dist/component/auth.d.ts.map +1 -0
- package/dist/component/auth.js +9 -0
- package/dist/component/errorMessage.d.ts +6 -0
- package/dist/component/errorMessage.d.ts.map +1 -0
- package/dist/component/errorMessage.js +7 -0
- package/dist/component/request.d.ts +13 -0
- package/dist/component/request.d.ts.map +1 -0
- package/dist/component/request.js +12 -0
- package/dist/component/response.d.ts +13 -0
- package/dist/component/response.d.ts.map +1 -0
- package/dist/component/response.js +13 -0
- package/dist/component/token.d.ts +32 -0
- package/dist/component/token.d.ts.map +1 -0
- package/dist/component/token.js +16 -0
- package/dist/hook/useProvider.d.ts +13 -0
- package/dist/hook/useProvider.d.ts.map +1 -0
- package/dist/hook/useProvider.js +51 -0
- package/dist/hook/useRequest.d.ts +11 -0
- package/dist/hook/useRequest.d.ts.map +1 -0
- package/dist/hook/useRequest.js +38 -0
- package/dist/hook/useRequireAuth.d.ts +4 -0
- package/dist/hook/useRequireAuth.d.ts.map +1 -0
- package/dist/hook/useRequireAuth.js +21 -0
- package/dist/service/crud.d.ts +15 -0
- package/dist/service/crud.d.ts.map +1 -0
- package/dist/service/crud.js +116 -0
- package/dist/service/fetchPage.d.ts +5 -0
- package/dist/service/fetchPage.d.ts.map +1 -0
- package/dist/service/fetchPage.js +22 -0
- package/dist/service/token.d.ts +10 -0
- package/dist/service/token.d.ts.map +1 -0
- package/dist/service/token.js +93 -0
- package/package.json +11 -6
- package/src/api/api.tsx +0 -38
- package/src/component/auth.tsx +0 -13
- package/src/component/errorMessage.tsx +0 -9
- package/src/component/request.tsx +0 -21
- package/src/component/response.tsx +0 -23
- package/src/component/token.tsx +0 -46
- package/src/hook/useProvider.tsx +0 -68
- package/src/hook/useRequest.tsx +0 -38
- package/src/hook/useRequireAuth.tsx +0 -20
- package/src/service/crud.tsx +0 -111
- package/src/service/fetchPage.tsx +0 -23
- package/src/service/token.tsx +0 -94
package/README.md
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
export type ApiClientOptions = {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
onUnauthorized?: () => void;
|
|
5
|
+
onForbidden?: () => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const createApiClient: (options: ApiClientOptions) => AxiosInstance;
|
|
8
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api/api.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAG5C,MAAM,MAAM,gBAAgB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,aA4B3D,CAAA"}
|
package/dist/api/api.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createApiClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const token_1 = require("../service/token");
|
|
9
|
+
const createApiClient = (options) => {
|
|
10
|
+
const api = axios_1.default.create({
|
|
11
|
+
baseURL: options.baseURL,
|
|
12
|
+
headers: { 'content-type': 'application/json' }
|
|
13
|
+
});
|
|
14
|
+
api.interceptors.request.use(async (config) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const token = (_a = (0, token_1.getToken)()) === null || _a === void 0 ? void 0 : _a.accessToken;
|
|
17
|
+
if (token) {
|
|
18
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
19
|
+
}
|
|
20
|
+
return config;
|
|
21
|
+
});
|
|
22
|
+
api.interceptors.response.use((response) => response, (error) => {
|
|
23
|
+
var _a, _b, _c, _d;
|
|
24
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
25
|
+
(0, token_1.removeToken)();
|
|
26
|
+
(_b = options.onUnauthorized) === null || _b === void 0 ? void 0 : _b.call(options);
|
|
27
|
+
}
|
|
28
|
+
if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 403) {
|
|
29
|
+
(_d = options.onForbidden) === null || _d === void 0 ? void 0 : _d.call(options);
|
|
30
|
+
}
|
|
31
|
+
return Promise.reject(error);
|
|
32
|
+
});
|
|
33
|
+
return api;
|
|
34
|
+
};
|
|
35
|
+
exports.createApiClient = createApiClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/component/auth.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACjB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,CAAA;CACd;AAED,eAAO,MAAM,WAAW,EAAG,IAK1B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessage.d.ts","sourceRoot":"","sources":["../../src/component/errorMessage.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,mBAAmB,EAAE,YAGjC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Sort {
|
|
2
|
+
key: string;
|
|
3
|
+
order: 'ASC' | 'DESC';
|
|
4
|
+
}
|
|
5
|
+
export interface Search {
|
|
6
|
+
value?: string;
|
|
7
|
+
page?: number;
|
|
8
|
+
size?: number;
|
|
9
|
+
sort?: Sort;
|
|
10
|
+
}
|
|
11
|
+
export declare const initialSearch: Search;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/component/request.tsx"],"names":[],"mappings":"AAAA,UAAU,IAAI;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,MAAM;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAA;CACd;AAED,eAAO,MAAM,aAAa,EAAE,MAQ3B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface PageInfo {
|
|
2
|
+
size: number;
|
|
3
|
+
number: number;
|
|
4
|
+
totalElements: number;
|
|
5
|
+
totalPages: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Page<T = unknown> {
|
|
8
|
+
content: T[];
|
|
9
|
+
page: PageInfo;
|
|
10
|
+
}
|
|
11
|
+
export declare const initialPage: Page;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/component/response.tsx"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAA;CAClB;AASD,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,OAAO;IAChC,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,IAAI,EAAE,QAAQ,CAAA;CACd;AAED,eAAO,MAAM,WAAW,EAAE,IAGzB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialPage = void 0;
|
|
4
|
+
const initialPageInfo = {
|
|
5
|
+
size: 0,
|
|
6
|
+
number: 0,
|
|
7
|
+
totalElements: 0,
|
|
8
|
+
totalPages: 0
|
|
9
|
+
};
|
|
10
|
+
exports.initialPage = {
|
|
11
|
+
content: [],
|
|
12
|
+
page: initialPageInfo
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Token {
|
|
2
|
+
header: {
|
|
3
|
+
alg: string;
|
|
4
|
+
typ: string;
|
|
5
|
+
};
|
|
6
|
+
payload: {
|
|
7
|
+
jti: string;
|
|
8
|
+
iss: string;
|
|
9
|
+
iat: string;
|
|
10
|
+
nbf: string;
|
|
11
|
+
exp: string;
|
|
12
|
+
sub: string;
|
|
13
|
+
aud: string;
|
|
14
|
+
};
|
|
15
|
+
signature: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Header {
|
|
18
|
+
alg: string;
|
|
19
|
+
typ: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Payload {
|
|
22
|
+
jti: string;
|
|
23
|
+
iss: string;
|
|
24
|
+
iat: string;
|
|
25
|
+
nbf: string;
|
|
26
|
+
exp: string;
|
|
27
|
+
sub: string;
|
|
28
|
+
aud: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const initialHeader: Header;
|
|
31
|
+
export declare const initialPayload: Payload;
|
|
32
|
+
//# sourceMappingURL=token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/component/token.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACf,CAAC;IACF,SAAS,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,MAAM;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,OAAO;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,aAAa,EAAE,MAG3B,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,OAQ5B,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialPayload = exports.initialHeader = void 0;
|
|
4
|
+
exports.initialHeader = {
|
|
5
|
+
alg: '',
|
|
6
|
+
typ: ''
|
|
7
|
+
};
|
|
8
|
+
exports.initialPayload = {
|
|
9
|
+
jti: '',
|
|
10
|
+
iss: '',
|
|
11
|
+
iat: '',
|
|
12
|
+
nbf: '',
|
|
13
|
+
exp: '',
|
|
14
|
+
sub: '',
|
|
15
|
+
aud: ''
|
|
16
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Auth } from '../component/auth';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
export interface AuthContextType extends Auth {
|
|
4
|
+
loginUser: (credentials: any) => Promise<any>;
|
|
5
|
+
logoutUser: () => void;
|
|
6
|
+
isAuthenticated: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const AuthContext: import("react").Context<AuthContextType>;
|
|
9
|
+
export declare const AuthProvider: ({ api, children }: {
|
|
10
|
+
api: AxiosInstance;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=useProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProvider.d.ts","sourceRoot":"","sources":["../../src/hook/useProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,WAAW,eAAgB,SAAQ,IAAI;IACzC,SAAS,EAAE,CAAC,WAAW,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC7C,UAAU,EAAE,MAAM,IAAI,CAAA;IACtB,eAAe,EAAE,OAAO,CAAA;CAC3B;AAED,eAAO,MAAM,WAAW,0CAAiE,CAAA;AAEzF,eAAO,MAAM,YAAY,GAAI,mBAAmB;IAC5C,GAAG,EAAE,aAAa,CAAA;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B,4CAkDA,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthProvider = exports.AuthContext = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const token_1 = require("../service/token");
|
|
7
|
+
const auth_1 = require("../component/auth");
|
|
8
|
+
const crud_1 = require("../service/crud");
|
|
9
|
+
exports.AuthContext = (0, react_1.createContext)(auth_1.initialAuth);
|
|
10
|
+
const AuthProvider = ({ api, children }) => {
|
|
11
|
+
const [state, setState] = (0, react_1.useState)(() => (0, token_1.isValidToken)() ? (0, token_1.getToken)() : auth_1.initialAuth);
|
|
12
|
+
const loginUser = (0, react_1.useCallback)(async (credentials) => {
|
|
13
|
+
const result = await (0, crud_1.login)(api, '/auth/login', credentials);
|
|
14
|
+
if (!Array.isArray(result)) {
|
|
15
|
+
setState(result);
|
|
16
|
+
return { success: true, data: result };
|
|
17
|
+
}
|
|
18
|
+
return { success: false, errors: result };
|
|
19
|
+
}, []);
|
|
20
|
+
const logoutUser = (0, react_1.useCallback)(() => {
|
|
21
|
+
(0, crud_1.logout)();
|
|
22
|
+
setState(auth_1.initialAuth);
|
|
23
|
+
window.location.href = '/login';
|
|
24
|
+
}, []);
|
|
25
|
+
// Verifica token expirado a cada minuto
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
const interval = setInterval(() => {
|
|
28
|
+
if (state.accessToken && !(0, token_1.isValidToken)()) {
|
|
29
|
+
logoutUser();
|
|
30
|
+
}
|
|
31
|
+
}, 60000);
|
|
32
|
+
return () => clearInterval(interval);
|
|
33
|
+
}, [state.accessToken, logoutUser]);
|
|
34
|
+
// Escuta mudanças no localStorage (ex.: logout em outra aba)
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
const handleStorageChange = (e) => {
|
|
37
|
+
if (e.key === 'token') {
|
|
38
|
+
if (!e.newValue || !(0, token_1.isValidToken)()) {
|
|
39
|
+
setState(auth_1.initialAuth);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setState((0, token_1.getToken)());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
window.addEventListener('storage', handleStorageChange);
|
|
47
|
+
return () => window.removeEventListener('storage', handleStorageChange);
|
|
48
|
+
}, []);
|
|
49
|
+
return ((0, jsx_runtime_1.jsx)(exports.AuthContext.Provider, { value: { ...state, loginUser, logoutUser, isAuthenticated: (0, token_1.isValidToken)() }, children: children }));
|
|
50
|
+
};
|
|
51
|
+
exports.AuthProvider = AuthProvider;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ErrorMessage } from '../component/errorMessage';
|
|
2
|
+
import { Page } from '../component/response';
|
|
3
|
+
import { Search } from '../component/request';
|
|
4
|
+
import { AxiosInstance } from 'axios';
|
|
5
|
+
export declare const useRequest: (api: AxiosInstance, endpoint: string, search?: Search) => {
|
|
6
|
+
response: Page<unknown>;
|
|
7
|
+
error: ErrorMessage[];
|
|
8
|
+
loading: boolean;
|
|
9
|
+
request: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequest.d.ts","sourceRoot":"","sources":["../../src/hook/useRequest.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAuB,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EAAe,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,eAAO,MAAM,UAAU,GAAI,KAAK,aAAa,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM;;;;;CA8B/E,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRequest = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const errorMessage_1 = require("../component/errorMessage");
|
|
6
|
+
const response_1 = require("../component/response");
|
|
7
|
+
const fetchPage_1 = require("../service/fetchPage");
|
|
8
|
+
const useRequest = (api, endpoint, search) => {
|
|
9
|
+
const [response, setResponse] = (0, react_1.useState)(response_1.initialPage);
|
|
10
|
+
const [error, setError] = (0, react_1.useState)([errorMessage_1.initialErrorMessage]);
|
|
11
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
12
|
+
const abortControllerRef = (0, react_1.useRef)(null);
|
|
13
|
+
const request = (0, react_1.useCallback)(async () => {
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = abortControllerRef.current) === null || _a === void 0 ? void 0 : _a.abort();
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
abortControllerRef.current = controller;
|
|
18
|
+
try {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
setError([errorMessage_1.initialErrorMessage]);
|
|
21
|
+
const data = await (0, fetchPage_1.FetchPage)(api, endpoint, search, controller.signal);
|
|
22
|
+
setResponse(data);
|
|
23
|
+
}
|
|
24
|
+
catch (requestError) {
|
|
25
|
+
setError([requestError]);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
setLoading(false);
|
|
29
|
+
abortControllerRef.current = null;
|
|
30
|
+
}
|
|
31
|
+
}, [endpoint, search]);
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
request();
|
|
34
|
+
return () => { var _a; return (_a = abortControllerRef.current) === null || _a === void 0 ? void 0 : _a.abort(); };
|
|
35
|
+
}, [request]);
|
|
36
|
+
return { response, error, loading, request };
|
|
37
|
+
};
|
|
38
|
+
exports.useRequest = useRequest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequireAuth.d.ts","sourceRoot":"","sources":["../../src/hook/useRequireAuth.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAe,eAAe,EAAE,MAAM,eAAe,CAAA;AAE5D,eAAO,MAAM,OAAO,QAAO,eAE1B,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,kBAAkB,GAAG,4CAWhD,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequireAuth = exports.useAuth = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
7
|
+
const useProvider_1 = require("./useProvider");
|
|
8
|
+
const useAuth = () => {
|
|
9
|
+
return (0, react_1.useContext)(useProvider_1.AuthContext);
|
|
10
|
+
};
|
|
11
|
+
exports.useAuth = useAuth;
|
|
12
|
+
const RequireAuth = ({ allowedRoles }) => {
|
|
13
|
+
const { role, accessToken } = (0, exports.useAuth)();
|
|
14
|
+
const location = (0, react_router_dom_1.useLocation)();
|
|
15
|
+
return ((role === null || role === void 0 ? void 0 : role.find((role) => allowedRoles === null || allowedRoles === void 0 ? void 0 : allowedRoles.includes(role)))
|
|
16
|
+
? (0, jsx_runtime_1.jsx)(react_router_dom_1.Outlet, {})
|
|
17
|
+
: accessToken
|
|
18
|
+
? (0, jsx_runtime_1.jsx)(react_router_dom_1.Navigate, { to: '/notAllowed', state: { from: location }, replace: true })
|
|
19
|
+
: (0, jsx_runtime_1.jsx)(react_router_dom_1.Navigate, { to: '/login', state: { from: location }, replace: true }));
|
|
20
|
+
};
|
|
21
|
+
exports.RequireAuth = RequireAuth;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { ErrorMessage } from '../component/errorMessage';
|
|
3
|
+
import { Search } from '../component/request';
|
|
4
|
+
export declare const login: <Auth>(api: AxiosInstance, url: string, object: Auth) => Promise<Auth | ErrorMessage[]>;
|
|
5
|
+
export declare const reset: <Auth>(api: AxiosInstance, url: string, object: Auth) => Promise<Auth | ErrorMessage[]>;
|
|
6
|
+
export declare const logout: () => void;
|
|
7
|
+
export declare const changePassword: <User>(api: AxiosInstance, data: User) => Promise<User | ErrorMessage[]>;
|
|
8
|
+
export declare const create: <T>(api: AxiosInstance, url: string, object: T) => Promise<any>;
|
|
9
|
+
export declare const createAll: <T>(api: AxiosInstance, url: string, object: T[]) => Promise<T | ErrorMessage[]>;
|
|
10
|
+
export declare const retrieve: <T>(api: AxiosInstance, url: string, search?: Search, signal?: AbortSignal) => Promise<T | ErrorMessage[]>;
|
|
11
|
+
export declare const update: <T>(api: AxiosInstance, url: string, object: T) => Promise<T | ErrorMessage[]>;
|
|
12
|
+
export declare const remove: <T>(api: AxiosInstance, url: string, id: string) => Promise<T | ErrorMessage[]>;
|
|
13
|
+
export declare const removeComposite: <T>(api: AxiosInstance, url: string, object: Object, one: string, two: string, three: string, four: string) => Promise<T | ErrorMessage[]>;
|
|
14
|
+
export declare const removeAll: <T>(api: AxiosInstance, url: string) => Promise<T | ErrorMessage[]>;
|
|
15
|
+
//# sourceMappingURL=crud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/service/crud.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAqB7C,eAAO,MAAM,KAAK,GAAS,IAAI,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,QAAQ,IAAI,mCAO9E,CAAA;AAED,eAAO,MAAM,KAAK,GAAS,IAAI,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,QAAQ,IAAI,mCAO9E,CAAA;AAED,eAAO,MAAM,MAAM,YAElB,CAAA;AAED,eAAO,MAAM,cAAc,GAAS,IAAI,EAAG,KAAK,aAAa,EAAE,MAAM,IAAI,mCAOxE,CAAA;AAED,eAAO,MAAM,MAAM,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,QAAQ,CAAC,iBAIzE,CAAA;AAED,eAAO,MAAM,SAAS,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,gCAI9E,CAAA;AAED,eAAO,MAAM,QAAQ,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,SAAS,MAAM,EAAE,SAAS,WAAW,gCAcvG,CAAA;AAED,eAAO,MAAM,MAAM,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,QAAQ,CAAC,gCAIzE,CAAA;AAED,eAAO,MAAM,MAAM,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,IAAI,MAAM,gCAI1E,CAAA;AAED,eAAO,MAAM,eAAe,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,QAAQ,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,MAAM,gCAU9I,CAAA;AAED,eAAO,MAAM,SAAS,GAAS,CAAC,EAAG,KAAK,aAAa,EAAE,KAAK,MAAM,gCAIjE,CAAA"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAll = exports.removeComposite = exports.remove = exports.update = exports.retrieve = exports.createAll = exports.create = exports.changePassword = exports.logout = exports.reset = exports.login = void 0;
|
|
4
|
+
const token_1 = require("./token");
|
|
5
|
+
// Respostas de informação (100-199),
|
|
6
|
+
// Respostas de sucesso (200-299),
|
|
7
|
+
// Redirecionamentos (300-399)
|
|
8
|
+
// Erros do cliente (400-499)
|
|
9
|
+
// Erros do servidor (500-599).
|
|
10
|
+
const addError = (error) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
let errorMessage = [];
|
|
13
|
+
if (error.response.data.validationErrors !== undefined) {
|
|
14
|
+
(_b = (_a = error.response.data) === null || _a === void 0 ? void 0 : _a.validationErrors) === null || _b === void 0 ? void 0 : _b.forEach((element) => {
|
|
15
|
+
errorMessage.push({ field: element.field, message: element.message });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
errorMessage.push({ field: 'Error', message: 'Internal Error' });
|
|
20
|
+
}
|
|
21
|
+
return errorMessage;
|
|
22
|
+
};
|
|
23
|
+
const login = async (api, url, object) => {
|
|
24
|
+
return await api.post(url, object)
|
|
25
|
+
.then(response => {
|
|
26
|
+
(0, token_1.setToken)(response.data);
|
|
27
|
+
return response.data;
|
|
28
|
+
})
|
|
29
|
+
.catch(error => { return addError(error); });
|
|
30
|
+
};
|
|
31
|
+
exports.login = login;
|
|
32
|
+
const reset = async (api, url, object) => {
|
|
33
|
+
return await api.put(url, object)
|
|
34
|
+
.then(response => {
|
|
35
|
+
(0, token_1.setToken)(response.data);
|
|
36
|
+
return response.data;
|
|
37
|
+
})
|
|
38
|
+
.catch(error => { return addError(error); });
|
|
39
|
+
};
|
|
40
|
+
exports.reset = reset;
|
|
41
|
+
const logout = () => {
|
|
42
|
+
(0, token_1.removeToken)();
|
|
43
|
+
};
|
|
44
|
+
exports.logout = logout;
|
|
45
|
+
const changePassword = async (api, data) => {
|
|
46
|
+
return await api.put(`/user/changePassword`, data)
|
|
47
|
+
.then(response => {
|
|
48
|
+
return response.data;
|
|
49
|
+
})
|
|
50
|
+
.catch(error => {
|
|
51
|
+
return addError(error);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.changePassword = changePassword;
|
|
55
|
+
const create = async (api, url, object) => {
|
|
56
|
+
return await api.post(`/${url}`, object)
|
|
57
|
+
.then(response => { return response.data; })
|
|
58
|
+
.catch(error => { return addError(error); });
|
|
59
|
+
};
|
|
60
|
+
exports.create = create;
|
|
61
|
+
const createAll = async (api, url, object) => {
|
|
62
|
+
return await api.post(`/${url}/createAll`, object)
|
|
63
|
+
.then(response => { return response.data; })
|
|
64
|
+
.catch(error => { return addError(error); });
|
|
65
|
+
};
|
|
66
|
+
exports.createAll = createAll;
|
|
67
|
+
const retrieve = async (api, url, search, signal) => {
|
|
68
|
+
var _a, _b, _c;
|
|
69
|
+
if ((search === null || search === void 0 ? void 0 : search.page) === undefined && (search === null || search === void 0 ? void 0 : search.size) === undefined) {
|
|
70
|
+
return await api.get(`/${url}`)
|
|
71
|
+
.then(response => { return response.data; })
|
|
72
|
+
.catch(error => { return addError(error); });
|
|
73
|
+
}
|
|
74
|
+
else if (((_a = search === null || search === void 0 ? void 0 : search.sort) === null || _a === void 0 ? void 0 : _a.order) === undefined) {
|
|
75
|
+
return await api.get(`/${url}?value=${search === null || search === void 0 ? void 0 : search.value}`, { params: { page: search === null || search === void 0 ? void 0 : search.page, size: search === null || search === void 0 ? void 0 : search.size }, signal })
|
|
76
|
+
.then(response => { return response.data; })
|
|
77
|
+
.catch(error => { return addError(error); });
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return await api.get(`/${url}?value=${search === null || search === void 0 ? void 0 : search.value}`, { params: { page: search === null || search === void 0 ? void 0 : search.page, size: search === null || search === void 0 ? void 0 : search.size, sort: `${(_b = search === null || search === void 0 ? void 0 : search.sort) === null || _b === void 0 ? void 0 : _b.key},${(_c = search === null || search === void 0 ? void 0 : search.sort) === null || _c === void 0 ? void 0 : _c.order}` }, signal })
|
|
81
|
+
.then(response => { return response.data; })
|
|
82
|
+
.catch(error => { return addError(error); });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.retrieve = retrieve;
|
|
86
|
+
const update = async (api, url, object) => {
|
|
87
|
+
return await api.put(`/${url}`, object)
|
|
88
|
+
.then(response => { return response.data; })
|
|
89
|
+
.catch(error => { return addError(error); });
|
|
90
|
+
};
|
|
91
|
+
exports.update = update;
|
|
92
|
+
const remove = async (api, url, id) => {
|
|
93
|
+
return await api.delete(`/${url}/${id}`)
|
|
94
|
+
.then(response => { return response.data; })
|
|
95
|
+
.catch(error => { return addError(error); });
|
|
96
|
+
};
|
|
97
|
+
exports.remove = remove;
|
|
98
|
+
const removeComposite = async (api, url, object, one, two, three, four) => {
|
|
99
|
+
if (three !== '' && four !== '') {
|
|
100
|
+
return await api.delete(`/${url}`, object)
|
|
101
|
+
.then(response => { return response.data; })
|
|
102
|
+
.catch(error => { return addError(error); });
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return await api.delete(`/${url}/${one}/${two}`, object)
|
|
106
|
+
.then(response => { return response.data; })
|
|
107
|
+
.catch(error => { return addError(error); });
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
exports.removeComposite = removeComposite;
|
|
111
|
+
const removeAll = async (api, url) => {
|
|
112
|
+
return await api.delete(`/${url}`)
|
|
113
|
+
.then(response => { return response.data; })
|
|
114
|
+
.catch(error => { return addError(error); });
|
|
115
|
+
};
|
|
116
|
+
exports.removeAll = removeAll;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Page } from '../component/response';
|
|
3
|
+
import { Search } from '../component/request';
|
|
4
|
+
export declare const FetchPage: (api: AxiosInstance, endpoint: string, search?: Search, signal?: AbortSignal) => Promise<Page>;
|
|
5
|
+
//# sourceMappingURL=fetchPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchPage.d.ts","sourceRoot":"","sources":["../../src/service/fetchPage.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,eAAO,MAAM,SAAS,GAAU,KAAK,aAAa,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,EAAE,SAAS,WAAW,KAAG,OAAO,CAAC,IAAI,CAkBzH,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchPage = void 0;
|
|
4
|
+
const FetchPage = async (api, endpoint, search, signal) => {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
const uri = ((_a = search === null || search === void 0 ? void 0 : search.value) === null || _a === void 0 ? void 0 : _a.trim())
|
|
7
|
+
? `/${endpoint}?value=${encodeURIComponent(search.value)}`
|
|
8
|
+
: `/${endpoint}`;
|
|
9
|
+
const params = {
|
|
10
|
+
page: search === null || search === void 0 ? void 0 : search.page,
|
|
11
|
+
size: search === null || search === void 0 ? void 0 : search.size
|
|
12
|
+
};
|
|
13
|
+
if (((_b = search === null || search === void 0 ? void 0 : search.sort) === null || _b === void 0 ? void 0 : _b.order) && ((_c = search === null || search === void 0 ? void 0 : search.sort) === null || _c === void 0 ? void 0 : _c.key)) {
|
|
14
|
+
params.sort = `${search.sort.key},${search.sort.order}`;
|
|
15
|
+
}
|
|
16
|
+
const { data } = await api.get(uri, {
|
|
17
|
+
params: Object.keys(params).length > 0 ? params : undefined,
|
|
18
|
+
signal
|
|
19
|
+
});
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
exports.FetchPage = FetchPage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Auth } from '../component/auth';
|
|
2
|
+
import { Header, Payload } from '../component/token';
|
|
3
|
+
export declare const isValidToken: () => boolean;
|
|
4
|
+
export declare const getToken: () => Auth;
|
|
5
|
+
export declare const setToken: (token: any) => void;
|
|
6
|
+
export declare const removeToken: () => void;
|
|
7
|
+
export declare const getPayload: () => Payload;
|
|
8
|
+
export declare const decodeJwt: () => string | null;
|
|
9
|
+
export declare const getHeader: () => Header;
|
|
10
|
+
//# sourceMappingURL=token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/service/token.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAiC,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAWnF,eAAO,MAAM,YAAY,QAAO,OAY/B,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,IAG3B,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,GAAG,KAAG,IAErC,CAAA;AAED,eAAO,MAAM,WAAW,YAEvB,CAAA;AAED,eAAO,MAAM,UAAU,QAAO,OAoB7B,CAAA;AAED,eAAO,MAAM,SAAS,qBAUrB,CAAA;AAED,eAAO,MAAM,SAAS,QAAO,MAoB5B,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHeader = exports.decodeJwt = exports.getPayload = exports.removeToken = exports.setToken = exports.getToken = exports.isValidToken = void 0;
|
|
4
|
+
const auth_1 = require("../component/auth");
|
|
5
|
+
const token_1 = require("../component/token");
|
|
6
|
+
const isValidJSON = (json) => {
|
|
7
|
+
try {
|
|
8
|
+
JSON.parse(json);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const isValidToken = () => {
|
|
16
|
+
try {
|
|
17
|
+
const token = (0, exports.getToken)();
|
|
18
|
+
if (!(token === null || token === void 0 ? void 0 : token.accessToken))
|
|
19
|
+
return false;
|
|
20
|
+
const { exp } = (0, exports.getPayload)();
|
|
21
|
+
if (typeof exp !== 'number')
|
|
22
|
+
return false;
|
|
23
|
+
return exp * 1000 > Date.now();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.isValidToken = isValidToken;
|
|
30
|
+
const getToken = () => {
|
|
31
|
+
let token = `${localStorage.getItem(`token`)}`;
|
|
32
|
+
return isValidJSON(token) ? JSON.parse(token) : auth_1.initialAuth;
|
|
33
|
+
};
|
|
34
|
+
exports.getToken = getToken;
|
|
35
|
+
const setToken = (token) => {
|
|
36
|
+
localStorage.setItem(`token`, JSON.stringify(token));
|
|
37
|
+
};
|
|
38
|
+
exports.setToken = setToken;
|
|
39
|
+
const removeToken = () => {
|
|
40
|
+
localStorage.removeItem('token');
|
|
41
|
+
};
|
|
42
|
+
exports.removeToken = removeToken;
|
|
43
|
+
const getPayload = () => {
|
|
44
|
+
try {
|
|
45
|
+
const token = (0, exports.getToken)();
|
|
46
|
+
if (!(token === null || token === void 0 ? void 0 : token.accessToken))
|
|
47
|
+
return token_1.initialPayload;
|
|
48
|
+
const base64 = token.accessToken.split('.')[1]
|
|
49
|
+
.replace(/-/g, '+')
|
|
50
|
+
.replace(/_/g, '/');
|
|
51
|
+
const payload = decodeURIComponent(atob(base64)
|
|
52
|
+
.split('')
|
|
53
|
+
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
54
|
+
.join(''));
|
|
55
|
+
return isValidJSON(payload) ? JSON.parse(payload) : token_1.initialPayload;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return token_1.initialPayload;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.getPayload = getPayload;
|
|
62
|
+
const decodeJwt = () => {
|
|
63
|
+
if ((0, exports.getToken)() !== null) {
|
|
64
|
+
var base64Url = (0, exports.getToken)().accessToken.split('.')[1];
|
|
65
|
+
var base64 = decodeURIComponent(atob(base64Url).split('').map((c) => {
|
|
66
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
67
|
+
}).join(''));
|
|
68
|
+
return base64;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.decodeJwt = decodeJwt;
|
|
75
|
+
const getHeader = () => {
|
|
76
|
+
try {
|
|
77
|
+
const token = (0, exports.getToken)();
|
|
78
|
+
if (!(token === null || token === void 0 ? void 0 : token.accessToken))
|
|
79
|
+
return token_1.initialHeader;
|
|
80
|
+
const base64 = token.accessToken.split('.')[0]
|
|
81
|
+
.replace(/-/g, '+')
|
|
82
|
+
.replace(/_/g, '/');
|
|
83
|
+
const header = decodeURIComponent(atob(base64)
|
|
84
|
+
.split('')
|
|
85
|
+
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
86
|
+
.join(''));
|
|
87
|
+
return isValidJSON(header) ? JSON.parse(header) : token_1.initialHeader;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return token_1.initialHeader;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.getHeader = getHeader;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hidrografico/request",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://github.com/hidrografico/request#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,19 +17,24 @@
|
|
|
17
17
|
],
|
|
18
18
|
"author": "Marcelo Gadelha",
|
|
19
19
|
"type": "commonjs",
|
|
20
|
-
"main": "index.js",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
21
25
|
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
22
27
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
23
28
|
},
|
|
24
29
|
"peerDependencies": {
|
|
25
|
-
"
|
|
26
|
-
"react": "^
|
|
30
|
+
"react": "^19.2.3",
|
|
31
|
+
"react-router-dom": "^7.12.0"
|
|
27
32
|
},
|
|
28
33
|
"devDependencies": {
|
|
29
34
|
"@types/react": "^19.2.9",
|
|
30
|
-
"
|
|
35
|
+
"typescript": "^5.9.3"
|
|
31
36
|
},
|
|
32
37
|
"dependencies": {
|
|
33
|
-
"
|
|
38
|
+
"axios": "^1.13.2"
|
|
34
39
|
}
|
|
35
40
|
}
|
package/src/api/api.tsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosInstance } from "axios"
|
|
2
|
-
import { getToken, removeToken } from "../service/token"
|
|
3
|
-
|
|
4
|
-
export type ApiClientOptions = {
|
|
5
|
-
baseURL: string
|
|
6
|
-
onUnauthorized?: () => void
|
|
7
|
-
onForbidden?: () => void
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const createApiClient = (options: ApiClientOptions): AxiosInstance => {
|
|
11
|
-
const api = axios.create({
|
|
12
|
-
baseURL: options.baseURL,
|
|
13
|
-
headers: { 'content-type': 'application/json' }
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
api.interceptors.request.use(async config => {
|
|
17
|
-
const token = getToken()?.accessToken
|
|
18
|
-
if (token) {
|
|
19
|
-
config.headers!.Authorization = `Bearer ${token}`
|
|
20
|
-
}
|
|
21
|
-
return config
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
api.interceptors.response.use(
|
|
25
|
-
(response) => response,
|
|
26
|
-
(error) => {
|
|
27
|
-
if (error.response?.status === 401) {
|
|
28
|
-
removeToken()
|
|
29
|
-
options.onUnauthorized?.()
|
|
30
|
-
}
|
|
31
|
-
if (error.response?.status === 403) {
|
|
32
|
-
options.onForbidden?.()
|
|
33
|
-
}
|
|
34
|
-
return Promise.reject(error)
|
|
35
|
-
}
|
|
36
|
-
)
|
|
37
|
-
return api
|
|
38
|
-
}
|
package/src/component/auth.tsx
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
interface Sort {
|
|
2
|
-
key: string,
|
|
3
|
-
order: 'ASC' | 'DESC'
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface Search {
|
|
7
|
-
value?: string,
|
|
8
|
-
page?: number,
|
|
9
|
-
size?: number,
|
|
10
|
-
sort?: Sort
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const initialSearch: Search = {
|
|
14
|
-
value: '',
|
|
15
|
-
page: 0,
|
|
16
|
-
size: 15,
|
|
17
|
-
sort: {
|
|
18
|
-
key: 'id',
|
|
19
|
-
order: 'ASC',
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
interface PageInfo {
|
|
2
|
-
size: number,
|
|
3
|
-
number: number,
|
|
4
|
-
totalElements: number,
|
|
5
|
-
totalPages: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const initialPageInfo: PageInfo = {
|
|
9
|
-
size: 0,
|
|
10
|
-
number: 0,
|
|
11
|
-
totalElements: 0,
|
|
12
|
-
totalPages: 0
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Page<T = unknown> {
|
|
16
|
-
content: T[],
|
|
17
|
-
page: PageInfo
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const initialPage: Page = {
|
|
21
|
-
content: [],
|
|
22
|
-
page: initialPageInfo
|
|
23
|
-
}
|
package/src/component/token.tsx
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export interface Token {
|
|
2
|
-
header: {
|
|
3
|
-
alg: string,
|
|
4
|
-
typ: string,
|
|
5
|
-
},
|
|
6
|
-
payload: {
|
|
7
|
-
jti: string, //jsonTokenIdentifier
|
|
8
|
-
iss: string, //issuer
|
|
9
|
-
iat: string, //issuedAt
|
|
10
|
-
nbf: string, //notBefore (Não Antes)
|
|
11
|
-
exp: string, //expiration
|
|
12
|
-
sub: string, //Subject
|
|
13
|
-
aud: string, //Audience
|
|
14
|
-
},
|
|
15
|
-
signature: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface Header {
|
|
19
|
-
alg: string,
|
|
20
|
-
typ: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface Payload {
|
|
24
|
-
jti: string, //jsonTokenIdentifier
|
|
25
|
-
iss: string, //issuer
|
|
26
|
-
iat: string, //issuedAt
|
|
27
|
-
nbf: string, //notBefore (Não Antes)
|
|
28
|
-
exp: string, //expiration
|
|
29
|
-
sub: string, //Subject
|
|
30
|
-
aud: string //Audience
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const initialHeader: Header = {
|
|
34
|
-
alg: '',
|
|
35
|
-
typ: ''
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const initialPayload: Payload = {
|
|
39
|
-
jti: '',
|
|
40
|
-
iss: '',
|
|
41
|
-
iat: '',
|
|
42
|
-
nbf: '',
|
|
43
|
-
exp: '',
|
|
44
|
-
sub: '',
|
|
45
|
-
aud: ''
|
|
46
|
-
}
|
package/src/hook/useProvider.tsx
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { createContext, useCallback, useEffect, useState } from 'react'
|
|
2
|
-
import { getToken, isValidToken } from '../service/token'
|
|
3
|
-
import { Auth, initialAuth } from '../component/auth'
|
|
4
|
-
import { login, logout } from '../service/crud'
|
|
5
|
-
import { AxiosInstance } from 'axios'
|
|
6
|
-
|
|
7
|
-
interface AuthContextType extends Auth {
|
|
8
|
-
loginUser: (credentials: any) => Promise<any>
|
|
9
|
-
logoutUser: () => void
|
|
10
|
-
isAuthenticated: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const AuthContext = createContext<AuthContextType>(initialAuth as AuthContextType)
|
|
14
|
-
|
|
15
|
-
export const AuthProvider = ({ api, children }: {
|
|
16
|
-
api: AxiosInstance
|
|
17
|
-
children: React.ReactNode
|
|
18
|
-
}) => {
|
|
19
|
-
const [state, setState] = useState<Auth>(() =>
|
|
20
|
-
isValidToken() ? getToken() : initialAuth
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
const loginUser = useCallback(async (credentials: any) => {
|
|
24
|
-
const result = await login(api, '/auth/login', credentials)
|
|
25
|
-
|
|
26
|
-
if (!Array.isArray(result)) {
|
|
27
|
-
setState(result)
|
|
28
|
-
return { success: true, data: result }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return { success: false, errors: result }
|
|
32
|
-
}, [])
|
|
33
|
-
|
|
34
|
-
const logoutUser = useCallback(() => {
|
|
35
|
-
logout()
|
|
36
|
-
setState(initialAuth)
|
|
37
|
-
window.location.href = '/login'
|
|
38
|
-
}, [])
|
|
39
|
-
// Verifica token expirado a cada minuto
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
const interval = setInterval(() => {
|
|
42
|
-
if (state.accessToken && !isValidToken()) {
|
|
43
|
-
logoutUser()
|
|
44
|
-
}
|
|
45
|
-
}, 60000)
|
|
46
|
-
return () => clearInterval(interval)
|
|
47
|
-
}, [state.accessToken, logoutUser])
|
|
48
|
-
// Escuta mudanças no localStorage (ex.: logout em outra aba)
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
const handleStorageChange = (e: StorageEvent) => {
|
|
51
|
-
if (e.key === 'token') {
|
|
52
|
-
if (!e.newValue || !isValidToken()) {
|
|
53
|
-
setState(initialAuth)
|
|
54
|
-
} else {
|
|
55
|
-
setState(getToken())
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
window.addEventListener('storage', handleStorageChange)
|
|
60
|
-
return () => window.removeEventListener('storage', handleStorageChange)
|
|
61
|
-
}, [])
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<AuthContext.Provider value={{ ...state, loginUser, logoutUser, isAuthenticated: isValidToken() }}>
|
|
65
|
-
{children}
|
|
66
|
-
</AuthContext.Provider>
|
|
67
|
-
)
|
|
68
|
-
}
|
package/src/hook/useRequest.tsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
-
import { ErrorMessage, initialErrorMessage } from '../component/component.errorMessage'
|
|
3
|
-
import { initialPage, Page } from '../component/component.response'
|
|
4
|
-
import { Search } from '../component/component.request'
|
|
5
|
-
import { FetchPage } from '../service/fetchPage'
|
|
6
|
-
import { AxiosInstance } from 'axios'
|
|
7
|
-
|
|
8
|
-
export const useRequest = (api: AxiosInstance, endpoint: string, search?: Search) => {
|
|
9
|
-
const [response, setResponse] = useState<Page>(initialPage)
|
|
10
|
-
const [error, setError] = useState<ErrorMessage[]>([initialErrorMessage])
|
|
11
|
-
const [loading, setLoading] = useState<boolean>(false)
|
|
12
|
-
const abortControllerRef = useRef<AbortController | null>(null)
|
|
13
|
-
|
|
14
|
-
const request = useCallback(async () => {
|
|
15
|
-
abortControllerRef.current?.abort()
|
|
16
|
-
const controller = new AbortController()
|
|
17
|
-
abortControllerRef.current = controller
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
setLoading(true)
|
|
21
|
-
setError([initialErrorMessage])
|
|
22
|
-
const data = await FetchPage(api, endpoint, search, controller.signal)
|
|
23
|
-
setResponse(data)
|
|
24
|
-
} catch (requestError) {
|
|
25
|
-
setError([requestError as ErrorMessage])
|
|
26
|
-
} finally {
|
|
27
|
-
setLoading(false)
|
|
28
|
-
abortControllerRef.current = null
|
|
29
|
-
}
|
|
30
|
-
}, [endpoint, search])
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
request()
|
|
34
|
-
return () => abortControllerRef.current?.abort()
|
|
35
|
-
}, [request])
|
|
36
|
-
|
|
37
|
-
return { response, error, loading, request }
|
|
38
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react'
|
|
2
|
-
import { useLocation, Navigate, Outlet } from 'react-router-dom'
|
|
3
|
-
import { AuthContext } from './useProvider'
|
|
4
|
-
|
|
5
|
-
export const useAuth = () => {
|
|
6
|
-
return useContext(AuthContext)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const RequireAuth = ({ allowedRoles }: any) => {
|
|
10
|
-
const { role, accessToken } = useAuth()
|
|
11
|
-
const location = useLocation()
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
role?.find((role: any) => allowedRoles?.includes(role))
|
|
15
|
-
? <Outlet />
|
|
16
|
-
: accessToken
|
|
17
|
-
? <Navigate to='/notAllowed' state={{ from: location }} replace />
|
|
18
|
-
: <Navigate to='/login' state={{ from: location }} replace />
|
|
19
|
-
)
|
|
20
|
-
}
|
package/src/service/crud.tsx
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios'
|
|
2
|
-
import { ErrorMessage } from '../component/errorMessage'
|
|
3
|
-
import { Search } from '../component/request'
|
|
4
|
-
import { removeToken, setToken } from './token'
|
|
5
|
-
|
|
6
|
-
// Respostas de informação (100-199),
|
|
7
|
-
// Respostas de sucesso (200-299),
|
|
8
|
-
// Redirecionamentos (300-399)
|
|
9
|
-
// Erros do cliente (400-499)
|
|
10
|
-
// Erros do servidor (500-599).
|
|
11
|
-
|
|
12
|
-
const addError = (error: any):ErrorMessage[] => {
|
|
13
|
-
let errorMessage: ErrorMessage[] = []
|
|
14
|
-
if (error.response.data.validationErrors !== undefined){
|
|
15
|
-
error.response.data?.validationErrors?.forEach((element: ErrorMessage) => {
|
|
16
|
-
errorMessage.push({ field: element.field, message: element.message })
|
|
17
|
-
})
|
|
18
|
-
} else {
|
|
19
|
-
errorMessage.push({ field: 'Error', message: 'Internal Error' })
|
|
20
|
-
}
|
|
21
|
-
return errorMessage
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const login = async<Auth,>(api: AxiosInstance, url: string, object: Auth) => {
|
|
25
|
-
return await api.post<Auth>(url, object)
|
|
26
|
-
.then(response => {
|
|
27
|
-
setToken(response.data)
|
|
28
|
-
return response.data
|
|
29
|
-
})
|
|
30
|
-
.catch(error => { return addError(error) })
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const reset = async<Auth,>(api: AxiosInstance, url: string, object: Auth) => {
|
|
34
|
-
return await api.put<Auth>(url, object)
|
|
35
|
-
.then(response => {
|
|
36
|
-
setToken(response.data)
|
|
37
|
-
return response.data
|
|
38
|
-
})
|
|
39
|
-
.catch(error => { return addError(error) })
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const logout = () => {
|
|
43
|
-
removeToken()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const changePassword = async<User,>(api: AxiosInstance, data: User) => {
|
|
47
|
-
return await api.put<User>(`/user/changePassword`, data)
|
|
48
|
-
.then(response => {
|
|
49
|
-
return response.data
|
|
50
|
-
})
|
|
51
|
-
.catch(error => {
|
|
52
|
-
return addError(error) })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const create = async<T,>(api: AxiosInstance, url: string, object: T) => {
|
|
56
|
-
return await api.post(`/${url}`, object)
|
|
57
|
-
.then(response => { return response.data })
|
|
58
|
-
.catch(error => { return addError(error) })
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const createAll = async<T,>(api: AxiosInstance, url: string, object: T[]) => {
|
|
62
|
-
return await api.post<T>(`/${url}/createAll`, object)
|
|
63
|
-
.then(response => { return response.data })
|
|
64
|
-
.catch(error => { return addError(error) })
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const retrieve = async<T,>(api: AxiosInstance, url: string, search?: Search, signal?: AbortSignal ) => {
|
|
68
|
-
if(search?.page === undefined && search?.size === undefined){
|
|
69
|
-
return await api.get<T>(`/${url}`)
|
|
70
|
-
.then(response => { return response.data })
|
|
71
|
-
.catch(error => { return addError(error) })
|
|
72
|
-
} else if (search?.sort?.order === undefined) {
|
|
73
|
-
return await api.get<T>(`/${url}?value=${search?.value}`, { params: { page: search?.page, size: search?.size }, signal } )
|
|
74
|
-
.then(response => { return response.data })
|
|
75
|
-
.catch(error => { return addError(error) })
|
|
76
|
-
} else {
|
|
77
|
-
return await api.get<T>(`/${url}?value=${search?.value}`, { params: { page: search?.page, size: search?.size, sort: `${search?.sort?.key},${search?.sort?.order}` }, signal } )
|
|
78
|
-
.then(response => { return response.data })
|
|
79
|
-
.catch(error => { return addError(error) })
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const update = async<T,>(api: AxiosInstance, url: string, object: T) => {
|
|
84
|
-
return await api.put<T>(`/${url}`, object)
|
|
85
|
-
.then(response => { return response.data })
|
|
86
|
-
.catch(error => { return addError(error) })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const remove = async<T,>(api: AxiosInstance, url: string, id: string) => {
|
|
90
|
-
return await api.delete<T>(`/${url}/${id}`)
|
|
91
|
-
.then(response => { return response.data })
|
|
92
|
-
.catch(error => { return addError(error) })
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const removeComposite = async<T,>(api: AxiosInstance, url: string, object: Object, one: string, two: string, three: string, four: string) => {
|
|
96
|
-
if(three !== '' && four !== ''){
|
|
97
|
-
return await api.delete<T>(`/${url}`, object)
|
|
98
|
-
.then(response => { return response.data })
|
|
99
|
-
.catch(error => { return addError(error) })
|
|
100
|
-
} else {
|
|
101
|
-
return await api.delete<T>(`/${url}/${one}/${two}`, object)
|
|
102
|
-
.then(response => { return response.data })
|
|
103
|
-
.catch(error => { return addError(error) })
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export const removeAll = async<T,>(api: AxiosInstance, url: string) => {
|
|
108
|
-
return await api.delete<T>(`/${url}`)
|
|
109
|
-
.then(response => { return response.data })
|
|
110
|
-
.catch(error => { return addError(error) });
|
|
111
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios'
|
|
2
|
-
import { Page } from '../component/response'
|
|
3
|
-
import { Search } from '../component/request'
|
|
4
|
-
|
|
5
|
-
export const FetchPage = async (api: AxiosInstance, endpoint: string, search?: Search, signal?: AbortSignal): Promise<Page> => {
|
|
6
|
-
const uri = search?.value?.trim()
|
|
7
|
-
? `/${endpoint}?value=${encodeURIComponent(search.value)}`
|
|
8
|
-
: `/${endpoint}`
|
|
9
|
-
const params: Record<string, unknown> = {
|
|
10
|
-
page: search?.page,
|
|
11
|
-
size: search?.size
|
|
12
|
-
}
|
|
13
|
-
if (search?.sort?.order && search?.sort?.key) {
|
|
14
|
-
params.sort = `${search.sort.key},${search.sort.order}`
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const { data } = await api.get<Page>(uri, {
|
|
18
|
-
params: Object.keys(params).length > 0 ? params : undefined,
|
|
19
|
-
signal
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
return data
|
|
23
|
-
}
|
package/src/service/token.tsx
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Auth, initialAuth } from '../component/auth'
|
|
2
|
-
import { Header, initialHeader, initialPayload, Payload } from '../component/token'
|
|
3
|
-
|
|
4
|
-
const isValidJSON = (json: string) => {
|
|
5
|
-
try {
|
|
6
|
-
JSON.parse(json)
|
|
7
|
-
return true
|
|
8
|
-
} catch {
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const isValidToken = (): boolean => {
|
|
14
|
-
try {
|
|
15
|
-
const token = getToken()
|
|
16
|
-
if (!token?.accessToken) return false
|
|
17
|
-
|
|
18
|
-
const { exp } = getPayload()
|
|
19
|
-
if (typeof exp !== 'number') return false
|
|
20
|
-
|
|
21
|
-
return exp * 1000 > Date.now()
|
|
22
|
-
} catch {
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const getToken = (): Auth => {
|
|
28
|
-
let token: string = `${localStorage.getItem(`token`)}`
|
|
29
|
-
return isValidJSON(token) ? JSON.parse(token) : initialAuth
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const setToken = (token: any): void => {
|
|
33
|
-
localStorage.setItem(`token`, JSON.stringify(token))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const removeToken = () => {
|
|
37
|
-
localStorage.removeItem('token')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const getPayload = (): Payload => {
|
|
41
|
-
try {
|
|
42
|
-
const token = getToken()
|
|
43
|
-
if (!token?.accessToken) return initialPayload;
|
|
44
|
-
|
|
45
|
-
const base64 = token.accessToken.split('.')[1]
|
|
46
|
-
.replace(/-/g, '+')
|
|
47
|
-
.replace(/_/g, '/')
|
|
48
|
-
|
|
49
|
-
const payload = decodeURIComponent(
|
|
50
|
-
atob(base64)
|
|
51
|
-
.split('')
|
|
52
|
-
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
53
|
-
.join('')
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
return isValidJSON(payload) ? JSON.parse(payload) : initialPayload
|
|
57
|
-
} catch {
|
|
58
|
-
return initialPayload
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const decodeJwt = () => {
|
|
63
|
-
if (getToken() !== null) {
|
|
64
|
-
var base64Url = getToken().accessToken.split('.')[1];
|
|
65
|
-
var base64 = decodeURIComponent(atob(base64Url).split('').map((c) => {
|
|
66
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
|
|
67
|
-
}).join(''))
|
|
68
|
-
return base64
|
|
69
|
-
} else {
|
|
70
|
-
return null
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const getHeader = (): Header => {
|
|
75
|
-
try {
|
|
76
|
-
const token = getToken()
|
|
77
|
-
if (!token?.accessToken) return initialHeader
|
|
78
|
-
|
|
79
|
-
const base64 = token.accessToken.split('.')[0]
|
|
80
|
-
.replace(/-/g, '+')
|
|
81
|
-
.replace(/_/g, '/')
|
|
82
|
-
|
|
83
|
-
const header = decodeURIComponent(
|
|
84
|
-
atob(base64)
|
|
85
|
-
.split('')
|
|
86
|
-
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
87
|
-
.join('')
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
return isValidJSON(header) ? JSON.parse(header) : initialHeader
|
|
91
|
-
} catch {
|
|
92
|
-
return initialHeader
|
|
93
|
-
}
|
|
94
|
-
}
|