dce-reactkit 3.6.19 → 3.6.21
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 +37 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/logClientEvent.d.ts +12 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/types/LogAction.d.ts +2 -0
- package/dist/esm/index.js +37 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/helpers/logClientEvent.d.ts +12 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/types/LogAction.d.ts +2 -0
- package/dist/index.d.ts +15 -1
- package/package.json +1 -1
- package/src/helpers/logClientEvent.tsx +44 -1
- package/src/index.ts +2 -1
- package/src/types/LogAction.ts +5 -1
- package/src/types/LogType.ts +1 -1
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import LogFunction from '../types/LogFunction';
|
|
2
|
+
type MetadataPopulator = () => Promise<{
|
|
3
|
+
[k: string]: any;
|
|
4
|
+
}>;
|
|
5
|
+
/**
|
|
6
|
+
* Set the metadata populator function that will be called before every client
|
|
7
|
+
* event is logged. The function should return a set of metadata values that
|
|
8
|
+
* will be added to all client events
|
|
9
|
+
* @author Gabe Abrams
|
|
10
|
+
* @param metadataPopulator function to call that will return a set of metadata
|
|
11
|
+
* values that will be added to all client events
|
|
12
|
+
*/
|
|
13
|
+
export declare const setClientEventMetadataPopulator: (newMetadataPopulator: MetadataPopulator) => void;
|
|
2
14
|
/**
|
|
3
15
|
* Log a user action on the client (cannot be used on the server)
|
|
4
16
|
* @author Gabe Abrams
|
|
@@ -51,7 +51,7 @@ import getPartOfDay from './helpers/getPartOfDay';
|
|
|
51
51
|
import stringsToHumanReadableList from './helpers/stringsToHumanReadableList';
|
|
52
52
|
import onlyKeepLetters from './helpers/onlyKeepLetters';
|
|
53
53
|
import parallelLimit from './helpers/parallelLimit';
|
|
54
|
-
import logClientEvent from './helpers/logClientEvent';
|
|
54
|
+
import logClientEvent, { setClientEventMetadataPopulator } from './helpers/logClientEvent';
|
|
55
55
|
import initLogCollection from './server/initLogCollection';
|
|
56
56
|
import getMonthName from './helpers/getMonthName';
|
|
57
57
|
import genCSV from './helpers/genCSV';
|
|
@@ -88,4 +88,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
|
|
|
88
88
|
import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
|
|
89
89
|
import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
|
|
90
90
|
import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
|
|
91
|
-
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, prefixWithAOrAn, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
|
|
91
|
+
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, prefixWithAOrAn, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
|
package/dist/index.d.ts
CHANGED
|
@@ -931,6 +931,8 @@ declare enum LogAction {
|
|
|
931
931
|
Activate = "Activate",
|
|
932
932
|
Deactivate = "Deactivate",
|
|
933
933
|
Peek = "Peek",
|
|
934
|
+
Halt = "Halt",
|
|
935
|
+
Resume = "Resume",
|
|
934
936
|
Unknown = "Unknown"
|
|
935
937
|
}
|
|
936
938
|
|
|
@@ -1186,6 +1188,18 @@ declare const onlyKeepLetters: (str: string) => string;
|
|
|
1186
1188
|
*/
|
|
1187
1189
|
declare const parallelLimit: (taskFunctions: (() => Promise<any>)[], limit?: number) => Promise<any[]>;
|
|
1188
1190
|
|
|
1191
|
+
type MetadataPopulator = () => Promise<{
|
|
1192
|
+
[k: string]: any;
|
|
1193
|
+
}>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Set the metadata populator function that will be called before every client
|
|
1196
|
+
* event is logged. The function should return a set of metadata values that
|
|
1197
|
+
* will be added to all client events
|
|
1198
|
+
* @author Gabe Abrams
|
|
1199
|
+
* @param metadataPopulator function to call that will return a set of metadata
|
|
1200
|
+
* values that will be added to all client events
|
|
1201
|
+
*/
|
|
1202
|
+
declare const setClientEventMetadataPopulator: (newMetadataPopulator: MetadataPopulator) => void;
|
|
1189
1203
|
/**
|
|
1190
1204
|
* Log a user action on the client (cannot be used on the server)
|
|
1191
1205
|
* @author Gabe Abrams
|
|
@@ -1495,4 +1509,4 @@ declare const LogBuiltInMetadata: {
|
|
|
1495
1509
|
};
|
|
1496
1510
|
};
|
|
1497
1511
|
|
|
1498
|
-
export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
|
|
1512
|
+
export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
|
package/package.json
CHANGED
|
@@ -7,11 +7,54 @@ import LogLevel from '../types/LogLevel';
|
|
|
7
7
|
// Import shared functions
|
|
8
8
|
import visitServerEndpoint from './visitServerEndpoint';
|
|
9
9
|
|
|
10
|
+
/* ------- Metadata Populator ------- */
|
|
11
|
+
|
|
12
|
+
// Type of a metadata populator function
|
|
13
|
+
type MetadataPopulator = () => Promise<{ [k: string]: any }>;
|
|
14
|
+
|
|
15
|
+
// Current metadata populator function
|
|
16
|
+
let metadataPopulator: MetadataPopulator;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Set the metadata populator function that will be called before every client
|
|
20
|
+
* event is logged. The function should return a set of metadata values that
|
|
21
|
+
* will be added to all client events
|
|
22
|
+
* @author Gabe Abrams
|
|
23
|
+
* @param metadataPopulator function to call that will return a set of metadata
|
|
24
|
+
* values that will be added to all client events
|
|
25
|
+
*/
|
|
26
|
+
export const setClientEventMetadataPopulator = (
|
|
27
|
+
newMetadataPopulator: MetadataPopulator,
|
|
28
|
+
) => {
|
|
29
|
+
metadataPopulator = newMetadataPopulator;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/* -------------- Main -------------- */
|
|
33
|
+
|
|
10
34
|
/**
|
|
11
35
|
* Log a user action on the client (cannot be used on the server)
|
|
12
36
|
* @author Gabe Abrams
|
|
13
37
|
*/
|
|
14
38
|
const logClientEvent: LogFunction = async (opts) => {
|
|
39
|
+
// Populate metadata
|
|
40
|
+
let metadata = (opts.metadata ?? {});
|
|
41
|
+
if (metadataPopulator) {
|
|
42
|
+
try {
|
|
43
|
+
const autoPopulatedMetadata = await metadataPopulator();
|
|
44
|
+
metadata = {
|
|
45
|
+
...autoPopulatedMetadata,
|
|
46
|
+
...metadata,
|
|
47
|
+
};
|
|
48
|
+
} catch (err) {
|
|
49
|
+
// Add error to metadata
|
|
50
|
+
metadata = {
|
|
51
|
+
autoPopulatedMetadataNotAvailable: true,
|
|
52
|
+
...metadata,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Send to server
|
|
15
58
|
return visitServerEndpoint({
|
|
16
59
|
path: LOG_ROUTE_PATH,
|
|
17
60
|
method: 'POST',
|
|
@@ -33,7 +76,7 @@ const logClientEvent: LogFunction = async (opts) => {
|
|
|
33
76
|
?? LogLevel.Info
|
|
34
77
|
),
|
|
35
78
|
tags: JSON.stringify(opts.tags ?? []),
|
|
36
|
-
metadata: JSON.stringify(
|
|
79
|
+
metadata: JSON.stringify(metadata),
|
|
37
80
|
errorMessage: (
|
|
38
81
|
(opts as any).error
|
|
39
82
|
? (opts as any).error.message
|
package/src/index.ts
CHANGED
|
@@ -66,7 +66,7 @@ import getPartOfDay from './helpers/getPartOfDay';
|
|
|
66
66
|
import stringsToHumanReadableList from './helpers/stringsToHumanReadableList';
|
|
67
67
|
import onlyKeepLetters from './helpers/onlyKeepLetters';
|
|
68
68
|
import parallelLimit from './helpers/parallelLimit';
|
|
69
|
-
import logClientEvent from './helpers/logClientEvent';
|
|
69
|
+
import logClientEvent, { setClientEventMetadataPopulator } from './helpers/logClientEvent';
|
|
70
70
|
import initLogCollection from './server/initLogCollection';
|
|
71
71
|
import getMonthName from './helpers/getMonthName';
|
|
72
72
|
import genCSV from './helpers/genCSV';
|
|
@@ -188,6 +188,7 @@ export {
|
|
|
188
188
|
leaveToURL,
|
|
189
189
|
combineClassNames,
|
|
190
190
|
useForceRender,
|
|
191
|
+
setClientEventMetadataPopulator,
|
|
191
192
|
// Server helpers
|
|
192
193
|
initServer,
|
|
193
194
|
genRouteHandler,
|
package/src/types/LogAction.ts
CHANGED
|
@@ -33,8 +33,12 @@ enum LogAction {
|
|
|
33
33
|
Deactivate = 'Deactivate',
|
|
34
34
|
// User showed interest in a target (hover, peek, etc.)
|
|
35
35
|
Peek = 'Peek',
|
|
36
|
+
// Halt a process (pause, etc.)
|
|
37
|
+
Halt = 'Halt',
|
|
38
|
+
// Resume a process (resume a halted process)
|
|
39
|
+
Resume = 'Resume',
|
|
36
40
|
// Unknown action
|
|
37
41
|
Unknown = 'Unknown',
|
|
38
|
-
}
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
export default LogAction;
|