dce-reactkit 3.12.1-beta-cross-server.8 → 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 (92) hide show
  1. package/.vscode/settings.json +3 -1
  2. package/README.md +0 -20
  3. package/dist/cjs/index.js +7838 -15905
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/types/components/ItemPicker/index.d.ts +1 -0
  6. package/dist/cjs/types/components/LoadingSpinner.d.ts +2 -2
  7. package/dist/cjs/types/components/Modal/ModalProps.d.ts +2 -0
  8. package/dist/cjs/types/components/SimpleDateChooser.d.ts +3 -1
  9. package/dist/cjs/types/components/SimpleTimeChooser.d.ts +20 -0
  10. package/dist/cjs/types/components/TabBox.d.ts +1 -0
  11. package/dist/cjs/types/components/Tooltip.d.ts +1 -1
  12. package/dist/cjs/types/helpers/getWordCount.d.ts +10 -0
  13. package/dist/cjs/types/index.d.ts +13 -13
  14. package/dist/cjs/types/types/ParamType.d.ts +10 -10
  15. package/dist/cjs/types/types/ReactKitErrorCode.d.ts +2 -28
  16. package/dist/esm/index.js +6661 -14723
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/types/components/ItemPicker/index.d.ts +1 -0
  19. package/dist/esm/types/components/LoadingSpinner.d.ts +2 -2
  20. package/dist/esm/types/components/Modal/ModalProps.d.ts +2 -0
  21. package/dist/esm/types/components/SimpleDateChooser.d.ts +3 -1
  22. package/dist/esm/types/components/SimpleTimeChooser.d.ts +20 -0
  23. package/dist/esm/types/components/TabBox.d.ts +1 -0
  24. package/dist/esm/types/components/Tooltip.d.ts +1 -1
  25. package/dist/esm/types/helpers/getWordCount.d.ts +10 -0
  26. package/dist/esm/types/index.d.ts +13 -13
  27. package/dist/esm/types/types/ParamType.d.ts +10 -10
  28. package/dist/esm/types/types/ReactKitErrorCode.d.ts +2 -28
  29. package/dist/index.d.ts +189 -379
  30. package/package.json +5 -11
  31. package/src/components/AppWrapper.tsx +3 -1
  32. package/src/components/CheckboxButton.tsx +1 -1
  33. package/src/components/Dropdown.tsx +1 -1
  34. package/src/components/IntelliTable.tsx +1 -1
  35. package/src/components/ItemPicker/NestableItemList.tsx +1 -0
  36. package/src/components/ItemPicker/index.tsx +96 -0
  37. package/src/components/LogReviewer.tsx +2 -2
  38. package/src/components/Modal/ModalProps.ts +4 -0
  39. package/src/components/Modal/index.tsx +60 -21
  40. package/src/components/RadioButton.tsx +3 -1
  41. package/src/components/SimpleDateChooser.tsx +62 -26
  42. package/src/components/SimpleTimeChooser.tsx +195 -0
  43. package/src/components/TabBox.tsx +27 -9
  44. package/src/components/Tooltip.tsx +1 -1
  45. package/src/helpers/getWordCount.ts +26 -0
  46. package/src/{client → helpers}/initClient.tsx +5 -1
  47. package/src/helpers/logClientEvent.tsx +3 -1
  48. package/src/helpers/visitServerEndpoint.tsx +1 -1
  49. package/src/index.ts +22 -24
  50. package/src/types/ParamType.ts +10 -10
  51. package/src/types/ReactKitErrorCode.tsx +3 -31
  52. package/dist/cjs/types/components/ItemPicker/index.test.d.ts +0 -1
  53. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +0 -41
  54. package/dist/cjs/types/helpers/dataSigner.d.ts +0 -40
  55. package/dist/cjs/types/helpers/genRouteHandler.d.ts +0 -76
  56. package/dist/cjs/types/helpers/handleError.d.ts +0 -18
  57. package/dist/cjs/types/helpers/handleSuccess.d.ts +0 -8
  58. package/dist/cjs/types/helpers/parseUserAgent.d.ts +0 -17
  59. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -20
  60. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -27
  61. package/dist/cjs/types/server/initCrossServerCredentialCollection.d.ts +0 -8
  62. package/dist/cjs/types/server/initLogCollection.d.ts +0 -8
  63. package/dist/cjs/types/server/initServer.d.ts +0 -53
  64. package/dist/cjs/types/types/CrossServerCredential.d.ts +0 -11
  65. package/dist/esm/types/components/ItemPicker/index.test.d.ts +0 -1
  66. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +0 -41
  67. package/dist/esm/types/helpers/dataSigner.d.ts +0 -40
  68. package/dist/esm/types/helpers/genRouteHandler.d.ts +0 -76
  69. package/dist/esm/types/helpers/handleError.d.ts +0 -18
  70. package/dist/esm/types/helpers/handleSuccess.d.ts +0 -8
  71. package/dist/esm/types/helpers/parseUserAgent.d.ts +0 -17
  72. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -20
  73. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -27
  74. package/dist/esm/types/server/initCrossServerCredentialCollection.d.ts +0 -8
  75. package/dist/esm/types/server/initLogCollection.d.ts +0 -8
  76. package/dist/esm/types/server/initServer.d.ts +0 -53
  77. package/dist/esm/types/types/CrossServerCredential.d.ts +0 -11
  78. package/src/components/ItemPicker/index.test.tsx +0 -783
  79. package/src/helpers/addDBEditorEndpoints.ts +0 -128
  80. package/src/helpers/dataSigner.ts +0 -342
  81. package/src/helpers/genRouteHandler.ts +0 -911
  82. package/src/helpers/handleError.ts +0 -65
  83. package/src/helpers/handleSuccess.ts +0 -18
  84. package/src/helpers/parseUserAgent.ts +0 -108
  85. package/src/helpers/visitEndpointOnAnotherServer/index.ts +0 -152
  86. package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +0 -162
  87. package/src/server/initCrossServerCredentialCollection.ts +0 -16
  88. package/src/server/initLogCollection.ts +0 -27
  89. package/src/server/initServer.ts +0 -305
  90. package/src/types/CrossServerCredential.ts +0 -16
  91. /package/dist/cjs/types/{client → helpers}/initClient.d.ts +0 -0
  92. /package/dist/esm/types/{client → helpers}/initClient.d.ts +0 -0
