dce-reactkit 3.2.9 → 3.3.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/dist/cjs/index.js +91 -42
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/client/initClient.d.ts +46 -0
- package/dist/cjs/types/components/AppWrapper.d.ts +0 -26
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/types/types/ReactKitErrorCode.d.ts +3 -1
- package/dist/esm/index.js +91 -43
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/client/initClient.d.ts +46 -0
- package/dist/esm/types/components/AppWrapper.d.ts +0 -26
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/types/types/ReactKitErrorCode.d.ts +3 -1
- package/dist/index.d.ts +37 -21
- package/package.json +1 -1
- package/src/client/initClient.tsx +134 -0
- package/src/components/AppWrapper.tsx +7 -57
- package/src/helpers/visitServerEndpoint.tsx +4 -3
- package/src/index.ts +2 -0
- package/src/types/ReactKitErrorCode.tsx +3 -1
package/dist/cjs/index.js
CHANGED
|
@@ -36,7 +36,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// Highest error code =
|
|
39
|
+
// Highest error code = DRK13
|
|
40
40
|
/**
|
|
41
41
|
* List of error codes built into the react kit
|
|
42
42
|
* @author Gabe Abrams
|
|
@@ -54,6 +54,8 @@ var ReactKitErrorCode;
|
|
|
54
54
|
ReactKitErrorCode["NotTTM"] = "DRK9";
|
|
55
55
|
ReactKitErrorCode["NotAdmin"] = "DRK10";
|
|
56
56
|
ReactKitErrorCode["NotAllowedToReviewLogs"] = "DRK11";
|
|
57
|
+
ReactKitErrorCode["ThemeCheckedBeforeReactKitReady"] = "DRK12";
|
|
58
|
+
ReactKitErrorCode["SessionExpiredMessageGottenBeforeReactKitReady"] = "DRK13";
|
|
57
59
|
})(ReactKitErrorCode || (ReactKitErrorCode = {}));
|
|
58
60
|
var ReactKitErrorCode$1 = ReactKitErrorCode;
|
|
59
61
|
|
|
@@ -149,6 +151,24 @@ var ModalType;
|
|
|
149
151
|
})(ModalType || (ModalType = {}));
|
|
150
152
|
var ModalType$1 = ModalType;
|
|
151
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Built-in metadata for logs
|
|
156
|
+
* @author Gabe Abrams
|
|
157
|
+
*/
|
|
158
|
+
const LogBuiltInMetadata = {
|
|
159
|
+
// Contexts
|
|
160
|
+
Context: {
|
|
161
|
+
Uncategorized: 'Uncategorized',
|
|
162
|
+
ServerRenderedErrorPage: 'ServerRenderedErrorPage',
|
|
163
|
+
ServerEndpointError: 'ServerEndpointError',
|
|
164
|
+
ClientFatalError: 'ClientFatalError',
|
|
165
|
+
},
|
|
166
|
+
// Targets
|
|
167
|
+
Target: {
|
|
168
|
+
NoTarget: 'NoTarget',
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
152
172
|
/**
|
|
153
173
|
* Wait for a certain number of ms
|
|
154
174
|
* @author Gabe Abrams
|
|
@@ -512,24 +532,6 @@ const ROUTE_PATH_PREFIX = '/dce-reactkit';
|
|
|
512
532
|
*/
|
|
513
533
|
const LOG_ROUTE_PATH = `${ROUTE_PATH_PREFIX}/log`;
|
|
514
534
|
|
|
515
|
-
/**
|
|
516
|
-
* Built-in metadata for logs
|
|
517
|
-
* @author Gabe Abrams
|
|
518
|
-
*/
|
|
519
|
-
const LogBuiltInMetadata = {
|
|
520
|
-
// Contexts
|
|
521
|
-
Context: {
|
|
522
|
-
Uncategorized: 'Uncategorized',
|
|
523
|
-
ServerRenderedErrorPage: 'ServerRenderedErrorPage',
|
|
524
|
-
ServerEndpointError: 'ServerEndpointError',
|
|
525
|
-
ClientFatalError: 'ClientFatalError',
|
|
526
|
-
},
|
|
527
|
-
// Targets
|
|
528
|
-
Target: {
|
|
529
|
-
NoTarget: 'NoTarget',
|
|
530
|
-
},
|
|
531
|
-
};
|
|
532
|
-
|
|
533
535
|
/**
|
|
534
536
|
* Allowed log levels
|
|
535
537
|
* @author Gabe Abrams
|
|
@@ -542,6 +544,71 @@ var LogLevel;
|
|
|
542
544
|
})(LogLevel || (LogLevel = {}));
|
|
543
545
|
var LogLevel$1 = LogLevel;
|
|
544
546
|
|
|
547
|
+
/*----------------------------------------*/
|
|
548
|
+
/* ---- Static Variables and Getters ---- */
|
|
549
|
+
/*----------------------------------------*/
|
|
550
|
+
/* ----------- Initialized ---------- */
|
|
551
|
+
let onInitialized;
|
|
552
|
+
let initialized = new Promise((resolve) => {
|
|
553
|
+
onInitialized = resolve;
|
|
554
|
+
});
|
|
555
|
+
/* ---------- Send Request ---------- */
|
|
556
|
+
let storedSendRequest;
|
|
557
|
+
/**
|
|
558
|
+
* Get the send request function
|
|
559
|
+
* @author Gabe Abrams
|
|
560
|
+
* @returns sendRequest function
|
|
561
|
+
*/
|
|
562
|
+
const getSendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
563
|
+
// Wait for initialization or timeout
|
|
564
|
+
let timedOut = false;
|
|
565
|
+
yield Promise.all([
|
|
566
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
567
|
+
yield waitMs(1000);
|
|
568
|
+
timedOut = true;
|
|
569
|
+
}))(),
|
|
570
|
+
initialized,
|
|
571
|
+
]);
|
|
572
|
+
// Error if no send request function
|
|
573
|
+
if (timedOut) {
|
|
574
|
+
showFatalError(new ErrorWithCode('Could not send a request because the request needed to be sent before dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.NoCACCLSendRequestFunction));
|
|
575
|
+
// Return dummy function that never resolves
|
|
576
|
+
return (() => {
|
|
577
|
+
return new Promise(() => { });
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
// Return
|
|
581
|
+
return storedSendRequest;
|
|
582
|
+
});
|
|
583
|
+
/* ----- Session Expired Message ---- */
|
|
584
|
+
let sessionExpiredMessage;
|
|
585
|
+
/**
|
|
586
|
+
* Get the custom session expired message
|
|
587
|
+
* @author Gabe Abrams
|
|
588
|
+
* @returns session expired message
|
|
589
|
+
*/
|
|
590
|
+
const getSessionExpiredMessage = () => {
|
|
591
|
+
// Return
|
|
592
|
+
return (sessionExpiredMessage !== null && sessionExpiredMessage !== void 0 ? sessionExpiredMessage : 'Your session has expired. Please go back to Canvas and start over.');
|
|
593
|
+
};
|
|
594
|
+
/*----------------------------------------*/
|
|
595
|
+
/* ---------------- Init ---------------- */
|
|
596
|
+
/*----------------------------------------*/
|
|
597
|
+
/**
|
|
598
|
+
* Initialize the client-side version of reactkit
|
|
599
|
+
* @author Gabe Abrams
|
|
600
|
+
* @param opts object containing all arguments
|
|
601
|
+
* @param opts.sendRequest caccl send request functions
|
|
602
|
+
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
603
|
+
*/
|
|
604
|
+
const initClient = (opts) => {
|
|
605
|
+
// Store values
|
|
606
|
+
storedSendRequest = opts.sendRequest;
|
|
607
|
+
sessionExpiredMessage = opts.sessionExpiredMessage;
|
|
608
|
+
// Mark as initialized
|
|
609
|
+
onInitialized(null);
|
|
610
|
+
};
|
|
611
|
+
|
|
545
612
|
// Keep track of whether or not session expiry has already been handled
|
|
546
613
|
let sessionAlreadyExpired = false;
|
|
547
614
|
/*------------------------------------------------------------------------*/
|
|
@@ -613,7 +680,8 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
|
|
|
613
680
|
throw new ErrorWithCode(stubResponse.errorMessage, stubResponse.errorCode);
|
|
614
681
|
}
|
|
615
682
|
// Send the request
|
|
616
|
-
const
|
|
683
|
+
const sendRequest = yield getSendRequest();
|
|
684
|
+
const response = yield sendRequest({
|
|
617
685
|
path: opts.path,
|
|
618
686
|
method: (_c = opts.method) !== null && _c !== void 0 ? _c : 'GET',
|
|
619
687
|
params: opts.params,
|
|
@@ -700,24 +768,6 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
700
768
|
/* Static Helpers */
|
|
701
769
|
/*------------------------------------------------------------------------*/
|
|
702
770
|
/*----------------------------------------*/
|
|
703
|
-
/* Send Request */
|
|
704
|
-
/*----------------------------------------*/
|
|
705
|
-
// Store copy of caccl send request
|
|
706
|
-
let _cacclSendRequest;
|
|
707
|
-
/**
|
|
708
|
-
* Send a request using caccl's send request feature
|
|
709
|
-
* @author Gabe Abrams
|
|
710
|
-
* @param opts send request options
|
|
711
|
-
* @returns send request response
|
|
712
|
-
*/
|
|
713
|
-
const cacclSendRequest = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
714
|
-
// Make sure send request has been passed in
|
|
715
|
-
if (!_cacclSendRequest) {
|
|
716
|
-
throw new ErrorWithCode(`\nThe request could not be sent because the AppWrapper component does not have a copy of sendRequest from CACCL.\nIf you are currently writing tests for your app, this means you did not properly stub the server response.\nMethod: ${opts.method}\nPath: ${opts.path}\n\n`, ReactKitErrorCode$1.NoCACCLSendRequestFunction);
|
|
717
|
-
}
|
|
718
|
-
return _cacclSendRequest(opts);
|
|
719
|
-
});
|
|
720
|
-
/*----------------------------------------*/
|
|
721
771
|
/* Alert */
|
|
722
772
|
/*----------------------------------------*/
|
|
723
773
|
// Stored copies of setters
|
|
@@ -841,9 +891,7 @@ const AppWrapper = (props) => {
|
|
|
841
891
|
/* Setup */
|
|
842
892
|
/*------------------------------------------------------------------------*/
|
|
843
893
|
/* -------------- Props ------------- */
|
|
844
|
-
const { children,
|
|
845
|
-
// Store copy of send request
|
|
846
|
-
_cacclSendRequest = sendRequest;
|
|
894
|
+
const { children, dark, } = props;
|
|
847
895
|
/* -------------- State ------------- */
|
|
848
896
|
// Fatal error
|
|
849
897
|
const [fatalErrorMessage, setFatalErrorMessageInner,] = React.useState();
|
|
@@ -896,7 +944,7 @@ const AppWrapper = (props) => {
|
|
|
896
944
|
if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
|
|
897
945
|
// Re-encapsulate in an error
|
|
898
946
|
const error = (sessionHasExpired
|
|
899
|
-
? new ErrorWithCode(
|
|
947
|
+
? new ErrorWithCode(getSessionExpiredMessage(), ReactKitErrorCode$1.SessionExpired)
|
|
900
948
|
: new ErrorWithCode((fatalErrorMessage !== null && fatalErrorMessage !== void 0 ? fatalErrorMessage : 'An unknown error has occurred. Please contact support.'), (fatalErrorCode !== null && fatalErrorCode !== void 0 ? fatalErrorCode : ReactKitErrorCode$1.NoCode)));
|
|
901
949
|
// Build error screen
|
|
902
950
|
body = (React__default["default"].createElement("div", { style: {
|
|
@@ -5650,6 +5698,7 @@ exports.getPartOfDay = getPartOfDay;
|
|
|
5650
5698
|
exports.getTimeInfoInET = getTimeInfoInET;
|
|
5651
5699
|
exports.handleError = handleError;
|
|
5652
5700
|
exports.handleSuccess = handleSuccess;
|
|
5701
|
+
exports.initClient = initClient;
|
|
5653
5702
|
exports.initLogCollection = initLogCollection;
|
|
5654
5703
|
exports.initServer = initServer;
|
|
5655
5704
|
exports.isMobileOrTablet = isMobileOrTablet;
|