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
|
@@ -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
|
-
|
|
512
|
-
typeof opts.
|
|
513
|
-
? opts.
|
|
512
|
+
context: (
|
|
513
|
+
typeof opts.context === 'string'
|
|
514
|
+
? opts.context
|
|
514
515
|
: (
|
|
515
|
-
((opts.
|
|
516
|
-
?? LogBuiltInMetadata.
|
|
516
|
+
((opts.context as any) ?? {})._
|
|
517
|
+
?? LogBuiltInMetadata.Context.Uncategorized
|
|
517
518
|
)
|
|
518
519
|
),
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
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
|
-
|
|
622
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
typeof opts.
|
|
20
|
-
? opts.
|
|
18
|
+
context: (
|
|
19
|
+
typeof opts.context === 'string'
|
|
20
|
+
? opts.context
|
|
21
21
|
: (
|
|
22
|
-
((opts.
|
|
23
|
-
?? LogBuiltInMetadata.
|
|
22
|
+
((opts.context as any) ?? {})._
|
|
23
|
+
?? LogBuiltInMetadata.Context.Uncategorized
|
|
24
24
|
)
|
|
25
25
|
),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
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
|
-
|
|
139
|
+
LogBuiltInMetadata,
|
|
140
140
|
// Component-specific-types
|
|
141
141
|
PickableItem,
|
|
142
142
|
// Server types
|
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
|
|
@@ -79,13 +80,14 @@ const initServer = (
|
|
|
79
80
|
/**
|
|
80
81
|
* Log an event
|
|
81
82
|
* @author Gabe Abrams
|
|
82
|
-
* @param {string}
|
|
83
|
-
*
|
|
84
|
-
* @param {string}
|
|
85
|
-
* how to
|
|
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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
115
|
+
// Create log info
|
|
116
|
+
const logInfo: Parameters<LogFunction>[0] = (
|
|
113
117
|
(params.errorMessage || params.errorCode || params.errorStack)
|
|
114
118
|
// Error
|
|
115
119
|
? {
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
129
|
-
|
|
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
|
-
//
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
|
|
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
|
|
2
|
+
* Built-in metadata for logs
|
|
3
3
|
* @author Gabe Abrams
|
|
4
4
|
*/
|
|
5
5
|
const LogBuiltInMetadata = {
|
|
6
|
-
//
|
|
7
|
-
|
|
6
|
+
// Contexts
|
|
7
|
+
Context: {
|
|
8
8
|
Uncategorized: 'n/a',
|
|
9
9
|
ServerRenderedErrorPage: '_server-rendered-error-page',
|
|
10
10
|
ServerEndpointError: '_server-endpoint-error',
|
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
|
|
@@ -10,16 +11,18 @@ type LogFunction = (
|
|
|
10
11
|
opts: (
|
|
11
12
|
// Shared info
|
|
12
13
|
{
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
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
|
| {
|