dcp-client 4.4.6 → 4.4.7

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/fs-basic.py ADDED
@@ -0,0 +1,46 @@
1
+ # @file fs-basic.py
2
+ # Python polyfills for OS-level functionality needed by dcp-client
3
+ #
4
+ # @author Wes Garland, wes@distributive.network
5
+ # @date Feb 2024
6
+
7
+ import os
8
+ import pythonmonkey as pm
9
+
10
+ def readFile(filename: str) -> str:
11
+ with open(filename, "r", encoding="utf8") as fileHnd:
12
+ return fileHnd.read()
13
+
14
+ def writeFile(filename: str, contents: str) -> None:
15
+ with open(filename, "w", encoding="utf8") as fileHnd:
16
+ fileHnd.write(contents)
17
+
18
+ def getMode(filename: str) -> int:
19
+ return os.stat(filename).st_mode
20
+
21
+ def fileExists(filename: str) -> bool:
22
+ return os.path.isfile(filename)
23
+
24
+ def dirExists(dirname: str) -> bool:
25
+ return os.path.isdir(dirname)
26
+
27
+ def mkdir(dirname: str) -> None:
28
+ return os.makedirs(dirname)
29
+
30
+ exports['readFile'] = readFile
31
+ exports['writeFile'] = writeFile
32
+ exports['getMode'] = getMode
33
+ exports['fileExists'] = fileExists
34
+ exports['dirExists'] = dirExists
35
+ exports['mkdir'] = mkdir
36
+ exports['constants'] = { 'W_OK': os.W_OK, 'R_OK': os.R_OK }
37
+ exports['pathResolve'] = os.path.join
38
+ exports['basename'] = os.path.basename
39
+ exports['dirname'] = os.path.dirname
40
+ exports['absPath'] = os.path.isabs
41
+ exports['joinPath'] = os.path.join
42
+ exports['pathSep'] = os.path.sep
43
+ exports['readDir'] = os.listdir
44
+ exports['rm'] = os.remove
45
+ exports['rmdir'] = os.rmdir
46
+ exports['fileSize'] = lambda filename: os.stat(filename).st_size
package/index.py ADDED
@@ -0,0 +1,105 @@
1
+ # @file index.py
2
+ # PythonMonkey loader for the dcp-client package.
3
+ #
4
+ # During module initialization, we load dist/dcp-client-bundle.js from the
5
+ # same directory as this file, and setup a minimum compatibility environment
6
+ # for dcp-client to execute in.
7
+ #
8
+ # Note that while this code may use PythonMonkey"s require() to get things done,
9
+ # require is not exposed as a symbol to JS here; the environment used by dcp-client
10
+ # for PythonMonkey looks pretty much like a web browser to keep things like SocketIO
11
+ # happy.
12
+ #
13
+ # A few OS-level interfaces are plumbed in, however, so that the dcp-client UX
14
+ # remains somewhat similar to Node.js. In particular,
15
+ # - window.localStorage is on disk and compatible with the Node.js version
16
+ # - id and bank keystores are loaded from the same location on disk as the Node.js version
17
+ # - FUTURE: support for oAuth
18
+ # - FUTURE: support for dcp-config fragments based on the Node.js loader (./index.js)
19
+ # - FUTURE: support for bundle auto-update similar to the Node.js loader
20
+ #
21
+ # @author Will Pringle, will@distributive.network
22
+ # @author Wes Garland, wes@distributive.network
23
+ # @date Feb 2024
24
+ #
25
+ import pythonmonkey as pm
26
+ import os
27
+ import asyncio
28
+
29
+ # @todo determine dcp_client_bundle_filename inside JS via require.resolve
30
+ dcp_client_bundle_filename = os.path.dirname(__file__) + "/dist/dcp-client-bundle.js"
31
+
32
+ # load dcp-client, then optionally run a callback function
33
+ async def load_dcp_client(callback=None, **kwargs):
34
+ if callback is not None and not callable(callback):
35
+ raise Exception("callback must be callable")
36
+
37
+ cb_retval = None
38
+
39
+ def fetch(url):
40
+ try:
41
+ import urllib.request
42
+ return urllib.request.urlopen(url).read().decode()
43
+ except Exception as error:
44
+ raise error
45
+
46
+ here = { "filename": __file__, "fromPythonFrame": True }
47
+ dcp_client_modules = pm.eval("""'use strict';(
48
+ function iife(kwargs, fetch, require, bootstrapRequire)
49
+ {
50
+ const fsBasic = require('./fs-basic');
51
+ const dcpSupport = require('./dcp-support');
52
+ const debug = bootstrapRequire('debug');
53
+ const vm = bootstrapRequire('vm');
54
+ debug('dcp-client:')('initializing');
55
+
56
+ const schedulerLocation = kwargs.scheduler || python.getenv('DCP_SCHEDULER_LOCATION') || 'https://scheduler.distributed.computer';
57
+ const configLocation = kwargs.config || python.getenv('DCP_CONFIG_LOCATION') || schedulerLocation + '/etc/dcp-config.js';
58
+ globalThis.window = globalThis; /** @todo fix in pythonmonkey */
59
+ globalThis.crypto = Object.assign({}, { getRandomValues: dcpSupport.getRandomValues }, globalThis.crypto);
60
+
61
+ /** @todo extract baked-in defaults from bundle */
62
+ if (!globalThis.dcpConfig)
63
+ globalThis.dcpConfig = {};
64
+
65
+ if (configLocation === false || configLocation === '') /* explicitly request no remote config */
66
+ {
67
+ debug('dcp-client:config')('no remote config')
68
+ if (!globalThis.dcpConfig)
69
+ globalThis.dcpConfig = {};
70
+ Object.assign(globalThis.dcpConfig, { scheduler: { configLocation: false } });
71
+ }
72
+ else
73
+ {
74
+ /** @todo use KVIN version instead */
75
+ debug('dcp-client:config')('fetching config from', configLocation);
76
+ const dcpConfigCode = fetch(configLocation);
77
+ Object.assign(globalThis.dcpConfig, vm.runInContext(dcpConfigCode, undefined, { "filename": configLocation }));
78
+ }
79
+
80
+ globalThis.dcpConfig.build = 'debug' /** @todo fix the bundle so that this is not necessary */
81
+ const bundleFilename = require.resolve('./dist/dcp-client-bundle');
82
+ debug('dcp-client:bundle')('loading bundle', bundleFilename);
83
+ const bundleCode = fsBasic.readFile(bundleFilename);
84
+ debug('dcp-client:bundle')('evaluating bundle', bundleFilename);
85
+ const dcpClientExports = vm.runInContext(bundleCode, undefined, { "filename": bundleFilename });
86
+ debug('dcp-client:bundle')('loaded bundle', bundleFilename);
87
+ globalThis.dcp = dcpClientExports;
88
+ Object.assign(dcpClientExports['fs-basic'], fsBasic);
89
+ return dcpClientExports;
90
+ }) /* iife */;
91
+ """, here)(kwargs, fetch, pm.createRequire(__file__), pm.bootstrap.require)
92
+
93
+ dcp_client_modules["utils"]["expandPath"] = os.path.expanduser
94
+
95
+ if (callback):
96
+ cb_retval = await callback()
97
+
98
+ await pm.wait()
99
+ return cb_retval
100
+
101
+ def init(*args, **kwargs):
102
+ asyncio.run(load_dcp_client(*args, **kwargs))
103
+
104
+ # exports of dcp-client python-language CommonJS module
105
+ exports["init"] = init
@@ -847,7 +847,7 @@ self.wrapScriptLoading({ scriptName: 'access-lists', ringTransition: true }, fun
847
847
  },
