dce-reactkit 3.12.3 → 4.0.0-beta.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 (71) hide show
  1. package/.vscode/settings.json +1 -3
  2. package/README.md +20 -0
  3. package/dist/cjs/index.js +156 -1792
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/types/components/ItemPicker/index.d.ts +0 -1
  6. package/dist/cjs/types/components/Modal/ModalProps.d.ts +0 -2
  7. package/dist/cjs/types/components/TabBox.d.ts +0 -1
  8. package/dist/cjs/types/index.d.ts +8 -12
  9. package/dist/cjs/types/types/ParamType.d.ts +10 -10
  10. package/dist/cjs/types/types/ReactKitErrorCode.d.ts +1 -15
  11. package/dist/esm/index.js +157 -1785
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/types/components/ItemPicker/index.d.ts +0 -1
  14. package/dist/esm/types/components/Modal/ModalProps.d.ts +0 -2
  15. package/dist/esm/types/components/TabBox.d.ts +0 -1
  16. package/dist/esm/types/index.d.ts +8 -12
  17. package/dist/esm/types/types/ParamType.d.ts +10 -10
  18. package/dist/esm/types/types/ReactKitErrorCode.d.ts +1 -15
  19. package/dist/index.d.ts +122 -351
  20. package/genEncodedSecret.ts +84 -0
  21. package/package.json +7 -5
  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/IntelliTable.tsx +1 -1
  27. package/src/components/ItemPicker/NestableItemList.tsx +0 -1
  28. package/src/components/ItemPicker/index.tsx +0 -96
  29. package/src/components/Modal/ModalProps.ts +0 -4
  30. package/src/components/Modal/index.tsx +21 -60
  31. package/src/components/RadioButton.tsx +3 -1
  32. package/src/components/TabBox.tsx +9 -27
  33. package/src/{client → helpers}/initClient.tsx +5 -1
  34. package/src/helpers/logClientEvent.tsx +3 -1
  35. package/src/helpers/visitServerEndpoint.tsx +1 -1
  36. package/src/index.ts +12 -22
  37. package/src/types/ParamType.ts +10 -10
  38. package/src/types/ReactKitErrorCode.tsx +1 -17
  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/getWordCount.d.ts +0 -10
  42. package/dist/cjs/types/helpers/handleError.d.ts +0 -18
  43. package/dist/cjs/types/helpers/handleSuccess.d.ts +0 -8
  44. package/dist/cjs/types/helpers/parseUserAgent.d.ts +0 -17
  45. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -24
  46. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -33
  47. package/dist/cjs/types/server/initLogCollection.d.ts +0 -8
  48. package/dist/cjs/types/server/initServer.d.ts +0 -42
  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/getWordCount.d.ts +0 -10
  52. package/dist/esm/types/helpers/handleError.d.ts +0 -18
  53. package/dist/esm/types/helpers/handleSuccess.d.ts +0 -8
  54. package/dist/esm/types/helpers/parseUserAgent.d.ts +0 -17
  55. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -24
  56. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -33
  57. package/dist/esm/types/server/initLogCollection.d.ts +0 -8
  58. package/dist/esm/types/server/initServer.d.ts +0 -42
  59. package/src/components/ItemPicker/index.test.tsx +0 -783
  60. package/src/helpers/addDBEditorEndpoints.ts +0 -128
  61. package/src/helpers/genRouteHandler.ts +0 -948
  62. package/src/helpers/getWordCount.ts +0 -26
  63. package/src/helpers/handleError.ts +0 -65
  64. package/src/helpers/handleSuccess.ts +0 -18
  65. package/src/helpers/parseUserAgent.ts +0 -108
  66. package/src/helpers/visitEndpointOnAnotherServer/index.ts +0 -93
  67. package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +0 -164
  68. package/src/server/initLogCollection.ts +0 -27
  69. package/src/server/initServer.ts +0 -287
  70. /package/dist/cjs/types/{client → helpers}/initClient.d.ts +0 -0
  71. /package/dist/esm/types/{client → helpers}/initClient.d.ts +0 -0
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import React$1 from 'react';
3
3
  import { IconProp } from '@fortawesome/fontawesome-svg-core';
