dce-reactkit 3.6.20 → 3.6.22
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 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/logClientEvent.d.ts +14 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/esm/index.js +33 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/helpers/logClientEvent.d.ts +14 -0
- package/dist/esm/types/index.d.ts +2 -2
- 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
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import LogFunction from '../types/LogFunction';
|
|
2
|
+
type MetadataPopulator = () => {
|
|
3
|
+
[k: string]: any;
|
|
4
|
+
} | Promise<{
|
|
5
|
+
[k: string]: any;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Set the metadata populator function that will be called before every client
|
|
9
|
+
* event is logged. The function should return a set of metadata values that
|
|
10
|
+
* will be added to all client events
|
|
11
|
+
* @author Gabe Abrams
|
|
12
|
+
* @param metadataPopulator function to call that will return a set of metadata
|
|
13
|
+
* values that will be added to all client events
|
|
14
|
+
*/
|
|
15
|
+
export declare const setClientEventMetadataPopulator: (newMetadataPopulator: MetadataPopulator) => void;
|
|
2
16
|
/**
|
|
3
17
|
* Log a user action on the client (cannot be used on the server)
|
|
4
18
|
* @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
|
@@ -1188,6 +1188,20 @@ declare const onlyKeepLetters: (str: string) => string;
|
|
|
1188
1188
|
*/
|
|
1189
1189
|
declare const parallelLimit: (taskFunctions: (() => Promise<any>)[], limit?: number) => Promise<any[]>;
|
|
1190
1190
|
|
|
1191
|
+
type MetadataPopulator = () => {
|
|
1192
|
+
[k: string]: any;
|
|
1193
|
+
} | Promise<{
|
|
1194
|
+
[k: string]: any;
|
|
1195
|
+
}>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Set the metadata populator function that will be called before every client
|
|
1198
|
+
* event is logged. The function should return a set of metadata values that
|
|
1199
|
+
* will be added to all client events
|
|
1200
|
+
* @author Gabe Abrams
|
|
1201
|
+
* @param metadataPopulator function to call that will return a set of metadata
|
|
1202
|
+
* values that will be added to all client events
|
|
1203
|
+
*/
|
|
1204
|
+
declare const setClientEventMetadataPopulator: (newMetadataPopulator: MetadataPopulator) => void;
|
|
1191
1205
|
/**
|
|
1192
1206
|
* Log a user action on the client (cannot be used on the server)
|
|
1193
1207
|
* @author Gabe Abrams
|
|
@@ -1497,4 +1511,4 @@ declare const LogBuiltInMetadata: {
|
|
|
1497
1511
|
};
|
|
1498
1512
|
};
|
|
1499
1513
|
|
|
1500
|
-
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 };
|
|
1514
|
+
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 = () => { [k: string]: any } | 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,
|