@peers-app/peers-sdk 0.12.2 → 0.12.3

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.
@@ -46,9 +46,11 @@ class UserContext {
46
46
  * so any tables in packages have been registered are available at sync time
47
47
  */
48
48
  loadAllPackages() {
49
- this.userDataContext.packageLoader.loadAllPackages();
49
+ this.userDataContext.packageLoader.loadAllPackages()
50
+ .catch(err => console.error('[UserContext] loadAllPackages failed for userDataContext:', err));
50
51
  for (const groupContext of this.groupDataContexts.values()) {
51
- groupContext.packageLoader.loadAllPackages();
52
+ groupContext.packageLoader.loadAllPackages()
53
+ .catch(err => console.error('[UserContext] loadAllPackages failed for groupContext:', err));
52
54
  }
53
55
  }
54
56
  async loadGroupContexts() {
@@ -95,6 +95,16 @@ class PackageLoader {
95
95
  }
96
96
  }
97
97
  _evaluateBundle(pkg, bundleCode) {
98
+ // Node.js built-in modules that do not exist in React Native (and would cause
99
+ // a fatal native error if passed through to RN's require). We block them here
100
+ // and throw a descriptive JS Error instead, which the surrounding try/catch
101
+ // converts into a warning rather than a process-killing crash.
102
+ const NODE_ONLY_MODULES = new Set([
103
+ 'child_process', 'fs', 'path', 'os', 'crypto', 'http', 'https',
104
+ 'net', 'tls', 'stream', 'buffer', 'util', 'events', 'assert',
105
+ 'dns', 'url', 'querystring', 'readline', 'repl', 'vm',
106
+ 'worker_threads', 'cluster', 'perf_hooks',
107
+ ]);
98
108
  const moduleExports = {};
99
109
  const module = { exports: moduleExports };
100
110
  const customRequire = (moduleId) => {
@@ -113,26 +123,37 @@ class PackageLoader {
113
123
  // external Node modules they need (e.g. child_process, os, path), and the loader
114
124
  // should verify they are allowed before granting access. For now we pass through
115
125
  // to the underlying require and log a warning so usages remain visible.
126
+ if (NODE_ONLY_MODULES.has(moduleId)) {
127
+ // Throw a plain JS Error so the surrounding try/catch can handle it
128
+ // gracefully instead of letting RN's require trigger a native fatal.
129
+ throw new Error(`[PackageLoader] Package "${pkg.name}" required Node.js-only module "${moduleId}" which is not available in this environment`);
130
+ }
116
131
  console.warn(`Package ${pkg.name} is requiring a module ${moduleId}, which is not provided by the package loader.`);
117
132
  return _require(moduleId);
118
133
  }
119
134
  };
120
- const bundleFunction = new Function('module', 'exports', 'require', bundleCode);
121
- bundleFunction(module, moduleExports, customRequire);
122
- const bundleExports = module.exports;
123
- const packageInstance = bundleExports?.exports || bundleExports?.package || bundleExports?.default || bundleExports;
124
- this.packageInstances[pkg.packageId] = packageInstance;
125
- if (packageInstance && typeof packageInstance === 'object') {
126
- packageInstance.toolInstances?.forEach((toolInstance) => {
127
- (0, tools_1.registerTool)(toolInstance);
128
- (0, tools_2.Tools)(this.dataContext).save(toolInstance.tool);
129
- });
130
- packageInstance.tableDefinitions?.forEach((tableDefinition) => {
131
- this.dataContext.tableContainer.registerTableDefinition(tableDefinition, { overwrite: true });
132
- });
133
- return packageInstance;
135
+ try {
136
+ const bundleFunction = new Function('module', 'exports', 'require', bundleCode);
137
+ bundleFunction(module, moduleExports, customRequire);
138
+ const bundleExports = module.exports;
139
+ const packageInstance = bundleExports?.exports || bundleExports?.package || bundleExports?.default || bundleExports;
140
+ this.packageInstances[pkg.packageId] = packageInstance;
141
+ if (packageInstance && typeof packageInstance === 'object') {
142
+ packageInstance.toolInstances?.forEach((toolInstance) => {
143
+ (0, tools_1.registerTool)(toolInstance);
144
+ (0, tools_2.Tools)(this.dataContext).save(toolInstance.tool);
145
+ });
146
+ packageInstance.tableDefinitions?.forEach((tableDefinition) => {
147
+ this.dataContext.tableContainer.registerTableDefinition(tableDefinition, { overwrite: true });
148
+ });
149
+ return packageInstance;
150
+ }
151
+ return;
152
+ }
153
+ catch (err) {
154
+ console.warn(`[PackageLoader] Failed to evaluate bundle for "${pkg.name}":`, err.message);
155
+ return undefined;
134
156
  }
135
- return;
136
157
  }
137
158
  }
138
159
  exports.PackageLoader = PackageLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"