4
- import express from 'express';
5
4
 
6
5
  /**
7
6
  * Bootstrap variants
@@ -209,8 +208,6 @@ type ModalProps = {
209
208
  confirmLabel?: string;
210
209
  confirmVariant?: Variant;
211
210
  onTopOfOtherModals?: boolean;
212
- isLoading?: boolean;
213
- isLoadingCancelable?: boolean;
214
211
  };
215
212
 
216
213
  /**
@@ -229,7 +226,6 @@ declare const Modal: React$1.FC<ModalProps>;
229
226
  type Props$j = {
230
227
  title: React$1.ReactNode;
231
228
  children: React$1.ReactNode;
232
- topRightChildren?: React$1.ReactNode;
233
229
  noBottomMargin?: boolean;
234
230
  noBottomPadding?: boolean;
235
231
  };
@@ -415,7 +411,6 @@ type Props$9 = {
415
411
  */
416
412
  onChanged: (updatedItems: PickableItem[]) => void;
417
413
  noBottomMargin?: boolean;
418
- hideSelectAllOrNoneButtons?: boolean;
419
414
  };
420
415
  declare const ItemPicker: React$1.FC<Props$9>;
421
416
 
@@ -473,16 +468,16 @@ declare const LogReviewer: React$1.FC<Props$8>;
473
468
  * @author Gabe Abrams
474
469
  */
475
470
  declare enum ParamType {
476
- Boolean = "boolean",
477
- BooleanOptional = "boolean-optional",
478
- Float = "float",
479
- FloatOptional = "float-optional",
480
- Int = "int",
481
- IntOptional = "int-optional",
482
- JSON = "json",
483
- JSONOptional = "json-optional",
484
- String = "string",
485
- StringOptional = "string-optional"
471
+ Boolean = "Boolean",
472
+ BooleanOptional = "BooleanOptional",
473
+ Float = "Float",
474
+ FloatOptional = "FloatOptional",
475
+ Int = "Int",
476
+ IntOptional = "IntOptional",
477
+ JSON = "JSON",
478
+ JSONOptional = "JSONOptional",
479
+ String = "String",
480
+ StringOptional = "StringOptional"
486
481
  }
487
482
 
