dce-reactkit 3.2.0 → 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/dist/cjs/index.js +33 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/types/Log/LogMainInfo.d.ts +2 -0
- package/dist/cjs/types/types/LogFunction.d.ts +2 -0
- package/dist/cjs/types/types/LogLevel.d.ts +10 -0
- package/dist/esm/index.js +33 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/types/Log/LogMainInfo.d.ts +2 -0
- package/dist/esm/types/types/LogFunction.d.ts +2 -0
- package/dist/esm/types/types/LogLevel.d.ts +10 -0
- package/dist/index.d.ts +12 -0
- package/package.json +1 -1
- package/src/helpers/genRouteHandler.ts +5 -2
- package/src/server/initServer.ts +17 -1
- package/src/types/Log/LogMainInfo.ts +5 -0
- package/src/types/LogFunction.ts +3 -0
- package/src/types/LogLevel.ts +11 -0
|
@@ -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
|
|
@@ -520,8 +521,9 @@ const genRouteHandler = (
|
|
|
520
521
|
opts.subcontext
|
|
521
522
|
?? LogBuiltInMetadata.Context.Uncategorized
|
|
522
523
|
),
|
|
523
|
-
tags: opts.tags ?? [],
|
|
524
|
-
|
|
524
|
+
tags: (opts.tags ?? []),
|
|
525
|
+
level: (opts.level ?? LogLevel.Info),
|
|
526
|
+
metadata: (opts.metadata ?? {}),
|
|
525
527
|
};
|
|
526
528
|
|
|
527
529
|
// Type-specific info
|
|
@@ -613,6 +615,7 @@ const genRouteHandler = (
|
|
|
613
615
|
minute: 1,
|
|
614
616
|
timestamp: Date.now(),
|
|
615
617
|
tags: [],
|
|
618
|
+
level: LogLevel.Warn,
|
|
616
619
|
metadata: {},
|
|
617
620
|
context: LogBuiltInMetadata.Context.Uncategorized,
|
|
618
621
|
subcontext: LogBuiltInMetadata.Context.Uncategorized,
|
package/src/server/initServer.ts
CHANGED
|
@@ -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
|
-
|
|
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,
|
package/src/types/LogFunction.ts
CHANGED
|
@@ -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
|
| {
|