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/dist/esm/index.js
CHANGED
|
@@ -2116,9 +2116,42 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
|
|
|
2116
2116
|
return body;
|
|
2117
2117
|
});
|
|
2118
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
|
+
|
|
2119
2150
|
// Import custom error
|
|
2120
2151
|
// Stored copy of caccl functions
|
|
2121
2152
|
let _cacclGetLaunchInfo;
|
|
2153
|
+
// Stored copy of dce-mango log collection
|
|
2154
|
+
let _logCollection;
|
|
2122
2155
|
/*------------------------------------------------------------------------*/
|
|
2123
2156
|
/* Helpers */
|
|
2124
2157
|
/*------------------------------------------------------------------------*/
|
|
@@ -2134,6 +2167,15 @@ const cacclGetLaunchInfo = (req) => {
|
|
|
2134
2167
|
}
|
|
2135
2168
|
return _cacclGetLaunchInfo(req);
|
|
2136
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
|
+
};
|
|
2137
2179
|
/*------------------------------------------------------------------------*/
|
|
2138
2180
|
/* Main */
|
|
2139
2181
|
/*------------------------------------------------------------------------*/
|
|
@@ -2141,31 +2183,73 @@ const cacclGetLaunchInfo = (req) => {
|
|
|
2141
2183
|
* Prepare dce-reactkit to run on the server
|
|
2142
2184
|
* @author Gabe Abrams
|
|
2143
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
|
|
2144
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
|
|
2145
2191
|
*/
|
|
2146
2192
|
const initServer = (opts) => {
|
|
2147
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
|
+
}));
|
|
2148
2251
|
};
|
|
2149
2252
|
|
|
2150
|
-
/**
|
|
2151
|
-
* Server-side API param types
|
|
2152
|
-
* @author Gabe Abrams
|
|
2153
|
-
*/
|
|
2154
|
-
var ParamType;
|
|
2155
|
-
(function (ParamType) {
|
|
2156
|
-
ParamType["Boolean"] = "boolean";
|
|
2157
|
-
ParamType["BooleanOptional"] = "boolean-optional";
|
|
2158
|
-
ParamType["Float"] = "float";
|
|
2159
|
-
ParamType["FloatOptional"] = "float-optional";
|
|
2160
|
-
ParamType["Int"] = "int";
|
|
2161
|
-
ParamType["IntOptional"] = "int-optional";
|
|
2162
|
-
ParamType["JSON"] = "json";
|
|
2163
|
-
ParamType["JSONOptional"] = "json-optional";
|
|
2164
|
-
ParamType["String"] = "string";
|
|
2165
|
-
ParamType["StringOptional"] = "string-optional";
|
|
2166
|
-
})(ParamType || (ParamType = {}));
|
|
2167
|
-
var ParamType$1 = ParamType;
|
|
2168
|
-
|
|
2169
2253
|
// Import shared types
|
|
2170
2254
|
/**
|
|
2171
2255
|
* Handle an error and respond to the client
|
|
@@ -2358,6 +2442,137 @@ const genErrorPage = (opts = {}) => {
|
|
|
2358
2442
|
`;
|
|
2359
2443
|
};
|
|
2360
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
|
+
|
|
2361
2576
|
/**
|
|
2362
2577
|
* Generate an express API route handler
|
|
2363
2578
|
* @author Gabe Abrams
|
|
@@ -2673,6 +2888,96 @@ const genRouteHandler = (opts) => {
|
|
|
2673
2888
|
status: 401,
|
|
2674
2889
|
});
|
|
2675
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: (typeof opts.category === 'string'
|
|
2930
|
+
? opts.category
|
|
2931
|
+
: opts.category.name),
|
|
2932
|
+
subcategory: (typeof opts.category === 'string'
|
|
2933
|
+
? opts.subcategory
|
|
2934
|
+
: ((_c = opts.subcategory) !== null && _c !== void 0 ? _c : { name: 'none' }).name),
|
|
2935
|
+
tags: (_d = opts.tags) !== null && _d !== void 0 ? _d : [],
|
|
2936
|
+
metadata: (_e = opts.metadata) !== null && _e !== void 0 ? _e : {},
|
|
2937
|
+
};
|
|
2938
|
+
// Type-specific info
|
|
2939
|
+
const typeSpecificInfo = (('error' in opts && opts.error)
|
|
2940
|
+
? {
|
|
2941
|
+
type: LogType$1.Error,
|
|
2942
|
+
errorMessage: (_f = opts.error.message) !== null && _f !== void 0 ? _f : 'Unknown message',
|
|
2943
|
+
errorCode: (_g = opts.error.code) !== null && _g !== void 0 ? _g : ReactKitErrorCode$1.NoCode,
|
|
2944
|
+
errorStack: (_h = opts.error.stack) !== null && _h !== void 0 ? _h : 'No stack',
|
|
2945
|
+
}
|
|
2946
|
+
: {
|
|
2947
|
+
type: LogType$1.Action,
|
|
2948
|
+
target: (_j = opts.target) !== null && _j !== void 0 ? _j : 'Unknown',
|
|
2949
|
+
action: (_k = opts.action) !== null && _k !== void 0 ? _k : 'Unknown'
|
|
2950
|
+
});
|
|
2951
|
+
// Source-specific info
|
|
2952
|
+
const sourceSpecificInfo = (opts.overrideAsClientEvent
|
|
2953
|
+
? {
|
|
2954
|
+
source: LogSource$1.Client,
|
|
2955
|
+
}
|
|
2956
|
+
: {
|
|
2957
|
+
source: LogSource$1.Server,
|
|
2958
|
+
routePath: req.path,
|
|
2959
|
+
routeTemplate: req.route.path,
|
|
2960
|
+
});
|
|
2961
|
+
// Build log event
|
|
2962
|
+
const log = Object.assign(Object.assign(Object.assign({}, mainLogInfo), typeSpecificInfo), sourceSpecificInfo);
|
|
2963
|
+
// Either print to console or save to db
|
|
2964
|
+
const logCollection = internalGetLogCollection();
|
|
2965
|
+
if (logCollection) {
|
|
2966
|
+
// Store to the log collection
|
|
2967
|
+
yield logCollection.insert(log);
|
|
2968
|
+
}
|
|
2969
|
+
else {
|
|
2970
|
+
// Print to console
|
|
2971
|
+
if (log.type === LogType$1.Error) {
|
|
2972
|
+
console.error('dce-reactkit error log:', log);
|
|
2973
|
+
}
|
|
2974
|
+
else {
|
|
2975
|
+
console.log('dce-reactkit action log:', log);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
// Return log entry
|
|
2979
|
+
return log;
|
|
2980
|
+
});
|
|
2676
2981
|
/*------------------------------------------------------------------------*/
|
|
2677
2982
|
/* Call handler */
|
|
2678
2983
|
/*------------------------------------------------------------------------*/
|
|
@@ -2726,6 +3031,7 @@ const genRouteHandler = (opts) => {
|
|
|
2726
3031
|
},
|
|
2727
3032
|
redirect,
|
|
2728
3033
|
renderErrorPage,
|
|
3034
|
+
logServerEvent,
|
|
2729
3035
|
});
|
|
2730
3036
|
// Send results to client (only if next wasn't called)
|
|
2731
3037
|
if (!responseSent) {
|
|
@@ -2929,6 +3235,43 @@ const parallelLimit = (taskFunctions, limit) => __awaiter(void 0, void 0, void 0
|
|
|
2929
3235
|
return results;
|
|
2930
3236
|
});
|
|
2931
3237
|
|
|
3238
|
+
/**
|
|
3239
|
+
* Log a user action on the client (cannot be used on the server)
|
|
3240
|
+
* @author Gabe Abrams
|
|
3241
|
+
*/
|
|
3242
|
+
const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
3243
|
+
var _a, _b;
|
|
3244
|
+
return visitServerEndpoint({
|
|
3245
|
+
path: LOG_ROUTE_PATH,
|
|
3246
|
+
method: 'POST',
|
|
3247
|
+
params: {
|
|
3248
|
+
category: (typeof opts.category === 'string'
|
|
3249
|
+
? opts.category
|
|
3250
|
+
: opts.category.name),
|
|
3251
|
+
subcategory: (typeof opts.category === 'string'
|
|
3252
|
+
? opts.subcategory
|
|
3253
|
+
: ((_a = opts.subcategory) !== null && _a !== void 0 ? _a : { name: 'none' }).name),
|
|
3254
|
+
tags: JSON.stringify(opts.tags),
|
|
3255
|
+
metadata: JSON.stringify((_b = opts.metadata) !== null && _b !== void 0 ? _b : {}),
|
|
3256
|
+
errorMessage: (opts.error
|
|
3257
|
+
? opts.error.message
|
|
3258
|
+
: undefined),
|
|
3259
|
+
errorCode: (opts.error
|
|
3260
|
+
? opts.error.code
|
|
3261
|
+
: undefined),
|
|
3262
|
+
errorStack: (opts.error
|
|
3263
|
+
? opts.error.stack
|
|
3264
|
+
: undefined),
|
|
3265
|
+
target: (opts.target
|
|
3266
|
+
? opts.target
|
|
3267
|
+
: undefined),
|
|
3268
|
+
action: (opts.action
|
|
3269
|
+
? opts.action
|
|
3270
|
+
: undefined),
|
|
3271
|
+
},
|
|
3272
|
+
});
|
|
3273
|
+
});
|
|
3274
|
+
|
|
2932
3275
|
/**
|
|
2933
3276
|
* Days of the week
|
|
2934
3277
|
* @author Gabe Abrams
|
|
@@ -2945,5 +3288,44 @@ var DayOfWeek;
|
|
|
2945
3288
|
})(DayOfWeek || (DayOfWeek = {}));
|
|
2946
3289
|
var DayOfWeek$1 = DayOfWeek;
|
|
2947
3290
|
|
|
2948
|
-
|
|
3291
|
+
/**
|
|
3292
|
+
* Types of actions
|
|
3293
|
+
* @author Gabe Abrams
|
|
3294
|
+
*/
|
|
3295
|
+
var LogAction;
|
|
3296
|
+
(function (LogAction) {
|
|
3297
|
+
// Target was opened by the user (it was not on screen, but now it is)
|
|
3298
|
+
LogAction["Open"] = "open";
|
|
3299
|
+
// Target was closed by the user (it was on screen, but now it is not)
|
|
3300
|
+
LogAction["Close"] = "close";
|
|
3301
|
+
// Target was expanded by the user (it always remains on screen, but size was changed)
|
|
3302
|
+
LogAction["Expand"] = "expand";
|
|
3303
|
+
// Target was collapsed by the user (it always remains on screen, but size was changed)
|
|
3304
|
+
LogAction["Collapse"] = "collapse";
|
|
3305
|
+
// Target was viewed by the user (only for items that are not opened or closed, those must use Open/Close actions)
|
|
3306
|
+
LogAction["View"] = "view";
|
|
3307
|
+
// Target interrupted the user (popup, dialog, validation message, etc. appeared without user prompting)
|
|
3308
|
+
LogAction["Interrupt"] = "interrupt";
|
|
3309
|
+
// Target was created by the user (it did not exist before)
|
|
3310
|
+
LogAction["Create"] = "create";
|
|
3311
|
+
// Target was edited by the user (it existed and was changed)
|
|
3312
|
+
LogAction["Edit"] = "edit";
|
|
3313
|
+
// Target was deleted by the user (it existed and now it doesn't)
|
|
3314
|
+
LogAction["Delete"] = "delete";
|
|
3315
|
+
// Target was added by the user (it already existed and was added to another place)
|
|
3316
|
+
LogAction["Add"] = "add";
|
|
3317
|
+
// Target was removed by the user (it was removed from something but still exists)
|
|
3318
|
+
LogAction["Remove"] = "remove";
|
|
3319
|
+
// Target was activated by the user (click, check, tap, keypress, etc.)
|
|
3320
|
+
LogAction["Activate"] = "activate";
|
|
3321
|
+
// Target was deactivated by the user (click away, uncheck, tap outside of, tab away, etc.)
|
|
3322
|
+
LogAction["Deactivate"] = "deactivate";
|
|
3323
|
+
// User showed interest in a target (hover, peek, etc.)
|
|
3324
|
+
LogAction["Peek"] = "peek";
|
|
3325
|
+
// Unknown action
|
|
3326
|
+
LogAction["Unknown"] = "unknown";
|
|
3327
|
+
})(LogAction || (LogAction = {}));
|
|
3328
|
+
var LogAction$1 = LogAction;
|
|
3329
|
+
|
|
3330
|
+
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, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
|
2949
3331
|
//# sourceMappingURL=index.js.map
|