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,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages timeouts for the content protection toolkit
|
|
3
|
+
* Provides a centralized way to create, track, and clear timeouts
|
|
4
|
+
*/
|
|
5
|
+
export declare class TimeoutManager {
|
|
6
|
+
private static instance;
|
|
7
|
+
private timeouts;
|
|
8
|
+
private logger;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new TimeoutManager
|
|
11
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
12
|
+
*/
|
|
13
|
+
private constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Get the TimeoutManager instance (singleton)
|
|
16
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
17
|
+
*/
|
|
18
|
+
static getInstance(debugMode?: boolean): TimeoutManager;
|
|
19
|
+
/**
|
|
20
|
+
* Set a timeout with a unique ID
|
|
21
|
+
* @param id Unique identifier for the timeout
|
|
22
|
+
* @param callback Function to execute
|
|
23
|
+
* @param delay Delay in milliseconds
|
|
24
|
+
* @returns The timeout ID for later reference
|
|
25
|
+
*/
|
|
26
|
+
setTimeout(id: string, callback: () => void, delay: number): string;
|
|
27
|
+
/**
|
|
28
|
+
* Clear a timeout by ID
|
|
29
|
+
* @param id Timeout ID to clear
|
|
30
|
+
* @returns True if the timeout was found and cleared
|
|
31
|
+
*/
|
|
32
|
+
clearTimeout(id: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Clear all timeouts
|
|
35
|
+
* @returns Number of timeouts cleared
|
|
36
|
+
*/
|
|
37
|
+
clearAllTimeouts(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a timeout exists
|
|
40
|
+
* @param id Timeout ID to check
|
|
41
|
+
* @returns True if the timeout exists
|
|
42
|
+
*/
|
|
43
|
+
hasTimeout(id: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get the number of active timeouts
|
|
46
|
+
* @returns Number of active timeouts
|
|
47
|
+
*/
|
|
48
|
+
getTimeoutCount(): number;
|
|
49
|
+
/**
|
|
50
|
+
* Set debug mode
|
|
51
|
+
* @param enabled Whether debug mode should be enabled
|
|
52
|
+
*/
|
|
53
|
+
setDebugMode(enabled: boolean): void;
|
|
54
|
+
}
|
|
55
|
+
export declare const timeoutManager: TimeoutManager;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { isBrowser } from "./environment";
|
|
2
|
+
import { SimpleLoggingService } from "./logging/simple/SimpleLoggingService";
|
|
3
|
+
/**
|
|
4
|
+
* Manages timeouts for the content protection toolkit
|
|
5
|
+
* Provides a centralized way to create, track, and clear timeouts
|
|
6
|
+
*/
|
|
7
|
+
export class TimeoutManager {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new TimeoutManager
|
|
10
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
11
|
+
*/
|
|
12
|
+
constructor(debugMode = false) {
|
|
13
|
+
this.timeouts = new Map();
|
|
14
|
+
this.logger = new SimpleLoggingService("TimeoutManager", debugMode);
|
|
15
|
+
this.logger.log("Initialized");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the TimeoutManager instance (singleton)
|
|
19
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
20
|
+
*/
|
|
21
|
+
static getInstance(debugMode = false) {
|
|
22
|
+
if (!TimeoutManager.instance) {
|
|
23
|
+
TimeoutManager.instance = new TimeoutManager(debugMode);
|
|
24
|
+
}
|
|
25
|
+
// Update debug mode if it's explicitly passed
|
|
26
|
+
if (arguments.length > 0) {
|
|
27
|
+
TimeoutManager.instance.setDebugMode(debugMode);
|
|
28
|
+
}
|
|
29
|
+
return TimeoutManager.instance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set a timeout with a unique ID
|
|
33
|
+
* @param id Unique identifier for the timeout
|
|
34
|
+
* @param callback Function to execute
|
|
35
|
+
* @param delay Delay in milliseconds
|
|
36
|
+
* @returns The timeout ID for later reference
|
|
37
|
+
*/
|
|
38
|
+
setTimeout(id, callback, delay) {
|
|
39
|
+
if (!isBrowser())
|
|
40
|
+
return id;
|
|
41
|
+
// Clear any existing timeout with this ID
|
|
42
|
+
this.clearTimeout(id);
|
|
43
|
+
// Create a new timeout
|
|
44
|
+
const timeoutId = window.setTimeout(() => {
|
|
45
|
+
// Remove from our map when it executes
|
|
46
|
+
this.timeouts.delete(id);
|
|
47
|
+
// Execute the callback
|
|
48
|
+
try {
|
|
49
|
+
callback();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.logger.error(`Error executing timeout "${id}":`, error);
|
|
53
|
+
}
|
|
54
|
+
}, delay);
|
|
55
|
+
// Store in our map
|
|
56
|
+
this.timeouts.set(id, timeoutId);
|
|
57
|
+
this.logger.log(`Set timeout "${id}" with delay ${delay}ms`);
|
|
58
|
+
return id;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Clear a timeout by ID
|
|
62
|
+
* @param id Timeout ID to clear
|
|
63
|
+
* @returns True if the timeout was found and cleared
|
|
64
|
+
*/
|
|
65
|
+
clearTimeout(id) {
|
|
66
|
+
if (!isBrowser())
|
|
67
|
+
return false;
|
|
68
|
+
const timeoutId = this.timeouts.get(id);
|
|
69
|
+
if (timeoutId !== undefined) {
|
|
70
|
+
window.clearTimeout(timeoutId);
|
|
71
|
+
this.timeouts.delete(id);
|
|
72
|
+
this.logger.log(`Cleared timeout "${id}"`);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Clear all timeouts
|
|
79
|
+
* @returns Number of timeouts cleared
|
|
80
|
+
*/
|
|
81
|
+
clearAllTimeouts() {
|
|
82
|
+
if (!isBrowser())
|
|
83
|
+
return 0;
|
|
84
|
+
let count = 0;
|
|
85
|
+
this.timeouts.forEach((timeoutId, _id) => {
|
|
86
|
+
window.clearTimeout(timeoutId);
|
|
87
|
+
count++;
|
|
88
|
+
});
|
|
89
|
+
this.timeouts.clear();
|
|
90
|
+
if (count > 0) {
|
|
91
|
+
this.logger.log(`Cleared all ${count} timeouts`);
|
|
92
|
+
}
|
|
93
|
+
return count;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if a timeout exists
|
|
97
|
+
* @param id Timeout ID to check
|
|
98
|
+
* @returns True if the timeout exists
|
|
99
|
+
*/
|
|
100
|
+
hasTimeout(id) {
|
|
101
|
+
return this.timeouts.has(id);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the number of active timeouts
|
|
105
|
+
* @returns Number of active timeouts
|
|
106
|
+
*/
|
|
107
|
+
getTimeoutCount() {
|
|
108
|
+
return this.timeouts.size;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set debug mode
|
|
112
|
+
* @param enabled Whether debug mode should be enabled
|
|
113
|
+
*/
|
|
114
|
+
setDebugMode(enabled) {
|
|
115
|
+
this.logger.setDebugMode(enabled);
|
|
116
|
+
this.logger.log(`Debug mode ${enabled ? "enabled" : "disabled"}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
TimeoutManager.instance = null;
|
|
120
|
+
// Create a singleton instance for use throughout the application
|
|
121
|
+
export const timeoutManager = TimeoutManager.getInstance(false);
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "content-security-toolkit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
13
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
14
|
+
"format": "prettier --write 'src/**/*.ts'",
|
|
15
|
+
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
16
|
+
"prepare": "npm run build",
|
|
17
|
+
"examples:install": "cd examples && npm install",
|
|
18
|
+
"examples:build": "npm run build && npm run examples:install",
|
|
19
|
+
"examples:start": "cd examples && npm run start"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"security",
|
|
23
|
+
"content-protection",
|
|
24
|
+
"drm",
|
|
25
|
+
"web-security"
|
|
26
|
+
],
|
|
27
|
+
"author": "Iker Laforga",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/Isonimus/content-security-toolkit.git"
|
|
32
|
+
},
|
|
33
|
+
"description": "Lightweight TypeScript toolkit to protect web content: blocks copying/printing, detects devtools/screenshots, adds watermarks, and provides extensible strategies and detectors.",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@eslint/js": "^9.22.0",
|
|
36
|
+
"@types/jest": "^29.5.14",
|
|
37
|
+
"@types/node": "^22.13.10",
|
|
38
|
+
"eslint": "^9.22.0",
|
|
39
|
+
"eslint-config-prettier": "^10.1.1",
|
|
40
|
+
"jest": "^29.7.0",
|
|
41
|
+
"prettier": "^3.5.3",
|
|
42
|
+
"ts-jest": "^29.2.6",
|
|
43
|
+
"typescript": "^5.8.2",
|
|
44
|
+
"typescript-eslint": "^8.27.0"
|
|
45
|
+
},
|
|
46
|
+
"eslintConfig": {
|
|
47
|
+
"files": [
|
|
48
|
+
"eslint.config.js"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"jest-environment-jsdom": "^29.7.0"
|
|
53
|
+
}
|
|
54
|
+
}
|