@widgetic/embed-sdk 0.0.0-stage → 2.0.7
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,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced Security Manager for Widgetic Embed SDK
|
|
3
|
+
*
|
|
4
|
+
* Implements comprehensive security and privacy features:
|
|
5
|
+
* - Content Security Policy (CSP) management
|
|
6
|
+
* - Secure data handling for sensitive widgets
|
|
7
|
+
* - Content filtering and moderation hooks
|
|
8
|
+
* - Audit logging for security events
|
|
9
|
+
* - Privacy controls (GDPR/CCPA compliance)
|
|
10
|
+
* - Advanced threat detection
|
|
11
|
+
*/
|
|
12
|
+
import { type SecurityConfig } from "./security-manager.js";
|
|
13
|
+
/**
|
|
14
|
+
* CSP Configuration for different security levels
|
|
15
|
+
*/
|
|
16
|
+
export interface CSPConfig {
|
|
17
|
+
level: 'strict' | 'balanced' | 'permissive';
|
|
18
|
+
customDirectives?: Record<string, string[]>;
|
|
19
|
+
allowedDomains?: string[];
|
|
20
|
+
allowInlineStyles?: boolean;
|
|
21
|
+
allowEval?: boolean;
|
|
22
|
+
reportOnly?: boolean;
|
|
23
|
+
reportUri?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Data classification levels for sensitive content
|
|
27
|
+
*/
|
|
28
|
+
export type DataClassification = 'public' | 'internal' | 'confidential' | 'restricted';
|
|
29
|
+
/**
|
|
30
|
+
* Secure data handling configuration
|
|
31
|
+
*/
|
|
32
|
+
export interface SecureDataConfig {
|
|
33
|
+
classification: DataClassification;
|
|
34
|
+
encryptInTransit?: boolean;
|
|
35
|
+
encryptAtRest?: boolean;
|
|
36
|
+
anonymizeData?: boolean;
|
|
37
|
+
dataRetentionDays?: number;
|
|
38
|
+
allowedRegions?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Content filtering and moderation configuration
|
|
42
|
+
*/
|
|
43
|
+
export interface ContentFilterConfig {
|
|
44
|
+
enableProfanityFilter?: boolean;
|
|
45
|
+
enableSpamDetection?: boolean;
|
|
46
|
+
enableMalwareScanning?: boolean;
|
|
47
|
+
customFilters?: ContentFilter[];
|
|
48
|
+
moderationWebhook?: string;
|
|
49
|
+
autoModeration?: boolean;
|
|
50
|
+
appealProcess?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Custom content filter definition
|
|
54
|
+
*/
|
|
55
|
+
export interface ContentFilter {
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
type: 'regex' | 'keyword' | 'ai' | 'custom';
|
|
60
|
+
pattern?: string | RegExp;
|
|
61
|
+
keywords?: string[];
|
|
62
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
63
|
+
action: 'warn' | 'block' | 'quarantine' | 'moderate';
|
|
64
|
+
customHandler?: (content: string, context: any) => Promise<FilterResult>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Content filter result
|
|
68
|
+
*/
|
|
69
|
+
export interface FilterResult {
|
|
70
|
+
allowed: boolean;
|
|
71
|
+
filtered?: boolean;
|
|
72
|
+
filteredContent?: string;
|
|
73
|
+
violations?: FilterViolation[];
|
|
74
|
+
confidence?: number;
|
|
75
|
+
requiresModeration?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Content filter violation
|
|
79
|
+
*/
|
|
80
|
+
export interface FilterViolation {
|
|
81
|
+
filterId: string;
|
|
82
|
+
filterName: string;
|
|
83
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
84
|
+
reason: string;
|
|
85
|
+
position?: {
|
|
86
|
+
start: number;
|
|
87
|
+
end: number;
|
|
88
|
+
};
|
|
89
|
+
suggestion?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Privacy control configuration
|
|
93
|
+
*/
|
|
94
|
+
export interface PrivacyConfig {
|
|
95
|
+
enableGDPRCompliance?: boolean;
|
|
96
|
+
enableCCPACompliance?: boolean;
|
|
97
|
+
anonymizeUserData?: boolean;
|
|
98
|
+
cookieConsent?: boolean;
|
|
99
|
+
dataProcessingBasis?: 'consent' | 'legitimate_interest' | 'contract' | 'legal_obligation';
|
|
100
|
+
dataSubjectRights?: boolean;
|
|
101
|
+
rightToErasure?: boolean;
|
|
102
|
+
dataPortability?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Audit event types
|
|
106
|
+
*/
|
|
107
|
+
export type AuditEventType = 'widget_loaded' | 'widget_interacted' | 'data_accessed' | 'data_modified' | 'security_violation' | 'privacy_consent' | 'content_filtered' | 'threat_detected' | 'configuration_changed' | 'user_authentication' | 'data_export' | 'data_deletion';
|
|
108
|
+
/**
|
|
109
|
+
* Audit event structure
|
|
110
|
+
*/
|
|
111
|
+
export interface AuditEvent {
|
|
112
|
+
id: string;
|
|
113
|
+
type: AuditEventType;
|
|
114
|
+
timestamp: string;
|
|
115
|
+
userId?: string;
|
|
116
|
+
sessionId?: string;
|
|
117
|
+
widgetId: string;
|
|
118
|
+
action: string;
|
|
119
|
+
resource?: string;
|
|
120
|
+
outcome: 'success' | 'failure' | 'blocked' | 'suspicious';
|
|
121
|
+
details: Record<string, any>;
|
|
122
|
+
ipAddress?: string;
|
|
123
|
+
userAgent?: string;
|
|
124
|
+
classification: DataClassification;
|
|
125
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
126
|
+
correlationId?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Advanced threat detection patterns
|
|
130
|
+
*/
|
|
131
|
+
export interface ThreatPattern {
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
description: string;
|
|
135
|
+
type: 'injection' | 'exfiltration' | 'enumeration' | 'ddos' | 'social_engineering';
|
|
136
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
137
|
+
indicators: ThreatIndicator[];
|
|
138
|
+
responseAction: 'log' | 'warn' | 'block' | 'quarantine';
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Threat detection indicators
|
|
142
|
+
*/
|
|
143
|
+
export interface ThreatIndicator {
|
|
144
|
+
type: 'pattern' | 'behavior' | 'frequency' | 'content';
|
|
145
|
+
condition: string | RegExp | ((context: any) => boolean);
|
|
146
|
+
weight: number;
|
|
147
|
+
timeWindow?: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Comprehensive security and privacy configuration
|
|
151
|
+
*/
|
|
152
|
+
export interface AdvancedSecurityConfig extends SecurityConfig {
|
|
153
|
+
csp?: CSPConfig;
|
|
154
|
+
secureData?: SecureDataConfig;
|
|
155
|
+
contentFilter?: ContentFilterConfig;
|
|
156
|
+
privacy?: PrivacyConfig;
|
|
157
|
+
auditLogging?: boolean;
|
|
158
|
+
threatDetection?: boolean;
|
|
159
|
+
customThreatPatterns?: ThreatPattern[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Advanced Security Manager
|
|
163
|
+
* Extends the basic security manager with advanced security features
|
|
164
|
+
*/
|
|
165
|
+
export declare class AdvancedSecurityManager {
|
|
166
|
+
private static instance;
|
|
167
|
+
private config;
|
|
168
|
+
private baseSecurityManager;
|
|
169
|
+
private cspDirectives;
|
|
170
|
+
private cspNonce;
|
|
171
|
+
private encryptionKey;
|
|
172
|
+
private sensitiveDataCache;
|
|
173
|
+
private contentFilters;
|
|
174
|
+
private moderationQueue;
|
|
175
|
+
private auditEvents;
|
|
176
|
+
private auditBuffer;
|
|
177
|
+
private threatPatterns;
|
|
178
|
+
private threatScores;
|
|
179
|
+
private consentStatus;
|
|
180
|
+
private dataSubjects;
|
|
181
|
+
private constructor();
|
|
182
|
+
/**
|
|
183
|
+
* Get singleton instance
|
|
184
|
+
*/
|
|
185
|
+
static getInstance(config?: AdvancedSecurityConfig): AdvancedSecurityManager;
|
|
186
|
+
/**
|
|
187
|
+
* Initialize Content Security Policy
|
|
188
|
+
*/
|
|
189
|
+
private initializeCSP;
|
|
190
|
+
/**
|
|
191
|
+
* Generate cryptographic nonce for CSP
|
|
192
|
+
*/
|
|
193
|
+
private generateNonce;
|
|
194
|
+
/**
|
|
195
|
+
* Set up CSP directives based on configuration
|
|
196
|
+
*/
|
|
197
|
+
private setupCSPDirectives;
|
|
198
|
+
/**
|
|
199
|
+
* Apply CSP to the document
|
|
200
|
+
*/
|
|
201
|
+
private applyCSP;
|
|
202
|
+
/**
|
|
203
|
+
* Build CSP string from directives
|
|
204
|
+
*/
|
|
205
|
+
private buildCSPString;
|
|
206
|
+
/**
|
|
207
|
+
* Initialize data security features
|
|
208
|
+
*/
|
|
209
|
+
private initializeDataSecurity;
|
|
210
|
+
/**
|
|
211
|
+
* Initialize content filtering system
|
|
212
|
+
*/
|
|
213
|
+
private initializeContentFilters;
|
|
214
|
+
/**
|
|
215
|
+
* Add default content filters
|
|
216
|
+
*/
|
|
217
|
+
private addDefaultContentFilters;
|
|
218
|
+
/**
|
|
219
|
+
* Initialize threat detection patterns
|
|
220
|
+
*/
|
|
221
|
+
private initializeThreatDetection;
|
|
222
|
+
/**
|
|
223
|
+
* Add default threat detection patterns
|
|
224
|
+
*/
|
|
225
|
+
private addDefaultThreatPatterns;
|
|
226
|
+
/**
|
|
227
|
+
* Initialize privacy controls
|
|
228
|
+
*/
|
|
229
|
+
private initializePrivacyControls;
|
|
230
|
+
/**
|
|
231
|
+
* Initialize consent management
|
|
232
|
+
*/
|
|
233
|
+
private initializeConsentManagement;
|
|
234
|
+
/**
|
|
235
|
+
* Initialize data subject rights handling
|
|
236
|
+
*/
|
|
237
|
+
private initializeDataSubjectRights;
|
|
238
|
+
/**
|
|
239
|
+
* MAIN PUBLIC API METHODS
|
|
240
|
+
*/
|
|
241
|
+
/**
|
|
242
|
+
* Validate and filter content through all security layers
|
|
243
|
+
*/
|
|
244
|
+
validateContent(widgetId: string, content: string, context?: {
|
|
245
|
+
userId?: string;
|
|
246
|
+
sessionId?: string;
|
|
247
|
+
fieldId?: string;
|
|
248
|
+
}): Promise<{
|
|
249
|
+
allowed: boolean;
|
|
250
|
+
filteredContent?: string;
|
|
251
|
+
violations: FilterViolation[];
|
|
252
|
+
}>;
|
|
253
|
+
/**
|
|
254
|
+
* Apply all content filters to the given content
|
|
255
|
+
*/
|
|
256
|
+
private applyContentFilters;
|
|
257
|
+
/**
|
|
258
|
+
* Apply a single content filter
|
|
259
|
+
*/
|
|
260
|
+
private applyFilter;
|
|
261
|
+
/**
|
|
262
|
+
* Apply regex-based filter
|
|
263
|
+
*/
|
|
264
|
+
private applyRegexFilter;
|
|
265
|
+
/**
|
|
266
|
+
* Apply keyword-based filter
|
|
267
|
+
*/
|
|
268
|
+
private applyKeywordFilter;
|
|
269
|
+
/**
|
|
270
|
+
* Detect link-based spam patterns
|
|
271
|
+
*/
|
|
272
|
+
private detectLinkSpam;
|
|
273
|
+
/**
|
|
274
|
+
* Detect threats in content
|
|
275
|
+
*/
|
|
276
|
+
private detectThreats;
|
|
277
|
+
/**
|
|
278
|
+
* Evaluate a single threat indicator
|
|
279
|
+
*/
|
|
280
|
+
private evaluateIndicator;
|
|
281
|
+
/**
|
|
282
|
+
* Log audit events
|
|
283
|
+
*/
|
|
284
|
+
logAuditEvent(eventData: Partial<AuditEvent> & {
|
|
285
|
+
type: AuditEventType;
|
|
286
|
+
widgetId: string;
|
|
287
|
+
action: string;
|
|
288
|
+
outcome: 'success' | 'failure' | 'blocked' | 'suspicious';
|
|
289
|
+
}): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Get CSP nonce for inline scripts/styles
|
|
292
|
+
*/
|
|
293
|
+
getCSPNonce(): string;
|
|
294
|
+
/**
|
|
295
|
+
* Update CSP configuration
|
|
296
|
+
*/
|
|
297
|
+
updateCSPConfig(config: Partial<CSPConfig>): void;
|
|
298
|
+
/**
|
|
299
|
+
* Record privacy consent
|
|
300
|
+
*/
|
|
301
|
+
recordConsent(widgetId: string, consentType: string, granted: boolean, context?: {
|
|
302
|
+
userId?: string;
|
|
303
|
+
sessionId?: string;
|
|
304
|
+
}): void;
|
|
305
|
+
/**
|
|
306
|
+
* Check if consent is granted for a specific type
|
|
307
|
+
*/
|
|
308
|
+
hasConsent(consentType: string): boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Get security statistics
|
|
311
|
+
*/
|
|
312
|
+
getSecurityStats(): {
|
|
313
|
+
auditEvents: number;
|
|
314
|
+
threatDetections: number;
|
|
315
|
+
contentFiltered: number;
|
|
316
|
+
blockedInstances: number;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Export audit logs (with privacy controls)
|
|
320
|
+
*/
|
|
321
|
+
exportAuditLogs(widgetId?: string, classification?: DataClassification): AuditEvent[];
|
|
322
|
+
private generateEventId;
|
|
323
|
+
private generateCorrelationId;
|
|
324
|
+
private getClientIP;
|
|
325
|
+
private getLogLevel;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get singleton instance of advanced security manager
|
|
329
|
+
*/
|
|
330
|
+
export declare function getAdvancedSecurityManager(config?: AdvancedSecurityConfig): AdvancedSecurityManager;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Event Tracker
|
|
3
|
+
* Central system for tracking composition analytics events in the embed SDK
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Composition view and interaction tracking
|
|
7
|
+
* - Session management
|
|
8
|
+
* - Device and referrer information collection
|
|
9
|
+
* - Privacy compliance (GDPR consent checking)
|
|
10
|
+
* - Event batching and local storage
|
|
11
|
+
* - Rate limiting and spam prevention
|
|
12
|
+
* - Integration with existing SDK components
|
|
13
|
+
*/
|
|
14
|
+
import { type DeviceInfo } from "../utils/device-detector.js";
|
|
15
|
+
import { PrivacyCompliance } from "./privacy-compliance.js";
|
|
16
|
+
export type AnalyticsEventType = 'composition_view' | 'composition_interaction' | 'session_start' | 'session_end' | 'device_info' | 'referrer_info';
|
|
17
|
+
export interface AnalyticsEvent {
|
|
18
|
+
id: string;
|
|
19
|
+
eventType: AnalyticsEventType;
|
|
20
|
+
compositionId: string;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
userId?: string;
|
|
24
|
+
data: Record<string, any>;
|
|
25
|
+
deviceInfo?: DeviceInfo;
|
|
26
|
+
referrer?: string;
|
|
27
|
+
userAgent: string;
|
|
28
|
+
url: string;
|
|
29
|
+
}
|
|
30
|
+
export interface InteractionEventData {
|
|
31
|
+
interactionType: 'click' | 'hover' | 'focus' | 'scroll' | 'touch';
|
|
32
|
+
elementType?: string;
|
|
33
|
+
elementId?: string;
|
|
34
|
+
coordinates?: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
};
|
|
38
|
+
duration?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface ViewEventData {
|
|
41
|
+
viewDuration?: number;
|
|
42
|
+
viewportSize: {
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
};
|
|
46
|
+
scrollPosition?: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
};
|
|
50
|
+
loadTime?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface SessionEventData {
|
|
53
|
+
sessionDuration?: number;
|
|
54
|
+
pageViews?: number;
|
|
55
|
+
interactions?: number;
|
|
56
|
+
exitReason?: 'user_close' | 'navigation' | 'timeout' | 'error' | 'visibility_hidden' | 'destroy';
|
|
57
|
+
}
|
|
58
|
+
export interface AnalyticsTrackerConfig {
|
|
59
|
+
compositionId: string;
|
|
60
|
+
apiEndpoint?: string;
|
|
61
|
+
batchSize?: number;
|
|
62
|
+
batchTimeout?: number;
|
|
63
|
+
maxRetries?: number;
|
|
64
|
+
rateLimitPerMinute?: number;
|
|
65
|
+
enableLocalStorage?: boolean;
|
|
66
|
+
enableDeviceTracking?: boolean;
|
|
67
|
+
enableInteractionTracking?: boolean;
|
|
68
|
+
trackOnlyClicks?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Central Analytics Event Tracker
|
|
72
|
+
* Singleton class for managing all analytics events in the embed SDK
|
|
73
|
+
*/
|
|
74
|
+
export declare class AnalyticsTracker {
|
|
75
|
+
private static instance;
|
|
76
|
+
private config;
|
|
77
|
+
private sessionId;
|
|
78
|
+
private deviceDetector;
|
|
79
|
+
private privacyCompliance;
|
|
80
|
+
private eventQueue;
|
|
81
|
+
private batchTimer;
|
|
82
|
+
private isOnline;
|
|
83
|
+
private rateLimitState;
|
|
84
|
+
private sessionStartTime;
|
|
85
|
+
private lastActivityTime;
|
|
86
|
+
private isSessionActive;
|
|
87
|
+
private interactionCount;
|
|
88
|
+
private viewStartTime;
|
|
89
|
+
private readonly STORAGE_KEY;
|
|
90
|
+
private readonly SESSION_KEY;
|
|
91
|
+
private constructor();
|
|
92
|
+
/**
|
|
93
|
+
* Get or create analytics tracker instance
|
|
94
|
+
*/
|
|
95
|
+
static getInstance(config?: AnalyticsTrackerConfig): AnalyticsTracker;
|
|
96
|
+
/**
|
|
97
|
+
* Initialize or restore session ID
|
|
98
|
+
*/
|
|
99
|
+
private initializeSession;
|
|
100
|
+
/**
|
|
101
|
+
* Set privacy compliance instance for consent checking
|
|
102
|
+
*/
|
|
103
|
+
setPrivacyCompliance(privacyCompliance: PrivacyCompliance): void;
|
|
104
|
+
/**
|
|
105
|
+
* Check if analytics tracking is allowed based on privacy consent
|
|
106
|
+
*/
|
|
107
|
+
private isTrackingAllowed;
|
|
108
|
+
/**
|
|
109
|
+
* Setup event listeners for browser events
|
|
110
|
+
*/
|
|
111
|
+
private setupEventListeners;
|
|
112
|
+
/**
|
|
113
|
+
* Update activity timestamp and interaction count
|
|
114
|
+
*/
|
|
115
|
+
private updateActivity;
|
|
116
|
+
/**
|
|
117
|
+
* Check rate limiting for event type
|
|
118
|
+
*/
|
|
119
|
+
private isRateLimited;
|
|
120
|
+
/**
|
|
121
|
+
* Generate unique event ID
|
|
122
|
+
*/
|
|
123
|
+
private generateEventId;
|
|
124
|
+
/**
|
|
125
|
+
* Create base analytics event
|
|
126
|
+
*/
|
|
127
|
+
private createBaseEvent;
|
|
128
|
+
/**
|
|
129
|
+
* Queue event for batch processing
|
|
130
|
+
*/
|
|
131
|
+
private queueEvent;
|
|
132
|
+
/**
|
|
133
|
+
* Schedule batch processing
|
|
134
|
+
*/
|
|
135
|
+
private scheduleBatch;
|
|
136
|
+
/**
|
|
137
|
+
* Process queued events in batch
|
|
138
|
+
*/
|
|
139
|
+
private processBatch;
|
|
140
|
+
/**
|
|
141
|
+
* Send event batch to analytics API
|
|
142
|
+
*/
|
|
143
|
+
private sendEventBatch;
|
|
144
|
+
/**
|
|
145
|
+
* Save event queue to local storage
|
|
146
|
+
*/
|
|
147
|
+
private saveQueueToStorage;
|
|
148
|
+
/**
|
|
149
|
+
* Load queued events from local storage
|
|
150
|
+
*/
|
|
151
|
+
private loadQueuedEvents;
|
|
152
|
+
/**
|
|
153
|
+
* Flush all events immediately (for page unload)
|
|
154
|
+
*/
|
|
155
|
+
private flushEvents;
|
|
156
|
+
/**
|
|
157
|
+
* Track composition view event
|
|
158
|
+
*/
|
|
159
|
+
trackCompositionView(data?: Partial<ViewEventData>): void;
|
|
160
|
+
/**
|
|
161
|
+
* Track composition interaction event
|
|
162
|
+
*/
|
|
163
|
+
trackCompositionInteraction(data: InteractionEventData): void;
|
|
164
|
+
/**
|
|
165
|
+
* Track session start event
|
|
166
|
+
*/
|
|
167
|
+
trackSessionStart(): void;
|
|
168
|
+
/**
|
|
169
|
+
* Track session end event
|
|
170
|
+
*/
|
|
171
|
+
trackSessionEnd(exitReason?: SessionEventData['exitReason']): void;
|
|
172
|
+
/**
|
|
173
|
+
* Track device information event (called once per session)
|
|
174
|
+
*/
|
|
175
|
+
trackDeviceInfo(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Track referrer information event
|
|
178
|
+
*/
|
|
179
|
+
trackReferrerInfo(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Get current session information
|
|
182
|
+
*/
|
|
183
|
+
getSessionInfo(): {
|
|
184
|
+
sessionId: string;
|
|
185
|
+
isActive: boolean;
|
|
186
|
+
startTime: number;
|
|
187
|
+
lastActivity: number;
|
|
188
|
+
interactionCount: number;
|
|
189
|
+
duration: number;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Update configuration
|
|
193
|
+
*/
|
|
194
|
+
updateConfig(newConfig: Partial<AnalyticsTrackerConfig>): void;
|
|
195
|
+
/**
|
|
196
|
+
* Clear all queued events
|
|
197
|
+
*/
|
|
198
|
+
clearQueue(): void;
|
|
199
|
+
/**
|
|
200
|
+
* Get analytics statistics
|
|
201
|
+
*/
|
|
202
|
+
getStats(): {
|
|
203
|
+
queueSize: number;
|
|
204
|
+
sessionInfo: {
|
|
205
|
+
sessionId: string;
|
|
206
|
+
isActive: boolean;
|
|
207
|
+
startTime: number;
|
|
208
|
+
lastActivity: number;
|
|
209
|
+
interactionCount: number;
|
|
210
|
+
duration: number;
|
|
211
|
+
};
|
|
212
|
+
rateLimits: {
|
|
213
|
+
[k: string]: number;
|
|
214
|
+
};
|
|
215
|
+
isOnline: boolean;
|
|
216
|
+
trackingAllowed: boolean;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Cleanup and destroy tracker
|
|
220
|
+
*/
|
|
221
|
+
destroy(): void;
|
|
222
|
+
}
|
|
223
|
+
export declare function getAnalyticsTracker(config?: AnalyticsTrackerConfig): AnalyticsTracker;
|
|
224
|
+
export declare function initializeAnalyticsTracking(config: AnalyticsTrackerConfig): AnalyticsTracker;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Detection Service
|
|
3
|
+
* Detects if user is authenticated and owns compositions for on-site editing
|
|
4
|
+
*/
|
|
5
|
+
import type { Composition } from "@widgetic/api-sdk";
|
|
6
|
+
export type Session = any;
|
|
7
|
+
export interface AuthenticationStatus {
|
|
8
|
+
isAuthenticated: boolean;
|
|
9
|
+
session?: Session;
|
|
10
|
+
user?: any;
|
|
11
|
+
canEdit: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface CompositionOwnership {
|
|
14
|
+
isOwner: boolean;
|
|
15
|
+
canEdit: boolean;
|
|
16
|
+
composition?: Composition;
|
|
17
|
+
error?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Authentication detector for on-site editing capabilities
|
|
21
|
+
*/
|
|
22
|
+
export declare class AuthDetector {
|
|
23
|
+
private authApi;
|
|
24
|
+
private compositionsApi;
|
|
25
|
+
private sessionCache;
|
|
26
|
+
private sessionCacheExpiry;
|
|
27
|
+
private ownershipCache;
|
|
28
|
+
constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Check if user is authenticated
|
|
31
|
+
*/
|
|
32
|
+
checkAuthentication(): Promise<AuthenticationStatus>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if authenticated user owns a specific composition
|
|
35
|
+
*/
|
|
36
|
+
checkCompositionOwnership(compositionId: string): Promise<CompositionOwnership>;
|
|
37
|
+
/**
|
|
38
|
+
* Check if user can edit a composition (authenticated + owns it)
|
|
39
|
+
*/
|
|
40
|
+
canEditComposition(compositionId: string): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Get current authenticated user
|
|
43
|
+
*/
|
|
44
|
+
getCurrentUser(): Promise<any | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Clear authentication cache (for logout)
|
|
47
|
+
*/
|
|
48
|
+
clearCache(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Check authentication status for multiple compositions
|
|
51
|
+
*/
|
|
52
|
+
checkMultipleCompositions(compositionIds: string[]): Promise<Map<string, CompositionOwnership>>;
|
|
53
|
+
/**
|
|
54
|
+
* Check if editing is enabled globally (can be disabled via config)
|
|
55
|
+
*/
|
|
56
|
+
isEditingEnabled(): boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get global auth detector instance
|
|
60
|
+
*/
|
|
61
|
+
export declare function getAuthDetector(): AuthDetector;
|
|
62
|
+
/**
|
|
63
|
+
* Reset global auth detector (for testing)
|
|
64
|
+
*/
|
|
65
|
+
export declare function resetAuthDetector(): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Manager for Widgetic SDK
|
|
3
|
+
*
|
|
4
|
+
* Handles token management including:
|
|
5
|
+
* - API key to JWT token exchange
|
|
6
|
+
* - Token validation and caching
|
|
7
|
+
* - Automatic token refresh
|
|
8
|
+
* - Scoped permissions
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthManagerConfig {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
apiUrl?: string;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
onTokenRefreshed?: (token: string) => void;
|
|
15
|
+
onTokenExpired?: () => void;
|
|
16
|
+
onAuthError?: (error: AuthError) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface TokenInfo {
|
|
19
|
+
token: string;
|
|
20
|
+
tokenType: 'Bearer' | 'API-Key';
|
|
21
|
+
expiresAt: string | null;
|
|
22
|
+
scopes: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface TokenExchangeOptions {
|
|
25
|
+
scopes: string[];
|
|
26
|
+
expiresIn?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare class AuthError extends Error {
|
|
29
|
+
code?: string;
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
constructor(message: string, code?: string, statusCode?: number);
|
|
32
|
+
}
|
|
33
|
+
export declare class AuthManager {
|
|
34
|
+
private config;
|
|
35
|
+
private currentToken;
|
|
36
|
+
private apiKey;
|
|
37
|
+
private refreshTimer;
|
|
38
|
+
private static validatedTokens;
|
|
39
|
+
constructor(config?: AuthManagerConfig);
|
|
40
|
+
private createTokensApiForApiKey;
|
|
41
|
+
private createTokensApiForAccessToken;
|
|
42
|
+
/**
|
|
43
|
+
* Set the API key for token exchange
|
|
44
|
+
*/
|
|
45
|
+
setApiKey(apiKey: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get current valid token, exchanging API key if needed
|
|
48
|
+
*/
|
|
49
|
+
getValidToken(options?: TokenExchangeOptions): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Exchange API key for JWT token with specific scopes
|
|
52
|
+
*/
|
|
53
|
+
exchangeApiKeyForJWT(options?: TokenExchangeOptions): Promise<TokenInfo>;
|
|
54
|
+
/**
|
|
55
|
+
* Validate current token
|
|
56
|
+
*/
|
|
57
|
+
validateToken(): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Set token and schedule refresh
|
|
60
|
+
*/
|
|
61
|
+
private setToken;
|
|
62
|
+
/**
|
|
63
|
+
* Clear current token and cancel refresh timer
|
|
64
|
+
*/
|
|
65
|
+
private clearToken;
|
|
66
|
+
/**
|
|
67
|
+
* Check if token is still valid (not expired)
|
|
68
|
+
*/
|
|
69
|
+
private isTokenValid;
|
|
70
|
+
/**
|
|
71
|
+
* Schedule token refresh before expiry
|
|
72
|
+
*/
|
|
73
|
+
private scheduleTokenRefresh;
|
|
74
|
+
/**
|
|
75
|
+
* Get default scopes for token exchange
|
|
76
|
+
*/
|
|
77
|
+
private getDefaultScopes;
|
|
78
|
+
/**
|
|
79
|
+
* Get current token info
|
|
80
|
+
*/
|
|
81
|
+
getCurrentTokenInfo(): TokenInfo | null;
|
|
82
|
+
/**
|
|
83
|
+
* Check if we have a valid authentication method
|
|
84
|
+
*/
|
|
85
|
+
hasAuthMethod(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Dispose and clean up resources
|
|
88
|
+
*/
|
|
89
|
+
dispose(): void;
|
|
90
|
+
}
|