dce-reactkit 3.12.3 → 4.0.0-beta-date-and-time.1

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.
Files changed (69) hide show
  1. package/dist/cjs/index.js +5338 -5515
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/components/LoadingSpinner.d.ts +2 -2
  4. package/dist/cjs/types/components/SimpleDateChooser.d.ts +3 -1
  5. package/dist/cjs/types/components/SimpleTimeChooser.d.ts +20 -0
  6. package/dist/cjs/types/components/Tooltip.d.ts +1 -1
  7. package/dist/cjs/types/index.d.ts +12 -11
  8. package/dist/cjs/types/types/ParamType.d.ts +10 -10
  9. package/dist/cjs/types/types/ReactKitErrorCode.d.ts +2 -14
  10. package/dist/esm/index.js +5344 -5517
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/types/components/LoadingSpinner.d.ts +2 -2
  13. package/dist/esm/types/components/SimpleDateChooser.d.ts +3 -1
  14. package/dist/esm/types/components/SimpleTimeChooser.d.ts +20 -0
  15. package/dist/esm/types/components/Tooltip.d.ts +1 -1
  16. package/dist/esm/types/index.d.ts +12 -11
  17. package/dist/esm/types/types/ParamType.d.ts +10 -10
  18. package/dist/esm/types/types/ReactKitErrorCode.d.ts +2 -14
  19. package/dist/index.d.ts +183 -354
  20. package/genEncodedSecret.ts +84 -0
  21. package/package.json +7 -9
  22. package/rollup.config.js +2 -0
  23. package/src/components/AppWrapper.tsx +3 -1
  24. package/src/components/CheckboxButton.tsx +1 -1
  25. package/src/components/Dropdown.tsx +1 -1
  26. package/src/components/LogReviewer.tsx +2 -2
  27. package/src/components/Modal/index.tsx +1 -1
  28. package/src/components/RadioButton.tsx +3 -1
  29. package/src/components/SimpleDateChooser.tsx +62 -26
  30. package/src/components/SimpleTimeChooser.tsx +195 -0
  31. package/src/components/Tooltip.tsx +1 -1
  32. package/src/{client → helpers}/initClient.tsx +5 -1
  33. package/src/helpers/logClientEvent.tsx +3 -1
  34. package/src/helpers/visitServerEndpoint.tsx +1 -1
  35. package/src/index.ts +20 -20
  36. package/src/types/ParamType.ts +10 -10
  37. package/src/types/ReactKitErrorCode.tsx +3 -17
  38. package/dist/cjs/types/components/ItemPicker/index.test.d.ts +0 -1
  39. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +0 -41
  40. package/dist/cjs/types/helpers/genRouteHandler.d.ts +0 -76
  41. package/dist/cjs/types/helpers/handleError.d.ts +0 -18
  42. package/dist/cjs/types/helpers/handleSuccess.d.ts +0 -8
  43. package/dist/cjs/types/helpers/parseUserAgent.d.ts +0 -17
  44. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -24
  45. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -33
  46. package/dist/cjs/types/server/initLogCollection.d.ts +0 -8
  47. package/dist/cjs/types/server/initServer.d.ts +0 -42
  48. package/dist/esm/types/components/ItemPicker/index.test.d.ts +0 -1
  49. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +0 -41
  50. package/dist/esm/types/helpers/genRouteHandler.d.ts +0 -76
  51. package/dist/esm/types/helpers/handleError.d.ts +0 -18
  52. package/dist/esm/types/helpers/handleSuccess.d.ts +0 -8
  53. package/dist/esm/types/helpers/parseUserAgent.d.ts +0 -17
  54. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -24
  55. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -33
  56. package/dist/esm/types/server/initLogCollection.d.ts +0 -8
  57. package/dist/esm/types/server/initServer.d.ts +0 -42
  58. package/src/components/ItemPicker/index.test.tsx +0 -783
  59. package/src/helpers/addDBEditorEndpoints.ts +0 -128
  60. package/src/helpers/genRouteHandler.ts +0 -948
  61. package/src/helpers/handleError.ts +0 -65
  62. package/src/helpers/handleSuccess.ts +0 -18
  63. package/src/helpers/parseUserAgent.ts +0 -108
  64. package/src/helpers/visitEndpointOnAnotherServer/index.ts +0 -93
  65. package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +0 -164
  66. package/src/server/initLogCollection.ts +0 -27
  67. package/src/server/initServer.ts +0 -287
  68. /package/dist/cjs/types/{client → helpers}/initClient.d.ts +0 -0
  69. /package/dist/esm/types/{client → helpers}/initClient.d.ts +0 -0
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import RadioButton from './components/RadioButton';
15
15
  import CheckboxButton from './components/CheckboxButton';
