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.
- package/LICENSE +9 -0
- package/README.md +171 -0
- package/dist/config/default-extensions-config.json +103 -0
- package/dist/core/ContentProtector.d.ts +63 -0
- package/dist/core/ContentProtector.js +279 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/mediator/ContentProtectionMediator.d.ts +86 -0
- package/dist/core/mediator/ContentProtectionMediator.js +238 -0
- package/dist/core/mediator/eventDataTypes.d.ts +205 -0
- package/dist/core/mediator/eventDataTypes.js +23 -0
- package/dist/core/mediator/handlers/abstractEventHandler.d.ts +67 -0
- package/dist/core/mediator/handlers/abstractEventHandler.js +106 -0
- package/dist/core/mediator/handlers/baseEventHandler.d.ts +65 -0
- package/dist/core/mediator/handlers/baseEventHandler.js +99 -0
- package/dist/core/mediator/handlers/devToolsEventHandler.d.ts +9 -0
- package/dist/core/mediator/handlers/devToolsEventHandler.js +95 -0
- package/dist/core/mediator/handlers/eventHandlerRegistry.d.ts +9 -0
- package/dist/core/mediator/handlers/eventHandlerRegistry.js +34 -0
- package/dist/core/mediator/handlers/extensionEventHandlers.d.ts +40 -0
- package/dist/core/mediator/handlers/extensionEventHandlers.js +140 -0
- package/dist/core/mediator/handlers/iFrameEventHandlers.d.ts +27 -0
- package/dist/core/mediator/handlers/iFrameEventHandlers.js +93 -0
- package/dist/core/mediator/handlers/index.d.ts +9 -0
- package/dist/core/mediator/handlers/index.js +34 -0
- package/dist/core/mediator/handlers/screenShotEventHandlers.d.ts +34 -0
- package/dist/core/mediator/handlers/screenShotEventHandlers.js +111 -0
- package/dist/core/mediator/protection-event.d.ts +94 -0
- package/dist/core/mediator/protection-event.js +43 -0
- package/dist/core/mediator/types.d.ts +105 -0
- package/dist/core/mediator/types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/strategies/AbstractStrategy.d.ts +152 -0
- package/dist/strategies/AbstractStrategy.js +296 -0
- package/dist/strategies/AbstractStrategy.mediator.d.ts +162 -0
- package/dist/strategies/AbstractStrategy.mediator.js +349 -0
- package/dist/strategies/ClipboardStrategy.d.ts +67 -0
- package/dist/strategies/ClipboardStrategy.js +291 -0
- package/dist/strategies/ContextMenuStrategy.d.ts +60 -0
- package/dist/strategies/ContextMenuStrategy.js +454 -0
- package/dist/strategies/DevToolsStrategy copy.d.ts +85 -0
- package/dist/strategies/DevToolsStrategy copy.js +362 -0
- package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +70 -0
- package/dist/strategies/DevToolsStrategy-detectorManager.js +309 -0
- package/dist/strategies/DevToolsStrategy-simple.d.ts +75 -0
- package/dist/strategies/DevToolsStrategy-simple.js +366 -0
- package/dist/strategies/DevToolsStrategy.d.ts +55 -0
- package/dist/strategies/DevToolsStrategy.js +314 -0
- package/dist/strategies/ExtensionStrategy.d.ts +66 -0
- package/dist/strategies/ExtensionStrategy.js +486 -0
- package/dist/strategies/IFrameStrategy.d.ts +49 -0
- package/dist/strategies/IFrameStrategy.js +255 -0
- package/dist/strategies/KeyboardStrategy.d.ts +35 -0
- package/dist/strategies/KeyboardStrategy.js +130 -0
- package/dist/strategies/PrintStrategy.d.ts +47 -0
- package/dist/strategies/PrintStrategy.js +201 -0
- package/dist/strategies/ScreenshotStrategy.d.ts +90 -0
- package/dist/strategies/ScreenshotStrategy.js +488 -0
- package/dist/strategies/SelectionStrategy.d.ts +49 -0
- package/dist/strategies/SelectionStrategy.js +216 -0
- package/dist/strategies/StrategyRegistry.d.ts +133 -0
- package/dist/strategies/StrategyRegistry.js +379 -0
- package/dist/strategies/WatermarkStrategy.d.ts +47 -0
- package/dist/strategies/WatermarkStrategy.js +273 -0
- package/dist/strategies/index.d.ts +9 -0
- package/dist/strategies/index.js +10 -0
- package/dist/types/index.d.ts +271 -0
- package/dist/types/index.js +16 -0
- package/dist/utils/DOMObserver.d.ts +68 -0
- package/dist/utils/DOMObserver.js +134 -0
- package/dist/utils/base/LoggableComponent.d.ts +62 -0
- package/dist/utils/base/LoggableComponent.js +95 -0
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +6 -0
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +24 -0
- package/dist/utils/debuggerDetector/debuggerDetector.d.ts +55 -0
- package/dist/utils/debuggerDetector/debuggerDetector.js +158 -0
- package/dist/utils/debuggerDetector/firefoxDetector.d.ts +8 -0
- package/dist/utils/debuggerDetector/firefoxDetector.js +64 -0
- package/dist/utils/detection.d.ts +29 -0
- package/dist/utils/detection.js +267 -0
- package/dist/utils/detectors/AbstractDevToolsDetector.d.ts +105 -0
- package/dist/utils/detectors/AbstractDevToolsDetector.js +136 -0
- package/dist/utils/detectors/dateToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/dateToStringDetector.js +96 -0
- package/dist/utils/detectors/debugLibDetector.d.ts +64 -0
- package/dist/utils/detectors/debugLibDetector.js +195 -0
- package/dist/utils/detectors/debuggerDetectionWorker.d.ts +6 -0
- package/dist/utils/detectors/debuggerDetectionWorker.js +24 -0
- package/dist/utils/detectors/debuggerDetector.d.ts +51 -0
- package/dist/utils/detectors/debuggerDetector.js +211 -0
- package/dist/utils/detectors/defineGetterDetector.d.ts +48 -0
- package/dist/utils/detectors/defineGetterDetector.js +150 -0
- package/dist/utils/detectors/detectorInterface.d.ts +36 -0
- package/dist/utils/detectors/detectorInterface.js +1 -0
- package/dist/utils/detectors/devToolsDetectorManager.d.ts +88 -0
- package/dist/utils/detectors/devToolsDetectorManager.js +246 -0
- package/dist/utils/detectors/firefoxDetector.d.ts +8 -0
- package/dist/utils/detectors/firefoxDetector.js +64 -0
- package/dist/utils/detectors/funcToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/funcToStringDetector.js +90 -0
- package/dist/utils/detectors/regToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/regToStringDetector.js +129 -0
- package/dist/utils/detectors/sizeDetector.d.ts +54 -0
- package/dist/utils/detectors/sizeDetector.js +134 -0
- package/dist/utils/detectors/timingDetector.d.ts +55 -0
- package/dist/utils/detectors/timingDetector.js +143 -0
- package/dist/utils/dom.d.ts +20 -0
- package/dist/utils/dom.js +83 -0
- package/dist/utils/environment.d.ts +29 -0
- package/dist/utils/environment.js +267 -0
- package/dist/utils/eventManager.d.ts +167 -0
- package/dist/utils/eventManager.js +556 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/intervalManager.d.ts +96 -0
- package/dist/utils/intervalManager.js +229 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.d.ts +41 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.js +135 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcuts.d.ts +18 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcuts.js +195 -0
- package/dist/utils/logging/LogLevel.d.ts +21 -0
- package/dist/utils/logging/LogLevel.js +46 -0
- package/dist/utils/logging/LoggingConfig.d.ts +68 -0
- package/dist/utils/logging/LoggingConfig.js +64 -0
- package/dist/utils/logging/LoggingFactory.d.ts +22 -0
- package/dist/utils/logging/LoggingFactory.js +61 -0
- package/dist/utils/logging/LoggingService.d.ts +235 -0
- package/dist/utils/logging/LoggingService.js +385 -0
- package/dist/utils/logging/SimpleLoggingService.d.ts +39 -0
- package/dist/utils/logging/SimpleLoggingService.js +58 -0
- package/dist/utils/logging/advanced/LogLevel.d.ts +21 -0
- package/dist/utils/logging/advanced/LogLevel.js +46 -0
- package/dist/utils/logging/advanced/LoggingConfig.d.ts +68 -0
- package/dist/utils/logging/advanced/LoggingConfig.js +64 -0
- package/dist/utils/logging/advanced/LoggingFactory.d.ts +22 -0
- package/dist/utils/logging/advanced/LoggingFactory.js +61 -0
- package/dist/utils/logging/advanced/LoggingService.d.ts +235 -0
- package/dist/utils/logging/advanced/LoggingService.js +385 -0
- package/dist/utils/logging/simple/Loggable.d.ts +33 -0
- package/dist/utils/logging/simple/Loggable.js +1 -0
- package/dist/utils/logging/simple/LoggingDelegate.d.ts +42 -0
- package/dist/utils/logging/simple/LoggingDelegate.js +53 -0
- package/dist/utils/logging/simple/SimpleLoggingService.d.ts +39 -0
- package/dist/utils/logging/simple/SimpleLoggingService.js +58 -0
- package/dist/utils/orientation.d.ts +15 -0
- package/dist/utils/orientation.js +32 -0
- package/dist/utils/protectedContentManager-simple.d.ts +86 -0
- package/dist/utils/protectedContentManager-simple.js +180 -0
- package/dist/utils/protectedContentManager.d.ts +162 -0
- package/dist/utils/protectedContentManager.js +427 -0
- package/dist/utils/screenshotDetector.d.ts +72 -0
- package/dist/utils/screenshotDetector.js +179 -0
- package/dist/utils/securityOverlayManager-observer-pause.d.ts +283 -0
- package/dist/utils/securityOverlayManager-observer-pause.js +878 -0
- package/dist/utils/securityOverlayManager-simple.d.ts +197 -0
- package/dist/utils/securityOverlayManager-simple.js +552 -0
- package/dist/utils/securityOverlayManager.d.ts +260 -0
- package/dist/utils/securityOverlayManager.js +774 -0
- package/dist/utils/timeoutManager.d.ts +55 -0
- package/dist/utils/timeoutManager.js +121 -0
- package/package.json +54 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { isBrowser, isMobile } from "../utils/environment";
|
|
2
|
+
import { AbstractStrategy, StrategyErrorType } from "./AbstractStrategy";
|
|
3
|
+
/**
|
|
4
|
+
* Strategy for preventing text selection
|
|
5
|
+
*/
|
|
6
|
+
export class SelectionStrategy extends AbstractStrategy {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new SelectionStrategy
|
|
9
|
+
* @param targetElement Element to protect (defaults to document.body)
|
|
10
|
+
* @param customHandler Optional custom handler for selection attempts
|
|
11
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
12
|
+
*/
|
|
13
|
+
constructor(targetElement, customHandler, debugMode = false) {
|
|
14
|
+
super("SelectionStrategy", debugMode);
|
|
15
|
+
this.targetElement = null;
|
|
16
|
+
this.styleElement = null;
|
|
17
|
+
this.preventDrag = true;
|
|
18
|
+
this.targetElement = targetElement || (isBrowser() ? document.body : null);
|
|
19
|
+
this.customHandler = customHandler;
|
|
20
|
+
this.selectionHandler = this.handleSelection.bind(this);
|
|
21
|
+
this.dragHandler = this.handleDrag.bind(this);
|
|
22
|
+
this.log("Initialized with target:", this.targetElement === document.body ? "document.body" : "custom element");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Handle selection event
|
|
26
|
+
*/
|
|
27
|
+
handleSelection(e) {
|
|
28
|
+
return (this.safeExecute("handleSelection", StrategyErrorType.EVENT_HANDLING, () => {
|
|
29
|
+
this.log("Selection attempt detected", {
|
|
30
|
+
eventType: e.type,
|
|
31
|
+
target: e.target,
|
|
32
|
+
});
|
|
33
|
+
// Call custom handler if provided
|
|
34
|
+
if (this.customHandler) {
|
|
35
|
+
this.customHandler(e);
|
|
36
|
+
}
|
|
37
|
+
if (isBrowser() && window.getSelection) {
|
|
38
|
+
const selection = window.getSelection();
|
|
39
|
+
if (selection) {
|
|
40
|
+
selection.removeAllRanges();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
e.stopPropagation();
|
|
45
|
+
return false;
|
|
46
|
+
}) || false);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Handle drag event
|
|
50
|
+
*/
|
|
51
|
+
handleDrag(e) {
|
|
52
|
+
this.safeExecute("handleDrag", StrategyErrorType.EVENT_HANDLING, () => {
|
|
53
|
+
this.log("Drag attempt detected", {
|
|
54
|
+
eventType: e.type,
|
|
55
|
+
target: e.target,
|
|
56
|
+
});
|
|
57
|
+
// Call custom handler if provided
|
|
58
|
+
if (this.customHandler) {
|
|
59
|
+
this.customHandler(e);
|
|
60
|
+
}
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
e.stopPropagation();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Inject CSS to prevent selection
|
|
67
|
+
*/
|
|
68
|
+
injectSelectionStyles() {
|
|
69
|
+
this.safeExecute("injectSelectionStyles", StrategyErrorType.APPLICATION, () => {
|
|
70
|
+
if (!isBrowser())
|
|
71
|
+
return;
|
|
72
|
+
this.styleElement = document.createElement("style");
|
|
73
|
+
this.styleElement.setAttribute("type", "text/css");
|
|
74
|
+
this.styleElement.setAttribute("data-content-security", "selection-blocker");
|
|
75
|
+
const selector = this.targetElement === document.body ? "body" : ".protected-content";
|
|
76
|
+
const css = `
|
|
77
|
+
${selector} {
|
|
78
|
+
-webkit-user-select: none;
|
|
79
|
+
-moz-user-select: none;
|
|
80
|
+
-ms-user-select: none;
|
|
81
|
+
user-select: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
${selector} ::selection {
|
|
85
|
+
background: transparent;
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
this.styleElement.textContent = css;
|
|
89
|
+
document.head.appendChild(this.styleElement);
|
|
90
|
+
// Add class if not targeting body
|
|
91
|
+
if (this.targetElement !== document.body) {
|
|
92
|
+
this.targetElement?.classList.add("protected-content");
|
|
93
|
+
}
|
|
94
|
+
this.log("Selection-blocking CSS injected");
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Remove selection-blocking CSS
|
|
99
|
+
*/
|
|
100
|
+
removeSelectionStyles() {
|
|
101
|
+
this.safeExecute("removeSelectionStyles", StrategyErrorType.REMOVAL, () => {
|
|
102
|
+
if (!this.styleElement || !isBrowser())
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
document.head.removeChild(this.styleElement);
|
|
106
|
+
this.styleElement = null;
|
|
107
|
+
// Remove class if not targeting body
|
|
108
|
+
if (this.targetElement !== document.body) {
|
|
109
|
+
this.targetElement?.classList.remove("protected-content");
|
|
110
|
+
}
|
|
111
|
+
this.log("Selection-blocking CSS removed");
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.handleError(StrategyErrorType.REMOVAL, "Error removing selection styles", error);
|
|
115
|
+
// Try to find and remove by selector as fallback
|
|
116
|
+
try {
|
|
117
|
+
const styles = document.querySelectorAll('style[data-content-security="selection-blocker"]');
|
|
118
|
+
styles.forEach((style) => {
|
|
119
|
+
if (style.parentNode) {
|
|
120
|
+
style.parentNode.removeChild(style);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
this.styleElement = null;
|
|
124
|
+
if (styles.length > 0) {
|
|
125
|
+
this.log(`Removed ${styles.length} selection-blocking styles by selector`);
|
|
126
|
+
}
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
128
|
+
}
|
|
129
|
+
catch (fallbackError) {
|
|
130
|
+
// Last resort fallback
|
|
131
|
+
this.styleElement = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Apply selection protection
|
|
138
|
+
*/
|
|
139
|
+
apply() {
|
|
140
|
+
this.safeExecute("apply", StrategyErrorType.APPLICATION, () => {
|
|
141
|
+
if (this.isAppliedFlag || !this.targetElement)
|
|
142
|
+
return;
|
|
143
|
+
this.log("Applying selection protection", {
|
|
144
|
+
targetElement: this.targetElement === document.body ? "document.body" : "custom element",
|
|
145
|
+
hasCustomHandler: !!this.customHandler,
|
|
146
|
+
preventDrag: this.preventDrag,
|
|
147
|
+
isMobile: isMobile(),
|
|
148
|
+
});
|
|
149
|
+
// Add CSS
|
|
150
|
+
this.injectSelectionStyles();
|
|
151
|
+
// Add event listeners using the registerEvent method from AbstractStrategy
|
|
152
|
+
this.registerEvent(this.targetElement, "selectstart", this.selectionHandler);
|
|
153
|
+
this.registerEvent(this.targetElement, "mousedown", this.selectionHandler, { capture: true });
|
|
154
|
+
// Disable drag
|
|
155
|
+
if (this.preventDrag) {
|
|
156
|
+
this.registerEvent(this.targetElement, "dragstart", this.dragHandler);
|
|
157
|
+
}
|
|
158
|
+
this.isAppliedFlag = true;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Remove selection protection
|
|
163
|
+
*/
|
|
164
|
+
remove() {
|
|
165
|
+
this.safeExecute("remove", StrategyErrorType.REMOVAL, () => {
|
|
166
|
+
if (!this.isAppliedFlag || !this.targetElement)
|
|
167
|
+
return;
|
|
168
|
+
// Remove CSS
|
|
169
|
+
this.removeSelectionStyles();
|
|
170
|
+
// Remove all events for this owner using the parent class method
|
|
171
|
+
this.removeEventsByOwner();
|
|
172
|
+
// Second attempt - try direct DOM removal as fallback
|
|
173
|
+
try {
|
|
174
|
+
if (this.targetElement) {
|
|
175
|
+
this.targetElement.removeEventListener("selectstart", this.selectionHandler);
|
|
176
|
+
this.targetElement.removeEventListener("mousedown", this.selectionHandler, { capture: true });
|
|
177
|
+
this.targetElement.removeEventListener("dragstart", this.dragHandler);
|
|
178
|
+
this.log("Removed events via direct DOM API");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (domError) {
|
|
182
|
+
// Ignore errors in direct DOM removal
|
|
183
|
+
this.handleError(StrategyErrorType.REMOVAL, "Error in fallback DOM removal", domError);
|
|
184
|
+
}
|
|
185
|
+
// Clear tracked event IDs
|
|
186
|
+
this.eventIds = [];
|
|
187
|
+
this.isAppliedFlag = false;
|
|
188
|
+
this.log("Selection protection removed");
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Update selection protection options
|
|
193
|
+
* @param options New options for selection protection
|
|
194
|
+
*/
|
|
195
|
+
updateOptions(options) {
|
|
196
|
+
this.safeExecute("updateOptions", StrategyErrorType.OPTION_UPDATE, () => {
|
|
197
|
+
this.log("Updating options", options);
|
|
198
|
+
// Update debug mode if specified
|
|
199
|
+
if (options.debugMode !== undefined) {
|
|
200
|
+
this.setDebugMode(!!options.debugMode);
|
|
201
|
+
}
|
|
202
|
+
// Update preventDrag if specified
|
|
203
|
+
if (options.preventDrag !== undefined) {
|
|
204
|
+
const oldPreventDrag = this.preventDrag;
|
|
205
|
+
this.preventDrag = !!options.preventDrag;
|
|
206
|
+
// If we need to update the applied strategy
|
|
207
|
+
if (this.isAppliedFlag && oldPreventDrag !== this.preventDrag) {
|
|
208
|
+
// Remove and reapply to update event listeners
|
|
209
|
+
this.remove();
|
|
210
|
+
this.apply();
|
|
211
|
+
this.log("Reapplied with updated options");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ProtectionStrategy } from "../types";
|
|
2
|
+
import type { MediatorAware, ProtectionMediator } from "../core/mediator/types";
|
|
3
|
+
/**
|
|
4
|
+
* Error types for strategy operations
|
|
5
|
+
*/
|
|
6
|
+
export declare enum StrategyErrorType {
|
|
7
|
+
REGISTRATION_ERROR = "registration_error",
|
|
8
|
+
UNREGISTRATION_ERROR = "unregistration_error",
|
|
9
|
+
APPLICATION_ERROR = "application_error",
|
|
10
|
+
REMOVAL_ERROR = "removal_error",
|
|
11
|
+
INVALID_STRATEGY = "invalid_strategy",
|
|
12
|
+
STRATEGY_NOT_FOUND = "strategy_not_found",
|
|
13
|
+
STRATEGY_ALREADY_REGISTERED = "strategy_already_registered"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Custom error class for strategy registry operations
|
|
17
|
+
*/
|
|
18
|
+
export declare class StrategyRegistryError extends Error {
|
|
19
|
+
readonly errorType: StrategyErrorType;
|
|
20
|
+
readonly strategyId?: string | undefined;
|
|
21
|
+
readonly originalError?: Error | undefined;
|
|
22
|
+
constructor(errorType: StrategyErrorType, message: string, strategyId?: string | undefined, originalError?: Error | undefined);
|
|
23
|
+
}
|
|
24
|
+
export interface StrategyRegistryOptions {
|
|
25
|
+
debugMode?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Registry for managing protection strategies
|
|
29
|
+
* Provides centralized access and lifecycle management
|
|
30
|
+
*/
|
|
31
|
+
export declare class StrategyRegistry implements MediatorAware {
|
|
32
|
+
readonly COMPONENT_NAME = "StrategyRegistry";
|
|
33
|
+
private strategies;
|
|
34
|
+
private logger;
|
|
35
|
+
private mediator;
|
|
36
|
+
constructor(options?: StrategyRegistryOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Set the mediator to communicate with other components
|
|
39
|
+
* @param mediator The protection mediator
|
|
40
|
+
*/
|
|
41
|
+
setMediator(mediator: ProtectionMediator): void;
|
|
42
|
+
/**
|
|
43
|
+
* Register a strategy with the registry
|
|
44
|
+
* @param id Unique identifier for the strategy
|
|
45
|
+
* @param strategy Strategy instance
|
|
46
|
+
* @returns True if registration was successful
|
|
47
|
+
* @throws StrategyRegistryError if registration fails
|
|
48
|
+
*/
|
|
49
|
+
register(id: string, strategy: ProtectionStrategy): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Unregister a strategy from the registry
|
|
52
|
+
* @param id Strategy ID to unregister
|
|
53
|
+
* @returns True if unregistration was successful
|
|
54
|
+
* @throws StrategyRegistryError if unregistration fails
|
|
55
|
+
*/
|
|
56
|
+
unregister(id: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Get a strategy by ID
|
|
59
|
+
* @param id Strategy ID
|
|
60
|
+
* @returns The strategy instance or undefined if not found
|
|
61
|
+
*/
|
|
62
|
+
getStrategy(id: string): ProtectionStrategy | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a strategy is registered
|
|
65
|
+
* @param id Strategy ID
|
|
66
|
+
* @returns True if the strategy is registered
|
|
67
|
+
*/
|
|
68
|
+
hasStrategy(id: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Apply a specific strategy
|
|
71
|
+
* @param id Strategy ID to apply
|
|
72
|
+
* @returns True if the strategy was applied successfully
|
|
73
|
+
* @throws StrategyRegistryError if application fails
|
|
74
|
+
*/
|
|
75
|
+
applyStrategy(id: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Apply all registered strategies
|
|
78
|
+
* @returns Array of strategy IDs that failed to apply
|
|
79
|
+
*/
|
|
80
|
+
applyAllStrategies(): string[];
|
|
81
|
+
/**
|
|
82
|
+
* Remove a specific strategy
|
|
83
|
+
* @param id Strategy ID to remove
|
|
84
|
+
* @returns True if removal was successful
|
|
85
|
+
* @throws StrategyRegistryError if removal fails
|
|
86
|
+
*/
|
|
87
|
+
removeStrategy(id: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Remove all registered strategies
|
|
90
|
+
* @returns Array of strategy IDs that failed to remove
|
|
91
|
+
*/
|
|
92
|
+
removeAllStrategies(): string[];
|
|
93
|
+
/**
|
|
94
|
+
* Get all registered strategy IDs
|
|
95
|
+
* @returns Array of strategy IDs
|
|
96
|
+
*/
|
|
97
|
+
getStrategyIds(): string[];
|
|
98
|
+
/**
|
|
99
|
+
* Get all registered strategies
|
|
100
|
+
* @returns Map of strategy IDs to strategy instances
|
|
101
|
+
*/
|
|
102
|
+
getAllStrategies(): Map<string, ProtectionStrategy>;
|
|
103
|
+
/**
|
|
104
|
+
* Get all applied strategies
|
|
105
|
+
* @returns Array of strategy IDs that are currently applied
|
|
106
|
+
*/
|
|
107
|
+
getAppliedStrategies(): string[];
|
|
108
|
+
/**
|
|
109
|
+
* Set debug mode for all strategies that support it
|
|
110
|
+
* @param enabled Whether debug mode should be enabled
|
|
111
|
+
*/
|
|
112
|
+
setDebugMode(enabled: boolean): void;
|
|
113
|
+
/**
|
|
114
|
+
* Clear the registry (remove all strategies first)
|
|
115
|
+
*/
|
|
116
|
+
clear(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Publish a strategy applied event through the mediator
|
|
119
|
+
* @param strategyId ID of the strategy that was applied
|
|
120
|
+
*/
|
|
121
|
+
private publishStrategyAppliedEvent;
|
|
122
|
+
/**
|
|
123
|
+
* Publish a strategy removed event through the mediator
|
|
124
|
+
* @param strategyId ID of the strategy that was removed
|
|
125
|
+
*/
|
|
126
|
+
private publishStrategyRemovedEvent;
|
|
127
|
+
/**
|
|
128
|
+
* Publish an error event through the mediator
|
|
129
|
+
* @param strategyId ID of the strategy that had an error
|
|
130
|
+
* @param error The error that occurred
|
|
131
|
+
*/
|
|
132
|
+
private publishErrorEvent;
|
|
133
|
+
}
|