@@ -1,305 +0,0 @@
1
- // Import custom error
2
- import ErrorWithCode from '../errors/ErrorWithCode';
3
-
4
- // Import shared constants
5
- import LOG_REVIEW_ROUTE_PATH_PREFIX from '../constants/LOG_REVIEW_ROUTE_PATH_PREFIX';
6
- import LOG_ROUTE_PATH from '../constants/LOG_ROUTE_PATH';
7
- import LOG_REVIEW_STATUS_ROUTE from '../constants/LOG_REVIEW_STATUS_ROUTE';
8
-
9
- // Import shared helpers
10
- import genRouteHandler from '../helpers/genRouteHandler';
11
-
12
- // Import shared types
13
- import Log from '../types/Log';
14
- import LogFunction from '../types/LogFunction';
15
- import ParamType from '../types/ParamType';
16
- import ReactKitErrorCode from '../types/ReactKitErrorCode';
17
-
18
- // Types
19
- type GetLaunchInfoFunction = (req: any) => {
20
- launched: boolean,
21
- launchInfo?: any,
22
- };
23
-
24
- // Stored copy of caccl functions
25
- let _cacclGetLaunchInfo: GetLaunchInfoFunction;
26
-
27
- // Stored copy of dce-mango log collection
28
- let _logCollection: any;
29
-
30
- // Stored copy of dce-mango cross-server credential collection
31
- let _crossServerCredentialCollection: any;
32
-
33
- /*------------------------------------------------------------------------*/
34
- /* Helpers */
35
- /*------------------------------------------------------------------------*/
36
-
37
- /**
38
- * Get launch info via CACCL
39
- * @author Gabe Abrams
40
- * @param req express request object
41
- * @returns object { launched, launchInfo }
42
- */
43
- export const cacclGetLaunchInfo: GetLaunchInfoFunction = (req: any) => {
44
- if (!_cacclGetLaunchInfo) {
45
- throw new ErrorWithCode(
46
- 'Could not get launch info because server was not initialized with dce-reactkit\'s initServer function',
47
- ReactKitErrorCode.NoCACCLGetLaunchInfoFunction,
48
- );
49
- }
50
-
51
- return _cacclGetLaunchInfo(req);
52
- };
53
-
54
- /**
55
- * Get log collection
56
- * @author Gabe Abrams
57
- * @returns log collection if one was included during launch or null if we don't
58
- * have a log collection (yet)
59
- */
60
- export const internalGetLogCollection = () => {
61
- return _logCollection ?? null;
62
- };
63
-
64
- /**
65
- * Get cross-server credential collection
66
- * @author Gabe Abrams
67
- * @return cross-server credential collection if one was included during launch or null
68
- * if we don't have a cross-server credential collection (yet)
69
- */
70
- export const internalGetCrossServerCredentialCollection = () => {
71
- return _crossServerCredentialCollection ?? null;
72
- };
73
-
74
- /*------------------------------------------------------------------------*/
75
- /* Main */
76
- /*------------------------------------------------------------------------*/
77
-
78
- /**
79
- * Prepare dce-reactkit to run on the server
80
- * @author Gabe Abrams
81
- * @param opts object containing all arguments
82
- * @param opts.app express app from inside of the postprocessor function that
83
- * we will add routes to
84
- * @param opts.getLaunchInfo CACCL LTI's get launch info function
85
- * @param [opts.logCollection] mongo collection from dce-mango to use for
86
- * storing logs. If none is included, logs are written to the console
87
- * @param [opts.logReviewAdmins=all] info on which admins can review
88
- * logs from the client. If not included, all Canvas admins are allowed to
89
- * review logs. If null, no Canvas admins are allowed to review logs.
90
- * If an array of Canvas userIds (numbers), only Canvas admins with those
91
- * userIds are allowed to review logs. If a dce-mango collection, only
92
- * Canvas admins with entries in that collection ({ userId, ...}) are allowed
93
- * to review logs
94
- * @param [opts.crossServerCredentialCollection] mongo collection from dce-mango to use for
95
- * storing cross-server credentials. If none is included, cross-server credentials
96
- * are not supported
97
- */
98
- const initServer = (
99
- opts: {
100
- app: any,
101
- getLaunchInfo: GetLaunchInfoFunction,
102
- logCollection?: any,
103
- logReviewAdmins?: (number[] | any),
104
- crossServerCredentialCollection?: any,
105
- },
106
- ) => {
107
- _cacclGetLaunchInfo = opts.getLaunchInfo;
108
- _logCollection = opts.logCollection;
109
- _crossServerCredentialCollection = opts.crossServerCredentialCollection;
110
-
111
- /*----------------------------------------*/
112
- /* Logging */
113
- /*----------------------------------------*/
114
-
115
- /**
116
- * Log an event
117
- * @author Gabe Abrams
118
- * @param {string} context Context of the event (each app determines how to
119
- * organize its contexts)
120
- * @param {string} subcontext Subcontext of the event (each app determines
121
- * how to organize its subcontexts)
122
- * @param {string} tags stringified list of tags that apply to this action
123
- * (each app determines tag usage)
124
- * @param {string} metadata stringified object containing optional custom metadata
125
- * @param {string} level log level
126
- * @param {string} [errorMessage] error message if type is an error
127
- * @param {string} [errorCode] error code if type is an error
128
- * @param {string} [errorStack] error stack if type is an error
129
- * @param {string} [target] Target of the action (each app determines the list
130
- * of targets) These are usually buttons, panels, elements, etc.
131
- * @param {LogAction} [action] the type of action performed on the target
132
- * @returns {Log}
133
- */
134
- opts.app.post(
135
- LOG_ROUTE_PATH,
136
- genRouteHandler({
137
- paramTypes: {
138
- context: ParamType.String,
139
- subcontext: ParamType.String,
140
- tags: ParamType.JSON,
141
- level: ParamType.String,
142
- metadata: ParamType.JSON,
143
- errorMessage: ParamType.StringOptional,
144
- errorCode: ParamType.StringOptional,
145
- errorStack: ParamType.StringOptional,
146
- target: ParamType.StringOptional,
147
- action: ParamType.StringOptional,
148
- },
149
- handler: ({ params, logServerEvent }) => {
150
- // Create log info
151
- const logInfo: Parameters<LogFunction>[0] = (
152
- (params.errorMessage || params.errorCode || params.errorStack)
153
- // Error
154
- ? {
155
- context: params.context,
156
- subcontext: params.subcontext,
157
- tags: params.tags,
158
- level: params.level,
159
- metadata: params.metadata,
160
- error: {
161
- message: params.errorMessage,
162
- code: params.errorCode,
163
- stack: params.errorStack,
164
- },
165
- }
166
- // Action
167
- : {
168
- context: params.context,
169
- subcontext: params.subcontext,
170
- tags: params.tags,
171
- level: params.level,
172
- metadata: params.metadata,
173
- target: params.target,
174
- action: params.action,
175
- }
176
- );
177
-
178
- // Add hidden boolean to change source to "client"
179
- const logInfoForcedFromClient = {
180
- ...logInfo,
181
- overrideAsClientEvent: true,
182
- };
183
-
184
- // Write the log
185
- const log = logServerEvent(logInfoForcedFromClient);
186
-
187
- // Return
188
- return log;
189
- },
190
- }),
191
- );
192
-
193
- /*----------------------------------------*/
194
- /* Log Reviewer */
195
- /*----------------------------------------*/
196
-
197
- /**
198
- * Check if a given user is allowed to review logs
199
- * @author Gabe Abrams
200
- * @param userId the id of the user
201
- * @param isAdmin if true, the user is an admin
202
- * @returns true if the user can review logs
203
- */
204
- const canReviewLogs = async (
205
- userId: number,
206
- isAdmin: boolean,
207
- ): Promise<boolean> => {
208
- // Immediately deny access if user is not an admin
209
- if (!isAdmin) {
210
- return false;
211
- }
212
-
213
- // If all admins are allowed, we're done
214
- if (!opts.logReviewAdmins) {
215
- return true;
216
- }
217
-
218
- // Do a dynamic check
219
- try {
220
- // Array of userIds
221
- if (Array.isArray(opts.logReviewAdmins)) {
222
- return opts.logReviewAdmins.some((allowedId) => {
223
- return (userId === allowedId);
224
- });
225
- }
226
-
227
- // Must be a collection
228
- const matches = await opts.logReviewAdmins.find({ userId });
229
-
230
- // Make sure at least one entry matches
231
- return matches.length > 0;
232
- } catch (err) {
233
- // If an error occurred, simply return false
234
- return false;
235
- }
236
- };
237
-
238
- /**
239
- * Check if the current user has access to logs
240
- * @author Gabe Abrams
241
- * @returns {boolean} true if user has access
242
- */
243
- opts.app.get(
244
- LOG_REVIEW_STATUS_ROUTE,
245
- genRouteHandler({
246
- handler: async ({ params }) => {
247
- const { userId, isAdmin } = params;
248
- const canReview = await canReviewLogs(userId, isAdmin);
249
- return canReview;
250
- },
251
- }),
252
- );
253
-
254
- /**
255
- * Get all logs for a certain month
256
- * @author Gabe Abrams
257
- * @param {number} year the year to query (e.g. 2022)
258
- * @param {number} month the month to query (e.g. 1 = January)
259
- * @returns {Log[]} list of logs from the given month
260
- */
261
- opts.app.get(
262
- `${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/:year/months/:month`,
263
- genRouteHandler({
264
- paramTypes: {
265
- year: ParamType.Int,
266
- month: ParamType.Int,
267
- pageNumber: ParamType.Int,
268
- },
269
- handler: async ({ params }) => {
270
- // Get user info
271
- const {
272
- year,
273
- month,
274
- pageNumber,
275
- userId,
276
- isAdmin,
277
- } = params;
278
-
279
- // Validate user
280
- const canReview = await canReviewLogs(userId, isAdmin);
281
- if (!canReview) {
282
- throw new ErrorWithCode(
283
- 'You cannot access this resource because you do not have the appropriate permissions.',
284
- ReactKitErrorCode.NotAllowedToReviewLogs,
285
- );
286
- }
287
-
288
- // Query for logs
289
- const response = await _logCollection.findPaged({
290
- query: {
291
- year,
292
- month,
293
- },
294
- perPage: 1000,
295
- pageNumber,
296
- });
297
-
298
- // Return response
299
- return response;
300
- },
301
- }),
302
- );
303
- };
304
-
305
- export default initServer;
@@ -1,16 +0,0 @@
1
- /**
2
- * Single cross-server credential
3
- * @author Gabe Abrams
4
- */
5
- type CrossServerCredential = {
6
- // Description of the credential (human-readable)
7
- description: string,
8
- // The key of the credential
9
- key: string,
10
- // The encoded secret of the credential
11
- encodedeSecret: string,
12
- // The list of scopes for the credential
13
- scopes: string[],
14
- };
15
-
16
- export default CrossServerCredential;