dce-reactkit 3.1.20 → 3.2.0-beta.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 +405 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/constants/LOG_ROUTE_PATH.d.ts +6 -0
- package/dist/cjs/types/constants/ROUTE_PATH_PREFIX.d.ts +6 -0
- package/dist/cjs/types/helpers/genRouteHandler.d.ts +2 -0
- package/dist/cjs/types/helpers/logClientEvent.d.ts +7 -0
- package/dist/cjs/types/helpers/parseUserAgent.d.ts +17 -0
- package/dist/cjs/types/index.d.ts +6 -1
- package/dist/cjs/types/server/initServer.d.ts +13 -0
- package/dist/cjs/types/types/Log/LogMainInfo.d.ts +37 -0
- package/dist/cjs/types/types/Log/LogSourceSpecificInfo.d.ts +13 -0
- package/dist/cjs/types/types/Log/LogTypeSpecificInfo.d.ts +17 -0
- package/dist/cjs/types/types/Log/index.d.ts +10 -0
- package/dist/cjs/types/types/LogAction.d.ts +22 -0
- package/dist/cjs/types/types/LogFunction.d.ts +24 -0
- package/dist/cjs/types/types/LogSource.d.ts +9 -0
- package/dist/cjs/types/types/LogType.d.ts +9 -0
- package/dist/esm/index.js +402 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/constants/LOG_ROUTE_PATH.d.ts +6 -0
- package/dist/esm/types/constants/ROUTE_PATH_PREFIX.d.ts +6 -0
- package/dist/esm/types/helpers/genRouteHandler.d.ts +2 -0
- package/dist/esm/types/helpers/logClientEvent.d.ts +7 -0
- package/dist/esm/types/helpers/parseUserAgent.d.ts +17 -0
- package/dist/esm/types/index.d.ts +6 -1
- package/dist/esm/types/server/initServer.d.ts +13 -0
- package/dist/esm/types/types/Log/LogMainInfo.d.ts +37 -0
- package/dist/esm/types/types/Log/LogSourceSpecificInfo.d.ts +13 -0
- package/dist/esm/types/types/Log/LogTypeSpecificInfo.d.ts +17 -0
- package/dist/esm/types/types/Log/index.d.ts +10 -0
- package/dist/esm/types/types/LogAction.d.ts +22 -0
- package/dist/esm/types/types/LogFunction.d.ts +24 -0
- package/dist/esm/types/types/LogSource.d.ts +9 -0
- package/dist/esm/types/types/LogType.d.ts +9 -0
- package/dist/index.d.ts +147 -1
- package/package.json +1 -1
- package/src/components/AppWrapper.tsx +1 -1
- package/src/constants/LOG_ROUTE_PATH.ts +9 -0
- package/src/constants/ROUTE_PATH_PREFIX.ts +7 -0
- package/src/helpers/genRouteHandler.ts +137 -1
- package/src/helpers/logClientEvent.tsx +58 -0
- package/src/helpers/parseUserAgent.ts +108 -0
- package/src/index.ts +10 -0
- package/src/server/initServer.ts +90 -0
- package/src/types/Log/LogMainInfo.ts +64 -0
- package/src/types/Log/LogSourceSpecificInfo.ts +25 -0
- package/src/types/Log/LogTypeSpecificInfo.ts +33 -0
- package/src/types/Log/index.ts +17 -0
- package/src/types/LogAction.ts +38 -0
- package/src/types/LogFunction.ts +41 -0
- package/src/types/LogSource.ts +12 -0
- package/src/types/LogType.ts +12 -0
package/src/server/initServer.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// Import custom error
|
|
2
|
+
import LOG_ROUTE_PATH from '../constants/LOG_ROUTE_PATH';
|
|
2
3
|
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
4
|
+
|
|
5
|
+
// Import shared helpers
|
|
6
|
+
import genRouteHandler from '../helpers/genRouteHandler';
|
|
7
|
+
import ParamType from '../types/ParamType';
|
|
8
|
+
|
|
9
|
+
// Import shared types
|
|
3
10
|
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
4
11
|
|
|
5
12
|
// Types
|
|
@@ -11,6 +18,9 @@ type GetLaunchInfoFunction = (req: any) => {
|
|
|
11
18
|
// Stored copy of caccl functions
|
|
12
19
|
let _cacclGetLaunchInfo: GetLaunchInfoFunction;
|
|
13
20
|
|
|
21
|
+
// Stored copy of dce-mango log collection
|
|
22
|
+
let _logCollection: any;
|
|
23
|
+
|
|
14
24
|
/*------------------------------------------------------------------------*/
|
|
15
25
|
/* Helpers */
|
|
16
26
|
/*------------------------------------------------------------------------*/
|
|
@@ -32,6 +42,16 @@ export const cacclGetLaunchInfo: GetLaunchInfoFunction = (req: any) => {
|
|
|
32
42
|
return _cacclGetLaunchInfo(req);
|
|
33
43
|
};
|
|
34
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Get log collection
|
|
47
|
+
* @author Gabe Abrams
|
|
48
|
+
* @returns log collection if one was included during launch or null if we don't
|
|
49
|
+
* have a log collection (yet)
|
|
50
|
+
*/
|
|
51
|
+
export const internalGetLogCollection = () => {
|
|
52
|
+
return _logCollection ?? null;
|
|
53
|
+
};
|
|
54
|
+
|
|
35
55
|
/*------------------------------------------------------------------------*/
|
|
36
56
|
/* Main */
|
|
37
57
|
/*------------------------------------------------------------------------*/
|
|
@@ -40,14 +60,84 @@ export const cacclGetLaunchInfo: GetLaunchInfoFunction = (req: any) => {
|
|
|
40
60
|
* Prepare dce-reactkit to run on the server
|
|
41
61
|
* @author Gabe Abrams
|
|
42
62
|
* @param opts object containing all arguments
|
|
63
|
+
* @param opts.app express app from inside of the postprocessor function that
|
|
64
|
+
* we will add routes to
|
|
43
65
|
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
66
|
+
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
67
|
+
* storing logs. If none is included, logs are written to the console
|
|
44
68
|
*/
|
|
45
69
|
const initServer = (
|
|
46
70
|
opts: {
|
|
71
|
+
app: any,
|
|
47
72
|
getLaunchInfo: GetLaunchInfoFunction,
|
|
73
|
+
logCollection?: any,
|
|
48
74
|
},
|
|
49
75
|
) => {
|
|
50
76
|
_cacclGetLaunchInfo = opts.getLaunchInfo;
|
|
77
|
+
_logCollection = opts.logCollection;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Log an event
|
|
81
|
+
* @author Gabe Abrams
|
|
82
|
+
* @param {string} category Category of the event (each app determines how to
|
|
83
|
+
* categorize its events)
|
|
84
|
+
* @param {string} subcategory Subcategory of the event (each app determines
|
|
85
|
+
* how to categorize its events)
|
|
86
|
+
* @param {string} tags stringified list of tags that apply to this action
|
|
87
|
+
* (each app determines tag usage)
|
|
88
|
+
* @param {string} metadata stringified object containing optional custom metadata
|
|
89
|
+
* @param {string} [errorMessage] error message if type is an error
|
|
90
|
+
* @param {string} [errorCode] error code if type is an error
|
|
91
|
+
* @param {string} [errorStack] error stack if type is an error
|
|
92
|
+
* @param {string} [target] Target of the action (each app determines the list
|
|
93
|
+
* of targets) These are usually buttons, panels, elements, etc.
|
|
94
|
+
* @param {LogAction} [action] the type of action performed on the target
|
|
95
|
+
* @returns {Log}
|
|
96
|
+
*/
|
|
97
|
+
opts.app.post(
|
|
98
|
+
LOG_ROUTE_PATH,
|
|
99
|
+
genRouteHandler({
|
|
100
|
+
paramTypes: {
|
|
101
|
+
category: ParamType.String,
|
|
102
|
+
subcategory: ParamType.String,
|
|
103
|
+
tags: ParamType.JSON,
|
|
104
|
+
metadata: ParamType.JSON,
|
|
105
|
+
errorMessage: ParamType.StringOptional,
|
|
106
|
+
errorCode: ParamType.StringOptional,
|
|
107
|
+
errorStack: ParamType.StringOptional,
|
|
108
|
+
target: ParamType.StringOptional,
|
|
109
|
+
action: ParamType.StringOptional,
|
|
110
|
+
},
|
|
111
|
+
handler: ({ params, logServerEvent }) => {
|
|
112
|
+
const log = logServerEvent(
|
|
113
|
+
(params.errorMessage || params.errorCode || params.errorStack)
|
|
114
|
+
// Error
|
|
115
|
+
? {
|
|
116
|
+
category: params.category,
|
|
117
|
+
subcategory: params.subcategory,
|
|
118
|
+
tags: params.tags,
|
|
119
|
+
metadata: params.metadata,
|
|
120
|
+
error: {
|
|
121
|
+
message: params.errorMessage,
|
|
122
|
+
code: params.errorCode,
|
|
123
|
+
stack: params.errorStack,
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
// Action
|
|
127
|
+
: {
|
|
128
|
+
category: params.category,
|
|
129
|
+
subcategory: params.subcategory,
|
|
130
|
+
tags: params.tags,
|
|
131
|
+
metadata: params.metadata,
|
|
132
|
+
target: params.target,
|
|
133
|
+
action: params.action,
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return log;
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
51
141
|
};
|
|
52
142
|
|
|
53
143
|
export default initServer;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main information in a log event
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
type LogMainInfo = {
|
|
6
|
+
// Unique id of the log event
|
|
7
|
+
id: string,
|
|
8
|
+
// First name of the user
|
|
9
|
+
userFirstName: string,
|
|
10
|
+
// Last name of the user
|
|
11
|
+
userLastName: string,
|
|
12
|
+
// User email
|
|
13
|
+
userEmail: string,
|
|
14
|
+
// User Canvas Id
|
|
15
|
+
userId: number,
|
|
16
|
+
// If true, the user is a learner
|
|
17
|
+
isLearner: boolean,
|
|
18
|
+
// If true, the user is an admin
|
|
19
|
+
isAdmin: boolean,
|
|
20
|
+
// If true, the user is a ttm
|
|
21
|
+
isTTM: boolean,
|
|
22
|
+
// The id of the Canvas course that the user launched from
|
|
23
|
+
courseId: number,
|
|
24
|
+
// The name of the Canvas course
|
|
25
|
+
courseName: string,
|
|
26
|
+
// Browser info
|
|
27
|
+
browser: {
|
|
28
|
+
// Name of the browser
|
|
29
|
+
name: string,
|
|
30
|
+
// Version of the browser
|
|
31
|
+
version: string,
|
|
32
|
+
},
|
|
33
|
+
// Device info
|
|
34
|
+
device: {
|
|
35
|
+
// Name of the operating system
|
|
36
|
+
os: string,
|
|
37
|
+
// If true, device is a mobile device
|
|
38
|
+
isMobile: boolean,
|
|
39
|
+
},
|
|
40
|
+
// Calendar year that the event is from
|
|
41
|
+
year: number,
|
|
42
|
+
// Month that the event is from (1 = Jan, 12 = Dec)
|
|
43
|
+
month: number,
|
|
44
|
+
// Day of the month that the event is from
|
|
45
|
+
day: number,
|
|
46
|
+
// Hour of the day (24hr) when the event occurred
|
|
47
|
+
hour: number,
|
|
48
|
+
// Minute of the day when the event occurred
|
|
49
|
+
minute: number,
|
|
50
|
+
// Timestamp of event (ms since epoch)
|
|
51
|
+
timestamp: number,
|
|
52
|
+
// Category of the event (each app determines how to categorize its events)
|
|
53
|
+
category: string,
|
|
54
|
+
// Subcategory of the event (each app determines how to categorize its events)
|
|
55
|
+
subcategory: string,
|
|
56
|
+
// List of tags that apply to this action (each app determines tag usage)
|
|
57
|
+
tags: string[],
|
|
58
|
+
// Additional optional custom metadata
|
|
59
|
+
metadata?: {
|
|
60
|
+
[k: string]: any,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default LogMainInfo;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Import shared types
|
|
2
|
+
import LogSource from '../LogSource';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Log info that is specific to the type of source
|
|
6
|
+
* @author Gabe Abrams
|
|
7
|
+
*/
|
|
8
|
+
type LogSourceSpecificInfo = (
|
|
9
|
+
// Client
|
|
10
|
+
| {
|
|
11
|
+
// Source of the event
|
|
12
|
+
source: LogSource.Client,
|
|
13
|
+
}
|
|
14
|
+
// Server
|
|
15
|
+
| {
|
|
16
|
+
// Source of the event
|
|
17
|
+
source: LogSource.Server,
|
|
18
|
+
// Route path (e.g. /api/admin/courses/53450/blocks)
|
|
19
|
+
routePath: string,
|
|
20
|
+
// Route template (e.g. /api/admin/courses/:courseId/blocks)
|
|
21
|
+
routeTemplate: string,
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export default LogSourceSpecificInfo;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Import shared types
|
|
2
|
+
import LogAction from '../LogAction';
|
|
3
|
+
import LogType from '../LogType';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Log info that is specific to the type of log
|
|
7
|
+
* @author Gabe Abrams
|
|
8
|
+
*/
|
|
9
|
+
type LogTypeSpecificInfo = (
|
|
10
|
+
// Error
|
|
11
|
+
| {
|
|
12
|
+
// Type of the event
|
|
13
|
+
type: LogType.Error,
|
|
14
|
+
// The error message
|
|
15
|
+
errorMessage: string,
|
|
16
|
+
// The error code
|
|
17
|
+
errorCode: string,
|
|
18
|
+
// Error stack trace
|
|
19
|
+
errorStack: string,
|
|
20
|
+
}
|
|
21
|
+
// Action
|
|
22
|
+
| {
|
|
23
|
+
// Type of the event
|
|
24
|
+
type: LogType.Action,
|
|
25
|
+
// Target of the action (each app determines the list of targets)
|
|
26
|
+
// These are usually buttons, panels, elements, etc.
|
|
27
|
+
target: string,
|
|
28
|
+
// The type of action performed on the target
|
|
29
|
+
action: LogAction,
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export default LogTypeSpecificInfo;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Import shared types
|
|
2
|
+
import LogMainInfo from './LogMainInfo';
|
|
3
|
+
import LogSourceSpecificInfo from './LogSourceSpecificInfo';
|
|
4
|
+
import LogTypeSpecificInfo from './LogTypeSpecificInfo';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A single log event corresponding to an action performed by a user or an
|
|
8
|
+
* error encountered by a user
|
|
9
|
+
* @author Gabe Abrams
|
|
10
|
+
*/
|
|
11
|
+
type Log = (
|
|
12
|
+
LogMainInfo
|
|
13
|
+
& LogSourceSpecificInfo
|
|
14
|
+
& LogTypeSpecificInfo
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export default Log;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of actions
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
enum LogAction {
|
|
6
|
+
// Target was opened by the user (it was not on screen, but now it is)
|
|
7
|
+
Open = 'open',
|
|
8
|
+
// Target was closed by the user (it was on screen, but now it is not)
|
|
9
|
+
Close = 'close',
|
|
10
|
+
// Target was expanded by the user (it always remains on screen, but size was changed)
|
|
11
|
+
Expand = 'expand',
|
|
12
|
+
// Target was collapsed by the user (it always remains on screen, but size was changed)
|
|
13
|
+
Collapse = 'collapse',
|
|
14
|
+
// Target was viewed by the user (only for items that are not opened or closed, those must use Open/Close actions)
|
|
15
|
+
View = 'view',
|
|
16
|
+
// Target interrupted the user (popup, dialog, validation message, etc. appeared without user prompting)
|
|
17
|
+
Interrupt = 'interrupt',
|
|
18
|
+
// Target was created by the user (it did not exist before)
|
|
19
|
+
Create = 'create',
|
|
20
|
+
// Target was edited by the user (it existed and was changed)
|
|
21
|
+
Edit = 'edit',
|
|
22
|
+
// Target was deleted by the user (it existed and now it doesn't)
|
|
23
|
+
Delete = 'delete',
|
|
24
|
+
// Target was added by the user (it already existed and was added to another place)
|
|
25
|
+
Add = 'add',
|
|
26
|
+
// Target was removed by the user (it was removed from something but still exists)
|
|
27
|
+
Remove = 'remove',
|
|
28
|
+
// Target was activated by the user (click, check, tap, keypress, etc.)
|
|
29
|
+
Activate = 'activate',
|
|
30
|
+
// Target was deactivated by the user (click away, uncheck, tap outside of, tab away, etc.)
|
|
31
|
+
Deactivate = 'deactivate',
|
|
32
|
+
// User showed interest in a target (hover, peek, etc.)
|
|
33
|
+
Peek = 'peek',
|
|
34
|
+
// Unknown action
|
|
35
|
+
Unknown = 'unknown',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default LogAction;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Import shared types
|
|
2
|
+
import Log from './Log';
|
|
3
|
+
import LogAction from './LogAction';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type of a log action function
|
|
7
|
+
* @author Gabe Abrams
|
|
8
|
+
*/
|
|
9
|
+
type LogFunction = (
|
|
10
|
+
opts: (
|
|
11
|
+
// Shared info
|
|
12
|
+
{
|
|
13
|
+
// Category of the event (each app determines how to categorize its events)
|
|
14
|
+
category: string | { name: string },
|
|
15
|
+
// Subcategory of the event (each app determines how to categorize its events)
|
|
16
|
+
subcategory?: string | { name: string },
|
|
17
|
+
// List of tags that apply to this action (each app determines tag usage)
|
|
18
|
+
tags?: string[],
|
|
19
|
+
// Additional optional custom metadata
|
|
20
|
+
metadata?: {
|
|
21
|
+
[k: string]: any,
|
|
22
|
+
},
|
|
23
|
+
} & (
|
|
24
|
+
// Error
|
|
25
|
+
| {
|
|
26
|
+
// The error object to log
|
|
27
|
+
error: any,
|
|
28
|
+
}
|
|
29
|
+
// Action
|
|
30
|
+
| {
|
|
31
|
+
// Target of the action (each app determines the list of targets)
|
|
32
|
+
// These are usually buttons, panels, elements, etc.
|
|
33
|
+
target: string,
|
|
34
|
+
// The type of action performed on the target
|
|
35
|
+
action: LogAction,
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
),
|
|
39
|
+
) => Promise<Log>;
|
|
40
|
+
|
|
41
|
+
export default LogFunction;
|