@servlyadmin/runtime-core 0.1.2 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -449,14 +449,19 @@ declare function resolveBindingPath(path: string, context: BindingContext): any;
449
449
  *
450
450
  * @param template - The template string containing {{path}} bindings
451
451
  * @param context - The binding context
452
+ * @param componentId - Optional component ID for error tracking
452
453
  * @returns The resolved string
453
454
  */
454
- declare function resolveTemplate(template: string, context: BindingContext): string;
455
+ declare function resolveTemplate(template: string, context: BindingContext, componentId?: string): string;
455
456
  /**
456
457
  * Resolve a template and return the raw value (not stringified)
457
458
  * Useful for non-string values like objects, arrays, booleans
459
+ *
460
+ * @param template - The template string
461
+ * @param context - The binding context
462
+ * @param componentId - Optional component ID for error tracking
458
463
  */
459
- declare function resolveTemplateValue(template: string, context: BindingContext): any;
464
+ declare function resolveTemplateValue(template: string, context: BindingContext, componentId?: string): any;
460
465
  /**
461
466
  * Recursively resolve all template bindings in an object or array
462
467
  *
@@ -772,4 +777,428 @@ declare function collectAllDependencies(rootId: string, rootVersion: string, fet
772
777
  */
773
778
  declare function detectCircularDependencies(manifest: DependencyManifest): string[] | null;
774
779
 
