fortify2-js
Version:
MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.
194 lines (190 loc) • 8.02 kB
JavaScript
;
var fortifiedFunction = require('./fortified-function.js');
require('../../core/random/random-types.js');
require('../../core/random/random-sources.js');
require('crypto');
require('nehonix-uri-processor');
require('../memory/index.js');
require('../../types.js');
require('../../core/hash/hash-core.js');
require('../../core/hash/hash-types.js');
require('argon2');
require('../../algorithms/hash-algorithms.js');
require('child_process');
require('../../types/secure-memory.js');
require('https');
require('../../security/runtime-verification.js');
require('../../security/tamper-evident-logging.js');
require('../../security/secure-string/advanced/entropy-analyzer.js');
require('../../security/secure-string/advanced/quantum-safe.js');
require('../../security/secure-string/advanced/performance-monitor.js');
require('nehoid');
require('../../core/password/index.js');
require('events');
require('../../integrations/express/cache/CacheFactory.js');
require('../../security/secure-array/utils/id-generator.js');
/***************************************************************************
* FortifyJS - Secure Array Types
*
* This file contains type definitions for the SecureArrayarchitecture
*
* @author Nehonix
* @license MIT
*
* Copyright (c) 2025 Nehonix. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************** */
// Export main class
/**
* Zero-Configuration Smart Function Factory
*
* Creates fortified functions with enterprise-grade security,
* performance optimization, and intelligent caching enabled by default.
* No manual configuration required for optimal performance.
*
* @param fn - The function to be fortified with smart capabilities
* @param options - Optional configuration overrides (all features enabled by default)
* @returns A fortified function with enhanced security and performance features
*
* @example
* ```typescript
* import { func } from 'fortify2-js';
*
* // Zero configuration needed - all smart features enabled by default
* const smartFunction = func(async (data: string) => {
* return processData(data);
* });
*
* // Execute with automatic optimization
* const result = await smartFunction('sensitive data');
*
* // Optional: Override specific settings if needed
* const customFunction = func(myFunction, {
* maxCacheSize: 5000,
* debugMode: true
* });
* ```
*/
function func(fn, options = {}) {
// Zero-config smart defaults - no manual configuration needed!
// All best practices are enabled by default for performance
const fortifiedFunction$1 = new fortifiedFunction.FortifiedFunction(fn, options);
// Create the enhanced function with all methods
const enhancedFunc = async (...args) => {
return await fortifiedFunction$1.execute(...args);
};
// Add all FortifiedFunction methods to the function for full IntelliSense support
Object.assign(enhancedFunc, {
// Analytics and monitoring methods
getStats: () => fortifiedFunction$1.getStats(),
getAnalyticsData: () => fortifiedFunction$1.getAnalyticsData(),
getOptimizationSuggestions: () => fortifiedFunction$1.getOptimizationSuggestions(),
getPerformanceTrends: () => fortifiedFunction$1.getPerformanceTrends(),
detectAnomalies: () => fortifiedFunction$1.detectAnomalies(),
getDetailedMetrics: () => fortifiedFunction$1.getDetailedMetrics(),
// Cache management methods
clearCache: () => fortifiedFunction$1.clearCache(),
getCacheStats: () => {
const stats = fortifiedFunction$1.getStats();
const cacheStats = fortifiedFunction$1.getCacheStats();
return {
hits: stats.cacheHits,
misses: stats.cacheMisses,
size: cacheStats.size || 0,
};
},
warmCache: async (args) => {
for (const argSet of args) {
await fortifiedFunction$1.execute(...argSet);
}
},
// Smart actions
handleMemoryPressure: (level) => fortifiedFunction$1.handleMemoryPressure(level),
optimizePerformance: () => {
// Trigger cache warming and optimization
fortifiedFunction$1.warmCache();
const suggestions = fortifiedFunction$1.getOptimizationSuggestions();
// Auto-apply high priority suggestions
suggestions
.filter((s) => s.priority === "high" || s.priority === "critical")
.forEach(() => fortifiedFunction$1.warmCache());
},
// Configuration methods
updateOptions: (newOptions) => {
fortifiedFunction$1.updateOptions(newOptions);
},
getConfiguration: () => ({ ...options }),
// Performance timing methods
startTimer: (label, metadata) => fortifiedFunction$1.startTimer(label, metadata),
endTimer: (label, additionalMetadata) => fortifiedFunction$1.endTimer(label, additionalMetadata),
measureDelay: (startPoint, endPoint) => fortifiedFunction$1.measureDelay(startPoint, endPoint),
timeFunction: (label, fn, metadata) => fortifiedFunction$1.timeFunction(label, fn, metadata),
getTimingStats: () => fortifiedFunction$1.getTimingStats(),
clearTimings: () => fortifiedFunction$1.clearTimings(),
// Lifecycle methods
destroy: () => fortifiedFunction$1.destroy(),
// Internal FortifiedFunction instance (for advanced usage)
_fortified: fortifiedFunction$1,
});
return enhancedFunc;
}
/**
* Create a fortified function with full access to smart analytics and optimization
* Provides complete access to performance metrics, analytics, and optimization features
*
* @example
* ```typescript
* import { createFortifiedFunction } from 'fortify2-js';
*
* const fortified = createFortifiedFunction(myFunction, {
* autoEncrypt: true,
* smartCaching: true,
* predictiveAnalytics: true,
* detailedMetrics: true
* });
*
* // Execute
* const result = await fortified.execute('data');
*
* // Access enhanced analytics
* const analytics = fortified.getAnalyticsData();
* const suggestions = fortified.getOptimizationSuggestions();
* const trends = fortified.getPerformanceTrends();
* const anomalies = fortified.detectAnomalies();
*
* // Smart actions
* fortified.warmCache();
* fortified.handleMemoryPressure('medium');
*
* // Get comprehensive metrics
* const detailedMetrics = fortified.getDetailedMetrics();
*
* // Clean up when done
* fortified.destroy();
* ```
*/
function createFortifiedFunction(fn, options = {}) {
return new fortifiedFunction.FortifiedFunction(fn, options);
}
exports.FortifiedFunction = fortifiedFunction.FortifiedFunction;
exports.createFortifiedFunction = createFortifiedFunction;
exports.default = func;
exports.func = func;
//# sourceMappingURL=index.js.map