dce-reactkit 3.2.0 → 3.2.2-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.
@@ -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
@@ -86,6 +87,7 @@ const initServer = (
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
@@ -101,6 +103,7 @@ const initServer = (
101
103
  context: ParamType.String,
102
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
120
  context: params.context,
117
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,
@@ -128,12 +133,23 @@ const initServer = (
128
133
  context: params.context,
129
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
@@ -55,6 +58,8 @@ type LogMainInfo = {
55
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,
@@ -8,6 +8,7 @@ const LogBuiltInMetadata = {
8
8
  Uncategorized: 'n/a',
9
9
  ServerRenderedErrorPage: '_server-rendered-error-page',
10
10
  ServerEndpointError: '_server-endpoint-error',
11
+ ClientFatalError: '_client-fatal-error',
11
12
  },
12
13
  // Targets
13
14
  Target: {
@@ -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
@@ -20,6 +21,8 @@ type LogFunction = (
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;