dce-reactkit 3.1.19 → 3.2.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.
- package/dist/cjs/index.js +373 -25
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +14 -3
- 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 +5 -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 +20 -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 +371 -26
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +14 -3
- 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 +5 -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 +20 -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 +165 -19
- package/package.json +1 -1
- package/src/components/AppWrapper.tsx +32 -13
- package/src/constants/LOG_ROUTE_PATH.ts +9 -0
- package/src/constants/ROUTE_PATH_PREFIX.ts +7 -0
- package/src/helpers/genRouteHandler.ts +129 -1
- package/src/helpers/logClientEvent.tsx +50 -0
- package/src/helpers/parseUserAgent.ts +108 -0
- package/src/index.ts +8 -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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Log from './Log';
|
|
2
|
+
import LogAction from './LogAction';
|
|
3
|
+
/**
|
|
4
|
+
* Type of a log action function
|
|
5
|
+
* @author Gabe Abrams
|
|
6
|
+
*/
|
|
7
|
+
declare type LogFunction = (opts: ({
|
|
8
|
+
category: string;
|
|
9
|
+
subcategory?: string;
|
|
10
|
+
tags?: string[];
|
|
11
|
+
metadata?: {
|
|
12
|
+
[k: string]: any;
|
|
13
|
+
};
|
|
14
|
+
} & ({
|
|
15
|
+
error: any;
|
|
16
|
+
} | {
|
|
17
|
+
target: string;
|
|
18
|
+
action: LogAction;
|
|
19
|
+
}))) => Promise<Log>;
|
|
20
|
+
export default LogFunction;
|
package/dist/esm/index.js
CHANGED
|
@@ -560,11 +560,16 @@ let onConfirmClosed;
|
|
|
560
560
|
* @author Gabe Abrams
|
|
561
561
|
* @param title the title text to display at the top of the alert
|
|
562
562
|
* @param text the text to display in the alert
|
|
563
|
-
* @param [
|
|
564
|
-
* @param [
|
|
563
|
+
* @param [opts={}] additional options for the confirmation dialog
|
|
564
|
+
* @param [opts.confirmButtonText=Okay] the text of the confirm button
|
|
565
|
+
* @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm
|
|
566
|
+
* button
|
|
567
|
+
* @param [opts.cancelButtonText=Cancel] the text of the cancel button
|
|
568
|
+
* @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel
|
|
569
|
+
* button
|
|
565
570
|
* @returns true if the user confirmed
|
|
566
571
|
*/
|
|
567
|
-
const confirm = (title, text,
|
|
572
|
+
const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
568
573
|
// Fallback if confirm is not available
|
|
569
574
|
if (!setConfirmInfo) {
|
|
570
575
|
return window.confirm(`${title}\n\n${text}`);
|
|
@@ -579,8 +584,7 @@ const confirm = (title, text, confirmButtonText = 'Okay', cancelButtonText = 'Ca
|
|
|
579
584
|
setConfirmInfo({
|
|
580
585
|
title,
|
|
581
586
|
text,
|
|
582
|
-
|
|
583
|
-
cancelButtonText,
|
|
587
|
+
opts: (opts !== null && opts !== void 0 ? opts : {}),
|
|
584
588
|
});
|
|
585
589
|
});
|
|
586
590
|
});
|
|
@@ -664,7 +668,7 @@ const AppWrapper = (props) => {
|
|
|
664
668
|
}
|
|
665
669
|
/* ------------- Confirm ------------ */
|
|
666
670
|
if (confirmInfo) {
|
|
667
|
-
modal = (React.createElement(Modal, { key: `confirm-${confirmInfo.title}-${confirmInfo.text}`, title: confirmInfo.title, type: ModalType$1.OkayCancel, okayLabel: confirmInfo.confirmButtonText, cancelLabel: confirmInfo.cancelButtonText, onClose: (buttonType) => {
|
|
671
|
+
modal = (React.createElement(Modal, { key: `confirm-${confirmInfo.title}-${confirmInfo.text}`, title: confirmInfo.title, type: ModalType$1.OkayCancel, okayLabel: confirmInfo.opts.confirmButtonText, okayVariant: confirmInfo.opts.confirmButtonVariant, cancelLabel: confirmInfo.opts.cancelButtonText, cancelVariant: confirmInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
|
|
668
672
|
setConfirmInfo(undefined);
|
|
669
673
|
if (onConfirmClosed) {
|
|
670
674
|
onConfirmClosed(buttonType === ModalButtonType$1.Okay);
|
|
@@ -2112,9 +2116,42 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
|
|
|
2112
2116
|
return body;
|
|
2113
2117
|
});
|
|
2114
2118
|
|
|
2119
|
+
/**
|
|
2120
|
+
* Path that all routes start with
|
|
2121
|
+
* @author Gabe Abrams
|
|
2122
|
+
*/
|
|
2123
|
+
const ROUTE_PATH_PREFIX = '/dce-reactkit';
|
|
2124
|
+
|
|
2125
|
+
/**
|
|
2126
|
+
* Path of the route for storing client-side logs
|
|
2127
|
+
* @author Gabe Abrams
|
|
2128
|
+
*/
|
|
2129
|
+
const LOG_ROUTE_PATH = `${ROUTE_PATH_PREFIX}/log`;
|
|
2130
|
+
|
|
2131
|
+
/**
|
|
2132
|
+
* Server-side API param types
|
|
2133
|
+
* @author Gabe Abrams
|
|
2134
|
+
*/
|
|
2135
|
+
var ParamType;
|
|
2136
|
+
(function (ParamType) {
|
|
2137
|
+
ParamType["Boolean"] = "boolean";
|
|
2138
|
+
ParamType["BooleanOptional"] = "boolean-optional";
|
|
2139
|
+
ParamType["Float"] = "float";
|
|
2140
|
+
ParamType["FloatOptional"] = "float-optional";
|
|
2141
|
+
ParamType["Int"] = "int";
|
|
2142
|
+
ParamType["IntOptional"] = "int-optional";
|
|
2143
|
+
ParamType["JSON"] = "json";
|
|
2144
|
+
ParamType["JSONOptional"] = "json-optional";
|
|
2145
|
+
ParamType["String"] = "string";
|
|
2146
|
+
ParamType["StringOptional"] = "string-optional";
|
|
2147
|
+
})(ParamType || (ParamType = {}));
|
|
2148
|
+
var ParamType$1 = ParamType;
|
|
2149
|
+
|
|
2115
2150
|
// Import custom error
|
|
2116
2151
|
// Stored copy of caccl functions
|
|
2117
2152
|
let _cacclGetLaunchInfo;
|
|
2153
|
+
// Stored copy of dce-mango log collection
|
|
2154
|
+
let _logCollection;
|
|
2118
2155
|
/*------------------------------------------------------------------------*/
|
|
2119
2156
|
/* Helpers */
|
|
2120
2157
|
/*------------------------------------------------------------------------*/
|
|
@@ -2130,6 +2167,15 @@ const cacclGetLaunchInfo = (req) => {
|
|
|
2130
2167
|
}
|
|
2131
2168
|
return _cacclGetLaunchInfo(req);
|
|
2132
2169
|
};
|
|
2170
|
+
/**
|
|
2171
|
+
* Get log collection
|
|
2172
|
+
* @author Gabe Abrams
|
|
2173
|
+
* @returns log collection if one was included during launch or null if we don't
|
|
2174
|
+
* have a log collection (yet)
|
|
2175
|
+
*/
|
|
2176
|
+
const internalGetLogCollection = () => {
|
|
2177
|
+
return _logCollection !== null && _logCollection !== void 0 ? _logCollection : null;
|
|
2178
|
+
};
|
|
2133
2179
|
/*------------------------------------------------------------------------*/
|
|
2134
2180
|
/* Main */
|
|
2135
2181
|
/*------------------------------------------------------------------------*/
|
|
@@ -2137,31 +2183,73 @@ const cacclGetLaunchInfo = (req) => {
|
|
|
2137
2183
|
* Prepare dce-reactkit to run on the server
|
|
2138
2184
|
* @author Gabe Abrams
|
|
2139
2185
|
* @param opts object containing all arguments
|
|
2186
|
+
* @param opts.app express app from inside of the postprocessor function that
|
|
2187
|
+
* we will add routes to
|
|
2140
2188
|
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
2189
|
+
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
2190
|
+
* storing logs. If none is included, logs are written to the console
|
|
2141
2191
|
*/
|
|
2142
2192
|
const initServer = (opts) => {
|
|
2143
2193
|
_cacclGetLaunchInfo = opts.getLaunchInfo;
|
|
2194
|
+
_logCollection = opts.logCollection;
|
|
2195
|
+
/**
|
|
2196
|
+
* Log an event
|
|
2197
|
+
* @author Gabe Abrams
|
|
2198
|
+
* @param {string} category Category of the event (each app determines how to
|
|
2199
|
+
* categorize its events)
|
|
2200
|
+
* @param {string} subcategory Subcategory of the event (each app determines
|
|
2201
|
+
* how to categorize its events)
|
|
2202
|
+
* @param {string} tags stringified list of tags that apply to this action
|
|
2203
|
+
* (each app determines tag usage)
|
|
2204
|
+
* @param {string} metadata stringified object containing optional custom metadata
|
|
2205
|
+
* @param {string} [errorMessage] error message if type is an error
|
|
2206
|
+
* @param {string} [errorCode] error code if type is an error
|
|
2207
|
+
* @param {string} [errorStack] error stack if type is an error
|
|
2208
|
+
* @param {string} [target] Target of the action (each app determines the list
|
|
2209
|
+
* of targets) These are usually buttons, panels, elements, etc.
|
|
2210
|
+
* @param {LogAction} [action] the type of action performed on the target
|
|
2211
|
+
* @returns {Log}
|
|
2212
|
+
*/
|
|
2213
|
+
opts.app.post(LOG_ROUTE_PATH, genRouteHandler({
|
|
2214
|
+
paramTypes: {
|
|
2215
|
+
category: ParamType$1.String,
|
|
2216
|
+
subcategory: ParamType$1.String,
|
|
2217
|
+
tags: ParamType$1.JSON,
|
|
2218
|
+
metadata: ParamType$1.JSON,
|
|
2219
|
+
errorMessage: ParamType$1.StringOptional,
|
|
2220
|
+
errorCode: ParamType$1.StringOptional,
|
|
2221
|
+
errorStack: ParamType$1.StringOptional,
|
|
2222
|
+
target: ParamType$1.StringOptional,
|
|
2223
|
+
action: ParamType$1.StringOptional,
|
|
2224
|
+
},
|
|
2225
|
+
handler: ({ params, logServerEvent }) => {
|
|
2226
|
+
const log = logServerEvent((params.errorMessage || params.errorCode || params.errorStack)
|
|
2227
|
+
// Error
|
|
2228
|
+
? {
|
|
2229
|
+
category: params.category,
|
|
2230
|
+
subcategory: params.subcategory,
|
|
2231
|
+
tags: params.tags,
|
|
2232
|
+
metadata: params.metadata,
|
|
2233
|
+
error: {
|
|
2234
|
+
message: params.errorMessage,
|
|
2235
|
+
code: params.errorCode,
|
|
2236
|
+
stack: params.errorStack,
|
|
2237
|
+
},
|
|
2238
|
+
}
|
|
2239
|
+
// Action
|
|
2240
|
+
: {
|
|
2241
|
+
category: params.category,
|
|
2242
|
+
subcategory: params.subcategory,
|
|
2243
|
+
tags: params.tags,
|
|
2244
|
+
metadata: params.metadata,
|
|
2245
|
+
target: params.target,
|
|
2246
|
+
action: params.action,
|
|
2247
|
+
});
|
|
2248
|
+
return log;
|
|
2249
|
+
},
|
|
2250
|
+
}));
|
|
2144
2251
|
};
|
|
2145
2252
|
|
|
2146
|
-
/**
|
|
2147
|
-
* Server-side API param types
|
|
2148
|
-
* @author Gabe Abrams
|
|
2149
|
-
*/
|
|
2150
|
-
var ParamType;
|
|
2151
|
-
(function (ParamType) {
|
|
2152
|
-
ParamType["Boolean"] = "boolean";
|
|
2153
|
-
ParamType["BooleanOptional"] = "boolean-optional";
|
|
2154
|
-
ParamType["Float"] = "float";
|
|
2155
|
-
ParamType["FloatOptional"] = "float-optional";
|
|
2156
|
-
ParamType["Int"] = "int";
|
|
2157
|
-
ParamType["IntOptional"] = "int-optional";
|
|
2158
|
-
ParamType["JSON"] = "json";
|
|
2159
|
-
ParamType["JSONOptional"] = "json-optional";
|
|
2160
|
-
ParamType["String"] = "string";
|
|
2161
|
-
ParamType["StringOptional"] = "string-optional";
|
|
2162
|
-
})(ParamType || (ParamType = {}));
|
|
2163
|
-
var ParamType$1 = ParamType;
|
|
2164
|
-
|
|
2165
2253
|
// Import shared types
|
|
2166
2254
|
/**
|
|
2167
2255
|
* Handle an error and respond to the client
|
|
@@ -2354,6 +2442,137 @@ const genErrorPage = (opts = {}) => {
|
|
|
2354
2442
|
`;
|
|
2355
2443
|
};
|
|
2356
2444
|
|
|
2445
|
+
/**
|
|
2446
|
+
* Perform a rudimentary parsing of the user's browser agent string
|
|
2447
|
+
* @author Gabe Abrams
|
|
2448
|
+
* @param userAgent the user's browser agent
|
|
2449
|
+
* @returns user info
|
|
2450
|
+
*/
|
|
2451
|
+
const parseUserAgent = (userAgent) => {
|
|
2452
|
+
/* ------------- Browser ------------ */
|
|
2453
|
+
let browser = {
|
|
2454
|
+
name: 'Unknown',
|
|
2455
|
+
version: 'Unknown',
|
|
2456
|
+
};
|
|
2457
|
+
// Parse user agent
|
|
2458
|
+
let verOffset;
|
|
2459
|
+
let nameOffset;
|
|
2460
|
+
if ((verOffset = userAgent.indexOf('Opera')) !== -1) {
|
|
2461
|
+
// In Opera, the true version is after 'Opera' or after 'Version'
|
|
2462
|
+
browser = {
|
|
2463
|
+
name: 'Opera',
|
|
2464
|
+
version: userAgent.substring(verOffset + 6),
|
|
2465
|
+
};
|
|
2466
|
+
if ((verOffset = userAgent.indexOf('Version')) !== -1) {
|
|
2467
|
+
browser.version = userAgent.substring(verOffset + 8);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
else if ((verOffset = userAgent.indexOf('MSIE')) !== -1) {
|
|
2471
|
+
// In MSIE, the true version is after 'MSIE' in userAgent
|
|
2472
|
+
browser = {
|
|
2473
|
+
name: 'Internet Explorer',
|
|
2474
|
+
version: userAgent.substring(verOffset + 5),
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
else if ((verOffset = userAgent.indexOf('Chrome')) !== -1) {
|
|
2478
|
+
// In Chrome, the true version is after 'Chrome'
|
|
2479
|
+
browser = {
|
|
2480
|
+
name: 'Chrome',
|
|
2481
|
+
version: userAgent.substring(verOffset + 7),
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
else if ((verOffset = userAgent.indexOf('Safari')) !== -1) {
|
|
2485
|
+
// In Safari, the true version is after 'Safari' or after 'Version'
|
|
2486
|
+
browser = {
|
|
2487
|
+
name: 'Safari',
|
|
2488
|
+
version: userAgent.substring(verOffset + 7),
|
|
2489
|
+
};
|
|
2490
|
+
if ((verOffset = userAgent.indexOf('Version')) !== -1) {
|
|
2491
|
+
browser.version = userAgent.substring(verOffset + 8);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
else if ((verOffset = userAgent.indexOf('Firefox')) != -1) {
|
|
2495
|
+
// In Firefox, the true version is after 'Firefox'
|
|
2496
|
+
browser = {
|
|
2497
|
+
name: 'Firefox',
|
|
2498
|
+
version: userAgent.substring(verOffset + 8),
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
else if ((nameOffset = userAgent.lastIndexOf(' ') + 1)
|
|
2502
|
+
< (verOffset = userAgent.lastIndexOf('/'))) {
|
|
2503
|
+
browser = {
|
|
2504
|
+
name: userAgent.substring(nameOffset, verOffset),
|
|
2505
|
+
version: userAgent.substring(verOffset + 1),
|
|
2506
|
+
};
|
|
2507
|
+
}
|
|
2508
|
+
// Postprocess version
|
|
2509
|
+
// trim the fullVersion string at semicolon/space if present
|
|
2510
|
+
let ix;
|
|
2511
|
+
if ((ix = browser.version.indexOf(';')) !== -1) {
|
|
2512
|
+
browser.version = browser.version.substring(0, ix);
|
|
2513
|
+
}
|
|
2514
|
+
if ((ix = browser.version.indexOf(' ')) !== -1) {
|
|
2515
|
+
browser.version = browser.version.substring(0, ix);
|
|
2516
|
+
}
|
|
2517
|
+
/* ------------- Device ------------- */
|
|
2518
|
+
// Detect os
|
|
2519
|
+
let os = 'Unknown';
|
|
2520
|
+
if (userAgent.includes('Linux')) {
|
|
2521
|
+
os = 'Linux';
|
|
2522
|
+
}
|
|
2523
|
+
else if (userAgent.includes('like Mac')) {
|
|
2524
|
+
os = 'iOS';
|
|
2525
|
+
}
|
|
2526
|
+
else if (userAgent.includes('Mac')) {
|
|
2527
|
+
os = 'Mac';
|
|
2528
|
+
}
|
|
2529
|
+
else if (userAgent.includes('Android')) {
|
|
2530
|
+
os = 'Android';
|
|
2531
|
+
}
|
|
2532
|
+
else if (userAgent.includes('Win')) {
|
|
2533
|
+
os = 'Win';
|
|
2534
|
+
}
|
|
2535
|
+
// Check if mobile
|
|
2536
|
+
const isMobile = !!userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
|
|
2537
|
+
// Device
|
|
2538
|
+
const device = {
|
|
2539
|
+
isMobile,
|
|
2540
|
+
os,
|
|
2541
|
+
};
|
|
2542
|
+
/* ------------- Finish ------------- */
|
|
2543
|
+
// Return info
|
|
2544
|
+
return {
|
|
2545
|
+
browser,
|
|
2546
|
+
device,
|
|
2547
|
+
};
|
|
2548
|
+
};
|
|
2549
|
+
|
|
2550
|
+
/**
|
|
2551
|
+
* Type of a log event
|
|
2552
|
+
* @author Gabe Abrams
|
|
2553
|
+
*/
|
|
2554
|
+
var LogType;
|
|
2555
|
+
(function (LogType) {
|
|
2556
|
+
// User action
|
|
2557
|
+
LogType["Action"] = "action";
|
|
2558
|
+
// Error
|
|
2559
|
+
LogType["Error"] = "error";
|
|
2560
|
+
})(LogType || (LogType = {}));
|
|
2561
|
+
var LogType$1 = LogType;
|
|
2562
|
+
|
|
2563
|
+
/**
|
|
2564
|
+
* Source of a log event
|
|
2565
|
+
* @author Gabe Abrams
|
|
2566
|
+
*/
|
|
2567
|
+
var LogSource;
|
|
2568
|
+
(function (LogSource) {
|
|
2569
|
+
// Client
|
|
2570
|
+
LogSource["Client"] = "client";
|
|
2571
|
+
// Server
|
|
2572
|
+
LogSource["Server"] = "server";
|
|
2573
|
+
})(LogSource || (LogSource = {}));
|
|
2574
|
+
var LogSource$1 = LogSource;
|
|
2575
|
+
|
|
2357
2576
|
/**
|
|
2358
2577
|
* Generate an express API route handler
|
|
2359
2578
|
* @author Gabe Abrams
|
|
@@ -2669,6 +2888,92 @@ const genRouteHandler = (opts) => {
|
|
|
2669
2888
|
status: 401,
|
|
2670
2889
|
});
|
|
2671
2890
|
}
|
|
2891
|
+
/*----------------------------------------*/
|
|
2892
|
+
/* Log Handler */
|
|
2893
|
+
/*----------------------------------------*/
|
|
2894
|
+
// Create a log handler function
|
|
2895
|
+
/**
|
|
2896
|
+
* Log an event on the server
|
|
2897
|
+
* @author Gabe Abrams
|
|
2898
|
+
*/
|
|
2899
|
+
const logServerEvent = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2900
|
+
// NOTE: internally, we slip through an opts.overrideAsClientEvent boolean
|
|
2901
|
+
// that indicates that this is actually a client event, but we don't
|
|
2902
|
+
// include that in the LogFunction type because this is internal and
|
|
2903
|
+
// hidden from users
|
|
2904
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2905
|
+
// Parse user agent
|
|
2906
|
+
const { browser, device, } = parseUserAgent(req.headers['user-agent']);
|
|
2907
|
+
// Get time info in ET
|
|
2908
|
+
const { timestamp, year, month, day, hour, minute, } = getTimeInfoInET();
|
|
2909
|
+
// Main log info
|
|
2910
|
+
const mainLogInfo = {
|
|
2911
|
+
id: `${launchInfo.userId}-${Date.now()}-${Math.floor(Math.random() * 100000)}-${Math.floor(Math.random() * 100000)}`,
|
|
2912
|
+
userFirstName: launchInfo.userFirstName,
|
|
2913
|
+
userLastName: launchInfo.userLastName,
|
|
2914
|
+
userEmail: launchInfo.userEmail,
|
|
2915
|
+
userId: launchInfo.userId,
|
|
2916
|
+
isLearner: !!launchInfo.isLearner,
|
|
2917
|
+
isAdmin: !!launchInfo.isAdmin,
|
|
2918
|
+
isTTM: !!launchInfo.isTTM,
|
|
2919
|
+
courseId: launchInfo.courseId,
|
|
2920
|
+
courseName: launchInfo.courseName,
|
|
2921
|
+
browser,
|
|
2922
|
+
device,
|
|
2923
|
+
year,
|
|
2924
|
+
month,
|
|
2925
|
+
day,
|
|
2926
|
+
hour,
|
|
2927
|
+
minute,
|
|
2928
|
+
timestamp,
|
|
2929
|
+
category: opts.category,
|
|
2930
|
+
subcategory: (_c = opts.subcategory) !== null && _c !== void 0 ? _c : 'none',
|
|
2931
|
+
tags: (_d = opts.tags) !== null && _d !== void 0 ? _d : [],
|
|
2932
|
+
metadata: (_e = opts.metadata) !== null && _e !== void 0 ? _e : {},
|
|
2933
|
+
};
|
|
2934
|
+
// Type-specific info
|
|
2935
|
+
const typeSpecificInfo = (('error' in opts && opts.error)
|
|
2936
|
+
? {
|
|
2937
|
+
type: LogType$1.Error,
|
|
2938
|
+
errorMessage: (_f = opts.error.message) !== null && _f !== void 0 ? _f : 'Unknown message',
|
|
2939
|
+
errorCode: (_g = opts.error.code) !== null && _g !== void 0 ? _g : ReactKitErrorCode$1.NoCode,
|
|
2940
|
+
errorStack: (_h = opts.error.stack) !== null && _h !== void 0 ? _h : 'No stack',
|
|
2941
|
+
}
|
|
2942
|
+
: {
|
|
2943
|
+
type: LogType$1.Action,
|
|
2944
|
+
target: (_j = opts.target) !== null && _j !== void 0 ? _j : 'Unknown',
|
|
2945
|
+
action: (_k = opts.action) !== null && _k !== void 0 ? _k : 'Unknown'
|
|
2946
|
+
});
|
|
2947
|
+
// Source-specific info
|
|
2948
|
+
const sourceSpecificInfo = (opts.overrideAsClientEvent
|
|
2949
|
+
? {
|
|
2950
|
+
source: LogSource$1.Client,
|
|
2951
|
+
}
|
|
2952
|
+
: {
|
|
2953
|
+
source: LogSource$1.Server,
|
|
2954
|
+
routePath: req.path,
|
|
2955
|
+
routeTemplate: req.route.path,
|
|
2956
|
+
});
|
|
2957
|
+
// Build log event
|
|
2958
|
+
const log = Object.assign(Object.assign(Object.assign({}, mainLogInfo), typeSpecificInfo), sourceSpecificInfo);
|
|
2959
|
+
// Either print to console or save to db
|
|
2960
|
+
const logCollection = internalGetLogCollection();
|
|
2961
|
+
if (logCollection) {
|
|
2962
|
+
// Store to the log collection
|
|
2963
|
+
yield logCollection.insert(log);
|
|
2964
|
+
}
|
|
2965
|
+
else {
|
|
2966
|
+
// Print to console
|
|
2967
|
+
if (log.type === LogType$1.Error) {
|
|
2968
|
+
console.error('dce-reactkit error log:', log);
|
|
2969
|
+
}
|
|
2970
|
+
else {
|
|
2971
|
+
console.log('dce-reactkit action log:', log);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
// Return log entry
|
|
2975
|
+
return log;
|
|
2976
|
+
});
|
|
2672
2977
|
/*------------------------------------------------------------------------*/
|
|
2673
2978
|
/* Call handler */
|
|
2674
2979
|
/*------------------------------------------------------------------------*/
|
|
@@ -2722,6 +3027,7 @@ const genRouteHandler = (opts) => {
|
|
|
2722
3027
|
},
|
|
2723
3028
|
redirect,
|
|
2724
3029
|
renderErrorPage,
|
|
3030
|
+
logServerEvent,
|
|
2725
3031
|
});
|
|
2726
3032
|
// Send results to client (only if next wasn't called)
|
|
2727
3033
|
if (!responseSent) {
|
|
@@ -2941,5 +3247,44 @@ var DayOfWeek;
|
|
|
2941
3247
|
})(DayOfWeek || (DayOfWeek = {}));
|
|
2942
3248
|
var DayOfWeek$1 = DayOfWeek;
|
|
2943
3249
|
|
|
2944
|
-
|
|
3250
|
+
/**
|
|
3251
|
+
* Types of actions
|
|
3252
|
+
* @author Gabe Abrams
|
|
3253
|
+
*/
|
|
3254
|
+
var LogAction;
|
|
3255
|
+
(function (LogAction) {
|
|
3256
|
+
// Target was opened by the user (it was not on screen, but now it is)
|
|
3257
|
+
LogAction["Open"] = "open";
|
|
3258
|
+
// Target was closed by the user (it was on screen, but now it is not)
|
|
3259
|
+
LogAction["Close"] = "close";
|
|
3260
|
+
// Target was expanded by the user (it always remains on screen, but size was changed)
|
|
3261
|
+
LogAction["Expand"] = "expand";
|
|
3262
|
+
// Target was collapsed by the user (it always remains on screen, but size was changed)
|
|
3263
|
+
LogAction["Collapse"] = "collapse";
|
|
3264
|
+
// Target was viewed by the user (only for items that are not opened or closed, those must use Open/Close actions)
|
|
3265
|
+
LogAction["View"] = "view";
|
|
3266
|
+
// Target interrupted the user (popup, dialog, validation message, etc. appeared without user prompting)
|
|
3267
|
+
LogAction["Interrupt"] = "interrupt";
|
|
3268
|
+
// Target was created by the user (it did not exist before)
|
|
3269
|
+
LogAction["Create"] = "create";
|
|
3270
|
+
// Target was edited by the user (it existed and was changed)
|
|
3271
|
+
LogAction["Edit"] = "edit";
|
|
3272
|
+
// Target was deleted by the user (it existed and now it doesn't)
|
|
3273
|
+
LogAction["Delete"] = "delete";
|
|
3274
|
+
// Target was added by the user (it already existed and was added to another place)
|
|
3275
|
+
LogAction["Add"] = "add";
|
|
3276
|
+
// Target was removed by the user (it was removed from something but still exists)
|
|
3277
|
+
LogAction["Remove"] = "remove";
|
|
3278
|
+
// Target was activated by the user (click, check, tap, keypress, etc.)
|
|
3279
|
+
LogAction["Activate"] = "activate";
|
|
3280
|
+
// Target was deactivated by the user (click away, uncheck, tap outside of, tab away, etc.)
|
|
3281
|
+
LogAction["Deactivate"] = "deactivate";
|
|
3282
|
+
// User showed interest in a target (hover, peek, etc.)
|
|
3283
|
+
LogAction["Peek"] = "peek";
|
|
3284
|
+
// Unknown action
|
|
3285
|
+
LogAction["Unknown"] = "unknown";
|
|
3286
|
+
})(LogAction || (LogAction = {}));
|
|
3287
|
+
var LogAction$1 = LogAction;
|
|
3288
|
+
|
|
3289
|
+
export { AppWrapper, ButtonInputGroup, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek$1 as DayOfWeek, Drawer, ErrorBox, ErrorWithCode, HOUR_IN_MS, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, Variant$1 as Variant, abbreviate, alert$1 as alert, avg, ceilToNumDecimals, confirm, floorToNumDecimals, forceNumIntoBounds, genRouteHandler, getHumanReadableDate, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, initServer, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
|
2945
3290
|
//# sourceMappingURL=index.js.map
|