dce-reactkit 3.0.0-beta.3 → 3.0.0-beta.32
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/.eslintrc.js +95 -0
- package/README.md +1 -546
- package/dist/cjs/index.js +787 -35684
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +26 -1
- package/dist/cjs/types/components/TabBox.d.ts +1 -0
- package/dist/cjs/types/helpers/genRouteHandler.d.ts +30 -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 +7 -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 +717 -35602
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +26 -1
- package/dist/esm/types/components/TabBox.d.ts +1 -0
- package/dist/esm/types/helpers/genRouteHandler.d.ts +30 -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 +7 -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 +125 -3
- package/package.json +13 -3
- package/rollup.config.js +0 -1
- package/src/components/AppWrapper.tsx +72 -12
- package/src/components/ErrorBox.tsx +4 -4
- package/src/components/LoadingSpinner.tsx +3 -3
- package/src/components/Modal.tsx +214 -97
- package/src/components/TabBox.tsx +65 -58
- package/src/helpers/genRouteHandler.ts +326 -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 +15 -0
- package/src/server/initServer.ts +53 -0
- package/src/types/ParamType.tsx +18 -0
- package/src/types/ReactKitErrorCode.tsx +3 -1
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A wrapper for the entire React app that adds global functionality like
|
|
3
|
-
* handling for fatal error messages
|
|
3
|
+
* handling for fatal error messages, adds bootstrap support
|
|
4
4
|
* @author Gabe Abrams
|
|
5
5
|
*/
|
|
6
6
|
import React from 'react';
|
|
7
7
|
declare type Props = {
|
|
8
8
|
children: React.ReactNode;
|
|
9
|
+
sendRequest: SendRequestFunction;
|
|
9
10
|
dark?: boolean;
|
|
10
11
|
sessionExpiredMessage?: string;
|
|
11
12
|
};
|
|
13
|
+
declare type SendRequestFunction = (opts: {
|
|
14
|
+
path: string;
|
|
15
|
+
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
16
|
+
params?: {
|
|
17
|
+
[x: string]: any;
|
|
18
|
+
} | undefined;
|
|
19
|
+
headers?: {
|
|
20
|
+
[x: string]: any;
|
|
21
|
+
} | undefined;
|
|
22
|
+
numRetries?: number | undefined;
|
|
23
|
+
}) => Promise<{
|
|
24
|
+
body: any;
|
|
25
|
+
status: number;
|
|
26
|
+
headers: {
|
|
27
|
+
[x: string]: any;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Send a request using caccl's send request feature
|
|
32
|
+
* @author Gabe Abrams
|
|
33
|
+
* @param opts send request options
|
|
34
|
+
* @returns send request response
|
|
35
|
+
*/
|
|
36
|
+
export declare const cacclSendRequest: SendRequestFunction;
|
|
12
37
|
/**
|
|
13
38
|
* Show an alert modal with an "Okay" button
|
|
14
39
|
* @author Gabe Abrams
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import ParamType from '../types/ParamType';
|
|
2
|
+
import handleError from './handleError';
|
|
3
|
+
import handleSuccess from './handleSuccess';
|
|
4
|
+
/**
|
|
5
|
+
* Generate an express API route handler
|
|
6
|
+
* @author Gabe Abrams
|
|
7
|
+
* @param opts object containing all arguments
|
|
8
|
+
* @param opts.paramTypes map containing the types for each parameter that is
|
|
9
|
+
* included in the request (map: param name => type)
|
|
10
|
+
* @param opts.handler function that processes the request
|
|
11
|
+
* @returns express route handler that takes the following arguments:
|
|
12
|
+
* params (map: param name => value), handleSuccess (function for handling
|
|
13
|
+
* successful requests), handleError (function for handling failed requests),
|
|
14
|
+
* req (express request object), res (express response object)
|
|
15
|
+
*/
|
|
16
|
+
declare const genRouteHandler: (opts: {
|
|
17
|
+
paramTypes?: {
|
|
18
|
+
[k: string]: ParamType;
|
|
19
|
+
} | undefined;
|
|
20
|
+
handler: (opts: {
|
|
21
|
+
params: {
|
|
22
|
+
[k: string]: any;
|
|
23
|
+
};
|
|
24
|
+
handleSuccess: (body: any) => void;
|
|
25
|
+
handleError: (error: any) => void;
|
|
26
|
+
req: any;
|
|
27
|
+
res: any;
|
|
28
|
+
}) => void;
|
|
29
|
+
}) => (req: any, res: any) => Promise<undefined>;
|
|
30
|
+
export default genRouteHandler;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handle an error and respond to the client
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param res express response
|
|
5
|
+
* @param error error info
|
|
6
|
+
* @param opts.err the error to send to the client
|
|
7
|
+
* or the error message
|
|
8
|
+
* @param [opts.code] an error code (only used if err.code is not
|
|
9
|
+
* included)
|
|
10
|
+
* @param [opts.status=500] the https status code to use
|
|
11
|
+
* defined)
|
|
12
|
+
*/
|
|
13
|
+
declare const handleError: (res: any, error: ({
|
|
14
|
+
message: any;
|
|
15
|
+
code?: string;
|
|
16
|
+
status?: number;
|
|
17
|
+
} | Error | string | any)) => undefined;
|
|
18
|
+
export default handleError;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set the session expiry handler
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param handler new handler to use when session expires
|
|
5
|
+
*/
|
|
6
|
+
export declare const setSessionExpiryHandler: (handler: () => void) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Visit an endpoint on the server [for client only]
|
|
9
|
+
* @author Gabe Abrams
|
|
10
|
+
* @param opts object containing all arguments
|
|
11
|
+
* @param opts.path - the path of the server endpoint
|
|
12
|
+
* @param [opts.method=GET] - the method of the endpoint
|
|
13
|
+
* @param [opts.params] - query/body parameters to include
|
|
14
|
+
* @returns response from server
|
|
15
|
+
*/
|
|
16
|
+
declare const visitServerEndpoint: (opts: {
|
|
17
|
+
path: string;
|
|
18
|
+
method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
|
|
19
|
+
params?: {
|
|
20
|
+
[x: string]: any;
|
|
21
|
+
} | undefined;
|
|
22
|
+
}) => Promise<any>;
|
|
23
|
+
export default visitServerEndpoint;
|
|
@@ -14,9 +14,15 @@ import padZerosLeft from './helpers/padZerosLeft';
|
|
|
14
14
|
import roundToNumDecimals from './helpers/roundToNumDecimals';
|
|
15
15
|
import sum from './helpers/sum';
|
|
16
16
|
import waitMs from './helpers/waitMs';
|
|
17
|
+
import visitServerEndpoint from './helpers/visitServerEndpoint';
|
|
18
|
+
import genRouteHandler from './helpers/genRouteHandler';
|
|
19
|
+
import handleError from './helpers/handleError';
|
|
20
|
+
import handleSuccess from './helpers/handleSuccess';
|
|
21
|
+
import initServer from './server/initServer';
|
|
17
22
|
import ModalButtonType from './types/ModalButtonType';
|
|
18
23
|
import ModalSize from './types/ModalSize';
|
|
19
24
|
import ModalType from './types/ModalType';
|
|
20
25
|
import ReactKitErrorCode from './types/ReactKitErrorCode';
|
|
21
26
|
import Variant from './types/Variant';
|
|
22
|
-
|
|
27
|
+
import ParamType from './types/ParamType';
|
|
28
|
+
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, alert, confirm, showFatalError, ErrorWithCode, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, visitServerEndpoint, initServer, genRouteHandler, handleError, handleSuccess, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, ParamType, };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare type GetLaunchInfoFunction = (req: any) => {
|
|
2
|
+
launched: boolean;
|
|
3
|
+
launchInfo?: any;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Get launch info via CACCL
|
|
7
|
+
* @author Gabe Abrams
|
|
8
|
+
* @param req express request object
|
|
9
|
+
* @returns object { launched, launchInfo }
|
|
10
|
+
*/
|
|
11
|
+
export declare const cacclGetLaunchInfo: GetLaunchInfoFunction;
|
|
12
|
+
/**
|
|
13
|
+
* Prepare dce-reactkit to run on the server
|
|
14
|
+
* @author Gabe Abrams
|
|
15
|
+
* @param opts object containing all arguments
|
|
16
|
+
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
17
|
+
*/
|
|
18
|
+
declare const initServer: (opts: {
|
|
19
|
+
getLaunchInfo: GetLaunchInfoFunction;
|
|
20
|
+
}) => void;
|
|
21
|
+
export default initServer;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side 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;
|
|
@@ -8,6 +8,8 @@ declare enum ReactKitErrorCode {
|
|
|
8
8
|
SessionExpired = "DRK3",
|
|
9
9
|
MissingParameter = "DRK4",
|
|
10
10
|
InvalidParameter = "DRK5",
|
|
11
|
-
WrongCourse = "DRK6"
|
|
11
|
+
WrongCourse = "DRK6",
|
|
12
|
+
NoCACCLSendRequestFunction = "DRK7",
|
|
13
|
+
NoCACCLGetLaunchInfoFunction = "DRK8"
|
|
12
14
|
}
|
|
13
15
|
export default ReactKitErrorCode;
|