dce-reactkit 3.0.0-beta.23 → 3.0.0-beta.27
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/dist/cjs/index.js +438 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +25 -0
- package/dist/cjs/types/helpers/genRouteHandler.d.ts +26 -0
- package/dist/cjs/types/helpers/handleError.d.ts +18 -0
- package/dist/cjs/types/helpers/handleSuccess.d.ts +8 -0
- package/dist/cjs/types/helpers/visitServerEndpoint.d.ts +23 -0
- package/dist/cjs/types/index.d.ts +6 -1
- package/dist/cjs/types/server/initServer.d.ts +21 -0
- package/dist/cjs/types/types/ParamType.d.ts +17 -0
- package/dist/cjs/types/types/ReactKitErrorCode.d.ts +3 -1
- package/dist/esm/index.js +433 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +25 -0
- package/dist/esm/types/helpers/genRouteHandler.d.ts +26 -0
- package/dist/esm/types/helpers/handleError.d.ts +18 -0
- package/dist/esm/types/helpers/handleSuccess.d.ts +8 -0
- package/dist/esm/types/helpers/visitServerEndpoint.d.ts +23 -0
- package/dist/esm/types/index.d.ts +6 -1
- package/dist/esm/types/server/initServer.d.ts +21 -0
- package/dist/esm/types/types/ParamType.d.ts +17 -0
- package/dist/esm/types/types/ReactKitErrorCode.d.ts +3 -1
- package/dist/index.d.ts +105 -2
- package/package.json +2 -1
- package/rollup.config.js +0 -1
- package/src/components/AppWrapper.tsx +69 -10
- package/src/helpers/genRouteHandler.ts +323 -0
- package/src/helpers/handleError.ts +65 -0
- package/src/helpers/handleSuccess.ts +18 -0
- package/src/helpers/visitServerEndpoint.tsx +110 -0
- package/src/index.ts +13 -0
- package/src/server/initServer.ts +53 -0
- package/src/types/ParamType.tsx +18 -0
- package/src/types/ReactKitErrorCode.tsx +3 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Import custom error
|
|
2
|
+
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
3
|
+
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
4
|
+
|
|
5
|
+
// Types
|
|
6
|
+
type GetLaunchInfoFunction = (req: any) => {
|
|
7
|
+
launched: boolean,
|
|
8
|
+
launchInfo?: any,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Stored copy of caccl functions
|
|
12
|
+
let _cacclGetLaunchInfo: GetLaunchInfoFunction;
|
|
13
|
+
|
|
14
|
+
/*------------------------------------------------------------------------*/
|
|
15
|
+
/* Helpers */
|
|
16
|
+
/*------------------------------------------------------------------------*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get launch info via CACCL
|
|
20
|
+
* @author Gabe Abrams
|
|
21
|
+
* @param req express request object
|
|
22
|
+
* @returns object { launched, launchInfo }
|
|
23
|
+
*/
|
|
24
|
+
export const cacclGetLaunchInfo: GetLaunchInfoFunction = (req: any) => {
|
|
25
|
+
if (!_cacclGetLaunchInfo) {
|
|
26
|
+
throw new ErrorWithCode(
|
|
27
|
+
'Could not get launch info because server was not initialized with dce-reactkit\'s initServer function',
|
|
28
|
+
ReactKitErrorCode.NoCACCLGetLaunchInfoFunction,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return _cacclGetLaunchInfo(req);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/*------------------------------------------------------------------------*/
|
|
36
|
+
/* Main */
|
|
37
|
+
/*------------------------------------------------------------------------*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Prepare dce-reactkit to run on the server
|
|
41
|
+
* @author Gabe Abrams
|
|
42
|
+
* @param opts object containing all arguments
|
|
43
|
+
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
44
|
+
*/
|
|
45
|
+
const initServer = (
|
|
46
|
+
opts: {
|
|
47
|
+
getLaunchInfo: GetLaunchInfoFunction,
|
|
48
|
+
},
|
|
49
|
+
) => {
|
|
50
|
+
_cacclGetLaunchInfo = opts.getLaunchInfo;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default initServer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side 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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Highest error code =
|
|
1
|
+
// Highest error code = DRK8
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* List of error codes built into the react kit
|
|
@@ -11,6 +11,8 @@ enum ReactKitErrorCode {
|
|
|
11
11
|
MissingParameter = 'DRK4',
|
|
12
12
|
InvalidParameter = 'DRK5',
|
|
13
13
|
WrongCourse = 'DRK6',
|
|
14
|
+
NoCACCLSendRequestFunction = 'DRK7',
|
|
15
|
+
NoCACCLGetLaunchInfoFunction = 'DRK8',
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export default ReactKitErrorCode;
|