UNPKG

@dynatrace/react-native-plugin

Version:

This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.

70 lines (69 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventLimitation = void 0; const ConsoleLogger_1 = require("../../../core/logging/ConsoleLogger"); const EventSpecContstants_1 = require("../spec/EventSpecContstants"); class EventLimitation { constructor() { this.logger = new ConsoleLogger_1.ConsoleLogger('EventLimitation'); } limitEventEntries(customEntries) { const fieldEntries = customEntries.slice(); fieldEntries.forEach(this.restrictingValueSize, this); const validEntries = fieldEntries .filter(this.isNotObject, this) .filter(this.doesNotExceedKeySize, this) .filter(this.isKeySyntaxAllowed, this); if (fieldEntries.length !== validEntries.length) { return validEntries; } else { return fieldEntries; } } limitEventProperties(eventEntries) { const allowedEntries = []; let propertyCounter = 0; for (const [key, value] of eventEntries) { if (key.startsWith("event_properties") || key.startsWith("session_properties")) { propertyCounter++; if (propertyCounter > EventSpecContstants_1.MAX_CUSTOM_EVENT_FIELDS) { this.logger.debug(`limitEventProperties(): Dropped ${key} because overall property limit is reached!`); continue; } } allowedEntries.push([key, value]); } return allowedEntries; } isKeySyntaxAllowed(entry) { const [key] = entry; const rV = EventSpecContstants_1.KEY_NAME_REGEX.test(key); if (!rV) { this.logger.debug(`isKeySyntaxAllowed(): Filtering key ${key} as it doesnt fulfill character rules!`); } return rV; } restrictingValueSize(entry) { const [key, value] = entry; if (typeof value === 'string' && value.length > EventSpecContstants_1.MAX_CUSTOM_EVENT_VALUE_LENGTH) { this.logger.debug(`restrictingValueSize(): Limiting value of ${key} as maximum value length (${EventSpecContstants_1.MAX_CUSTOM_EVENT_VALUE_LENGTH}) is reached!`); entry[1] = value.slice(0, EventSpecContstants_1.MAX_CUSTOM_EVENT_VALUE_LENGTH); } } doesNotExceedKeySize([key]) { if (key.length <= EventSpecContstants_1.MAX_CUSTOM_EVENT_KEY_LENGTH) { return true; } else { this.logger.debug(`doesNotExceedKeySize(): Dropping key ${key} as maximum key length (${EventSpecContstants_1.MAX_CUSTOM_EVENT_KEY_LENGTH}) is reached!`); return false; } } isNotObject([, val]) { return typeof val !== 'object' || val === null; } } exports.EventLimitation = EventLimitation;