UNPKG

@iota-big3/sdk-gateway

Version:

Universal API Gateway with protocol translation, intelligent routing, rate limiting, health checking, and caching

495 lines 16.7 kB
"use strict"; /** * Analytics & Metrics Type Definitions * * @module analytics-metrics-types * @description Comprehensive types for analytics and metrics including: * - Time-series data management * - Key Performance Indicators (KPIs) * - Business metrics and dashboards * - Reporting and visualization * - Real-time analytics * - Data aggregation and roll-ups * - Custom metrics and dimensions * - Alerting and anomaly detection * * Designed for scalable analytics and business intelligence */ Object.defineProperty(exports, "__esModule", { value: true }); exports.analyticsMetricsTypes = exports.AlertStatus = exports.AlertActionType = exports.DistributionChannel = exports.ReportFormat = exports.ScheduleFrequency = exports.ParameterType = exports.SectionType = exports.ReportType = exports.FilterType = exports.InteractionType = exports.ComparisonOperator = exports.WidgetType = exports.LayoutType = exports.PeriodType = exports.KPIStatus = exports.TrendDirection = exports.TargetType = exports.DimensionType = exports.FilterOperator = exports.UnitType = exports.MetricCategory = exports.MetricType = exports.AggregationType = exports.TimeGranularity = exports.DataQuality = void 0; exports.calculateTimeSeriesStats = calculateTimeSeriesStats; exports.isKPIMeetingTarget = isKPIMeetingTarget; exports.aggregateMetricValues = aggregateMetricValues; /** * Data quality indicator */ var DataQuality; (function (DataQuality) { DataQuality["Good"] = "GOOD"; DataQuality["Estimated"] = "ESTIMATED"; DataQuality["Interpolated"] = "INTERPOLATED"; DataQuality["Missing"] = "MISSING"; DataQuality["Anomalous"] = "ANOMALOUS"; })(DataQuality || (exports.DataQuality = DataQuality = {})); /** * Time granularity levels */ var TimeGranularity; (function (TimeGranularity) { TimeGranularity["Second"] = "SECOND"; TimeGranularity["Minute"] = "MINUTE"; TimeGranularity["FiveMinutes"] = "FIVE_MINUTES"; TimeGranularity["FifteenMinutes"] = "FIFTEEN_MINUTES"; TimeGranularity["Hour"] = "HOUR"; TimeGranularity["Day"] = "DAY"; TimeGranularity["Week"] = "WEEK"; TimeGranularity["Month"] = "MONTH"; TimeGranularity["Quarter"] = "QUARTER"; TimeGranularity["Year"] = "YEAR"; })(TimeGranularity || (exports.TimeGranularity = TimeGranularity = {})); /** * Aggregation types */ var AggregationType; (function (AggregationType) { AggregationType["Sum"] = "SUM"; AggregationType["Average"] = "AVERAGE"; AggregationType["Minimum"] = "MINIMUM"; AggregationType["Maximum"] = "MAXIMUM"; AggregationType["Count"] = "COUNT"; AggregationType["CountDistinct"] = "COUNT_DISTINCT"; AggregationType["Median"] = "MEDIAN"; AggregationType["Percentile"] = "PERCENTILE"; AggregationType["StandardDeviation"] = "STANDARD_DEVIATION"; AggregationType["First"] = "FIRST"; AggregationType["Last"] = "LAST"; })(AggregationType || (exports.AggregationType = AggregationType = {})); /** * Metric types */ var MetricType; (function (MetricType) { MetricType["Counter"] = "COUNTER"; MetricType["Gauge"] = "GAUGE"; MetricType["Histogram"] = "HISTOGRAM"; MetricType["Summary"] = "SUMMARY"; MetricType["Rate"] = "RATE"; MetricType["Percentage"] = "PERCENTAGE"; MetricType["Currency"] = "CURRENCY"; MetricType["Duration"] = "DURATION"; // Time spans })(MetricType || (exports.MetricType = MetricType = {})); /** * Metric categories */ var MetricCategory; (function (MetricCategory) { MetricCategory["Business"] = "BUSINESS"; MetricCategory["Technical"] = "TECHNICAL"; MetricCategory["Financial"] = "FINANCIAL"; MetricCategory["Customer"] = "CUSTOMER"; MetricCategory["Operational"] = "OPERATIONAL"; MetricCategory["Marketing"] = "MARKETING"; MetricCategory["Sales"] = "SALES"; MetricCategory["Support"] = "SUPPORT"; MetricCategory["Custom"] = "CUSTOM"; })(MetricCategory || (exports.MetricCategory = MetricCategory = {})); /** * Unit types */ var UnitType; (function (UnitType) { UnitType["Count"] = "COUNT"; UnitType["Percentage"] = "PERCENTAGE"; UnitType["Currency"] = "CURRENCY"; UnitType["Bytes"] = "BYTES"; UnitType["Time"] = "TIME"; UnitType["Rate"] = "RATE"; UnitType["Custom"] = "CUSTOM"; })(UnitType || (exports.UnitType = UnitType = {})); /** * Filter operators */ var FilterOperator; (function (FilterOperator) { FilterOperator["Equals"] = "EQUALS"; FilterOperator["NotEquals"] = "NOT_EQUALS"; FilterOperator["GreaterThan"] = "GREATER_THAN"; FilterOperator["LessThan"] = "LESS_THAN"; FilterOperator["GreaterThanOrEqual"] = "GREATER_THAN_OR_EQUAL"; FilterOperator["LessThanOrEqual"] = "LESS_THAN_OR_EQUAL"; FilterOperator["Contains"] = "CONTAINS"; FilterOperator["NotContains"] = "NOT_CONTAINS"; FilterOperator["StartsWith"] = "STARTS_WITH"; FilterOperator["EndsWith"] = "ENDS_WITH"; FilterOperator["In"] = "IN"; FilterOperator["NotIn"] = "NOT_IN"; FilterOperator["Between"] = "BETWEEN"; FilterOperator["IsNull"] = "IS_NULL"; FilterOperator["IsNotNull"] = "IS_NOT_NULL"; })(FilterOperator || (exports.FilterOperator = FilterOperator = {})); /** * Dimension types */ var DimensionType; (function (DimensionType) { DimensionType["String"] = "STRING"; DimensionType["Number"] = "NUMBER"; DimensionType["Date"] = "DATE"; DimensionType["Boolean"] = "BOOLEAN"; DimensionType["Geography"] = "GEOGRAPHY"; DimensionType["Category"] = "CATEGORY"; DimensionType["Hierarchy"] = "HIERARCHY"; })(DimensionType || (exports.DimensionType = DimensionType = {})); /** * Target types */ var TargetType; (function (TargetType) { TargetType["Fixed"] = "FIXED"; TargetType["Percentage"] = "PERCENTAGE"; TargetType["Growth"] = "GROWTH"; TargetType["Reduction"] = "REDUCTION"; TargetType["Range"] = "RANGE"; })(TargetType || (exports.TargetType = TargetType = {})); /** * Trend directions */ var TrendDirection; (function (TrendDirection) { TrendDirection["Up"] = "UP"; TrendDirection["Down"] = "DOWN"; TrendDirection["Flat"] = "FLAT"; })(TrendDirection || (exports.TrendDirection = TrendDirection = {})); /** * KPI status */ var KPIStatus; (function (KPIStatus) { KPIStatus["OnTrack"] = "ON_TRACK"; KPIStatus["AtRisk"] = "AT_RISK"; KPIStatus["OffTrack"] = "OFF_TRACK"; KPIStatus["Exceeded"] = "EXCEEDED"; KPIStatus["NoData"] = "NO_DATA"; })(KPIStatus || (exports.KPIStatus = KPIStatus = {})); /** * Period types */ var PeriodType; (function (PeriodType) { PeriodType["Custom"] = "CUSTOM"; PeriodType["Today"] = "TODAY"; PeriodType["Yesterday"] = "YESTERDAY"; PeriodType["ThisWeek"] = "THIS_WEEK"; PeriodType["LastWeek"] = "LAST_WEEK"; PeriodType["ThisMonth"] = "THIS_MONTH"; PeriodType["LastMonth"] = "LAST_MONTH"; PeriodType["ThisQuarter"] = "THIS_QUARTER"; PeriodType["LastQuarter"] = "LAST_QUARTER"; PeriodType["ThisYear"] = "THIS_YEAR"; PeriodType["LastYear"] = "LAST_YEAR"; PeriodType["Last7Days"] = "LAST_7_DAYS"; PeriodType["Last30Days"] = "LAST_30_DAYS"; PeriodType["Last90Days"] = "LAST_90_DAYS"; })(PeriodType || (exports.PeriodType = PeriodType = {})); /** * Layout types */ var LayoutType; (function (LayoutType) { LayoutType["Grid"] = "GRID"; LayoutType["Flex"] = "FLEX"; LayoutType["Fixed"] = "FIXED"; LayoutType["Masonry"] = "MASONRY"; })(LayoutType || (exports.LayoutType = LayoutType = {})); /** * Widget types */ var WidgetType; (function (WidgetType) { // Charts WidgetType["LineChart"] = "LINE_CHART"; WidgetType["BarChart"] = "BAR_CHART"; WidgetType["PieChart"] = "PIE_CHART"; WidgetType["AreaChart"] = "AREA_CHART"; WidgetType["ScatterPlot"] = "SCATTER_PLOT"; WidgetType["Heatmap"] = "HEATMAP"; WidgetType["Gauge"] = "GAUGE"; // Numbers WidgetType["Metric"] = "METRIC"; WidgetType["KPICard"] = "KPI_CARD"; WidgetType["Sparkline"] = "SPARKLINE"; // Tables WidgetType["Table"] = "TABLE"; WidgetType["PivotTable"] = "PIVOT_TABLE"; // Maps WidgetType["GeoMap"] = "GEO_MAP"; WidgetType["HeatMap"] = "HEAT_MAP"; // Other WidgetType["Text"] = "TEXT"; WidgetType["Image"] = "IMAGE"; WidgetType["Filter"] = "FILTER"; })(WidgetType || (exports.WidgetType = WidgetType = {})); /** * Comparison operators */ var ComparisonOperator; (function (ComparisonOperator) { ComparisonOperator["GreaterThan"] = ">"; ComparisonOperator["LessThan"] = "<"; ComparisonOperator["GreaterThanOrEqual"] = ">="; ComparisonOperator["LessThanOrEqual"] = "<="; ComparisonOperator["Equal"] = "="; ComparisonOperator["NotEqual"] = "!="; })(ComparisonOperator || (exports.ComparisonOperator = ComparisonOperator = {})); /** * Interaction types */ var InteractionType; (function (InteractionType) { InteractionType["Click"] = "CLICK"; InteractionType["Hover"] = "HOVER"; InteractionType["Drill"] = "DRILL"; InteractionType["Filter"] = "FILTER"; InteractionType["Export"] = "EXPORT"; InteractionType["Share"] = "SHARE"; })(InteractionType || (exports.InteractionType = InteractionType = {})); /** * Filter types */ var FilterType; (function (FilterType) { FilterType["Dropdown"] = "DROPDOWN"; FilterType["MultiSelect"] = "MULTI_SELECT"; FilterType["DateRange"] = "DATE_RANGE"; FilterType["NumberRange"] = "NUMBER_RANGE"; FilterType["Search"] = "SEARCH"; FilterType["Toggle"] = "TOGGLE"; })(FilterType || (exports.FilterType = FilterType = {})); /** * Report types */ var ReportType; (function (ReportType) { ReportType["Executive"] = "EXECUTIVE"; ReportType["Operational"] = "OPERATIONAL"; ReportType["Financial"] = "FINANCIAL"; ReportType["Compliance"] = "COMPLIANCE"; ReportType["Performance"] = "PERFORMANCE"; ReportType["Custom"] = "CUSTOM"; })(ReportType || (exports.ReportType = ReportType = {})); /** * Section types */ var SectionType; (function (SectionType) { SectionType["Header"] = "HEADER"; SectionType["Summary"] = "SUMMARY"; SectionType["Chart"] = "CHART"; SectionType["Table"] = "TABLE"; SectionType["Text"] = "TEXT"; SectionType["PageBreak"] = "PAGE_BREAK"; SectionType["Footer"] = "FOOTER"; })(SectionType || (exports.SectionType = SectionType = {})); /** * Parameter types */ var ParameterType; (function (ParameterType) { ParameterType["String"] = "STRING"; ParameterType["Number"] = "NUMBER"; ParameterType["Date"] = "DATE"; ParameterType["DateRange"] = "DATE_RANGE"; ParameterType["Boolean"] = "BOOLEAN"; ParameterType["Select"] = "SELECT"; ParameterType["MultiSelect"] = "MULTI_SELECT"; })(ParameterType || (exports.ParameterType = ParameterType = {})); /** * Schedule frequencies */ var ScheduleFrequency; (function (ScheduleFrequency) { ScheduleFrequency["Once"] = "ONCE"; ScheduleFrequency["Hourly"] = "HOURLY"; ScheduleFrequency["Daily"] = "DAILY"; ScheduleFrequency["Weekly"] = "WEEKLY"; ScheduleFrequency["BiWeekly"] = "BI_WEEKLY"; ScheduleFrequency["Monthly"] = "MONTHLY"; ScheduleFrequency["Quarterly"] = "QUARTERLY"; ScheduleFrequency["Yearly"] = "YEARLY"; })(ScheduleFrequency || (exports.ScheduleFrequency = ScheduleFrequency = {})); /** * Report formats */ var ReportFormat; (function (ReportFormat) { ReportFormat["PDF"] = "PDF"; ReportFormat["Excel"] = "EXCEL"; ReportFormat["CSV"] = "CSV"; ReportFormat["PowerPoint"] = "POWERPOINT"; ReportFormat["HTML"] = "HTML"; ReportFormat["JSON"] = "JSON"; })(ReportFormat || (exports.ReportFormat = ReportFormat = {})); /** * Distribution channels */ var DistributionChannel; (function (DistributionChannel) { DistributionChannel["Email"] = "EMAIL"; DistributionChannel["Slack"] = "SLACK"; DistributionChannel["Teams"] = "TEAMS"; DistributionChannel["Webhook"] = "WEBHOOK"; DistributionChannel["FileShare"] = "FILE_SHARE"; DistributionChannel["API"] = "API"; })(DistributionChannel || (exports.DistributionChannel = DistributionChannel = {})); /** * Alert action types */ var AlertActionType; (function (AlertActionType) { AlertActionType["Email"] = "EMAIL"; AlertActionType["SMS"] = "SMS"; AlertActionType["Slack"] = "SLACK"; AlertActionType["Webhook"] = "WEBHOOK"; AlertActionType["PagerDuty"] = "PAGER_DUTY"; AlertActionType["Custom"] = "CUSTOM"; })(AlertActionType || (exports.AlertActionType = AlertActionType = {})); /** * Alert status */ var AlertStatus; (function (AlertStatus) { AlertStatus["Active"] = "ACTIVE"; AlertStatus["Triggered"] = "TRIGGERED"; AlertStatus["Resolved"] = "RESOLVED"; AlertStatus["Disabled"] = "DISABLED"; AlertStatus["Error"] = "ERROR"; })(AlertStatus || (exports.AlertStatus = AlertStatus = {})); // ============================================ // Validation Functions // ============================================ /** * Calculate time series statistics */ function calculateTimeSeriesStats(series) { if (series.length === 0) { return { count: 0, min: 0, max: 0, mean: 0, median: 0, stdDev: 0, sum: 0 }; } const values = series.map(p => p.value); const sum = values.reduce((a, b) => a + b, 0); const mean = sum / values.length; const sorted = [...values].sort((a, b) => a - b); const median = sorted.length % 2 === 0 ? ((sorted[sorted.length / 2 - 1] ?? 0) + (sorted[sorted.length / 2] ?? 0)) / 2 : sorted[Math.floor(sorted.length / 2)] ?? 0; const variance = values.reduce((acc, val) => acc + Math.pow(val - mean, 2), 0) / values.length; const stdDev = Math.sqrt(variance); return { count: values.length, min: Math.min(...values), max: Math.max(...values), mean, median, stdDev, sum }; } /** * Check if KPI is meeting target */ function isKPIMeetingTarget(kpi) { const { actual, target } = kpi; const tolerance = target.tolerance || 0; switch (target.type) { case TargetType.Fixed: return actual.value >= target.value * (1 - tolerance / 100); case TargetType.Percentage: return actual.value >= target.value; case TargetType.Growth: return actual.value >= target.value; case TargetType.Reduction: return actual.value <= target.value; case TargetType.Range: { // Assuming target.value is the midpoint const range = target.value * (tolerance / 100); return actual.value >= (target.value - range) && actual.value <= (target.value + range); } default: return false; } } /** * Calculate metric aggregation */ function aggregateMetricValues(values, type) { if (values.length === 0) return 0; switch (type) { case AggregationType.Sum: return values.reduce((a, b) => a + b, 0); case AggregationType.Average: return values.reduce((a, b) => a + b, 0) / values.length; case AggregationType.Minimum: return Math.min(...values); case AggregationType.Maximum: return Math.max(...values); case AggregationType.Count: return values.length; case AggregationType.First: return values[0] ?? 0; case AggregationType.Last: return values[values.length - 1] ?? 0; case AggregationType.Median: { const sorted = [...values].sort((a, b) => a - b); const mid = Math.floor(sorted.length / 2); return sorted.length % 2 === 0 ? ((sorted[mid - 1] ?? 0) + (sorted[mid] ?? 0)) / 2 : sorted[mid] ?? 0; } default: return 0; } } // ============================================ // Export Analytics/Metrics Types // ============================================ exports.analyticsMetricsTypes = { // Enums DataQuality, TimeGranularity, AggregationType, MetricType, MetricCategory, UnitType, FilterOperator, DimensionType, TargetType, TrendDirection, KPIStatus, PeriodType, LayoutType, WidgetType, ComparisonOperator, InteractionType, FilterType, ReportType, SectionType, ParameterType, ScheduleFrequency, ReportFormat, DistributionChannel, AlertActionType, AlertStatus, // Functions calculateTimeSeriesStats, isKPIMeetingTarget, aggregateMetricValues }; //# sourceMappingURL=analytics-metrics-types.js.map