dce-reactkit 3.6.20 → 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 CHANGED
@@ -773,23 +773,50 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
773
773
  return body;
774
774
  });
775
775
 
776
+ // Current metadata populator function
777
+ let metadataPopulator;
778
+ /**
779
+ * Set the metadata populator function that will be called before every client
780
+ * event is logged. The function should return a set of metadata values that
781
+ * will be added to all client events
782
+ * @author Gabe Abrams
783
+ * @param metadataPopulator function to call that will return a set of metadata
784
+ * values that will be added to all client events
785
+ */
786
+ const setClientEventMetadataPopulator = (newMetadataPopulator) => {
787
+ metadataPopulator = newMetadataPopulator;
788
+ };
789
+ /* -------------- Main -------------- */
776
790
  /**
777
791
  * Log a user action on the client (cannot be used on the server)
778
792
  * @author Gabe Abrams
779
793
  */
780
794
  const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* () {
781
795
  var _a, _b, _c, _d, _e, _f, _g;
796
+ // Populate metadata
797
+ let metadata = ((_a = opts.metadata) !== null && _a !== void 0 ? _a : {});
798
+ if (metadataPopulator) {
799
+ try {
800
+ const autoPopulatedMetadata = yield metadataPopulator();
801
+ metadata = Object.assign(Object.assign({}, autoPopulatedMetadata), metadata);
802
+ }
803
+ catch (err) {
804
+ // Add error to metadata
805
+ metadata = Object.assign({ autoPopulatedMetadataNotAvailable: true }, metadata);
806
+ }
807
+ }
808
+ // Send to server
782
809
  return visitServerEndpoint({
783
810
  path: LOG_ROUTE_PATH,
784
811
  method: 'POST',
785
812
  params: {
786
813
  context: (typeof opts.context === 'string'
787
814
  ? opts.context
788
- : ((_b = ((_a = opts.context) !== null && _a !== void 0 ? _a : {})._) !== null && _b !== void 0 ? _b : LogBuiltInMetadata.Context.Uncategorized)),
789
- subcontext: ((_c = opts.subcontext) !== null && _c !== void 0 ? _c : LogBuiltInMetadata.Context.Uncategorized),
790
- level: ((_d = opts.level) !== null && _d !== void 0 ? _d : LogLevel$1.Info),
791
- tags: JSON.stringify((_e = opts.tags) !== null && _e !== void 0 ? _e : []),
792
- metadata: JSON.stringify((_f = opts.metadata) !== null && _f !== void 0 ? _f : {}),
815
+ : ((_c = ((_b = opts.context) !== null && _b !== void 0 ? _b : {})._) !== null && _c !== void 0 ? _c : LogBuiltInMetadata.Context.Uncategorized)),
816
+ subcontext: ((_d = opts.subcontext) !== null && _d !== void 0 ? _d : LogBuiltInMetadata.Context.Uncategorized),
817
+ level: ((_e = opts.level) !== null && _e !== void 0 ? _e : LogLevel$1.Info),
818
+ tags: JSON.stringify((_f = opts.tags) !== null && _f !== void 0 ? _f : []),
819
+ metadata: JSON.stringify(metadata),
793
820
  errorMessage: (opts.error
794
821
  ? opts.error.message
795
822
  : undefined),
@@ -43510,6 +43537,7 @@ exports.padZerosLeft = padZerosLeft;
43510
43537
  exports.parallelLimit = parallelLimit;
43511
43538
  exports.prefixWithAOrAn = prefixWithAOrAn;
43512
43539
  exports.roundToNumDecimals = roundToNumDecimals;
43540
+ exports.setClientEventMetadataPopulator = setClientEventMetadataPopulator;
43513
43541
  exports.showFatalError = showFatalError;
43514
43542
  exports.startMinWait = startMinWait;
43515
43543
  exports.stringsToHumanReadableList = stringsToHumanReadableList;