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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type of CACCL's send request function
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
declare type SendRequestFunction = (opts: {
|
|
6
|
+
path: string;
|
|
7
|
+
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
8
|
+
params?: {
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
} | undefined;
|
|
11
|
+
headers?: {
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
} | undefined;
|
|
14
|
+
numRetries?: number | undefined;
|
|
15
|
+
}) => Promise<{
|
|
16
|
+
body: any;
|
|
17
|
+
status: number;
|
|
18
|
+
headers: {
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the send request function
|
|
24
|
+
* @author Gabe Abrams
|
|
25
|
+
* @returns sendRequest function
|
|
26
|
+
*/
|
|
27
|
+
export declare const getSendRequest: () => Promise<SendRequestFunction>;
|
|
28
|
+
declare let sessionExpiredMessage: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Get the custom session expired message
|
|
31
|
+
* @author Gabe Abrams
|
|
32
|
+
* @returns session expired message
|
|
33
|
+
*/
|
|
34
|
+
export declare const getSessionExpiredMessage: () => string;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the client-side version of reactkit
|
|
37
|
+
* @author Gabe Abrams
|
|
38
|
+
* @param opts object containing all arguments
|
|
39
|
+
* @param opts.sendRequest caccl send request functions
|
|
40
|
+
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
41
|
+
*/
|
|
42
|
+
declare const initClient: (opts: {
|
|
43
|
+
sendRequest: SendRequestFunction;
|
|
44
|
+
sessionExpiredMessage?: string;
|
|
45
|
+
}) => void;
|
|
46
|
+
export default initClient;
|
|
@@ -7,34 +7,8 @@ import React from 'react';
|
|
|
7
7
|
import Variant from '../types/Variant';
|
|
8
8
|
declare type Props = {
|
|
9
9
|
children: React.ReactNode;
|
|
10
|
-
sendRequest: SendRequestFunction;
|
|
11
10
|
dark?: boolean;
|
|
12
|
-
sessionExpiredMessage?: string;
|
|
13
11
|
};
|
|
14
|
-
declare type SendRequestFunction = (opts: {
|
|
15
|
-
path: string;
|
|
16
|
-
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
17
|
-
params?: {
|
|
18
|
-
[x: string]: any;
|
|
19
|
-
} | undefined;
|
|
20
|
-
headers?: {
|
|
21
|
-
[x: string]: any;
|
|
22
|
-
} | undefined;
|
|
23
|
-
numRetries?: number | undefined;
|
|
24
|
-
}) => Promise<{
|
|
25
|
-
body: any;
|
|
26
|
-
status: number;
|
|
27
|
-
headers: {
|
|
28
|
-
[x: string]: any;
|
|
29
|
-
};
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* Send a request using caccl's send request feature
|
|
33
|
-
* @author Gabe Abrams
|
|
34
|
-
* @param opts send request options
|
|
35
|
-
* @returns send request response
|
|
36
|
-
*/
|
|
37
|
-
export declare const cacclSendRequest: SendRequestFunction;
|
|
38
12
|
/**
|
|
39
13
|
* Show an alert modal with an "Okay" button
|
|
40
14
|
* @author Gabe Abrams
|
|
@@ -21,6 +21,7 @@ import MINUTE_IN_MS from './constants/MINUTE_IN_MS';
|
|
|
21
21
|
import HOUR_IN_MS from './constants/HOUR_IN_MS';
|
|
22
22
|
import DAY_IN_MS from './constants/DAY_IN_MS';
|
|
23
23
|
import DynamicWord from './dynamicConstants/DynamicWord';
|
|
24
|
+
import initClient from './client/initClient';
|
|
24
25
|
import abbreviate from './helpers/abbreviate';
|
|
25
26
|
import avg from './helpers/avg';
|
|
26
27
|
import ceilToNumDecimals from './helpers/ceilToNumDecimals';
|
|
@@ -68,4 +69,4 @@ import LogBuiltInMetadata from './types/LogBuiltInMetadata';
|
|
|
68
69
|
import LogMetadataType from './types/LogMetadataType';
|
|
69
70
|
import IntelliTableColumn from './types/IntelliTableColumn';
|
|
70
71
|
import PickableItem from './components/ItemPicker/types/PickableItem';
|
|
71
|
-
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, visitServerEndpoint, logClientEvent, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, ParamType, };
|
|
72
|
+
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, initClient, visitServerEndpoint, logClientEvent, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, ParamType, };
|
|
@@ -13,6 +13,8 @@ declare enum ReactKitErrorCode {
|
|
|
13
13
|
NoCACCLGetLaunchInfoFunction = "DRK8",
|
|
14
14
|
NotTTM = "DRK9",
|
|
15
15
|
NotAdmin = "DRK10",
|
|
16
|
-
NotAllowedToReviewLogs = "DRK11"
|
|
16
|
+
NotAllowedToReviewLogs = "DRK11",
|
|
17
|
+
ThemeCheckedBeforeReactKitReady = "DRK12",
|
|
18
|
+
SessionExpiredMessageGottenBeforeReactKitReady = "DRK13"
|
|
17
19
|
}
|
|
18
20
|
export default ReactKitErrorCode;
|
package/dist/index.d.ts
CHANGED
|
@@ -24,27 +24,8 @@ declare enum Variant {
|
|
|
24
24
|
|
|
25
25
|
declare type Props$g = {
|
|
26
26
|
children: React.ReactNode;
|
|
27
|
-
sendRequest: SendRequestFunction;
|
|
28
27
|
dark?: boolean;
|
|
29
|
-
sessionExpiredMessage?: string;
|
|
30
28
|
};
|
|
31
|
-
declare type SendRequestFunction = (opts: {
|
|
32
|
-
path: string;
|
|
33
|
-
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
34
|
-
params?: {
|
|
35
|
-
[x: string]: any;
|
|
36
|
-
} | undefined;
|
|
37
|
-
headers?: {
|
|
38
|
-
[x: string]: any;
|
|
39
|
-
} | undefined;
|
|
40
|
-
numRetries?: number | undefined;
|
|
41
|
-
}) => Promise<{
|
|
42
|
-
body: any;
|
|
43
|
-
status: number;
|
|
44
|
-
headers: {
|
|
45
|
-
[x: string]: any;
|
|
46
|
-
};
|
|
47
|
-
}>;
|
|
48
29
|
/**
|
|
49
30
|
* Show an alert modal with an "Okay" button
|
|
50
31
|
* @author Gabe Abrams
|
|
@@ -523,6 +504,39 @@ declare const DynamicWord: {
|
|
|
523
504
|
DeviceCapitalized: string;
|
|
524
505
|
};
|
|
525
506
|
|
|
507
|
+
/**
|
|
508
|
+
* Type of CACCL's send request function
|
|
509
|
+
* @author Gabe Abrams
|
|
510
|
+
*/
|
|
511
|
+
declare type SendRequestFunction = (opts: {
|
|
512
|
+
path: string;
|
|
513
|
+
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
514
|
+
params?: {
|
|
515
|
+
[x: string]: any;
|
|
516
|
+
} | undefined;
|
|
517
|
+
headers?: {
|
|
518
|
+
[x: string]: any;
|
|
519
|
+
} | undefined;
|
|
520
|
+
numRetries?: number | undefined;
|
|
521
|
+
}) => Promise<{
|
|
522
|
+
body: any;
|
|
523
|
+
status: number;
|
|
524
|
+
headers: {
|
|
525
|
+
[x: string]: any;
|
|
526
|
+
};
|
|
527
|
+
}>;
|
|
528
|
+
/**
|
|
529
|
+
* Initialize the client-side version of reactkit
|
|
530
|
+
* @author Gabe Abrams
|
|
531
|
+
* @param opts object containing all arguments
|
|
532
|
+
* @param opts.sendRequest caccl send request functions
|
|
533
|
+
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
534
|
+
*/
|
|
535
|
+
declare const initClient: (opts: {
|
|
536
|
+
sendRequest: SendRequestFunction;
|
|
537
|
+
sessionExpiredMessage?: string;
|
|
538
|
+
}) => void;
|
|
539
|
+
|
|
526
540
|
/**
|
|
527
541
|
* Shorten text so it fits into a certain number of chars
|
|
528
542
|
* @author Gabe Abrams
|
|
@@ -1064,7 +1078,9 @@ declare enum ReactKitErrorCode {
|
|
|
1064
1078
|
NoCACCLGetLaunchInfoFunction = "DRK8",
|
|
1065
1079
|
NotTTM = "DRK9",
|
|
1066
1080
|
NotAdmin = "DRK10",
|
|
1067
|
-
NotAllowedToReviewLogs = "DRK11"
|
|
1081
|
+
NotAllowedToReviewLogs = "DRK11",
|
|
1082
|
+
ThemeCheckedBeforeReactKitReady = "DRK12",
|
|
1083
|
+
SessionExpiredMessageGottenBeforeReactKitReady = "DRK13"
|
|
1068
1084
|
}
|
|
1069
1085
|
|
|
1070
1086
|
/**
|
|
@@ -1097,4 +1113,4 @@ declare const LogBuiltInMetadata: {
|
|
|
1097
1113
|
};
|
|
1098
1114
|
};
|
|
1099
1115
|
|
|
1100
|
-
export { AppWrapper, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, Variant, abbreviate, alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genRouteHandler, getHumanReadableDate, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, initLogCollection, initServer, isMobileOrTablet, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
|
1116
|
+
export { AppWrapper, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, Variant, abbreviate, alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genRouteHandler, getHumanReadableDate, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, initClient, initLogCollection, initServer, isMobileOrTablet, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
package/package.json
CHANGED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Import other components
|
|
2
|
+
import { showFatalError } from '../components/AppWrapper';
|
|
3
|
+
|
|
4
|
+
// Import shared types
|
|
5
|
+
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
6
|
+
import waitMs from '../helpers/waitMs';
|
|
7
|
+
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/*----------------------------------------*/
|
|
11
|
+
/* ---------------- Types --------------- */
|
|
12
|
+
/*----------------------------------------*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type of CACCL's send request function
|
|
16
|
+
* @author Gabe Abrams
|
|
17
|
+
*/
|
|
18
|
+
type SendRequestFunction = (
|
|
19
|
+
opts: {
|
|
20
|
+
path: string;
|
|
21
|
+
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
22
|
+
params?: {
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
} | undefined;
|
|
25
|
+
headers?: {
|
|
26
|
+
[x: string]: any;
|
|
27
|
+
} | undefined;
|
|
28
|
+
numRetries?: number | undefined;
|
|
29
|
+
},
|
|
30
|
+
) => Promise<{
|
|
31
|
+
body: any;
|
|
32
|
+
status: number;
|
|
33
|
+
headers: {
|
|
34
|
+
[x: string]: any;
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
/*----------------------------------------*/
|
|
39
|
+
/* ---- Static Variables and Getters ---- */
|
|
40
|
+
/*----------------------------------------*/
|
|
41
|
+
|
|
42
|
+
/* ----------- Initialized ---------- */
|
|
43
|
+
|
|
44
|
+
let onInitialized: (a: unknown) => void;
|
|
45
|
+
let initialized = new Promise((resolve) => {
|
|
46
|
+
onInitialized = resolve;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/* ---------- Send Request ---------- */
|
|
50
|
+
|
|
51
|
+
let storedSendRequest: SendRequestFunction;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the send request function
|
|
55
|
+
* @author Gabe Abrams
|
|
56
|
+
* @returns sendRequest function
|
|
57
|
+
*/
|
|
58
|
+
export const getSendRequest = async () => {
|
|
59
|
+
// Wait for initialization or timeout
|
|
60
|
+
let timedOut = false;
|
|
61
|
+
await Promise.all([
|
|
62
|
+
(async () => {
|
|
63
|
+
await waitMs(1000);
|
|
64
|
+
timedOut = true;
|
|
65
|
+
})(),
|
|
66
|
+
initialized,
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
// Error if no send request function
|
|
70
|
+
if (timedOut) {
|
|
71
|
+
showFatalError(
|
|
72
|
+
new ErrorWithCode(
|
|
73
|
+
'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.',
|
|
74
|
+
ReactKitErrorCode.NoCACCLSendRequestFunction,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Return dummy function that never resolves
|
|
79
|
+
return (
|
|
80
|
+
() => {
|
|
81
|
+
return new Promise(() => {});
|
|
82
|
+
}
|
|
83
|
+
) as SendRequestFunction;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Return
|
|
87
|
+
return storedSendRequest;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/* ----- Session Expired Message ---- */
|
|
91
|
+
|
|
92
|
+
let sessionExpiredMessage: string | undefined;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the custom session expired message
|
|
96
|
+
* @author Gabe Abrams
|
|
97
|
+
* @returns session expired message
|
|
98
|
+
*/
|
|
99
|
+
export const getSessionExpiredMessage = () => {
|
|
100
|
+
// Return
|
|
101
|
+
return (
|
|
102
|
+
sessionExpiredMessage
|
|
103
|
+
?? 'Your session has expired. Please go back to Canvas and start over.'
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/*----------------------------------------*/
|
|
108
|
+
/* ---------------- Init ---------------- */
|
|
109
|
+
/*----------------------------------------*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Initialize the client-side version of reactkit
|
|
113
|
+
* @author Gabe Abrams
|
|
114
|
+
* @param opts object containing all arguments
|
|
115
|
+
* @param opts.sendRequest caccl send request functions
|
|
116
|
+
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
117
|
+
*/
|
|
118
|
+
const initClient = (
|
|
119
|
+
opts: {
|
|
120
|
+
// Copy of CACCL's send request function
|
|
121
|
+
sendRequest: SendRequestFunction,
|
|
122
|
+
// Custom session expired message
|
|
123
|
+
sessionExpiredMessage?: string,
|
|
124
|
+
},
|
|
125
|
+
) => {
|
|
126
|
+
// Store values
|
|
127
|
+
storedSendRequest = opts.sendRequest;
|
|
128
|
+
sessionExpiredMessage = opts.sessionExpiredMessage;
|
|
129
|
+
|
|
130
|
+
// Mark as initialized
|
|
131
|
+
onInitialized(null);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default initClient;
|
|
@@ -15,14 +15,19 @@ import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
|
15
15
|
import ModalButtonType from '../types/ModalButtonType';
|
|
16
16
|
import ModalType from '../types/ModalType';
|
|
17
17
|
import Variant from '../types/Variant';
|
|
18
|
+
import LogBuiltInMetadata from '../types/LogBuiltInMetadata';
|
|
18
19
|
|
|
19
20
|
// Import shared components
|
|
20
21
|
import Modal from './Modal';
|
|
21
22
|
|
|
22
23
|
// Import custom errors
|
|
23
24
|
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
25
|
+
|
|
26
|
+
// Import other helpers
|
|
24
27
|
import logClientEvent from '../helpers/logClientEvent';
|
|
25
|
-
import
|
|
28
|
+
import {
|
|
29
|
+
getSessionExpiredMessage,
|
|
30
|
+
} from '../client/initClient';
|
|
26
31
|
|
|
27
32
|
/*------------------------------------------------------------------------*/
|
|
28
33
|
/* Props */
|
|
@@ -31,64 +36,14 @@ import LogBuiltInMetadata from '../types/LogBuiltInMetadata';
|
|
|
31
36
|
type Props = {
|
|
32
37
|
// The entire app
|
|
33
38
|
children: React.ReactNode,
|
|
34
|
-
// Copy of CACCL's send request function
|
|
35
|
-
sendRequest: SendRequestFunction,
|
|
36
39
|
// True if this app is a dark-themed app
|
|
37
40
|
dark?: boolean,
|
|
38
|
-
// Custom session expired message
|
|
39
|
-
sessionExpiredMessage?: string,
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
// Type of CACCL's send request function
|
|
43
|
-
type SendRequestFunction = (
|
|
44
|
-
opts: {
|
|
45
|
-
path: string;
|
|
46
|
-
method: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
47
|
-
params?: {
|
|
48
|
-
[x: string]: any;
|
|
49
|
-
} | undefined;
|
|
50
|
-
headers?: {
|
|
51
|
-
[x: string]: any;
|
|
52
|
-
} | undefined;
|
|
53
|
-
numRetries?: number | undefined;
|
|
54
|
-
},
|
|
55
|
-
) => Promise<{
|
|
56
|
-
body: any;
|
|
57
|
-
status: number;
|
|
58
|
-
headers: {
|
|
59
|
-
[x: string]: any;
|
|
60
|
-
};
|
|
61
|
-
}>;
|
|
62
|
-
|
|
63
43
|
/*------------------------------------------------------------------------*/
|
|
64
44
|
/* Static Helpers */
|
|
65
45
|
/*------------------------------------------------------------------------*/
|
|
66
46
|
|
|
67
|
-
/*----------------------------------------*/
|
|
68
|
-
/* Send Request */
|
|
69
|
-
/*----------------------------------------*/
|
|
70
|
-
|
|
71
|
-
// Store copy of caccl send request
|
|
72
|
-
let _cacclSendRequest: SendRequestFunction;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Send a request using caccl's send request feature
|
|
76
|
-
* @author Gabe Abrams
|
|
77
|
-
* @param opts send request options
|
|
78
|
-
* @returns send request response
|
|
79
|
-
*/
|
|
80
|
-
export const cacclSendRequest: SendRequestFunction = async (opts) => {
|
|
81
|
-
// Make sure send request has been passed in
|
|
82
|
-
if (!_cacclSendRequest) {
|
|
83
|
-
throw new ErrorWithCode(
|
|
84
|
-
`\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`,
|
|
85
|
-
ReactKitErrorCode.NoCACCLSendRequestFunction,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return _cacclSendRequest(opts);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
47
|
/*----------------------------------------*/
|
|
93
48
|
/* Alert */
|
|
94
49
|
/*----------------------------------------*/
|
|
@@ -283,14 +238,9 @@ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
|
|
|
283
238
|
|
|
284
239
|
const {
|
|
285
240
|
children,
|
|
286
|
-
sendRequest,
|
|
287
241
|
dark,
|
|
288
|
-
sessionExpiredMessage = 'Your session has expired. Please go back to Canvas and start over.',
|
|
289
242
|
} = props;
|
|
290
243
|
|
|
291
|
-
// Store copy of send request
|
|
292
|
-
_cacclSendRequest = sendRequest;
|
|
293
|
-
|
|
294
244
|
/* -------------- State ------------- */
|
|
295
245
|
|
|
296
246
|
// Fatal error
|
|
@@ -421,7 +371,7 @@ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
|
|
|
421
371
|
const error = (
|
|
422
372
|
sessionHasExpired
|
|
423
373
|
? new ErrorWithCode(
|
|
424
|
-
|
|
374
|
+
getSessionExpiredMessage(),
|
|
425
375
|
ReactKitErrorCode.SessionExpired,
|
|
426
376
|
)
|
|
427
377
|
: new ErrorWithCode(
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
3
3
|
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
4
4
|
|
|
5
|
-
// Import helpers
|
|
6
|
-
import {
|
|
5
|
+
// Import helpers
|
|
6
|
+
import { getSendRequest } from '../client/initClient';
|
|
7
7
|
|
|
8
8
|
/*------------------------------------------------------------------------*/
|
|
9
9
|
/* Listener */
|
|
@@ -138,7 +138,8 @@ const visitServerEndpoint = async (
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// Send the request
|
|
141
|
-
const
|
|
141
|
+
const sendRequest = await getSendRequest();
|
|
142
|
+
const response = await sendRequest({
|
|
142
143
|
path: opts.path,
|
|
143
144
|
method: opts.method ?? 'GET',
|
|
144
145
|
params: opts.params,
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import DAY_IN_MS from './constants/DAY_IN_MS';
|
|
|
30
30
|
import DynamicWord from './dynamicConstants/DynamicWord';
|
|
31
31
|
|
|
32
32
|
// Import helpers
|
|
33
|
+
import initClient from './client/initClient';
|
|
33
34
|
import abbreviate from './helpers/abbreviate';
|
|
34
35
|
import avg from './helpers/avg';
|
|
35
36
|
import ceilToNumDecimals from './helpers/ceilToNumDecimals';
|
|
@@ -142,6 +143,7 @@ export {
|
|
|
142
143
|
extractProp,
|
|
143
144
|
compareArraysByProp,
|
|
144
145
|
// Client helpers
|
|
146
|
+
initClient,
|
|
145
147
|
visitServerEndpoint,
|
|
146
148
|
logClientEvent,
|
|
147
149
|
// Server helpers
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Highest error code =
|
|
1
|
+
// Highest error code = DRK13
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* List of error codes built into the react kit
|
|
@@ -16,6 +16,8 @@ enum ReactKitErrorCode {
|
|
|
16
16
|
NotTTM = 'DRK9',
|
|
17
17
|
NotAdmin = 'DRK10',
|
|
18
18
|
NotAllowedToReviewLogs = 'DRK11',
|
|
19
|
+
ThemeCheckedBeforeReactKitReady = 'DRK12',
|
|
20
|
+
SessionExpiredMessageGottenBeforeReactKitReady = 'DRK13',
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export default ReactKitErrorCode;
|