@bugmail-js/core 0.1.3 → 0.1.4

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.
@@ -26,11 +26,18 @@ export class BugMailCoreClient {
26
26
 
27
27
  try {
28
28
  // Use fetch if available (browser or Node >=18), else fallback
29
+ // Prefer global fetch (browsers, Node 18+). Avoid importing node-fetch in bundlers
29
30
  let fetchFn = (typeof fetch !== 'undefined') ? fetch : undefined;
30
31
  if (!fetchFn) {
32
+ // In Node environments where fetch is not global, try dynamic import at runtime only
31
33
  try {
32
- // Dynamically import node-fetch if not in browser
33
- fetchFn = (await import('node-fetch')).default;
34
+ // Use require-like dynamic import only in Node; bundlers should not include node-fetch for browser builds
35
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
36
+ fetchFn = (await import('node-fetch')).default;
37
+ } else {
38
+ console.error('[BugMail] fetch is not available in this environment.');
39
+ return;
40
+ }
34
41
  } catch (e) {
35
42
  console.error('[BugMail] fetch is not available in this environment.');
36
43
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugmail-js/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "exports": {
package/plugin-manager.js CHANGED
@@ -1,7 +1,45 @@
1
1
  // Plugin manager (core, generic)
2
2
  export class CorePluginManager {
3
3
  constructor() {
4
- // ...core plugin system
4
+ // Maintain a set of plugins and a simple hook map
5
+ this.plugins = new Set();
6
+ this.hooks = {
7
+ setup: new Set(),
8
+ disconnect: new Set(),
9
+ onErrorCaptured: new Set(),
10
+ };
11
+ }
12
+
13
+ register(plugin) {
14
+ this.plugins.add(plugin);
15
+ }
16
+
17
+ unregister(plugin) {
18
+ this.plugins.delete(plugin);
19
+ }
20
+
21
+ runHooks(hookName, data, client) {
22
+ const hooks = this.hooks[hookName];
23
+ if (!hooks) return data;
24
+ let result = data;
25
+ for (const fn of hooks) {
26
+ try {
27
+ const r = fn(result, client);
28
+ if (r !== undefined) result = r;
29
+ } catch (e) {
30
+ // swallow plugin errors to avoid breaking host app
31
+ console.error('[BugMail] Plugin hook error:', e);
32
+ }
33
+ }
34
+ return result;
35
+ }
36
+
37
+ addHook(hookName, fn) {
38
+ if (!this.hooks[hookName]) this.hooks[hookName] = new Set();
39
+ this.hooks[hookName].add(fn);
40
+ }
41
+
42
+ removeHook(hookName, fn) {
43
+ this.hooks[hookName]?.delete(fn);
5
44
  }
6
- // ...core methods
7
45
  }