@vrtmrz/livesync-commonlib 0.1.0-rc.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 +21 -0
- package/README.md +49 -0
- package/dist/API/DirectFileManipulator.d.ts +2 -0
- package/dist/API/DirectFileManipulator.js +4 -0
- package/dist/API/DirectFileManipulatorV2.d.ts +150 -0
- package/dist/API/DirectFileManipulatorV2.js +424 -0
- package/dist/API/processSetting.d.ts +41 -0
- package/dist/API/processSetting.js +140 -0
- package/dist/ContentSplitter/ContentSplitter.d.ts +28 -0
- package/dist/ContentSplitter/ContentSplitter.js +5 -0
- package/dist/ContentSplitter/ContentSplitterBase.d.ts +51 -0
- package/dist/ContentSplitter/ContentSplitterBase.js +83 -0
- package/dist/ContentSplitter/ContentSplitterRabinKarp.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterRabinKarp.js +32 -0
- package/dist/ContentSplitter/ContentSplitterV1.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterV1.js +34 -0
- package/dist/ContentSplitter/ContentSplitterV2.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterV2.js +34 -0
- package/dist/ContentSplitter/ContentSplitters.d.ts +12 -0
- package/dist/ContentSplitter/ContentSplitters.js +29 -0
- package/dist/bureau/bureau.d.ts +7 -0
- package/dist/bureau/bureau.js +5 -0
- package/dist/common/ConnectionString.d.ts +30 -0
- package/dist/common/ConnectionString.js +179 -0
- package/dist/common/LSError.d.ts +48 -0
- package/dist/common/LSError.js +112 -0
- package/dist/common/configForDoc.d.ts +79 -0
- package/dist/common/configForDoc.js +312 -0
- package/dist/common/coreEnvFunctions.d.ts +21 -0
- package/dist/common/coreEnvFunctions.js +22 -0
- package/dist/common/coreEnvVars.d.ts +3 -0
- package/dist/common/coreEnvVars.js +6 -0
- package/dist/common/i18n.d.ts +18 -0
- package/dist/common/i18n.js +7193 -0
- package/dist/common/logger.d.ts +2 -0
- package/dist/common/logger.js +1 -0
- package/dist/common/messages/combinedMessages.dev.d.ts +7 -0
- package/dist/common/messages/combinedMessages.dev.js +44 -0
- package/dist/common/messages/combinedMessages.prod.d.ts +9264 -0
- package/dist/common/messages/combinedMessages.prod.js +9271 -0
- package/dist/common/messages/de.d.ts +297 -0
- package/dist/common/messages/de.js +7 -0
- package/dist/common/messages/def.d.ts +1119 -0
- package/dist/common/messages/def.js +7 -0
- package/dist/common/messages/es.d.ts +689 -0
- package/dist/common/messages/es.js +7 -0
- package/dist/common/messages/fr.d.ts +582 -0
- package/dist/common/messages/fr.js +7 -0
- package/dist/common/messages/he.d.ts +583 -0
- package/dist/common/messages/he.js +7 -0
- package/dist/common/messages/ja.d.ts +838 -0
- package/dist/common/messages/ja.js +7 -0
- package/dist/common/messages/ko.d.ts +800 -0
- package/dist/common/messages/ko.js +7 -0
- package/dist/common/messages/ru.d.ts +858 -0
- package/dist/common/messages/ru.js +7 -0
- package/dist/common/messages/zh-tw.d.ts +384 -0
- package/dist/common/messages/zh-tw.js +7 -0
- package/dist/common/messages/zh.d.ts +1093 -0
- package/dist/common/messages/zh.js +7 -0
- package/dist/common/messagesJson/de.json +295 -0
- package/dist/common/messagesJson/en.json +1117 -0
- package/dist/common/messagesJson/es.json +687 -0
- package/dist/common/messagesJson/fr.json +580 -0
- package/dist/common/messagesJson/he.json +581 -0
- package/dist/common/messagesJson/ja.json +836 -0
- package/dist/common/messagesJson/ko.json +798 -0
- package/dist/common/messagesJson/ru.json +856 -0
- package/dist/common/messagesJson/zh-tw.json +382 -0
- package/dist/common/messagesJson/zh.json +1091 -0
- package/dist/common/models/auth.type.d.ts +41 -0
- package/dist/common/models/auth.type.js +0 -0
- package/dist/common/models/db.const.d.ts +20 -0
- package/dist/common/models/db.const.js +28 -0
- package/dist/common/models/db.definition.d.ts +56 -0
- package/dist/common/models/db.definition.js +6 -0
- package/dist/common/models/db.type.d.ts +142 -0
- package/dist/common/models/db.type.js +0 -0
- package/dist/common/models/diff.definition.d.ts +16 -0
- package/dist/common/models/diff.definition.js +0 -0
- package/dist/common/models/fileaccess.const.d.ts +7 -0
- package/dist/common/models/fileaccess.const.js +16 -0
- package/dist/common/models/fileaccess.type.d.ts +72 -0
- package/dist/common/models/fileaccess.type.js +0 -0
- package/dist/common/models/redflag.const.d.ts +32 -0
- package/dist/common/models/redflag.const.js +27 -0
- package/dist/common/models/setting.const.d.ts +49 -0
- package/dist/common/models/setting.const.defaults.d.ts +3 -0
- package/dist/common/models/setting.const.defaults.js +185 -0
- package/dist/common/models/setting.const.js +68 -0
- package/dist/common/models/setting.const.preferred.d.ts +5 -0
- package/dist/common/models/setting.const.preferred.js +35 -0
- package/dist/common/models/setting.const.qr.d.ts +2 -0
- package/dist/common/models/setting.const.qr.js +174 -0
- package/dist/common/models/setting.type.d.ts +900 -0
- package/dist/common/models/setting.type.js +8 -0
- package/dist/common/models/shared.const.behabiour.d.ts +28 -0
- package/dist/common/models/shared.const.behabiour.js +36 -0
- package/dist/common/models/shared.const.d.ts +5 -0
- package/dist/common/models/shared.const.js +12 -0
- package/dist/common/models/shared.const.symbols.d.ts +9 -0
- package/dist/common/models/shared.const.symbols.js +20 -0
- package/dist/common/models/shared.definition.configNames.d.ts +36 -0
- package/dist/common/models/shared.definition.configNames.js +203 -0
- package/dist/common/models/shared.definition.d.ts +22 -0
- package/dist/common/models/shared.definition.js +24 -0
- package/dist/common/models/shared.type.util.d.ts +8 -0
- package/dist/common/models/shared.type.util.js +0 -0
- package/dist/common/models/sync.definition.d.ts +18 -0
- package/dist/common/models/sync.definition.js +20 -0
- package/dist/common/models/tweak.definition.d.ts +191 -0
- package/dist/common/models/tweak.definition.js +77 -0
- package/dist/common/rosetta.d.ts +42 -0
- package/dist/common/rosetta.js +57 -0
- package/dist/common/settingConstants.d.ts +216 -0
- package/dist/common/settingConstants.js +434 -0
- package/dist/common/typeUtils.d.ts +17 -0
- package/dist/common/typeUtils.js +51 -0
- package/dist/common/types.d.ts +107 -0
- package/dist/common/types.js +212 -0
- package/dist/common/utils.d.ts +129 -0
- package/dist/common/utils.doc.d.ts +11 -0
- package/dist/common/utils.doc.js +35 -0
- package/dist/common/utils.js +583 -0
- package/dist/common/utils.object.d.ts +2 -0
- package/dist/common/utils.object.js +14 -0
- package/dist/common/utils.patch.d.ts +8 -0
- package/dist/common/utils.patch.js +178 -0
- package/dist/common/utils.type.d.ts +1 -0
- package/dist/common/utils.type.js +0 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.js +14 -0
- package/dist/databases/IndexedDBKeyValueDatabase.d.ts +26 -0
- package/dist/databases/IndexedDBKeyValueDatabase.js +130 -0
- package/dist/dataobject/StoredMap.d.ts +12 -0
- package/dist/dataobject/StoredMap.js +47 -0
- package/dist/dev/checks.d.ts +5 -0
- package/dist/dev/checks.js +38 -0
- package/dist/encryption/encryptHKDF.d.ts +3 -0
- package/dist/encryption/encryptHKDF.js +7 -0
- package/dist/encryption/stringEncryption.d.ts +27 -0
- package/dist/encryption/stringEncryption.js +59 -0
- package/dist/events/coreEvents.d.ts +54 -0
- package/dist/events/coreEvents.js +46 -0
- package/dist/hub/hub.d.ts +11 -0
- package/dist/hub/hub.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/interfaces/AsyncActivityRunner.d.ts +18 -0
- package/dist/interfaces/AsyncActivityRunner.js +7 -0
- package/dist/interfaces/Confirm.d.ts +17 -0
- package/dist/interfaces/Confirm.js +0 -0
- package/dist/interfaces/DatabaseFileAccess.d.ts +14 -0
- package/dist/interfaces/DatabaseFileAccess.js +0 -0
- package/dist/interfaces/DatabaseRebuilder.d.ts +13 -0
- package/dist/interfaces/DatabaseRebuilder.js +0 -0
- package/dist/interfaces/FileHandler.d.ts +13 -0
- package/dist/interfaces/FileHandler.js +0 -0
- package/dist/interfaces/KeyValueDatabase.d.ts +11 -0
- package/dist/interfaces/KeyValueDatabase.js +0 -0
- package/dist/interfaces/ServiceModule.d.ts +59 -0
- package/dist/interfaces/ServiceModule.js +19 -0
- package/dist/interfaces/StorageAccess.d.ts +44 -0
- package/dist/interfaces/StorageAccess.js +0 -0
- package/dist/interfaces/StorageEventManager.d.ts +16 -0
- package/dist/interfaces/StorageEventManager.js +5 -0
- package/dist/managers/ChangeManager.d.ts +61 -0
- package/dist/managers/ChangeManager.js +104 -0
- package/dist/managers/ChunkDeliveryCoordinator.d.ts +51 -0
- package/dist/managers/ChunkDeliveryCoordinator.js +136 -0
- package/dist/managers/ChunkFetcher.d.ts +44 -0
- package/dist/managers/ChunkFetcher.js +251 -0
- package/dist/managers/ChunkManager.d.ts +2 -0
- package/dist/managers/ChunkManager.js +4 -0
- package/dist/managers/ConflictManager.d.ts +37 -0
- package/dist/managers/ConflictManager.js +322 -0
- package/dist/managers/EntryManager/EntryManager.d.ts +37 -0
- package/dist/managers/EntryManager/EntryManager.js +73 -0
- package/dist/managers/EntryManager/EntryManagerImpls.d.ts +74 -0
- package/dist/managers/EntryManager/EntryManagerImpls.js +499 -0
- package/dist/managers/HashManager/HashManager.d.ts +60 -0
- package/dist/managers/HashManager/HashManager.js +97 -0
- package/dist/managers/HashManager/HashManagerCore.d.ts +114 -0
- package/dist/managers/HashManager/HashManagerCore.js +99 -0
- package/dist/managers/HashManager/PureJSHashManager.d.ts +77 -0
- package/dist/managers/HashManager/PureJSHashManager.js +84 -0
- package/dist/managers/HashManager/XXHashHashManager.d.ts +96 -0
- package/dist/managers/HashManager/XXHashHashManager.js +111 -0
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.d.ts +30 -0
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.js +115 -0
- package/dist/managers/LayeredChunkManager/CacheLayer.d.ts +59 -0
- package/dist/managers/LayeredChunkManager/CacheLayer.js +161 -0
- package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.d.ts +37 -0
- package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.js +0 -0
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.d.ts +14 -0
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.js +78 -0
- package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.d.ts +11 -0
- package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.js +43 -0
- package/dist/managers/LayeredChunkManager/HotPackLayer.d.ts +9 -0
- package/dist/managers/LayeredChunkManager/HotPackLayer.js +8 -0
- package/dist/managers/LayeredChunkManager/types.d.ts +39 -0
- package/dist/managers/LayeredChunkManager/types.js +0 -0
- package/dist/managers/LayeredChunkManager.d.ts +53 -0
- package/dist/managers/LayeredChunkManager.js +240 -0
- package/dist/managers/LiveSyncManagers.d.ts +48 -0
- package/dist/managers/LiveSyncManagers.js +136 -0
- package/dist/managers/StorageEventManager.d.ts +135 -0
- package/dist/managers/StorageEventManager.js +564 -0
- package/dist/managers/StorageProcessingManager.d.ts +14 -0
- package/dist/managers/StorageProcessingManager.js +48 -0
- package/dist/managers/adapters/IStorageEventConverterAdapter.d.ts +16 -0
- package/dist/managers/adapters/IStorageEventConverterAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventManagerAdapter.d.ts +18 -0
- package/dist/managers/adapters/IStorageEventManagerAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventPersistenceAdapter.d.ts +15 -0
- package/dist/managers/adapters/IStorageEventPersistenceAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventStatusAdapter.d.ts +13 -0
- package/dist/managers/adapters/IStorageEventStatusAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventTypeGuardAdapter.d.ts +16 -0
- package/dist/managers/adapters/IStorageEventTypeGuardAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventWatchAdapter.d.ts +21 -0
- package/dist/managers/adapters/IStorageEventWatchAdapter.js +0 -0
- package/dist/managers/adapters/index.d.ts +6 -0
- package/dist/managers/adapters/index.js +0 -0
- package/dist/mock_and_interop/stores.d.ts +21 -0
- package/dist/mock_and_interop/stores.js +15 -0
- package/dist/mock_and_interop/wrapper.d.ts +7 -0
- package/dist/mock_and_interop/wrapper.js +37 -0
- package/dist/mods.d.ts +1 -0
- package/dist/mods.js +18 -0
- package/dist/platform/browser/index.d.ts +1 -0
- package/dist/platform/browser/index.js +10 -0
- package/dist/platform/browser/storage.d.ts +35 -0
- package/dist/platform/browser/storage.js +139 -0
- package/dist/platform/node/index.d.ts +23 -0
- package/dist/platform/node/index.js +33 -0
- package/dist/platform/node/storage.d.ts +31 -0
- package/dist/platform/node/storage.js +104 -0
- package/dist/platform/storagePath.d.ts +7 -0
- package/dist/platform/storagePath.js +20 -0
- package/dist/pouchdb/LiveSyncDBFunctions.d.ts +14 -0
- package/dist/pouchdb/LiveSyncDBFunctions.js +129 -0
- package/dist/pouchdb/LiveSyncLocalDB.d.ts +196 -0
- package/dist/pouchdb/LiveSyncLocalDB.js +381 -0
- package/dist/pouchdb/PouchDBConstructor.d.ts +3 -0
- package/dist/pouchdb/PouchDBConstructor.js +0 -0
- package/dist/pouchdb/ReplicatorShim.d.ts +51 -0
- package/dist/pouchdb/ReplicatorShim.js +109 -0
- package/dist/pouchdb/StreamingFetch.d.ts +19 -0
- package/dist/pouchdb/StreamingFetch.js +263 -0
- package/dist/pouchdb/chunks.d.ts +38 -0
- package/dist/pouchdb/chunks.js +314 -0
- package/dist/pouchdb/compress.d.ts +11 -0
- package/dist/pouchdb/compress.js +99 -0
- package/dist/pouchdb/encryption.d.ts +20 -0
- package/dist/pouchdb/encryption.js +458 -0
- package/dist/pouchdb/negotiation.d.ts +9 -0
- package/dist/pouchdb/negotiation.js +109 -0
- package/dist/pouchdb/pouchdb-browser.d.ts +2 -0
- package/dist/pouchdb/pouchdb-browser.js +96 -0
- package/dist/pouchdb/pouchdb-http.d.ts +2 -0
- package/dist/pouchdb/pouchdb-http.js +94 -0
- package/dist/pouchdb/pouchdb-test.d.ts +2 -0
- package/dist/pouchdb/pouchdb-test.js +12 -0
- package/dist/pouchdb/utils_couchdb.d.ts +4 -0
- package/dist/pouchdb/utils_couchdb.js +38 -0
- package/dist/replication/LiveSyncAbstractReplicator.d.ts +69 -0
- package/dist/replication/LiveSyncAbstractReplicator.js +92 -0
- package/dist/replication/SyncParamsHandler.d.ts +35 -0
- package/dist/replication/SyncParamsHandler.js +118 -0
- package/dist/replication/couchdb/LiveSyncReplicator.d.ts +85 -0
- package/dist/replication/couchdb/LiveSyncReplicator.js +1132 -0
- package/dist/replication/httplib.d.ts +75 -0
- package/dist/replication/httplib.js +187 -0
- package/dist/replication/journal/JournalSyncCore.d.ts +70 -0
- package/dist/replication/journal/JournalSyncCore.js +737 -0
- package/dist/replication/journal/JournalSyncTypes.d.ts +9 -0
- package/dist/replication/journal/JournalSyncTypes.js +11 -0
- package/dist/replication/journal/LiveSyncJournalReplicator.d.ts +40 -0
- package/dist/replication/journal/LiveSyncJournalReplicator.js +294 -0
- package/dist/replication/journal/LiveSyncJournalReplicatorEnv.d.ts +3 -0
- package/dist/replication/journal/LiveSyncJournalReplicatorEnv.js +0 -0
- package/dist/replication/journal/objectstore/JournalStorageAdapter.d.ts +15 -0
- package/dist/replication/journal/objectstore/JournalStorageAdapter.js +0 -0
- package/dist/replication/journal/objectstore/MinioStorageAdapter.d.ts +21 -0
- package/dist/replication/journal/objectstore/MinioStorageAdapter.js +204 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +90 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.js +380 -0
- package/dist/replication/trystero/P2PLogCollector.d.ts +8 -0
- package/dist/replication/trystero/P2PLogCollector.js +91 -0
- package/dist/replication/trystero/P2PReplicatorBase.d.ts +19 -0
- package/dist/replication/trystero/P2PReplicatorBase.js +0 -0
- package/dist/replication/trystero/P2PReplicatorCore.d.ts +12 -0
- package/dist/replication/trystero/P2PReplicatorCore.js +126 -0
- package/dist/replication/trystero/P2PReplicatorPaneCommon.d.ts +41 -0
- package/dist/replication/trystero/P2PReplicatorPaneCommon.js +20 -0
- package/dist/replication/trystero/ProxiedDB.d.ts +13 -0
- package/dist/replication/trystero/ProxiedDB.js +20 -0
- package/dist/replication/trystero/TrysteroReplicator.d.ts +152 -0
- package/dist/replication/trystero/TrysteroReplicator.js +683 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PClient.d.ts +19 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PClient.js +80 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PConnection.d.ts +2 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PConnection.js +4 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.d.ts +117 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +540 -0
- package/dist/replication/trystero/UseP2PReplicatorResult.d.ts +11 -0
- package/dist/replication/trystero/UseP2PReplicatorResult.js +0 -0
- package/dist/replication/trystero/addP2PEventHandlers.d.ts +35 -0
- package/dist/replication/trystero/addP2PEventHandlers.js +43 -0
- package/dist/replication/trystero/rpcCompat.d.ts +1 -0
- package/dist/replication/trystero/rpcCompat.js +9 -0
- package/dist/replication/trystero/types.d.ts +95 -0
- package/dist/replication/trystero/types.js +27 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.d.ts +7 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.js +25 -0
- package/dist/replication/trystero/useP2PReplicatorFeature.d.ts +17 -0
- package/dist/replication/trystero/useP2PReplicatorFeature.js +82 -0
- package/dist/rpc/RpcRoom.d.ts +24 -0
- package/dist/rpc/RpcRoom.js +300 -0
- package/dist/rpc/RpcSession.d.ts +9 -0
- package/dist/rpc/RpcSession.js +32 -0
- package/dist/rpc/chunking.d.ts +11 -0
- package/dist/rpc/chunking.js +58 -0
- package/dist/rpc/errors.d.ts +8 -0
- package/dist/rpc/errors.js +26 -0
- package/dist/rpc/index.d.ts +6 -0
- package/dist/rpc/index.js +12 -0
- package/dist/rpc/pouchdb/RpcPouchDBProxy.d.ts +75 -0
- package/dist/rpc/pouchdb/RpcPouchDBProxy.js +115 -0
- package/dist/rpc/pouchdb/RpcPouchDBServer.d.ts +16 -0
- package/dist/rpc/pouchdb/RpcPouchDBServer.js +55 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.d.ts +24 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.js +208 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.types.d.ts +64 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.types.js +12 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.utils.d.ts +33 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.utils.js +217 -0
- package/dist/rpc/transports/TrysteroTransport.d.ts +216 -0
- package/dist/rpc/transports/TrysteroTransport.js +134 -0
- package/dist/rpc/transports/trysteroUtils.d.ts +3 -0
- package/dist/rpc/transports/trysteroUtils.js +37 -0
- package/dist/rpc/types.d.ts +75 -0
- package/dist/rpc/types.js +6 -0
- package/dist/serviceFeatures/checkRemoteSize.d.ts +28 -0
- package/dist/serviceFeatures/checkRemoteSize.js +178 -0
- package/dist/serviceFeatures/offlineScanner.d.ts +128 -0
- package/dist/serviceFeatures/offlineScanner.js +553 -0
- package/dist/serviceFeatures/prepareDatabaseForUse.d.ts +20 -0
- package/dist/serviceFeatures/prepareDatabaseForUse.js +39 -0
- package/dist/serviceFeatures/remoteConfig.d.ts +46 -0
- package/dist/serviceFeatures/remoteConfig.js +247 -0
- package/dist/serviceFeatures/setupObsidian/qrCode.d.ts +4 -0
- package/dist/serviceFeatures/setupObsidian/qrCode.js +67 -0
- package/dist/serviceFeatures/setupObsidian/setupUri.d.ts +7 -0
- package/dist/serviceFeatures/setupObsidian/setupUri.js +70 -0
- package/dist/serviceFeatures/setupObsidian/types.d.ts +2 -0
- package/dist/serviceFeatures/setupObsidian/types.js +0 -0
- package/dist/serviceFeatures/targetFilter.d.ts +24 -0
- package/dist/serviceFeatures/targetFilter.js +178 -0
- package/dist/serviceModules/FileAccessBase.d.ts +93 -0
- package/dist/serviceModules/FileAccessBase.js +219 -0
- package/dist/serviceModules/Rebuilder.d.ts +92 -0
- package/dist/serviceModules/Rebuilder.js +449 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +40 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +306 -0
- package/dist/serviceModules/ServiceFileAccessBase.d.ts +64 -0
- package/dist/serviceModules/ServiceFileAccessBase.js +312 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +52 -0
- package/dist/serviceModules/ServiceFileHandlerBase.js +493 -0
- package/dist/serviceModules/ServiceModuleBase.d.ts +10 -0
- package/dist/serviceModules/ServiceModuleBase.js +13 -0
- package/dist/serviceModules/adapters/IConversionAdapter.d.ts +15 -0
- package/dist/serviceModules/adapters/IConversionAdapter.js +0 -0
- package/dist/serviceModules/adapters/IFileSystemAdapter.d.ts +47 -0
- package/dist/serviceModules/adapters/IFileSystemAdapter.js +0 -0
- package/dist/serviceModules/adapters/IPathAdapter.d.ts +15 -0
- package/dist/serviceModules/adapters/IPathAdapter.js +0 -0
- package/dist/serviceModules/adapters/IStorageAdapter.d.ts +56 -0
- package/dist/serviceModules/adapters/IStorageAdapter.js +0 -0
- package/dist/serviceModules/adapters/ITypeGuardAdapter.d.ts +14 -0
- package/dist/serviceModules/adapters/ITypeGuardAdapter.js +0 -0
- package/dist/serviceModules/adapters/IVaultAdapter.d.ts +51 -0
- package/dist/serviceModules/adapters/IVaultAdapter.js +0 -0
- package/dist/serviceModules/adapters/index.d.ts +6 -0
- package/dist/serviceModules/adapters/index.js +0 -0
- package/dist/services/BrowserServices.d.ts +36 -0
- package/dist/services/BrowserServices.js +123 -0
- package/dist/services/HeadlessServices.d.ts +14 -0
- package/dist/services/HeadlessServices.js +144 -0
- package/dist/services/InjectableServices.d.ts +1 -0
- package/dist/services/InjectableServices.js +4 -0
- package/dist/services/ServiceHub.d.ts +82 -0
- package/dist/services/ServiceHub.js +66 -0
- package/dist/services/base/APIService.d.ts +93 -0
- package/dist/services/base/APIService.js +44 -0
- package/dist/services/base/AppLifecycleService.d.ts +132 -0
- package/dist/services/base/AppLifecycleService.js +123 -0
- package/dist/services/base/ConfigService.d.ts +7 -0
- package/dist/services/base/ConfigService.js +6 -0
- package/dist/services/base/ConflictService.d.ts +54 -0
- package/dist/services/base/ConflictService.js +22 -0
- package/dist/services/base/ControlService.d.ts +54 -0
- package/dist/services/base/ControlService.js +103 -0
- package/dist/services/base/DatabaseEventService.d.ts +38 -0
- package/dist/services/base/DatabaseEventService.js +38 -0
- package/dist/services/base/DatabaseService.d.ts +40 -0
- package/dist/services/base/DatabaseService.js +79 -0
- package/dist/services/base/FileProcessingService.d.ts +25 -0
- package/dist/services/base/FileProcessingService.js +28 -0
- package/dist/services/base/IService.d.ts +284 -0
- package/dist/services/base/IService.js +1 -0
- package/dist/services/base/KeyValueDBService.d.ts +42 -0
- package/dist/services/base/KeyValueDBService.js +133 -0
- package/dist/services/base/MessageTranslator.d.ts +6 -0
- package/dist/services/base/MessageTranslator.js +4 -0
- package/dist/services/base/PathService.d.ts +38 -0
- package/dist/services/base/PathService.js +66 -0
- package/dist/services/base/RemoteService.d.ts +61 -0
- package/dist/services/base/RemoteService.js +212 -0
- package/dist/services/base/ReplicationService.d.ts +92 -0
- package/dist/services/base/ReplicationService.js +261 -0
- package/dist/services/base/ReplicatorService.d.ts +66 -0
- package/dist/services/base/ReplicatorService.js +164 -0
- package/dist/services/base/ServiceBase.d.ts +33 -0
- package/dist/services/base/ServiceBase.js +27 -0
- package/dist/services/base/SettingService.d.ts +112 -0
- package/dist/services/base/SettingService.js +543 -0
- package/dist/services/base/TestService.d.ts +28 -0
- package/dist/services/base/TestService.js +19 -0
- package/dist/services/base/TweakValueService.d.ts +40 -0
- package/dist/services/base/TweakValueService.js +6 -0
- package/dist/services/base/UnresolvedErrorManager.d.ts +15 -0
- package/dist/services/base/UnresolvedErrorManager.js +44 -0
- package/dist/services/base/VaultService.d.ts +69 -0
- package/dist/services/base/VaultService.js +70 -0
- package/dist/services/implements/base/SvelteDialog.d.ts +79 -0
- package/dist/services/implements/base/SvelteDialog.js +134 -0
- package/dist/services/implements/base/UIService.d.ts +24 -0
- package/dist/services/implements/base/UIService.js +37 -0
- package/dist/services/implements/browser/BrowserAPIService.d.ts +54 -0
- package/dist/services/implements/browser/BrowserAPIService.js +298 -0
- package/dist/services/implements/browser/BrowserDatabaseService.d.ts +7 -0
- package/dist/services/implements/browser/BrowserDatabaseService.js +10 -0
- package/dist/services/implements/browser/ConfigServiceBrowserCompat.d.ts +16 -0
- package/dist/services/implements/browser/ConfigServiceBrowserCompat.js +23 -0
- package/dist/services/implements/headless/HeadlessAPIService.d.ts +52 -0
- package/dist/services/implements/headless/HeadlessAPIService.js +127 -0
- package/dist/services/implements/headless/HeadlessDatabaseService.d.ts +7 -0
- package/dist/services/implements/headless/HeadlessDatabaseService.js +10 -0
- package/dist/services/implements/injectable/InjectableAPIService.d.ts +7 -0
- package/dist/services/implements/injectable/InjectableAPIService.js +18 -0
- package/dist/services/implements/injectable/InjectableAppLifecycleService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableAppLifecycleService.js +14 -0
- package/dist/services/implements/injectable/InjectableConflictService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableConflictService.js +14 -0
- package/dist/services/implements/injectable/InjectableDatabaseEventService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableDatabaseEventService.js +7 -0
- package/dist/services/implements/injectable/InjectableFileProcessingService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableFileProcessingService.js +6 -0
- package/dist/services/implements/injectable/InjectablePathService.d.ts +12 -0
- package/dist/services/implements/injectable/InjectablePathService.js +36 -0
- package/dist/services/implements/injectable/InjectableRemoteService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableRemoteService.js +7 -0
- package/dist/services/implements/injectable/InjectableReplicationService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableReplicationService.js +6 -0
- package/dist/services/implements/injectable/InjectableReplicatorService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableReplicatorService.js +7 -0
- package/dist/services/implements/injectable/InjectableServiceHub.d.ts +72 -0
- package/dist/services/implements/injectable/InjectableServiceHub.js +125 -0
- package/dist/services/implements/injectable/InjectableServices.d.ts +36 -0
- package/dist/services/implements/injectable/InjectableServices.js +1 -0
- package/dist/services/implements/injectable/InjectableSettingService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableSettingService.js +33 -0
- package/dist/services/implements/injectable/InjectableTestService.d.ts +5 -0
- package/dist/services/implements/injectable/InjectableTestService.js +8 -0
- package/dist/services/implements/injectable/InjectableTweakValueService.d.ts +15 -0
- package/dist/services/implements/injectable/InjectableTweakValueService.js +12 -0
- package/dist/services/implements/injectable/InjectableVaultService.d.ts +9 -0
- package/dist/services/implements/injectable/InjectableVaultService.js +20 -0
- package/dist/services/lib/HandlerUtils.d.ts +374 -0
- package/dist/services/lib/HandlerUtils.js +412 -0
- package/dist/services/lib/logUtils.d.ts +13 -0
- package/dist/services/lib/logUtils.js +28 -0
- package/dist/services/lib/remoteActivity.d.ts +13 -0
- package/dist/services/lib/remoteActivity.js +11 -0
- package/dist/string_and_binary/chunks.d.ts +10 -0
- package/dist/string_and_binary/chunks.js +561 -0
- package/dist/string_and_binary/convert.d.ts +8 -0
- package/dist/string_and_binary/convert.js +46 -0
- package/dist/string_and_binary/hash.d.ts +2 -0
- package/dist/string_and_binary/hash.js +1 -0
- package/dist/string_and_binary/path.d.ts +35 -0
- package/dist/string_and_binary/path.js +240 -0
- package/dist/worker/bg.common.d.ts +2 -0
- package/dist/worker/bg.common.js +6 -0
- package/dist/worker/bg.worker.d.ts +1 -0
- package/dist/worker/bg.worker.encryption.d.ts +7 -0
- package/dist/worker/bg.worker.encryption.js +30 -0
- package/dist/worker/bg.worker.js +14 -0
- package/dist/worker/bg.worker.splitting.d.ts +6 -0
- package/dist/worker/bg.worker.splitting.js +36 -0
- package/dist/worker/bgWorker.d.ts +25 -0
- package/dist/worker/bgWorker.direct.d.ts +40 -0
- package/dist/worker/bgWorker.direct.js +65 -0
- package/dist/worker/bgWorker.encryption.d.ts +22 -0
- package/dist/worker/bgWorker.encryption.js +40 -0
- package/dist/worker/bgWorker.js +348 -0
- package/dist/worker/bgWorker.splitting.d.ts +27 -0
- package/dist/worker/bgWorker.splitting.js +123 -0
- package/dist/worker/universalTypes.d.ts +63 -0
- package/dist/worker/universalTypes.js +4 -0
- package/docs/development.md +51 -0
- package/docs/platform-storage.md +60 -0
- package/docs/releasing.md +69 -0
- package/package.json +693 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChunkAlgorithmNames,
|
|
3
|
+
DEFAULT_SETTINGS,
|
|
4
|
+
LOG_LEVEL_NOTICE,
|
|
5
|
+
LOG_LEVEL_URGENT,
|
|
6
|
+
LOG_LEVEL_VERBOSE,
|
|
7
|
+
SALT_OF_PASSPHRASE,
|
|
8
|
+
SETTING_KEY_P2P_DEVICE_NAME
|
|
9
|
+
} from "../../common/types.js";
|
|
10
|
+
import { handlers } from "../lib/HandlerUtils.js";
|
|
11
|
+
import { ServiceBase } from "./ServiceBase.js";
|
|
12
|
+
import { createInstanceLogFunction } from "../lib/logUtils.js";
|
|
13
|
+
import { isCloudantURI } from "../../pouchdb/utils_couchdb.js";
|
|
14
|
+
import { decryptString, encryptString } from "../../encryption/stringEncryption.js";
|
|
15
|
+
import { setLang } from "../../common/i18n.js";
|
|
16
|
+
import {
|
|
17
|
+
activateP2PRemoteConfiguration,
|
|
18
|
+
activateRemoteConfiguration,
|
|
19
|
+
migrateLegacyRemoteConfigurationsInPlace,
|
|
20
|
+
migrateP2PActiveRemoteConfigurationIdInPlace
|
|
21
|
+
} from "../../serviceFeatures/remoteConfig.js";
|
|
22
|
+
import { ConnectionStringParser } from "../../common/ConnectionString.js";
|
|
23
|
+
class SettingService extends ServiceBase {
|
|
24
|
+
deviceAndVaultName = "";
|
|
25
|
+
APIService;
|
|
26
|
+
_settings;
|
|
27
|
+
get settings() {
|
|
28
|
+
return this._settings;
|
|
29
|
+
}
|
|
30
|
+
set settings(value) {
|
|
31
|
+
this._settings = value;
|
|
32
|
+
}
|
|
33
|
+
_lastPersistedSettings;
|
|
34
|
+
_log;
|
|
35
|
+
constructor(context, dependencies) {
|
|
36
|
+
super(context);
|
|
37
|
+
this.APIService = dependencies.APIService;
|
|
38
|
+
this._log = createInstanceLogFunction("SettingService", this.APIService);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adjust the given settings, e.g., migrate old settings to new format.
|
|
42
|
+
* @param settings The settings to adjust.
|
|
43
|
+
*/
|
|
44
|
+
adjustSettings(settings) {
|
|
45
|
+
if (migrateLegacyRemoteConfigurationsInPlace(settings, (message) => {
|
|
46
|
+
this._log(message, LOG_LEVEL_NOTICE);
|
|
47
|
+
})) {
|
|
48
|
+
this._log(
|
|
49
|
+
"Legacy remote configuration has been migrated to the remote configuration list.",
|
|
50
|
+
LOG_LEVEL_NOTICE
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
settings.disableRequestURI = true;
|
|
54
|
+
settings.gcDelay = 0;
|
|
55
|
+
settings.useHistory = true;
|
|
56
|
+
if ("workingEncrypt" in settings) delete settings.workingEncrypt;
|
|
57
|
+
if ("workingPassphrase" in settings) delete settings.workingPassphrase;
|
|
58
|
+
if (settings.chunkSplitterVersion == "") {
|
|
59
|
+
if (settings.enableChunkSplitterV2) {
|
|
60
|
+
if (settings.useSegmenter) {
|
|
61
|
+
settings.chunkSplitterVersion = "v2-segmenter";
|
|
62
|
+
} else {
|
|
63
|
+
settings.chunkSplitterVersion = "v2";
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
settings.chunkSplitterVersion = "";
|
|
67
|
+
}
|
|
68
|
+
} else if (!(settings.chunkSplitterVersion in ChunkAlgorithmNames)) {
|
|
69
|
+
settings.chunkSplitterVersion = "";
|
|
70
|
+
}
|
|
71
|
+
return Promise.resolve(settings);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the unique name for identify the device.
|
|
75
|
+
*/
|
|
76
|
+
getDeviceAndVaultName() {
|
|
77
|
+
return this.deviceAndVaultName;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the unique name for identify the device.
|
|
81
|
+
* @param name The unique name to set.
|
|
82
|
+
*/
|
|
83
|
+
setDeviceAndVaultName(name) {
|
|
84
|
+
this.deviceAndVaultName = name;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Save the current device and vault name to settings, aside from the main settings.
|
|
88
|
+
*/
|
|
89
|
+
saveDeviceAndVaultName() {
|
|
90
|
+
const lsKey = "obsidian-live-sync-vaultanddevicename-" + this.APIService.getSystemVaultName() + this.additionalSuffixOfDatabaseName();
|
|
91
|
+
this.setItem(lsKey, this.deviceAndVaultName);
|
|
92
|
+
}
|
|
93
|
+
additionalSuffixOfDatabaseName() {
|
|
94
|
+
const suffix = this.settings?.additionalSuffixOfDatabaseName;
|
|
95
|
+
if (typeof suffix === "undefined") {
|
|
96
|
+
this._log("too early to get additionalSuffixOfDatabaseName, returning empty string");
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
return `-${suffix}`;
|
|
100
|
+
}
|
|
101
|
+
getKey(key) {
|
|
102
|
+
const keyMain = this.APIService.getSystemVaultName();
|
|
103
|
+
const addSuffix = this.additionalSuffixOfDatabaseName();
|
|
104
|
+
return `${keyMain}${addSuffix}-${key}`;
|
|
105
|
+
}
|
|
106
|
+
setSmallConfig(key, value) {
|
|
107
|
+
const dbKey = this.getKey(key);
|
|
108
|
+
this.setItem(dbKey, value);
|
|
109
|
+
}
|
|
110
|
+
getSmallConfig(key) {
|
|
111
|
+
const dbKey = this.getKey(key);
|
|
112
|
+
return this.getItem(dbKey);
|
|
113
|
+
}
|
|
114
|
+
deleteSmallConfig(key) {
|
|
115
|
+
const dbKey = this.getKey(key);
|
|
116
|
+
this.deleteItem(dbKey);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Save the current settings to storage.
|
|
120
|
+
*/
|
|
121
|
+
async saveSettingData() {
|
|
122
|
+
this.saveDeviceAndVaultName();
|
|
123
|
+
const previousSettings = this._lastPersistedSettings ?? this.cloneSettings(this.settings);
|
|
124
|
+
const settings = {
|
|
125
|
+
...this.settings,
|
|
126
|
+
remoteConfigurations: Object.fromEntries(
|
|
127
|
+
Object.entries(this.settings.remoteConfigurations || {}).map(([id, config]) => [id, { ...config }])
|
|
128
|
+
)
|
|
129
|
+
};
|
|
130
|
+
const hookResults = await this.onBeforeSaveSettingData(settings, previousSettings);
|
|
131
|
+
for (const patch of hookResults) {
|
|
132
|
+
if (patch instanceof Error || !patch) continue;
|
|
133
|
+
Object.assign(settings, patch);
|
|
134
|
+
Object.assign(this.settings, patch);
|
|
135
|
+
}
|
|
136
|
+
settings.deviceAndVaultName = "";
|
|
137
|
+
if (settings.P2P_DevicePeerName && settings.P2P_DevicePeerName.trim() !== "") {
|
|
138
|
+
this._log("Saving device peer name to small config");
|
|
139
|
+
this.setSmallConfig(SETTING_KEY_P2P_DEVICE_NAME, settings.P2P_DevicePeerName.trim());
|
|
140
|
+
settings.P2P_DevicePeerName = "";
|
|
141
|
+
}
|
|
142
|
+
if (this.usedPassphrase == "" && !await this.getPassphrase(settings)) {
|
|
143
|
+
this._log("Failed to retrieve passphrase. data.json contains unencrypted items!", LOG_LEVEL_NOTICE);
|
|
144
|
+
} else {
|
|
145
|
+
if (settings.couchDB_PASSWORD != "" || settings.couchDB_URI != "" || settings.couchDB_USER != "" || settings.couchDB_DBNAME) {
|
|
146
|
+
const connectionSetting = {
|
|
147
|
+
couchDB_DBNAME: settings.couchDB_DBNAME,
|
|
148
|
+
couchDB_PASSWORD: settings.couchDB_PASSWORD,
|
|
149
|
+
couchDB_URI: settings.couchDB_URI,
|
|
150
|
+
couchDB_USER: settings.couchDB_USER,
|
|
151
|
+
accessKey: settings.accessKey,
|
|
152
|
+
bucket: settings.bucket,
|
|
153
|
+
endpoint: settings.endpoint,
|
|
154
|
+
region: settings.region,
|
|
155
|
+
secretKey: settings.secretKey,
|
|
156
|
+
useCustomRequestHandler: settings.useCustomRequestHandler,
|
|
157
|
+
bucketCustomHeaders: settings.bucketCustomHeaders,
|
|
158
|
+
couchDB_CustomHeaders: settings.couchDB_CustomHeaders,
|
|
159
|
+
useJWT: settings.useJWT,
|
|
160
|
+
jwtKey: settings.jwtKey,
|
|
161
|
+
jwtAlgorithm: settings.jwtAlgorithm,
|
|
162
|
+
jwtKid: settings.jwtKid,
|
|
163
|
+
jwtExpDuration: settings.jwtExpDuration,
|
|
164
|
+
jwtSub: settings.jwtSub,
|
|
165
|
+
useRequestAPI: settings.useRequestAPI,
|
|
166
|
+
bucketPrefix: settings.bucketPrefix,
|
|
167
|
+
forcePathStyle: settings.forcePathStyle
|
|
168
|
+
};
|
|
169
|
+
settings.encryptedCouchDBConnection = await this.encryptConfigurationItem(
|
|
170
|
+
JSON.stringify(connectionSetting),
|
|
171
|
+
settings
|
|
172
|
+
);
|
|
173
|
+
settings.couchDB_PASSWORD = "";
|
|
174
|
+
settings.couchDB_DBNAME = "";
|
|
175
|
+
settings.couchDB_URI = "";
|
|
176
|
+
settings.couchDB_USER = "";
|
|
177
|
+
settings.accessKey = "";
|
|
178
|
+
settings.bucket = "";
|
|
179
|
+
settings.region = "";
|
|
180
|
+
settings.secretKey = "";
|
|
181
|
+
settings.endpoint = "";
|
|
182
|
+
}
|
|
183
|
+
if (settings.encrypt && settings.passphrase != "") {
|
|
184
|
+
settings.encryptedPassphrase = await this.encryptConfigurationItem(settings.passphrase, settings);
|
|
185
|
+
settings.passphrase = "";
|
|
186
|
+
}
|
|
187
|
+
await this.encryptRemoteConfigurationUris(settings);
|
|
188
|
+
}
|
|
189
|
+
await this.saveData(settings);
|
|
190
|
+
this._lastPersistedSettings = this.cloneSettings(this.settings);
|
|
191
|
+
void this.onSettingSaved(settings);
|
|
192
|
+
}
|
|
193
|
+
async encryptRemoteConfigurationUris(settings) {
|
|
194
|
+
const configs = settings.remoteConfigurations || {};
|
|
195
|
+
for (const [id, config] of Object.entries(configs)) {
|
|
196
|
+
if (config.isEncrypted || config.uri.trim() === "") {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const encryptedURI = await this.encryptConfigurationItem(config.uri, settings);
|
|
200
|
+
if (encryptedURI === "") {
|
|
201
|
+
this._log(
|
|
202
|
+
`Failed to encrypt remote configuration '${id}'. This entry will be saved in plain text.`,
|
|
203
|
+
LOG_LEVEL_URGENT
|
|
204
|
+
);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
configs[id] = {
|
|
208
|
+
...config,
|
|
209
|
+
uri: encryptedURI,
|
|
210
|
+
isEncrypted: true
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async decryptRemoteConfigurationUris(settings, passphrase) {
|
|
215
|
+
const configs = settings.remoteConfigurations || {};
|
|
216
|
+
for (const [id, config] of Object.entries(configs)) {
|
|
217
|
+
if (!config.isEncrypted) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
const decryptedURI = await this.decryptConfigurationItem(config.uri, passphrase);
|
|
221
|
+
if (decryptedURI === false) {
|
|
222
|
+
try {
|
|
223
|
+
ConnectionStringParser.parse(config.uri);
|
|
224
|
+
configs[id] = {
|
|
225
|
+
...config,
|
|
226
|
+
isEncrypted: false
|
|
227
|
+
};
|
|
228
|
+
this._log(
|
|
229
|
+
`Remote configuration '${id}' had a plain-text URI marked as encrypted. The flag has been repaired.`,
|
|
230
|
+
LOG_LEVEL_NOTICE
|
|
231
|
+
);
|
|
232
|
+
continue;
|
|
233
|
+
} catch {
|
|
234
|
+
}
|
|
235
|
+
this._log(
|
|
236
|
+
`Failed to decrypt remote configuration '${id}'. Verify passphrase and configuration.`,
|
|
237
|
+
LOG_LEVEL_URGENT
|
|
238
|
+
);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
configs[id] = {
|
|
242
|
+
...config,
|
|
243
|
+
uri: decryptedURI,
|
|
244
|
+
isEncrypted: false
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Event triggered before realising the settings.
|
|
250
|
+
* Handlers can return false to abort the realisation process.
|
|
251
|
+
*/
|
|
252
|
+
onBeforeRealiseSetting = handlers().bailFirstFailure("onBeforeRealiseSetting");
|
|
253
|
+
/**
|
|
254
|
+
* Event triggered after the settings have been realised.
|
|
255
|
+
*/
|
|
256
|
+
onSettingRealised = handlers().bailFirstFailure("onSettingRealised");
|
|
257
|
+
/**
|
|
258
|
+
* Event triggered to realise the settings.
|
|
259
|
+
*/
|
|
260
|
+
onRealiseSetting = handlers().bailFirstFailure("onRealiseSetting");
|
|
261
|
+
/**
|
|
262
|
+
* Suspend all synchronisation activities and save to the settings.
|
|
263
|
+
*/
|
|
264
|
+
suspendAllSync = handlers().all("suspendAllSync");
|
|
265
|
+
/**
|
|
266
|
+
* Suspend extra synchronisation activities, e.g., hidden files sync.
|
|
267
|
+
*/
|
|
268
|
+
suspendExtraSync = handlers().all("suspendExtraSync");
|
|
269
|
+
/**
|
|
270
|
+
* Suggest enabling optional features to the user.
|
|
271
|
+
*/
|
|
272
|
+
suggestOptionalFeatures = handlers().all("suggestOptionalFeatures");
|
|
273
|
+
/**
|
|
274
|
+
* Enable an optional feature and save to the settings.
|
|
275
|
+
* It may also raised from `handleSuggestOptionalFeatures` if the user agrees.
|
|
276
|
+
* @param mode The optional feature to enable.
|
|
277
|
+
*/
|
|
278
|
+
enableOptionalFeature = handlers().all("enableOptionalFeature");
|
|
279
|
+
onSettingLoaded = handlers().allParallel("onSettingLoaded");
|
|
280
|
+
onSettingChanged = handlers().allParallel("onSettingChanged");
|
|
281
|
+
onSettingSaved = handlers().allParallel("onSettingSaved");
|
|
282
|
+
onBeforeSaveSettingData = handlers().dispatchParallel("onBeforeSaveSettingData");
|
|
283
|
+
/**
|
|
284
|
+
* Get the current settings.
|
|
285
|
+
*/
|
|
286
|
+
currentSettings() {
|
|
287
|
+
return this.settings;
|
|
288
|
+
}
|
|
289
|
+
updateSettings(updateFn, saveImmediately) {
|
|
290
|
+
try {
|
|
291
|
+
const updated = updateFn(this.settings);
|
|
292
|
+
this.settings = updated;
|
|
293
|
+
} catch (ex) {
|
|
294
|
+
this._log("Error in update function: ", LOG_LEVEL_URGENT);
|
|
295
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
296
|
+
return Promise.reject(ex instanceof Error ? ex : new Error(String(ex)));
|
|
297
|
+
}
|
|
298
|
+
if (saveImmediately) {
|
|
299
|
+
return this.saveSettingData();
|
|
300
|
+
}
|
|
301
|
+
return Promise.resolve();
|
|
302
|
+
}
|
|
303
|
+
async applyExternalSettings(partial, saveImmediately) {
|
|
304
|
+
try {
|
|
305
|
+
this.settings = await this.adjustSettings({
|
|
306
|
+
...this.settings,
|
|
307
|
+
...partial
|
|
308
|
+
});
|
|
309
|
+
} catch (ex) {
|
|
310
|
+
this._log("Error in applying external settings: ", LOG_LEVEL_URGENT);
|
|
311
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
312
|
+
return Promise.reject(ex instanceof Error ? ex : new Error(String(ex)));
|
|
313
|
+
}
|
|
314
|
+
if (saveImmediately) {
|
|
315
|
+
return this.saveSettingData();
|
|
316
|
+
}
|
|
317
|
+
return Promise.resolve();
|
|
318
|
+
}
|
|
319
|
+
applyPartial(partial, saveImmediately) {
|
|
320
|
+
try {
|
|
321
|
+
this.settings = { ...this.settings, ...partial };
|
|
322
|
+
} catch (ex) {
|
|
323
|
+
this._log("Error in applying partial settings: ", LOG_LEVEL_URGENT);
|
|
324
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
325
|
+
return Promise.reject(ex instanceof Error ? ex : new Error(String(ex)));
|
|
326
|
+
}
|
|
327
|
+
if (saveImmediately) {
|
|
328
|
+
return this.saveSettingData();
|
|
329
|
+
}
|
|
330
|
+
return Promise.resolve();
|
|
331
|
+
}
|
|
332
|
+
getPassphrase(settings) {
|
|
333
|
+
const methods = {
|
|
334
|
+
"": () => Promise.resolve("*"),
|
|
335
|
+
LOCALSTORAGE: () => Promise.resolve(this.getItem("ls-setting-passphrase") ?? false),
|
|
336
|
+
ASK_AT_LAUNCH: () => this.APIService.confirm.askString("Passphrase", "passphrase", "")
|
|
337
|
+
};
|
|
338
|
+
const method = settings.configPassphraseStore;
|
|
339
|
+
const methodFunc = method in methods ? methods[method] : methods[""];
|
|
340
|
+
return methodFunc();
|
|
341
|
+
}
|
|
342
|
+
usedPassphrase = "";
|
|
343
|
+
/**
|
|
344
|
+
* Clear any used passphrase from memory.
|
|
345
|
+
*/
|
|
346
|
+
clearUsedPassphrase() {
|
|
347
|
+
this.usedPassphrase = "";
|
|
348
|
+
}
|
|
349
|
+
async decryptConfigurationItem(encrypted, passphrase) {
|
|
350
|
+
try {
|
|
351
|
+
const dec = await decryptString(encrypted, passphrase + SALT_OF_PASSPHRASE);
|
|
352
|
+
if (dec) {
|
|
353
|
+
this.usedPassphrase = passphrase;
|
|
354
|
+
return dec;
|
|
355
|
+
}
|
|
356
|
+
} catch (ex) {
|
|
357
|
+
this._log(`Failed to decrypt configuration item`, LOG_LEVEL_NOTICE);
|
|
358
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
359
|
+
}
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
async encryptConfigurationItem(src, settings) {
|
|
363
|
+
if (this.usedPassphrase != "") {
|
|
364
|
+
return await encryptString(src, this.usedPassphrase + SALT_OF_PASSPHRASE);
|
|
365
|
+
}
|
|
366
|
+
const passphrase = await this.getPassphrase(settings);
|
|
367
|
+
if (passphrase === false) {
|
|
368
|
+
this._log(
|
|
369
|
+
"Failed to obtain passphrase when saving data.json! Please verify the configuration.",
|
|
370
|
+
LOG_LEVEL_URGENT
|
|
371
|
+
);
|
|
372
|
+
return "";
|
|
373
|
+
}
|
|
374
|
+
const dec = await encryptString(src, passphrase + SALT_OF_PASSPHRASE);
|
|
375
|
+
if (dec) {
|
|
376
|
+
this.usedPassphrase = passphrase;
|
|
377
|
+
return dec;
|
|
378
|
+
}
|
|
379
|
+
return "";
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Decrypt the given settings.
|
|
383
|
+
* @param settings The settings to decrypt.
|
|
384
|
+
*/
|
|
385
|
+
async decryptSettings(settings) {
|
|
386
|
+
const passphrase = await this.getPassphrase(settings);
|
|
387
|
+
if (passphrase === false) {
|
|
388
|
+
this._log("No passphrase found for data.json! Verify configuration before syncing.", LOG_LEVEL_URGENT);
|
|
389
|
+
const hasEncryptedRemoteConfigurations = Object.values(settings.remoteConfigurations || {}).some(
|
|
390
|
+
(config) => config.isEncrypted
|
|
391
|
+
);
|
|
392
|
+
if (hasEncryptedRemoteConfigurations) {
|
|
393
|
+
this._log(
|
|
394
|
+
"Encrypted remote configurations found, but passphrase is unavailable. Verify configuration before syncing.",
|
|
395
|
+
LOG_LEVEL_URGENT
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
if (settings.encryptedCouchDBConnection) {
|
|
400
|
+
const keys = [
|
|
401
|
+
"couchDB_URI",
|
|
402
|
+
"couchDB_USER",
|
|
403
|
+
"couchDB_PASSWORD",
|
|
404
|
+
"couchDB_DBNAME",
|
|
405
|
+
"accessKey",
|
|
406
|
+
"bucket",
|
|
407
|
+
"endpoint",
|
|
408
|
+
"region",
|
|
409
|
+
"secretKey"
|
|
410
|
+
];
|
|
411
|
+
const decrypted = this.tryDecodeJson(
|
|
412
|
+
await this.decryptConfigurationItem(settings.encryptedCouchDBConnection, passphrase)
|
|
413
|
+
);
|
|
414
|
+
if (decrypted) {
|
|
415
|
+
for (const key of keys) {
|
|
416
|
+
if (key in decrypted) {
|
|
417
|
+
settings[key] = decrypted[key];
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
this._log(
|
|
422
|
+
"Failed to decrypt passphrase from data.json! Ensure configuration is correct before syncing with remote.",
|
|
423
|
+
LOG_LEVEL_URGENT
|
|
424
|
+
);
|
|
425
|
+
for (const key of keys) {
|
|
426
|
+
settings[key] = "";
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (settings.encrypt && settings.encryptedPassphrase) {
|
|
431
|
+
const encrypted = settings.encryptedPassphrase;
|
|
432
|
+
const decrypted = await this.decryptConfigurationItem(encrypted, passphrase);
|
|
433
|
+
if (decrypted) {
|
|
434
|
+
settings.passphrase = decrypted;
|
|
435
|
+
} else {
|
|
436
|
+
this._log(
|
|
437
|
+
"Failed to decrypt passphrase from data.json! Ensure configuration is correct before syncing with remote.",
|
|
438
|
+
LOG_LEVEL_URGENT
|
|
439
|
+
);
|
|
440
|
+
settings.passphrase = "";
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
await this.decryptRemoteConfigurationUris(settings, passphrase);
|
|
444
|
+
}
|
|
445
|
+
return settings;
|
|
446
|
+
}
|
|
447
|
+
async loadSettings() {
|
|
448
|
+
const settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
|
449
|
+
const hadRemoteConfigurations = Object.keys(settings.remoteConfigurations ?? {}).length > 0;
|
|
450
|
+
if (typeof settings.isConfigured == "undefined") {
|
|
451
|
+
if (JSON.stringify(settings) !== JSON.stringify(DEFAULT_SETTINGS)) {
|
|
452
|
+
settings.isConfigured = true;
|
|
453
|
+
} else {
|
|
454
|
+
const appId = this.APIService.getAppID();
|
|
455
|
+
settings.additionalSuffixOfDatabaseName = appId;
|
|
456
|
+
settings.isConfigured = false;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
this.settings = await this.decryptSettings(settings);
|
|
460
|
+
setLang(this.settings.displayLanguage);
|
|
461
|
+
await this.adjustSettings(this.settings);
|
|
462
|
+
const migratedLegacyRemoteConfigurations = !hadRemoteConfigurations && Object.keys(this.settings.remoteConfigurations ?? {}).length > 0;
|
|
463
|
+
const migratedP2PActiveRemoteConfiguration = migratedLegacyRemoteConfigurations && migrateP2PActiveRemoteConfigurationIdInPlace(this.settings);
|
|
464
|
+
const activeConfigurationId = this.settings.activeConfigurationId;
|
|
465
|
+
if (activeConfigurationId && this.settings.remoteConfigurations?.[activeConfigurationId]) {
|
|
466
|
+
const activated = activateRemoteConfiguration(this.settings, activeConfigurationId);
|
|
467
|
+
if (!activated) {
|
|
468
|
+
this._log(
|
|
469
|
+
`Failed to activate the selected remote configuration: ${activeConfigurationId}`,
|
|
470
|
+
LOG_LEVEL_NOTICE
|
|
471
|
+
);
|
|
472
|
+
} else {
|
|
473
|
+
this._log(
|
|
474
|
+
`Active remote configuration '${activeConfigurationId}' has been activated.`,
|
|
475
|
+
LOG_LEVEL_VERBOSE
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const p2pActiveConfigurationId = this.settings.P2P_ActiveRemoteConfigurationId;
|
|
480
|
+
if (p2pActiveConfigurationId && this.settings.remoteConfigurations?.[p2pActiveConfigurationId]) {
|
|
481
|
+
const activatedP2P = activateP2PRemoteConfiguration(this.settings, p2pActiveConfigurationId);
|
|
482
|
+
if (!activatedP2P) {
|
|
483
|
+
this._log(
|
|
484
|
+
`Failed to activate the selected P2P remote configuration: ${p2pActiveConfigurationId}`,
|
|
485
|
+
LOG_LEVEL_NOTICE
|
|
486
|
+
);
|
|
487
|
+
} else {
|
|
488
|
+
this._log(
|
|
489
|
+
`P2P active remote configuration '${p2pActiveConfigurationId}' has been activated.`,
|
|
490
|
+
LOG_LEVEL_VERBOSE
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const lsKey = "obsidian-live-sync-vaultanddevicename-" + this.APIService.getSystemVaultName() + this.additionalSuffixOfDatabaseName();
|
|
495
|
+
if (this.settings.deviceAndVaultName != "") {
|
|
496
|
+
if (!this.getItem(lsKey)) {
|
|
497
|
+
this.setDeviceAndVaultName(this.settings.deviceAndVaultName);
|
|
498
|
+
this.saveDeviceAndVaultName();
|
|
499
|
+
this.settings.deviceAndVaultName = "";
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (isCloudantURI(this.settings.couchDB_URI) && this.settings.customChunkSize != 0) {
|
|
503
|
+
this._log(
|
|
504
|
+
"Configuration issues detected and automatically resolved. However, unsynchronized data may exist. Consider rebuilding if necessary.",
|
|
505
|
+
LOG_LEVEL_NOTICE
|
|
506
|
+
);
|
|
507
|
+
this.settings.customChunkSize = 0;
|
|
508
|
+
}
|
|
509
|
+
this.setDeviceAndVaultName(this.getItem(lsKey) || "");
|
|
510
|
+
if (this.getDeviceAndVaultName() == "") {
|
|
511
|
+
if (this.settings.usePluginSync) {
|
|
512
|
+
this._log("Device name missing. Disabling plug-in sync.", LOG_LEVEL_NOTICE);
|
|
513
|
+
this.settings.usePluginSync = false;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (migratedLegacyRemoteConfigurations || migratedP2PActiveRemoteConfiguration) {
|
|
517
|
+
await this.saveSettingData();
|
|
518
|
+
}
|
|
519
|
+
this._lastPersistedSettings = this.cloneSettings(this.settings);
|
|
520
|
+
const dispatch = this.settings;
|
|
521
|
+
void this.onSettingLoaded(dispatch);
|
|
522
|
+
void this.onSettingChanged(dispatch);
|
|
523
|
+
}
|
|
524
|
+
tryDecodeJson(encoded) {
|
|
525
|
+
try {
|
|
526
|
+
if (!encoded) return false;
|
|
527
|
+
return JSON.parse(encoded);
|
|
528
|
+
} catch {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
cloneSettings(settings) {
|
|
533
|
+
return {
|
|
534
|
+
...settings,
|
|
535
|
+
remoteConfigurations: Object.fromEntries(
|
|
536
|
+
Object.entries(settings.remoteConfigurations || {}).map(([id, config]) => [id, { ...config }])
|
|
537
|
+
)
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
export {
|
|
542
|
+
SettingService
|
|
543
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ITestService } from "./IService.js";
|
|
2
|
+
import { ServiceBase, type ServiceContext } from "./ServiceBase.js";
|
|
3
|
+
/**
|
|
4
|
+
* The TestService provides methods for adding and handling test results.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class TestService<T extends ServiceContext = ServiceContext> extends ServiceBase<T> implements ITestService {
|
|
7
|
+
/**
|
|
8
|
+
* Run the test suite to verify the plug-in's functionality.
|
|
9
|
+
* This is typically used for development and debugging purposes.
|
|
10
|
+
* It may involve user interaction (means raising resolveByUserInteraction).
|
|
11
|
+
*/
|
|
12
|
+
readonly test: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
|
|
13
|
+
/**
|
|
14
|
+
* Run the multi-device test suite to verify the plug-in's functionality across multiple devices.
|
|
15
|
+
* This is typically used for development and debugging purposes.
|
|
16
|
+
* It may involve user interaction (means raising resolveByUserInteraction).
|
|
17
|
+
*/
|
|
18
|
+
readonly testMultiDevice: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
|
|
19
|
+
/**
|
|
20
|
+
* Add a test result to the test suite.
|
|
21
|
+
* @param name The name of the test case.
|
|
22
|
+
* @param key The key of the test result.
|
|
23
|
+
* @param result The result of the test (true for success, false for failure).
|
|
24
|
+
* @param summary A brief summary of the test result.
|
|
25
|
+
* @param message A detailed message about the test result.
|
|
26
|
+
*/
|
|
27
|
+
abstract addTestResult(name: string, key: string, result: boolean, summary?: string, message?: string): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { handlers } from "../lib/HandlerUtils.js";
|
|
2
|
+
import { ServiceBase } from "./ServiceBase.js";
|
|
3
|
+
class TestService extends ServiceBase {
|
|
4
|
+
/**
|
|
5
|
+
* Run the test suite to verify the plug-in's functionality.
|
|
6
|
+
* This is typically used for development and debugging purposes.
|
|
7
|
+
* It may involve user interaction (means raising resolveByUserInteraction).
|
|
8
|
+
*/
|
|
9
|
+
test = handlers().bailFirstFailure("test");
|
|
10
|
+
/**
|
|
11
|
+
* Run the multi-device test suite to verify the plug-in's functionality across multiple devices.
|
|
12
|
+
* This is typically used for development and debugging purposes.
|
|
13
|
+
* It may involve user interaction (means raising resolveByUserInteraction).
|
|
14
|
+
*/
|
|
15
|
+
testMultiDevice = handlers().bailFirstFailure("testMultiDevice");
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
TestService
|
|
19
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RemoteDBSettings, TweakValues } from "../../common/types.js";
|
|
2
|
+
import type { ITweakValueService } from "./IService.js";
|
|
3
|
+
import { ServiceBase, type ServiceContext } from "./ServiceBase.js";
|
|
4
|
+
/**
|
|
5
|
+
* The TweakValueService provides methods for managing tweak values and resolving mismatches.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class TweakValueService<T extends ServiceContext = ServiceContext> extends ServiceBase<T> implements ITweakValueService {
|
|
8
|
+
/**
|
|
9
|
+
* Fetch and trial the remote database settings to determine if they are preferred.
|
|
10
|
+
* @param trialSetting The remote database settings to connect.
|
|
11
|
+
*/
|
|
12
|
+
abstract fetchRemotePreferred(trialSetting: RemoteDBSettings): Promise<TweakValues | false>;
|
|
13
|
+
/**
|
|
14
|
+
* Check and ask the user to resolve any mismatched tweak values.
|
|
15
|
+
* @param preferred The preferred tweak values to check against.
|
|
16
|
+
*/
|
|
17
|
+
abstract checkAndAskResolvingMismatched(preferred: Partial<TweakValues>): Promise<[TweakValues | boolean, boolean]>;
|
|
18
|
+
/**
|
|
19
|
+
* Ask the user to resolve any mismatched tweak values.
|
|
20
|
+
* @param preferredSource The preferred tweak values to resolve against.
|
|
21
|
+
*/
|
|
22
|
+
abstract askResolvingMismatched(preferredSource: TweakValues): Promise<"OK" | "CHECKAGAIN" | "IGNORE">;
|
|
23
|
+
/**
|
|
24
|
+
* Check and ask the user to use the remote configuration.
|
|
25
|
+
* @param settings The remote database settings to connect.
|
|
26
|
+
*/
|
|
27
|
+
abstract checkAndAskUseRemoteConfiguration(settings: RemoteDBSettings): Promise<{
|
|
28
|
+
result: false | TweakValues;
|
|
29
|
+
requireFetch: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Ask the user to use the remote configuration.
|
|
33
|
+
* @param trialSetting The remote database settings to connect.
|
|
34
|
+
* @param preferred The preferred tweak values to use.
|
|
35
|
+
*/
|
|
36
|
+
abstract askUseRemoteConfiguration(trialSetting: RemoteDBSettings, preferred: TweakValues): Promise<{
|
|
37
|
+
result: false | TweakValues;
|
|
38
|
+
requireFetch: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type LOG_LEVEL } from "octagonal-wheels/common/logger";
|
|
2
|
+
import type { AppLifecycleService } from "./AppLifecycleService.js";
|
|
3
|
+
import type { LiveSyncEventHub } from "../../hub/hub.js";
|
|
4
|
+
export declare class UnresolvedErrorManager {
|
|
5
|
+
private readonly events;
|
|
6
|
+
private _log;
|
|
7
|
+
private appLifecycleService;
|
|
8
|
+
private _occurredErrors;
|
|
9
|
+
showError(msg: string, max_log_level?: LOG_LEVEL): void;
|
|
10
|
+
clearError(msg: string): void;
|
|
11
|
+
clearErrors(): void;
|
|
12
|
+
countErrors(needle: string): number;
|
|
13
|
+
private _reportUnresolvedMessages;
|
|
14
|
+
constructor(appLifecycleService: AppLifecycleService, events: LiveSyncEventHub);
|
|
15
|
+
}
|