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.
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "cSpell.words": [
3
+ "Subcontext",
3
4
  "Uncategorized"
4
5
  ]
5
6
  }
package/dist/cjs/index.js CHANGED
@@ -2203,13 +2203,14 @@ const initServer = (opts) => {
2203
2203
  /**
2204
2204
  * Log an event
2205
2205
  * @author Gabe Abrams
2206
- * @param {string} category Category of the event (each app determines how to
2207
- * categorize its events)
2208
- * @param {string} subcategory Subcategory of the event (each app determines
2209
- * how to categorize its events)
2206
+ * @param {string} context Context of the event (each app determines how to
2207
+ * organize its contexts)
2208
+ * @param {string} subcontext Subcontext of the event (each app determines
2209
+ * how to organize its subcontexts)
2210
2210
  * @param {string} tags stringified list of tags that apply to this action
2211
2211
  * (each app determines tag usage)
2212
2212
  * @param {string} metadata stringified object containing optional custom metadata
2213
+ * @param {string} level log level
2213
2214
  * @param {string} [errorMessage] error message if type is an error
2214
2215
  * @param {string} [errorCode] error code if type is an error
2215
2216
  * @param {string} [errorStack] error stack if type is an error
@@ -2220,9 +2221,10 @@ const initServer = (opts) => {
2220
2221
  */
2221
2222
  opts.app.post(LOG_ROUTE_PATH, genRouteHandler({
2222
2223
  paramTypes: {
2223
- category: ParamType$1.String,
2224
- subcategory: ParamType$1.String,
2224
+ context: ParamType$1.String,
2225
+ subcontext: ParamType$1.String,
2225
2226
  tags: ParamType$1.JSON,
2227
+ level: ParamType$1.String,
2226
2228
  metadata: ParamType$1.JSON,
2227
2229
  errorMessage: ParamType$1.StringOptional,
2228
2230
  errorCode: ParamType$1.StringOptional,
@@ -2231,12 +2233,14 @@ const initServer = (opts) => {
2231
2233
  action: ParamType$1.StringOptional,
2232
2234
  },
2233
2235
  handler: ({ params, logServerEvent }) => {
2234
- const log = logServerEvent((params.errorMessage || params.errorCode || params.errorStack)
2236
+ // Create log info
2237
+ const logInfo = ((params.errorMessage || params.errorCode || params.errorStack)
2235
2238
  // Error
2236
2239
  ? {
2237
- category: params.category,
2238
- subcategory: params.subcategory,
2240
+ context: params.context,
2241
+ subcontext: params.subcontext,
2239
2242
  tags: params.tags,
2243
+ level: params.level,
2240
2244
  metadata: params.metadata,
2241
2245
  error: {
2242
2246
  message: params.errorMessage,
@@ -2246,13 +2250,19 @@ const initServer = (opts) => {
2246
2250
  }
2247
2251
  // Action
2248
2252
  : {
2249
- category: params.category,
2250
- subcategory: params.subcategory,
2253
+ context: params.context,
2254
+ subcontext: params.subcontext,
2251
2255
  tags: params.tags,
2256
+ level: params.level,
2252
2257
  metadata: params.metadata,
2253
2258
  target: params.target,
2254
2259
  action: params.action,
2255
2260
  });
2261
+ // Add hidden boolean to change source to "client"
2262
+ const logInfoForcedFromClient = Object.assign(Object.assign({}, logInfo), { overrideAsClientEvent: true });
2263
+ // Write the log
2264
+ const log = logServerEvent(logInfoForcedFromClient);
2265
+ // Return
2256
2266
  return log;
2257
2267
  },
2258
2268
  }));
@@ -2582,12 +2592,12 @@ var LogSource;
2582
2592
  var LogSource$1 = LogSource;
2583
2593
 
2584
2594
  /**
2585
- * Built-in categories for logs
2595
+ * Built-in metadata for logs
2586
2596
  * @author Gabe Abrams
2587
2597
  */
2588
2598
  const LogBuiltInMetadata = {
2589
- // Categories
2590
- Category: {
2599
+ // Contexts
2600
+ Context: {
2591
2601
  Uncategorized: 'n/a',
2592
2602
  ServerRenderedErrorPage: '_server-rendered-error-page',
2593
2603
  ServerEndpointError: '_server-endpoint-error',
@@ -2639,6 +2649,18 @@ var LogAction;
2639
2649
  })(LogAction || (LogAction = {}));
2640
2650
  var LogAction$1 = LogAction;
2641
2651
 
2652
+ /**
2653
+ * Allowed log levels
2654
+ * @author Gabe Abrams
2655
+ */
2656
+ var LogLevel;
2657
+ (function (LogLevel) {
2658
+ LogLevel["Warn"] = "Warn";
2659
+ LogLevel["Info"] = "Info";
2660
+ LogLevel["Debug"] = "Debug";
2661
+ })(LogLevel || (LogLevel = {}));
2662
+ var LogLevel$1 = LogLevel;
2663
+
2642
2664
  /**
2643
2665
  * Generate an express API route handler
2644
2666
  * @author Gabe Abrams
@@ -2993,14 +3015,13 @@ const genRouteHandler = (opts) => {
2993
3015
  hour,
2994
3016
  minute,
2995
3017
  timestamp,
2996
- category: (typeof opts.category === 'string'
2997
- ? opts.category
2998
- : ((_d = ((_c = opts.category) !== null && _c !== void 0 ? _c : {})._) !== null && _d !== void 0 ? _d : LogBuiltInMetadata.Category.Uncategorized)),
2999
- subcategory: (typeof opts.category === 'string'
3000
- ? opts.subcategory
3001
- : ((_f = ((_e = opts.subcategory) !== null && _e !== void 0 ? _e : {})._) !== null && _f !== void 0 ? _f : LogBuiltInMetadata.Category.Uncategorized)),
3002
- tags: (_g = opts.tags) !== null && _g !== void 0 ? _g : [],
3003
- metadata: (_h = opts.metadata) !== null && _h !== void 0 ? _h : {},
3018
+ context: (typeof opts.context === 'string'
3019
+ ? opts.context
3020
+ : ((_d = ((_c = opts.context) !== null && _c !== void 0 ? _c : {})._) !== null && _d !== void 0 ? _d : LogBuiltInMetadata.Context.Uncategorized)),
3021
+ subcontext: ((_e = opts.subcontext) !== null && _e !== void 0 ? _e : LogBuiltInMetadata.Context.Uncategorized),
3022
+ tags: ((_f = opts.tags) !== null && _f !== void 0 ? _f : []),
3023
+ level: ((_g = opts.level) !== null && _g !== void 0 ? _g : LogLevel$1.Info),
3024
+ metadata: ((_h = opts.metadata) !== null && _h !== void 0 ? _h : {}),
3004
3025
  };
3005
3026
  // Type-specific info
3006
3027
  const typeSpecificInfo = (('error' in opts && opts.error)
@@ -3075,9 +3096,10 @@ const genRouteHandler = (opts) => {
3075
3096
  minute: 1,
3076
3097
  timestamp: Date.now(),
3077
3098
  tags: [],
3099
+ level: LogLevel$1.Warn,
3078
3100
  metadata: {},
3079
- category: LogBuiltInMetadata.Category.Uncategorized,
3080
- subcategory: LogBuiltInMetadata.Category.Uncategorized,
3101
+ context: LogBuiltInMetadata.Context.Uncategorized,
3102
+ subcontext: LogBuiltInMetadata.Context.Uncategorized,
3081
3103
  };
3082
3104
  const dummyTypeSpecificInfo = {
3083
3105
  type: LogType$1.Error,
@@ -3136,7 +3158,7 @@ const genRouteHandler = (opts) => {
3136
3158
  send(html, (_a = opts.status) !== null && _a !== void 0 ? _a : 500);
3137
3159
  // Log
3138
3160
  logServerEvent({
3139
- category: LogBuiltInMetadata.Category.ServerRenderedErrorPage,
3161
+ context: LogBuiltInMetadata.Context.ServerRenderedErrorPage,
3140
3162
  error: {
3141
3163
  message: `${opts.title}: ${opts.description}`,
3142
3164
  code: opts.code,
@@ -3175,7 +3197,7 @@ const genRouteHandler = (opts) => {
3175
3197
  handleError(res, err);
3176
3198
  // Log server-side error
3177
3199
  logServerEvent({
3178
- category: LogBuiltInMetadata.Category.ServerEndpointError,
3200
+ context: LogBuiltInMetadata.Context.ServerEndpointError,
3179
3201
  error: err,
3180
3202
  });
3181
3203
  return;
@@ -3377,19 +3399,17 @@ const parallelLimit = (taskFunctions, limit) => __awaiter(void 0, void 0, void 0
3377
3399
  * @author Gabe Abrams
3378
3400
  */
3379
3401
  const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* () {
3380
- var _a, _b, _c, _d, _e, _f, _g;
3402
+ var _a, _b, _c, _d, _e, _f;
3381
3403
  return visitServerEndpoint({
3382
3404
  path: LOG_ROUTE_PATH,
3383
3405
  method: 'POST',
3384
3406
  params: {
3385
- category: (typeof opts.category === 'string'
3386
- ? opts.category
3387
- : ((_b = ((_a = opts.category) !== null && _a !== void 0 ? _a : {})._) !== null && _b !== void 0 ? _b : LogBuiltInMetadata.Category.Uncategorized)),
3388
- subcategory: (typeof opts.category === 'string'
3389
- ? opts.subcategory
3390
- : ((_d = ((_c = opts.subcategory) !== null && _c !== void 0 ? _c : {})._) !== null && _d !== void 0 ? _d : LogBuiltInMetadata.Category.Uncategorized)),
3391
- tags: JSON.stringify((_e = opts.tags) !== null && _e !== void 0 ? _e : []),
3392
- metadata: JSON.stringify((_f = opts.metadata) !== null && _f !== void 0 ? _f : {}),
3407
+ context: (typeof opts.context === 'string'
3408
+ ? opts.context
3409
+ : ((_b = ((_a = opts.context) !== null && _a !== void 0 ? _a : {})._) !== null && _b !== void 0 ? _b : LogBuiltInMetadata.Context.Uncategorized)),
3410
+ subcontext: ((_c = opts.subcontext) !== null && _c !== void 0 ? _c : LogBuiltInMetadata.Context.Uncategorized),
3411
+ tags: JSON.stringify((_d = opts.tags) !== null && _d !== void 0 ? _d : []),
3412
+ metadata: JSON.stringify((_e = opts.metadata) !== null && _e !== void 0 ? _e : {}),
3393
3413
  errorMessage: (opts.error
3394
3414
  ? opts.error.message
3395
3415
  : undefined),
@@ -3400,7 +3420,7 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
3400
3420
  ? opts.error.stack
3401
3421
  : undefined),
3402
3422
  target: (opts.action
3403
- ? ((_g = opts.target) !== null && _g !== void 0 ? _g : LogBuiltInMetadata.Target.NoSpecificTarget)
3423
+ ? ((_f = opts.target) !== null && _f !== void 0 ? _f : LogBuiltInMetadata.Target.NoSpecificTarget)
3404
3424
  : undefined),
3405
3425
  action: (opts.action
3406
3426
  ? opts.action
@@ -3420,8 +3440,8 @@ const initLogCollection = (Collection) => {
3420
3440
  uniqueIndexKey: 'id',
3421
3441
  indexKeys: [
3422
3442
  'courseId',
3423
- 'category',
3424
- 'subcategory',
3443
+ 'context',
3444
+ 'subcontext',
3425
3445
  'tags',
3426
3446
  ],
3427
3447
  });
@@ -3456,7 +3476,7 @@ exports.HOUR_IN_MS = HOUR_IN_MS;
3456
3476
  exports.ItemPicker = ItemPicker;
3457
3477
  exports.LoadingSpinner = LoadingSpinner;
3458
3478
  exports.LogAction = LogAction$1;
3459
- exports.LogBuiltInCategory = LogBuiltInMetadata;
3479
+ exports.LogBuiltInMetadata = LogBuiltInMetadata;
3460
3480
  exports.LogSource = LogSource$1;
3461
3481
  exports.LogType = LogType$1;
3462
3482
  exports.MINUTE_IN_MS = MINUTE_IN_MS;