848
848
  configurable: false
849
849
  });
850
- } else if (prop in blockList) {
850
+ } else if (blockList.hasOwnProperty(prop)) {
851
851
  let isSet = false;
852
852
  let blocked = blockList[prop];
853
853
  let propValue = obj[prop];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcp-client",
3
- "version": "4.4.6",
3
+ "version": "4.4.7",
4
4
  "description": "Core libraries for accessing DCP network",
5
5
  "keywords": [
6
6
  "dcp"
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "license": "MIT",
17
17
  "author": "Distributive",
18
- "main": "index.js",
18
+ "main": "index",
19
19
  "directories": {
20
20
  "example": "examples"
21
21
  },
@@ -39,7 +39,6 @@
39
39
  "https-proxy-agent": "^5.0.0",
40
40
  "kvin": "1.2.14",
41
41
  "nanoid": "3.3.7",
42
- "node-localstorage": "^2.1.5",
43
42
  "physical-cpu-count": "^2.0.0",
44
43
  "polyfill-crypto.getrandomvalues": "^1.0.0",
45
44
  "regedit": "^3.0.3",
@@ -59,6 +58,10 @@
59
58
  "npm": ">=7"
60
59
  },
61
60
  "overrides": {
62
- "@azure/msal-node": "2.2.0"
61
+ "@kingsds/socket.io-client": {
62
+ "@kingsds/engine.io-client": {
63
+ "ws": "8.17.1"
64
+ }
65
+ }
63
66
  }
64
67
  }