@bikdotai/bik-shared-backend 20.3.2-beta.2 → 20.3.2-beta.3

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.
@@ -5,6 +5,11 @@ import { IndexMetadata, BackingIndexInfo, QueryDateRangeInfo } from './indexFilt
5
5
  * Provides static methods for date extraction, metadata fetching, and overlap detection
6
6
  */
7
7
  export declare class IndexFilteringHelper {
8
+ /**
9
+ * Known date fields that are valid for min/max aggregations.
10
+ * Stored as a Set for O(1) lookup; defined once to avoid per-call allocation.
11
+ */
12
+ private static readonly DATE_FIELDS;
8
13
  /**
9
14
  * Extract date range information from an Elasticsearch query
10
15
  * Supports both direct query objects and full search request bodies
@@ -81,12 +81,16 @@ class IndexFilteringHelper {
81
81
  if (rangeFilters.length === 0) {
82
82
  return { hasDateRange: false };
83
83
  }
84
- // Find first date-related range filter
85
- // Priority: createdAt, timestamp, then any other field
86
- const dateFieldPriority = ['createdAt', 'timestamp'];
87
- let selectedFilter = rangeFilters.find((f) => dateFieldPriority.includes(f.field));
84
+ // Find first date-related range filter.
85
+ // Priority: known date fields first, then any non-keyword field as fallback.
86
+ // Keyword fields are excluded — they are not supported by min/max aggregations.
87
+ let selectedFilter = rangeFilters.find((f) => IndexFilteringHelper.DATE_FIELDS.has(f.field));
88
88
  if (!selectedFilter) {
89
- selectedFilter = rangeFilters[0]; // fallback to first range
89
+ // Fallback: pick first non-keyword range field
90
+ selectedFilter = rangeFilters.find((f) => !f.field.endsWith('.keyword'));
91
+ }
92
+ if (!selectedFilter) {
93
+ return { hasDateRange: false };
90
94
  }
91
95
  const range = selectedFilter.range;
92
96
  const startQueryDate = range.gte !== undefined ? range.gte : range.gt;
@@ -483,3 +487,13 @@ class IndexFilteringHelper {
483
487
  }
484
488
  }
485
489
  exports.IndexFilteringHelper = IndexFilteringHelper;
490
+ /**
491
+ * Known date fields that are valid for min/max aggregations.
492
+ * Stored as a Set for O(1) lookup; defined once to avoid per-call allocation.
493
+ */
494
+ IndexFilteringHelper.DATE_FIELDS = new Set([
495
+ 'createdAt',
496
+ 'eventProperties.taskCreatedAt',
497
+ 'eventProperties.triggeredDate',
498
+ 'timestamp',
499
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-shared-backend",
3
- "version": "20.3.2-beta.2",
3
+ "version": "20.3.2-beta.3",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@amplitude/identify": "^1.10.0",
37
37
  "@amplitude/node": "^1.10.0",
38
- "@bikdotai/bik-models": "11.6.2-beta.1",
38
+ "@bikdotai/bik-models": "11.6.2-beta.2",
39
39
  "@elastic/elasticsearch": "^8.7.0",
40
40
  "@fastify/cookie": "^9.4.0",
41
41
  "@fastify/cors": "^9.0.1",