dce-reactkit 3.2.0-beta.9 → 3.2.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/.vscode/settings.json +1 -0
- package/dist/cjs/index.js +59 -39
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/types/Log/LogMainInfo.d.ts +4 -2
- package/dist/cjs/types/types/LogBuiltInMetadata.d.ts +2 -2
- package/dist/cjs/types/types/LogFunction.d.ts +4 -4
- package/dist/cjs/types/types/LogLevel.d.ts +10 -0
- package/dist/esm/index.js +59 -39
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/types/Log/LogMainInfo.d.ts +4 -2
- package/dist/esm/types/types/LogBuiltInMetadata.d.ts +2 -2
- package/dist/esm/types/types/LogFunction.d.ts +4 -4
- package/dist/esm/types/types/LogLevel.d.ts +10 -0
- package/dist/index.d.ts +19 -9
- package/package.json +1 -1
- package/src/helpers/genRouteHandler.ts +17 -18
- package/src/helpers/logClientEvent.tsx +8 -12
- package/src/index.ts +2 -2
- package/src/server/initLogCollection.ts +2 -2
- package/src/server/initServer.ts +27 -11
- package/src/types/Log/LogMainInfo.ts +9 -4
- package/src/types/LogBuiltInMetadata.ts +3 -3
- package/src/types/LogFunction.ts +7 -4
- package/src/types/LogLevel.ts +11 -0
package/dist/esm/index.js
CHANGED
|
@@ -2195,13 +2195,14 @@ const initServer = (opts) => {
|
|
|
2195
2195
|
/**
|
|
2196
2196
|
* Log an event
|
|
2197
2197
|
* @author Gabe Abrams
|
|
2198
|
-
* @param {string}
|
|
2199
|
-
*
|
|
2200
|
-
* @param {string}
|
|
2201
|
-
* how to
|
|
2198
|
+
* @param {string} context Context of the event (each app determines how to
|
|
2199
|
+
* organize its contexts)
|
|
2200
|
+
* @param {string} subcontext Subcontext of the event (each app determines
|
|
2201
|
+
* how to organize its subcontexts)
|
|
2202
2202
|
* @param {string} tags stringified list of tags that apply to this action
|
|
2203
2203
|
* (each app determines tag usage)
|
|
2204
2204
|
* @param {string} metadata stringified object containing optional custom metadata
|
|
2205
|
+
* @param {string} level log level
|
|
2205
2206
|
* @param {string} [errorMessage] error message if type is an error
|
|
2206
2207
|
* @param {string} [errorCode] error code if type is an error
|
|
2207
2208
|
* @param {string} [errorStack] error stack if type is an error
|
|
@@ -2212,9 +2213,10 @@ const initServer = (opts) => {
|
|
|
2212
2213
|
*/
|
|
2213
2214
|
opts.app.post(LOG_ROUTE_PATH, genRouteHandler({
|
|
2214
2215
|
paramTypes: {
|
|
2215
|
-
|
|
2216
|
-
|
|
2216
|
+
context: ParamType$1.String,
|
|
2217
|
+
subcontext: ParamType$1.String,
|
|
2217
2218
|
tags: ParamType$1.JSON,
|
|
2219
|
+
level: ParamType$1.String,
|
|
2218
2220
|
metadata: ParamType$1.JSON,
|
|
2219
2221
|
errorMessage: ParamType$1.StringOptional,
|
|
2220
2222
|
errorCode: ParamType$1.StringOptional,
|
|
@@ -2223,12 +2225,14 @@ const initServer = (opts) => {
|
|
|
2223
2225
|
action: ParamType$1.StringOptional,
|
|
2224
2226
|
},
|
|
2225
2227
|
handler: ({ params, logServerEvent }) => {
|
|
2226
|
-
|
|
2228
|
+
// Create log info
|
|
2229
|
+
const logInfo = ((params.errorMessage || params.errorCode || params.errorStack)
|
|
2227
2230
|
// Error
|
|
2228
2231
|
? {
|
|
2229
|
-
|
|
2230
|
-
|
|
2232
|
+
context: params.context,
|
|
2233
|
+
subcontext: params.subcontext,
|
|
2231
2234
|
tags: params.tags,
|
|
2235
|
+
level: params.level,
|
|
2232
2236
|
metadata: params.metadata,
|
|
2233
2237
|
error: {
|
|
2234
2238
|
message: params.errorMessage,
|
|
@@ -2238,13 +2242,19 @@ const initServer = (opts) => {
|
|
|
2238
2242
|
}
|
|
2239
2243
|
// Action
|
|
2240
2244
|
: {
|
|
2241
|
-
|
|
2242
|
-
|
|
2245
|
+
context: params.context,
|
|
2246
|
+
subcontext: params.subcontext,
|
|
2243
2247
|
tags: params.tags,
|
|
2248
|
+
level: params.level,
|
|
2244
2249
|
metadata: params.metadata,
|
|
2245
2250
|
target: params.target,
|
|
2246
2251
|
action: params.action,
|
|
2247
2252
|
});
|
|
2253
|
+
// Add hidden boolean to change source to "client"
|
|
2254
|
+
const logInfoForcedFromClient = Object.assign(Object.assign({}, logInfo), { overrideAsClientEvent: true });
|
|
2255
|
+
// Write the log
|
|
2256
|
+
const log = logServerEvent(logInfoForcedFromClient);
|
|
2257
|
+
// Return
|
|
2248
2258
|
return log;
|
|
2249
2259
|
},
|
|
2250
2260
|
}));
|
|
@@ -2574,12 +2584,12 @@ var LogSource;
|
|
|
2574
2584
|
var LogSource$1 = LogSource;
|
|
2575
2585
|
|
|
2576
2586
|
/**
|
|
2577
|
-
* Built-in
|
|
2587
|
+
* Built-in metadata for logs
|
|
2578
2588
|
* @author Gabe Abrams
|
|
2579
2589
|
*/
|
|
2580
2590
|
const LogBuiltInMetadata = {
|
|
2581
|
-
//
|
|
2582
|
-
|
|
2591
|
+
// Contexts
|
|
2592
|
+
Context: {
|
|
2583
2593
|
Uncategorized: 'n/a',
|
|
2584
2594
|
ServerRenderedErrorPage: '_server-rendered-error-page',
|
|
2585
2595
|
ServerEndpointError: '_server-endpoint-error',
|
|
@@ -2631,6 +2641,18 @@ var LogAction;
|
|
|
2631
2641
|
})(LogAction || (LogAction = {}));
|
|
2632
2642
|
var LogAction$1 = LogAction;
|
|
2633
2643
|
|
|
2644
|
+
/**
|
|
2645
|
+
* Allowed log levels
|
|
2646
|
+
* @author Gabe Abrams
|
|
2647
|
+
*/
|
|
2648
|
+
var LogLevel;
|
|
2649
|
+
(function (LogLevel) {
|
|
2650
|
+
LogLevel["Warn"] = "Warn";
|
|
2651
|
+
LogLevel["Info"] = "Info";
|
|
2652
|
+
LogLevel["Debug"] = "Debug";
|
|
2653
|
+
})(LogLevel || (LogLevel = {}));
|
|
2654
|
+
var LogLevel$1 = LogLevel;
|
|
2655
|
+
|
|
2634
2656
|
/**
|
|
2635
2657
|
* Generate an express API route handler
|
|
2636
2658
|
* @author Gabe Abrams
|
|
@@ -2985,14 +3007,13 @@ const genRouteHandler = (opts) => {
|
|
|
2985
3007
|
hour,
|
|
2986
3008
|
minute,
|
|
2987
3009
|
timestamp,
|
|
2988
|
-
|
|
2989
|
-
? opts.
|
|
2990
|
-
: ((_d = ((_c = opts.
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
metadata: (_h = opts.metadata) !== null && _h !== void 0 ? _h : {},
|
|
3010
|
+
context: (typeof opts.context === 'string'
|
|
3011
|
+
? opts.context
|
|
3012
|
+
: ((_d = ((_c = opts.context) !== null && _c !== void 0 ? _c : {})._) !== null && _d !== void 0 ? _d : LogBuiltInMetadata.Context.Uncategorized)),
|
|
3013
|
+
subcontext: ((_e = opts.subcontext) !== null && _e !== void 0 ? _e : LogBuiltInMetadata.Context.Uncategorized),
|
|
3014
|
+
tags: ((_f = opts.tags) !== null && _f !== void 0 ? _f : []),
|
|
3015
|
+
level: ((_g = opts.level) !== null && _g !== void 0 ? _g : LogLevel$1.Info),
|
|
3016
|
+
metadata: ((_h = opts.metadata) !== null && _h !== void 0 ? _h : {}),
|
|
2996
3017
|
};
|
|
2997
3018
|
// Type-specific info
|
|
2998
3019
|
const typeSpecificInfo = (('error' in opts && opts.error)
|
|
@@ -3067,9 +3088,10 @@ const genRouteHandler = (opts) => {
|
|
|
3067
3088
|
minute: 1,
|
|
3068
3089
|
timestamp: Date.now(),
|
|
3069
3090
|
tags: [],
|
|
3091
|
+
level: LogLevel$1.Warn,
|
|
3070
3092
|
metadata: {},
|
|
3071
|
-
|
|
3072
|
-
|
|
3093
|
+
context: LogBuiltInMetadata.Context.Uncategorized,
|
|
3094
|
+
subcontext: LogBuiltInMetadata.Context.Uncategorized,
|
|
3073
3095
|
};
|
|
3074
3096
|
const dummyTypeSpecificInfo = {
|
|
3075
3097
|
type: LogType$1.Error,
|
|
@@ -3128,7 +3150,7 @@ const genRouteHandler = (opts) => {
|
|
|
3128
3150
|
send(html, (_a = opts.status) !== null && _a !== void 0 ? _a : 500);
|
|
3129
3151
|
// Log
|
|
3130
3152
|
logServerEvent({
|
|
3131
|
-
|
|
3153
|
+
context: LogBuiltInMetadata.Context.ServerRenderedErrorPage,
|
|
3132
3154
|
error: {
|
|
3133
3155
|
message: `${opts.title}: ${opts.description}`,
|
|
3134
3156
|
code: opts.code,
|
|
@@ -3167,7 +3189,7 @@ const genRouteHandler = (opts) => {
|
|
|
3167
3189
|
handleError(res, err);
|
|
3168
3190
|
// Log server-side error
|
|
3169
3191
|
logServerEvent({
|
|
3170
|
-
|
|
3192
|
+
context: LogBuiltInMetadata.Context.ServerEndpointError,
|
|
3171
3193
|
error: err,
|
|
3172
3194
|
});
|
|
3173
3195
|
return;
|
|
@@ -3369,19 +3391,17 @@ const parallelLimit = (taskFunctions, limit) => __awaiter(void 0, void 0, void 0
|
|
|
3369
3391
|
* @author Gabe Abrams
|
|
3370
3392
|
*/
|
|
3371
3393
|
const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
3372
|
-
var _a, _b, _c, _d, _e, _f
|
|
3394
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3373
3395
|
return visitServerEndpoint({
|
|
3374
3396
|
path: LOG_ROUTE_PATH,
|
|
3375
3397
|
method: 'POST',
|
|
3376
3398
|
params: {
|
|
3377
|
-
|
|
3378
|
-
? opts.
|
|
3379
|
-
: ((_b = ((_a = opts.
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
tags: JSON.stringify((_e = opts.tags) !== null && _e !== void 0 ? _e : []),
|
|
3384
|
-
metadata: JSON.stringify((_f = opts.metadata) !== null && _f !== void 0 ? _f : {}),
|
|
3399
|
+
context: (typeof opts.context === 'string'
|
|
3400
|
+
? opts.context
|
|
3401
|
+
: ((_b = ((_a = opts.context) !== null && _a !== void 0 ? _a : {})._) !== null && _b !== void 0 ? _b : LogBuiltInMetadata.Context.Uncategorized)),
|
|
3402
|
+
subcontext: ((_c = opts.subcontext) !== null && _c !== void 0 ? _c : LogBuiltInMetadata.Context.Uncategorized),
|
|
3403
|
+
tags: JSON.stringify((_d = opts.tags) !== null && _d !== void 0 ? _d : []),
|
|
3404
|
+
metadata: JSON.stringify((_e = opts.metadata) !== null && _e !== void 0 ? _e : {}),
|
|
3385
3405
|
errorMessage: (opts.error
|
|
3386
3406
|
? opts.error.message
|
|
3387
3407
|
: undefined),
|
|
@@ -3392,7 +3412,7 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
3392
3412
|
? opts.error.stack
|
|
3393
3413
|
: undefined),
|
|
3394
3414
|
target: (opts.action
|
|
3395
|
-
? ((
|
|
3415
|
+
? ((_f = opts.target) !== null && _f !== void 0 ? _f : LogBuiltInMetadata.Target.NoSpecificTarget)
|
|
3396
3416
|
: undefined),
|
|
3397
3417
|
action: (opts.action
|
|
3398
3418
|
? opts.action
|
|
@@ -3412,8 +3432,8 @@ const initLogCollection = (Collection) => {
|
|
|
3412
3432
|
uniqueIndexKey: 'id',
|
|
3413
3433
|
indexKeys: [
|
|
3414
3434
|
'courseId',
|
|
3415
|
-
'
|
|
3416
|
-
'
|
|
3435
|
+
'context',
|
|
3436
|
+
'subcontext',
|
|
3417
3437
|
'tags',
|
|
3418
3438
|
],
|
|
3419
3439
|
});
|
|
@@ -3435,5 +3455,5 @@ var DayOfWeek;
|
|
|
3435
3455
|
})(DayOfWeek || (DayOfWeek = {}));
|
|
3436
3456
|
var DayOfWeek$1 = DayOfWeek;
|
|
3437
3457
|
|
|
3438
|
-
export { AppWrapper, ButtonInputGroup, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek$1 as DayOfWeek, Drawer, ErrorBox, ErrorWithCode, HOUR_IN_MS, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata
|
|
3458
|
+
export { AppWrapper, ButtonInputGroup, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek$1 as DayOfWeek, Drawer, ErrorBox, ErrorWithCode, HOUR_IN_MS, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, 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, initLogCollection, initServer, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
|
3439
3459
|
//# sourceMappingURL=index.js.map
|