@bugmail-js/core 0.1.3 → 0.1.5

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.
@@ -22,15 +22,34 @@ export class BugMailCoreClient {
22
22
  'Content-Type': 'application/json',
23
23
  ...(context.headers || {})
24
24
  };
25
+
26
+ // If an API key is provided in the client config, ensure the request
27
+ // includes the expected header unless the caller already supplied one.
28
+ if (this.config && this.config.apiKey) {
29
+ const hasApiKeyHeader = Object.keys(headers).some(h => h.toLowerCase() === 'x-bugmail-api-key');
30
+ if (!hasApiKeyHeader) {
31
+ headers['X-BugMail-API-Key'] = this.config.apiKey;
32
+ }
33
+ }
25
34
  const payload = context.payload || {};
26
35
 
27
36
  try {
28
37
  // Use fetch if available (browser or Node >=18), else fallback
38
+ // Prefer global fetch (browsers, Node 18+). Avoid importing node-fetch in bundlers
29
39
  let fetchFn = (typeof fetch !== 'undefined') ? fetch : undefined;
30
40
  if (!fetchFn) {
41
+ // In Node environments where fetch is not global, try dynamic import at runtime only
31
42
  try {
32
- // Dynamically import node-fetch if not in browser
33
- fetchFn = (await import('node-fetch')).default;
43
+ // Use require-like dynamic import only in Node; bundlers should not include node-fetch for browser builds
44
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
45
+ // Construct the module name at runtime to avoid bundlers statically
46
+ // resolving/including `node-fetch` in browser builds (Vite/Rollup).
47
+ const nodeFetchName = 'node' + '-fetch';
48
+ fetchFn = (await import(nodeFetchName)).default;
49
+ } else {
50
+ console.error('[BugMail] fetch is not available in this environment.');
51
+ return;
52
+ }
34
53
  } catch (e) {
35
54
  console.error('[BugMail] fetch is not available in this environment.');
36
55
  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.5",
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
  }