@lvce-editor/extension-management-worker 4.41.2 → 4.43.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.
@@ -1200,19 +1200,58 @@ const create$5 = async ({
1200
1200
  return rpc;
1201
1201
  };
1202
1202
 
1203
+ const reconnectDelay = 2000;
1204
+ const waitForReconnect = async () => {
1205
+ await new Promise(resolve => {
1206
+ setTimeout(resolve, reconnectDelay);
1207
+ });
1208
+ };
1209
+ const connect = async ({
1210
+ commandMap,
1211
+ wsUrl
1212
+ }) => {
1213
+ const webSocket = new WebSocket(wsUrl);
1214
+ try {
1215
+ const rpc = await create$5({
1216
+ commandMap,
1217
+ webSocket
1218
+ });
1219
+ return {
1220
+ rpc,
1221
+ webSocket
1222
+ };
1223
+ } catch (error) {
1224
+ webSocket.close();
1225
+ throw error;
1226
+ }
1227
+ };
1203
1228
  const create$4 = async ({
1204
1229
  commandMap,
1230
+ onClose,
1205
1231
  type
1206
1232
  }) => {
1207
1233
  const host = getHost();
1208
1234
  const protocol = getProtocol();
1209
1235
  const wsUrl = getWebSocketUrl(type, host, protocol);
1210
- const webSocket = new WebSocket(wsUrl);
1211
- const rpc = await create$5({
1212
- commandMap,
1213
- webSocket
1214
- });
1215
- return rpc;
1236
+ let connection;
1237
+ try {
1238
+ connection = await connect({
1239
+ commandMap,
1240
+ wsUrl
1241
+ });
1242
+ } catch {
1243
+ await waitForReconnect();
1244
+ connection = await connect({
1245
+ commandMap,
1246
+ wsUrl
1247
+ });
1248
+ }
1249
+ if (onClose) {
1250
+ connection.webSocket.addEventListener('close', onClose, {
1251
+ once: true
1252
+ });
1253
+ }
1254
+ return connection.rpc;
1216
1255
  };
1217
1256
 
1218
1257
  const create$3 = async ({
@@ -1721,6 +1760,45 @@ const getNodeRpcInfo = async (extensionId, rpcId) => {
1721
1760
  };
1722
1761
  };
1723
1762
 
1763
+ const cacheName$1 = 'ExtensionSecrets';
1764
+ const getRequestUrl = (extensionId, key) => {
1765
+ return `https://secret-storage.invalid/${encodeURIComponent(extensionId)}/${encodeURIComponent(key)}`;
1766
+ };
1767
+ const isElectron = () => {
1768
+ return get$5().platform === Electron;
1769
+ };
1770
+ const deleteSecret = async (extensionId, key) => {
1771
+ string(extensionId);
1772
+ string(key);
1773
+ if (isElectron()) {
1774
+ await invoke$1('SecretStorage.delete', extensionId, key);
1775
+ return;
1776
+ }
1777
+ const cache = await caches.open(cacheName$1);
1778
+ await cache.delete(getRequestUrl(extensionId, key));
1779
+ };
1780
+ const getSecret = async (extensionId, key) => {
1781
+ string(extensionId);
1782
+ string(key);
1783
+ if (isElectron()) {
1784
+ return invoke$1('SecretStorage.get', extensionId, key);
1785
+ }
1786
+ const cache = await caches.open(cacheName$1);
1787
+ const response = await cache.match(getRequestUrl(extensionId, key));
1788
+ return response?.text();
1789
+ };
1790
+ const storeSecret = async (extensionId, key, value) => {
1791
+ string(extensionId);
1792
+ string(key);
1793
+ string(value);
1794
+ if (isElectron()) {
1795
+ await invoke$1('SecretStorage.store', extensionId, key, value);
1796
+ return;
1797
+ }
1798
+ const cache = await caches.open(cacheName$1);
1799
+ await cache.put(getRequestUrl(extensionId, key), new Response(value));
1800
+ };
1801
+
1724
1802
  class CommandNotFoundError extends Error {
1725
1803
  constructor(command) {
1726
1804
  super(`Command not found ${command}`);
@@ -1732,8 +1810,17 @@ class CommandNotFoundError extends Error {
1732
1810
  const createExtensionCommandMap = extensionId => {
1733
1811
  return {
1734
1812
  ...commandMapRef,
1813
+ 'Extensions.deleteSecret'(key) {
1814
+ return deleteSecret(extensionId, key);
1815
+ },
1735
1816
  'Extensions.getNodeRpcInfo'(rpcId) {
1736
1817
  return getNodeRpcInfo(extensionId, rpcId);
1818
+ },
1819
+ 'Extensions.getSecret'(key) {
1820
+ return getSecret(extensionId, key);
1821
+ },
1822
+ 'Extensions.storeSecret'(key, value) {
1823
+ return storeSecret(extensionId, key, value);
1737
1824
  }
1738
1825
  };
1739
1826
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.41.2",
3
+ "version": "4.43.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"