content-security-toolkit 1.0.0

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.
Files changed (162) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +171 -0
  3. package/dist/config/default-extensions-config.json +103 -0
  4. package/dist/core/ContentProtector.d.ts +63 -0
  5. package/dist/core/ContentProtector.js +279 -0
  6. package/dist/core/index.d.ts +1 -0
  7. package/dist/core/index.js +2 -0
  8. package/dist/core/mediator/ContentProtectionMediator.d.ts +86 -0
  9. package/dist/core/mediator/ContentProtectionMediator.js +238 -0
  10. package/dist/core/mediator/eventDataTypes.d.ts +205 -0
  11. package/dist/core/mediator/eventDataTypes.js +23 -0
  12. package/dist/core/mediator/handlers/abstractEventHandler.d.ts +67 -0
  13. package/dist/core/mediator/handlers/abstractEventHandler.js +106 -0
  14. package/dist/core/mediator/handlers/baseEventHandler.d.ts +65 -0
  15. package/dist/core/mediator/handlers/baseEventHandler.js +99 -0
  16. package/dist/core/mediator/handlers/devToolsEventHandler.d.ts +9 -0
  17. package/dist/core/mediator/handlers/devToolsEventHandler.js +95 -0
  18. package/dist/core/mediator/handlers/eventHandlerRegistry.d.ts +9 -0
  19. package/dist/core/mediator/handlers/eventHandlerRegistry.js +34 -0
  20. package/dist/core/mediator/handlers/extensionEventHandlers.d.ts +40 -0
  21. package/dist/core/mediator/handlers/extensionEventHandlers.js +140 -0
  22. package/dist/core/mediator/handlers/iFrameEventHandlers.d.ts +27 -0
  23. package/dist/core/mediator/handlers/iFrameEventHandlers.js +93 -0
  24. package/dist/core/mediator/handlers/index.d.ts +9 -0
  25. package/dist/core/mediator/handlers/index.js +34 -0
  26. package/dist/core/mediator/handlers/screenShotEventHandlers.d.ts +34 -0
  27. package/dist/core/mediator/handlers/screenShotEventHandlers.js +111 -0
  28. package/dist/core/mediator/protection-event.d.ts +94 -0
  29. package/dist/core/mediator/protection-event.js +43 -0
  30. package/dist/core/mediator/types.d.ts +105 -0
  31. package/dist/core/mediator/types.js +1 -0
  32. package/dist/index.d.ts +4 -0
  33. package/dist/index.js +5 -0
  34. package/dist/strategies/AbstractStrategy.d.ts +152 -0
  35. package/dist/strategies/AbstractStrategy.js +296 -0
  36. package/dist/strategies/AbstractStrategy.mediator.d.ts +162 -0
  37. package/dist/strategies/AbstractStrategy.mediator.js +349 -0
  38. package/dist/strategies/ClipboardStrategy.d.ts +67 -0
  39. package/dist/strategies/ClipboardStrategy.js +291 -0
  40. package/dist/strategies/ContextMenuStrategy.d.ts +60 -0
  41. package/dist/strategies/ContextMenuStrategy.js +454 -0
  42. package/dist/strategies/DevToolsStrategy copy.d.ts +85 -0
  43. package/dist/strategies/DevToolsStrategy copy.js +362 -0
  44. package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +70 -0
  45. package/dist/strategies/DevToolsStrategy-detectorManager.js +309 -0
  46. package/dist/strategies/DevToolsStrategy-simple.d.ts +75 -0
  47. package/dist/strategies/DevToolsStrategy-simple.js +366 -0
  48. package/dist/strategies/DevToolsStrategy.d.ts +55 -0
  49. package/dist/strategies/DevToolsStrategy.js +314 -0
  50. package/dist/strategies/ExtensionStrategy.d.ts +66 -0
  51. package/dist/strategies/ExtensionStrategy.js +486 -0
  52. package/dist/strategies/IFrameStrategy.d.ts +49 -0
  53. package/dist/strategies/IFrameStrategy.js +255 -0
  54. package/dist/strategies/KeyboardStrategy.d.ts +35 -0
  55. package/dist/strategies/KeyboardStrategy.js +130 -0
  56. package/dist/strategies/PrintStrategy.d.ts +47 -0
  57. package/dist/strategies/PrintStrategy.js +201 -0
  58. package/dist/strategies/ScreenshotStrategy.d.ts +90 -0
  59. package/dist/strategies/ScreenshotStrategy.js +488 -0
  60. package/dist/strategies/SelectionStrategy.d.ts +49 -0
  61. package/dist/strategies/SelectionStrategy.js +216 -0
  62. package/dist/strategies/StrategyRegistry.d.ts +133 -0
  63. package/dist/strategies/StrategyRegistry.js +379 -0
  64. package/dist/strategies/WatermarkStrategy.d.ts +47 -0
  65. package/dist/strategies/WatermarkStrategy.js +273 -0
  66. package/dist/strategies/index.d.ts +9 -0
  67. package/dist/strategies/index.js +10 -0
  68. package/dist/types/index.d.ts +271 -0
  69. package/dist/types/index.js +16 -0
  70. package/dist/utils/DOMObserver.d.ts +68 -0
  71. package/dist/utils/DOMObserver.js +134 -0
  72. package/dist/utils/base/LoggableComponent.d.ts +62 -0
  73. package/dist/utils/base/LoggableComponent.js +95 -0
  74. package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +6 -0
  75. package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +24 -0
  76. package/dist/utils/debuggerDetector/debuggerDetector.d.ts +55 -0
  77. package/dist/utils/debuggerDetector/debuggerDetector.js +158 -0
  78. package/dist/utils/debuggerDetector/firefoxDetector.d.ts +8 -0
  79. package/dist/utils/debuggerDetector/firefoxDetector.js +64 -0
  80. package/dist/utils/detection.d.ts +29 -0
  81. package/dist/utils/detection.js +267 -0
  82. package/dist/utils/detectors/AbstractDevToolsDetector.d.ts +105 -0
  83. package/dist/utils/detectors/AbstractDevToolsDetector.js +136 -0
  84. package/dist/utils/detectors/dateToStringDetector.d.ts +43 -0
  85. package/dist/utils/detectors/dateToStringDetector.js +96 -0
  86. package/dist/utils/detectors/debugLibDetector.d.ts +64 -0
  87. package/dist/utils/detectors/debugLibDetector.js +195 -0
  88. package/dist/utils/detectors/debuggerDetectionWorker.d.ts +6 -0
  89. package/dist/utils/detectors/debuggerDetectionWorker.js +24 -0
  90. package/dist/utils/detectors/debuggerDetector.d.ts +51 -0
  91. package/dist/utils/detectors/debuggerDetector.js +211 -0
  92. package/dist/utils/detectors/defineGetterDetector.d.ts +48 -0
  93. package/dist/utils/detectors/defineGetterDetector.js +150 -0
  94. package/dist/utils/detectors/detectorInterface.d.ts +36 -0
  95. package/dist/utils/detectors/detectorInterface.js +1 -0
  96. package/dist/utils/detectors/devToolsDetectorManager.d.ts +88 -0
  97. package/dist/utils/detectors/devToolsDetectorManager.js +246 -0
  98. package/dist/utils/detectors/firefoxDetector.d.ts +8 -0
  99. package/dist/utils/detectors/firefoxDetector.js +64 -0
  100. package/dist/utils/detectors/funcToStringDetector.d.ts +43 -0
  101. package/dist/utils/detectors/funcToStringDetector.js +90 -0
  102. package/dist/utils/detectors/regToStringDetector.d.ts +43 -0
  103. package/dist/utils/detectors/regToStringDetector.js +129 -0
  104. package/dist/utils/detectors/sizeDetector.d.ts +54 -0
  105. package/dist/utils/detectors/sizeDetector.js +134 -0
  106. package/dist/utils/detectors/timingDetector.d.ts +55 -0
  107. package/dist/utils/detectors/timingDetector.js +143 -0
  108. package/dist/utils/dom.d.ts +20 -0
  109. package/dist/utils/dom.js +83 -0
  110. package/dist/utils/environment.d.ts +29 -0
  111. package/dist/utils/environment.js +267 -0
  112. package/dist/utils/eventManager.d.ts +167 -0
  113. package/dist/utils/eventManager.js +556 -0
  114. package/dist/utils/index.d.ts +2 -0
  115. package/dist/utils/index.js +3 -0
  116. package/dist/utils/intervalManager.d.ts +96 -0
  117. package/dist/utils/intervalManager.js +229 -0
  118. package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.d.ts +41 -0
  119. package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.js +135 -0
  120. package/dist/utils/keyboardShortcutManager/keyboardShortcuts.d.ts +18 -0
  121. package/dist/utils/keyboardShortcutManager/keyboardShortcuts.js +195 -0
  122. package/dist/utils/logging/LogLevel.d.ts +21 -0
  123. package/dist/utils/logging/LogLevel.js +46 -0
  124. package/dist/utils/logging/LoggingConfig.d.ts +68 -0
  125. package/dist/utils/logging/LoggingConfig.js +64 -0
  126. package/dist/utils/logging/LoggingFactory.d.ts +22 -0
  127. package/dist/utils/logging/LoggingFactory.js +61 -0
  128. package/dist/utils/logging/LoggingService.d.ts +235 -0
  129. package/dist/utils/logging/LoggingService.js +385 -0
  130. package/dist/utils/logging/SimpleLoggingService.d.ts +39 -0
  131. package/dist/utils/logging/SimpleLoggingService.js +58 -0
  132. package/dist/utils/logging/advanced/LogLevel.d.ts +21 -0
  133. package/dist/utils/logging/advanced/LogLevel.js +46 -0
  134. package/dist/utils/logging/advanced/LoggingConfig.d.ts +68 -0
  135. package/dist/utils/logging/advanced/LoggingConfig.js +64 -0
  136. package/dist/utils/logging/advanced/LoggingFactory.d.ts +22 -0
  137. package/dist/utils/logging/advanced/LoggingFactory.js +61 -0
  138. package/dist/utils/logging/advanced/LoggingService.d.ts +235 -0
  139. package/dist/utils/logging/advanced/LoggingService.js +385 -0
  140. package/dist/utils/logging/simple/Loggable.d.ts +33 -0
  141. package/dist/utils/logging/simple/Loggable.js +1 -0
  142. package/dist/utils/logging/simple/LoggingDelegate.d.ts +42 -0
  143. package/dist/utils/logging/simple/LoggingDelegate.js +53 -0
  144. package/dist/utils/logging/simple/SimpleLoggingService.d.ts +39 -0
  145. package/dist/utils/logging/simple/SimpleLoggingService.js +58 -0
  146. package/dist/utils/orientation.d.ts +15 -0
  147. package/dist/utils/orientation.js +32 -0
  148. package/dist/utils/protectedContentManager-simple.d.ts +86 -0
  149. package/dist/utils/protectedContentManager-simple.js +180 -0
  150. package/dist/utils/protectedContentManager.d.ts +162 -0
  151. package/dist/utils/protectedContentManager.js +427 -0
  152. package/dist/utils/screenshotDetector.d.ts +72 -0
  153. package/dist/utils/screenshotDetector.js +179 -0
  154. package/dist/utils/securityOverlayManager-observer-pause.d.ts +283 -0
  155. package/dist/utils/securityOverlayManager-observer-pause.js +878 -0
  156. package/dist/utils/securityOverlayManager-simple.d.ts +197 -0
  157. package/dist/utils/securityOverlayManager-simple.js +552 -0
  158. package/dist/utils/securityOverlayManager.d.ts +260 -0
  159. package/dist/utils/securityOverlayManager.js +774 -0
  160. package/dist/utils/timeoutManager.d.ts +55 -0
  161. package/dist/utils/timeoutManager.js +121 -0
  162. package/package.json +54 -0
