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.
@@ -25,6 +25,7 @@ import LogMainInfo from '../types/Log/LogMainInfo';
25
25
  import LogSourceSpecificInfo from '../types/Log/LogSourceSpecificInfo';
26
26
  import LogBuiltInMetadata from '../types/LogBuiltInMetadata';
27
27
  import LogAction from '../types/LogAction';
28
+ import LogLevel from '../types/LogLevel';
28
29
 
29
30
  /**
30
31
  * Generate an express API route handler
@@ -508,24 +509,21 @@ const genRouteHandler = (
508
509
  hour,
509
510
  minute,
510
511
  timestamp,
511
- category: (
512
- typeof opts.category === 'string'
513
- ? opts.category
512
+ context: (
513
+ typeof opts.context === 'string'
514
+ ? opts.context
514
515
  : (
515
- ((opts.category as any) ?? {})._
516
- ?? LogBuiltInMetadata.Category.Uncategorized
516
+ ((opts.context as any) ?? {})._
517
+ ?? LogBuiltInMetadata.Context.Uncategorized
517
518
  )
518
519
  ),
519
- subcategory: (
520
- typeof opts.category === 'string'
521
- ? opts.subcategory
522
- : (
523
- ((opts.subcategory as any) ?? {})._
524
- ?? LogBuiltInMetadata.Category.Uncategorized
525
- )
520
+ subcontext: (
521
+ opts.subcontext
522
+ ?? LogBuiltInMetadata.Context.Uncategorized
526
523
  ),
527
- tags: opts.tags ?? [],
528
- metadata: opts.metadata ?? {},
524
+ tags: (opts.tags ?? []),
525
+ level: (opts.level ?? LogLevel.Info),
526
+ metadata: (opts.metadata ?? {}),
529
527
  };
530
528
 
531
529
  // Type-specific info
@@ -617,9 +615,10 @@ const genRouteHandler = (
617
615
  minute: 1,
618
616
  timestamp: Date.now(),
619
617
  tags: [],
618
+ level: LogLevel.Warn,
620
619
  metadata: {},
621
- category: LogBuiltInMetadata.Category.Uncategorized,
622
- subcategory: LogBuiltInMetadata.Category.Uncategorized,
620
+ context: LogBuiltInMetadata.Context.Uncategorized,
621
+ subcontext: LogBuiltInMetadata.Context.Uncategorized,
623
622
  };
624
623
 
625
624
  const dummyTypeSpecificInfo: LogTypeSpecificInfo = {
@@ -699,7 +698,7 @@ const genRouteHandler = (
699
698
 
700
699
  // Log
701
700
  logServerEvent({
702
- category: LogBuiltInMetadata.Category.ServerRenderedErrorPage,
701
+ context: LogBuiltInMetadata.Context.ServerRenderedErrorPage,
703
702
  error: {
704
703
  message: `${opts.title}: ${opts.description}`,
705
704
  code: opts.code,
@@ -740,7 +739,7 @@ const genRouteHandler = (
740
739
 
741
740
  // Log server-side error
742
741
  logServerEvent({
743
- category: LogBuiltInMetadata.Category.ServerEndpointError,
742
+ context: LogBuiltInMetadata.Context.ServerEndpointError,
744
743
  error: err,
745
744
  });
746
745
 
@@ -15,21 +15,17 @@ const logClientEvent: LogFunction = async (opts) => {
15
15
  path: LOG_ROUTE_PATH,
16
16
  method: 'POST',
17
17
  params: {
18
- category: (
19
- typeof opts.category === 'string'
20
- ? opts.category
18
+ context: (
19
+ typeof opts.context === 'string'
20
+ ? opts.context
21
21
  : (
22
- ((opts.category as any) ?? {})._
23
- ?? LogBuiltInMetadata.Category.Uncategorized
22
+ ((opts.context as any) ?? {})._
23
+ ?? LogBuiltInMetadata.Context.Uncategorized
24
24
  )
25
25
  ),
26
- subcategory: (
27
- typeof opts.category === 'string'
28
- ? opts.subcategory
29
- : (
30
- ((opts.subcategory as any) ?? {})._
31
- ?? LogBuiltInMetadata.Category.Uncategorized
32
- )
26
+ subcontext: (
27
+ opts.subcontext
28
+ ?? LogBuiltInMetadata.Context.Uncategorized
33
29
  ),
34
30
  tags: JSON.stringify(opts.tags ?? []),
35
31
  metadata: JSON.stringify(opts.metadata ?? {}),
package/src/index.ts CHANGED
@@ -63,7 +63,7 @@ import Log from './types/Log';
63
63
  import LogType from './types/LogType';
64
64
  import LogSource from './types/LogSource';
65
65
  import LogAction from './types/LogAction';
66
- import LogBuiltInCategory from './types/LogBuiltInMetadata';
66
+ import LogBuiltInMetadata from './types/LogBuiltInMetadata';
67
67
 
68
68
  // Component-specific-types
69
69
  import PickableItem from './components/ItemPicker/types/PickableItem';
@@ -136,7 +136,7 @@ export {
136
136
  LogType,
137
137
  LogSource,
138
138
  LogAction,
139
- LogBuiltInCategory,
139
+ LogBuiltInMetadata,
140
140
  // Component-specific-types
141
141
  PickableItem,
142
142
  // Server types
@@ -11,8 +11,8 @@ const initLogCollection = (Collection: any) => {
11
11
  uniqueIndexKey: 'id',
12
12
  indexKeys: [
13
13
  'courseId',
14
- 'category',
15
- 'subcategory',
14
+ 'context',
15
+ 'subcontext',
16
16
  'tags',
17
17
  ],
18
18
  },
@@ -4,6 +4,7 @@ import ErrorWithCode from '../errors/ErrorWithCode';
4
4
 
5
5
  // Import shared helpers
6
6
  import genRouteHandler from '../helpers/genRouteHandler';
7
+ import LogFunction from '../types/LogFunction';
7
8
  import ParamType from '../types/ParamType';
8
9
 
9
10
  // Import shared types
@@ -79,13 +80,14 @@ const initServer = (
79
80
  /**
80
81
  * Log an event
81
82
  * @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)
83
+ * @param {string} context Context of the event (each app determines how to
84
+ * organize its contexts)
85
+ * @param {string} subcontext Subcontext of the event (each app determines
86
+ * how to organize its subcontexts)
86
87
  * @param {string} tags stringified list of tags that apply to this action
87
88
  * (each app determines tag usage)
88
89
  * @param {string} metadata stringified object containing optional custom metadata
90
+ * @param {string} level log level
89
91
  * @param {string} [errorMessage] error message if type is an error
90
92
  * @param {string} [errorCode] error code if type is an error
91
93
  * @param {string} [errorStack] error stack if type is an error
@@ -98,9 +100,10 @@ const initServer = (
98
100
  LOG_ROUTE_PATH,
99
101
  genRouteHandler({
100
102
  paramTypes: {
101
- category: ParamType.String,
102
- subcategory: ParamType.String,
103
+ context: ParamType.String,
104
+ subcontext: ParamType.String,
103
105
  tags: ParamType.JSON,
106
+ level: ParamType.String,
104
107
  metadata: ParamType.JSON,
105
108
  errorMessage: ParamType.StringOptional,
106
109
  errorCode: ParamType.StringOptional,
@@ -109,13 +112,15 @@ const initServer = (
109
112
  action: ParamType.StringOptional,
110
113
  },
111
114
  handler: ({ params, logServerEvent }) => {
112
- const log = logServerEvent(
115
+ // Create log info
116
+ const logInfo: Parameters<LogFunction>[0] = (
113
117
  (params.errorMessage || params.errorCode || params.errorStack)
114
118
  // Error
115
119
  ? {
116
- category: params.category,
117
- subcategory: params.subcategory,
120
+ context: params.context,
121
+ subcontext: params.subcontext,
118
122
  tags: params.tags,
123
+ level: params.level,
119
124
  metadata: params.metadata,
120
125
  error: {
121
126
  message: params.errorMessage,
@@ -125,15 +130,26 @@ const initServer = (
125
130
  }
126
131
  // Action
127
132
  : {
128
- category: params.category,
129
- subcategory: params.subcategory,
133
+ context: params.context,
134
+ subcontext: params.subcontext,
130
135
  tags: params.tags,
136
+ level: params.level,
131
137
  metadata: params.metadata,
132
138
  target: params.target,
133
139
  action: params.action,
134
140
  }
135
141
  );
136
142
 
143
+ // Add hidden boolean to change source to "client"
144
+ const logInfoForcedFromClient = {
145
+ ...logInfo,
146
+ overrideAsClientEvent: true,
147
+ };
148
+
149
+ // Write the log
150
+ const log = logServerEvent(logInfoForcedFromClient);
151
+
152
+ // Return
137
153
  return log;
138
154
  },
139
155
  }),
@@ -1,3 +1,6 @@
1
+ // Import shared types
2
+ import LogLevel from '../LogLevel';
3
+
1
4
  /**
2
5
  * Main information in a log event
3
6
  * @author Gabe Abrams
@@ -49,12 +52,14 @@ type LogMainInfo = {
49
52
  minute: number,
50
53
  // Timestamp of event (ms since epoch)
51
54
  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,
55
+ // Context of the event (each app determines how to organize contexts)
56
+ context: string,
57
+ // Subcontext of the event (each app determines how to organize subcontexts)
58
+ subcontext: string,
56
59
  // List of tags that apply to this action (each app determines tag usage)
57
60
  tags: string[],
61
+ // Log level
62
+ level: LogLevel,
58
63
  // Additional optional custom metadata
59
64
  metadata?: {
60
65
  [k: string]: any,
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Built-in categories for logs
2
+ * Built-in metadata for logs
3
3
  * @author Gabe Abrams
4
4
  */
