@bugmail-js/core 0.1.5 → 0.1.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/LICENSE CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  MIT License
2
3
 
3
4
  Copyright (c) 2025 MarcorpAI
package/README.md CHANGED
@@ -23,13 +23,13 @@ Quick example (capture an exception)
23
23
  import { BugMailCoreClient } from '@bugmail-js/core';
24
24
 
25
25
  const client = new BugMailCoreClient({
26
- baseUrl: 'http://localhost:8000',
26
+ baseUrl: process.env.BUGMAIL_ENDPOINT || '<your-bugmail-endpoint>',
27
27
  apiPath: '/api/sdk/v1/errors',
28
28
  onError: (info) => console.warn('Reporting failed', info),
29
29
  });
30
30
 
31
31
  await client.captureException(new Error('Test error'), {
32
- headers: { 'X-Bugmail-Api-Key': 'YOUR_PROJECT_API_KEY' },
32
+ headers: { 'x-bugmail-api-key': 'YOUR_PROJECT_API_KEY' },
33
33
  payload: {
34
34
  error: { name: 'Error', message: 'Test error', stack: '...' },
35
35
  context: { url: '/test', environment: 'development' }
@@ -40,14 +40,14 @@ await client.captureException(new Error('Test error'), {
40
40
  API reference (important parts)
41
41
 
42
42
  - `new BugMailCoreClient(config)`
43
- - `config.baseUrl` — backend base URL (default: env `BUGMAIL_API_BASE_URL` or `http://localhost:8000`)
43
+ - `config.baseUrl` — backend base URL (default: env `BUGMAIL_API_BASE_URL` or `<your-bugmail-endpoint>`)
44
44
  - `config.apiPath` — ingestion path (default: `/api/sdk/v1/errors`)
45
45
  - `config.onError` — optional callback invoked when report fails
46
46
 
47
47
  - `captureException(error, context)`
48
48
  - `error` — Error object or any serializable value
49
49
  - `context` — optional object: `{ headers, payload, user, breadcrumbs }`
50
- - Include `headers: { 'X-Bugmail-Api-Key': '<YOUR_PROJECT_API_KEY>' }`
50
+ - Include `headers: { 'x-bugmail-api-key': '<YOUR_PROJECT_API_KEY>' }`
51
51
 
52
52
  - `BreadcrumbTracker`
53
53
  - `new BreadcrumbTracker({ maxBreadcrumbs })`
@@ -67,7 +67,8 @@ Integration notes
67
67
  Backend integration & headers
68
68
 
69
69
  - Ingestion endpoint: `POST {baseUrl}/api/sdk/v1/errors`
70
- - Auth header: `x-bugmail-api-key: <YOUR_PROJECT_API_KEY>` (case-insensitive)
70
+ - Auth header: `x-bugmail-api-key: <YOUR_PROJECT_API_KEY>`
71
+ - Note: HTTP header names are case-insensitive; use the canonical lowercase form above for consistency.
71
72
  - Typical payload shape:
72
73
 
73
74
  ```
@@ -15,7 +15,14 @@ export class BugMailCoreClient {
15
15
  * @param {Object} context - { headers, payload, ... }
16
16
  */
17
17
  async captureException(error, context = {}) {
18
- const baseUrl = this.config.baseUrl || process.env.BUGMAIL_API_BASE_URL || 'http://localhost:8000';
18
+ const isProd = (typeof process !== 'undefined' && process.env?.NODE_ENV === 'production');
19
+ const baseUrl = this.config.baseUrl ||
20
+ (typeof process !== 'undefined' ? (process.env?.BUGMAIL_API_BASE_URL || process.env?.API_BASE_URL || process.env?.BUGMAIL_API_URL) : '') ||
21
+ '';
22
+
23
+ if (isProd && !baseUrl) {
24
+ console.warn('[BugMail] BUGMAIL API base URL missing in production. Reporting might default to localhost.');
25
+ }
19
26
  const apiPath = this.config.apiPath || '/api/sdk/v1/errors';
20
27
  const url = baseUrl.replace(/\/$/, '') + apiPath;
21
28
  const headers = {
@@ -40,10 +47,10 @@ export class BugMailCoreClient {
40
47
  if (!fetchFn) {
41
48
  // In Node environments where fetch is not global, try dynamic import at runtime only
42
49
  try {
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).
50
+ // Check if we're actually in Node.js (not a browser with process polyfill)
51
+ // typeof window === 'undefined' is a reliable check for Node vs Browser
52
+ if (typeof window === 'undefined' && typeof process !== 'undefined' && process.versions && process.versions.node) {
53
+ // Only import node-fetch in actual Node.js environments
47
54
  const nodeFetchName = 'node' + '-fetch';
48
55
  fetchFn = (await import(nodeFetchName)).default;
49
56
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugmail-js/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "exports": {
@@ -35,4 +35,4 @@
35
35
  "url": "https://github.com/MarcorpAI/Bugmail-SDKs/issues"
36
36
  },
37
37
  "sideEffects": false
38
- }
38
+ }