488
483
  /**
@@ -935,6 +930,106 @@ declare const visitServerEndpoint: (opts: {
935
930
  } | undefined;
936
931
  }) => Promise<any>;
937
932
 
933
+ /**
934
+ * Get a number's ordinal
935
+ * @author Gabe Abrams
936
+ * @param num the number being analyzed
937
+ * @returns ordinal
938
+ */
939
+ declare const getOrdinal: (num: number) => string;
940
+
941
+ /**
942
+ * Get current time info in US Boston Eastern Time, independent of machine
943
+ * timezone
944
+ * @author Gabe Abrams
945
+ * @param [dateOrTimestamp=now] the date to get info on or a ms since epoch timestamp
946
+ * @returns object with timestamp (ms since epoch) and numbers
947
+ * corresponding to ET time values for year, month, day, hour, hour12, minute, isPM
948
+ * where hour is in 24hr time and hour12 is in 12hr time.
949
+ */
950
+ declare const getTimeInfoInET: (dateOrTimestamp?: Date | number) => {
951
+ timestamp: number;
952
+ year: number;
953
+ month: number;
954
+ day: number;
955
+ hour: number;
956
+ hour12: number;
957
+ minute: number;
958
+ isPM: boolean;
959
+ };
960
+
961
+ /**
962
+ * Stub a server endpoint response
963
+ * @author Gabe Abrams
964
+ * @param opts object containing all arguments
965
+ * @param [opts.method=GET] http method to stub
966
+ * @param opts.path full pathname to stub
967
+ * @param opts.body body of response if stubbing a successful response
968
+ * @param opts.errorMessage message of error if stubbing a failed response
969
+ * @param [opts.errorCode] error code if stubbing a failed response
970
+ */
971
+ declare const stubServerEndpoint: (opts: {
972
+ method?: string | undefined;
973
+ path: string;
974
+ body?: any;
975
+ errorMessage?: string | undefined;
976
+ errorCode?: string | undefined;
977
+ }) => void;
978
+
979
+ /**
980
+ * Start a dynamic wait, call the function once the operation has completed and
981
+ * the dynamic wait will continue waiting for the rest of the minimum time
982
+ * @author Gabe Abrams
983
+ * @param minWaitMs the minimum number of ms to wait
984
+ * @returns async function to call to finish the wait
985
+ */
986
+ declare const startMinWait: (minWaitMs: number) => () => Promise<void>;
987
+
988
+ /**
989
+ * Get a human-readable description of a date (all in ET)
990
+ * @author Gabe Abrams
991
+ * @param [dateOrTimestamp=today] the date or timestamp for the date to describe
992
+ * @returns human-readable description of the date
993
+ */
994
+ declare const getHumanReadableDate: (dateOrTimestamp?: Date | number) => string;
995
+
996
+ /**
997
+ * Get the current part of day (morning, evening, etc.)
998
+ * @author Gabe Abrams
999
+ * @returns the part of day (morning, evening, etc.)
1000
+ */
1001
+ declare const getPartOfDay: () => string;
1002
+
1003
+ /**
1004
+ * Create a human readable list from an array of strings.
1005
+ * For example, ['apple', 'orange'] becomes "apple and orange"
1006
+ * and ['apple', 'orange', 'mango'] becomes "apple, orange, and mango"
1007
+ * @author Gabe Abrams
1008
+ * @param items list of items in the list
1009
+ * @returns human-readable list
1010
+ */
1011
+ declare const stringsToHumanReadableList: (items: string[]) => string;
1012
+
1013
+ /**
1014
+ * Given a string, only keep the letters inside it
1015
+ * @author Gabe Abrams
1016
+ * @param str the string to parse
1017
+ * @returns only the letters inside of the string
1018
+ */
1019
+ declare const onlyKeepLetters: (str: string) => string;
1020
+
1021
+ /**
1022
+ * Run tasks in parallel with a limit on how many tasks can execute at once.
1023
+ * No guarantees are made about the order of task execution
1024
+ * @author Gabe Abrams
1025
+ * @param taskFunctions functions that start asynchronous tasks and optionally
1026
+ * resolve with values
1027
+ * @param [limit=no limit] maximum number of asynchronous tasks to permit to run at
1028
+ * once
1029
+ * @returns array of resolved values in the same order as the task functions
1030
+ */
1031
+ declare const parallelLimit: (taskFunctions: (() => Promise<any>)[], limit?: number) => Promise<any[]>;
1032
+
938
1033
  /**
939
1034
  * Allowed log levels
940
1035
  * @author Gabe Abrams
@@ -1083,234 +1178,6 @@ type LogFunction = (opts: ({
1083
1178
  target?: string;
1084
1179
  }))) => Promise<Log>;
1085
1180
 
1086
- /**
1087
- * Generate an express API route handler
1088
- * @author Gabe Abrams
1089
- * @param opts object containing all arguments
1090
- * @param opts.paramTypes map containing the types for each parameter that is
1091
- * included in the request (map: param name => type)
1092
- * @param opts.handler function that processes the request
1093
- * @param [opts.skipSessionCheck] if true, skip the session check (allow users
1094
- * to not be logged in and launched via LTI)
1095
- * @param [opts.allowedHosts] if included, only allow requests from these hosts
1096
- * (start a hostname with a "*" to only check the end of the hostname)
1097
- * you can include just one string instead of an array
1098
- * @param [opts.bannedHosts] if included, do not allow requests from these hosts
1099
- * (start a hostname with a "*" to only check the end of the hostname)
1100
- * you can include just one string instead of an array
1101
- * @param [opts.unhandledErrorMessagePrefix] if included, when an error that
1102
- * is not of type ErrorWithCode is thrown, the client will receive an error
1103
- * where the error message is prefixed with this string. For example,
1104
- * if unhandledErrorMessagePrefix is
1105
- * 'While saving progress, we encountered an error:'
1106
- * and the error is 'progressInfo is not an object',
1107
- * the client will receive an error with the message
1108
- * 'While saving progress, we encountered an error: progressInfo is not an object'
1109
- * @returns express route handler that takes the following arguments:
1110
- * params (map: param name => value),
1111
- * req (express request object),
1112
- * next (express next function),
1113
- * send (a function that sends a string to the client),
1114
- * redirect (takes a url and redirects the user to that url),
1115
- * renderErrorPage (shows a static error page to the user),
1116
- * renderInfoPage (shows a static info page to the user),
1117
- * renderCustomHTML (renders custom html and sends it to the user),
1118
- * and returns the value to send to the client as a JSON API response, or
1119
- * calls next() or redirect(...) or send(...) or renderErrorPage(...).
1120
- * Note: params also has userId, userFirstName,
1121
- * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
1122
- * and any other variables that
1123
- * are directly added to the session, if the user does have a session.
1124
- */
1125
- declare const genRouteHandler: (opts: {
1126
- paramTypes?: {
1127
- [k: string]: ParamType;
1128
- } | undefined;
1129
- handler: (opts: {
1130
- params: {
1131
- [k: string]: any;
1132
- };
1133
- req: any;
1134
- next: () => void;
1135
- redirect: (pathOrURL: string) => void;
1136
- send: (text: string, status?: number) => void;
1137
- renderErrorPage: (opts?: {
1138
- title?: string;
1139
- description?: string;
1140
- code?: string;
1141
- pageTitle?: string;
1142
- status?: number;
1143
- }) => void;
1144
- renderInfoPage: (opts: {
1145
- title: string;
1146
- body: string;
1147
- }) => void;
1148
- renderCustomHTML: (opts: {
1149
- html: string;
1150
- status?: number;
1151
- }) => void;
1152
- logServerEvent: LogFunction;
1153
- }) => any;
1154
- skipSessionCheck?: boolean | undefined;
1155
- allowedHosts?: string | string[] | undefined;
1156
- bannedHosts?: string | string[] | undefined;
1157
- unhandledErrorMessagePrefix?: string | undefined;
1158
- }) => (req: any, res: any, next: () => void) => Promise<undefined>;
1159
-
1160
- /**
1161
- * Handle an error and respond to the client
1162
- * @author Gabe Abrams
1163
- * @param res express response
1164
- * @param error error info
1165
- * @param opts.err the error to send to the client
1166
- * or the error message
1167
- * @param [opts.code] an error code (only used if err.code is not
1168
- * included)
1169
- * @param [opts.status=500] the https status code to use
1170
- * defined)
1171
- */
1172
- declare const handleError: (res: any, error: ({
1173
- message: any;
1174
- code?: string;
1175
- status?: number;
1176
- } | Error | string | any)) => undefined;
1177
-
1178
- /**
1179
- * Send successful API response
1180
- * @author Gabe Abrams
1181
- * @param res express response
1182
- * @param body the body of the response to send to the client
1183
- */
1184
- declare const handleSuccess: (res: any, body: any) => undefined;
1185
-
1186
- type GetLaunchInfoFunction = (req: any) => {
1187
- launched: boolean;
1188
- launchInfo?: any;
1189
- };
1190
- /**
1191
- * Prepare dce-reactkit to run on the server
1192
- * @author Gabe Abrams
1193
- * @param opts object containing all arguments
1194
- * @param opts.app express app from inside of the postprocessor function that
1195
- * we will add routes to
1196
- * @param opts.getLaunchInfo CACCL LTI's get launch info function
1197
- * @param [opts.logCollection] mongo collection from dce-mango to use for
1198
- * storing logs. If none is included, logs are written to the console
1199
- * @param [opts.logReviewAdmins=all] info on which admins can review
1200
- * logs from the client. If not included, all Canvas admins are allowed to
1201
- * review logs. If null, no Canvas admins are allowed to review logs.
1202
- * If an array of Canvas userIds (numbers), only Canvas admins with those
1203
- * userIds are allowed to review logs. If a dce-mango collection, only
1204
- * Canvas admins with entries in that collection ({ userId, ...}) are allowed
1205
- * to review logs
1206
- */
1207
- declare const initServer: (opts: {
1208
- app: any;
1209
- getLaunchInfo: GetLaunchInfoFunction;
1210
- logCollection?: any;
1211
- logReviewAdmins?: (number[] | any);
1212
- }) => void;
1213
-
1214
- /**
1215
- * Get a number's ordinal
1216
- * @author Gabe Abrams
1217
- * @param num the number being analyzed
1218
- * @returns ordinal
1219
- */
1220
- declare const getOrdinal: (num: number) => string;
1221
-
1222
- /**
1223
- * Get current time info in US Boston Eastern Time, independent of machine
1224
- * timezone
1225
- * @author Gabe Abrams
1226
- * @param [dateOrTimestamp=now] the date to get info on or a ms since epoch timestamp
1227
- * @returns object with timestamp (ms since epoch) and numbers
1228
- * corresponding to ET time values for year, month, day, hour, hour12, minute, isPM
1229
- * where hour is in 24hr time and hour12 is in 12hr time.
1230
- */
1231
- declare const getTimeInfoInET: (dateOrTimestamp?: Date | number) => {
1232
- timestamp: number;
1233
- year: number;
1234
- month: number;
1235
- day: number;
1236
- hour: number;
1237
- hour12: number;
1238
- minute: number;
1239
- isPM: boolean;
1240
- };
1241
-
1242
- /**
1243
- * Stub a server endpoint response
1244
- * @author Gabe Abrams
1245
- * @param opts object containing all arguments
1246
- * @param [opts.method=GET] http method to stub
1247
- * @param opts.path full pathname to stub
1248
- * @param opts.body body of response if stubbing a successful response
1249
- * @param opts.errorMessage message of error if stubbing a failed response
1250
- * @param [opts.errorCode] error code if stubbing a failed response
1251
- */
1252
- declare const stubServerEndpoint: (opts: {
1253
- method?: string | undefined;
1254
- path: string;
1255
- body?: any;
1256
- errorMessage?: string | undefined;
1257
- errorCode?: string | undefined;
1258
- }) => void;
1259
-
1260
- /**
1261
- * Start a dynamic wait, call the function once the operation has completed and
1262
- * the dynamic wait will continue waiting for the rest of the minimum time
1263
- * @author Gabe Abrams
1264
- * @param minWaitMs the minimum number of ms to wait
1265
- * @returns async function to call to finish the wait
1266
- */
1267
- declare const startMinWait: (minWaitMs: number) => () => Promise<void>;
1268
-
1269
- /**
1270
- * Get a human-readable description of a date (all in ET)
1271
- * @author Gabe Abrams
1272
- * @param [dateOrTimestamp=today] the date or timestamp for the date to describe
1273
- * @returns human-readable description of the date
1274
- */
1275
- declare const getHumanReadableDate: (dateOrTimestamp?: Date | number) => string;
1276
-
1277
- /**
1278
- * Get the current part of day (morning, evening, etc.)
1279
- * @author Gabe Abrams
1280
- * @returns the part of day (morning, evening, etc.)
1281
- */
1282
- declare const getPartOfDay: () => string;
1283
-
1284
- /**
1285
- * Create a human readable list from an array of strings.
1286
- * For example, ['apple', 'orange'] becomes "apple and orange"
1287
- * and ['apple', 'orange', 'mango'] becomes "apple, orange, and mango"
1288
- * @author Gabe Abrams
1289
- * @param items list of items in the list
1290
- * @returns human-readable list
1291
- */
1292
- declare const stringsToHumanReadableList: (items: string[]) => string;
1293
-
1294
- /**
1295
- * Given a string, only keep the letters inside it
1296
- * @author Gabe Abrams
1297
- * @param str the string to parse
1298
- * @returns only the letters inside of the string
1299
- */
1300
- declare const onlyKeepLetters: (str: string) => string;
1301
-
1302
- /**
1303
- * Run tasks in parallel with a limit on how many tasks can execute at once.
1304
- * No guarantees are made about the order of task execution
1305
- * @author Gabe Abrams
1306
- * @param taskFunctions functions that start asynchronous tasks and optionally
1307
- * resolve with values
1308
- * @param [limit=no limit] maximum number of asynchronous tasks to permit to run at
1309
- * once
1310
- * @returns array of resolved values in the same order as the task functions
1311
- */
1312
- declare const parallelLimit: (taskFunctions: (() => Promise<any>)[], limit?: number) => Promise<any[]>;
1313
-
1314
1181
  type MetadataPopulator = () => {
1315
1182
  [k: string]: any;
1316
1183
  } | Promise<{
@@ -1331,14 +1198,6 @@ declare const setClientEventMetadataPopulator: (newMetadataPopulator: MetadataPo
1331
1198
  */
1332
1199
  declare const logClientEvent: LogFunction;
1333
1200
 
1334
- /**
1335
- * Initialize a log collection given the dce-mango Collection class
1336
- * @author Gabe Abrams
1337
- * @param Collection the Collection class from dce-mango
1338
- * @returns initialized logCollection
1339
- */
1340
- declare const initLogCollection: (Collection: any) => any;
1341
-
1342
1201
  /**
1343
1202
  * Get the name of a month given the month number (1 = January, etc.)
1344
1203
  * If an invalid number is provided, we will treat it like January
@@ -1425,46 +1284,6 @@ declare const getLocalTimeInfo: (dateOrTimestamp?: Date | number) => {
1425
1284
  isPM: boolean;
1426
1285
  };
1427
1286
 
1428
- /**
1429
- * Interface for a collection in the database
1430
- * @author Yuen Ler Chow
1431
- */
1432
- type DCEMangoCollection = {
1433
- /**
1434
- * Find all items in the collection that match the filter query
1435
- * @param filterQuery query for the filter
1436
- * @returns list of items that match the filter query
1437
- */
1438
- find: (filterQuery: any) => Promise<any[]>;
1439
- /**
1440
- * Insert an item into the collection
1441
- * @param item the item to insert
1442
- */
1443
- insert: (item: any) => Promise<void>;
1444
- /**
1445
- * Delete an item in the collection
1446
- * @param id the id of the item to delete
1447
- */
1448
- delete: (filterQuery: {
1449
- id: string;
1450
- }) => Promise<void>;
1451
- };
1452
- /**
1453
- * Add all routes for the DBEditor
1454
- * @author Yuen Ler Chow
1455
- * @param opts object containing all arguments
1456
- * @param opts.app express app to add routes too
1457
- * @param opts.collectionName the name of the collection
1458
- * @param opts.adminsOnly true if the endpoint is for admins only
1459
- * @param opts.collection dce-mango db collection
1460
- */
1461
- declare const addDBEditorEndpoints: (opts: {
1462
- app: express.Application;
1463
- collectionName: string;
1464
- adminsOnly: boolean;
1465
- collection: DCEMangoCollection;
1466
- }) => void;
1467
-
1468
1287
  /**
1469
1288
  * Given an array of strings, create a single comma-separated string that includes
1470
1289
  * 'and' as well as an oxford comma.
@@ -1659,65 +1478,6 @@ declare const capitalize: (str: string) => string;
1659
1478
  */
1660
1479
  declare const shuffleArray: <T>(arr: T[]) => T[];
1661
1480
 
1662
- /**
1663
- * Send a server-to-server request from this sever to another server that uses
1664
- * dce-reactkit [for server only]
1665
- * @author Gabe Abrams
1666
- * @param opts object containing all arguments
1667
- * @param opts.host - the host of the other server
1668
- * @param opts.path - the path of the other server's endpoint
1669
- * @param [opts.method=GET] - the method of the endpoint
1670
- * @param [opts.params] - query/body parameters to include
1671
- * @param [opts.headers] - headers to include
1672
- * @returns response from server
1673
- */
1674
- declare const visitEndpointOnAnotherServer: (opts: {
1675
- host: string;
1676
- path: string;
1677
- method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
1678
- params?: {
1679
- [x: string]: any;
1680
- } | undefined;
1681
- headers?: {
1682
- [x: string]: any;
1683
- } | undefined;
1684
- }) => Promise<any>;
1685
-
1686
- /**
1687
- * Get number of words in string
1688
- * @author Gardenia Liu
1689
- * @author Allison Zhang
1690
- * @author Gabe Abrams
1691
- * @param text the string to check
1692
- * @returns number of words in the string
1693
- */
1694
- declare const getWordCount: (text: string) => number;
1695
-
1696
- /**
1697
- * List of error codes built into the react kit
1698
- * @author Gabe Abrams
1699
- */
1700
- declare enum ReactKitErrorCode {
1701
- NoResponse = "DRK1",
1702
- NoCode = "DRK2",
1703
- SessionExpired = "DRK3",
1704
- MissingParameter = "DRK4",
1705
- InvalidParameter = "DRK5",
1706
- HostNotAllowed = "DRK17",
1707
- HostBanned = "DRK18",
1708
- WrongCourse = "DRK6",
1709
- NoCACCLSendRequestFunction = "DRK7",
1710
- NoCACCLGetLaunchInfoFunction = "DRK8",
1711
- NotTTM = "DRK9",
1712
- NotAdmin = "DRK10",
1713
- NotAllowedToReviewLogs = "DRK11",
1714
- ThemeCheckedBeforeReactKitReady = "DRK12",
1715
- SessionExpiredMessageGottenBeforeReactKitReady = "DRK13",
1716
- NotConnected = "DRK14",
1717
- SelfSigned = "DRK15",
1718
- ResponseParseError = "DRK16"
1719
- }
1720
-
1721
1481
  /**
1722
1482
  * Days of the week
1723
1483
  * @author Gabe Abrams
@@ -1748,4 +1508,15 @@ declare const LogBuiltInMetadata: {
1748
1508
  };
1749
1509
  };
1750
1510
 
1751
- export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, Dropdown, DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogFunction, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, getWordCount, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
1511
+ /**
1512
+ * List of error codes built into the react kit
1513
+ * @author Gabe Abrams
1514
+ */
1515
+ declare enum ReactKitErrorCode {
1516
+ NoResponse = "DRK1",
1517
+ NoCode = "DRK2",
1518
+ SessionExpired = "DRK3",
1519
+ NoCACCLSendRequestFunction = "DRK7"
1520
+ }
1521
+
1522
+ export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, Dropdown, DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogFunction, LogLevel, LogMainInfo, LogMetadataType, LogReviewer, LogSource, LogSourceSpecificInfo, LogType, LogTypeSpecificInfo, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, idify, initClient, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
@@ -0,0 +1,84 @@
1
+ // Import crypto lib
2
+ import crypto from 'crypto';
3
+
4
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
5
+
6
+ // Get args
7
+ const REACTKIT_CRED_ENCODING_SALT = process.env.npm_config_salt;
8
+ if (!REACTKIT_CRED_ENCODING_SALT) {
9
+ console.log('Encoding salt is required: --salt=...');
10
+ process.exit(1);
11
+ }
12
+
13
+ // Get the key
14
+ let key = process.env.npm_config_key;
15
+ if (!key) {
16
+ console.log('Key is required: --key=...');
17
+ process.exit(1);
18
+ }
19
+
20
+ // Get the description
21
+ let description = process.env.npm_config_description;
22
+ if (!description) {
23
+ console.log('Description is required: --description=...');
24
+ process.exit(1);
25
+ }
26
+
27
+ // Get secret
28
+ let secret = process.env.npm_config_secret;
29
+ if (!secret) {
30
+ // Generate a random secret
31
+ secret = '';
32
+ for (let i = 0; i < 32; i++) {
33
+ secret += chars.charAt(Math.floor(Math.random() * chars.length));
34
+ }
35
+ console.log('Generated a random secret. If you have one in mind, use --secret=...');
36
+ }
37
+
38
+ // Get the host name
39
+ const host = process.env.npm_config_host;
40
+ if (!host) {
41
+ console.log('Host of the receiving server is required: --host=...');
42
+ process.exit(1);
43
+ }
44
+
45
+ // Encryption process based on:
46
+ // https://medium.com/@tony.infisical/guide-to-nodes-crypto-module-for-encryption-decryption-65c077176980
47
+
48
+ // Create a random initialization vector
49
+ const iv = crypto.randomBytes(12).toString('base64');
50
+
51
+ // Create a cipher
52
+ const cipher = crypto.createCipheriv(
53
+ 'aes-256-gcm',
54
+ Buffer.from(secret, 'base64'),
55
+ Buffer.from(iv, 'base64'),
56
+ );
57
+
58
+ // Encrypt the string
59
+ let ciphertext = cipher.update(secret, 'utf8', 'base64');
60
+
61
+ // Finalize the encryption
62
+ ciphertext += cipher.final('base64');
63
+
64
+ // Get the authentication tag
65
+ const tag = cipher.getAuthTag();
66
+
67
+ // JSONify the encrypted data
68
+ const encryptionPack = encodeURIComponent(JSON.stringify({
69
+ ciphertext,
70
+ iv,
71
+ tag,
72
+ }));
73
+
74
+ // Show the encrypted data
75
+ console.log('\n\n');
76
+ console.log('––––– Done! What\'s Next: –––––');
77
+ console.log('');
78
+ console.log('On the server *sending* the requests, append the following to the REACTKIT_CROSS_SERVER_CREDENTIALS env var:');
79
+ console.log(`|${host}:${key}:${secret}|`);
80
+ console.log('');
81
+ console.log('On the server *receiving* the requests, add an entry to the "CrossServerCredential" collection:');
82
+ console.log(`{ "description": "${description}", "key": "${key}", "encodedeSecret": "${encryptionPack}", "scopes": [] }`);
83
+ console.log('');
84
+ console.log('For all scopes that the server should have access to, add them to the "scopes" array.');
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.12.3",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
9
  "build": "rm -rf dist && rollup -c",
10
- "test": "jest --runInBand"
10
+ "test": "jest --runInBand",
11
+ "gen-reactkit-cross-server-secret": "npx tsx genEncodedSecret.ts"
11
12
  },
12
13
  "jest": {
13
14
  "preset": "ts-jest",
@@ -24,7 +25,6 @@
24
25
  },
25
26
  "homepage": "https://github.com/harvard-edtech/dce-reactkit#readme",
26
27
  "dependencies": {
27
- "qs": "^6.x.x",
28
28
  "react-select": "^5.7.3"
29
29
  },
30
30
  "peerDependencies": {
@@ -45,11 +45,13 @@
45
45
  "@types/bootstrap": "^5.2.8",
46
46
  "@types/express": "^4.17.17",
47
47
  "@types/jest": "^28.1.7",
48
+ "@types/jwt-simple": "^0.5.36",
48
49
  "@types/node": "^20.2.5",
50
+ "@types/oauth-signature": "^1.5.2",
49
51
  "@types/react": "^17.0.7",
50
52
  "@typescript-eslint/eslint-plugin": "^5.59.9",
51
53
  "@typescript-eslint/parser": "^5.59.9",
52
- "eslint": "^8.42.0",
54
+ "eslint": "^8.57.1",
53
55
  "eslint-config-airbnb": "^19.0.4",
54
56
  "eslint-config-airbnb-typescript": "^17.0.0",
55
57
  "eslint-plugin-import": "^2.27.5",
@@ -58,7 +60,7 @@
58
60
  "eslint-plugin-react-hooks": "^4.6.0",
59
61
  "jest": "^28.1.3",
60
62
  "jest-environment-jsdom": "^28.1.3",
61
- "raixa": "^1.0.21",
63
+ "oauth-signature": "^1.5.0",
62
64
  "rollup": "^2.70.2",
63
65
  "rollup-plugin-dts": "^4.2.1",
64
66
  "rollup-plugin-sourcemaps": "^0.6.3",
package/rollup.config.js CHANGED
@@ -27,6 +27,7 @@ export default [
27
27
  typescript({ tsconfig: "./tsconfig.json" }),
28
28
  sourcemaps(),
29
29
  ],
30
+ inlineDynamicImports: true,
30
31
  external: [
31
32
  ...Object.keys(packageJson.dependencies || {}),
32
33
  ...Object.keys(packageJson.peerDependencies || {}),
@@ -36,6 +37,7 @@ export default [
36
37
  input: "dist/esm/types/index.d.ts",
37
38
  output: [{ file: "dist/index.d.ts", format: "esm" }],
38
39
  plugins: [dts()],
40
+ inlineDynamicImports: true,
39
41
  external: [
40
42
  ...Object.keys(packageJson.dependencies || {}),
41
43
  ...Object.keys(packageJson.peerDependencies || {}),