5
5
  const LogBuiltInMetadata = {
6
- // Categories
7
- Category: {
6
+ // Contexts
7
+ Context: {
8
8
  Uncategorized: 'n/a',
9
9
  ServerRenderedErrorPage: '_server-rendered-error-page',
10
10
  ServerEndpointError: '_server-endpoint-error',
@@ -1,6 +1,7 @@
1
1
  // Import shared types
2
2
  import Log from './Log';
3
3
  import LogAction from './LogAction';
4
+ import LogLevel from './LogLevel';
4
5
 
5
6
  /**
6
7
  * Type of a log action function
@@ -10,16 +11,18 @@ type LogFunction = (
10
11
  opts: (
11
12
  // Shared info
12
13
  {
13
- // Category of the event (each app determines how to categorize its events)
14
- category: string | { _: string },
15
- // Subcategory of the event (each app determines how to categorize its events)
16
- subcategory?: string | { _: string },
14
+ // Context of the event (each app determines how to organize contexts)
15
+ context: string | { _: string },
16
+ // Subcontext of the event (each app determines how to organize subcontexts)
17
+ subcontext?: string,
17
18
  // List of tags that apply to this action (each app determines tag usage)
18
19
  tags?: string[],
19
20
  // Additional optional custom metadata
20
21
  metadata?: {
21
22
  [k: string]: any,
22
23
  },
24
+ // Log level (default is info)
25
+ level?: LogLevel,
23
26
  } & (
24
27
  // Error
25
28
  | {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Allowed log levels
3
+ * @author Gabe Abrams
4
+ */
5
+ enum LogLevel {
6
+ Warn = 'Warn',
7
+ Info = 'Info', // Default
8
+ Debug = 'Debug',
9
+ }
10
+
11
+ export default LogLevel;