@cityofzion/bs-electron 0.1.50 → 0.1.52

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/dist/renderer.js CHANGED
@@ -39,7 +39,8 @@ function bindApiFromMain(apiName) {
39
39
  exposedApi.syncMethods.forEach(method => {
40
40
  (0, utils_1.populateObjectFromPath)(api, String(method), {
41
41
  value: (...args) => {
42
- const result = window.ipcBsElectron.sendSync((0, utils_1.buildIpcChannelName)(apiName, method), ...args);
42
+ const plainArgs = (0, utils_1.toPlainObject)(args);
43
+ const result = window.ipcBsElectron.sendSync((0, utils_1.buildIpcChannelName)(apiName, method), ...plainArgs);
43
44
  if (result.error) {
44
45
  throw new Error(result.error);
45
46
  }
@@ -51,7 +52,8 @@ function bindApiFromMain(apiName) {
51
52
  exposedApi.asyncMethods.forEach(method => {
52
53
  (0, utils_1.populateObjectFromPath)(api, String(method), {
53
54
  value: (...args) => __awaiter(this, void 0, void 0, function* () {
54
- const result = yield window.ipcBsElectron.invoke((0, utils_1.buildIpcChannelName)(apiName, method), ...args);
55
+ const plainArgs = (0, utils_1.toPlainObject)(args);
56
+ const result = yield window.ipcBsElectron.invoke((0, utils_1.buildIpcChannelName)(apiName, method), ...plainArgs);
55
57
  if (result.error) {
56
58
  throw new Error(result.error);
57
59
  }
package/dist/utils.d.ts CHANGED
@@ -16,3 +16,4 @@ export declare function getPropertiesAndMethods(object: any): {
16
16
  export declare function getValueFromPath(obj: any, path: string): any;
17
17
  export declare function populateObjectFromPath(obj: any, path: string, value: PropertyDescriptor & ThisType<any>): any;
18
18
  export declare function buildIpcChannelName<T>(apiName: string, methodOrProperty: keyof T): string;
19
+ export declare function toPlainObject(obj: any): any;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildIpcChannelName = exports.populateObjectFromPath = exports.getValueFromPath = exports.getPropertiesAndMethods = exports.GET_EXPOSED_API_CHANNEL = exports.CHANNEL_PREFIX = void 0;
3
+ exports.toPlainObject = exports.buildIpcChannelName = exports.populateObjectFromPath = exports.getValueFromPath = exports.getPropertiesAndMethods = exports.GET_EXPOSED_API_CHANNEL = exports.CHANNEL_PREFIX = void 0;
4
4
  exports.CHANNEL_PREFIX = 'bsElectron';
5
5
  exports.GET_EXPOSED_API_CHANNEL = `${exports.CHANNEL_PREFIX}:getExposedApi`;
6
6
  // It returns all properties and methods from an object and its prototype chain, that is, extended classes are also considered
@@ -71,3 +71,50 @@ function buildIpcChannelName(apiName, methodOrProperty) {
71
71
  return `${exports.CHANNEL_PREFIX}:${apiName}:${String(methodOrProperty)}`;
72
72
  }
73
73
  exports.buildIpcChannelName = buildIpcChannelName;
74
+ function toPlainObject(obj) {
75
+ if (obj === null || typeof obj !== 'object') {
76
+ return obj;
77
+ }
78
+ if (Array.isArray(obj)) {
79
+ return obj.map(toPlainObject);
80
+ }
81
+ const plain = {};
82
+ const allKeys = new Set();
83
+ // Walk through the prototype chain to get all properties
84
+ let currentObj = obj;
85
+ while (currentObj && currentObj !== Object.prototype) {
86
+ Object.getOwnPropertyNames(currentObj).forEach(key => {
87
+ if (key !== 'constructor') {
88
+ allKeys.add(key);
89
+ }
90
+ });
91
+ currentObj = Object.getPrototypeOf(currentObj);
92
+ }
93
+ for (const key of allKeys) {
94
+ try {
95
+ // Get the property descriptor to check if it's a getter
96
+ const descriptor = Object.getOwnPropertyDescriptor(obj, key) || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(obj), key);
97
+ if (descriptor) {
98
+ if (descriptor.get) {
99
+ // It's a getter, call it to get the value
100
+ const value = obj[key];
101
+ plain[key] = toPlainObject(value);
102
+ }
103
+ else if (descriptor.value !== undefined) {
104
+ // It's a regular property
105
+ plain[key] = toPlainObject(descriptor.value);
106
+ }
107
+ }
108
+ else if (obj[key] !== undefined) {
109
+ // Fallback for edge cases
110
+ plain[key] = toPlainObject(obj[key]);
111
+ }
112
+ }
113
+ catch (_a) {
114
+ // Skip properties that can't be accessed
115
+ continue;
116
+ }
117
+ }
118
+ return plain;
119
+ }
120
+ exports.toPlainObject = toPlainObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-electron",
3
- "version": "0.1.50",
3
+ "version": "0.1.52",
4
4
  "repository": "https://github.com/CityOfZion/blockchain-services",
5
5
  "author": "Coz",
6
6
  "license": "GPL-3.0-only",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "lodash.clonedeep": "~4.5.0",
12
- "@cityofzion/blockchain-service": "1.21.1"
12
+ "@cityofzion/blockchain-service": "1.21.2"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "~20.2.5",