16
16
  import ButtonInputGroup from './components/ButtonInputGroup';
17
17
  import SimpleDateChooser from './components/SimpleDateChooser';
18
+ import SimpleTimeChooser from './components/SimpleTimeChooser';
18
19
  import Drawer from './components/Drawer';
19
20
  import PopSuccessMark from './components/PopSuccessMark';
20
21
  import PopFailureMark from './components/PopFailureMark';
@@ -38,12 +39,15 @@ import ErrorWithCode from './errors/ErrorWithCode';
38
39
  import MINUTE_IN_MS from './constants/MINUTE_IN_MS';
39
40
  import HOUR_IN_MS from './constants/HOUR_IN_MS';
40
41
  import DAY_IN_MS from './constants/DAY_IN_MS';
42
+ import LOG_REVIEW_ROUTE_PATH_PREFIX from './constants/LOG_REVIEW_ROUTE_PATH_PREFIX';
43
+ import LOG_ROUTE_PATH from './constants/LOG_ROUTE_PATH';
44
+ import LOG_REVIEW_STATUS_ROUTE from './constants/LOG_REVIEW_STATUS_ROUTE';
41
45
 
42
46
  // Import dynamic constants
43
47
  import DynamicWord from './dynamicConstants/DynamicWord';
44
48
 
45
49
  // Import helpers
46
- import initClient from './client/initClient';
50
+ import initClient from './helpers/initClient';
47
51
  import abbreviate from './helpers/abbreviate';
48
52
  import avg from './helpers/avg';
49
53
  import ceilToNumDecimals from './helpers/ceilToNumDecimals';
@@ -55,10 +59,6 @@ import roundToNumDecimals from './helpers/roundToNumDecimals';
55
59
  import sum from './helpers/sum';
56
60
  import waitMs from './helpers/waitMs';
57
61
  import visitServerEndpoint from './helpers/visitServerEndpoint';
58
- import genRouteHandler from './helpers/genRouteHandler';
59
- import handleError from './helpers/handleError';
60
- import handleSuccess from './helpers/handleSuccess';
61
- import initServer from './server/initServer';
62
62
  import getOrdinal from './helpers/getOrdinal';
63
63
  import getTimeInfoInET from './helpers/getTimeInfoInET';
64
64
  import stubServerEndpoint from './helpers/stubServerEndpoint';
@@ -69,7 +69,6 @@ import stringsToHumanReadableList from './helpers/stringsToHumanReadableList';
69
69
  import onlyKeepLetters from './helpers/onlyKeepLetters';
70
70
  import parallelLimit from './helpers/parallelLimit';
71
71
  import logClientEvent, { setClientEventMetadataPopulator } from './helpers/logClientEvent';
72
- import initLogCollection from './server/initLogCollection';
73
72
  import getMonthName from './helpers/getMonthName';
74
73
  import genCSV from './helpers/genCSV';
75
74
  import canReviewLogs from './helpers/canReviewLogs';
@@ -77,7 +76,6 @@ import isMobileOrTablet from './helpers/isMobileOrTablet';
77
76
  import extractProp from './helpers/extractProp';
78
77
  import compareArraysByProp from './helpers/compareArraysByProp';
79
78
  import getLocalTimeInfo from './helpers/getLocalTimeInfo';
80
- import addDBEditorEndpoints from './helpers/addDBEditorEndpoints';
81
79
  import genCommaList from './helpers/genCommaList';
82
80
  import validateEmail from './helpers/validators/validateEmail';
83
81
  import validatePhoneNumber from './helpers/validators/validatePhoneNumber';
@@ -94,16 +92,14 @@ import mapAsync from './helpers/asyncArrayFunctions/mapAsync';
94
92
  import someAsync from './helpers/asyncArrayFunctions/someAsync';
95
93
  import capitalize from './helpers/capitalize';
96
94
  import shuffleArray from './helpers/shuffleArray';
97
- import visitEndpointOnAnotherServer from './helpers/visitEndpointOnAnotherServer';
98
95
  import getWordCount from './helpers/getWordCount';