@@ -0,0 +1,93 @@
1
+ import { ProtectionEventType } from "../../mediator/protection-event";
2
+ import { AbstractEventHandler } from "./abstractEventHandler";
3
+ /**
4
+ * Handler for frame embedding events
5
+ */
6
+ export class FrameEmbeddingEventHandler extends AbstractEventHandler {
7
+ /**
8
+ * Create a new FrameEmbeddingEventHandler
9
+ * @param mediator The protection mediator
10
+ * @param debugMode Enable debug mode for troubleshooting
11
+ */
12
+ constructor(mediator, debugMode = false) {
13
+ super(mediator, "FrameEmbeddingEventHandler", debugMode);
14
+ }
15
+ /**
16
+ * Initialize the handler and set up event subscriptions
17
+ */
18
+ initialize() {
19
+ // Subscribe to the FRAME_EMBEDDING_DETECTED event
20
+ this.subscribe(ProtectionEventType.FRAME_EMBEDDING_DETECTED, this.handleFrameEmbeddingDetected.bind(this));
21
+ this.log("Initialized and subscribed to frame embedding events");
22
+ }
23
+ /**
24
+ * Handle frame embedding detection event
25
+ * @param event The protection event containing frame embedding data
26
+ */
27
+ handleFrameEmbeddingDetected(event) {
28
+ try {
29
+ const frameEvent = event;
30
+ this.log("Handling frame embedding detected event", frameEvent);
31
+ const data = frameEvent.data;
32
+ if (!data) {
33
+ this.warn("Received invalid frame embedding event data");
34
+ return;
35
+ }
36
+ // Only handle external frames
37
+ if (data.isEmbedded && data.isExternalFrame) {
38
+ this.log(`Applying protection for external frame embedding from ${data.parentDomain || "unknown domain"}`);
39
+ // Show overlay if configured
40
+ if (data.showOverlay) {
41
+ this.mediator.publish({
42
+ type: ProtectionEventType.OVERLAY_SHOWN,
43
+ source: this.COMPONENT_NAME,
44
+ timestamp: Date.now(),
45
+ data: {
46
+ strategyName: this.COMPONENT_NAME,
47
+ overlayType: "frame_embedding",
48
+ options: {
49
+ ...data.overlayOptions,
50
+ blockEvents: true,
51
+ autoRestore: true,
52
+ },
53
+ priority: 9, // High priority for frame embedding
54
+ },
55
+ });
56
+ }
57
+ // Hide content if configured
58
+ if (data.hideContent) {
59
+ this.mediator.publish({
60
+ type: ProtectionEventType.CONTENT_HIDDEN,
61
+ source: this.COMPONENT_NAME,
62
+ timestamp: Date.now(),
63
+ data: {
64
+ strategyName: this.COMPONENT_NAME,
65
+ reason: "frame_embedding",
66
+ targetElement: data.targetElement,
67
+ options: {
68
+ title: data.overlayOptions?.title,
69
+ message: data.overlayOptions?.message,
70
+ secondaryMessage: data.overlayOptions?.secondaryMessage,
71
+ textColor: "black",
72
+ backgroundColor: "rgba(0, 0, 0, 0.05)",
73
+ },
74
+ priority: 9, // High priority for frame embedding
75
+ },
76
+ });
77
+ }
78
+ }
79
+ else {
80
+ this.log("Skipping protection for non-external frame embedding");
81
+ }
82
+ }
83
+ catch (error) {
84
+ this.error("Error handling frame embedding detected event:", error);
85
+ }
86
+ }
87
+ /**
88
+ * Clean up resources when the handler is disposed
89
+ */
90
+ onDispose() {
91
+ // No additional cleanup needed beyond what the base class does
92
+ }
93
+ }
@@ -0,0 +1,9 @@
1
+ import type { ProtectionMediator } from "../types";
2
+ export declare class HandlerRegistry {
3
+ private handlers;
4
+ private mediator;
5
+ private debugMode;
6
+ constructor(mediator: ProtectionMediator, debugMode?: boolean);
7
+ private initializeHandlers;
8
+ setDebugMode(enabled: boolean): void;
9
+ }
@@ -0,0 +1,34 @@
1
+ import { DevToolsEventHandler } from "./devToolsEventHandler";
2
+ import { BrowserExtensionEventHandler } from "./extensionEventHandlers";
3
+ import { FrameEmbeddingEventHandler } from "./iFrameEventHandlers";
4
+ import { ScreenshotEventHandler } from "./screenShotEventHandlers";
5
+ export class HandlerRegistry {
6
+ constructor(mediator, debugMode = false) {
7
+ this.handlers = {};
8
+ this.mediator = mediator;
9
+ this.debugMode = debugMode;
10
+ this.initializeHandlers();
11
+ }
12
+ initializeHandlers() {
13
+ // Initialize all handlers
14
+ this.handlers.devTools = new DevToolsEventHandler(this.mediator, this.debugMode);
15
+ this.handlers.extension = new BrowserExtensionEventHandler(this.mediator, this.debugMode);
16
+ this.handlers.screenshot = new ScreenshotEventHandler(this.mediator, this.debugMode);
17
+ this.handlers.iFrame = new FrameEmbeddingEventHandler(this.mediator, this.debugMode);
18
+ // Add more handlers as you implement them
19
+ // this.handlers.screenshot = new ScreenshotEventHandler(this.mediator, this.debugMode);
20
+ // this.handlers.frameEmbedding = new FrameEmbeddingEventHandler(this.mediator, this.debugMode);
21
+ if (this.debugMode) {
22
+ console.log("HandlerRegistry: Initialized all event handlers");
23
+ }
24
+ }
25
+ setDebugMode(enabled) {
26
+ this.debugMode = enabled;
27
+ // Update debug mode for all handlers
28
+ Object.values(this.handlers).forEach(handler => {
29
+ if (typeof handler.setDebugMode === 'function') {
30
+ handler.setDebugMode(enabled);
31
+ }
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,34 @@
1
+ import type { ProtectionMediator } from "../../mediator/types";
2
+ import { type ProtectionEvent } from "../protection-event";
3
+ import { AbstractEventHandler } from "./abstractEventHandler";
4
+ /**
5
+ * Handler for screenshot detection events
6
+ */
7
+ export declare class ScreenshotEventHandler extends AbstractEventHandler {
8
+ private timeoutManager;
9
+ private activeTimeouts;
10
+ /**
11
+ * Create a new ScreenshotEventHandler
12
+ * @param mediator The protection mediator
13
+ * @param debugMode Enable debug mode for troubleshooting
14
+ */
15
+ constructor(mediator: ProtectionMediator, debugMode?: boolean);
16
+ /**
17
+ * Initialize the handler and subscribe to events
18
+ */
19
+ protected initialize(): void;
20
+ /**
21
+ * Handle screenshot attempt event
22
+ * @param event The protection event
23
+ */
24
+ handleScreenshotAttempt(event: ProtectionEvent): void;
25
+ /**
26
+ * Set debug mode
27
+ * @param enabled Whether debug mode should be enabled
28
+ */
29
+ setDebugMode(enabled: boolean): void;
30
+ /**
31
+ * Additional cleanup to be performed on disposal
32
+ */
33
+ protected onDispose(): void;
34
+ }
@@ -0,0 +1,111 @@
1
+ import { ProtectionEventType } from "../protection-event";
2
+ import { TimeoutManager } from "../../../utils/timeoutManager";
3
+ import { AbstractEventHandler } from "./abstractEventHandler";
4
+ /**
5
+ * Handler for screenshot detection events
6
+ */
7
+ export class ScreenshotEventHandler extends AbstractEventHandler {
8
+ /**
9
+ * Create a new ScreenshotEventHandler
10
+ * @param mediator The protection mediator
11
+ * @param debugMode Enable debug mode for troubleshooting
12
+ */
13
+ constructor(mediator, debugMode = false) {
14
+ super(mediator, "ScreenshotEventHandler", debugMode);
15
+ this.activeTimeouts = new Set(); // Track active timeouts
16
+ this.timeoutManager = TimeoutManager.getInstance();
17
+ this.timeoutManager.setDebugMode(this.debugMode);
18
+ }
19
+ /**
20
+ * Initialize the handler and subscribe to events
21
+ */
22
+ initialize() {
23
+ // Subscribe to the SCREENSHOT_ATTEMPT event
24
+ this.subscribe(ProtectionEventType.SCREENSHOT_ATTEMPT, this.handleScreenshotAttempt.bind(this));
25
+ }
26
+ /**
27
+ * Handle screenshot attempt event
28
+ * @param event The protection event
29
+ */
30
+ handleScreenshotAttempt(event) {
31
+ const screenshotEvent = event;
32
+ this.log("Handling screenshot attempt event", screenshotEvent);
33
+ // Generate a unique ID for this protection instance
34
+ const protectionId = `screenshot_${Date.now()}`;
35
+ if (screenshotEvent.data.showOverlay) {
36
+ this.mediator.publish({
37
+ type: ProtectionEventType.OVERLAY_SHOWN,
38
+ source: screenshotEvent.source,
39
+ timestamp: Date.now(),
40
+ data: {
41
+ strategyName: screenshotEvent.source,
42
+ overlayType: "screenshot",
43
+ options: {
44
+ ...screenshotEvent.data.overlayOptions,
45
+ blockEvents: false, // Don't block events, just show a notification
46
+ autoRestore: true,
47
+ },
48
+ priority: screenshotEvent.data.priority || 5,
49
+ duration: screenshotEvent.data.overlayOptions?.duration || 3000
50
+ },
51
+ });
52
+ }
53
+ if (screenshotEvent.data.hideContent) {
54
+ this.mediator.publish({
55
+ type: ProtectionEventType.CONTENT_HIDDEN,
56
+ source: screenshotEvent.source,
57
+ timestamp: Date.now(),
58
+ data: {
59
+ strategyName: screenshotEvent.source,
60
+ reason: "screenshot_attempt",
61
+ options: {
62
+ title: screenshotEvent.data.overlayOptions?.title,
63
+ message: screenshotEvent.data.overlayOptions?.message,
64
+ secondaryMessage: screenshotEvent.data.overlayOptions?.secondaryMessage,
65
+ textColor: 'black',
66
+ backgroundColor: screenshotEvent.data.overlayOptions?.backgroundColor || "rgba(0, 0, 0, 0.05)",
67
+ },
68
+ targetElement: screenshotEvent.data.target,
69
+ priority: screenshotEvent.data.priority || 5,
70
+ },
71
+ });
72
+ // Create a unique timeout ID for this screenshot event
73
+ const contentTimeoutId = `${protectionId}_content`;
74
+ this.activeTimeouts.add(contentTimeoutId);
75
+ // If duration is specified, set a timeout to restore content
76
+ if (screenshotEvent.data.overlayOptions?.duration) {
77
+ this.timeoutManager.setTimeout(contentTimeoutId, () => {
78
+ this.mediator.publish({
79
+ type: ProtectionEventType.CONTENT_RESTORED,
80
+ source: screenshotEvent.source,
81
+ timestamp: Date.now(),
82
+ data: {
83
+ strategyName: screenshotEvent.source,
84
+ targetElement: screenshotEvent.data.target,
85
+ },
86
+ });
87
+ this.activeTimeouts.delete(contentTimeoutId);
88
+ }, screenshotEvent.data.overlayOptions?.duration);
89
+ this.log(`Set timeout ${contentTimeoutId} to restore content after ${screenshotEvent.data.overlayOptions.duration}s`);
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * Set debug mode
95
+ * @param enabled Whether debug mode should be enabled
96
+ */
97
+ setDebugMode(enabled) {
98
+ super.setDebugMode(enabled);
99
+ this.timeoutManager.setDebugMode(enabled);
100
+ }
101
+ /**
102
+ * Additional cleanup to be performed on disposal
103
+ */
104
+ onDispose() {
105
+ // Clear all active timeouts
106
+ for (const timeoutId of this.activeTimeouts) {
107
+ this.timeoutManager.clearTimeout(timeoutId);
108
+ }
109
+ this.activeTimeouts.clear();
110
+ }
111
+ }
@@ -0,0 +1,94 @@
1
+ import { EventDataMap } from "./eventDataTypes";
2
+ /**
3
+ * Types of protection events that can be published and subscribed to
4
+ */
5
+ export declare enum ProtectionEventType {
6
+ STRATEGY_APPLIED = "strategy:applied",
7
+ STRATEGY_REMOVED = "strategy:removed",
8
+ STRATEGY_UPDATED = "strategy:updated",
9
+ CONTEXT_MENU_ATTEMPT = "interaction:contextmenu",
10
+ SELECTION_ATTEMPT = "interaction:selection",
11
+ DRAG_ATTEMPT = "interaction:drag",
12
+ KEYBOARD_SHORTCUT_BLOCKED = "interaction:keyboard",
13
+ PRINT_ATTEMPT = "protection:print",
14
+ SCREENSHOT_ATTEMPT = "protection:screenshot",
15
+ DEVTOOLS_STATE_CHANGE = "protection:devtools",
16
+ EXTENSION_DETECTED = "protection:extension",
17
+ FRAME_EMBEDDING_DETECTED = "protection:frame",
18
+ FULLSCREEN_CHANGE = "protection:fullscreen",
19
+ WATERMARK_TAMPERED = "protection:watermark_tampered",
20
+ OVERLAY_SHOWN = "overlay:shown",
21
+ OVERLAY_REMOVED = "overlay:removed",
22
+ OVERLAY_RESTORED = "overlay:restored",
23
+ CONTENT_HIDDEN = "content:hidden",
24
+ CONTENT_RESTORED = "content:restored",
25
+ WATERMARK_CREATED = "content:watermark_created",
26
+ WATERMARK_REMOVED = "content:watermark_removed",
27
+ MEDIATOR_INITIALIZED = "mediator:initialized",
28
+ MEDIATOR_DISPOSED = "mediator:disposed",
29
+ ERROR_OCCURRED = "system:error",
30
+ DEBUG_MESSAGE = "system:debug",
31
+ CONFIG_UPDATED = "system:config_updated",
32
+ KEYBOARD_SHORTCUTS_REQUESTED = "keyboard:shortcuts_requested",
33
+ KEYBOARD_SHORTCUTS_PROVIDED = "keyboard:shortcuts_provided",
34
+ KEYBOARD_SHORTCUTS_UPDATED = "keyboard:shortcuts_updated"
35
+ }
36
+ /**
37
+ * Base protection event interface
38
+ */
39
+ export interface ProtectionEvent {
40
+ /**
41
+ * Type of the event
42
+ */
43
+ type: ProtectionEventType;
44
+ /**
45
+ * Source of the event (usually strategy name)
46
+ */
47
+ source: string;
48
+ /**
49
+ * Timestamp when the event occurred
50
+ */
51
+ timestamp: number;
52
+ /**
53
+ * Additional data specific to the event type
54
+ */
55
+ data?: unknown;
56
+ }
57
+ /**
58
+ * Event for DevTools state changes
59
+ */
60
+ export interface DevToolsEvent extends ProtectionEvent {
61
+ type: ProtectionEventType.DEVTOOLS_STATE_CHANGE;
62
+ data: EventDataMap[ProtectionEventType.DEVTOOLS_STATE_CHANGE];
63
+ }
64
+ /**
65
+ * Event for extension detection
66
+ */
67
+ export interface ExtensionEvent extends ProtectionEvent {
68
+ type: ProtectionEventType.EXTENSION_DETECTED;
69
+ data: EventDataMap[ProtectionEventType.EXTENSION_DETECTED];
70
+ }
71
+ /**
72
+ * Event for screenshot detection
73
+ */
74
+ export interface ScreenshotEvent extends ProtectionEvent {
75
+ type: ProtectionEventType.SCREENSHOT_ATTEMPT;
76
+ data: EventDataMap[ProtectionEventType.SCREENSHOT_ATTEMPT];
77
+ }
78
+ /**
79
+ * Event for frame embedding detection
80
+ */
81
+ export interface FrameEmbeddingEvent extends ProtectionEvent {
82
+ type: ProtectionEventType.FRAME_EMBEDDING_DETECTED;
83
+ data: EventDataMap[ProtectionEventType.FRAME_EMBEDDING_DETECTED];
84
+ }
85
+ /**
86
+ * Event for watermark-related events
87
+ */
88
+ export interface WatermarkEvent extends ProtectionEvent {
89
+ data: {
90
+ targetElement?: HTMLElement | null;
91
+ watermarkId?: string;
92
+ [key: string]: unknown;
93
+ };
94
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Types of protection events that can be published and subscribed to
3
+ */
4
+ export var ProtectionEventType;
5
+ (function (ProtectionEventType) {
6
+ // Strategy lifecycle events
7
+ ProtectionEventType["STRATEGY_APPLIED"] = "strategy:applied";
8
+ ProtectionEventType["STRATEGY_REMOVED"] = "strategy:removed";
9
+ ProtectionEventType["STRATEGY_UPDATED"] = "strategy:updated";
10
+ // User interaction events
11
+ ProtectionEventType["CONTEXT_MENU_ATTEMPT"] = "interaction:contextmenu";
12
+ ProtectionEventType["SELECTION_ATTEMPT"] = "interaction:selection";
13
+ ProtectionEventType["DRAG_ATTEMPT"] = "interaction:drag";
14
+ ProtectionEventType["KEYBOARD_SHORTCUT_BLOCKED"] = "interaction:keyboard";
15
+ // Protection events
16
+ ProtectionEventType["PRINT_ATTEMPT"] = "protection:print";
17
+ ProtectionEventType["SCREENSHOT_ATTEMPT"] = "protection:screenshot";
18
+ ProtectionEventType["DEVTOOLS_STATE_CHANGE"] = "protection:devtools";
19
+ ProtectionEventType["EXTENSION_DETECTED"] = "protection:extension";
20
+ ProtectionEventType["FRAME_EMBEDDING_DETECTED"] = "protection:frame";
21
+ ProtectionEventType["FULLSCREEN_CHANGE"] = "protection:fullscreen";
22
+ ProtectionEventType["WATERMARK_TAMPERED"] = "protection:watermark_tampered";
23
+ // Overlay events
24
+ ProtectionEventType["OVERLAY_SHOWN"] = "overlay:shown";
25
+ ProtectionEventType["OVERLAY_REMOVED"] = "overlay:removed";
26
+ ProtectionEventType["OVERLAY_RESTORED"] = "overlay:restored";
27
+ // Content events
28
+ ProtectionEventType["CONTENT_HIDDEN"] = "content:hidden";
29
+ ProtectionEventType["CONTENT_RESTORED"] = "content:restored";
30
+ ProtectionEventType["WATERMARK_CREATED"] = "content:watermark_created";
31
+ ProtectionEventType["WATERMARK_REMOVED"] = "content:watermark_removed";
32
+ // Mediator events
33
+ ProtectionEventType["MEDIATOR_INITIALIZED"] = "mediator:initialized";
34
+ ProtectionEventType["MEDIATOR_DISPOSED"] = "mediator:disposed";
35
+ // System events
36
+ ProtectionEventType["ERROR_OCCURRED"] = "system:error";
37
+ ProtectionEventType["DEBUG_MESSAGE"] = "system:debug";
38
+ ProtectionEventType["CONFIG_UPDATED"] = "system:config_updated";
39
+ // Keyboard
40
+ ProtectionEventType["KEYBOARD_SHORTCUTS_REQUESTED"] = "keyboard:shortcuts_requested";
41
+ ProtectionEventType["KEYBOARD_SHORTCUTS_PROVIDED"] = "keyboard:shortcuts_provided";
42
+ ProtectionEventType["KEYBOARD_SHORTCUTS_UPDATED"] = "keyboard:shortcuts_updated";
43
+ })(ProtectionEventType || (ProtectionEventType = {}));
@@ -0,0 +1,105 @@
1
+ import { EventDataMap } from './eventDataTypes';
2
+ import { ProtectionEvent, ProtectionEventType } from './protection-event';
3
+ /**
4
+ * Event handler function type
5
+ */
6
+ export type ProtectionEventHandler = (event: ProtectionEvent) => void;
7
+ /**
8
+ * Subscription information
9
+ */
10
+ export interface Subscription {
11
+ /**
12
+ * Unique ID for the subscription
13
+ */
14
+ id: string;
15
+ /**
16
+ * Event type being subscribed to
17
+ */
18
+ eventType: ProtectionEventType;
19
+ /**
20
+ * Handler function for the event
21
+ */
22
+ handler: ProtectionEventHandler;
23
+ /**
24
+ * Optional filter function to determine if the handler should be called
25
+ */
26
+ filter?: (event: ProtectionEvent) => boolean;
27
+ /**
28
+ * Optional priority for the handler (higher numbers execute first)
29
+ */
30
+ priority?: number;
31
+ /**
32
+ * Optional context information (e.g., strategy name)
33
+ */
34
+ context?: string;
35
+ }
36
+ /**
37
+ * Subscription options
38
+ */
39
+ export interface SubscriptionOptions {
40
+ /**
41
+ * Optional filter function to determine if the handler should be called
42
+ */
43
+ filter?: (event: ProtectionEvent) => boolean;
44
+ /**
45
+ * Optional priority for the handler (higher numbers execute first)
46
+ */
47
+ priority?: number;
48
+ /**
49
+ * Optional context information (e.g., strategy name)
50
+ */
51
+ context?: string;
52
+ }
53
+ /**
54
+ * Interface for the protection mediator
55
+ */
56
+ export interface ProtectionMediator {
57
+ /**
58
+ * Subscribe to an event
59
+ * @param eventType Type of event to subscribe to
60
+ * @param handler Handler function for the event
61
+ * @param options Optional subscription options
62
+ * @returns Subscription ID for later unsubscribing
63
+ */
64
+ subscribe(eventType: ProtectionEventType, handler: ProtectionEventHandler, options?: SubscriptionOptions): string;
65
+ /**
66
+ * Unsubscribe from an event
67
+ * @param subscriptionId ID of the subscription to remove
68
+ * @returns True if the subscription was found and removed
69
+ */
70
+ unsubscribe(subscriptionId: string): boolean;
71
+ /**
72
+ * Publish an event to all subscribers
73
+ * @param event Event to publish
74
+ */
75
+ publish<T extends ProtectionEventType | string>(event: Omit<ProtectionEvent, "data"> & {
76
+ type: T;
77
+ data?: T extends ProtectionEventType ? EventDataMap[T] : Record<string, unknown>;
78
+ }): void;
79
+ /**
80
+ * Get all subscriptions for a specific event type
81
+ * @param eventType Type of event to get subscriptions for
82
+ * @returns Array of subscriptions
83
+ */
84
+ getSubscriptions(eventType: ProtectionEventType): Subscription[];
85
+ /**
86
+ * Set debug mode
87
+ * @param enabled Whether debug mode should be enabled
88
+ */
89
+ setDebugMode(enabled: boolean): void;
90
+ }
91
+ /**
92
+ * Interface for components that can work with the mediator
93
+ */
94
+ export interface MediatorAware {
95
+ /**
96
+ * Set the mediator for this component
97
+ * @param mediator The protection mediator
98
+ */
99
+ setMediator(mediator: ProtectionMediator): void;
100
+ /**
101
+ * Get the component name
102
+ * Used to identify the component in mediator communications
103
+ */
104
+ readonly COMPONENT_NAME: string;
105
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export { ContentProtector } from './core/index.js';
2
+ export * from './types/index.js';
3
+ export * from './strategies/index.js';
4
+ export * from './utils/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // MAIN ENTRY POINT
2
+ export { ContentProtector } from './core/index.js';
3
+ export * from './types/index.js';
4
+ export * from './strategies/index.js';
5
+ export * from './utils/index.js';