dce-reactkit 2.0.3 → 2.0.6
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/lib/components/AppWrapper.d.ts +19 -0
- package/lib/components/AppWrapper.js +127 -0
- package/lib/components/AppWrapper.js.map +1 -0
- package/{src → lib}/components/AppWrapper.tsx +61 -7
- package/lib/components/ErrorBox.d.ts +12 -0
- package/lib/components/ErrorBox.js +65 -0
- package/lib/components/ErrorBox.js.map +1 -0
- package/{src → lib}/components/ErrorBox.tsx +4 -1
- package/{src → lib}/components/LoadingSpinner.tsx +0 -0
- package/{src → lib}/components/Modal.tsx +0 -0
- package/{src → lib}/errors/ErrorWithCode.tsx +0 -0
- package/{src → lib}/helpers/abbreviate.tsx +0 -0
- package/{src → lib}/helpers/avg.tsx +0 -0
- package/{src → lib}/helpers/ceilToNumDecimals.tsx +0 -0
- package/{src → lib}/helpers/floorToNumDecimals.tsx +0 -0
- package/{src → lib}/helpers/forceNumIntoBounds.tsx +0 -0
- package/lib/helpers/handleError.d.ts +14 -0
- package/lib/helpers/handleError.js +54 -0
- package/lib/helpers/handleError.js.map +1 -0
- package/lib/helpers/handleError.ts +65 -0
- package/lib/helpers/handleSuccess.d.ts +8 -0
- package/lib/helpers/handleSuccess.js +20 -0
- package/lib/helpers/handleSuccess.js.map +1 -0
- package/lib/helpers/handleSuccess.ts +18 -0
- package/{src → lib}/helpers/padDecimalZeros.tsx +0 -0
- package/{src → lib}/helpers/padZerosLeft.tsx +0 -0
- package/lib/helpers/parseRequest.d.ts +21 -0
- package/lib/helpers/parseRequest.js +240 -0
- package/lib/helpers/parseRequest.js.map +1 -0
- package/lib/helpers/parseRequest.ts +299 -0
- package/{src → lib}/helpers/roundToNumDecimals.tsx +0 -0
- package/lib/helpers/showFatalError.d.ts +2 -0
- package/lib/helpers/showFatalError.js +5 -0
- package/lib/helpers/showFatalError.js.map +1 -0
- package/{src → lib}/helpers/showFatalError.tsx +0 -0
- package/{src → lib}/helpers/sum.tsx +0 -0
- package/lib/helpers/visitServerEndpoint.d.ts +7 -1
- package/lib/helpers/visitServerEndpoint.js +57 -6
- package/lib/helpers/visitServerEndpoint.js.map +1 -1
- package/lib/helpers/visitServerEndpoint.tsx +110 -0
- package/{src → lib}/helpers/waitMs.tsx +0 -0
- package/lib/types/ParamType.d.ts +17 -0
- package/lib/types/ParamType.js +21 -0
- package/lib/types/ParamType.js.map +1 -0
- package/lib/types/ParamType.ts +18 -0
- package/lib/types/ReactKitErrorCode.d.ts +5 -1
- package/lib/types/ReactKitErrorCode.js +4 -0
- package/lib/types/ReactKitErrorCode.js.map +1 -1
- package/{src → lib}/types/ReactKitErrorCode.tsx +4 -0
- package/{src → lib}/types/Variant.tsx +0 -0
- package/package.json +5 -2
- package/tsconfig.json +1 -1
- package/src/helpers/visitServerEndpoint.tsx +0 -59
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Initialize caccl
|
|
2
|
+
import { sendRequest } from 'caccl/client';
|
|
3
|
+
|
|
4
|
+
// Import custom error
|
|
5
|
+
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
6
|
+
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
7
|
+
|
|
8
|
+
/*------------------------------------------------------------------------*/
|
|
9
|
+
/* Listener */
|
|
10
|
+
/*------------------------------------------------------------------------*/
|
|
11
|
+
|
|
12
|
+
// Handler for session expiry
|
|
13
|
+
let sessionExpiryHandler: () => void;
|
|
14
|
+
|
|
15
|
+
// Keep track of whether or not session expiry has already been handled
|
|
16
|
+
let sessionAlreadyExpired = false;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Set the session expiry handler
|
|
20
|
+
* @author Gabe Abrams
|
|
21
|
+
* @param handler new handler to use when session expires
|
|
22
|
+
*/
|
|
23
|
+
export const setSessionExpiryHandler = (handler: () => void) => {
|
|
24
|
+
sessionExpiryHandler = handler;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/*------------------------------------------------------------------------*/
|
|
28
|
+
/* Main */
|
|
29
|
+
/*------------------------------------------------------------------------*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Visit an endpoint on the server [for client only]
|
|
33
|
+
* @author Gabe Abrams
|
|
34
|
+
* @param opts object containing all arguments
|
|
35
|
+
* @param opts.path - the path of the server endpoint
|
|
36
|
+
* @param [opts.method=GET] - the method of the endpoint
|
|
37
|
+
* @param [opts.params] - query/body parameters to include
|
|
38
|
+
* @returns response from server
|
|
39
|
+
*/
|
|
40
|
+
const visitServerEndpoint = async (
|
|
41
|
+
opts: {
|
|
42
|
+
path: string,
|
|
43
|
+
method?: ('GET' | 'POST' | 'DELETE' | 'PUT'),
|
|
44
|
+
params?: { [key in string]: any },
|
|
45
|
+
},
|
|
46
|
+
): Promise<any> => {
|
|
47
|
+
// Send the request
|
|
48
|
+
const response = await sendRequest({
|
|
49
|
+
path: opts.path,
|
|
50
|
+
method: opts.method,
|
|
51
|
+
params: opts.params,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Check for failure
|
|
55
|
+
if (!response || !response.body) {
|
|
56
|
+
throw new ErrorWithCode(
|
|
57
|
+
'We didn\'t get a response from the server. Please check your internet connection.',
|
|
58
|
+
ReactKitErrorCode.NoResponse,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (!response.body.success) {
|
|
62
|
+
// Session expired
|
|
63
|
+
if (response.body.code === ReactKitErrorCode.SessionExpired) {
|
|
64
|
+
// Skip notice if session was already expired
|
|
65
|
+
if (sessionAlreadyExpired) {
|
|
66
|
+
// Never return (browser is already reloading)
|
|
67
|
+
await new Promise<{ [key in string]: any }>(() => {
|
|
68
|
+
// Promise that never returns
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
sessionAlreadyExpired = true;
|
|
72
|
+
|
|
73
|
+
// Show session expiration message
|
|
74
|
+
if (sessionExpiryHandler) {
|
|
75
|
+
// Use handler
|
|
76
|
+
sessionExpiryHandler();
|
|
77
|
+
} else {
|
|
78
|
+
// Fallback to alert
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line no-alert
|
|
81
|
+
alert('Your session has expired. Please start over.');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Never return (don't continue execution)
|
|
85
|
+
await new Promise<{ [key in string]: any }>(() => {
|
|
86
|
+
// Promise that never returns
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Other errors
|
|
91
|
+
throw new ErrorWithCode(
|
|
92
|
+
(
|
|
93
|
+
response.body.message
|
|
94
|
+
|| 'An unknown error occurred. Please contact an admin.'
|
|
95
|
+
),
|
|
96
|
+
(
|
|
97
|
+
response.body.code
|
|
98
|
+
|| ReactKitErrorCode.NoCode
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Success! Extract the body
|
|
104
|
+
const { body } = response.body;
|
|
105
|
+
|
|
106
|
+
// Return
|
|
107
|
+
return body;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default visitServerEndpoint;
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API param types
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
declare enum ParamType {
|
|
6
|
+
Boolean = "boolean",
|
|
7
|
+
BooleanOptional = "boolean-optional",
|
|
8
|
+
Float = "float",
|
|
9
|
+
FloatOptional = "float-optional",
|
|
10
|
+
Int = "int",
|
|
11
|
+
IntOptional = "int-optional",
|
|
12
|
+
JSON = "json",
|
|
13
|
+
JSONOptional = "json-optional",
|
|
14
|
+
String = "string",
|
|
15
|
+
StringOptional = "string-optional"
|
|
16
|
+
}
|
|
17
|
+
export default ParamType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* API param types
|
|
5
|
+
* @author Gabe Abrams
|
|
6
|
+
*/
|
|
7
|
+
var ParamType;
|
|
8
|
+
(function (ParamType) {
|
|
9
|
+
ParamType["Boolean"] = "boolean";
|
|
10
|
+
ParamType["BooleanOptional"] = "boolean-optional";
|
|
11
|
+
ParamType["Float"] = "float";
|
|
12
|
+
ParamType["FloatOptional"] = "float-optional";
|
|
13
|
+
ParamType["Int"] = "int";
|
|
14
|
+
ParamType["IntOptional"] = "int-optional";
|
|
15
|
+
ParamType["JSON"] = "json";
|
|
16
|
+
ParamType["JSONOptional"] = "json-optional";
|
|
17
|
+
ParamType["String"] = "string";
|
|
18
|
+
ParamType["StringOptional"] = "string-optional";
|
|
19
|
+
})(ParamType || (ParamType = {}));
|
|
20
|
+
exports.default = ParamType;
|
|
21
|
+
//# sourceMappingURL=ParamType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParamType.js","sourceRoot":"","sources":["../../src/types/ParamType.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,IAAK,SAWJ;AAXD,WAAK,SAAS;IACZ,gCAAmB,CAAA;IACnB,iDAAoC,CAAA;IACpC,4BAAe,CAAA;IACf,6CAAgC,CAAA;IAChC,wBAAW,CAAA;IACX,yCAA4B,CAAA;IAC5B,0BAAa,CAAA;IACb,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,+CAAkC,CAAA;AACpC,CAAC,EAXI,SAAS,KAAT,SAAS,QAWb;AAED,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API param types
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
enum ParamType {
|
|
6
|
+
Boolean = 'boolean', // Boolean
|
|
7
|
+
BooleanOptional = 'boolean-optional', // Optional boolean
|
|
8
|
+
Float = 'float', // Float Number
|
|
9
|
+
FloatOptional = 'float-optional', // Optional Float Number
|
|
10
|
+
Int = 'int', // Integer Number
|
|
11
|
+
IntOptional = 'int-optional', // Optional Integer Number
|
|
12
|
+
JSON = 'json', // JSONified object
|
|
13
|
+
JSONOptional = 'json-optional', // Optional JSONified object
|
|
14
|
+
String = 'string', // String
|
|
15
|
+
StringOptional = 'string-optional', // Optional string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default ParamType;
|
|
@@ -9,6 +9,10 @@ var ReactKitErrorCode;
|
|
|
9
9
|
(function (ReactKitErrorCode) {
|
|
10
10
|
ReactKitErrorCode["NoResponse"] = "DRK1";
|
|
11
11
|
ReactKitErrorCode["NoCode"] = "DRK2";
|
|
12
|
+
ReactKitErrorCode["SessionExpired"] = "DRK3";
|
|
13
|
+
ReactKitErrorCode["MissingParameter"] = "DRK4";
|
|
14
|
+
ReactKitErrorCode["InvalidParameter"] = "DRK5";
|
|
15
|
+
ReactKitErrorCode["WrongCourse"] = "DRK6";
|
|
12
16
|
})(ReactKitErrorCode || (ReactKitErrorCode = {}));
|
|
13
17
|
exports.default = ReactKitErrorCode;
|
|
14
18
|
//# sourceMappingURL=ReactKitErrorCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ReactKitErrorCode.tsx"],"names":[],"mappings":";AAAA,4BAA4B;;AAE5B;;;GAGG;AACH,IAAK,
|
|
1
|
+
{"version":3,"file":"ReactKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ReactKitErrorCode.tsx"],"names":[],"mappings":";AAAA,4BAA4B;;AAE5B;;;GAGG;AACH,IAAK,iBAOJ;AAPD,WAAK,iBAAiB;IACpB,wCAAmB,CAAA;IACnB,oCAAe,CAAA;IACf,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;IACzB,8CAAyB,CAAA;IACzB,yCAAoB,CAAA;AACtB,CAAC,EAPI,iBAAiB,KAAjB,iBAAiB,QAOrB;AAED,kBAAe,iBAAiB,CAAC"}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dce-reactkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "tsc --project ./tsconfig.json"
|
|
7
|
+
"build": "rimraf lib/ && tsc --project ./tsconfig.json && copyfiles -u 1 src/**/*.tsx src/**/*.ts lib/"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
"react-bootstrap": "^2.2.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/express": "^4.17.13",
|
|
25
26
|
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
26
27
|
"@typescript-eslint/parser": "^5.18.0",
|
|
28
|
+
"copyfiles": "^2.4.1",
|
|
27
29
|
"eslint": "^8.12.0",
|
|
28
30
|
"eslint-config-airbnb": "^19.0.4",
|
|
29
31
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
@@ -32,6 +34,7 @@
|
|
|
32
34
|
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
33
35
|
"eslint-plugin-react": "^7.29.4",
|
|
34
36
|
"eslint-plugin-react-hooks": "^4.4.0",
|
|
37
|
+
"rimraf": "^3.0.2",
|
|
35
38
|
"typescript": "^4.6.3"
|
|
36
39
|
}
|
|
37
40
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Initialize caccl
|
|
2
|
-
import { sendRequest } from 'caccl/client';
|
|
3
|
-
|
|
4
|
-
// Import custom error
|
|
5
|
-
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
6
|
-
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Visit an endpoint on the server
|
|
10
|
-
* @author Gabe Abrams
|
|
11
|
-
* @param opts object containing all arguments
|
|
12
|
-
* @param opts.path - the path of the server endpoint
|
|
13
|
-
* @param [opts.method=GET] - the method of the endpoint
|
|
14
|
-
* @param [opts.params] - query/body parameters to include
|
|
15
|
-
* @returns response from server
|
|
16
|
-
*/
|
|
17
|
-
const visitServerEndpoint = async (
|
|
18
|
-
opts: {
|
|
19
|
-
path: string,
|
|
20
|
-
method?: ('GET' | 'POST' | 'DELETE' | 'PUT'),
|
|
21
|
-
params?: { [key in string]: any },
|
|
22
|
-
},
|
|
23
|
-
): Promise<any> => {
|
|
24
|
-
// Send the request
|
|
25
|
-
const response = await sendRequest({
|
|
26
|
-
path: opts.path,
|
|
27
|
-
method: opts.method,
|
|
28
|
-
params: opts.params,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Check for failure
|
|
32
|
-
if (!response || !response.body) {
|
|
33
|
-
throw new ErrorWithCode(
|
|
34
|
-
'We didn\'t get a response from the server. Please check your internet connection.',
|
|
35
|
-
ReactKitErrorCode.NoResponse,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
if (!response.body.success) {
|
|
39
|
-
// Other errors
|
|
40
|
-
throw new ErrorWithCode(
|
|
41
|
-
(
|
|
42
|
-
response.body.message
|
|
43
|
-
|| 'An unknown error occurred. Please contact an admin.'
|
|
44
|
-
),
|
|
45
|
-
(
|
|
46
|
-
response.body.code
|
|
47
|
-
|| ReactKitErrorCode.NoCode
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Success! Extract the body
|
|
53
|
-
const { body } = response.body;
|
|
54
|
-
|
|
55
|
-
// Return
|
|
56
|
-
return body;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default visitServerEndpoint;
|