@widgetic/embed-sdk 0.0.0-stage → 2.0.6
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/README.md +567 -2
- package/dist/browser/chunks/ABTestManager.js +1 -0
- package/dist/browser/chunks/advanced.js +1 -0
- package/dist/browser/chunks/api.js +1 -0
- package/dist/browser/chunks/core.js +1 -0
- package/dist/browser/chunks/display.js +1 -0
- package/dist/browser/chunks/media.js +1 -0
- package/dist/browser/chunks/messaging.js +1 -0
- package/dist/browser/chunks/performance.js +1 -0
- package/dist/browser/chunks/renderers.js +1 -0
- package/dist/browser/chunks/scanner.js +1 -0
- package/dist/browser/chunks/security.js +1 -0
- package/dist/browser/chunks/vendor.js +1 -0
- package/dist/browser/embed-bootstrap.js +1 -0
- package/dist/browser/embed-sdk.js +1 -0
- package/dist/esm/chunks/ABTestManager.js +1 -0
- package/dist/esm/chunks/advanced.js +1 -0
- package/dist/esm/chunks/api.js +1 -0
- package/dist/esm/chunks/core.js +1 -0
- package/dist/esm/chunks/display.js +1 -0
- package/dist/esm/chunks/media.js +1 -0
- package/dist/esm/chunks/messaging.js +1 -0
- package/dist/esm/chunks/performance.js +1 -0
- package/dist/esm/chunks/renderers.js +1 -0
- package/dist/esm/chunks/scanner.js +1 -0
- package/dist/esm/chunks/security.js +1 -0
- package/dist/esm/chunks/vendor.js +1 -0
- package/dist/esm/embed-bootstrap.js +1 -0
- package/dist/esm/embed-sdk.js +1 -0
- package/dist/esm/types/abTesting/ABTestElement.d.ts +120 -0
- package/dist/esm/types/abTesting/ABTestManager.d.ts +177 -0
- package/dist/esm/types/api/batch-client.d.ts +163 -0
- package/dist/esm/types/api/layers.d.ts +119 -0
- package/dist/esm/types/core/advanced-security-manager.d.ts +330 -0
- package/dist/esm/types/core/analytics-tracker.d.ts +224 -0
- package/dist/esm/types/core/auth-detector.d.ts +65 -0
- package/dist/esm/types/core/auth-manager.d.ts +90 -0
- package/dist/esm/types/core/autoscale-manager.d.ts +91 -0
- package/dist/esm/types/core/breakpoints.d.ts +48 -0
- package/dist/esm/types/core/config.d.ts +152 -0
- package/dist/esm/types/core/constants.d.ts +75 -0
- package/dist/esm/types/core/content-position-manager.d.ts +228 -0
- package/dist/esm/types/core/custom-element.d.ts +152 -0
- package/dist/esm/types/core/display-manager.d.ts +109 -0
- package/dist/esm/types/core/editor-overlay.d.ts +113 -0
- package/dist/esm/types/core/embed-sdk.d.ts +310 -0
- package/dist/esm/types/core/exit-intent-trigger.d.ts +114 -0
- package/dist/esm/types/core/lazy-loader.d.ts +111 -0
- package/dist/esm/types/core/media-manager.d.ts +364 -0
- package/dist/esm/types/core/messaging.d.ts +251 -0
- package/dist/esm/types/core/overlay-manager.d.ts +119 -0
- package/dist/esm/types/core/performance-monitor.d.ts +152 -0
- package/dist/esm/types/core/privacy-compliance.d.ts +236 -0
- package/dist/esm/types/core/realtime-manager.d.ts +279 -0
- package/dist/esm/types/core/resize-handler.d.ts +81 -0
- package/dist/esm/types/core/resource-optimizer.d.ts +133 -0
- package/dist/esm/types/core/responsive-manager.d.ts +49 -0
- package/dist/esm/types/core/scroll-trigger.d.ts +105 -0
- package/dist/esm/types/core/security-manager.d.ts +150 -0
- package/dist/esm/types/core/text-field-manager.d.ts +204 -0
- package/dist/esm/types/core/token-provider.d.ts +75 -0
- package/dist/esm/types/core/trigger-defaults.d.ts +36 -0
- package/dist/esm/types/core/trigger-manager.d.ts +248 -0
- package/dist/esm/types/core/types.d.ts +473 -0
- package/dist/esm/types/core/ui-sdk-loader.d.ts +90 -0
- package/dist/esm/types/core/widget-manager.d.ts +285 -0
- package/dist/esm/types/core/widget-metadata.d.ts +107 -0
- package/dist/esm/types/embed-sdk.d.ts +31 -0
- package/dist/esm/types/loaders/module-loader.d.ts +147 -0
- package/dist/esm/types/renderers/custom-element-renderer.d.ts +78 -0
- package/dist/esm/types/renderers/iframe-renderer.d.ts +185 -0
- package/dist/esm/types/renderers/widget-renderer.d.ts +173 -0
- package/dist/esm/types/sdk/embed-bootstrap.d.ts +84 -0
- package/dist/esm/types/sdk/embed-sdk.d.ts +31 -0
- package/dist/esm/types/translations/TranslationElement.d.ts +93 -0
- package/dist/esm/types/utils/browser.d.ts +29 -0
- package/dist/esm/types/utils/caseConversion.d.ts +2 -0
- package/dist/esm/types/utils/css-debug.d.ts +105 -0
- package/dist/esm/types/utils/device-detector.d.ts +100 -0
- package/dist/esm/types/utils/event-emitter.d.ts +14 -0
- package/dist/esm/types/utils/hydrate-published-host.d.ts +17 -0
- package/dist/esm/types/utils/logger.d.ts +31 -0
- package/dist/esm/types/utils/parser.d.ts +39 -0
- package/dist/esm/types/utils/portal.d.ts +74 -0
- package/dist/esm/types/utils/public-embed-lookup.d.ts +68 -0
- package/dist/esm/types/utils/published-host-display.d.ts +61 -0
- package/dist/umd/embed-bootstrap.js +1 -0
- package/dist/umd/embed-sdk.js +1 -0
- package/package.json +154 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource Optimizer - Advanced resource loading and optimization
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Intelligent resource preloading and prefetching
|
|
6
|
+
* - Service Worker integration for caching
|
|
7
|
+
* - Bundle size optimization and code splitting
|
|
8
|
+
* - Critical resource prioritization
|
|
9
|
+
* - Network-aware loading strategies
|
|
10
|
+
* - Resource hint generation
|
|
11
|
+
*/
|
|
12
|
+
export interface ResourceConfig {
|
|
13
|
+
enablePreloading: boolean;
|
|
14
|
+
enablePrefetching: boolean;
|
|
15
|
+
enableServiceWorker: boolean;
|
|
16
|
+
enableBundleSplitting: boolean;
|
|
17
|
+
enableCriticalResourceOptimization: boolean;
|
|
18
|
+
enableNetworkAwareLoading: boolean;
|
|
19
|
+
preloadThreshold: number;
|
|
20
|
+
prefetchDelay: number;
|
|
21
|
+
maxConcurrentRequests: number;
|
|
22
|
+
cacheDuration: number;
|
|
23
|
+
priorityLevels: ResourcePriority[];
|
|
24
|
+
}
|
|
25
|
+
export interface ResourcePriority {
|
|
26
|
+
pattern: string;
|
|
27
|
+
priority: 'critical' | 'high' | 'medium' | 'low';
|
|
28
|
+
preload: boolean;
|
|
29
|
+
prefetch: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ResourceInfo {
|
|
32
|
+
url: string;
|
|
33
|
+
type: ResourceType;
|
|
34
|
+
priority: 'critical' | 'high' | 'medium' | 'low';
|
|
35
|
+
size?: number;
|
|
36
|
+
isLoaded: boolean;
|
|
37
|
+
isPreloaded: boolean;
|
|
38
|
+
isPrefetched: boolean;
|
|
39
|
+
loadTime?: number;
|
|
40
|
+
cached: boolean;
|
|
41
|
+
compositionId?: string;
|
|
42
|
+
}
|
|
43
|
+
export type ResourceType = 'script' | 'style' | 'image' | 'font' | 'fetch' | 'document';
|
|
44
|
+
export interface NetworkInfo {
|
|
45
|
+
effectiveType: string;
|
|
46
|
+
downlink: number;
|
|
47
|
+
rtt: number;
|
|
48
|
+
saveData: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare class ResourceOptimizer {
|
|
51
|
+
private config;
|
|
52
|
+
private resources;
|
|
53
|
+
private loadQueue;
|
|
54
|
+
private activeRequests;
|
|
55
|
+
private performanceMonitor;
|
|
56
|
+
private serviceWorker?;
|
|
57
|
+
private networkInfo?;
|
|
58
|
+
constructor(config?: Partial<ResourceConfig>);
|
|
59
|
+
private init;
|
|
60
|
+
private detectNetworkInfo;
|
|
61
|
+
private initServiceWorker;
|
|
62
|
+
private setupResourceObserver;
|
|
63
|
+
private trackResourceLoad;
|
|
64
|
+
private addGlobalResourceHints;
|
|
65
|
+
private addResourceHint;
|
|
66
|
+
/**
|
|
67
|
+
* Register a resource for optimization
|
|
68
|
+
*/
|
|
69
|
+
registerResource(url: string, type: ResourceType, options?: {
|
|
70
|
+
compositionId?: string;
|
|
71
|
+
priority?: 'critical' | 'high' | 'medium' | 'low';
|
|
72
|
+
preload?: boolean;
|
|
73
|
+
prefetch?: boolean;
|
|
74
|
+
}): ResourceInfo;
|
|
75
|
+
private determineResourcePriority;
|
|
76
|
+
private matchesPattern;
|
|
77
|
+
private shouldPreload;
|
|
78
|
+
private shouldPrefetch;
|
|
79
|
+
/**
|
|
80
|
+
* Preload a resource immediately
|
|
81
|
+
*/
|
|
82
|
+
preloadResource(resource: ResourceInfo): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Prefetch a resource for future use
|
|
85
|
+
*/
|
|
86
|
+
prefetchResource(resource: ResourceInfo): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Load multiple resources with priority and concurrency control
|
|
89
|
+
*/
|
|
90
|
+
loadResources(urls: string[], options?: {
|
|
91
|
+
type?: ResourceType;
|
|
92
|
+
priority?: 'critical' | 'high' | 'medium' | 'low';
|
|
93
|
+
compositionId?: string;
|
|
94
|
+
}): Promise<ResourceInfo[]>;
|
|
95
|
+
private loadResource;
|
|
96
|
+
/**
|
|
97
|
+
* Optimize bundle loading with code splitting
|
|
98
|
+
*/
|
|
99
|
+
loadBundleWithSplitting(entryPoint: string, compositionId: string): Promise<void>;
|
|
100
|
+
private loadBundle;
|
|
101
|
+
/**
|
|
102
|
+
* Generate critical resource hints for the page
|
|
103
|
+
*/
|
|
104
|
+
generateCriticalResourceHints(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Get resource optimization metrics
|
|
107
|
+
*/
|
|
108
|
+
getMetrics(): any;
|
|
109
|
+
/**
|
|
110
|
+
* Clear resource cache and reset state
|
|
111
|
+
*/
|
|
112
|
+
clearCache(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Update configuration
|
|
115
|
+
*/
|
|
116
|
+
updateConfig(config: Partial<ResourceConfig>): void;
|
|
117
|
+
/**
|
|
118
|
+
* Get resource by URL
|
|
119
|
+
*/
|
|
120
|
+
getResource(url: string): ResourceInfo | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Get all resources for a composition
|
|
123
|
+
*/
|
|
124
|
+
getResourcesByComposition(compositionId: string): ResourceInfo[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get or create global resource optimizer
|
|
128
|
+
*/
|
|
129
|
+
export declare function getResourceOptimizer(config?: Partial<ResourceConfig>): ResourceOptimizer;
|
|
130
|
+
/**
|
|
131
|
+
* Initialize resource optimization with configuration
|
|
132
|
+
*/
|
|
133
|
+
export declare function initializeResourceOptimization(config?: Partial<ResourceConfig>): ResourceOptimizer;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ResponsiveState, ResponsiveConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Event callback for responsive state changes
|
|
4
|
+
*/
|
|
5
|
+
export type ResponsiveCallback = (state: ResponsiveState) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Manages responsive breakpoint monitoring for widgets
|
|
8
|
+
* Detects when container size crosses breakpoints and triggers mobile/desktop UI changes
|
|
9
|
+
*/
|
|
10
|
+
export declare class ResponsiveManager {
|
|
11
|
+
private observers;
|
|
12
|
+
private callbacks;
|
|
13
|
+
private currentStates;
|
|
14
|
+
private debounceTimers;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Register a widget for responsive breakpoint monitoring
|
|
18
|
+
*/
|
|
19
|
+
registerWidget(widgetId: string, container: HTMLElement, config: ResponsiveConfig, callback: ResponsiveCallback): void;
|
|
20
|
+
/**
|
|
21
|
+
* Unregister a widget from responsive monitoring
|
|
22
|
+
*/
|
|
23
|
+
unregisterWidget(widgetId: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get current responsive state for a widget
|
|
26
|
+
*/
|
|
27
|
+
getCurrentState(widgetId: string): ResponsiveState | null;
|
|
28
|
+
/**
|
|
29
|
+
* Manually trigger responsive state check (useful for testing)
|
|
30
|
+
*/
|
|
31
|
+
checkResponsiveState(widgetId: string, width: number): void;
|
|
32
|
+
/**
|
|
33
|
+
* Handle resize events with debouncing
|
|
34
|
+
*/
|
|
35
|
+
private handleResize;
|
|
36
|
+
/**
|
|
37
|
+
* Process the actual resize logic
|
|
38
|
+
*/
|
|
39
|
+
private processResize;
|
|
40
|
+
/**
|
|
41
|
+
* Get all registered widgets
|
|
42
|
+
*/
|
|
43
|
+
getRegisteredWidgets(): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Cleanup all registered widgets
|
|
46
|
+
*/
|
|
47
|
+
cleanup(): void;
|
|
48
|
+
}
|
|
49
|
+
export declare function getResponsiveManager(): ResponsiveManager;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scroll Trigger
|
|
3
|
+
* Handles viewport detection for mixed mode and scroll distance tracking for overlay mode
|
|
4
|
+
* Uses Intersection Observer and debounced scroll events for performance
|
|
5
|
+
*/
|
|
6
|
+
import type { ScrollTriggerConfig } from "./types.js";
|
|
7
|
+
export interface ScrollTriggerOptions {
|
|
8
|
+
widgetId: string;
|
|
9
|
+
element: HTMLElement;
|
|
10
|
+
type: 'viewport' | 'distance';
|
|
11
|
+
config: ScrollTriggerConfig;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Manages scroll-based triggers for widget display
|
|
15
|
+
*/
|
|
16
|
+
export declare class ScrollTrigger {
|
|
17
|
+
private widgetId;
|
|
18
|
+
private element;
|
|
19
|
+
private type;
|
|
20
|
+
private config;
|
|
21
|
+
private intersectionObserver;
|
|
22
|
+
private isInViewport;
|
|
23
|
+
private hasBeenInViewport;
|
|
24
|
+
private scrollListener;
|
|
25
|
+
private lastScrollY;
|
|
26
|
+
private scrollDistance;
|
|
27
|
+
private isTriggered;
|
|
28
|
+
private debounceTimer;
|
|
29
|
+
private rafId;
|
|
30
|
+
private isDestroyed;
|
|
31
|
+
private stats;
|
|
32
|
+
constructor(options: ScrollTriggerOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Get default scroll trigger configuration
|
|
35
|
+
*/
|
|
36
|
+
private getDefaultConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Initialize scroll trigger based on type
|
|
39
|
+
*/
|
|
40
|
+
private initialize;
|
|
41
|
+
/**
|
|
42
|
+
* Initialize viewport detection for mixed mode
|
|
43
|
+
*/
|
|
44
|
+
private initializeViewportDetection;
|
|
45
|
+
/**
|
|
46
|
+
* Initialize scroll distance tracking for overlay mode
|
|
47
|
+
*/
|
|
48
|
+
private initializeScrollDistance;
|
|
49
|
+
/**
|
|
50
|
+
* Handle intersection observer changes
|
|
51
|
+
*/
|
|
52
|
+
private handleIntersection;
|
|
53
|
+
/**
|
|
54
|
+
* Watch another element from now on (viewport type only).
|
|
55
|
+
*
|
|
56
|
+
* Mixed mode uses it to follow the widget's stand-in while the widget itself
|
|
57
|
+
* is in the overlay. The widget is on screen there, so a watch that stayed on
|
|
58
|
+
* it would report "back in view" the moment it arrived and send it home again.
|
|
59
|
+
*/
|
|
60
|
+
observeElement(element: HTMLElement): void;
|
|
61
|
+
/**
|
|
62
|
+
* Handle scroll distance tracking
|
|
63
|
+
*/
|
|
64
|
+
private handleScrollDistance;
|
|
65
|
+
/**
|
|
66
|
+
* Dispatch trigger activated event
|
|
67
|
+
*/
|
|
68
|
+
private triggerActivated;
|
|
69
|
+
/**
|
|
70
|
+
* Dispatch trigger deactivated event
|
|
71
|
+
*/
|
|
72
|
+
private triggerDeactivated;
|
|
73
|
+
/**
|
|
74
|
+
* Debounce utility for performance optimization
|
|
75
|
+
*/
|
|
76
|
+
private debounce;
|
|
77
|
+
/**
|
|
78
|
+
* Update scroll trigger configuration
|
|
79
|
+
*/
|
|
80
|
+
updateConfig(newConfig: Partial<ScrollTriggerConfig>): void;
|
|
81
|
+
/**
|
|
82
|
+
* Reset trigger state
|
|
83
|
+
*/
|
|
84
|
+
reset(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get current trigger stats
|
|
87
|
+
*/
|
|
88
|
+
getStats(): any;
|
|
89
|
+
/**
|
|
90
|
+
* Check if trigger is currently active
|
|
91
|
+
*/
|
|
92
|
+
isActive(): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Manually trigger activation (for testing)
|
|
95
|
+
*/
|
|
96
|
+
forceActivate(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Manually trigger deactivation (for testing)
|
|
99
|
+
*/
|
|
100
|
+
forceDeactivate(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Destroy scroll trigger and clean up
|
|
103
|
+
*/
|
|
104
|
+
destroy(): void;
|
|
105
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Manager
|
|
3
|
+
* Handles input sanitization, rate limiting, and bot detection for text field operations
|
|
4
|
+
* Designed to be transparent to legitimate users while blocking malicious activity
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Security configuration options
|
|
8
|
+
*/
|
|
9
|
+
export interface SecurityConfig {
|
|
10
|
+
/** Enable input sanitization */
|
|
11
|
+
enableSanitization?: boolean;
|
|
12
|
+
/** Enable rate limiting */
|
|
13
|
+
enableRateLimit?: boolean;
|
|
14
|
+
/** Enable bot detection */
|
|
15
|
+
enableBotDetection?: boolean;
|
|
16
|
+
/** Maximum text length (characters) */
|
|
17
|
+
maxTextLength?: number;
|
|
18
|
+
/** Rate limit: max updates per minute per widget */
|
|
19
|
+
maxUpdatesPerMinute?: number;
|
|
20
|
+
/** Rate limit: max updates per minute globally */
|
|
21
|
+
maxGlobalUpdatesPerMinute?: number;
|
|
22
|
+
/** Suspicious activity threshold */
|
|
23
|
+
suspiciousActivityThreshold?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Rate limit tracking entry
|
|
27
|
+
*/
|
|
28
|
+
export interface RateLimitEntry {
|
|
29
|
+
count: number;
|
|
30
|
+
windowStart: number;
|
|
31
|
+
violations: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Behavioral analysis entry
|
|
35
|
+
*/
|
|
36
|
+
export interface BehaviorEntry {
|
|
37
|
+
updateCount: number;
|
|
38
|
+
averageInterval: number;
|
|
39
|
+
suspiciousPatterns: number;
|
|
40
|
+
firstSeen: number;
|
|
41
|
+
lastSeen: number;
|
|
42
|
+
textLengthVariations: number[];
|
|
43
|
+
updateIntervals: number[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Security validation result
|
|
47
|
+
*/
|
|
48
|
+
export interface SecurityValidationResult {
|
|
49
|
+
allowed: boolean;
|
|
50
|
+
sanitizedText?: string;
|
|
51
|
+
reason?: string;
|
|
52
|
+
severity?: 'low' | 'medium' | 'high';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Security manager for text field operations
|
|
56
|
+
*/
|
|
57
|
+
export declare class SecurityManager {
|
|
58
|
+
private static instance;
|
|
59
|
+
private config;
|
|
60
|
+
private rateLimitTracker;
|
|
61
|
+
private globalRateLimit;
|
|
62
|
+
private behaviorTracker;
|
|
63
|
+
private blockedInstances;
|
|
64
|
+
private suspiciousInstances;
|
|
65
|
+
private cleanupInterval;
|
|
66
|
+
private constructor();
|
|
67
|
+
/**
|
|
68
|
+
* Get singleton instance
|
|
69
|
+
*/
|
|
70
|
+
static getInstance(config?: SecurityConfig): SecurityManager;
|
|
71
|
+
/**
|
|
72
|
+
* Validate text field update for security issues
|
|
73
|
+
*/
|
|
74
|
+
validateTextFieldUpdate(instanceId: string, fieldId: string, text: string, metadata?: any): SecurityValidationResult;
|
|
75
|
+
/**
|
|
76
|
+
* Sanitize input text to prevent XSS and other attacks
|
|
77
|
+
*/
|
|
78
|
+
private sanitizeInput;
|
|
79
|
+
/**
|
|
80
|
+
* Sanitize links to add no-follow attributes and prevent spam
|
|
81
|
+
*/
|
|
82
|
+
private sanitizeLinks;
|
|
83
|
+
/**
|
|
84
|
+
* Check if a URL is external to the current domain
|
|
85
|
+
*/
|
|
86
|
+
private isExternalLink;
|
|
87
|
+
/**
|
|
88
|
+
* Check rate limits for text field updates
|
|
89
|
+
*/
|
|
90
|
+
private checkRateLimit;
|
|
91
|
+
/**
|
|
92
|
+
* Analyze user behavior for bot detection
|
|
93
|
+
*/
|
|
94
|
+
private analyzeBehavior;
|
|
95
|
+
/**
|
|
96
|
+
* Analyze content patterns for suspicious activity
|
|
97
|
+
*/
|
|
98
|
+
private analyzeContentPatterns;
|
|
99
|
+
/**
|
|
100
|
+
* Record security violation
|
|
101
|
+
*/
|
|
102
|
+
private recordViolation;
|
|
103
|
+
/**
|
|
104
|
+
* Calculate variance for behavioral analysis
|
|
105
|
+
*/
|
|
106
|
+
private calculateVariance;
|
|
107
|
+
/**
|
|
108
|
+
* Start cleanup task for old entries
|
|
109
|
+
*/
|
|
110
|
+
private startCleanupTask;
|
|
111
|
+
/**
|
|
112
|
+
* Clean up old tracking data
|
|
113
|
+
*/
|
|
114
|
+
private cleanup;
|
|
115
|
+
/**
|
|
116
|
+
* Check if instance is blocked
|
|
117
|
+
*/
|
|
118
|
+
isInstanceBlocked(instanceId: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Check if instance is suspicious
|
|
121
|
+
*/
|
|
122
|
+
isInstanceSuspicious(instanceId: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Manually unblock instance (for admin purposes)
|
|
125
|
+
*/
|
|
126
|
+
unblockInstance(instanceId: string): void;
|
|
127
|
+
/**
|
|
128
|
+
* Get security statistics
|
|
129
|
+
*/
|
|
130
|
+
getSecurityStats(): {
|
|
131
|
+
blockedInstances: number;
|
|
132
|
+
suspiciousInstances: number;
|
|
133
|
+
rateLimitEntries: number;
|
|
134
|
+
behaviorEntries: number;
|
|
135
|
+
globalRateLimit: RateLimitEntry;
|
|
136
|
+
config: Required<SecurityConfig>;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Update security configuration
|
|
140
|
+
*/
|
|
141
|
+
updateConfig(newConfig: Partial<SecurityConfig>): void;
|
|
142
|
+
/**
|
|
143
|
+
* Destroy security manager and cleanup resources
|
|
144
|
+
*/
|
|
145
|
+
destroy(): void;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get singleton instance of SecurityManager
|
|
149
|
+
*/
|
|
150
|
+
export declare function getSecurityManager(config?: SecurityConfig): SecurityManager;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Field Manager
|
|
3
|
+
* Handles persistence of text input data across widget sessions
|
|
4
|
+
* Follows the same architectural pattern as ContentPositionManager and MediaManager
|
|
5
|
+
*/
|
|
6
|
+
import { type SecurityConfig } from "./security-manager.js";
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for text field persistence
|
|
9
|
+
*/
|
|
10
|
+
export interface TextFieldConfig {
|
|
11
|
+
/** Whether to auto-persist text changes */
|
|
12
|
+
autoPersist?: boolean;
|
|
13
|
+
/** Type of text content being tracked */
|
|
14
|
+
textType?: 'form' | 'editor' | 'comment' | 'note' | 'custom';
|
|
15
|
+
/** Whether to persist state in localStorage */
|
|
16
|
+
persistState?: boolean;
|
|
17
|
+
/** Whether to auto-restore text after page refresh */
|
|
18
|
+
autoRestore?: boolean;
|
|
19
|
+
/** Maximum time since last change to allow auto-restore (ms, default: 24 hours) */
|
|
20
|
+
autoRestoreTimeout?: number;
|
|
21
|
+
/** Debounce delay for auto-save in milliseconds */
|
|
22
|
+
debounceDelay?: number;
|
|
23
|
+
/** Maximum length of text to persist */
|
|
24
|
+
maxLength?: number;
|
|
25
|
+
/** Custom storage key suffix */
|
|
26
|
+
storageKeySuffix?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Text field state stored in localStorage
|
|
30
|
+
*/
|
|
31
|
+
export interface TextFieldState {
|
|
32
|
+
/** Widget instance ID */
|
|
33
|
+
instanceId: string;
|
|
34
|
+
/** Field identifier within the widget */
|
|
35
|
+
fieldId: string;
|
|
36
|
+
/** Text content */
|
|
37
|
+
text: string;
|
|
38
|
+
/** Timestamp of last modification */
|
|
39
|
+
lastModified: number;
|
|
40
|
+
/** Text type/category */
|
|
41
|
+
textType: string;
|
|
42
|
+
/** Optional metadata */
|
|
43
|
+
metadata?: {
|
|
44
|
+
/** Field label or name */
|
|
45
|
+
fieldName?: string;
|
|
46
|
+
/** Field type (textarea, input, editor, etc.) */
|
|
47
|
+
fieldType?: string;
|
|
48
|
+
/** Character count */
|
|
49
|
+
characterCount?: number;
|
|
50
|
+
/** Word count */
|
|
51
|
+
wordCount?: number;
|
|
52
|
+
/** Additional custom metadata */
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Text field persistence manager
|
|
58
|
+
* Handles auto-save and restore functionality for text inputs across widgets
|
|
59
|
+
*/
|
|
60
|
+
export declare class TextFieldManager {
|
|
61
|
+
private static instance;
|
|
62
|
+
private textStates;
|
|
63
|
+
private debounceTimers;
|
|
64
|
+
private storageKey;
|
|
65
|
+
private storageVersion;
|
|
66
|
+
private maxStorageAge;
|
|
67
|
+
private autoRestoreEnabled;
|
|
68
|
+
private initialized;
|
|
69
|
+
private securityManager;
|
|
70
|
+
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Get singleton instance
|
|
73
|
+
*/
|
|
74
|
+
static getInstance(): TextFieldManager;
|
|
75
|
+
/**
|
|
76
|
+
* Initialize the manager
|
|
77
|
+
*/
|
|
78
|
+
private initialize;
|
|
79
|
+
/**
|
|
80
|
+
* Register text field for persistence
|
|
81
|
+
*/
|
|
82
|
+
registerTextField(instanceId: string, fieldId: string, config?: TextFieldConfig): string;
|
|
83
|
+
/**
|
|
84
|
+
* Update text field content
|
|
85
|
+
*/
|
|
86
|
+
updateTextField(instanceId: string, fieldId: string, text: string, config?: TextFieldConfig, metadata?: TextFieldState['metadata']): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get text field content
|
|
89
|
+
*/
|
|
90
|
+
getTextField(instanceId: string, fieldId: string): TextFieldState | null;
|
|
91
|
+
/**
|
|
92
|
+
* Get all text fields for a widget instance
|
|
93
|
+
*/
|
|
94
|
+
getWidgetTextFields(instanceId: string): TextFieldState[];
|
|
95
|
+
/**
|
|
96
|
+
* Clear text field content
|
|
97
|
+
*/
|
|
98
|
+
clearTextField(instanceId: string, fieldId: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Clear all text fields for a widget instance
|
|
101
|
+
*/
|
|
102
|
+
clearWidgetTextFields(instanceId: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Manually persist current state
|
|
105
|
+
*/
|
|
106
|
+
persistTextFields(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Check if auto-restore should be applied
|
|
109
|
+
*/
|
|
110
|
+
private shouldAutoRestore;
|
|
111
|
+
/**
|
|
112
|
+
* Generate unique state key for text field
|
|
113
|
+
*/
|
|
114
|
+
private generateStateKey;
|
|
115
|
+
/**
|
|
116
|
+
* Debounced persistence to avoid excessive localStorage writes
|
|
117
|
+
*/
|
|
118
|
+
private debouncePersist;
|
|
119
|
+
/**
|
|
120
|
+
* Clear debounce timer for a specific field
|
|
121
|
+
*/
|
|
122
|
+
private clearDebounceTimer;
|
|
123
|
+
/**
|
|
124
|
+
* Load stored state from localStorage
|
|
125
|
+
*/
|
|
126
|
+
private loadStoredState;
|
|
127
|
+
/**
|
|
128
|
+
* Persist current state to localStorage
|
|
129
|
+
*/
|
|
130
|
+
private persistState;
|
|
131
|
+
/**
|
|
132
|
+
* Clean up old entries to prevent localStorage bloat
|
|
133
|
+
*/
|
|
134
|
+
private cleanupOldEntries;
|
|
135
|
+
/**
|
|
136
|
+
* Count words in text
|
|
137
|
+
*/
|
|
138
|
+
private countWords;
|
|
139
|
+
/**
|
|
140
|
+
* Enable/disable auto-restore functionality
|
|
141
|
+
*/
|
|
142
|
+
setAutoRestoreEnabled(enabled: boolean): void;
|
|
143
|
+
/**
|
|
144
|
+
* Get manager statistics
|
|
145
|
+
*/
|
|
146
|
+
getStats(): {
|
|
147
|
+
totalFields: number;
|
|
148
|
+
totalCharacters: number;
|
|
149
|
+
avgCharactersPerField: number;
|
|
150
|
+
oldestEntry: number | null;
|
|
151
|
+
newestEntry: number | null;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Cleanup all data and reset manager
|
|
155
|
+
*/
|
|
156
|
+
cleanup(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Configure security settings
|
|
159
|
+
*/
|
|
160
|
+
configureSecurity(config: Partial<SecurityConfig>): void;
|
|
161
|
+
/**
|
|
162
|
+
* Check if an instance is blocked by security
|
|
163
|
+
*/
|
|
164
|
+
isInstanceBlocked(instanceId: string): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Check if an instance is marked as suspicious
|
|
167
|
+
*/
|
|
168
|
+
isInstanceSuspicious(instanceId: string): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Unblock an instance (admin function)
|
|
171
|
+
*/
|
|
172
|
+
unblockInstance(instanceId: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* Get security statistics
|
|
175
|
+
*/
|
|
176
|
+
getSecurityStats(): {
|
|
177
|
+
blockedInstances: number;
|
|
178
|
+
suspiciousInstances: number;
|
|
179
|
+
rateLimitEntries: number;
|
|
180
|
+
behaviorEntries: number;
|
|
181
|
+
globalRateLimit: import("./security-manager.js").RateLimitEntry;
|
|
182
|
+
config: Required<SecurityConfig>;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Validate text without storing it (for preview/testing)
|
|
186
|
+
*/
|
|
187
|
+
validateText(instanceId: string, fieldId: string, text: string, metadata?: any): import("./security-manager.js").SecurityValidationResult;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get singleton instance of TextFieldManager
|
|
191
|
+
*/
|
|
192
|
+
export declare function getTextFieldManager(): TextFieldManager;
|
|
193
|
+
/**
|
|
194
|
+
* Convenience function to register a text field
|
|
195
|
+
*/
|
|
196
|
+
export declare function registerTextField(instanceId: string, fieldId: string, config?: TextFieldConfig): string;
|
|
197
|
+
/**
|
|
198
|
+
* Convenience function to update text field content
|
|
199
|
+
*/
|
|
200
|
+
export declare function updateTextField(instanceId: string, fieldId: string, text: string, config?: TextFieldConfig, metadata?: TextFieldState['metadata']): void;
|
|
201
|
+
/**
|
|
202
|
+
* Convenience function to get text field content
|
|
203
|
+
*/
|
|
204
|
+
export declare function getTextField(instanceId: string, fieldId: string): TextFieldState | null;
|