99
96
 
100
97
  // Import types
98
+ import ParamType from './types/ParamType';
101
99
  import ModalButtonType from './types/ModalButtonType';
102
100
  import ModalSize from './types/ModalSize';
103
101
  import ModalType from './types/ModalType';
104
- import ReactKitErrorCode from './types/ReactKitErrorCode';
105
102
  import Variant from './types/Variant';
106
- import ParamType from './types/ParamType';
107
103
  import DayOfWeek from './types/DayOfWeek';
108
104
  import Log from './types/Log';
109
105
  import LogType from './types/LogType';
@@ -112,8 +108,13 @@ import LogAction from './types/LogAction';
112
108
  import LogBuiltInMetadata from './types/LogBuiltInMetadata';
113
109
  import LogMetadataType from './types/LogMetadataType';
114
110
  import LogFunction from './types/LogFunction';
111
+ import LogTypeSpecificInfo from './types/Log/LogTypeSpecificInfo';
112
+ import LogMainInfo from './types/Log/LogMainInfo';
113
+ import LogSourceSpecificInfo from './types/Log/LogSourceSpecificInfo';
114
+ import LogLevel from './types/LogLevel';
115
115
  import IntelliTableColumn from './types/IntelliTableColumn';
116
116
  import DropdownItemType from './types/DropdownItemType';
117
+ import ReactKitErrorCode from './types/ReactKitErrorCode';
117
118
 
118
119
  // Component-specific-types
119
120
  import PickableItem from './components/ItemPicker/types/PickableItem';
