UNPKG

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.

190 lines (187 loc) 7.81 kB
import { FortifiedFunction } from './fortified-function.js'; import '../../core/random/random-types.js'; import '../../core/random/random-sources.js'; import 'crypto'; import 'nehonix-uri-processor'; import '../memory/index.js'; import '../../types.js'; import '../../core/hash/hash-core.js'; import '../../core/hash/hash-types.js'; import 'argon2'; import '../../algorithms/hash-algorithms.js'; import 'child_process'; import '../../types/secure-memory.js'; import 'https'; import '../../security/runtime-verification.js'; import '../../security/tamper-evident-logging.js'; import '../../security/secure-string/advanced/entropy-analyzer.js'; import '../../security/secure-string/advanced/quantum-safe.js'; import '../../security/secure-string/advanced/performance-monitor.js'; import 'nehoid'; import '../../core/password/index.js'; import 'events'; import '../../integrations/express/cache/CacheFactory.js'; import './safe-serializer.js'; import '../../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 = new FortifiedFunction(fn, options); // Create the enhanced function with all methods const enhancedFunc = async (...args) => { return await fortifiedFunction.execute(...args); }; // Add all FortifiedFunction methods to the function for full IntelliSense support Object.assign(enhancedFunc, { // Analytics and monitoring methods getStats: () => fortifiedFunction.getStats(), getAnalyticsData: () => fortifiedFunction.getAnalyticsData(), getOptimizationSuggestions: () => fortifiedFunction.getOptimizationSuggestions(), getPerformanceTrends: () => fortifiedFunction.getPerformanceTrends(), detectAnomalies: () => fortifiedFunction.detectAnomalies(), getDetailedMetrics: () => fortifiedFunction.getDetailedMetrics(), // Cache management methods clearCache: () => fortifiedFunction.clearCache(), getCacheStats: () => { const stats = fortifiedFunction.getStats(); const cacheStats = fortifiedFunction.getCacheStats(); return { hits: stats.cacheHits, misses: stats.cacheMisses, size: cacheStats.size || 0, }; }, warmCache: async (args) => { for (const argSet of args) { await fortifiedFunction.execute(...argSet); } }, // Smart actions handleMemoryPressure: (level) => fortifiedFunction.handleMemoryPressure(level), optimizePerformance: () => { // Trigger cache warming and optimization fortifiedFunction.warmCache(); const suggestions = fortifiedFunction.getOptimizationSuggestions(); // Auto-apply high priority suggestions suggestions .filter((s) => s.priority === "high" || s.priority === "critical") .forEach(() => fortifiedFunction.warmCache()); }, // Configuration methods updateOptions: (newOptions) => { fortifiedFunction.updateOptions(newOptions); }, getConfiguration: () => ({ ...options }), // Performance timing methods startTimer: (label, metadata) => fortifiedFunction.startTimer(label, metadata), endTimer: (label, additionalMetadata) => fortifiedFunction.endTimer(label, additionalMetadata), measureDelay: (startPoint, endPoint) => fortifiedFunction.measureDelay(startPoint, endPoint), timeFunction: (label, fn, metadata) => fortifiedFunction.timeFunction(label, fn, metadata), getTimingStats: () => fortifiedFunction.getTimingStats(), clearTimings: () => fortifiedFunction.clearTimings(), // Lifecycle methods destroy: () => fortifiedFunction.destroy(), // Internal FortifiedFunction instance (for advanced usage) _fortified: fortifiedFunction, }); 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(fn, options); } export { FortifiedFunction, createFortifiedFunction, func as default, func }; //# sourceMappingURL=index.js.map