775
- export { type Assertion$1 as Assertion, type AssertionResult$1 as AssertionResult, type BindingContext, type BundleStrategy, type BundledComponent, type CacheConfig, type CacheEntry, type CacheStrategy, type ComponentBundle, type ComponentData, type ComponentRegistry, DEFAULT_CACHE_CONFIG, DEFAULT_RETRY_CONFIG, type DependencyEntry, type DependencyManifest, type DependencyType, type ElementConfig, type FetchOptions, type FetchResult, type LayoutElement, type ParsedVersion, type PropDefinition, type RenderOptions, type RenderResult, type RetryConfig, type AssertionResult as TestAssertionResult, type TestCase$1 as TestCase, type TestCase as TestCaseInput, type TestCaseResult, type TestResult, type TestSummary as TestRunSummary, type TestSummary$1 as TestSummary, applyStyles, batchFetchComponents, buildClassName, buildElementStyles, buildRegistryFromBundle, bumpVersion, camelToKebab, clearAllCaches, clearLocalStorageCache, clearMemoryCache, clearStyles, collectAllDependencies, compareVersions, createRegistry, detectCircularDependencies, extractBindingKeys, extractDependencies, extractDependenciesFromCode, fetchComponent, fetchComponentWithDependencies, formatStyleValue, formatVersion, generateTestCases, getCacheKey, getDependencyTree, getFromCache, getMemoryCacheSize, getRegistryUrl, hasTemplateSyntax, invalidateCache, isComponentAvailable, isValidSpecifier, parseVersion, prefetchComponents, processStyles, render, renderDynamicList, resolveBindingPath, resolveTemplate, resolveTemplateValue, resolveTemplatesDeep, resolveVersion, runAllTests, runTestCase, satisfiesVersion, setInCache, setRegistryUrl, updateStyles, validateAssertion, validateProps };
780
+ /**
781
+ * Component Analytics Types
782
+ * Type definitions for analytics event collection and transmission
783
+ */
784
+ /**
785
+ * Analytics configuration options
786
+ */
787
+ interface AnalyticsConfig {
788
+ /** Enable/disable analytics collection */
789
+ enabled: boolean;
790
+ /** Analytics API endpoint */
791
+ endpoint: string;
792
+ /** API key for authentication */
793
+ apiKey?: string;
794
+ /** Application ID to include in all events */
795
+ appId?: string;
796
+ /** Batch size before auto-flush */
797
+ batchSize: number;
798
+ /** Flush interval in milliseconds */
799
+ flushInterval: number;
800
+ /** Sample rate (0-1) for high-volume events */
801
+ sampleRate: number;
802
+ /** Environment identifier */
803
+ environment: 'development' | 'staging' | 'production';
804
+ /** Enable debug logging */
805
+ debug: boolean;
806
+ }
807
+ /**
808
+ * Analytics event types
809
+ */
810
+ type AnalyticsEventType = 'render' | 'fetch' | 'error';
811
+ /**
812
+ * Base analytics event
813
+ */
814
+ interface AnalyticsEvent {
815
+ /** Event type */
816
+ type: AnalyticsEventType;
817
+ /** Component identifier */
818
+ componentId: string;
819
+ /** Component version */
820
+ version: string;
821
+ /** Unix timestamp in milliseconds */
822
+ timestamp: number;
823
+ /** Anonymous session ID */
824
+ sessionId?: string;
825
+ /** Application ID */
826
+ appId?: string;
827
+ /** Duration in milliseconds */
828
+ duration?: number;
829
+ /** Event-specific metadata */
830
+ metadata?: Record<string, unknown>;
831
+ }
832
+ /**
833
+ * Metadata for render events
834
+ */
835
+ interface RenderMetadata {
836
+ /** Number of DOM elements rendered */
837
+ elementCount?: number;
838
+ /** Whether component was served from cache */
839
+ fromCache?: boolean;
840
+ /** Memory heap change in KB (Chrome only) */
841
+ heapDeltaKB?: number;
842
+ /** Number of DOM nodes created */
843
+ domNodesCreated?: number;
844
+ /** Number of long tasks (>50ms) during render */
845
+ longTaskCount?: number;
846
+ /** Whether component has event handlers */
847
+ hasEventHandlers?: boolean;
848
+ /** Whether component has dependencies */
849
+ hasDependencies?: boolean;
850
+ }
851
+ /**
852
+ * Metadata for fetch events
853
+ */
854
+ interface FetchMetadata {
855
+ /** Whether fetch was a cache hit */
856
+ cacheHit: boolean;
857
+ /** Fetch duration in milliseconds */
858
+ fetchDuration: number;
859
+ /** Bundle size in bytes */
860
+ bundleSize?: number;
861
+ /** Number of dependencies */
862
+ dependencyCount?: number;
863
+ }
864
+ /**
865
+ * Error types for error events
866
+ */
867
+ type ErrorType = 'render' | 'fetch' | 'binding';
868
+ /**
869
+ * Metadata for error events
870
+ */
871
+ interface ErrorMetadata {
872
+ /** Type of error */
873
+ errorType: ErrorType;
874
+ /** Error message (max 1000 chars) */
875
+ errorMessage: string;
876
+ /** Stack trace (truncated to 500 chars) */
877
+ stackTrace?: string;
878
+ /** Failed binding path (for binding errors) */
879
+ bindingPath?: string;
880
+ /** Element ID where error occurred */
881
+ elementId?: string;
882
+ }
883
+ /**
884
+ * Client info included in batch requests
885
+ */
886
+ interface ClientInfo {
887
+ /** SDK version */
888
+ sdkVersion: string;
889
+ /** Environment */
890
+ environment: string;
891
+ }
892
+ /**
893
+ * Batch events request body
894
+ */
895
+ interface BatchEventsRequest {
896
+ /** Array of analytics events */
897
+ events: AnalyticsEvent[];
898
+ /** Client information */
899
+ clientInfo: ClientInfo;
900
+ }
901
+ /**
902
+ * Batch events response
903
+ */
904
+ interface BatchEventsResponse {
905
+ /** Whether request was successful */
906
+ success: boolean;
907
+ /** Number of events accepted */
908
+ accepted: number;
909
+ /** Number of events rejected */
910
+ rejected: number;
911
+ /** Error messages for rejected events */
912
+ errors?: string[];
913
+ /** Retry-After header value (for rate limiting) */
914
+ retryAfter?: number;
915
+ }
916
+ /**
917
+ * Session information
918
+ */
919
+ interface SessionInfo {
920
+ /** Session ID */
921
+ id: string;
922
+ /** Timestamp when session was created */
923
+ createdAt: number;
924
+ /** Timestamp of last activity */
925
+ lastActivityAt: number;
926
+ }
927
+
928
+ /**
929
+ * Component Analytics
930
+ * Collects and transmits component usage, performance, and error metrics
931
+ */
932
+
933
+ /**
934
+ * Analytics Collector class
935
+ * Manages event collection, batching, and transmission
936
+ */
937
+ declare class AnalyticsCollector {
938
+ private config;
939
+ private eventQueue;
940
+ private flushTimer;
941
+ private isEnabled;
942
+ private isFlushing;
943
+ private retryDelay;
944
+ constructor(config?: Partial<AnalyticsConfig>);
945
+ /**
946
+ * Configure analytics
947
+ */
948
+ configure(config: Partial<AnalyticsConfig>): void;
949
+ /**
950
+ * Disable analytics collection
951
+ */
952
+ disable(): void;
953
+ /**
954
+ * Enable analytics collection
955
+ */
956
+ enable(): void;
957
+ /**
958
+ * Destroy and cleanup
959
+ */
960
+ destroy(): void;
961
+ /**
962
+ * Track component render
963
+ */
964
+ trackRender(componentId: string, version: string, duration: number, metadata?: RenderMetadata): void;
965
+ /**
966
+ * Track component fetch
967
+ */
968
+ trackFetch(componentId: string, version: string, duration: number, fromCache: boolean, metadata?: Partial<FetchMetadata>): void;
969
+ /**
970
+ * Track error
971
+ */
972
+ trackError(componentId: string, version: string, error: Error, context?: Partial<ErrorMetadata>): void;
973
+ /**
974
+ * Check if event should be tracked (sampling + enabled)
975
+ */
976
+ private shouldTrack;
977
+ /**
978
+ * Add event to queue
979
+ */
980
+ private queueEvent;
981
+ /**
982
+ * Get current queue size
983
+ */
984
+ getQueueSize(): number;
985
+ /**
986
+ * Start the flush timer
987
+ */
988
+ private startFlushTimer;
989
+ /**
990
+ * Stop the flush timer
991
+ */
992
+ private stopFlushTimer;
993
+ /**
994
+ * Flush events to server
995
+ */
996
+ flush(): Promise<void>;
997
+ /**
998
+ * Perform the actual flush
999
+ */
1000
+ private doFlush;
1001
+ /**
1002
+ * Send events to the API
1003
+ */
1004
+ private sendEvents;
1005
+ /**
1006
+ * Handle failed events (partial success)
1007
+ */
1008
+ private handleFailedEvents;
1009
+ /**
1010
+ * Handle network error
1011
+ */
1012
+ private handleNetworkError;
1013
+ /**
1014
+ * Schedule a retry flush
1015
+ */
1016
+ private scheduleRetry;
1017
+ /**
1018
+ * Truncate string to max length
1019
+ */
1020
+ private truncateString;
1021
+ /**
1022
+ * Log debug message
1023
+ */
1024
+ private log;
1025
+ }
1026
+ /**
1027
+ * Get the analytics collector singleton
1028
+ */
1029
+ declare function getAnalytics(): AnalyticsCollector;
1030
+ /**
1031
+ * Configure analytics (convenience function)
1032
+ */
1033
+ declare function configureAnalytics(config: Partial<AnalyticsConfig>): void;
1034
+ /**
1035
+ * Reset analytics (for testing)
1036
+ */
1037
+ declare function resetAnalytics(): void;
1038
+ declare const analytics: {
1039
+ readonly instance: AnalyticsCollector;
1040
+ configure: typeof configureAnalytics;
1041
+ trackRender: (componentId: string, version: string, duration: number, metadata?: RenderMetadata) => void;
1042
+ trackFetch: (componentId: string, version: string, duration: number, fromCache: boolean, metadata?: Partial<FetchMetadata>) => void;
1043
+ trackError: (componentId: string, version: string, error: Error, context?: Partial<ErrorMetadata>) => void;
1044
+ flush: () => Promise<void>;
1045
+ disable: () => void;
1046
+ enable: () => void;
1047
+ };
1048
+
1049
+ /**
1050
+ * Session Manager
1051
+ * Manages anonymous session IDs for analytics tracking
1052
+ */
1053
+
1054
+ /**
1055
+ * Session Manager class
1056
+ * Manages anonymous session IDs with automatic rotation
1057
+ */
1058
+ declare class SessionManager {
1059
+ private session;
1060
+ constructor();
1061
+ /**
1062
+ * Initialize session manager
1063
+ */
1064
+ private initialize;
1065
+ /**
1066
+ * Create a new session
1067
+ */
1068
+ private createNewSession;
1069
+ /**
1070
+ * Get current session ID
1071
+ * Creates new session if expired
1072
+ */
1073
+ getSessionId(): string;
1074
+ /**
1075
+ * Update last activity timestamp
1076
+ */
1077
+ touch(): void;
1078
+ /**
1079
+ * Force create a new session
1080
+ */
1081
+ rotate(): void;
1082
+ /**
1083
+ * Clear current session
1084
+ */
1085
+ clear(): void;
1086
+ /**
1087
+ * Get session info (for debugging)
1088
+ */
1089
+ getSessionInfo(): SessionInfo | null;
1090
+ }
1091
+ /**
1092
+ * Get the session manager singleton
1093
+ */
1094
+ declare function getSessionManager(): SessionManager;
1095
+ /**
1096
+ * Reset the session manager (for testing)
1097
+ */
1098
+ declare function resetSessionManager(): void;
1099
+
1100
+ /**
1101
+ * Memory Sampler
1102
+ * Samples memory usage using Chrome's performance.memory API
1103
+ * Gracefully degrades on unsupported browsers
1104
+ */
1105
+ /**
1106
+ * Memory sample data
1107
+ */
1108
+ interface MemorySample {
1109
+ /** Used JS heap size in KB */
1110
+ heapUsedKB: number;
1111
+ /** Total JS heap size in KB */
1112
+ heapTotalKB: number;
1113
+ /** Timestamp when sample was taken */
1114
+ timestamp: number;
1115
+ }
1116
+ /**
1117
+ * Memory Sampler class
1118
+ * Provides memory sampling functionality for Chrome browsers
1119
+ */
1120
+ declare class MemorySampler {
1121
+ private isSupported;
1122
+ constructor();
1123
+ /**
1124
+ * Check if memory API is available
1125
+ */
1126
+ private checkSupport;
1127
+ /**
1128
+ * Check if memory sampling is available
1129
+ */
1130
+ isAvailable(): boolean;
1131
+ /**
1132
+ * Take a memory sample
1133
+ * Returns null if memory API is not available
1134
+ */
1135
+ sample(): MemorySample | null;
1136
+ /**
1137
+ * Calculate heap delta between two samples
1138
+ * Returns the difference in KB (positive = memory increased)
1139
+ */
1140
+ calculateDelta(before: MemorySample | null, after: MemorySample | null): number | null;
1141
+ }
1142
+ /**
1143
+ * Get the memory sampler singleton
1144
+ */
1145
+ declare function getMemorySampler(): MemorySampler;
1146
+ /**
1147
+ * Reset the memory sampler (for testing)
1148
+ */
1149
+ declare function resetMemorySampler(): void;
1150
+
1151
+ /**
1152
+ * Long Task Observer
1153
+ * Observes long tasks (>50ms) using PerformanceObserver API
1154
+ * Gracefully degrades on unsupported browsers
1155
+ */
1156
+ /**
1157
+ * Long Task Observer class
1158
+ * Counts tasks that take longer than 50ms during a measurement period
1159
+ */
1160
+ declare class LongTaskObserver {
1161
+ private observer;
1162
+ private longTaskCount;
1163
+ private isSupported;
1164
+ private isObserving;
1165
+ constructor();
1166
+ /**
1167
+ * Check if PerformanceObserver with longtask support is available
1168
+ */
1169
+ private checkSupport;
1170
+ /**
1171
+ * Check if long task observation is available
1172
+ */
1173
+ isAvailable(): boolean;
1174
+ /**
1175
+ * Start observing long tasks
1176
+ */
1177
+ start(): void;
1178
+ /**
1179
+ * Stop observing and return the count of long tasks
1180
+ */
1181
+ stop(): number;
1182
+ /**
1183
+ * Reset the long task counter
1184
+ */
1185
+ reset(): void;
1186
+ /**
1187
+ * Get current count without stopping observation
1188
+ */
1189
+ getCount(): number;
1190
+ /**
1191
+ * Check if currently observing
1192
+ */
1193
+ isActive(): boolean;
1194
+ }
1195
+ /**
1196
+ * Get the long task observer singleton
1197
+ */
1198
+ declare function getLongTaskObserver(): LongTaskObserver;
1199
+ /**
1200
+ * Reset the long task observer (for testing)
1201
+ */
1202
+ declare function resetLongTaskObserver(): void;
1203
+
1204
+ export { AnalyticsCollector, type AnalyticsConfig, type AnalyticsEvent, type AnalyticsEventType, type Assertion$1 as Assertion, type AssertionResult$1 as AssertionResult, type BatchEventsRequest, type BatchEventsResponse, type BindingContext, type BundleStrategy, type BundledComponent, type CacheConfig, type CacheEntry, type CacheStrategy, type ClientInfo, type ComponentBundle, type ComponentData, type ComponentRegistry, DEFAULT_CACHE_CONFIG, DEFAULT_RETRY_CONFIG, type DependencyEntry, type DependencyManifest, type DependencyType, type ElementConfig, type ErrorMetadata, type ErrorType, type FetchMetadata, type FetchOptions, type FetchResult, type LayoutElement, LongTaskObserver, MemorySampler, type ParsedVersion, type PropDefinition, type RenderMetadata, type RenderOptions, type RenderResult, type RetryConfig, type SessionInfo, SessionManager, type AssertionResult as TestAssertionResult, type TestCase$1 as TestCase, type TestCase as TestCaseInput, type TestCaseResult, type TestResult, type TestSummary as TestRunSummary, type TestSummary$1 as TestSummary, analytics, applyStyles, batchFetchComponents, buildClassName, buildElementStyles, buildRegistryFromBundle, bumpVersion, camelToKebab, clearAllCaches, clearLocalStorageCache, clearMemoryCache, clearStyles, collectAllDependencies, compareVersions, configureAnalytics, createRegistry, detectCircularDependencies, extractBindingKeys, extractDependencies, extractDependenciesFromCode, fetchComponent, fetchComponentWithDependencies, formatStyleValue, formatVersion, generateTestCases, getAnalytics, getCacheKey, getDependencyTree, getFromCache, getLongTaskObserver, getMemoryCacheSize, getMemorySampler, getRegistryUrl, getSessionManager, hasTemplateSyntax, invalidateCache, isComponentAvailable, isValidSpecifier, parseVersion, prefetchComponents, processStyles, render, renderDynamicList, resetAnalytics, resetLongTaskObserver, resetMemorySampler, resetSessionManager, resolveBindingPath, resolveTemplate, resolveTemplateValue, resolveTemplatesDeep, resolveVersion, runAllTests, runTestCase, satisfiesVersion, setInCache, setRegistryUrl, updateStyles, validateAssertion, validateProps };