bbbeba4e57b3b2e792c7c808821a42c024551fadbba15c76b7b603c6f4daed24.json raw
1 {"ast":null,"code":"import _asyncToGenerator from \"/home/mleku/src/orly.dev/next/signer/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport { v4 as uuidv4 } from 'uuid';\n/**\n * Handler for extension settings stored outside the encrypted vault.\n * This includes sync preferences, backups, reckless mode, whitelisted hosts, etc.\n */\nexport class SignerMetaHandler {\n get extensionSettings() {\n return this.#extensionSettings;\n }\n /** @deprecated Use extensionSettings instead */\n get signerMetaData() {\n return this.#extensionSettings;\n }\n #extensionSettings;\n metaProperties = ['syncFlow', 'vaultSnapshots', 'maxBackups', 'recklessMode', 'whitelistedHosts', 'bookmarks', 'devMode'];\n DEFAULT_MAX_BACKUPS = 5;\n setFullData(data) {\n this.#extensionSettings = data;\n }\n /**\n * Sets the sync flow preference for the user and immediately saves it.\n */\n setSyncFlow(flow) {\n var _this = this;\n return _asyncToGenerator(function* () {\n if (!_this.#extensionSettings) {\n _this.#extensionSettings = {\n syncFlow: flow\n };\n } else {\n _this.#extensionSettings.syncFlow = flow;\n }\n yield _this.saveFullData(_this.#extensionSettings);\n })();\n }\n /** @deprecated Use setSyncFlow instead */\n setBrowserSyncFlow(flow) {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n return _this2.setSyncFlow(flow);\n })();\n }\n /**\n * Sets the reckless mode and immediately saves it.\n */\n setRecklessMode(enabled) {\n var _this3 = this;\n return _asyncToGenerator(function* () {\n if (!_this3.#extensionSettings) {\n _this3.#extensionSettings = {\n recklessMode: enabled\n };\n } else {\n _this3.#extensionSettings.recklessMode = enabled;\n }\n yield _this3.saveFullData(_this3.#extensionSettings);\n })();\n }\n /**\n * Sets dev mode and immediately saves it.\n */\n setDevMode(enabled) {\n var _this4 = this;\n return _asyncToGenerator(function* () {\n if (!_this4.#extensionSettings) {\n _this4.#extensionSettings = {\n devMode: enabled\n };\n } else {\n _this4.#extensionSettings.devMode = enabled;\n }\n yield _this4.saveFullData(_this4.#extensionSettings);\n })();\n }\n /**\n * Adds a host to the whitelist and immediately saves it.\n */\n addWhitelistedHost(host) {\n var _this5 = this;\n return _asyncToGenerator(function* () {\n if (!_this5.#extensionSettings) {\n _this5.#extensionSettings = {\n whitelistedHosts: [host]\n };\n } else {\n const hosts = _this5.#extensionSettings.whitelistedHosts ?? [];\n if (!hosts.includes(host)) {\n hosts.push(host);\n _this5.#extensionSettings.whitelistedHosts = hosts;\n }\n }\n yield _this5.saveFullData(_this5.#extensionSettings);\n })();\n }\n /**\n * Removes a host from the whitelist and immediately saves it.\n */\n removeWhitelistedHost(host) {\n var _this6 = this;\n return _asyncToGenerator(function* () {\n if (!_this6.#extensionSettings?.whitelistedHosts) {\n return;\n }\n _this6.#extensionSettings.whitelistedHosts = _this6.#extensionSettings.whitelistedHosts.filter(h => h !== host);\n yield _this6.saveFullData(_this6.#extensionSettings);\n })();\n }\n /**\n * Sets the bookmarks array and immediately saves it.\n */\n setBookmarks(bookmarks) {\n var _this7 = this;\n return _asyncToGenerator(function* () {\n if (!_this7.#extensionSettings) {\n _this7.#extensionSettings = {\n bookmarks\n };\n } else {\n _this7.#extensionSettings.bookmarks = bookmarks;\n }\n yield _this7.saveFullData(_this7.#extensionSettings);\n })();\n }\n /**\n * Gets the current bookmarks.\n */\n getBookmarks() {\n return this.#extensionSettings?.bookmarks ?? [];\n }\n /**\n * Gets the maximum number of backups to keep.\n */\n getMaxBackups() {\n return this.#extensionSettings?.maxBackups ?? this.DEFAULT_MAX_BACKUPS;\n }\n /**\n * Sets the maximum number of backups to keep and immediately saves it.\n */\n setMaxBackups(count) {\n var _this8 = this;\n return _asyncToGenerator(function* () {\n const clampedCount = Math.max(1, Math.min(20, count)); // Clamp between 1-20\n if (!_this8.#extensionSettings) {\n _this8.#extensionSettings = {\n maxBackups: clampedCount\n };\n } else {\n _this8.#extensionSettings.maxBackups = clampedCount;\n }\n yield _this8.saveFullData(_this8.#extensionSettings);\n })();\n }\n /**\n * Gets all vault backups, sorted newest first.\n */\n getBackups() {\n const backups = this.#extensionSettings?.vaultSnapshots ?? [];\n return [...backups].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());\n }\n /**\n * Gets a specific backup by ID.\n */\n getBackupById(id) {\n return this.#extensionSettings?.vaultSnapshots?.find(b => b.id === id);\n }\n /**\n * Creates a new backup of the vault data.\n * Automatically removes old backups if exceeding maxBackups.\n */\n createBackup(_x) {\n var _this9 = this;\n return _asyncToGenerator(function* (encryptedVault, reason = 'manual') {\n const now = new Date();\n const dateTimeString = now.toISOString().replace(/[:.]/g, '-').slice(0, 19);\n const identityCount = encryptedVault.identities?.length ?? 0;\n const snapshot = {\n id: uuidv4(),\n fileName: `Vault Backup - ${dateTimeString}`,\n createdAt: now.toISOString(),\n data: JSON.parse(JSON.stringify(encryptedVault)),\n // Deep clone\n identityCount,\n reason\n };\n if (!_this9.#extensionSettings) {\n _this9.#extensionSettings = {\n vaultSnapshots: [snapshot]\n };\n } else {\n const existingBackups = _this9.#extensionSettings.vaultSnapshots ?? [];\n existingBackups.push(snapshot);\n // Enforce max backups limit (only for auto backups, keep manual and pre-restore)\n const maxBackups = _this9.getMaxBackups();\n const autoBackups = existingBackups.filter(b => b.reason === 'auto');\n const otherBackups = existingBackups.filter(b => b.reason !== 'auto');\n // Sort auto backups by date (newest first) and keep only maxBackups\n autoBackups.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());\n const trimmedAutoBackups = autoBackups.slice(0, maxBackups);\n _this9.#extensionSettings.vaultSnapshots = [...otherBackups, ...trimmedAutoBackups];\n }\n yield _this9.saveFullData(_this9.#extensionSettings);\n return snapshot;\n }).apply(this, arguments);\n }\n /**\n * Deletes a backup by ID.\n */\n deleteBackup(backupId) {\n var _this0 = this;\n return _asyncToGenerator(function* () {\n if (!_this0.#extensionSettings?.vaultSnapshots) {\n return false;\n }\n const initialLength = _this0.#extensionSettings.vaultSnapshots.length;\n _this0.#extensionSettings.vaultSnapshots = _this0.#extensionSettings.vaultSnapshots.filter(b => b.id !== backupId);\n if (_this0.#extensionSettings.vaultSnapshots.length < initialLength) {\n yield _this0.saveFullData(_this0.#extensionSettings);\n return true;\n }\n return false;\n })();\n }\n /**\n * Gets the data from a backup for restoration.\n * Note: The caller should create a pre-restore backup before calling this.\n */\n getBackupData(backupId) {\n const backup = this.getBackupById(backupId);\n return backup?.data;\n }\n}","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}