{"ast":null,"code":"import _asyncToGenerator from \"/home/mleku/src/orly.dev/next/signer/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport * as i0 from \"@angular/core\";\nconst LOGS_STORAGE_KEY = 'extensionLogs';\nexport let LoggerService = /*#__PURE__*/(() => {\n  class LoggerService {\n    #namespace;\n    #logs = [];\n    #maxLogs = 500;\n    get logs() {\n      return this.#logs;\n    }\n    initialize(namespace) {\n      var _this = this;\n      return _asyncToGenerator(function* () {\n        _this.#namespace = namespace;\n        yield _this.#loadLogsFromStorage();\n      })();\n    }\n    #loadLogsFromStorage() {\n      var _this2 = this;\n      return _asyncToGenerator(function* () {\n        try {\n          if (typeof chrome !== 'undefined' && chrome.storage?.session) {\n            const result = yield chrome.storage.session.get(LOGS_STORAGE_KEY);\n            if (result[LOGS_STORAGE_KEY]) {\n              // Convert stored format back to LogEntry with Date objects\n              _this2.#logs = result[LOGS_STORAGE_KEY].map(entry => ({\n                ...entry,\n                timestamp: new Date(entry.timestamp)\n              }));\n            }\n          }\n        } catch (error) {\n          console.error('Failed to load logs from storage:', error);\n        }\n      })();\n    }\n    #saveLogsToStorage() {\n      var _this3 = this;\n      return _asyncToGenerator(function* () {\n        try {\n          if (typeof chrome !== 'undefined' && chrome.storage?.session) {\n            // Convert Date to ISO string for storage\n            const storedLogs = _this3.#logs.map(entry => ({\n              ...entry,\n              timestamp: entry.timestamp.toISOString()\n            }));\n            yield chrome.storage.session.set({\n              [LOGS_STORAGE_KEY]: storedLogs\n            });\n          }\n        } catch (error) {\n          console.error('Failed to save logs to storage:', error);\n        }\n      })();\n    }\n    refreshLogs() {\n      var _this4 = this;\n      return _asyncToGenerator(function* () {\n        yield _this4.#loadLogsFromStorage();\n      })();\n    }\n    // ============================================\n    // Generic logging methods\n    // ============================================\n    log(value, data) {\n      this.#assureInitialized();\n      this.#addLog('log', 'system', '📝', value, data);\n      this.#consoleLog('log', value);\n    }\n    warn(value, data) {\n      this.#assureInitialized();\n      this.#addLog('warn', 'system', '⚠️', value, data);\n      this.#consoleLog('warn', value);\n    }\n    error(value, data) {\n      this.#assureInitialized();\n      this.#addLog('error', 'system', '❌', value, data);\n      this.#consoleLog('error', value);\n    }\n    debug(value, data) {\n      this.#assureInitialized();\n      this.#addLog('debug', 'system', '🔍', value, data);\n      this.#consoleLog('debug', value);\n    }\n    // ============================================\n    // NIP-07 Action Logging\n    // ============================================\n    logNip07Action(method, host, approved, autoApproved, details) {\n      this.#assureInitialized();\n      const approvalType = autoApproved ? 'auto-approved' : approved ? 'approved' : 'denied';\n      const icon = approved ? '✅' : '🚫';\n      let message = `${method} from ${host} - ${approvalType}`;\n      if (details?.kind !== undefined) {\n        message += ` (kind: ${details.kind})`;\n      }\n      this.#addLog('log', 'nip07', icon, message, {\n        method,\n        host,\n        approved,\n        autoApproved,\n        ...details\n      });\n      this.#consoleLog('log', message);\n    }\n    logNip07GetPublicKey(host, approved, autoApproved) {\n      this.logNip07Action('getPublicKey', host, approved, autoApproved);\n    }\n    logNip07SignEvent(host, kind, approved, autoApproved) {\n      this.logNip07Action('signEvent', host, approved, autoApproved, {\n        kind\n      });\n    }\n    logNip07Encrypt(method, host, approved, autoApproved, peerPubkey) {\n      this.logNip07Action(method, host, approved, autoApproved, {\n        peerPubkey\n      });\n    }\n    logNip07Decrypt(method, host, approved, autoApproved, peerPubkey) {\n      this.logNip07Action(method, host, approved, autoApproved, {\n        peerPubkey\n      });\n    }\n    logNip07GetRelays(host, approved, autoApproved) {\n      this.logNip07Action('getRelays', host, approved, autoApproved);\n    }\n    // ============================================\n    // Permission Logging\n    // ============================================\n    logPermissionStored(host, method, policy, kind) {\n      this.#assureInitialized();\n      const icon = policy === 'allow' ? '🔓' : '🔒';\n      let message = `Permission stored: ${method} for ${host} - ${policy}`;\n      if (kind !== undefined) {\n        message += ` (kind: ${kind})`;\n      }\n      this.#addLog('log', 'permission', icon, message, {\n        host,\n        method,\n        policy,\n        kind\n      });\n      this.#consoleLog('log', message);\n    }\n    logPermissionDeleted(host, method, kind) {\n      this.#assureInitialized();\n      let message = `Permission deleted: ${method} for ${host}`;\n      if (kind !== undefined) {\n        message += ` (kind: ${kind})`;\n      }\n      this.#addLog('log', 'permission', '🗑️', message, {\n        host,\n        method,\n        kind\n      });\n      this.#consoleLog('log', message);\n    }\n    // ============================================\n    // Vault Operations Logging\n    // ============================================\n    logVaultUnlock() {\n      this.#assureInitialized();\n      this.#addLog('log', 'vault', '🔓', 'Vault unlocked', undefined);\n      this.#consoleLog('log', 'Vault unlocked');\n    }\n    logVaultLock() {\n      this.#assureInitialized();\n      this.#addLog('log', 'vault', '🔒', 'Vault locked', undefined);\n      this.#consoleLog('log', 'Vault locked');\n    }\n    logVaultCreated() {\n      this.#assureInitialized();\n      this.#addLog('log', 'vault', '🆕', 'Vault created', undefined);\n      this.#consoleLog('log', 'Vault created');\n    }\n    logVaultExport(fileName) {\n      this.#assureInitialized();\n      this.#addLog('log', 'vault', '📤', `Vault exported: ${fileName}`, {\n        fileName\n      });\n      this.#consoleLog('log', `Vault exported: ${fileName}`);\n    }\n    logVaultImport(fileName) {\n      this.#assureInitialized();\n      this.#addLog('log', 'vault', '📥', `Vault imported: ${fileName}`, {\n        fileName\n      });\n      this.#consoleLog('log', `Vault imported: ${fileName}`);\n    }\n    logVaultReset() {\n      this.#assureInitialized();\n      this.#addLog('warn', 'vault', '🗑️', 'Extension reset', undefined);\n      this.#consoleLog('warn', 'Extension reset');\n    }\n    // ============================================\n    // Profile Operations Logging\n    // ============================================\n    logProfileFetchError(pubkey, error) {\n      this.#assureInitialized();\n      const shortPubkey = pubkey.substring(0, 8) + '...';\n      this.#addLog('error', 'profile', '👤', `Failed to fetch profile for ${shortPubkey}: ${error}`, {\n        pubkey,\n        error\n      });\n      this.#consoleLog('error', `Failed to fetch profile for ${shortPubkey}: ${error}`);\n    }\n    logProfileParseError(pubkey) {\n      this.#assureInitialized();\n      const shortPubkey = pubkey.substring(0, 8) + '...';\n      this.#addLog('error', 'profile', '👤', `Failed to parse profile content for ${shortPubkey}`, {\n        pubkey\n      });\n      this.#consoleLog('error', `Failed to parse profile content for ${shortPubkey}`);\n    }\n    logNip05ValidationError(nip05, error) {\n      this.#assureInitialized();\n      this.#addLog('error', 'profile', '🔗', `NIP-05 validation failed for ${nip05}: ${error}`, {\n        nip05,\n        error\n      });\n      this.#consoleLog('error', `NIP-05 validation failed for ${nip05}: ${error}`);\n    }\n    logNip05ValidationSuccess(nip05, pubkey) {\n      this.#assureInitialized();\n      const shortPubkey = pubkey.substring(0, 8) + '...';\n      this.#addLog('log', 'profile', '✓', `NIP-05 verified: ${nip05} → ${shortPubkey}`, {\n        nip05,\n        pubkey\n      });\n      this.#consoleLog('log', `NIP-05 verified: ${nip05} → ${shortPubkey}`);\n    }\n    logProfileEdit(identityNick, field) {\n      this.#assureInitialized();\n      this.#addLog('log', 'profile', '✏️', `Profile edited: ${identityNick} - ${field}`, {\n        identityNick,\n        field\n      });\n      this.#consoleLog('log', `Profile edited: ${identityNick} - ${field}`);\n    }\n    logIdentityCreated(nick) {\n      this.#assureInitialized();\n      this.#addLog('log', 'profile', '🆕', `Identity created: ${nick}`, {\n        nick\n      });\n      this.#consoleLog('log', `Identity created: ${nick}`);\n    }\n    logIdentityDeleted(nick) {\n      this.#assureInitialized();\n      this.#addLog('warn', 'profile', '🗑️', `Identity deleted: ${nick}`, {\n        nick\n      });\n      this.#consoleLog('warn', `Identity deleted: ${nick}`);\n    }\n    logIdentitySelected(nick) {\n      this.#assureInitialized();\n      this.#addLog('log', 'profile', '👆', `Identity selected: ${nick}`, {\n        nick\n      });\n      this.#consoleLog('log', `Identity selected: ${nick}`);\n    }\n    // ============================================\n    // Bookmark Operations Logging\n    // ============================================\n    logBookmarkAdded(url, title) {\n      this.#assureInitialized();\n      this.#addLog('log', 'bookmark', '🔖', `Bookmark added: ${title}`, {\n        url,\n        title\n      });\n      this.#consoleLog('log', `Bookmark added: ${title}`);\n    }\n    logBookmarkRemoved(url, title) {\n      this.#assureInitialized();\n      this.#addLog('log', 'bookmark', '🗑️', `Bookmark removed: ${title}`, {\n        url,\n        title\n      });\n      this.#consoleLog('log', `Bookmark removed: ${title}`);\n    }\n    // ============================================\n    // System/Error Logging\n    // ============================================\n    logRelayFetchError(identityNick, error) {\n      this.#assureInitialized();\n      this.#addLog('error', 'system', '📡', `Failed to fetch relays for ${identityNick}: ${error}`, {\n        identityNick,\n        error\n      });\n      this.#consoleLog('error', `Failed to fetch relays for ${identityNick}: ${error}`);\n    }\n    logStorageError(operation, error) {\n      this.#assureInitialized();\n      this.#addLog('error', 'system', '💾', `Storage error (${operation}): ${error}`, {\n        operation,\n        error\n      });\n      this.#consoleLog('error', `Storage error (${operation}): ${error}`);\n    }\n    logCryptoError(operation, error) {\n      this.#assureInitialized();\n      this.#addLog('error', 'system', '🔐', `Crypto error (${operation}): ${error}`, {\n        operation,\n        error\n      });\n      this.#consoleLog('error', `Crypto error (${operation}): ${error}`);\n    }\n    // ============================================\n    // Internal methods\n    // ============================================\n    clear() {\n      var _this5 = this;\n      return _asyncToGenerator(function* () {\n        _this5.#logs = [];\n        yield _this5.#saveLogsToStorage();\n      })();\n    }\n    #addLog(level, category, icon, message, data) {\n      const entry = {\n        timestamp: new Date(),\n        level,\n        category,\n        icon,\n        message: typeof message === 'string' ? message : JSON.stringify(message),\n        data\n      };\n      this.#logs.unshift(entry);\n      // Limit stored logs\n      if (this.#logs.length > this.#maxLogs) {\n        this.#logs.pop();\n      }\n      // Save to storage asynchronously (don't block)\n      this.#saveLogsToStorage();\n    }\n    #consoleLog(level, message) {\n      const nowString = new Date().toLocaleString();\n      const formattedMsg = `[${this.#namespace} - ${nowString}] ${message}`;\n      switch (level) {\n        case 'warn':\n          console.warn(formattedMsg);\n          break;\n        case 'error':\n          console.error(formattedMsg);\n          break;\n        case 'debug':\n          console.debug(formattedMsg);\n          break;\n        default:\n          console.log(formattedMsg);\n      }\n    }\n    #assureInitialized() {\n      if (!this.#namespace) {\n        throw new Error('LoggerService not initialized. Please call initialize(..) first.');\n      }\n    }\n    static ɵfac = function LoggerService_Factory(__ngFactoryType__) {\n      return new (__ngFactoryType__ || LoggerService)();\n    };\n    static ɵprov = /*@__PURE__*/i0.ɵɵdefineInjectable({\n      token: LoggerService,\n      factory: LoggerService.ɵfac,\n      providedIn: 'root'\n    });\n  }\n  return LoggerService;\n})();\n// ============================================\n// Standalone functions for background script\n// (Background script runs in different context without Angular DI)\n// ============================================\nexport function backgroundLog(_x, _x2, _x3, _x4, _x5) {\n  return _backgroundLog.apply(this, arguments);\n}\nfunction _backgroundLog() {\n  _backgroundLog = _asyncToGenerator(function* (category, icon, level, message, data) {\n    try {\n      if (typeof chrome === 'undefined' || !chrome.storage?.session) {\n        console.log(`[Background] ${message}`);\n        return;\n      }\n      const result = yield chrome.storage.session.get(LOGS_STORAGE_KEY);\n      const existingLogs = result[LOGS_STORAGE_KEY] || [];\n      const newEntry = {\n        timestamp: new Date().toISOString(),\n        level,\n        category,\n        icon,\n        message,\n        data\n      };\n      const updatedLogs = [newEntry, ...existingLogs].slice(0, 500);\n      yield chrome.storage.session.set({\n        [LOGS_STORAGE_KEY]: updatedLogs\n      });\n    } catch (error) {\n      console.error('Failed to add background log:', error);\n    }\n  });\n  return _backgroundLog.apply(this, arguments);\n}\nexport function backgroundLogNip07Action(_x6, _x7, _x8, _x9, _x0) {\n  return _backgroundLogNip07Action.apply(this, arguments);\n}\nfunction _backgroundLogNip07Action() {\n  _backgroundLogNip07Action = _asyncToGenerator(function* (method, host, approved, autoApproved, details) {\n    const approvalType = autoApproved ? 'auto-approved' : approved ? 'approved' : 'denied';\n    const icon = approved ? '✅' : '🚫';\n    let message = `${method} from ${host} - ${approvalType}`;\n    if (details?.kind !== undefined) {\n      message += ` (kind: ${details.kind})`;\n    }\n    yield backgroundLog('nip07', icon, 'log', message, {\n      method,\n      host,\n      approved,\n      autoApproved,\n      ...details\n    });\n  });\n  return _backgroundLogNip07Action.apply(this, arguments);\n}\nexport function backgroundLogPermissionStored(_x1, _x10, _x11, _x12) {\n  return _backgroundLogPermissionStored.apply(this, arguments);\n}\nfunction _backgroundLogPermissionStored() {\n  _backgroundLogPermissionStored = _asyncToGenerator(function* (host, method, policy, kind) {\n    const icon = policy === 'allow' ? '🔓' : '🔒';\n    let message = `Permission stored: ${method} for ${host} - ${policy}`;\n    if (kind !== undefined) {\n      message += ` (kind: ${kind})`;\n    }\n    yield backgroundLog('permission', icon, 'log', message, {\n      host,\n      method,\n      policy,\n      kind\n    });\n  });\n  return _backgroundLogPermissionStored.apply(this, arguments);\n}","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}