@@ -133,6 +134,7 @@ export {
133
134
  CheckboxButton,
134
135
  ButtonInputGroup,
135
136
  SimpleDateChooser,
137
+ SimpleTimeChooser,
136
138
  Drawer,
137
139
  PopSuccessMark,
138
140
  PopFailureMark,
@@ -159,6 +161,9 @@ export {
159
161
  MINUTE_IN_MS,
160
162
  HOUR_IN_MS,
161
163
  DAY_IN_MS,
164
+ LOG_REVIEW_ROUTE_PATH_PREFIX,
165
+ LOG_ROUTE_PATH,
166
+ LOG_REVIEW_STATUS_ROUTE,
162
167
  // Dynamic Constants
163
168
  DynamicWord,
164
169
  // Helpers
@@ -212,15 +217,8 @@ export {
212
217
  combineClassNames,
213
218
  useForceRender,
214
219
  setClientEventMetadataPopulator,
215
- // Server helpers
216
- initServer,
217
- genRouteHandler,
218
- handleError,
219
- handleSuccess,
220
- initLogCollection,
221
- addDBEditorEndpoints,
222
- visitEndpointOnAnotherServer,
223
220
  // Types
221
+ ParamType,
224
222
  ModalButtonType,
225
223
  ModalSize,
226
224
  ModalType,
@@ -234,6 +232,10 @@ export {
234
232
  LogBuiltInMetadata,
235
233
  LogMetadataType,
236
234
  LogFunction,
235
+ LogTypeSpecificInfo,
236
+ LogMainInfo,
237
+ LogSourceSpecificInfo,
238
+ LogLevel,
237
239
  IntelliTableColumn,
238
240
  DropdownItemType,
239
241
  // Component-specific-types
@@ -241,6 +243,4 @@ export {
241
243
  DBEntry,
242
244
  DBEntryField,
243
245
  DBEntryFieldType,
244
- // Server types
245
- ParamType,
246
246
  };
@@ -3,16 +3,16 @@
3
3
  * @author Gabe Abrams
4
4
  */
5
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
6
+ Boolean = 'Boolean', // Boolean
7
+ BooleanOptional = 'BooleanOptional', // Optional boolean
8
+ Float = 'Float', // Float Number
9
+ FloatOptional = 'FloatOptional', // Optional Float Number
10
+ Int = 'Int', // Integer Number
11
+ IntOptional = 'IntOptional', // Optional Integer Number
12
+ JSON = 'JSON', // JSONified object
13
+ JSONOptional = 'JSONOptional', // Optional JSONified object
14
+ String = 'String', // String
15
+ StringOptional = 'StringOptional', // Optional string
16
16
  }
17
17
 
18
18
  export default ParamType;
@@ -1,4 +1,4 @@
1
- // Highest error code = DRK18
1
+ // Highest error code = DRK36
2
2
 
3
3
  /**
4
4
  * List of error codes built into the react kit
@@ -8,23 +8,9 @@ enum ReactKitErrorCode {
8
8
  NoResponse = 'DRK1',
9
9
  NoCode = 'DRK2',
10
10
  SessionExpired = 'DRK3',
11
- MissingParameter = 'DRK4',
12
- InvalidParameter = 'DRK5',
13
- HostNotAllowed = 'DRK17',
14
- HostBanned = 'DRK18',
15
- WrongCourse = 'DRK6',
16
11
  NoCACCLSendRequestFunction = 'DRK7',
17
- NoCACCLGetLaunchInfoFunction = 'DRK8',
18
- NotTTM = 'DRK9',
19
- NotAdmin = 'DRK10',
20
- NotAllowedToReviewLogs = 'DRK11',
21
- ThemeCheckedBeforeReactKitReady = 'DRK12',
22
- SessionExpiredMessageGottenBeforeReactKitReady = 'DRK13',
23
-
24
- // Server-to-server requests
25
- NotConnected = 'DRK14',
26
- SelfSigned = 'DRK15',
27
- ResponseParseError = 'DRK16',
12
+ SimpleDateChooserInvalidDateRange = 'DRK35',
13
+ SimpleDateChooserInvalidNumMonths = 'DRK36',
28
14
  }
29
15
 
30
16
  export default ReactKitErrorCode;
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * Interface for a collection in the database
4
- * @author Yuen Ler Chow
5
- */
6
- type DCEMangoCollection = {
7
- /**
8
- * Find all items in the collection that match the filter query
9
- * @param filterQuery query for the filter
10
- * @returns list of items that match the filter query
11
- */
12
- find: (filterQuery: any) => Promise<any[]>;
13
- /**
14
- * Insert an item into the collection
15
- * @param item the item to insert
16
- */
17
- insert: (item: any) => Promise<void>;
18
- /**
19
- * Delete an item in the collection
20
- * @param id the id of the item to delete
21
- */
22
- delete: (filterQuery: {
23
- id: string;
24
- }) => Promise<void>;
25
- };
26
- /**
27
- * Add all routes for the DBEditor
28
- * @author Yuen Ler Chow
29
- * @param opts object containing all arguments
30
- * @param opts.app express app to add routes too
31
- * @param opts.collectionName the name of the collection
32
- * @param opts.adminsOnly true if the endpoint is for admins only
33
- * @param opts.collection dce-mango db collection
34
- */
35
- declare const addDBEditorEndpoints: (opts: {
36
- app: express.Application;
37
- collectionName: string;
38
- adminsOnly: boolean;
39
- collection: DCEMangoCollection;
40
- }) => void;
41
- export default addDBEditorEndpoints;
@@ -1,76 +0,0 @@
1
- import ParamType from '../types/ParamType';
2
- import LogFunction from '../types/LogFunction';
3
- /**
4
- * Generate an express API route handler
5
- * @author Gabe Abrams
6
- * @param opts object containing all arguments
7
- * @param opts.paramTypes map containing the types for each parameter that is
8
- * included in the request (map: param name => type)
9
- * @param opts.handler function that processes the request
10
- * @param [opts.skipSessionCheck] if true, skip the session check (allow users
11
- * to not be logged in and launched via LTI)
12
- * @param [opts.allowedHosts] if included, only allow requests from these hosts
13
- * (start a hostname with a "*" to only check the end of the hostname)
14
- * you can include just one string instead of an array
15
- * @param [opts.bannedHosts] if included, do not allow requests from these hosts
16
- * (start a hostname with a "*" to only check the end of the hostname)
17
- * you can include just one string instead of an array
18
- * @param [opts.unhandledErrorMessagePrefix] if included, when an error that
19
- * is not of type ErrorWithCode is thrown, the client will receive an error
20
- * where the error message is prefixed with this string. For example,
21
- * if unhandledErrorMessagePrefix is
22
- * 'While saving progress, we encountered an error:'
23
- * and the error is 'progressInfo is not an object',
24
- * the client will receive an error with the message
25
- * 'While saving progress, we encountered an error: progressInfo is not an object'
26
- * @returns express route handler that takes the following arguments:
27
- * params (map: param name => value),
28
- * req (express request object),
29
- * next (express next function),
30
- * send (a function that sends a string to the client),
31
- * redirect (takes a url and redirects the user to that url),
32
- * renderErrorPage (shows a static error page to the user),
33
- * renderInfoPage (shows a static info page to the user),
34
- * renderCustomHTML (renders custom html and sends it to the user),
35
- * and returns the value to send to the client as a JSON API response, or
36
- * calls next() or redirect(...) or send(...) or renderErrorPage(...).
37
- * Note: params also has userId, userFirstName,
38
- * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
39
- * and any other variables that
40
- * are directly added to the session, if the user does have a session.
41
- */
42
- declare const genRouteHandler: (opts: {
43
- paramTypes?: {
44
- [k: string]: ParamType;
45
- } | undefined;
46
- handler: (opts: {
47
- params: {
48
- [k: string]: any;
49
- };
50
- req: any;
51
- next: () => void;
52
- redirect: (pathOrURL: string) => void;
53
- send: (text: string, status?: number) => void;
54
- renderErrorPage: (opts?: {
55
- title?: string;
56
- description?: string;
57
- code?: string;
58
- pageTitle?: string;
59
- status?: number;
60
- }) => void;
61
- renderInfoPage: (opts: {
62
- title: string;
63
- body: string;
64
- }) => void;
65
- renderCustomHTML: (opts: {
66
- html: string;
67
- status?: number;
68
- }) => void;
69
- logServerEvent: LogFunction;
70
- }) => any;
71
- skipSessionCheck?: boolean | undefined;
72
- allowedHosts?: string | string[] | undefined;
73
- bannedHosts?: string | string[] | undefined;
74
- unhandledErrorMessagePrefix?: string | undefined;
75
- }) => (req: any, res: any, next: () => void) => Promise<undefined>;
76
- export default genRouteHandler;
@@ -1,18 +0,0 @@
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;
@@ -1,8 +0,0 @@
1
- /**
2
- * Send successful API response
3
- * @author Gabe Abrams
4
- * @param res express response
5
- * @param body the body of the response to send to the client
6
- */
7
- declare const handleSuccess: (res: any, body: any) => undefined;
8
- export default handleSuccess;
@@ -1,17 +0,0 @@
1
- /**
2
- * Perform a rudimentary parsing of the user's browser agent string
3
- * @author Gabe Abrams
4
- * @param userAgent the user's browser agent
5
- * @returns user info
6
- */
7
- declare const parseUserAgent: (userAgent: string) => {
8
- browser: {
9
- name: string;
10
- version: string;
11
- };
12
- device: {
13
- isMobile: boolean;
14
- os: string;
15
- };
16
- };
17
- export default parseUserAgent;
@@ -1,24 +0,0 @@
1
- /**
2
- * Send a server-to-server request from this sever to another server that uses
3
- * dce-reactkit [for server only]
4
- * @author Gabe Abrams
5
- * @param opts object containing all arguments
6
- * @param opts.host - the host of the other server
7
- * @param opts.path - the path of the other server's endpoint
8
- * @param [opts.method=GET] - the method of the endpoint
9
- * @param [opts.params] - query/body parameters to include
10
- * @param [opts.headers] - headers to include
11
- * @returns response from server
12
- */
13
- declare const visitEndpointOnAnotherServer: (opts: {
14
- host: string;
15
- path: string;
16
- method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
17
- params?: {
18
- [x: string]: any;
19
- } | undefined;
20
- headers?: {
21
- [x: string]: any;
22
- } | undefined;
23
- }) => Promise<any>;
24
- export default visitEndpointOnAnotherServer;
@@ -1,33 +0,0 @@
1
- /**
2
- * Sends and retries an http request
3
- * @author Gabriel Abrams
4
- * @param opts object containing all arguments
5
- * @param opts.path path to send request to
6
- * @param [opts.host] host to send request to
7
- * @param [opts.method=GET] http method to use
8
- * @param [opts.params] body/data to include in the request
9
- * @param [opts.headers] headers to include in the request
10
- * @param [opts.sendCrossDomainCredentials=true if in development mode] if true,
11
- * send cross-domain credentials even if not in dev mode
12
- * @param [opts.responseType=JSON] expected response type
13
- * @returns { body, status, headers } on success
14
- */
15
- declare const sendServerToServerRequest: (opts: {
16
- path: string;
17
- host?: string | undefined;
18
- method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
19
- params?: {
20
- [x: string]: any;
21
- } | undefined;
22
- headers?: {
23
- [x: string]: any;
24
- } | undefined;
25
- responseType?: "Text" | "JSON" | undefined;
26
- }) => Promise<{
27
- body: any;
28
- status: number;
29
- headers: {
30
- [x: string]: any;
31
- };
32
- }>;
33
- export default sendServerToServerRequest;
@@ -1,8 +0,0 @@
1
- /**
2
- * Initialize a log collection given the dce-mango Collection class
3
- * @author Gabe Abrams
4
- * @param Collection the Collection class from dce-mango
5
- * @returns initialized logCollection
6
- */
7
- declare const initLogCollection: (Collection: any) => any;
8
- export default initLogCollection;
@@ -1,42 +0,0 @@
1
- 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
- * Get log collection
14
- * @author Gabe Abrams
15
- * @returns log collection if one was included during launch or null if we don't
16
- * have a log collection (yet)
17
- */
18
- export declare const internalGetLogCollection: () => any;
19
- /**
20
- * Prepare dce-reactkit to run on the server
21
- * @author Gabe Abrams
22
- * @param opts object containing all arguments
23
- * @param opts.app express app from inside of the postprocessor function that
24
- * we will add routes to
25
- * @param opts.getLaunchInfo CACCL LTI's get launch info function
26
- * @param [opts.logCollection] mongo collection from dce-mango to use for
27
- * storing logs. If none is included, logs are written to the console
28
- * @param [opts.logReviewAdmins=all] info on which admins can review
29
- * logs from the client. If not included, all Canvas admins are allowed to
30
- * review logs. If null, no Canvas admins are allowed to review logs.
31
- * If an array of Canvas userIds (numbers), only Canvas admins with those
32
- * userIds are allowed to review logs. If a dce-mango collection, only
33
- * Canvas admins with entries in that collection ({ userId, ...}) are allowed
34
- * to review logs
35
- */
36
- declare const initServer: (opts: {
37
- app: any;
38
- getLaunchInfo: GetLaunchInfoFunction;
39
- logCollection?: any;
40
- logReviewAdmins?: (number[] | any);
41
- }) => void;
42
- export default initServer;
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * Interface for a collection in the database
4
- * @author Yuen Ler Chow
5
- */
6
- type DCEMangoCollection = {
7
- /**
8
- * Find all items in the collection that match the filter query
9
- * @param filterQuery query for the filter
10
- * @returns list of items that match the filter query
11
- */
12
- find: (filterQuery: any) => Promise<any[]>;
13
- /**
14
- * Insert an item into the collection
15
- * @param item the item to insert
16
- */
17
- insert: (item: any) => Promise<void>;
18
- /**
19
- * Delete an item in the collection
20
- * @param id the id of the item to delete
21
- */
22
- delete: (filterQuery: {
23
- id: string;
24
- }) => Promise<void>;
25
- };
26
- /**
27
- * Add all routes for the DBEditor
28
- * @author Yuen Ler Chow
29
- * @param opts object containing all arguments
30
- * @param opts.app express app to add routes too
31
- * @param opts.collectionName the name of the collection
32
- * @param opts.adminsOnly true if the endpoint is for admins only
33
- * @param opts.collection dce-mango db collection
34
- */
35
- declare const addDBEditorEndpoints: (opts: {
36
- app: express.Application;
37
- collectionName: string;
38
- adminsOnly: boolean;
39
- collection: DCEMangoCollection;
40
- }) => void;
41
- export default addDBEditorEndpoints;
@@ -1,76 +0,0 @@
1
- import ParamType from '../types/ParamType';
2
- import LogFunction from '../types/LogFunction';
3
- /**
4
- * Generate an express API route handler
5
- * @author Gabe Abrams
6
- * @param opts object containing all arguments
7
- * @param opts.paramTypes map containing the types for each parameter that is
8
- * included in the request (map: param name => type)
9
- * @param opts.handler function that processes the request
10
- * @param [opts.skipSessionCheck] if true, skip the session check (allow users
11
- * to not be logged in and launched via LTI)
12
- * @param [opts.allowedHosts] if included, only allow requests from these hosts
13
- * (start a hostname with a "*" to only check the end of the hostname)
14
- * you can include just one string instead of an array
15
- * @param [opts.bannedHosts] if included, do not allow requests from these hosts
16
- * (start a hostname with a "*" to only check the end of the hostname)
17
- * you can include just one string instead of an array
18
- * @param [opts.unhandledErrorMessagePrefix] if included, when an error that
19
- * is not of type ErrorWithCode is thrown, the client will receive an error
20
- * where the error message is prefixed with this string. For example,
21
- * if unhandledErrorMessagePrefix is
22
- * 'While saving progress, we encountered an error:'
23
- * and the error is 'progressInfo is not an object',
24
- * the client will receive an error with the message
25
- * 'While saving progress, we encountered an error: progressInfo is not an object'
26
- * @returns express route handler that takes the following arguments:
27
- * params (map: param name => value),
28
- * req (express request object),
29
- * next (express next function),
30
- * send (a function that sends a string to the client),
31
- * redirect (takes a url and redirects the user to that url),
32
- * renderErrorPage (shows a static error page to the user),
33
- * renderInfoPage (shows a static info page to the user),
34
- * renderCustomHTML (renders custom html and sends it to the user),
35
- * and returns the value to send to the client as a JSON API response, or
36
- * calls next() or redirect(...) or send(...) or renderErrorPage(...).
37
- * Note: params also has userId, userFirstName,
38
- * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
39
- * and any other variables that
40
- * are directly added to the session, if the user does have a session.
41
- */
42
- declare const genRouteHandler: (opts: {
43
- paramTypes?: {
44
- [k: string]: ParamType;
45
- } | undefined;
46
- handler: (opts: {
47
- params: {
48
- [k: string]: any;
49
- };
50
- req: any;
51
- next: () => void;
52
- redirect: (pathOrURL: string) => void;
53
- send: (text: string, status?: number) => void;
54
- renderErrorPage: (opts?: {
55
- title?: string;
56
- description?: string;
57
- code?: string;
58
- pageTitle?: string;
59
- status?: number;
60
- }) => void;
61
- renderInfoPage: (opts: {
62
- title: string;
63
- body: string;
64
- }) => void;
65
- renderCustomHTML: (opts: {
66
- html: string;
67
- status?: number;
68
- }) => void;
69
- logServerEvent: LogFunction;
70
- }) => any;
71
- skipSessionCheck?: boolean | undefined;
72
- allowedHosts?: string | string[] | undefined;
73
- bannedHosts?: string | string[] | undefined;
74
- unhandledErrorMessagePrefix?: string | undefined;
75
- }) => (req: any, res: any, next: () => void) => Promise<undefined>;
76
- export default genRouteHandler;
@@ -1,18 +0,0 @@
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;
@@ -1,8 +0,0 @@
1
- /**
2
- * Send successful API response
3
- * @author Gabe Abrams
4
- * @param res express response
5
- * @param body the body of the response to send to the client
6
- */
7
- declare const handleSuccess: (res: any, body: any) => undefined;
8
- export default handleSuccess;
@@ -1,17 +0,0 @@
1
- /**
2
- * Perform a rudimentary parsing of the user's browser agent string
3
- * @author Gabe Abrams
4
- * @param userAgent the user's browser agent
5
- * @returns user info
6
- */
7
- declare const parseUserAgent: (userAgent: string) => {
8
- browser: {
9
- name: string;
10
- version: string;
11
- };
12
- device: {
13
- isMobile: boolean;
14
- os: string;
15
- };
16
- };
17
- export default parseUserAgent;
@@ -1,24 +0,0 @@
1
- /**
2
- * Send a server-to-server request from this sever to another server that uses
3
- * dce-reactkit [for server only]
4
- * @author Gabe Abrams
5
- * @param opts object containing all arguments
6
- * @param opts.host - the host of the other server
7
- * @param opts.path - the path of the other server's endpoint
8
- * @param [opts.method=GET] - the method of the endpoint
9
- * @param [opts.params] - query/body parameters to include
10
- * @param [opts.headers] - headers to include
11
- * @returns response from server
12
- */
13
- declare const visitEndpointOnAnotherServer: (opts: {
14
- host: string;
15
- path: string;
16
- method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
17
- params?: {
18
- [x: string]: any;
19
- } | undefined;
20
- headers?: {
21
- [x: string]: any;
22
- } | undefined;
23
- }) => Promise<any>;
24
- export default visitEndpointOnAnotherServer;